deps: upgrade openssl to 1.0.0f
authorBen Noordhuis <info@bnoordhuis.nl>
Tue, 10 Apr 2012 13:57:21 +0000 (15:57 +0200)
committerBen Noordhuis <info@bnoordhuis.nl>
Wed, 11 Apr 2012 23:34:05 +0000 (01:34 +0200)
1534 files changed:
deps/openssl/README.chromium
deps/openssl/config/android/openssl/opensslconf.h [moved from deps/openssl/config/k8/openssl/opensslconf-posix.h with 80% similarity]
deps/openssl/config/k8/openssl/opensslconf-win32.h [deleted file]
deps/openssl/config/k8/openssl/opensslconf.h
deps/openssl/config/piii/openssl/opensslconf-posix.h [deleted file]
deps/openssl/config/piii/openssl/opensslconf-win32.h [deleted file]
deps/openssl/config/piii/openssl/opensslconf.h
deps/openssl/openssl.gyp
deps/openssl/openssl/CHANGES
deps/openssl/openssl/CHANGES.SSLeay
deps/openssl/openssl/Configure
deps/openssl/openssl/FAQ
deps/openssl/openssl/INSTALL
deps/openssl/openssl/INSTALL.VMS
deps/openssl/openssl/INSTALL.W32
deps/openssl/openssl/INSTALL.WCE
deps/openssl/openssl/Makefile
deps/openssl/openssl/Makefile.org
deps/openssl/openssl/Makefile.shared
deps/openssl/openssl/NEWS
deps/openssl/openssl/Netware/build.bat
deps/openssl/openssl/README
deps/openssl/openssl/VMS/install-vms.com [new file with mode: 0644]
deps/openssl/openssl/VMS/install.com [deleted file]
deps/openssl/openssl/VMS/mkshared.com
deps/openssl/openssl/VMS/openssl_startup.com [new file with mode: 0644]
deps/openssl/openssl/VMS/openssl_undo.com [new file with mode: 0644]
deps/openssl/openssl/apps/CA.com
deps/openssl/openssl/apps/Makefile
deps/openssl/openssl/apps/apps.c
deps/openssl/openssl/apps/apps.h
deps/openssl/openssl/apps/asn1pars.c
deps/openssl/openssl/apps/ca.c
deps/openssl/openssl/apps/ciphers.c
deps/openssl/openssl/apps/cms.c
deps/openssl/openssl/apps/crl2p7.c
deps/openssl/openssl/apps/dgst.c
deps/openssl/openssl/apps/dh.c
deps/openssl/openssl/apps/dhparam.c
deps/openssl/openssl/apps/dsa.c
deps/openssl/openssl/apps/ec.c
deps/openssl/openssl/apps/ecparam.c
deps/openssl/openssl/apps/enc.c
deps/openssl/openssl/apps/engine.c
deps/openssl/openssl/apps/errstr.c
deps/openssl/openssl/apps/gendh.c
deps/openssl/openssl/apps/genpkey.c [new file with mode: 0644]
deps/openssl/openssl/apps/genrsa.c
deps/openssl/openssl/apps/install-apps.com [new file with mode: 0644]
deps/openssl/openssl/apps/install.com [deleted file]
deps/openssl/openssl/apps/makeapps.com
deps/openssl/openssl/apps/ocsp.c
deps/openssl/openssl/apps/openssl-vms.cnf
deps/openssl/openssl/apps/openssl.c
deps/openssl/openssl/apps/openssl.cnf
deps/openssl/openssl/apps/pkcs12.c
deps/openssl/openssl/apps/pkcs7.c
deps/openssl/openssl/apps/pkcs8.c
deps/openssl/openssl/apps/pkey.c [new file with mode: 0644]
deps/openssl/openssl/apps/pkeyparam.c [new file with mode: 0644]
deps/openssl/openssl/apps/pkeyutl.c [new file with mode: 0644]
deps/openssl/openssl/apps/prime.c
deps/openssl/openssl/apps/progs.h
deps/openssl/openssl/apps/progs.pl
deps/openssl/openssl/apps/req.c
deps/openssl/openssl/apps/rsa.c
deps/openssl/openssl/apps/rsautl.c
deps/openssl/openssl/apps/s_apps.h
deps/openssl/openssl/apps/s_cb.c
deps/openssl/openssl/apps/s_client.c
deps/openssl/openssl/apps/s_server.c
deps/openssl/openssl/apps/s_socket.c
deps/openssl/openssl/apps/s_time.c
deps/openssl/openssl/apps/smime.c
deps/openssl/openssl/apps/speed.c
deps/openssl/openssl/apps/ts.c [new file with mode: 0644]
deps/openssl/openssl/apps/tsget [new file with mode: 0644]
deps/openssl/openssl/apps/verify.c
deps/openssl/openssl/apps/vms_decc_init.c [new file with mode: 0644]
deps/openssl/openssl/apps/x509.c
deps/openssl/openssl/config
deps/openssl/openssl/crypto/LPdir_vms.c
deps/openssl/openssl/crypto/LPdir_win.c
deps/openssl/openssl/crypto/Makefile
deps/openssl/openssl/crypto/aes/Makefile
deps/openssl/openssl/crypto/aes/aes.h
deps/openssl/openssl/crypto/aes/aes_cbc.c
deps/openssl/openssl/crypto/aes/aes_cfb.c
deps/openssl/openssl/crypto/aes/aes_core.c
deps/openssl/openssl/crypto/aes/aes_ctr.c
deps/openssl/openssl/crypto/aes/aes_ige.c
deps/openssl/openssl/crypto/aes/aes_ofb.c
deps/openssl/openssl/crypto/aes/aes_x86core.c [new file with mode: 0644]
deps/openssl/openssl/crypto/aes/asm/aes-586.pl
deps/openssl/openssl/crypto/aes/asm/aes-armv4.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/aes/asm/aes-ppc.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/aes/asm/aes-s390x.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/aes/asm/aes-sparcv9.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/aes/asm/aes-x86_64.pl
deps/openssl/openssl/crypto/alphacpuid.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/asn1/Makefile
deps/openssl/openssl/crypto/asn1/a_bitstr.c
deps/openssl/openssl/crypto/asn1/a_dup.c
deps/openssl/openssl/crypto/asn1/a_gentm.c
deps/openssl/openssl/crypto/asn1/a_hdr.c [deleted file]
deps/openssl/openssl/crypto/asn1/a_int.c
deps/openssl/openssl/crypto/asn1/a_meth.c [deleted file]
deps/openssl/openssl/crypto/asn1/a_object.c
deps/openssl/openssl/crypto/asn1/a_octet.c
deps/openssl/openssl/crypto/asn1/a_set.c
deps/openssl/openssl/crypto/asn1/a_sign.c
deps/openssl/openssl/crypto/asn1/a_strnid.c
deps/openssl/openssl/crypto/asn1/a_time.c
deps/openssl/openssl/crypto/asn1/a_type.c
deps/openssl/openssl/crypto/asn1/a_utctm.c
deps/openssl/openssl/crypto/asn1/a_verify.c
deps/openssl/openssl/crypto/asn1/ameth_lib.c [new file with mode: 0644]
deps/openssl/openssl/crypto/asn1/asn1.h
deps/openssl/openssl/crypto/asn1/asn1_err.c
deps/openssl/openssl/crypto/asn1/asn1_gen.c
deps/openssl/openssl/crypto/asn1/asn1_lib.c
deps/openssl/openssl/crypto/asn1/asn1_locl.h [new file with mode: 0644]
deps/openssl/openssl/crypto/asn1/asn1_mac.h
deps/openssl/openssl/crypto/asn1/asn1_par.c
deps/openssl/openssl/crypto/asn1/asn1t.h
deps/openssl/openssl/crypto/asn1/asn_mime.c
deps/openssl/openssl/crypto/asn1/asn_pack.c
deps/openssl/openssl/crypto/asn1/bio_asn1.c [new file with mode: 0644]
deps/openssl/openssl/crypto/asn1/bio_ndef.c [new file with mode: 0644]
deps/openssl/openssl/crypto/asn1/charmap.h
deps/openssl/openssl/crypto/asn1/d2i_pr.c
deps/openssl/openssl/crypto/asn1/d2i_pu.c
deps/openssl/openssl/crypto/asn1/i2d_pr.c
deps/openssl/openssl/crypto/asn1/nsseq.c
deps/openssl/openssl/crypto/asn1/p5_pbe.c
deps/openssl/openssl/crypto/asn1/p5_pbev2.c
deps/openssl/openssl/crypto/asn1/p8_key.c [deleted file]
deps/openssl/openssl/crypto/asn1/p8_pkey.c
deps/openssl/openssl/crypto/asn1/t_pkey.c
deps/openssl/openssl/crypto/asn1/t_req.c
deps/openssl/openssl/crypto/asn1/t_spki.c
deps/openssl/openssl/crypto/asn1/t_x509.c
deps/openssl/openssl/crypto/asn1/tasn_dec.c
deps/openssl/openssl/crypto/asn1/tasn_enc.c
deps/openssl/openssl/crypto/asn1/tasn_fre.c
deps/openssl/openssl/crypto/asn1/tasn_new.c
deps/openssl/openssl/crypto/asn1/tasn_prn.c
deps/openssl/openssl/crypto/asn1/tasn_typ.c
deps/openssl/openssl/crypto/asn1/x_crl.c
deps/openssl/openssl/crypto/asn1/x_long.c
deps/openssl/openssl/crypto/asn1/x_name.c
deps/openssl/openssl/crypto/asn1/x_nx509.c [moved from deps/openssl/openssl/fips/dh/fips_dh_lib.c with 73% similarity]
deps/openssl/openssl/crypto/asn1/x_pubkey.c
deps/openssl/openssl/crypto/asn1/x_req.c
deps/openssl/openssl/crypto/asn1/x_x509.c
deps/openssl/openssl/crypto/bf/Makefile
deps/openssl/openssl/crypto/bf/asm/bf-586.pl
deps/openssl/openssl/crypto/bf/bf_skey.c
deps/openssl/openssl/crypto/bf/blowfish.h
deps/openssl/openssl/crypto/bio/Makefile
deps/openssl/openssl/crypto/bio/b_print.c
deps/openssl/openssl/crypto/bio/b_sock.c
deps/openssl/openssl/crypto/bio/bf_buff.c
deps/openssl/openssl/crypto/bio/bio.h
deps/openssl/openssl/crypto/bio/bio_cb.c
deps/openssl/openssl/crypto/bio/bio_err.c
deps/openssl/openssl/crypto/bio/bio_lcl.h
deps/openssl/openssl/crypto/bio/bio_lib.c
deps/openssl/openssl/crypto/bio/bss_acpt.c
deps/openssl/openssl/crypto/bio/bss_dgram.c
deps/openssl/openssl/crypto/bio/bss_fd.c
deps/openssl/openssl/crypto/bio/bss_file.c
deps/openssl/openssl/crypto/bio/bss_log.c
deps/openssl/openssl/crypto/bio/bss_mem.c
deps/openssl/openssl/crypto/bn/Makefile
deps/openssl/openssl/crypto/bn/asm/alpha-mont.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/bn/asm/armv4-mont.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/bn/asm/bn-586.pl
deps/openssl/openssl/crypto/bn/asm/co-586.pl
deps/openssl/openssl/crypto/bn/asm/mips3-mont.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/bn/asm/ppc-mont.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/bn/asm/ppc.pl
deps/openssl/openssl/crypto/bn/asm/ppc64-mont.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/bn/asm/s390x-mont.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/bn/asm/s390x.S [new file with mode: 0644]
deps/openssl/openssl/crypto/bn/asm/sparcv8plus.S
deps/openssl/openssl/crypto/bn/asm/sparcv9-mont.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/bn/asm/sparcv9a-mont.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/bn/asm/via-mont.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/bn/asm/x86-mont.pl [moved from deps/openssl/openssl/crypto/bn/asm/mo-586.pl with 97% similarity]
deps/openssl/openssl/crypto/bn/asm/x86_64-gcc.c
deps/openssl/openssl/crypto/bn/asm/x86_64-mont.pl
deps/openssl/openssl/crypto/bn/bn.h
deps/openssl/openssl/crypto/bn/bn_asm.c
deps/openssl/openssl/crypto/bn/bn_blind.c
deps/openssl/openssl/crypto/bn/bn_ctx.c
deps/openssl/openssl/crypto/bn/bn_div.c
deps/openssl/openssl/crypto/bn/bn_gf2m.c
deps/openssl/openssl/crypto/bn/bn_lcl.h
deps/openssl/openssl/crypto/bn/bn_lib.c
deps/openssl/openssl/crypto/bn/bn_mont.c
deps/openssl/openssl/crypto/bn/bn_nist.c
deps/openssl/openssl/crypto/bn/bn_print.c
deps/openssl/openssl/crypto/bn/bn_x931p.c [deleted file]
deps/openssl/openssl/crypto/bn/bntest.c
deps/openssl/openssl/crypto/bn/exptest.c
deps/openssl/openssl/crypto/buffer/Makefile
deps/openssl/openssl/crypto/buffer/buf_err.c
deps/openssl/openssl/crypto/buffer/buffer.c
deps/openssl/openssl/crypto/buffer/buffer.h
deps/openssl/openssl/crypto/camellia/Makefile
deps/openssl/openssl/crypto/camellia/asm/cmll-x86.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/camellia/asm/cmll-x86_64.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/camellia/camellia.c
deps/openssl/openssl/crypto/camellia/camellia.h
deps/openssl/openssl/crypto/camellia/cmll_cbc.c
deps/openssl/openssl/crypto/camellia/cmll_cfb.c
deps/openssl/openssl/crypto/camellia/cmll_ctr.c
deps/openssl/openssl/crypto/camellia/cmll_locl.h
deps/openssl/openssl/crypto/camellia/cmll_misc.c
deps/openssl/openssl/crypto/camellia/cmll_ofb.c
deps/openssl/openssl/crypto/cast/Makefile
deps/openssl/openssl/crypto/cast/asm/cast-586.pl
deps/openssl/openssl/crypto/cast/c_skey.c
deps/openssl/openssl/crypto/cast/cast.h
deps/openssl/openssl/crypto/cms/Makefile
deps/openssl/openssl/crypto/cms/cms.h
deps/openssl/openssl/crypto/cms/cms_asn1.c
deps/openssl/openssl/crypto/cms/cms_env.c
deps/openssl/openssl/crypto/cms/cms_err.c
deps/openssl/openssl/crypto/cms/cms_ess.c
deps/openssl/openssl/crypto/cms/cms_io.c
deps/openssl/openssl/crypto/cms/cms_lcl.h
deps/openssl/openssl/crypto/cms/cms_lib.c
deps/openssl/openssl/crypto/cms/cms_sd.c
deps/openssl/openssl/crypto/cms/cms_smime.c
deps/openssl/openssl/crypto/comp/Makefile
deps/openssl/openssl/crypto/comp/c_zlib.c
deps/openssl/openssl/crypto/comp/comp_err.c
deps/openssl/openssl/crypto/conf/Makefile
deps/openssl/openssl/crypto/conf/README
deps/openssl/openssl/crypto/conf/conf.h
deps/openssl/openssl/crypto/conf/conf_api.c
deps/openssl/openssl/crypto/conf/conf_def.c
deps/openssl/openssl/crypto/conf/conf_err.c
deps/openssl/openssl/crypto/conf/conf_lib.c
deps/openssl/openssl/crypto/conf/conf_mall.c
deps/openssl/openssl/crypto/conf/conf_mod.c
deps/openssl/openssl/crypto/cpt_err.c
deps/openssl/openssl/crypto/cryptlib.c
deps/openssl/openssl/crypto/crypto-lib.com
deps/openssl/openssl/crypto/crypto.h
deps/openssl/openssl/crypto/des/Makefile
deps/openssl/openssl/crypto/des/asm/crypt586.pl
deps/openssl/openssl/crypto/des/asm/des-586.pl
deps/openssl/openssl/crypto/des/asm/des686.pl [deleted file]
deps/openssl/openssl/crypto/des/asm/des_enc.m4
deps/openssl/openssl/crypto/des/des-lib.com
deps/openssl/openssl/crypto/des/des_enc.c
deps/openssl/openssl/crypto/des/des_locl.h
deps/openssl/openssl/crypto/des/ecb_enc.c
deps/openssl/openssl/crypto/des/enc_read.c
deps/openssl/openssl/crypto/des/enc_writ.c
deps/openssl/openssl/crypto/des/fcrypt_b.c
deps/openssl/openssl/crypto/des/set_key.c
deps/openssl/openssl/crypto/des/xcbc_enc.c
deps/openssl/openssl/crypto/dh/Makefile
deps/openssl/openssl/crypto/dh/dh.h
deps/openssl/openssl/crypto/dh/dh_ameth.c [new file with mode: 0644]
deps/openssl/openssl/crypto/dh/dh_asn1.c
deps/openssl/openssl/crypto/dh/dh_check.c
deps/openssl/openssl/crypto/dh/dh_err.c
deps/openssl/openssl/crypto/dh/dh_gen.c
deps/openssl/openssl/crypto/dh/dh_key.c
deps/openssl/openssl/crypto/dh/dh_pmeth.c [new file with mode: 0644]
deps/openssl/openssl/crypto/dh/dh_prn.c [moved from deps/openssl/openssl/crypto/bn/bn_opt.c with 86% similarity]
deps/openssl/openssl/crypto/dsa/Makefile
deps/openssl/openssl/crypto/dsa/dsa.h
deps/openssl/openssl/crypto/dsa/dsa_ameth.c [new file with mode: 0644]
deps/openssl/openssl/crypto/dsa/dsa_asn1.c
deps/openssl/openssl/crypto/dsa/dsa_err.c
deps/openssl/openssl/crypto/dsa/dsa_gen.c
deps/openssl/openssl/crypto/dsa/dsa_key.c
deps/openssl/openssl/crypto/dsa/dsa_lib.c
deps/openssl/openssl/crypto/dsa/dsa_locl.h [moved from deps/openssl/openssl/fips/rand/fips_rand.h with 79% similarity]
deps/openssl/openssl/crypto/dsa/dsa_ossl.c
deps/openssl/openssl/crypto/dsa/dsa_pmeth.c [new file with mode: 0644]
deps/openssl/openssl/crypto/dsa/dsa_prn.c [moved from deps/openssl/openssl/fips/rsa/fips_rsa_lib.c with 69% similarity]
deps/openssl/openssl/crypto/dsa/dsa_sign.c
deps/openssl/openssl/crypto/dsa/dsa_vrf.c
deps/openssl/openssl/crypto/dsa/dsatest.c
deps/openssl/openssl/crypto/dso/Makefile
deps/openssl/openssl/crypto/dso/dso.h
deps/openssl/openssl/crypto/dso/dso_beos.c [new file with mode: 0644]
deps/openssl/openssl/crypto/dso/dso_dl.c
deps/openssl/openssl/crypto/dso/dso_dlfcn.c
deps/openssl/openssl/crypto/dso/dso_err.c
deps/openssl/openssl/crypto/dso/dso_lib.c
deps/openssl/openssl/crypto/dso/dso_null.c
deps/openssl/openssl/crypto/dso/dso_openssl.c
deps/openssl/openssl/crypto/dso/dso_vms.c
deps/openssl/openssl/crypto/dso/dso_win32.c
deps/openssl/openssl/crypto/dyn_lck.c [deleted file]
deps/openssl/openssl/crypto/ec/Makefile
deps/openssl/openssl/crypto/ec/ec.h
deps/openssl/openssl/crypto/ec/ec2_mult.c
deps/openssl/openssl/crypto/ec/ec2_smpl.c
deps/openssl/openssl/crypto/ec/ec2_smpt.c [deleted file]
deps/openssl/openssl/crypto/ec/ec_ameth.c [new file with mode: 0644]
deps/openssl/openssl/crypto/ec/ec_curve.c
deps/openssl/openssl/crypto/ec/ec_err.c
deps/openssl/openssl/crypto/ec/ec_lcl.h
deps/openssl/openssl/crypto/ec/ec_lib.c
deps/openssl/openssl/crypto/ec/ec_mult.c
deps/openssl/openssl/crypto/ec/ec_pmeth.c [new file with mode: 0644]
deps/openssl/openssl/crypto/ec/eck_prn.c [new file with mode: 0644]
deps/openssl/openssl/crypto/ec/ecp_nist.c
deps/openssl/openssl/crypto/ec/ectest.c
deps/openssl/openssl/crypto/ecdh/Makefile
deps/openssl/openssl/crypto/ecdh/ecdhtest.c
deps/openssl/openssl/crypto/ecdh/ech_err.c
deps/openssl/openssl/crypto/ecdh/ech_lib.c
deps/openssl/openssl/crypto/ecdsa/Makefile
deps/openssl/openssl/crypto/ecdsa/ecdsa.h
deps/openssl/openssl/crypto/ecdsa/ecdsatest.c
deps/openssl/openssl/crypto/ecdsa/ecs_err.c
deps/openssl/openssl/crypto/ecdsa/ecs_ossl.c
deps/openssl/openssl/crypto/engine/Makefile
deps/openssl/openssl/crypto/engine/eng_all.c
deps/openssl/openssl/crypto/engine/eng_cryptodev.c
deps/openssl/openssl/crypto/engine/eng_dyn.c
deps/openssl/openssl/crypto/engine/eng_err.c
deps/openssl/openssl/crypto/engine/eng_fat.c
deps/openssl/openssl/crypto/engine/eng_int.h
deps/openssl/openssl/crypto/engine/eng_lib.c
deps/openssl/openssl/crypto/engine/eng_list.c
deps/openssl/openssl/crypto/engine/eng_openssl.c
deps/openssl/openssl/crypto/engine/eng_table.c
deps/openssl/openssl/crypto/engine/engine.h
deps/openssl/openssl/crypto/engine/enginetest.c
deps/openssl/openssl/crypto/engine/tb_asnmth.c [new file with mode: 0644]
deps/openssl/openssl/crypto/engine/tb_pkmeth.c [new file with mode: 0644]
deps/openssl/openssl/crypto/err/Makefile
deps/openssl/openssl/crypto/err/err.c
deps/openssl/openssl/crypto/err/err.h
deps/openssl/openssl/crypto/err/err_all.c
deps/openssl/openssl/crypto/err/err_def.c [deleted file]
deps/openssl/openssl/crypto/err/err_prn.c
deps/openssl/openssl/crypto/err/err_str.c [deleted file]
deps/openssl/openssl/crypto/err/openssl.ec
deps/openssl/openssl/crypto/evp/Makefile
deps/openssl/openssl/crypto/evp/bio_enc.c
deps/openssl/openssl/crypto/evp/bio_md.c
deps/openssl/openssl/crypto/evp/c_all.c
deps/openssl/openssl/crypto/evp/c_allc.c
deps/openssl/openssl/crypto/evp/c_alld.c
deps/openssl/openssl/crypto/evp/dig_eng.c [deleted file]
deps/openssl/openssl/crypto/evp/digest.c
deps/openssl/openssl/crypto/evp/e_aes.c
deps/openssl/openssl/crypto/evp/e_camellia.c
deps/openssl/openssl/crypto/evp/e_des.c
deps/openssl/openssl/crypto/evp/e_des3.c
deps/openssl/openssl/crypto/evp/e_idea.c
deps/openssl/openssl/crypto/evp/e_null.c
deps/openssl/openssl/crypto/evp/e_rc2.c
deps/openssl/openssl/crypto/evp/e_rc4.c
deps/openssl/openssl/crypto/evp/e_seed.c
deps/openssl/openssl/crypto/evp/e_xcbc_d.c
deps/openssl/openssl/crypto/evp/enc_min.c [deleted file]
deps/openssl/openssl/crypto/evp/encode.c
deps/openssl/openssl/crypto/evp/evp.h
deps/openssl/openssl/crypto/evp/evp_enc.c
deps/openssl/openssl/crypto/evp/evp_err.c
deps/openssl/openssl/crypto/evp/evp_key.c
deps/openssl/openssl/crypto/evp/evp_lib.c
deps/openssl/openssl/crypto/evp/evp_locl.h
deps/openssl/openssl/crypto/evp/evp_pbe.c
deps/openssl/openssl/crypto/evp/evp_pkey.c
deps/openssl/openssl/crypto/evp/evp_test.c
deps/openssl/openssl/crypto/evp/m_dss.c
deps/openssl/openssl/crypto/evp/m_dss1.c
deps/openssl/openssl/crypto/evp/m_ecdsa.c
deps/openssl/openssl/crypto/evp/m_md2.c
deps/openssl/openssl/crypto/evp/m_md4.c
deps/openssl/openssl/crypto/evp/m_md5.c
deps/openssl/openssl/crypto/evp/m_mdc2.c
deps/openssl/openssl/crypto/evp/m_sha.c
deps/openssl/openssl/crypto/evp/m_sha1.c
deps/openssl/openssl/crypto/evp/m_sigver.c [new file with mode: 0644]
deps/openssl/openssl/crypto/evp/m_wp.c [new file with mode: 0644]
deps/openssl/openssl/crypto/evp/names.c
deps/openssl/openssl/crypto/evp/p5_crpt.c
deps/openssl/openssl/crypto/evp/p5_crpt2.c
deps/openssl/openssl/crypto/evp/p_dec.c
deps/openssl/openssl/crypto/evp/p_enc.c
deps/openssl/openssl/crypto/evp/p_lib.c
deps/openssl/openssl/crypto/evp/p_open.c
deps/openssl/openssl/crypto/evp/p_seal.c
deps/openssl/openssl/crypto/evp/p_sign.c
deps/openssl/openssl/crypto/evp/p_verify.c
deps/openssl/openssl/crypto/evp/pmeth_fn.c [new file with mode: 0644]
deps/openssl/openssl/crypto/evp/pmeth_gn.c [new file with mode: 0644]
deps/openssl/openssl/crypto/evp/pmeth_lib.c [new file with mode: 0644]
deps/openssl/openssl/crypto/ex_data.c
deps/openssl/openssl/crypto/fips_err.c [deleted file]
deps/openssl/openssl/crypto/fips_err.h [deleted file]
deps/openssl/openssl/crypto/hmac/Makefile
deps/openssl/openssl/crypto/hmac/hm_ameth.c [moved from deps/openssl/openssl/crypto/evp/evp_cnf.c with 59% similarity]
deps/openssl/openssl/crypto/hmac/hm_pmeth.c [new file with mode: 0644]
deps/openssl/openssl/crypto/hmac/hmac.c
deps/openssl/openssl/crypto/hmac/hmac.h
deps/openssl/openssl/crypto/ia64cpuid.S
deps/openssl/openssl/crypto/idea/Makefile
deps/openssl/openssl/crypto/idea/i_skey.c
deps/openssl/openssl/crypto/idea/idea.h
deps/openssl/openssl/crypto/install-crypto.com [new file with mode: 0644]
deps/openssl/openssl/crypto/install.com [deleted file]
deps/openssl/openssl/crypto/jpake/Makefile
deps/openssl/openssl/crypto/jpake/jpake.c
deps/openssl/openssl/crypto/jpake/jpaketest.c
deps/openssl/openssl/crypto/krb5/Makefile
deps/openssl/openssl/crypto/lhash/Makefile
deps/openssl/openssl/crypto/lhash/lh_stats.c
deps/openssl/openssl/crypto/lhash/lhash.c
deps/openssl/openssl/crypto/lhash/lhash.h
deps/openssl/openssl/crypto/md2/Makefile
deps/openssl/openssl/crypto/md2/md2.h
deps/openssl/openssl/crypto/md2/md2_dgst.c
deps/openssl/openssl/crypto/md32_common.h
deps/openssl/openssl/crypto/md4/Makefile
deps/openssl/openssl/crypto/md4/md4.h
deps/openssl/openssl/crypto/md4/md4_dgst.c
deps/openssl/openssl/crypto/md5/Makefile
deps/openssl/openssl/crypto/md5/asm/md5-586.pl
deps/openssl/openssl/crypto/md5/asm/md5-ia64.S [new file with mode: 0644]
deps/openssl/openssl/crypto/md5/asm/md5-x86_64.pl
deps/openssl/openssl/crypto/md5/md5.h
deps/openssl/openssl/crypto/md5/md5_dgst.c
deps/openssl/openssl/crypto/md5/md5_locl.h
deps/openssl/openssl/crypto/mdc2/Makefile
deps/openssl/openssl/crypto/mdc2/mdc2.h
deps/openssl/openssl/crypto/mdc2/mdc2dgst.c
deps/openssl/openssl/crypto/mem.c
deps/openssl/openssl/crypto/mem_dbg.c
deps/openssl/openssl/crypto/modes/Makefile [new file with mode: 0644]
deps/openssl/openssl/crypto/modes/cbc128.c [new file with mode: 0644]
deps/openssl/openssl/crypto/modes/cfb128.c [new file with mode: 0644]
deps/openssl/openssl/crypto/modes/ctr128.c [new file with mode: 0644]
deps/openssl/openssl/crypto/modes/cts128.c [new file with mode: 0644]
deps/openssl/openssl/crypto/modes/modes.h [new file with mode: 0644]
deps/openssl/openssl/crypto/modes/ofb128.c [moved from deps/openssl/openssl/crypto/o_init.c with 58% similarity]
deps/openssl/openssl/crypto/o_time.c
deps/openssl/openssl/crypto/o_time.h
deps/openssl/openssl/crypto/objects/Makefile
deps/openssl/openssl/crypto/objects/o_names.c
deps/openssl/openssl/crypto/objects/obj_dat.c
deps/openssl/openssl/crypto/objects/obj_dat.h
deps/openssl/openssl/crypto/objects/obj_dat.pl
deps/openssl/openssl/crypto/objects/obj_err.c
deps/openssl/openssl/crypto/objects/obj_lib.c
deps/openssl/openssl/crypto/objects/obj_xref.c [new file with mode: 0644]
deps/openssl/openssl/crypto/objects/obj_xref.h [new file with mode: 0644]
deps/openssl/openssl/crypto/objects/obj_xref.txt [new file with mode: 0644]
deps/openssl/openssl/crypto/objects/objects.h
deps/openssl/openssl/crypto/objects/objects.pl
deps/openssl/openssl/crypto/objects/objxref.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/ocsp/Makefile
deps/openssl/openssl/crypto/ocsp/ocsp.h
deps/openssl/openssl/crypto/ocsp/ocsp_cl.c
deps/openssl/openssl/crypto/ocsp/ocsp_err.c
deps/openssl/openssl/crypto/ocsp/ocsp_ext.c
deps/openssl/openssl/crypto/ocsp/ocsp_ht.c
deps/openssl/openssl/crypto/ocsp/ocsp_lib.c
deps/openssl/openssl/crypto/ocsp/ocsp_prn.c
deps/openssl/openssl/crypto/ocsp/ocsp_vfy.c
deps/openssl/openssl/crypto/opensslconf.h.in
deps/openssl/openssl/crypto/opensslv.h
deps/openssl/openssl/crypto/ossl_typ.h
deps/openssl/openssl/crypto/pem/Makefile
deps/openssl/openssl/crypto/pem/pem.h
deps/openssl/openssl/crypto/pem/pem_all.c
deps/openssl/openssl/crypto/pem/pem_err.c
deps/openssl/openssl/crypto/pem/pem_info.c
deps/openssl/openssl/crypto/pem/pem_lib.c
deps/openssl/openssl/crypto/pem/pem_pkey.c
deps/openssl/openssl/crypto/pem/pem_x509.c
deps/openssl/openssl/crypto/pem/pem_xaux.c
deps/openssl/openssl/crypto/pem/pvkfmt.c [new file with mode: 0644]
deps/openssl/openssl/crypto/perlasm/cbc.pl
deps/openssl/openssl/crypto/perlasm/ppc-xlate.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/perlasm/x86_64-xlate.pl
deps/openssl/openssl/crypto/perlasm/x86asm.pl
deps/openssl/openssl/crypto/perlasm/x86gas.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/perlasm/x86masm.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/perlasm/x86ms.pl [deleted file]
deps/openssl/openssl/crypto/perlasm/x86nasm.pl
deps/openssl/openssl/crypto/perlasm/x86unix.pl [deleted file]
deps/openssl/openssl/crypto/pkcs12/Makefile
deps/openssl/openssl/crypto/pkcs12/p12_add.c
deps/openssl/openssl/crypto/pkcs12/p12_attr.c
deps/openssl/openssl/crypto/pkcs12/p12_crpt.c
deps/openssl/openssl/crypto/pkcs12/p12_crt.c
deps/openssl/openssl/crypto/pkcs12/p12_key.c
deps/openssl/openssl/crypto/pkcs12/p12_kiss.c
deps/openssl/openssl/crypto/pkcs12/p12_mutl.c
deps/openssl/openssl/crypto/pkcs12/p12_utl.c
deps/openssl/openssl/crypto/pkcs12/pk12err.c
deps/openssl/openssl/crypto/pkcs12/pkcs12.h
deps/openssl/openssl/crypto/pkcs7/Makefile
deps/openssl/openssl/crypto/pkcs7/bio_pk7.c [moved from deps/openssl/openssl/crypto/rc4/rc4_fblk.c with 84% similarity]
deps/openssl/openssl/crypto/pkcs7/pk7_asn1.c
deps/openssl/openssl/crypto/pkcs7/pk7_attr.c
deps/openssl/openssl/crypto/pkcs7/pk7_doit.c
deps/openssl/openssl/crypto/pkcs7/pk7_lib.c
deps/openssl/openssl/crypto/pkcs7/pk7_mime.c
deps/openssl/openssl/crypto/pkcs7/pk7_smime.c
deps/openssl/openssl/crypto/pkcs7/pkcs7.h
deps/openssl/openssl/crypto/pkcs7/pkcs7err.c
deps/openssl/openssl/crypto/ppccpuid.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/pqueue/Makefile
deps/openssl/openssl/crypto/pqueue/pq_compat.h [deleted file]
deps/openssl/openssl/crypto/pqueue/pqueue.c
deps/openssl/openssl/crypto/pqueue/pqueue.h
deps/openssl/openssl/crypto/rand/Makefile
deps/openssl/openssl/crypto/rand/md_rand.c
deps/openssl/openssl/crypto/rand/rand.h
deps/openssl/openssl/crypto/rand/rand_egd.c
deps/openssl/openssl/crypto/rand/rand_eng.c [deleted file]
deps/openssl/openssl/crypto/rand/rand_err.c
deps/openssl/openssl/crypto/rand/rand_lcl.h
deps/openssl/openssl/crypto/rand/rand_lib.c
deps/openssl/openssl/crypto/rand/rand_os2.c
deps/openssl/openssl/crypto/rand/rand_unix.c
deps/openssl/openssl/crypto/rand/rand_vms.c
deps/openssl/openssl/crypto/rand/randfile.c
deps/openssl/openssl/crypto/rc2/Makefile
deps/openssl/openssl/crypto/rc2/rc2.h
deps/openssl/openssl/crypto/rc2/rc2_skey.c
deps/openssl/openssl/crypto/rc4/Makefile
deps/openssl/openssl/crypto/rc4/asm/rc4-586.pl
deps/openssl/openssl/crypto/rc4/asm/rc4-ia64.S [deleted file]
deps/openssl/openssl/crypto/rc4/asm/rc4-ia64.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/rc4/asm/rc4-s390x.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/rc4/asm/rc4-x86_64.pl
deps/openssl/openssl/crypto/rc4/rc4.h
deps/openssl/openssl/crypto/rc4/rc4_enc.c
deps/openssl/openssl/crypto/rc4/rc4_skey.c
deps/openssl/openssl/crypto/rc4/rc4test.c
deps/openssl/openssl/crypto/rc5/Makefile
deps/openssl/openssl/crypto/rc5/asm/rc5-586.pl
deps/openssl/openssl/crypto/rc5/rc5.h
deps/openssl/openssl/crypto/rc5/rc5_locl.h
deps/openssl/openssl/crypto/rc5/rc5_skey.c
deps/openssl/openssl/crypto/ripemd/Makefile
deps/openssl/openssl/crypto/ripemd/asm/rmd-586.pl
deps/openssl/openssl/crypto/ripemd/ripemd.h
deps/openssl/openssl/crypto/ripemd/rmd_dgst.c
deps/openssl/openssl/crypto/ripemd/rmd_locl.h
deps/openssl/openssl/crypto/rsa/Makefile
deps/openssl/openssl/crypto/rsa/rsa.h
deps/openssl/openssl/crypto/rsa/rsa_ameth.c [new file with mode: 0644]
deps/openssl/openssl/crypto/rsa/rsa_asn1.c
deps/openssl/openssl/crypto/rsa/rsa_eay.c
deps/openssl/openssl/crypto/rsa/rsa_eng.c [deleted file]
deps/openssl/openssl/crypto/rsa/rsa_err.c
deps/openssl/openssl/crypto/rsa/rsa_gen.c
deps/openssl/openssl/crypto/rsa/rsa_lib.c
deps/openssl/openssl/crypto/rsa/rsa_locl.h [new file with mode: 0644]
deps/openssl/openssl/crypto/rsa/rsa_oaep.c
deps/openssl/openssl/crypto/rsa/rsa_pmeth.c [new file with mode: 0644]
deps/openssl/openssl/crypto/rsa/rsa_prn.c [moved from deps/openssl/openssl/fips/dsa/fips_dsa_lib.c with 74% similarity]
deps/openssl/openssl/crypto/rsa/rsa_pss.c
deps/openssl/openssl/crypto/rsa/rsa_sign.c
deps/openssl/openssl/crypto/rsa/rsa_test.c
deps/openssl/openssl/crypto/rsa/rsa_x931g.c [deleted file]
deps/openssl/openssl/crypto/s390xcap.c [new file with mode: 0644]
deps/openssl/openssl/crypto/s390xcpuid.S [new file with mode: 0644]
deps/openssl/openssl/crypto/seed/Makefile
deps/openssl/openssl/crypto/seed/seed.c
deps/openssl/openssl/crypto/seed/seed.h
deps/openssl/openssl/crypto/seed/seed_cbc.c
deps/openssl/openssl/crypto/seed/seed_cfb.c
deps/openssl/openssl/crypto/seed/seed_ofb.c
deps/openssl/openssl/crypto/sha/Makefile
deps/openssl/openssl/crypto/sha/asm/sha1-586.pl
deps/openssl/openssl/crypto/sha/asm/sha1-armv4-large.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/sha/asm/sha1-ppc.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/sha/asm/sha1-s390x.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/sha/asm/sha1-sparcv9.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/sha/asm/sha1-sparcv9a.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/sha/asm/sha1-thumb.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/sha/asm/sha1-x86_64.pl
deps/openssl/openssl/crypto/sha/asm/sha256-586.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/sha/asm/sha256-armv4.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/sha/asm/sha512-586.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/sha/asm/sha512-armv4.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/sha/asm/sha512-ppc.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/sha/asm/sha512-s390x.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/sha/asm/sha512-sparcv9.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/sha/asm/sha512-sse2.pl [deleted file]
deps/openssl/openssl/crypto/sha/asm/sha512-x86_64.pl
deps/openssl/openssl/crypto/sha/sha.h
deps/openssl/openssl/crypto/sha/sha1_one.c
deps/openssl/openssl/crypto/sha/sha1dgst.c
deps/openssl/openssl/crypto/sha/sha256.c
deps/openssl/openssl/crypto/sha/sha512.c
deps/openssl/openssl/crypto/sha/sha_dgst.c
deps/openssl/openssl/crypto/sha/sha_locl.h
deps/openssl/openssl/crypto/sha/shatest.c
deps/openssl/openssl/crypto/sparccpuid.S
deps/openssl/openssl/crypto/sparcv9cap.c [new file with mode: 0644]
deps/openssl/openssl/crypto/stack/Makefile
deps/openssl/openssl/crypto/stack/safestack.h
deps/openssl/openssl/crypto/stack/stack.c
deps/openssl/openssl/crypto/stack/stack.h
deps/openssl/openssl/crypto/store/Makefile
deps/openssl/openssl/crypto/store/store.h
deps/openssl/openssl/crypto/store/str_err.c
deps/openssl/openssl/crypto/store/str_lib.c
deps/openssl/openssl/crypto/store/str_mem.c
deps/openssl/openssl/crypto/symhacks.h
deps/openssl/openssl/crypto/threads/mttest.c
deps/openssl/openssl/crypto/tmdiff.c [deleted file]
deps/openssl/openssl/crypto/tmdiff.h [deleted file]
deps/openssl/openssl/crypto/ts/Makefile [new file with mode: 0644]
deps/openssl/openssl/crypto/ts/ts.h [new file with mode: 0644]
deps/openssl/openssl/crypto/ts/ts_asn1.c [new file with mode: 0644]
deps/openssl/openssl/crypto/ts/ts_conf.c [new file with mode: 0644]
deps/openssl/openssl/crypto/ts/ts_err.c [new file with mode: 0644]
deps/openssl/openssl/crypto/ts/ts_lib.c [new file with mode: 0644]
deps/openssl/openssl/crypto/ts/ts_req_print.c [moved from deps/openssl/openssl/crypto/buffer/buf_str.c with 70% similarity]
deps/openssl/openssl/crypto/ts/ts_req_utils.c [new file with mode: 0644]
deps/openssl/openssl/crypto/ts/ts_rsp_print.c [new file with mode: 0644]
deps/openssl/openssl/crypto/ts/ts_rsp_sign.c [new file with mode: 0644]
deps/openssl/openssl/crypto/ts/ts_rsp_utils.c [new file with mode: 0644]
deps/openssl/openssl/crypto/ts/ts_rsp_verify.c [new file with mode: 0644]
deps/openssl/openssl/crypto/ts/ts_verify_ctx.c [new file with mode: 0644]
deps/openssl/openssl/crypto/txt_db/Makefile
deps/openssl/openssl/crypto/txt_db/txt_db.c
deps/openssl/openssl/crypto/txt_db/txt_db.h
deps/openssl/openssl/crypto/ui/Makefile
deps/openssl/openssl/crypto/ui/ui.h
deps/openssl/openssl/crypto/ui/ui_err.c
deps/openssl/openssl/crypto/ui/ui_lib.c
deps/openssl/openssl/crypto/ui/ui_openssl.c
deps/openssl/openssl/crypto/vms_rms.h [new file with mode: 0644]
deps/openssl/openssl/crypto/whrlpool/Makefile [new file with mode: 0644]
deps/openssl/openssl/crypto/whrlpool/asm/wp-mmx.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/whrlpool/asm/wp-x86_64.pl [new file with mode: 0644]
deps/openssl/openssl/crypto/whrlpool/whrlpool.h [new file with mode: 0644]
deps/openssl/openssl/crypto/whrlpool/wp_block.c [new file with mode: 0644]
deps/openssl/openssl/crypto/whrlpool/wp_dgst.c [new file with mode: 0644]
deps/openssl/openssl/crypto/whrlpool/wp_locl.h [new file with mode: 0644]
deps/openssl/openssl/crypto/whrlpool/wp_test.c [new file with mode: 0644]
deps/openssl/openssl/crypto/x509/Makefile
deps/openssl/openssl/crypto/x509/by_dir.c
deps/openssl/openssl/crypto/x509/by_file.c
deps/openssl/openssl/crypto/x509/x509.h
deps/openssl/openssl/crypto/x509/x509_cmp.c
deps/openssl/openssl/crypto/x509/x509_err.c
deps/openssl/openssl/crypto/x509/x509_lu.c
deps/openssl/openssl/crypto/x509/x509_obj.c
deps/openssl/openssl/crypto/x509/x509_req.c
deps/openssl/openssl/crypto/x509/x509_set.c
deps/openssl/openssl/crypto/x509/x509_trs.c
deps/openssl/openssl/crypto/x509/x509_txt.c
deps/openssl/openssl/crypto/x509/x509_vfy.c
deps/openssl/openssl/crypto/x509/x509_vfy.h
deps/openssl/openssl/crypto/x509/x509_vpm.c
deps/openssl/openssl/crypto/x509/x509cset.c
deps/openssl/openssl/crypto/x509/x509name.c
deps/openssl/openssl/crypto/x509/x509type.c
deps/openssl/openssl/crypto/x509/x_all.c
deps/openssl/openssl/crypto/x509v3/Makefile
deps/openssl/openssl/crypto/x509v3/ext_dat.h
deps/openssl/openssl/crypto/x509v3/pcy_cache.c
deps/openssl/openssl/crypto/x509v3/pcy_data.c
deps/openssl/openssl/crypto/x509v3/pcy_int.h
deps/openssl/openssl/crypto/x509v3/pcy_map.c
deps/openssl/openssl/crypto/x509v3/pcy_node.c
deps/openssl/openssl/crypto/x509v3/pcy_tree.c
deps/openssl/openssl/crypto/x509v3/v3_addr.c
deps/openssl/openssl/crypto/x509v3/v3_alt.c
deps/openssl/openssl/crypto/x509v3/v3_asid.c
deps/openssl/openssl/crypto/x509v3/v3_conf.c
deps/openssl/openssl/crypto/x509v3/v3_cpols.c
deps/openssl/openssl/crypto/x509v3/v3_crld.c
deps/openssl/openssl/crypto/x509v3/v3_enum.c
deps/openssl/openssl/crypto/x509v3/v3_extku.c
deps/openssl/openssl/crypto/x509v3/v3_genn.c
deps/openssl/openssl/crypto/x509v3/v3_lib.c
deps/openssl/openssl/crypto/x509v3/v3_ncons.c
deps/openssl/openssl/crypto/x509v3/v3_ocsp.c
deps/openssl/openssl/crypto/x509v3/v3_pci.c
deps/openssl/openssl/crypto/x509v3/v3_pcons.c
deps/openssl/openssl/crypto/x509v3/v3_pmaps.c
deps/openssl/openssl/crypto/x509v3/v3_prn.c
deps/openssl/openssl/crypto/x509v3/v3_purp.c
deps/openssl/openssl/crypto/x509v3/v3_utl.c
deps/openssl/openssl/crypto/x509v3/v3err.c
deps/openssl/openssl/crypto/x509v3/x509v3.h
deps/openssl/openssl/crypto/x86_64cpuid.pl
deps/openssl/openssl/crypto/x86cpuid.pl
deps/openssl/openssl/demos/cms/cacert.pem [new file with mode: 0644]
deps/openssl/openssl/demos/cms/cakey.pem [new file with mode: 0644]
deps/openssl/openssl/demos/cms/cms_comp.c [new file with mode: 0644]
deps/openssl/openssl/demos/cms/cms_ddec.c [new file with mode: 0644]
deps/openssl/openssl/demos/cms/cms_dec.c [new file with mode: 0644]
deps/openssl/openssl/demos/cms/cms_denc.c [new file with mode: 0644]
deps/openssl/openssl/demos/cms/cms_enc.c [new file with mode: 0644]
deps/openssl/openssl/demos/cms/cms_sign.c [new file with mode: 0644]
deps/openssl/openssl/demos/cms/cms_sign2.c [new file with mode: 0644]
deps/openssl/openssl/demos/cms/cms_uncomp.c [new file with mode: 0644]
deps/openssl/openssl/demos/cms/cms_ver.c [new file with mode: 0644]
deps/openssl/openssl/demos/cms/comp.txt [new file with mode: 0644]
deps/openssl/openssl/demos/cms/encr.txt [new file with mode: 0644]
deps/openssl/openssl/demos/cms/sign.txt [new file with mode: 0644]
deps/openssl/openssl/demos/cms/signer.pem [new file with mode: 0644]
deps/openssl/openssl/demos/cms/signer2.pem [new file with mode: 0644]
deps/openssl/openssl/demos/jpake/Makefile [deleted file]
deps/openssl/openssl/demos/jpake/jpakedemo.c [deleted file]
deps/openssl/openssl/demos/pkcs12/pkread.c
deps/openssl/openssl/demos/smime/cacert.pem [new file with mode: 0644]
deps/openssl/openssl/demos/smime/cakey.pem [new file with mode: 0644]
deps/openssl/openssl/demos/smime/encr.txt [new file with mode: 0644]
deps/openssl/openssl/demos/smime/sign.txt [new file with mode: 0644]
deps/openssl/openssl/demos/smime/signer.pem [new file with mode: 0644]
deps/openssl/openssl/demos/smime/signer2.pem [new file with mode: 0644]
deps/openssl/openssl/demos/smime/smdec.c [new file with mode: 0644]
deps/openssl/openssl/demos/smime/smenc.c [new file with mode: 0644]
deps/openssl/openssl/demos/smime/smsign.c [new file with mode: 0644]
deps/openssl/openssl/demos/smime/smsign2.c [new file with mode: 0644]
deps/openssl/openssl/demos/smime/smver.c [new file with mode: 0644]
deps/openssl/openssl/demos/tunala/autoungunk.sh
deps/openssl/openssl/demos/tunala/cb.c
deps/openssl/openssl/demos/tunala/tunala.c
deps/openssl/openssl/doc/HOWTO/certificates.txt [new file with mode: 0644]
deps/openssl/openssl/doc/HOWTO/keys.txt [new file with mode: 0644]
deps/openssl/openssl/doc/HOWTO/proxy_certificates.txt [new file with mode: 0644]
deps/openssl/openssl/doc/README [new file with mode: 0644]
deps/openssl/openssl/doc/apps/CA.pl.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/asn1parse.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/ca.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/ciphers.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/cms.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/config.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/crl.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/crl2pkcs7.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/dgst.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/dhparam.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/dsa.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/dsaparam.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/ec.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/ecparam.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/enc.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/errstr.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/gendsa.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/genpkey.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/genrsa.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/nseq.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/ocsp.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/openssl.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/passwd.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/pkcs12.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/pkcs7.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/pkcs8.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/pkey.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/pkeyparam.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/pkeyutl.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/rand.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/req.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/rsa.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/rsautl.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/s_client.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/s_server.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/s_time.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/sess_id.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/smime.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/speed.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/spkac.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/ts.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/tsget.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/verify.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/version.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/x509.pod [new file with mode: 0644]
deps/openssl/openssl/doc/apps/x509v3_config.pod [new file with mode: 0644]
deps/openssl/openssl/doc/c-indentation.el [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/ASN1_OBJECT_new.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/ASN1_STRING_length.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/ASN1_STRING_new.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/ASN1_STRING_print_ex.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/ASN1_generate_nconf.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BIO_ctrl.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BIO_f_base64.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BIO_f_buffer.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BIO_f_cipher.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BIO_f_md.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BIO_f_null.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BIO_f_ssl.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BIO_find_type.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BIO_new.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BIO_new_CMS.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BIO_push.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BIO_read.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BIO_s_accept.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BIO_s_bio.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BIO_s_connect.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BIO_s_fd.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BIO_s_file.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BIO_s_mem.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BIO_s_null.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BIO_s_socket.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BIO_set_callback.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BIO_should_retry.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BN_BLINDING_new.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BN_CTX_new.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BN_CTX_start.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BN_add.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BN_add_word.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BN_bn2bin.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BN_cmp.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BN_copy.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BN_generate_prime.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BN_mod_inverse.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BN_mod_mul_montgomery.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BN_mod_mul_reciprocal.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BN_new.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BN_num_bytes.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BN_rand.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BN_set_bit.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BN_swap.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/BN_zero.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/CMS_add0_cert.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/CMS_add1_recipient_cert.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/CMS_compress.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/CMS_decrypt.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/CMS_encrypt.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/CMS_final.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/CMS_get0_RecipientInfos.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/CMS_get0_SignerInfos.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/CMS_get0_type.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/CMS_get1_ReceiptRequest.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/CMS_sign.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/CMS_sign_add1_signer.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/CMS_sign_receipt.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/CMS_uncompress.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/CMS_verify.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/CMS_verify_receipt.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/CONF_modules_free.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/CONF_modules_load_file.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/CRYPTO_set_ex_data.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/DH_generate_key.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/DH_generate_parameters.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/DH_get_ex_new_index.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/DH_new.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/DH_set_method.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/DH_size.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/DSA_SIG_new.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/DSA_do_sign.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/DSA_dup_DH.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/DSA_generate_key.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/DSA_generate_parameters.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/DSA_get_ex_new_index.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/DSA_new.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/DSA_set_method.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/DSA_sign.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/DSA_size.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/ERR_GET_LIB.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/ERR_clear_error.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/ERR_error_string.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/ERR_get_error.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/ERR_load_crypto_strings.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/ERR_load_strings.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/ERR_print_errors.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/ERR_put_error.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/ERR_remove_state.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/ERR_set_mark.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/EVP_BytesToKey.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/EVP_DigestInit.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/EVP_DigestSignInit.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/EVP_DigestVerifyInit.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/EVP_EncryptInit.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/EVP_OpenInit.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/EVP_PKEY_CTX_ctrl.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/EVP_PKEY_CTX_new.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/EVP_PKEY_cmp.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/EVP_PKEY_decrypt.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/EVP_PKEY_derive.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/EVP_PKEY_encrypt.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/EVP_PKEY_get_default_digest.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/EVP_PKEY_keygen.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/EVP_PKEY_new.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/EVP_PKEY_print_private.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/EVP_PKEY_set1_RSA.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/EVP_PKEY_sign.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/EVP_PKEY_verify.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/EVP_PKEY_verifyrecover.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/EVP_SealInit.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/EVP_SignInit.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/EVP_VerifyInit.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/OBJ_nid2obj.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/OPENSSL_Applink.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/OPENSSL_VERSION_NUMBER.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/OPENSSL_config.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/OPENSSL_ia32cap.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/OPENSSL_load_builtin_modules.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/OpenSSL_add_all_algorithms.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/PEM_write_bio_CMS_stream.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/PEM_write_bio_PKCS7_stream.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/PKCS12_create.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/PKCS12_parse.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/PKCS7_decrypt.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/PKCS7_encrypt.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/PKCS7_sign.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/PKCS7_sign_add_signer.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/PKCS7_verify.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/RAND_add.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/RAND_bytes.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/RAND_cleanup.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/RAND_egd.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/RAND_load_file.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/RAND_set_rand_method.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/RSA_blinding_on.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/RSA_check_key.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/RSA_generate_key.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/RSA_get_ex_new_index.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/RSA_new.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/RSA_padding_add_PKCS1_type_1.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/RSA_print.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/RSA_private_encrypt.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/RSA_public_encrypt.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/RSA_set_method.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/RSA_sign.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/RSA_sign_ASN1_OCTET_STRING.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/RSA_size.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/SMIME_read_CMS.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/SMIME_read_PKCS7.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/SMIME_write_CMS.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/SMIME_write_PKCS7.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/X509_NAME_ENTRY_get_object.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/X509_NAME_add_entry_by_txt.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/X509_NAME_get_index_by_NID.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/X509_NAME_print_ex.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/X509_STORE_CTX_get_error.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/X509_STORE_CTX_get_ex_new_index.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/X509_STORE_CTX_new.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/X509_STORE_CTX_set_verify_cb.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/X509_STORE_set_verify_cb_func.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/X509_VERIFY_PARAM_set_flags.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/X509_new.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/X509_verify_cert.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/bio.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/blowfish.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/bn.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/bn_internal.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/buffer.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/crypto.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/d2i_ASN1_OBJECT.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/d2i_DHparams.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/d2i_DSAPublicKey.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/d2i_PKCS8PrivateKey.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/d2i_RSAPublicKey.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/d2i_X509.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/d2i_X509_ALGOR.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/d2i_X509_CRL.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/d2i_X509_NAME.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/d2i_X509_REQ.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/d2i_X509_SIG.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/des.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/des_modes.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/dh.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/dsa.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/ecdsa.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/engine.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/err.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/evp.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/hmac.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/i2d_CMS_bio_stream.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/i2d_PKCS7_bio_stream.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/lh_stats.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/lhash.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/md5.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/mdc2.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/pem.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/rand.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/rc4.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/ripemd.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/rsa.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/sha.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/threads.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/ui.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/ui_compat.pod [new file with mode: 0644]
deps/openssl/openssl/doc/crypto/x509.pod [new file with mode: 0644]
deps/openssl/openssl/doc/fingerprints.txt [new file with mode: 0644]
deps/openssl/openssl/doc/openssl-shared.txt [new file with mode: 0644]
deps/openssl/openssl/doc/openssl.txt [new file with mode: 0644]
deps/openssl/openssl/doc/openssl_button.gif [new file with mode: 0644]
deps/openssl/openssl/doc/openssl_button.html [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CIPHER_get_name.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_COMP_add_compression_method.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_add_extra_chain_cert.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_add_session.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_ctrl.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_flush_sessions.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_free.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_get_ex_new_index.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_get_verify_mode.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_load_verify_locations.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_new.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_sess_number.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_sess_set_cache_size.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_sess_set_get_cb.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_sessions.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_set_cert_store.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_set_cert_verify_callback.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_set_cipher_list.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_set_client_CA_list.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_set_client_cert_cb.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_set_default_passwd_cb.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_set_generate_session_id.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_set_info_callback.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_set_max_cert_list.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_set_mode.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_set_msg_callback.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_set_options.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_set_psk_client_callback.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_set_quiet_shutdown.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_set_session_cache_mode.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_set_session_id_context.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_set_ssl_version.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_set_timeout.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_set_tmp_dh_callback.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_set_tmp_rsa_callback.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_set_verify.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_use_certificate.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_CTX_use_psk_identity_hint.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_SESSION_free.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_SESSION_get_ex_new_index.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_SESSION_get_time.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_accept.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_alert_type_string.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_clear.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_connect.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_do_handshake.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_free.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_get_SSL_CTX.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_get_ciphers.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_get_client_CA_list.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_get_current_cipher.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_get_default_timeout.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_get_error.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_get_ex_data_X509_STORE_CTX_idx.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_get_ex_new_index.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_get_fd.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_get_peer_cert_chain.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_get_peer_certificate.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_get_psk_identity.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_get_rbio.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_get_session.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_get_verify_result.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_get_version.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_library_init.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_load_client_CA_file.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_new.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_pending.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_read.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_rstate_string.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_session_reused.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_set_bio.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_set_connect_state.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_set_fd.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_set_session.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_set_shutdown.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_set_verify_result.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_shutdown.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_state_string.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_want.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/SSL_write.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/d2i_SSL_SESSION.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssl/ssl.pod [new file with mode: 0644]
deps/openssl/openssl/doc/ssleay.txt [new file with mode: 0644]
deps/openssl/openssl/doc/standards.txt [new file with mode: 0644]
deps/openssl/openssl/e_os.h
deps/openssl/openssl/e_os2.h
deps/openssl/openssl/engines/Makefile
deps/openssl/openssl/engines/axp.opt [new file with mode: 0644]
deps/openssl/openssl/engines/capierr.bat [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/Makefile [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/README.gost [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/e_gost_err.c [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/e_gost_err.h [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/e_gost_err.proto [moved from deps/openssl/openssl/fips/fips_locl.h with 80% similarity]
deps/openssl/openssl/engines/ccgost/gost.ec [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/gost2001.c [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/gost2001_keyx.c [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/gost2001_keyx.h [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/gost89.c [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/gost89.h [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/gost94_keyx.c [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/gost_ameth.c [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/gost_asn1.c [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/gost_crypt.c [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/gost_ctl.c [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/gost_eng.c [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/gost_keywrap.c [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/gost_keywrap.h [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/gost_lcl.h [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/gost_md.c [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/gost_params.c [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/gost_params.h [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/gost_pmeth.c [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/gost_sign.c [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/gosthash.c [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/gosthash.h [new file with mode: 0644]
deps/openssl/openssl/engines/ccgost/gostsum.c [new file with mode: 0644]
deps/openssl/openssl/engines/e_4758cca.c
deps/openssl/openssl/engines/e_aep.c
deps/openssl/openssl/engines/e_capi.c
deps/openssl/openssl/engines/e_capi_err.c
deps/openssl/openssl/engines/e_capi_err.h
deps/openssl/openssl/engines/e_chil.c
deps/openssl/openssl/engines/e_gmp.c
deps/openssl/openssl/engines/e_padlock.c [moved from deps/openssl/openssl/crypto/engine/eng_padlock.c with 98% similarity]
deps/openssl/openssl/engines/e_padlock.ec [new file with mode: 0644]
deps/openssl/openssl/engines/e_sureware.c
deps/openssl/openssl/engines/e_ubsec.c
deps/openssl/openssl/engines/makeengines.com
deps/openssl/openssl/fips/Makefile [deleted file]
deps/openssl/openssl/fips/aes/Makefile [deleted file]
deps/openssl/openssl/fips/aes/fips_aes_selftest.c [deleted file]
deps/openssl/openssl/fips/aes/fips_aesavs.c [deleted file]
deps/openssl/openssl/fips/des/Makefile [deleted file]
deps/openssl/openssl/fips/des/fips_des_selftest.c [deleted file]
deps/openssl/openssl/fips/des/fips_desmovs.c [deleted file]
deps/openssl/openssl/fips/dh/Makefile [deleted file]
deps/openssl/openssl/fips/dh/dh_gen.c [deleted file]
deps/openssl/openssl/fips/dh/fips_dh_check.c [deleted file]
deps/openssl/openssl/fips/dh/fips_dh_gen.c [deleted file]
deps/openssl/openssl/fips/dh/fips_dh_key.c [deleted file]
deps/openssl/openssl/fips/dsa/Makefile [deleted file]
deps/openssl/openssl/fips/dsa/fips_dsa_gen.c [deleted file]
deps/openssl/openssl/fips/dsa/fips_dsa_key.c [deleted file]
deps/openssl/openssl/fips/dsa/fips_dsa_ossl.c [deleted file]
deps/openssl/openssl/fips/dsa/fips_dsa_selftest.c [deleted file]
deps/openssl/openssl/fips/dsa/fips_dsa_sign.c [deleted file]
deps/openssl/openssl/fips/dsa/fips_dsatest.c [deleted file]
deps/openssl/openssl/fips/dsa/fips_dssvs.c [deleted file]
deps/openssl/openssl/fips/fips-lib.com [deleted file]
deps/openssl/openssl/fips/fips-nodiff.txt [deleted file]
deps/openssl/openssl/fips/fips.c [deleted file]
deps/openssl/openssl/fips/fips.h [deleted file]
deps/openssl/openssl/fips/fips_canister.c [deleted file]
deps/openssl/openssl/fips/fips_premain.c [deleted file]
deps/openssl/openssl/fips/fips_premain.c.sha1 [deleted file]
deps/openssl/openssl/fips/fips_test_suite.c [deleted file]
deps/openssl/openssl/fips/fips_utl.h [deleted file]
deps/openssl/openssl/fips/fipsalgtest.pl [deleted file]
deps/openssl/openssl/fips/fipsld [deleted file]
deps/openssl/openssl/fips/fipstests.bat [deleted file]
deps/openssl/openssl/fips/fipstests.sh [deleted file]
deps/openssl/openssl/fips/hmac/Makefile [deleted file]
deps/openssl/openssl/fips/hmac/fips_hmac.c [deleted file]
deps/openssl/openssl/fips/hmac/fips_hmac_selftest.c [deleted file]
deps/openssl/openssl/fips/hmac/fips_hmactest.c [deleted file]
deps/openssl/openssl/fips/install.com [deleted file]
deps/openssl/openssl/fips/mkfipsscr.pl [deleted file]
deps/openssl/openssl/fips/openssl_fips_fingerprint [deleted file]
deps/openssl/openssl/fips/rand/Makefile [deleted file]
deps/openssl/openssl/fips/rand/fips_rand.c [deleted file]
deps/openssl/openssl/fips/rand/fips_rand_selftest.c [deleted file]
deps/openssl/openssl/fips/rand/fips_randtest.c [deleted file]
deps/openssl/openssl/fips/rand/fips_rngvs.c [deleted file]
deps/openssl/openssl/fips/rsa/Makefile [deleted file]
deps/openssl/openssl/fips/rsa/fips_rsa_eay.c [deleted file]
deps/openssl/openssl/fips/rsa/fips_rsa_gen.c [deleted file]
deps/openssl/openssl/fips/rsa/fips_rsa_selftest.c [deleted file]
deps/openssl/openssl/fips/rsa/fips_rsa_sign.c [deleted file]
deps/openssl/openssl/fips/rsa/fips_rsa_x931g.c [deleted file]
deps/openssl/openssl/fips/rsa/fips_rsagtest.c [deleted file]
deps/openssl/openssl/fips/rsa/fips_rsastest.c [deleted file]
deps/openssl/openssl/fips/rsa/fips_rsavtest.c [deleted file]
deps/openssl/openssl/fips/sha/Makefile [deleted file]
deps/openssl/openssl/fips/sha/fips_sha1_selftest.c [deleted file]
deps/openssl/openssl/fips/sha/fips_shatest.c [deleted file]
deps/openssl/openssl/fips/sha/fips_standalone_sha1.c [deleted file]
deps/openssl/openssl/include/openssl/camellia.h [new file with mode: 0644]
deps/openssl/openssl/include/openssl/cms.h [new file with mode: 0644]
deps/openssl/openssl/include/openssl/fips.h [deleted file]
deps/openssl/openssl/include/openssl/fips_rand.h [deleted file]
deps/openssl/openssl/include/openssl/mdc2.h [new file with mode: 0644]
deps/openssl/openssl/include/openssl/modes.h [new file with mode: 0644]
deps/openssl/openssl/include/openssl/pq_compat.h [deleted file]
deps/openssl/openssl/include/openssl/seed.h [new file with mode: 0644]
deps/openssl/openssl/include/openssl/tmdiff.h [deleted file]
deps/openssl/openssl/include/openssl/ts.h [new file with mode: 0644]
deps/openssl/openssl/include/openssl/whrlpool.h [new file with mode: 0644]
deps/openssl/openssl/install.com
deps/openssl/openssl/makevms.com
deps/openssl/openssl/ms/README
deps/openssl/openssl/ms/bcb4.bat
deps/openssl/openssl/ms/do_fips.bat [deleted file]
deps/openssl/openssl/ms/do_masm.bat [deleted file]
deps/openssl/openssl/ms/do_nasm.bat
deps/openssl/openssl/ms/do_nt.bat
deps/openssl/openssl/ms/do_win64a.bat
deps/openssl/openssl/ms/do_win64i.bat
deps/openssl/openssl/ms/mingw32.bat
deps/openssl/openssl/ms/mw.bat
deps/openssl/openssl/ms/segrenam.pl [deleted file]
deps/openssl/openssl/ms/tenc.bat
deps/openssl/openssl/ms/tencce.bat
deps/openssl/openssl/ms/test.bat
deps/openssl/openssl/ms/testenc.bat
deps/openssl/openssl/ms/testencce.bat
deps/openssl/openssl/ms/testpem.bat
deps/openssl/openssl/ms/testpemce.bat
deps/openssl/openssl/ms/testss.bat
deps/openssl/openssl/ms/testssce.bat
deps/openssl/openssl/ms/tpem.bat
deps/openssl/openssl/ms/tpemce.bat
deps/openssl/openssl/ms/uplink-common.pl [new file with mode: 0644]
deps/openssl/openssl/ms/uplink-ia64.pl [new file with mode: 0644]
deps/openssl/openssl/ms/uplink-x86.pl [new file with mode: 0644]
deps/openssl/openssl/ms/uplink-x86_64.pl [new file with mode: 0644]
deps/openssl/openssl/ms/uplink.c
deps/openssl/openssl/ms/x86asm.bat
deps/openssl/openssl/openssl.spec
deps/openssl/openssl/shlib/win32.bat
deps/openssl/openssl/shlib/win32dll.bat
deps/openssl/openssl/ssl/Makefile
deps/openssl/openssl/ssl/bio_ssl.c
deps/openssl/openssl/ssl/d1_both.c
deps/openssl/openssl/ssl/d1_clnt.c
deps/openssl/openssl/ssl/d1_enc.c
deps/openssl/openssl/ssl/d1_lib.c
deps/openssl/openssl/ssl/d1_meth.c
deps/openssl/openssl/ssl/d1_pkt.c
deps/openssl/openssl/ssl/d1_srvr.c
deps/openssl/openssl/ssl/dtls1.h
deps/openssl/openssl/ssl/fnv1a64.c [deleted file]
deps/openssl/openssl/ssl/fnv1a64.h [deleted file]
deps/openssl/openssl/ssl/install-ssl.com [new file with mode: 0644]
deps/openssl/openssl/ssl/install.com [deleted file]
deps/openssl/openssl/ssl/kssl.c
deps/openssl/openssl/ssl/kssl_lcl.h
deps/openssl/openssl/ssl/s23_clnt.c
deps/openssl/openssl/ssl/s23_lib.c
deps/openssl/openssl/ssl/s23_meth.c
deps/openssl/openssl/ssl/s23_srvr.c
deps/openssl/openssl/ssl/s2_clnt.c
deps/openssl/openssl/ssl/s2_enc.c
deps/openssl/openssl/ssl/s2_lib.c
deps/openssl/openssl/ssl/s2_meth.c
deps/openssl/openssl/ssl/s2_pkt.c
deps/openssl/openssl/ssl/s2_srvr.c
deps/openssl/openssl/ssl/s3_both.c
deps/openssl/openssl/ssl/s3_clnt.c
deps/openssl/openssl/ssl/s3_enc.c
deps/openssl/openssl/ssl/s3_lib.c
deps/openssl/openssl/ssl/s3_meth.c
deps/openssl/openssl/ssl/s3_pkt.c
deps/openssl/openssl/ssl/s3_srvr.c
deps/openssl/openssl/ssl/ssl-lib.com
deps/openssl/openssl/ssl/ssl.h
deps/openssl/openssl/ssl/ssl3.h
deps/openssl/openssl/ssl/ssl_algs.c
deps/openssl/openssl/ssl/ssl_asn1.c
deps/openssl/openssl/ssl/ssl_cert.c
deps/openssl/openssl/ssl/ssl_ciph.c
deps/openssl/openssl/ssl/ssl_err.c
deps/openssl/openssl/ssl/ssl_lib.c
deps/openssl/openssl/ssl/ssl_locl.h
deps/openssl/openssl/ssl/ssl_rsa.c
deps/openssl/openssl/ssl/ssl_sess.c
deps/openssl/openssl/ssl/ssl_stat.c
deps/openssl/openssl/ssl/ssl_txt.c
deps/openssl/openssl/ssl/ssltest.c
deps/openssl/openssl/ssl/t1_clnt.c
deps/openssl/openssl/ssl/t1_enc.c
deps/openssl/openssl/ssl/t1_lib.c
deps/openssl/openssl/ssl/t1_meth.c
deps/openssl/openssl/ssl/t1_srvr.c
deps/openssl/openssl/ssl/tls1.h
deps/openssl/openssl/test/CAss.cnf [new file with mode: 0644]
deps/openssl/openssl/test/CAssdh.cnf [new file with mode: 0644]
deps/openssl/openssl/test/CAssdsa.cnf [new file with mode: 0644]
deps/openssl/openssl/test/CAssrsa.cnf [new file with mode: 0644]
deps/openssl/openssl/test/CAtsa.cnf [new file with mode: 0644]
deps/openssl/openssl/test/Makefile [new file with mode: 0644]
deps/openssl/openssl/test/P1ss.cnf [new file with mode: 0644]
deps/openssl/openssl/test/P2ss.cnf [new file with mode: 0644]
deps/openssl/openssl/test/Sssdsa.cnf [new file with mode: 0644]
deps/openssl/openssl/test/Sssrsa.cnf [new file with mode: 0644]
deps/openssl/openssl/test/Uss.cnf [new file with mode: 0644]
deps/openssl/openssl/test/VMSca-response.1 [new file with mode: 0644]
deps/openssl/openssl/test/VMSca-response.2 [new file with mode: 0644]
deps/openssl/openssl/test/asn1test.c [new file with mode: 0644]
deps/openssl/openssl/test/bctest [new file with mode: 0755]
deps/openssl/openssl/test/bctest.com [new file with mode: 0644]
deps/openssl/openssl/test/bftest.c [new symlink]
deps/openssl/openssl/test/bntest.c [new symlink]
deps/openssl/openssl/test/bntest.com [new file with mode: 0644]
deps/openssl/openssl/test/casttest.c [new symlink]
deps/openssl/openssl/test/clean_test.com [new file with mode: 0644]
deps/openssl/openssl/test/cms-examples.pl [new file with mode: 0644]
deps/openssl/openssl/test/cms-test.pl [new file with mode: 0644]
deps/openssl/openssl/test/destest.c [new symlink]
deps/openssl/openssl/test/dhtest.c [new symlink]
deps/openssl/openssl/test/dsatest.c [new symlink]
deps/openssl/openssl/test/dummytest.c [new file with mode: 0644]
deps/openssl/openssl/test/ecdhtest.c [new symlink]
deps/openssl/openssl/test/ecdsatest.c [new symlink]
deps/openssl/openssl/test/ectest.c [new symlink]
deps/openssl/openssl/test/enginetest.c [new symlink]
deps/openssl/openssl/test/evp_test.c [new symlink]
deps/openssl/openssl/test/evptests.txt [new file with mode: 0644]
deps/openssl/openssl/test/exptest.c [new symlink]
deps/openssl/openssl/test/fips_aesavs.c [new symlink]
deps/openssl/openssl/test/fips_desmovs.c [new symlink]
deps/openssl/openssl/test/fips_dsatest.c [new symlink]
deps/openssl/openssl/test/fips_dssvs.c [new symlink]
deps/openssl/openssl/test/fips_hmactest.c [new symlink]
deps/openssl/openssl/test/fips_randtest.c [new symlink]
deps/openssl/openssl/test/fips_rngvs.c [new symlink]
deps/openssl/openssl/test/fips_rsagtest.c [new symlink]
deps/openssl/openssl/test/fips_rsastest.c [new symlink]
deps/openssl/openssl/test/fips_rsavtest.c [new symlink]
deps/openssl/openssl/test/fips_shatest.c [new symlink]
deps/openssl/openssl/test/fips_test_suite.c [new symlink]
deps/openssl/openssl/test/hmactest.c [new symlink]
deps/openssl/openssl/test/ideatest.c [new symlink]
deps/openssl/openssl/test/igetest.c [new file with mode: 0644]
deps/openssl/openssl/test/jpaketest.c [new symlink]
deps/openssl/openssl/test/maketests.com [new file with mode: 0644]
deps/openssl/openssl/test/md2test.c [new symlink]
deps/openssl/openssl/test/md4test.c [new symlink]
deps/openssl/openssl/test/md5test.c [new symlink]
deps/openssl/openssl/test/mdc2test.c [new symlink]
deps/openssl/openssl/test/methtest.c [moved from deps/openssl/openssl/crypto/dsa/dsa_utl.c with 72% similarity]
deps/openssl/openssl/test/pkcs7-1.pem [new file with mode: 0644]
deps/openssl/openssl/test/pkcs7.pem [new file with mode: 0644]
deps/openssl/openssl/test/pkits-test.pl [new file with mode: 0644]
deps/openssl/openssl/test/r160test.c [moved from deps/openssl/openssl/crypto/err/err_bio.c with 89% similarity]
deps/openssl/openssl/test/randtest.c [new symlink]
deps/openssl/openssl/test/rc2test.c [new symlink]
deps/openssl/openssl/test/rc4test.c [new symlink]
deps/openssl/openssl/test/rc5test.c [new symlink]
deps/openssl/openssl/test/rmdtest.c [new symlink]
deps/openssl/openssl/test/rsa_test.c [new symlink]
deps/openssl/openssl/test/sha1test.c [new symlink]
deps/openssl/openssl/test/sha256t.c [new symlink]
deps/openssl/openssl/test/sha512t.c [new symlink]
deps/openssl/openssl/test/shatest.c [new symlink]
deps/openssl/openssl/test/smcont.txt [new file with mode: 0644]
deps/openssl/openssl/test/smime-certs/smdsa1.pem [new file with mode: 0644]
deps/openssl/openssl/test/smime-certs/smdsa2.pem [new file with mode: 0644]
deps/openssl/openssl/test/smime-certs/smdsa3.pem [new file with mode: 0644]
deps/openssl/openssl/test/smime-certs/smdsap.pem [new file with mode: 0644]
deps/openssl/openssl/test/smime-certs/smroot.pem [new file with mode: 0644]
deps/openssl/openssl/test/smime-certs/smrsa1.pem [new file with mode: 0644]
deps/openssl/openssl/test/smime-certs/smrsa2.pem [new file with mode: 0644]
deps/openssl/openssl/test/smime-certs/smrsa3.pem [new file with mode: 0644]
deps/openssl/openssl/test/ssltest.c [new symlink]
deps/openssl/openssl/test/tcrl [new file with mode: 0644]
deps/openssl/openssl/test/tcrl.com [new file with mode: 0644]
deps/openssl/openssl/test/test.cnf [new file with mode: 0644]
deps/openssl/openssl/test/test_padlock [new file with mode: 0644]
deps/openssl/openssl/test/testca [new file with mode: 0644]
deps/openssl/openssl/test/testca.com [new file with mode: 0644]
deps/openssl/openssl/test/testcrl.pem [new file with mode: 0644]
deps/openssl/openssl/test/testenc [new file with mode: 0644]
deps/openssl/openssl/test/testenc.com [new file with mode: 0644]
deps/openssl/openssl/test/testgen [new file with mode: 0644]
deps/openssl/openssl/test/testgen.com [new file with mode: 0644]
deps/openssl/openssl/test/testp7.pem [new file with mode: 0644]
deps/openssl/openssl/test/testreq2.pem [new file with mode: 0644]
deps/openssl/openssl/test/testrsa.pem [new file with mode: 0644]
deps/openssl/openssl/test/tests.com [new file with mode: 0644]
deps/openssl/openssl/test/testsid.pem [new file with mode: 0644]
deps/openssl/openssl/test/testss [new file with mode: 0644]
deps/openssl/openssl/test/testss.com [new file with mode: 0644]
deps/openssl/openssl/test/testssl [new file with mode: 0644]
deps/openssl/openssl/test/testssl.com [new file with mode: 0644]
deps/openssl/openssl/test/testsslproxy [new file with mode: 0644]
deps/openssl/openssl/test/testtsa [new file with mode: 0644]
deps/openssl/openssl/test/testtsa.com [new file with mode: 0644]
deps/openssl/openssl/test/testx509.pem [new file with mode: 0644]
deps/openssl/openssl/test/times [new file with mode: 0644]
deps/openssl/openssl/test/tpkcs7 [new file with mode: 0644]
deps/openssl/openssl/test/tpkcs7.com [new file with mode: 0644]
deps/openssl/openssl/test/tpkcs7d [new file with mode: 0644]
deps/openssl/openssl/test/tpkcs7d.com [new file with mode: 0644]
deps/openssl/openssl/test/treq [new file with mode: 0644]
deps/openssl/openssl/test/treq.com [new file with mode: 0644]
deps/openssl/openssl/test/trsa [new file with mode: 0644]
deps/openssl/openssl/test/trsa.com [new file with mode: 0644]
deps/openssl/openssl/test/tsid [new file with mode: 0644]
deps/openssl/openssl/test/tsid.com [new file with mode: 0644]
deps/openssl/openssl/test/tverify.com [new file with mode: 0644]
deps/openssl/openssl/test/tx509 [new file with mode: 0644]
deps/openssl/openssl/test/tx509.com [new file with mode: 0644]
deps/openssl/openssl/test/v3-cert1.pem [new file with mode: 0644]
deps/openssl/openssl/test/v3-cert2.pem [new file with mode: 0644]
deps/openssl/openssl/test/wp_test.c [new file with mode: 0644]
deps/openssl/openssl/times/090/586-100.nt [new file with mode: 0644]
deps/openssl/openssl/times/091/486-50.nt [new file with mode: 0644]
deps/openssl/openssl/times/091/586-100.lnx [new file with mode: 0644]
deps/openssl/openssl/times/091/68000.bsd [new file with mode: 0644]
deps/openssl/openssl/times/091/686-200.lnx [new file with mode: 0644]
deps/openssl/openssl/times/091/alpha064.osf [new file with mode: 0644]
deps/openssl/openssl/times/091/alpha164.lnx [new file with mode: 0644]
deps/openssl/openssl/times/091/alpha164.osf [new file with mode: 0644]
deps/openssl/openssl/times/091/mips-rel.pl [new file with mode: 0644]
deps/openssl/openssl/times/091/r10000.irx [new file with mode: 0644]
deps/openssl/openssl/times/091/r3000.ult [new file with mode: 0644]
deps/openssl/openssl/times/091/r4400.irx [new file with mode: 0644]
deps/openssl/openssl/times/100.lnx [new file with mode: 0644]
deps/openssl/openssl/times/100.nt [new file with mode: 0644]
deps/openssl/openssl/times/200.lnx [new file with mode: 0644]
deps/openssl/openssl/times/486-66.dos [new file with mode: 0644]
deps/openssl/openssl/times/486-66.nt [new file with mode: 0644]
deps/openssl/openssl/times/486-66.w31 [new file with mode: 0644]
deps/openssl/openssl/times/5.lnx [new file with mode: 0644]
deps/openssl/openssl/times/586-085i.nt [new file with mode: 0644]
deps/openssl/openssl/times/586-100.LN3 [new file with mode: 0644]
deps/openssl/openssl/times/586-100.NT2 [new file with mode: 0644]
deps/openssl/openssl/times/586-100.dos [new file with mode: 0644]
deps/openssl/openssl/times/586-100.ln4 [new file with mode: 0644]
deps/openssl/openssl/times/586-100.lnx [new file with mode: 0644]
deps/openssl/openssl/times/586-100.nt [new file with mode: 0644]
deps/openssl/openssl/times/586-100.ntx [new file with mode: 0644]
deps/openssl/openssl/times/586-100.w31 [new file with mode: 0644]
deps/openssl/openssl/times/586-1002.lnx [new file with mode: 0644]
deps/openssl/openssl/times/586p-100.lnx [new file with mode: 0644]
deps/openssl/openssl/times/686-200.bsd [new file with mode: 0644]
deps/openssl/openssl/times/686-200.lnx [new file with mode: 0644]
deps/openssl/openssl/times/686-200.nt [new file with mode: 0644]
deps/openssl/openssl/times/L1 [new file with mode: 0644]
deps/openssl/openssl/times/R10000.t [new file with mode: 0644]
deps/openssl/openssl/times/R4400.t [new file with mode: 0644]
deps/openssl/openssl/times/aix.t [new file with mode: 0644]
deps/openssl/openssl/times/aixold.t [new file with mode: 0644]
deps/openssl/openssl/times/alpha.t [new file with mode: 0644]
deps/openssl/openssl/times/alpha400.t [new file with mode: 0644]
deps/openssl/openssl/times/cyrix100.lnx [new file with mode: 0644]
deps/openssl/openssl/times/dgux-x86.t [new file with mode: 0644]
deps/openssl/openssl/times/dgux.t [new file with mode: 0644]
deps/openssl/openssl/times/hpux-acc.t [new file with mode: 0644]
deps/openssl/openssl/times/hpux-kr.t [new file with mode: 0644]
deps/openssl/openssl/times/hpux.t [new file with mode: 0644]
deps/openssl/openssl/times/p2.w95 [new file with mode: 0644]
deps/openssl/openssl/times/pent2.t [new file with mode: 0644]
deps/openssl/openssl/times/readme [new file with mode: 0644]
deps/openssl/openssl/times/s586-100.lnx [new file with mode: 0644]
deps/openssl/openssl/times/s586-100.nt [new file with mode: 0644]
deps/openssl/openssl/times/sgi.t [new file with mode: 0644]
deps/openssl/openssl/times/sparc.t [new file with mode: 0644]
deps/openssl/openssl/times/sparc2 [new file with mode: 0644]
deps/openssl/openssl/times/sparcLX.t [new file with mode: 0644]
deps/openssl/openssl/times/usparc.t [new file with mode: 0644]
deps/openssl/openssl/times/x86/bfs.cpp [new file with mode: 0644]
deps/openssl/openssl/times/x86/casts.cpp [new file with mode: 0644]
deps/openssl/openssl/times/x86/des3s.cpp [new file with mode: 0644]
deps/openssl/openssl/times/x86/dess.cpp [new file with mode: 0644]
deps/openssl/openssl/times/x86/md4s.cpp [new file with mode: 0644]
deps/openssl/openssl/times/x86/md5s.cpp [new file with mode: 0644]
deps/openssl/openssl/times/x86/rc4s.cpp [new file with mode: 0644]
deps/openssl/openssl/times/x86/sha1s.cpp [moved from deps/openssl/openssl/crypto/sha/sha1s.cpp with 92% similarity]
deps/openssl/openssl/tools/Makefile
deps/openssl/openssl/tools/c_rehash
deps/openssl/openssl/tools/c_rehash.in
deps/openssl/openssl/util/FreeBSD.sh [new file with mode: 0755]
deps/openssl/openssl/util/add_cr.pl [moved from deps/openssl/openssl/crypto/des/des_lib.c with 73% similarity, mode: 0755]
deps/openssl/openssl/util/bat.sh [new file with mode: 0755]
deps/openssl/openssl/util/ck_errf.pl [new file with mode: 0755]
deps/openssl/openssl/util/clean-depend.pl [new file with mode: 0755]
deps/openssl/openssl/util/copy.pl [new file with mode: 0644]
deps/openssl/openssl/util/cygwin.sh [new file with mode: 0755]
deps/openssl/openssl/util/deleof.pl [new file with mode: 0755]
deps/openssl/openssl/util/deltree.com [new file with mode: 0644]
deps/openssl/openssl/util/dirname.pl [new file with mode: 0644]
deps/openssl/openssl/util/do_ms.sh [new file with mode: 0755]
deps/openssl/openssl/util/domd [new file with mode: 0755]
deps/openssl/openssl/util/err-ins.pl [new file with mode: 0755]
deps/openssl/openssl/util/extract-names.pl [new file with mode: 0644]
deps/openssl/openssl/util/extract-section.pl [new file with mode: 0644]
deps/openssl/openssl/util/files.pl [new file with mode: 0755]
deps/openssl/openssl/util/fixNT.sh [new file with mode: 0755]
deps/openssl/openssl/util/install.sh [new file with mode: 0755]
deps/openssl/openssl/util/libeay.num [new file with mode: 0755]
deps/openssl/openssl/util/mk1mf.pl [new file with mode: 0755]
deps/openssl/openssl/util/mkcerts.sh [new file with mode: 0755]
deps/openssl/openssl/util/mkdef.pl [new file with mode: 0755]
deps/openssl/openssl/util/mkdir-p.pl [new file with mode: 0755]
deps/openssl/openssl/util/mkerr.pl [new file with mode: 0644]
deps/openssl/openssl/util/mkfiles.pl [new file with mode: 0755]
deps/openssl/openssl/util/mklink.pl [new file with mode: 0755]
deps/openssl/openssl/util/mkrc.pl [new file with mode: 0644]
deps/openssl/openssl/util/mkstack.pl [new file with mode: 0755]
deps/openssl/openssl/util/opensslwrap.sh [new file with mode: 0755]
deps/openssl/openssl/util/perlpath.pl [new file with mode: 0755]
deps/openssl/openssl/util/pl/BC-32.pl [new file with mode: 0644]
deps/openssl/openssl/util/pl/Mingw32.pl [new file with mode: 0644]
deps/openssl/openssl/util/pl/OS2-EMX.pl [new file with mode: 0644]
deps/openssl/openssl/util/pl/VC-32.pl [new file with mode: 0644]
deps/openssl/openssl/util/pl/linux.pl [new file with mode: 0644]
deps/openssl/openssl/util/pl/netware.pl [new file with mode: 0644]
deps/openssl/openssl/util/pl/ultrix.pl [new file with mode: 0644]
deps/openssl/openssl/util/pl/unix.pl [new file with mode: 0644]
deps/openssl/openssl/util/pod2man.pl [new file with mode: 0755]
deps/openssl/openssl/util/pod2mantest [new file with mode: 0755]
deps/openssl/openssl/util/pod2mantest.pod [new file with mode: 0644]
deps/openssl/openssl/util/point.sh [new file with mode: 0755]
deps/openssl/openssl/util/selftest.pl [new file with mode: 0644]
deps/openssl/openssl/util/shlib_wrap.sh [new file with mode: 0755]
deps/openssl/openssl/util/sp-diff.pl [new file with mode: 0755]
deps/openssl/openssl/util/speed.sh [new file with mode: 0755]
deps/openssl/openssl/util/src-dep.pl [new file with mode: 0755]
deps/openssl/openssl/util/ssleay.num [new file with mode: 0755]
deps/openssl/openssl/util/tab_num.pl [new file with mode: 0755]
deps/openssl/openssl/util/x86asm.sh [new file with mode: 0755]
deps/openssl/patches/empty_OPENSSL_cpuid_setup.patch [new file with mode: 0644]
deps/openssl/patches/handshake_cutthrough.patch
deps/openssl/patches/jsse.patch [new file with mode: 0644]
deps/openssl/patches/missing_stddef.patch [deleted file]
deps/openssl/patches/npn.patch [moved from deps/openssl/patches/next_proto_neg.patch with 58% similarity]
deps/openssl/patches/openssl_no_dtls1.patch [new file with mode: 0644]
deps/openssl/patches/posix_c_source.patch [deleted file]
deps/openssl/patches/progs.patch [new file with mode: 0644]
deps/openssl/patches/sha1_armv4_large.patch [new file with mode: 0644]
deps/openssl/patches/small_records.patch [new file with mode: 0644]
deps/openssl/patches/snap_start.patch [deleted file]
deps/openssl/patches/tls_exporter.patch [new file with mode: 0755]
deps/openssl/patches/x509_hash_name_algorithm_change.patch [new file with mode: 0644]

index 8364775..aec361b 100644 (file)
@@ -1,20 +1,34 @@
 Name: openssl
 URL: http://openssl.org/source/
-Version: 0.9.8o
+Version: 1.0.0f
 License: BSDish
 License File: openssl/LICENSE
 
 Description:
-This is OpenSSL, the standard SSL/TLS library, which is used only for testing.
+This is OpenSSL, the standard SSL/TLS library, which is used only in Android.
+
 It's an unmodified, upstream source except for the patches listed below.
 
 
-Patches are applied in this order:
+********************************************************************************
+The following patches are taken from Android Open Source Project.
+
+
+progs.patch:
 
-missing_stddef.patch
+Fixup sources under the apps/ directory that are not built under the android environment.
 
-Add stddef.h to header files which use size_t, otherwise apps that include
-those headers get compiler errors.
+
+small_records.patch:
+
+Reduce OpenSSL memory consumption.
+SSL records may be as large as 16K, but are typically < 2K.  In
+addition, a historic bug in Windows allowed records to be as large
+32K.  OpenSSL statically allocates read and write buffers (34K and
+18K respectively) used for processing records.
+With this patch, OpenSSL statically allocates 4K + 4K buffers, with
+the option of dynamically growing buffers to 34K + 4K, which is a
+saving of 44K per connection for the typical case.
 
 
 handshake_cutthrough.patch
@@ -25,24 +39,58 @@ clients can negotiate SSL connections in 1-RTT even when performing
 full-handshakes.
 
 
-next_proto_neg.patch
+jsse.patch
+
+Support for JSSE implementation based on OpenSSL.
+
+
+npn.patch
+
+Transport Layer Security (TLS) Next Protocol Negotiation Extension
+
+
+sha1_armv4_large.patch
+
+This patch eliminates memory stores to addresses below SP.
+
+
+openssl_no_dtls1.patch
+
+Add missing #ifndef OPENSSL_NO_DTLS1
+
+
+********************************************************************************
+The following patches are needed to compile this openssl on Chromium and pass
+the related net unit tests.
+
+
+empty_OPENSSL_cpuid_setup.patch
+
+Use a empty implementation for function OPENSSL_cpuid_setup to resolve link
+error. We should figure out how to geenrate platform specific implementation
+of OPENSSL_cpuid_setup by leveraging crypto/*cpuid.pl.
+
 
-Adds next-protocol-negotation support:
-  http://tools.ietf.org/html/draft-agl-tls-nextprotoneg-00
+x509_hash_name_algorithm_change.patch
 
-EXPERIMENTAL: this patches uses extension and handshake numbers that are not
-assigned by IANA.
+There are many symbolic links under /etc/ssl/certs created by using hash of
+the pem certificates in order for OpenSSL to find those certificate.
+Openssl has a tool to help you create hash symbolic links. (See tools/c_rehash)
+However the new openssl changed the hash algorithm, Unless you compile/install
+the latest openssl library and re-create all related symbolic links, the new
+openssl can not find some certificates because the links of those certificates
+were created by using old hash algorithm, which causes some tests failed.
+This patch gives a way to find a certificate according to its hash by using both
+new algorithm and old algorithm.
+crbug.com/111045 is used to track this issue.
 
-This patch implements server and client side support. Additionally, it includes
-code that assumes the structure of the 'opaque' protocol strings in the draft.
 
+tls_exporter.patch
 
-snap_start.patch
+Keying Material Exporters for Transport Layer Security (RFC 5705).
 
-Adds server-side support for Snap Start. This allows for 0-RTT handshakes in
-the case that the application protocol involves the client side speaking first.
 
-http://tools.ietf.org/html/draft-agl-tls-snapstart-00
+Android platform support
 
-EXPERIMENTAL: this patches uses an extension number that is not assigned by
-IANA.
+Copy config/android/openssl/opensslconf.h from Android's
+external/openssl/include/openssl/opensslconf.h
@@ -5,17 +5,8 @@
 #ifndef OPENSSL_DOING_MAKEDEPEND
 
 
-#ifndef OPENSSL_NO_CAMELLIA
-# define OPENSSL_NO_CAMELLIA
-#endif
-#ifndef OPENSSL_NO_CAPIENG
-# define OPENSSL_NO_CAPIENG
-#endif
-#ifndef OPENSSL_NO_CMS
-# define OPENSSL_NO_CMS
-#endif
-#ifndef OPENSSL_NO_FIPS
-# define OPENSSL_NO_FIPS
+#ifndef OPENSSL_NO_CAST
+# define OPENSSL_NO_CAST
 #endif
 #ifndef OPENSSL_NO_GMP
 # define OPENSSL_NO_GMP
@@ -29,8 +20,8 @@
 #ifndef OPENSSL_NO_KRB5
 # define OPENSSL_NO_KRB5
 #endif
-#ifndef OPENSSL_NO_MDC2
-# define OPENSSL_NO_MDC2
+#ifndef OPENSSL_NO_MD2
+# define OPENSSL_NO_MD2
 #endif
 #ifndef OPENSSL_NO_RC5
 # define OPENSSL_NO_RC5
 #ifndef OPENSSL_NO_SEED
 # define OPENSSL_NO_SEED
 #endif
-#ifndef OPENSSL_NO_ASM
-# define OPENSSL_NO_ASM
+#ifndef OPENSSL_NO_SHA0
+# define OPENSSL_NO_SHA0
+#endif
+#ifndef OPENSSL_NO_STORE
+# define OPENSSL_NO_STORE
+#endif
+#ifndef OPENSSL_NO_WHRLPOOL
+# define OPENSSL_NO_WHRLPOOL
 #endif
 
 #endif /* OPENSSL_DOING_MAKEDEPEND */
    who haven't had the time to do the appropriate changes in their
    applications.  */
 #ifdef OPENSSL_ALGORITHM_DEFINES
-# if defined(OPENSSL_NO_CAMELLIA) && !defined(NO_CAMELLIA)
-#  define NO_CAMELLIA
-# endif
-# if defined(OPENSSL_NO_CAPIENG) && !defined(NO_CAPIENG)
-#  define NO_CAPIENG
-# endif
-# if defined(OPENSSL_NO_CMS) && !defined(NO_CMS)
-#  define NO_CMS
-# endif
-# if defined(OPENSSL_NO_FIPS) && !defined(NO_FIPS)
-#  define NO_FIPS
+# if defined(OPENSSL_NO_CAST) && !defined(NO_CAST)
+#  define NO_CAST
 # endif
 # if defined(OPENSSL_NO_GMP) && !defined(NO_GMP)
 #  define NO_GMP
@@ -83,8 +71,8 @@
 # if defined(OPENSSL_NO_KRB5) && !defined(NO_KRB5)
 #  define NO_KRB5
 # endif
-# if defined(OPENSSL_NO_MDC2) && !defined(NO_MDC2)
-#  define NO_MDC2
+# if defined(OPENSSL_NO_MD2) && !defined(NO_MD2)
+#  define NO_MD2
 # endif
 # if defined(OPENSSL_NO_RC5) && !defined(NO_RC5)
 #  define NO_RC5
 # if defined(OPENSSL_NO_SEED) && !defined(NO_SEED)
 #  define NO_SEED
 # endif
+# if defined(OPENSSL_NO_SHA0) && !defined(NO_SHA0)
+#  define NO_SHA0
+# endif
+# if defined(OPENSSL_NO_STORE) && !defined(NO_STORE)
+#  define NO_STORE
+# endif
+# if defined(OPENSSL_NO_WHRLPOOL) && !defined(NO_WHRLPOOL)
+#  define NO_WHRLPOOL
+# endif
 #endif
 
-#define OPENSSL_CPUID_OBJ
-
 /* crypto/opensslconf.h.in */
 
-#ifdef OPENSSL_DOING_MAKEDEPEND
-
-/* Include any symbols here that have to be explicitly set to enable a feature
- * that should be visible to makedepend.
- *
- * [Our "make depend" doesn't actually look at this, we use actual build settings
- * instead; we want to make it easy to remove subdirectories with disabled algorithms.]
- */
-
-#ifndef OPENSSL_FIPS
-#define OPENSSL_FIPS
-#endif
-
-#endif
-
 /* Generate 80386 code? */
 #undef I386_ONLY
 
 
 #undef OPENSSL_UNISTD
 #define OPENSSL_UNISTD <unistd.h>
-#if !defined(SWIG)
-#include <unistd.h>
-#endif
 
 #undef OPENSSL_EXPORT_VAR_AS_FUNCTION
 
  * - Intel P6 because partial register stalls are very expensive;
  * - elder Alpha because it lacks byte load/store instructions;
  */
-#define RC4_INT unsigned int
+#define RC4_INT unsigned char
 #endif
 #if !defined(RC4_CHUNK)
 /*
 
 #if defined(HEADER_BN_H) && !defined(CONFIG_HEADER_BN_H)
 #define CONFIG_HEADER_BN_H
-#undef BN_LLONG
+#define BN_LLONG
 
 /* Should we define BN_DIV2W here? */
 
 /* Only one for the following should be defined */
-/* The prime number generation stuff may not work when
- * EIGHT_BIT but I don't care since I've only used this mode
- * for debuging the bignum libraries */
-#define SIXTY_FOUR_BIT_LONG
+#undef SIXTY_FOUR_BIT_LONG
 #undef SIXTY_FOUR_BIT
-#undef THIRTY_TWO_BIT
-#undef SIXTEEN_BIT
-#undef EIGHT_BIT
+#define THIRTY_TWO_BIT
 #endif
 
 #if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H)
 
 #if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H)
 #define CONFIG_HEADER_BF_LOCL_H
-#undef BF_PTR
+#define BF_PTR
 #endif /* HEADER_BF_LOCL_H */
 
 #if defined(HEADER_DES_LOCL_H) && !defined(CONFIG_HEADER_DES_LOCL_H)
diff --git a/deps/openssl/config/k8/openssl/opensslconf-win32.h b/deps/openssl/config/k8/openssl/opensslconf-win32.h
deleted file mode 100644 (file)
index c57a235..0000000
+++ /dev/null
@@ -1,262 +0,0 @@
-/* opensslconf.h */
-/* WARNING: Generated automatically from opensslconf.h.in by Configure. */
-
-/* OpenSSL was configured with the following options: */
-#ifndef OPENSSL_SYSNAME_WIN32
-# define OPENSSL_SYSNAME_WIN32
-#endif
-#ifndef OPENSSL_DOING_MAKEDEPEND
-
-
-#ifndef OPENSSL_NO_CAMELLIA
-# define OPENSSL_NO_CAMELLIA
-#endif
-#ifndef OPENSSL_NO_CAPIENG
-# define OPENSSL_NO_CAPIENG
-#endif
-#ifndef OPENSSL_NO_CMS
-# define OPENSSL_NO_CMS
-#endif
-#ifndef OPENSSL_NO_GMP
-# define OPENSSL_NO_GMP
-#endif
-#ifndef OPENSSL_NO_IDEA
-# define OPENSSL_NO_IDEA
-#endif
-#ifndef OPENSSL_NO_JPAKE
-# define OPENSSL_NO_JPAKE
-#endif
-#ifndef OPENSSL_NO_KRB5
-# define OPENSSL_NO_KRB5
-#endif
-#ifndef OPENSSL_NO_MDC2
-# define OPENSSL_NO_MDC2
-#endif
-#ifndef OPENSSL_NO_RC5
-# define OPENSSL_NO_RC5
-#endif
-#ifndef OPENSSL_NO_RFC3779
-# define OPENSSL_NO_RFC3779
-#endif
-#ifndef OPENSSL_NO_SEED
-# define OPENSSL_NO_SEED
-#endif
-
-#endif /* OPENSSL_DOING_MAKEDEPEND */
-
-#ifndef OPENSSL_THREADS
-# define OPENSSL_THREADS
-#endif
-
-/* The OPENSSL_NO_* macros are also defined as NO_* if the application
-   asks for it.  This is a transient feature that is provided for those
-   who haven't had the time to do the appropriate changes in their
-   applications.  */
-#ifdef OPENSSL_ALGORITHM_DEFINES
-# if defined(OPENSSL_NO_CAMELLIA) && !defined(NO_CAMELLIA)
-#  define NO_CAMELLIA
-# endif
-# if defined(OPENSSL_NO_CAPIENG) && !defined(NO_CAPIENG)
-#  define NO_CAPIENG
-# endif
-# if defined(OPENSSL_NO_CMS) && !defined(NO_CMS)
-#  define NO_CMS
-# endif
-# if defined(OPENSSL_NO_GMP) && !defined(NO_GMP)
-#  define NO_GMP
-# endif
-# if defined(OPENSSL_NO_JPAKE) && !defined(NO_JPAKE)
-#  define NO_JPAKE
-# endif
-# if defined(OPENSSL_NO_KRB5) && !defined(NO_KRB5)
-#  define NO_KRB5
-# endif
-# if defined(OPENSSL_NO_MDC2) && !defined(NO_MDC2)
-#  define NO_MDC2
-# endif
-# if defined(OPENSSL_NO_RC5) && !defined(NO_RC5)
-#  define NO_RC5
-# endif
-# if defined(OPENSSL_NO_RFC3779) && !defined(NO_RFC3779)
-#  define NO_RFC3779
-# endif
-# if defined(OPENSSL_NO_SEED) && !defined(NO_SEED)
-#  define NO_SEED
-# endif
-#endif
-
-/* crypto/opensslconf.h.in */
-
-#ifdef OPENSSL_DOING_MAKEDEPEND
-
-/* Include any symbols here that have to be explicitly set to enable a feature
- * that should be visible to makedepend.
- *
- * [Our "make depend" doesn't actually look at this, we use actual build settings
- * instead; we want to make it easy to remove subdirectories with disabled algorithms.]
- */
-
-#ifndef OPENSSL_FIPS
-#define OPENSSL_FIPS
-#endif
-
-#endif
-
-/* Generate 80386 code? */
-#undef I386_ONLY
-
-#if !(defined(VMS) || defined(__VMS)) /* VMS uses logical names instead */
-#if defined(HEADER_CRYPTLIB_H) && !defined(OPENSSLDIR)
-#define ENGINESDIR "ssl/lib/engines"
-#define OPENSSLDIR "ssl"
-#endif
-#endif
-
-#undef OPENSSL_UNISTD
-#define OPENSSL_UNISTD <unistd.h>
-
-#undef OPENSSL_EXPORT_VAR_AS_FUNCTION
-#define OPENSSL_EXPORT_VAR_AS_FUNCTION
-
-#if defined(HEADER_IDEA_H) && !defined(IDEA_INT)
-#define IDEA_INT unsigned int
-#endif
-
-#if defined(HEADER_MD2_H) && !defined(MD2_INT)
-#define MD2_INT unsigned int
-#endif
-
-#if defined(HEADER_RC2_H) && !defined(RC2_INT)
-/* I need to put in a mod for the alpha - eay */
-#define RC2_INT unsigned int
-#endif
-
-#if defined(HEADER_RC4_H)
-#if !defined(RC4_INT)
-/* using int types make the structure larger but make the code faster
- * on most boxes I have tested - up to %20 faster. */
-/*
- * I don't know what does "most" mean, but declaring "int" is a must on:
- * - Intel P6 because partial register stalls are very expensive;
- * - elder Alpha because it lacks byte load/store instructions;
- */
-#define RC4_INT unsigned int
-#endif
-#if !defined(RC4_CHUNK)
-/*
- * This enables code handling data aligned at natural CPU word
- * boundary. See crypto/rc4/rc4_enc.c for further details.
- */
-#define RC4_CHUNK unsigned long long
-#endif
-#endif
-
-#if (defined(HEADER_NEW_DES_H) || defined(HEADER_DES_H)) && !defined(DES_LONG)
-/* 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 int
-#endif
-#endif
-
-#if defined(HEADER_BN_H) && !defined(CONFIG_HEADER_BN_H)
-#define CONFIG_HEADER_BN_H
-#undef BN_LLONG
-
-/* Should we define BN_DIV2W here? */
-
-/* Only one for the following should be defined */
-/* The prime number generation stuff may not work when
- * EIGHT_BIT but I don't care since I've only used this mode
- * for debuging the bignum libraries */
-#undef SIXTY_FOUR_BIT_LONG
-#define SIXTY_FOUR_BIT
-#undef THIRTY_TWO_BIT
-#undef SIXTEEN_BIT
-#undef EIGHT_BIT
-#endif
-
-#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H)
-#define CONFIG_HEADER_RC4_LOCL_H
-/* if this is defined data[i] is used instead of *data, this is a %20
- * speedup on x86 */
-#undef RC4_INDEX
-#endif
-
-#if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H)
-#define CONFIG_HEADER_BF_LOCL_H
-#undef BF_PTR
-#endif /* HEADER_BF_LOCL_H */
-
-#if defined(HEADER_DES_LOCL_H) && !defined(CONFIG_HEADER_DES_LOCL_H)
-#define CONFIG_HEADER_DES_LOCL_H
-#ifndef DES_DEFAULT_OPTIONS
-/* the following is tweaked from a config script, that is why it is a
- * protected undef/define */
-#ifndef DES_PTR
-#undef DES_PTR
-#endif
-
-/* This helps C compiler generate the correct code for multiple functional
- * units.  It reduces register dependancies at the expense of 2 more
- * registers */
-#ifndef DES_RISC1
-#undef DES_RISC1
-#endif
-
-#ifndef DES_RISC2
-#undef DES_RISC2
-#endif
-
-#if defined(DES_RISC1) && defined(DES_RISC2)
-YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!!
-#endif
-
-/* Unroll the inner loop, this sometimes helps, sometimes hinders.
- * Very mucy CPU dependant */
-#ifndef DES_UNROLL
-#undef DES_UNROLL
-#endif
-
-/* These default values were supplied by
- * Peter Gutman <pgut001@cs.auckland.ac.nz>
- * They are only used if nothing else has been defined */
-#if !defined(DES_PTR) && !defined(DES_RISC1) && !defined(DES_RISC2) && !defined(DES_UNROLL)
-/* Special defines which change the way the code is built depending on the
-   CPU and OS.  For SGI machines you can use _MIPS_SZLONG (32 or 64) to find
-   even newer MIPS CPU's, but at the moment one size fits all for
-   optimization options.  Older Sparc's work better with only UNROLL, but
-   there's no way to tell at compile time what it is you're running on */
-#if defined( sun )             /* Newer Sparc's */
-#  define DES_PTR
-#  define DES_RISC1
-#  define DES_UNROLL
-#elif defined( __ultrix )      /* Older MIPS */
-#  define DES_PTR
-#  define DES_RISC2
-#  define DES_UNROLL
-#elif defined( __osf1__ )      /* Alpha */
-#  define DES_PTR
-#  define DES_RISC2
-#elif defined ( _AIX )         /* RS6000 */
-  /* Unknown */
-#elif defined( __hpux )                /* HP-PA */
-  /* Unknown */
-#elif defined( __aux )         /* 68K */
-  /* Unknown */
-#elif defined( __dgux )                /* 88K (but P6 in latest boxes) */
-#  define DES_UNROLL
-#elif defined( __sgi )         /* Newer MIPS */
-#  define DES_PTR
-#  define DES_RISC2
-#  define DES_UNROLL
-#elif defined(i386) || defined(__i386__)       /* x86 boxes, should be gcc */
-#  define DES_PTR
-#  define DES_RISC1
-#  define DES_UNROLL
-#endif /* Systems-specific speed defines */
-#endif
-
-#endif /* DES_DEFAULT_OPTIONS */
-#endif /* HEADER_DES_LOCL_H */
index 0ea58de..f47e7b6 100644 (file)
@@ -1,5 +1,278 @@
-#ifdef WIN32
-#include "opensslconf-win32.h"
-#else
-#include "opensslconf-posix.h"
+/* opensslconf.h */
+/* WARNING: Generated automatically from opensslconf.h.in by Configure. */
+
+/* OpenSSL was configured with the following options: */
+#ifndef OPENSSL_DOING_MAKEDEPEND
+
+
+#ifndef OPENSSL_NO_CAMELLIA
+# define OPENSSL_NO_CAMELLIA
 #endif
+#ifndef OPENSSL_NO_CAPIENG
+# define OPENSSL_NO_CAPIENG
+#endif
+#ifndef OPENSSL_NO_CMS
+# define OPENSSL_NO_CMS
+#endif
+#ifndef OPENSSL_NO_FIPS
+# define OPENSSL_NO_FIPS
+#endif
+#ifndef OPENSSL_NO_GMP
+# define OPENSSL_NO_GMP
+#endif
+#ifndef OPENSSL_NO_IDEA
+# define OPENSSL_NO_IDEA
+#endif
+#ifndef OPENSSL_NO_JPAKE
+# define OPENSSL_NO_JPAKE
+#endif
+#ifndef OPENSSL_NO_KRB5
+# define OPENSSL_NO_KRB5
+#endif
+#ifndef OPENSSL_NO_MDC2
+# define OPENSSL_NO_MDC2
+#endif
+#ifndef OPENSSL_NO_RC5
+# define OPENSSL_NO_RC5
+#endif
+#ifndef OPENSSL_NO_RFC3779
+# define OPENSSL_NO_RFC3779
+#endif
+#ifndef OPENSSL_NO_SEED
+# define OPENSSL_NO_SEED
+#endif
+#ifndef OPENSSL_NO_ASM
+# define OPENSSL_NO_ASM
+#endif
+
+#endif /* OPENSSL_DOING_MAKEDEPEND */
+
+#ifndef OPENSSL_THREADS
+# define OPENSSL_THREADS
+#endif
+#ifndef OPENSSL_NO_DYNAMIC_ENGINE
+# define OPENSSL_NO_DYNAMIC_ENGINE
+#endif
+
+/* The OPENSSL_NO_* macros are also defined as NO_* if the application
+   asks for it.  This is a transient feature that is provided for those
+   who haven't had the time to do the appropriate changes in their
+   applications.  */
+#ifdef OPENSSL_ALGORITHM_DEFINES
+# if defined(OPENSSL_NO_CAMELLIA) && !defined(NO_CAMELLIA)
+#  define NO_CAMELLIA
+# endif
+# if defined(OPENSSL_NO_CAPIENG) && !defined(NO_CAPIENG)
+#  define NO_CAPIENG
+# endif
+# if defined(OPENSSL_NO_CMS) && !defined(NO_CMS)
+#  define NO_CMS
+# endif
+# if defined(OPENSSL_NO_FIPS) && !defined(NO_FIPS)
+#  define NO_FIPS
+# endif
+# if defined(OPENSSL_NO_GMP) && !defined(NO_GMP)
+#  define NO_GMP
+# endif
+# if defined(OPENSSL_NO_IDEA) && !defined(NO_IDEA)
+#  define NO_IDEA
+# endif
+# if defined(OPENSSL_NO_JPAKE) && !defined(NO_JPAKE)
+#  define NO_JPAKE
+# endif
+# if defined(OPENSSL_NO_KRB5) && !defined(NO_KRB5)
+#  define NO_KRB5
+# endif
+# if defined(OPENSSL_NO_MDC2) && !defined(NO_MDC2)
+#  define NO_MDC2
+# endif
+# if defined(OPENSSL_NO_RC5) && !defined(NO_RC5)
+#  define NO_RC5
+# endif
+# if defined(OPENSSL_NO_RFC3779) && !defined(NO_RFC3779)
+#  define NO_RFC3779
+# endif
+# if defined(OPENSSL_NO_SEED) && !defined(NO_SEED)
+#  define NO_SEED
+# endif
+#endif
+
+#define OPENSSL_CPUID_OBJ
+
+/* crypto/opensslconf.h.in */
+
+#ifdef OPENSSL_DOING_MAKEDEPEND
+
+/* Include any symbols here that have to be explicitly set to enable a feature
+ * that should be visible to makedepend.
+ *
+ * [Our "make depend" doesn't actually look at this, we use actual build settings
+ * instead; we want to make it easy to remove subdirectories with disabled algorithms.]
+ */
+
+#ifndef OPENSSL_FIPS
+#define OPENSSL_FIPS
+#endif
+
+#endif
+
+/* Generate 80386 code? */
+#undef I386_ONLY
+
+#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"
+#endif
+#endif
+
+#undef OPENSSL_UNISTD
+#define OPENSSL_UNISTD <unistd.h>
+#if !defined(SWIG)
+#include <unistd.h>
+#endif
+
+#undef OPENSSL_EXPORT_VAR_AS_FUNCTION
+
+#if defined(HEADER_IDEA_H) && !defined(IDEA_INT)
+#define IDEA_INT unsigned int
+#endif
+
+#if defined(HEADER_MD2_H) && !defined(MD2_INT)
+#define MD2_INT unsigned int
+#endif
+
+#if defined(HEADER_RC2_H) && !defined(RC2_INT)
+/* I need to put in a mod for the alpha - eay */
+#define RC2_INT unsigned int
+#endif
+
+#if defined(HEADER_RC4_H)
+#if !defined(RC4_INT)
+/* using int types make the structure larger but make the code faster
+ * on most boxes I have tested - up to %20 faster. */
+/*
+ * I don't know what does "most" mean, but declaring "int" is a must on:
+ * - Intel P6 because partial register stalls are very expensive;
+ * - elder Alpha because it lacks byte load/store instructions;
+ */
+#define RC4_INT unsigned int
+#endif
+#if !defined(RC4_CHUNK)
+/*
+ * This enables code handling data aligned at natural CPU word
+ * boundary. See crypto/rc4/rc4_enc.c for further details.
+ */
+#define RC4_CHUNK unsigned long
+#endif
+#endif
+
+#if (defined(HEADER_NEW_DES_H) || defined(HEADER_DES_H)) && !defined(DES_LONG)
+/* 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 int
+#endif
+#endif
+
+#if defined(HEADER_BN_H) && !defined(CONFIG_HEADER_BN_H)
+#define CONFIG_HEADER_BN_H
+#undef BN_LLONG
+
+/* Should we define BN_DIV2W here? */
+
+/* Only one for the following should be defined */
+/* The prime number generation stuff may not work when
+ * EIGHT_BIT but I don't care since I've only used this mode
+ * for debuging the bignum libraries */
+#define SIXTY_FOUR_BIT_LONG
+#undef SIXTY_FOUR_BIT
+#undef THIRTY_TWO_BIT
+#undef SIXTEEN_BIT
+#undef EIGHT_BIT
+#endif
+
+#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H)
+#define CONFIG_HEADER_RC4_LOCL_H
+/* if this is defined data[i] is used instead of *data, this is a %20
+ * speedup on x86 */
+#undef RC4_INDEX
+#endif
+
+#if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H)
+#define CONFIG_HEADER_BF_LOCL_H
+#undef BF_PTR
+#endif /* HEADER_BF_LOCL_H */
+
+#if defined(HEADER_DES_LOCL_H) && !defined(CONFIG_HEADER_DES_LOCL_H)
+#define CONFIG_HEADER_DES_LOCL_H
+#ifndef DES_DEFAULT_OPTIONS
+/* the following is tweaked from a config script, that is why it is a
+ * protected undef/define */
+#ifndef DES_PTR
+#undef DES_PTR
+#endif
+
+/* This helps C compiler generate the correct code for multiple functional
+ * units.  It reduces register dependancies at the expense of 2 more
+ * registers */
+#ifndef DES_RISC1
+#undef DES_RISC1
+#endif
+
+#ifndef DES_RISC2
+#undef DES_RISC2
+#endif
+
+#if defined(DES_RISC1) && defined(DES_RISC2)
+YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!!
+#endif
+
+/* Unroll the inner loop, this sometimes helps, sometimes hinders.
+ * Very mucy CPU dependant */
+#ifndef DES_UNROLL
+#define DES_UNROLL
+#endif
+
+/* These default values were supplied by
+ * Peter Gutman <pgut001@cs.auckland.ac.nz>
+ * They are only used if nothing else has been defined */
+#if !defined(DES_PTR) && !defined(DES_RISC1) && !defined(DES_RISC2) && !defined(DES_UNROLL)
+/* Special defines which change the way the code is built depending on the
+   CPU and OS.  For SGI machines you can use _MIPS_SZLONG (32 or 64) to find
+   even newer MIPS CPU's, but at the moment one size fits all for
+   optimization options.  Older Sparc's work better with only UNROLL, but
+   there's no way to tell at compile time what it is you're running on */
+#if defined( sun )             /* Newer Sparc's */
+#  define DES_PTR
+#  define DES_RISC1
+#  define DES_UNROLL
+#elif defined( __ultrix )      /* Older MIPS */
+#  define DES_PTR
+#  define DES_RISC2
+#  define DES_UNROLL
+#elif defined( __osf1__ )      /* Alpha */
+#  define DES_PTR
+#  define DES_RISC2
+#elif defined ( _AIX )         /* RS6000 */
+  /* Unknown */
+#elif defined( __hpux )                /* HP-PA */
+  /* Unknown */
+#elif defined( __aux )         /* 68K */
+  /* Unknown */
+#elif defined( __dgux )                /* 88K (but P6 in latest boxes) */
+#  define DES_UNROLL
+#elif defined( __sgi )         /* Newer MIPS */
+#  define DES_PTR
+#  define DES_RISC2
+#  define DES_UNROLL
+#elif defined(i386) || defined(__i386__)       /* x86 boxes, should be gcc */
+#  define DES_PTR
+#  define DES_RISC1
+#  define DES_UNROLL
+#endif /* Systems-specific speed defines */
+#endif
+
+#endif /* DES_DEFAULT_OPTIONS */
+#endif /* HEADER_DES_LOCL_H */
diff --git a/deps/openssl/config/piii/openssl/opensslconf-posix.h b/deps/openssl/config/piii/openssl/opensslconf-posix.h
deleted file mode 100644 (file)
index 9f87f27..0000000
+++ /dev/null
@@ -1,290 +0,0 @@
-/* opensslconf.h */
-/* WARNING: Generated automatically from opensslconf.h.in by Configure. */
-
-/* OpenSSL was configured with the following options: */
-#ifndef OPENSSL_DOING_MAKEDEPEND
-
-
-#ifndef OPENSSL_NO_CAMELLIA
-# define OPENSSL_NO_CAMELLIA
-#endif
-#ifndef OPENSSL_NO_CAPIENG
-# define OPENSSL_NO_CAPIENG
-#endif
-#ifndef OPENSSL_NO_CMS
-# define OPENSSL_NO_CMS
-#endif
-#ifndef OPENSSL_NO_FIPS
-# define OPENSSL_NO_FIPS
-#endif
-#ifndef OPENSSL_NO_GMP
-# define OPENSSL_NO_GMP
-#endif
-#ifndef OPENSSL_NO_IDEA
-# define OPENSSL_NO_IDEA
-#endif
-#ifndef OPENSSL_NO_JPAKE
-# define OPENSSL_NO_JPAKE
-#endif
-#ifndef OPENSSL_NO_KRB5
-# define OPENSSL_NO_KRB5
-#endif
-#ifndef OPENSSL_NO_MDC2
-# define OPENSSL_NO_MDC2
-#endif
-#ifndef OPENSSL_NO_RC5
-# define OPENSSL_NO_RC5
-#endif
-#ifndef OPENSSL_NO_RFC3779
-# define OPENSSL_NO_RFC3779
-#endif
-#ifndef OPENSSL_NO_SEED
-# define OPENSSL_NO_SEED
-#endif
-#ifndef OPENSSL_NO_ASM
-# define OPENSSL_NO_ASM
-#endif
-
-#endif /* OPENSSL_DOING_MAKEDEPEND */
-
-#ifndef OPENSSL_THREADS
-# define OPENSSL_THREADS
-#endif
-#ifndef OPENSSL_NO_DYNAMIC_ENGINE
-# define OPENSSL_NO_DYNAMIC_ENGINE
-#endif
-
-/* The OPENSSL_NO_* macros are also defined as NO_* if the application
-   asks for it.  This is a transient feature that is provided for those
-   who haven't had the time to do the appropriate changes in their
-   applications.  */
-#ifdef OPENSSL_ALGORITHM_DEFINES
-# if defined(OPENSSL_NO_CAMELLIA) && !defined(NO_CAMELLIA)
-#  define NO_CAMELLIA
-# endif
-# if defined(OPENSSL_NO_CAPIENG) && !defined(NO_CAPIENG)
-#  define NO_CAPIENG
-# endif
-# if defined(OPENSSL_NO_CMS) && !defined(NO_CMS)
-#  define NO_CMS
-# endif
-# if defined(OPENSSL_NO_FIPS) && !defined(NO_FIPS)
-#  define NO_FIPS
-# endif
-# if defined(OPENSSL_NO_GMP) && !defined(NO_GMP)
-#  define NO_GMP
-# endif
-# if defined(OPENSSL_NO_IDEA) && !defined(NO_IDEA)
-#  define NO_IDEA
-# endif
-# if defined(OPENSSL_NO_JPAKE) && !defined(NO_JPAKE)
-#  define NO_JPAKE
-# endif
-# if defined(OPENSSL_NO_KRB5) && !defined(NO_KRB5)
-#  define NO_KRB5
-# endif
-# if defined(OPENSSL_NO_MDC2) && !defined(NO_MDC2)
-#  define NO_MDC2
-# endif
-# if defined(OPENSSL_NO_RC5) && !defined(NO_RC5)
-#  define NO_RC5
-# endif
-# if defined(OPENSSL_NO_RFC3779) && !defined(NO_RFC3779)
-#  define NO_RFC3779
-# endif
-# if defined(OPENSSL_NO_SEED) && !defined(NO_SEED)
-#  define NO_SEED
-# endif
-#endif
-
-#define OPENSSL_CPUID_OBJ
-
-/* crypto/opensslconf.h.in */
-
-#ifdef OPENSSL_DOING_MAKEDEPEND
-
-/* Include any symbols here that have to be explicitly set to enable a feature
- * that should be visible to makedepend.
- *
- * [Our "make depend" doesn't actually look at this, we use actual build settings
- * instead; we want to make it easy to remove subdirectories with disabled algorithms.]
- */
-
-#ifndef OPENSSL_FIPS
-#define OPENSSL_FIPS
-#endif
-
-#endif
-
-/* Generate 80386 code? */
-#undef I386_ONLY
-
-#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"
-#endif
-#endif
-
-#undef OPENSSL_UNISTD
-#define OPENSSL_UNISTD <unistd.h>
-#if !defined(SWIG)
-#include <unistd.h>
-#endif
-
-#undef OPENSSL_EXPORT_VAR_AS_FUNCTION
-
-#if defined(HEADER_IDEA_H) && !defined(IDEA_INT)
-#define IDEA_INT unsigned int
-#endif
-
-#if defined(HEADER_MD2_H) && !defined(MD2_INT)
-#define MD2_INT unsigned int
-#endif
-
-#if defined(HEADER_RC2_H) && !defined(RC2_INT)
-/* I need to put in a mod for the alpha - eay */
-#define RC2_INT unsigned int
-#endif
-
-#if defined(HEADER_RC4_H)
-#if !defined(RC4_INT)
-/* using int types make the structure larger but make the code faster
- * on most boxes I have tested - up to %20 faster. */
-/*
- * I don't know what does "most" mean, but declaring "int" is a must on:
- * - Intel P6 because partial register stalls are very expensive;
- * - elder Alpha because it lacks byte load/store instructions;
- */
-#define RC4_INT unsigned int
-#endif
-#if !defined(RC4_CHUNK)
-/*
- * This enables code handling data aligned at natural CPU word
- * boundary. See crypto/rc4/rc4_enc.c for further details.
- */
-#undef RC4_CHUNK
-#endif
-#endif
-
-#if (defined(HEADER_NEW_DES_H) || defined(HEADER_DES_H)) && !defined(DES_LONG)
-/* 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
-#endif
-#endif
-
-#if defined(HEADER_BN_H) && !defined(CONFIG_HEADER_BN_H)
-#define CONFIG_HEADER_BN_H
-#define BN_LLONG
-
-/* Should we define BN_DIV2W here? */
-
-/* Only one for the following should be defined */
-/* The prime number generation stuff may not work when
- * EIGHT_BIT but I don't care since I've only used this mode
- * for debuging the bignum libraries */
-#undef SIXTY_FOUR_BIT_LONG
-#undef SIXTY_FOUR_BIT
-#undef THIRTY_TWO_BIT
-#undef SIXTEEN_BIT
-#undef EIGHT_BIT
-
-/* Let's hope ARM never releases a 64 bits CPU... */
-#if __x86_64__
-# define SIXTY_FOUR_BIT
-#else
-# define THIRTY_TWO_BIT
-#endif
-
-#endif /* defined(HEADER_BN_H) && !defined(CONFIG_HEADER_BN_H) */
-
-#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H)
-#define CONFIG_HEADER_RC4_LOCL_H
-/* if this is defined data[i] is used instead of *data, this is a %20
- * speedup on x86 */
-#define RC4_INDEX
-#endif
-
-#if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H)
-#define CONFIG_HEADER_BF_LOCL_H
-#undef BF_PTR
-#endif /* HEADER_BF_LOCL_H */
-
-#if defined(HEADER_DES_LOCL_H) && !defined(CONFIG_HEADER_DES_LOCL_H)
-#define CONFIG_HEADER_DES_LOCL_H
-#ifndef DES_DEFAULT_OPTIONS
-/* the following is tweaked from a config script, that is why it is a
- * protected undef/define */
-#ifndef DES_PTR
-#define DES_PTR
-#endif
-
-#if __x86_64__
-#undef DES_PTR
-#endif
-
-/* This helps C compiler generate the correct code for multiple functional
- * units.  It reduces register dependancies at the expense of 2 more
- * registers */
-#ifndef DES_RISC1
-#define DES_RISC1
-#endif
-
-#ifndef DES_RISC2
-#undef DES_RISC2
-#endif
-
-#if defined(DES_RISC1) && defined(DES_RISC2)
-YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!!
-#endif
-
-/* Unroll the inner loop, this sometimes helps, sometimes hinders.
- * Very mucy CPU dependant */
-#ifndef DES_UNROLL
-#define DES_UNROLL
-#endif
-
-/* These default values were supplied by
- * Peter Gutman <pgut001@cs.auckland.ac.nz>
- * They are only used if nothing else has been defined */
-#if !defined(DES_PTR) && !defined(DES_RISC1) && !defined(DES_RISC2) && !defined(DES_UNROLL)
-/* Special defines which change the way the code is built depending on the
-   CPU and OS.  For SGI machines you can use _MIPS_SZLONG (32 or 64) to find
-   even newer MIPS CPU's, but at the moment one size fits all for
-   optimization options.  Older Sparc's work better with only UNROLL, but
-   there's no way to tell at compile time what it is you're running on */
-
-#if defined( sun )             /* Newer Sparc's */
-#  define DES_PTR
-#  define DES_RISC1
-#  define DES_UNROLL
-#elif defined( __ultrix )      /* Older MIPS */
-#  define DES_PTR
-#  define DES_RISC2
-#  define DES_UNROLL
-#elif defined( __osf1__ )      /* Alpha */
-#  define DES_PTR
-#  define DES_RISC2
-#elif defined ( _AIX )         /* RS6000 */
-  /* Unknown */
-#elif defined( __hpux )                /* HP-PA */
-  /* Unknown */
-#elif defined( __aux )         /* 68K */
-  /* Unknown */
-#elif defined( __dgux )                /* 88K (but P6 in latest boxes) */
-#  define DES_UNROLL
-#elif defined( __sgi )         /* Newer MIPS */
-#  define DES_PTR
-#  define DES_RISC2
-#  define DES_UNROLL
-#elif defined(i386) || defined(__i386__)       /* x86 boxes, should be gcc */
-#  define DES_PTR
-#  define DES_RISC1
-#  define DES_UNROLL
-#endif /* Systems-specific speed defines */
-#endif
-
-#endif /* DES_DEFAULT_OPTIONS */
-#endif /* HEADER_DES_LOCL_H */
diff --git a/deps/openssl/config/piii/openssl/opensslconf-win32.h b/deps/openssl/config/piii/openssl/opensslconf-win32.h
deleted file mode 100644 (file)
index c27b492..0000000
+++ /dev/null
@@ -1,279 +0,0 @@
-/* opensslconf.h */
-/* WARNING: Generated automatically from opensslconf.h.in by Configure. */
-
-/* OpenSSL was configured with the following options: */
-#ifndef OPENSSL_SYSNAME_WIN32
-# define OPENSSL_SYSNAME_WIN32
-#endif
-#ifndef OPENSSL_DOING_MAKEDEPEND
-
-
-#ifndef OPENSSL_NO_CAMELLIA
-# define OPENSSL_NO_CAMELLIA
-#endif
-#ifndef OPENSSL_NO_CAPIENG
-# define OPENSSL_NO_CAPIENG
-#endif
-#ifndef OPENSSL_NO_CMS
-# define OPENSSL_NO_CMS
-#endif
-#ifndef OPENSSL_NO_FIPS
-# define OPENSSL_NO_FIPS
-#endif
-#ifndef OPENSSL_NO_GMP
-# define OPENSSL_NO_GMP
-#endif
-#ifndef OPENSSL_NO_IDEA
-# define OPENSSL_NO_IDEA
-#endif
-#ifndef OPENSSL_NO_JPAKE
-# define OPENSSL_NO_JPAKE
-#endif
-#ifndef OPENSSL_NO_KRB5
-# define OPENSSL_NO_KRB5
-#endif
-#ifndef OPENSSL_NO_MDC2
-# define OPENSSL_NO_MDC2
-#endif
-#ifndef OPENSSL_NO_RC5
-# define OPENSSL_NO_RC5
-#endif
-#ifndef OPENSSL_NO_RFC3779
-# define OPENSSL_NO_RFC3779
-#endif
-#ifndef OPENSSL_NO_SEED
-# define OPENSSL_NO_SEED
-#endif
-#ifndef OPENSSL_NO_ASM
-# define OPENSSL_NO_ASM
-#endif
-
-#endif /* OPENSSL_DOING_MAKEDEPEND */
-
-#ifndef OPENSSL_THREADS
-# define OPENSSL_THREADS
-#endif
-#ifndef OPENSSL_NO_DYNAMIC_ENGINE
-# define OPENSSL_NO_DYNAMIC_ENGINE
-#endif
-
-/* The OPENSSL_NO_* macros are also defined as NO_* if the application
-   asks for it.  This is a transient feature that is provided for those
-   who haven't had the time to do the appropriate changes in their
-   applications.  */
-#ifdef OPENSSL_ALGORITHM_DEFINES
-# if defined(OPENSSL_NO_CAMELLIA) && !defined(NO_CAMELLIA)
-#  define NO_CAMELLIA
-# endif
-# if defined(OPENSSL_NO_CAPIENG) && !defined(NO_CAPIENG)
-#  define NO_CAPIENG
-# endif
-# if defined(OPENSSL_NO_CMS) && !defined(NO_CMS)
-#  define NO_CMS
-# endif
-# if defined(OPENSSL_NO_FIPS) && !defined(NO_FIPS)
-#  define NO_FIPS
-# endif
-# if defined(OPENSSL_NO_GMP) && !defined(NO_GMP)
-#  define NO_GMP
-# endif
-# if defined(OPENSSL_NO_IDEA) && !defined(NO_IDEA)
-#  define NO_IDEA
-# endif
-# if defined(OPENSSL_NO_JPAKE) && !defined(NO_JPAKE)
-#  define NO_JPAKE
-# endif
-# if defined(OPENSSL_NO_KRB5) && !defined(NO_KRB5)
-#  define NO_KRB5
-# endif
-# if defined(OPENSSL_NO_MDC2) && !defined(NO_MDC2)
-#  define NO_MDC2
-# endif
-# if defined(OPENSSL_NO_RC5) && !defined(NO_RC5)
-#  define NO_RC5
-# endif
-# if defined(OPENSSL_NO_RFC3779) && !defined(NO_RFC3779)
-#  define NO_RFC3779
-# endif
-# if defined(OPENSSL_NO_SEED) && !defined(NO_SEED)
-#  define NO_SEED
-# endif
-#endif
-
-#define OPENSSL_CPUID_OBJ
-
-/* crypto/opensslconf.h.in */
-
-#ifdef OPENSSL_DOING_MAKEDEPEND
-
-/* Include any symbols here that have to be explicitly set to enable a feature
- * that should be visible to makedepend.
- *
- * [Our "make depend" doesn't actually look at this, we use actual build settings
- * instead; we want to make it easy to remove subdirectories with disabled algorithms.]
- */
-
-#ifndef OPENSSL_FIPS
-#define OPENSSL_FIPS
-#endif
-
-#endif
-
-/* Generate 80386 code? */
-#undef I386_ONLY
-
-#if !(defined(VMS) || defined(__VMS)) /* VMS uses logical names instead */
-#if defined(HEADER_CRYPTLIB_H) && !defined(OPENSSLDIR)
-#define ENGINESDIR "ssl/lib/engines"
-#define OPENSSLDIR "ssl"
-#endif
-#endif
-
-#undef OPENSSL_UNISTD
-#define OPENSSL_UNISTD <unistd.h>
-
-#undef OPENSSL_EXPORT_VAR_AS_FUNCTION
-#define OPENSSL_EXPORT_VAR_AS_FUNCTION
-
-#if defined(HEADER_IDEA_H) && !defined(IDEA_INT)
-#define IDEA_INT unsigned int
-#endif
-
-#if defined(HEADER_MD2_H) && !defined(MD2_INT)
-#define MD2_INT unsigned int
-#endif
-
-#if defined(HEADER_RC2_H) && !defined(RC2_INT)
-/* I need to put in a mod for the alpha - eay */
-#define RC2_INT unsigned int
-#endif
-
-#if defined(HEADER_RC4_H)
-#if !defined(RC4_INT)
-/* using int types make the structure larger but make the code faster
- * on most boxes I have tested - up to %20 faster. */
-/*
- * I don't know what does "most" mean, but declaring "int" is a must on:
- * - Intel P6 because partial register stalls are very expensive;
- * - elder Alpha because it lacks byte load/store instructions;
- */
-#define RC4_INT unsigned int
-#endif
-#if !defined(RC4_CHUNK)
-/*
- * This enables code handling data aligned at natural CPU word
- * boundary. See crypto/rc4/rc4_enc.c for further details.
- */
-#undef RC4_CHUNK
-#endif
-#endif
-
-#if (defined(HEADER_NEW_DES_H) || defined(HEADER_DES_H)) && !defined(DES_LONG)
-/* 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
-#endif
-#endif
-
-#if defined(HEADER_BN_H) && !defined(CONFIG_HEADER_BN_H)
-#define CONFIG_HEADER_BN_H
-#define BN_LLONG
-
-/* Should we define BN_DIV2W here? */
-
-/* Only one for the following should be defined */
-/* The prime number generation stuff may not work when
- * EIGHT_BIT but I don't care since I've only used this mode
- * for debuging the bignum libraries */
-#undef SIXTY_FOUR_BIT_LONG
-#undef SIXTY_FOUR_BIT
-#define THIRTY_TWO_BIT
-#undef SIXTEEN_BIT
-#undef EIGHT_BIT
-#endif
-
-#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H)
-#define CONFIG_HEADER_RC4_LOCL_H
-/* if this is defined data[i] is used instead of *data, this is a %20
- * speedup on x86 */
-#define RC4_INDEX
-#endif
-
-#if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H)
-#define CONFIG_HEADER_BF_LOCL_H
-#undef BF_PTR
-#endif /* HEADER_BF_LOCL_H */
-
-#if defined(HEADER_DES_LOCL_H) && !defined(CONFIG_HEADER_DES_LOCL_H)
-#define CONFIG_HEADER_DES_LOCL_H
-#ifndef DES_DEFAULT_OPTIONS
-/* the following is tweaked from a config script, that is why it is a
- * protected undef/define */
-#ifndef DES_PTR
-#undef DES_PTR
-#endif
-
-/* This helps C compiler generate the correct code for multiple functional
- * units.  It reduces register dependancies at the expense of 2 more
- * registers */
-#ifndef DES_RISC1
-#undef DES_RISC1
-#endif
-
-#ifndef DES_RISC2
-#undef DES_RISC2
-#endif
-
-#if defined(DES_RISC1) && defined(DES_RISC2)
-YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!!
-#endif
-
-/* Unroll the inner loop, this sometimes helps, sometimes hinders.
- * Very mucy CPU dependant */
-#ifndef DES_UNROLL
-#undef DES_UNROLL
-#endif
-
-/* These default values were supplied by
- * Peter Gutman <pgut001@cs.auckland.ac.nz>
- * They are only used if nothing else has been defined */
-#if !defined(DES_PTR) && !defined(DES_RISC1) && !defined(DES_RISC2) && !defined(DES_UNROLL)
-/* Special defines which change the way the code is built depending on the
-   CPU and OS.  For SGI machines you can use _MIPS_SZLONG (32 or 64) to find
-   even newer MIPS CPU's, but at the moment one size fits all for
-   optimization options.  Older Sparc's work better with only UNROLL, but
-   there's no way to tell at compile time what it is you're running on */
-
-#if defined( sun )             /* Newer Sparc's */
-#  define DES_PTR
-#  define DES_RISC1
-#  define DES_UNROLL
-#elif defined( __ultrix )      /* Older MIPS */
-#  define DES_PTR
-#  define DES_RISC2
-#  define DES_UNROLL
-#elif defined( __osf1__ )      /* Alpha */
-#  define DES_PTR
-#  define DES_RISC2
-#elif defined ( _AIX )         /* RS6000 */
-  /* Unknown */
-#elif defined( __hpux )                /* HP-PA */
-  /* Unknown */
-#elif defined( __aux )         /* 68K */
-  /* Unknown */
-#elif defined( __dgux )                /* 88K (but P6 in latest boxes) */
-#  define DES_UNROLL
-#elif defined( __sgi )         /* Newer MIPS */
-#  define DES_PTR
-#  define DES_RISC2
-#  define DES_UNROLL
-#elif defined(i386) || defined(__i386__)       /* x86 boxes, should be gcc */
-#  define DES_PTR
-#  define DES_RISC1
-#  define DES_UNROLL
-#endif /* Systems-specific speed defines */
-#endif
-
-#endif /* DES_DEFAULT_OPTIONS */
-#endif /* HEADER_DES_LOCL_H */
index 0ea58de..9725efa 100644 (file)
@@ -1,5 +1,278 @@
-#ifdef WIN32
-#include "opensslconf-win32.h"
-#else
-#include "opensslconf-posix.h"
+/* opensslconf.h */
+/* WARNING: Generated automatically from opensslconf.h.in by Configure. */
+
+/* OpenSSL was configured with the following options: */
+#ifndef OPENSSL_DOING_MAKEDEPEND
+
+
+#ifndef OPENSSL_NO_CAMELLIA
+# define OPENSSL_NO_CAMELLIA
 #endif
+#ifndef OPENSSL_NO_CAPIENG
+# define OPENSSL_NO_CAPIENG
+#endif
+#ifndef OPENSSL_NO_CMS
+# define OPENSSL_NO_CMS
+#endif
+#ifndef OPENSSL_NO_FIPS
+# define OPENSSL_NO_FIPS
+#endif
+#ifndef OPENSSL_NO_GMP
+# define OPENSSL_NO_GMP
+#endif
+#ifndef OPENSSL_NO_IDEA
+# define OPENSSL_NO_IDEA
+#endif
+#ifndef OPENSSL_NO_JPAKE
+# define OPENSSL_NO_JPAKE
+#endif
+#ifndef OPENSSL_NO_KRB5
+# define OPENSSL_NO_KRB5
+#endif
+#ifndef OPENSSL_NO_MDC2
+# define OPENSSL_NO_MDC2
+#endif
+#ifndef OPENSSL_NO_RC5
+# define OPENSSL_NO_RC5
+#endif
+#ifndef OPENSSL_NO_RFC3779
+# define OPENSSL_NO_RFC3779
+#endif
+#ifndef OPENSSL_NO_SEED
+# define OPENSSL_NO_SEED
+#endif
+#ifndef OPENSSL_NO_ASM
+# define OPENSSL_NO_ASM
+#endif
+
+#endif /* OPENSSL_DOING_MAKEDEPEND */
+
+#ifndef OPENSSL_THREADS
+# define OPENSSL_THREADS
+#endif
+#ifndef OPENSSL_NO_DYNAMIC_ENGINE
+# define OPENSSL_NO_DYNAMIC_ENGINE
+#endif
+
+/* The OPENSSL_NO_* macros are also defined as NO_* if the application
+   asks for it.  This is a transient feature that is provided for those
+   who haven't had the time to do the appropriate changes in their
+   applications.  */
+#ifdef OPENSSL_ALGORITHM_DEFINES
+# if defined(OPENSSL_NO_CAMELLIA) && !defined(NO_CAMELLIA)
+#  define NO_CAMELLIA
+# endif
+# if defined(OPENSSL_NO_CAPIENG) && !defined(NO_CAPIENG)
+#  define NO_CAPIENG
+# endif
+# if defined(OPENSSL_NO_CMS) && !defined(NO_CMS)
+#  define NO_CMS
+# endif
+# if defined(OPENSSL_NO_FIPS) && !defined(NO_FIPS)
+#  define NO_FIPS
+# endif
+# if defined(OPENSSL_NO_GMP) && !defined(NO_GMP)
+#  define NO_GMP
+# endif
+# if defined(OPENSSL_NO_IDEA) && !defined(NO_IDEA)
+#  define NO_IDEA
+# endif
+# if defined(OPENSSL_NO_JPAKE) && !defined(NO_JPAKE)
+#  define NO_JPAKE
+# endif
+# if defined(OPENSSL_NO_KRB5) && !defined(NO_KRB5)
+#  define NO_KRB5
+# endif
+# if defined(OPENSSL_NO_MDC2) && !defined(NO_MDC2)
+#  define NO_MDC2
+# endif
+# if defined(OPENSSL_NO_RC5) && !defined(NO_RC5)
+#  define NO_RC5
+# endif
+# if defined(OPENSSL_NO_RFC3779) && !defined(NO_RFC3779)
+#  define NO_RFC3779
+# endif
+# if defined(OPENSSL_NO_SEED) && !defined(NO_SEED)
+#  define NO_SEED
+# endif
+#endif
+
+#define OPENSSL_CPUID_OBJ
+
+/* crypto/opensslconf.h.in */
+
+#ifdef OPENSSL_DOING_MAKEDEPEND
+
+/* Include any symbols here that have to be explicitly set to enable a feature
+ * that should be visible to makedepend.
+ *
+ * [Our "make depend" doesn't actually look at this, we use actual build settings
+ * instead; we want to make it easy to remove subdirectories with disabled algorithms.]
+ */
+
+#ifndef OPENSSL_FIPS
+#define OPENSSL_FIPS
+#endif
+
+#endif
+
+/* Generate 80386 code? */
+#undef I386_ONLY
+
+#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"
+#endif
+#endif
+
+#undef OPENSSL_UNISTD
+#define OPENSSL_UNISTD <unistd.h>
+#if !defined(SWIG)
+#include <unistd.h>
+#endif
+
+#undef OPENSSL_EXPORT_VAR_AS_FUNCTION
+
+#if defined(HEADER_IDEA_H) && !defined(IDEA_INT)
+#define IDEA_INT unsigned int
+#endif
+
+#if defined(HEADER_MD2_H) && !defined(MD2_INT)
+#define MD2_INT unsigned int
+#endif
+
+#if defined(HEADER_RC2_H) && !defined(RC2_INT)
+/* I need to put in a mod for the alpha - eay */
+#define RC2_INT unsigned int
+#endif
+
+#if defined(HEADER_RC4_H)
+#if !defined(RC4_INT)
+/* using int types make the structure larger but make the code faster
+ * on most boxes I have tested - up to %20 faster. */
+/*
+ * I don't know what does "most" mean, but declaring "int" is a must on:
+ * - Intel P6 because partial register stalls are very expensive;
+ * - elder Alpha because it lacks byte load/store instructions;
+ */
+#define RC4_INT unsigned int
+#endif
+#if !defined(RC4_CHUNK)
+/*
+ * This enables code handling data aligned at natural CPU word
+ * boundary. See crypto/rc4/rc4_enc.c for further details.
+ */
+#undef RC4_CHUNK
+#endif
+#endif
+
+#if (defined(HEADER_NEW_DES_H) || defined(HEADER_DES_H)) && !defined(DES_LONG)
+/* 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
+#endif
+#endif
+
+#if defined(HEADER_BN_H) && !defined(CONFIG_HEADER_BN_H)
+#define CONFIG_HEADER_BN_H
+#define BN_LLONG
+
+/* Should we define BN_DIV2W here? */
+
+/* Only one for the following should be defined */
+/* The prime number generation stuff may not work when
+ * EIGHT_BIT but I don't care since I've only used this mode
+ * for debuging the bignum libraries */
+#undef SIXTY_FOUR_BIT_LONG
+#undef SIXTY_FOUR_BIT
+#define THIRTY_TWO_BIT
+#undef SIXTEEN_BIT
+#undef EIGHT_BIT
+#endif
+
+#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H)
+#define CONFIG_HEADER_RC4_LOCL_H
+/* if this is defined data[i] is used instead of *data, this is a %20
+ * speedup on x86 */
+#define RC4_INDEX
+#endif
+
+#if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H)
+#define CONFIG_HEADER_BF_LOCL_H
+#undef BF_PTR
+#endif /* HEADER_BF_LOCL_H */
+
+#if defined(HEADER_DES_LOCL_H) && !defined(CONFIG_HEADER_DES_LOCL_H)
+#define CONFIG_HEADER_DES_LOCL_H
+#ifndef DES_DEFAULT_OPTIONS
+/* the following is tweaked from a config script, that is why it is a
+ * protected undef/define */
+#ifndef DES_PTR
+#define DES_PTR
+#endif
+
+/* This helps C compiler generate the correct code for multiple functional
+ * units.  It reduces register dependancies at the expense of 2 more
+ * registers */
+#ifndef DES_RISC1
+#define DES_RISC1
+#endif
+
+#ifndef DES_RISC2
+#undef DES_RISC2
+#endif
+
+#if defined(DES_RISC1) && defined(DES_RISC2)
+YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!!
+#endif
+
+/* Unroll the inner loop, this sometimes helps, sometimes hinders.
+ * Very mucy CPU dependant */
+#ifndef DES_UNROLL
+#define DES_UNROLL
+#endif
+
+/* These default values were supplied by
+ * Peter Gutman <pgut001@cs.auckland.ac.nz>
+ * They are only used if nothing else has been defined */
+#if !defined(DES_PTR) && !defined(DES_RISC1) && !defined(DES_RISC2) && !defined(DES_UNROLL)
+/* Special defines which change the way the code is built depending on the
+   CPU and OS.  For SGI machines you can use _MIPS_SZLONG (32 or 64) to find
+   even newer MIPS CPU's, but at the moment one size fits all for
+   optimization options.  Older Sparc's work better with only UNROLL, but
+   there's no way to tell at compile time what it is you're running on */
+#if defined( sun )             /* Newer Sparc's */
+#  define DES_PTR
+#  define DES_RISC1
+#  define DES_UNROLL
+#elif defined( __ultrix )      /* Older MIPS */
+#  define DES_PTR
+#  define DES_RISC2
+#  define DES_UNROLL
+#elif defined( __osf1__ )      /* Alpha */
+#  define DES_PTR
+#  define DES_RISC2
+#elif defined ( _AIX )         /* RS6000 */
+  /* Unknown */
+#elif defined( __hpux )                /* HP-PA */
+  /* Unknown */
+#elif defined( __aux )         /* 68K */
+  /* Unknown */
+#elif defined( __dgux )                /* 88K (but P6 in latest boxes) */
+#  define DES_UNROLL
+#elif defined( __sgi )         /* Newer MIPS */
+#  define DES_PTR
+#  define DES_RISC2
+#  define DES_UNROLL
+#elif defined(i386) || defined(__i386__)       /* x86 boxes, should be gcc */
+#  define DES_PTR
+#  define DES_RISC1
+#  define DES_UNROLL
+#endif /* Systems-specific speed defines */
+#endif
+
+#endif /* DES_DEFAULT_OPTIONS */
+#endif /* HEADER_DES_LOCL_H */
index 9578ac4..c9bf79f 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2010 The Chromium Authors. All rights reserved.
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
@@ -9,63 +9,12 @@
       'type': '<(library)',
       'defines': [
         'L_ENDIAN',
-        'OPENSSLDIR="ssl"',
-        'ENGINESDIR="ssl/lib/engines"',
         'OPENSSL_THREADS',
         'PURIFY',
+        'TERMIO',
         '_REENTRANT',
-      ],
-
-      'cflags!': [
-        '-ansi'
-      ],
-
-      'conditions': [
-        ['OS=="win"', {
-          'defines': [
-            'WIN32_LEAN_AND_MEAN',     # needed to avoid some name clashes that break the build.
-            'MK1MF_BUILD',             # trick buildinf.h into believing that we're building from nmake
-            'MK1MF_PLATFORM_VC_WIN32', # ditto
-          ],
-        }],
-        ['OS=="mac"', {
-          'defines': [
-            'TERMIOS'
-          ],
-        }],
-        ['OS=="linux"', {
-          'defines': [
-            'TERMIO',
-          ],
-        }],
-        ['target_arch=="ia32" or target_arch=="x64"', {
-          'include_dirs': [
-            'config/piii',
-          ],
-          'direct_dependent_settings': {
-            'include_dirs': [
-              'openssl/include',
-              'config/piii',
-            ],
-          },
-        }],
-        ['target_arch=="x64"', {
-          'include_dirs': [
-            'config/k8',
-          ],
-          'direct_dependent_settings': {
-            'include_dirs': [
-              'openssl/include',
-              'config/k8',
-            ],
-          },
-        }],
-      ],
-
-      'copts': [
-        '-w',
-        '-Wno-cast-qual',
-        '-Wno-error',
+        # We do not use TLS over UDP on Chromium so far.
+        'OPENSSL_NO_DTLS1',
       ],
       'sources': [
         'openssl/ssl/bio_ssl.c',
@@ -76,7 +25,6 @@
         'openssl/ssl/d1_meth.c',
         'openssl/ssl/d1_pkt.c',
         'openssl/ssl/d1_srvr.c',
-        'openssl/ssl/fnv1a64.c',
         'openssl/ssl/kssl.c',
         'openssl/ssl/s23_clnt.c',
         'openssl/ssl/s23_lib.c',
         'openssl/crypto/asn1/a_dup.c',
         'openssl/crypto/asn1/a_enum.c',
         'openssl/crypto/asn1/a_gentm.c',
-        'openssl/crypto/asn1/a_hdr.c',
         'openssl/crypto/asn1/a_i2d_fp.c',
         'openssl/crypto/asn1/a_int.c',
         'openssl/crypto/asn1/a_mbstr.c',
-        'openssl/crypto/asn1/a_meth.c',
         'openssl/crypto/asn1/a_object.c',
         'openssl/crypto/asn1/a_octet.c',
         'openssl/crypto/asn1/a_print.c',
         'openssl/crypto/asn1/a_utctm.c',
         'openssl/crypto/asn1/a_utf8.c',
         'openssl/crypto/asn1/a_verify.c',
+        'openssl/crypto/asn1/ameth_lib.c',
         'openssl/crypto/asn1/asn1_err.c',
         'openssl/crypto/asn1/asn1_gen.c',
         'openssl/crypto/asn1/asn1_lib.c',
         'openssl/crypto/asn1/asn_mime.c',
         'openssl/crypto/asn1/asn_moid.c',
         'openssl/crypto/asn1/asn_pack.c',
+        'openssl/crypto/asn1/bio_asn1.c',
+        'openssl/crypto/asn1/bio_ndef.c',
         'openssl/crypto/asn1/d2i_pr.c',
         'openssl/crypto/asn1/d2i_pu.c',
         'openssl/crypto/asn1/evp_asn1.c',
         'openssl/crypto/asn1/tasn_enc.c',
         'openssl/crypto/asn1/tasn_fre.c',
         'openssl/crypto/asn1/tasn_new.c',
+        'openssl/crypto/asn1/tasn_prn.c',
         'openssl/crypto/asn1/tasn_typ.c',
         'openssl/crypto/asn1/tasn_utl.c',
         'openssl/crypto/asn1/x_algor.c',
         'openssl/crypto/asn1/x_info.c',
         'openssl/crypto/asn1/x_long.c',
         'openssl/crypto/asn1/x_name.c',
+        'openssl/crypto/asn1/x_nx509.c',
         'openssl/crypto/asn1/x_pkey.c',
         'openssl/crypto/asn1/x_pubkey.c',
         'openssl/crypto/asn1/x_req.c',
         'openssl/crypto/bn/bn_mpi.c',
         'openssl/crypto/bn/bn_mul.c',
         'openssl/crypto/bn/bn_nist.c',
-        'openssl/crypto/bn/bn_opt.c',
         'openssl/crypto/bn/bn_prime.c',
         'openssl/crypto/bn/bn_print.c',
         'openssl/crypto/bn/bn_rand.c',
         'openssl/crypto/bn/bn_sqr.c',
         'openssl/crypto/bn/bn_sqrt.c',
         'openssl/crypto/bn/bn_word.c',
-        'openssl/crypto/bn/bn_x931p.c',
         'openssl/crypto/buffer/buf_err.c',
-        'openssl/crypto/buffer/buf_str.c',
         'openssl/crypto/buffer/buffer.c',
+        'openssl/crypto/camellia/camellia.c',
+        'openssl/crypto/camellia/cmll_cbc.c',
+        'openssl/crypto/camellia/cmll_cfb.c',
+        'openssl/crypto/camellia/cmll_ctr.c',
+        'openssl/crypto/camellia/cmll_ecb.c',
+        'openssl/crypto/camellia/cmll_misc.c',
+        'openssl/crypto/camellia/cmll_ofb.c',
         'openssl/crypto/cast/c_cfb64.c',
         'openssl/crypto/cast/c_ecb.c',
         'openssl/crypto/cast/c_enc.c',
         'openssl/crypto/cast/c_ofb64.c',
         'openssl/crypto/cast/c_skey.c',
+        'openssl/crypto/cms/cms_asn1.c',
+        'openssl/crypto/cms/cms_att.c',
+        'openssl/crypto/cms/cms_cd.c',
+        'openssl/crypto/cms/cms_dd.c',
+        'openssl/crypto/cms/cms_enc.c',
+        'openssl/crypto/cms/cms_env.c',
+        'openssl/crypto/cms/cms_err.c',
+        'openssl/crypto/cms/cms_ess.c',
+        'openssl/crypto/cms/cms_io.c',
+        'openssl/crypto/cms/cms_lib.c',
+        'openssl/crypto/cms/cms_sd.c',
+        'openssl/crypto/cms/cms_smime.c',
         'openssl/crypto/comp/c_rle.c',
         'openssl/crypto/comp/c_zlib.c',
         'openssl/crypto/comp/comp_err.c',
         'openssl/crypto/des/cfb64enc.c',
         'openssl/crypto/des/cfb_enc.c',
         'openssl/crypto/des/des_enc.c',
-        'openssl/crypto/des/des_lib.c',
         'openssl/crypto/des/des_old.c',
         'openssl/crypto/des/des_old2.c',
         'openssl/crypto/des/ecb3_enc.c',
         'openssl/crypto/des/set_key.c',
         'openssl/crypto/des/str2key.c',
         'openssl/crypto/des/xcbc_enc.c',
+        'openssl/crypto/dh/dh_ameth.c',
         'openssl/crypto/dh/dh_asn1.c',
         'openssl/crypto/dh/dh_check.c',
         'openssl/crypto/dh/dh_depr.c',
         'openssl/crypto/dh/dh_gen.c',
         'openssl/crypto/dh/dh_key.c',
         'openssl/crypto/dh/dh_lib.c',
+        'openssl/crypto/dh/dh_pmeth.c',
+        'openssl/crypto/dh/dh_prn.c',
+        'openssl/crypto/dsa/dsa_ameth.c',
         'openssl/crypto/dsa/dsa_asn1.c',
         'openssl/crypto/dsa/dsa_depr.c',
         'openssl/crypto/dsa/dsa_err.c',
         'openssl/crypto/dsa/dsa_key.c',
         'openssl/crypto/dsa/dsa_lib.c',
         'openssl/crypto/dsa/dsa_ossl.c',
+        'openssl/crypto/dsa/dsa_pmeth.c',
+        'openssl/crypto/dsa/dsa_prn.c',
         'openssl/crypto/dsa/dsa_sign.c',
-        'openssl/crypto/dsa/dsa_utl.c',
         'openssl/crypto/dsa/dsa_vrf.c',
+        'openssl/crypto/dso/dso_beos.c',
         'openssl/crypto/dso/dso_err.c',
         'openssl/crypto/dso/dso_lib.c',
         'openssl/crypto/dso/dso_null.c',
         'openssl/crypto/dso/dso_openssl.c',
-        'openssl/crypto/dyn_lck.c',
         'openssl/crypto/ebcdic.c',
         'openssl/crypto/ec/ec2_mult.c',
         'openssl/crypto/ec/ec2_smpl.c',
         'openssl/crypto/ec/ec_asn1.c',
+        'openssl/crypto/ec/ec_ameth.c',
         'openssl/crypto/ec/ec_check.c',
         'openssl/crypto/ec/ec_curve.c',
         'openssl/crypto/ec/ec_cvt.c',
         'openssl/crypto/ec/ec_key.c',
         'openssl/crypto/ec/ec_lib.c',
         'openssl/crypto/ec/ec_mult.c',
+        'openssl/crypto/ec/ec_pmeth.c',
         'openssl/crypto/ec/ec_print.c',
+        'openssl/crypto/ec/eck_prn.c',
         'openssl/crypto/ec/ecp_mont.c',
         'openssl/crypto/ec/ecp_nist.c',
         'openssl/crypto/ec/ecp_smpl.c',
         'openssl/crypto/engine/eng_lib.c',
         'openssl/crypto/engine/eng_list.c',
         'openssl/crypto/engine/eng_openssl.c',
-        'openssl/crypto/engine/eng_padlock.c',
         'openssl/crypto/engine/eng_pkey.c',
         'openssl/crypto/engine/eng_table.c',
+        'openssl/crypto/engine/tb_asnmth.c',
         'openssl/crypto/engine/tb_cipher.c',
         'openssl/crypto/engine/tb_dh.c',
         'openssl/crypto/engine/tb_digest.c',
         'openssl/crypto/engine/tb_dsa.c',
         'openssl/crypto/engine/tb_ecdh.c',
         'openssl/crypto/engine/tb_ecdsa.c',
+        'openssl/crypto/engine/tb_pkmeth.c',
         'openssl/crypto/engine/tb_rand.c',
         'openssl/crypto/engine/tb_rsa.c',
         'openssl/crypto/engine/tb_store.c',
         'openssl/crypto/err/err.c',
         'openssl/crypto/err/err_all.c',
-        'openssl/crypto/err/err_bio.c',
-        'openssl/crypto/err/err_def.c',
         'openssl/crypto/err/err_prn.c',
-        'openssl/crypto/err/err_str.c',
         'openssl/crypto/evp/bio_b64.c',
         'openssl/crypto/evp/bio_enc.c',
         'openssl/crypto/evp/bio_md.c',
         'openssl/crypto/evp/c_all.c',
         'openssl/crypto/evp/c_allc.c',
         'openssl/crypto/evp/c_alld.c',
-        'openssl/crypto/evp/dig_eng.c',
         'openssl/crypto/evp/digest.c',
         'openssl/crypto/evp/e_aes.c',
         'openssl/crypto/evp/e_bf.c',
         'openssl/crypto/evp/e_rc5.c',
         'openssl/crypto/evp/e_seed.c',
         'openssl/crypto/evp/e_xcbc_d.c',
-        'openssl/crypto/evp/enc_min.c',
         'openssl/crypto/evp/encode.c',
         'openssl/crypto/evp/evp_acnf.c',
-        'openssl/crypto/evp/evp_cnf.c',
         'openssl/crypto/evp/evp_enc.c',
         'openssl/crypto/evp/evp_err.c',
         'openssl/crypto/evp/evp_key.c',
         'openssl/crypto/evp/m_ripemd.c',
         'openssl/crypto/evp/m_sha.c',
         'openssl/crypto/evp/m_sha1.c',
+        'openssl/crypto/evp/m_sigver.c',
+        'openssl/crypto/evp/m_wp.c',
         'openssl/crypto/evp/names.c',
         'openssl/crypto/evp/p5_crpt.c',
         'openssl/crypto/evp/p5_crpt2.c',
         'openssl/crypto/evp/p_seal.c',
         'openssl/crypto/evp/p_sign.c',
         'openssl/crypto/evp/p_verify.c',
+        'openssl/crypto/evp/pmeth_fn.c',
+        'openssl/crypto/evp/pmeth_gn.c',
+        'openssl/crypto/evp/pmeth_lib.c',
         'openssl/crypto/ex_data.c',
-        'openssl/crypto/fips_err.c',
+        'openssl/crypto/hmac/hm_ameth.c',
+        'openssl/crypto/hmac/hm_pmeth.c',
         'openssl/crypto/hmac/hmac.c',
         'openssl/crypto/krb5/krb5_asn.c',
         'openssl/crypto/lhash/lh_stats.c',
         'openssl/crypto/md4/md4_one.c',
         'openssl/crypto/md5/md5_dgst.c',
         'openssl/crypto/md5/md5_one.c',
+        'openssl/crypto/mdc2/mdc2dgst.c',
+        'openssl/crypto/mdc2/mdc2_one.c',
         'openssl/crypto/mem.c',
         'openssl/crypto/mem_clr.c',
         'openssl/crypto/mem_dbg.c',
+        'openssl/crypto/modes/cbc128.c',
+        'openssl/crypto/modes/cfb128.c',
+        'openssl/crypto/modes/ctr128.c',
+        'openssl/crypto/modes/cts128.c',
+        'openssl/crypto/modes/ofb128.c',
         'openssl/crypto/o_dir.c',
-        'openssl/crypto/o_init.c',
         'openssl/crypto/o_str.c',
         'openssl/crypto/o_time.c',
         'openssl/crypto/objects/o_names.c',
         'openssl/crypto/objects/obj_dat.c',
         'openssl/crypto/objects/obj_err.c',
         'openssl/crypto/objects/obj_lib.c',
+        'openssl/crypto/objects/obj_xref.c',
         'openssl/crypto/ocsp/ocsp_asn.c',
         'openssl/crypto/ocsp/ocsp_cl.c',
         'openssl/crypto/ocsp/ocsp_err.c',
         'openssl/crypto/pem/pem_sign.c',
         'openssl/crypto/pem/pem_x509.c',
         'openssl/crypto/pem/pem_xaux.c',
+        'openssl/crypto/pem/pvkfmt.c',
         'openssl/crypto/pkcs12/p12_add.c',
         'openssl/crypto/pkcs12/p12_asn.c',
         'openssl/crypto/pkcs12/p12_attr.c',
         'openssl/crypto/pkcs12/p12_p8e.c',
         'openssl/crypto/pkcs12/p12_utl.c',
         'openssl/crypto/pkcs12/pk12err.c',
+        'openssl/crypto/pkcs7/bio_pk7.c',
         'openssl/crypto/pkcs7/pk7_asn1.c',
         'openssl/crypto/pkcs7/pk7_attr.c',
         'openssl/crypto/pkcs7/pk7_doit.c',
         'openssl/crypto/pqueue/pqueue.c',
         'openssl/crypto/rand/md_rand.c',
         'openssl/crypto/rand/rand_egd.c',
-        'openssl/crypto/rand/rand_eng.c',
         'openssl/crypto/rand/rand_err.c',
         'openssl/crypto/rand/rand_lib.c',
         'openssl/crypto/rand/rand_nw.c',
         'openssl/crypto/rc2/rc2cfb64.c',
         'openssl/crypto/rc2/rc2ofb64.c',
         'openssl/crypto/rc4/rc4_enc.c',
-        'openssl/crypto/rc4/rc4_fblk.c',
         'openssl/crypto/rc4/rc4_skey.c',
         'openssl/crypto/ripemd/rmd_dgst.c',
         'openssl/crypto/ripemd/rmd_one.c',
+        'openssl/crypto/rsa/rsa_ameth.c',
         'openssl/crypto/rsa/rsa_asn1.c',
         'openssl/crypto/rsa/rsa_chk.c',
         'openssl/crypto/rsa/rsa_depr.c',
         'openssl/crypto/rsa/rsa_eay.c',
-        'openssl/crypto/rsa/rsa_eng.c',
         'openssl/crypto/rsa/rsa_err.c',
         'openssl/crypto/rsa/rsa_gen.c',
         'openssl/crypto/rsa/rsa_lib.c',
         'openssl/crypto/rsa/rsa_null.c',
         'openssl/crypto/rsa/rsa_oaep.c',
         'openssl/crypto/rsa/rsa_pk1.c',
+        'openssl/crypto/rsa/rsa_pmeth.c',
+        'openssl/crypto/rsa/rsa_prn.c',
         'openssl/crypto/rsa/rsa_pss.c',
         'openssl/crypto/rsa/rsa_saos.c',
         'openssl/crypto/rsa/rsa_sign.c',
         'openssl/crypto/rsa/rsa_ssl.c',
         'openssl/crypto/rsa/rsa_x931.c',
-        'openssl/crypto/rsa/rsa_x931g.c',
         'openssl/crypto/sha/sha1_one.c',
         'openssl/crypto/sha/sha1dgst.c',
         'openssl/crypto/sha/sha256.c',
         'openssl/crypto/store/str_lib.c',
         'openssl/crypto/store/str_mem.c',
         'openssl/crypto/store/str_meth.c',
-        'openssl/crypto/tmdiff.c',
+        'openssl/crypto/ts/ts_asn1.c',
+        'openssl/crypto/ts/ts_conf.c',
+        'openssl/crypto/ts/ts_err.c',
+        'openssl/crypto/ts/ts_lib.c',
+        'openssl/crypto/ts/ts_req_print.c',
+        'openssl/crypto/ts/ts_req_utils.c',
+        'openssl/crypto/ts/ts_rsp_print.c',
+        'openssl/crypto/ts/ts_rsp_sign.c',
+        'openssl/crypto/ts/ts_rsp_utils.c',
+        'openssl/crypto/ts/ts_rsp_verify.c',
+        'openssl/crypto/ts/ts_verify_ctx.c',
         'openssl/crypto/txt_db/txt_db.c',
         'openssl/crypto/ui/ui_compat.c',
         'openssl/crypto/ui/ui_err.c',
         'openssl/crypto/ui/ui_openssl.c',
         'openssl/crypto/ui/ui_util.c',
         'openssl/crypto/uid.c',
+        'openssl/crypto/whrlpool/wp_block.c',
+        'openssl/crypto/whrlpool/wp_dgst.c',
         'openssl/crypto/x509/by_dir.c',
         'openssl/crypto/x509/by_file.c',
         'openssl/crypto/x509/x509_att.c',
         'openssl/engines/e_sureware.c',
         'openssl/engines/e_ubsec.c',
       ],
+      'conditions': [
+        ['os_posix==1 and OS!="android"', {
+          'defines': [
+            # ENGINESDIR must be defined if OPENSSLDIR is.
+            'ENGINESDIR="/dev/null"',
+            # Set to ubuntu default path for convenience. If necessary, override
+            # this at runtime with the SSL_CERT_DIR environment variable.
+            'OPENSSLDIR="/etc/ssl"',
+          ],
+          'variables': {
+            'conditions': [
+              ['target_arch=="ia32"', {
+                'openssl_config_path': 'config/piii',
+              }, {
+                'openssl_config_path': 'config/k8',
+              }],
+            ],
+          },
+        }],
+        ['OS=="android"', {
+          'variables': {
+            'openssl_config_path': 'config/android',
+          },
+          'sources/': [
+            ['exclude', 'cast/.*$'],
+            ['exclude', 'crypto/md2/.*$'],
+            ['exclude', 'crypto/store/.*$'],
+            ['exclude', 'crypto/whrlpool/.$'],
+          ],
+        }, {
+          'sources/': [
+            ['exclude', 'camellia/.*$'],
+            ['exclude', 'cms/.*$'],
+            ['exclude', 'mdc2/.*$'],
+          ],
+        }],
+        ['clang==1', {
+          'cflags': [
+            # OpenSSL has a few |if ((foo == NULL))| checks.
+            '-Wno-parentheses-equality',
+            # OpenSSL uses several function-style macros and then ignores the
+            # returned value.
+            '-Wno-unused-value',
+          ],
+        }, { # Not clang. Disable all warnings.
+          'cflags': [
+            '-w',
+          ],
+        }]
+      ],
       'include_dirs': [
         '.',
         'openssl',
         'openssl/crypto',
         'openssl/crypto/asn1',
         'openssl/crypto/evp',
+        'openssl/crypto/store',
         'openssl/include',
+        '<@(openssl_config_path)',
       ],
+      'direct_dependent_settings': {
+        'include_dirs': [
+          'openssl/include',
+          '<@(openssl_config_path)',
+        ],
+      },
     },
   ],
 }
index a0442b5..03e744a 100644 (file)
  OpenSSL CHANGES
  _______________
 
+ Changes between 1.0.0e and 1.0.0f [4 Jan 2012]
+
+  *) Nadhem Alfardan and Kenny Paterson have discovered an extension
+     of the Vaudenay padding oracle attack on CBC mode encryption
+     which enables an efficient plaintext recovery attack against
+     the OpenSSL implementation of DTLS. Their attack exploits timing
+     differences arising during decryption processing. A research
+     paper describing this attack can be found at:
+                  http://www.isg.rhul.ac.uk/~kp/dtls.pdf
+     Thanks go to Nadhem Alfardan and Kenny Paterson of the Information
+     Security Group at Royal Holloway, University of London
+     (www.isg.rhul.ac.uk) for discovering this flaw and to Robin Seggelmann
+     <seggelmann@fh-muenster.de> and Michael Tuexen <tuexen@fh-muenster.de>
+     for preparing the fix. (CVE-2011-4108)
+     [Robin Seggelmann, Michael Tuexen]
+
+  *) Clear bytes used for block padding of SSL 3.0 records.
+     (CVE-2011-4576)
+     [Adam Langley (Google)]
+
+  *) Only allow one SGC handshake restart for SSL/TLS. (CVE-2011-4619)
+     [Adam Langley (Google)]
+
+  *) Check parameters are not NULL in GOST ENGINE. (CVE-2012-0027)
+     [Andrey Kulikov <amdeich@gmail.com>]
+
+  *) Prevent malformed RFC3779 data triggering an assertion failure.
+     Thanks to Andrew Chi, BBN Technologies, for discovering the flaw
+     and Rob Austein <sra@hactrn.net> for fixing it. (CVE-2011-4577)
+     [Rob Austein <sra@hactrn.net>]
+
+  *) Improved PRNG seeding for VOS.
+     [Paul Green <Paul.Green@stratus.com>]
+
+  *) Fix ssl_ciph.c set-up race.
+     [Adam Langley (Google)]
+
+  *) Fix spurious failures in ecdsatest.c.
+     [Emilia Käsper (Google)]
+
+  *) Fix the BIO_f_buffer() implementation (which was mixing different
+     interpretations of the '..._len' fields).
+     [Adam Langley (Google)]
+
+  *) Fix handling of BN_BLINDING: now BN_BLINDING_invert_ex (rather than
+     BN_BLINDING_invert_ex) calls BN_BLINDING_update, ensuring that concurrent
+     threads won't reuse the same blinding coefficients.
+
+     This also avoids the need to obtain the CRYPTO_LOCK_RSA_BLINDING
+     lock to call BN_BLINDING_invert_ex, and avoids one use of
+     BN_BLINDING_update for each BN_BLINDING structure (previously,
+     the last update always remained unused).
+     [Emilia Käsper (Google)]
+
+  *) In ssl3_clear, preserve s3->init_extra along with s3->rbuf.
+     [Bob Buckholz (Google)]
+
+ Changes between 1.0.0d and 1.0.0e [6 Sep 2011]
+
+  *) Fix bug where CRLs with nextUpdate in the past are sometimes accepted
+     by initialising X509_STORE_CTX properly. (CVE-2011-3207)
+     [Kaspar Brand <ossl@velox.ch>]
+
+  *) Fix SSL memory handling for (EC)DH ciphersuites, in particular
+     for multi-threaded use of ECDH. (CVE-2011-3210)
+     [Adam Langley (Google)]
+
+  *) Fix x509_name_ex_d2i memory leak on bad inputs.
+     [Bodo Moeller]
+
+  *) Remove hard coded ecdsaWithSHA1 signature tests in ssl code and check
+     signature public key algorithm by using OID xref utilities instead.
+     Before this you could only use some ECC ciphersuites with SHA1 only.
+     [Steve Henson]
+
+  *) Add protection against ECDSA timing attacks as mentioned in the paper
+     by Billy Bob Brumley and Nicola Tuveri, see:
+
+       http://eprint.iacr.org/2011/232.pdf
+
+     [Billy Bob Brumley and Nicola Tuveri]
+
+ Changes between 1.0.0c and 1.0.0d [8 Feb 2011]
+
+  *) Fix parsing of OCSP stapling ClientHello extension. CVE-2011-0014
+     [Neel Mehta, Adam Langley, Bodo Moeller (Google)]
+
+  *) Fix bug in string printing code: if *any* escaping is enabled we must
+     escape the escape character (backslash) or the resulting string is
+     ambiguous.
+     [Steve Henson]
+
+ Changes between 1.0.0b and 1.0.0c  [2 Dec 2010]
+
+  *) Disable code workaround for ancient and obsolete Netscape browsers
+     and servers: an attacker can use it in a ciphersuite downgrade attack.
+     Thanks to Martin Rex for discovering this bug. CVE-2010-4180
+     [Steve Henson]
+
+  *) Fixed J-PAKE implementation error, originally discovered by
+     Sebastien Martini, further info and confirmation from Stefan
+     Arentz and Feng Hao. Note that this fix is a security fix. CVE-2010-4252
+     [Ben Laurie]
+
+ Changes between 1.0.0a and 1.0.0b  [16 Nov 2010]
+
+  *) Fix extension code to avoid race conditions which can result in a buffer
+     overrun vulnerability: resumed sessions must not be modified as they can
+     be shared by multiple threads. CVE-2010-3864
+     [Steve Henson]
+
+  *) Fix WIN32 build system to correctly link an ENGINE directory into
+     a DLL. 
+     [Steve Henson]
+
+ Changes between 1.0.0 and 1.0.0a  [01 Jun 2010]
+
+  *) Check return value of int_rsa_verify in pkey_rsa_verifyrecover 
+     (CVE-2010-1633)
+     [Steve Henson, Peter-Michael Hager <hager@dortmund.net>]
+
+ Changes between 0.9.8n and 1.0.0  [29 Mar 2010]
+
+  *) Add "missing" function EVP_CIPHER_CTX_copy(). This copies a cipher
+     context. The operation can be customised via the ctrl mechanism in
+     case ENGINEs want to include additional functionality.
+     [Steve Henson]
+
+  *) Tolerate yet another broken PKCS#8 key format: private key value negative.
+     [Steve Henson]
+
+  *) Add new -subject_hash_old and -issuer_hash_old options to x509 utility to
+     output hashes compatible with older versions of OpenSSL.
+     [Willy Weisz <weisz@vcpc.univie.ac.at>]
+
+  *) Fix compression algorithm handling: if resuming a session use the
+     compression algorithm of the resumed session instead of determining
+     it from client hello again. Don't allow server to change algorithm.
+     [Steve Henson]
+
+  *) Add load_crls() function to apps tidying load_certs() too. Add option
+     to verify utility to allow additional CRLs to be included.
+     [Steve Henson]
+
+  *) Update OCSP request code to permit adding custom headers to the request:
+     some responders need this.
+     [Steve Henson]
+
+  *) The function EVP_PKEY_sign() returns <=0 on error: check return code
+     correctly.
+     [Julia Lawall <julia@diku.dk>]
+
+  *) Update verify callback code in apps/s_cb.c and apps/verify.c, it
+     needlessly dereferenced structures, used obsolete functions and
+     didn't handle all updated verify codes correctly.
+     [Steve Henson]
+
+  *) Disable MD2 in the default configuration.
+     [Steve Henson]
+
+  *) In BIO_pop() and BIO_push() use the ctrl argument (which was NULL) to
+     indicate the initial BIO being pushed or popped. This makes it possible
+     to determine whether the BIO is the one explicitly called or as a result
+     of the ctrl being passed down the chain. Fix BIO_pop() and SSL BIOs so
+     it handles reference counts correctly and doesn't zero out the I/O bio
+     when it is not being explicitly popped. WARNING: applications which
+     included workarounds for the old buggy behaviour will need to be modified
+     or they could free up already freed BIOs.
+     [Steve Henson]
+
+  *) Extend the uni2asc/asc2uni => OPENSSL_uni2asc/OPENSSL_asc2uni
+     renaming to all platforms (within the 0.9.8 branch, this was
+     done conditionally on Netware platforms to avoid a name clash).
+     [Guenter <lists@gknw.net>]
+
+  *) Add ECDHE and PSK support to DTLS.
+     [Michael Tuexen <tuexen@fh-muenster.de>]
+
+  *) Add CHECKED_STACK_OF macro to safestack.h, otherwise safestack can't
+     be used on C++.
+     [Steve Henson]
+
+  *) Add "missing" function EVP_MD_flags() (without this the only way to
+     retrieve a digest flags is by accessing the structure directly. Update
+     EVP_MD_do_all*() and EVP_CIPHER_do_all*() to include the name a digest
+     or cipher is registered as in the "from" argument. Print out all
+     registered digests in the dgst usage message instead of manually 
+     attempting to work them out.
+     [Steve Henson]
+
+  *) If no SSLv2 ciphers are used don't use an SSLv2 compatible client hello:
+     this allows the use of compression and extensions. Change default cipher
+     string to remove SSLv2 ciphersuites. This effectively avoids ancient SSLv2
+     by default unless an application cipher string requests it.
+     [Steve Henson]
+
+  *) Alter match criteria in PKCS12_parse(). It used to try to use local
+     key ids to find matching certificates and keys but some PKCS#12 files
+     don't follow the (somewhat unwritten) rules and this strategy fails.
+     Now just gather all certificates together and the first private key
+     then look for the first certificate that matches the key.
+     [Steve Henson]
+
+  *) Support use of registered digest and cipher names for dgst and cipher
+     commands instead of having to add each one as a special case. So now
+     you can do:
+
+        openssl sha256 foo
+
+     as well as:
+
+        openssl dgst -sha256 foo
+
+     and this works for ENGINE based algorithms too.
+
+     [Steve Henson]
+
+  *) Update Gost ENGINE to support parameter files.
+     [Victor B. Wagner <vitus@cryptocom.ru>]
+
+  *) Support GeneralizedTime in ca utility. 
+     [Oliver Martin <oliver@volatilevoid.net>, Steve Henson]
+
+  *) Enhance the hash format used for certificate directory links. The new
+     form uses the canonical encoding (meaning equivalent names will work
+     even if they aren't identical) and uses SHA1 instead of MD5. This form
+     is incompatible with the older format and as a result c_rehash should
+     be used to rebuild symbolic links.
+     [Steve Henson]
+
+  *) Make PKCS#8 the default write format for private keys, replacing the
+     traditional format. This form is standardised, more secure and doesn't
+     include an implicit MD5 dependency.
+     [Steve Henson]
+
+  *) Add a $gcc_devteam_warn option to Configure. The idea is that any code
+     committed to OpenSSL should pass this lot as a minimum.
+     [Steve Henson]
+
+  *) Add session ticket override functionality for use by EAP-FAST.
+     [Jouni Malinen <j@w1.fi>]
+
+  *) Modify HMAC functions to return a value. Since these can be implemented
+     in an ENGINE errors can occur.
+     [Steve Henson]
+
+  *) Type-checked OBJ_bsearch_ex.
+     [Ben Laurie]
+
+  *) Type-checked OBJ_bsearch. Also some constification necessitated
+     by type-checking.  Still to come: TXT_DB, bsearch(?),
+     OBJ_bsearch_ex, qsort, CRYPTO_EX_DATA, ASN1_VALUE, ASN1_STRING,
+     CONF_VALUE.
+     [Ben Laurie]
+
+  *) New function OPENSSL_gmtime_adj() to add a specific number of days and
+     seconds to a tm structure directly, instead of going through OS
+     specific date routines. This avoids any issues with OS routines such
+     as the year 2038 bug. New *_adj() functions for ASN1 time structures
+     and X509_time_adj_ex() to cover the extended range. The existing
+     X509_time_adj() is still usable and will no longer have any date issues.
+     [Steve Henson]
+
+  *) Delta CRL support. New use deltas option which will attempt to locate
+     and search any appropriate delta CRLs available.
+
+     This work was sponsored by Google.
+     [Steve Henson]
+
+  *) Support for CRLs partitioned by reason code. Reorganise CRL processing
+     code and add additional score elements. Validate alternate CRL paths
+     as part of the CRL checking and indicate a new error "CRL path validation
+     error" in this case. Applications wanting additional details can use
+     the verify callback and check the new "parent" field. If this is not
+     NULL CRL path validation is taking place. Existing applications wont
+     see this because it requires extended CRL support which is off by
+     default.
+
+     This work was sponsored by Google.
+     [Steve Henson]
+
+  *) Support for freshest CRL extension.
+
+     This work was sponsored by Google.
+     [Steve Henson]
+
+  *) Initial indirect CRL support. Currently only supported in the CRLs
+     passed directly and not via lookup. Process certificate issuer
+     CRL entry extension and lookup CRL entries by bother issuer name
+     and serial number. Check and process CRL issuer entry in IDP extension.
+
+     This work was sponsored by Google.
+     [Steve Henson]
+
+  *) Add support for distinct certificate and CRL paths. The CRL issuer
+     certificate is validated separately in this case. Only enabled if
+     an extended CRL support flag is set: this flag will enable additional
+     CRL functionality in future.
+
+     This work was sponsored by Google.
+     [Steve Henson]
+
+  *) Add support for policy mappings extension.
+
+     This work was sponsored by Google.
+     [Steve Henson]
+
+  *) Fixes to pathlength constraint, self issued certificate handling,
+     policy processing to align with RFC3280 and PKITS tests.
+
+     This work was sponsored by Google.
+     [Steve Henson]
+
+  *) Support for name constraints certificate extension. DN, email, DNS
+     and URI types are currently supported.
+
+     This work was sponsored by Google.
+     [Steve Henson]
+
+  *) To cater for systems that provide a pointer-based thread ID rather
+     than numeric, deprecate the current numeric thread ID mechanism and
+     replace it with a structure and associated callback type. This
+     mechanism allows a numeric "hash" to be extracted from a thread ID in
+     either case, and on platforms where pointers are larger than 'long',
+     mixing is done to help ensure the numeric 'hash' is usable even if it
+     can't be guaranteed unique. The default mechanism is to use "&errno"
+     as a pointer-based thread ID to distinguish between threads.
+
+     Applications that want to provide their own thread IDs should now use
+     CRYPTO_THREADID_set_callback() to register a callback that will call
+     either CRYPTO_THREADID_set_numeric() or CRYPTO_THREADID_set_pointer().
+
+     Note that ERR_remove_state() is now deprecated, because it is tied
+     to the assumption that thread IDs are numeric.  ERR_remove_state(0)
+     to free the current thread's error state should be replaced by
+     ERR_remove_thread_state(NULL).
+
+     (This new approach replaces the functions CRYPTO_set_idptr_callback(),
+     CRYPTO_get_idptr_callback(), and CRYPTO_thread_idptr() that existed in
+     OpenSSL 0.9.9-dev between June 2006 and August 2008. Also, if an
+     application was previously providing a numeric thread callback that
+     was inappropriate for distinguishing threads, then uniqueness might
+     have been obtained with &errno that happened immediately in the
+     intermediate development versions of OpenSSL; this is no longer the
+     case, the numeric thread callback will now override the automatic use
+     of &errno.)
+     [Geoff Thorpe, with help from Bodo Moeller]
+
+  *) Initial support for different CRL issuing certificates. This covers a
+     simple case where the self issued certificates in the chain exist and
+     the real CRL issuer is higher in the existing chain.
+
+     This work was sponsored by Google.
+     [Steve Henson]
+
+  *) Removed effectively defunct crypto/store from the build.
+     [Ben Laurie]
+
+  *) Revamp of STACK to provide stronger type-checking. Still to come:
+     TXT_DB, bsearch(?), OBJ_bsearch, qsort, CRYPTO_EX_DATA, ASN1_VALUE,
+     ASN1_STRING, CONF_VALUE.
+     [Ben Laurie]
+
+  *) Add a new SSL_MODE_RELEASE_BUFFERS mode flag to release unused buffer
+     RAM on SSL connections.  This option can save about 34k per idle SSL.
+     [Nick Mathewson]
+
+  *) Revamp of LHASH to provide stronger type-checking. Still to come:
+     STACK, TXT_DB, bsearch, qsort.
+     [Ben Laurie]
+
+  *) Initial support for Cryptographic Message Syntax (aka CMS) based
+     on RFC3850, RFC3851 and RFC3852. New cms directory and cms utility,
+     support for data, signedData, compressedData, digestedData and
+     encryptedData, envelopedData types included. Scripts to check against
+     RFC4134 examples draft and interop and consistency checks of many
+     content types and variants.
+     [Steve Henson]
+
+  *) Add options to enc utility to support use of zlib compression BIO.
+     [Steve Henson]
+
+  *) Extend mk1mf to support importing of options and assembly language
+     files from Configure script, currently only included in VC-WIN32.
+     The assembly language rules can now optionally generate the source
+     files from the associated perl scripts.
+     [Steve Henson]
+
+  *) Implement remaining functionality needed to support GOST ciphersuites.
+     Interop testing has been performed using CryptoPro implementations.
+     [Victor B. Wagner <vitus@cryptocom.ru>]
+
+  *) s390x assembler pack.
+     [Andy Polyakov]
+
+  *) ARMv4 assembler pack. ARMv4 refers to v4 and later ISA, not CPU
+     "family."
+     [Andy Polyakov]
+
+  *) Implement Opaque PRF Input TLS extension as specified in
+     draft-rescorla-tls-opaque-prf-input-00.txt.  Since this is not an
+     official specification yet and no extension type assignment by
+     IANA exists, this extension (for now) will have to be explicitly
+     enabled when building OpenSSL by providing the extension number
+     to use.  For example, specify an option
+
+         -DTLSEXT_TYPE_opaque_prf_input=0x9527
+
+     to the "config" or "Configure" script to enable the extension,
+     assuming extension number 0x9527 (which is a completely arbitrary
+     and unofficial assignment based on the MD5 hash of the Internet
+     Draft).  Note that by doing so, you potentially lose
+     interoperability with other TLS implementations since these might
+     be using the same extension number for other purposes.
+
+     SSL_set_tlsext_opaque_prf_input(ssl, src, len) is used to set the
+     opaque PRF input value to use in the handshake.  This will create
+     an interal copy of the length-'len' string at 'src', and will
+     return non-zero for success.
+
+     To get more control and flexibility, provide a callback function
+     by using
+
+          SSL_CTX_set_tlsext_opaque_prf_input_callback(ctx, cb)
+          SSL_CTX_set_tlsext_opaque_prf_input_callback_arg(ctx, arg)
+
+     where
+
+          int (*cb)(SSL *, void *peerinput, size_t len, void *arg);
+          void *arg;
+
+     Callback function 'cb' will be called in handshakes, and is
+     expected to use SSL_set_tlsext_opaque_prf_input() as appropriate.
+     Argument 'arg' is for application purposes (the value as given to
+     SSL_CTX_set_tlsext_opaque_prf_input_callback_arg() will directly
+     be provided to the callback function).  The callback function
+     has to return non-zero to report success: usually 1 to use opaque
+     PRF input just if possible, or 2 to enforce use of the opaque PRF
+     input.  In the latter case, the library will abort the handshake
+     if opaque PRF input is not successfully negotiated.
+
+     Arguments 'peerinput' and 'len' given to the callback function
+     will always be NULL and 0 in the case of a client.  A server will
+     see the client's opaque PRF input through these variables if
+     available (NULL and 0 otherwise).  Note that if the server
+     provides an opaque PRF input, the length must be the same as the
+     length of the client's opaque PRF input.
+
+     Note that the callback function will only be called when creating
+     a new session (session resumption can resume whatever was
+     previously negotiated), and will not be called in SSL 2.0
+     handshakes; thus, SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2) or
+     SSL_set_options(ssl, SSL_OP_NO_SSLv2) is especially recommended
+     for applications that need to enforce opaque PRF input.
+
+     [Bodo Moeller]
+
+  *) Update ssl code to support digests other than SHA1+MD5 for handshake
+     MAC. 
+
+     [Victor B. Wagner <vitus@cryptocom.ru>]
+
+  *) Add RFC4507 support to OpenSSL. This includes the corrections in
+     RFC4507bis. The encrypted ticket format is an encrypted encoded
+     SSL_SESSION structure, that way new session features are automatically
+     supported.
+
+     If a client application caches session in an SSL_SESSION structure
+     support is transparent because tickets are now stored in the encoded
+     SSL_SESSION.
+     
+     The SSL_CTX structure automatically generates keys for ticket
+     protection in servers so again support should be possible
+     with no application modification.
+
+     If a client or server wishes to disable RFC4507 support then the option
+     SSL_OP_NO_TICKET can be set.
+
+     Add a TLS extension debugging callback to allow the contents of any client
+     or server extensions to be examined.
+
+     This work was sponsored by Google.
+     [Steve Henson]
+
+  *) Final changes to avoid use of pointer pointer casts in OpenSSL.
+     OpenSSL should now compile cleanly on gcc 4.2
+     [Peter Hartley <pdh@utter.chaos.org.uk>, Steve Henson]
+
+  *) Update SSL library to use new EVP_PKEY MAC API. Include generic MAC
+     support including streaming MAC support: this is required for GOST
+     ciphersuite support.
+     [Victor B. Wagner <vitus@cryptocom.ru>, Steve Henson]
+
+  *) Add option -stream to use PKCS#7 streaming in smime utility. New
+     function i2d_PKCS7_bio_stream() and PEM_write_PKCS7_bio_stream()
+     to output in BER and PEM format.
+     [Steve Henson]
+
+  *) Experimental support for use of HMAC via EVP_PKEY interface. This
+     allows HMAC to be handled via the EVP_DigestSign*() interface. The
+     EVP_PKEY "key" in this case is the HMAC key, potentially allowing
+     ENGINE support for HMAC keys which are unextractable. New -mac and
+     -macopt options to dgst utility.
+     [Steve Henson]
+
+  *) New option -sigopt to dgst utility. Update dgst to use
+     EVP_Digest{Sign,Verify}*. These two changes make it possible to use
+     alternative signing paramaters such as X9.31 or PSS in the dgst 
+     utility.
+     [Steve Henson]
+
+  *) Change ssl_cipher_apply_rule(), the internal function that does
+     the work each time a ciphersuite string requests enabling
+     ("foo+bar"), moving ("+foo+bar"), disabling ("-foo+bar", or
+     removing ("!foo+bar") a class of ciphersuites: Now it maintains
+     the order of disabled ciphersuites such that those ciphersuites
+     that most recently went from enabled to disabled not only stay
+     in order with respect to each other, but also have higher priority
+     than other disabled ciphersuites the next time ciphersuites are
+     enabled again.
+
+     This means that you can now say, e.g., "PSK:-PSK:HIGH" to enable
+     the same ciphersuites as with "HIGH" alone, but in a specific
+     order where the PSK ciphersuites come first (since they are the
+     most recently disabled ciphersuites when "HIGH" is parsed).
+
+     Also, change ssl_create_cipher_list() (using this new
+     funcionality) such that between otherwise identical
+     cihpersuites, ephemeral ECDH is preferred over ephemeral DH in
+     the default order.
+     [Bodo Moeller]
+
+  *) Change ssl_create_cipher_list() so that it automatically
+     arranges the ciphersuites in reasonable order before starting
+     to process the rule string.  Thus, the definition for "DEFAULT"
+     (SSL_DEFAULT_CIPHER_LIST) now is just "ALL:!aNULL:!eNULL", but
+     remains equivalent to "AES:ALL:!aNULL:!eNULL:+aECDH:+kRSA:+RC4:@STRENGTH".
+     This makes it much easier to arrive at a reasonable default order
+     in applications for which anonymous ciphers are OK (meaning
+     that you can't actually use DEFAULT).
+     [Bodo Moeller; suggested by Victor Duchovni]
+
+  *) Split the SSL/TLS algorithm mask (as used for ciphersuite string
+     processing) into multiple integers instead of setting
+     "SSL_MKEY_MASK" bits, "SSL_AUTH_MASK" bits, "SSL_ENC_MASK",
+     "SSL_MAC_MASK", and "SSL_SSL_MASK" bits all in a single integer.
+     (These masks as well as the individual bit definitions are hidden
+     away into the non-exported interface ssl/ssl_locl.h, so this
+     change to the definition of the SSL_CIPHER structure shouldn't
+     affect applications.)  This give us more bits for each of these
+     categories, so there is no longer a need to coagulate AES128 and
+     AES256 into a single algorithm bit, and to coagulate Camellia128
+     and Camellia256 into a single algorithm bit, which has led to all
+     kinds of kludges.
+
+     Thus, among other things, the kludge introduced in 0.9.7m and
+     0.9.8e for masking out AES256 independently of AES128 or masking
+     out Camellia256 independently of AES256 is not needed here in 0.9.9.
+
+     With the change, we also introduce new ciphersuite aliases that
+     so far were missing: "AES128", "AES256", "CAMELLIA128", and
+     "CAMELLIA256".
+     [Bodo Moeller]
+
+  *) Add support for dsa-with-SHA224 and dsa-with-SHA256.
+     Use the leftmost N bytes of the signature input if the input is
+     larger than the prime q (with N being the size in bytes of q).
+     [Nils Larsch]
+
+  *) Very *very* experimental PKCS#7 streaming encoder support. Nothing uses
+     it yet and it is largely untested.
+     [Steve Henson]
+
+  *) Add support for the ecdsa-with-SHA224/256/384/512 signature types.
+     [Nils Larsch]
+
+  *) Initial incomplete changes to avoid need for function casts in OpenSSL
+     some compilers (gcc 4.2 and later) reject their use. Safestack is
+     reimplemented.  Update ASN1 to avoid use of legacy functions. 
+     [Steve Henson]
+
+  *) Win32/64 targets are linked with Winsock2.
+     [Andy Polyakov]
+
+  *) Add an X509_CRL_METHOD structure to allow CRL processing to be redirected
+     to external functions. This can be used to increase CRL handling 
+     efficiency especially when CRLs are very large by (for example) storing
+     the CRL revoked certificates in a database.
+     [Steve Henson]
+
+  *) Overhaul of by_dir code. Add support for dynamic loading of CRLs so
+     new CRLs added to a directory can be used. New command line option
+     -verify_return_error to s_client and s_server. This causes real errors
+     to be returned by the verify callback instead of carrying on no matter
+     what. This reflects the way a "real world" verify callback would behave.
+     [Steve Henson]
+
+  *) GOST engine, supporting several GOST algorithms and public key formats.
+     Kindly donated by Cryptocom.
+     [Cryptocom]
+
+  *) Partial support for Issuing Distribution Point CRL extension. CRLs
+     partitioned by DP are handled but no indirect CRL or reason partitioning
+     (yet). Complete overhaul of CRL handling: now the most suitable CRL is
+     selected via a scoring technique which handles IDP and AKID in CRLs.
+     [Steve Henson]
+
+  *) New X509_STORE_CTX callbacks lookup_crls() and lookup_certs() which
+     will ultimately be used for all verify operations: this will remove the
+     X509_STORE dependency on certificate verification and allow alternative
+     lookup methods.  X509_STORE based implementations of these two callbacks.
+     [Steve Henson]
+
+  *) Allow multiple CRLs to exist in an X509_STORE with matching issuer names.
+     Modify get_crl() to find a valid (unexpired) CRL if possible.
+     [Steve Henson]
+
+  *) New function X509_CRL_match() to check if two CRLs are identical. Normally
+     this would be called X509_CRL_cmp() but that name is already used by
+     a function that just compares CRL issuer names. Cache several CRL 
+     extensions in X509_CRL structure and cache CRLDP in X509.
+     [Steve Henson]
+
+  *) Store a "canonical" representation of X509_NAME structure (ASN1 Name)
+     this maps equivalent X509_NAME structures into a consistent structure.
+     Name comparison can then be performed rapidly using memcmp().
+     [Steve Henson]
+
+  *) Non-blocking OCSP request processing. Add -timeout option to ocsp 
+     utility.
+     [Steve Henson]
+
+  *) Allow digests to supply their own micalg string for S/MIME type using
+     the ctrl EVP_MD_CTRL_MICALG.
+     [Steve Henson]
+
+  *) During PKCS7 signing pass the PKCS7 SignerInfo structure to the
+     EVP_PKEY_METHOD before and after signing via the EVP_PKEY_CTRL_PKCS7_SIGN
+     ctrl. It can then customise the structure before and/or after signing
+     if necessary.
+     [Steve Henson]
+
+  *) New function OBJ_add_sigid() to allow application defined signature OIDs
+     to be added to OpenSSLs internal tables. New function OBJ_sigid_free()
+     to free up any added signature OIDs.
+     [Steve Henson]
+
+  *) New functions EVP_CIPHER_do_all(), EVP_CIPHER_do_all_sorted(),
+     EVP_MD_do_all() and EVP_MD_do_all_sorted() to enumerate internal
+     digest and cipher tables. New options added to openssl utility:
+     list-message-digest-algorithms and list-cipher-algorithms.
+     [Steve Henson]
+
+  *) Change the array representation of binary polynomials: the list
+     of degrees of non-zero coefficients is now terminated with -1.
+     Previously it was terminated with 0, which was also part of the
+     value; thus, the array representation was not applicable to
+     polynomials where t^0 has coefficient zero.  This change makes
+     the array representation useful in a more general context.
+     [Douglas Stebila]
+
+  *) Various modifications and fixes to SSL/TLS cipher string
+     handling.  For ECC, the code now distinguishes between fixed ECDH
+     with RSA certificates on the one hand and with ECDSA certificates
+     on the other hand, since these are separate ciphersuites.  The
+     unused code for Fortezza ciphersuites has been removed.
+
+     For consistency with EDH, ephemeral ECDH is now called "EECDH"
+     (not "ECDHE").  For consistency with the code for DH
+     certificates, use of ECDH certificates is now considered ECDH
+     authentication, not RSA or ECDSA authentication (the latter is
+     merely the CA's signing algorithm and not actively used in the
+     protocol).
+
+     The temporary ciphersuite alias "ECCdraft" is no longer
+     available, and ECC ciphersuites are no longer excluded from "ALL"
+     and "DEFAULT".  The following aliases now exist for RFC 4492
+     ciphersuites, most of these by analogy with the DH case:
+
+         kECDHr   - ECDH cert, signed with RSA
+         kECDHe   - ECDH cert, signed with ECDSA
+         kECDH    - ECDH cert (signed with either RSA or ECDSA)
+         kEECDH   - ephemeral ECDH
+         ECDH     - ECDH cert or ephemeral ECDH
+
+         aECDH    - ECDH cert
+         aECDSA   - ECDSA cert
+         ECDSA    - ECDSA cert
+
+         AECDH    - anonymous ECDH
+         EECDH    - non-anonymous ephemeral ECDH (equivalent to "kEECDH:-AECDH")
+
+     [Bodo Moeller]
+
+  *) Add additional S/MIME capabilities for AES and GOST ciphers if supported.
+     Use correct micalg parameters depending on digest(s) in signed message.
+     [Steve Henson]
+
+  *) Add engine support for EVP_PKEY_ASN1_METHOD. Add functions to process
+     an ENGINE asn1 method. Support ENGINE lookups in the ASN1 code.
+     [Steve Henson]
+
+  *) Initial engine support for EVP_PKEY_METHOD. New functions to permit
+     an engine to register a method. Add ENGINE lookups for methods and
+     functional reference processing.
+     [Steve Henson]
+
+  *) New functions EVP_Digest{Sign,Verify)*. These are enchance versions of
+     EVP_{Sign,Verify}* which allow an application to customise the signature
+     process.
+     [Steve Henson]
+
+  *) New -resign option to smime utility. This adds one or more signers
+     to an existing PKCS#7 signedData structure. Also -md option to use an
+     alternative message digest algorithm for signing.
+     [Steve Henson]
+
+  *) Tidy up PKCS#7 routines and add new functions to make it easier to
+     create PKCS7 structures containing multiple signers. Update smime
+     application to support multiple signers.
+     [Steve Henson]
+
+  *) New -macalg option to pkcs12 utility to allow setting of an alternative
+     digest MAC.
+     [Steve Henson]
+
+  *) Initial support for PKCS#5 v2.0 PRFs other than default SHA1 HMAC.
+     Reorganize PBE internals to lookup from a static table using NIDs,
+     add support for HMAC PBE OID translation. Add a EVP_CIPHER ctrl:
+     EVP_CTRL_PBE_PRF_NID this allows a cipher to specify an alternative
+     PRF which will be automatically used with PBES2.
+     [Steve Henson]
+
+  *) Replace the algorithm specific calls to generate keys in "req" with the
+     new API.
+     [Steve Henson]
+
+  *) Update PKCS#7 enveloped data routines to use new API. This is now
+     supported by any public key method supporting the encrypt operation. A
+     ctrl is added to allow the public key algorithm to examine or modify
+     the PKCS#7 RecipientInfo structure if it needs to: for RSA this is
+     a no op.
+     [Steve Henson]
+
+  *) Add a ctrl to asn1 method to allow a public key algorithm to express
+     a default digest type to use. In most cases this will be SHA1 but some
+     algorithms (such as GOST) need to specify an alternative digest. The
+     return value indicates how strong the prefernce is 1 means optional and
+     2 is mandatory (that is it is the only supported type). Modify
+     ASN1_item_sign() to accept a NULL digest argument to indicate it should
+     use the default md. Update openssl utilities to use the default digest
+     type for signing if it is not explicitly indicated.
+     [Steve Henson]
+
+  *) Use OID cross reference table in ASN1_sign() and ASN1_verify(). New 
+     EVP_MD flag EVP_MD_FLAG_PKEY_METHOD_SIGNATURE. This uses the relevant
+     signing method from the key type. This effectively removes the link
+     between digests and public key types.
+     [Steve Henson]
+
+  *) Add an OID cross reference table and utility functions. Its purpose is to
+     translate between signature OIDs such as SHA1WithrsaEncryption and SHA1,
+     rsaEncryption. This will allow some of the algorithm specific hackery
+     needed to use the correct OID to be removed. 
+     [Steve Henson]
+
+  *) Remove algorithm specific dependencies when setting PKCS7_SIGNER_INFO
+     structures for PKCS7_sign(). They are now set up by the relevant public
+     key ASN1 method.
+     [Steve Henson]
+
+  *) Add provisional EC pkey method with support for ECDSA and ECDH.
+     [Steve Henson]
+
+  *) Add support for key derivation (agreement) in the API, DH method and
+     pkeyutl.
+     [Steve Henson]
+
+  *) Add DSA pkey method and DH pkey methods, extend DH ASN1 method to support
+     public and private key formats. As a side effect these add additional 
+     command line functionality not previously available: DSA signatures can be
+     generated and verified using pkeyutl and DH key support and generation in
+     pkey, genpkey.
+     [Steve Henson]
+
+  *) BeOS support.
+     [Oliver Tappe <zooey@hirschkaefer.de>]
+
+  *) New make target "install_html_docs" installs HTML renditions of the
+     manual pages.
+     [Oliver Tappe <zooey@hirschkaefer.de>]
+
+  *) New utility "genpkey" this is analagous to "genrsa" etc except it can
+     generate keys for any algorithm. Extend and update EVP_PKEY_METHOD to
+     support key and parameter generation and add initial key generation
+     functionality for RSA.
+     [Steve Henson]
+
+  *) Add functions for main EVP_PKEY_method operations. The undocumented
+     functions EVP_PKEY_{encrypt,decrypt} have been renamed to
+     EVP_PKEY_{encrypt,decrypt}_old. 
+     [Steve Henson]
+
+  *) Initial definitions for EVP_PKEY_METHOD. This will be a high level public
+     key API, doesn't do much yet.
+     [Steve Henson]
+
+  *) New function EVP_PKEY_asn1_get0_info() to retrieve information about
+     public key algorithms. New option to openssl utility:
+     "list-public-key-algorithms" to print out info.
+     [Steve Henson]
+
+  *) Implement the Supported Elliptic Curves Extension for
+     ECC ciphersuites from draft-ietf-tls-ecc-12.txt.
+     [Douglas Stebila]
+
+  *) Don't free up OIDs in OBJ_cleanup() if they are in use by EVP_MD or
+     EVP_CIPHER structures to avoid later problems in EVP_cleanup().
+     [Steve Henson]
+
+  *) New utilities pkey and pkeyparam. These are similar to algorithm specific
+     utilities such as rsa, dsa, dsaparam etc except they process any key
+     type.
+     [Steve Henson]
+
+  *) Transfer public key printing routines to EVP_PKEY_ASN1_METHOD. New 
+     functions EVP_PKEY_print_public(), EVP_PKEY_print_private(),
+     EVP_PKEY_print_param() to print public key data from an EVP_PKEY
+     structure.
+     [Steve Henson]
+
+  *) Initial support for pluggable public key ASN1.
+     De-spaghettify the public key ASN1 handling. Move public and private
+     key ASN1 handling to a new EVP_PKEY_ASN1_METHOD structure. Relocate
+     algorithm specific handling to a single module within the relevant
+     algorithm directory. Add functions to allow (near) opaque processing
+     of public and private key structures.
+     [Steve Henson]
+
+  *) Implement the Supported Point Formats Extension for
+     ECC ciphersuites from draft-ietf-tls-ecc-12.txt.
+     [Douglas Stebila]
+
+  *) Add initial support for RFC 4279 PSK TLS ciphersuites. Add members
+     for the psk identity [hint] and the psk callback functions to the
+     SSL_SESSION, SSL and SSL_CTX structure.
+     
+     New ciphersuites:
+         PSK-RC4-SHA, PSK-3DES-EDE-CBC-SHA, PSK-AES128-CBC-SHA,
+         PSK-AES256-CBC-SHA
+     New functions:
+         SSL_CTX_use_psk_identity_hint
+         SSL_get_psk_identity_hint
+         SSL_get_psk_identity
+         SSL_use_psk_identity_hint
+
+     [Mika Kousa and Pasi Eronen of Nokia Corporation]
+
+  *) Add RFC 3161 compliant time stamp request creation, response generation
+     and response verification functionality.
+     [Zoltán Glózik <zglozik@opentsa.org>, The OpenTSA Project]
+
+  *) Add initial support for TLS extensions, specifically for the server_name
+     extension so far.  The SSL_SESSION, SSL_CTX, and SSL data structures now
+     have new members for a host name.  The SSL data structure has an
+     additional member SSL_CTX *initial_ctx so that new sessions can be
+     stored in that context to allow for session resumption, even after the
+     SSL has been switched to a new SSL_CTX in reaction to a client's
+     server_name extension.
+
+     New functions (subject to change):
+
+         SSL_get_servername()
+         SSL_get_servername_type()
+         SSL_set_SSL_CTX()
+
+     New CTRL codes and macros (subject to change):
+
+         SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
+                                 - SSL_CTX_set_tlsext_servername_callback()
+         SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG
+                                      - SSL_CTX_set_tlsext_servername_arg()
+         SSL_CTRL_SET_TLSEXT_HOSTNAME           - SSL_set_tlsext_host_name()
+
+     openssl s_client has a new '-servername ...' option.
+
+     openssl s_server has new options '-servername_host ...', '-cert2 ...',
+     '-key2 ...', '-servername_fatal' (subject to change).  This allows
+     testing the HostName extension for a specific single host name ('-cert'
+     and '-key' remain fallbacks for handshakes without HostName
+     negotiation).  If the unrecogninzed_name alert has to be sent, this by
+     default is a warning; it becomes fatal with the '-servername_fatal'
+     option.
+
+     [Peter Sylvester,  Remy Allais, Christophe Renou]
+
+  *) Whirlpool hash implementation is added.
+     [Andy Polyakov]
+
+  *) BIGNUM code on 64-bit SPARCv9 targets is switched from bn(64,64) to
+     bn(64,32). Because of instruction set limitations it doesn't have
+     any negative impact on performance. This was done mostly in order
+     to make it possible to share assembler modules, such as bn_mul_mont
+     implementations, between 32- and 64-bit builds without hassle.
+     [Andy Polyakov]
+
+  *) Move code previously exiled into file crypto/ec/ec2_smpt.c
+     to ec2_smpl.c, and no longer require the OPENSSL_EC_BIN_PT_COMP
+     macro.
+     [Bodo Moeller]
+
+  *) New candidate for BIGNUM assembler implementation, bn_mul_mont,
+     dedicated Montgomery multiplication procedure, is introduced.
+     BN_MONT_CTX is modified to allow bn_mul_mont to reach for higher
+     "64-bit" performance on certain 32-bit targets.
+     [Andy Polyakov]
+
+  *) New option SSL_OP_NO_COMP to disable use of compression selectively
+     in SSL structures. New SSL ctrl to set maximum send fragment size. 
+     Save memory by seeting the I/O buffer sizes dynamically instead of
+     using the maximum available value.
+     [Steve Henson]
+
+  *) New option -V for 'openssl ciphers'. This prints the ciphersuite code
+     in addition to the text details.
+     [Bodo Moeller]
+
+  *) Very, very preliminary EXPERIMENTAL support for printing of general
+     ASN1 structures. This currently produces rather ugly output and doesn't
+     handle several customised structures at all.
+     [Steve Henson]
+
+  *) Integrated support for PVK file format and some related formats such
+     as MS PUBLICKEYBLOB and PRIVATEKEYBLOB. Command line switches to support
+     these in the 'rsa' and 'dsa' utilities.
+     [Steve Henson]
+
+  *) Support for PKCS#1 RSAPublicKey format on rsa utility command line.
+     [Steve Henson]
+
+  *) Remove the ancient ASN1_METHOD code. This was only ever used in one
+     place for the (very old) "NETSCAPE" format certificates which are now
+     handled using new ASN1 code equivalents.
+     [Steve Henson]
+
+  *) Let the TLSv1_method() etc. functions return a 'const' SSL_METHOD
+     pointer and make the SSL_METHOD parameter in SSL_CTX_new,
+     SSL_CTX_set_ssl_version and SSL_set_ssl_method 'const'.
+     [Nils Larsch]
+
+  *) Modify CRL distribution points extension code to print out previously
+     unsupported fields. Enhance extension setting code to allow setting of
+     all fields.
+     [Steve Henson]
+
+  *) Add print and set support for Issuing Distribution Point CRL extension.
+     [Steve Henson]
+
+  *) Change 'Configure' script to enable Camellia by default.
+     [NTT]
+  
+ Changes between 0.9.8r and 0.9.8s [xx XXX xxxx]
+
+  *) Fix ssl_ciph.c set-up race.
+     [Adam Langley (Google)]
+
+  *) Fix spurious failures in ecdsatest.c.
+     [Emilia Käsper (Google)]
+
+  *) Fix the BIO_f_buffer() implementation (which was mixing different
+     interpretations of the '..._len' fields).
+     [Adam Langley (Google)]
+
+  *) Fix handling of BN_BLINDING: now BN_BLINDING_invert_ex (rather than
+     BN_BLINDING_invert_ex) calls BN_BLINDING_update, ensuring that concurrent
+     threads won't reuse the same blinding coefficients.
+
+     This also avoids the need to obtain the CRYPTO_LOCK_RSA_BLINDING
+     lock to call BN_BLINDING_invert_ex, and avoids one use of
+     BN_BLINDING_update for each BN_BLINDING structure (previously,
+     the last update always remained unused).
+     [Emilia Käsper (Google)]
+
+  *) Fix SSL memory handling for (EC)DH ciphersuites, in particular
+     for multi-threaded use of ECDH.
+     [Adam Langley (Google)]
+
+  *) Fix x509_name_ex_d2i memory leak on bad inputs.
+     [Bodo Moeller]
+
+  *) Add protection against ECDSA timing attacks as mentioned in the paper
+     by Billy Bob Brumley and Nicola Tuveri, see:
+
+       http://eprint.iacr.org/2011/232.pdf
+
+     [Billy Bob Brumley and Nicola Tuveri]
+
  Changes between 0.9.8q and 0.9.8r [8 Feb 2011]
 
-  *) Fix parsing of OCSP stapling ClientHello extension.  CVE-2011-0014
+  *) Fix parsing of OCSP stapling ClientHello extension. CVE-2011-0014
      [Neel Mehta, Adam Langley, Bodo Moeller (Google)]
 
   *) Fix bug in string printing code: if *any* escaping is enabled we must
index dbb80b0..ca5cd72 100644 (file)
@@ -148,7 +148,7 @@ eric (about to go bushwalking for the 4 day easter break :-)
       This would tend to cause memory overwrites since SSLv3 has
       a maximum packet size of 16k.  If your program uses
       buffers <= 16k, you would probably never see this problem.
-    - Fixed a new errors that were cause by malloc() not returning
+    - Fixed a few errors that were cause by malloc() not returning
       0 initialised memory..
     - SSL_OP_NETSCAPE_CA_DN_BUG was being switched on when using
       SSL_CTX_set_options(ssl_ctx,SSL_OP_ALL); which was a bad thing
index ec87f24..7941c93 100755 (executable)
@@ -6,13 +6,11 @@ eval 'exec perl -S $0 ${1+"$@"}'
 ##
 
 require 5.000;
-eval 'use strict;';
-
-print STDERR "Warning: perl module strict not found.\n" if ($@);
+use strict;
 
 # see INSTALL for instructions.
 
-my $usage="Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [experimental-<cipher> ...] [-Dxxx] [-lxxx] [-Lxxx] [-fxxx] [-Kxxx] [no-hw-xxx|no-hw] [[no-]threads] [[no-]shared] [[no-]zlib|zlib-dynamic] [enable-montasm] [no-asm] [no-dso] [no-krb5] [386] [--prefix=DIR] [--openssldir=OPENSSLDIR] [--with-xxx[=vvv]] [--test-sanity] os/compiler[:flags]\n";
+my $usage="Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [experimental-<cipher> ...] [-Dxxx] [-lxxx] [-Lxxx] [-fxxx] [-Kxxx] [no-hw-xxx|no-hw] [[no-]threads] [[no-]shared] [[no-]zlib|zlib-dynamic] [no-asm] [no-dso] [no-krb5] [386] [--prefix=DIR] [--openssldir=OPENSSLDIR] [--with-xxx[=vvv]] [--test-sanity] os/compiler[:flags]\n";
 
 # Options:
 #
@@ -40,6 +38,8 @@ my $usage="Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [experimenta
 # --test-sanity Make a number of sanity checks on the data in this file.
 #               This is a debugging tool for OpenSSL developers.
 #
+# --cross-compile-prefix Add specified prefix to binutils components.
+#
 # no-hw-xxx     do not compile support for specific crypto hardware.
 #               Generic OpenSSL-style methods relating to this support
 #               are always compiled but return NULL if the hardware
@@ -56,8 +56,6 @@ my $usage="Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [experimenta
 # [no-]zlib     [don't] compile support for zlib compression.
 # zlib-dynamic Like "zlib", but the zlib library is expected to be a shared
 #              library and will be loaded in run-time by the OpenSSL library.
-# enable-montasm 0.9.8 branch only: enable Montgomery x86 assembler backport
-#               from 0.9.9
 # 386           generate 80386 code
 # no-sse2      disables IA-32 SSE2 code, above option implies no-sse2
 # no-<cipher>   build without specified algorithm (rsa, idea, rc5, ...)
@@ -125,14 +123,21 @@ my $tlib="-lnsl -lsocket";
 my $bits1="THIRTY_TWO_BIT ";
 my $bits2="SIXTY_FOUR_BIT ";
 
-my $x86_elf_asm="x86cpuid-elf.o:bn86-elf.o co86-elf.o MAYBE-MO86-elf.o:dx86-elf.o yx86-elf.o:ax86-elf.o:bx86-elf.o:mx86-elf.o:sx86-elf.o s512sse2-elf.o:cx86-elf.o:rx86-elf.o rc4_skey.o:rm86-elf.o:r586-elf.o";
-my $x86_coff_asm="x86cpuid-cof.o:bn86-cof.o co86-cof.o MAYBE-MO86-cof.o:dx86-cof.o yx86-cof.o:ax86-cof.o:bx86-cof.o:mx86-cof.o:sx86-cof.o s512sse2-cof.o:cx86-cof.o:rx86-cof.o rc4_skey.o:rm86-cof.o:r586-cof.o";
-my $x86_out_asm="x86cpuid-out.o:bn86-out.o co86-out.o MAYBE-MO86-out.o:dx86-out.o yx86-out.o:ax86-out.o:bx86-out.o:mx86-out.o:sx86-out.o s512sse2-out.o:cx86-out.o:rx86-out.o rc4_skey.o:rm86-out.o:r586-out.o";
+my $x86_asm="x86cpuid.o:bn-586.o co-586.o x86-mont.o:des-586.o crypt586.o:aes-586.o:bf-586.o:md5-586.o:sha1-586.o sha256-586.o sha512-586.o:cast-586.o:rc4-586.o:rmd-586.o:rc5-586.o:wp_block.o wp-mmx.o:cmll-x86.o";
 
-my $x86_64_asm="x86_64cpuid.o:x86_64-gcc.o x86_64-mont.o::aes-x86_64.o::md5-x86_64.o:sha1-x86_64.o sha256-x86_64.o sha512-x86_64.o::rc4-x86_64.o::";
-my $ia64_asm=":bn-ia64.o::aes_core.o aes_cbc.o aes-ia64.o:::sha1-ia64.o sha256-ia64.o sha512-ia64.o::rc4-ia64.o rc4_skey.o::";
+my $x86_elf_asm="$x86_asm:elf";
 
-my $no_asm="::::::::::";
+my $x86_64_asm="x86_64cpuid.o:x86_64-gcc.o x86_64-mont.o::aes-x86_64.o::md5-x86_64.o:sha1-x86_64.o sha256-x86_64.o sha512-x86_64.o::rc4-x86_64.o:::wp-x86_64.o:cmll-x86_64.o cmll_misc.o";
+my $ia64_asm="ia64cpuid.o:bn-ia64.o::aes_core.o aes_cbc.o aes-ia64.o::md5-ia64.o:sha1-ia64.o sha256-ia64.o sha512-ia64.o::rc4-ia64.o rc4_skey.o:::::void";
+my $sparcv9_asm="sparcv9cap.o sparccpuid.o:bn-sparcv9.o sparcv9-mont.o sparcv9a-mont.o:des_enc-sparc.o fcrypt_b.o:aes_core.o aes_cbc.o aes-sparcv9.o:::sha1-sparcv9.o sha256-sparcv9.o sha512-sparcv9.o:::::::void";
+my $sparcv8_asm=":sparcv8.o:des_enc-sparc.o fcrypt_b.o:::::::::::void";
+my $alpha_asm="alphacpuid.o:bn_asm.o alpha-mont.o::::::::::::void";
+my $mips3_asm=":bn-mips3.o::::::::::::void";
+my $s390x_asm="s390xcap.o s390xcpuid.o:bn-s390x.o s390x-mont.o::aes-s390x.o:::sha1-s390x.o sha256-s390x.o sha512-s390x.o::rc4-s390x.o:::::void";
+my $armv4_asm=":bn_asm.o armv4-mont.o::aes_cbc.o aes-armv4.o:::sha1-armv4-large.o sha256-armv4.o sha512-armv4.o:::::::void";
+my $ppc32_asm="ppccpuid.o:bn-ppc.o::aes_core.o aes_cbc.o aes-ppc.o:::sha1-ppc.o sha256-ppc.o::::::";
+my $ppc64_asm="ppccpuid.o:bn-ppc.o ppc-mont.o::aes_core.o aes_cbc.o aes-ppc.o:::sha1-ppc.o sha256-ppc.o sha512-ppc.o::::::";
+my $no_asm=":::::::::::::void";
 
 # As for $BSDthreads. Idea is to maintain "collective" set of flags,
 # which would cover all BSD flavors. -pthread applies to them all, 
@@ -143,7 +148,7 @@ my $no_asm="::::::::::";
 # seems to be sufficient?
 my $BSDthreads="-pthread -D_THREAD_SAFE -D_REENTRANT";
 
-#config-string $cc : $cflags : $unistd : $thread_cflag : $sys_id : $lflags : $bn_ops : $cpuid_obj : $bn_obj : $des_obj : $aes_obj : $bf_obj : $md5_obj : $sha1_obj : $cast_obj : $rc4_obj : $rmd160_obj : $rc5_obj : $dso_scheme : $shared_target : $shared_cflag : $shared_ldflag : $shared_extension : $ranlib : $arflags
+#config-string $cc : $cflags : $unistd : $thread_cflag : $sys_id : $lflags : $bn_ops : $cpuid_obj : $bn_obj : $des_obj : $aes_obj : $bf_obj : $md5_obj : $sha1_obj : $cast_obj : $rc4_obj : $rmd160_obj : $rc5_obj : $wp_obj : $cmll_obj : $dso_scheme : $shared_target : $shared_cflag : $shared_ldflag : $shared_extension : $ranlib : $arflags : $multilib
 
 my %table=(
 # File 'TABLE' (created by 'make TABLE') contains the data from this list,
@@ -158,32 +163,32 @@ my %table=(
 # Our development configs
 "purify",      "purify gcc:-g -DPURIFY -Wall::(unknown)::-lsocket -lnsl::::",
 "debug",       "gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DOPENSSL_NO_ASM -ggdb -g2 -Wformat -Wshadow -Wmissing-prototypes -Wmissing-declarations -Werror::(unknown)::-lefence::::",
-"debug-ben",   "gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DPEDANTIC -DDEBUG_SAFESTACK -O2 -pedantic -Wall -Wshadow -Werror -pipe::(unknown):::::bn86-elf.o co86-elf.o",
+"debug-ben",   "gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DPEDANTIC -DDEBUG_SAFESTACK -DDEBUG_UNUSED -O2 -pedantic -Wall -Wshadow -Werror -pipe::(unknown):::::bn86-elf.o co86-elf.o",
 "debug-ben-openbsd","gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DPEDANTIC -DDEBUG_SAFESTACK -DOPENSSL_OPENBSD_DEV_CRYPTO -DOPENSSL_NO_ASM -O2 -pedantic -Wall -Wshadow -Werror -pipe::(unknown)::::",
 "debug-ben-openbsd-debug","gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DPEDANTIC -DDEBUG_SAFESTACK -DOPENSSL_OPENBSD_DEV_CRYPTO -DOPENSSL_NO_ASM -g3 -O2 -pedantic -Wall -Wshadow -Werror -pipe::(unknown)::::",
-"debug-ben-debug",     "gcc:$gcc_devteam_warn -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG  -DDEBUG_SAFESTACK -ggdb3 -O2 -pipe::(unknown)::::::",
-"debug-ben-debug-noopt",       "gcc:$gcc_devteam_warn -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG  -DDEBUG_SAFESTACK -ggdb3 -pipe::(unknown)::::::",
+"debug-ben-debug",     "gcc44:$gcc_devteam_warn -DBN_DEBUG -DCONF_DEBUG -DDEBUG_SAFESTACK -DDEBUG_UNUSED -g3 -O2 -pipe::(unknown)::::::",
+"debug-ben-no-opt",    "gcc: -Wall -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -DDEBUG_SAFESTACK -DCRYPTO_MDEBUG -Werror -DL_ENDIAN -DTERMIOS -Wall -g3::(unknown)::::::",
 "debug-ben-strict",    "gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DCONST_STRICT -O2 -Wall -Wshadow -Werror -Wpointer-arith -Wcast-qual -Wwrite-strings -pipe::(unknown)::::::",
 "debug-rse","cc:-DTERMIOS -DL_ENDIAN -pipe -O -g -ggdb3 -Wall::(unknown):::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}",
-"debug-bodo",  "gcc:-DL_ENDIAN -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBIO_PAIR_DEBUG -DPEDANTIC -g -march=i486 -pedantic -Wshadow -Wall -Wcast-align -Wstrict-prototypes -Wmissing-prototypes -Wno-long-long -Wundef -Wconversion -pipe::-D_REENTRANT:::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}",
+"debug-bodo",  "gcc:-DL_ENDIAN -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBIO_PAIR_DEBUG -DPEDANTIC -g -march=i486 -pedantic -Wshadow -Wall -Wcast-align -Wstrict-prototypes -Wmissing-prototypes -Wno-long-long -Wundef -Wconversion::-D_REENTRANT:::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}",
 "debug-ulf", "gcc:-DTERMIOS -DL_ENDIAN -march=i486 -Wall -DBN_DEBUG -DBN_DEBUG_RAND -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DOPENSSL_NO_ASM -g -Wformat -Wshadow -Wmissing-prototypes -Wmissing-declarations:::CYGWIN32:::${no_asm}:win32:cygwin-shared:::.dll",
-"debug-steve64", "gcc:$gcc_devteam_warn -m64 -DL_ENDIAN -DTERMIO -DCONF_DEBUG -DDEBUG_SAFESTACK -g -DMD32_REG_T=int::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:dlfcn:linux-shared:-fPIC:-m64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"debug-steve64", "gcc:$gcc_devteam_warn -m64 -DL_ENDIAN -DTERMIO -DCONF_DEBUG -DDEBUG_SAFESTACK -g -DMD32_REG_T=int::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:elf:dlfcn:linux-shared:-fPIC:-m64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
 "debug-steve32", "gcc:$gcc_devteam_warn -m32 -DL_ENDIAN -DCONF_DEBUG -DDEBUG_SAFESTACK -g -pipe::-D_REENTRANT::-rdynamic -ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn:linux-shared:-fPIC:-m32:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"debug-steve-opt", "gcc:$gcc_devteam_warn -m64 -O3 -DL_ENDIAN -DTERMIO -DCONF_DEBUG -DDEBUG_SAFESTACK -g -DMD32_REG_T=int::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:dlfcn:linux-shared:-fPIC:-m64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"debug-steve", "gcc:-DL_ENDIAN -DREF_CHECK -DCONF_DEBUG -DDEBUG_SAFESTACK -DCRYPTO_MDEBUG_ALL -DPEDANTIC -m32 -g -pedantic -Wno-long-long -Wall -Werror -Wshadow -pipe::-D_REENTRANT::-rdynamic -ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn:linux-shared",
-"debug-steve-linux-pseudo64",  "gcc:-DL_ENDIAN -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DDEBUG_SAFESTACK -DCRYPTO_MDEBUG_ALL -DOPENSSL_NO_ASM -g -mcpu=i486 -Wall -Werror -Wshadow -pipe::-D_REENTRANT::-rdynamic -ldl:SIXTY_FOUR_BIT:${no_asm}:dlfcn:linux-shared",
+"debug-steve-opt", "gcc:$gcc_devteam_warn -m64 -O3 -DL_ENDIAN -DTERMIO -DCONF_DEBUG -DDEBUG_SAFESTACK -g -DMD32_REG_T=int::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:elf:dlfcn:linux-shared:-fPIC:-m64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
 "debug-levitte-linux-elf","gcc:-DLEVITTE_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_DEBUG -DBN_DEBUG_RAND -DCRYPTO_MDEBUG -DENGINE_CONF_DEBUG -DL_ENDIAN -DTERMIO -D_POSIX_SOURCE -DPEDANTIC -ggdb -g3 -mcpu=i486 -pedantic -ansi -Wall -Wshadow -Wcast-align -Wstrict-prototypes -Wmissing-prototypes -Wno-long-long -Wundef -Wconversion -pipe::-D_REENTRANT::-ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
 "debug-levitte-linux-noasm","gcc:-DLEVITTE_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_DEBUG -DBN_DEBUG_RAND -DCRYPTO_MDEBUG -DENGINE_CONF_DEBUG -DOPENSSL_NO_ASM -DL_ENDIAN -DTERMIO -D_POSIX_SOURCE -DPEDANTIC -ggdb -g3 -mcpu=i486 -pedantic -ansi -Wall -Wshadow -Wcast-align -Wstrict-prototypes -Wmissing-prototypes -Wno-long-long -Wundef -Wconversion -pipe::-D_REENTRANT::-ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${no_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
 "debug-levitte-linux-elf-extreme","gcc:-DLEVITTE_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_DEBUG -DBN_DEBUG_RAND -DCRYPTO_MDEBUG -DENGINE_CONF_DEBUG -DL_ENDIAN -DTERMIO -D_POSIX_SOURCE -DPEDANTIC -ggdb -g3 -mcpu=i486 -pedantic -ansi -Wall -W -Wundef -Wshadow -Wcast-align -Wstrict-prototypes -Wmissing-prototypes -Wno-long-long -Wundef -Wconversion -pipe::-D_REENTRANT::-ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
 "debug-levitte-linux-noasm-extreme","gcc:-DLEVITTE_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_DEBUG -DBN_DEBUG_RAND -DCRYPTO_MDEBUG -DENGINE_CONF_DEBUG -DOPENSSL_NO_ASM -DL_ENDIAN -DTERMIO -D_POSIX_SOURCE -DPEDANTIC -ggdb -g3 -mcpu=i486 -pedantic -ansi -Wall -W -Wundef -Wshadow -Wcast-align -Wstrict-prototypes -Wmissing-prototypes -Wno-long-long -Wundef -Wconversion -pipe::-D_REENTRANT::-ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${no_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"debug-geoff","gcc:-DBN_DEBUG -DBN_DEBUG_RAND -DBN_STRICT -DPURIFY -DOPENSSL_NO_DEPRECATED -DOPENSSL_NO_ASM -DOPENSSL_NO_INLINE_ASM -DL_ENDIAN -DTERMIO -DPEDANTIC -O1 -ggdb2 -Wall -Werror -Wundef -pedantic -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wsign-compare -Wmissing-prototypes -Wmissing-declarations -Wno-long-long::-D_REENTRANT::-ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${no_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"debug-linux-pentium","gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -DL_ENDIAN -DTERMIO -g -mcpu=pentium -Wall::-D_REENTRANT::-ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn",
-"debug-linux-ppro","gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -DL_ENDIAN -DTERMIO -g -mcpu=pentiumpro -Wall::-D_REENTRANT::-ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn",
-"debug-linux-elf","gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -DL_ENDIAN -DTERMIO -g -march=i486 -Wall::-D_REENTRANT::-lefence -ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"debug-linux-elf-noefence","gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -DL_ENDIAN -DTERMIO -g -march=i486 -Wall::-D_REENTRANT::-ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"debug-linux-generic32","gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -DTERMIO  -g -Wall::-D_REENTRANT::-ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL BF_PTR:${no_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"debug-geoff32","gcc:-DBN_DEBUG -DBN_DEBUG_RAND -DBN_STRICT -DPURIFY -DOPENSSL_NO_DEPRECATED -DOPENSSL_NO_ASM -DOPENSSL_NO_INLINE_ASM -DL_ENDIAN -DTERMIO -DPEDANTIC -DMD32_REG_T=int -O1 -ggdb2 -Wall -Werror -Wundef -pedantic -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wsign-compare -Wmissing-prototypes -Wmissing-declarations -Wno-long-long::-D_REENTRANT::-ldl:BN_LLONG:${no_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"debug-geoff64","gcc:-DBN_DEBUG -DBN_DEBUG_RAND -DBN_STRICT -DPURIFY -DOPENSSL_NO_DEPRECATED -DOPENSSL_NO_ASM -DOPENSSL_NO_INLINE_ASM -DL_ENDIAN -DTERMIO -DPEDANTIC -DMD32_REG_T=int -O1 -ggdb2 -Wall -Werror -Wundef -pedantic -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wsign-compare -Wmissing-prototypes -Wmissing-declarations -Wno-long-long::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL BF_PTR:${no_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"debug-linux-pentium","gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DL_ENDIAN -DTERMIO -g -mcpu=pentium -Wall::-D_REENTRANT::-ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn",
+"debug-linux-ppro","gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DL_ENDIAN -DTERMIO -g -mcpu=pentiumpro -Wall::-D_REENTRANT::-ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn",
+"debug-linux-elf","gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DL_ENDIAN -DTERMIO -g -march=i486 -Wall::-D_REENTRANT::-lefence -ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"debug-linux-elf-noefence","gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DL_ENDIAN -DTERMIO -g -march=i486 -Wall::-D_REENTRANT::-ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"debug-linux-ia32-aes", "gcc:-DAES_EXPERIMENTAL -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -Wall::-D_REENTRANT::-ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:x86cpuid.o:bn-586.o co-586.o x86-mont.o:des-586.o crypt586.o:aes_x86core.o aes_cbc.o:bf-586.o:md5-586.o:sha1-586.o sha256-586.o sha512-586.o:cast-586.o:rc4-586.o:rmd-586.o:rc5-586.o:wp_block.o wp-mmx.o::elf:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"debug-linux-generic32","gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -DTERMIO -g -Wall::-D_REENTRANT::-ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL BF_PTR:${no_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
 "debug-linux-generic64","gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -DTERMIO -g -Wall::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL BF_PTR:${no_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"debug-linux-x86_64","gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -m64 -DL_ENDIAN -DTERMIO -g -Wall -DMD32_REG_T=int::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:dlfcn:linux-shared:-fPIC:-m64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"debug-linux-x86_64",  "gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -m64 -DL_ENDIAN -DTERMIO -g -Wall -DMD32_REG_T=int::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:elf:dlfcn:linux-shared:-fPIC:-m64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::64",
 "dist",                "cc:-O::(unknown)::::::",
 
 # Basic configs that should work on any (32 and less bit) box
@@ -191,8 +196,8 @@ my %table=(
 "cc",          "cc:-O::(unknown)::::::",
 
 ####VOS Configurations
-"vos-gcc","gcc:-O3 -Wall -D_POSIX_C_SOURCE=200112L -D_BSD -DB_ENDIAN::(unknown):VOS:-Wl,-map:BN_LLONG:${no_asm}:::::.so:",
-"debug-vos-gcc","gcc:-O0 -g -Wall -D_POSIX_C_SOURCE=200112L -D_BSD -DB_ENDIAN -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG::(unknown):VOS:-Wl,-map:BN_LLONG:${no_asm}:::::.so:",
+"vos-gcc","gcc:-O3 -Wall -DOPENSSL_SYSNAME_VOS -D_POSIX_C_SOURCE=200112L -D_BSD -D_VOS_EXTENDED_NAMES -DB_ENDIAN::(unknown):VOS:-Wl,-map:BN_LLONG:${no_asm}:::::.so:",
+"debug-vos-gcc","gcc:-O0 -g -Wall -DOPENSSL_SYSNAME_VOS -D_POSIX_C_SOURCE=200112L -D_BSD -D_VOS_EXTENDED_NAMES -DB_ENDIAN -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG::(unknown):VOS:-Wl,-map:BN_LLONG:${no_asm}:::::.so:",
 
 #### Solaris x86 with GNU C setups
 # -DOPENSSL_NO_INLINE_ASM switches off inline assembler. We have to do it
@@ -209,33 +214,33 @@ my %table=(
 # actually recommend to consider using gcc shared build even with vendor
 # compiler:-)
 #                                              <appro@fy.chalmers.se>
-"solaris64-x86_64-gcc","gcc:-m64 -O3 -Wall -DL_ENDIAN -DMD32_REG_T=int::-D_REENTRANT::-lsocket -lnsl -ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:dlfcn:solaris-shared:-fPIC:-m64 -shared -static-libgcc:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"solaris64-x86_64-gcc","gcc:-m64 -O3 -Wall -DL_ENDIAN -DMD32_REG_T=int::-D_REENTRANT::-lsocket -lnsl -ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:elf:dlfcn:solaris-shared:-fPIC:-m64 -shared -static-libgcc:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::/64",
  
 #### Solaris x86 with Sun C setups
 "solaris-x86-cc","cc:-fast -O -Xa::-D_REENTRANT::-lsocket -lnsl -ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_PTR DES_UNROLL BF_PTR:${no_asm}:dlfcn:solaris-shared:-KPIC:-G -dy -z text:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"solaris64-x86_64-cc","cc:-fast -xarch=amd64 -xstrconst -Xa -DL_ENDIAN::-D_REENTRANT::-lsocket -lnsl -ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:dlfcn:solaris-shared:-KPIC:-xarch=amd64 -G -dy -z text:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"solaris64-x86_64-cc","cc:-fast -xarch=amd64 -xstrconst -Xa -DL_ENDIAN::-D_REENTRANT::-lsocket -lnsl -ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:elf:dlfcn:solaris-shared:-KPIC:-xarch=amd64 -G -dy -z text:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::/64",
 
 #### SPARC Solaris with GNU C setups
 "solaris-sparcv7-gcc","gcc:-O3 -fomit-frame-pointer -Wall -DB_ENDIAN -DBN_DIV2W::-D_REENTRANT::-lsocket -lnsl -ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${no_asm}:dlfcn:solaris-shared:-fPIC:-shared:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"solaris-sparcv8-gcc","gcc:-mv8 -O3 -fomit-frame-pointer -Wall -DB_ENDIAN -DBN_DIV2W::-D_REENTRANT::-lsocket -lnsl -ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR::sparcv8.o:des_enc-sparc.o fcrypt_b.o:::::::::dlfcn:solaris-shared:-fPIC:-shared:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"solaris-sparcv8-gcc","gcc:-mv8 -O3 -fomit-frame-pointer -Wall -DB_ENDIAN -DBN_DIV2W::-D_REENTRANT::-lsocket -lnsl -ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${sparcv8_asm}:dlfcn:solaris-shared:-fPIC:-shared:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
 # -m32 should be safe to add as long as driver recognizes -mcpu=ultrasparc
-"solaris-sparcv9-gcc","gcc:-m32 -mcpu=ultrasparc -O3 -fomit-frame-pointer -Wall -DB_ENDIAN -DBN_DIV2W::-D_REENTRANT:ULTRASPARC:-lsocket -lnsl -ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR::sparcv8plus.o:des_enc-sparc.o fcrypt_b.o:::::::::dlfcn:solaris-shared:-fPIC:-shared:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"solaris64-sparcv9-gcc","gcc:-m64 -mcpu=ultrasparc -O3 -Wall -DB_ENDIAN::-D_REENTRANT:ULTRASPARC:-lsocket -lnsl -ldl:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_INT DES_PTR DES_RISC1 DES_UNROLL BF_PTR:::des_enc-sparc.o fcrypt_b.o:::::::::dlfcn:solaris-shared:-fPIC:-m64 -shared:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"solaris-sparcv9-gcc","gcc:-m32 -mcpu=ultrasparc -O3 -fomit-frame-pointer -Wall -DB_ENDIAN -DBN_DIV2W::-D_REENTRANT:ULTRASPARC:-lsocket -lnsl -ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${sparcv9_asm}:dlfcn:solaris-shared:-fPIC:-shared:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"solaris64-sparcv9-gcc","gcc:-m64 -mcpu=ultrasparc -O3 -Wall -DB_ENDIAN::-D_REENTRANT:ULTRASPARC:-lsocket -lnsl -ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_INT DES_PTR DES_RISC1 DES_UNROLL BF_PTR:${sparcv9_asm}:dlfcn:solaris-shared:-fPIC:-m64 -shared:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::/64",
 ####
-"debug-solaris-sparcv8-gcc","gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG_ALL -O -g -mv8 -Wall -DB_ENDIAN::-D_REENTRANT::-lsocket -lnsl -ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR::sparcv8.o::::::::::dlfcn:solaris-shared:-fPIC:-shared:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"debug-solaris-sparcv9-gcc","gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG_ALL -DPEDANTIC -O -g -mcpu=ultrasparc -pedantic -ansi -Wall -Wshadow -Wno-long-long -D__EXTENSIONS__ -DB_ENDIAN -DBN_DIV2W::-D_REENTRANT:ULTRASPARC:-lsocket -lnsl -ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR::sparcv8plus.o:des_enc-sparc.o fcrypt_b.o:::::::::dlfcn:solaris-shared:-fPIC:-shared:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"debug-solaris-sparcv8-gcc","gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG_ALL -O -g -mv8 -Wall -DB_ENDIAN::-D_REENTRANT::-lsocket -lnsl -ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${sparcv8_asm}:dlfcn:solaris-shared:-fPIC:-shared:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"debug-solaris-sparcv9-gcc","gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG_ALL -DPEDANTIC -O -g -mcpu=ultrasparc -pedantic -ansi -Wall -Wshadow -Wno-long-long -D__EXTENSIONS__ -DB_ENDIAN -DBN_DIV2W::-D_REENTRANT:ULTRASPARC:-lsocket -lnsl -ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${sparcv9_asm}:dlfcn:solaris-shared:-fPIC:-shared:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
 
 #### SPARC Solaris with Sun C setups
 # SC4.0 doesn't pass 'make test', upgrade to SC5.0 or SC4.2.
 # SC4.2 is ok, better than gcc even on bn as long as you tell it -xarch=v8
 # SC5.0 note: Compiler common patch 107357-01 or later is required!
 "solaris-sparcv7-cc","cc:-xO5 -xstrconst -xdepend -Xa -DB_ENDIAN -DBN_DIV2W::-D_REENTRANT::-lsocket -lnsl -ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_PTR DES_RISC1 DES_UNROLL BF_PTR:${no_asm}:dlfcn:solaris-shared:-KPIC:-G -dy -z text:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"solaris-sparcv8-cc","cc:-xarch=v8 -xO5 -xstrconst -xdepend -Xa -DB_ENDIAN -DBN_DIV2W::-D_REENTRANT::-lsocket -lnsl -ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_PTR DES_RISC1 DES_UNROLL BF_PTR::sparcv8.o:des_enc-sparc.o fcrypt_b.o:::::::::dlfcn:solaris-shared:-KPIC:-G -dy -z text:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"solaris-sparcv9-cc","cc:-xtarget=ultra -xarch=v8plus -xO5 -xstrconst -xdepend -Xa -DB_ENDIAN -DBN_DIV2W::-D_REENTRANT:ULTRASPARC:-lsocket -lnsl -ldl:BN_LLONG RC4_CHAR RC4_CHUNK_LL DES_PTR DES_RISC1 DES_UNROLL BF_PTR::sparcv8plus.o:des_enc-sparc.o fcrypt_b.o:::::::::dlfcn:solaris-shared:-KPIC:-G -dy -z text:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"solaris64-sparcv9-cc","cc:-xtarget=ultra -xarch=v9 -xO5 -xstrconst -xdepend -Xa -DB_ENDIAN::-D_REENTRANT:ULTRASPARC:-lsocket -lnsl -ldl:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_INT DES_PTR DES_RISC1 DES_UNROLL BF_PTR:::des_enc-sparc.o fcrypt_b.o:::::::::dlfcn:solaris-shared:-KPIC:-xarch=v9 -G -dy -z text:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):/usr/ccs/bin/ar rs",
+"solaris-sparcv8-cc","cc:-xarch=v8 -xO5 -xstrconst -xdepend -Xa -DB_ENDIAN -DBN_DIV2W::-D_REENTRANT::-lsocket -lnsl -ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_PTR DES_RISC1 DES_UNROLL BF_PTR:${sparcv8_asm}:dlfcn:solaris-shared:-KPIC:-G -dy -z text:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"solaris-sparcv9-cc","cc:-xtarget=ultra -xarch=v8plus -xO5 -xstrconst -xdepend -Xa -DB_ENDIAN -DBN_DIV2W::-D_REENTRANT:ULTRASPARC:-lsocket -lnsl -ldl:BN_LLONG RC4_CHAR RC4_CHUNK_LL DES_PTR DES_RISC1 DES_UNROLL BF_PTR:${sparcv9_asm}:dlfcn:solaris-shared:-KPIC:-G -dy -z text:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"solaris64-sparcv9-cc","cc:-xtarget=ultra -xarch=v9 -xO5 -xstrconst -xdepend -Xa -DB_ENDIAN::-D_REENTRANT:ULTRASPARC:-lsocket -lnsl -ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_INT DES_PTR DES_RISC1 DES_UNROLL BF_PTR:${sparcv9_asm}:dlfcn:solaris-shared:-KPIC:-xarch=v9 -G -dy -z text:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):/usr/ccs/bin/ar rs::/64",
 ####
-"debug-solaris-sparcv8-cc","cc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG_ALL -xarch=v8 -g -O -xstrconst -Xa -DB_ENDIAN -DBN_DIV2W::-D_REENTRANT::-lsocket -lnsl -ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_PTR DES_RISC1 DES_UNROLL BF_PTR::sparcv8.o::::::::::dlfcn:solaris-shared:-KPIC:-G -dy -z text:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"debug-solaris-sparcv9-cc","cc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG_ALL -xtarget=ultra -xarch=v8plus -g -O -xstrconst -Xa -DB_ENDIAN -DBN_DIV2W::-D_REENTRANT:ULTRASPARC:-lsocket -lnsl -ldl:BN_LLONG RC4_CHAR RC4_CHUNK_LL DES_PTR DES_RISC1 DES_UNROLL BF_PTR::sparcv8plus.o::::::::::dlfcn:solaris-shared:-KPIC:-G -dy -z text:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", 
+"debug-solaris-sparcv8-cc","cc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG_ALL -xarch=v8 -g -O -xstrconst -Xa -DB_ENDIAN -DBN_DIV2W::-D_REENTRANT::-lsocket -lnsl -ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_PTR DES_RISC1 DES_UNROLL BF_PTR:${sparcv8_asm}:dlfcn:solaris-shared:-KPIC:-G -dy -z text:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"debug-solaris-sparcv9-cc","cc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG_ALL -xtarget=ultra -xarch=v8plus -g -O -xstrconst -Xa -DB_ENDIAN -DBN_DIV2W::-D_REENTRANT:ULTRASPARC:-lsocket -lnsl -ldl:BN_LLONG RC4_CHAR RC4_CHUNK_LL DES_PTR DES_RISC1 DES_UNROLL BF_PTR:${sparcv9_asm}:dlfcn:solaris-shared:-KPIC:-G -dy -z text:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", 
 
 #### SunOS configs, assuming sparc for the gcc one.
 #"sunos-cc", "cc:-O4 -DNOPROTO -DNOCONST::(unknown):SUNOS::DES_UNROLL:${no_asm}::",
@@ -248,11 +253,11 @@ my %table=(
 #### IRIX 6.x configs
 # Only N32 and N64 ABIs are supported. If you need O32 ABI build, invoke
 # './Configure irix-cc -o32' manually.
-"irix-mips3-gcc","gcc:-mabi=n32 -O3 -DTERMIOS -DB_ENDIAN -DBN_DIV3W::-D_SGI_MP_SOURCE:::MD2_CHAR RC4_INDEX RC4_CHAR RC4_CHUNK_LL DES_UNROLL DES_RISC2 DES_PTR BF_PTR SIXTY_FOUR_BIT::bn-mips3.o::::::::::dlfcn:irix-shared::-mabi=n32:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"irix-mips3-cc", "cc:-n32 -mips3 -O2 -use_readonly_const -G0 -rdata_shared -DTERMIOS -DB_ENDIAN -DBN_DIV3W::-D_SGI_MP_SOURCE:::DES_PTR RC4_CHAR RC4_CHUNK_LL DES_RISC2 DES_UNROLL BF_PTR SIXTY_FOUR_BIT::bn-mips3.o::::::::::dlfcn:irix-shared::-n32:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"irix-mips3-gcc","gcc:-mabi=n32 -O3 -DTERMIOS -DB_ENDIAN -DBN_DIV3W::-D_SGI_MP_SOURCE:::MD2_CHAR RC4_INDEX RC4_CHAR RC4_CHUNK_LL DES_UNROLL DES_RISC2 DES_PTR BF_PTR SIXTY_FOUR_BIT:${mips3_asm}:dlfcn:irix-shared::-mabi=n32:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::32",
+"irix-mips3-cc", "cc:-n32 -mips3 -O2 -use_readonly_const -G0 -rdata_shared -DTERMIOS -DB_ENDIAN -DBN_DIV3W::-D_SGI_MP_SOURCE:::DES_PTR RC4_CHAR RC4_CHUNK_LL DES_RISC2 DES_UNROLL BF_PTR SIXTY_FOUR_BIT:${mips3_asm}:dlfcn:irix-shared::-n32:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::32",
 # N64 ABI builds.
-"irix64-mips4-gcc","gcc:-mabi=64 -mips4 -O3 -DTERMIOS -DB_ENDIAN -DBN_DIV3W::-D_SGI_MP_SOURCE:::RC4_CHAR RC4_CHUNK DES_RISC2 DES_UNROLL SIXTY_FOUR_BIT_LONG::bn-mips3.o::::::::::dlfcn:irix-shared::-mabi=64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"irix64-mips4-cc", "cc:-64 -mips4 -O2 -use_readonly_const -G0 -rdata_shared -DTERMIOS -DB_ENDIAN -DBN_DIV3W::-D_SGI_MP_SOURCE:::RC4_CHAR RC4_CHUNK DES_RISC2 DES_UNROLL SIXTY_FOUR_BIT_LONG::bn-mips3.o::::::::::dlfcn:irix-shared::-64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"irix64-mips4-gcc","gcc:-mabi=64 -mips4 -O3 -DTERMIOS -DB_ENDIAN -DBN_DIV3W::-D_SGI_MP_SOURCE:::RC4_CHAR RC4_CHUNK DES_RISC2 DES_UNROLL SIXTY_FOUR_BIT_LONG:${mips3_asm}:dlfcn:irix-shared::-mabi=64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::64",
+"irix64-mips4-cc", "cc:-64 -mips4 -O2 -use_readonly_const -G0 -rdata_shared -DTERMIOS -DB_ENDIAN -DBN_DIV3W::-D_SGI_MP_SOURCE:::RC4_CHAR RC4_CHUNK DES_RISC2 DES_UNROLL SIXTY_FOUR_BIT_LONG:${mips3_asm}:dlfcn:irix-shared::-64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::64",
 
 #### Unified HP-UX ANSI C configs.
 # Special notes:
@@ -285,8 +290,8 @@ my %table=(
 # Since there is mention of this in shlib/hpux10-cc.sh
 "hpux-parisc-cc-o4","cc:-Ae +O4 +ESlit -z -DB_ENDIAN -DBN_DIV2W -DMD32_XARRAY::-D_REENTRANT::-ldld:BN_LLONG DES_PTR DES_UNROLL DES_RISC1:${no_asm}:dl:hpux-shared:+Z:-b:.sl.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
 "hpux-parisc-gcc","gcc:-O3 -DB_ENDIAN -DBN_DIV2W::-D_REENTRANT::-Wl,+s -ldld:BN_LLONG DES_PTR DES_UNROLL DES_RISC1:${no_asm}:dl:hpux-shared:-fPIC:-shared:.sl.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"hpux-parisc2-gcc","gcc:-march=2.0 -O3 -DB_ENDIAN -D_REENTRANT::::-Wl,+s -ldld:SIXTY_FOUR_BIT RC4_CHAR RC4_CHUNK DES_PTR DES_UNROLL DES_RISC1::pa-risc2.o::::::::::dl:hpux-shared:-fPIC:-shared:.sl.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"hpux64-parisc2-gcc","gcc:-O3 -DB_ENDIAN -D_REENTRANT::::-ldl:SIXTY_FOUR_BIT_LONG MD2_CHAR RC4_INDEX RC4_CHAR DES_UNROLL DES_RISC1 DES_INT::pa-risc2W.o::::::::::dlfcn:hpux-shared:-fpic:-shared:.sl.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"hpux-parisc2-gcc","gcc:-march=2.0 -O3 -DB_ENDIAN -D_REENTRANT::::-Wl,+s -ldld:SIXTY_FOUR_BIT RC4_CHAR RC4_CHUNK DES_PTR DES_UNROLL DES_RISC1::pa-risc2.o::::::::::::void:dl:hpux-shared:-fPIC:-shared:.sl.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"hpux64-parisc2-gcc","gcc:-O3 -DB_ENDIAN -D_REENTRANT::::-ldl:SIXTY_FOUR_BIT_LONG MD2_CHAR RC4_INDEX RC4_CHAR DES_UNROLL DES_RISC1 DES_INT::pa-risc2W.o::::::::::::void:dlfcn:hpux-shared:-fpic:-shared:.sl.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::/pa20_64",
 
 # More attempts at unified 10.X and 11.X targets for HP C compiler.
 #
@@ -294,17 +299,17 @@ my %table=(
 # Kevin Steves <ks@hp.se>
 "hpux-parisc-cc","cc:+O3 +Optrs_strongly_typed -Ae +ESlit -DB_ENDIAN -DBN_DIV2W -DMD32_XARRAY::-D_REENTRANT::-Wl,+s -ldld:MD2_CHAR RC4_INDEX RC4_CHAR DES_UNROLL DES_RISC1 DES_INT:${no_asm}:dl:hpux-shared:+Z:-b:.sl.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
 "hpux-parisc1_0-cc","cc:+DAportable +O3 +Optrs_strongly_typed -Ae +ESlit -DB_ENDIAN -DMD32_XARRAY::-D_REENTRANT::-Wl,+s -ldld:MD2_CHAR RC4_INDEX RC4_CHAR DES_UNROLL DES_RISC1 DES_INT:${no_asm}:dl:hpux-shared:+Z:-b:.sl.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"hpux-parisc2-cc","cc:+DA2.0 +DS2.0 +O3 +Optrs_strongly_typed -Ae +ESlit -DB_ENDIAN -DMD32_XARRAY -D_REENTRANT::::-Wl,+s -ldld:SIXTY_FOUR_BIT MD2_CHAR RC4_INDEX RC4_CHAR DES_UNROLL DES_RISC1 DES_INT::pa-risc2.o::::::::::dl:hpux-shared:+Z:-b:.sl.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"hpux64-parisc2-cc","cc:+DD64 +O3 +Optrs_strongly_typed -Ae +ESlit -DB_ENDIAN -DMD32_XARRAY -D_REENTRANT::::-ldl:SIXTY_FOUR_BIT_LONG MD2_CHAR RC4_INDEX RC4_CHAR DES_UNROLL DES_RISC1 DES_INT::pa-risc2W.o::::::::::dlfcn:hpux-shared:+Z:+DD64 -b:.sl.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"hpux-parisc2-cc","cc:+DA2.0 +DS2.0 +O3 +Optrs_strongly_typed -Ae +ESlit -DB_ENDIAN -DMD32_XARRAY -D_REENTRANT::::-Wl,+s -ldld:SIXTY_FOUR_BIT MD2_CHAR RC4_INDEX RC4_CHAR DES_UNROLL DES_RISC1 DES_INT::pa-risc2.o::::::::::::void:dl:hpux-shared:+Z:-b:.sl.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"hpux64-parisc2-cc","cc:+DD64 +O3 +Optrs_strongly_typed -Ae +ESlit -DB_ENDIAN -DMD32_XARRAY -D_REENTRANT::::-ldl:SIXTY_FOUR_BIT_LONG MD2_CHAR RC4_INDEX RC4_CHAR DES_UNROLL DES_RISC1 DES_INT::pa-risc2W.o::::::::::::void:dlfcn:hpux-shared:+Z:+DD64 -b:.sl.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::/pa20_64",
 
 # HP/UX IA-64 targets
-"hpux-ia64-cc","cc:-Ae +DD32 +O2 +Olit=all -z -DB_ENDIAN -D_REENTRANT::::-ldl:SIXTY_FOUR_BIT MD2_CHAR RC4_INDEX DES_UNROLL DES_RISC1 DES_INT:${ia64_asm}:dlfcn:hpux-shared:+Z:+DD32 -b:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"hpux-ia64-cc","cc:-Ae +DD32 +O2 +Olit=all -z -DB_ENDIAN -D_REENTRANT::::-ldl:SIXTY_FOUR_BIT MD2_CHAR RC4_INDEX DES_UNROLL DES_RISC1 DES_INT:${ia64_asm}:dlfcn:hpux-shared:+Z:+DD32 -b:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::/hpux32",
 # Frank Geurts <frank.geurts@nl.abnamro.com> has patiently assisted with
 # with debugging of the following config.
-"hpux64-ia64-cc","cc:-Ae +DD64 +O3 +Olit=all -z -DB_ENDIAN -D_REENTRANT::::-ldl:SIXTY_FOUR_BIT_LONG MD2_CHAR RC4_INDEX DES_UNROLL DES_RISC1 DES_INT:${ia64_asm}:dlfcn:hpux-shared:+Z:+DD64 -b:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"hpux64-ia64-cc","cc:-Ae +DD64 +O3 +Olit=all -z -DB_ENDIAN -D_REENTRANT::::-ldl:SIXTY_FOUR_BIT_LONG MD2_CHAR RC4_INDEX DES_UNROLL DES_RISC1 DES_INT:${ia64_asm}:dlfcn:hpux-shared:+Z:+DD64 -b:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::/hpux64",
 # GCC builds...
-"hpux-ia64-gcc","gcc:-O3 -DB_ENDIAN -D_REENTRANT::::-ldl:SIXTY_FOUR_BIT MD2_CHAR RC4_INDEX DES_UNROLL DES_RISC1 DES_INT:${ia64_asm}:dlfcn:hpux-shared:-fpic:-shared:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"hpux64-ia64-gcc","gcc:-mlp64 -O3 -DB_ENDIAN -D_REENTRANT::::-ldl:SIXTY_FOUR_BIT_LONG MD2_CHAR RC4_INDEX DES_UNROLL DES_RISC1 DES_INT:${ia64_asm}:dlfcn:hpux-shared:-fpic:-mlp64 -shared:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", 
+"hpux-ia64-gcc","gcc:-O3 -DB_ENDIAN -D_REENTRANT::::-ldl:SIXTY_FOUR_BIT MD2_CHAR RC4_INDEX DES_UNROLL DES_RISC1 DES_INT:${ia64_asm}:dlfcn:hpux-shared:-fpic:-shared:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::/hpux32",
+"hpux64-ia64-gcc","gcc:-mlp64 -O3 -DB_ENDIAN -D_REENTRANT::::-ldl:SIXTY_FOUR_BIT_LONG MD2_CHAR RC4_INDEX DES_UNROLL DES_RISC1 DES_INT:${ia64_asm}:dlfcn:hpux-shared:-fpic:-mlp64 -shared:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::/hpux64", 
 
 # Legacy HPUX 9.X configs...
 "hpux-cc",     "cc:-DB_ENDIAN -DBN_DIV2W -DMD32_XARRAY -Ae +ESlit +O2 -z::(unknown)::-Wl,+s -ldld:DES_PTR DES_UNROLL DES_RISC1:${no_asm}:dl:hpux-shared:+Z:-b:.sl.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
@@ -322,9 +327,9 @@ my %table=(
 #
 # For gcc, the following gave a %50 speedup on a 164 over the 'DES_INT' version
 #
-"osf1-alpha-gcc", "gcc:-O3::(unknown):::SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_UNROLL DES_RISC1:${no_asm}:dlfcn:alpha-osf1-shared:::.so",
-"osf1-alpha-cc",  "cc:-std1 -tune host -O4 -readonly_strings::(unknown):::SIXTY_FOUR_BIT_LONG RC4_CHUNK:${no_asm}:dlfcn:alpha-osf1-shared:::.so",
-"tru64-alpha-cc", "cc:-std1 -tune host -fast -readonly_strings::-pthread:::SIXTY_FOUR_BIT_LONG RC4_CHUNK:${no_asm}:dlfcn:alpha-osf1-shared::-msym:.so",
+"osf1-alpha-gcc", "gcc:-O3::(unknown):::SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_UNROLL DES_RISC1:${alpha_asm}:dlfcn:alpha-osf1-shared:::.so",
+"osf1-alpha-cc",  "cc:-std1 -tune host -O4 -readonly_strings::(unknown):::SIXTY_FOUR_BIT_LONG RC4_CHUNK:${alpha_asm}:dlfcn:alpha-osf1-shared:::.so",
+"tru64-alpha-cc", "cc:-std1 -tune host -fast -readonly_strings::-pthread:::SIXTY_FOUR_BIT_LONG RC4_CHUNK:${alpha_asm}:dlfcn:alpha-osf1-shared::-msym:.so",
 
 ####
 #### Variety of LINUX:-)
@@ -332,27 +337,31 @@ my %table=(
 # *-generic* is endian-neutral target, but ./config is free to
 # throw in -D[BL]_ENDIAN, whichever appropriate...
 "linux-generic32","gcc:-DTERMIO -O3 -fomit-frame-pointer -Wall::-D_REENTRANT::-ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL BF_PTR:${no_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"linux-ppc",   "gcc:-DB_ENDIAN -DTERMIO -O3 -Wall::-D_REENTRANT::-ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_RISC1 DES_UNROLL::linux_ppc32.o::::::::::dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"linux-ppc",   "gcc:-DB_ENDIAN -DTERMIO -O3 -Wall::-D_REENTRANT::-ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_RISC1 DES_UNROLL:${ppc32_asm}:linux32:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+# It's believed that majority of ARM toolchains predefine appropriate -march.
+# If you compiler does not, do complement config command line with one!
+"linux-armv4", "gcc:-DTERMIO -O3 -Wall::-D_REENTRANT::-ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL BF_PTR:${armv4_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
 #### IA-32 targets...
 "linux-ia32-icc",      "icc:-DL_ENDIAN -DTERMIO -O2 -no_cpprt::-D_REENTRANT::-ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn:linux-shared:-KPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
 "linux-elf",   "gcc:-DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -Wall::-D_REENTRANT::-ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"linux-aout",  "gcc:-DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -march=i486 -Wall::(unknown):::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_out_asm}",
+"linux-aout",  "gcc:-DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -march=i486 -Wall::(unknown):::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_asm}:a.out",
 ####
 "linux-generic64","gcc:-DTERMIO -O3 -Wall::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL BF_PTR:${no_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"linux-ppc64", "gcc:-m64 -DB_ENDIAN -DTERMIO -O3 -Wall::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_RISC1 DES_UNROLL::linux_ppc64.o::::::::::dlfcn:linux-shared:-fPIC:-m64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"linux-ia64",  "gcc:-DL_ENDIAN -DTERMIO -O3 -Wall::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK:${ia64_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"linux-ia64-ecc","ecc:-DL_ENDIAN -DTERMIO -O2 -Wall -no_cpprt::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK:${ia64_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"linux-ia64-icc","icc:-DL_ENDIAN -DTERMIO -O2 -Wall -no_cpprt::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK:${ia64_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"linux-x86_64",        "gcc:-m64 -DL_ENDIAN -DTERMIO -O3 -Wall -DMD32_REG_T=int::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:dlfcn:linux-shared:-fPIC:-m64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"linux-ppc64", "gcc:-m64 -DB_ENDIAN -DTERMIO -O3 -Wall::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_RISC1 DES_UNROLL:${ppc64_asm}:linux64:dlfcn:linux-shared:-fPIC:-m64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::64",
+"linux-ia64",  "gcc:-DL_ENDIAN -DTERMIO -O3 -Wall::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_UNROLL DES_INT:${ia64_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"linux-ia64-ecc","ecc:-DL_ENDIAN -DTERMIO -O2 -Wall -no_cpprt::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT:${ia64_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"linux-ia64-icc","icc:-DL_ENDIAN -DTERMIO -O2 -Wall -no_cpprt::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_RISC1 DES_INT:${ia64_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"linux-x86_64",        "gcc:-m64 -DL_ENDIAN -DTERMIO -O3 -Wall -DMD32_REG_T=int::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:elf:dlfcn:linux-shared:-fPIC:-m64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::64",
+"linux-s390x", "gcc:-m64 -DB_ENDIAN -DTERMIO -O3 -Wall::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL:${s390x_asm}:dlfcn:linux-shared:-fPIC:-m64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::64",
 #### SPARC Linux setups
 # Ray Miller <ray.miller@computing-services.oxford.ac.uk> has patiently
 # assisted with debugging of following two configs.
-"linux-sparcv8","gcc:-mv8 -DB_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -Wall -DBN_DIV2W::-D_REENTRANT::-ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR::sparcv8.o:des_enc-sparc.o fcrypt_b.o:::::::::dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"linux-sparcv8","gcc:-mv8 -DB_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -Wall -DBN_DIV2W::-D_REENTRANT::-ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${sparcv8_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
 # it's a real mess with -mcpu=ultrasparc option under Linux, but
 # -Wa,-Av8plus should do the trick no matter what.
-"linux-sparcv9","gcc:-m32 -mcpu=ultrasparc -DB_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -Wall -Wa,-Av8plus -DBN_DIV2W::-D_REENTRANT:ULTRASPARC:-ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR::sparcv8plus.o:des_enc-sparc.o fcrypt_b.o:::::::::dlfcn:linux-shared:-fPIC:-m32:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"linux-sparcv9","gcc:-m32 -mcpu=ultrasparc -DB_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -Wall -Wa,-Av8plus -DBN_DIV2W::-D_REENTRANT:ULTRASPARC:-ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${sparcv9_asm}:dlfcn:linux-shared:-fPIC:-m32:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
 # GCC 3.1 is a requirement
-"linux64-sparcv9","gcc:-m64 -mcpu=ultrasparc -DB_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -Wall::-D_REENTRANT:ULTRASPARC:-ldl:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR::::::::::::dlfcn:linux-shared:-fPIC:-m64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"linux64-sparcv9","gcc:-m64 -mcpu=ultrasparc -DB_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -Wall::-D_REENTRANT:ULTRASPARC:-ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_INT DES_PTR DES_RISC1 DES_UNROLL BF_PTR:${sparcv9_asm}:dlfcn:linux-shared:-fPIC:-m64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::64",
 #### Alpha Linux with GNU C and Compaq C setups
 # Special notes:
 # - linux-alpha+bwx-gcc is ment to be used from ./config only. If you
@@ -366,28 +375,25 @@ my %table=(
 #
 #                                      <appro@fy.chalmers.se>
 #
-"linux-alpha-gcc","gcc:-O3 -DL_ENDIAN -DTERMIO::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_RISC1 DES_UNROLL:${no_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"linux-alpha+bwx-gcc","gcc:-O3 -DL_ENDIAN -DTERMIO::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_RISC1 DES_UNROLL:${no_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"linux-alpha-ccc","ccc:-fast -readonly_strings -DL_ENDIAN -DTERMIO::-D_REENTRANT:::SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_PTR DES_RISC1 DES_UNROLL:${no_asm}",
-"linux-alpha+bwx-ccc","ccc:-fast -readonly_strings -DL_ENDIAN -DTERMIO::-D_REENTRANT:::SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_INT DES_PTR DES_RISC1 DES_UNROLL:${no_asm}",
-
-# Android: Linux but without -DTERMIO and pointers to headers and libs.
-"android","gcc:-mandroid -I\$(ANDROID_DEV)/include -B\$(ANDROID_DEV)/lib -O3 -fomit-frame-pointer -Wall::-D_REENTRANT::-ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL BF_PTR:${no_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"linux-alpha-gcc","gcc:-O3 -DL_ENDIAN -DTERMIO::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_RISC1 DES_UNROLL:${alpha_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"linux-alpha+bwx-gcc","gcc:-O3 -DL_ENDIAN -DTERMIO::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_RISC1 DES_UNROLL:${alpha_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"linux-alpha-ccc","ccc:-fast -readonly_strings -DL_ENDIAN -DTERMIO::-D_REENTRANT:::SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_PTR DES_RISC1 DES_UNROLL:${alpha_asm}",
+"linux-alpha+bwx-ccc","ccc:-fast -readonly_strings -DL_ENDIAN -DTERMIO::-D_REENTRANT:::SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_INT DES_PTR DES_RISC1 DES_UNROLL:${alpha_asm}",
 
 #### *BSD [do see comment about ${BSDthreads} above!]
 "BSD-generic32","gcc:-DTERMIOS -O3 -fomit-frame-pointer -Wall::${BSDthreads}:::BN_LLONG RC2_CHAR RC4_INDEX DES_INT DES_UNROLL:${no_asm}:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"BSD-x86",     "gcc:-DL_ENDIAN -DTERMIOS -O3 -fomit-frame-pointer -Wall::${BSDthreads}:::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_out_asm}:dlfcn:bsd-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"BSD-x86",     "gcc:-DL_ENDIAN -DTERMIOS -O3 -fomit-frame-pointer -Wall::${BSDthreads}:::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_asm}:a.out:dlfcn:bsd-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
 "BSD-x86-elf", "gcc:-DL_ENDIAN -DTERMIOS -O3 -fomit-frame-pointer -Wall::${BSDthreads}:::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn:bsd-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
 "debug-BSD-x86-elf",   "gcc:-DL_ENDIAN -DTERMIOS -O3 -Wall -g::${BSDthreads}:::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn:bsd-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"BSD-sparcv8", "gcc:-DB_ENDIAN -DTERMIOS -O3 -mv8 -Wall::${BSDthreads}:::BN_LLONG RC2_CHAR RC4_INDEX DES_INT DES_UNROLL::sparcv8.o:des_enc-sparc.o fcrypt_b.o:::::::::dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"BSD-sparcv8", "gcc:-DB_ENDIAN -DTERMIOS -O3 -mv8 -Wall::${BSDthreads}:::BN_LLONG RC2_CHAR RC4_INDEX DES_INT DES_UNROLL:${sparcv8_asm}:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
 
 "BSD-generic64","gcc:-DTERMIOS -O3 -Wall::${BSDthreads}:::SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${no_asm}:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
 # -DMD32_REG_T=int doesn't actually belong in sparc64 target, it
 # simply *happens* to work around a compiler bug in gcc 3.3.3,
 # triggered by RIPEMD160 code.
-"BSD-sparc64", "gcc:-DB_ENDIAN -DTERMIOS -O3 -DMD32_REG_T=int -Wall::${BSDthreads}:::SIXTY_FOUR_BIT_LONG RC2_CHAR RC4_CHUNK DES_INT DES_PTR DES_RISC2 BF_PTR:::des_enc-sparc.o fcrypt_b.o:::::::::dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"BSD-ia64",    "gcc:-DL_ENDIAN -DTERMIOS -O3 -Wall::${BSDthreads}:::SIXTY_FOUR_BIT_LONG RC4_CHUNK:${ia64_asm}:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-"BSD-x86_64",  "gcc:-DL_ENDIAN -DTERMIOS -O3 -DMD32_REG_T=int -Wall::${BSDthreads}:::SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"BSD-sparc64", "gcc:-DB_ENDIAN -DTERMIOS -O3 -DMD32_REG_T=int -Wall::${BSDthreads}:::BN_LLONG RC2_CHAR RC4_CHUNK DES_INT DES_PTR DES_RISC2 BF_PTR:${sparcv9_asm}:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"BSD-ia64",    "gcc:-DL_ENDIAN -DTERMIOS -O3 -Wall::${BSDthreads}:::SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_UNROLL DES_INT:${ia64_asm}:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+"BSD-x86_64",  "gcc:-DL_ENDIAN -DTERMIOS -O3 -DMD32_REG_T=int -Wall::${BSDthreads}:::SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:elf:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
 
 "bsdi-elf-gcc",     "gcc:-DPERL5 -DL_ENDIAN -fomit-frame-pointer -O3 -march=i486 -Wall::(unknown)::-ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
 
@@ -402,6 +408,10 @@ my %table=(
 "QNX6",       "gcc:-DTERMIOS::::-lsocket::${no_asm}:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
 "QNX6-i386",  "gcc:-DL_ENDIAN -DTERMIOS -O2 -Wall::::-lsocket:${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
 
+# BeOS
+"beos-x86-r5",   "gcc:-DL_ENDIAN -DTERMIOS -O3 -fomit-frame-pointer -mcpu=pentium -Wall::-D_REENTRANT:BEOS:-lbe -lnet:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:beos:beos-shared:-fPIC -DPIC:-shared:.so",
+"beos-x86-bone", "gcc:-DL_ENDIAN -DTERMIOS -O3 -fomit-frame-pointer -mcpu=pentium -Wall::-D_REENTRANT:BEOS:-lbe -lbind -lsocket:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:beos:beos-shared:-fPIC:-shared:.so",
+
 #### SCO/Caldera targets.
 #
 # Originally we had like unixware-*, unixware-*-pentium, unixware-*-p6, etc.
@@ -424,12 +434,12 @@ my %table=(
 
 #### IBM's AIX.
 "aix3-cc",  "cc:-O -DB_ENDIAN -qmaxmem=16384::(unknown):AIX::BN_LLONG RC4_CHAR:::",
-"aix-gcc",  "gcc:-O -DB_ENDIAN::-pthread:AIX::BN_LLONG RC4_CHAR::aix_ppc32.o::::::::::dlfcn:aix-shared::-shared -Wl,-G:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)::-X 32",
-"aix64-gcc","gcc:-maix64 -O -DB_ENDIAN::-pthread:AIX::SIXTY_FOUR_BIT_LONG RC4_CHAR::aix_ppc64.o::::::::::dlfcn:aix-shared::-maix64 -shared -Wl,-G:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)::-X64",
+"aix-gcc",  "gcc:-O -DB_ENDIAN::-pthread:AIX::BN_LLONG RC4_CHAR:${ppc32_asm}:aix32:dlfcn:aix-shared::-shared -Wl,-G:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)::-X32",
+"aix64-gcc","gcc:-maix64 -O -DB_ENDIAN::-pthread:AIX::SIXTY_FOUR_BIT_LONG RC4_CHAR:${ppc64_asm}:aix64:dlfcn:aix-shared::-maix64 -shared -Wl,-G:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)::-X64",
 # Below targets assume AIX 5. Idea is to effectively disregard $OBJECT_MODE
 # at build time. $OBJECT_MODE is respected at ./config stage!
-"aix-cc",   "cc:-q32 -O -DB_ENDIAN -qmaxmem=16384 -qro -qroconst::-qthreaded:AIX::BN_LLONG RC4_CHAR::aix_ppc32.o::::::::::dlfcn:aix-shared::-q32 -G:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)::-X 32",
-"aix64-cc", "cc:-q64 -O -DB_ENDIAN -qmaxmem=16384 -qro -qroconst::-qthreaded:AIX::SIXTY_FOUR_BIT_LONG RC4_CHAR::aix_ppc64.o::::::::::dlfcn:aix-shared::-q64 -G:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)::-X 64",
+"aix-cc",   "cc:-q32 -O -DB_ENDIAN -qmaxmem=16384 -qro -qroconst::-qthreaded:AIX::BN_LLONG RC4_CHAR:${ppc32_asm}:aix32:dlfcn:aix-shared::-q32 -G:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)::-X 32",
+"aix64-cc", "cc:-q64 -O -DB_ENDIAN -qmaxmem=16384 -qro -qroconst::-qthreaded:AIX::SIXTY_FOUR_BIT_LONG RC4_CHAR:${ppc64_asm}:aix64:dlfcn:aix-shared::-q64 -G:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)::-X 64",
 
 #
 # Cray T90 and similar (SDSC)
@@ -477,28 +487,41 @@ my %table=(
 #
 "OS390-Unix","c89.sh:-O -DB_ENDIAN -DCHARSET_EBCDIC -DNO_SYS_PARAM_H  -D_ALL_SOURCE::(unknown):::THIRTY_TWO_BIT DES_PTR DES_UNROLL MD2_CHAR RC4_INDEX RC4_CHAR BF_PTR:::",
 
-# Win64 targets, WIN64I denotes IA-64 and WIN64A - AMD64
-"VC-WIN64I","cl::::WIN64I::SIXTY_FOUR_BIT RC4_CHUNK_LL DES_INT EXPORT_VAR_AS_FN:${no_asm}:win32",
-"VC-WIN64A","cl::::WIN64A::SIXTY_FOUR_BIT RC4_CHUNK_LL DES_INT EXPORT_VAR_AS_FN:${no_asm}:win32",
-
 # Visual C targets
-"VC-NT","cl::::WINNT::BN_LLONG RC4_INDEX EXPORT_VAR_AS_FN ${x86_gcc_opts}:${no_asm}:win32",
+#
+# Win64 targets, WIN64I denotes IA-64 and WIN64A - AMD64
+"VC-WIN64I","cl:-W3 -Gs0 -Gy -nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DUNICODE -D_UNICODE -D_CRT_SECURE_NO_DEPRECATE:::WIN64I::SIXTY_FOUR_BIT RC4_CHUNK_LL DES_INT EXPORT_VAR_AS_FN:ia64cpuid.o:ia64.o::aes_core.o aes_cbc.o aes-ia64.o::md5-ia64.o:sha1-ia64.o sha256-ia64.o sha512-ia64.o:::::::ias:win32",
+"VC-WIN64A","cl:-W3 -Gs0 -Gy -nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DUNICODE -D_UNICODE -D_CRT_SECURE_NO_DEPRECATE:::WIN64A::SIXTY_FOUR_BIT RC4_CHUNK_LL DES_INT EXPORT_VAR_AS_FN:x86_64cpuid.o:bn_asm.o x86_64-mont.o::aes-x86_64.o::md5-x86_64.o:sha1-x86_64.o sha256-x86_64.o sha512-x86_64.o::rc4-x86_64.o:::wp-x86_64.o:cmll-x86_64.o cmll_misc.o:auto:win32",
+"debug-VC-WIN64I","cl:-W3 -Gs0 -Gy -Zi -nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DUNICODE -D_UNICODE -D_CRT_SECURE_NO_DEPRECATE:::WIN64I::SIXTY_FOUR_BIT RC4_CHUNK_LL DES_INT EXPORT_VAR_AS_FN:ia64cpuid.o:ia64.o::aes_core.o aes_cbc.o aes-ia64.o::md5-ia64.o:sha1-ia64.o sha256-ia64.o sha512-ia64.o:::::::ias:win32",
+"debug-VC-WIN64A","cl:-W3 -Gs0 -Gy -Zi -nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DUNICODE -D_UNICODE -D_CRT_SECURE_NO_DEPRECATE:::WIN64A::SIXTY_FOUR_BIT RC4_CHUNK_LL DES_INT EXPORT_VAR_AS_FN:x86_64cpuid.o:bn_asm.o x86_64-mont.o::aes-x86_64.o::md5-x86_64.o:sha1-x86_64.o sha256-x86_64.o sha512-x86_64.o::rc4-x86_64.o:::wp-x86_64.o:cmll-x86_64.o cmll_misc.o:auto:win32",
+# x86 Win32 target defaults to ANSI API, if you want UNICODE, complement
+# 'perl Configure VC-WIN32' with '-DUNICODE -D_UNICODE'
+"VC-WIN32","cl:-W3 -WX -Gs0 -GF -Gy -nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -D_CRT_SECURE_NO_DEPRECATE:::WIN32::BN_LLONG RC4_INDEX EXPORT_VAR_AS_FN ${x86_gcc_opts}:${x86_asm}:win32n:win32",
+# Unified CE target
+"debug-VC-WIN32","cl:-W3 -WX -Gs0 -GF -Gy -Zi -nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -D_CRT_SECURE_NO_DEPRECATE:::WIN32::BN_LLONG RC4_INDEX EXPORT_VAR_AS_FN ${x86_gcc_opts}:${x86_asm}:win32n:win32",
 "VC-CE","cl::::WINCE::BN_LLONG RC4_INDEX EXPORT_VAR_AS_FN ${x86_gcc_opts}:${no_asm}:win32",
-"VC-WIN32","cl::::WIN32::BN_LLONG RC4_INDEX EXPORT_VAR_AS_FN ${x86_gcc_opts}:${no_asm}:win32",
 
 # Borland C++ 4.5
 "BC-32","bcc32::::WIN32::BN_LLONG DES_PTR RC4_INDEX EXPORT_VAR_AS_FN:${no_asm}:win32",
 
 # MinGW
-"mingw", "gcc:-mno-cygwin -DL_ENDIAN -fomit-frame-pointer -O3 -march=i486 -Wall -D_WIN32_WINNT=0x333:::MINGW32:-lwsock32 -lgdi32:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts} EXPORT_VAR_AS_FN:${x86_coff_asm}:win32:cygwin-shared:-D_WINDLL -DOPENSSL_USE_APPLINK:-mno-cygwin -shared:.dll.a",
+"mingw", "gcc:-mno-cygwin -DL_ENDIAN -DWIN32_LEAN_AND_MEAN -fomit-frame-pointer -O3 -march=i486 -Wall::-D_MT:MINGW32:-lws2_32 -lgdi32 -lcrypt32:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts} EXPORT_VAR_AS_FN:${x86_asm}:coff:win32:cygwin-shared:-D_WINDLL -DOPENSSL_USE_APPLINK:-mno-cygwin:.dll.a",
+# As for OPENSSL_USE_APPLINK. Applink makes it possible to use .dll
+# compiled with one compiler with application compiled with another
+# compiler. It's possible to engage Applink support in mingw64 build,
+# but it's not done, because till mingw64 supports structured exception
+# handling, one can't seriously consider its binaries for using with
+# non-mingw64 run-time environment. And as mingw64 is always consistent
+# with itself, Applink is never engaged and can as well be omitted.
+"mingw64", "gcc:-mno-cygwin -DL_ENDIAN -O3 -Wall -DWIN32_LEAN_AND_MEAN -DUNICODE -D_UNICODE::-D_MT:MINGW64:-lws2_32 -lgdi32 -lcrypt32:SIXTY_FOUR_BIT RC4_CHUNK_LL DES_INT EXPORT_VAR_AS_FN:${x86_64_asm}:mingw64:win32:cygwin-shared:-D_WINDLL:-mno-cygwin:.dll.a",
 
 # UWIN 
 "UWIN", "cc:-DTERMIOS -DL_ENDIAN -O -Wall:::UWIN::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${no_asm}:win32",
 
 # Cygwin
 "Cygwin-pre1.3", "gcc:-DTERMIOS -DL_ENDIAN -fomit-frame-pointer -O3 -m486 -Wall::(unknown):CYGWIN32::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${no_asm}:win32",
-"Cygwin", "gcc:-DTERMIOS -DL_ENDIAN -fomit-frame-pointer -O3 -march=i486 -Wall:::CYGWIN32::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_coff_asm}:dlfcn:cygwin-shared:-D_WINDLL:-shared:.dll.a",
-"debug-Cygwin", "gcc:-DTERMIOS -DL_ENDIAN -march=i486 -Wall -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -DOPENSSL_NO_ASM -g -Wformat -Wshadow -Wmissing-prototypes -Wmissing-declarations -Werror:::CYGWIN32:::${no_asm}:dlfcn:cygwin-shared:-D_WINDLL:-shared:.dll.a",
+"Cygwin", "gcc:-DTERMIOS -DL_ENDIAN -fomit-frame-pointer -O3 -march=i486 -Wall:::CYGWIN32::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_asm}:coff:dlfcn:cygwin-shared:-D_WINDLL:-shared:.dll.a",
+"debug-Cygwin", "gcc:-DTERMIOS -DL_ENDIAN -march=i486 -Wall -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DOPENSSL_NO_ASM -g -Wformat -Wshadow -Wmissing-prototypes -Wmissing-declarations -Werror:::CYGWIN32:::${no_asm}:dlfcn:cygwin-shared:-D_WINDLL:-shared:.dll.a",
 
 # NetWare from David Ward (dsward@novell.com)
 # requires either MetroWerks NLM development tools, or gcc / nlmconv
@@ -516,7 +539,7 @@ my %table=(
 "netware-libc-bsdsock-gcc", "i586-netware-gcc:-nostdinc -I/ndk/libc/include -DNETWARE_BSDSOCK -DL_ENDIAN -DNETWARE_LIBC -DOPENSSL_SYSNAME_NETWARE -DTERMIO -O2 -Wall:::::BN_LLONG ${x86_gcc_opts}::",
 
 # DJGPP
-"DJGPP", "gcc:-I/dev/env/WATT_ROOT/inc -DTERMIOS -DL_ENDIAN -fomit-frame-pointer -O2 -Wall:::MSDOS:-L/dev/env/WATT_ROOT/lib -lwatt:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_out_asm}:",
+"DJGPP", "gcc:-I/dev/env/WATT_ROOT/inc -DTERMIOS -DL_ENDIAN -fomit-frame-pointer -O2 -Wall:::MSDOS:-L/dev/env/WATT_ROOT/lib -lwatt:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_asm}:a.out:",
 
 # Ultrix from Bernhard Simon <simon@zid.tuwien.ac.at>
 "ultrix-cc","cc:-std1 -O -Olimit 2500 -DL_ENDIAN::(unknown):::::::",
@@ -526,12 +549,12 @@ my %table=(
 
 ##### MacOS X (a.k.a. Rhapsody or Darwin) setup
 "rhapsody-ppc-cc","cc:-O3 -DB_ENDIAN::(unknown):MACOSX_RHAPSODY::BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${no_asm}::",
-"darwin-ppc-cc","cc:-arch ppc -O3 -DB_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR::osx_ppc32.o::::::::::dlfcn:darwin-shared:-fPIC -fno-common:-arch ppc -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
-"darwin64-ppc-cc","cc:-arch ppc64 -O3 -DB_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR::osx_ppc64.o::::::::::dlfcn:darwin-shared:-fPIC -fno-common:-arch ppc64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
-"darwin-i386-cc","cc:-arch i386 -O3 -fomit-frame-pointer -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${no_asm}:dlfcn:darwin-shared:-fPIC -fno-common:-arch i386 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
-"debug-darwin-i386-cc","cc:-arch i386 -g3 -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${no_asm}:dlfcn:darwin-shared:-fPIC -fno-common:-arch i386 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
-"darwin64-x86_64-cc","cc:-arch x86_64 -O3 -fomit-frame-pointer -DL_ENDIAN -DMD32_REG_T=int -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL:${no_asm}:dlfcn:darwin-shared:-fPIC -fno-common:-arch x86_64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
-"debug-darwin-ppc-cc","cc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -DB_ENDIAN -g -Wall -O::-D_REENTRANT:MACOSX::BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR::osx_ppc32.o::::::::::dlfcn:darwin-shared:-fPIC -fno-common:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+"darwin-ppc-cc","cc:-arch ppc -O3 -DB_ENDIAN -Wa,-force_cpusubtype_ALL::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${ppc32_asm}:osx32:dlfcn:darwin-shared:-fPIC -fno-common:-arch ppc -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+"darwin64-ppc-cc","cc:-arch ppc64 -O3 -DB_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${ppc64_asm}:osx64:dlfcn:darwin-shared:-fPIC -fno-common:-arch ppc64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+"darwin-i386-cc","cc:-arch i386 -O3 -fomit-frame-pointer -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR:${x86_asm}:macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch i386 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+"debug-darwin-i386-cc","cc:-arch i386 -g3 -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR:${x86_asm}:macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch i386 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+"darwin64-x86_64-cc","cc:-arch x86_64 -O3 -DL_ENDIAN -DMD32_REG_T=int -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL:".eval{my $asm=$x86_64_asm;$asm=~s/rc4\-[^:]+//;$asm}.":macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch x86_64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+"debug-darwin-ppc-cc","cc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -DB_ENDIAN -g -Wall -O::-D_REENTRANT:MACOSX::BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${ppc32_asm}:osx32:dlfcn:darwin-shared:-fPIC:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
 
 ##### A/UX
 "aux3-gcc","gcc:-O2 -DTERMIO::(unknown):AUX:-lbsd:RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:::",
@@ -548,18 +571,23 @@ my %table=(
 ##### VxWorks for various targets
 "vxworks-ppc405","ccppc:-g -msoft-float -mlongcall -DCPU=PPC405 -I\$(WIND_BASE)/target/h:::VXWORKS:-r:::::",
 "vxworks-ppc750","ccppc:-ansi -nostdinc -DPPC750 -D_REENTRANT -fvolatile -fno-builtin -fno-for-scope -fsigned-char -Wall -msoft-float -mlongcall -DCPU=PPC604 -I\$(WIND_BASE)/target/h \$(DEBUG_FLAG):::VXWORKS:-r:::::",
-"vxworks-ppc750-debug","ccppc:-ansi -nostdinc -DPPC750 -D_REENTRANT -fvolatile -fno-builtin -fno-for-scope -fsigned-char -Wall -msoft-float -mlongcall -DCPU=PPC604 -I\$(WIND_BASE)/target/h -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -DPEDANTIC -DDEBUG_SAFESTACK -DDEBUG -g:::VXWORKS:-r:::::",
+"vxworks-ppc750-debug","ccppc:-ansi -nostdinc -DPPC750 -D_REENTRANT -fvolatile -fno-builtin -fno-for-scope -fsigned-char -Wall -msoft-float -mlongcall -DCPU=PPC604 -I\$(WIND_BASE)/target/h -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DPEDANTIC -DDEBUG_SAFESTACK -DDEBUG -g:::VXWORKS:-r:::::",
 "vxworks-ppc860","ccppc:-nostdinc -msoft-float -DCPU=PPC860 -DNO_STRINGS_H -I\$(WIND_BASE)/target/h:::VXWORKS:-r:::::",
 "vxworks-mipsle","ccmips:-B\$(WIND_BASE)/host/\$(WIND_HOST_TYPE)/lib/gcc-lib/ -DL_ENDIAN -EL -Wl,-EL -mips2 -mno-branch-likely -G 0 -fno-builtin -msoft-float -DCPU=MIPS32 -DMIPSEL -DNO_STRINGS_H -I\$(WIND_BASE)/target/h:::VXWORKS:-r::${no_asm}::::::ranlibmips:",
 
 ##### Compaq Non-Stop Kernel (Tandem)
 "tandem-c89","c89:-Ww -D__TANDEM -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED=1 -D_TANDEM_SOURCE -DB_ENDIAN::(unknown):::THIRTY_TWO_BIT:::",
 
+# uClinux
+"uClinux-dist","$ENV{'CC'}:\$(CFLAGS)::-D_REENTRANT::\$(LDFLAGS) \$(LDLIBS):BN_LLONG:::::::::::::::$ENV{'LIBSSL_dlfcn'}:linux-shared:-fPIC:-shared:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):$ENV{'RANLIB'}::",
+"uClinux-dist64","$ENV{'CC'}:\$(CFLAGS)::-D_REENTRANT::\$(LDFLAGS) \$(LDLIBS):SIXTY_FOUR_BIT_LONG:::::::::::::::$ENV{'LIBSSL_dlfcn'}:linux-shared:-fPIC:-shared:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):$ENV{'RANLIB'}::",
+
 );
 
 my @MK1MF_Builds=qw(VC-WIN64I VC-WIN64A
-                   VC-NT VC-CE VC-WIN32
-                   BC-32 OS2-EMX
+                   debug-VC-WIN64I debug-VC-WIN64A
+                   VC-NT VC-CE VC-WIN32 debug-VC-WIN32
+                   BC-32 
                    netware-clib netware-clib-bsdsock
                    netware-libc netware-libc-bsdsock);
 
@@ -582,6 +610,9 @@ my $idx_cast_obj = $idx++;
 my $idx_rc4_obj = $idx++;
 my $idx_rmd160_obj = $idx++;
 my $idx_rc5_obj = $idx++;
+my $idx_wp_obj = $idx++;
+my $idx_cmll_obj = $idx++;
+my $idx_perlasm_scheme = $idx++;
 my $idx_dso_scheme = $idx++;
 my $idx_shared_target = $idx++;
 my $idx_shared_cflag = $idx++;
@@ -589,6 +620,7 @@ my $idx_shared_ldflag = $idx++;
 my $idx_shared_extension = $idx++;
 my $idx_ranlib = $idx++;
 my $idx_arflags = $idx++;
+my $idx_multilib = $idx++;
 
 my $prefix="";
 my $libdir="";
@@ -596,18 +628,12 @@ my $openssldir="";
 my $exe_ext="";
 my $install_prefix= "$ENV{'INSTALL_PREFIX'}";
 my $cross_compile_prefix="";
-my $fipslibdir="/usr/local/ssl/fips-1.0/lib/";
-my $nofipscanistercheck=0;
-my $fipsdso=0;
-my $fipscanisterinternal="n";
-my $baseaddr="0xFB00000";
 my $no_threads=0;
 my $threads=0;
 my $no_shared=0; # but "no-shared" is default
 my $zlib=1;      # but "no-zlib" is default
 my $no_krb5=0;   # but "no-krb5" is implied unless "--with-krb5-..." is used
 my $no_rfc3779=1; # but "no-rfc3779" is default
-my $montasm=1;   # but "no-montasm" is default
 my $no_asm=0;
 my $no_dso=0;
 my $no_gmp=0;
@@ -624,7 +650,6 @@ my $rc2     ="crypto/rc2/rc2.h";
 my $bf ="crypto/bf/bf_locl.h";
 my $bn_asm     ="bn_asm.o";
 my $des_enc="des_enc.o fcrypt_b.o";
-my $fips_des_enc="fips_des_enc.o";
 my $aes_enc="aes_core.o aes_cbc.o";
 my $bf_enc     ="bf_enc.o";
 my $cast_enc="c_enc.o";
@@ -633,26 +658,22 @@ my $rc5_enc="rc5_enc.o";
 my $md5_obj="";
 my $sha1_obj="";
 my $rmd160_obj="";
+my $cmll_enc="camellia.o cmll_misc.o cmll_cbc.o";
 my $processor="";
 my $default_ranlib;
 my $perl;
-my $fips=0;
 
 
 # All of the following is disabled by default (RC5 was enabled before 0.9.8):
 
 my %disabled = ( # "what"         => "comment" [or special keyword "experimental"]
-                 "camellia"       => "default",
-                 "capieng"        => "default",
-                 "cms"            => "default",
-                 "gmp"            => "default",
+                "gmp"            => "default",
                  "jpake"          => "experimental",
-                 "mdc2"           => "default",
-                 "montasm"        => "default", # explicit option in 0.9.8 only (implicitly enabled in 0.9.9)
+                 "md2"            => "default",
                  "rc5"            => "default",
-                 "rfc3779"        => "default",
-                 "seed"           => "default",
+                "rfc3779"        => "default",
                  "shared"         => "default",
+                "store"          => "experimental",
                  "zlib"           => "default",
                  "zlib-dynamic"   => "default"
                );
@@ -660,8 +681,7 @@ my @experimental = ();
 
 # This is what $depflags will look like with the above defaults
 # (we need this to see if we should advise the user to run "make depend"):
-my $default_depflags = " -DOPENSSL_NO_CAMELLIA -DOPENSSL_NO_CAPIENG -DOPENSSL_NO_CMS -DOPENSSL_NO_GMP -DOPENSSL_NO_JPAKE -DOPENSSL_NO_MDC2 -DOPENSSL_NO_RC5 -DOPENSSL_NO_RFC3779 -DOPENSSL_NO_SEED";
-
+my $default_depflags = " -DOPENSSL_NO_GMP -DOPENSSL_NO_JPAKE -DOPENSSL_NO_MD2 -DOPENSSL_NO_RC5 -DOPENSSL_NO_RFC3779 -DOPENSSL_NO_STORE";
 
 # Explicit "no-..." options will be collected in %disabled along with the defaults.
 # To remove something from %disabled, use "enable-foo" (unless it's experimental).
@@ -740,8 +760,8 @@ PROCESS_ARGS:
                                        {
                                        $disabled{$1} = "option";
                                        }
-                               }
-                       }                       
+                               }                       
+                       }
                elsif (/^enable-(.+)$/ || /^experimental-(.+)$/)
                        {
                        my $algo = $1;
@@ -788,39 +808,15 @@ PROCESS_ARGS:
                        }
                elsif (/^386$/)
                        { $processor=386; }
-               elsif (/^fips$/)
-                       {
-                       $fips=1;
-                       }
                elsif (/^rsaref$/)
                        {
                        # No RSAref support any more since it's not needed.
                        # The check for the option is there so scripts aren't
                        # broken
                        }
-               elsif (/^nofipscanistercheck$/)
-                       {
-                       $fips = 1;
-                       $nofipscanistercheck = 1;
-                       }
-               elsif (/^fipscanisterbuild$/)
-                       {
-                       $fips = 1;
-                       $nofipscanistercheck = 1;
-                       $fipslibdir="";
-                       $fipscanisterinternal="y";
-                       }
-               elsif (/^fipsdso$/)
-                       {
-                       $fips = 1;
-                       $nofipscanistercheck = 1;
-                       $fipslibdir="";
-                       $fipscanisterinternal="y";
-                       $fipsdso = 1;
-                       }
                elsif (/^[-+]/)
                        {
-                       if (/^-[lL](.*)$/)
+                       if (/^-[lL](.*)$/ or /^-Wl,/)
                                {
                                $libs.=$_." ";
                                }
@@ -856,13 +852,9 @@ PROCESS_ARGS:
                                {
                                $withargs{"zlib-include"}="-I$1";
                                }
-                       elsif (/^--with-fipslibdir=(.*)$/)
-                               {
-                               $fipslibdir="$1/";
-                               }
-                       elsif (/^--with-baseaddr=(.*)$/)
+                       elsif (/^--cross-compile-prefix=(.*)$/)
                                {
-                               $baseaddr="$1";
+                               $cross_compile_prefix=$1;
                                }
                        else
                                {
@@ -948,6 +940,12 @@ if (defined($disabled{"tls1"}))
        $disabled{"tlsext"} = "forced";
        }
 
+if (defined($disabled{"ec"}) || defined($disabled{"dsa"})
+    || defined($disabled{"dh"}))
+       {
+       $disabled{"gost"} = "forced";
+       }
+
 if ($target eq "TABLE") {
        foreach $target (sort keys %table) {
                print_table_entry($target);
@@ -971,55 +969,6 @@ print "Configuring for $target\n";
 
 &usage if (!defined($table{$target}));
 
-my @fields = split(/\s*:\s*/,$table{$target} . ":" x 30 , -1);
-my $cc = $fields[$idx_cc];
-# Allow environment CC to override compiler...
-if($ENV{CC}) {
-    $cc = $ENV{CC};
-}
-my $cflags = $fields[$idx_cflags];
-my $unistd = $fields[$idx_unistd];
-my $thread_cflag = $fields[$idx_thread_cflag];
-my $sys_id = $fields[$idx_sys_id];
-my $lflags = $fields[$idx_lflags];
-my $bn_ops = $fields[$idx_bn_ops];
-my $cpuid_obj = $fields[$idx_cpuid_obj];
-my $bn_obj = $fields[$idx_bn_obj];
-my $des_obj = $fields[$idx_des_obj];
-my $aes_obj = $fields[$idx_aes_obj];
-my $bf_obj = $fields[$idx_bf_obj];
-my $md5_obj = $fields[$idx_md5_obj];
-my $sha1_obj = $fields[$idx_sha1_obj];
-my $cast_obj = $fields[$idx_cast_obj];
-my $rc4_obj = $fields[$idx_rc4_obj];
-my $rmd160_obj = $fields[$idx_rmd160_obj];
-my $rc5_obj = $fields[$idx_rc5_obj];
-my $dso_scheme = $fields[$idx_dso_scheme];
-my $shared_target = $fields[$idx_shared_target];
-my $shared_cflag = $fields[$idx_shared_cflag];
-my $shared_ldflag = $fields[$idx_shared_ldflag];
-my $shared_extension = $fields[$idx_shared_extension];
-my $ranlib = $ENV{'RANLIB'} || $fields[$idx_ranlib];
-my $ar = $ENV{'AR'} || "ar";
-my $arflags = $fields[$idx_arflags];
-
-if ($fips)
-       {
-       delete $disabled{"shared"} if ($disabled{"shared"} eq "default");
-       $disabled{"asm"}="forced"
-               if ($target !~ "VC\-.*" &&
-                   "$cpuid_obj:$bn_obj:$aes_obj:$des_obj:$sha1_obj" eq "::::");
-       }
-
-foreach (sort @experimental)
-       {
-       my $ALGO;
-       ($ALGO = $_) =~ tr/[a-z]/[A-Z]/;
-
-       # opensslconf.h will set OPENSSL_NO_... unless OPENSSL_EXPERIMENTAL_... is defined
-       $openssl_experimental_defines .= "#define OPENSSL_NO_$ALGO\n";
-       $cflags .= " -DOPENSSL_EXPERIMENTAL_$ALGO";
-       }
 
 foreach (sort (keys %disabled))
        {
@@ -1035,8 +984,6 @@ foreach (sort (keys %disabled))
                { $no_shared = 1; }
        elsif (/^zlib$/)
                { $zlib = 0; }
-       elsif (/^montasm$/)
-               { $montasm = 0; }
        elsif (/^static-engine$/)
                { }
        elsif (/^zlib-dynamic$/)
@@ -1078,30 +1025,25 @@ foreach (sort (keys %disabled))
        print "\n";
        }
 
-my $IsMK1MF=scalar grep /^$target$/,@MK1MF_Builds;
+my $exp_cflags = "";
+foreach (sort @experimental)
+       {
+       my $ALGO;
+       ($ALGO = $_) =~ tr/[a-z]/[A-Z]/;
 
-$IsMK1MF=1 if ($target eq "mingw" && $^O ne "cygwin" && !is_msys());
+       # opensslconf.h will set OPENSSL_NO_... unless OPENSSL_EXPERIMENTAL_... is defined
+       $openssl_experimental_defines .= "#define OPENSSL_NO_$ALGO\n";
+       $exp_cflags .= " -DOPENSSL_EXPERIMENTAL_$ALGO";
+       }
 
-$no_shared = 0 if ($fipsdso && !$IsMK1MF);
+my $IsMK1MF=scalar grep /^$target$/,@MK1MF_Builds;
 
-$exe_ext=".exe" if ($target eq "Cygwin" || $target eq "DJGPP" || $target eq "mingw");
+$exe_ext=".exe" if ($target eq "Cygwin" || $target eq "DJGPP" || $target =~ /^mingw/);
 $exe_ext=".nlm" if ($target =~ /netware/);
 $exe_ext=".pm"  if ($target =~ /vos/);
-if ($openssldir eq "" and $prefix eq "")
-       {
-       if ($fips)
-               {
-               $openssldir="/usr/local/ssl/fips";
-               }
-       else
-               {
-               $openssldir="/usr/local/ssl";
-               }
-       }
+$openssldir="/usr/local/ssl" if ($openssldir eq "" and $prefix eq "");
 $prefix=$openssldir if $prefix eq "";
 
-$libdir="lib" if $libdir eq "";
-
 $default_ranlib= &which("ranlib") or $default_ranlib="true";
 $perl=$ENV{'PERL'} or $perl=&which("perl5") or $perl=&which("perl")
   or $perl="perl";
@@ -1118,10 +1060,62 @@ $openssldir=$prefix . "/" . $openssldir if $openssldir !~ /(^\/|^[a-zA-Z]:[\\\/]
 
 print "IsMK1MF=$IsMK1MF\n";
 
+my @fields = split(/\s*:\s*/,$table{$target} . ":" x 30 , -1);
+my $cc = $fields[$idx_cc];
+# Allow environment CC to override compiler...
+if($ENV{CC}) {
+    $cc = $ENV{CC};
+}
+my $cflags = $fields[$idx_cflags];
+my $unistd = $fields[$idx_unistd];
+my $thread_cflag = $fields[$idx_thread_cflag];
+my $sys_id = $fields[$idx_sys_id];
+my $lflags = $fields[$idx_lflags];
+my $bn_ops = $fields[$idx_bn_ops];
+my $cpuid_obj = $fields[$idx_cpuid_obj];
+my $bn_obj = $fields[$idx_bn_obj];
+my $des_obj = $fields[$idx_des_obj];
+my $aes_obj = $fields[$idx_aes_obj];
+my $bf_obj = $fields[$idx_bf_obj];
+my $md5_obj = $fields[$idx_md5_obj];
+my $sha1_obj = $fields[$idx_sha1_obj];
+my $cast_obj = $fields[$idx_cast_obj];
+my $rc4_obj = $fields[$idx_rc4_obj];
+my $rmd160_obj = $fields[$idx_rmd160_obj];
+my $rc5_obj = $fields[$idx_rc5_obj];
+my $wp_obj = $fields[$idx_wp_obj];
+my $cmll_obj = $fields[$idx_cmll_obj];
+my $perlasm_scheme = $fields[$idx_perlasm_scheme];
+my $dso_scheme = $fields[$idx_dso_scheme];
+my $shared_target = $fields[$idx_shared_target];
+my $shared_cflag = $fields[$idx_shared_cflag];
+my $shared_ldflag = $fields[$idx_shared_ldflag];
+my $shared_extension = $fields[$idx_shared_extension];
+my $ranlib = $ENV{'RANLIB'} || $fields[$idx_ranlib];
+my $ar = $ENV{'AR'} || "ar";
+my $arflags = $fields[$idx_arflags];
+my $multilib = $fields[$idx_multilib];
+
+# if $prefix/lib$multilib is not an existing directory, then
+# assume that it's not searched by linker automatically, in
+# which case adding $multilib suffix causes more grief than
+# we're ready to tolerate, so don't...
+$multilib="" if !-d "$prefix/lib$multilib";
+
+$libdir="lib$multilib" if $libdir eq "";
+
+$cflags = "$cflags$exp_cflags";
+
 # '%' in $lflags is used to split flags to "pre-" and post-flags
 my ($prelflags,$postlflags)=split('%',$lflags);
-if (defined($postlflags))      { $lflags=$postlflags;  }
-else                           { $lflags=$prelflags; undef $prelflags; }
+if (defined($postlflags))      { $lflags=$postlflags;  }
+else                           { $lflags=$prelflags; undef $prelflags; }
+
+if ($target =~ /^mingw/ && `$cc --target-help 2>&1` !~ m/\-mno\-cygwin/m)
+       {
+       $cflags =~ s/\-mno\-cygwin\s*//;
+       $shared_ldflag =~ s/\-mno\-cygwin\s*//;
+       }
 
 my $no_shared_warn=0;
 my $no_user_cflags=0;
@@ -1249,18 +1243,9 @@ $lflags="$libs$lflags" if ($libs ne "");
 
 if ($no_asm)
        {
-       $cpuid_obj=$bn_obj=$des_obj=$aes_obj=$bf_obj=$cast_obj=$rc4_obj=$rc5_obj="";
-       $sha1_obj=$md5_obj=$rmd160_obj="";
-       $cflags=~s/\-D[BL]_ENDIAN//             if ($fips);
-       $thread_cflags=~s/\-D[BL]_ENDIAN//      if ($fips);
-       }
-if ($montasm)
-       {
-       $bn_obj =~ s/MAYBE-MO86-/mo86-/;
-       }
-else
-       {
-       $bn_obj =~ s/MAYBE-MO86-[a-z.]*//;
+       $cpuid_obj=$bn_obj=
+       $des_obj=$aes_obj=$bf_obj=$cast_obj=$rc4_obj=$rc5_obj=$cmll_obj=
+       $sha1_obj=$md5_obj=$rmd160_obj=$wp_obj="";
        }
 
 if (!$no_shared)
@@ -1279,7 +1264,14 @@ if ($zlib)
        $cflags = "-DZLIB $cflags";
        if (defined($disabled{"zlib-dynamic"}))
                {
-               $lflags = "$lflags -lz";
+               if (defined($withargs{"zlib-lib"}))
+                       {
+                       $lflags = "$lflags -L" . $withargs{"zlib-lib"} . " -lz";
+                       }
+               else
+                       {
+                       $lflags = "$lflags -lz";
+                       }
                }
        else
                {
@@ -1291,7 +1283,7 @@ if ($zlib)
 my $shared_mark = "";
 if ($shared_target eq "")
        {
-       $no_shared_warn = 1 if !$no_shared && !$fips;
+       $no_shared_warn = 1 if !$no_shared;
        $no_shared = 1;
        }
 if (!$no_shared)
@@ -1304,13 +1296,16 @@ if (!$no_shared)
 
 if (!$IsMK1MF)
        {
+       # add {no-}static-engine to options to allow mkdef.pl to work without extra arguments
        if ($no_shared)
                {
                $openssl_other_defines.="#define OPENSSL_NO_DYNAMIC_ENGINE\n";
+               $options.=" static-engine";
                }
        else
                {
                $openssl_other_defines.="#define OPENSSL_NO_STATIC_ENGINE\n";
+               $options.=" no-static-engine";
                }
        }
 
@@ -1377,17 +1372,13 @@ if ($ranlib eq "")
 $cpuid_obj="" if ($processor eq "386");
 
 $bn_obj = $bn_asm unless $bn_obj ne "";
-# bn86* is the only one implementing bn_*_part_words
-$cflags.=" -DOPENSSL_BN_ASM_PART_WORDS" if ($bn_obj =~ /bn86/);
-$cflags.=" -DOPENSSL_IA32_SSE2" if (!$no_sse2 && $bn_obj =~ /bn86/);
-
-$cflags.=" -DOPENSSL_BN_ASM_MONT" if ($bn_obj =~ /\-mont|mo86\-/);
+# bn-586 is the only one implementing bn_*_part_words
+$cflags.=" -DOPENSSL_BN_ASM_PART_WORDS" if ($bn_obj =~ /bn-586/);
+$cflags.=" -DOPENSSL_IA32_SSE2" if (!$no_sse2 && $bn_obj =~ /86/);
 
-if ($fips)
-       {
-       $openssl_other_defines.="#define OPENSSL_FIPS\n";
-       }
+$cflags.=" -DOPENSSL_BN_ASM_MONT" if ($bn_obj =~ /-mont/);
 
+$cpuid_obj="mem_clr.o" unless ($cpuid_obj =~ /\.o$/);
 $des_obj=$des_enc      unless ($des_obj =~ /\.o$/);
 $bf_obj=$bf_enc                unless ($bf_obj =~ /\.o$/);
 $cast_obj=$cast_enc    unless ($cast_obj =~ /\.o$/);
@@ -1423,6 +1414,15 @@ if ($aes_obj =~ /\.o$/)
 else   {
        $aes_obj=$aes_enc;
        }
+$wp_obj="" if ($wp_obj =~ /mmx/ && $processor eq "386");
+if ($wp_obj =~ /\.o$/)
+       {
+       $cflags.=" -DWHIRLPOOL_ASM";
+       }
+else   {
+       $wp_obj="wp_block.o";
+       }
+$cmll_obj=$cmll_enc    unless ($cmll_obj =~ /.o$/);
 
 # "Stringify" the C flags string.  This permits it to be made part of a string
 # and works as well on command lines.
@@ -1482,13 +1482,13 @@ while (<IN>)
        if ($sdirs) {
                my $dir;
                foreach $dir (@skip) {
-                       s/(\s)$dir\s/$1/;
+                       s/(\s)$dir /$1/;
                        s/\s$dir$//;
                        }
                }
        $sdirs = 0 unless /\\$/;
-        s/fips // if (/^DIRS=/ && !$fips);
         s/engines // if (/^DIRS=/ && $disabled{"engine"});
+       s/ccgost// if (/^ENGDIRS=/ && $disabled{"gost"});
        s/^VERSION=.*/VERSION=$version/;
        s/^MAJOR=.*/MAJOR=$major/;
        s/^MINOR=.*/MINOR=$minor/;
@@ -1498,6 +1498,7 @@ while (<IN>)
        s/^SHLIB_MINOR=.*/SHLIB_MINOR=$shlib_minor/;
        s/^SHLIB_EXT=.*/SHLIB_EXT=$shared_extension/;
        s/^INSTALLTOP=.*$/INSTALLTOP=$prefix/;
+       s/^MULTILIB=.*$/MULTILIB=$multilib/;
        s/^OPENSSLDIR=.*$/OPENSSLDIR=$openssldir/;
        s/^LIBDIR=.*$/LIBDIR=$libdir/;
        s/^INSTALL_PREFIX=.*$/INSTALL_PREFIX=$install_prefix/;
@@ -1508,14 +1509,16 @@ while (<IN>)
                {
                s/^CC=.*$/CROSS_COMPILE= $cross_compile_prefix\nCC= \$\(CROSS_COMPILE\)$cc/;
                s/^AR=\s*/AR= \$\(CROSS_COMPILE\)/;
+               s/^NM=\s*/NM= \$\(CROSS_COMPILE\)/;
                s/^RANLIB=\s*/RANLIB= \$\(CROSS_COMPILE\)/;
+               s/^MAKEDEPPROG=.*$/MAKEDEPPROG= \$\(CROSS_COMPILE\)$cc/ if $cc eq "gcc";
                }
        else    {
                s/^CC=.*$/CC= $cc/;
                s/^AR=\s*ar/AR= $ar/;
                s/^RANLIB=.*/RANLIB= $ranlib/;
+               s/^MAKEDEPPROG=.*$/MAKEDEPPROG= $cc/ if $cc eq "gcc";
                }
-       s/^MAKEDEPPROG=.*$/MAKEDEPPROG= $cc/ if $cc eq "gcc";
        s/^CFLAG=.*$/CFLAG= $cflags/;
        s/^DEPFLAG=.*$/DEPFLAG=$depflags/;
        s/^PEX_LIBS=.*$/PEX_LIBS= $prelflags/;
@@ -1524,7 +1527,7 @@ while (<IN>)
        s/^CPUID_OBJ=.*$/CPUID_OBJ= $cpuid_obj/;
        s/^BN_ASM=.*$/BN_ASM= $bn_obj/;
        s/^DES_ENC=.*$/DES_ENC= $des_obj/;
-       s/^AES_ASM_OBJ=.*$/AES_ASM_OBJ= $aes_obj/;
+       s/^AES_ENC=.*$/AES_ENC= $aes_obj/;
        s/^BF_ENC=.*$/BF_ENC= $bf_obj/;
        s/^CAST_ENC=.*$/CAST_ENC= $cast_obj/;
        s/^RC4_ENC=.*$/RC4_ENC= $rc4_obj/;
@@ -1532,6 +1535,9 @@ while (<IN>)
        s/^MD5_ASM_OBJ=.*$/MD5_ASM_OBJ= $md5_obj/;
        s/^SHA1_ASM_OBJ=.*$/SHA1_ASM_OBJ= $sha1_obj/;
        s/^RMD160_ASM_OBJ=.*$/RMD160_ASM_OBJ= $rmd160_obj/;
+       s/^WP_ASM_OBJ=.*$/WP_ASM_OBJ= $wp_obj/;
+       s/^CMLL_ENC=.*$/CMLL_ENC= $cmll_obj/;
+       s/^PERLASM_SCHEME=.*$/PERLASM_SCHEME= $perlasm_scheme/;
        s/^PROCESSOR=.*/PROCESSOR= $processor/;
        s/^ARFLAGS=.*/ARFLAGS= $arflags/;
        s/^PERL=.*/PERL= $perl/;
@@ -1539,24 +1545,9 @@ while (<IN>)
        s/^LIBKRB5=.*/LIBKRB5=$withargs{"krb5-lib"}/;
        s/^LIBZLIB=.*/LIBZLIB=$withargs{"zlib-lib"}/;
        s/^ZLIB_INCLUDE=.*/ZLIB_INCLUDE=$withargs{"zlib-include"}/;
-       s/^FIPSLIBDIR=.*/FIPSLIBDIR=$fipslibdir/;
-       if ($fipsdso)
-               {
-               s/^FIPSCANLIB=.*/FIPSCANLIB=libfips/;
-               s/^SHARED_FIPS=.*/SHARED_FIPS=libfips\$(SHLIB_EXT)/;
-               s/^SHLIBDIRS=.*/SHLIBDIRS= crypto ssl fips/;
-               }
-       else
-               {
-               s/^FIPSCANLIB=.*/FIPSCANLIB=libcrypto/ if $fips;
-               s/^SHARED_FIPS=.*/SHARED_FIPS=/;
-               s/^SHLIBDIRS=.*/SHLIBDIRS= crypto ssl/;
-               }
-       s/^FIPSCANISTERINTERNAL=.*/FIPSCANISTERINTERNAL=$fipscanisterinternal/;
-       s/^BASEADDR=.*/BASEADDR=$baseaddr/;
        s/^SHLIB_TARGET=.*/SHLIB_TARGET=$shared_target/;
        s/^SHLIB_MARK=.*/SHLIB_MARK=$shared_mark/;
-       s/^SHARED_LIBS=.*/SHARED_LIBS=\$(SHARED_FIPS) \$(SHARED_CRYPTO) \$(SHARED_SSL)/ if (!$no_shared);
+       s/^SHARED_LIBS=.*/SHARED_LIBS=\$(SHARED_CRYPTO) \$(SHARED_SSL)/ if (!$no_shared);
        if ($shared_extension ne "" && $shared_extension =~ /^\.s([ol])\.[^\.]*$/)
                {
                my $sotmp = $1;
@@ -1589,7 +1580,7 @@ print "EX_LIBS       =$lflags\n";
 print "CPUID_OBJ     =$cpuid_obj\n";
 print "BN_ASM        =$bn_obj\n";
 print "DES_ENC       =$des_obj\n";
-print "AES_ASM_OBJ   =$aes_obj\n";
+print "AES_ENC       =$aes_obj\n";
 print "BF_ENC        =$bf_obj\n";
 print "CAST_ENC      =$cast_obj\n";
 print "RC4_ENC       =$rc4_obj\n";
@@ -1597,6 +1588,7 @@ print "RC5_ENC       =$rc5_obj\n";
 print "MD5_OBJ_ASM   =$md5_obj\n";
 print "SHA1_OBJ_ASM  =$sha1_obj\n";
 print "RMD160_OBJ_ASM=$rmd160_obj\n";
+print "CMLL_ENC=     =$cmll_obj\n";
 print "PROCESSOR     =$processor\n";
 print "RANLIB        =$ranlib\n";
 print "ARFLAGS       =$arflags\n";
@@ -1684,7 +1676,7 @@ print OUT "#ifdef OPENSSL_ALGORITHM_DEFINES\n";
 print OUT $openssl_algorithm_defines_trans;
 print OUT "#endif\n\n";
 
-print OUT "#define OPENSSL_CPUID_OBJ\n\n" if ($cpuid_obj);
+print OUT "#define OPENSSL_CPUID_OBJ\n\n" if ($cpuid_obj ne "mem_clr.o");
 
 while (<IN>)
        {
@@ -1696,10 +1688,7 @@ while (<IN>)
                }
        elsif   (/^#define\s+ENGINESDIR/)
                {
-               # $foo is to become "$prefix/lib$multilib/engines";
-               # as Makefile.org and engines/Makefile are adapted for
-               # $multilib suffix.
-               my $foo = "$prefix/lib/engines";
+               my $foo = "$prefix/$libdir/engines";
                $foo =~ s/\\/\\\\/g;
                print OUT "#define ENGINESDIR \"$foo\"\n";
                }
@@ -1865,16 +1854,9 @@ BEGIN
     BEGIN
        BLOCK "040904b0"
        BEGIN
-#if defined(FIPS)
-           VALUE "Comments", "WARNING: TEST VERSION ONLY ***NOT*** FIPS 140-2 VALIDATED.\\0"
-#endif
            // Required:            
            VALUE "CompanyName", "The OpenSSL Project, http://www.openssl.org/\\0"
-#if defined(FIPS)
-           VALUE "FileDescription", "TEST UNVALIDATED FIPS140-2 DLL\\0"
-#else
            VALUE "FileDescription", "OpenSSL Shared Library\\0"
-#endif
            VALUE "FileVersion", "$version\\0"
 #if defined(CRYPTO)
            VALUE "InternalName", "libeay32\\0"
@@ -1882,15 +1864,12 @@ BEGIN
 #elif defined(SSL)
            VALUE "InternalName", "ssleay32\\0"
            VALUE "OriginalFilename", "ssleay32.dll\\0"
-#elif defined(FIPS)
-           VALUE "InternalName", "libosslfips\\0"
-           VALUE "OriginalFilename", "libosslfips.dll\\0"
 #endif
            VALUE "ProductName", "The OpenSSL Toolkit\\0"
            VALUE "ProductVersion", "$version\\0"
            // Optional:
            //VALUE "Comments", "\\0"
-           VALUE "LegalCopyright", "Copyright Â© 1998-2007 The OpenSSL Project. Copyright Â© 1995-1998 Eric A. Young, Tim J. Hudson. All rights reserved.\\0"
+           VALUE "LegalCopyright", "Copyright Â© 1998-2005 The OpenSSL Project. Copyright Â© 1995-1998 Eric A. Young, Tim J. Hudson. All rights reserved.\\0"
            //VALUE "LegalTrademarks", "\\0"
            //VALUE "PrivateBuild", "\\0"
            //VALUE "SpecialBuild", "\\0"
@@ -1927,21 +1906,6 @@ libraries on this platform, they will at least look at it and try their best
 (but please first make sure you have tried with a current version of OpenSSL).
 EOF
 
-print <<\EOF if ($fipscanisterinternal eq "y");
-
-WARNING: OpenSSL has been configured using unsupported option(s) to internally
-generate a fipscanister.o object module for TESTING PURPOSES ONLY; that
-compiled module is NOT FIPS 140-2 validated and CANNOT be used to replace the
-OpenSSL FIPS Object Module as identified by the CMVP
-(http://csrc.nist.gov/cryptval/) in any application requiring the use of FIPS
-140-2 validated software. 
-
-This is an OpenSSL 0.9.8 test version.
-
-See the file README.FIPS for details of how to build a test library.
-
-EOF
-
 exit(0);
 
 sub usage
@@ -2017,8 +1981,8 @@ sub print_table_entry
        (my $cc,my $cflags,my $unistd,my $thread_cflag,my $sys_id,my $lflags,
        my $bn_ops,my $cpuid_obj,my $bn_obj,my $des_obj,my $aes_obj, my $bf_obj,
        my $md5_obj,my $sha1_obj,my $cast_obj,my $rc4_obj,my $rmd160_obj,
-       my $rc5_obj,my $dso_scheme,my $shared_target,my $shared_cflag,
-       my $shared_ldflag,my $shared_extension,my $ranlib,my $arflags)=
+       my $rc5_obj,my $wp_obj,my $cmll_obj,my $perlasm_scheme,my $dso_scheme,my $shared_target,my $shared_cflag,
+       my $shared_ldflag,my $shared_extension,my $ranlib,my $arflags,my $multilib)=
        split(/\s*:\s*/,$table{$target} . ":" x 30 , -1);
                        
        print <<EOF
@@ -2042,6 +2006,9 @@ sub print_table_entry
 \$rc4_obj      = $rc4_obj
 \$rmd160_obj   = $rmd160_obj
 \$rc5_obj      = $rc5_obj
+\$wp_obj       = $wp_obj
+\$cmll_obj     = $cmll_obj
+\$perlasm_scheme = $perlasm_scheme
 \$dso_scheme   = $dso_scheme
 \$shared_target= $shared_target
 \$shared_cflag = $shared_cflag
@@ -2049,6 +2016,7 @@ sub print_table_entry
 \$shared_extension = $shared_extension
 \$ranlib       = $ranlib
 \$arflags      = $arflags
+\$multilib     = $multilib
 EOF
        }
 
@@ -2065,33 +2033,25 @@ sub test_sanity
                {
                @fields = split(/\s*:\s*/,$table{$target} . ":" x 30 , -1);
 
-               if ($fields[$idx_dso_scheme-1] =~ /^(dl|dlfcn|win32|vms)$/)
+               if ($fields[$idx_dso_scheme-1] =~ /^(beos|dl|dlfcn|win32|vms)$/)
                        {
                        $errorcnt++;
                        print STDERR "SANITY ERROR: '$target' has the dso_scheme [$idx_dso_scheme] values\n";
                        print STDERR "              in the previous field\n";
                        }
-               elsif ($fields[$idx_dso_scheme+1] =~ /^(dl|dlfcn|win32|vms)$/)
+               elsif ($fields[$idx_dso_scheme+1] =~ /^(beos|dl|dlfcn|win32|vms)$/)
                        {
                        $errorcnt++;
                        print STDERR "SANITY ERROR: '$target' has the dso_scheme [$idx_dso_scheme] values\n";
                        print STDERR "              in the following field\n";
                        }
-               elsif ($fields[$idx_dso_scheme] !~ /^(dl|dlfcn|win32|vms|)$/)
+               elsif ($fields[$idx_dso_scheme] !~ /^(beos|dl|dlfcn|win32|vms|)$/)
                        {
                        $errorcnt++;
                        print STDERR "SANITY ERROR: '$target' has the dso_scheme [$idx_dso_scheme] field = ",$fields[$idx_dso_scheme],"\n";
-                       print STDERR "              valid values are 'dl', 'dlfcn', 'win32' and 'vms'\n";
+                       print STDERR "              valid values are 'beos', 'dl', 'dlfcn', 'win32' and 'vms'\n";
                        }
                }
        print STDERR "No sanity errors detected!\n" if $errorcnt == 0;
        return $errorcnt;
        }
-
-# Attempt to detect MSYS environment
-
-sub is_msys
-       {
-       return 1 if (exists $ENV{"TERM"} && $ENV{"TERM"} eq "msys");
-       return 0;
-       }
index 0e008cb..3b07cd3 100644 (file)
@@ -82,7 +82,7 @@ OpenSSL  -  Frequently Asked Questions
 * Which is the current version of OpenSSL?
 
 The current version is available from <URL: http://www.openssl.org>.
-OpenSSL 1.0.0d was released on Feb 8th, 2011.
+OpenSSL 1.0.0f was released on Jan 4th, 2012.
 
 In addition to the current stable release, you can also access daily
 snapshots of the OpenSSL development version at <URL:
index c72cc1d..1325079 100644 (file)
                 The crypto/<cipher> directory can be removed after running
                 "make depend".
 
-  -Dxxx, -lxxx, -Lxxx, -fxxx, -mxxx, -Kxxx These system specific options will
+  -Dxxx, -lxxx, -Lxxx, -fxxx, -mXXX, -Kxxx These system specific options will
                 be passed through to the compiler to allow you to
                 define preprocessor symbols, specify additional libraries,
                 library directories or other compiler options.
 
+  -DHAVE_CRYPTODEV Enable the BSD cryptodev engine even if we are not using
+               BSD. Useful if you are running ocf-linux or something
+               similar. Once enabled you can also enable the use of
+               cryptodev digests, which is usually slower unless you have
+               large amounts data. Use -DUSE_CRYPTODEV_DIGESTS to force
+               it.
 
  Installation in Detail
  ----------------------
                        compile programs with libcrypto or libssl.
        lib             Contains the OpenSSL library files themselves.
 
+     Use "make install_sw" to install the software without documentation,
+     and "install_docs_html" to install HTML renditions of the manual
+     pages.
+
      Package builders who want to configure the library for standard
      locations, but have the package installed somewhere else so that
      it can easily be packaged, can use
index 7658f64..e5d43a5 100644 (file)
@@ -71,7 +71,7 @@ the top to understand how to use them.  However, if you want to
 compile all you can get, the simplest is to use MAKEVMS.COM in the top
 directory.  The syntax is the following:
 
-  @MAKEVMS <option> <rsaref-p> <debug-p> [<compiler>]
+  @MAKEVMS <option> <bits> <debug-p> [<compiler>]
 
 <option> must be one of the following:
 
@@ -87,24 +87,11 @@ directory.  The syntax is the following:
       TEST      Just build the "[.xxx.EXE.TEST]" test programs for OpenSSL.
       APPS      Just build the "[.xxx.EXE.APPS]" application programs for OpenSSL.
 
-<rsaref-p> must be one of the following:
+<bits> must be one of the following:
 
-      RSAREF    compile using the RSAREF Library
-      NORSAREF  compile without using RSAREF
-
-Note 0: The RSAREF library IS NO LONGER NEEDED.  The RSA patent
-        expires September 20, 2000, and RSA Security chose to make
-        the algorithm public domain two weeks before that.
-
-Note 1: If you still want to use RSAREF, the library is NOT INCLUDED
-        and you have to download it.  RSA Security doesn't carry it
-        any more, but there are a number of places where you can find
-        it.  You have to get the ".tar-Z" file as the ".zip" file
-        doesn't have the directory structure stored.  You have to
-        extract the file into the [.RSAREF] directory as that is where
-        the scripts will look for the files.
-
-Note 2: I have never done this, so I've no idea if it works or not.
+      ""        compile using default pointer size
+      32        compile using 32 bit pointer size
+      64        compile using 64 bit pointer size
 
 <debug-p> must be one of the following:
 
@@ -117,12 +104,13 @@ Note 2: I have never done this, so I've no idea if it works or not.
       GNUC      For GNU C.
 
 
-You will find the crypto library in [.xxx.EXE.CRYPTO], called LIBCRYPTO.OLB,
-where xxx is VAX or AXP.  You will find the SSL library in [.xxx.EXE.SSL],
-named LIBSSL.OLB, and you will find a bunch of useful programs in
-[.xxx.EXE.APPS].  However, these shouldn't be used right off unless it's
-just to test them.  For production use, make sure you install first, see
-Installation below.
+You will find the crypto library in [.xxx.EXE.CRYPTO] (where xxx is VAX,
+ALPHA or IA64), called SSL_LIBCRYPTO32.OLB or SSL_LIBCRYPTO.OLB depending
+on how it was built.  You will find the SSL library in [.xxx.EXE.SSL],
+named SSL_LIBSSL32.OLB or SSL_LIBSSL.OLB, and you will find a bunch of
+useful programs in [.xxx.EXE.APPS].  However, these shouldn't be used
+right off unless it's just to test them.  For production use, make sure
+you install first, see Installation below.
 
 Note 1: Some programs in this package require a TCP/IP library.
 
@@ -170,12 +158,14 @@ Installation:
 
 Installation is easy, just do the following:
 
-  @INSTALL <root>
+  @INSTALL <root> <bits>
 
 <root> is the directory in which everything will be installed,
 subdirectories, libraries, header files, programs and startup command
 procedures.
 
+<bits> works the same way as for MAKEVMS.COM
+
 N.B.: INSTALL.COM builds a new directory structure, different from
 the directory tree where you have now build OpenSSL.
 
@@ -196,6 +186,10 @@ following command procedures:
         sets up the symbols to the applications.  Should be called
         from for example SYS$MANAGER:SYLOGIN.COM 
 
+  OPENSSL_UNDO.COM
+
+       deassigns the logical names created with OPENSSL_STARTUP.COM.
+
 The logical names that are set up are the following:
 
   SSLROOT       a dotted concealed logical name pointing at the
@@ -203,7 +197,6 @@ The logical names that are set up are the following:
 
   SSLCERTS      Initially an empty directory, this is the default
                location for certificate files.
-  SSLMISC      Various scripts.
   SSLPRIVATE   Initially an empty directory, this is the default
                location for private key files.
 
@@ -211,8 +204,9 @@ The logical names that are set up are the following:
                programs.
   SSLINCLUDE    Contains the header files needed if you want to
                compile programs with libcrypto or libssl.
-  SSLLIB        Contains the OpenSSL library files (LIBCRYPTO.OLB
-               and LIBSSL.OLB) themselves.
+  SSLLIB        Contains the OpenSSL library files themselves:
+               - SSL_LIBCRYPTO32.OLB and SSL_LIBSSL32.OLB or
+               - SSL_LIBCRYPTO.OLB and SSL_LIBSSL.OLB
 
   OPENSSL      Same as SSLINCLUDE.  This is because the standard
                way to include OpenSSL header files from version
@@ -296,4 +290,4 @@ have any ideas.
 
 --
 Richard Levitte <richard@levitte.org>
-2000-02-27
+2000-02-27, 2011-03-18
index 3dd7832..d23c4ba 100644 (file)
@@ -5,19 +5,30 @@
  [Instructions for building for Windows CE can be found in INSTALL.WCE]
  [Instructions for building for Win64 can be found in INSTALL.W64]
 
- Heres a few comments about building OpenSSL in Windows environments.  Most
- of this is tested on Win32 but it may also work in Win 3.1 with some
- modification.
+ Here are a few comments about building OpenSSL for Win32 environments,
+ such as Windows NT and Windows 9x. It should be noted though that
+ Windows 9x are not ordinarily tested. Its mention merely means that we
+ attempt to maintain certain programming discipline and pay attention
+ to backward compatibility issues, in other words it's kind of expected
+ to work on Windows 9x, but no regression tests are actually performed.
 
- You need Perl for Win32.  Unless you will build on Cygwin, you will need
- ActiveState Perl, available from http://www.activestate.com/ActivePerl.
+ On additional note newer OpenSSL versions are compiled and linked with
+ Winsock 2. This means that minimum OS requirement was elevated to NT 4
+ and Windows 98 [there is Winsock 2 update for Windows 95 though].
 
- and one of the following C compilers:
+ - you need Perl for Win32.  Unless you will build on Cygwin, you will need
+   ActiveState Perl, available from http://www.activestate.com/ActivePerl.
+
+ - one of the following C compilers:
 
   * Visual C++
   * Borland C
   * GNU C (Cygwin or MinGW)
 
+- Netwide Assembler, a.k.a. NASM, available from http://nasm.sourceforge.net/
+  is required if you intend to utilize assembler modules. Note that NASM
+  is now the only supported assembler.
+
  If you are compiling from a tarball or a CVS snapshot then the Win32 files
  may well be not up to date. This may mean that some "tweaking" is required to
  get it all to work. See the trouble shooting section later on for if (when?)
  Visual C++
  ----------
 
- If you want to compile in the assembly language routines with Visual C++ then
- you will need an assembler. This is worth doing because it will result in
- faster code: for example it will typically result in a 2 times speedup in the
- RSA routines. Currently the following assemblers are supported:
-
-  * Microsoft MASM (aka "ml")
-  * Free Netwide Assembler NASM.
-
- MASM is distributed with most versions of VC++. For the versions where it is
- not included in VC++, it is also distributed with some Microsoft DDKs, for
- example the Windows NT 4.0 DDK and the Windows 98 DDK. If you do not have
- either of these DDKs then you can just download the binaries for the Windows
- 98 DDK and extract and rename the two files XXXXXml.exe and XXXXXml.err, to
- ml.exe and ml.err and install somewhere on your PATH. Both DDKs can be
- downloaded from the Microsoft developers site www.msdn.com.
-
- NASM is freely available. Version 0.98 was used during testing: other versions
- may also work. It is available from many places, see for example:
- http://www.kernel.org/pub/software/devel/nasm/binaries/win32/
- The NASM binary nasmw.exe needs to be installed anywhere on your PATH.
+ If you want to compile in the assembly language routines with Visual
+ C++, then you will need already mentioned Netwide Assembler binary,
+ nasmw.exe or nasm.exe, to be available on your %PATH%.
 
- Firstly you should run Configure:
+ Firstly you should run Configure with platform VC-WIN32:
 
- > perl Configure VC-WIN32 --prefix=c:/some/openssl/dir
+ > perl Configure VC-WIN32 --prefix=c:\some\openssl\dir
 
-Where the prefix argument specifies where OpenSSL will be installed to.
+ Where the prefix argument specifies where OpenSSL will be installed to.
 
- Next you need to build the Makefiles and optionally the assembly language
- files:
-
- - If you are using MASM then run:
-
-   > ms\do_masm
+ Next you need to build the Makefiles and optionally the assembly
+ language files:
 
  - If you are using NASM then run:
 
@@ -66,6 +56,7 @@ Where the prefix argument specifies where OpenSSL will be installed to.
 
  - If you don't want to use the assembly language files at all then run:
 
+   > perl Configure VC-WIN32 no-asm --prefix=c:/some/openssl/dir
    > ms\do_ms
 
  If you get errors about things not having numbers assigned then check the
@@ -76,42 +67,39 @@ Where the prefix argument specifies where OpenSSL will be installed to.
 
  > nmake -f ms\ntdll.mak
 
- If all is well it should compile and you will have some DLLs and executables
- in out32dll. If you want to try the tests then do:
+ If all is well it should compile and you will have some DLLs and
executables in out32dll. If you want to try the tests then do:
  
  > nmake -f ms\ntdll.mak test
 
 
-To install OpenSSL to the specified location do:
+ To install OpenSSL to the specified location do:
 
-> nmake -f ms\ntdll.mak install
+ > nmake -f ms\ntdll.mak install
 
  Tweaks:
 
- There are various changes you can make to the Win32 compile environment. By
- default the library is not compiled with debugging symbols. If you add 'debug'
- to the mk1mf.pl lines in the do_* batch file then debugging symbols will be
- compiled in. Note that mk1mf.pl expects the platform to be the last argument
- on the command line, so 'debug' must appear before that, as all other options.
-
+ There are various changes you can make to the Win32 compile
+ environment. By default the library is not compiled with debugging
+ symbols. If you use the platform debug-VC-WIN32 instead of VC-WIN32
+ then debugging symbols will be compiled in.
 
- By default in 0.9.8 OpenSSL will compile builtin ENGINES into the libeay32.dll
- shared library. If you specify the "no-static-engine" option on the command
- line to Configure the shared library build (ms\ntdll.mak) will compile the
engines as separate DLLs.
+ By default in 1.0.0 OpenSSL will compile builtin ENGINES into the
+ separate shared librariesy. If you specify the "enable-static-engine"
+ option on the command line to Configure the shared library build
(ms\ntdll.mak) will compile the engines into libeay32.dll instead.
 
  The default Win32 environment is to leave out any Windows NT specific
  features.
 
- If you want to enable the NT specific features of OpenSSL (currently only the
- logging BIO) follow the instructions above but call the batch file do_nt.bat
- instead of do_ms.bat.
+ If you want to enable the NT specific features of OpenSSL (currently
+ only the logging BIO) follow the instructions above but call the batch
file do_nt.bat instead of do_ms.bat.
 
  You can also build a static version of the library using the Makefile
  ms\nt.mak
 
 
-
  Borland C++ builder 5
  ---------------------
 
@@ -137,17 +125,13 @@ To install OpenSSL to the specified location do:
  GNU C (Cygwin)
  --------------
 
- Cygwin provides a bash shell and GNU tools environment running
- on NT 4.0, Windows 9x, Windows ME, Windows 2000, and Windows XP.
- Consequently, a make of OpenSSL with Cygwin is closer to a GNU
- bash environment such as Linux than to other the other Win32
- makes.
-
- Cygwin implements a Posix/Unix runtime system (cygwin1.dll).
- It is also possible to create Win32 binaries that only use the
- Microsoft C runtime system (msvcrt.dll or crtdll.dll) using
- MinGW. MinGW can be used in the Cygwin development environment
- or in a standalone setup as described in the following section.
+ Cygwin implements a Posix/Unix runtime system (cygwin1.dll) on top of
+ Win32 subsystem and provides a bash shell and GNU tools environment.
+ Consequently, a make of OpenSSL with Cygwin is virtually identical to
+ Unix procedure. It is also possible to create Win32 binaries that only
+ use the Microsoft C runtime system (msvcrt.dll or crtdll.dll) using
+ MinGW. MinGW can be used in the Cygwin development environment or in a
+ standalone setup as described in the following section.
 
  To build OpenSSL using Cygwin:
 
@@ -192,35 +176,44 @@ To install OpenSSL to the specified location do:
  non-fatal error in "make test" but is otherwise harmless.  If
  desired and needed, GNU bc can be built with Cygwin without change.
 
- GNU C (MinGW)
+ GNU C (MinGW/MSYS)
  -------------
 
- * Compiler installation:
+ * Compiler and shell environment installation:
 
-   MinGW is available from http://www.mingw.org. Run the installer and
-   set the MinGW bin directory to the PATH in "System Properties" or
-   autoexec.bat.
+   MinGW and MSYS are available from http://www.mingw.org/, both are
+   required. Run the installers and do whatever magic they say it takes
+   to start MSYS bash shell with GNU tools on its PATH.
+
+   N.B. Since source tar-ball can contain symbolic links, it's essential
+   that you use accompanying MSYS tar to unpack the source. It will
+   either handle them in one way or another or fail to extract them,
+   which does the trick too. Latter means that you may safely ignore all
+   "cannot create symlink" messages, as they will be "re-created" at
+   configure stage by copying corresponding files. Alternative programs
+   were observed to create empty files instead, which results in build
+   failure.
 
  * Compile OpenSSL:
 
-   > ms\mingw32
+   $ ./config
+   [...]
+   $ make
+   [...]
+   $ make test
+
+   This will create the library and binaries in root source directory
+   and openssl.exe application in apps directory.
 
-   This will create the library and binaries in out. In case any problems
-   occur, try
-   > ms\mingw32 no-asm
-   instead.
+   It is also possible to cross-compile it on Linux by configuring
+   with './Configure --cross-compile-prefix=i386-mingw32- mingw ...'.
+   'make test' is naturally not applicable then.
 
    libcrypto.a and libssl.a are the static libraries. To use the DLLs,
    link with libeay32.a and libssl32.a instead.
 
-   See troubleshooting if you get error messages about functions not having
-   a number assigned.
-
- * You can now try the tests:
-
-   > cd out
-   > ..\ms\test
-
+   See troubleshooting if you get error messages about functions not
+   having a number assigned.
 
  Installation
  ------------
@@ -307,13 +300,24 @@ To install OpenSSL to the specified location do:
 
  If you link with static OpenSSL libraries [those built with ms/nt.mak],
  then you're expected to additionally link your application with
- WSOCK32.LIB, ADVAPI32.LIB, GDI32.LIB and USER32.LIB. Those developing
+ WS2_32.LIB, ADVAPI32.LIB, GDI32.LIB and USER32.LIB. Those developing
  non-interactive service applications might feel concerned about linking
- with latter two, as they are justly associated with interactive desktop,
- which is not available to service processes. The toolkit is designed
- to detect in which context it's currently executed, GUI, console app
- or service, and act accordingly, namely whether or not to actually make
- GUI calls.
+ with the latter two, as they are justly associated with interactive
+ desktop, which is not available to service processes. The toolkit is
+ designed to detect in which context it's currently executed, GUI,
+ console app or service, and act accordingly, namely whether or not to
+ actually make GUI calls. Additionally those who wish to
+ /DELAYLOAD:GDI32.DLL and /DELAYLOAD:USER32.DLL and actually keep them
+ off service process should consider implementing and exporting from
+ .exe image in question own _OPENSSL_isservice not relying on USER32.DLL.
+ E.g., on Windows Vista and later you could:
+
+       __declspec(dllexport) __cdecl BOOL _OPENSSL_isservice(void)
+       {   DWORD sess;
+           if (ProcessIdToSessionId(GetCurrentProcessId(),&sess))
+               return sess==0;
+           return FALSE;
+       }
 
  If you link with OpenSSL .DLLs, then you're expected to include into
  your application code small "shim" snippet, which provides glue between
index adc03f4..d78c61a 100644 (file)
@@ -4,27 +4,36 @@
 
  Building OpenSSL for Windows CE requires the following external tools:
 
-  * Microsoft eMbedded Visual C++ 3.0
-  * wcecompat compatibility library (www.essemer.com.au)
-  * Optionally ceutils for running automated tests (www.essemer.com.au)
-
- You also need Perl for Win32.  You will need ActiveState Perl, available
- from http://www.activestate.com/ActivePerl.
-
- Windows CE support in OpenSSL relies on wcecompat and therefore it's
- appropriate to check http://www.essemer.com.au/windowsce/ for updates in
- case of compilation problems. As for the moment of this writing version
- 1.1 is available and actually required for WCE 4.2 and newer platforms.
- All Windows CE specific issues should be directed to www.essemer.com.au.
-
- The C Runtime Library implementation for Windows CE that is included with
- Microsoft eMbedded Visual C++ 3.0 is incomplete and in some places
- incorrect.  wcecompat plugs the holes and tries to bring the Windows CE
- CRT to a level that is more compatible with ANSI C.  wcecompat goes further
- and provides low-level IO and stream IO support for stdin/stdout/stderr
- (which Windows CE does not provide).  This IO functionality is not needed
- by the OpenSSL library itself but is used for the tests and openssl.exe.
- More information is available at www.essemer.com.au.
+  * Microsoft eMbedded Visual C++ 3.0 or later
+  * Appropriate SDK might be required
+  * Perl for Win32 [commonly recommended ActiveState Perl is available
+    from http://www.activestate.com/Products/ActivePerl/]
+
+  * wcecompat compatibility library available at
+    http://www.essemer.com.au/windowsce/
+  * Optionally ceutils for running automated tests (same location)
+
+  _or_
+
+  * PocketConsole driver and PortSDK available at
+    http://www.symbolictools.de/public/pocketconsole/
+  * CMD command interpreter (same location)
+
+ As Windows CE support in OpenSSL relies on 3rd party compatibility
+ library, it's appropriate to check corresponding URL for updates. For
+ example if you choose wcecompat, note that as for the moment of this
+ writing version 1.2 is available and actually required for WCE 4.2
+ and newer platforms. All wcecompat issues should be directed to
+ www.essemer.com.au.
+
+ Why compatibility library at all? The C Runtime Library implementation
+ for Windows CE that is included with Microsoft eMbedded Visual C++ is
+ incomplete and in some places incorrect.  Compatibility library plugs
+ the holes and tries to bring the Windows CE CRT to [more] usable level.
+ Most gaping hole in CRT is support for stdin/stdout/stderr IO, which
+ proposed compatibility libraries solve in two different ways: wcecompat
+ redirects IO to active sync link, while PortSDK - to NT-like console
+ driver on the handheld itself.
 
  Building
  --------
 
  > "C:\Program Files\Microsoft eMbedded Tools\EVC\WCE300\BIN\WCEARM.BAT"
 
- Next indicate where wcecompat is located:
+ Next pick compatibility library according to your preferences.
 
- > set WCECOMPAT=C:\wcecompat
+ 1. To choose wcecompat set up WCECOMPAT environment variable pointing
+    at the location of wcecompat tree "root":
+
+    > set WCECOMPAT=C:\wcecompat
+    > set PORTSDK_LIBPATH=
+
+ 2. To choose PortSDK set up PORTSDK_LIBPATH to point at hardware-
+    specific location where your portlib.lib is installed:
+
+    > set PORTSDK_LIBPATH=C:\PortSDK\lib\ARM
+    > set WCECOMPAT=
+
+ Note that you may not set both variables.
 
  Next you should run Configure:
 
 
  Then from the VC++ environment at a prompt do:
 
- - to build static libraries:
+   > nmake -f ms\cedll.mak
 
-   > nmake -f ms\ce.mak
+ [note that static builds are not supported under CE]
 
- - or to build DLLs:
+ If all is well it should compile and you will have some DLLs and executables
+ in out32dll*. 
 
-   > nmake -f ms\cedll.mak
+ <<< everyting below needs revision in respect to wcecompat vs. PortSDK >>>
 
- If all is well it should compile and you will have some static libraries and
- executables in out32, or some DLLs and executables in out32dll.  If you want
+ If you want
  to try the tests then make sure the ceutils are in the path and do:
  
  > cd out32
index 0528300..8fe8885 100644 (file)
@@ -4,17 +4,17 @@
 ## Makefile for OpenSSL
 ##
 
-VERSION=0.9.8r
-MAJOR=0
-MINOR=9.8
-SHLIB_VERSION_NUMBER=0.9.8
+VERSION=1.0.0f
+MAJOR=1
+MINOR=0.0
+SHLIB_VERSION_NUMBER=1.0.0
 SHLIB_VERSION_HISTORY=
-SHLIB_MAJOR=0
-SHLIB_MINOR=9.8
+SHLIB_MAJOR=1
+SHLIB_MINOR=0.0
 SHLIB_EXT=
-PLATFORM=VC-WIN32
-OPTIONS=--prefix=build\debug\lib no-camellia no-capieng no-cms no-gmp no-jpake no-krb5 no-mdc2 no-montasm no-rc5 no-rfc3779 no-seed no-shared no-zlib no-zlib-dynamic
-CONFIGURE_ARGS=VC-WIN32 --prefix=build\debug\lib no-zlib no-zlib-dynamic
+PLATFORM=dist
+OPTIONS= no-gmp no-jpake no-krb5 no-md2 no-rc5 no-rfc3779 no-shared no-store no-zlib no-zlib-dynamic static-engine
+CONFIGURE_ARGS=dist
 SHLIB_TARGET=
 
 # 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=build\debug\lib
+INSTALLTOP=/usr/local/ssl
 
 # Do not edit this manually. Use Configure --openssldir=DIR do change this!
-OPENSSLDIR=build\debug\lib/build\debug\lib/ssl
+OPENSSLDIR=/usr/local/ssl
 
 # NO_IDEA - Define to build without the IDEA algorithm
 # NO_RC4  - Define to build without the RC4 algorithm
@@ -59,17 +59,17 @@ OPENSSLDIR=build\debug\lib/build\debug\lib/ssl
 # equal 4.
 # PKCS1_CHECK - pkcs1 tests.
 
-CC= cl
-CFLAG= -DOPENSSL_THREADS  -DDSO_WIN32 
-DEPFLAG= -DOPENSSL_NO_CAMELLIA -DOPENSSL_NO_CAPIENG -DOPENSSL_NO_CMS -DOPENSSL_NO_GMP -DOPENSSL_NO_JPAKE -DOPENSSL_NO_MDC2 -DOPENSSL_NO_RC5 -DOPENSSL_NO_RFC3779 -DOPENSSL_NO_SEED
+CC= cc
+CFLAG= -O
+DEPFLAG= -DOPENSSL_NO_GMP -DOPENSSL_NO_JPAKE -DOPENSSL_NO_MD2 -DOPENSSL_NO_RC5 -DOPENSSL_NO_RFC3779 -DOPENSSL_NO_STORE
 PEX_LIBS= 
 EX_LIBS= 
 EXE_EXT= 
 ARFLAGS= 
 AR= ar $(ARFLAGS) r
-ARD=ar $(ARFLAGS) d
-RANLIB= true
-PERL= perl
+RANLIB= /usr/bin/ranlib
+NM= nm
+PERL= /usr/bin/perl
 TAR= tar
 TARFLAGS= --no-recursion
 MAKEDEPPROG=makedepend
@@ -88,10 +88,10 @@ ASFLAG=$(CFLAG)
 PROCESSOR= 
 
 # CPUID module collects small commonly used assembler snippets
-CPUID_OBJ= 
+CPUID_OBJ= mem_clr.o
 BN_ASM= bn_asm.o
 DES_ENC= des_enc.o fcrypt_b.o
-AES_ASM_OBJ= aes_core.o aes_cbc.o
+AES_ENC= aes_core.o aes_cbc.o
 BF_ENC= bf_enc.o
 CAST_ENC= c_enc.o
 RC4_ENC= rc4_enc.o rc4_skey.o
@@ -99,6 +99,9 @@ RC5_ENC= rc5_enc.o
 MD5_ASM_OBJ= 
 SHA1_ASM_OBJ= 
 RMD160_ASM_OBJ= 
+WP_ASM_OBJ= wp_block.o
+CMLL_ENC= camellia.o cmll_misc.o cmll_cbc.o
+PERLASM_SCHEME= 
 
 # KRB5 stuff
 KRB5_INCLUDES=
@@ -108,44 +111,19 @@ LIBKRB5=
 ZLIB_INCLUDE=
 LIBZLIB=
 
-# This is the location of fipscanister.o and friends.
-# The FIPS module build will place it $(INSTALLTOP)/lib
-# but since $(INSTALLTOP) can only take the default value
-# when the module is built it will be in /usr/local/ssl/lib
-# $(INSTALLTOP) for this build make be different so hard
-# code the path.
-
-FIPSLIBDIR=/usr/local/ssl/fips-1.0/lib/
-
-# This is set to "y" if fipscanister.o is compiled internally as
-# opposed to coming from an external validated location.
-
-FIPSCANISTERINTERNAL=n
-
-# The location of the library which contains fipscanister.o
-# normally it will be libcrypto unless fipsdso is set in which
-# case it will be libfips. If not compiling in FIPS mode at all
-# this is empty making it a useful test for a FIPS compile.
-
-FIPSCANLIB=
-
-# Shared library base address. Currently only used on Windows.
-#
-
-BASEADDR=0xFB00000
-
 DIRS=   crypto ssl engines apps test tools
+ENGDIRS= ccgost
 SHLIBDIRS= crypto ssl
 
 # dirs in crypto to build
 SDIRS=  \
        objects \
-       md2 md4 md5 sha hmac ripemd \
-       des aes rc2 rc4 idea bf cast \
+       md4 md5 sha mdc2 hmac ripemd whrlpool \
+       des aes rc2 rc4 idea bf cast camellia seed modes \
        bn ec rsa dsa ecdsa dh ecdh dso engine \
        buffer bio stack lhash rand err \
        evp asn1 pem x509 x509v3 conf txt_db pkcs7 pkcs12 comp ocsp ui krb5 \
-       store pqueue
+       cms pqueue ts
 # keep in mind that the above list is adjusted by ./Configure
 # according to no-xxx arguments...
 
@@ -159,6 +137,8 @@ MANDIR=$(OPENSSLDIR)/man
 MAN1=1
 MAN3=3
 MANSUFFIX=
+HTMLSUFFIX=html
+HTMLDIR=$(OPENSSLDIR)/html
 SHELL=/bin/sh
 
 TOP=    .
@@ -168,7 +148,6 @@ WDIRS=  windows
 LIBS=   libcrypto.a libssl.a
 SHARED_CRYPTO=libcrypto$(SHLIB_EXT)
 SHARED_SSL=libssl$(SHLIB_EXT)
-SHARED_FIPS=
 SHARED_LIBS=
 SHARED_LIBS_LINK_EXTS=
 SHARED_LDFLAGS=
@@ -199,34 +178,35 @@ CLEARENV= TOP= && unset TOP $${LIB+LIB} $${LIBS+LIBS}     \
                $${SHAREDCMD+SHAREDCMD} $${SHAREDFLAGS+SHAREDFLAGS}     \
                $${SHARED_LIB+SHARED_LIB} $${LIBEXTRAS+LIBEXTRAS}
 
-BUILDENV=      PLATFORM='${PLATFORM}' PROCESSOR='${PROCESSOR}' \
-               CC='${CC}' CFLAG='${CFLAG}'                     \
-               AS='${CC}' ASFLAG='${CFLAG} -c'                 \
-               AR='${AR}' PERL='${PERL}' RANLIB='${RANLIB}'    \
-               SDIRS='${SDIRS}' LIBRPATH='${INSTALLTOP}/$(LIBDIR)'     \
-               INSTALL_PREFIX='${INSTALL_PREFIX}'              \
-               INSTALLTOP='${INSTALLTOP}' OPENSSLDIR='${OPENSSLDIR}'   \
-               LIBDIR='${LIBDIR}' \
-               MAKEDEPEND='$$$${TOP}/util/domd $$$${TOP} -MD ${MAKEDEPPROG}' \
-               DEPFLAG='-DOPENSSL_NO_DEPRECATED ${DEPFLAG}'    \
-               MAKEDEPPROG='${MAKEDEPPROG}'                    \
-               SHARED_LDFLAGS='${SHARED_LDFLAGS}'              \
-               KRB5_INCLUDES='${KRB5_INCLUDES}' LIBKRB5='${LIBKRB5}'   \
-               EXE_EXT='${EXE_EXT}' SHARED_LIBS='${SHARED_LIBS}'       \
-               SHLIB_EXT='${SHLIB_EXT}' SHLIB_TARGET='${SHLIB_TARGET}' \
-               PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}'     \
-               CPUID_OBJ='${CPUID_OBJ}'                        \
-               BN_ASM='${BN_ASM}' DES_ENC='${DES_ENC}'         \
-               AES_ASM_OBJ='${AES_ASM_OBJ}'                    \
-               BF_ENC='${BF_ENC}' CAST_ENC='${CAST_ENC}'       \
-               RC4_ENC='${RC4_ENC}' RC5_ENC='${RC5_ENC}'       \
-               SHA1_ASM_OBJ='${SHA1_ASM_OBJ}'                  \
-               MD5_ASM_OBJ='${MD5_ASM_OBJ}'                    \
-               RMD160_ASM_OBJ='${RMD160_ASM_OBJ}'              \
-               FIPSLIBDIR='${FIPSLIBDIR}'                      \
-               FIPSCANLIB="$${FIPSCANLIB:-$(FIPSCANLIB)}"      \
-               FIPSCANISTERINTERNAL='${FIPSCANISTERINTERNAL}'  \
-               FIPS_EX_OBJ='${FIPS_EX_OBJ}'    \
+BUILDENV=      PLATFORM='$(PLATFORM)' PROCESSOR='$(PROCESSOR)' \
+               CC='$(CC)' CFLAG='$(CFLAG)'                     \
+               AS='$(CC)' ASFLAG='$(CFLAG) -c'                 \
+               AR='$(AR)' NM='$(NM)' RANLIB='$(RANLIB)'        \
+               CROSS_COMPILE='$(CROSS_COMPILE)'        \
+               PERL='$(PERL)' ENGDIRS='$(ENGDIRS)'             \
+               SDIRS='$(SDIRS)' LIBRPATH='$(INSTALLTOP)/$(LIBDIR)'     \
+               INSTALL_PREFIX='$(INSTALL_PREFIX)'              \
+               INSTALLTOP='$(INSTALLTOP)' OPENSSLDIR='$(OPENSSLDIR)'   \
+               LIBDIR='$(LIBDIR)'                              \
+               MAKEDEPEND='$$$${TOP}/util/domd $$$${TOP} -MD $(MAKEDEPPROG)' \
+               DEPFLAG='-DOPENSSL_NO_DEPRECATED $(DEPFLAG)'    \
+               MAKEDEPPROG='$(MAKEDEPPROG)'                    \
+               SHARED_LDFLAGS='$(SHARED_LDFLAGS)'              \
+               KRB5_INCLUDES='$(KRB5_INCLUDES)' LIBKRB5='$(LIBKRB5)'   \
+               ZLIB_INCLUDE='$(ZLIB_INCLUDE)' LIBZLIB='$(LIBZLIB)'     \
+               EXE_EXT='$(EXE_EXT)' SHARED_LIBS='$(SHARED_LIBS)'       \
+               SHLIB_EXT='$(SHLIB_EXT)' SHLIB_TARGET='$(SHLIB_TARGET)' \
+               PEX_LIBS='$(PEX_LIBS)' EX_LIBS='$(EX_LIBS)'     \
+               CPUID_OBJ='$(CPUID_OBJ)'                        \
+               BN_ASM='$(BN_ASM)' DES_ENC='$(DES_ENC)'         \
+               AES_ENC='$(AES_ENC)' CMLL_ENC='$(CMLL_ENC)'     \
+               BF_ENC='$(BF_ENC)' CAST_ENC='$(CAST_ENC)'       \
+               RC4_ENC='$(RC4_ENC)' RC5_ENC='$(RC5_ENC)'       \
+               SHA1_ASM_OBJ='$(SHA1_ASM_OBJ)'                  \
+               MD5_ASM_OBJ='$(MD5_ASM_OBJ)'                    \
+               RMD160_ASM_OBJ='$(RMD160_ASM_OBJ)'              \
+               WP_ASM_OBJ='$(WP_ASM_OBJ)'                      \
+               PERLASM_SCHEME='$(PERLASM_SCHEME)'              \
                THIS=$${THIS:-$@} MAKEFILE=Makefile MAKEOVERRIDES=
 # MAKEOVERRIDES= effectively "equalizes" GNU-ish and SysV-ish make flavors,
 # which in turn eliminates ambiguities in variable treatment with -e.
@@ -245,127 +225,44 @@ BUILDENV=        PLATFORM='${PLATFORM}' PROCESSOR='${PROCESSOR}' \
 # subdirectories defined in $(DIRS).  It requires that the target
 # is given through the shell variable `target'.
 BUILD_CMD=  if [ -d "$$dir" ]; then \
-           (   [ $$target != all -a -z "$(FIPSCANLIB)" ] && FIPSCANLIB=/dev/null; \
-               cd $$dir && echo "making $$target in $$dir..." && \
+           (   cd $$dir && echo "making $$target in $$dir..." && \
                $(CLEARENV) && $(MAKE) -e $(BUILDENV) TOP=.. DIR=$$dir $$target \
            ) || exit 1; \
            fi
 RECURSIVE_BUILD_CMD=for dir in $(DIRS); do $(BUILD_CMD); done
 BUILD_ONE_CMD=\
-       if echo " $(DIRS) " | grep " $$dir " >/dev/null 2>/dev/null; then \
+       if expr " $(DIRS) " : ".* $$dir " >/dev/null 2>&1; then \
                $(BUILD_CMD); \
        fi
 
 reflect:
        @[ -n "$(THIS)" ] && $(CLEARENV) && $(MAKE) $(THIS) -e $(BUILDENV)
 
-FIPS_EX_OBJ= ../crypto/aes/aes_cfb.o \
-       ../crypto/aes/aes_ecb.o \
-       ../crypto/aes/aes_ofb.o \
-       ../crypto/bn/bn_add.o \
-       ../crypto/bn/bn_blind.o \
-       ../crypto/bn/bn_ctx.o \
-       ../crypto/bn/bn_div.o \
-       ../crypto/bn/bn_exp2.o \
-       ../crypto/bn/bn_exp.o \
-       ../crypto/bn/bn_gcd.o \
-       ../crypto/bn/bn_lib.o \
-       ../crypto/bn/bn_mod.o \
-       ../crypto/bn/bn_mont.o \
-       ../crypto/bn/bn_mul.o \
-       ../crypto/bn/bn_prime.o \
-       ../crypto/bn/bn_rand.o \
-       ../crypto/bn/bn_recp.o \
-       ../crypto/bn/bn_shift.o \
-       ../crypto/bn/bn_sqr.o \
-       ../crypto/bn/bn_word.o \
-       ../crypto/bn/bn_x931p.o \
-       ../crypto/buffer/buf_str.o \
-       ../crypto/cryptlib.o \
-       ../crypto/des/cfb64ede.o \
-       ../crypto/des/cfb64enc.o \
-       ../crypto/des/cfb_enc.o \
-       ../crypto/des/ecb3_enc.o \
-       ../crypto/des/ecb_enc.o \
-       ../crypto/des/ofb64ede.o \
-       ../crypto/des/ofb64enc.o \
-       ../crypto/des/fcrypt.o \
-       ../crypto/des/set_key.o \
-       ../crypto/dsa/dsa_utl.o \
-       ../crypto/dsa/dsa_sign.o \
-       ../crypto/dsa/dsa_vrf.o \
-       ../crypto/err/err.o \
-       ../crypto/evp/digest.o \
-       ../crypto/evp/enc_min.o \
-       ../crypto/evp/e_aes.o \
-       ../crypto/evp/e_des3.o \
-       ../crypto/evp/p_sign.o \
-       ../crypto/evp/p_verify.o \
-       ../crypto/mem_clr.o \
-       ../crypto/mem.o \
-       ../crypto/rand/md_rand.o \
-       ../crypto/rand/rand_egd.o \
-       ../crypto/rand/randfile.o \
-       ../crypto/rand/rand_lib.o \
-       ../crypto/rand/rand_os2.o \
-       ../crypto/rand/rand_unix.o \
-       ../crypto/rand/rand_win.o \
-       ../crypto/rsa/rsa_lib.o \
-       ../crypto/rsa/rsa_none.o \
-       ../crypto/rsa/rsa_oaep.o \
-       ../crypto/rsa/rsa_pk1.o \
-       ../crypto/rsa/rsa_pss.o \
-       ../crypto/rsa/rsa_ssl.o \
-       ../crypto/rsa/rsa_x931.o \
-       ../crypto/sha/sha1dgst.o \
-       ../crypto/sha/sha256.o \
-       ../crypto/sha/sha512.o \
-       ../crypto/uid.o
-
 sub_all: build_all
 build_all: build_libs build_apps build_tests build_tools
 
-build_libs: build_crypto build_fips build_ssl build_shared build_engines
+build_libs: build_crypto build_ssl build_engines
 
 build_crypto:
-       if [ -n "$(FIPSCANLIB)" ]; then \
-               EXCL_OBJ='$(AES_ASM_OBJ) $(BN_ASM) $(DES_ENC) $(CPUID_OBJ) $(SHA1_ASM_OBJ) $(FIPS_EX_OBJ)' ; export EXCL_OBJ ; \
-               ARX='$(PERL) $${TOP}/util/arx.pl $(AR)' ; \
-       else \
-               ARX='${AR}' ; \
-       fi ; export ARX ; \
-               dir=crypto; target=all; $(BUILD_ONE_CMD)
-build_fips:
-       @dir=fips; target=all; [ -z "$(FIPSCANLIB)" ] || $(BUILD_ONE_CMD)
-build_ssl: build_crypto
+       @dir=crypto; target=all; $(BUILD_ONE_CMD)
+build_ssl:
        @dir=ssl; target=all; $(BUILD_ONE_CMD)
-build_engines: build_crypto
+build_engines:
        @dir=engines; target=all; $(BUILD_ONE_CMD)
-build_apps: build_libs
+build_apps:
        @dir=apps; target=all; $(BUILD_ONE_CMD)
-build_tests: build_libs
+build_tests:
        @dir=test; target=all; $(BUILD_ONE_CMD)
-build_tools: build_libs
+build_tools:
        @dir=tools; target=all; $(BUILD_ONE_CMD)
 
 all_testapps: build_libs build_testapps
 build_testapps:
        @dir=crypto; target=testapps; $(BUILD_ONE_CMD)
 
-build_shared:  $(SHARED_LIBS)
-libcrypto$(SHLIB_EXT): libcrypto.a $(SHARED_FIPS)
+libcrypto$(SHLIB_EXT): libcrypto.a
        @if [ "$(SHLIB_TARGET)" != "" ]; then \
-               if [ "$(FIPSCANLIB)" = "libfips" ]; then \
-                       $(ARD) libcrypto.a fipscanister.o ; \
-                       $(MAKE) SHLIBDIRS='crypto' SHLIBDEPS='-lfips' build-shared; \
-                       $(AR) libcrypto.a fips/fipscanister.o ; \
-               else \
-                       if [ "$(FIPSCANLIB)" = "libcrypto" ]; then \
-                               FIPSLD_CC="$(CC)"; CC=fips/fipsld; \
-                               export CC FIPSLD_CC; \
-                       fi; \
-                       $(MAKE) -e SHLIBDIRS='crypto' build-shared; \
-               fi \
+               $(MAKE) SHLIBDIRS=crypto build-shared; \
        else \
                echo "There's no support for shared libraries on this platform" >&2; \
                exit 1; \
@@ -373,32 +270,12 @@ libcrypto$(SHLIB_EXT): libcrypto.a $(SHARED_FIPS)
 
 libssl$(SHLIB_EXT): libcrypto$(SHLIB_EXT) libssl.a
        @if [ "$(SHLIB_TARGET)" != "" ]; then \
-               shlibdeps=-lcrypto; \
-               [ "$(FIPSCANLIB)" = "libfips" ] && shlibdeps="$$shlibdeps -lfips"; \
-               $(MAKE) SHLIBDIRS=ssl SHLIBDEPS="$$shlibdeps" build-shared; \
-       else \
-               echo "There's no support for shared libraries on this platform" >&2 ; \
-               exit 1; \
-       fi
-
-fips/fipscanister.o:   build_fips
-libfips$(SHLIB_EXT):           fips/fipscanister.o
-       @if [ "$(SHLIB_TARGET)" != "" ]; then \
-               FIPSLD_CC="$(CC)"; CC=fips/fipsld; export CC FIPSLD_CC; \
-               $(MAKE) -f Makefile.shared -e $(BUILDENV) \
-                       CC=$${CC} LIBNAME=fips THIS=$@ \
-                       LIBEXTRAS=fips/fipscanister.o \
-                       LIBDEPS="$(EX_LIBS)" \
-                       LIBVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR} \
-                       link_o.$(SHLIB_TARGET) || { rm -f $@; exit 1; } \
+               $(MAKE) SHLIBDIRS=ssl SHLIBDEPS='-lcrypto' build-shared; \
        else \
                echo "There's no support for shared libraries on this platform" >&2; \
                exit 1; \
        fi
 
-libfips.a:
-       dir=fips; target=all; $(BUILD_ONE_CMD)
-
 clean-shared:
        @set -e; for i in $(SHLIBDIRS); do \
                if [ -n "$(SHARED_LIBS_LINK_EXTS)" ]; then \
@@ -414,10 +291,10 @@ clean-shared:
        done
 
 link-shared:
-       @ set -e; for i in ${SHLIBDIRS}; do \
+       @ set -e; for i in $(SHLIBDIRS); do \
                $(MAKE) -f $(HERE)/Makefile.shared -e $(BUILDENV) \
-                       LIBNAME=$$i LIBVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR} \
-                       LIBCOMPATVERSIONS=";${SHLIB_VERSION_HISTORY}" \
+                       LIBNAME=$$i LIBVERSION=$(SHLIB_MAJOR).$(SHLIB_MINOR) \
+                       LIBCOMPATVERSIONS=";$(SHLIB_VERSION_HISTORY)" \
                        symlink.$(SHLIB_TARGET); \
                libs="$$libs -l$$i"; \
        done
@@ -425,13 +302,13 @@ link-shared:
 build-shared: do_$(SHLIB_TARGET) link-shared
 
 do_$(SHLIB_TARGET):
-       @ set -e; libs='-L. ${SHLIBDEPS}'; for i in ${SHLIBDIRS}; do \
-               if [ "${SHLIBDIRS}" = "ssl" -a -n "$(LIBKRB5)" ]; then \
+       @ set -e; libs='-L. $(SHLIBDEPS)'; for i in $(SHLIBDIRS); do \
+               if [ "$$i" = "ssl" -a -n "$(LIBKRB5)" ]; then \
                        libs="$(LIBKRB5) $$libs"; \
                fi; \
                $(CLEARENV) && $(MAKE) -f Makefile.shared -e $(BUILDENV) \
-                       LIBNAME=$$i LIBVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR} \
-                       LIBCOMPATVERSIONS=";${SHLIB_VERSION_HISTORY}" \
+                       LIBNAME=$$i LIBVERSION=$(SHLIB_MAJOR).$(SHLIB_MINOR) \
+                       LIBCOMPATVERSIONS=";$(SHLIB_VERSION_HISTORY)" \
                        LIBDEPS="$$libs $(EX_LIBS)" \
                        link_a.$(SHLIB_TARGET); \
                libs="-l$$i $$libs"; \
@@ -508,34 +385,32 @@ links:
        @$(PERL) $(TOP)/util/mkdir-p.pl include/openssl
        @$(PERL) $(TOP)/util/mklink.pl include/openssl $(EXHEADER)
        @set -e; target=links; $(RECURSIVE_BUILD_CMD)
-       @if [ -z "$(FIPSCANLIB)" ]; then \
-               set -e; target=links; dir=fips ; $(BUILD_CMD) ; \
-       fi
 
 gentests:
        @(cd test && echo "generating dummy tests (if needed)..." && \
-       $(CLEARENV) && $(MAKE) -e $(BUILDENV) TESTS='${TESTS}' OPENSSL_DEBUG_MEMORY=on generate );
+       $(CLEARENV) && $(MAKE) -e $(BUILDENV) TESTS='$(TESTS)' OPENSSL_DEBUG_MEMORY=on generate );
 
 dclean:
-       rm -f *.bak
+       rm -rf *.bak include/openssl certs/.0
        @set -e; target=dclean; $(RECURSIVE_BUILD_CMD)
 
 rehash: rehash.time
 rehash.time: certs apps
        @if [ -z "$(CROSS_COMPILE)" ]; then \
                (OPENSSL="`pwd`/util/opensslwrap.sh"; \
+               [ -x "apps/openssl.exe" ] && OPENSSL="apps/openssl.exe" || :; \
                OPENSSL_DEBUG_MEMORY=on; \
                export OPENSSL OPENSSL_DEBUG_MEMORY; \
                $(PERL) tools/c_rehash certs) && \
                touch rehash.time; \
-       fi
+       else :; fi
 
 test:   tests
 
 tests: rehash
        @(cd test && echo "testing..." && \
-       $(CLEARENV) && $(MAKE) -e $(BUILDENV) TOP=.. TESTS='${TESTS}' OPENSSL_DEBUG_MEMORY=on tests );
-       util/opensslwrap.sh version -a
+       $(CLEARENV) && $(MAKE) -e $(BUILDENV) TOP=.. TESTS='$(TESTS)' OPENSSL_DEBUG_MEMORY=on OPENSSL_CONF=../apps/openssl.cnf tests );
+       OPENSSL_CONF=apps/openssl.cnf util/opensslwrap.sh version -a
 
 report:
        @$(PERL) util/selftest.pl
@@ -568,6 +443,8 @@ crypto/objects/obj_dat.h: crypto/objects/obj_dat.pl crypto/objects/obj_mac.h
        $(PERL) crypto/objects/obj_dat.pl crypto/objects/obj_mac.h crypto/objects/obj_dat.h
 crypto/objects/obj_mac.h: crypto/objects/objects.pl crypto/objects/objects.txt crypto/objects/obj_mac.num
        $(PERL) crypto/objects/objects.pl crypto/objects/objects.txt crypto/objects/obj_mac.num crypto/objects/obj_mac.h
+crypto/objects/obj_xref.h: crypto/objects/objxref.pl crypto/objects/obj_xref.txt crypto/objects/obj_mac.num
+       $(PERL) crypto/objects/objxref.pl crypto/objects/obj_mac.num crypto/objects/obj_xref.txt >crypto/objects/obj_xref.h
 
 apps/openssl-vms.cnf: apps/openssl.cnf
        $(PERL) VMS/VMSify-conf.pl < apps/openssl.cnf > apps/openssl-vms.cnf
@@ -580,7 +457,7 @@ TABLE: Configure
        (echo 'Output of `Configure TABLE'"':"; \
        $(PERL) Configure TABLE) > TABLE
 
-update: errors stacks util/libeay.num util/ssleay.num crypto/objects/obj_dat.h apps/openssl-vms.cnf crypto/bn/bn_prime.h TABLE depend
+update: errors stacks util/libeay.num util/ssleay.num crypto/objects/obj_dat.h crypto/objects/obj_xref.h apps/openssl-vms.cnf crypto/bn/bn_prime.h TABLE depend
 
 # Build distribution tar-file. As the list of files returned by "find" is
 # pretty long, on several platforms a "too many arguments" error or similar
@@ -611,8 +488,8 @@ tar-snap:
 dist:   
        $(PERL) Configure dist
        @$(MAKE) dist_pem_h
-       @$(MAKE) SDIRS='${SDIRS}' clean
-       @$(MAKE) TAR='${TAR}' TARFLAGS='${TARFLAGS}' tar
+       @$(MAKE) SDIRS='$(SDIRS)' clean
+       @$(MAKE) TAR='$(TAR)' TARFLAGS='$(TARFLAGS)' tar
 
 dist_pem_h:
        (cd crypto/pem; $(MAKE) -e $(BUILDENV) pem.h; $(MAKE) clean)
@@ -663,6 +540,16 @@ install_sw:
                                        chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$i.new; \
                                        mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$i.new $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$i; \
                                fi ); \
+                               if expr $(PLATFORM) : 'mingw' > /dev/null; then \
+                               (       case $$i in \
+                                               *crypto*) i=libeay32.dll;; \
+                                               *ssl*)    i=ssleay32.dll;; \
+                                       esac; \
+                                       echo installing $$i; \
+                                       cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new; \
+                                       chmod 755 $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new; \
+                                       mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i ); \
+                               fi; \
                        fi; \
                done; \
                (       here="`pwd`"; \
@@ -682,6 +569,27 @@ install_sw:
        cp openssl.pc $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
        chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc
 
+install_html_docs:
+       here="`pwd`"; \
+       for subdir in apps crypto ssl; do \
+               mkdir -p $(INSTALL_PREFIX)$(HTMLDIR)/$$subdir; \
+               for i in doc/$$subdir/*.pod; do \
+                       fn=`basename $$i .pod`; \
+                       echo "installing html/$$fn.$(HTMLSUFFIX)"; \
+                       cat $$i \
+                       | sed -r 's/L<([^)]*)(\([0-9]\))?\|([^)]*)(\([0-9]\))?>/L<\1|\3>/g' \
+                       | pod2html --podroot=doc --htmlroot=.. --podpath=apps:crypto:ssl \
+                       | sed -r 's/<!DOCTYPE.*//g' \
+                       > $(INSTALL_PREFIX)$(HTMLDIR)/$$subdir/$$fn.$(HTMLSUFFIX); \
+                       $(PERL) util/extract-names.pl < $$i | \
+                               grep -v $$filecase "^$$fn\$$" | \
+                               (cd $(INSTALL_PREFIX)$(HTMLDIR)/$$subdir; \
+                                while read n; do \
+                                       PLATFORM=$(PLATFORM) $$here/util/point.sh $$fn.$(HTMLSUFFIX) "$$n".$(HTMLSUFFIX); \
+                                done); \
+               done; \
+       done
+
 install_docs:
        @$(PERL) $(TOP)/util/mkdir-p.pl \
                $(INSTALL_PREFIX)$(MANDIR)/man1 \
@@ -708,7 +616,7 @@ install_docs:
                        (grep -v "[     ]"; true) | \
                        (cd $(INSTALL_PREFIX)$(MANDIR)/man$$sec/; \
                         while read n; do \
-                               $$here/util/point.sh $$fn.$${sec}$(MANSUFFIX) "$$n".$${sec}$(MANSUFFIX); \
+                               PLATFORM=$(PLATFORM) $$here/util/point.sh $$fn.$${sec}$(MANSUFFIX) "$$n".$${sec}$(MANSUFFIX); \
                         done); \
        done; \
        set -e; for i in doc/crypto/*.pod doc/ssl/*.pod; do \
@@ -725,7 +633,7 @@ install_docs:
                        (grep -v "[     ]"; true) | \
                        (cd $(INSTALL_PREFIX)$(MANDIR)/man$$sec/; \
                         while read n; do \
-                               $$here/util/point.sh $$fn.$${sec}$(MANSUFFIX) "$$n".$${sec}$(MANSUFFIX); \
+                               PLATFORM=$(PLATFORM) $$here/util/point.sh $$fn.$${sec}$(MANSUFFIX) "$$n".$${sec}$(MANSUFFIX); \
                         done); \
        done
 
index e87d623..fb0af7e 100644 (file)
@@ -65,8 +65,8 @@ EX_LIBS=
 EXE_EXT= 
 ARFLAGS=
 AR=ar $(ARFLAGS) r
-ARD=ar $(ARFLAGS) d
 RANLIB= ranlib
+NM= nm
 PERL= perl
 TAR= tar
 TARFLAGS= --no-recursion
@@ -89,7 +89,7 @@ PROCESSOR=
 CPUID_OBJ= 
 BN_ASM= bn_asm.o
 DES_ENC= des_enc.o fcrypt_b.o
-AES_ASM_OBJ=aes_core.o aes_cbc.o
+AES_ENC= aes_core.o aes_cbc.o
 BF_ENC= bf_enc.o
 CAST_ENC= c_enc.o
 RC4_ENC= rc4_enc.o
@@ -97,6 +97,9 @@ RC5_ENC= rc5_enc.o
 MD5_ASM_OBJ= 
 SHA1_ASM_OBJ= 
 RMD160_ASM_OBJ= 
+WP_ASM_OBJ=
+CMLL_ENC=
+PERLASM_SCHEME=
 
 # KRB5 stuff
 KRB5_INCLUDES=
@@ -106,44 +109,19 @@ LIBKRB5=
 ZLIB_INCLUDE=
 LIBZLIB=
 
-# This is the location of fipscanister.o and friends.
-# The FIPS module build will place it $(INSTALLTOP)/lib
-# but since $(INSTALLTOP) can only take the default value
-# when the module is built it will be in /usr/local/ssl/lib
-# $(INSTALLTOP) for this build make be different so hard
-# code the path.
-
-FIPSLIBDIR=/usr/local/ssl/$(LIBDIR)/
-
-# This is set to "y" if fipscanister.o is compiled internally as
-# opposed to coming from an external validated location.
-
-FIPSCANISTERINTERNAL=n
-
-# The location of the library which contains fipscanister.o
-# normally it will be libcrypto unless fipsdso is set in which
-# case it will be libfips. If not compiling in FIPS mode at all
-# this is empty making it a useful test for a FIPS compile.
-
-FIPSCANLIB=
-
-# Shared library base address. Currently only used on Windows.
-#
-
-BASEADDR=
-
-DIRS=   crypto fips ssl engines apps test tools
-SHLIBDIRS= crypto ssl fips
+DIRS=   crypto ssl engines apps test tools
+ENGDIRS= ccgost
+SHLIBDIRS= crypto ssl
 
 # dirs in crypto to build
 SDIRS=  \
        objects \
-       md2 md4 md5 sha mdc2 hmac ripemd \
-       des aes rc2 rc4 rc5 idea bf cast camellia seed \
+       md2 md4 md5 sha mdc2 hmac ripemd whrlpool \
+       des aes rc2 rc4 rc5 idea bf cast camellia seed modes \
        bn ec rsa dsa ecdsa dh ecdh dso engine \
        buffer bio stack lhash rand err \
        evp asn1 pem x509 x509v3 conf txt_db pkcs7 pkcs12 comp ocsp ui krb5 \
-       store cms pqueue jpake
+       cms pqueue ts jpake store
 # keep in mind that the above list is adjusted by ./Configure
 # according to no-xxx arguments...
 
@@ -157,6 +135,8 @@ MANDIR=$(OPENSSLDIR)/man
 MAN1=1
 MAN3=3
 MANSUFFIX=
+HTMLSUFFIX=html
+HTMLDIR=$(OPENSSLDIR)/html
 SHELL=/bin/sh
 
 TOP=    .
@@ -166,7 +146,6 @@ WDIRS=  windows
 LIBS=   libcrypto.a libssl.a
 SHARED_CRYPTO=libcrypto$(SHLIB_EXT)
 SHARED_SSL=libssl$(SHLIB_EXT)
-SHARED_FIPS=
 SHARED_LIBS=
 SHARED_LIBS_LINK_EXTS=
 SHARED_LDFLAGS=
@@ -197,34 +176,35 @@ CLEARENV= TOP= && unset TOP $${LIB+LIB} $${LIBS+LIBS}     \
                $${SHAREDCMD+SHAREDCMD} $${SHAREDFLAGS+SHAREDFLAGS}     \
                $${SHARED_LIB+SHARED_LIB} $${LIBEXTRAS+LIBEXTRAS}
 
-BUILDENV=      PLATFORM='${PLATFORM}' PROCESSOR='${PROCESSOR}' \
-               CC='${CC}' CFLAG='${CFLAG}'                     \
-               AS='${CC}' ASFLAG='${CFLAG} -c'                 \
-               AR='${AR}' PERL='${PERL}' RANLIB='${RANLIB}'    \
-               SDIRS='${SDIRS}' LIBRPATH='${INSTALLTOP}/$(LIBDIR)'     \
-               INSTALL_PREFIX='${INSTALL_PREFIX}'              \
-               INSTALLTOP='${INSTALLTOP}' OPENSSLDIR='${OPENSSLDIR}'   \
-               LIBDIR='${LIBDIR}' \
-               MAKEDEPEND='$$$${TOP}/util/domd $$$${TOP} -MD ${MAKEDEPPROG}' \
-               DEPFLAG='-DOPENSSL_NO_DEPRECATED ${DEPFLAG}'    \
-               MAKEDEPPROG='${MAKEDEPPROG}'                    \
-               SHARED_LDFLAGS='${SHARED_LDFLAGS}'              \
-               KRB5_INCLUDES='${KRB5_INCLUDES}' LIBKRB5='${LIBKRB5}'   \
-               EXE_EXT='${EXE_EXT}' SHARED_LIBS='${SHARED_LIBS}'       \
-               SHLIB_EXT='${SHLIB_EXT}' SHLIB_TARGET='${SHLIB_TARGET}' \
-               PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}'     \
-               CPUID_OBJ='${CPUID_OBJ}'                        \
-               BN_ASM='${BN_ASM}' DES_ENC='${DES_ENC}'         \
-               AES_ASM_OBJ='${AES_ASM_OBJ}'                    \
-               BF_ENC='${BF_ENC}' CAST_ENC='${CAST_ENC}'       \
-               RC4_ENC='${RC4_ENC}' RC5_ENC='${RC5_ENC}'       \
-               SHA1_ASM_OBJ='${SHA1_ASM_OBJ}'                  \
-               MD5_ASM_OBJ='${MD5_ASM_OBJ}'                    \
-               RMD160_ASM_OBJ='${RMD160_ASM_OBJ}'              \
-               FIPSLIBDIR='${FIPSLIBDIR}'                      \
-               FIPSCANLIB="$${FIPSCANLIB:-$(FIPSCANLIB)}"      \
-               FIPSCANISTERINTERNAL='${FIPSCANISTERINTERNAL}'  \
-               FIPS_EX_OBJ='${FIPS_EX_OBJ}'    \
+BUILDENV=      PLATFORM='$(PLATFORM)' PROCESSOR='$(PROCESSOR)' \
+               CC='$(CC)' CFLAG='$(CFLAG)'                     \
+               AS='$(CC)' ASFLAG='$(CFLAG) -c'                 \
+               AR='$(AR)' NM='$(NM)' RANLIB='$(RANLIB)'        \
+               CROSS_COMPILE='$(CROSS_COMPILE)'        \
+               PERL='$(PERL)' ENGDIRS='$(ENGDIRS)'             \
+               SDIRS='$(SDIRS)' LIBRPATH='$(INSTALLTOP)/$(LIBDIR)'     \
+               INSTALL_PREFIX='$(INSTALL_PREFIX)'              \
+               INSTALLTOP='$(INSTALLTOP)' OPENSSLDIR='$(OPENSSLDIR)'   \
+               LIBDIR='$(LIBDIR)'                              \
+               MAKEDEPEND='$$$${TOP}/util/domd $$$${TOP} -MD $(MAKEDEPPROG)' \
+               DEPFLAG='-DOPENSSL_NO_DEPRECATED $(DEPFLAG)'    \
+               MAKEDEPPROG='$(MAKEDEPPROG)'                    \
+               SHARED_LDFLAGS='$(SHARED_LDFLAGS)'              \
+               KRB5_INCLUDES='$(KRB5_INCLUDES)' LIBKRB5='$(LIBKRB5)'   \
+               ZLIB_INCLUDE='$(ZLIB_INCLUDE)' LIBZLIB='$(LIBZLIB)'     \
+               EXE_EXT='$(EXE_EXT)' SHARED_LIBS='$(SHARED_LIBS)'       \
+               SHLIB_EXT='$(SHLIB_EXT)' SHLIB_TARGET='$(SHLIB_TARGET)' \
+               PEX_LIBS='$(PEX_LIBS)' EX_LIBS='$(EX_LIBS)'     \
+               CPUID_OBJ='$(CPUID_OBJ)'                        \
+               BN_ASM='$(BN_ASM)' DES_ENC='$(DES_ENC)'         \
+               AES_ENC='$(AES_ENC)' CMLL_ENC='$(CMLL_ENC)'     \
+               BF_ENC='$(BF_ENC)' CAST_ENC='$(CAST_ENC)'       \
+               RC4_ENC='$(RC4_ENC)' RC5_ENC='$(RC5_ENC)'       \
+               SHA1_ASM_OBJ='$(SHA1_ASM_OBJ)'                  \
+               MD5_ASM_OBJ='$(MD5_ASM_OBJ)'                    \
+               RMD160_ASM_OBJ='$(RMD160_ASM_OBJ)'              \
+               WP_ASM_OBJ='$(WP_ASM_OBJ)'                      \
+               PERLASM_SCHEME='$(PERLASM_SCHEME)'              \
                THIS=$${THIS:-$@} MAKEFILE=Makefile MAKEOVERRIDES=
 # MAKEOVERRIDES= effectively "equalizes" GNU-ish and SysV-ish make flavors,
 # which in turn eliminates ambiguities in variable treatment with -e.
@@ -243,127 +223,44 @@ BUILDENV=        PLATFORM='${PLATFORM}' PROCESSOR='${PROCESSOR}' \
 # subdirectories defined in $(DIRS).  It requires that the target
 # is given through the shell variable `target'.
 BUILD_CMD=  if [ -d "$$dir" ]; then \
-           (   [ $$target != all -a -z "$(FIPSCANLIB)" ] && FIPSCANLIB=/dev/null; \
-               cd $$dir && echo "making $$target in $$dir..." && \
+           (   cd $$dir && echo "making $$target in $$dir..." && \
                $(CLEARENV) && $(MAKE) -e $(BUILDENV) TOP=.. DIR=$$dir $$target \
            ) || exit 1; \
            fi
 RECURSIVE_BUILD_CMD=for dir in $(DIRS); do $(BUILD_CMD); done
 BUILD_ONE_CMD=\
-       if echo " $(DIRS) " | grep " $$dir " >/dev/null 2>/dev/null; then \
+       if expr " $(DIRS) " : ".* $$dir " >/dev/null 2>&1; then \
                $(BUILD_CMD); \
        fi
 
 reflect:
        @[ -n "$(THIS)" ] && $(CLEARENV) && $(MAKE) $(THIS) -e $(BUILDENV)
 
-FIPS_EX_OBJ= ../crypto/aes/aes_cfb.o \
-       ../crypto/aes/aes_ecb.o \
-       ../crypto/aes/aes_ofb.o \
-       ../crypto/bn/bn_add.o \
-       ../crypto/bn/bn_blind.o \
-       ../crypto/bn/bn_ctx.o \
-       ../crypto/bn/bn_div.o \
-       ../crypto/bn/bn_exp2.o \
-       ../crypto/bn/bn_exp.o \
-       ../crypto/bn/bn_gcd.o \
-       ../crypto/bn/bn_lib.o \
-       ../crypto/bn/bn_mod.o \
-       ../crypto/bn/bn_mont.o \
-       ../crypto/bn/bn_mul.o \
-       ../crypto/bn/bn_prime.o \
-       ../crypto/bn/bn_rand.o \
-       ../crypto/bn/bn_recp.o \
-       ../crypto/bn/bn_shift.o \
-       ../crypto/bn/bn_sqr.o \
-       ../crypto/bn/bn_word.o \
-       ../crypto/bn/bn_x931p.o \
-       ../crypto/buffer/buf_str.o \
-       ../crypto/cryptlib.o \
-       ../crypto/des/cfb64ede.o \
-       ../crypto/des/cfb64enc.o \
-       ../crypto/des/cfb_enc.o \
-       ../crypto/des/ecb3_enc.o \
-       ../crypto/des/ecb_enc.o \
-       ../crypto/des/ofb64ede.o \
-       ../crypto/des/ofb64enc.o \
-       ../crypto/des/fcrypt.o \
-       ../crypto/des/set_key.o \
-       ../crypto/dsa/dsa_utl.o \
-       ../crypto/dsa/dsa_sign.o \
-       ../crypto/dsa/dsa_vrf.o \
-       ../crypto/err/err.o \
-       ../crypto/evp/digest.o \
-       ../crypto/evp/enc_min.o \
-       ../crypto/evp/e_aes.o \
-       ../crypto/evp/e_des3.o \
-       ../crypto/evp/p_sign.o \
-       ../crypto/evp/p_verify.o \
-       ../crypto/mem_clr.o \
-       ../crypto/mem.o \
-       ../crypto/rand/md_rand.o \
-       ../crypto/rand/rand_egd.o \
-       ../crypto/rand/randfile.o \
-       ../crypto/rand/rand_lib.o \
-       ../crypto/rand/rand_os2.o \
-       ../crypto/rand/rand_unix.o \
-       ../crypto/rand/rand_win.o \
-       ../crypto/rsa/rsa_lib.o \
-       ../crypto/rsa/rsa_none.o \
-       ../crypto/rsa/rsa_oaep.o \
-       ../crypto/rsa/rsa_pk1.o \
-       ../crypto/rsa/rsa_pss.o \
-       ../crypto/rsa/rsa_ssl.o \
-       ../crypto/rsa/rsa_x931.o \
-       ../crypto/sha/sha1dgst.o \
-       ../crypto/sha/sha256.o \
-       ../crypto/sha/sha512.o \
-       ../crypto/uid.o
-
 sub_all: build_all
 build_all: build_libs build_apps build_tests build_tools
 
-build_libs: build_crypto build_fips build_ssl build_shared build_engines
+build_libs: build_crypto build_ssl build_engines
 
 build_crypto:
-       if [ -n "$(FIPSCANLIB)" ]; then \
-               EXCL_OBJ='$(AES_ASM_OBJ) $(BN_ASM) $(DES_ENC) $(CPUID_OBJ) $(SHA1_ASM_OBJ) $(FIPS_EX_OBJ)' ; export EXCL_OBJ ; \
-               ARX='$(PERL) $${TOP}/util/arx.pl $(AR)' ; \
-       else \
-               ARX='${AR}' ; \
-       fi ; export ARX ; \
-               dir=crypto; target=all; $(BUILD_ONE_CMD)
-build_fips:
-       @dir=fips; target=all; [ -z "$(FIPSCANLIB)" ] || $(BUILD_ONE_CMD)
-build_ssl: build_crypto
+       @dir=crypto; target=all; $(BUILD_ONE_CMD)
+build_ssl:
        @dir=ssl; target=all; $(BUILD_ONE_CMD)
-build_engines: build_crypto
+build_engines:
        @dir=engines; target=all; $(BUILD_ONE_CMD)
-build_apps: build_libs
+build_apps:
        @dir=apps; target=all; $(BUILD_ONE_CMD)
-build_tests: build_libs
+build_tests:
        @dir=test; target=all; $(BUILD_ONE_CMD)
-build_tools: build_libs
+build_tools:
        @dir=tools; target=all; $(BUILD_ONE_CMD)
 
 all_testapps: build_libs build_testapps
 build_testapps:
        @dir=crypto; target=testapps; $(BUILD_ONE_CMD)
 
-build_shared:  $(SHARED_LIBS)
-libcrypto$(SHLIB_EXT): libcrypto.a $(SHARED_FIPS)
+libcrypto$(SHLIB_EXT): libcrypto.a
        @if [ "$(SHLIB_TARGET)" != "" ]; then \
-               if [ "$(FIPSCANLIB)" = "libfips" ]; then \
-                       $(ARD) libcrypto.a fipscanister.o ; \
-                       $(MAKE) SHLIBDIRS='crypto' SHLIBDEPS='-lfips' build-shared; \
-                       $(AR) libcrypto.a fips/fipscanister.o ; \
-               else \
-                       if [ "$(FIPSCANLIB)" = "libcrypto" ]; then \
-                               FIPSLD_CC="$(CC)"; CC=fips/fipsld; \
-                               export CC FIPSLD_CC; \
-                       fi; \
-                       $(MAKE) -e SHLIBDIRS='crypto' build-shared; \
-               fi \
+               $(MAKE) SHLIBDIRS=crypto build-shared; \
        else \
                echo "There's no support for shared libraries on this platform" >&2; \
                exit 1; \
@@ -371,32 +268,12 @@ libcrypto$(SHLIB_EXT): libcrypto.a $(SHARED_FIPS)
 
 libssl$(SHLIB_EXT): libcrypto$(SHLIB_EXT) libssl.a
        @if [ "$(SHLIB_TARGET)" != "" ]; then \
-               shlibdeps=-lcrypto; \
-               [ "$(FIPSCANLIB)" = "libfips" ] && shlibdeps="$$shlibdeps -lfips"; \
-               $(MAKE) SHLIBDIRS=ssl SHLIBDEPS="$$shlibdeps" build-shared; \
-       else \
-               echo "There's no support for shared libraries on this platform" >&2 ; \
-               exit 1; \
-       fi
-
-fips/fipscanister.o:   build_fips
-libfips$(SHLIB_EXT):           fips/fipscanister.o
-       @if [ "$(SHLIB_TARGET)" != "" ]; then \
-               FIPSLD_CC="$(CC)"; CC=fips/fipsld; export CC FIPSLD_CC; \
-               $(MAKE) -f Makefile.shared -e $(BUILDENV) \
-                       CC=$${CC} LIBNAME=fips THIS=$@ \
-                       LIBEXTRAS=fips/fipscanister.o \
-                       LIBDEPS="$(EX_LIBS)" \
-                       LIBVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR} \
-                       link_o.$(SHLIB_TARGET) || { rm -f $@; exit 1; } \
+               $(MAKE) SHLIBDIRS=ssl SHLIBDEPS='-lcrypto' build-shared; \
        else \
                echo "There's no support for shared libraries on this platform" >&2; \
                exit 1; \
        fi
 
-libfips.a:
-       dir=fips; target=all; $(BUILD_ONE_CMD)
-
 clean-shared:
        @set -e; for i in $(SHLIBDIRS); do \
                if [ -n "$(SHARED_LIBS_LINK_EXTS)" ]; then \
@@ -412,10 +289,10 @@ clean-shared:
        done
 
 link-shared:
-       @ set -e; for i in ${SHLIBDIRS}; do \
+       @ set -e; for i in $(SHLIBDIRS); do \
                $(MAKE) -f $(HERE)/Makefile.shared -e $(BUILDENV) \
-                       LIBNAME=$$i LIBVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR} \
-                       LIBCOMPATVERSIONS=";${SHLIB_VERSION_HISTORY}" \
+                       LIBNAME=$$i LIBVERSION=$(SHLIB_MAJOR).$(SHLIB_MINOR) \
+                       LIBCOMPATVERSIONS=";$(SHLIB_VERSION_HISTORY)" \
                        symlink.$(SHLIB_TARGET); \
                libs="$$libs -l$$i"; \
        done
@@ -423,13 +300,13 @@ link-shared:
 build-shared: do_$(SHLIB_TARGET) link-shared
 
 do_$(SHLIB_TARGET):
-       @ set -e; libs='-L. ${SHLIBDEPS}'; for i in ${SHLIBDIRS}; do \
-               if [ "${SHLIBDIRS}" = "ssl" -a -n "$(LIBKRB5)" ]; then \
+       @ set -e; libs='-L. $(SHLIBDEPS)'; for i in $(SHLIBDIRS); do \
+               if [ "$$i" = "ssl" -a -n "$(LIBKRB5)" ]; then \
                        libs="$(LIBKRB5) $$libs"; \
                fi; \
                $(CLEARENV) && $(MAKE) -f Makefile.shared -e $(BUILDENV) \
-                       LIBNAME=$$i LIBVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR} \
-                       LIBCOMPATVERSIONS=";${SHLIB_VERSION_HISTORY}" \
+                       LIBNAME=$$i LIBVERSION=$(SHLIB_MAJOR).$(SHLIB_MINOR) \
+                       LIBCOMPATVERSIONS=";$(SHLIB_VERSION_HISTORY)" \
                        LIBDEPS="$$libs $(EX_LIBS)" \
                        link_a.$(SHLIB_TARGET); \
                libs="-l$$i $$libs"; \
@@ -506,34 +383,32 @@ links:
        @$(PERL) $(TOP)/util/mkdir-p.pl include/openssl
        @$(PERL) $(TOP)/util/mklink.pl include/openssl $(EXHEADER)
        @set -e; target=links; $(RECURSIVE_BUILD_CMD)
-       @if [ -z "$(FIPSCANLIB)" ]; then \
-               set -e; target=links; dir=fips ; $(BUILD_CMD) ; \
-       fi
 
 gentests:
        @(cd test && echo "generating dummy tests (if needed)..." && \
-       $(CLEARENV) && $(MAKE) -e $(BUILDENV) TESTS='${TESTS}' OPENSSL_DEBUG_MEMORY=on generate );
+       $(CLEARENV) && $(MAKE) -e $(BUILDENV) TESTS='$(TESTS)' OPENSSL_DEBUG_MEMORY=on generate );
 
 dclean:
-       rm -f *.bak
+       rm -rf *.bak include/openssl certs/.0
        @set -e; target=dclean; $(RECURSIVE_BUILD_CMD)
 
 rehash: rehash.time
 rehash.time: certs apps
        @if [ -z "$(CROSS_COMPILE)" ]; then \
                (OPENSSL="`pwd`/util/opensslwrap.sh"; \
+               [ -x "apps/openssl.exe" ] && OPENSSL="apps/openssl.exe" || :; \
                OPENSSL_DEBUG_MEMORY=on; \
                export OPENSSL OPENSSL_DEBUG_MEMORY; \
                $(PERL) tools/c_rehash certs) && \
                touch rehash.time; \
-       fi
+       else :; fi
 
 test:   tests
 
 tests: rehash
        @(cd test && echo "testing..." && \
-       $(CLEARENV) && $(MAKE) -e $(BUILDENV) TOP=.. TESTS='${TESTS}' OPENSSL_DEBUG_MEMORY=on tests );
-       util/opensslwrap.sh version -a
+       $(CLEARENV) && $(MAKE) -e $(BUILDENV) TOP=.. TESTS='$(TESTS)' OPENSSL_DEBUG_MEMORY=on OPENSSL_CONF=../apps/openssl.cnf tests );
+       OPENSSL_CONF=apps/openssl.cnf util/opensslwrap.sh version -a
 
 report:
        @$(PERL) util/selftest.pl
@@ -566,6 +441,8 @@ crypto/objects/obj_dat.h: crypto/objects/obj_dat.pl crypto/objects/obj_mac.h
        $(PERL) crypto/objects/obj_dat.pl crypto/objects/obj_mac.h crypto/objects/obj_dat.h
 crypto/objects/obj_mac.h: crypto/objects/objects.pl crypto/objects/objects.txt crypto/objects/obj_mac.num
        $(PERL) crypto/objects/objects.pl crypto/objects/objects.txt crypto/objects/obj_mac.num crypto/objects/obj_mac.h
+crypto/objects/obj_xref.h: crypto/objects/objxref.pl crypto/objects/obj_xref.txt crypto/objects/obj_mac.num
+       $(PERL) crypto/objects/objxref.pl crypto/objects/obj_mac.num crypto/objects/obj_xref.txt >crypto/objects/obj_xref.h
 
 apps/openssl-vms.cnf: apps/openssl.cnf
        $(PERL) VMS/VMSify-conf.pl < apps/openssl.cnf > apps/openssl-vms.cnf
@@ -578,7 +455,7 @@ TABLE: Configure
        (echo 'Output of `Configure TABLE'"':"; \
        $(PERL) Configure TABLE) > TABLE
 
-update: errors stacks util/libeay.num util/ssleay.num crypto/objects/obj_dat.h apps/openssl-vms.cnf crypto/bn/bn_prime.h TABLE depend
+update: errors stacks util/libeay.num util/ssleay.num crypto/objects/obj_dat.h crypto/objects/obj_xref.h apps/openssl-vms.cnf crypto/bn/bn_prime.h TABLE depend
 
 # Build distribution tar-file. As the list of files returned by "find" is
 # pretty long, on several platforms a "too many arguments" error or similar
@@ -609,8 +486,8 @@ tar-snap:
 dist:   
        $(PERL) Configure dist
        @$(MAKE) dist_pem_h
-       @$(MAKE) SDIRS='${SDIRS}' clean
-       @$(MAKE) TAR='${TAR}' TARFLAGS='${TARFLAGS}' tar
+       @$(MAKE) SDIRS='$(SDIRS)' clean
+       @$(MAKE) TAR='$(TAR)' TARFLAGS='$(TARFLAGS)' tar
 
 dist_pem_h:
        (cd crypto/pem; $(MAKE) -e $(BUILDENV) pem.h; $(MAKE) clean)
@@ -661,6 +538,16 @@ install_sw:
                                        chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$i.new; \
                                        mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$i.new $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$i; \
                                fi ); \
+                               if expr $(PLATFORM) : 'mingw' > /dev/null; then \
+                               (       case $$i in \
+                                               *crypto*) i=libeay32.dll;; \
+                                               *ssl*)    i=ssleay32.dll;; \
+                                       esac; \
+                                       echo installing $$i; \
+                                       cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new; \
+                                       chmod 755 $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new; \
+                                       mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i ); \
+                               fi; \
                        fi; \
                done; \
                (       here="`pwd`"; \
@@ -680,6 +567,27 @@ install_sw:
        cp openssl.pc $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
        chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc
 
+install_html_docs:
+       here="`pwd`"; \
+       for subdir in apps crypto ssl; do \
+               mkdir -p $(INSTALL_PREFIX)$(HTMLDIR)/$$subdir; \
+               for i in doc/$$subdir/*.pod; do \
+                       fn=`basename $$i .pod`; \
+                       echo "installing html/$$fn.$(HTMLSUFFIX)"; \
+                       cat $$i \
+                       | sed -r 's/L<([^)]*)(\([0-9]\))?\|([^)]*)(\([0-9]\))?>/L<\1|\3>/g' \
+                       | pod2html --podroot=doc --htmlroot=.. --podpath=apps:crypto:ssl \
+                       | sed -r 's/<!DOCTYPE.*//g' \
+                       > $(INSTALL_PREFIX)$(HTMLDIR)/$$subdir/$$fn.$(HTMLSUFFIX); \
+                       $(PERL) util/extract-names.pl < $$i | \
+                               grep -v $$filecase "^$$fn\$$" | \
+                               (cd $(INSTALL_PREFIX)$(HTMLDIR)/$$subdir; \
+                                while read n; do \
+                                       PLATFORM=$(PLATFORM) $$here/util/point.sh $$fn.$(HTMLSUFFIX) "$$n".$(HTMLSUFFIX); \
+                                done); \
+               done; \
+       done
+
 install_docs:
        @$(PERL) $(TOP)/util/mkdir-p.pl \
                $(INSTALL_PREFIX)$(MANDIR)/man1 \
@@ -706,7 +614,7 @@ install_docs:
                        (grep -v "[     ]"; true) | \
                        (cd $(INSTALL_PREFIX)$(MANDIR)/man$$sec/; \
                         while read n; do \
-                               $$here/util/point.sh $$fn.$${sec}$(MANSUFFIX) "$$n".$${sec}$(MANSUFFIX); \
+                               PLATFORM=$(PLATFORM) $$here/util/point.sh $$fn.$${sec}$(MANSUFFIX) "$$n".$${sec}$(MANSUFFIX); \
                         done); \
        done; \
        set -e; for i in doc/crypto/*.pod doc/ssl/*.pod; do \
@@ -723,7 +631,7 @@ install_docs:
                        (grep -v "[     ]"; true) | \
                        (cd $(INSTALL_PREFIX)$(MANDIR)/man$$sec/; \
                         while read n; do \
-                               $$here/util/point.sh $$fn.$${sec}$(MANSUFFIX) "$$n".$${sec}$(MANSUFFIX); \
+                               PLATFORM=$(PLATFORM) $$here/util/point.sh $$fn.$${sec}$(MANSUFFIX) "$$n".$${sec}$(MANSUFFIX); \
                         done); \
        done
 
index 3183436..e753f44 100644 (file)
@@ -14,6 +14,8 @@ CFLAGS=$(CFLAG)
 LDFLAGS=
 SHARED_LDFLAGS=
 
+NM=nm
+
 # LIBNAME contains just the name of the library, without prefix ("lib"
 # on Unix, "cyg" for certain forms under Cygwin...) or suffix (.a, .so,
 # .dll, ...).  This one MUST have a value when using this makefile to
@@ -91,7 +93,7 @@ LINK_APP=     \
   ( $(SET_X);   \
     LIBDEPS="$${LIBDEPS:-$(LIBDEPS)}"; \
     LDCMD="$${LDCMD:-$(CC)}"; LDFLAGS="$${LDFLAGS:-$(CFLAGS)}"; \
-    LIBPATH=`for x in $$LIBDEPS; do if echo $$x | grep '^ *-L' > /dev/null 2>&1; then echo $$x | sed -e 's/^ *-L//'; fi; done | uniq`; \
+    LIBPATH=`for x in $$LIBDEPS; do echo $$x; done | sed -e 's/^ *-L//;t' -e d | uniq`; \
     LIBPATH=`echo $$LIBPATH | sed -e 's/ /:/g'`; \
     LD_LIBRARY_PATH=$$LIBPATH:$$LD_LIBRARY_PATH \
     $${LDCMD} $${LDFLAGS} -o $${APPNAME:=$(APPNAME)} $(OBJECTS) $${LIBDEPS} )
@@ -101,7 +103,7 @@ LINK_SO=    \
     LIBDEPS="$${LIBDEPS:-$(LIBDEPS)}"; \
     SHAREDCMD="$${SHAREDCMD:-$(CC)}"; \
     SHAREDFLAGS="$${SHAREDFLAGS:-$(CFLAGS) $(SHARED_LDFLAGS)}"; \
-    LIBPATH=`for x in $$LIBDEPS; do if echo $$x | grep '^ *-L' > /dev/null 2>&1; then echo $$x | sed -e 's/^ *-L//'; fi; done | uniq`; \
+    LIBPATH=`for x in $$LIBDEPS; do echo $$x; done | sed -e 's/^ *-L//;t' -e d | uniq`; \
     LIBPATH=`echo $$LIBPATH | sed -e 's/ /:/g'`; \
     LD_LIBRARY_PATH=$$LIBPATH:$$LD_LIBRARY_PATH \
     $${SHAREDCMD} $${SHAREDFLAGS} \
@@ -133,7 +135,7 @@ LINK_SO_A_VIA_O=    \
   ALL=$$ALLSYMSFLAGS; ALLSYMSFLAGS=; NOALLSYMSFLAGS=; \
   ( $(SET_X); \
     ld $(LDFLAGS) -r -o lib$(LIBNAME).o $$ALL lib$(LIBNAME).a $(LIBEXTRAS) ); \
-  $(LINK_SO) && rm -f $(LIBNAME).o
+  $(LINK_SO) && rm -f lib$(LIBNAME).o
 
 LINK_SO_A_UNPACKED=    \
   UNPACKDIR=link_tmp.$$$$; rm -rf $$UNPACKDIR; mkdir $$UNPACKDIR; \
@@ -142,7 +144,7 @@ LINK_SO_A_UNPACKED= \
   SHOBJECTS=$$UNPACKDIR/*.o; \
   $(LINK_SO) && rm -rf $$UNPACKDIR
 
-DETECT_GNU_LD=(${CC} -Wl,-V /dev/null 2>&1 | grep '^GNU ld' )>/dev/null
+DETECT_GNU_LD=($(CC) -Wl,-V /dev/null 2>&1 | grep '^GNU ld' )>/dev/null
 
 DO_GNU_SO=$(CALC_VERSIONS); \
        SHLIB=lib$(LIBNAME).so; \
@@ -168,8 +170,19 @@ link_a.gnu:
 link_app.gnu:
        @ $(DO_GNU_APP); $(LINK_APP)
 
+DO_BEOS_SO=    SHLIB=lib$(LIBNAME).so; \
+       SHLIB_SUFFIX=; \
+       ALLSYMSFLAGS='-Wl,--whole-archive'; \
+       NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
+       SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-Bsymbolic -Wl,-soname=$$SHLIB$$SHLIB_SUFFIX"
+
+link_o.beos:
+       @ $(DO_BEOS_SO); $(LINK_SO_O)
+link_a.beos:
+       @ $(DO_BEOS_SO); $(LINK_SO_A)
+
 link_o.bsd:
-       @if ${DETECT_GNU_LD}; then $(DO_GNU_SO); else \
+       @if $(DETECT_GNU_LD); then $(DO_GNU_SO); else \
        $(CALC_VERSIONS); \
        SHLIB=lib$(LIBNAME).so; \
        SHLIB_SUFFIX=; \
@@ -179,7 +192,7 @@ link_o.bsd:
        SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -nostdlib"; \
        fi; $(LINK_SO_O)
 link_a.bsd:
-       @if ${DETECT_GNU_LD}; then $(DO_GNU_SO); else \
+       @if $(DETECT_GNU_LD); then $(DO_GNU_SO); else \
        $(CALC_VERSIONS); \
        SHLIB=lib$(LIBNAME).so; \
        SHLIB_SUFFIX=; \
@@ -189,24 +202,34 @@ link_a.bsd:
        SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -nostdlib"; \
        fi; $(LINK_SO_A)
 link_app.bsd:
-       @if ${DETECT_GNU_LD}; then $(DO_GNU_APP); else \
+       @if $(DETECT_GNU_LD); then $(DO_GNU_APP); else \
        LDFLAGS="$(CFLAGS) -Wl,-rpath,$(LIBPATH)"; \
        fi; $(LINK_APP)
 
 # For Darwin AKA Mac OS/X (dyld)
-# link_o.darwin produces .so, because we let it use dso_dlfcn module,
-# which has .so extension hard-coded. One can argue that one should
-# develop special dso module for MacOS X. At least manual encourages
-# to use native NSModule(3) API and refers to dlfcn as termporary hack.
+# Originally link_o.darwin produced .so, because it was hard-coded
+# in dso_dlfcn module. At later point dso_dlfcn switched to .dylib
+# extension in order to allow for run-time linking with vendor-
+# supplied shared libraries such as libz, so that link_o.darwin had
+# to be harmonized with it. This caused minor controversy, because
+# it was believed that dlopen can't be used to dynamically load
+# .dylib-s, only so called bundle modules (ones linked with -bundle
+# flag). The belief seems to be originating from pre-10.4 release,
+# where dlfcn functionality was emulated by dlcompat add-on. In
+# 10.4 dlopen was rewritten as native part of dyld and is documented
+# to be capable of loading both dynamic libraries and bundles. In
+# order to provide compatibility with pre-10.4 dlopen, modules are
+# linked with -bundle flag, which makes .dylib extension misleading.
+# It works, because dlopen is [and always was] extension-agnostic.
+# Alternative to this heuristic approach is to develop specific
+# MacOS X dso module relying on whichever "native" dyld interface.
 link_o.darwin:
        @ $(CALC_VERSIONS); \
-       SHLIB=`expr "$$THIS" : '.*/\([^/\.]*\)\.'`; \
-       SHLIB=$${SHLIB:-lib$(LIBNAME)}; \
-       SHLIB_SUFFIX=`expr "$$THIS" : '.*\(\.[^\.]*\)$$'`; \
-       SHLIB_SUFFIX=$${SHLIB_SUFFIX:-.so}; \
+       SHLIB=lib$(LIBNAME); \
+       SHLIB_SUFFIX=.dylib; \
        ALLSYMSFLAGS='-all_load'; \
        NOALLSYMSFLAGS=''; \
-       SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS)"; \
+       SHAREDFLAGS="$(CFLAGS) `echo $(SHARED_LDFLAGS) | sed s/dynamiclib/bundle/`"; \
        if [ -n "$(LIBVERSION)" ]; then \
                SHAREDFLAGS="$$SHAREDFLAGS -current_version $(LIBVERSION)"; \
        fi; \
@@ -227,7 +250,7 @@ link_a.darwin:
        if [ -n "$$SHLIB_SOVER_NODOT" ]; then \
                SHAREDFLAGS="$$SHAREDFLAGS -compatibility_version $$SHLIB_SOVER_NODOT"; \
        fi; \
-       SHAREDFLAGS="$$SHAREDFLAGS -install_name ${INSTALLTOP}/lib/$$SHLIB${SHLIB_EXT}"; \
+       SHAREDFLAGS="$$SHAREDFLAGS -install_name $(INSTALLTOP)/$(LIBDIR)/$$SHLIB$(SHLIB_EXT)"; \
        $(LINK_SO_A)
 link_app.darwin:       # is there run-path on darwin?
        $(LINK_APP)
@@ -237,40 +260,59 @@ link_o.cygwin:
        INHIBIT_SYMLINKS=yes; \
        SHLIB=cyg$(LIBNAME); \
        base=-Wl,--enable-auto-image-base; \
+       deffile=; \
        if expr $(PLATFORM) : 'mingw' > /dev/null; then \
                SHLIB=$(LIBNAME)eay32; base=; \
+               if test -f $(LIBNAME)eay32.def; then \
+                       deffile=$(LIBNAME)eay32.def; \
+               fi; \
        fi; \
        SHLIB_SUFFIX=.dll; \
        LIBVERSION="$(LIBVERSION)"; \
        SHLIB_SOVER=${LIBVERSION:+"-$(LIBVERSION)"}; \
        ALLSYMSFLAGS='-Wl,--whole-archive'; \
        NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
-       SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared $$base -Wl,-Bsymbolic -Wl,--out-implib,lib$(LIBNAME).dll.a"; \
+       SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared $$base $$deffile -Wl,-s,-Bsymbolic"; \
        $(LINK_SO_O)
+#for mingw target if def-file is in use dll-name should match library-name
 link_a.cygwin:
        @ $(CALC_VERSIONS); \
        INHIBIT_SYMLINKS=yes; \
-       SHLIB=cyg$(LIBNAME); \
+       SHLIB=cyg$(LIBNAME); SHLIB_SOVER=-$(LIBVERSION); SHLIB_SUFFIX=.dll; \
+       dll_name=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX; extras=; \
        base=-Wl,--enable-auto-image-base; \
        if expr $(PLATFORM) : 'mingw' > /dev/null; then \
-               SHLIB=$(LIBNAME)eay32; \
-               base=;  [ $(LIBNAME) = "crypto" ] && base=-Wl,--image-base,0x63000000; \
+               case $(LIBNAME) in \
+                       crypto) SHLIB=libeay;; \
+                       ssl) SHLIB=ssleay;; \
+               esac; \
+               SHLIB_SOVER=32; \
+               extras="$(LIBNAME).def"; \
+               $(PERL) util/mkdef.pl 32 $$SHLIB > $$extras; \
+               base=; [ $(LIBNAME) = "crypto" ] && base=-Wl,--image-base,0x63000000; \
        fi; \
-       SHLIB_SUFFIX=.dll; \
-       SHLIB_SOVER=-$(LIBVERSION); \
+       dll_name=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX; \
+       $(PERL) util/mkrc.pl $$dll_name | \
+               $(CROSS_COMPILE)windres -o rc.o; \
+       extras="$$extras rc.o"; \
        ALLSYMSFLAGS='-Wl,--whole-archive'; \
        NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
-       SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared $$base -Wl,-Bsymbolic -Wl,--out-implib,lib$(LIBNAME).dll.a"; \
-       [ -f apps/$$SHLIB$$SHLIB_SUFFIX ] && rm apps/$$SHLIB$$SHLIB_SUFFIX; \
-       [ -f test/$$SHLIB$$SHLIB_SUFFIX ] && rm test/$$SHLIB$$SHLIB_SUFFIX; \
+       SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared $$base -Wl,-s,-Bsymbolic -Wl,--out-implib,lib$(LIBNAME).dll.a $$extras"; \
+       [ -f apps/$$dll_name ] && rm apps/$$dll_name; \
+       [ -f test/$$dll_name ] && rm test/$$dll_name; \
        $(LINK_SO_A) || exit 1; \
-       cp -p $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX apps/; \
-       cp -p $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX test/
+       rm $$extras; \
+       cp -p $$dll_name apps/; \
+       cp -p $$dll_name test/
 link_app.cygwin:
+       @if expr "$(CFLAGS)" : '.*OPENSSL_USE_APPLINK' > /dev/null; then \
+               LIBDEPS="$(TOP)/crypto/applink.o $${LIBDEPS:-$(LIBDEPS)}"; \
+               export LIBDEPS; \
+       fi; \
        $(LINK_APP)
 
 link_o.alpha-osf1:
-       @ if ${DETECT_GNU_LD}; then \
+       @ if $(DETECT_GNU_LD); then \
                $(DO_GNU_SO); \
        else \
                SHLIB=lib$(LIBNAME).so; \
@@ -291,7 +333,7 @@ link_o.alpha-osf1:
        fi; \
        $(LINK_SO_O)
 link_a.alpha-osf1:
-       @ if ${DETECT_GNU_LD}; then \
+       @ if $(DETECT_GNU_LD); then \
                $(DO_GNU_SO); \
        else \
                SHLIB=lib$(LIBNAME).so; \
@@ -312,7 +354,7 @@ link_a.alpha-osf1:
        fi; \
        $(LINK_SO_A)
 link_app.alpha-osf1:
-       @if ${DETECT_GNU_LD}; then \
+       @if $(DETECT_GNU_LD); then \
                $(DO_GNU_APP); \
        else \
                LDFLAGS="$(CFLAGS) -rpath $(LIBRPATH)"; \
@@ -320,7 +362,7 @@ link_app.alpha-osf1:
        $(LINK_APP)
 
 link_o.solaris:
-       @ if ${DETECT_GNU_LD}; then \
+       @ if $(DETECT_GNU_LD); then \
                $(DO_GNU_SO); \
        else \
                $(CALC_VERSIONS); \
@@ -334,12 +376,12 @@ link_o.solaris:
        fi; \
        $(LINK_SO_O)
 link_a.solaris:
-       @ if ${DETECT_GNU_LD}; then \
+       @ if $(DETECT_GNU_LD); then \
                $(DO_GNU_SO); \
        else \
                $(CALC_VERSIONS); \
                MINUSZ='-z '; \
-               (${CC} -v 2>&1 | grep gcc) > /dev/null && MINUSZ='-Wl,-z,'; \
+               ($(CC) -v 2>&1 | grep gcc) > /dev/null && MINUSZ='-Wl,-z,'; \
                SHLIB=lib$(LIBNAME).so; \
                SHLIB_SUFFIX=;\
                ALLSYMSFLAGS="$${MINUSZ}allextract"; \
@@ -348,7 +390,7 @@ link_a.solaris:
        fi; \
        $(LINK_SO_A)
 link_app.solaris:
-       @ if ${DETECT_GNU_LD}; then \
+       @ if $(DETECT_GNU_LD); then \
                $(DO_GNU_APP); \
        else \
                LDFLAGS="$(CFLAGS) -R $(LIBRPATH)"; \
@@ -357,7 +399,7 @@ link_app.solaris:
 
 # OpenServer 5 native compilers used
 link_o.svr3:
-       @ if ${DETECT_GNU_LD}; then \
+       @ if $(DETECT_GNU_LD); then \
                $(DO_GNU_SO); \
        else \
                $(CALC_VERSIONS); \
@@ -369,7 +411,7 @@ link_o.svr3:
        fi; \
        $(LINK_SO_O)
 link_a.svr3:
-       @ if ${DETECT_GNU_LD}; then \
+       @ if $(DETECT_GNU_LD); then \
                $(DO_GNU_SO); \
        else \
                $(CALC_VERSIONS); \
@@ -381,12 +423,12 @@ link_a.svr3:
        fi; \
        $(LINK_SO_A_UNPACKED)
 link_app.svr3:
-       @${DETECT_GNU_LD} && $(DO_GNU_APP); \
+       @$(DETECT_GNU_LD) && $(DO_GNU_APP); \
        $(LINK_APP)
 
 # UnixWare 7 and OpenUNIX 8 native compilers used
 link_o.svr5:
-       @ if ${DETECT_GNU_LD}; then \
+       @ if $(DETECT_GNU_LD); then \
                $(DO_GNU_SO); \
        else \
                $(CALC_VERSIONS); \
@@ -400,12 +442,12 @@ link_o.svr5:
        fi; \
        $(LINK_SO_O)
 link_a.svr5:
-       @ if ${DETECT_GNU_LD}; then \
+       @ if $(DETECT_GNU_LD); then \
                $(DO_GNU_SO); \
        else \
                $(CALC_VERSIONS); \
                SHARE_FLAG='-G'; \
-               (${CC} -v 2>&1 | grep gcc) > /dev/null && SHARE_FLAG='-shared'; \
+               ($(CC) -v 2>&1 | grep gcc) > /dev/null && SHARE_FLAG='-shared'; \
                SHLIB=lib$(LIBNAME).so; \
                SHLIB_SUFFIX=; \
                ALLSYMSFLAGS=''; \
@@ -414,11 +456,11 @@ link_a.svr5:
        fi; \
        $(LINK_SO_A_UNPACKED)
 link_app.svr5:
-       @${DETECT_GNU_LD} && $(DO_GNU_APP); \
+       @$(DETECT_GNU_LD) && $(DO_GNU_APP); \
        $(LINK_APP)
 
 link_o.irix:
-       @ if ${DETECT_GNU_LD}; then \
+       @ if $(DETECT_GNU_LD); then \
                $(DO_GNU_SO); \
        else \
                $(CALC_VERSIONS); \
@@ -432,7 +474,7 @@ link_o.irix:
        fi; \
        $(LINK_SO_O)
 link_a.irix:
-       @ if ${DETECT_GNU_LD}; then \
+       @ if $(DETECT_GNU_LD); then \
                $(DO_GNU_SO); \
        else \
                $(CALC_VERSIONS); \
@@ -458,7 +500,7 @@ link_app.irix:
 # ELFs by the way].
 #
 link_o.hpux:
-       @if ${DETECT_GNU_LD}; then $(DO_GNU_SO); else \
+       @if $(DETECT_GNU_LD); then $(DO_GNU_SO); else \
        $(CALC_VERSIONS); \
        SHLIB=lib$(LIBNAME).sl; \
        expr "$(CFLAGS)" : '.*DSO_DLFCN' > /dev/null && SHLIB=lib$(LIBNAME).so; \
@@ -471,7 +513,7 @@ link_o.hpux:
        rm -f $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX || :; \
        $(LINK_SO_O) && chmod a=rx $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX
 link_a.hpux:
-       @if ${DETECT_GNU_LD}; then $(DO_GNU_SO); else \
+       @if $(DETECT_GNU_LD); then $(DO_GNU_SO); else \
        $(CALC_VERSIONS); \
        SHLIB=lib$(LIBNAME).sl; \
        expr $(PLATFORM) : '.*ia64' > /dev/null && SHLIB=lib$(LIBNAME).so; \
@@ -484,7 +526,7 @@ link_a.hpux:
        rm -f $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX || :; \
        $(LINK_SO_A) && chmod a=rx $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX
 link_app.hpux:
-       @if ${DETECT_GNU_LD}; then $(DO_GNU_APP); else \
+       @if $(DETECT_GNU_LD); then $(DO_GNU_APP); else \
        LDFLAGS="$(CFLAGS) -Wl,+s,+cdp,../:,+cdp,./:,+b,$(LIBRPATH)"; \
        fi; \
        $(LINK_APP)
@@ -549,7 +591,7 @@ symlink.hpux:
        expr $(PLATFORM) : '.*ia64' > /dev/null && SHLIB=lib$(LIBNAME).so; \
        $(SYMLINK_SO)
 # The following lines means those specific architectures do no symlinks
-symlink.cygwin symlink.alpha-osf1 symlink.tru64 symlink.tru64-rpath:
+symlink.cygwin symlink.alpha-osf1 symlink.tru64 symlink.tru64-rpath symlink.beos:
 
 # Compatibility targets
 link_o.bsd-gcc-shared link_o.linux-shared link_o.gnu-shared: link_o.gnu
@@ -607,3 +649,7 @@ link_o.reliantunix-shared: link_o.reliantunix
 link_a.reliantunix-shared: link_a.reliantunix
 link_app.reliantunix-shared: link_app.reliantunix
 symlink.reliantunix-shared: symlink.reliantunix
+link_o.beos-shared: link_o.beos
+link_a.beos-shared: link_a.beos
+link_app.beos-shared: link_app.gnu
+symlink.beos-shared: symlink.beos
index 2f9afe8..1fb25c6 100644 (file)
@@ -5,6 +5,68 @@
   This file gives a brief overview of the major changes between each OpenSSL
   release. For more details please read the CHANGES file.
 
+  Major changes between OpenSSL 1.0.0e and OpenSSL 1.0.0f:
+
+      o Fix for DTLS plaintext recovery attack CVE-2011-4108
+      o Clear block padding bytes of SSL 3.0 records CVE-2011-4576
+      o Only allow one SGC handshake restart for SSL/TLS CVE-2011-4619
+      o Check parameters are not NULL in GOST ENGINE CVE-2012-0027
+      o Check for malformed RFC3779 data CVE-2011-4577
+
+  Major changes between OpenSSL 1.0.0d and OpenSSL 1.0.0e:
+
+      o Fix for CRL vulnerability issue CVE-2011-3207
+      o Fix for ECDH crashes CVE-2011-3210
+      o Protection against EC timing attacks.
+      o Support ECDH ciphersuites for certificates using SHA2 algorithms.
+      o Various DTLS fixes.
+
+  Major changes between OpenSSL 1.0.0c and OpenSSL 1.0.0d:
+
+      o Fix for security issue CVE-2011-0014
+
+  Major changes between OpenSSL 1.0.0b and OpenSSL 1.0.0c:
+
+      o Fix for security issue CVE-2010-4180
+      o Fix for CVE-2010-4252
+      o Fix mishandling of absent EC point format extension.
+      o Fix various platform compilation issues.
+      o Corrected fix for security issue CVE-2010-3864.
+
+  Major changes between OpenSSL 1.0.0a and OpenSSL 1.0.0b:
+
+      o Fix for security issue CVE-2010-3864.
+      o Fix for CVE-2010-2939
+      o Fix WIN32 build system for GOST ENGINE.
+
+  Major changes between OpenSSL 1.0.0 and OpenSSL 1.0.0a:
+
+      o Fix for security issue CVE-2010-1633.
+      o GOST MAC and CFB fixes.
+
+  Major changes between OpenSSL 0.9.8n and OpenSSL 1.0.0:
+
+      o RFC3280 path validation: sufficient to process PKITS tests.
+      o Integrated support for PVK files and keyblobs.
+      o Change default private key format to PKCS#8.
+      o CMS support: able to process all examples in RFC4134
+      o Streaming ASN1 encode support for PKCS#7 and CMS.
+      o Multiple signer and signer add support for PKCS#7 and CMS.
+      o ASN1 printing support.
+      o Whirlpool hash algorithm added.
+      o RFC3161 time stamp support.
+      o New generalised public key API supporting ENGINE based algorithms.
+      o New generalised public key API utilities.
+      o New ENGINE supporting GOST algorithms.
+      o SSL/TLS GOST ciphersuite support.
+      o PKCS#7 and CMS GOST support.
+      o RFC4279 PSK ciphersuite support.
+      o Supported points format extension for ECC ciphersuites.
+      o ecdsa-with-SHA224/256/384/512 signature types.
+      o dsa-with-SHA224 and dsa-with-SHA256 signature types.
+      o Opaque PRF Input TLS extension support.
+      o Updated time routines to avoid OS limitations.
+
   Major changes between OpenSSL 0.9.8q and OpenSSL 0.9.8r:
 
       o Fix for security issue CVE-2011-0014
index 823134b..3125c2a 100644 (file)
@@ -159,6 +159,8 @@ cd ..\..\..
 echo SHA1
 cd crypto\sha\asm
 perl sha1-586.pl %ASM_MODE% > s1-nw.asm
+perl sha256-586.pl %ASM_MODE% > sha256-nw.asm
+perl sha512-586.pl %ASM_MODE% > sha512-nw.asm
 cd ..\..\..
 
 echo RIPEMD160
@@ -171,6 +173,11 @@ cd crypto\rc5\asm
 perl rc5-586.pl %ASM_MODE% > r5-nw.asm
 cd ..\..\..
 
+echo WHIRLPOOL
+cd crypto\whrlpool\asm
+perl wp-mmx.pl %ASM_MODE% > wp-nw.asm
+cd ..\..\..
+
 echo CPUID
 cd crypto
 perl x86cpuid.pl %ASM_MODE% > x86cpuid-nw.asm
index 3438b40..50d54d5 100644 (file)
@@ -1,5 +1,5 @@
 
- OpenSSL 0.9.8r
+ OpenSSL 1.0.0f 4 Jan 2012
 
  Copyright (c) 1998-2011 The OpenSSL Project
  Copyright (c) 1995-1998 Eric A. Young, Tim J. Hudson
diff --git a/deps/openssl/openssl/VMS/install-vms.com b/deps/openssl/openssl/VMS/install-vms.com
new file mode 100644 (file)
index 0000000..7da8b21
--- /dev/null
@@ -0,0 +1,67 @@
+$! install-vms.com -- Installs the files in a given directory tree
+$!
+$! Author: Richard Levitte <richard@levitte.org>
+$! Time of creation: 23-MAY-1998 19:22
+$!
+$! P1  root of the directory tree
+$!
+$!
+$! Announce/identify.
+$!
+$ proc = f$environment( "procedure")
+$ write sys$output "@@@ "+ -
+   f$parse( proc, , , "name")+ f$parse( proc, , , "type")
+$!
+$ on error then goto tidy
+$ on control_c then goto tidy
+$!
+$ if p1 .eqs. ""
+$ then
+$   write sys$output "First argument missing."
+$   write sys$output -
+     "Should be the directory where you want things installed."
+$   exit
+$ endif
+$
+$ if (f$getsyi( "cpu") .lt. 128)
+$ then
+$   arch = "VAX"
+$ else
+$   arch = f$edit( f$getsyi( "arch_name"), "upcase")
+$   if (arch .eqs. "") then arch = "UNK"
+$ endif
+$
+$ root = f$parse( P1, "[]A.;0", , , "SYNTAX_ONLY, NO_CONCEAL")- "A.;0"
+$ root_dev = f$parse( root, , , "device", "syntax_only")
+$ root_dir = f$parse( root, , , "directory", "syntax_only") - -
+   "[000000." - "][" - "[" - "]"
+$ root = root_dev + "[" + root_dir
+$
+$ define /nolog wrk_sslroot 'root'.] /translation_attributes = concealed
+$ define /nolog wrk_sslinclude wrk_sslroot:[include]
+$
+$ if f$parse( "wrk_sslroot:[000000]") .eqs. "" then -
+   create /directory /log wrk_sslroot:[000000]
+$ if f$parse( "wrk_sslinclude:") .eqs. "" then -
+   create /directory /log wrk_sslinclude:
+$ if f$parse( "wrk_sslroot:[vms]") .eqs. "" then -
+   create /directory /log wrk_sslroot:[vms]
+$!
+$ copy /log /protection = world:re openssl_startup.com wrk_sslroot:[vms]
+$ copy /log /protection = world:re openssl_undo.com wrk_sslroot:[vms]
+$ copy /log /protection = world:re openssl_utils.com wrk_sslroot:[vms]
+$!
+$ tidy:
+$!
+$ call deass wrk_sslroot
+$ call deass wrk_sslinclude
+$!
+$ exit
+$!
+$ deass: subroutine
+$ if (f$trnlnm( p1, "LNM$PROCESS") .nes. "")
+$ then
+$   deassign /process 'p1'
+$ endif
+$ endsubroutine
+$!
diff --git a/deps/openssl/openssl/VMS/install.com b/deps/openssl/openssl/VMS/install.com
deleted file mode 100644 (file)
index 9c9c0e1..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-$! INSTALL.COM -- Installs the files in a given directory tree
-$!
-$! Author: Richard Levitte <richard@levitte.org>
-$! Time of creation: 23-MAY-1998 19:22
-$!
-$! P1  root of the directory tree
-$!
-$      IF P1 .EQS. ""
-$      THEN
-$          WRITE SYS$OUTPUT "First argument missing."
-$          WRITE SYS$OUTPUT "Should be the directory where you want things installed."
-$          EXIT
-$      ENDIF
-$
-$      IF (F$GETSYI("CPU").LT.128)
-$      THEN
-$          ARCH := VAX
-$      ELSE
-$          ARCH = F$EDIT( F$GETSYI( "ARCH_NAME"), "UPCASE")
-$          IF (ARCH .EQS. "") THEN ARCH = "UNK"
-$      ENDIF
-$
-$      ROOT = F$PARSE(P1,"[]A.;0",,,"SYNTAX_ONLY,NO_CONCEAL") - "A.;0"
-$      ROOT_DEV = F$PARSE(ROOT,,,"DEVICE","SYNTAX_ONLY")
-$      ROOT_DIR = F$PARSE(ROOT,,,"DIRECTORY","SYNTAX_ONLY") -
-                  - "[000000." - "][" - "[" - "]"
-$      ROOT = ROOT_DEV + "[" + ROOT_DIR
-$
-$      DEFINE/NOLOG WRK_SSLROOT 'ROOT'.] /TRANS=CONC
-$      DEFINE/NOLOG WRK_SSLINCLUDE WRK_SSLROOT:[INCLUDE]
-$
-$      IF F$PARSE("WRK_SSLROOT:[000000]") .EQS. "" THEN -
-          CREATE/DIR/LOG WRK_SSLROOT:[000000]
-$      IF F$PARSE("WRK_SSLINCLUDE:") .EQS. "" THEN -
-          CREATE/DIR/LOG WRK_SSLINCLUDE:
-$      IF F$PARSE("WRK_SSLROOT:[VMS]") .EQS. "" THEN -
-          CREATE/DIR/LOG WRK_SSLROOT:[VMS]
-$
-$      IF F$SEARCH("WRK_SSLINCLUDE:vms_idhacks.h") .NES. "" THEN -
-          DELETE WRK_SSLINCLUDE:vms_idhacks.h;*
-$
-$      OPEN/WRITE SF WRK_SSLROOT:[VMS]OPENSSL_STARTUP.COM
-$      WRITE SYS$OUTPUT "%OPEN-I-CREATED,  ",F$SEARCH("WRK_SSLROOT:[VMS]OPENSSL_STARTUP.COM")," created."
-$      WRITE SF "$! Startup file for Openssl"
-$      WRITE SF "$!"
-$      WRITE SF "$! Do not edit this file, as it will be regenerated during next installation."
-$      WRITE SF "$! Instead, add or change SSLROOT:[VMS]OPENSSL_SYSTARTUP.COM"
-$      WRITE SF "$!"
-$      WRITE SF "$! P1 a qualifier to DEFINE.  For example ""/SYSTEM"" to get the logical names"
-$      WRITE SF "$!    defined in the system logical name table."
-$      WRITE SF "$!"
-$      WRITE SF "$     IF (F$GETSYI(""CPU"").LT.128)"
-$      WRITE SF "$     THEN"
-$      WRITE SF "$         ARCH := VAX"
-$      WRITE SF "$     ELSE"
-$      WRITE SF "$         ARCH = F$EDIT( F$GETSYI( ""ARCH_NAME""), ""UPCASE"")"
-$      WRITE SF "$         IF (ARCH .EQS. """") THEN ARCH = ""UNK"""
-$      WRITE SF "$     ENDIF"
-$      WRITE SF "$     DEFINE/NOLOG'P1 SSLROOT         ",ROOT,".] /TRANS=CONC"
-$      WRITE SF "$     DEFINE/NOLOG'P1 SSLLIB          SSLROOT:['ARCH'_LIB]"
-$      WRITE SF "$     DEFINE/NOLOG'P1 SSLINCLUDE      SSLROOT:[INCLUDE]"
-$      WRITE SF "$     DEFINE/NOLOG'P1 SSLEXE          SSLROOT:['ARCH'_EXE]"
-$      WRITE SF "$     DEFINE/NOLOG'P1 SSLCERTS        SSLROOT:[CERTS]"
-$      WRITE SF "$     DEFINE/NOLOG'P1 SSLPRIVATE      SSLROOT:[PRIVATE]"
-$      WRITE SF "$"
-$      WRITE SF "$!    This is program can include <openssl/{foo}.h>"
-$      WRITE SF "$     DEFINE/NOLOG'P1 OPENSSL         SSLINCLUDE:"
-$      WRITE SF "$"
-$      WRITE SF "$     IF F$SEARCH(""SSLROOT:[VMS]OPENSSL_SYSTARTUP.COM"") .NES."""" THEN -"
-$      WRITE SF "         @SSLROOT:[VMS]OPENSSL_SYSTARTUP.COM"
-$      WRITE SF "$"
-$      WRITE SF "$     EXIT"
-$      CLOSE SF
-$      SET FILE/PROT=WORLD:RE WRK_SSLROOT:[VMS]OPENSSL_STARTUP.COM
-$
-$      COPY OPENSSL_UTILS.COM WRK_SSLROOT:[VMS]/LOG
-$      SET FILE/PROT=WORLD:RE WRK_SSLROOT:[VMS]OPENSSL_UTILS.COM
-$
-$      EXIT
index c8acd2a..b0d1fda 100644 (file)
-$! MKSHARED.COM -- script to created shareable images on VMS
+$! MKSHARED.COM -- Create shareable images.
 $!
-$! No command line parameters.  This should be run at the start of the source
-$! tree (the same directory where one finds INSTALL.VMS).
+$! P1: "64" for 64-bit pointers.
 $!
-$! Input:      [.UTIL]LIBEAY.NUM,[.xxx.EXE.CRYPTO]LIBCRYPTO.OLB
-$!             [.UTIL]SSLEAY.NUM,[.xxx.EXE.SSL]LIBSSL.OLB
-$! Output:     [.xxx.EXE.CRYPTO]LIBCRYPTO.OPT,.MAP,.EXE
-$!             [.xxx.EXE.SSL]LIBSSL.OPT,.MAP,.EXE
+$! P2: Zlib object library path (optional).
+$!
+$! Input:      [.UTIL]LIBEAY.NUM,[.xxx.EXE.CRYPTO]SSL_LIBCRYPTO[32].OLB
+$!             [.UTIL]SSLEAY.NUM,[.xxx.EXE.SSL]SSL_LIBSSL[32].OLB
+$!             [.CRYPTO.xxx]OPENSSLCONF.H
+$! Output:     [.xxx.EXE.CRYPTO]SSL_LIBCRYPTO_SHR[32].OPT,.MAP,.EXE
+$!             [.xxx.EXE.SSL]SSL_LIBSSL_SRH[32].OPT,.MAP,.EXE
 $!
 $! So far, tests have only been made on VMS for Alpha.  VAX will come in time.
 $! ===========================================================================
-$
+$!
+$! Announce/identify.
+$!
+$ proc = f$environment( "procedure")
+$ write sys$output "@@@ "+ -
+   f$parse( proc, , , "name")+ f$parse( proc, , , "type")
+$!
+$! Save the original default device:[directory].
+$!
+$ def_orig = f$environment( "default")
+$ on error then goto tidy
+$ on control_c then goto tidy
+$!
+$! SET DEFAULT to the main kit directory.
+$!
+$ proc = f$environment("procedure")
+$ proc = f$parse( "A.;", proc)- "A.;"
+$ set default 'proc'
+$ set default [-]
+$!
 $! ----- Prepare info for processing: version number and file info
 $ gosub read_version_info
 $ if libver .eqs. ""
 $ then
 $   write sys$error "ERROR: Couldn't find any library version info..."
-$   exit
+$   go to tidy:
 $ endif
 $
-$ if (f$getsyi("cpu").lt.128)
+$ if (f$getsyi("cpu") .lt. 128)
 $ then
-$     arch := VAX
+$   arch_vax = 1
+$   arch = "VAX"
 $ else
-$     arch = f$edit( f$getsyi( "ARCH_NAME"), "UPCASE")
-$     if (arch .eqs. "") then arch = "UNK"
+$   arch_vax = 0
+$   arch = f$edit( f$getsyi( "ARCH_NAME"), "UPCASE")
+$   if (arch .eqs. "") then arch = "UNK"
 $ endif
-$
-$ if arch .nes. "VAX"
+$!
+$ archd = arch
+$ lib32 = "32"
+$ shr = "SHR32"
+$!
+$ if (p1 .nes. "")
 $ then
-$   arch_vax = 0
+$   if (p1 .eqs. "64")
+$   then
+$     archd = arch+ "_64"
+$     lib32 = ""
+$     shr = "SHR"
+$   else
+$     if (p1 .nes. "32")
+$     then
+$       write sys$output "Second argument invalid."
+$       write sys$output "It should be "32", "64", or nothing."
+$       exit
+$     endif
+$   endif
+$ endif
+$!
+$! ----- Prepare info for processing: disabled algorithms info
+$ gosub read_disabled_algorithms_info
+$!
+$ ZLIB = p2
+$ zlib_lib = ""
+$ if (ZLIB .nes. "")
+$ then
+$   file2 = f$parse( ZLIB, "libz.olb", , , "syntax_only")
+$   if (f$search( file2) .eqs. "")
+$   then
+$     write sys$output ""
+$     write sys$output "The Option ", ZLIB, " Is Invalid."
+$     write sys$output "    Can't find library: ''file2'"
+$     write sys$output ""
+$     goto tidy
+$   endif
+$   zlib_lib = ", ''file2' /library"
+$ endif
+$!
+$ if (arch_vax)
+$ then
+$   libtit = "CRYPTO_TRANSFER_VECTOR"
 $   libid  = "Crypto"
 $   libnum = "[.UTIL]LIBEAY.NUM"
-$   libdir = "[.''ARCH'.EXE.CRYPTO]"
-$   libolb = "''libdir'LIBCRYPTO.OLB"
-$   libopt = "''libdir'LIBCRYPTO.OPT"
-$   libmap = "''libdir'LIBCRYPTO.MAP"
-$   libgoal= "''libdir'LIBCRYPTO.EXE"
+$   libdir = "[.''ARCHD'.EXE.CRYPTO]"
+$   libmar = "''libdir'SSL_LIBCRYPTO_''shr'.MAR"
+$   libolb = "''libdir'SSL_LIBCRYPTO''lib32'.OLB"
+$   libopt = "''libdir'SSL_LIBCRYPTO_''shr'.OPT"
+$   libobj = "''libdir'SSL_LIBCRYPTO_''shr'.OBJ"
+$   libmap = "''libdir'SSL_LIBCRYPTO_''shr'.MAP"
+$   libgoal= "''libdir'SSL_LIBCRYPTO_''shr'.EXE"
 $   libref = ""
-$   gosub create_nonvax_shr
+$   libvec = "LIBCRYPTO"
+$   if f$search( libolb) .nes. "" then gosub create_vax_shr
+$   libtit = "SSL_TRANSFER_VECTOR"
 $   libid  = "SSL"
 $   libnum = "[.UTIL]SSLEAY.NUM"
-$   libdir = "[.''ARCH'.EXE.SSL]"
-$   libolb = "''libdir'LIBSSL.OLB"
-$   libopt = "''libdir'LIBSSL.OPT"
-$   libmap = "''libdir'LIBSSL.MAP"
-$   libgoal= "''libdir'LIBSSL.EXE"
-$   libref = "[.''ARCH'.EXE.CRYPTO]LIBCRYPTO.EXE"
-$   gosub create_nonvax_shr
+$   libdir = "[.''ARCHD'.EXE.SSL]"
+$   libmar = "''libdir'SSL_LIBSSL_''shr'.MAR"
+$   libolb = "''libdir'SSL_LIBSSL''lib32'.OLB"
+$   libopt = "''libdir'SSL_LIBSSL_''shr'.OPT"
+$   libobj = "''libdir'SSL_LIBSSL_''shr'.OBJ"
+$   libmap = "''libdir'SSL_LIBSSL_''shr'.MAP"
+$   libgoal= "''libdir'SSL_LIBSSL_''shr'.EXE"
+$   libref = "[.''ARCHD'.EXE.CRYPTO]SSL_LIBCRYPTO_''shr'.EXE"
+$   libvec = "LIBSSL"
+$   if f$search( libolb) .nes. "" then gosub create_vax_shr
 $ else
-$   arch_vax = 1
-$   libtit = "CRYPTO_TRANSFER_VECTOR"
 $   libid  = "Crypto"
 $   libnum = "[.UTIL]LIBEAY.NUM"
-$   libdir = "[.''ARCH'.EXE.CRYPTO]"
-$   libmar = "''libdir'LIBCRYPTO.MAR"
-$   libolb = "''libdir'LIBCRYPTO.OLB"
-$   libopt = "''libdir'LIBCRYPTO.OPT"
-$   libobj = "''libdir'LIBCRYPTO.OBJ"
-$   libmap = "''libdir'LIBCRYPTO.MAP"
-$   libgoal= "''libdir'LIBCRYPTO.EXE"
+$   libdir = "[.''ARCHD'.EXE.CRYPTO]"
+$   libolb = "''libdir'SSL_LIBCRYPTO''lib32'.OLB"
+$   libopt = "''libdir'SSL_LIBCRYPTO_''shr'.OPT"
+$   libmap = "''libdir'SSL_LIBCRYPTO_''shr'.MAP"
+$   libgoal= "''libdir'SSL_LIBCRYPTO_''shr'.EXE"
 $   libref = ""
-$   libvec = "LIBCRYPTO"
-$   gosub create_vax_shr
-$   libtit = "SSL_TRANSFER_VECTOR"
+$   if f$search( libolb) .nes. "" then gosub create_nonvax_shr
 $   libid  = "SSL"
 $   libnum = "[.UTIL]SSLEAY.NUM"
-$   libdir = "[.''ARCH'.EXE.SSL]"
-$   libmar = "''libdir'LIBSSL.MAR"
-$   libolb = "''libdir'LIBSSL.OLB"
-$   libopt = "''libdir'LIBSSL.OPT"
-$   libobj = "''libdir'LIBSSL.OBJ"
-$   libmap = "''libdir'LIBSSL.MAP"
-$   libgoal= "''libdir'LIBSSL.EXE"
-$   libref = "[.''ARCH'.EXE.CRYPTO]LIBCRYPTO.EXE"
-$   libvec = "LIBSSL"
-$   gosub create_vax_shr
+$   libdir = "[.''ARCHD'.EXE.SSL]"
+$   libolb = "''libdir'SSL_LIBSSL''lib32'.OLB"
+$   libopt = "''libdir'SSL_LIBSSL_''shr'.OPT"
+$   libmap = "''libdir'SSL_LIBSSL_''shr'.MAP"
+$   libgoal= "''libdir'SSL_LIBSSL_''shr'.EXE"
+$   libref = "[.''ARCHD'.EXE.CRYPTO]SSL_LIBCRYPTO_''shr'.EXE"
+$   if f$search( libolb) .nes. "" then gosub create_nonvax_shr
 $ endif
+$!
+$ tidy:
+$!
+$! Close any open files.
+$!
+$ if (f$trnlnm( "libnum", "LNM$PROCESS", 0, "SUPERVISOR") .nes. "") then -
+   close libnum
+$!
+$ if (f$trnlnm( "mar", "LNM$PROCESS", 0, "SUPERVISOR") .nes. "") then -
+   close mar
+$!
+$ if (f$trnlnm( "opt", "LNM$PROCESS", 0, "SUPERVISOR") .nes. "") then -
+   close opt
+$!
+$ if (f$trnlnm( "vf", "LNM$PROCESS", 0, "SUPERVISOR") .nes. "") then -
+   close vf
+$!
+$! Restore the original default device:[directory].
+$!
+$ set default 'def_orig'
 $ exit
 $
-$! ----- Soubroutines to build the shareable libraries
+$! ----- Subroutines to build the shareable libraries
 $! For each supported architecture, there's a main shareable library
 $! creator, which is called from the main code above.
 $! The creator will define a number of variables to tell the next levels of
@@ -111,9 +192,9 @@ $! ----- Subroutines for non-VAX
 $! -----
 $! The creator routine
 $ create_nonvax_shr:
-$   open/write opt 'libopt'
+$   open /write opt 'libopt'
 $   write opt "identification=""",libid," ",libverstr,""""
-$   write opt libolb,"/lib"
+$   write opt libolb, " /library"
 $   if libref .nes. "" then write opt libref,"/SHARE"
 $   write opt "SYMBOL_VECTOR=(-"
 $   libfirstentry := true
@@ -124,7 +205,8 @@ $   gosub read_func_num
 $   write opt ")"
 $   write opt "GSMATCH=",libvmatch,",",libver
 $   close opt
-$   link/map='libmap'/full/share='libgoal' 'libopt'/option
+$   link /map = 'libmap' /full /share = 'libgoal' 'libopt' /options -
+     'zlib_lib'
 $   return
 $
 $! The record writer routine
@@ -158,7 +240,7 @@ $! ----- Subroutines for VAX
 $! -----
 $! The creator routine
 $ create_vax_shr:
-$   open/write mar 'libmar'
+$   open /write mar 'libmar'
 $   type sys$input:/out=mar:
 ;
 ; Transfer vector for VAX shareable image
@@ -193,10 +275,10 @@ $!   libwriter := write_vax_vtransfer_entry
 $!   gosub read_func_num
 $   write mar "        .END"
 $   close mar
-$   open/write opt 'libopt'
+$   open /write opt 'libopt'
 $   write opt "identification=""",libid," ",libverstr,""""
 $   write opt libobj
-$   write opt libolb,"/lib"
+$   write opt libolb, " /library"
 $   if libref .nes. "" then write opt libref,"/SHARE"
 $   type sys$input:/out=opt:
 !
@@ -215,7 +297,8 @@ $   libwriter := write_vax_psect_attr
 $   gosub read_func_num
 $   close opt
 $   macro/obj='libobj' 'libmar'
-$   link/map='libmap'/full/share='libgoal' 'libopt'/option
+$   link /map = 'libmap' /full /share = 'libgoal' 'libopt' /options -
+     'zlib_lib'
 $   return
 $
 $! The record writer routine for VAX functions
@@ -237,9 +320,9 @@ $   return
 $
 $! ----- Common subroutines
 $! -----
-$! The .num file reader.  This one has great responsability.
+$! The .num file reader.  This one has great responsibility.
 $ read_func_num:
-$   open libnum 'libnum'
+$   open /read libnum 'libnum'
 $   goto read_nums
 $
 $ read_nums:
@@ -247,27 +330,30 @@ $   libentrynum=0
 $   liblastentry:=false
 $   entrycount=0
 $   loop:
-$     read/end=loop_end/err=loop_end libnum line
-$     entrynum=f$int(f$element(1," ",f$edit(line,"COMPRESS,TRIM")))
-$     entryinfo=f$element(2," ",f$edit(line,"COMPRESS,TRIM"))
-$     curentry=f$element(0," ",f$edit(line,"COMPRESS,TRIM"))
-$     info_exist=f$element(0,":",entryinfo)
-$     info_platforms=","+f$element(1,":",entryinfo)+","
-$     info_kind=f$element(2,":",entryinfo)
-$     info_algorithms=","+f$element(3,":",entryinfo)+","
+$     read /end=loop_end /err=loop_end libnum line
+$     lin = f$edit( line, "COMPRESS,TRIM")
+$!    Skip a "#" comment line.
+$     if (f$extract( 0, 1, lin) .eqs. "#") then goto loop
+$     entrynum = f$int(f$element( 1, " ", lin))
+$     entryinfo = f$element( 2, " ", lin)
+$     curentry = f$element( 0, " ", lin)
+$     info_exist = f$element( 0, ":", entryinfo)
+$     info_platforms = ","+ f$element(1, ":", entryinfo)+ ","
+$     info_kind = f$element( 2, ":", entryinfo)
+$     info_algorithms = ","+ f$element( 3, ":", entryinfo)+ ","
 $     if info_exist .eqs. "NOEXIST" then goto loop
 $     truesum = 0
 $     falsesum = 0
 $     negatives = 1
 $     plat_i = 0
 $     loop1:
-$       plat_entry = f$element(plat_i,",",info_platforms)
+$       plat_entry = f$element( plat_i, ",", info_platforms)
 $       plat_i = plat_i + 1
 $       if plat_entry .eqs. "" then goto loop1
 $       if plat_entry .nes. ","
 $       then
 $         if f$extract(0,1,plat_entry) .nes. "!" then negatives = 0
-$         if f$getsyi("CPU") .lt. 128
+$         if (arch_vax)
 $         then
 $           if plat_entry .eqs. "EXPORT_VAR_AS_FUNCTION" then -
 $             truesum = truesum + 1
@@ -276,6 +362,7 @@ $             falsesum = falsesum + 1
 $         endif
 $!
 $         if ((plat_entry .eqs. "VMS") .or. -
+            ((plat_entry .eqs. "ZLIB") .and. (ZLIB .nes. "")) .or. -
             (arch_vax .and. (plat_entry .eqs. "VMSVAX"))) then -
             truesum = truesum + 1
 $!
@@ -301,8 +388,7 @@ $   alg_i = alg_i + 1
 $       if alg_entry .eqs. "" then goto loop2
 $       if alg_entry .nes. ","
 $       then
-$         if alg_entry .eqs. "KRB5" then goto loop ! Special for now
-$        if alg_entry .eqs. "STATIC_ENGINE" then goto loop ! Special for now
+$        if disabled_algorithms - ("," + alg_entry + ",") .nes disabled_algorithms then goto loop
 $         if f$trnlnm("OPENSSL_NO_"+alg_entry) .nes. "" then goto loop
 $        goto loop2
 $       endif
@@ -345,7 +431,7 @@ $
 $! The version number reader
 $ read_version_info:
 $   libver = ""
-$   open/read vf [.CRYPTO]OPENSSLV.H
+$   open /read vf [.CRYPTO]OPENSSLV.H
 $   loop_rvi:
 $     read/err=endloop_rvi/end=endloop_rvi vf rvi_line
 $     if rvi_line - "SHLIB_VERSION_NUMBER """ .eqs. rvi_line then -
@@ -369,3 +455,22 @@ $     endif
 $   endloop_rvi:
 $   close vf
 $   return
+$
+$! The disabled algorithms reader
+$ read_disabled_algorithms_info:
+$   disabled_algorithms = ","
+$   open /read cf [.CRYPTO.'ARCH']OPENSSLCONF.H
+$   loop_rci:
+$     read/err=endloop_rci/end=endloop_rci cf rci_line
+$     rci_line = f$edit(rci_line,"TRIM,COMPRESS")
+$     rci_ei = 0
+$     if f$extract(0,9,rci_line) .eqs. "# define " then rci_ei = 2
+$     if f$extract(0,8,rci_line) .eqs. "#define " then rci_ei = 1
+$     if rci_ei .eq. 0 then goto loop_rci
+$     rci_e = f$element(rci_ei," ",rci_line)
+$     if f$extract(0,11,rci_e) .nes. "OPENSSL_NO_" then goto loop_rci
+$     disabled_algorithms = disabled_algorithms + f$extract(11,999,rci_e) + ","
+$     goto loop_rci
+$   endloop_rci:
+$   close cf
+$   return
diff --git a/deps/openssl/openssl/VMS/openssl_startup.com b/deps/openssl/openssl/VMS/openssl_startup.com
new file mode 100644 (file)
index 0000000..04bbbde
--- /dev/null
@@ -0,0 +1,108 @@
+$!
+$! Startup file for OpenSSL 1.x.
+$!
+$! 2011-03-05 SMS.
+$!
+$! This procedure must reside in the OpenSSL installation directory.
+$! It will fail if it is copied to a different location.
+$!
+$! P1  qualifier(s) for DEFINE.  For example, "/SYSTEM" to get the
+$!     logical names defined in the system logical name table.
+$!
+$! P2  "64", to use executables which were built with 64-bit pointers.
+$!
+$! Good (default) and bad status values.
+$!
+$ status =    %x00010001 ! RMS$_NORMAL, normal successful completion.
+$ rms_e_fnf = %x00018292 ! RMS$_FNF, file not found.
+$!
+$! Prepare for problems.
+$!
+$ orig_dev_dir = f$environment( "DEFAULT")
+$ on control_y then goto clean_up
+$ on error then goto clean_up
+$!
+$! Determine hardware architecture.
+$!
+$ if (f$getsyi( "cpu") .lt. 128)
+$ then
+$   arch_name = "VAX"
+$ else
+$   arch_name = f$edit( f$getsyi( "arch_name"), "upcase")
+$   if (arch_name .eqs. "") then arch_name = "UNK"
+$ endif
+$!
+$ if (p2 .eqs. "64")
+$ then
+$   arch_name_exe = arch_name+ "_64"
+$ else
+$   arch_name_exe = arch_name
+$ endif
+$!
+$! Derive the OpenSSL installation device:[directory] from the location
+$! of this command procedure.
+$!
+$ proc = f$environment( "procedure")
+$ proc_dev_dir = f$parse( "A.;", proc, , , "no_conceal") - "A.;"
+$ proc_dev = f$parse( proc_dev_dir, , , "device", "syntax_only")
+$ proc_dir = f$parse( proc_dev_dir, , , "directory", "syntax_only") - -
+   ".][000000"- "[000000."- "]["- "["- "]"
+$ proc_dev_dir = proc_dev+ "["+ proc_dir+ "]"
+$ set default 'proc_dev_dir'
+$ set default [-]
+$ ossl_dev_dir = f$environment( "default")
+$!
+$! Check existence of expected directories (to see if this procedure has
+$! been moved away from its proper place).
+$!
+$ if ((f$search( "certs.dir;1") .eqs. "") .or. -
+   (f$search( "include.dir;1") .eqs. "") .or. -
+   (f$search( "private.dir;1") .eqs. "") .or. -
+   (f$search( "vms.dir;1") .eqs. ""))
+$ then
+$    write sys$output -
+      "   Can't find expected common OpenSSL directories in:"
+$    write sys$output "   ''ossl_dev_dir'"
+$    status = rms_e_fnf
+$    goto clean_up
+$ endif
+$!
+$ if ((f$search( "''arch_name_exe'_exe.dir;1") .eqs. "") .or. -
+   (f$search( "''arch_name'_lib.dir;1") .eqs. ""))
+$ then
+$    write sys$output -
+      "   Can't find expected architecture-specific OpenSSL directories in:"
+$    write sys$output "   ''ossl_dev_dir'"
+$    status = rms_e_fnf
+$    goto clean_up
+$ endif
+$!
+$! All seems well (enough).  Define the OpenSSL logical names.
+$!
+$ ossl_root = ossl_dev_dir- "]"+ ".]"
+$ define /translation_attributes = concealed /nolog'p1 SSLROOT 'ossl_root'
+$ define /nolog 'p1' SSLCERTS     sslroot:[certs]
+$ define /nolog 'p1' SSLINCLUDE   sslroot:[include]
+$ define /nolog 'p1' SSLPRIVATE   sslroot:[private]
+$ define /nolog 'p1' SSLEXE       sslroot:['arch_name_exe'_exe]
+$ define /nolog 'p1' SSLLIB       sslroot:['arch_name'_lib]
+$!
+$! Defining OPENSSL lets a C program use "#include <openssl/{foo}.h>":
+$ define /nolog 'p1' OPENSSL      SSLINCLUDE:
+$!
+$! Run a site-specific procedure, if it exists.
+$!
+$ if f$search( "sslroot:[vms]openssl_systartup.com") .nes."" then -
+   @ sslroot:[vms]openssl_systartup.com
+$!
+$! Restore the original default dev:[dir] (if known).
+$!
+$ clean_up:
+$!
+$ if (f$type( orig_dev_dir) .nes. "")
+$ then
+$    set default 'orig_dev_dir'
+$ endif
+$!
+$ EXIT 'status'
+$!
diff --git a/deps/openssl/openssl/VMS/openssl_undo.com b/deps/openssl/openssl/VMS/openssl_undo.com
new file mode 100644 (file)
index 0000000..d1623a3
--- /dev/null
@@ -0,0 +1,20 @@
+$!
+$! Deassign OpenSSL logical names.
+$!
+$ call deass "OPENSSL" "''p1'"
+$ call deass "SSLCERTS" "''p1'"
+$ call deass "SSLEXE" "''p1'"
+$ call deass "SSLINCLUDE" "''p1'"
+$ call deass "SSLLIB" "''p1'"
+$ call deass "SSLPRIVATE" "''p1'"
+$ call deass "SSLROOT" "''p1'"
+$!
+$ exit
+$!
+$deass: subroutine
+$ if (f$trnlnm( p1) .nes. "")
+$ then
+$    deassign 'p2' 'p1'
+$ endif
+$ endsubroutine
+$!
index 00266db..2c0d465 100644 (file)
@@ -37,14 +37,25 @@ $ VERIFY = openssl + " verify"
 $ X509   = openssl + " x509"
 $ PKCS12 = openssl + " pkcs12"
 $ echo   = "write sys$Output"
+$ RET = 1
+$!
+$! 2010-12-20 SMS.
+$! Use a concealed logical name to reduce command line lengths, to
+$! avoid DCL errors on VAX:
+$!     %DCL-W-TKNOVF, command element is too long - shorten
+$! (Path segments like "openssl-1_0_1-stable-SNAP-20101217" accumulate
+$! quickly.)
+$!
+$ CATOP = F$PARSE( F$ENVIRONMENT( "DEFAULT"), "[]")- "].;"+ ".demoCA.]"
+$ define /translation_attributes = concealed CATOP 'CATOP'
 $!
-$ s = F$PARSE(F$ENVIRONMENT("DEFAULT"),"[]") - "].;"
-$ CATOP  := 's'.demoCA
-$ CAKEY  := ]cakey.pem
-$ CACERT := ]cacert.pem
+$ on error then goto clean_up
+$ on control_y then goto clean_up
+$!
+$ CAKEY  = "CATOP:[private]cakey.pem"
+$ CACERT = "CATOP:[000000]cacert.pem"
 $
 $ __INPUT := SYS$COMMAND
-$ RET = 1
 $!
 $ i = 1
 $opt_loop:
@@ -55,7 +66,7 @@ $
 $ IF (prog_opt .EQS. "?" .OR. prog_opt .EQS. "-h" .OR. prog_opt .EQS. "-help") 
 $ THEN
 $   echo "usage: CA -newcert|-newreq|-newca|-sign|-verify" 
-$   exit
+$   goto clean_up
 $ ENDIF
 $!
 $ IF (prog_opt .EQS. "-input")
@@ -69,7 +80,7 @@ $!
 $ IF (prog_opt .EQS. "-newcert")
 $ THEN
 $   ! Create a certificate.
-$   DEFINE/USER SYS$INPUT '__INPUT'
+$   DEFINE /USER_MODE SYS$INPUT '__INPUT'
 $   REQ -new -x509 -keyout newreq.pem -out newreq.pem 'DAYS'
 $   RET=$STATUS
 $   echo "Certificate (and private key) is in newreq.pem"
@@ -79,7 +90,7 @@ $!
 $ IF (prog_opt .EQS. "-newreq")
 $ THEN
 $   ! Create a certificate request
-$   DEFINE/USER SYS$INPUT '__INPUT'
+$   DEFINE /USER_MODE SYS$INPUT '__INPUT'
 $   REQ -new -keyout newreq.pem -out newreq.pem 'DAYS'
 $   RET=$STATUS
 $   echo "Request (and private key) is in newreq.pem"
@@ -90,41 +101,40 @@ $ IF (prog_opt .EQS. "-newca")
 $ THEN
 $   ! If explicitly asked for or it doesn't exist then setup the directory
 $   ! structure that Eric likes to manage things.
-$   IF F$SEARCH(CATOP+"]serial.") .EQS. ""
+$   IF F$SEARCH( "CATOP:[000000]serial.") .EQS. ""
 $   THEN
-$     CREATE /DIR /PROTECTION=OWNER:RWED 'CATOP']
-$     CREATE /DIR /PROTECTION=OWNER:RWED 'CATOP'.certs]
-$     CREATE /DIR /PROTECTION=OWNER:RWED 'CATOP'.crl]
-$     CREATE /DIR /PROTECTION=OWNER:RWED 'CATOP'.newcerts]
-$     CREATE /DIR /PROTECTION=OWNER:RWED 'CATOP'.private]
+$     CREATE /DIRECTORY /PROTECTION=OWNER:RWED CATOP:[000000]
+$     CREATE /DIRECTORY /PROTECTION=OWNER:RWED CATOP:[certs]
+$     CREATE /DIRECTORY /PROTECTION=OWNER:RWED CATOP:[crl]
+$     CREATE /DIRECTORY /PROTECTION=OWNER:RWED CATOP:[newcerts]
+$     CREATE /DIRECTORY /PROTECTION=OWNER:RWED CATOP:[private]
 $
-$     OPEN   /WRITE ser_file 'CATOP']serial. 
+$     OPEN /WRITE ser_file CATOP:[000000]serial. 
 $     WRITE ser_file "01"
 $     CLOSE ser_file
-$     APPEND/NEW NL: 'CATOP']index.txt
+$     APPEND /NEW_VERSION NL: CATOP:[000000]index.txt
 $
 $     ! The following is to make sure access() doesn't get confused.  It
 $     ! really needs one file in the directory to give correct answers...
-$     COPY NLA0: 'CATOP'.certs].;
-$     COPY NLA0: 'CATOP'.crl].;
-$     COPY NLA0: 'CATOP'.newcerts].;
-$     COPY NLA0: 'CATOP'.private].;
+$     COPY NLA0: CATOP:[certs].;
+$     COPY NLA0: CATOP:[crl].;
+$     COPY NLA0: CATOP:[newcerts].;
+$     COPY NLA0: CATOP:[private].;
 $   ENDIF
 $!
-$   IF F$SEARCH(CATOP+".private"+CAKEY) .EQS. ""
+$   IF F$SEARCH( CAKEY) .EQS. ""
 $   THEN
 $     READ '__INPUT' FILE -
-          /PROMPT="CA certificate filename (or enter to create): "
+       /PROMPT="CA certificate filename (or enter to create): "
 $     IF (FILE .NES. "") .AND. (F$SEARCH(FILE) .NES. "")
 $     THEN
-$       COPY 'FILE' 'CATOP'.private'CAKEY'
-$      RET=$STATUS
+$       COPY 'FILE' 'CAKEY'
+$       RET=$STATUS
 $     ELSE
 $       echo "Making CA certificate ..."
-$       DEFINE/USER SYS$INPUT '__INPUT'
-$       REQ -new -x509 -keyout 'CATOP'.private'CAKEY' -
-                      -out 'CATOP''CACERT' 'DAYS'
-$      RET=$STATUS
+$       DEFINE /USER_MODE SYS$INPUT '__INPUT'
+$       REQ -new -x509 -keyout 'CAKEY' -out 'CACERT' 'DAYS'
+$       RET=$STATUS
 $     ENDIF
 $   ENDIF
 $   GOTO opt_loop_continue
@@ -135,16 +145,16 @@ $ THEN
 $   i = i + 1
 $   cname = P'i'
 $   IF cname .EQS. "" THEN cname = "My certificate"
-$   PKCS12 -in newcert.pem -inkey newreq.pem -certfile 'CATOP''CACERT -
-          -out newcert.p12 -export -name "''cname'"
+$   PKCS12 -in newcert.pem -inkey newreq.pem -certfile 'CACERT' -
+     -out newcert.p12 -export -name "''cname'"
 $   RET=$STATUS
-$   exit RET
+$   goto clean_up
 $ ENDIF
 $!
 $ IF (prog_opt .EQS. "-xsign")
 $ THEN
 $!
-$   DEFINE/USER SYS$INPUT '__INPUT'
+$   DEFINE /USER_MODE SYS$INPUT '__INPUT'
 $   CA -policy policy_anything -infiles newreq.pem
 $   RET=$STATUS
 $   GOTO opt_loop_continue
@@ -153,7 +163,7 @@ $!
 $ IF ((prog_opt .EQS. "-sign") .OR. (prog_opt .EQS. "-signreq"))
 $ THEN
 $!   
-$   DEFINE/USER SYS$INPUT '__INPUT'
+$   DEFINE /USER_MODE SYS$INPUT '__INPUT'
 $   CA -policy policy_anything -out newcert.pem -infiles newreq.pem
 $   RET=$STATUS
 $   type newcert.pem
@@ -165,9 +175,9 @@ $ IF (prog_opt .EQS. "-signcert")
 $  THEN
 $!   
 $   echo "Cert passphrase will be requested twice - bug?"
-$   DEFINE/USER SYS$INPUT '__INPUT'
+$   DEFINE /USER_MODE SYS$INPUT '__INPUT'
 $   X509 -x509toreq -in newreq.pem -signkey newreq.pem -out tmp.pem
-$   DEFINE/USER SYS$INPUT '__INPUT'
+$   DEFINE /USER_MODE SYS$INPUT '__INPUT'
 $   CA -policy policy_anything -out newcert.pem -infiles tmp.pem
 y
 y
@@ -182,17 +192,17 @@ $!
 $   i = i + 1
 $   IF (p'i' .EQS. "")
 $   THEN
-$     DEFINE/USER SYS$INPUT '__INPUT'
-$     VERIFY "-CAfile" 'CATOP''CACERT' newcert.pem
+$     DEFINE /USER_MODE SYS$INPUT '__INPUT'
+$     VERIFY "-CAfile" 'CACERT' newcert.pem
 $   ELSE
 $     j = i
 $    verify_opt_loop:
 $     IF j .GT. 8 THEN GOTO verify_opt_loop_end
 $     IF p'j' .NES. ""
 $     THEN 
-$       DEFINE/USER SYS$INPUT '__INPUT'
+$       DEFINE /USER_MODE SYS$INPUT '__INPUT'
 $       __tmp = p'j'
-$       VERIFY "-CAfile" 'CATOP''CACERT' '__tmp'
+$       VERIFY "-CAfile" 'CACERT' '__tmp'
 $       tmp=$STATUS
 $       IF tmp .NE. 0 THEN RET=tmp
 $     ENDIF
@@ -208,8 +218,8 @@ $ IF (prog_opt .NES. "")
 $ THEN
 $!   
 $   echo "Unknown argument ''prog_opt'"
-$   
-$   EXIT 3
+$   RET = 3
+$   goto clean_up
 $ ENDIF
 $
 $opt_loop_continue:
@@ -217,4 +227,10 @@ $ i = i + 1
 $ GOTO opt_loop
 $
 $opt_loop_end:
+$!
+$clean_up:
+$!
+$ if f$trnlnm( "CATOP", "LNM$PROCESS") .nes. "" then -
+   deassign /process CATOP
+$!
 $ EXIT 'RET'
index a548815..fa32d2d 100644 (file)
@@ -31,15 +31,15 @@ LIBSSL=-L.. -lssl
 
 PROGRAM= openssl
 
-SCRIPTS=CA.sh CA.pl
+SCRIPTS=CA.sh CA.pl tsget
 
 EXE= $(PROGRAM)$(EXE_EXT)
 
 E_EXE= verify asn1pars req dgst dh dhparam enc passwd gendh errstr \
        ca crl rsa rsautl dsa dsaparam ec ecparam \
-       x509 genrsa gendsa s_server s_client speed \
+       x509 genrsa gendsa genpkey s_server s_client speed \
        s_time version pkcs7 cms crl2pkcs7 sess_id ciphers nseq pkcs12 \
-       pkcs8 spkac smime rand engine ocsp prime
+       pkcs8 pkey pkeyparam pkeyutl spkac smime rand engine ocsp prime ts
 
 PROGS= $(PROGRAM).c
 
@@ -53,18 +53,18 @@ RAND_SRC=app_rand.c
 E_OBJ= verify.o asn1pars.o req.o dgst.o dh.o dhparam.o enc.o passwd.o gendh.o errstr.o \
        ca.o pkcs7.o crl2p7.o crl.o \
        rsa.o rsautl.o dsa.o dsaparam.o ec.o ecparam.o \
-       x509.o genrsa.o gendsa.o s_server.o s_client.o speed.o \
+       x509.o genrsa.o gendsa.o genpkey.o s_server.o s_client.o speed.o \
        s_time.o $(A_OBJ) $(S_OBJ) $(RAND_OBJ) version.o sess_id.o \
-       ciphers.o nseq.o pkcs12.o pkcs8.o spkac.o smime.o rand.o engine.o \
-       ocsp.o prime.o cms.o
+       ciphers.o nseq.o pkcs12.o pkcs8.o pkey.o pkeyparam.o pkeyutl.o \
+       spkac.o smime.o cms.o rand.o engine.o ocsp.o prime.o ts.o
 
 E_SRC= verify.c asn1pars.c req.c dgst.c dh.c enc.c passwd.c gendh.c errstr.c ca.c \
        pkcs7.c crl2p7.c crl.c \
        rsa.c rsautl.c dsa.c dsaparam.c ec.c ecparam.c \
-       x509.c genrsa.c gendsa.c s_server.c s_client.c speed.c \
+       x509.c genrsa.c gendsa.c genpkey.c s_server.c s_client.c speed.c \
        s_time.c $(A_SRC) $(S_SRC) $(RAND_SRC) version.c sess_id.c \
-       ciphers.c nseq.c pkcs12.c pkcs8.c spkac.c smime.c rand.c engine.c \
-       ocsp.c prime.c cms.c
+       ciphers.c nseq.c pkcs12.c pkcs8.c pkey.c pkeyparam.c pkeyutl.c \
+       spkac.c smime.c cms.c rand.c engine.c ocsp.c prime.c ts.c
 
 SRC=$(E_SRC)
 
@@ -137,9 +137,10 @@ depend:
 dclean:
        $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
        mv -f Makefile.new $(MAKEFILE)
+       rm -f CA.pl
 
 clean:
-       rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff $(EXE)
+       rm -f *.o *.obj *.dll lib tags core .pure .nfs* *.old *.bak fluff $(EXE)
        rm -f req
 
 $(DLIBSSL):
@@ -152,20 +153,13 @@ $(EXE): progs.h $(E_OBJ) $(PROGRAM).o $(DLIBCRYPTO) $(DLIBSSL)
        $(RM) $(EXE)
        shlib_target=; if [ -n "$(SHARED_LIBS)" ]; then \
                shlib_target="$(SHLIB_TARGET)"; \
-       elif [ -n "$(FIPSCANLIB)" ]; then \
-         FIPSLD_CC="$(CC)"; CC=$(TOP)/fips/fipsld; export CC FIPSLD_CC; \
        fi; \
        LIBRARIES="$(LIBSSL) $(LIBKRB5) $(LIBCRYPTO)" ; \
-       [ "x$(FIPSCANLIB)" = "xlibfips" ] && LIBRARIES="$$LIBRARIES -lfips"; \
        $(MAKE) -f $(TOP)/Makefile.shared -e \
-               CC="$${CC}" APPNAME=$(EXE) OBJECTS="$(PROGRAM).o $(E_OBJ)" \
+               APPNAME=$(EXE) OBJECTS="$(PROGRAM).o $(E_OBJ)" \
                LIBDEPS="$(PEX_LIBS) $$LIBRARIES $(EX_LIBS)" \
                link_app.$${shlib_target}
-       @if [ -z "$(CROSS_COMPILE)" ]; then \
-               (cd ..; \
-               OPENSSL="`pwd`/util/opensslwrap.sh"; export OPENSSL; \
-               $(PERL) tools/c_rehash certs) \
-       fi
+       @(cd ..; $(MAKE) rehash)
 
 progs.h: progs.pl
        $(PERL) progs.pl $(E_EXE) >progs.h
@@ -178,150 +172,149 @@ app_rand.o: ../include/openssl/buffer.h ../include/openssl/conf.h
 app_rand.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
 app_rand.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 app_rand.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
-app_rand.o: ../include/openssl/evp.h ../include/openssl/fips.h
-app_rand.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-app_rand.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
-app_rand.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
-app_rand.o: ../include/openssl/ossl_typ.h ../include/openssl/pkcs7.h
-app_rand.o: ../include/openssl/rand.h ../include/openssl/safestack.h
-app_rand.o: ../include/openssl/sha.h ../include/openssl/stack.h
-app_rand.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
-app_rand.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-app_rand.o: ../include/openssl/x509v3.h app_rand.c apps.h
+app_rand.o: ../include/openssl/evp.h ../include/openssl/lhash.h
+app_rand.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+app_rand.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
+app_rand.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+app_rand.o: ../include/openssl/pkcs7.h ../include/openssl/rand.h
+app_rand.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+app_rand.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+app_rand.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+app_rand.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h
+app_rand.o: app_rand.c apps.h
 apps.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 apps.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 apps.o: ../include/openssl/conf.h ../include/openssl/crypto.h
 apps.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
 apps.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
 apps.o: ../include/openssl/engine.h ../include/openssl/err.h
-apps.o: ../include/openssl/evp.h ../include/openssl/fips.h
-apps.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-apps.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
-apps.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
-apps.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
-apps.o: ../include/openssl/pem2.h ../include/openssl/pkcs12.h
-apps.o: ../include/openssl/pkcs7.h ../include/openssl/rsa.h
-apps.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-apps.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-apps.o: ../include/openssl/txt_db.h ../include/openssl/ui.h
-apps.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-apps.o: ../include/openssl/x509v3.h apps.c apps.h
+apps.o: ../include/openssl/evp.h ../include/openssl/lhash.h
+apps.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+apps.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
+apps.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+apps.o: ../include/openssl/pem.h ../include/openssl/pem2.h
+apps.o: ../include/openssl/pkcs12.h ../include/openssl/pkcs7.h
+apps.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+apps.o: ../include/openssl/sha.h ../include/openssl/stack.h
+apps.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
+apps.o: ../include/openssl/ui.h ../include/openssl/x509.h
+apps.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.c apps.h
 asn1pars.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 asn1pars.o: ../include/openssl/buffer.h ../include/openssl/conf.h
 asn1pars.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
 asn1pars.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 asn1pars.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
 asn1pars.o: ../include/openssl/err.h ../include/openssl/evp.h
-asn1pars.o: ../include/openssl/fips.h ../include/openssl/lhash.h
-asn1pars.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
-asn1pars.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
-asn1pars.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-asn1pars.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-asn1pars.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
-asn1pars.o: ../include/openssl/sha.h ../include/openssl/stack.h
-asn1pars.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
-asn1pars.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-asn1pars.o: ../include/openssl/x509v3.h apps.h asn1pars.c
+asn1pars.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+asn1pars.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
+asn1pars.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+asn1pars.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+asn1pars.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
+asn1pars.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+asn1pars.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+asn1pars.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+asn1pars.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
+asn1pars.o: asn1pars.c
 ca.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 ca.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 ca.o: ../include/openssl/conf.h ../include/openssl/crypto.h
 ca.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
 ca.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
 ca.o: ../include/openssl/engine.h ../include/openssl/err.h
-ca.o: ../include/openssl/evp.h ../include/openssl/fips.h
-ca.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-ca.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
-ca.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
-ca.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
-ca.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-ca.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-ca.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-ca.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
-ca.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h ca.c
+ca.o: ../include/openssl/evp.h ../include/openssl/lhash.h
+ca.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+ca.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
+ca.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+ca.o: ../include/openssl/pem.h ../include/openssl/pem2.h
+ca.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
+ca.o: ../include/openssl/sha.h ../include/openssl/stack.h
+ca.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
+ca.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
+ca.o: ../include/openssl/x509v3.h apps.h ca.c
 ciphers.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-ciphers.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-ciphers.o: ../include/openssl/comp.h ../include/openssl/conf.h
-ciphers.o: ../include/openssl/crypto.h ../include/openssl/dtls1.h
-ciphers.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-ciphers.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-ciphers.o: ../include/openssl/engine.h ../include/openssl/err.h
-ciphers.o: ../include/openssl/evp.h ../include/openssl/fips.h
+ciphers.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+ciphers.o: ../include/openssl/conf.h ../include/openssl/crypto.h
+ciphers.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+ciphers.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+ciphers.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
+ciphers.o: ../include/openssl/err.h ../include/openssl/evp.h
 ciphers.o: ../include/openssl/hmac.h ../include/openssl/kssl.h
 ciphers.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
 ciphers.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
 ciphers.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 ciphers.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 ciphers.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-ciphers.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-ciphers.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-ciphers.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
-ciphers.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
-ciphers.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-ciphers.o: ../include/openssl/tls1.h ../include/openssl/txt_db.h
-ciphers.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-ciphers.o: ../include/openssl/x509v3.h apps.h ciphers.c
+ciphers.o: ../include/openssl/pqueue.h ../include/openssl/safestack.h
+ciphers.o: ../include/openssl/sha.h ../include/openssl/ssl.h
+ciphers.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
+ciphers.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
+ciphers.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
+ciphers.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+ciphers.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
+ciphers.o: ciphers.c
 cms.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-cms.o: ../include/openssl/buffer.h ../include/openssl/conf.h
-cms.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
-cms.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
-cms.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
-cms.o: ../include/openssl/evp.h ../include/openssl/fips.h
-cms.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-cms.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
-cms.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
-cms.o: ../include/openssl/ossl_typ.h ../include/openssl/pkcs7.h
-cms.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-cms.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-cms.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
-cms.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h cms.c
+cms.o: ../include/openssl/buffer.h ../include/openssl/cms.h
+cms.o: ../include/openssl/conf.h ../include/openssl/crypto.h
+cms.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
+cms.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
+cms.o: ../include/openssl/engine.h ../include/openssl/err.h
+cms.o: ../include/openssl/evp.h ../include/openssl/lhash.h
+cms.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+cms.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
+cms.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+cms.o: ../include/openssl/pem.h ../include/openssl/pem2.h
+cms.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
+cms.o: ../include/openssl/sha.h ../include/openssl/stack.h
+cms.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
+cms.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
+cms.o: ../include/openssl/x509v3.h apps.h cms.c
 crl.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 crl.o: ../include/openssl/buffer.h ../include/openssl/conf.h
 crl.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
 crl.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 crl.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
 crl.o: ../include/openssl/err.h ../include/openssl/evp.h
-crl.o: ../include/openssl/fips.h ../include/openssl/lhash.h
-crl.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
-crl.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
-crl.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-crl.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-crl.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
-crl.o: ../include/openssl/sha.h ../include/openssl/stack.h
-crl.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
-crl.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-crl.o: ../include/openssl/x509v3.h apps.h crl.c
+crl.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+crl.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
+crl.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+crl.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+crl.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
+crl.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+crl.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+crl.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+crl.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h crl.c
 crl2p7.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 crl2p7.o: ../include/openssl/buffer.h ../include/openssl/conf.h
 crl2p7.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
 crl2p7.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 crl2p7.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
 crl2p7.o: ../include/openssl/err.h ../include/openssl/evp.h
-crl2p7.o: ../include/openssl/fips.h ../include/openssl/lhash.h
-crl2p7.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
-crl2p7.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
-crl2p7.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-crl2p7.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-crl2p7.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
-crl2p7.o: ../include/openssl/sha.h ../include/openssl/stack.h
-crl2p7.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
-crl2p7.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-crl2p7.o: ../include/openssl/x509v3.h apps.h crl2p7.c
+crl2p7.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+crl2p7.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
+crl2p7.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+crl2p7.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+crl2p7.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
+crl2p7.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+crl2p7.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+crl2p7.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+crl2p7.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
+crl2p7.o: crl2p7.c
 dgst.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 dgst.o: ../include/openssl/buffer.h ../include/openssl/conf.h
 dgst.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
 dgst.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 dgst.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
 dgst.o: ../include/openssl/err.h ../include/openssl/evp.h
-dgst.o: ../include/openssl/fips.h ../include/openssl/hmac.h
-dgst.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-dgst.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
-dgst.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
-dgst.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
-dgst.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-dgst.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-dgst.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-dgst.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
-dgst.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h dgst.c
+dgst.o: ../include/openssl/hmac.h ../include/openssl/lhash.h
+dgst.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+dgst.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
+dgst.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+dgst.o: ../include/openssl/pem.h ../include/openssl/pem2.h
+dgst.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
+dgst.o: ../include/openssl/sha.h ../include/openssl/stack.h
+dgst.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
+dgst.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
+dgst.o: ../include/openssl/x509v3.h apps.h dgst.c
 dh.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 dh.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 dh.o: ../include/openssl/conf.h ../include/openssl/crypto.h
@@ -329,16 +322,15 @@ dh.o: ../include/openssl/dh.h ../include/openssl/e_os2.h
 dh.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 dh.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
 dh.o: ../include/openssl/err.h ../include/openssl/evp.h
-dh.o: ../include/openssl/fips.h ../include/openssl/lhash.h
-dh.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
-dh.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
-dh.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-dh.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-dh.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
-dh.o: ../include/openssl/sha.h ../include/openssl/stack.h
-dh.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
-dh.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-dh.o: ../include/openssl/x509v3.h apps.h dh.c
+dh.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+dh.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
+dh.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+dh.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+dh.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
+dh.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+dh.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+dh.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+dh.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h dh.c
 dsa.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 dsa.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 dsa.o: ../include/openssl/conf.h ../include/openssl/crypto.h
@@ -346,16 +338,15 @@ dsa.o: ../include/openssl/dsa.h ../include/openssl/e_os2.h
 dsa.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 dsa.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
 dsa.o: ../include/openssl/err.h ../include/openssl/evp.h
-dsa.o: ../include/openssl/fips.h ../include/openssl/lhash.h
-dsa.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
-dsa.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
-dsa.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-dsa.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-dsa.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
-dsa.o: ../include/openssl/sha.h ../include/openssl/stack.h
-dsa.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
-dsa.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-dsa.o: ../include/openssl/x509v3.h apps.h dsa.c
+dsa.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+dsa.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
+dsa.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+dsa.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+dsa.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
+dsa.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+dsa.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+dsa.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+dsa.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h dsa.c
 dsaparam.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 dsaparam.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 dsaparam.o: ../include/openssl/conf.h ../include/openssl/crypto.h
@@ -363,15 +354,14 @@ dsaparam.o: ../include/openssl/dh.h ../include/openssl/dsa.h
 dsaparam.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
 dsaparam.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
 dsaparam.o: ../include/openssl/engine.h ../include/openssl/err.h
-dsaparam.o: ../include/openssl/evp.h ../include/openssl/fips.h
-dsaparam.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-dsaparam.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
-dsaparam.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
-dsaparam.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
-dsaparam.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-dsaparam.o: ../include/openssl/rand.h ../include/openssl/rsa.h
-dsaparam.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-dsaparam.o: ../include/openssl/stack.h ../include/openssl/store.h
+dsaparam.o: ../include/openssl/evp.h ../include/openssl/lhash.h
+dsaparam.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+dsaparam.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
+dsaparam.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+dsaparam.o: ../include/openssl/pem.h ../include/openssl/pem2.h
+dsaparam.o: ../include/openssl/pkcs7.h ../include/openssl/rand.h
+dsaparam.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+dsaparam.o: ../include/openssl/sha.h ../include/openssl/stack.h
 dsaparam.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
 dsaparam.o: ../include/openssl/ui.h ../include/openssl/x509.h
 dsaparam.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
@@ -382,40 +372,38 @@ ec.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
 ec.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 ec.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
 ec.o: ../include/openssl/err.h ../include/openssl/evp.h
-ec.o: ../include/openssl/fips.h ../include/openssl/lhash.h
-ec.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
-ec.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
-ec.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-ec.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-ec.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
-ec.o: ../include/openssl/sha.h ../include/openssl/stack.h
-ec.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
-ec.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-ec.o: ../include/openssl/x509v3.h apps.h ec.c
+ec.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+ec.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
+ec.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+ec.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+ec.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
+ec.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+ec.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+ec.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+ec.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h ec.c
 ecparam.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 ecparam.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 ecparam.o: ../include/openssl/conf.h ../include/openssl/crypto.h
 ecparam.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
 ecparam.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
 ecparam.o: ../include/openssl/engine.h ../include/openssl/err.h
-ecparam.o: ../include/openssl/evp.h ../include/openssl/fips.h
-ecparam.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-ecparam.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
-ecparam.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
-ecparam.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
-ecparam.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-ecparam.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-ecparam.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-ecparam.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
-ecparam.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
-ecparam.o: ecparam.c
+ecparam.o: ../include/openssl/evp.h ../include/openssl/lhash.h
+ecparam.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+ecparam.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
+ecparam.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+ecparam.o: ../include/openssl/pem.h ../include/openssl/pem2.h
+ecparam.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
+ecparam.o: ../include/openssl/sha.h ../include/openssl/stack.h
+ecparam.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
+ecparam.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
+ecparam.o: ../include/openssl/x509v3.h apps.h ecparam.c
 enc.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-enc.o: ../include/openssl/buffer.h ../include/openssl/conf.h
-enc.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
-enc.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
-enc.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
-enc.o: ../include/openssl/err.h ../include/openssl/evp.h
-enc.o: ../include/openssl/fips.h ../include/openssl/lhash.h
+enc.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+enc.o: ../include/openssl/conf.h ../include/openssl/crypto.h
+enc.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
+enc.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
+enc.o: ../include/openssl/engine.h ../include/openssl/err.h
+enc.o: ../include/openssl/evp.h ../include/openssl/lhash.h
 enc.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 enc.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
 enc.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
@@ -426,49 +414,47 @@ enc.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
 enc.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
 enc.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h enc.c
 engine.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-engine.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-engine.o: ../include/openssl/comp.h ../include/openssl/conf.h
-engine.o: ../include/openssl/crypto.h ../include/openssl/dtls1.h
-engine.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-engine.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-engine.o: ../include/openssl/engine.h ../include/openssl/err.h
-engine.o: ../include/openssl/evp.h ../include/openssl/fips.h
+engine.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+engine.o: ../include/openssl/conf.h ../include/openssl/crypto.h
+engine.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+engine.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+engine.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
+engine.o: ../include/openssl/err.h ../include/openssl/evp.h
 engine.o: ../include/openssl/hmac.h ../include/openssl/kssl.h
 engine.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
 engine.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
 engine.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 engine.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 engine.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-engine.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-engine.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-engine.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
-engine.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
-engine.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-engine.o: ../include/openssl/tls1.h ../include/openssl/txt_db.h
-engine.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-engine.o: ../include/openssl/x509v3.h apps.h engine.c
+engine.o: ../include/openssl/pqueue.h ../include/openssl/safestack.h
+engine.o: ../include/openssl/sha.h ../include/openssl/ssl.h
+engine.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
+engine.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
+engine.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
+engine.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+engine.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
+engine.o: engine.c
 errstr.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-errstr.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-errstr.o: ../include/openssl/comp.h ../include/openssl/conf.h
-errstr.o: ../include/openssl/crypto.h ../include/openssl/dtls1.h
-errstr.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-errstr.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-errstr.o: ../include/openssl/engine.h ../include/openssl/err.h
-errstr.o: ../include/openssl/evp.h ../include/openssl/fips.h
+errstr.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+errstr.o: ../include/openssl/conf.h ../include/openssl/crypto.h
+errstr.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+errstr.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+errstr.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
+errstr.o: ../include/openssl/err.h ../include/openssl/evp.h
 errstr.o: ../include/openssl/hmac.h ../include/openssl/kssl.h
 errstr.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
 errstr.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
 errstr.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 errstr.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 errstr.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-errstr.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-errstr.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-errstr.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
-errstr.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
-errstr.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-errstr.o: ../include/openssl/tls1.h ../include/openssl/txt_db.h
-errstr.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-errstr.o: ../include/openssl/x509v3.h apps.h errstr.c
+errstr.o: ../include/openssl/pqueue.h ../include/openssl/safestack.h
+errstr.o: ../include/openssl/sha.h ../include/openssl/ssl.h
+errstr.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
+errstr.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
+errstr.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
+errstr.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+errstr.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
+errstr.o: errstr.c
 gendh.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 gendh.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 gendh.o: ../include/openssl/conf.h ../include/openssl/crypto.h
@@ -476,15 +462,14 @@ gendh.o: ../include/openssl/dh.h ../include/openssl/dsa.h
 gendh.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
 gendh.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
 gendh.o: ../include/openssl/engine.h ../include/openssl/err.h
-gendh.o: ../include/openssl/evp.h ../include/openssl/fips.h
-gendh.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-gendh.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
-gendh.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
-gendh.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
-gendh.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-gendh.o: ../include/openssl/rand.h ../include/openssl/rsa.h
-gendh.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-gendh.o: ../include/openssl/stack.h ../include/openssl/store.h
+gendh.o: ../include/openssl/evp.h ../include/openssl/lhash.h
+gendh.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+gendh.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
+gendh.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+gendh.o: ../include/openssl/pem.h ../include/openssl/pem2.h
+gendh.o: ../include/openssl/pkcs7.h ../include/openssl/rand.h
+gendh.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+gendh.o: ../include/openssl/sha.h ../include/openssl/stack.h
 gendh.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
 gendh.o: ../include/openssl/ui.h ../include/openssl/x509.h
 gendh.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
@@ -496,16 +481,32 @@ gendsa.o: ../include/openssl/dsa.h ../include/openssl/e_os2.h
 gendsa.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 gendsa.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
 gendsa.o: ../include/openssl/err.h ../include/openssl/evp.h
-gendsa.o: ../include/openssl/fips.h ../include/openssl/lhash.h
-gendsa.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
-gendsa.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
-gendsa.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-gendsa.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-gendsa.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
-gendsa.o: ../include/openssl/sha.h ../include/openssl/stack.h
-gendsa.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
-gendsa.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-gendsa.o: ../include/openssl/x509v3.h apps.h gendsa.c
+gendsa.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+gendsa.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
+gendsa.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+gendsa.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+gendsa.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
+gendsa.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+gendsa.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+gendsa.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+gendsa.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
+gendsa.o: gendsa.c
+genpkey.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
+genpkey.o: ../include/openssl/buffer.h ../include/openssl/conf.h
+genpkey.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
+genpkey.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+genpkey.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
+genpkey.o: ../include/openssl/err.h ../include/openssl/evp.h
+genpkey.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+genpkey.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
+genpkey.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+genpkey.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+genpkey.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
+genpkey.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+genpkey.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+genpkey.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+genpkey.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
+genpkey.o: genpkey.c
 genrsa.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 genrsa.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 genrsa.o: ../include/openssl/conf.h ../include/openssl/crypto.h
@@ -513,15 +514,14 @@ genrsa.o: ../include/openssl/dh.h ../include/openssl/dsa.h
 genrsa.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
 genrsa.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
 genrsa.o: ../include/openssl/engine.h ../include/openssl/err.h
-genrsa.o: ../include/openssl/evp.h ../include/openssl/fips.h
-genrsa.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-genrsa.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
-genrsa.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
-genrsa.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
-genrsa.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-genrsa.o: ../include/openssl/rand.h ../include/openssl/rsa.h
-genrsa.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-genrsa.o: ../include/openssl/stack.h ../include/openssl/store.h
+genrsa.o: ../include/openssl/evp.h ../include/openssl/lhash.h
+genrsa.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+genrsa.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
+genrsa.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+genrsa.o: ../include/openssl/pem.h ../include/openssl/pem2.h
+genrsa.o: ../include/openssl/pkcs7.h ../include/openssl/rand.h
+genrsa.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+genrsa.o: ../include/openssl/sha.h ../include/openssl/stack.h
 genrsa.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
 genrsa.o: ../include/openssl/ui.h ../include/openssl/x509.h
 genrsa.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
@@ -532,16 +532,15 @@ nseq.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
 nseq.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 nseq.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
 nseq.o: ../include/openssl/err.h ../include/openssl/evp.h
-nseq.o: ../include/openssl/fips.h ../include/openssl/lhash.h
-nseq.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
-nseq.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
-nseq.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-nseq.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-nseq.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
-nseq.o: ../include/openssl/sha.h ../include/openssl/stack.h
-nseq.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
-nseq.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-nseq.o: ../include/openssl/x509v3.h apps.h nseq.c
+nseq.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+nseq.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
+nseq.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+nseq.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+nseq.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
+nseq.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+nseq.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+nseq.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+nseq.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h nseq.c
 ocsp.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 ocsp.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 ocsp.o: ../include/openssl/comp.h ../include/openssl/conf.h
@@ -549,14 +548,13 @@ ocsp.o: ../include/openssl/crypto.h ../include/openssl/dtls1.h
 ocsp.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
 ocsp.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
 ocsp.o: ../include/openssl/engine.h ../include/openssl/err.h
-ocsp.o: ../include/openssl/evp.h ../include/openssl/fips.h
-ocsp.o: ../include/openssl/hmac.h ../include/openssl/kssl.h
-ocsp.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-ocsp.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
-ocsp.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
-ocsp.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
-ocsp.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-ocsp.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
+ocsp.o: ../include/openssl/evp.h ../include/openssl/hmac.h
+ocsp.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
+ocsp.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+ocsp.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
+ocsp.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+ocsp.o: ../include/openssl/pem.h ../include/openssl/pem2.h
+ocsp.o: ../include/openssl/pkcs7.h ../include/openssl/pqueue.h
 ocsp.o: ../include/openssl/safestack.h ../include/openssl/sha.h
 ocsp.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
 ocsp.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
@@ -565,27 +563,26 @@ ocsp.o: ../include/openssl/tls1.h ../include/openssl/txt_db.h
 ocsp.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
 ocsp.o: ../include/openssl/x509v3.h apps.h ocsp.c
 openssl.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-openssl.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-openssl.o: ../include/openssl/comp.h ../include/openssl/conf.h
-openssl.o: ../include/openssl/crypto.h ../include/openssl/dtls1.h
-openssl.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-openssl.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-openssl.o: ../include/openssl/engine.h ../include/openssl/err.h
-openssl.o: ../include/openssl/evp.h ../include/openssl/fips.h
+openssl.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+openssl.o: ../include/openssl/conf.h ../include/openssl/crypto.h
+openssl.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+openssl.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+openssl.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
+openssl.o: ../include/openssl/err.h ../include/openssl/evp.h
 openssl.o: ../include/openssl/hmac.h ../include/openssl/kssl.h
 openssl.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
 openssl.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
 openssl.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 openssl.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 openssl.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-openssl.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-openssl.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-openssl.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
-openssl.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
-openssl.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-openssl.o: ../include/openssl/tls1.h ../include/openssl/txt_db.h
-openssl.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-openssl.o: ../include/openssl/x509v3.h apps.h openssl.c progs.h s_apps.h
+openssl.o: ../include/openssl/pqueue.h ../include/openssl/safestack.h
+openssl.o: ../include/openssl/sha.h ../include/openssl/ssl.h
+openssl.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
+openssl.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
+openssl.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
+openssl.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+openssl.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
+openssl.o: openssl.c progs.h s_apps.h
 passwd.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 passwd.o: ../include/openssl/buffer.h ../include/openssl/conf.h
 passwd.o: ../include/openssl/crypto.h ../include/openssl/des.h
@@ -593,97 +590,142 @@ passwd.o: ../include/openssl/des_old.h ../include/openssl/e_os2.h
 passwd.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 passwd.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
 passwd.o: ../include/openssl/err.h ../include/openssl/evp.h
-passwd.o: ../include/openssl/fips.h ../include/openssl/lhash.h
-passwd.o: ../include/openssl/md5.h ../include/openssl/obj_mac.h
-passwd.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
-passwd.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
-passwd.o: ../include/openssl/ossl_typ.h ../include/openssl/pkcs7.h
-passwd.o: ../include/openssl/rand.h ../include/openssl/safestack.h
-passwd.o: ../include/openssl/sha.h ../include/openssl/stack.h
-passwd.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
-passwd.o: ../include/openssl/ui.h ../include/openssl/ui_compat.h
-passwd.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-passwd.o: ../include/openssl/x509v3.h apps.h passwd.c
+passwd.o: ../include/openssl/lhash.h ../include/openssl/md5.h
+passwd.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+passwd.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
+passwd.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+passwd.o: ../include/openssl/pkcs7.h ../include/openssl/rand.h
+passwd.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+passwd.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+passwd.o: ../include/openssl/txt_db.h ../include/openssl/ui.h
+passwd.o: ../include/openssl/ui_compat.h ../include/openssl/x509.h
+passwd.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
+passwd.o: passwd.c
 pkcs12.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 pkcs12.o: ../include/openssl/buffer.h ../include/openssl/conf.h
 pkcs12.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
 pkcs12.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 pkcs12.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
 pkcs12.o: ../include/openssl/err.h ../include/openssl/evp.h
-pkcs12.o: ../include/openssl/fips.h ../include/openssl/lhash.h
-pkcs12.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
-pkcs12.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
-pkcs12.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-pkcs12.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-pkcs12.o: ../include/openssl/pkcs12.h ../include/openssl/pkcs7.h
-pkcs12.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-pkcs12.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-pkcs12.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
-pkcs12.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
-pkcs12.o: pkcs12.c
+pkcs12.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+pkcs12.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
+pkcs12.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+pkcs12.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+pkcs12.o: ../include/openssl/pem2.h ../include/openssl/pkcs12.h
+pkcs12.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
+pkcs12.o: ../include/openssl/sha.h ../include/openssl/stack.h
+pkcs12.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
+pkcs12.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
+pkcs12.o: ../include/openssl/x509v3.h apps.h pkcs12.c
 pkcs7.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 pkcs7.o: ../include/openssl/buffer.h ../include/openssl/conf.h
 pkcs7.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
 pkcs7.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 pkcs7.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
 pkcs7.o: ../include/openssl/err.h ../include/openssl/evp.h
-pkcs7.o: ../include/openssl/fips.h ../include/openssl/lhash.h
-pkcs7.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
-pkcs7.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
-pkcs7.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-pkcs7.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-pkcs7.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
-pkcs7.o: ../include/openssl/sha.h ../include/openssl/stack.h
-pkcs7.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
-pkcs7.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-pkcs7.o: ../include/openssl/x509v3.h apps.h pkcs7.c
+pkcs7.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+pkcs7.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
+pkcs7.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+pkcs7.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+pkcs7.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
+pkcs7.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+pkcs7.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+pkcs7.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+pkcs7.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
+pkcs7.o: pkcs7.c
 pkcs8.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 pkcs8.o: ../include/openssl/buffer.h ../include/openssl/conf.h
 pkcs8.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
 pkcs8.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 pkcs8.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
 pkcs8.o: ../include/openssl/err.h ../include/openssl/evp.h
-pkcs8.o: ../include/openssl/fips.h ../include/openssl/lhash.h
-pkcs8.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
-pkcs8.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
-pkcs8.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-pkcs8.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-pkcs8.o: ../include/openssl/pkcs12.h ../include/openssl/pkcs7.h
-pkcs8.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-pkcs8.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-pkcs8.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
-pkcs8.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
-pkcs8.o: pkcs8.c
+pkcs8.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+pkcs8.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
+pkcs8.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+pkcs8.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+pkcs8.o: ../include/openssl/pem2.h ../include/openssl/pkcs12.h
+pkcs8.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
+pkcs8.o: ../include/openssl/sha.h ../include/openssl/stack.h
+pkcs8.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
+pkcs8.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
+pkcs8.o: ../include/openssl/x509v3.h apps.h pkcs8.c
+pkey.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
+pkey.o: ../include/openssl/buffer.h ../include/openssl/conf.h
+pkey.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
+pkey.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+pkey.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
+pkey.o: ../include/openssl/err.h ../include/openssl/evp.h
+pkey.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+pkey.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
+pkey.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+pkey.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+pkey.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
+pkey.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+pkey.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+pkey.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+pkey.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h pkey.c
+pkeyparam.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
+pkeyparam.o: ../include/openssl/buffer.h ../include/openssl/conf.h
+pkeyparam.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
+pkeyparam.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+pkeyparam.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
+pkeyparam.o: ../include/openssl/err.h ../include/openssl/evp.h
+pkeyparam.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+pkeyparam.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
+pkeyparam.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+pkeyparam.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+pkeyparam.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
+pkeyparam.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+pkeyparam.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+pkeyparam.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+pkeyparam.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
+pkeyparam.o: pkeyparam.c
+pkeyutl.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
+pkeyutl.o: ../include/openssl/buffer.h ../include/openssl/conf.h
+pkeyutl.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
+pkeyutl.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+pkeyutl.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
+pkeyutl.o: ../include/openssl/err.h ../include/openssl/evp.h
+pkeyutl.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+pkeyutl.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
+pkeyutl.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+pkeyutl.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+pkeyutl.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
+pkeyutl.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+pkeyutl.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+pkeyutl.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+pkeyutl.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
+pkeyutl.o: pkeyutl.c
 prime.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 prime.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 prime.o: ../include/openssl/conf.h ../include/openssl/crypto.h
 prime.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
 prime.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
 prime.o: ../include/openssl/engine.h ../include/openssl/evp.h
-prime.o: ../include/openssl/fips.h ../include/openssl/lhash.h
-prime.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
-prime.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
-prime.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-prime.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
-prime.o: ../include/openssl/sha.h ../include/openssl/stack.h
-prime.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
-prime.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-prime.o: ../include/openssl/x509v3.h apps.h prime.c
+prime.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+prime.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
+prime.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+prime.o: ../include/openssl/ossl_typ.h ../include/openssl/pkcs7.h
+prime.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+prime.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+prime.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+prime.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
+prime.o: prime.c
 rand.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 rand.o: ../include/openssl/buffer.h ../include/openssl/conf.h
 rand.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
 rand.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 rand.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
 rand.o: ../include/openssl/err.h ../include/openssl/evp.h
-rand.o: ../include/openssl/fips.h ../include/openssl/lhash.h
-rand.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
-rand.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
-rand.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-rand.o: ../include/openssl/pkcs7.h ../include/openssl/rand.h
-rand.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-rand.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-rand.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
-rand.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h rand.c
+rand.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+rand.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
+rand.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+rand.o: ../include/openssl/ossl_typ.h ../include/openssl/pkcs7.h
+rand.o: ../include/openssl/rand.h ../include/openssl/safestack.h
+rand.o: ../include/openssl/sha.h ../include/openssl/stack.h
+rand.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
+rand.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
+rand.o: ../include/openssl/x509v3.h apps.h rand.c
 req.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 req.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 req.o: ../include/openssl/conf.h ../include/openssl/crypto.h
@@ -691,15 +733,14 @@ req.o: ../include/openssl/dh.h ../include/openssl/dsa.h
 req.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
 req.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
 req.o: ../include/openssl/engine.h ../include/openssl/err.h
-req.o: ../include/openssl/evp.h ../include/openssl/fips.h
-req.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-req.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
-req.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
-req.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
-req.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-req.o: ../include/openssl/rand.h ../include/openssl/rsa.h
-req.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-req.o: ../include/openssl/stack.h ../include/openssl/store.h
+req.o: ../include/openssl/evp.h ../include/openssl/lhash.h
+req.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+req.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
+req.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+req.o: ../include/openssl/pem.h ../include/openssl/pem2.h
+req.o: ../include/openssl/pkcs7.h ../include/openssl/rand.h
+req.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+req.o: ../include/openssl/sha.h ../include/openssl/stack.h
 req.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
 req.o: ../include/openssl/ui.h ../include/openssl/x509.h
 req.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h req.c
@@ -709,57 +750,53 @@ rsa.o: ../include/openssl/conf.h ../include/openssl/crypto.h
 rsa.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
 rsa.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
 rsa.o: ../include/openssl/engine.h ../include/openssl/err.h
-rsa.o: ../include/openssl/evp.h ../include/openssl/fips.h
-rsa.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-rsa.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
-rsa.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
-rsa.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
-rsa.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-rsa.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-rsa.o: ../include/openssl/sha.h ../include/openssl/stack.h
-rsa.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
-rsa.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-rsa.o: ../include/openssl/x509v3.h apps.h rsa.c
+rsa.o: ../include/openssl/evp.h ../include/openssl/lhash.h
+rsa.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+rsa.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
+rsa.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+rsa.o: ../include/openssl/pem.h ../include/openssl/pem2.h
+rsa.o: ../include/openssl/pkcs7.h ../include/openssl/rsa.h
+rsa.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+rsa.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+rsa.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+rsa.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h rsa.c
 rsautl.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 rsautl.o: ../include/openssl/buffer.h ../include/openssl/conf.h
 rsautl.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
 rsautl.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 rsautl.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
 rsautl.o: ../include/openssl/err.h ../include/openssl/evp.h
-rsautl.o: ../include/openssl/fips.h ../include/openssl/lhash.h
-rsautl.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
-rsautl.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
-rsautl.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-rsautl.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-rsautl.o: ../include/openssl/pkcs7.h ../include/openssl/rsa.h
-rsautl.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-rsautl.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-rsautl.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
-rsautl.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
-rsautl.o: rsautl.c
+rsautl.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+rsautl.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
+rsautl.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+rsautl.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+rsautl.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
+rsautl.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+rsautl.o: ../include/openssl/sha.h ../include/openssl/stack.h
+rsautl.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
+rsautl.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
+rsautl.o: ../include/openssl/x509v3.h apps.h rsautl.c
 s_cb.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-s_cb.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-s_cb.o: ../include/openssl/comp.h ../include/openssl/conf.h
-s_cb.o: ../include/openssl/crypto.h ../include/openssl/dtls1.h
-s_cb.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-s_cb.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-s_cb.o: ../include/openssl/engine.h ../include/openssl/err.h
-s_cb.o: ../include/openssl/evp.h ../include/openssl/fips.h
+s_cb.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+s_cb.o: ../include/openssl/conf.h ../include/openssl/crypto.h
+s_cb.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+s_cb.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+s_cb.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
+s_cb.o: ../include/openssl/err.h ../include/openssl/evp.h
 s_cb.o: ../include/openssl/hmac.h ../include/openssl/kssl.h
 s_cb.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
 s_cb.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
 s_cb.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 s_cb.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 s_cb.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-s_cb.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-s_cb.o: ../include/openssl/rand.h ../include/openssl/safestack.h
-s_cb.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-s_cb.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-s_cb.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-s_cb.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-s_cb.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
-s_cb.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
-s_cb.o: s_apps.h s_cb.c
+s_cb.o: ../include/openssl/pqueue.h ../include/openssl/rand.h
+s_cb.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+s_cb.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+s_cb.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+s_cb.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+s_cb.o: ../include/openssl/tls1.h ../include/openssl/txt_db.h
+s_cb.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
+s_cb.o: ../include/openssl/x509v3.h apps.h s_apps.h s_cb.c
 s_client.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 s_client.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 s_client.o: ../include/openssl/comp.h ../include/openssl/conf.h
@@ -767,14 +804,13 @@ s_client.o: ../include/openssl/crypto.h ../include/openssl/dtls1.h
 s_client.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
 s_client.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
 s_client.o: ../include/openssl/engine.h ../include/openssl/err.h
-s_client.o: ../include/openssl/evp.h ../include/openssl/fips.h
-s_client.o: ../include/openssl/hmac.h ../include/openssl/kssl.h
-s_client.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-s_client.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
-s_client.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
-s_client.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
-s_client.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-s_client.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
+s_client.o: ../include/openssl/evp.h ../include/openssl/hmac.h
+s_client.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
+s_client.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+s_client.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
+s_client.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+s_client.o: ../include/openssl/pem.h ../include/openssl/pem2.h
+s_client.o: ../include/openssl/pkcs7.h ../include/openssl/pqueue.h
 s_client.o: ../include/openssl/rand.h ../include/openssl/safestack.h
 s_client.o: ../include/openssl/sha.h ../include/openssl/ssl.h
 s_client.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
@@ -791,128 +827,125 @@ s_server.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
 s_server.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
 s_server.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
 s_server.o: ../include/openssl/engine.h ../include/openssl/err.h
-s_server.o: ../include/openssl/evp.h ../include/openssl/fips.h
-s_server.o: ../include/openssl/hmac.h ../include/openssl/kssl.h
-s_server.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-s_server.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
-s_server.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
-s_server.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
-s_server.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-s_server.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
+s_server.o: ../include/openssl/evp.h ../include/openssl/hmac.h
+s_server.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
+s_server.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+s_server.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
+s_server.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+s_server.o: ../include/openssl/pem.h ../include/openssl/pem2.h
+s_server.o: ../include/openssl/pkcs7.h ../include/openssl/pqueue.h
 s_server.o: ../include/openssl/rand.h ../include/openssl/rsa.h
 s_server.o: ../include/openssl/safestack.h ../include/openssl/sha.h
 s_server.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
 s_server.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
-s_server.o: ../include/openssl/stack.h ../include/openssl/store.h
-s_server.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-s_server.o: ../include/openssl/txt_db.h ../include/openssl/ui.h
-s_server.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-s_server.o: ../include/openssl/x509v3.h apps.h s_apps.h s_server.c timeouts.h
+s_server.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+s_server.o: ../include/openssl/tls1.h ../include/openssl/txt_db.h
+s_server.o: ../include/openssl/ui.h ../include/openssl/x509.h
+s_server.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
+s_server.o: s_apps.h s_server.c timeouts.h
 s_socket.o: ../e_os.h ../e_os2.h ../include/openssl/asn1.h
-s_socket.o: ../include/openssl/bio.h ../include/openssl/bn.h
-s_socket.o: ../include/openssl/buffer.h ../include/openssl/comp.h
-s_socket.o: ../include/openssl/conf.h ../include/openssl/crypto.h
-s_socket.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
-s_socket.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
-s_socket.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
-s_socket.o: ../include/openssl/evp.h ../include/openssl/fips.h
+s_socket.o: ../include/openssl/bio.h ../include/openssl/buffer.h
+s_socket.o: ../include/openssl/comp.h ../include/openssl/conf.h
+s_socket.o: ../include/openssl/crypto.h ../include/openssl/dtls1.h
+s_socket.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
+s_socket.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
+s_socket.o: ../include/openssl/engine.h ../include/openssl/evp.h
 s_socket.o: ../include/openssl/hmac.h ../include/openssl/kssl.h
 s_socket.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
 s_socket.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
 s_socket.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 s_socket.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 s_socket.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-s_socket.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-s_socket.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-s_socket.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
-s_socket.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
-s_socket.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-s_socket.o: ../include/openssl/tls1.h ../include/openssl/txt_db.h
-s_socket.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-s_socket.o: ../include/openssl/x509v3.h apps.h s_apps.h s_socket.c
+s_socket.o: ../include/openssl/pqueue.h ../include/openssl/safestack.h
+s_socket.o: ../include/openssl/sha.h ../include/openssl/ssl.h
+s_socket.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
+s_socket.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
+s_socket.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
+s_socket.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+s_socket.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
+s_socket.o: s_apps.h s_socket.c
 s_time.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-s_time.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-s_time.o: ../include/openssl/comp.h ../include/openssl/conf.h
-s_time.o: ../include/openssl/crypto.h ../include/openssl/dtls1.h
-s_time.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-s_time.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-s_time.o: ../include/openssl/engine.h ../include/openssl/err.h
-s_time.o: ../include/openssl/evp.h ../include/openssl/fips.h
+s_time.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+s_time.o: ../include/openssl/conf.h ../include/openssl/crypto.h
+s_time.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+s_time.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+s_time.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
+s_time.o: ../include/openssl/err.h ../include/openssl/evp.h
 s_time.o: ../include/openssl/hmac.h ../include/openssl/kssl.h
 s_time.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
 s_time.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
 s_time.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 s_time.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 s_time.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-s_time.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-s_time.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-s_time.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
-s_time.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
-s_time.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-s_time.o: ../include/openssl/tls1.h ../include/openssl/txt_db.h
-s_time.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-s_time.o: ../include/openssl/x509v3.h apps.h s_apps.h s_time.c
+s_time.o: ../include/openssl/pqueue.h ../include/openssl/safestack.h
+s_time.o: ../include/openssl/sha.h ../include/openssl/ssl.h
+s_time.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
+s_time.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
+s_time.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
+s_time.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+s_time.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
+s_time.o: s_apps.h s_time.c
 sess_id.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-sess_id.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-sess_id.o: ../include/openssl/comp.h ../include/openssl/conf.h
-sess_id.o: ../include/openssl/crypto.h ../include/openssl/dtls1.h
-sess_id.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-sess_id.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-sess_id.o: ../include/openssl/engine.h ../include/openssl/err.h
-sess_id.o: ../include/openssl/evp.h ../include/openssl/fips.h
+sess_id.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+sess_id.o: ../include/openssl/conf.h ../include/openssl/crypto.h
+sess_id.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+sess_id.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+sess_id.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
+sess_id.o: ../include/openssl/err.h ../include/openssl/evp.h
 sess_id.o: ../include/openssl/hmac.h ../include/openssl/kssl.h
 sess_id.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
 sess_id.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
 sess_id.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 sess_id.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 sess_id.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-sess_id.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-sess_id.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-sess_id.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
-sess_id.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
-sess_id.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-sess_id.o: ../include/openssl/tls1.h ../include/openssl/txt_db.h
-sess_id.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-sess_id.o: ../include/openssl/x509v3.h apps.h sess_id.c
+sess_id.o: ../include/openssl/pqueue.h ../include/openssl/safestack.h
+sess_id.o: ../include/openssl/sha.h ../include/openssl/ssl.h
+sess_id.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
+sess_id.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
+sess_id.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
+sess_id.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+sess_id.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
+sess_id.o: sess_id.c
 smime.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 smime.o: ../include/openssl/buffer.h ../include/openssl/conf.h
 smime.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
 smime.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 smime.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
 smime.o: ../include/openssl/err.h ../include/openssl/evp.h
-smime.o: ../include/openssl/fips.h ../include/openssl/lhash.h
-smime.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
-smime.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
-smime.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-smime.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-smime.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
-smime.o: ../include/openssl/sha.h ../include/openssl/stack.h
-smime.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
-smime.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-smime.o: ../include/openssl/x509v3.h apps.h smime.c
+smime.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+smime.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
+smime.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+smime.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+smime.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
+smime.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+smime.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+smime.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+smime.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
+smime.o: smime.c
 speed.o: ../e_os.h ../include/openssl/aes.h ../include/openssl/asn1.h
 speed.o: ../include/openssl/bio.h ../include/openssl/blowfish.h
 speed.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-speed.o: ../include/openssl/cast.h ../include/openssl/conf.h
-speed.o: ../include/openssl/crypto.h ../include/openssl/des.h
-speed.o: ../include/openssl/des_old.h ../include/openssl/dsa.h
-speed.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-speed.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-speed.o: ../include/openssl/engine.h ../include/openssl/err.h
-speed.o: ../include/openssl/evp.h ../include/openssl/fips.h
+speed.o: ../include/openssl/camellia.h ../include/openssl/cast.h
+speed.o: ../include/openssl/conf.h ../include/openssl/crypto.h
+speed.o: ../include/openssl/des.h ../include/openssl/des_old.h
+speed.o: ../include/openssl/dsa.h ../include/openssl/e_os2.h
+speed.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+speed.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
+speed.o: ../include/openssl/err.h ../include/openssl/evp.h
 speed.o: ../include/openssl/hmac.h ../include/openssl/idea.h
-speed.o: ../include/openssl/lhash.h ../include/openssl/md2.h
-speed.o: ../include/openssl/md4.h ../include/openssl/md5.h
+speed.o: ../include/openssl/lhash.h ../include/openssl/md4.h
+speed.o: ../include/openssl/md5.h ../include/openssl/mdc2.h
 speed.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 speed.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
 speed.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
 speed.o: ../include/openssl/pkcs7.h ../include/openssl/rand.h
 speed.o: ../include/openssl/rc2.h ../include/openssl/rc4.h
 speed.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h
-speed.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-speed.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-speed.o: ../include/openssl/txt_db.h ../include/openssl/ui.h
-speed.o: ../include/openssl/ui_compat.h ../include/openssl/x509.h
+speed.o: ../include/openssl/safestack.h ../include/openssl/seed.h
+speed.o: ../include/openssl/sha.h ../include/openssl/stack.h
+speed.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
+speed.o: ../include/openssl/ui.h ../include/openssl/ui_compat.h
+speed.o: ../include/openssl/whrlpool.h ../include/openssl/x509.h
 speed.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
 speed.o: speed.c testdsa.h testrsa.h
 spkac.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
@@ -921,32 +954,50 @@ spkac.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
 spkac.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 spkac.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
 spkac.o: ../include/openssl/err.h ../include/openssl/evp.h
-spkac.o: ../include/openssl/fips.h ../include/openssl/lhash.h
-spkac.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
-spkac.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
-spkac.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-spkac.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-spkac.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
-spkac.o: ../include/openssl/sha.h ../include/openssl/stack.h
-spkac.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
-spkac.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-spkac.o: ../include/openssl/x509v3.h apps.h spkac.c
+spkac.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+spkac.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
+spkac.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+spkac.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+spkac.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
+spkac.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+spkac.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+spkac.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+spkac.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
+spkac.o: spkac.c
+ts.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
+ts.o: ../include/openssl/bn.h ../include/openssl/buffer.h
+ts.o: ../include/openssl/conf.h ../include/openssl/crypto.h
+ts.o: ../include/openssl/dh.h ../include/openssl/dsa.h
+ts.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
+ts.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
+ts.o: ../include/openssl/engine.h ../include/openssl/err.h
+ts.o: ../include/openssl/evp.h ../include/openssl/lhash.h
+ts.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+ts.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
+ts.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+ts.o: ../include/openssl/pem.h ../include/openssl/pem2.h
+ts.o: ../include/openssl/pkcs7.h ../include/openssl/rand.h
+ts.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+ts.o: ../include/openssl/sha.h ../include/openssl/stack.h
+ts.o: ../include/openssl/symhacks.h ../include/openssl/ts.h
+ts.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+ts.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h ts.c
 verify.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 verify.o: ../include/openssl/buffer.h ../include/openssl/conf.h
 verify.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
 verify.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 verify.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
 verify.o: ../include/openssl/err.h ../include/openssl/evp.h
-verify.o: ../include/openssl/fips.h ../include/openssl/lhash.h
-verify.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
-verify.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
-verify.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-verify.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-verify.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
-verify.o: ../include/openssl/sha.h ../include/openssl/stack.h
-verify.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
-verify.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-verify.o: ../include/openssl/x509v3.h apps.h verify.c
+verify.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+verify.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
+verify.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+verify.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+verify.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
+verify.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+verify.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+verify.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
+verify.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
+verify.o: verify.c
 version.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 version.o: ../include/openssl/blowfish.h ../include/openssl/bn.h
 version.o: ../include/openssl/buffer.h ../include/openssl/conf.h
@@ -954,9 +1005,8 @@ version.o: ../include/openssl/crypto.h ../include/openssl/des.h
 version.o: ../include/openssl/des_old.h ../include/openssl/e_os2.h
 version.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 version.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
-version.o: ../include/openssl/evp.h ../include/openssl/fips.h
-version.o: ../include/openssl/idea.h ../include/openssl/lhash.h
-version.o: ../include/openssl/md2.h ../include/openssl/obj_mac.h
+version.o: ../include/openssl/evp.h ../include/openssl/idea.h
+version.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
 version.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
 version.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 version.o: ../include/openssl/ossl_typ.h ../include/openssl/pkcs7.h
@@ -973,13 +1023,13 @@ x509.o: ../include/openssl/dsa.h ../include/openssl/e_os2.h
 x509.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 x509.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
 x509.o: ../include/openssl/err.h ../include/openssl/evp.h
-x509.o: ../include/openssl/fips.h ../include/openssl/lhash.h
-x509.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
-x509.o: ../include/openssl/ocsp.h ../include/openssl/opensslconf.h
-x509.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-x509.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-x509.o: ../include/openssl/pkcs7.h ../include/openssl/rsa.h
-x509.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-x509.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-x509.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
-x509.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h x509.c
+x509.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+x509.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
+x509.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+x509.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+x509.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
+x509.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+x509.o: ../include/openssl/sha.h ../include/openssl/stack.h
+x509.o: ../include/openssl/symhacks.h ../include/openssl/txt_db.h
+x509.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
+x509.o: ../include/openssl/x509v3.h apps.h x509.c
index fab49c4..38e6197 100644 (file)
  *
  */
 
+#ifndef _POSIX_C_SOURCE
+#define _POSIX_C_SOURCE 2      /* On VMS, you need to define this to get
+                                  the declaration of fileno().  The value
+                                  2 is to make sure no function defined
+                                  in POSIX-2 is left undefined. */
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#if !defined(OPENSSL_SYSNAME_WIN32) && !defined(NETWARE_CLIB)
+#include <strings.h>
+#endif
 #include <sys/types.h>
-#include <sys/stat.h>
 #include <ctype.h>
+#include <errno.h>
 #include <assert.h>
 #include <openssl/err.h>
 #include <openssl/x509.h>
 #include "apps.h"
 #undef NON_MAIN
 
+#ifdef _WIN32
+static int WIN32_rename(const char *from, const char *to);
+#define rename(from,to) WIN32_rename((from),(to))
+#endif
+
 typedef struct {
        const char *name;
        unsigned long flag;
@@ -166,18 +180,23 @@ int args_from_file(char *file, int *argc, char **argv[])
        static char *buf=NULL;
        static char **arg=NULL;
        char *p;
-       struct stat stbuf;
-
-       if (stat(file,&stbuf) < 0) return(0);
 
        fp=fopen(file,"r");
        if (fp == NULL)
                return(0);
 
+       if (fseek(fp,0,SEEK_END)==0)
+               len=ftell(fp), rewind(fp);
+       else    len=-1;
+       if (len<=0)
+               {
+               fclose(fp);
+               return(0);
+               }
+
        *argc=0;
        *argv=NULL;
 
-       len=(unsigned int)stbuf.st_size;
        if (buf != NULL) OPENSSL_free(buf);
        buf=(char *)OPENSSL_malloc(len+1);
        if (buf == NULL) return(0);
@@ -238,22 +257,31 @@ int args_from_file(char *file, int *argc, char **argv[])
 
 int str2fmt(char *s)
        {
+       if (s == NULL)
+               return FORMAT_UNDEF;
        if      ((*s == 'D') || (*s == 'd'))
                return(FORMAT_ASN1);
        else if ((*s == 'T') || (*s == 't'))
                return(FORMAT_TEXT);
-       else if ((*s == 'P') || (*s == 'p'))
-               return(FORMAT_PEM);
-       else if ((*s == 'N') || (*s == 'n'))
-               return(FORMAT_NETSCAPE);
-       else if ((*s == 'S') || (*s == 's'))
-               return(FORMAT_SMIME);
+       else if ((*s == 'N') || (*s == 'n'))
+               return(FORMAT_NETSCAPE);
+       else if ((*s == 'S') || (*s == 's'))
+               return(FORMAT_SMIME);
+       else if ((*s == 'M') || (*s == 'm'))
+               return(FORMAT_MSBLOB);
        else if ((*s == '1')
                || (strcmp(s,"PKCS12") == 0) || (strcmp(s,"pkcs12") == 0)
                || (strcmp(s,"P12") == 0) || (strcmp(s,"p12") == 0))
                return(FORMAT_PKCS12);
        else if ((*s == 'E') || (*s == 'e'))
                return(FORMAT_ENGINE);
+       else if ((*s == 'P') || (*s == 'p'))
+               {
+               if (s[1] == 'V' || s[1] == 'v')
+                       return FORMAT_PVK;
+               else
+                       return(FORMAT_PEM);
+               }
        else
                return(FORMAT_UNDEF);
        }
@@ -638,6 +666,15 @@ static char *app_get_pass(BIO *err, char *arg, int keepbio)
                                BIO_printf(err, "Can't open file %s\n", arg + 5);
                                return NULL;
                        }
+#if !defined(_WIN32)
+               /*
+                * Under _WIN32, which covers even Win64 and CE, file
+                * descriptors referenced by BIO_s_fd are not inherited
+                * by child process and therefore below is not an option.
+                * It could have been an option if bss_fd.c was operating
+                * on real Windows descriptors, such as those obtained
+                * with CreateFile.
+                */
                } else if(!strncmp(arg, "fd:", 3)) {
                        BIO *btmp;
                        i = atoi(arg + 3);
@@ -649,6 +686,7 @@ static char *app_get_pass(BIO *err, char *arg, int keepbio)
                        /* Can't do BIO_gets on an fd BIO so add a buffering BIO */
                        btmp = BIO_new(BIO_f_buffer());
                        pwdbio = BIO_push(btmp, pwdbio);
+#endif
                } else if(!strcmp(arg, "stdin")) {
                        pwdbio = BIO_new_fp(stdin, BIO_NOCLOSE);
                        if(!pwdbio) {
@@ -748,8 +786,6 @@ static int load_pkcs12(BIO *err, BIO *in, const char *desc,
 X509 *load_cert(BIO *err, const char *file, int format,
        const char *pass, ENGINE *e, const char *cert_descrip)
        {
-       ASN1_HEADER *ah=NULL;
-       BUF_MEM *buf=NULL;
        X509 *x=NULL;
        BIO *cert;
 
@@ -761,7 +797,11 @@ X509 *load_cert(BIO *err, const char *file, int format,
 
        if (file == NULL)
                {
+#ifdef _IONBF
+# ifndef OPENSSL_NO_SETVBUF_IONBF
                setvbuf(stdin, NULL, _IONBF, 0);
+# endif /* ndef OPENSSL_NO_SETVBUF_IONBF */
+#endif
                BIO_set_fp(cert,stdin,BIO_NOCLOSE);
                }
        else
@@ -779,46 +819,21 @@ X509 *load_cert(BIO *err, const char *file, int format,
                x=d2i_X509_bio(cert,NULL);
        else if (format == FORMAT_NETSCAPE)
                {
-               const unsigned char *p,*op;
-               int size=0,i;
-
-               /* We sort of have to do it this way because it is sort of nice
-                * to read the header first and check it, then
-                * try to read the certificate */
-               buf=BUF_MEM_new();
-               for (;;)
-                       {
-                       if ((buf == NULL) || (!BUF_MEM_grow(buf,size+1024*10)))
-                               goto end;
-                       i=BIO_read(cert,&(buf->data[size]),1024*10);
-                       size+=i;
-                       if (i == 0) break;
-                       if (i < 0)
-                               {
-                               perror("reading certificate");
+               NETSCAPE_X509 *nx;
+               nx=ASN1_item_d2i_bio(ASN1_ITEM_rptr(NETSCAPE_X509),cert,NULL);
+               if (nx == NULL)
                                goto end;
-                               }
-                       }
-               p=(unsigned char *)buf->data;
-               op=p;
 
-               /* First load the header */
-               if ((ah=d2i_ASN1_HEADER(NULL,&p,(long)size)) == NULL)
-                       goto end;
-               if ((ah->header == NULL) || (ah->header->data == NULL) ||
-                       (strncmp(NETSCAPE_CERT_HDR,(char *)ah->header->data,
-                       ah->header->length) != 0))
+               if ((strncmp(NETSCAPE_CERT_HDR,(char *)nx->header->data,
+                       nx->header->length) != 0))
                        {
+                       NETSCAPE_X509_free(nx);
                        BIO_printf(err,"Error reading header on certificate\n");
                        goto end;
                        }
-               /* header is ok, so now read the object */
-               p=op;
-               ah->meth=X509_asn1_meth();
-               if ((ah=d2i_ASN1_HEADER(&ah,&p,(long)size)) == NULL)
-                       goto end;
-               x=(X509 *)ah->data;
-               ah->data=NULL;
+               x=nx->cert;
+               nx->cert = NULL;
+               NETSCAPE_X509_free(nx);
                }
        else if (format == FORMAT_PEM)
                x=PEM_read_bio_X509_AUX(cert,NULL,
@@ -840,9 +855,7 @@ end:
                BIO_printf(err,"unable to load certificate\n");
                ERR_print_errors(err);
                }
-       if (ah != NULL) ASN1_HEADER_free(ah);
        if (cert != NULL) BIO_free(cert);
-       if (buf != NULL) BUF_MEM_free(buf);
        return(x);
        }
 
@@ -887,7 +900,11 @@ EVP_PKEY *load_key(BIO *err, const char *file, int format, int maybe_stdin,
                }
        if (file == NULL && maybe_stdin)
                {
+#ifdef _IONBF
+# ifndef OPENSSL_NO_SETVBUF_IONBF
                setvbuf(stdin, NULL, _IONBF, 0);
+# endif /* ndef OPENSSL_NO_SETVBUF_IONBF */
+#endif
                BIO_set_fp(key,stdin,BIO_NOCLOSE);
                }
        else
@@ -918,6 +935,13 @@ EVP_PKEY *load_key(BIO *err, const char *file, int format, int maybe_stdin,
                                &pkey, NULL, NULL))
                        goto end;
                }
+#if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DSA) && !defined (OPENSSL_NO_RC4)
+       else if (format == FORMAT_MSBLOB)
+               pkey = b2i_PrivateKey_bio(key);
+       else if (format == FORMAT_PVK)
+               pkey = b2i_PVK_bio(key, (pem_password_cb *)password_callback,
+                                                               &cb_data);
+#endif
        else
                {
                BIO_printf(err,"bad input format specified for key file\n");
@@ -967,7 +991,11 @@ EVP_PKEY *load_pubkey(BIO *err, const char *file, int format, int maybe_stdin,
                }
        if (file == NULL && maybe_stdin)
                {
+#ifdef _IONBF
+# ifndef OPENSSL_NO_SETVBUF_IONBF
                setvbuf(stdin, NULL, _IONBF, 0);
+# endif /* ndef OPENSSL_NO_SETVBUF_IONBF */
+#endif
                BIO_set_fp(key,stdin,BIO_NOCLOSE);
                }
        else
@@ -982,6 +1010,37 @@ EVP_PKEY *load_pubkey(BIO *err, const char *file, int format, int maybe_stdin,
                {
                pkey=d2i_PUBKEY_bio(key, NULL);
                }
+#ifndef OPENSSL_NO_RSA
+       else if (format == FORMAT_ASN1RSA)
+               {
+               RSA *rsa;
+               rsa = d2i_RSAPublicKey_bio(key, NULL);
+               if (rsa)
+                       {
+                       pkey = EVP_PKEY_new();
+                       if (pkey)
+                               EVP_PKEY_set1_RSA(pkey, rsa);
+                       RSA_free(rsa);
+                       }
+               else
+                       pkey = NULL;
+               }
+       else if (format == FORMAT_PEMRSA)
+               {
+               RSA *rsa;
+               rsa = PEM_read_bio_RSAPublicKey(key, NULL, 
+                       (pem_password_cb *)password_callback, &cb_data);
+               if (rsa)
+                       {
+                       pkey = EVP_PKEY_new();
+                       if (pkey)
+                               EVP_PKEY_set1_RSA(pkey, rsa);
+                       RSA_free(rsa);
+                       }
+               else
+                       pkey = NULL;
+               }
+#endif
        else if (format == FORMAT_PEM)
                {
                pkey=PEM_read_bio_PUBKEY(key,NULL,
@@ -991,6 +1050,10 @@ EVP_PKEY *load_pubkey(BIO *err, const char *file, int format, int maybe_stdin,
        else if (format == FORMAT_NETSCAPE || format == FORMAT_IISSGC)
                pkey = load_netscape_key(err, key, file, key_descrip, format);
 #endif
+#if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DSA)
+       else if (format == FORMAT_MSBLOB)
+               pkey = b2i_PublicKey_bio(key);
+#endif
        else
                {
                BIO_printf(err,"bad input format specified for key file\n");
@@ -1049,76 +1112,120 @@ error:
        }
 #endif /* ndef OPENSSL_NO_RC4 */
 
-STACK_OF(X509) *load_certs(BIO *err, const char *file, int format,
-       const char *pass, ENGINE *e, const char *cert_descrip)
+static int load_certs_crls(BIO *err, const char *file, int format,
+       const char *pass, ENGINE *e, const char *desc,
+       STACK_OF(X509) **pcerts, STACK_OF(X509_CRL) **pcrls)
        {
-       BIO *certs;
        int i;
-       STACK_OF(X509) *othercerts = NULL;
-       STACK_OF(X509_INFO) *allcerts = NULL;
+       BIO *bio;
+       STACK_OF(X509_INFO) *xis = NULL;
        X509_INFO *xi;
        PW_CB_DATA cb_data;
+       int rv = 0;
 
        cb_data.password = pass;
        cb_data.prompt_info = file;
 
-       if((certs = BIO_new(BIO_s_file())) == NULL)
+       if (format != FORMAT_PEM)
                {
-               ERR_print_errors(err);
-               goto end;
+               BIO_printf(err,"bad input format specified for %s\n", desc);
+               return 0;
                }
 
        if (file == NULL)
-               BIO_set_fp(certs,stdin,BIO_NOCLOSE);
+               bio = BIO_new_fp(stdin,BIO_NOCLOSE);
        else
+               bio = BIO_new_file(file, "r");
+
+       if (bio == NULL)
                {
-               if (BIO_read_filename(certs,file) <= 0)
-                       {
-                       BIO_printf(err, "Error opening %s %s\n",
-                               cert_descrip, file);
-                       ERR_print_errors(err);
+               BIO_printf(err, "Error opening %s %s\n",
+                               desc, file ? file : "stdin");
+               ERR_print_errors(err);
+               return 0;
+               }
+
+       xis = PEM_X509_INFO_read_bio(bio, NULL,
+                               (pem_password_cb *)password_callback, &cb_data);
+
+       BIO_free(bio);
+
+       if (pcerts)
+               {
+               *pcerts = sk_X509_new_null();
+               if (!*pcerts)
                        goto end;
-                       }
                }
 
-       if      (format == FORMAT_PEM)
+       if (pcrls)
                {
-               othercerts = sk_X509_new_null();
-               if(!othercerts)
-                       {
-                       sk_X509_free(othercerts);
-                       othercerts = NULL;
+               *pcrls = sk_X509_CRL_new_null();
+               if (!*pcrls)
                        goto end;
+               }
+
+       for(i = 0; i < sk_X509_INFO_num(xis); i++)
+               {
+               xi = sk_X509_INFO_value (xis, i);
+               if (xi->x509 && pcerts)
+                       {
+                       if (!sk_X509_push(*pcerts, xi->x509))
+                               goto end;
+                       xi->x509 = NULL;
                        }
-               allcerts = PEM_X509_INFO_read_bio(certs, NULL,
-                               (pem_password_cb *)password_callback, &cb_data);
-               for(i = 0; i < sk_X509_INFO_num(allcerts); i++)
+               if (xi->crl && pcrls)
                        {
-                       xi = sk_X509_INFO_value (allcerts, i);
-                       if (xi->x509)
-                               {
-                               sk_X509_push(othercerts, xi->x509);
-                               xi->x509 = NULL;
-                               }
+                       if (!sk_X509_CRL_push(*pcrls, xi->crl))
+                               goto end;
+                       xi->crl = NULL;
                        }
-               goto end;
                }
-       else    {
-               BIO_printf(err,"bad input format specified for %s\n",
-                       cert_descrip);
-               goto end;
-               }
-end:
-       if (othercerts == NULL)
+
+       if (pcerts && sk_X509_num(*pcerts) > 0)
+               rv = 1;
+
+       if (pcrls && sk_X509_CRL_num(*pcrls) > 0)
+               rv = 1;
+
+       end:
+
+       if (xis)
+               sk_X509_INFO_pop_free(xis, X509_INFO_free);
+
+       if (rv == 0)
                {
-               BIO_printf(err,"unable to load certificates\n");
+               if (pcerts)
+                       {
+                       sk_X509_pop_free(*pcerts, X509_free);
+                       *pcerts = NULL;
+                       }
+               if (pcrls)
+                       {
+                       sk_X509_CRL_pop_free(*pcrls, X509_CRL_free);
+                       *pcrls = NULL;
+                       }
+               BIO_printf(err,"unable to load %s\n",
+                               pcerts ? "certificates" : "CRLs");
                ERR_print_errors(err);
                }
-       if (allcerts) sk_X509_INFO_pop_free(allcerts, X509_INFO_free);
-       if (certs != NULL) BIO_free(certs);
-       return(othercerts);
+       return rv;
        }
 
+STACK_OF(X509) *load_certs(BIO *err, const char *file, int format,
+       const char *pass, ENGINE *e, const char *desc)
+       {
+       STACK_OF(X509) *certs;
+       load_certs_crls(err, file, format, pass, e, desc, &certs, NULL);
+       return certs;
+       }       
+
+STACK_OF(X509_CRL) *load_crls(BIO *err, const char *file, int format,
+       const char *pass, ENGINE *e, const char *desc)
+       {
+       STACK_OF(X509_CRL) *crls;
+       load_certs_crls(err, file, format, pass, e, desc, NULL, &crls);
+       return crls;
+       }       
 
 #define X509V3_EXT_UNKNOWN_MASK                (0xfL << 16)
 /* Return error for unknown extensions */
@@ -1405,6 +1512,10 @@ ENGINE *setup_engine(BIO *err, const char *engine, int debug)
 
 int load_config(BIO *err, CONF *cnf)
        {
+       static int load_config_called = 0;
+       if (load_config_called)
+               return 1;
+       load_config_called = 1;
        if (!cnf)
                cnf = config;
        if (!cnf)
@@ -1438,7 +1549,7 @@ char *make_config_name()
        return p;
        }
 
-static unsigned long index_serial_hash(const char **a)
+static unsigned long index_serial_hash(const OPENSSL_CSTRING *a)
        {
        const char *n;
 
@@ -1447,7 +1558,7 @@ static unsigned long index_serial_hash(const char **a)
        return(lh_strhash(n));
        }
 
-static int index_serial_cmp(const char **a, const char **b)
+static int index_serial_cmp(const OPENSSL_CSTRING *a, const OPENSSL_CSTRING *b)
        {
        const char *aa,*bb;
 
@@ -1459,17 +1570,16 @@ static int index_serial_cmp(const char **a, const char **b)
 static int index_name_qual(char **a)
        { return(a[0][0] == 'V'); }
 
-static unsigned long index_name_hash(const char **a)
+static unsigned long index_name_hash(const OPENSSL_CSTRING *a)
        { return(lh_strhash(a[DB_name])); }
 
-int index_name_cmp(const char **a, const char **b)
-       { return(strcmp(a[DB_name],
-            b[DB_name])); }
+int index_name_cmp(const OPENSSL_CSTRING *a, const OPENSSL_CSTRING *b)
+       { return(strcmp(a[DB_name], b[DB_name])); }
 
-static IMPLEMENT_LHASH_HASH_FN(index_serial_hash,const char **)
-static IMPLEMENT_LHASH_COMP_FN(index_serial_cmp,const char **)
-static IMPLEMENT_LHASH_HASH_FN(index_name_hash,const char **)
-static IMPLEMENT_LHASH_COMP_FN(index_name_cmp,const char **)
+static IMPLEMENT_LHASH_HASH_FN(index_serial, OPENSSL_CSTRING)
+static IMPLEMENT_LHASH_COMP_FN(index_serial, OPENSSL_CSTRING)
+static IMPLEMENT_LHASH_HASH_FN(index_name, OPENSSL_CSTRING)
+static IMPLEMENT_LHASH_COMP_FN(index_name, OPENSSL_CSTRING)
 
 #undef BSIZE
 #define BSIZE 256
@@ -1597,7 +1707,6 @@ int rotate_serial(char *serialfile, char *new_suffix, char *old_suffix)
        {
        char buf[5][BSIZE];
        int i,j;
-       struct stat sb;
 
        i = strlen(serialfile) + strlen(old_suffix);
        j = strlen(serialfile) + strlen(new_suffix);
@@ -1622,30 +1731,21 @@ int rotate_serial(char *serialfile, char *new_suffix, char *old_suffix)
        j = BIO_snprintf(buf[1], sizeof buf[1], "%s-%s",
                serialfile, old_suffix);
 #endif
-       if (stat(serialfile,&sb) < 0)
-               {
-               if (errno != ENOENT 
+#ifdef RL_DEBUG
+       BIO_printf(bio_err, "DEBUG: renaming \"%s\" to \"%s\"\n",
+               serialfile, buf[1]);
+#endif
+       if (rename(serialfile,buf[1]) < 0 && errno != ENOENT
 #ifdef ENOTDIR
                        && errno != ENOTDIR
 #endif
-                  )
-                       goto err;
-               }
-       else
-               {
-#ifdef RL_DEBUG
-               BIO_printf(bio_err, "DEBUG: renaming \"%s\" to \"%s\"\n",
-                       serialfile, buf[1]);
-#endif
-               if (rename(serialfile,buf[1]) < 0)
-                       {
+          )            {
                        BIO_printf(bio_err,
                                "unable to rename %s to %s\n",
                                serialfile, buf[1]);
                        perror("reason");
                        goto err;
                        }
-               }
 #ifdef RL_DEBUG
        BIO_printf(bio_err, "DEBUG: renaming \"%s\" to \"%s\"\n",
                buf[0],serialfile);
@@ -1712,10 +1812,7 @@ CA_DB *load_index(char *dbfile, DB_ATTR *db_attr)
                goto err;
                }
        if ((tmpdb = TXT_DB_read(in,DB_NUMBER)) == NULL)
-               {
-               if (tmpdb != NULL) TXT_DB_free(tmpdb);
                goto err;
-               }
 
 #ifndef OPENSSL_SYS_VMS
        BIO_snprintf(buf[0], sizeof buf[0], "%s.attr", dbfile);
@@ -1776,8 +1873,8 @@ CA_DB *load_index(char *dbfile, DB_ATTR *db_attr)
 int index_index(CA_DB *db)
        {
        if (!TXT_DB_create_index(db->db, DB_serial, NULL,
-                               LHASH_HASH_FN(index_serial_hash),
-                               LHASH_COMP_FN(index_serial_cmp)))
+                               LHASH_HASH_FN(index_serial),
+                               LHASH_COMP_FN(index_serial)))
                {
                BIO_printf(bio_err,
                  "error creating serial number index:(%ld,%ld,%ld)\n",
@@ -1787,8 +1884,8 @@ int index_index(CA_DB *db)
 
        if (db->attributes.unique_subject
                && !TXT_DB_create_index(db->db, DB_name, index_name_qual,
-                       LHASH_HASH_FN(index_name_hash),
-                       LHASH_COMP_FN(index_name_cmp)))
+                       LHASH_HASH_FN(index_name),
+                       LHASH_COMP_FN(index_name)))
                {
                BIO_printf(bio_err,"error creating name index:(%ld,%ld,%ld)\n",
                        db->db->error,db->db->arg1,db->db->arg2);
@@ -1868,7 +1965,6 @@ int rotate_index(const char *dbfile, const char *new_suffix, const char *old_suf
        {
        char buf[5][BSIZE];
        int i,j;
-       struct stat sb;
 
        i = strlen(dbfile) + strlen(old_suffix);
        j = strlen(dbfile) + strlen(new_suffix);
@@ -1912,30 +2008,21 @@ int rotate_index(const char *dbfile, const char *new_suffix, const char *old_suf
        j = BIO_snprintf(buf[3], sizeof buf[3], "%s-attr-%s",
                dbfile, old_suffix);
 #endif
-       if (stat(dbfile,&sb) < 0)
-               {
-               if (errno != ENOENT 
-#ifdef ENOTDIR
-                       && errno != ENOTDIR
-#endif
-                  )
-                       goto err;
-               }
-       else
-               {
 #ifdef RL_DEBUG
-               BIO_printf(bio_err, "DEBUG: renaming \"%s\" to \"%s\"\n",
-                       dbfile, buf[1]);
+       BIO_printf(bio_err, "DEBUG: renaming \"%s\" to \"%s\"\n",
+               dbfile, buf[1]);
 #endif
-               if (rename(dbfile,buf[1]) < 0)
-                       {
+       if (rename(dbfile,buf[1]) < 0 && errno != ENOENT
+#ifdef ENOTDIR
+               && errno != ENOTDIR
+#endif
+          )            {
                        BIO_printf(bio_err,
                                "unable to rename %s to %s\n",
                                dbfile, buf[1]);
                        perror("reason");
                        goto err;
                        }
-               }
 #ifdef RL_DEBUG
        BIO_printf(bio_err, "DEBUG: renaming \"%s\" to \"%s\"\n",
                buf[0],dbfile);
@@ -1949,23 +2036,15 @@ int rotate_index(const char *dbfile, const char *new_suffix, const char *old_suf
                rename(buf[1],dbfile);
                goto err;
                }
-       if (stat(buf[4],&sb) < 0)
-               {
-               if (errno != ENOENT 
-#ifdef ENOTDIR
-                       && errno != ENOTDIR
-#endif
-                  )
-                       goto err;
-               }
-       else
-               {
 #ifdef RL_DEBUG
-               BIO_printf(bio_err, "DEBUG: renaming \"%s\" to \"%s\"\n",
-                       buf[4],buf[3]);
+       BIO_printf(bio_err, "DEBUG: renaming \"%s\" to \"%s\"\n",
+               buf[4],buf[3]);
 #endif
-               if (rename(buf[4],buf[3]) < 0)
-                       {
+       if (rename(buf[4],buf[3]) < 0 && errno != ENOENT
+#ifdef ENOTDIR
+               && errno != ENOTDIR
+#endif
+          )            {
                        BIO_printf(bio_err,
                                "unable to rename %s to %s\n",
                                buf[4], buf[3]);
@@ -1974,7 +2053,6 @@ int rotate_index(const char *dbfile, const char *new_suffix, const char *old_suf
                        rename(buf[1],dbfile);
                        goto err;
                        }
-               }
 #ifdef RL_DEBUG
        BIO_printf(bio_err, "DEBUG: renaming \"%s\" to \"%s\"\n",
                buf[2],buf[4]);
@@ -2169,52 +2247,13 @@ error:
        return NULL;
 }
 
-/* This code MUST COME AFTER anything that uses rename() */
-#ifdef OPENSSL_SYS_WIN32
-int WIN32_rename(const char *from, const char *to)
-       {
-#ifndef OPENSSL_SYS_WINCE
-       /* Windows rename gives an error if 'to' exists, so delete it
-        * first and ignore file not found errror
-        */
-       if((remove(to) != 0) && (errno != ENOENT))
-               return -1;
-#undef rename
-       return rename(from, to);
-#else
-       /* convert strings to UNICODE */
-       {
-       BOOL result = FALSE;
-       WCHAR* wfrom;
-       WCHAR* wto;
-       int i;
-       wfrom = malloc((strlen(from)+1)*2);
-       wto = malloc((strlen(to)+1)*2);
-       if (wfrom != NULL && wto != NULL)
-               {
-               for (i=0; i<(int)strlen(from)+1; i++)
-                       wfrom[i] = (short)from[i];
-               for (i=0; i<(int)strlen(to)+1; i++)
-                       wto[i] = (short)to[i];
-               result = MoveFile(wfrom, wto);
-               }
-       if (wfrom != NULL)
-               free(wfrom);
-       if (wto != NULL)
-               free(wto);
-       return result;
-       }
-#endif
-       }
-#endif
-
 int args_verify(char ***pargs, int *pargc,
                        int *badarg, BIO *err, X509_VERIFY_PARAM **pm)
        {
        ASN1_OBJECT *otmp = NULL;
        unsigned long flags = 0;
        int i;
-       int purpose = 0;
+       int purpose = 0, depth = -1;
        char **oldargs = *pargs;
        char *arg = **pargs, *argn = (*pargs)[1];
        if (!strcmp(arg, "-policy"))
@@ -2254,6 +2293,21 @@ int args_verify(char ***pargs, int *pargc,
                        }
                (*pargs)++;
                }
+       else if (strcmp(arg,"-verify_depth") == 0)
+               {
+               if (!argn)
+                       *badarg = 1;
+               else
+                       {
+                       depth = atoi(argn);
+                       if(depth < 0)
+                               {
+                               BIO_printf(err, "invalid depth\n");
+                               *badarg = 1;
+                               }
+                       }
+               (*pargs)++;
+               }
        else if (!strcmp(arg, "-ignore_critical"))
                flags |= X509_V_FLAG_IGNORE_CRITICAL;
        else if (!strcmp(arg, "-issuer_checks"))
@@ -2266,8 +2320,16 @@ int args_verify(char ***pargs, int *pargc,
                flags |= X509_V_FLAG_POLICY_CHECK;
        else if (!strcmp(arg, "-explicit_policy"))
                flags |= X509_V_FLAG_EXPLICIT_POLICY;
+       else if (!strcmp(arg, "-inhibit_any"))
+               flags |= X509_V_FLAG_INHIBIT_ANY;
+       else if (!strcmp(arg, "-inhibit_map"))
+               flags |= X509_V_FLAG_INHIBIT_MAP;
        else if (!strcmp(arg, "-x509_strict"))
                flags |= X509_V_FLAG_X509_STRICT;
+       else if (!strcmp(arg, "-extended_crl"))
+               flags |= X509_V_FLAG_EXTENDED_CRL_SUPPORT;
+       else if (!strcmp(arg, "-use_deltas"))
+               flags |= X509_V_FLAG_USE_DELTAS;
        else if (!strcmp(arg, "-policy_print"))
                flags |= X509_V_FLAG_NOTIFY_POLICY;
        else if (!strcmp(arg, "-check_ss_sig"))
@@ -2297,6 +2359,9 @@ int args_verify(char ***pargs, int *pargc,
        if (purpose)
                X509_VERIFY_PARAM_set_purpose(*pm, purpose);
 
+       if (depth >= 0)
+               X509_VERIFY_PARAM_set_depth(*pm, depth);
+
        end:
 
        (*pargs)++;
@@ -2308,6 +2373,61 @@ int args_verify(char ***pargs, int *pargc,
 
        }
 
+/* Read whole contents of a BIO into an allocated memory buffer and
+ * return it.
+ */
+
+int bio_to_mem(unsigned char **out, int maxlen, BIO *in)
+       {
+       BIO *mem;
+       int len, ret;
+       unsigned char tbuf[1024];
+       mem = BIO_new(BIO_s_mem());
+       if (!mem)
+               return -1;
+       for(;;)
+               {
+               if ((maxlen != -1) && maxlen < 1024)
+                       len = maxlen;
+               else
+                       len = 1024;
+               len = BIO_read(in, tbuf, len);
+               if (len <= 0)
+                       break;
+               if (BIO_write(mem, tbuf, len) != len)
+                       {
+                       BIO_free(mem);
+                       return -1;
+                       }
+               maxlen -= len;
+
+               if (maxlen == 0)
+                       break;
+               }
+       ret = BIO_get_mem_data(mem, (char **)out);
+       BIO_set_flags(mem, BIO_FLAGS_MEM_RDONLY);
+       BIO_free(mem);
+       return ret;
+       }
+
+int pkey_ctrl_string(EVP_PKEY_CTX *ctx, char *value)
+       {
+       int rv;
+       char *stmp, *vtmp = NULL;
+       stmp = BUF_strdup(value);
+       if (!stmp)
+               return -1;
+       vtmp = strchr(stmp, ':');
+       if (vtmp)
+               {
+               *vtmp = 0;
+               vtmp++;
+               }
+       rv = EVP_PKEY_CTX_ctrl_str(ctx, stmp, vtmp);
+       OPENSSL_free(stmp);
+       return rv;
+       }
+
 static void nodes_print(BIO *out, const char *name,
        STACK_OF(X509_POLICY_NODE) *nodes)
        {
@@ -2349,7 +2469,7 @@ void policies_print(BIO *out, X509_STORE_CTX *ctx)
                BIO_free(out);
        }
 
-#ifndef OPENSSL_NO_JPAKE
+#if !defined(OPENSSL_NO_JPAKE) && !defined(OPENSSL_NO_PSK)
 
 static JPAKE_CTX *jpake_init(const char *us, const char *them,
                                                         const char *secret)
@@ -2532,17 +2652,14 @@ void jpake_client_auth(BIO *out, BIO *conn, const char *secret)
        jpake_send_step3a(bconn, ctx);
        jpake_receive_step3b(ctx, bconn);
 
-       /*
-        * The problem is that you must use the derived key in the
-        * session key or you are subject to man-in-the-middle
-        * attacks.
-        */
-       BIO_puts(out, "JPAKE authentication succeeded (N.B. This version can"
-                " be MitMed. See the version in HEAD for how to do it"
-                " properly)\n");
+       BIO_puts(out, "JPAKE authentication succeeded, setting PSK\n");
+
+       psk_key = BN_bn2hex(JPAKE_get_shared_key(ctx));
 
        BIO_pop(bconn);
        BIO_free(bconn);
+
+       JPAKE_CTX_free(ctx);
        }
 
 void jpake_server_auth(BIO *out, BIO *conn, const char *secret)
@@ -2564,28 +2681,351 @@ void jpake_server_auth(BIO *out, BIO *conn, const char *secret)
        jpake_receive_step3a(ctx, bconn);
        jpake_send_step3b(bconn, ctx);
 
-       /*
-        * The problem is that you must use the derived key in the
-        * session key or you are subject to man-in-the-middle
-        * attacks.
-        */
-       BIO_puts(out, "JPAKE authentication succeeded (N.B. This version can"
-                " be MitMed. See the version in HEAD for how to do it"
-                " properly)\n");
+       BIO_puts(out, "JPAKE authentication succeeded, setting PSK\n");
+
+       psk_key = BN_bn2hex(JPAKE_get_shared_key(ctx));
 
        BIO_pop(bconn);
        BIO_free(bconn);
+
+       JPAKE_CTX_free(ctx);
+       }
+
+#endif
+
+/*
+ * Platform-specific sections
+ */
+#if defined(_WIN32)
+# ifdef fileno
+#  undef fileno
+#  define fileno(a) (int)_fileno(a)
+# endif
+
+# include <windows.h>
+# include <tchar.h>
+
+static int WIN32_rename(const char *from, const char *to)
+       {
+       TCHAR  *tfrom=NULL,*tto;
+       DWORD   err;
+       int     ret=0;
+
+       if (sizeof(TCHAR) == 1)
+               {
+               tfrom = (TCHAR *)from;
+               tto   = (TCHAR *)to;
+               }
+       else    /* UNICODE path */
+               {
+               size_t i,flen=strlen(from)+1,tlen=strlen(to)+1;
+               tfrom = (TCHAR *)malloc(sizeof(TCHAR)*(flen+tlen));
+               if (tfrom==NULL) goto err;
+               tto=tfrom+flen;
+#if !defined(_WIN32_WCE) || _WIN32_WCE>=101
+               if (!MultiByteToWideChar(CP_ACP,0,from,flen,(WCHAR *)tfrom,flen))
+#endif
+                       for (i=0;i<flen;i++)    tfrom[i]=(TCHAR)from[i];
+#if !defined(_WIN32_WCE) || _WIN32_WCE>=101
+               if (!MultiByteToWideChar(CP_ACP,0,to,  tlen,(WCHAR *)tto,  tlen))
+#endif
+                       for (i=0;i<tlen;i++)    tto[i]  =(TCHAR)to[i];
+               }
+
+       if (MoveFile(tfrom,tto))        goto ok;
+       err=GetLastError();
+       if (err==ERROR_ALREADY_EXISTS || err==ERROR_FILE_EXISTS)
+               {
+               if (DeleteFile(tto) && MoveFile(tfrom,tto))
+                       goto ok;
+               err=GetLastError();
+               }
+       if (err==ERROR_FILE_NOT_FOUND || err==ERROR_PATH_NOT_FOUND)
+               errno = ENOENT;
+       else if (err==ERROR_ACCESS_DENIED)
+               errno = EACCES;
+       else
+               errno = EINVAL; /* we could map more codes... */
+err:
+       ret=-1;
+ok:
+       if (tfrom!=NULL && tfrom!=(TCHAR *)from)        free(tfrom);
+       return ret;
+       }
+#endif
+
+/* app_tminterval section */
+#if defined(_WIN32)
+double app_tminterval(int stop,int usertime)
+       {
+       FILETIME                now;
+       double                  ret=0;
+       static ULARGE_INTEGER   tmstart;
+       static int              warning=1;
+#ifdef _WIN32_WINNT
+       static HANDLE           proc=NULL;
+
+       if (proc==NULL)
+               {
+               if (GetVersion() < 0x80000000)
+                       proc = OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,
+                                               GetCurrentProcessId());
+               if (proc==NULL) proc = (HANDLE)-1;
+               }
+
+       if (usertime && proc!=(HANDLE)-1)
+               {
+               FILETIME junk;
+               GetProcessTimes(proc,&junk,&junk,&junk,&now);
+               }
+       else
+#endif
+               {
+               SYSTEMTIME systime;
+
+               if (usertime && warning)
+                       {
+                       BIO_printf(bio_err,"To get meaningful results, run "
+                                          "this program on idle system.\n");
+                       warning=0;
+                       }
+               GetSystemTime(&systime);
+               SystemTimeToFileTime(&systime,&now);
+               }
+
+       if (stop==TM_START)
+               {
+               tmstart.u.LowPart  = now.dwLowDateTime;
+               tmstart.u.HighPart = now.dwHighDateTime;
+               }
+       else    {
+               ULARGE_INTEGER tmstop;
+
+               tmstop.u.LowPart   = now.dwLowDateTime;
+               tmstop.u.HighPart  = now.dwHighDateTime;
+
+               ret = (__int64)(tmstop.QuadPart - tmstart.QuadPart)*1e-7;
+               }
+
+       return (ret);
        }
 
+#elif defined(OPENSSL_SYS_NETWARE)
+#include <time.h>
+
+double app_tminterval(int stop,int usertime)
+       {
+       double          ret=0;
+       static clock_t  tmstart;
+       static int      warning=1;
+
+       if (usertime && warning)
+               {
+               BIO_printf(bio_err,"To get meaningful results, run "
+                                  "this program on idle system.\n");
+               warning=0;
+               }
+
+       if (stop==TM_START)     tmstart = clock();
+       else                    ret     = (clock()-tmstart)/(double)CLOCKS_PER_SEC;
+
+       return (ret);
+       }
+
+#elif defined(OPENSSL_SYSTEM_VXWORKS)
+#include <time.h>
+
+double app_tminterval(int stop,int usertime)
+       {
+       double ret=0;
+#ifdef CLOCK_REALTIME
+       static struct timespec  tmstart;
+       struct timespec         now;
+#else
+       static unsigned long    tmstart;
+       unsigned long           now;
+#endif
+       static int warning=1;
+
+       if (usertime && warning)
+               {
+               BIO_printf(bio_err,"To get meaningful results, run "
+                                  "this program on idle system.\n");
+               warning=0;
+               }
+
+#ifdef CLOCK_REALTIME
+       clock_gettime(CLOCK_REALTIME,&now);
+       if (stop==TM_START)     tmstart = now;
+       else    ret = ( (now.tv_sec+now.tv_nsec*1e-9)
+                       - (tmstart.tv_sec+tmstart.tv_nsec*1e-9) );
+#else
+       now = tickGet();
+       if (stop==TM_START)     tmstart = now;
+       else                    ret = (now - tmstart)/(double)sysClkRateGet();
+#endif
+       return (ret);
+       }
+
+#elif defined(OPENSSL_SYSTEM_VMS)
+#include <time.h>
+#include <times.h>
+
+double app_tminterval(int stop,int usertime)
+       {
+       static clock_t  tmstart;
+       double          ret = 0;
+       clock_t         now;
+#ifdef __TMS
+       struct tms      rus;
+
+       now = times(&rus);
+       if (usertime)   now = rus.tms_utime;
+#else
+       if (usertime)
+               now = clock(); /* sum of user and kernel times */
+       else    {
+               struct timeval tv;
+               gettimeofday(&tv,NULL);
+               now = (clock_t)(
+                       (unsigned long long)tv.tv_sec*CLK_TCK +
+                       (unsigned long long)tv.tv_usec*(1000000/CLK_TCK)
+                       );
+               }
+#endif
+       if (stop==TM_START)     tmstart = now;
+       else                    ret = (now - tmstart)/(double)(CLK_TCK);
+
+       return (ret);
+       }
+
+#elif defined(_SC_CLK_TCK)     /* by means of unistd.h */
+#include <sys/times.h>
+
+double app_tminterval(int stop,int usertime)
+       {
+       double          ret = 0;
+       struct tms      rus;
+       clock_t         now = times(&rus);
+       static clock_t  tmstart;
+
+       if (usertime)           now = rus.tms_utime;
+
+       if (stop==TM_START)     tmstart = now;
+       else
+               {
+               long int tck = sysconf(_SC_CLK_TCK);
+               ret = (now - tmstart)/(double)tck;
+               }
+
+       return (ret);
+       }
+
+#else
+#include <sys/time.h>
+#include <sys/resource.h>
+
+double app_tminterval(int stop,int usertime)
+       {
+       double          ret = 0;
+       struct rusage   rus;
+       struct timeval  now;
+       static struct timeval tmstart;
+
+       if (usertime)           getrusage(RUSAGE_SELF,&rus), now = rus.ru_utime;
+       else                    gettimeofday(&now,NULL);
+
+       if (stop==TM_START)     tmstart = now;
+       else                    ret = ( (now.tv_sec+now.tv_usec*1e-6)
+                                       - (tmstart.tv_sec+tmstart.tv_usec*1e-6) );
+
+       return ret;
+       }
+#endif
+
+/* app_isdir section */
+#ifdef _WIN32
+int app_isdir(const char *name)
+       {
+       HANDLE          hList;
+       WIN32_FIND_DATA FileData;
+#if defined(UNICODE) || defined(_UNICODE)
+       size_t i, len_0 = strlen(name)+1;
+
+       if (len_0 > sizeof(FileData.cFileName)/sizeof(FileData.cFileName[0]))
+               return -1;
+
+#if !defined(_WIN32_WCE) || _WIN32_WCE>=101
+       if (!MultiByteToWideChar(CP_ACP,0,name,len_0,FileData.cFileName,len_0))
+#endif
+               for (i=0;i<len_0;i++)
+                       FileData.cFileName[i] = (WCHAR)name[i];
+
+       hList = FindFirstFile(FileData.cFileName,&FileData);
+#else
+       hList = FindFirstFile(name,&FileData);
+#endif
+       if (hList == INVALID_HANDLE_VALUE)      return -1;
+       FindClose(hList);
+       return ((FileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)!=0);
+       }
+#else
+#include <sys/stat.h>
+#ifndef S_ISDIR
+# if defined(_S_IFMT) && defined(_S_IFDIR)
+#  define S_ISDIR(a)   (((a) & _S_IFMT) == _S_IFDIR)
+# else 
+#  define S_ISDIR(a)   (((a) & S_IFMT) == S_IFDIR)
+# endif 
+#endif 
+
+int app_isdir(const char *name)
+       {
+#if defined(S_ISDIR)
+       struct stat st;
+
+       if (stat(name,&st)==0)  return S_ISDIR(st.st_mode);
+       else                    return -1;
+#else
+       return -1;
+#endif
+       }
+#endif
+
+/* raw_read|write section */
+#if defined(_WIN32) && defined(STD_INPUT_HANDLE)
+int raw_read_stdin(void *buf,int siz)
+       {
+       DWORD n;
+       if (ReadFile(GetStdHandle(STD_INPUT_HANDLE),buf,siz,&n,NULL))
+               return (n);
+       else    return (-1);
+       }
+#else
+int raw_read_stdin(void *buf,int siz)
+       {       return read(fileno(stdin),buf,siz);     }
+#endif
+
+#if defined(_WIN32) && defined(STD_OUTPUT_HANDLE)
+int raw_write_stdout(const void *buf,int siz)
+       {
+       DWORD n;
+       if (WriteFile(GetStdHandle(STD_OUTPUT_HANDLE),buf,siz,&n,NULL))
+               return (n);
+       else    return (-1);
+       }
+#else
+int raw_write_stdout(const void *buf,int siz)
+       {       return write(fileno(stdout),buf,siz);   }
 #endif
 
+#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
 /* next_protos_parse parses a comma separated list of strings into a string
  * in a format suitable for passing to SSL_CTX_set_next_protos_advertised.
  *   outlen: (output) set to the length of the resulting buffer on success.
- *   err: (maybe NULL) on failure, an error message line is written to this BIO.
  *   in: a NUL termianted string like "abc,def,ghi"
  *
- *   returns: a malloced buffer
+ *   returns: a malloced buffer or NULL on failure.
  */
 unsigned char *next_protos_parse(unsigned short *outlen, const char *in)
        {
@@ -2594,7 +3034,7 @@ unsigned char *next_protos_parse(unsigned short *outlen, const char *in)
        size_t i, start = 0;
 
        len = strlen(in);
-       if (len > 65535)
+       if (len >= 65535)
                return NULL;
 
        out = OPENSSL_malloc(strlen(in) + 1);
@@ -2620,3 +3060,4 @@ unsigned char *next_protos_parse(unsigned short *outlen, const char *in)
        *outlen = len + 1;
        return out;
        }
+#endif  /* !OPENSSL_NO_TLSEXT && !OPENSSL_NO_NEXTPROTONEG */
index 8857909..42072ec 100644 (file)
@@ -137,11 +137,6 @@ long app_RAND_load_files(char *file); /* `file' is a list of files to read,
                                        * (see e_os.h).  The string is
                                        * destroyed! */
 
-#ifdef OPENSSL_SYS_WIN32
-#define rename(from,to) WIN32_rename((from),(to))
-int WIN32_rename(const char *oldname,const char *newname);
-#endif
-
 #ifndef MONOLITH
 
 #define MAIN(a,v)      main(a,v)
@@ -149,11 +144,9 @@ int WIN32_rename(const char *oldname,const char *newname);
 #ifndef NON_MAIN
 CONF *config=NULL;
 BIO *bio_err=NULL;
-int in_FIPS_mode=0;
 #else
 extern CONF *config;
 extern BIO *bio_err;
-extern int in_FIPS_mode;
 #endif
 
 #else
@@ -162,7 +155,6 @@ extern int in_FIPS_mode;
 extern CONF *config;
 extern char *default_config_file;
 extern BIO *bio_err;
-extern int in_FIPS_mode;
 
 #endif
 
@@ -176,61 +168,37 @@ extern int in_FIPS_mode;
 #define do_pipe_sig()
 #endif
 
+#ifdef OPENSSL_NO_COMP
+#define zlib_cleanup() 
+#else
+#define zlib_cleanup() COMP_zlib_cleanup()
+#endif
+
 #if defined(MONOLITH) && !defined(OPENSSL_C)
 #  define apps_startup() \
                do_pipe_sig()
 #  define apps_shutdown()
 #else
 #  ifndef OPENSSL_NO_ENGINE
-#    if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WIN16) || \
-     defined(OPENSSL_SYS_WIN32)
-#      ifdef _O_BINARY
-#        define apps_startup() \
-                       do { _fmode=_O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \
+#    define apps_startup() \
+                       do { do_pipe_sig(); CRYPTO_malloc_init(); \
                        ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \
                        ENGINE_load_builtin_engines(); setup_ui_method(); } while(0)
-#      else
-#        define apps_startup() \
-                       do { _fmode=O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \
-                       ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \
-                       ENGINE_load_builtin_engines(); setup_ui_method(); } while(0)
-#      endif
-#    else
-#      define apps_startup() \
-                       do { do_pipe_sig(); OpenSSL_add_all_algorithms(); \
-                       ERR_load_crypto_strings(); ENGINE_load_builtin_engines(); \
-                       setup_ui_method(); } while(0)
-#    endif
 #    define apps_shutdown() \
                        do { CONF_modules_unload(1); destroy_ui_method(); \
-                       EVP_cleanup(); ENGINE_cleanup(); \
-                       CRYPTO_cleanup_all_ex_data(); ERR_remove_state(0); \
-                       ERR_free_strings(); } while(0)
+                       OBJ_cleanup(); EVP_cleanup(); ENGINE_cleanup(); \
+                       CRYPTO_cleanup_all_ex_data(); ERR_remove_thread_state(NULL); \
+                       ERR_free_strings(); zlib_cleanup();} while(0)
 #  else
-#    if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WIN16) || \
-     defined(OPENSSL_SYS_WIN32)
-#      ifdef _O_BINARY
-#        define apps_startup() \
-                       do { _fmode=_O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \
+#    define apps_startup() \
+                       do { do_pipe_sig(); CRYPTO_malloc_init(); \
                        ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \
                        setup_ui_method(); } while(0)
-#      else
-#        define apps_startup() \
-                       do { _fmode=O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \
-                       ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \
-                       setup_ui_method(); } while(0)
-#      endif
-#    else
-#      define apps_startup() \
-                       do { do_pipe_sig(); OpenSSL_add_all_algorithms(); \
-                       ERR_load_crypto_strings(); \
-                       setup_ui_method(); } while(0)
-#    endif
 #    define apps_shutdown() \
                        do { CONF_modules_unload(1); destroy_ui_method(); \
-                       EVP_cleanup(); \
-                       CRYPTO_cleanup_all_ex_data(); ERR_remove_state(0); \
-                       ERR_free_strings(); } while(0)
+                       OBJ_cleanup(); EVP_cleanup(); \
+                       CRYPTO_cleanup_all_ex_data(); ERR_remove_thread_state(NULL); \
+                       ERR_free_strings(); zlib_cleanup(); } while(0)
 #  endif
 #endif
 
@@ -240,6 +208,7 @@ extern int in_FIPS_mode;
 #  define openssl_fdset(a,b) FD_SET(a, b)
 #endif
 
+
 typedef struct args_st
        {
        char **data;
@@ -282,6 +251,8 @@ EVP_PKEY *load_pubkey(BIO *err, const char *file, int format, int maybe_stdin,
        const char *pass, ENGINE *e, const char *key_descrip);
 STACK_OF(X509) *load_certs(BIO *err, const char *file, int format,
        const char *pass, ENGINE *e, const char *cert_descrip);
+STACK_OF(X509_CRL) *load_crls(BIO *err, const char *file, int format,
+       const char *pass, ENGINE *e, const char *cert_descrip);
 X509_STORE *setup_verify(BIO *bp, char *CAfile, char *CApath);
 #ifndef OPENSSL_NO_ENGINE
 ENGINE *setup_engine(BIO *err, const char *engine, int debug);
@@ -290,6 +261,7 @@ ENGINE *setup_engine(BIO *err, const char *engine, int debug);
 #ifndef OPENSSL_NO_OCSP
 OCSP_RESPONSE *process_responder(BIO *err, OCSP_REQUEST *req,
                        char *host, char *path, char *port, int use_ssl,
+                       STACK_OF(CONF_VALUE) *headers,
                        int req_timeout);
 #endif
 
@@ -331,13 +303,23 @@ int index_index(CA_DB *db);
 int save_index(const char *dbfile, const char *suffix, CA_DB *db);
 int rotate_index(const char *dbfile, const char *new_suffix, const char *old_suffix);
 void free_index(CA_DB *db);
-int index_name_cmp(const char **a, const char **b);
+#define index_name_cmp_noconst(a, b) \
+       index_name_cmp((const OPENSSL_CSTRING *)CHECKED_PTR_OF(OPENSSL_STRING, a), \
+       (const OPENSSL_CSTRING *)CHECKED_PTR_OF(OPENSSL_STRING, b))
+int index_name_cmp(const OPENSSL_CSTRING *a, const OPENSSL_CSTRING *b);
 int parse_yesno(const char *str, int def);
 
 X509_NAME *parse_name(char *str, long chtype, int multirdn);
 int args_verify(char ***pargs, int *pargc,
                        int *badarg, BIO *err, X509_VERIFY_PARAM **pm);
 void policies_print(BIO *out, X509_STORE_CTX *ctx);
+int bio_to_mem(unsigned char **out, int maxlen, BIO *in);
+int pkey_ctrl_string(EVP_PKEY_CTX *ctx, char *value);
+int init_gen_str(BIO *err, EVP_PKEY_CTX **pctx,
+                       const char *algname, ENGINE *e, int do_param);
+#ifndef OPENSSL_NO_PSK
+extern char *psk_key;
+#endif
 #ifndef OPENSSL_NO_JPAKE
 void jpake_client_auth(BIO *out, BIO *conn, const char *secret);
 void jpake_server_auth(BIO *out, BIO *conn, const char *secret);
@@ -353,6 +335,10 @@ void jpake_server_auth(BIO *out, BIO *conn, const char *secret);
 #define FORMAT_ENGINE   7
 #define FORMAT_IISSGC  8       /* XXX this stupid macro helps us to avoid
                                 * adding yet another param to load_*key() */
+#define FORMAT_PEMRSA  9       /* PEM RSAPubicKey format */
+#define FORMAT_ASN1RSA 10      /* DER RSAPubicKey format */
+#define FORMAT_MSBLOB  11      /* MS Key blob format */
+#define FORMAT_PVK     12      /* MS PVK file format */
 
 #define EXT_COPY_NONE  0
 #define EXT_COPY_ADD   1
@@ -364,4 +350,15 @@ void jpake_server_auth(BIO *out, BIO *conn, const char *secret);
 
 #define SERIAL_RAND_BITS       64
 
+int app_isdir(const char *);
+int raw_read_stdin(void *,int);
+int raw_write_stdout(const void *,int);
+
+#define TM_START       0
+#define TM_STOP                1
+double app_tminterval (int stop,int usertime);
+#endif
+
+#ifndef OPENSSL_NO_NEXTPROTONEG
+unsigned char *next_protos_parse(unsigned short *outlen, const char *in);
 #endif
index bde61d0..0d66070 100644 (file)
@@ -96,7 +96,7 @@ int MAIN(int argc, char **argv)
        unsigned char *tmpbuf;
        const unsigned char *ctmpbuf;
        BUF_MEM *buf=NULL;
-       STACK *osk=NULL;
+       STACK_OF(OPENSSL_STRING) *osk=NULL;
        ASN1_TYPE *at=NULL;
 
        informat=FORMAT_PEM;
@@ -113,7 +113,7 @@ int MAIN(int argc, char **argv)
        prog=argv[0];
        argc--;
        argv++;
-       if ((osk=sk_new_null()) == NULL)
+       if ((osk=sk_OPENSSL_STRING_new_null()) == NULL)
                {
                BIO_printf(bio_err,"Memory allocation failure\n");
                goto end;
@@ -169,7 +169,7 @@ int MAIN(int argc, char **argv)
                else if (strcmp(*argv,"-strparse") == 0)
                        {
                        if (--argc < 1) goto bad;
-                       sk_push(osk,*(++argv));
+                       sk_OPENSSL_STRING_push(osk,*(++argv));
                        }
                else if (strcmp(*argv,"-genstr") == 0)
                        {
@@ -302,18 +302,18 @@ bad:
 
        /* If any structs to parse go through in sequence */
 
-       if (sk_num(osk))
+       if (sk_OPENSSL_STRING_num(osk))
                {
                tmpbuf=(unsigned char *)str;
                tmplen=num;
-               for (i=0; i<sk_num(osk); i++)
+               for (i=0; i<sk_OPENSSL_STRING_num(osk); i++)
                        {
                        ASN1_TYPE *atmp;
                        int typ;
-                       j=atoi(sk_value(osk,i));
+                       j=atoi(sk_OPENSSL_STRING_value(osk,i));
                        if (j == 0)
                                {
-                               BIO_printf(bio_err,"'%s' is an invalid number\n",sk_value(osk,i));
+                               BIO_printf(bio_err,"'%s' is an invalid number\n",sk_OPENSSL_STRING_value(osk,i));
                                continue;
                                }
                        tmpbuf+=j;
@@ -378,7 +378,7 @@ end:
                ERR_print_errors(bio_err);
        if (buf != NULL) BUF_MEM_free(buf);
        if (at != NULL) ASN1_TYPE_free(at);
-       if (osk != NULL) sk_free(osk);
+       if (osk != NULL) sk_OPENSSL_STRING_free(osk);
        OBJ_cleanup();
        apps_shutdown();
        OPENSSL_EXIT(ret);
@@ -408,6 +408,7 @@ static int do_generate(BIO *bio, char *genstr, char *genconf, BUF_MEM *buf)
 
        atyp = ASN1_generate_nconf(genstr, cnf);
        NCONF_free(cnf);
+       cnf = NULL;
 
        if (!atyp)
                return -1;
index 651c5a6..6b8b0ef 100644 (file)
@@ -63,7 +63,6 @@
 #include <string.h>
 #include <ctype.h>
 #include <sys/types.h>
-#include <sys/stat.h>
 #include <openssl/conf.h>
 #include <openssl/bio.h>
 #include <openssl/err.h>
@@ -83,7 +82,7 @@
 #    else
 #      include <unixlib.h>
 #    endif
-#  elif !defined(OPENSSL_SYS_VXWORKS) && !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_NETWARE) && !defined(__TANDEM)
+#  elif !defined(OPENSSL_SYS_VXWORKS) && !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_NETWARE)
 #    include <sys/file.h>
 #  endif
 #endif
@@ -258,6 +257,7 @@ int MAIN(int argc, char **argv)
        int doupdatedb=0;
        long crldays=0;
        long crlhours=0;
+       long crlsec=0;
        long errorline= -1;
        char *configfile=NULL;
        char *md=NULL;
@@ -305,7 +305,8 @@ int MAIN(int argc, char **argv)
        ASN1_TIME *tmptm;
        ASN1_INTEGER *tmpser;
        char *f;
-       const char *p, **pp;
+       const char *p;
+       char * const *pp;
        int i,j;
        const EVP_MD *dgst=NULL;
        STACK_OF(CONF_VALUE) *attribs=NULL;
@@ -456,6 +457,11 @@ EF_ALIGNMENT=0;
                        if (--argc < 1) goto bad;
                        crlhours= atol(*(++argv));
                        }
+               else if (strcmp(*argv,"-crlsec") == 0)
+                       {
+                       if (--argc < 1) goto bad;
+                       crlsec = atol(*(++argv));
+                       }
                else if (strcmp(*argv,"-infiles") == 0)
                        {
                        argc--;
@@ -549,8 +555,10 @@ bad:
 
        if (badops)
                {
-               for (pp=ca_usage; (*pp != NULL); pp++)
-                       BIO_printf(bio_err,"%s",*pp);
+               const char **pp2;
+
+               for (pp2=ca_usage; (*pp2 != NULL); pp2++)
+                       BIO_printf(bio_err,"%s",*pp2);
                goto err;
                }
 
@@ -825,7 +833,6 @@ bad:
        /* lookup where to write new certificates */
        if ((outdir == NULL) && (req))
                {
-               struct stat sb;
 
                if ((outdir=NCONF_get_string(conf,section,ENV_NEW_CERTS_DIR))
                        == NULL)
@@ -844,28 +851,24 @@ bad:
               that to access().  However, time's too short to do that just
               now.
            */
+#ifndef _WIN32
                if (access(outdir,R_OK|W_OK|X_OK) != 0)
+#else
+               if (_access(outdir,R_OK|W_OK|X_OK) != 0)
+#endif
                        {
                        BIO_printf(bio_err,"I am unable to access the %s directory\n",outdir);
                        perror(outdir);
                        goto err;
                        }
 
-               if (stat(outdir,&sb) != 0)
-                       {
-                       BIO_printf(bio_err,"unable to stat(%s)\n",outdir);
-                       perror(outdir);
-                       goto err;
-                       }
-#ifdef S_ISDIR
-               if (!S_ISDIR(sb.st_mode))
+               if (app_isdir(outdir)<=0)
                        {
                        BIO_printf(bio_err,"%s need to be a directory\n",outdir);
                        perror(outdir);
                        goto err;
                        }
 #endif
-#endif
                }
 
        /*****************************************************************/
@@ -879,9 +882,9 @@ bad:
        if (db == NULL) goto err;
 
        /* Lets check some fields */
-       for (i=0; i<sk_num(db->db->data); i++)
+       for (i=0; i<sk_OPENSSL_PSTRING_num(db->db->data); i++)
                {
-               pp=(const char **)sk_value(db->db->data,i);
+               pp=sk_OPENSSL_PSTRING_value(db->db->data,i);
                if ((pp[DB_type][0] != DB_TYPE_REV) &&
                        (pp[DB_rev_date][0] != '\0'))
                        {
@@ -894,7 +897,7 @@ bad:
                        BIO_printf(bio_err," in entry %d\n", i+1);
                        goto err;
                        }
-               if (!check_time_format(pp[DB_exp_date]))
+               if (!check_time_format((char *)pp[DB_exp_date]))
                        {
                        BIO_printf(bio_err,"entry %d: invalid expiry date\n",i+1);
                        goto err;
@@ -934,7 +937,7 @@ bad:
 #endif
                TXT_DB_write(out,db->db);
                BIO_printf(bio_err,"%d entries loaded from the database\n",
-                       db->db->data->num);
+                          sk_OPENSSL_PSTRING_num(db->db->data));
                BIO_printf(bio_err,"generating index\n");
                }
        
@@ -1025,6 +1028,17 @@ bad:
                goto err;
                }
 
+       if (!strcmp(md, "default"))
+               {
+               int def_nid;
+               if (EVP_PKEY_get_default_digest_nid(pkey, &def_nid) <= 0)
+                       {
+                       BIO_puts(bio_err,"no default digest\n");
+                       goto err;
+                       }
+               md = (char *)OBJ_nid2sn(def_nid);
+               }
+
        if ((dgst=EVP_get_digestbyname(md)) == NULL)
                {
                BIO_printf(bio_err,"%s is an unsupported message digest type\n",md);
@@ -1094,9 +1108,9 @@ bad:
                        if (startdate == NULL)
                                ERR_clear_error();
                        }
-               if (startdate && !ASN1_UTCTIME_set_string(NULL,startdate))
+               if (startdate && !ASN1_TIME_set_string(NULL, startdate))
                        {
-                       BIO_printf(bio_err,"start date is invalid, it should be YYMMDDHHMMSSZ\n");
+                       BIO_printf(bio_err,"start date is invalid, it should be YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ\n");
                        goto err;
                        }
                if (startdate == NULL) startdate="today";
@@ -1108,9 +1122,9 @@ bad:
                        if (enddate == NULL)
                                ERR_clear_error();
                        }
-               if (enddate && !ASN1_UTCTIME_set_string(NULL,enddate))
+               if (enddate && !ASN1_TIME_set_string(NULL, enddate))
                        {
-                       BIO_printf(bio_err,"end date is invalid, it should be YYMMDDHHMMSSZ\n");
+                       BIO_printf(bio_err,"end date is invalid, it should be YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ\n");
                        goto err;
                        }
 
@@ -1370,7 +1384,7 @@ bad:
                                goto err;
                                }
 
-               if (!crldays && !crlhours)
+               if (!crldays && !crlhours && !crlsec)
                        {
                        if (!NCONF_get_number(conf,section,
                                ENV_DEFAULT_CRL_DAYS, &crldays))
@@ -1379,7 +1393,7 @@ bad:
                                ENV_DEFAULT_CRL_HOURS, &crlhours))
                                crlhours = 0;
                        }
-               if ((crldays == 0) && (crlhours == 0))
+               if ((crldays == 0) && (crlhours == 0) && (crlsec == 0))
                        {
                        BIO_printf(bio_err,"cannot lookup how long until the next CRL is issued\n");
                        goto err;
@@ -1393,14 +1407,19 @@ bad:
                if (!tmptm) goto err;
                X509_gmtime_adj(tmptm,0);
                X509_CRL_set_lastUpdate(crl, tmptm);    
-               X509_gmtime_adj(tmptm,(crldays*24+crlhours)*60*60);
+               if (!X509_time_adj_ex(tmptm, crldays, crlhours*60*60 + crlsec,
+                       NULL))
+                       {
+                       BIO_puts(bio_err, "error setting CRL nextUpdate\n");
+                       goto err;
+                       }
                X509_CRL_set_nextUpdate(crl, tmptm);    
 
                ASN1_TIME_free(tmptm);
 
-               for (i=0; i<sk_num(db->db->data); i++)
+               for (i=0; i<sk_OPENSSL_PSTRING_num(db->db->data); i++)
                        {
-                       pp=(const char **)sk_value(db->db->data,i);
+                       pp=sk_OPENSSL_PSTRING_value(db->db->data,i);
                        if (pp[DB_type][0] == DB_TYPE_REV)
                                {
                                if ((r=X509_REVOKED_new()) == NULL) goto err;
@@ -1426,15 +1445,6 @@ bad:
 
                /* we now have a CRL */
                if (verbose) BIO_printf(bio_err,"signing CRL\n");
-#ifndef OPENSSL_NO_DSA
-               if (pkey->type == EVP_PKEY_DSA) 
-                       dgst=EVP_dss1();
-               else
-#endif
-#ifndef OPENSSL_NO_ECDSA
-               if (pkey->type == EVP_PKEY_EC)
-                       dgst=EVP_ecdsa();
-#endif
 
                /* Add any extensions asked for */
 
@@ -1467,6 +1477,12 @@ bad:
                if (crlnumberfile != NULL)      /* we have a CRL number that need updating */
                        if (!save_serial(crlnumberfile,"new",crlnumber,NULL)) goto err;
 
+               if (crlnumber)
+                       {
+                       BN_free(crlnumber);
+                       crlnumber = NULL;
+                       }
+
                if (!X509_CRL_sign(crl,pkey,dgst)) goto err;
 
                PEM_write_bio_X509_CRL(Sout,crl);
@@ -1519,6 +1535,7 @@ err:
        if (free_key && key)
                OPENSSL_free(key);
        BN_free(serial);
+       BN_free(crlnumber);
        free_index(db);
        EVP_PKEY_free(pkey);
        if (x509) X509_free(x509);
@@ -1677,7 +1694,9 @@ static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, const EVP_MD *dgst,
        int ok= -1,i,j,last,nid;
        const char *p;
        CONF_VALUE *cv;
-       char *row[DB_NUMBER],**rrow=NULL,**irow=NULL;
+       OPENSSL_STRING row[DB_NUMBER];
+       OPENSSL_STRING *irow=NULL;
+       OPENSSL_STRING *rrow=NULL;
        char buf[25];
 
        tmptm=ASN1_UTCTIME_new();
@@ -1919,7 +1938,9 @@ again2:
 
        if (db->attributes.unique_subject)
                {
-               rrow=TXT_DB_get_by_index(db->db,DB_name,row);
+               OPENSSL_STRING *crow=row;
+
+               rrow=TXT_DB_get_by_index(db->db,DB_name,crow);
                if (rrow != NULL)
                        {
                        BIO_printf(bio_err,
@@ -1995,11 +2016,11 @@ again2:
 
        if (strcmp(startdate,"today") == 0)
                X509_gmtime_adj(X509_get_notBefore(ret),0);
-       else ASN1_UTCTIME_set_string(X509_get_notBefore(ret),startdate);
+       else ASN1_TIME_set_string(X509_get_notBefore(ret),startdate);
 
        if (enddate == NULL)
-               X509_gmtime_adj(X509_get_notAfter(ret),(long)60*60*24*days);
-       else ASN1_UTCTIME_set_string(X509_get_notAfter(ret),enddate);
+               X509_time_adj_ex(X509_get_notAfter(ret),days, 0, NULL);
+       else ASN1_TIME_set_string(X509_get_notAfter(ret),enddate);
 
        if (!X509_set_subject_name(ret,subject)) goto err;
 
@@ -2119,25 +2140,11 @@ again2:
                        }
                }
 
-
-#ifndef OPENSSL_NO_DSA
-       if (pkey->type == EVP_PKEY_DSA) dgst=EVP_dss1();
        pktmp=X509_get_pubkey(ret);
        if (EVP_PKEY_missing_parameters(pktmp) &&
                !EVP_PKEY_missing_parameters(pkey))
                EVP_PKEY_copy_parameters(pktmp,pkey);
        EVP_PKEY_free(pktmp);
-#endif
-#ifndef OPENSSL_NO_ECDSA
-       if (pkey->type == EVP_PKEY_EC)
-               dgst = EVP_ecdsa();
-       pktmp = X509_get_pubkey(ret);
-       if (EVP_PKEY_missing_parameters(pktmp) &&
-               !EVP_PKEY_missing_parameters(pkey))
-               EVP_PKEY_copy_parameters(pktmp, pkey);
-       EVP_PKEY_free(pktmp);
-#endif
-
 
        if (!X509_sign(ret,pkey,dgst))
                goto err;
@@ -2239,7 +2246,7 @@ static int certify_spkac(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509,
             unsigned long nameopt, int default_op, int ext_copy)
        {
        STACK_OF(CONF_VALUE) *sk=NULL;
-       LHASH *parms=NULL;
+       LHASH_OF(CONF_VALUE) *parms=NULL;
        X509_REQ *req=NULL;
        CONF_VALUE *cv=NULL;
        NETSCAPE_SPKI *spki = NULL;
@@ -2373,15 +2380,7 @@ err:
 
 static int check_time_format(const char *str)
        {
-       ASN1_TIME tm;
-
-       tm.data=(unsigned char *)str;
-       tm.length=strlen(str);
-       tm.type=V_ASN1_UTCTIME;
-       if (ASN1_TIME_check(&tm))
-               return 1;
-       tm.type=V_ASN1_GENERALIZEDTIME;
-       return ASN1_TIME_check(&tm);
+       return ASN1_TIME_set_string(NULL, str);
        }
 
 static int do_revoke(X509 *x509, CA_DB *db, int type, char *value)
@@ -2396,6 +2395,8 @@ static int do_revoke(X509 *x509, CA_DB *db, int type, char *value)
                row[i]=NULL;
        row[DB_name]=X509_NAME_oneline(X509_get_subject_name(x509),NULL,0);
        bn = ASN1_INTEGER_to_BN(X509_get_serialNumber(x509),NULL);
+       if (!bn)
+               goto err;
        if (BN_is_zero(bn))
                row[DB_serial]=BUF_strdup("00");
        else
@@ -2465,7 +2466,7 @@ static int do_revoke(X509 *x509, CA_DB *db, int type, char *value)
                goto err;
 
                }
-       else if (index_name_cmp((const char **)row,(const char **)rrow))
+       else if (index_name_cmp_noconst(row, rrow))
                {
                BIO_printf(bio_err,"ERROR:name does not match %s\n",
                           row[DB_name]);
@@ -2614,9 +2615,9 @@ static int do_updatedb (CA_DB *db)
        else
                a_y2k = 0;
 
-       for (i = 0; i < sk_num(db->db->data); i++)
+       for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++)
                {
-               rrow = (char **) sk_value(db->db->data, i);
+               rrow = sk_OPENSSL_PSTRING_value(db->db->data, i);
 
                if (rrow[DB_type][0] == 'V')
                        {
@@ -2863,22 +2864,13 @@ int old_entry_print(BIO *bp, ASN1_OBJECT *obj, ASN1_STRING *str)
        p=(char *)str->data;
        for (j=str->length; j>0; j--)
                {
-#ifdef CHARSET_EBCDIC
-               if ((*p >= 0x20) && (*p <= 0x7e))
-                       BIO_printf(bp,"%c",os_toebcdic[*p]);
-#else
                if ((*p >= ' ') && (*p <= '~'))
                        BIO_printf(bp,"%c",*p);
-#endif
                else if (*p & 0x80)
                        BIO_printf(bp,"\\0x%02X",*p);
                else if ((unsigned char)*p == 0xf7)
                        BIO_printf(bp,"^?");
-#ifdef CHARSET_EBCDIC
-               else    BIO_printf(bp,"^%c",os_toebcdic[*p+0x40]);
-#else
                else    BIO_printf(bp,"^%c",*p+'@');
-#endif
                p++;
                }
        BIO_printf(bp,"'\n");
index 43f0ac5..3d4c60d 100644 (file)
@@ -71,7 +71,8 @@
 
 static const char *ciphers_usage[]={
 "usage: ciphers args\n",
-" -v          - verbose mode, a textual listing of the ciphers in SSLeay\n",
+" -v          - verbose mode, a textual listing of the SSL/TLS ciphers in OpenSSL\n",
+" -V          - even more verbose\n",
 " -ssl2       - SSL2 mode\n",
 " -ssl3       - SSL3 mode\n",
 " -tls1       - TLS1 mode\n",
@@ -83,14 +84,14 @@ int MAIN(int, char **);
 int MAIN(int argc, char **argv)
        {
        int ret=1,i;
-       int verbose=0;
+       int verbose=0,Verbose=0;
        const char **pp;
        const char *p;
        int badops=0;
        SSL_CTX *ctx=NULL;
        SSL *ssl=NULL;
        char *ciphers=NULL;
-       SSL_METHOD *meth=NULL;
+       const SSL_METHOD *meth=NULL;
        STACK_OF(SSL_CIPHER) *sk;
        char buf[512];
        BIO *STDout=NULL;
@@ -114,6 +115,8 @@ int MAIN(int argc, char **argv)
        STDout = BIO_push(tmpbio, STDout);
        }
 #endif
+       if (!load_config(bio_err, NULL))
+               goto end;
 
        argc--;
        argv++;
@@ -121,6 +124,8 @@ int MAIN(int argc, char **argv)
                {
                if (strcmp(*argv,"-v") == 0)
                        verbose=1;
+               else if (strcmp(*argv,"-V") == 0)
+                       verbose=Verbose=1;
 #ifndef OPENSSL_NO_SSL2
                else if (strcmp(*argv,"-ssl2") == 0)
                        meth=SSLv2_client_method();
@@ -179,15 +184,33 @@ int MAIN(int argc, char **argv)
                        }
                BIO_printf(STDout,"\n");
                }
-       else
+       else /* verbose */
                {
                sk=SSL_get_ciphers(ssl);
 
                for (i=0; i<sk_SSL_CIPHER_num(sk); i++)
                        {
-                       BIO_puts(STDout,SSL_CIPHER_description(
-                               sk_SSL_CIPHER_value(sk,i),
-                               buf,sizeof buf));
+                       SSL_CIPHER *c;
+
+                       c = sk_SSL_CIPHER_value(sk,i);
+                       
+                       if (Verbose)
+                               {
+                               unsigned long id = c->id;
+                               int id0 = (int)(id >> 24);
+                               int id1 = (int)((id >> 16) & 0xffL);
+                               int id2 = (int)((id >> 8) & 0xffL);
+                               int id3 = (int)(id & 0xffL);
+                               
+                               if ((id & 0xff000000L) == 0x02000000L)
+                                       BIO_printf(STDout, "     0x%02X,0x%02X,0x%02X - ", id1, id2, id3); /* SSL2 cipher */
+                               else if ((id & 0xff000000L) == 0x03000000L)
+                                       BIO_printf(STDout, "          0x%02X,0x%02X - ", id2, id3); /* SSL3 cipher */
+                               else
+                                       BIO_printf(STDout, "0x%02X,0x%02X,0x%02X,0x%02X - ", id0, id1, id2, id3); /* whatever */
+                               }
+
+                       BIO_puts(STDout,SSL_CIPHER_description(c,buf,sizeof buf));
                        }
                }
 
index 6d227ac..3f5ee1b 100644 (file)
@@ -71,8 +71,9 @@
 static int save_certs(char *signerfile, STACK_OF(X509) *signers);
 static int cms_cb(int ok, X509_STORE_CTX *ctx);
 static void receipt_request_print(BIO *out, CMS_ContentInfo *cms);
-static CMS_ReceiptRequest *make_receipt_request(STACK *rr_to, int rr_allorfirst,
-                                                               STACK *rr_from);
+static CMS_ReceiptRequest *make_receipt_request(STACK_OF(OPENSSL_STRING) *rr_to,
+                                               int rr_allorfirst,
+                                       STACK_OF(OPENSSL_STRING) *rr_from);
 
 #define SMIME_OP       0x10
 #define SMIME_IP       0x20
@@ -94,6 +95,8 @@ static CMS_ReceiptRequest *make_receipt_request(STACK *rr_to, int rr_allorfirst,
 #define SMIME_SIGN_RECEIPT     (15 | SMIME_IP | SMIME_OP)
 #define SMIME_VERIFY_RECEIPT   (16 | SMIME_IP)
 
+int verify_err = 0;
+
 int MAIN(int, char **);
 
 int MAIN(int argc, char **argv)
@@ -105,7 +108,7 @@ int MAIN(int argc, char **argv)
        const char *inmode = "r", *outmode = "w";
        char *infile = NULL, *outfile = NULL, *rctfile = NULL;
        char *signerfile = NULL, *recipfile = NULL;
-       STACK *sksigners = NULL, *skkeys = NULL;
+       STACK_OF(OPENSSL_STRING) *sksigners = NULL, *skkeys = NULL;
        char *certfile = NULL, *keyfile = NULL, *contfile=NULL;
        char *certsoutfile = NULL;
        const EVP_CIPHER *cipher = NULL;
@@ -116,9 +119,10 @@ int MAIN(int argc, char **argv)
        STACK_OF(X509) *encerts = NULL, *other = NULL;
        BIO *in = NULL, *out = NULL, *indata = NULL, *rctin = NULL;
        int badarg = 0;
-       int flags = CMS_DETACHED;
+       int flags = CMS_DETACHED, noout = 0, print = 0;
+       int verify_retcode = 0;
        int rr_print = 0, rr_allorfirst = -1;
-       STACK *rr_to = NULL, *rr_from = NULL;
+       STACK_OF(OPENSSL_STRING) *rr_to = NULL, *rr_from = NULL;
        CMS_ReceiptRequest *rr = NULL;
        char *to = NULL, *from = NULL, *subject = NULL;
        char *CAfile = NULL, *CApath = NULL;
@@ -166,6 +170,8 @@ int MAIN(int argc, char **argv)
                        operation = SMIME_RESIGN;
                else if (!strcmp (*args, "-verify"))
                        operation = SMIME_VERIFY;
+               else if (!strcmp (*args, "-verify_retcode"))
+                       verify_retcode = 1;
                else if (!strcmp(*args,"-verify_receipt"))
                        {
                        operation = SMIME_VERIFY_RECEIPT;
@@ -252,21 +258,17 @@ int MAIN(int argc, char **argv)
                else if (!strcmp (*args, "-no_attr_verify"))
                                flags |= CMS_NO_ATTR_VERIFY;
                else if (!strcmp (*args, "-stream"))
-                               {
-                               args++;
-                               continue;
-                               }
+                               flags |= CMS_STREAM;
                else if (!strcmp (*args, "-indef"))
-                               {
-                               args++;
-                               continue;
-                               }
+                               flags |= CMS_STREAM;
                else if (!strcmp (*args, "-noindef"))
                                flags &= ~CMS_STREAM;
                else if (!strcmp (*args, "-nooldmime"))
                                flags |= CMS_NOOLDMIMETYPE;
                else if (!strcmp (*args, "-crlfeol"))
                                flags |= CMS_CRLFEOL;
+               else if (!strcmp (*args, "-noout"))
+                               noout = 1;
                else if (!strcmp (*args, "-receipt_request_print"))
                                rr_print = 1;
                else if (!strcmp (*args, "-receipt_request_all"))
@@ -279,8 +281,8 @@ int MAIN(int argc, char **argv)
                                goto argerr;
                        args++;
                        if (!rr_from)
-                               rr_from = sk_new_null();
-                       sk_push(rr_from, *args);
+                               rr_from = sk_OPENSSL_STRING_new_null();
+                       sk_OPENSSL_STRING_push(rr_from, *args);
                        }
                else if (!strcmp(*args,"-receipt_request_to"))
                        {
@@ -288,9 +290,14 @@ int MAIN(int argc, char **argv)
                                goto argerr;
                        args++;
                        if (!rr_to)
-                               rr_to = sk_new_null();
-                       sk_push(rr_to, *args);
+                               rr_to = sk_OPENSSL_STRING_new_null();
+                       sk_OPENSSL_STRING_push(rr_to, *args);
                        }
+               else if (!strcmp (*args, "-print"))
+                               {
+                               noout = 1;
+                               print = 1;
+                               }
                else if (!strcmp(*args,"-secretkey"))
                        {
                        long ltmp;
@@ -380,13 +387,13 @@ int MAIN(int argc, char **argv)
                        if (signerfile)
                                {
                                if (!sksigners)
-                                       sksigners = sk_new_null();
-                               sk_push(sksigners, signerfile);
+                                       sksigners = sk_OPENSSL_STRING_new_null();
+                               sk_OPENSSL_STRING_push(sksigners, signerfile);
                                if (!keyfile)
                                        keyfile = signerfile;
                                if (!skkeys)
-                                       skkeys = sk_new_null();
-                               sk_push(skkeys, keyfile);
+                                       skkeys = sk_OPENSSL_STRING_new_null();
+                               sk_OPENSSL_STRING_push(skkeys, keyfile);
                                keyfile = NULL;
                                }
                        signerfile = *++args;
@@ -428,12 +435,12 @@ int MAIN(int argc, char **argv)
                                        goto argerr;
                                        }
                                if (!sksigners)
-                                       sksigners = sk_new_null();
-                               sk_push(sksigners, signerfile);
+                                       sksigners = sk_OPENSSL_STRING_new_null();
+                               sk_OPENSSL_STRING_push(sksigners, signerfile);
                                signerfile = NULL;
                                if (!skkeys)
-                                       skkeys = sk_new_null();
-                               sk_push(skkeys, keyfile);
+                                       skkeys = sk_OPENSSL_STRING_new_null();
+                               sk_OPENSSL_STRING_push(skkeys, keyfile);
                                }
                        keyfile = *++args;
                        }
@@ -532,13 +539,13 @@ int MAIN(int argc, char **argv)
                if (signerfile)
                        {
                        if (!sksigners)
-                               sksigners = sk_new_null();
-                       sk_push(sksigners, signerfile);
+                               sksigners = sk_OPENSSL_STRING_new_null();
+                       sk_OPENSSL_STRING_push(sksigners, signerfile);
                        if (!skkeys)
-                               skkeys = sk_new_null();
+                               skkeys = sk_OPENSSL_STRING_new_null();
                        if (!keyfile)
                                keyfile = signerfile;
-                       sk_push(skkeys, keyfile);
+                       sk_OPENSSL_STRING_push(skkeys, keyfile);
                        }
                if (!sksigners)
                        {
@@ -611,7 +618,7 @@ int MAIN(int argc, char **argv)
                BIO_printf (bio_err, "-certsout file certificate output file\n");
                BIO_printf (bio_err, "-signer file   signer certificate file\n");
                BIO_printf (bio_err, "-recip  file   recipient certificate file for decryption\n");
-               BIO_printf (bio_err, "-skeyid        use subject key identifier\n");
+               BIO_printf (bio_err, "-keyid        use subject key identifier\n");
                BIO_printf (bio_err, "-in file       input file\n");
                BIO_printf (bio_err, "-inform arg    input format SMIME (default), PEM or DER\n");
                BIO_printf (bio_err, "-inkey file    input private key (if not signer or recipient)\n");
@@ -697,7 +704,7 @@ int MAIN(int argc, char **argv)
 
                if (secret_key && !secret_keyid)
                        {
-                       BIO_printf(bio_err, "No sectre key id\n");
+                       BIO_printf(bio_err, "No secret key id\n");
                        goto end;
                        }
 
@@ -873,7 +880,7 @@ int MAIN(int argc, char **argv)
                {
                if (!(store = setup_verify(bio_err, CAfile, CApath)))
                        goto end;
-               X509_STORE_set_verify_cb_func(store, cms_cb);
+               X509_STORE_set_verify_cb(store, cms_cb);
                if (vpm)
                        X509_STORE_set1_param(store, vpm);
                }
@@ -973,11 +980,11 @@ int MAIN(int argc, char **argv)
                        }
                else
                        flags |= CMS_REUSE_DIGEST;
-               for (i = 0; i < sk_num(sksigners); i++)
+               for (i = 0; i < sk_OPENSSL_STRING_num(sksigners); i++)
                        {
                        CMS_SignerInfo *si;
-                       signerfile = sk_value(sksigners, i);
-                       keyfile = sk_value(skkeys, i);
+                       signerfile = sk_OPENSSL_STRING_value(sksigners, i);
+                       keyfile = sk_OPENSSL_STRING_value(skkeys, i);
                        signer = load_cert(bio_err, signerfile,FORMAT_PEM, NULL,
                                        e, "signer certificate");
                        if (!signer)
@@ -1075,6 +1082,8 @@ int MAIN(int argc, char **argv)
                else
                        {
                        BIO_printf(bio_err, "Verification failure\n");
+                       if (verify_retcode)
+                               ret = verify_err + 32;
                        goto end;
                        }
                if (signerfile)
@@ -1107,7 +1116,12 @@ int MAIN(int argc, char **argv)
                }
        else
                {
-               if (outformat == FORMAT_SMIME)
+               if (noout)
+                       {
+                       if (print)
+                               CMS_ContentInfo_print_ctx(out, cms, 0, NULL);
+                       }
+               else if (outformat == FORMAT_SMIME)
                        {
                        if (to)
                                BIO_printf(out, "To: %s\n", to);
@@ -1121,9 +1135,9 @@ int MAIN(int argc, char **argv)
                                ret = SMIME_write_CMS(out, cms, in, flags);
                        }
                else if (outformat == FORMAT_PEM) 
-                       ret = PEM_write_bio_CMS(out, cms);
+                       ret = PEM_write_bio_CMS_stream(out, cms, in, flags);
                else if (outformat == FORMAT_ASN1) 
-                       ret = i2d_CMS_bio(out,cms);
+                       ret = i2d_CMS_bio_stream(out,cms, in, flags);
                else
                        {
                        BIO_printf(bio_err, "Bad output format for CMS file\n");
@@ -1146,9 +1160,9 @@ end:
        if (vpm)
                X509_VERIFY_PARAM_free(vpm);
        if (sksigners)
-               sk_free(sksigners);
+               sk_OPENSSL_STRING_free(sksigners);
        if (skkeys)
-               sk_free(skkeys);
+               sk_OPENSSL_STRING_free(skkeys);
        if (secret_key)
                OPENSSL_free(secret_key);
        if (secret_keyid)
@@ -1158,9 +1172,9 @@ end:
        if (rr)
                CMS_ReceiptRequest_free(rr);
        if (rr_to)
-               sk_free(rr_to);
+               sk_OPENSSL_STRING_free(rr_to);
        if (rr_from)
-               sk_free(rr_from);
+               sk_OPENSSL_STRING_free(rr_from);
        X509_STORE_free(store);
        X509_free(cert);
        X509_free(recip);
@@ -1199,6 +1213,8 @@ static int cms_cb(int ok, X509_STORE_CTX *ctx)
 
        error = X509_STORE_CTX_get_error(ctx);
 
+       verify_err = error;
+
        if ((error != X509_V_ERR_NO_EXPLICIT_POLICY)
                && ((error != X509_V_OK) || (ok != 2)))
                return ok;
@@ -1280,7 +1296,7 @@ static void receipt_request_print(BIO *out, CMS_ContentInfo *cms)
                }
        }
 
-static STACK_OF(GENERAL_NAMES) *make_names_stack(STACK *ns)
+static STACK_OF(GENERAL_NAMES) *make_names_stack(STACK_OF(OPENSSL_STRING) *ns)
        {
        int i;
        STACK_OF(GENERAL_NAMES) *ret;
@@ -1289,12 +1305,10 @@ static STACK_OF(GENERAL_NAMES) *make_names_stack(STACK *ns)
        ret = sk_GENERAL_NAMES_new_null();
        if (!ret)
                goto err;
-       for (i = 0; i < sk_num(ns); i++)
+       for (i = 0; i < sk_OPENSSL_STRING_num(ns); i++)
                {
-               CONF_VALUE cnf;
-               cnf.name = "email";
-               cnf.value = sk_value(ns, i);
-               gen = v2i_GENERAL_NAME(NULL, NULL, &cnf);
+               char *str = sk_OPENSSL_STRING_value(ns, i);
+               gen = a2i_GENERAL_NAME(NULL, NULL, NULL, GEN_EMAIL, str, 0);
                if (!gen)
                        goto err;
                gens = GENERAL_NAMES_new();
@@ -1321,8 +1335,9 @@ static STACK_OF(GENERAL_NAMES) *make_names_stack(STACK *ns)
        }
 
 
-static CMS_ReceiptRequest *make_receipt_request(STACK *rr_to, int rr_allorfirst,
-                                                               STACK *rr_from)
+static CMS_ReceiptRequest *make_receipt_request(STACK_OF(OPENSSL_STRING) *rr_to,
+                                               int rr_allorfirst,
+                                               STACK_OF(OPENSSL_STRING) *rr_from)
        {
        STACK_OF(GENERAL_NAMES) *rct_to, *rct_from;
        CMS_ReceiptRequest *rr;
index b2f2d12..bbc8377 100644 (file)
@@ -63,7 +63,6 @@
 #include <stdio.h>
 #include <string.h>
 #include <sys/types.h>
-#include <sys/stat.h>
 #include "apps.h"
 #include <openssl/err.h>
 #include <openssl/evp.h>
@@ -93,7 +92,7 @@ int MAIN(int argc, char **argv)
        PKCS7 *p7 = NULL;
        PKCS7_SIGNED *p7s = NULL;
        X509_CRL *crl=NULL;
-       STACK *certflst=NULL;
+       STACK_OF(OPENSSL_STRING) *certflst=NULL;
        STACK_OF(X509_CRL) *crl_stack=NULL;
        STACK_OF(X509) *cert_stack=NULL;
        int ret=1,nocrl=0;
@@ -141,8 +140,8 @@ int MAIN(int argc, char **argv)
                else if (strcmp(*argv,"-certfile") == 0)
                        {
                        if (--argc < 1) goto bad;
-                       if(!certflst) certflst = sk_new_null();
-                       sk_push(certflst,*(++argv));
+                       if(!certflst) certflst = sk_OPENSSL_STRING_new_null();
+                       sk_OPENSSL_STRING_push(certflst,*(++argv));
                        }
                else
                        {
@@ -227,8 +226,8 @@ bad:
        if ((cert_stack=sk_X509_new_null()) == NULL) goto end;
        p7s->cert=cert_stack;
 
-       if(certflst) for(i = 0; i < sk_num(certflst); i++) {
-               certfile = sk_value(certflst, i);
+       if(certflst) for(i = 0; i < sk_OPENSSL_STRING_num(certflst); i++) {
+               certfile = sk_OPENSSL_STRING_value(certflst, i);
                if (add_certs_from_file(cert_stack,certfile) < 0)
                        {
                        BIO_printf(bio_err, "error loading certificates\n");
@@ -237,7 +236,7 @@ bad:
                        }
        }
 
-       sk_free(certflst);
+       sk_OPENSSL_STRING_free(certflst);
 
        if (outfile == NULL)
                {
@@ -295,19 +294,12 @@ end:
  */
 static int add_certs_from_file(STACK_OF(X509) *stack, char *certfile)
        {
-       struct stat st;
        BIO *in=NULL;
        int count=0;
        int ret= -1;
        STACK_OF(X509_INFO) *sk=NULL;
        X509_INFO *xi;
 
-       if ((stat(certfile,&st) != 0))
-               {
-               BIO_printf(bio_err,"unable to load the file, %s\n",certfile);
-               goto end;
-               }
-
        in=BIO_new(BIO_s_file());
        if ((in == NULL) || (BIO_read_filename(in,certfile) <= 0))
                {
index 9ebfc22..9bf38ce 100644 (file)
 #define PROG   dgst_main
 
 int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
-         EVP_PKEY *key, unsigned char *sigin, int siglen, const char *title,
-         const char *file,BIO *bmd,const char *hmac_key, int non_fips_allow);
+         EVP_PKEY *key, unsigned char *sigin, int siglen,
+         const char *sig_name, const char *md_name,
+         const char *file,BIO *bmd);
+
+static void list_md_fn(const EVP_MD *m,
+                       const char *from, const char *to, void *arg)
+       {
+       const char *mname;
+       /* Skip aliases */
+       if (!m)
+               return;
+       mname = OBJ_nid2ln(EVP_MD_type(m));
+       /* Skip shortnames */
+       if (strcmp(from, mname))
+               return;
+       /* Skip clones */
+       if (EVP_MD_flags(m) & EVP_MD_FLAG_PKEY_DIGEST)
+               return;
+       if (strchr(mname, ' '))
+               mname= EVP_MD_name(m);
+       BIO_printf(arg, "-%-14s to use the %s message digest algorithm\n",
+                       mname, mname);
+       }
 
 int MAIN(int, char **);
 
@@ -89,7 +110,6 @@ int MAIN(int argc, char **argv)
        BIO *in=NULL,*inp;
        BIO *bmd=NULL;
        BIO *out = NULL;
-       const char *name;
 #define PROG_NAME_SIZE  39
        char pname[PROG_NAME_SIZE+1];
        int separator=0;
@@ -101,16 +121,16 @@ int MAIN(int argc, char **argv)
        EVP_PKEY *sigkey = NULL;
        unsigned char *sigbuf = NULL;
        int siglen = 0;
-       unsigned int sig_flags = 0;
        char *passargin = NULL, *passin = NULL;
 #ifndef OPENSSL_NO_ENGINE
        char *engine=NULL;
 #endif
        char *hmac_key=NULL;
-       int non_fips_allow = 0;
+       char *mac_name=NULL;
+       STACK_OF(OPENSSL_STRING) *sigopts = NULL, *macopts = NULL;
 
        apps_startup();
-ERR_load_crypto_strings();
+
        if ((buf=(unsigned char *)OPENSSL_malloc(BUFSIZE)) == NULL)
                {
                BIO_printf(bio_err,"out of memory\n");
@@ -135,6 +155,8 @@ ERR_load_crypto_strings();
                if ((*argv)[0] != '-') break;
                if (strcmp(*argv,"-c") == 0)
                        separator=1;
+               else if (strcmp(*argv,"-r") == 0)
+                       separator=2;
                else if (strcmp(*argv,"-rand") == 0)
                        {
                        if (--argc < 1) break;
@@ -169,27 +191,6 @@ ERR_load_crypto_strings();
                        keyfile=*(++argv);
                        do_verify = 1;
                        }
-               else if (strcmp(*argv,"-x931") == 0)
-                       sig_flags = EVP_MD_CTX_FLAG_PAD_X931;
-               else if (strcmp(*argv,"-pss_saltlen") == 0)
-                       {
-                       int saltlen;
-                       if (--argc < 1) break;
-                       saltlen=atoi(*(++argv));
-                       if (saltlen == -1)
-                               sig_flags = EVP_MD_CTX_FLAG_PSS_MREC;
-                       else if (saltlen == -2)
-                               sig_flags = EVP_MD_CTX_FLAG_PSS_MDLEN;
-                       else if (saltlen < -2 || saltlen >= 0xFFFE)
-                               {
-                               BIO_printf(bio_err, "Invalid PSS salt length %d\n", saltlen);
-                               goto end;
-                               }
-                       else
-                               sig_flags = saltlen;
-                       sig_flags <<= 16;
-                       sig_flags |= EVP_MD_CTX_FLAG_PAD_PSS;
-                       }
                else if (strcmp(*argv,"-signature") == 0)
                        {
                        if (--argc < 1) break;
@@ -205,6 +206,7 @@ ERR_load_crypto_strings();
                        {
                        if (--argc < 1) break;
                        engine= *(++argv);
+                       e = setup_engine(bio_err, engine, 0);
                        }
 #endif
                else if (strcmp(*argv,"-hex") == 0)
@@ -213,16 +215,36 @@ ERR_load_crypto_strings();
                        out_bin = 1;
                else if (strcmp(*argv,"-d") == 0)
                        debug=1;
-               else if (strcmp(*argv,"-non-fips-allow") == 0)
-                       non_fips_allow=1;
-               else if (!strcmp(*argv,"-fips-fingerprint"))
-                       hmac_key = "etaonrishdlcupfm";
                else if (!strcmp(*argv,"-hmac"))
                        {
                        if (--argc < 1)
                                break;
                        hmac_key=*++argv;
                        }
+               else if (!strcmp(*argv,"-mac"))
+                       {
+                       if (--argc < 1)
+                               break;
+                       mac_name=*++argv;
+                       }
+               else if (strcmp(*argv,"-sigopt") == 0)
+                       {
+                       if (--argc < 1)
+                               break;
+                       if (!sigopts)
+                               sigopts = sk_OPENSSL_STRING_new_null();
+                       if (!sigopts || !sk_OPENSSL_STRING_push(sigopts, *(++argv)))
+                               break;
+                       }
+               else if (strcmp(*argv,"-macopt") == 0)
+                       {
+                       if (--argc < 1)
+                               break;
+                       if (!macopts)
+                               macopts = sk_OPENSSL_STRING_new_null();
+                       if (!macopts || !sk_OPENSSL_STRING_push(macopts, *(++argv)))
+                               break;
+                       }
                else if ((m=EVP_get_digestbyname(&((*argv)[1]))) != NULL)
                        md=m;
                else
@@ -231,12 +253,9 @@ ERR_load_crypto_strings();
                argv++;
                }
 
-       if (md == NULL)
-               md=EVP_md5();
 
        if(do_verify && !sigfile) {
                BIO_printf(bio_err, "No signature to verify: use the -signature option\n");
-               err = 1; 
                goto end;
        }
 
@@ -245,6 +264,7 @@ ERR_load_crypto_strings();
                BIO_printf(bio_err,"unknown option '%s'\n",*argv);
                BIO_printf(bio_err,"options are\n");
                BIO_printf(bio_err,"-c              to output the digest with separating colons\n");
+               BIO_printf(bio_err,"-r              to output the digest in coreutils format\n");
                BIO_printf(bio_err,"-d              to output debug info\n");
                BIO_printf(bio_err,"-hex            output as hex dump\n");
                BIO_printf(bio_err,"-binary         output in binary form\n");
@@ -252,49 +272,20 @@ ERR_load_crypto_strings();
                BIO_printf(bio_err,"-verify file    verify a signature using public key in file\n");
                BIO_printf(bio_err,"-prverify file  verify a signature using private key in file\n");
                BIO_printf(bio_err,"-keyform arg    key file format (PEM or ENGINE)\n");
+               BIO_printf(bio_err,"-out filename   output to filename rather than stdout\n");
                BIO_printf(bio_err,"-signature file signature to verify\n");
-               BIO_printf(bio_err,"-binary         output in binary form\n");
+               BIO_printf(bio_err,"-sigopt nm:v    signature parameter\n");
                BIO_printf(bio_err,"-hmac key       create hashed MAC with key\n");
+               BIO_printf(bio_err,"-mac algorithm  create MAC (not neccessarily HMAC)\n"); 
+               BIO_printf(bio_err,"-macopt nm:v    MAC algorithm parameters or key\n");
 #ifndef OPENSSL_NO_ENGINE
                BIO_printf(bio_err,"-engine e       use engine e, possibly a hardware device.\n");
 #endif
 
-               BIO_printf(bio_err,"-%-14s to use the %s message digest algorithm (default)\n",
-                       LN_md5,LN_md5);
-               BIO_printf(bio_err,"-%-14s to use the %s message digest algorithm\n",
-                       LN_md4,LN_md4);
-               BIO_printf(bio_err,"-%-14s to use the %s message digest algorithm\n",
-                       LN_md2,LN_md2);
-#ifndef OPENSSL_NO_SHA
-               BIO_printf(bio_err,"-%-14s to use the %s message digest algorithm\n",
-                       LN_sha1,LN_sha1);
-               BIO_printf(bio_err,"-%-14s to use the %s message digest algorithm\n",
-                       LN_sha,LN_sha);
-#ifndef OPENSSL_NO_SHA256
-               BIO_printf(bio_err,"-%-14s to use the %s message digest algorithm\n",
-                       LN_sha224,LN_sha224);
-               BIO_printf(bio_err,"-%-14s to use the %s message digest algorithm\n",
-                       LN_sha256,LN_sha256);
-#endif
-#ifndef OPENSSL_NO_SHA512
-               BIO_printf(bio_err,"-%-14s to use the %s message digest algorithm\n",
-                       LN_sha384,LN_sha384);
-               BIO_printf(bio_err,"-%-14s to use the %s message digest algorithm\n",
-                       LN_sha512,LN_sha512);
-#endif
-#endif
-               BIO_printf(bio_err,"-%-14s to use the %s message digest algorithm\n",
-                       LN_mdc2,LN_mdc2);
-               BIO_printf(bio_err,"-%-14s to use the %s message digest algorithm\n",
-                       LN_ripemd160,LN_ripemd160);
-               err=1;
+               EVP_MD_do_all_sorted(list_md_fn, bio_err);
                goto end;
                }
 
-#ifndef OPENSSL_NO_ENGINE
-        e = setup_engine(bio_err, engine, 0);
-#endif
-
        in=BIO_new(BIO_s_file());
        bmd=BIO_new(BIO_f_md());
        if (debug)
@@ -317,8 +308,10 @@ ERR_load_crypto_strings();
                }
 
        if(out_bin == -1) {
-               if(keyfile) out_bin = 1;
-               else out_bin = 0;
+               if(keyfile)
+                       out_bin = 1;
+               else
+                       out_bin = 0;
        }
 
        if(randfile)
@@ -344,6 +337,11 @@ ERR_load_crypto_strings();
                ERR_print_errors(bio_err);
                goto end;
        }
+       if ((!!mac_name + !!keyfile + !!hmac_key) > 1)
+               {
+               BIO_printf(bio_err, "MAC and Signing key cannot both be specified\n");
+               goto end;
+               }
 
        if(keyfile)
                {
@@ -361,6 +359,101 @@ ERR_load_crypto_strings();
                        }
                }
 
+       if (mac_name)
+               {
+               EVP_PKEY_CTX *mac_ctx = NULL;
+               int r = 0;
+               if (!init_gen_str(bio_err, &mac_ctx, mac_name,e, 0))
+                       goto mac_end;
+               if (macopts)
+                       {
+                       char *macopt;
+                       for (i = 0; i < sk_OPENSSL_STRING_num(macopts); i++)
+                               {
+                               macopt = sk_OPENSSL_STRING_value(macopts, i);
+                               if (pkey_ctrl_string(mac_ctx, macopt) <= 0)
+                                       {
+                                       BIO_printf(bio_err,
+                                               "MAC parameter error \"%s\"\n",
+                                               macopt);
+                                       ERR_print_errors(bio_err);
+                                       goto mac_end;
+                                       }
+                               }
+                       }
+               if (EVP_PKEY_keygen(mac_ctx, &sigkey) <= 0)
+                       {
+                       BIO_puts(bio_err, "Error generating key\n");
+                       ERR_print_errors(bio_err);
+                       goto mac_end;
+                       }
+               r = 1;
+               mac_end:
+               if (mac_ctx)
+                       EVP_PKEY_CTX_free(mac_ctx);
+               if (r == 0)
+                       goto end;
+               }
+
+       if (hmac_key)
+               {
+               sigkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, e,
+                                       (unsigned char *)hmac_key, -1);
+               if (!sigkey)
+                       goto end;
+               }
+
+       if (sigkey)
+               {
+               EVP_MD_CTX *mctx = NULL;
+               EVP_PKEY_CTX *pctx = NULL;
+               int r;
+               if (!BIO_get_md_ctx(bmd, &mctx))
+                       {
+                       BIO_printf(bio_err, "Error getting context\n");
+                       ERR_print_errors(bio_err);
+                       goto end;
+                       }
+               if (do_verify)
+                       r = EVP_DigestVerifyInit(mctx, &pctx, md, e, sigkey);
+               else
+                       r = EVP_DigestSignInit(mctx, &pctx, md, e, sigkey);
+               if (!r)
+                       {
+                       BIO_printf(bio_err, "Error setting context\n");
+                       ERR_print_errors(bio_err);
+                       goto end;
+                       }
+               if (sigopts)
+                       {
+                       char *sigopt;
+                       for (i = 0; i < sk_OPENSSL_STRING_num(sigopts); i++)
+                               {
+                               sigopt = sk_OPENSSL_STRING_value(sigopts, i);
+                               if (pkey_ctrl_string(pctx, sigopt) <= 0)
+                                       {
+                                       BIO_printf(bio_err,
+                                               "parameter error \"%s\"\n",
+                                               sigopt);
+                                       ERR_print_errors(bio_err);
+                                       goto end;
+                                       }
+                               }
+                       }
+               }
+       /* we use md as a filter, reading from 'in' */
+       else
+               {
+               if (md == NULL)
+                       md = EVP_md5(); 
+               if (!BIO_set_md(bmd,md))
+                       {
+                       BIO_printf(bio_err, "Error setting digest %s\n", pname);
+                       ERR_print_errors(bio_err);
+                       goto end;
+                       }
+               }
+
        if(sigfile && sigkey) {
                BIO *sigbio;
                sigbio = BIO_new_file(sigfile, "rb");
@@ -381,67 +474,51 @@ ERR_load_crypto_strings();
                        goto end;
                }
        }
+       inp=BIO_push(bmd,in);
 
-       if (non_fips_allow)
-               {
-               EVP_MD_CTX *md_ctx;
-               BIO_get_md_ctx(bmd,&md_ctx);
-               EVP_MD_CTX_set_flags(md_ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
-               }
-
-       if (sig_flags)
+       if (md == NULL)
                {
-               EVP_MD_CTX *md_ctx;
-               BIO_get_md_ctx(bmd,&md_ctx);
-               EVP_MD_CTX_set_flags(md_ctx, sig_flags);
+               EVP_MD_CTX *tctx;
+               BIO_get_md_ctx(bmd, &tctx);
+               md = EVP_MD_CTX_md(tctx);
                }
 
-       /* we use md as a filter, reading from 'in' */
-       if (!BIO_set_md(bmd,md))
-               {
-               BIO_printf(bio_err, "Error setting digest %s\n", pname);
-               ERR_print_errors(bio_err);
-               goto end;
-               }
-               
-       inp=BIO_push(bmd,in);
-
        if (argc == 0)
                {
                BIO_set_fp(in,stdin,BIO_NOCLOSE);
                err=do_fp(out, buf,inp,separator, out_bin, sigkey, sigbuf,
-                         siglen,"","(stdin)",bmd,hmac_key,non_fips_allow);
+                         siglen,NULL,NULL,"stdin",bmd);
                }
        else
                {
-               name=OBJ_nid2sn(md->type);
+               const char *md_name = NULL, *sig_name = NULL;
+               if(!out_bin)
+                       {
+                       if (sigkey)
+                               {
+                               const EVP_PKEY_ASN1_METHOD *ameth;
+                               ameth = EVP_PKEY_get0_asn1(sigkey);
+                               if (ameth)
+                                       EVP_PKEY_asn1_get0_info(NULL, NULL,
+                                               NULL, NULL, &sig_name, ameth);
+                               }
+                       md_name = EVP_MD_name(md);
+                       }
                err = 0;
                for (i=0; i<argc; i++)
                        {
-                       char *tmp,*tofree=NULL;
                        int r;
-
                        if (BIO_read_filename(in,argv[i]) <= 0)
                                {
                                perror(argv[i]);
                                err++;
                                continue;
                                }
-                       if(!out_bin)
-                               {
-                               size_t len = strlen(name)+strlen(argv[i])+(hmac_key ? 5 : 0)+5;
-                               tmp=tofree=OPENSSL_malloc(len);
-                               BIO_snprintf(tmp,len,"%s%s(%s)= ",
-                                                        hmac_key ? "HMAC-" : "",name,argv[i]);
-                               }
                        else
-                               tmp="";
                        r=do_fp(out,buf,inp,separator,out_bin,sigkey,sigbuf,
-                               siglen,tmp,argv[i],bmd,hmac_key,non_fips_allow);
+                               siglen,sig_name,md_name, argv[i],bmd);
                        if(r)
                            err=r;
-                       if(tofree)
-                               OPENSSL_free(tofree);
                        (void)BIO_reset(bmd);
                        }
                }
@@ -456,6 +533,10 @@ end:
                OPENSSL_free(passin);
        BIO_free_all(out);
        EVP_PKEY_free(sigkey);
+       if (sigopts)
+               sk_OPENSSL_STRING_free(sigopts);
+       if (macopts)
+               sk_OPENSSL_STRING_free(macopts);
        if(sigbuf) OPENSSL_free(sigbuf);
        if (bmd != NULL) BIO_free(bmd);
        apps_shutdown();
@@ -463,24 +544,13 @@ end:
        }
 
 int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
-         EVP_PKEY *key, unsigned char *sigin, int siglen, const char *title,
-         const char *file,BIO *bmd,const char *hmac_key,int non_fips_allow)
+         EVP_PKEY *key, unsigned char *sigin, int siglen,
+         const char *sig_name, const char *md_name,
+         const char *file,BIO *bmd)
        {
-       unsigned int len;
+       size_t len;
        int i;
-       EVP_MD_CTX *md_ctx;
-       HMAC_CTX hmac_ctx;
-
-       if (hmac_key)
-               {
-               EVP_MD *md;
 
-               BIO_get_md(bmd,&md);
-               HMAC_CTX_init(&hmac_ctx);
-               HMAC_Init_ex(&hmac_ctx,hmac_key,strlen(hmac_key),md, NULL);
-               BIO_get_md_ctx(bmd,&md_ctx);
-               BIO_set_md_ctx(bmd,&hmac_ctx.md_ctx);
-               }
        for (;;)
                {
                i=BIO_read(bp,(char *)buf,BUFSIZE);
@@ -496,7 +566,7 @@ int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
                {
                EVP_MD_CTX *ctx;
                BIO_get_md_ctx(bp, &ctx);
-               i = EVP_VerifyFinal(ctx, sigin, (unsigned int)siglen, key); 
+               i = EVP_DigestVerifyFinal(ctx, sigin, (unsigned int)siglen); 
                if(i > 0)
                        BIO_printf(out, "Verified OK\n");
                else if(i == 0)
@@ -516,25 +586,39 @@ int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
                {
                EVP_MD_CTX *ctx;
                BIO_get_md_ctx(bp, &ctx);
-               if(!EVP_SignFinal(ctx, buf, (unsigned int *)&len, key)) 
+               len = BUFSIZE;
+               if(!EVP_DigestSignFinal(ctx, buf, &len)) 
                        {
                        BIO_printf(bio_err, "Error Signing Data\n");
                        ERR_print_errors(bio_err);
                        return 1;
                        }
                }
-       else if(hmac_key)
-               {
-               HMAC_Final(&hmac_ctx,buf,&len);
-               HMAC_CTX_cleanup(&hmac_ctx);
-               }
        else
+               {
                len=BIO_gets(bp,(char *)buf,BUFSIZE);
+               if ((int)len <0)
+                       {
+                       ERR_print_errors(bio_err);
+                       return 1;
+                       }
+               }
 
        if(binout) BIO_write(out, buf, len);
+       else if (sep == 2)
+               {
+               for (i=0; i<(int)len; i++)
+                       BIO_printf(out, "%02x",buf[i]);
+               BIO_printf(out, " *%s\n", file);
+               }
        else 
                {
-               BIO_write(out,title,strlen(title));
+               if (sig_name)
+                       BIO_printf(out, "%s-%s(%s)= ", sig_name, md_name, file);
+               else if (md_name)
+                       BIO_printf(out, "%s(%s)= ", md_name, file);
+               else
+                       BIO_printf(out, "(%s)= ", file);
                for (i=0; i<(int)len; i++)
                        {
                        if (sep && (i != 0))
@@ -543,10 +627,6 @@ int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
                        }
                BIO_printf(out, "\n");
                }
-       if (hmac_key)
-               {
-               BIO_set_md_ctx(bmd,md_ctx);
-               }
        return 0;
        }
 
index 7e45bd3..dee9c01 100644 (file)
@@ -346,4 +346,10 @@ end:
        apps_shutdown();
        OPENSSL_EXIT(ret);
        }
+#else /* !OPENSSL_NO_DH */
+
+# if PEDANTIC
+static void *dummy=&dummy;
+# endif
+
 #endif
index 465cdfe..b47097c 100644 (file)
@@ -551,4 +551,10 @@ static int MS_CALLBACK dh_cb(int p, int n, BN_GENCB *cb)
        return 1;
        }
 
+#else /* !OPENSSL_NO_DH */
+
+# if PEDANTIC
+static void *dummy=&dummy;
+# endif
+
 #endif
index 5e68a56..5222487 100644 (file)
 #include "apps.h"
 #include <openssl/bio.h>
 #include <openssl/err.h>
+#include <openssl/dsa.h>
 #include <openssl/evp.h>
 #include <openssl/x509.h>
 #include <openssl/pem.h>
 #include <openssl/bn.h>
-#include <openssl/dsa.h>
 
 #undef PROG
 #define PROG   dsa_main
@@ -112,6 +112,8 @@ int MAIN(int argc, char **argv)
        char *passin = NULL, *passout = NULL;
        int modulus=0;
 
+       int pvk_encr = 2;
+
        apps_startup();
 
        if (bio_err == NULL)
@@ -171,6 +173,12 @@ int MAIN(int argc, char **argv)
                        engine= *(++argv);
                        }
 #endif
+               else if (strcmp(*argv,"-pvk-strong") == 0)
+                       pvk_encr=2;
+               else if (strcmp(*argv,"-pvk-weak") == 0)
+                       pvk_encr=1;
+               else if (strcmp(*argv,"-pvk-none") == 0)
+                       pvk_encr=0;
                else if (strcmp(*argv,"-noout") == 0)
                        noout=1;
                else if (strcmp(*argv,"-text") == 0)
@@ -238,16 +246,30 @@ bad:
                goto end;
        }
 
+       in=BIO_new(BIO_s_file());
        out=BIO_new(BIO_s_file());
-       if (out == NULL)
+       if ((in == NULL) || (out == NULL))
                {
                ERR_print_errors(bio_err);
                goto end;
                }
 
+       if (infile == NULL)
+               BIO_set_fp(in,stdin,BIO_NOCLOSE);
+       else
+               {
+               if (BIO_read_filename(in,infile) <= 0)
+                       {
+                       perror(infile);
+                       goto end;
+                       }
+               }
+
        BIO_printf(bio_err,"read DSA key\n");
-       {
+
+               {
                EVP_PKEY        *pkey;
+
                if (pubin)
                        pkey = load_pubkey(bio_err, infile, informat, 1,
                                passin, e, "Public Key");
@@ -255,10 +277,12 @@ bad:
                        pkey = load_key(bio_err, infile, informat, 1,
                                passin, e, "Private Key");
 
-               if (pkey != NULL)
-               dsa = pkey == NULL ? NULL : EVP_PKEY_get1_DSA(pkey);
-               EVP_PKEY_free(pkey);
-       }
+               if (pkey)
+                       {
+                       dsa = EVP_PKEY_get1_DSA(pkey);
+                       EVP_PKEY_free(pkey);
+                       }
+               }
        if (dsa == NULL)
                {
                BIO_printf(bio_err,"unable to load Key\n");
@@ -310,11 +334,24 @@ bad:
                        i=PEM_write_bio_DSA_PUBKEY(out,dsa);
                else i=PEM_write_bio_DSAPrivateKey(out,dsa,enc,
                                                        NULL,0,NULL, passout);
+#if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_RC4)
+       } else if (outformat == FORMAT_MSBLOB || outformat == FORMAT_PVK) {
+               EVP_PKEY *pk;
+               pk = EVP_PKEY_new();
+               EVP_PKEY_set1_DSA(pk, dsa);
+               if (outformat == FORMAT_PVK)
+                       i = i2b_PVK_bio(out, pk, pvk_encr, 0, passout);
+               else if (pubin || pubout)
+                       i = i2b_PublicKey_bio(out, pk);
+               else
+                       i = i2b_PrivateKey_bio(out, pk);
+               EVP_PKEY_free(pk);
+#endif
        } else {
                BIO_printf(bio_err,"bad output format specified for outfile\n");
                goto end;
                }
-       if (!i)
+       if (i <= 0)
                {
                BIO_printf(bio_err,"unable to write private key\n");
                ERR_print_errors(bio_err);
@@ -330,4 +367,10 @@ end:
        apps_shutdown();
        OPENSSL_EXIT(ret);
        }
+#else /* !OPENSSL_NO_DSA */
+
+# if PEDANTIC
+static void *dummy=&dummy;
+# endif
+
 #endif
index 6b3d3ad..896eabc 100644 (file)
@@ -397,4 +397,10 @@ end:
        apps_shutdown();
        OPENSSL_EXIT(ret);
 }
+#else /* !OPENSSL_NO_EC */
+
+# if PEDANTIC
+static void *dummy=&dummy;
+# endif
+
 #endif
index 2d3fd30..465480b 100644 (file)
@@ -722,4 +722,10 @@ static int ecparam_print_var(BIO *out, BIGNUM *in, const char *var,
        BIO_printf(out, "\n\t};\n\n");
        return 1;
        }
+#else /* !OPENSSL_NO_EC */
+
+# if PEDANTIC
+static void *dummy=&dummy;
+# endif
+
 #endif
index 8beb2df..076225c 100644 (file)
@@ -67,6 +67,7 @@
 #include <openssl/x509.h>
 #include <openssl/rand.h>
 #include <openssl/pem.h>
+#include <openssl/comp.h>
 #include <ctype.h>
 
 int set_hex(char *in,unsigned char *out,int size);
@@ -113,6 +114,10 @@ int MAIN(int argc, char **argv)
        char *hkey=NULL,*hiv=NULL,*hsalt = NULL;
        char *md=NULL;
        int enc=1,printkey=0,i,base64=0;
+#ifdef ZLIB
+       int do_zlib=0;
+       BIO *bzl = NULL;
+#endif
        int debug=0,olb64=0,nosalt=0;
        const EVP_CIPHER *cipher=NULL,*c;
        EVP_CIPHER_CTX *ctx = NULL;
@@ -124,7 +129,6 @@ int MAIN(int argc, char **argv)
        char *engine = NULL;
 #endif
        const EVP_MD *dgst=NULL;
-       int non_fips_allow = 0;
 
        apps_startup();
 
@@ -139,9 +143,18 @@ int MAIN(int argc, char **argv)
        program_name(argv[0],pname,sizeof pname);
        if (strcmp(pname,"base64") == 0)
                base64=1;
+#ifdef ZLIB
+       if (strcmp(pname,"zlib") == 0)
+               do_zlib=1;
+#endif
 
        cipher=EVP_get_cipherbyname(pname);
+#ifdef ZLIB
+       if (!do_zlib && !base64 && (cipher == NULL)
+                               && (strcmp(pname,"enc") != 0))
+#else
        if (!base64 && (cipher == NULL) && (strcmp(pname,"enc") != 0))
+#endif
                {
                BIO_printf(bio_err,"%s is an unknown cipher\n",pname);
                goto bad;
@@ -197,6 +210,10 @@ int MAIN(int argc, char **argv)
                        base64=1;
                else if (strcmp(*argv,"-base64") == 0)
                        base64=1;
+#ifdef ZLIB
+               else if (strcmp(*argv,"-z") == 0)
+                       do_zlib=1;
+#endif
                else if (strcmp(*argv,"-bufsize") == 0)
                        {
                        if (--argc < 1) goto bad;
@@ -264,8 +281,6 @@ int MAIN(int argc, char **argv)
                        if (--argc < 1) goto bad;
                        md= *(++argv);
                        }
-               else if (strcmp(*argv,"-non-fips-allow") == 0)
-                       non_fips_allow = 1;
                else if ((argv[0][0] == '-') &&
                        ((c=EVP_get_cipherbyname(&(argv[0][1]))) != NULL))
                        {
@@ -288,9 +303,11 @@ bad:
                        BIO_printf(bio_err,"%-14s passphrase is the first line of the file argument\n","-kfile");
                        BIO_printf(bio_err,"%-14s the next argument is the md to use to create a key\n","-md");
                        BIO_printf(bio_err,"%-14s   from a passphrase.  One of md2, md5, sha or sha1\n","");
+                       BIO_printf(bio_err,"%-14s salt in hex is the next argument\n","-S");
                        BIO_printf(bio_err,"%-14s key/iv in hex is the next argument\n","-K/-iv");
                        BIO_printf(bio_err,"%-14s print the iv/key (then exit if -P)\n","-[pP]");
                        BIO_printf(bio_err,"%-14s buffer size\n","-bufsize <n>");
+                       BIO_printf(bio_err,"%-14s disable standard block padding\n","-nopad");
 #ifndef OPENSSL_NO_ENGINE
                        BIO_printf(bio_err,"%-14s use engine e, possibly a hardware device.\n","-engine e");
 #endif
@@ -319,10 +336,7 @@ bad:
 
        if (dgst == NULL)
                {
-               if (in_FIPS_mode)
-                       dgst = EVP_sha1();
-               else
-                       dgst = EVP_md5();
+               dgst = EVP_md5();
                }
 
        if (bufsize != NULL)
@@ -379,8 +393,10 @@ bad:
 
        if (inf == NULL)
                {
+#ifndef OPENSSL_NO_SETVBUF_IONBF
                if (bufsize != NULL)
                        setvbuf(stdin, (char *)NULL, _IONBF, 0);
+#endif /* ndef OPENSSL_NO_SETVBUF_IONBF */
                BIO_set_fp(in,stdin,BIO_NOCLOSE);
                }
        else
@@ -433,8 +449,10 @@ bad:
        if (outf == NULL)
                {
                BIO_set_fp(out,stdout,BIO_NOCLOSE);
+#ifndef OPENSSL_NO_SETVBUF_IONBF
                if (bufsize != NULL)
                        setvbuf(stdout, (char *)NULL, _IONBF, 0);
+#endif /* ndef OPENSSL_NO_SETVBUF_IONBF */
 #ifdef OPENSSL_SYS_VMS
                {
                BIO *tmpbio = BIO_new(BIO_f_linebuffer());
@@ -454,6 +472,19 @@ bad:
        rbio=in;
        wbio=out;
 
+#ifdef ZLIB
+
+       if (do_zlib)
+               {
+               if ((bzl=BIO_new(BIO_f_zlib())) == NULL)
+                       goto end;
+               if (enc)
+                       wbio=BIO_push(bzl,wbio);
+               else
+                       rbio=BIO_push(bzl,rbio);
+               }
+#endif
+
        if (base64)
                {
                if ((b64=BIO_new(BIO_f_base64())) == NULL)
@@ -558,11 +589,6 @@ bad:
                 */
 
                BIO_get_cipher_ctx(benc, &ctx);
-
-               if (non_fips_allow)
-                       EVP_CIPHER_CTX_set_flags(ctx,
-                               EVP_CIPH_FLAG_NON_FIPS_ALLOW);
-
                if (!EVP_CipherInit_ex(ctx, cipher, NULL, NULL, NULL, enc))
                        {
                        BIO_printf(bio_err, "Error setting cipher %s\n",
@@ -653,6 +679,9 @@ end:
        if (out != NULL) BIO_free_all(out);
        if (benc != NULL) BIO_free(benc);
        if (b64 != NULL) BIO_free(b64);
+#ifdef ZLIB
+       if (bzl != NULL) BIO_free(bzl);
+#endif
        if(pass) OPENSSL_free(pass);
        apps_shutdown();
        OPENSSL_EXIT(ret);
index 17bd81f..9a02943 100644 (file)
@@ -92,7 +92,7 @@ static const char *engine_usage[]={
 NULL
 };
 
-static void identity(void *ptr)
+static void identity(char *ptr)
        {
        return;
        }
@@ -148,11 +148,6 @@ static int util_flags(BIO *bio_out, unsigned int flags, const char *indent)
 
        if(flags & ENGINE_CMD_FLAG_NUMERIC)
                {
-               if(started)
-                       {
-                       BIO_printf(bio_out, "|");
-                       err = 1;
-                       }
                BIO_printf(bio_out, "NUMERIC");
                started = 1;
                }
@@ -205,7 +200,7 @@ static int util_verbose(ENGINE *e, int verbose, BIO *bio_out, const char *indent
        char *desc = NULL;
        int flags;
        int xpos = 0;
-       STACK *cmds = NULL;
+       STACK_OF(OPENSSL_STRING) *cmds = NULL;
        if(!ENGINE_ctrl(e, ENGINE_CTRL_HAS_CTRL_FUNCTION, 0, NULL, NULL) ||
                        ((num = ENGINE_ctrl(e, ENGINE_CTRL_GET_FIRST_CMD_TYPE,
                                        0, NULL, NULL)) <= 0))
@@ -216,7 +211,7 @@ static int util_verbose(ENGINE *e, int verbose, BIO *bio_out, const char *indent
                return 1;
                }
 
-       cmds = sk_new_null();
+       cmds = sk_OPENSSL_STRING_new_null();
 
        if(!cmds)
                goto err;
@@ -289,15 +284,17 @@ static int util_verbose(ENGINE *e, int verbose, BIO *bio_out, const char *indent
                BIO_printf(bio_out, "\n");
        ret = 1;
 err:
-       if(cmds) sk_pop_free(cmds, identity);
+       if(cmds) sk_OPENSSL_STRING_pop_free(cmds, identity);
        if(name) OPENSSL_free(name);
        if(desc) OPENSSL_free(desc);
        return ret;
        }
 
-static void util_do_cmds(ENGINE *e, STACK *cmds, BIO *bio_out, const char *indent)
+static void util_do_cmds(ENGINE *e, STACK_OF(OPENSSL_STRING) *cmds,
+                       BIO *bio_out, const char *indent)
        {
-       int loop, res, num = sk_num(cmds);
+       int loop, res, num = sk_OPENSSL_STRING_num(cmds);
+
        if(num < 0)
                {
                BIO_printf(bio_out, "[Error]: internal stack error\n");
@@ -307,7 +304,7 @@ static void util_do_cmds(ENGINE *e, STACK *cmds, BIO *bio_out, const char *inden
                {
                char buf[256];
                const char *cmd, *arg;
-               cmd = sk_value(cmds, loop);
+               cmd = sk_OPENSSL_STRING_value(cmds, loop);
                res = 1; /* assume success */
                /* Check if this command has no ":arg" */
                if((arg = strstr(cmd, ":")) == NULL)
@@ -347,9 +344,9 @@ int MAIN(int argc, char **argv)
        const char **pp;
        int verbose=0, list_cap=0, test_avail=0, test_avail_noise = 0;
        ENGINE *e;
-       STACK *engines = sk_new_null();
-       STACK *pre_cmds = sk_new_null();
-       STACK *post_cmds = sk_new_null();
+       STACK_OF(OPENSSL_STRING) *engines = sk_OPENSSL_STRING_new_null();
+       STACK_OF(OPENSSL_STRING) *pre_cmds = sk_OPENSSL_STRING_new_null();
+       STACK_OF(OPENSSL_STRING) *post_cmds = sk_OPENSSL_STRING_new_null();
        int badops=1;
        BIO *bio_out=NULL;
        const char *indent = "     ";
@@ -396,20 +393,20 @@ int MAIN(int argc, char **argv)
                        argc--; argv++;
                        if (argc == 0)
                                goto skip_arg_loop;
-                       sk_push(pre_cmds,*argv);
+                       sk_OPENSSL_STRING_push(pre_cmds,*argv);
                        }
                else if (strcmp(*argv,"-post") == 0)
                        {
                        argc--; argv++;
                        if (argc == 0)
                                goto skip_arg_loop;
-                       sk_push(post_cmds,*argv);
+                       sk_OPENSSL_STRING_push(post_cmds,*argv);
                        }
                else if ((strncmp(*argv,"-h",2) == 0) ||
                                (strcmp(*argv,"-?") == 0))
                        goto skip_arg_loop;
                else
-                       sk_push(engines,*argv);
+                       sk_OPENSSL_STRING_push(engines,*argv);
                argc--;
                argv++;
                }
@@ -424,17 +421,17 @@ skip_arg_loop:
                goto end;
                }
 
-       if (sk_num(engines) == 0)
+       if (sk_OPENSSL_STRING_num(engines) == 0)
                {
                for(e = ENGINE_get_first(); e != NULL; e = ENGINE_get_next(e))
                        {
-                       sk_push(engines,(char *)ENGINE_get_id(e));
+                       sk_OPENSSL_STRING_push(engines,(char *)ENGINE_get_id(e));
                        }
                }
 
-       for (i=0; i<sk_num(engines); i++)
+       for (i=0; i<sk_OPENSSL_STRING_num(engines); i++)
                {
-               const char *id = sk_value(engines,i);
+               const char *id = sk_OPENSSL_STRING_value(engines,i);
                if ((e = ENGINE_by_id(id)) != NULL)
                        {
                        const char *name = ENGINE_get_name(e);
@@ -454,6 +451,7 @@ skip_arg_loop:
                                const int *nids;
                                ENGINE_CIPHERS_PTR fn_c;
                                ENGINE_DIGESTS_PTR fn_d;
+                               ENGINE_PKEY_METHS_PTR fn_pk;
 
                                if (ENGINE_get_RSA(e) != NULL
                                        && !append_buf(&cap_buf, "RSA",
@@ -492,6 +490,15 @@ skip_ciphers:
                                                goto end;
 
 skip_digests:
+                               fn_pk = ENGINE_get_pkey_meths(e);
+                               if(!fn_pk) goto skip_pmeths;
+                               n = fn_pk(e, NULL, &nids, 0);
+                               for(k=0 ; k < n ; ++k)
+                                       if(!append_buf(&cap_buf,
+                                                      OBJ_nid2sn(nids[k]),
+                                                      &cap_size, 256))
+                                               goto end;
+skip_pmeths:
                                if (cap_buf && (*cap_buf != '\0'))
                                        BIO_printf(bio_out, " [%s]\n", cap_buf);
 
@@ -526,9 +533,9 @@ skip_digests:
 end:
 
        ERR_print_errors(bio_err);
-       sk_pop_free(engines, identity);
-       sk_pop_free(pre_cmds, identity);
-       sk_pop_free(post_cmds, identity);
+       sk_OPENSSL_STRING_pop_free(engines, identity);
+       sk_OPENSSL_STRING_pop_free(pre_cmds, identity);
+       sk_OPENSSL_STRING_pop_free(post_cmds, identity);
        if (bio_out != NULL) BIO_free_all(bio_out);
        apps_shutdown();
        OPENSSL_EXIT(ret);
index 19489b0..fe3b980 100644 (file)
@@ -97,10 +97,12 @@ int MAIN(int argc, char **argv)
                        out = BIO_push(tmpbio, out);
                        }
 #endif
-                       lh_node_stats_bio((LHASH *)ERR_get_string_table(),out);
-                       lh_stats_bio((LHASH *)ERR_get_string_table(),out);
-                       lh_node_usage_stats_bio((LHASH *)
-                               ERR_get_string_table(),out);
+                       lh_ERR_STRING_DATA_node_stats_bio(
+                                                 ERR_get_string_table(), out);
+                       lh_ERR_STRING_DATA_stats_bio(ERR_get_string_table(),
+                                                    out);
+                       lh_ERR_STRING_DATA_node_usage_stats_bio(
+                                                   ERR_get_string_table(),out);
                        }
                if (out != NULL) BIO_free_all(out);
                argc--;
index 346ea4a..4ec776b 100644 (file)
@@ -232,4 +232,10 @@ static int MS_CALLBACK dh_cb(int p, int n, BN_GENCB *cb)
 #endif
        return 1;
        }
+#else /* !OPENSSL_NO_DH */
+
+# if PEDANTIC
+static void *dummy=&dummy;
+# endif
+
 #endif
diff --git a/deps/openssl/openssl/apps/genpkey.c b/deps/openssl/openssl/apps/genpkey.c
new file mode 100644 (file)
index 0000000..6dfda08
--- /dev/null
@@ -0,0 +1,440 @@
+/* apps/genpkey.c */
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project 2006
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+#include <stdio.h>
+#include <string.h>
+#include "apps.h"
+#include <openssl/pem.h>
+#include <openssl/err.h>
+#include <openssl/evp.h>
+#ifndef OPENSSL_NO_ENGINE
+#include <openssl/engine.h>
+#endif
+
+static int init_keygen_file(BIO *err, EVP_PKEY_CTX **pctx,
+                               const char *file, ENGINE *e);
+static int genpkey_cb(EVP_PKEY_CTX *ctx);
+
+#define PROG genpkey_main
+
+int MAIN(int, char **);
+
+int MAIN(int argc, char **argv)
+       {
+       ENGINE *e = NULL;
+       char **args, *outfile = NULL;
+       char *passarg = NULL;
+       BIO *in = NULL, *out = NULL;
+       const EVP_CIPHER *cipher = NULL;
+       int outformat;
+       int text = 0;
+       EVP_PKEY *pkey=NULL;
+       EVP_PKEY_CTX *ctx = NULL;
+       char *pass = NULL;
+       int badarg = 0;
+       int ret = 1, rv;
+
+       int do_param = 0;
+
+       if (bio_err == NULL)
+               bio_err = BIO_new_fp (stderr, BIO_NOCLOSE);
+
+       if (!load_config(bio_err, NULL))
+               goto end;
+
+       outformat=FORMAT_PEM;
+
+       ERR_load_crypto_strings();
+       OpenSSL_add_all_algorithms();
+       args = argv + 1;
+       while (!badarg && *args && *args[0] == '-')
+               {
+               if (!strcmp(*args,"-outform"))
+                       {
+                       if (args[1])
+                               {
+                               args++;
+                               outformat=str2fmt(*args);
+                               }
+                       else badarg = 1;
+                       }
+               else if (!strcmp(*args,"-pass"))
+                       {
+                       if (!args[1]) goto bad;
+                       passarg= *(++args);
+                       }
+#ifndef OPENSSL_NO_ENGINE
+               else if (strcmp(*args,"-engine") == 0)
+                       {
+                       if (!args[1])
+                               goto bad;
+                       e = setup_engine(bio_err, *(++args), 0);
+                       }
+#endif
+               else if (!strcmp (*args, "-paramfile"))
+                       {
+                       if (!args[1])
+                               goto bad;
+                       args++;
+                       if (do_param == 1)
+                               goto bad;
+                       if (!init_keygen_file(bio_err, &ctx, *args, e))
+                               goto end;
+                       }
+               else if (!strcmp (*args, "-out"))
+                       {
+                       if (args[1])
+                               {
+                               args++;
+                               outfile = *args;
+                               }
+                       else badarg = 1;
+                       }
+               else if (strcmp(*args,"-algorithm") == 0)
+                       {
+                       if (!args[1])
+                               goto bad;
+                       if (!init_gen_str(bio_err, &ctx, *(++args),e, do_param))
+                               goto end;
+                       }
+               else if (strcmp(*args,"-pkeyopt") == 0)
+                       {
+                       if (!args[1])
+                               goto bad;
+                       if (!ctx)
+                               {
+                               BIO_puts(bio_err, "No keytype specified\n");
+                               goto bad;
+                               }
+                       else if (pkey_ctrl_string(ctx, *(++args)) <= 0)
+                               {
+                               BIO_puts(bio_err, "parameter setting error\n");
+                               ERR_print_errors(bio_err);
+                               goto end;
+                               }
+                       }
+               else if (strcmp(*args,"-genparam") == 0)
+                       {
+                       if (ctx)
+                               goto bad;
+                       do_param = 1;
+                       }
+               else if (strcmp(*args,"-text") == 0)
+                       text=1;
+               else
+                       {
+                       cipher = EVP_get_cipherbyname(*args + 1);
+                       if (!cipher)
+                               {
+                               BIO_printf(bio_err, "Unknown cipher %s\n",
+                                                               *args + 1);
+                               badarg = 1;
+                               }
+                       if (do_param == 1)
+                               badarg = 1;
+                       }
+               args++;
+               }
+
+       if (!ctx)
+               badarg = 1;
+
+       if (badarg)
+               {
+               bad:
+               BIO_printf(bio_err, "Usage: genpkey [options]\n");
+               BIO_printf(bio_err, "where options may be\n");
+               BIO_printf(bio_err, "-out file          output file\n");
+               BIO_printf(bio_err, "-outform X         output format (DER or PEM)\n");
+               BIO_printf(bio_err, "-pass arg          output file pass phrase source\n");
+               BIO_printf(bio_err, "-<cipher>          use cipher <cipher> to encrypt the key\n");
+#ifndef OPENSSL_NO_ENGINE
+               BIO_printf(bio_err, "-engine e          use engine e, possibly a hardware device.\n");
+#endif
+               BIO_printf(bio_err, "-paramfile file    parameters file\n");
+               BIO_printf(bio_err, "-algorithm alg     the public key algorithm\n");
+               BIO_printf(bio_err, "-pkeyopt opt:value set the public key algorithm option <opt>\n"
+                                           "                   to value <value>\n");
+               BIO_printf(bio_err, "-genparam          generate parameters, not key\n");
+               BIO_printf(bio_err, "-text              print the in text\n");
+               BIO_printf(bio_err, "NB: options order may be important!  See the manual page.\n");
+               goto end;
+               }
+
+       if (!app_passwd(bio_err, passarg, NULL, &pass, NULL))
+               {
+               BIO_puts(bio_err, "Error getting password\n");
+               goto end;
+               }
+
+       if (outfile)
+               {
+               if (!(out = BIO_new_file (outfile, "wb")))
+                       {
+                       BIO_printf(bio_err,
+                                "Can't open output file %s\n", outfile);
+                       goto end;
+                       }
+               }
+       else
+               {
+               out = BIO_new_fp (stdout, BIO_NOCLOSE);
+#ifdef OPENSSL_SYS_VMS
+                       {
+                       BIO *tmpbio = BIO_new(BIO_f_linebuffer());
+                       out = BIO_push(tmpbio, out);
+                       }
+#endif
+               }
+
+       EVP_PKEY_CTX_set_cb(ctx, genpkey_cb);
+       EVP_PKEY_CTX_set_app_data(ctx, bio_err);
+
+       if (do_param)
+               {
+               if (EVP_PKEY_paramgen(ctx, &pkey) <= 0)
+                       {
+                       BIO_puts(bio_err, "Error generating parameters\n");
+                       ERR_print_errors(bio_err);
+                       goto end;
+                       }
+               }
+       else
+               {
+               if (EVP_PKEY_keygen(ctx, &pkey) <= 0)
+                       {
+                       BIO_puts(bio_err, "Error generating key\n");
+                       ERR_print_errors(bio_err);
+                       goto end;
+                       }
+               }
+
+       if (do_param)
+               rv = PEM_write_bio_Parameters(out, pkey);
+       else if (outformat == FORMAT_PEM) 
+               rv = PEM_write_bio_PrivateKey(out, pkey, cipher, NULL, 0,
+                                                               NULL, pass);
+       else if (outformat == FORMAT_ASN1)
+               rv = i2d_PrivateKey_bio(out, pkey);
+       else
+               {
+               BIO_printf(bio_err, "Bad format specified for key\n");
+               goto end;
+               }
+
+       if (rv <= 0)
+               {
+               BIO_puts(bio_err, "Error writing key\n");
+               ERR_print_errors(bio_err);
+               }
+
+       if (text)
+               {
+               if (do_param)
+                       rv = EVP_PKEY_print_params(out, pkey, 0, NULL);
+               else
+                       rv = EVP_PKEY_print_private(out, pkey, 0, NULL);
+
+               if (rv <= 0)
+                       {
+                       BIO_puts(bio_err, "Error printing key\n");
+                       ERR_print_errors(bio_err);
+                       }
+               }
+
+       ret = 0;
+
+       end:
+       if (pkey)
+               EVP_PKEY_free(pkey);
+       if (ctx)
+               EVP_PKEY_CTX_free(ctx);
+       if (out)
+               BIO_free_all(out);
+       BIO_free(in);
+       if (pass)
+               OPENSSL_free(pass);
+
+       return ret;
+       }
+
+static int init_keygen_file(BIO *err, EVP_PKEY_CTX **pctx,
+                               const char *file, ENGINE *e)
+       {
+       BIO *pbio;
+       EVP_PKEY *pkey = NULL;
+       EVP_PKEY_CTX *ctx = NULL;
+       if (*pctx)
+               {
+               BIO_puts(err, "Parameters already set!\n");
+               return 0;
+               }
+
+       pbio = BIO_new_file(file, "r");
+       if (!pbio)
+               {
+               BIO_printf(err, "Can't open parameter file %s\n", file);
+               return 0;
+               }
+
+       pkey = PEM_read_bio_Parameters(pbio, NULL);
+       BIO_free(pbio);
+
+       if (!pkey)
+               {
+               BIO_printf(bio_err, "Error reading parameter file %s\n", file);
+               return 0;
+               }
+
+       ctx = EVP_PKEY_CTX_new(pkey, e);
+       if (!ctx)
+               goto err;
+       if (EVP_PKEY_keygen_init(ctx) <= 0)
+               goto err;
+       EVP_PKEY_free(pkey);
+       *pctx = ctx;
+       return 1;
+
+       err:
+       BIO_puts(err, "Error initializing context\n");
+       ERR_print_errors(err);
+       if (ctx)
+               EVP_PKEY_CTX_free(ctx);
+       if (pkey)
+               EVP_PKEY_free(pkey);
+       return 0;
+
+       }
+
+int init_gen_str(BIO *err, EVP_PKEY_CTX **pctx,
+                       const char *algname, ENGINE *e, int do_param)
+       {
+       EVP_PKEY_CTX *ctx = NULL;
+       const EVP_PKEY_ASN1_METHOD *ameth;
+       ENGINE *tmpeng = NULL;
+       int pkey_id;
+
+       if (*pctx)
+               {
+               BIO_puts(err, "Algorithm already set!\n");
+               return 0;
+               }
+
+       ameth = EVP_PKEY_asn1_find_str(&tmpeng, algname, -1);
+
+#ifndef OPENSSL_NO_ENGINE
+       if (!ameth && e)
+               ameth = ENGINE_get_pkey_asn1_meth_str(e, algname, -1);
+#endif
+
+       if (!ameth)
+               {
+               BIO_printf(bio_err, "Algorithm %s not found\n", algname);
+               return 0;
+               }
+
+       ERR_clear_error();
+
+       EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, NULL, NULL, ameth);
+#ifndef OPENSSL_NO_ENGINE
+       if (tmpeng)
+               ENGINE_finish(tmpeng);
+#endif
+       ctx = EVP_PKEY_CTX_new_id(pkey_id, e);
+
+       if (!ctx)
+               goto err;
+       if (do_param)
+               {
+               if (EVP_PKEY_paramgen_init(ctx) <= 0)
+                       goto err;
+               }
+       else
+               {
+               if (EVP_PKEY_keygen_init(ctx) <= 0)
+                       goto err;
+               }
+
+       *pctx = ctx;
+       return 1;
+
+       err:
+       BIO_printf(err, "Error initializing %s context\n", algname);
+       ERR_print_errors(err);
+       if (ctx)
+               EVP_PKEY_CTX_free(ctx);
+       return 0;
+
+       }
+
+static int genpkey_cb(EVP_PKEY_CTX *ctx)
+       {
+       char c='*';
+       BIO *b = EVP_PKEY_CTX_get_app_data(ctx);
+       int p;
+       p = EVP_PKEY_CTX_get_keygen_info(ctx, 0);
+       if (p == 0) c='.';
+       if (p == 1) c='+';
+       if (p == 2) c='*';
+       if (p == 3) c='\n';
+       BIO_write(b,&c,1);
+       (void)BIO_flush(b);
+#ifdef LINT
+       p=n;
+#endif
+       return 1;
+       }
index dfb0139..37e9310 100644 (file)
@@ -89,10 +89,12 @@ int MAIN(int, char **);
 int MAIN(int argc, char **argv)
        {
        BN_GENCB cb;
+#ifndef OPENSSL_NO_ENGINE
+       ENGINE *e = NULL;
+#endif
        int ret=1;
        int i,num=DEFBITS;
        long l;
-       int use_x931 = 0;
        const EVP_CIPHER *enc=NULL;
        unsigned long f4=RSA_F4;
        char *outfile=NULL;
@@ -136,8 +138,6 @@ int MAIN(int argc, char **argv)
                        f4=3;
                else if (strcmp(*argv,"-F4") == 0 || strcmp(*argv,"-f4") == 0)
                        f4=RSA_F4;
-               else if (strcmp(*argv,"-x931") == 0)
-                       use_x931 = 1;
 #ifndef OPENSSL_NO_ENGINE
                else if (strcmp(*argv,"-engine") == 0)
                        {
@@ -232,7 +232,7 @@ bad:
        }
 
 #ifndef OPENSSL_NO_ENGINE
-        setup_engine(bio_err, engine, 0);
+        e = setup_engine(bio_err, engine, 0);
 #endif
 
        if (outfile == NULL)
@@ -265,22 +265,15 @@ bad:
 
        BIO_printf(bio_err,"Generating RSA private key, %d bit long modulus\n",
                num);
-
+#ifdef OPENSSL_NO_ENGINE
        rsa = RSA_new();
+#else
+       rsa = RSA_new_method(e);
+#endif
        if (!rsa)
                goto err;
 
-       if (use_x931)
-               {
-               BIGNUM *pubexp;
-               pubexp = BN_new();
-               if (!BN_set_word(pubexp, f4))
-                       goto err;
-               if (!RSA_X931_generate_key_ex(rsa, num, pubexp, &cb))
-                       goto err;
-               BN_free(pubexp);
-               }
-       else if(!BN_set_word(bn, f4) || !RSA_generate_key_ex(rsa, num, bn, &cb))
+       if(!BN_set_word(bn, f4) || !RSA_generate_key_ex(rsa, num, bn, &cb))
                goto err;
                
        app_RAND_write_file(NULL, bio_err);
diff --git a/deps/openssl/openssl/apps/install-apps.com b/deps/openssl/openssl/apps/install-apps.com
new file mode 100644 (file)
index 0000000..7a553aa
--- /dev/null
@@ -0,0 +1,107 @@
+$! INSTALL.COM -- Installs the files in a given directory tree
+$!
+$! Author: Richard Levitte <richard@levitte.org>
+$! Time of creation: 22-MAY-1998 10:13
+$!
+$! P1  root of the directory tree
+$! P2  "64" for 64-bit pointers.
+$!
+$!
+$! Announce/identify.
+$!
+$ proc = f$environment( "procedure")
+$ write sys$output "@@@ "+ -
+   f$parse( proc, , , "name")+ f$parse( proc, , , "type")
+$!
+$ on error then goto tidy
+$ on control_c then goto tidy
+$!
+$ if (p1 .eqs. "")
+$ then
+$   write sys$output "First argument missing."
+$   write sys$output -
+     "It should be the directory where you want things installed."
+$   exit
+$ endif
+$!
+$ if (f$getsyi("cpu") .lt. 128)
+$ then
+$   arch = "VAX"
+$ else
+$   arch = f$edit( f$getsyi( "arch_name"), "upcase")
+$   if (arch .eqs. "") then arch = "UNK"
+$ endif
+$!
+$ archd = arch
+$!
+$ if (p2 .nes. "")
+$ then
+$   if (p2 .eqs. "64")
+$   then
+$     archd = arch+ "_64"
+$   else
+$     if (p2 .nes. "32")
+$     then
+$       write sys$output "Second argument invalid."
+$       write sys$output "It should be "32", "64", or nothing."
+$       exit
+$     endif
+$   endif
+$ endif
+$!
+$ root = f$parse( p1, "[]A.;0", , , "syntax_only, no_conceal") - "A.;0"
+$ root_dev = f$parse(root,,,"device","syntax_only")
+$ root_dir = f$parse(root,,,"directory","syntax_only") - -
+   "[000000." - "][" - "[" - "]"
+$ root = root_dev + "[" + root_dir
+$!
+$ define /nolog wrk_sslroot 'root'.] /trans=conc
+$ define /nolog wrk_sslxexe wrk_sslroot:['archd'_exe]
+$!
+$ if f$parse("wrk_sslroot:[000000]") .eqs. "" then -
+   create /directory /log wrk_sslroot:[000000]
+$ if f$parse("wrk_sslxexe:") .eqs. "" then -
+   create /directory /log wrk_sslxexe:
+$!
+$ exe := openssl
+$!
+$ exe_dir := [-.'archd'.exe.apps]
+$!
+$! Executables.
+$!
+$ i = 0
+$ loop_exe:
+$   e = f$edit(f$element( i, ",", exe), "trim")
+$   i = i + 1
+$   if e .eqs. "," then goto loop_exe_end
+$   set noon
+$   file = exe_dir+ e+ ".exe"
+$   if f$search( file) .nes. ""
+$   then
+$     copy /protection = w:re 'file' wrk_sslxexe: /log
+$   endif
+$   set on
+$ goto loop_exe
+$ loop_exe_end:
+$!
+$! Miscellaneous.
+$!
+$ set noon
+$ copy /protection = w:re ca.com wrk_sslxexe:ca.com /log
+$ copy /protection = w:re openssl-vms.cnf wrk_sslroot:[000000]openssl.cnf /log
+$ set on
+$!
+$ tidy:
+$!
+$ call deass wrk_sslroot
+$ call deass wrk_sslxexe
+$!
+$ exit
+$!
+$ deass: subroutine
+$ if (f$trnlnm( p1, "LNM$PROCESS") .nes. "")
+$ then
+$   deassign /process 'p1'
+$ endif
+$ endsubroutine
+$!
diff --git a/deps/openssl/openssl/apps/install.com b/deps/openssl/openssl/apps/install.com
deleted file mode 100644 (file)
index c5821b4..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-$! INSTALL.COM -- Installs the files in a given directory tree
-$!
-$! Author: Richard Levitte <richard@levitte.org>
-$! Time of creation: 22-MAY-1998 10:13
-$!
-$! P1  root of the directory tree
-$!
-$
-$      IF P1 .EQS. ""
-$      THEN
-$          WRITE SYS$OUTPUT "First argument missing."
-$          WRITE SYS$OUTPUT -
-                 "Should be the directory where you want things installed."
-$          EXIT
-$      ENDIF
-$
-$      IF (F$GETSYI("CPU").LT.128)
-$      THEN
-$          ARCH := VAX
-$      ELSE
-$          ARCH = F$EDIT( F$GETSYI( "ARCH_NAME"), "UPCASE")
-$          IF (ARCH .EQS. "") THEN ARCH = "UNK"
-$      ENDIF
-$
-$      ROOT = F$PARSE(P1,"[]A.;0",,,"SYNTAX_ONLY,NO_CONCEAL") - "A.;0"
-$      ROOT_DEV = F$PARSE(ROOT,,,"DEVICE","SYNTAX_ONLY")
-$      ROOT_DIR = F$PARSE(ROOT,,,"DIRECTORY","SYNTAX_ONLY") -
-                  - "[000000." - "][" - "[" - "]"
-$      ROOT = ROOT_DEV + "[" + ROOT_DIR
-$
-$      DEFINE/NOLOG WRK_SSLROOT 'ROOT'.] /TRANS=CONC
-$      DEFINE/NOLOG WRK_SSLEXE WRK_SSLROOT:['ARCH'_EXE]
-$
-$      IF F$PARSE("WRK_SSLROOT:[000000]") .EQS. "" THEN -
-          CREATE/DIR/LOG WRK_SSLROOT:[000000]
-$      IF F$PARSE("WRK_SSLEXE:") .EQS. "" THEN -
-          CREATE/DIR/LOG WRK_SSLEXE:
-$
-$      EXE := openssl
-$
-$      EXE_DIR := [-.'ARCH'.EXE.APPS]
-$
-$      I = 0
-$ LOOP_EXE: 
-$      E = F$EDIT(F$ELEMENT(I, ",", EXE),"TRIM")
-$      I = I + 1
-$      IF E .EQS. "," THEN GOTO LOOP_EXE_END
-$      SET NOON
-$      IF F$SEARCH(EXE_DIR+E+".EXE") .NES. ""
-$      THEN
-$        COPY 'EXE_DIR''E'.EXE WRK_SSLEXE:'E'.EXE/log
-$        SET FILE/PROT=W:RE WRK_SSLEXE:'E'.EXE
-$      ENDIF
-$      SET ON
-$      GOTO LOOP_EXE
-$ LOOP_EXE_END:
-$
-$      SET NOON
-$      COPY CA.COM WRK_SSLEXE:CA.COM/LOG
-$      SET FILE/PROT=W:RE WRK_SSLEXE:CA.COM
-$      COPY OPENSSL-VMS.CNF WRK_SSLROOT:[000000]OPENSSL.CNF/LOG
-$      SET FILE/PROT=W:R WRK_SSLROOT:[000000]OPENSSL.CNF
-$      SET ON
-$
-$      EXIT
index cb749bf..71417a8 100644 (file)
@@ -25,7 +25,7 @@ $!       VAXC  For VAX C.
 $!        DECC  For DEC C.
 $!        GNUC  For GNU C.
 $!
-$!  If you don't speficy a compiler, it will try to determine which
+$!  If you don't specify a compiler, it will try to determine which
 $!  "C" compiler to use.
 $!
 $!  P3, if defined, sets a TCP/IP library to use, through one of the following
@@ -39,11 +39,35 @@ $!  P4, if defined, sets a compiler thread NOT needed on OpenVMS 7.1 (and up)
 $!
 $!  P5, if defined, sets a choice of programs to compile.
 $!
+$!  P6, if defined, specifies the C pointer size.  Ignored on VAX.
+$!      ("64=ARGV" gives more efficient code with HP C V7.3 or newer.)
+$!      Supported values are:
+$!
+$!      ""       Compile with default (/NOPOINTER_SIZE)
+$!      32       Compile with /POINTER_SIZE=32 (SHORT)
+$!      64       Compile with /POINTER_SIZE=64[=ARGV] (LONG[=ARGV])
+$!               (Automatically select ARGV if compiler supports it.)
+$!      64=      Compile with /POINTER_SIZE=64 (LONG).
+$!      64=ARGV  Compile with /POINTER_SIZE=64=ARGV (LONG=ARGV).
+$!
+$!  P7, if defined, specifies a directory where ZLIB files (zlib.h,
+$!  libz.olb) may be found.  Optionally, a non-default object library
+$!  name may be included ("dev:[dir]libz_64.olb", for example).
+$!
+$!
+$! Announce/identify.
+$!
+$ proc = f$environment( "procedure")
+$ write sys$output "@@@ "+ -
+   f$parse( proc, , , "name")+ f$parse( proc, , , "type")
+$!
+$ on control_c then goto exit
 $!
 $! Define A TCP/IP Library That We Will Need To Link To.
 $! (That Is, If We Need To Link To One.)
 $!
 $ TCPIP_LIB = ""
+$ ZLIB_LIB = ""
 $!
 $! Check What Architecture We Are Using.
 $!
@@ -52,7 +76,7 @@ $ THEN
 $!
 $!  The Architecture Is VAX.
 $!
-$   ARCH := VAX
+$   ARCH = "VAX"
 $!
 $! Else...
 $!
@@ -67,29 +91,45 @@ $! End The Architecture Check.
 $!
 $ ENDIF
 $!
+$ ARCHD = ARCH
+$ LIB32 = "32"
+$ OPT_FILE = ""
+$ POINTER_SIZE = ""
+$!
 $! Define what programs should be compiled
 $!
 $ PROGRAMS := OPENSSL
 $!
+$! Check To Make Sure We Have Valid Command Line Parameters.
+$!
+$ GOSUB CHECK_OPTIONS
+$!
 $! Define The CRYPTO Library.
 $!
-$ CRYPTO_LIB := SYS$DISK:[-.'ARCH'.EXE.CRYPTO]LIBCRYPTO.OLB
+$ CRYPTO_LIB := SYS$DISK:[-.'ARCHD'.EXE.CRYPTO]SSL_LIBCRYPTO'LIB32'.OLB
 $!
 $! Define The SSL Library.
 $!
-$ SSL_LIB := SYS$DISK:[-.'ARCH'.EXE.SSL]LIBSSL.OLB
+$ SSL_LIB := SYS$DISK:[-.'ARCHD'.EXE.SSL]SSL_LIBSSL'LIB32'.OLB
 $!
-$! Define The OBJ Directory.
+$! Define The OBJ and EXE Directories.
 $!
-$ OBJ_DIR := SYS$DISK:[-.'ARCH'.OBJ.APPS]
+$ OBJ_DIR := SYS$DISK:[-.'ARCHD'.OBJ.APPS]
+$ EXE_DIR := SYS$DISK:[-.'ARCHD'.EXE.APPS]
 $!
-$! Define The EXE Directory.
+$! Specify the destination directory in any /MAP option.
 $!
-$ EXE_DIR := SYS$DISK:[-.'ARCH'.EXE.APPS]
+$ if (LINKMAP .eqs. "MAP")
+$ then
+$   LINKMAP = LINKMAP+ "=''EXE_DIR'"
+$ endif
 $!
-$! Check To Make Sure We Have Valid Command Line Parameters.
+$! Add the location prefix to the linker options file name.
 $!
-$ GOSUB CHECK_OPTIONS
+$ if (OPT_FILE .nes. "")
+$ then
+$   OPT_FILE = EXE_DIR+ OPT_FILE
+$ endif
 $!
 $! Initialise logical names and such
 $!
@@ -97,7 +137,7 @@ $ GOSUB INITIALISE
 $!
 $! Tell The User What Kind of Machine We Run On.
 $!
-$ WRITE SYS$OUTPUT "Compiling On A ",ARCH," Machine."
+$ WRITE SYS$OUTPUT "Host system architecture: ''ARCHD'"
 $!
 $! Check To See If The OBJ Directory Exists.
 $!
@@ -139,12 +179,15 @@ $! reflect the E_OBJ variable in Makefile as closely as possible, thereby
 $! making it fairly easy to verify that the lists are the same.
 $!
 $ LIB_OPENSSL = "VERIFY,ASN1PARS,REQ,DGST,DH,DHPARAM,ENC,PASSWD,GENDH,ERRSTR,"+-
-               "CA,PKCS7,CRL2P7,CRL,"+-
-               "RSA,RSAUTL,DSA,DSAPARAM,EC,ECPARAM,"+-
-               "X509,GENRSA,GENDSA,S_SERVER,S_CLIENT,SPEED,"+-
-               "S_TIME,APPS,S_CB,S_SOCKET,APP_RAND,VERSION,SESS_ID,"+-
-               "CIPHERS,NSEQ,PKCS12,PKCS8,SPKAC,SMIME,RAND,ENGINE,"+-
-               "OCSP,PRIME,CMS"
+               "CA,PKCS7,CRL2P7,CRL,"+-
+               "RSA,RSAUTL,DSA,DSAPARAM,EC,ECPARAM,"+-
+               "X509,GENRSA,GENDSA,GENPKEY,S_SERVER,S_CLIENT,SPEED,"+-
+               "S_TIME,APPS,S_CB,S_SOCKET,APP_RAND,VERSION,SESS_ID,"+-
+               "CIPHERS,NSEQ,PKCS12,PKCS8,PKEY,PKEYPARAM,PKEYUTL,"+ -
+               "SPKAC,SMIME,CMS,RAND,ENGINE,OCSP,PRIME,TS"
+$!
+$ LIB_OPENSSL = LIB_OPENSSL+ ",VMS_DECC_INIT"
+$!
 $ TCPIP_PROGRAMS = ",,"
 $ IF COMPILER .EQS. "VAXC" THEN -
      TCPIP_PROGRAMS = ",OPENSSL,"
@@ -202,7 +245,7 @@ $   LIB_COUNTER = -1
 $!
 $!  Create a .OPT file for the object files
 $!
-$   OPEN/WRITE OBJECTS 'EXE_DIR''CURRENT_APP'.OPT
+$   OPEN /WRITE OBJECTS 'EXE_DIR''CURRENT_APP'.OPT
 $!
 $!  Top Of The File Loop.
 $!
@@ -289,34 +332,18 @@ $   GOTO NEXT_APP
 $ ENDIF
 $!
 $! Link The Program.
-$! Check To See If We Are To Link With A Specific TCP/IP Library.
 $!
 $ ON WARNING THEN GOTO NEXT_APP
 $!
-$ IF (TCPIP_LIB.NES."")
-$ THEN
-$!
 $! Don't Link With The RSAREF Routines And TCP/IP Library.
 $!
-$   LINK/'DEBUGGER'/'TRACEBACK' /EXE='EXE_FILE' -
-       'EXE_DIR''CURRENT_APP'.OPT/OPTION, -
-        'SSL_LIB'/LIBRARY,'CRYPTO_LIB'/LIBRARY, -
-        'TCPIP_LIB','OPT_FILE'/OPTION
-$!
-$! Else...
-$!
-$ ELSE
-$!
-$! Don't Link With The RSAREF Routines And Link With A TCP/IP Library.
-$!
-$   LINK/'DEBUGGER'/'TRACEBACK' /EXE='EXE_FILE' -
-       'EXE_DIR''CURRENT_APP'.OPT/OPTION, -
-        'SSL_LIB'/LIBRARY,'CRYPTO_LIB'/LIBRARY, -
-        'OPT_FILE'/OPTION
-$!
-$! End The TCP/IP Library Check.
-$!
-$ ENDIF
+$ LINK /'DEBUGGER' /'LINKMAP' /'TRACEBACK' /EXE='EXE_FILE' -
+  'EXE_DIR''CURRENT_APP'.OPT /OPTIONS, -
+  'SSL_LIB' /LIBRARY, -
+  'CRYPTO_LIB' /LIBRARY -
+  'TCPIP_LIB' -
+  'ZLIB_LIB' -
+  ,'OPT_FILE' /OPTIONS
 $!
 $! Go Back And Do It Again.
 $!
@@ -351,7 +378,7 @@ $!
 $     CREATE 'OPT_FILE'
 $DECK
 !
-! Default System Options File To Link Agianst 
+! Default System Options File To Link Against 
 ! The Sharable VAX C Runtime Library.
 !
 SYS$SHARE:VAXCRTL.EXE/SHARE
@@ -380,7 +407,7 @@ $!
 $     CREATE 'OPT_FILE'
 $DECK
 !
-! Default System Options File To Link Agianst 
+! Default System Options File To Link Against 
 ! The Sharable C Runtime Library.
 !
 GNU_CC:[000000]GCCLIB/LIBRARY
@@ -415,7 +442,7 @@ $!
 $       CREATE 'OPT_FILE'
 $DECK
 !
-! Default System Options File To Link Agianst 
+! Default System Options File To Link Against 
 ! The Sharable DEC C Runtime Library.
 !
 SYS$SHARE:DECC$SHR.EXE/SHARE
@@ -430,7 +457,7 @@ $!
 $       CREATE 'OPT_FILE'
 $DECK
 !
-! Default System Options File For non-VAX To Link Agianst 
+! Default System Options File For non-VAX To Link Against 
 ! The Sharable C Runtime Library.
 !
 SYS$SHARE:CMA$OPEN_LIB_SHR/SHARE
@@ -514,14 +541,15 @@ $!
 $ IF (P1.EQS."NODEBUG")
 $ THEN
 $!
-$!   P1 Is NODEBUG, So Compile Without Debugger Information.
+$!  P1 Is NODEBUG, So Compile Without Debugger Information.
 $!
-$    DEBUGGER  = "NODEBUG"
-$    TRACEBACK = "NOTRACEBACK" 
-$    GCC_OPTIMIZE = "OPTIMIZE"
-$    CC_OPTIMIZE = "OPTIMIZE"
-$    WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile."
-$    WRITE SYS$OUTPUT "Compiling With Compiler Optimization."
+$   DEBUGGER  = "NODEBUG"
+$   LINKMAP = "NOMAP"
+$   TRACEBACK = "NOTRACEBACK" 
+$   GCC_OPTIMIZE = "OPTIMIZE"
+$   CC_OPTIMIZE = "OPTIMIZE"
+$   WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile."
+$   WRITE SYS$OUTPUT "Compiling With Compiler Optimization."
 $!
 $! Else...
 $!
@@ -535,6 +563,7 @@ $!
 $!    Compile With Debugger Information.
 $!
 $     DEBUGGER  = "DEBUG"
+$     LINKMAP = "MAP"
 $     TRACEBACK = "TRACEBACK"
 $     GCC_OPTIMIZE = "NOOPTIMIZE"
 $     CC_OPTIMIZE = "NOOPTIMIZE"
@@ -542,7 +571,7 @@ $     WRITE SYS$OUTPUT "Debugger Information Will Be Produced During Compile."
 $     WRITE SYS$OUTPUT "Compiling Without Compiler Optimization."
 $   ELSE
 $!
-$!    Tell The User Entered An Invalid Option..
+$!    Tell The User Entered An Invalid Option.
 $!
 $     WRITE SYS$OUTPUT ""
 $     WRITE SYS$OUTPUT "The Option ",P1," Is Invalid.  The Valid Options Are:"
@@ -555,7 +584,7 @@ $!    Time To EXIT.
 $!
 $     EXIT
 $!
-$!  End The Valid Arguement Check.
+$!  End The Valid Argument Check.
 $!
 $   ENDIF
 $!
@@ -563,6 +592,87 @@ $! End The P1 Check.
 $!
 $ ENDIF
 $!
+$! Check P6 (POINTER_SIZE).
+$!
+$ IF (P6 .NES. "") .AND. (ARCH .NES. "VAX")
+$ THEN
+$!
+$   IF (P6 .EQS. "32")
+$   THEN
+$     POINTER_SIZE = " /POINTER_SIZE=32"
+$   ELSE
+$     POINTER_SIZE = F$EDIT( P6, "COLLAPSE, UPCASE")
+$     IF ((POINTER_SIZE .EQS. "64") .OR. -
+       (POINTER_SIZE .EQS. "64=") .OR. -
+       (POINTER_SIZE .EQS. "64=ARGV"))
+$     THEN
+$       ARCHD = ARCH+ "_64"
+$       LIB32 = ""
+$       IF (F$EXTRACT( 2, 1, POINTER_SIZE) .EQS. "=")
+$       THEN
+$!        Explicit user choice: "64" or "64=ARGV".
+$         IF (POINTER_SIZE .EQS. "64=") THEN POINTER_SIZE = "64"
+$       ELSE
+$         SET NOON
+$         DEFINE /USER_MODE SYS$OUTPUT NL:
+$         DEFINE /USER_MODE SYS$ERROR NL:
+$         CC /NOLIST /NOOBJECT /POINTER_SIZE=64=ARGV NL:
+$         IF ($STATUS .AND. %X0FFF0000) .EQ. %X00030000
+$         THEN
+$           ! If we got here, it means DCL complained like this:
+$           ! %DCL-W-NOVALU, value not allowed - remove value specification
+$           !  \64=\
+$           !
+$           ! If the compiler was run, logicals defined in /USER would
+$           ! have been deassigned automatically.  However, when DCL
+$           ! complains, they aren't, so we do it here (it might be
+$           ! unnecessary, but just in case there will be another error
+$           ! message further on that we don't want to miss)
+$           DEASSIGN /USER_MODE SYS$ERROR
+$           DEASSIGN /USER_MODE SYS$OUTPUT
+$         ELSE
+$           POINTER_SIZE = POINTER_SIZE + "=ARGV"
+$         ENDIF
+$         SET ON
+$       ENDIF
+$       POINTER_SIZE = " /POINTER_SIZE=''POINTER_SIZE'"
+$!
+$     ELSE
+$!
+$!      Tell The User Entered An Invalid Option.
+$!
+$       WRITE SYS$OUTPUT ""
+$       WRITE SYS$OUTPUT "The Option ", P6, -
+         " Is Invalid.  The Valid Options Are:"
+$       WRITE SYS$OUTPUT ""
+$       WRITE SYS$OUTPUT -
+         "    """"  :  Compile with default (short) pointers."
+$       WRITE SYS$OUTPUT -
+         "    32  :  Compile with 32-bit (short) pointers."
+$       WRITE SYS$OUTPUT -
+         "    64       :  Compile with 64-bit (long) pointers (auto ARGV)."
+$       WRITE SYS$OUTPUT -
+         "    64=      :  Compile with 64-bit (long) pointers (no ARGV)."
+$       WRITE SYS$OUTPUT -
+         "    64=ARGV  :  Compile with 64-bit (long) pointers (ARGV)."
+$       WRITE SYS$OUTPUT ""
+$! 
+$!      Time To EXIT.
+$!
+$       EXIT
+$!
+$     ENDIF
+$!
+$   ENDIF
+$!
+$! End The P6 (POINTER_SIZE) Check.
+$!
+$ ENDIF
+$!
+$! Set basic C compiler /INCLUDE directories.
+$!
+$ CC_INCLUDES = "SYS$DISK:[-],SYS$DISK:[-.CRYPTO]"
+$!
 $! Check To See If P2 Is Blank.
 $!
 $ IF (P2.EQS."")
@@ -663,11 +773,64 @@ $ CCDEFS = "MONOLITH"
 $ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS
 $ CCEXTRAFLAGS = ""
 $ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS
-$ CCDISABLEWARNINGS = "LONGLONGTYPE,LONGLONGSUFX,FOUNDCR"
+$ CCDISABLEWARNINGS = "" !!! "LONGLONGTYPE,LONGLONGSUFX,FOUNDCR"
 $ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN -
        CCDISABLEWARNINGS = CCDISABLEWARNINGS + "," + USER_CCDISABLEWARNINGS
 $!
-$!  Check To See If The User Entered A Valid Paramter.
+$! Check To See If We Have A ZLIB Option.
+$!
+$ ZLIB = P7
+$ IF (ZLIB .NES. "")
+$ THEN
+$!
+$!  Check for expected ZLIB files.
+$!
+$   err = 0
+$   file1 = f$parse( "zlib.h", ZLIB, , , "SYNTAX_ONLY")
+$   if (f$search( file1) .eqs. "")
+$   then
+$     WRITE SYS$OUTPUT ""
+$     WRITE SYS$OUTPUT "The Option ", ZLIB, " Is Invalid."
+$     WRITE SYS$OUTPUT "    Can't find header: ''file1'"
+$     err = 1
+$   endif
+$   file1 = f$parse( "A.;", ZLIB)- "A.;"
+$!
+$   file2 = f$parse( ZLIB, "libz.olb", , , "SYNTAX_ONLY")
+$   if (f$search( file2) .eqs. "")
+$   then
+$     if (err .eq. 0)
+$     then
+$       WRITE SYS$OUTPUT ""
+$       WRITE SYS$OUTPUT "The Option ", ZLIB, " Is Invalid."
+$     endif
+$     WRITE SYS$OUTPUT "    Can't find library: ''file2'"
+$     WRITE SYS$OUTPUT ""
+$     err = err+ 2
+$   endif
+$   if (err .eq. 1)
+$   then
+$     WRITE SYS$OUTPUT ""
+$   endif
+$!
+$   if (err .ne. 0)
+$   then
+$     EXIT
+$   endif
+$!
+$   CCDEFS = """ZLIB=1"", "+ CCDEFS
+$   CC_INCLUDES = CC_INCLUDES+ ", "+ file1
+$   ZLIB_LIB = ", ''file2' /library"
+$!
+$!  Print info
+$!
+$   WRITE SYS$OUTPUT "ZLIB library spec: ", file2
+$!
+$! End The ZLIB Check.
+$!
+$ ENDIF
+$!
+$!  Check To See If The User Entered A Valid Parameter.
 $!
 $ IF (P2.EQS."VAXC").OR.(P2.EQS."DECC").OR.(P2.EQS."GNUC")
 $ THEN
@@ -690,13 +853,13 @@ $!
 $     CC = "CC"
 $     IF ARCH.EQS."VAX" .AND. F$TRNLNM("DECC$CC_DEFAULT").NES."/DECC" -
         THEN CC = "CC/DECC"
-$     CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/STANDARD=ANSI89" + -
-           "/NOLIST/PREFIX=ALL" + -
-          "/INCLUDE=(SYS$DISK:[-],SYS$DISK:[-.CRYPTO])" + CCEXTRAFLAGS
+$     CC = CC + " /''CC_OPTIMIZE' /''DEBUGGER' /STANDARD=RELAXED"+ -
+       "''POINTER_SIZE' /NOLIST /PREFIX=ALL" + -
+       " /INCLUDE=(''CC_INCLUDES') " + CCEXTRAFLAGS
 $!
 $!    Define The Linker Options File Name.
 $!
-$     OPT_FILE = "''EXE_DIR'VAX_DECC_OPTIONS.OPT"
+$     OPT_FILE = "VAX_DECC_OPTIONS.OPT"
 $!
 $!  End DECC Check.
 $!
@@ -724,7 +887,7 @@ $   EXIT
 $     ENDIF
 $     IF F$TRNLNM("DECC$CC_DEFAULT").EQS."/DECC" THEN CC = "CC/VAXC"
 $     CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/NOLIST" + -
-          "/INCLUDE=(SYS$DISK:[-],SYS$DISK:[-.CRYPTO])" + CCEXTRAFLAGS
+          "/INCLUDE=(''CC_INCLUDES')" + CCEXTRAFLAGS
 $     CCDEFS = CCDEFS + ",""VAXC"""
 $!
 $!    Define <sys> As SYS$COMMON:[SYSLIB]
@@ -733,7 +896,7 @@ $     DEFINE/NOLOG SYS SYS$COMMON:[SYSLIB]
 $!
 $!    Define The Linker Options File Name.
 $!
-$     OPT_FILE = "''EXE_DIR'VAX_VAXC_OPTIONS.OPT"
+$     OPT_FILE = "VAX_VAXC_OPTIONS.OPT"
 $!
 $!  End VAXC Check
 $!
@@ -756,11 +919,11 @@ $!    Use GNU C...
 $!
 $     IF F$TYPE(GCC) .EQS. "" THEN GCC := GCC
 $     CC = GCC+"/NOCASE_HACK/''GCC_OPTIMIZE'/''DEBUGGER'/NOLIST" + -
-          "/INCLUDE=(SYS$DISK:[-],SYS$DISK:[-.CRYPTO])" + CCEXTRAFLAGS
+          "/INCLUDE=(''CC_INCLUDES')" + CCEXTRAFLAGS
 $!
 $!    Define The Linker Options File Name.
 $!
-$     OPT_FILE = "''EXE_DIR'VAX_GNUC_OPTIONS.OPT"
+$     OPT_FILE = "VAX_GNUC_OPTIONS.OPT"
 $!
 $!  End The GNU C Check.
 $!
@@ -770,7 +933,7 @@ $!  Set up default defines
 $!
 $   CCDEFS = """FLAT_INC=1""," + CCDEFS
 $!
-$!  Else The User Entered An Invalid Arguement.
+$!  Else The User Entered An Invalid Argument.
 $!
 $ ELSE
 $!
@@ -802,7 +965,7 @@ $   THEN
 $!
 $!    Set the library to use SOCKETSHR
 $!
-$     TCPIP_LIB = "SYS$DISK:[-.VMS]SOCKETSHR_SHR.OPT/OPT"
+$     TCPIP_LIB = ",SYS$DISK:[-.VMS]SOCKETSHR_SHR.OPT /OPTIONS"
 $!
 $!    Done with SOCKETSHR
 $!
@@ -828,13 +991,13 @@ $   THEN
 $!
 $!    Set the library to use UCX.
 $!
-$     TCPIP_LIB = "SYS$DISK:[-.VMS]UCX_SHR_DECC.OPT/OPT"
+$     TCPIP_LIB = ",SYS$DISK:[-.VMS]UCX_SHR_DECC.OPT /OPTIONS"
 $     IF F$TRNLNM("UCX$IPC_SHR") .NES. ""
 $     THEN
-$       TCPIP_LIB = "SYS$DISK:[-.VMS]UCX_SHR_DECC_LOG.OPT/OPT"
+$       TCPIP_LIB = ",SYS$DISK:[-.VMS]UCX_SHR_DECC_LOG.OPT /OPTIONS"
 $     ELSE
 $       IF COMPILER .NES. "DECC" .AND. ARCH .EQS. "VAX" THEN -
-         TCPIP_LIB = "SYS$DISK:[-.VMS]UCX_SHR_VAXC.OPT/OPT"
+         TCPIP_LIB = ",SYS$DISK:[-.VMS]UCX_SHR_VAXC.OPT /OPTIONS"
 $     ENDIF
 $!
 $!    Done with UCX
@@ -848,7 +1011,7 @@ $   THEN
 $!
 $!    Set the library to use TCPIP.
 $!
-$     TCPIP_LIB = "SYS$DISK:[-.VMS]TCPIP_SHR_DECC.OPT/OPT"
+$     TCPIP_LIB = ",SYS$DISK:[-.VMS]TCPIP_SHR_DECC.OPT /OPTIONS"
 $!
 $!    Done with TCPIP
 $!
@@ -873,9 +1036,9 @@ $   CCDEFS = CCDEFS + ",TCPIP_TYPE_''P3'"
 $!
 $!  Print info
 $!
-$   WRITE SYS$OUTPUT "TCP/IP library spec: ", TCPIP_LIB
+$   WRITE SYS$OUTPUT "TCP/IP library spec: ", TCPIP_LIB- ","
 $!
-$!  Else The User Entered An Invalid Arguement.
+$!  Else The User Entered An Invalid Argument.
 $!
 $ ELSE
 $!
@@ -903,13 +1066,13 @@ $ IF COMPILER .EQS. "DECC"
 $ THEN
 $   IF CCDISABLEWARNINGS .NES. ""
 $   THEN
-$     CCDISABLEWARNINGS = "/WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))"
+$     CCDISABLEWARNINGS = " /WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))"
 $   ENDIF
 $ ELSE
 $   CCDISABLEWARNINGS = ""
 $ ENDIF
-$ CC2 = CC + "/DEFINE=(" + CCDEFS + ",_POSIX_C_SOURCE)" + CCDISABLEWARNINGS
-$ CC = CC + "/DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS
+$ CC2 = CC + " /DEFINE=(" + CCDEFS + ",_POSIX_C_SOURCE)" + CCDISABLEWARNINGS
+$ CC = CC + " /DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS
 $!
 $! Show user the result
 $!
@@ -975,7 +1138,7 @@ $ __INCLUDE = __TOP + "INCLUDE.OPENSSL]"
 $!
 $! Set up the logical name OPENSSL to point at the include directory
 $!
-$ DEFINE OPENSSL/NOLOG '__INCLUDE'
+$ DEFINE OPENSSL /NOLOG '__INCLUDE'
 $!
 $! Done
 $!
@@ -983,15 +1146,24 @@ $ RETURN
 $!
 $ CLEANUP:
 $!
-$! Restore the logical name OPENSSL if it had a value
+$! Restore the saved logical name OPENSSL, if it had a value.
 $!
-$ IF __SAVE_OPENSSL .EQS. ""
-$ THEN
-$   DEASSIGN OPENSSL
-$ ELSE
-$   DEFINE/NOLOG OPENSSL '__SAVE_OPENSSL'
-$ ENDIF
+$ if (f$type( __SAVE_OPENSSL) .nes. "")
+$ then
+$   IF __SAVE_OPENSSL .EQS. ""
+$   THEN
+$     DEASSIGN OPENSSL
+$   ELSE
+$     DEFINE /NOLOG OPENSSL '__SAVE_OPENSSL'
+$   ENDIF
+$ endif
+$!
+$! Close any open files.
+$!
+$ if (f$trnlnm( "objects", "LNM$PROCESS", 0, "SUPERVISOR") .nes. "") then -
+   close objects
 $!
 $! Done
 $!
 $ RETURN
+$!
index 251044d..01847df 100644 (file)
  *
  */
 #ifndef OPENSSL_NO_OCSP
+
+#ifdef OPENSSL_SYS_VMS
+#define _XOPEN_SOURCE_EXTENDED /* So fd_set and friends get properly defined
+                                  on OpenVMS */
+#endif
+
 #define USE_SOCKETS
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 #include "apps.h" /* needs to be included before the openssl headers! */
 #include <openssl/e_os2.h>
-#include <openssl/ssl.h>
+#include <openssl/crypto.h>
 #include <openssl/err.h>
-
+#include <openssl/ssl.h>
+#include <openssl/evp.h>
+#include <openssl/bn.h>
+#include <openssl/x509v3.h>
+
+#if defined(NETWARE_CLIB)
+#  ifdef NETWARE_BSDSOCK
+#    include <sys/socket.h>
+#    include <sys/bsdskt.h>
+#  else
+#    include <novsock2.h>
+#  endif
+#elif defined(NETWARE_LIBC)
+#  ifdef NETWARE_BSDSOCK
+#    include <sys/select.h>
+#  else
+#    include <novsock2.h>
+#  endif
+#endif
+  
 /* Maximum leeway in validity period: default 5 minutes */
 #define MAX_VALIDITY_PERIOD    (5 * 60)
 
-static int add_ocsp_cert(OCSP_REQUEST **req, X509 *cert, X509 *issuer,
+static int add_ocsp_cert(OCSP_REQUEST **req, X509 *cert, const EVP_MD *cert_id_md, X509 *issuer,
                                STACK_OF(OCSP_CERTID) *ids);
-static int add_ocsp_serial(OCSP_REQUEST **req, char *serial, X509 *issuer,
+static int add_ocsp_serial(OCSP_REQUEST **req, char *serial, const EVP_MD * cert_id_md, X509 *issuer,
                                STACK_OF(OCSP_CERTID) *ids);
 static int print_ocsp_summary(BIO *out, OCSP_BASICRESP *bs, OCSP_REQUEST *req,
-                               STACK *names, STACK_OF(OCSP_CERTID) *ids,
-                               long nsec, long maxage);
+                             STACK_OF(OPENSSL_STRING) *names,
+                             STACK_OF(OCSP_CERTID) *ids, long nsec,
+                             long maxage);
 
 static int make_ocsp_response(OCSP_RESPONSE **resp, OCSP_REQUEST *req, CA_DB *db,
                        X509 *ca, X509 *rcert, EVP_PKEY *rkey,
@@ -86,6 +114,7 @@ static BIO *init_responder(char *port);
 static int do_responder(OCSP_REQUEST **preq, BIO **pcbio, BIO *acbio, char *port);
 static int send_ocsp_response(BIO *cbio, OCSP_RESPONSE *resp);
 static OCSP_RESPONSE *query_responder(BIO *err, BIO *cbio, char *path,
+                               STACK_OF(CONF_VALUE) *headers,
                                OCSP_REQUEST *req, int req_timeout);
 
 #undef PROG
@@ -104,6 +133,7 @@ int MAIN(int argc, char **argv)
        char *rsignfile = NULL, *rkeyfile = NULL;
        char *outfile = NULL;
        int add_nonce = 1, noverify = 0, use_ssl = -1;
+       STACK_OF(CONF_VALUE) *headers = NULL;
        OCSP_REQUEST *req = NULL;
        OCSP_RESPONSE *resp = NULL;
        OCSP_BASICRESP *bs = NULL;
@@ -126,7 +156,7 @@ int MAIN(int argc, char **argv)
        int badarg = 0;
        int i;
        int ignore_err = 0;
-       STACK *reqnames = NULL;
+       STACK_OF(OPENSSL_STRING) *reqnames = NULL;
        STACK_OF(OCSP_CERTID) *ids = NULL;
 
        X509 *rca_cert = NULL;
@@ -134,6 +164,7 @@ int MAIN(int argc, char **argv)
        char *rca_filename = NULL;
        CA_DB *rdb = NULL;
        int nmin = 0, ndays = -1;
+       const EVP_MD *cert_id_md = NULL;
 
        if (bio_err == NULL) bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
 
@@ -142,7 +173,7 @@ int MAIN(int argc, char **argv)
        SSL_load_error_strings();
        OpenSSL_add_ssl_algorithms();
        args = argv + 1;
-       reqnames = sk_new_null();
+       reqnames = sk_OPENSSL_STRING_new_null();
        ids = sk_OCSP_CERTID_new_null();
        while (!badarg && *args && *args[0] == '-')
                {
@@ -202,6 +233,16 @@ int MAIN(int argc, char **argv)
                                }
                        else badarg = 1;
                        }
+               else if (!strcmp(*args, "-header"))
+                       {
+                       if (args[1] && args[2])
+                               {
+                               if (!X509V3_add_value(args[1], args[2], &headers))
+                                       goto end;
+                               args += 2;
+                               }
+                       else badarg = 1;
+                       }
                else if (!strcmp(*args, "-ignore_err"))
                        ignore_err = 1;
                else if (!strcmp(*args, "-noverify"))
@@ -401,9 +442,10 @@ int MAIN(int argc, char **argv)
                                cert = load_cert(bio_err, *args, FORMAT_PEM,
                                        NULL, e, "certificate");
                                if(!cert) goto end;
-                               if(!add_ocsp_cert(&req, cert, issuer, ids))
+                               if (!cert_id_md) cert_id_md = EVP_sha1();
+                               if(!add_ocsp_cert(&req, cert, cert_id_md, issuer, ids))
                                        goto end;
-                               if(!sk_push(reqnames, *args))
+                               if(!sk_OPENSSL_STRING_push(reqnames, *args))
                                        goto end;
                                }
                        else badarg = 1;
@@ -413,9 +455,10 @@ int MAIN(int argc, char **argv)
                        if (args[1])
                                {
                                args++;
-                               if(!add_ocsp_serial(&req, *args, issuer, ids))
+                               if (!cert_id_md) cert_id_md = EVP_sha1();
+                               if(!add_ocsp_serial(&req, *args, cert_id_md, issuer, ids))
                                        goto end;
-                               if(!sk_push(reqnames, *args))
+                               if(!sk_OPENSSL_STRING_push(reqnames, *args))
                                        goto end;
                                }
                        else badarg = 1;
@@ -515,7 +558,10 @@ int MAIN(int argc, char **argv)
                                }
                        else badarg = 1;
                        }
-               else badarg = 1;
+               else if ((cert_id_md = EVP_get_digestbyname((*args)+1))==NULL)
+                       {
+                       badarg = 1;
+                       }
                args++;
                }
 
@@ -571,6 +617,7 @@ int MAIN(int argc, char **argv)
                BIO_printf (bio_err, "-ndays n           number of days before next update\n");
                BIO_printf (bio_err, "-resp_key_id       identify reponse by signing certificate key ID\n");
                BIO_printf (bio_err, "-nrequest n        number of requests to accept (default unlimited)\n");
+               BIO_printf (bio_err, "-<dgst alg>     use specified digest in the request");
                goto end;
                }
 
@@ -677,7 +724,8 @@ int MAIN(int argc, char **argv)
                        "signer private key");
                if (!key)
                        goto end;
-               if (!OCSP_request_sign(req, signer, key, EVP_sha1(), sign_other, sign_flags))
+
+               if (!OCSP_request_sign(req, signer, key, NULL, sign_other, sign_flags))
                        {
                        BIO_printf(bio_err, "Error signing OCSP request\n");
                        goto end;
@@ -721,7 +769,7 @@ int MAIN(int argc, char **argv)
                {
 #ifndef OPENSSL_NO_SOCK
                resp = process_responder(bio_err, req, host, path,
-                                               port, use_ssl, req_timeout);
+                                       port, use_ssl, headers, req_timeout);
                if (!resp)
                        goto end;
 #else
@@ -866,10 +914,11 @@ end:
        OCSP_REQUEST_free(req);
        OCSP_RESPONSE_free(resp);
        OCSP_BASICRESP_free(bs);
-       sk_free(reqnames);
+       sk_OPENSSL_STRING_free(reqnames);
        sk_OCSP_CERTID_free(ids);
        sk_X509_pop_free(sign_other, X509_free);
        sk_X509_pop_free(verify_other, X509_free);
+       sk_CONF_VALUE_pop_free(headers, X509V3_conf_free);
 
        if (use_ssl != -1)
                {
@@ -881,7 +930,7 @@ end:
        OPENSSL_EXIT(ret);
 }
 
-static int add_ocsp_cert(OCSP_REQUEST **req, X509 *cert, X509 *issuer,
+static int add_ocsp_cert(OCSP_REQUEST **req, X509 *cert, const EVP_MD *cert_id_md,X509 *issuer,
                                STACK_OF(OCSP_CERTID) *ids)
        {
        OCSP_CERTID *id;
@@ -892,7 +941,7 @@ static int add_ocsp_cert(OCSP_REQUEST **req, X509 *cert, X509 *issuer,
                }
        if(!*req) *req = OCSP_REQUEST_new();
        if(!*req) goto err;
-       id = OCSP_cert_to_id(NULL, cert, issuer);
+       id = OCSP_cert_to_id(cert_id_md, cert, issuer);
        if(!id || !sk_OCSP_CERTID_push(ids, id)) goto err;
        if(!OCSP_request_add0_id(*req, id)) goto err;
        return 1;
@@ -902,7 +951,7 @@ static int add_ocsp_cert(OCSP_REQUEST **req, X509 *cert, X509 *issuer,
        return 0;
        }
 
-static int add_ocsp_serial(OCSP_REQUEST **req, char *serial, X509 *issuer,
+static int add_ocsp_serial(OCSP_REQUEST **req, char *serial,const EVP_MD *cert_id_md, X509 *issuer,
                                STACK_OF(OCSP_CERTID) *ids)
        {
        OCSP_CERTID *id;
@@ -924,7 +973,7 @@ static int add_ocsp_serial(OCSP_REQUEST **req, char *serial, X509 *issuer,
                BIO_printf(bio_err, "Error converting serial number %s\n", serial);
                return 0;
                }
-       id = OCSP_cert_id_new(EVP_sha1(), iname, ikey, sno);
+       id = OCSP_cert_id_new(cert_id_md, iname, ikey, sno);
        ASN1_INTEGER_free(sno);
        if(!id || !sk_OCSP_CERTID_push(ids, id)) goto err;
        if(!OCSP_request_add0_id(*req, id)) goto err;
@@ -936,8 +985,9 @@ static int add_ocsp_serial(OCSP_REQUEST **req, char *serial, X509 *issuer,
        }
 
 static int print_ocsp_summary(BIO *out, OCSP_BASICRESP *bs, OCSP_REQUEST *req,
-                                       STACK *names, STACK_OF(OCSP_CERTID) *ids,
-                                       long nsec, long maxage)
+                             STACK_OF(OPENSSL_STRING) *names,
+                             STACK_OF(OCSP_CERTID) *ids, long nsec,
+                             long maxage)
        {
        OCSP_CERTID *id;
        char *name;
@@ -947,13 +997,13 @@ static int print_ocsp_summary(BIO *out, OCSP_BASICRESP *bs, OCSP_REQUEST *req,
 
        ASN1_GENERALIZEDTIME *rev, *thisupd, *nextupd;
 
-       if (!bs || !req || !sk_num(names) || !sk_OCSP_CERTID_num(ids))
+       if (!bs || !req || !sk_OPENSSL_STRING_num(names) || !sk_OCSP_CERTID_num(ids))
                return 1;
 
        for (i = 0; i < sk_OCSP_CERTID_num(ids); i++)
                {
                id = sk_OCSP_CERTID_value(ids, i);
-               name = sk_value(names, i);
+               name = sk_OPENSSL_STRING_value(names, i);
                BIO_printf(out, "%s: ", name);
 
                if(!OCSP_resp_find_status(bs, id, &status, &reason,
@@ -1010,7 +1060,6 @@ static int make_ocsp_response(OCSP_RESPONSE **resp, OCSP_REQUEST *req, CA_DB *db
        OCSP_BASICRESP *bs = NULL;
        int i, id_count, ret = 1;
 
-
        id_count = OCSP_request_onereq_count(req);
 
        if (id_count <= 0)
@@ -1019,7 +1068,6 @@ static int make_ocsp_response(OCSP_RESPONSE **resp, OCSP_REQUEST *req, CA_DB *db
                goto end;
                }
 
-       ca_id = OCSP_cert_to_id(EVP_sha1(), NULL, ca);
 
        bs = OCSP_BASICRESP_new();
        thisupd = X509_gmtime_adj(NULL, 0);
@@ -1032,8 +1080,23 @@ static int make_ocsp_response(OCSP_RESPONSE **resp, OCSP_REQUEST *req, CA_DB *db
                OCSP_ONEREQ *one;
                ASN1_INTEGER *serial;
                char **inf;
+               ASN1_OBJECT *cert_id_md_oid;
+               const EVP_MD *cert_id_md;
                one = OCSP_request_onereq_get0(req, i);
                cid = OCSP_onereq_get0_id(one);
+
+               OCSP_id_get0_info(NULL,&cert_id_md_oid, NULL,NULL, cid);
+
+               cert_id_md = EVP_get_digestbyobj(cert_id_md_oid);       
+               if (! cert_id_md) 
+                       {
+                       *resp = OCSP_response_create(OCSP_RESPONSE_STATUS_INTERNALERROR,
+                               NULL);
+                               goto end;
+                       }       
+               if (ca_id) OCSP_CERTID_free(ca_id);
+               ca_id = OCSP_cert_to_id(cert_id_md, NULL, ca);
+
                /* Is this request about our CA? */
                if (OCSP_id_issuer_cmp(ca_id, cid))
                        {
@@ -1078,8 +1141,8 @@ static int make_ocsp_response(OCSP_RESPONSE **resp, OCSP_REQUEST *req, CA_DB *db
                }
 
        OCSP_copy_nonce(bs, req);
-               
-       OCSP_basic_sign(bs, rcert, rkey, EVP_sha1(), rother, flags);
+       
+       OCSP_basic_sign(bs, rcert, rkey, NULL, rother, flags);
 
        *resp = OCSP_response_create(OCSP_RESPONSE_STATUS_SUCCESSFUL, bs);
 
@@ -1211,10 +1274,12 @@ static int send_ocsp_response(BIO *cbio, OCSP_RESPONSE *resp)
        }
 
 static OCSP_RESPONSE *query_responder(BIO *err, BIO *cbio, char *path,
+                               STACK_OF(CONF_VALUE) *headers,
                                OCSP_REQUEST *req, int req_timeout)
        {
        int fd;
        int rv;
+       int i;
        OCSP_REQ_CTX *ctx = NULL;
        OCSP_RESPONSE *rsp = NULL;
        fd_set confds;
@@ -1231,16 +1296,13 @@ static OCSP_RESPONSE *query_responder(BIO *err, BIO *cbio, char *path,
                return NULL;
                }
 
-       if (req_timeout == -1)
-               return OCSP_sendreq_bio(cbio, path, req);
-
        if (BIO_get_fd(cbio, &fd) <= 0)
                {
                BIO_puts(err, "Can't get connection fd\n");
                goto err;
                }
 
-       if (rv <= 0)
+       if (req_timeout != -1 && rv <= 0)
                {
                FD_ZERO(&confds);
                openssl_fdset(fd, &confds);
@@ -1255,15 +1317,27 @@ static OCSP_RESPONSE *query_responder(BIO *err, BIO *cbio, char *path,
                }
 
 
-       ctx = OCSP_sendreq_new(cbio, path, req, -1);
+       ctx = OCSP_sendreq_new(cbio, path, NULL, -1);
        if (!ctx)
                return NULL;
+
+       for (i = 0; i < sk_CONF_VALUE_num(headers); i++)
+               {
+               CONF_VALUE *hdr = sk_CONF_VALUE_value(headers, i);
+               if (!OCSP_REQ_CTX_add1_header(ctx, hdr->name, hdr->value))
+                       goto err;
+               }
+
+       if (!OCSP_REQ_CTX_set1_req(ctx, req))
+               goto err;
        
        for (;;)
                {
                rv = OCSP_sendreq_nbio(&rsp, ctx);
                if (rv != -1)
                        break;
+               if (req_timeout == -1)
+                       continue;
                FD_ZERO(&confds);
                openssl_fdset(fd, &confds);
                tv.tv_usec = 0;
@@ -1287,7 +1361,7 @@ static OCSP_RESPONSE *query_responder(BIO *err, BIO *cbio, char *path,
                        BIO_puts(err, "Select error\n");
                        break;
                        }
-                       
+
                }
        err:
        if (ctx)
@@ -1298,6 +1372,7 @@ static OCSP_RESPONSE *query_responder(BIO *err, BIO *cbio, char *path,
 
 OCSP_RESPONSE *process_responder(BIO *err, OCSP_REQUEST *req,
                        char *host, char *path, char *port, int use_ssl,
+                       STACK_OF(CONF_VALUE) *headers,
                        int req_timeout)
        {
        BIO *cbio = NULL;
@@ -1332,14 +1407,14 @@ OCSP_RESPONSE *process_responder(BIO *err, OCSP_REQUEST *req,
                sbio = BIO_new_ssl(ctx, 1);
                cbio = BIO_push(sbio, cbio);
                }
-       resp = query_responder(err, cbio, path, req, req_timeout);
+       resp = query_responder(err, cbio, path, headers, req, req_timeout);
        if (!resp)
                BIO_printf(bio_err, "Error querying OCSP responsder\n");
        end:
-       if (ctx)
-               SSL_CTX_free(ctx);
        if (cbio)
                BIO_free_all(cbio);
+       if (ctx)
+               SSL_CTX_free(ctx);
        return resp;
        }
 
index fae82b0..45e46a0 100644 (file)
@@ -21,12 +21,17 @@ oid_section         = new_oids
 
 [ new_oids ]
 
-# We can add new OIDs in here for use by 'ca' and 'req'.
+# We can add new OIDs in here for use by 'ca', 'req' and 'ts'.
 # Add a simple OID like this:
 # testoid1=1.2.3.4
 # Or use config file substitution like this:
 # testoid2=${testoid1}.5.6
 
+# Policies used by the TSA examples.
+tsa_policy1 = 1.2.3.4.1
+tsa_policy2 = 1.2.3.4.5.6
+tsa_policy3 = 1.2.3.4.5.7
+
 ####################################################################
 [ ca ]
 default_ca     = CA_default            # The default ca section
@@ -67,7 +72,7 @@ cert_opt      = ca_default            # Certificate field options
 
 default_days   = 365                   # how long to certify for
 default_crl_days= 30                   # how long before next CRL
-default_md     = sha1                  # which md to use.
+default_md     = default               # use public key default MD
 preserve       = no                    # keep passed DN ordering
 
 # A few difference way of specifying how similar the request should look
@@ -110,13 +115,12 @@ x509_extensions   = v3_ca # The extentions to add to the self signed cert
 
 # This sets a mask for permitted string types. There are several options. 
 # default: PrintableString, T61String, BMPString.
-# pkix  : PrintableString, BMPString.
-# utf8only: only UTF8Strings.
+# pkix  : PrintableString, BMPString (PKIX recommendation before 2004)
+# utf8only: only UTF8Strings (PKIX recommendation after 2004).
 # nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings).
 # MASK:XXXX a literal mask value.
-# WARNING: current versions of Netscape crash on BMPStrings or UTF8Strings
-# so use this option with caution!
-string_mask = nombstr
+# WARNING: ancient versions of Netscape crash on BMPStrings or UTF8Strings.
+string_mask = utf8only
 
 # req_extensions = v3_req # The extensions to add to a certificate request
 
@@ -141,7 +145,7 @@ localityName                        = Locality Name (eg, city)
 organizationalUnitName         = Organizational Unit Name (eg, section)
 #organizationalUnitName_default        =
 
-commonName                     = Common Name (eg, YOUR name)
+commonName                     = Common Name (e.g. server FQDN or YOUR name)
 commonName_max                 = 64
 
 emailAddress                   = Email Address
@@ -207,6 +211,9 @@ authorityKeyIdentifier=keyid,issuer
 #nsCaPolicyUrl
 #nsSslServerName
 
+# This is required for TSA certificates.
+# extendedKeyUsage = critical,timeStamping
+
 [ v3_req ]
 
 # Extensions to add to a certificate request
@@ -224,7 +231,7 @@ keyUsage = nonRepudiation, digitalSignature, keyEncipherment
 
 subjectKeyIdentifier=hash
 
-authorityKeyIdentifier=keyid:always,issuer:always
+authorityKeyIdentifier=keyid:always,issuer
 
 # This is what PKIX recommends but some broken software chokes on critical
 # extensions.
@@ -257,7 +264,7 @@ basicConstraints = CA:true
 # Only issuerAltName and authorityKeyIdentifier make any sense in a CRL.
 
 # issuerAltName=issuer:copy
-authorityKeyIdentifier=keyid:always,issuer:always
+authorityKeyIdentifier=keyid:always
 
 [ proxy_cert_ext ]
 # These extensions should be added when creating a proxy certificate
@@ -290,7 +297,7 @@ nsComment                   = "OpenSSL Generated Certificate"
 
 # PKIX recommendations harmless if included in all certificates.
 subjectKeyIdentifier=hash
-authorityKeyIdentifier=keyid,issuer:always
+authorityKeyIdentifier=keyid,issuer
 
 # This stuff is for subjectAltName and issuerAltname.
 # Import the email address.
@@ -311,3 +318,33 @@ authorityKeyIdentifier=keyid,issuer:always
 
 # This really needs to be in place for it to be a proxy certificate.
 proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:3,policy:foo
+
+####################################################################
+[ tsa ]
+
+default_tsa = tsa_config1      # the default TSA section
+
+[ tsa_config1 ]
+
+# These are used by the TSA reply generation only.
+dir            = sys\$disk:[.demoCA            # TSA root directory
+serial         = $dir]tsaserial.       # The current serial number (mandatory)
+crypto_device  = builtin               # OpenSSL engine to use for signing
+signer_cert    = $dir/tsacert.pem      # The TSA signing certificate
+                                       # (optional)
+certs          = $dir.cacert.pem]      # Certificate chain to include in reply
+                                       # (optional)
+signer_key     = $dir/private/tsakey.pem # The TSA private key (optional)
+
+default_policy = tsa_policy1           # Policy if request did not specify it
+                                       # (optional)
+other_policies = tsa_policy2, tsa_policy3      # acceptable policies (optional)
+digests                = md5, sha1             # Acceptable message digests (mandatory)
+accuracy       = secs:1, millisecs:500, microsecs:100  # (optional)
+clock_precision_digits  = 0    # number of digits after dot. (optional)
+ordering               = yes   # Is ordering defined for timestamps?
+                               # (optional, default: no)
+tsa_name               = yes   # Must the TSA name be included in the reply?
+                               # (optional, default: no)
+ess_cert_id_chain      = no    # Must the ESS cert id chain be included?
+                               # (optional, default: no)
index 480fef9..1068957 100644 (file)
  * type of "FUNCTION*"). This removes the necessity for macro-generated wrapper
  * functions. */
 
-/* static unsigned long MS_CALLBACK hash(FUNCTION *a); */
-static unsigned long MS_CALLBACK hash(const void *a_void);
-/* static int MS_CALLBACK cmp(FUNCTION *a,FUNCTION *b); */
-static int MS_CALLBACK cmp(const void *a_void,const void *b_void);
-static LHASH *prog_init(void );
-static int do_cmd(LHASH *prog,int argc,char *argv[]);
+static LHASH_OF(FUNCTION) *prog_init(void );
+static int do_cmd(LHASH_OF(FUNCTION) *prog,int argc,char *argv[]);
+static void list_pkey(BIO *out);
+static void list_cipher(BIO *out);
+static void list_md(BIO *out);
 char *default_config_file=NULL;
 
 /* Make sure there is only one when MONOLITH is defined */
 #ifdef MONOLITH
 CONF *config=NULL;
 BIO *bio_err=NULL;
-int in_FIPS_mode=0;
 #endif
 
 
@@ -214,8 +212,13 @@ static void lock_dbg_cb(int mode, int type, const char *file, int line)
                }
        }
 
+#if defined( OPENSSL_SYS_VMS) && (__INITIAL_POINTER_SIZE == 64)
+# define ARGV _Argv
+#else
+# define ARGV Argv
+#endif
 
-int main(int Argc, char *Argv[])
+int main(int Argc, char *ARGV[])
        {
        ARGS arg;
 #define PROG_NAME_SIZE 39
@@ -227,27 +230,59 @@ int main(int Argc, char *Argv[])
        int n,i,ret=0;
        int argc;
        char **argv,*p;
-       LHASH *prog=NULL;
+       LHASH_OF(FUNCTION) *prog=NULL;
        long errline;
-       arg.data=NULL;
-       arg.count=0;
-
-       in_FIPS_mode = 0;
 
-       if(getenv("OPENSSL_FIPS")) {
-#ifdef OPENSSL_FIPS
-               if (!FIPS_mode_set(1)) {
-                       ERR_load_crypto_strings();
-                       ERR_print_errors(BIO_new_fp(stderr,BIO_NOCLOSE));
-                       EXIT(1);
+#if defined( OPENSSL_SYS_VMS) && (__INITIAL_POINTER_SIZE == 64)
+       /* 2011-03-22 SMS.
+        * If we have 32-bit pointers everywhere, then we're safe, and
+        * we bypass this mess, as on non-VMS systems.  (See ARGV,
+        * above.)
+        * Problem 1: Compaq/HP C before V7.3 always used 32-bit
+        * pointers for argv[].
+        * Fix 1: For a 32-bit argv[], when we're using 64-bit pointers
+        * everywhere else, we always allocate and use a 64-bit
+        * duplicate of argv[].
+        * Problem 2: Compaq/HP C V7.3 (Alpha, IA64) before ECO1 failed
+        * to NULL-terminate a 64-bit argv[].  (As this was written, the
+        * compiler ECO was available only on IA64.)
+        * Fix 2: Unless advised not to (VMS_TRUST_ARGV), we test a
+        * 64-bit argv[argc] for NULL, and, if necessary, use a
+        * (properly) NULL-terminated (64-bit) duplicate of argv[].
+        * The same code is used in either case to duplicate argv[].
+        * Some of these decisions could be handled in preprocessing,
+        * but the code tends to get even uglier, and the penalty for
+        * deciding at compile- or run-time is tiny.
+        */
+       char **Argv = NULL;
+       int free_Argv = 0;
+
+       if ((sizeof( _Argv) < 8)        /* 32-bit argv[]. */
+# if !defined( VMS_TRUST_ARGV)
+        || (_Argv[ Argc] != NULL)      /* Untrusted argv[argc] not NULL. */
+# endif
+               )
+               {
+               int i;
+               Argv = OPENSSL_malloc( (Argc+ 1)* sizeof( char *));
+               if (Argv == NULL)
+                       { ret = -1; goto end; }
+               for(i = 0; i < Argc; i++)
+                       Argv[i] = _Argv[i];
+               Argv[ Argc] = NULL;     /* Certain NULL termination. */
+               free_Argv = 1;
                }
-               in_FIPS_mode = 1;
-#else
-               fprintf(stderr, "FIPS mode not supported.\n");
-               EXIT(1);
-#endif
+       else
+               {
+               /* Use the known-good 32-bit argv[] (which needs the
+                * type cast to satisfy the compiler), or the trusted or
+                * tested-good 64-bit argv[] as-is. */
+               Argv = (char **)_Argv;
                }
+#endif /* defined( OPENSSL_SYS_VMS) && (__INITIAL_POINTER_SIZE == 64) */
+
+       arg.data=NULL;
+       arg.count=0;
 
        if (bio_err == NULL)
                if ((bio_err=BIO_new(BIO_s_file())) != NULL)
@@ -290,9 +325,23 @@ int main(int Argc, char *Argv[])
        i=NCONF_load(config,p,&errline);
        if (i == 0)
                {
-               NCONF_free(config);
-               config = NULL;
-               ERR_clear_error();
+               if (ERR_GET_REASON(ERR_peek_last_error())
+                   == CONF_R_NO_SUCH_FILE)
+                       {
+#if 0 /* ANDROID */
+                       BIO_printf(bio_err,
+                                  "WARNING: can't open config file: %s\n",p);
+#endif
+                       ERR_clear_error();
+                       NCONF_free(config);
+                       config = NULL;
+                       }
+               else
+                       {
+                       ERR_print_errors(bio_err);
+                       NCONF_free(config);
+                       exit(1);
+                       }
                }
 
        prog=prog_init();
@@ -301,7 +350,7 @@ int main(int Argc, char *Argv[])
        program_name(Argv[0],pname,sizeof pname);
 
        f.name=pname;
-       fp=(FUNCTION *)lh_retrieve(prog,&f);
+       fp=lh_FUNCTION_retrieve(prog,&f);
        if (fp != NULL)
                {
                Argv[0]=pname;
@@ -368,7 +417,7 @@ end:
                NCONF_free(config);
                config=NULL;
                }
-       if (prog != NULL) lh_free(prog);
+       if (prog != NULL) lh_FUNCTION_free(prog);
        if (arg.data != NULL) OPENSSL_free(arg.data);
 
        apps_shutdown();
@@ -379,14 +428,25 @@ end:
                BIO_free(bio_err);
                bio_err=NULL;
                }
+#if defined( OPENSSL_SYS_VMS) && (__INITIAL_POINTER_SIZE == 64)
+       /* Free any duplicate Argv[] storage. */
+       if (free_Argv)
+               {
+               OPENSSL_free(Argv);
+               }
+#endif
        OPENSSL_EXIT(ret);
        }
 
 #define LIST_STANDARD_COMMANDS "list-standard-commands"
 #define LIST_MESSAGE_DIGEST_COMMANDS "list-message-digest-commands"
+#define LIST_MESSAGE_DIGEST_ALGORITHMS "list-message-digest-algorithms"
 #define LIST_CIPHER_COMMANDS "list-cipher-commands"
+#define LIST_CIPHER_ALGORITHMS "list-cipher-algorithms"
+#define LIST_PUBLIC_KEY_ALGORITHMS "list-public-key-algorithms"
+
 
-static int do_cmd(LHASH *prog, int argc, char *argv[])
+static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[])
        {
        FUNCTION f,*fp;
        int i,ret=1,tp,nl;
@@ -394,7 +454,22 @@ static int do_cmd(LHASH *prog, int argc, char *argv[])
        if ((argc <= 0) || (argv[0] == NULL))
                { ret=0; goto end; }
        f.name=argv[0];
-       fp=(FUNCTION *)lh_retrieve(prog,&f);
+       fp=lh_FUNCTION_retrieve(prog,&f);
+       if (fp == NULL)
+               {
+               if (EVP_get_digestbyname(argv[0]))
+                       {
+                       f.type = FUNC_TYPE_MD;
+                       f.func = dgst_main;
+                       fp = &f;
+                       }
+               else if (EVP_get_cipherbyname(argv[0]))
+                       {
+                       f.type = FUNC_TYPE_CIPHER;
+                       f.func = enc_main;
+                       fp = &f;
+                       }
+               }
        if (fp != NULL)
                {
                ret=fp->func(argc,argv);
@@ -409,7 +484,7 @@ static int do_cmd(LHASH *prog, int argc, char *argv[])
                }
 #endif
                f.name=argv[0]+3;
-               ret = (lh_retrieve(prog,&f) != NULL);
+               ret = (lh_FUNCTION_retrieve(prog,&f) != NULL);
                if (!ret)
                        BIO_printf(bio_stdout, "%s\n", argv[0]);
                else
@@ -427,7 +502,10 @@ static int do_cmd(LHASH *prog, int argc, char *argv[])
                }
        else if ((strcmp(argv[0],LIST_STANDARD_COMMANDS) == 0) ||
                (strcmp(argv[0],LIST_MESSAGE_DIGEST_COMMANDS) == 0) ||
-               (strcmp(argv[0],LIST_CIPHER_COMMANDS) == 0))
+               (strcmp(argv[0],LIST_MESSAGE_DIGEST_ALGORITHMS) == 0) ||
+               (strcmp(argv[0],LIST_CIPHER_COMMANDS) == 0) ||
+               (strcmp(argv[0],LIST_CIPHER_ALGORITHMS) == 0) ||
+               (strcmp(argv[0],LIST_PUBLIC_KEY_ALGORITHMS) == 0))
                {
                int list_type;
                BIO *bio_stdout;
@@ -436,6 +514,12 @@ static int do_cmd(LHASH *prog, int argc, char *argv[])
                        list_type = FUNC_TYPE_GENERAL;
                else if (strcmp(argv[0],LIST_MESSAGE_DIGEST_COMMANDS) == 0)
                        list_type = FUNC_TYPE_MD;
+               else if (strcmp(argv[0],LIST_MESSAGE_DIGEST_ALGORITHMS) == 0)
+                       list_type = FUNC_TYPE_MD_ALG;
+               else if (strcmp(argv[0],LIST_PUBLIC_KEY_ALGORITHMS) == 0)
+                       list_type = FUNC_TYPE_PKEY;
+               else if (strcmp(argv[0],LIST_CIPHER_ALGORITHMS) == 0)
+                       list_type = FUNC_TYPE_CIPHER_ALG;
                else /* strcmp(argv[0],LIST_CIPHER_COMMANDS) == 0 */
                        list_type = FUNC_TYPE_CIPHER;
                bio_stdout = BIO_new_fp(stdout,BIO_NOCLOSE);
@@ -445,10 +529,23 @@ static int do_cmd(LHASH *prog, int argc, char *argv[])
                bio_stdout = BIO_push(tmpbio, bio_stdout);
                }
 #endif
-               
-               for (fp=functions; fp->name != NULL; fp++)
-                       if (fp->type == list_type)
-                               BIO_printf(bio_stdout, "%s\n", fp->name);
+
+               if (!load_config(bio_err, NULL))
+                       goto end;
+
+               if (list_type == FUNC_TYPE_PKEY)
+                       list_pkey(bio_stdout);  
+               if (list_type == FUNC_TYPE_MD_ALG)
+                       list_md(bio_stdout);    
+               if (list_type == FUNC_TYPE_CIPHER_ALG)
+                       list_cipher(bio_stdout);        
+               else
+                       {
+                       for (fp=functions; fp->name != NULL; fp++)
+                               if (fp->type == list_type)
+                                       BIO_printf(bio_stdout, "%s\n",
+                                                               fp->name);
+                       }
                BIO_free_all(bio_stdout);
                ret=0;
                goto end;
@@ -511,9 +608,94 @@ static int SortFnByName(const void *_f1,const void *_f2)
     return strcmp(f1->name,f2->name);
     }
 
-static LHASH *prog_init(void)
+static void list_pkey(BIO *out)
        {
-       LHASH *ret;
+       int i;
+       for (i = 0; i < EVP_PKEY_asn1_get_count(); i++)
+               {
+               const EVP_PKEY_ASN1_METHOD *ameth;
+               int pkey_id, pkey_base_id, pkey_flags;
+               const char *pinfo, *pem_str;
+               ameth = EVP_PKEY_asn1_get0(i);
+               EVP_PKEY_asn1_get0_info(&pkey_id, &pkey_base_id, &pkey_flags,
+                                               &pinfo, &pem_str, ameth);
+               if (pkey_flags & ASN1_PKEY_ALIAS)
+                       {
+                       BIO_printf(out, "Name: %s\n", 
+                                       OBJ_nid2ln(pkey_id));
+                       BIO_printf(out, "\tType: Alias to %s\n",
+                                       OBJ_nid2ln(pkey_base_id));
+                       }
+               else
+                       {
+                       BIO_printf(out, "Name: %s\n", pinfo);
+                       BIO_printf(out, "\tType: %s Algorithm\n", 
+                               pkey_flags & ASN1_PKEY_DYNAMIC ?
+                                       "External" : "Builtin");
+                       BIO_printf(out, "\tOID: %s\n", OBJ_nid2ln(pkey_id));
+                       if (pem_str == NULL)
+                               pem_str = "(none)";
+                       BIO_printf(out, "\tPEM string: %s\n", pem_str);
+                       }
+                                       
+               }
+       }
+
+static void list_cipher_fn(const EVP_CIPHER *c,
+                       const char *from, const char *to, void *arg)
+       {
+       if (c)
+               BIO_printf(arg, "%s\n", EVP_CIPHER_name(c));
+       else
+               {
+               if (!from)
+                       from = "<undefined>";
+               if (!to)
+                       to = "<undefined>";
+               BIO_printf(arg, "%s => %s\n", from, to);
+               }
+       }
+
+static void list_cipher(BIO *out)
+       {
+       EVP_CIPHER_do_all_sorted(list_cipher_fn, out);
+       }
+
+static void list_md_fn(const EVP_MD *m,
+                       const char *from, const char *to, void *arg)
+       {
+       if (m)
+               BIO_printf(arg, "%s\n", EVP_MD_name(m));
+       else
+               {
+               if (!from)
+                       from = "<undefined>";
+               if (!to)
+                       to = "<undefined>";
+               BIO_printf(arg, "%s => %s\n", from, to);
+               }
+       }
+
+static void list_md(BIO *out)
+       {
+       EVP_MD_do_all_sorted(list_md_fn, out);
+       }
+
+static int MS_CALLBACK function_cmp(const FUNCTION *a, const FUNCTION *b)
+       {
+       return strncmp(a->name,b->name,8);
+       }
+static IMPLEMENT_LHASH_COMP_FN(function, FUNCTION)
+
+static unsigned long MS_CALLBACK function_hash(const FUNCTION *a)
+       {
+       return lh_strhash(a->name);
+       }       
+static IMPLEMENT_LHASH_HASH_FN(function, FUNCTION)
+
+static LHASH_OF(FUNCTION) *prog_init(void)
+       {
+       LHASH_OF(FUNCTION) *ret;
        FUNCTION *f;
        size_t i;
 
@@ -522,23 +704,11 @@ static LHASH *prog_init(void)
            ;
        qsort(functions,i,sizeof *functions,SortFnByName);
 
-       if ((ret=lh_new(hash, cmp)) == NULL)
+       if ((ret=lh_FUNCTION_new()) == NULL)
                return(NULL);
 
        for (f=functions; f->name != NULL; f++)
-               lh_insert(ret,f);
+               (void)lh_FUNCTION_insert(ret,f);
        return(ret);
        }
 
-/* static int MS_CALLBACK cmp(FUNCTION *a, FUNCTION *b) */
-static int MS_CALLBACK cmp(const void *a_void, const void *b_void)
-       {
-       return(strncmp(((const FUNCTION *)a_void)->name,
-                       ((const FUNCTION *)b_void)->name,8));
-       }
-
-/* static unsigned long MS_CALLBACK hash(FUNCTION *a) */
-static unsigned long MS_CALLBACK hash(const void *a_void)
-       {
-       return(lh_strhash(((const FUNCTION *)a_void)->name));
-       }
index 9e59020..18760c6 100644 (file)
@@ -21,12 +21,17 @@ oid_section         = new_oids
 
 [ new_oids ]
 
-# We can add new OIDs in here for use by 'ca' and 'req'.
+# We can add new OIDs in here for use by 'ca', 'req' and 'ts'.
 # Add a simple OID like this:
 # testoid1=1.2.3.4
 # Or use config file substitution like this:
 # testoid2=${testoid1}.5.6
 
+# Policies used by the TSA examples.
+tsa_policy1 = 1.2.3.4.1
+tsa_policy2 = 1.2.3.4.5.6
+tsa_policy3 = 1.2.3.4.5.7
+
 ####################################################################
 [ ca ]
 default_ca     = CA_default            # The default ca section
@@ -67,7 +72,7 @@ cert_opt      = ca_default            # Certificate field options
 
 default_days   = 365                   # how long to certify for
 default_crl_days= 30                   # how long before next CRL
-default_md     = sha1                  # which md to use.
+default_md     = default               # use public key default MD
 preserve       = no                    # keep passed DN ordering
 
 # A few difference way of specifying how similar the request should look
@@ -110,13 +115,12 @@ x509_extensions   = v3_ca # The extentions to add to the self signed cert
 
 # This sets a mask for permitted string types. There are several options. 
 # default: PrintableString, T61String, BMPString.
-# pkix  : PrintableString, BMPString.
-# utf8only: only UTF8Strings.
+# pkix  : PrintableString, BMPString (PKIX recommendation before 2004)
+# utf8only: only UTF8Strings (PKIX recommendation after 2004).
 # nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings).
 # MASK:XXXX a literal mask value.
-# WARNING: current versions of Netscape crash on BMPStrings or UTF8Strings
-# so use this option with caution!
-string_mask = nombstr
+# WARNING: ancient versions of Netscape crash on BMPStrings or UTF8Strings.
+string_mask = utf8only
 
 # req_extensions = v3_req # The extensions to add to a certificate request
 
@@ -141,7 +145,7 @@ localityName                        = Locality Name (eg, city)
 organizationalUnitName         = Organizational Unit Name (eg, section)
 #organizationalUnitName_default        =
 
-commonName                     = Common Name (eg, YOUR name)
+commonName                     = Common Name (e.g. server FQDN or YOUR name)
 commonName_max                 = 64
 
 emailAddress                   = Email Address
@@ -207,6 +211,9 @@ authorityKeyIdentifier=keyid,issuer
 #nsCaPolicyUrl
 #nsSslServerName
 
+# This is required for TSA certificates.
+# extendedKeyUsage = critical,timeStamping
+
 [ v3_req ]
 
 # Extensions to add to a certificate request
@@ -224,7 +231,7 @@ keyUsage = nonRepudiation, digitalSignature, keyEncipherment
 
 subjectKeyIdentifier=hash
 
-authorityKeyIdentifier=keyid:always,issuer:always
+authorityKeyIdentifier=keyid:always,issuer
 
 # This is what PKIX recommends but some broken software chokes on critical
 # extensions.
@@ -257,7 +264,7 @@ basicConstraints = CA:true
 # Only issuerAltName and authorityKeyIdentifier make any sense in a CRL.
 
 # issuerAltName=issuer:copy
-authorityKeyIdentifier=keyid:always,issuer:always
+authorityKeyIdentifier=keyid:always
 
 [ proxy_cert_ext ]
 # These extensions should be added when creating a proxy certificate
@@ -290,7 +297,7 @@ nsComment                   = "OpenSSL Generated Certificate"
 
 # PKIX recommendations harmless if included in all certificates.
 subjectKeyIdentifier=hash
-authorityKeyIdentifier=keyid,issuer:always
+authorityKeyIdentifier=keyid,issuer
 
 # This stuff is for subjectAltName and issuerAltname.
 # Import the email address.
@@ -311,3 +318,33 @@ authorityKeyIdentifier=keyid,issuer:always
 
 # This really needs to be in place for it to be a proxy certificate.
 proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:3,policy:foo
+
+####################################################################
+[ tsa ]
+
+default_tsa = tsa_config1      # the default TSA section
+
+[ tsa_config1 ]
+
+# These are used by the TSA reply generation only.
+dir            = ./demoCA              # TSA root directory
+serial         = $dir/tsaserial        # The current serial number (mandatory)
+crypto_device  = builtin               # OpenSSL engine to use for signing
+signer_cert    = $dir/tsacert.pem      # The TSA signing certificate
+                                       # (optional)
+certs          = $dir/cacert.pem       # Certificate chain to include in reply
+                                       # (optional)
+signer_key     = $dir/private/tsakey.pem # The TSA private key (optional)
+
+default_policy = tsa_policy1           # Policy if request did not specify it
+                                       # (optional)
+other_policies = tsa_policy2, tsa_policy3      # acceptable policies (optional)
+digests                = md5, sha1             # Acceptable message digests (mandatory)
+accuracy       = secs:1, millisecs:500, microsecs:100  # (optional)
+clock_precision_digits  = 0    # number of digits after dot. (optional)
+ordering               = yes   # Is ordering defined for timestamps?
+                               # (optional, default: no)
+tsa_name               = yes   # Must the TSA name be included in the reply?
+                               # (optional, default: no)
+ess_cert_id_chain      = no    # Must the ESS cert id chain be included?
+                               # (optional, default: no)
index 0db0b79..b54c6f8 100644 (file)
 #include <openssl/pem.h>
 #include <openssl/pkcs12.h>
 
-#ifdef OPENSSL_SYS_NETWARE
-/* Rename these functions to avoid name clashes on NetWare OS */
-#define uni2asc OPENSSL_uni2asc
-#define asc2uni OPENSSL_asc2uni
-#endif
-
 #define PROG pkcs12_main
 
 const EVP_CIPHER *enc;
@@ -94,6 +88,7 @@ int print_attribs(BIO *out, STACK_OF(X509_ATTRIBUTE) *attrlst,const char *name);
 void hex_prin(BIO *out, unsigned char *buf, int len);
 int alg_print(BIO *x, X509_ALGOR *alg);
 int cert_load(BIO *in, STACK_OF(X509) *sk);
+static int set_pbe(BIO *err, int *ppbe, const char *str);
 
 int MAIN(int, char **);
 
@@ -117,16 +112,17 @@ int MAIN(int argc, char **argv)
     int maciter = PKCS12_DEFAULT_ITER;
     int twopass = 0;
     int keytype = 0;
-    int cert_pbe;
+    int cert_pbe = NID_pbe_WithSHA1And40BitRC2_CBC;
     int key_pbe = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
     int ret = 1;
     int macver = 1;
     int noprompt = 0;
-    STACK *canames = NULL;
+    STACK_OF(OPENSSL_STRING) *canames = NULL;
     char *cpass = NULL, *mpass = NULL;
     char *passargin = NULL, *passargout = NULL, *passarg = NULL;
     char *passin = NULL, *passout = NULL;
     char *inrand = NULL;
+    char *macalg = NULL;
     char *CApath = NULL, *CAfile = NULL;
 #ifndef OPENSSL_NO_ENGINE
     char *engine=NULL;
@@ -134,13 +130,6 @@ int MAIN(int argc, char **argv)
 
     apps_startup();
 
-#ifdef OPENSSL_FIPS
-    if (FIPS_mode())
-       cert_pbe = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
-    else
-#endif
-    cert_pbe = NID_pbe_WithSHA1And40BitRC2_CBC;
-
     enc = EVP_des_ede3_cbc();
     if (bio_err == NULL ) bio_err = BIO_new_fp (stderr, BIO_NOCLOSE);
 
@@ -191,33 +180,18 @@ int MAIN(int argc, char **argv)
                                         maciter = 1;
                else if (!strcmp (*args, "-nomac"))
                                         maciter = -1;
+               else if (!strcmp (*args, "-macalg"))
+                   if (args[1]) {
+                       args++; 
+                       macalg = *args;
+                   } else badarg = 1;
                else if (!strcmp (*args, "-nodes")) enc=NULL;
                else if (!strcmp (*args, "-certpbe")) {
-                       if (args[1]) {
-                               args++;
-                               if (!strcmp(*args, "NONE"))
-                                       cert_pbe = -1;
-                               else
-                                       cert_pbe=OBJ_txt2nid(*args);
-                               if(cert_pbe == NID_undef) {
-                                       BIO_printf(bio_err,
-                                                "Unknown PBE algorithm %s\n", *args);
-                                       badarg = 1;
-                               }
-                       } else badarg = 1;
+                       if (!set_pbe(bio_err, &cert_pbe, *++args))
+                               badarg = 1;
                } else if (!strcmp (*args, "-keypbe")) {
-                       if (args[1]) {
-                               args++;
-                               if (!strcmp(*args, "NONE"))
-                                       key_pbe = -1;
-                               else
-                                       key_pbe=OBJ_txt2nid(*args);
-                               if(key_pbe == NID_undef) {
-                                       BIO_printf(bio_err,
-                                                "Unknown PBE algorithm %s\n", *args);
-                                       badarg = 1;
-                               }
-                       } else badarg = 1;
+                       if (!set_pbe(bio_err, &key_pbe, *++args))
+                               badarg = 1;
                } else if (!strcmp (*args, "-rand")) {
                    if (args[1]) {
                        args++; 
@@ -248,8 +222,8 @@ int MAIN(int argc, char **argv)
                } else if (!strcmp (*args, "-caname")) {
                    if (args[1]) {
                        args++; 
-                       if (!canames) canames = sk_new_null();
-                       sk_push(canames, *args);
+                       if (!canames) canames = sk_OPENSSL_STRING_new_null();
+                       sk_OPENSSL_STRING_push(canames, *args);
                    } else badarg = 1;
                } else if (!strcmp (*args, "-in")) {
                    if (args[1]) {
@@ -338,11 +312,14 @@ int MAIN(int argc, char **argv)
 #endif
        BIO_printf (bio_err, "-nodes        don't encrypt private keys\n");
        BIO_printf (bio_err, "-noiter       don't use encryption iteration\n");
+       BIO_printf (bio_err, "-nomaciter    don't use MAC iteration\n");
        BIO_printf (bio_err, "-maciter      use MAC iteration\n");
+       BIO_printf (bio_err, "-nomac        don't generate MAC\n");
        BIO_printf (bio_err, "-twopass      separate MAC, encryption passwords\n");
        BIO_printf (bio_err, "-descert      encrypt PKCS#12 certificates with triple DES (default RC2-40)\n");
        BIO_printf (bio_err, "-certpbe alg  specify certificate PBE algorithm (default RC2-40)\n");
        BIO_printf (bio_err, "-keypbe alg   specify private key PBE algorithm (default 3DES)\n");
+       BIO_printf (bio_err, "-macalg alg   digest algorithm used in MAC (default SHA1)\n");
        BIO_printf (bio_err, "-keyex        set MS key exchange type\n");
        BIO_printf (bio_err, "-keysig       set MS key signature type\n");
        BIO_printf (bio_err, "-password p   set import/export password source\n");
@@ -354,8 +331,8 @@ int MAIN(int argc, char **argv)
        BIO_printf(bio_err,  "-rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR);
        BIO_printf(bio_err,  "              load the file (or the files in the directory) into\n");
        BIO_printf(bio_err,  "              the random number generator\n");
-       BIO_printf(bio_err,  "-CSP name     Microsoft CSP name\n");
-       BIO_printf(bio_err,  "-LMK          Add local machine keyset attribute to private key\n");
+       BIO_printf(bio_err,  "-CSP name     Microsoft CSP name\n");
+       BIO_printf(bio_err,  "-LMK          Add local machine keyset attribute to private key\n");
        goto end;
     }
 
@@ -445,6 +422,7 @@ int MAIN(int argc, char **argv)
        EVP_PKEY *key = NULL;
        X509 *ucert = NULL, *x = NULL;
        STACK_OF(X509) *certs=NULL;
+       const EVP_MD *macmd = NULL;
        unsigned char *catmp = NULL;
        int i;
 
@@ -571,9 +549,9 @@ int MAIN(int argc, char **argv)
 
        /* Add any CA names */
 
-       for (i = 0; i < sk_num(canames); i++)
+       for (i = 0; i < sk_OPENSSL_STRING_num(canames); i++)
                {
-               catmp = (unsigned char *)sk_value(canames, i);
+               catmp = (unsigned char *)sk_OPENSSL_STRING_value(canames, i);
                X509_alias_set1(sk_X509_value(certs, i), catmp, -1);
                }
 
@@ -611,8 +589,18 @@ int MAIN(int argc, char **argv)
                goto export_end;
                }
 
+       if (macalg)
+               {
+               macmd = EVP_get_digestbyname(macalg);
+               if (!macmd)
+                       {
+                       BIO_printf(bio_err, "Unknown digest algorithm %s\n", 
+                                               macalg);
+                       }
+               }
+
        if (maciter != -1)
-               PKCS12_set_mac(p12, mpass, -1, NULL, 0, maciter, NULL);
+               PKCS12_set_mac(p12, mpass, -1, NULL, 0, maciter, macmd);
 
 #ifdef CRYPTO_MDEBUG
        CRYPTO_pop_info();
@@ -659,7 +647,7 @@ int MAIN(int argc, char **argv)
 
     if (!twopass) BUF_strlcpy(macpass, pass, sizeof macpass);
 
-    if (options & INFO) BIO_printf (bio_err, "MAC Iteration %ld\n", p12->mac->iter ? ASN1_INTEGER_get (p12->mac->iter) : 1);
+    if ((options & INFO) && p12->mac) BIO_printf (bio_err, "MAC Iteration %ld\n", p12->mac->iter ? ASN1_INTEGER_get (p12->mac->iter) : 1);
     if(macver) {
 #ifdef CRYPTO_MDEBUG
     CRYPTO_push_info("verify MAC");
@@ -699,7 +687,7 @@ int MAIN(int argc, char **argv)
 #endif
     BIO_free(in);
     BIO_free_all(out);
-    if (canames) sk_free(canames);
+    if (canames) sk_OPENSSL_STRING_free(canames);
     if(passin) OPENSSL_free(passin);
     if(passout) OPENSSL_free(passout);
     apps_shutdown();
@@ -935,7 +923,7 @@ int print_attribs (BIO *out, STACK_OF(X509_ATTRIBUTE) *attrlst,const char *name)
                        av = sk_ASN1_TYPE_value(attr->value.set, 0);
                        switch(av->type) {
                                case V_ASN1_BMPSTRING:
-                               value = uni2asc(av->value.bmpstring->data,
+                               value = OPENSSL_uni2asc(av->value.bmpstring->data,
                                               av->value.bmpstring->length);
                                BIO_printf(out, "%s\n", value);
                                OPENSSL_free(value);
@@ -968,4 +956,22 @@ void hex_prin(BIO *out, unsigned char *buf, int len)
        for (i = 0; i < len; i++) BIO_printf (out, "%02X ", buf[i]);
 }
 
+static int set_pbe(BIO *err, int *ppbe, const char *str)
+       {
+       if (!str)
+               return 0;
+       if (!strcmp(str, "NONE"))
+               {
+               *ppbe = -1;
+               return 1;
+               }
+       *ppbe=OBJ_txt2nid(str);
+       if (*ppbe == NID_undef)
+               {
+               BIO_printf(bio_err, "Unknown PBE algorithm %s\n", str);
+               return 0;
+               }
+       return 1;
+       }
+                       
 #endif
index bdbb102..ae6cd33 100644 (file)
@@ -87,7 +87,7 @@ int MAIN(int argc, char **argv)
        BIO *in=NULL,*out=NULL;
        int informat,outformat;
        char *infile,*outfile,*prog;
-       int print_certs=0,text=0,noout=0;
+       int print_certs=0,text=0,noout=0,p7_print=0;
        int ret=1;
 #ifndef OPENSSL_NO_ENGINE
        char *engine=NULL;
@@ -136,6 +136,8 @@ int MAIN(int argc, char **argv)
                        noout=1;
                else if (strcmp(*argv,"-text") == 0)
                        text=1;
+               else if (strcmp(*argv,"-print") == 0)
+                       p7_print=1;
                else if (strcmp(*argv,"-print_certs") == 0)
                        print_certs=1;
 #ifndef OPENSSL_NO_ENGINE
@@ -235,6 +237,9 @@ bad:
                        }
                }
 
+       if (p7_print)
+               PKCS7_print_ctx(out, p7, 0, NULL);
+
        if (print_certs)
                {
                STACK_OF(X509) *certs=NULL;
index 9633a14..7edeb17 100644 (file)
@@ -80,11 +80,12 @@ int MAIN(int argc, char **argv)
        int informat, outformat;
        int p8_broken = PKCS8_OK;
        int nocrypt = 0;
-       X509_SIG *p8;
-       PKCS8_PRIV_KEY_INFO *p8inf;
+       X509_SIG *p8 = NULL;
+       PKCS8_PRIV_KEY_INFO *p8inf = NULL;
        EVP_PKEY *pkey=NULL;
        char pass[50], *passin = NULL, *passout = NULL, *p8pass = NULL;
        int badarg = 0;
+       int ret = 1;
 #ifndef OPENSSL_NO_ENGINE
        char *engine=NULL;
 #endif
@@ -225,7 +226,7 @@ int MAIN(int argc, char **argv)
 #ifndef OPENSSL_NO_ENGINE
                BIO_printf(bio_err," -engine e       use engine e, possibly a hardware device.\n");
 #endif
-               return 1;
+               goto end;
                }
 
 #ifndef OPENSSL_NO_ENGINE
@@ -235,7 +236,7 @@ int MAIN(int argc, char **argv)
        if (!app_passwd(bio_err, passargin, passargout, &passin, &passout))
                {
                BIO_printf(bio_err, "Error getting passwords\n");
-               return 1;
+               goto end;
                }
 
        if ((pbe_nid == -1) && !cipher)
@@ -247,7 +248,7 @@ int MAIN(int argc, char **argv)
                        {
                        BIO_printf(bio_err,
                                 "Can't open input file %s\n", infile);
-                       return (1);
+                       goto end;
                        }
                }
        else
@@ -259,7 +260,7 @@ int MAIN(int argc, char **argv)
                        {
                        BIO_printf(bio_err,
                                 "Can't open output file %s\n", outfile);
-                       return (1);
+                       goto end;
                        }
                }
        else
@@ -274,21 +275,15 @@ int MAIN(int argc, char **argv)
                }
        if (topk8)
                {
-               BIO_free(in); /* Not needed in this section */
                pkey = load_key(bio_err, infile, informat, 1,
                        passin, e, "key");
                if (!pkey)
-                       {
-                       BIO_free_all(out);
-                       return 1;
-                       }
+                       goto end;
                if (!(p8inf = EVP_PKEY2PKCS8_broken(pkey, p8_broken)))
                        {
                        BIO_printf(bio_err, "Error converting key\n");
                        ERR_print_errors(bio_err);
-                       EVP_PKEY_free(pkey);
-                       BIO_free_all(out);
-                       return 1;
+                       goto end;
                        }
                if (nocrypt)
                        {
@@ -299,10 +294,7 @@ int MAIN(int argc, char **argv)
                        else
                                {
                                BIO_printf(bio_err, "Bad format specified for key\n");
-                               PKCS8_PRIV_KEY_INFO_free(p8inf);
-                               EVP_PKEY_free(pkey);
-                               BIO_free_all(out);
-                               return (1);
+                               goto end;
                                }
                        }
                else
@@ -313,12 +305,7 @@ int MAIN(int argc, char **argv)
                                {
                                p8pass = pass;
                                if (EVP_read_pw_string(pass, sizeof pass, "Enter Encryption Password:", 1))
-                                       {
-                                       PKCS8_PRIV_KEY_INFO_free(p8inf);
-                                       EVP_PKEY_free(pkey);
-                                       BIO_free_all(out);
-                                       return (1);
-                                       }
+                                       goto end;
                                }
                        app_RAND_load_file(NULL, bio_err, 0);
                        if (!(p8 = PKCS8_encrypt(pbe_nid, cipher,
@@ -327,10 +314,7 @@ int MAIN(int argc, char **argv)
                                {
                                BIO_printf(bio_err, "Error encrypting key\n");
                                ERR_print_errors(bio_err);
-                               PKCS8_PRIV_KEY_INFO_free(p8inf);
-                               EVP_PKEY_free(pkey);
-                               BIO_free_all(out);
-                               return (1);
+                               goto end;
                                }
                        app_RAND_write_file(NULL, bio_err);
                        if (outformat == FORMAT_PEM) 
@@ -340,22 +324,12 @@ int MAIN(int argc, char **argv)
                        else
                                {
                                BIO_printf(bio_err, "Bad format specified for key\n");
-                               PKCS8_PRIV_KEY_INFO_free(p8inf);
-                               EVP_PKEY_free(pkey);
-                               BIO_free_all(out);
-                               return (1);
+                               goto end;
                                }
-                       X509_SIG_free(p8);
                        }
 
-               PKCS8_PRIV_KEY_INFO_free (p8inf);
-               EVP_PKEY_free(pkey);
-               BIO_free_all(out);
-               if (passin)
-                       OPENSSL_free(passin);
-               if (passout)
-                       OPENSSL_free(passout);
-               return (0);
+               ret = 0;
+               goto end;
                }
 
        if (nocrypt)
@@ -367,7 +341,7 @@ int MAIN(int argc, char **argv)
                else
                        {
                        BIO_printf(bio_err, "Bad format specified for key\n");
-                       return (1);
+                       goto end;
                        }
                }
        else
@@ -379,14 +353,14 @@ int MAIN(int argc, char **argv)
                else
                        {
                        BIO_printf(bio_err, "Bad format specified for key\n");
-                       return (1);
+                       goto end;
                        }
 
                if (!p8)
                        {
                        BIO_printf (bio_err, "Error reading key\n");
                        ERR_print_errors(bio_err);
-                       return (1);
+                       goto end;
                        }
                if (passin)
                        p8pass = passin;
@@ -396,21 +370,20 @@ int MAIN(int argc, char **argv)
                        EVP_read_pw_string(pass, sizeof pass, "Enter Password:", 0);
                        }
                p8inf = PKCS8_decrypt(p8, p8pass, strlen(p8pass));
-               X509_SIG_free(p8);
                }
 
        if (!p8inf)
                {
                BIO_printf(bio_err, "Error decrypting key\n");
                ERR_print_errors(bio_err);
-               return (1);
+               goto end;
                }
 
        if (!(pkey = EVP_PKCS82PKEY(p8inf)))
                {
                BIO_printf(bio_err, "Error converting key\n");
                ERR_print_errors(bio_err);
-               return (1);
+               goto end;
                }
        
        if (p8inf->broken)
@@ -430,13 +403,16 @@ int MAIN(int argc, char **argv)
                        BIO_printf(bio_err, "DSA public key include in PrivateKey\n");
                        break;
 
+                       case PKCS8_NEG_PRIVKEY:
+                       BIO_printf(bio_err, "DSA private key value is negative\n");
+                       break;
+
                        default:
                        BIO_printf(bio_err, "Unknown broken type\n");
                        break;
                }
        }
        
-       PKCS8_PRIV_KEY_INFO_free(p8inf);
        if (outformat == FORMAT_PEM) 
                PEM_write_bio_PrivateKey(out, pkey, NULL, NULL, 0, NULL, passout);
        else if (outformat == FORMAT_ASN1)
@@ -444,10 +420,13 @@ int MAIN(int argc, char **argv)
        else
                {
                BIO_printf(bio_err, "Bad format specified for key\n");
-                       return (1);
+                       goto end;
                }
+       ret = 0;
 
        end:
+       X509_SIG_free(p8);
+       PKCS8_PRIV_KEY_INFO_free(p8inf);
        EVP_PKEY_free(pkey);
        BIO_free_all(out);
        BIO_free(in);
@@ -456,5 +435,5 @@ int MAIN(int argc, char **argv)
        if (passout)
                OPENSSL_free(passout);
 
-       return (0);
+       return ret;
        }
diff --git a/deps/openssl/openssl/apps/pkey.c b/deps/openssl/openssl/apps/pkey.c
new file mode 100644 (file)
index 0000000..17e6702
--- /dev/null
@@ -0,0 +1,284 @@
+/* apps/pkey.c */
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project 2006
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+#include <stdio.h>
+#include <string.h>
+#include "apps.h"
+#include <openssl/pem.h>
+#include <openssl/err.h>
+#include <openssl/evp.h>
+
+#define PROG pkey_main
+
+int MAIN(int, char **);
+
+int MAIN(int argc, char **argv)
+       {
+       ENGINE *e = NULL;
+       char **args, *infile = NULL, *outfile = NULL;
+       char *passargin = NULL, *passargout = NULL;
+       BIO *in = NULL, *out = NULL;
+       const EVP_CIPHER *cipher = NULL;
+       int informat, outformat;
+       int pubin = 0, pubout = 0, pubtext = 0, text = 0, noout = 0;
+       EVP_PKEY *pkey=NULL;
+       char *passin = NULL, *passout = NULL;
+       int badarg = 0;
+#ifndef OPENSSL_NO_ENGINE
+       char *engine=NULL;
+#endif
+       int ret = 1;
+
+       if (bio_err == NULL)
+               bio_err = BIO_new_fp (stderr, BIO_NOCLOSE);
+
+       if (!load_config(bio_err, NULL))
+               goto end;
+
+       informat=FORMAT_PEM;
+       outformat=FORMAT_PEM;
+
+       ERR_load_crypto_strings();
+       OpenSSL_add_all_algorithms();
+       args = argv + 1;
+       while (!badarg && *args && *args[0] == '-')
+               {
+               if (!strcmp(*args,"-inform"))
+                       {
+                       if (args[1])
+                               {
+                               args++;
+                               informat=str2fmt(*args);
+                               }
+                       else badarg = 1;
+                       }
+               else if (!strcmp(*args,"-outform"))
+                       {
+                       if (args[1])
+                               {
+                               args++;
+                               outformat=str2fmt(*args);
+                               }
+                       else badarg = 1;
+                       }
+               else if (!strcmp(*args,"-passin"))
+                       {
+                       if (!args[1]) goto bad;
+                       passargin= *(++args);
+                       }
+               else if (!strcmp(*args,"-passout"))
+                       {
+                       if (!args[1]) goto bad;
+                       passargout= *(++args);
+                       }
+#ifndef OPENSSL_NO_ENGINE
+               else if (strcmp(*args,"-engine") == 0)
+                       {
+                       if (!args[1]) goto bad;
+                       engine= *(++args);
+                       }
+#endif
+               else if (!strcmp (*args, "-in"))
+                       {
+                       if (args[1])
+                               {
+                               args++;
+                               infile = *args;
+                               }
+                       else badarg = 1;
+                       }
+               else if (!strcmp (*args, "-out"))
+                       {
+                       if (args[1])
+                               {
+                               args++;
+                               outfile = *args;
+                               }
+                       else badarg = 1;
+                       }
+               else if (strcmp(*args,"-pubin") == 0)
+                       {
+                       pubin=1;
+                       pubout=1;
+                       pubtext=1;
+                       }
+               else if (strcmp(*args,"-pubout") == 0)
+                       pubout=1;
+               else if (strcmp(*args,"-text_pub") == 0)
+                       {
+                       pubtext=1;
+                       text=1;
+                       }
+               else if (strcmp(*args,"-text") == 0)
+                       text=1;
+               else if (strcmp(*args,"-noout") == 0)
+                       noout=1;
+               else
+                       {
+                       cipher = EVP_get_cipherbyname(*args + 1);
+                       if (!cipher)
+                               {
+                               BIO_printf(bio_err, "Unknown cipher %s\n",
+                                                               *args + 1);
+                               badarg = 1;
+                               }
+                       }
+               args++;
+               }
+
+       if (badarg)
+               {
+               bad:
+               BIO_printf(bio_err, "Usage pkey [options]\n");
+               BIO_printf(bio_err, "where options are\n");
+               BIO_printf(bio_err, "-in file        input file\n");
+               BIO_printf(bio_err, "-inform X       input format (DER or PEM)\n");
+               BIO_printf(bio_err, "-passin arg     input file pass phrase source\n");
+               BIO_printf(bio_err, "-outform X      output format (DER or PEM)\n");
+               BIO_printf(bio_err, "-out file       output file\n");
+               BIO_printf(bio_err, "-passout arg    output file pass phrase source\n");
+#ifndef OPENSSL_NO_ENGINE
+               BIO_printf(bio_err, "-engine e       use engine e, possibly a hardware device.\n");
+#endif
+               return 1;
+               }
+
+#ifndef OPENSSL_NO_ENGINE
+        e = setup_engine(bio_err, engine, 0);
+#endif
+
+       if (!app_passwd(bio_err, passargin, passargout, &passin, &passout))
+               {
+               BIO_printf(bio_err, "Error getting passwords\n");
+               goto end;
+               }
+
+       if (outfile)
+               {
+               if (!(out = BIO_new_file (outfile, "wb")))
+                       {
+                       BIO_printf(bio_err,
+                                "Can't open output file %s\n", outfile);
+                       goto end;
+                       }
+               }
+       else
+               {
+               out = BIO_new_fp (stdout, BIO_NOCLOSE);
+#ifdef OPENSSL_SYS_VMS
+                       {
+                       BIO *tmpbio = BIO_new(BIO_f_linebuffer());
+                       out = BIO_push(tmpbio, out);
+                       }
+#endif
+               }
+
+       if (pubin)
+               pkey = load_pubkey(bio_err, infile, informat, 1,
+                       passin, e, "Public Key");
+       else
+               pkey = load_key(bio_err, infile, informat, 1,
+                       passin, e, "key");
+       if (!pkey)
+               goto end;
+
+       if (!noout)
+               {
+               if (outformat == FORMAT_PEM) 
+                       {
+                       if (pubout)
+                               PEM_write_bio_PUBKEY(out,pkey);
+                       else
+                               PEM_write_bio_PrivateKey(out, pkey, cipher,
+                                                       NULL, 0, NULL, passout);
+                       }
+               else if (outformat == FORMAT_ASN1)
+                       {
+                       if (pubout)
+                               i2d_PUBKEY_bio(out, pkey);
+                       else
+                               i2d_PrivateKey_bio(out, pkey);
+                       }
+               else
+                       {
+                       BIO_printf(bio_err, "Bad format specified for key\n");
+                       goto end;
+                       }
+
+               }
+
+       if (text)
+               {
+               if (pubtext)
+                       EVP_PKEY_print_public(out, pkey, 0, NULL);
+               else
+                       EVP_PKEY_print_private(out, pkey, 0, NULL);
+               }
+
+       ret = 0;
+
+       end:
+       EVP_PKEY_free(pkey);
+       BIO_free_all(out);
+       BIO_free(in);
+       if (passin)
+               OPENSSL_free(passin);
+       if (passout)
+               OPENSSL_free(passout);
+
+       return ret;
+       }
diff --git a/deps/openssl/openssl/apps/pkeyparam.c b/deps/openssl/openssl/apps/pkeyparam.c
new file mode 100644 (file)
index 0000000..6f7a357
--- /dev/null
@@ -0,0 +1,200 @@
+/* apps/pkeyparam.c */
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project 2006
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+#include <stdio.h>
+#include <string.h>
+#include "apps.h"
+#include <openssl/pem.h>
+#include <openssl/err.h>
+#include <openssl/evp.h>
+
+#define PROG pkeyparam_main
+
+int MAIN(int, char **);
+
+int MAIN(int argc, char **argv)
+       {
+       char **args, *infile = NULL, *outfile = NULL;
+       BIO *in = NULL, *out = NULL;
+       int text = 0, noout = 0;
+       EVP_PKEY *pkey=NULL;
+       int badarg = 0;
+#ifndef OPENSSL_NO_ENGINE
+       char *engine=NULL;
+#endif
+       int ret = 1;
+
+       if (bio_err == NULL)
+               bio_err = BIO_new_fp (stderr, BIO_NOCLOSE);
+
+       if (!load_config(bio_err, NULL))
+               goto end;
+
+       ERR_load_crypto_strings();
+       OpenSSL_add_all_algorithms();
+       args = argv + 1;
+       while (!badarg && *args && *args[0] == '-')
+               {
+               if (!strcmp (*args, "-in"))
+                       {
+                       if (args[1])
+                               {
+                               args++;
+                               infile = *args;
+                               }
+                       else badarg = 1;
+                       }
+               else if (!strcmp (*args, "-out"))
+                       {
+                       if (args[1])
+                               {
+                               args++;
+                               outfile = *args;
+                               }
+                       else badarg = 1;
+                       }
+#ifndef OPENSSL_NO_ENGINE
+               else if (strcmp(*args,"-engine") == 0)
+                       {
+                       if (!args[1]) goto bad;
+                       engine= *(++args);
+                       }
+#endif
+
+               else if (strcmp(*args,"-text") == 0)
+                       text=1;
+               else if (strcmp(*args,"-noout") == 0)
+                       noout=1;
+               args++;
+               }
+
+       if (badarg)
+               {
+#ifndef OPENSSL_NO_ENGINE
+               bad:
+#endif
+               BIO_printf(bio_err, "Usage pkeyparam [options]\n");
+               BIO_printf(bio_err, "where options are\n");
+               BIO_printf(bio_err, "-in file        input file\n");
+               BIO_printf(bio_err, "-out file       output file\n");
+               BIO_printf(bio_err, "-text           print parameters as text\n");
+               BIO_printf(bio_err, "-noout          don't output encoded parameters\n");
+#ifndef OPENSSL_NO_ENGINE
+               BIO_printf(bio_err, "-engine e       use engine e, possibly a hardware device.\n");
+#endif
+               return 1;
+               }
+
+#ifndef OPENSSL_NO_ENGINE
+        setup_engine(bio_err, engine, 0);
+#endif
+
+       if (infile)
+               {
+               if (!(in = BIO_new_file (infile, "r")))
+                       {
+                       BIO_printf(bio_err,
+                                "Can't open input file %s\n", infile);
+                       goto end;
+                       }
+               }
+       else
+               in = BIO_new_fp (stdin, BIO_NOCLOSE);
+
+       if (outfile)
+               {
+               if (!(out = BIO_new_file (outfile, "w")))
+                       {
+                       BIO_printf(bio_err,
+                                "Can't open output file %s\n", outfile);
+                       goto end;
+                       }
+               }
+       else
+               {
+               out = BIO_new_fp (stdout, BIO_NOCLOSE);
+#ifdef OPENSSL_SYS_VMS
+                       {
+                       BIO *tmpbio = BIO_new(BIO_f_linebuffer());
+                       out = BIO_push(tmpbio, out);
+                       }
+#endif
+               }
+
+       pkey = PEM_read_bio_Parameters(in, NULL);
+       if (!pkey)
+               {
+               BIO_printf(bio_err, "Error reading parameters\n");
+               ERR_print_errors(bio_err);
+               goto end;
+               }
+
+       if (!noout)
+               PEM_write_bio_Parameters(out,pkey);
+
+       if (text)
+               EVP_PKEY_print_params(out, pkey, 0, NULL);
+
+       ret = 0;
+
+       end:
+       EVP_PKEY_free(pkey);
+       BIO_free_all(out);
+       BIO_free(in);
+
+       return ret;
+       }
diff --git a/deps/openssl/openssl/apps/pkeyutl.c b/deps/openssl/openssl/apps/pkeyutl.c
new file mode 100644 (file)
index 0000000..7eb3f5c
--- /dev/null
@@ -0,0 +1,570 @@
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project 2006.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+
+#include "apps.h"
+#include <string.h>
+#include <openssl/err.h>
+#include <openssl/pem.h>
+#include <openssl/evp.h>
+
+#define KEY_PRIVKEY    1
+#define KEY_PUBKEY     2
+#define KEY_CERT       3
+
+static void usage(void);
+
+#undef PROG
+
+#define PROG pkeyutl_main
+
+static EVP_PKEY_CTX *init_ctx(int *pkeysize,
+                               char *keyfile, int keyform, int key_type,
+                               char *passargin, int pkey_op, ENGINE *e);
+
+static int setup_peer(BIO *err, EVP_PKEY_CTX *ctx, int peerform,
+                                                       const char *file);
+
+static int do_keyop(EVP_PKEY_CTX *ctx, int pkey_op,
+               unsigned char *out, size_t *poutlen,
+               unsigned char *in, size_t inlen);
+
+int MAIN(int argc, char **);
+
+int MAIN(int argc, char **argv)
+{
+       BIO *in = NULL, *out = NULL;
+       char *infile = NULL, *outfile = NULL, *sigfile = NULL;
+       ENGINE *e = NULL;
+       int pkey_op = EVP_PKEY_OP_SIGN, key_type = KEY_PRIVKEY;
+       int keyform = FORMAT_PEM, peerform = FORMAT_PEM;
+       char badarg = 0, rev = 0;
+       char hexdump = 0, asn1parse = 0;
+       EVP_PKEY_CTX *ctx = NULL;
+       char *passargin = NULL;
+       int keysize = -1;
+
+       unsigned char *buf_in = NULL, *buf_out = NULL, *sig = NULL;
+       size_t buf_outlen;
+       int buf_inlen = 0, siglen = -1;
+
+       int ret = 1, rv = -1;
+
+       argc--;
+       argv++;
+
+       if(!bio_err) bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
+
+       if (!load_config(bio_err, NULL))
+               goto end;
+       ERR_load_crypto_strings();
+       OpenSSL_add_all_algorithms();
+       
+       while(argc >= 1)
+               {
+               if (!strcmp(*argv,"-in"))
+                       {
+                       if (--argc < 1) badarg = 1;
+                        else infile= *(++argv);
+                       }
+               else if (!strcmp(*argv,"-out"))
+                       {
+                       if (--argc < 1) badarg = 1;
+                       else outfile= *(++argv);
+                       }
+               else if (!strcmp(*argv,"-sigfile"))
+                       {
+                       if (--argc < 1) badarg = 1;
+                       else sigfile= *(++argv);
+                       }
+               else if(!strcmp(*argv, "-inkey"))
+                       {
+                       if (--argc < 1)
+                               badarg = 1;
+                       else
+                               {
+                               ctx = init_ctx(&keysize,
+                                               *(++argv), keyform, key_type,
+                                               passargin, pkey_op, e);
+                               if (!ctx)
+                                       {
+                                       BIO_puts(bio_err,
+                                               "Error initializing context\n");
+                                       ERR_print_errors(bio_err);
+                                       badarg = 1;
+                                       }
+                               }
+                       }
+               else if (!strcmp(*argv,"-peerkey"))
+                       {
+                       if (--argc < 1)
+                               badarg = 1;
+                       else if (!setup_peer(bio_err, ctx, peerform, *(++argv)))
+                               badarg = 1;
+                       }
+               else if (!strcmp(*argv,"-passin"))
+                       {
+                       if (--argc < 1) badarg = 1;
+                       else passargin= *(++argv);
+                       }
+               else if (strcmp(*argv,"-peerform") == 0)
+                       {
+                       if (--argc < 1) badarg = 1;
+                       else peerform=str2fmt(*(++argv));
+                       }
+               else if (strcmp(*argv,"-keyform") == 0)
+                       {
+                       if (--argc < 1) badarg = 1;
+                       else keyform=str2fmt(*(++argv));
+                       }
+#ifndef OPENSSL_NO_ENGINE
+               else if(!strcmp(*argv, "-engine"))
+                       {
+                       if (--argc < 1)
+                               badarg = 1;
+                       else
+                               e = setup_engine(bio_err, *(++argv), 0);
+                       }
+#endif
+               else if(!strcmp(*argv, "-pubin"))
+                       key_type = KEY_PUBKEY;
+               else if(!strcmp(*argv, "-certin"))
+                       key_type = KEY_CERT;
+               else if(!strcmp(*argv, "-asn1parse"))
+                       asn1parse = 1;
+               else if(!strcmp(*argv, "-hexdump"))
+                       hexdump = 1;
+               else if(!strcmp(*argv, "-sign"))
+                       pkey_op = EVP_PKEY_OP_SIGN;
+               else if(!strcmp(*argv, "-verify"))
+                       pkey_op = EVP_PKEY_OP_VERIFY;
+               else if(!strcmp(*argv, "-verifyrecover"))
+                       pkey_op = EVP_PKEY_OP_VERIFYRECOVER;
+               else if(!strcmp(*argv, "-rev"))
+                       rev = 1;
+               else if(!strcmp(*argv, "-encrypt"))
+                       pkey_op = EVP_PKEY_OP_ENCRYPT;
+               else if(!strcmp(*argv, "-decrypt"))
+                       pkey_op = EVP_PKEY_OP_DECRYPT;
+               else if(!strcmp(*argv, "-derive"))
+                       pkey_op = EVP_PKEY_OP_DERIVE;
+               else if (strcmp(*argv,"-pkeyopt") == 0)
+                       {
+                       if (--argc < 1)
+                               badarg = 1;
+                       else if (!ctx)
+                               {
+                               BIO_puts(bio_err,
+                                       "-pkeyopt command before -inkey\n");
+                               badarg = 1;
+                               }
+                       else if (pkey_ctrl_string(ctx, *(++argv)) <= 0)
+                               {
+                               BIO_puts(bio_err, "parameter setting error\n");
+                               ERR_print_errors(bio_err);
+                               goto end;
+                               }
+                       }
+               else badarg = 1;
+               if(badarg)
+                       {
+                       usage();
+                       goto end;
+                       }
+               argc--;
+               argv++;
+               }
+
+       if (!ctx)
+               {
+               usage();
+               goto end;
+               }
+
+       if (sigfile && (pkey_op != EVP_PKEY_OP_VERIFY))
+               {
+               BIO_puts(bio_err, "Signature file specified for non verify\n");
+               goto end;
+               }
+
+       if (!sigfile && (pkey_op == EVP_PKEY_OP_VERIFY))
+               {
+               BIO_puts(bio_err, "No signature file specified for verify\n");
+               goto end;
+               }
+
+/* FIXME: seed PRNG only if needed */
+       app_RAND_load_file(NULL, bio_err, 0);
+
+       if (pkey_op != EVP_PKEY_OP_DERIVE)
+               {
+               if(infile)
+                       {
+                       if(!(in = BIO_new_file(infile, "rb")))
+                               {
+                               BIO_puts(bio_err,
+                                       "Error Opening Input File\n");
+                               ERR_print_errors(bio_err);      
+                               goto end;
+                               }
+                       }
+               else
+                       in = BIO_new_fp(stdin, BIO_NOCLOSE);
+               }
+
+       if(outfile)
+               {
+               if(!(out = BIO_new_file(outfile, "wb")))
+                       {
+                       BIO_printf(bio_err, "Error Creating Output File\n");
+                       ERR_print_errors(bio_err);      
+                       goto end;
+                       }
+               }
+       else
+               {
+               out = BIO_new_fp(stdout, BIO_NOCLOSE);
+#ifdef OPENSSL_SYS_VMS
+               {
+                   BIO *tmpbio = BIO_new(BIO_f_linebuffer());
+                   out = BIO_push(tmpbio, out);
+               }
+#endif
+       }
+
+       if (sigfile)
+               {
+               BIO *sigbio = BIO_new_file(sigfile, "rb");
+               if (!sigbio)
+                       {
+                       BIO_printf(bio_err, "Can't open signature file %s\n",
+                                                               sigfile);
+                       goto end;
+                       }
+               siglen = bio_to_mem(&sig, keysize * 10, sigbio);
+               BIO_free(sigbio);
+               if (siglen <= 0)
+                       {
+                       BIO_printf(bio_err, "Error reading signature data\n");
+                       goto end;
+                       }
+               }
+       
+       if (in)
+               {
+               /* Read the input data */
+               buf_inlen = bio_to_mem(&buf_in, keysize * 10, in);
+               if(buf_inlen <= 0)
+                       {
+                       BIO_printf(bio_err, "Error reading input Data\n");
+                       exit(1);
+                       }
+               if(rev)
+                       {
+                       size_t i;
+                       unsigned char ctmp;
+                       size_t l = (size_t)buf_inlen;
+                       for(i = 0; i < l/2; i++)
+                               {
+                               ctmp = buf_in[i];
+                               buf_in[i] = buf_in[l - 1 - i];
+                               buf_in[l - 1 - i] = ctmp;
+                               }
+                       }
+               }
+
+       if(pkey_op == EVP_PKEY_OP_VERIFY)
+               {
+               rv  = EVP_PKEY_verify(ctx, sig, (size_t)siglen,
+                                     buf_in, (size_t)buf_inlen);
+               if (rv == 0)
+                       BIO_puts(out, "Signature Verification Failure\n");
+               else if (rv == 1)
+                       BIO_puts(out, "Signature Verified Successfully\n");
+               if (rv >= 0)
+                       goto end;
+               }
+       else
+               {       
+               rv = do_keyop(ctx, pkey_op, NULL, (size_t *)&buf_outlen,
+                             buf_in, (size_t)buf_inlen);
+               if (rv > 0)
+                       {
+                       buf_out = OPENSSL_malloc(buf_outlen);
+                       if (!buf_out)
+                               rv = -1;
+                       else
+                               rv = do_keyop(ctx, pkey_op,
+                                               buf_out, (size_t *)&buf_outlen,
+                                               buf_in, (size_t)buf_inlen);
+                       }
+               }
+
+       if(rv <= 0)
+               {
+               BIO_printf(bio_err, "Public Key operation error\n");
+               ERR_print_errors(bio_err);
+               goto end;
+               }
+       ret = 0;
+       if(asn1parse)
+               {
+               if(!ASN1_parse_dump(out, buf_out, buf_outlen, 1, -1))
+                       ERR_print_errors(bio_err);
+               }
+       else if(hexdump)
+               BIO_dump(out, (char *)buf_out, buf_outlen);
+       else
+               BIO_write(out, buf_out, buf_outlen);
+
+       end:
+       if (ctx)
+               EVP_PKEY_CTX_free(ctx);
+       BIO_free(in);
+       BIO_free_all(out);
+       if (buf_in)
+               OPENSSL_free(buf_in);
+       if (buf_out)
+               OPENSSL_free(buf_out);
+       if (sig)
+               OPENSSL_free(sig);
+       return ret;
+}
+
+static void usage()
+{
+       BIO_printf(bio_err, "Usage: pkeyutl [options]\n");
+       BIO_printf(bio_err, "-in file        input file\n");
+       BIO_printf(bio_err, "-out file       output file\n");
+       BIO_printf(bio_err, "-sigfile file signature file (verify operation only)\n");
+       BIO_printf(bio_err, "-inkey file     input key\n");
+       BIO_printf(bio_err, "-keyform arg    private key format - default PEM\n");
+       BIO_printf(bio_err, "-pubin          input is a public key\n");
+       BIO_printf(bio_err, "-certin         input is a certificate carrying a public key\n");
+       BIO_printf(bio_err, "-pkeyopt X:Y    public key options\n");
+       BIO_printf(bio_err, "-sign           sign with private key\n");
+       BIO_printf(bio_err, "-verify         verify with public key\n");
+       BIO_printf(bio_err, "-verifyrecover  verify with public key, recover original data\n");
+       BIO_printf(bio_err, "-encrypt        encrypt with public key\n");
+       BIO_printf(bio_err, "-decrypt        decrypt with private key\n");
+       BIO_printf(bio_err, "-derive         derive shared secret\n");
+       BIO_printf(bio_err, "-hexdump        hex dump output\n");
+#ifndef OPENSSL_NO_ENGINE
+       BIO_printf(bio_err, "-engine e       use engine e, possibly a hardware device.\n");
+#endif
+       BIO_printf(bio_err, "-passin arg     pass phrase source\n");
+
+}
+
+static EVP_PKEY_CTX *init_ctx(int *pkeysize,
+                               char *keyfile, int keyform, int key_type,
+                               char *passargin, int pkey_op, ENGINE *e)
+       {
+       EVP_PKEY *pkey = NULL;
+       EVP_PKEY_CTX *ctx = NULL;
+       char *passin = NULL;
+       int rv = -1;
+       X509 *x;
+       if(((pkey_op == EVP_PKEY_OP_SIGN) || (pkey_op == EVP_PKEY_OP_DECRYPT) 
+               || (pkey_op == EVP_PKEY_OP_DERIVE))
+               && (key_type != KEY_PRIVKEY))
+               {
+               BIO_printf(bio_err, "A private key is needed for this operation\n");
+               goto end;
+               }
+       if(!app_passwd(bio_err, passargin, NULL, &passin, NULL))
+               {
+               BIO_printf(bio_err, "Error getting password\n");
+               goto end;
+               }
+       switch(key_type)
+               {
+               case KEY_PRIVKEY:
+               pkey = load_key(bio_err, keyfile, keyform, 0,
+                       passin, e, "Private Key");
+               break;
+
+               case KEY_PUBKEY:
+               pkey = load_pubkey(bio_err, keyfile, keyform, 0,
+                       NULL, e, "Public Key");
+               break;
+
+               case KEY_CERT:
+               x = load_cert(bio_err, keyfile, keyform,
+                       NULL, e, "Certificate");
+               if(x)
+                       {
+                       pkey = X509_get_pubkey(x);
+                       X509_free(x);
+                       }
+               break;
+
+               }
+
+       *pkeysize = EVP_PKEY_size(pkey);
+
+       if (!pkey)
+               goto end;
+
+       ctx = EVP_PKEY_CTX_new(pkey, e);
+
+       EVP_PKEY_free(pkey);
+
+       if (!ctx)
+               goto end;
+
+       switch(pkey_op)
+               {
+               case EVP_PKEY_OP_SIGN:
+               rv = EVP_PKEY_sign_init(ctx);
+               break;
+
+               case EVP_PKEY_OP_VERIFY:
+               rv = EVP_PKEY_verify_init(ctx);
+               break;
+
+               case EVP_PKEY_OP_VERIFYRECOVER:
+               rv = EVP_PKEY_verify_recover_init(ctx);
+               break;
+
+               case EVP_PKEY_OP_ENCRYPT:
+               rv = EVP_PKEY_encrypt_init(ctx);
+               break;
+
+               case EVP_PKEY_OP_DECRYPT:
+               rv = EVP_PKEY_decrypt_init(ctx);
+               break;
+
+               case EVP_PKEY_OP_DERIVE:
+               rv = EVP_PKEY_derive_init(ctx);
+               break;
+               }
+
+       if (rv <= 0)
+               {
+               EVP_PKEY_CTX_free(ctx);
+               ctx = NULL;
+               }
+
+       end:
+
+       if (passin)
+               OPENSSL_free(passin);
+
+       return ctx;
+
+
+       }
+
+static int setup_peer(BIO *err, EVP_PKEY_CTX *ctx, int peerform,
+                                                       const char *file)
+       {
+       EVP_PKEY *peer = NULL;
+       int ret;
+       if (!ctx)
+               {
+               BIO_puts(err, "-peerkey command before -inkey\n");
+               return 0;
+               }
+               
+       peer = load_pubkey(bio_err, file, peerform, 0, NULL, NULL, "Peer Key");
+
+       if (!peer)
+               {
+               BIO_printf(bio_err, "Error reading peer key %s\n", file);
+               ERR_print_errors(err);
+               return 0;
+               }
+
+       ret = EVP_PKEY_derive_set_peer(ctx, peer);
+
+       EVP_PKEY_free(peer);
+       if (ret <= 0)
+               ERR_print_errors(err);
+       return ret;
+       }
+
+static int do_keyop(EVP_PKEY_CTX *ctx, int pkey_op,
+               unsigned char *out, size_t *poutlen,
+               unsigned char *in, size_t inlen)
+       {
+       int rv = 0;
+       switch(pkey_op)
+               {
+               case EVP_PKEY_OP_VERIFYRECOVER:
+               rv  = EVP_PKEY_verify_recover(ctx, out, poutlen, in, inlen);
+               break;
+
+               case EVP_PKEY_OP_SIGN:
+               rv  = EVP_PKEY_sign(ctx, out, poutlen, in, inlen);
+               break;
+
+               case EVP_PKEY_OP_ENCRYPT:
+               rv  = EVP_PKEY_encrypt(ctx, out, poutlen, in, inlen);
+               break;
+
+               case EVP_PKEY_OP_DECRYPT:
+               rv  = EVP_PKEY_decrypt(ctx, out, poutlen, in, inlen);
+               break; 
+
+               case EVP_PKEY_OP_DERIVE:
+               rv  = EVP_PKEY_derive(ctx, out, poutlen);
+               break;
+
+               }
+       return rv;
+       }
index af2fed1..f1aaef8 100644 (file)
@@ -62,6 +62,9 @@ int MAIN(int argc, char **argv)
     {
     int hex=0;
     int checks=20;
+    int generate=0;
+    int bits=0;
+    int safe=0;
     BIGNUM *bn=NULL;
     BIO *bio_out;
 
@@ -77,6 +80,15 @@ int MAIN(int argc, char **argv)
        {
        if(!strcmp(*argv,"-hex"))
            hex=1;
+       else if(!strcmp(*argv,"-generate"))
+           generate=1;
+       else if(!strcmp(*argv,"-bits"))
+           if(--argc < 1)
+               goto bad;
+           else
+               bits=atoi(*++argv);
+       else if(!strcmp(*argv,"-safe"))
+           safe=1;
        else if(!strcmp(*argv,"-checks"))
            if(--argc < 1)
                goto bad;
@@ -91,13 +103,13 @@ int MAIN(int argc, char **argv)
        ++argv;
        }
 
-    if (argv[0] == NULL)
+    if (argv[0] == NULL && !generate)
        {
        BIO_printf(bio_err,"No prime specified\n");
        goto bad;
        }
 
-   if ((bio_out=BIO_new(BIO_s_file())) != NULL)
+    if ((bio_out=BIO_new(BIO_s_file())) != NULL)
        {
        BIO_set_fp(bio_out,stdout,BIO_NOCLOSE);
 #ifdef OPENSSL_SYS_VMS
@@ -108,14 +120,32 @@ int MAIN(int argc, char **argv)
 #endif
        }
 
-    if(hex)
-       BN_hex2bn(&bn,argv[0]);
+    if(generate)
+       {
+       char *s;
+
+       if(!bits)
+           {
+           BIO_printf(bio_err,"Specifiy the number of bits.\n");
+           return 1;
+           }
+       bn=BN_new();
+       BN_generate_prime_ex(bn,bits,safe,NULL,NULL,NULL);
+       s=hex ? BN_bn2hex(bn) : BN_bn2dec(bn);
+       BIO_printf(bio_out,"%s\n",s);
+       OPENSSL_free(s);
+       }
     else
-       BN_dec2bn(&bn,argv[0]);
+       {
+       if(hex)
+           BN_hex2bn(&bn,argv[0]);
+       else
+           BN_dec2bn(&bn,argv[0]);
 
-    BN_print(bio_out,bn);
-    BIO_printf(bio_out," is %sprime\n",
-              BN_is_prime_ex(bn,checks,NULL,NULL) ? "" : "not ");
+       BN_print(bio_out,bn);
+       BIO_printf(bio_out," is %sprime\n",
+                  BN_is_prime_ex(bn,checks,NULL,NULL) ? "" : "not ");
+       }
 
     BN_free(bn);
     BIO_free_all(bio_out);
index aafd800..728bb6d 100644 (file)
@@ -22,6 +22,7 @@ extern int ecparam_main(int argc,char *argv[]);
 extern int x509_main(int argc,char *argv[]);
 extern int genrsa_main(int argc,char *argv[]);
 extern int gendsa_main(int argc,char *argv[]);
+extern int genpkey_main(int argc,char *argv[]);
 extern int s_server_main(int argc,char *argv[]);
 extern int s_client_main(int argc,char *argv[]);
 extern int speed_main(int argc,char *argv[]);
@@ -35,22 +36,30 @@ extern int ciphers_main(int argc,char *argv[]);
 extern int nseq_main(int argc,char *argv[]);
 extern int pkcs12_main(int argc,char *argv[]);
 extern int pkcs8_main(int argc,char *argv[]);
+extern int pkey_main(int argc,char *argv[]);
+extern int pkeyparam_main(int argc,char *argv[]);
+extern int pkeyutl_main(int argc,char *argv[]);
 extern int spkac_main(int argc,char *argv[]);
 extern int smime_main(int argc,char *argv[]);
 extern int rand_main(int argc,char *argv[]);
 extern int engine_main(int argc,char *argv[]);
 extern int ocsp_main(int argc,char *argv[]);
 extern int prime_main(int argc,char *argv[]);
+extern int ts_main(int argc,char *argv[]);
 
 #define FUNC_TYPE_GENERAL      1
 #define FUNC_TYPE_MD           2
 #define FUNC_TYPE_CIPHER       3
+#define FUNC_TYPE_PKEY         4
+#define FUNC_TYPE_MD_ALG       5
+#define FUNC_TYPE_CIPHER_ALG   6
 
 typedef struct {
        int type;
        const char *name;
        int (*func)(int argc,char *argv[]);
        } FUNCTION;
+DECLARE_LHASH_OF(FUNCTION);
 
 FUNCTION functions[] = {
        {FUNC_TYPE_GENERAL,"verify",verify_main},
@@ -96,6 +105,7 @@ FUNCTION functions[] = {
 #ifndef OPENSSL_NO_DSA
        {FUNC_TYPE_GENERAL,"gendsa",gendsa_main},
 #endif
+       {FUNC_TYPE_GENERAL,"genpkey",genpkey_main},
 #if !defined(OPENSSL_NO_SOCK) && !(defined(OPENSSL_NO_SSL2) && defined(OPENSSL_NO_SSL3))
        {FUNC_TYPE_GENERAL,"s_server",s_server_main},
 #endif
@@ -123,14 +133,22 @@ FUNCTION functions[] = {
        {FUNC_TYPE_GENERAL,"pkcs12",pkcs12_main},
 #endif
        {FUNC_TYPE_GENERAL,"pkcs8",pkcs8_main},
+       {FUNC_TYPE_GENERAL,"pkey",pkey_main},
+       {FUNC_TYPE_GENERAL,"pkeyparam",pkeyparam_main},
+       {FUNC_TYPE_GENERAL,"pkeyutl",pkeyutl_main},
        {FUNC_TYPE_GENERAL,"spkac",spkac_main},
        {FUNC_TYPE_GENERAL,"smime",smime_main},
        {FUNC_TYPE_GENERAL,"rand",rand_main},
 #ifndef OPENSSL_NO_ENGINE
        {FUNC_TYPE_GENERAL,"engine",engine_main},
 #endif
+#ifndef OPENSSL_NO_OCSP
        {FUNC_TYPE_GENERAL,"ocsp",ocsp_main},
+#endif
        {FUNC_TYPE_GENERAL,"prime",prime_main},
+#if 0 /* ANDROID */
+       {FUNC_TYPE_GENERAL,"ts",ts_main},
+#endif
 #ifndef OPENSSL_NO_MD2
        {FUNC_TYPE_MD,"md2",dgst_main},
 #endif
@@ -189,6 +207,9 @@ FUNCTION functions[] = {
        {FUNC_TYPE_CIPHER,"camellia-256-ecb",enc_main},
 #endif
        {FUNC_TYPE_CIPHER,"base64",enc_main},
+#ifdef ZLIB
+       {FUNC_TYPE_CIPHER,"zlib",enc_main},
+#endif
 #ifndef OPENSSL_NO_DES
        {FUNC_TYPE_CIPHER,"des",enc_main},
 #endif
index 645432c..de6fdea 100644 (file)
@@ -13,12 +13,16 @@ print <<'EOF';
 #define FUNC_TYPE_GENERAL      1
 #define FUNC_TYPE_MD           2
 #define FUNC_TYPE_CIPHER       3
+#define FUNC_TYPE_PKEY         4
+#define FUNC_TYPE_MD_ALG       5
+#define FUNC_TYPE_CIPHER_ALG   6
 
 typedef struct {
        int type;
        const char *name;
        int (*func)(int argc,char *argv[]);
        } FUNCTION;
+DECLARE_LHASH_OF(FUNCTION);
 
 FUNCTION functions[] = {
 EOF
@@ -45,6 +49,8 @@ foreach (@ARGV)
                { print "#if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_SHA1)\n${str}#endif\n"; }
        elsif ( ($_ =~ /^cms$/))
                { print "#ifndef OPENSSL_NO_CMS\n${str}#endif\n"; }
+       elsif ( ($_ =~ /^ocsp$/))
+               { print "#ifndef OPENSSL_NO_OCSP\n${str}#endif\n"; }
        else
                { print $str; }
        }
@@ -62,7 +68,7 @@ foreach (
        "camellia-128-cbc", "camellia-128-ecb",
        "camellia-192-cbc", "camellia-192-ecb",
        "camellia-256-cbc", "camellia-256-ecb",
-       "base64",
+       "base64", "zlib",
        "des", "des3", "desx", "idea", "seed", "rc4", "rc4-40",
        "rc2", "bf", "cast", "rc5",
        "des-ecb", "des-ede",    "des-ede3",
@@ -89,6 +95,7 @@ foreach (
        elsif ($_ =~ /bf/)   { $t="#ifndef OPENSSL_NO_BF\n${t}#endif\n"; }
        elsif ($_ =~ /cast/) { $t="#ifndef OPENSSL_NO_CAST\n${t}#endif\n"; }
        elsif ($_ =~ /rc5/)  { $t="#ifndef OPENSSL_NO_RC5\n${t}#endif\n"; }
+       elsif ($_ =~ /zlib/)  { $t="#ifdef ZLIB\n${t}#endif\n"; }
        print $t;
        }
 
index 9f55cde..820cd18 100644 (file)
@@ -141,39 +141,33 @@ static int add_attribute_object(X509_REQ *req, char *text, const char *def,
                                int n_max, unsigned long chtype);
 static int add_DN_object(X509_NAME *n, char *text, const char *def, char *value,
        int nid,int n_min,int n_max, unsigned long chtype, int mval);
-#ifndef OPENSSL_NO_RSA
-static int MS_CALLBACK req_cb(int p, int n, BN_GENCB *cb);
-#endif
+static int genpkey_cb(EVP_PKEY_CTX *ctx);
 static int req_check_len(int len,int n_min,int n_max);
 static int check_end(const char *str, const char *end);
+static EVP_PKEY_CTX *set_keygen_ctx(BIO *err, const char *gstr, int *pkey_type,
+                                       long *pkeylen, char **palgnam,
+                                       ENGINE *keygen_engine);
 #ifndef MONOLITH
 static char *default_config_file=NULL;
 #endif
 static CONF *req_conf=NULL;
 static int batch=0;
 
-#define TYPE_RSA       1
-#define TYPE_DSA       2
-#define TYPE_DH                3
-#define TYPE_EC                4
-
 int MAIN(int, char **);
 
 int MAIN(int argc, char **argv)
        {
-       ENGINE *e = NULL;
-#ifndef OPENSSL_NO_DSA
-       DSA *dsa_params=NULL;
-#endif
-#ifndef OPENSSL_NO_ECDSA
-       EC_KEY *ec_params = NULL;
-#endif
+       ENGINE *e = NULL, *gen_eng = NULL;
        unsigned long nmflag = 0, reqflag = 0;
        int ex=1,x509=0,days=30;
        X509 *x509ss=NULL;
        X509_REQ *req=NULL;
+       EVP_PKEY_CTX *genctx = NULL;
+       const char *keyalg = NULL;
+       char *keyalgstr = NULL;
+       STACK_OF(OPENSSL_STRING) *pkeyopts = NULL;
        EVP_PKEY *pkey=NULL;
-       int i=0,badops=0,newreq=0,verbose=0,pkey_type=TYPE_RSA;
+       int i=0,badops=0,newreq=0,verbose=0,pkey_type=-1;
        long newkey = -1;
        BIO *in=NULL,*out=NULL;
        int informat,outformat,verify=0,noout=0,text=0,keyform=FORMAT_PEM;
@@ -193,7 +187,7 @@ int MAIN(int argc, char **argv)
        char *p;
        char *subj = NULL;
        int multirdn = 0;
-       const EVP_MD *md_alg=NULL,*digest=EVP_sha1();
+       const EVP_MD *md_alg=NULL,*digest=NULL;
        unsigned long chtype = MBSTRING_ASC;
 #ifndef MONOLITH
        char *to_free;
@@ -236,6 +230,16 @@ int MAIN(int argc, char **argv)
                        if (--argc < 1) goto bad;
                        engine= *(++argv);
                        }
+               else if (strcmp(*argv,"-keygen_engine") == 0)
+                       {
+                       if (--argc < 1) goto bad;
+                       gen_eng = ENGINE_by_id(*(++argv));
+                       if (gen_eng == NULL)
+                               {
+                               BIO_printf(bio_err, "Can't find keygen engine %s\n", *argv);
+                               goto end;
+                               }
+                       }
 #endif
                else if (strcmp(*argv,"-key") == 0)
                        {
@@ -292,126 +296,20 @@ int MAIN(int argc, char **argv)
                        }
                else if (strcmp(*argv,"-newkey") == 0)
                        {
-                       int is_numeric;
-
-                       if (--argc < 1) goto bad;
-                       p= *(++argv);
-                       is_numeric = p[0] >= '0' && p[0] <= '9';
-                       if (strncmp("rsa:",p,4) == 0 || is_numeric)
-                               {
-                               pkey_type=TYPE_RSA;
-                               if(!is_numeric)
-                                   p+=4;
-                               newkey= atoi(p);
-                               }
-                       else
-#ifndef OPENSSL_NO_DSA
-                               if (strncmp("dsa:",p,4) == 0)
-                               {
-                               X509 *xtmp=NULL;
-                               EVP_PKEY *dtmp;
-
-                               pkey_type=TYPE_DSA;
-                               p+=4;
-                               if ((in=BIO_new_file(p,"r")) == NULL)
-                                       {
-                                       perror(p);
-                                       goto end;
-                                       }
-                               if ((dsa_params=PEM_read_bio_DSAparams(in,NULL,NULL,NULL)) == NULL)
-                                       {
-                                       ERR_clear_error();
-                                       (void)BIO_reset(in);
-                                       if ((xtmp=PEM_read_bio_X509(in,NULL,NULL,NULL)) == NULL)
-                                               {
-                                               BIO_printf(bio_err,"unable to load DSA parameters from file\n");
-                                               goto end;
-                                               }
-
-                                       if ((dtmp=X509_get_pubkey(xtmp)) == NULL) goto end;
-                                       if (dtmp->type == EVP_PKEY_DSA)
-                                               dsa_params=DSAparams_dup(dtmp->pkey.dsa);
-                                       EVP_PKEY_free(dtmp);
-                                       X509_free(xtmp);
-                                       if (dsa_params == NULL)
-                                               {
-                                               BIO_printf(bio_err,"Certificate does not contain DSA parameters\n");
-                                               goto end;
-                                               }
-                                       }
-                               BIO_free(in);
-                               in=NULL;
-                               newkey=BN_num_bits(dsa_params->p);
-                               }
-                       else 
-#endif
-#ifndef OPENSSL_NO_ECDSA
-                               if (strncmp("ec:",p,3) == 0)
-                               {
-                               X509 *xtmp=NULL;
-                               EVP_PKEY *dtmp;
-                               EC_GROUP *group;
-
-                               pkey_type=TYPE_EC;
-                               p+=3;
-                               if ((in=BIO_new_file(p,"r")) == NULL)
-                                       {
-                                       perror(p);
-                                       goto end;
-                                       }
-                               if ((ec_params = EC_KEY_new()) == NULL)
-                                       goto end;
-                               group = PEM_read_bio_ECPKParameters(in, NULL, NULL, NULL);
-                               if (group == NULL)
-                                       {
-                                       EC_KEY_free(ec_params);
-                                       ERR_clear_error();
-                                       (void)BIO_reset(in);
-                                       if ((xtmp=PEM_read_bio_X509(in,NULL,NULL,NULL)) == NULL)
-                                               {       
-                                               BIO_printf(bio_err,"unable to load EC parameters from file\n");
-                                               goto end;
-                                               }
-
-                                       if ((dtmp=X509_get_pubkey(xtmp))==NULL)
-                                               goto end;
-                                       if (dtmp->type == EVP_PKEY_EC)
-                                               ec_params = EC_KEY_dup(dtmp->pkey.ec);
-                                       EVP_PKEY_free(dtmp);
-                                       X509_free(xtmp);
-                                       if (ec_params == NULL)
-                                               {
-                                               BIO_printf(bio_err,"Certificate does not contain EC parameters\n");
-                                               goto end;
-                                               }
-                                       }
-                               else
-                                       {
-                                       if (EC_KEY_set_group(ec_params, group) == 0)
-                                               goto end;
-                                       EC_GROUP_free(group);
-                                       }
-
-                               BIO_free(in);
-                               in=NULL;
-                               newkey = EC_GROUP_get_degree(EC_KEY_get0_group(ec_params));
-                               }
-                       else
-#endif
-#ifndef OPENSSL_NO_DH
-                               if (strncmp("dh:",p,4) == 0)
-                               {
-                               pkey_type=TYPE_DH;
-                               p+=3;
-                               }
-                       else
-#endif
-                               {
+                       if (--argc < 1)
                                goto bad;
-                               }
-
+                       keyalg = *(++argv);
                        newreq=1;
                        }
+               else if (strcmp(*argv,"-pkeyopt") == 0)
+                       {
+                       if (--argc < 1)
+                               goto bad;
+                       if (!pkeyopts)
+                               pkeyopts = sk_OPENSSL_STRING_new_null();
+                       if (!pkeyopts || !sk_OPENSSL_STRING_push(pkeyopts, *(++argv)))
+                               goto bad;
+                       }
                else if (strcmp(*argv,"-batch") == 0)
                        batch=1;
                else if (strcmp(*argv,"-newhdr") == 0)
@@ -467,11 +365,6 @@ int MAIN(int argc, char **argv)
                        serial = s2i_ASN1_INTEGER(NULL, *(++argv));
                        if (!serial) goto bad;
                        }
-               else if ((md_alg=EVP_get_digestbyname(&((*argv)[1]))) != NULL)
-                       {
-                       /* ok */
-                       digest=md_alg;
-                       }
                else if (strcmp(*argv,"-extensions") == 0)
                        {
                        if (--argc < 1) goto bad;
@@ -482,6 +375,11 @@ int MAIN(int argc, char **argv)
                        if (--argc < 1) goto bad;
                        req_exts = *(++argv);
                        }
+               else if ((md_alg=EVP_get_digestbyname(&((*argv)[1]))) != NULL)
+                       {
+                       /* ok */
+                       digest=md_alg;
+                       }
                else
                        {
                        BIO_printf(bio_err,"unknown option %s\n",*argv);
@@ -730,15 +628,20 @@ bad:
 
        if (newreq && (pkey == NULL))
                {
-#ifndef OPENSSL_NO_RSA
-               BN_GENCB cb;
-#endif
                char *randfile = NCONF_get_string(req_conf,SECTION,"RANDFILE");
                if (randfile == NULL)
                        ERR_clear_error();
                app_RAND_load_file(randfile, bio_err, 0);
                if (inrand)
                        app_RAND_load_files(inrand);
+
+               if (keyalg)
+                       {
+                       genctx = set_keygen_ctx(bio_err, keyalg, &pkey_type, &newkey,
+                                                       &keyalgstr, gen_eng);
+                       if (!genctx)
+                               goto end;
+                       }
        
                if (newkey <= 0)
                        {
@@ -746,57 +649,54 @@ bad:
                                newkey=DEFAULT_KEY_LENGTH;
                        }
 
-               if (newkey < MIN_KEY_LENGTH && (pkey_type == TYPE_RSA || pkey_type == TYPE_DSA))
+               if (newkey < MIN_KEY_LENGTH && (pkey_type == EVP_PKEY_RSA || pkey_type == EVP_PKEY_DSA))
                        {
                        BIO_printf(bio_err,"private key length is too short,\n");
                        BIO_printf(bio_err,"it needs to be at least %d bits, not %ld\n",MIN_KEY_LENGTH,newkey);
                        goto end;
                        }
-               BIO_printf(bio_err,"Generating a %ld bit %s private key\n",
-                       newkey,(pkey_type == TYPE_RSA)?"RSA":
-                       (pkey_type == TYPE_DSA)?"DSA":"EC");
-
-               if ((pkey=EVP_PKEY_new()) == NULL) goto end;
 
-#ifndef OPENSSL_NO_RSA
-               BN_GENCB_set(&cb, req_cb, bio_err);
-               if (pkey_type == TYPE_RSA)
-                       {
-                       RSA *rsa = RSA_new();
-                       BIGNUM *bn = BN_new();
-                       if(!bn || !rsa || !BN_set_word(bn, 0x10001) ||
-                                       !RSA_generate_key_ex(rsa, newkey, bn, &cb) ||
-                                       !EVP_PKEY_assign_RSA(pkey, rsa))
-                               {
-                               if(bn) BN_free(bn);
-                               if(rsa) RSA_free(rsa);
+               if (!genctx)
+                       {
+                       genctx = set_keygen_ctx(bio_err, NULL, &pkey_type, &newkey,
+                                                       &keyalgstr, gen_eng);
+                       if (!genctx)
                                goto end;
-                               }
-                       BN_free(bn);
                        }
-               else
-#endif
-#ifndef OPENSSL_NO_DSA
-                       if (pkey_type == TYPE_DSA)
+
+               if (pkeyopts)
                        {
-                       if (!DSA_generate_key(dsa_params)) goto end;
-                       if (!EVP_PKEY_assign_DSA(pkey,dsa_params)) goto end;
-                       dsa_params=NULL;
+                       char *genopt;
+                       for (i = 0; i < sk_OPENSSL_STRING_num(pkeyopts); i++)
+                               {
+                               genopt = sk_OPENSSL_STRING_value(pkeyopts, i);
+                               if (pkey_ctrl_string(genctx, genopt) <= 0)
+                                       {
+                                       BIO_printf(bio_err,
+                                               "parameter error \"%s\"\n",
+                                               genopt);
+                                       ERR_print_errors(bio_err);
+                                       goto end;
+                                       }
+                               }
                        }
-#endif
-#ifndef OPENSSL_NO_ECDSA
-                       if (pkey_type == TYPE_EC)
+
+               BIO_printf(bio_err,"Generating a %ld bit %s private key\n",
+                               newkey, keyalgstr);
+
+               EVP_PKEY_CTX_set_cb(genctx, genpkey_cb);
+               EVP_PKEY_CTX_set_app_data(genctx, bio_err);
+
+               if (EVP_PKEY_keygen(genctx, &pkey) <= 0)
                        {
-                       if (!EC_KEY_generate_key(ec_params)) goto end;
-                       if (!EVP_PKEY_assign_EC_KEY(pkey, ec_params)) 
-                               goto end;
-                       ec_params = NULL;
+                       BIO_puts(bio_err, "Error Generating Key\n");
+                       goto end;
                        }
-#endif
 
-               app_RAND_write_file(randfile, bio_err);
+               EVP_PKEY_CTX_free(genctx);
+               genctx = NULL;
 
-               if (pkey == NULL) goto end;
+               app_RAND_write_file(randfile, bio_err);
 
                if (keyout == NULL)
                        {
@@ -895,14 +795,7 @@ loop:
                        BIO_printf(bio_err,"you need to specify a private key\n");
                        goto end;
                        }
-#ifndef OPENSSL_NO_DSA
-               if (pkey->type == EVP_PKEY_DSA)
-                       digest=EVP_dss1();
-#endif
-#ifndef OPENSSL_NO_ECDSA
-               if (pkey->type == EVP_PKEY_EC)
-                       digest=EVP_ecdsa();
-#endif
+
                if (req == NULL)
                        {
                        req=X509_REQ_new();
@@ -945,7 +838,7 @@ loop:
 
                        if (!X509_set_issuer_name(x509ss, X509_REQ_get_subject_name(req))) goto end;
                        if (!X509_gmtime_adj(X509_get_notBefore(x509ss),0)) goto end;
-                       if (!X509_gmtime_adj(X509_get_notAfter(x509ss), (long)60*60*24*days)) goto end;
+                       if (!X509_time_adj_ex(X509_get_notAfter(x509ss), days, 0, NULL)) goto end;
                        if (!X509_set_subject_name(x509ss, X509_REQ_get_subject_name(req))) goto end;
                        tmppkey = X509_REQ_get_pubkey(req);
                        if (!tmppkey || !X509_set_pubkey(x509ss,tmppkey)) goto end;
@@ -967,7 +860,10 @@ loop:
                                }
                        
                        if (!(i=X509_sign(x509ss,pkey,digest)))
+                               {
+                               ERR_print_errors(bio_err);
                                goto end;
+                               }
                        }
                else
                        {
@@ -988,7 +884,10 @@ loop:
                                goto end;
                                }
                        if (!(i=X509_REQ_sign(req,pkey,digest)))
+                               {
+                               ERR_print_errors(bio_err);
                                goto end;
+                               }
                        }
                }
 
@@ -1125,7 +1024,7 @@ loop:
                        }
                fprintf(stdout,"Modulus=");
 #ifndef OPENSSL_NO_RSA
-               if (tpubkey->type == EVP_PKEY_RSA)
+               if (EVP_PKEY_base_id(tpubkey) == EVP_PKEY_RSA)
                        BN_print(out,tpubkey->pkey.rsa->n);
                else
 #endif
@@ -1181,18 +1080,22 @@ end:
        BIO_free(in);
        BIO_free_all(out);
        EVP_PKEY_free(pkey);
+       if (genctx)
+               EVP_PKEY_CTX_free(genctx);
+       if (pkeyopts)
+               sk_OPENSSL_STRING_free(pkeyopts);
+#ifndef OPENSSL_NO_ENGINE
+       if (gen_eng)
+               ENGINE_free(gen_eng);
+#endif
+       if (keyalgstr)
+               OPENSSL_free(keyalgstr);
        X509_REQ_free(req);
        X509_free(x509ss);
        ASN1_INTEGER_free(serial);
        if(passargin && passin) OPENSSL_free(passin);
        if(passargout && passout) OPENSSL_free(passout);
        OBJ_cleanup();
-#ifndef OPENSSL_NO_DSA
-       if (dsa_params != NULL) DSA_free(dsa_params);
-#endif
-#ifndef OPENSSL_NO_ECDSA
-       if (ec_params != NULL) EC_KEY_free(ec_params);
-#endif
        apps_shutdown();
        OPENSSL_EXIT(ex);
        }
@@ -1647,24 +1550,6 @@ err:
        return(0);
        }
 
-#ifndef OPENSSL_NO_RSA
-static int MS_CALLBACK req_cb(int p, int n, BN_GENCB *cb)
-       {
-       char c='*';
-
-       if (p == 0) c='.';
-       if (p == 1) c='+';
-       if (p == 2) c='*';
-       if (p == 3) c='\n';
-       BIO_write(cb->arg,&c,1);
-       (void)BIO_flush(cb->arg);
-#ifdef LINT
-       p=n;
-#endif
-       return 1;
-       }
-#endif
-
 static int req_check_len(int len, int n_min, int n_max)
        {
        if ((n_min > 0) && (len < n_min))
@@ -1691,3 +1576,183 @@ static int check_end(const char *str, const char *end)
        tmp = str + slen - elen;
        return strcmp(tmp, end);
 }
+
+static EVP_PKEY_CTX *set_keygen_ctx(BIO *err, const char *gstr, int *pkey_type,
+                                       long *pkeylen, char **palgnam,
+                                       ENGINE *keygen_engine)
+       {
+       EVP_PKEY_CTX *gctx = NULL;
+       EVP_PKEY *param = NULL;
+       long keylen = -1;
+       BIO *pbio = NULL;
+       const char *paramfile = NULL;
+
+       if (gstr == NULL)
+               {
+               *pkey_type = EVP_PKEY_RSA;
+               keylen = *pkeylen;
+               }
+       else if (gstr[0] >= '0' && gstr[0] <= '9')
+               {
+               *pkey_type = EVP_PKEY_RSA;
+               keylen = atol(gstr);
+               *pkeylen = keylen;
+               }
+       else if (!strncmp(gstr, "param:", 6))
+               paramfile = gstr + 6;
+       else
+               {
+               const char *p = strchr(gstr, ':');
+               int len;
+               ENGINE *tmpeng;
+               const EVP_PKEY_ASN1_METHOD *ameth;
+
+               if (p)
+                       len = p - gstr;
+               else
+                       len = strlen(gstr);
+               /* The lookup of a the string will cover all engines so
+                * keep a note of the implementation.
+                */
+
+               ameth = EVP_PKEY_asn1_find_str(&tmpeng, gstr, len);
+
+               if (!ameth)
+                       {
+                       BIO_printf(err, "Unknown algorithm %.*s\n", len, gstr);
+                       return NULL;
+                       }
+
+               EVP_PKEY_asn1_get0_info(NULL, pkey_type, NULL, NULL, NULL,
+                                                                       ameth);
+#ifndef OPENSSL_NO_ENGINE
+               if (tmpeng)
+                       ENGINE_finish(tmpeng);
+#endif
+               if (*pkey_type == EVP_PKEY_RSA)
+                       {
+                       if (p)
+                               {
+                               keylen = atol(p + 1);
+                               *pkeylen = keylen;
+                               }
+                       }
+               else if (p)
+                       paramfile = p + 1;
+               }
+
+       if (paramfile)
+               {
+               pbio = BIO_new_file(paramfile, "r");
+               if (!pbio)
+                       {
+                       BIO_printf(err, "Can't open parameter file %s\n",
+                                       paramfile);
+                       return NULL;
+                       }
+               param = PEM_read_bio_Parameters(pbio, NULL);
+
+               if (!param)
+                       {
+                       X509 *x;
+                       (void)BIO_reset(pbio);
+                       x = PEM_read_bio_X509(pbio, NULL, NULL, NULL);
+                       if (x)
+                               {
+                               param = X509_get_pubkey(x);
+                               X509_free(x);
+                               }
+                       }
+
+               BIO_free(pbio);
+
+               if (!param)
+                       {
+                       BIO_printf(err, "Error reading parameter file %s\n",
+                                       paramfile);
+                       return NULL;
+                       }
+               if (*pkey_type == -1)
+                       *pkey_type = EVP_PKEY_id(param);
+               else if (*pkey_type != EVP_PKEY_base_id(param))
+                       {
+                       BIO_printf(err, "Key Type does not match parameters\n");
+                       EVP_PKEY_free(param);
+                       return NULL;
+                       }
+               }
+
+       if (palgnam)
+               {
+               const EVP_PKEY_ASN1_METHOD *ameth;
+               ENGINE *tmpeng;
+               const char *anam;
+               ameth = EVP_PKEY_asn1_find(&tmpeng, *pkey_type);
+               if (!ameth)
+                       {
+                       BIO_puts(err, "Internal error: can't find key algorithm\n");
+                       return NULL;
+                       }
+               EVP_PKEY_asn1_get0_info(NULL, NULL, NULL, NULL, &anam, ameth);
+               *palgnam = BUF_strdup(anam);
+#ifndef OPENSSL_NO_ENGINE
+               if (tmpeng)
+                       ENGINE_finish(tmpeng);
+#endif
+               }
+
+       if (param)
+               {
+               gctx = EVP_PKEY_CTX_new(param, keygen_engine);
+               *pkeylen = EVP_PKEY_bits(param);
+               EVP_PKEY_free(param);
+               }
+       else
+               gctx = EVP_PKEY_CTX_new_id(*pkey_type, keygen_engine);
+
+       if (!gctx)
+               {
+               BIO_puts(err, "Error allocating keygen context\n");
+               ERR_print_errors(err);
+               return NULL;
+               }
+
+       if (EVP_PKEY_keygen_init(gctx) <= 0)
+               {
+               BIO_puts(err, "Error initializing keygen context\n");
+               ERR_print_errors(err);
+               return NULL;
+               }
+#ifndef OPENSSL_NO_RSA
+       if ((*pkey_type == EVP_PKEY_RSA) && (keylen != -1))
+               {
+               if (EVP_PKEY_CTX_set_rsa_keygen_bits(gctx, keylen) <= 0)
+                       {
+                       BIO_puts(err, "Error setting RSA keysize\n");
+                       ERR_print_errors(err);
+                       EVP_PKEY_CTX_free(gctx);
+                       return NULL;
+                       }
+               }
+#endif
+
+       return gctx;
+       }
+
+static int genpkey_cb(EVP_PKEY_CTX *ctx)
+       {
+       char c='*';
+       BIO *b = EVP_PKEY_CTX_get_app_data(ctx);
+       int p;
+       p = EVP_PKEY_CTX_get_keygen_info(ctx, 0);
+       if (p == 0) c='.';
+       if (p == 1) c='+';
+       if (p == 2) c='*';
+       if (p == 3) c='\n';
+       BIO_write(b,&c,1);
+       (void)BIO_flush(b);
+#ifdef LINT
+       p=n;
+#endif
+       return 1;
+       }
index 930f1f0..a17708f 100644 (file)
@@ -115,6 +115,8 @@ int MAIN(int argc, char **argv)
 #endif
        int modulus=0;
 
+       int pvk_encr = 2;
+
        apps_startup();
 
        if (bio_err == NULL)
@@ -177,6 +179,16 @@ int MAIN(int argc, char **argv)
                        pubin=1;
                else if (strcmp(*argv,"-pubout") == 0)
                        pubout=1;
+               else if (strcmp(*argv,"-RSAPublicKey_in") == 0)
+                       pubin = 2;
+               else if (strcmp(*argv,"-RSAPublicKey_out") == 0)
+                       pubout = 2;
+               else if (strcmp(*argv,"-pvk-strong") == 0)
+                       pvk_encr=2;
+               else if (strcmp(*argv,"-pvk-weak") == 0)
+                       pvk_encr=1;
+               else if (strcmp(*argv,"-pvk-none") == 0)
+                       pvk_encr=0;
                else if (strcmp(*argv,"-noout") == 0)
                        noout=1;
                else if (strcmp(*argv,"-text") == 0)
@@ -257,10 +269,23 @@ bad:
                EVP_PKEY        *pkey;
 
                if (pubin)
-                       pkey = load_pubkey(bio_err, infile,
-                               (informat == FORMAT_NETSCAPE && sgckey ?
-                                       FORMAT_IISSGC : informat), 1,
+                       {
+                       int tmpformat=-1;
+                       if (pubin == 2)
+                               {
+                               if (informat == FORMAT_PEM)
+                                       tmpformat = FORMAT_PEMRSA;
+                               else if (informat == FORMAT_ASN1)
+                                       tmpformat = FORMAT_ASN1RSA;
+                               }
+                       else if (informat == FORMAT_NETSCAPE && sgckey)
+                               tmpformat = FORMAT_IISSGC;
+                       else
+                               tmpformat = informat;
+                                       
+                       pkey = load_pubkey(bio_err, infile, tmpformat, 1,
                                passin, e, "Public Key");
+                       }
                else
                        pkey = load_key(bio_err, infile,
                                (informat == FORMAT_NETSCAPE && sgckey ?
@@ -268,7 +293,7 @@ bad:
                                passin, e, "Private Key");
 
                if (pkey != NULL)
-               rsa = pkey == NULL ? NULL : EVP_PKEY_get1_RSA(pkey);
+                       rsa = EVP_PKEY_get1_RSA(pkey);
                EVP_PKEY_free(pkey);
        }
 
@@ -346,7 +371,13 @@ bad:
                }
        BIO_printf(bio_err,"writing RSA key\n");
        if      (outformat == FORMAT_ASN1) {
-               if(pubout || pubin) i=i2d_RSA_PUBKEY_bio(out,rsa);
+               if(pubout || pubin) 
+                       {
+                       if (pubout == 2)
+                               i=i2d_RSAPublicKey_bio(out,rsa);
+                       else
+                               i=i2d_RSA_PUBKEY_bio(out,rsa);
+                       }
                else i=i2d_RSAPrivateKey_bio(out,rsa);
        }
 #ifndef OPENSSL_NO_RC4
@@ -370,14 +401,32 @@ bad:
 #endif
        else if (outformat == FORMAT_PEM) {
                if(pubout || pubin)
-                   i=PEM_write_bio_RSA_PUBKEY(out,rsa);
+                       {
+                       if (pubout == 2)
+                               i=PEM_write_bio_RSAPublicKey(out,rsa);
+                       else
+                               i=PEM_write_bio_RSA_PUBKEY(out,rsa);
+                       }
                else i=PEM_write_bio_RSAPrivateKey(out,rsa,
                                                enc,NULL,0,NULL,passout);
+#if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_RC4)
+       } else if (outformat == FORMAT_MSBLOB || outformat == FORMAT_PVK) {
+               EVP_PKEY *pk;
+               pk = EVP_PKEY_new();
+               EVP_PKEY_set1_RSA(pk, rsa);
+               if (outformat == FORMAT_PVK)
+                       i = i2b_PVK_bio(out, pk, pvk_encr, 0, passout);
+               else if (pubin || pubout)
+                       i = i2b_PublicKey_bio(out, pk);
+               else
+                       i = i2b_PrivateKey_bio(out, pk);
+               EVP_PKEY_free(pk);
+#endif
        } else  {
                BIO_printf(bio_err,"bad output format specified for outfile\n");
                goto end;
                }
-       if (!i)
+       if (i <= 0)
                {
                BIO_printf(bio_err,"unable to write key\n");
                ERR_print_errors(bio_err);
index 923e2b6..b01f004 100644 (file)
@@ -342,4 +342,10 @@ static void usage()
 
 }
 
+#else /* !OPENSSL_NO_RSA */
+
+# if PEDANTIC
+static void *dummy=&dummy;
+# endif
+
 #endif
index 513bcfe..820e5c5 100644 (file)
 #include <conio.h>
 #endif
 
-#ifdef OPENSSL_SYS_MSDOS
+#if defined(OPENSSL_SYS_MSDOS) && !defined(_WIN32)
 #define _kbhit kbhit
 #endif
 
@@ -162,7 +162,7 @@ int extract_port(char *str, short *port_ptr);
 int extract_host_port(char *str,char **host_ptr,unsigned char *ip,short *p);
 
 long MS_CALLBACK bio_dump_callback(BIO *bio, int cmd, const char *argp,
-       int argi, long argl, long ret);
+                                  int argi, long argl, long ret);
 
 #ifdef HEADER_SSL_H
 void MS_CALLBACK apps_ssl_info_callback(const SSL *s, int where, int ret);
@@ -174,5 +174,3 @@ void MS_CALLBACK tlsext_cb(SSL *s, int client_server, int type,
 
 int MS_CALLBACK generate_cookie_callback(SSL *ssl, unsigned char *cookie, unsigned int *cookie_len);
 int MS_CALLBACK verify_cookie_callback(SSL *ssl, unsigned char *cookie, unsigned int cookie_len);
-
-unsigned char *next_protos_parse(unsigned short *outlen, const char *in);
index 97caffc..c4f5512 100644 (file)
@@ -56,7 +56,7 @@
  * [including the GNU Public Licence.]
  */
 /* ====================================================================
- * Copyright (c) 1998-2001 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 int verify_depth=0;
 int verify_error=X509_V_OK;
+int verify_return_error=0;
 unsigned char cookie_secret[COOKIE_SECRET_LENGTH];
 int cookie_initialized=0;
 
 int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx)
        {
-       char buf[256];
        X509 *err_cert;
        int err,depth;
 
@@ -139,15 +139,23 @@ int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx)
        err=    X509_STORE_CTX_get_error(ctx);
        depth=  X509_STORE_CTX_get_error_depth(ctx);
 
-       X509_NAME_oneline(X509_get_subject_name(err_cert),buf,sizeof buf);
-       BIO_printf(bio_err,"depth=%d %s\n",depth,buf);
+       BIO_printf(bio_err,"depth=%d ",depth);
+       if (err_cert)
+               {
+               X509_NAME_print_ex(bio_err, X509_get_subject_name(err_cert),
+                                       0, XN_FLAG_ONELINE);
+               BIO_puts(bio_err, "\n");
+               }
+       else
+               BIO_puts(bio_err, "<no cert>\n");
        if (!ok)
                {
                BIO_printf(bio_err,"verify error:num=%d:%s\n",err,
                        X509_verify_cert_error_string(err));
                if (verify_depth >= depth)
                        {
-                       ok=1;
+                       if (!verify_return_error)
+                               ok=1;
                        verify_error=X509_V_OK;
                        }
                else
@@ -156,25 +164,33 @@ int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx)
                        verify_error=X509_V_ERR_CERT_CHAIN_TOO_LONG;
                        }
                }
-       switch (ctx->error)
+       switch (err)
                {
        case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
-               X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert),buf,sizeof buf);
-               BIO_printf(bio_err,"issuer= %s\n",buf);
+               BIO_puts(bio_err,"issuer= ");
+               X509_NAME_print_ex(bio_err, X509_get_issuer_name(err_cert),
+                                       0, XN_FLAG_ONELINE);
+               BIO_puts(bio_err, "\n");
                break;
        case X509_V_ERR_CERT_NOT_YET_VALID:
        case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
                BIO_printf(bio_err,"notBefore=");
-               ASN1_TIME_print(bio_err,X509_get_notBefore(ctx->current_cert));
+               ASN1_TIME_print(bio_err,X509_get_notBefore(err_cert));
                BIO_printf(bio_err,"\n");
                break;
        case X509_V_ERR_CERT_HAS_EXPIRED:
        case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
                BIO_printf(bio_err,"notAfter=");
-               ASN1_TIME_print(bio_err,X509_get_notAfter(ctx->current_cert));
+               ASN1_TIME_print(bio_err,X509_get_notAfter(err_cert));
                BIO_printf(bio_err,"\n");
                break;
+       case X509_V_ERR_NO_EXPLICIT_POLICY:
+               policies_print(bio_err, ctx);
+               break;
                }
+       if (err == X509_V_OK && ok == 2)
+               policies_print(bio_err, ctx);
+
        BIO_printf(bio_err,"verify return:%d\n",ok);
        return(ok);
        }
@@ -263,7 +279,7 @@ int set_cert_key_stuff(SSL_CTX *ctx, X509 *cert, EVP_PKEY *key)
        }
 
 long MS_CALLBACK bio_dump_callback(BIO *bio, int cmd, const char *argp,
-       int argi, long argl, long ret)
+                                  int argi, long argl, long ret)
        {
        BIO *out;
 
@@ -272,15 +288,15 @@ long MS_CALLBACK bio_dump_callback(BIO *bio, int cmd, const char *argp,
 
        if (cmd == (BIO_CB_READ|BIO_CB_RETURN))
                {
-               BIO_printf(out,"read from %p [%p] (%d bytes => %ld (0x%lX))\n",
-                       (void *)bio,argp,argi,ret,ret);
+               BIO_printf(out,"read from %p [%p] (%lu bytes => %ld (0x%lX))\n",
+                       (void *)bio,argp,(unsigned long)argi,ret,ret);
                BIO_dump(out,argp,(int)ret);
                return(ret);
                }
        else if (cmd == (BIO_CB_WRITE|BIO_CB_RETURN))
                {
-               BIO_printf(out,"write to %p [%p] (%d bytes => %ld (0x%lX))\n",
-                       (void *)bio,argp,argi,ret,ret);
+               BIO_printf(out,"write to %p [%p] (%lu bytes => %ld (0x%lX))\n",
+                       (void *)bio,argp,(unsigned long)argi,ret,ret);
                BIO_dump(out,argp,(int)ret);
                }
        return(ret);
@@ -341,14 +357,14 @@ void MS_CALLBACK msg_cb(int write_p, int version, int content_type, const void *
        case TLS1_VERSION:
                str_version = "TLS 1.0 ";
                break;
-       default:
-               str_version = "???";
        case DTLS1_VERSION:
                str_version = "DTLS 1.0 ";
                break;
        case DTLS1_BAD_VER:
                str_version = "DTLS 1.0 (bad) ";
                break;
+       default:
+               str_version = "???";
                }
 
        if (version == SSL2_VERSION)
@@ -518,6 +534,21 @@ void MS_CALLBACK msg_cb(int write_p, int version, int content_type, const void *
                                case 100:
                                        str_details2 = " no_renegotiation";
                                        break;
+                               case 110:
+                                       str_details2 = " unsupported_extension";
+                                       break;
+                               case 111:
+                                       str_details2 = " certificate_unobtainable";
+                                       break;
+                               case 112:
+                                       str_details2 = " unrecognized_name";
+                                       break;
+                               case 113:
+                                       str_details2 = " bad_certificate_status_response";
+                                       break;
+                               case 114:
+                                       str_details2 = " bad_certificate_hash_value";
+                                       break;
                                        }
                                }
                        }
@@ -539,6 +570,9 @@ void MS_CALLBACK msg_cb(int write_p, int version, int content_type, const void *
                                case 2:
                                        str_details1 = ", ServerHello";
                                        break;
+                               case 3:
+                                       str_details1 = ", HelloVerifyRequest";
+                                       break;
                                case 11:
                                        str_details1 = ", Certificate";
                                        break;
@@ -554,9 +588,6 @@ void MS_CALLBACK msg_cb(int write_p, int version, int content_type, const void *
                                case 15:
                                        str_details1 = ", CertificateVerify";
                                        break;
-                               case 3:
-                                       str_details1 = ", HelloVerifyRequest";
-                                       break;
                                case 16:
                                        str_details1 = ", ClientKeyExchange";
                                        break;
@@ -642,6 +673,12 @@ void MS_CALLBACK tlsext_cb(SSL *s, int client_server, int type,
                extname = "renegotiate";
                break;
 
+#ifdef TLSEXT_TYPE_opaque_prf_input
+               case TLSEXT_TYPE_opaque_prf_input:
+               extname = "opaque PRF input";
+               break;
+#endif
+
                default:
                extname = "unknown";
                break;
@@ -659,8 +696,14 @@ int MS_CALLBACK generate_cookie_callback(SSL *ssl, unsigned char *cookie, unsign
        {
        unsigned char *buffer, result[EVP_MAX_MD_SIZE];
        unsigned int length, resultlength;
-       struct sockaddr_in peer;
-       
+       union {
+               struct sockaddr sa;
+               struct sockaddr_in s4;
+#if OPENSSL_USE_IPV6
+               struct sockaddr_in6 s6;
+#endif
+       } peer;
+
        /* Initialize a random secret */
        if (!cookie_initialized)
                {
@@ -676,8 +719,23 @@ int MS_CALLBACK generate_cookie_callback(SSL *ssl, unsigned char *cookie, unsign
        (void)BIO_dgram_get_peer(SSL_get_rbio(ssl), &peer);
 
        /* Create buffer with peer's address and port */
-       length = sizeof(peer.sin_addr);
-       length += sizeof(peer.sin_port);
+       length = 0;
+       switch (peer.sa.sa_family)
+               {
+       case AF_INET:
+               length += sizeof(struct in_addr);
+               length += sizeof(peer.s4.sin_port);
+               break;
+#if OPENSSL_USE_IPV6
+       case AF_INET6:
+               length += sizeof(struct in6_addr);
+               length += sizeof(peer.s6.sin6_port);
+               break;
+#endif
+       default:
+               OPENSSL_assert(0);
+               break;
+               }
        buffer = OPENSSL_malloc(length);
 
        if (buffer == NULL)
@@ -685,9 +743,31 @@ int MS_CALLBACK generate_cookie_callback(SSL *ssl, unsigned char *cookie, unsign
                BIO_printf(bio_err,"out of memory\n");
                return 0;
                }
-       
-       memcpy(buffer, &peer.sin_addr, sizeof(peer.sin_addr));
-       memcpy(buffer + sizeof(peer.sin_addr), &peer.sin_port, sizeof(peer.sin_port));
+
+       switch (peer.sa.sa_family)
+               {
+       case AF_INET:
+               memcpy(buffer,
+                      &peer.s4.sin_port,
+                      sizeof(peer.s4.sin_port));
+               memcpy(buffer + sizeof(peer.s4.sin_port),
+                      &peer.s4.sin_addr,
+                      sizeof(struct in_addr));
+               break;
+#if OPENSSL_USE_IPV6
+       case AF_INET6:
+               memcpy(buffer,
+                      &peer.s6.sin6_port,
+                      sizeof(peer.s6.sin6_port));
+               memcpy(buffer + sizeof(peer.s6.sin6_port),
+                      &peer.s6.sin6_addr,
+                      sizeof(struct in6_addr));
+               break;
+#endif
+       default:
+               OPENSSL_assert(0);
+               break;
+               }
 
        /* Calculate HMAC of buffer using the secret */
        HMAC(EVP_sha1(), cookie_secret, COOKIE_SECRET_LENGTH,
@@ -704,8 +784,14 @@ int MS_CALLBACK verify_cookie_callback(SSL *ssl, unsigned char *cookie, unsigned
        {
        unsigned char *buffer, result[EVP_MAX_MD_SIZE];
        unsigned int length, resultlength;
-       struct sockaddr_in peer;
-       
+       union {
+               struct sockaddr sa;
+               struct sockaddr_in s4;
+#if OPENSSL_USE_IPV6
+               struct sockaddr_in6 s6;
+#endif
+       } peer;
+
        /* If secret isn't initialized yet, the cookie can't be valid */
        if (!cookie_initialized)
                return 0;
@@ -714,24 +800,61 @@ int MS_CALLBACK verify_cookie_callback(SSL *ssl, unsigned char *cookie, unsigned
        (void)BIO_dgram_get_peer(SSL_get_rbio(ssl), &peer);
 
        /* Create buffer with peer's address and port */
-       length = sizeof(peer.sin_addr);
-       length += sizeof(peer.sin_port);
-       buffer = (unsigned char*) OPENSSL_malloc(length);
+       length = 0;
+       switch (peer.sa.sa_family)
+               {
+       case AF_INET:
+               length += sizeof(struct in_addr);
+               length += sizeof(peer.s4.sin_port);
+               break;
+#if OPENSSL_USE_IPV6
+       case AF_INET6:
+               length += sizeof(struct in6_addr);
+               length += sizeof(peer.s6.sin6_port);
+               break;
+#endif
+       default:
+               OPENSSL_assert(0);
+               break;
+               }
+       buffer = OPENSSL_malloc(length);
        
        if (buffer == NULL)
                {
                BIO_printf(bio_err,"out of memory\n");
                return 0;
                }
-       
-       memcpy(buffer, &peer.sin_addr, sizeof(peer.sin_addr));
-       memcpy(buffer + sizeof(peer.sin_addr), &peer.sin_port, sizeof(peer.sin_port));
+
+       switch (peer.sa.sa_family)
+               {
+       case AF_INET:
+               memcpy(buffer,
+                      &peer.s4.sin_port,
+                      sizeof(peer.s4.sin_port));
+               memcpy(buffer + sizeof(peer.s4.sin_port),
+                      &peer.s4.sin_addr,
+                      sizeof(struct in_addr));
+               break;
+#if OPENSSL_USE_IPV6
+       case AF_INET6:
+               memcpy(buffer,
+                      &peer.s6.sin6_port,
+                      sizeof(peer.s6.sin6_port));
+               memcpy(buffer + sizeof(peer.s6.sin6_port),
+                      &peer.s6.sin6_addr,
+                      sizeof(struct in6_addr));
+               break;
+#endif
+       default:
+               OPENSSL_assert(0);
+               break;
+               }
 
        /* Calculate HMAC of buffer using the secret */
        HMAC(EVP_sha1(), cookie_secret, COOKIE_SECRET_LENGTH,
             buffer, length, result, &resultlength);
        OPENSSL_free(buffer);
-       
+
        if (cookie_len == resultlength && memcmp(result, cookie, resultlength) == 0)
                return 1;
 
index 6033e77..b951513 100644 (file)
@@ -56,7 +56,7 @@
  * [including the GNU Public Licence.]
  */
 /* ====================================================================
- * Copyright (c) 1998-2001 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * Hudson (tjh@cryptsoft.com).
  *
  */
+/* ====================================================================
+ * Copyright 2005 Nokia. All rights reserved.
+ *
+ * The portions of the attached software ("Contribution") is developed by
+ * Nokia Corporation and is licensed pursuant to the OpenSSL open source
+ * license.
+ *
+ * The Contribution, originally written by Mika Kousa and Pasi Eronen of
+ * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
+ * support (see RFC 4279) to OpenSSL.
+ *
+ * No patent licenses or other rights except those expressly stated in
+ * the OpenSSL open source license shall be deemed granted or received
+ * expressly, by implication, estoppel, or otherwise.
+ *
+ * No assurances are provided by Nokia that the Contribution does not
+ * infringe the patent or other intellectual property rights of any third
+ * party or that the license provides you with all the necessary rights
+ * to make use of the Contribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
+ * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
+ * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
+ * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
+ * OTHERWISE.
+ */
 
 #include <assert.h>
+#include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -135,23 +162,19 @@ typedef unsigned int u_int;
 #include <openssl/pem.h>
 #include <openssl/rand.h>
 #include <openssl/ocsp.h>
+#include <openssl/bn.h>
 #include "s_apps.h"
 #include "timeouts.h"
 
-#ifdef OPENSSL_SYS_WINCE
-/* Windows CE incorrectly defines fileno as returning void*, so to avoid problems below... */
-#ifdef fileno
-#undef fileno
-#endif
-#define fileno(a) (int)_fileno(a)
-#endif
-
-
 #if (defined(OPENSSL_SYS_VMS) && __VMS_VER < 70000000)
 /* FIONBIO used as a switch to enable ioctl, and that isn't in VMS < 7.0 */
 #undef FIONBIO
 #endif
 
+#if defined(OPENSSL_SYS_BEOS_R5)
+#include <fcntl.h>
+#endif
+
 #undef PROG
 #define PROG   s_client_main
 
@@ -166,6 +189,7 @@ typedef unsigned int u_int;
 
 extern int verify_depth;
 extern int verify_error;
+extern int verify_return_error;
 
 #ifdef FIONBIO
 static int c_nbio=0;
@@ -188,6 +212,69 @@ static BIO *bio_c_out=NULL;
 static int c_quiet=0;
 static int c_ign_eof=0;
 
+#ifndef OPENSSL_NO_PSK
+/* Default PSK identity and key */
+static char *psk_identity="Client_identity";
+/*char *psk_key=NULL;  by default PSK is not used */
+
+static unsigned int psk_client_cb(SSL *ssl, const char *hint, char *identity,
+       unsigned int max_identity_len, unsigned char *psk,
+       unsigned int max_psk_len)
+       {
+       unsigned int psk_len = 0;
+       int ret;
+        BIGNUM *bn=NULL;
+
+       if (c_debug)
+               BIO_printf(bio_c_out, "psk_client_cb\n");
+       if (!hint)
+                {
+                /* no ServerKeyExchange message*/
+               if (c_debug)
+                       BIO_printf(bio_c_out,"NULL received PSK identity hint, continuing anyway\n");
+                }
+        else if (c_debug)
+               BIO_printf(bio_c_out, "Received PSK identity hint '%s'\n", hint);
+
+       /* lookup PSK identity and PSK key based on the given identity hint here */
+       ret = BIO_snprintf(identity, max_identity_len, "%s", psk_identity);
+       if (ret < 0 || (unsigned int)ret > max_identity_len)
+               goto out_err;
+       if (c_debug)
+               BIO_printf(bio_c_out, "created identity '%s' len=%d\n", identity, ret);
+        ret=BN_hex2bn(&bn, psk_key);
+        if (!ret)
+                {
+                BIO_printf(bio_err,"Could not convert PSK key '%s' to BIGNUM\n", psk_key);
+                if (bn)
+                        BN_free(bn);
+                return 0;
+                }
+
+        if ((unsigned int)BN_num_bytes(bn) > max_psk_len)
+                {
+                BIO_printf(bio_err,"psk buffer of callback is too small (%d) for key (%d)\n",
+                        max_psk_len, BN_num_bytes(bn));
+                BN_free(bn);
+                return 0;
+                }
+
+        psk_len=BN_bn2bin(bn, psk);
+        BN_free(bn);
+        if (psk_len == 0)
+                goto out_err;
+
+       if (c_debug)
+               BIO_printf(bio_c_out, "created PSK len=%d\n", psk_len);
+
+        return psk_len;
+ out_err:
+       if (c_debug)
+               BIO_printf(bio_err, "Error in PSK client callback\n");
+        return 0;
+       }
+#endif
+
 static void sc_usage(void)
        {
        BIO_printf(bio_err,"usage: s_client args\n");
@@ -196,7 +283,7 @@ static void sc_usage(void)
        BIO_printf(bio_err," -port port     - use -connect instead\n");
        BIO_printf(bio_err," -connect host:port - who to connect to (default is %s:%s)\n",SSL_HOST_NAME,PORT_STR);
 
-       BIO_printf(bio_err," -verify depth - turn on peer certificate verification\n");
+       BIO_printf(bio_err," -verify arg   - turn on peer certificate verification\n");
        BIO_printf(bio_err," -cert arg     - certificate file to use, PEM format assumed\n");
        BIO_printf(bio_err," -certform arg - certificate format (PEM or DER) PEM default\n");
        BIO_printf(bio_err," -key arg      - Private key file to use, in cert file if\n");
@@ -222,6 +309,13 @@ static void sc_usage(void)
        BIO_printf(bio_err," -quiet        - no s_client output\n");
        BIO_printf(bio_err," -ign_eof      - ignore input eof (default when -quiet)\n");
        BIO_printf(bio_err," -no_ign_eof   - don't ignore input eof\n");
+#ifndef OPENSSL_NO_PSK
+       BIO_printf(bio_err," -psk_identity arg - PSK identity\n");
+       BIO_printf(bio_err," -psk arg      - PSK in hex (without 0x)\n");
+# ifndef OPENSSL_NO_JPAKE
+       BIO_printf(bio_err," -jpake arg    - JPAKE secret to use\n");
+# endif
+#endif
        BIO_printf(bio_err," -ssl2         - just use SSLv2\n");
        BIO_printf(bio_err," -ssl3         - just use SSLv3\n");
        BIO_printf(bio_err," -tls1         - just use TLSv1\n");
@@ -248,8 +342,10 @@ static void sc_usage(void)
        BIO_printf(bio_err," -tlsextdebug      - hex dump of all TLS extensions received\n");
        BIO_printf(bio_err," -status           - request certificate status from server\n");
        BIO_printf(bio_err," -no_ticket        - disable use of RFC4507bis session tickets\n");
-       BIO_printf(bio_err," -cutthrough       - enable 1-RTT full-handshake for strong ciphers\n");
+# ifndef OPENSSL_NO_NEXTPROTONEG
        BIO_printf(bio_err," -nextprotoneg arg - enable NPN extension, considering named protocols supported (comma-separated list)\n");
+# endif
+       BIO_printf(bio_err," -cutthrough       - enable 1-RTT full-handshake for strong ciphers\n");
 #endif
        BIO_printf(bio_err," -legacy_renegotiation - enable use of legacy renegotiation (dangerous)\n");
        }
@@ -274,17 +370,8 @@ static int MS_CALLBACK ssl_servername_cb(SSL *s, int *ad, void *arg)
        
        return SSL_TLSEXT_ERR_OK;
        }
-#endif
-enum
-{
-       PROTO_OFF       = 0,
-       PROTO_SMTP,
-       PROTO_POP3,
-       PROTO_IMAP,
-       PROTO_FTP,
-       PROTO_XMPP
-};
 
+# ifndef OPENSSL_NO_NEXTPROTONEG
 /* This the context that we pass to next_proto_cb */
 typedef struct tlsextnextprotoctx_st {
        unsigned char *data;
@@ -316,14 +403,25 @@ static int next_proto_cb(SSL *s, unsigned char **out, unsigned char *outlen, con
        ctx->status = SSL_select_next_proto(out, outlen, in, inlen, ctx->data, ctx->len);
        return SSL_TLSEXT_ERR_OK;
        }
+# endif  /* ndef OPENSSL_NO_NEXTPROTONEG */
+#endif
+
+enum
+{
+       PROTO_OFF       = 0,
+       PROTO_SMTP,
+       PROTO_POP3,
+       PROTO_IMAP,
+       PROTO_FTP,
+       PROTO_XMPP
+};
 
 int MAIN(int, char **);
 
 int MAIN(int argc, char **argv)
        {
-       int off=0, clr = 0;
-       SSL *con=NULL,*con2=NULL;
-       X509_STORE *store = NULL;
+       unsigned int off=0, clr=0;
+       SSL *con=NULL;
        int s,k,width,state=0;
        char *cbuf=NULL,*sbuf=NULL,*mbuf=NULL;
        int cbuf_len,cbuf_off;
@@ -345,12 +443,11 @@ int MAIN(int argc, char **argv)
        SSL_CTX *ctx=NULL;
        int ret=1,in_init=1,i,nbio_test=0;
        int starttls_proto = PROTO_OFF;
-       int prexit = 0, vflags = 0;
-       SSL_METHOD *meth=NULL;
-#ifdef sock_type
-#undef sock_type
-#endif
-       int sock_type=SOCK_STREAM;
+       int prexit = 0;
+       X509_VERIFY_PARAM *vpm = NULL;
+       int badarg = 0;
+       const SSL_METHOD *meth=NULL;
+       int socket_type=SOCK_STREAM;
        BIO *sbio;
        char *inrand=NULL;
        int mbuf_len=0;
@@ -361,15 +458,19 @@ int MAIN(int argc, char **argv)
        ENGINE *ssl_client_engine=NULL;
 #endif
        ENGINE *e=NULL;
-#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE)
+#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE) || defined(OPENSSL_SYS_BEOS_R5)
        struct timeval tv;
+#if defined(OPENSSL_SYS_BEOS_R5)
+       int stdin_set = 0;
+#endif
 #endif
-
 #ifndef OPENSSL_NO_TLSEXT
        char *servername = NULL; 
         tlsextctx tlsextcbp = 
         {NULL,0};
+# ifndef OPENSSL_NO_NEXTPROTONEG
        const char *next_proto_neg_in = NULL;
+# endif
 #endif
        char *sess_in = NULL;
        char *sess_out = NULL;
@@ -465,10 +566,14 @@ int MAIN(int argc, char **argv)
                        if (--argc < 1) goto bad;
                        cert_format = str2fmt(*(++argv));
                        }
-               else if (strcmp(*argv,"-crl_check") == 0)
-                       vflags |= X509_V_FLAG_CRL_CHECK;
-               else if (strcmp(*argv,"-crl_check_all") == 0)
-                       vflags |= X509_V_FLAG_CRL_CHECK|X509_V_FLAG_CRL_CHECK_ALL;
+               else if (args_verify(&argv, &argc, &badarg, bio_err, &vpm))
+                       {
+                       if (badarg)
+                               goto bad;
+                       continue;
+                       }
+               else if (strcmp(*argv,"-verify_return_error") == 0)
+                       verify_return_error = 1;
                else if (strcmp(*argv,"-prexit") == 0)
                        prexit=1;
                else if (strcmp(*argv,"-crlf") == 0)
@@ -504,6 +609,27 @@ int MAIN(int argc, char **argv)
                        nbio_test=1;
                else if (strcmp(*argv,"-state") == 0)
                        state=1;
+#ifndef OPENSSL_NO_PSK
+                else if (strcmp(*argv,"-psk_identity") == 0)
+                       {
+                       if (--argc < 1) goto bad;
+                       psk_identity=*(++argv);
+                       }
+                else if (strcmp(*argv,"-psk") == 0)
+                       {
+                        size_t j;
+
+                       if (--argc < 1) goto bad;
+                       psk_key=*(++argv);
+                       for (j = 0; j < strlen(psk_key); j++)
+                                {
+                                if (isxdigit((int)psk_key[j]))
+                                        continue;
+                                BIO_printf(bio_err,"Not a hex number '%s'\n",*argv);
+                                goto bad;
+                                }
+                       }
+#endif
 #ifndef OPENSSL_NO_SSL2
                else if (strcmp(*argv,"-ssl2") == 0)
                        meth=SSLv2_client_method();
@@ -520,7 +646,7 @@ int MAIN(int argc, char **argv)
                else if (strcmp(*argv,"-dtls1") == 0)
                        {
                        meth=DTLSv1_client_method();
-                       sock_type=SOCK_DGRAM;
+                       socket_type=SOCK_DGRAM;
                        }
                else if (strcmp(*argv,"-timeout") == 0)
                        enable_timeouts=1;
@@ -567,14 +693,18 @@ int MAIN(int argc, char **argv)
                        off|=SSL_OP_NO_SSLv3;
                else if (strcmp(*argv,"-no_ssl2") == 0)
                        off|=SSL_OP_NO_SSLv2;
+               else if (strcmp(*argv,"-no_comp") == 0)
+                       { off|=SSL_OP_NO_COMPRESSION; }
 #ifndef OPENSSL_NO_TLSEXT
                else if (strcmp(*argv,"-no_ticket") == 0)
                        { off|=SSL_OP_NO_TICKET; }
+# ifndef OPENSSL_NO_NEXTPROTONEG
                else if (strcmp(*argv,"-nextprotoneg") == 0)
                        {
                        if (--argc < 1) goto bad;
                        next_proto_neg_in = *(++argv);
                        }
+# endif
 #endif
                else if (strcmp(*argv,"-cutthrough") == 0)
                        cutthrough=1;
@@ -660,10 +790,30 @@ bad:
                goto end;
                }
 
+#if !defined(OPENSSL_NO_JPAKE) && !defined(OPENSSL_NO_PSK)
+       if (jpake_secret)
+               {
+               if (psk_key)
+                       {
+                       BIO_printf(bio_err,
+                                  "Can't use JPAKE and PSK together\n");
+                       goto end;
+                       }
+               psk_identity = "JPAKE";
+               }
+
+       if (cipher)
+               {
+               BIO_printf(bio_err, "JPAKE sets cipher to PSK\n");
+               goto end;
+               }
+       cipher = "PSK";
+#endif
+
        OpenSSL_add_ssl_algorithms();
        SSL_load_error_strings();
 
-#ifndef OPENSSL_NO_TLSEXT
+#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
        next_proto.status = -1;
        if (next_proto_neg_in)
                {
@@ -690,6 +840,7 @@ bad:
                        goto end;
                        }
                }
+
 #endif
        if (!app_passwd(bio_err, passarg, NULL, &pass, NULL))
                {
@@ -757,6 +908,9 @@ bad:
                goto end;
                }
 
+       if (vpm)
+               SSL_CTX_set1_param(ctx, vpm);
+
 #ifndef OPENSSL_NO_ENGINE
        if (ssl_client_engine)
                {
@@ -771,6 +925,18 @@ bad:
                }
 #endif
 
+#ifndef OPENSSL_NO_PSK
+#ifdef OPENSSL_NO_JPAKE
+       if (psk_key != NULL)
+#else
+       if (psk_key != NULL || jpake_secret)
+#endif
+               {
+               if (c_debug)
+                       BIO_printf(bio_c_out, "PSK key given or JPAKE in use, setting client callback\n");
+               SSL_CTX_set_psk_client_callback(ctx, psk_client_cb);
+               }
+#endif
        if (bugs)
                SSL_CTX_set_options(ctx,SSL_OP_ALL|off);
        else
@@ -781,7 +947,7 @@ bad:
        /* DTLS: partial reads end up discarding unread UDP bytes :-( 
         * Setting read ahead solves this problem.
         */
-       if (sock_type == SOCK_DGRAM) SSL_CTX_set_read_ahead(ctx, 1);
+       if (socket_type == SOCK_DGRAM) SSL_CTX_set_read_ahead(ctx, 1);
 
        /* Enable handshake cutthrough for client connections using
         * strong ciphers. */
@@ -792,8 +958,10 @@ bad:
                SSL_CTX_set_mode(ctx, ssl_mode);
                }
 
+#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
        if (next_proto.data)
                SSL_CTX_set_next_proto_select_cb(ctx, next_proto_cb, &next_proto);
+#endif
 
        if (state) SSL_CTX_set_info_callback(ctx,apps_ssl_info_callback);
        if (cipher != NULL)
@@ -819,8 +987,6 @@ bad:
                /* goto end; */
                }
 
-       store = SSL_CTX_get_cert_store(ctx);
-       X509_STORE_set_flags(store, vflags);
 #ifndef OPENSSL_NO_TLSEXT
        if (servername != NULL)
                {
@@ -865,7 +1031,6 @@ bad:
                        }
                }
 #endif
-
 #ifndef OPENSSL_NO_KRB5
        if (con  &&  (con->kssl_ctx = kssl_ctx_new()) != NULL)
                 {
@@ -873,10 +1038,15 @@ bad:
                }
 #endif /* OPENSSL_NO_KRB5  */
 /*     SSL_set_cipher_list(con,"RC4-MD5"); */
+#if 0
+#ifdef TLSEXT_TYPE_opaque_prf_input
+       SSL_set_tlsext_opaque_prf_input(con, "Test client", 11);
+#endif
+#endif
 
 re_start:
 
-       if (init_client(&s,host,port,sock_type) == 0)
+       if (init_client(&s,host,port,socket_type) == 0)
                {
                BIO_printf(bio_err,"connect:errno=%d\n",get_last_socket_error());
                SHUTDOWN(s);
@@ -912,7 +1082,7 @@ re_start:
 
                (void)BIO_ctrl_set_connected(sbio, 1, &peer);
 
-               if ( enable_timeouts)
+               if (enable_timeouts)
                        {
                        timeout.tv_sec = 0;
                        timeout.tv_usec = DGRAM_RCV_TIMEOUT;
@@ -1133,6 +1303,14 @@ SSL_set_tlsext_status_ids(con, ids);
                        if (in_init)
                                {
                                in_init=0;
+#if 0 /* This test doesn't really work as intended (needs to be fixed) */
+#ifndef OPENSSL_NO_TLSEXT
+                               if (servername != NULL && !SSL_session_reused(con))
+                                       {
+                                       BIO_printf(bio_c_out,"Server did %sacknowledge servername extension.\n",tlsextcbp.ack?"":"not ");
+                                       }
+#endif
+#endif
                                if (sess_out)
                                        {
                                        BIO *stmp = BIO_new_file(sess_out, "w");
@@ -1170,22 +1348,22 @@ SSL_set_tlsext_status_ids(con, ids);
 
                if (!ssl_pending)
                        {
-#if !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_NETWARE)
+#if !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_NETWARE) && !defined (OPENSSL_SYS_BEOS_R5)
                        if (tty_on)
                                {
-                               if (read_tty)  FD_SET(fileno(stdin),&readfds);
-                               if (write_tty) FD_SET(fileno(stdout),&writefds);
+                               if (read_tty)  openssl_fdset(fileno(stdin),&readfds);
+                               if (write_tty) openssl_fdset(fileno(stdout),&writefds);
                                }
                        if (read_ssl)
-                               FD_SET(SSL_get_fd(con),&readfds);
+                               openssl_fdset(SSL_get_fd(con),&readfds);
                        if (write_ssl)
-                               FD_SET(SSL_get_fd(con),&writefds);
+                               openssl_fdset(SSL_get_fd(con),&writefds);
 #else
                        if(!tty_on || !write_tty) {
                                if (read_ssl)
-                                       FD_SET(SSL_get_fd(con),&readfds);
+                                       openssl_fdset(SSL_get_fd(con),&readfds);
                                if (write_ssl)
-                                       FD_SET(SSL_get_fd(con),&writefds);
+                                       openssl_fdset(SSL_get_fd(con),&writefds);
                        }
 #endif
 /*                     printf("mode tty(%d %d%d) ssl(%d%d)\n",
@@ -1230,6 +1408,25 @@ SSL_set_tlsext_status_ids(con, ids);
                                } else  i=select(width,(void *)&readfds,(void *)&writefds,
                                        NULL,timeoutp);
                        }
+#elif defined(OPENSSL_SYS_BEOS_R5)
+                       /* Under BeOS-R5 the situation is similar to DOS */
+                       i=0;
+                       stdin_set = 0;
+                       (void)fcntl(fileno(stdin), F_SETFL, O_NONBLOCK);
+                       if(!write_tty) {
+                               if(read_tty) {
+                                       tv.tv_sec = 1;
+                                       tv.tv_usec = 0;
+                                       i=select(width,(void *)&readfds,(void *)&writefds,
+                                                NULL,&tv);
+                                       if (read(fileno(stdin), sbuf, 0) >= 0)
+                                               stdin_set = 1;
+                                       if (!i && (stdin_set != 1 || !read_tty))
+                                               continue;
+                               } else  i=select(width,(void *)&readfds,(void *)&writefds,
+                                        NULL,timeoutp);
+                       }
+                       (void)fcntl(fileno(stdin), F_SETFL, 0);
 #else
                        i=select(width,(void *)&readfds,(void *)&writefds,
                                 NULL,timeoutp);
@@ -1288,6 +1485,7 @@ SSL_set_tlsext_status_ids(con, ids);
                                if (cbuf_len != 0)
                                        {
                                        BIO_printf(bio_c_out,"shutdown\n");
+                                       ret = 0;
                                        goto shut;
                                        }
                                else
@@ -1315,8 +1513,8 @@ SSL_set_tlsext_status_ids(con, ids);
                                goto shut;
                                }
                        }
-#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE)
-               /* Assume Windows/DOS can always write */
+#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE) || defined(OPENSSL_SYS_BEOS_R5)
+               /* Assume Windows/DOS/BeOS can always write */
                else if (!ssl_pending && write_tty)
 #else
                else if (!ssl_pending && FD_ISSET(fileno(stdout),&writefds))
@@ -1325,11 +1523,12 @@ SSL_set_tlsext_status_ids(con, ids);
 #ifdef CHARSET_EBCDIC
                        ascii2ebcdic(&(sbuf[sbuf_off]),&(sbuf[sbuf_off]),sbuf_len);
 #endif
-                       i=write(fileno(stdout),&(sbuf[sbuf_off]),sbuf_len);
+                       i=raw_write_stdout(&(sbuf[sbuf_off]),sbuf_len);
 
                        if (i <= 0)
                                {
                                BIO_printf(bio_c_out,"DONE\n");
+                               ret = 0;
                                goto shut;
                                /* goto end; */
                                }
@@ -1384,10 +1583,12 @@ printf("read=%d pending=%d peek=%d\n",k,SSL_pending(con),SSL_peek(con,zbuf,10240
                                BIO_printf(bio_c_out,"read X BLOCK\n");
                                break;
                        case SSL_ERROR_SYSCALL:
-                               BIO_printf(bio_err,"read:errno=%d\n",get_last_socket_error());
+                               ret=get_last_socket_error();
+                               BIO_printf(bio_err,"read:errno=%d\n",ret);
                                goto shut;
                        case SSL_ERROR_ZERO_RETURN:
                                BIO_printf(bio_c_out,"closed\n");
+                               ret=0;
                                goto shut;
                        case SSL_ERROR_SSL:
                                ERR_print_errors(bio_err);
@@ -1403,7 +1604,9 @@ printf("read=%d pending=%d peek=%d\n",k,SSL_pending(con),SSL_peek(con,zbuf,10240
                else if ((_kbhit()) || (WAIT_OBJECT_0 == WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE), 0)))
 #endif
 #elif defined (OPENSSL_SYS_NETWARE)
-        else if (_kbhit())
+               else if (_kbhit())
+#elif defined(OPENSSL_SYS_BEOS_R5)
+               else if (stdin_set)
 #else
                else if (FD_ISSET(fileno(stdin),&readfds))
 #endif
@@ -1412,7 +1615,7 @@ printf("read=%d pending=%d peek=%d\n",k,SSL_pending(con),SSL_peek(con,zbuf,10240
                                {
                                int j, lf_num;
 
-                               i=read(fileno(stdin),cbuf,BUFSIZZ/2);
+                               i=raw_read_stdin(cbuf,BUFSIZZ/2);
                                lf_num = 0;
                                /* both loops are skipped when i <= 0 */
                                for (j = 0; j < i; j++)
@@ -1431,11 +1634,12 @@ printf("read=%d pending=%d peek=%d\n",k,SSL_pending(con),SSL_peek(con,zbuf,10240
                                assert(lf_num == 0);
                                }
                        else
-                               i=read(fileno(stdin),cbuf,BUFSIZZ);
+                               i=raw_read_stdin(cbuf,BUFSIZZ);
 
                        if ((!c_ign_eof) && ((i <= 0) || (cbuf[0] == 'Q')))
                                {
                                BIO_printf(bio_err,"DONE\n");
+                               ret=0;
                                goto shut;
                                }
 
@@ -1458,14 +1662,20 @@ printf("read=%d pending=%d peek=%d\n",k,SSL_pending(con),SSL_peek(con,zbuf,10240
                        read_tty=0;
                        }
                }
+
+       ret=0;
 shut:
+       if (in_init)
+               print_stuff(bio_c_out,con,full_log);
        SSL_shutdown(con);
        SHUTDOWN(SSL_get_fd(con));
-       ret=0;
 end:
-       if(prexit) print_stuff(bio_c_out,con,1);
-       if (con != NULL) SSL_free(con);
-       if (con2 != NULL) SSL_free(con2);
+       if (con != NULL)
+               {
+               if (prexit != 0)
+                       print_stuff(bio_c_out,con,1);
+               SSL_free(con);
+               }
        if (ctx != NULL) SSL_CTX_free(ctx);
        if (cert)
                X509_free(cert);
@@ -1494,7 +1704,7 @@ static void print_stuff(BIO *bio, SSL *s, int full)
        char buf[BUFSIZ];
        STACK_OF(X509) *sk;
        STACK_OF(X509_NAME) *sk2;
-       SSL_CIPHER *c;
+       const SSL_CIPHER *c;
        X509_NAME *xn;
        int j,i;
 #ifndef OPENSSL_NO_COMP
@@ -1613,16 +1823,14 @@ static void print_stuff(BIO *bio, SSL *s, int full)
                expansion ? SSL_COMP_get_name(expansion) : "NONE");
 #endif
 
-#ifndef OPENSSL_NO_TLSEXT
-       {
-               if (next_proto.status != -1) {
-                       const unsigned char *proto;
-                       unsigned int proto_len;
-                       SSL_get0_next_proto_negotiated(s, &proto, &proto_len);
-                       BIO_printf(bio, "Next protocol: (%d) ", next_proto.status);
-                       BIO_write(bio, proto, proto_len);
-                       BIO_write(bio, "\n", 1);
-               }
+#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
+       if (next_proto.status != -1) {
+               const unsigned char *proto;
+               unsigned int proto_len;
+               SSL_get0_next_proto_negotiated(s, &proto, &proto_len);
+               BIO_printf(bio, "Next protocol: (%d) ", next_proto.status);
+               BIO_write(bio, proto, proto_len);
+               BIO_write(bio, "\n", 1);
        }
 #endif
 
@@ -1661,4 +1869,5 @@ static int ocsp_resp_cb(SSL *s, void *arg)
        OCSP_RESPONSE_free(rsp);
        return 1;
        }
-#endif  /* ndef OPENSSL_NO_TLSEXT */
+
+#endif
index 4f38016..a8e057c 100644 (file)
@@ -56,7 +56,7 @@
  * [including the GNU Public Licence.]
  */
 /* ====================================================================
- * Copyright (c) 1998-2001 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * ECC cipher suite support in OpenSSL originally developed by 
  * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
  */
+/* ====================================================================
+ * Copyright 2005 Nokia. All rights reserved.
+ *
+ * The portions of the attached software ("Contribution") is developed by
+ * Nokia Corporation and is licensed pursuant to the OpenSSL open source
+ * license.
+ *
+ * The Contribution, originally written by Mika Kousa and Pasi Eronen of
+ * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
+ * support (see RFC 4279) to OpenSSL.
+ *
+ * No patent licenses or other rights except those expressly stated in
+ * the OpenSSL open source license shall be deemed granted or received
+ * expressly, by implication, estoppel, or otherwise.
+ *
+ * No assurances are provided by Nokia that the Contribution does not
+ * infringe the patent or other intellectual property rights of any third
+ * party or that the license provides you with all the necessary rights
+ * to make use of the Contribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
+ * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
+ * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
+ * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
+ * OTHERWISE.
+ */
 
 /* Until the key-gen callbacks are modified to use newer prototypes, we allow
  * deprecated functions for openssl-internal code */
 #endif
 
 #include <assert.h>
+#include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include <sys/stat.h>
 #include <openssl/e_os2.h>
 #ifdef OPENSSL_NO_STDIO
 #define APPS_WIN16
@@ -163,19 +189,15 @@ typedef unsigned int u_int;
 #include "s_apps.h"
 #include "timeouts.h"
 
-#ifdef OPENSSL_SYS_WINCE
-/* Windows CE incorrectly defines fileno as returning void*, so to avoid problems below... */
-#ifdef fileno
-#undef fileno
-#endif
-#define fileno(a) (int)_fileno(a)
-#endif
-
 #if (defined(OPENSSL_SYS_VMS) && __VMS_VER < 70000000)
 /* FIONBIO used as a switch to enable ioctl, and that isn't in VMS < 7.0 */
 #undef FIONBIO
 #endif
 
+#if defined(OPENSSL_SYS_BEOS_R5)
+#include <fcntl.h>
+#endif
+
 #ifndef OPENSSL_NO_RSA
 static RSA MS_CALLBACK *tmp_rsa_cb(SSL *s, int is_export, int keylength);
 #endif
@@ -196,14 +218,6 @@ static DH *get_dh512(void);
 static void s_server_init(void);
 #endif
 
-#ifndef S_ISDIR
-# if defined(_S_IFMT) && defined(_S_IFDIR)
-#  define S_ISDIR(a)   (((a) & _S_IFMT) == _S_IFDIR)
-# else
-#  define S_ISDIR(a)   (((a) & S_IFMT) == S_IFDIR)
-# endif
-#endif
-
 #ifndef OPENSSL_NO_DH
 static unsigned char dh512_p[]={
        0xDA,0x58,0x3C,0x16,0xD9,0x85,0x22,0x89,0xD0,0xE4,0xAF,0x75,
@@ -245,7 +259,7 @@ static int accept_socket= -1;
 #undef PROG
 #define PROG           s_server_main
 
-extern int verify_depth;
+extern int verify_depth, verify_return_error;
 
 static char *cipher=NULL;
 static int s_server_verify=SSL_VERIFY_NONE;
@@ -288,6 +302,72 @@ static long socket_mtu;
 static int cert_chain = 0;
 #endif
 
+#ifndef OPENSSL_NO_PSK
+static char *psk_identity="Client_identity";
+char *psk_key=NULL; /* by default PSK is not used */
+
+static unsigned int psk_server_cb(SSL *ssl, const char *identity,
+       unsigned char *psk, unsigned int max_psk_len)
+       {
+       unsigned int psk_len = 0;
+       int ret;
+       BIGNUM *bn = NULL;
+
+       if (s_debug)
+               BIO_printf(bio_s_out,"psk_server_cb\n");
+       if (!identity)
+               {
+               BIO_printf(bio_err,"Error: client did not send PSK identity\n");
+               goto out_err;
+               }
+       if (s_debug)
+               BIO_printf(bio_s_out,"identity_len=%d identity=%s\n",
+                       identity ? (int)strlen(identity) : 0, identity);
+
+       /* here we could lookup the given identity e.g. from a database */
+       if (strcmp(identity, psk_identity) != 0)
+               {
+                BIO_printf(bio_s_out, "PSK error: client identity not found"
+                          " (got '%s' expected '%s')\n", identity,
+                          psk_identity);
+               goto out_err;
+                }
+       if (s_debug)
+               BIO_printf(bio_s_out, "PSK client identity found\n");
+
+       /* convert the PSK key to binary */
+       ret = BN_hex2bn(&bn, psk_key);
+       if (!ret)
+               {
+               BIO_printf(bio_err,"Could not convert PSK key '%s' to BIGNUM\n", psk_key);
+               if (bn)
+                       BN_free(bn);
+               return 0;
+               }
+       if (BN_num_bytes(bn) > (int)max_psk_len)
+               {
+               BIO_printf(bio_err,"psk buffer of callback is too small (%d) for key (%d)\n",
+                       max_psk_len, BN_num_bytes(bn));
+               BN_free(bn);
+               return 0;
+               }
+
+       ret = BN_bn2bin(bn, psk);
+       BN_free(bn);
+
+       if (ret < 0)
+               goto out_err;
+       psk_len = (unsigned int)ret;
+
+       if (s_debug)
+               BIO_printf(bio_s_out, "fetched PSK len=%d\n", psk_len);
+        return psk_len;
+ out_err:
+       if (s_debug)
+               BIO_printf(bio_err, "Error in PSK server callback\n");
+       return 0;
+        }
+#endif
 
 #ifdef MONOLITH
 static void s_server_init(void)
@@ -352,7 +432,7 @@ static void sv_usage(void)
 #ifndef OPENSSL_NO_ECDH
        BIO_printf(bio_err," -named_curve arg  - Elliptic curve name to use for ephemeral ECDH keys.\n" \
                           "                 Use \"openssl ecparam -list_curves\" for all names\n" \
-                          "                 (default is sect163r2).\n");
+                          "                 (default is nistp256).\n");
 #endif
 #ifdef FIONBIO
        BIO_printf(bio_err," -nbio         - Run with non-blocking IO\n");
@@ -369,6 +449,13 @@ static void sv_usage(void)
        BIO_printf(bio_err," -serverpref   - Use server's cipher preferences\n");
        BIO_printf(bio_err," -quiet        - No server output\n");
        BIO_printf(bio_err," -no_tmp_rsa   - Do not generate a tmp RSA key\n");
+#ifndef OPENSSL_NO_PSK
+       BIO_printf(bio_err," -psk_hint arg - PSK identity hint to use\n");
+       BIO_printf(bio_err," -psk arg      - PSK in hex (without 0x)\n");
+# ifndef OPENSSL_NO_JPAKE
+       BIO_printf(bio_err," -jpake arg    - JPAKE secret to use\n");
+# endif
+#endif
        BIO_printf(bio_err," -ssl2         - Just talk SSLv2\n");
        BIO_printf(bio_err," -ssl3         - Just talk SSLv3\n");
        BIO_printf(bio_err," -tls1         - Just talk TLSv1\n");
@@ -405,7 +492,9 @@ static void sv_usage(void)
        BIO_printf(bio_err," -tlsextdebug  - hex dump of all TLS extensions received\n");
        BIO_printf(bio_err," -no_ticket    - disable use of RFC4507bis session tickets\n");
        BIO_printf(bio_err," -legacy_renegotiation - enable use of legacy renegotiation (dangerous)\n");
+# ifndef OPENSSL_NO_NEXTPROTONEG
        BIO_printf(bio_err," -nextprotoneg arg - set the advertised protocols for the NPN extension (comma-separated list)\n");
+# endif
 #endif
        }
 
@@ -588,7 +677,7 @@ static int MS_CALLBACK ssl_servername_cb(SSL *s, int *ad, void *arg)
                        return p->extension_error;
                if (ctx2)
                        {
-                       BIO_printf(p->biodebug,"Swiching server context.\n");
+                       BIO_printf(p->biodebug,"Switching server context.\n");
                        SSL_set_SSL_CTX(s,ctx2);
                        }     
                }
@@ -627,7 +716,7 @@ static int cert_status_cb(SSL *s, void *arg)
        int use_ssl;
        unsigned char *rspder = NULL;
        int rspderlen;
-       STACK *aia = NULL;
+       STACK_OF(OPENSSL_STRING) *aia = NULL;
        X509 *x = NULL;
        X509_STORE_CTX inctx;
        X509_OBJECT obj;
@@ -649,7 +738,7 @@ BIO_printf(err, "cert_status: received %d ids\n", sk_OCSP_RESPID_num(ids));
        aia = X509_get1_ocsp(x);
        if (aia)
                {
-               if (!OCSP_parse_url(sk_value(aia, 0),
+               if (!OCSP_parse_url(sk_OPENSSL_STRING_value(aia, 0),
                        &host, &port, &path, &use_ssl))
                        {
                        BIO_puts(err, "cert_status: can't parse AIA URL\n");
@@ -657,7 +746,7 @@ BIO_printf(err, "cert_status: received %d ids\n", sk_OCSP_RESPID_num(ids));
                        }
                if (srctx->verbose)
                        BIO_printf(err, "cert_status: AIA URL: %s\n",
-                                       sk_value(aia, 0));
+                                       sk_OPENSSL_STRING_value(aia, 0));
                }
        else
                {
@@ -702,7 +791,7 @@ BIO_printf(err, "cert_status: received %d ids\n", sk_OCSP_RESPID_num(ids));
                if (!OCSP_REQUEST_add_ext(req, ext, -1))
                        goto err;
                }
-       resp = process_responder(err, req, host, path, port, use_ssl,
+       resp = process_responder(err, req, host, path, port, use_ssl, NULL,
                                        srctx->timeout);
        if (!resp)
                {
@@ -740,16 +829,14 @@ BIO_printf(err, "cert_status: received %d ids\n", sk_OCSP_RESPID_num(ids));
        ret = SSL_TLSEXT_ERR_ALERT_FATAL;
        goto done;
        }
-#endif
 
-
-/* This the context that we pass to next_proto_cb */
+# ifndef OPENSSL_NO_NEXTPROTONEG
+/* This is the context that we pass to next_proto_cb */
 typedef struct tlsextnextprotoctx_st {
        unsigned char *data;
        unsigned int len;
 } tlsextnextprotoctx;
 
-
 static int next_proto_cb(SSL *s, const unsigned char **data, unsigned int *len, void *arg)
        {
        tlsextnextprotoctx *next_proto = arg;
@@ -759,7 +846,8 @@ static int next_proto_cb(SSL *s, const unsigned char **data, unsigned int *len,
 
        return SSL_TLSEXT_ERR_OK;
        }
-
+# endif  /* ndef OPENSSL_NO_NPN */
+#endif
 
 int MAIN(int, char **);
 
@@ -769,8 +857,8 @@ static char *jpake_secret = NULL;
 
 int MAIN(int argc, char *argv[])
        {
-       X509_STORE *store = NULL;
-       int vflags = 0;
+       X509_VERIFY_PARAM *vpm = NULL;
+       int badarg = 0;
        short port=PORT;
        char *CApath=NULL,*CAfile=NULL;
        unsigned char *context = NULL;
@@ -783,8 +871,8 @@ int MAIN(int argc, char *argv[])
        int off=0;
        int no_tmp_rsa=0,no_dhe=0,no_ecdhe=0,nocert=0;
        int state=0;
-       SSL_METHOD *meth=NULL;
-        int socket_type=SOCK_STREAM;
+       const SSL_METHOD *meth=NULL;
+       int socket_type=SOCK_STREAM;
        ENGINE *e=NULL;
        char *inrand=NULL;
        int s_cert_format = FORMAT_PEM, s_key_format = FORMAT_PEM;
@@ -800,11 +888,15 @@ int MAIN(int argc, char *argv[])
 #endif
 #ifndef OPENSSL_NO_TLSEXT
         tlsextctx tlsextcbp = {NULL, NULL, SSL_TLSEXT_ERR_ALERT_WARNING};
+# ifndef OPENSSL_NO_NEXTPROTONEG
        const char *next_proto_neg_in = NULL;
        tlsextnextprotoctx next_proto;
-       char snapstart = 0;
+# endif
+#endif
+#ifndef OPENSSL_NO_PSK
+       /* by default do not send a PSK identity hint */
+       static char *psk_identity_hint=NULL;
 #endif
-
 #if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL3)
        meth=SSLv23_server_method();
 #elif !defined(OPENSSL_NO_SSL3)
@@ -938,14 +1030,14 @@ int MAIN(int argc, char *argv[])
                        }
                else if (strcmp(*argv,"-no_cache") == 0)
                        no_cache = 1;
-               else if (strcmp(*argv,"-crl_check") == 0)
-                       {
-                       vflags |= X509_V_FLAG_CRL_CHECK;
-                       }
-               else if (strcmp(*argv,"-crl_check_all") == 0)
+               else if (args_verify(&argv, &argc, &badarg, bio_err, &vpm))
                        {
-                       vflags |= X509_V_FLAG_CRL_CHECK|X509_V_FLAG_CRL_CHECK_ALL;
+                       if (badarg)
+                               goto bad;
+                       continue;
                        }
+               else if (strcmp(*argv,"-verify_return_error") == 0)
+                       verify_return_error = 1;
                else if (strcmp(*argv,"-serverpref") == 0)
                        { off|=SSL_OP_CIPHER_SERVER_PREFERENCE; }
                else if (strcmp(*argv,"-legacy_renegotiation") == 0)
@@ -1022,6 +1114,27 @@ int MAIN(int argc, char *argv[])
                        { no_dhe=1; }
                else if (strcmp(*argv,"-no_ecdhe") == 0)
                        { no_ecdhe=1; }
+#ifndef OPENSSL_NO_PSK
+                else if (strcmp(*argv,"-psk_hint") == 0)
+                       {
+                        if (--argc < 1) goto bad;
+                        psk_identity_hint= *(++argv);
+                        }
+                else if (strcmp(*argv,"-psk") == 0)
+                       {
+                       size_t i;
+
+                       if (--argc < 1) goto bad;
+                       psk_key=*(++argv);
+                       for (i=0; i<strlen(psk_key); i++)
+                               {
+                               if (isxdigit((int)psk_key[i]))
+                                       continue;
+                               BIO_printf(bio_err,"Not a hex number '%s'\n",*argv);
+                               goto bad;
+                               }
+                       }
+#endif
                else if (strcmp(*argv,"-www") == 0)
                        { www=1; }
                else if (strcmp(*argv,"-WWW") == 0)
@@ -1034,6 +1147,8 @@ int MAIN(int argc, char *argv[])
                        { off|=SSL_OP_NO_SSLv3; }
                else if (strcmp(*argv,"-no_tls1") == 0)
                        { off|=SSL_OP_NO_TLSv1; }
+               else if (strcmp(*argv,"-no_comp") == 0)
+                       { off|=SSL_OP_NO_COMPRESSION; }
 #ifndef OPENSSL_NO_TLSEXT
                else if (strcmp(*argv,"-no_ticket") == 0)
                        { off|=SSL_OP_NO_TICKET; }
@@ -1101,17 +1216,15 @@ int MAIN(int argc, char *argv[])
                        if (--argc < 1) goto bad;
                        s_key_file2= *(++argv);
                        }
+# ifndef OPENSSL_NO_NEXTPROTONEG
                else if (strcmp(*argv,"-nextprotoneg") == 0)
                        {
                        if (--argc < 1) goto bad;
                        next_proto_neg_in = *(++argv);
                        }
-               else if (strcmp(*argv,"-snapstart") == 0)
-                       {
-                       snapstart = 1;
-                       }
+# endif
 #endif
-#ifndef OPENSSL_NO_JPAKE
+#if !defined(OPENSSL_NO_JPAKE) && !defined(OPENSSL_NO_PSK)
                else if (strcmp(*argv,"-jpake") == 0)
                        {
                        if (--argc < 1) goto bad;
@@ -1134,6 +1247,26 @@ bad:
                goto end;
                }
 
+#if !defined(OPENSSL_NO_JPAKE) && !defined(OPENSSL_NO_PSK)
+       if (jpake_secret)
+               {
+               if (psk_key)
+                       {
+                       BIO_printf(bio_err,
+                                  "Can't use JPAKE and PSK together\n");
+                       goto end;
+                       }
+               psk_identity = "JPAKE";
+               if (cipher)
+                       {
+                       BIO_printf(bio_err, "JPAKE sets cipher to PSK\n");
+                       goto end;
+                       }
+               cipher = "PSK";
+               }
+
+#endif
+
        SSL_load_error_strings();
        OpenSSL_add_ssl_algorithms();
 
@@ -1194,22 +1327,10 @@ bad:
                                goto end;
                                }
                        }
-
-               if (next_proto_neg_in)
-                       {
-                       unsigned short len;
-                       next_proto.data = next_protos_parse(&len,
-                               next_proto_neg_in);
-                       if (next_proto.data == NULL)
-                               goto end;
-                       next_proto.len = len;
-                       }
-               else
-                       {
-                       next_proto.data = NULL;
-                       }
 #endif
                }
+
+
        if (s_dcert_file)
                {
 
@@ -1328,8 +1449,9 @@ bad:
                ERR_print_errors(bio_err);
                /* goto end; */
                }
-       store = SSL_CTX_get_cert_store(ctx);
-       X509_STORE_set_flags(store, vflags);
+       if (vpm)
+               SSL_CTX_set1_param(ctx, vpm);
+
 #ifndef OPENSSL_NO_TLSEXT
        if (s_cert2)
                {
@@ -1365,13 +1487,11 @@ bad:
                if (bugs) SSL_CTX_set_options(ctx2,SSL_OP_ALL);
                if (hack) SSL_CTX_set_options(ctx2,SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG);
                SSL_CTX_set_options(ctx2,off);
-
                /* DTLS: partial reads end up discarding unread UDP bytes :-( 
                 * Setting read ahead solves this problem.
                 */
                if (socket_type == SOCK_DGRAM) SSL_CTX_set_read_ahead(ctx2, 1);
 
-
                if (state) SSL_CTX_set_info_callback(ctx2,apps_ssl_info_callback);
 
                if (no_cache)
@@ -1384,22 +1504,16 @@ bad:
                        {
                        ERR_print_errors(bio_err);
                        }
-               store = SSL_CTX_get_cert_store(ctx2);
-               X509_STORE_set_flags(store, vflags);
+               if (vpm)
+                       SSL_CTX_set1_param(ctx2, vpm);
                }
 
+# ifndef OPENSSL_NO_NEXTPROTONEG
        if (next_proto.data)
-               {
                SSL_CTX_set_next_protos_advertised_cb(ctx, next_proto_cb, &next_proto);
-               }
+# endif
 #endif 
 
-       if (snapstart)
-               {
-               static const unsigned char orbit[8] = {1, 2, 3, 4, 5, 6, 7, 8};
-               SSL_CTX_set_snap_start_orbit(ctx, orbit);
-               }
-
 #ifndef OPENSSL_NO_DH
        if (!no_dhe)
                {
@@ -1475,10 +1589,10 @@ bad:
                else
                        {
                        BIO_printf(bio_s_out,"Using default temp ECDH parameters\n");
-                       ecdh = EC_KEY_new_by_curve_name(NID_sect163r2);
+                       ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
                        if (ecdh == NULL) 
                                {
-                               BIO_printf(bio_err, "unable to create curve (sect163r2)\n");
+                               BIO_printf(bio_err, "unable to create curve (nistp256)\n");
                                goto end;
                                }
                        }
@@ -1513,7 +1627,7 @@ bad:
 #ifndef OPENSSL_NO_TLSEXT
                if (ctx2) 
                        SSL_CTX_set_tmp_rsa_callback(ctx2,tmp_rsa_cb);
-#endif 
+#endif         
                }
 #else
        if (!no_tmp_rsa && SSL_CTX_need_tmp_RSA(ctx))
@@ -1539,6 +1653,21 @@ bad:
                                        goto end;
                                        }
                                }
+# ifndef OPENSSL_NO_NEXTPROTONEG
+               if (next_proto_neg_in)
+                       {
+                       unsigned short len;
+                       next_proto.data = next_protos_parse(&len,
+                               next_proto_neg_in);
+                       if (next_proto.data == NULL)
+                               goto end;
+                       next_proto.len = len;
+                       }
+               else
+                       {
+                       next_proto.data = NULL;
+                       }
+# endif
 #endif
                RSA_free(rsa);
                BIO_printf(bio_s_out,"\n");
@@ -1546,11 +1675,34 @@ bad:
 #endif
 #endif
 
-       if (cipher != NULL)
-               if(!SSL_CTX_set_cipher_list(ctx,cipher)) {
-               BIO_printf(bio_err,"error setting cipher list\n");
+#ifndef OPENSSL_NO_PSK
+#ifdef OPENSSL_NO_JPAKE
+       if (psk_key != NULL)
+#else
+       if (psk_key != NULL || jpake_secret)
+#endif
+               {
+               if (s_debug)
+                       BIO_printf(bio_s_out, "PSK key given or JPAKE in use, setting server callback\n");
+               SSL_CTX_set_psk_server_callback(ctx, psk_server_cb);
+               }
+
+       if (!SSL_CTX_use_psk_identity_hint(ctx, psk_identity_hint))
+               {
+               BIO_printf(bio_err,"error setting PSK identity hint to context\n");
                ERR_print_errors(bio_err);
                goto end;
+               }
+#endif
+
+       if (cipher != NULL)
+               {
+               if(!SSL_CTX_set_cipher_list(ctx,cipher))
+                       {
+                       BIO_printf(bio_err,"error setting cipher list\n");
+                       ERR_print_errors(bio_err);
+                       goto end;
+                       }
 #ifndef OPENSSL_NO_TLSEXT
                if (ctx2 && !SSL_CTX_set_cipher_list(ctx2,cipher))
                        {
@@ -1559,7 +1711,7 @@ bad:
                        goto end;
                        }
 #endif
-       }
+               }
        SSL_CTX_set_verify(ctx,s_server_verify,verify_callback);
        SSL_CTX_set_session_id_context(ctx,(void*)&s_server_session_id_context,
                sizeof s_server_session_id_context);
@@ -1582,6 +1734,7 @@ bad:
                SSL_CTX_set_tlsext_servername_arg(ctx, &tlsextcbp);
                }
 #endif
+
        if (CAfile != NULL)
                {
                SSL_CTX_set_client_CA_list(ctx,SSL_load_client_CA_file(CAfile));
@@ -1590,7 +1743,9 @@ bad:
                        SSL_CTX_set_client_CA_list(ctx2,SSL_load_client_CA_file(CAfile));
 #endif
                }
+
        BIO_printf(bio_s_out,"ACCEPT\n");
+       (void)BIO_flush(bio_s_out);
        if (www)
                do_server(port,socket_type,&accept_socket,www_body, context);
        else
@@ -1662,7 +1817,7 @@ static int sv_body(char *hostname, int s, unsigned char *context)
        SSL *con=NULL;
        BIO *sbio;
        struct timeval timeout;
-#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE)
+#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE) || defined(OPENSSL_SYS_BEOS_R5)
        struct timeval tv;
 #else
        struct timeval *timeoutp;
@@ -1714,13 +1869,18 @@ static int sv_body(char *hostname, int s, unsigned char *context)
                                                 strlen((char *)context));
        }
        SSL_clear(con);
+#if 0
+#ifdef TLSEXT_TYPE_opaque_prf_input
+       SSL_set_tlsext_opaque_prf_input(con, "Test server", 11);
+#endif
+#endif
 
        if (SSL_version(con) == DTLS1_VERSION)
                {
 
                sbio=BIO_new_dgram(s,BIO_NOCLOSE);
 
-               if ( enable_timeouts)
+               if (enable_timeouts)
                        {
                        timeout.tv_sec = 0;
                        timeout.tv_usec = DGRAM_RCV_TIMEOUT;
@@ -1731,7 +1891,6 @@ static int sv_body(char *hostname, int s, unsigned char *context)
                        BIO_ctrl(sbio, BIO_CTRL_DGRAM_SET_SEND_TIMEOUT, 0, &timeout);
                        }
 
-               
                if (socket_mtu > 28)
                        {
                        SSL_set_options(con, SSL_OP_NO_QUERY_MTU);
@@ -1794,10 +1953,10 @@ static int sv_body(char *hostname, int s, unsigned char *context)
                if (!read_from_sslcon)
                        {
                        FD_ZERO(&readfds);
-#if !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_NETWARE)
-                       FD_SET(fileno(stdin),&readfds);
+#if !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_NETWARE) && !defined(OPENSSL_SYS_BEOS_R5)
+                       openssl_fdset(fileno(stdin),&readfds);
 #endif
-                       FD_SET(s,&readfds);
+                       openssl_fdset(s,&readfds);
                        /* Note: under VMS with SOCKETSHR the second parameter is
                         * currently of type (int *) whereas under other systems
                         * it is (void *) if you don't have a cast it will choke
@@ -1816,6 +1975,17 @@ static int sv_body(char *hostname, int s, unsigned char *context)
                        if((i < 0) || (!i && !_kbhit() ) )continue;
                        if(_kbhit())
                                read_from_terminal = 1;
+#elif defined(OPENSSL_SYS_BEOS_R5)
+                       /* Under BeOS-R5 the situation is similar to DOS */
+                       tv.tv_sec = 1;
+                       tv.tv_usec = 0;
+                       (void)fcntl(fileno(stdin), F_SETFL, O_NONBLOCK);
+                       i=select(width,(void *)&readfds,NULL,NULL,&tv);
+                       if ((i < 0) || (!i && read(fileno(stdin), buf, 0) < 0))
+                               continue;
+                       if (read(fileno(stdin), buf, 0) >= 0)
+                               read_from_terminal = 1;
+                       (void)fcntl(fileno(stdin), F_SETFL, 0);
 #else
                        if ((SSL_version(con) == DTLS1_VERSION) &&
                                DTLSv1_get_timeout(con, &timeout))
@@ -1843,7 +2013,7 @@ static int sv_body(char *hostname, int s, unsigned char *context)
                                {
                                int j, lf_num;
 
-                               i=read(fileno(stdin), buf, bufsize/2);
+                               i=raw_read_stdin(buf, bufsize/2);
                                lf_num = 0;
                                /* both loops are skipped when i <= 0 */
                                for (j = 0; j < i; j++)
@@ -1862,7 +2032,7 @@ static int sv_body(char *hostname, int s, unsigned char *context)
                                assert(lf_num == 0);
                                }
                        else
-                               i=read(fileno(stdin),buf,bufsize);
+                               i=raw_read_stdin(buf,bufsize);
                        if (!s_quiet)
                                {
                                if ((i <= 0) || (buf[0] == 'Q'))
@@ -1882,6 +2052,7 @@ static int sv_body(char *hostname, int s, unsigned char *context)
                                        ret= -11;*/
                                        goto err;
                                        }
+
                                if ((buf[0] == 'r') && 
                                        ((buf[1] == '\n') || (buf[1] == '\r')))
                                        {
@@ -1978,7 +2149,7 @@ again:
 #ifdef CHARSET_EBCDIC
                                        ascii2ebcdic(buf,buf,i);
 #endif
-                                       write(fileno(stdout),buf,
+                                       raw_write_stdout(buf,
                                                (unsigned int)i);
                                        if (SSL_pending(con)) goto again;
                                        break;
@@ -2002,13 +2173,16 @@ again:
                        }
                }
 err:
-       BIO_printf(bio_s_out,"shutting down SSL\n");
+       if (con != NULL)
+               {
+               BIO_printf(bio_s_out,"shutting down SSL\n");
 #if 1
-       SSL_set_shutdown(con,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
+               SSL_set_shutdown(con,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
 #else
-       SSL_shutdown(con);
+               SSL_shutdown(con);
 #endif
-       if (con != NULL) SSL_free(con);
+               SSL_free(con);
+               }
        BIO_printf(bio_s_out,"CONNECTION CLOSED\n");
        if (buf != NULL)
                {
@@ -2036,12 +2210,11 @@ static int init_ssl_connection(SSL *con)
        X509 *peer;
        long verify_error;
        MS_STATIC char buf[BUFSIZ];
-#ifndef OPENSSL_NO_TLSEXT
+#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
        const unsigned char *next_proto_neg;
        unsigned next_proto_neg_len;
 #endif
 
-again:
        if ((i=SSL_accept(con)) <= 0)
                {
                if (BIO_sock_should_retry(i))
@@ -2050,12 +2223,6 @@ again:
                        return(1);
                        }
 
-               if (SSL_get_error(con, i) == SSL_ERROR_SERVER_RANDOM_VALIDATION_PENDING)
-                       {
-                       SSL_set_suggested_server_random_validity(con, 1);
-                       goto again;
-                       }
-
                BIO_printf(bio_err,"ERROR\n");
                verify_error=SSL_get_verify_result(con);
                if (verify_error != X509_V_OK)
@@ -2086,13 +2253,14 @@ again:
                BIO_printf(bio_s_out,"Shared ciphers:%s\n",buf);
        str=SSL_CIPHER_get_name(SSL_get_current_cipher(con));
        BIO_printf(bio_s_out,"CIPHER is %s\n",(str != NULL)?str:"(NONE)");
-#ifndef OPENSSL_NO_TLSEXT
+#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
        SSL_get0_next_proto_negotiated(con, &next_proto_neg, &next_proto_neg_len);
-       if (next_proto_neg) {
+       if (next_proto_neg)
+               {
                BIO_printf(bio_s_out,"NEXTPROTO is ");
                BIO_write(bio_s_out, next_proto_neg, next_proto_neg_len);
                BIO_printf(bio_s_out, "\n");
-       }
+               }
 #endif
        if (con->hit) BIO_printf(bio_s_out,"Reused session-id\n");
        if (SSL_ctrl(con,SSL_CTRL_GET_FLAGS,0,NULL) &
@@ -2151,13 +2319,9 @@ static int www_body(char *hostname, int s, unsigned char *context)
        char *buf=NULL;
        int ret=1;
        int i,j,k,dot;
-       struct stat st_buf;
        SSL *con;
-       SSL_CIPHER *c;
+       const SSL_CIPHER *c;
        BIO *io,*ssl_bio,*sbio;
-#ifdef RENEG
-       long total_bytes;
-#endif
 
        buf=OPENSSL_malloc(bufsize);
        if (buf == NULL) return(0);
@@ -2242,9 +2406,6 @@ static int www_body(char *hostname, int s, unsigned char *context)
                        case SSL_ERROR_WANT_READ:
                        case SSL_ERROR_WANT_X509_LOOKUP:
                                continue;
-                       case SSL_ERROR_SERVER_RANDOM_VALIDATION_PENDING:
-                               SSL_set_suggested_server_random_validity(con, 1);
-                               continue;
                        case SSL_ERROR_SYSCALL:
                        case SSL_ERROR_SSL:
                        case SSL_ERROR_ZERO_RETURN:
@@ -2427,14 +2588,7 @@ static int www_body(char *hostname, int s, unsigned char *context)
 #endif
 
                        /* if a directory, do the index thang */
-                       if (stat(p,&st_buf) < 0)
-                               {
-                               BIO_puts(io,text);
-                               BIO_printf(io,"Error accessing '%s'\r\n",p);
-                               ERR_print_errors(io);
-                               break;
-                               }
-                       if (S_ISDIR(st_buf.st_mode))
+                       if (app_isdir(p)>0)
                                {
 #if 0 /* must check buffer size */
                                strcat(p,"/index.html");
@@ -2467,9 +2621,6 @@ static int www_body(char *hostname, int s, unsigned char *context)
                                         BIO_puts(io,"HTTP/1.0 200 ok\r\nContent-type: text/plain\r\n\r\n");
                                 }
                        /* send the file */
-#ifdef RENEG
-                       total_bytes=0;
-#endif
                        for (;;)
                                {
                                i=BIO_read(file,buf,bufsize);
index 6d1d7d7..c08544a 100644 (file)
@@ -237,13 +237,11 @@ static int ssl_sock_init(void)
 int init_client(int *sock, char *host, int port, int type)
        {
        unsigned char ip[4];
-       short p=0;
 
        if (!host_ip(host,&(ip[0])))
                {
                return(0);
                }
-       if (p != 0) port=p;
        return(init_client_ip(sock,ip,port,type));
        }
 
@@ -272,7 +270,7 @@ static int init_client_ip(int *sock, unsigned char ip[4], int port, int type)
                        
        if (s == INVALID_SOCKET) { perror("socket"); return(0); }
 
-#ifndef OPENSSL_SYS_MPE
+#if defined(SO_KEEPALIVE) && !defined(OPENSSL_SYS_MPE)
        if (type == SOCK_STREAM)
                {
                i=0;
@@ -282,7 +280,7 @@ static int init_client_ip(int *sock, unsigned char ip[4], int port, int type)
 #endif
 
        if (connect(s,(struct sockaddr *)&them,sizeof(them)) == -1)
-               { close(s); perror("connect"); return(0); }
+               { closesocket(s); perror("connect"); return(0); }
        *sock=s;
        return(1);
        }
@@ -291,7 +289,7 @@ int do_server(int port, int type, int *ret, int (*cb)(char *hostname, int s, uns
        {
        int sock;
        char *name = NULL;
-       int accept_socket;
+       int accept_socket = 0;
        int i;
 
        if (!init_server(&accept_socket,port,type)) return(0);
index 904945e..b823c33 100644 (file)
 #include OPENSSL_UNISTD
 #endif
 
-#if !defined(OPENSSL_SYS_NETWARE) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VXWORKS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC))
-#define TIMES
-#endif
-
-#ifndef _IRIX
-#include <time.h>
-#endif
-#ifdef TIMES
-#include <sys/types.h>
-#include <sys/times.h>
-#endif
-
-/* Depending on the VMS version, the tms structure is perhaps defined.
-   The __TMS macro will show if it was.  If it wasn't defined, we should
-   undefine TIMES, since that tells the rest of the program how things
-   should be handled.                          -- Richard Levitte */
-#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
-#undef TIMES
-#endif
-
-#if !defined(TIMES) && !defined(OPENSSL_SYS_VXWORKS) && !defined(OPENSSL_SYS_NETWARE)
-#include <sys/timeb.h>
-#endif
-
-#if defined(sun) || defined(__ultrix)
-#define _POSIX_SOURCE
-#include <limits.h>
-#include <sys/param.h>
-#endif
-
-/* The following if from times(3) man page.  It may need to be changed
-*/
-#ifndef HZ
-# ifdef _SC_CLK_TCK
-#  define HZ ((double)sysconf(_SC_CLK_TCK))
-# else
-#  ifndef CLK_TCK
-#   ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
-#    define HZ 100.0
-#   else /* _BSD_CLK_TCK_ */
-#    define HZ ((double)_BSD_CLK_TCK_)
-#   endif
-#  else /* CLK_TCK */
-#   define HZ ((double)CLK_TCK)
-#  endif
-# endif
-#endif
-
 #undef PROG
 #define PROG s_time_main
 
@@ -177,7 +129,7 @@ static char *tm_cipher=NULL;
 static int tm_verify = SSL_VERIFY_NONE;
 static int maxTime = SECONDS;
 static SSL_CTX *tm_ctx=NULL;
-static SSL_METHOD *s_time_meth=NULL;
+static const SSL_METHOD *s_time_meth=NULL;
 static char *s_www_path=NULL;
 static long bytes_read=0; 
 static int st_bugs=0;
@@ -372,63 +324,8 @@ bad:
 
 static double tm_Time_F(int s)
        {
-       static double ret;
-#ifdef TIMES
-       static struct tms tstart,tend;
-
-       if(s == START) {
-               times(&tstart);
-               return(0);
-       } else {
-               times(&tend);
-               ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
-               return((ret == 0.0)?1e-6:ret);
+       return app_tminterval(s,1);
        }
-#elif defined(OPENSSL_SYS_NETWARE)
-    static clock_t tstart,tend;
-
-    if (s == START)
-    {
-        tstart=clock();
-        return(0);
-    }
-    else
-    {
-        tend=clock();
-        ret=(double)((double)(tend)-(double)(tstart));
-        return((ret < 0.001)?0.001:ret);
-    }
-#elif defined(OPENSSL_SYS_VXWORKS)
-        {
-       static unsigned long tick_start, tick_end;
-
-       if( s == START )
-               {
-               tick_start = tickGet();
-               return 0;
-               }
-       else
-               {
-               tick_end = tickGet();
-               ret = (double)(tick_end - tick_start) / (double)sysClkRateGet();
-               return((ret == 0.0)?1e-6:ret);
-               }
-        }
-#else /* !times() */
-       static struct timeb tstart,tend;
-       long i;
-
-       if(s == START) {
-               ftime(&tstart);
-               return(0);
-       } else {
-               ftime(&tend);
-               i=(long)tend.millitm-(long)tstart.millitm;
-               ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
-               return((ret == 0.0)?1e-6:ret);
-       }
-#endif
-}
 
 /***********************************************************************
  * MAIN - main processing area for client
@@ -704,7 +601,7 @@ static SSL *doConnection(SSL *scon)
                        i=SSL_get_fd(serverCon);
                        width=i+1;
                        FD_ZERO(&readfds);
-                       FD_SET(i,&readfds);
+                       openssl_fdset(i,&readfds);
                        /* Note: under VMS with SOCKETSHR the 2nd parameter
                         * is currently of type (int *) whereas under other
                         * systems it is (void *) if you don't have a cast it
index 75804b8..c583f8a 100644 (file)
@@ -73,11 +73,14 @@ static int save_certs(char *signerfile, STACK_OF(X509) *signers);
 static int smime_cb(int ok, X509_STORE_CTX *ctx);
 
 #define SMIME_OP       0x10
+#define SMIME_IP       0x20
+#define SMIME_SIGNERS  0x40
 #define SMIME_ENCRYPT  (1 | SMIME_OP)
-#define SMIME_DECRYPT  2
-#define SMIME_SIGN     (3 | SMIME_OP)
-#define SMIME_VERIFY   4
-#define SMIME_PK7OUT   5
+#define SMIME_DECRYPT  (2 | SMIME_IP)
+#define SMIME_SIGN     (3 | SMIME_OP | SMIME_SIGNERS)
+#define SMIME_VERIFY   (4 | SMIME_IP)
+#define SMIME_PK7OUT   (5 | SMIME_IP | SMIME_OP)
+#define SMIME_RESIGN   (6 | SMIME_IP | SMIME_OP | SMIME_SIGNERS)
 
 int MAIN(int, char **);
 
@@ -90,6 +93,7 @@ int MAIN(int argc, char **argv)
        const char *inmode = "r", *outmode = "w";
        char *infile = NULL, *outfile = NULL;
        char *signerfile = NULL, *recipfile = NULL;
+       STACK_OF(OPENSSL_STRING) *sksigners = NULL, *skkeys = NULL;
        char *certfile = NULL, *keyfile = NULL, *contfile=NULL;
        const EVP_CIPHER *cipher = NULL;
        PKCS7 *p7 = NULL;
@@ -105,6 +109,8 @@ int MAIN(int argc, char **argv)
        char *passargin = NULL, *passin = NULL;
        char *inrand = NULL;
        int need_rand = 0;
+       int indef = 0;
+       const EVP_MD *sign_md = NULL;
        int informat = FORMAT_SMIME, outformat = FORMAT_SMIME;
         int keyform = FORMAT_PEM;
 #ifndef OPENSSL_NO_ENGINE
@@ -135,6 +141,8 @@ int MAIN(int argc, char **argv)
                        operation = SMIME_DECRYPT;
                else if (!strcmp (*args, "-sign"))
                        operation = SMIME_SIGN;
+               else if (!strcmp (*args, "-resign"))
+                       operation = SMIME_RESIGN;
                else if (!strcmp (*args, "-verify"))
                        operation = SMIME_VERIFY;
                else if (!strcmp (*args, "-pk7out"))
@@ -193,205 +201,209 @@ int MAIN(int argc, char **argv)
                                flags |= PKCS7_BINARY;
                else if (!strcmp (*args, "-nosigs"))
                                flags |= PKCS7_NOSIGS;
+               else if (!strcmp (*args, "-stream"))
+                               indef = 1;
+               else if (!strcmp (*args, "-indef"))
+                               indef = 1;
+               else if (!strcmp (*args, "-noindef"))
+                               indef = 0;
                else if (!strcmp (*args, "-nooldmime"))
                                flags |= PKCS7_NOOLDMIMETYPE;
                else if (!strcmp (*args, "-crlfeol"))
                                flags |= PKCS7_CRLFEOL;
                else if (!strcmp(*args,"-rand"))
                        {
-                       if (args[1])
-                               {
-                               args++;
-                               inrand = *args;
-                               }
-                       else
-                               badarg = 1;
+                       if (!args[1])
+                               goto argerr;
+                       args++;
+                       inrand = *args;
                        need_rand = 1;
                        }
 #ifndef OPENSSL_NO_ENGINE
                else if (!strcmp(*args,"-engine"))
                        {
-                       if (args[1])
-                               {
-                               args++;
-                               engine = *args;
-                               }
-                       else badarg = 1;
+                       if (!args[1])
+                               goto argerr;
+                       engine = *++args;
                        }
 #endif
                else if (!strcmp(*args,"-passin"))
                        {
-                       if (args[1])
-                               {
-                               args++;
-                               passargin = *args;
-                               }
-                       else
-                               badarg = 1;
+                       if (!args[1])
+                               goto argerr;
+                       passargin = *++args;
                        }
                else if (!strcmp (*args, "-to"))
                        {
-                       if (args[1])
-                               {
-                               args++;
-                               to = *args;
-                               }
-                       else
-                               badarg = 1;
+                       if (!args[1])
+                               goto argerr;
+                       to = *++args;
                        }
                else if (!strcmp (*args, "-from"))
                        {
-                       if (args[1])
-                               {
-                               args++;
-                               from = *args;
-                               }
-                       else badarg = 1;
+                       if (!args[1])
+                               goto argerr;
+                       from = *++args;
                        }
                else if (!strcmp (*args, "-subject"))
                        {
-                       if (args[1])
-                               {
-                               args++;
-                               subject = *args;
-                               }
-                       else
-                               badarg = 1;
+                       if (!args[1])
+                               goto argerr;
+                       subject = *++args;
                        }
                else if (!strcmp (*args, "-signer"))
                        {
-                       if (args[1])
+                       if (!args[1])
+                               goto argerr;
+                       /* If previous -signer argument add signer to list */
+
+                       if (signerfile)
                                {
-                               args++;
-                               signerfile = *args;
+                               if (!sksigners)
+                                       sksigners = sk_OPENSSL_STRING_new_null();
+                               sk_OPENSSL_STRING_push(sksigners, signerfile);
+                               if (!keyfile)
+                                       keyfile = signerfile;
+                               if (!skkeys)
+                                       skkeys = sk_OPENSSL_STRING_new_null();
+                               sk_OPENSSL_STRING_push(skkeys, keyfile);
+                               keyfile = NULL;
                                }
-                       else
-                               badarg = 1;
+                       signerfile = *++args;
                        }
                else if (!strcmp (*args, "-recip"))
                        {
-                       if (args[1])
+                       if (!args[1])
+                               goto argerr;
+                       recipfile = *++args;
+                       }
+               else if (!strcmp (*args, "-md"))
+                       {
+                       if (!args[1])
+                               goto argerr;
+                       sign_md = EVP_get_digestbyname(*++args);
+                       if (sign_md == NULL)
                                {
-                               args++;
-                               recipfile = *args;
+                               BIO_printf(bio_err, "Unknown digest %s\n",
+                                                       *args);
+                               goto argerr;
                                }
-                       else badarg = 1;
                        }
                else if (!strcmp (*args, "-inkey"))
                        {
-                       if (args[1])
+                       if (!args[1])   
+                               goto argerr;
+                       /* If previous -inkey arument add signer to list */
+                       if (keyfile)
                                {
-                               args++;
-                               keyfile = *args;
+                               if (!signerfile)
+                                       {
+                                       BIO_puts(bio_err, "Illegal -inkey without -signer\n");
+                                       goto argerr;
+                                       }
+                               if (!sksigners)
+                                       sksigners = sk_OPENSSL_STRING_new_null();
+                               sk_OPENSSL_STRING_push(sksigners, signerfile);
+                               signerfile = NULL;
+                               if (!skkeys)
+                                       skkeys = sk_OPENSSL_STRING_new_null();
+                               sk_OPENSSL_STRING_push(skkeys, keyfile);
                                }
-                       else
-                               badarg = 1;
-               }
+                       keyfile = *++args;
+                       }
                else if (!strcmp (*args, "-keyform"))
                        {
-                       if (args[1])
-                               {
-                               args++;
-                               keyform = str2fmt(*args);
-                               }
-                       else
-                               badarg = 1;
+                       if (!args[1])
+                               goto argerr;
+                       keyform = str2fmt(*++args);
                        }
                else if (!strcmp (*args, "-certfile"))
                        {
-                       if (args[1])
-                               {
-                               args++;
-                               certfile = *args;
-                               }
-                       else
-                               badarg = 1;
+                       if (!args[1])
+                               goto argerr;
+                       certfile = *++args;
                        }
                else if (!strcmp (*args, "-CAfile"))
                        {
-                       if (args[1])
-                               {
-                               args++;
-                               CAfile = *args;
-                               }
-                       else
-                               badarg = 1;
+                       if (!args[1])
+                               goto argerr;
+                       CAfile = *++args;
                        }
                else if (!strcmp (*args, "-CApath"))
                        {
-                       if (args[1])
-                               {
-                               args++;
-                               CApath = *args;
-                               }
-                       else
-                               badarg = 1;
+                       if (!args[1])
+                               goto argerr;
+                       CApath = *++args;
                        }
                else if (!strcmp (*args, "-in"))
                        {
-                       if (args[1])
-                               {
-                               args++;
-                               infile = *args;
-                               }
-                       else
-                               badarg = 1;
+                       if (!args[1])
+                               goto argerr;
+                       infile = *++args;
                        }
                else if (!strcmp (*args, "-inform"))
                        {
-                       if (args[1])
-                               {
-                               args++;
-                               informat = str2fmt(*args);
-                               }
-                       else
-                               badarg = 1;
+                       if (!args[1])
+                               goto argerr;
+                       informat = str2fmt(*++args);
                        }
                else if (!strcmp (*args, "-outform"))
                        {
-                       if (args[1])
-                               {
-                               args++;
-                               outformat = str2fmt(*args);
-                               }
-                       else
-                               badarg = 1;
+                       if (!args[1])
+                               goto argerr;
+                       outformat = str2fmt(*++args);
                        }
                else if (!strcmp (*args, "-out"))
                        {
-                       if (args[1])
-                               {
-                               args++;
-                               outfile = *args;
-                               }
-                       else
-                               badarg = 1;
+                       if (!args[1])
+                               goto argerr;
+                       outfile = *++args;
                        }
                else if (!strcmp (*args, "-content"))
                        {
-                       if (args[1])
-                               {
-                               args++;
-                               contfile = *args;
-                               }
-                       else
-                               badarg = 1;
+                       if (!args[1])
+                               goto argerr;
+                       contfile = *++args;
                        }
                else if (args_verify(&args, NULL, &badarg, bio_err, &vpm))
                        continue;
-               else
+               else if ((cipher = EVP_get_cipherbyname(*args + 1)) == NULL)
                        badarg = 1;
                args++;
                }
 
+       if (!(operation & SMIME_SIGNERS) && (skkeys || sksigners))
+               {
+               BIO_puts(bio_err, "Multiple signers or keys not allowed\n");
+               goto argerr;
+               }
 
-       if (operation == SMIME_SIGN)
+       if (operation & SMIME_SIGNERS)
                {
-               if (!signerfile)
+               /* Check to see if any final signer needs to be appended */
+               if (keyfile && !signerfile)
+                       {
+                       BIO_puts(bio_err, "Illegal -inkey without -signer\n");
+                       goto argerr;
+                       }
+               if (signerfile)
+                       {
+                       if (!sksigners)
+                               sksigners = sk_OPENSSL_STRING_new_null();
+                       sk_OPENSSL_STRING_push(sksigners, signerfile);
+                       if (!skkeys)
+                               skkeys = sk_OPENSSL_STRING_new_null();
+                       if (!keyfile)
+                               keyfile = signerfile;
+                       sk_OPENSSL_STRING_push(skkeys, keyfile);
+                       }
+               if (!sksigners)
                        {
                        BIO_printf(bio_err, "No signer certificate specified\n");
                        badarg = 1;
                        }
+               signerfile = NULL;
+               keyfile = NULL;
                need_rand = 1;
                }
        else if (operation == SMIME_DECRYPT)
@@ -416,6 +428,7 @@ int MAIN(int argc, char **argv)
 
        if (badarg)
                {
+               argerr:
                BIO_printf (bio_err, "Usage smime [options] cert.pem ...\n");
                BIO_printf (bio_err, "where options are\n");
                BIO_printf (bio_err, "-encrypt       encrypt message\n");
@@ -499,13 +512,11 @@ int MAIN(int argc, char **argv)
 
        ret = 2;
 
-       if (operation != SMIME_SIGN)
+       if (!(operation & SMIME_SIGNERS))
                flags &= ~PKCS7_DETACHED;
 
        if (operation & SMIME_OP)
                {
-               if (flags & PKCS7_BINARY)
-                       inmode = "rb";
                if (outformat == FORMAT_ASN1)
                        outmode = "wb";
                }
@@ -513,9 +524,18 @@ int MAIN(int argc, char **argv)
                {
                if (flags & PKCS7_BINARY)
                        outmode = "wb";
+               }
+
+       if (operation & SMIME_IP)
+               {
                if (informat == FORMAT_ASN1)
                        inmode = "rb";
                }
+       else
+               {
+               if (flags & PKCS7_BINARY)
+                       inmode = "rb";
+               }
 
        if (operation == SMIME_ENCRYPT)
                {
@@ -545,26 +565,11 @@ int MAIN(int argc, char **argv)
                        }
                }
 
-       if (signerfile && (operation == SMIME_SIGN))
-               {
-               if (!(signer = load_cert(bio_err,signerfile,FORMAT_PEM, NULL,
-                       e, "signer certificate")))
-                       {
-#if 0                  /* An appropri message has already been printed */
-                       BIO_printf(bio_err, "Can't read signer certificate file %s\n", signerfile);
-#endif
-                       goto end;
-                       }
-               }
-
        if (certfile)
                {
                if (!(other = load_certs(bio_err,certfile,FORMAT_PEM, NULL,
                        e, "certificate file")))
                        {
-#if 0                  /* An appropriate message has already been printed */
-                       BIO_printf(bio_err, "Can't read certificate file %s\n", certfile);
-#endif
                        ERR_print_errors(bio_err);
                        goto end;
                        }
@@ -575,9 +580,6 @@ int MAIN(int argc, char **argv)
                if (!(recip = load_cert(bio_err,recipfile,FORMAT_PEM,NULL,
                        e, "recipient certificate file")))
                        {
-#if 0                  /* An appropriate message has alrady been printed */
-                       BIO_printf(bio_err, "Can't read recipient certificate file %s\n", recipfile);
-#endif
                        ERR_print_errors(bio_err);
                        goto end;
                        }
@@ -615,6 +617,36 @@ int MAIN(int argc, char **argv)
        else
                in = BIO_new_fp(stdin, BIO_NOCLOSE);
 
+       if (operation & SMIME_IP)
+               {
+               if (informat == FORMAT_SMIME) 
+                       p7 = SMIME_read_PKCS7(in, &indata);
+               else if (informat == FORMAT_PEM) 
+                       p7 = PEM_read_bio_PKCS7(in, NULL, NULL, NULL);
+               else if (informat == FORMAT_ASN1) 
+                       p7 = d2i_PKCS7_bio(in, NULL);
+               else
+                       {
+                       BIO_printf(bio_err, "Bad input format for PKCS#7 file\n");
+                       goto end;
+                       }
+
+               if (!p7)
+                       {
+                       BIO_printf(bio_err, "Error reading S/MIME message\n");
+                       goto end;
+                       }
+               if (contfile)
+                       {
+                       BIO_free(indata);
+                       if (!(indata = BIO_new_file(contfile, "rb")))
+                               {
+                               BIO_printf(bio_err, "Can't read content file %s\n", contfile);
+                               goto end;
+                               }
+                       }
+               }
+
        if (outfile)
                {
                if (!(out = BIO_new_file(outfile, outmode)))
@@ -639,7 +671,7 @@ int MAIN(int argc, char **argv)
                {
                if (!(store = setup_verify(bio_err, CAfile, CApath)))
                        goto end;
-               X509_STORE_set_verify_cb_func(store, smime_cb);
+               X509_STORE_set_verify_cb(store, smime_cb);
                if (vpm)
                        X509_STORE_set1_param(store, vpm);
                }
@@ -648,43 +680,58 @@ int MAIN(int argc, char **argv)
        ret = 3;
 
        if (operation == SMIME_ENCRYPT)
-               p7 = PKCS7_encrypt(encerts, in, cipher, flags);
-       else if (operation == SMIME_SIGN)
                {
-               /* If detached data and SMIME output enable partial
-                * signing.
-                */
-               if ((flags & PKCS7_DETACHED) && (outformat == FORMAT_SMIME))
+               if (indef)
                        flags |= PKCS7_STREAM;
-               p7 = PKCS7_sign(signer, key, other, in, flags);
+               p7 = PKCS7_encrypt(encerts, in, cipher, flags);
                }
-       else
+       else if (operation & SMIME_SIGNERS)
                {
-               if (informat == FORMAT_SMIME) 
-                       p7 = SMIME_read_PKCS7(in, &indata);
-               else if (informat == FORMAT_PEM) 
-                       p7 = PEM_read_bio_PKCS7(in, NULL, NULL, NULL);
-               else if (informat == FORMAT_ASN1) 
-                       p7 = d2i_PKCS7_bio(in, NULL);
-               else
+               int i;
+               /* If detached data content we only enable streaming if
+                * S/MIME output format.
+                */
+               if (operation == SMIME_SIGN)
                        {
-                       BIO_printf(bio_err, "Bad input format for PKCS#7 file\n");
-                       goto end;
+                       if (flags & PKCS7_DETACHED)
+                               {
+                               if (outformat == FORMAT_SMIME)
+                                       flags |= PKCS7_STREAM;
+                               }
+                       else if (indef)
+                               flags |= PKCS7_STREAM;
+                       flags |= PKCS7_PARTIAL;
+                       p7 = PKCS7_sign(NULL, NULL, other, in, flags);
+                       if (!p7)
+                               goto end;
                        }
-
-               if (!p7)
-                       {
-                       BIO_printf(bio_err, "Error reading S/MIME message\n");
-                       goto end;
+               else
+                       flags |= PKCS7_REUSE_DIGEST;
+               for (i = 0; i < sk_OPENSSL_STRING_num(sksigners); i++)
+                       {
+                       signerfile = sk_OPENSSL_STRING_value(sksigners, i);
+                       keyfile = sk_OPENSSL_STRING_value(skkeys, i);
+                       signer = load_cert(bio_err, signerfile,FORMAT_PEM, NULL,
+                                       e, "signer certificate");
+                       if (!signer)
+                               goto end;
+                       key = load_key(bio_err, keyfile, keyform, 0, passin, e,
+                              "signing key file");
+                       if (!key)
+                               goto end;
+                       if (!PKCS7_sign_add_signer(p7, signer, key,
+                                               sign_md, flags))
+                               goto end;
+                       X509_free(signer);
+                       signer = NULL;
+                       EVP_PKEY_free(key);
+                       key = NULL;
                        }
-               if (contfile)
+               /* If not streaming or resigning finalize structure */
+               if ((operation == SMIME_SIGN) && !(flags & PKCS7_STREAM))
                        {
-                       BIO_free(indata);
-                       if (!(indata = BIO_new_file(contfile, "rb")))
-                               {
-                               BIO_printf(bio_err, "Can't read content file %s\n", contfile);
+                       if (!PKCS7_final(p7, in, flags))
                                goto end;
-                               }
                        }
                }
 
@@ -734,11 +781,16 @@ int MAIN(int argc, char **argv)
                if (subject)
                        BIO_printf(out, "Subject: %s\n", subject);
                if (outformat == FORMAT_SMIME) 
-                       SMIME_write_PKCS7(out, p7, in, flags);
+                       {
+                       if (operation == SMIME_RESIGN)
+                               SMIME_write_PKCS7(out, p7, indata, flags);
+                       else
+                               SMIME_write_PKCS7(out, p7, in, flags);
+                       }
                else if (outformat == FORMAT_PEM) 
-                       PEM_write_bio_PKCS7(out,p7);
+                       PEM_write_bio_PKCS7_stream(out, p7, in, flags);
                else if (outformat == FORMAT_ASN1) 
-                       i2d_PKCS7_bio(out,p7);
+                       i2d_PKCS7_bio_stream(out,p7, in, flags);
                else
                        {
                        BIO_printf(bio_err, "Bad output format for PKCS#7 file\n");
@@ -754,6 +806,10 @@ end:
        sk_X509_pop_free(other, X509_free);
        if (vpm)
                X509_VERIFY_PARAM_free(vpm);
+       if (sksigners)
+               sk_OPENSSL_STRING_free(sksigners);
+       if (skkeys)
+               sk_OPENSSL_STRING_free(skkeys);
        X509_STORE_free(store);
        X509_free(cert);
        X509_free(recip);
index 84ce35d..b3c5442 100644 (file)
 #include <signal.h>
 #endif
 
-#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(OPENSSL_SYS_MACOSX)
-# define USE_TOD
-#elif !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VXWORKS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC))
-# define TIMES
-#endif
-#if !defined(_UNICOS) && !defined(__OpenBSD__) && !defined(sgi) && !defined(__FreeBSD__) && !(defined(__bsdi) || defined(__bsdi__)) && !defined(_AIX) && !defined(OPENSSL_SYS_MPE) && !defined(__NetBSD__) && !defined(OPENSSL_SYS_VXWORKS) /* FIXME */
-# define TIMEB
-#endif
-
-#if defined(OPENSSL_SYS_NETWARE)
-#undef TIMES
-#undef TIMEB
-#include <time.h>
-#endif
-
-#ifndef _IRIX
-# include <time.h>
-#endif
-#ifdef TIMES
-# include <sys/types.h>
-# include <sys/times.h>
-#endif
-#ifdef USE_TOD
-# include <sys/time.h>
-# include <sys/resource.h>
-#endif
-
-/* Depending on the VMS version, the tms structure is perhaps defined.
-   The __TMS macro will show if it was.  If it wasn't defined, we should
-   undefine TIMES, since that tells the rest of the program how things
-   should be handled.                          -- Richard Levitte */
-#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
-#undef TIMES
-#endif
-
-#ifdef TIMEB
-#include <sys/timeb.h>
-#endif
-
-#if !defined(TIMES) && !defined(TIMEB) && !defined(USE_TOD) && !defined(OPENSSL_SYS_VXWORKS) && !defined(OPENSSL_SYS_NETWARE)
-#error "It seems neither struct tms nor struct timeb is supported in this platform!"
-#endif
-
-#if defined(sun) || defined(__ultrix)
-#define _POSIX_SOURCE
-#include <limits.h>
-#include <sys/param.h>
+#ifdef _WIN32
+#include <windows.h>
 #endif
 
 #include <openssl/bn.h>
 #ifndef OPENSSL_NO_RIPEMD
 #include <openssl/ripemd.h>
 #endif
+#ifndef OPENSSL_NO_WHIRLPOOL
+#include <openssl/whrlpool.h>
+#endif
 #ifndef OPENSSL_NO_RC4
 #include <openssl/rc4.h>
 #endif
 #include <openssl/ecdh.h>
 #endif
 
-/*
- * The following "HZ" timing stuff should be sync'd up with the code in
- * crypto/tmdiff.[ch]. That appears to try to do the same job, though I think
- * this code is more up to date than libcrypto's so there may be features to
- * migrate over first. This is used in two places further down AFAICS. 
- * The point is that nothing in openssl actually *uses* that tmdiff stuff, so
- * either speed.c should be using it or it should go because it's obviously not
- * useful enough. Anyone want to do a janitorial job on this?
- */
-
-/* The following if from times(3) man page.  It may need to be changed */
-#ifndef HZ
-# if defined(_SC_CLK_TCK) \
-     && (!defined(OPENSSL_SYS_VMS) || __CTRL_VER >= 70000000)
-#  define HZ sysconf(_SC_CLK_TCK)
-# else
-#  ifndef CLK_TCK
-#   ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
-#    define HZ 100.0
-#   else /* _BSD_CLK_TCK_ */
-#    define HZ ((double)_BSD_CLK_TCK_)
-#   endif
-#  else /* CLK_TCK */
-#   define HZ ((double)CLK_TCK)
-#  endif
-# endif
-#endif
-
 #ifndef HAVE_FORK
 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
 #  define HAVE_FORK 0
 #endif
 
 #if HAVE_FORK
-# undef NO_FORK
+#undef NO_FORK
 #else
-# define NO_FORK
+#define NO_FORK
 #endif
 
 #undef BUFSIZE
 #define BUFSIZE        ((long)1024*8+1)
 int run=0;
 
-static char ftime_used = 0, times_used = 0, gettimeofday_used = 0, getrusage_used = 0;
 static int mr=0;
 static int usertime=1;
 
@@ -285,7 +214,7 @@ static void print_result(int alg,int run_no,int count,double time_used);
 static int do_multi(int multi);
 #endif
 
-#define ALGOR_NUM      28
+#define ALGOR_NUM      29
 #define SIZE_NUM       5
 #define RSA_NUM                4
 #define DSA_NUM                3
@@ -299,7 +228,7 @@ static const char *names[ALGOR_NUM]={
   "rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc",
   "aes-128 cbc","aes-192 cbc","aes-256 cbc",
   "camellia-128 cbc","camellia-192 cbc","camellia-256 cbc",
-  "evp","sha256","sha512",
+  "evp","sha256","sha512","whirlpool",
   "aes-128 ige","aes-192 ige","aes-256 ige"};
 static double results[ALGOR_NUM][SIZE_NUM];
 static int lengths[SIZE_NUM]={16,64,256,1024,8*1024};
@@ -342,141 +271,46 @@ static SIGRETTYPE sig_done(int sig)
 #define START  0
 #define STOP   1
 
-#if defined(OPENSSL_SYS_NETWARE)
+#if defined(_WIN32)
 
-   /* for NetWare the best we can do is use clock() which returns the
-    * time, in hundredths of a second, since the NLM began executing
-   */
-static double Time_F(int s)
-       {
-       double ret;
-
-   static clock_t tstart,tend;
-
-   if (s == START)
-   {
-      tstart=clock();
-      return(0);
-   }
-   else
-   {
-      tend=clock();
-      ret=(double)((double)(tend)-(double)(tstart));
-      return((ret < 0.001)?0.001:ret);
-   }
-   }
+#define SIGALRM
+static unsigned int lapse,schlock;
+static void alarm(unsigned int secs) { lapse = secs*1000; }
 
-#else
+static DWORD WINAPI sleepy(VOID *arg)
+       {
+       schlock = 1;
+       Sleep(lapse);
+       run = 0;
+       return 0;
+       }
 
 static double Time_F(int s)
        {
-       double ret;
-
-#ifdef USE_TOD
-       if(usertime)
-               {
-               static struct rusage tstart,tend;
-
-               getrusage_used = 1;
-               if (s == START)
-                       {
-                       getrusage(RUSAGE_SELF,&tstart);
-                       return(0);
-                       }
-               else
-                       {
-                       long i;
-
-                       getrusage(RUSAGE_SELF,&tend);
-                       i=(long)tend.ru_utime.tv_usec-(long)tstart.ru_utime.tv_usec;
-                       ret=((double)(tend.ru_utime.tv_sec-tstart.ru_utime.tv_sec))
-                         +((double)i)/1000000.0;
-                       return((ret < 0.001)?0.001:ret);
-                       }
-               }
-       else
-               {
-               static struct timeval tstart,tend;
-               long i;
-
-               gettimeofday_used = 1;
-               if (s == START)
-                       {
-                       gettimeofday(&tstart,NULL);
-                       return(0);
-                       }
-               else
-                       {
-                       gettimeofday(&tend,NULL);
-                       i=(long)tend.tv_usec-(long)tstart.tv_usec;
-                       ret=((double)(tend.tv_sec-tstart.tv_sec))+((double)i)/1000000.0;
-                       return((ret < 0.001)?0.001:ret);
-                       }
-               }
-#else  /* ndef USE_TOD */
-               
-# ifdef TIMES
-       if (usertime)
+       if (s == START)
                {
-               static struct tms tstart,tend;
-
-               times_used = 1;
-               if (s == START)
+               HANDLE  thr;
+               schlock = 0;
+               thr = CreateThread(NULL,4096,sleepy,NULL,0,NULL);
+               if (thr==NULL)
                        {
-                       times(&tstart);
-                       return(0);
-                       }
-               else
-                       {
-                       times(&tend);
-                       ret = HZ;
-                       ret=(double)(tend.tms_utime-tstart.tms_utime) / ret;
-                       return((ret < 1e-3)?1e-3:ret);
+                       DWORD ret=GetLastError();
+                       BIO_printf(bio_err,"unable to CreateThread (%d)",ret);
+                       ExitProcess(ret);
                        }
+               CloseHandle(thr);               /* detach the thread    */
+               while (!schlock) Sleep(0);      /* scheduler spinlock   */
                }
-# endif /* times() */
-# if defined(TIMES) && defined(TIMEB)
-       else
-# endif
-# ifdef OPENSSL_SYS_VXWORKS
-                {
-               static unsigned long tick_start, tick_end;
 
-               if( s == START )
-                       {
-                       tick_start = tickGet();
-                       return 0;
-                       }
-               else
-                       {
-                       tick_end = tickGet();
-                       ret = (double)(tick_end - tick_start) / (double)sysClkRateGet();
-                       return((ret < 0.001)?0.001:ret);
-                       }
-                }
-# elif defined(TIMEB)
-               {
-               static struct timeb tstart,tend;
-               long i;
+       return app_tminterval(s,usertime);
+       }
+#else
 
-               ftime_used = 1;
-               if (s == START)
-                       {
-                       ftime(&tstart);
-                       return(0);
-                       }
-               else
-                       {
-                       ftime(&tend);
-                       i=(long)tend.millitm-(long)tstart.millitm;
-                       ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
-                       return((ret < 0.001)?0.001:ret);
-                       }
-               }
-# endif
-#endif
+static double Time_F(int s)
+       {
+       return app_tminterval(s,usertime);
        }
-#endif /* if defined(OPENSSL_SYS_NETWARE) */
+#endif
 
 
 #ifndef OPENSSL_NO_ECDH
@@ -533,6 +367,9 @@ int MAIN(int argc, char **argv)
        unsigned char sha512[SHA512_DIGEST_LENGTH];
 #endif
 #endif
+#ifndef OPENSSL_NO_WHIRLPOOL
+       unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
+#endif
 #ifndef OPENSSL_NO_RIPEMD
        unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
 #endif
@@ -628,9 +465,10 @@ int MAIN(int argc, char **argv)
 #define D_EVP          22
 #define D_SHA256       23      
 #define D_SHA512       24
-#define D_IGE_128_AES   25
-#define D_IGE_192_AES   26
-#define D_IGE_256_AES   27
+#define D_WHIRLPOOL    25
+#define D_IGE_128_AES   26
+#define D_IGE_192_AES   27
+#define D_IGE_256_AES   28
        double d=0.0;
        long c[ALGOR_NUM][SIZE_NUM];
 #define        R_DSA_512       0
@@ -947,6 +785,10 @@ int MAIN(int argc, char **argv)
                else
 #endif
 #endif
+#ifndef OPENSSL_NO_WHIRLPOOL
+                       if (strcmp(*argv,"whirlpool") == 0) doit[D_WHIRLPOOL]=1;
+               else
+#endif
 #ifndef OPENSSL_NO_RIPEMD
                        if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;
                else
@@ -1158,12 +1000,16 @@ int MAIN(int argc, char **argv)
 #ifndef OPENSSL_NO_SHA512
                        BIO_printf(bio_err,"sha512   ");
 #endif
+#ifndef OPENSSL_NO_WHIRLPOOL
+                       BIO_printf(bio_err,"whirlpool");
+#endif
 #ifndef OPENSSL_NO_RIPEMD160
                        BIO_printf(bio_err,"rmd160");
 #endif
 #if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
     !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
-    !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160)
+    !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) || \
+    !defined(OPENSSL_NO_WHIRLPOOL)
                        BIO_printf(bio_err,"\n");
 #endif
 
@@ -1290,17 +1136,20 @@ int MAIN(int argc, char **argv)
                        rsa_doit[i]=1;
                for (i=0; i<DSA_NUM; i++)
                        dsa_doit[i]=1;
+#ifndef OPENSSL_NO_ECDSA
+               for (i=0; i<EC_NUM; i++)
+                       ecdsa_doit[i]=1;
+#endif
+#ifndef OPENSSL_NO_ECDH
+               for (i=0; i<EC_NUM; i++)
+                       ecdh_doit[i]=1;
+#endif
                }
        for (i=0; i<ALGOR_NUM; i++)
                if (doit[i]) pr_header++;
 
        if (usertime == 0 && !mr)
                BIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\n");
-       if (usertime <= 0 && !mr)
-               {
-               BIO_printf(bio_err,"To get the most accurate results, try to run this\n");
-               BIO_printf(bio_err,"program when this computer is idle.\n");
-               }
 
 #ifndef OPENSSL_NO_RSA
        for (i=0; i<RSA_NUM; i++)
@@ -1411,6 +1260,7 @@ int MAIN(int argc, char **argv)
        c[D_CBC_256_CML][0]=count;
        c[D_SHA256][0]=count;
        c[D_SHA512][0]=count;
+       c[D_WHIRLPOOL][0]=count;
        c[D_IGE_128_AES][0]=count;
        c[D_IGE_192_AES][0]=count;
        c[D_IGE_256_AES][0]=count;
@@ -1426,6 +1276,7 @@ int MAIN(int argc, char **argv)
                c[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i];
                c[D_SHA256][i]=c[D_SHA256][0]*4*lengths[0]/lengths[i];
                c[D_SHA512][i]=c[D_SHA512][0]*4*lengths[0]/lengths[i];
+               c[D_WHIRLPOOL][i]=c[D_WHIRLPOOL][0]*4*lengths[0]/lengths[i];
                }
        for (i=1; i<SIZE_NUM; i++)
                {
@@ -1609,7 +1460,9 @@ int MAIN(int argc, char **argv)
 #else
 #define COND(c)        (run)
 #define COUNT(d) (count)
+#ifndef _WIN32
        signal(SIGALRM,sig_done);
+#endif
 #endif /* SIGALRM */
 
 #ifndef OPENSSL_NO_MD2
@@ -1739,8 +1592,23 @@ int MAIN(int argc, char **argv)
                        }
                }
 #endif
+#endif
 
+#ifndef OPENSSL_NO_WHIRLPOOL
+       if (doit[D_WHIRLPOOL])
+               {
+               for (j=0; j<SIZE_NUM; j++)
+                       {
+                       print_message(names[D_WHIRLPOOL],c[D_WHIRLPOOL][j],lengths[j]);
+                       Time_F(START);
+                       for (count=0,run=1; COND(c[D_WHIRLPOOL][j]); count++)
+                               WHIRLPOOL(buf,lengths[j],whirlpool);
+                       d=Time_F(STOP);
+                       print_result(D_WHIRLPOOL,j,count,d);
+                       }
+               }
 #endif
+
 #ifndef OPENSSL_NO_RIPEMD
        if (doit[D_RMD160])
                {
@@ -1844,6 +1712,7 @@ int MAIN(int argc, char **argv)
                        }
                }
 
+#if 0 /* ANDROID */
        if (doit[D_IGE_128_AES])
                {
                for (j=0; j<SIZE_NUM; j++)
@@ -1886,6 +1755,9 @@ int MAIN(int argc, char **argv)
                        print_result(D_IGE_256_AES,j,count,d);
                        }
                }
+
+
+#endif
 #endif
 #ifndef OPENSSL_NO_CAMELLIA
        if (doit[D_CBC_128_CML])
@@ -2498,35 +2370,6 @@ show_res:
                printf("%s ",BF_options());
 #endif
                fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS));
-               printf("available timing options: ");
-#ifdef TIMES
-               printf("TIMES ");
-#endif
-#ifdef TIMEB
-               printf("TIMEB ");
-#endif
-#ifdef USE_TOD
-               printf("USE_TOD ");
-#endif
-#ifdef HZ
-#define as_string(s) (#s)
-               {
-               double dbl = HZ;
-               printf("HZ=%g", dbl);
-               }
-# ifdef _SC_CLK_TCK
-               printf(" [sysconf value]");
-# endif
-#endif
-               printf("\n");
-               printf("timing function used: %s%s%s%s%s%s%s\n",
-                      (ftime_used ? "ftime" : ""),
-                      (ftime_used + times_used > 1 ? "," : ""),
-                      (times_used ? "times" : ""),
-                      (ftime_used + times_used + gettimeofday_used > 1 ? "," : ""),
-                      (gettimeofday_used ? "gettimeofday" : ""),
-                      (ftime_used + times_used + gettimeofday_used + getrusage_used > 1 ? "," : ""),
-                      (getrusage_used ? "getrusage" : ""));
                }
 
        if (pr_header)
@@ -2783,6 +2626,7 @@ static int do_multi(int multi)
                        close(fd[1]);
                        mr=1;
                        usertime=0;
+                       free(fds);
                        return 0;
                        }
                printf("Forked child %d\n",n);
@@ -2861,6 +2705,7 @@ static int do_multi(int multi)
                                else
                                        rsa_results[k][1]=d;
                                }
+#ifndef OPENSSL_NO_DSA
                        else if(!strncmp(buf,"+F3:",4))
                                {
                                int k;
@@ -2882,6 +2727,7 @@ static int do_multi(int multi)
                                else
                                        dsa_results[k][1]=d;
                                }
+#endif
 #ifndef OPENSSL_NO_ECDSA
                        else if(!strncmp(buf,"+F4:",4))
                                {
@@ -2931,7 +2777,10 @@ static int do_multi(int multi)
                        else
                                fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n);
                        }
+
+               fclose(f);
                }
+       free(fds);
        return 1;
        }
 #endif
diff --git a/deps/openssl/openssl/apps/ts.c b/deps/openssl/openssl/apps/ts.c
new file mode 100644 (file)
index 0000000..5fa9f7f
--- /dev/null
@@ -0,0 +1,1147 @@
+/* apps/ts.c */
+/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
+ * project 2002.
+ */
+/* ====================================================================
+ * Copyright (c) 2001 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "apps.h"
+#include <openssl/bio.h>
+#include <openssl/err.h>
+#include <openssl/pem.h>
+#include <openssl/rand.h>
+#include <openssl/ts.h>
+#include <openssl/bn.h>
+
+#undef PROG
+#define PROG   ts_main
+
+/* Length of the nonce of the request in bits (must be a multiple of 8). */
+#define        NONCE_LENGTH            64
+
+/* Macro definitions for the configuration file. */
+#define        ENV_OID_FILE            "oid_file"
+
+/* Local function declarations. */
+
+static ASN1_OBJECT *txt2obj(const char *oid);
+static CONF *load_config_file(const char *configfile);
+
+/* Query related functions. */
+static int query_command(const char *data, char *digest,
+                        const EVP_MD *md, const char *policy, int no_nonce, 
+                        int cert, const char *in, const char *out, int text);
+static BIO *BIO_open_with_default(const char *file, const char *mode, 
+                                 FILE *default_fp);
+static TS_REQ *create_query(BIO *data_bio, char *digest, const EVP_MD *md,
+                           const char *policy, int no_nonce, int cert);
+static int create_digest(BIO *input, char *digest,
+                        const EVP_MD *md, unsigned char **md_value);
+static ASN1_INTEGER *create_nonce(int bits);
+
+/* Reply related functions. */
+static int reply_command(CONF *conf, char *section, char *engine, 
+                        char *queryfile, char *passin, char *inkey, 
+                        char *signer, char *chain, const char *policy, 
+                        char *in, int token_in, char *out, int token_out,
+                        int text);
+static TS_RESP *read_PKCS7(BIO *in_bio);
+static TS_RESP *create_response(CONF *conf, const char *section, char *engine,
+                               char *queryfile, char *passin, char *inkey,
+                               char *signer, char *chain, const char *policy);
+static ASN1_INTEGER * MS_CALLBACK serial_cb(TS_RESP_CTX *ctx, void *data);
+static ASN1_INTEGER *next_serial(const char *serialfile);
+static int save_ts_serial(const char *serialfile, ASN1_INTEGER *serial);
+
+/* Verify related functions. */
+static int verify_command(char *data, char *digest, char *queryfile,
+                         char *in, int token_in,
+                         char *ca_path, char *ca_file, char *untrusted);
+static TS_VERIFY_CTX *create_verify_ctx(char *data, char *digest, 
+                                       char *queryfile, 
+                                       char *ca_path, char *ca_file,
+                                       char *untrusted);
+static X509_STORE *create_cert_store(char *ca_path, char *ca_file);
+static int MS_CALLBACK verify_cb(int ok, X509_STORE_CTX *ctx);
+
+/* Main function definition. */
+int MAIN(int, char **);
+
+int MAIN(int argc, char **argv)
+       {
+       int ret = 1;
+       char *configfile = NULL;
+       char *section = NULL;
+       CONF *conf = NULL;
+       enum mode {
+       CMD_NONE, CMD_QUERY, CMD_REPLY, CMD_VERIFY 
+       } mode = CMD_NONE;
+       char *data = NULL;
+       char *digest = NULL;
+       const EVP_MD *md = NULL;
+       char *rnd = NULL;
+       char *policy = NULL;
+       int no_nonce = 0;
+       int cert = 0;
+       char *in = NULL;
+       char *out = NULL;
+       int text = 0;
+       char *queryfile = NULL;
+       char *passin = NULL;    /* Password source. */
+       char *password =NULL;   /* Password itself. */
+       char *inkey = NULL;
+       char *signer = NULL;
+       char *chain = NULL;
+       char *ca_path = NULL;
+       char *ca_file = NULL;
+       char *untrusted = NULL;
+       char *engine = NULL;
+       /* Input is ContentInfo instead of TimeStampResp. */
+       int token_in = 0;       
+       /* Output is ContentInfo instead of TimeStampResp. */
+       int token_out = 0;
+       int free_bio_err = 0;
+
+       ERR_load_crypto_strings();
+       apps_startup();
+
+       if (bio_err == NULL && (bio_err = BIO_new(BIO_s_file())) != NULL)
+               {
+               free_bio_err = 1;
+               BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);
+               }
+
+       if (!load_config(bio_err, NULL))
+               goto cleanup;
+
+       for (argc--, argv++; argc > 0; argc--, argv++)
+               {
+               if (strcmp(*argv, "-config") == 0)
+                       {
+                       if (argc-- < 1) goto usage;
+                       configfile = *++argv;
+                       }
+               else if (strcmp(*argv, "-section") == 0)
+                       {
+                       if (argc-- < 1) goto usage;
+                       section = *++argv;
+                       }
+               else if (strcmp(*argv, "-query") == 0)
+                       {
+                       if (mode != CMD_NONE) goto usage;
+                       mode = CMD_QUERY;
+                       }
+               else if (strcmp(*argv, "-data") == 0)
+                       {
+                       if (argc-- < 1) goto usage;
+                       data = *++argv;
+                       }
+               else if (strcmp(*argv, "-digest") == 0)
+                       {
+                       if (argc-- < 1) goto usage;
+                       digest = *++argv;
+                       }
+               else if (strcmp(*argv, "-rand") == 0)
+                       {
+                       if (argc-- < 1) goto usage;
+                       rnd = *++argv;
+                       }
+               else if (strcmp(*argv, "-policy") == 0)
+                       {
+                       if (argc-- < 1) goto usage;
+                       policy = *++argv;
+                       }
+               else if (strcmp(*argv, "-no_nonce") == 0)
+                       {
+                       no_nonce = 1;
+                       }
+               else if (strcmp(*argv, "-cert") == 0)
+                       {
+                       cert = 1;
+                       }
+               else if (strcmp(*argv, "-in") == 0)
+                       {
+                       if (argc-- < 1) goto usage;
+                       in = *++argv;
+                       }
+               else if (strcmp(*argv, "-token_in") == 0)
+                       {
+                       token_in = 1;
+                       }
+               else if (strcmp(*argv, "-out") == 0)
+                       {
+                       if (argc-- < 1) goto usage;
+                       out = *++argv;
+                       }
+               else if (strcmp(*argv, "-token_out") == 0)
+                       {
+                       token_out = 1;
+                       }
+               else if (strcmp(*argv, "-text") == 0)
+                       {
+                       text = 1;
+                       }
+               else if (strcmp(*argv, "-reply") == 0)
+                       {
+                       if (mode != CMD_NONE) goto usage;
+                       mode = CMD_REPLY;
+                       }
+               else if (strcmp(*argv, "-queryfile") == 0)
+                       {
+                       if (argc-- < 1) goto usage;
+                       queryfile = *++argv;
+                       }
+               else if (strcmp(*argv, "-passin") == 0)
+                       {
+                       if (argc-- < 1) goto usage;
+                       passin = *++argv;
+                       }
+               else if (strcmp(*argv, "-inkey") == 0)
+                       {
+                       if (argc-- < 1) goto usage;
+                       inkey = *++argv;
+                       }
+               else if (strcmp(*argv, "-signer") == 0)
+                       {
+                       if (argc-- < 1) goto usage;
+                       signer = *++argv;
+                       }
+               else if (strcmp(*argv, "-chain") == 0)
+                       {
+                       if (argc-- < 1) goto usage;
+                       chain = *++argv;
+                       }
+               else if (strcmp(*argv, "-verify") == 0)
+                       {
+                       if (mode != CMD_NONE) goto usage;
+                       mode = CMD_VERIFY;
+                       }
+               else if (strcmp(*argv, "-CApath") == 0)
+                       {
+                       if (argc-- < 1) goto usage;
+                       ca_path = *++argv;
+                       }
+               else if (strcmp(*argv, "-CAfile") == 0)
+                       {
+                       if (argc-- < 1) goto usage;
+                       ca_file = *++argv;
+                       }
+               else if (strcmp(*argv, "-untrusted") == 0)
+                       {
+                       if (argc-- < 1) goto usage;
+                       untrusted = *++argv;
+                       }
+               else if (strcmp(*argv, "-engine") == 0)
+                       {
+                       if (argc-- < 1) goto usage;
+                       engine = *++argv;
+                       }
+               else if ((md = EVP_get_digestbyname(*argv + 1)) != NULL)
+                       {
+                       /* empty. */
+                       }
+               else
+                       goto usage;
+               }
+       
+       /* Seed the random number generator if it is going to be used. */
+       if (mode == CMD_QUERY && !no_nonce)
+               {
+               if (!app_RAND_load_file(NULL, bio_err, 1) && rnd == NULL)
+                       BIO_printf(bio_err, "warning, not much extra random "
+                                  "data, consider using the -rand option\n");
+               if (rnd != NULL)
+                       BIO_printf(bio_err,"%ld semi-random bytes loaded\n",
+                                  app_RAND_load_files(rnd));
+               }
+
+       /* Get the password if required. */
+       if(mode == CMD_REPLY && passin &&
+          !app_passwd(bio_err, passin, NULL, &password, NULL))
+               {
+               BIO_printf(bio_err,"Error getting password.\n");
+               goto cleanup;
+               }
+
+       /* Check consistency of parameters and execute 
+          the appropriate function. */
+       switch (mode)
+               {
+       case CMD_NONE:
+               goto usage;
+       case CMD_QUERY:
+               /* Data file and message imprint cannot be specified
+                  at the same time. */
+               ret = data != NULL && digest != NULL;
+               if (ret) goto usage;
+               /* Load the config file for possible policy OIDs. */
+               conf = load_config_file(configfile);
+               ret = !query_command(data, digest, md, policy, no_nonce, cert,
+                                    in, out, text);
+               break;
+       case CMD_REPLY:
+               conf = load_config_file(configfile);
+               if (in == NULL)
+                       {
+                       ret = !(queryfile != NULL && conf != NULL && !token_in);
+                       if (ret) goto usage;
+                       }
+               else
+                       {
+                       /* 'in' and 'queryfile' are exclusive. */
+                       ret = !(queryfile == NULL);
+                       if (ret) goto usage;
+                       }
+
+               ret = !reply_command(conf, section, engine, queryfile, 
+                                    password, inkey, signer, chain, policy, 
+                                    in, token_in, out, token_out, text);
+               break;
+       case CMD_VERIFY:
+               ret = !(((queryfile && !data && !digest)
+                        || (!queryfile && data && !digest)
+                        || (!queryfile && !data && digest))
+                       && in != NULL);
+               if (ret) goto usage;
+
+               ret = !verify_command(data, digest, queryfile, in, token_in,
+                                     ca_path, ca_file, untrusted);
+               }
+
+       goto cleanup;
+
+ usage:
+       BIO_printf(bio_err, "usage:\n"
+                  "ts -query [-rand file%cfile%c...] [-config configfile] "
+                  "[-data file_to_hash] [-digest digest_bytes]"
+                  "[-md2|-md4|-md5|-sha|-sha1|-mdc2|-ripemd160] "
+                  "[-policy object_id] [-no_nonce] [-cert] "
+                  "[-in request.tsq] [-out request.tsq] [-text]\n",
+                  LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR);
+       BIO_printf(bio_err, "or\n"
+                  "ts -reply [-config configfile] [-section tsa_section] "
+                  "[-queryfile request.tsq] [-passin password] "
+                  "[-signer tsa_cert.pem] [-inkey private_key.pem] "
+                  "[-chain certs_file.pem] [-policy object_id] "
+                  "[-in response.tsr] [-token_in] "
+                  "[-out response.tsr] [-token_out] [-text] [-engine id]\n");
+       BIO_printf(bio_err, "or\n"
+                  "ts -verify [-data file_to_hash] [-digest digest_bytes] "
+                  "[-queryfile request.tsq] "
+                  "-in response.tsr [-token_in] "
+                  "-CApath ca_path -CAfile ca_file.pem "
+                  "-untrusted cert_file.pem\n");
+ cleanup:
+       /* Clean up. */
+       app_RAND_write_file(NULL, bio_err);
+       NCONF_free(conf);
+       OPENSSL_free(password);
+       OBJ_cleanup();
+       if (free_bio_err)
+               {
+               BIO_free_all(bio_err);
+               bio_err = NULL;
+               }
+
+       OPENSSL_EXIT(ret);
+       }
+
+/*
+ * Configuration file-related function definitions.
+ */
+
+static ASN1_OBJECT *txt2obj(const char *oid)
+       {
+       ASN1_OBJECT *oid_obj = NULL;
+
+       if (!(oid_obj = OBJ_txt2obj(oid, 0)))
+               BIO_printf(bio_err, "cannot convert %s to OID\n", oid);
+
+       return oid_obj;
+       }
+
+static CONF *load_config_file(const char *configfile)
+       {
+       CONF *conf = NULL;
+       long errorline = -1;
+
+       if (!configfile) configfile = getenv("OPENSSL_CONF");
+       if (!configfile) configfile = getenv("SSLEAY_CONF");
+
+       if (configfile &&
+           (!(conf = NCONF_new(NULL)) ||
+            NCONF_load(conf, configfile, &errorline) <= 0))
+               {
+               if (errorline <= 0)
+                       BIO_printf(bio_err, "error loading the config file "
+                                  "'%s'\n", configfile);
+               else
+                       BIO_printf(bio_err, "error on line %ld of config file "
+                                  "'%s'\n", errorline, configfile);
+               }
+
+       if (conf != NULL)
+               {
+               const char *p;
+
+               BIO_printf(bio_err,"Using configuration from %s\n", configfile);
+               p = NCONF_get_string(conf, NULL, ENV_OID_FILE);
+               if (p != NULL)
+                       {
+                       BIO *oid_bio = BIO_new_file(p, "r");
+                       if (!oid_bio) 
+                               ERR_print_errors(bio_err);
+                       else
+                               {
+                               OBJ_create_objects(oid_bio);
+                               BIO_free_all(oid_bio);
+                               }
+                       }
+               else
+                       ERR_clear_error();
+               if(!add_oid_section(bio_err, conf)) 
+                       ERR_print_errors(bio_err);
+               }
+       return conf;
+       }
+
+/*
+ * Query-related method definitions.
+ */
+
+static int query_command(const char *data, char *digest, const EVP_MD *md,
+                        const char *policy, int no_nonce, 
+                        int cert, const char *in, const char *out, int text)
+       {
+       int ret = 0;
+       TS_REQ *query = NULL;
+       BIO *in_bio = NULL;
+       BIO *data_bio = NULL;
+       BIO *out_bio = NULL;
+
+       /* Build query object either from file or from scratch. */
+       if (in != NULL)
+               {
+               if ((in_bio = BIO_new_file(in, "rb")) == NULL) goto end;
+               query = d2i_TS_REQ_bio(in_bio, NULL);
+               }
+       else
+               {
+               /* Open the file if no explicit digest bytes were specified. */
+               if (!digest 
+                   && !(data_bio = BIO_open_with_default(data, "rb", stdin)))
+                       goto end;
+               /* Creating the query object. */
+               query = create_query(data_bio, digest, md,
+                                    policy, no_nonce, cert);
+               /* Saving the random number generator state. */
+               }
+       if (query == NULL) goto end;
+
+       /* Write query either in ASN.1 or in text format. */
+       if ((out_bio = BIO_open_with_default(out, "wb", stdout)) == NULL)
+               goto end;
+       if (text)
+               {
+               /* Text output. */
+               if (!TS_REQ_print_bio(out_bio, query))
+                       goto end;
+               }
+       else
+               {
+               /* ASN.1 output. */
+               if (!i2d_TS_REQ_bio(out_bio, query))
+                       goto end;
+               }
+
+       ret = 1;
+
+ end:
+       ERR_print_errors(bio_err);
+
+       /* Clean up. */
+       BIO_free_all(in_bio);
+       BIO_free_all(data_bio);
+       BIO_free_all(out_bio);
+       TS_REQ_free(query);
+
+       return ret;
+       }
+
+static BIO *BIO_open_with_default(const char *file, const char *mode, 
+                                 FILE *default_fp)
+       {
+       return file == NULL ? 
+               BIO_new_fp(default_fp, BIO_NOCLOSE) 
+               : BIO_new_file(file, mode);
+       }
+
+static TS_REQ *create_query(BIO *data_bio, char *digest, const EVP_MD *md,
+                           const char *policy, int no_nonce, int cert)
+       {
+       int ret = 0;
+       TS_REQ *ts_req = NULL;
+       int len;
+       TS_MSG_IMPRINT *msg_imprint = NULL;
+       X509_ALGOR *algo = NULL;
+       unsigned char *data = NULL;
+       ASN1_OBJECT *policy_obj = NULL;
+       ASN1_INTEGER *nonce_asn1 = NULL;
+
+       /* Setting default message digest. */
+       if (!md && !(md = EVP_get_digestbyname("sha1"))) goto err;
+
+       /* Creating request object. */
+       if (!(ts_req = TS_REQ_new())) goto err;
+
+       /* Setting version. */
+       if (!TS_REQ_set_version(ts_req, 1)) goto err;
+
+       /* Creating and adding MSG_IMPRINT object. */
+       if (!(msg_imprint = TS_MSG_IMPRINT_new())) goto err;
+
+       /* Adding algorithm. */
+       if (!(algo = X509_ALGOR_new())) goto err;
+       if (!(algo->algorithm = OBJ_nid2obj(EVP_MD_type(md)))) goto err;
+       if (!(algo->parameter = ASN1_TYPE_new())) goto err;
+       algo->parameter->type = V_ASN1_NULL;
+       if (!TS_MSG_IMPRINT_set_algo(msg_imprint, algo)) goto err;
+
+       /* Adding message digest. */
+       if ((len = create_digest(data_bio, digest, md, &data)) == 0)
+               goto err;
+       if (!TS_MSG_IMPRINT_set_msg(msg_imprint, data, len)) goto err;
+
+       if (!TS_REQ_set_msg_imprint(ts_req, msg_imprint)) goto err;
+       
+       /* Setting policy if requested. */
+       if (policy && !(policy_obj = txt2obj(policy))) goto err;
+       if (policy_obj && !TS_REQ_set_policy_id(ts_req, policy_obj)) goto err;
+
+       /* Setting nonce if requested. */
+       if (!no_nonce && !(nonce_asn1 = create_nonce(NONCE_LENGTH))) goto err;
+       if (nonce_asn1 && !TS_REQ_set_nonce(ts_req, nonce_asn1)) goto err;
+
+       /* Setting certificate request flag if requested. */
+       if (!TS_REQ_set_cert_req(ts_req, cert)) goto err;
+
+       ret = 1;
+ err:
+       if (!ret)
+               {
+               TS_REQ_free(ts_req);
+               ts_req = NULL;
+               BIO_printf(bio_err, "could not create query\n");
+               }
+       TS_MSG_IMPRINT_free(msg_imprint);
+       X509_ALGOR_free(algo);
+       OPENSSL_free(data);
+       ASN1_OBJECT_free(policy_obj);
+       ASN1_INTEGER_free(nonce_asn1);
+       return ts_req;
+       }
+
+static int create_digest(BIO *input, char *digest, const EVP_MD *md,
+                        unsigned char **md_value)
+       {
+       int md_value_len;
+
+       md_value_len = EVP_MD_size(md);
+       if (md_value_len < 0)
+           goto err;
+       if (input)
+               {
+               /* Digest must be computed from an input file. */
+               EVP_MD_CTX md_ctx;
+               unsigned char buffer[4096];
+               int length;
+
+               *md_value = OPENSSL_malloc(md_value_len);
+               if (*md_value == 0) goto err;
+
+               EVP_DigestInit(&md_ctx, md);
+               while ((length = BIO_read(input, buffer, sizeof(buffer))) > 0)
+                       {
+                       EVP_DigestUpdate(&md_ctx, buffer, length);
+                       }
+               EVP_DigestFinal(&md_ctx, *md_value, NULL);
+               }
+       else
+               {
+               /* Digest bytes are specified with digest. */
+               long digest_len;
+               *md_value = string_to_hex(digest, &digest_len);
+               if (!*md_value || md_value_len != digest_len)
+                       {
+                       OPENSSL_free(*md_value);
+                       *md_value = NULL;
+                       BIO_printf(bio_err, "bad digest, %d bytes "
+                                  "must be specified\n", md_value_len);
+                       goto err;
+                       }
+               }
+
+       return md_value_len;
+ err:
+       return 0;
+       }
+
+static ASN1_INTEGER *create_nonce(int bits)
+       {
+       unsigned char buf[20];
+       ASN1_INTEGER *nonce = NULL;
+       int len = (bits - 1) / 8 + 1;
+       int i;
+
+       /* Generating random byte sequence. */
+       if (len > (int)sizeof(buf)) goto err;
+       if (RAND_bytes(buf, len) <= 0) goto err;
+
+       /* Find the first non-zero byte and creating ASN1_INTEGER object. */
+       for (i = 0; i < len && !buf[i]; ++i);
+       if (!(nonce = ASN1_INTEGER_new())) goto err;
+       OPENSSL_free(nonce->data);
+       /* Allocate at least one byte. */
+       nonce->length = len - i;
+       if (!(nonce->data = OPENSSL_malloc(nonce->length + 1))) goto err;
+       memcpy(nonce->data, buf + i, nonce->length);
+
+       return nonce;
+ err:
+       BIO_printf(bio_err, "could not create nonce\n");
+       ASN1_INTEGER_free(nonce);
+       return NULL;
+       }
+/*
+ * Reply-related method definitions.
+ */
+
+static int reply_command(CONF *conf, char *section, char *engine, 
+                        char *queryfile, char *passin, char *inkey,
+                        char *signer, char *chain, const char *policy, 
+                        char *in, int token_in,
+                        char *out, int token_out, int text)
+       {
+       int ret = 0;
+       TS_RESP *response = NULL;
+       BIO *in_bio = NULL;
+       BIO *query_bio = NULL;
+       BIO *inkey_bio = NULL;
+       BIO *signer_bio = NULL;
+       BIO *out_bio = NULL;
+
+       /* Build response object either from response or query. */
+       if (in != NULL)
+               {
+               if ((in_bio = BIO_new_file(in, "rb")) == NULL) goto end;
+               if (token_in)
+                       {
+                       /* We have a ContentInfo (PKCS7) object, add
+                          'granted' status info around it. */
+                       response = read_PKCS7(in_bio);
+                       }
+               else
+                       {
+                       /* We have a ready-made TS_RESP object. */
+                       response = d2i_TS_RESP_bio(in_bio, NULL);
+                       }
+               }
+       else
+               {
+               response = create_response(conf, section, engine, queryfile,
+                                          passin, inkey, signer, chain,
+                                          policy);
+               if (response)
+                       BIO_printf(bio_err, "Response has been generated.\n");
+               else
+                       BIO_printf(bio_err, "Response is not generated.\n");
+               }
+       if (response == NULL) goto end;
+
+       /* Write response either in ASN.1 or text format. */
+       if ((out_bio = BIO_open_with_default(out, "wb", stdout)) == NULL)
+               goto end;
+       if (text)
+               {
+               /* Text output. */
+               if (token_out)
+                       {
+                       TS_TST_INFO *tst_info = TS_RESP_get_tst_info(response);
+                       if (!TS_TST_INFO_print_bio(out_bio, tst_info)) goto end;
+                       }
+               else
+                       {
+                       if (!TS_RESP_print_bio(out_bio, response)) goto end;
+                       }
+               }
+       else
+               {
+               /* ASN.1 DER output. */
+               if (token_out)
+                       {
+                       PKCS7 *token = TS_RESP_get_token(response);
+                       if (!i2d_PKCS7_bio(out_bio, token)) goto end;
+                       }
+               else
+                       {
+                       if (!i2d_TS_RESP_bio(out_bio, response)) goto end;
+                       }
+               }
+
+       ret = 1;
+
+ end:
+       ERR_print_errors(bio_err);
+
+       /* Clean up. */
+       BIO_free_all(in_bio);
+       BIO_free_all(query_bio);
+       BIO_free_all(inkey_bio);
+       BIO_free_all(signer_bio);
+       BIO_free_all(out_bio);
+       TS_RESP_free(response);
+
+       return ret;
+       }
+
+/* Reads a PKCS7 token and adds default 'granted' status info to it. */
+static TS_RESP *read_PKCS7(BIO *in_bio)
+       {
+       int ret = 0;
+       PKCS7 *token = NULL;
+       TS_TST_INFO *tst_info = NULL;
+       TS_RESP *resp = NULL;
+       TS_STATUS_INFO *si = NULL;
+
+       /* Read PKCS7 object and extract the signed time stamp info. */
+       if (!(token = d2i_PKCS7_bio(in_bio, NULL))) goto end;
+       if (!(tst_info = PKCS7_to_TS_TST_INFO(token))) goto end;
+
+       /* Creating response object. */
+       if (!(resp = TS_RESP_new())) goto end;
+
+       /* Create granted status info. */
+       if (!(si = TS_STATUS_INFO_new())) goto end;
+       if (!(ASN1_INTEGER_set(si->status, TS_STATUS_GRANTED))) goto end;
+       if (!TS_RESP_set_status_info(resp, si)) goto end;
+
+       /* Setting encapsulated token. */
+       TS_RESP_set_tst_info(resp, token, tst_info);
+       token = NULL;           /* Ownership is lost. */
+       tst_info = NULL;        /* Ownership is lost. */
+
+       ret = 1;
+ end:
+       PKCS7_free(token);
+       TS_TST_INFO_free(tst_info);
+       if (!ret)
+               {
+               TS_RESP_free(resp);
+               resp = NULL;
+               }
+       TS_STATUS_INFO_free(si);
+       return resp;
+       }
+
+static TS_RESP *create_response(CONF *conf, const char *section, char *engine, 
+                               char *queryfile, char *passin, char *inkey,
+                               char *signer, char *chain, const char *policy)
+       {
+       int ret = 0;
+       TS_RESP *response = NULL;
+       BIO *query_bio = NULL;
+       TS_RESP_CTX *resp_ctx = NULL;
+
+       if (!(query_bio = BIO_new_file(queryfile, "rb")))
+               goto end;
+
+       /* Getting TSA configuration section. */
+       if (!(section = TS_CONF_get_tsa_section(conf, section)))
+               goto end;
+
+       /* Setting up response generation context. */
+       if (!(resp_ctx = TS_RESP_CTX_new())) goto end;
+
+       /* Setting serial number provider callback. */
+       if (!TS_CONF_set_serial(conf, section, serial_cb, resp_ctx)) goto end;
+#ifndef OPENSSL_NO_ENGINE
+       /* Setting default OpenSSL engine. */
+       if (!TS_CONF_set_crypto_device(conf, section, engine)) goto end;
+#endif
+
+       /* Setting TSA signer certificate. */
+       if (!TS_CONF_set_signer_cert(conf, section, signer, resp_ctx)) goto end;
+
+       /* Setting TSA signer certificate chain. */
+       if (!TS_CONF_set_certs(conf, section, chain, resp_ctx)) goto end;
+
+       /* Setting TSA signer private key. */
+       if (!TS_CONF_set_signer_key(conf, section, inkey, passin, resp_ctx))
+               goto end;
+
+       /* Setting default policy OID. */
+       if (!TS_CONF_set_def_policy(conf, section, policy, resp_ctx)) goto end;
+
+       /* Setting acceptable policy OIDs. */
+       if (!TS_CONF_set_policies(conf, section, resp_ctx)) goto end;
+
+       /* Setting the acceptable one-way hash algorithms. */
+       if (!TS_CONF_set_digests(conf, section, resp_ctx)) goto end;
+
+       /* Setting guaranteed time stamp accuracy. */
+       if (!TS_CONF_set_accuracy(conf, section, resp_ctx)) goto end;
+
+       /* Setting the precision of the time. */
+       if (!TS_CONF_set_clock_precision_digits(conf, section, resp_ctx))
+               goto end;
+
+       /* Setting the ordering flaf if requested. */
+       if (!TS_CONF_set_ordering(conf, section, resp_ctx)) goto end;
+
+       /* Setting the TSA name required flag if requested. */
+       if (!TS_CONF_set_tsa_name(conf, section, resp_ctx)) goto end;
+
+       /* Setting the ESS cert id chain flag if requested. */
+       if (!TS_CONF_set_ess_cert_id_chain(conf, section, resp_ctx)) goto end;
+
+       /* Creating the response. */
+       if (!(response = TS_RESP_create_response(resp_ctx, query_bio)))
+               goto end;
+
+       ret = 1;
+ end:
+       if (!ret) 
+               {
+               TS_RESP_free(response);
+               response = NULL;
+               }
+       TS_RESP_CTX_free(resp_ctx);
+       BIO_free_all(query_bio);
+
+       return response;
+       }
+
+static ASN1_INTEGER * MS_CALLBACK serial_cb(TS_RESP_CTX *ctx, void *data)
+       {
+       const char *serial_file = (const char *) data;
+       ASN1_INTEGER *serial = next_serial(serial_file);
+
+       if (!serial)
+               {
+               TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION,
+                                           "Error during serial number "
+                                           "generation.");
+               TS_RESP_CTX_add_failure_info(ctx,
+                                            TS_INFO_ADD_INFO_NOT_AVAILABLE);
+               }
+       else
+               save_ts_serial(serial_file, serial);
+
+       return serial;
+       }
+
+static ASN1_INTEGER *next_serial(const char *serialfile)
+       {
+       int ret = 0;
+       BIO *in = NULL;
+       ASN1_INTEGER *serial = NULL;
+       BIGNUM *bn = NULL;
+
+       if (!(serial = ASN1_INTEGER_new())) goto err;
+
+       if (!(in = BIO_new_file(serialfile, "r"))) 
+               {
+               ERR_clear_error();
+               BIO_printf(bio_err, "Warning: could not open file %s for "
+                          "reading, using serial number: 1\n", serialfile);
+               if (!ASN1_INTEGER_set(serial, 1)) goto err;
+               }
+       else
+               {
+               char buf[1024];
+               if (!a2i_ASN1_INTEGER(in, serial, buf, sizeof(buf)))
+                       {
+                       BIO_printf(bio_err, "unable to load number from %s\n",
+                                  serialfile);
+                       goto err;
+                       }
+               if (!(bn = ASN1_INTEGER_to_BN(serial, NULL))) goto err;
+               ASN1_INTEGER_free(serial);
+               serial = NULL;
+               if (!BN_add_word(bn, 1)) goto err;
+               if (!(serial = BN_to_ASN1_INTEGER(bn, NULL))) goto err;
+               }
+       ret = 1;
+ err:
+       if (!ret)
+               {
+               ASN1_INTEGER_free(serial);
+               serial = NULL;
+               }
+       BIO_free_all(in);
+       BN_free(bn);
+       return serial;
+       }
+
+static int save_ts_serial(const char *serialfile, ASN1_INTEGER *serial)
+       {
+       int ret = 0;
+       BIO *out = NULL;
+
+       if (!(out = BIO_new_file(serialfile, "w"))) goto err;
+       if (i2a_ASN1_INTEGER(out, serial) <= 0) goto err;
+       if (BIO_puts(out, "\n") <= 0) goto err;
+       ret = 1;
+ err:
+       if (!ret)
+               BIO_printf(bio_err, "could not save serial number to %s\n",
+                          serialfile);
+       BIO_free_all(out);
+       return ret;
+       }
+
+/*
+ * Verify-related method definitions.
+ */
+
+static int verify_command(char *data, char *digest, char *queryfile,
+                         char *in, int token_in,
+                         char *ca_path, char *ca_file, char *untrusted)
+       {
+       BIO *in_bio = NULL;
+       PKCS7 *token = NULL;
+       TS_RESP *response = NULL;
+       TS_VERIFY_CTX *verify_ctx = NULL;
+       int ret = 0;
+
+       /* Decode the token (PKCS7) or response (TS_RESP) files. */
+       if (!(in_bio = BIO_new_file(in, "rb"))) goto end;
+       if (token_in)
+               {
+               if (!(token = d2i_PKCS7_bio(in_bio, NULL))) goto end;
+               }
+       else
+               {
+               if (!(response = d2i_TS_RESP_bio(in_bio, NULL))) goto end;
+               }
+
+       if (!(verify_ctx = create_verify_ctx(data, digest, queryfile, 
+                                            ca_path, ca_file, untrusted)))
+               goto end;
+
+       /* Checking the token or response against the request. */
+       ret = token_in ?
+               TS_RESP_verify_token(verify_ctx, token) :
+               TS_RESP_verify_response(verify_ctx, response);
+
+ end:
+       printf("Verification: ");
+       if (ret)
+               printf("OK\n");
+       else
+               {
+               printf("FAILED\n");
+               /* Print errors, if there are any. */
+               ERR_print_errors(bio_err);
+               }
+       
+       /* Clean up. */
+       BIO_free_all(in_bio);
+       PKCS7_free(token);
+       TS_RESP_free(response);
+       TS_VERIFY_CTX_free(verify_ctx);
+       return ret;
+       }
+
+static TS_VERIFY_CTX *create_verify_ctx(char *data, char *digest, 
+                                       char *queryfile, 
+                                       char *ca_path, char *ca_file,
+                                       char *untrusted)
+       {
+       TS_VERIFY_CTX *ctx = NULL;
+       BIO *input = NULL;
+       TS_REQ *request = NULL;
+       int ret = 0;
+
+       if (data != NULL || digest != NULL)
+               {
+               if (!(ctx = TS_VERIFY_CTX_new())) goto err;
+               ctx->flags = TS_VFY_VERSION | TS_VFY_SIGNER;
+               if (data != NULL)
+                       {
+                       ctx->flags |= TS_VFY_DATA;
+                       if (!(ctx->data = BIO_new_file(data, "rb"))) goto err;
+                       }
+               else if (digest != NULL)
+                       {
+                       long imprint_len;
+                       ctx->flags |= TS_VFY_IMPRINT;
+                       if (!(ctx->imprint = string_to_hex(digest,
+                                                          &imprint_len)))
+                               {
+                               BIO_printf(bio_err, "invalid digest string\n");
+                               goto err;
+                               }
+                       ctx->imprint_len = imprint_len;
+                       }
+               
+               }
+       else if (queryfile != NULL)
+               {
+               /* The request has just to be read, decoded and converted to
+                  a verify context object. */
+               if (!(input = BIO_new_file(queryfile, "rb"))) goto err;
+               if (!(request = d2i_TS_REQ_bio(input, NULL))) goto err;
+               if (!(ctx = TS_REQ_to_TS_VERIFY_CTX(request, NULL))) goto err;
+               }
+       else
+               return NULL;
+
+       /* Add the signature verification flag and arguments. */
+       ctx->flags |= TS_VFY_SIGNATURE;
+
+       /* Initialising the X509_STORE object. */
+       if (!(ctx->store = create_cert_store(ca_path, ca_file))) goto err;
+
+       /* Loading untrusted certificates. */
+       if (untrusted && !(ctx->certs = TS_CONF_load_certs(untrusted))) 
+               goto err;
+
+       ret = 1;
+ err:
+       if (!ret)
+               {
+               TS_VERIFY_CTX_free(ctx);
+               ctx = NULL;
+               }
+       BIO_free_all(input);
+       TS_REQ_free(request);
+       return ctx;
+       }
+
+static X509_STORE *create_cert_store(char *ca_path, char *ca_file)
+       {
+       X509_STORE *cert_ctx = NULL;
+       X509_LOOKUP *lookup = NULL;
+       int i;
+
+       /* Creating the X509_STORE object. */
+       cert_ctx = X509_STORE_new();
+
+       /* Setting the callback for certificate chain verification. */
+       X509_STORE_set_verify_cb(cert_ctx, verify_cb);
+
+       /* Adding a trusted certificate directory source. */
+       if (ca_path)
+               {
+               lookup = X509_STORE_add_lookup(cert_ctx,
+                                              X509_LOOKUP_hash_dir());
+               if (lookup == NULL)
+                       {
+                       BIO_printf(bio_err, "memory allocation failure\n");
+                       goto err;
+                       }
+               i = X509_LOOKUP_add_dir(lookup, ca_path, X509_FILETYPE_PEM);
+               if (!i)
+                       {
+                       BIO_printf(bio_err, "Error loading directory %s\n",
+                                  ca_path);
+                       goto err;
+                       }
+               }
+
+       /* Adding a trusted certificate file source. */
+       if (ca_file)
+               {
+               lookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_file());
+               if (lookup == NULL)
+                       {
+                       BIO_printf(bio_err, "memory allocation failure\n");
+                       goto err;
+                       }
+               i = X509_LOOKUP_load_file(lookup, ca_file, X509_FILETYPE_PEM);
+               if (!i)
+                       {
+                       BIO_printf(bio_err, "Error loading file %s\n", ca_file);
+                       goto err;
+                       }
+               }
+
+       return cert_ctx;
+ err:
+       X509_STORE_free(cert_ctx);
+       return NULL;
+       }
+
+static int MS_CALLBACK verify_cb(int ok, X509_STORE_CTX *ctx)
+       {
+       /*
+       char buf[256];
+
+       if (!ok)
+               {
+               X509_NAME_oneline(X509_get_subject_name(ctx->current_cert),
+                                 buf, sizeof(buf));
+               printf("%s\n", buf);
+               printf("error %d at %d depth lookup: %s\n",
+                      ctx->error, ctx->error_depth,
+                       X509_verify_cert_error_string(ctx->error));
+               }
+       */
+
+       return ok;
+       }
diff --git a/deps/openssl/openssl/apps/tsget b/deps/openssl/openssl/apps/tsget
new file mode 100644 (file)
index 0000000..0d54e9f
--- /dev/null
@@ -0,0 +1,196 @@
+#!/usr/bin/perl -w
+# Written by Zoltan Glozik <zglozik@stones.com>.
+# Copyright (c) 2002 The OpenTSA Project.  All rights reserved.
+$::version = '$Id: tsget,v 1.1.2.2 2009/09/07 17:57:02 steve Exp $';
+
+use strict;
+use IO::Handle;
+use Getopt::Std;
+use File::Basename;
+use WWW::Curl::Easy;
+
+use vars qw(%options);
+
+# Callback for reading the body.
+sub read_body {
+    my ($maxlength, $state) = @_;
+    my $return_data = "";
+    my $data_len = length ${$state->{data}};
+    if ($state->{bytes} < $data_len) {
+       $data_len = $data_len - $state->{bytes};
+       $data_len = $maxlength if $data_len > $maxlength;
+       $return_data = substr ${$state->{data}}, $state->{bytes}, $data_len;
+       $state->{bytes} += $data_len;
+    }
+    return $return_data;
+}
+
+# Callback for writing the body into a variable.
+sub write_body {
+    my ($data, $pointer) = @_;
+    ${$pointer} .= $data;
+    return length($data);
+}
+
+# Initialise a new Curl object.
+sub create_curl {
+    my $url = shift;
+
+    # Create Curl object.
+    my $curl = WWW::Curl::Easy::new();
+
+    # Error-handling related options.
+    $curl->setopt(CURLOPT_VERBOSE, 1) if $options{d};
+    $curl->setopt(CURLOPT_FAILONERROR, 1);
+    $curl->setopt(CURLOPT_USERAGENT, "OpenTSA tsget.pl/" . (split / /, $::version)[2]);
+
+    # Options for POST method.
+    $curl->setopt(CURLOPT_UPLOAD, 1);
+    $curl->setopt(CURLOPT_CUSTOMREQUEST, "POST");
+    $curl->setopt(CURLOPT_HTTPHEADER,
+               ["Content-Type: application/timestamp-query",
+               "Accept: application/timestamp-reply,application/timestamp-response"]);
+    $curl->setopt(CURLOPT_READFUNCTION, \&read_body);
+    $curl->setopt(CURLOPT_HEADERFUNCTION, sub { return length($_[0]); });
+
+    # Options for getting the result.
+    $curl->setopt(CURLOPT_WRITEFUNCTION, \&write_body);
+
+    # SSL related options.
+    $curl->setopt(CURLOPT_SSLKEYTYPE, "PEM");
+    $curl->setopt(CURLOPT_SSL_VERIFYPEER, 1);  # Verify server's certificate.
+    $curl->setopt(CURLOPT_SSL_VERIFYHOST, 2);  # Check server's CN.
+    $curl->setopt(CURLOPT_SSLKEY, $options{k}) if defined($options{k});
+    $curl->setopt(CURLOPT_SSLKEYPASSWD, $options{p}) if defined($options{p});
+    $curl->setopt(CURLOPT_SSLCERT, $options{c}) if defined($options{c});
+    $curl->setopt(CURLOPT_CAINFO, $options{C}) if defined($options{C});
+    $curl->setopt(CURLOPT_CAPATH, $options{P}) if defined($options{P});
+    $curl->setopt(CURLOPT_RANDOM_FILE, $options{r}) if defined($options{r});
+    $curl->setopt(CURLOPT_EGDSOCKET, $options{g}) if defined($options{g});
+
+    # Setting destination.
+    $curl->setopt(CURLOPT_URL, $url);
+
+    return $curl;
+}
+
+# Send a request and returns the body back.
+sub get_timestamp {
+    my $curl = shift;
+    my $body = shift;
+    my $ts_body;
+    local $::error_buf;
+
+    # Error-handling related options.
+    $curl->setopt(CURLOPT_ERRORBUFFER, "::error_buf");
+
+    # Options for POST method.
+    $curl->setopt(CURLOPT_INFILE, {data => $body, bytes => 0});
+    $curl->setopt(CURLOPT_INFILESIZE, length(${$body}));
+
+    # Options for getting the result.
+    $curl->setopt(CURLOPT_FILE, \$ts_body);
+
+    # Send the request...
+    my $error_code = $curl->perform();
+    my $error_string;
+    if ($error_code != 0) {
+        my $http_code = $curl->getinfo(CURLINFO_HTTP_CODE);
+       $error_string = "could not get timestamp";
+       $error_string .= ", http code: $http_code" unless $http_code == 0;
+       $error_string .= ", curl code: $error_code";
+       $error_string .= " ($::error_buf)" if defined($::error_buf);
+    } else {
+        my $ct = $curl->getinfo(CURLINFO_CONTENT_TYPE);
+       if (lc($ct) ne "application/timestamp-reply"
+           && lc($ct) ne "application/timestamp-response") {
+           $error_string = "unexpected content type returned: $ct";
+        }
+    }
+    return ($ts_body, $error_string);
+
+}
+
+# Print usage information and exists.
+sub usage {
+
+    print STDERR "usage: $0 -h <server_url> [-e <extension>] [-o <output>] ";
+    print STDERR "[-v] [-d] [-k <private_key.pem>] [-p <key_password>] ";
+    print STDERR "[-c <client_cert.pem>] [-C <CA_certs.pem>] [-P <CA_path>] ";
+    print STDERR "[-r <file:file...>] [-g <EGD_socket>] [<request>]...\n";
+    exit 1;
+}
+
+# ----------------------------------------------------------------------
+#   Main program
+# ----------------------------------------------------------------------
+
+# Getting command-line options (default comes from TSGET environment variable).
+my $getopt_arg =  "h:e:o:vdk:p:c:C:P:r:g:";
+if (exists $ENV{TSGET}) {
+    my @old_argv = @ARGV;
+    @ARGV = split /\s+/, $ENV{TSGET};
+    getopts($getopt_arg, \%options) or usage;
+    @ARGV = @old_argv;
+}
+getopts($getopt_arg, \%options) or usage;
+
+# Checking argument consistency.
+if (!exists($options{h}) || (@ARGV == 0 && !exists($options{o}))
+    || (@ARGV > 1 && exists($options{o}))) {
+    print STDERR "Inconsistent command line options.\n";
+    usage;
+}
+# Setting defaults.
+@ARGV = ("-") unless @ARGV != 0;
+$options{e} = ".tsr" unless defined($options{e});
+
+# Processing requests.
+my $curl = create_curl $options{h};
+undef $/;   # For reading whole files.
+REQUEST: foreach (@ARGV) {
+    my $input = $_;
+    my ($base, $path) = fileparse($input, '\.[^.]*');
+    my $output_base = $base . $options{e};
+    my $output = defined($options{o}) ? $options{o} : $path . $output_base;
+
+    STDERR->printflush("$input: ") if $options{v};
+    # Read request.
+    my $body;
+    if ($input eq "-") {
+       # Read the request from STDIN;
+       $body = <STDIN>;
+    } else {
+       # Read the request from file.
+        open INPUT, "<" . $input
+           or warn("$input: could not open input file: $!\n"), next REQUEST;
+        $body = <INPUT>;
+        close INPUT
+           or warn("$input: could not close input file: $!\n"), next REQUEST;
+    }
+
+    # Send request.
+    STDERR->printflush("sending request") if $options{v};
+
+    my ($ts_body, $error) = get_timestamp $curl, \$body;
+    if (defined($error)) {
+       die "$input: fatal error: $error\n";
+    }
+    STDERR->printflush(", reply received") if $options{v};
+
+    # Write response.
+    if ($output eq "-") {
+       # Write to STDOUT.
+        print $ts_body;
+    } else {
+       # Write to file.
+        open OUTPUT, ">", $output
+           or warn("$output: could not open output file: $!\n"), next REQUEST;
+        print OUTPUT $ts_body;
+        close OUTPUT
+           or warn("$output: could not close output file: $!\n"), next REQUEST;
+    }
+    STDERR->printflush(", $output written.\n") if $options{v};
+}
+$curl->cleanup();
+WWW::Curl::Easy::global_cleanup();
index 20cc9e3..9163997 100644 (file)
@@ -70,8 +70,9 @@
 #define PROG   verify_main
 
 static int MS_CALLBACK cb(int ok, X509_STORE_CTX *ctx);
-static int check(X509_STORE *ctx, char *file, STACK_OF(X509) *uchain, STACK_OF(X509) *tchain, int purpose, ENGINE *e);
-static STACK_OF(X509) *load_untrusted(char *file);
+static int check(X509_STORE *ctx, char *file,
+               STACK_OF(X509) *uchain, STACK_OF(X509) *tchain,
+               STACK_OF(X509_CRL) *crls, ENGINE *e);
 static int v_verbose=0, vflags = 0;
 
 int MAIN(int, char **);
@@ -80,10 +81,10 @@ int MAIN(int argc, char **argv)
        {
        ENGINE *e = NULL;
        int i,ret=1, badarg = 0;
-       int purpose = -1;
        char *CApath=NULL,*CAfile=NULL;
-       char *untfile = NULL, *trustfile = NULL;
+       char *untfile = NULL, *trustfile = NULL, *crlfile = NULL;
        STACK_OF(X509) *untrusted = NULL, *trusted = NULL;
+       STACK_OF(X509_CRL) *crls = NULL;
        X509_STORE *cert_ctx=NULL;
        X509_LOOKUP *lookup=NULL;
        X509_VERIFY_PARAM *vpm = NULL;
@@ -93,7 +94,7 @@ int MAIN(int argc, char **argv)
 
        cert_ctx=X509_STORE_new();
        if (cert_ctx == NULL) goto end;
-       X509_STORE_set_verify_cb_func(cert_ctx,cb);
+       X509_STORE_set_verify_cb(cert_ctx,cb);
 
        ERR_load_crypto_strings();
 
@@ -139,6 +140,11 @@ int MAIN(int argc, char **argv)
                                if (argc-- < 1) goto end;
                                trustfile= *(++argv);
                                }
+                       else if (strcmp(*argv,"-CRLfile") == 0)
+                               {
+                               if (argc-- < 1) goto end;
+                               crlfile= *(++argv);
+                               }
 #ifndef OPENSSL_NO_ENGINE
                        else if (strcmp(*argv,"-engine") == 0)
                                {
@@ -192,26 +198,34 @@ int MAIN(int argc, char **argv)
 
        ERR_clear_error();
 
-       if(untfile) {
-               if(!(untrusted = load_untrusted(untfile))) {
-                       BIO_printf(bio_err, "Error loading untrusted file %s\n", untfile);
-                       ERR_print_errors(bio_err);
+       if(untfile)
+               {
+               untrusted = load_certs(bio_err, untfile, FORMAT_PEM,
+                                       NULL, e, "untrusted certificates");
+               if(!untrusted)
                        goto end;
                }
-       }
 
-       if(trustfile) {
-               if(!(trusted = load_untrusted(trustfile))) {
-                       BIO_printf(bio_err, "Error loading untrusted file %s\n", trustfile);
-                       ERR_print_errors(bio_err);
+       if(trustfile)
+               {
+               trusted = load_certs(bio_err, trustfile, FORMAT_PEM,
+                                       NULL, e, "trusted certificates");
+               if(!trusted)
                        goto end;
                }
-       }
 
-       if (argc < 1) check(cert_ctx, NULL, untrusted, trusted, purpose, e);
+       if(crlfile)
+               {
+               crls = load_crls(bio_err, crlfile, FORMAT_PEM,
+                                       NULL, e, "other CRLs");
+               if(!crls)
+                       goto end;
+               }
+
+       if (argc < 1) check(cert_ctx, NULL, untrusted, trusted, crls, e);
        else
                for (i=0; i<argc; i++)
-                       check(cert_ctx,argv[i], untrusted, trusted, purpose, e);
+                       check(cert_ctx,argv[i], untrusted, trusted, crls, e);
        ret=0;
 end:
        if (ret == 1) {
@@ -232,11 +246,14 @@ end:
        if (cert_ctx != NULL) X509_STORE_free(cert_ctx);
        sk_X509_pop_free(untrusted, X509_free);
        sk_X509_pop_free(trusted, X509_free);
+       sk_X509_CRL_pop_free(crls, X509_CRL_free);
        apps_shutdown();
        OPENSSL_EXIT(ret);
        }
 
-static int check(X509_STORE *ctx, char *file, STACK_OF(X509) *uchain, STACK_OF(X509) *tchain, int purpose, ENGINE *e)
+static int check(X509_STORE *ctx, char *file,
+               STACK_OF(X509) *uchain, STACK_OF(X509) *tchain,
+               STACK_OF(X509_CRL) *crls, ENGINE *e)
        {
        X509 *x=NULL;
        int i=0,ret=0;
@@ -260,7 +277,8 @@ static int check(X509_STORE *ctx, char *file, STACK_OF(X509) *uchain, STACK_OF(X
                goto end;
                }
        if(tchain) X509_STORE_CTX_trusted_stack(csc, tchain);
-       if(purpose >= 0) X509_STORE_CTX_set_purpose(csc, purpose);
+       if (crls)
+               X509_STORE_CTX_set0_crls(csc, crls);
        i=X509_verify_cert(csc);
        X509_STORE_CTX_free(csc);
 
@@ -278,90 +296,53 @@ end:
        return(ret);
        }
 
-static STACK_OF(X509) *load_untrusted(char *certfile)
-{
-       STACK_OF(X509_INFO) *sk=NULL;
-       STACK_OF(X509) *stack=NULL, *ret=NULL;
-       BIO *in=NULL;
-       X509_INFO *xi;
-
-       if(!(stack = sk_X509_new_null())) {
-               BIO_printf(bio_err,"memory allocation failure\n");
-               goto end;
-       }
-
-       if(!(in=BIO_new_file(certfile, "r"))) {
-               BIO_printf(bio_err,"error opening the file, %s\n",certfile);
-               goto end;
-       }
-
-       /* This loads from a file, a stack of x509/crl/pkey sets */
-       if(!(sk=PEM_X509_INFO_read_bio(in,NULL,NULL,NULL))) {
-               BIO_printf(bio_err,"error reading the file, %s\n",certfile);
-               goto end;
-       }
-
-       /* scan over it and pull out the certs */
-       while (sk_X509_INFO_num(sk))
-               {
-               xi=sk_X509_INFO_shift(sk);
-               if (xi->x509 != NULL)
-                       {
-                       sk_X509_push(stack,xi->x509);
-                       xi->x509=NULL;
-                       }
-               X509_INFO_free(xi);
-               }
-       if(!sk_X509_num(stack)) {
-               BIO_printf(bio_err,"no certificates in file, %s\n",certfile);
-               sk_X509_free(stack);
-               goto end;
-       }
-       ret=stack;
-end:
-       BIO_free(in);
-       sk_X509_INFO_free(sk);
-       return(ret);
-       }
-
 static int MS_CALLBACK cb(int ok, X509_STORE_CTX *ctx)
        {
-       char buf[256];
+       int cert_error = X509_STORE_CTX_get_error(ctx);
+       X509 *current_cert = X509_STORE_CTX_get_current_cert(ctx);
 
        if (!ok)
                {
-               if (ctx->current_cert)
+               if (current_cert)
+                       {
+                       X509_NAME_print_ex_fp(stdout,
+                               X509_get_subject_name(current_cert),
+                               0, XN_FLAG_ONELINE);
+                       printf("\n");
+                       }
+               printf("%serror %d at %d depth lookup:%s\n",
+                       X509_STORE_CTX_get0_parent_ctx(ctx) ? "[CRL path]" : "",
+                       cert_error,
+                       X509_STORE_CTX_get_error_depth(ctx),
+                       X509_verify_cert_error_string(cert_error));
+               switch(cert_error)
                        {
-                       X509_NAME_oneline(
-                               X509_get_subject_name(ctx->current_cert),buf,
-                               sizeof buf);
-                       printf("%s\n",buf);
+                       case X509_V_ERR_NO_EXPLICIT_POLICY:
+                               policies_print(NULL, ctx);
+                       case X509_V_ERR_CERT_HAS_EXPIRED:
+
+                       /* since we are just checking the certificates, it is
+                        * ok if they are self signed. But we should still warn
+                        * the user.
+                        */
+
+                       case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
+                       /* Continue after extension errors too */
+                       case X509_V_ERR_INVALID_CA:
+                       case X509_V_ERR_INVALID_NON_CA:
+                       case X509_V_ERR_PATH_LENGTH_EXCEEDED:
+                       case X509_V_ERR_INVALID_PURPOSE:
+                       case X509_V_ERR_CRL_HAS_EXPIRED:
+                       case X509_V_ERR_CRL_NOT_YET_VALID:
+                       case X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION:
+                       ok = 1;
+
                        }
-               printf("error %d at %d depth lookup:%s\n",ctx->error,
-                       ctx->error_depth,
-                       X509_verify_cert_error_string(ctx->error));
-               if (ctx->error == X509_V_ERR_CERT_HAS_EXPIRED) ok=1;
-               /* since we are just checking the certificates, it is
-                * ok if they are self signed. But we should still warn
-                * the user.
-                */
-               if (ctx->error == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) ok=1;
-               /* Continue after extension errors too */
-               if (ctx->error == X509_V_ERR_INVALID_CA) ok=1;
-               if (ctx->error == X509_V_ERR_INVALID_NON_CA) ok=1;
-               if (ctx->error == X509_V_ERR_PATH_LENGTH_EXCEEDED) ok=1;
-               if (ctx->error == X509_V_ERR_INVALID_PURPOSE) ok=1;
-               if (ctx->error == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) ok=1;
-               if (ctx->error == X509_V_ERR_CRL_HAS_EXPIRED) ok=1;
-               if (ctx->error == X509_V_ERR_CRL_NOT_YET_VALID) ok=1;
-               if (ctx->error == X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION) ok=1;
 
-               if (ctx->error == X509_V_ERR_NO_EXPLICIT_POLICY)
-                       policies_print(NULL, ctx);
                return ok;
 
                }
-       if ((ctx->error == X509_V_OK) && (ok == 2))
+       if (cert_error == X509_V_OK && ok == 2)
                policies_print(NULL, ctx);
        if (!v_verbose)
                ERR_clear_error();
diff --git a/deps/openssl/openssl/apps/vms_decc_init.c b/deps/openssl/openssl/apps/vms_decc_init.c
new file mode 100644 (file)
index 0000000..f512c8f
--- /dev/null
@@ -0,0 +1,188 @@
+#if defined( __VMS) && !defined( OPENSSL_NO_DECC_INIT) && \
+ defined( __DECC) && !defined( __VAX) && (__CRTL_VER >= 70301000)
+# define USE_DECC_INIT 1
+#endif
+
+#ifdef USE_DECC_INIT
+
+/*
+ * 2010-04-26 SMS.
+ *
+ *----------------------------------------------------------------------
+ *
+ *       decc_init()
+ *
+ *    On non-VAX systems, uses LIB$INITIALIZE to set a collection of C
+ *    RTL features without using the DECC$* logical name method.
+ *
+ *----------------------------------------------------------------------
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unixlib.h>
+
+
+/* Global storage. */
+
+/* Flag to sense if decc_init() was called. */
+
+int decc_init_done = -1;
+
+
+/* Structure to hold a DECC$* feature name and its desired value. */
+
+typedef struct
+{
+    char *name;
+    int value;
+} decc_feat_t;
+
+
+/* Array of DECC$* feature names and their desired values.
+ * Note: DECC$ARGV_PARSE_STYLE is the urgent one.
+ */
+
+decc_feat_t decc_feat_array[] =
+{
+ /* Preserve command-line case with SET PROCESS/PARSE_STYLE=EXTENDED */
+ { "DECC$ARGV_PARSE_STYLE", 1 },
+
+ /* Preserve case for file names on ODS5 disks. */
+ { "DECC$EFS_CASE_PRESERVE", 1 },
+
+ /* Enable multiple dots (and most characters) in ODS5 file names,
+  * while preserving VMS-ness of ";version".
+  */
+ { "DECC$EFS_CHARSET", 1 },
+
+ /* List terminator. */
+ { (char *)NULL, 0 }
+};
+
+
+/* LIB$INITIALIZE initialization function. */
+
+static void decc_init( void)
+{
+    char *openssl_debug_decc_init;
+    int verbose = 0;
+    int feat_index;
+    int feat_value;
+    int feat_value_max;
+    int feat_value_min;
+    int i;
+    int sts;
+
+    /* Get debug option. */
+    openssl_debug_decc_init = getenv( "OPENSSL_DEBUG_DECC_INIT");
+    if (openssl_debug_decc_init != NULL)
+    {
+        verbose = strtol( openssl_debug_decc_init, NULL, 10);
+        if (verbose <= 0)
+        {
+            verbose = 1;
+        }
+    }
+
+    /* Set the global flag to indicate that LIB$INITIALIZE worked. */
+    decc_init_done = 1;
+
+    /* Loop through all items in the decc_feat_array[]. */
+
+    for (i = 0; decc_feat_array[ i].name != NULL; i++)
+    {
+        /* Get the feature index. */
+        feat_index = decc$feature_get_index( decc_feat_array[ i].name);
+        if (feat_index >= 0)
+        {
+            /* Valid item.  Collect its properties. */
+            feat_value = decc$feature_get_value( feat_index, 1);
+            feat_value_min = decc$feature_get_value( feat_index, 2);
+            feat_value_max = decc$feature_get_value( feat_index, 3);
+
+            /* Check the validity of our desired value. */
+            if ((decc_feat_array[ i].value >= feat_value_min) &&
+             (decc_feat_array[ i].value <= feat_value_max))
+            {
+                /* Valid value.  Set it if necessary. */
+                if (feat_value != decc_feat_array[ i].value)
+                {
+                    sts = decc$feature_set_value( feat_index,
+                     1,
+                     decc_feat_array[ i].value);
+
+                     if (verbose > 1)
+                     {
+                         fprintf( stderr, " %s = %d, sts = %d.\n",
+                          decc_feat_array[ i].name,
+                          decc_feat_array[ i].value,
+                          sts);
+                     }
+                }
+            }
+            else
+            {
+                /* Invalid DECC feature value. */
+                fprintf( stderr,
+                 " INVALID DECC$FEATURE VALUE, %d: %d <= %s <= %d.\n",
+                 feat_value,
+                 feat_value_min, decc_feat_array[ i].name, feat_value_max);
+            }
+        }
+        else
+        {
+            /* Invalid DECC feature name. */
+            fprintf( stderr,
+             " UNKNOWN DECC$FEATURE: %s.\n", decc_feat_array[ i].name);
+        }
+    }
+
+    if (verbose > 0)
+    {
+        fprintf( stderr, " DECC_INIT complete.\n");
+    }
+}
+
+/* Get "decc_init()" into a valid, loaded LIB$INITIALIZE PSECT. */
+
+#pragma nostandard
+
+/* Establish the LIB$INITIALIZE PSECTs, with proper alignment and
+ * other attributes.  Note that "nopic" is significant only on VAX.
+ */
+#pragma extern_model save
+
+#if __INITIAL_POINTER_SIZE == 64
+# define PSECT_ALIGN 3
+#else
+# define PSECT_ALIGN 2
+#endif
+
+#pragma extern_model strict_refdef "LIB$INITIALIZ" PSECT_ALIGN, nopic, nowrt
+const int spare[ 8] = { 0 };
+
+#pragma extern_model strict_refdef "LIB$INITIALIZE" PSECT_ALIGN, nopic, nowrt
+void (*const x_decc_init)() = decc_init;
+
+#pragma extern_model restore
+
+/* Fake reference to ensure loading the LIB$INITIALIZE PSECT. */
+
+#pragma extern_model save
+
+int LIB$INITIALIZE( void);
+
+#pragma extern_model strict_refdef
+int dmy_lib$initialize = (int) LIB$INITIALIZE;
+
+#pragma extern_model restore
+
+#pragma standard
+
+#else /* def USE_DECC_INIT */
+
+/* Dummy code to avoid a %CC-W-EMPTYFILE complaint. */
+int decc_init_dummy( void);
+
+#endif /* def USE_DECC_INIT */
index 151d3a9..9f5eaeb 100644 (file)
@@ -99,7 +99,13 @@ static const char *x509_usage[]={
 " -passin arg     - private key password source\n",
 " -serial         - print serial number value\n",
 " -subject_hash   - print subject hash value\n",
+#ifndef OPENSSL_NO_MD5
+" -subject_hash_old   - print old-style (MD5) subject hash value\n",
+#endif
 " -issuer_hash    - print issuer hash value\n",
+#ifndef OPENSSL_NO_MD5
+" -issuer_hash_old    - print old-style (MD5) issuer hash value\n",
+#endif
 " -hash           - synonym for -subject_hash\n",
 " -subject        - print subject DN\n",
 " -issuer         - print issuer DN\n",
@@ -179,6 +185,9 @@ int MAIN(int argc, char **argv)
        int text=0,serial=0,subject=0,issuer=0,startdate=0,enddate=0;
        int next_serial=0;
        int subject_hash=0,issuer_hash=0,ocspid=0;
+#ifndef OPENSSL_NO_MD5
+       int subject_hash_old=0,issuer_hash_old=0;
+#endif
        int noout=0,sign_flag=0,CA_flag=0,CA_createserial=0,email=0;
        int ocsp_uri=0;
        int trustout=0,clrtrust=0,clrreject=0,aliasout=0,clrext=0;
@@ -190,7 +199,7 @@ int MAIN(int argc, char **argv)
        X509_REQ *rq=NULL;
        int fingerprint=0;
        char buf[256];
-       const EVP_MD *md_alg,*digest=EVP_sha1();
+       const EVP_MD *md_alg,*digest=NULL;
        CONF *extconf = NULL;
        char *extsect = NULL, *extfile = NULL, *passin = NULL, *passargin = NULL;
        int need_rand = 0;
@@ -225,7 +234,7 @@ int MAIN(int argc, char **argv)
 
        ctx=X509_STORE_new();
        if (ctx == NULL) goto end;
-       X509_STORE_set_verify_cb_func(ctx,callb);
+       X509_STORE_set_verify_cb(ctx,callb);
 
        argc--;
        argv++;
@@ -397,8 +406,16 @@ int MAIN(int argc, char **argv)
                else if (strcmp(*argv,"-hash") == 0
                        || strcmp(*argv,"-subject_hash") == 0)
                        subject_hash= ++num;
+#ifndef OPENSSL_NO_MD5
+               else if (strcmp(*argv,"-subject_hash_old") == 0)
+                       subject_hash_old= ++num;
+#endif
                else if (strcmp(*argv,"-issuer_hash") == 0)
                        issuer_hash= ++num;
+#ifndef OPENSSL_NO_MD5
+               else if (strcmp(*argv,"-issuer_hash_old") == 0)
+                       issuer_hash_old= ++num;
+#endif
                else if (strcmp(*argv,"-subject") == 0)
                        subject= ++num;
                else if (strcmp(*argv,"-issuer") == 0)
@@ -624,7 +641,7 @@ bad:
                if (!X509_set_subject_name(x,req->req_info->subject)) goto end;
 
                X509_gmtime_adj(X509_get_notBefore(x),0);
-               X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*days);
+               X509_time_adj_ex(X509_get_notAfter(x),days, 0, NULL);
 
                pkey = X509_REQ_get_pubkey(req);
                X509_set_pubkey(x,pkey);
@@ -736,13 +753,14 @@ bad:
                        else if ((email == i) || (ocsp_uri == i))
                                {
                                int j;
-                               STACK *emlst;
+                               STACK_OF(OPENSSL_STRING) *emlst;
                                if (email == i)
                                        emlst = X509_get1_email(x);
                                else
                                        emlst = X509_get1_ocsp(x);
-                               for (j = 0; j < sk_num(emlst); j++)
-                                       BIO_printf(STDout, "%s\n", sk_value(emlst, j));
+                               for (j = 0; j < sk_OPENSSL_STRING_num(emlst); j++)
+                                       BIO_printf(STDout, "%s\n",
+                                                  sk_OPENSSL_STRING_value(emlst, j));
                                X509_email_free(emlst);
                                }
                        else if (aliasout == i)
@@ -756,10 +774,22 @@ bad:
                                {
                                BIO_printf(STDout,"%08lx\n",X509_subject_name_hash(x));
                                }
+#ifndef OPENSSL_NO_MD5
+                       else if (subject_hash_old == i)
+                               {
+                               BIO_printf(STDout,"%08lx\n",X509_subject_name_hash_old(x));
+                               }
+#endif
                        else if (issuer_hash == i)
                                {
                                BIO_printf(STDout,"%08lx\n",X509_issuer_name_hash(x));
                                }
+#ifndef OPENSSL_NO_MD5
+                       else if (issuer_hash_old == i)
+                               {
+                               BIO_printf(STDout,"%08lx\n",X509_issuer_name_hash_old(x));
+                               }
+#endif
                        else if (pprint == i)
                                {
                                X509_PURPOSE *ptmp;
@@ -890,14 +920,18 @@ bad:
                                int j;
                                unsigned int n;
                                unsigned char md[EVP_MAX_MD_SIZE];
+                               const EVP_MD *fdig = digest;
+
+                               if (!fdig)
+                                       fdig = EVP_sha1();
 
-                               if (!X509_digest(x,digest,md,&n))
+                               if (!X509_digest(x,fdig,md,&n))
                                        {
                                        BIO_printf(bio_err,"out of memory\n");
                                        goto end;
                                        }
                                BIO_printf(STDout,"%s Fingerprint=",
-                                               OBJ_nid2sn(EVP_MD_type(digest)));
+                                               OBJ_nid2sn(EVP_MD_type(fdig)));
                                for (j=0; j<(int)n; j++)
                                        {
                                        BIO_printf(STDout,"%02X%c",md[j],
@@ -917,14 +951,6 @@ bad:
                                                passin, e, "Private key");
                                        if (Upkey == NULL) goto end;
                                        }
-#ifndef OPENSSL_NO_DSA
-                               if (Upkey->type == EVP_PKEY_DSA)
-                                       digest=EVP_dss1();
-#endif
-#ifndef OPENSSL_NO_ECDSA
-                               if (Upkey->type == EVP_PKEY_EC)
-                                       digest=EVP_ecdsa();
-#endif
 
                                assert(need_rand);
                                if (!sign(x,Upkey,days,clrext,digest,
@@ -941,14 +967,6 @@ bad:
                                                "CA Private Key");
                                        if (CApkey == NULL) goto end;
                                        }
-#ifndef OPENSSL_NO_DSA
-                               if (CApkey->type == EVP_PKEY_DSA)
-                                       digest=EVP_dss1();
-#endif
-#ifndef OPENSSL_NO_ECDSA
-                               if (CApkey->type == EVP_PKEY_EC)
-                                       digest = EVP_ecdsa();
-#endif
                                
                                assert(need_rand);
                                if (!x509_certify(ctx,CAfile,digest,x,xca,
@@ -969,22 +987,13 @@ bad:
                                else
                                        {
                                        pk=load_key(bio_err,
-                                               keyfile, FORMAT_PEM, 0,
+                                               keyfile, keyformat, 0,
                                                passin, e, "request key");
                                        if (pk == NULL) goto end;
                                        }
 
                                BIO_printf(bio_err,"Generating certificate request\n");
 
-#ifndef OPENSSL_NO_DSA
-                               if (pk->type == EVP_PKEY_DSA)
-                                       digest=EVP_dss1();
-#endif
-#ifndef OPENSSL_NO_ECDSA
-                               if (pk->type == EVP_PKEY_EC)
-                                       digest=EVP_ecdsa();
-#endif
-
                                rq=X509_to_X509_REQ(x,pk,digest);
                                EVP_PKEY_free(pk);
                                if (rq == NULL)
@@ -1038,16 +1047,15 @@ bad:
                }
        else if (outformat == FORMAT_NETSCAPE)
                {
-               ASN1_HEADER ah;
-               ASN1_OCTET_STRING os;
+               NETSCAPE_X509 nx;
+               ASN1_OCTET_STRING hdr;
 
-               os.data=(unsigned char *)NETSCAPE_CERT_HDR;
-               os.length=strlen(NETSCAPE_CERT_HDR);
-               ah.header= &os;
-               ah.data=(char *)x;
-               ah.meth=X509_asn1_meth();
+               hdr.data=(unsigned char *)NETSCAPE_CERT_HDR;
+               hdr.length=strlen(NETSCAPE_CERT_HDR);
+               nx.header= &hdr;
+               nx.cert=x;
 
-               i=ASN1_i2d_bio_of(ASN1_HEADER,i2d_ASN1_HEADER,out,&ah);
+               i=ASN1_item_i2d_bio(ASN1_ITEM_rptr(NETSCAPE_X509),out,&nx);
                }
        else    {
                BIO_printf(bio_err,"bad output format specified for outfile\n");
@@ -1166,7 +1174,7 @@ static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest,
                goto end;
 
        /* hardwired expired */
-       if (X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*days) == NULL)
+       if (X509_time_adj_ex(X509_get_notAfter(x),days, 0, NULL) == NULL)
                goto end;
 
        if (clrext)
index b9d1c7a..cf64ec5 100755 (executable)
@@ -29,7 +29,7 @@ EXE=""
 for i
 do
 case "$i" in 
--d) PREFIX="debug-";;
+-d*) PREFIX="debug-";;
 -t*) TEST="true";;
 -h*) TEST="true"; cat <<EOF
 Usage: config [options]
@@ -122,6 +122,14 @@ case "${SYSTEM}:${RELEASE}:${VERSION}:${MACHINE}" in
        echo "${MACHINE}-ibm-aix3"; exit 0
        ;;
 
+    BeOS:*:BePC)
+    if [ -e /boot/develop/headers/be/bone ]; then
+               echo "beos-x86-bone"; exit 0
+       else
+               echo "beos-x86-r5"; exit 0
+       fi
+       ;;
+
     dgux:*)
        echo "${MACHINE}-dg-dgux"; exit 0
        ;;
@@ -270,7 +278,7 @@ case "${SYSTEM}:${RELEASE}:${VERSION}:${MACHINE}" in
                echo "ppc-apple-darwin${VERSION}"
                ;;
            *)
-               echo "i386-apple-darwin${VERSION}"
+               echo "i686-apple-darwin${VERSION}"
                ;;
        esac
        exit 0
@@ -488,6 +496,12 @@ echo Operating system: $GUESSOS
 # script above so we end up with values in vars but that would take
 # more time that I want to waste at the moment
 case "$GUESSOS" in
+  uClinux*64*)
+    OUT=uClinux-dist64
+       ;;
+  uClinux*)
+    OUT=uClinux-dist
+       ;;
   mips2-sgi-irix)
        CPU=`(hinv -t cpu) 2>/dev/null | head -1 | sed 's/^CPU:[^R]*R\([0-9]*\).*/\1/'`
        CPU=${CPU:-0}
@@ -523,8 +537,28 @@ case "$GUESSOS" in
        OUT="irix-mips3-$CC"
        ;;
   ppc-apple-rhapsody) OUT="rhapsody-ppc-cc" ;;
-  ppc-apple-darwin*) OUT="darwin-ppc-cc" ;;
-  i386-apple-darwin*) OUT="darwin-i386-cc" ;;
+  ppc-apple-darwin*)
+       ISA64=`(sysctl -n hw.optional.64bitops) 2>/dev/null`
+       if [ "$ISA64" = "1" ]; then
+           echo "WARNING! If you wish to build 64-bit library, then you have to"
+           echo "         invoke './Configure darwin64-ppc-cc' *manually*."
+           if [ "$TEST" = "false" -a -t 1 ]; then
+             echo "         You have about 5 seconds to press Ctrl-C to abort."
+             (trap "stty `stty -g`" 2 0; stty -icanon min 0 time 50; read waste) <&1
+           fi
+       fi
+       OUT="darwin-ppc-cc" ;;
+  i?86-apple-darwin*)
+       ISA64=`(sysctl -n hw.optional.x86_64) 2>/dev/null`
+       if [ "$ISA64" = "1" ]; then
+           echo "WARNING! If you wish to build 64-bit library, then you have to"
+           echo "         invoke './Configure darwin64-x86_64-cc' *manually*."
+           if [ "$TEST" = "false" -a -t 1 ]; then
+             echo "         You have about 5 seconds to press Ctrl-C to abort."
+             (trap "stty `stty -g`" 2 0; stty -icanon min 0 time 50; read waste) <&1
+           fi
+       fi
+       OUT="darwin-i386-cc" ;;
   alpha-*-linux2)
         ISA=`awk '/cpu model/{print$4;exit(0);}' /proc/cpuinfo`
        case ${ISA:-generic} in
@@ -589,13 +623,13 @@ case "$GUESSOS" in
 
        options="$options -DB_ENDIAN -mschedule=$CPUSCHEDULE -march=$CPUARCH"
        OUT="linux-generic32" ;;
-  arm*b-*-linux2) OUT="linux-generic32"; options="$options -DB_ENDIAN" ;;
-  arm*l-*-linux2) OUT="linux-generic32"; options="$options -DL_ENDIAN" ;;
+  armv[1-3]*-*-linux2) OUT="linux-generic32" ;;
+  arm*-*-linux2) OUT="linux-armv4" ;;
   sh*b-*-linux2) OUT="linux-generic32"; options="$options -DB_ENDIAN" ;;
   sh*-*-linux2)  OUT="linux-generic32"; options="$options -DL_ENDIAN" ;;
   m68k*-*-linux2) OUT="linux-generic32"; options="$options -DB_ENDIAN" ;;
-  s390-*-linux2) OUT="linux-generic32"; options="$options -DB_ENDIAN -DNO_ASM" ;;
-  s390x-*-linux2) OUT="linux-generic64"; options="$options -DB_ENDIAN" ;;
+  s390-*-linux2) OUT="linux-generic32"; options="$options -DB_ENDIAN" ;;
+  s390x-*-linux2) OUT="linux-s390x" ;;
   x86_64-*-linux?) OUT="linux-x86_64" ;;
   *86-*-linux2) OUT="linux-elf"
        if [ "$GCCVER" -gt 28 ]; then
@@ -773,6 +807,7 @@ case "$GUESSOS" in
   t3e-cray-unicosmk) OUT="cray-t3e" ;;
   j90-cray-unicos) OUT="cray-j90" ;;
   nsr-tandem-nsk) OUT="tandem-c89" ;;
+  beos-*) OUT="$GUESSOS" ;;
   x86pc-*-qnx6) OUT="QNX6-i386" ;;
   *-*-qnx6) OUT="QNX6" ;;
   *) OUT=`echo $GUESSOS | awk -F- '{print $3}'`;;
@@ -790,6 +825,10 @@ esac
 #  options="$options -DATALLA"
 #fi
 
+($CC -Wa,--help -c -o /dev/null -x assembler /dev/null 2>&1 | \
+ grep \\--noexecstack) 2>&1 > /dev/null && \
+  options="$options -Wa,--noexecstack"
+
 # gcc < 2.8 does not support -march=ultrasparc
 if [ "$OUT" = solaris-sparcv9-gcc -a $GCCVER -lt 28 ]
 then
index 85b427a..7613bd2 100644 (file)
 #ifndef LPDIR_H
 #include "LPdir.h"
 #endif
+#include "vms_rms.h"
 
-/* Because some compiler options hide this macor */
+/* Some compiler options hide EVMSERR. */
 #ifndef EVMSERR
-#define EVMSERR                65535  /* error for non-translatable VMS errors */
+# define EVMSERR       65535  /* error for non-translatable VMS errors */
 #endif
 
 struct LP_dir_context_st
 {
   unsigned long VMS_context;
-#ifdef NAML$C_MAXRSS
-  char filespec[NAML$C_MAXRSS+1];
-  char result[NAML$C_MAXRSS+1];
-#else
-  char filespec[256];
-  char result[256];
-#endif
+  char filespec[ NAMX_MAXRSS+ 1];
+  char result[ NAMX_MAXRSS+ 1];
   struct dsc$descriptor_d filespec_dsc;
   struct dsc$descriptor_d result_dsc;
 };
@@ -66,6 +62,16 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
   char *p, *r;
   size_t l;
   unsigned long flags = 0;
+
+/* Arrange 32-bit pointer to (copied) string storage, if needed. */
+#if __INITIAL_POINTER_SIZE == 64
+# pragma pointer_size save
+# pragma pointer_size 32
+        char *ctx_filespec_32p;
+# pragma pointer_size restore
+        char ctx_filespec_32[ NAMX_MAXRSS+ 1];
+#endif /* __INITIAL_POINTER_SIZE == 64 */
+
 #ifdef NAML$C_MAXRSS
   flags |= LIB$M_FIL_LONG_NAMES;
 #endif
@@ -93,13 +99,7 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
 
       filespeclen += 4;                /* "*.*;" */
 
-      if (filespeclen >
-#ifdef NAML$C_MAXRSS
-         NAML$C_MAXRSS
-#else
-         255
-#endif
-         )
+      if (filespeclen > NAMX_MAXRSS)
        {
          errno = ENAMETOOLONG;
          return 0;
@@ -115,14 +115,21 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
 
       strcpy((*ctx)->filespec,directory);
       strcat((*ctx)->filespec,"*.*;");
+
+/* Arrange 32-bit pointer to (copied) string storage, if needed. */
+#if __INITIAL_POINTER_SIZE == 64
+# define CTX_FILESPEC ctx_filespec_32p
+        /* Copy the file name to storage with a 32-bit pointer. */
+        ctx_filespec_32p = ctx_filespec_32;
+        strcpy( ctx_filespec_32p, (*ctx)->filespec);
+#else /* __INITIAL_POINTER_SIZE == 64 */
+# define CTX_FILESPEC (*ctx)->filespec
+#endif /* __INITIAL_POINTER_SIZE == 64 [else] */
+
       (*ctx)->filespec_dsc.dsc$w_length = filespeclen;
       (*ctx)->filespec_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
       (*ctx)->filespec_dsc.dsc$b_class = DSC$K_CLASS_S;
-      (*ctx)->filespec_dsc.dsc$a_pointer = (*ctx)->filespec;
-      (*ctx)->result_dsc.dsc$w_length = 0;
-      (*ctx)->result_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
-      (*ctx)->result_dsc.dsc$b_class = DSC$K_CLASS_D;
-      (*ctx)->result_dsc.dsc$a_pointer = 0;
+      (*ctx)->filespec_dsc.dsc$a_pointer = CTX_FILESPEC;
     }
 
   (*ctx)->result_dsc.dsc$w_length = 0;
index 09b475b..702dbc7 100644 (file)
@@ -54,8 +54,6 @@ struct LP_dir_context_st
 
 const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
 {
-  struct dirent *direntry = NULL;
-
   if (ctx == NULL || directory == NULL)
     {
       errno = EINVAL;
index 6557f2b..85d9f24 100644 (file)
@@ -5,9 +5,9 @@
 DIR=           crypto
 TOP=           ..
 CC=            cc
-INCLUDE=       -I. -I$(TOP) -I../include
+INCLUDE=       -I. -I$(TOP) -I../include $(ZLIB_INCLUDE)
 # INCLUDES targets sudbirs!
-INCLUDES=      -I.. -I../.. -I../../include
+INCLUDES=      -I.. -I../.. -I../asn1 -I../evp -I../../include $(ZLIB_INCLUDE)
 CFLAG=         -g
 MAKEDEPPROG=   makedepend
 MAKEDEPEND=    $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
@@ -17,7 +17,7 @@ AR=           ar r
 
 RECURSIVE_MAKE=        [ -n "$(SDIRS)" ] && for i in $(SDIRS) ; do \
                    (cd $$i && echo "making $$target in $(DIR)/$$i..." && \
-                   $(MAKE) -e TOP=../.. DIR=$$i INCLUDES='${INCLUDES}' $$target ) || exit 1; \
+                   $(MAKE) -e TOP=../.. DIR=$$i INCLUDES='$(INCLUDES)' $$target ) || exit 1; \
                done;
 
 PEX_LIBS=
@@ -26,6 +26,7 @@ EX_LIBS=
 CFLAGS= $(INCLUDE) $(CFLAG)
 ASFLAGS= $(INCLUDE) $(ASFLAG)
 AFLAGS=$(ASFLAGS)
+CPUID_OBJ=mem_clr.o
 
 LIBS=
 
@@ -33,12 +34,12 @@ GENERAL=Makefile README crypto-lib.com install.com
 
 LIB= $(TOP)/libcrypto.a
 SHARED_LIB= libcrypto$(SHLIB_EXT)
-LIBSRC=        cryptlib.c dyn_lck.c mem.c mem_clr.c mem_dbg.c cversion.c ex_data.c tmdiff.c cpt_err.c ebcdic.c uid.c o_time.c o_str.c o_dir.c o_init.c fips_err.c
-LIBOBJ= cryptlib.o dyn_lck.o mem.o mem_clr.o mem_dbg.o cversion.o ex_data.o tmdiff.o cpt_err.o ebcdic.o uid.o o_time.o o_str.o o_dir.o o_init.o fips_err.o $(CPUID_OBJ)
+LIBSRC=        cryptlib.c mem.c mem_clr.c mem_dbg.c cversion.c ex_data.c cpt_err.c ebcdic.c uid.c o_time.c o_str.c o_dir.c
+LIBOBJ= cryptlib.o mem.o mem_dbg.o cversion.o ex_data.o cpt_err.o ebcdic.o uid.o o_time.o o_str.o o_dir.o $(CPUID_OBJ)
 
 SRC= $(LIBSRC)
 
-EXHEADER= crypto.h tmdiff.h opensslv.h opensslconf.h ebcdic.h symhacks.h \
+EXHEADER= crypto.h opensslv.h opensslconf.h ebcdic.h symhacks.h \
        ossl_typ.h
 HEADER=        cryptlib.h buildinf.h md32_common.h o_time.h o_str.h o_dir.h $(EXHEADER)
 
@@ -47,7 +48,7 @@ ALL=    $(GENERAL) $(SRC) $(HEADER)
 top:
        @(cd ..; $(MAKE) DIRS=$(DIR) all)
 
-all: lib
+all: shared
 
 buildinf.h: ../Makefile
        ( echo "#ifndef MK1MF_BUILD"; \
@@ -57,26 +58,28 @@ buildinf.h: ../Makefile
        echo "  #define DATE \"`LC_ALL=C LC_TIME=C date`\""; \
        echo '#endif' ) >buildinf.h
 
-x86cpuid-elf.s:        x86cpuid.pl perlasm/x86asm.pl
-       $(PERL) x86cpuid.pl elf $(CFLAGS) $(PROCESSOR) > $@
-x86cpuid-cof.s: x86cpuid.pl perlasm/x86asm.pl
-       $(PERL) x86cpuid.pl coff $(CFLAGS) $(PROCESSOR) > $@
-x86cpuid-out.s: x86cpuid.pl perlasm/x86asm.pl
-       $(PERL) x86cpuid.pl a.out $(CFLAGS) $(PROCESSOR) > $@
+x86cpuid.s:    x86cpuid.pl perlasm/x86asm.pl
+       $(PERL) x86cpuid.pl $(PERLASM_SCHEME) $(CFLAGS) $(PROCESSOR) > $@
 
-uplink.o:      ../ms/uplink.c
-       $(CC) $(CFLAGS) -c -o $@ ../ms/uplink.c
+applink.o:     $(TOP)/ms/applink.c
+       $(CC) $(CFLAGS) -c -o $@ $(TOP)/ms/applink.c
 
-uplink-cof.s:  ../ms/uplink.pl
-       $(PERL) ../ms/uplink.pl coff > $@
+uplink.o:      $(TOP)/ms/uplink.c applink.o
+       $(CC) $(CFLAGS) -c -o $@ $(TOP)/ms/uplink.c
+
+uplink-cof.s:  $(TOP)/ms/uplink.pl
+       $(PERL) $(TOP)/ms/uplink.pl coff > $@
 
 x86_64cpuid.s: x86_64cpuid.pl
-       $(PERL) x86_64cpuid.pl $@
+       $(PERL) x86_64cpuid.pl $(PERLASM_SCHEME) > $@
 ia64cpuid.s: ia64cpuid.S
        $(CC) $(CFLAGS) -E ia64cpuid.S > $@
+ppccpuid.s:    ppccpuid.pl;    $(PERL) ppccpuid.pl $(PERLASM_SCHEME) $@
+alphacpuid.s:  alphacpuid.pl
+       $(PERL) $< | $(CC) -E - | tee $@ > /dev/null
 
 testapps:
-       [ -z "$(THIS)" ] || (   if echo ${SDIRS} | fgrep ' des '; \
+       [ -z "$(THIS)" ] || (   if echo $(SDIRS) | fgrep ' des '; \
                                then cd des && $(MAKE) -e des; fi )
        [ -z "$(THIS)" ] || ( cd pkcs7 && $(MAKE) -e testapps );
        @if [ -z "$(THIS)" ]; then $(MAKE) -f $(TOP)/Makefile reflect THIS=$@; fi
@@ -94,11 +97,11 @@ links:
        @$(PERL) $(TOP)/util/mklink.pl ../apps $(APPS)
        @target=links; $(RECURSIVE_MAKE)
 
-# lib: and $(LIB): are splitted to avoid end-less loop
-lib:   buildinf.h $(LIB) subdirs
+# lib: $(LIB): are splitted to avoid end-less loop
+lib:   $(LIB)
        @touch lib
 $(LIB):        $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
 
 shared: buildinf.h lib subdirs
@@ -135,6 +138,7 @@ clean:
 dclean:
        $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
        mv -f Makefile.new $(MAKEFILE)
+       rm -f opensslconf.h
        @target=dclean; $(RECURSIVE_MAKE)
 
 # DO NOT DELETE THIS LINE -- make depend depends on it.
@@ -159,13 +163,6 @@ cversion.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 cversion.o: ../include/openssl/ossl_typ.h ../include/openssl/safestack.h
 cversion.o: ../include/openssl/stack.h ../include/openssl/symhacks.h buildinf.h
 cversion.o: cryptlib.h cversion.c
-dyn_lck.o: ../e_os.h ../include/openssl/bio.h ../include/openssl/buffer.h
-dyn_lck.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
-dyn_lck.o: ../include/openssl/err.h ../include/openssl/lhash.h
-dyn_lck.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
-dyn_lck.o: ../include/openssl/ossl_typ.h ../include/openssl/safestack.h
-dyn_lck.o: ../include/openssl/stack.h ../include/openssl/symhacks.h cryptlib.h
-dyn_lck.o: dyn_lck.c
 ebcdic.o: ../include/openssl/e_os2.h ../include/openssl/opensslconf.h ebcdic.c
 ex_data.o: ../e_os.h ../include/openssl/bio.h ../include/openssl/buffer.h
 ex_data.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
@@ -174,13 +171,6 @@ ex_data.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 ex_data.o: ../include/openssl/ossl_typ.h ../include/openssl/safestack.h
 ex_data.o: ../include/openssl/stack.h ../include/openssl/symhacks.h cryptlib.h
 ex_data.o: ex_data.c
-fips_err.o: ../include/openssl/bio.h ../include/openssl/crypto.h
-fips_err.o: ../include/openssl/e_os2.h ../include/openssl/err.h
-fips_err.o: ../include/openssl/fips.h ../include/openssl/lhash.h
-fips_err.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
-fips_err.o: ../include/openssl/ossl_typ.h ../include/openssl/safestack.h
-fips_err.o: ../include/openssl/stack.h ../include/openssl/symhacks.h fips_err.c
-fips_err.o: fips_err.h
 mem.o: ../e_os.h ../include/openssl/bio.h ../include/openssl/buffer.h
 mem.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
 mem.o: ../include/openssl/err.h ../include/openssl/lhash.h
@@ -201,23 +191,10 @@ mem_dbg.o: ../include/openssl/stack.h ../include/openssl/symhacks.h cryptlib.h
 mem_dbg.o: mem_dbg.c
 o_dir.o: ../e_os.h ../include/openssl/e_os2.h ../include/openssl/opensslconf.h
 o_dir.o: LPdir_unix.c o_dir.c o_dir.h
-o_init.o: ../e_os.h ../include/openssl/bio.h ../include/openssl/crypto.h
-o_init.o: ../include/openssl/e_os2.h ../include/openssl/err.h
-o_init.o: ../include/openssl/lhash.h ../include/openssl/opensslconf.h
-o_init.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-o_init.o: ../include/openssl/safestack.h ../include/openssl/stack.h
-o_init.o: ../include/openssl/symhacks.h o_init.c
 o_str.o: ../e_os.h ../include/openssl/e_os2.h ../include/openssl/opensslconf.h
 o_str.o: o_str.c o_str.h
 o_time.o: ../include/openssl/e_os2.h ../include/openssl/opensslconf.h o_time.c
 o_time.o: o_time.h
-tmdiff.o: ../e_os.h ../include/openssl/bio.h ../include/openssl/buffer.h
-tmdiff.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
-tmdiff.o: ../include/openssl/err.h ../include/openssl/lhash.h
-tmdiff.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
-tmdiff.o: ../include/openssl/ossl_typ.h ../include/openssl/safestack.h
-tmdiff.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-tmdiff.o: ../include/openssl/tmdiff.h cryptlib.h tmdiff.c
 uid.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
 uid.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 uid.o: ../include/openssl/ossl_typ.h ../include/openssl/safestack.h
index 9d174f4..c501a43 100644 (file)
@@ -11,7 +11,7 @@ CFLAG=-g
 MAKEFILE=      Makefile
 AR=            ar r
 
-AES_ASM_OBJ=aes_core.o aes_cbc.o
+AES_ENC=aes_core.o aes_cbc.o
 
 CFLAGS= $(INCLUDES) $(CFLAG)
 ASFLAGS= $(INCLUDES) $(ASFLAG)
@@ -26,7 +26,7 @@ LIB=$(TOP)/libcrypto.a
 LIBSRC=aes_core.c aes_misc.c aes_ecb.c aes_cbc.c aes_cfb.c aes_ofb.c \
        aes_ctr.c aes_ige.c aes_wrap.c
 LIBOBJ=aes_misc.o aes_ecb.o aes_cfb.o aes_ofb.o aes_ctr.o aes_ige.o aes_wrap.o \
-       $(AES_ASM_OBJ)
+       $(AES_ENC)
 
 SRC= $(LIBSRC)
 
@@ -41,24 +41,27 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
-$(LIBOBJ): $(LIBSRC)
-
 aes-ia64.s: asm/aes-ia64.S
        $(CC) $(CFLAGS) -E asm/aes-ia64.S > $@
 
-ax86-elf.s: asm/aes-586.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) aes-586.pl elf $(CFLAGS) $(PROCESSOR) > ../$@)
-ax86-cof.s: asm/aes-586.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) aes-586.pl coff $(CFLAGS) $(PROCESSOR) > ../$@)
-ax86-out.s: asm/aes-586.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) aes-586.pl a.out $(CFLAGS) $(PROCESSOR) > ../$@)
+aes-586.s:     asm/aes-586.pl ../perlasm/x86asm.pl
+       $(PERL) asm/aes-586.pl $(PERLASM_SCHEME) $(CFLAGS) $(PROCESSOR) > $@
 
 aes-x86_64.s: asm/aes-x86_64.pl
-       $(PERL) asm/aes-x86_64.pl $@
+       $(PERL) asm/aes-x86_64.pl $(PERLASM_SCHEME) > $@
+
+aes-sparcv9.s: asm/aes-sparcv9.pl
+       $(PERL) asm/aes-sparcv9.pl $(CFLAGS) > $@
+
+aes-ppc.s:     asm/aes-ppc.pl
+       $(PERL) asm/aes-ppc.pl $(PERLASM_SCHEME) $@
+
+# GNU make "catch all"
+aes-%.s:       asm/aes-%.pl;   $(PERL) $< $(CFLAGS) > $@
 
 files:
        $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
@@ -97,16 +100,14 @@ clean:
 
 # DO NOT DELETE THIS LINE -- make depend depends on it.
 
-aes_cbc.o: ../../include/openssl/aes.h ../../include/openssl/e_os2.h
-aes_cbc.o: ../../include/openssl/opensslconf.h aes_cbc.c aes_locl.h
-aes_cfb.o: ../../e_os.h ../../include/openssl/aes.h
-aes_cfb.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
-aes_cfb.o: aes_cfb.c aes_locl.h
+aes_cbc.o: ../../include/openssl/aes.h ../../include/openssl/modes.h
+aes_cbc.o: ../../include/openssl/opensslconf.h aes_cbc.c
+aes_cfb.o: ../../include/openssl/aes.h ../../include/openssl/modes.h
+aes_cfb.o: ../../include/openssl/opensslconf.h aes_cfb.c
 aes_core.o: ../../include/openssl/aes.h ../../include/openssl/e_os2.h
-aes_core.o: ../../include/openssl/fips.h ../../include/openssl/opensslconf.h
-aes_core.o: aes_core.c aes_locl.h
-aes_ctr.o: ../../include/openssl/aes.h ../../include/openssl/e_os2.h
-aes_ctr.o: ../../include/openssl/opensslconf.h aes_ctr.c aes_locl.h
+aes_core.o: ../../include/openssl/opensslconf.h aes_core.c aes_locl.h
+aes_ctr.o: ../../include/openssl/aes.h ../../include/openssl/modes.h
+aes_ctr.o: ../../include/openssl/opensslconf.h aes_ctr.c
 aes_ecb.o: ../../include/openssl/aes.h ../../include/openssl/e_os2.h
 aes_ecb.o: ../../include/openssl/opensslconf.h aes_ecb.c aes_locl.h
 aes_ige.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/bio.h
@@ -119,8 +120,8 @@ aes_ige.o: ../../include/openssl/symhacks.h ../cryptlib.h aes_ige.c aes_locl.h
 aes_misc.o: ../../include/openssl/aes.h ../../include/openssl/e_os2.h
 aes_misc.o: ../../include/openssl/opensslconf.h
 aes_misc.o: ../../include/openssl/opensslv.h aes_locl.h aes_misc.c
-aes_ofb.o: ../../include/openssl/aes.h ../../include/openssl/e_os2.h
-aes_ofb.o: ../../include/openssl/opensslconf.h aes_locl.h aes_ofb.c
+aes_ofb.o: ../../include/openssl/aes.h ../../include/openssl/modes.h
+aes_ofb.o: ../../include/openssl/opensslconf.h aes_ofb.c
 aes_wrap.o: ../../e_os.h ../../include/openssl/aes.h
 aes_wrap.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 aes_wrap.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
index 450f2b4..d2c9973 100644 (file)
@@ -58,6 +58,8 @@
 #error AES is disabled.
 #endif
 
+#include <stddef.h>
+
 #define AES_ENCRYPT    1
 #define AES_DECRYPT    0
 
 #define AES_MAXNR 14
 #define AES_BLOCK_SIZE 16
 
-#ifdef OPENSSL_FIPS
-#define FIPS_AES_SIZE_T        int
-#endif
-
 #ifdef  __cplusplus
 extern "C" {
 #endif
@@ -100,37 +98,32 @@ void AES_decrypt(const unsigned char *in, unsigned char *out,
 void AES_ecb_encrypt(const unsigned char *in, unsigned char *out,
        const AES_KEY *key, const int enc);
 void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
-       const unsigned long length, const AES_KEY *key,
+       size_t length, const AES_KEY *key,
        unsigned char *ivec, const int enc);
 void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out,
-       const unsigned long length, const AES_KEY *key,
+       size_t length, const AES_KEY *key,
        unsigned char *ivec, int *num, const int enc);
 void AES_cfb1_encrypt(const unsigned char *in, unsigned char *out,
-       const unsigned long length, const AES_KEY *key,
+       size_t length, const AES_KEY *key,
        unsigned char *ivec, int *num, const int enc);
 void AES_cfb8_encrypt(const unsigned char *in, unsigned char *out,
-       const unsigned long length, const AES_KEY *key,
+       size_t length, const AES_KEY *key,
        unsigned char *ivec, int *num, const int enc);
-void AES_cfbr_encrypt_block(const unsigned char *in,unsigned char *out,
-                           const int nbits,const AES_KEY *key,
-                           unsigned char *ivec,const int enc);
 void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out,
-       const unsigned long length, const AES_KEY *key,
+       size_t length, const AES_KEY *key,
        unsigned char *ivec, int *num);
 void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out,
-       const unsigned long length, const AES_KEY *key,
+       size_t length, const AES_KEY *key,
        unsigned char ivec[AES_BLOCK_SIZE],
        unsigned char ecount_buf[AES_BLOCK_SIZE],
        unsigned int *num);
-
-/* For IGE, see also http://www.links.org/files/openssl-ige.pdf */
 /* NB: the IV is _two_ blocks long */
 void AES_ige_encrypt(const unsigned char *in, unsigned char *out,
-                    const unsigned long length, const AES_KEY *key,
+                    size_t length, const AES_KEY *key,
                     unsigned char *ivec, const int enc);
 /* NB: the IV is _four_ blocks long */
 void AES_bi_ige_encrypt(const unsigned char *in, unsigned char *out,
-                       const unsigned long length, const AES_KEY *key,
+                       size_t length, const AES_KEY *key,
                        const AES_KEY *key2, const unsigned char *ivec,
                        const int enc);
 
@@ -141,6 +134,7 @@ int AES_unwrap_key(AES_KEY *key, const unsigned char *iv,
                unsigned char *out,
                const unsigned char *in, unsigned int inlen);
 
+
 #ifdef  __cplusplus
 }
 #endif
index 373864c..227f756 100644 (file)
  *
  */
 
-#ifndef AES_DEBUG
-# ifndef NDEBUG
-#  define NDEBUG
-# endif
-#endif
-#include <assert.h>
-
 #include <openssl/aes.h>
-#include "aes_locl.h"
+#include <openssl/modes.h>
 
-#if !defined(OPENSSL_FIPS_AES_ASM)
 void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
-                    const unsigned long length, const AES_KEY *key,
+                    size_t len, const AES_KEY *key,
                     unsigned char *ivec, const int enc) {
 
-       unsigned long n;
-       unsigned long len = length;
-       unsigned char tmp[AES_BLOCK_SIZE];
-       const unsigned char *iv = ivec;
-
-       assert(in && out && key && ivec);
-       assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc));
-
-       if (AES_ENCRYPT == enc) {
-               while (len >= AES_BLOCK_SIZE) {
-                       for(n=0; n < AES_BLOCK_SIZE; ++n)
-                               out[n] = in[n] ^ iv[n];
-                       AES_encrypt(out, out, key);
-                       iv = out;
-                       len -= AES_BLOCK_SIZE;
-                       in += AES_BLOCK_SIZE;
-                       out += AES_BLOCK_SIZE;
-               }
-               if (len) {
-                       for(n=0; n < len; ++n)
-                               out[n] = in[n] ^ iv[n];
-                       for(n=len; n < AES_BLOCK_SIZE; ++n)
-                               out[n] = iv[n];
-                       AES_encrypt(out, out, key);
-                       iv = out;
-               }
-               memcpy(ivec,iv,AES_BLOCK_SIZE);
-       } else if (in != out) {
-               while (len >= AES_BLOCK_SIZE) {
-                       AES_decrypt(in, out, key);
-                       for(n=0; n < AES_BLOCK_SIZE; ++n)
-                               out[n] ^= iv[n];
-                       iv = in;
-                       len -= AES_BLOCK_SIZE;
-                       in  += AES_BLOCK_SIZE;
-                       out += AES_BLOCK_SIZE;
-               }
-               if (len) {
-                       AES_decrypt(in,tmp,key);
-                       for(n=0; n < len; ++n)
-                               out[n] = tmp[n] ^ iv[n];
-                       iv = in;
-               }
-               memcpy(ivec,iv,AES_BLOCK_SIZE);
-       } else {
-               while (len >= AES_BLOCK_SIZE) {
-                       memcpy(tmp, in, AES_BLOCK_SIZE);
-                       AES_decrypt(in, out, key);
-                       for(n=0; n < AES_BLOCK_SIZE; ++n)
-                               out[n] ^= ivec[n];
-                       memcpy(ivec, tmp, AES_BLOCK_SIZE);
-                       len -= AES_BLOCK_SIZE;
-                       in += AES_BLOCK_SIZE;
-                       out += AES_BLOCK_SIZE;
-               }
-               if (len) {
-                       memcpy(tmp, in, AES_BLOCK_SIZE);
-                       AES_decrypt(tmp, out, key);
-                       for(n=0; n < len; ++n)
-                               out[n] ^= ivec[n];
-                       for(n=len; n < AES_BLOCK_SIZE; ++n)
-                               out[n] = tmp[n];
-                       memcpy(ivec, tmp, AES_BLOCK_SIZE);
-               }
-       }
+       if (enc)
+               CRYPTO_cbc128_encrypt(in,out,len,key,ivec,(block128_f)AES_encrypt);
+       else
+               CRYPTO_cbc128_decrypt(in,out,len,key,ivec,(block128_f)AES_decrypt);
 }
-#endif
index 9384ba6..0c6d058 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/aes/aes_cfb.c -*- mode:C; c-file-style: "eay" -*- */
 /* ====================================================================
- * Copyright (c) 1998-2002 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 2002-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * ====================================================================
  *
  */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-#ifndef AES_DEBUG
-# ifndef NDEBUG
-#  define NDEBUG
-# endif
-#endif
-#include <assert.h>
 
 #include <openssl/aes.h>
-#include "aes_locl.h"
-#include "e_os.h"
+#include <openssl/modes.h>
 
 /* The input and output encrypted as though 128bit cfb mode is being
  * used.  The extra state information to record how much of the
  */
 
 void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out,
-       const unsigned long length, const AES_KEY *key,
+       size_t length, const AES_KEY *key,
        unsigned char *ivec, int *num, const int enc) {
 
-       unsigned int n;
-       unsigned long l = length;
-       unsigned char c;
-
-       assert(in && out && key && ivec && num);
-
-       n = *num;
-
-       if (enc) {
-               while (l--) {
-                       if (n == 0) {
-                               AES_encrypt(ivec, ivec, key);
-                       }
-                       ivec[n] = *(out++) = *(in++) ^ ivec[n];
-                       n = (n+1) % AES_BLOCK_SIZE;
-               }
-       } else {
-               while (l--) {
-                       if (n == 0) {
-                               AES_encrypt(ivec, ivec, key);
-                       }
-                       c = *(in);
-                       *(out++) = *(in++) ^ ivec[n];
-                       ivec[n] = c;
-                       n = (n+1) % AES_BLOCK_SIZE;
-               }
-       }
-
-       *num=n;
+       CRYPTO_cfb128_encrypt(in,out,length,key,ivec,num,enc,(block128_f)AES_encrypt);
 }
 
-/* This expects a single block of size nbits for both in and out. Note that
-   it corrupts any extra bits in the last byte of out */
-void AES_cfbr_encrypt_block(const unsigned char *in,unsigned char *out,
-                           const int nbits,const AES_KEY *key,
-                           unsigned char *ivec,const int enc)
-    {
-    int n,rem,num;
-    unsigned char ovec[AES_BLOCK_SIZE*2];
-
-    if (nbits<=0 || nbits>128) return;
-
-       /* fill in the first half of the new IV with the current IV */
-       memcpy(ovec,ivec,AES_BLOCK_SIZE);
-       /* construct the new IV */
-       AES_encrypt(ivec,ivec,key);
-       num = (nbits+7)/8;
-       if (enc)        /* encrypt the input */
-           for(n=0 ; n < num ; ++n)
-               out[n] = (ovec[AES_BLOCK_SIZE+n] = in[n] ^ ivec[n]);
-       else            /* decrypt the input */
-           for(n=0 ; n < num ; ++n)
-               out[n] = (ovec[AES_BLOCK_SIZE+n] = in[n]) ^ ivec[n];
-       /* shift ovec left... */
-       rem = nbits%8;
-       num = nbits/8;
-       if(rem==0)
-           memcpy(ivec,ovec+num,AES_BLOCK_SIZE);
-       else
-           for(n=0 ; n < AES_BLOCK_SIZE ; ++n)
-               ivec[n] = ovec[n+num]<<rem | ovec[n+num+1]>>(8-rem);
-
-    /* it is not necessary to cleanse ovec, since the IV is not secret */
-    }
-
 /* N.B. This expects the input to be packed, MS bit first */
 void AES_cfb1_encrypt(const unsigned char *in, unsigned char *out,
-                     const unsigned long length, const AES_KEY *key,
+                     size_t length, const AES_KEY *key,
                      unsigned char *ivec, int *num, const int enc)
     {
-    unsigned int n;
-    unsigned char c[1],d[1];
-
-    assert(in && out && key && ivec && num);
-    assert(*num == 0);
-
-    for(n=0 ; n < length ; ++n)
-       {
-       c[0]=(in[n/8]&(1 << (7-n%8))) ? 0x80 : 0;
-       AES_cfbr_encrypt_block(c,d,1,key,ivec,enc);
-       out[n/8]=(out[n/8]&~(1 << (7-n%8)))|((d[0]&0x80) >> (n%8));
-       }
+    CRYPTO_cfb128_1_encrypt(in,out,length,key,ivec,num,enc,(block128_f)AES_encrypt);
     }
 
 void AES_cfb8_encrypt(const unsigned char *in, unsigned char *out,
-                     const unsigned long length, const AES_KEY *key,
+                     size_t length, const AES_KEY *key,
                      unsigned char *ivec, int *num, const int enc)
     {
-    unsigned int n;
-
-    assert(in && out && key && ivec && num);
-    assert(*num == 0);
-
-    for(n=0 ; n < length ; ++n)
-       AES_cfbr_encrypt_block(&in[n],&out[n],8,key,ivec,enc);
+    CRYPTO_cfb128_8_encrypt(in,out,length,key,ivec,num,enc,(block128_f)AES_encrypt);
     }
 
index cffdd4d..a7ec54f 100644 (file)
 
 #include <stdlib.h>
 #include <openssl/aes.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
 #include "aes_locl.h"
 
+#ifndef AES_ASM
 /*
 Te0[x] = S [x].[02, 01, 01, 03];
 Te1[x] = S [x].[03, 02, 01, 01];
@@ -635,10 +632,6 @@ int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
        int i = 0;
        u32 temp;
 
-#ifdef OPENSSL_FIPS
-       FIPS_selftest_check();
-#endif
-
        if (!userKey || !key)
                return -1;
        if (bits != 128 && bits != 192 && bits != 256)
@@ -781,7 +774,6 @@ int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
        return 0;
 }
 
-#ifndef AES_ASM
 /*
  * Encrypt a single block
  * in and out can overlap
@@ -1164,4 +1156,203 @@ void AES_decrypt(const unsigned char *in, unsigned char *out,
        PUTU32(out + 12, s3);
 }
 
+#else /* AES_ASM */
+
+static const u8 Te4[256] = {
+    0x63U, 0x7cU, 0x77U, 0x7bU, 0xf2U, 0x6bU, 0x6fU, 0xc5U,
+    0x30U, 0x01U, 0x67U, 0x2bU, 0xfeU, 0xd7U, 0xabU, 0x76U,
+    0xcaU, 0x82U, 0xc9U, 0x7dU, 0xfaU, 0x59U, 0x47U, 0xf0U,
+    0xadU, 0xd4U, 0xa2U, 0xafU, 0x9cU, 0xa4U, 0x72U, 0xc0U,
+    0xb7U, 0xfdU, 0x93U, 0x26U, 0x36U, 0x3fU, 0xf7U, 0xccU,
+    0x34U, 0xa5U, 0xe5U, 0xf1U, 0x71U, 0xd8U, 0x31U, 0x15U,
+    0x04U, 0xc7U, 0x23U, 0xc3U, 0x18U, 0x96U, 0x05U, 0x9aU,
+    0x07U, 0x12U, 0x80U, 0xe2U, 0xebU, 0x27U, 0xb2U, 0x75U,
+    0x09U, 0x83U, 0x2cU, 0x1aU, 0x1bU, 0x6eU, 0x5aU, 0xa0U,
+    0x52U, 0x3bU, 0xd6U, 0xb3U, 0x29U, 0xe3U, 0x2fU, 0x84U,
+    0x53U, 0xd1U, 0x00U, 0xedU, 0x20U, 0xfcU, 0xb1U, 0x5bU,
+    0x6aU, 0xcbU, 0xbeU, 0x39U, 0x4aU, 0x4cU, 0x58U, 0xcfU,
+    0xd0U, 0xefU, 0xaaU, 0xfbU, 0x43U, 0x4dU, 0x33U, 0x85U,
+    0x45U, 0xf9U, 0x02U, 0x7fU, 0x50U, 0x3cU, 0x9fU, 0xa8U,
+    0x51U, 0xa3U, 0x40U, 0x8fU, 0x92U, 0x9dU, 0x38U, 0xf5U,
+    0xbcU, 0xb6U, 0xdaU, 0x21U, 0x10U, 0xffU, 0xf3U, 0xd2U,
+    0xcdU, 0x0cU, 0x13U, 0xecU, 0x5fU, 0x97U, 0x44U, 0x17U,
+    0xc4U, 0xa7U, 0x7eU, 0x3dU, 0x64U, 0x5dU, 0x19U, 0x73U,
+    0x60U, 0x81U, 0x4fU, 0xdcU, 0x22U, 0x2aU, 0x90U, 0x88U,
+    0x46U, 0xeeU, 0xb8U, 0x14U, 0xdeU, 0x5eU, 0x0bU, 0xdbU,
+    0xe0U, 0x32U, 0x3aU, 0x0aU, 0x49U, 0x06U, 0x24U, 0x5cU,
+    0xc2U, 0xd3U, 0xacU, 0x62U, 0x91U, 0x95U, 0xe4U, 0x79U,
+    0xe7U, 0xc8U, 0x37U, 0x6dU, 0x8dU, 0xd5U, 0x4eU, 0xa9U,
+    0x6cU, 0x56U, 0xf4U, 0xeaU, 0x65U, 0x7aU, 0xaeU, 0x08U,
+    0xbaU, 0x78U, 0x25U, 0x2eU, 0x1cU, 0xa6U, 0xb4U, 0xc6U,
+    0xe8U, 0xddU, 0x74U, 0x1fU, 0x4bU, 0xbdU, 0x8bU, 0x8aU,
+    0x70U, 0x3eU, 0xb5U, 0x66U, 0x48U, 0x03U, 0xf6U, 0x0eU,
+    0x61U, 0x35U, 0x57U, 0xb9U, 0x86U, 0xc1U, 0x1dU, 0x9eU,
+    0xe1U, 0xf8U, 0x98U, 0x11U, 0x69U, 0xd9U, 0x8eU, 0x94U,
+    0x9bU, 0x1eU, 0x87U, 0xe9U, 0xceU, 0x55U, 0x28U, 0xdfU,
+    0x8cU, 0xa1U, 0x89U, 0x0dU, 0xbfU, 0xe6U, 0x42U, 0x68U,
+    0x41U, 0x99U, 0x2dU, 0x0fU, 0xb0U, 0x54U, 0xbbU, 0x16U
+};
+static const u32 rcon[] = {
+       0x01000000, 0x02000000, 0x04000000, 0x08000000,
+       0x10000000, 0x20000000, 0x40000000, 0x80000000,
+       0x1B000000, 0x36000000, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */
+};
+
+/**
+ * Expand the cipher key into the encryption key schedule.
+ */
+int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
+                       AES_KEY *key) {
+       u32 *rk;
+       int i = 0;
+       u32 temp;
+
+       if (!userKey || !key)
+               return -1;
+       if (bits != 128 && bits != 192 && bits != 256)
+               return -2;
+
+       rk = key->rd_key;
+
+       if (bits==128)
+               key->rounds = 10;
+       else if (bits==192)
+               key->rounds = 12;
+       else
+               key->rounds = 14;
+
+       rk[0] = GETU32(userKey     );
+       rk[1] = GETU32(userKey +  4);
+       rk[2] = GETU32(userKey +  8);
+       rk[3] = GETU32(userKey + 12);
+       if (bits == 128) {
+               while (1) {
+                       temp  = rk[3];
+                       rk[4] = rk[0] ^
+                               (Te4[(temp >> 16) & 0xff] << 24) ^
+                               (Te4[(temp >>  8) & 0xff] << 16) ^
+                               (Te4[(temp      ) & 0xff] << 8) ^
+                               (Te4[(temp >> 24)       ]) ^
+                               rcon[i];
+                       rk[5] = rk[1] ^ rk[4];
+                       rk[6] = rk[2] ^ rk[5];
+                       rk[7] = rk[3] ^ rk[6];
+                       if (++i == 10) {
+                               return 0;
+                       }
+                       rk += 4;
+               }
+       }
+       rk[4] = GETU32(userKey + 16);
+       rk[5] = GETU32(userKey + 20);
+       if (bits == 192) {
+               while (1) {
+                       temp = rk[ 5];
+                       rk[ 6] = rk[ 0] ^
+                               (Te4[(temp >> 16) & 0xff] << 24) ^
+                               (Te4[(temp >>  8) & 0xff] << 16) ^
+                               (Te4[(temp      ) & 0xff] << 8) ^
+                               (Te4[(temp >> 24)       ]) ^
+                               rcon[i];
+                       rk[ 7] = rk[ 1] ^ rk[ 6];
+                       rk[ 8] = rk[ 2] ^ rk[ 7];
+                       rk[ 9] = rk[ 3] ^ rk[ 8];
+                       if (++i == 8) {
+                               return 0;
+                       }
+                       rk[10] = rk[ 4] ^ rk[ 9];
+                       rk[11] = rk[ 5] ^ rk[10];
+                       rk += 6;
+               }
+       }
+       rk[6] = GETU32(userKey + 24);
+       rk[7] = GETU32(userKey + 28);
+       if (bits == 256) {
+               while (1) {
+                       temp = rk[ 7];
+                       rk[ 8] = rk[ 0] ^
+                               (Te4[(temp >> 16) & 0xff] << 24) ^
+                               (Te4[(temp >>  8) & 0xff] << 16) ^
+                               (Te4[(temp      ) & 0xff] << 8) ^
+                               (Te4[(temp >> 24)       ]) ^
+                               rcon[i];
+                       rk[ 9] = rk[ 1] ^ rk[ 8];
+                       rk[10] = rk[ 2] ^ rk[ 9];
+                       rk[11] = rk[ 3] ^ rk[10];
+                       if (++i == 7) {
+                               return 0;
+                       }
+                       temp = rk[11];
+                       rk[12] = rk[ 4] ^
+                               (Te4[(temp >> 24)       ] << 24) ^
+                               (Te4[(temp >> 16) & 0xff] << 16) ^
+                               (Te4[(temp >>  8) & 0xff] << 8) ^
+                               (Te4[(temp      ) & 0xff]);
+                       rk[13] = rk[ 5] ^ rk[12];
+                       rk[14] = rk[ 6] ^ rk[13];
+                       rk[15] = rk[ 7] ^ rk[14];
+
+                       rk += 8;
+               }
+       }
+       return 0;
+}
+
+/**
+ * Expand the cipher key into the decryption key schedule.
+ */
+int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
+                        AES_KEY *key) {
+
+        u32 *rk;
+       int i, j, status;
+       u32 temp;
+
+       /* first, start with an encryption schedule */
+       status = AES_set_encrypt_key(userKey, bits, key);
+       if (status < 0)
+               return status;
+
+       rk = key->rd_key;
+
+       /* invert the order of the round keys: */
+       for (i = 0, j = 4*(key->rounds); i < j; i += 4, j -= 4) {
+               temp = rk[i    ]; rk[i    ] = rk[j    ]; rk[j    ] = temp;
+               temp = rk[i + 1]; rk[i + 1] = rk[j + 1]; rk[j + 1] = temp;
+               temp = rk[i + 2]; rk[i + 2] = rk[j + 2]; rk[j + 2] = temp;
+               temp = rk[i + 3]; rk[i + 3] = rk[j + 3]; rk[j + 3] = temp;
+       }
+       /* apply the inverse MixColumn transform to all round keys but the first and the last: */
+       for (i = 1; i < (key->rounds); i++) {
+               rk += 4;
+               for (j = 0; j < 4; j++) {
+                       u32 tp1, tp2, tp4, tp8, tp9, tpb, tpd, tpe, m;
+
+                       tp1 = rk[j];
+                       m = tp1 & 0x80808080;
+                       tp2 = ((tp1 & 0x7f7f7f7f) << 1) ^
+                               ((m - (m >> 7)) & 0x1b1b1b1b);
+                       m = tp2 & 0x80808080;
+                       tp4 = ((tp2 & 0x7f7f7f7f) << 1) ^
+                               ((m - (m >> 7)) & 0x1b1b1b1b);
+                       m = tp4 & 0x80808080;
+                       tp8 = ((tp4 & 0x7f7f7f7f) << 1) ^
+                               ((m - (m >> 7)) & 0x1b1b1b1b);
+                       tp9 = tp8 ^ tp1;
+                       tpb = tp9 ^ tp2;
+                       tpd = tp9 ^ tp4;
+                       tpe = tp8 ^ tp4 ^ tp2;
+#if defined(ROTATE)
+                       rk[j] = tpe ^ ROTATE(tpd,16) ^
+                               ROTATE(tp9,24) ^ ROTATE(tpb,8);
+#else
+                       rk[j] = tpe ^ (tpd >> 16) ^ (tpd << 16) ^ 
+                               (tp9 >> 8) ^ (tp9 << 24) ^
+                               (tpb >> 24) ^ (tpb << 8);
+#endif
+               }
+       }
+       return 0;
+}
+
 #endif /* AES_ASM */
index f36982b..7c9d165 100644 (file)
  *
  */
 
-#ifndef AES_DEBUG
-# ifndef NDEBUG
-#  define NDEBUG
-# endif
-#endif
-#include <assert.h>
-
 #include <openssl/aes.h>
-#include "aes_locl.h"
-
-/* NOTE: the IV/counter CTR mode is big-endian.  The rest of the AES code
- * is endian-neutral. */
-
-/* increment counter (128-bit int) by 1 */
-static void AES_ctr128_inc(unsigned char *counter) {
-       unsigned long c;
-
-       /* Grab bottom dword of counter and increment */
-       c = GETU32(counter + 12);
-       c++;    c &= 0xFFFFFFFF;
-       PUTU32(counter + 12, c);
-
-       /* if no overflow, we're done */
-       if (c)
-               return;
-
-       /* Grab 1st dword of counter and increment */
-       c = GETU32(counter +  8);
-       c++;    c &= 0xFFFFFFFF;
-       PUTU32(counter +  8, c);
-
-       /* if no overflow, we're done */
-       if (c)
-               return;
-
-       /* Grab 2nd dword of counter and increment */
-       c = GETU32(counter +  4);
-       c++;    c &= 0xFFFFFFFF;
-       PUTU32(counter +  4, c);
-
-       /* if no overflow, we're done */
-       if (c)
-               return;
+#include <openssl/modes.h>
 
-       /* Grab top dword of counter and increment */
-       c = GETU32(counter +  0);
-       c++;    c &= 0xFFFFFFFF;
-       PUTU32(counter +  0, c);
-}
-
-/* The input encrypted as though 128bit counter mode is being
- * used.  The extra state information to record how much of the
- * 128bit block we have used is contained in *num, and the
- * encrypted counter is kept in ecount_buf.  Both *num and
- * ecount_buf must be initialised with zeros before the first
- * call to AES_ctr128_encrypt().
- *
- * This algorithm assumes that the counter is in the x lower bits
- * of the IV (ivec), and that the application has full control over
- * overflow and the rest of the IV.  This implementation takes NO
- * responsability for checking that the counter doesn't overflow
- * into the rest of the IV when incremented.
- */
 void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out,
-       const unsigned long length, const AES_KEY *key,
-       unsigned char ivec[AES_BLOCK_SIZE],
-       unsigned char ecount_buf[AES_BLOCK_SIZE],
-       unsigned int *num) {
-
-       unsigned int n;
-       unsigned long l=length;
-
-       assert(in && out && key && counter && num);
-       assert(*num < AES_BLOCK_SIZE);
-
-       n = *num;
-
-       while (l--) {
-               if (n == 0) {
-                       AES_encrypt(ivec, ecount_buf, key);
-                       AES_ctr128_inc(ivec);
-               }
-               *(out++) = *(in++) ^ ecount_buf[n];
-               n = (n+1) % AES_BLOCK_SIZE;
-       }
-
-       *num=n;
+                       size_t length, const AES_KEY *key,
+                       unsigned char ivec[AES_BLOCK_SIZE],
+                       unsigned char ecount_buf[AES_BLOCK_SIZE],
+                       unsigned int *num) {
+       CRYPTO_ctr128_encrypt(in,out,length,key,ivec,ecount_buf,num,(block128_f)AES_encrypt);
 }
index 45d7096..c161351 100644 (file)
@@ -77,11 +77,11 @@ typedef struct {
 /* N.B. The IV for this mode is _twice_ the block size */
 
 void AES_ige_encrypt(const unsigned char *in, unsigned char *out,
-                                        const unsigned long length, const AES_KEY *key,
+                                        size_t length, const AES_KEY *key,
                                         unsigned char *ivec, const int enc)
        {
-       unsigned long n;
-       unsigned long len;
+       size_t n;
+       size_t len = length;
 
        OPENSSL_assert(in && out && key && ivec);
        OPENSSL_assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc));
@@ -211,12 +211,12 @@ void AES_ige_encrypt(const unsigned char *in, unsigned char *out,
 /* N.B. The IV for this mode is _four times_ the block size */
 
 void AES_bi_ige_encrypt(const unsigned char *in, unsigned char *out,
-                                               const unsigned long length, const AES_KEY *key,
+                                               size_t length, const AES_KEY *key,
                                                const AES_KEY *key2, const unsigned char *ivec,
                                                const int enc)
        {
-       unsigned long n;
-       unsigned long len = length;
+       size_t n;
+       size_t len = length;
        unsigned char tmp[AES_BLOCK_SIZE];
        unsigned char tmp2[AES_BLOCK_SIZE];
        unsigned char tmp3[AES_BLOCK_SIZE];
index f358bb3..50bf0b8 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/aes/aes_ofb.c -*- mode:C; c-file-style: "eay" -*- */
 /* ====================================================================
- * Copyright (c) 1998-2002 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 2002-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * ====================================================================
  *
  */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-#ifndef AES_DEBUG
-# ifndef NDEBUG
-#  define NDEBUG
-# endif
-#endif
-#include <assert.h>
 
 #include <openssl/aes.h>
-#include "aes_locl.h"
+#include <openssl/modes.h>
 
-/* The input and output encrypted as though 128bit ofb mode is being
- * used.  The extra state information to record how much of the
- * 128bit block we have used is contained in *num;
- */
 void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out,
-       const unsigned long length, const AES_KEY *key,
-       unsigned char *ivec, int *num) {
-
-       unsigned int n;
-       unsigned long l=length;
-
-       assert(in && out && key && ivec && num);
-
-       n = *num;
-
-       while (l--) {
-               if (n == 0) {
-                       AES_encrypt(ivec, ivec, key);
-               }
-               *(out++) = *(in++) ^ ivec[n];
-               n = (n+1) % AES_BLOCK_SIZE;
-       }
-
-       *num=n;
+       size_t length, const AES_KEY *key,
+       unsigned char *ivec, int *num)
+{
+       CRYPTO_ofb128_encrypt(in,out,length,key,ivec,num,(block128_f)AES_encrypt);
 }
diff --git a/deps/openssl/openssl/crypto/aes/aes_x86core.c b/deps/openssl/openssl/crypto/aes/aes_x86core.c
new file mode 100644 (file)
index 0000000..d323e26
--- /dev/null
@@ -0,0 +1,1063 @@
+/* crypto/aes/aes_core.c -*- mode:C; c-file-style: "eay" -*- */
+/**
+ * rijndael-alg-fst.c
+ *
+ * @version 3.0 (December 2000)
+ *
+ * Optimised ANSI C code for the Rijndael cipher (now AES)
+ *
+ * @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
+ * @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
+ * @author Paulo Barreto <paulo.barreto@terra.com.br>
+ *
+ * This code is hereby placed in the public domain.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
+ * 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 AUTHORS OR 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.
+ */
+
+/*
+ * This is experimental x86[_64] derivative. It assumes little-endian
+ * byte order and expects CPU to sustain unaligned memory references.
+ * It is used as playground for cache-time attack mitigations and
+ * serves as reference C implementation for x86[_64] assembler.
+ *
+ *                                     <appro@fy.chalmers.se>
+ */
+
+
+#ifndef AES_DEBUG
+# ifndef NDEBUG
+#  define NDEBUG
+# endif
+#endif
+#include <assert.h>
+
+#include <stdlib.h>
+#include <openssl/aes.h>
+#include "aes_locl.h"
+
+/*
+ * These two parameters control which table, 256-byte or 2KB, is
+ * referenced in outer and respectively inner rounds.
+ */
+#define AES_COMPACT_IN_OUTER_ROUNDS
+#ifdef  AES_COMPACT_IN_OUTER_ROUNDS
+/* AES_COMPACT_IN_OUTER_ROUNDS costs ~30% in performance, while
+ * adding AES_COMPACT_IN_INNER_ROUNDS reduces benchmark *further*
+ * by factor of ~2. */
+# undef  AES_COMPACT_IN_INNER_ROUNDS
+#endif
+
+#if 1
+static void prefetch256(const void *table)
+{
+       volatile unsigned long *t=(void *)table,ret;
+       unsigned long sum;
+       int i;
+
+       /* 32 is common least cache-line size */
+       for (sum=0,i=0;i<256/sizeof(t[0]);i+=32/sizeof(t[0]))   sum ^= t[i];
+
+       ret = sum;
+}
+#else
+# define prefetch256(t)
+#endif
+
+#undef GETU32
+#define GETU32(p) (*((u32*)(p)))
+
+#if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__)
+typedef unsigned __int64 u64;
+#define U64(C) C##UI64
+#elif defined(__arch64__)
+typedef unsigned long u64;
+#define U64(C) C##UL
+#else
+typedef unsigned long long u64;
+#define U64(C) C##ULL
+#endif
+
+#undef ROTATE
+#if defined(_MSC_VER) || defined(__ICC)
+# define ROTATE(a,n)   _lrotl(a,n)
+#elif defined(__GNUC__) && __GNUC__>=2
+# if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)
+#   define ROTATE(a,n) ({ register unsigned int ret;   \
+                               asm (                   \
+                               "roll %1,%0"            \
+                               : "=r"(ret)             \
+                               : "I"(n), "0"(a)        \
+                               : "cc");                \
+                          ret;                         \
+                       })
+# endif
+#endif
+/*
+Te [x] = S [x].[02, 01, 01, 03, 02, 01, 01, 03];
+Te0[x] = S [x].[02, 01, 01, 03];
+Te1[x] = S [x].[03, 02, 01, 01];
+Te2[x] = S [x].[01, 03, 02, 01];
+Te3[x] = S [x].[01, 01, 03, 02];
+*/
+#define Te0 (u32)((u64*)((u8*)Te+0))
+#define Te1 (u32)((u64*)((u8*)Te+3))
+#define Te2 (u32)((u64*)((u8*)Te+2))
+#define Te3 (u32)((u64*)((u8*)Te+1))
+/*
+Td [x] = Si[x].[0e, 09, 0d, 0b, 0e, 09, 0d, 0b];
+Td0[x] = Si[x].[0e, 09, 0d, 0b];
+Td1[x] = Si[x].[0b, 0e, 09, 0d];
+Td2[x] = Si[x].[0d, 0b, 0e, 09];
+Td3[x] = Si[x].[09, 0d, 0b, 0e];
+Td4[x] = Si[x].[01];
+*/
+#define Td0 (u32)((u64*)((u8*)Td+0))
+#define Td1 (u32)((u64*)((u8*)Td+3))
+#define Td2 (u32)((u64*)((u8*)Td+2))
+#define Td3 (u32)((u64*)((u8*)Td+1))
+
+static const u64 Te[256] = {
+    U64(0xa56363c6a56363c6), U64(0x847c7cf8847c7cf8),
+    U64(0x997777ee997777ee), U64(0x8d7b7bf68d7b7bf6),
+    U64(0x0df2f2ff0df2f2ff), U64(0xbd6b6bd6bd6b6bd6),
+    U64(0xb16f6fdeb16f6fde), U64(0x54c5c59154c5c591),
+    U64(0x5030306050303060), U64(0x0301010203010102),
+    U64(0xa96767cea96767ce), U64(0x7d2b2b567d2b2b56),
+    U64(0x19fefee719fefee7), U64(0x62d7d7b562d7d7b5),
+    U64(0xe6abab4de6abab4d), U64(0x9a7676ec9a7676ec),
+    U64(0x45caca8f45caca8f), U64(0x9d82821f9d82821f),
+    U64(0x40c9c98940c9c989), U64(0x877d7dfa877d7dfa),
+    U64(0x15fafaef15fafaef), U64(0xeb5959b2eb5959b2),
+    U64(0xc947478ec947478e), U64(0x0bf0f0fb0bf0f0fb),
+    U64(0xecadad41ecadad41), U64(0x67d4d4b367d4d4b3),
+    U64(0xfda2a25ffda2a25f), U64(0xeaafaf45eaafaf45),
+    U64(0xbf9c9c23bf9c9c23), U64(0xf7a4a453f7a4a453),
+    U64(0x967272e4967272e4), U64(0x5bc0c09b5bc0c09b),
+    U64(0xc2b7b775c2b7b775), U64(0x1cfdfde11cfdfde1),
+    U64(0xae93933dae93933d), U64(0x6a26264c6a26264c),
+    U64(0x5a36366c5a36366c), U64(0x413f3f7e413f3f7e),
+    U64(0x02f7f7f502f7f7f5), U64(0x4fcccc834fcccc83),
+    U64(0x5c3434685c343468), U64(0xf4a5a551f4a5a551),
+    U64(0x34e5e5d134e5e5d1), U64(0x08f1f1f908f1f1f9),
+    U64(0x937171e2937171e2), U64(0x73d8d8ab73d8d8ab),
+    U64(0x5331316253313162), U64(0x3f15152a3f15152a),
+    U64(0x0c0404080c040408), U64(0x52c7c79552c7c795),
+    U64(0x6523234665232346), U64(0x5ec3c39d5ec3c39d),
+    U64(0x2818183028181830), U64(0xa1969637a1969637),
+    U64(0x0f05050a0f05050a), U64(0xb59a9a2fb59a9a2f),
+    U64(0x0907070e0907070e), U64(0x3612122436121224),
+    U64(0x9b80801b9b80801b), U64(0x3de2e2df3de2e2df),
+    U64(0x26ebebcd26ebebcd), U64(0x6927274e6927274e),
+    U64(0xcdb2b27fcdb2b27f), U64(0x9f7575ea9f7575ea),
+    U64(0x1b0909121b090912), U64(0x9e83831d9e83831d),
+    U64(0x742c2c58742c2c58), U64(0x2e1a1a342e1a1a34),
+    U64(0x2d1b1b362d1b1b36), U64(0xb26e6edcb26e6edc),
+    U64(0xee5a5ab4ee5a5ab4), U64(0xfba0a05bfba0a05b),
+    U64(0xf65252a4f65252a4), U64(0x4d3b3b764d3b3b76),
+    U64(0x61d6d6b761d6d6b7), U64(0xceb3b37dceb3b37d),
+    U64(0x7b2929527b292952), U64(0x3ee3e3dd3ee3e3dd),
+    U64(0x712f2f5e712f2f5e), U64(0x9784841397848413),
+    U64(0xf55353a6f55353a6), U64(0x68d1d1b968d1d1b9),
+    U64(0x0000000000000000), U64(0x2cededc12cededc1),
+    U64(0x6020204060202040), U64(0x1ffcfce31ffcfce3),
+    U64(0xc8b1b179c8b1b179), U64(0xed5b5bb6ed5b5bb6),
+    U64(0xbe6a6ad4be6a6ad4), U64(0x46cbcb8d46cbcb8d),
+    U64(0xd9bebe67d9bebe67), U64(0x4b3939724b393972),
+    U64(0xde4a4a94de4a4a94), U64(0xd44c4c98d44c4c98),
+    U64(0xe85858b0e85858b0), U64(0x4acfcf854acfcf85),
+    U64(0x6bd0d0bb6bd0d0bb), U64(0x2aefefc52aefefc5),
+    U64(0xe5aaaa4fe5aaaa4f), U64(0x16fbfbed16fbfbed),
+    U64(0xc5434386c5434386), U64(0xd74d4d9ad74d4d9a),
+    U64(0x5533336655333366), U64(0x9485851194858511),
+    U64(0xcf45458acf45458a), U64(0x10f9f9e910f9f9e9),
+    U64(0x0602020406020204), U64(0x817f7ffe817f7ffe),
+    U64(0xf05050a0f05050a0), U64(0x443c3c78443c3c78),
+    U64(0xba9f9f25ba9f9f25), U64(0xe3a8a84be3a8a84b),
+    U64(0xf35151a2f35151a2), U64(0xfea3a35dfea3a35d),
+    U64(0xc0404080c0404080), U64(0x8a8f8f058a8f8f05),
+    U64(0xad92923fad92923f), U64(0xbc9d9d21bc9d9d21),
+    U64(0x4838387048383870), U64(0x04f5f5f104f5f5f1),
+    U64(0xdfbcbc63dfbcbc63), U64(0xc1b6b677c1b6b677),
+    U64(0x75dadaaf75dadaaf), U64(0x6321214263212142),
+    U64(0x3010102030101020), U64(0x1affffe51affffe5),
+    U64(0x0ef3f3fd0ef3f3fd), U64(0x6dd2d2bf6dd2d2bf),
+    U64(0x4ccdcd814ccdcd81), U64(0x140c0c18140c0c18),
+    U64(0x3513132635131326), U64(0x2fececc32fececc3),
+    U64(0xe15f5fbee15f5fbe), U64(0xa2979735a2979735),
+    U64(0xcc444488cc444488), U64(0x3917172e3917172e),
+    U64(0x57c4c49357c4c493), U64(0xf2a7a755f2a7a755),
+    U64(0x827e7efc827e7efc), U64(0x473d3d7a473d3d7a),
+    U64(0xac6464c8ac6464c8), U64(0xe75d5dbae75d5dba),
+    U64(0x2b1919322b191932), U64(0x957373e6957373e6),
+    U64(0xa06060c0a06060c0), U64(0x9881811998818119),
+    U64(0xd14f4f9ed14f4f9e), U64(0x7fdcdca37fdcdca3),
+    U64(0x6622224466222244), U64(0x7e2a2a547e2a2a54),
+    U64(0xab90903bab90903b), U64(0x8388880b8388880b),
+    U64(0xca46468cca46468c), U64(0x29eeeec729eeeec7),
+    U64(0xd3b8b86bd3b8b86b), U64(0x3c1414283c141428),
+    U64(0x79dedea779dedea7), U64(0xe25e5ebce25e5ebc),
+    U64(0x1d0b0b161d0b0b16), U64(0x76dbdbad76dbdbad),
+    U64(0x3be0e0db3be0e0db), U64(0x5632326456323264),
+    U64(0x4e3a3a744e3a3a74), U64(0x1e0a0a141e0a0a14),
+    U64(0xdb494992db494992), U64(0x0a06060c0a06060c),
+    U64(0x6c2424486c242448), U64(0xe45c5cb8e45c5cb8),
+    U64(0x5dc2c29f5dc2c29f), U64(0x6ed3d3bd6ed3d3bd),
+    U64(0xefacac43efacac43), U64(0xa66262c4a66262c4),
+    U64(0xa8919139a8919139), U64(0xa4959531a4959531),
+    U64(0x37e4e4d337e4e4d3), U64(0x8b7979f28b7979f2),
+    U64(0x32e7e7d532e7e7d5), U64(0x43c8c88b43c8c88b),
+    U64(0x5937376e5937376e), U64(0xb76d6ddab76d6dda),
+    U64(0x8c8d8d018c8d8d01), U64(0x64d5d5b164d5d5b1),
+    U64(0xd24e4e9cd24e4e9c), U64(0xe0a9a949e0a9a949),
+    U64(0xb46c6cd8b46c6cd8), U64(0xfa5656acfa5656ac),
+    U64(0x07f4f4f307f4f4f3), U64(0x25eaeacf25eaeacf),
+    U64(0xaf6565caaf6565ca), U64(0x8e7a7af48e7a7af4),
+    U64(0xe9aeae47e9aeae47), U64(0x1808081018080810),
+    U64(0xd5baba6fd5baba6f), U64(0x887878f0887878f0),
+    U64(0x6f25254a6f25254a), U64(0x722e2e5c722e2e5c),
+    U64(0x241c1c38241c1c38), U64(0xf1a6a657f1a6a657),
+    U64(0xc7b4b473c7b4b473), U64(0x51c6c69751c6c697),
+    U64(0x23e8e8cb23e8e8cb), U64(0x7cdddda17cdddda1),
+    U64(0x9c7474e89c7474e8), U64(0x211f1f3e211f1f3e),
+    U64(0xdd4b4b96dd4b4b96), U64(0xdcbdbd61dcbdbd61),
+    U64(0x868b8b0d868b8b0d), U64(0x858a8a0f858a8a0f),
+    U64(0x907070e0907070e0), U64(0x423e3e7c423e3e7c),
+    U64(0xc4b5b571c4b5b571), U64(0xaa6666ccaa6666cc),
+    U64(0xd8484890d8484890), U64(0x0503030605030306),
+    U64(0x01f6f6f701f6f6f7), U64(0x120e0e1c120e0e1c),
+    U64(0xa36161c2a36161c2), U64(0x5f35356a5f35356a),
+    U64(0xf95757aef95757ae), U64(0xd0b9b969d0b9b969),
+    U64(0x9186861791868617), U64(0x58c1c19958c1c199),
+    U64(0x271d1d3a271d1d3a), U64(0xb99e9e27b99e9e27),
+    U64(0x38e1e1d938e1e1d9), U64(0x13f8f8eb13f8f8eb),
+    U64(0xb398982bb398982b), U64(0x3311112233111122),
+    U64(0xbb6969d2bb6969d2), U64(0x70d9d9a970d9d9a9),
+    U64(0x898e8e07898e8e07), U64(0xa7949433a7949433),
+    U64(0xb69b9b2db69b9b2d), U64(0x221e1e3c221e1e3c),
+    U64(0x9287871592878715), U64(0x20e9e9c920e9e9c9),
+    U64(0x49cece8749cece87), U64(0xff5555aaff5555aa),
+    U64(0x7828285078282850), U64(0x7adfdfa57adfdfa5),
+    U64(0x8f8c8c038f8c8c03), U64(0xf8a1a159f8a1a159),
+    U64(0x8089890980898909), U64(0x170d0d1a170d0d1a),
+    U64(0xdabfbf65dabfbf65), U64(0x31e6e6d731e6e6d7),
+    U64(0xc6424284c6424284), U64(0xb86868d0b86868d0),
+    U64(0xc3414182c3414182), U64(0xb0999929b0999929),
+    U64(0x772d2d5a772d2d5a), U64(0x110f0f1e110f0f1e),
+    U64(0xcbb0b07bcbb0b07b), U64(0xfc5454a8fc5454a8),
+    U64(0xd6bbbb6dd6bbbb6d), U64(0x3a16162c3a16162c)
+};
+
+static const u8 Te4[256] = {
+    0x63U, 0x7cU, 0x77U, 0x7bU, 0xf2U, 0x6bU, 0x6fU, 0xc5U,
+    0x30U, 0x01U, 0x67U, 0x2bU, 0xfeU, 0xd7U, 0xabU, 0x76U,
+    0xcaU, 0x82U, 0xc9U, 0x7dU, 0xfaU, 0x59U, 0x47U, 0xf0U,
+    0xadU, 0xd4U, 0xa2U, 0xafU, 0x9cU, 0xa4U, 0x72U, 0xc0U,
+    0xb7U, 0xfdU, 0x93U, 0x26U, 0x36U, 0x3fU, 0xf7U, 0xccU,
+    0x34U, 0xa5U, 0xe5U, 0xf1U, 0x71U, 0xd8U, 0x31U, 0x15U,
+    0x04U, 0xc7U, 0x23U, 0xc3U, 0x18U, 0x96U, 0x05U, 0x9aU,
+    0x07U, 0x12U, 0x80U, 0xe2U, 0xebU, 0x27U, 0xb2U, 0x75U,
+    0x09U, 0x83U, 0x2cU, 0x1aU, 0x1bU, 0x6eU, 0x5aU, 0xa0U,
+    0x52U, 0x3bU, 0xd6U, 0xb3U, 0x29U, 0xe3U, 0x2fU, 0x84U,
+    0x53U, 0xd1U, 0x00U, 0xedU, 0x20U, 0xfcU, 0xb1U, 0x5bU,
+    0x6aU, 0xcbU, 0xbeU, 0x39U, 0x4aU, 0x4cU, 0x58U, 0xcfU,
+    0xd0U, 0xefU, 0xaaU, 0xfbU, 0x43U, 0x4dU, 0x33U, 0x85U,
+    0x45U, 0xf9U, 0x02U, 0x7fU, 0x50U, 0x3cU, 0x9fU, 0xa8U,
+    0x51U, 0xa3U, 0x40U, 0x8fU, 0x92U, 0x9dU, 0x38U, 0xf5U,
+    0xbcU, 0xb6U, 0xdaU, 0x21U, 0x10U, 0xffU, 0xf3U, 0xd2U,
+    0xcdU, 0x0cU, 0x13U, 0xecU, 0x5fU, 0x97U, 0x44U, 0x17U,
+    0xc4U, 0xa7U, 0x7eU, 0x3dU, 0x64U, 0x5dU, 0x19U, 0x73U,
+    0x60U, 0x81U, 0x4fU, 0xdcU, 0x22U, 0x2aU, 0x90U, 0x88U,
+    0x46U, 0xeeU, 0xb8U, 0x14U, 0xdeU, 0x5eU, 0x0bU, 0xdbU,
+    0xe0U, 0x32U, 0x3aU, 0x0aU, 0x49U, 0x06U, 0x24U, 0x5cU,
+    0xc2U, 0xd3U, 0xacU, 0x62U, 0x91U, 0x95U, 0xe4U, 0x79U,
+    0xe7U, 0xc8U, 0x37U, 0x6dU, 0x8dU, 0xd5U, 0x4eU, 0xa9U,
+    0x6cU, 0x56U, 0xf4U, 0xeaU, 0x65U, 0x7aU, 0xaeU, 0x08U,
+    0xbaU, 0x78U, 0x25U, 0x2eU, 0x1cU, 0xa6U, 0xb4U, 0xc6U,
+    0xe8U, 0xddU, 0x74U, 0x1fU, 0x4bU, 0xbdU, 0x8bU, 0x8aU,
+    0x70U, 0x3eU, 0xb5U, 0x66U, 0x48U, 0x03U, 0xf6U, 0x0eU,
+    0x61U, 0x35U, 0x57U, 0xb9U, 0x86U, 0xc1U, 0x1dU, 0x9eU,
+    0xe1U, 0xf8U, 0x98U, 0x11U, 0x69U, 0xd9U, 0x8eU, 0x94U,
+    0x9bU, 0x1eU, 0x87U, 0xe9U, 0xceU, 0x55U, 0x28U, 0xdfU,
+    0x8cU, 0xa1U, 0x89U, 0x0dU, 0xbfU, 0xe6U, 0x42U, 0x68U,
+    0x41U, 0x99U, 0x2dU, 0x0fU, 0xb0U, 0x54U, 0xbbU, 0x16U
+};
+
+static const u64 Td[256] = {
+    U64(0x50a7f45150a7f451), U64(0x5365417e5365417e),
+    U64(0xc3a4171ac3a4171a), U64(0x965e273a965e273a),
+    U64(0xcb6bab3bcb6bab3b), U64(0xf1459d1ff1459d1f),
+    U64(0xab58faacab58faac), U64(0x9303e34b9303e34b),
+    U64(0x55fa302055fa3020), U64(0xf66d76adf66d76ad),
+    U64(0x9176cc889176cc88), U64(0x254c02f5254c02f5),
+    U64(0xfcd7e54ffcd7e54f), U64(0xd7cb2ac5d7cb2ac5),
+    U64(0x8044352680443526), U64(0x8fa362b58fa362b5),
+    U64(0x495ab1de495ab1de), U64(0x671bba25671bba25),
+    U64(0x980eea45980eea45), U64(0xe1c0fe5de1c0fe5d),
+    U64(0x02752fc302752fc3), U64(0x12f04c8112f04c81),
+    U64(0xa397468da397468d), U64(0xc6f9d36bc6f9d36b),
+    U64(0xe75f8f03e75f8f03), U64(0x959c9215959c9215),
+    U64(0xeb7a6dbfeb7a6dbf), U64(0xda595295da595295),
+    U64(0x2d83bed42d83bed4), U64(0xd3217458d3217458),
+    U64(0x2969e0492969e049), U64(0x44c8c98e44c8c98e),
+    U64(0x6a89c2756a89c275), U64(0x78798ef478798ef4),
+    U64(0x6b3e58996b3e5899), U64(0xdd71b927dd71b927),
+    U64(0xb64fe1beb64fe1be), U64(0x17ad88f017ad88f0),
+    U64(0x66ac20c966ac20c9), U64(0xb43ace7db43ace7d),
+    U64(0x184adf63184adf63), U64(0x82311ae582311ae5),
+    U64(0x6033519760335197), U64(0x457f5362457f5362),
+    U64(0xe07764b1e07764b1), U64(0x84ae6bbb84ae6bbb),
+    U64(0x1ca081fe1ca081fe), U64(0x942b08f9942b08f9),
+    U64(0x5868487058684870), U64(0x19fd458f19fd458f),
+    U64(0x876cde94876cde94), U64(0xb7f87b52b7f87b52),
+    U64(0x23d373ab23d373ab), U64(0xe2024b72e2024b72),
+    U64(0x578f1fe3578f1fe3), U64(0x2aab55662aab5566),
+    U64(0x0728ebb20728ebb2), U64(0x03c2b52f03c2b52f),
+    U64(0x9a7bc5869a7bc586), U64(0xa50837d3a50837d3),
+    U64(0xf2872830f2872830), U64(0xb2a5bf23b2a5bf23),
+    U64(0xba6a0302ba6a0302), U64(0x5c8216ed5c8216ed),
+    U64(0x2b1ccf8a2b1ccf8a), U64(0x92b479a792b479a7),
+    U64(0xf0f207f3f0f207f3), U64(0xa1e2694ea1e2694e),
+    U64(0xcdf4da65cdf4da65), U64(0xd5be0506d5be0506),
+    U64(0x1f6234d11f6234d1), U64(0x8afea6c48afea6c4),
+    U64(0x9d532e349d532e34), U64(0xa055f3a2a055f3a2),
+    U64(0x32e18a0532e18a05), U64(0x75ebf6a475ebf6a4),
+    U64(0x39ec830b39ec830b), U64(0xaaef6040aaef6040),
+    U64(0x069f715e069f715e), U64(0x51106ebd51106ebd),
+    U64(0xf98a213ef98a213e), U64(0x3d06dd963d06dd96),
+    U64(0xae053eddae053edd), U64(0x46bde64d46bde64d),
+    U64(0xb58d5491b58d5491), U64(0x055dc471055dc471),
+    U64(0x6fd406046fd40604), U64(0xff155060ff155060),
+    U64(0x24fb981924fb9819), U64(0x97e9bdd697e9bdd6),
+    U64(0xcc434089cc434089), U64(0x779ed967779ed967),
+    U64(0xbd42e8b0bd42e8b0), U64(0x888b8907888b8907),
+    U64(0x385b19e7385b19e7), U64(0xdbeec879dbeec879),
+    U64(0x470a7ca1470a7ca1), U64(0xe90f427ce90f427c),
+    U64(0xc91e84f8c91e84f8), U64(0x0000000000000000),
+    U64(0x8386800983868009), U64(0x48ed2b3248ed2b32),
+    U64(0xac70111eac70111e), U64(0x4e725a6c4e725a6c),
+    U64(0xfbff0efdfbff0efd), U64(0x5638850f5638850f),
+    U64(0x1ed5ae3d1ed5ae3d), U64(0x27392d3627392d36),
+    U64(0x64d90f0a64d90f0a), U64(0x21a65c6821a65c68),
+    U64(0xd1545b9bd1545b9b), U64(0x3a2e36243a2e3624),
+    U64(0xb1670a0cb1670a0c), U64(0x0fe757930fe75793),
+    U64(0xd296eeb4d296eeb4), U64(0x9e919b1b9e919b1b),
+    U64(0x4fc5c0804fc5c080), U64(0xa220dc61a220dc61),
+    U64(0x694b775a694b775a), U64(0x161a121c161a121c),
+    U64(0x0aba93e20aba93e2), U64(0xe52aa0c0e52aa0c0),
+    U64(0x43e0223c43e0223c), U64(0x1d171b121d171b12),
+    U64(0x0b0d090e0b0d090e), U64(0xadc78bf2adc78bf2),
+    U64(0xb9a8b62db9a8b62d), U64(0xc8a91e14c8a91e14),
+    U64(0x8519f1578519f157), U64(0x4c0775af4c0775af),
+    U64(0xbbdd99eebbdd99ee), U64(0xfd607fa3fd607fa3),
+    U64(0x9f2601f79f2601f7), U64(0xbcf5725cbcf5725c),
+    U64(0xc53b6644c53b6644), U64(0x347efb5b347efb5b),
+    U64(0x7629438b7629438b), U64(0xdcc623cbdcc623cb),
+    U64(0x68fcedb668fcedb6), U64(0x63f1e4b863f1e4b8),
+    U64(0xcadc31d7cadc31d7), U64(0x1085634210856342),
+    U64(0x4022971340229713), U64(0x2011c6842011c684),
+    U64(0x7d244a857d244a85), U64(0xf83dbbd2f83dbbd2),
+    U64(0x1132f9ae1132f9ae), U64(0x6da129c76da129c7),
+    U64(0x4b2f9e1d4b2f9e1d), U64(0xf330b2dcf330b2dc),
+    U64(0xec52860dec52860d), U64(0xd0e3c177d0e3c177),
+    U64(0x6c16b32b6c16b32b), U64(0x99b970a999b970a9),
+    U64(0xfa489411fa489411), U64(0x2264e9472264e947),
+    U64(0xc48cfca8c48cfca8), U64(0x1a3ff0a01a3ff0a0),
+    U64(0xd82c7d56d82c7d56), U64(0xef903322ef903322),
+    U64(0xc74e4987c74e4987), U64(0xc1d138d9c1d138d9),
+    U64(0xfea2ca8cfea2ca8c), U64(0x360bd498360bd498),
+    U64(0xcf81f5a6cf81f5a6), U64(0x28de7aa528de7aa5),
+    U64(0x268eb7da268eb7da), U64(0xa4bfad3fa4bfad3f),
+    U64(0xe49d3a2ce49d3a2c), U64(0x0d9278500d927850),
+    U64(0x9bcc5f6a9bcc5f6a), U64(0x62467e5462467e54),
+    U64(0xc2138df6c2138df6), U64(0xe8b8d890e8b8d890),
+    U64(0x5ef7392e5ef7392e), U64(0xf5afc382f5afc382),
+    U64(0xbe805d9fbe805d9f), U64(0x7c93d0697c93d069),
+    U64(0xa92dd56fa92dd56f), U64(0xb31225cfb31225cf),
+    U64(0x3b99acc83b99acc8), U64(0xa77d1810a77d1810),
+    U64(0x6e639ce86e639ce8), U64(0x7bbb3bdb7bbb3bdb),
+    U64(0x097826cd097826cd), U64(0xf418596ef418596e),
+    U64(0x01b79aec01b79aec), U64(0xa89a4f83a89a4f83),
+    U64(0x656e95e6656e95e6), U64(0x7ee6ffaa7ee6ffaa),
+    U64(0x08cfbc2108cfbc21), U64(0xe6e815efe6e815ef),
+    U64(0xd99be7bad99be7ba), U64(0xce366f4ace366f4a),
+    U64(0xd4099fead4099fea), U64(0xd67cb029d67cb029),
+    U64(0xafb2a431afb2a431), U64(0x31233f2a31233f2a),
+    U64(0x3094a5c63094a5c6), U64(0xc066a235c066a235),
+    U64(0x37bc4e7437bc4e74), U64(0xa6ca82fca6ca82fc),
+    U64(0xb0d090e0b0d090e0), U64(0x15d8a73315d8a733),
+    U64(0x4a9804f14a9804f1), U64(0xf7daec41f7daec41),
+    U64(0x0e50cd7f0e50cd7f), U64(0x2ff691172ff69117),
+    U64(0x8dd64d768dd64d76), U64(0x4db0ef434db0ef43),
+    U64(0x544daacc544daacc), U64(0xdf0496e4df0496e4),
+    U64(0xe3b5d19ee3b5d19e), U64(0x1b886a4c1b886a4c),
+    U64(0xb81f2cc1b81f2cc1), U64(0x7f5165467f516546),
+    U64(0x04ea5e9d04ea5e9d), U64(0x5d358c015d358c01),
+    U64(0x737487fa737487fa), U64(0x2e410bfb2e410bfb),
+    U64(0x5a1d67b35a1d67b3), U64(0x52d2db9252d2db92),
+    U64(0x335610e9335610e9), U64(0x1347d66d1347d66d),
+    U64(0x8c61d79a8c61d79a), U64(0x7a0ca1377a0ca137),
+    U64(0x8e14f8598e14f859), U64(0x893c13eb893c13eb),
+    U64(0xee27a9ceee27a9ce), U64(0x35c961b735c961b7),
+    U64(0xede51ce1ede51ce1), U64(0x3cb1477a3cb1477a),
+    U64(0x59dfd29c59dfd29c), U64(0x3f73f2553f73f255),
+    U64(0x79ce141879ce1418), U64(0xbf37c773bf37c773),
+    U64(0xeacdf753eacdf753), U64(0x5baafd5f5baafd5f),
+    U64(0x146f3ddf146f3ddf), U64(0x86db447886db4478),
+    U64(0x81f3afca81f3afca), U64(0x3ec468b93ec468b9),
+    U64(0x2c3424382c342438), U64(0x5f40a3c25f40a3c2),
+    U64(0x72c31d1672c31d16), U64(0x0c25e2bc0c25e2bc),
+    U64(0x8b493c288b493c28), U64(0x41950dff41950dff),
+    U64(0x7101a8397101a839), U64(0xdeb30c08deb30c08),
+    U64(0x9ce4b4d89ce4b4d8), U64(0x90c1566490c15664),
+    U64(0x6184cb7b6184cb7b), U64(0x70b632d570b632d5),
+    U64(0x745c6c48745c6c48), U64(0x4257b8d04257b8d0)
+};
+static const u8 Td4[256] = {
+    0x52U, 0x09U, 0x6aU, 0xd5U, 0x30U, 0x36U, 0xa5U, 0x38U,
+    0xbfU, 0x40U, 0xa3U, 0x9eU, 0x81U, 0xf3U, 0xd7U, 0xfbU,
+    0x7cU, 0xe3U, 0x39U, 0x82U, 0x9bU, 0x2fU, 0xffU, 0x87U,
+    0x34U, 0x8eU, 0x43U, 0x44U, 0xc4U, 0xdeU, 0xe9U, 0xcbU,
+    0x54U, 0x7bU, 0x94U, 0x32U, 0xa6U, 0xc2U, 0x23U, 0x3dU,
+    0xeeU, 0x4cU, 0x95U, 0x0bU, 0x42U, 0xfaU, 0xc3U, 0x4eU,
+    0x08U, 0x2eU, 0xa1U, 0x66U, 0x28U, 0xd9U, 0x24U, 0xb2U,
+    0x76U, 0x5bU, 0xa2U, 0x49U, 0x6dU, 0x8bU, 0xd1U, 0x25U,
+    0x72U, 0xf8U, 0xf6U, 0x64U, 0x86U, 0x68U, 0x98U, 0x16U,
+    0xd4U, 0xa4U, 0x5cU, 0xccU, 0x5dU, 0x65U, 0xb6U, 0x92U,
+    0x6cU, 0x70U, 0x48U, 0x50U, 0xfdU, 0xedU, 0xb9U, 0xdaU,
+    0x5eU, 0x15U, 0x46U, 0x57U, 0xa7U, 0x8dU, 0x9dU, 0x84U,
+    0x90U, 0xd8U, 0xabU, 0x00U, 0x8cU, 0xbcU, 0xd3U, 0x0aU,
+    0xf7U, 0xe4U, 0x58U, 0x05U, 0xb8U, 0xb3U, 0x45U, 0x06U,
+    0xd0U, 0x2cU, 0x1eU, 0x8fU, 0xcaU, 0x3fU, 0x0fU, 0x02U,
+    0xc1U, 0xafU, 0xbdU, 0x03U, 0x01U, 0x13U, 0x8aU, 0x6bU,
+    0x3aU, 0x91U, 0x11U, 0x41U, 0x4fU, 0x67U, 0xdcU, 0xeaU,
+    0x97U, 0xf2U, 0xcfU, 0xceU, 0xf0U, 0xb4U, 0xe6U, 0x73U,
+    0x96U, 0xacU, 0x74U, 0x22U, 0xe7U, 0xadU, 0x35U, 0x85U,
+    0xe2U, 0xf9U, 0x37U, 0xe8U, 0x1cU, 0x75U, 0xdfU, 0x6eU,
+    0x47U, 0xf1U, 0x1aU, 0x71U, 0x1dU, 0x29U, 0xc5U, 0x89U,
+    0x6fU, 0xb7U, 0x62U, 0x0eU, 0xaaU, 0x18U, 0xbeU, 0x1bU,
+    0xfcU, 0x56U, 0x3eU, 0x4bU, 0xc6U, 0xd2U, 0x79U, 0x20U,
+    0x9aU, 0xdbU, 0xc0U, 0xfeU, 0x78U, 0xcdU, 0x5aU, 0xf4U,
+    0x1fU, 0xddU, 0xa8U, 0x33U, 0x88U, 0x07U, 0xc7U, 0x31U,
+    0xb1U, 0x12U, 0x10U, 0x59U, 0x27U, 0x80U, 0xecU, 0x5fU,
+    0x60U, 0x51U, 0x7fU, 0xa9U, 0x19U, 0xb5U, 0x4aU, 0x0dU,
+    0x2dU, 0xe5U, 0x7aU, 0x9fU, 0x93U, 0xc9U, 0x9cU, 0xefU,
+    0xa0U, 0xe0U, 0x3bU, 0x4dU, 0xaeU, 0x2aU, 0xf5U, 0xb0U,
+    0xc8U, 0xebU, 0xbbU, 0x3cU, 0x83U, 0x53U, 0x99U, 0x61U,
+    0x17U, 0x2bU, 0x04U, 0x7eU, 0xbaU, 0x77U, 0xd6U, 0x26U,
+    0xe1U, 0x69U, 0x14U, 0x63U, 0x55U, 0x21U, 0x0cU, 0x7dU
+};
+
+static const u32 rcon[] = {
+    0x00000001U, 0x00000002U, 0x00000004U, 0x00000008U,
+    0x00000010U, 0x00000020U, 0x00000040U, 0x00000080U,
+    0x0000001bU, 0x00000036U, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */
+};
+
+/**
+ * Expand the cipher key into the encryption key schedule.
+ */
+int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
+                       AES_KEY *key) {
+
+       u32 *rk;
+       int i = 0;
+       u32 temp;
+
+       if (!userKey || !key)
+               return -1;
+       if (bits != 128 && bits != 192 && bits != 256)
+               return -2;
+
+       rk = key->rd_key;
+
+       if (bits==128)
+               key->rounds = 10;
+       else if (bits==192)
+               key->rounds = 12;
+       else
+               key->rounds = 14;
+
+       rk[0] = GETU32(userKey     );
+       rk[1] = GETU32(userKey +  4);
+       rk[2] = GETU32(userKey +  8);
+       rk[3] = GETU32(userKey + 12);
+       if (bits == 128) {
+               while (1) {
+                       temp  = rk[3];
+                       rk[4] = rk[0] ^
+                               (Te4[(temp >>  8) & 0xff]      ) ^
+                               (Te4[(temp >> 16) & 0xff] <<  8) ^
+                               (Te4[(temp >> 24)       ] << 16) ^
+                               (Te4[(temp      ) & 0xff] << 24) ^
+                               rcon[i];
+                       rk[5] = rk[1] ^ rk[4];
+                       rk[6] = rk[2] ^ rk[5];
+                       rk[7] = rk[3] ^ rk[6];
+                       if (++i == 10) {
+                               return 0;
+                       }
+                       rk += 4;
+               }
+       }
+       rk[4] = GETU32(userKey + 16);
+       rk[5] = GETU32(userKey + 20);
+       if (bits == 192) {
+               while (1) {
+                       temp = rk[ 5];
+                       rk[ 6] = rk[ 0] ^
+                               (Te4[(temp >>  8) & 0xff]      ) ^
+                               (Te4[(temp >> 16) & 0xff] <<  8) ^
+                               (Te4[(temp >> 24)       ] << 16) ^
+                               (Te4[(temp      ) & 0xff] << 24) ^
+                               rcon[i];
+                       rk[ 7] = rk[ 1] ^ rk[ 6];
+                       rk[ 8] = rk[ 2] ^ rk[ 7];
+                       rk[ 9] = rk[ 3] ^ rk[ 8];
+                       if (++i == 8) {
+                               return 0;
+                       }
+                       rk[10] = rk[ 4] ^ rk[ 9];
+                       rk[11] = rk[ 5] ^ rk[10];
+                       rk += 6;
+               }
+       }
+       rk[6] = GETU32(userKey + 24);
+       rk[7] = GETU32(userKey + 28);
+       if (bits == 256) {
+               while (1) {
+                       temp = rk[ 7];
+                       rk[ 8] = rk[ 0] ^
+                               (Te4[(temp >>  8) & 0xff]      ) ^
+                               (Te4[(temp >> 16) & 0xff] <<  8) ^
+                               (Te4[(temp >> 24)       ] << 16) ^
+                               (Te4[(temp      ) & 0xff] << 24) ^
+                               rcon[i];
+                       rk[ 9] = rk[ 1] ^ rk[ 8];
+                       rk[10] = rk[ 2] ^ rk[ 9];
+                       rk[11] = rk[ 3] ^ rk[10];
+                       if (++i == 7) {
+                               return 0;
+                       }
+                       temp = rk[11];
+                       rk[12] = rk[ 4] ^
+                               (Te4[(temp      ) & 0xff]      ) ^
+                               (Te4[(temp >>  8) & 0xff] <<  8) ^
+                               (Te4[(temp >> 16) & 0xff] << 16) ^
+                               (Te4[(temp >> 24)       ] << 24);
+                       rk[13] = rk[ 5] ^ rk[12];
+                       rk[14] = rk[ 6] ^ rk[13];
+                       rk[15] = rk[ 7] ^ rk[14];
+
+                       rk += 8;
+               }
+       }
+       return 0;
+}
+
+/**
+ * Expand the cipher key into the decryption key schedule.
+ */
+int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
+                        AES_KEY *key) {
+
+        u32 *rk;
+       int i, j, status;
+       u32 temp;
+
+       /* first, start with an encryption schedule */
+       status = AES_set_encrypt_key(userKey, bits, key);
+       if (status < 0)
+               return status;
+
+       rk = key->rd_key;
+
+       /* invert the order of the round keys: */
+       for (i = 0, j = 4*(key->rounds); i < j; i += 4, j -= 4) {
+               temp = rk[i    ]; rk[i    ] = rk[j    ]; rk[j    ] = temp;
+               temp = rk[i + 1]; rk[i + 1] = rk[j + 1]; rk[j + 1] = temp;
+               temp = rk[i + 2]; rk[i + 2] = rk[j + 2]; rk[j + 2] = temp;
+               temp = rk[i + 3]; rk[i + 3] = rk[j + 3]; rk[j + 3] = temp;
+       }
+       /* apply the inverse MixColumn transform to all round keys but the first and the last: */
+       for (i = 1; i < (key->rounds); i++) {
+               rk += 4;
+#if 1
+               for (j = 0; j < 4; j++) {
+                       u32 tp1, tp2, tp4, tp8, tp9, tpb, tpd, tpe, m;
+
+                       tp1 = rk[j];
+                       m = tp1 & 0x80808080;
+                       tp2 = ((tp1 & 0x7f7f7f7f) << 1) ^
+                               ((m - (m >> 7)) & 0x1b1b1b1b);
+                       m = tp2 & 0x80808080;
+                       tp4 = ((tp2 & 0x7f7f7f7f) << 1) ^
+                               ((m - (m >> 7)) & 0x1b1b1b1b);
+                       m = tp4 & 0x80808080;
+                       tp8 = ((tp4 & 0x7f7f7f7f) << 1) ^
+                               ((m - (m >> 7)) & 0x1b1b1b1b);
+                       tp9 = tp8 ^ tp1;
+                       tpb = tp9 ^ tp2;
+                       tpd = tp9 ^ tp4;
+                       tpe = tp8 ^ tp4 ^ tp2;
+#if defined(ROTATE)
+                       rk[j] = tpe ^ ROTATE(tpd,16) ^
+                               ROTATE(tp9,8) ^ ROTATE(tpb,24);
+#else
+                       rk[j] = tpe ^ (tpd >> 16) ^ (tpd << 16) ^ 
+                               (tp9 >> 24) ^ (tp9 << 8) ^
+                               (tpb >> 8) ^ (tpb << 24);
+#endif
+               }
+#else
+               rk[0] =
+                       Td0[Te2[(rk[0]      ) & 0xff] & 0xff] ^
+                       Td1[Te2[(rk[0] >>  8) & 0xff] & 0xff] ^
+                       Td2[Te2[(rk[0] >> 16) & 0xff] & 0xff] ^
+                       Td3[Te2[(rk[0] >> 24)       ] & 0xff];
+               rk[1] =
+                       Td0[Te2[(rk[1]      ) & 0xff] & 0xff] ^
+                       Td1[Te2[(rk[1] >>  8) & 0xff] & 0xff] ^
+                       Td2[Te2[(rk[1] >> 16) & 0xff] & 0xff] ^
+                       Td3[Te2[(rk[1] >> 24)       ] & 0xff];
+               rk[2] =
+                       Td0[Te2[(rk[2]      ) & 0xff] & 0xff] ^
+                       Td1[Te2[(rk[2] >>  8) & 0xff] & 0xff] ^
+                       Td2[Te2[(rk[2] >> 16) & 0xff] & 0xff] ^
+                       Td3[Te2[(rk[2] >> 24)       ] & 0xff];
+               rk[3] =
+                       Td0[Te2[(rk[3]      ) & 0xff] & 0xff] ^
+                       Td1[Te2[(rk[3] >>  8) & 0xff] & 0xff] ^
+                       Td2[Te2[(rk[3] >> 16) & 0xff] & 0xff] ^
+                       Td3[Te2[(rk[3] >> 24)       ] & 0xff];
+#endif
+       }
+       return 0;
+}
+
+/*
+ * Encrypt a single block
+ * in and out can overlap
+ */
+void AES_encrypt(const unsigned char *in, unsigned char *out,
+                const AES_KEY *key) {
+
+       const u32 *rk;
+       u32 s0, s1, s2, s3, t[4];
+       int r;
+
+       assert(in && out && key);
+       rk = key->rd_key;
+
+       /*
+        * map byte array block to cipher state
+        * and add initial round key:
+        */
+       s0 = GETU32(in     ) ^ rk[0];
+       s1 = GETU32(in +  4) ^ rk[1];
+       s2 = GETU32(in +  8) ^ rk[2];
+       s3 = GETU32(in + 12) ^ rk[3];
+
+#if defined(AES_COMPACT_IN_OUTER_ROUNDS)
+       prefetch256(Te4);
+
+       t[0] =  Te4[(s0      ) & 0xff]       ^
+               Te4[(s1 >>  8) & 0xff] <<  8 ^
+               Te4[(s2 >> 16) & 0xff] << 16 ^
+               Te4[(s3 >> 24)       ] << 24;
+       t[1] =  Te4[(s1      ) & 0xff]       ^
+               Te4[(s2 >>  8) & 0xff] <<  8 ^
+               Te4[(s3 >> 16) & 0xff] << 16 ^
+               Te4[(s0 >> 24)       ] << 24;
+       t[2] =  Te4[(s2      ) & 0xff]       ^
+               Te4[(s3 >>  8) & 0xff] <<  8 ^
+               Te4[(s0 >> 16) & 0xff] << 16 ^
+               Te4[(s1 >> 24)       ] << 24;
+       t[3] =  Te4[(s3      ) & 0xff]       ^
+               Te4[(s0 >>  8) & 0xff] <<  8 ^
+               Te4[(s1 >> 16) & 0xff] << 16 ^
+               Te4[(s2 >> 24)       ] << 24;
+
+       /* now do the linear transform using words */
+       {       int i;
+               u32 r0, r1, r2;
+
+               for (i = 0; i < 4; i++) {
+                       r0 = t[i];
+                       r1 = r0 & 0x80808080;
+                       r2 = ((r0 & 0x7f7f7f7f) << 1) ^
+                               ((r1 - (r1 >> 7)) & 0x1b1b1b1b);
+#if defined(ROTATE)
+                       t[i] = r2 ^ ROTATE(r2,24) ^ ROTATE(r0,24) ^
+                               ROTATE(r0,16) ^ ROTATE(r0,8);
+#else
+                       t[i] = r2 ^ ((r2 ^ r0) << 24) ^ ((r2 ^ r0) >> 8) ^
+                               (r0 << 16) ^ (r0 >> 16) ^
+                               (r0 << 8) ^ (r0 >> 24);
+#endif
+                       t[i] ^= rk[4+i];
+               }
+       }
+#else
+       t[0] =  Te0[(s0      ) & 0xff] ^
+               Te1[(s1 >>  8) & 0xff] ^
+               Te2[(s2 >> 16) & 0xff] ^
+               Te3[(s3 >> 24)       ] ^
+               rk[4];
+       t[1] =  Te0[(s1      ) & 0xff] ^
+               Te1[(s2 >>  8) & 0xff] ^
+               Te2[(s3 >> 16) & 0xff] ^
+               Te3[(s0 >> 24)       ] ^
+               rk[5];
+       t[2] =  Te0[(s2      ) & 0xff] ^
+               Te1[(s3 >>  8) & 0xff] ^
+               Te2[(s0 >> 16) & 0xff] ^
+               Te3[(s1 >> 24)       ] ^
+               rk[6];
+       t[3] =  Te0[(s3      ) & 0xff] ^
+               Te1[(s0 >>  8) & 0xff] ^
+               Te2[(s1 >> 16) & 0xff] ^
+               Te3[(s2 >> 24)       ] ^
+               rk[7];
+#endif
+       s0 = t[0]; s1 = t[1]; s2 = t[2]; s3 = t[3];
+
+    /*
+     * Nr - 2 full rounds:
+     */
+    for (rk+=8,r=key->rounds-2; r>0; rk+=4,r--) {
+#if defined(AES_COMPACT_IN_INNER_ROUNDS)
+       t[0] =  Te4[(s0      ) & 0xff]       ^
+               Te4[(s1 >>  8) & 0xff] <<  8 ^
+               Te4[(s2 >> 16) & 0xff] << 16 ^
+               Te4[(s3 >> 24)       ] << 24;
+       t[1] =  Te4[(s1      ) & 0xff]       ^
+               Te4[(s2 >>  8) & 0xff] <<  8 ^
+               Te4[(s3 >> 16) & 0xff] << 16 ^
+               Te4[(s0 >> 24)       ] << 24;
+       t[2] =  Te4[(s2      ) & 0xff]       ^
+               Te4[(s3 >>  8) & 0xff] <<  8 ^
+               Te4[(s0 >> 16) & 0xff] << 16 ^
+               Te4[(s1 >> 24)       ] << 24;
+       t[3] =  Te4[(s3      ) & 0xff]       ^
+               Te4[(s0 >>  8) & 0xff] <<  8 ^
+               Te4[(s1 >> 16) & 0xff] << 16 ^
+               Te4[(s2 >> 24)       ] << 24;
+
+       /* now do the linear transform using words */
+       {       int i;
+               u32 r0, r1, r2;
+
+               for (i = 0; i < 4; i++) {
+                       r0 = t[i];
+                       r1 = r0 & 0x80808080;
+                       r2 = ((r0 & 0x7f7f7f7f) << 1) ^
+                               ((r1 - (r1 >> 7)) & 0x1b1b1b1b);
+#if defined(ROTATE)
+                       t[i] = r2 ^ ROTATE(r2,24) ^ ROTATE(r0,24) ^
+                               ROTATE(r0,16) ^ ROTATE(r0,8);
+#else
+                       t[i] = r2 ^ ((r2 ^ r0) << 24) ^ ((r2 ^ r0) >> 8) ^
+                               (r0 << 16) ^ (r0 >> 16) ^
+                               (r0 << 8) ^ (r0 >> 24);
+#endif
+                       t[i] ^= rk[i];
+               }
+       }
+#else
+       t[0] =  Te0[(s0      ) & 0xff] ^
+               Te1[(s1 >>  8) & 0xff] ^
+               Te2[(s2 >> 16) & 0xff] ^
+               Te3[(s3 >> 24)       ] ^
+               rk[0];
+       t[1] =  Te0[(s1      ) & 0xff] ^
+               Te1[(s2 >>  8) & 0xff] ^
+               Te2[(s3 >> 16) & 0xff] ^
+               Te3[(s0 >> 24)       ] ^
+               rk[1];
+       t[2] =  Te0[(s2      ) & 0xff] ^
+               Te1[(s3 >>  8) & 0xff] ^
+               Te2[(s0 >> 16) & 0xff] ^
+               Te3[(s1 >> 24)       ] ^
+               rk[2];
+       t[3] =  Te0[(s3      ) & 0xff] ^
+               Te1[(s0 >>  8) & 0xff] ^
+               Te2[(s1 >> 16) & 0xff] ^
+               Te3[(s2 >> 24)       ] ^
+               rk[3];
+#endif
+       s0 = t[0]; s1 = t[1]; s2 = t[2]; s3 = t[3];
+    }
+    /*
+        * apply last round and
+        * map cipher state to byte array block:
+        */
+#if defined(AES_COMPACT_IN_OUTER_ROUNDS)
+       prefetch256(Te4);
+
+       *(u32*)(out+0) =
+               Te4[(s0      ) & 0xff]       ^
+               Te4[(s1 >>  8) & 0xff] <<  8 ^
+               Te4[(s2 >> 16) & 0xff] << 16 ^
+               Te4[(s3 >> 24)       ] << 24 ^
+               rk[0];
+       *(u32*)(out+4) =
+               Te4[(s1      ) & 0xff]       ^
+               Te4[(s2 >>  8) & 0xff] <<  8 ^
+               Te4[(s3 >> 16) & 0xff] << 16 ^
+               Te4[(s0 >> 24)       ] << 24 ^
+               rk[1];
+       *(u32*)(out+8) =
+               Te4[(s2      ) & 0xff]       ^
+               Te4[(s3 >>  8) & 0xff] <<  8 ^
+               Te4[(s0 >> 16) & 0xff] << 16 ^
+               Te4[(s1 >> 24)       ] << 24 ^
+               rk[2];
+       *(u32*)(out+12) =
+               Te4[(s3      ) & 0xff]       ^
+               Te4[(s0 >>  8) & 0xff] <<  8 ^
+               Te4[(s1 >> 16) & 0xff] << 16 ^
+               Te4[(s2 >> 24)       ] << 24 ^
+               rk[3];
+#else
+       *(u32*)(out+0) =
+               (Te2[(s0      ) & 0xff] & 0x000000ffU) ^
+               (Te3[(s1 >>  8) & 0xff] & 0x0000ff00U) ^
+               (Te0[(s2 >> 16) & 0xff] & 0x00ff0000U) ^
+               (Te1[(s3 >> 24)       ] & 0xff000000U) ^
+               rk[0];
+       *(u32*)(out+4) =
+               (Te2[(s1      ) & 0xff] & 0x000000ffU) ^
+               (Te3[(s2 >>  8) & 0xff] & 0x0000ff00U) ^
+               (Te0[(s3 >> 16) & 0xff] & 0x00ff0000U) ^
+               (Te1[(s0 >> 24)       ] & 0xff000000U) ^
+               rk[1];
+       *(u32*)(out+8) =
+               (Te2[(s2      ) & 0xff] & 0x000000ffU) ^
+               (Te3[(s3 >>  8) & 0xff] & 0x0000ff00U) ^
+               (Te0[(s0 >> 16) & 0xff] & 0x00ff0000U) ^
+               (Te1[(s1 >> 24)       ] & 0xff000000U) ^
+               rk[2];
+       *(u32*)(out+12) =
+               (Te2[(s3      ) & 0xff] & 0x000000ffU) ^
+               (Te3[(s0 >>  8) & 0xff] & 0x0000ff00U) ^
+               (Te0[(s1 >> 16) & 0xff] & 0x00ff0000U) ^
+               (Te1[(s2 >> 24)       ] & 0xff000000U) ^
+               rk[3];
+#endif
+}
+
+/*
+ * Decrypt a single block
+ * in and out can overlap
+ */
+void AES_decrypt(const unsigned char *in, unsigned char *out,
+                const AES_KEY *key) {
+
+       const u32 *rk;
+       u32 s0, s1, s2, s3, t[4];
+       int r;
+
+       assert(in && out && key);
+       rk = key->rd_key;
+
+       /*
+        * map byte array block to cipher state
+        * and add initial round key:
+        */
+       s0 = GETU32(in     ) ^ rk[0];
+       s1 = GETU32(in +  4) ^ rk[1];
+       s2 = GETU32(in +  8) ^ rk[2];
+       s3 = GETU32(in + 12) ^ rk[3];
+
+#if defined(AES_COMPACT_IN_OUTER_ROUNDS)
+       prefetch256(Td4);
+
+        t[0] = Td4[(s0      ) & 0xff]       ^
+               Td4[(s3 >>  8) & 0xff] <<  8 ^
+               Td4[(s2 >> 16) & 0xff] << 16 ^
+               Td4[(s1 >> 24)       ] << 24;
+        t[1] = Td4[(s1      ) & 0xff]       ^
+               Td4[(s0 >>  8) & 0xff] <<  8 ^
+               Td4[(s3 >> 16) & 0xff] << 16 ^
+               Td4[(s2 >> 24)       ] << 24;
+        t[2] = Td4[(s2      ) & 0xff]       ^
+               Td4[(s1 >>  8) & 0xff] <<  8 ^
+               Td4[(s0 >> 16) & 0xff] << 16 ^
+               Td4[(s3 >> 24)       ] << 24;
+        t[3] = Td4[(s3      ) & 0xff]       ^
+               Td4[(s2 >>  8) & 0xff] <<  8 ^
+               Td4[(s1 >> 16) & 0xff] << 16 ^
+               Td4[(s0 >> 24)       ] << 24;
+
+       /* now do the linear transform using words */ 
+       {       int i;
+               u32 tp1, tp2, tp4, tp8, tp9, tpb, tpd, tpe, m;
+
+               for (i = 0; i < 4; i++) {
+                       tp1 = t[i];
+                       m = tp1 & 0x80808080;
+                       tp2 = ((tp1 & 0x7f7f7f7f) << 1) ^
+                               ((m - (m >> 7)) & 0x1b1b1b1b);
+                       m = tp2 & 0x80808080;
+                       tp4 = ((tp2 & 0x7f7f7f7f) << 1) ^
+                               ((m - (m >> 7)) & 0x1b1b1b1b);
+                       m = tp4 & 0x80808080;
+                       tp8 = ((tp4 & 0x7f7f7f7f) << 1) ^
+                               ((m - (m >> 7)) & 0x1b1b1b1b);
+                       tp9 = tp8 ^ tp1;
+                       tpb = tp9 ^ tp2;
+                       tpd = tp9 ^ tp4;
+                       tpe = tp8 ^ tp4 ^ tp2;
+#if defined(ROTATE)
+                       t[i] = tpe ^ ROTATE(tpd,16) ^
+                               ROTATE(tp9,8) ^ ROTATE(tpb,24);
+#else
+                       t[i] = tpe ^ (tpd >> 16) ^ (tpd << 16) ^ 
+                               (tp9 >> 24) ^ (tp9 << 8) ^
+                               (tpb >> 8) ^ (tpb << 24);
+#endif
+                       t[i] ^= rk[4+i];
+               }
+       }
+#else
+       t[0] =  Td0[(s0      ) & 0xff] ^
+               Td1[(s3 >>  8) & 0xff] ^
+               Td2[(s2 >> 16) & 0xff] ^
+               Td3[(s1 >> 24)       ] ^
+               rk[4];
+       t[1] =  Td0[(s1      ) & 0xff] ^
+               Td1[(s0 >>  8) & 0xff] ^
+               Td2[(s3 >> 16) & 0xff] ^
+               Td3[(s2 >> 24)       ] ^
+               rk[5];
+       t[2] =  Td0[(s2      ) & 0xff] ^
+               Td1[(s1 >>  8) & 0xff] ^
+               Td2[(s0 >> 16) & 0xff] ^
+               Td3[(s3 >> 24)       ] ^
+               rk[6];
+       t[3] =  Td0[(s3      ) & 0xff] ^
+               Td1[(s2 >>  8) & 0xff] ^
+               Td2[(s1 >> 16) & 0xff] ^
+               Td3[(s0 >> 24)       ] ^
+               rk[7];
+#endif
+       s0 = t[0]; s1 = t[1]; s2 = t[2]; s3 = t[3];
+
+    /*
+     * Nr - 2 full rounds:
+     */
+    for (rk+=8,r=key->rounds-2; r>0; rk+=4,r--) {
+#if defined(AES_COMPACT_IN_INNER_ROUNDS)
+        t[0] = Td4[(s0      ) & 0xff]       ^
+               Td4[(s3 >>  8) & 0xff] <<  8 ^
+               Td4[(s2 >> 16) & 0xff] << 16 ^
+               Td4[(s1 >> 24)       ] << 24;
+        t[1] = Td4[(s1      ) & 0xff]       ^
+               Td4[(s0 >>  8) & 0xff] <<  8 ^
+               Td4[(s3 >> 16) & 0xff] << 16 ^
+               Td4[(s2 >> 24)       ] << 24;
+        t[2] = Td4[(s2      ) & 0xff]       ^
+               Td4[(s1 >>  8) & 0xff] <<  8 ^
+               Td4[(s0 >> 16) & 0xff] << 16 ^
+               Td4[(s3 >> 24)       ] << 24;
+        t[3] = Td4[(s3      ) & 0xff]       ^
+               Td4[(s2 >>  8) & 0xff] <<  8 ^
+               Td4[(s1 >> 16) & 0xff] << 16 ^
+               Td4[(s0 >> 24)       ] << 24;
+
+       /* now do the linear transform using words */ 
+       {       int i;
+               u32 tp1, tp2, tp4, tp8, tp9, tpb, tpd, tpe, m;
+
+               for (i = 0; i < 4; i++) {
+                       tp1 = t[i];
+                       m = tp1 & 0x80808080;
+                       tp2 = ((tp1 & 0x7f7f7f7f) << 1) ^
+                               ((m - (m >> 7)) & 0x1b1b1b1b);
+                       m = tp2 & 0x80808080;
+                       tp4 = ((tp2 & 0x7f7f7f7f) << 1) ^
+                               ((m - (m >> 7)) & 0x1b1b1b1b);
+                       m = tp4 & 0x80808080;
+                       tp8 = ((tp4 & 0x7f7f7f7f) << 1) ^
+                               ((m - (m >> 7)) & 0x1b1b1b1b);
+                       tp9 = tp8 ^ tp1;
+                       tpb = tp9 ^ tp2;
+                       tpd = tp9 ^ tp4;
+                       tpe = tp8 ^ tp4 ^ tp2;
+#if defined(ROTATE)
+                       t[i] = tpe ^ ROTATE(tpd,16) ^
+                               ROTATE(tp9,8) ^ ROTATE(tpb,24);
+#else
+                       t[i] = tpe ^ (tpd >> 16) ^ (tpd << 16) ^ 
+                               (tp9 >> 24) ^ (tp9 << 8) ^
+                               (tpb >> 8) ^ (tpb << 24);
+#endif
+                       t[i] ^= rk[i];
+               }
+       }
+#else
+       t[0] =  Td0[(s0      ) & 0xff] ^
+               Td1[(s3 >>  8) & 0xff] ^
+               Td2[(s2 >> 16) & 0xff] ^
+               Td3[(s1 >> 24)       ] ^
+               rk[0];
+       t[1] =  Td0[(s1      ) & 0xff] ^
+               Td1[(s0 >>  8) & 0xff] ^
+               Td2[(s3 >> 16) & 0xff] ^
+               Td3[(s2 >> 24)       ] ^
+               rk[1];
+       t[2] =  Td0[(s2      ) & 0xff] ^
+               Td1[(s1 >>  8) & 0xff] ^
+               Td2[(s0 >> 16) & 0xff] ^
+               Td3[(s3 >> 24)       ] ^
+               rk[2];
+       t[3] =  Td0[(s3      ) & 0xff] ^
+               Td1[(s2 >>  8) & 0xff] ^
+               Td2[(s1 >> 16) & 0xff] ^
+               Td3[(s0 >> 24)       ] ^
+               rk[3];
+#endif
+       s0 = t[0]; s1 = t[1]; s2 = t[2]; s3 = t[3];
+    }
+    /*
+        * apply last round and
+        * map cipher state to byte array block:
+        */
+       prefetch256(Td4);
+
+       *(u32*)(out+0) =
+               (Td4[(s0      ) & 0xff])        ^
+               (Td4[(s3 >>  8) & 0xff] <<  8) ^
+               (Td4[(s2 >> 16) & 0xff] << 16) ^
+               (Td4[(s1 >> 24)       ] << 24) ^
+               rk[0];
+       *(u32*)(out+4) =
+               (Td4[(s1      ) & 0xff])         ^
+               (Td4[(s0 >>  8) & 0xff] <<  8) ^
+               (Td4[(s3 >> 16) & 0xff] << 16) ^
+               (Td4[(s2 >> 24)       ] << 24) ^
+               rk[1];
+       *(u32*)(out+8) =
+               (Td4[(s2      ) & 0xff])         ^
+               (Td4[(s1 >>  8) & 0xff] <<  8) ^
+               (Td4[(s0 >> 16) & 0xff] << 16) ^
+               (Td4[(s3 >> 24)       ] << 24) ^
+               rk[2];
+       *(u32*)(out+12) =
+               (Td4[(s3      ) & 0xff])         ^
+               (Td4[(s2 >>  8) & 0xff] <<  8) ^
+               (Td4[(s1 >> 16) & 0xff] << 16) ^
+               (Td4[(s0 >> 24)       ] << 24) ^
+               rk[3];
+}
index 3bc46a9..aab40e6 100755 (executable)
@@ -2,11 +2,12 @@
 #
 # ====================================================================
 # Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
-# project. Rights for redistribution and usage in source and binary
-# forms are granted according to the OpenSSL license.
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
 # ====================================================================
 #
-# Version 3.6.
+# Version 4.3.
 #
 # You might fail to appreciate this module performance from the first
 # try. If compared to "vanilla" linux-ia32-icc target, i.e. considered
 # AMD K8       20                      19
 # PIII         25                      23
 # Pentium      81                      78
-
-push(@INC,"perlasm","../../perlasm");
+#
+# Version 3.7 reimplements outer rounds as "compact." Meaning that
+# first and last rounds reference compact 256 bytes S-box. This means
+# that first round consumes a lot more CPU cycles and that encrypt
+# and decrypt performance becomes asymmetric. Encrypt performance
+# drops by 10-12%, while decrypt - by 20-25%:-( 256 bytes S-box is
+# aggressively pre-fetched.
+#
+# Version 4.0 effectively rolls back to 3.6 and instead implements
+# additional set of functions, _[x86|sse]_AES_[en|de]crypt_compact,
+# which use exclusively 256 byte S-box. These functions are to be
+# called in modes not concealing plain text, such as ECB, or when
+# we're asked to process smaller amount of data [or unconditionally
+# on hyper-threading CPU]. Currently it's called unconditionally from
+# AES_[en|de]crypt, which affects all modes, but CBC. CBC routine
+# still needs to be modified to switch between slower and faster
+# mode when appropriate... But in either case benchmark landscape
+# changes dramatically and below numbers are CPU cycles per processed
+# byte for 128-bit key.
+#
+#              ECB encrypt     ECB decrypt     CBC large chunk
+# P4           56[60]          84[100]         23
+# AMD K8       48[44]          70[79]          18
+# PIII         41[50]          61[91]          24
+# Core 2       32[38]          45[70]          18.5
+# Pentium      120             160             77
+#
+# Version 4.1 switches to compact S-box even in key schedule setup.
+#
+# Version 4.2 prefetches compact S-box in every SSE round or in other
+# words every cache-line is *guaranteed* to be accessed within ~50
+# cycles window. Why just SSE? Because it's needed on hyper-threading
+# CPU! Which is also why it's prefetched with 64 byte stride. Best
+# part is that it has no negative effect on performance:-)  
+#
+# Version 4.3 implements switch between compact and non-compact block
+# functions in AES_cbc_encrypt depending on how much data was asked
+# to be processed in one stroke.
+#
+######################################################################
+# Timing attacks are classified in two classes: synchronous when
+# attacker consciously initiates cryptographic operation and collects
+# timing data of various character afterwards, and asynchronous when
+# malicious code is executed on same CPU simultaneously with AES,
+# instruments itself and performs statistical analysis of this data.
+#
+# As far as synchronous attacks go the root to the AES timing
+# vulnerability is twofold. Firstly, of 256 S-box elements at most 160
+# are referred to in single 128-bit block operation. Well, in C
+# implementation with 4 distinct tables it's actually as little as 40
+# references per 256 elements table, but anyway... Secondly, even
+# though S-box elements are clustered into smaller amount of cache-
+# lines, smaller than 160 and even 40, it turned out that for certain
+# plain-text pattern[s] or simply put chosen plain-text and given key
+# few cache-lines remain unaccessed during block operation. Now, if
+# attacker can figure out this access pattern, he can deduct the key
+# [or at least part of it]. The natural way to mitigate this kind of
+# attacks is to minimize the amount of cache-lines in S-box and/or
+# prefetch them to ensure that every one is accessed for more uniform
+# timing. But note that *if* plain-text was concealed in such way that
+# input to block function is distributed *uniformly*, then attack
+# wouldn't apply. Now note that some encryption modes, most notably
+# CBC, do mask the plain-text in this exact way [secure cipher output
+# is distributed uniformly]. Yes, one still might find input that
+# would reveal the information about given key, but if amount of
+# candidate inputs to be tried is larger than amount of possible key
+# combinations then attack becomes infeasible. This is why revised
+# AES_cbc_encrypt "dares" to switch to larger S-box when larger chunk
+# of data is to be processed in one stroke. The current size limit of
+# 512 bytes is chosen to provide same [diminishigly low] probability
+# for cache-line to remain untouched in large chunk operation with
+# large S-box as for single block operation with compact S-box and
+# surely needs more careful consideration...
+#
+# As for asynchronous attacks. There are two flavours: attacker code
+# being interleaved with AES on hyper-threading CPU at *instruction*
+# level, and two processes time sharing single core. As for latter.
+# Two vectors. 1. Given that attacker process has higher priority,
+# yield execution to process performing AES just before timer fires
+# off the scheduler, immediately regain control of CPU and analyze the
+# cache state. For this attack to be efficient attacker would have to
+# effectively slow down the operation by several *orders* of magnitute,
+# by ratio of time slice to duration of handful of AES rounds, which
+# unlikely to remain unnoticed. Not to mention that this also means
+# that he would spend correspondigly more time to collect enough
+# statistical data to mount the attack. It's probably appropriate to
+# say that if adeversary reckons that this attack is beneficial and
+# risks to be noticed, you probably have larger problems having him
+# mere opportunity. In other words suggested code design expects you
+# to preclude/mitigate this attack by overall system security design.
+# 2. Attacker manages to make his code interrupt driven. In order for
+# this kind of attack to be feasible, interrupt rate has to be high
+# enough, again comparable to duration of handful of AES rounds. But
+# is there interrupt source of such rate? Hardly, not even 1Gbps NIC
+# generates interrupts at such raging rate...
+#
+# And now back to the former, hyper-threading CPU or more specifically
+# Intel P4. Recall that asynchronous attack implies that malicious
+# code instruments itself. And naturally instrumentation granularity
+# has be noticeably lower than duration of codepath accessing S-box.
+# Given that all cache-lines are accessed during that time that is.
+# Current implementation accesses *all* cache-lines within ~50 cycles
+# window, which is actually *less* than RDTSC latency on Intel P4!
+
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+push(@INC,"${dir}","${dir}../../perlasm");
 require "x86asm.pl";
 
-&asm_init($ARGV[0],"aes-586.pl",$ARGV[$#ARGV] eq "386");
+&asm_init($ARGV[0],"aes-586.pl",$x86only = $ARGV[$#ARGV] eq "386");
+&static_label("AES_Te");
+&static_label("AES_Td");
 
 $s0="eax";
 $s1="ebx";
@@ -93,21 +200,36 @@ $s2="ecx";
 $s3="edx";
 $key="edi";
 $acc="esi";
+$tbl="ebp";
+
+# stack frame layout in _[x86|sse]_AES_* routines, frame is allocated
+# by caller
+$__ra=&DWP(0,"esp");   # return address
+$__s0=&DWP(4,"esp");   # s0 backing store
+$__s1=&DWP(8,"esp");   # s1 backing store
+$__s2=&DWP(12,"esp");  # s2 backing store
+$__s3=&DWP(16,"esp");  # s3 backing store
+$__key=&DWP(20,"esp"); # pointer to key schedule
+$__end=&DWP(24,"esp"); # pointer to end of key schedule
+$__tbl=&DWP(28,"esp"); # %ebp backing store
+
+# stack frame layout in AES_[en|crypt] routines, which differs from
+# above by 4 and overlaps by %ebp backing store
+$_tbl=&DWP(24,"esp");
+$_esp=&DWP(28,"esp");
+
+sub _data_word() { my $i; while(defined($i=shift)) { &data_word($i,$i); } }
 
-$compromise=0;         # $compromise=128 abstains from copying key
-                       # schedule to stack when encrypting inputs
-                       # shorter than 128 bytes at the cost of
-                       # risksing aliasing with S-boxes. In return
-                       # you get way better, up to +70%, small block
-                       # performance.
+$speed_limit=512;      # chunks smaller than $speed_limit are
+                       # processed with compact routine in CBC mode
 $small_footprint=1;    # $small_footprint=1 code is ~5% slower [on
                        # recent Âµ-archs], but ~5 times smaller!
                        # I favor compact code to minimize cache
                        # contention and in hope to "collect" 5% back
                        # in real-life applications...
+
 $vertical_spin=0;      # shift "verticaly" defaults to 0, because of
                        # its proof-of-concept status...
-
 # Note that there is no decvert(), as well as last encryption round is
 # performed with "horizontal" shifts. This is because this "vertical"
 # implementation [one which groups shifts on a given $s[i] to form a
@@ -170,17 +292,484 @@ sub encvert()
        &movz   ($v0,&HB($v1));
        &and    ($v1,0xFF);
        &xor    ($s[3],&DWP(2,$te,$v1,8));              # s1>>16
-        &mov   ($key,&DWP(12,"esp"));                  # reincarnate v1 as key
+        &mov   ($key,$__key);                          # reincarnate v1 as key
        &xor    ($s[2],&DWP(1,$te,$v0,8));              # s1>>24
 }
 
+# Another experimental routine, which features "horizontal spin," but
+# eliminates one reference to stack. Strangely enough runs slower...
+sub enchoriz()
+{ my $v0 = $key, $v1 = $acc;
+
+       &movz   ($v0,&LB($s0));                 #  3, 2, 1, 0*
+       &rotr   ($s2,8);                        #  8,11,10, 9
+       &mov    ($v1,&DWP(0,$te,$v0,8));        #  0
+       &movz   ($v0,&HB($s1));                 #  7, 6, 5*, 4
+       &rotr   ($s3,16);                       # 13,12,15,14
+       &xor    ($v1,&DWP(3,$te,$v0,8));        #  5
+       &movz   ($v0,&HB($s2));                 #  8,11,10*, 9
+       &rotr   ($s0,16);                       #  1, 0, 3, 2
+       &xor    ($v1,&DWP(2,$te,$v0,8));        # 10
+       &movz   ($v0,&HB($s3));                 # 13,12,15*,14
+       &xor    ($v1,&DWP(1,$te,$v0,8));        # 15, t[0] collected
+       &mov    ($__s0,$v1);                    # t[0] saved
+
+       &movz   ($v0,&LB($s1));                 #  7, 6, 5, 4*
+       &shr    ($s1,16);                       #  -, -, 7, 6
+       &mov    ($v1,&DWP(0,$te,$v0,8));        #  4
+       &movz   ($v0,&LB($s3));                 # 13,12,15,14*
+       &xor    ($v1,&DWP(2,$te,$v0,8));        # 14
+       &movz   ($v0,&HB($s0));                 #  1, 0, 3*, 2
+       &and    ($s3,0xffff0000);               # 13,12, -, -
+       &xor    ($v1,&DWP(1,$te,$v0,8));        #  3
+       &movz   ($v0,&LB($s2));                 #  8,11,10, 9*
+       &or     ($s3,$s1);                      # 13,12, 7, 6
+       &xor    ($v1,&DWP(3,$te,$v0,8));        #  9, t[1] collected
+       &mov    ($s1,$v1);                      #  s[1]=t[1]
+
+       &movz   ($v0,&LB($s0));                 #  1, 0, 3, 2*
+       &shr    ($s2,16);                       #  -, -, 8,11
+       &mov    ($v1,&DWP(2,$te,$v0,8));        #  2
+       &movz   ($v0,&HB($s3));                 # 13,12, 7*, 6
+       &xor    ($v1,&DWP(1,$te,$v0,8));        #  7
+       &movz   ($v0,&HB($s2));                 #  -, -, 8*,11
+       &xor    ($v1,&DWP(0,$te,$v0,8));        #  8
+       &mov    ($v0,$s3);
+       &shr    ($v0,24);                       # 13
+       &xor    ($v1,&DWP(3,$te,$v0,8));        # 13, t[2] collected
+
+       &movz   ($v0,&LB($s2));                 #  -, -, 8,11*
+       &shr    ($s0,24);                       #  1*
+       &mov    ($s2,&DWP(1,$te,$v0,8));        # 11
+       &xor    ($s2,&DWP(3,$te,$s0,8));        #  1
+       &mov    ($s0,$__s0);                    # s[0]=t[0]
+       &movz   ($v0,&LB($s3));                 # 13,12, 7, 6*
+       &shr    ($s3,16);                       #   ,  ,13,12
+       &xor    ($s2,&DWP(2,$te,$v0,8));        #  6
+       &mov    ($key,$__key);                  # reincarnate v0 as key
+       &and    ($s3,0xff);                     #   ,  ,13,12*
+       &mov    ($s3,&DWP(0,$te,$s3,8));        # 12
+       &xor    ($s3,$s2);                      # s[2]=t[3] collected
+       &mov    ($s2,$v1);                      # s[2]=t[2]
+}
+
+# More experimental code... SSE one... Even though this one eliminates
+# *all* references to stack, it's not faster...
+sub sse_encbody()
+{
+       &movz   ($acc,&LB("eax"));              #  0
+       &mov    ("ecx",&DWP(0,$tbl,$acc,8));    #  0
+       &pshufw ("mm2","mm0",0x0d);             #  7, 6, 3, 2
+       &movz   ("edx",&HB("eax"));             #  1
+       &mov    ("edx",&DWP(3,$tbl,"edx",8));   #  1
+       &shr    ("eax",16);                     #  5, 4
+
+       &movz   ($acc,&LB("ebx"));              # 10
+       &xor    ("ecx",&DWP(2,$tbl,$acc,8));    # 10
+       &pshufw ("mm6","mm4",0x08);             # 13,12, 9, 8
+       &movz   ($acc,&HB("ebx"));              # 11
+       &xor    ("edx",&DWP(1,$tbl,$acc,8));    # 11
+       &shr    ("ebx",16);                     # 15,14
+
+       &movz   ($acc,&HB("eax"));              #  5
+       &xor    ("ecx",&DWP(3,$tbl,$acc,8));    #  5
+       &movq   ("mm3",QWP(16,$key));
+       &movz   ($acc,&HB("ebx"));              # 15
+       &xor    ("ecx",&DWP(1,$tbl,$acc,8));    # 15
+       &movd   ("mm0","ecx");                  # t[0] collected
+
+       &movz   ($acc,&LB("eax"));              #  4
+       &mov    ("ecx",&DWP(0,$tbl,$acc,8));    #  4
+       &movd   ("eax","mm2");                  #  7, 6, 3, 2
+       &movz   ($acc,&LB("ebx"));              # 14
+       &xor    ("ecx",&DWP(2,$tbl,$acc,8));    # 14
+       &movd   ("ebx","mm6");                  # 13,12, 9, 8
+
+       &movz   ($acc,&HB("eax"));              #  3
+       &xor    ("ecx",&DWP(1,$tbl,$acc,8));    #  3
+       &movz   ($acc,&HB("ebx"));              #  9
+       &xor    ("ecx",&DWP(3,$tbl,$acc,8));    #  9
+       &movd   ("mm1","ecx");                  # t[1] collected
+
+       &movz   ($acc,&LB("eax"));              #  2
+       &mov    ("ecx",&DWP(2,$tbl,$acc,8));    #  2
+       &shr    ("eax",16);                     #  7, 6
+       &punpckldq      ("mm0","mm1");          # t[0,1] collected
+       &movz   ($acc,&LB("ebx"));              #  8
+       &xor    ("ecx",&DWP(0,$tbl,$acc,8));    #  8
+       &shr    ("ebx",16);                     # 13,12
+
+       &movz   ($acc,&HB("eax"));              #  7
+       &xor    ("ecx",&DWP(1,$tbl,$acc,8));    #  7
+       &pxor   ("mm0","mm3");
+       &movz   ("eax",&LB("eax"));             #  6
+       &xor    ("edx",&DWP(2,$tbl,"eax",8));   #  6
+       &pshufw ("mm1","mm0",0x08);             #  5, 4, 1, 0
+       &movz   ($acc,&HB("ebx"));              # 13
+       &xor    ("ecx",&DWP(3,$tbl,$acc,8));    # 13
+       &xor    ("ecx",&DWP(24,$key));          # t[2]
+       &movd   ("mm4","ecx");                  # t[2] collected
+       &movz   ("ebx",&LB("ebx"));             # 12
+       &xor    ("edx",&DWP(0,$tbl,"ebx",8));   # 12
+       &shr    ("ecx",16);
+       &movd   ("eax","mm1");                  #  5, 4, 1, 0
+       &mov    ("ebx",&DWP(28,$key));          # t[3]
+       &xor    ("ebx","edx");
+       &movd   ("mm5","ebx");                  # t[3] collected
+       &and    ("ebx",0xffff0000);
+       &or     ("ebx","ecx");
+
+       &punpckldq      ("mm4","mm5");          # t[2,3] collected
+}
+
+######################################################################
+# "Compact" block function
+######################################################################
+
+sub enccompact()
+{ my $Fn = mov;
+  while ($#_>5) { pop(@_); $Fn=sub{}; }
+  my ($i,$te,@s)=@_;
+  my $tmp = $key;
+  my $out = $i==3?$s[0]:$acc;
+
+       # $Fn is used in first compact round and its purpose is to
+       # void restoration of some values from stack, so that after
+       # 4xenccompact with extra argument $key value is left there...
+       if ($i==3)  {   &$Fn    ($key,$__key);                  }##%edx
+       else        {   &mov    ($out,$s[0]);                   }
+                       &and    ($out,0xFF);
+       if ($i==1)  {   &shr    ($s[0],16);                     }#%ebx[1]
+       if ($i==2)  {   &shr    ($s[0],24);                     }#%ecx[2]
+                       &movz   ($out,&BP(-128,$te,$out,1));
+
+       if ($i==3)  {   $tmp=$s[1];                             }##%eax
+                       &movz   ($tmp,&HB($s[1]));
+                       &movz   ($tmp,&BP(-128,$te,$tmp,1));
+                       &shl    ($tmp,8);
+                       &xor    ($out,$tmp);
+
+       if ($i==3)  {   $tmp=$s[2]; &mov ($s[1],$__s0);         }##%ebx
+       else        {   &mov    ($tmp,$s[2]);
+                       &shr    ($tmp,16);                      }
+       if ($i==2)  {   &and    ($s[1],0xFF);                   }#%edx[2]
+                       &and    ($tmp,0xFF);
+                       &movz   ($tmp,&BP(-128,$te,$tmp,1));
+                       &shl    ($tmp,16);
+                       &xor    ($out,$tmp);
+
+       if ($i==3)  {   $tmp=$s[3]; &mov ($s[2],$__s1);         }##%ecx
+       elsif($i==2){   &movz   ($tmp,&HB($s[3]));              }#%ebx[2]
+       else        {   &mov    ($tmp,$s[3]);
+                       &shr    ($tmp,24);                      }
+                       &movz   ($tmp,&BP(-128,$te,$tmp,1));
+                       &shl    ($tmp,24);
+                       &xor    ($out,$tmp);
+       if ($i<2)   {   &mov    (&DWP(4+4*$i,"esp"),$out);      }
+       if ($i==3)  {   &mov    ($s[3],$acc);                   }
+       &comment();
+}
+
+sub enctransform()
+{ my @s = ($s0,$s1,$s2,$s3);
+  my $i = shift;
+  my $tmp = $tbl;
+  my $r2  = $key ;
+
+       &mov    ($acc,$s[$i]);
+       &and    ($acc,0x80808080);
+       &mov    ($tmp,$acc);
+       &shr    ($tmp,7);
+       &lea    ($r2,&DWP(0,$s[$i],$s[$i]));
+       &sub    ($acc,$tmp);
+       &and    ($r2,0xfefefefe);
+       &and    ($acc,0x1b1b1b1b);
+       &mov    ($tmp,$s[$i]);
+       &xor    ($acc,$r2);     # r2
+
+       &xor    ($s[$i],$acc);  # r0 ^ r2
+       &rotl   ($s[$i],24);
+       &xor    ($s[$i],$acc)   # ROTATE(r2^r0,24) ^ r2
+       &rotr   ($tmp,16);
+       &xor    ($s[$i],$tmp);
+       &rotr   ($tmp,8);
+       &xor    ($s[$i],$tmp);
+}
+
+&function_begin_B("_x86_AES_encrypt_compact");
+       # note that caller is expected to allocate stack frame for me!
+       &mov    ($__key,$key);                  # save key
+
+       &xor    ($s0,&DWP(0,$key));             # xor with key
+       &xor    ($s1,&DWP(4,$key));
+       &xor    ($s2,&DWP(8,$key));
+       &xor    ($s3,&DWP(12,$key));
+
+       &mov    ($acc,&DWP(240,$key));          # load key->rounds
+       &lea    ($acc,&DWP(-2,$acc,$acc));
+       &lea    ($acc,&DWP(0,$key,$acc,8));
+       &mov    ($__end,$acc);                  # end of key schedule
+
+       # prefetch Te4
+       &mov    ($key,&DWP(0-128,$tbl));
+       &mov    ($acc,&DWP(32-128,$tbl));
+       &mov    ($key,&DWP(64-128,$tbl));
+       &mov    ($acc,&DWP(96-128,$tbl));
+       &mov    ($key,&DWP(128-128,$tbl));
+       &mov    ($acc,&DWP(160-128,$tbl));
+       &mov    ($key,&DWP(192-128,$tbl));
+       &mov    ($acc,&DWP(224-128,$tbl));
+
+       &set_label("loop",16);
+
+               &enccompact(0,$tbl,$s0,$s1,$s2,$s3,1);
+               &enccompact(1,$tbl,$s1,$s2,$s3,$s0,1);
+               &enccompact(2,$tbl,$s2,$s3,$s0,$s1,1);
+               &enccompact(3,$tbl,$s3,$s0,$s1,$s2,1);
+               &enctransform(2);
+               &enctransform(3);
+               &enctransform(0);
+               &enctransform(1);
+               &mov    ($key,$__key);
+               &mov    ($tbl,$__tbl);
+               &add    ($key,16);              # advance rd_key
+               &xor    ($s0,&DWP(0,$key));
+               &xor    ($s1,&DWP(4,$key));
+               &xor    ($s2,&DWP(8,$key));
+               &xor    ($s3,&DWP(12,$key));
+
+       &cmp    ($key,$__end);
+       &mov    ($__key,$key);
+       &jb     (&label("loop"));
+
+       &enccompact(0,$tbl,$s0,$s1,$s2,$s3);
+       &enccompact(1,$tbl,$s1,$s2,$s3,$s0);
+       &enccompact(2,$tbl,$s2,$s3,$s0,$s1);
+       &enccompact(3,$tbl,$s3,$s0,$s1,$s2);
+
+       &xor    ($s0,&DWP(16,$key));
+       &xor    ($s1,&DWP(20,$key));
+       &xor    ($s2,&DWP(24,$key));
+       &xor    ($s3,&DWP(28,$key));
+
+       &ret    ();
+&function_end_B("_x86_AES_encrypt_compact");
+
+######################################################################
+# "Compact" SSE block function.
+######################################################################
+#
+# Performance is not actually extraordinary in comparison to pure
+# x86 code. In particular encrypt performance is virtually the same.
+# Decrypt performance on the other hand is 15-20% better on newer
+# Âµ-archs [but we're thankful for *any* improvement here], and ~50%
+# better on PIII:-) And additionally on the pros side this code
+# eliminates redundant references to stack and thus relieves/
+# minimizes the pressure on the memory bus.
+#
+# MMX register layout                           lsb
+# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+# |          mm4          |          mm0          |
+# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+# |     s3    |     s2    |     s1    |     s0    |    
+# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+# |15|14|13|12|11|10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0|
+# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+#
+# Indexes translate as s[N/4]>>(8*(N%4)), e.g. 5 means s1>>8.
+# In this terms encryption and decryption "compact" permutation
+# matrices can be depicted as following:
+#
+# encryption              lsb  # decryption              lsb
+# +----++----+----+----+----+  # +----++----+----+----+----+
+# | t0 || 15 | 10 |  5 |  0 |  # | t0 ||  7 | 10 | 13 |  0 |
+# +----++----+----+----+----+  # +----++----+----+----+----+
+# | t1 ||  3 | 14 |  9 |  4 |  # | t1 || 11 | 14 |  1 |  4 |
+# +----++----+----+----+----+  # +----++----+----+----+----+
+# | t2 ||  7 |  2 | 13 |  8 |  # | t2 || 15 |  2 |  5 |  8 |
+# +----++----+----+----+----+  # +----++----+----+----+----+
+# | t3 || 11 |  6 |  1 | 12 |  # | t3 ||  3 |  6 |  9 | 12 |
+# +----++----+----+----+----+  # +----++----+----+----+----+
+#
+######################################################################
+# Why not xmm registers? Short answer. It was actually tested and
+# was not any faster, but *contrary*, most notably on Intel CPUs.
+# Longer answer. Main advantage of using mm registers is that movd
+# latency is lower, especially on Intel P4. While arithmetic
+# instructions are twice as many, they can be scheduled every cycle
+# and not every second one when they are operating on xmm register,
+# so that "arithmetic throughput" remains virtually the same. And
+# finally the code can be executed even on elder SSE-only CPUs:-)
+
+sub sse_enccompact()
+{
+       &pshufw ("mm1","mm0",0x08);             #  5, 4, 1, 0
+       &pshufw ("mm5","mm4",0x0d);             # 15,14,11,10
+       &movd   ("eax","mm1");                  #  5, 4, 1, 0
+       &movd   ("ebx","mm5");                  # 15,14,11,10
+
+       &movz   ($acc,&LB("eax"));              #  0
+       &movz   ("ecx",&BP(-128,$tbl,$acc,1));  #  0
+       &pshufw ("mm2","mm0",0x0d);             #  7, 6, 3, 2
+       &movz   ("edx",&HB("eax"));             #  1
+       &movz   ("edx",&BP(-128,$tbl,"edx",1)); #  1
+       &shl    ("edx",8);                      #  1
+       &shr    ("eax",16);                     #  5, 4
+
+       &movz   ($acc,&LB("ebx"));              # 10
+       &movz   ($acc,&BP(-128,$tbl,$acc,1));   # 10
+       &shl    ($acc,16);                      # 10
+       &or     ("ecx",$acc);                   # 10
+       &pshufw ("mm6","mm4",0x08);             # 13,12, 9, 8
+       &movz   ($acc,&HB("ebx"));              # 11
+       &movz   ($acc,&BP(-128,$tbl,$acc,1));   # 11
+       &shl    ($acc,24);                      # 11
+       &or     ("edx",$acc);                   # 11
+       &shr    ("ebx",16);                     # 15,14
+
+       &movz   ($acc,&HB("eax"));              #  5
+       &movz   ($acc,&BP(-128,$tbl,$acc,1));   #  5
+       &shl    ($acc,8);                       #  5
+       &or     ("ecx",$acc);                   #  5
+       &movz   ($acc,&HB("ebx"));              # 15
+       &movz   ($acc,&BP(-128,$tbl,$acc,1));   # 15
+       &shl    ($acc,24);                      # 15
+       &or     ("ecx",$acc);                   # 15
+       &movd   ("mm0","ecx");                  # t[0] collected
+
+       &movz   ($acc,&LB("eax"));              #  4
+       &movz   ("ecx",&BP(-128,$tbl,$acc,1));  #  4
+       &movd   ("eax","mm2");                  #  7, 6, 3, 2
+       &movz   ($acc,&LB("ebx"));              # 14
+       &movz   ($acc,&BP(-128,$tbl,$acc,1));   # 14
+       &shl    ($acc,16);                      # 14
+       &or     ("ecx",$acc);                   # 14
+
+       &movd   ("ebx","mm6");                  # 13,12, 9, 8
+       &movz   ($acc,&HB("eax"));              #  3
+       &movz   ($acc,&BP(-128,$tbl,$acc,1));   #  3
+       &shl    ($acc,24);                      #  3
+       &or     ("ecx",$acc);                   #  3
+       &movz   ($acc,&HB("ebx"));              #  9
+       &movz   ($acc,&BP(-128,$tbl,$acc,1));   #  9
+       &shl    ($acc,8);                       #  9
+       &or     ("ecx",$acc);                   #  9
+       &movd   ("mm1","ecx");                  # t[1] collected
+
+       &movz   ($acc,&LB("ebx"));              #  8
+       &movz   ("ecx",&BP(-128,$tbl,$acc,1));  #  8
+       &shr    ("ebx",16);                     # 13,12
+       &movz   ($acc,&LB("eax"));              #  2
+       &movz   ($acc,&BP(-128,$tbl,$acc,1));   #  2
+       &shl    ($acc,16);                      #  2
+       &or     ("ecx",$acc);                   #  2
+       &shr    ("eax",16);                     #  7, 6
+
+       &punpckldq      ("mm0","mm1");          # t[0,1] collected
+
+       &movz   ($acc,&HB("eax"));              #  7
+       &movz   ($acc,&BP(-128,$tbl,$acc,1));   #  7
+       &shl    ($acc,24);                      #  7
+       &or     ("ecx",$acc);                   #  7
+       &and    ("eax",0xff);                   #  6
+       &movz   ("eax",&BP(-128,$tbl,"eax",1)); #  6
+       &shl    ("eax",16);                     #  6
+       &or     ("edx","eax");                  #  6
+       &movz   ($acc,&HB("ebx"));              # 13
+       &movz   ($acc,&BP(-128,$tbl,$acc,1));   # 13
+       &shl    ($acc,8);                       # 13
+       &or     ("ecx",$acc);                   # 13
+       &movd   ("mm4","ecx");                  # t[2] collected
+       &and    ("ebx",0xff);                   # 12
+       &movz   ("ebx",&BP(-128,$tbl,"ebx",1)); # 12
+       &or     ("edx","ebx");                  # 12
+       &movd   ("mm5","edx");                  # t[3] collected
+
+       &punpckldq      ("mm4","mm5");          # t[2,3] collected
+}
+
+                                       if (!$x86only) {
+&function_begin_B("_sse_AES_encrypt_compact");
+       &pxor   ("mm0",&QWP(0,$key));   #  7, 6, 5, 4, 3, 2, 1, 0
+       &pxor   ("mm4",&QWP(8,$key));   # 15,14,13,12,11,10, 9, 8
+
+       # note that caller is expected to allocate stack frame for me!
+       &mov    ($acc,&DWP(240,$key));          # load key->rounds
+       &lea    ($acc,&DWP(-2,$acc,$acc));
+       &lea    ($acc,&DWP(0,$key,$acc,8));
+       &mov    ($__end,$acc);                  # end of key schedule
+
+       &mov    ($s0,0x1b1b1b1b);               # magic constant
+       &mov    (&DWP(8,"esp"),$s0);
+       &mov    (&DWP(12,"esp"),$s0);
+
+       # prefetch Te4
+       &mov    ($s0,&DWP(0-128,$tbl));
+       &mov    ($s1,&DWP(32-128,$tbl));
+       &mov    ($s2,&DWP(64-128,$tbl));
+       &mov    ($s3,&DWP(96-128,$tbl));
+       &mov    ($s0,&DWP(128-128,$tbl));
+       &mov    ($s1,&DWP(160-128,$tbl));
+       &mov    ($s2,&DWP(192-128,$tbl));
+       &mov    ($s3,&DWP(224-128,$tbl));
+
+       &set_label("loop",16);
+               &sse_enccompact();
+               &add    ($key,16);
+               &cmp    ($key,$__end);
+               &ja     (&label("out"));
+
+               &movq   ("mm2",&QWP(8,"esp"));
+               &pxor   ("mm3","mm3");          &pxor   ("mm7","mm7");
+               &movq   ("mm1","mm0");          &movq   ("mm5","mm4");  # r0
+               &pcmpgtb("mm3","mm0");          &pcmpgtb("mm7","mm4");
+               &pand   ("mm3","mm2");          &pand   ("mm7","mm2");
+               &pshufw ("mm2","mm0",0xb1);     &pshufw ("mm6","mm4",0xb1);# ROTATE(r0,16)
+               &paddb  ("mm0","mm0");          &paddb  ("mm4","mm4");
+               &pxor   ("mm0","mm3");          &pxor   ("mm4","mm7");  # = r2
+               &pshufw ("mm3","mm2",0xb1);     &pshufw ("mm7","mm6",0xb1);# r0
+               &pxor   ("mm1","mm0");          &pxor   ("mm5","mm4");  # r0^r2
+               &pxor   ("mm0","mm2");          &pxor   ("mm4","mm6");  # ^= ROTATE(r0,16)
+
+               &movq   ("mm2","mm3");          &movq   ("mm6","mm7");
+               &pslld  ("mm3",8);              &pslld  ("mm7",8);
+               &psrld  ("mm2",24);             &psrld  ("mm6",24);
+               &pxor   ("mm0","mm3");          &pxor   ("mm4","mm7");  # ^= r0<<8
+               &pxor   ("mm0","mm2");          &pxor   ("mm4","mm6");  # ^= r0>>24
+
+               &movq   ("mm3","mm1");          &movq   ("mm7","mm5");
+               &movq   ("mm2",&QWP(0,$key));   &movq   ("mm6",&QWP(8,$key));
+               &psrld  ("mm1",8);              &psrld  ("mm5",8);
+               &mov    ($s0,&DWP(0-128,$tbl));
+               &pslld  ("mm3",24);             &pslld  ("mm7",24);
+               &mov    ($s1,&DWP(64-128,$tbl));
+               &pxor   ("mm0","mm1");          &pxor   ("mm4","mm5");  # ^= (r2^r0)<<8
+               &mov    ($s2,&DWP(128-128,$tbl));
+               &pxor   ("mm0","mm3");          &pxor   ("mm4","mm7");  # ^= (r2^r0)>>24
+               &mov    ($s3,&DWP(192-128,$tbl));
+
+               &pxor   ("mm0","mm2");          &pxor   ("mm4","mm6");
+       &jmp    (&label("loop"));
+
+       &set_label("out",16);
+       &pxor   ("mm0",&QWP(0,$key));
+       &pxor   ("mm4",&QWP(8,$key));
+
+       &ret    ();
+&function_end_B("_sse_AES_encrypt_compact");
+                                       }
+
+######################################################################
+# Vanilla block function.
+######################################################################
+
 sub encstep()
 { my ($i,$te,@s) = @_;
   my $tmp = $key;
   my $out = $i==3?$s[0]:$acc;
 
        # lines marked with #%e?x[i] denote "reordered" instructions...
-       if ($i==3)  {   &mov    ($key,&DWP(12,"esp"));          }##%edx
+       if ($i==3)  {   &mov    ($key,$__key);                  }##%edx
        else        {   &mov    ($out,$s[0]);
                        &and    ($out,0xFF);                    }
        if ($i==1)  {   &shr    ($s[0],16);                     }#%ebx[1]
@@ -191,14 +780,14 @@ sub encstep()
                        &movz   ($tmp,&HB($s[1]));
                        &xor    ($out,&DWP(3,$te,$tmp,8));
 
-       if ($i==3)  {   $tmp=$s[2]; &mov ($s[1],&DWP(4,"esp")); }##%ebx
+       if ($i==3)  {   $tmp=$s[2]; &mov ($s[1],$__s0);         }##%ebx
        else        {   &mov    ($tmp,$s[2]);
                        &shr    ($tmp,16);                      }
        if ($i==2)  {   &and    ($s[1],0xFF);                   }#%edx[2]
                        &and    ($tmp,0xFF);
                        &xor    ($out,&DWP(2,$te,$tmp,8));
 
-       if ($i==3)  {   $tmp=$s[3]; &mov ($s[2],&DWP(8,"esp")); }##%ecx
+       if ($i==3)  {   $tmp=$s[3]; &mov ($s[2],$__s1);         }##%ecx
        elsif($i==2){   &movz   ($tmp,&HB($s[3]));              }#%ebx[2]
        else        {   &mov    ($tmp,$s[3]); 
                        &shr    ($tmp,24)                       }
@@ -213,7 +802,7 @@ sub enclast()
   my $tmp = $key;
   my $out = $i==3?$s[0]:$acc;
 
-       if ($i==3)  {   &mov    ($key,&DWP(12,"esp"));          }##%edx
+       if ($i==3)  {   &mov    ($key,$__key);                  }##%edx
        else        {   &mov    ($out,$s[0]);                   }
                        &and    ($out,0xFF);
        if ($i==1)  {   &shr    ($s[0],16);                     }#%ebx[1]
@@ -227,8 +816,8 @@ sub enclast()
                        &and    ($tmp,0x0000ff00);
                        &xor    ($out,$tmp);
 
-       if ($i==3)  {   $tmp=$s[2]; &mov ($s[1],&DWP(4,"esp")); }##%ebx
-       else        {   mov     ($tmp,$s[2]);
+       if ($i==3)  {   $tmp=$s[2]; &mov ($s[1],$__s0);         }##%ebx
+       else        {   &mov    ($tmp,$s[2]);
                        &shr    ($tmp,16);                      }
        if ($i==2)  {   &and    ($s[1],0xFF);                   }#%edx[2]
                        &and    ($tmp,0xFF);
@@ -236,7 +825,7 @@ sub enclast()
                        &and    ($tmp,0x00ff0000);
                        &xor    ($out,$tmp);
 
-       if ($i==3)  {   $tmp=$s[3]; &mov ($s[2],&DWP(8,"esp")); }##%ecx
+       if ($i==3)  {   $tmp=$s[3]; &mov ($s[2],$__s1);         }##%ecx
        elsif($i==2){   &movz   ($tmp,&HB($s[3]));              }#%ebx[2]
        else        {   &mov    ($tmp,$s[3]);
                        &shr    ($tmp,24);                      }
@@ -247,9 +836,6 @@ sub enclast()
        if ($i==3)  {   &mov    ($s[3],$acc);                   }
 }
 
-sub _data_word() { my $i; while(defined($i=shift)) { &data_word($i,$i); } }
-
-&public_label("AES_Te");
 &function_begin_B("_x86_AES_encrypt");
        if ($vertical_spin) {
                # I need high parts of volatile registers to be accessible...
@@ -258,7 +844,7 @@ sub _data_word() { my $i; while(defined($i=shift)) { &data_word($i,$i); } }
        }
 
        # note that caller is expected to allocate stack frame for me!
-       &mov    (&DWP(12,"esp"),$key);          # save key
+       &mov    ($__key,$key);                  # save key
 
        &xor    ($s0,&DWP(0,$key));             # xor with key
        &xor    ($s1,&DWP(4,$key));
@@ -270,24 +856,24 @@ sub _data_word() { my $i; while(defined($i=shift)) { &data_word($i,$i); } }
        if ($small_footprint) {
            &lea        ($acc,&DWP(-2,$acc,$acc));
            &lea        ($acc,&DWP(0,$key,$acc,8));
-           &mov        (&DWP(16,"esp"),$acc);  # end of key schedule
-           &align      (4);
-           &set_label("loop");
+           &mov        ($__end,$acc);          # end of key schedule
+
+           &set_label("loop",16);
                if ($vertical_spin) {
-                   &encvert("ebp",$s0,$s1,$s2,$s3);
+                   &encvert($tbl,$s0,$s1,$s2,$s3);
                } else {
-                   &encstep(0,"ebp",$s0,$s1,$s2,$s3);
-                   &encstep(1,"ebp",$s1,$s2,$s3,$s0);
-                   &encstep(2,"ebp",$s2,$s3,$s0,$s1);
-                   &encstep(3,"ebp",$s3,$s0,$s1,$s2);
+                   &encstep(0,$tbl,$s0,$s1,$s2,$s3);
+                   &encstep(1,$tbl,$s1,$s2,$s3,$s0);
+                   &encstep(2,$tbl,$s2,$s3,$s0,$s1);
+                   &encstep(3,$tbl,$s3,$s0,$s1,$s2);
                }
                &add    ($key,16);              # advance rd_key
                &xor    ($s0,&DWP(0,$key));
                &xor    ($s1,&DWP(4,$key));
                &xor    ($s2,&DWP(8,$key));
                &xor    ($s3,&DWP(12,$key));
-           &cmp        ($key,&DWP(16,"esp"));
-           &mov        (&DWP(12,"esp"),$key);
+           &cmp        ($key,$__end);
+           &mov        ($__key,$key);
            &jb         (&label("loop"));
        }
        else {
@@ -296,15 +882,15 @@ sub _data_word() { my $i; while(defined($i=shift)) { &data_word($i,$i); } }
            &cmp        ($acc,12);
            &jle        (&label("12rounds"));
 
-       &set_label("14rounds");
+       &set_label("14rounds",4);
            for ($i=1;$i<3;$i++) {
                if ($vertical_spin) {
-                   &encvert("ebp",$s0,$s1,$s2,$s3);
+                   &encvert($tbl,$s0,$s1,$s2,$s3);
                } else {
-                   &encstep(0,"ebp",$s0,$s1,$s2,$s3);
-                   &encstep(1,"ebp",$s1,$s2,$s3,$s0);
-                   &encstep(2,"ebp",$s2,$s3,$s0,$s1);
-                   &encstep(3,"ebp",$s3,$s0,$s1,$s2);
+                   &encstep(0,$tbl,$s0,$s1,$s2,$s3);
+                   &encstep(1,$tbl,$s1,$s2,$s3,$s0);
+                   &encstep(2,$tbl,$s2,$s3,$s0,$s1);
+                   &encstep(3,$tbl,$s3,$s0,$s1,$s2);
                }
                &xor    ($s0,&DWP(16*$i+0,$key));
                &xor    ($s1,&DWP(16*$i+4,$key));
@@ -312,16 +898,16 @@ sub _data_word() { my $i; while(defined($i=shift)) { &data_word($i,$i); } }
                &xor    ($s3,&DWP(16*$i+12,$key));
            }
            &add        ($key,32);
-           &mov        (&DWP(12,"esp"),$key);  # advance rd_key
-       &set_label("12rounds");
+           &mov        ($__key,$key);          # advance rd_key
+       &set_label("12rounds",4);
            for ($i=1;$i<3;$i++) {
                if ($vertical_spin) {
-                   &encvert("ebp",$s0,$s1,$s2,$s3);
+                   &encvert($tbl,$s0,$s1,$s2,$s3);
                } else {
-                   &encstep(0,"ebp",$s0,$s1,$s2,$s3);
-                   &encstep(1,"ebp",$s1,$s2,$s3,$s0);
-                   &encstep(2,"ebp",$s2,$s3,$s0,$s1);
-                   &encstep(3,"ebp",$s3,$s0,$s1,$s2);
+                   &encstep(0,$tbl,$s0,$s1,$s2,$s3);
+                   &encstep(1,$tbl,$s1,$s2,$s3,$s0);
+                   &encstep(2,$tbl,$s2,$s3,$s0,$s1);
+                   &encstep(3,$tbl,$s3,$s0,$s1,$s2);
                }
                &xor    ($s0,&DWP(16*$i+0,$key));
                &xor    ($s1,&DWP(16*$i+4,$key));
@@ -329,16 +915,16 @@ sub _data_word() { my $i; while(defined($i=shift)) { &data_word($i,$i); } }
                &xor    ($s3,&DWP(16*$i+12,$key));
            }
            &add        ($key,32);
-           &mov        (&DWP(12,"esp"),$key);  # advance rd_key
-       &set_label("10rounds");
+           &mov        ($__key,$key);          # advance rd_key
+       &set_label("10rounds",4);
            for ($i=1;$i<10;$i++) {
                if ($vertical_spin) {
-                   &encvert("ebp",$s0,$s1,$s2,$s3);
+                   &encvert($tbl,$s0,$s1,$s2,$s3);
                } else {
-                   &encstep(0,"ebp",$s0,$s1,$s2,$s3);
-                   &encstep(1,"ebp",$s1,$s2,$s3,$s0);
-                   &encstep(2,"ebp",$s2,$s3,$s0,$s1);
-                   &encstep(3,"ebp",$s3,$s0,$s1,$s2);
+                   &encstep(0,$tbl,$s0,$s1,$s2,$s3);
+                   &encstep(1,$tbl,$s1,$s2,$s3,$s0);
+                   &encstep(2,$tbl,$s2,$s3,$s0,$s1);
+                   &encstep(3,$tbl,$s3,$s0,$s1,$s2);
                }
                &xor    ($s0,&DWP(16*$i+0,$key));
                &xor    ($s1,&DWP(16*$i+4,$key));
@@ -352,10 +938,10 @@ sub _data_word() { my $i; while(defined($i=shift)) { &data_word($i,$i); } }
            &mov        ($s1="ebx",$key="edi");
            &mov        ($s2="ecx",$acc="esi");
        }
-       &enclast(0,"ebp",$s0,$s1,$s2,$s3);
-       &enclast(1,"ebp",$s1,$s2,$s3,$s0);
-       &enclast(2,"ebp",$s2,$s3,$s0,$s1);
-       &enclast(3,"ebp",$s3,$s0,$s1,$s2);
+       &enclast(0,$tbl,$s0,$s1,$s2,$s3);
+       &enclast(1,$tbl,$s1,$s2,$s3,$s0);
+       &enclast(2,$tbl,$s2,$s3,$s0,$s1);
+       &enclast(3,$tbl,$s3,$s0,$s1,$s2);
 
        &add    ($key,$small_footprint?16:160);
        &xor    ($s0,&DWP(0,$key));
@@ -430,38 +1016,198 @@ sub _data_word() { my $i; while(defined($i=shift)) { &data_word($i,$i); } }
        &_data_word(0xdabfbf65, 0x31e6e6d7, 0xc6424284, 0xb86868d0);
        &_data_word(0xc3414182, 0xb0999929, 0x772d2d5a, 0x110f0f1e);
        &_data_word(0xcbb0b07b, 0xfc5454a8, 0xd6bbbb6d, 0x3a16162c);
+
+#Te4   # four copies of Te4 to choose from to avoid L1 aliasing
+       &data_byte(0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5);
+       &data_byte(0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76);
+       &data_byte(0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0);
+       &data_byte(0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0);
+       &data_byte(0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc);
+       &data_byte(0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15);
+       &data_byte(0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a);
+       &data_byte(0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75);
+       &data_byte(0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0);
+       &data_byte(0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84);
+       &data_byte(0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b);
+       &data_byte(0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf);
+       &data_byte(0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85);
+       &data_byte(0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8);
+       &data_byte(0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5);
+       &data_byte(0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2);
+       &data_byte(0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17);
+       &data_byte(0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73);
+       &data_byte(0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88);
+       &data_byte(0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb);
+       &data_byte(0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c);
+       &data_byte(0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79);
+       &data_byte(0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9);
+       &data_byte(0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08);
+       &data_byte(0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6);
+       &data_byte(0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a);
+       &data_byte(0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e);
+       &data_byte(0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e);
+       &data_byte(0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94);
+       &data_byte(0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf);
+       &data_byte(0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68);
+       &data_byte(0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16);
+
+       &data_byte(0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5);
+       &data_byte(0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76);
+       &data_byte(0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0);
+       &data_byte(0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0);
+       &data_byte(0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc);
+       &data_byte(0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15);
+       &data_byte(0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a);
+       &data_byte(0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75);
+       &data_byte(0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0);
+       &data_byte(0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84);
+       &data_byte(0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b);
+       &data_byte(0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf);
+       &data_byte(0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85);
+       &data_byte(0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8);
+       &data_byte(0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5);
+       &data_byte(0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2);
+       &data_byte(0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17);
+       &data_byte(0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73);
+       &data_byte(0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88);
+       &data_byte(0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb);
+       &data_byte(0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c);
+       &data_byte(0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79);
+       &data_byte(0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9);
+       &data_byte(0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08);
+       &data_byte(0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6);
+       &data_byte(0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a);
+       &data_byte(0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e);
+       &data_byte(0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e);
+       &data_byte(0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94);
+       &data_byte(0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf);
+       &data_byte(0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68);
+       &data_byte(0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16);
+
+       &data_byte(0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5);
+       &data_byte(0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76);
+       &data_byte(0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0);
+       &data_byte(0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0);
+       &data_byte(0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc);
+       &data_byte(0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15);
+       &data_byte(0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a);
+       &data_byte(0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75);
+       &data_byte(0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0);
+       &data_byte(0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84);
+       &data_byte(0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b);
+       &data_byte(0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf);
+       &data_byte(0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85);
+       &data_byte(0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8);
+       &data_byte(0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5);
+       &data_byte(0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2);
+       &data_byte(0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17);
+       &data_byte(0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73);
+       &data_byte(0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88);
+       &data_byte(0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb);
+       &data_byte(0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c);
+       &data_byte(0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79);
+       &data_byte(0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9);
+       &data_byte(0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08);
+       &data_byte(0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6);
+       &data_byte(0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a);
+       &data_byte(0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e);
+       &data_byte(0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e);
+       &data_byte(0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94);
+       &data_byte(0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf);
+       &data_byte(0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68);
+       &data_byte(0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16);
+
+       &data_byte(0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5);
+       &data_byte(0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76);
+       &data_byte(0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0);
+       &data_byte(0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0);
+       &data_byte(0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc);
+       &data_byte(0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15);
+       &data_byte(0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a);
+       &data_byte(0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75);
+       &data_byte(0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0);
+       &data_byte(0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84);
+       &data_byte(0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b);
+       &data_byte(0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf);
+       &data_byte(0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85);
+       &data_byte(0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8);
+       &data_byte(0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5);
+       &data_byte(0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2);
+       &data_byte(0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17);
+       &data_byte(0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73);
+       &data_byte(0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88);
+       &data_byte(0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb);
+       &data_byte(0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c);
+       &data_byte(0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79);
+       &data_byte(0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9);
+       &data_byte(0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08);
+       &data_byte(0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6);
+       &data_byte(0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a);
+       &data_byte(0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e);
+       &data_byte(0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e);
+       &data_byte(0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94);
+       &data_byte(0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf);
+       &data_byte(0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68);
+       &data_byte(0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16);
 #rcon:
        &data_word(0x00000001, 0x00000002, 0x00000004, 0x00000008);
        &data_word(0x00000010, 0x00000020, 0x00000040, 0x00000080);
-       &data_word(0x0000001b, 0x00000036, 0, 0, 0, 0, 0, 0);
+       &data_word(0x0000001b, 0x00000036, 0x00000000, 0x00000000);
+       &data_word(0x00000000, 0x00000000, 0x00000000, 0x00000000);
 &function_end_B("_x86_AES_encrypt");
 
 # void AES_encrypt (const void *inp,void *out,const AES_KEY *key);
-&public_label("AES_Te");
 &function_begin("AES_encrypt");
        &mov    ($acc,&wparam(0));              # load inp
        &mov    ($key,&wparam(2));              # load key
 
        &mov    ($s0,"esp");
-       &sub    ("esp",24);
-       &and    ("esp",-64);
-       &add    ("esp",4);
-       &mov    (&DWP(16,"esp"),$s0);
+       &sub    ("esp",36);
+       &and    ("esp",-64);                    # align to cache-line
+
+       # place stack frame just "above" the key schedule
+       &lea    ($s1,&DWP(-64-63,$key));
+       &sub    ($s1,"esp");
+       &neg    ($s1);
+       &and    ($s1,0x3C0);    # modulo 1024, but aligned to cache-line
+       &sub    ("esp",$s1);
+       &add    ("esp",4);      # 4 is reserved for caller's return address
+       &mov    ($_esp,$s0);                    # save stack pointer
 
        &call   (&label("pic_point"));          # make it PIC!
        &set_label("pic_point");
-       &blindpop("ebp");
-       &lea    ("ebp",&DWP(&label("AES_Te")."-".&label("pic_point"),"ebp"));
-
+       &blindpop($tbl);
+       &picmeup($s0,"OPENSSL_ia32cap_P",$tbl,&label("pic_point")) if (!$x86only);
+       &lea    ($tbl,&DWP(&label("AES_Te")."-".&label("pic_point"),$tbl));
+
+       # pick Te4 copy which can't "overlap" with stack frame or key schedule
+       &lea    ($s1,&DWP(768-4,"esp"));
+       &sub    ($s1,$tbl);
+       &and    ($s1,0x300);
+       &lea    ($tbl,&DWP(2048+128,$tbl,$s1));
+
+                                       if (!$x86only) {
+       &bt     (&DWP(0,$s0),25);       # check for SSE bit
+       &jnc    (&label("x86"));
+
+       &movq   ("mm0",&QWP(0,$acc));
+       &movq   ("mm4",&QWP(8,$acc));
+       &call   ("_sse_AES_encrypt_compact");
+       &mov    ("esp",$_esp);                  # restore stack pointer
+       &mov    ($acc,&wparam(1));              # load out
+       &movq   (&QWP(0,$acc),"mm0");           # write output data
+       &movq   (&QWP(8,$acc),"mm4");
+       &emms   ();
+       &function_end_A();
+                                       }
+       &set_label("x86",16);
+       &mov    ($_tbl,$tbl);
        &mov    ($s0,&DWP(0,$acc));             # load input data
        &mov    ($s1,&DWP(4,$acc));
        &mov    ($s2,&DWP(8,$acc));
        &mov    ($s3,&DWP(12,$acc));
-
-       &call   ("_x86_AES_encrypt");
-
-       &mov    ("esp",&DWP(16,"esp"));
-
+       &call   ("_x86_AES_encrypt_compact");
+       &mov    ("esp",$_esp);                  # restore stack pointer
        &mov    ($acc,&wparam(1));              # load out
        &mov    (&DWP(0,$acc),$s0);             # write output data
        &mov    (&DWP(4,$acc),$s1);
@@ -469,7 +1215,370 @@ sub _data_word() { my $i; while(defined($i=shift)) { &data_word($i,$i); } }
        &mov    (&DWP(12,$acc),$s3);
 &function_end("AES_encrypt");
 
-#------------------------------------------------------------------#
+#--------------------------------------------------------------------#
+
+######################################################################
+# "Compact" block function
+######################################################################
+
+sub deccompact()
+{ my $Fn = mov;
+  while ($#_>5) { pop(@_); $Fn=sub{}; }
+  my ($i,$td,@s)=@_;
+  my $tmp = $key;
+  my $out = $i==3?$s[0]:$acc;
+
+       # $Fn is used in first compact round and its purpose is to
+       # void restoration of some values from stack, so that after
+       # 4xdeccompact with extra argument $key, $s0 and $s1 values
+       # are left there...
+       if($i==3)   {   &$Fn    ($key,$__key);                  }
+       else        {   &mov    ($out,$s[0]);                   }
+                       &and    ($out,0xFF);
+                       &movz   ($out,&BP(-128,$td,$out,1));
+
+       if ($i==3)  {   $tmp=$s[1];                             }
+                       &movz   ($tmp,&HB($s[1]));
+                       &movz   ($tmp,&BP(-128,$td,$tmp,1));
+                       &shl    ($tmp,8);
+                       &xor    ($out,$tmp);
+
+       if ($i==3)  {   $tmp=$s[2]; &mov ($s[1],$acc);          }
+       else        {   mov     ($tmp,$s[2]);                   }
+                       &shr    ($tmp,16);
+                       &and    ($tmp,0xFF);
+                       &movz   ($tmp,&BP(-128,$td,$tmp,1));
+                       &shl    ($tmp,16);
+                       &xor    ($out,$tmp);
+
+       if ($i==3)  {   $tmp=$s[3]; &$Fn ($s[2],$__s1);         }
+       else        {   &mov    ($tmp,$s[3]);                   }
+                       &shr    ($tmp,24);
+                       &movz   ($tmp,&BP(-128,$td,$tmp,1));
+                       &shl    ($tmp,24);
+                       &xor    ($out,$tmp);
+       if ($i<2)   {   &mov    (&DWP(4+4*$i,"esp"),$out);      }
+       if ($i==3)  {   &$Fn    ($s[3],$__s0);                  }
+}
+
+# must be called with 2,3,0,1 as argument sequence!!!
+sub dectransform()
+{ my @s = ($s0,$s1,$s2,$s3);
+  my $i = shift;
+  my $tmp = $key;
+  my $tp2 = @s[($i+2)%4]; $tp2 = @s[2] if ($i==1);
+  my $tp4 = @s[($i+3)%4]; $tp4 = @s[3] if ($i==1);
+  my $tp8 = $tbl;
+
+       &mov    ($acc,$s[$i]);
+       &and    ($acc,0x80808080);
+       &mov    ($tmp,$acc);
+       &shr    ($tmp,7);
+       &lea    ($tp2,&DWP(0,$s[$i],$s[$i]));
+       &sub    ($acc,$tmp);
+       &and    ($tp2,0xfefefefe);
+       &and    ($acc,0x1b1b1b1b);
+       &xor    ($acc,$tp2);
+       &mov    ($tp2,$acc);
+
+       &and    ($acc,0x80808080);
+       &mov    ($tmp,$acc);
+       &shr    ($tmp,7);
+       &lea    ($tp4,&DWP(0,$tp2,$tp2));
+       &sub    ($acc,$tmp);
+       &and    ($tp4,0xfefefefe);
+       &and    ($acc,0x1b1b1b1b);
+        &xor   ($tp2,$s[$i]);  # tp2^tp1
+       &xor    ($acc,$tp4);
+       &mov    ($tp4,$acc);
+
+       &and    ($acc,0x80808080);
+       &mov    ($tmp,$acc);
+       &shr    ($tmp,7);
+       &lea    ($tp8,&DWP(0,$tp4,$tp4));
+       &sub    ($acc,$tmp);
+       &and    ($tp8,0xfefefefe);
+       &and    ($acc,0x1b1b1b1b);
+        &xor   ($tp4,$s[$i]);  # tp4^tp1
+        &rotl  ($s[$i],8);     # = ROTATE(tp1,8)
+       &xor    ($tp8,$acc);
+
+       &xor    ($s[$i],$tp2);
+       &xor    ($tp2,$tp8);
+       &rotl   ($tp2,24);
+       &xor    ($s[$i],$tp4);
+       &xor    ($tp4,$tp8);
+       &rotl   ($tp4,16);
+       &xor    ($s[$i],$tp8);  # ^= tp8^(tp4^tp1)^(tp2^tp1)
+       &rotl   ($tp8,8);
+       &xor    ($s[$i],$tp2);  # ^= ROTATE(tp8^tp2^tp1,24)
+       &xor    ($s[$i],$tp4);  # ^= ROTATE(tp8^tp4^tp1,16)
+        &mov   ($s[0],$__s0)                   if($i==2); #prefetch $s0
+        &mov   ($s[1],$__s1)                   if($i==3); #prefetch $s1
+        &mov   ($s[2],$__s2)                   if($i==1);
+       &xor    ($s[$i],$tp8);  # ^= ROTATE(tp8,8)
+
+       &mov    ($s[3],$__s3)                   if($i==1);
+       &mov    (&DWP(4+4*$i,"esp"),$s[$i])     if($i>=2);
+}
+
+&function_begin_B("_x86_AES_decrypt_compact");
+       # note that caller is expected to allocate stack frame for me!
+       &mov    ($__key,$key);                  # save key
+
+       &xor    ($s0,&DWP(0,$key));             # xor with key
+       &xor    ($s1,&DWP(4,$key));
+       &xor    ($s2,&DWP(8,$key));
+       &xor    ($s3,&DWP(12,$key));
+
+       &mov    ($acc,&DWP(240,$key));          # load key->rounds
+
+       &lea    ($acc,&DWP(-2,$acc,$acc));
+       &lea    ($acc,&DWP(0,$key,$acc,8));
+       &mov    ($__end,$acc);                  # end of key schedule
+
+       # prefetch Td4
+       &mov    ($key,&DWP(0-128,$tbl));
+       &mov    ($acc,&DWP(32-128,$tbl));
+       &mov    ($key,&DWP(64-128,$tbl));
+       &mov    ($acc,&DWP(96-128,$tbl));
+       &mov    ($key,&DWP(128-128,$tbl));
+       &mov    ($acc,&DWP(160-128,$tbl));
+       &mov    ($key,&DWP(192-128,$tbl));
+       &mov    ($acc,&DWP(224-128,$tbl));
+
+       &set_label("loop",16);
+
+               &deccompact(0,$tbl,$s0,$s3,$s2,$s1,1);
+               &deccompact(1,$tbl,$s1,$s0,$s3,$s2,1);
+               &deccompact(2,$tbl,$s2,$s1,$s0,$s3,1);
+               &deccompact(3,$tbl,$s3,$s2,$s1,$s0,1);
+               &dectransform(2);
+               &dectransform(3);
+               &dectransform(0);
+               &dectransform(1);
+               &mov    ($key,$__key);
+               &mov    ($tbl,$__tbl);
+               &add    ($key,16);              # advance rd_key
+               &xor    ($s0,&DWP(0,$key));
+               &xor    ($s1,&DWP(4,$key));
+               &xor    ($s2,&DWP(8,$key));
+               &xor    ($s3,&DWP(12,$key));
+
+       &cmp    ($key,$__end);
+       &mov    ($__key,$key);
+       &jb     (&label("loop"));
+
+       &deccompact(0,$tbl,$s0,$s3,$s2,$s1);
+       &deccompact(1,$tbl,$s1,$s0,$s3,$s2);
+       &deccompact(2,$tbl,$s2,$s1,$s0,$s3);
+       &deccompact(3,$tbl,$s3,$s2,$s1,$s0);
+
+       &xor    ($s0,&DWP(16,$key));
+       &xor    ($s1,&DWP(20,$key));
+       &xor    ($s2,&DWP(24,$key));
+       &xor    ($s3,&DWP(28,$key));
+
+       &ret    ();
+&function_end_B("_x86_AES_decrypt_compact");
+
+######################################################################
+# "Compact" SSE block function.
+######################################################################
+
+sub sse_deccompact()
+{
+       &pshufw ("mm1","mm0",0x0c);             #  7, 6, 1, 0
+       &movd   ("eax","mm1");                  #  7, 6, 1, 0
+
+       &pshufw ("mm5","mm4",0x09);             # 13,12,11,10
+       &movz   ($acc,&LB("eax"));              #  0
+       &movz   ("ecx",&BP(-128,$tbl,$acc,1));  #  0
+       &movd   ("ebx","mm5");                  # 13,12,11,10
+       &movz   ("edx",&HB("eax"));             #  1
+       &movz   ("edx",&BP(-128,$tbl,"edx",1)); #  1
+       &shl    ("edx",8);                      #  1
+
+       &pshufw ("mm2","mm0",0x06);             #  3, 2, 5, 4
+       &movz   ($acc,&LB("ebx"));              # 10
+       &movz   ($acc,&BP(-128,$tbl,$acc,1));   # 10
+       &shl    ($acc,16);                      # 10
+       &or     ("ecx",$acc);                   # 10
+       &shr    ("eax",16);                     #  7, 6
+       &movz   ($acc,&HB("ebx"));              # 11
+       &movz   ($acc,&BP(-128,$tbl,$acc,1));   # 11
+       &shl    ($acc,24);                      # 11
+       &or     ("edx",$acc);                   # 11
+       &shr    ("ebx",16);                     # 13,12
+
+       &pshufw ("mm6","mm4",0x03);             # 9, 8,15,14
+       &movz   ($acc,&HB("eax"));              #  7
+       &movz   ($acc,&BP(-128,$tbl,$acc,1));   #  7
+       &shl    ($acc,24);                      #  7
+       &or     ("ecx",$acc);                   #  7
+       &movz   ($acc,&HB("ebx"));              # 13
+       &movz   ($acc,&BP(-128,$tbl,$acc,1));   # 13
+       &shl    ($acc,8);                       # 13
+       &or     ("ecx",$acc);                   # 13
+       &movd   ("mm0","ecx");                  # t[0] collected
+
+       &movz   ($acc,&LB("eax"));              #  6
+       &movd   ("eax","mm2");                  #  3, 2, 5, 4
+       &movz   ("ecx",&BP(-128,$tbl,$acc,1));  #  6
+       &shl    ("ecx",16);                     #  6
+       &movz   ($acc,&LB("ebx"));              # 12
+       &movd   ("ebx","mm6");                  #  9, 8,15,14
+       &movz   ($acc,&BP(-128,$tbl,$acc,1));   # 12
+       &or     ("ecx",$acc);                   # 12
+
+       &movz   ($acc,&LB("eax"));              #  4
+       &movz   ($acc,&BP(-128,$tbl,$acc,1));   #  4
+       &or     ("edx",$acc);                   #  4
+       &movz   ($acc,&LB("ebx"));              # 14
+       &movz   ($acc,&BP(-128,$tbl,$acc,1));   # 14
+       &shl    ($acc,16);                      # 14
+       &or     ("edx",$acc);                   # 14
+       &movd   ("mm1","edx");                  # t[1] collected
+
+       &movz   ($acc,&HB("eax"));              #  5
+       &movz   ("edx",&BP(-128,$tbl,$acc,1));  #  5
+       &shl    ("edx",8);                      #  5
+       &movz   ($acc,&HB("ebx"));              # 15
+       &shr    ("eax",16);                     #  3, 2
+       &movz   ($acc,&BP(-128,$tbl,$acc,1));   # 15
+       &shl    ($acc,24);                      # 15
+       &or     ("edx",$acc);                   # 15
+       &shr    ("ebx",16);                     #  9, 8
+
+       &punpckldq      ("mm0","mm1");          # t[0,1] collected
+
+       &movz   ($acc,&HB("ebx"));              #  9
+       &movz   ($acc,&BP(-128,$tbl,$acc,1));   #  9
+       &shl    ($acc,8);                       #  9
+       &or     ("ecx",$acc);                   #  9
+       &and    ("ebx",0xff);                   #  8
+       &movz   ("ebx",&BP(-128,$tbl,"ebx",1)); #  8
+       &or     ("edx","ebx");                  #  8
+       &movz   ($acc,&LB("eax"));              #  2
+       &movz   ($acc,&BP(-128,$tbl,$acc,1));   #  2
+       &shl    ($acc,16);                      #  2
+       &or     ("edx",$acc);                   #  2
+       &movd   ("mm4","edx");                  # t[2] collected
+       &movz   ("eax",&HB("eax"));             #  3
+       &movz   ("eax",&BP(-128,$tbl,"eax",1)); #  3
+       &shl    ("eax",24);                     #  3
+       &or     ("ecx","eax");                  #  3
+       &movd   ("mm5","ecx");                  # t[3] collected
+
+       &punpckldq      ("mm4","mm5");          # t[2,3] collected
+}
+
+                                       if (!$x86only) {
+&function_begin_B("_sse_AES_decrypt_compact");
+       &pxor   ("mm0",&QWP(0,$key));   #  7, 6, 5, 4, 3, 2, 1, 0
+       &pxor   ("mm4",&QWP(8,$key));   # 15,14,13,12,11,10, 9, 8
+
+       # note that caller is expected to allocate stack frame for me!
+       &mov    ($acc,&DWP(240,$key));          # load key->rounds
+       &lea    ($acc,&DWP(-2,$acc,$acc));
+       &lea    ($acc,&DWP(0,$key,$acc,8));
+       &mov    ($__end,$acc);                  # end of key schedule
+
+       &mov    ($s0,0x1b1b1b1b);               # magic constant
+       &mov    (&DWP(8,"esp"),$s0);
+       &mov    (&DWP(12,"esp"),$s0);
+
+       # prefetch Td4
+       &mov    ($s0,&DWP(0-128,$tbl));
+       &mov    ($s1,&DWP(32-128,$tbl));
+       &mov    ($s2,&DWP(64-128,$tbl));
+       &mov    ($s3,&DWP(96-128,$tbl));
+       &mov    ($s0,&DWP(128-128,$tbl));
+       &mov    ($s1,&DWP(160-128,$tbl));
+       &mov    ($s2,&DWP(192-128,$tbl));
+       &mov    ($s3,&DWP(224-128,$tbl));
+
+       &set_label("loop",16);
+               &sse_deccompact();
+               &add    ($key,16);
+               &cmp    ($key,$__end);
+               &ja     (&label("out"));
+
+               # ROTATE(x^y,N) == ROTATE(x,N)^ROTATE(y,N)
+               &movq   ("mm3","mm0");          &movq   ("mm7","mm4");
+               &movq   ("mm2","mm0",1);        &movq   ("mm6","mm4",1);
+               &movq   ("mm1","mm0");          &movq   ("mm5","mm4");
+               &pshufw ("mm0","mm0",0xb1);     &pshufw ("mm4","mm4",0xb1);# = ROTATE(tp0,16)
+               &pslld  ("mm2",8);              &pslld  ("mm6",8);
+               &psrld  ("mm3",8);              &psrld  ("mm7",8);
+               &pxor   ("mm0","mm2");          &pxor   ("mm4","mm6");  # ^= tp0<<8
+               &pxor   ("mm0","mm3");          &pxor   ("mm4","mm7");  # ^= tp0>>8
+               &pslld  ("mm2",16);             &pslld  ("mm6",16);
+               &psrld  ("mm3",16);             &psrld  ("mm7",16);
+               &pxor   ("mm0","mm2");          &pxor   ("mm4","mm6");  # ^= tp0<<24
+               &pxor   ("mm0","mm3");          &pxor   ("mm4","mm7");  # ^= tp0>>24
+
+               &movq   ("mm3",&QWP(8,"esp"));
+               &pxor   ("mm2","mm2");          &pxor   ("mm6","mm6");
+               &pcmpgtb("mm2","mm1");          &pcmpgtb("mm6","mm5");
+               &pand   ("mm2","mm3");          &pand   ("mm6","mm3");
+               &paddb  ("mm1","mm1");          &paddb  ("mm5","mm5");
+               &pxor   ("mm1","mm2");          &pxor   ("mm5","mm6");  # tp2
+               &movq   ("mm3","mm1");          &movq   ("mm7","mm5");
+               &movq   ("mm2","mm1");          &movq   ("mm6","mm5");
+               &pxor   ("mm0","mm1");          &pxor   ("mm4","mm5");  # ^= tp2
+               &pslld  ("mm3",24);             &pslld  ("mm7",24);
+               &psrld  ("mm2",8);              &psrld  ("mm6",8);
+               &pxor   ("mm0","mm3");          &pxor   ("mm4","mm7");  # ^= tp2<<24
+               &pxor   ("mm0","mm2");          &pxor   ("mm4","mm6");  # ^= tp2>>8
+
+               &movq   ("mm2",&QWP(8,"esp"));
+               &pxor   ("mm3","mm3");          &pxor   ("mm7","mm7");
+               &pcmpgtb("mm3","mm1");          &pcmpgtb("mm7","mm5");
+               &pand   ("mm3","mm2");          &pand   ("mm7","mm2");
+               &paddb  ("mm1","mm1");          &paddb  ("mm5","mm5");
+               &pxor   ("mm1","mm3");          &pxor   ("mm5","mm7");  # tp4
+               &pshufw ("mm3","mm1",0xb1);     &pshufw ("mm7","mm5",0xb1);
+               &pxor   ("mm0","mm1");          &pxor   ("mm4","mm5");  # ^= tp4
+               &pxor   ("mm0","mm3");          &pxor   ("mm4","mm7");  # ^= ROTATE(tp4,16)     
+
+               &pxor   ("mm3","mm3");          &pxor   ("mm7","mm7");
+               &pcmpgtb("mm3","mm1");          &pcmpgtb("mm7","mm5");
+               &pand   ("mm3","mm2");          &pand   ("mm7","mm2");
+               &paddb  ("mm1","mm1");          &paddb  ("mm5","mm5");
+               &pxor   ("mm1","mm3");          &pxor   ("mm5","mm7");  # tp8
+               &pxor   ("mm0","mm1");          &pxor   ("mm4","mm5");  # ^= tp8
+               &movq   ("mm3","mm1");          &movq   ("mm7","mm5");
+               &pshufw ("mm2","mm1",0xb1);     &pshufw ("mm6","mm5",0xb1);
+               &pxor   ("mm0","mm2");          &pxor   ("mm4","mm6");  # ^= ROTATE(tp8,16)
+               &pslld  ("mm1",8);              &pslld  ("mm5",8);
+               &psrld  ("mm3",8);              &psrld  ("mm7",8);
+               &movq   ("mm2",&QWP(0,$key));   &movq   ("mm6",&QWP(8,$key));
+               &pxor   ("mm0","mm1");          &pxor   ("mm4","mm5");  # ^= tp8<<8
+               &pxor   ("mm0","mm3");          &pxor   ("mm4","mm7");  # ^= tp8>>8
+               &mov    ($s0,&DWP(0-128,$tbl));
+               &pslld  ("mm1",16);             &pslld  ("mm5",16);
+               &mov    ($s1,&DWP(64-128,$tbl));
+               &psrld  ("mm3",16);             &psrld  ("mm7",16);
+               &mov    ($s2,&DWP(128-128,$tbl));
+               &pxor   ("mm0","mm1");          &pxor   ("mm4","mm5");  # ^= tp8<<24
+               &mov    ($s3,&DWP(192-128,$tbl));
+               &pxor   ("mm0","mm3");          &pxor   ("mm4","mm7");  # ^= tp8>>24
+
+               &pxor   ("mm0","mm2");          &pxor   ("mm4","mm6");
+       &jmp    (&label("loop"));
+
+       &set_label("out",16);
+       &pxor   ("mm0",&QWP(0,$key));
+       &pxor   ("mm4",&QWP(8,$key));
+
+       &ret    ();
+&function_end_B("_sse_AES_decrypt_compact");
+                                       }
+
+######################################################################
+# Vanilla block function.
+######################################################################
 
 sub decstep()
 { my ($i,$td,@s) = @_;
@@ -480,7 +1589,7 @@ sub decstep()
        # optimal... or rather that all attempts to reorder didn't
        # result in better performance [which by the way is not a
        # bit lower than ecryption].
-       if($i==3)   {   &mov    ($key,&DWP(12,"esp"));          }
+       if($i==3)   {   &mov    ($key,$__key);                  }
        else        {   &mov    ($out,$s[0]);                   }
                        &and    ($out,0xFF);
                        &mov    ($out,&DWP(0,$td,$out,8));
@@ -495,12 +1604,12 @@ sub decstep()
                        &and    ($tmp,0xFF);
                        &xor    ($out,&DWP(2,$td,$tmp,8));
 
-       if ($i==3)  {   $tmp=$s[3]; &mov ($s[2],&DWP(8,"esp")); }
+       if ($i==3)  {   $tmp=$s[3]; &mov ($s[2],$__s1);         }
        else        {   &mov    ($tmp,$s[3]);                   }
                        &shr    ($tmp,24);
                        &xor    ($out,&DWP(1,$td,$tmp,8));
        if ($i<2)   {   &mov    (&DWP(4+4*$i,"esp"),$out);      }
-       if ($i==3)  {   &mov    ($s[3],&DWP(4,"esp"));          }
+       if ($i==3)  {   &mov    ($s[3],$__s0);                  }
                        &comment();
 }
 
@@ -509,14 +1618,24 @@ sub declast()
   my $tmp = $key;
   my $out = $i==3?$s[0]:$acc;
 
-       if($i==3)   {   &mov    ($key,&DWP(12,"esp"));          }
+       if($i==0)   {   &lea    ($td,&DWP(2048+128,$td));
+                       &mov    ($tmp,&DWP(0-128,$td));
+                       &mov    ($acc,&DWP(32-128,$td));
+                       &mov    ($tmp,&DWP(64-128,$td));
+                       &mov    ($acc,&DWP(96-128,$td));
+                       &mov    ($tmp,&DWP(128-128,$td));
+                       &mov    ($acc,&DWP(160-128,$td));
+                       &mov    ($tmp,&DWP(192-128,$td));
+                       &mov    ($acc,&DWP(224-128,$td));
+                       &lea    ($td,&DWP(-128,$td));           }
+       if($i==3)   {   &mov    ($key,$__key);                  }
        else        {   &mov    ($out,$s[0]);                   }
                        &and    ($out,0xFF);
-                       &movz   ($out,&BP(2048,$td,$out,1));
+                       &movz   ($out,&BP(0,$td,$out,1));
 
        if ($i==3)  {   $tmp=$s[1];                             }
                        &movz   ($tmp,&HB($s[1]));
-                       &movz   ($tmp,&BP(2048,$td,$tmp,1));
+                       &movz   ($tmp,&BP(0,$td,$tmp,1));
                        &shl    ($tmp,8);
                        &xor    ($out,$tmp);
 
@@ -524,24 +1643,24 @@ sub declast()
        else        {   mov     ($tmp,$s[2]);                   }
                        &shr    ($tmp,16);
                        &and    ($tmp,0xFF);
-                       &movz   ($tmp,&BP(2048,$td,$tmp,1));
+                       &movz   ($tmp,&BP(0,$td,$tmp,1));
                        &shl    ($tmp,16);
                        &xor    ($out,$tmp);
 
-       if ($i==3)  {   $tmp=$s[3]; &mov ($s[2],&DWP(8,"esp")); }
+       if ($i==3)  {   $tmp=$s[3]; &mov ($s[2],$__s1);         }
        else        {   &mov    ($tmp,$s[3]);                   }
                        &shr    ($tmp,24);
-                       &movz   ($tmp,&BP(2048,$td,$tmp,1));
+                       &movz   ($tmp,&BP(0,$td,$tmp,1));
                        &shl    ($tmp,24);
                        &xor    ($out,$tmp);
        if ($i<2)   {   &mov    (&DWP(4+4*$i,"esp"),$out);      }
-       if ($i==3)  {   &mov    ($s[3],&DWP(4,"esp"));          }
+       if ($i==3)  {   &mov    ($s[3],$__s0);
+                       &lea    ($td,&DWP(-2048,$td));          }
 }
 
-&public_label("AES_Td");
 &function_begin_B("_x86_AES_decrypt");
        # note that caller is expected to allocate stack frame for me!
-       &mov    (&DWP(12,"esp"),$key);          # save key
+       &mov    ($__key,$key);                  # save key
 
        &xor    ($s0,&DWP(0,$key));             # xor with key
        &xor    ($s1,&DWP(4,$key));
@@ -553,20 +1672,19 @@ sub declast()
        if ($small_footprint) {
            &lea        ($acc,&DWP(-2,$acc,$acc));
            &lea        ($acc,&DWP(0,$key,$acc,8));
-           &mov        (&DWP(16,"esp"),$acc);  # end of key schedule
-           &align      (4);
-           &set_label("loop");
-               &decstep(0,"ebp",$s0,$s3,$s2,$s1);
-               &decstep(1,"ebp",$s1,$s0,$s3,$s2);
-               &decstep(2,"ebp",$s2,$s1,$s0,$s3);
-               &decstep(3,"ebp",$s3,$s2,$s1,$s0);
+           &mov        ($__end,$acc);          # end of key schedule
+           &set_label("loop",16);
+               &decstep(0,$tbl,$s0,$s3,$s2,$s1);
+               &decstep(1,$tbl,$s1,$s0,$s3,$s2);
+               &decstep(2,$tbl,$s2,$s1,$s0,$s3);
+               &decstep(3,$tbl,$s3,$s2,$s1,$s0);
                &add    ($key,16);              # advance rd_key
                &xor    ($s0,&DWP(0,$key));
                &xor    ($s1,&DWP(4,$key));
                &xor    ($s2,&DWP(8,$key));
                &xor    ($s3,&DWP(12,$key));
-           &cmp        ($key,&DWP(16,"esp"));
-           &mov        (&DWP(12,"esp"),$key);
+           &cmp        ($key,$__end);
+           &mov        ($__key,$key);
            &jb         (&label("loop"));
        }
        else {
@@ -575,38 +1693,38 @@ sub declast()
            &cmp        ($acc,12);
            &jle        (&label("12rounds"));
 
-       &set_label("14rounds");
+       &set_label("14rounds",4);
            for ($i=1;$i<3;$i++) {
-               &decstep(0,"ebp",$s0,$s3,$s2,$s1);
-               &decstep(1,"ebp",$s1,$s0,$s3,$s2);
-               &decstep(2,"ebp",$s2,$s1,$s0,$s3);
-               &decstep(3,"ebp",$s3,$s2,$s1,$s0);
+               &decstep(0,$tbl,$s0,$s3,$s2,$s1);
+               &decstep(1,$tbl,$s1,$s0,$s3,$s2);
+               &decstep(2,$tbl,$s2,$s1,$s0,$s3);
+               &decstep(3,$tbl,$s3,$s2,$s1,$s0);
                &xor    ($s0,&DWP(16*$i+0,$key));
                &xor    ($s1,&DWP(16*$i+4,$key));
                &xor    ($s2,&DWP(16*$i+8,$key));
                &xor    ($s3,&DWP(16*$i+12,$key));
            }
            &add        ($key,32);
-           &mov        (&DWP(12,"esp"),$key);  # advance rd_key
-       &set_label("12rounds");
+           &mov        ($__key,$key);          # advance rd_key
+       &set_label("12rounds",4);
            for ($i=1;$i<3;$i++) {
-               &decstep(0,"ebp",$s0,$s3,$s2,$s1);
-               &decstep(1,"ebp",$s1,$s0,$s3,$s2);
-               &decstep(2,"ebp",$s2,$s1,$s0,$s3);
-               &decstep(3,"ebp",$s3,$s2,$s1,$s0);
+               &decstep(0,$tbl,$s0,$s3,$s2,$s1);
+               &decstep(1,$tbl,$s1,$s0,$s3,$s2);
+               &decstep(2,$tbl,$s2,$s1,$s0,$s3);
+               &decstep(3,$tbl,$s3,$s2,$s1,$s0);
                &xor    ($s0,&DWP(16*$i+0,$key));
                &xor    ($s1,&DWP(16*$i+4,$key));
                &xor    ($s2,&DWP(16*$i+8,$key));
                &xor    ($s3,&DWP(16*$i+12,$key));
            }
            &add        ($key,32);
-           &mov        (&DWP(12,"esp"),$key);  # advance rd_key
-       &set_label("10rounds");
+           &mov        ($__key,$key);          # advance rd_key
+       &set_label("10rounds",4);
            for ($i=1;$i<10;$i++) {
-               &decstep(0,"ebp",$s0,$s3,$s2,$s1);
-               &decstep(1,"ebp",$s1,$s0,$s3,$s2);
-               &decstep(2,"ebp",$s2,$s1,$s0,$s3);
-               &decstep(3,"ebp",$s3,$s2,$s1,$s0);
+               &decstep(0,$tbl,$s0,$s3,$s2,$s1);
+               &decstep(1,$tbl,$s1,$s0,$s3,$s2);
+               &decstep(2,$tbl,$s2,$s1,$s0,$s3);
+               &decstep(3,$tbl,$s3,$s2,$s1,$s0);
                &xor    ($s0,&DWP(16*$i+0,$key));
                &xor    ($s1,&DWP(16*$i+4,$key));
                &xor    ($s2,&DWP(16*$i+8,$key));
@@ -614,10 +1732,10 @@ sub declast()
            }
        }
 
-       &declast(0,"ebp",$s0,$s3,$s2,$s1);
-       &declast(1,"ebp",$s1,$s0,$s3,$s2);
-       &declast(2,"ebp",$s2,$s1,$s0,$s3);
-       &declast(3,"ebp",$s3,$s2,$s1,$s0);
+       &declast(0,$tbl,$s0,$s3,$s2,$s1);
+       &declast(1,$tbl,$s1,$s0,$s3,$s2);
+       &declast(2,$tbl,$s2,$s1,$s0,$s3);
+       &declast(3,$tbl,$s3,$s2,$s1,$s0);
 
        &add    ($key,$small_footprint?16:160);
        &xor    ($s0,&DWP(0,$key));
@@ -692,7 +1810,8 @@ sub declast()
        &_data_word(0x72c31d16, 0x0c25e2bc, 0x8b493c28, 0x41950dff);
        &_data_word(0x7101a839, 0xdeb30c08, 0x9ce4b4d8, 0x90c15664);
        &_data_word(0x6184cb7b, 0x70b632d5, 0x745c6c48, 0x4257b8d0);
-#Td4:
+
+#Td4:  # four copies of Td4 to choose from to avoid L1 aliasing
        &data_byte(0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38);
        &data_byte(0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb);
        &data_byte(0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87);
@@ -725,178 +1844,301 @@ sub declast()
        &data_byte(0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61);
        &data_byte(0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26);
        &data_byte(0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d);
-&function_end_B("_x86_AES_decrypt");
-
-# void AES_decrypt (const void *inp,void *out,const AES_KEY *key);
-&public_label("AES_Td");
-&function_begin("AES_decrypt");
-       &mov    ($acc,&wparam(0));              # load inp
-       &mov    ($key,&wparam(2));              # load key
-
-       &mov    ($s0,"esp");
-       &sub    ("esp",24);
-       &and    ("esp",-64);
-       &add    ("esp",4);
-       &mov    (&DWP(16,"esp"),$s0);
-
-       &call   (&label("pic_point"));          # make it PIC!
-       &set_label("pic_point");
-       &blindpop("ebp");
-       &lea    ("ebp",&DWP(&label("AES_Td")."-".&label("pic_point"),"ebp"));
-
-       # prefetch Td4
-       &lea    ("ebp",&DWP(2048+128,"ebp"));
-       &mov    ($s0,&DWP(0-128,"ebp"));
-       &mov    ($s1,&DWP(32-128,"ebp"));
-       &mov    ($s2,&DWP(64-128,"ebp"));
-       &mov    ($s3,&DWP(96-128,"ebp"));
-       &mov    ($s0,&DWP(128-128,"ebp"));
-       &mov    ($s1,&DWP(160-128,"ebp"));
-       &mov    ($s2,&DWP(192-128,"ebp"));
-       &mov    ($s3,&DWP(224-128,"ebp"));
-       &lea    ("ebp",&DWP(-2048-128,"ebp"));
-
-       &mov    ($s0,&DWP(0,$acc));             # load input data
-       &mov    ($s1,&DWP(4,$acc));
-       &mov    ($s2,&DWP(8,$acc));
-       &mov    ($s3,&DWP(12,$acc));
 
-       &call   ("_x86_AES_decrypt");
-
-       &mov    ("esp",&DWP(16,"esp"));
+       &data_byte(0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38);
+       &data_byte(0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb);
+       &data_byte(0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87);
+       &data_byte(0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb);
+       &data_byte(0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d);
+       &data_byte(0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e);
+       &data_byte(0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2);
+       &data_byte(0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25);
+       &data_byte(0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16);
+       &data_byte(0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92);
+       &data_byte(0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda);
+       &data_byte(0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84);
+       &data_byte(0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a);
+       &data_byte(0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06);
+       &data_byte(0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02);
+       &data_byte(0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b);
+       &data_byte(0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea);
+       &data_byte(0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73);
+       &data_byte(0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85);
+       &data_byte(0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e);
+       &data_byte(0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89);
+       &data_byte(0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b);
+       &data_byte(0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20);
+       &data_byte(0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4);
+       &data_byte(0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31);
+       &data_byte(0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f);
+       &data_byte(0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d);
+       &data_byte(0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef);
+       &data_byte(0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0);
+       &data_byte(0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61);
+       &data_byte(0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26);
+       &data_byte(0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d);
 
-       &mov    ($acc,&wparam(1));              # load out
-       &mov    (&DWP(0,$acc),$s0);             # write output data
-       &mov    (&DWP(4,$acc),$s1);
-       &mov    (&DWP(8,$acc),$s2);
-       &mov    (&DWP(12,$acc),$s3);
-&function_end("AES_decrypt");
+       &data_byte(0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38);
+       &data_byte(0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb);
+       &data_byte(0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87);
+       &data_byte(0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb);
+       &data_byte(0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d);
+       &data_byte(0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e);
+       &data_byte(0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2);
+       &data_byte(0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25);
+       &data_byte(0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16);
+       &data_byte(0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92);
+       &data_byte(0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda);
+       &data_byte(0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84);
+       &data_byte(0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a);
+       &data_byte(0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06);
+       &data_byte(0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02);
+       &data_byte(0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b);
+       &data_byte(0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea);
+       &data_byte(0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73);
+       &data_byte(0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85);
+       &data_byte(0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e);
+       &data_byte(0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89);
+       &data_byte(0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b);
+       &data_byte(0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20);
+       &data_byte(0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4);
+       &data_byte(0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31);
+       &data_byte(0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f);
+       &data_byte(0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d);
+       &data_byte(0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef);
+       &data_byte(0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0);
+       &data_byte(0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61);
+       &data_byte(0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26);
+       &data_byte(0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d);
 
-# void AES_cbc_encrypt (const void char *inp, unsigned char *out,
-#                      size_t length, const AES_KEY *key,
-#                      unsigned char *ivp,const int enc);
+       &data_byte(0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38);
+       &data_byte(0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb);
+       &data_byte(0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87);
+       &data_byte(0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb);
+       &data_byte(0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d);
+       &data_byte(0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e);
+       &data_byte(0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2);
+       &data_byte(0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25);
+       &data_byte(0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16);
+       &data_byte(0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92);
+       &data_byte(0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda);
+       &data_byte(0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84);
+       &data_byte(0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a);
+       &data_byte(0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06);
+       &data_byte(0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02);
+       &data_byte(0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b);
+       &data_byte(0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea);
+       &data_byte(0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73);
+       &data_byte(0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85);
+       &data_byte(0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e);
+       &data_byte(0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89);
+       &data_byte(0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b);
+       &data_byte(0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20);
+       &data_byte(0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4);
+       &data_byte(0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31);
+       &data_byte(0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f);
+       &data_byte(0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d);
+       &data_byte(0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef);
+       &data_byte(0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0);
+       &data_byte(0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61);
+       &data_byte(0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26);
+       &data_byte(0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d);
+&function_end_B("_x86_AES_decrypt");
+
+# void AES_decrypt (const void *inp,void *out,const AES_KEY *key);
+&function_begin("AES_decrypt");
+       &mov    ($acc,&wparam(0));              # load inp
+       &mov    ($key,&wparam(2));              # load key
+
+       &mov    ($s0,"esp");
+       &sub    ("esp",36);
+       &and    ("esp",-64);                    # align to cache-line
+
+       # place stack frame just "above" the key schedule
+       &lea    ($s1,&DWP(-64-63,$key));
+       &sub    ($s1,"esp");
+       &neg    ($s1);
+       &and    ($s1,0x3C0);    # modulo 1024, but aligned to cache-line
+       &sub    ("esp",$s1);
+       &add    ("esp",4);      # 4 is reserved for caller's return address
+       &mov    ($_esp,$s0);    # save stack pointer
+
+       &call   (&label("pic_point"));          # make it PIC!
+       &set_label("pic_point");
+       &blindpop($tbl);
+       &picmeup($s0,"OPENSSL_ia32cap_P",$tbl,&label("pic_point")) if(!$x86only);
+       &lea    ($tbl,&DWP(&label("AES_Td")."-".&label("pic_point"),$tbl));
+
+       # pick Td4 copy which can't "overlap" with stack frame or key schedule
+       &lea    ($s1,&DWP(768-4,"esp"));
+       &sub    ($s1,$tbl);
+       &and    ($s1,0x300);
+       &lea    ($tbl,&DWP(2048+128,$tbl,$s1));
+
+                                       if (!$x86only) {
+       &bt     (&DWP(0,$s0),25);       # check for SSE bit
+       &jnc    (&label("x86"));
+
+       &movq   ("mm0",&QWP(0,$acc));
+       &movq   ("mm4",&QWP(8,$acc));
+       &call   ("_sse_AES_decrypt_compact");
+       &mov    ("esp",$_esp);                  # restore stack pointer
+       &mov    ($acc,&wparam(1));              # load out
+       &movq   (&QWP(0,$acc),"mm0");           # write output data
+       &movq   (&QWP(8,$acc),"mm4");
+       &emms   ();
+       &function_end_A();
+                                       }
+       &set_label("x86",16);
+       &mov    ($_tbl,$tbl);
+       &mov    ($s0,&DWP(0,$acc));             # load input data
+       &mov    ($s1,&DWP(4,$acc));
+       &mov    ($s2,&DWP(8,$acc));
+       &mov    ($s3,&DWP(12,$acc));
+       &call   ("_x86_AES_decrypt_compact");
+       &mov    ("esp",$_esp);                  # restore stack pointer
+       &mov    ($acc,&wparam(1));              # load out
+       &mov    (&DWP(0,$acc),$s0);             # write output data
+       &mov    (&DWP(4,$acc),$s1);
+       &mov    (&DWP(8,$acc),$s2);
+       &mov    (&DWP(12,$acc),$s3);
+&function_end("AES_decrypt");
+
+# void AES_cbc_encrypt (const void char *inp, unsigned char *out,
+#                      size_t length, const AES_KEY *key,
+#                      unsigned char *ivp,const int enc);
 {
 # stack frame layout
-# -4(%esp)     0(%esp)         return address
-# 0(%esp)      4(%esp)         tmp1
-# 4(%esp)      8(%esp)         tmp2
-# 8(%esp)      12(%esp)        key
-# 12(%esp)     16(%esp)        end of key schedule
-my $_esp=&DWP(16,"esp");       #saved %esp
-my $_inp=&DWP(20,"esp");       #copy of wparam(0)
-my $_out=&DWP(24,"esp");       #copy of wparam(1)
-my $_len=&DWP(28,"esp");       #copy of wparam(2)
-my $_key=&DWP(32,"esp");       #copy of wparam(3)
-my $_ivp=&DWP(36,"esp");       #copy of wparam(4)
-my $_tmp=&DWP(40,"esp");       #volatile variable
-my $ivec=&DWP(44,"esp");       #ivec[16]
-my $aes_key=&DWP(60,"esp");    #copy of aes_key
-my $mark=&DWP(60+240,"esp");   #copy of aes_key->rounds
-
-&public_label("AES_Te");
-&public_label("AES_Td");
+#             -4(%esp)         # return address         0(%esp)
+#              0(%esp)         # s0 backing store       4(%esp)        
+#              4(%esp)         # s1 backing store       8(%esp)
+#              8(%esp)         # s2 backing store      12(%esp)
+#             12(%esp)         # s3 backing store      16(%esp)
+#             16(%esp)         # key backup            20(%esp)
+#             20(%esp)         # end of key schedule   24(%esp)
+#             24(%esp)         # %ebp backup           28(%esp)
+#             28(%esp)         # %esp backup
+my $_inp=&DWP(32,"esp");       # copy of wparam(0)
+my $_out=&DWP(36,"esp");       # copy of wparam(1)
+my $_len=&DWP(40,"esp");       # copy of wparam(2)
+my $_key=&DWP(44,"esp");       # copy of wparam(3)
+my $_ivp=&DWP(48,"esp");       # copy of wparam(4)
+my $_tmp=&DWP(52,"esp");       # volatile variable
+#
+my $ivec=&DWP(60,"esp");       # ivec[16]
+my $aes_key=&DWP(76,"esp");    # copy of aes_key
+my $mark=&DWP(76+240,"esp");   # copy of aes_key->rounds
+
 &function_begin("AES_cbc_encrypt");
        &mov    ($s2 eq "ecx"? $s2 : "",&wparam(2));    # load len
        &cmp    ($s2,0);
-       &je     (&label("enc_out"));
+       &je     (&label("drop_out"));
 
        &call   (&label("pic_point"));          # make it PIC!
        &set_label("pic_point");
-       &blindpop("ebp");
-
-       &pushf  ();
-       &cld    ();
+       &blindpop($tbl);
+       &picmeup($s0,"OPENSSL_ia32cap_P",$tbl,&label("pic_point")) if(!$x86only);
 
        &cmp    (&wparam(5),0);
-       &je     (&label("DECRYPT"));
-
-       &lea    ("ebp",&DWP(&label("AES_Te")."-".&label("pic_point"),"ebp"));
+       &lea    ($tbl,&DWP(&label("AES_Te")."-".&label("pic_point"),$tbl));
+       &jne    (&label("picked_te"));
+       &lea    ($tbl,&DWP(&label("AES_Td")."-".&label("AES_Te"),$tbl));
+       &set_label("picked_te");
 
-       # allocate aligned stack frame...
-       &lea    ($key,&DWP(-64-244,"esp"));
-       &and    ($key,-64);
+       # one can argue if this is required
+       &pushf  ();
+       &cld    ();
 
-       # ... and make sure it doesn't alias with AES_Te modulo 4096
-       &mov    ($s0,"ebp");
-       &lea    ($s1,&DWP(2048,"ebp"));
-       &mov    ($s3,$key);
+       &cmp    ($s2,$speed_limit);
+       &jb     (&label("slow_way"));
+       &test   ($s2,15);
+       &jnz    (&label("slow_way"));
+                                       if (!$x86only) {
+       &bt     (&DWP(0,$s0),28);       # check for hyper-threading bit
+       &jc     (&label("slow_way"));
+                                       }
+       # pre-allocate aligned stack frame...
+       &lea    ($acc,&DWP(-80-244,"esp"));
+       &and    ($acc,-64);
+
+       # ... and make sure it doesn't alias with $tbl modulo 4096
+       &mov    ($s0,$tbl);
+       &lea    ($s1,&DWP(2048+256,$tbl));
+       &mov    ($s3,$acc);
        &and    ($s0,0xfff);            # s = %ebp&0xfff
-       &and    ($s1,0xfff);            # e = (%ebp+2048)&0xfff
+       &and    ($s1,0xfff);            # e = (%ebp+2048+256)&0xfff
        &and    ($s3,0xfff);            # p = %esp&0xfff
 
        &cmp    ($s3,$s1);              # if (p>=e) %esp =- (p-e);
-       &jb     (&label("te_break_out"));
+       &jb     (&label("tbl_break_out"));
        &sub    ($s3,$s1);
-       &sub    ($key,$s3);
-       &jmp    (&label("te_ok"));
-       &set_label("te_break_out");     # else %esp -= (p-s)&0xfff + framesz;
+       &sub    ($acc,$s3);
+       &jmp    (&label("tbl_ok"));
+       &set_label("tbl_break_out",4);  # else %esp -= (p-s)&0xfff + framesz;
        &sub    ($s3,$s0);
        &and    ($s3,0xfff);
-       &add    ($s3,64+256);
-       &sub    ($key,$s3);
-       &align  (4);
-       &set_label("te_ok");
-
-       &mov    ($s0,&wparam(0));       # load inp
-       &mov    ($s1,&wparam(1));       # load out
-       &mov    ($s3,&wparam(3));       # load key
-       &mov    ($acc,&wparam(4));      # load ivp
+       &add    ($s3,384);
+       &sub    ($acc,$s3);
+       &set_label("tbl_ok",4);
 
-       &exch   ("esp",$key);
+       &lea    ($s3,&wparam(0));       # obtain pointer to parameter block
+       &exch   ("esp",$acc);           # allocate stack frame
        &add    ("esp",4);              # reserve for return address!
-       &mov    ($_esp,$key);           # save %esp
+       &mov    ($_tbl,$tbl);           # save %ebp
+       &mov    ($_esp,$acc);           # save %esp
+
+       &mov    ($s0,&DWP(0,$s3));      # load inp
+       &mov    ($s1,&DWP(4,$s3));      # load out
+       #&mov   ($s2,&DWP(8,$s3));      # load len
+       &mov    ($key,&DWP(12,$s3));    # load key
+       &mov    ($acc,&DWP(16,$s3));    # load ivp
+       &mov    ($s3,&DWP(20,$s3));     # load enc flag
 
        &mov    ($_inp,$s0);            # save copy of inp
        &mov    ($_out,$s1);            # save copy of out
        &mov    ($_len,$s2);            # save copy of len
-       &mov    ($_key,$s3);            # save copy of key
+       &mov    ($_key,$key);           # save copy of key
        &mov    ($_ivp,$acc);           # save copy of ivp
 
        &mov    ($mark,0);              # copy of aes_key->rounds = 0;
-       if ($compromise) {
-               &cmp    ($s2,$compromise);
-               &jb     (&label("skip_ecopy"));
-       }
        # do we copy key schedule to stack?
-       &mov    ($s1 eq "ebx" ? $s1 : "",$s3);
+       &mov    ($s1 eq "ebx" ? $s1 : "",$key);
        &mov    ($s2 eq "ecx" ? $s2 : "",244/4);
-       &sub    ($s1,"ebp");
-       &mov    ("esi",$s3);
+       &sub    ($s1,$tbl);
+       &mov    ("esi",$key);
        &and    ($s1,0xfff);
        &lea    ("edi",$aes_key);
-       &cmp    ($s1,2048);
-       &jb     (&label("do_ecopy"));
+       &cmp    ($s1,2048+256);
+       &jb     (&label("do_copy"));
        &cmp    ($s1,4096-244);
-       &jb     (&label("skip_ecopy"));
-       &align  (4);
-       &set_label("do_ecopy");
+       &jb     (&label("skip_copy"));
+       &set_label("do_copy",4);
                &mov    ($_key,"edi");
                &data_word(0xA5F3F689); # rep movsd
-       &set_label("skip_ecopy");
+       &set_label("skip_copy");
 
-       &mov    ($acc,$s0);
        &mov    ($key,16);
-       &align  (4);
-       &set_label("prefetch_te");
-               &mov    ($s0,&DWP(0,"ebp"));
-               &mov    ($s1,&DWP(32,"ebp"));
-               &mov    ($s2,&DWP(64,"ebp"));
-               &mov    ($s3,&DWP(96,"ebp"));
-               &lea    ("ebp",&DWP(128,"ebp"));
-               &dec    ($key);
-       &jnz    (&label("prefetch_te"));
-       &sub    ("ebp",2048);
-
-       &mov    ($s2,$_len);
+       &set_label("prefetch_tbl",4);
+               &mov    ($s0,&DWP(0,$tbl));
+               &mov    ($s1,&DWP(32,$tbl));
+               &mov    ($s2,&DWP(64,$tbl));
+               &mov    ($acc,&DWP(96,$tbl));
+               &lea    ($tbl,&DWP(128,$tbl));
+               &sub    ($key,1);
+       &jnz    (&label("prefetch_tbl"));
+       &sub    ($tbl,2048);
+
+       &mov    ($acc,$_inp);
        &mov    ($key,$_ivp);
-       &test   ($s2,0xFFFFFFF0);
-       &jz     (&label("enc_tail"));           # short input...
 
+       &cmp    ($s3,0);
+       &je     (&label("fast_decrypt"));
+
+#----------------------------- ENCRYPT -----------------------------#
        &mov    ($s0,&DWP(0,$key));             # load iv
        &mov    ($s1,&DWP(4,$key));
 
-       &align  (4);
-       &set_label("enc_loop");
+       &set_label("fast_enc_loop",16);
                &mov    ($s2,&DWP(8,$key));
                &mov    ($s3,&DWP(12,$key));
 
@@ -916,22 +2158,16 @@ my $mark=&DWP(60+240,"esp");     #copy of aes_key->rounds
                &mov    (&DWP(8,$key),$s2);
                &mov    (&DWP(12,$key),$s3);
 
+               &lea    ($acc,&DWP(16,$acc));   # advance inp
                &mov    ($s2,$_len);            # load len
-
-               &lea    ($acc,&DWP(16,$acc));
                &mov    ($_inp,$acc);           # save inp
-
-               &lea    ($s3,&DWP(16,$key));
+               &lea    ($s3,&DWP(16,$key));    # advance out
                &mov    ($_out,$s3);            # save out
-
-               &sub    ($s2,16);
-               &test   ($s2,0xFFFFFFF0);
+               &sub    ($s2,16);               # decrease len
                &mov    ($_len,$s2);            # save len
-       &jnz    (&label("enc_loop"));
-       &test   ($s2,15);
-       &jnz    (&label("enc_tail"));
+       &jnz    (&label("fast_enc_loop"));
        &mov    ($acc,$_ivp);           # load ivp
-       &mov    ($s2,&DWP(8,$key));     # restore last dwords
+       &mov    ($s2,&DWP(8,$key));     # restore last dwords
        &mov    ($s3,&DWP(12,$key));
        &mov    (&DWP(0,$acc),$s0);     # save ivec
        &mov    (&DWP(4,$acc),$s1);
@@ -949,125 +2185,20 @@ my $mark=&DWP(60+240,"esp");    #copy of aes_key->rounds
        &set_label("skip_ezero")
        &mov    ("esp",$_esp);
        &popf   ();
-    &set_label("enc_out");
+    &set_label("drop_out");
        &function_end_A();
        &pushf  ();                     # kludge, never executed
 
-    &align     (4);
-    &set_label("enc_tail");
-       &mov    ($s0,$key eq "edi" ? $key : "");
-       &mov    ($key,$_out);                   # load out
-       &push   ($s0);                          # push ivp
-       &mov    ($s1,16);
-       &sub    ($s1,$s2);
-       &cmp    ($key,$acc);                    # compare with inp
-       &je     (&label("enc_in_place"));
-       &align  (4);
-       &data_word(0xA4F3F689); # rep movsb     # copy input
-       &jmp    (&label("enc_skip_in_place"));
-    &set_label("enc_in_place");
-       &lea    ($key,&DWP(0,$key,$s2));
-    &set_label("enc_skip_in_place");
-       &mov    ($s2,$s1);
-       &xor    ($s0,$s0);
-       &align  (4);
-       &data_word(0xAAF3F689); # rep stosb     # zero tail
-       &pop    ($key);                         # pop ivp
-
-       &mov    ($acc,$_out);                   # output as input
-       &mov    ($s0,&DWP(0,$key));
-       &mov    ($s1,&DWP(4,$key));
-       &mov    ($_len,16);                     # len=16
-       &jmp    (&label("enc_loop"));           # one more spin...
-
 #----------------------------- DECRYPT -----------------------------#
-&align (4);
-&set_label("DECRYPT");
-       &lea    ("ebp",&DWP(&label("AES_Td")."-".&label("pic_point"),"ebp"));
-
-       # allocate aligned stack frame...
-       &lea    ($key,&DWP(-64-244,"esp"));
-       &and    ($key,-64);
-
-       # ... and make sure it doesn't alias with AES_Td modulo 4096
-       &mov    ($s0,"ebp");
-       &lea    ($s1,&DWP(2048+256,"ebp"));
-       &mov    ($s3,$key);
-       &and    ($s0,0xfff);            # s = %ebp&0xfff
-       &and    ($s1,0xfff);            # e = (%ebp+2048+256)&0xfff
-       &and    ($s3,0xfff);            # p = %esp&0xfff
-
-       &cmp    ($s3,$s1);              # if (p>=e) %esp =- (p-e);
-       &jb     (&label("td_break_out"));
-       &sub    ($s3,$s1);
-       &sub    ($key,$s3);
-       &jmp    (&label("td_ok"));
-       &set_label("td_break_out");     # else %esp -= (p-s)&0xfff + framesz;
-       &sub    ($s3,$s0);
-       &and    ($s3,0xfff);
-       &add    ($s3,64+256);
-       &sub    ($key,$s3);
-       &align  (4);
-       &set_label("td_ok");
-
-       &mov    ($s0,&wparam(0));       # load inp
-       &mov    ($s1,&wparam(1));       # load out
-       &mov    ($s3,&wparam(3));       # load key
-       &mov    ($acc,&wparam(4));      # load ivp
-
-       &exch   ("esp",$key);
-       &add    ("esp",4);              # reserve for return address!
-       &mov    ($_esp,$key);           # save %esp
-
-       &mov    ($_inp,$s0);            # save copy of inp
-       &mov    ($_out,$s1);            # save copy of out
-       &mov    ($_len,$s2);            # save copy of len
-       &mov    ($_key,$s3);            # save copy of key
-       &mov    ($_ivp,$acc);           # save copy of ivp
-
-       &mov    ($mark,0);              # copy of aes_key->rounds = 0;
-       if ($compromise) {
-               &cmp    ($s2,$compromise);
-               &jb     (&label("skip_dcopy"));
-       }
-       # do we copy key schedule to stack?
-       &mov    ($s1 eq "ebx" ? $s1 : "",$s3);
-       &mov    ($s2 eq "ecx" ? $s2 : "",244/4);
-       &sub    ($s1,"ebp");
-       &mov    ("esi",$s3);
-       &and    ($s1,0xfff);
-       &lea    ("edi",$aes_key);
-       &cmp    ($s1,2048+256);
-       &jb     (&label("do_dcopy"));
-       &cmp    ($s1,4096-244);
-       &jb     (&label("skip_dcopy"));
-       &align  (4);
-       &set_label("do_dcopy");
-               &mov    ($_key,"edi");
-               &data_word(0xA5F3F689); # rep movsd
-       &set_label("skip_dcopy");
-
-       &mov    ($acc,$s0);
-       &mov    ($key,18);
-       &align  (4);
-       &set_label("prefetch_td");
-               &mov    ($s0,&DWP(0,"ebp"));
-               &mov    ($s1,&DWP(32,"ebp"));
-               &mov    ($s2,&DWP(64,"ebp"));
-               &mov    ($s3,&DWP(96,"ebp"));
-               &lea    ("ebp",&DWP(128,"ebp"));
-               &dec    ($key);
-       &jnz    (&label("prefetch_td"));
-       &sub    ("ebp",2048+256);
+&set_label("fast_decrypt",16);
 
        &cmp    ($acc,$_out);
-       &je     (&label("dec_in_place"));       # in-place processing...
+       &je     (&label("fast_dec_in_place"));  # in-place processing...
 
-       &mov    ($key,$_ivp);           # load ivp
        &mov    ($_tmp,$key);
 
        &align  (4);
-       &set_label("dec_loop");
+       &set_label("fast_dec_loop",16);
                &mov    ($s0,&DWP(0,$acc));     # read input
                &mov    ($s1,&DWP(4,$acc));
                &mov    ($s2,&DWP(8,$acc));
@@ -1083,27 +2214,24 @@ my $mark=&DWP(60+240,"esp");    #copy of aes_key->rounds
                &xor    ($s2,&DWP(8,$key));
                &xor    ($s3,&DWP(12,$key));
 
-               &sub    ($acc,16);
-               &jc     (&label("dec_partial"));
-               &mov    ($_len,$acc);           # save len
-               &mov    ($acc,$_inp);           # load inp
                &mov    ($key,$_out);           # load out
+               &mov    ($acc,$_inp);           # load inp
 
                &mov    (&DWP(0,$key),$s0);     # write output
                &mov    (&DWP(4,$key),$s1);
                &mov    (&DWP(8,$key),$s2);
                &mov    (&DWP(12,$key),$s3);
 
+               &mov    ($s2,$_len);            # load len
                &mov    ($_tmp,$acc);           # save ivp
-               &lea    ($acc,&DWP(16,$acc));
+               &lea    ($acc,&DWP(16,$acc));   # advance inp
                &mov    ($_inp,$acc);           # save inp
-
-               &lea    ($key,&DWP(16,$key));
+               &lea    ($key,&DWP(16,$key));   # advance out
                &mov    ($_out,$key);           # save out
-
-       &jnz    (&label("dec_loop"));
+               &sub    ($s2,16);               # decrease len
+               &mov    ($_len,$s2);            # save len
+       &jnz    (&label("fast_dec_loop"));
        &mov    ($key,$_tmp);           # load temp ivp
-    &set_label("dec_end");
        &mov    ($acc,$_ivp);           # load user ivp
        &mov    ($s0,&DWP(0,$key));     # load iv
        &mov    ($s1,&DWP(4,$key));
@@ -1113,31 +2241,16 @@ my $mark=&DWP(60+240,"esp");    #copy of aes_key->rounds
        &mov    (&DWP(4,$acc),$s1);
        &mov    (&DWP(8,$acc),$s2);
        &mov    (&DWP(12,$acc),$s3);
-       &jmp    (&label("dec_out"));
+       &jmp    (&label("fast_dec_out"));
 
-    &align     (4);
-    &set_label("dec_partial");
-       &lea    ($key,$ivec);
-       &mov    (&DWP(0,$key),$s0);     # dump output to stack
-       &mov    (&DWP(4,$key),$s1);
-       &mov    (&DWP(8,$key),$s2);
-       &mov    (&DWP(12,$key),$s3);
-       &lea    ($s2 eq "ecx" ? $s2 : "",&DWP(16,$acc));
-       &mov    ($acc eq "esi" ? $acc : "",$key);
-       &mov    ($key eq "edi" ? $key : "",$_out);      # load out
-       &data_word(0xA4F3F689); # rep movsb             # copy output
-       &mov    ($key,$_inp);                           # use inp as temp ivp
-       &jmp    (&label("dec_end"));
-
-    &align     (4);
-    &set_label("dec_in_place");
-       &set_label("dec_in_place_loop");
-               &lea    ($key,$ivec);
+    &set_label("fast_dec_in_place",16);
+       &set_label("fast_dec_in_place_loop");
                &mov    ($s0,&DWP(0,$acc));     # read input
                &mov    ($s1,&DWP(4,$acc));
                &mov    ($s2,&DWP(8,$acc));
                &mov    ($s3,&DWP(12,$acc));
 
+               &lea    ($key,$ivec);
                &mov    (&DWP(0,$key),$s0);     # copy to temp
                &mov    (&DWP(4,$key),$s1);
                &mov    (&DWP(8,$key),$s2);
@@ -1158,7 +2271,7 @@ my $mark=&DWP(60+240,"esp");      #copy of aes_key->rounds
                &mov    (&DWP(8,$acc),$s2);
                &mov    (&DWP(12,$acc),$s3);
 
-               &lea    ($acc,&DWP(16,$acc));
+               &lea    ($acc,&DWP(16,$acc));   # advance out
                &mov    ($_out,$acc);           # save out
 
                &lea    ($acc,$ivec);
@@ -1173,40 +2286,340 @@ my $mark=&DWP(60+240,"esp");   #copy of aes_key->rounds
                &mov    (&DWP(12,$key),$s3);
 
                &mov    ($acc,$_inp);           # load inp
+               &mov    ($s2,$_len);            # load len
+               &lea    ($acc,&DWP(16,$acc));   # advance inp
+               &mov    ($_inp,$acc);           # save inp
+               &sub    ($s2,16);               # decrease len
+               &mov    ($_len,$s2);            # save len
+       &jnz    (&label("fast_dec_in_place_loop"));
+
+    &set_label("fast_dec_out",4);
+       &cmp    ($mark,0);              # was the key schedule copied?
+       &mov    ("edi",$_key);
+       &je     (&label("skip_dzero"));
+       # zero copy of key schedule
+       &mov    ("ecx",240/4);
+       &xor    ("eax","eax");
+       &align  (4);
+       &data_word(0xABF3F689); # rep stosd
+       &set_label("skip_dzero")
+       &mov    ("esp",$_esp);
+       &popf   ();
+       &function_end_A();
+       &pushf  ();                     # kludge, never executed
+
+#--------------------------- SLOW ROUTINE ---------------------------#
+&set_label("slow_way",16);
+
+       &mov    ($s0,&DWP(0,$s0)) if (!$x86only);# load OPENSSL_ia32cap
+       &mov    ($key,&wparam(3));      # load key
+
+       # pre-allocate aligned stack frame...
+       &lea    ($acc,&DWP(-80,"esp"));
+       &and    ($acc,-64);
+
+       # ... and make sure it doesn't alias with $key modulo 1024
+       &lea    ($s1,&DWP(-80-63,$key));
+       &sub    ($s1,$acc);
+       &neg    ($s1);
+       &and    ($s1,0x3C0);    # modulo 1024, but aligned to cache-line
+       &sub    ($acc,$s1);
+
+       # pick S-box copy which can't overlap with stack frame or $key
+       &lea    ($s1,&DWP(768,$acc));
+       &sub    ($s1,$tbl);
+       &and    ($s1,0x300);
+       &lea    ($tbl,&DWP(2048+128,$tbl,$s1));
+
+       &lea    ($s3,&wparam(0));       # pointer to parameter block
+
+       &exch   ("esp",$acc);
+       &add    ("esp",4);              # reserve for return address!
+       &mov    ($_tbl,$tbl);           # save %ebp
+       &mov    ($_esp,$acc);           # save %esp
+       &mov    ($_tmp,$s0);            # save OPENSSL_ia32cap
+
+       &mov    ($s0,&DWP(0,$s3));      # load inp
+       &mov    ($s1,&DWP(4,$s3));      # load out
+       #&mov   ($s2,&DWP(8,$s3));      # load len
+       #&mov   ($key,&DWP(12,$s3));    # load key
+       &mov    ($acc,&DWP(16,$s3));    # load ivp
+       &mov    ($s3,&DWP(20,$s3));     # load enc flag
+
+       &mov    ($_inp,$s0);            # save copy of inp
+       &mov    ($_out,$s1);            # save copy of out
+       &mov    ($_len,$s2);            # save copy of len
+       &mov    ($_key,$key);           # save copy of key
+       &mov    ($_ivp,$acc);           # save copy of ivp
+
+       &mov    ($key,$acc);
+       &mov    ($acc,$s0);
+
+       &cmp    ($s3,0);
+       &je     (&label("slow_decrypt"));
+
+#--------------------------- SLOW ENCRYPT ---------------------------#
+       &cmp    ($s2,16);
+       &mov    ($s3,$s1);
+       &jb     (&label("slow_enc_tail"));
+
+                                       if (!$x86only) {
+       &bt     ($_tmp,25);             # check for SSE bit
+       &jnc    (&label("slow_enc_x86"));
+
+       &movq   ("mm0",&QWP(0,$key));   # load iv
+       &movq   ("mm4",&QWP(8,$key));
+
+       &set_label("slow_enc_loop_sse",16);
+               &pxor   ("mm0",&QWP(0,$acc));   # xor input data
+               &pxor   ("mm4",&QWP(8,$acc));
+
+               &mov    ($key,$_key);
+               &call   ("_sse_AES_encrypt_compact");
+
+               &mov    ($acc,$_inp);           # load inp
+               &mov    ($key,$_out);           # load out
+               &mov    ($s2,$_len);            # load len
 
-               &lea    ($acc,&DWP(16,$acc));
+               &movq   (&QWP(0,$key),"mm0");   # save output data
+               &movq   (&QWP(8,$key),"mm4");
+
+               &lea    ($acc,&DWP(16,$acc));   # advance inp
                &mov    ($_inp,$acc);           # save inp
+               &lea    ($s3,&DWP(16,$key));    # advance out
+               &mov    ($_out,$s3);            # save out
+               &sub    ($s2,16);               # decrease len
+               &cmp    ($s2,16);
+               &mov    ($_len,$s2);            # save len
+       &jae    (&label("slow_enc_loop_sse"));
+       &test   ($s2,15);
+       &jnz    (&label("slow_enc_tail"));
+       &mov    ($acc,$_ivp);           # load ivp
+       &movq   (&QWP(0,$acc),"mm0");   # save ivec
+       &movq   (&QWP(8,$acc),"mm4");
+       &emms   ();
+       &mov    ("esp",$_esp);
+       &popf   ();
+       &function_end_A();
+       &pushf  ();                     # kludge, never executed
+                                       }
+    &set_label("slow_enc_x86",16);
+       &mov    ($s0,&DWP(0,$key));     # load iv
+       &mov    ($s1,&DWP(4,$key));
+
+       &set_label("slow_enc_loop_x86",4);
+               &mov    ($s2,&DWP(8,$key));
+               &mov    ($s3,&DWP(12,$key));
+
+               &xor    ($s0,&DWP(0,$acc));     # xor input data
+               &xor    ($s1,&DWP(4,$acc));
+               &xor    ($s2,&DWP(8,$acc));
+               &xor    ($s3,&DWP(12,$acc));
+
+               &mov    ($key,$_key);           # load key
+               &call   ("_x86_AES_encrypt_compact");
+
+               &mov    ($acc,$_inp);           # load inp
+               &mov    ($key,$_out);           # load out
+
+               &mov    (&DWP(0,$key),$s0);     # save output data
+               &mov    (&DWP(4,$key),$s1);
+               &mov    (&DWP(8,$key),$s2);
+               &mov    (&DWP(12,$key),$s3);
 
                &mov    ($s2,$_len);            # load len
-               &sub    ($s2,16);
-               &jc     (&label("dec_in_place_partial"));
+               &lea    ($acc,&DWP(16,$acc));   # advance inp
+               &mov    ($_inp,$acc);           # save inp
+               &lea    ($s3,&DWP(16,$key));    # advance out
+               &mov    ($_out,$s3);            # save out
+               &sub    ($s2,16);               # decrease len
+               &cmp    ($s2,16);
                &mov    ($_len,$s2);            # save len
-       &jnz    (&label("dec_in_place_loop"));
-       &jmp    (&label("dec_out"));
-
-    &align     (4);
-    &set_label("dec_in_place_partial");
-       # one can argue if this is actually required...
-       &mov    ($key eq "edi" ? $key : "",$_out);
-       &lea    ($acc eq "esi" ? $acc : "",$ivec);
+       &jae    (&label("slow_enc_loop_x86"));
+       &test   ($s2,15);
+       &jnz    (&label("slow_enc_tail"));
+       &mov    ($acc,$_ivp);           # load ivp
+       &mov    ($s2,&DWP(8,$key));     # restore last dwords
+       &mov    ($s3,&DWP(12,$key));
+       &mov    (&DWP(0,$acc),$s0);     # save ivec
+       &mov    (&DWP(4,$acc),$s1);
+       &mov    (&DWP(8,$acc),$s2);
+       &mov    (&DWP(12,$acc),$s3);
+
+       &mov    ("esp",$_esp);
+       &popf   ();
+       &function_end_A();
+       &pushf  ();                     # kludge, never executed
+
+    &set_label("slow_enc_tail",16);
+       &emms   ()      if (!$x86only);
+       &mov    ($key eq "edi"? $key:"",$s3);   # load out to edi
+       &mov    ($s1,16);
+       &sub    ($s1,$s2);
+       &cmp    ($key,$acc eq "esi"? $acc:"");  # compare with inp
+       &je     (&label("enc_in_place"));
+       &align  (4);
+       &data_word(0xA4F3F689); # rep movsb     # copy input
+       &jmp    (&label("enc_skip_in_place"));
+    &set_label("enc_in_place");
        &lea    ($key,&DWP(0,$key,$s2));
-       &lea    ($acc,&DWP(16,$acc,$s2));
-       &neg    ($s2 eq "ecx" ? $s2 : "");
-       &data_word(0xA4F3F689); # rep movsb     # restore tail
-
-    &align     (4);
-    &set_label("dec_out");
-    &cmp       ($mark,0);              # was the key schedule copied?
-    &mov       ("edi",$_key);
-    &je                (&label("skip_dzero"));
-    # zero copy of key schedule
-    &mov       ("ecx",240/4);
-    &xor       ("eax","eax");
-    &align     (4);
-    &data_word(0xABF3F689);    # rep stosd
-    &set_label("skip_dzero")
-    &mov       ("esp",$_esp);
-    &popf      ();
+    &set_label("enc_skip_in_place");
+       &mov    ($s2,$s1);
+       &xor    ($s0,$s0);
+       &align  (4);
+       &data_word(0xAAF3F689); # rep stosb     # zero tail
+
+       &mov    ($key,$_ivp);                   # restore ivp
+       &mov    ($acc,$s3);                     # output as input
+       &mov    ($s0,&DWP(0,$key));
+       &mov    ($s1,&DWP(4,$key));
+       &mov    ($_len,16);                     # len=16
+       &jmp    (&label("slow_enc_loop_x86"));  # one more spin...
+
+#--------------------------- SLOW DECRYPT ---------------------------#
+&set_label("slow_decrypt",16);
+                                       if (!$x86only) {
+       &bt     ($_tmp,25);             # check for SSE bit
+       &jnc    (&label("slow_dec_loop_x86"));
+
+       &set_label("slow_dec_loop_sse",4);
+               &movq   ("mm0",&QWP(0,$acc));   # read input
+               &movq   ("mm4",&QWP(8,$acc));
+
+               &mov    ($key,$_key);
+               &call   ("_sse_AES_decrypt_compact");
+
+               &mov    ($acc,$_inp);           # load inp
+               &lea    ($s0,$ivec);
+               &mov    ($s1,$_out);            # load out
+               &mov    ($s2,$_len);            # load len
+               &mov    ($key,$_ivp);           # load ivp
+
+               &movq   ("mm1",&QWP(0,$acc));   # re-read input
+               &movq   ("mm5",&QWP(8,$acc));
+
+               &pxor   ("mm0",&QWP(0,$key));   # xor iv
+               &pxor   ("mm4",&QWP(8,$key));
+
+               &movq   (&QWP(0,$key),"mm1");   # copy input to iv
+               &movq   (&QWP(8,$key),"mm5");
+
+               &sub    ($s2,16);               # decrease len
+               &jc     (&label("slow_dec_partial_sse"));
+
+               &movq   (&QWP(0,$s1),"mm0");    # write output
+               &movq   (&QWP(8,$s1),"mm4");
+
+               &lea    ($s1,&DWP(16,$s1));     # advance out
+               &mov    ($_out,$s1);            # save out
+               &lea    ($acc,&DWP(16,$acc));   # advance inp
+               &mov    ($_inp,$acc);           # save inp
+               &mov    ($_len,$s2);            # save len
+       &jnz    (&label("slow_dec_loop_sse"));
+       &emms   ();
+       &mov    ("esp",$_esp);
+       &popf   ();
+       &function_end_A();
+       &pushf  ();                     # kludge, never executed
+
+    &set_label("slow_dec_partial_sse",16);
+       &movq   (&QWP(0,$s0),"mm0");    # save output to temp
+       &movq   (&QWP(8,$s0),"mm4");
+       &emms   ();
+
+       &add    ($s2 eq "ecx" ? "ecx":"",16);
+       &mov    ("edi",$s1);            # out
+       &mov    ("esi",$s0);            # temp
+       &align  (4);
+       &data_word(0xA4F3F689);         # rep movsb # copy partial output
+
+       &mov    ("esp",$_esp);
+       &popf   ();
+       &function_end_A();
+       &pushf  ();                     # kludge, never executed
+                                       }
+       &set_label("slow_dec_loop_x86",16);
+               &mov    ($s0,&DWP(0,$acc));     # read input
+               &mov    ($s1,&DWP(4,$acc));
+               &mov    ($s2,&DWP(8,$acc));
+               &mov    ($s3,&DWP(12,$acc));
+
+               &lea    ($key,$ivec);
+               &mov    (&DWP(0,$key),$s0);     # copy to temp
+               &mov    (&DWP(4,$key),$s1);
+               &mov    (&DWP(8,$key),$s2);
+               &mov    (&DWP(12,$key),$s3);
+
+               &mov    ($key,$_key);           # load key
+               &call   ("_x86_AES_decrypt_compact");
+
+               &mov    ($key,$_ivp);           # load ivp
+               &mov    ($acc,$_len);           # load len
+               &xor    ($s0,&DWP(0,$key));     # xor iv
+               &xor    ($s1,&DWP(4,$key));
+               &xor    ($s2,&DWP(8,$key));
+               &xor    ($s3,&DWP(12,$key));
+
+               &sub    ($acc,16);
+               &jc     (&label("slow_dec_partial_x86"));
+
+               &mov    ($_len,$acc);           # save len
+               &mov    ($acc,$_out);           # load out
+
+               &mov    (&DWP(0,$acc),$s0);     # write output
+               &mov    (&DWP(4,$acc),$s1);
+               &mov    (&DWP(8,$acc),$s2);
+               &mov    (&DWP(12,$acc),$s3);
+
+               &lea    ($acc,&DWP(16,$acc));   # advance out
+               &mov    ($_out,$acc);           # save out
+
+               &lea    ($acc,$ivec);
+               &mov    ($s0,&DWP(0,$acc));     # read temp
+               &mov    ($s1,&DWP(4,$acc));
+               &mov    ($s2,&DWP(8,$acc));
+               &mov    ($s3,&DWP(12,$acc));
+
+               &mov    (&DWP(0,$key),$s0);     # copy it to iv
+               &mov    (&DWP(4,$key),$s1);
+               &mov    (&DWP(8,$key),$s2);
+               &mov    (&DWP(12,$key),$s3);
+
+               &mov    ($acc,$_inp);           # load inp
+               &lea    ($acc,&DWP(16,$acc));   # advance inp
+               &mov    ($_inp,$acc);           # save inp
+       &jnz    (&label("slow_dec_loop_x86"));
+       &mov    ("esp",$_esp);
+       &popf   ();
+       &function_end_A();
+       &pushf  ();                     # kludge, never executed
+
+    &set_label("slow_dec_partial_x86",16);
+       &lea    ($acc,$ivec);
+       &mov    (&DWP(0,$acc),$s0);     # save output to temp
+       &mov    (&DWP(4,$acc),$s1);
+       &mov    (&DWP(8,$acc),$s2);
+       &mov    (&DWP(12,$acc),$s3);
+
+       &mov    ($acc,$_inp);
+       &mov    ($s0,&DWP(0,$acc));     # re-read input
+       &mov    ($s1,&DWP(4,$acc));
+       &mov    ($s2,&DWP(8,$acc));
+       &mov    ($s3,&DWP(12,$acc));
+
+       &mov    (&DWP(0,$key),$s0);     # copy it to iv
+       &mov    (&DWP(4,$key),$s1);
+       &mov    (&DWP(8,$key),$s2);
+       &mov    (&DWP(12,$key),$s3);
+
+       &mov    ("ecx",$_len);
+       &mov    ("edi",$_out);
+       &lea    ("esi",$ivec);
+       &align  (4);
+       &data_word(0xA4F3F689);         # rep movsb # copy partial output
+
+       &mov    ("esp",$_esp);
+       &popf   ();
 &function_end("AES_cbc_encrypt");
 }
 
@@ -1215,35 +2628,31 @@ my $mark=&DWP(60+240,"esp");    #copy of aes_key->rounds
 sub enckey()
 {
        &movz   ("esi",&LB("edx"));             # rk[i]>>0
-       &mov    ("ebx",&DWP(2,"ebp","esi",8));
+       &movz   ("ebx",&BP(-128,$tbl,"esi",1));
        &movz   ("esi",&HB("edx"));             # rk[i]>>8
-       &and    ("ebx",0xFF000000);
+       &shl    ("ebx",24);
        &xor    ("eax","ebx");
 
-       &mov    ("ebx",&DWP(2,"ebp","esi",8));
+       &movz   ("ebx",&BP(-128,$tbl,"esi",1));
        &shr    ("edx",16);
-       &and    ("ebx",0x000000FF);
        &movz   ("esi",&LB("edx"));             # rk[i]>>16
        &xor    ("eax","ebx");
 
-       &mov    ("ebx",&DWP(0,"ebp","esi",8));
+       &movz   ("ebx",&BP(-128,$tbl,"esi",1));
        &movz   ("esi",&HB("edx"));             # rk[i]>>24
-       &and    ("ebx",0x0000FF00);
+       &shl    ("ebx",8);
        &xor    ("eax","ebx");
 
-       &mov    ("ebx",&DWP(0,"ebp","esi",8));
-       &and    ("ebx",0x00FF0000);
+       &movz   ("ebx",&BP(-128,$tbl,"esi",1));
+       &shl    ("ebx",16);
        &xor    ("eax","ebx");
 
-       &xor    ("eax",&DWP(2048,"ebp","ecx",4));       # rcon
+       &xor    ("eax",&DWP(1024-128,$tbl,"ecx",4));    # rcon
 }
 
-# int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
-#                        AES_KEY *key)
-&public_label("AES_Te");
-&function_begin("AES_set_encrypt_key");
-       &mov    ("esi",&wparam(0));             # user supplied key
-       &mov    ("edi",&wparam(2));             # private key schedule
+&function_begin("_x86_AES_set_encrypt_key");
+       &mov    ("esi",&wparam(1));             # user supplied key
+       &mov    ("edi",&wparam(3));             # private key schedule
 
        &test   ("esi",-1);
        &jz     (&label("badpointer"));
@@ -1252,10 +2661,21 @@ sub enckey()
 
        &call   (&label("pic_point"));
        &set_label("pic_point");
-       &blindpop("ebp");
-       &lea    ("ebp",&DWP(&label("AES_Te")."-".&label("pic_point"),"ebp"));
-
-       &mov    ("ecx",&wparam(1));             # number of bits in key
+       &blindpop($tbl);
+       &lea    ($tbl,&DWP(&label("AES_Te")."-".&label("pic_point"),$tbl));
+       &lea    ($tbl,&DWP(2048+128,$tbl));
+
+       # prefetch Te4
+       &mov    ("eax",&DWP(0-128,$tbl));
+       &mov    ("ebx",&DWP(32-128,$tbl));
+       &mov    ("ecx",&DWP(64-128,$tbl));
+       &mov    ("edx",&DWP(96-128,$tbl));
+       &mov    ("eax",&DWP(128-128,$tbl));
+       &mov    ("ebx",&DWP(160-128,$tbl));
+       &mov    ("ecx",&DWP(192-128,$tbl));
+       &mov    ("edx",&DWP(224-128,$tbl));
+
+       &mov    ("ecx",&wparam(2));             # number of bits in key
        &cmp    ("ecx",128);
        &je     (&label("10rounds"));
        &cmp    ("ecx",192);
@@ -1394,24 +2814,23 @@ sub enckey()
                &mov    ("edx","eax");
                &mov    ("eax",&DWP(16,"edi"));         # rk[4]
                &movz   ("esi",&LB("edx"));             # rk[11]>>0
-               &mov    ("ebx",&DWP(2,"ebp","esi",8));
+               &movz   ("ebx",&BP(-128,$tbl,"esi",1));
                &movz   ("esi",&HB("edx"));             # rk[11]>>8
-               &and    ("ebx",0x000000FF);
                &xor    ("eax","ebx");
 
-               &mov    ("ebx",&DWP(0,"ebp","esi",8));
+               &movz   ("ebx",&BP(-128,$tbl,"esi",1));
                &shr    ("edx",16);
-               &and    ("ebx",0x0000FF00);
+               &shl    ("ebx",8);
                &movz   ("esi",&LB("edx"));             # rk[11]>>16
                &xor    ("eax","ebx");
 
-               &mov    ("ebx",&DWP(0,"ebp","esi",8));
+               &movz   ("ebx",&BP(-128,$tbl,"esi",1));
                &movz   ("esi",&HB("edx"));             # rk[11]>>24
-               &and    ("ebx",0x00FF0000);
+               &shl    ("ebx",16);
                &xor    ("eax","ebx");
 
-               &mov    ("ebx",&DWP(2,"ebp","esi",8));
-               &and    ("ebx",0xFF000000);
+               &movz   ("ebx",&BP(-128,$tbl,"esi",1));
+               &shl    ("ebx",24);
                &xor    ("eax","ebx");
 
                &mov    (&DWP(48,"edi"),"eax");         # rk[12]
@@ -1433,43 +2852,74 @@ sub enckey()
     &set_label("badpointer");
        &mov    ("eax",-1);
     &set_label("exit");
-&function_end("AES_set_encrypt_key");
+&function_end("_x86_AES_set_encrypt_key");
 
-sub deckey()
-{ my ($i,$ptr,$te,$td) = @_;
+# int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
+#                        AES_KEY *key)
+&function_begin_B("AES_set_encrypt_key");
+       &call   ("_x86_AES_set_encrypt_key");
+       &ret    ();
+&function_end_B("AES_set_encrypt_key");
 
-       &mov    ("eax",&DWP($i,$ptr));
-       &mov    ("edx","eax");
-       &movz   ("ebx",&HB("eax"));
-       &shr    ("edx",16);
-       &and    ("eax",0xFF);
-       &movz   ("eax",&BP(2,$te,"eax",8));
-       &movz   ("ebx",&BP(2,$te,"ebx",8));
-       &mov    ("eax",&DWP(0,$td,"eax",8));
-       &xor    ("eax",&DWP(3,$td,"ebx",8));
-       &movz   ("ebx",&HB("edx"));
-       &and    ("edx",0xFF);
-       &movz   ("edx",&BP(2,$te,"edx",8));
-       &movz   ("ebx",&BP(2,$te,"ebx",8));
-       &xor    ("eax",&DWP(2,$td,"edx",8));
-       &xor    ("eax",&DWP(1,$td,"ebx",8));
-       &mov    (&DWP($i,$ptr),"eax");
+sub deckey()
+{ my ($i,$key,$tp1,$tp2,$tp4,$tp8) = @_;
+  my $tmp = $tbl;
+
+       &mov    ($acc,$tp1);
+       &and    ($acc,0x80808080);
+       &mov    ($tmp,$acc);
+       &shr    ($tmp,7);
+       &lea    ($tp2,&DWP(0,$tp1,$tp1));
+       &sub    ($acc,$tmp);
+       &and    ($tp2,0xfefefefe);
+       &and    ($acc,0x1b1b1b1b);
+       &xor    ($acc,$tp2);
+       &mov    ($tp2,$acc);
+
+       &and    ($acc,0x80808080);
+       &mov    ($tmp,$acc);
+       &shr    ($tmp,7);
+       &lea    ($tp4,&DWP(0,$tp2,$tp2));
+       &sub    ($acc,$tmp);
+       &and    ($tp4,0xfefefefe);
+       &and    ($acc,0x1b1b1b1b);
+        &xor   ($tp2,$tp1);    # tp2^tp1
+       &xor    ($acc,$tp4);
+       &mov    ($tp4,$acc);
+
+       &and    ($acc,0x80808080);
+       &mov    ($tmp,$acc);
+       &shr    ($tmp,7);
+       &lea    ($tp8,&DWP(0,$tp4,$tp4));
+        &xor   ($tp4,$tp1);    # tp4^tp1
+       &sub    ($acc,$tmp);
+       &and    ($tp8,0xfefefefe);
+       &and    ($acc,0x1b1b1b1b);
+        &rotl  ($tp1,8);       # = ROTATE(tp1,8)
+       &xor    ($tp8,$acc);
+
+       &mov    ($tmp,&DWP(4*($i+1),$key));     # modulo-scheduled load
+
+       &xor    ($tp1,$tp2);
+       &xor    ($tp2,$tp8);
+       &xor    ($tp1,$tp4);
+       &rotl   ($tp2,24);
+       &xor    ($tp4,$tp8);
+       &xor    ($tp1,$tp8);    # ^= tp8^(tp4^tp1)^(tp2^tp1)
+       &rotl   ($tp4,16);
+       &xor    ($tp1,$tp2);    # ^= ROTATE(tp8^tp2^tp1,24)
+       &rotl   ($tp8,8);
+       &xor    ($tp1,$tp4);    # ^= ROTATE(tp8^tp4^tp1,16)
+       &mov    ($tp2,$tmp);
+       &xor    ($tp1,$tp8);    # ^= ROTATE(tp8,8)
+
+       &mov    (&DWP(4*$i,$key),$tp1);
 }
 
 # int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
 #                        AES_KEY *key)
-&public_label("AES_Td");
-&public_label("AES_Te");
 &function_begin_B("AES_set_decrypt_key");
-       &mov    ("eax",&wparam(0));
-       &mov    ("ecx",&wparam(1));
-       &mov    ("edx",&wparam(2));
-       &sub    ("esp",12);
-       &mov    (&DWP(0,"esp"),"eax");
-       &mov    (&DWP(4,"esp"),"ecx");
-       &mov    (&DWP(8,"esp"),"edx");
-       &call   ("AES_set_encrypt_key");
-       &add    ("esp",12);
+       &call   ("_x86_AES_set_encrypt_key");
        &cmp    ("eax",0);
        &je     (&label("proceed"));
        &ret    ();
@@ -1485,8 +2935,7 @@ sub deckey()
        &lea    ("ecx",&DWP(0,"","ecx",4));
        &lea    ("edi",&DWP(0,"esi","ecx",4));  # pointer to last chunk
 
-       &align  (4);
-       &set_label("invert");                   # invert order of chunks
+       &set_label("invert",4);                 # invert order of chunks
                &mov    ("eax",&DWP(0,"esi"));
                &mov    ("ebx",&DWP(4,"esi"));
                &mov    ("ecx",&DWP(0,"edi"));
@@ -1508,26 +2957,24 @@ sub deckey()
                &cmp    ("esi","edi");
        &jne    (&label("invert"));
 
-       &call   (&label("pic_point"));
-       &set_label("pic_point");
-       blindpop("ebp");
-       &lea    ("edi",&DWP(&label("AES_Td")."-".&label("pic_point"),"ebp"));
-       &lea    ("ebp",&DWP(&label("AES_Te")."-".&label("pic_point"),"ebp"));
-
-       &mov    ("esi",&wparam(2));
-       &mov    ("ecx",&DWP(240,"esi"));        # pull number of rounds
-       &dec    ("ecx");
-       &align  (4);
-       &set_label("permute");                  # permute the key schedule
-               &add    ("esi",16);
-               &deckey (0,"esi","ebp","edi");
-               &deckey (4,"esi","ebp","edi");
-               &deckey (8,"esi","ebp","edi");
-               &deckey (12,"esi","ebp","edi");
-               &dec    ("ecx");
-       &jnz    (&label("permute"));
+       &mov    ($key,&wparam(2));
+       &mov    ($acc,&DWP(240,$key));          # pull number of rounds
+       &lea    ($acc,&DWP(-2,$acc,$acc));
+       &lea    ($acc,&DWP(0,$key,$acc,8));
+       &mov    (&wparam(2),$acc);
+
+       &mov    ($s0,&DWP(16,$key));            # modulo-scheduled load
+       &set_label("permute",4);                # permute the key schedule
+               &add    ($key,16);
+               &deckey (0,$key,$s0,$s1,$s2,$s3);
+               &deckey (1,$key,$s1,$s2,$s3,$s0);
+               &deckey (2,$key,$s2,$s3,$s0,$s1);
+               &deckey (3,$key,$s3,$s0,$s1,$s2);
+               &cmp    ($key,&wparam(2));
+       &jb     (&label("permute"));
 
        &xor    ("eax","eax");                  # return success
 &function_end("AES_set_decrypt_key");
+&asciz("AES for x86, CRYPTOGAMS by <appro\@openssl.org>");
 
 &asm_finish();
diff --git a/deps/openssl/openssl/crypto/aes/asm/aes-armv4.pl b/deps/openssl/openssl/crypto/aes/asm/aes-armv4.pl
new file mode 100644 (file)
index 0000000..c51ee1f
--- /dev/null
@@ -0,0 +1,1030 @@
+#!/usr/bin/env perl
+
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+
+# AES for ARMv4
+
+# January 2007.
+#
+# Code uses single 1K S-box and is >2 times faster than code generated
+# by gcc-3.4.1. This is thanks to unique feature of ARMv4 ISA, which
+# allows to merge logical or arithmetic operation with shift or rotate
+# in one instruction and emit combined result every cycle. The module
+# is endian-neutral. The performance is ~42 cycles/byte for 128-bit
+# key [on single-issue Xscale PXA250 core].
+
+# May 2007.
+#
+# AES_set_[en|de]crypt_key is added.
+
+# July 2010.
+#
+# Rescheduling for dual-issue pipeline resulted in 12% improvement on
+# Cortex A8 core and ~25 cycles per byte processed with 128-bit key.
+
+while (($output=shift) && ($output!~/^\w[\w\-]*\.\w+$/)) {}
+open STDOUT,">$output";
+
+$s0="r0";
+$s1="r1";
+$s2="r2";
+$s3="r3";
+$t1="r4";
+$t2="r5";
+$t3="r6";
+$i1="r7";
+$i2="r8";
+$i3="r9";
+
+$tbl="r10";
+$key="r11";
+$rounds="r12";
+
+$code=<<___;
+.text
+.code  32
+
+.type  AES_Te,%object
+.align 5
+AES_Te:
+.word  0xc66363a5, 0xf87c7c84, 0xee777799, 0xf67b7b8d
+.word  0xfff2f20d, 0xd66b6bbd, 0xde6f6fb1, 0x91c5c554
+.word  0x60303050, 0x02010103, 0xce6767a9, 0x562b2b7d
+.word  0xe7fefe19, 0xb5d7d762, 0x4dababe6, 0xec76769a
+.word  0x8fcaca45, 0x1f82829d, 0x89c9c940, 0xfa7d7d87
+.word  0xeffafa15, 0xb25959eb, 0x8e4747c9, 0xfbf0f00b
+.word  0x41adadec, 0xb3d4d467, 0x5fa2a2fd, 0x45afafea
+.word  0x239c9cbf, 0x53a4a4f7, 0xe4727296, 0x9bc0c05b
+.word  0x75b7b7c2, 0xe1fdfd1c, 0x3d9393ae, 0x4c26266a
+.word  0x6c36365a, 0x7e3f3f41, 0xf5f7f702, 0x83cccc4f
+.word  0x6834345c, 0x51a5a5f4, 0xd1e5e534, 0xf9f1f108
+.word  0xe2717193, 0xabd8d873, 0x62313153, 0x2a15153f
+.word  0x0804040c, 0x95c7c752, 0x46232365, 0x9dc3c35e
+.word  0x30181828, 0x379696a1, 0x0a05050f, 0x2f9a9ab5
+.word  0x0e070709, 0x24121236, 0x1b80809b, 0xdfe2e23d
+.word  0xcdebeb26, 0x4e272769, 0x7fb2b2cd, 0xea75759f
+.word  0x1209091b, 0x1d83839e, 0x582c2c74, 0x341a1a2e
+.word  0x361b1b2d, 0xdc6e6eb2, 0xb45a5aee, 0x5ba0a0fb
+.word  0xa45252f6, 0x763b3b4d, 0xb7d6d661, 0x7db3b3ce
+.word  0x5229297b, 0xdde3e33e, 0x5e2f2f71, 0x13848497
+.word  0xa65353f5, 0xb9d1d168, 0x00000000, 0xc1eded2c
+.word  0x40202060, 0xe3fcfc1f, 0x79b1b1c8, 0xb65b5bed
+.word  0xd46a6abe, 0x8dcbcb46, 0x67bebed9, 0x7239394b
+.word  0x944a4ade, 0x984c4cd4, 0xb05858e8, 0x85cfcf4a
+.word  0xbbd0d06b, 0xc5efef2a, 0x4faaaae5, 0xedfbfb16
+.word  0x864343c5, 0x9a4d4dd7, 0x66333355, 0x11858594
+.word  0x8a4545cf, 0xe9f9f910, 0x04020206, 0xfe7f7f81
+.word  0xa05050f0, 0x783c3c44, 0x259f9fba, 0x4ba8a8e3
+.word  0xa25151f3, 0x5da3a3fe, 0x804040c0, 0x058f8f8a
+.word  0x3f9292ad, 0x219d9dbc, 0x70383848, 0xf1f5f504
+.word  0x63bcbcdf, 0x77b6b6c1, 0xafdada75, 0x42212163
+.word  0x20101030, 0xe5ffff1a, 0xfdf3f30e, 0xbfd2d26d
+.word  0x81cdcd4c, 0x180c0c14, 0x26131335, 0xc3ecec2f
+.word  0xbe5f5fe1, 0x359797a2, 0x884444cc, 0x2e171739
+.word  0x93c4c457, 0x55a7a7f2, 0xfc7e7e82, 0x7a3d3d47
+.word  0xc86464ac, 0xba5d5de7, 0x3219192b, 0xe6737395
+.word  0xc06060a0, 0x19818198, 0x9e4f4fd1, 0xa3dcdc7f
+.word  0x44222266, 0x542a2a7e, 0x3b9090ab, 0x0b888883
+.word  0x8c4646ca, 0xc7eeee29, 0x6bb8b8d3, 0x2814143c
+.word  0xa7dede79, 0xbc5e5ee2, 0x160b0b1d, 0xaddbdb76
+.word  0xdbe0e03b, 0x64323256, 0x743a3a4e, 0x140a0a1e
+.word  0x924949db, 0x0c06060a, 0x4824246c, 0xb85c5ce4
+.word  0x9fc2c25d, 0xbdd3d36e, 0x43acacef, 0xc46262a6
+.word  0x399191a8, 0x319595a4, 0xd3e4e437, 0xf279798b
+.word  0xd5e7e732, 0x8bc8c843, 0x6e373759, 0xda6d6db7
+.word  0x018d8d8c, 0xb1d5d564, 0x9c4e4ed2, 0x49a9a9e0
+.word  0xd86c6cb4, 0xac5656fa, 0xf3f4f407, 0xcfeaea25
+.word  0xca6565af, 0xf47a7a8e, 0x47aeaee9, 0x10080818
+.word  0x6fbabad5, 0xf0787888, 0x4a25256f, 0x5c2e2e72
+.word  0x381c1c24, 0x57a6a6f1, 0x73b4b4c7, 0x97c6c651
+.word  0xcbe8e823, 0xa1dddd7c, 0xe874749c, 0x3e1f1f21
+.word  0x964b4bdd, 0x61bdbddc, 0x0d8b8b86, 0x0f8a8a85
+.word  0xe0707090, 0x7c3e3e42, 0x71b5b5c4, 0xcc6666aa
+.word  0x904848d8, 0x06030305, 0xf7f6f601, 0x1c0e0e12
+.word  0xc26161a3, 0x6a35355f, 0xae5757f9, 0x69b9b9d0
+.word  0x17868691, 0x99c1c158, 0x3a1d1d27, 0x279e9eb9
+.word  0xd9e1e138, 0xebf8f813, 0x2b9898b3, 0x22111133
+.word  0xd26969bb, 0xa9d9d970, 0x078e8e89, 0x339494a7
+.word  0x2d9b9bb6, 0x3c1e1e22, 0x15878792, 0xc9e9e920
+.word  0x87cece49, 0xaa5555ff, 0x50282878, 0xa5dfdf7a
+.word  0x038c8c8f, 0x59a1a1f8, 0x09898980, 0x1a0d0d17
+.word  0x65bfbfda, 0xd7e6e631, 0x844242c6, 0xd06868b8
+.word  0x824141c3, 0x299999b0, 0x5a2d2d77, 0x1e0f0f11
+.word  0x7bb0b0cb, 0xa85454fc, 0x6dbbbbd6, 0x2c16163a
+@ Te4[256]
+.byte  0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5
+.byte  0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76
+.byte  0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0
+.byte  0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0
+.byte  0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc
+.byte  0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15
+.byte  0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a
+.byte  0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75
+.byte  0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0
+.byte  0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84
+.byte  0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b
+.byte  0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf
+.byte  0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85
+.byte  0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8
+.byte  0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5
+.byte  0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2
+.byte  0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17
+.byte  0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73
+.byte  0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88
+.byte  0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb
+.byte  0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c
+.byte  0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79
+.byte  0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9
+.byte  0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08
+.byte  0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6
+.byte  0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a
+.byte  0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e
+.byte  0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e
+.byte  0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94
+.byte  0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf
+.byte  0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68
+.byte  0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
+@ rcon[]
+.word  0x01000000, 0x02000000, 0x04000000, 0x08000000
+.word  0x10000000, 0x20000000, 0x40000000, 0x80000000
+.word  0x1B000000, 0x36000000, 0, 0, 0, 0, 0, 0
+.size  AES_Te,.-AES_Te
+
+@ void AES_encrypt(const unsigned char *in, unsigned char *out,
+@               const AES_KEY *key) {
+.global AES_encrypt
+.type   AES_encrypt,%function
+.align 5
+AES_encrypt:
+       sub     r3,pc,#8                @ AES_encrypt
+       stmdb   sp!,{r1,r4-r12,lr}
+       mov     $rounds,r0              @ inp
+       mov     $key,r2
+       sub     $tbl,r3,#AES_encrypt-AES_Te     @ Te
+
+       ldrb    $s0,[$rounds,#3]        @ load input data in endian-neutral
+       ldrb    $t1,[$rounds,#2]        @ manner...
+       ldrb    $t2,[$rounds,#1]
+       ldrb    $t3,[$rounds,#0]
+       orr     $s0,$s0,$t1,lsl#8
+       ldrb    $s1,[$rounds,#7]
+       orr     $s0,$s0,$t2,lsl#16
+       ldrb    $t1,[$rounds,#6]
+       orr     $s0,$s0,$t3,lsl#24
+       ldrb    $t2,[$rounds,#5]
+       ldrb    $t3,[$rounds,#4]
+       orr     $s1,$s1,$t1,lsl#8
+       ldrb    $s2,[$rounds,#11]
+       orr     $s1,$s1,$t2,lsl#16
+       ldrb    $t1,[$rounds,#10]
+       orr     $s1,$s1,$t3,lsl#24
+       ldrb    $t2,[$rounds,#9]
+       ldrb    $t3,[$rounds,#8]
+       orr     $s2,$s2,$t1,lsl#8
+       ldrb    $s3,[$rounds,#15]
+       orr     $s2,$s2,$t2,lsl#16
+       ldrb    $t1,[$rounds,#14]
+       orr     $s2,$s2,$t3,lsl#24
+       ldrb    $t2,[$rounds,#13]
+       ldrb    $t3,[$rounds,#12]
+       orr     $s3,$s3,$t1,lsl#8
+       orr     $s3,$s3,$t2,lsl#16
+       orr     $s3,$s3,$t3,lsl#24
+
+       bl      _armv4_AES_encrypt
+
+       ldr     $rounds,[sp],#4         @ pop out
+       mov     $t1,$s0,lsr#24          @ write output in endian-neutral
+       mov     $t2,$s0,lsr#16          @ manner...
+       mov     $t3,$s0,lsr#8
+       strb    $t1,[$rounds,#0]
+       strb    $t2,[$rounds,#1]
+       mov     $t1,$s1,lsr#24
+       strb    $t3,[$rounds,#2]
+       mov     $t2,$s1,lsr#16
+       strb    $s0,[$rounds,#3]
+       mov     $t3,$s1,lsr#8
+       strb    $t1,[$rounds,#4]
+       strb    $t2,[$rounds,#5]
+       mov     $t1,$s2,lsr#24
+       strb    $t3,[$rounds,#6]
+       mov     $t2,$s2,lsr#16
+       strb    $s1,[$rounds,#7]
+       mov     $t3,$s2,lsr#8
+       strb    $t1,[$rounds,#8]
+       strb    $t2,[$rounds,#9]
+       mov     $t1,$s3,lsr#24
+       strb    $t3,[$rounds,#10]
+       mov     $t2,$s3,lsr#16
+       strb    $s2,[$rounds,#11]
+       mov     $t3,$s3,lsr#8
+       strb    $t1,[$rounds,#12]
+       strb    $t2,[$rounds,#13]
+       strb    $t3,[$rounds,#14]
+       strb    $s3,[$rounds,#15]
+
+       ldmia   sp!,{r4-r12,lr}
+       tst     lr,#1
+       moveq   pc,lr                   @ be binary compatible with V4, yet
+       bx      lr                      @ interoperable with Thumb ISA:-)
+.size  AES_encrypt,.-AES_encrypt
+
+.type   _armv4_AES_encrypt,%function
+.align 2
+_armv4_AES_encrypt:
+       str     lr,[sp,#-4]!            @ push lr
+       ldmia   $key!,{$t1-$i1}
+       eor     $s0,$s0,$t1
+       ldr     $rounds,[$key,#240-16]
+       eor     $s1,$s1,$t2
+       eor     $s2,$s2,$t3
+       eor     $s3,$s3,$i1
+       sub     $rounds,$rounds,#1
+       mov     lr,#255
+
+       and     $i1,lr,$s0
+       and     $i2,lr,$s0,lsr#8
+       and     $i3,lr,$s0,lsr#16
+       mov     $s0,$s0,lsr#24
+.Lenc_loop:
+       ldr     $t1,[$tbl,$i1,lsl#2]    @ Te3[s0>>0]
+       and     $i1,lr,$s1,lsr#16       @ i0
+       ldr     $t2,[$tbl,$i2,lsl#2]    @ Te2[s0>>8]
+       and     $i2,lr,$s1
+       ldr     $t3,[$tbl,$i3,lsl#2]    @ Te1[s0>>16]
+       and     $i3,lr,$s1,lsr#8
+       ldr     $s0,[$tbl,$s0,lsl#2]    @ Te0[s0>>24]
+       mov     $s1,$s1,lsr#24
+
+       ldr     $i1,[$tbl,$i1,lsl#2]    @ Te1[s1>>16]
+       ldr     $i2,[$tbl,$i2,lsl#2]    @ Te3[s1>>0]
+       ldr     $i3,[$tbl,$i3,lsl#2]    @ Te2[s1>>8]
+       eor     $s0,$s0,$i1,ror#8
+       ldr     $s1,[$tbl,$s1,lsl#2]    @ Te0[s1>>24]
+       and     $i1,lr,$s2,lsr#8        @ i0
+       eor     $t2,$t2,$i2,ror#8
+       and     $i2,lr,$s2,lsr#16       @ i1
+       eor     $t3,$t3,$i3,ror#8
+       and     $i3,lr,$s2
+       eor     $s1,$s1,$t1,ror#24
+       ldr     $i1,[$tbl,$i1,lsl#2]    @ Te2[s2>>8]
+       mov     $s2,$s2,lsr#24
+
+       ldr     $i2,[$tbl,$i2,lsl#2]    @ Te1[s2>>16]
+       ldr     $i3,[$tbl,$i3,lsl#2]    @ Te3[s2>>0]
+       eor     $s0,$s0,$i1,ror#16
+       ldr     $s2,[$tbl,$s2,lsl#2]    @ Te0[s2>>24]
+       and     $i1,lr,$s3              @ i0
+       eor     $s1,$s1,$i2,ror#8
+       and     $i2,lr,$s3,lsr#8        @ i1
+       eor     $t3,$t3,$i3,ror#16
+       and     $i3,lr,$s3,lsr#16       @ i2
+       eor     $s2,$s2,$t2,ror#16
+       ldr     $i1,[$tbl,$i1,lsl#2]    @ Te3[s3>>0]
+       mov     $s3,$s3,lsr#24
+
+       ldr     $i2,[$tbl,$i2,lsl#2]    @ Te2[s3>>8]
+       ldr     $i3,[$tbl,$i3,lsl#2]    @ Te1[s3>>16]
+       eor     $s0,$s0,$i1,ror#24
+       ldr     $s3,[$tbl,$s3,lsl#2]    @ Te0[s3>>24]
+       eor     $s1,$s1,$i2,ror#16
+       ldr     $i1,[$key],#16
+       eor     $s2,$s2,$i3,ror#8
+       ldr     $t1,[$key,#-12]
+       eor     $s3,$s3,$t3,ror#8
+
+       ldr     $t2,[$key,#-8]
+       eor     $s0,$s0,$i1
+       ldr     $t3,[$key,#-4]
+       and     $i1,lr,$s0
+       eor     $s1,$s1,$t1
+       and     $i2,lr,$s0,lsr#8
+       eor     $s2,$s2,$t2
+       and     $i3,lr,$s0,lsr#16
+       eor     $s3,$s3,$t3
+       mov     $s0,$s0,lsr#24
+
+       subs    $rounds,$rounds,#1
+       bne     .Lenc_loop
+
+       add     $tbl,$tbl,#2
+
+       ldrb    $t1,[$tbl,$i1,lsl#2]    @ Te4[s0>>0]
+       and     $i1,lr,$s1,lsr#16       @ i0
+       ldrb    $t2,[$tbl,$i2,lsl#2]    @ Te4[s0>>8]
+       and     $i2,lr,$s1
+       ldrb    $t3,[$tbl,$i3,lsl#2]    @ Te4[s0>>16]
+       and     $i3,lr,$s1,lsr#8
+       ldrb    $s0,[$tbl,$s0,lsl#2]    @ Te4[s0>>24]
+       mov     $s1,$s1,lsr#24
+
+       ldrb    $i1,[$tbl,$i1,lsl#2]    @ Te4[s1>>16]
+       ldrb    $i2,[$tbl,$i2,lsl#2]    @ Te4[s1>>0]
+       ldrb    $i3,[$tbl,$i3,lsl#2]    @ Te4[s1>>8]
+       eor     $s0,$i1,$s0,lsl#8
+       ldrb    $s1,[$tbl,$s1,lsl#2]    @ Te4[s1>>24]
+       and     $i1,lr,$s2,lsr#8        @ i0
+       eor     $t2,$i2,$t2,lsl#8
+       and     $i2,lr,$s2,lsr#16       @ i1
+       eor     $t3,$i3,$t3,lsl#8
+       and     $i3,lr,$s2
+       eor     $s1,$t1,$s1,lsl#24
+       ldrb    $i1,[$tbl,$i1,lsl#2]    @ Te4[s2>>8]
+       mov     $s2,$s2,lsr#24
+
+       ldrb    $i2,[$tbl,$i2,lsl#2]    @ Te4[s2>>16]
+       ldrb    $i3,[$tbl,$i3,lsl#2]    @ Te4[s2>>0]
+       eor     $s0,$i1,$s0,lsl#8
+       ldrb    $s2,[$tbl,$s2,lsl#2]    @ Te4[s2>>24]
+       and     $i1,lr,$s3              @ i0
+       eor     $s1,$s1,$i2,lsl#16
+       and     $i2,lr,$s3,lsr#8        @ i1
+       eor     $t3,$i3,$t3,lsl#8
+       and     $i3,lr,$s3,lsr#16       @ i2
+       eor     $s2,$t2,$s2,lsl#24
+       ldrb    $i1,[$tbl,$i1,lsl#2]    @ Te4[s3>>0]
+       mov     $s3,$s3,lsr#24
+
+       ldrb    $i2,[$tbl,$i2,lsl#2]    @ Te4[s3>>8]
+       ldrb    $i3,[$tbl,$i3,lsl#2]    @ Te4[s3>>16]
+       eor     $s0,$i1,$s0,lsl#8
+       ldrb    $s3,[$tbl,$s3,lsl#2]    @ Te4[s3>>24]
+       ldr     $i1,[$key,#0]
+       eor     $s1,$s1,$i2,lsl#8
+       ldr     $t1,[$key,#4]
+       eor     $s2,$s2,$i3,lsl#16
+       ldr     $t2,[$key,#8]
+       eor     $s3,$t3,$s3,lsl#24
+       ldr     $t3,[$key,#12]
+
+       eor     $s0,$s0,$i1
+       eor     $s1,$s1,$t1
+       eor     $s2,$s2,$t2
+       eor     $s3,$s3,$t3
+
+       sub     $tbl,$tbl,#2
+       ldr     pc,[sp],#4              @ pop and return
+.size  _armv4_AES_encrypt,.-_armv4_AES_encrypt
+
+.global AES_set_encrypt_key
+.type   AES_set_encrypt_key,%function
+.align 5
+AES_set_encrypt_key:
+       sub     r3,pc,#8                @ AES_set_encrypt_key
+       teq     r0,#0
+       moveq   r0,#-1
+       beq     .Labrt
+       teq     r2,#0
+       moveq   r0,#-1
+       beq     .Labrt
+
+       teq     r1,#128
+       beq     .Lok
+       teq     r1,#192
+       beq     .Lok
+       teq     r1,#256
+       movne   r0,#-1
+       bne     .Labrt
+
+.Lok:  stmdb   sp!,{r4-r12,lr}
+       sub     $tbl,r3,#AES_set_encrypt_key-AES_Te-1024        @ Te4
+
+       mov     $rounds,r0              @ inp
+       mov     lr,r1                   @ bits
+       mov     $key,r2                 @ key
+
+       ldrb    $s0,[$rounds,#3]        @ load input data in endian-neutral
+       ldrb    $t1,[$rounds,#2]        @ manner...
+       ldrb    $t2,[$rounds,#1]
+       ldrb    $t3,[$rounds,#0]
+       orr     $s0,$s0,$t1,lsl#8
+       ldrb    $s1,[$rounds,#7]
+       orr     $s0,$s0,$t2,lsl#16
+       ldrb    $t1,[$rounds,#6]
+       orr     $s0,$s0,$t3,lsl#24
+       ldrb    $t2,[$rounds,#5]
+       ldrb    $t3,[$rounds,#4]
+       orr     $s1,$s1,$t1,lsl#8
+       ldrb    $s2,[$rounds,#11]
+       orr     $s1,$s1,$t2,lsl#16
+       ldrb    $t1,[$rounds,#10]
+       orr     $s1,$s1,$t3,lsl#24
+       ldrb    $t2,[$rounds,#9]
+       ldrb    $t3,[$rounds,#8]
+       orr     $s2,$s2,$t1,lsl#8
+       ldrb    $s3,[$rounds,#15]
+       orr     $s2,$s2,$t2,lsl#16
+       ldrb    $t1,[$rounds,#14]
+       orr     $s2,$s2,$t3,lsl#24
+       ldrb    $t2,[$rounds,#13]
+       ldrb    $t3,[$rounds,#12]
+       orr     $s3,$s3,$t1,lsl#8
+       str     $s0,[$key],#16
+       orr     $s3,$s3,$t2,lsl#16
+       str     $s1,[$key,#-12]
+       orr     $s3,$s3,$t3,lsl#24
+       str     $s2,[$key,#-8]
+       str     $s3,[$key,#-4]
+
+       teq     lr,#128
+       bne     .Lnot128
+       mov     $rounds,#10
+       str     $rounds,[$key,#240-16]
+       add     $t3,$tbl,#256                   @ rcon
+       mov     lr,#255
+
+.L128_loop:
+       and     $t2,lr,$s3,lsr#24
+       and     $i1,lr,$s3,lsr#16
+       ldrb    $t2,[$tbl,$t2]
+       and     $i2,lr,$s3,lsr#8
+       ldrb    $i1,[$tbl,$i1]
+       and     $i3,lr,$s3
+       ldrb    $i2,[$tbl,$i2]
+       orr     $t2,$t2,$i1,lsl#24
+       ldrb    $i3,[$tbl,$i3]
+       orr     $t2,$t2,$i2,lsl#16
+       ldr     $t1,[$t3],#4                    @ rcon[i++]
+       orr     $t2,$t2,$i3,lsl#8
+       eor     $t2,$t2,$t1
+       eor     $s0,$s0,$t2                     @ rk[4]=rk[0]^...
+       eor     $s1,$s1,$s0                     @ rk[5]=rk[1]^rk[4]
+       str     $s0,[$key],#16
+       eor     $s2,$s2,$s1                     @ rk[6]=rk[2]^rk[5]
+       str     $s1,[$key,#-12]
+       eor     $s3,$s3,$s2                     @ rk[7]=rk[3]^rk[6]
+       str     $s2,[$key,#-8]
+       subs    $rounds,$rounds,#1
+       str     $s3,[$key,#-4]
+       bne     .L128_loop
+       sub     r2,$key,#176
+       b       .Ldone
+
+.Lnot128:
+       ldrb    $i2,[$rounds,#19]
+       ldrb    $t1,[$rounds,#18]
+       ldrb    $t2,[$rounds,#17]
+       ldrb    $t3,[$rounds,#16]
+       orr     $i2,$i2,$t1,lsl#8
+       ldrb    $i3,[$rounds,#23]
+       orr     $i2,$i2,$t2,lsl#16
+       ldrb    $t1,[$rounds,#22]
+       orr     $i2,$i2,$t3,lsl#24
+       ldrb    $t2,[$rounds,#21]
+       ldrb    $t3,[$rounds,#20]
+       orr     $i3,$i3,$t1,lsl#8
+       orr     $i3,$i3,$t2,lsl#16
+       str     $i2,[$key],#8
+       orr     $i3,$i3,$t3,lsl#24
+       str     $i3,[$key,#-4]
+
+       teq     lr,#192
+       bne     .Lnot192
+       mov     $rounds,#12
+       str     $rounds,[$key,#240-24]
+       add     $t3,$tbl,#256                   @ rcon
+       mov     lr,#255
+       mov     $rounds,#8
+
+.L192_loop:
+       and     $t2,lr,$i3,lsr#24
+       and     $i1,lr,$i3,lsr#16
+       ldrb    $t2,[$tbl,$t2]
+       and     $i2,lr,$i3,lsr#8
+       ldrb    $i1,[$tbl,$i1]
+       and     $i3,lr,$i3
+       ldrb    $i2,[$tbl,$i2]
+       orr     $t2,$t2,$i1,lsl#24
+       ldrb    $i3,[$tbl,$i3]
+       orr     $t2,$t2,$i2,lsl#16
+       ldr     $t1,[$t3],#4                    @ rcon[i++]
+       orr     $t2,$t2,$i3,lsl#8
+       eor     $i3,$t2,$t1
+       eor     $s0,$s0,$i3                     @ rk[6]=rk[0]^...
+       eor     $s1,$s1,$s0                     @ rk[7]=rk[1]^rk[6]
+       str     $s0,[$key],#24
+       eor     $s2,$s2,$s1                     @ rk[8]=rk[2]^rk[7]
+       str     $s1,[$key,#-20]
+       eor     $s3,$s3,$s2                     @ rk[9]=rk[3]^rk[8]
+       str     $s2,[$key,#-16]
+       subs    $rounds,$rounds,#1
+       str     $s3,[$key,#-12]
+       subeq   r2,$key,#216
+       beq     .Ldone
+
+       ldr     $i1,[$key,#-32]
+       ldr     $i2,[$key,#-28]
+       eor     $i1,$i1,$s3                     @ rk[10]=rk[4]^rk[9]
+       eor     $i3,$i2,$i1                     @ rk[11]=rk[5]^rk[10]
+       str     $i1,[$key,#-8]
+       str     $i3,[$key,#-4]
+       b       .L192_loop
+
+.Lnot192:
+       ldrb    $i2,[$rounds,#27]
+       ldrb    $t1,[$rounds,#26]
+       ldrb    $t2,[$rounds,#25]
+       ldrb    $t3,[$rounds,#24]
+       orr     $i2,$i2,$t1,lsl#8
+       ldrb    $i3,[$rounds,#31]
+       orr     $i2,$i2,$t2,lsl#16
+       ldrb    $t1,[$rounds,#30]
+       orr     $i2,$i2,$t3,lsl#24
+       ldrb    $t2,[$rounds,#29]
+       ldrb    $t3,[$rounds,#28]
+       orr     $i3,$i3,$t1,lsl#8
+       orr     $i3,$i3,$t2,lsl#16
+       str     $i2,[$key],#8
+       orr     $i3,$i3,$t3,lsl#24
+       str     $i3,[$key,#-4]
+
+       mov     $rounds,#14
+       str     $rounds,[$key,#240-32]
+       add     $t3,$tbl,#256                   @ rcon
+       mov     lr,#255
+       mov     $rounds,#7
+
+.L256_loop:
+       and     $t2,lr,$i3,lsr#24
+       and     $i1,lr,$i3,lsr#16
+       ldrb    $t2,[$tbl,$t2]
+       and     $i2,lr,$i3,lsr#8
+       ldrb    $i1,[$tbl,$i1]
+       and     $i3,lr,$i3
+       ldrb    $i2,[$tbl,$i2]
+       orr     $t2,$t2,$i1,lsl#24
+       ldrb    $i3,[$tbl,$i3]
+       orr     $t2,$t2,$i2,lsl#16
+       ldr     $t1,[$t3],#4                    @ rcon[i++]
+       orr     $t2,$t2,$i3,lsl#8
+       eor     $i3,$t2,$t1
+       eor     $s0,$s0,$i3                     @ rk[8]=rk[0]^...
+       eor     $s1,$s1,$s0                     @ rk[9]=rk[1]^rk[8]
+       str     $s0,[$key],#32
+       eor     $s2,$s2,$s1                     @ rk[10]=rk[2]^rk[9]
+       str     $s1,[$key,#-28]
+       eor     $s3,$s3,$s2                     @ rk[11]=rk[3]^rk[10]
+       str     $s2,[$key,#-24]
+       subs    $rounds,$rounds,#1
+       str     $s3,[$key,#-20]
+       subeq   r2,$key,#256
+       beq     .Ldone
+
+       and     $t2,lr,$s3
+       and     $i1,lr,$s3,lsr#8
+       ldrb    $t2,[$tbl,$t2]
+       and     $i2,lr,$s3,lsr#16
+       ldrb    $i1,[$tbl,$i1]
+       and     $i3,lr,$s3,lsr#24
+       ldrb    $i2,[$tbl,$i2]
+       orr     $t2,$t2,$i1,lsl#8
+       ldrb    $i3,[$tbl,$i3]
+       orr     $t2,$t2,$i2,lsl#16
+       ldr     $t1,[$key,#-48]
+       orr     $t2,$t2,$i3,lsl#24
+
+       ldr     $i1,[$key,#-44]
+       ldr     $i2,[$key,#-40]
+       eor     $t1,$t1,$t2                     @ rk[12]=rk[4]^...
+       ldr     $i3,[$key,#-36]
+       eor     $i1,$i1,$t1                     @ rk[13]=rk[5]^rk[12]
+       str     $t1,[$key,#-16]
+       eor     $i2,$i2,$i1                     @ rk[14]=rk[6]^rk[13]
+       str     $i1,[$key,#-12]
+       eor     $i3,$i3,$i2                     @ rk[15]=rk[7]^rk[14]
+       str     $i2,[$key,#-8]
+       str     $i3,[$key,#-4]
+       b       .L256_loop
+
+.Ldone:        mov     r0,#0
+       ldmia   sp!,{r4-r12,lr}
+.Labrt:        tst     lr,#1
+       moveq   pc,lr                   @ be binary compatible with V4, yet
+       bx      lr                      @ interoperable with Thumb ISA:-)
+.size  AES_set_encrypt_key,.-AES_set_encrypt_key
+
+.global AES_set_decrypt_key
+.type   AES_set_decrypt_key,%function
+.align 5
+AES_set_decrypt_key:
+       str     lr,[sp,#-4]!            @ push lr
+       bl      AES_set_encrypt_key
+       teq     r0,#0
+       ldrne   lr,[sp],#4              @ pop lr
+       bne     .Labrt
+
+       stmdb   sp!,{r4-r12}
+
+       ldr     $rounds,[r2,#240]       @ AES_set_encrypt_key preserves r2,
+       mov     $key,r2                 @ which is AES_KEY *key
+       mov     $i1,r2
+       add     $i2,r2,$rounds,lsl#4
+
+.Linv: ldr     $s0,[$i1]
+       ldr     $s1,[$i1,#4]
+       ldr     $s2,[$i1,#8]
+       ldr     $s3,[$i1,#12]
+       ldr     $t1,[$i2]
+       ldr     $t2,[$i2,#4]
+       ldr     $t3,[$i2,#8]
+       ldr     $i3,[$i2,#12]
+       str     $s0,[$i2],#-16
+       str     $s1,[$i2,#16+4]
+       str     $s2,[$i2,#16+8]
+       str     $s3,[$i2,#16+12]
+       str     $t1,[$i1],#16
+       str     $t2,[$i1,#-12]
+       str     $t3,[$i1,#-8]
+       str     $i3,[$i1,#-4]
+       teq     $i1,$i2
+       bne     .Linv
+___
+$mask80=$i1;
+$mask1b=$i2;
+$mask7f=$i3;
+$code.=<<___;
+       ldr     $s0,[$key,#16]!         @ prefetch tp1
+       mov     $mask80,#0x80
+       mov     $mask1b,#0x1b
+       orr     $mask80,$mask80,#0x8000
+       orr     $mask1b,$mask1b,#0x1b00
+       orr     $mask80,$mask80,$mask80,lsl#16
+       orr     $mask1b,$mask1b,$mask1b,lsl#16
+       sub     $rounds,$rounds,#1
+       mvn     $mask7f,$mask80
+       mov     $rounds,$rounds,lsl#2   @ (rounds-1)*4
+
+.Lmix: and     $t1,$s0,$mask80
+       and     $s1,$s0,$mask7f
+       sub     $t1,$t1,$t1,lsr#7
+       and     $t1,$t1,$mask1b
+       eor     $s1,$t1,$s1,lsl#1       @ tp2
+
+       and     $t1,$s1,$mask80
+       and     $s2,$s1,$mask7f
+       sub     $t1,$t1,$t1,lsr#7
+       and     $t1,$t1,$mask1b
+       eor     $s2,$t1,$s2,lsl#1       @ tp4
+
+       and     $t1,$s2,$mask80
+       and     $s3,$s2,$mask7f
+       sub     $t1,$t1,$t1,lsr#7
+       and     $t1,$t1,$mask1b
+       eor     $s3,$t1,$s3,lsl#1       @ tp8
+
+       eor     $t1,$s1,$s2
+       eor     $t2,$s0,$s3             @ tp9
+       eor     $t1,$t1,$s3             @ tpe
+       eor     $t1,$t1,$s1,ror#24
+       eor     $t1,$t1,$t2,ror#24      @ ^= ROTATE(tpb=tp9^tp2,8)
+       eor     $t1,$t1,$s2,ror#16
+       eor     $t1,$t1,$t2,ror#16      @ ^= ROTATE(tpd=tp9^tp4,16)
+       eor     $t1,$t1,$t2,ror#8       @ ^= ROTATE(tp9,24)
+
+       ldr     $s0,[$key,#4]           @ prefetch tp1
+       str     $t1,[$key],#4
+       subs    $rounds,$rounds,#1
+       bne     .Lmix
+
+       mov     r0,#0
+       ldmia   sp!,{r4-r12,lr}
+       tst     lr,#1
+       moveq   pc,lr                   @ be binary compatible with V4, yet
+       bx      lr                      @ interoperable with Thumb ISA:-)
+.size  AES_set_decrypt_key,.-AES_set_decrypt_key
+
+.type  AES_Td,%object
+.align 5
+AES_Td:
+.word  0x51f4a750, 0x7e416553, 0x1a17a4c3, 0x3a275e96
+.word  0x3bab6bcb, 0x1f9d45f1, 0xacfa58ab, 0x4be30393
+.word  0x2030fa55, 0xad766df6, 0x88cc7691, 0xf5024c25
+.word  0x4fe5d7fc, 0xc52acbd7, 0x26354480, 0xb562a38f
+.word  0xdeb15a49, 0x25ba1b67, 0x45ea0e98, 0x5dfec0e1
+.word  0xc32f7502, 0x814cf012, 0x8d4697a3, 0x6bd3f9c6
+.word  0x038f5fe7, 0x15929c95, 0xbf6d7aeb, 0x955259da
+.word  0xd4be832d, 0x587421d3, 0x49e06929, 0x8ec9c844
+.word  0x75c2896a, 0xf48e7978, 0x99583e6b, 0x27b971dd
+.word  0xbee14fb6, 0xf088ad17, 0xc920ac66, 0x7dce3ab4
+.word  0x63df4a18, 0xe51a3182, 0x97513360, 0x62537f45
+.word  0xb16477e0, 0xbb6bae84, 0xfe81a01c, 0xf9082b94
+.word  0x70486858, 0x8f45fd19, 0x94de6c87, 0x527bf8b7
+.word  0xab73d323, 0x724b02e2, 0xe31f8f57, 0x6655ab2a
+.word  0xb2eb2807, 0x2fb5c203, 0x86c57b9a, 0xd33708a5
+.word  0x302887f2, 0x23bfa5b2, 0x02036aba, 0xed16825c
+.word  0x8acf1c2b, 0xa779b492, 0xf307f2f0, 0x4e69e2a1
+.word  0x65daf4cd, 0x0605bed5, 0xd134621f, 0xc4a6fe8a
+.word  0x342e539d, 0xa2f355a0, 0x058ae132, 0xa4f6eb75
+.word  0x0b83ec39, 0x4060efaa, 0x5e719f06, 0xbd6e1051
+.word  0x3e218af9, 0x96dd063d, 0xdd3e05ae, 0x4de6bd46
+.word  0x91548db5, 0x71c45d05, 0x0406d46f, 0x605015ff
+.word  0x1998fb24, 0xd6bde997, 0x894043cc, 0x67d99e77
+.word  0xb0e842bd, 0x07898b88, 0xe7195b38, 0x79c8eedb
+.word  0xa17c0a47, 0x7c420fe9, 0xf8841ec9, 0x00000000
+.word  0x09808683, 0x322bed48, 0x1e1170ac, 0x6c5a724e
+.word  0xfd0efffb, 0x0f853856, 0x3daed51e, 0x362d3927
+.word  0x0a0fd964, 0x685ca621, 0x9b5b54d1, 0x24362e3a
+.word  0x0c0a67b1, 0x9357e70f, 0xb4ee96d2, 0x1b9b919e
+.word  0x80c0c54f, 0x61dc20a2, 0x5a774b69, 0x1c121a16
+.word  0xe293ba0a, 0xc0a02ae5, 0x3c22e043, 0x121b171d
+.word  0x0e090d0b, 0xf28bc7ad, 0x2db6a8b9, 0x141ea9c8
+.word  0x57f11985, 0xaf75074c, 0xee99ddbb, 0xa37f60fd
+.word  0xf701269f, 0x5c72f5bc, 0x44663bc5, 0x5bfb7e34
+.word  0x8b432976, 0xcb23c6dc, 0xb6edfc68, 0xb8e4f163
+.word  0xd731dcca, 0x42638510, 0x13972240, 0x84c61120
+.word  0x854a247d, 0xd2bb3df8, 0xaef93211, 0xc729a16d
+.word  0x1d9e2f4b, 0xdcb230f3, 0x0d8652ec, 0x77c1e3d0
+.word  0x2bb3166c, 0xa970b999, 0x119448fa, 0x47e96422
+.word  0xa8fc8cc4, 0xa0f03f1a, 0x567d2cd8, 0x223390ef
+.word  0x87494ec7, 0xd938d1c1, 0x8ccaa2fe, 0x98d40b36
+.word  0xa6f581cf, 0xa57ade28, 0xdab78e26, 0x3fadbfa4
+.word  0x2c3a9de4, 0x5078920d, 0x6a5fcc9b, 0x547e4662
+.word  0xf68d13c2, 0x90d8b8e8, 0x2e39f75e, 0x82c3aff5
+.word  0x9f5d80be, 0x69d0937c, 0x6fd52da9, 0xcf2512b3
+.word  0xc8ac993b, 0x10187da7, 0xe89c636e, 0xdb3bbb7b
+.word  0xcd267809, 0x6e5918f4, 0xec9ab701, 0x834f9aa8
+.word  0xe6956e65, 0xaaffe67e, 0x21bccf08, 0xef15e8e6
+.word  0xbae79bd9, 0x4a6f36ce, 0xea9f09d4, 0x29b07cd6
+.word  0x31a4b2af, 0x2a3f2331, 0xc6a59430, 0x35a266c0
+.word  0x744ebc37, 0xfc82caa6, 0xe090d0b0, 0x33a7d815
+.word  0xf104984a, 0x41ecdaf7, 0x7fcd500e, 0x1791f62f
+.word  0x764dd68d, 0x43efb04d, 0xccaa4d54, 0xe49604df
+.word  0x9ed1b5e3, 0x4c6a881b, 0xc12c1fb8, 0x4665517f
+.word  0x9d5eea04, 0x018c355d, 0xfa877473, 0xfb0b412e
+.word  0xb3671d5a, 0x92dbd252, 0xe9105633, 0x6dd64713
+.word  0x9ad7618c, 0x37a10c7a, 0x59f8148e, 0xeb133c89
+.word  0xcea927ee, 0xb761c935, 0xe11ce5ed, 0x7a47b13c
+.word  0x9cd2df59, 0x55f2733f, 0x1814ce79, 0x73c737bf
+.word  0x53f7cdea, 0x5ffdaa5b, 0xdf3d6f14, 0x7844db86
+.word  0xcaaff381, 0xb968c43e, 0x3824342c, 0xc2a3405f
+.word  0x161dc372, 0xbce2250c, 0x283c498b, 0xff0d9541
+.word  0x39a80171, 0x080cb3de, 0xd8b4e49c, 0x6456c190
+.word  0x7bcb8461, 0xd532b670, 0x486c5c74, 0xd0b85742
+@ Td4[256]
+.byte  0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38
+.byte  0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb
+.byte  0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87
+.byte  0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb
+.byte  0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d
+.byte  0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e
+.byte  0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2
+.byte  0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25
+.byte  0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16
+.byte  0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92
+.byte  0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda
+.byte  0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84
+.byte  0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a
+.byte  0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06
+.byte  0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02
+.byte  0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b
+.byte  0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea
+.byte  0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73
+.byte  0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85
+.byte  0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e
+.byte  0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89
+.byte  0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b
+.byte  0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20
+.byte  0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4
+.byte  0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31
+.byte  0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f
+.byte  0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d
+.byte  0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef
+.byte  0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0
+.byte  0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61
+.byte  0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26
+.byte  0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d
+.size  AES_Td,.-AES_Td
+
+@ void AES_decrypt(const unsigned char *in, unsigned char *out,
+@               const AES_KEY *key) {
+.global AES_decrypt
+.type   AES_decrypt,%function
+.align 5
+AES_decrypt:
+       sub     r3,pc,#8                @ AES_decrypt
+       stmdb   sp!,{r1,r4-r12,lr}
+       mov     $rounds,r0              @ inp
+       mov     $key,r2
+       sub     $tbl,r3,#AES_decrypt-AES_Td             @ Td
+
+       ldrb    $s0,[$rounds,#3]        @ load input data in endian-neutral
+       ldrb    $t1,[$rounds,#2]        @ manner...
+       ldrb    $t2,[$rounds,#1]
+       ldrb    $t3,[$rounds,#0]
+       orr     $s0,$s0,$t1,lsl#8
+       ldrb    $s1,[$rounds,#7]
+       orr     $s0,$s0,$t2,lsl#16
+       ldrb    $t1,[$rounds,#6]
+       orr     $s0,$s0,$t3,lsl#24
+       ldrb    $t2,[$rounds,#5]
+       ldrb    $t3,[$rounds,#4]
+       orr     $s1,$s1,$t1,lsl#8
+       ldrb    $s2,[$rounds,#11]
+       orr     $s1,$s1,$t2,lsl#16
+       ldrb    $t1,[$rounds,#10]
+       orr     $s1,$s1,$t3,lsl#24
+       ldrb    $t2,[$rounds,#9]
+       ldrb    $t3,[$rounds,#8]
+       orr     $s2,$s2,$t1,lsl#8
+       ldrb    $s3,[$rounds,#15]
+       orr     $s2,$s2,$t2,lsl#16
+       ldrb    $t1,[$rounds,#14]
+       orr     $s2,$s2,$t3,lsl#24
+       ldrb    $t2,[$rounds,#13]
+       ldrb    $t3,[$rounds,#12]
+       orr     $s3,$s3,$t1,lsl#8
+       orr     $s3,$s3,$t2,lsl#16
+       orr     $s3,$s3,$t3,lsl#24
+
+       bl      _armv4_AES_decrypt
+
+       ldr     $rounds,[sp],#4         @ pop out
+       mov     $t1,$s0,lsr#24          @ write output in endian-neutral
+       mov     $t2,$s0,lsr#16          @ manner...
+       mov     $t3,$s0,lsr#8
+       strb    $t1,[$rounds,#0]
+       strb    $t2,[$rounds,#1]
+       mov     $t1,$s1,lsr#24
+       strb    $t3,[$rounds,#2]
+       mov     $t2,$s1,lsr#16
+       strb    $s0,[$rounds,#3]
+       mov     $t3,$s1,lsr#8
+       strb    $t1,[$rounds,#4]
+       strb    $t2,[$rounds,#5]
+       mov     $t1,$s2,lsr#24
+       strb    $t3,[$rounds,#6]
+       mov     $t2,$s2,lsr#16
+       strb    $s1,[$rounds,#7]
+       mov     $t3,$s2,lsr#8
+       strb    $t1,[$rounds,#8]
+       strb    $t2,[$rounds,#9]
+       mov     $t1,$s3,lsr#24
+       strb    $t3,[$rounds,#10]
+       mov     $t2,$s3,lsr#16
+       strb    $s2,[$rounds,#11]
+       mov     $t3,$s3,lsr#8
+       strb    $t1,[$rounds,#12]
+       strb    $t2,[$rounds,#13]
+       strb    $t3,[$rounds,#14]
+       strb    $s3,[$rounds,#15]
+
+       ldmia   sp!,{r4-r12,lr}
+       tst     lr,#1
+       moveq   pc,lr                   @ be binary compatible with V4, yet
+       bx      lr                      @ interoperable with Thumb ISA:-)
+.size  AES_decrypt,.-AES_decrypt
+
+.type   _armv4_AES_decrypt,%function
+.align 2
+_armv4_AES_decrypt:
+       str     lr,[sp,#-4]!            @ push lr
+       ldmia   $key!,{$t1-$i1}
+       eor     $s0,$s0,$t1
+       ldr     $rounds,[$key,#240-16]
+       eor     $s1,$s1,$t2
+       eor     $s2,$s2,$t3
+       eor     $s3,$s3,$i1
+       sub     $rounds,$rounds,#1
+       mov     lr,#255
+
+       and     $i1,lr,$s0,lsr#16
+       and     $i2,lr,$s0,lsr#8
+       and     $i3,lr,$s0
+       mov     $s0,$s0,lsr#24
+.Ldec_loop:
+       ldr     $t1,[$tbl,$i1,lsl#2]    @ Td1[s0>>16]
+       and     $i1,lr,$s1              @ i0
+       ldr     $t2,[$tbl,$i2,lsl#2]    @ Td2[s0>>8]
+       and     $i2,lr,$s1,lsr#16
+       ldr     $t3,[$tbl,$i3,lsl#2]    @ Td3[s0>>0]
+       and     $i3,lr,$s1,lsr#8
+       ldr     $s0,[$tbl,$s0,lsl#2]    @ Td0[s0>>24]
+       mov     $s1,$s1,lsr#24
+
+       ldr     $i1,[$tbl,$i1,lsl#2]    @ Td3[s1>>0]
+       ldr     $i2,[$tbl,$i2,lsl#2]    @ Td1[s1>>16]
+       ldr     $i3,[$tbl,$i3,lsl#2]    @ Td2[s1>>8]
+       eor     $s0,$s0,$i1,ror#24
+       ldr     $s1,[$tbl,$s1,lsl#2]    @ Td0[s1>>24]
+       and     $i1,lr,$s2,lsr#8        @ i0
+       eor     $t2,$i2,$t2,ror#8
+       and     $i2,lr,$s2              @ i1
+       eor     $t3,$i3,$t3,ror#8
+       and     $i3,lr,$s2,lsr#16
+       eor     $s1,$s1,$t1,ror#8
+       ldr     $i1,[$tbl,$i1,lsl#2]    @ Td2[s2>>8]
+       mov     $s2,$s2,lsr#24
+
+       ldr     $i2,[$tbl,$i2,lsl#2]    @ Td3[s2>>0]
+       ldr     $i3,[$tbl,$i3,lsl#2]    @ Td1[s2>>16]
+       eor     $s0,$s0,$i1,ror#16
+       ldr     $s2,[$tbl,$s2,lsl#2]    @ Td0[s2>>24]
+       and     $i1,lr,$s3,lsr#16       @ i0
+       eor     $s1,$s1,$i2,ror#24
+       and     $i2,lr,$s3,lsr#8        @ i1
+       eor     $t3,$i3,$t3,ror#8
+       and     $i3,lr,$s3              @ i2
+       eor     $s2,$s2,$t2,ror#8
+       ldr     $i1,[$tbl,$i1,lsl#2]    @ Td1[s3>>16]
+       mov     $s3,$s3,lsr#24
+
+       ldr     $i2,[$tbl,$i2,lsl#2]    @ Td2[s3>>8]
+       ldr     $i3,[$tbl,$i3,lsl#2]    @ Td3[s3>>0]
+       eor     $s0,$s0,$i1,ror#8
+       ldr     $s3,[$tbl,$s3,lsl#2]    @ Td0[s3>>24]
+       eor     $s1,$s1,$i2,ror#16
+       eor     $s2,$s2,$i3,ror#24
+       ldr     $i1,[$key],#16
+       eor     $s3,$s3,$t3,ror#8
+
+       ldr     $t1,[$key,#-12]
+       ldr     $t2,[$key,#-8]
+       eor     $s0,$s0,$i1
+       ldr     $t3,[$key,#-4]
+       and     $i1,lr,$s0,lsr#16
+       eor     $s1,$s1,$t1
+       and     $i2,lr,$s0,lsr#8
+       eor     $s2,$s2,$t2
+       and     $i3,lr,$s0
+       eor     $s3,$s3,$t3
+       mov     $s0,$s0,lsr#24
+
+       subs    $rounds,$rounds,#1
+       bne     .Ldec_loop
+
+       add     $tbl,$tbl,#1024
+
+       ldr     $t2,[$tbl,#0]           @ prefetch Td4
+       ldr     $t3,[$tbl,#32]
+       ldr     $t1,[$tbl,#64]
+       ldr     $t2,[$tbl,#96]
+       ldr     $t3,[$tbl,#128]
+       ldr     $t1,[$tbl,#160]
+       ldr     $t2,[$tbl,#192]
+       ldr     $t3,[$tbl,#224]
+
+       ldrb    $s0,[$tbl,$s0]          @ Td4[s0>>24]
+       ldrb    $t1,[$tbl,$i1]          @ Td4[s0>>16]
+       and     $i1,lr,$s1              @ i0
+       ldrb    $t2,[$tbl,$i2]          @ Td4[s0>>8]
+       and     $i2,lr,$s1,lsr#16
+       ldrb    $t3,[$tbl,$i3]          @ Td4[s0>>0]
+       and     $i3,lr,$s1,lsr#8
+
+       ldrb    $i1,[$tbl,$i1]          @ Td4[s1>>0]
+       ldrb    $s1,[$tbl,$s1,lsr#24]   @ Td4[s1>>24]
+       ldrb    $i2,[$tbl,$i2]          @ Td4[s1>>16]
+       eor     $s0,$i1,$s0,lsl#24
+       ldrb    $i3,[$tbl,$i3]          @ Td4[s1>>8]
+       eor     $s1,$t1,$s1,lsl#8
+       and     $i1,lr,$s2,lsr#8        @ i0
+       eor     $t2,$t2,$i2,lsl#8
+       and     $i2,lr,$s2              @ i1
+       eor     $t3,$t3,$i3,lsl#8
+       ldrb    $i1,[$tbl,$i1]          @ Td4[s2>>8]
+       and     $i3,lr,$s2,lsr#16
+
+       ldrb    $i2,[$tbl,$i2]          @ Td4[s2>>0]
+       ldrb    $s2,[$tbl,$s2,lsr#24]   @ Td4[s2>>24]
+       eor     $s0,$s0,$i1,lsl#8
+       ldrb    $i3,[$tbl,$i3]          @ Td4[s2>>16]
+       eor     $s1,$i2,$s1,lsl#16
+       and     $i1,lr,$s3,lsr#16       @ i0
+       eor     $s2,$t2,$s2,lsl#16
+       and     $i2,lr,$s3,lsr#8        @ i1
+       eor     $t3,$t3,$i3,lsl#16
+       ldrb    $i1,[$tbl,$i1]          @ Td4[s3>>16]
+       and     $i3,lr,$s3              @ i2
+
+       ldrb    $i2,[$tbl,$i2]          @ Td4[s3>>8]
+       ldrb    $i3,[$tbl,$i3]          @ Td4[s3>>0]
+       ldrb    $s3,[$tbl,$s3,lsr#24]   @ Td4[s3>>24]
+       eor     $s0,$s0,$i1,lsl#16
+       ldr     $i1,[$key,#0]
+       eor     $s1,$s1,$i2,lsl#8
+       ldr     $t1,[$key,#4]
+       eor     $s2,$i3,$s2,lsl#8
+       ldr     $t2,[$key,#8]
+       eor     $s3,$t3,$s3,lsl#24
+       ldr     $t3,[$key,#12]
+
+       eor     $s0,$s0,$i1
+       eor     $s1,$s1,$t1
+       eor     $s2,$s2,$t2
+       eor     $s3,$s3,$t3
+
+       sub     $tbl,$tbl,#1024
+       ldr     pc,[sp],#4              @ pop and return
+.size  _armv4_AES_decrypt,.-_armv4_AES_decrypt
+.asciz "AES for ARMv4, CRYPTOGAMS by <appro\@openssl.org>"
+.align 2
+___
+
+$code =~ s/\bbx\s+lr\b/.word\t0xe12fff1e/gm;   # make it possible to compile with -march=armv4
+print $code;
+close STDOUT;  # enforce flush
diff --git a/deps/openssl/openssl/crypto/aes/asm/aes-ppc.pl b/deps/openssl/openssl/crypto/aes/asm/aes-ppc.pl
new file mode 100644 (file)
index 0000000..f82c5e1
--- /dev/null
@@ -0,0 +1,1189 @@
+#!/usr/bin/env perl
+
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+
+# Needs more work: key setup, page boundaries, CBC routine...
+#
+# ppc_AES_[en|de]crypt perform at 18 cycles per byte processed with
+# 128-bit key, which is ~40% better than 64-bit code generated by gcc
+# 4.0. But these are not the ones currently used! Their "compact"
+# counterparts are, for security reason. ppc_AES_encrypt_compact runs
+# at 1/2 of ppc_AES_encrypt speed, while ppc_AES_decrypt_compact -
+# at 1/3 of ppc_AES_decrypt.
+
+# February 2010
+#
+# Rescheduling instructions to favour Power6 pipeline gives 10%
+# performance improvement on the platfrom in question (and marginal
+# improvement even on others). It should be noted that Power6 fails
+# to process byte in 18 cycles, only in 23, because it fails to issue
+# 4 load instructions in two cycles, only in 3. As result non-compact
+# block subroutines are 25% slower than one would expect. Compact
+# functions scale better, because they have pure computational part,
+# which scales perfectly with clock frequency. To be specific
+# ppc_AES_encrypt_compact operates at 42 cycles per byte, while
+# ppc_AES_decrypt_compact - at 55 (in 64-bit build).
+
+$flavour = shift;
+
+if ($flavour =~ /64/) {
+       $SIZE_T =8;
+       $STU    ="stdu";
+       $POP    ="ld";
+       $PUSH   ="std";
+} elsif ($flavour =~ /32/) {
+       $SIZE_T =4;
+       $STU    ="stwu";
+       $POP    ="lwz";
+       $PUSH   ="stw";
+} else { die "nonsense $flavour"; }
+
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+( $xlate="${dir}ppc-xlate.pl" and -f $xlate ) or
+( $xlate="${dir}../../perlasm/ppc-xlate.pl" and -f $xlate) or
+die "can't locate ppc-xlate.pl";
+
+open STDOUT,"| $^X $xlate $flavour ".shift || die "can't call $xlate: $!";
+
+$FRAME=32*$SIZE_T;
+
+sub _data_word()
+{ my $i;
+    while(defined($i=shift)) { $code.=sprintf"\t.long\t0x%08x,0x%08x\n",$i,$i; }
+}
+
+$sp="r1";
+$toc="r2";
+$inp="r3";
+$out="r4";
+$key="r5";
+
+$Tbl0="r3";
+$Tbl1="r6";
+$Tbl2="r7";
+$Tbl3="r2";
+
+$s0="r8";
+$s1="r9";
+$s2="r10";
+$s3="r11";
+
+$t0="r12";
+$t1="r13";
+$t2="r14";
+$t3="r15";
+
+$acc00="r16";
+$acc01="r17";
+$acc02="r18";
+$acc03="r19";
+
+$acc04="r20";
+$acc05="r21";
+$acc06="r22";
+$acc07="r23";
+
+$acc08="r24";
+$acc09="r25";
+$acc10="r26";
+$acc11="r27";
+
+$acc12="r28";
+$acc13="r29";
+$acc14="r30";
+$acc15="r31";
+
+# stay away from TLS pointer
+if ($SIZE_T==8)        { die if ($t1 ne "r13");  $t1="r0";             }
+else           { die if ($Tbl3 ne "r2"); $Tbl3=$t0; $t0="r0";  }
+$mask80=$Tbl2;
+$mask1b=$Tbl3;
+
+$code.=<<___;
+.machine       "any"
+.text
+
+.align 7
+LAES_Te:
+       mflr    r0
+       bcl     20,31,\$+4
+       mflr    $Tbl0   ;    vvvvv "distance" between . and 1st data entry
+       addi    $Tbl0,$Tbl0,`128-8`
+       mtlr    r0
+       blr
+       .space  `32-24`
+LAES_Td:
+       mflr    r0
+       bcl     20,31,\$+4
+       mflr    $Tbl0   ;    vvvvvvvv "distance" between . and 1st data entry
+       addi    $Tbl0,$Tbl0,`128-8-32+2048+256`
+       mtlr    r0
+       blr
+       .space  `128-32-24`
+___
+&_data_word(
+       0xc66363a5, 0xf87c7c84, 0xee777799, 0xf67b7b8d,
+       0xfff2f20d, 0xd66b6bbd, 0xde6f6fb1, 0x91c5c554,
+       0x60303050, 0x02010103, 0xce6767a9, 0x562b2b7d,
+       0xe7fefe19, 0xb5d7d762, 0x4dababe6, 0xec76769a,
+       0x8fcaca45, 0x1f82829d, 0x89c9c940, 0xfa7d7d87,
+       0xeffafa15, 0xb25959eb, 0x8e4747c9, 0xfbf0f00b,
+       0x41adadec, 0xb3d4d467, 0x5fa2a2fd, 0x45afafea,
+       0x239c9cbf, 0x53a4a4f7, 0xe4727296, 0x9bc0c05b,
+       0x75b7b7c2, 0xe1fdfd1c, 0x3d9393ae, 0x4c26266a,
+       0x6c36365a, 0x7e3f3f41, 0xf5f7f702, 0x83cccc4f,
+       0x6834345c, 0x51a5a5f4, 0xd1e5e534, 0xf9f1f108,
+       0xe2717193, 0xabd8d873, 0x62313153, 0x2a15153f,
+       0x0804040c, 0x95c7c752, 0x46232365, 0x9dc3c35e,
+       0x30181828, 0x379696a1, 0x0a05050f, 0x2f9a9ab5,
+       0x0e070709, 0x24121236, 0x1b80809b, 0xdfe2e23d,
+       0xcdebeb26, 0x4e272769, 0x7fb2b2cd, 0xea75759f,
+       0x1209091b, 0x1d83839e, 0x582c2c74, 0x341a1a2e,
+       0x361b1b2d, 0xdc6e6eb2, 0xb45a5aee, 0x5ba0a0fb,
+       0xa45252f6, 0x763b3b4d, 0xb7d6d661, 0x7db3b3ce,
+       0x5229297b, 0xdde3e33e, 0x5e2f2f71, 0x13848497,
+       0xa65353f5, 0xb9d1d168, 0x00000000, 0xc1eded2c,
+       0x40202060, 0xe3fcfc1f, 0x79b1b1c8, 0xb65b5bed,
+       0xd46a6abe, 0x8dcbcb46, 0x67bebed9, 0x7239394b,
+       0x944a4ade, 0x984c4cd4, 0xb05858e8, 0x85cfcf4a,
+       0xbbd0d06b, 0xc5efef2a, 0x4faaaae5, 0xedfbfb16,
+       0x864343c5, 0x9a4d4dd7, 0x66333355, 0x11858594,
+       0x8a4545cf, 0xe9f9f910, 0x04020206, 0xfe7f7f81,
+       0xa05050f0, 0x783c3c44, 0x259f9fba, 0x4ba8a8e3,
+       0xa25151f3, 0x5da3a3fe, 0x804040c0, 0x058f8f8a,
+       0x3f9292ad, 0x219d9dbc, 0x70383848, 0xf1f5f504,
+       0x63bcbcdf, 0x77b6b6c1, 0xafdada75, 0x42212163,
+       0x20101030, 0xe5ffff1a, 0xfdf3f30e, 0xbfd2d26d,
+       0x81cdcd4c, 0x180c0c14, 0x26131335, 0xc3ecec2f,
+       0xbe5f5fe1, 0x359797a2, 0x884444cc, 0x2e171739,
+       0x93c4c457, 0x55a7a7f2, 0xfc7e7e82, 0x7a3d3d47,
+       0xc86464ac, 0xba5d5de7, 0x3219192b, 0xe6737395,
+       0xc06060a0, 0x19818198, 0x9e4f4fd1, 0xa3dcdc7f,
+       0x44222266, 0x542a2a7e, 0x3b9090ab, 0x0b888883,
+       0x8c4646ca, 0xc7eeee29, 0x6bb8b8d3, 0x2814143c,
+       0xa7dede79, 0xbc5e5ee2, 0x160b0b1d, 0xaddbdb76,
+       0xdbe0e03b, 0x64323256, 0x743a3a4e, 0x140a0a1e,
+       0x924949db, 0x0c06060a, 0x4824246c, 0xb85c5ce4,
+       0x9fc2c25d, 0xbdd3d36e, 0x43acacef, 0xc46262a6,
+       0x399191a8, 0x319595a4, 0xd3e4e437, 0xf279798b,
+       0xd5e7e732, 0x8bc8c843, 0x6e373759, 0xda6d6db7,
+       0x018d8d8c, 0xb1d5d564, 0x9c4e4ed2, 0x49a9a9e0,
+       0xd86c6cb4, 0xac5656fa, 0xf3f4f407, 0xcfeaea25,
+       0xca6565af, 0xf47a7a8e, 0x47aeaee9, 0x10080818,
+       0x6fbabad5, 0xf0787888, 0x4a25256f, 0x5c2e2e72,
+       0x381c1c24, 0x57a6a6f1, 0x73b4b4c7, 0x97c6c651,
+       0xcbe8e823, 0xa1dddd7c, 0xe874749c, 0x3e1f1f21,
+       0x964b4bdd, 0x61bdbddc, 0x0d8b8b86, 0x0f8a8a85,
+       0xe0707090, 0x7c3e3e42, 0x71b5b5c4, 0xcc6666aa,
+       0x904848d8, 0x06030305, 0xf7f6f601, 0x1c0e0e12,
+       0xc26161a3, 0x6a35355f, 0xae5757f9, 0x69b9b9d0,
+       0x17868691, 0x99c1c158, 0x3a1d1d27, 0x279e9eb9,
+       0xd9e1e138, 0xebf8f813, 0x2b9898b3, 0x22111133,
+       0xd26969bb, 0xa9d9d970, 0x078e8e89, 0x339494a7,
+       0x2d9b9bb6, 0x3c1e1e22, 0x15878792, 0xc9e9e920,
+       0x87cece49, 0xaa5555ff, 0x50282878, 0xa5dfdf7a,
+       0x038c8c8f, 0x59a1a1f8, 0x09898980, 0x1a0d0d17,
+       0x65bfbfda, 0xd7e6e631, 0x844242c6, 0xd06868b8,
+       0x824141c3, 0x299999b0, 0x5a2d2d77, 0x1e0f0f11,
+       0x7bb0b0cb, 0xa85454fc, 0x6dbbbbd6, 0x2c16163a);
+$code.=<<___;
+.byte  0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5
+.byte  0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76
+.byte  0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0
+.byte  0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0
+.byte  0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc
+.byte  0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15
+.byte  0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a
+.byte  0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75
+.byte  0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0
+.byte  0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84
+.byte  0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b
+.byte  0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf
+.byte  0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85
+.byte  0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8
+.byte  0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5
+.byte  0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2
+.byte  0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17
+.byte  0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73
+.byte  0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88
+.byte  0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb
+.byte  0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c
+.byte  0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79
+.byte  0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9
+.byte  0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08
+.byte  0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6
+.byte  0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a
+.byte  0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e
+.byte  0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e
+.byte  0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94
+.byte  0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf
+.byte  0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68
+.byte  0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
+___
+&_data_word(
+       0x51f4a750, 0x7e416553, 0x1a17a4c3, 0x3a275e96,
+       0x3bab6bcb, 0x1f9d45f1, 0xacfa58ab, 0x4be30393,
+       0x2030fa55, 0xad766df6, 0x88cc7691, 0xf5024c25,
+       0x4fe5d7fc, 0xc52acbd7, 0x26354480, 0xb562a38f,
+       0xdeb15a49, 0x25ba1b67, 0x45ea0e98, 0x5dfec0e1,
+       0xc32f7502, 0x814cf012, 0x8d4697a3, 0x6bd3f9c6,
+       0x038f5fe7, 0x15929c95, 0xbf6d7aeb, 0x955259da,
+       0xd4be832d, 0x587421d3, 0x49e06929, 0x8ec9c844,
+       0x75c2896a, 0xf48e7978, 0x99583e6b, 0x27b971dd,
+       0xbee14fb6, 0xf088ad17, 0xc920ac66, 0x7dce3ab4,
+       0x63df4a18, 0xe51a3182, 0x97513360, 0x62537f45,
+       0xb16477e0, 0xbb6bae84, 0xfe81a01c, 0xf9082b94,
+       0x70486858, 0x8f45fd19, 0x94de6c87, 0x527bf8b7,
+       0xab73d323, 0x724b02e2, 0xe31f8f57, 0x6655ab2a,
+       0xb2eb2807, 0x2fb5c203, 0x86c57b9a, 0xd33708a5,
+       0x302887f2, 0x23bfa5b2, 0x02036aba, 0xed16825c,
+       0x8acf1c2b, 0xa779b492, 0xf307f2f0, 0x4e69e2a1,
+       0x65daf4cd, 0x0605bed5, 0xd134621f, 0xc4a6fe8a,
+       0x342e539d, 0xa2f355a0, 0x058ae132, 0xa4f6eb75,
+       0x0b83ec39, 0x4060efaa, 0x5e719f06, 0xbd6e1051,
+       0x3e218af9, 0x96dd063d, 0xdd3e05ae, 0x4de6bd46,
+       0x91548db5, 0x71c45d05, 0x0406d46f, 0x605015ff,
+       0x1998fb24, 0xd6bde997, 0x894043cc, 0x67d99e77,
+       0xb0e842bd, 0x07898b88, 0xe7195b38, 0x79c8eedb,
+       0xa17c0a47, 0x7c420fe9, 0xf8841ec9, 0x00000000,
+       0x09808683, 0x322bed48, 0x1e1170ac, 0x6c5a724e,
+       0xfd0efffb, 0x0f853856, 0x3daed51e, 0x362d3927,
+       0x0a0fd964, 0x685ca621, 0x9b5b54d1, 0x24362e3a,
+       0x0c0a67b1, 0x9357e70f, 0xb4ee96d2, 0x1b9b919e,
+       0x80c0c54f, 0x61dc20a2, 0x5a774b69, 0x1c121a16,
+       0xe293ba0a, 0xc0a02ae5, 0x3c22e043, 0x121b171d,
+       0x0e090d0b, 0xf28bc7ad, 0x2db6a8b9, 0x141ea9c8,
+       0x57f11985, 0xaf75074c, 0xee99ddbb, 0xa37f60fd,
+       0xf701269f, 0x5c72f5bc, 0x44663bc5, 0x5bfb7e34,
+       0x8b432976, 0xcb23c6dc, 0xb6edfc68, 0xb8e4f163,
+       0xd731dcca, 0x42638510, 0x13972240, 0x84c61120,
+       0x854a247d, 0xd2bb3df8, 0xaef93211, 0xc729a16d,
+       0x1d9e2f4b, 0xdcb230f3, 0x0d8652ec, 0x77c1e3d0,
+       0x2bb3166c, 0xa970b999, 0x119448fa, 0x47e96422,
+       0xa8fc8cc4, 0xa0f03f1a, 0x567d2cd8, 0x223390ef,
+       0x87494ec7, 0xd938d1c1, 0x8ccaa2fe, 0x98d40b36,
+       0xa6f581cf, 0xa57ade28, 0xdab78e26, 0x3fadbfa4,
+       0x2c3a9de4, 0x5078920d, 0x6a5fcc9b, 0x547e4662,
+       0xf68d13c2, 0x90d8b8e8, 0x2e39f75e, 0x82c3aff5,
+       0x9f5d80be, 0x69d0937c, 0x6fd52da9, 0xcf2512b3,
+       0xc8ac993b, 0x10187da7, 0xe89c636e, 0xdb3bbb7b,
+       0xcd267809, 0x6e5918f4, 0xec9ab701, 0x834f9aa8,
+       0xe6956e65, 0xaaffe67e, 0x21bccf08, 0xef15e8e6,
+       0xbae79bd9, 0x4a6f36ce, 0xea9f09d4, 0x29b07cd6,
+       0x31a4b2af, 0x2a3f2331, 0xc6a59430, 0x35a266c0,
+       0x744ebc37, 0xfc82caa6, 0xe090d0b0, 0x33a7d815,
+       0xf104984a, 0x41ecdaf7, 0x7fcd500e, 0x1791f62f,
+       0x764dd68d, 0x43efb04d, 0xccaa4d54, 0xe49604df,
+       0x9ed1b5e3, 0x4c6a881b, 0xc12c1fb8, 0x4665517f,
+       0x9d5eea04, 0x018c355d, 0xfa877473, 0xfb0b412e,
+       0xb3671d5a, 0x92dbd252, 0xe9105633, 0x6dd64713,
+       0x9ad7618c, 0x37a10c7a, 0x59f8148e, 0xeb133c89,
+       0xcea927ee, 0xb761c935, 0xe11ce5ed, 0x7a47b13c,
+       0x9cd2df59, 0x55f2733f, 0x1814ce79, 0x73c737bf,
+       0x53f7cdea, 0x5ffdaa5b, 0xdf3d6f14, 0x7844db86,
+       0xcaaff381, 0xb968c43e, 0x3824342c, 0xc2a3405f,
+       0x161dc372, 0xbce2250c, 0x283c498b, 0xff0d9541,
+       0x39a80171, 0x080cb3de, 0xd8b4e49c, 0x6456c190,
+       0x7bcb8461, 0xd532b670, 0x486c5c74, 0xd0b85742);
+$code.=<<___;
+.byte  0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38
+.byte  0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb
+.byte  0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87
+.byte  0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb
+.byte  0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d
+.byte  0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e
+.byte  0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2
+.byte  0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25
+.byte  0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16
+.byte  0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92
+.byte  0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda
+.byte  0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84
+.byte  0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a
+.byte  0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06
+.byte  0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02
+.byte  0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b
+.byte  0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea
+.byte  0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73
+.byte  0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85
+.byte  0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e
+.byte  0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89
+.byte  0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b
+.byte  0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20
+.byte  0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4
+.byte  0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31
+.byte  0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f
+.byte  0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d
+.byte  0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef
+.byte  0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0
+.byte  0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61
+.byte  0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26
+.byte  0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d
+
+
+.globl .AES_encrypt
+.align 7
+.AES_encrypt:
+       mflr    r0
+       $STU    $sp,-$FRAME($sp)
+
+       $PUSH   r0,`$FRAME-$SIZE_T*21`($sp)
+       $PUSH   $toc,`$FRAME-$SIZE_T*20`($sp)
+       $PUSH   r13,`$FRAME-$SIZE_T*19`($sp)
+       $PUSH   r14,`$FRAME-$SIZE_T*18`($sp)
+       $PUSH   r15,`$FRAME-$SIZE_T*17`($sp)
+       $PUSH   r16,`$FRAME-$SIZE_T*16`($sp)
+       $PUSH   r17,`$FRAME-$SIZE_T*15`($sp)
+       $PUSH   r18,`$FRAME-$SIZE_T*14`($sp)
+       $PUSH   r19,`$FRAME-$SIZE_T*13`($sp)
+       $PUSH   r20,`$FRAME-$SIZE_T*12`($sp)
+       $PUSH   r21,`$FRAME-$SIZE_T*11`($sp)
+       $PUSH   r22,`$FRAME-$SIZE_T*10`($sp)
+       $PUSH   r23,`$FRAME-$SIZE_T*9`($sp)
+       $PUSH   r24,`$FRAME-$SIZE_T*8`($sp)
+       $PUSH   r25,`$FRAME-$SIZE_T*7`($sp)
+       $PUSH   r26,`$FRAME-$SIZE_T*6`($sp)
+       $PUSH   r27,`$FRAME-$SIZE_T*5`($sp)
+       $PUSH   r28,`$FRAME-$SIZE_T*4`($sp)
+       $PUSH   r29,`$FRAME-$SIZE_T*3`($sp)
+       $PUSH   r30,`$FRAME-$SIZE_T*2`($sp)
+       $PUSH   r31,`$FRAME-$SIZE_T*1`($sp)
+
+       lwz     $s0,0($inp)
+       lwz     $s1,4($inp)
+       lwz     $s2,8($inp)
+       lwz     $s3,12($inp)
+       bl      LAES_Te
+       bl      Lppc_AES_encrypt_compact
+       stw     $s0,0($out)
+       stw     $s1,4($out)
+       stw     $s2,8($out)
+       stw     $s3,12($out)
+
+       $POP    r0,`$FRAME-$SIZE_T*21`($sp)
+       $POP    $toc,`$FRAME-$SIZE_T*20`($sp)
+       $POP    r13,`$FRAME-$SIZE_T*19`($sp)
+       $POP    r14,`$FRAME-$SIZE_T*18`($sp)
+       $POP    r15,`$FRAME-$SIZE_T*17`($sp)
+       $POP    r16,`$FRAME-$SIZE_T*16`($sp)
+       $POP    r17,`$FRAME-$SIZE_T*15`($sp)
+       $POP    r18,`$FRAME-$SIZE_T*14`($sp)
+       $POP    r19,`$FRAME-$SIZE_T*13`($sp)
+       $POP    r20,`$FRAME-$SIZE_T*12`($sp)
+       $POP    r21,`$FRAME-$SIZE_T*11`($sp)
+       $POP    r22,`$FRAME-$SIZE_T*10`($sp)
+       $POP    r23,`$FRAME-$SIZE_T*9`($sp)
+       $POP    r24,`$FRAME-$SIZE_T*8`($sp)
+       $POP    r25,`$FRAME-$SIZE_T*7`($sp)
+       $POP    r26,`$FRAME-$SIZE_T*6`($sp)
+       $POP    r27,`$FRAME-$SIZE_T*5`($sp)
+       $POP    r28,`$FRAME-$SIZE_T*4`($sp)
+       $POP    r29,`$FRAME-$SIZE_T*3`($sp)
+       $POP    r30,`$FRAME-$SIZE_T*2`($sp)
+       $POP    r31,`$FRAME-$SIZE_T*1`($sp)
+       mtlr    r0
+       addi    $sp,$sp,$FRAME
+       blr
+
+.align 5
+Lppc_AES_encrypt:
+       lwz     $acc00,240($key)
+       lwz     $t0,0($key)
+       lwz     $t1,4($key)
+       lwz     $t2,8($key)
+       lwz     $t3,12($key)
+       addi    $Tbl1,$Tbl0,3
+       addi    $Tbl2,$Tbl0,2
+       addi    $Tbl3,$Tbl0,1
+       addi    $acc00,$acc00,-1
+       addi    $key,$key,16
+       xor     $s0,$s0,$t0
+       xor     $s1,$s1,$t1
+       xor     $s2,$s2,$t2
+       xor     $s3,$s3,$t3
+       mtctr   $acc00
+.align 4
+Lenc_loop:
+       rlwinm  $acc00,$s0,`32-24+3`,21,28
+       rlwinm  $acc01,$s1,`32-24+3`,21,28
+       rlwinm  $acc02,$s2,`32-24+3`,21,28
+       rlwinm  $acc03,$s3,`32-24+3`,21,28
+       lwz     $t0,0($key)
+       lwz     $t1,4($key)
+       rlwinm  $acc04,$s1,`32-16+3`,21,28
+       rlwinm  $acc05,$s2,`32-16+3`,21,28
+       lwz     $t2,8($key)
+       lwz     $t3,12($key)
+       rlwinm  $acc06,$s3,`32-16+3`,21,28
+       rlwinm  $acc07,$s0,`32-16+3`,21,28
+       lwzx    $acc00,$Tbl0,$acc00
+       lwzx    $acc01,$Tbl0,$acc01
+       rlwinm  $acc08,$s2,`32-8+3`,21,28
+       rlwinm  $acc09,$s3,`32-8+3`,21,28
+       lwzx    $acc02,$Tbl0,$acc02
+       lwzx    $acc03,$Tbl0,$acc03
+       rlwinm  $acc10,$s0,`32-8+3`,21,28
+       rlwinm  $acc11,$s1,`32-8+3`,21,28
+       lwzx    $acc04,$Tbl1,$acc04
+       lwzx    $acc05,$Tbl1,$acc05
+       rlwinm  $acc12,$s3,`0+3`,21,28
+       rlwinm  $acc13,$s0,`0+3`,21,28
+       lwzx    $acc06,$Tbl1,$acc06
+       lwzx    $acc07,$Tbl1,$acc07
+       rlwinm  $acc14,$s1,`0+3`,21,28
+       rlwinm  $acc15,$s2,`0+3`,21,28
+       lwzx    $acc08,$Tbl2,$acc08
+       lwzx    $acc09,$Tbl2,$acc09
+       xor     $t0,$t0,$acc00
+       xor     $t1,$t1,$acc01
+       lwzx    $acc10,$Tbl2,$acc10
+       lwzx    $acc11,$Tbl2,$acc11
+       xor     $t2,$t2,$acc02
+       xor     $t3,$t3,$acc03
+       lwzx    $acc12,$Tbl3,$acc12
+       lwzx    $acc13,$Tbl3,$acc13
+       xor     $t0,$t0,$acc04
+       xor     $t1,$t1,$acc05
+       lwzx    $acc14,$Tbl3,$acc14
+       lwzx    $acc15,$Tbl3,$acc15
+       xor     $t2,$t2,$acc06
+       xor     $t3,$t3,$acc07
+       xor     $t0,$t0,$acc08
+       xor     $t1,$t1,$acc09
+       xor     $t2,$t2,$acc10
+       xor     $t3,$t3,$acc11
+       xor     $s0,$t0,$acc12
+       xor     $s1,$t1,$acc13
+       xor     $s2,$t2,$acc14
+       xor     $s3,$t3,$acc15
+       addi    $key,$key,16
+       bdnz-   Lenc_loop
+
+       addi    $Tbl2,$Tbl0,2048
+       nop
+       lwz     $t0,0($key)
+       lwz     $t1,4($key)
+       rlwinm  $acc00,$s0,`32-24`,24,31
+       rlwinm  $acc01,$s1,`32-24`,24,31
+       lwz     $t2,8($key)
+       lwz     $t3,12($key)
+       rlwinm  $acc02,$s2,`32-24`,24,31
+       rlwinm  $acc03,$s3,`32-24`,24,31
+       lwz     $acc08,`2048+0`($Tbl0)  ! prefetch Te4
+       lwz     $acc09,`2048+32`($Tbl0)
+       rlwinm  $acc04,$s1,`32-16`,24,31
+       rlwinm  $acc05,$s2,`32-16`,24,31
+       lwz     $acc10,`2048+64`($Tbl0)
+       lwz     $acc11,`2048+96`($Tbl0)
+       rlwinm  $acc06,$s3,`32-16`,24,31
+       rlwinm  $acc07,$s0,`32-16`,24,31
+       lwz     $acc12,`2048+128`($Tbl0)
+       lwz     $acc13,`2048+160`($Tbl0)
+       rlwinm  $acc08,$s2,`32-8`,24,31
+       rlwinm  $acc09,$s3,`32-8`,24,31
+       lwz     $acc14,`2048+192`($Tbl0)
+       lwz     $acc15,`2048+224`($Tbl0)
+       rlwinm  $acc10,$s0,`32-8`,24,31
+       rlwinm  $acc11,$s1,`32-8`,24,31
+       lbzx    $acc00,$Tbl2,$acc00
+       lbzx    $acc01,$Tbl2,$acc01
+       rlwinm  $acc12,$s3,`0`,24,31
+       rlwinm  $acc13,$s0,`0`,24,31
+       lbzx    $acc02,$Tbl2,$acc02
+       lbzx    $acc03,$Tbl2,$acc03
+       rlwinm  $acc14,$s1,`0`,24,31
+       rlwinm  $acc15,$s2,`0`,24,31
+       lbzx    $acc04,$Tbl2,$acc04
+       lbzx    $acc05,$Tbl2,$acc05
+       rlwinm  $s0,$acc00,24,0,7
+       rlwinm  $s1,$acc01,24,0,7
+       lbzx    $acc06,$Tbl2,$acc06
+       lbzx    $acc07,$Tbl2,$acc07
+       rlwinm  $s2,$acc02,24,0,7
+       rlwinm  $s3,$acc03,24,0,7
+       lbzx    $acc08,$Tbl2,$acc08
+       lbzx    $acc09,$Tbl2,$acc09
+       rlwimi  $s0,$acc04,16,8,15
+       rlwimi  $s1,$acc05,16,8,15
+       lbzx    $acc10,$Tbl2,$acc10
+       lbzx    $acc11,$Tbl2,$acc11
+       rlwimi  $s2,$acc06,16,8,15
+       rlwimi  $s3,$acc07,16,8,15
+       lbzx    $acc12,$Tbl2,$acc12
+       lbzx    $acc13,$Tbl2,$acc13
+       rlwimi  $s0,$acc08,8,16,23
+       rlwimi  $s1,$acc09,8,16,23
+       lbzx    $acc14,$Tbl2,$acc14
+       lbzx    $acc15,$Tbl2,$acc15
+       rlwimi  $s2,$acc10,8,16,23
+       rlwimi  $s3,$acc11,8,16,23
+       or      $s0,$s0,$acc12
+       or      $s1,$s1,$acc13
+       or      $s2,$s2,$acc14
+       or      $s3,$s3,$acc15
+       xor     $s0,$s0,$t0
+       xor     $s1,$s1,$t1
+       xor     $s2,$s2,$t2
+       xor     $s3,$s3,$t3
+       blr
+
+.align 4
+Lppc_AES_encrypt_compact:
+       lwz     $acc00,240($key)
+       lwz     $t0,0($key)
+       lwz     $t1,4($key)
+       lwz     $t2,8($key)
+       lwz     $t3,12($key)
+       addi    $Tbl1,$Tbl0,2048
+       lis     $mask80,0x8080
+       lis     $mask1b,0x1b1b
+       addi    $key,$key,16
+       ori     $mask80,$mask80,0x8080
+       ori     $mask1b,$mask1b,0x1b1b
+       mtctr   $acc00
+.align 4
+Lenc_compact_loop:
+       xor     $s0,$s0,$t0
+       xor     $s1,$s1,$t1
+       xor     $s2,$s2,$t2
+       xor     $s3,$s3,$t3
+       rlwinm  $acc00,$s0,`32-24`,24,31
+       rlwinm  $acc01,$s1,`32-24`,24,31
+       rlwinm  $acc02,$s2,`32-24`,24,31
+       rlwinm  $acc03,$s3,`32-24`,24,31
+       rlwinm  $acc04,$s1,`32-16`,24,31
+       rlwinm  $acc05,$s2,`32-16`,24,31
+       rlwinm  $acc06,$s3,`32-16`,24,31
+       rlwinm  $acc07,$s0,`32-16`,24,31
+       lbzx    $acc00,$Tbl1,$acc00
+       lbzx    $acc01,$Tbl1,$acc01
+       rlwinm  $acc08,$s2,`32-8`,24,31
+       rlwinm  $acc09,$s3,`32-8`,24,31
+       lbzx    $acc02,$Tbl1,$acc02
+       lbzx    $acc03,$Tbl1,$acc03
+       rlwinm  $acc10,$s0,`32-8`,24,31
+       rlwinm  $acc11,$s1,`32-8`,24,31
+       lbzx    $acc04,$Tbl1,$acc04
+       lbzx    $acc05,$Tbl1,$acc05
+       rlwinm  $acc12,$s3,`0`,24,31
+       rlwinm  $acc13,$s0,`0`,24,31
+       lbzx    $acc06,$Tbl1,$acc06
+       lbzx    $acc07,$Tbl1,$acc07
+       rlwinm  $acc14,$s1,`0`,24,31
+       rlwinm  $acc15,$s2,`0`,24,31
+       lbzx    $acc08,$Tbl1,$acc08
+       lbzx    $acc09,$Tbl1,$acc09
+       rlwinm  $s0,$acc00,24,0,7
+       rlwinm  $s1,$acc01,24,0,7
+       lbzx    $acc10,$Tbl1,$acc10
+       lbzx    $acc11,$Tbl1,$acc11
+       rlwinm  $s2,$acc02,24,0,7
+       rlwinm  $s3,$acc03,24,0,7
+       lbzx    $acc12,$Tbl1,$acc12
+       lbzx    $acc13,$Tbl1,$acc13
+       rlwimi  $s0,$acc04,16,8,15
+       rlwimi  $s1,$acc05,16,8,15
+       lbzx    $acc14,$Tbl1,$acc14
+       lbzx    $acc15,$Tbl1,$acc15
+       rlwimi  $s2,$acc06,16,8,15
+       rlwimi  $s3,$acc07,16,8,15
+       rlwimi  $s0,$acc08,8,16,23
+       rlwimi  $s1,$acc09,8,16,23
+       rlwimi  $s2,$acc10,8,16,23
+       rlwimi  $s3,$acc11,8,16,23
+       lwz     $t0,0($key)
+       lwz     $t1,4($key)
+       or      $s0,$s0,$acc12
+       or      $s1,$s1,$acc13
+       lwz     $t2,8($key)
+       lwz     $t3,12($key)
+       or      $s2,$s2,$acc14
+       or      $s3,$s3,$acc15
+
+       addi    $key,$key,16
+       bdz     Lenc_compact_done
+
+       and     $acc00,$s0,$mask80      # r1=r0&0x80808080
+       and     $acc01,$s1,$mask80
+       and     $acc02,$s2,$mask80
+       and     $acc03,$s3,$mask80
+       srwi    $acc04,$acc00,7         # r1>>7
+       srwi    $acc05,$acc01,7
+       srwi    $acc06,$acc02,7
+       srwi    $acc07,$acc03,7
+       andc    $acc08,$s0,$mask80      # r0&0x7f7f7f7f
+       andc    $acc09,$s1,$mask80
+       andc    $acc10,$s2,$mask80
+       andc    $acc11,$s3,$mask80
+       sub     $acc00,$acc00,$acc04    # r1-(r1>>7)
+       sub     $acc01,$acc01,$acc05
+       sub     $acc02,$acc02,$acc06
+       sub     $acc03,$acc03,$acc07
+       add     $acc08,$acc08,$acc08    # (r0&0x7f7f7f7f)<<1
+       add     $acc09,$acc09,$acc09
+       add     $acc10,$acc10,$acc10
+       add     $acc11,$acc11,$acc11
+       and     $acc00,$acc00,$mask1b   # (r1-(r1>>7))&0x1b1b1b1b
+       and     $acc01,$acc01,$mask1b
+       and     $acc02,$acc02,$mask1b
+       and     $acc03,$acc03,$mask1b
+       xor     $acc00,$acc00,$acc08    # r2
+       xor     $acc01,$acc01,$acc09
+       xor     $acc02,$acc02,$acc10
+       xor     $acc03,$acc03,$acc11
+
+       rotlwi  $acc12,$s0,16           # ROTATE(r0,16)
+       rotlwi  $acc13,$s1,16
+       rotlwi  $acc14,$s2,16
+       rotlwi  $acc15,$s3,16
+       xor     $s0,$s0,$acc00          # r0^r2
+       xor     $s1,$s1,$acc01
+       xor     $s2,$s2,$acc02
+       xor     $s3,$s3,$acc03
+       rotrwi  $s0,$s0,24              # ROTATE(r2^r0,24)
+       rotrwi  $s1,$s1,24
+       rotrwi  $s2,$s2,24
+       rotrwi  $s3,$s3,24
+       xor     $s0,$s0,$acc00          # ROTATE(r2^r0,24)^r2
+       xor     $s1,$s1,$acc01
+       xor     $s2,$s2,$acc02
+       xor     $s3,$s3,$acc03
+       rotlwi  $acc08,$acc12,8         # ROTATE(r0,24)
+       rotlwi  $acc09,$acc13,8
+       rotlwi  $acc10,$acc14,8
+       rotlwi  $acc11,$acc15,8
+       xor     $s0,$s0,$acc12          #
+       xor     $s1,$s1,$acc13
+       xor     $s2,$s2,$acc14
+       xor     $s3,$s3,$acc15
+       xor     $s0,$s0,$acc08          #
+       xor     $s1,$s1,$acc09
+       xor     $s2,$s2,$acc10
+       xor     $s3,$s3,$acc11
+
+       b       Lenc_compact_loop
+.align 4
+Lenc_compact_done:
+       xor     $s0,$s0,$t0
+       xor     $s1,$s1,$t1
+       xor     $s2,$s2,$t2
+       xor     $s3,$s3,$t3
+       blr
+
+.globl .AES_decrypt
+.align 7
+.AES_decrypt:
+       mflr    r0
+       $STU    $sp,-$FRAME($sp)
+
+       $PUSH   r0,`$FRAME-$SIZE_T*21`($sp)
+       $PUSH   $toc,`$FRAME-$SIZE_T*20`($sp)
+       $PUSH   r13,`$FRAME-$SIZE_T*19`($sp)
+       $PUSH   r14,`$FRAME-$SIZE_T*18`($sp)
+       $PUSH   r15,`$FRAME-$SIZE_T*17`($sp)
+       $PUSH   r16,`$FRAME-$SIZE_T*16`($sp)
+       $PUSH   r17,`$FRAME-$SIZE_T*15`($sp)
+       $PUSH   r18,`$FRAME-$SIZE_T*14`($sp)
+       $PUSH   r19,`$FRAME-$SIZE_T*13`($sp)
+       $PUSH   r20,`$FRAME-$SIZE_T*12`($sp)
+       $PUSH   r21,`$FRAME-$SIZE_T*11`($sp)
+       $PUSH   r22,`$FRAME-$SIZE_T*10`($sp)
+       $PUSH   r23,`$FRAME-$SIZE_T*9`($sp)
+       $PUSH   r24,`$FRAME-$SIZE_T*8`($sp)
+       $PUSH   r25,`$FRAME-$SIZE_T*7`($sp)
+       $PUSH   r26,`$FRAME-$SIZE_T*6`($sp)
+       $PUSH   r27,`$FRAME-$SIZE_T*5`($sp)
+       $PUSH   r28,`$FRAME-$SIZE_T*4`($sp)
+       $PUSH   r29,`$FRAME-$SIZE_T*3`($sp)
+       $PUSH   r30,`$FRAME-$SIZE_T*2`($sp)
+       $PUSH   r31,`$FRAME-$SIZE_T*1`($sp)
+
+       lwz     $s0,0($inp)
+       lwz     $s1,4($inp)
+       lwz     $s2,8($inp)
+       lwz     $s3,12($inp)
+       bl      LAES_Td
+       bl      Lppc_AES_decrypt_compact
+       stw     $s0,0($out)
+       stw     $s1,4($out)
+       stw     $s2,8($out)
+       stw     $s3,12($out)
+
+       $POP    r0,`$FRAME-$SIZE_T*21`($sp)
+       $POP    $toc,`$FRAME-$SIZE_T*20`($sp)
+       $POP    r13,`$FRAME-$SIZE_T*19`($sp)
+       $POP    r14,`$FRAME-$SIZE_T*18`($sp)
+       $POP    r15,`$FRAME-$SIZE_T*17`($sp)
+       $POP    r16,`$FRAME-$SIZE_T*16`($sp)
+       $POP    r17,`$FRAME-$SIZE_T*15`($sp)
+       $POP    r18,`$FRAME-$SIZE_T*14`($sp)
+       $POP    r19,`$FRAME-$SIZE_T*13`($sp)
+       $POP    r20,`$FRAME-$SIZE_T*12`($sp)
+       $POP    r21,`$FRAME-$SIZE_T*11`($sp)
+       $POP    r22,`$FRAME-$SIZE_T*10`($sp)
+       $POP    r23,`$FRAME-$SIZE_T*9`($sp)
+       $POP    r24,`$FRAME-$SIZE_T*8`($sp)
+       $POP    r25,`$FRAME-$SIZE_T*7`($sp)
+       $POP    r26,`$FRAME-$SIZE_T*6`($sp)
+       $POP    r27,`$FRAME-$SIZE_T*5`($sp)
+       $POP    r28,`$FRAME-$SIZE_T*4`($sp)
+       $POP    r29,`$FRAME-$SIZE_T*3`($sp)
+       $POP    r30,`$FRAME-$SIZE_T*2`($sp)
+       $POP    r31,`$FRAME-$SIZE_T*1`($sp)
+       mtlr    r0
+       addi    $sp,$sp,$FRAME
+       blr
+
+.align 5
+Lppc_AES_decrypt:
+       lwz     $acc00,240($key)
+       lwz     $t0,0($key)
+       lwz     $t1,4($key)
+       lwz     $t2,8($key)
+       lwz     $t3,12($key)
+       addi    $Tbl1,$Tbl0,3
+       addi    $Tbl2,$Tbl0,2
+       addi    $Tbl3,$Tbl0,1
+       addi    $acc00,$acc00,-1
+       addi    $key,$key,16
+       xor     $s0,$s0,$t0
+       xor     $s1,$s1,$t1
+       xor     $s2,$s2,$t2
+       xor     $s3,$s3,$t3
+       mtctr   $acc00
+.align 4
+Ldec_loop:
+       rlwinm  $acc00,$s0,`32-24+3`,21,28
+       rlwinm  $acc01,$s1,`32-24+3`,21,28
+       rlwinm  $acc02,$s2,`32-24+3`,21,28
+       rlwinm  $acc03,$s3,`32-24+3`,21,28
+       lwz     $t0,0($key)
+       lwz     $t1,4($key)
+       rlwinm  $acc04,$s3,`32-16+3`,21,28
+       rlwinm  $acc05,$s0,`32-16+3`,21,28
+       lwz     $t2,8($key)
+       lwz     $t3,12($key)
+       rlwinm  $acc06,$s1,`32-16+3`,21,28
+       rlwinm  $acc07,$s2,`32-16+3`,21,28
+       lwzx    $acc00,$Tbl0,$acc00
+       lwzx    $acc01,$Tbl0,$acc01
+       rlwinm  $acc08,$s2,`32-8+3`,21,28
+       rlwinm  $acc09,$s3,`32-8+3`,21,28
+       lwzx    $acc02,$Tbl0,$acc02
+       lwzx    $acc03,$Tbl0,$acc03
+       rlwinm  $acc10,$s0,`32-8+3`,21,28
+       rlwinm  $acc11,$s1,`32-8+3`,21,28
+       lwzx    $acc04,$Tbl1,$acc04
+       lwzx    $acc05,$Tbl1,$acc05
+       rlwinm  $acc12,$s1,`0+3`,21,28
+       rlwinm  $acc13,$s2,`0+3`,21,28
+       lwzx    $acc06,$Tbl1,$acc06
+       lwzx    $acc07,$Tbl1,$acc07
+       rlwinm  $acc14,$s3,`0+3`,21,28
+       rlwinm  $acc15,$s0,`0+3`,21,28
+       lwzx    $acc08,$Tbl2,$acc08
+       lwzx    $acc09,$Tbl2,$acc09
+       xor     $t0,$t0,$acc00
+       xor     $t1,$t1,$acc01
+       lwzx    $acc10,$Tbl2,$acc10
+       lwzx    $acc11,$Tbl2,$acc11
+       xor     $t2,$t2,$acc02
+       xor     $t3,$t3,$acc03
+       lwzx    $acc12,$Tbl3,$acc12
+       lwzx    $acc13,$Tbl3,$acc13
+       xor     $t0,$t0,$acc04
+       xor     $t1,$t1,$acc05
+       lwzx    $acc14,$Tbl3,$acc14
+       lwzx    $acc15,$Tbl3,$acc15
+       xor     $t2,$t2,$acc06
+       xor     $t3,$t3,$acc07
+       xor     $t0,$t0,$acc08
+       xor     $t1,$t1,$acc09
+       xor     $t2,$t2,$acc10
+       xor     $t3,$t3,$acc11
+       xor     $s0,$t0,$acc12
+       xor     $s1,$t1,$acc13
+       xor     $s2,$t2,$acc14
+       xor     $s3,$t3,$acc15
+       addi    $key,$key,16
+       bdnz-   Ldec_loop
+
+       addi    $Tbl2,$Tbl0,2048
+       nop
+       lwz     $t0,0($key)
+       lwz     $t1,4($key)
+       rlwinm  $acc00,$s0,`32-24`,24,31
+       rlwinm  $acc01,$s1,`32-24`,24,31
+       lwz     $t2,8($key)
+       lwz     $t3,12($key)
+       rlwinm  $acc02,$s2,`32-24`,24,31
+       rlwinm  $acc03,$s3,`32-24`,24,31
+       lwz     $acc08,`2048+0`($Tbl0)  ! prefetch Td4
+       lwz     $acc09,`2048+32`($Tbl0)
+       rlwinm  $acc04,$s3,`32-16`,24,31
+       rlwinm  $acc05,$s0,`32-16`,24,31
+       lwz     $acc10,`2048+64`($Tbl0)
+       lwz     $acc11,`2048+96`($Tbl0)
+       lbzx    $acc00,$Tbl2,$acc00
+       lbzx    $acc01,$Tbl2,$acc01
+       lwz     $acc12,`2048+128`($Tbl0)
+       lwz     $acc13,`2048+160`($Tbl0)
+       rlwinm  $acc06,$s1,`32-16`,24,31
+       rlwinm  $acc07,$s2,`32-16`,24,31
+       lwz     $acc14,`2048+192`($Tbl0)
+       lwz     $acc15,`2048+224`($Tbl0)
+       rlwinm  $acc08,$s2,`32-8`,24,31
+       rlwinm  $acc09,$s3,`32-8`,24,31
+       lbzx    $acc02,$Tbl2,$acc02
+       lbzx    $acc03,$Tbl2,$acc03
+       rlwinm  $acc10,$s0,`32-8`,24,31
+       rlwinm  $acc11,$s1,`32-8`,24,31
+       lbzx    $acc04,$Tbl2,$acc04
+       lbzx    $acc05,$Tbl2,$acc05
+       rlwinm  $acc12,$s1,`0`,24,31
+       rlwinm  $acc13,$s2,`0`,24,31
+       lbzx    $acc06,$Tbl2,$acc06
+       lbzx    $acc07,$Tbl2,$acc07
+       rlwinm  $acc14,$s3,`0`,24,31
+       rlwinm  $acc15,$s0,`0`,24,31
+       lbzx    $acc08,$Tbl2,$acc08
+       lbzx    $acc09,$Tbl2,$acc09
+       rlwinm  $s0,$acc00,24,0,7
+       rlwinm  $s1,$acc01,24,0,7
+       lbzx    $acc10,$Tbl2,$acc10
+       lbzx    $acc11,$Tbl2,$acc11
+       rlwinm  $s2,$acc02,24,0,7
+       rlwinm  $s3,$acc03,24,0,7
+       lbzx    $acc12,$Tbl2,$acc12
+       lbzx    $acc13,$Tbl2,$acc13
+       rlwimi  $s0,$acc04,16,8,15
+       rlwimi  $s1,$acc05,16,8,15
+       lbzx    $acc14,$Tbl2,$acc14
+       lbzx    $acc15,$Tbl2,$acc15
+       rlwimi  $s2,$acc06,16,8,15
+       rlwimi  $s3,$acc07,16,8,15
+       rlwimi  $s0,$acc08,8,16,23
+       rlwimi  $s1,$acc09,8,16,23
+       rlwimi  $s2,$acc10,8,16,23
+       rlwimi  $s3,$acc11,8,16,23
+       or      $s0,$s0,$acc12
+       or      $s1,$s1,$acc13
+       or      $s2,$s2,$acc14
+       or      $s3,$s3,$acc15
+       xor     $s0,$s0,$t0
+       xor     $s1,$s1,$t1
+       xor     $s2,$s2,$t2
+       xor     $s3,$s3,$t3
+       blr
+
+.align 4
+Lppc_AES_decrypt_compact:
+       lwz     $acc00,240($key)
+       lwz     $t0,0($key)
+       lwz     $t1,4($key)
+       lwz     $t2,8($key)
+       lwz     $t3,12($key)
+       addi    $Tbl1,$Tbl0,2048
+       lis     $mask80,0x8080
+       lis     $mask1b,0x1b1b
+       addi    $key,$key,16
+       ori     $mask80,$mask80,0x8080
+       ori     $mask1b,$mask1b,0x1b1b
+___
+$code.=<<___ if ($SIZE_T==8);
+       insrdi  $mask80,$mask80,32,0
+       insrdi  $mask1b,$mask1b,32,0
+___
+$code.=<<___;
+       mtctr   $acc00
+.align 4
+Ldec_compact_loop:
+       xor     $s0,$s0,$t0
+       xor     $s1,$s1,$t1
+       xor     $s2,$s2,$t2
+       xor     $s3,$s3,$t3
+       rlwinm  $acc00,$s0,`32-24`,24,31
+       rlwinm  $acc01,$s1,`32-24`,24,31
+       rlwinm  $acc02,$s2,`32-24`,24,31
+       rlwinm  $acc03,$s3,`32-24`,24,31
+       rlwinm  $acc04,$s3,`32-16`,24,31
+       rlwinm  $acc05,$s0,`32-16`,24,31
+       rlwinm  $acc06,$s1,`32-16`,24,31
+       rlwinm  $acc07,$s2,`32-16`,24,31
+       lbzx    $acc00,$Tbl1,$acc00
+       lbzx    $acc01,$Tbl1,$acc01
+       rlwinm  $acc08,$s2,`32-8`,24,31
+       rlwinm  $acc09,$s3,`32-8`,24,31
+       lbzx    $acc02,$Tbl1,$acc02
+       lbzx    $acc03,$Tbl1,$acc03
+       rlwinm  $acc10,$s0,`32-8`,24,31
+       rlwinm  $acc11,$s1,`32-8`,24,31
+       lbzx    $acc04,$Tbl1,$acc04
+       lbzx    $acc05,$Tbl1,$acc05
+       rlwinm  $acc12,$s1,`0`,24,31
+       rlwinm  $acc13,$s2,`0`,24,31
+       lbzx    $acc06,$Tbl1,$acc06
+       lbzx    $acc07,$Tbl1,$acc07
+       rlwinm  $acc14,$s3,`0`,24,31
+       rlwinm  $acc15,$s0,`0`,24,31
+       lbzx    $acc08,$Tbl1,$acc08
+       lbzx    $acc09,$Tbl1,$acc09
+       rlwinm  $s0,$acc00,24,0,7
+       rlwinm  $s1,$acc01,24,0,7
+       lbzx    $acc10,$Tbl1,$acc10
+       lbzx    $acc11,$Tbl1,$acc11
+       rlwinm  $s2,$acc02,24,0,7
+       rlwinm  $s3,$acc03,24,0,7
+       lbzx    $acc12,$Tbl1,$acc12
+       lbzx    $acc13,$Tbl1,$acc13
+       rlwimi  $s0,$acc04,16,8,15
+       rlwimi  $s1,$acc05,16,8,15
+       lbzx    $acc14,$Tbl1,$acc14
+       lbzx    $acc15,$Tbl1,$acc15
+       rlwimi  $s2,$acc06,16,8,15
+       rlwimi  $s3,$acc07,16,8,15
+       rlwimi  $s0,$acc08,8,16,23
+       rlwimi  $s1,$acc09,8,16,23
+       rlwimi  $s2,$acc10,8,16,23
+       rlwimi  $s3,$acc11,8,16,23
+       lwz     $t0,0($key)
+       lwz     $t1,4($key)
+       or      $s0,$s0,$acc12
+       or      $s1,$s1,$acc13
+       lwz     $t2,8($key)
+       lwz     $t3,12($key)
+       or      $s2,$s2,$acc14
+       or      $s3,$s3,$acc15
+
+       addi    $key,$key,16
+       bdz     Ldec_compact_done
+___
+$code.=<<___ if ($SIZE_T==8);
+       # vectorized permutation improves decrypt performance by 10%
+       insrdi  $s0,$s1,32,0
+       insrdi  $s2,$s3,32,0
+
+       and     $acc00,$s0,$mask80      # r1=r0&0x80808080
+       and     $acc02,$s2,$mask80
+       srdi    $acc04,$acc00,7         # r1>>7
+       srdi    $acc06,$acc02,7
+       andc    $acc08,$s0,$mask80      # r0&0x7f7f7f7f
+       andc    $acc10,$s2,$mask80
+       sub     $acc00,$acc00,$acc04    # r1-(r1>>7)
+       sub     $acc02,$acc02,$acc06
+       add     $acc08,$acc08,$acc08    # (r0&0x7f7f7f7f)<<1
+       add     $acc10,$acc10,$acc10
+       and     $acc00,$acc00,$mask1b   # (r1-(r1>>7))&0x1b1b1b1b
+       and     $acc02,$acc02,$mask1b
+       xor     $acc00,$acc00,$acc08    # r2
+       xor     $acc02,$acc02,$acc10
+
+       and     $acc04,$acc00,$mask80   # r1=r2&0x80808080
+       and     $acc06,$acc02,$mask80
+       srdi    $acc08,$acc04,7         # r1>>7
+       srdi    $acc10,$acc06,7
+       andc    $acc12,$acc00,$mask80   # r2&0x7f7f7f7f
+       andc    $acc14,$acc02,$mask80
+       sub     $acc04,$acc04,$acc08    # r1-(r1>>7)
+       sub     $acc06,$acc06,$acc10
+       add     $acc12,$acc12,$acc12    # (r2&0x7f7f7f7f)<<1
+       add     $acc14,$acc14,$acc14
+       and     $acc04,$acc04,$mask1b   # (r1-(r1>>7))&0x1b1b1b1b
+       and     $acc06,$acc06,$mask1b
+       xor     $acc04,$acc04,$acc12    # r4
+       xor     $acc06,$acc06,$acc14
+
+       and     $acc08,$acc04,$mask80   # r1=r4&0x80808080
+       and     $acc10,$acc06,$mask80
+       srdi    $acc12,$acc08,7         # r1>>7
+       srdi    $acc14,$acc10,7
+       sub     $acc08,$acc08,$acc12    # r1-(r1>>7)
+       sub     $acc10,$acc10,$acc14
+       andc    $acc12,$acc04,$mask80   # r4&0x7f7f7f7f
+       andc    $acc14,$acc06,$mask80
+       add     $acc12,$acc12,$acc12    # (r4&0x7f7f7f7f)<<1
+       add     $acc14,$acc14,$acc14
+       and     $acc08,$acc08,$mask1b   # (r1-(r1>>7))&0x1b1b1b1b
+       and     $acc10,$acc10,$mask1b
+       xor     $acc08,$acc08,$acc12    # r8
+       xor     $acc10,$acc10,$acc14
+
+       xor     $acc00,$acc00,$s0       # r2^r0
+       xor     $acc02,$acc02,$s2
+       xor     $acc04,$acc04,$s0       # r4^r0
+       xor     $acc06,$acc06,$s2
+
+       extrdi  $acc01,$acc00,32,0
+       extrdi  $acc03,$acc02,32,0
+       extrdi  $acc05,$acc04,32,0
+       extrdi  $acc07,$acc06,32,0
+       extrdi  $acc09,$acc08,32,0
+       extrdi  $acc11,$acc10,32,0
+___
+$code.=<<___ if ($SIZE_T==4);
+       and     $acc00,$s0,$mask80      # r1=r0&0x80808080
+       and     $acc01,$s1,$mask80
+       and     $acc02,$s2,$mask80
+       and     $acc03,$s3,$mask80
+       srwi    $acc04,$acc00,7         # r1>>7
+       srwi    $acc05,$acc01,7
+       srwi    $acc06,$acc02,7
+       srwi    $acc07,$acc03,7
+       andc    $acc08,$s0,$mask80      # r0&0x7f7f7f7f
+       andc    $acc09,$s1,$mask80
+       andc    $acc10,$s2,$mask80
+       andc    $acc11,$s3,$mask80
+       sub     $acc00,$acc00,$acc04    # r1-(r1>>7)
+       sub     $acc01,$acc01,$acc05
+       sub     $acc02,$acc02,$acc06
+       sub     $acc03,$acc03,$acc07
+       add     $acc08,$acc08,$acc08    # (r0&0x7f7f7f7f)<<1
+       add     $acc09,$acc09,$acc09
+       add     $acc10,$acc10,$acc10
+       add     $acc11,$acc11,$acc11
+       and     $acc00,$acc00,$mask1b   # (r1-(r1>>7))&0x1b1b1b1b
+       and     $acc01,$acc01,$mask1b
+       and     $acc02,$acc02,$mask1b
+       and     $acc03,$acc03,$mask1b
+       xor     $acc00,$acc00,$acc08    # r2
+       xor     $acc01,$acc01,$acc09
+       xor     $acc02,$acc02,$acc10
+       xor     $acc03,$acc03,$acc11
+
+       and     $acc04,$acc00,$mask80   # r1=r2&0x80808080
+       and     $acc05,$acc01,$mask80
+       and     $acc06,$acc02,$mask80
+       and     $acc07,$acc03,$mask80
+       srwi    $acc08,$acc04,7         # r1>>7
+       srwi    $acc09,$acc05,7
+       srwi    $acc10,$acc06,7
+       srwi    $acc11,$acc07,7
+       andc    $acc12,$acc00,$mask80   # r2&0x7f7f7f7f
+       andc    $acc13,$acc01,$mask80
+       andc    $acc14,$acc02,$mask80
+       andc    $acc15,$acc03,$mask80
+       sub     $acc04,$acc04,$acc08    # r1-(r1>>7)
+       sub     $acc05,$acc05,$acc09
+       sub     $acc06,$acc06,$acc10
+       sub     $acc07,$acc07,$acc11
+       add     $acc12,$acc12,$acc12    # (r2&0x7f7f7f7f)<<1
+       add     $acc13,$acc13,$acc13
+       add     $acc14,$acc14,$acc14
+       add     $acc15,$acc15,$acc15
+       and     $acc04,$acc04,$mask1b   # (r1-(r1>>7))&0x1b1b1b1b
+       and     $acc05,$acc05,$mask1b
+       and     $acc06,$acc06,$mask1b
+       and     $acc07,$acc07,$mask1b
+       xor     $acc04,$acc04,$acc12    # r4
+       xor     $acc05,$acc05,$acc13
+       xor     $acc06,$acc06,$acc14
+       xor     $acc07,$acc07,$acc15
+
+       and     $acc08,$acc04,$mask80   # r1=r4&0x80808080
+       and     $acc09,$acc05,$mask80
+       and     $acc10,$acc06,$mask80
+       and     $acc11,$acc07,$mask80
+       srwi    $acc12,$acc08,7         # r1>>7
+       srwi    $acc13,$acc09,7
+       srwi    $acc14,$acc10,7
+       srwi    $acc15,$acc11,7
+       sub     $acc08,$acc08,$acc12    # r1-(r1>>7)
+       sub     $acc09,$acc09,$acc13
+       sub     $acc10,$acc10,$acc14
+       sub     $acc11,$acc11,$acc15
+       andc    $acc12,$acc04,$mask80   # r4&0x7f7f7f7f
+       andc    $acc13,$acc05,$mask80
+       andc    $acc14,$acc06,$mask80
+       andc    $acc15,$acc07,$mask80
+       add     $acc12,$acc12,$acc12    # (r4&0x7f7f7f7f)<<1
+       add     $acc13,$acc13,$acc13
+       add     $acc14,$acc14,$acc14
+       add     $acc15,$acc15,$acc15
+       and     $acc08,$acc08,$mask1b   # (r1-(r1>>7))&0x1b1b1b1b
+       and     $acc09,$acc09,$mask1b
+       and     $acc10,$acc10,$mask1b
+       and     $acc11,$acc11,$mask1b
+       xor     $acc08,$acc08,$acc12    # r8
+       xor     $acc09,$acc09,$acc13
+       xor     $acc10,$acc10,$acc14
+       xor     $acc11,$acc11,$acc15
+
+       xor     $acc00,$acc00,$s0       # r2^r0
+       xor     $acc01,$acc01,$s1
+       xor     $acc02,$acc02,$s2
+       xor     $acc03,$acc03,$s3
+       xor     $acc04,$acc04,$s0       # r4^r0
+       xor     $acc05,$acc05,$s1
+       xor     $acc06,$acc06,$s2
+       xor     $acc07,$acc07,$s3
+___
+$code.=<<___;
+       rotrwi  $s0,$s0,8               # = ROTATE(r0,8)
+       rotrwi  $s1,$s1,8
+       rotrwi  $s2,$s2,8
+       rotrwi  $s3,$s3,8
+       xor     $s0,$s0,$acc00          # ^= r2^r0
+       xor     $s1,$s1,$acc01
+       xor     $s2,$s2,$acc02
+       xor     $s3,$s3,$acc03
+       xor     $acc00,$acc00,$acc08
+       xor     $acc01,$acc01,$acc09
+       xor     $acc02,$acc02,$acc10
+       xor     $acc03,$acc03,$acc11
+       xor     $s0,$s0,$acc04          # ^= r4^r0
+       xor     $s1,$s1,$acc05
+       xor     $s2,$s2,$acc06
+       xor     $s3,$s3,$acc07
+       rotrwi  $acc00,$acc00,24
+       rotrwi  $acc01,$acc01,24
+       rotrwi  $acc02,$acc02,24
+       rotrwi  $acc03,$acc03,24
+       xor     $acc04,$acc04,$acc08
+       xor     $acc05,$acc05,$acc09
+       xor     $acc06,$acc06,$acc10
+       xor     $acc07,$acc07,$acc11
+       xor     $s0,$s0,$acc08          # ^= r8 [^((r4^r0)^(r2^r0)=r4^r2)]
+       xor     $s1,$s1,$acc09
+       xor     $s2,$s2,$acc10
+       xor     $s3,$s3,$acc11
+       rotrwi  $acc04,$acc04,16
+       rotrwi  $acc05,$acc05,16
+       rotrwi  $acc06,$acc06,16
+       rotrwi  $acc07,$acc07,16
+       xor     $s0,$s0,$acc00          # ^= ROTATE(r8^r2^r0,24)
+       xor     $s1,$s1,$acc01
+       xor     $s2,$s2,$acc02
+       xor     $s3,$s3,$acc03
+       rotrwi  $acc08,$acc08,8
+       rotrwi  $acc09,$acc09,8
+       rotrwi  $acc10,$acc10,8
+       rotrwi  $acc11,$acc11,8
+       xor     $s0,$s0,$acc04          # ^= ROTATE(r8^r4^r0,16)
+       xor     $s1,$s1,$acc05
+       xor     $s2,$s2,$acc06
+       xor     $s3,$s3,$acc07
+       xor     $s0,$s0,$acc08          # ^= ROTATE(r8,8)       
+       xor     $s1,$s1,$acc09  
+       xor     $s2,$s2,$acc10  
+       xor     $s3,$s3,$acc11  
+
+       b       Ldec_compact_loop
+.align 4
+Ldec_compact_done:
+       xor     $s0,$s0,$t0
+       xor     $s1,$s1,$t1
+       xor     $s2,$s2,$t2
+       xor     $s3,$s3,$t3
+       blr
+.long  0
+.asciz "AES for PPC, CRYPTOGAMS by <appro\@openssl.org>"
+.align 7
+___
+
+$code =~ s/\`([^\`]*)\`/eval $1/gem;
+print $code;
+close STDOUT;
diff --git a/deps/openssl/openssl/crypto/aes/asm/aes-s390x.pl b/deps/openssl/openssl/crypto/aes/asm/aes-s390x.pl
new file mode 100644 (file)
index 0000000..7e01889
--- /dev/null
@@ -0,0 +1,1339 @@
+#!/usr/bin/env perl
+
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+
+# AES for s390x.
+
+# April 2007.
+#
+# Software performance improvement over gcc-generated code is ~70% and
+# in absolute terms is ~73 cycles per byte processed with 128-bit key.
+# You're likely to exclaim "why so slow?" Keep in mind that z-CPUs are
+# *strictly* in-order execution and issued instruction [in this case
+# load value from memory is critical] has to complete before execution
+# flow proceeds. S-boxes are compressed to 2KB[+256B].
+#
+# As for hardware acceleration support. It's basically a "teaser," as
+# it can and should be improved in several ways. Most notably support
+# for CBC is not utilized, nor multiple blocks are ever processed.
+# Then software key schedule can be postponed till hardware support
+# detection... Performance improvement over assembler is reportedly
+# ~2.5x, but can reach >8x [naturally on larger chunks] if proper
+# support is implemented.
+
+# May 2007.
+#
+# Implement AES_set_[en|de]crypt_key. Key schedule setup is avoided
+# for 128-bit keys, if hardware support is detected.
+
+# Januray 2009.
+#
+# Add support for hardware AES192/256 and reschedule instructions to
+# minimize/avoid Address Generation Interlock hazard and to favour
+# dual-issue z10 pipeline. This gave ~25% improvement on z10 and
+# almost 50% on z9. The gain is smaller on z10, because being dual-
+# issue z10 makes it improssible to eliminate the interlock condition:
+# critial path is not long enough. Yet it spends ~24 cycles per byte
+# processed with 128-bit key.
+#
+# Unlike previous version hardware support detection takes place only
+# at the moment of key schedule setup, which is denoted in key->rounds.
+# This is done, because deferred key setup can't be made MT-safe, not
+# for key lengthes longer than 128 bits.
+#
+# Add AES_cbc_encrypt, which gives incredible performance improvement,
+# it was measured to be ~6.6x. It's less than previously mentioned 8x,
+# because software implementation was optimized.
+
+$softonly=0;   # allow hardware support
+
+$t0="%r0";     $mask="%r0";
+$t1="%r1";
+$t2="%r2";     $inp="%r2";
+$t3="%r3";     $out="%r3";     $bits="%r3";
+$key="%r4";
+$i1="%r5";
+$i2="%r6";
+$i3="%r7";
+$s0="%r8";
+$s1="%r9";
+$s2="%r10";
+$s3="%r11";
+$tbl="%r12";
+$rounds="%r13";
+$ra="%r14";
+$sp="%r15";
+
+sub _data_word()
+{ my $i;
+    while(defined($i=shift)) { $code.=sprintf".long\t0x%08x,0x%08x\n",$i,$i; }
+}
+
+$code=<<___;
+.text
+
+.type  AES_Te,\@object
+.align 256
+AES_Te:
+___
+&_data_word(
+       0xc66363a5, 0xf87c7c84, 0xee777799, 0xf67b7b8d,
+       0xfff2f20d, 0xd66b6bbd, 0xde6f6fb1, 0x91c5c554,
+       0x60303050, 0x02010103, 0xce6767a9, 0x562b2b7d,
+       0xe7fefe19, 0xb5d7d762, 0x4dababe6, 0xec76769a,
+       0x8fcaca45, 0x1f82829d, 0x89c9c940, 0xfa7d7d87,
+       0xeffafa15, 0xb25959eb, 0x8e4747c9, 0xfbf0f00b,
+       0x41adadec, 0xb3d4d467, 0x5fa2a2fd, 0x45afafea,
+       0x239c9cbf, 0x53a4a4f7, 0xe4727296, 0x9bc0c05b,
+       0x75b7b7c2, 0xe1fdfd1c, 0x3d9393ae, 0x4c26266a,
+       0x6c36365a, 0x7e3f3f41, 0xf5f7f702, 0x83cccc4f,
+       0x6834345c, 0x51a5a5f4, 0xd1e5e534, 0xf9f1f108,
+       0xe2717193, 0xabd8d873, 0x62313153, 0x2a15153f,
+       0x0804040c, 0x95c7c752, 0x46232365, 0x9dc3c35e,
+       0x30181828, 0x379696a1, 0x0a05050f, 0x2f9a9ab5,
+       0x0e070709, 0x24121236, 0x1b80809b, 0xdfe2e23d,
+       0xcdebeb26, 0x4e272769, 0x7fb2b2cd, 0xea75759f,
+       0x1209091b, 0x1d83839e, 0x582c2c74, 0x341a1a2e,
+       0x361b1b2d, 0xdc6e6eb2, 0xb45a5aee, 0x5ba0a0fb,
+       0xa45252f6, 0x763b3b4d, 0xb7d6d661, 0x7db3b3ce,
+       0x5229297b, 0xdde3e33e, 0x5e2f2f71, 0x13848497,
+       0xa65353f5, 0xb9d1d168, 0x00000000, 0xc1eded2c,
+       0x40202060, 0xe3fcfc1f, 0x79b1b1c8, 0xb65b5bed,
+       0xd46a6abe, 0x8dcbcb46, 0x67bebed9, 0x7239394b,
+       0x944a4ade, 0x984c4cd4, 0xb05858e8, 0x85cfcf4a,
+       0xbbd0d06b, 0xc5efef2a, 0x4faaaae5, 0xedfbfb16,
+       0x864343c5, 0x9a4d4dd7, 0x66333355, 0x11858594,
+       0x8a4545cf, 0xe9f9f910, 0x04020206, 0xfe7f7f81,
+       0xa05050f0, 0x783c3c44, 0x259f9fba, 0x4ba8a8e3,
+       0xa25151f3, 0x5da3a3fe, 0x804040c0, 0x058f8f8a,
+       0x3f9292ad, 0x219d9dbc, 0x70383848, 0xf1f5f504,
+       0x63bcbcdf, 0x77b6b6c1, 0xafdada75, 0x42212163,
+       0x20101030, 0xe5ffff1a, 0xfdf3f30e, 0xbfd2d26d,
+       0x81cdcd4c, 0x180c0c14, 0x26131335, 0xc3ecec2f,
+       0xbe5f5fe1, 0x359797a2, 0x884444cc, 0x2e171739,
+       0x93c4c457, 0x55a7a7f2, 0xfc7e7e82, 0x7a3d3d47,
+       0xc86464ac, 0xba5d5de7, 0x3219192b, 0xe6737395,
+       0xc06060a0, 0x19818198, 0x9e4f4fd1, 0xa3dcdc7f,
+       0x44222266, 0x542a2a7e, 0x3b9090ab, 0x0b888883,
+       0x8c4646ca, 0xc7eeee29, 0x6bb8b8d3, 0x2814143c,
+       0xa7dede79, 0xbc5e5ee2, 0x160b0b1d, 0xaddbdb76,
+       0xdbe0e03b, 0x64323256, 0x743a3a4e, 0x140a0a1e,
+       0x924949db, 0x0c06060a, 0x4824246c, 0xb85c5ce4,
+       0x9fc2c25d, 0xbdd3d36e, 0x43acacef, 0xc46262a6,
+       0x399191a8, 0x319595a4, 0xd3e4e437, 0xf279798b,
+       0xd5e7e732, 0x8bc8c843, 0x6e373759, 0xda6d6db7,
+       0x018d8d8c, 0xb1d5d564, 0x9c4e4ed2, 0x49a9a9e0,
+       0xd86c6cb4, 0xac5656fa, 0xf3f4f407, 0xcfeaea25,
+       0xca6565af, 0xf47a7a8e, 0x47aeaee9, 0x10080818,
+       0x6fbabad5, 0xf0787888, 0x4a25256f, 0x5c2e2e72,
+       0x381c1c24, 0x57a6a6f1, 0x73b4b4c7, 0x97c6c651,
+       0xcbe8e823, 0xa1dddd7c, 0xe874749c, 0x3e1f1f21,
+       0x964b4bdd, 0x61bdbddc, 0x0d8b8b86, 0x0f8a8a85,
+       0xe0707090, 0x7c3e3e42, 0x71b5b5c4, 0xcc6666aa,
+       0x904848d8, 0x06030305, 0xf7f6f601, 0x1c0e0e12,
+       0xc26161a3, 0x6a35355f, 0xae5757f9, 0x69b9b9d0,
+       0x17868691, 0x99c1c158, 0x3a1d1d27, 0x279e9eb9,
+       0xd9e1e138, 0xebf8f813, 0x2b9898b3, 0x22111133,
+       0xd26969bb, 0xa9d9d970, 0x078e8e89, 0x339494a7,
+       0x2d9b9bb6, 0x3c1e1e22, 0x15878792, 0xc9e9e920,
+       0x87cece49, 0xaa5555ff, 0x50282878, 0xa5dfdf7a,
+       0x038c8c8f, 0x59a1a1f8, 0x09898980, 0x1a0d0d17,
+       0x65bfbfda, 0xd7e6e631, 0x844242c6, 0xd06868b8,
+       0x824141c3, 0x299999b0, 0x5a2d2d77, 0x1e0f0f11,
+       0x7bb0b0cb, 0xa85454fc, 0x6dbbbbd6, 0x2c16163a);
+$code.=<<___;
+# Te4[256]
+.byte  0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5
+.byte  0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76
+.byte  0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0
+.byte  0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0
+.byte  0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc
+.byte  0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15
+.byte  0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a
+.byte  0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75
+.byte  0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0
+.byte  0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84
+.byte  0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b
+.byte  0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf
+.byte  0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85
+.byte  0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8
+.byte  0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5
+.byte  0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2
+.byte  0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17
+.byte  0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73
+.byte  0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88
+.byte  0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb
+.byte  0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c
+.byte  0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79
+.byte  0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9
+.byte  0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08
+.byte  0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6
+.byte  0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a
+.byte  0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e
+.byte  0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e
+.byte  0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94
+.byte  0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf
+.byte  0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68
+.byte  0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
+# rcon[]
+.long  0x01000000, 0x02000000, 0x04000000, 0x08000000
+.long  0x10000000, 0x20000000, 0x40000000, 0x80000000
+.long  0x1B000000, 0x36000000, 0, 0, 0, 0, 0, 0
+.align 256
+.size  AES_Te,.-AES_Te
+
+# void AES_encrypt(const unsigned char *inp, unsigned char *out,
+#               const AES_KEY *key) {
+.globl AES_encrypt
+.type  AES_encrypt,\@function
+AES_encrypt:
+___
+$code.=<<___ if (!$softonly);
+       l       %r0,240($key)
+       lhi     %r1,16
+       clr     %r0,%r1
+       jl      .Lesoft
+
+       la      %r1,0($key)
+       #la     %r2,0($inp)
+       la      %r4,0($out)
+       lghi    %r3,16          # single block length
+       .long   0xb92e0042      # km %r4,%r2
+       brc     1,.-4           # can this happen?
+       br      %r14
+.align 64
+.Lesoft:
+___
+$code.=<<___;
+       stmg    %r3,$ra,24($sp)
+
+       llgf    $s0,0($inp)
+       llgf    $s1,4($inp)
+       llgf    $s2,8($inp)
+       llgf    $s3,12($inp)
+
+       larl    $tbl,AES_Te
+       bras    $ra,_s390x_AES_encrypt
+
+       lg      $out,24($sp)
+       st      $s0,0($out)
+       st      $s1,4($out)
+       st      $s2,8($out)
+       st      $s3,12($out)
+
+       lmg     %r6,$ra,48($sp)
+       br      $ra
+.size  AES_encrypt,.-AES_encrypt
+
+.type   _s390x_AES_encrypt,\@function
+.align 16
+_s390x_AES_encrypt:
+       stg     $ra,152($sp)
+       x       $s0,0($key)
+       x       $s1,4($key)
+       x       $s2,8($key)
+       x       $s3,12($key)
+       l       $rounds,240($key)
+       llill   $mask,`0xff<<3`
+       aghi    $rounds,-1
+       j       .Lenc_loop
+.align 16
+.Lenc_loop:
+       sllg    $t1,$s0,`0+3`
+       srlg    $t2,$s0,`8-3`
+       srlg    $t3,$s0,`16-3`
+       srl     $s0,`24-3`
+       nr      $s0,$mask
+       ngr     $t1,$mask
+       nr      $t2,$mask
+       nr      $t3,$mask
+
+       srlg    $i1,$s1,`16-3`  # i0
+       sllg    $i2,$s1,`0+3`
+       srlg    $i3,$s1,`8-3`
+       srl     $s1,`24-3`
+       nr      $i1,$mask
+       nr      $s1,$mask
+       ngr     $i2,$mask
+       nr      $i3,$mask
+
+       l       $s0,0($s0,$tbl) # Te0[s0>>24]
+       l       $t1,1($t1,$tbl) # Te3[s0>>0]
+       l       $t2,2($t2,$tbl) # Te2[s0>>8]
+       l       $t3,3($t3,$tbl) # Te1[s0>>16]
+
+       x       $s0,3($i1,$tbl) # Te1[s1>>16]
+       l       $s1,0($s1,$tbl) # Te0[s1>>24]
+       x       $t2,1($i2,$tbl) # Te3[s1>>0]
+       x       $t3,2($i3,$tbl) # Te2[s1>>8]
+
+       srlg    $i1,$s2,`8-3`   # i0
+       srlg    $i2,$s2,`16-3`  # i1
+       nr      $i1,$mask
+       nr      $i2,$mask
+       sllg    $i3,$s2,`0+3`
+       srl     $s2,`24-3`
+       nr      $s2,$mask
+       ngr     $i3,$mask
+
+       xr      $s1,$t1
+       srlg    $ra,$s3,`8-3`   # i1
+       sllg    $t1,$s3,`0+3`   # i0
+       nr      $ra,$mask
+       la      $key,16($key)
+       ngr     $t1,$mask
+
+       x       $s0,2($i1,$tbl) # Te2[s2>>8]
+       x       $s1,3($i2,$tbl) # Te1[s2>>16]
+       l       $s2,0($s2,$tbl) # Te0[s2>>24]
+       x       $t3,1($i3,$tbl) # Te3[s2>>0]
+
+       srlg    $i3,$s3,`16-3`  # i2
+       xr      $s2,$t2
+       srl     $s3,`24-3`
+       nr      $i3,$mask
+       nr      $s3,$mask
+
+       x       $s0,0($key)
+       x       $s1,4($key)
+       x       $s2,8($key)
+       x       $t3,12($key)
+
+       x       $s0,1($t1,$tbl) # Te3[s3>>0]
+       x       $s1,2($ra,$tbl) # Te2[s3>>8]
+       x       $s2,3($i3,$tbl) # Te1[s3>>16]
+       l       $s3,0($s3,$tbl) # Te0[s3>>24]
+       xr      $s3,$t3
+
+       brct    $rounds,.Lenc_loop
+       .align  16
+
+       sllg    $t1,$s0,`0+3`
+       srlg    $t2,$s0,`8-3`
+       ngr     $t1,$mask
+       srlg    $t3,$s0,`16-3`
+       srl     $s0,`24-3`
+       nr      $s0,$mask
+       nr      $t2,$mask
+       nr      $t3,$mask
+
+       srlg    $i1,$s1,`16-3`  # i0
+       sllg    $i2,$s1,`0+3`
+       ngr     $i2,$mask
+       srlg    $i3,$s1,`8-3`
+       srl     $s1,`24-3`
+       nr      $i1,$mask
+       nr      $s1,$mask
+       nr      $i3,$mask
+
+       llgc    $s0,2($s0,$tbl) # Te4[s0>>24]
+       llgc    $t1,2($t1,$tbl) # Te4[s0>>0]
+       sll     $s0,24
+       llgc    $t2,2($t2,$tbl) # Te4[s0>>8]
+       llgc    $t3,2($t3,$tbl) # Te4[s0>>16]
+       sll     $t2,8
+       sll     $t3,16
+
+       llgc    $i1,2($i1,$tbl) # Te4[s1>>16]
+       llgc    $s1,2($s1,$tbl) # Te4[s1>>24]
+       llgc    $i2,2($i2,$tbl) # Te4[s1>>0]
+       llgc    $i3,2($i3,$tbl) # Te4[s1>>8]
+       sll     $i1,16
+       sll     $s1,24
+       sll     $i3,8
+       or      $s0,$i1
+       or      $s1,$t1
+       or      $t2,$i2
+       or      $t3,$i3
+       
+       srlg    $i1,$s2,`8-3`   # i0
+       srlg    $i2,$s2,`16-3`  # i1
+       nr      $i1,$mask
+       nr      $i2,$mask
+       sllg    $i3,$s2,`0+3`
+       srl     $s2,`24-3`
+       ngr     $i3,$mask
+       nr      $s2,$mask
+
+       sllg    $t1,$s3,`0+3`   # i0
+       srlg    $ra,$s3,`8-3`   # i1
+       ngr     $t1,$mask
+
+       llgc    $i1,2($i1,$tbl) # Te4[s2>>8]
+       llgc    $i2,2($i2,$tbl) # Te4[s2>>16]
+       sll     $i1,8
+       llgc    $s2,2($s2,$tbl) # Te4[s2>>24]
+       llgc    $i3,2($i3,$tbl) # Te4[s2>>0]
+       sll     $i2,16
+       nr      $ra,$mask
+       sll     $s2,24
+       or      $s0,$i1
+       or      $s1,$i2
+       or      $s2,$t2
+       or      $t3,$i3
+
+       srlg    $i3,$s3,`16-3`  # i2
+       srl     $s3,`24-3`
+       nr      $i3,$mask
+       nr      $s3,$mask
+
+       l       $t0,16($key)
+       l       $t2,20($key)
+
+       llgc    $i1,2($t1,$tbl) # Te4[s3>>0]
+       llgc    $i2,2($ra,$tbl) # Te4[s3>>8]
+       llgc    $i3,2($i3,$tbl) # Te4[s3>>16]
+       llgc    $s3,2($s3,$tbl) # Te4[s3>>24]
+       sll     $i2,8
+       sll     $i3,16
+       sll     $s3,24
+       or      $s0,$i1
+       or      $s1,$i2
+       or      $s2,$i3
+       or      $s3,$t3
+
+       lg      $ra,152($sp)
+       xr      $s0,$t0
+       xr      $s1,$t2
+       x       $s2,24($key)
+       x       $s3,28($key)
+
+       br      $ra     
+.size  _s390x_AES_encrypt,.-_s390x_AES_encrypt
+___
+
+$code.=<<___;
+.type  AES_Td,\@object
+.align 256
+AES_Td:
+___
+&_data_word(
+       0x51f4a750, 0x7e416553, 0x1a17a4c3, 0x3a275e96,
+       0x3bab6bcb, 0x1f9d45f1, 0xacfa58ab, 0x4be30393,
+       0x2030fa55, 0xad766df6, 0x88cc7691, 0xf5024c25,
+       0x4fe5d7fc, 0xc52acbd7, 0x26354480, 0xb562a38f,
+       0xdeb15a49, 0x25ba1b67, 0x45ea0e98, 0x5dfec0e1,
+       0xc32f7502, 0x814cf012, 0x8d4697a3, 0x6bd3f9c6,
+       0x038f5fe7, 0x15929c95, 0xbf6d7aeb, 0x955259da,
+       0xd4be832d, 0x587421d3, 0x49e06929, 0x8ec9c844,
+       0x75c2896a, 0xf48e7978, 0x99583e6b, 0x27b971dd,
+       0xbee14fb6, 0xf088ad17, 0xc920ac66, 0x7dce3ab4,
+       0x63df4a18, 0xe51a3182, 0x97513360, 0x62537f45,
+       0xb16477e0, 0xbb6bae84, 0xfe81a01c, 0xf9082b94,
+       0x70486858, 0x8f45fd19, 0x94de6c87, 0x527bf8b7,
+       0xab73d323, 0x724b02e2, 0xe31f8f57, 0x6655ab2a,
+       0xb2eb2807, 0x2fb5c203, 0x86c57b9a, 0xd33708a5,
+       0x302887f2, 0x23bfa5b2, 0x02036aba, 0xed16825c,
+       0x8acf1c2b, 0xa779b492, 0xf307f2f0, 0x4e69e2a1,
+       0x65daf4cd, 0x0605bed5, 0xd134621f, 0xc4a6fe8a,
+       0x342e539d, 0xa2f355a0, 0x058ae132, 0xa4f6eb75,
+       0x0b83ec39, 0x4060efaa, 0x5e719f06, 0xbd6e1051,
+       0x3e218af9, 0x96dd063d, 0xdd3e05ae, 0x4de6bd46,
+       0x91548db5, 0x71c45d05, 0x0406d46f, 0x605015ff,
+       0x1998fb24, 0xd6bde997, 0x894043cc, 0x67d99e77,
+       0xb0e842bd, 0x07898b88, 0xe7195b38, 0x79c8eedb,
+       0xa17c0a47, 0x7c420fe9, 0xf8841ec9, 0x00000000,
+       0x09808683, 0x322bed48, 0x1e1170ac, 0x6c5a724e,
+       0xfd0efffb, 0x0f853856, 0x3daed51e, 0x362d3927,
+       0x0a0fd964, 0x685ca621, 0x9b5b54d1, 0x24362e3a,
+       0x0c0a67b1, 0x9357e70f, 0xb4ee96d2, 0x1b9b919e,
+       0x80c0c54f, 0x61dc20a2, 0x5a774b69, 0x1c121a16,
+       0xe293ba0a, 0xc0a02ae5, 0x3c22e043, 0x121b171d,
+       0x0e090d0b, 0xf28bc7ad, 0x2db6a8b9, 0x141ea9c8,
+       0x57f11985, 0xaf75074c, 0xee99ddbb, 0xa37f60fd,
+       0xf701269f, 0x5c72f5bc, 0x44663bc5, 0x5bfb7e34,
+       0x8b432976, 0xcb23c6dc, 0xb6edfc68, 0xb8e4f163,
+       0xd731dcca, 0x42638510, 0x13972240, 0x84c61120,
+       0x854a247d, 0xd2bb3df8, 0xaef93211, 0xc729a16d,
+       0x1d9e2f4b, 0xdcb230f3, 0x0d8652ec, 0x77c1e3d0,
+       0x2bb3166c, 0xa970b999, 0x119448fa, 0x47e96422,
+       0xa8fc8cc4, 0xa0f03f1a, 0x567d2cd8, 0x223390ef,
+       0x87494ec7, 0xd938d1c1, 0x8ccaa2fe, 0x98d40b36,
+       0xa6f581cf, 0xa57ade28, 0xdab78e26, 0x3fadbfa4,
+       0x2c3a9de4, 0x5078920d, 0x6a5fcc9b, 0x547e4662,
+       0xf68d13c2, 0x90d8b8e8, 0x2e39f75e, 0x82c3aff5,
+       0x9f5d80be, 0x69d0937c, 0x6fd52da9, 0xcf2512b3,
+       0xc8ac993b, 0x10187da7, 0xe89c636e, 0xdb3bbb7b,
+       0xcd267809, 0x6e5918f4, 0xec9ab701, 0x834f9aa8,
+       0xe6956e65, 0xaaffe67e, 0x21bccf08, 0xef15e8e6,
+       0xbae79bd9, 0x4a6f36ce, 0xea9f09d4, 0x29b07cd6,
+       0x31a4b2af, 0x2a3f2331, 0xc6a59430, 0x35a266c0,
+       0x744ebc37, 0xfc82caa6, 0xe090d0b0, 0x33a7d815,
+       0xf104984a, 0x41ecdaf7, 0x7fcd500e, 0x1791f62f,
+       0x764dd68d, 0x43efb04d, 0xccaa4d54, 0xe49604df,
+       0x9ed1b5e3, 0x4c6a881b, 0xc12c1fb8, 0x4665517f,
+       0x9d5eea04, 0x018c355d, 0xfa877473, 0xfb0b412e,
+       0xb3671d5a, 0x92dbd252, 0xe9105633, 0x6dd64713,
+       0x9ad7618c, 0x37a10c7a, 0x59f8148e, 0xeb133c89,
+       0xcea927ee, 0xb761c935, 0xe11ce5ed, 0x7a47b13c,
+       0x9cd2df59, 0x55f2733f, 0x1814ce79, 0x73c737bf,
+       0x53f7cdea, 0x5ffdaa5b, 0xdf3d6f14, 0x7844db86,
+       0xcaaff381, 0xb968c43e, 0x3824342c, 0xc2a3405f,
+       0x161dc372, 0xbce2250c, 0x283c498b, 0xff0d9541,
+       0x39a80171, 0x080cb3de, 0xd8b4e49c, 0x6456c190,
+       0x7bcb8461, 0xd532b670, 0x486c5c74, 0xd0b85742);
+$code.=<<___;
+# Td4[256]
+.byte  0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38
+.byte  0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb
+.byte  0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87
+.byte  0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb
+.byte  0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d
+.byte  0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e
+.byte  0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2
+.byte  0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25
+.byte  0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16
+.byte  0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92
+.byte  0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda
+.byte  0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84
+.byte  0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a
+.byte  0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06
+.byte  0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02
+.byte  0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b
+.byte  0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea
+.byte  0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73
+.byte  0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85
+.byte  0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e
+.byte  0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89
+.byte  0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b
+.byte  0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20
+.byte  0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4
+.byte  0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31
+.byte  0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f
+.byte  0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d
+.byte  0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef
+.byte  0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0
+.byte  0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61
+.byte  0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26
+.byte  0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d
+.size  AES_Td,.-AES_Td
+
+# void AES_decrypt(const unsigned char *inp, unsigned char *out,
+#               const AES_KEY *key) {
+.globl AES_decrypt
+.type  AES_decrypt,\@function
+AES_decrypt:
+___
+$code.=<<___ if (!$softonly);
+       l       %r0,240($key)
+       lhi     %r1,16
+       clr     %r0,%r1
+       jl      .Ldsoft
+
+       la      %r1,0($key)
+       #la     %r2,0($inp)
+       la      %r4,0($out)
+       lghi    %r3,16          # single block length
+       .long   0xb92e0042      # km %r4,%r2
+       brc     1,.-4           # can this happen?
+       br      %r14
+.align 64
+.Ldsoft:
+___
+$code.=<<___;
+       stmg    %r3,$ra,24($sp)
+
+       llgf    $s0,0($inp)
+       llgf    $s1,4($inp)
+       llgf    $s2,8($inp)
+       llgf    $s3,12($inp)
+
+       larl    $tbl,AES_Td
+       bras    $ra,_s390x_AES_decrypt
+
+       lg      $out,24($sp)
+       st      $s0,0($out)
+       st      $s1,4($out)
+       st      $s2,8($out)
+       st      $s3,12($out)
+
+       lmg     %r6,$ra,48($sp)
+       br      $ra
+.size  AES_decrypt,.-AES_decrypt
+
+.type   _s390x_AES_decrypt,\@function
+.align 16
+_s390x_AES_decrypt:
+       stg     $ra,152($sp)
+       x       $s0,0($key)
+       x       $s1,4($key)
+       x       $s2,8($key)
+       x       $s3,12($key)
+       l       $rounds,240($key)
+       llill   $mask,`0xff<<3`
+       aghi    $rounds,-1
+       j       .Ldec_loop
+.align 16
+.Ldec_loop:
+       srlg    $t1,$s0,`16-3`
+       srlg    $t2,$s0,`8-3`
+       sllg    $t3,$s0,`0+3`
+       srl     $s0,`24-3`
+       nr      $s0,$mask
+       nr      $t1,$mask
+       nr      $t2,$mask
+       ngr     $t3,$mask
+
+       sllg    $i1,$s1,`0+3`   # i0
+       srlg    $i2,$s1,`16-3`
+       srlg    $i3,$s1,`8-3`
+       srl     $s1,`24-3`
+       ngr     $i1,$mask
+       nr      $s1,$mask
+       nr      $i2,$mask
+       nr      $i3,$mask
+
+       l       $s0,0($s0,$tbl) # Td0[s0>>24]
+       l       $t1,3($t1,$tbl) # Td1[s0>>16]
+       l       $t2,2($t2,$tbl) # Td2[s0>>8]
+       l       $t3,1($t3,$tbl) # Td3[s0>>0]
+
+       x       $s0,1($i1,$tbl) # Td3[s1>>0]
+       l       $s1,0($s1,$tbl) # Td0[s1>>24]
+       x       $t2,3($i2,$tbl) # Td1[s1>>16]
+       x       $t3,2($i3,$tbl) # Td2[s1>>8]
+
+       srlg    $i1,$s2,`8-3`   # i0
+       sllg    $i2,$s2,`0+3`   # i1
+       srlg    $i3,$s2,`16-3`
+       srl     $s2,`24-3`
+       nr      $i1,$mask
+       ngr     $i2,$mask
+       nr      $s2,$mask
+       nr      $i3,$mask
+
+       xr      $s1,$t1
+       srlg    $ra,$s3,`8-3`   # i1
+       srlg    $t1,$s3,`16-3`  # i0
+       nr      $ra,$mask
+       la      $key,16($key)
+       nr      $t1,$mask
+
+       x       $s0,2($i1,$tbl) # Td2[s2>>8]
+       x       $s1,1($i2,$tbl) # Td3[s2>>0]
+       l       $s2,0($s2,$tbl) # Td0[s2>>24]
+       x       $t3,3($i3,$tbl) # Td1[s2>>16]
+
+       sllg    $i3,$s3,`0+3`   # i2
+       srl     $s3,`24-3`
+       ngr     $i3,$mask
+       nr      $s3,$mask
+
+       xr      $s2,$t2
+       x       $s0,0($key)
+       x       $s1,4($key)
+       x       $s2,8($key)
+       x       $t3,12($key)
+
+       x       $s0,3($t1,$tbl) # Td1[s3>>16]
+       x       $s1,2($ra,$tbl) # Td2[s3>>8]
+       x       $s2,1($i3,$tbl) # Td3[s3>>0]
+       l       $s3,0($s3,$tbl) # Td0[s3>>24]
+       xr      $s3,$t3
+
+       brct    $rounds,.Ldec_loop
+       .align  16
+
+       l       $t1,`2048+0`($tbl)      # prefetch Td4
+       l       $t2,`2048+64`($tbl)
+       l       $t3,`2048+128`($tbl)
+       l       $i1,`2048+192`($tbl)
+       llill   $mask,0xff
+
+       srlg    $i3,$s0,24      # i0
+       srlg    $t1,$s0,16
+       srlg    $t2,$s0,8
+       nr      $s0,$mask       # i3
+       nr      $t1,$mask
+
+       srlg    $i1,$s1,24
+       nr      $t2,$mask
+       srlg    $i2,$s1,16
+       srlg    $ra,$s1,8
+       nr      $s1,$mask       # i0
+       nr      $i2,$mask
+       nr      $ra,$mask
+
+       llgc    $i3,2048($i3,$tbl)      # Td4[s0>>24]
+       llgc    $t1,2048($t1,$tbl)      # Td4[s0>>16]
+       llgc    $t2,2048($t2,$tbl)      # Td4[s0>>8]
+       sll     $t1,16
+       llgc    $t3,2048($s0,$tbl)      # Td4[s0>>0]
+       sllg    $s0,$i3,24
+       sll     $t2,8
+
+       llgc    $s1,2048($s1,$tbl)      # Td4[s1>>0]
+       llgc    $i1,2048($i1,$tbl)      # Td4[s1>>24]
+       llgc    $i2,2048($i2,$tbl)      # Td4[s1>>16]
+       sll     $i1,24
+       llgc    $i3,2048($ra,$tbl)      # Td4[s1>>8]
+       sll     $i2,16
+       sll     $i3,8
+       or      $s0,$s1
+       or      $t1,$i1
+       or      $t2,$i2
+       or      $t3,$i3
+
+       srlg    $i1,$s2,8       # i0
+       srlg    $i2,$s2,24
+       srlg    $i3,$s2,16
+       nr      $s2,$mask       # i1
+       nr      $i1,$mask
+       nr      $i3,$mask
+       llgc    $i1,2048($i1,$tbl)      # Td4[s2>>8]
+       llgc    $s1,2048($s2,$tbl)      # Td4[s2>>0]
+       llgc    $i2,2048($i2,$tbl)      # Td4[s2>>24]
+       llgc    $i3,2048($i3,$tbl)      # Td4[s2>>16]
+       sll     $i1,8
+       sll     $i2,24
+       or      $s0,$i1
+       sll     $i3,16
+       or      $t2,$i2
+       or      $t3,$i3
+
+       srlg    $i1,$s3,16      # i0
+       srlg    $i2,$s3,8       # i1
+       srlg    $i3,$s3,24
+       nr      $s3,$mask       # i2
+       nr      $i1,$mask
+       nr      $i2,$mask
+
+       lg      $ra,152($sp)
+       or      $s1,$t1
+       l       $t0,16($key)
+       l       $t1,20($key)
+
+       llgc    $i1,2048($i1,$tbl)      # Td4[s3>>16]
+       llgc    $i2,2048($i2,$tbl)      # Td4[s3>>8]
+       sll     $i1,16
+       llgc    $s2,2048($s3,$tbl)      # Td4[s3>>0]
+       llgc    $s3,2048($i3,$tbl)      # Td4[s3>>24]
+       sll     $i2,8
+       sll     $s3,24
+       or      $s0,$i1
+       or      $s1,$i2
+       or      $s2,$t2
+       or      $s3,$t3
+
+       xr      $s0,$t0
+       xr      $s1,$t1
+       x       $s2,24($key)
+       x       $s3,28($key)
+
+       br      $ra     
+.size  _s390x_AES_decrypt,.-_s390x_AES_decrypt
+___
+
+$code.=<<___;
+# void AES_set_encrypt_key(const unsigned char *in, int bits,
+#               AES_KEY *key) {
+.globl AES_set_encrypt_key
+.type  AES_set_encrypt_key,\@function
+.align 16
+AES_set_encrypt_key:
+       lghi    $t0,0
+       clgr    $inp,$t0
+       je      .Lminus1
+       clgr    $key,$t0
+       je      .Lminus1
+
+       lghi    $t0,128
+       clr     $bits,$t0
+       je      .Lproceed
+       lghi    $t0,192
+       clr     $bits,$t0
+       je      .Lproceed
+       lghi    $t0,256
+       clr     $bits,$t0
+       je      .Lproceed
+       lghi    %r2,-2
+       br      %r14
+
+.align 16
+.Lproceed:
+___
+$code.=<<___ if (!$softonly);
+       # convert bits to km code, [128,192,256]->[18,19,20]
+       lhi     %r5,-128
+       lhi     %r0,18
+       ar      %r5,$bits
+       srl     %r5,6
+       ar      %r5,%r0
+
+       larl    %r1,OPENSSL_s390xcap_P
+       lg      %r0,0(%r1)
+       tmhl    %r0,0x4000      # check for message-security assist
+       jz      .Lekey_internal
+
+       lghi    %r0,0           # query capability vector
+       la      %r1,16($sp)
+       .long   0xb92f0042      # kmc %r4,%r2
+
+       llihh   %r1,0x8000
+       srlg    %r1,%r1,0(%r5)
+       ng      %r1,16($sp)
+       jz      .Lekey_internal
+
+       lmg     %r0,%r1,0($inp) # just copy 128 bits...
+       stmg    %r0,%r1,0($key)
+       lhi     %r0,192
+       cr      $bits,%r0
+       jl      1f
+       lg      %r1,16($inp)
+       stg     %r1,16($key)
+       je      1f
+       lg      %r1,24($inp)
+       stg     %r1,24($key)
+1:     st      $bits,236($key) # save bits
+       st      %r5,240($key)   # save km code
+       lghi    %r2,0
+       br      %r14
+___
+$code.=<<___;
+.align 16
+.Lekey_internal:
+       stmg    %r6,%r13,48($sp)        # all non-volatile regs
+
+       larl    $tbl,AES_Te+2048
+
+       llgf    $s0,0($inp)
+       llgf    $s1,4($inp)
+       llgf    $s2,8($inp)
+       llgf    $s3,12($inp)
+       st      $s0,0($key)
+       st      $s1,4($key)
+       st      $s2,8($key)
+       st      $s3,12($key)
+       lghi    $t0,128
+       cr      $bits,$t0
+       jne     .Lnot128
+
+       llill   $mask,0xff
+       lghi    $t3,0                   # i=0
+       lghi    $rounds,10
+       st      $rounds,240($key)
+
+       llgfr   $t2,$s3                 # temp=rk[3]
+       srlg    $i1,$s3,8
+       srlg    $i2,$s3,16
+       srlg    $i3,$s3,24
+       nr      $t2,$mask
+       nr      $i1,$mask
+       nr      $i2,$mask
+
+.align 16
+.L128_loop:
+       la      $t2,0($t2,$tbl)
+       la      $i1,0($i1,$tbl)
+       la      $i2,0($i2,$tbl)
+       la      $i3,0($i3,$tbl)
+       icm     $t2,2,0($t2)            # Te4[rk[3]>>0]<<8
+       icm     $t2,4,0($i1)            # Te4[rk[3]>>8]<<16
+       icm     $t2,8,0($i2)            # Te4[rk[3]>>16]<<24
+       icm     $t2,1,0($i3)            # Te4[rk[3]>>24]
+       x       $t2,256($t3,$tbl)       # rcon[i]
+       xr      $s0,$t2                 # rk[4]=rk[0]^...
+       xr      $s1,$s0                 # rk[5]=rk[1]^rk[4]
+       xr      $s2,$s1                 # rk[6]=rk[2]^rk[5]
+       xr      $s3,$s2                 # rk[7]=rk[3]^rk[6]
+
+       llgfr   $t2,$s3                 # temp=rk[3]
+       srlg    $i1,$s3,8
+       srlg    $i2,$s3,16
+       nr      $t2,$mask
+       nr      $i1,$mask
+       srlg    $i3,$s3,24
+       nr      $i2,$mask
+
+       st      $s0,16($key)
+       st      $s1,20($key)
+       st      $s2,24($key)
+       st      $s3,28($key)
+       la      $key,16($key)           # key+=4
+       la      $t3,4($t3)              # i++
+       brct    $rounds,.L128_loop
+       lghi    %r2,0
+       lmg     %r6,%r13,48($sp)
+       br      $ra
+
+.align 16
+.Lnot128:
+       llgf    $t0,16($inp)
+       llgf    $t1,20($inp)
+       st      $t0,16($key)
+       st      $t1,20($key)
+       lghi    $t0,192
+       cr      $bits,$t0
+       jne     .Lnot192
+
+       llill   $mask,0xff
+       lghi    $t3,0                   # i=0
+       lghi    $rounds,12
+       st      $rounds,240($key)
+       lghi    $rounds,8
+
+       srlg    $i1,$t1,8
+       srlg    $i2,$t1,16
+       srlg    $i3,$t1,24
+       nr      $t1,$mask
+       nr      $i1,$mask
+       nr      $i2,$mask
+
+.align 16
+.L192_loop:
+       la      $t1,0($t1,$tbl)
+       la      $i1,0($i1,$tbl)
+       la      $i2,0($i2,$tbl)
+       la      $i3,0($i3,$tbl)
+       icm     $t1,2,0($t1)            # Te4[rk[5]>>0]<<8
+       icm     $t1,4,0($i1)            # Te4[rk[5]>>8]<<16
+       icm     $t1,8,0($i2)            # Te4[rk[5]>>16]<<24
+       icm     $t1,1,0($i3)            # Te4[rk[5]>>24]
+       x       $t1,256($t3,$tbl)       # rcon[i]
+       xr      $s0,$t1                 # rk[6]=rk[0]^...
+       xr      $s1,$s0                 # rk[7]=rk[1]^rk[6]
+       xr      $s2,$s1                 # rk[8]=rk[2]^rk[7]
+       xr      $s3,$s2                 # rk[9]=rk[3]^rk[8]
+
+       st      $s0,24($key)
+       st      $s1,28($key)
+       st      $s2,32($key)
+       st      $s3,36($key)
+       brct    $rounds,.L192_continue
+       lghi    %r2,0
+       lmg     %r6,%r13,48($sp)
+       br      $ra
+
+.align 16
+.L192_continue:
+       lgr     $t1,$s3
+       x       $t1,16($key)            # rk[10]=rk[4]^rk[9]
+       st      $t1,40($key)
+       x       $t1,20($key)            # rk[11]=rk[5]^rk[10]
+       st      $t1,44($key)
+
+       srlg    $i1,$t1,8
+       srlg    $i2,$t1,16
+       srlg    $i3,$t1,24
+       nr      $t1,$mask
+       nr      $i1,$mask
+       nr      $i2,$mask
+
+       la      $key,24($key)           # key+=6
+       la      $t3,4($t3)              # i++
+       j       .L192_loop
+
+.align 16
+.Lnot192:
+       llgf    $t0,24($inp)
+       llgf    $t1,28($inp)
+       st      $t0,24($key)
+       st      $t1,28($key)
+       llill   $mask,0xff
+       lghi    $t3,0                   # i=0
+       lghi    $rounds,14
+       st      $rounds,240($key)
+       lghi    $rounds,7
+
+       srlg    $i1,$t1,8
+       srlg    $i2,$t1,16
+       srlg    $i3,$t1,24
+       nr      $t1,$mask
+       nr      $i1,$mask
+       nr      $i2,$mask
+
+.align 16
+.L256_loop:
+       la      $t1,0($t1,$tbl)
+       la      $i1,0($i1,$tbl)
+       la      $i2,0($i2,$tbl)
+       la      $i3,0($i3,$tbl)
+       icm     $t1,2,0($t1)            # Te4[rk[7]>>0]<<8
+       icm     $t1,4,0($i1)            # Te4[rk[7]>>8]<<16
+       icm     $t1,8,0($i2)            # Te4[rk[7]>>16]<<24
+       icm     $t1,1,0($i3)            # Te4[rk[7]>>24]
+       x       $t1,256($t3,$tbl)       # rcon[i]
+       xr      $s0,$t1                 # rk[8]=rk[0]^...
+       xr      $s1,$s0                 # rk[9]=rk[1]^rk[8]
+       xr      $s2,$s1                 # rk[10]=rk[2]^rk[9]
+       xr      $s3,$s2                 # rk[11]=rk[3]^rk[10]
+       st      $s0,32($key)
+       st      $s1,36($key)
+       st      $s2,40($key)
+       st      $s3,44($key)
+       brct    $rounds,.L256_continue
+       lghi    %r2,0
+       lmg     %r6,%r13,48($sp)
+       br      $ra
+
+.align 16
+.L256_continue:
+       lgr     $t1,$s3                 # temp=rk[11]
+       srlg    $i1,$s3,8
+       srlg    $i2,$s3,16
+       srlg    $i3,$s3,24
+       nr      $t1,$mask
+       nr      $i1,$mask
+       nr      $i2,$mask
+       la      $t1,0($t1,$tbl)
+       la      $i1,0($i1,$tbl)
+       la      $i2,0($i2,$tbl)
+       la      $i3,0($i3,$tbl)
+       llgc    $t1,0($t1)              # Te4[rk[11]>>0]
+       icm     $t1,2,0($i1)            # Te4[rk[11]>>8]<<8
+       icm     $t1,4,0($i2)            # Te4[rk[11]>>16]<<16
+       icm     $t1,8,0($i3)            # Te4[rk[11]>>24]<<24
+       x       $t1,16($key)            # rk[12]=rk[4]^...
+       st      $t1,48($key)
+       x       $t1,20($key)            # rk[13]=rk[5]^rk[12]
+       st      $t1,52($key)
+       x       $t1,24($key)            # rk[14]=rk[6]^rk[13]
+       st      $t1,56($key)
+       x       $t1,28($key)            # rk[15]=rk[7]^rk[14]
+       st      $t1,60($key)
+
+       srlg    $i1,$t1,8
+       srlg    $i2,$t1,16
+       srlg    $i3,$t1,24
+       nr      $t1,$mask
+       nr      $i1,$mask
+       nr      $i2,$mask
+
+       la      $key,32($key)           # key+=8
+       la      $t3,4($t3)              # i++
+       j       .L256_loop
+
+.Lminus1:
+       lghi    %r2,-1
+       br      $ra
+.size  AES_set_encrypt_key,.-AES_set_encrypt_key
+
+# void AES_set_decrypt_key(const unsigned char *in, int bits,
+#               AES_KEY *key) {
+.globl AES_set_decrypt_key
+.type  AES_set_decrypt_key,\@function
+.align 16
+AES_set_decrypt_key:
+       stg     $key,32($sp)            # I rely on AES_set_encrypt_key to
+       stg     $ra,112($sp)            # save non-volatile registers!
+       bras    $ra,AES_set_encrypt_key
+       lg      $key,32($sp)
+       lg      $ra,112($sp)
+       ltgr    %r2,%r2
+       bnzr    $ra
+___
+$code.=<<___ if (!$softonly);
+       l       $t0,240($key)
+       lhi     $t1,16
+       cr      $t0,$t1
+       jl      .Lgo
+       oill    $t0,0x80        # set "decrypt" bit
+       st      $t0,240($key)
+       br      $ra
+
+.align 16
+.Ldkey_internal:
+       stg     $key,32($sp)
+       stg     $ra,40($sp)
+       bras    $ra,.Lekey_internal
+       lg      $key,32($sp)
+       lg      $ra,40($sp)
+___
+$code.=<<___;
+
+.Lgo:  llgf    $rounds,240($key)
+       la      $i1,0($key)
+       sllg    $i2,$rounds,4
+       la      $i2,0($i2,$key)
+       srl     $rounds,1
+       lghi    $t1,-16
+
+.align 16
+.Linv: lmg     $s0,$s1,0($i1)
+       lmg     $s2,$s3,0($i2)
+       stmg    $s0,$s1,0($i2)
+       stmg    $s2,$s3,0($i1)
+       la      $i1,16($i1)
+       la      $i2,0($t1,$i2)
+       brct    $rounds,.Linv
+___
+$mask80=$i1;
+$mask1b=$i2;
+$maskfe=$i3;
+$code.=<<___;
+       llgf    $rounds,240($key)
+       aghi    $rounds,-1
+       sll     $rounds,2       # (rounds-1)*4
+       llilh   $mask80,0x8080
+       llilh   $mask1b,0x1b1b
+       llilh   $maskfe,0xfefe
+       oill    $mask80,0x8080
+       oill    $mask1b,0x1b1b
+       oill    $maskfe,0xfefe
+
+.align 16
+.Lmix: l       $s0,16($key)    # tp1
+       lr      $s1,$s0
+       ngr     $s1,$mask80
+       srlg    $t1,$s1,7
+       slr     $s1,$t1
+       nr      $s1,$mask1b
+       sllg    $t1,$s0,1
+       nr      $t1,$maskfe
+       xr      $s1,$t1         # tp2
+
+       lr      $s2,$s1
+       ngr     $s2,$mask80
+       srlg    $t1,$s2,7
+       slr     $s2,$t1
+       nr      $s2,$mask1b
+       sllg    $t1,$s1,1
+       nr      $t1,$maskfe
+       xr      $s2,$t1         # tp4
+
+       lr      $s3,$s2
+       ngr     $s3,$mask80
+       srlg    $t1,$s3,7
+       slr     $s3,$t1
+       nr      $s3,$mask1b
+       sllg    $t1,$s2,1
+       nr      $t1,$maskfe
+       xr      $s3,$t1         # tp8
+
+       xr      $s1,$s0         # tp2^tp1
+       xr      $s2,$s0         # tp4^tp1
+       rll     $s0,$s0,24      # = ROTATE(tp1,8)
+       xr      $s2,$s3         # ^=tp8
+       xr      $s0,$s1         # ^=tp2^tp1
+       xr      $s1,$s3         # tp2^tp1^tp8
+       xr      $s0,$s2         # ^=tp4^tp1^tp8
+       rll     $s1,$s1,8
+       rll     $s2,$s2,16
+       xr      $s0,$s1         # ^= ROTATE(tp8^tp2^tp1,24)
+       rll     $s3,$s3,24
+       xr      $s0,$s2         # ^= ROTATE(tp8^tp4^tp1,16)
+       xr      $s0,$s3         # ^= ROTATE(tp8,8)
+
+       st      $s0,16($key)
+       la      $key,4($key)
+       brct    $rounds,.Lmix
+
+       lmg     %r6,%r13,48($sp)# as was saved by AES_set_encrypt_key!
+       lghi    %r2,0
+       br      $ra
+.size  AES_set_decrypt_key,.-AES_set_decrypt_key
+___
+
+#void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
+#                     size_t length, const AES_KEY *key,
+#                     unsigned char *ivec, const int enc)
+{
+my $inp="%r2";
+my $out="%r4"; # length and out are swapped
+my $len="%r3";
+my $key="%r5";
+my $ivp="%r6";
+
+$code.=<<___;
+.globl AES_cbc_encrypt
+.type  AES_cbc_encrypt,\@function
+.align 16
+AES_cbc_encrypt:
+       xgr     %r3,%r4         # flip %r3 and %r4, out and len
+       xgr     %r4,%r3
+       xgr     %r3,%r4
+___
+$code.=<<___ if (!$softonly);
+       lhi     %r0,16
+       cl      %r0,240($key)
+       jh      .Lcbc_software
+
+       lg      %r0,0($ivp)     # copy ivec
+       lg      %r1,8($ivp)
+       stmg    %r0,%r1,16($sp)
+       lmg     %r0,%r1,0($key) # copy key, cover 256 bit
+       stmg    %r0,%r1,32($sp)
+       lmg     %r0,%r1,16($key)
+       stmg    %r0,%r1,48($sp)
+       l       %r0,240($key)   # load kmc code
+       lghi    $key,15         # res=len%16, len-=res;
+       ngr     $key,$len
+       slgr    $len,$key
+       la      %r1,16($sp)     # parameter block - ivec || key
+       jz      .Lkmc_truncated
+       .long   0xb92f0042      # kmc %r4,%r2
+       brc     1,.-4           # pay attention to "partial completion"
+       ltr     $key,$key
+       jnz     .Lkmc_truncated
+.Lkmc_done:
+       lmg     %r0,%r1,16($sp) # copy ivec to caller
+       stg     %r0,0($ivp)
+       stg     %r1,8($ivp)
+       br      $ra
+.align 16
+.Lkmc_truncated:
+       ahi     $key,-1         # it's the way it's encoded in mvc
+       tmll    %r0,0x80
+       jnz     .Lkmc_truncated_dec
+       lghi    %r1,0
+       stg     %r1,128($sp)
+       stg     %r1,136($sp)
+       bras    %r1,1f
+       mvc     128(1,$sp),0($inp)
+1:     ex      $key,0(%r1)
+       la      %r1,16($sp)     # restore parameter block
+       la      $inp,128($sp)
+       lghi    $len,16
+       .long   0xb92f0042      # kmc %r4,%r2
+       j       .Lkmc_done
+.align 16
+.Lkmc_truncated_dec:
+       stg     $out,64($sp)
+       la      $out,128($sp)
+       lghi    $len,16
+       .long   0xb92f0042      # kmc %r4,%r2
+       lg      $out,64($sp)
+       bras    %r1,2f
+       mvc     0(1,$out),128($sp)
+2:     ex      $key,0(%r1)
+       j       .Lkmc_done
+.align 16
+.Lcbc_software:
+___
+$code.=<<___;
+       stmg    $key,$ra,40($sp)
+       lhi     %r0,0
+       cl      %r0,164($sp)
+       je      .Lcbc_decrypt
+
+       larl    $tbl,AES_Te
+
+       llgf    $s0,0($ivp)
+       llgf    $s1,4($ivp)
+       llgf    $s2,8($ivp)
+       llgf    $s3,12($ivp)
+
+       lghi    $t0,16
+       slgr    $len,$t0
+       brc     4,.Lcbc_enc_tail        # if borrow
+.Lcbc_enc_loop:
+       stmg    $inp,$out,16($sp)
+       x       $s0,0($inp)
+       x       $s1,4($inp)
+       x       $s2,8($inp)
+       x       $s3,12($inp)
+       lgr     %r4,$key
+
+       bras    $ra,_s390x_AES_encrypt
+
+       lmg     $inp,$key,16($sp)
+       st      $s0,0($out)
+       st      $s1,4($out)
+       st      $s2,8($out)
+       st      $s3,12($out)
+
+       la      $inp,16($inp)
+       la      $out,16($out)
+       lghi    $t0,16
+       ltgr    $len,$len
+       jz      .Lcbc_enc_done
+       slgr    $len,$t0
+       brc     4,.Lcbc_enc_tail        # if borrow
+       j       .Lcbc_enc_loop
+.align 16
+.Lcbc_enc_done:
+       lg      $ivp,48($sp)
+       st      $s0,0($ivp)
+       st      $s1,4($ivp)     
+       st      $s2,8($ivp)
+       st      $s3,12($ivp)
+
+       lmg     %r7,$ra,56($sp)
+       br      $ra
+
+.align 16
+.Lcbc_enc_tail:
+       aghi    $len,15
+       lghi    $t0,0
+       stg     $t0,128($sp)
+       stg     $t0,136($sp)
+       bras    $t1,3f
+       mvc     128(1,$sp),0($inp)
+3:     ex      $len,0($t1)
+       lghi    $len,0
+       la      $inp,128($sp)
+       j       .Lcbc_enc_loop
+
+.align 16
+.Lcbc_decrypt:
+       larl    $tbl,AES_Td
+
+       lg      $t0,0($ivp)
+       lg      $t1,8($ivp)
+       stmg    $t0,$t1,128($sp)
+
+.Lcbc_dec_loop:
+       stmg    $inp,$out,16($sp)
+       llgf    $s0,0($inp)
+       llgf    $s1,4($inp)
+       llgf    $s2,8($inp)
+       llgf    $s3,12($inp)
+       lgr     %r4,$key
+
+       bras    $ra,_s390x_AES_decrypt
+
+       lmg     $inp,$key,16($sp)
+       sllg    $s0,$s0,32
+       sllg    $s2,$s2,32
+       lr      $s0,$s1
+       lr      $s2,$s3
+
+       lg      $t0,0($inp)
+       lg      $t1,8($inp)
+       xg      $s0,128($sp)
+       xg      $s2,136($sp)
+       lghi    $s1,16
+       slgr    $len,$s1
+       brc     4,.Lcbc_dec_tail        # if borrow
+       brc     2,.Lcbc_dec_done        # if zero
+       stg     $s0,0($out)
+       stg     $s2,8($out)
+       stmg    $t0,$t1,128($sp)
+
+       la      $inp,16($inp)
+       la      $out,16($out)
+       j       .Lcbc_dec_loop
+
+.Lcbc_dec_done:
+       stg     $s0,0($out)
+       stg     $s2,8($out)
+.Lcbc_dec_exit:
+       lmg     $ivp,$ra,48($sp)
+       stmg    $t0,$t1,0($ivp)
+
+       br      $ra
+
+.align 16
+.Lcbc_dec_tail:
+       aghi    $len,15
+       stg     $s0,128($sp)
+       stg     $s2,136($sp)
+       bras    $s1,4f
+       mvc     0(1,$out),128($sp)
+4:     ex      $len,0($s1)
+       j       .Lcbc_dec_exit
+.size  AES_cbc_encrypt,.-AES_cbc_encrypt
+.comm  OPENSSL_s390xcap_P,8,8
+___
+}
+$code.=<<___;
+.string        "AES for s390x, CRYPTOGAMS by <appro\@openssl.org>"
+___
+
+$code =~ s/\`([^\`]*)\`/eval $1/gem;
+print $code;
diff --git a/deps/openssl/openssl/crypto/aes/asm/aes-sparcv9.pl b/deps/openssl/openssl/crypto/aes/asm/aes-sparcv9.pl
new file mode 100644 (file)
index 0000000..c57b3a2
--- /dev/null
@@ -0,0 +1,1181 @@
+#!/usr/bin/env perl
+#
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. Rights for redistribution and usage in source and binary
+# forms are granted according to the OpenSSL license.
+# ====================================================================
+#
+# Version 1.1
+#
+# The major reason for undertaken effort was to mitigate the hazard of
+# cache-timing attack. This is [currently and initially!] addressed in
+# two ways. 1. S-boxes are compressed from 5KB to 2KB+256B size each.
+# 2. References to them are scheduled for L2 cache latency, meaning
+# that the tables don't have to reside in L1 cache. Once again, this
+# is an initial draft and one should expect more countermeasures to
+# be implemented...
+#
+# Version 1.1 prefetches T[ed]4 in order to mitigate attack on last
+# round.
+#
+# Even though performance was not the primary goal [on the contrary,
+# extra shifts "induced" by compressed S-box and longer loop epilogue
+# "induced" by scheduling for L2 have negative effect on performance],
+# the code turned out to run in ~23 cycles per processed byte en-/
+# decrypted with 128-bit key. This is pretty good result for code
+# with mentioned qualities and UltraSPARC core. Compared to Sun C
+# generated code my encrypt procedure runs just few percents faster,
+# while decrypt one - whole 50% faster [yes, Sun C failed to generate
+# optimal decrypt procedure]. Compared to GNU C generated code both
+# procedures are more than 60% faster:-)
+
+$bits=32;
+for (@ARGV)    { $bits=64 if (/\-m64/ || /\-xarch\=v9/); }
+if ($bits==64) { $bias=2047; $frame=192; }
+else           { $bias=0;    $frame=112; }
+$locals=16;
+
+$acc0="%l0";
+$acc1="%o0";
+$acc2="%o1";
+$acc3="%o2";
+
+$acc4="%l1";
+$acc5="%o3";
+$acc6="%o4";
+$acc7="%o5";
+
+$acc8="%l2";
+$acc9="%o7";
+$acc10="%g1";
+$acc11="%g2";
+
+$acc12="%l3";
+$acc13="%g3";
+$acc14="%g4";
+$acc15="%g5";
+
+$t0="%l4";
+$t1="%l5";
+$t2="%l6";
+$t3="%l7";
+
+$s0="%i0";
+$s1="%i1";
+$s2="%i2";
+$s3="%i3";
+$tbl="%i4";
+$key="%i5";
+$rounds="%i7"; # aliases with return address, which is off-loaded to stack
+
+sub _data_word()
+{ my $i;
+    while(defined($i=shift)) { $code.=sprintf"\t.long\t0x%08x,0x%08x\n",$i,$i; }
+}
+
+$code.=<<___ if ($bits==64);
+.register      %g2,#scratch
+.register      %g3,#scratch
+___
+$code.=<<___;
+.section       ".text",#alloc,#execinstr
+
+.align 256
+AES_Te:
+___
+&_data_word(
+       0xc66363a5, 0xf87c7c84, 0xee777799, 0xf67b7b8d,
+       0xfff2f20d, 0xd66b6bbd, 0xde6f6fb1, 0x91c5c554,
+       0x60303050, 0x02010103, 0xce6767a9, 0x562b2b7d,
+       0xe7fefe19, 0xb5d7d762, 0x4dababe6, 0xec76769a,
+       0x8fcaca45, 0x1f82829d, 0x89c9c940, 0xfa7d7d87,
+       0xeffafa15, 0xb25959eb, 0x8e4747c9, 0xfbf0f00b,
+       0x41adadec, 0xb3d4d467, 0x5fa2a2fd, 0x45afafea,
+       0x239c9cbf, 0x53a4a4f7, 0xe4727296, 0x9bc0c05b,
+       0x75b7b7c2, 0xe1fdfd1c, 0x3d9393ae, 0x4c26266a,
+       0x6c36365a, 0x7e3f3f41, 0xf5f7f702, 0x83cccc4f,
+       0x6834345c, 0x51a5a5f4, 0xd1e5e534, 0xf9f1f108,
+       0xe2717193, 0xabd8d873, 0x62313153, 0x2a15153f,
+       0x0804040c, 0x95c7c752, 0x46232365, 0x9dc3c35e,
+       0x30181828, 0x379696a1, 0x0a05050f, 0x2f9a9ab5,
+       0x0e070709, 0x24121236, 0x1b80809b, 0xdfe2e23d,
+       0xcdebeb26, 0x4e272769, 0x7fb2b2cd, 0xea75759f,
+       0x1209091b, 0x1d83839e, 0x582c2c74, 0x341a1a2e,
+       0x361b1b2d, 0xdc6e6eb2, 0xb45a5aee, 0x5ba0a0fb,
+       0xa45252f6, 0x763b3b4d, 0xb7d6d661, 0x7db3b3ce,
+       0x5229297b, 0xdde3e33e, 0x5e2f2f71, 0x13848497,
+       0xa65353f5, 0xb9d1d168, 0x00000000, 0xc1eded2c,
+       0x40202060, 0xe3fcfc1f, 0x79b1b1c8, 0xb65b5bed,
+       0xd46a6abe, 0x8dcbcb46, 0x67bebed9, 0x7239394b,
+       0x944a4ade, 0x984c4cd4, 0xb05858e8, 0x85cfcf4a,
+       0xbbd0d06b, 0xc5efef2a, 0x4faaaae5, 0xedfbfb16,
+       0x864343c5, 0x9a4d4dd7, 0x66333355, 0x11858594,
+       0x8a4545cf, 0xe9f9f910, 0x04020206, 0xfe7f7f81,
+       0xa05050f0, 0x783c3c44, 0x259f9fba, 0x4ba8a8e3,
+       0xa25151f3, 0x5da3a3fe, 0x804040c0, 0x058f8f8a,
+       0x3f9292ad, 0x219d9dbc, 0x70383848, 0xf1f5f504,
+       0x63bcbcdf, 0x77b6b6c1, 0xafdada75, 0x42212163,
+       0x20101030, 0xe5ffff1a, 0xfdf3f30e, 0xbfd2d26d,
+       0x81cdcd4c, 0x180c0c14, 0x26131335, 0xc3ecec2f,
+       0xbe5f5fe1, 0x359797a2, 0x884444cc, 0x2e171739,
+       0x93c4c457, 0x55a7a7f2, 0xfc7e7e82, 0x7a3d3d47,
+       0xc86464ac, 0xba5d5de7, 0x3219192b, 0xe6737395,
+       0xc06060a0, 0x19818198, 0x9e4f4fd1, 0xa3dcdc7f,
+       0x44222266, 0x542a2a7e, 0x3b9090ab, 0x0b888883,
+       0x8c4646ca, 0xc7eeee29, 0x6bb8b8d3, 0x2814143c,
+       0xa7dede79, 0xbc5e5ee2, 0x160b0b1d, 0xaddbdb76,
+       0xdbe0e03b, 0x64323256, 0x743a3a4e, 0x140a0a1e,
+       0x924949db, 0x0c06060a, 0x4824246c, 0xb85c5ce4,
+       0x9fc2c25d, 0xbdd3d36e, 0x43acacef, 0xc46262a6,
+       0x399191a8, 0x319595a4, 0xd3e4e437, 0xf279798b,
+       0xd5e7e732, 0x8bc8c843, 0x6e373759, 0xda6d6db7,
+       0x018d8d8c, 0xb1d5d564, 0x9c4e4ed2, 0x49a9a9e0,
+       0xd86c6cb4, 0xac5656fa, 0xf3f4f407, 0xcfeaea25,
+       0xca6565af, 0xf47a7a8e, 0x47aeaee9, 0x10080818,
+       0x6fbabad5, 0xf0787888, 0x4a25256f, 0x5c2e2e72,
+       0x381c1c24, 0x57a6a6f1, 0x73b4b4c7, 0x97c6c651,
+       0xcbe8e823, 0xa1dddd7c, 0xe874749c, 0x3e1f1f21,
+       0x964b4bdd, 0x61bdbddc, 0x0d8b8b86, 0x0f8a8a85,
+       0xe0707090, 0x7c3e3e42, 0x71b5b5c4, 0xcc6666aa,
+       0x904848d8, 0x06030305, 0xf7f6f601, 0x1c0e0e12,
+       0xc26161a3, 0x6a35355f, 0xae5757f9, 0x69b9b9d0,
+       0x17868691, 0x99c1c158, 0x3a1d1d27, 0x279e9eb9,
+       0xd9e1e138, 0xebf8f813, 0x2b9898b3, 0x22111133,
+       0xd26969bb, 0xa9d9d970, 0x078e8e89, 0x339494a7,
+       0x2d9b9bb6, 0x3c1e1e22, 0x15878792, 0xc9e9e920,
+       0x87cece49, 0xaa5555ff, 0x50282878, 0xa5dfdf7a,
+       0x038c8c8f, 0x59a1a1f8, 0x09898980, 0x1a0d0d17,
+       0x65bfbfda, 0xd7e6e631, 0x844242c6, 0xd06868b8,
+       0x824141c3, 0x299999b0, 0x5a2d2d77, 0x1e0f0f11,
+       0x7bb0b0cb, 0xa85454fc, 0x6dbbbbd6, 0x2c16163a);
+$code.=<<___;
+       .byte   0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5
+       .byte   0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76
+       .byte   0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0
+       .byte   0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0
+       .byte   0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc
+       .byte   0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15
+       .byte   0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a
+       .byte   0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75
+       .byte   0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0
+       .byte   0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84
+       .byte   0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b
+       .byte   0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf
+       .byte   0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85
+       .byte   0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8
+       .byte   0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5
+       .byte   0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2
+       .byte   0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17
+       .byte   0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73
+       .byte   0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88
+       .byte   0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb
+       .byte   0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c
+       .byte   0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79
+       .byte   0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9
+       .byte   0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08
+       .byte   0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6
+       .byte   0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a
+       .byte   0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e
+       .byte   0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e
+       .byte   0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94
+       .byte   0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf
+       .byte   0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68
+       .byte   0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
+.type  AES_Te,#object
+.size  AES_Te,(.-AES_Te)
+
+.align 64
+.skip  16
+_sparcv9_AES_encrypt:
+       save    %sp,-$frame-$locals,%sp
+       stx     %i7,[%sp+$bias+$frame+0]        ! off-load return address
+       ld      [$key+240],$rounds
+       ld      [$key+0],$t0
+       ld      [$key+4],$t1                    !
+       ld      [$key+8],$t2
+       srl     $rounds,1,$rounds
+       xor     $t0,$s0,$s0
+       ld      [$key+12],$t3
+       srl     $s0,21,$acc0
+       xor     $t1,$s1,$s1
+       ld      [$key+16],$t0
+       srl     $s1,13,$acc1                    !
+       xor     $t2,$s2,$s2
+       ld      [$key+20],$t1
+       xor     $t3,$s3,$s3
+       ld      [$key+24],$t2
+       and     $acc0,2040,$acc0
+       ld      [$key+28],$t3
+       nop
+.Lenc_loop:
+       srl     $s2,5,$acc2                     !
+       and     $acc1,2040,$acc1
+       ldx     [$tbl+$acc0],$acc0
+       sll     $s3,3,$acc3
+       and     $acc2,2040,$acc2
+       ldx     [$tbl+$acc1],$acc1
+       srl     $s1,21,$acc4
+       and     $acc3,2040,$acc3
+       ldx     [$tbl+$acc2],$acc2              !
+       srl     $s2,13,$acc5
+       and     $acc4,2040,$acc4
+       ldx     [$tbl+$acc3],$acc3
+       srl     $s3,5,$acc6
+       and     $acc5,2040,$acc5
+       ldx     [$tbl+$acc4],$acc4
+       fmovs   %f0,%f0
+       sll     $s0,3,$acc7                     !
+       and     $acc6,2040,$acc6
+       ldx     [$tbl+$acc5],$acc5
+       srl     $s2,21,$acc8
+       and     $acc7,2040,$acc7
+       ldx     [$tbl+$acc6],$acc6
+       srl     $s3,13,$acc9
+       and     $acc8,2040,$acc8
+       ldx     [$tbl+$acc7],$acc7              !
+       srl     $s0,5,$acc10
+       and     $acc9,2040,$acc9
+       ldx     [$tbl+$acc8],$acc8
+       sll     $s1,3,$acc11
+       and     $acc10,2040,$acc10
+       ldx     [$tbl+$acc9],$acc9
+       fmovs   %f0,%f0
+       srl     $s3,21,$acc12                   !
+       and     $acc11,2040,$acc11
+       ldx     [$tbl+$acc10],$acc10
+       srl     $s0,13,$acc13
+       and     $acc12,2040,$acc12
+       ldx     [$tbl+$acc11],$acc11
+       srl     $s1,5,$acc14
+       and     $acc13,2040,$acc13
+       ldx     [$tbl+$acc12],$acc12            !
+       sll     $s2,3,$acc15
+       and     $acc14,2040,$acc14
+       ldx     [$tbl+$acc13],$acc13
+       and     $acc15,2040,$acc15
+       add     $key,32,$key
+       ldx     [$tbl+$acc14],$acc14
+       fmovs   %f0,%f0
+       subcc   $rounds,1,$rounds               !
+       ldx     [$tbl+$acc15],$acc15
+       bz,a,pn %icc,.Lenc_last
+       add     $tbl,2048,$rounds
+
+               srlx    $acc1,8,$acc1
+               xor     $acc0,$t0,$t0
+       ld      [$key+0],$s0
+       fmovs   %f0,%f0
+               srlx    $acc2,16,$acc2          !
+               xor     $acc1,$t0,$t0
+       ld      [$key+4],$s1
+               srlx    $acc3,24,$acc3
+               xor     $acc2,$t0,$t0
+       ld      [$key+8],$s2
+               srlx    $acc5,8,$acc5
+               xor     $acc3,$t0,$t0
+       ld      [$key+12],$s3                   !
+               srlx    $acc6,16,$acc6
+               xor     $acc4,$t1,$t1
+       fmovs   %f0,%f0
+               srlx    $acc7,24,$acc7
+               xor     $acc5,$t1,$t1
+               srlx    $acc9,8,$acc9
+               xor     $acc6,$t1,$t1
+               srlx    $acc10,16,$acc10        !
+               xor     $acc7,$t1,$t1
+               srlx    $acc11,24,$acc11
+               xor     $acc8,$t2,$t2
+               srlx    $acc13,8,$acc13
+               xor     $acc9,$t2,$t2
+               srlx    $acc14,16,$acc14
+               xor     $acc10,$t2,$t2
+               srlx    $acc15,24,$acc15        !
+               xor     $acc11,$t2,$t2
+               xor     $acc12,$acc14,$acc14
+               xor     $acc13,$t3,$t3
+       srl     $t0,21,$acc0
+               xor     $acc14,$t3,$t3
+       srl     $t1,13,$acc1
+               xor     $acc15,$t3,$t3
+
+       and     $acc0,2040,$acc0                !
+       srl     $t2,5,$acc2
+       and     $acc1,2040,$acc1
+       ldx     [$tbl+$acc0],$acc0
+       sll     $t3,3,$acc3
+       and     $acc2,2040,$acc2
+       ldx     [$tbl+$acc1],$acc1
+       fmovs   %f0,%f0
+       srl     $t1,21,$acc4                    !
+       and     $acc3,2040,$acc3
+       ldx     [$tbl+$acc2],$acc2
+       srl     $t2,13,$acc5
+       and     $acc4,2040,$acc4
+       ldx     [$tbl+$acc3],$acc3
+       srl     $t3,5,$acc6
+       and     $acc5,2040,$acc5
+       ldx     [$tbl+$acc4],$acc4              !
+       sll     $t0,3,$acc7
+       and     $acc6,2040,$acc6
+       ldx     [$tbl+$acc5],$acc5
+       srl     $t2,21,$acc8
+       and     $acc7,2040,$acc7
+       ldx     [$tbl+$acc6],$acc6
+       fmovs   %f0,%f0
+       srl     $t3,13,$acc9                    !
+       and     $acc8,2040,$acc8
+       ldx     [$tbl+$acc7],$acc7
+       srl     $t0,5,$acc10
+       and     $acc9,2040,$acc9
+       ldx     [$tbl+$acc8],$acc8
+       sll     $t1,3,$acc11
+       and     $acc10,2040,$acc10
+       ldx     [$tbl+$acc9],$acc9              !
+       srl     $t3,21,$acc12
+       and     $acc11,2040,$acc11
+       ldx     [$tbl+$acc10],$acc10
+       srl     $t0,13,$acc13
+       and     $acc12,2040,$acc12
+       ldx     [$tbl+$acc11],$acc11
+       fmovs   %f0,%f0
+       srl     $t1,5,$acc14                    !
+       and     $acc13,2040,$acc13
+       ldx     [$tbl+$acc12],$acc12
+       sll     $t2,3,$acc15
+       and     $acc14,2040,$acc14
+       ldx     [$tbl+$acc13],$acc13
+               srlx    $acc1,8,$acc1
+       and     $acc15,2040,$acc15
+       ldx     [$tbl+$acc14],$acc14            !
+
+               srlx    $acc2,16,$acc2
+               xor     $acc0,$s0,$s0
+       ldx     [$tbl+$acc15],$acc15
+               srlx    $acc3,24,$acc3
+               xor     $acc1,$s0,$s0
+       ld      [$key+16],$t0
+       fmovs   %f0,%f0
+               srlx    $acc5,8,$acc5           !
+               xor     $acc2,$s0,$s0
+       ld      [$key+20],$t1
+               srlx    $acc6,16,$acc6
+               xor     $acc3,$s0,$s0
+       ld      [$key+24],$t2
+               srlx    $acc7,24,$acc7
+               xor     $acc4,$s1,$s1
+       ld      [$key+28],$t3                   !
+               srlx    $acc9,8,$acc9
+               xor     $acc5,$s1,$s1
+       ldx     [$tbl+2048+0],%g0               ! prefetch te4
+               srlx    $acc10,16,$acc10
+               xor     $acc6,$s1,$s1
+       ldx     [$tbl+2048+32],%g0              ! prefetch te4
+               srlx    $acc11,24,$acc11
+               xor     $acc7,$s1,$s1
+       ldx     [$tbl+2048+64],%g0              ! prefetch te4
+               srlx    $acc13,8,$acc13
+               xor     $acc8,$s2,$s2
+       ldx     [$tbl+2048+96],%g0              ! prefetch te4
+               srlx    $acc14,16,$acc14        !
+               xor     $acc9,$s2,$s2
+       ldx     [$tbl+2048+128],%g0             ! prefetch te4
+               srlx    $acc15,24,$acc15
+               xor     $acc10,$s2,$s2
+       ldx     [$tbl+2048+160],%g0             ! prefetch te4
+       srl     $s0,21,$acc0
+               xor     $acc11,$s2,$s2
+       ldx     [$tbl+2048+192],%g0             ! prefetch te4
+               xor     $acc12,$acc14,$acc14
+               xor     $acc13,$s3,$s3
+       ldx     [$tbl+2048+224],%g0             ! prefetch te4
+       srl     $s1,13,$acc1                    !
+               xor     $acc14,$s3,$s3
+               xor     $acc15,$s3,$s3
+       ba      .Lenc_loop
+       and     $acc0,2040,$acc0
+
+.align 32
+.Lenc_last:
+               srlx    $acc1,8,$acc1           !
+               xor     $acc0,$t0,$t0
+       ld      [$key+0],$s0
+               srlx    $acc2,16,$acc2
+               xor     $acc1,$t0,$t0
+       ld      [$key+4],$s1
+               srlx    $acc3,24,$acc3
+               xor     $acc2,$t0,$t0
+       ld      [$key+8],$s2                    !
+               srlx    $acc5,8,$acc5
+               xor     $acc3,$t0,$t0
+       ld      [$key+12],$s3
+               srlx    $acc6,16,$acc6
+               xor     $acc4,$t1,$t1
+               srlx    $acc7,24,$acc7
+               xor     $acc5,$t1,$t1
+               srlx    $acc9,8,$acc9           !
+               xor     $acc6,$t1,$t1
+               srlx    $acc10,16,$acc10
+               xor     $acc7,$t1,$t1
+               srlx    $acc11,24,$acc11
+               xor     $acc8,$t2,$t2
+               srlx    $acc13,8,$acc13
+               xor     $acc9,$t2,$t2
+               srlx    $acc14,16,$acc14        !
+               xor     $acc10,$t2,$t2
+               srlx    $acc15,24,$acc15
+               xor     $acc11,$t2,$t2
+               xor     $acc12,$acc14,$acc14
+               xor     $acc13,$t3,$t3
+       srl     $t0,24,$acc0
+               xor     $acc14,$t3,$t3
+       srl     $t1,16,$acc1                    !
+               xor     $acc15,$t3,$t3
+
+       srl     $t2,8,$acc2
+       and     $acc1,255,$acc1
+       ldub    [$rounds+$acc0],$acc0
+       srl     $t1,24,$acc4
+       and     $acc2,255,$acc2
+       ldub    [$rounds+$acc1],$acc1
+       srl     $t2,16,$acc5                    !
+       and     $t3,255,$acc3
+       ldub    [$rounds+$acc2],$acc2
+       ldub    [$rounds+$acc3],$acc3
+       srl     $t3,8,$acc6
+       and     $acc5,255,$acc5
+       ldub    [$rounds+$acc4],$acc4
+       fmovs   %f0,%f0
+       srl     $t2,24,$acc8                    !
+       and     $acc6,255,$acc6
+       ldub    [$rounds+$acc5],$acc5
+       srl     $t3,16,$acc9
+       and     $t0,255,$acc7
+       ldub    [$rounds+$acc6],$acc6
+       ldub    [$rounds+$acc7],$acc7
+       fmovs   %f0,%f0
+       srl     $t0,8,$acc10                    !
+       and     $acc9,255,$acc9
+       ldub    [$rounds+$acc8],$acc8
+       srl     $t3,24,$acc12
+       and     $acc10,255,$acc10
+       ldub    [$rounds+$acc9],$acc9
+       srl     $t0,16,$acc13
+       and     $t1,255,$acc11
+       ldub    [$rounds+$acc10],$acc10         !
+       srl     $t1,8,$acc14
+       and     $acc13,255,$acc13
+       ldub    [$rounds+$acc11],$acc11
+       ldub    [$rounds+$acc12],$acc12
+       and     $acc14,255,$acc14
+       ldub    [$rounds+$acc13],$acc13
+       and     $t2,255,$acc15
+       ldub    [$rounds+$acc14],$acc14         !
+
+               sll     $acc0,24,$acc0
+               xor     $acc3,$s0,$s0
+       ldub    [$rounds+$acc15],$acc15
+               sll     $acc1,16,$acc1
+               xor     $acc0,$s0,$s0
+       ldx     [%sp+$bias+$frame+0],%i7        ! restore return address
+       fmovs   %f0,%f0
+               sll     $acc2,8,$acc2           !
+               xor     $acc1,$s0,$s0
+               sll     $acc4,24,$acc4
+               xor     $acc2,$s0,$s0
+               sll     $acc5,16,$acc5
+               xor     $acc7,$s1,$s1
+               sll     $acc6,8,$acc6
+               xor     $acc4,$s1,$s1
+               sll     $acc8,24,$acc8          !
+               xor     $acc5,$s1,$s1
+               sll     $acc9,16,$acc9
+               xor     $acc11,$s2,$s2
+               sll     $acc10,8,$acc10
+               xor     $acc6,$s1,$s1
+               sll     $acc12,24,$acc12
+               xor     $acc8,$s2,$s2
+               sll     $acc13,16,$acc13        !
+               xor     $acc9,$s2,$s2
+               sll     $acc14,8,$acc14
+               xor     $acc10,$s2,$s2
+               xor     $acc12,$acc14,$acc14
+               xor     $acc13,$s3,$s3
+               xor     $acc14,$s3,$s3
+               xor     $acc15,$s3,$s3
+
+       ret
+       restore
+.type  _sparcv9_AES_encrypt,#function
+.size  _sparcv9_AES_encrypt,(.-_sparcv9_AES_encrypt)
+
+.align 32
+.globl AES_encrypt
+AES_encrypt:
+       or      %o0,%o1,%g1
+       andcc   %g1,3,%g0
+       bnz,pn  %xcc,.Lunaligned_enc
+       save    %sp,-$frame,%sp
+
+       ld      [%i0+0],%o0
+       ld      [%i0+4],%o1
+       ld      [%i0+8],%o2
+       ld      [%i0+12],%o3
+
+1:     call    .+8
+       add     %o7,AES_Te-1b,%o4
+       call    _sparcv9_AES_encrypt
+       mov     %i2,%o5
+
+       st      %o0,[%i1+0]
+       st      %o1,[%i1+4]
+       st      %o2,[%i1+8]
+       st      %o3,[%i1+12]
+
+       ret
+       restore
+
+.align 32
+.Lunaligned_enc:
+       ldub    [%i0+0],%l0
+       ldub    [%i0+1],%l1
+       ldub    [%i0+2],%l2
+
+       sll     %l0,24,%l0
+       ldub    [%i0+3],%l3
+       sll     %l1,16,%l1
+       ldub    [%i0+4],%l4
+       sll     %l2,8,%l2
+       or      %l1,%l0,%l0
+       ldub    [%i0+5],%l5
+       sll     %l4,24,%l4
+       or      %l3,%l2,%l2
+       ldub    [%i0+6],%l6
+       sll     %l5,16,%l5
+       or      %l0,%l2,%o0
+       ldub    [%i0+7],%l7
+
+       sll     %l6,8,%l6
+       or      %l5,%l4,%l4
+       ldub    [%i0+8],%l0
+       or      %l7,%l6,%l6
+       ldub    [%i0+9],%l1
+       or      %l4,%l6,%o1
+       ldub    [%i0+10],%l2
+
+       sll     %l0,24,%l0
+       ldub    [%i0+11],%l3
+       sll     %l1,16,%l1
+       ldub    [%i0+12],%l4
+       sll     %l2,8,%l2
+       or      %l1,%l0,%l0
+       ldub    [%i0+13],%l5
+       sll     %l4,24,%l4
+       or      %l3,%l2,%l2
+       ldub    [%i0+14],%l6
+       sll     %l5,16,%l5
+       or      %l0,%l2,%o2
+       ldub    [%i0+15],%l7
+
+       sll     %l6,8,%l6
+       or      %l5,%l4,%l4
+       or      %l7,%l6,%l6
+       or      %l4,%l6,%o3
+
+1:     call    .+8
+       add     %o7,AES_Te-1b,%o4
+       call    _sparcv9_AES_encrypt
+       mov     %i2,%o5
+
+       srl     %o0,24,%l0
+       srl     %o0,16,%l1
+       stb     %l0,[%i1+0]
+       srl     %o0,8,%l2
+       stb     %l1,[%i1+1]
+       stb     %l2,[%i1+2]
+       srl     %o1,24,%l4
+       stb     %o0,[%i1+3]
+
+       srl     %o1,16,%l5
+       stb     %l4,[%i1+4]
+       srl     %o1,8,%l6
+       stb     %l5,[%i1+5]
+       stb     %l6,[%i1+6]
+       srl     %o2,24,%l0
+       stb     %o1,[%i1+7]
+
+       srl     %o2,16,%l1
+       stb     %l0,[%i1+8]
+       srl     %o2,8,%l2
+       stb     %l1,[%i1+9]
+       stb     %l2,[%i1+10]
+       srl     %o3,24,%l4
+       stb     %o2,[%i1+11]
+
+       srl     %o3,16,%l5
+       stb     %l4,[%i1+12]
+       srl     %o3,8,%l6
+       stb     %l5,[%i1+13]
+       stb     %l6,[%i1+14]
+       stb     %o3,[%i1+15]
+
+       ret
+       restore
+.type  AES_encrypt,#function
+.size  AES_encrypt,(.-AES_encrypt)
+
+___
+
+$code.=<<___;
+.align 256
+AES_Td:
+___
+&_data_word(
+       0x51f4a750, 0x7e416553, 0x1a17a4c3, 0x3a275e96,
+       0x3bab6bcb, 0x1f9d45f1, 0xacfa58ab, 0x4be30393,
+       0x2030fa55, 0xad766df6, 0x88cc7691, 0xf5024c25,
+       0x4fe5d7fc, 0xc52acbd7, 0x26354480, 0xb562a38f,
+       0xdeb15a49, 0x25ba1b67, 0x45ea0e98, 0x5dfec0e1,
+       0xc32f7502, 0x814cf012, 0x8d4697a3, 0x6bd3f9c6,
+       0x038f5fe7, 0x15929c95, 0xbf6d7aeb, 0x955259da,
+       0xd4be832d, 0x587421d3, 0x49e06929, 0x8ec9c844,
+       0x75c2896a, 0xf48e7978, 0x99583e6b, 0x27b971dd,
+       0xbee14fb6, 0xf088ad17, 0xc920ac66, 0x7dce3ab4,
+       0x63df4a18, 0xe51a3182, 0x97513360, 0x62537f45,
+       0xb16477e0, 0xbb6bae84, 0xfe81a01c, 0xf9082b94,
+       0x70486858, 0x8f45fd19, 0x94de6c87, 0x527bf8b7,
+       0xab73d323, 0x724b02e2, 0xe31f8f57, 0x6655ab2a,
+       0xb2eb2807, 0x2fb5c203, 0x86c57b9a, 0xd33708a5,
+       0x302887f2, 0x23bfa5b2, 0x02036aba, 0xed16825c,
+       0x8acf1c2b, 0xa779b492, 0xf307f2f0, 0x4e69e2a1,
+       0x65daf4cd, 0x0605bed5, 0xd134621f, 0xc4a6fe8a,
+       0x342e539d, 0xa2f355a0, 0x058ae132, 0xa4f6eb75,
+       0x0b83ec39, 0x4060efaa, 0x5e719f06, 0xbd6e1051,
+       0x3e218af9, 0x96dd063d, 0xdd3e05ae, 0x4de6bd46,
+       0x91548db5, 0x71c45d05, 0x0406d46f, 0x605015ff,
+       0x1998fb24, 0xd6bde997, 0x894043cc, 0x67d99e77,
+       0xb0e842bd, 0x07898b88, 0xe7195b38, 0x79c8eedb,
+       0xa17c0a47, 0x7c420fe9, 0xf8841ec9, 0x00000000,
+       0x09808683, 0x322bed48, 0x1e1170ac, 0x6c5a724e,
+       0xfd0efffb, 0x0f853856, 0x3daed51e, 0x362d3927,
+       0x0a0fd964, 0x685ca621, 0x9b5b54d1, 0x24362e3a,
+       0x0c0a67b1, 0x9357e70f, 0xb4ee96d2, 0x1b9b919e,
+       0x80c0c54f, 0x61dc20a2, 0x5a774b69, 0x1c121a16,
+       0xe293ba0a, 0xc0a02ae5, 0x3c22e043, 0x121b171d,
+       0x0e090d0b, 0xf28bc7ad, 0x2db6a8b9, 0x141ea9c8,
+       0x57f11985, 0xaf75074c, 0xee99ddbb, 0xa37f60fd,
+       0xf701269f, 0x5c72f5bc, 0x44663bc5, 0x5bfb7e34,
+       0x8b432976, 0xcb23c6dc, 0xb6edfc68, 0xb8e4f163,
+       0xd731dcca, 0x42638510, 0x13972240, 0x84c61120,
+       0x854a247d, 0xd2bb3df8, 0xaef93211, 0xc729a16d,
+       0x1d9e2f4b, 0xdcb230f3, 0x0d8652ec, 0x77c1e3d0,
+       0x2bb3166c, 0xa970b999, 0x119448fa, 0x47e96422,
+       0xa8fc8cc4, 0xa0f03f1a, 0x567d2cd8, 0x223390ef,
+       0x87494ec7, 0xd938d1c1, 0x8ccaa2fe, 0x98d40b36,
+       0xa6f581cf, 0xa57ade28, 0xdab78e26, 0x3fadbfa4,
+       0x2c3a9de4, 0x5078920d, 0x6a5fcc9b, 0x547e4662,
+       0xf68d13c2, 0x90d8b8e8, 0x2e39f75e, 0x82c3aff5,
+       0x9f5d80be, 0x69d0937c, 0x6fd52da9, 0xcf2512b3,
+       0xc8ac993b, 0x10187da7, 0xe89c636e, 0xdb3bbb7b,
+       0xcd267809, 0x6e5918f4, 0xec9ab701, 0x834f9aa8,
+       0xe6956e65, 0xaaffe67e, 0x21bccf08, 0xef15e8e6,
+       0xbae79bd9, 0x4a6f36ce, 0xea9f09d4, 0x29b07cd6,
+       0x31a4b2af, 0x2a3f2331, 0xc6a59430, 0x35a266c0,
+       0x744ebc37, 0xfc82caa6, 0xe090d0b0, 0x33a7d815,
+       0xf104984a, 0x41ecdaf7, 0x7fcd500e, 0x1791f62f,
+       0x764dd68d, 0x43efb04d, 0xccaa4d54, 0xe49604df,
+       0x9ed1b5e3, 0x4c6a881b, 0xc12c1fb8, 0x4665517f,
+       0x9d5eea04, 0x018c355d, 0xfa877473, 0xfb0b412e,
+       0xb3671d5a, 0x92dbd252, 0xe9105633, 0x6dd64713,
+       0x9ad7618c, 0x37a10c7a, 0x59f8148e, 0xeb133c89,
+       0xcea927ee, 0xb761c935, 0xe11ce5ed, 0x7a47b13c,
+       0x9cd2df59, 0x55f2733f, 0x1814ce79, 0x73c737bf,
+       0x53f7cdea, 0x5ffdaa5b, 0xdf3d6f14, 0x7844db86,
+       0xcaaff381, 0xb968c43e, 0x3824342c, 0xc2a3405f,
+       0x161dc372, 0xbce2250c, 0x283c498b, 0xff0d9541,
+       0x39a80171, 0x080cb3de, 0xd8b4e49c, 0x6456c190,
+       0x7bcb8461, 0xd532b670, 0x486c5c74, 0xd0b85742);
+$code.=<<___;
+       .byte   0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38
+       .byte   0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb
+       .byte   0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87
+       .byte   0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb
+       .byte   0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d
+       .byte   0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e
+       .byte   0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2
+       .byte   0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25
+       .byte   0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16
+       .byte   0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92
+       .byte   0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda
+       .byte   0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84
+       .byte   0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a
+       .byte   0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06
+       .byte   0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02
+       .byte   0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b
+       .byte   0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea
+       .byte   0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73
+       .byte   0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85
+       .byte   0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e
+       .byte   0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89
+       .byte   0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b
+       .byte   0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20
+       .byte   0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4
+       .byte   0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31
+       .byte   0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f
+       .byte   0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d
+       .byte   0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef
+       .byte   0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0
+       .byte   0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61
+       .byte   0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26
+       .byte   0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d
+.type  AES_Td,#object
+.size  AES_Td,(.-AES_Td)
+
+.align 64
+.skip  16
+_sparcv9_AES_decrypt:
+       save    %sp,-$frame-$locals,%sp
+       stx     %i7,[%sp+$bias+$frame+0]        ! off-load return address
+       ld      [$key+240],$rounds
+       ld      [$key+0],$t0
+       ld      [$key+4],$t1                    !
+       ld      [$key+8],$t2
+       ld      [$key+12],$t3
+       srl     $rounds,1,$rounds
+       xor     $t0,$s0,$s0
+       ld      [$key+16],$t0
+       xor     $t1,$s1,$s1
+       ld      [$key+20],$t1
+       srl     $s0,21,$acc0                    !
+       xor     $t2,$s2,$s2
+       ld      [$key+24],$t2
+       xor     $t3,$s3,$s3
+       and     $acc0,2040,$acc0
+       ld      [$key+28],$t3
+       srl     $s3,13,$acc1
+       nop
+.Ldec_loop:
+       srl     $s2,5,$acc2                     !
+       and     $acc1,2040,$acc1
+       ldx     [$tbl+$acc0],$acc0
+       sll     $s1,3,$acc3
+       and     $acc2,2040,$acc2
+       ldx     [$tbl+$acc1],$acc1
+       srl     $s1,21,$acc4
+       and     $acc3,2040,$acc3
+       ldx     [$tbl+$acc2],$acc2              !
+       srl     $s0,13,$acc5
+       and     $acc4,2040,$acc4
+       ldx     [$tbl+$acc3],$acc3
+       srl     $s3,5,$acc6
+       and     $acc5,2040,$acc5
+       ldx     [$tbl+$acc4],$acc4
+       fmovs   %f0,%f0
+       sll     $s2,3,$acc7                     !
+       and     $acc6,2040,$acc6
+       ldx     [$tbl+$acc5],$acc5
+       srl     $s2,21,$acc8
+       and     $acc7,2040,$acc7
+       ldx     [$tbl+$acc6],$acc6
+       srl     $s1,13,$acc9
+       and     $acc8,2040,$acc8
+       ldx     [$tbl+$acc7],$acc7              !
+       srl     $s0,5,$acc10
+       and     $acc9,2040,$acc9
+       ldx     [$tbl+$acc8],$acc8
+       sll     $s3,3,$acc11
+       and     $acc10,2040,$acc10
+       ldx     [$tbl+$acc9],$acc9
+       fmovs   %f0,%f0
+       srl     $s3,21,$acc12                   !
+       and     $acc11,2040,$acc11
+       ldx     [$tbl+$acc10],$acc10
+       srl     $s2,13,$acc13
+       and     $acc12,2040,$acc12
+       ldx     [$tbl+$acc11],$acc11
+       srl     $s1,5,$acc14
+       and     $acc13,2040,$acc13
+       ldx     [$tbl+$acc12],$acc12            !
+       sll     $s0,3,$acc15
+       and     $acc14,2040,$acc14
+       ldx     [$tbl+$acc13],$acc13
+       and     $acc15,2040,$acc15
+       add     $key,32,$key
+       ldx     [$tbl+$acc14],$acc14
+       fmovs   %f0,%f0
+       subcc   $rounds,1,$rounds               !
+       ldx     [$tbl+$acc15],$acc15
+       bz,a,pn %icc,.Ldec_last
+       add     $tbl,2048,$rounds
+
+               srlx    $acc1,8,$acc1
+               xor     $acc0,$t0,$t0
+       ld      [$key+0],$s0
+       fmovs   %f0,%f0
+               srlx    $acc2,16,$acc2          !
+               xor     $acc1,$t0,$t0
+       ld      [$key+4],$s1
+               srlx    $acc3,24,$acc3
+               xor     $acc2,$t0,$t0
+       ld      [$key+8],$s2
+               srlx    $acc5,8,$acc5
+               xor     $acc3,$t0,$t0
+       ld      [$key+12],$s3                   !
+               srlx    $acc6,16,$acc6
+               xor     $acc4,$t1,$t1
+       fmovs   %f0,%f0
+               srlx    $acc7,24,$acc7
+               xor     $acc5,$t1,$t1
+               srlx    $acc9,8,$acc9
+               xor     $acc6,$t1,$t1
+               srlx    $acc10,16,$acc10        !
+               xor     $acc7,$t1,$t1
+               srlx    $acc11,24,$acc11
+               xor     $acc8,$t2,$t2
+               srlx    $acc13,8,$acc13
+               xor     $acc9,$t2,$t2
+               srlx    $acc14,16,$acc14
+               xor     $acc10,$t2,$t2
+               srlx    $acc15,24,$acc15        !
+               xor     $acc11,$t2,$t2
+               xor     $acc12,$acc14,$acc14
+               xor     $acc13,$t3,$t3
+       srl     $t0,21,$acc0
+               xor     $acc14,$t3,$t3
+               xor     $acc15,$t3,$t3
+       srl     $t3,13,$acc1
+
+       and     $acc0,2040,$acc0                !
+       srl     $t2,5,$acc2
+       and     $acc1,2040,$acc1
+       ldx     [$tbl+$acc0],$acc0
+       sll     $t1,3,$acc3
+       and     $acc2,2040,$acc2
+       ldx     [$tbl+$acc1],$acc1
+       fmovs   %f0,%f0
+       srl     $t1,21,$acc4                    !
+       and     $acc3,2040,$acc3
+       ldx     [$tbl+$acc2],$acc2
+       srl     $t0,13,$acc5
+       and     $acc4,2040,$acc4
+       ldx     [$tbl+$acc3],$acc3
+       srl     $t3,5,$acc6
+       and     $acc5,2040,$acc5
+       ldx     [$tbl+$acc4],$acc4              !
+       sll     $t2,3,$acc7
+       and     $acc6,2040,$acc6
+       ldx     [$tbl+$acc5],$acc5
+       srl     $t2,21,$acc8
+       and     $acc7,2040,$acc7
+       ldx     [$tbl+$acc6],$acc6
+       fmovs   %f0,%f0
+       srl     $t1,13,$acc9                    !
+       and     $acc8,2040,$acc8
+       ldx     [$tbl+$acc7],$acc7
+       srl     $t0,5,$acc10
+       and     $acc9,2040,$acc9
+       ldx     [$tbl+$acc8],$acc8
+       sll     $t3,3,$acc11
+       and     $acc10,2040,$acc10
+       ldx     [$tbl+$acc9],$acc9              !
+       srl     $t3,21,$acc12
+       and     $acc11,2040,$acc11
+       ldx     [$tbl+$acc10],$acc10
+       srl     $t2,13,$acc13
+       and     $acc12,2040,$acc12
+       ldx     [$tbl+$acc11],$acc11
+       fmovs   %f0,%f0
+       srl     $t1,5,$acc14                    !
+       and     $acc13,2040,$acc13
+       ldx     [$tbl+$acc12],$acc12
+       sll     $t0,3,$acc15
+       and     $acc14,2040,$acc14
+       ldx     [$tbl+$acc13],$acc13
+               srlx    $acc1,8,$acc1
+       and     $acc15,2040,$acc15
+       ldx     [$tbl+$acc14],$acc14            !
+
+               srlx    $acc2,16,$acc2
+               xor     $acc0,$s0,$s0
+       ldx     [$tbl+$acc15],$acc15
+               srlx    $acc3,24,$acc3
+               xor     $acc1,$s0,$s0
+       ld      [$key+16],$t0
+       fmovs   %f0,%f0
+               srlx    $acc5,8,$acc5           !
+               xor     $acc2,$s0,$s0
+       ld      [$key+20],$t1
+               srlx    $acc6,16,$acc6
+               xor     $acc3,$s0,$s0
+       ld      [$key+24],$t2
+               srlx    $acc7,24,$acc7
+               xor     $acc4,$s1,$s1
+       ld      [$key+28],$t3                   !
+               srlx    $acc9,8,$acc9
+               xor     $acc5,$s1,$s1
+       ldx     [$tbl+2048+0],%g0               ! prefetch td4
+               srlx    $acc10,16,$acc10
+               xor     $acc6,$s1,$s1
+       ldx     [$tbl+2048+32],%g0              ! prefetch td4
+               srlx    $acc11,24,$acc11
+               xor     $acc7,$s1,$s1
+       ldx     [$tbl+2048+64],%g0              ! prefetch td4
+               srlx    $acc13,8,$acc13
+               xor     $acc8,$s2,$s2
+       ldx     [$tbl+2048+96],%g0              ! prefetch td4
+               srlx    $acc14,16,$acc14        !
+               xor     $acc9,$s2,$s2
+       ldx     [$tbl+2048+128],%g0             ! prefetch td4
+               srlx    $acc15,24,$acc15
+               xor     $acc10,$s2,$s2
+       ldx     [$tbl+2048+160],%g0             ! prefetch td4
+       srl     $s0,21,$acc0
+               xor     $acc11,$s2,$s2
+       ldx     [$tbl+2048+192],%g0             ! prefetch td4
+               xor     $acc12,$acc14,$acc14
+               xor     $acc13,$s3,$s3
+       ldx     [$tbl+2048+224],%g0             ! prefetch td4
+       and     $acc0,2040,$acc0                !
+               xor     $acc14,$s3,$s3
+               xor     $acc15,$s3,$s3
+       ba      .Ldec_loop
+       srl     $s3,13,$acc1
+
+.align 32
+.Ldec_last:
+               srlx    $acc1,8,$acc1           !
+               xor     $acc0,$t0,$t0
+       ld      [$key+0],$s0
+               srlx    $acc2,16,$acc2
+               xor     $acc1,$t0,$t0
+       ld      [$key+4],$s1
+               srlx    $acc3,24,$acc3
+               xor     $acc2,$t0,$t0
+       ld      [$key+8],$s2                    !
+               srlx    $acc5,8,$acc5
+               xor     $acc3,$t0,$t0
+       ld      [$key+12],$s3
+               srlx    $acc6,16,$acc6
+               xor     $acc4,$t1,$t1
+               srlx    $acc7,24,$acc7
+               xor     $acc5,$t1,$t1
+               srlx    $acc9,8,$acc9           !
+               xor     $acc6,$t1,$t1
+               srlx    $acc10,16,$acc10
+               xor     $acc7,$t1,$t1
+               srlx    $acc11,24,$acc11
+               xor     $acc8,$t2,$t2
+               srlx    $acc13,8,$acc13
+               xor     $acc9,$t2,$t2
+               srlx    $acc14,16,$acc14        !
+               xor     $acc10,$t2,$t2
+               srlx    $acc15,24,$acc15
+               xor     $acc11,$t2,$t2
+               xor     $acc12,$acc14,$acc14
+               xor     $acc13,$t3,$t3
+       srl     $t0,24,$acc0
+               xor     $acc14,$t3,$t3
+               xor     $acc15,$t3,$t3          !
+       srl     $t3,16,$acc1
+
+       srl     $t2,8,$acc2
+       and     $acc1,255,$acc1
+       ldub    [$rounds+$acc0],$acc0
+       srl     $t1,24,$acc4
+       and     $acc2,255,$acc2
+       ldub    [$rounds+$acc1],$acc1
+       srl     $t0,16,$acc5                    !
+       and     $t1,255,$acc3
+       ldub    [$rounds+$acc2],$acc2
+       ldub    [$rounds+$acc3],$acc3
+       srl     $t3,8,$acc6
+       and     $acc5,255,$acc5
+       ldub    [$rounds+$acc4],$acc4
+       fmovs   %f0,%f0
+       srl     $t2,24,$acc8                    !
+       and     $acc6,255,$acc6
+       ldub    [$rounds+$acc5],$acc5
+       srl     $t1,16,$acc9
+       and     $t2,255,$acc7
+       ldub    [$rounds+$acc6],$acc6
+       ldub    [$rounds+$acc7],$acc7
+       fmovs   %f0,%f0
+       srl     $t0,8,$acc10                    !
+       and     $acc9,255,$acc9
+       ldub    [$rounds+$acc8],$acc8
+       srl     $t3,24,$acc12
+       and     $acc10,255,$acc10
+       ldub    [$rounds+$acc9],$acc9
+       srl     $t2,16,$acc13
+       and     $t3,255,$acc11
+       ldub    [$rounds+$acc10],$acc10         !
+       srl     $t1,8,$acc14
+       and     $acc13,255,$acc13
+       ldub    [$rounds+$acc11],$acc11
+       ldub    [$rounds+$acc12],$acc12
+       and     $acc14,255,$acc14
+       ldub    [$rounds+$acc13],$acc13
+       and     $t0,255,$acc15
+       ldub    [$rounds+$acc14],$acc14         !
+
+               sll     $acc0,24,$acc0
+               xor     $acc3,$s0,$s0
+       ldub    [$rounds+$acc15],$acc15
+               sll     $acc1,16,$acc1
+               xor     $acc0,$s0,$s0
+       ldx     [%sp+$bias+$frame+0],%i7        ! restore return address
+       fmovs   %f0,%f0
+               sll     $acc2,8,$acc2           !
+               xor     $acc1,$s0,$s0
+               sll     $acc4,24,$acc4
+               xor     $acc2,$s0,$s0
+               sll     $acc5,16,$acc5
+               xor     $acc7,$s1,$s1
+               sll     $acc6,8,$acc6
+               xor     $acc4,$s1,$s1
+               sll     $acc8,24,$acc8          !
+               xor     $acc5,$s1,$s1
+               sll     $acc9,16,$acc9
+               xor     $acc11,$s2,$s2
+               sll     $acc10,8,$acc10
+               xor     $acc6,$s1,$s1
+               sll     $acc12,24,$acc12
+               xor     $acc8,$s2,$s2
+               sll     $acc13,16,$acc13        !
+               xor     $acc9,$s2,$s2
+               sll     $acc14,8,$acc14
+               xor     $acc10,$s2,$s2
+               xor     $acc12,$acc14,$acc14
+               xor     $acc13,$s3,$s3
+               xor     $acc14,$s3,$s3
+               xor     $acc15,$s3,$s3
+
+       ret
+       restore
+.type  _sparcv9_AES_decrypt,#function
+.size  _sparcv9_AES_decrypt,(.-_sparcv9_AES_decrypt)
+
+.align 32
+.globl AES_decrypt
+AES_decrypt:
+       or      %o0,%o1,%g1
+       andcc   %g1,3,%g0
+       bnz,pn  %xcc,.Lunaligned_dec
+       save    %sp,-$frame,%sp
+
+       ld      [%i0+0],%o0
+       ld      [%i0+4],%o1
+       ld      [%i0+8],%o2
+       ld      [%i0+12],%o3
+
+1:     call    .+8
+       add     %o7,AES_Td-1b,%o4
+       call    _sparcv9_AES_decrypt
+       mov     %i2,%o5
+
+       st      %o0,[%i1+0]
+       st      %o1,[%i1+4]
+       st      %o2,[%i1+8]
+       st      %o3,[%i1+12]
+
+       ret
+       restore
+
+.align 32
+.Lunaligned_dec:
+       ldub    [%i0+0],%l0
+       ldub    [%i0+1],%l1
+       ldub    [%i0+2],%l2
+
+       sll     %l0,24,%l0
+       ldub    [%i0+3],%l3
+       sll     %l1,16,%l1
+       ldub    [%i0+4],%l4
+       sll     %l2,8,%l2
+       or      %l1,%l0,%l0
+       ldub    [%i0+5],%l5
+       sll     %l4,24,%l4
+       or      %l3,%l2,%l2
+       ldub    [%i0+6],%l6
+       sll     %l5,16,%l5
+       or      %l0,%l2,%o0
+       ldub    [%i0+7],%l7
+
+       sll     %l6,8,%l6
+       or      %l5,%l4,%l4
+       ldub    [%i0+8],%l0
+       or      %l7,%l6,%l6
+       ldub    [%i0+9],%l1
+       or      %l4,%l6,%o1
+       ldub    [%i0+10],%l2
+
+       sll     %l0,24,%l0
+       ldub    [%i0+11],%l3
+       sll     %l1,16,%l1
+       ldub    [%i0+12],%l4
+       sll     %l2,8,%l2
+       or      %l1,%l0,%l0
+       ldub    [%i0+13],%l5
+       sll     %l4,24,%l4
+       or      %l3,%l2,%l2
+       ldub    [%i0+14],%l6
+       sll     %l5,16,%l5
+       or      %l0,%l2,%o2
+       ldub    [%i0+15],%l7
+
+       sll     %l6,8,%l6
+       or      %l5,%l4,%l4
+       or      %l7,%l6,%l6
+       or      %l4,%l6,%o3
+
+1:     call    .+8
+       add     %o7,AES_Td-1b,%o4
+       call    _sparcv9_AES_decrypt
+       mov     %i2,%o5
+
+       srl     %o0,24,%l0
+       srl     %o0,16,%l1
+       stb     %l0,[%i1+0]
+       srl     %o0,8,%l2
+       stb     %l1,[%i1+1]
+       stb     %l2,[%i1+2]
+       srl     %o1,24,%l4
+       stb     %o0,[%i1+3]
+
+       srl     %o1,16,%l5
+       stb     %l4,[%i1+4]
+       srl     %o1,8,%l6
+       stb     %l5,[%i1+5]
+       stb     %l6,[%i1+6]
+       srl     %o2,24,%l0
+       stb     %o1,[%i1+7]
+
+       srl     %o2,16,%l1
+       stb     %l0,[%i1+8]
+       srl     %o2,8,%l2
+       stb     %l1,[%i1+9]
+       stb     %l2,[%i1+10]
+       srl     %o3,24,%l4
+       stb     %o2,[%i1+11]
+
+       srl     %o3,16,%l5
+       stb     %l4,[%i1+12]
+       srl     %o3,8,%l6
+       stb     %l5,[%i1+13]
+       stb     %l6,[%i1+14]
+       stb     %o3,[%i1+15]
+
+       ret
+       restore
+.type  AES_decrypt,#function
+.size  AES_decrypt,(.-AES_decrypt)
+___
+
+# fmovs instructions substituting for FP nops were originally added
+# to meet specific instruction alignment requirements to maximize ILP.
+# As UltraSPARC T1, a.k.a. Niagara, has shared FPU, FP nops can have
+# undesired effect, so just omit them and sacrifice some portion of
+# percent in performance...
+$code =~ s/fmovs.*$//gem;
+
+print $code;
index b510057..a545e89 100755 (executable)
@@ -2,11 +2,12 @@
 #
 # ====================================================================
 # Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
-# project. Rights for redistribution and usage in source and binary
-# forms are granted according to the OpenSSL license.
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
 # ====================================================================
 #
-# Version 1.2.
+# Version 2.1.
 #
 # aes-*-cbc benchmarks are improved by >70% [compared to gcc 3.3.2 on
 # Opteron 240 CPU] plus all the bells-n-whistles from 32-bit version
 #
 # Performance in number of cycles per processed byte for 128-bit key:
 #
-#              ECB             CBC encrypt
-# AMD64                13.7            13.0(*)
-# EM64T                20.2            18.6(*)
+#              ECB encrypt     ECB decrypt     CBC large chunk
+# AMD64                33              41              13.0
+# EM64T                38              59              18.6(*)
+# Core 2       30              43              14.5(*)
 #
-# (*)  CBC benchmarks are better than ECB thanks to custom ABI used
-#      by the private block encryption function.
+# (*) with hyper-threading off
+
+$flavour = shift;
+$output  = shift;
+if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
+
+$win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
+
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+( $xlate="${dir}x86_64-xlate.pl" and -f $xlate ) or
+( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
+die "can't locate x86_64-xlate.pl";
+
+open STDOUT,"| $^X $xlate $flavour $output";
 
 $verticalspin=1;       # unlike 32-bit version $verticalspin performs
                        # ~15% better on both AMD and Intel cores
-$output=shift;
-open STDOUT,"| $^X ../perlasm/x86_64-xlate.pl $output";
+$speed_limit=512;      # see aes-586.pl for details
 
 $code=".text\n";
 
@@ -35,9 +48,9 @@ $s0="%eax";
 $s1="%ebx";
 $s2="%ecx";
 $s3="%edx";
-$acc0="%esi";
-$acc1="%edi";
-$acc2="%ebp";
+$acc0="%esi";  $mask80="%rsi";
+$acc1="%edi";  $maskfe="%rdi";
+$acc2="%ebp";  $mask1b="%rbp";
 $inp="%r8";
 $out="%r9";
 $t0="%r10d";
@@ -51,6 +64,8 @@ sub hi() { my $r=shift;       $r =~ s/%[er]([a-d])x/%\1h/;    $r; }
 sub lo() { my $r=shift;        $r =~ s/%[er]([a-d])x/%\1l/;
                        $r =~ s/%[er]([sd]i)/%\1l/;
                        $r =~ s/%(r[0-9]+)[d]?/%\1b/;   $r; }
+sub LO() { my $r=shift; $r =~ s/%r([a-z]+)/%e\1/;
+                       $r =~ s/%r([0-9]+)/%r\1d/;      $r; }
 sub _data_word()
 { my $i;
     while(defined($i=shift)) { $code.=sprintf".long\t0x%08x,0x%08x\n",$i,$i; }
@@ -138,22 +153,17 @@ $code.=<<___;
        movzb   `&lo("$s0")`,$acc0
        movzb   `&lo("$s1")`,$acc1
        movzb   `&lo("$s2")`,$acc2
-       mov     2($sbox,$acc0,8),$t0
-       mov     2($sbox,$acc1,8),$t1
-       mov     2($sbox,$acc2,8),$t2
-
-       and     \$0x000000ff,$t0
-       and     \$0x000000ff,$t1
-       and     \$0x000000ff,$t2
+       movzb   2($sbox,$acc0,8),$t0
+       movzb   2($sbox,$acc1,8),$t1
+       movzb   2($sbox,$acc2,8),$t2
 
        movzb   `&lo("$s3")`,$acc0
        movzb   `&hi("$s1")`,$acc1
        movzb   `&hi("$s2")`,$acc2
-       mov     2($sbox,$acc0,8),$t3
+       movzb   2($sbox,$acc0,8),$t3
        mov     0($sbox,$acc1,8),$acc1  #$t0
        mov     0($sbox,$acc2,8),$acc2  #$t1
 
-       and     \$0x000000ff,$t3
        and     \$0x0000ff00,$acc1
        and     \$0x0000ff00,$acc2
 
@@ -345,6 +355,234 @@ $code.=<<___;
 .size  _x86_64_AES_encrypt,.-_x86_64_AES_encrypt
 ___
 
+# it's possible to implement this by shifting tN by 8, filling least
+# significant byte with byte load and finally bswap-ing at the end,
+# but such partial register load kills Core 2...
+sub enccompactvert()
+{ my ($t3,$t4,$t5)=("%r8d","%r9d","%r13d");
+
+$code.=<<___;
+       movzb   `&lo("$s0")`,$t0
+       movzb   `&lo("$s1")`,$t1
+       movzb   `&lo("$s2")`,$t2
+       movzb   ($sbox,$t0,1),$t0
+       movzb   ($sbox,$t1,1),$t1
+       movzb   ($sbox,$t2,1),$t2
+
+       movzb   `&lo("$s3")`,$t3
+       movzb   `&hi("$s1")`,$acc0
+       movzb   `&hi("$s2")`,$acc1
+       movzb   ($sbox,$t3,1),$t3
+       movzb   ($sbox,$acc0,1),$t4     #$t0
+       movzb   ($sbox,$acc1,1),$t5     #$t1
+
+       movzb   `&hi("$s3")`,$acc2
+       movzb   `&hi("$s0")`,$acc0
+       shr     \$16,$s2
+       movzb   ($sbox,$acc2,1),$acc2   #$t2
+       movzb   ($sbox,$acc0,1),$acc0   #$t3
+       shr     \$16,$s3
+
+       movzb   `&lo("$s2")`,$acc1
+       shl     \$8,$t4
+       shl     \$8,$t5
+       movzb   ($sbox,$acc1,1),$acc1   #$t0
+       xor     $t4,$t0
+       xor     $t5,$t1
+
+       movzb   `&lo("$s3")`,$t4
+       shr     \$16,$s0
+       shr     \$16,$s1
+       movzb   `&lo("$s0")`,$t5
+       shl     \$8,$acc2
+       shl     \$8,$acc0
+       movzb   ($sbox,$t4,1),$t4       #$t1
+       movzb   ($sbox,$t5,1),$t5       #$t2
+       xor     $acc2,$t2
+       xor     $acc0,$t3
+
+       movzb   `&lo("$s1")`,$acc2
+       movzb   `&hi("$s3")`,$acc0
+       shl     \$16,$acc1
+       movzb   ($sbox,$acc2,1),$acc2   #$t3
+       movzb   ($sbox,$acc0,1),$acc0   #$t0
+       xor     $acc1,$t0
+
+       movzb   `&hi("$s0")`,$acc1
+       shr     \$8,$s2
+       shr     \$8,$s1
+       movzb   ($sbox,$acc1,1),$acc1   #$t1
+       movzb   ($sbox,$s2,1),$s3       #$t3
+       movzb   ($sbox,$s1,1),$s2       #$t2
+       shl     \$16,$t4
+       shl     \$16,$t5
+       shl     \$16,$acc2
+       xor     $t4,$t1
+       xor     $t5,$t2
+       xor     $acc2,$t3
+
+       shl     \$24,$acc0
+       shl     \$24,$acc1
+       shl     \$24,$s3
+       xor     $acc0,$t0
+       shl     \$24,$s2
+       xor     $acc1,$t1
+       mov     $t0,$s0
+       mov     $t1,$s1
+       xor     $t2,$s2
+       xor     $t3,$s3
+___
+}
+
+sub enctransform_ref()
+{ my $sn = shift;
+  my ($acc,$r2,$tmp)=("%r8d","%r9d","%r13d");
+
+$code.=<<___;
+       mov     $sn,$acc
+       and     \$0x80808080,$acc
+       mov     $acc,$tmp
+       shr     \$7,$tmp
+       lea     ($sn,$sn),$r2
+       sub     $tmp,$acc
+       and     \$0xfefefefe,$r2
+       and     \$0x1b1b1b1b,$acc
+       mov     $sn,$tmp
+       xor     $acc,$r2
+
+       xor     $r2,$sn
+       rol     \$24,$sn
+       xor     $r2,$sn
+       ror     \$16,$tmp
+       xor     $tmp,$sn
+       ror     \$8,$tmp
+       xor     $tmp,$sn
+___
+}
+
+# unlike decrypt case it does not pay off to parallelize enctransform
+sub enctransform()
+{ my ($t3,$r20,$r21)=($acc2,"%r8d","%r9d");
+
+$code.=<<___;
+       mov     $s0,$acc0
+       mov     $s1,$acc1
+       and     \$0x80808080,$acc0
+       and     \$0x80808080,$acc1
+       mov     $acc0,$t0
+       mov     $acc1,$t1
+       shr     \$7,$t0
+       lea     ($s0,$s0),$r20
+       shr     \$7,$t1
+       lea     ($s1,$s1),$r21
+       sub     $t0,$acc0
+       sub     $t1,$acc1
+       and     \$0xfefefefe,$r20
+       and     \$0xfefefefe,$r21
+       and     \$0x1b1b1b1b,$acc0
+       and     \$0x1b1b1b1b,$acc1
+       mov     $s0,$t0
+       mov     $s1,$t1
+       xor     $acc0,$r20
+       xor     $acc1,$r21
+
+       xor     $r20,$s0
+       xor     $r21,$s1
+        mov    $s2,$acc0
+        mov    $s3,$acc1
+       rol     \$24,$s0
+       rol     \$24,$s1
+        and    \$0x80808080,$acc0
+        and    \$0x80808080,$acc1
+       xor     $r20,$s0
+       xor     $r21,$s1
+        mov    $acc0,$t2
+        mov    $acc1,$t3
+       ror     \$16,$t0
+       ror     \$16,$t1
+        shr    \$7,$t2
+        lea    ($s2,$s2),$r20
+       xor     $t0,$s0
+       xor     $t1,$s1
+        shr    \$7,$t3
+        lea    ($s3,$s3),$r21
+       ror     \$8,$t0
+       ror     \$8,$t1
+        sub    $t2,$acc0
+        sub    $t3,$acc1
+       xor     $t0,$s0
+       xor     $t1,$s1
+
+       and     \$0xfefefefe,$r20
+       and     \$0xfefefefe,$r21
+       and     \$0x1b1b1b1b,$acc0
+       and     \$0x1b1b1b1b,$acc1
+       mov     $s2,$t2
+       mov     $s3,$t3
+       xor     $acc0,$r20
+       xor     $acc1,$r21
+
+       xor     $r20,$s2
+       xor     $r21,$s3
+       rol     \$24,$s2
+       rol     \$24,$s3
+       xor     $r20,$s2
+       xor     $r21,$s3
+       mov     0($sbox),$acc0                  # prefetch Te4
+       ror     \$16,$t2
+       ror     \$16,$t3
+       mov     64($sbox),$acc1
+       xor     $t2,$s2
+       xor     $t3,$s3
+       mov     128($sbox),$r20
+       ror     \$8,$t2
+       ror     \$8,$t3
+       mov     192($sbox),$r21
+       xor     $t2,$s2
+       xor     $t3,$s3
+___
+}
+
+$code.=<<___;
+.type  _x86_64_AES_encrypt_compact,\@abi-omnipotent
+.align 16
+_x86_64_AES_encrypt_compact:
+       lea     128($sbox),$inp                 # size optimization
+       mov     0-128($inp),$acc1               # prefetch Te4
+       mov     32-128($inp),$acc2
+       mov     64-128($inp),$t0
+       mov     96-128($inp),$t1
+       mov     128-128($inp),$acc1
+       mov     160-128($inp),$acc2
+       mov     192-128($inp),$t0
+       mov     224-128($inp),$t1
+       jmp     .Lenc_loop_compact
+.align 16
+.Lenc_loop_compact:
+               xor     0($key),$s0             # xor with key
+               xor     4($key),$s1
+               xor     8($key),$s2
+               xor     12($key),$s3
+               lea     16($key),$key
+___
+               &enccompactvert();
+$code.=<<___;
+               cmp     16(%rsp),$key
+               je      .Lenc_compact_done
+___
+               &enctransform();
+$code.=<<___;
+       jmp     .Lenc_loop_compact
+.align 16
+.Lenc_compact_done:
+       xor     0($key),$s0
+       xor     4($key),$s1
+       xor     8($key),$s2
+       xor     12($key),$s3
+       .byte   0xf3,0xc3                       # rep ret
+.size  _x86_64_AES_encrypt_compact,.-_x86_64_AES_encrypt_compact
+___
+
 # void AES_encrypt (const void *inp,void *out,const AES_KEY *key);
 $code.=<<___;
 .globl AES_encrypt
@@ -358,31 +596,57 @@ AES_encrypt:
        push    %r14
        push    %r15
 
-       mov     %rdx,$key
-       mov     %rdi,$inp
-       mov     %rsi,$out
-
-       .picmeup        $sbox
-       lea     AES_Te-.($sbox),$sbox
-
-       mov     0($inp),$s0
-       mov     4($inp),$s1
-       mov     8($inp),$s2
-       mov     12($inp),$s3
+       # allocate frame "above" key schedule
+       mov     %rsp,%r10
+       lea     -63(%rdx),%rcx  # %rdx is key argument
+       and     \$-64,%rsp
+       sub     %rsp,%rcx
+       neg     %rcx
+       and     \$0x3c0,%rcx
+       sub     %rcx,%rsp
+       sub     \$32,%rsp
 
-       call    _x86_64_AES_encrypt
+       mov     %rsi,16(%rsp)   # save out
+       mov     %r10,24(%rsp)   # save real stack pointer
+.Lenc_prologue:
 
-       mov     $s0,0($out)
+       mov     %rdx,$key
+       mov     240($key),$rnds # load rounds
+
+       mov     0(%rdi),$s0     # load input vector
+       mov     4(%rdi),$s1
+       mov     8(%rdi),$s2
+       mov     12(%rdi),$s3
+
+       shl     \$4,$rnds
+       lea     ($key,$rnds),%rbp
+       mov     $key,(%rsp)     # key schedule
+       mov     %rbp,8(%rsp)    # end of key schedule
+
+       # pick Te4 copy which can't "overlap" with stack frame or key schedule
+       lea     .LAES_Te+2048(%rip),$sbox
+       lea     768(%rsp),%rbp
+       sub     $sbox,%rbp
+       and     \$0x300,%rbp
+       lea     ($sbox,%rbp),$sbox
+
+       call    _x86_64_AES_encrypt_compact
+
+       mov     16(%rsp),$out   # restore out
+       mov     24(%rsp),%rsi   # restore saved stack pointer
+       mov     $s0,0($out)     # write output vector
        mov     $s1,4($out)
        mov     $s2,8($out)
        mov     $s3,12($out)
 
-       pop     %r15
-       pop     %r14
-       pop     %r13
-       pop     %r12
-       pop     %rbp
-       pop     %rbx
+       mov     (%rsi),%r15
+       mov     8(%rsi),%r14
+       mov     16(%rsi),%r13
+       mov     24(%rsi),%r12
+       mov     32(%rsi),%rbp
+       mov     40(%rsi),%rbx
+       lea     48(%rsi),%rsp
+.Lenc_epilogue:
        ret
 .size  AES_encrypt,.-AES_encrypt
 ___
@@ -453,19 +717,20 @@ sub declastvert()
 { my $t3="%r8d";       # zaps $inp!
 
 $code.=<<___;
+       lea     2048($sbox),$sbox       # size optimization
        movzb   `&lo("$s0")`,$acc0
        movzb   `&lo("$s1")`,$acc1
        movzb   `&lo("$s2")`,$acc2
-       movzb   2048($sbox,$acc0,1),$t0
-       movzb   2048($sbox,$acc1,1),$t1
-       movzb   2048($sbox,$acc2,1),$t2
+       movzb   ($sbox,$acc0,1),$t0
+       movzb   ($sbox,$acc1,1),$t1
+       movzb   ($sbox,$acc2,1),$t2
 
        movzb   `&lo("$s3")`,$acc0
        movzb   `&hi("$s3")`,$acc1
        movzb   `&hi("$s0")`,$acc2
-       movzb   2048($sbox,$acc0,1),$t3
-       movzb   2048($sbox,$acc1,1),$acc1       #$t0
-       movzb   2048($sbox,$acc2,1),$acc2       #$t1
+       movzb   ($sbox,$acc0,1),$t3
+       movzb   ($sbox,$acc1,1),$acc1   #$t0
+       movzb   ($sbox,$acc2,1),$acc2   #$t1
 
        shl     \$8,$acc1
        shl     \$8,$acc2
@@ -477,8 +742,8 @@ $code.=<<___;
        movzb   `&hi("$s1")`,$acc0
        movzb   `&hi("$s2")`,$acc1
        shr     \$16,$s0
-       movzb   2048($sbox,$acc0,1),$acc0       #$t2
-       movzb   2048($sbox,$acc1,1),$acc1       #$t3
+       movzb   ($sbox,$acc0,1),$acc0   #$t2
+       movzb   ($sbox,$acc1,1),$acc1   #$t3
 
        shl     \$8,$acc0
        shl     \$8,$acc1
@@ -490,9 +755,9 @@ $code.=<<___;
        movzb   `&lo("$s2")`,$acc0
        movzb   `&lo("$s3")`,$acc1
        movzb   `&lo("$s0")`,$acc2
-       movzb   2048($sbox,$acc0,1),$acc0       #$t0
-       movzb   2048($sbox,$acc1,1),$acc1       #$t1
-       movzb   2048($sbox,$acc2,1),$acc2       #$t2
+       movzb   ($sbox,$acc0,1),$acc0   #$t0
+       movzb   ($sbox,$acc1,1),$acc1   #$t1
+       movzb   ($sbox,$acc2,1),$acc2   #$t2
 
        shl     \$16,$acc0
        shl     \$16,$acc1
@@ -505,9 +770,9 @@ $code.=<<___;
        movzb   `&lo("$s1")`,$acc0
        movzb   `&hi("$s1")`,$acc1
        movzb   `&hi("$s2")`,$acc2
-       movzb   2048($sbox,$acc0,1),$acc0       #$t3
-       movzb   2048($sbox,$acc1,1),$acc1       #$t0
-       movzb   2048($sbox,$acc2,1),$acc2       #$t1
+       movzb   ($sbox,$acc0,1),$acc0   #$t3
+       movzb   ($sbox,$acc1,1),$acc1   #$t0
+       movzb   ($sbox,$acc2,1),$acc2   #$t1
 
        shl     \$16,$acc0
        shl     \$24,$acc1
@@ -520,8 +785,8 @@ $code.=<<___;
        movzb   `&hi("$s3")`,$acc0
        movzb   `&hi("$s0")`,$acc1
        mov     16+12($key),$s3
-       movzb   2048($sbox,$acc0,1),$acc0       #$t2
-       movzb   2048($sbox,$acc1,1),$acc1       #$t3
+       movzb   ($sbox,$acc0,1),$acc0   #$t2
+       movzb   ($sbox,$acc1,1),$acc1   #$t3
        mov     16+0($key),$s0
 
        shl     \$24,$acc0
@@ -532,6 +797,7 @@ $code.=<<___;
 
        mov     16+4($key),$s1
        mov     16+8($key),$s2
+       lea     -2048($sbox),$sbox
        xor     $t0,$s0
        xor     $t1,$s1
        xor     $t2,$s2
@@ -659,6 +925,260 @@ $code.=<<___;
 .size  _x86_64_AES_decrypt,.-_x86_64_AES_decrypt
 ___
 
+sub deccompactvert()
+{ my ($t3,$t4,$t5)=("%r8d","%r9d","%r13d");
+
+$code.=<<___;
+       movzb   `&lo("$s0")`,$t0
+       movzb   `&lo("$s1")`,$t1
+       movzb   `&lo("$s2")`,$t2
+       movzb   ($sbox,$t0,1),$t0
+       movzb   ($sbox,$t1,1),$t1
+       movzb   ($sbox,$t2,1),$t2
+
+       movzb   `&lo("$s3")`,$t3
+       movzb   `&hi("$s3")`,$acc0
+       movzb   `&hi("$s0")`,$acc1
+       movzb   ($sbox,$t3,1),$t3
+       movzb   ($sbox,$acc0,1),$t4     #$t0
+       movzb   ($sbox,$acc1,1),$t5     #$t1
+
+       movzb   `&hi("$s1")`,$acc2
+       movzb   `&hi("$s2")`,$acc0
+       shr     \$16,$s2
+       movzb   ($sbox,$acc2,1),$acc2   #$t2
+       movzb   ($sbox,$acc0,1),$acc0   #$t3
+       shr     \$16,$s3
+
+       movzb   `&lo("$s2")`,$acc1
+       shl     \$8,$t4
+       shl     \$8,$t5
+       movzb   ($sbox,$acc1,1),$acc1   #$t0
+       xor     $t4,$t0
+       xor     $t5,$t1
+
+       movzb   `&lo("$s3")`,$t4
+       shr     \$16,$s0
+       shr     \$16,$s1
+       movzb   `&lo("$s0")`,$t5
+       shl     \$8,$acc2
+       shl     \$8,$acc0
+       movzb   ($sbox,$t4,1),$t4       #$t1
+       movzb   ($sbox,$t5,1),$t5       #$t2
+       xor     $acc2,$t2
+       xor     $acc0,$t3
+
+       movzb   `&lo("$s1")`,$acc2
+       movzb   `&hi("$s1")`,$acc0
+       shl     \$16,$acc1
+       movzb   ($sbox,$acc2,1),$acc2   #$t3
+       movzb   ($sbox,$acc0,1),$acc0   #$t0
+       xor     $acc1,$t0
+
+       movzb   `&hi("$s2")`,$acc1
+       shl     \$16,$t4
+       shl     \$16,$t5
+       movzb   ($sbox,$acc1,1),$s1     #$t1
+       xor     $t4,$t1
+       xor     $t5,$t2
+
+       movzb   `&hi("$s3")`,$acc1
+       shr     \$8,$s0
+       shl     \$16,$acc2
+       movzb   ($sbox,$acc1,1),$s2     #$t2
+       movzb   ($sbox,$s0,1),$s3       #$t3
+       xor     $acc2,$t3
+
+       shl     \$24,$acc0
+       shl     \$24,$s1
+       shl     \$24,$s2
+       xor     $acc0,$t0
+       shl     \$24,$s3
+       xor     $t1,$s1
+       mov     $t0,$s0
+       xor     $t2,$s2
+       xor     $t3,$s3
+___
+}
+
+# parallelized version! input is pair of 64-bit values: %rax=s1.s0
+# and %rcx=s3.s2, output is four 32-bit values in %eax=s0, %ebx=s1,
+# %ecx=s2 and %edx=s3.
+sub dectransform()
+{ my ($tp10,$tp20,$tp40,$tp80,$acc0)=("%rax","%r8", "%r9", "%r10","%rbx");
+  my ($tp18,$tp28,$tp48,$tp88,$acc8)=("%rcx","%r11","%r12","%r13","%rdx");
+  my $prefetch = shift;
+
+$code.=<<___;
+       mov     $tp10,$acc0
+       mov     $tp18,$acc8
+       and     $mask80,$acc0
+       and     $mask80,$acc8
+       mov     $acc0,$tp40
+       mov     $acc8,$tp48
+       shr     \$7,$tp40
+       lea     ($tp10,$tp10),$tp20
+       shr     \$7,$tp48
+       lea     ($tp18,$tp18),$tp28
+       sub     $tp40,$acc0
+       sub     $tp48,$acc8
+       and     $maskfe,$tp20
+       and     $maskfe,$tp28
+       and     $mask1b,$acc0
+       and     $mask1b,$acc8
+       xor     $tp20,$acc0
+       xor     $tp28,$acc8
+       mov     $acc0,$tp20
+       mov     $acc8,$tp28
+
+       and     $mask80,$acc0
+       and     $mask80,$acc8
+       mov     $acc0,$tp80
+       mov     $acc8,$tp88
+       shr     \$7,$tp80
+       lea     ($tp20,$tp20),$tp40
+       shr     \$7,$tp88
+       lea     ($tp28,$tp28),$tp48
+       sub     $tp80,$acc0
+       sub     $tp88,$acc8
+       and     $maskfe,$tp40
+       and     $maskfe,$tp48
+       and     $mask1b,$acc0
+       and     $mask1b,$acc8
+       xor     $tp40,$acc0
+       xor     $tp48,$acc8
+       mov     $acc0,$tp40
+       mov     $acc8,$tp48
+
+       and     $mask80,$acc0
+       and     $mask80,$acc8
+       mov     $acc0,$tp80
+       mov     $acc8,$tp88
+       shr     \$7,$tp80
+        xor    $tp10,$tp20             # tp2^=tp1
+       shr     \$7,$tp88
+        xor    $tp18,$tp28             # tp2^=tp1
+       sub     $tp80,$acc0
+       sub     $tp88,$acc8
+       lea     ($tp40,$tp40),$tp80
+       lea     ($tp48,$tp48),$tp88
+        xor    $tp10,$tp40             # tp4^=tp1
+        xor    $tp18,$tp48             # tp4^=tp1
+       and     $maskfe,$tp80
+       and     $maskfe,$tp88
+       and     $mask1b,$acc0
+       and     $mask1b,$acc8
+       xor     $acc0,$tp80
+       xor     $acc8,$tp88
+
+       xor     $tp80,$tp10             # tp1^=tp8
+       xor     $tp88,$tp18             # tp1^=tp8
+       xor     $tp80,$tp20             # tp2^tp1^=tp8
+       xor     $tp88,$tp28             # tp2^tp1^=tp8
+       mov     $tp10,$acc0
+       mov     $tp18,$acc8
+       xor     $tp80,$tp40             # tp4^tp1^=tp8
+       xor     $tp88,$tp48             # tp4^tp1^=tp8
+       shr     \$32,$acc0
+       shr     \$32,$acc8
+       xor     $tp20,$tp80             # tp8^=tp8^tp2^tp1=tp2^tp1
+       xor     $tp28,$tp88             # tp8^=tp8^tp2^tp1=tp2^tp1
+       rol     \$8,`&LO("$tp10")`      # ROTATE(tp1^tp8,8)
+       rol     \$8,`&LO("$tp18")`      # ROTATE(tp1^tp8,8)
+       xor     $tp40,$tp80             # tp2^tp1^=tp8^tp4^tp1=tp8^tp4^tp2
+       xor     $tp48,$tp88             # tp2^tp1^=tp8^tp4^tp1=tp8^tp4^tp2
+
+       rol     \$8,`&LO("$acc0")`      # ROTATE(tp1^tp8,8)
+       rol     \$8,`&LO("$acc8")`      # ROTATE(tp1^tp8,8)
+       xor     `&LO("$tp80")`,`&LO("$tp10")`
+       xor     `&LO("$tp88")`,`&LO("$tp18")`
+       shr     \$32,$tp80
+       shr     \$32,$tp88
+       xor     `&LO("$tp80")`,`&LO("$acc0")`
+       xor     `&LO("$tp88")`,`&LO("$acc8")`
+
+       mov     $tp20,$tp80
+       mov     $tp28,$tp88
+       shr     \$32,$tp80
+       shr     \$32,$tp88
+       rol     \$24,`&LO("$tp20")`     # ROTATE(tp2^tp1^tp8,24)
+       rol     \$24,`&LO("$tp28")`     # ROTATE(tp2^tp1^tp8,24)
+       rol     \$24,`&LO("$tp80")`     # ROTATE(tp2^tp1^tp8,24)
+       rol     \$24,`&LO("$tp88")`     # ROTATE(tp2^tp1^tp8,24)
+       xor     `&LO("$tp20")`,`&LO("$tp10")`
+       xor     `&LO("$tp28")`,`&LO("$tp18")`
+       mov     $tp40,$tp20
+       mov     $tp48,$tp28
+       xor     `&LO("$tp80")`,`&LO("$acc0")`
+       xor     `&LO("$tp88")`,`&LO("$acc8")`
+
+       `"mov   0($sbox),$mask80"       if ($prefetch)`
+       shr     \$32,$tp20
+       shr     \$32,$tp28
+       `"mov   64($sbox),$maskfe"      if ($prefetch)`
+       rol     \$16,`&LO("$tp40")`     # ROTATE(tp4^tp1^tp8,16)
+       rol     \$16,`&LO("$tp48")`     # ROTATE(tp4^tp1^tp8,16)
+       `"mov   128($sbox),$mask1b"     if ($prefetch)`
+       rol     \$16,`&LO("$tp20")`     # ROTATE(tp4^tp1^tp8,16)
+       rol     \$16,`&LO("$tp28")`     # ROTATE(tp4^tp1^tp8,16)
+       `"mov   192($sbox),$tp80"       if ($prefetch)`
+       xor     `&LO("$tp40")`,`&LO("$tp10")`
+       xor     `&LO("$tp48")`,`&LO("$tp18")`
+       `"mov   256($sbox),$tp88"       if ($prefetch)`
+       xor     `&LO("$tp20")`,`&LO("$acc0")`
+       xor     `&LO("$tp28")`,`&LO("$acc8")`
+___
+}
+
+$code.=<<___;
+.type  _x86_64_AES_decrypt_compact,\@abi-omnipotent
+.align 16
+_x86_64_AES_decrypt_compact:
+       lea     128($sbox),$inp                 # size optimization
+       mov     0-128($inp),$acc1               # prefetch Td4
+       mov     32-128($inp),$acc2
+       mov     64-128($inp),$t0
+       mov     96-128($inp),$t1
+       mov     128-128($inp),$acc1
+       mov     160-128($inp),$acc2
+       mov     192-128($inp),$t0
+       mov     224-128($inp),$t1
+       jmp     .Ldec_loop_compact
+
+.align 16
+.Ldec_loop_compact:
+               xor     0($key),$s0             # xor with key
+               xor     4($key),$s1
+               xor     8($key),$s2
+               xor     12($key),$s3
+               lea     16($key),$key
+___
+               &deccompactvert();
+$code.=<<___;
+               cmp     16(%rsp),$key
+               je      .Ldec_compact_done
+
+               mov     256+0($sbox),$mask80
+               shl     \$32,%rbx
+               shl     \$32,%rdx
+               mov     256+8($sbox),$maskfe
+               or      %rbx,%rax
+               or      %rdx,%rcx
+               mov     256+16($sbox),$mask1b
+___
+               &dectransform(1);
+$code.=<<___;
+       jmp     .Ldec_loop_compact
+.align 16
+.Ldec_compact_done:
+       xor     0($key),$s0
+       xor     4($key),$s1
+       xor     8($key),$s2
+       xor     12($key),$s3
+       .byte   0xf3,0xc3                       # rep ret
+.size  _x86_64_AES_decrypt_compact,.-_x86_64_AES_decrypt_compact
+___
+
 # void AES_decrypt (const void *inp,void *out,const AES_KEY *key);
 $code.=<<___;
 .globl AES_decrypt
@@ -672,43 +1192,59 @@ AES_decrypt:
        push    %r14
        push    %r15
 
-       mov     %rdx,$key
-       mov     %rdi,$inp
-       mov     %rsi,$out
+       # allocate frame "above" key schedule
+       mov     %rsp,%r10
+       lea     -63(%rdx),%rcx  # %rdx is key argument
+       and     \$-64,%rsp
+       sub     %rsp,%rcx
+       neg     %rcx
+       and     \$0x3c0,%rcx
+       sub     %rcx,%rsp
+       sub     \$32,%rsp
 
-       .picmeup        $sbox
-       lea     AES_Td-.($sbox),$sbox
-
-       # prefetch Td4
-       lea     2048+128($sbox),$sbox;
-       mov     0-128($sbox),$s0
-       mov     32-128($sbox),$s1
-       mov     64-128($sbox),$s2
-       mov     96-128($sbox),$s3
-       mov     128-128($sbox),$s0
-       mov     160-128($sbox),$s1
-       mov     192-128($sbox),$s2
-       mov     224-128($sbox),$s3
-       lea     -2048-128($sbox),$sbox;
-
-       mov     0($inp),$s0
-       mov     4($inp),$s1
-       mov     8($inp),$s2
-       mov     12($inp),$s3
-
-       call    _x86_64_AES_decrypt
-
-       mov     $s0,0($out)
+       mov     %rsi,16(%rsp)   # save out
+       mov     %r10,24(%rsp)   # save real stack pointer
+.Ldec_prologue:
+
+       mov     %rdx,$key
+       mov     240($key),$rnds # load rounds
+
+       mov     0(%rdi),$s0     # load input vector
+       mov     4(%rdi),$s1
+       mov     8(%rdi),$s2
+       mov     12(%rdi),$s3
+
+       shl     \$4,$rnds
+       lea     ($key,$rnds),%rbp
+       mov     $key,(%rsp)     # key schedule
+       mov     %rbp,8(%rsp)    # end of key schedule
+
+       # pick Td4 copy which can't "overlap" with stack frame or key schedule
+       lea     .LAES_Td+2048(%rip),$sbox
+       lea     768(%rsp),%rbp
+       sub     $sbox,%rbp
+       and     \$0x300,%rbp
+       lea     ($sbox,%rbp),$sbox
+       shr     \$3,%rbp        # recall "magic" constants!
+       add     %rbp,$sbox
+
+       call    _x86_64_AES_decrypt_compact
+
+       mov     16(%rsp),$out   # restore out
+       mov     24(%rsp),%rsi   # restore saved stack pointer
+       mov     $s0,0($out)     # write output vector
        mov     $s1,4($out)
        mov     $s2,8($out)
        mov     $s3,12($out)
 
-       pop     %r15
-       pop     %r14
-       pop     %r13
-       pop     %r12
-       pop     %rbp
-       pop     %rbx
+       mov     (%rsi),%r15
+       mov     8(%rsi),%r14
+       mov     16(%rsi),%r13
+       mov     24(%rsi),%r12
+       mov     32(%rsi),%rbp
+       mov     40(%rsi),%rbx
+       lea     48(%rsi),%rsp
+.Ldec_epilogue:
        ret
 .size  AES_decrypt,.-AES_decrypt
 ___
@@ -718,27 +1254,26 @@ sub enckey()
 {
 $code.=<<___;
        movz    %dl,%esi                # rk[i]>>0
-       mov     2(%rbp,%rsi,8),%ebx
+       movzb   -128(%rbp,%rsi),%ebx
        movz    %dh,%esi                # rk[i]>>8
-       and     \$0xFF000000,%ebx
+       shl     \$24,%ebx
        xor     %ebx,%eax
 
-       mov     2(%rbp,%rsi,8),%ebx
+       movzb   -128(%rbp,%rsi),%ebx
        shr     \$16,%edx
-       and     \$0x000000FF,%ebx
        movz    %dl,%esi                # rk[i]>>16
        xor     %ebx,%eax
 
-       mov     0(%rbp,%rsi,8),%ebx
+       movzb   -128(%rbp,%rsi),%ebx
        movz    %dh,%esi                # rk[i]>>24
-       and     \$0x0000FF00,%ebx
+       shl     \$8,%ebx
        xor     %ebx,%eax
 
-       mov     0(%rbp,%rsi,8),%ebx
-       and     \$0x00FF0000,%ebx
+       movzb   -128(%rbp,%rsi),%ebx
+       shl     \$16,%ebx
        xor     %ebx,%eax
 
-       xor     2048(%rbp,%rcx,4),%eax          # rcon
+       xor     1024-128(%rbp,%rcx,4),%eax              # rcon
 ___
 }
 
@@ -751,13 +1286,23 @@ $code.=<<___;
 AES_set_encrypt_key:
        push    %rbx
        push    %rbp
+       push    %r12                    # redundant, but allows to share 
+       push    %r13                    # exception handler...
+       push    %r14
+       push    %r15
        sub     \$8,%rsp
+.Lenc_key_prologue:
 
        call    _x86_64_AES_set_encrypt_key
 
-       mov     8(%rsp),%rbp
-       mov     16(%rsp),%rbx
-       add     \$24,%rsp
+       mov     8(%rsp),%r15
+       mov     16(%rsp),%r14
+       mov     24(%rsp),%r13
+       mov     32(%rsp),%r12
+       mov     40(%rsp),%rbp
+       mov     48(%rsp),%rbx
+       add     \$56,%rsp
+.Lenc_key_epilogue:
        ret
 .size  AES_set_encrypt_key,.-AES_set_encrypt_key
 
@@ -773,8 +1318,18 @@ _x86_64_AES_set_encrypt_key:
        test    \$-1,%rdi
        jz      .Lbadpointer
 
-       .picmeup %rbp
-       lea     AES_Te-.(%rbp),%rbp
+       lea     .LAES_Te(%rip),%rbp
+       lea     2048+128(%rbp),%rbp
+
+       # prefetch Te4
+       mov     0-128(%rbp),%eax
+       mov     32-128(%rbp),%ebx
+       mov     64-128(%rbp),%r8d
+       mov     96-128(%rbp),%edx
+       mov     128-128(%rbp),%eax
+       mov     160-128(%rbp),%ebx
+       mov     192-128(%rbp),%r8d
+       mov     224-128(%rbp),%edx
 
        cmp     \$128,%ecx
        je      .L10rounds
@@ -786,15 +1341,12 @@ _x86_64_AES_set_encrypt_key:
        jmp     .Lexit
 
 .L10rounds:
-       mov     0(%rsi),%eax                    # copy first 4 dwords
-       mov     4(%rsi),%ebx
-       mov     8(%rsi),%ecx
-       mov     12(%rsi),%edx
-       mov     %eax,0(%rdi)
-       mov     %ebx,4(%rdi)
-       mov     %ecx,8(%rdi)
-       mov     %edx,12(%rdi)
+       mov     0(%rsi),%rax                    # copy first 4 dwords
+       mov     8(%rsi),%rdx
+       mov     %rax,0(%rdi)
+       mov     %rdx,8(%rdi)
 
+       shr     \$32,%rdx
        xor     %ecx,%ecx
        jmp     .L10shortcut
 .align 4
@@ -822,19 +1374,14 @@ $code.=<<___;
        jmp     .Lexit
 
 .L12rounds:
-       mov     0(%rsi),%eax                    # copy first 6 dwords
-       mov     4(%rsi),%ebx
-       mov     8(%rsi),%ecx
-       mov     12(%rsi),%edx
-       mov     %eax,0(%rdi)
-       mov     %ebx,4(%rdi)
-       mov     %ecx,8(%rdi)
-       mov     %edx,12(%rdi)
-       mov     16(%rsi),%ecx
-       mov     20(%rsi),%edx
-       mov     %ecx,16(%rdi)
-       mov     %edx,20(%rdi)
-
+       mov     0(%rsi),%rax                    # copy first 6 dwords
+       mov     8(%rsi),%rbx
+       mov     16(%rsi),%rdx
+       mov     %rax,0(%rdi)
+       mov     %rbx,8(%rdi)
+       mov     %rdx,16(%rdi)
+
+       shr     \$32,%rdx
        xor     %ecx,%ecx
        jmp     .L12shortcut
 .align 4
@@ -870,30 +1417,23 @@ $code.=<<___;
        jmp     .Lexit
 
 .L14rounds:            
-       mov     0(%rsi),%eax                    # copy first 8 dwords
-       mov     4(%rsi),%ebx
-       mov     8(%rsi),%ecx
-       mov     12(%rsi),%edx
-       mov     %eax,0(%rdi)
-       mov     %ebx,4(%rdi)
-       mov     %ecx,8(%rdi)
-       mov     %edx,12(%rdi)
-       mov     16(%rsi),%eax
-       mov     20(%rsi),%ebx
-       mov     24(%rsi),%ecx
-       mov     28(%rsi),%edx
-       mov     %eax,16(%rdi)
-       mov     %ebx,20(%rdi)
-       mov     %ecx,24(%rdi)
-       mov     %edx,28(%rdi)
-
+       mov     0(%rsi),%rax                    # copy first 8 dwords
+       mov     8(%rsi),%rbx
+       mov     16(%rsi),%rcx
+       mov     24(%rsi),%rdx
+       mov     %rax,0(%rdi)
+       mov     %rbx,8(%rdi)
+       mov     %rcx,16(%rdi)
+       mov     %rdx,24(%rdi)
+
+       shr     \$32,%rdx
        xor     %ecx,%ecx
        jmp     .L14shortcut
 .align 4
 .L14loop:
+               mov     0(%rdi),%eax                    # rk[0]
                mov     28(%rdi),%edx                   # rk[4]
 .L14shortcut:
-               mov     0(%rdi),%eax                    # rk[0]
 ___
                &enckey ();
 $code.=<<___;
@@ -912,24 +1452,23 @@ $code.=<<___;
                mov     %eax,%edx
                mov     16(%rdi),%eax                   # rk[4]
                movz    %dl,%esi                        # rk[11]>>0
-               mov     2(%rbp,%rsi,8),%ebx
+               movzb   -128(%rbp,%rsi),%ebx
                movz    %dh,%esi                        # rk[11]>>8
-               and     \$0x000000FF,%ebx
                xor     %ebx,%eax
 
-               mov     0(%rbp,%rsi,8),%ebx
+               movzb   -128(%rbp,%rsi),%ebx
                shr     \$16,%edx
-               and     \$0x0000FF00,%ebx
+               shl     \$8,%ebx
                movz    %dl,%esi                        # rk[11]>>16
                xor     %ebx,%eax
 
-               mov     0(%rbp,%rsi,8),%ebx
+               movzb   -128(%rbp,%rsi),%ebx
                movz    %dh,%esi                        # rk[11]>>24
-               and     \$0x00FF0000,%ebx
+               shl     \$16,%ebx
                xor     %ebx,%eax
 
-               mov     2(%rbp,%rsi,8),%ebx
-               and     \$0xFF000000,%ebx
+               movzb   -128(%rbp,%rsi),%ebx
+               shl     \$24,%ebx
                xor     %ebx,%eax
 
                mov     %eax,48(%rdi)                   # rk[12]
@@ -950,29 +1489,61 @@ $code.=<<___;
 .Lbadpointer:
        mov     \$-1,%rax
 .Lexit:
-       .byte   0xf3,0xc3               # rep ret
+       .byte   0xf3,0xc3                       # rep ret
 .size  _x86_64_AES_set_encrypt_key,.-_x86_64_AES_set_encrypt_key
 ___
 
-sub deckey()
+sub deckey_ref()
 { my ($i,$ptr,$te,$td) = @_;
+  my ($tp1,$tp2,$tp4,$tp8,$acc)=("%eax","%ebx","%edi","%edx","%r8d");
 $code.=<<___;
-       mov     $i($ptr),%eax
-       mov     %eax,%edx
-       movz    %ah,%ebx
-       shr     \$16,%edx
-       and     \$0xFF,%eax
-       movzb   2($te,%rax,8),%rax
-       movzb   2($te,%rbx,8),%rbx
-       mov     0($td,%rax,8),%eax
-       xor     3($td,%rbx,8),%eax
-       movzb   %dh,%ebx
-       and     \$0xFF,%edx
-       movzb   2($te,%rdx,8),%rdx
-       movzb   2($te,%rbx,8),%rbx
-       xor     2($td,%rdx,8),%eax
-       xor     1($td,%rbx,8),%eax
-       mov     %eax,$i($ptr)
+       mov     $i($ptr),$tp1
+       mov     $tp1,$acc
+       and     \$0x80808080,$acc
+       mov     $acc,$tp4
+       shr     \$7,$tp4
+       lea     0($tp1,$tp1),$tp2
+       sub     $tp4,$acc
+       and     \$0xfefefefe,$tp2
+       and     \$0x1b1b1b1b,$acc
+       xor     $tp2,$acc
+       mov     $acc,$tp2
+
+       and     \$0x80808080,$acc
+       mov     $acc,$tp8
+       shr     \$7,$tp8
+       lea     0($tp2,$tp2),$tp4
+       sub     $tp8,$acc
+       and     \$0xfefefefe,$tp4
+       and     \$0x1b1b1b1b,$acc
+        xor    $tp1,$tp2               # tp2^tp1
+       xor     $tp4,$acc
+       mov     $acc,$tp4
+
+       and     \$0x80808080,$acc
+       mov     $acc,$tp8
+       shr     \$7,$tp8
+       sub     $tp8,$acc
+       lea     0($tp4,$tp4),$tp8
+        xor    $tp1,$tp4               # tp4^tp1
+       and     \$0xfefefefe,$tp8
+       and     \$0x1b1b1b1b,$acc
+       xor     $acc,$tp8
+
+       xor     $tp8,$tp1               # tp1^tp8
+       rol     \$8,$tp1                # ROTATE(tp1^tp8,8)
+       xor     $tp8,$tp2               # tp2^tp1^tp8
+       xor     $tp8,$tp4               # tp4^tp1^tp8
+       xor     $tp2,$tp8
+       xor     $tp4,$tp8               # tp8^(tp8^tp4^tp1)^(tp8^tp2^tp1)=tp8^tp4^tp2
+
+       xor     $tp8,$tp1
+       rol     \$24,$tp2               # ROTATE(tp2^tp1^tp8,24)
+       xor     $tp2,$tp1
+       rol     \$16,$tp4               # ROTATE(tp4^tp1^tp8,16)
+       xor     $tp4,$tp1
+
+       mov     $tp1,$i($ptr)
 ___
 }
 
@@ -985,16 +1556,21 @@ $code.=<<___;
 AES_set_decrypt_key:
        push    %rbx
        push    %rbp
+       push    %r12
+       push    %r13
+       push    %r14
+       push    %r15
        push    %rdx                    # save key schedule
+.Ldec_key_prologue:
 
        call    _x86_64_AES_set_encrypt_key
        mov     (%rsp),%r8              # restore key schedule
        cmp     \$0,%eax
        jne     .Labort
 
-       mov     240(%r8),%ecx           # pull number of rounds
+       mov     240(%r8),%r14d          # pull number of rounds
        xor     %rdi,%rdi
-       lea     (%rdi,%rcx,4),%rcx
+       lea     (%rdi,%r14d,4),%rcx
        mov     %r8,%rsi
        lea     (%r8,%rcx,4),%rdi       # pointer to last chunk
 .align 4
@@ -1012,30 +1588,39 @@ AES_set_decrypt_key:
                cmp     %rsi,%rdi
        jne     .Linvert
 
-       .picmeup %r9
-       lea     AES_Td-.(%r9),%rdi
-       lea     AES_Te-AES_Td(%rdi),%r9
+       lea     .LAES_Te+2048+1024(%rip),%rax   # rcon
 
-       mov     %r8,%rsi
-       mov     240(%r8),%ecx           # pull number of rounds
-       sub     \$1,%ecx
+       mov     40(%rax),$mask80
+       mov     48(%rax),$maskfe
+       mov     56(%rax),$mask1b
+
+       mov     %r8,$key
+       sub     \$1,%r14d
 .align 4
 .Lpermute:
-               lea     16(%rsi),%rsi
+               lea     16($key),$key
+               mov     0($key),%rax
+               mov     8($key),%rcx
 ___
-               &deckey (0,"%rsi","%r9","%rdi");
-               &deckey (4,"%rsi","%r9","%rdi");
-               &deckey (8,"%rsi","%r9","%rdi");
-               &deckey (12,"%rsi","%r9","%rdi");
+               &dectransform ();
 $code.=<<___;
-               sub     \$1,%ecx
+               mov     %eax,0($key)
+               mov     %ebx,4($key)
+               mov     %ecx,8($key)
+               mov     %edx,12($key)
+               sub     \$1,%r14d
        jnz     .Lpermute
 
        xor     %rax,%rax
 .Labort:
-       mov     8(%rsp),%rbp
-       mov     16(%rsp),%rbx
-       add     \$24,%rsp
+       mov     8(%rsp),%r15
+       mov     16(%rsp),%r14
+       mov     24(%rsp),%r13
+       mov     32(%rsp),%r12
+       mov     40(%rsp),%rbp
+       mov     48(%rsp),%rbx
+       add     \$56,%rsp
+.Ldec_key_epilogue:
        ret
 .size  AES_set_decrypt_key,.-AES_set_decrypt_key
 ___
@@ -1046,47 +1631,59 @@ ___
 {
 # stack frame layout
 # -8(%rsp)             return address
-my $_rsp="0(%rsp)";            # saved %rsp
-my $_len="8(%rsp)";            # copy of 3rd parameter, length
-my $_key="16(%rsp)";           # copy of 4th parameter, key
-my $_ivp="24(%rsp)";           # copy of 5th parameter, ivp
-my $keyp="32(%rsp)";           # one to pass as $key
-my $ivec="40(%rsp)";           # ivec[16]
-my $aes_key="56(%rsp)";                # copy of aes_key
-my $mark="56+240(%rsp)";       # copy of aes_key->rounds
+my $keyp="0(%rsp)";            # one to pass as $key
+my $keyend="8(%rsp)";          # &(keyp->rd_key[4*keyp->rounds])
+my $_rsp="16(%rsp)";           # saved %rsp
+my $_inp="24(%rsp)";           # copy of 1st parameter, inp
+my $_out="32(%rsp)";           # copy of 2nd parameter, out
+my $_len="40(%rsp)";           # copy of 3rd parameter, length
+my $_key="48(%rsp)";           # copy of 4th parameter, key
+my $_ivp="56(%rsp)";           # copy of 5th parameter, ivp
+my $ivec="64(%rsp)";           # ivec[16]
+my $aes_key="80(%rsp)";                # copy of aes_key
+my $mark="80+240(%rsp)";       # copy of aes_key->rounds
 
 $code.=<<___;
 .globl AES_cbc_encrypt
 .type  AES_cbc_encrypt,\@function,6
 .align 16
+.extern        OPENSSL_ia32cap_P
 AES_cbc_encrypt:
        cmp     \$0,%rdx        # check length
-       je      .Lcbc_just_ret
+       je      .Lcbc_epilogue
+       pushfq
        push    %rbx
        push    %rbp
        push    %r12
        push    %r13
        push    %r14
        push    %r15
-       pushfq
+.Lcbc_prologue:
+
        cld
        mov     %r9d,%r9d       # clear upper half of enc
 
-       .picmeup $sbox
-.Lcbc_pic_point:
-
+       lea     .LAES_Te(%rip),$sbox
        cmp     \$0,%r9
-       je      .LDECRYPT
-
-       lea     AES_Te-.Lcbc_pic_point($sbox),$sbox
+       jne     .Lcbc_picked_te
+       lea     .LAES_Td(%rip),$sbox
+.Lcbc_picked_te:
+
+       mov     OPENSSL_ia32cap_P(%rip),%r10d
+       cmp     \$$speed_limit,%rdx
+       jb      .Lcbc_slow_prologue
+       test    \$15,%rdx
+       jnz     .Lcbc_slow_prologue
+       bt      \$28,%r10d
+       jc      .Lcbc_slow_prologue
 
        # allocate aligned stack frame...
-       lea     -64-248(%rsp),$key
+       lea     -88-248(%rsp),$key
        and     \$-64,$key
 
-       # ... and make it doesn't alias with AES_Te modulo 4096
+       # ... and make sure it doesn't alias with AES_T[ed] modulo 4096
        mov     $sbox,%r10
-       lea     2048($sbox),%r11
+       lea     2304($sbox),%r11
        mov     $key,%r12
        and     \$0xFFF,%r10    # s = $sbox&0xfff
        and     \$0xFFF,%r11    # e = ($sbox+2048)&0xfff
@@ -1106,22 +1703,27 @@ AES_cbc_encrypt:
 .Lcbc_te_ok:
 
        xchg    %rsp,$key
-       add     \$8,%rsp        # reserve for return address!
+       #add    \$8,%rsp        # reserve for return address!
        mov     $key,$_rsp      # save %rsp
+.Lcbc_fast_body:
+       mov     %rdi,$_inp      # save copy of inp
+       mov     %rsi,$_out      # save copy of out
        mov     %rdx,$_len      # save copy of len
        mov     %rcx,$_key      # save copy of key
        mov     %r8,$_ivp       # save copy of ivp
        movl    \$0,$mark       # copy of aes_key->rounds = 0;
        mov     %r8,%rbp        # rearrange input arguments
+       mov     %r9,%rbx
        mov     %rsi,$out
        mov     %rdi,$inp
        mov     %rcx,$key
 
+       mov     240($key),%eax          # key->rounds
        # do we copy key schedule to stack?
        mov     $key,%r10
        sub     $sbox,%r10
        and     \$0xfff,%r10
-       cmp     \$2048,%r10
+       cmp     \$2304,%r10
        jb      .Lcbc_do_ecopy
        cmp     \$4096-248,%r10
        jb      .Lcbc_skip_ecopy
@@ -1132,12 +1734,11 @@ AES_cbc_encrypt:
                lea     $aes_key,$key
                mov     \$240/8,%ecx
                .long   0x90A548F3      # rep movsq
-               mov     (%rsi),%eax     # copy aes_key->rounds
-               mov     %eax,(%rdi)
+               mov     %eax,(%rdi)     # copy aes_key->rounds
 .Lcbc_skip_ecopy:
        mov     $key,$keyp      # save key pointer
 
-       mov     \$16,%ecx
+       mov     \$18,%ecx
 .align 4
 .Lcbc_prefetch_te:
                mov     0($sbox),%r10
@@ -1147,184 +1748,77 @@ AES_cbc_encrypt:
                lea     128($sbox),$sbox
                sub     \$1,%ecx
        jnz     .Lcbc_prefetch_te
-       sub     \$2048,$sbox
+       lea     -2304($sbox),$sbox
 
-       test    \$-16,%rdx              # check upon length
-       mov     %rdx,%r10
+       cmp     \$0,%rbx
+       je      .LFAST_DECRYPT
+
+#----------------------------- ENCRYPT -----------------------------#
        mov     0(%rbp),$s0             # load iv
        mov     4(%rbp),$s1
        mov     8(%rbp),$s2
        mov     12(%rbp),$s3
-       jz      .Lcbc_enc_tail          # short input...
 
 .align 4
-.Lcbc_enc_loop:
+.Lcbc_fast_enc_loop:
                xor     0($inp),$s0
                xor     4($inp),$s1
                xor     8($inp),$s2
                xor     12($inp),$s3
-               mov     $inp,$ivec      # if ($verticalspin) save inp
-
                mov     $keyp,$key      # restore key
+               mov     $inp,$_inp      # if ($verticalspin) save inp
+
                call    _x86_64_AES_encrypt
 
-               mov     $ivec,$inp      # if ($verticalspin) restore inp
+               mov     $_inp,$inp      # if ($verticalspin) restore inp
+               mov     $_len,%r10
                mov     $s0,0($out)
                mov     $s1,4($out)
                mov     $s2,8($out)
                mov     $s3,12($out)
 
-               mov     $_len,%r10
                lea     16($inp),$inp
                lea     16($out),$out
                sub     \$16,%r10
                test    \$-16,%r10
                mov     %r10,$_len
-       jnz     .Lcbc_enc_loop
-       test    \$15,%r10
-       jnz     .Lcbc_enc_tail
+       jnz     .Lcbc_fast_enc_loop
        mov     $_ivp,%rbp      # restore ivp
        mov     $s0,0(%rbp)     # save ivec
        mov     $s1,4(%rbp)
        mov     $s2,8(%rbp)
        mov     $s3,12(%rbp)
 
-.align 4
-.Lcbc_cleanup:
-       cmpl    \$0,$mark       # was the key schedule copied?
-       lea     $aes_key,%rdi
-       je      .Lcbc_exit
-               mov     \$240/8,%ecx
-               xor     %rax,%rax
-               .long   0x90AB48F3      # rep stosq
-.Lcbc_exit:
-       mov     $_rsp,%rsp
-       popfq
-       pop     %r15
-       pop     %r14
-       pop     %r13
-       pop     %r12
-       pop     %rbp
-       pop     %rbx
-.Lcbc_just_ret:
-       ret
-.align 4
-.Lcbc_enc_tail:
-       mov     %rax,%r11
-       mov     %rcx,%r12
-       mov     %r10,%rcx
-       mov     $inp,%rsi
-       mov     $out,%rdi
-       .long   0xF689A4F3              # rep movsb
-       mov     \$16,%rcx               # zero tail
-       sub     %r10,%rcx
-       xor     %rax,%rax
-       .long   0xF689AAF3              # rep stosb
-       mov     $out,$inp               # this is not a mistake!
-       movq    \$16,$_len              # len=16
-       mov     %r11,%rax
-       mov     %r12,%rcx
-       jmp     .Lcbc_enc_loop          # one more spin...
+       jmp     .Lcbc_fast_cleanup
+
 #----------------------------- DECRYPT -----------------------------#
 .align 16
-.LDECRYPT:
-       lea     AES_Td-.Lcbc_pic_point($sbox),$sbox
-
-       # allocate aligned stack frame...
-       lea     -64-248(%rsp),$key
-       and     \$-64,$key
-
-       # ... and make it doesn't alias with AES_Td modulo 4096
-       mov     $sbox,%r10
-       lea     2304($sbox),%r11
-       mov     $key,%r12
-       and     \$0xFFF,%r10    # s = $sbox&0xfff
-       and     \$0xFFF,%r11    # e = ($sbox+2048+256)&0xfff
-       and     \$0xFFF,%r12    # p = %rsp&0xfff
+.LFAST_DECRYPT:
+       cmp     $inp,$out
+       je      .Lcbc_fast_dec_in_place
 
-       cmp     %r11,%r12       # if (p=>e) %rsp =- (p-e);
-       jb      .Lcbc_td_break_out
-       sub     %r11,%r12
-       sub     %r12,$key
-       jmp     .Lcbc_td_ok
-.Lcbc_td_break_out:            # else %rsp -= (p-s)&0xfff + framesz
-       sub     %r10,%r12
-       and     \$0xFFF,%r12
-       add     \$320,%r12
-       sub     %r12,$key
+       mov     %rbp,$ivec
 .align 4
-.Lcbc_td_ok:
+.Lcbc_fast_dec_loop:
+               mov     0($inp),$s0     # read input
+               mov     4($inp),$s1
+               mov     8($inp),$s2
+               mov     12($inp),$s3
+               mov     $keyp,$key      # restore key
+               mov     $inp,$_inp      # if ($verticalspin) save inp
 
-       xchg    %rsp,$key
-       add     \$8,%rsp        # reserve for return address!
-       mov     $key,$_rsp      # save %rsp
-       mov     %rdx,$_len      # save copy of len
-       mov     %rcx,$_key      # save copy of key
-       mov     %r8,$_ivp       # save copy of ivp
-       movl    \$0,$mark       # copy of aes_key->rounds = 0;
-       mov     %r8,%rbp        # rearrange input arguments
-       mov     %rsi,$out
-       mov     %rdi,$inp
-       mov     %rcx,$key
-
-       # do we copy key schedule to stack?
-       mov     $key,%r10
-       sub     $sbox,%r10
-       and     \$0xfff,%r10
-       cmp     \$2304,%r10
-       jb      .Lcbc_do_dcopy
-       cmp     \$4096-248,%r10
-       jb      .Lcbc_skip_dcopy
-.align 4
-.Lcbc_do_dcopy:
-               mov     $key,%rsi
-               lea     $aes_key,%rdi
-               lea     $aes_key,$key
-               mov     \$240/8,%ecx
-               .long   0x90A548F3      # rep movsq
-               mov     (%rsi),%eax     # copy aes_key->rounds
-               mov     %eax,(%rdi)
-.Lcbc_skip_dcopy:
-       mov     $key,$keyp      # save key pointer
-
-       mov     \$18,%ecx
-.align 4
-.Lcbc_prefetch_td:
-               mov     0($sbox),%r10
-               mov     32($sbox),%r11
-               mov     64($sbox),%r12
-               mov     96($sbox),%r13
-               lea     128($sbox),$sbox
-               sub     \$1,%ecx
-       jnz     .Lcbc_prefetch_td
-       sub     \$2304,$sbox
-
-       cmp     $inp,$out
-       je      .Lcbc_dec_in_place
-
-       mov     %rbp,$ivec
-.align 4
-.Lcbc_dec_loop:
-               mov     0($inp),$s0             # read input
-               mov     4($inp),$s1
-               mov     8($inp),$s2
-               mov     12($inp),$s3
-               mov     $inp,8+$ivec    # if ($verticalspin) save inp
-
-               mov     $keyp,$key      # restore key
-               call    _x86_64_AES_decrypt
+               call    _x86_64_AES_decrypt
 
                mov     $ivec,%rbp      # load ivp
-               mov     8+$ivec,$inp    # if ($verticalspin) restore inp
+               mov     $_inp,$inp      # if ($verticalspin) restore inp
+               mov     $_len,%r10      # load len
                xor     0(%rbp),$s0     # xor iv
                xor     4(%rbp),$s1
                xor     8(%rbp),$s2
                xor     12(%rbp),$s3
                mov     $inp,%rbp       # current input, next iv
 
-               mov     $_len,%r10      # load len
                sub     \$16,%r10
-               jc      .Lcbc_dec_partial
                mov     %r10,$_len      # update len
                mov     %rbp,$ivec      # update ivp
 
@@ -1335,81 +1829,281 @@ AES_cbc_encrypt:
 
                lea     16($inp),$inp
                lea     16($out),$out
-       jnz     .Lcbc_dec_loop
-.Lcbc_dec_end:
+       jnz     .Lcbc_fast_dec_loop
        mov     $_ivp,%r12              # load user ivp
        mov     0(%rbp),%r10            # load iv
        mov     8(%rbp),%r11
        mov     %r10,0(%r12)            # copy back to user
        mov     %r11,8(%r12)
-       jmp     .Lcbc_cleanup
-
-.align 4
-.Lcbc_dec_partial:
-       mov     $s0,0+$ivec             # dump output to stack
-       mov     $s1,4+$ivec
-       mov     $s2,8+$ivec
-       mov     $s3,12+$ivec
-       mov     $out,%rdi
-       lea     $ivec,%rsi
-       mov     \$16,%rcx
-       add     %r10,%rcx               # number of bytes to copy
-       .long   0xF689A4F3              # rep movsb
-       jmp     .Lcbc_dec_end
+       jmp     .Lcbc_fast_cleanup
 
 .align 16
-.Lcbc_dec_in_place:
+.Lcbc_fast_dec_in_place:
+       mov     0(%rbp),%r10            # copy iv to stack
+       mov     8(%rbp),%r11
+       mov     %r10,0+$ivec
+       mov     %r11,8+$ivec
+.align 4
+.Lcbc_fast_dec_in_place_loop:
                mov     0($inp),$s0     # load input
                mov     4($inp),$s1
                mov     8($inp),$s2
                mov     12($inp),$s3
+               mov     $keyp,$key      # restore key
+               mov     $inp,$_inp      # if ($verticalspin) save inp
 
-               mov     $inp,$ivec      # if ($verticalspin) save inp
-               mov     $keyp,$key
                call    _x86_64_AES_decrypt
 
-               mov     $ivec,$inp      # if ($verticalspin) restore inp
-               mov     $_ivp,%rbp
-               xor     0(%rbp),$s0
-               xor     4(%rbp),$s1
-               xor     8(%rbp),$s2
-               xor     12(%rbp),$s3
+               mov     $_inp,$inp      # if ($verticalspin) restore inp
+               mov     $_len,%r10
+               xor     0+$ivec,$s0
+               xor     4+$ivec,$s1
+               xor     8+$ivec,$s2
+               xor     12+$ivec,$s3
 
-               mov     0($inp),%r10    # copy input to iv
-               mov     8($inp),%r11
-               mov     %r10,0(%rbp)
-               mov     %r11,8(%rbp)
+               mov     0($inp),%r11    # load input
+               mov     8($inp),%r12
+               sub     \$16,%r10
+               jz      .Lcbc_fast_dec_in_place_done
+
+               mov     %r11,0+$ivec    # copy input to iv
+               mov     %r12,8+$ivec
 
                mov     $s0,0($out)     # save output [zaps input]
                mov     $s1,4($out)
                mov     $s2,8($out)
                mov     $s3,12($out)
 
-               mov     $_len,%rcx
                lea     16($inp),$inp
                lea     16($out),$out
-               sub     \$16,%rcx
-               jc      .Lcbc_dec_in_place_partial
-               mov     %rcx,$_len
-       jnz     .Lcbc_dec_in_place
-       jmp     .Lcbc_cleanup
+               mov     %r10,$_len
+       jmp     .Lcbc_fast_dec_in_place_loop
+.Lcbc_fast_dec_in_place_done:
+       mov     $_ivp,%rdi
+       mov     %r11,0(%rdi)    # copy iv back to user
+       mov     %r12,8(%rdi)
+
+       mov     $s0,0($out)     # save output [zaps input]
+       mov     $s1,4($out)
+       mov     $s2,8($out)
+       mov     $s3,12($out)
 
 .align 4
-.Lcbc_dec_in_place_partial:
-       # one can argue if this is actually required
-       lea     ($out,%rcx),%rdi
-       lea     (%rbp,%rcx),%rsi
-       neg     %rcx
-       .long   0xF689A4F3      # rep movsb     # restore tail
-       jmp     .Lcbc_cleanup
+.Lcbc_fast_cleanup:
+       cmpl    \$0,$mark       # was the key schedule copied?
+       lea     $aes_key,%rdi
+       je      .Lcbc_exit
+               mov     \$240/8,%ecx
+               xor     %rax,%rax
+               .long   0x90AB48F3      # rep stosq
+
+       jmp     .Lcbc_exit
+
+#--------------------------- SLOW ROUTINE ---------------------------#
+.align 16
+.Lcbc_slow_prologue:
+       # allocate aligned stack frame...
+       lea     -88(%rsp),%rbp
+       and     \$-64,%rbp
+       # ... just "above" key schedule
+       lea     -88-63(%rcx),%r10
+       sub     %rbp,%r10
+       neg     %r10
+       and     \$0x3c0,%r10
+       sub     %r10,%rbp
+
+       xchg    %rsp,%rbp
+       #add    \$8,%rsp        # reserve for return address!
+       mov     %rbp,$_rsp      # save %rsp
+.Lcbc_slow_body:
+       #mov    %rdi,$_inp      # save copy of inp
+       #mov    %rsi,$_out      # save copy of out
+       #mov    %rdx,$_len      # save copy of len
+       #mov    %rcx,$_key      # save copy of key
+       mov     %r8,$_ivp       # save copy of ivp
+       mov     %r8,%rbp        # rearrange input arguments
+       mov     %r9,%rbx
+       mov     %rsi,$out
+       mov     %rdi,$inp
+       mov     %rcx,$key
+       mov     %rdx,%r10
+
+       mov     240($key),%eax
+       mov     $key,$keyp      # save key pointer
+       shl     \$4,%eax
+       lea     ($key,%rax),%rax
+       mov     %rax,$keyend
+
+       # pick Te4 copy which can't "overlap" with stack frame or key scdedule
+       lea     2048($sbox),$sbox
+       lea     768-8(%rsp),%rax
+       sub     $sbox,%rax
+       and     \$0x300,%rax
+       lea     ($sbox,%rax),$sbox
+
+       cmp     \$0,%rbx
+       je      .LSLOW_DECRYPT
+
+#--------------------------- SLOW ENCRYPT ---------------------------#
+       test    \$-16,%r10              # check upon length
+       mov     0(%rbp),$s0             # load iv
+       mov     4(%rbp),$s1
+       mov     8(%rbp),$s2
+       mov     12(%rbp),$s3
+       jz      .Lcbc_slow_enc_tail     # short input...
+
+.align 4
+.Lcbc_slow_enc_loop:
+               xor     0($inp),$s0
+               xor     4($inp),$s1
+               xor     8($inp),$s2
+               xor     12($inp),$s3
+               mov     $keyp,$key      # restore key
+               mov     $inp,$_inp      # save inp
+               mov     $out,$_out      # save out
+               mov     %r10,$_len      # save len
+
+               call    _x86_64_AES_encrypt_compact
+
+               mov     $_inp,$inp      # restore inp
+               mov     $_out,$out      # restore out
+               mov     $_len,%r10      # restore len
+               mov     $s0,0($out)
+               mov     $s1,4($out)
+               mov     $s2,8($out)
+               mov     $s3,12($out)
+
+               lea     16($inp),$inp
+               lea     16($out),$out
+               sub     \$16,%r10
+               test    \$-16,%r10
+       jnz     .Lcbc_slow_enc_loop
+       test    \$15,%r10
+       jnz     .Lcbc_slow_enc_tail
+       mov     $_ivp,%rbp      # restore ivp
+       mov     $s0,0(%rbp)     # save ivec
+       mov     $s1,4(%rbp)
+       mov     $s2,8(%rbp)
+       mov     $s3,12(%rbp)
+
+       jmp     .Lcbc_exit
+
+.align 4
+.Lcbc_slow_enc_tail:
+       mov     %rax,%r11
+       mov     %rcx,%r12
+       mov     %r10,%rcx
+       mov     $inp,%rsi
+       mov     $out,%rdi
+       .long   0x9066A4F3              # rep movsb
+       mov     \$16,%rcx               # zero tail
+       sub     %r10,%rcx
+       xor     %rax,%rax
+       .long   0x9066AAF3              # rep stosb
+       mov     $out,$inp               # this is not a mistake!
+       mov     \$16,%r10               # len=16
+       mov     %r11,%rax
+       mov     %r12,%rcx
+       jmp     .Lcbc_slow_enc_loop     # one more spin...
+#--------------------------- SLOW DECRYPT ---------------------------#
+.align 16
+.LSLOW_DECRYPT:
+       shr     \$3,%rax
+       add     %rax,$sbox              # recall "magic" constants!
+
+       mov     0(%rbp),%r11            # copy iv to stack
+       mov     8(%rbp),%r12
+       mov     %r11,0+$ivec
+       mov     %r12,8+$ivec
+
+.align 4
+.Lcbc_slow_dec_loop:
+               mov     0($inp),$s0     # load input
+               mov     4($inp),$s1
+               mov     8($inp),$s2
+               mov     12($inp),$s3
+               mov     $keyp,$key      # restore key
+               mov     $inp,$_inp      # save inp
+               mov     $out,$_out      # save out
+               mov     %r10,$_len      # save len
+
+               call    _x86_64_AES_decrypt_compact
+
+               mov     $_inp,$inp      # restore inp
+               mov     $_out,$out      # restore out
+               mov     $_len,%r10
+               xor     0+$ivec,$s0
+               xor     4+$ivec,$s1
+               xor     8+$ivec,$s2
+               xor     12+$ivec,$s3
+
+               mov     0($inp),%r11    # load input
+               mov     8($inp),%r12
+               sub     \$16,%r10
+               jc      .Lcbc_slow_dec_partial
+               jz      .Lcbc_slow_dec_done
+
+               mov     %r11,0+$ivec    # copy input to iv
+               mov     %r12,8+$ivec
+
+               mov     $s0,0($out)     # save output [can zap input]
+               mov     $s1,4($out)
+               mov     $s2,8($out)
+               mov     $s3,12($out)
+
+               lea     16($inp),$inp
+               lea     16($out),$out
+       jmp     .Lcbc_slow_dec_loop
+.Lcbc_slow_dec_done:
+       mov     $_ivp,%rdi
+       mov     %r11,0(%rdi)            # copy iv back to user
+       mov     %r12,8(%rdi)
+
+       mov     $s0,0($out)             # save output [can zap input]
+       mov     $s1,4($out)
+       mov     $s2,8($out)
+       mov     $s3,12($out)
+
+       jmp     .Lcbc_exit
+
+.align 4
+.Lcbc_slow_dec_partial:
+       mov     $_ivp,%rdi
+       mov     %r11,0(%rdi)            # copy iv back to user
+       mov     %r12,8(%rdi)
+
+       mov     $s0,0+$ivec             # save output to stack
+       mov     $s1,4+$ivec
+       mov     $s2,8+$ivec
+       mov     $s3,12+$ivec
+
+       mov     $out,%rdi
+       lea     $ivec,%rsi
+       lea     16(%r10),%rcx
+       .long   0x9066A4F3      # rep movsb
+       jmp     .Lcbc_exit
+
+.align 16
+.Lcbc_exit:
+       mov     $_rsp,%rsi
+       mov     (%rsi),%r15
+       mov     8(%rsi),%r14
+       mov     16(%rsi),%r13
+       mov     24(%rsi),%r12
+       mov     32(%rsi),%rbp
+       mov     40(%rsi),%rbx
+       lea     48(%rsi),%rsp
+.Lcbc_popfq:
+       popfq
+.Lcbc_epilogue:
+       ret
 .size  AES_cbc_encrypt,.-AES_cbc_encrypt
 ___
 }
 
 $code.=<<___;
-.globl AES_Te
 .align 64
-AES_Te:
+.LAES_Te:
 ___
        &_data_word(0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6);
        &_data_word(0x0df2f2ff, 0xbd6b6bd6, 0xb16f6fde, 0x54c5c591);
@@ -1475,16 +2169,149 @@ ___
        &_data_word(0xdabfbf65, 0x31e6e6d7, 0xc6424284, 0xb86868d0);
        &_data_word(0xc3414182, 0xb0999929, 0x772d2d5a, 0x110f0f1e);
        &_data_word(0xcbb0b07b, 0xfc5454a8, 0xd6bbbb6d, 0x3a16162c);
+
+#Te4   # four copies of Te4 to choose from to avoid L1 aliasing
+       &data_byte(0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5);
+       &data_byte(0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76);
+       &data_byte(0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0);
+       &data_byte(0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0);
+       &data_byte(0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc);
+       &data_byte(0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15);
+       &data_byte(0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a);
+       &data_byte(0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75);
+       &data_byte(0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0);
+       &data_byte(0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84);
+       &data_byte(0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b);
+       &data_byte(0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf);
+       &data_byte(0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85);
+       &data_byte(0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8);
+       &data_byte(0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5);
+       &data_byte(0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2);
+       &data_byte(0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17);
+       &data_byte(0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73);
+       &data_byte(0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88);
+       &data_byte(0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb);
+       &data_byte(0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c);
+       &data_byte(0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79);
+       &data_byte(0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9);
+       &data_byte(0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08);
+       &data_byte(0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6);
+       &data_byte(0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a);
+       &data_byte(0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e);
+       &data_byte(0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e);
+       &data_byte(0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94);
+       &data_byte(0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf);
+       &data_byte(0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68);
+       &data_byte(0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16);
+
+       &data_byte(0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5);
+       &data_byte(0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76);
+       &data_byte(0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0);
+       &data_byte(0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0);
+       &data_byte(0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc);
+       &data_byte(0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15);
+       &data_byte(0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a);
+       &data_byte(0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75);
+       &data_byte(0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0);
+       &data_byte(0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84);
+       &data_byte(0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b);
+       &data_byte(0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf);
+       &data_byte(0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85);
+       &data_byte(0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8);
+       &data_byte(0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5);
+       &data_byte(0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2);
+       &data_byte(0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17);
+       &data_byte(0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73);
+       &data_byte(0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88);
+       &data_byte(0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb);
+       &data_byte(0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c);
+       &data_byte(0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79);
+       &data_byte(0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9);
+       &data_byte(0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08);
+       &data_byte(0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6);
+       &data_byte(0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a);
+       &data_byte(0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e);
+       &data_byte(0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e);
+       &data_byte(0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94);
+       &data_byte(0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf);
+       &data_byte(0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68);
+       &data_byte(0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16);
+
+       &data_byte(0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5);
+       &data_byte(0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76);
+       &data_byte(0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0);
+       &data_byte(0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0);
+       &data_byte(0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc);
+       &data_byte(0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15);
+       &data_byte(0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a);
+       &data_byte(0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75);
+       &data_byte(0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0);
+       &data_byte(0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84);
+       &data_byte(0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b);
+       &data_byte(0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf);
+       &data_byte(0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85);
+       &data_byte(0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8);
+       &data_byte(0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5);
+       &data_byte(0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2);
+       &data_byte(0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17);
+       &data_byte(0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73);
+       &data_byte(0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88);
+       &data_byte(0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb);
+       &data_byte(0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c);
+       &data_byte(0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79);
+       &data_byte(0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9);
+       &data_byte(0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08);
+       &data_byte(0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6);
+       &data_byte(0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a);
+       &data_byte(0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e);
+       &data_byte(0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e);
+       &data_byte(0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94);
+       &data_byte(0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf);
+       &data_byte(0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68);
+       &data_byte(0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16);
+
+       &data_byte(0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5);
+       &data_byte(0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76);
+       &data_byte(0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0);
+       &data_byte(0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0);
+       &data_byte(0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc);
+       &data_byte(0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15);
+       &data_byte(0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a);
+       &data_byte(0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75);
+       &data_byte(0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0);
+       &data_byte(0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84);
+       &data_byte(0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b);
+       &data_byte(0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf);
+       &data_byte(0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85);
+       &data_byte(0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8);
+       &data_byte(0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5);
+       &data_byte(0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2);
+       &data_byte(0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17);
+       &data_byte(0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73);
+       &data_byte(0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88);
+       &data_byte(0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb);
+       &data_byte(0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c);
+       &data_byte(0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79);
+       &data_byte(0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9);
+       &data_byte(0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08);
+       &data_byte(0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6);
+       &data_byte(0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a);
+       &data_byte(0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e);
+       &data_byte(0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e);
+       &data_byte(0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94);
+       &data_byte(0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf);
+       &data_byte(0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68);
+       &data_byte(0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16);
 #rcon:
 $code.=<<___;
        .long   0x00000001, 0x00000002, 0x00000004, 0x00000008
        .long   0x00000010, 0x00000020, 0x00000040, 0x00000080
-       .long   0x0000001b, 0x00000036, 0, 0, 0, 0, 0, 0
+       .long   0x0000001b, 0x00000036, 0x80808080, 0x80808080
+       .long   0xfefefefe, 0xfefefefe, 0x1b1b1b1b, 0x1b1b1b1b
 ___
 $code.=<<___;
-.globl AES_Td
 .align 64
-AES_Td:
+.LAES_Td:
 ___
        &_data_word(0x50a7f451, 0x5365417e, 0xc3a4171a, 0x965e273a);
        &_data_word(0xcb6bab3b, 0xf1459d1f, 0xab58faac, 0x9303e34b);
@@ -1550,7 +2377,80 @@ ___
        &_data_word(0x72c31d16, 0x0c25e2bc, 0x8b493c28, 0x41950dff);
        &_data_word(0x7101a839, 0xdeb30c08, 0x9ce4b4d8, 0x90c15664);
        &_data_word(0x6184cb7b, 0x70b632d5, 0x745c6c48, 0x4257b8d0);
-#Td4:
+
+#Td4:  # four copies of Td4 to choose from to avoid L1 aliasing
+       &data_byte(0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38);
+       &data_byte(0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb);
+       &data_byte(0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87);
+       &data_byte(0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb);
+       &data_byte(0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d);
+       &data_byte(0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e);
+       &data_byte(0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2);
+       &data_byte(0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25);
+       &data_byte(0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16);
+       &data_byte(0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92);
+       &data_byte(0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda);
+       &data_byte(0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84);
+       &data_byte(0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a);
+       &data_byte(0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06);
+       &data_byte(0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02);
+       &data_byte(0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b);
+       &data_byte(0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea);
+       &data_byte(0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73);
+       &data_byte(0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85);
+       &data_byte(0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e);
+       &data_byte(0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89);
+       &data_byte(0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b);
+       &data_byte(0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20);
+       &data_byte(0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4);
+       &data_byte(0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31);
+       &data_byte(0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f);
+       &data_byte(0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d);
+       &data_byte(0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef);
+       &data_byte(0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0);
+       &data_byte(0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61);
+       &data_byte(0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26);
+       &data_byte(0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d);
+$code.=<<___;
+       .long   0x80808080, 0x80808080, 0xfefefefe, 0xfefefefe
+       .long   0x1b1b1b1b, 0x1b1b1b1b, 0, 0
+___
+       &data_byte(0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38);
+       &data_byte(0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb);
+       &data_byte(0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87);
+       &data_byte(0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb);
+       &data_byte(0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d);
+       &data_byte(0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e);
+       &data_byte(0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2);
+       &data_byte(0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25);
+       &data_byte(0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16);
+       &data_byte(0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92);
+       &data_byte(0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda);
+       &data_byte(0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84);
+       &data_byte(0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a);
+       &data_byte(0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06);
+       &data_byte(0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02);
+       &data_byte(0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b);
+       &data_byte(0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea);
+       &data_byte(0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73);
+       &data_byte(0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85);
+       &data_byte(0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e);
+       &data_byte(0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89);
+       &data_byte(0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b);
+       &data_byte(0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20);
+       &data_byte(0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4);
+       &data_byte(0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31);
+       &data_byte(0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f);
+       &data_byte(0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d);
+       &data_byte(0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef);
+       &data_byte(0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0);
+       &data_byte(0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61);
+       &data_byte(0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26);
+       &data_byte(0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d);
+$code.=<<___;
+       .long   0x80808080, 0x80808080, 0xfefefefe, 0xfefefefe
+       .long   0x1b1b1b1b, 0x1b1b1b1b, 0, 0
+___
        &data_byte(0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38);
        &data_byte(0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb);
        &data_byte(0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87);
@@ -1583,6 +2483,324 @@ ___
        &data_byte(0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61);
        &data_byte(0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26);
        &data_byte(0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d);
+$code.=<<___;
+       .long   0x80808080, 0x80808080, 0xfefefefe, 0xfefefefe
+       .long   0x1b1b1b1b, 0x1b1b1b1b, 0, 0
+___
+       &data_byte(0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38);
+       &data_byte(0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb);
+       &data_byte(0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87);
+       &data_byte(0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb);
+       &data_byte(0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d);
+       &data_byte(0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e);
+       &data_byte(0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2);
+       &data_byte(0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25);
+       &data_byte(0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16);
+       &data_byte(0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92);
+       &data_byte(0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda);
+       &data_byte(0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84);
+       &data_byte(0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a);
+       &data_byte(0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06);
+       &data_byte(0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02);
+       &data_byte(0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b);
+       &data_byte(0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea);
+       &data_byte(0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73);
+       &data_byte(0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85);
+       &data_byte(0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e);
+       &data_byte(0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89);
+       &data_byte(0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b);
+       &data_byte(0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20);
+       &data_byte(0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4);
+       &data_byte(0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31);
+       &data_byte(0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f);
+       &data_byte(0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d);
+       &data_byte(0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef);
+       &data_byte(0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0);
+       &data_byte(0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61);
+       &data_byte(0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26);
+       &data_byte(0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d);
+$code.=<<___;
+       .long   0x80808080, 0x80808080, 0xfefefefe, 0xfefefefe
+       .long   0x1b1b1b1b, 0x1b1b1b1b, 0, 0
+.asciz  "AES for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
+.align 64
+___
+
+# EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
+#              CONTEXT *context,DISPATCHER_CONTEXT *disp)
+if ($win64) {
+$rec="%rcx";
+$frame="%rdx";
+$context="%r8";
+$disp="%r9";
+
+$code.=<<___;
+.extern        __imp_RtlVirtualUnwind
+.type  block_se_handler,\@abi-omnipotent
+.align 16
+block_se_handler:
+       push    %rsi
+       push    %rdi
+       push    %rbx
+       push    %rbp
+       push    %r12
+       push    %r13
+       push    %r14
+       push    %r15
+       pushfq
+       sub     \$64,%rsp
+
+       mov     120($context),%rax      # pull context->Rax
+       mov     248($context),%rbx      # pull context->Rip
+
+       mov     8($disp),%rsi           # disp->ImageBase
+       mov     56($disp),%r11          # disp->HandlerData
+
+       mov     0(%r11),%r10d           # HandlerData[0]
+       lea     (%rsi,%r10),%r10        # prologue label
+       cmp     %r10,%rbx               # context->Rip<prologue label
+       jb      .Lin_block_prologue
+
+       mov     152($context),%rax      # pull context->Rsp
+
+       mov     4(%r11),%r10d           # HandlerData[1]
+       lea     (%rsi,%r10),%r10        # epilogue label
+       cmp     %r10,%rbx               # context->Rip>=epilogue label
+       jae     .Lin_block_prologue
+
+       mov     24(%rax),%rax           # pull saved real stack pointer
+       lea     48(%rax),%rax           # adjust...
+
+       mov     -8(%rax),%rbx
+       mov     -16(%rax),%rbp
+       mov     -24(%rax),%r12
+       mov     -32(%rax),%r13
+       mov     -40(%rax),%r14
+       mov     -48(%rax),%r15
+       mov     %rbx,144($context)      # restore context->Rbx
+       mov     %rbp,160($context)      # restore context->Rbp
+       mov     %r12,216($context)      # restore context->R12
+       mov     %r13,224($context)      # restore context->R13
+       mov     %r14,232($context)      # restore context->R14
+       mov     %r15,240($context)      # restore context->R15
+
+.Lin_block_prologue:
+       mov     8(%rax),%rdi
+       mov     16(%rax),%rsi
+       mov     %rax,152($context)      # restore context->Rsp
+       mov     %rsi,168($context)      # restore context->Rsi
+       mov     %rdi,176($context)      # restore context->Rdi
+
+       jmp     .Lcommon_seh_exit
+.size  block_se_handler,.-block_se_handler
+
+.type  key_se_handler,\@abi-omnipotent
+.align 16
+key_se_handler:
+       push    %rsi
+       push    %rdi
+       push    %rbx
+       push    %rbp
+       push    %r12
+       push    %r13
+       push    %r14
+       push    %r15
+       pushfq
+       sub     \$64,%rsp
+
+       mov     120($context),%rax      # pull context->Rax
+       mov     248($context),%rbx      # pull context->Rip
+
+       mov     8($disp),%rsi           # disp->ImageBase
+       mov     56($disp),%r11          # disp->HandlerData
+
+       mov     0(%r11),%r10d           # HandlerData[0]
+       lea     (%rsi,%r10),%r10        # prologue label
+       cmp     %r10,%rbx               # context->Rip<prologue label
+       jb      .Lin_key_prologue
+
+       mov     152($context),%rax      # pull context->Rsp
+
+       mov     4(%r11),%r10d           # HandlerData[1]
+       lea     (%rsi,%r10),%r10        # epilogue label
+       cmp     %r10,%rbx               # context->Rip>=epilogue label
+       jae     .Lin_key_prologue
+
+       lea     56(%rax),%rax
+
+       mov     -8(%rax),%rbx
+       mov     -16(%rax),%rbp
+       mov     -24(%rax),%r12
+       mov     -32(%rax),%r13
+       mov     -40(%rax),%r14
+       mov     -48(%rax),%r15
+       mov     %rbx,144($context)      # restore context->Rbx
+       mov     %rbp,160($context)      # restore context->Rbp
+       mov     %r12,216($context)      # restore context->R12
+       mov     %r13,224($context)      # restore context->R13
+       mov     %r14,232($context)      # restore context->R14
+       mov     %r15,240($context)      # restore context->R15
+
+.Lin_key_prologue:
+       mov     8(%rax),%rdi
+       mov     16(%rax),%rsi
+       mov     %rax,152($context)      # restore context->Rsp
+       mov     %rsi,168($context)      # restore context->Rsi
+       mov     %rdi,176($context)      # restore context->Rdi
+
+       jmp     .Lcommon_seh_exit
+.size  key_se_handler,.-key_se_handler
+
+.type  cbc_se_handler,\@abi-omnipotent
+.align 16
+cbc_se_handler:
+       push    %rsi
+       push    %rdi
+       push    %rbx
+       push    %rbp
+       push    %r12
+       push    %r13
+       push    %r14
+       push    %r15
+       pushfq
+       sub     \$64,%rsp
+
+       mov     120($context),%rax      # pull context->Rax
+       mov     248($context),%rbx      # pull context->Rip
+
+       lea     .Lcbc_prologue(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip<.Lcbc_prologue
+       jb      .Lin_cbc_prologue
+
+       lea     .Lcbc_fast_body(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip<.Lcbc_fast_body
+       jb      .Lin_cbc_frame_setup
+
+       lea     .Lcbc_slow_prologue(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip<.Lcbc_slow_prologue
+       jb      .Lin_cbc_body
+
+       lea     .Lcbc_slow_body(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip<.Lcbc_slow_body
+       jb      .Lin_cbc_frame_setup
+
+.Lin_cbc_body:
+       mov     152($context),%rax      # pull context->Rsp
+
+       lea     .Lcbc_epilogue(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip>=.Lcbc_epilogue
+       jae     .Lin_cbc_prologue
+
+       lea     8(%rax),%rax
+
+       lea     .Lcbc_popfq(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip>=.Lcbc_popfq
+       jae     .Lin_cbc_prologue
+
+       mov     `16-8`(%rax),%rax       # biased $_rsp
+       lea     56(%rax),%rax
+
+.Lin_cbc_frame_setup:
+       mov     -16(%rax),%rbx
+       mov     -24(%rax),%rbp
+       mov     -32(%rax),%r12
+       mov     -40(%rax),%r13
+       mov     -48(%rax),%r14
+       mov     -56(%rax),%r15
+       mov     %rbx,144($context)      # restore context->Rbx
+       mov     %rbp,160($context)      # restore context->Rbp
+       mov     %r12,216($context)      # restore context->R12
+       mov     %r13,224($context)      # restore context->R13
+       mov     %r14,232($context)      # restore context->R14
+       mov     %r15,240($context)      # restore context->R15
+
+.Lin_cbc_prologue:
+       mov     8(%rax),%rdi
+       mov     16(%rax),%rsi
+       mov     %rax,152($context)      # restore context->Rsp
+       mov     %rsi,168($context)      # restore context->Rsi
+       mov     %rdi,176($context)      # restore context->Rdi
+
+.Lcommon_seh_exit:
+
+       mov     40($disp),%rdi          # disp->ContextRecord
+       mov     $context,%rsi           # context
+       mov     \$`1232/8`,%ecx         # sizeof(CONTEXT)
+       .long   0xa548f3fc              # cld; rep movsq
+
+       mov     $disp,%rsi
+       xor     %rcx,%rcx               # arg1, UNW_FLAG_NHANDLER
+       mov     8(%rsi),%rdx            # arg2, disp->ImageBase
+       mov     0(%rsi),%r8             # arg3, disp->ControlPc
+       mov     16(%rsi),%r9            # arg4, disp->FunctionEntry
+       mov     40(%rsi),%r10           # disp->ContextRecord
+       lea     56(%rsi),%r11           # &disp->HandlerData
+       lea     24(%rsi),%r12           # &disp->EstablisherFrame
+       mov     %r10,32(%rsp)           # arg5
+       mov     %r11,40(%rsp)           # arg6
+       mov     %r12,48(%rsp)           # arg7
+       mov     %rcx,56(%rsp)           # arg8, (NULL)
+       call    *__imp_RtlVirtualUnwind(%rip)
+
+       mov     \$1,%eax                # ExceptionContinueSearch
+       add     \$64,%rsp
+       popfq
+       pop     %r15
+       pop     %r14
+       pop     %r13
+       pop     %r12
+       pop     %rbp
+       pop     %rbx
+       pop     %rdi
+       pop     %rsi
+       ret
+.size  cbc_se_handler,.-cbc_se_handler
+
+.section       .pdata
+.align 4
+       .rva    .LSEH_begin_AES_encrypt
+       .rva    .LSEH_end_AES_encrypt
+       .rva    .LSEH_info_AES_encrypt
+
+       .rva    .LSEH_begin_AES_decrypt
+       .rva    .LSEH_end_AES_decrypt
+       .rva    .LSEH_info_AES_decrypt
+
+       .rva    .LSEH_begin_AES_set_encrypt_key
+       .rva    .LSEH_end_AES_set_encrypt_key
+       .rva    .LSEH_info_AES_set_encrypt_key
+
+       .rva    .LSEH_begin_AES_set_decrypt_key
+       .rva    .LSEH_end_AES_set_decrypt_key
+       .rva    .LSEH_info_AES_set_decrypt_key
+
+       .rva    .LSEH_begin_AES_cbc_encrypt
+       .rva    .LSEH_end_AES_cbc_encrypt
+       .rva    .LSEH_info_AES_cbc_encrypt
+
+.section       .xdata
+.align 8
+.LSEH_info_AES_encrypt:
+       .byte   9,0,0,0
+       .rva    block_se_handler
+       .rva    .Lenc_prologue,.Lenc_epilogue   # HandlerData[]
+.LSEH_info_AES_decrypt:
+       .byte   9,0,0,0
+       .rva    block_se_handler
+       .rva    .Ldec_prologue,.Ldec_epilogue   # HandlerData[]
+.LSEH_info_AES_set_encrypt_key:
+       .byte   9,0,0,0
+       .rva    key_se_handler
+       .rva    .Lenc_key_prologue,.Lenc_key_epilogue   # HandlerData[]
+.LSEH_info_AES_set_decrypt_key:
+       .byte   9,0,0,0
+       .rva    key_se_handler
+       .rva    .Ldec_key_prologue,.Ldec_key_epilogue   # HandlerData[]
+.LSEH_info_AES_cbc_encrypt:
+       .byte   9,0,0,0
+       .rva    cbc_se_handler
+___
+}
 
 $code =~ s/\`([^\`]*)\`/eval($1)/gem;
 
diff --git a/deps/openssl/openssl/crypto/alphacpuid.pl b/deps/openssl/openssl/crypto/alphacpuid.pl
new file mode 100644 (file)
index 0000000..4b3cbb9
--- /dev/null
@@ -0,0 +1,126 @@
+#!/usr/bin/env perl
+print <<'___';
+.text
+
+.set   noat
+
+.globl OPENSSL_cpuid_setup
+.ent   OPENSSL_cpuid_setup
+OPENSSL_cpuid_setup:
+       .frame  $30,0,$26
+       .prologue 0
+       ret     ($26)
+.end   OPENSSL_cpuid_setup
+
+.globl OPENSSL_wipe_cpu
+.ent   OPENSSL_wipe_cpu
+OPENSSL_wipe_cpu:
+       .frame  $30,0,$26
+       .prologue 0
+       clr     $1
+       clr     $2
+       clr     $3
+       clr     $4
+       clr     $5
+       clr     $6
+       clr     $7
+       clr     $8
+       clr     $16
+       clr     $17
+       clr     $18
+       clr     $19
+       clr     $20
+       clr     $21
+       clr     $22
+       clr     $23
+       clr     $24
+       clr     $25
+       clr     $27
+       clr     $at
+       clr     $29
+       fclr    $f0
+       fclr    $f1
+       fclr    $f10
+       fclr    $f11
+       fclr    $f12
+       fclr    $f13
+       fclr    $f14
+       fclr    $f15
+       fclr    $f16
+       fclr    $f17
+       fclr    $f18
+       fclr    $f19
+       fclr    $f20
+       fclr    $f21
+       fclr    $f22
+       fclr    $f23
+       fclr    $f24
+       fclr    $f25
+       fclr    $f26
+       fclr    $f27
+       fclr    $f28
+       fclr    $f29
+       fclr    $f30
+       mov     $sp,$0
+       ret     ($26)
+.end   OPENSSL_wipe_cpu
+
+.globl OPENSSL_atomic_add
+.ent   OPENSSL_atomic_add
+OPENSSL_atomic_add:
+       .frame  $30,0,$26
+       .prologue 0
+1:     ldl_l   $0,0($16)
+       addl    $0,$17,$1
+       stl_c   $1,0($16)
+       beq     $1,1b
+       addl    $0,$17,$0
+       ret     ($26)
+.end   OPENSSL_atomic_add
+
+.globl OPENSSL_rdtsc
+.ent   OPENSSL_rdtsc
+OPENSSL_rdtsc:
+       .frame  $30,0,$26
+       .prologue 0
+       rpcc    $0
+       ret     ($26)
+.end   OPENSSL_rdtsc
+
+.globl OPENSSL_cleanse
+.ent   OPENSSL_cleanse
+OPENSSL_cleanse:
+       .frame  $30,0,$26
+       .prologue 0
+       beq     $17,.Ldone
+       and     $16,7,$0
+       bic     $17,7,$at
+       beq     $at,.Little
+       beq     $0,.Laligned
+
+.Little:
+       subq    $0,8,$0
+       ldq_u   $1,0($16)
+       mov     $16,$2
+.Lalign:
+       mskbl   $1,$16,$1
+       lda     $16,1($16)
+       subq    $17,1,$17
+       addq    $0,1,$0
+       beq     $17,.Lout
+       bne     $0,.Lalign
+.Lout: stq_u   $1,0($2)
+       beq     $17,.Ldone
+       bic     $17,7,$at
+       beq     $at,.Little
+
+.Laligned:
+       stq     $31,0($16)
+       subq    $17,8,$17
+       lda     $16,8($16)
+       bic     $17,7,$at
+       bne     $at,.Laligned
+       bne     $17,.Little
+.Ldone: ret    ($26)
+.end   OPENSSL_cleanse
+___
index 94a6885..160544e 100644 (file)
@@ -22,30 +22,32 @@ LIBSRC=     a_object.c a_bitstr.c a_utctm.c a_gentm.c a_time.c a_int.c a_octet.c \
        a_enum.c a_utf8.c a_sign.c a_digest.c a_verify.c a_mbstr.c a_strex.c \
        x_algor.c x_val.c x_pubkey.c x_sig.c x_req.c x_attrib.c x_bignum.c \
        x_long.c x_name.c x_x509.c x_x509a.c x_crl.c x_info.c x_spki.c nsseq.c \
-       d2i_pu.c d2i_pr.c i2d_pu.c i2d_pr.c\
+       x_nx509.c d2i_pu.c d2i_pr.c i2d_pu.c i2d_pr.c\
        t_req.c t_x509.c t_x509a.c t_crl.c t_pkey.c t_spki.c t_bitst.c \
        tasn_new.c tasn_fre.c tasn_enc.c tasn_dec.c tasn_utl.c tasn_typ.c \
+       tasn_prn.c ameth_lib.c \
        f_int.c f_string.c n_pkey.c \
-       f_enum.c a_hdr.c x_pkey.c a_bool.c x_exten.c asn_mime.c \
-       asn1_gen.c asn1_par.c asn1_lib.c asn1_err.c a_meth.c a_bytes.c a_strnid.c \
+       f_enum.c x_pkey.c a_bool.c x_exten.c bio_asn1.c bio_ndef.c asn_mime.c \
+       asn1_gen.c asn1_par.c asn1_lib.c asn1_err.c a_bytes.c a_strnid.c \
        evp_asn1.c asn_pack.c p5_pbe.c p5_pbev2.c p8_pkey.c asn_moid.c
 LIBOBJ= a_object.o a_bitstr.o a_utctm.o a_gentm.o a_time.o a_int.o a_octet.o \
        a_print.o a_type.o a_set.o a_dup.o a_d2i_fp.o a_i2d_fp.o \
        a_enum.o a_utf8.o a_sign.o a_digest.o a_verify.o a_mbstr.o a_strex.o \
        x_algor.o x_val.o x_pubkey.o x_sig.o x_req.o x_attrib.o x_bignum.o \
        x_long.o x_name.o x_x509.o x_x509a.o x_crl.o x_info.o x_spki.o nsseq.o \
-       d2i_pu.o d2i_pr.o i2d_pu.o i2d_pr.o \
+       x_nx509.o d2i_pu.o d2i_pr.o i2d_pu.o i2d_pr.o \
        t_req.o t_x509.o t_x509a.o t_crl.o t_pkey.o t_spki.o t_bitst.o \
        tasn_new.o tasn_fre.o tasn_enc.o tasn_dec.o tasn_utl.o tasn_typ.o \
+       tasn_prn.o ameth_lib.o \
        f_int.o f_string.o n_pkey.o \
-       f_enum.o a_hdr.o x_pkey.o a_bool.o x_exten.o asn_mime.o \
-       asn1_gen.o asn1_par.o asn1_lib.o asn1_err.o a_meth.o a_bytes.o a_strnid.o \
+       f_enum.o x_pkey.o a_bool.o x_exten.o bio_asn1.o bio_ndef.o asn_mime.o \
+       asn1_gen.o asn1_par.o asn1_lib.o asn1_err.o a_bytes.o a_strnid.o \
        evp_asn1.o asn_pack.o p5_pbe.o p5_pbev2.o p8_pkey.o asn_moid.o
 
 SRC= $(LIBSRC)
 
 EXHEADER=  asn1.h asn1_mac.h asn1t.h
-HEADER=        $(EXHEADER)
+HEADER=        $(EXHEADER) asn1_locl.h
 
 ALL=    $(GENERAL) $(SRC) $(HEADER)
 
@@ -63,7 +65,7 @@ pk:   pk.c
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -142,9 +144,9 @@ a_digest.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 a_digest.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 a_digest.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 a_digest.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-a_digest.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-a_digest.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-a_digest.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+a_digest.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+a_digest.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+a_digest.o: ../../include/openssl/opensslconf.h
 a_digest.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 a_digest.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 a_digest.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -173,14 +175,6 @@ a_gentm.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
 a_gentm.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
 a_gentm.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
 a_gentm.o: ../cryptlib.h ../o_time.h a_gentm.c
-a_hdr.o: ../../e_os.h ../../include/openssl/asn1.h
-a_hdr.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
-a_hdr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
-a_hdr.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-a_hdr.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
-a_hdr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-a_hdr.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-a_hdr.o: ../../include/openssl/symhacks.h ../cryptlib.h a_hdr.c
 a_i2d_fp.o: ../../e_os.h ../../include/openssl/asn1.h
 a_i2d_fp.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 a_i2d_fp.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
@@ -205,13 +199,6 @@ a_mbstr.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
 a_mbstr.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
 a_mbstr.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
 a_mbstr.o: ../cryptlib.h a_mbstr.c
-a_meth.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
-a_meth.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
-a_meth.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-a_meth.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
-a_meth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-a_meth.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-a_meth.o: ../../include/openssl/symhacks.h ../cryptlib.h a_meth.c
 a_object.o: ../../e_os.h ../../include/openssl/asn1.h
 a_object.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
 a_object.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
@@ -250,27 +237,27 @@ a_sign.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
 a_sign.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 a_sign.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 a_sign.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-a_sign.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-a_sign.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-a_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-a_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-a_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-a_sign.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-a_sign.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-a_sign.o: ../../include/openssl/x509_vfy.h ../cryptlib.h a_sign.c
+a_sign.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+a_sign.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+a_sign.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+a_sign.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+a_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+a_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+a_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+a_sign.o: ../cryptlib.h a_sign.c asn1_locl.h
 a_strex.o: ../../e_os.h ../../include/openssl/asn1.h
 a_strex.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 a_strex.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 a_strex.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 a_strex.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-a_strex.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-a_strex.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-a_strex.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-a_strex.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-a_strex.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-a_strex.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-a_strex.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-a_strex.o: ../../include/openssl/x509_vfy.h ../cryptlib.h a_strex.c charmap.h
+a_strex.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+a_strex.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+a_strex.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+a_strex.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+a_strex.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+a_strex.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+a_strex.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+a_strex.o: ../cryptlib.h a_strex.c charmap.h
 a_strnid.o: ../../e_os.h ../../include/openssl/asn1.h
 a_strnid.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 a_strnid.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
@@ -318,14 +305,29 @@ a_verify.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 a_verify.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 a_verify.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 a_verify.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-a_verify.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-a_verify.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-a_verify.o: ../../include/openssl/opensslconf.h
+a_verify.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+a_verify.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 a_verify.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 a_verify.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 a_verify.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
 a_verify.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
 a_verify.o: ../../include/openssl/x509_vfy.h ../cryptlib.h a_verify.c
+a_verify.o: asn1_locl.h
+ameth_lib.o: ../../e_os.h ../../include/openssl/asn1.h
+ameth_lib.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
+ameth_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
+ameth_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+ameth_lib.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
+ameth_lib.o: ../../include/openssl/engine.h ../../include/openssl/err.h
+ameth_lib.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+ameth_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+ameth_lib.o: ../../include/openssl/opensslconf.h
+ameth_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+ameth_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+ameth_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+ameth_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+ameth_lib.o: ../../include/openssl/x509_vfy.h ../cryptlib.h ameth_lib.c
+ameth_lib.o: asn1_locl.h
 asn1_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
 asn1_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 asn1_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
@@ -339,9 +341,8 @@ asn1_gen.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 asn1_gen.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 asn1_gen.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 asn1_gen.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-asn1_gen.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-asn1_gen.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-asn1_gen.o: ../../include/openssl/opensslconf.h
+asn1_gen.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+asn1_gen.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 asn1_gen.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 asn1_gen.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 asn1_gen.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -371,24 +372,23 @@ asn_mime.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 asn_mime.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 asn_mime.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 asn_mime.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-asn_mime.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-asn_mime.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-asn_mime.o: ../../include/openssl/opensslconf.h
+asn_mime.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+asn_mime.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 asn_mime.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 asn_mime.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
 asn_mime.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
 asn_mime.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
 asn_mime.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-asn_mime.o: ../cryptlib.h asn_mime.c
+asn_mime.o: ../cryptlib.h asn1_locl.h asn_mime.c
 asn_moid.o: ../../e_os.h ../../include/openssl/asn1.h
 asn_moid.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 asn_moid.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 asn_moid.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
 asn_moid.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 asn_moid.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-asn_moid.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-asn_moid.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-asn_moid.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+asn_moid.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+asn_moid.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+asn_moid.o: ../../include/openssl/opensslconf.h
 asn_moid.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 asn_moid.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 asn_moid.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -402,28 +402,43 @@ asn_pack.o: ../../include/openssl/opensslconf.h
 asn_pack.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 asn_pack.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
 asn_pack.o: ../../include/openssl/symhacks.h ../cryptlib.h asn_pack.c
+bio_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
+bio_asn1.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+bio_asn1.o: ../../include/openssl/opensslconf.h
+bio_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+bio_asn1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+bio_asn1.o: ../../include/openssl/symhacks.h bio_asn1.c
+bio_ndef.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
+bio_ndef.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
+bio_ndef.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
+bio_ndef.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
+bio_ndef.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+bio_ndef.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+bio_ndef.o: ../../include/openssl/symhacks.h bio_ndef.c
 d2i_pr.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 d2i_pr.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
-d2i_pr.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
-d2i_pr.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+d2i_pr.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+d2i_pr.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+d2i_pr.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
 d2i_pr.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-d2i_pr.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-d2i_pr.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-d2i_pr.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-d2i_pr.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rsa.h
-d2i_pr.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-d2i_pr.o: ../../include/openssl/symhacks.h ../cryptlib.h d2i_pr.c
+d2i_pr.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+d2i_pr.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+d2i_pr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+d2i_pr.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+d2i_pr.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+d2i_pr.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+d2i_pr.o: ../../include/openssl/x509_vfy.h ../cryptlib.h asn1_locl.h d2i_pr.c
 d2i_pu.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 d2i_pu.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
 d2i_pu.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
 d2i_pu.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 d2i_pu.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-d2i_pu.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-d2i_pu.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-d2i_pu.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-d2i_pu.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rsa.h
-d2i_pu.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-d2i_pu.o: ../../include/openssl/symhacks.h ../cryptlib.h d2i_pu.c
+d2i_pu.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+d2i_pu.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+d2i_pu.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+d2i_pu.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+d2i_pu.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+d2i_pu.o: ../cryptlib.h d2i_pu.c
 evp_asn1.o: ../../e_os.h ../../include/openssl/asn1.h
 evp_asn1.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
 evp_asn1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
@@ -455,77 +470,76 @@ f_string.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 f_string.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
 f_string.o: ../../include/openssl/symhacks.h ../cryptlib.h f_string.c
 i2d_pr.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
-i2d_pr.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
-i2d_pr.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
+i2d_pr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 i2d_pr.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+i2d_pr.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 i2d_pr.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-i2d_pr.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-i2d_pr.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-i2d_pr.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-i2d_pr.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rsa.h
-i2d_pr.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-i2d_pr.o: ../../include/openssl/symhacks.h ../cryptlib.h i2d_pr.c
+i2d_pr.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+i2d_pr.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+i2d_pr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+i2d_pr.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+i2d_pr.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+i2d_pr.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+i2d_pr.o: ../../include/openssl/x509_vfy.h ../cryptlib.h asn1_locl.h i2d_pr.c
 i2d_pu.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 i2d_pu.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
 i2d_pu.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
 i2d_pu.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 i2d_pu.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-i2d_pu.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-i2d_pu.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-i2d_pu.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-i2d_pu.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rsa.h
-i2d_pu.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-i2d_pu.o: ../../include/openssl/symhacks.h ../cryptlib.h i2d_pu.c
+i2d_pu.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+i2d_pu.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+i2d_pu.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+i2d_pu.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+i2d_pu.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+i2d_pu.o: ../cryptlib.h i2d_pu.c
 n_pkey.o: ../../e_os.h ../../include/openssl/asn1.h
 n_pkey.o: ../../include/openssl/asn1_mac.h ../../include/openssl/asn1t.h
 n_pkey.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 n_pkey.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 n_pkey.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 n_pkey.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-n_pkey.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-n_pkey.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-n_pkey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-n_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-n_pkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
-n_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-n_pkey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-n_pkey.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-n_pkey.o: ../cryptlib.h n_pkey.c
+n_pkey.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+n_pkey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+n_pkey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+n_pkey.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+n_pkey.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+n_pkey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+n_pkey.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+n_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h n_pkey.c
 nsseq.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
 nsseq.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 nsseq.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 nsseq.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 nsseq.o: ../../include/openssl/ecdsa.h ../../include/openssl/evp.h
-nsseq.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-nsseq.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-nsseq.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-nsseq.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-nsseq.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-nsseq.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-nsseq.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h nsseq.c
+nsseq.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+nsseq.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+nsseq.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+nsseq.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+nsseq.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+nsseq.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+nsseq.o: ../../include/openssl/x509_vfy.h nsseq.c
 p5_pbe.o: ../../e_os.h ../../include/openssl/asn1.h
 p5_pbe.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 p5_pbe.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 p5_pbe.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 p5_pbe.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 p5_pbe.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-p5_pbe.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-p5_pbe.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-p5_pbe.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-p5_pbe.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-p5_pbe.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
-p5_pbe.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-p5_pbe.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-p5_pbe.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p5_pbe.c
+p5_pbe.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+p5_pbe.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+p5_pbe.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+p5_pbe.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
+p5_pbe.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+p5_pbe.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+p5_pbe.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+p5_pbe.o: ../cryptlib.h p5_pbe.c
 p5_pbev2.o: ../../e_os.h ../../include/openssl/asn1.h
 p5_pbev2.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 p5_pbev2.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 p5_pbev2.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 p5_pbev2.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 p5_pbev2.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-p5_pbev2.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-p5_pbev2.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-p5_pbev2.o: ../../include/openssl/opensslconf.h
+p5_pbev2.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+p5_pbev2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 p5_pbev2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 p5_pbev2.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
 p5_pbev2.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
@@ -538,51 +552,48 @@ p8_pkey.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 p8_pkey.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 p8_pkey.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 p8_pkey.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-p8_pkey.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-p8_pkey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-p8_pkey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-p8_pkey.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-p8_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-p8_pkey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-p8_pkey.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-p8_pkey.o: ../cryptlib.h p8_pkey.c
+p8_pkey.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+p8_pkey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+p8_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+p8_pkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+p8_pkey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+p8_pkey.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+p8_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p8_pkey.c
 t_bitst.o: ../../e_os.h ../../include/openssl/asn1.h
 t_bitst.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 t_bitst.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 t_bitst.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 t_bitst.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 t_bitst.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-t_bitst.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-t_bitst.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-t_bitst.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-t_bitst.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-t_bitst.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-t_bitst.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-t_bitst.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-t_bitst.o: ../../include/openssl/x509v3.h ../cryptlib.h t_bitst.c
+t_bitst.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+t_bitst.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+t_bitst.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+t_bitst.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+t_bitst.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+t_bitst.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+t_bitst.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+t_bitst.o: ../cryptlib.h t_bitst.c
 t_crl.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 t_crl.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
 t_crl.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 t_crl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 t_crl.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 t_crl.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-t_crl.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-t_crl.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-t_crl.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-t_crl.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-t_crl.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-t_crl.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-t_crl.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-t_crl.o: ../../include/openssl/x509v3.h ../cryptlib.h t_crl.c
+t_crl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+t_crl.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+t_crl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+t_crl.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+t_crl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+t_crl.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+t_crl.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+t_crl.o: ../cryptlib.h t_crl.c
 t_pkey.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 t_pkey.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
-t_pkey.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
-t_pkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
-t_pkey.o: ../../include/openssl/ec.h ../../include/openssl/err.h
-t_pkey.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-t_pkey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-t_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-t_pkey.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+t_pkey.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+t_pkey.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
+t_pkey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+t_pkey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+t_pkey.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
 t_pkey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
 t_pkey.o: ../cryptlib.h t_pkey.c
 t_req.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
@@ -591,57 +602,57 @@ t_req.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 t_req.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
 t_req.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 t_req.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-t_req.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-t_req.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-t_req.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-t_req.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-t_req.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
-t_req.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-t_req.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-t_req.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-t_req.o: ../../include/openssl/x509v3.h ../cryptlib.h t_req.c
+t_req.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+t_req.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+t_req.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+t_req.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+t_req.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+t_req.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+t_req.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+t_req.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+t_req.o: ../cryptlib.h t_req.c
 t_spki.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 t_spki.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
 t_spki.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
 t_spki.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 t_spki.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 t_spki.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-t_spki.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-t_spki.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-t_spki.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-t_spki.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-t_spki.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
-t_spki.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-t_spki.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-t_spki.o: ../../include/openssl/x509_vfy.h ../cryptlib.h t_spki.c
+t_spki.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+t_spki.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+t_spki.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+t_spki.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
+t_spki.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+t_spki.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+t_spki.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+t_spki.o: ../cryptlib.h t_spki.c
 t_x509.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 t_x509.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
 t_x509.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 t_x509.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
 t_x509.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 t_x509.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-t_x509.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-t_x509.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-t_x509.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-t_x509.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-t_x509.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
-t_x509.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-t_x509.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-t_x509.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-t_x509.o: ../../include/openssl/x509v3.h ../cryptlib.h t_x509.c
+t_x509.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+t_x509.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+t_x509.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+t_x509.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+t_x509.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+t_x509.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+t_x509.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+t_x509.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+t_x509.o: ../cryptlib.h t_x509.c
 t_x509a.o: ../../e_os.h ../../include/openssl/asn1.h
 t_x509a.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 t_x509a.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 t_x509a.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 t_x509a.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-t_x509a.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-t_x509a.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-t_x509a.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-t_x509a.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-t_x509a.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-t_x509a.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-t_x509a.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-t_x509a.o: ../../include/openssl/x509_vfy.h ../cryptlib.h t_x509a.c
+t_x509a.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+t_x509a.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+t_x509a.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+t_x509a.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+t_x509a.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+t_x509a.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+t_x509a.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+t_x509a.o: ../cryptlib.h t_x509a.c
 tasn_dec.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
 tasn_dec.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 tasn_dec.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
@@ -675,6 +686,21 @@ tasn_new.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 tasn_new.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 tasn_new.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
 tasn_new.o: ../../include/openssl/symhacks.h tasn_new.c
+tasn_prn.o: ../../e_os.h ../../include/openssl/asn1.h
+tasn_prn.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
+tasn_prn.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
+tasn_prn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+tasn_prn.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+tasn_prn.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
+tasn_prn.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+tasn_prn.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+tasn_prn.o: ../../include/openssl/opensslconf.h
+tasn_prn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+tasn_prn.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+tasn_prn.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+tasn_prn.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+tasn_prn.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+tasn_prn.o: ../cryptlib.h asn1_locl.h tasn_prn.c
 tasn_typ.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
 tasn_typ.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
 tasn_typ.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
@@ -694,23 +720,21 @@ x_algor.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 x_algor.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 x_algor.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 x_algor.o: ../../include/openssl/ecdsa.h ../../include/openssl/evp.h
-x_algor.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-x_algor.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-x_algor.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-x_algor.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-x_algor.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-x_algor.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-x_algor.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-x_algor.o: x_algor.c
+x_algor.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+x_algor.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+x_algor.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+x_algor.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+x_algor.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+x_algor.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+x_algor.o: ../../include/openssl/x509_vfy.h x_algor.c
 x_attrib.o: ../../e_os.h ../../include/openssl/asn1.h
 x_attrib.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 x_attrib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 x_attrib.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 x_attrib.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 x_attrib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-x_attrib.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-x_attrib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-x_attrib.o: ../../include/openssl/opensslconf.h
+x_attrib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+x_attrib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 x_attrib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 x_attrib.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 x_attrib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -727,44 +751,42 @@ x_bignum.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
 x_bignum.o: ../../include/openssl/symhacks.h ../cryptlib.h x_bignum.c
 x_crl.o: ../../e_os.h ../../include/openssl/asn1.h
 x_crl.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
-x_crl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
-x_crl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-x_crl.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
-x_crl.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-x_crl.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
+x_crl.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
+x_crl.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+x_crl.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+x_crl.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
+x_crl.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
 x_crl.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
 x_crl.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
 x_crl.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
 x_crl.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
 x_crl.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
 x_crl.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-x_crl.o: ../cryptlib.h x_crl.c
+x_crl.o: ../../include/openssl/x509v3.h ../cryptlib.h asn1_locl.h x_crl.c
 x_exten.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
 x_exten.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 x_exten.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 x_exten.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 x_exten.o: ../../include/openssl/ecdsa.h ../../include/openssl/evp.h
-x_exten.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-x_exten.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-x_exten.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-x_exten.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-x_exten.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-x_exten.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-x_exten.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-x_exten.o: x_exten.c
+x_exten.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+x_exten.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+x_exten.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+x_exten.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+x_exten.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+x_exten.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+x_exten.o: ../../include/openssl/x509_vfy.h x_exten.c
 x_info.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 x_info.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 x_info.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 x_info.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 x_info.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-x_info.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-x_info.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-x_info.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-x_info.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-x_info.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-x_info.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-x_info.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-x_info.o: ../cryptlib.h x_info.c
+x_info.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+x_info.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+x_info.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+x_info.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+x_info.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+x_info.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+x_info.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_info.c
 x_long.o: ../../e_os.h ../../include/openssl/asn1.h
 x_long.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 x_long.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
@@ -780,125 +802,129 @@ x_name.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 x_name.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 x_name.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 x_name.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-x_name.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-x_name.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-x_name.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-x_name.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-x_name.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-x_name.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-x_name.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-x_name.o: ../cryptlib.h x_name.c
+x_name.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+x_name.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+x_name.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+x_name.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+x_name.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+x_name.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+x_name.o: ../../include/openssl/x509_vfy.h ../cryptlib.h asn1_locl.h x_name.c
+x_nx509.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
+x_nx509.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
+x_nx509.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+x_nx509.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+x_nx509.o: ../../include/openssl/ecdsa.h ../../include/openssl/evp.h
+x_nx509.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+x_nx509.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+x_nx509.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+x_nx509.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+x_nx509.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+x_nx509.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+x_nx509.o: ../../include/openssl/x509_vfy.h x_nx509.c
 x_pkey.o: ../../e_os.h ../../include/openssl/asn1.h
 x_pkey.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
 x_pkey.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 x_pkey.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 x_pkey.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 x_pkey.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-x_pkey.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-x_pkey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-x_pkey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-x_pkey.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-x_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-x_pkey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-x_pkey.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-x_pkey.o: ../cryptlib.h x_pkey.c
+x_pkey.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+x_pkey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+x_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+x_pkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+x_pkey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+x_pkey.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+x_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_pkey.c
 x_pubkey.o: ../../e_os.h ../../include/openssl/asn1.h
 x_pubkey.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 x_pubkey.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 x_pubkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
 x_pubkey.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 x_pubkey.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-x_pubkey.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-x_pubkey.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-x_pubkey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+x_pubkey.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+x_pubkey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+x_pubkey.o: ../../include/openssl/opensslconf.h
 x_pubkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 x_pubkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
 x_pubkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
 x_pubkey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
 x_pubkey.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-x_pubkey.o: ../cryptlib.h x_pubkey.c
+x_pubkey.o: ../cryptlib.h asn1_locl.h x_pubkey.c
 x_req.o: ../../e_os.h ../../include/openssl/asn1.h
 x_req.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 x_req.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 x_req.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 x_req.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 x_req.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-x_req.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-x_req.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-x_req.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-x_req.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-x_req.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-x_req.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-x_req.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-x_req.o: ../cryptlib.h x_req.c
+x_req.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+x_req.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+x_req.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+x_req.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+x_req.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+x_req.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+x_req.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_req.c
 x_sig.o: ../../e_os.h ../../include/openssl/asn1.h
 x_sig.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 x_sig.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 x_sig.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 x_sig.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 x_sig.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-x_sig.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-x_sig.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-x_sig.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-x_sig.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-x_sig.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-x_sig.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-x_sig.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-x_sig.o: ../cryptlib.h x_sig.c
+x_sig.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+x_sig.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+x_sig.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+x_sig.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+x_sig.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+x_sig.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+x_sig.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_sig.c
 x_spki.o: ../../e_os.h ../../include/openssl/asn1.h
 x_spki.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 x_spki.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 x_spki.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 x_spki.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 x_spki.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-x_spki.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-x_spki.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-x_spki.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-x_spki.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-x_spki.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-x_spki.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-x_spki.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-x_spki.o: ../cryptlib.h x_spki.c
+x_spki.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+x_spki.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+x_spki.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+x_spki.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+x_spki.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+x_spki.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+x_spki.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_spki.c
 x_val.o: ../../e_os.h ../../include/openssl/asn1.h
 x_val.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 x_val.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 x_val.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 x_val.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 x_val.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-x_val.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-x_val.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-x_val.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-x_val.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-x_val.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-x_val.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-x_val.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-x_val.o: ../cryptlib.h x_val.c
+x_val.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+x_val.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+x_val.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+x_val.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+x_val.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+x_val.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+x_val.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_val.c
 x_x509.o: ../../e_os.h ../../include/openssl/asn1.h
 x_x509.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 x_x509.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 x_x509.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 x_x509.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 x_x509.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-x_x509.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-x_x509.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-x_x509.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-x_x509.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-x_x509.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-x_x509.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-x_x509.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-x_x509.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
-x_x509.o: ../cryptlib.h x_x509.c
+x_x509.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+x_x509.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+x_x509.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+x_x509.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+x_x509.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+x_x509.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+x_x509.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+x_x509.o: ../../include/openssl/x509v3.h ../cryptlib.h x_x509.c
 x_x509a.o: ../../e_os.h ../../include/openssl/asn1.h
 x_x509a.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 x_x509a.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 x_x509a.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 x_x509a.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 x_x509a.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-x_x509a.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-x_x509a.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-x_x509a.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-x_x509a.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-x_x509a.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-x_x509a.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-x_x509a.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-x_x509a.o: ../cryptlib.h x_x509a.c
+x_x509a.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+x_x509a.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+x_x509a.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+x_x509a.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+x_x509a.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+x_x509a.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+x_x509a.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_x509a.c
index 0fb9ce0..3417996 100644 (file)
@@ -223,3 +223,26 @@ int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n)
        return((a->data[w]&v) != 0);
        }
 
+/*
+ * Checks if the given bit string contains only bits specified by 
+ * the flags vector. Returns 0 if there is at least one bit set in 'a'
+ * which is not specified in 'flags', 1 otherwise.
+ * 'len' is the length of 'flags'.
+ */
+int ASN1_BIT_STRING_check(ASN1_BIT_STRING *a,
+                         unsigned char *flags, int flags_len)
+       {
+       int i, ok;
+       /* Check if there is one bit set at all. */
+       if (!a || !a->data) return 1;
+
+       /* Check each byte of the internal representation of the bit string. */
+       ok = 1;
+       for (i = 0; i < a->length && ok; ++i)
+               {
+               unsigned char mask = i < flags_len ? ~flags[i] : 0xff;
+               /* We are done if there is an unneeded bit set. */
+               ok = (a->data[i] & mask) == 0;
+               }
+       return ok;
+       }
index 199d50f..d989925 100644 (file)
@@ -62,7 +62,7 @@
 
 #ifndef NO_OLD_ASN1
 
-void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, char *x)
+void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x)
        {
        unsigned char *b,*p;
        const unsigned char *p2;
index def7906..c79c6f5 100644 (file)
@@ -117,8 +117,8 @@ err:
 
 int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d)
        {
-       static int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0};
-       static int max[9]={99, 99,12,31,23,59,59,12,59};
+       static const int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0};
+       static const int max[9]={99, 99,12,31,23,59,59,12,59};
        char *a;
        int n,i,l,o;
 
@@ -176,6 +176,11 @@ int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d)
                        o++;
                        }
                }
+       else
+               {
+               /* Missing time zone information. */
+               goto err;
+               }
        return(o == l);
 err:
        return(0);
@@ -206,6 +211,12 @@ int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str)
 ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
             time_t t)
        {
+               return ASN1_GENERALIZEDTIME_adj(s, t, 0, 0);
+       }
+
+ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
+            time_t t, int offset_day, long offset_sec)
+       {
        char *p;
        struct tm *ts;
        struct tm data;
@@ -220,13 +231,19 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
        if (ts == NULL)
                return(NULL);
 
+       if (offset_day || offset_sec)
+               { 
+               if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
+                       return NULL;
+               }
+
        p=(char *)s->data;
        if ((p == NULL) || ((size_t)s->length < len))
                {
                p=OPENSSL_malloc(len);
                if (p == NULL)
                        {
-                       ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_SET,
+                       ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ,
                                ERR_R_MALLOC_FAILURE);
                        return(NULL);
                        }
diff --git a/deps/openssl/openssl/crypto/asn1/a_hdr.c b/deps/openssl/openssl/crypto/asn1/a_hdr.c
deleted file mode 100644 (file)
index d1c2a7b..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-/* crypto/asn1/a_hdr.c */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-#include <stdio.h>
-#include "cryptlib.h"
-#include <openssl/asn1_mac.h>
-#include <openssl/asn1.h>
-
-int i2d_ASN1_HEADER(ASN1_HEADER *a, unsigned char **pp)
-       {
-       M_ASN1_I2D_vars(a);
-
-       M_ASN1_I2D_len(a->header,       i2d_ASN1_OCTET_STRING);
-       M_ASN1_I2D_len(a->data,         a->meth->i2d);
-
-       M_ASN1_I2D_seq_total();
-
-       M_ASN1_I2D_put(a->header,       i2d_ASN1_OCTET_STRING);
-       M_ASN1_I2D_put(a->data,         a->meth->i2d);
-
-       M_ASN1_I2D_finish();
-       }
-
-ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a, const unsigned char **pp,
-            long length)
-       {
-       M_ASN1_D2I_vars(a,ASN1_HEADER *,ASN1_HEADER_new);
-
-       M_ASN1_D2I_Init();
-        M_ASN1_D2I_start_sequence();
-        M_ASN1_D2I_get_x(ASN1_OCTET_STRING,ret->header,d2i_ASN1_OCTET_STRING);
-       if (ret->meth != NULL)
-               {
-               M_ASN1_D2I_get_x(void,ret->data,ret->meth->d2i);
-               }
-       else
-               {
-               if (a != NULL) (*a)=ret;
-               return(ret);
-               }
-        M_ASN1_D2I_Finish(a,ASN1_HEADER_free,ASN1_F_D2I_ASN1_HEADER);
-       }
-
-ASN1_HEADER *ASN1_HEADER_new(void)
-       {
-       ASN1_HEADER *ret=NULL;
-       ASN1_CTX c;
-
-       M_ASN1_New_Malloc(ret,ASN1_HEADER);
-       M_ASN1_New(ret->header,M_ASN1_OCTET_STRING_new);
-       ret->meth=NULL;
-       ret->data=NULL;
-       return(ret);
-        M_ASN1_New_Error(ASN1_F_ASN1_HEADER_NEW);
-       }
-
-void ASN1_HEADER_free(ASN1_HEADER *a)
-       {
-       if (a == NULL) return;
-       M_ASN1_OCTET_STRING_free(a->header);
-       if (a->meth != NULL)
-               a->meth->destroy(a->data);
-       OPENSSL_free(a);
-       }
index f551bdb..3348b87 100644 (file)
 #include <openssl/asn1.h>
 #include <openssl/bn.h>
 
-ASN1_INTEGER *ASN1_INTEGER_dup(ASN1_INTEGER *x)
+ASN1_INTEGER *ASN1_INTEGER_dup(const ASN1_INTEGER *x)
 { return M_ASN1_INTEGER_dup(x);}
 
-int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y)
+int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y)
        { 
        int neg, ret;
        /* Compare signs */
@@ -372,7 +372,7 @@ int ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
        return(1);
        }
 
-long ASN1_INTEGER_get(ASN1_INTEGER *a)
+long ASN1_INTEGER_get(const ASN1_INTEGER *a)
        {
        int neg=0,i;
        long r=0;
@@ -401,7 +401,7 @@ long ASN1_INTEGER_get(ASN1_INTEGER *a)
        return(r);
        }
 
-ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai)
+ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai)
        {
        ASN1_INTEGER *ret;
        int len,j;
@@ -443,7 +443,7 @@ err:
        return(NULL);
        }
 
-BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai, BIGNUM *bn)
+BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn)
        {
        BIGNUM *ret;
 
diff --git a/deps/openssl/openssl/crypto/asn1/a_meth.c b/deps/openssl/openssl/crypto/asn1/a_meth.c
deleted file mode 100644 (file)
index 50bea91..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/* crypto/asn1/a_meth.c */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-#include <stdio.h>
-#include "cryptlib.h"
-#include <openssl/buffer.h>
-#include <openssl/asn1.h>
-
-static  ASN1_METHOD ia5string_meth={
-       (I2D_OF(void))  i2d_ASN1_IA5STRING,
-       (D2I_OF(void))  d2i_ASN1_IA5STRING,
-       (void *(*)(void))ASN1_STRING_new,
-       (void (*)(void *))ASN1_STRING_free};
-
-static  ASN1_METHOD bit_string_meth={
-       (I2D_OF(void))  i2d_ASN1_BIT_STRING,
-       (D2I_OF(void))  d2i_ASN1_BIT_STRING,
-       (void *(*)(void))ASN1_STRING_new,
-       (void (*)(void *))ASN1_STRING_free};
-
-ASN1_METHOD *ASN1_IA5STRING_asn1_meth(void)
-       {
-       return(&ia5string_meth);
-       }
-
-ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(void)
-       {
-       return(&bit_string_meth);
-       }
index 365e467..3978c91 100644 (file)
@@ -139,7 +139,7 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
                                ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT);
                                goto err;
                                }
-                       if (!use_bn && l > (ULONG_MAX / 10L))
+                       if (!use_bn && l >= ((ULONG_MAX - 80) / 10L))
                                {
                                use_bn = 1;
                                if (!bl)
@@ -281,8 +281,6 @@ ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
        return ret;
 err:
        ASN1err(ASN1_F_D2I_ASN1_OBJECT,i);
-       if ((ret != NULL) && ((a == NULL) || (*a != ret)))
-               ASN1_OBJECT_free(ret);
        return(NULL);
 }
 ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
@@ -290,11 +288,12 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
        {
        ASN1_OBJECT *ret=NULL;
        const unsigned char *p;
+       unsigned char *data;
        int i;
        /* Sanity check OID encoding: can't have leading 0x80 in
         * subidentifiers, see: X.690 8.19.2
         */
-       for (i = 0, p = *pp + 1; i < len - 1; i++, p++)
+       for (i = 0, p = *pp; i < len; i++, p++)
                {
                if (*p == 0x80 && (!i || !(p[-1] & 0x80)))
                        {
@@ -313,15 +312,22 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
        else    ret=(*a);
 
        p= *pp;
-       if ((ret->data == NULL) || (ret->length < len))
+       /* detach data from object */
+       data = (unsigned char *)ret->data;
+       ret->data = NULL;
+       /* once detached we can change it */
+       if ((data == NULL) || (ret->length < len))
                {
-               if (ret->data != NULL) OPENSSL_free(ret->data);
-               ret->data=(unsigned char *)OPENSSL_malloc(len ? (int)len : 1);
-               ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA;
-               if (ret->data == NULL)
+               ret->length=0;
+               if (data != NULL) OPENSSL_free(data);
+               data=(unsigned char *)OPENSSL_malloc(len ? (int)len : 1);
+               if (data == NULL)
                        { i=ERR_R_MALLOC_FAILURE; goto err; }
+               ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA;
                }
-       memcpy(ret->data,p,(int)len);
+       memcpy(data,p,(int)len);
+       /* reattach data to object, after which it remains const */
+       ret->data  =data;
        ret->length=(int)len;
        ret->sn=NULL;
        ret->ln=NULL;
@@ -370,7 +376,7 @@ void ASN1_OBJECT_free(ASN1_OBJECT *a)
                }
        if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA)
                {
-               if (a->data != NULL) OPENSSL_free(a->data);
+               if (a->data != NULL) OPENSSL_free((void *)a->data);
                a->data=NULL;
                a->length=0;
                }
index 24fd0f8..e8725e4 100644 (file)
 #include "cryptlib.h"
 #include <openssl/asn1.h>
 
-ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(ASN1_OCTET_STRING *x)
+ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(const ASN1_OCTET_STRING *x)
 { return M_ASN1_OCTET_STRING_dup(x); }
 
-int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b)
+int ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a, const ASN1_OCTET_STRING *b)
 { return M_ASN1_OCTET_STRING_cmp(a, b); }
 
 int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, const unsigned char *d, int len)
index 958558c..d726c8d 100644 (file)
@@ -85,8 +85,9 @@ static int SetBlobCmp(const void *elem1, const void *elem2 )
     }
 
 /* int is_set:  if TRUE, then sort the contents (i.e. it isn't a SEQUENCE)    */
-int i2d_ASN1_SET(STACK *a, unsigned char **pp, i2d_of_void *i2d, int ex_tag,
-                int ex_class, int is_set)
+int i2d_ASN1_SET(STACK_OF(OPENSSL_BLOCK) *a, unsigned char **pp,
+                i2d_of_void *i2d, int ex_tag, int ex_class,
+                int is_set)
        {
        int ret=0,r;
        int i;
@@ -96,8 +97,8 @@ int i2d_ASN1_SET(STACK *a, unsigned char **pp, i2d_of_void *i2d, int ex_tag,
         int totSize;
 
        if (a == NULL) return(0);
-       for (i=sk_num(a)-1; i>=0; i--)
-               ret+=i2d(sk_value(a,i),NULL);
+       for (i=sk_OPENSSL_BLOCK_num(a)-1; i>=0; i--)
+               ret+=i2d(sk_OPENSSL_BLOCK_value(a,i),NULL);
        r=ASN1_object_size(1,ret,ex_tag);
        if (pp == NULL) return(r);
 
@@ -108,10 +109,10 @@ int i2d_ASN1_SET(STACK *a, unsigned char **pp, i2d_of_void *i2d, int ex_tag,
        /* And then again by Ben */
        /* And again by Steve */
 
-       if(!is_set || (sk_num(a) < 2))
+       if(!is_set || (sk_OPENSSL_BLOCK_num(a) < 2))
                {
-               for (i=0; i<sk_num(a); i++)
-                       i2d(sk_value(a,i),&p);
+               for (i=0; i<sk_OPENSSL_BLOCK_num(a); i++)
+                       i2d(sk_OPENSSL_BLOCK_value(a,i),&p);
 
                *pp=p;
                return(r);
@@ -119,17 +120,17 @@ int i2d_ASN1_SET(STACK *a, unsigned char **pp, i2d_of_void *i2d, int ex_tag,
 
         pStart  = p; /* Catch the beg of Setblobs*/
                /* In this array we will store the SET blobs */
-               rgSetBlob = (MYBLOB *)OPENSSL_malloc(sk_num(a) * sizeof(MYBLOB));
+               rgSetBlob = OPENSSL_malloc(sk_OPENSSL_BLOCK_num(a) * sizeof(MYBLOB));
                if (rgSetBlob == NULL)
                        {
                        ASN1err(ASN1_F_I2D_ASN1_SET,ERR_R_MALLOC_FAILURE);
                        return(0);
                        }
 
-        for (i=0; i<sk_num(a); i++)
+        for (i=0; i<sk_OPENSSL_BLOCK_num(a); i++)
                {
                 rgSetBlob[i].pbData = p;  /* catch each set encode blob */
-                i2d(sk_value(a,i),&p);
+                i2d(sk_OPENSSL_BLOCK_value(a,i),&p);
                 rgSetBlob[i].cbData = p - rgSetBlob[i].pbData; /* Length of this
 SetBlob
 */
@@ -139,7 +140,7 @@ SetBlob
 
  /* Now we have to sort the blobs. I am using a simple algo.
     *Sort ptrs *Copy to temp-mem *Copy from temp-mem to user-mem*/
-        qsort( rgSetBlob, sk_num(a), sizeof(MYBLOB), SetBlobCmp);
+        qsort( rgSetBlob, sk_OPENSSL_BLOCK_num(a), sizeof(MYBLOB), SetBlobCmp);
                if (!(pTempMem = OPENSSL_malloc(totSize)))
                        {
                        ASN1err(ASN1_F_I2D_ASN1_SET,ERR_R_MALLOC_FAILURE);
@@ -148,7 +149,7 @@ SetBlob
 
 /* Copy to temp mem */
         p = pTempMem;
-        for(i=0; i<sk_num(a); ++i)
+        for(i=0; i<sk_OPENSSL_BLOCK_num(a); ++i)
                {
                 memcpy(p, rgSetBlob[i].pbData, rgSetBlob[i].cbData);
                 p += rgSetBlob[i].cbData;
@@ -162,16 +163,18 @@ SetBlob
         return(r);
         }
 
-STACK *d2i_ASN1_SET(STACK **a, const unsigned char **pp, long length,
-                   d2i_of_void *d2i, void (*free_func)(void *), int ex_tag,
-                   int ex_class)
+STACK_OF(OPENSSL_BLOCK) *d2i_ASN1_SET(STACK_OF(OPENSSL_BLOCK) **a,
+                             const unsigned char **pp,
+                             long length, d2i_of_void *d2i,
+                             void (*free_func)(OPENSSL_BLOCK), int ex_tag,
+                             int ex_class)
        {
        ASN1_const_CTX c;
-       STACK *ret=NULL;
+       STACK_OF(OPENSSL_BLOCK) *ret=NULL;
 
        if ((a == NULL) || ((*a) == NULL))
                {
-               if ((ret=sk_new_null()) == NULL)
+               if ((ret=sk_OPENSSL_BLOCK_new_null()) == NULL)
                        {
                        ASN1err(ASN1_F_D2I_ASN1_SET,ERR_R_MALLOC_FAILURE);
                        goto err;
@@ -216,10 +219,10 @@ STACK *d2i_ASN1_SET(STACK **a, const unsigned char **pp, long length,
                if ((s=d2i(NULL,&c.p,c.slen)) == NULL)
                        {
                        ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_ERROR_PARSING_SET_ELEMENT);
-                       asn1_add_error(*pp,(int)(c.q- *pp));
+                       asn1_add_error(*pp,(int)(c.p- *pp));
                        goto err;
                        }
-               if (!sk_push(ret,s)) goto err;
+               if (!sk_OPENSSL_BLOCK_push(ret,s)) goto err;
                }
        if (a != NULL) (*a)=ret;
        *pp=c.p;
@@ -228,9 +231,9 @@ err:
        if ((ret != NULL) && ((a == NULL) || (*a != ret)))
                {
                if (free_func != NULL)
-                       sk_pop_free(ret,free_func);
+                       sk_OPENSSL_BLOCK_pop_free(ret,free_func);
                else
-                       sk_free(ret);
+                       sk_OPENSSL_BLOCK_free(ret);
                }
        return(NULL);
        }
index 4dee45f..ff63bfc 100644 (file)
 #include <openssl/x509.h>
 #include <openssl/objects.h>
 #include <openssl/buffer.h>
+#include "asn1_locl.h"
 
 #ifndef NO_ASN1_OLD
 
@@ -218,45 +219,47 @@ int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
        {
        EVP_MD_CTX ctx;
        unsigned char *buf_in=NULL,*buf_out=NULL;
-       int i,inl=0,outl=0,outll=0;
-       X509_ALGOR *a;
+       int inl=0,outl=0,outll=0;
+       int signid, paramtype;
 
-       EVP_MD_CTX_init(&ctx);
-       for (i=0; i<2; i++)
+       if (type == NULL)
                {
-               if (i == 0)
-                       a=algor1;
-               else
-                       a=algor2;
-               if (a == NULL) continue;
-                if (type->pkey_type == NID_dsaWithSHA1 ||
-                       type->pkey_type == NID_ecdsa_with_SHA1)
-                       {
-                       /* special case: RFC 3279 tells us to omit 'parameters'
-                        * with id-dsa-with-sha1 and ecdsa-with-SHA1 */
-                       ASN1_TYPE_free(a->parameter);
-                       a->parameter = NULL;
-                       }
-               else if ((a->parameter == NULL) || 
-                       (a->parameter->type != V_ASN1_NULL))
-                       {
-                       ASN1_TYPE_free(a->parameter);
-                       if ((a->parameter=ASN1_TYPE_new()) == NULL) goto err;
-                       a->parameter->type=V_ASN1_NULL;
-                       }
-               ASN1_OBJECT_free(a->algorithm);
-               a->algorithm=OBJ_nid2obj(type->pkey_type);
-               if (a->algorithm == NULL)
-                       {
-                       ASN1err(ASN1_F_ASN1_ITEM_SIGN,ASN1_R_UNKNOWN_OBJECT_TYPE);
-                       goto err;
-                       }
-               if (a->algorithm->length == 0)
+               int def_nid;
+               if (EVP_PKEY_get_default_digest_nid(pkey, &def_nid) > 0)
+                       type = EVP_get_digestbynid(def_nid);
+               }
+
+       if (type == NULL)
+               {
+               ASN1err(ASN1_F_ASN1_ITEM_SIGN, ASN1_R_NO_DEFAULT_DIGEST);
+               return 0;
+               }
+
+       if (type->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE)
+               {
+               if (!pkey->ameth ||
+                       !OBJ_find_sigid_by_algs(&signid, EVP_MD_nid(type),
+                                               pkey->ameth->pkey_id))
                        {
-                       ASN1err(ASN1_F_ASN1_ITEM_SIGN,ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD);
-                       goto err;
+                       ASN1err(ASN1_F_ASN1_ITEM_SIGN,
+                               ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED);
+                       return 0;
                        }
                }
+       else
+               signid = type->pkey_type;
+
+       if (pkey->ameth->pkey_flags & ASN1_PKEY_SIGPARAM_NULL)
+               paramtype = V_ASN1_NULL;
+       else
+               paramtype = V_ASN1_UNDEF;
+
+       if (algor1)
+               X509_ALGOR_set0(algor1, OBJ_nid2obj(signid), paramtype, NULL);
+       if (algor2)
+               X509_ALGOR_set0(algor2, OBJ_nid2obj(signid), paramtype, NULL);
+
+       EVP_MD_CTX_init(&ctx);
        inl=ASN1_item_i2d(asn,&buf_in, it);
        outll=outl=EVP_PKEY_size(pkey);
        buf_out=(unsigned char *)OPENSSL_malloc((unsigned int)outl);
@@ -267,12 +270,7 @@ int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
                goto err;
                }
 
-       if (!EVP_SignInit_ex(&ctx,type, NULL))
-               {
-               outl=0;
-               ASN1err(ASN1_F_ASN1_ITEM_SIGN,ERR_R_EVP_LIB);
-               goto err;
-               }
+       EVP_SignInit_ex(&ctx,type, NULL);
        EVP_SignUpdate(&ctx,(unsigned char *)buf_in,inl);
        if (!EVP_SignFinal(&ctx,(unsigned char *)buf_out,
                        (unsigned int *)&outl,pkey))
index b68ae43..2fc48c1 100644 (file)
@@ -67,7 +67,6 @@ static STACK_OF(ASN1_STRING_TABLE) *stable = NULL;
 static void st_free(ASN1_STRING_TABLE *tbl);
 static int sk_table_cmp(const ASN1_STRING_TABLE * const *a,
                        const ASN1_STRING_TABLE * const *b);
-static int table_cmp(const void *a, const void *b);
 
 
 /* This is the global mask for the mbstring functions: this is use to
@@ -158,7 +157,7 @@ ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in,
 
 /* This table must be kept in NID order */
 
-static ASN1_STRING_TABLE tbl_standard[] = {
+static const ASN1_STRING_TABLE tbl_standard[] = {
 {NID_commonName,               1, ub_common_name, DIRSTRING_TYPE, 0},
 {NID_countryName,              2, 2, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
 {NID_localityName,             1, ub_locality_name, DIRSTRING_TYPE, 0},
@@ -186,22 +185,23 @@ static int sk_table_cmp(const ASN1_STRING_TABLE * const *a,
        return (*a)->nid - (*b)->nid;
 }
 
-static int table_cmp(const void *a, const void *b)
+DECLARE_OBJ_BSEARCH_CMP_FN(ASN1_STRING_TABLE, ASN1_STRING_TABLE, table);
+
+static int table_cmp(const ASN1_STRING_TABLE *a, const ASN1_STRING_TABLE *b)
 {
-       const ASN1_STRING_TABLE *sa = a, *sb = b;
-       return sa->nid - sb->nid;
+       return a->nid - b->nid;
 }
 
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(ASN1_STRING_TABLE, ASN1_STRING_TABLE, table);
+
 ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid)
 {
        int idx;
        ASN1_STRING_TABLE *ttmp;
        ASN1_STRING_TABLE fnd;
        fnd.nid = nid;
-       ttmp = (ASN1_STRING_TABLE *) OBJ_bsearch((char *)&fnd,
-                                       (char *)tbl_standard, 
-                       sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE),
-                       sizeof(ASN1_STRING_TABLE), table_cmp);
+       ttmp = OBJ_bsearch_table(&fnd, tbl_standard, 
+                          sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE));
        if(ttmp) return ttmp;
        if(!stable) return NULL;
        idx = sk_ASN1_STRING_TABLE_find(stable, &fnd);
index 159681f..e2eb9b2 100644 (file)
@@ -100,18 +100,29 @@ int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp)
 
 ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)
        {
+       return ASN1_TIME_adj(s, t, 0, 0);
+       }
+
+ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t,
+                               int offset_day, long offset_sec)
+       {
        struct tm *ts;
        struct tm data;
 
        ts=OPENSSL_gmtime(&t,&data);
        if (ts == NULL)
                {
-               ASN1err(ASN1_F_ASN1_TIME_SET, ASN1_R_ERROR_GETTING_TIME);
+               ASN1err(ASN1_F_ASN1_TIME_ADJ, ASN1_R_ERROR_GETTING_TIME);
                return NULL;
                }
+       if (offset_day || offset_sec)
+               { 
+               if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
+                       return NULL;
+               }
        if((ts->tm_year >= 50) && (ts->tm_year < 150))
-                                       return ASN1_UTCTIME_set(s, t);
-       return ASN1_GENERALIZEDTIME_set(s,t);
+                       return ASN1_UTCTIME_adj(s, t, offset_day, offset_sec);
+       return ASN1_GENERALIZEDTIME_adj(s, t, offset_day, offset_sec);
        }
 
 int ASN1_TIME_check(ASN1_TIME *t)
@@ -162,3 +173,26 @@ ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZE
 
        return ret;
        }
+
+int ASN1_TIME_set_string(ASN1_TIME *s, const char *str)
+       {
+       ASN1_TIME t;
+
+       t.length = strlen(str);
+       t.data = (unsigned char *)str;
+       t.flags = 0;
+       
+       t.type = V_ASN1_UTCTIME;
+
+       if (!ASN1_TIME_check(&t))
+               {
+               t.type = V_ASN1_GENERALIZEDTIME;
+               if (!ASN1_TIME_check(&t))
+                       return 0;
+               }
+       
+       if (s && !ASN1_STRING_copy((ASN1_STRING *)s, (ASN1_STRING *)&t))
+                       return 0;
+
+       return 1;
+       }
index 36becea..a45d2f9 100644 (file)
@@ -77,7 +77,10 @@ void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value)
                ASN1_primitive_free((ASN1_VALUE **)tmp_a, NULL);
                }
        a->type=type;
-       a->value.ptr=value;
+       if (type == V_ASN1_BOOLEAN)
+               a->value.boolean = value ? 0xff : 0;
+       else
+               a->value.ptr=value;
        }
 
 int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value)
@@ -98,7 +101,7 @@ int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value)
        else
                {
                ASN1_STRING *sdup;
-               sdup = ASN1_STRING_dup((ASN1_STRING *)value);
+               sdup = ASN1_STRING_dup(value);
                if (!sdup)
                        return 0;
                ASN1_TYPE_set(a, type, sdup);
@@ -108,3 +111,49 @@ int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value)
 
 IMPLEMENT_STACK_OF(ASN1_TYPE)
 IMPLEMENT_ASN1_SET_OF(ASN1_TYPE)
+
+/* Returns 0 if they are equal, != 0 otherwise. */
+int ASN1_TYPE_cmp(ASN1_TYPE *a, ASN1_TYPE *b)
+       {
+       int result = -1;
+
+       if (!a || !b || a->type != b->type) return -1;
+
+       switch (a->type)
+               {
+       case V_ASN1_OBJECT:
+               result = OBJ_cmp(a->value.object, b->value.object);
+               break;
+       case V_ASN1_NULL:
+               result = 0;     /* They do not have content. */
+               break;
+       case V_ASN1_INTEGER:
+       case V_ASN1_NEG_INTEGER:
+       case V_ASN1_ENUMERATED:
+       case V_ASN1_NEG_ENUMERATED:
+       case V_ASN1_BIT_STRING:
+       case V_ASN1_OCTET_STRING:
+       case V_ASN1_SEQUENCE:
+       case V_ASN1_SET:
+       case V_ASN1_NUMERICSTRING:
+       case V_ASN1_PRINTABLESTRING:
+       case V_ASN1_T61STRING:
+       case V_ASN1_VIDEOTEXSTRING:
+       case V_ASN1_IA5STRING:
+       case V_ASN1_UTCTIME:
+       case V_ASN1_GENERALIZEDTIME:
+       case V_ASN1_GRAPHICSTRING:
+       case V_ASN1_VISIBLESTRING:
+       case V_ASN1_GENERALSTRING:
+       case V_ASN1_UNIVERSALSTRING:
+       case V_ASN1_BMPSTRING:
+       case V_ASN1_UTF8STRING:
+       case V_ASN1_OTHER:
+       default:
+               result = ASN1_STRING_cmp((ASN1_STRING *) a->value.ptr,
+                                        (ASN1_STRING *) b->value.ptr);
+               break;
+               }
+
+       return result;
+       }
index d31c028..072e236 100644 (file)
@@ -114,8 +114,8 @@ err:
 
 int ASN1_UTCTIME_check(ASN1_UTCTIME *d)
        {
-       static int min[8]={ 0, 1, 1, 0, 0, 0, 0, 0};
-       static int max[8]={99,12,31,23,59,59,12,59};
+       static const int min[8]={ 0, 1, 1, 0, 0, 0, 0, 0};
+       static const int max[8]={99,12,31,23,59,59,12,59};
        char *a;
        int n,i,l,o;
 
@@ -186,6 +186,12 @@ int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str)
 
 ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t)
        {
+       return ASN1_UTCTIME_adj(s, t, 0, 0);
+       }
+
+ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
+                               int offset_day, long offset_sec)
+       {
        char *p;
        struct tm *ts;
        struct tm data;
@@ -200,13 +206,22 @@ ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t)
        if (ts == NULL)
                return(NULL);
 
+       if (offset_day || offset_sec)
+               { 
+               if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
+                       return NULL;
+               }
+
+       if((ts->tm_year < 50) || (ts->tm_year >= 150))
+               return NULL;
+
        p=(char *)s->data;
        if ((p == NULL) || ((size_t)s->length < len))
                {
                p=OPENSSL_malloc(len);
                if (p == NULL)
                        {
-                       ASN1err(ASN1_F_ASN1_UTCTIME_SET,ERR_R_MALLOC_FAILURE);
+                       ASN1err(ASN1_F_ASN1_UTCTIME_ADJ,ERR_R_MALLOC_FAILURE);
                        return(NULL);
                        }
                if (s->data != NULL)
index da3efaa..cecdb13 100644 (file)
@@ -60,6 +60,7 @@
 #include <time.h>
 
 #include "cryptlib.h"
+#include "asn1_locl.h"
 
 #ifndef NO_SYS_TYPES_H
 # include <sys/types.h>
@@ -100,12 +101,7 @@ int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *a, ASN1_BIT_STRING *signature,
        p=buf_in;
 
        i2d(data,&p);
-       if (!EVP_VerifyInit_ex(&ctx,type, NULL))
-               {
-               ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);
-               ret=0;
-               goto err;
-               }
+       EVP_VerifyInit_ex(&ctx,type, NULL);
        EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl);
 
        OPENSSL_cleanse(buf_in,(unsigned int)inl);
@@ -134,19 +130,34 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, ASN1_BIT_STRING *signat
             void *asn, EVP_PKEY *pkey)
        {
        EVP_MD_CTX ctx;
-       const EVP_MD *type;
+       const EVP_MD *type = NULL;
        unsigned char *buf_in=NULL;
-       int ret= -1,i,inl;
+       int ret= -1,inl;
+
+       int mdnid, pknid;
 
        EVP_MD_CTX_init(&ctx);
-       i=OBJ_obj2nid(a->algorithm);
-       type=EVP_get_digestbyname(OBJ_nid2sn(i));
+
+       /* Convert signature OID into digest and public key OIDs */
+       if (!OBJ_find_sigid_algs(OBJ_obj2nid(a->algorithm), &mdnid, &pknid))
+               {
+               ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM);
+               goto err;
+               }
+       type=EVP_get_digestbynid(mdnid);
        if (type == NULL)
                {
                ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
                goto err;
                }
 
+       /* Check public key OID matches public key type */
+       if (EVP_PKEY_type(pknid) != pkey->ameth->pkey_id)
+               {
+               ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_WRONG_PUBLIC_KEY_TYPE);
+               goto err;
+               }
+
        if (!EVP_VerifyInit_ex(&ctx,type, NULL))
                {
                ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB);
diff --git a/deps/openssl/openssl/crypto/asn1/ameth_lib.c b/deps/openssl/openssl/crypto/asn1/ameth_lib.c
new file mode 100644 (file)
index 0000000..5a581b9
--- /dev/null
@@ -0,0 +1,450 @@
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project 2006.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include "cryptlib.h"
+#include <openssl/asn1t.h>
+#include <openssl/x509.h>
+#ifndef OPENSSL_NO_ENGINE
+#include <openssl/engine.h>
+#endif
+#include "asn1_locl.h"
+
+extern const EVP_PKEY_ASN1_METHOD rsa_asn1_meths[];
+extern const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[];
+extern const EVP_PKEY_ASN1_METHOD dh_asn1_meth;
+extern const EVP_PKEY_ASN1_METHOD eckey_asn1_meth;
+extern const EVP_PKEY_ASN1_METHOD hmac_asn1_meth;
+
+/* Keep this sorted in type order !! */
+static const EVP_PKEY_ASN1_METHOD *standard_methods[] = 
+       {
+#ifndef OPENSSL_NO_RSA
+       &rsa_asn1_meths[0],
+       &rsa_asn1_meths[1],
+#endif
+#ifndef OPENSSL_NO_DH
+       &dh_asn1_meth,
+#endif
+#ifndef OPENSSL_NO_DSA
+       &dsa_asn1_meths[0],
+       &dsa_asn1_meths[1],
+       &dsa_asn1_meths[2],
+       &dsa_asn1_meths[3],
+       &dsa_asn1_meths[4],
+#endif
+#ifndef OPENSSL_NO_EC
+       &eckey_asn1_meth,
+#endif
+       &hmac_asn1_meth
+       };
+
+typedef int sk_cmp_fn_type(const char * const *a, const char * const *b);
+DECLARE_STACK_OF(EVP_PKEY_ASN1_METHOD)
+static STACK_OF(EVP_PKEY_ASN1_METHOD) *app_methods = NULL;
+
+
+
+#ifdef TEST
+void main()
+       {
+       int i;
+       for (i = 0;
+               i < sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *);
+               i++)
+               fprintf(stderr, "Number %d id=%d (%s)\n", i,
+                       standard_methods[i]->pkey_id,
+                       OBJ_nid2sn(standard_methods[i]->pkey_id));
+       }
+#endif
+
+DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *,
+                          const EVP_PKEY_ASN1_METHOD *, ameth);
+
+static int ameth_cmp(const EVP_PKEY_ASN1_METHOD * const *a,
+                    const EVP_PKEY_ASN1_METHOD * const *b)
+       {
+        return ((*a)->pkey_id - (*b)->pkey_id);
+       }
+
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *,
+                            const EVP_PKEY_ASN1_METHOD *, ameth);
+
+int EVP_PKEY_asn1_get_count(void)
+       {
+       int num = sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *);
+       if (app_methods)
+               num += sk_EVP_PKEY_ASN1_METHOD_num(app_methods);
+       return num;
+       }
+
+const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx)
+       {
+       int num = sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *);
+       if (idx < 0)
+               return NULL; 
+       if (idx < num)
+               return standard_methods[idx];
+       idx -= num;
+       return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx);
+       }
+
+static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type)
+       {
+       EVP_PKEY_ASN1_METHOD tmp;
+       const EVP_PKEY_ASN1_METHOD *t = &tmp, **ret;
+       tmp.pkey_id = type;
+       if (app_methods)
+               {
+               int idx;
+               idx = sk_EVP_PKEY_ASN1_METHOD_find(app_methods, &tmp);
+               if (idx >= 0)
+                       return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx);
+               }
+       ret = OBJ_bsearch_ameth(&t, standard_methods,
+                         sizeof(standard_methods)
+                         /sizeof(EVP_PKEY_ASN1_METHOD *));
+       if (!ret || !*ret)
+               return NULL;
+       return *ret;
+       }
+
+/* Find an implementation of an ASN1 algorithm. If 'pe' is not NULL
+ * also search through engines and set *pe to a functional reference
+ * to the engine implementing 'type' or NULL if no engine implements 
+ * it.
+ */
+
+const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type)
+       {
+       const EVP_PKEY_ASN1_METHOD *t;
+
+       for (;;)
+               {
+               t = pkey_asn1_find(type);
+               if (!t || !(t->pkey_flags & ASN1_PKEY_ALIAS))
+                       break;
+               type = t->pkey_base_id;
+               }
+       if (pe)
+               {
+#ifndef OPENSSL_NO_ENGINE
+               ENGINE *e;
+               /* type will contain the final unaliased type */
+               e = ENGINE_get_pkey_asn1_meth_engine(type);
+               if (e)
+                       {
+                       *pe = e;
+                       return ENGINE_get_pkey_asn1_meth(e, type);
+                       }
+#endif
+               *pe = NULL;
+               }
+       return t;
+       }
+
+const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe,
+                                       const char *str, int len)
+       {
+       int i;
+       const EVP_PKEY_ASN1_METHOD *ameth;
+       if (len == -1)
+               len = strlen(str);
+       if (pe)
+               {
+#ifndef OPENSSL_NO_ENGINE
+               ENGINE *e;
+               ameth = ENGINE_pkey_asn1_find_str(&e, str, len);
+               if (ameth)
+                       {
+                       /* Convert structural into
+                        * functional reference
+                        */
+                       if (!ENGINE_init(e))
+                               ameth = NULL;
+                       ENGINE_free(e);
+                       *pe = e;
+                       return ameth;
+                       }
+#endif
+               *pe = NULL;
+               }
+       for (i = 0; i < EVP_PKEY_asn1_get_count(); i++)
+               {
+               ameth = EVP_PKEY_asn1_get0(i);
+               if (ameth->pkey_flags & ASN1_PKEY_ALIAS)
+                       continue;
+               if (((int)strlen(ameth->pem_str) == len) && 
+                       !strncasecmp(ameth->pem_str, str, len))
+                       return ameth;
+               }
+       return NULL;
+       }
+
+int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth)
+       {
+       if (app_methods == NULL)
+               {
+               app_methods = sk_EVP_PKEY_ASN1_METHOD_new(ameth_cmp);
+               if (!app_methods)
+                       return 0;
+               }
+       if (!sk_EVP_PKEY_ASN1_METHOD_push(app_methods, ameth))
+               return 0;
+       sk_EVP_PKEY_ASN1_METHOD_sort(app_methods);
+       return 1;
+       }
+
+int EVP_PKEY_asn1_add_alias(int to, int from)
+       {
+       EVP_PKEY_ASN1_METHOD *ameth;
+       ameth = EVP_PKEY_asn1_new(from, ASN1_PKEY_ALIAS, NULL, NULL);
+       if (!ameth)
+               return 0;
+       ameth->pkey_base_id = to;
+       return EVP_PKEY_asn1_add0(ameth);
+       }
+
+int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *ppkey_base_id, int *ppkey_flags,
+                               const char **pinfo, const char **ppem_str,
+                                       const EVP_PKEY_ASN1_METHOD *ameth)
+       {
+       if (!ameth)
+               return 0;
+       if (ppkey_id)
+               *ppkey_id = ameth->pkey_id;
+       if (ppkey_base_id)
+               *ppkey_base_id = ameth->pkey_base_id;
+       if (ppkey_flags)
+               *ppkey_flags = ameth->pkey_flags;
+       if (pinfo)
+               *pinfo = ameth->info;
+       if (ppem_str)
+               *ppem_str = ameth->pem_str;
+       return 1;
+       }
+
+const EVP_PKEY_ASN1_METHOD* EVP_PKEY_get0_asn1(EVP_PKEY *pkey)
+       {
+       return pkey->ameth;
+       }
+
+EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags,
+                                       const char *pem_str, const char *info)
+       {
+       EVP_PKEY_ASN1_METHOD *ameth;
+       ameth = OPENSSL_malloc(sizeof(EVP_PKEY_ASN1_METHOD));
+       if (!ameth)
+               return NULL;
+
+       ameth->pkey_id = id;
+       ameth->pkey_base_id = id;
+       ameth->pkey_flags = flags | ASN1_PKEY_DYNAMIC;
+
+       if (info)
+               {
+               ameth->info = BUF_strdup(info);
+               if (!ameth->info)
+                       goto err;
+               }
+       else
+               ameth->info = NULL;
+
+       if (pem_str)
+               {
+               ameth->pem_str = BUF_strdup(pem_str);
+               if (!ameth->pem_str)
+                       goto err;
+               }
+       else
+               ameth->pem_str = NULL;
+
+       ameth->pub_decode = 0;
+       ameth->pub_encode = 0;
+       ameth->pub_cmp = 0;
+       ameth->pub_print = 0;
+
+       ameth->priv_decode = 0;
+       ameth->priv_encode = 0;
+       ameth->priv_print = 0;
+
+       ameth->old_priv_encode = 0;
+       ameth->old_priv_decode = 0;
+
+       ameth->pkey_size = 0;
+       ameth->pkey_bits = 0;
+
+       ameth->param_decode = 0;
+       ameth->param_encode = 0;
+       ameth->param_missing = 0;
+       ameth->param_copy = 0;
+       ameth->param_cmp = 0;
+       ameth->param_print = 0;
+
+       ameth->pkey_free = 0;
+       ameth->pkey_ctrl = 0;
+
+       return ameth;
+
+       err:
+
+       EVP_PKEY_asn1_free(ameth);
+       return NULL;
+
+       }
+
+void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst, 
+                       const EVP_PKEY_ASN1_METHOD *src)
+       {
+
+       dst->pub_decode = src->pub_decode;
+       dst->pub_encode = src->pub_encode;
+       dst->pub_cmp = src->pub_cmp;
+       dst->pub_print = src->pub_print;
+
+       dst->priv_decode = src->priv_decode;
+       dst->priv_encode = src->priv_encode;
+       dst->priv_print = src->priv_print;
+
+       dst->old_priv_encode = src->old_priv_encode;
+       dst->old_priv_decode = src->old_priv_decode;
+
+       dst->pkey_size = src->pkey_size;
+       dst->pkey_bits = src->pkey_bits;
+
+       dst->param_decode = src->param_decode;
+       dst->param_encode = src->param_encode;
+       dst->param_missing = src->param_missing;
+       dst->param_copy = src->param_copy;
+       dst->param_cmp = src->param_cmp;
+       dst->param_print = src->param_print;
+
+       dst->pkey_free = src->pkey_free;
+       dst->pkey_ctrl = src->pkey_ctrl;
+
+       }
+
+void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth)
+       {
+       if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC))
+               {
+               if (ameth->pem_str)
+                       OPENSSL_free(ameth->pem_str);
+               if (ameth->info)
+                       OPENSSL_free(ameth->info);
+               OPENSSL_free(ameth);
+               }
+       }
+
+void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth,
+               int (*pub_decode)(EVP_PKEY *pk, X509_PUBKEY *pub),
+               int (*pub_encode)(X509_PUBKEY *pub, const EVP_PKEY *pk),
+               int (*pub_cmp)(const EVP_PKEY *a, const EVP_PKEY *b),
+               int (*pub_print)(BIO *out, const EVP_PKEY *pkey, int indent,
+                                                       ASN1_PCTX *pctx),
+               int (*pkey_size)(const EVP_PKEY *pk),
+               int (*pkey_bits)(const EVP_PKEY *pk))
+       {
+       ameth->pub_decode = pub_decode;
+       ameth->pub_encode = pub_encode;
+       ameth->pub_cmp = pub_cmp;
+       ameth->pub_print = pub_print;
+       ameth->pkey_size = pkey_size;
+       ameth->pkey_bits = pkey_bits;
+       }
+
+void EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth,
+               int (*priv_decode)(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf),
+               int (*priv_encode)(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk),
+               int (*priv_print)(BIO *out, const EVP_PKEY *pkey, int indent,
+                                                       ASN1_PCTX *pctx))
+       {
+       ameth->priv_decode = priv_decode;
+       ameth->priv_encode = priv_encode;
+       ameth->priv_print = priv_print;
+       }
+
+void EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth,
+               int (*param_decode)(EVP_PKEY *pkey,
+                               const unsigned char **pder, int derlen),
+               int (*param_encode)(const EVP_PKEY *pkey, unsigned char **pder),
+               int (*param_missing)(const EVP_PKEY *pk),
+               int (*param_copy)(EVP_PKEY *to, const EVP_PKEY *from),
+               int (*param_cmp)(const EVP_PKEY *a, const EVP_PKEY *b),
+               int (*param_print)(BIO *out, const EVP_PKEY *pkey, int indent,
+                                                       ASN1_PCTX *pctx))
+       {
+       ameth->param_decode = param_decode;
+       ameth->param_encode = param_encode;
+       ameth->param_missing = param_missing;
+       ameth->param_copy = param_copy;
+       ameth->param_cmp = param_cmp;
+       ameth->param_print = param_print;
+       }
+
+void EVP_PKEY_asn1_set_free(EVP_PKEY_ASN1_METHOD *ameth,
+               void (*pkey_free)(EVP_PKEY *pkey))
+       {
+       ameth->pkey_free = pkey_free;
+       }
+
+void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth,
+               int (*pkey_ctrl)(EVP_PKEY *pkey, int op,
+                                                       long arg1, void *arg2))
+       {
+       ameth->pkey_ctrl = pkey_ctrl;
+       }
index d9d5443..59540e4 100644 (file)
@@ -213,7 +213,7 @@ typedef struct asn1_object_st
        const char *sn,*ln;
        int nid;
        int length;
-       unsigned char *data;
+       const unsigned char *data;      /* data remains const after init */
        int flags;      /* Should we free this one */
        } ASN1_OBJECT;
 
@@ -228,8 +228,12 @@ typedef struct asn1_object_st
  * complete and is a place holder for content when it had all been 
  * accessed. The flag will be reset when content has been written to it.
  */
-#define ASN1_STRING_FLAG_CONT 0x020 
 
+#define ASN1_STRING_FLAG_CONT 0x020 
+/* This flag is used by ASN1 code to indicate an ASN1_STRING is an MSTRING
+ * type.
+ */
+#define ASN1_STRING_FLAG_MSTRING 0x040 
 /* This is the base type that holds just about everything :-) */
 typedef struct asn1_string_st
        {
@@ -330,6 +334,13 @@ typedef struct ASN1_VALUE_st ASN1_VALUE;
        type *name##_new(void); \
        void name##_free(type *a);
 
+#define DECLARE_ASN1_PRINT_FUNCTION(stname) \
+       DECLARE_ASN1_PRINT_FUNCTION_fname(stname, stname)
+
+#define DECLARE_ASN1_PRINT_FUNCTION_fname(stname, fname) \
+       int fname##_print_ctx(BIO *out, stname *x, int indent, \
+                                        const ASN1_PCTX *pctx);
+
 #define D2I_OF(type) type *(*)(type **,const unsigned char **,long)
 #define I2D_OF(type) int (*)(type *,unsigned char **)
 #define I2D_OF_const(type) int (*)(const type *,unsigned char **)
@@ -344,8 +355,6 @@ typedef struct ASN1_VALUE_st ASN1_VALUE;
     ((void*) (1 ? p : (type*)0))
 #define CHECKED_PPTR_OF(type, p) \
     ((void**) (1 ? p : (type**)0))
-#define CHECKED_PTR_OF_TO_CHAR(type, p) \
-    ((char*) (1 ? p : (type*)0))
 
 #define TYPEDEF_D2I_OF(type) typedef type *d2i_of_##type(type **,const unsigned char **,long)
 #define TYPEDEF_I2D_OF(type) typedef int i2d_of_##type(type *,unsigned char **)
@@ -536,28 +545,23 @@ typedef struct asn1_type_st
                 * contain the set or sequence bytes */
                ASN1_STRING *           set;
                ASN1_STRING *           sequence;
-               ASN1_VALUE  *           asn1_value;
+               ASN1_VALUE            asn1_value;
                } value;
        } ASN1_TYPE;
 
 DECLARE_STACK_OF(ASN1_TYPE)
 DECLARE_ASN1_SET_OF(ASN1_TYPE)
 
-typedef struct asn1_method_st
-       {
-       i2d_of_void *i2d;
-       d2i_of_void *d2i;
-       void *(*create)(void);
-       void (*destroy)(void *);
-       } ASN1_METHOD;
-
-/* This is used when parsing some Netscape objects */
-typedef struct asn1_header_st
+typedef STACK_OF(ASN1_TYPE) ASN1_SEQUENCE_ANY;
+
+DECLARE_ASN1_ENCODE_FUNCTIONS_const(ASN1_SEQUENCE_ANY, ASN1_SEQUENCE_ANY)
+DECLARE_ASN1_ENCODE_FUNCTIONS_const(ASN1_SEQUENCE_ANY, ASN1_SET_ANY)
+
+typedef struct NETSCAPE_X509_st
        {
        ASN1_OCTET_STRING *header;
-       void *data;
-       ASN1_METHOD *meth;
-       } ASN1_HEADER;
+       X509 *cert;
+       } NETSCAPE_X509;
 
 /* This is used to contain a list of bit names */
 typedef struct BIT_STRING_BITNAME_st {
@@ -577,32 +581,34 @@ typedef struct BIT_STRING_BITNAME_st {
                ASN1_STRING_type_new(V_ASN1_BIT_STRING)
 #define M_ASN1_BIT_STRING_free(a)      ASN1_STRING_free((ASN1_STRING *)a)
 #define M_ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\
-               ASN1_STRING_dup((ASN1_STRING *)a)
+               ASN1_STRING_dup((const ASN1_STRING *)a)
 #define M_ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\
-               (ASN1_STRING *)a,(ASN1_STRING *)b)
+               (const ASN1_STRING *)a,(const ASN1_STRING *)b)
 #define M_ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
 
 #define M_ASN1_INTEGER_new()   (ASN1_INTEGER *)\
                ASN1_STRING_type_new(V_ASN1_INTEGER)
 #define M_ASN1_INTEGER_free(a)         ASN1_STRING_free((ASN1_STRING *)a)
-#define M_ASN1_INTEGER_dup(a) (ASN1_INTEGER *)ASN1_STRING_dup((ASN1_STRING *)a)
+#define M_ASN1_INTEGER_dup(a) (ASN1_INTEGER *)\
+               ASN1_STRING_dup((const ASN1_STRING *)a)
 #define M_ASN1_INTEGER_cmp(a,b)        ASN1_STRING_cmp(\
-               (ASN1_STRING *)a,(ASN1_STRING *)b)
+               (const ASN1_STRING *)a,(const ASN1_STRING *)b)
 
 #define M_ASN1_ENUMERATED_new()        (ASN1_ENUMERATED *)\
                ASN1_STRING_type_new(V_ASN1_ENUMERATED)
 #define M_ASN1_ENUMERATED_free(a)      ASN1_STRING_free((ASN1_STRING *)a)
-#define M_ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)ASN1_STRING_dup((ASN1_STRING *)a)
+#define M_ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)\
+               ASN1_STRING_dup((const ASN1_STRING *)a)
 #define M_ASN1_ENUMERATED_cmp(a,b)     ASN1_STRING_cmp(\
-               (ASN1_STRING *)a,(ASN1_STRING *)b)
+               (const ASN1_STRING *)a,(const ASN1_STRING *)b)
 
 #define M_ASN1_OCTET_STRING_new()      (ASN1_OCTET_STRING *)\
                ASN1_STRING_type_new(V_ASN1_OCTET_STRING)
 #define M_ASN1_OCTET_STRING_free(a)    ASN1_STRING_free((ASN1_STRING *)a)
 #define M_ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\
-               ASN1_STRING_dup((ASN1_STRING *)a)
+               ASN1_STRING_dup((const ASN1_STRING *)a)
 #define M_ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\
-               (ASN1_STRING *)a,(ASN1_STRING *)b)
+               (const ASN1_STRING *)a,(const ASN1_STRING *)b)
 #define M_ASN1_OCTET_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
 #define M_ASN1_OCTET_STRING_print(a,b) ASN1_STRING_print(a,(ASN1_STRING *)b)
 #define M_i2d_ASN1_OCTET_STRING(a,pp) \
@@ -686,7 +692,7 @@ typedef struct BIT_STRING_BITNAME_st {
                ASN1_STRING_type_new(V_ASN1_IA5STRING)
 #define M_ASN1_IA5STRING_free(a)       ASN1_STRING_free((ASN1_STRING *)a)
 #define M_ASN1_IA5STRING_dup(a)        \
-                       (ASN1_IA5STRING *)ASN1_STRING_dup((ASN1_STRING *)a)
+               (ASN1_IA5STRING *)ASN1_STRING_dup((const ASN1_STRING *)a)
 #define M_i2d_ASN1_IA5STRING(a,pp) \
                i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\
                        V_ASN1_UNIVERSAL)
@@ -697,18 +703,20 @@ typedef struct BIT_STRING_BITNAME_st {
 #define M_ASN1_UTCTIME_new()   (ASN1_UTCTIME *)\
                ASN1_STRING_type_new(V_ASN1_UTCTIME)
 #define M_ASN1_UTCTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
-#define M_ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup((ASN1_STRING *)a)
+#define M_ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)\
+               ASN1_STRING_dup((const ASN1_STRING *)a)
 
 #define M_ASN1_GENERALIZEDTIME_new()   (ASN1_GENERALIZEDTIME *)\
                ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME)
 #define M_ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
 #define M_ASN1_GENERALIZEDTIME_dup(a) (ASN1_GENERALIZEDTIME *)ASN1_STRING_dup(\
-       (ASN1_STRING *)a)
+       (const ASN1_STRING *)a)
 
 #define M_ASN1_TIME_new()      (ASN1_TIME *)\
                ASN1_STRING_type_new(V_ASN1_UTCTIME)
 #define M_ASN1_TIME_free(a)    ASN1_STRING_free((ASN1_STRING *)a)
-#define M_ASN1_TIME_dup(a) (ASN1_TIME *)ASN1_STRING_dup((ASN1_STRING *)a)
+#define M_ASN1_TIME_dup(a) (ASN1_TIME *)\
+       ASN1_STRING_dup((const ASN1_STRING *)a)
 
 #define M_ASN1_GENERALSTRING_new()     (ASN1_GENERALSTRING *)\
                ASN1_STRING_type_new(V_ASN1_GENERALSTRING)
@@ -769,6 +777,7 @@ DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
 int ASN1_TYPE_get(ASN1_TYPE *a);
 void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
 int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value);
+int            ASN1_TYPE_cmp(ASN1_TYPE *a, ASN1_TYPE *b);
 
 ASN1_OBJECT *  ASN1_OBJECT_new(void );
 void           ASN1_OBJECT_free(ASN1_OBJECT *a);
@@ -785,14 +794,15 @@ DECLARE_ASN1_SET_OF(ASN1_OBJECT)
 
 ASN1_STRING *  ASN1_STRING_new(void);
 void           ASN1_STRING_free(ASN1_STRING *a);
-ASN1_STRING *  ASN1_STRING_dup(ASN1_STRING *a);
+int            ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str);
+ASN1_STRING *  ASN1_STRING_dup(const ASN1_STRING *a);
 ASN1_STRING *  ASN1_STRING_type_new(int type );
-int            ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b);
+int            ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b);
   /* Since this is used to store all sorts of things, via macros, for now, make
      its data void * */
 int            ASN1_STRING_set(ASN1_STRING *str, const void *data, int len);
 void           ASN1_STRING_set0(ASN1_STRING *str, void *data, int len);
-int ASN1_STRING_length(ASN1_STRING *x);
+int ASN1_STRING_length(const ASN1_STRING *x);
 void ASN1_STRING_length_set(ASN1_STRING *x, int n);
 int ASN1_STRING_type(ASN1_STRING *x);
 unsigned char * ASN1_STRING_data(ASN1_STRING *x);
@@ -805,6 +815,8 @@ int         ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d,
                        int length );
 int            ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value);
 int            ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n);
+int            ASN1_BIT_STRING_check(ASN1_BIT_STRING *a,
+                                     unsigned char *flags, int flags_len);
 
 #ifndef OPENSSL_NO_BIO
 int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
@@ -823,13 +835,15 @@ ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a,const unsigned char **pp,
                        long length);
 ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a,const unsigned char **pp,
                        long length);
-ASN1_INTEGER * ASN1_INTEGER_dup(ASN1_INTEGER *x);
-int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y);
+ASN1_INTEGER * ASN1_INTEGER_dup(const ASN1_INTEGER *x);
+int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y);
 
 DECLARE_ASN1_FUNCTIONS(ASN1_ENUMERATED)
 
 int ASN1_UTCTIME_check(ASN1_UTCTIME *a);
 ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t);
+ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
+                               int offset_day, long offset_sec);
 int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str);
 int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t);
 #if 0
@@ -838,11 +852,13 @@ time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s);
 
 int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *a);
 ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,time_t t);
+ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
+            time_t t, int offset_day, long offset_sec);
 int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str);
 
 DECLARE_ASN1_FUNCTIONS(ASN1_OCTET_STRING)
-ASN1_OCTET_STRING *    ASN1_OCTET_STRING_dup(ASN1_OCTET_STRING *a);
-int    ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b);
+ASN1_OCTET_STRING *    ASN1_OCTET_STRING_dup(const ASN1_OCTET_STRING *a);
+int    ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a, const ASN1_OCTET_STRING *b);
 int    ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, const unsigned char *data, int len);
 
 DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING)
@@ -869,14 +885,20 @@ DECLARE_ASN1_FUNCTIONS(ASN1_TIME)
 DECLARE_ASN1_ITEM(ASN1_OCTET_STRING_NDEF)
 
 ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t);
+ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s,time_t t,
+                               int offset_day, long offset_sec);
 int ASN1_TIME_check(ASN1_TIME *t);
 ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out);
+int ASN1_TIME_set_string(ASN1_TIME *s, const char *str);
 
-int i2d_ASN1_SET(STACK *a, unsigned char **pp,
-                i2d_of_void *i2d, int ex_tag, int ex_class, int is_set);
-STACK *        d2i_ASN1_SET(STACK **a, const unsigned char **pp, long length,
-                    d2i_of_void *d2i, void (*free_func)(void *),
-                    int ex_tag, int ex_class);
+int i2d_ASN1_SET(STACK_OF(OPENSSL_BLOCK) *a, unsigned char **pp,
+                i2d_of_void *i2d, int ex_tag, int ex_class,
+                int is_set);
+STACK_OF(OPENSSL_BLOCK) *d2i_ASN1_SET(STACK_OF(OPENSSL_BLOCK) **a,
+                             const unsigned char **pp,
+                             long length, d2i_of_void *d2i,
+                             void (*free_func)(OPENSSL_BLOCK), int ex_tag,
+                             int ex_class);
 
 #ifndef OPENSSL_NO_BIO
 int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);
@@ -894,9 +916,9 @@ ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data,int len,
        const char *sn, const char *ln);
 
 int ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
-long ASN1_INTEGER_get(ASN1_INTEGER *a);
-ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai);
-BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn);
+long ASN1_INTEGER_get(const ASN1_INTEGER *a);
+ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai);
+BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai,BIGNUM *bn);
 
 int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v);
 long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a);
@@ -930,17 +952,17 @@ int ASN1_put_eoc(unsigned char **pp);
 int ASN1_object_size(int constructed, int length, int tag);
 
 /* Used to implement other functions */
-void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, char *x);
+void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x);
 
 #define ASN1_dup_of(type,i2d,d2i,x) \
     ((type*)ASN1_dup(CHECKED_I2D_OF(type, i2d), \
                     CHECKED_D2I_OF(type, d2i), \
-                    CHECKED_PTR_OF_TO_CHAR(type, x)))
+                    CHECKED_PTR_OF(type, x)))
 
 #define ASN1_dup_of_const(type,i2d,d2i,x) \
     ((type*)ASN1_dup(CHECKED_I2D_OF(const type, i2d), \
                     CHECKED_D2I_OF(type, d2i), \
-                    CHECKED_PTR_OF_TO_CHAR(const type, x)))
+                    CHECKED_PTR_OF(const type, x)))
 
 void *ASN1_item_dup(const ASN1_ITEM *it, void *x);
 
@@ -1001,29 +1023,23 @@ int ASN1_i2d_bio(i2d_of_void *i2d,BIO *out, unsigned char *x);
                  CHECKED_PTR_OF(const type, x)))
 
 int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x);
-int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a);
-int ASN1_GENERALIZEDTIME_print(BIO *fp,ASN1_GENERALIZEDTIME *a);
-int ASN1_TIME_print(BIO *fp,ASN1_TIME *a);
-int ASN1_STRING_print(BIO *bp,ASN1_STRING *v);
+int ASN1_UTCTIME_print(BIO *fp, const ASN1_UTCTIME *a);
+int ASN1_GENERALIZEDTIME_print(BIO *fp, const ASN1_GENERALIZEDTIME *a);
+int ASN1_TIME_print(BIO *fp, const ASN1_TIME *a);
+int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v);
 int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags);
+int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num,
+                               unsigned char *buf, int off);
 int ASN1_parse(BIO *bp,const unsigned char *pp,long len,int indent);
 int ASN1_parse_dump(BIO *bp,const unsigned char *pp,long len,int indent,int dump);
 #endif
 const char *ASN1_tag2str(int tag);
 
-/* Used to load and write netscape format cert/key */
-int i2d_ASN1_HEADER(ASN1_HEADER *a,unsigned char **pp);
-ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a,const unsigned char **pp, long length);
-ASN1_HEADER *ASN1_HEADER_new(void );
-void ASN1_HEADER_free(ASN1_HEADER *a);
+/* Used to load and write netscape format cert */
 
-int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s);
+DECLARE_ASN1_FUNCTIONS(NETSCAPE_X509)
 
-/* Not used that much at this point, except for the first two */
-ASN1_METHOD *X509_asn1_meth(void);
-ASN1_METHOD *RSAPrivateKey_asn1_meth(void);
-ASN1_METHOD *ASN1_IA5STRING_asn1_meth(void);
-ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(void);
+int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s);
 
 int ASN1_TYPE_set_octetstring(ASN1_TYPE *a,
        unsigned char *data, int len);
@@ -1034,9 +1050,9 @@ int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num,
 int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num,
        unsigned char *data, int max_len);
 
-STACK *ASN1_seq_unpack(const unsigned char *buf, int len,
-                      d2i_of_void *d2i, void (*free_func)(void *));
-unsigned char *ASN1_seq_pack(STACK *safes, i2d_of_void *i2d,
+STACK_OF(OPENSSL_BLOCK) *ASN1_seq_unpack(const unsigned char *buf, int len,
+                                d2i_of_void *d2i, void (*free_func)(OPENSSL_BLOCK));
+unsigned char *ASN1_seq_pack(STACK_OF(OPENSSL_BLOCK) *safes, i2d_of_void *i2d,
                             unsigned char **buf, int *len );
 void *ASN1_unpack_string(ASN1_STRING *oct, d2i_of_void *d2i);
 void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it);
@@ -1079,15 +1095,58 @@ void ASN1_add_oid_module(void);
 ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf);
 ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf);
 
-typedef int asn1_output_data_fn(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
-                                       const ASN1_ITEM *it);
-
-int int_smime_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
+/* ASN1 Print flags */
+
+/* Indicate missing OPTIONAL fields */
+#define ASN1_PCTX_FLAGS_SHOW_ABSENT            0x001   
+/* Mark start and end of SEQUENCE */
+#define ASN1_PCTX_FLAGS_SHOW_SEQUENCE          0x002
+/* Mark start and end of SEQUENCE/SET OF */
+#define ASN1_PCTX_FLAGS_SHOW_SSOF              0x004
+/* Show the ASN1 type of primitives */
+#define ASN1_PCTX_FLAGS_SHOW_TYPE              0x008
+/* Don't show ASN1 type of ANY */
+#define ASN1_PCTX_FLAGS_NO_ANY_TYPE            0x010
+/* Don't show ASN1 type of MSTRINGs */
+#define ASN1_PCTX_FLAGS_NO_MSTRING_TYPE                0x020
+/* Don't show field names in SEQUENCE */
+#define ASN1_PCTX_FLAGS_NO_FIELD_NAME          0x040
+/* Show structure names of each SEQUENCE field */
+#define ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME 0x080
+/* Don't show structure name even at top level */
+#define ASN1_PCTX_FLAGS_NO_STRUCT_NAME         0x100
+
+int ASN1_item_print(BIO *out, ASN1_VALUE *ifld, int indent,
+                               const ASN1_ITEM *it, const ASN1_PCTX *pctx);
+ASN1_PCTX *ASN1_PCTX_new(void);
+void ASN1_PCTX_free(ASN1_PCTX *p);
+unsigned long ASN1_PCTX_get_flags(ASN1_PCTX *p);
+void ASN1_PCTX_set_flags(ASN1_PCTX *p, unsigned long flags);
+unsigned long ASN1_PCTX_get_nm_flags(ASN1_PCTX *p);
+void ASN1_PCTX_set_nm_flags(ASN1_PCTX *p, unsigned long flags);
+unsigned long ASN1_PCTX_get_cert_flags(ASN1_PCTX *p);
+void ASN1_PCTX_set_cert_flags(ASN1_PCTX *p, unsigned long flags);
+unsigned long ASN1_PCTX_get_oid_flags(ASN1_PCTX *p);
+void ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags);
+unsigned long ASN1_PCTX_get_str_flags(ASN1_PCTX *p);
+void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags);
+
+BIO_METHOD *BIO_f_asn1(void);
+
+BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it);
+
+int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
+                               const ASN1_ITEM *it);
+int PEM_write_bio_ASN1_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
+                               const char *hdr,
+                               const ASN1_ITEM *it);
+int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
                                int ctype_nid, int econt_nid,
                                STACK_OF(X509_ALGOR) *mdalgs,
-                               asn1_output_data_fn *data_fn,
                                const ASN1_ITEM *it);
 ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it);
+int SMIME_crlf_copy(BIO *in, BIO *out, int flags);
+int SMIME_text(BIO *in, BIO *out);
 
 /* BEGIN ERROR CODES */
 /* The following lines are auto generated by the script mkerr.pl. Any changes
@@ -1118,6 +1177,7 @@ void ERR_load_ASN1_strings(void);
 #define ASN1_F_ASN1_ENUMERATED_TO_BN                    113
 #define ASN1_F_ASN1_EX_C2I                              204
 #define ASN1_F_ASN1_FIND_END                            190
+#define ASN1_F_ASN1_GENERALIZEDTIME_ADJ                         216
 #define ASN1_F_ASN1_GENERALIZEDTIME_SET                         185
 #define ASN1_F_ASN1_GENERATE_V3                                 178
 #define ASN1_F_ASN1_GET_OBJECT                          114
@@ -1138,7 +1198,7 @@ void ERR_load_ASN1_strings(void);
 #define ASN1_F_ASN1_ITEM_VERIFY                                 197
 #define ASN1_F_ASN1_MBSTRING_NCOPY                      122
 #define ASN1_F_ASN1_OBJECT_NEW                          123
-#define ASN1_F_ASN1_OUTPUT_DATA                                 207
+#define ASN1_F_ASN1_OUTPUT_DATA                                 214
 #define ASN1_F_ASN1_PACK_STRING                                 124
 #define ASN1_F_ASN1_PCTX_NEW                            205
 #define ASN1_F_ASN1_PKCS5_PBE_SET                       125
@@ -1152,14 +1212,17 @@ void ERR_load_ASN1_strings(void);
 #define ASN1_F_ASN1_TEMPLATE_EX_D2I                     132
 #define ASN1_F_ASN1_TEMPLATE_NEW                        133
 #define ASN1_F_ASN1_TEMPLATE_NOEXP_D2I                  131
+#define ASN1_F_ASN1_TIME_ADJ                            217
 #define ASN1_F_ASN1_TIME_SET                            175
 #define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING            134
 #define ASN1_F_ASN1_TYPE_GET_OCTETSTRING                135
 #define ASN1_F_ASN1_UNPACK_STRING                       136
+#define ASN1_F_ASN1_UTCTIME_ADJ                                 218
 #define ASN1_F_ASN1_UTCTIME_SET                                 187
 #define ASN1_F_ASN1_VERIFY                              137
-#define ASN1_F_B64_READ_ASN1                            208
-#define ASN1_F_B64_WRITE_ASN1                           209
+#define ASN1_F_B64_READ_ASN1                            209
+#define ASN1_F_B64_WRITE_ASN1                           210
+#define ASN1_F_BIO_NEW_NDEF                             208
 #define ASN1_F_BITSTR_CB                                180
 #define ASN1_F_BN_TO_ASN1_ENUMERATED                    138
 #define ASN1_F_BN_TO_ASN1_INTEGER                       139
@@ -1178,6 +1241,7 @@ void ERR_load_ASN1_strings(void);
 #define ASN1_F_D2I_ASN1_TYPE_BYTES                      149
 #define ASN1_F_D2I_ASN1_UINTEGER                        150
 #define ASN1_F_D2I_ASN1_UTCTIME                                 151
+#define ASN1_F_D2I_AUTOPRIVATEKEY                       207
 #define ASN1_F_D2I_NETSCAPE_RSA                                 152
 #define ASN1_F_D2I_NETSCAPE_RSA_2                       153
 #define ASN1_F_D2I_PRIVATEKEY                           154
@@ -1187,6 +1251,7 @@ void ERR_load_ASN1_strings(void);
 #define ASN1_F_D2I_X509                                         156
 #define ASN1_F_D2I_X509_CINF                            157
 #define ASN1_F_D2I_X509_PKEY                            159
+#define ASN1_F_I2D_ASN1_BIO_STREAM                      211
 #define ASN1_F_I2D_ASN1_SET                             188
 #define ASN1_F_I2D_ASN1_TIME                            160
 #define ASN1_F_I2D_DSA_PUBKEY                           161
@@ -1198,10 +1263,11 @@ void ERR_load_ASN1_strings(void);
 #define ASN1_F_LONG_C2I                                         166
 #define ASN1_F_OID_MODULE_INIT                          174
 #define ASN1_F_PARSE_TAGGING                            182
-#define ASN1_F_PKCS5_PBE2_SET                           167
+#define ASN1_F_PKCS5_PBE2_SET_IV                        167
 #define ASN1_F_PKCS5_PBE_SET                            202
-#define ASN1_F_SMIME_READ_ASN1                          210
-#define ASN1_F_SMIME_TEXT                               211
+#define ASN1_F_PKCS5_PBE_SET0_ALGOR                     215
+#define ASN1_F_SMIME_READ_ASN1                          212
+#define ASN1_F_SMIME_TEXT                               213
 #define ASN1_F_X509_CINF_NEW                            168
 #define ASN1_F_X509_CRL_ADD0_REVOKED                    169
 #define ASN1_F_X509_INFO_NEW                            170
@@ -1213,14 +1279,14 @@ void ERR_load_ASN1_strings(void);
 
 /* Reason codes. */
 #define ASN1_R_ADDING_OBJECT                            171
-#define ASN1_R_ASN1_PARSE_ERROR                                 198
-#define ASN1_R_ASN1_SIG_PARSE_ERROR                     199
+#define ASN1_R_ASN1_PARSE_ERROR                                 203
+#define ASN1_R_ASN1_SIG_PARSE_ERROR                     204
 #define ASN1_R_AUX_ERROR                                100
 #define ASN1_R_BAD_CLASS                                101
 #define ASN1_R_BAD_OBJECT_HEADER                        102
 #define ASN1_R_BAD_PASSWORD_READ                        103
 #define ASN1_R_BAD_TAG                                  104
-#define ASN1_R_BMPSTRING_IS_WRONG_LENGTH                210
+#define ASN1_R_BMPSTRING_IS_WRONG_LENGTH                214
 #define ASN1_R_BN_LIB                                   105
 #define ASN1_R_BOOLEAN_IS_WRONG_LENGTH                  106
 #define ASN1_R_BUFFER_TOO_SMALL                                 107
@@ -1229,6 +1295,7 @@ void ERR_load_ASN1_strings(void);
 #define ASN1_R_DECODE_ERROR                             110
 #define ASN1_R_DECODING_ERROR                           111
 #define ASN1_R_DEPTH_EXCEEDED                           174
+#define ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED        198
 #define ASN1_R_ENCODE_ERROR                             112
 #define ASN1_R_ERROR_GETTING_TIME                       173
 #define ASN1_R_ERROR_LOADING_SECTION                    172
@@ -1262,10 +1329,10 @@ void ERR_load_ASN1_strings(void);
 #define ASN1_R_INTEGER_TOO_LARGE_FOR_LONG               128
 #define ASN1_R_INVALID_BMPSTRING_LENGTH                         129
 #define ASN1_R_INVALID_DIGIT                            130
-#define ASN1_R_INVALID_MIME_TYPE                        200
+#define ASN1_R_INVALID_MIME_TYPE                        205
 #define ASN1_R_INVALID_MODIFIER                                 186
 #define ASN1_R_INVALID_NUMBER                           187
-#define ASN1_R_INVALID_OBJECT_ENCODING                  212
+#define ASN1_R_INVALID_OBJECT_ENCODING                  216
 #define ASN1_R_INVALID_SEPARATOR                        131
 #define ASN1_R_INVALID_TIME_FORMAT                      132
 #define ASN1_R_INVALID_UNIVERSALSTRING_LENGTH           133
@@ -1273,9 +1340,9 @@ void ERR_load_ASN1_strings(void);
 #define ASN1_R_IV_TOO_LARGE                             135
 #define ASN1_R_LENGTH_ERROR                             136
 #define ASN1_R_LIST_ERROR                               188
-#define ASN1_R_MIME_NO_CONTENT_TYPE                     201
-#define ASN1_R_MIME_PARSE_ERROR                                 202
-#define ASN1_R_MIME_SIG_PARSE_ERROR                     203
+#define ASN1_R_MIME_NO_CONTENT_TYPE                     206
+#define ASN1_R_MIME_PARSE_ERROR                                 207
+#define ASN1_R_MIME_SIG_PARSE_ERROR                     208
 #define ASN1_R_MISSING_EOC                              137
 #define ASN1_R_MISSING_SECOND_NUMBER                    138
 #define ASN1_R_MISSING_VALUE                            189
@@ -1285,11 +1352,12 @@ void ERR_load_ASN1_strings(void);
 #define ASN1_R_NON_HEX_CHARACTERS                       141
 #define ASN1_R_NOT_ASCII_FORMAT                                 190
 #define ASN1_R_NOT_ENOUGH_DATA                          142
-#define ASN1_R_NO_CONTENT_TYPE                          204
+#define ASN1_R_NO_CONTENT_TYPE                          209
+#define ASN1_R_NO_DEFAULT_DIGEST                        201
 #define ASN1_R_NO_MATCHING_CHOICE_TYPE                  143
-#define ASN1_R_NO_MULTIPART_BODY_FAILURE                205
-#define ASN1_R_NO_MULTIPART_BOUNDARY                    206
-#define ASN1_R_NO_SIG_CONTENT_TYPE                      207
+#define ASN1_R_NO_MULTIPART_BODY_FAILURE                210
+#define ASN1_R_NO_MULTIPART_BOUNDARY                    211
+#define ASN1_R_NO_SIG_CONTENT_TYPE                      212
 #define ASN1_R_NULL_IS_WRONG_LENGTH                     144
 #define ASN1_R_OBJECT_NOT_ASCII_FORMAT                  191
 #define ASN1_R_ODD_NUMBER_OF_CHARS                      145
@@ -1299,8 +1367,8 @@ void ERR_load_ASN1_strings(void);
 #define ASN1_R_SEQUENCE_NOT_CONSTRUCTED                         149
 #define ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG             192
 #define ASN1_R_SHORT_LINE                               150
-#define ASN1_R_SIG_INVALID_MIME_TYPE                    208
-#define ASN1_R_STREAMING_NOT_SUPPORTED                  209
+#define ASN1_R_SIG_INVALID_MIME_TYPE                    213
+#define ASN1_R_STREAMING_NOT_SUPPORTED                  202
 #define ASN1_R_STRING_TOO_LONG                          151
 #define ASN1_R_STRING_TOO_SHORT                                 152
 #define ASN1_R_TAG_VALUE_TOO_HIGH                       153
@@ -1311,11 +1379,12 @@ void ERR_load_ASN1_strings(void);
 #define ASN1_R_UNABLE_TO_DECODE_RSA_KEY                         157
 #define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY                 158
 #define ASN1_R_UNEXPECTED_EOC                           159
-#define ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH          211
+#define ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH          215
 #define ASN1_R_UNKNOWN_FORMAT                           160
 #define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM                 161
 #define ASN1_R_UNKNOWN_OBJECT_TYPE                      162
 #define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE                  163
+#define ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM              199
 #define ASN1_R_UNKNOWN_TAG                              194
 #define ASN1_R_UNKOWN_FORMAT                            195
 #define ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE          164
@@ -1323,6 +1392,7 @@ void ERR_load_ASN1_strings(void);
 #define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM                 166
 #define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE              167
 #define ASN1_R_UNSUPPORTED_TYPE                                 196
+#define ASN1_R_WRONG_PUBLIC_KEY_TYPE                    200
 #define ASN1_R_WRONG_TAG                                168
 #define ASN1_R_WRONG_TYPE                               169
 
index ba88eb3..6e04d08 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/asn1/asn1_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2008 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2009 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -90,10 +90,11 @@ static ERR_STRING_DATA ASN1_str_functs[]=
 {ERR_FUNC(ASN1_F_ASN1_ENUMERATED_TO_BN),       "ASN1_ENUMERATED_to_BN"},
 {ERR_FUNC(ASN1_F_ASN1_EX_C2I), "ASN1_EX_C2I"},
 {ERR_FUNC(ASN1_F_ASN1_FIND_END),       "ASN1_FIND_END"},
+{ERR_FUNC(ASN1_F_ASN1_GENERALIZEDTIME_ADJ),    "ASN1_GENERALIZEDTIME_adj"},
 {ERR_FUNC(ASN1_F_ASN1_GENERALIZEDTIME_SET),    "ASN1_GENERALIZEDTIME_set"},
 {ERR_FUNC(ASN1_F_ASN1_GENERATE_V3),    "ASN1_generate_v3"},
 {ERR_FUNC(ASN1_F_ASN1_GET_OBJECT),     "ASN1_get_object"},
-{ERR_FUNC(ASN1_F_ASN1_HEADER_NEW),     "ASN1_HEADER_new"},
+{ERR_FUNC(ASN1_F_ASN1_HEADER_NEW),     "ASN1_HEADER_NEW"},
 {ERR_FUNC(ASN1_F_ASN1_I2D_BIO),        "ASN1_i2d_bio"},
 {ERR_FUNC(ASN1_F_ASN1_I2D_FP), "ASN1_i2d_fp"},
 {ERR_FUNC(ASN1_F_ASN1_INTEGER_SET),    "ASN1_INTEGER_set"},
@@ -112,7 +113,7 @@ static ERR_STRING_DATA ASN1_str_functs[]=
 {ERR_FUNC(ASN1_F_ASN1_OBJECT_NEW),     "ASN1_OBJECT_new"},
 {ERR_FUNC(ASN1_F_ASN1_OUTPUT_DATA),    "ASN1_OUTPUT_DATA"},
 {ERR_FUNC(ASN1_F_ASN1_PACK_STRING),    "ASN1_pack_string"},
-{ERR_FUNC(ASN1_F_ASN1_PCTX_NEW),       "ASN1_PCTX_NEW"},
+{ERR_FUNC(ASN1_F_ASN1_PCTX_NEW),       "ASN1_PCTX_new"},
 {ERR_FUNC(ASN1_F_ASN1_PKCS5_PBE_SET),  "ASN1_PKCS5_PBE_SET"},
 {ERR_FUNC(ASN1_F_ASN1_SEQ_PACK),       "ASN1_seq_pack"},
 {ERR_FUNC(ASN1_F_ASN1_SEQ_UNPACK),     "ASN1_seq_unpack"},
@@ -124,14 +125,17 @@ static ERR_STRING_DATA ASN1_str_functs[]=
 {ERR_FUNC(ASN1_F_ASN1_TEMPLATE_EX_D2I),        "ASN1_TEMPLATE_EX_D2I"},
 {ERR_FUNC(ASN1_F_ASN1_TEMPLATE_NEW),   "ASN1_TEMPLATE_NEW"},
 {ERR_FUNC(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I),     "ASN1_TEMPLATE_NOEXP_D2I"},
+{ERR_FUNC(ASN1_F_ASN1_TIME_ADJ),       "ASN1_TIME_adj"},
 {ERR_FUNC(ASN1_F_ASN1_TIME_SET),       "ASN1_TIME_set"},
 {ERR_FUNC(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING),       "ASN1_TYPE_get_int_octetstring"},
 {ERR_FUNC(ASN1_F_ASN1_TYPE_GET_OCTETSTRING),   "ASN1_TYPE_get_octetstring"},
 {ERR_FUNC(ASN1_F_ASN1_UNPACK_STRING),  "ASN1_unpack_string"},
+{ERR_FUNC(ASN1_F_ASN1_UTCTIME_ADJ),    "ASN1_UTCTIME_adj"},
 {ERR_FUNC(ASN1_F_ASN1_UTCTIME_SET),    "ASN1_UTCTIME_set"},
 {ERR_FUNC(ASN1_F_ASN1_VERIFY), "ASN1_verify"},
 {ERR_FUNC(ASN1_F_B64_READ_ASN1),       "B64_READ_ASN1"},
 {ERR_FUNC(ASN1_F_B64_WRITE_ASN1),      "B64_WRITE_ASN1"},
+{ERR_FUNC(ASN1_F_BIO_NEW_NDEF),        "BIO_new_NDEF"},
 {ERR_FUNC(ASN1_F_BITSTR_CB),   "BITSTR_CB"},
 {ERR_FUNC(ASN1_F_BN_TO_ASN1_ENUMERATED),       "BN_to_ASN1_ENUMERATED"},
 {ERR_FUNC(ASN1_F_BN_TO_ASN1_INTEGER),  "BN_to_ASN1_INTEGER"},
@@ -143,13 +147,14 @@ static ERR_STRING_DATA ASN1_str_functs[]=
 {ERR_FUNC(ASN1_F_D2I_ASN1_BOOLEAN),    "d2i_ASN1_BOOLEAN"},
 {ERR_FUNC(ASN1_F_D2I_ASN1_BYTES),      "d2i_ASN1_bytes"},
 {ERR_FUNC(ASN1_F_D2I_ASN1_GENERALIZEDTIME),    "D2I_ASN1_GENERALIZEDTIME"},
-{ERR_FUNC(ASN1_F_D2I_ASN1_HEADER),     "d2i_ASN1_HEADER"},
+{ERR_FUNC(ASN1_F_D2I_ASN1_HEADER),     "D2I_ASN1_HEADER"},
 {ERR_FUNC(ASN1_F_D2I_ASN1_INTEGER),    "D2I_ASN1_INTEGER"},
 {ERR_FUNC(ASN1_F_D2I_ASN1_OBJECT),     "d2i_ASN1_OBJECT"},
 {ERR_FUNC(ASN1_F_D2I_ASN1_SET),        "d2i_ASN1_SET"},
 {ERR_FUNC(ASN1_F_D2I_ASN1_TYPE_BYTES), "d2i_ASN1_type_bytes"},
 {ERR_FUNC(ASN1_F_D2I_ASN1_UINTEGER),   "d2i_ASN1_UINTEGER"},
 {ERR_FUNC(ASN1_F_D2I_ASN1_UTCTIME),    "D2I_ASN1_UTCTIME"},
+{ERR_FUNC(ASN1_F_D2I_AUTOPRIVATEKEY),  "d2i_AutoPrivateKey"},
 {ERR_FUNC(ASN1_F_D2I_NETSCAPE_RSA),    "d2i_Netscape_RSA"},
 {ERR_FUNC(ASN1_F_D2I_NETSCAPE_RSA_2),  "D2I_NETSCAPE_RSA_2"},
 {ERR_FUNC(ASN1_F_D2I_PRIVATEKEY),      "d2i_PrivateKey"},
@@ -159,6 +164,7 @@ static ERR_STRING_DATA ASN1_str_functs[]=
 {ERR_FUNC(ASN1_F_D2I_X509),    "D2I_X509"},
 {ERR_FUNC(ASN1_F_D2I_X509_CINF),       "D2I_X509_CINF"},
 {ERR_FUNC(ASN1_F_D2I_X509_PKEY),       "d2i_X509_PKEY"},
+{ERR_FUNC(ASN1_F_I2D_ASN1_BIO_STREAM), "i2d_ASN1_bio_stream"},
 {ERR_FUNC(ASN1_F_I2D_ASN1_SET),        "i2d_ASN1_SET"},
 {ERR_FUNC(ASN1_F_I2D_ASN1_TIME),       "I2D_ASN1_TIME"},
 {ERR_FUNC(ASN1_F_I2D_DSA_PUBKEY),      "i2d_DSA_PUBKEY"},
@@ -170,8 +176,9 @@ static ERR_STRING_DATA ASN1_str_functs[]=
 {ERR_FUNC(ASN1_F_LONG_C2I),    "LONG_C2I"},
 {ERR_FUNC(ASN1_F_OID_MODULE_INIT),     "OID_MODULE_INIT"},
 {ERR_FUNC(ASN1_F_PARSE_TAGGING),       "PARSE_TAGGING"},
-{ERR_FUNC(ASN1_F_PKCS5_PBE2_SET),      "PKCS5_pbe2_set"},
+{ERR_FUNC(ASN1_F_PKCS5_PBE2_SET_IV),   "PKCS5_pbe2_set_iv"},
 {ERR_FUNC(ASN1_F_PKCS5_PBE_SET),       "PKCS5_pbe_set"},
+{ERR_FUNC(ASN1_F_PKCS5_PBE_SET0_ALGOR),        "PKCS5_pbe_set0_algor"},
 {ERR_FUNC(ASN1_F_SMIME_READ_ASN1),     "SMIME_read_ASN1"},
 {ERR_FUNC(ASN1_F_SMIME_TEXT),  "SMIME_text"},
 {ERR_FUNC(ASN1_F_X509_CINF_NEW),       "X509_CINF_NEW"},
@@ -204,6 +211,7 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
 {ERR_REASON(ASN1_R_DECODE_ERROR)         ,"decode error"},
 {ERR_REASON(ASN1_R_DECODING_ERROR)       ,"decoding error"},
 {ERR_REASON(ASN1_R_DEPTH_EXCEEDED)       ,"depth exceeded"},
+{ERR_REASON(ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED),"digest and key type not supported"},
 {ERR_REASON(ASN1_R_ENCODE_ERROR)         ,"encode error"},
 {ERR_REASON(ASN1_R_ERROR_GETTING_TIME)   ,"error getting time"},
 {ERR_REASON(ASN1_R_ERROR_LOADING_SECTION),"error loading section"},
@@ -261,6 +269,7 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
 {ERR_REASON(ASN1_R_NOT_ASCII_FORMAT)     ,"not ascii format"},
 {ERR_REASON(ASN1_R_NOT_ENOUGH_DATA)      ,"not enough data"},
 {ERR_REASON(ASN1_R_NO_CONTENT_TYPE)      ,"no content type"},
+{ERR_REASON(ASN1_R_NO_DEFAULT_DIGEST)    ,"no default digest"},
 {ERR_REASON(ASN1_R_NO_MATCHING_CHOICE_TYPE),"no matching choice type"},
 {ERR_REASON(ASN1_R_NO_MULTIPART_BODY_FAILURE),"no multipart body failure"},
 {ERR_REASON(ASN1_R_NO_MULTIPART_BOUNDARY),"no multipart boundary"},
@@ -291,6 +300,7 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
 {ERR_REASON(ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM),"unknown message digest algorithm"},
 {ERR_REASON(ASN1_R_UNKNOWN_OBJECT_TYPE)  ,"unknown object type"},
 {ERR_REASON(ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE),"unknown public key type"},
+{ERR_REASON(ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM),"unknown signature algorithm"},
 {ERR_REASON(ASN1_R_UNKNOWN_TAG)          ,"unknown tag"},
 {ERR_REASON(ASN1_R_UNKOWN_FORMAT)        ,"unkown format"},
 {ERR_REASON(ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE),"unsupported any defined by type"},
@@ -298,6 +308,7 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
 {ERR_REASON(ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM),"unsupported encryption algorithm"},
 {ERR_REASON(ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE),"unsupported public key type"},
 {ERR_REASON(ASN1_R_UNSUPPORTED_TYPE)     ,"unsupported type"},
+{ERR_REASON(ASN1_R_WRONG_PUBLIC_KEY_TYPE),"wrong public key type"},
 {ERR_REASON(ASN1_R_WRONG_TAG)            ,"wrong tag"},
 {ERR_REASON(ASN1_R_WRONG_TYPE)           ,"wrong type"},
 {0,NULL}
index 213a8e9..4fc2419 100644 (file)
@@ -247,8 +247,14 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf)
        /* If IMPLICIT, output tag */
 
        if (asn1_tags.imp_tag != -1)
+               {
+               if (asn1_tags.imp_class == V_ASN1_UNIVERSAL 
+                   && (asn1_tags.imp_tag == V_ASN1_SEQUENCE
+                    || asn1_tags.imp_tag == V_ASN1_SET) )
+                       hdr_constructed = V_ASN1_CONSTRUCTED;
                ASN1_put_object(&p, hdr_constructed, hdr_len,
                                        asn1_tags.imp_tag, asn1_tags.imp_class);
+               }
 
        /* Copy across original encoding */
        memcpy(p, cpy_start, cpy_len);
@@ -441,12 +447,12 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass)
 
 static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf)
        {
-       ASN1_TYPE *ret = NULL, *typ = NULL;
+       ASN1_TYPE *ret = NULL;
        STACK_OF(ASN1_TYPE) *sk = NULL;
        STACK_OF(CONF_VALUE) *sect = NULL;
-       unsigned char *der = NULL, *p;
+       unsigned char *der = NULL;
        int derlen;
-       int i, is_set;
+       int i;
        sk = sk_ASN1_TYPE_new_null();
        if (!sk)
                goto bad;
@@ -459,31 +465,23 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf)
                        goto bad;
                for (i = 0; i < sk_CONF_VALUE_num(sect); i++)
                        {
-                       typ = ASN1_generate_v3(sk_CONF_VALUE_value(sect, i)->value, cnf);
+                       ASN1_TYPE *typ = ASN1_generate_v3(sk_CONF_VALUE_value(sect, i)->value, cnf);
                        if (!typ)
                                goto bad;
                        if (!sk_ASN1_TYPE_push(sk, typ))
                                goto bad;
-                       typ = NULL;
                        }
                }
 
        /* Now we has a STACK of the components, convert to the correct form */
 
        if (utype == V_ASN1_SET)
-               is_set = 1;
+               derlen = i2d_ASN1_SET_ANY(sk, &der);
        else
-               is_set = 0;
-
+               derlen = i2d_ASN1_SEQUENCE_ANY(sk, &der);
 
-       derlen = i2d_ASN1_SET_OF_ASN1_TYPE(sk, NULL, i2d_ASN1_TYPE, utype,
-                                          V_ASN1_UNIVERSAL, is_set);
-       der = OPENSSL_malloc(derlen);
-       if (!der)
+       if (derlen < 0)
                goto bad;
-       p = der;
-       i2d_ASN1_SET_OF_ASN1_TYPE(sk, &p, i2d_ASN1_TYPE, utype,
-                                 V_ASN1_UNIVERSAL, is_set);
 
        if (!(ret = ASN1_TYPE_new()))
                goto bad;
@@ -505,8 +503,6 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf)
 
        if (sk)
                sk_ASN1_TYPE_pop_free(sk, ASN1_TYPE_free);
-       if (typ)
-               ASN1_TYPE_free(typ);
        if (sect)
                X509V3_section_free(cnf, sect);
 
@@ -556,7 +552,7 @@ static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_cons
 static int asn1_str2tag(const char *tagstr, int len)
        {
        unsigned int i;
-       static struct tag_name_st *tntmp, tnst [] = {
+       static const struct tag_name_st *tntmp, tnst [] = {
                ASN1_GEN_STR("BOOL", V_ASN1_BOOLEAN),
                ASN1_GEN_STR("BOOLEAN", V_ASN1_BOOLEAN),
                ASN1_GEN_STR("NULL", V_ASN1_NULL),
@@ -591,6 +587,8 @@ static int asn1_str2tag(const char *tagstr, int len)
                ASN1_GEN_STR("TELETEXSTRING", V_ASN1_T61STRING),
                ASN1_GEN_STR("GeneralString", V_ASN1_GENERALSTRING),
                ASN1_GEN_STR("GENSTR", V_ASN1_GENERALSTRING),
+               ASN1_GEN_STR("NUMERIC", V_ASN1_NUMERICSTRING),
+               ASN1_GEN_STR("NUMERICSTRING", V_ASN1_NUMERICSTRING),
 
                /* Special cases */
                ASN1_GEN_STR("SEQUENCE", V_ASN1_SEQUENCE),
@@ -736,6 +734,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
                case V_ASN1_VISIBLESTRING:
                case V_ASN1_UNIVERSALSTRING:
                case V_ASN1_GENERALSTRING:
+               case V_ASN1_NUMERICSTRING:
 
                if (format == ASN1_GEN_FORMAT_ASCII)
                        format = MBSTRING_ASC;
index 5af559e..1bcb44a 100644 (file)
@@ -340,20 +340,31 @@ int asn1_GetSequence(ASN1_const_CTX *c, long *length)
        return(1);
        }
 
-ASN1_STRING *ASN1_STRING_dup(ASN1_STRING *str)
+int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str)
        {
-       ASN1_STRING *ret;
+       if (str == NULL)
+               return 0;
+       dst->type = str->type;
+       if (!ASN1_STRING_set(dst,str->data,str->length))
+               return 0;
+       dst->flags = str->flags;
+       return 1;
+       }
 
-       if (str == NULL) return(NULL);
-       if ((ret=ASN1_STRING_type_new(str->type)) == NULL)
-               return(NULL);
-       if (!ASN1_STRING_set(ret,str->data,str->length))
+ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *str)
+       {
+       ASN1_STRING *ret;
+       if (!str)
+                return NULL;
+       ret=ASN1_STRING_new();
+       if (!ret)
+               return NULL;
+       if (!ASN1_STRING_copy(ret,str))
                {
                ASN1_STRING_free(ret);
-               return(NULL);
+               return NULL;
                }
-       ret->flags = str->flags;
-       return(ret);
+       return ret;
        }
 
 int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
@@ -427,11 +438,12 @@ ASN1_STRING *ASN1_STRING_type_new(int type)
 void ASN1_STRING_free(ASN1_STRING *a)
        {
        if (a == NULL) return;
-       if (a->data != NULL) OPENSSL_free(a->data);
+       if (a->data && !(a->flags & ASN1_STRING_FLAG_NDEF))
+               OPENSSL_free(a->data);
        OPENSSL_free(a);
        }
 
-int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b)
+int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b)
        {
        int i;
 
@@ -457,7 +469,7 @@ void asn1_add_error(const unsigned char *address, int offset)
        ERR_add_error_data(4,"address=",buf1," offset=",buf2);
        }
 
-int ASN1_STRING_length(ASN1_STRING *x)
+int ASN1_STRING_length(const ASN1_STRING *x)
 { return M_ASN1_STRING_length(x); }
 
 void ASN1_STRING_length_set(ASN1_STRING *x, int len)
diff --git a/deps/openssl/openssl/crypto/asn1/asn1_locl.h b/deps/openssl/openssl/crypto/asn1/asn1_locl.h
new file mode 100644 (file)
index 0000000..5aa65e2
--- /dev/null
@@ -0,0 +1,134 @@
+/* asn1t.h */
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project 2006.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+/* Internal ASN1 structures and functions: not for application use */
+
+/* ASN1 print context structure */
+
+struct asn1_pctx_st
+       {
+       unsigned long flags;
+       unsigned long nm_flags;
+       unsigned long cert_flags;
+       unsigned long oid_flags;
+       unsigned long str_flags;
+       } /* ASN1_PCTX */;
+
+/* ASN1 public key method structure */
+
+struct evp_pkey_asn1_method_st
+       {
+       int pkey_id;
+       int pkey_base_id;
+       unsigned long pkey_flags;
+
+       char *pem_str;
+       char *info;
+
+       int (*pub_decode)(EVP_PKEY *pk, X509_PUBKEY *pub);
+       int (*pub_encode)(X509_PUBKEY *pub, const EVP_PKEY *pk);
+       int (*pub_cmp)(const EVP_PKEY *a, const EVP_PKEY *b);
+       int (*pub_print)(BIO *out, const EVP_PKEY *pkey, int indent,
+                                                       ASN1_PCTX *pctx);
+
+       int (*priv_decode)(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf);
+       int (*priv_encode)(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk);
+       int (*priv_print)(BIO *out, const EVP_PKEY *pkey, int indent,
+                                                       ASN1_PCTX *pctx);
+
+       int (*pkey_size)(const EVP_PKEY *pk);
+       int (*pkey_bits)(const EVP_PKEY *pk);
+
+       int (*param_decode)(EVP_PKEY *pkey,
+                               const unsigned char **pder, int derlen);
+       int (*param_encode)(const EVP_PKEY *pkey, unsigned char **pder);
+       int (*param_missing)(const EVP_PKEY *pk);
+       int (*param_copy)(EVP_PKEY *to, const EVP_PKEY *from);
+       int (*param_cmp)(const EVP_PKEY *a, const EVP_PKEY *b);
+       int (*param_print)(BIO *out, const EVP_PKEY *pkey, int indent,
+                                                       ASN1_PCTX *pctx);
+
+       void (*pkey_free)(EVP_PKEY *pkey);
+       int (*pkey_ctrl)(EVP_PKEY *pkey, int op, long arg1, void *arg2);
+
+       /* Legacy functions for old PEM */
+
+       int (*old_priv_decode)(EVP_PKEY *pkey,
+                               const unsigned char **pder, int derlen);
+       int (*old_priv_encode)(const EVP_PKEY *pkey, unsigned char **pder);
+
+       } /* EVP_PKEY_ASN1_METHOD */;
+
+/* Method to handle CRL access.
+ * In general a CRL could be very large (several Mb) and can consume large
+ * amounts of resources if stored in memory by multiple processes.
+ * This method allows general CRL operations to be redirected to more
+ * efficient callbacks: for example a CRL entry database.
+ */
+
+#define X509_CRL_METHOD_DYNAMIC                1
+
+struct x509_crl_method_st
+       {
+       int flags;
+       int (*crl_init)(X509_CRL *crl);
+       int (*crl_free)(X509_CRL *crl);
+       int (*crl_lookup)(X509_CRL *crl, X509_REVOKED **ret,
+                               ASN1_INTEGER *ser, X509_NAME *issuer);
+       int (*crl_verify)(X509_CRL *crl, EVP_PKEY *pk);
+       };
index d958ca6..87bd0e9 100644 (file)
@@ -153,6 +153,13 @@ err:\
                M_ASN1_D2I_get(b,func); \
                }
 
+#define M_ASN1_D2I_get_int_opt(b,func,type) \
+       if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \
+               == (V_ASN1_UNIVERSAL|(type)))) \
+               { \
+               M_ASN1_D2I_get_int(b,func); \
+               }
+
 #define M_ASN1_D2I_get_imp(b,func, type) \
        M_ASN1_next=(_tmp& V_ASN1_CONSTRUCTED)|type; \
        c.q=c.p; \
index cb08e15..aaca69a 100644 (file)
@@ -70,9 +70,8 @@ static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed,
             int indent)
        {
        static const char fmt[]="%-18s";
-       static const char fmt2[]="%2d %-15s";
        char str[128];
-       const char *p,*p2=NULL;
+       const char *p;
 
        if (constructed & V_ASN1_CONSTRUCTED)
                p="cons: ";
@@ -93,14 +92,8 @@ static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed,
        else
                p = ASN1_tag2str(tag);
 
-       if (p2 != NULL)
-               {
-               if (BIO_printf(bp,fmt2,tag,p2) <= 0) goto err;
-               }
-       else
-               {
-               if (BIO_printf(bp,fmt,p) <= 0) goto err;
-               }
+       if (BIO_printf(bp,fmt,p) <= 0)
+               goto err;
        return(1);
 err:
        return(0);
@@ -424,7 +417,7 @@ end:
 
 const char *ASN1_tag2str(int tag)
 {
-       static const char *tag2str[] = {
+       static const char * const tag2str[] = {
         "EOC", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING", /* 0-4 */
         "NULL", "OBJECT", "OBJECT DESCRIPTOR", "EXTERNAL", "REAL", /* 5-9 */
         "ENUMERATED", "<ASN1 11>", "UTF8STRING", "<ASN1 13>",      /* 10-13 */
index ac14f94..d230e4b 100644 (file)
@@ -3,7 +3,7 @@
  * project 2000.
  */
 /* ====================================================================
- * Copyright (c) 2000 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 2000-2005 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -218,6 +218,18 @@ extern "C" {
                #stname \
        ASN1_ITEM_end(tname)
 
+#define ASN1_NDEF_SEQUENCE_END_cb(stname, tname) \
+       ;\
+       ASN1_ITEM_start(tname) \
+               ASN1_ITYPE_NDEF_SEQUENCE,\
+               V_ASN1_SEQUENCE,\
+               tname##_seq_tt,\
+               sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
+               &tname##_aux,\
+               sizeof(stname),\
+               #stname \
+       ASN1_ITEM_end(tname)
+
 
 /* This pair helps declare a CHOICE type. We can do:
  *
@@ -651,8 +663,13 @@ typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM
 typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
 typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
 
+typedef int ASN1_ex_print_func(BIO *out, ASN1_VALUE **pval, 
+                                               int indent, const char *fname, 
+                                               const ASN1_PCTX *pctx);
+
 typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
 typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
+typedef int ASN1_primitive_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it, int indent, const ASN1_PCTX *pctx);
 
 typedef struct ASN1_COMPAT_FUNCS_st {
        ASN1_new_func *asn1_new;
@@ -668,6 +685,7 @@ typedef struct ASN1_EXTERN_FUNCS_st {
        ASN1_ex_free_func *asn1_ex_clear;
        ASN1_ex_d2i *asn1_ex_d2i;
        ASN1_ex_i2d *asn1_ex_i2d;
+       ASN1_ex_print_func *asn1_ex_print;
 } ASN1_EXTERN_FUNCS;
 
 typedef struct ASN1_PRIMITIVE_FUNCS_st {
@@ -678,6 +696,7 @@ typedef struct ASN1_PRIMITIVE_FUNCS_st {
        ASN1_ex_free_func *prim_clear;
        ASN1_primitive_c2i *prim_c2i;
        ASN1_primitive_i2c *prim_i2c;
+       ASN1_primitive_print *prim_print;
 } ASN1_PRIMITIVE_FUNCS;
 
 /* This is the ASN1_AUX structure: it handles various
@@ -697,7 +716,8 @@ typedef struct ASN1_PRIMITIVE_FUNCS_st {
  * then an external type is more appropriate.
  */
 
-typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it);
+typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it,
+                               void *exarg);
 
 typedef struct ASN1_AUX_st {
        void *app_data;
@@ -708,6 +728,23 @@ typedef struct ASN1_AUX_st {
        int enc_offset;         /* Offset of ASN1_ENCODING structure */
 } ASN1_AUX;
 
+/* For print related callbacks exarg points to this structure */
+typedef struct ASN1_PRINT_ARG_st {
+       BIO *out;
+       int indent;
+       const ASN1_PCTX *pctx;
+} ASN1_PRINT_ARG;
+
+/* For streaming related callbacks exarg points to this structure */
+typedef struct ASN1_STREAM_ARG_st {
+       /* BIO to stream through */
+       BIO *out;
+       /* BIO with filters appended */
+       BIO *ndef_bio;
+       /* Streaming I/O boundary */
+       unsigned char **boundary;
+} ASN1_STREAM_ARG;
+
 /* Flags in ASN1_AUX */
 
 /* Use a reference count */
@@ -727,6 +764,12 @@ typedef struct ASN1_AUX_st {
 #define ASN1_OP_D2I_POST       5
 #define ASN1_OP_I2D_PRE                6
 #define ASN1_OP_I2D_POST       7
+#define ASN1_OP_PRINT_PRE      8
+#define ASN1_OP_PRINT_POST     9
+#define ASN1_OP_STREAM_PRE     10
+#define ASN1_OP_STREAM_POST    11
+#define ASN1_OP_DETACHED_PRE   12
+#define ASN1_OP_DETACHED_POST  13
 
 /* Macro to implement a primitive type */
 #define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0)
@@ -782,9 +825,22 @@ typedef struct ASN1_AUX_st {
 #define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \
                        IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname)
 
+#define IMPLEMENT_STATIC_ASN1_ALLOC_FUNCTIONS(stname) \
+               IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(static, stname, stname, stname)
+
 #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \
                IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname)
 
+#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(pre, stname, itname, fname) \
+       pre stname *fname##_new(void) \
+       { \
+               return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \
+       } \
+       pre void fname##_free(stname *a) \
+       { \
+               ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \
+       }
+
 #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \
        stname *fname##_new(void) \
        { \
@@ -834,6 +890,17 @@ typedef struct ASN1_AUX_st {
         return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \
         }
 
+#define IMPLEMENT_ASN1_PRINT_FUNCTION(stname) \
+       IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, stname, stname)
+
+#define IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, itname, fname) \
+       int fname##_print_ctx(BIO *out, stname *x, int indent, \
+                                               const ASN1_PCTX *pctx) \
+       { \
+               return ASN1_item_print(out, (ASN1_VALUE *)x, indent, \
+                       ASN1_ITEM_rptr(itname), pctx); \
+       } 
+
 #define IMPLEMENT_ASN1_FUNCTIONS_const(name) \
                IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name)
 
index d8d9e76..c1d1b12 100644 (file)
@@ -59,6 +59,7 @@
 #include <openssl/x509.h>
 #include <openssl/asn1.h>
 #include <openssl/asn1t.h>
+#include "asn1_locl.h"
 
 /* Generalised MIME like utilities for streaming ASN1. Although many
  * have a PKCS7/CMS like flavour others are more general purpose.
@@ -86,6 +87,8 @@ STACK_OF(MIME_PARAM) *params;         /* Zero or more parameters */
 DECLARE_STACK_OF(MIME_HEADER)
 IMPLEMENT_STACK_OF(MIME_HEADER)
 
+static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
+                                       const ASN1_ITEM *it);
 static char * strip_ends(char *name);
 static char * strip_start(char *name);
 static char * strip_end(char *name);
@@ -107,6 +110,39 @@ static void mime_hdr_free(MIME_HEADER *hdr);
 #define MAX_SMLEN 1024
 #define mime_debug(x) /* x */
 
+/* Output an ASN1 structure in BER format streaming if necessary */
+
+int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
+                               const ASN1_ITEM *it)
+       {
+       /* If streaming create stream BIO and copy all content through it */
+       if (flags & SMIME_STREAM)
+               {
+               BIO *bio, *tbio;
+               bio = BIO_new_NDEF(out, val, it);
+               if (!bio)
+                       {
+                       ASN1err(ASN1_F_I2D_ASN1_BIO_STREAM,ERR_R_MALLOC_FAILURE);
+                       return 0;
+                       }
+               SMIME_crlf_copy(in, bio, flags);
+               (void)BIO_flush(bio);
+               /* Free up successive BIOs until we hit the old output BIO */
+               do
+                       {
+                       tbio = BIO_pop(bio);
+                       BIO_free(bio);
+                       bio = tbio;
+                       } while (bio != out);
+               }
+       /* else just write out ASN1 structure which will have all content
+        * stored internally
+        */
+       else
+               ASN1_item_i2d_bio(it, out, val);
+       return 1;
+       }
+
 /* Base 64 read and write of ASN1 structure */
 
 static int B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
@@ -123,13 +159,26 @@ static int B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
        /* prepend the b64 BIO so all data is base64 encoded.
         */
        out = BIO_push(b64, out);
-       r = ASN1_item_i2d_bio(it, out, val);
+       r = i2d_ASN1_bio_stream(out, val, in, flags, it);
        (void)BIO_flush(out);
        BIO_pop(out);
        BIO_free(b64);
        return r;
        }
 
+/* Streaming ASN1 PEM write */
+
+int PEM_write_bio_ASN1_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
+                               const char *hdr,
+                               const ASN1_ITEM *it)
+       {
+       int r;
+       BIO_printf(out, "-----BEGIN %s-----\n", hdr);
+       r = B64_write_ASN1(out, val, in, flags, it);
+       BIO_printf(out, "-----END %s-----\n", hdr);
+       return r;
+       }
+
 static ASN1_VALUE *b64_read_asn1(BIO *bio, const ASN1_ITEM *it)
 {
        BIO *b64;
@@ -152,7 +201,8 @@ static ASN1_VALUE *b64_read_asn1(BIO *bio, const ASN1_ITEM *it)
 
 static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs)
        {
-       int i, have_unknown = 0, write_comma, md_nid;
+       const EVP_MD *md;
+       int i, have_unknown = 0, write_comma, ret = 0, md_nid;
        have_unknown = 0;
        write_comma = 0;
        for (i = 0; i < sk_X509_ALGOR_num(mdalgs); i++)
@@ -161,6 +211,21 @@ static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs)
                        BIO_write(out, ",", 1);
                write_comma = 1;
                md_nid = OBJ_obj2nid(sk_X509_ALGOR_value(mdalgs, i)->algorithm);
+               md = EVP_get_digestbynid(md_nid);
+               if (md && md->md_ctrl)
+                       {
+                       int rv;
+                       char *micstr;
+                       rv = md->md_ctrl(NULL, EVP_MD_CTRL_MICALG, 0, &micstr);
+                       if (rv > 0)
+                               {
+                               BIO_puts(out, micstr);
+                               OPENSSL_free(micstr);
+                               continue;
+                               }
+                       if (rv != -2)
+                               goto err;
+                       }
                switch(md_nid)
                        {
                        case NID_sha1:
@@ -183,6 +248,11 @@ static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs)
                        BIO_puts(out, "sha-512");
                        break;
 
+                       case NID_id_GostR3411_94:
+                       BIO_puts(out, "gostr3411-94");
+                               goto err;
+                       break;
+
                        default:
                        if (have_unknown)
                                write_comma = 0;
@@ -196,16 +266,18 @@ static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs)
                        }
                }
 
-       return 1;
+       ret = 1;
+       err:
+
+       return ret;
 
        }
 
 /* SMIME sender */
 
-int int_smime_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
+int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
                                int ctype_nid, int econt_nid,
                                STACK_OF(X509_ALGOR) *mdalgs,
-                               asn1_output_data_fn *data_fn,
                                const ASN1_ITEM *it)
 {
        char bound[33], c;
@@ -243,7 +315,7 @@ int int_smime_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
                                                mime_eol, mime_eol);
                /* Now write out the first part */
                BIO_printf(bio, "------%s%s", bound, mime_eol);
-               if (!data_fn(bio, data, val, flags, it))
+               if (!asn1_output_data(bio, data, val, flags, it))
                        return 0;
                BIO_printf(bio, "%s------%s%s", mime_eol, bound, mime_eol);
 
@@ -296,8 +368,6 @@ int int_smime_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
        return 1;
 }
 
-#if 0
-
 /* Handle output of ASN1 data */
 
 
@@ -350,8 +420,6 @@ static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
 
        }
 
-#endif
-
 /* SMIME reader: handle multipart/signed and opaque signing.
  * in multipart case the content is placed in a memory BIO
  * pointed to by "bcont". In opaque this is set to NULL
index f1a5a05..ad73821 100644 (file)
 
 /* Turn an ASN1 encoded SEQUENCE OF into a STACK of structures */
 
-STACK *ASN1_seq_unpack(const unsigned char *buf, int len,
-                      d2i_of_void *d2i,void (*free_func)(void *))
+STACK_OF(OPENSSL_BLOCK) *ASN1_seq_unpack(const unsigned char *buf, int len,
+                        d2i_of_void *d2i, void (*free_func)(OPENSSL_BLOCK))
 {
-    STACK *sk;
+    STACK_OF(OPENSSL_BLOCK) *sk;
     const unsigned char *pbuf;
     pbuf =  buf;
     if (!(sk = d2i_ASN1_SET(NULL, &pbuf, len, d2i, free_func,
@@ -82,7 +82,7 @@ STACK *ASN1_seq_unpack(const unsigned char *buf, int len,
  * OPENSSL_malloc'ed buffer
  */
 
-unsigned char *ASN1_seq_pack(STACK *safes, i2d_of_void *i2d,
+unsigned char *ASN1_seq_pack(STACK_OF(OPENSSL_BLOCK) *safes, i2d_of_void *i2d,
                             unsigned char **buf, int *len)
 {
        int safelen;
diff --git a/deps/openssl/openssl/crypto/asn1/bio_asn1.c b/deps/openssl/openssl/crypto/asn1/bio_asn1.c
new file mode 100644 (file)
index 0000000..dc7efd5
--- /dev/null
@@ -0,0 +1,495 @@
+/* bio_asn1.c */
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+/* Experimental ASN1 BIO. When written through the data is converted
+ * to an ASN1 string type: default is OCTET STRING. Additional functions
+ * can be provided to add prefix and suffix data.
+ */
+
+#include <string.h>
+#include <openssl/bio.h>
+#include <openssl/asn1.h>
+
+/* Must be large enough for biggest tag+length */
+#define DEFAULT_ASN1_BUF_SIZE 20
+
+typedef enum 
+       {
+       ASN1_STATE_START,
+       ASN1_STATE_PRE_COPY,
+       ASN1_STATE_HEADER,
+       ASN1_STATE_HEADER_COPY,
+       ASN1_STATE_DATA_COPY,
+       ASN1_STATE_POST_COPY,
+       ASN1_STATE_DONE
+       } asn1_bio_state_t;
+
+typedef struct BIO_ASN1_EX_FUNCS_st
+       {
+       asn1_ps_func    *ex_func;
+       asn1_ps_func    *ex_free_func;
+       } BIO_ASN1_EX_FUNCS;
+
+typedef struct BIO_ASN1_BUF_CTX_t
+       {
+       /* Internal state */
+       asn1_bio_state_t state;
+       /* Internal buffer */
+       unsigned char *buf;
+       /* Size of buffer */
+       int bufsize;
+       /* Current position in buffer */
+       int bufpos;
+       /* Current buffer length */
+       int buflen;
+       /* Amount of data to copy */
+       int copylen;
+       /* Class and tag to use */
+       int asn1_class, asn1_tag;
+       asn1_ps_func *prefix, *prefix_free, *suffix, *suffix_free;
+       /* Extra buffer for prefix and suffix data */
+       unsigned char *ex_buf;
+       int ex_len;
+       int ex_pos;
+       void *ex_arg;
+       } BIO_ASN1_BUF_CTX;
+
+
+static int asn1_bio_write(BIO *h, const char *buf,int num);
+static int asn1_bio_read(BIO *h, char *buf, int size);
+static int asn1_bio_puts(BIO *h, const char *str);
+static int asn1_bio_gets(BIO *h, char *str, int size);
+static long asn1_bio_ctrl(BIO *h, int cmd, long arg1, void *arg2);
+static int asn1_bio_new(BIO *h);
+static int asn1_bio_free(BIO *data);
+static long asn1_bio_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
+
+static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size);
+static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
+                               asn1_ps_func *cleanup, asn1_bio_state_t next);
+static int asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
+                               asn1_ps_func *setup, 
+                               asn1_bio_state_t ex_state,
+                               asn1_bio_state_t other_state);
+
+static BIO_METHOD methods_asn1=
+       {
+       BIO_TYPE_ASN1,
+       "asn1",
+       asn1_bio_write,
+       asn1_bio_read,
+       asn1_bio_puts,
+       asn1_bio_gets,
+       asn1_bio_ctrl,
+       asn1_bio_new,
+       asn1_bio_free,
+       asn1_bio_callback_ctrl,
+       };
+
+BIO_METHOD *BIO_f_asn1(void)
+       {
+       return(&methods_asn1);
+       }
+
+
+static int asn1_bio_new(BIO *b)
+       {
+       BIO_ASN1_BUF_CTX *ctx;
+       ctx = OPENSSL_malloc(sizeof(BIO_ASN1_BUF_CTX));
+       if (!ctx)
+               return 0;
+       if (!asn1_bio_init(ctx, DEFAULT_ASN1_BUF_SIZE))
+               return 0;
+       b->init = 1;
+       b->ptr = (char *)ctx;
+       b->flags = 0;
+       return 1;
+       }
+
+static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size)
+       {
+       ctx->buf = OPENSSL_malloc(size);
+       if (!ctx->buf)
+               return 0;
+       ctx->bufsize = size;
+       ctx->bufpos = 0;
+       ctx->buflen = 0;
+       ctx->copylen = 0;
+       ctx->asn1_class = V_ASN1_UNIVERSAL;
+       ctx->asn1_tag = V_ASN1_OCTET_STRING;
+       ctx->ex_buf = 0;
+       ctx->ex_pos = 0;
+       ctx->ex_len = 0;
+       ctx->state = ASN1_STATE_START;
+       return 1;
+       }
+
+static int asn1_bio_free(BIO *b)
+       {
+       BIO_ASN1_BUF_CTX *ctx;
+       ctx = (BIO_ASN1_BUF_CTX *) b->ptr;
+       if (ctx == NULL)
+               return 0;
+       if (ctx->buf)
+               OPENSSL_free(ctx->buf);
+       OPENSSL_free(ctx);
+       b->init = 0;
+       b->ptr = NULL;
+       b->flags = 0;
+       return 1;
+       }
+
+static int asn1_bio_write(BIO *b, const char *in , int inl)
+       {
+       BIO_ASN1_BUF_CTX *ctx;
+       int wrmax, wrlen, ret;
+       unsigned char *p;
+       if (!in || (inl < 0) || (b->next_bio == NULL))
+               return 0;
+       ctx = (BIO_ASN1_BUF_CTX *) b->ptr;
+       if (ctx == NULL)
+               return 0;
+
+       wrlen = 0;
+       ret = -1;
+
+       for(;;)
+               {
+               switch (ctx->state)
+                       {
+
+                       /* Setup prefix data, call it */
+                       case ASN1_STATE_START:
+                       if (!asn1_bio_setup_ex(b, ctx, ctx->prefix,
+                               ASN1_STATE_PRE_COPY, ASN1_STATE_HEADER))
+                               return 0;
+                       break;
+
+                       /* Copy any pre data first */
+                       case ASN1_STATE_PRE_COPY:
+
+                       ret = asn1_bio_flush_ex(b, ctx, ctx->prefix_free,
+                                                       ASN1_STATE_HEADER);
+
+                       if (ret <= 0)
+                               goto done;
+
+                       break;
+
+                       case ASN1_STATE_HEADER:
+                       ctx->buflen =
+                               ASN1_object_size(0, inl, ctx->asn1_tag) - inl;
+                       OPENSSL_assert(ctx->buflen <= ctx->bufsize);
+                       p = ctx->buf;
+                       ASN1_put_object(&p, 0, inl,
+                                       ctx->asn1_tag, ctx->asn1_class);
+                       ctx->copylen = inl;
+                       ctx->state = ASN1_STATE_HEADER_COPY;
+
+                       break;
+
+                       case ASN1_STATE_HEADER_COPY:    
+                       ret = BIO_write(b->next_bio,
+                                       ctx->buf + ctx->bufpos, ctx->buflen);
+                       if (ret <= 0)
+                               goto done;
+
+                       ctx->buflen -= ret;
+                       if (ctx->buflen)
+                               ctx->bufpos += ret;
+                       else
+                               {
+                               ctx->bufpos = 0;
+                               ctx->state = ASN1_STATE_DATA_COPY;
+                               }
+
+                       break;
+
+                       case ASN1_STATE_DATA_COPY:
+
+                       if (inl > ctx->copylen)
+                               wrmax = ctx->copylen;
+                       else
+                               wrmax = inl;
+                       ret = BIO_write(b->next_bio, in, wrmax);
+                       if (ret <= 0)
+                               break;
+                       wrlen += ret;
+                       ctx->copylen -= ret;
+                       in += ret;
+                       inl -= ret;
+
+                       if (ctx->copylen == 0)
+                               ctx->state = ASN1_STATE_HEADER;
+
+                       if (inl == 0)
+                               goto done;
+
+                       break;
+
+                       default:
+                       BIO_clear_retry_flags(b);
+                       return 0;
+
+                       }
+
+               }
+
+       done:
+       BIO_clear_retry_flags(b);
+       BIO_copy_next_retry(b);
+
+       return (wrlen > 0) ? wrlen : ret;
+
+       }
+
+static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
+                               asn1_ps_func *cleanup, asn1_bio_state_t next)
+       {
+       int ret;
+       if (ctx->ex_len <= 0)
+               return 1;
+       for(;;)
+               {
+               ret = BIO_write(b->next_bio, ctx->ex_buf + ctx->ex_pos,
+                                                               ctx->ex_len);
+               if (ret <= 0)
+                       break;
+               ctx->ex_len -= ret;
+               if (ctx->ex_len > 0)
+                       ctx->ex_pos += ret;
+               else
+                       {
+                       if(cleanup)
+                               cleanup(b, &ctx->ex_buf, &ctx->ex_len,
+                                                               &ctx->ex_arg);
+                       ctx->state = next;
+                       ctx->ex_pos = 0;
+                       break;
+                       }
+               }
+       return ret;
+       }
+
+static int asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
+                               asn1_ps_func *setup, 
+                               asn1_bio_state_t ex_state,
+                               asn1_bio_state_t other_state)
+       {
+       if (setup && !setup(b, &ctx->ex_buf, &ctx->ex_len, &ctx->ex_arg))
+               {
+               BIO_clear_retry_flags(b);
+               return 0;
+               }
+       if (ctx->ex_len > 0)
+               ctx->state = ex_state;
+       else
+               ctx->state = other_state;
+       return 1;
+       }
+
+static int asn1_bio_read(BIO *b, char *in , int inl)
+       {
+       if (!b->next_bio)
+               return 0;
+       return BIO_read(b->next_bio, in , inl);
+       }
+
+static int asn1_bio_puts(BIO *b, const char *str)
+       {
+       return asn1_bio_write(b, str, strlen(str));
+       }
+
+static int asn1_bio_gets(BIO *b, char *str, int size)
+       {
+       if (!b->next_bio)
+               return 0;
+       return BIO_gets(b->next_bio, str , size);
+       }
+
+static long asn1_bio_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
+       {
+       if (b->next_bio == NULL) return(0);
+       return BIO_callback_ctrl(b->next_bio,cmd,fp);
+       }
+
+static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2)
+       {
+       BIO_ASN1_BUF_CTX *ctx;
+       BIO_ASN1_EX_FUNCS *ex_func;
+       long ret = 1;
+       ctx = (BIO_ASN1_BUF_CTX *) b->ptr;
+       if (ctx == NULL)
+               return 0;
+       switch(cmd)
+               {
+
+               case BIO_C_SET_PREFIX:
+               ex_func = arg2;
+               ctx->prefix  = ex_func->ex_func;
+               ctx->prefix_free  = ex_func->ex_free_func;
+               break;
+
+               case BIO_C_GET_PREFIX:
+               ex_func = arg2;
+               ex_func->ex_func = ctx->prefix;
+               ex_func->ex_free_func = ctx->prefix_free;
+               break;
+
+               case BIO_C_SET_SUFFIX:
+               ex_func = arg2;
+               ctx->suffix  = ex_func->ex_func;
+               ctx->suffix_free  = ex_func->ex_free_func;
+               break;
+
+               case BIO_C_GET_SUFFIX:
+               ex_func = arg2;
+               ex_func->ex_func = ctx->suffix;
+               ex_func->ex_free_func = ctx->suffix_free;
+               break;
+
+               case BIO_C_SET_EX_ARG:
+               ctx->ex_arg = arg2;
+               break;
+
+               case BIO_C_GET_EX_ARG:
+               *(void **)arg2 = ctx->ex_arg;
+               break;
+
+               case BIO_CTRL_FLUSH:
+               if (!b->next_bio)
+                       return 0;
+
+               /* Call post function if possible */
+               if (ctx->state == ASN1_STATE_HEADER)
+                       {
+                       if (!asn1_bio_setup_ex(b, ctx, ctx->suffix,
+                               ASN1_STATE_POST_COPY, ASN1_STATE_DONE))
+                               return 0;
+                       }
+
+               if (ctx->state == ASN1_STATE_POST_COPY)
+                       {
+                       ret = asn1_bio_flush_ex(b, ctx, ctx->suffix_free,
+                                                       ASN1_STATE_DONE);
+                       if (ret <= 0)
+                               return ret;
+                       }
+
+               if (ctx->state == ASN1_STATE_DONE)
+                       return BIO_ctrl(b->next_bio, cmd, arg1, arg2);
+               else
+                       {
+                       BIO_clear_retry_flags(b);
+                       return 0;
+                       }
+               break;
+
+
+               default:
+               if (!b->next_bio)
+                       return 0;
+               return BIO_ctrl(b->next_bio, cmd, arg1, arg2);
+
+               }
+
+       return ret;
+       }
+
+static int asn1_bio_set_ex(BIO *b, int cmd,
+               asn1_ps_func *ex_func, asn1_ps_func *ex_free_func)
+       {
+       BIO_ASN1_EX_FUNCS extmp;
+       extmp.ex_func = ex_func;
+       extmp.ex_free_func = ex_free_func;
+       return BIO_ctrl(b, cmd, 0, &extmp);
+       }
+
+static int asn1_bio_get_ex(BIO *b, int cmd,
+               asn1_ps_func **ex_func, asn1_ps_func **ex_free_func)
+       {
+       BIO_ASN1_EX_FUNCS extmp;
+       int ret;
+       ret = BIO_ctrl(b, cmd, 0, &extmp);
+       if (ret > 0)
+               {
+               *ex_func = extmp.ex_func;
+               *ex_free_func = extmp.ex_free_func;
+               }
+       return ret;
+       }
+
+int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, asn1_ps_func *prefix_free)
+       {
+       return asn1_bio_set_ex(b, BIO_C_SET_PREFIX, prefix, prefix_free);
+       }
+
+int BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix, asn1_ps_func **pprefix_free)
+       {
+       return asn1_bio_get_ex(b, BIO_C_GET_PREFIX, pprefix, pprefix_free);
+       }
+
+int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, asn1_ps_func *suffix_free)
+       {
+       return asn1_bio_set_ex(b, BIO_C_SET_SUFFIX, suffix, suffix_free);
+       }
+
+int BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, asn1_ps_func **psuffix_free)
+       {
+       return asn1_bio_get_ex(b, BIO_C_GET_SUFFIX, psuffix, psuffix_free);
+       }
diff --git a/deps/openssl/openssl/crypto/asn1/bio_ndef.c b/deps/openssl/openssl/crypto/asn1/bio_ndef.c
new file mode 100644 (file)
index 0000000..b91f97a
--- /dev/null
@@ -0,0 +1,243 @@
+/* bio_ndef.c */
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project.
+ */
+/* ====================================================================
+ * Copyright (c) 2008 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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 <openssl/asn1.h>
+#include <openssl/asn1t.h>
+#include <openssl/bio.h>
+#include <openssl/err.h>
+
+#include <stdio.h>
+
+/* Experimental NDEF ASN1 BIO support routines */
+
+/* The usage is quite simple, initialize an ASN1 structure,
+ * get a BIO from it then any data written through the BIO
+ * will end up translated to approptiate format on the fly.
+ * The data is streamed out and does *not* need to be
+ * all held in memory at once.
+ *
+ * When the BIO is flushed the output is finalized and any
+ * signatures etc written out.
+ *
+ * The BIO is a 'proper' BIO and can handle non blocking I/O
+ * correctly.
+ *
+ * The usage is simple. The implementation is *not*...
+ */
+
+/* BIO support data stored in the ASN1 BIO ex_arg */
+
+typedef struct ndef_aux_st
+       {
+       /* ASN1 structure this BIO refers to */
+       ASN1_VALUE *val;
+       const ASN1_ITEM *it;
+       /* Top of the BIO chain */
+       BIO *ndef_bio;
+       /* Output BIO */
+       BIO *out;
+       /* Boundary where content is inserted */
+       unsigned char **boundary;
+       /* DER buffer start */
+       unsigned char *derbuf;
+       } NDEF_SUPPORT;
+
+static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg);
+static int ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg);
+static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg);
+static int ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg);
+
+BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it)
+       {
+       NDEF_SUPPORT *ndef_aux = NULL;
+       BIO *asn_bio = NULL;
+       const ASN1_AUX *aux = it->funcs;
+       ASN1_STREAM_ARG sarg;
+
+       if (!aux || !aux->asn1_cb)
+               {
+               ASN1err(ASN1_F_BIO_NEW_NDEF, ASN1_R_STREAMING_NOT_SUPPORTED);
+               return NULL;
+               }
+       ndef_aux = OPENSSL_malloc(sizeof(NDEF_SUPPORT));
+       asn_bio = BIO_new(BIO_f_asn1());
+
+       /* ASN1 bio needs to be next to output BIO */
+
+       out = BIO_push(asn_bio, out);
+
+       if (!ndef_aux || !asn_bio || !out)
+               goto err;
+
+       BIO_asn1_set_prefix(asn_bio, ndef_prefix, ndef_prefix_free);
+       BIO_asn1_set_suffix(asn_bio, ndef_suffix, ndef_suffix_free);
+
+       /* Now let callback prepend any digest, cipher etc BIOs
+        * ASN1 structure needs.
+        */
+
+       sarg.out = out;
+       sarg.ndef_bio = NULL;
+       sarg.boundary = NULL;
+
+       if (aux->asn1_cb(ASN1_OP_STREAM_PRE, &val, it, &sarg) <= 0)
+               goto err;
+
+       ndef_aux->val = val;
+       ndef_aux->it = it;
+       ndef_aux->ndef_bio = sarg.ndef_bio;
+       ndef_aux->boundary = sarg.boundary;
+       ndef_aux->out = out;
+
+       BIO_ctrl(asn_bio, BIO_C_SET_EX_ARG, 0, ndef_aux);
+
+       return sarg.ndef_bio;
+
+       err:
+       if (asn_bio)
+               BIO_free(asn_bio);
+       if (ndef_aux)
+               OPENSSL_free(ndef_aux);
+       return NULL;
+       }
+
+static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
+       {
+       NDEF_SUPPORT *ndef_aux;
+       unsigned char *p;
+       int derlen;
+
+       if (!parg)
+               return 0;
+
+       ndef_aux = *(NDEF_SUPPORT **)parg;
+
+       derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it);
+       p = OPENSSL_malloc(derlen);
+       ndef_aux->derbuf = p;
+       *pbuf = p;
+       derlen = ASN1_item_ndef_i2d(ndef_aux->val, &p, ndef_aux->it);
+
+       if (!*ndef_aux->boundary)
+               return 0;
+
+       *plen = *ndef_aux->boundary - *pbuf;
+
+       return 1;
+       }
+
+static int ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg)
+       {
+       NDEF_SUPPORT *ndef_aux;
+
+       if (!parg)
+               return 0;
+
+       ndef_aux = *(NDEF_SUPPORT **)parg;
+
+       if (ndef_aux->derbuf)
+               OPENSSL_free(ndef_aux->derbuf);
+
+       ndef_aux->derbuf = NULL;
+       *pbuf = NULL;
+       *plen = 0;
+       return 1;
+       }
+
+static int ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg)
+       {
+       NDEF_SUPPORT **pndef_aux = (NDEF_SUPPORT **)parg;
+       if (!ndef_prefix_free(b, pbuf, plen, parg))
+               return 0;
+       OPENSSL_free(*pndef_aux);
+       *pndef_aux = NULL;
+       return 1;
+       }
+
+static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
+       {
+       NDEF_SUPPORT *ndef_aux;
+       unsigned char *p;
+       int derlen;
+       const ASN1_AUX *aux;
+       ASN1_STREAM_ARG sarg;
+
+       if (!parg)
+               return 0;
+
+       ndef_aux = *(NDEF_SUPPORT **)parg;
+
+       aux = ndef_aux->it->funcs;
+
+       /* Finalize structures */
+       sarg.ndef_bio = ndef_aux->ndef_bio;
+       sarg.out = ndef_aux->out;
+       sarg.boundary = ndef_aux->boundary;
+       if (aux->asn1_cb(ASN1_OP_STREAM_POST,
+                               &ndef_aux->val, ndef_aux->it, &sarg) <= 0)
+               return 0;
+
+       derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it);
+       p = OPENSSL_malloc(derlen);
+       ndef_aux->derbuf = p;
+       *pbuf = p;
+       derlen = ASN1_item_ndef_i2d(ndef_aux->val, &p, ndef_aux->it);
+
+       if (!*ndef_aux->boundary)
+               return 0;
+       *pbuf = *ndef_aux->boundary;
+       *plen = derlen - (*ndef_aux->boundary - ndef_aux->derbuf);
+
+       return 1;
+       }
index bd020a9..b55e638 100644 (file)
@@ -2,7 +2,7 @@
  * Mask of various character properties
  */
 
-static unsigned char char_type[] = {
+static const unsigned char char_type[] = {
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
 120, 0, 1,40, 0, 0, 0,16,16,16, 0,25,25,16,16,16,
index 207ccda..2828944 100644 (file)
 #include <openssl/bn.h>
 #include <openssl/evp.h>
 #include <openssl/objects.h>
-#include <openssl/asn1.h>
-#ifndef OPENSSL_NO_RSA
-#include <openssl/rsa.h>
-#endif
-#ifndef OPENSSL_NO_DSA
-#include <openssl/dsa.h>
-#endif
-#ifndef OPENSSL_NO_EC
-#include <openssl/ec.h>
+#ifndef OPENSSL_NO_ENGINE
+#include <openssl/engine.h>
 #endif
+#include <openssl/x509.h>
+#include <openssl/asn1.h>
+#include "asn1_locl.h"
 
 EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp,
             long length)
@@ -85,47 +81,43 @@ EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp,
                        return(NULL);
                        }
                }
-       else    ret= *a;
-
-       ret->save_type=type;
-       ret->type=EVP_PKEY_type(type);
-       switch (ret->type)
+       else
                {
-#ifndef OPENSSL_NO_RSA
-       case EVP_PKEY_RSA:
-               if ((ret->pkey.rsa=d2i_RSAPrivateKey(NULL,
-                       (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */
+               ret= *a;
+#ifndef OPENSSL_NO_ENGINE
+               if (ret->engine)
                        {
-                       ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB);
-                       goto err;
+                       ENGINE_finish(ret->engine);
+                       ret->engine = NULL;
                        }
-               break;
 #endif
-#ifndef OPENSSL_NO_DSA
-       case EVP_PKEY_DSA:
-               if ((ret->pkey.dsa=d2i_DSAPrivateKey(NULL,
-                       (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */
+               }
+
+       if (!EVP_PKEY_set_type(ret, type))
+               {
+               ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
+               goto err;
+               }
+
+       if (!ret->ameth->old_priv_decode ||
+                       !ret->ameth->old_priv_decode(ret, pp, length))
+               {
+               if (ret->ameth->priv_decode) 
                        {
-                       ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB);
-                       goto err;
-                       }
-               break;
-#endif
-#ifndef OPENSSL_NO_EC
-       case EVP_PKEY_EC:
-               if ((ret->pkey.ec = d2i_ECPrivateKey(NULL, 
-                       (const unsigned char **)pp, length)) == NULL)
+                       PKCS8_PRIV_KEY_INFO *p8=NULL;
+                       p8=d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length);
+                       if (!p8) goto err;
+                       EVP_PKEY_free(ret);
+                       ret = EVP_PKCS82PKEY(p8);
+                       PKCS8_PRIV_KEY_INFO_free(p8);
+
+                       } 
+               else 
                        {
-                       ASN1err(ASN1_F_D2I_PRIVATEKEY, ERR_R_ASN1_LIB);
+                       ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB);
                        goto err;
                        }
-               break;
-#endif
-       default:
-               ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
-               goto err;
-               /* break; */
-               }
+               }       
        if (a != NULL) (*a)=ret;
        return(ret);
 err:
@@ -146,8 +138,7 @@ EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp,
         * by analyzing it we can determine the passed structure: this
         * assumes the input is surrounded by an ASN1 SEQUENCE.
         */
-       inkey = d2i_ASN1_SET_OF_ASN1_TYPE(NULL, &p, length, d2i_ASN1_TYPE, 
-                       ASN1_TYPE_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
+       inkey = d2i_ASN1_SEQUENCE_ANY(NULL, &p, length);
        /* Since we only need to discern "traditional format" RSA and DSA
         * keys we can just count the elements.
          */
@@ -155,6 +146,24 @@ EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp,
                keytype = EVP_PKEY_DSA;
        else if (sk_ASN1_TYPE_num(inkey) == 4)
                keytype = EVP_PKEY_EC;
+       else if (sk_ASN1_TYPE_num(inkey) == 3)  
+               { /* This seems to be PKCS8, not traditional format */
+                       PKCS8_PRIV_KEY_INFO *p8 = d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length);
+                       EVP_PKEY *ret;
+
+                       sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free);
+                       if (!p8) 
+                               {
+                               ASN1err(ASN1_F_D2I_AUTOPRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
+                               return NULL;
+                               }
+                       ret = EVP_PKCS82PKEY(p8);
+                       PKCS8_PRIV_KEY_INFO_free(p8);
+                       if (a) {
+                               *a = ret;
+                       }       
+                       return ret;
+               }
        else keytype = EVP_PKEY_RSA;
        sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free);
        return d2i_PrivateKey(keytype, a, pp, length);
index 3694f51..c8f39ce 100644 (file)
@@ -87,9 +87,13 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp,
                }
        else    ret= *a;
 
-       ret->save_type=type;
-       ret->type=EVP_PKEY_type(type);
-       switch (ret->type)
+       if (!EVP_PKEY_set_type(ret, type))
+               {
+               ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB);
+               goto err;
+               }
+
+       switch (EVP_PKEY_id(ret))
                {
 #ifndef OPENSSL_NO_RSA
        case EVP_PKEY_RSA:
index 0be52c5..e398b62 100644 (file)
 
 #include <stdio.h>
 #include "cryptlib.h"
-#include <openssl/bn.h>
 #include <openssl/evp.h>
-#include <openssl/objects.h>
-#ifndef OPENSSL_NO_RSA
-#include <openssl/rsa.h>
-#endif
-#ifndef OPENSSL_NO_DSA
-#include <openssl/dsa.h>
-#endif
-#ifndef OPENSSL_NO_EC
-#include <openssl/ec.h>
-#endif
+#include <openssl/x509.h>
+#include "asn1_locl.h"
 
 int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp)
        {
-#ifndef OPENSSL_NO_RSA
-       if (a->type == EVP_PKEY_RSA)
+       if (a->ameth && a->ameth->old_priv_encode)
                {
-               return(i2d_RSAPrivateKey(a->pkey.rsa,pp));
+               return a->ameth->old_priv_encode(a, pp);
                }
-       else
-#endif
-#ifndef OPENSSL_NO_DSA
-       if (a->type == EVP_PKEY_DSA)
-               {
-               return(i2d_DSAPrivateKey(a->pkey.dsa,pp));
-               }
-#endif
-#ifndef OPENSSL_NO_EC
-       if (a->type == EVP_PKEY_EC)
-               {
-               return(i2d_ECPrivateKey(a->pkey.ec, pp));
-               }
-#endif
-
+       if (a->ameth && a->ameth->priv_encode) {
+               PKCS8_PRIV_KEY_INFO *p8 = EVP_PKEY2PKCS8(a);
+               int ret = i2d_PKCS8_PRIV_KEY_INFO(p8,pp);
+               PKCS8_PRIV_KEY_INFO_free(p8);
+               return ret;
+       }       
        ASN1err(ASN1_F_I2D_PRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
        return(-1);
        }
index e551c57..b8c4202 100644 (file)
@@ -3,7 +3,7 @@
  * project 1999.
  */
 /* ====================================================================
- * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -62,7 +62,8 @@
 #include <openssl/x509.h>
 #include <openssl/objects.h>
 
-static int nsseq_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
+static int nsseq_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
+                                                       void *exarg)
 {
        if(operation == ASN1_OP_NEW_POST) {
                NETSCAPE_CERT_SEQUENCE *nsseq;
index c4582f8..94bc38b 100644 (file)
@@ -71,61 +71,78 @@ ASN1_SEQUENCE(PBEPARAM) = {
 
 IMPLEMENT_ASN1_FUNCTIONS(PBEPARAM)
 
-/* Return an algorithm identifier for a PKCS#5 PBE algorithm */
 
-X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt,
-            int saltlen)
-{
+/* Set an algorithm identifier for a PKCS#5 PBE algorithm */
+
+int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter,
+                               const unsigned char *salt, int saltlen)
+       {
        PBEPARAM *pbe=NULL;
-       ASN1_OBJECT *al;
-       X509_ALGOR *algor;
-       ASN1_TYPE *astype=NULL;
+       ASN1_STRING *pbe_str=NULL;
+       unsigned char *sstr;
 
-       if (!(pbe = PBEPARAM_new ())) {
-               ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE);
+       pbe = PBEPARAM_new();
+       if (!pbe)
+               {
+               ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE);
                goto err;
-       }
-       if(iter <= 0) iter = PKCS5_DEFAULT_ITER;
-       if (!ASN1_INTEGER_set(pbe->iter, iter)) {
-               ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE);
+               }
+       if(iter <= 0)
+               iter = PKCS5_DEFAULT_ITER;
+       if (!ASN1_INTEGER_set(pbe->iter, iter))
+               {
+               ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE);
                goto err;
-       }
-       if (!saltlen) saltlen = PKCS5_SALT_LEN;
-       if (!(pbe->salt->data = OPENSSL_malloc (saltlen))) {
-               ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE);
+               }
+       if (!saltlen)
+               saltlen = PKCS5_SALT_LEN;
+       if (!ASN1_STRING_set(pbe->salt, NULL, saltlen))
+               {
+               ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE);
                goto err;
-       }
-       pbe->salt->length = saltlen;
-       if (salt) memcpy (pbe->salt->data, salt, saltlen);
-       else if (RAND_pseudo_bytes (pbe->salt->data, saltlen) < 0)
+               }
+       sstr = ASN1_STRING_data(pbe->salt);
+       if (salt)
+               memcpy(sstr, salt, saltlen);
+       else if (RAND_pseudo_bytes(sstr, saltlen) < 0)
                goto err;
 
-       if (!(astype = ASN1_TYPE_new())) {
-               ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE);
+       if(!ASN1_item_pack(pbe, ASN1_ITEM_rptr(PBEPARAM), &pbe_str))
+               {
+               ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE);
                goto err;
-       }
+               }
 
-       astype->type = V_ASN1_SEQUENCE;
-       if(!ASN1_pack_string_of(PBEPARAM, pbe, i2d_PBEPARAM,
-                               &astype->value.sequence)) {
-               ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE);
-               goto err;
-       }
-       PBEPARAM_free (pbe);
+       PBEPARAM_free(pbe);
        pbe = NULL;
-       
-       al = OBJ_nid2obj(alg); /* never need to free al */
-       if (!(algor = X509_ALGOR_new())) {
-               ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE);
-               goto err;
-       }
-       ASN1_OBJECT_free(algor->algorithm);
-       algor->algorithm = al;
-       algor->parameter = astype;
 
-       return (algor);
+       if (X509_ALGOR_set0(algor, OBJ_nid2obj(alg), V_ASN1_SEQUENCE, pbe_str))
+               return 1;
+
 err:
-       if (pbe != NULL) PBEPARAM_free(pbe);
-       if (astype != NULL) ASN1_TYPE_free(astype);
+       if (pbe != NULL)
+               PBEPARAM_free(pbe);
+       if (pbe_str != NULL)
+               ASN1_STRING_free(pbe_str);
+       return 0;
+       }
+
+/* Return an algorithm identifier for a PKCS#5 PBE algorithm */
+
+X509_ALGOR *PKCS5_pbe_set(int alg, int iter,
+                               const unsigned char *salt, int saltlen)
+       {
+       X509_ALGOR *ret;
+       ret = X509_ALGOR_new();
+       if (!ret)
+               {
+               ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE);
+               return NULL;
+               }
+
+       if (PKCS5_pbe_set0_algor(ret, alg, iter, salt, saltlen)) 
+               return ret;
+
+       X509_ALGOR_free(ret);
        return NULL;
-}
+       }
index 2b0516a..cb49b66 100644 (file)
@@ -82,10 +82,13 @@ IMPLEMENT_ASN1_FUNCTIONS(PBKDF2PARAM)
 
 /* Return an algorithm identifier for a PKCS#5 v2.0 PBE algorithm:
  * yes I know this is horrible!
+ *
+ * Extended version to allow application supplied PRF NID and IV.
  */
 
-X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
-                                unsigned char *salt, int saltlen)
+X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter,
+                                unsigned char *salt, int saltlen,
+                                unsigned char *aiv, int prf_nid)
 {
        X509_ALGOR *scheme = NULL, *kalg = NULL, *ret = NULL;
        int alg_nid;
@@ -98,7 +101,7 @@ X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
 
        alg_nid = EVP_CIPHER_type(cipher);
        if(alg_nid == NID_undef) {
-               ASN1err(ASN1_F_PKCS5_PBE2_SET,
+               ASN1err(ASN1_F_PKCS5_PBE2_SET_IV,
                                ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER);
                goto err;
        }
@@ -113,20 +116,33 @@ X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
        if(!(scheme->parameter = ASN1_TYPE_new())) goto merr;
 
        /* Create random IV */
-       if (EVP_CIPHER_iv_length(cipher) &&
-               RAND_pseudo_bytes(iv, EVP_CIPHER_iv_length(cipher)) < 0)
-               goto err;
+       if (EVP_CIPHER_iv_length(cipher))
+               {
+               if (aiv)
+                       memcpy(iv, aiv, EVP_CIPHER_iv_length(cipher));
+               else if (RAND_pseudo_bytes(iv, EVP_CIPHER_iv_length(cipher)) < 0)
+                       goto err;
+               }
 
        EVP_CIPHER_CTX_init(&ctx);
 
-       /* Dummy cipherinit to just setup the IV */
+       /* Dummy cipherinit to just setup the IV, and PRF */
        EVP_CipherInit_ex(&ctx, cipher, NULL, NULL, iv, 0);
        if(EVP_CIPHER_param_to_asn1(&ctx, scheme->parameter) < 0) {
-               ASN1err(ASN1_F_PKCS5_PBE2_SET,
+               ASN1err(ASN1_F_PKCS5_PBE2_SET_IV,
                                        ASN1_R_ERROR_SETTING_CIPHER_PARAMS);
                EVP_CIPHER_CTX_cleanup(&ctx);
                goto err;
        }
+       /* If prf NID unspecified see if cipher has a preference.
+        * An error is OK here: just means use default PRF.
+        */
+       if ((prf_nid == -1) && 
+       EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_PBE_PRF_NID, 0, &prf_nid) <= 0)
+               {
+               ERR_clear_error();
+               prf_nid = NID_hmacWithSHA1;
+               }
        EVP_CIPHER_CTX_cleanup(&ctx);
 
        if(!(kdf = PBKDF2PARAM_new())) goto merr;
@@ -154,7 +170,15 @@ X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
                                 EVP_CIPHER_key_length(cipher))) goto merr;
        }
 
-       /* prf can stay NULL because we are using hmacWithSHA1 */
+       /* prf can stay NULL if we are using hmacWithSHA1 */
+       if (prf_nid != NID_hmacWithSHA1)
+               {
+               kdf->prf = X509_ALGOR_new();
+               if (!kdf->prf)
+                       goto merr;
+               X509_ALGOR_set0(kdf->prf, OBJ_nid2obj(prf_nid),
+                                       V_ASN1_NULL, NULL);
+               }
 
        /* Now setup the PBE2PARAM keyfunc structure */
 
@@ -164,7 +188,7 @@ X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
 
        if(!(pbe2->keyfunc->parameter = ASN1_TYPE_new())) goto merr;
 
-       if(!ASN1_pack_string_of(PBKDF2PARAM, kdf, i2d_PBKDF2PARAM,
+       if(!ASN1_item_pack(kdf, ASN1_ITEM_rptr(PBKDF2PARAM),
                         &pbe2->keyfunc->parameter->value.sequence)) goto merr;
        pbe2->keyfunc->parameter->type = V_ASN1_SEQUENCE;
 
@@ -180,7 +204,7 @@ X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
 
        /* Encode PBE2PARAM into parameter */
 
-       if(!ASN1_pack_string_of(PBE2PARAM, pbe2, i2d_PBE2PARAM,
+       if(!ASN1_item_pack(pbe2, ASN1_ITEM_rptr(PBE2PARAM),
                                 &ret->parameter->value.sequence)) goto merr;
        ret->parameter->type = V_ASN1_SEQUENCE;
 
@@ -190,7 +214,7 @@ X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
        return ret;
 
        merr:
-       ASN1err(ASN1_F_PKCS5_PBE2_SET,ERR_R_MALLOC_FAILURE);
+       ASN1err(ASN1_F_PKCS5_PBE2_SET_IV,ERR_R_MALLOC_FAILURE);
 
        err:
        PBE2PARAM_free(pbe2);
@@ -203,3 +227,9 @@ X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
        return NULL;
 
 }
+
+X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
+                                unsigned char *salt, int saltlen)
+       {
+       return PKCS5_pbe2_set_iv(cipher, iter, salt, saltlen, NULL, -1);
+       }
diff --git a/deps/openssl/openssl/crypto/asn1/p8_key.c b/deps/openssl/openssl/crypto/asn1/p8_key.c
deleted file mode 100644 (file)
index 3a31248..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-/* crypto/asn1/p8_key.c */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-#include <stdio.h>
-#include "cryptlib.h"
-#include <openssl/asn1_mac.h>
-#include <openssl/objects.h>
-
-int i2d_X509_KEY(X509 *a, unsigned char **pp)
-       {
-       M_ASN1_I2D_vars(a);
-
-       M_ASN1_I2D_len(a->cert_info,    i2d_X509_CINF);
-       M_ASN1_I2D_len(a->sig_alg,      i2d_X509_ALGOR);
-       M_ASN1_I2D_len(a->signature,    i2d_ASN1_BIT_STRING);
-
-       M_ASN1_I2D_seq_total();
-
-       M_ASN1_I2D_put(a->cert_info,    i2d_X509_CINF);
-       M_ASN1_I2D_put(a->sig_alg,      i2d_X509_ALGOR);
-       M_ASN1_I2D_put(a->signature,    i2d_ASN1_BIT_STRING);
-
-       M_ASN1_I2D_finish();
-       }
-
-X509 *d2i_X509_KEY(X509 **a, unsigned char **pp, long length)
-       {
-       M_ASN1_D2I_vars(a,X509 *,X509_new);
-
-       M_ASN1_D2I_Init();
-       M_ASN1_D2I_start_sequence();
-       M_ASN1_D2I_get(ret->cert_info,d2i_X509_CINF);
-       M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
-       M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
-       M_ASN1_D2I_Finish(a,X509_free,ASN1_F_D2I_X509);
-       }
-
-X509 *X509_KEY_new(void)
-       {
-       X509_KEY *ret=NULL;
-
-       M_ASN1_New_OPENSSL_malloc(ret,X509_KEY);
-       ret->references=1;
-       ret->type=NID
-       M_ASN1_New(ret->cert_info,X509_CINF_new);
-       M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
-       M_ASN1_New(ret->signature,ASN1_BIT_STRING_new);
-       return(ret);
-       M_ASN1_New_Error(ASN1_F_X509_NEW);
-       }
-
-void X509_KEY_free(X509 *a)
-       {
-       int i;
-
-       if (a == NULL) return;
-
-       i=CRYPTO_add_lock(&a->references,-1,CRYPTO_LOCK_X509_KEY);
-#ifdef REF_PRINT
-       REF_PRINT("X509_KEY",a);
-#endif
-       if (i > 0) return;
-#ifdef REF_CHECK
-       if (i < 0)
-               {
-               fprintf(stderr,"X509_KEY_free, bad reference count\n");
-               abort();
-               }
-#endif
-
-       X509_CINF_free(a->cert_info);
-       X509_ALGOR_free(a->sig_alg);
-       ASN1_BIT_STRING_free(a->signature);
-       OPENSSL_free(a);
-       }
-
index 0a19575..17b68d3 100644 (file)
@@ -3,7 +3,7 @@
  * project 1999.
  */
 /* ====================================================================
- * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -62,7 +62,8 @@
 #include <openssl/x509.h>
 
 /* Minor tweak to operation: zero private key data */
-static int pkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
+static int pkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
+                                                       void *exarg)
 {
        /* Since the structure must still be valid use ASN1_OP_FREE_PRE */
        if(operation == ASN1_OP_FREE_PRE) {
@@ -82,3 +83,73 @@ ASN1_SEQUENCE_cb(PKCS8_PRIV_KEY_INFO, pkey_cb) = {
 } ASN1_SEQUENCE_END_cb(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
 
 IMPLEMENT_ASN1_FUNCTIONS(PKCS8_PRIV_KEY_INFO)
+
+int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj,
+                                       int version,
+                                       int ptype, void *pval,
+                                       unsigned char *penc, int penclen)
+       {
+       unsigned char **ppenc = NULL;
+       if (version >= 0)
+               {
+               if (!ASN1_INTEGER_set(priv->version, version))
+                       return 0;
+               }
+       if (penc)
+               {
+               int pmtype;
+               ASN1_OCTET_STRING *oct;
+               oct = ASN1_OCTET_STRING_new();
+               if (!oct)
+                       return 0;
+               oct->data = penc;
+               ppenc = &oct->data;
+               oct->length = penclen;
+               if (priv->broken == PKCS8_NO_OCTET)
+                       pmtype = V_ASN1_SEQUENCE;
+               else
+                       pmtype = V_ASN1_OCTET_STRING;
+               ASN1_TYPE_set(priv->pkey, pmtype, oct);
+               }
+       if (!X509_ALGOR_set0(priv->pkeyalg, aobj, ptype, pval))
+               {
+               /* If call fails do not swallow 'enc' */
+               if (ppenc)
+                       *ppenc = NULL;
+               return 0;
+               }
+       return 1;
+       }
+
+int PKCS8_pkey_get0(ASN1_OBJECT **ppkalg,
+               const unsigned char **pk, int *ppklen,
+               X509_ALGOR **pa,
+               PKCS8_PRIV_KEY_INFO *p8)
+       {
+       if (ppkalg)
+               *ppkalg = p8->pkeyalg->algorithm;
+       if(p8->pkey->type == V_ASN1_OCTET_STRING)
+               {
+               p8->broken = PKCS8_OK;
+               if (pk)
+                       {
+                       *pk = p8->pkey->value.octet_string->data;
+                       *ppklen = p8->pkey->value.octet_string->length;
+                       }
+               }
+       else if (p8->pkey->type == V_ASN1_SEQUENCE)
+               {
+               p8->broken = PKCS8_NO_OCTET;
+               if (pk)
+                       {
+                       *pk = p8->pkey->value.sequence->data;
+                       *ppklen = p8->pkey->value.sequence->length;
+                       }
+               }
+       else
+               return 0;
+       if (pa)
+               *pa = p8->pkeyalg;
+       return 1;
+       }
+
index afb95d6..9dd18f6 100644 (file)
  * copied and put under another distribution licence
  * [including the GNU Public Licence.]
  */
-/* ====================================================================
- * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
- * Binary polynomial ECC support in OpenSSL originally developed by 
- * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
- */
 
 #include <stdio.h>
 #include "cryptlib.h"
 #include <openssl/objects.h>
 #include <openssl/buffer.h>
 #include <openssl/bn.h>
-#ifndef OPENSSL_NO_RSA
-#include <openssl/rsa.h>
-#endif
-#ifndef OPENSSL_NO_DH
-#include <openssl/dh.h>
-#endif
-#ifndef OPENSSL_NO_DSA
-#include <openssl/dsa.h>
-#endif
-#ifndef OPENSSL_NO_EC
-#include <openssl/ec.h>
-#endif
-
-static int print(BIO *fp,const char *str, const BIGNUM *num,
-               unsigned char *buf,int off);
-#ifndef OPENSSL_NO_EC
-static int print_bin(BIO *fp, const char *str, const unsigned char *num,
-               size_t len, int off);
-#endif
-#ifndef OPENSSL_NO_RSA
-#ifndef OPENSSL_NO_FP_API
-int RSA_print_fp(FILE *fp, const RSA *x, int off)
-       {
-       BIO *b;
-       int ret;
-
-       if ((b=BIO_new(BIO_s_file())) == NULL)
-               {
-               RSAerr(RSA_F_RSA_PRINT_FP,ERR_R_BUF_LIB);
-               return(0);
-               }
-       BIO_set_fp(b,fp,BIO_NOCLOSE);
-       ret=RSA_print(b,x,off);
-       BIO_free(b);
-       return(ret);
-       }
-#endif
-
-int RSA_print(BIO *bp, const RSA *x, int off)
-       {
-       char str[128];
-       const char *s;
-       unsigned char *m=NULL;
-       int ret=0, mod_len = 0;
-       size_t buf_len=0, i;
-
-       if (x->n)
-               buf_len = (size_t)BN_num_bytes(x->n);
-       if (x->e)
-               if (buf_len < (i = (size_t)BN_num_bytes(x->e)))
-                       buf_len = i;
-       if (x->d)
-               if (buf_len < (i = (size_t)BN_num_bytes(x->d)))
-                       buf_len = i;
-       if (x->p)
-               if (buf_len < (i = (size_t)BN_num_bytes(x->p)))
-                       buf_len = i;
-       if (x->q)
-               if (buf_len < (i = (size_t)BN_num_bytes(x->q)))
-                       buf_len = i;
-       if (x->dmp1)
-               if (buf_len < (i = (size_t)BN_num_bytes(x->dmp1)))
-                       buf_len = i;
-       if (x->dmq1)
-               if (buf_len < (i = (size_t)BN_num_bytes(x->dmq1)))
-                       buf_len = i;
-       if (x->iqmp)
-               if (buf_len < (i = (size_t)BN_num_bytes(x->iqmp)))
-                       buf_len = i;
-
-       m=(unsigned char *)OPENSSL_malloc(buf_len+10);
-       if (m == NULL)
-               {
-               RSAerr(RSA_F_RSA_PRINT,ERR_R_MALLOC_FAILURE);
-               goto err;
-               }
-
-       if (x->n != NULL)
-               mod_len = BN_num_bits(x->n);
-
-       if (x->d != NULL)
-               {
-               if(!BIO_indent(bp,off,128))
-                  goto err;
-               if (BIO_printf(bp,"Private-Key: (%d bit)\n", mod_len)
-                       <= 0) goto err;
-               }
-
-       if (x->d == NULL)
-               BIO_snprintf(str,sizeof str,"Modulus (%d bit):", mod_len);
-       else
-               BUF_strlcpy(str,"modulus:",sizeof str);
-       if (!print(bp,str,x->n,m,off)) goto err;
-       s=(x->d == NULL)?"Exponent:":"publicExponent:";
-       if ((x->e != NULL) && !print(bp,s,x->e,m,off))
-               goto err;
-       if ((x->d != NULL) && !print(bp,"privateExponent:",x->d,m,off))
-               goto err;
-       if ((x->p != NULL) && !print(bp,"prime1:",x->p,m,off))
-               goto err;
-       if ((x->q != NULL) && !print(bp,"prime2:",x->q,m,off))
-               goto err;
-       if ((x->dmp1 != NULL) && !print(bp,"exponent1:",x->dmp1,m,off))
-               goto err;
-       if ((x->dmq1 != NULL) && !print(bp,"exponent2:",x->dmq1,m,off))
-               goto err;
-       if ((x->iqmp != NULL) && !print(bp,"coefficient:",x->iqmp,m,off))
-               goto err;
-       ret=1;
-err:
-       if (m != NULL) OPENSSL_free(m);
-       return(ret);
-       }
-#endif /* OPENSSL_NO_RSA */
-
-#ifndef OPENSSL_NO_DSA
-#ifndef OPENSSL_NO_FP_API
-int DSA_print_fp(FILE *fp, const DSA *x, int off)
-       {
-       BIO *b;
-       int ret;
-
-       if ((b=BIO_new(BIO_s_file())) == NULL)
-               {
-               DSAerr(DSA_F_DSA_PRINT_FP,ERR_R_BUF_LIB);
-               return(0);
-               }
-       BIO_set_fp(b,fp,BIO_NOCLOSE);
-       ret=DSA_print(b,x,off);
-       BIO_free(b);
-       return(ret);
-       }
-#endif
-
-int DSA_print(BIO *bp, const DSA *x, int off)
-       {
-       unsigned char *m=NULL;
-       int ret=0;
-       size_t buf_len=0,i;
-
-       if (x->p)
-               buf_len = (size_t)BN_num_bytes(x->p);
-       else
-               {
-               DSAerr(DSA_F_DSA_PRINT,DSA_R_MISSING_PARAMETERS);
-               goto err;
-               }
-       if (x->q)
-               if (buf_len < (i = (size_t)BN_num_bytes(x->q)))
-                       buf_len = i;
-       if (x->g)
-               if (buf_len < (i = (size_t)BN_num_bytes(x->g)))
-                       buf_len = i;
-       if (x->priv_key)
-               if (buf_len < (i = (size_t)BN_num_bytes(x->priv_key)))
-                       buf_len = i;
-       if (x->pub_key)
-               if (buf_len < (i = (size_t)BN_num_bytes(x->pub_key)))
-                       buf_len = i;
-
-       m=(unsigned char *)OPENSSL_malloc(buf_len+10);
-       if (m == NULL)
-               {
-               DSAerr(DSA_F_DSA_PRINT,ERR_R_MALLOC_FAILURE);
-               goto err;
-               }
-
-       if (x->priv_key != NULL)
-               {
-               if(!BIO_indent(bp,off,128))
-                  goto err;
-               if (BIO_printf(bp,"Private-Key: (%d bit)\n",BN_num_bits(x->p))
-                       <= 0) goto err;
-               }
-
-       if ((x->priv_key != NULL) && !print(bp,"priv:",x->priv_key,m,off))
-               goto err;
-       if ((x->pub_key  != NULL) && !print(bp,"pub: ",x->pub_key,m,off))
-               goto err;
-       if ((x->p != NULL) && !print(bp,"P:   ",x->p,m,off)) goto err;
-       if ((x->q != NULL) && !print(bp,"Q:   ",x->q,m,off)) goto err;
-       if ((x->g != NULL) && !print(bp,"G:   ",x->g,m,off)) goto err;
-       ret=1;
-err:
-       if (m != NULL) OPENSSL_free(m);
-       return(ret);
-       }
-#endif /* !OPENSSL_NO_DSA */
-
-#ifndef OPENSSL_NO_EC
-#ifndef OPENSSL_NO_FP_API
-int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off)
-       {
-       BIO *b;
-       int ret;
-
-       if ((b=BIO_new(BIO_s_file())) == NULL)
-               {
-               ECerr(EC_F_ECPKPARAMETERS_PRINT_FP,ERR_R_BUF_LIB);
-               return(0);
-               }
-       BIO_set_fp(b, fp, BIO_NOCLOSE);
-       ret = ECPKParameters_print(b, x, off);
-       BIO_free(b);
-       return(ret);
-       }
-
-int EC_KEY_print_fp(FILE *fp, const EC_KEY *x, int off)
-       {
-       BIO *b;
-       int ret;
-       if ((b=BIO_new(BIO_s_file())) == NULL)
-               {
-               ECerr(EC_F_EC_KEY_PRINT_FP, ERR_R_BIO_LIB);
-               return(0);
-               }
-       BIO_set_fp(b, fp, BIO_NOCLOSE);
-       ret = EC_KEY_print(b, x, off);
-       BIO_free(b);
-       return(ret);
-       }
-#endif
-
-int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off)
-       {
-       unsigned char *buffer=NULL;
-       size_t  buf_len=0, i;
-       int     ret=0, reason=ERR_R_BIO_LIB;
-       BN_CTX  *ctx=NULL;
-       const EC_POINT *point=NULL;
-       BIGNUM  *p=NULL, *a=NULL, *b=NULL, *gen=NULL,
-               *order=NULL, *cofactor=NULL;
-       const unsigned char *seed;
-       size_t  seed_len=0;
-       
-       static const char *gen_compressed = "Generator (compressed):";
-       static const char *gen_uncompressed = "Generator (uncompressed):";
-       static const char *gen_hybrid = "Generator (hybrid):";
-       if (!x)
-               {
-               reason = ERR_R_PASSED_NULL_PARAMETER;
-               goto err;
-               }
-
-       if (EC_GROUP_get_asn1_flag(x))
-               {
-               /* the curve parameter are given by an asn1 OID */
-               int nid;
-
-               if (!BIO_indent(bp, off, 128))
-                       goto err;
-
-               nid = EC_GROUP_get_curve_name(x);
-               if (nid == 0)
-                       goto err;
-
-               if (BIO_printf(bp, "ASN1 OID: %s", OBJ_nid2sn(nid)) <= 0)
-                       goto err;
-               if (BIO_printf(bp, "\n") <= 0)
-                       goto err;
-               }
-       else
-               {
-               /* explicit parameters */
-               int is_char_two = 0;
-               point_conversion_form_t form;
-               int tmp_nid = EC_METHOD_get_field_type(EC_GROUP_method_of(x));
-
-               if (tmp_nid == NID_X9_62_characteristic_two_field)
-                       is_char_two = 1;
-
-               if ((p = BN_new()) == NULL || (a = BN_new()) == NULL ||
-                       (b = BN_new()) == NULL || (order = BN_new()) == NULL ||
-                       (cofactor = BN_new()) == NULL)
-                       {
-                       reason = ERR_R_MALLOC_FAILURE;
-                       goto err;
-                       }
-
-               if (is_char_two)
-                       {
-                       if (!EC_GROUP_get_curve_GF2m(x, p, a, b, ctx))
-                               {
-                               reason = ERR_R_EC_LIB;
-                               goto err;
-                               }
-                       }
-               else /* prime field */
-                       {
-                       if (!EC_GROUP_get_curve_GFp(x, p, a, b, ctx))
-                               {
-                               reason = ERR_R_EC_LIB;
-                               goto err;
-                               }
-                       }
-
-               if ((point = EC_GROUP_get0_generator(x)) == NULL)
-                       {
-                       reason = ERR_R_EC_LIB;
-                       goto err;
-                       }
-               if (!EC_GROUP_get_order(x, order, NULL) || 
-                       !EC_GROUP_get_cofactor(x, cofactor, NULL))
-                       {
-                       reason = ERR_R_EC_LIB;
-                       goto err;
-                       }
-               
-               form = EC_GROUP_get_point_conversion_form(x);
-
-               if ((gen = EC_POINT_point2bn(x, point, 
-                               form, NULL, ctx)) == NULL)
-                       {
-                       reason = ERR_R_EC_LIB;
-                       goto err;
-                       }
-
-               buf_len = (size_t)BN_num_bytes(p);
-               if (buf_len < (i = (size_t)BN_num_bytes(a)))
-                       buf_len = i;
-               if (buf_len < (i = (size_t)BN_num_bytes(b)))
-                       buf_len = i;
-               if (buf_len < (i = (size_t)BN_num_bytes(gen)))
-                       buf_len = i;
-               if (buf_len < (i = (size_t)BN_num_bytes(order)))
-                       buf_len = i;
-               if (buf_len < (i = (size_t)BN_num_bytes(cofactor))) 
-                       buf_len = i;
-
-               if ((seed = EC_GROUP_get0_seed(x)) != NULL)
-                       seed_len = EC_GROUP_get_seed_len(x);
-
-               buf_len += 10;
-               if ((buffer = OPENSSL_malloc(buf_len)) == NULL)
-                       {
-                       reason = ERR_R_MALLOC_FAILURE;
-                       goto err;
-                       }
-
-               if (!BIO_indent(bp, off, 128))
-                       goto err;
-
-               /* print the 'short name' of the field type */
-               if (BIO_printf(bp, "Field Type: %s\n", OBJ_nid2sn(tmp_nid))
-                       <= 0)
-                       goto err;  
-
-               if (is_char_two)
-                       {
-                       /* print the 'short name' of the base type OID */
-                       int basis_type = EC_GROUP_get_basis_type(x);
-                       if (basis_type == 0)
-                               goto err;
-
-                       if (!BIO_indent(bp, off, 128))
-                               goto err;
-
-                       if (BIO_printf(bp, "Basis Type: %s\n", 
-                               OBJ_nid2sn(basis_type)) <= 0)
-                               goto err;
-
-                       /* print the polynomial */
-                       if ((p != NULL) && !print(bp, "Polynomial:", p, buffer,
-                               off))
-                               goto err;
-                       }
-               else
-                       {
-                       if ((p != NULL) && !print(bp, "Prime:", p, buffer,off))
-                               goto err;
-                       }
-               if ((a != NULL) && !print(bp, "A:   ", a, buffer, off)) 
-                       goto err;
-               if ((b != NULL) && !print(bp, "B:   ", b, buffer, off))
-                       goto err;
-               if (form == POINT_CONVERSION_COMPRESSED)
-                       {
-                       if ((gen != NULL) && !print(bp, gen_compressed, gen,
-                               buffer, off))
-                               goto err;
-                       }
-               else if (form == POINT_CONVERSION_UNCOMPRESSED)
-                       {
-                       if ((gen != NULL) && !print(bp, gen_uncompressed, gen,
-                               buffer, off))
-                               goto err;
-                       }
-               else /* form == POINT_CONVERSION_HYBRID */
-                       {
-                       if ((gen != NULL) && !print(bp, gen_hybrid, gen,
-                               buffer, off))
-                               goto err;
-                       }
-               if ((order != NULL) && !print(bp, "Order: ", order, 
-                       buffer, off)) goto err;
-               if ((cofactor != NULL) && !print(bp, "Cofactor: ", cofactor, 
-                       buffer, off)) goto err;
-               if (seed && !print_bin(bp, "Seed:", seed, seed_len, off))
-                       goto err;
-               }
-       ret=1;
-err:
-       if (!ret)
-               ECerr(EC_F_ECPKPARAMETERS_PRINT, reason);
-       if (p) 
-               BN_free(p);
-       if (a) 
-               BN_free(a);
-       if (b)
-               BN_free(b);
-       if (gen)
-               BN_free(gen);
-       if (order)
-               BN_free(order);
-       if (cofactor)
-               BN_free(cofactor);
-       if (ctx)
-               BN_CTX_free(ctx);
-       if (buffer != NULL) 
-               OPENSSL_free(buffer);
-       return(ret);    
-       }
 
-int EC_KEY_print(BIO *bp, const EC_KEY *x, int off)
-       {
-       unsigned char *buffer=NULL;
-       size_t  buf_len=0, i;
-       int     ret=0, reason=ERR_R_BIO_LIB;
-       BIGNUM  *pub_key=NULL, *order=NULL;
-       BN_CTX  *ctx=NULL;
-       const EC_GROUP *group;
-       const EC_POINT *public_key;
-       const BIGNUM *priv_key;
-       if (x == NULL || (group = EC_KEY_get0_group(x)) == NULL)
-               {
-               reason = ERR_R_PASSED_NULL_PARAMETER;
-               goto err;
-               }
-
-       public_key = EC_KEY_get0_public_key(x);
-       if ((pub_key = EC_POINT_point2bn(group, public_key,
-               EC_KEY_get_conv_form(x), NULL, ctx)) == NULL)
-               {
-               reason = ERR_R_EC_LIB;
-               goto err;
-               }
-
-       buf_len = (size_t)BN_num_bytes(pub_key);
-       priv_key = EC_KEY_get0_private_key(x);
-       if (priv_key != NULL)
-               {
-               if ((i = (size_t)BN_num_bytes(priv_key)) > buf_len)
-                       buf_len = i;
-               }
-
-       buf_len += 10;
-       if ((buffer = OPENSSL_malloc(buf_len)) == NULL)
-               {
-               reason = ERR_R_MALLOC_FAILURE;
-               goto err;
-               }
-
-       if (priv_key != NULL)
-               {
-               if (!BIO_indent(bp, off, 128))
-                       goto err;
-               if ((order = BN_new()) == NULL)
-                       goto err;
-               if (!EC_GROUP_get_order(group, order, NULL))
-                       goto err;
-               if (BIO_printf(bp, "Private-Key: (%d bit)\n", 
-                       BN_num_bits(order)) <= 0) goto err;
-               }
-  
-       if ((priv_key != NULL) && !print(bp, "priv:", priv_key, 
-               buffer, off))
-               goto err;
-       if ((pub_key != NULL) && !print(bp, "pub: ", pub_key,
-               buffer, off))
-               goto err;
-       if (!ECPKParameters_print(bp, group, off))
-               goto err;
-       ret=1;
-err:
-       if (!ret)
-               ECerr(EC_F_EC_KEY_PRINT, reason);
-       if (pub_key) 
-               BN_free(pub_key);
-       if (order)
-               BN_free(order);
-       if (ctx)
-               BN_CTX_free(ctx);
-       if (buffer != NULL)
-               OPENSSL_free(buffer);
-       return(ret);
-       }
-#endif /* OPENSSL_NO_EC */
-
-static int print(BIO *bp, const char *number, const BIGNUM *num, unsigned char *buf,
-            int off)
+int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num,
+                       unsigned char *buf, int off)
        {
        int n,i;
        const char *neg;
@@ -617,223 +112,3 @@ static int print(BIO *bp, const char *number, const BIGNUM *num, unsigned char *
                }
        return(1);
        }
-
-#ifndef OPENSSL_NO_EC
-static int print_bin(BIO *fp, const char *name, const unsigned char *buf,
-               size_t len, int off)
-       {
-       size_t i;
-       char str[128];
-
-       if (buf == NULL)
-               return 1;
-       if (off)
-               {
-               if (off > 128)
-                       off=128;
-               memset(str,' ',off);
-               if (BIO_write(fp, str, off) <= 0)
-                       return 0;
-               }
-
-       if (BIO_printf(fp,"%s", name) <= 0)
-               return 0;
-
-       for (i=0; i<len; i++)
-               {
-               if ((i%15) == 0)
-                       {
-                       str[0]='\n';
-                       memset(&(str[1]),' ',off+4);
-                       if (BIO_write(fp, str, off+1+4) <= 0)
-                               return 0;
-                       }
-               if (BIO_printf(fp,"%02x%s",buf[i],((i+1) == len)?"":":") <= 0)
-                       return 0;
-               }
-       if (BIO_write(fp,"\n",1) <= 0)
-               return 0;
-
-       return 1;
-       }
-#endif
-
-#ifndef OPENSSL_NO_DH
-#ifndef OPENSSL_NO_FP_API
-int DHparams_print_fp(FILE *fp, const DH *x)
-       {
-       BIO *b;
-       int ret;
-
-       if ((b=BIO_new(BIO_s_file())) == NULL)
-               {
-               DHerr(DH_F_DHPARAMS_PRINT_FP,ERR_R_BUF_LIB);
-               return(0);
-               }
-       BIO_set_fp(b,fp,BIO_NOCLOSE);
-       ret=DHparams_print(b, x);
-       BIO_free(b);
-       return(ret);
-       }
-#endif
-
-int DHparams_print(BIO *bp, const DH *x)
-       {
-       unsigned char *m=NULL;
-       int reason=ERR_R_BUF_LIB,ret=0;
-       size_t buf_len=0, i;
-
-       if (x->p)
-               buf_len = (size_t)BN_num_bytes(x->p);
-       else
-               {
-               reason = ERR_R_PASSED_NULL_PARAMETER;
-               goto err;
-               }
-       if (x->g)
-               if (buf_len < (i = (size_t)BN_num_bytes(x->g)))
-                       buf_len = i;
-       m=(unsigned char *)OPENSSL_malloc(buf_len+10);
-       if (m == NULL)
-               {
-               reason=ERR_R_MALLOC_FAILURE;
-               goto err;
-               }
-
-       if (BIO_printf(bp,"Diffie-Hellman-Parameters: (%d bit)\n",
-               BN_num_bits(x->p)) <= 0)
-               goto err;
-       if (!print(bp,"prime:",x->p,m,4)) goto err;
-       if (!print(bp,"generator:",x->g,m,4)) goto err;
-       if (x->length != 0)
-               {
-               if (BIO_printf(bp,"    recommended-private-length: %d bits\n",
-                       (int)x->length) <= 0) goto err;
-               }
-       ret=1;
-       if (0)
-               {
-err:
-               DHerr(DH_F_DHPARAMS_PRINT,reason);
-               }
-       if (m != NULL) OPENSSL_free(m);
-       return(ret);
-       }
-#endif
-
-#ifndef OPENSSL_NO_DSA
-#ifndef OPENSSL_NO_FP_API
-int DSAparams_print_fp(FILE *fp, const DSA *x)
-       {
-       BIO *b;
-       int ret;
-
-       if ((b=BIO_new(BIO_s_file())) == NULL)
-               {
-               DSAerr(DSA_F_DSAPARAMS_PRINT_FP,ERR_R_BUF_LIB);
-               return(0);
-               }
-       BIO_set_fp(b,fp,BIO_NOCLOSE);
-       ret=DSAparams_print(b, x);
-       BIO_free(b);
-       return(ret);
-       }
-#endif
-
-int DSAparams_print(BIO *bp, const DSA *x)
-       {
-       unsigned char *m=NULL;
-       int ret=0;
-       size_t buf_len=0,i;
-
-       if (x->p)
-               buf_len = (size_t)BN_num_bytes(x->p);
-       else
-               {
-               DSAerr(DSA_F_DSAPARAMS_PRINT,DSA_R_MISSING_PARAMETERS);
-               goto err;
-               }
-       if (x->q)
-               if (buf_len < (i = (size_t)BN_num_bytes(x->q)))
-                       buf_len = i;
-       if (x->g)
-               if (buf_len < (i = (size_t)BN_num_bytes(x->g)))
-                       buf_len = i;
-       m=(unsigned char *)OPENSSL_malloc(buf_len+10);
-       if (m == NULL)
-               {
-               DSAerr(DSA_F_DSAPARAMS_PRINT,ERR_R_MALLOC_FAILURE);
-               goto err;
-               }
-
-       if (BIO_printf(bp,"DSA-Parameters: (%d bit)\n",
-               BN_num_bits(x->p)) <= 0)
-               goto err;
-       if (!print(bp,"p:",x->p,m,4)) goto err;
-       if ((x->q != NULL) && !print(bp,"q:",x->q,m,4)) goto err;
-       if ((x->g != NULL) && !print(bp,"g:",x->g,m,4)) goto err;
-       ret=1;
-err:
-       if (m != NULL) OPENSSL_free(m);
-       return(ret);
-       }
-
-#endif /* !OPENSSL_NO_DSA */
-
-#ifndef OPENSSL_NO_EC
-#ifndef OPENSSL_NO_FP_API
-int ECParameters_print_fp(FILE *fp, const EC_KEY *x)
-       {
-       BIO *b;
-       int ret;
-       if ((b=BIO_new(BIO_s_file())) == NULL)
-               {
-               ECerr(EC_F_ECPARAMETERS_PRINT_FP, ERR_R_BIO_LIB);
-               return(0);
-               }
-       BIO_set_fp(b, fp, BIO_NOCLOSE);
-       ret = ECParameters_print(b, x);
-       BIO_free(b);
-       return(ret);
-       }
-#endif
-
-int ECParameters_print(BIO *bp, const EC_KEY *x)
-       {
-       int     reason=ERR_R_EC_LIB, ret=0;
-       BIGNUM  *order=NULL;
-       const EC_GROUP *group;
-       if (x == NULL || (group = EC_KEY_get0_group(x)) == NULL)
-               {
-               reason = ERR_R_PASSED_NULL_PARAMETER;;
-               goto err;
-               }
-
-       if ((order = BN_new()) == NULL)
-               {
-               reason = ERR_R_MALLOC_FAILURE;
-               goto err;
-               }
-
-       if (!EC_GROUP_get_order(group, order, NULL))
-               {
-               reason = ERR_R_EC_LIB;
-               goto err;
-               }
-       if (BIO_printf(bp, "ECDSA-Parameters: (%d bit)\n", 
-               BN_num_bits(order)) <= 0)
-               goto err;
-       if (!ECPKParameters_print(bp, group, 4))
-               goto err;
-       ret=1;
-err:
-       if (order)
-               BN_free(order);
-       ECerr(EC_F_ECPARAMETERS_PRINT, reason);
-       return(ret);
-       }
-  
-#endif
index 5557e06..ea1794e 100644 (file)
@@ -149,34 +149,10 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long
                        ERR_print_errors(bp);
                        }
                else
-#ifndef OPENSSL_NO_RSA
-               if (pkey->type == EVP_PKEY_RSA)
-                       {
-                       BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","",
-                       BN_num_bits(pkey->pkey.rsa->n));
-                       RSA_print(bp,pkey->pkey.rsa,16);
-                       }
-               else
-#endif
-#ifndef OPENSSL_NO_DSA
-               if (pkey->type == EVP_PKEY_DSA)
                        {
-                       BIO_printf(bp,"%12sDSA Public Key:\n","");
-                       DSA_print(bp,pkey->pkey.dsa,16);
+                       EVP_PKEY_print_public(bp, pkey, 16, NULL);
+                       EVP_PKEY_free(pkey);
                        }
-               else
-#endif
-#ifndef OPENSSL_NO_EC
-               if (pkey->type == EVP_PKEY_EC)
-               {
-                       BIO_printf(bp, "%12sEC Public Key: \n","");
-                       EC_KEY_print(bp, pkey->pkey.ec, 16);
-               }
-       else
-#endif
-                       BIO_printf(bp,"%12sUnknown Public Key:\n","");
-
-               EVP_PKEY_free(pkey);
                }
 
        if(!(cflag & X509_FLAG_NO_ATTRIBUTES))
index a73369b..079c081 100644 (file)
@@ -82,36 +82,11 @@ int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki)
                                (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
        pkey = X509_PUBKEY_get(spki->spkac->pubkey);
        if(!pkey) BIO_printf(out, "  Unable to load public key\n");
-       else {
-#ifndef OPENSSL_NO_RSA
-               if (pkey->type == EVP_PKEY_RSA)
-                       {
-                       BIO_printf(out,"  RSA Public Key: (%d bit)\n",
-                               BN_num_bits(pkey->pkey.rsa->n));
-                       RSA_print(out,pkey->pkey.rsa,2);
-                       }
-               else 
-#endif
-#ifndef OPENSSL_NO_DSA
-               if (pkey->type == EVP_PKEY_DSA)
-               {
-               BIO_printf(out,"  DSA Public Key:\n");
-               DSA_print(out,pkey->pkey.dsa,2);
-               }
-               else
-#endif
-#ifndef OPENSSL_NO_EC
-               if (pkey->type == EVP_PKEY_EC)
+       else
                {
-                       BIO_printf(out, "  EC Public Key:\n");
-                       EC_KEY_print(out, pkey->pkey.ec,2);
-               }
-               else
-#endif
-
-                       BIO_printf(out,"  Unknown Public Key:\n");
+               EVP_PKEY_print_public(out, pkey, 4, NULL);
                EVP_PKEY_free(pkey);
-       }
+               }
        chal = spki->spkac->challenge;
        if(chal->length)
                BIO_printf(out, "  Challenge String: %s\n", chal->data);
index 6f295b4..e061f2f 100644 (file)
@@ -111,7 +111,6 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag)
        ASN1_INTEGER *bs;
        EVP_PKEY *pkey=NULL;
        const char *neg;
-       ASN1_STRING *str=NULL;
 
        if((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) {
                        mlch = '\n';
@@ -215,34 +214,10 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag)
                        ERR_print_errors(bp);
                        }
                else
-#ifndef OPENSSL_NO_RSA
-               if (pkey->type == EVP_PKEY_RSA)
-                       {
-                       BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","",
-                       BN_num_bits(pkey->pkey.rsa->n));
-                       RSA_print(bp,pkey->pkey.rsa,16);
-                       }
-               else
-#endif
-#ifndef OPENSSL_NO_DSA
-               if (pkey->type == EVP_PKEY_DSA)
-                       {
-                       BIO_printf(bp,"%12sDSA Public Key:\n","");
-                       DSA_print(bp,pkey->pkey.dsa,16);
-                       }
-               else
-#endif
-#ifndef OPENSSL_NO_EC
-               if (pkey->type == EVP_PKEY_EC)
                        {
-                       BIO_printf(bp, "%12sEC Public Key:\n","");
-                       EC_KEY_print(bp, pkey->pkey.ec, 16);
+                       EVP_PKEY_print_public(bp, pkey, 16, NULL);
+                       EVP_PKEY_free(pkey);
                        }
-               else
-#endif
-                       BIO_printf(bp,"%12sUnknown Public Key:\n","");
-
-               EVP_PKEY_free(pkey);
                }
 
        if (!(cflag & X509_FLAG_NO_EXTENSIONS))
@@ -259,7 +234,6 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag)
                }
        ret=1;
 err:
-       if (str != NULL) ASN1_STRING_free(str);
        if (m != NULL) OPENSSL_free(m);
        return(ret);
        }
@@ -329,14 +303,15 @@ int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig)
        return 1;
 }
 
-int ASN1_STRING_print(BIO *bp, ASN1_STRING *v)
+int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v)
        {
        int i,n;
-       char buf[80],*p;
+       char buf[80];
+       const char *p;
 
        if (v == NULL) return(0);
        n=0;
-       p=(char *)v->data;
+       p=(const char *)v->data;
        for (i=0; i<v->length; i++)
                {
                if ((p[i] > '~') || ((p[i] < ' ') &&
@@ -358,7 +333,7 @@ int ASN1_STRING_print(BIO *bp, ASN1_STRING *v)
        return(1);
        }
 
-int ASN1_TIME_print(BIO *bp, ASN1_TIME *tm)
+int ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm)
 {
        if(tm->type == V_ASN1_UTCTIME) return ASN1_UTCTIME_print(bp, tm);
        if(tm->type == V_ASN1_GENERALIZEDTIME)
@@ -373,7 +348,7 @@ static const char *mon[12]=
     "Jul","Aug","Sep","Oct","Nov","Dec"
     };
 
-int ASN1_GENERALIZEDTIME_print(BIO *bp, ASN1_GENERALIZEDTIME *tm)
+int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm)
        {
        char *v;
        int gmt=0;
@@ -421,15 +396,15 @@ err:
        return(0);
        }
 
-int ASN1_UTCTIME_print(BIO *bp, ASN1_UTCTIME *tm)
+int ASN1_UTCTIME_print(BIO *bp, const ASN1_UTCTIME *tm)
        {
-       char *v;
+       const char *v;
        int gmt=0;
        int i;
        int y=0,M=0,d=0,h=0,m=0,s=0;
 
        i=tm->length;
-       v=(char *)tm->data;
+       v=(const char *)tm->data;
 
        if (i < 10) goto err;
        if (v[i-1] == 'Z') gmt=1;
index a228c0d..87d7dfd 100644 (file)
@@ -114,6 +114,8 @@ unsigned long ASN1_tag2bit(int tag)
 /* Macro to initialize and invalidate the cache */
 
 #define asn1_tlc_clear(c)      if (c) (c)->valid = 0
+/* Version to avoid compiler warning about 'c' always non-NULL */
+#define asn1_tlc_clear_nc(c)   (c)->valid = 0
 
 /* Decode an ASN1 item, this currently behaves just 
  * like a standard 'd2i' function. 'in' points to 
@@ -130,7 +132,7 @@ ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval,
        ASN1_VALUE *ptmpval = NULL;
        if (!pval)
                pval = &ptmpval;
-       c.valid = 0;
+       asn1_tlc_clear_nc(&c);
        if (ASN1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c) > 0) 
                return *pval;
        return NULL;
@@ -140,7 +142,7 @@ int ASN1_template_d2i(ASN1_VALUE **pval,
                const unsigned char **in, long len, const ASN1_TEMPLATE *tt)
        {
        ASN1_TLC c;
-       c.valid = 0;
+       asn1_tlc_clear_nc(&c);
        return asn1_template_ex_d2i(pval, in, len, tt, 0, &c);
        }
 
@@ -306,7 +308,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
 
 
                case ASN1_ITYPE_CHOICE:
-               if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it))
+               if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
                                goto auxerr;
 
                /* Allocate structure */
@@ -355,7 +357,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
 
                asn1_set_choice_selector(pval, i, it);
                *in = p;
-               if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it))
+               if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL))
                                goto auxerr;
                return 1;
 
@@ -402,7 +404,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                        goto err;
                        }
 
-               if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it))
+               if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
                                goto auxerr;
 
                /* Get each field entry */
@@ -504,7 +506,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                if (!asn1_enc_save(pval, *in, p - *in, it))
                        goto auxerr;
                *in = p;
-               if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it))
+               if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL))
                                goto auxerr;
                return 1;
 
@@ -664,11 +666,12 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
                else
                        {
                        /* We've got a valid STACK: free up any items present */
-                       STACK *sktmp = (STACK *)*val;
+                       STACK_OF(ASN1_VALUE) *sktmp
+                           = (STACK_OF(ASN1_VALUE) *)*val;
                        ASN1_VALUE *vtmp;
-                       while(sk_num(sktmp) > 0)
+                       while(sk_ASN1_VALUE_num(sktmp) > 0)
                                {
-                               vtmp = (ASN1_VALUE *)sk_pop(sktmp);
+                               vtmp = sk_ASN1_VALUE_pop(sktmp);
                                ASN1_item_ex_free(&vtmp,
                                                ASN1_ITEM_ptr(tt->item));
                                }
@@ -709,7 +712,8 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
                                goto err;
                                }
                        len -= p - q;
-                       if (!sk_push((STACK *)*val, (char *)skfield))
+                       if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val,
+                                               skfield))
                                {
                                ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
                                                ERR_R_MALLOC_FAILURE);
index 2721f90..936ad1f 100644 (file)
@@ -158,7 +158,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                return asn1_i2d_ex_primitive(pval, out, it, -1, aclass);
 
                case ASN1_ITYPE_CHOICE:
-               if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it))
+               if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
                                return 0;
                i = asn1_get_choice_selector(pval, it);
                if ((i >= 0) && (i < it->tcount))
@@ -171,7 +171,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                                                                -1, aclass);
                        }
                /* Fixme: error condition if selector out of range */
-               if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it))
+               if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL))
                                return 0;
                break;
 
@@ -216,7 +216,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                        aclass = (aclass & ~ASN1_TFLG_TAG_CLASS)
                                        | V_ASN1_UNIVERSAL;
                        }
-               if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it))
+               if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
                                return 0;
                /* First work out sequence content length */
                for (i = 0, tt = it->templates; i < it->tcount; tt++, i++)
@@ -250,7 +250,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                        }
                if (ndef == 2)
                        ASN1_put_eoc(out);
-               if (asn1_cb  && !asn1_cb(ASN1_OP_I2D_POST, pval, it))
+               if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL))
                                return 0;
                return seqlen;
 
@@ -569,7 +569,8 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
        ASN1_STRING *strtmp;
        ASN1_OBJECT *otmp;
        int utype;
-       unsigned char *cont, c;
+       const unsigned char *cont;
+       unsigned char c;
        int len;
        const ASN1_PRIMITIVE_FUNCS *pf;
        pf = it->funcs;
index d7c017f..77d3092 100644 (file)
@@ -110,7 +110,7 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c
                case ASN1_ITYPE_CHOICE:
                if (asn1_cb)
                        {
-                       i = asn1_cb(ASN1_OP_FREE_PRE, pval, it);
+                       i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL);
                        if (i == 2)
                                return;
                        }
@@ -123,7 +123,7 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c
                        ASN1_template_free(pchval, tt);
                        }
                if (asn1_cb)
-                       asn1_cb(ASN1_OP_FREE_POST, pval, it);
+                       asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL);
                if (!combine)
                        {
                        OPENSSL_free(*pval);
@@ -149,7 +149,7 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c
                        return;
                if (asn1_cb)
                        {
-                       i = asn1_cb(ASN1_OP_FREE_PRE, pval, it);
+                       i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL);
                        if (i == 2)
                                return;
                        }               
@@ -170,7 +170,7 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c
                        ASN1_template_free(pseqval, seqtt);
                        }
                if (asn1_cb)
-                       asn1_cb(ASN1_OP_FREE_POST, pval, it);
+                       asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL);
                if (!combine)
                        {
                        OPENSSL_free(*pval);
index 5c6a2eb..0d9e78c 100644 (file)
@@ -68,7 +68,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
                                                                int combine);
 static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
 static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
-void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
+static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
 
 ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it)
        {
@@ -146,7 +146,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
                case ASN1_ITYPE_CHOICE:
                if (asn1_cb)
                        {
-                       i = asn1_cb(ASN1_OP_NEW_PRE, pval, it);
+                       i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL);
                        if (!i)
                                goto auxerr;
                        if (i==2)
@@ -166,7 +166,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
                        memset(*pval, 0, it->size);
                        }
                asn1_set_choice_selector(pval, -1, it);
-               if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it))
+               if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL))
                                goto auxerr;
                break;
 
@@ -174,7 +174,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
                case ASN1_ITYPE_SEQUENCE:
                if (asn1_cb)
                        {
-                       i = asn1_cb(ASN1_OP_NEW_PRE, pval, it);
+                       i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL);
                        if (!i)
                                goto auxerr;
                        if (i==2)
@@ -201,7 +201,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
                        if (!ASN1_template_new(pseqval, tt))
                                goto memerr;
                        }
-               if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it))
+               if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL))
                                goto auxerr;
                break;
        }
@@ -325,6 +325,7 @@ static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
 int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
        {
        ASN1_TYPE *typ;
+       ASN1_STRING *str;
        int utype;
 
        if (it && it->funcs)
@@ -345,10 +346,7 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
                return 1;
 
                case V_ASN1_BOOLEAN:
-               if (it)
-                       *(ASN1_BOOLEAN *)pval = it->size;
-               else
-                       *(ASN1_BOOLEAN *)pval = -1;
+               *(ASN1_BOOLEAN *)pval = it->size;
                return 1;
 
                case V_ASN1_NULL:
@@ -365,7 +363,10 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
                break;
 
                default:
-               *pval = (ASN1_VALUE *)ASN1_STRING_type_new(utype);
+               str = ASN1_STRING_type_new(utype);
+               if (it->itype == ASN1_ITYPE_MSTRING && str)
+                       str->flags |= ASN1_STRING_FLAG_MSTRING;
+               *pval = (ASN1_VALUE *)str;
                break;
                }
        if (*pval)
@@ -373,7 +374,7 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
        return 0;
        }
 
-void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
+static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
        {
        int utype;
        if (it && it->funcs)
index b9c96a6..4536980 100644 (file)
@@ -3,7 +3,7 @@
  * project 2000.
  */
 /* ====================================================================
- * Copyright (c) 2000 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 2000,2005 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 
 #include <stddef.h>
+#include "cryptlib.h"
 #include <openssl/asn1.h>
+#include <openssl/asn1t.h>
 #include <openssl/objects.h>
 #include <openssl/buffer.h>
 #include <openssl/err.h>
-#include <openssl/nasn.h>
+#include <openssl/x509v3.h>
+#include "asn1_locl.h"
 
-/* Print routines. Print out a whole structure from a template.
+/* Print routines.
  */
 
-static int asn1_item_print_nm(BIO *out, void *fld, int indent, const ASN1_ITEM *it, const char *name);
+/* ASN1_PCTX routines */
 
-int ASN1_item_print(BIO *out, void *fld, int indent, const ASN1_ITEM *it)
-{
-       return asn1_item_print_nm(out, fld, indent, it, it->sname);
-}
+ASN1_PCTX default_pctx = 
+       {
+       ASN1_PCTX_FLAGS_SHOW_ABSENT,    /* flags */
+       0,      /* nm_flags */
+       0,      /* cert_flags */
+       0,      /* oid_flags */
+       0       /* str_flags */
+       };
+       
 
-static int asn1_item_print_nm(BIO *out, void *fld, int indent, const ASN1_ITEM *it, const char *name)
-{
-       ASN1_STRING *str;
+ASN1_PCTX *ASN1_PCTX_new(void)
+       {
+       ASN1_PCTX *ret;
+       ret = OPENSSL_malloc(sizeof(ASN1_PCTX));
+       if (ret == NULL)
+               {
+               ASN1err(ASN1_F_ASN1_PCTX_NEW, ERR_R_MALLOC_FAILURE);
+               return NULL;
+               }
+       ret->flags = 0;
+       ret->nm_flags = 0;
+       ret->cert_flags = 0;
+       ret->oid_flags = 0;
+       ret->str_flags = 0;
+       return ret;
+       }
+
+void ASN1_PCTX_free(ASN1_PCTX *p)
+       {
+       OPENSSL_free(p);
+       }
+
+unsigned long ASN1_PCTX_get_flags(ASN1_PCTX *p)
+       {
+       return p->flags;
+       }
+
+void ASN1_PCTX_set_flags(ASN1_PCTX *p, unsigned long flags)
+       {
+       p->flags = flags;
+       }
+
+unsigned long ASN1_PCTX_get_nm_flags(ASN1_PCTX *p)
+       {
+       return p->nm_flags;
+       }
+
+void ASN1_PCTX_set_nm_flags(ASN1_PCTX *p, unsigned long flags)
+       {
+       p->nm_flags = flags;
+       }
+
+unsigned long ASN1_PCTX_get_cert_flags(ASN1_PCTX *p)
+       {
+       return p->cert_flags;
+       }
+
+void ASN1_PCTX_set_cert_flags(ASN1_PCTX *p, unsigned long flags)
+       {
+       p->cert_flags = flags;
+       }
+
+unsigned long ASN1_PCTX_get_oid_flags(ASN1_PCTX *p)
+       {
+       return p->oid_flags;
+       }
+
+void ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags)
+       {
+       p->oid_flags = flags;
+       }
+
+unsigned long ASN1_PCTX_get_str_flags(ASN1_PCTX *p)
+       {
+       return p->str_flags;
+       }
+
+void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags)
+       {
+       p->str_flags = flags;
+       }
+
+/* Main print routines */
+
+static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
+                               const ASN1_ITEM *it,
+                               const char *fname, const char *sname,
+                               int nohdr, const ASN1_PCTX *pctx);
+
+int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
+                               const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx);
+
+static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
+                               const ASN1_ITEM *it, int indent,
+                               const char *fname, const char *sname,
+                               const ASN1_PCTX *pctx);
+
+static int asn1_print_fsname(BIO *out, int indent,
+                       const char *fname, const char *sname,
+                       const ASN1_PCTX *pctx);
+
+int ASN1_item_print(BIO *out, ASN1_VALUE *ifld, int indent,
+                               const ASN1_ITEM *it, const ASN1_PCTX *pctx)
+       {
+       const char *sname;
+       if (pctx == NULL)
+               pctx = &default_pctx;
+       if (pctx->flags & ASN1_PCTX_FLAGS_NO_STRUCT_NAME)
+               sname = NULL;
+       else
+               sname = it->sname;
+       return asn1_item_print_ctx(out, &ifld, indent, it,
+                                                       NULL, sname, 0, pctx);
+       }
+
+static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
+                               const ASN1_ITEM *it,
+                               const char *fname, const char *sname,
+                               int nohdr, const ASN1_PCTX *pctx)
+       {
        const ASN1_TEMPLATE *tt;
-       void *tmpfld;
+       const ASN1_EXTERN_FUNCS *ef;
+       ASN1_VALUE **tmpfld;
+       const ASN1_AUX *aux = it->funcs;
+       ASN1_aux_cb *asn1_cb;
+       ASN1_PRINT_ARG parg;
        int i;
-       if(!fld) {
-               BIO_printf(out, "%*s%s ABSENT\n", indent, "", name);
+       if (aux && aux->asn1_cb)
+               {
+               parg.out = out;
+               parg.indent = indent;
+               parg.pctx = pctx;
+               asn1_cb = aux->asn1_cb;
+               }
+       else asn1_cb = 0;
+
+       if(*fld == NULL)
+               {
+               if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_ABSENT)
+                       {
+                       if (!nohdr && !asn1_print_fsname(out, indent,
+                                                       fname, sname, pctx))
+                               return 0;
+                       if (BIO_puts(out, "<ABSENT>\n") <= 0)
+                               return 0;
+                       }
                return 1;
-       }
-       switch(it->itype) {
+               }
 
+       switch(it->itype)
+               {
                case ASN1_ITYPE_PRIMITIVE:
                if(it->templates)
-                       return ASN1_template_print(out, fld, indent, it->templates);
-               return asn1_primitive_print(out, fld, it->utype, indent, name);
-               break;
-
+                       {
+                       if (!asn1_template_print_ctx(out, fld, indent,
+                                                       it->templates, pctx))
+                               return 0;
+                       }
+               /* fall thru */
                case ASN1_ITYPE_MSTRING:
-               str = fld;
-               return asn1_primitive_print(out, fld, str->type, indent, name);
+               if (!asn1_primitive_print(out, fld, it,
+                               indent, fname, sname,pctx))
+                       return 0;
+               break;
 
                case ASN1_ITYPE_EXTERN:
-               BIO_printf(out, "%*s%s:EXTERNAL TYPE %s %s\n", indent, "", name, it->sname, fld ? "" : "ABSENT");
-               return 1;
-               case ASN1_ITYPE_COMPAT:
-               BIO_printf(out, "%*s%s:COMPATIBLE TYPE %s %s\n", indent, "", name, it->sname, fld ? "" : "ABSENT");
-               return 1;
-
+               if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx))
+                       return 0;
+               /* Use new style print routine if possible */
+               ef = it->funcs;
+               if (ef && ef->asn1_ex_print)
+                       {
+                       i = ef->asn1_ex_print(out, fld, indent, "", pctx);
+                       if (!i)
+                               return 0;
+                       if ((i == 2) && (BIO_puts(out, "\n") <= 0))
+                               return 0;
+                       return 1;
+                       }
+               else if (sname && 
+                       BIO_printf(out, ":EXTERNAL TYPE %s\n", sname) <= 0)
+                       return 0;
+               break;
 
                case ASN1_ITYPE_CHOICE:
+#if 0
+               if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx))
+                       return 0;
+#endif
                /* CHOICE type, get selector */
                i = asn1_get_choice_selector(fld, it);
                /* This should never happen... */
-               if((i < 0) || (i >= it->tcount)) {
-                       BIO_printf(out, "%s selector [%d] out of range\n", it->sname, i);
+               if((i < 0) || (i >= it->tcount))
+                       {
+                       if (BIO_printf(out,
+                               "ERROR: selector [%d] invalid\n", i) <= 0)
+                               return 0;
                        return 1;
-               }
+                       }
                tt = it->templates + i;
-               tmpfld = asn1_get_field(fld, tt);
-               return ASN1_template_print(out, tmpfld, indent, tt);
+               tmpfld = asn1_get_field_ptr(fld, tt);
+               if (!asn1_template_print_ctx(out, tmpfld, indent, tt, pctx))
+                       return 0;
+               break;
 
                case ASN1_ITYPE_SEQUENCE:
-               BIO_printf(out, "%*s%s {\n", indent, "", name);
-               /* Get each field entry */
-               for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
-                       tmpfld = asn1_get_field(fld, tt);
-                       ASN1_template_print(out, tmpfld, indent + 2, tt);
-               }
-               BIO_printf(out, "%*s}\n", indent, "");
-               return 1;
+               case ASN1_ITYPE_NDEF_SEQUENCE:
+               if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx))
+                       return 0;
+               if (fname || sname)
+                       {
+                       if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE)
+                               {
+                               if (BIO_puts(out, " {\n") <= 0)
+                                       return 0;
+                               }
+                       else
+                               {
+                               if (BIO_puts(out, "\n") <= 0)
+                                       return 0;
+                               }
+                       }
+
+               if (asn1_cb)
+                       {
+                       i = asn1_cb(ASN1_OP_PRINT_PRE, fld, it, &parg);
+                       if (i == 0)
+                               return 0;
+                       if (i == 2)
+                               return 1;
+                       }
+
+               /* Print each field entry */
+               for(i = 0, tt = it->templates; i < it->tcount; i++, tt++)
+                       {
+                       const ASN1_TEMPLATE *seqtt;
+                       seqtt = asn1_do_adb(fld, tt, 1);
+                       tmpfld = asn1_get_field_ptr(fld, seqtt);
+                       if (!asn1_template_print_ctx(out, tmpfld,
+                                               indent + 2, seqtt, pctx))
+                               return 0;
+                       }
+               if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE)
+                       {
+                       if (BIO_printf(out, "%*s}\n", indent, "") < 0)
+                               return 0;
+                       }
+
+               if (asn1_cb)
+                       {
+                       i = asn1_cb(ASN1_OP_PRINT_POST, fld, it, &parg);
+                       if (i == 0)
+                               return 0;
+                       }
+               break;
 
                default:
+               BIO_printf(out, "Unprocessed type %d\n", it->itype);
                return 0;
+               }
+
+       return 1;
        }
-}
 
-int ASN1_template_print(BIO *out, void *fld, int indent, const ASN1_TEMPLATE *tt)
-{
+int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
+                               const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx)
+       {
        int i, flags;
-#if 0
-       if(!fld) return 0; 
-#endif
+       const char *sname, *fname;
        flags = tt->flags;
-       if(flags & ASN1_TFLG_SK_MASK) {
+       if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME)
+               sname = ASN1_ITEM_ptr(tt->item)->sname;
+       else
+               sname = NULL;
+       if(pctx->flags & ASN1_PCTX_FLAGS_NO_FIELD_NAME)
+               fname = NULL;
+       else
+               fname = tt->field_name;
+       if(flags & ASN1_TFLG_SK_MASK)
+               {
                char *tname;
-               void *skitem;
+               ASN1_VALUE *skitem;
+               STACK_OF(ASN1_VALUE) *stack;
+
                /* SET OF, SEQUENCE OF */
-               if(flags & ASN1_TFLG_SET_OF) tname = "SET";
-               else tname = "SEQUENCE";
-               if(fld) {
-                       BIO_printf(out, "%*s%s OF %s {\n", indent, "", tname, tt->field_name);
-                       for(i = 0; i < sk_num(fld); i++) {
-                               skitem = sk_value(fld, i);
-                               asn1_item_print_nm(out, skitem, indent + 2, tt->item, "");
+               if (fname)
+                       {
+                       if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SSOF)
+                               {
+                               if(flags & ASN1_TFLG_SET_OF)
+                                       tname = "SET";
+                               else
+                                       tname = "SEQUENCE";
+                               if (BIO_printf(out, "%*s%s OF %s {\n",
+                                       indent, "", tname, tt->field_name) <= 0)
+                                       return 0;
+                               }
+                       else if (BIO_printf(out, "%*s%s:\n", indent, "",
+                                       fname) <= 0)
+                               return 0;
+                       }
+               stack = (STACK_OF(ASN1_VALUE) *)*fld;
+               for(i = 0; i < sk_ASN1_VALUE_num(stack); i++)
+                       {
+                       if ((i > 0) && (BIO_puts(out, "\n") <= 0))
+                               return 0;
+
+                       skitem = sk_ASN1_VALUE_value(stack, i);
+                       if (!asn1_item_print_ctx(out, &skitem, indent + 2,
+                               ASN1_ITEM_ptr(tt->item), NULL, NULL, 1, pctx))
+                               return 0;
+                       }
+               if (!i && BIO_printf(out, "%*s<EMPTY>\n", indent + 2, "") <= 0)
+                               return 0;
+               if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE)
+                       {
+                       if (BIO_printf(out, "%*s}\n", indent, "") <= 0)
+                               return 0;
                        }
-                       BIO_printf(out, "%*s}\n", indent, "");
-               } else 
-                       BIO_printf(out, "%*s%s OF %s ABSENT\n", indent, "", tname, tt->field_name);
                return 1;
+               }
+       return asn1_item_print_ctx(out, fld, indent, ASN1_ITEM_ptr(tt->item),
+                                                       fname, sname, 0, pctx);
        }
-       return asn1_item_print_nm(out, fld, indent, tt->item, tt->field_name);
-}
-
-static int asn1_primitive_print(BIO *out, void *fld, long utype, int indent, const char *name)
-{
-       ASN1_STRING *str = fld;
-       if(fld) {
-               if(utype == V_ASN1_BOOLEAN) {
-                       int *bool = fld;
-if(*bool == -1) printf("BOOL MISSING\n");
-                       BIO_printf(out, "%*s%s:%s", indent, "", "BOOLEAN", *bool ? "TRUE" : "FALSE");
-               } else if((utype == V_ASN1_INTEGER) 
-                         || (utype == V_ASN1_ENUMERATED)) {
-                       char *s, *nm;
-                       s = i2s_ASN1_INTEGER(NULL, fld);
-                       if(utype == V_ASN1_INTEGER) nm = "INTEGER";
-                       else nm = "ENUMERATED";
-                       BIO_printf(out, "%*s%s:%s", indent, "", nm, s);
-                       OPENSSL_free(s);
-               } else if(utype == V_ASN1_NULL) {
-                       BIO_printf(out, "%*s%s", indent, "", "NULL");
-               } else if(utype == V_ASN1_UTCTIME) {
-                       BIO_printf(out, "%*s%s:%s:", indent, "", name, "UTCTIME");
-                       ASN1_UTCTIME_print(out, str);
-               } else if(utype == V_ASN1_GENERALIZEDTIME) {
-                       BIO_printf(out, "%*s%s:%s:", indent, "", name, "GENERALIZEDTIME");
-                       ASN1_GENERALIZEDTIME_print(out, str);
-               } else if(utype == V_ASN1_OBJECT) {
-                       char objbuf[80], *ln;
-                       ln = OBJ_nid2ln(OBJ_obj2nid(fld));
-                       if(!ln) ln = "";
-                       OBJ_obj2txt(objbuf, sizeof objbuf, fld, 1);
-                       BIO_printf(out, "%*s%s:%s (%s)", indent, "", "OBJECT", ln, objbuf);
-               } else {
-                       BIO_printf(out, "%*s%s:", indent, "", name);
-                       ASN1_STRING_print_ex(out, str, ASN1_STRFLGS_DUMP_UNKNOWN|ASN1_STRFLGS_SHOW_TYPE);
+
+static int asn1_print_fsname(BIO *out, int indent,
+                       const char *fname, const char *sname,
+                       const ASN1_PCTX *pctx)
+       {
+       static char spaces[] = "                    ";
+       const int nspaces = sizeof(spaces) - 1;
+
+#if 0
+       if (!sname && !fname)
+               return 1;
+#endif
+
+       while (indent > nspaces)
+               {
+               if (BIO_write(out, spaces, nspaces) != nspaces)
+                       return 0;
+               indent -= nspaces;
+               }
+       if (BIO_write(out, spaces, indent) != indent)
+               return 0;
+       if (pctx->flags & ASN1_PCTX_FLAGS_NO_STRUCT_NAME)
+               sname = NULL;
+       if (pctx->flags & ASN1_PCTX_FLAGS_NO_FIELD_NAME)
+               fname = NULL;
+       if (!sname && !fname)
+               return 1;
+       if (fname)
+               {
+               if (BIO_puts(out, fname) <= 0)
+                       return 0;
                }
-               BIO_printf(out, "\n");
-       } else BIO_printf(out, "%*s%s [ABSENT]\n", indent, "", name);
+       if (sname)
+               {
+               if (fname)
+                       {
+                       if (BIO_printf(out, " (%s)", sname) <= 0)
+                               return 0;
+                       }
+               else
+                       {
+                       if (BIO_puts(out, sname) <= 0)
+                               return 0;
+                       }
+               }
+       if (BIO_write(out, ": ", 2) != 2)
+               return 0;
        return 1;
-}
+       }
+
+static int asn1_print_boolean_ctx(BIO *out, const int bool,
+                                                       const ASN1_PCTX *pctx)
+       {
+       const char *str;
+       switch (bool)
+               {
+               case -1:
+               str = "BOOL ABSENT";
+               break;
+
+               case 0:
+               str = "FALSE";
+               break;
+
+               default:
+               str = "TRUE";
+               break;
+
+               }
+
+       if (BIO_puts(out, str) <= 0)
+               return 0;
+       return 1;
+
+       }
+
+static int asn1_print_integer_ctx(BIO *out, ASN1_INTEGER *str,
+                                               const ASN1_PCTX *pctx)
+       {
+       char *s;
+       int ret = 1;
+       s = i2s_ASN1_INTEGER(NULL, str);
+       if (BIO_puts(out, s) <= 0)
+               ret = 0;
+       OPENSSL_free(s);
+       return ret;
+       }
+
+static int asn1_print_oid_ctx(BIO *out, const ASN1_OBJECT *oid,
+                                               const ASN1_PCTX *pctx)
+       {
+       char objbuf[80];
+       const char *ln;
+       ln = OBJ_nid2ln(OBJ_obj2nid(oid));
+       if(!ln)
+               ln = "";
+       OBJ_obj2txt(objbuf, sizeof objbuf, oid, 1);
+       if (BIO_printf(out, "%s (%s)", ln, objbuf) <= 0)
+               return 0;
+       return 1;
+       }
+
+static int asn1_print_obstring_ctx(BIO *out, ASN1_STRING *str, int indent,
+                                               const ASN1_PCTX *pctx)
+       {
+       if (str->type == V_ASN1_BIT_STRING)
+               {
+               if (BIO_printf(out, " (%ld unused bits)\n",
+                                       str->flags & 0x7) <= 0)
+                               return 0;
+               }
+       else if (BIO_puts(out, "\n") <= 0)
+               return 0;
+       if ((str->length > 0)
+               && BIO_dump_indent(out, (char *)str->data, str->length,
+                               indent + 2) <= 0)
+               return 0;
+       return 1;
+       }
+
+static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
+                               const ASN1_ITEM *it, int indent,
+                               const char *fname, const char *sname,
+                               const ASN1_PCTX *pctx)
+       {
+       long utype;
+       ASN1_STRING *str;
+       int ret = 1, needlf = 1;
+       const char *pname;
+       const ASN1_PRIMITIVE_FUNCS *pf;
+       pf = it->funcs;
+       if (!asn1_print_fsname(out, indent, fname, sname, pctx))
+                       return 0;
+       if (pf && pf->prim_print)
+               return pf->prim_print(out, fld, it, indent, pctx);
+       str = (ASN1_STRING *)*fld;
+       if (it->itype == ASN1_ITYPE_MSTRING)
+               utype = str->type & ~V_ASN1_NEG;
+       else
+               utype = it->utype;
+       if (utype == V_ASN1_ANY)
+               {
+               ASN1_TYPE *atype = (ASN1_TYPE *)*fld;
+               utype = atype->type;
+               fld = &atype->value.asn1_value;
+               str = (ASN1_STRING *)*fld;
+               if (pctx->flags & ASN1_PCTX_FLAGS_NO_ANY_TYPE)
+                       pname = NULL;
+               else 
+                       pname = ASN1_tag2str(utype);
+               }
+       else
+               {
+               if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_TYPE)
+                       pname = ASN1_tag2str(utype);
+               else 
+                       pname = NULL;
+               }
+
+       if (utype == V_ASN1_NULL)
+               {
+               if (BIO_puts(out, "NULL\n") <= 0)
+                       return 0;
+               return 1;
+               }
+
+       if (pname)
+               {
+               if (BIO_puts(out, pname) <= 0)
+                       return 0;
+               if (BIO_puts(out, ":") <= 0)
+                       return 0;
+               }
+
+       switch (utype)
+               {
+               case V_ASN1_BOOLEAN:
+                       {
+                       int bool = *(int *)fld;
+                       if (bool == -1)
+                               bool = it->size;
+                       ret = asn1_print_boolean_ctx(out, bool, pctx);
+                       }
+               break;
+
+               case V_ASN1_INTEGER:
+               case V_ASN1_ENUMERATED:
+               ret = asn1_print_integer_ctx(out, str, pctx);
+               break;
+
+               case V_ASN1_UTCTIME:
+               ret = ASN1_UTCTIME_print(out, str);
+               break;
+
+               case V_ASN1_GENERALIZEDTIME:
+               ret = ASN1_GENERALIZEDTIME_print(out, str);
+               break;
+
+               case V_ASN1_OBJECT:
+               ret = asn1_print_oid_ctx(out, (const ASN1_OBJECT *)*fld, pctx);
+               break;
+
+               case V_ASN1_OCTET_STRING:
+               case V_ASN1_BIT_STRING:
+               ret = asn1_print_obstring_ctx(out, str, indent, pctx);
+               needlf = 0;
+               break;
+
+               case V_ASN1_SEQUENCE:
+               case V_ASN1_SET:
+               case V_ASN1_OTHER:
+               if (BIO_puts(out, "\n") <= 0)
+                       return 0;
+               if (ASN1_parse_dump(out, str->data, str->length,
+                                               indent, 0) <= 0)
+                       ret = 0;
+               needlf = 0;
+               break;
+
+               default:
+               ret = ASN1_STRING_print_ex(out, str, pctx->str_flags);
+
+               }
+       if (!ret)
+               return 0;
+       if (needlf && BIO_puts(out, "\n") <= 0)
+               return 0;
+       return 1;
+       }
index 6252213..6fb1c37 100644 (file)
@@ -135,3 +135,14 @@ IMPLEMENT_ASN1_TYPE_ex(ASN1_FBOOLEAN, ASN1_BOOLEAN, 0)
 /* Special, OCTET STRING with indefinite length constructed support */
 
 IMPLEMENT_ASN1_TYPE_ex(ASN1_OCTET_STRING_NDEF, ASN1_OCTET_STRING, ASN1_TFLG_NDEF)
+
+ASN1_ITEM_TEMPLATE(ASN1_SEQUENCE_ANY) = 
+       ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, ASN1_SEQUENCE_ANY, ASN1_ANY)
+ASN1_ITEM_TEMPLATE_END(ASN1_SEQUENCE_ANY)
+
+ASN1_ITEM_TEMPLATE(ASN1_SET_ANY) = 
+       ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_OF, 0, ASN1_SET_ANY, ASN1_ANY)
+ASN1_ITEM_TEMPLATE_END(ASN1_SET_ANY)
+
+IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(ASN1_SEQUENCE_ANY, ASN1_SEQUENCE_ANY, ASN1_SEQUENCE_ANY)
+IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(ASN1_SEQUENCE_ANY, ASN1_SET_ANY, ASN1_SET_ANY)
index 70d56a6..c51c690 100644 (file)
 
 #include <stdio.h>
 #include "cryptlib.h"
+#include "asn1_locl.h"
 #include <openssl/asn1t.h>
 #include <openssl/x509.h>
+#include <openssl/x509v3.h>
 
 static int X509_REVOKED_cmp(const X509_REVOKED * const *a,
                                const X509_REVOKED * const *b);
+static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp);
 
 ASN1_SEQUENCE(X509_REVOKED) = {
        ASN1_SIMPLE(X509_REVOKED,serialNumber, ASN1_INTEGER),
@@ -70,11 +73,26 @@ ASN1_SEQUENCE(X509_REVOKED) = {
        ASN1_SEQUENCE_OF_OPT(X509_REVOKED,extensions, X509_EXTENSION)
 } ASN1_SEQUENCE_END(X509_REVOKED)
 
+static int def_crl_verify(X509_CRL *crl, EVP_PKEY *r);
+static int def_crl_lookup(X509_CRL *crl,
+               X509_REVOKED **ret, ASN1_INTEGER *serial, X509_NAME *issuer);
+
+static X509_CRL_METHOD int_crl_meth =
+       {
+       0,
+       0,0,
+       def_crl_lookup,
+       def_crl_verify
+       };
+
+static const X509_CRL_METHOD *default_crl_method = &int_crl_meth;
+
 /* The X509_CRL_INFO structure needs a bit of customisation.
  * Since we cache the original encoding the signature wont be affected by
  * reordering of the revoked field.
  */
-static int crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
+static int crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
+                                                               void *exarg)
 {
        X509_CRL_INFO *a = (X509_CRL_INFO *)*pval;
 
@@ -101,7 +119,237 @@ ASN1_SEQUENCE_enc(X509_CRL_INFO, enc, crl_inf_cb) = {
        ASN1_EXP_SEQUENCE_OF_OPT(X509_CRL_INFO, extensions, X509_EXTENSION, 0)
 } ASN1_SEQUENCE_END_enc(X509_CRL_INFO, X509_CRL_INFO)
 
-ASN1_SEQUENCE_ref(X509_CRL, 0, CRYPTO_LOCK_X509_CRL) = {
+/* Set CRL entry issuer according to CRL certificate issuer extension.
+ * Check for unhandled critical CRL entry extensions.
+ */
+
+static int crl_set_issuers(X509_CRL *crl)
+       {
+
+       int i, j;
+       GENERAL_NAMES *gens, *gtmp;
+       STACK_OF(X509_REVOKED) *revoked;
+
+       revoked = X509_CRL_get_REVOKED(crl);
+
+       gens = NULL;
+       for (i = 0; i < sk_X509_REVOKED_num(revoked); i++)
+               {
+               X509_REVOKED *rev = sk_X509_REVOKED_value(revoked, i);
+               STACK_OF(X509_EXTENSION) *exts;
+               ASN1_ENUMERATED *reason;
+               X509_EXTENSION *ext;
+               gtmp = X509_REVOKED_get_ext_d2i(rev, 
+                                               NID_certificate_issuer,
+                                               &j, NULL);
+               if (!gtmp && (j != -1))
+                       {
+                       crl->flags |= EXFLAG_INVALID;
+                       return 1;
+                       }
+
+               if (gtmp)
+                       {
+                       gens = gtmp;
+                       if (!crl->issuers)
+                               {
+                               crl->issuers = sk_GENERAL_NAMES_new_null();
+                               if (!crl->issuers)
+                                       return 0;
+                               }
+                       if (!sk_GENERAL_NAMES_push(crl->issuers, gtmp))
+                               return 0;
+                       }
+               rev->issuer = gens;
+
+               reason = X509_REVOKED_get_ext_d2i(rev, NID_crl_reason,
+                                                               &j, NULL);
+               if (!reason && (j != -1))
+                       {
+                       crl->flags |= EXFLAG_INVALID;
+                       return 1;
+                       }
+
+               if (reason)
+                       {
+                       rev->reason = ASN1_ENUMERATED_get(reason);
+                       ASN1_ENUMERATED_free(reason);
+                       }
+               else
+                       rev->reason = CRL_REASON_NONE;  
+
+               /* Check for critical CRL entry extensions */
+
+               exts = rev->extensions;
+
+               for (j = 0; j < sk_X509_EXTENSION_num(exts); j++)
+                       {
+                       ext = sk_X509_EXTENSION_value(exts, j);
+                       if (ext->critical > 0)
+                               {
+                               if (OBJ_obj2nid(ext->object) ==
+                                       NID_certificate_issuer)
+                                       continue;
+                               crl->flags |= EXFLAG_CRITICAL;
+                               break;
+                               }
+                       }
+
+
+               }
+
+       return 1;
+
+       }
+
+/* The X509_CRL structure needs a bit of customisation. Cache some extensions
+ * and hash of the whole CRL.
+ */
+static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
+                                                               void *exarg)
+       {
+       X509_CRL *crl = (X509_CRL *)*pval;
+       STACK_OF(X509_EXTENSION) *exts;
+       X509_EXTENSION *ext;
+       int idx;
+
+       switch(operation)
+               {
+               case ASN1_OP_NEW_POST:
+               crl->idp = NULL;
+               crl->akid = NULL;
+               crl->flags = 0;
+               crl->idp_flags = 0;
+               crl->idp_reasons = CRLDP_ALL_REASONS;
+               crl->meth = default_crl_method;
+               crl->meth_data = NULL;
+               crl->issuers = NULL;
+               crl->crl_number = NULL;
+               crl->base_crl_number = NULL;
+               break;
+
+               case ASN1_OP_D2I_POST:
+#ifndef OPENSSL_NO_SHA
+               X509_CRL_digest(crl, EVP_sha1(), crl->sha1_hash, NULL);
+#endif
+               crl->idp = X509_CRL_get_ext_d2i(crl,
+                               NID_issuing_distribution_point, NULL, NULL);
+               if (crl->idp)
+                       setup_idp(crl, crl->idp);
+
+               crl->akid = X509_CRL_get_ext_d2i(crl,
+                               NID_authority_key_identifier, NULL, NULL);      
+
+               crl->crl_number = X509_CRL_get_ext_d2i(crl,
+                               NID_crl_number, NULL, NULL);    
+
+               crl->base_crl_number = X509_CRL_get_ext_d2i(crl,
+                               NID_delta_crl, NULL, NULL);     
+               /* Delta CRLs must have CRL number */
+               if (crl->base_crl_number && !crl->crl_number)
+                       crl->flags |= EXFLAG_INVALID;
+
+               /* See if we have any unhandled critical CRL extensions and 
+                * indicate this in a flag. We only currently handle IDP so
+                * anything else critical sets the flag.
+                *
+                * This code accesses the X509_CRL structure directly:
+                * applications shouldn't do this.
+                */
+
+               exts = crl->crl->extensions;
+
+               for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++)
+                       {
+                       int nid;
+                       ext = sk_X509_EXTENSION_value(exts, idx);
+                       nid = OBJ_obj2nid(ext->object);
+                       if (nid == NID_freshest_crl)
+                               crl->flags |= EXFLAG_FRESHEST;
+                       if (ext->critical > 0)
+                               {
+                               /* We handle IDP and deltas */
+                               if ((nid == NID_issuing_distribution_point)
+                                       || (nid == NID_delta_crl))
+                                       break;;
+                               crl->flags |= EXFLAG_CRITICAL;
+                               break;
+                               }
+                       }
+
+
+               if (!crl_set_issuers(crl))
+                       return 0;
+
+               if (crl->meth->crl_init)
+                       {
+                       if (crl->meth->crl_init(crl) == 0)
+                               return 0;
+                       }
+               break;
+
+               case ASN1_OP_FREE_POST:
+               if (crl->meth->crl_free)
+                       {
+                       if (!crl->meth->crl_free(crl))
+                               return 0;
+                       }
+               if (crl->akid)
+                       AUTHORITY_KEYID_free(crl->akid);
+               if (crl->idp)
+                       ISSUING_DIST_POINT_free(crl->idp);
+               ASN1_INTEGER_free(crl->crl_number);
+               ASN1_INTEGER_free(crl->base_crl_number);
+               sk_GENERAL_NAMES_pop_free(crl->issuers, GENERAL_NAMES_free);
+               break;
+               }
+       return 1;
+       }
+
+/* Convert IDP into a more convenient form */
+
+static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp)
+       {
+       int idp_only = 0;
+       /* Set various flags according to IDP */
+       crl->idp_flags |= IDP_PRESENT;
+       if (idp->onlyuser > 0)
+               {
+               idp_only++;
+               crl->idp_flags |= IDP_ONLYUSER;
+               }
+       if (idp->onlyCA > 0)
+               {
+               idp_only++;
+               crl->idp_flags |= IDP_ONLYCA;
+               }
+       if (idp->onlyattr > 0)
+               {
+               idp_only++;
+               crl->idp_flags |= IDP_ONLYATTR;
+               }
+
+       if (idp_only > 1)
+               crl->idp_flags |= IDP_INVALID;
+
+       if (idp->indirectCRL > 0)
+               crl->idp_flags |= IDP_INDIRECT;
+
+       if (idp->onlysomereasons)
+               {
+               crl->idp_flags |= IDP_REASONS;
+               if (idp->onlysomereasons->length > 0)
+                       crl->idp_reasons = idp->onlysomereasons->data[0];
+               if (idp->onlysomereasons->length > 1)
+                       crl->idp_reasons |=
+                               (idp->onlysomereasons->data[1] << 8);
+               crl->idp_reasons &= CRLDP_ALL_REASONS;
+               }
+
+       DIST_POINT_set_dpname(idp->distpoint, X509_CRL_get_issuer(crl));
+       }
+
+ASN1_SEQUENCE_ref(X509_CRL, crl_cb, CRYPTO_LOCK_X509_CRL) = {
        ASN1_SIMPLE(X509_CRL, crl, X509_CRL_INFO),
        ASN1_SIMPLE(X509_CRL, sig_alg, X509_ALGOR),
        ASN1_SIMPLE(X509_CRL, signature, ASN1_BIT_STRING)
@@ -134,6 +382,145 @@ int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev)
        return 1;
 }
 
+int X509_CRL_verify(X509_CRL *crl, EVP_PKEY *r)
+       {
+       if (crl->meth->crl_verify)
+               return crl->meth->crl_verify(crl, r);
+       return 0;
+       }
+
+int X509_CRL_get0_by_serial(X509_CRL *crl,
+               X509_REVOKED **ret, ASN1_INTEGER *serial)
+       {
+       if (crl->meth->crl_lookup)
+               return crl->meth->crl_lookup(crl, ret, serial, NULL);
+       return 0;
+       }
+
+int X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret, X509 *x)
+       {
+       if (crl->meth->crl_lookup)
+               return crl->meth->crl_lookup(crl, ret,
+                                               X509_get_serialNumber(x),
+                                               X509_get_issuer_name(x));
+       return 0;
+       }
+
+static int def_crl_verify(X509_CRL *crl, EVP_PKEY *r)
+       {
+       return(ASN1_item_verify(ASN1_ITEM_rptr(X509_CRL_INFO),
+               crl->sig_alg, crl->signature,crl->crl,r));
+       }
+
+static int crl_revoked_issuer_match(X509_CRL *crl, X509_NAME *nm,
+                                               X509_REVOKED *rev)
+       {
+       int i;
+
+       if (!rev->issuer)
+               {
+               if (!nm)
+                       return 1;
+               if (!X509_NAME_cmp(nm, X509_CRL_get_issuer(crl)))
+                       return 1;
+               return 0;
+               }
+
+       if (!nm)
+               nm = X509_CRL_get_issuer(crl);
+
+       for (i = 0; i < sk_GENERAL_NAME_num(rev->issuer); i++)
+               {
+               GENERAL_NAME *gen = sk_GENERAL_NAME_value(rev->issuer, i);
+               if (gen->type != GEN_DIRNAME)
+                       continue;
+               if (!X509_NAME_cmp(nm, gen->d.directoryName))
+                       return 1;
+               }
+       return 0;
+
+       }
+
+static int def_crl_lookup(X509_CRL *crl,
+               X509_REVOKED **ret, ASN1_INTEGER *serial, X509_NAME *issuer)
+       {
+       X509_REVOKED rtmp, *rev;
+       int idx;
+       rtmp.serialNumber = serial;
+       /* Sort revoked into serial number order if not already sorted.
+        * Do this under a lock to avoid race condition.
+        */
+       if (!sk_X509_REVOKED_is_sorted(crl->crl->revoked))
+               {
+               CRYPTO_w_lock(CRYPTO_LOCK_X509_CRL);
+               sk_X509_REVOKED_sort(crl->crl->revoked);
+               CRYPTO_w_unlock(CRYPTO_LOCK_X509_CRL);
+               }
+       idx = sk_X509_REVOKED_find(crl->crl->revoked, &rtmp);
+       if(idx < 0)
+               return 0;
+       /* Need to look for matching name */
+       for(;idx < sk_X509_REVOKED_num(crl->crl->revoked); idx++)
+               {
+               rev = sk_X509_REVOKED_value(crl->crl->revoked, idx);
+               if (ASN1_INTEGER_cmp(rev->serialNumber, serial))
+                       return 0;
+               if (crl_revoked_issuer_match(crl, issuer, rev))
+                       {
+                       if (ret)
+                               *ret = rev;
+                       if (rev->reason == CRL_REASON_REMOVE_FROM_CRL)
+                               return 2;
+                       return 1;
+                       }
+               }
+       return 0;
+       }
+
+void X509_CRL_set_default_method(const X509_CRL_METHOD *meth)
+       {
+       if (meth == NULL)
+               default_crl_method = &int_crl_meth;
+       else 
+               default_crl_method = meth;
+       }
+
+X509_CRL_METHOD *X509_CRL_METHOD_new(
+       int (*crl_init)(X509_CRL *crl),
+       int (*crl_free)(X509_CRL *crl),
+       int (*crl_lookup)(X509_CRL *crl, X509_REVOKED **ret,
+                               ASN1_INTEGER *ser, X509_NAME *issuer),
+       int (*crl_verify)(X509_CRL *crl, EVP_PKEY *pk))
+       {
+       X509_CRL_METHOD *m;
+       m = OPENSSL_malloc(sizeof(X509_CRL_METHOD));
+       if (!m)
+               return NULL;
+       m->crl_init = crl_init;
+       m->crl_free = crl_free;
+       m->crl_lookup = crl_lookup;
+       m->crl_verify = crl_verify;
+       m->flags = X509_CRL_METHOD_DYNAMIC;
+       return m;
+       }
+
+void X509_CRL_METHOD_free(X509_CRL_METHOD *m)
+       {
+       if (!(m->flags & X509_CRL_METHOD_DYNAMIC))
+               return;
+       OPENSSL_free(m);
+       }
+
+void X509_CRL_set_meth_data(X509_CRL *crl, void *dat)
+       {
+       crl->meth_data = dat;
+       }
+
+void *X509_CRL_get_meth_data(X509_CRL *crl)
+       {
+       return crl->meth_data;
+       }
+
 IMPLEMENT_STACK_OF(X509_REVOKED)
 IMPLEMENT_ASN1_SET_OF(X509_REVOKED)
 IMPLEMENT_STACK_OF(X509_CRL)
index bf35457..7531741 100644 (file)
@@ -71,6 +71,7 @@ static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
 
 static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
 static int long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
+static int long_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it, int indent, const ASN1_PCTX *pctx);
 
 static ASN1_PRIMITIVE_FUNCS long_pf = {
        NULL, 0,
@@ -78,7 +79,8 @@ static ASN1_PRIMITIVE_FUNCS long_pf = {
        long_free,
        long_free,      /* Clear should set to initial value */
        long_c2i,
-       long_i2c
+       long_i2c,
+       long_print
 };
 
 ASN1_ITEM_start(LONG)
@@ -169,3 +171,9 @@ static int long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
        memcpy(cp, &ltmp, sizeof(long));
        return 1;
 }
+
+static int long_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it,
+                       int indent, const ASN1_PCTX *pctx)
+       {
+       return BIO_printf(out, "%ld\n", *(long *)pval);
+       }
index 04380ab..49be08b 100644 (file)
  */
 
 #include <stdio.h>
+#include <ctype.h>
 #include "cryptlib.h"
 #include <openssl/asn1t.h>
 #include <openssl/x509.h>
+#include "asn1_locl.h"
 
-static int x509_name_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long len, const ASN1_ITEM *it,
-                                       int tag, int aclass, char opt, ASN1_TLC *ctx);
+typedef STACK_OF(X509_NAME_ENTRY) STACK_OF_X509_NAME_ENTRY;
+DECLARE_STACK_OF(STACK_OF_X509_NAME_ENTRY)
 
-static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
+static int x509_name_ex_d2i(ASN1_VALUE **val,
+                               const unsigned char **in, long len,
+                               const ASN1_ITEM *it,
+                               int tag, int aclass, char opt, ASN1_TLC *ctx);
+
+static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out,
+                               const ASN1_ITEM *it, int tag, int aclass);
 static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it);
 static void x509_name_ex_free(ASN1_VALUE **val, const ASN1_ITEM *it);
 
 static int x509_name_encode(X509_NAME *a);
+static int x509_name_canon(X509_NAME *a);
+static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in);
+static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) *intname,
+                         unsigned char **in);
+
+
+static int x509_name_ex_print(BIO *out, ASN1_VALUE **pval,
+                                               int indent,
+                                               const char *fname, 
+                                               const ASN1_PCTX *pctx);
 
 ASN1_SEQUENCE(X509_NAME_ENTRY) = {
        ASN1_SIMPLE(X509_NAME_ENTRY, object, ASN1_OBJECT),
@@ -102,7 +120,8 @@ const ASN1_EXTERN_FUNCS x509_name_ff = {
        x509_name_ex_free,
        0,      /* Default clear behaviour is OK */
        x509_name_ex_d2i,
-       x509_name_ex_i2d
+       x509_name_ex_i2d,
+       x509_name_ex_print
 };
 
 IMPLEMENT_EXTERN_ASN1(X509_NAME, V_ASN1_SEQUENCE, x509_name_ff) 
@@ -118,6 +137,8 @@ static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it)
        if ((ret->entries=sk_X509_NAME_ENTRY_new_null()) == NULL)
                goto memerr;
        if((ret->bytes = BUF_MEM_new()) == NULL) goto memerr;
+       ret->canon_enc = NULL;
+       ret->canon_enclen = 0;
        ret->modified=1;
        *val = (ASN1_VALUE *)ret;
        return 1;
@@ -142,25 +163,19 @@ static void x509_name_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
 
        BUF_MEM_free(a->bytes);
        sk_X509_NAME_ENTRY_pop_free(a->entries,X509_NAME_ENTRY_free);
+       if (a->canon_enc)
+               OPENSSL_free(a->canon_enc);
        OPENSSL_free(a);
        *pval = NULL;
 }
 
-/* Used with sk_pop_free() to free up the internal representation.
- * NB: we only free the STACK and not its contents because it is
- * already present in the X509_NAME structure.
- */
-
-static void sk_internal_free(void *a)
-{
-       sk_free(a);
-}
-
-static int x509_name_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long len, const ASN1_ITEM *it,
-                                       int tag, int aclass, char opt, ASN1_TLC *ctx)
+static int x509_name_ex_d2i(ASN1_VALUE **val,
+                       const unsigned char **in, long len, const ASN1_ITEM *it,
+                               int tag, int aclass, char opt, ASN1_TLC *ctx)
 {
        const unsigned char *p = *in, *q;
-       union { STACK *s; ASN1_VALUE *a; } intname = {NULL};
+       union { STACK_OF(STACK_OF_X509_NAME_ENTRY) *s;
+               ASN1_VALUE *a; } intname = {NULL};
        union { X509_NAME *x; ASN1_VALUE *a; } nm = {NULL};
        int i, j, ret;
        STACK_OF(X509_NAME_ENTRY) *entries;
@@ -181,8 +196,8 @@ static int x509_name_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long len
        memcpy(nm.x->bytes->data, q, p - q);
 
        /* Convert internal representation to X509_NAME structure */
-       for(i = 0; i < sk_num(intname.s); i++) {
-               entries = (STACK_OF(X509_NAME_ENTRY) *)sk_value(intname.s, i);
+       for(i = 0; i < sk_STACK_OF_X509_NAME_ENTRY_num(intname.s); i++) {
+               entries = sk_STACK_OF_X509_NAME_ENTRY_value(intname.s, i);
                for(j = 0; j < sk_X509_NAME_ENTRY_num(entries); j++) {
                        entry = sk_X509_NAME_ENTRY_value(entries, j);
                        entry->set = i;
@@ -191,12 +206,17 @@ static int x509_name_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long len
                }
                sk_X509_NAME_ENTRY_free(entries);
        }
-       sk_free(intname.s);
+       sk_STACK_OF_X509_NAME_ENTRY_free(intname.s);
+       ret = x509_name_canon(nm.x);
+       if (!ret)
+               goto err;
        nm.x->modified = 0;
        *val = nm.a;
        *in = p;
        return ret;
-       err:
+err:
+        if (nm.x != NULL)
+               X509_NAME_free(nm.x);
        ASN1err(ASN1_F_X509_NAME_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
        return 0;
 }
@@ -206,8 +226,12 @@ static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_IT
        int ret;
        X509_NAME *a = (X509_NAME *)*val;
        if(a->modified) {
-               ret = x509_name_encode((X509_NAME *)a);
-               if(ret < 0) return ret;
+               ret = x509_name_encode(a);
+               if(ret < 0)
+                       return ret;
+               ret = x509_name_canon(a);
+               if(ret < 0)
+                       return ret;
        }
        ret = a->bytes->length;
        if(out != NULL) {
@@ -217,22 +241,35 @@ static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_IT
        return ret;
 }
 
+static void local_sk_X509_NAME_ENTRY_free(STACK_OF(X509_NAME_ENTRY) *ne)
+       {
+       sk_X509_NAME_ENTRY_free(ne);
+       }
+
+static void local_sk_X509_NAME_ENTRY_pop_free(STACK_OF(X509_NAME_ENTRY) *ne)
+       {
+       sk_X509_NAME_ENTRY_pop_free(ne, X509_NAME_ENTRY_free);
+       }
+
 static int x509_name_encode(X509_NAME *a)
 {
-       union { STACK *s; ASN1_VALUE *a; } intname = {NULL};
+       union { STACK_OF(STACK_OF_X509_NAME_ENTRY) *s;
+               ASN1_VALUE *a; } intname = {NULL};
        int len;
        unsigned char *p;
        STACK_OF(X509_NAME_ENTRY) *entries = NULL;
        X509_NAME_ENTRY *entry;
        int i, set = -1;
-       intname.s = sk_new_null();
+       intname.s = sk_STACK_OF_X509_NAME_ENTRY_new_null();
        if(!intname.s) goto memerr;
        for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
                entry = sk_X509_NAME_ENTRY_value(a->entries, i);
                if(entry->set != set) {
                        entries = sk_X509_NAME_ENTRY_new_null();
                        if(!entries) goto memerr;
-                       if(!sk_push(intname.s, (char *)entries)) goto memerr;
+                       if(!sk_STACK_OF_X509_NAME_ENTRY_push(intname.s,
+                                                            entries))
+                               goto memerr;
                        set = entry->set;
                }
                if(!sk_X509_NAME_ENTRY_push(entries, entry)) goto memerr;
@@ -243,15 +280,223 @@ static int x509_name_encode(X509_NAME *a)
        p=(unsigned char *)a->bytes->data;
        ASN1_item_ex_i2d(&intname.a,
                         &p, ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1);
-       sk_pop_free(intname.s, sk_internal_free);
+       sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s,
+                                            local_sk_X509_NAME_ENTRY_free);
        a->modified = 0;
        return len;
-       memerr:
-       sk_pop_free(intname.s, sk_internal_free);
+memerr:
+       sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s,
+                                            local_sk_X509_NAME_ENTRY_free);
        ASN1err(ASN1_F_X509_NAME_ENCODE, ERR_R_MALLOC_FAILURE);
        return -1;
 }
 
+static int x509_name_ex_print(BIO *out, ASN1_VALUE **pval,
+                                               int indent,
+                                               const char *fname, 
+                                               const ASN1_PCTX *pctx)
+       {
+       if (X509_NAME_print_ex(out, (X509_NAME *)*pval,
+                                       indent, pctx->nm_flags) <= 0)
+               return 0;
+       return 2;
+       }
+
+/* This function generates the canonical encoding of the Name structure.
+ * In it all strings are converted to UTF8, leading, trailing and
+ * multiple spaces collapsed, converted to lower case and the leading
+ * SEQUENCE header removed.
+ *
+ * In future we could also normalize the UTF8 too.
+ *
+ * By doing this comparison of Name structures can be rapidly
+ * perfomed by just using memcmp() of the canonical encoding.
+ * By omitting the leading SEQUENCE name constraints of type
+ * dirName can also be checked with a simple memcmp().
+ */
+
+static int x509_name_canon(X509_NAME *a)
+       {
+       unsigned char *p;
+       STACK_OF(STACK_OF_X509_NAME_ENTRY) *intname = NULL;
+       STACK_OF(X509_NAME_ENTRY) *entries = NULL;
+       X509_NAME_ENTRY *entry, *tmpentry = NULL;
+       int i, set = -1, ret = 0;
+
+       if (a->canon_enc)
+               {
+               OPENSSL_free(a->canon_enc);
+               a->canon_enc = NULL;
+               }
+       /* Special case: empty X509_NAME => null encoding */
+       if (sk_X509_NAME_ENTRY_num(a->entries) == 0)
+               {
+               a->canon_enclen = 0;
+               return 1;
+               }
+       intname = sk_STACK_OF_X509_NAME_ENTRY_new_null();
+       if(!intname)
+               goto err;
+       for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++)
+               {
+               entry = sk_X509_NAME_ENTRY_value(a->entries, i);
+               if(entry->set != set)
+                       {
+                       entries = sk_X509_NAME_ENTRY_new_null();
+                       if(!entries)
+                               goto err;
+                       if(!sk_STACK_OF_X509_NAME_ENTRY_push(intname, entries))
+                               goto err;
+                       set = entry->set;
+                       }
+               tmpentry = X509_NAME_ENTRY_new();
+               tmpentry->object = OBJ_dup(entry->object);
+               if (!asn1_string_canon(tmpentry->value, entry->value))
+                       goto err;
+               if(!sk_X509_NAME_ENTRY_push(entries, tmpentry))
+                       goto err;
+               tmpentry = NULL;
+               }
+
+       /* Finally generate encoding */
+
+       a->canon_enclen = i2d_name_canon(intname, NULL);
+
+       p = OPENSSL_malloc(a->canon_enclen);
+
+       if (!p)
+               goto err;
+
+       a->canon_enc = p;
+
+       i2d_name_canon(intname, &p);
+
+       ret = 1;
+
+       err:
+
+       if (tmpentry)
+               X509_NAME_ENTRY_free(tmpentry);
+       if (intname)
+               sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname,
+                                       local_sk_X509_NAME_ENTRY_pop_free);
+       return ret;
+       }
+
+/* Bitmap of all the types of string that will be canonicalized. */
+
+#define ASN1_MASK_CANON        \
+       (B_ASN1_UTF8STRING | B_ASN1_BMPSTRING | B_ASN1_UNIVERSALSTRING \
+       | B_ASN1_PRINTABLESTRING | B_ASN1_T61STRING | B_ASN1_IA5STRING \
+       | B_ASN1_VISIBLESTRING)
+       
+
+static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in)
+       {
+       unsigned char *to, *from;
+       int len, i;
+
+       /* If type not in bitmask just copy string across */
+       if (!(ASN1_tag2bit(in->type) & ASN1_MASK_CANON))
+               {
+               out->type = in->type;
+               if (!ASN1_STRING_set(out, in->data, in->length))
+                       return 0;
+               return 1;
+               }
+
+       out->type = V_ASN1_UTF8STRING;
+       out->length = ASN1_STRING_to_UTF8(&out->data, in);
+       if (out->length == -1)
+               return 0;
+
+       to = out->data;
+       from = to;
+
+       len = out->length;
+
+       /* Convert string in place to canonical form.
+        * Ultimately we may need to handle a wider range of characters
+        * but for now ignore anything with MSB set and rely on the
+        * isspace() and tolower() functions.
+        */
+
+       /* Ignore leading spaces */
+       while((len > 0) && !(*from & 0x80) && isspace(*from))
+               {
+               from++;
+               len--;
+               }
+
+       to = from + len - 1;
+
+       /* Ignore trailing spaces */
+       while ((len > 0) && !(*to & 0x80) && isspace(*to))
+               {
+               to--;
+               len--;
+               }
+
+       to = out->data;
+
+       i = 0;
+       while(i < len)
+               {
+               /* If MSB set just copy across */
+               if (*from & 0x80)
+                       {
+                       *to++ = *from++;
+                       i++;
+                       }
+               /* Collapse multiple spaces */
+               else if (isspace(*from))
+                       {
+                       /* Copy one space across */
+                       *to++ = ' ';
+                       /* Ignore subsequent spaces. Note: don't need to
+                        * check len here because we know the last 
+                        * character is a non-space so we can't overflow.
+                        */
+                       do
+                               {
+                               from++;
+                               i++;
+                               }
+                       while(!(*from & 0x80) && isspace(*from));
+                       }
+               else
+                       {
+                       *to++ = tolower(*from);
+                       from++;
+                       i++;
+                       }
+               }
+
+       out->length = to - out->data;
+
+       return 1;
+
+       }
+
+static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) *_intname,
+                         unsigned char **in)
+       {
+       int i, len, ltmp;
+       ASN1_VALUE *v;
+       STACK_OF(ASN1_VALUE) *intname = (STACK_OF(ASN1_VALUE) *)_intname;
+
+       len = 0;
+       for (i = 0; i < sk_ASN1_VALUE_num(intname); i++)
+               {
+               v = sk_ASN1_VALUE_value(intname, i);
+               ltmp = ASN1_item_ex_i2d(&v, in,
+                       ASN1_ITEM_rptr(X509_NAME_ENTRIES), -1, -1);
+               if (ltmp < 0)
+                       return ltmp;
+               len += ltmp;
+               }
+       return len;
+       }
 
 int X509_NAME_set(X509_NAME **xn, X509_NAME *name)
        {
similarity index 73%
rename from deps/openssl/openssl/fips/dh/fips_dh_lib.c
rename to deps/openssl/openssl/crypto/asn1/x_nx509.c
index 4a822cf..fbd9a22 100644 (file)
@@ -1,9 +1,9 @@
-/* fips_dh_lib.c */
+/* x_nx509.c */
 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
- * project 2007.
+ * project 2005.
  */
 /* ====================================================================
- * Copyright (c) 2007 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 2005 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  *
  */
 
-#include <string.h>
-#include <openssl/bn.h>
-#include <openssl/dh.h>
+#include <stddef.h>
+#include <openssl/x509.h>
+#include <openssl/asn1.h>
+#include <openssl/asn1t.h>
 
-/* Minimal FIPS versions of FIPS_dh_new() and FIPS_dh_free(): to
- * reduce external dependencies. 
- */
+/* Old netscape certificate wrapper format */
+
+ASN1_SEQUENCE(NETSCAPE_X509) = {
+       ASN1_SIMPLE(NETSCAPE_X509, header, ASN1_OCTET_STRING),
+       ASN1_OPT(NETSCAPE_X509, cert, X509)
+} ASN1_SEQUENCE_END(NETSCAPE_X509)
 
-DH *FIPS_dh_new(void)
-       {
-       DH *ret;
-       ret = OPENSSL_malloc(sizeof(DH));
-       if (!ret)
-               return NULL;
-       memset(ret, 0, sizeof(DH));
-       ret->meth = DH_OpenSSL();
-       if (ret->meth->init)
-               ret->meth->init(ret);
-       return ret;
-       }
+IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_X509)
 
-void FIPS_dh_free(DH *r)
-       {
-       if (!r)
-               return;
-       if (r->meth->finish)
-               r->meth->finish(r);
-       if (r->p != NULL) BN_clear_free(r->p);
-       if (r->g != NULL) BN_clear_free(r->g);
-       if (r->q != NULL) BN_clear_free(r->q);
-       if (r->j != NULL) BN_clear_free(r->j);
-       if (r->seed) OPENSSL_free(r->seed);
-       if (r->counter != NULL) BN_clear_free(r->counter);
-       if (r->pub_key != NULL) BN_clear_free(r->pub_key);
-       if (r->priv_key != NULL) BN_clear_free(r->priv_key);
-       OPENSSL_free(r);
-       }
index 91c2756..d42b6a2 100644 (file)
@@ -60,6 +60,7 @@
 #include "cryptlib.h"
 #include <openssl/asn1t.h>
 #include <openssl/x509.h>
+#include "asn1_locl.h"
 #ifndef OPENSSL_NO_RSA
 #include <openssl/rsa.h>
 #endif
@@ -68,7 +69,8 @@
 #endif
 
 /* Minor tweak to operation: free up EVP_PKEY */
-static int pubkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
+static int pubkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
+                       void *exarg)
        {
        if (operation == ASN1_OP_FREE_POST)
                {
@@ -88,169 +90,42 @@ IMPLEMENT_ASN1_FUNCTIONS(X509_PUBKEY)
 int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
        {
        X509_PUBKEY *pk=NULL;
-       X509_ALGOR *a;
-       ASN1_OBJECT *o;
-       unsigned char *s,*p = NULL;
-       int i;
 
        if (x == NULL) return(0);
 
-       if ((pk=X509_PUBKEY_new()) == NULL) goto err;
-       a=pk->algor;
+       if ((pk=X509_PUBKEY_new()) == NULL) goto error;
 
-       /* set the algorithm id */
-       if ((o=OBJ_nid2obj(pkey->type)) == NULL) goto err;
-       ASN1_OBJECT_free(a->algorithm);
-       a->algorithm=o;
-
-       /* Set the parameter list */
-       if (!pkey->save_parameters || (pkey->type == EVP_PKEY_RSA))
+       if (pkey->ameth)
                {
-               if ((a->parameter == NULL) ||
-                       (a->parameter->type != V_ASN1_NULL))
+               if (pkey->ameth->pub_encode)
                        {
-                       ASN1_TYPE_free(a->parameter);
-                       if (!(a->parameter=ASN1_TYPE_new()))
+                       if (!pkey->ameth->pub_encode(pk, pkey))
                                {
-                               X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE);
-                               goto err;
+                               X509err(X509_F_X509_PUBKEY_SET,
+                                       X509_R_PUBLIC_KEY_ENCODE_ERROR);
+                               goto error;
                                }
-                       a->parameter->type=V_ASN1_NULL;
-                       }
-               }
-#ifndef OPENSSL_NO_DSA
-       else if (pkey->type == EVP_PKEY_DSA)
-               {
-               unsigned char *pp;
-               DSA *dsa;
-               
-               dsa=pkey->pkey.dsa;
-               dsa->write_params=0;
-               ASN1_TYPE_free(a->parameter);
-               if ((i=i2d_DSAparams(dsa,NULL)) <= 0)
-                       goto err;
-               if (!(p=(unsigned char *)OPENSSL_malloc(i)))
-                       {
-                       X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE);
-                       goto err;
-                       }
-               pp=p;
-               i2d_DSAparams(dsa,&pp);
-               if (!(a->parameter=ASN1_TYPE_new()))
-                       {
-                       OPENSSL_free(p);
-                       X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE);
-                       goto err;
-                       }
-               a->parameter->type=V_ASN1_SEQUENCE;
-               if (!(a->parameter->value.sequence=ASN1_STRING_new()))
-                       {
-                       OPENSSL_free(p);
-                       X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE);
-                       goto err;
                        }
-               if (!ASN1_STRING_set(a->parameter->value.sequence,p,i))
+               else
                        {
-                       OPENSSL_free(p);
-                       X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE);
-                       goto err;
+                       X509err(X509_F_X509_PUBKEY_SET,
+                               X509_R_METHOD_NOT_SUPPORTED);
+                       goto error;
                        }
-               OPENSSL_free(p);
                }
-#endif
-#ifndef OPENSSL_NO_EC
-       else if (pkey->type == EVP_PKEY_EC)
-               {
-               int nid=0;
-               unsigned char *pp;
-               EC_KEY *ec_key;
-               const EC_GROUP *group;
-               
-               ec_key = pkey->pkey.ec;
-               ASN1_TYPE_free(a->parameter);
-
-               if ((a->parameter = ASN1_TYPE_new()) == NULL)
-                       {
-                       X509err(X509_F_X509_PUBKEY_SET, ERR_R_ASN1_LIB);
-                       goto err;
-                       }
-
-               group = EC_KEY_get0_group(ec_key);
-               if (EC_GROUP_get_asn1_flag(group)
-                     && (nid = EC_GROUP_get_curve_name(group)))
-                       {
-                       /* just set the OID */
-                       a->parameter->type = V_ASN1_OBJECT;
-                       a->parameter->value.object = OBJ_nid2obj(nid);
-                       }
-               else /* explicit parameters */
-                       {
-                       if ((i = i2d_ECParameters(ec_key, NULL)) == 0)
-                               {
-                               X509err(X509_F_X509_PUBKEY_SET, ERR_R_EC_LIB);
-                               goto err;
-                               }
-                       if ((p = (unsigned char *) OPENSSL_malloc(i)) == NULL)
-                               {
-                               X509err(X509_F_X509_PUBKEY_SET, ERR_R_MALLOC_FAILURE);
-                               goto err;
-                               }       
-                       pp = p;
-                       if (!i2d_ECParameters(ec_key, &pp))
-                               {
-                               X509err(X509_F_X509_PUBKEY_SET, ERR_R_EC_LIB);
-                               OPENSSL_free(p);
-                               goto err;
-                               }
-                       a->parameter->type = V_ASN1_SEQUENCE;
-                       if ((a->parameter->value.sequence = ASN1_STRING_new()) == NULL)
-                               {
-                               X509err(X509_F_X509_PUBKEY_SET, ERR_R_ASN1_LIB);
-                               OPENSSL_free(p);
-                               goto err;
-                               }
-                       ASN1_STRING_set(a->parameter->value.sequence, p, i);
-                       OPENSSL_free(p);
-                       }
-               }
-#endif
-       else if (1)
+       else
                {
                X509err(X509_F_X509_PUBKEY_SET,X509_R_UNSUPPORTED_ALGORITHM);
-               goto err;
+               goto error;
                }
 
-       if ((i=i2d_PublicKey(pkey,NULL)) <= 0) goto err;
-       if ((s=(unsigned char *)OPENSSL_malloc(i+1)) == NULL)
-               {
-               X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE);
-               goto err;
-               }
-       p=s;
-       i2d_PublicKey(pkey,&p);
-       if (!M_ASN1_BIT_STRING_set(pk->public_key,s,i))
-               {
-               X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE);
-               goto err;
-               }
-       /* Set number of unused bits to zero */
-       pk->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
-       pk->public_key->flags|=ASN1_STRING_FLAG_BITS_LEFT;
-
-       OPENSSL_free(s);
-
-#if 0
-       CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
-       pk->pkey=pkey;
-#endif
-
        if (*x != NULL)
                X509_PUBKEY_free(*x);
 
        *x=pk;
 
        return 1;
-err:
+error:
        if (pk != NULL) X509_PUBKEY_free(pk);
        return 0;
        }
@@ -258,119 +133,50 @@ err:
 EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)
        {
        EVP_PKEY *ret=NULL;
-       long j;
-       int type;
-       const unsigned char *p;
-#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_ECDSA)
-       const unsigned char *cp;
-       X509_ALGOR *a;
-#endif
 
-       if (key == NULL) goto err;
+       if (key == NULL) goto error;
 
        if (key->pkey != NULL)
                {
                CRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
-               return(key->pkey);
+               return key->pkey;
                }
 
-       if (key->public_key == NULL) goto err;
+       if (key->public_key == NULL) goto error;
 
-       type=OBJ_obj2nid(key->algor->algorithm);
        if ((ret = EVP_PKEY_new()) == NULL)
                {
                X509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE);
-               goto err;
+               goto error;
                }
-       ret->type = EVP_PKEY_type(type);
-
-       /* the parameters must be extracted before the public key (ECDSA!) */
-       
-#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_ECDSA)
-       a=key->algor;
-#endif
 
-       if (0)
-               ;
-#ifndef OPENSSL_NO_DSA
-       else if (ret->type == EVP_PKEY_DSA)
+       if (!EVP_PKEY_set_type(ret, OBJ_obj2nid(key->algor->algorithm)))
                {
-               if (a->parameter && (a->parameter->type == V_ASN1_SEQUENCE))
-                       {
-                       if ((ret->pkey.dsa = DSA_new()) == NULL)
-                               {
-                               X509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE);
-                               goto err;
-                               }
-                       ret->pkey.dsa->write_params=0;
-                       cp=p=a->parameter->value.sequence->data;
-                       j=a->parameter->value.sequence->length;
-                       if (!d2i_DSAparams(&ret->pkey.dsa, &cp, (long)j))
-                               goto err;
-                       }
-               ret->save_parameters=1;
+               X509err(X509_F_X509_PUBKEY_GET,X509_R_UNSUPPORTED_ALGORITHM);
+               goto error;
                }
-#endif
-#ifndef OPENSSL_NO_EC
-       else if (ret->type == EVP_PKEY_EC)
+
+       if (ret->ameth->pub_decode)
                {
-               if (a->parameter && (a->parameter->type == V_ASN1_SEQUENCE))
+               if (!ret->ameth->pub_decode(ret, key))
                        {
-                       /* type == V_ASN1_SEQUENCE => we have explicit parameters
-                         * (e.g. parameters in the X9_62_EC_PARAMETERS-structure )
-                        */
-                       if ((ret->pkey.ec= EC_KEY_new()) == NULL)
-                               {
-                               X509err(X509_F_X509_PUBKEY_GET, 
-                                       ERR_R_MALLOC_FAILURE);
-                               goto err;
-                               }
-                       cp = p = a->parameter->value.sequence->data;
-                       j = a->parameter->value.sequence->length;
-                       if (!d2i_ECParameters(&ret->pkey.ec, &cp, (long)j))
-                               {
-                               X509err(X509_F_X509_PUBKEY_GET, ERR_R_EC_LIB);
-                               goto err;
-                               }
-                       }
-               else if (a->parameter && (a->parameter->type == V_ASN1_OBJECT))
-                       {
-                       /* type == V_ASN1_OBJECT => the parameters are given
-                        * by an asn1 OID
-                        */
-                       EC_KEY   *ec_key;
-                       EC_GROUP *group;
-
-                       if (ret->pkey.ec == NULL)
-                               ret->pkey.ec = EC_KEY_new();
-                       ec_key = ret->pkey.ec;
-                       if (ec_key == NULL)
-                               goto err;
-                       group = EC_GROUP_new_by_curve_name(OBJ_obj2nid(a->parameter->value.object));
-                       if (group == NULL)
-                               goto err;
-                       EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE);
-                       if (EC_KEY_set_group(ec_key, group) == 0)
-                               goto err;
-                       EC_GROUP_free(group);
+                       X509err(X509_F_X509_PUBKEY_GET,
+                                               X509_R_PUBLIC_KEY_DECODE_ERROR);
+                       goto error;
                        }
-                       /* the case implicitlyCA is currently not implemented */
-               ret->save_parameters = 1;
                }
-#endif
-
-       p=key->public_key->data;
-        j=key->public_key->length;
-        if (!d2i_PublicKey(type, &ret, &p, (long)j))
+       else
                {
-               X509err(X509_F_X509_PUBKEY_GET, X509_R_ERR_ASN1_LIB);
-               goto err;
+               X509err(X509_F_X509_PUBKEY_GET, X509_R_METHOD_NOT_SUPPORTED);
+               goto error;
                }
 
        key->pkey = ret;
        CRYPTO_add(&ret->references, 1, CRYPTO_LOCK_EVP_PKEY);
-       return(ret);
-err:
+
+       return ret;
+
+       error:
        if (ret != NULL)
                EVP_PKEY_free(ret);
        return(NULL);
@@ -529,3 +335,39 @@ int i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp)
        return(ret);
        }
 #endif
+
+int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj,
+                                       int ptype, void *pval,
+                                       unsigned char *penc, int penclen)
+       {
+       if (!X509_ALGOR_set0(pub->algor, aobj, ptype, pval))
+               return 0;
+       if (penc)
+               {
+               if (pub->public_key->data)
+                       OPENSSL_free(pub->public_key->data);
+               pub->public_key->data = penc;
+               pub->public_key->length = penclen;
+               /* Set number of unused bits to zero */
+               pub->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
+               pub->public_key->flags|=ASN1_STRING_FLAG_BITS_LEFT;
+               }
+       return 1;
+       }
+
+int X509_PUBKEY_get0_param(ASN1_OBJECT **ppkalg,
+               const unsigned char **pk, int *ppklen,
+               X509_ALGOR **pa,
+               X509_PUBKEY *pub)
+       {
+       if (ppkalg)
+               *ppkalg = pub->algor->algorithm;
+       if (pk)
+               {
+               *pk = pub->public_key->data;
+               *ppklen = pub->public_key->length;
+               }
+       if (pa)
+               *pa = pub->algor;
+       return 1;
+       }
index 59ca8ce..d575558 100644 (file)
@@ -79,7 +79,8 @@
  *
  */
 
-static int rinf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
+static int rinf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
+                                                       void *exarg)
 {
        X509_REQ_INFO *rinf = (X509_REQ_INFO *)*pval;
 
index 088d550..de3df9e 100644 (file)
@@ -81,7 +81,8 @@ IMPLEMENT_ASN1_FUNCTIONS(X509_CINF)
 
 extern void policy_cache_free(X509_POLICY_CACHE *cache);
 
-static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
+static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
+                                                               void *exarg)
 {
        X509 *ret = (X509 *)*pval;
 
@@ -99,6 +100,7 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
                ret->rfc3779_asid = NULL;
 #endif
                ret->aux = NULL;
+               ret->crldp = NULL;
                CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data);
                break;
 
@@ -112,7 +114,10 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
                X509_CERT_AUX_free(ret->aux);
                ASN1_OCTET_STRING_free(ret->skid);
                AUTHORITY_KEYID_free(ret->akid);
+               CRL_DIST_POINTS_free(ret->crldp);
                policy_cache_free(ret->policy_cache);
+               GENERAL_NAMES_free(ret->altname);
+               NAME_CONSTRAINTS_free(ret->nc);
 #ifndef OPENSSL_NO_RFC3779
                sk_IPAddressFamily_pop_free(ret->rfc3779_addr, IPAddressFamily_free);
                ASIdentifiers_free(ret->rfc3779_asid);
@@ -136,19 +141,6 @@ ASN1_SEQUENCE_ref(X509, x509_cb, CRYPTO_LOCK_X509) = {
 IMPLEMENT_ASN1_FUNCTIONS(X509)
 IMPLEMENT_ASN1_DUP_FUNCTION(X509)
 
-static ASN1_METHOD meth=
-    {
-    (I2D_OF(void))  i2d_X509,
-    (D2I_OF(void)) d2i_X509,
-    (void *(*)(void))X509_new,
-    (void (*)(void *)) X509_free
-    };
-
-ASN1_METHOD *X509_asn1_meth(void)
-       {
-       return(&meth);
-       }
-
 int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
             CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
         {
index 7f4f03e..dd2c2c7 100644 (file)
@@ -12,8 +12,6 @@ MAKEFILE=     Makefile
 AR=            ar r
 
 BF_ENC=                bf_enc.o
-# or use
-#DES_ENC=      bx86-elf.o
 
 CFLAGS= $(INCLUDES) $(CFLAG)
 ASFLAGS= $(INCLUDES) $(ASFLAG)
@@ -40,19 +38,12 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
-# ELF
-bx86-elf.s: asm/bf-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
-       (cd asm; $(PERL) bf-586.pl elf $(CFLAGS) $(PROCESSOR) > ../$@)
-# COFF
-bx86-cof.s: asm/bf-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
-       (cd asm; $(PERL) bf-586.pl coff $(CFLAGS) $(PROCESSOR) > ../$@)
-# a.out
-bx86-out.s: asm/bf-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
-       (cd asm; $(PERL) bf-586.pl a.out $(CFLAGS) $(PROCESSOR) > ../$@)
+bf-586.s:      asm/bf-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
+       $(PERL) asm/bf-586.pl $(PERLASM_SCHEME) $(CFLAGS) $(PROCESSOR) > $@
 
 files:
        $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
@@ -103,9 +94,5 @@ bf_enc.o: ../../include/openssl/blowfish.h ../../include/openssl/e_os2.h
 bf_enc.o: ../../include/openssl/opensslconf.h bf_enc.c bf_locl.h
 bf_ofb64.o: ../../include/openssl/blowfish.h ../../include/openssl/e_os2.h
 bf_ofb64.o: ../../include/openssl/opensslconf.h bf_locl.h bf_ofb64.c
-bf_skey.o: ../../include/openssl/blowfish.h ../../include/openssl/crypto.h
-bf_skey.o: ../../include/openssl/e_os2.h ../../include/openssl/fips.h
-bf_skey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-bf_skey.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
-bf_skey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-bf_skey.o: bf_locl.h bf_pi.h bf_skey.c
+bf_skey.o: ../../include/openssl/blowfish.h ../../include/openssl/e_os2.h
+bf_skey.o: ../../include/openssl/opensslconf.h bf_locl.h bf_pi.h bf_skey.c
index b556642..b74cfba 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/local/bin/perl
 
-push(@INC,"perlasm","../../perlasm");
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+push(@INC,"${dir}","${dir}../../perlasm");
 require "x86asm.pl";
 require "cbc.pl";
 
index 6ac2aeb..3673cde 100644 (file)
 #include <stdio.h>
 #include <string.h>
 #include <openssl/blowfish.h>
-#include <openssl/crypto.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
 #include "bf_locl.h"
 #include "bf_pi.h"
 
-FIPS_NON_FIPS_VCIPHER_Init(BF)
+void BF_set_key(BF_KEY *key, int len, const unsigned char *data)
        {
        int i;
        BF_LONG *p,ri,in[2];
index d24ffcc..b97e76f 100644 (file)
@@ -79,7 +79,7 @@ extern "C" {
  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  */
 
-#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)
+#if defined(__LP32__)
 #define BF_LONG unsigned long
 #elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
 #define BF_LONG unsigned long
@@ -104,9 +104,7 @@ typedef struct bf_key_st
        BF_LONG S[4*256];
        } BF_KEY;
 
-#ifdef OPENSSL_FIPS 
-void private_BF_set_key(BF_KEY *key, int len, const unsigned char *data);
-#endif
 void BF_set_key(BF_KEY *key, int len, const unsigned char *data);
 
 void BF_encrypt(BF_LONG *data,const BF_KEY *key);
index 1cd76ce..c395d80 100644 (file)
@@ -45,7 +45,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -102,11 +102,12 @@ b_print.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
 b_print.o: ../../include/openssl/symhacks.h ../cryptlib.h b_print.c
 b_sock.o: ../../e_os.h ../../include/openssl/bio.h
 b_sock.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
-b_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-b_sock.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
-b_sock.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-b_sock.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-b_sock.o: ../../include/openssl/symhacks.h ../cryptlib.h b_sock.c
+b_sock.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
+b_sock.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
+b_sock.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+b_sock.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
+b_sock.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+b_sock.o: ../cryptlib.h b_sock.c
 bf_buff.o: ../../e_os.h ../../include/openssl/bio.h
 bf_buff.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 bf_buff.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
index 3a87b0e..143a7cf 100644 (file)
 #define LDOUBLE double
 #endif
 
-#if HAVE_LONG_LONG
-# if defined(OPENSSL_SYS_WIN32) && !defined(__GNUC__)
+#ifdef HAVE_LONG_LONG
+# if defined(_WIN32) && !defined(__GNUC__)
 # define LLONG __int64
 # else
 # define LLONG long long
index f0d9cfc..d47310d 100644 (file)
@@ -72,11 +72,9 @@ NETDB_DEFINE_CONTEXT
 
 #ifndef OPENSSL_NO_SOCK
 
-#ifdef OPENSSL_SYS_WIN16
-#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
-#else
+#include <openssl/dso.h>
+
 #define SOCKET_PROTOCOL IPPROTO_TCP
-#endif
 
 #ifdef SO_MAXCONN
 #define MAX_LISTEN  SO_MAXCONN
@@ -90,6 +88,17 @@ NETDB_DEFINE_CONTEXT
 static int wsa_init_done=0;
 #endif
 
+/*
+ * WSAAPI specifier is required to make indirect calls to run-time
+ * linked WinSock 2 functions used in this module, to be specific
+ * [get|free]addrinfo and getnameinfo. This is because WinSock uses
+ * uses non-C calling convention, __stdcall vs. __cdecl, on x86
+ * Windows. On non-WinSock platforms WSAAPI needs to be void.
+ */
+#ifndef WSAAPI
+#define WSAAPI
+#endif
+
 #if 0
 static unsigned long BIO_ghbn_hits=0L;
 static unsigned long BIO_ghbn_miss=0L;
@@ -226,6 +235,10 @@ int BIO_sock_error(int sock)
        int j,i;
        int size;
                 
+#if defined(OPENSSL_SYS_BEOS_R5)
+       return 0;
+#endif
+                
        size=sizeof(int);
        /* Note: under Windows the third parameter is of type (char *)
         * whereas under other systems it is (void *) if you don't have
@@ -466,7 +479,12 @@ int BIO_sock_init(void)
          
                wsa_init_done=1;
                memset(&wsa_state,0,sizeof(wsa_state));
-               if (WSAStartup(0x0101,&wsa_state)!=0)
+               /* Not making wsa_state available to the rest of the
+                * code is formally wrong. But the structures we use
+                * are [beleived to be] invariable among Winsock DLLs,
+                * while API availability is [expected to be] probed
+                * at run-time with DSO_global_lookup. */
+               if (WSAStartup(0x0202,&wsa_state)!=0)
                        {
                        err=WSAGetLastError();
                        SYSerr(SYS_F_WSASTARTUP,err);
@@ -510,8 +528,8 @@ void BIO_sock_cleanup(void)
        if (wsa_init_done)
                {
                wsa_init_done=0;
-#ifndef OPENSSL_SYS_WINCE
-               WSACancelBlockingCall();        /* Winsock 1.1 specific */
+#if 0          /* this call is claimed to be non-present in Winsock2 */
+               WSACancelBlockingCall();
 #endif
                WSACleanup();
                }
@@ -533,7 +551,30 @@ int BIO_socket_ioctl(int fd, long type, void *arg)
 #ifdef __DJGPP__
        i=ioctlsocket(fd,type,(char *)arg);
 #else
-       i=ioctlsocket(fd,type,arg);
+# if defined(OPENSSL_SYS_VMS)
+       /* 2011-02-18 SMS.
+        * VMS ioctl() can't tolerate a 64-bit "void *arg", but we
+        * observe that all the consumers pass in an "unsigned long *",
+        * so we arrange a local copy with a short pointer, and use
+        * that, instead.
+        */
+#  if __INITIAL_POINTER_SIZE == 64
+#   define ARG arg_32p
+#   pragma pointer_size save
+#   pragma pointer_size 32
+       unsigned long arg_32;
+       unsigned long *arg_32p;
+#   pragma pointer_size restore
+       arg_32p = &arg_32;
+       arg_32 = *((unsigned long *) arg);
+#  else /* __INITIAL_POINTER_SIZE == 64 */
+#   define ARG arg
+#  endif /* __INITIAL_POINTER_SIZE == 64 [else] */
+# else /* defined(OPENSSL_SYS_VMS) */
+#  define ARG arg
+# endif /* defined(OPENSSL_SYS_VMS) [else] */
+
+       i=ioctlsocket(fd,type,ARG);
 #endif /* __DJGPP__ */
        if (i < 0)
                SYSerr(SYS_F_IOCTLSOCKET,get_last_socket_error());
@@ -581,12 +622,18 @@ static int get_ip(const char *str, unsigned char ip[4])
 int BIO_get_accept_socket(char *host, int bind_mode)
        {
        int ret=0;
-       struct sockaddr_in server,client;
-       int s=INVALID_SOCKET,cs;
+       union {
+               struct sockaddr sa;
+               struct sockaddr_in sa_in;
+#if OPENSSL_USE_IPV6
+               struct sockaddr_in6 sa_in6;
+#endif
+       } server,client;
+       int s=INVALID_SOCKET,cs,addrlen;
        unsigned char ip[4];
        unsigned short port;
        char *str=NULL,*e;
-       const char *h,*p;
+       char *h,*p;
        unsigned long l;
        int err_num;
 
@@ -600,8 +647,7 @@ int BIO_get_accept_socket(char *host, int bind_mode)
                {
                if (*e == ':')
                        {
-                       p= &(e[1]);
-                       *e='\0';
+                       p=e;
                        }
                else if (*e == '/')
                        {
@@ -609,21 +655,74 @@ int BIO_get_accept_socket(char *host, int bind_mode)
                        break;
                        }
                }
-
-       if (p == NULL)
+       if (p)  *p++='\0';      /* points at last ':', '::port' is special [see below] */
+       else    p=h,h=NULL;
+
+#ifdef EAI_FAMILY
+       do {
+       static union {  void *p;
+                       int (WSAAPI *f)(const char *,const char *,
+                                const struct addrinfo *,
+                                struct addrinfo **);
+                       } p_getaddrinfo = {NULL};
+       static union {  void *p;
+                       void (WSAAPI *f)(struct addrinfo *);
+                       } p_freeaddrinfo = {NULL};
+       struct addrinfo *res,hint;
+
+       if (p_getaddrinfo.p==NULL)
                {
-               p=h;
-               h="*";
+               if ((p_getaddrinfo.p=DSO_global_lookup("getaddrinfo"))==NULL ||
+                   (p_freeaddrinfo.p=DSO_global_lookup("freeaddrinfo"))==NULL)
+                       p_getaddrinfo.p=(void*)-1;
+               }
+       if (p_getaddrinfo.p==(void *)-1) break;
+
+       /* '::port' enforces IPv6 wildcard listener. Some OSes,
+        * e.g. Solaris, default to IPv6 without any hint. Also
+        * note that commonly IPv6 wildchard socket can service
+        * IPv4 connections just as well...  */
+       memset(&hint,0,sizeof(hint));
+       hint.ai_flags = AI_PASSIVE;
+       if (h)
+               {
+               if (strchr(h,':'))
+                       {
+                       if (h[1]=='\0') h=NULL;
+#if OPENSSL_USE_IPV6
+                       hint.ai_family = AF_INET6;
+#else
+                       h=NULL;
+#endif
+                       }
+               else if (h[0]=='*' && h[1]=='\0')
+                       {
+                       hint.ai_family = AF_INET;
+                       h=NULL;
+                       }
                }
 
+       if ((*p_getaddrinfo.f)(h,p,&hint,&res)) break;
+
+       addrlen = res->ai_addrlen<=sizeof(server) ?
+                       res->ai_addrlen :
+                       sizeof(server);
+       memcpy(&server, res->ai_addr, addrlen);
+
+       (*p_freeaddrinfo.f)(res);
+       goto again;
+       } while (0);
+#endif
+
        if (!BIO_get_port(p,&port)) goto err;
 
        memset((char *)&server,0,sizeof(server));
-       server.sin_family=AF_INET;
-       server.sin_port=htons(port);
+       server.sa_in.sin_family=AF_INET;
+       server.sa_in.sin_port=htons(port);
+       addrlen = sizeof(server.sa_in);
 
-       if (strcmp(h,"*") == 0)
-               server.sin_addr.s_addr=INADDR_ANY;
+       if (h == NULL || strcmp(h,"*") == 0)
+               server.sa_in.sin_addr.s_addr=INADDR_ANY;
        else
                {
                 if (!BIO_get_host_ip(h,&(ip[0]))) goto err;
@@ -632,11 +731,11 @@ int BIO_get_accept_socket(char *host, int bind_mode)
                        ((unsigned long)ip[1]<<16L)|
                        ((unsigned long)ip[2]<< 8L)|
                        ((unsigned long)ip[3]);
-               server.sin_addr.s_addr=htonl(l);
+               server.sa_in.sin_addr.s_addr=htonl(l);
                }
 
 again:
-       s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
+       s=socket(server.sa.sa_family,SOCK_STREAM,SOCKET_PROTOCOL);
        if (s == INVALID_SOCKET)
                {
                SYSerr(SYS_F_SOCKET,get_last_socket_error());
@@ -654,7 +753,7 @@ again:
                bind_mode=BIO_BIND_NORMAL;
                }
 #endif
-       if (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1)
+       if (bind(s,&server.sa,addrlen) == -1)
                {
 #ifdef SO_REUSEADDR
                err_num=get_last_socket_error();
@@ -668,15 +767,28 @@ again:
                        (err_num == EADDRINUSE))
 #endif
                        {
-                       memcpy((char *)&client,(char *)&server,sizeof(server));
-                       if (strcmp(h,"*") == 0)
-                               client.sin_addr.s_addr=htonl(0x7F000001);
-                       cs=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
+                       client = server;
+                       if (h == NULL || strcmp(h,"*") == 0)
+                               {
+#if OPENSSL_USE_IPV6
+                               if (client.sa.sa_family == AF_INET6)
+                                       {
+                                       memset(&client.sa_in6.sin6_addr,0,sizeof(client.sa_in6.sin6_addr));
+                                       client.sa_in6.sin6_addr.s6_addr[15]=1;
+                                       }
+                               else
+#endif
+                               if (client.sa.sa_family == AF_INET)
+                                       {
+                                       client.sa_in.sin_addr.s_addr=htonl(0x7F000001);
+                                       }
+                               else    goto err;
+                               }
+                       cs=socket(client.sa.sa_family,SOCK_STREAM,SOCKET_PROTOCOL);
                        if (cs != INVALID_SOCKET)
                                {
                                int ii;
-                               ii=connect(cs,(struct sockaddr *)&client,
-                                       sizeof(client));
+                               ii=connect(cs,&client.sa,addrlen);
                                closesocket(cs);
                                if (ii == INVALID_SOCKET)
                                        {
@@ -715,20 +827,52 @@ err:
 int BIO_accept(int sock, char **addr)
        {
        int ret=INVALID_SOCKET;
-       static struct sockaddr_in from;
        unsigned long l;
        unsigned short port;
-       int len;
        char *p;
 
-       memset((char *)&from,0,sizeof(from));
-       len=sizeof(from);
-       /* Note: under VMS with SOCKETSHR the fourth parameter is currently
-        * of type (int *) whereas under other systems it is (void *) if
-        * you don't have a cast it will choke the compiler: if you do
-        * have a cast then you can either go for (int *) or (void *).
+       struct {
+       /*
+        * As for following union. Trouble is that there are platforms
+        * that have socklen_t and there are platforms that don't, on
+        * some platforms socklen_t is int and on some size_t. So what
+        * one can do? One can cook #ifdef spaghetti, which is nothing
+        * but masochistic. Or one can do union between int and size_t.
+        * One naturally does it primarily for 64-bit platforms where
+        * sizeof(int) != sizeof(size_t). But would it work? Note that
+        * if size_t member is initialized to 0, then later int member
+        * assignment naturally does the job on little-endian platforms
+        * regardless accept's expectations! What about big-endians?
+        * If accept expects int*, then it works, and if size_t*, then
+        * length value would appear as unreasonably large. But this
+        * won't prevent it from filling in the address structure. The
+        * trouble of course would be if accept returns more data than
+        * actual buffer can accomodate and overwrite stack... That's
+        * where early OPENSSL_assert comes into picture. Besides, the
+        * only 64-bit big-endian platform found so far that expects
+        * size_t* is HP-UX, where stack grows towards higher address.
+        * <appro>
         */
-       ret=accept(sock,(struct sockaddr *)&from,(void *)&len);
+       union { size_t s; int i; } len;
+       union {
+               struct sockaddr sa;
+               struct sockaddr_in sa_in;
+#if OPENSSL_USE_IPV6
+               struct sockaddr_in6 sa_in6;
+#endif
+               } from;
+       } sa;
+
+       sa.len.s=0;
+       sa.len.i=sizeof(sa.from);
+       memset(&sa.from,0,sizeof(sa.from));
+       ret=accept(sock,&sa.from.sa,(void *)&sa.len);
+       if (sizeof(sa.len.i)!=sizeof(sa.len.s) && sa.len.i==0)
+               {
+               OPENSSL_assert(sa.len.s<=sizeof(sa.from));
+               sa.len.i = (int)sa.len.s;
+               /* use sa.len.i from this point */
+               }
        if (ret == INVALID_SOCKET)
                {
                if(BIO_sock_should_retry(ret)) return -2;
@@ -739,8 +883,46 @@ int BIO_accept(int sock, char **addr)
 
        if (addr == NULL) goto end;
 
-       l=ntohl(from.sin_addr.s_addr);
-       port=ntohs(from.sin_port);
+#ifdef EAI_FAMILY
+       do {
+       char   h[NI_MAXHOST],s[NI_MAXSERV];
+       size_t nl;
+       static union {  void *p;
+                       int (WSAAPI *f)(const struct sockaddr *,size_t/*socklen_t*/,
+                                char *,size_t,char *,size_t,int);
+                       } p_getnameinfo = {NULL};
+                       /* 2nd argument to getnameinfo is specified to
+                        * be socklen_t. Unfortunately there is a number
+                        * of environments where socklen_t is not defined.
+                        * As it's passed by value, it's safe to pass it
+                        * as size_t... <appro> */
+
+       if (p_getnameinfo.p==NULL)
+               {
+               if ((p_getnameinfo.p=DSO_global_lookup("getnameinfo"))==NULL)
+                       p_getnameinfo.p=(void*)-1;
+               }
+       if (p_getnameinfo.p==(void *)-1) break;
+
+       if ((*p_getnameinfo.f)(&sa.from.sa,sa.len.i,h,sizeof(h),s,sizeof(s),
+           NI_NUMERICHOST|NI_NUMERICSERV)) break;
+       nl = strlen(h)+strlen(s)+2;
+       p = *addr;
+       if (p)  { *p = '\0'; p = OPENSSL_realloc(p,nl); }
+       else    { p = OPENSSL_malloc(nl);               }
+       if (p==NULL)
+               {
+               BIOerr(BIO_F_BIO_ACCEPT,ERR_R_MALLOC_FAILURE);
+               goto end;
+               }
+       *addr = p;
+       BIO_snprintf(*addr,nl,"%s:%s",h,s);
+       goto end;
+       } while(0);
+#endif
+       if (sa.from.sa.sa_family != AF_INET) goto end;
+       l=ntohl(sa.from.sa_in.sin_addr.s_addr);
+       port=ntohs(sa.from.sa_in.sin_port);
        if (*addr == NULL)
                {
                if ((p=OPENSSL_malloc(24)) == NULL)
index c1fd75a..4b5a132 100644 (file)
@@ -209,7 +209,7 @@ start:
        /* add to buffer and return */
        if (i >= inl)
                {
-               memcpy(&(ctx->obuf[ctx->obuf_len]),in,inl);
+               memcpy(&(ctx->obuf[ctx->obuf_off+ctx->obuf_len]),in,inl);
                ctx->obuf_len+=inl;
                return(num+inl);
                }
@@ -219,7 +219,7 @@ start:
                {
                if (i > 0) /* lets fill it up if we can */
                        {
-                       memcpy(&(ctx->obuf[ctx->obuf_len]),in,i);
+                       memcpy(&(ctx->obuf[ctx->obuf_off+ctx->obuf_len]),in,i);
                        in+=i;
                        inl-=i;
                        num+=i;
@@ -294,9 +294,9 @@ static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
        case BIO_C_GET_BUFF_NUM_LINES:
                ret=0;
                p1=ctx->ibuf;
-               for (i=ctx->ibuf_off; i<ctx->ibuf_len; i++)
+               for (i=0; i<ctx->ibuf_len; i++)
                        {
-                       if (p1[i] == '\n') ret++;
+                       if (p1[ctx->ibuf_off + i] == '\n') ret++;
                        }
                break;
        case BIO_CTRL_WPENDING:
@@ -399,17 +399,18 @@ static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
                for (;;)
                        {
                        BIO_clear_retry_flags(b);
-                       if (ctx->obuf_len > ctx->obuf_off)
+                       if (ctx->obuf_len > 0)
                                {
                                r=BIO_write(b->next_bio,
                                        &(ctx->obuf[ctx->obuf_off]),
-                                       ctx->obuf_len-ctx->obuf_off);
+                                       ctx->obuf_len);
 #if 0
-fprintf(stderr,"FLUSH [%3d] %3d -> %3d\n",ctx->obuf_off,ctx->obuf_len-ctx->obuf_off,r);
+fprintf(stderr,"FLUSH [%3d] %3d -> %3d\n",ctx->obuf_off,ctx->obuf_len,r);
 #endif
                                BIO_copy_next_retry(b);
                                if (r <= 0) return((long)r);
                                ctx->obuf_off+=r;
+                               ctx->obuf_len-=r;
                                }
                        else
                                {
index ebb4278..ab47abc 100644 (file)
@@ -95,6 +95,7 @@ extern "C" {
 #define BIO_TYPE_BIO           (19|0x0400)             /* (half a) BIO pair */
 #define BIO_TYPE_LINEBUFFER    (20|0x0200)             /* filter */
 #define BIO_TYPE_DGRAM         (21|0x0400|0x0100)
+#define BIO_TYPE_ASN1          (22|0x0200)             /* filter */
 #define BIO_TYPE_COMP          (23|0x0200)             /* filter */
 
 #define BIO_TYPE_DESCRIPTOR    0x0100  /* socket, fd, connect or accept */
@@ -265,7 +266,6 @@ int BIO_method_type(const BIO *b);
 
 typedef void bio_info_cb(struct bio_st *, int, const char *, int, long, long);
 
-#ifndef OPENSSL_SYS_WIN16
 typedef struct bio_method_st
        {
        int type;
@@ -279,21 +279,6 @@ typedef struct bio_method_st
        int (*destroy)(BIO *);
         long (*callback_ctrl)(BIO *, int, bio_info_cb *);
        } BIO_METHOD;
-#else
-typedef struct bio_method_st
-       {
-       int type;
-       const char *name;
-       int (_far *bwrite)();
-       int (_far *bread)();
-       int (_far *bputs)();
-       int (_far *bgets)();
-       long (_far *ctrl)();
-       int (_far *create)();
-       int (_far *destroy)();
-       long (_far *callback_ctrl)();
-       } BIO_METHOD;
-#endif
 
 struct bio_st
        {
@@ -321,6 +306,15 @@ DECLARE_STACK_OF(BIO)
 
 typedef struct bio_f_buffer_ctx_struct
        {
+       /* Buffers are setup like this:
+        *
+        * <---------------------- size ----------------------->
+        * +---------------------------------------------------+
+        * | consumed | remaining          | free space        |
+        * +---------------------------------------------------+
+        * <-- off --><------- len ------->
+        */
+
        /* BIO *bio; */ /* this is now in the BIO struct */
        int ibuf_size;  /* how big is the input buffer */
        int obuf_size;  /* how big is the output buffer */
@@ -334,6 +328,9 @@ typedef struct bio_f_buffer_ctx_struct
        int obuf_off;           /* write/read offset */
        } BIO_F_BUFFER_CTX;
 
+/* Prefix and suffix callback in ASN1 BIO */
+typedef int asn1_ps_func(BIO *b, unsigned char **pbuf, int *plen, void *parg);
+
 /* connect BIO stuff */
 #define BIO_CONN_S_BEFORE              1
 #define BIO_CONN_S_GET_IP              2
@@ -396,6 +393,13 @@ typedef struct bio_f_buffer_ctx_struct
 #define BIO_C_RESET_READ_REQUEST               147
 #define BIO_C_SET_MD_CTX                       148
 
+#define BIO_C_SET_PREFIX                       149
+#define BIO_C_GET_PREFIX                       150
+#define BIO_C_SET_SUFFIX                       151
+#define BIO_C_GET_SUFFIX                       152
+
+#define BIO_C_SET_EX_ARG                       153
+#define BIO_C_GET_EX_ARG                       154
 
 #define BIO_set_app_data(s,arg)                BIO_set_ex_data(s,0,arg)
 #define BIO_get_app_data(s)            BIO_get_ex_data(s,0)
@@ -559,22 +563,21 @@ int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
 unsigned long BIO_number_read(BIO *bio);
 unsigned long BIO_number_written(BIO *bio);
 
+/* For BIO_f_asn1() */
+int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix,
+                                       asn1_ps_func *prefix_free);
+int BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix,
+                                       asn1_ps_func **pprefix_free);
+int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix,
+                                       asn1_ps_func *suffix_free);
+int BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix,
+                                       asn1_ps_func **psuffix_free);
+
 # ifndef OPENSSL_NO_FP_API
-#  if defined(OPENSSL_SYS_WIN16) && defined(_WINDLL)
-BIO_METHOD *BIO_s_file_internal(void);
-BIO *BIO_new_file_internal(char *filename, char *mode);
-BIO *BIO_new_fp_internal(FILE *stream, int close_flag);
-#    define BIO_s_file BIO_s_file_internal
-#    define BIO_new_file       BIO_new_file_internal
-#    define BIO_new_fp BIO_new_fp_internal
-#  else /* FP_API */
 BIO_METHOD *BIO_s_file(void );
 BIO *BIO_new_file(const char *filename, const char *mode);
 BIO *BIO_new_fp(FILE *stream, int close_flag);
-#    define BIO_s_file_internal                BIO_s_file
-#    define BIO_new_file_internal      BIO_new_file
-#    define BIO_new_fp_internal                BIO_s_file
-#  endif /* FP_API */
+# define BIO_s_file_internal   BIO_s_file
 # endif
 BIO *  BIO_new(BIO_METHOD *type);
 int    BIO_set(BIO *a,BIO_METHOD *type);
@@ -603,13 +606,8 @@ int BIO_nread(BIO *bio, char **buf, int num);
 int BIO_nwrite0(BIO *bio, char **buf);
 int BIO_nwrite(BIO *bio, char **buf, int num);
 
-#ifndef OPENSSL_SYS_WIN16
 long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi,
        long argl,long ret);
-#else
-long _far _loadds BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi,
-       long argl,long ret);
-#endif
 
 BIO_METHOD *BIO_s_mem(void);
 BIO *BIO_new_mem_buf(void *buf, int len);
index 6f4254a..9bcbc32 100644 (file)
@@ -85,28 +85,32 @@ long MS_CALLBACK BIO_debug_callback(BIO *bio, int cmd, const char *argp,
                break;
        case BIO_CB_READ:
                if (bio->method->type & BIO_TYPE_DESCRIPTOR)
-                       BIO_snprintf(p,p_maxlen,"read(%d,%d) - %s fd=%d\n",
-                                bio->num,argi,bio->method->name,bio->num);
+                       BIO_snprintf(p,p_maxlen,"read(%d,%lu) - %s fd=%d\n",
+                                bio->num,(unsigned long)argi,
+                                bio->method->name,bio->num);
                else
-                       BIO_snprintf(p,p_maxlen,"read(%d,%d) - %s\n",
-                                bio->num,argi,bio->method->name);
+                       BIO_snprintf(p,p_maxlen,"read(%d,%lu) - %s\n",
+                                bio->num,(unsigned long)argi,
+                                bio->method->name);
                break;
        case BIO_CB_WRITE:
                if (bio->method->type & BIO_TYPE_DESCRIPTOR)
-                       BIO_snprintf(p,p_maxlen,"write(%d,%d) - %s fd=%d\n",
-                                bio->num,argi,bio->method->name,bio->num);
+                       BIO_snprintf(p,p_maxlen,"write(%d,%lu) - %s fd=%d\n",
+                                bio->num,(unsigned long)argi,
+                                bio->method->name,bio->num);
                else
-                       BIO_snprintf(p,p_maxlen,"write(%d,%d) - %s\n",
-                                bio->num,argi,bio->method->name);
+                       BIO_snprintf(p,p_maxlen,"write(%d,%lu) - %s\n",
+                                bio->num,(unsigned long)argi,
+                                bio->method->name);
                break;
        case BIO_CB_PUTS:
                BIO_snprintf(p,p_maxlen,"puts() - %s\n",bio->method->name);
                break;
        case BIO_CB_GETS:
-               BIO_snprintf(p,p_maxlen,"gets(%d) - %s\n",argi,bio->method->name);
+               BIO_snprintf(p,p_maxlen,"gets(%lu) - %s\n",(unsigned long)argi,bio->method->name);
                break;
        case BIO_CB_CTRL:
-               BIO_snprintf(p,p_maxlen,"ctrl(%d) - %s\n",argi,bio->method->name);
+               BIO_snprintf(p,p_maxlen,"ctrl(%lu) - %s\n",(unsigned long)argi,bio->method->name);
                break;
        case BIO_CB_RETURN|BIO_CB_READ:
                BIO_snprintf(p,p_maxlen,"read return %ld\n",ret);
index 6603f1c..a224edd 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/bio/bio_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
index dba2919..e7f7ec8 100644 (file)
 #define        UP_ftell        ftell
 #define        UP_fflush       fflush
 #define        UP_ferror       ferror
+#ifdef _WIN32
+#define        UP_fileno       _fileno
+#define        UP_open         _open
+#define        UP_read         _read
+#define        UP_write        _write
+#define        UP_lseek        _lseek
+#define        UP_close        _close
+#else
 #define        UP_fileno       fileno
-
 #define        UP_open         open
 #define        UP_read         read
 #define        UP_write        write
 #define        UP_lseek        lseek
 #define        UP_close        close
 #endif
+#endif
index 371cdf5..e12bc3a 100644 (file)
@@ -429,7 +429,7 @@ BIO *BIO_push(BIO *b, BIO *bio)
        if (bio != NULL)
                bio->prev_bio=lb;
        /* called to do internal processing */
-       BIO_ctrl(b,BIO_CTRL_PUSH,0,NULL);
+       BIO_ctrl(b,BIO_CTRL_PUSH,0,lb);
        return(b);
        }
 
@@ -441,7 +441,7 @@ BIO *BIO_pop(BIO *b)
        if (b == NULL) return(NULL);
        ret=b->next_bio;
 
-       BIO_ctrl(b,BIO_CTRL_POP,0,NULL);
+       BIO_ctrl(b,BIO_CTRL_POP,0,b);
 
        if (b->prev_bio != NULL)
                b->prev_bio->next_bio=b->next_bio;
index e7fb892..5d49e1a 100644 (file)
@@ -100,8 +100,8 @@ static int acpt_new(BIO *h);
 static int acpt_free(BIO *data);
 static int acpt_state(BIO *b, BIO_ACCEPT *c);
 static void acpt_close_socket(BIO *data);
-BIO_ACCEPT *BIO_ACCEPT_new(void );
-void BIO_ACCEPT_free(BIO_ACCEPT *a);
+static BIO_ACCEPT *BIO_ACCEPT_new(void );
+static void BIO_ACCEPT_free(BIO_ACCEPT *a);
 
 #define ACPT_S_BEFORE                  1
 #define ACPT_S_GET_ACCEPT_SOCKET       2
@@ -141,7 +141,7 @@ static int acpt_new(BIO *bi)
        return(1);
        }
 
-BIO_ACCEPT *BIO_ACCEPT_new(void)
+static BIO_ACCEPT *BIO_ACCEPT_new(void)
        {
        BIO_ACCEPT *ret;
 
@@ -154,7 +154,7 @@ BIO_ACCEPT *BIO_ACCEPT_new(void)
        return(ret);
        }
 
-void BIO_ACCEPT_free(BIO_ACCEPT *a)
+static void BIO_ACCEPT_free(BIO_ACCEPT *a)
        {
        if(a == NULL)
            return;
index 14ca854..71ebe98 100644 (file)
@@ -57,7 +57,6 @@
  *
  */
 
-#ifndef OPENSSL_NO_DGRAM
 
 #include <stdio.h>
 #include <errno.h>
@@ -65,6 +64,7 @@
 #include "cryptlib.h"
 
 #include <openssl/bio.h>
+#ifndef OPENSSL_NO_DGRAM
 
 #if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS)
 #include <sys/timeb.h>
@@ -108,7 +108,13 @@ static BIO_METHOD methods_dgramp=
 
 typedef struct bio_dgram_data_st
        {
-       struct sockaddr peer;
+       union {
+               struct sockaddr sa;
+               struct sockaddr_in sa_in;
+#if OPENSSL_USE_IPV6
+               struct sockaddr_in6 sa_in6;
+#endif
+       } peer;
        unsigned int connected;
        unsigned int _errno;
        unsigned int mtu;
@@ -274,24 +280,37 @@ static int dgram_read(BIO *b, char *out, int outl)
        int ret=0;
        bio_dgram_data *data = (bio_dgram_data *)b->ptr;
 
-       struct sockaddr peer;
-       int peerlen = sizeof(peer);
+       struct  {
+       /*
+        * See commentary in b_sock.c. <appro>
+        */
+       union   { size_t s; int i; } len;
+       union   {
+               struct sockaddr sa;
+               struct sockaddr_in sa_in;
+#if OPENSSL_USE_IPV6
+               struct sockaddr_in6 sa_in6;
+#endif
+               } peer;
+       } sa;
+
+       sa.len.s=0;
+       sa.len.i=sizeof(sa.peer);
 
        if (out != NULL)
                {
                clear_socket_error();
-               memset(&peer, 0x00, peerlen);
-               /* Last arg in recvfrom is signed on some platforms and
-                * unsigned on others. It is of type socklen_t on some
-                * but this is not universal. Cast to (void *) to avoid
-                * compiler warnings.
-                */
+               memset(&sa.peer, 0x00, sizeof(sa.peer));
                dgram_adjust_rcv_timeout(b);
-               ret=recvfrom(b->num,out,outl,0,&peer,(void *)&peerlen);
-               dgram_reset_rcv_timeout(b);
+               ret=recvfrom(b->num,out,outl,0,&sa.peer.sa,(void *)&sa.len);
+               if (sizeof(sa.len.i)!=sizeof(sa.len.s) && sa.len.i==0)
+                       {
+                       OPENSSL_assert(sa.len.s<=sizeof(sa.peer));
+                       sa.len.i = (int)sa.len.s;
+                       }
 
                if ( ! data->connected  && ret >= 0)
-                       BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, &peer);
+                       BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, &sa.peer);
 
                BIO_clear_retry_flags(b);
                if (ret < 0)
@@ -302,6 +321,8 @@ static int dgram_read(BIO *b, char *out, int outl)
                                data->_errno = get_last_socket_error();
                                }
                        }
+
+               dgram_reset_rcv_timeout(b);
                }
        return(ret);
        }
@@ -312,14 +333,24 @@ static int dgram_write(BIO *b, const char *in, int inl)
        bio_dgram_data *data = (bio_dgram_data *)b->ptr;
        clear_socket_error();
 
-    if ( data->connected )
-        ret=writesocket(b->num,in,inl);
-    else
+       if ( data->connected )
+               ret=writesocket(b->num,in,inl);
+       else
+               {
+               int peerlen = sizeof(data->peer);
+
+               if (data->peer.sa.sa_family == AF_INET)
+                       peerlen = sizeof(data->peer.sa_in);
+#if OPENSSL_USE_IPV6
+               else if (data->peer.sa.sa_family == AF_INET6)
+                       peerlen = sizeof(data->peer.sa_in6);
+#endif
 #if defined(NETWARE_CLIB) && defined(NETWARE_BSDSOCK)
-        ret=sendto(b->num, (char *)in, inl, 0, &data->peer, sizeof(data->peer));
+               ret=sendto(b->num, (char *)in, inl, 0, &data->peer.sa, peerlen);
 #else
-        ret=sendto(b->num, in, inl, 0, &data->peer, sizeof(data->peer));
+               ret=sendto(b->num, in, inl, 0, &data->peer.sa, peerlen);
 #endif
+               }
 
        BIO_clear_retry_flags(b);
        if (ret <= 0)
@@ -351,7 +382,13 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
 #endif
 #ifdef OPENSSL_SYS_LINUX
        socklen_t addr_len;
-       struct sockaddr_storage addr;
+       union   {
+               struct sockaddr sa;
+               struct sockaddr_in s4;
+#if OPENSSL_USE_IPV6
+               struct sockaddr_in6 s6;
+#endif
+               } addr;
 #endif
 
        data = (bio_dgram_data *)b->ptr;
@@ -405,7 +442,20 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
                else
                        {
 #endif
-                       memcpy(&(data->peer),to, sizeof(struct sockaddr));
+                       switch (to->sa_family)
+                               {
+                               case AF_INET:
+                                       memcpy(&data->peer,to,sizeof(data->peer.sa_in));
+                                       break;
+#if OPENSSL_USE_IPV6
+                               case AF_INET6:
+                                       memcpy(&data->peer,to,sizeof(data->peer.sa_in6));
+                                       break;
+#endif
+                               default:
+                                       memcpy(&data->peer,to,sizeof(data->peer.sa));
+                                       break;
+                               }
 #if 0
                        }
 #endif
@@ -413,15 +463,15 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
                /* (Linux)kernel sets DF bit on outgoing IP packets */
        case BIO_CTRL_DGRAM_MTU_DISCOVER:
 #ifdef OPENSSL_SYS_LINUX
-               addr_len = (socklen_t)sizeof(struct sockaddr_storage);
-               memset((void *)&addr, 0, sizeof(struct sockaddr_storage));
-               if (getsockname(b->num, (void *)&addr, &addr_len) < 0)
+               addr_len = (socklen_t)sizeof(addr);
+               memset((void *)&addr, 0, sizeof(addr));
+               if (getsockname(b->num, &addr.sa, &addr_len) < 0)
                        {
                        ret = 0;
                        break;
                        }
                sockopt_len = sizeof(sockopt_val);
-               switch (addr.ss_family)
+               switch (addr.sa.sa_family)
                        {
                case AF_INET:
                        sockopt_val = IP_PMTUDISC_DO;
@@ -429,12 +479,14 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
                                &sockopt_val, sizeof(sockopt_val))) < 0)
                                perror("setsockopt");
                        break;
+#if OPENSSL_USE_IPV6 && defined(IPV6_MTU_DISCOVER)
                case AF_INET6:
                        sockopt_val = IPV6_PMTUDISC_DO;
                        if ((ret = setsockopt(b->num, IPPROTO_IPV6, IPV6_MTU_DISCOVER,
                                &sockopt_val, sizeof(sockopt_val))) < 0)
                                perror("setsockopt");
                        break;
+#endif
                default:
                        ret = -1;
                        break;
@@ -445,15 +497,15 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
 #endif
        case BIO_CTRL_DGRAM_QUERY_MTU:
 #ifdef OPENSSL_SYS_LINUX
-               addr_len = (socklen_t)sizeof(struct sockaddr_storage);
-               memset((void *)&addr, 0, sizeof(struct sockaddr_storage));
-               if (getsockname(b->num, (void *)&addr, &addr_len) < 0)
+               addr_len = (socklen_t)sizeof(addr);
+               memset((void *)&addr, 0, sizeof(addr));
+               if (getsockname(b->num, &addr.sa, &addr_len) < 0)
                        {
                        ret = 0;
                        break;
                        }
                sockopt_len = sizeof(sockopt_val);
-               switch (addr.ss_family)
+               switch (addr.sa.sa_family)
                        {
                case AF_INET:
                        if ((ret = getsockopt(b->num, IPPROTO_IP, IP_MTU, (void *)&sockopt_val,
@@ -470,6 +522,7 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
                                ret = data->mtu;
                                }
                        break;
+#if OPENSSL_USE_IPV6 && defined(IPV6_MTU)
                case AF_INET6:
                        if ((ret = getsockopt(b->num, IPPROTO_IPV6, IPV6_MTU, (void *)&sockopt_val,
                                &sockopt_len)) < 0 || sockopt_val < 0)
@@ -485,6 +538,7 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
                                ret = data->mtu;
                                }
                        break;
+#endif
                default:
                        ret = 0;
                        break;
@@ -506,27 +560,65 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
                if ( to != NULL)
                        {
                        data->connected = 1;
-                       memcpy(&(data->peer),to, sizeof(struct sockaddr));
+                       switch (to->sa_family)
+                               {
+                               case AF_INET:
+                                       memcpy(&data->peer,to,sizeof(data->peer.sa_in));
+                                       break;
+#if OPENSSL_USE_IPV6
+                               case AF_INET6:
+                                       memcpy(&data->peer,to,sizeof(data->peer.sa_in6));
+                                       break;
+#endif
+                               default:
+                                       memcpy(&data->peer,to,sizeof(data->peer.sa));
+                                       break;
+                               }
                        }
                else
                        {
                        data->connected = 0;
-                       memset(&(data->peer), 0x00, sizeof(struct sockaddr));
+                       memset(&(data->peer), 0x00, sizeof(data->peer));
+                       }
+               break;
+       case BIO_CTRL_DGRAM_GET_PEER:
+               switch (data->peer.sa.sa_family)
+                       {
+                       case AF_INET:
+                               ret=sizeof(data->peer.sa_in);
+                               break;
+#if OPENSSL_USE_IPV6
+                       case AF_INET6:
+                               ret=sizeof(data->peer.sa_in6);
+                               break;
+#endif
+                       default:
+                               ret=sizeof(data->peer.sa);
+                               break;
+                       }
+               if (num==0 || num>ret)
+                       num=ret;
+               memcpy(ptr,&data->peer,(ret=num));
+               break;
+       case BIO_CTRL_DGRAM_SET_PEER:
+               to = (struct sockaddr *) ptr;
+               switch (to->sa_family)
+                       {
+                       case AF_INET:
+                               memcpy(&data->peer,to,sizeof(data->peer.sa_in));
+                               break;
+#if OPENSSL_USE_IPV6
+                       case AF_INET6:
+                               memcpy(&data->peer,to,sizeof(data->peer.sa_in6));
+                               break;
+#endif
+                       default:
+                               memcpy(&data->peer,to,sizeof(data->peer.sa));
+                               break;
                        }
                break;
-    case BIO_CTRL_DGRAM_GET_PEER:
-        to = (struct sockaddr *) ptr;
-
-        memcpy(to, &(data->peer), sizeof(struct sockaddr));
-               ret = sizeof(struct sockaddr);
-        break;
-    case BIO_CTRL_DGRAM_SET_PEER:
-        to = (struct sockaddr *) ptr;
-
-        memcpy(&(data->peer), to, sizeof(struct sockaddr));
-        break;
        case BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT:
-               memcpy(&(data->next_timeout), ptr, sizeof(struct timeval));             
+               memcpy(&(data->next_timeout), ptr, sizeof(struct timeval));
                break;
 #if defined(SO_RCVTIMEO)
        case BIO_CTRL_DGRAM_SET_RECV_TIMEOUT:
@@ -654,9 +746,13 @@ static int BIO_dgram_should_retry(int i)
                {
                err=get_last_socket_error();
 
-#if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */
-               if ((i == -1) && (err == 0))
-                       return(1);
+#if defined(OPENSSL_SYS_WINDOWS)
+       /* If the socket return value (i) is -1
+        * and err is unexpectedly 0 at this point,
+        * the error code was overwritten by
+        * another system call before this error
+        * handling is called.
+        */
 #endif
 
                return(BIO_dgram_non_fatal_error(err));
@@ -719,7 +815,6 @@ int BIO_dgram_non_fatal_error(int err)
                }
        return(0);
        }
-#endif
 
 static void get_current_time(struct timeval *t)
        {
@@ -737,3 +832,5 @@ static void get_current_time(struct timeval *t)
        gettimeofday(t, NULL);
 #endif
        }
+
+#endif
index 4c229bf..d1bf85a 100644 (file)
 #include <errno.h>
 #define USE_SOCKETS
 #include "cryptlib.h"
+
+#if defined(OPENSSL_NO_POSIX_IO)
+/*
+ * One can argue that one should implement dummy placeholder for
+ * BIO_s_fd here...
+ */
+#else
 /*
  * As for unconditional usage of "UPLINK" interface in this module.
  * Trouble is that unlike Unix file descriptors [which are indexes
@@ -77,6 +84,7 @@
 static int fd_write(BIO *h, const char *buf, int num);
 static int fd_read(BIO *h, char *buf, int size);
 static int fd_puts(BIO *h, const char *str);
+static int fd_gets(BIO *h, char *buf, int size);
 static long fd_ctrl(BIO *h, int cmd, long arg1, void *arg2);
 static int fd_new(BIO *h);
 static int fd_free(BIO *data);
@@ -88,7 +96,7 @@ static BIO_METHOD methods_fdp=
        fd_write,
        fd_read,
        fd_puts,
-       NULL, /* fd_gets, */
+       fd_gets,
        fd_ctrl,
        fd_new,
        fd_free,
@@ -227,6 +235,22 @@ static int fd_puts(BIO *bp, const char *str)
        return(ret);
        }
 
+static int fd_gets(BIO *bp, char *buf, int size)
+        {
+       int ret=0;
+       char *ptr=buf;
+       char *end=buf+size-1;
+
+       while ( (ptr < end) && (fd_read(bp, ptr, 1) > 0) && (ptr[0] != '\n') )
+               ptr++;
+
+       ptr[0]='\0';
+
+       if (buf[0] != '\0')
+               ret=strlen(buf);
+       return(ret);
+        }
+
 int BIO_fd_should_retry(int i)
        {
        int err;
@@ -292,3 +316,4 @@ int BIO_fd_non_fatal_error(int err)
                }
        return(0);
        }
+#endif
index 47fa266..b954fe7 100644 (file)
@@ -118,10 +118,53 @@ static BIO_METHOD methods_filep=
 
 BIO *BIO_new_file(const char *filename, const char *mode)
        {
-       BIO *ret;
-       FILE *file;
+       BIO  *ret;
+       FILE *file=NULL;
+
+#if defined(_WIN32) && defined(CP_UTF8)
+       int sz, len_0 = (int)strlen(filename)+1;
+       DWORD flags;
 
-       if ((file=fopen(filename,mode)) == NULL)
+       /*
+        * Basically there are three cases to cover: a) filename is
+        * pure ASCII string; b) actual UTF-8 encoded string and
+        * c) locale-ized string, i.e. one containing 8-bit
+        * characters that are meaningful in current system locale.
+        * If filename is pure ASCII or real UTF-8 encoded string,
+        * MultiByteToWideChar succeeds and _wfopen works. If
+        * filename is locale-ized string, chances are that
+        * MultiByteToWideChar fails reporting
+        * ERROR_NO_UNICODE_TRANSLATION, in which case we fall
+        * back to fopen...
+        */
+       if ((sz=MultiByteToWideChar(CP_UTF8,(flags=MB_ERR_INVALID_CHARS),
+                                       filename,len_0,NULL,0))>0 ||
+           (GetLastError()==ERROR_INVALID_FLAGS &&
+            (sz=MultiByteToWideChar(CP_UTF8,(flags=0),
+                                       filename,len_0,NULL,0))>0)
+          )
+               {
+               WCHAR  wmode[8];
+               WCHAR *wfilename = _alloca(sz*sizeof(WCHAR));
+
+               if (MultiByteToWideChar(CP_UTF8,flags,
+                                       filename,len_0,wfilename,sz) &&
+                   MultiByteToWideChar(CP_UTF8,0,mode,strlen(mode)+1,
+                                       wmode,sizeof(wmode)/sizeof(wmode[0])) &&
+                   (file=_wfopen(wfilename,wmode))==NULL &&
+                   (errno==ENOENT || errno==EBADF)
+                  )    /* UTF-8 decode succeeded, but no file, filename
+                        * could still have been locale-ized... */
+                       file = fopen(filename,mode);
+               }
+       else if (GetLastError()==ERROR_NO_UNICODE_TRANSLATION)
+               {
+               file = fopen(filename,mode);
+               }
+#else
+       file=fopen(filename,mode);      
+#endif
+       if (file == NULL)
                {
                SYSerr(SYS_F_FOPEN,get_last_sys_error());
                ERR_add_error_data(5,"fopen('",filename,"','",mode,"')");
@@ -131,7 +174,7 @@ BIO *BIO_new_file(const char *filename, const char *mode)
                        BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB);
                return(NULL);
                }
-       if ((ret=BIO_new(BIO_s_file_internal())) == NULL)
+       if ((ret=BIO_new(BIO_s_file())) == NULL)
                {
                fclose(file);
                return(NULL);
@@ -286,8 +329,7 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr)
                        _setmode(fd,_O_BINARY);
 #elif defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB)
                int fd = fileno((FILE*)ptr);
-         /* Under CLib there are differences in file modes
-         */
+               /* Under CLib there are differences in file modes */
                if (num & BIO_FP_TEXT)
                        setmode(fd,O_TEXT);
                else
@@ -308,7 +350,7 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr)
                        else
                                _setmode(fd,_O_BINARY);
                        }
-#elif defined(OPENSSL_SYS_OS2)
+#elif defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN)
                int fd = fileno((FILE*)ptr);
                if (num & BIO_FP_TEXT)
                        setmode(fd, O_TEXT);
index 6360dbc..b7dce5c 100644 (file)
 
 #if defined(OPENSSL_SYS_WINCE)
 #elif defined(OPENSSL_SYS_WIN32)
-#  include <process.h>
 #elif defined(OPENSSL_SYS_VMS)
 #  include <opcdef.h>
 #  include <descrip.h>
 #  include <lib$routines.h>
 #  include <starlet.h>
+/* Some compiler options may mask the declaration of "_malloc32". */
+#  if __INITIAL_POINTER_SIZE && defined _ANSI_C_SOURCE
+#    if __INITIAL_POINTER_SIZE == 64
+#      pragma pointer_size save
+#      pragma pointer_size 32
+    void * _malloc32  (__size_t);
+#      pragma pointer_size restore
+#    endif /* __INITIAL_POINTER_SIZE == 64 */
+#  endif /* __INITIAL_POINTER_SIZE && defined _ANSI_C_SOURCE */
 #elif defined(__ultrix)
 #  include <sys/syslog.h>
 #elif defined(OPENSSL_SYS_NETWARE)
@@ -122,18 +130,6 @@ static int MS_CALLBACK slg_free(BIO *data);
 static void xopenlog(BIO* bp, char* name, int level);
 static void xsyslog(BIO* bp, int priority, const char* string);
 static void xcloselog(BIO* bp);
-#ifdef OPENSSL_SYS_WIN32
-LONG   (WINAPI *go_for_advapi)()       = RegOpenKeyEx;
-HANDLE (WINAPI *register_event_source)()       = NULL;
-BOOL   (WINAPI *deregister_event_source)()     = NULL;
-BOOL   (WINAPI *report_event)()        = NULL;
-#define DL_PROC(m,f)   (GetProcAddress( m, f ))
-#ifdef UNICODE
-#define DL_PROC_X(m,f) DL_PROC( m, f "W" )
-#else
-#define DL_PROC_X(m,f) DL_PROC( m, f "A" )
-#endif
-#endif
 
 static BIO_METHOD methods_slg=
        {
@@ -175,7 +171,7 @@ static int MS_CALLBACK slg_write(BIO *b, const char *in, int inl)
        char* buf;
        char* pp;
        int priority, i;
-       static struct
+       static const struct
                {
                int strl;
                char str[10];
@@ -249,35 +245,20 @@ static int MS_CALLBACK slg_puts(BIO *bp, const char *str)
 
 static void xopenlog(BIO* bp, char* name, int level)
 {
-       if ( !register_event_source )
-               {
-               HANDLE  advapi;
-               if ( !(advapi = GetModuleHandle("advapi32")) )
-                       return;
-               register_event_source = (HANDLE (WINAPI *)())DL_PROC_X(advapi,
-                       "RegisterEventSource" );
-               deregister_event_source = (BOOL (WINAPI *)())DL_PROC(advapi,
-                       "DeregisterEventSource");
-               report_event = (BOOL (WINAPI *)())DL_PROC_X(advapi,
-                       "ReportEvent" );
-               if ( !(register_event_source && deregister_event_source &&
-                               report_event) )
-                       {
-                       register_event_source = NULL;
-                       deregister_event_source = NULL;
-                       report_event = NULL;
-                       return;
-                       }
-               }
-       bp->ptr= (char *)register_event_source(NULL, name);
+       if (GetVersion() < 0x80000000)
+               bp->ptr = RegisterEventSourceA(NULL,name);
+       else
+               bp->ptr = NULL;
 }
 
 static void xsyslog(BIO *bp, int priority, const char *string)
 {
        LPCSTR lpszStrings[2];
        WORD evtype= EVENTLOG_ERROR_TYPE;
-       int pid = _getpid();
-       char pidbuf[DECIMAL_SIZE(pid)+4];
+       char pidbuf[DECIMAL_SIZE(DWORD)+4];
+
+       if (bp->ptr == NULL)
+               return;
 
        switch (priority)
                {
@@ -301,19 +282,18 @@ static void xsyslog(BIO *bp, int priority, const char *string)
                break;
                }
 
-       sprintf(pidbuf, "[%d] ", pid);
+       sprintf(pidbuf, "[%u] ", GetCurrentProcessId());
        lpszStrings[0] = pidbuf;
        lpszStrings[1] = string;
 
-       if(report_event && bp->ptr)
-               report_event(bp->ptr, evtype, 0, 1024, NULL, 2, 0,
+       ReportEventA(bp->ptr, evtype, 0, 1024, NULL, 2, 0,
                                lpszStrings, NULL);
 }
        
 static void xcloselog(BIO* bp)
 {
-       if(deregister_event_source && bp->ptr)
-               deregister_event_source((HANDLE)(bp->ptr));
+       if(bp->ptr)
+               DeregisterEventSource((HANDLE)(bp->ptr));
        bp->ptr= NULL;
 }
 
@@ -329,7 +309,24 @@ static void xopenlog(BIO* bp, char* name, int level)
 static void xsyslog(BIO *bp, int priority, const char *string)
 {
        struct dsc$descriptor_s opc_dsc;
+
+/* Arrange 32-bit pointer to opcdef buffer and malloc(), if needed. */
+#if __INITIAL_POINTER_SIZE == 64
+# pragma pointer_size save
+# pragma pointer_size 32
+# define OPCDEF_TYPE __char_ptr32
+# define OPCDEF_MALLOC _malloc32
+#else /* __INITIAL_POINTER_SIZE == 64 */
+# define OPCDEF_TYPE char *
+# define OPCDEF_MALLOC OPENSSL_malloc
+#endif /* __INITIAL_POINTER_SIZE == 64 [else] */
+
        struct opcdef *opcdef_p;
+
+#if __INITIAL_POINTER_SIZE == 64
+# pragma pointer_size restore
+#endif /* __INITIAL_POINTER_SIZE == 64 */
+
        char buf[10240];
        unsigned int len;
         struct dsc$descriptor_s buf_dsc;
@@ -355,8 +352,8 @@ static void xsyslog(BIO *bp, int priority, const char *string)
 
        lib$sys_fao(&fao_cmd, &len, &buf_dsc, priority_tag, string);
 
-       /* we know there's an 8 byte header.  That's documented */
-       opcdef_p = (struct opcdef *) OPENSSL_malloc(8 + len);
+       /* We know there's an 8-byte header.  That's documented. */
+       opcdef_p = OPCDEF_MALLOC( 8+ len);
        opcdef_p->opc$b_ms_type = OPC$_RQ_RQST;
        memcpy(opcdef_p->opc$z_ms_target_classes, &VMS_OPC_target, 3);
        opcdef_p->opc$l_ms_rqstid = 0;
@@ -364,7 +361,7 @@ static void xsyslog(BIO *bp, int priority, const char *string)
 
        opc_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
        opc_dsc.dsc$b_class = DSC$K_CLASS_S;
-       opc_dsc.dsc$a_pointer = (char *)opcdef_p;
+       opc_dsc.dsc$a_pointer = (OPCDEF_TYPE) opcdef_p;
        opc_dsc.dsc$w_length = len + 8;
 
        sys$sndopr(opc_dsc, 0);
index e7ab9cb..37d4194 100644 (file)
@@ -94,16 +94,18 @@ BIO *BIO_new_mem_buf(void *buf, int len)
 {
        BIO *ret;
        BUF_MEM *b;
+       size_t sz;
+
        if (!buf) {
                BIOerr(BIO_F_BIO_NEW_MEM_BUF,BIO_R_NULL_PARAMETER);
                return NULL;
        }
-       if(len == -1) len = strlen(buf);
+       sz = (len<0) ? strlen(buf) : (size_t)len;
        if(!(ret = BIO_new(BIO_s_mem())) ) return NULL;
        b = (BUF_MEM *)ret->ptr;
        b->data = buf;
-       b->length = len;
-       b->max = len;
+       b->length = sz;
+       b->max = sz;
        ret->flags |= BIO_FLAGS_MEM_RDONLY;
        /* Since this is static data retrying wont help */
        ret->num = 0;
@@ -144,22 +146,16 @@ static int mem_read(BIO *b, char *out, int outl)
        {
        int ret= -1;
        BUF_MEM *bm;
-       int i;
-       char *from,*to;
 
        bm=(BUF_MEM *)b->ptr;
        BIO_clear_retry_flags(b);
-       ret=(outl > bm->length)?bm->length:outl;
+       ret=(outl >=0 && (size_t)outl > bm->length)?(int)bm->length:outl;
        if ((out != NULL) && (ret > 0)) {
                memcpy(out,bm->data,ret);
                bm->length-=ret;
-               /* memmove(&(bm->data[0]),&(bm->data[ret]), bm->length); */
                if(b->flags & BIO_FLAGS_MEM_RDONLY) bm->data += ret;
                else {
-                       from=(char *)&(bm->data[ret]);
-                       to=(char *)&(bm->data[0]);
-                       for (i=0; i<bm->length; i++)
-                               to[i]=from[i];
+                       memmove(&(bm->data[0]),&(bm->data[ret]),bm->length);
                }
        } else if (bm->length == 0)
                {
index f5e8f65..aabc4f5 100644 (file)
@@ -12,8 +12,6 @@ MAKEFILE=     Makefile
 AR=            ar r
 
 BN_ASM=                bn_asm.o
-# or use
-#BN_ASM=       bn86-elf.o
 
 CFLAGS= $(INCLUDES) $(CFLAG)
 ASFLAGS= $(INCLUDES) $(ASFLAG)
@@ -28,13 +26,13 @@ LIBSRC=     bn_add.c bn_div.c bn_exp.c bn_lib.c bn_ctx.c bn_mul.c bn_mod.c \
        bn_print.c bn_rand.c bn_shift.c bn_word.c bn_blind.c \
        bn_kron.c bn_sqrt.c bn_gcd.c bn_prime.c bn_err.c bn_sqr.c bn_asm.c \
        bn_recp.c bn_mont.c bn_mpi.c bn_exp2.c bn_gf2m.c bn_nist.c \
-       bn_depr.c bn_x931p.c bn_const.c bn_opt.c
+       bn_depr.c bn_const.c
 
 LIBOBJ=        bn_add.o bn_div.o bn_exp.o bn_lib.o bn_ctx.o bn_mul.o bn_mod.o \
        bn_print.o bn_rand.o bn_shift.o bn_word.o bn_blind.o \
        bn_kron.o bn_sqrt.o bn_gcd.o bn_prime.o bn_err.o bn_sqr.o $(BN_ASM) \
        bn_recp.o bn_mont.o bn_mpi.o bn_exp2.o bn_gf2m.o bn_nist.o \
-       bn_depr.o bn_x931p.o bn_const.o bn_opt.o
+       bn_depr.o bn_const.o
 
 SRC= $(LIBSRC)
 
@@ -58,36 +56,25 @@ bnbug: bnbug.c ../../libcrypto.a top
        cc -g -I../../include bnbug.c -o bnbug ../../libcrypto.a
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
-# ELF
-bn86-elf.s:    asm/bn-586.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) bn-586.pl elf $(CFLAGS) > ../$@)
-co86-elf.s:    asm/co-586.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) co-586.pl elf $(CFLAGS) > ../$@)
-mo86-elf.s:    asm/mo-586.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) mo-586.pl elf $(CFLAGS) > ../$@)
-# COFF
-bn86-cof.s: asm/bn-586.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) bn-586.pl coff $(CFLAGS) > ../$@)
-co86-cof.s: asm/co-586.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) co-586.pl coff $(CFLAGS) > ../$@)
-mo86-cof.s: asm/mo-586.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) mo-586.pl coff $(CFLAGS) > ../$@)
-# a.out
-bn86-out.s: asm/bn-586.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) bn-586.pl a.out $(CFLAGS) > ../$@)
-co86-out.s: asm/co-586.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) co-586.pl a.out $(CFLAGS) > ../$@)
-mo86-out.s: asm/mo-586.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) mo-586.pl a.out $(CFLAGS) > ../$@)
+bn-586.s:      asm/bn-586.pl ../perlasm/x86asm.pl
+       $(PERL) asm/bn-586.pl $(PERLASM_SCHEME) $(CFLAGS) $(PROCESSOR) > $@
+co-586.s:      asm/co-586.pl ../perlasm/x86asm.pl
+       $(PERL) asm/co-586.pl $(PERLASM_SCHEME) $(CFLAGS) $(PROCESSOR) > $@
+x86-mont.s:    asm/x86-mont.pl ../perlasm/x86asm.pl
+       $(PERL) asm/x86-mont.pl $(PERLASM_SCHEME) $(CFLAGS) $(PROCESSOR) > $@
 
 sparcv8.o:     asm/sparcv8.S
        $(CC) $(CFLAGS) -c asm/sparcv8.S
-sparcv8plus.o: asm/sparcv8plus.S
-       $(CC) $(CFLAGS) -c asm/sparcv8plus.S
+bn-sparcv9.o:  asm/sparcv8plus.S
+       $(CC) $(CFLAGS) -c -o $@ asm/sparcv8plus.S
+sparcv9a-mont.s:       asm/sparcv9a-mont.pl
+       $(PERL) asm/sparcv9a-mont.pl $(CFLAGS) > $@
+sparcv9-mont.s:                asm/sparcv9-mont.pl
+       $(PERL) asm/sparcv9-mont.pl $(CFLAGS) > $@
 
 bn-mips3.o:    asm/mips3.s
        @if [ "$(CC)" = "gcc" ]; then \
@@ -95,10 +82,13 @@ bn-mips3.o: asm/mips3.s
                as -$$ABI -O -o $@ asm/mips3.s; \
        else    $(CC) -c $(CFLAGS) -o $@ asm/mips3.s; fi
 
+bn-s390x.o:    asm/s390x.S
+       $(CC) $(CFLAGS) -c -o $@ asm/s390x.S
+
 x86_64-gcc.o:  asm/x86_64-gcc.c
        $(CC) $(CFLAGS) -c -o $@ asm/x86_64-gcc.c
 x86_64-mont.s: asm/x86_64-mont.pl
-       $(PERL) asm/x86_64-mont.pl $@
+       $(PERL) asm/x86_64-mont.pl $(PERLASM_SCHEME) > $@
 
 bn-ia64.s:     asm/ia64.S
        $(CC) $(CFLAGS) -E asm/ia64.S > $@
@@ -111,12 +101,14 @@ pa-risc2.o: asm/pa-risc2.s
        /usr/ccs/bin/as -o pa-risc2.o asm/pa-risc2.s
 
 # ppc - AIX, Linux, MacOS X...
-linux_ppc32.s: asm/ppc.pl;     $(PERL) $< $@
-linux_ppc64.s: asm/ppc.pl;     $(PERL) $< $@
-aix_ppc32.s: asm/ppc.pl;       $(PERL) asm/ppc.pl $@
-aix_ppc64.s: asm/ppc.pl;       $(PERL) asm/ppc.pl $@
-osx_ppc32.s: asm/ppc.pl;       $(PERL) $< $@
-osx_ppc64.s: asm/ppc.pl;       $(PERL) $< $@
+bn-ppc.s:      asm/ppc.pl;     $(PERL) asm/ppc.pl $(PERLASM_SCHEME) $@
+ppc-mont.s:    asm/ppc-mont.pl;$(PERL) asm/ppc-mont.pl $(PERLASM_SCHEME) $@
+
+alpha-mont.s:  asm/alpha-mont.pl
+       $(PERL) $< | $(CC) -E - | tee $@ > /dev/null
+
+# GNU make "catch all"
+%-mont.s:      asm/%-mont.pl;  $(PERL) $< $(CFLAGS) > $@
 
 files:
        $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
@@ -184,8 +176,11 @@ bn_blind.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
 bn_blind.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 bn_blind.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
 bn_blind.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_blind.c bn_lcl.h
-bn_const.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
-bn_const.o: ../../include/openssl/ossl_typ.h bn.h bn_const.c
+bn_const.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+bn_const.o: ../../include/openssl/opensslconf.h
+bn_const.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+bn_const.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+bn_const.o: ../../include/openssl/symhacks.h bn.h bn_const.c
 bn_ctx.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
 bn_ctx.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 bn_ctx.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
@@ -292,13 +287,6 @@ bn_nist.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
 bn_nist.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 bn_nist.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
 bn_nist.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_lcl.h bn_nist.c
-bn_opt.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
-bn_opt.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
-bn_opt.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-bn_opt.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
-bn_opt.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-bn_opt.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-bn_opt.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_lcl.h bn_opt.c
 bn_prime.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
 bn_prime.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 bn_prime.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
@@ -357,6 +345,3 @@ bn_word.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
 bn_word.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 bn_word.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
 bn_word.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_lcl.h bn_word.c
-bn_x931p.o: ../../include/openssl/bn.h ../../include/openssl/e_os2.h
-bn_x931p.o: ../../include/openssl/opensslconf.h
-bn_x931p.o: ../../include/openssl/ossl_typ.h bn_x931p.c
diff --git a/deps/openssl/openssl/crypto/bn/asm/alpha-mont.pl b/deps/openssl/openssl/crypto/bn/asm/alpha-mont.pl
new file mode 100644 (file)
index 0000000..03596e2
--- /dev/null
@@ -0,0 +1,321 @@
+#!/usr/bin/env perl
+#
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+#
+# On 21264 RSA sign performance improves by 70/35/20/15 percent for
+# 512/1024/2048/4096 bit key lengths. This is against vendor compiler
+# instructed to '-tune host' code with in-line assembler. Other
+# benchmarks improve by 15-20%. To anchor it to something else, the
+# code provides approximately the same performance per GHz as AMD64.
+# I.e. if you compare 1GHz 21264 and 2GHz Opteron, you'll observe ~2x
+# difference.
+
+# int bn_mul_mont(
+$rp="a0";      # BN_ULONG *rp,
+$ap="a1";      # const BN_ULONG *ap,
+$bp="a2";      # const BN_ULONG *bp,
+$np="a3";      # const BN_ULONG *np,
+$n0="a4";      # const BN_ULONG *n0,
+$num="a5";     # int num);
+
+$lo0="t0";
+$hi0="t1";
+$lo1="t2";
+$hi1="t3";
+$aj="t4";
+$bi="t5";
+$nj="t6";
+$tp="t7";
+$alo="t8";
+$ahi="t9";
+$nlo="t10";
+$nhi="t11";
+$tj="t12";
+$i="s3";
+$j="s4";
+$m1="s5";
+
+$code=<<___;
+#ifdef __linux__
+#include <asm/regdef.h>
+#else
+#include <asm.h>
+#include <regdef.h>
+#endif
+
+.text
+
+.set   noat
+.set   noreorder
+
+.globl bn_mul_mont
+.align 5
+.ent   bn_mul_mont
+bn_mul_mont:
+       lda     sp,-48(sp)
+       stq     ra,0(sp)
+       stq     s3,8(sp)
+       stq     s4,16(sp)
+       stq     s5,24(sp)
+       stq     fp,32(sp)
+       mov     sp,fp
+       .mask   0x0400f000,-48
+       .frame  fp,48,ra
+       .prologue 0
+
+       .align  4
+       .set    reorder
+       sextl   $num,$num
+       mov     0,v0
+       cmplt   $num,4,AT
+       bne     AT,.Lexit
+
+       ldq     $hi0,0($ap)     # ap[0]
+       s8addq  $num,16,AT
+       ldq     $aj,8($ap)
+       subq    sp,AT,sp
+       ldq     $bi,0($bp)      # bp[0]
+       lda     AT,-4096(zero)  # mov   -4096,AT
+       ldq     $n0,0($n0)
+       and     sp,AT,sp
+
+       mulq    $hi0,$bi,$lo0
+       ldq     $hi1,0($np)     # np[0]
+       umulh   $hi0,$bi,$hi0
+       ldq     $nj,8($np)
+
+       mulq    $lo0,$n0,$m1
+
+       mulq    $hi1,$m1,$lo1
+       umulh   $hi1,$m1,$hi1
+
+       addq    $lo1,$lo0,$lo1
+       cmpult  $lo1,$lo0,AT
+       addq    $hi1,AT,$hi1
+
+       mulq    $aj,$bi,$alo
+       mov     2,$j
+       umulh   $aj,$bi,$ahi
+       mov     sp,$tp
+
+       mulq    $nj,$m1,$nlo
+       s8addq  $j,$ap,$aj
+       umulh   $nj,$m1,$nhi
+       s8addq  $j,$np,$nj
+.align 4
+.L1st:
+       .set    noreorder
+       ldq     $aj,0($aj)
+       addl    $j,1,$j
+       ldq     $nj,0($nj)
+       lda     $tp,8($tp)
+
+       addq    $alo,$hi0,$lo0
+       mulq    $aj,$bi,$alo
+       cmpult  $lo0,$hi0,AT
+       addq    $nlo,$hi1,$lo1
+
+       mulq    $nj,$m1,$nlo
+       addq    $ahi,AT,$hi0
+       cmpult  $lo1,$hi1,v0
+       cmplt   $j,$num,$tj
+
+       umulh   $aj,$bi,$ahi
+       addq    $nhi,v0,$hi1
+       addq    $lo1,$lo0,$lo1
+       s8addq  $j,$ap,$aj
+
+       umulh   $nj,$m1,$nhi
+       cmpult  $lo1,$lo0,v0
+       addq    $hi1,v0,$hi1
+       s8addq  $j,$np,$nj
+
+       stq     $lo1,-8($tp)
+       nop
+       unop
+       bne     $tj,.L1st
+       .set    reorder
+
+       addq    $alo,$hi0,$lo0
+       addq    $nlo,$hi1,$lo1
+       cmpult  $lo0,$hi0,AT
+       cmpult  $lo1,$hi1,v0
+       addq    $ahi,AT,$hi0
+       addq    $nhi,v0,$hi1
+
+       addq    $lo1,$lo0,$lo1
+       cmpult  $lo1,$lo0,v0
+       addq    $hi1,v0,$hi1
+
+       stq     $lo1,0($tp)
+
+       addq    $hi1,$hi0,$hi1
+       cmpult  $hi1,$hi0,AT
+       stq     $hi1,8($tp)
+       stq     AT,16($tp)
+
+       mov     1,$i
+.align 4
+.Louter:
+       s8addq  $i,$bp,$bi
+       ldq     $hi0,0($ap)
+       ldq     $aj,8($ap)
+       ldq     $bi,0($bi)
+       ldq     $hi1,0($np)
+       ldq     $nj,8($np)
+       ldq     $tj,0(sp)
+
+       mulq    $hi0,$bi,$lo0
+       umulh   $hi0,$bi,$hi0
+
+       addq    $lo0,$tj,$lo0
+       cmpult  $lo0,$tj,AT
+       addq    $hi0,AT,$hi0
+
+       mulq    $lo0,$n0,$m1
+
+       mulq    $hi1,$m1,$lo1
+       umulh   $hi1,$m1,$hi1
+
+       addq    $lo1,$lo0,$lo1
+       cmpult  $lo1,$lo0,AT
+       mov     2,$j
+       addq    $hi1,AT,$hi1
+
+       mulq    $aj,$bi,$alo
+       mov     sp,$tp
+       umulh   $aj,$bi,$ahi
+
+       mulq    $nj,$m1,$nlo
+       s8addq  $j,$ap,$aj
+       umulh   $nj,$m1,$nhi
+.align 4
+.Linner:
+       .set    noreorder
+       ldq     $tj,8($tp)      #L0
+       nop                     #U1
+       ldq     $aj,0($aj)      #L1
+       s8addq  $j,$np,$nj      #U0
+
+       ldq     $nj,0($nj)      #L0
+       nop                     #U1
+       addq    $alo,$hi0,$lo0  #L1
+       lda     $tp,8($tp)
+
+       mulq    $aj,$bi,$alo    #U1
+       cmpult  $lo0,$hi0,AT    #L0
+       addq    $nlo,$hi1,$lo1  #L1
+       addl    $j,1,$j
+
+       mulq    $nj,$m1,$nlo    #U1
+       addq    $ahi,AT,$hi0    #L0
+       addq    $lo0,$tj,$lo0   #L1
+       cmpult  $lo1,$hi1,v0    #U0
+
+       umulh   $aj,$bi,$ahi    #U1
+       cmpult  $lo0,$tj,AT     #L0
+       addq    $lo1,$lo0,$lo1  #L1
+       addq    $nhi,v0,$hi1    #U0
+
+       umulh   $nj,$m1,$nhi    #U1
+       s8addq  $j,$ap,$aj      #L0
+       cmpult  $lo1,$lo0,v0    #L1
+       cmplt   $j,$num,$tj     #U0     # borrow $tj
+
+       addq    $hi0,AT,$hi0    #L0
+       addq    $hi1,v0,$hi1    #U1
+       stq     $lo1,-8($tp)    #L1
+       bne     $tj,.Linner     #U0
+       .set    reorder
+
+       ldq     $tj,8($tp)
+       addq    $alo,$hi0,$lo0
+       addq    $nlo,$hi1,$lo1
+       cmpult  $lo0,$hi0,AT
+       cmpult  $lo1,$hi1,v0
+       addq    $ahi,AT,$hi0
+       addq    $nhi,v0,$hi1
+
+       addq    $lo0,$tj,$lo0
+       cmpult  $lo0,$tj,AT
+       addq    $hi0,AT,$hi0
+
+       ldq     $tj,16($tp)
+       addq    $lo1,$lo0,$j
+       cmpult  $j,$lo0,v0
+       addq    $hi1,v0,$hi1
+
+       addq    $hi1,$hi0,$lo1
+       stq     $j,0($tp)
+       cmpult  $lo1,$hi0,$hi1
+       addq    $lo1,$tj,$lo1
+       cmpult  $lo1,$tj,AT
+       addl    $i,1,$i
+       addq    $hi1,AT,$hi1
+       stq     $lo1,8($tp)
+       cmplt   $i,$num,$tj     # borrow $tj
+       stq     $hi1,16($tp)
+       bne     $tj,.Louter
+\f
+       s8addq  $num,sp,$tj     # &tp[num]
+       mov     $rp,$bp         # put rp aside
+       mov     sp,$tp
+       mov     sp,$ap
+       mov     0,$hi0          # clear borrow bit
+
+.align 4
+.Lsub: ldq     $lo0,0($tp)
+       ldq     $lo1,0($np)
+       lda     $tp,8($tp)
+       lda     $np,8($np)
+       subq    $lo0,$lo1,$lo1  # tp[i]-np[i]
+       cmpult  $lo0,$lo1,AT
+       subq    $lo1,$hi0,$lo0
+       cmpult  $lo1,$lo0,$hi0
+       or      $hi0,AT,$hi0
+       stq     $lo0,0($rp)
+       cmpult  $tp,$tj,v0
+       lda     $rp,8($rp)
+       bne     v0,.Lsub
+
+       subq    $hi1,$hi0,$hi0  # handle upmost overflow bit
+       mov     sp,$tp
+       mov     $bp,$rp         # restore rp
+
+       and     sp,$hi0,$ap
+       bic     $bp,$hi0,$bp
+       bis     $bp,$ap,$ap     # ap=borrow?tp:rp
+
+.align 4
+.Lcopy:        ldq     $aj,0($ap)      # copy or in-place refresh
+       lda     $tp,8($tp)
+       lda     $rp,8($rp)
+       lda     $ap,8($ap)
+       stq     zero,-8($tp)    # zap tp
+       cmpult  $tp,$tj,AT
+       stq     $aj,-8($rp)
+       bne     AT,.Lcopy
+       mov     1,v0
+
+.Lexit:
+       .set    noreorder
+       mov     fp,sp
+       /*ldq   ra,0(sp)*/
+       ldq     s3,8(sp)
+       ldq     s4,16(sp)
+       ldq     s5,24(sp)
+       ldq     fp,32(sp)
+       lda     sp,48(sp)
+       ret     (ra)
+.end   bn_mul_mont
+.ascii "Montgomery Multiplication for Alpha, CRYPTOGAMS by <appro\@openssl.org>"
+.align 2
+___
+
+print $code;
+close STDOUT;
diff --git a/deps/openssl/openssl/crypto/bn/asm/armv4-mont.pl b/deps/openssl/openssl/crypto/bn/asm/armv4-mont.pl
new file mode 100644 (file)
index 0000000..14e0d2d
--- /dev/null
@@ -0,0 +1,201 @@
+#!/usr/bin/env perl
+
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+
+# January 2007.
+
+# Montgomery multiplication for ARMv4.
+#
+# Performance improvement naturally varies among CPU implementations
+# and compilers. The code was observed to provide +65-35% improvement
+# [depending on key length, less for longer keys] on ARM920T, and
+# +115-80% on Intel IXP425. This is compared to pre-bn_mul_mont code
+# base and compiler generated code with in-lined umull and even umlal
+# instructions. The latter means that this code didn't really have an 
+# "advantage" of utilizing some "secret" instruction.
+#
+# The code is interoperable with Thumb ISA and is rather compact, less
+# than 1/2KB. Windows CE port would be trivial, as it's exclusively
+# about decorations, ABI and instruction syntax are identical.
+
+$num="r0";     # starts as num argument, but holds &tp[num-1]
+$ap="r1";
+$bp="r2"; $bi="r2"; $rp="r2";
+$np="r3";
+$tp="r4";
+$aj="r5";
+$nj="r6";
+$tj="r7";
+$n0="r8";
+###########    # r9 is reserved by ELF as platform specific, e.g. TLS pointer
+$alo="r10";    # sl, gcc uses it to keep @GOT
+$ahi="r11";    # fp
+$nlo="r12";    # ip
+###########    # r13 is stack pointer
+$nhi="r14";    # lr
+###########    # r15 is program counter
+
+#### argument block layout relative to &tp[num-1], a.k.a. $num
+$_rp="$num,#12*4";
+# ap permanently resides in r1
+$_bp="$num,#13*4";
+# np permanently resides in r3
+$_n0="$num,#14*4";
+$_num="$num,#15*4";    $_bpend=$_num;
+
+$code=<<___;
+.text
+
+.global        bn_mul_mont
+.type  bn_mul_mont,%function
+
+.align 2
+bn_mul_mont:
+       stmdb   sp!,{r0,r2}             @ sp points at argument block
+       ldr     $num,[sp,#3*4]          @ load num
+       cmp     $num,#2
+       movlt   r0,#0
+       addlt   sp,sp,#2*4
+       blt     .Labrt
+
+       stmdb   sp!,{r4-r12,lr}         @ save 10 registers
+
+       mov     $num,$num,lsl#2         @ rescale $num for byte count
+       sub     sp,sp,$num              @ alloca(4*num)
+       sub     sp,sp,#4                @ +extra dword
+       sub     $num,$num,#4            @ "num=num-1"
+       add     $tp,$bp,$num            @ &bp[num-1]
+
+       add     $num,sp,$num            @ $num to point at &tp[num-1]
+       ldr     $n0,[$_n0]              @ &n0
+       ldr     $bi,[$bp]               @ bp[0]
+       ldr     $aj,[$ap],#4            @ ap[0],ap++
+       ldr     $nj,[$np],#4            @ np[0],np++
+       ldr     $n0,[$n0]               @ *n0
+       str     $tp,[$_bpend]           @ save &bp[num]
+
+       umull   $alo,$ahi,$aj,$bi       @ ap[0]*bp[0]
+       str     $n0,[$_n0]              @ save n0 value
+       mul     $n0,$alo,$n0            @ "tp[0]"*n0
+       mov     $nlo,#0
+       umlal   $alo,$nlo,$nj,$n0       @ np[0]*n0+"t[0]"
+       mov     $tp,sp
+
+.L1st:
+       ldr     $aj,[$ap],#4            @ ap[j],ap++
+       mov     $alo,$ahi
+       mov     $ahi,#0
+       umlal   $alo,$ahi,$aj,$bi       @ ap[j]*bp[0]
+       ldr     $nj,[$np],#4            @ np[j],np++
+       mov     $nhi,#0
+       umlal   $nlo,$nhi,$nj,$n0       @ np[j]*n0
+       adds    $nlo,$nlo,$alo
+       str     $nlo,[$tp],#4           @ tp[j-1]=,tp++
+       adc     $nlo,$nhi,#0
+       cmp     $tp,$num
+       bne     .L1st
+
+       adds    $nlo,$nlo,$ahi
+       mov     $nhi,#0
+       adc     $nhi,$nhi,#0
+       ldr     $tp,[$_bp]              @ restore bp
+       str     $nlo,[$num]             @ tp[num-1]=
+       ldr     $n0,[$_n0]              @ restore n0
+       str     $nhi,[$num,#4]          @ tp[num]=
+\f
+.Louter:
+       sub     $tj,$num,sp             @ "original" $num-1 value
+       sub     $ap,$ap,$tj             @ "rewind" ap to &ap[1]
+       sub     $np,$np,$tj             @ "rewind" np to &np[1]
+       ldr     $bi,[$tp,#4]!           @ *(++bp)
+       ldr     $aj,[$ap,#-4]           @ ap[0]
+       ldr     $nj,[$np,#-4]           @ np[0]
+       ldr     $alo,[sp]               @ tp[0]
+       ldr     $tj,[sp,#4]             @ tp[1]
+
+       mov     $ahi,#0
+       umlal   $alo,$ahi,$aj,$bi       @ ap[0]*bp[i]+tp[0]
+       str     $tp,[$_bp]              @ save bp
+       mul     $n0,$alo,$n0
+       mov     $nlo,#0
+       umlal   $alo,$nlo,$nj,$n0       @ np[0]*n0+"tp[0]"
+       mov     $tp,sp
+
+.Linner:
+       ldr     $aj,[$ap],#4            @ ap[j],ap++
+       adds    $alo,$ahi,$tj           @ +=tp[j]
+       mov     $ahi,#0
+       umlal   $alo,$ahi,$aj,$bi       @ ap[j]*bp[i]
+       ldr     $nj,[$np],#4            @ np[j],np++
+       mov     $nhi,#0
+       umlal   $nlo,$nhi,$nj,$n0       @ np[j]*n0
+       ldr     $tj,[$tp,#8]            @ tp[j+1]
+       adc     $ahi,$ahi,#0
+       adds    $nlo,$nlo,$alo
+       str     $nlo,[$tp],#4           @ tp[j-1]=,tp++
+       adc     $nlo,$nhi,#0
+       cmp     $tp,$num
+       bne     .Linner
+
+       adds    $nlo,$nlo,$ahi
+       mov     $nhi,#0
+       adc     $nhi,$nhi,#0
+       adds    $nlo,$nlo,$tj
+       adc     $nhi,$nhi,#0
+       ldr     $tp,[$_bp]              @ restore bp
+       ldr     $tj,[$_bpend]           @ restore &bp[num]
+       str     $nlo,[$num]             @ tp[num-1]=
+       ldr     $n0,[$_n0]              @ restore n0
+       str     $nhi,[$num,#4]          @ tp[num]=
+
+       cmp     $tp,$tj
+       bne     .Louter
+\f
+       ldr     $rp,[$_rp]              @ pull rp
+       add     $num,$num,#4            @ $num to point at &tp[num]
+       sub     $aj,$num,sp             @ "original" num value
+       mov     $tp,sp                  @ "rewind" $tp
+       mov     $ap,$tp                 @ "borrow" $ap
+       sub     $np,$np,$aj             @ "rewind" $np to &np[0]
+
+       subs    $tj,$tj,$tj             @ "clear" carry flag
+.Lsub: ldr     $tj,[$tp],#4
+       ldr     $nj,[$np],#4
+       sbcs    $tj,$tj,$nj             @ tp[j]-np[j]
+       str     $tj,[$rp],#4            @ rp[j]=
+       teq     $tp,$num                @ preserve carry
+       bne     .Lsub
+       sbcs    $nhi,$nhi,#0            @ upmost carry
+       mov     $tp,sp                  @ "rewind" $tp
+       sub     $rp,$rp,$aj             @ "rewind" $rp
+
+       and     $ap,$tp,$nhi
+       bic     $np,$rp,$nhi
+       orr     $ap,$ap,$np             @ ap=borrow?tp:rp
+
+.Lcopy:        ldr     $tj,[$ap],#4            @ copy or in-place refresh
+       str     sp,[$tp],#4             @ zap tp
+       str     $tj,[$rp],#4
+       cmp     $tp,$num
+       bne     .Lcopy
+
+       add     sp,$num,#4              @ skip over tp[num+1]
+       ldmia   sp!,{r4-r12,lr}         @ restore registers
+       add     sp,sp,#2*4              @ skip over {r0,r2}
+       mov     r0,#1
+.Labrt:        tst     lr,#1
+       moveq   pc,lr                   @ be binary compatible with V4, yet
+       bx      lr                      @ interoperable with Thumb ISA:-)
+.size  bn_mul_mont,.-bn_mul_mont
+.asciz "Montgomery multiplication for ARMv4, CRYPTOGAMS by <appro\@openssl.org>"
+.align 2
+___
+
+$code =~ s/\bbx\s+lr\b/.word\t0xe12fff1e/gm;   # make it possible to compile with -march=armv4
+print $code;
+close STDOUT;
index 26c2685..332ef3e 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/local/bin/perl
 
-push(@INC,"perlasm","../../perlasm");
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+push(@INC,"${dir}","${dir}../../perlasm");
 require "x86asm.pl";
 
 &asm_init($ARGV[0],$0);
@@ -24,38 +25,25 @@ sub bn_mul_add_words
        {
        local($name)=@_;
 
-       &function_begin($name,$sse2?"EXTRN\t_OPENSSL_ia32cap_P:DWORD":"");
+       &function_begin_B($name,$sse2?"EXTRN\t_OPENSSL_ia32cap_P:DWORD":"");
 
-       &comment("");
-       $Low="eax";
-       $High="edx";
-       $a="ebx";
-       $w="ebp";
-       $r="edi";
-       $c="esi";
-
-       &xor($c,$c);            # clear carry
-       &mov($r,&wparam(0));    #
-
-       &mov("ecx",&wparam(2)); #
-       &mov($a,&wparam(1));    #
-
-       &and("ecx",0xfffffff8); # num / 8
-       &mov($w,&wparam(3));    #
-
-       &push("ecx");           # Up the stack for a tmp variable
-
-       &jz(&label("maw_finish"));
+       $r="eax";
+       $a="edx";
+       $c="ecx";
 
        if ($sse2) {
                &picmeup("eax","OPENSSL_ia32cap_P");
                &bt(&DWP(0,"eax"),26);
-               &jnc(&label("maw_loop"));
+               &jnc(&label("maw_non_sse2"));
 
-               &movd("mm0",$w);                # mm0 = w
+               &mov($r,&wparam(0));
+               &mov($a,&wparam(1));
+               &mov($c,&wparam(2));
+               &movd("mm0",&wparam(3));        # mm0 = w
                &pxor("mm1","mm1");             # mm1 = carry_in
-
-               &set_label("maw_sse2_loop",0);
+               &jmp(&label("maw_sse2_entry"));
+               
+       &set_label("maw_sse2_unrolled",16);
                &movd("mm3",&DWP(0,$r,"",0));   # mm3 = r[0]
                &paddq("mm1","mm3");            # mm1 = carry_in + r[0]
                &movd("mm2",&DWP(0,$a,"",0));   # mm2 = a[0]
@@ -112,42 +100,82 @@ sub bn_mul_add_words
                &psrlq("mm1",32);               # mm1 = carry6
                &paddq("mm1","mm3");            # mm1 = carry6 + r[7] + w*a[7]
                &movd(&DWP(28,$r,"",0),"mm1");
-               &add($r,32);
+               &lea($r,&DWP(32,$r));
                &psrlq("mm1",32);               # mm1 = carry_out
 
-               &sub("ecx",8);
+               &sub($c,8);
+               &jz(&label("maw_sse2_exit"));
+       &set_label("maw_sse2_entry");
+               &test($c,0xfffffff8);
+               &jnz(&label("maw_sse2_unrolled"));
+
+       &set_label("maw_sse2_loop",4);
+               &movd("mm2",&DWP(0,$a));        # mm2 = a[i]
+               &movd("mm3",&DWP(0,$r));        # mm3 = r[i]
+               &pmuludq("mm2","mm0");          # a[i] *= w
+               &lea($a,&DWP(4,$a));
+               &paddq("mm1","mm3");            # carry += r[i]
+               &paddq("mm1","mm2");            # carry += a[i]*w
+               &movd(&DWP(0,$r),"mm1");        # r[i] = carry_low
+               &sub($c,1);
+               &psrlq("mm1",32);               # carry = carry_high
+               &lea($r,&DWP(4,$r));
                &jnz(&label("maw_sse2_loop"));
-
-               &movd($c,"mm1");                # c = carry_out
+       &set_label("maw_sse2_exit");
+               &movd("eax","mm1");             # c = carry_out
                &emms();
+               &ret();
 
-               &jmp(&label("maw_finish"));
+       &set_label("maw_non_sse2",16);
        }
 
-       &set_label("maw_loop",0);
+       # function_begin prologue
+       &push("ebp");
+       &push("ebx");
+       &push("esi");
+       &push("edi");
+
+       &comment("");
+       $Low="eax";
+       $High="edx";
+       $a="ebx";
+       $w="ebp";
+       $r="edi";
+       $c="esi";
+
+       &xor($c,$c);            # clear carry
+       &mov($r,&wparam(0));    #
+
+       &mov("ecx",&wparam(2)); #
+       &mov($a,&wparam(1));    #
+
+       &and("ecx",0xfffffff8); # num / 8
+       &mov($w,&wparam(3));    #
 
-       &mov(&swtmp(0),"ecx");  #
+       &push("ecx");           # Up the stack for a tmp variable
+
+       &jz(&label("maw_finish"));
+
+       &set_label("maw_loop",16);
 
        for ($i=0; $i<32; $i+=4)
                {
                &comment("Round $i");
 
-                &mov("eax",&DWP($i,$a,"",0));  # *a
+                &mov("eax",&DWP($i,$a));       # *a
                &mul($w);                       # *a * w
-               &add("eax",$c);         # L(t)+= *r
-                &mov($c,&DWP($i,$r,"",0));     # L(t)+= *r
+               &add("eax",$c);                 # L(t)+= c
                &adc("edx",0);                  # H(t)+=carry
-                &add("eax",$c);                # L(t)+=c
+                &add("eax",&DWP($i,$r));       # L(t)+= *r
                &adc("edx",0);                  # H(t)+=carry
-                &mov(&DWP($i,$r,"",0),"eax");  # *r= L(t);
+                &mov(&DWP($i,$r),"eax");       # *r= L(t);
                &mov($c,"edx");                 # c=  H(t);
                }
 
        &comment("");
-       &mov("ecx",&swtmp(0));  #
-       &add($a,32);
-       &add($r,32);
        &sub("ecx",8);
+       &lea($a,&DWP(32,$a));
+       &lea($r,&DWP(32,$r));
        &jnz(&label("maw_loop"));
 
        &set_label("maw_finish",0);
@@ -160,16 +188,15 @@ sub bn_mul_add_words
        for ($i=0; $i<7; $i++)
                {
                &comment("Tail Round $i");
-                &mov("eax",&DWP($i*4,$a,"",0));# *a
+                &mov("eax",&DWP($i*4,$a));     # *a
                &mul($w);                       # *a * w
                &add("eax",$c);                 # L(t)+=c
-                &mov($c,&DWP($i*4,$r,"",0));   # L(t)+= *r
                &adc("edx",0);                  # H(t)+=carry
-                &add("eax",$c);
+                &add("eax",&DWP($i*4,$r));     # L(t)+= *r
                &adc("edx",0);                  # H(t)+=carry
                 &dec("ecx") if ($i != 7-1);
-               &mov(&DWP($i*4,$r,"",0),"eax"); # *r= L(t);
-                &mov($c,"edx");                        # c=  H(t);
+               &mov(&DWP($i*4,$r),"eax");      # *r= L(t);
+                &mov($c,"edx");                # c=  H(t);
                &jz(&label("maw_end")) if ($i != 7-1);
                }
        &set_label("maw_end",0);
@@ -184,7 +211,45 @@ sub bn_mul_words
        {
        local($name)=@_;
 
-       &function_begin($name,"");
+       &function_begin_B($name,$sse2?"EXTRN\t_OPENSSL_ia32cap_P:DWORD":"");
+
+       $r="eax";
+       $a="edx";
+       $c="ecx";
+
+       if ($sse2) {
+               &picmeup("eax","OPENSSL_ia32cap_P");
+               &bt(&DWP(0,"eax"),26);
+               &jnc(&label("mw_non_sse2"));
+
+               &mov($r,&wparam(0));
+               &mov($a,&wparam(1));
+               &mov($c,&wparam(2));
+               &movd("mm0",&wparam(3));        # mm0 = w
+               &pxor("mm1","mm1");             # mm1 = carry = 0
+
+       &set_label("mw_sse2_loop",16);
+               &movd("mm2",&DWP(0,$a));        # mm2 = a[i]
+               &pmuludq("mm2","mm0");          # a[i] *= w
+               &lea($a,&DWP(4,$a));
+               &paddq("mm1","mm2");            # carry += a[i]*w
+               &movd(&DWP(0,$r),"mm1");        # r[i] = carry_low
+               &sub($c,1);
+               &psrlq("mm1",32);               # carry = carry_high
+               &lea($r,&DWP(4,$r));
+               &jnz(&label("mw_sse2_loop"));
+
+               &movd("eax","mm1");             # return carry
+               &emms();
+               &ret();
+       &set_label("mw_non_sse2",16);
+       }
+
+       # function_begin prologue
+       &push("ebp");
+       &push("ebx");
+       &push("esi");
+       &push("edi");
 
        &comment("");
        $Low="eax";
@@ -257,7 +322,40 @@ sub bn_sqr_words
        {
        local($name)=@_;
 
-       &function_begin($name,"");
+       &function_begin_B($name,$sse2?"EXTRN\t_OPENSSL_ia32cap_P:DWORD":"");
+
+       $r="eax";
+       $a="edx";
+       $c="ecx";
+
+       if ($sse2) {
+               &picmeup("eax","OPENSSL_ia32cap_P");
+               &bt(&DWP(0,"eax"),26);
+               &jnc(&label("sqr_non_sse2"));
+
+               &mov($r,&wparam(0));
+               &mov($a,&wparam(1));
+               &mov($c,&wparam(2));
+
+       &set_label("sqr_sse2_loop",16);
+               &movd("mm0",&DWP(0,$a));        # mm0 = a[i]
+               &pmuludq("mm0","mm0");          # a[i] *= a[i]
+               &lea($a,&DWP(4,$a));            # a++
+               &movq(&QWP(0,$r),"mm0");        # r[i] = a[i]*a[i]
+               &sub($c,1);
+               &lea($r,&DWP(8,$r));            # r += 2
+               &jnz(&label("sqr_sse2_loop"));
+
+               &emms();
+               &ret();
+       &set_label("sqr_non_sse2",16);
+       }
+
+       # function_begin prologue
+       &push("ebp");
+       &push("ebx");
+       &push("esi");
+       &push("edi");
 
        &comment("");
        $r="esi";
@@ -313,12 +411,13 @@ sub bn_div_words
        {
        local($name)=@_;
 
-       &function_begin($name,"");
+       &function_begin_B($name,"");
        &mov("edx",&wparam(0)); #
        &mov("eax",&wparam(1)); #
-       &mov("ebx",&wparam(2)); #
-       &div("ebx");
-       &function_end($name);
+       &mov("ecx",&wparam(2)); #
+       &div("ecx");
+       &ret();
+       &function_end_B($name);
        }
 
 sub bn_add_words
index 5d962cb..57101a6 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/local/bin/perl
 
-push(@INC,"perlasm","../../perlasm");
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+push(@INC,"${dir}","${dir}../../perlasm");
 require "x86asm.pl";
 
 &asm_init($ARGV[0],$0);
diff --git a/deps/openssl/openssl/crypto/bn/asm/mips3-mont.pl b/deps/openssl/openssl/crypto/bn/asm/mips3-mont.pl
new file mode 100644 (file)
index 0000000..8f9156e
--- /dev/null
@@ -0,0 +1,327 @@
+#!/usr/bin/env perl
+#
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+
+# This module doesn't present direct interest for OpenSSL, because it
+# doesn't provide better performance for longer keys. While 512-bit
+# RSA private key operations are 40% faster, 1024-bit ones are hardly
+# faster at all, while longer key operations are slower by up to 20%.
+# It might be of interest to embedded system developers though, as
+# it's smaller than 1KB, yet offers ~3x improvement over compiler
+# generated code.
+#
+# The module targets N32 and N64 MIPS ABIs and currently is a bit
+# IRIX-centric, i.e. is likely to require adaptation for other OSes.
+
+# int bn_mul_mont(
+$rp="a0";      # BN_ULONG *rp,
+$ap="a1";      # const BN_ULONG *ap,
+$bp="a2";      # const BN_ULONG *bp,
+$np="a3";      # const BN_ULONG *np,
+$n0="a4";      # const BN_ULONG *n0,
+$num="a5";     # int num);
+
+$lo0="a6";
+$hi0="a7";
+$lo1="v0";
+$hi1="v1";
+$aj="t0";
+$bi="t1";
+$nj="t2";
+$tp="t3";
+$alo="s0";
+$ahi="s1";
+$nlo="s2";
+$nhi="s3";
+$tj="s4";
+$i="s5";
+$j="s6";
+$fp="t8";
+$m1="t9";
+
+$FRAME=8*(2+8);
+
+$code=<<___;
+#include <asm.h>
+#include <regdef.h>
+
+.text
+
+.set   noat
+.set   reorder
+
+.align 5
+.globl bn_mul_mont
+.ent   bn_mul_mont
+bn_mul_mont:
+       .set    noreorder
+       PTR_SUB sp,64
+       move    $fp,sp
+       .frame  $fp,64,ra
+       slt     AT,$num,4
+       li      v0,0
+       beqzl   AT,.Lproceed
+       nop
+       jr      ra
+       PTR_ADD sp,$fp,64
+       .set    reorder
+.align 5
+.Lproceed:
+       ld      $n0,0($n0)
+       ld      $bi,0($bp)      # bp[0]
+       ld      $aj,0($ap)      # ap[0]
+       ld      $nj,0($np)      # np[0]
+       PTR_SUB sp,16           # place for two extra words
+       sll     $num,3
+       li      AT,-4096
+       PTR_SUB sp,$num
+       and     sp,AT
+
+       sd      s0,0($fp)
+       sd      s1,8($fp)
+       sd      s2,16($fp)
+       sd      s3,24($fp)
+       sd      s4,32($fp)
+       sd      s5,40($fp)
+       sd      s6,48($fp)
+       sd      s7,56($fp)
+
+       dmultu  $aj,$bi
+       ld      $alo,8($ap)
+       ld      $nlo,8($np)
+       mflo    $lo0
+       mfhi    $hi0
+       dmultu  $lo0,$n0
+       mflo    $m1
+
+       dmultu  $alo,$bi
+       mflo    $alo
+       mfhi    $ahi
+
+       dmultu  $nj,$m1
+       mflo    $lo1
+       mfhi    $hi1
+       dmultu  $nlo,$m1
+       daddu   $lo1,$lo0
+       sltu    AT,$lo1,$lo0
+       daddu   $hi1,AT
+       mflo    $nlo
+       mfhi    $nhi
+
+       move    $tp,sp
+       li      $j,16
+.align 4
+.L1st:
+       .set    noreorder
+       PTR_ADD $aj,$ap,$j
+       ld      $aj,($aj)
+       PTR_ADD $nj,$np,$j
+       ld      $nj,($nj)
+
+       dmultu  $aj,$bi
+       daddu   $lo0,$alo,$hi0
+       daddu   $lo1,$nlo,$hi1
+       sltu    AT,$lo0,$hi0
+       sltu    s7,$lo1,$hi1
+       daddu   $hi0,$ahi,AT
+       daddu   $hi1,$nhi,s7
+       mflo    $alo
+       mfhi    $ahi
+
+       daddu   $lo1,$lo0
+       sltu    AT,$lo1,$lo0
+       dmultu  $nj,$m1
+       daddu   $hi1,AT
+       addu    $j,8
+       sd      $lo1,($tp)
+       sltu    s7,$j,$num
+       mflo    $nlo
+       mfhi    $nhi
+
+       bnez    s7,.L1st
+       PTR_ADD $tp,8
+       .set    reorder
+
+       daddu   $lo0,$alo,$hi0
+       sltu    AT,$lo0,$hi0
+       daddu   $hi0,$ahi,AT
+
+       daddu   $lo1,$nlo,$hi1
+       sltu    s7,$lo1,$hi1
+       daddu   $hi1,$nhi,s7
+       daddu   $lo1,$lo0
+       sltu    AT,$lo1,$lo0
+       daddu   $hi1,AT
+
+       sd      $lo1,($tp)
+
+       daddu   $hi1,$hi0
+       sltu    AT,$hi1,$hi0
+       sd      $hi1,8($tp)
+       sd      AT,16($tp)
+
+       li      $i,8
+.align 4
+.Louter:
+       PTR_ADD $bi,$bp,$i
+       ld      $bi,($bi)
+       ld      $aj,($ap)
+       ld      $alo,8($ap)
+       ld      $tj,(sp)
+
+       dmultu  $aj,$bi
+       ld      $nj,($np)
+       ld      $nlo,8($np)
+       mflo    $lo0
+       mfhi    $hi0
+       daddu   $lo0,$tj
+       dmultu  $lo0,$n0
+       sltu    AT,$lo0,$tj
+       daddu   $hi0,AT
+       mflo    $m1
+
+       dmultu  $alo,$bi
+       mflo    $alo
+       mfhi    $ahi
+
+       dmultu  $nj,$m1
+       mflo    $lo1
+       mfhi    $hi1
+
+       dmultu  $nlo,$m1
+       daddu   $lo1,$lo0
+       sltu    AT,$lo1,$lo0
+       daddu   $hi1,AT
+       mflo    $nlo
+       mfhi    $nhi
+
+       move    $tp,sp
+       li      $j,16
+       ld      $tj,8($tp)
+.align 4
+.Linner:
+       .set    noreorder
+       PTR_ADD $aj,$ap,$j
+       ld      $aj,($aj)
+       PTR_ADD $nj,$np,$j
+       ld      $nj,($nj)
+
+       dmultu  $aj,$bi
+       daddu   $lo0,$alo,$hi0
+       daddu   $lo1,$nlo,$hi1
+       sltu    AT,$lo0,$hi0
+       sltu    s7,$lo1,$hi1
+       daddu   $hi0,$ahi,AT
+       daddu   $hi1,$nhi,s7
+       mflo    $alo
+       mfhi    $ahi
+
+       daddu   $lo0,$tj
+       addu    $j,8
+       dmultu  $nj,$m1
+       sltu    AT,$lo0,$tj
+       daddu   $lo1,$lo0
+       daddu   $hi0,AT
+       sltu    s7,$lo1,$lo0
+       ld      $tj,16($tp)
+       daddu   $hi1,s7
+       sltu    AT,$j,$num
+       mflo    $nlo
+       mfhi    $nhi
+       sd      $lo1,($tp)
+       bnez    AT,.Linner
+       PTR_ADD $tp,8
+       .set    reorder
+
+       daddu   $lo0,$alo,$hi0
+       sltu    AT,$lo0,$hi0
+       daddu   $hi0,$ahi,AT
+       daddu   $lo0,$tj
+       sltu    s7,$lo0,$tj
+       daddu   $hi0,s7
+
+       ld      $tj,16($tp)
+       daddu   $lo1,$nlo,$hi1
+       sltu    AT,$lo1,$hi1
+       daddu   $hi1,$nhi,AT
+       daddu   $lo1,$lo0
+       sltu    s7,$lo1,$lo0
+       daddu   $hi1,s7
+       sd      $lo1,($tp)
+
+       daddu   $lo1,$hi1,$hi0
+       sltu    $hi1,$lo1,$hi0
+       daddu   $lo1,$tj
+       sltu    AT,$lo1,$tj
+       daddu   $hi1,AT
+       sd      $lo1,8($tp)
+       sd      $hi1,16($tp)
+
+       addu    $i,8
+       sltu    s7,$i,$num
+       bnez    s7,.Louter
+\f
+       .set    noreorder
+       PTR_ADD $tj,sp,$num     # &tp[num]
+       move    $tp,sp
+       move    $ap,sp
+       li      $hi0,0          # clear borrow bit
+
+.align 4
+.Lsub: ld      $lo0,($tp)
+       ld      $lo1,($np)
+       PTR_ADD $tp,8
+       PTR_ADD $np,8
+       dsubu   $lo1,$lo0,$lo1  # tp[i]-np[i]
+       sgtu    AT,$lo1,$lo0
+       dsubu   $lo0,$lo1,$hi0
+       sgtu    $hi0,$lo0,$lo1
+       sd      $lo0,($rp)
+       or      $hi0,AT
+       sltu    AT,$tp,$tj
+       bnez    AT,.Lsub
+       PTR_ADD $rp,8
+
+       dsubu   $hi0,$hi1,$hi0  # handle upmost overflow bit
+       move    $tp,sp
+       PTR_SUB $rp,$num        # restore rp
+       not     $hi1,$hi0
+
+       and     $ap,$hi0,sp
+       and     $bp,$hi1,$rp
+       or      $ap,$ap,$bp     # ap=borrow?tp:rp
+
+.align 4
+.Lcopy:        ld      $aj,($ap)
+       PTR_ADD $ap,8
+       PTR_ADD $tp,8
+       sd      zero,-8($tp)
+       sltu    AT,$tp,$tj
+       sd      $aj,($rp)
+       bnez    AT,.Lcopy
+       PTR_ADD $rp,8
+
+       ld      s0,0($fp)
+       ld      s1,8($fp)
+       ld      s2,16($fp)
+       ld      s3,24($fp)
+       ld      s4,32($fp)
+       ld      s5,40($fp)
+       ld      s6,48($fp)
+       ld      s7,56($fp)
+       li      v0,1
+       jr      ra
+       PTR_ADD sp,$fp,64
+       .set    reorder
+END(bn_mul_mont)
+.rdata
+.asciiz        "Montgomery Multiplication for MIPS III/IV, CRYPTOGAMS by <appro\@openssl.org>"
+___
+
+print $code;
+close STDOUT;
diff --git a/deps/openssl/openssl/crypto/bn/asm/ppc-mont.pl b/deps/openssl/openssl/crypto/bn/asm/ppc-mont.pl
new file mode 100644 (file)
index 0000000..7849eae
--- /dev/null
@@ -0,0 +1,323 @@
+#!/usr/bin/env perl
+
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+
+# April 2006
+
+# "Teaser" Montgomery multiplication module for PowerPC. It's possible
+# to gain a bit more by modulo-scheduling outer loop, then dedicated
+# squaring procedure should give further 20% and code can be adapted
+# for 32-bit application running on 64-bit CPU. As for the latter.
+# It won't be able to achieve "native" 64-bit performance, because in
+# 32-bit application context every addc instruction will have to be
+# expanded as addc, twice right shift by 32 and finally adde, etc.
+# So far RSA *sign* performance improvement over pre-bn_mul_mont asm
+# for 64-bit application running on PPC970/G5 is:
+#
+# 512-bit      +65%    
+# 1024-bit     +35%
+# 2048-bit     +18%
+# 4096-bit     +4%
+
+$flavour = shift;
+
+if ($flavour =~ /32/) {
+       $BITS=  32;
+       $BNSZ=  $BITS/8;
+       $SIZE_T=4;
+       $RZONE= 224;
+       $FRAME= $SIZE_T*16;
+
+       $LD=    "lwz";          # load
+       $LDU=   "lwzu";         # load and update
+       $LDX=   "lwzx";         # load indexed
+       $ST=    "stw";          # store
+       $STU=   "stwu";         # store and update
+       $STX=   "stwx";         # store indexed
+       $STUX=  "stwux";        # store indexed and update
+       $UMULL= "mullw";        # unsigned multiply low
+       $UMULH= "mulhwu";       # unsigned multiply high
+       $UCMP=  "cmplw";        # unsigned compare
+       $SHRI=  "srwi";         # unsigned shift right by immediate     
+       $PUSH=  $ST;
+       $POP=   $LD;
+} elsif ($flavour =~ /64/) {
+       $BITS=  64;
+       $BNSZ=  $BITS/8;
+       $SIZE_T=8;
+       $RZONE= 288;
+       $FRAME= $SIZE_T*16;
+
+       # same as above, but 64-bit mnemonics...
+       $LD=    "ld";           # load
+       $LDU=   "ldu";          # load and update
+       $LDX=   "ldx";          # load indexed
+       $ST=    "std";          # store
+       $STU=   "stdu";         # store and update
+       $STX=   "stdx";         # store indexed
+       $STUX=  "stdux";        # store indexed and update
+       $UMULL= "mulld";        # unsigned multiply low
+       $UMULH= "mulhdu";       # unsigned multiply high
+       $UCMP=  "cmpld";        # unsigned compare
+       $SHRI=  "srdi";         # unsigned shift right by immediate     
+       $PUSH=  $ST;
+       $POP=   $LD;
+} else { die "nonsense $flavour"; }
+
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+( $xlate="${dir}ppc-xlate.pl" and -f $xlate ) or
+( $xlate="${dir}../../perlasm/ppc-xlate.pl" and -f $xlate) or
+die "can't locate ppc-xlate.pl";
+
+open STDOUT,"| $^X $xlate $flavour ".shift || die "can't call $xlate: $!";
+
+$sp="r1";
+$toc="r2";
+$rp="r3";      $ovf="r3";
+$ap="r4";
+$bp="r5";
+$np="r6";
+$n0="r7";
+$num="r8";
+$rp="r9";      # $rp is reassigned
+$aj="r10";
+$nj="r11";
+$tj="r12";
+# non-volatile registers
+$i="r14";
+$j="r15";
+$tp="r16";
+$m0="r17";
+$m1="r18";
+$lo0="r19";
+$hi0="r20";
+$lo1="r21";
+$hi1="r22";
+$alo="r23";
+$ahi="r24";
+$nlo="r25";
+#
+$nhi="r0";
+
+$code=<<___;
+.machine "any"
+.text
+
+.globl .bn_mul_mont
+.align 4
+.bn_mul_mont:
+       cmpwi   $num,4
+       mr      $rp,r3          ; $rp is reassigned
+       li      r3,0
+       bltlr
+
+       slwi    $num,$num,`log($BNSZ)/log(2)`
+       li      $tj,-4096
+       addi    $ovf,$num,`$FRAME+$RZONE`
+       subf    $ovf,$ovf,$sp   ; $sp-$ovf
+       and     $ovf,$ovf,$tj   ; minimize TLB usage
+       subf    $ovf,$sp,$ovf   ; $ovf-$sp
+       srwi    $num,$num,`log($BNSZ)/log(2)`
+       $STUX   $sp,$sp,$ovf
+
+       $PUSH   r14,`4*$SIZE_T`($sp)
+       $PUSH   r15,`5*$SIZE_T`($sp)
+       $PUSH   r16,`6*$SIZE_T`($sp)
+       $PUSH   r17,`7*$SIZE_T`($sp)
+       $PUSH   r18,`8*$SIZE_T`($sp)
+       $PUSH   r19,`9*$SIZE_T`($sp)
+       $PUSH   r20,`10*$SIZE_T`($sp)
+       $PUSH   r21,`11*$SIZE_T`($sp)
+       $PUSH   r22,`12*$SIZE_T`($sp)
+       $PUSH   r23,`13*$SIZE_T`($sp)
+       $PUSH   r24,`14*$SIZE_T`($sp)
+       $PUSH   r25,`15*$SIZE_T`($sp)
+
+       $LD     $n0,0($n0)      ; pull n0[0] value
+       addi    $num,$num,-2    ; adjust $num for counter register
+\f
+       $LD     $m0,0($bp)      ; m0=bp[0]
+       $LD     $aj,0($ap)      ; ap[0]
+       addi    $tp,$sp,$FRAME
+       $UMULL  $lo0,$aj,$m0    ; ap[0]*bp[0]
+       $UMULH  $hi0,$aj,$m0
+
+       $LD     $aj,$BNSZ($ap)  ; ap[1]
+       $LD     $nj,0($np)      ; np[0]
+
+       $UMULL  $m1,$lo0,$n0    ; "tp[0]"*n0
+
+       $UMULL  $alo,$aj,$m0    ; ap[1]*bp[0]
+       $UMULH  $ahi,$aj,$m0
+
+       $UMULL  $lo1,$nj,$m1    ; np[0]*m1
+       $UMULH  $hi1,$nj,$m1
+       $LD     $nj,$BNSZ($np)  ; np[1]
+       addc    $lo1,$lo1,$lo0
+       addze   $hi1,$hi1
+
+       $UMULL  $nlo,$nj,$m1    ; np[1]*m1
+       $UMULH  $nhi,$nj,$m1
+
+       mtctr   $num
+       li      $j,`2*$BNSZ`
+.align 4
+L1st:
+       $LDX    $aj,$ap,$j      ; ap[j]
+       addc    $lo0,$alo,$hi0
+       $LDX    $nj,$np,$j      ; np[j]
+       addze   $hi0,$ahi
+       $UMULL  $alo,$aj,$m0    ; ap[j]*bp[0]
+       addc    $lo1,$nlo,$hi1
+       $UMULH  $ahi,$aj,$m0
+       addze   $hi1,$nhi
+       $UMULL  $nlo,$nj,$m1    ; np[j]*m1
+       addc    $lo1,$lo1,$lo0  ; np[j]*m1+ap[j]*bp[0]
+       $UMULH  $nhi,$nj,$m1
+       addze   $hi1,$hi1
+       $ST     $lo1,0($tp)     ; tp[j-1]
+
+       addi    $j,$j,$BNSZ     ; j++
+       addi    $tp,$tp,$BNSZ   ; tp++
+       bdnz-   L1st
+;L1st
+       addc    $lo0,$alo,$hi0
+       addze   $hi0,$ahi
+
+       addc    $lo1,$nlo,$hi1
+       addze   $hi1,$nhi
+       addc    $lo1,$lo1,$lo0  ; np[j]*m1+ap[j]*bp[0]
+       addze   $hi1,$hi1
+       $ST     $lo1,0($tp)     ; tp[j-1]
+
+       li      $ovf,0
+       addc    $hi1,$hi1,$hi0
+       addze   $ovf,$ovf       ; upmost overflow bit
+       $ST     $hi1,$BNSZ($tp)
+\f
+       li      $i,$BNSZ
+.align 4
+Louter:
+       $LDX    $m0,$bp,$i      ; m0=bp[i]
+       $LD     $aj,0($ap)      ; ap[0]
+       addi    $tp,$sp,$FRAME
+       $LD     $tj,$FRAME($sp) ; tp[0]
+       $UMULL  $lo0,$aj,$m0    ; ap[0]*bp[i]
+       $UMULH  $hi0,$aj,$m0
+       $LD     $aj,$BNSZ($ap)  ; ap[1]
+       $LD     $nj,0($np)      ; np[0]
+       addc    $lo0,$lo0,$tj   ; ap[0]*bp[i]+tp[0]
+       $UMULL  $alo,$aj,$m0    ; ap[j]*bp[i]
+       addze   $hi0,$hi0
+       $UMULL  $m1,$lo0,$n0    ; tp[0]*n0
+       $UMULH  $ahi,$aj,$m0
+       $UMULL  $lo1,$nj,$m1    ; np[0]*m1
+       $UMULH  $hi1,$nj,$m1
+       $LD     $nj,$BNSZ($np)  ; np[1]
+       addc    $lo1,$lo1,$lo0
+       $UMULL  $nlo,$nj,$m1    ; np[1]*m1
+       addze   $hi1,$hi1
+       $UMULH  $nhi,$nj,$m1
+\f
+       mtctr   $num
+       li      $j,`2*$BNSZ`
+.align 4
+Linner:
+       $LDX    $aj,$ap,$j      ; ap[j]
+       addc    $lo0,$alo,$hi0
+       $LD     $tj,$BNSZ($tp)  ; tp[j]
+       addze   $hi0,$ahi
+       $LDX    $nj,$np,$j      ; np[j]
+       addc    $lo1,$nlo,$hi1
+       $UMULL  $alo,$aj,$m0    ; ap[j]*bp[i]
+       addze   $hi1,$nhi
+       $UMULH  $ahi,$aj,$m0
+       addc    $lo0,$lo0,$tj   ; ap[j]*bp[i]+tp[j]
+       $UMULL  $nlo,$nj,$m1    ; np[j]*m1
+       addze   $hi0,$hi0
+       $UMULH  $nhi,$nj,$m1
+       addc    $lo1,$lo1,$lo0  ; np[j]*m1+ap[j]*bp[i]+tp[j]
+       addi    $j,$j,$BNSZ     ; j++
+       addze   $hi1,$hi1
+       $ST     $lo1,0($tp)     ; tp[j-1]
+       addi    $tp,$tp,$BNSZ   ; tp++
+       bdnz-   Linner
+;Linner
+       $LD     $tj,$BNSZ($tp)  ; tp[j]
+       addc    $lo0,$alo,$hi0
+       addze   $hi0,$ahi
+       addc    $lo0,$lo0,$tj   ; ap[j]*bp[i]+tp[j]
+       addze   $hi0,$hi0
+
+       addc    $lo1,$nlo,$hi1
+       addze   $hi1,$nhi
+       addc    $lo1,$lo1,$lo0  ; np[j]*m1+ap[j]*bp[i]+tp[j]
+       addze   $hi1,$hi1
+       $ST     $lo1,0($tp)     ; tp[j-1]
+
+       addic   $ovf,$ovf,-1    ; move upmost overflow to XER[CA]
+       li      $ovf,0
+       adde    $hi1,$hi1,$hi0
+       addze   $ovf,$ovf
+       $ST     $hi1,$BNSZ($tp)
+;
+       slwi    $tj,$num,`log($BNSZ)/log(2)`
+       $UCMP   $i,$tj
+       addi    $i,$i,$BNSZ
+       ble-    Louter
+\f
+       addi    $num,$num,2     ; restore $num
+       subfc   $j,$j,$j        ; j=0 and "clear" XER[CA]
+       addi    $tp,$sp,$FRAME
+       mtctr   $num
+
+.align 4
+Lsub:  $LDX    $tj,$tp,$j
+       $LDX    $nj,$np,$j
+       subfe   $aj,$nj,$tj     ; tp[j]-np[j]
+       $STX    $aj,$rp,$j
+       addi    $j,$j,$BNSZ
+       bdnz-   Lsub
+
+       li      $j,0
+       mtctr   $num
+       subfe   $ovf,$j,$ovf    ; handle upmost overflow bit
+       and     $ap,$tp,$ovf
+       andc    $np,$rp,$ovf
+       or      $ap,$ap,$np     ; ap=borrow?tp:rp
+
+.align 4
+Lcopy:                         ; copy or in-place refresh
+       $LDX    $tj,$ap,$j
+       $STX    $tj,$rp,$j
+       $STX    $j,$tp,$j       ; zap at once
+       addi    $j,$j,$BNSZ
+       bdnz-   Lcopy
+
+       $POP    r14,`4*$SIZE_T`($sp)
+       $POP    r15,`5*$SIZE_T`($sp)
+       $POP    r16,`6*$SIZE_T`($sp)
+       $POP    r17,`7*$SIZE_T`($sp)
+       $POP    r18,`8*$SIZE_T`($sp)
+       $POP    r19,`9*$SIZE_T`($sp)
+       $POP    r20,`10*$SIZE_T`($sp)
+       $POP    r21,`11*$SIZE_T`($sp)
+       $POP    r22,`12*$SIZE_T`($sp)
+       $POP    r23,`13*$SIZE_T`($sp)
+       $POP    r24,`14*$SIZE_T`($sp)
+       $POP    r25,`15*$SIZE_T`($sp)
+       $POP    $sp,0($sp)
+       li      r3,1
+       blr
+       .long   0
+.asciz  "Montgomery Multiplication for PPC, CRYPTOGAMS by <appro\@fy.chalmers.se>"
+___
+
+$code =~ s/\`([^\`]*)\`/eval $1/gem;
+print $code;
+close STDOUT;
index 806e53a..f409317 100644 (file)
 #      me a note at schari@us.ibm.com
 #
 
-$opf = shift;
+$flavour = shift;
 
-if ($opf =~ /32\.s/) {
+if ($flavour =~ /32/) {
        $BITS=  32;
        $BNSZ=  $BITS/8;
        $ISA=   "\"ppc\"";
@@ -125,7 +125,7 @@ if ($opf =~ /32\.s/) {
        $INSR=  "insrwi";       # insert right
        $ROTL=  "rotlwi";       # rotate left by immediate
        $TR=    "tw";           # conditional trap
-} elsif ($opf =~ /64\.s/) {
+} elsif ($flavour =~ /64/) {
        $BITS=  64;
        $BNSZ=  $BITS/8;
        $ISA=   "\"ppc64\"";
@@ -149,93 +149,16 @@ if ($opf =~ /32\.s/) {
        $INSR=  "insrdi";       # insert right 
        $ROTL=  "rotldi";       # rotate left by immediate
        $TR=    "td";           # conditional trap
-} else { die "nonsense $opf"; }
+} else { die "nonsense $flavour"; }
 
-( defined shift || open STDOUT,">$opf" ) || die "can't open $opf: $!";
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+( $xlate="${dir}ppc-xlate.pl" and -f $xlate ) or
+( $xlate="${dir}../../perlasm/ppc-xlate.pl" and -f $xlate) or
+die "can't locate ppc-xlate.pl";
 
-# function entry points from the AIX code
-#
-# There are other, more elegant, ways to handle this. We (IBM) chose
-# this approach as it plays well with scripts we run to 'namespace'
-# OpenSSL .i.e. we add a prefix to all the public symbols so we can
-# co-exist in the same process with other implementations of OpenSSL.
-# 'cleverer' ways of doing these substitutions tend to hide data we
-# need to be obvious.
-#
-my @items = ("bn_sqr_comba4",
-            "bn_sqr_comba8",
-            "bn_mul_comba4",
-            "bn_mul_comba8",
-            "bn_sub_words",
-            "bn_add_words",
-            "bn_div_words",
-            "bn_sqr_words",
-            "bn_mul_words",
-            "bn_mul_add_words");
+open STDOUT,"| $^X $xlate $flavour ".shift || die "can't call $xlate: $!";
 
-if    ($opf =~ /linux/)        {  do_linux();  }
-elsif ($opf =~ /aix/)  {  do_aix();    }
-elsif ($opf =~ /osx/)  {  do_osx();    }
-else                   {  do_bsd();    }
-
-sub do_linux {
-    $d=&data();
-
-    if ($BITS==64) {
-      foreach $t (@items) {
-        $d =~ s/\.$t:/\
-\t.section\t".opd","aw"\
-\t.align\t3\
-\t.globl\t$t\
-$t:\
-\t.quad\t.$t,.TOC.\@tocbase,0\
-\t.size\t$t,24\
-\t.previous\n\
-\t.type\t.$t,\@function\
-\t.globl\t.$t\
-.$t:/g;
-      }
-    }
-    else {
-      foreach $t (@items) {
-        $d=~s/\.$t/$t/g;
-      }
-    }
-    # hide internal labels to avoid pollution of name table...
-    $d=~s/Lppcasm_/.Lppcasm_/gm;
-    print $d;
-}
-
-sub do_aix {
-    # AIX assembler is smart enough to please the linker without
-    # making us do something special...
-    print &data();
-}
-
-# MacOSX 32 bit
-sub do_osx {
-    $d=&data();
-    # Change the bn symbol prefix from '.' to '_'
-    foreach $t (@items) {
-      $d=~s/\.$t/_$t/g;
-    }
-    # Change .machine to something OS X asm will accept
-    $d=~s/\.machine.*/.text/g;
-    $d=~s/\#/;/g; # change comment from '#' to ';'
-    print $d;
-}
-
-# BSD (Untested)
-sub do_bsd {
-    $d=&data();
-    foreach $t (@items) {
-      $d=~s/\.$t/_$t/g;
-    }
-    print $d;
-}
-
-sub data {
-       local($data)=<<EOF;
+$data=<<EOF;
 #--------------------------------------------------------------------
 #
 #
@@ -297,33 +220,20 @@ sub data {
 #
 #      Defines to be used in the assembly code.
 #      
-.set r0,0      # we use it as storage for value of 0
-.set SP,1      # preserved
-.set RTOC,2    # preserved 
-.set r3,3      # 1st argument/return value
-.set r4,4      # 2nd argument/volatile register
-.set r5,5      # 3rd argument/volatile register
-.set r6,6      # ...
-.set r7,7
-.set r8,8
-.set r9,9
-.set r10,10
-.set r11,11
-.set r12,12
-.set r13,13    # not used, nor any other "below" it...
-
-.set BO_IF_NOT,4
-.set BO_IF,12
-.set BO_dCTR_NZERO,16
-.set BO_dCTR_ZERO,18
-.set BO_ALWAYS,20
-.set CR0_LT,0;
-.set CR0_GT,1;
-.set CR0_EQ,2
-.set CR1_FX,4;
-.set CR1_FEX,5;
-.set CR1_VX,6
-.set LR,8
+#.set r0,0     # we use it as storage for value of 0
+#.set SP,1     # preserved
+#.set RTOC,2   # preserved 
+#.set r3,3     # 1st argument/return value
+#.set r4,4     # 2nd argument/volatile register
+#.set r5,5     # 3rd argument/volatile register
+#.set r6,6     # ...
+#.set r7,7
+#.set r8,8
+#.set r9,9
+#.set r10,10
+#.set r11,11
+#.set r12,12
+#.set r13,13   # not used, nor any other "below" it...
 
 #      Declare function names to be global
 #      NOTE:   For gcc these names MUST be changed to remove
@@ -344,7 +254,7 @@ sub data {
        
 # .text section
        
-       .machine        $ISA
+       .machine        "any"
 
 #
 #      NOTE:   The following label name should be changed to
@@ -478,7 +388,7 @@ sub data {
 
        $ST             r9,`6*$BNSZ`(r3)        #r[6]=c1
        $ST             r10,`7*$BNSZ`(r3)       #r[7]=c2
-       bclr    BO_ALWAYS,CR0_LT
+       blr
        .long   0x00000000
 
 #
@@ -903,7 +813,7 @@ sub data {
        $ST             r9, `15*$BNSZ`(r3)      #r[15]=c1;
 
 
-       bclr    BO_ALWAYS,CR0_LT
+       blr
 
        .long   0x00000000
 
@@ -1039,7 +949,7 @@ sub data {
        addze   r11,r0
                                        #mul_add_c(a[3],b[2],c3,c1,c2);
        $LD     r6,`3*$BNSZ`(r4)
-       $LD     r7,`2*$BNSZ`(r4)
+       $LD     r7,`2*$BNSZ`(r5)
        $UMULL  r8,r6,r7
        $UMULH  r9,r6,r7
        addc    r12,r8,r12
@@ -1055,7 +965,7 @@ sub data {
 
        $ST     r10,`6*$BNSZ`(r3)       #r[6]=c1
        $ST     r11,`7*$BNSZ`(r3)       #r[7]=c2
-       bclr    BO_ALWAYS,CR0_LT
+       blr
        .long   0x00000000
 
 #
@@ -1591,7 +1501,7 @@ sub data {
        adde    r10,r10,r9
        $ST     r12,`14*$BNSZ`(r3)      #r[14]=c3;
        $ST     r10,`15*$BNSZ`(r3)      #r[15]=c1;
-       bclr    BO_ALWAYS,CR0_LT
+       blr
        .long   0x00000000
 
 #
@@ -1623,7 +1533,7 @@ sub data {
        subfc.  r7,r0,r6        # If r6 is 0 then result is 0.
                                # if r6 > 0 then result !=0
                                # In either case carry bit is set.
-       bc      BO_IF,CR0_EQ,Lppcasm_sub_adios
+       beq     Lppcasm_sub_adios
        addi    r4,r4,-$BNSZ
        addi    r3,r3,-$BNSZ
        addi    r5,r5,-$BNSZ
@@ -1635,11 +1545,11 @@ Lppcasm_sub_mainloop:
                                # if carry = 1 this is r7-r8. Else it
                                # is r7-r8 -1 as we need.
        $STU    r6,$BNSZ(r3)
-       bc      BO_dCTR_NZERO,CR0_EQ,Lppcasm_sub_mainloop
+       bdnz-   Lppcasm_sub_mainloop
 Lppcasm_sub_adios:     
        subfze  r3,r0           # if carry bit is set then r3 = 0 else -1
        andi.   r3,r3,1         # keep only last bit.
-       bclr    BO_ALWAYS,CR0_LT
+       blr
        .long   0x00000000
 
 
@@ -1670,7 +1580,7 @@ Lppcasm_sub_adios:
 #      check for r6 = 0. Is this needed?
 #
        addic.  r6,r6,0         #test r6 and clear carry bit.
-       bc      BO_IF,CR0_EQ,Lppcasm_add_adios
+       beq     Lppcasm_add_adios
        addi    r4,r4,-$BNSZ
        addi    r3,r3,-$BNSZ
        addi    r5,r5,-$BNSZ
@@ -1680,10 +1590,10 @@ Lppcasm_add_mainloop:
        $LDU    r8,$BNSZ(r5)
        adde    r8,r7,r8
        $STU    r8,$BNSZ(r3)
-       bc      BO_dCTR_NZERO,CR0_EQ,Lppcasm_add_mainloop
+       bdnz-   Lppcasm_add_mainloop
 Lppcasm_add_adios:     
        addze   r3,r0                   #return carry bit.
-       bclr    BO_ALWAYS,CR0_LT
+       blr
        .long   0x00000000
 
 #
@@ -1707,24 +1617,24 @@ Lppcasm_add_adios:
 #      r5 = d
        
        $UCMPI  0,r5,0                  # compare r5 and 0
-       bc      BO_IF_NOT,CR0_EQ,Lppcasm_div1   # proceed if d!=0
+       bne     Lppcasm_div1            # proceed if d!=0
        li      r3,-1                   # d=0 return -1
-       bclr    BO_ALWAYS,CR0_LT        
+       blr
 Lppcasm_div1:
        xor     r0,r0,r0                #r0=0
        li      r8,$BITS
        $CNTLZ. r7,r5                   #r7 = num leading 0s in d.
-       bc      BO_IF,CR0_EQ,Lppcasm_div2       #proceed if no leading zeros
+       beq     Lppcasm_div2            #proceed if no leading zeros
        subf    r8,r7,r8                #r8 = BN_num_bits_word(d)
        $SHR.   r9,r3,r8                #are there any bits above r8'th?
        $TR     16,r9,r0                #if there're, signal to dump core...
 Lppcasm_div2:
        $UCMP   0,r3,r5                 #h>=d?
-       bc      BO_IF,CR0_LT,Lppcasm_div3       #goto Lppcasm_div3 if not
+       blt     Lppcasm_div3            #goto Lppcasm_div3 if not
        subf    r3,r5,r3                #h-=d ; 
 Lppcasm_div3:                          #r7 = BN_BITS2-i. so r7=i
        cmpi    0,0,r7,0                # is (i == 0)?
-       bc      BO_IF,CR0_EQ,Lppcasm_div4
+       beq     Lppcasm_div4
        $SHL    r3,r3,r7                # h = (h<< i)
        $SHR    r8,r4,r8                # r8 = (l >> BN_BITS2 -i)
        $SHL    r5,r5,r7                # d<<=i
@@ -1741,7 +1651,7 @@ Lppcasm_divouterloop:
        $SHRI   r11,r4,`$BITS/2`        #r11= (l&BN_MASK2h)>>BN_BITS4
                                        # compute here for innerloop.
        $UCMP   0,r8,r9                 # is (h>>BN_BITS4)==dh
-       bc      BO_IF_NOT,CR0_EQ,Lppcasm_div5   # goto Lppcasm_div5 if not
+       bne     Lppcasm_div5            # goto Lppcasm_div5 if not
 
        li      r8,-1
        $CLRU   r8,r8,`$BITS/2`         #q = BN_MASK2l 
@@ -1762,9 +1672,9 @@ Lppcasm_divinnerloop:
                                        # the following 2 instructions do that
        $SHLI   r7,r10,`$BITS/2`        # r7 = (t<<BN_BITS4)
        or      r7,r7,r11               # r7|=((l&BN_MASK2h)>>BN_BITS4)
-       $UCMP   1,r6,r7                 # compare (tl <= r7)
-       bc      BO_IF_NOT,CR0_EQ,Lppcasm_divinnerexit
-       bc      BO_IF_NOT,CR1_FEX,Lppcasm_divinnerexit
+       $UCMP   cr1,r6,r7               # compare (tl <= r7)
+       bne     Lppcasm_divinnerexit
+       ble     cr1,Lppcasm_divinnerexit
        addi    r8,r8,-1                #q--
        subf    r12,r9,r12              #th -=dh
        $CLRU   r10,r5,`$BITS/2`        #r10=dl. t is no longer needed in loop.
@@ -1773,14 +1683,14 @@ Lppcasm_divinnerloop:
 Lppcasm_divinnerexit:
        $SHRI   r10,r6,`$BITS/2`        #t=(tl>>BN_BITS4)
        $SHLI   r11,r6,`$BITS/2`        #tl=(tl<<BN_BITS4)&BN_MASK2h;
-       $UCMP   1,r4,r11                # compare l and tl
+       $UCMP   cr1,r4,r11              # compare l and tl
        add     r12,r12,r10             # th+=t
-       bc      BO_IF_NOT,CR1_FX,Lppcasm_div7  # if (l>=tl) goto Lppcasm_div7
+       bge     cr1,Lppcasm_div7        # if (l>=tl) goto Lppcasm_div7
        addi    r12,r12,1               # th++
 Lppcasm_div7:
        subf    r11,r11,r4              #r11=l-tl
-       $UCMP   1,r3,r12                #compare h and th
-       bc      BO_IF_NOT,CR1_FX,Lppcasm_div8   #if (h>=th) goto Lppcasm_div8
+       $UCMP   cr1,r3,r12              #compare h and th
+       bge     cr1,Lppcasm_div8        #if (h>=th) goto Lppcasm_div8
        addi    r8,r8,-1                # q--
        add     r3,r5,r3                # h+=d
 Lppcasm_div8:
@@ -1791,12 +1701,12 @@ Lppcasm_div8:
                                        # the following 2 instructions will do this.
        $INSR   r11,r12,`$BITS/2`,`$BITS/2`     # r11 is the value we want rotated $BITS/2.
        $ROTL   r3,r11,`$BITS/2`        # rotate by $BITS/2 and store in r3
-       bc      BO_dCTR_ZERO,CR0_EQ,Lppcasm_div9#if (count==0) break ;
+       bdz     Lppcasm_div9            #if (count==0) break ;
        $SHLI   r0,r8,`$BITS/2`         #ret =q<<BN_BITS4
        b       Lppcasm_divouterloop
 Lppcasm_div9:
        or      r3,r8,r0
-       bclr    BO_ALWAYS,CR0_LT
+       blr
        .long   0x00000000
 
 #
@@ -1822,7 +1732,7 @@ Lppcasm_div9:
 #      No unrolling done here. Not performance critical.
 
        addic.  r5,r5,0                 #test r5.
-       bc      BO_IF,CR0_EQ,Lppcasm_sqr_adios
+       beq     Lppcasm_sqr_adios
        addi    r4,r4,-$BNSZ
        addi    r3,r3,-$BNSZ
        mtctr   r5
@@ -1833,9 +1743,9 @@ Lppcasm_sqr_mainloop:
        $UMULH  r8,r6,r6
        $STU    r7,$BNSZ(r3)
        $STU    r8,$BNSZ(r3)
-       bc      BO_dCTR_NZERO,CR0_EQ,Lppcasm_sqr_mainloop
+       bdnz-   Lppcasm_sqr_mainloop
 Lppcasm_sqr_adios:     
-       bclr    BO_ALWAYS,CR0_LT
+       blr
        .long   0x00000000
 
 
@@ -1858,7 +1768,7 @@ Lppcasm_sqr_adios:
        xor     r0,r0,r0
        xor     r12,r12,r12             # used for carry
        rlwinm. r7,r5,30,2,31           # num >> 2
-       bc      BO_IF,CR0_EQ,Lppcasm_mw_REM
+       beq     Lppcasm_mw_REM
        mtctr   r7
 Lppcasm_mw_LOOP:       
                                        #mul(rp[0],ap[0],w,c1);
@@ -1896,11 +1806,11 @@ Lppcasm_mw_LOOP:
        
        addi    r3,r3,`4*$BNSZ`
        addi    r4,r4,`4*$BNSZ`
-       bc      BO_dCTR_NZERO,CR0_EQ,Lppcasm_mw_LOOP
+       bdnz-   Lppcasm_mw_LOOP
 
 Lppcasm_mw_REM:
        andi.   r5,r5,0x3
-       bc      BO_IF,CR0_EQ,Lppcasm_mw_OVER
+       beq     Lppcasm_mw_OVER
                                        #mul(rp[0],ap[0],w,c1);
        $LD     r8,`0*$BNSZ`(r4)
        $UMULL  r9,r6,r8
@@ -1912,7 +1822,7 @@ Lppcasm_mw_REM:
        
        addi    r5,r5,-1
        cmpli   0,0,r5,0
-       bc      BO_IF,CR0_EQ,Lppcasm_mw_OVER
+       beq     Lppcasm_mw_OVER
 
        
                                        #mul(rp[1],ap[1],w,c1);
@@ -1926,7 +1836,7 @@ Lppcasm_mw_REM:
        
        addi    r5,r5,-1
        cmpli   0,0,r5,0
-       bc      BO_IF,CR0_EQ,Lppcasm_mw_OVER
+       beq     Lppcasm_mw_OVER
        
                                        #mul_add(rp[2],ap[2],w,c1);
        $LD     r8,`2*$BNSZ`(r4)
@@ -1939,7 +1849,7 @@ Lppcasm_mw_REM:
                
 Lppcasm_mw_OVER:       
        addi    r3,r12,0
-       bclr    BO_ALWAYS,CR0_LT
+       blr
        .long   0x00000000
 
 #
@@ -1964,7 +1874,7 @@ Lppcasm_mw_OVER:
        xor     r0,r0,r0                #r0 = 0
        xor     r12,r12,r12             #r12 = 0 . used for carry               
        rlwinm. r7,r5,30,2,31           # num >> 2
-       bc      BO_IF,CR0_EQ,Lppcasm_maw_leftover       # if (num < 4) go LPPCASM_maw_leftover
+       beq     Lppcasm_maw_leftover    # if (num < 4) go LPPCASM_maw_leftover
        mtctr   r7
 Lppcasm_maw_mainloop:  
                                        #mul_add(rp[0],ap[0],w,c1);
@@ -2017,11 +1927,11 @@ Lppcasm_maw_mainloop:
        $ST     r11,`3*$BNSZ`(r3)
        addi    r3,r3,`4*$BNSZ`
        addi    r4,r4,`4*$BNSZ`
-       bc      BO_dCTR_NZERO,CR0_EQ,Lppcasm_maw_mainloop
+       bdnz-   Lppcasm_maw_mainloop
        
 Lppcasm_maw_leftover:
        andi.   r5,r5,0x3
-       bc      BO_IF,CR0_EQ,Lppcasm_maw_adios
+       beq     Lppcasm_maw_adios
        addi    r3,r3,-$BNSZ
        addi    r4,r4,-$BNSZ
                                        #mul_add(rp[0],ap[0],w,c1);
@@ -2036,7 +1946,7 @@ Lppcasm_maw_leftover:
        addze   r12,r10
        $ST     r9,0(r3)
        
-       bc      BO_dCTR_ZERO,CR0_EQ,Lppcasm_maw_adios
+       bdz     Lppcasm_maw_adios
                                        #mul_add(rp[1],ap[1],w,c1);
        $LDU    r8,$BNSZ(r4)    
        $UMULL  r9,r6,r8
@@ -2048,7 +1958,7 @@ Lppcasm_maw_leftover:
        addze   r12,r10
        $ST     r9,0(r3)
        
-       bc      BO_dCTR_ZERO,CR0_EQ,Lppcasm_maw_adios
+       bdz     Lppcasm_maw_adios
                                        #mul_add(rp[2],ap[2],w,c1);
        $LDU    r8,$BNSZ(r4)
        $UMULL  r9,r6,r8
@@ -2062,19 +1972,10 @@ Lppcasm_maw_leftover:
                
 Lppcasm_maw_adios:     
        addi    r3,r12,0
-       bclr    BO_ALWAYS,CR0_LT
+       blr
        .long   0x00000000
        .align  4
 EOF
-       $data =~ s/\`([^\`]*)\`/eval $1/gem;
-
-       # if some assembler chokes on some simplified mnemonic,
-       # this is the spot to fix it up, e.g.:
-       # GNU as doesn't seem to accept cmplw, 32-bit unsigned compare
-       $data =~ s/^(\s*)cmplw(\s+)([^,]+),(.*)/$1cmpl$2$3,0,$4/gm;
-       # assembler X doesn't accept li, load immediate value
-       #$data =~ s/^(\s*)li(\s+)([^,]+),(.*)/$1addi$2$3,0,$4/gm;
-       # assembler Y chokes on apostrophes in comments
-       $data =~ s/'//gm;
-       return($data);
-}
+$data =~ s/\`([^\`]*)\`/eval $1/gem;
+print $data;
+close STDOUT;
diff --git a/deps/openssl/openssl/crypto/bn/asm/ppc64-mont.pl b/deps/openssl/openssl/crypto/bn/asm/ppc64-mont.pl
new file mode 100644 (file)
index 0000000..3449b35
--- /dev/null
@@ -0,0 +1,918 @@
+#!/usr/bin/env perl
+
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+
+# December 2007
+
+# The reason for undertaken effort is basically following. Even though
+# Power 6 CPU operates at incredible 4.7GHz clock frequency, its PKI
+# performance was observed to be less than impressive, essentially as
+# fast as 1.8GHz PPC970, or 2.6 times(!) slower than one would hope.
+# Well, it's not surprising that IBM had to make some sacrifices to
+# boost the clock frequency that much, but no overall improvement?
+# Having observed how much difference did switching to FPU make on
+# UltraSPARC, playing same stunt on Power 6 appeared appropriate...
+# Unfortunately the resulting performance improvement is not as
+# impressive, ~30%, and in absolute terms is still very far from what
+# one would expect from 4.7GHz CPU. There is a chance that I'm doing
+# something wrong, but in the lack of assembler level micro-profiling
+# data or at least decent platform guide I can't tell... Or better
+# results might be achieved with VMX... Anyway, this module provides
+# *worse* performance on other PowerPC implementations, ~40-15% slower
+# on PPC970 depending on key length and ~40% slower on Power 5 for all
+# key lengths. As it's obviously inappropriate as "best all-round"
+# alternative, it has to be complemented with run-time CPU family
+# detection. Oh! It should also be noted that unlike other PowerPC
+# implementation IALU ppc-mont.pl module performs *suboptimaly* on
+# >=1024-bit key lengths on Power 6. It should also be noted that
+# *everything* said so far applies to 64-bit builds! As far as 32-bit
+# application executed on 64-bit CPU goes, this module is likely to
+# become preferred choice, because it's easy to adapt it for such
+# case and *is* faster than 32-bit ppc-mont.pl on *all* processors.
+
+# February 2008
+
+# Micro-profiling assisted optimization results in ~15% improvement
+# over original ppc64-mont.pl version, or overall ~50% improvement
+# over ppc.pl module on Power 6. If compared to ppc-mont.pl on same
+# Power 6 CPU, this module is 5-150% faster depending on key length,
+# [hereafter] more for longer keys. But if compared to ppc-mont.pl
+# on 1.8GHz PPC970, it's only 5-55% faster. Still far from impressive
+# in absolute terms, but it's apparently the way Power 6 is...
+
+$flavour = shift;
+
+if ($flavour =~ /32/) {
+       $SIZE_T=4;
+       $RZONE= 224;
+       $FRAME= $SIZE_T*12+8*12;
+       $fname= "bn_mul_mont_ppc64";
+
+       $STUX=  "stwux";        # store indexed and update
+       $PUSH=  "stw";
+       $POP=   "lwz";
+       die "not implemented yet";
+} elsif ($flavour =~ /64/) {
+       $SIZE_T=8;
+       $RZONE= 288;
+       $FRAME= $SIZE_T*12+8*12;
+       $fname= "bn_mul_mont";
+
+       # same as above, but 64-bit mnemonics...
+       $STUX=  "stdux";        # store indexed and update
+       $PUSH=  "std";
+       $POP=   "ld";
+} else { die "nonsense $flavour"; }
+
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+( $xlate="${dir}ppc-xlate.pl" and -f $xlate ) or
+( $xlate="${dir}../../perlasm/ppc-xlate.pl" and -f $xlate) or
+die "can't locate ppc-xlate.pl";
+
+open STDOUT,"| $^X $xlate $flavour ".shift || die "can't call $xlate: $!";
+
+$FRAME=($FRAME+63)&~63;
+$TRANSFER=16*8;
+
+$carry="r0";
+$sp="r1";
+$toc="r2";
+$rp="r3";      $ovf="r3";
+$ap="r4";
+$bp="r5";
+$np="r6";
+$n0="r7";
+$num="r8";
+$rp="r9";      # $rp is reassigned
+$tp="r10";
+$j="r11";
+$i="r12";
+# non-volatile registers
+$nap_d="r14";  # interleaved ap and np in double format
+$a0="r15";     # ap[0]
+$t0="r16";     # temporary registers
+$t1="r17";
+$t2="r18";
+$t3="r19";
+$t4="r20";
+$t5="r21";
+$t6="r22";
+$t7="r23";
+
+# PPC offers enough register bank capacity to unroll inner loops twice
+#
+#     ..A3A2A1A0
+#           dcba
+#    -----------
+#            A0a
+#           A0b
+#          A0c
+#         A0d
+#          A1a
+#         A1b
+#        A1c
+#       A1d
+#        A2a
+#       A2b
+#      A2c
+#     A2d
+#      A3a
+#     A3b
+#    A3c
+#   A3d
+#    ..a
+#   ..b
+#
+$ba="f0";      $bb="f1";       $bc="f2";       $bd="f3";
+$na="f4";      $nb="f5";       $nc="f6";       $nd="f7";
+$dota="f8";    $dotb="f9";
+$A0="f10";     $A1="f11";      $A2="f12";      $A3="f13";
+$N0="f14";     $N1="f15";      $N2="f16";      $N3="f17";
+$T0a="f18";    $T0b="f19";
+$T1a="f20";    $T1b="f21";
+$T2a="f22";    $T2b="f23";
+$T3a="f24";    $T3b="f25";
+\f
+# sp----------->+-------------------------------+
+#              | saved sp                      |
+#              +-------------------------------+
+#              |                               |
+#              +-------------------------------+
+#              | 10 saved gpr, r14-r23         |
+#              .                               .
+#              .                               .
+#   +12*size_t +-------------------------------+
+#              | 12 saved fpr, f14-f25         |
+#              .                               .
+#              .                               .
+#   +12*8      +-------------------------------+
+#              | padding to 64 byte boundary   |
+#              .                               .
+#   +X         +-------------------------------+
+#              | 16 gpr<->fpr transfer zone    |
+#              .                               .
+#              .                               .
+#   +16*8      +-------------------------------+
+#              | __int64 tmp[-1]               |
+#              +-------------------------------+
+#              | __int64 tmp[num]              |
+#              .                               .
+#              .                               .
+#              .                               .
+#   +(num+1)*8 +-------------------------------+
+#              | padding to 64 byte boundary   |
+#              .                               .
+#   +X         +-------------------------------+
+#              | double nap_d[4*num]           |
+#              .                               .
+#              .                               .
+#              .                               .
+#              +-------------------------------+
+\f
+$code=<<___;
+.machine "any"
+.text
+
+.globl .$fname
+.align 5
+.$fname:
+       cmpwi   $num,4
+       mr      $rp,r3          ; $rp is reassigned
+       li      r3,0            ; possible "not handled" return code
+       bltlr-
+       andi.   r0,$num,1       ; $num has to be even
+       bnelr-
+
+       slwi    $num,$num,3     ; num*=8
+       li      $i,-4096
+       slwi    $tp,$num,2      ; place for {an}p_{lh}[num], i.e. 4*num
+       add     $tp,$tp,$num    ; place for tp[num+1]
+       addi    $tp,$tp,`$FRAME+$TRANSFER+8+64+$RZONE`
+       subf    $tp,$tp,$sp     ; $sp-$tp
+       and     $tp,$tp,$i      ; minimize TLB usage
+       subf    $tp,$sp,$tp     ; $tp-$sp
+       $STUX   $sp,$sp,$tp     ; alloca
+
+       $PUSH   r14,`2*$SIZE_T`($sp)
+       $PUSH   r15,`3*$SIZE_T`($sp)
+       $PUSH   r16,`4*$SIZE_T`($sp)
+       $PUSH   r17,`5*$SIZE_T`($sp)
+       $PUSH   r18,`6*$SIZE_T`($sp)
+       $PUSH   r19,`7*$SIZE_T`($sp)
+       $PUSH   r20,`8*$SIZE_T`($sp)
+       $PUSH   r21,`9*$SIZE_T`($sp)
+       $PUSH   r22,`10*$SIZE_T`($sp)
+       $PUSH   r23,`11*$SIZE_T`($sp)
+       stfd    f14,`12*$SIZE_T+0`($sp)
+       stfd    f15,`12*$SIZE_T+8`($sp)
+       stfd    f16,`12*$SIZE_T+16`($sp)
+       stfd    f17,`12*$SIZE_T+24`($sp)
+       stfd    f18,`12*$SIZE_T+32`($sp)
+       stfd    f19,`12*$SIZE_T+40`($sp)
+       stfd    f20,`12*$SIZE_T+48`($sp)
+       stfd    f21,`12*$SIZE_T+56`($sp)
+       stfd    f22,`12*$SIZE_T+64`($sp)
+       stfd    f23,`12*$SIZE_T+72`($sp)
+       stfd    f24,`12*$SIZE_T+80`($sp)
+       stfd    f25,`12*$SIZE_T+88`($sp)
+
+       ld      $a0,0($ap)      ; pull ap[0] value
+       ld      $n0,0($n0)      ; pull n0[0] value
+       ld      $t3,0($bp)      ; bp[0]
+
+       addi    $tp,$sp,`$FRAME+$TRANSFER+8+64`
+       li      $i,-64
+       add     $nap_d,$tp,$num
+       and     $nap_d,$nap_d,$i        ; align to 64 bytes
+\f
+       mulld   $t7,$a0,$t3     ; ap[0]*bp[0]
+       ; nap_d is off by 1, because it's used with stfdu/lfdu
+       addi    $nap_d,$nap_d,-8
+       srwi    $j,$num,`3+1`   ; counter register, num/2
+       mulld   $t7,$t7,$n0     ; tp[0]*n0
+       addi    $j,$j,-1
+       addi    $tp,$sp,`$FRAME+$TRANSFER-8`
+       li      $carry,0
+       mtctr   $j
+
+       ; transfer bp[0] to FPU as 4x16-bit values
+       extrdi  $t0,$t3,16,48
+       extrdi  $t1,$t3,16,32
+       extrdi  $t2,$t3,16,16
+       extrdi  $t3,$t3,16,0
+       std     $t0,`$FRAME+0`($sp)
+       std     $t1,`$FRAME+8`($sp)
+       std     $t2,`$FRAME+16`($sp)
+       std     $t3,`$FRAME+24`($sp)
+       ; transfer (ap[0]*bp[0])*n0 to FPU as 4x16-bit values
+       extrdi  $t4,$t7,16,48
+       extrdi  $t5,$t7,16,32
+       extrdi  $t6,$t7,16,16
+       extrdi  $t7,$t7,16,0
+       std     $t4,`$FRAME+32`($sp)
+       std     $t5,`$FRAME+40`($sp)
+       std     $t6,`$FRAME+48`($sp)
+       std     $t7,`$FRAME+56`($sp)
+       lwz     $t0,4($ap)              ; load a[j] as 32-bit word pair
+       lwz     $t1,0($ap)
+       lwz     $t2,12($ap)             ; load a[j+1] as 32-bit word pair
+       lwz     $t3,8($ap)
+       lwz     $t4,4($np)              ; load n[j] as 32-bit word pair
+       lwz     $t5,0($np)
+       lwz     $t6,12($np)             ; load n[j+1] as 32-bit word pair
+       lwz     $t7,8($np)
+       lfd     $ba,`$FRAME+0`($sp)
+       lfd     $bb,`$FRAME+8`($sp)
+       lfd     $bc,`$FRAME+16`($sp)
+       lfd     $bd,`$FRAME+24`($sp)
+       lfd     $na,`$FRAME+32`($sp)
+       lfd     $nb,`$FRAME+40`($sp)
+       lfd     $nc,`$FRAME+48`($sp)
+       lfd     $nd,`$FRAME+56`($sp)
+       std     $t0,`$FRAME+64`($sp)
+       std     $t1,`$FRAME+72`($sp)
+       std     $t2,`$FRAME+80`($sp)
+       std     $t3,`$FRAME+88`($sp)
+       std     $t4,`$FRAME+96`($sp)
+       std     $t5,`$FRAME+104`($sp)
+       std     $t6,`$FRAME+112`($sp)
+       std     $t7,`$FRAME+120`($sp)
+       fcfid   $ba,$ba
+       fcfid   $bb,$bb
+       fcfid   $bc,$bc
+       fcfid   $bd,$bd
+       fcfid   $na,$na
+       fcfid   $nb,$nb
+       fcfid   $nc,$nc
+       fcfid   $nd,$nd
+
+       lfd     $A0,`$FRAME+64`($sp)
+       lfd     $A1,`$FRAME+72`($sp)
+       lfd     $A2,`$FRAME+80`($sp)
+       lfd     $A3,`$FRAME+88`($sp)
+       lfd     $N0,`$FRAME+96`($sp)
+       lfd     $N1,`$FRAME+104`($sp)
+       lfd     $N2,`$FRAME+112`($sp)
+       lfd     $N3,`$FRAME+120`($sp)
+       fcfid   $A0,$A0
+       fcfid   $A1,$A1
+       fcfid   $A2,$A2
+       fcfid   $A3,$A3
+       fcfid   $N0,$N0
+       fcfid   $N1,$N1
+       fcfid   $N2,$N2
+       fcfid   $N3,$N3
+       addi    $ap,$ap,16
+       addi    $np,$np,16
+
+       fmul    $T1a,$A1,$ba
+       fmul    $T1b,$A1,$bb
+       stfd    $A0,8($nap_d)           ; save a[j] in double format
+       stfd    $A1,16($nap_d)
+       fmul    $T2a,$A2,$ba
+       fmul    $T2b,$A2,$bb
+       stfd    $A2,24($nap_d)          ; save a[j+1] in double format
+       stfd    $A3,32($nap_d)
+       fmul    $T3a,$A3,$ba
+       fmul    $T3b,$A3,$bb
+       stfd    $N0,40($nap_d)          ; save n[j] in double format
+       stfd    $N1,48($nap_d)
+       fmul    $T0a,$A0,$ba
+       fmul    $T0b,$A0,$bb
+       stfd    $N2,56($nap_d)          ; save n[j+1] in double format
+       stfdu   $N3,64($nap_d)
+
+       fmadd   $T1a,$A0,$bc,$T1a
+       fmadd   $T1b,$A0,$bd,$T1b
+       fmadd   $T2a,$A1,$bc,$T2a
+       fmadd   $T2b,$A1,$bd,$T2b
+       fmadd   $T3a,$A2,$bc,$T3a
+       fmadd   $T3b,$A2,$bd,$T3b
+       fmul    $dota,$A3,$bc
+       fmul    $dotb,$A3,$bd
+
+       fmadd   $T1a,$N1,$na,$T1a
+       fmadd   $T1b,$N1,$nb,$T1b
+       fmadd   $T2a,$N2,$na,$T2a
+       fmadd   $T2b,$N2,$nb,$T2b
+       fmadd   $T3a,$N3,$na,$T3a
+       fmadd   $T3b,$N3,$nb,$T3b
+       fmadd   $T0a,$N0,$na,$T0a
+       fmadd   $T0b,$N0,$nb,$T0b
+
+       fmadd   $T1a,$N0,$nc,$T1a
+       fmadd   $T1b,$N0,$nd,$T1b
+       fmadd   $T2a,$N1,$nc,$T2a
+       fmadd   $T2b,$N1,$nd,$T2b
+       fmadd   $T3a,$N2,$nc,$T3a
+       fmadd   $T3b,$N2,$nd,$T3b
+       fmadd   $dota,$N3,$nc,$dota
+       fmadd   $dotb,$N3,$nd,$dotb
+
+       fctid   $T0a,$T0a
+       fctid   $T0b,$T0b
+       fctid   $T1a,$T1a
+       fctid   $T1b,$T1b
+       fctid   $T2a,$T2a
+       fctid   $T2b,$T2b
+       fctid   $T3a,$T3a
+       fctid   $T3b,$T3b
+
+       stfd    $T0a,`$FRAME+0`($sp)
+       stfd    $T0b,`$FRAME+8`($sp)
+       stfd    $T1a,`$FRAME+16`($sp)
+       stfd    $T1b,`$FRAME+24`($sp)
+       stfd    $T2a,`$FRAME+32`($sp)
+       stfd    $T2b,`$FRAME+40`($sp)
+       stfd    $T3a,`$FRAME+48`($sp)
+       stfd    $T3b,`$FRAME+56`($sp)
+\f
+.align 5
+L1st:
+       lwz     $t0,4($ap)              ; load a[j] as 32-bit word pair
+       lwz     $t1,0($ap)
+       lwz     $t2,12($ap)             ; load a[j+1] as 32-bit word pair
+       lwz     $t3,8($ap)
+       lwz     $t4,4($np)              ; load n[j] as 32-bit word pair
+       lwz     $t5,0($np)
+       lwz     $t6,12($np)             ; load n[j+1] as 32-bit word pair
+       lwz     $t7,8($np)
+       std     $t0,`$FRAME+64`($sp)
+       std     $t1,`$FRAME+72`($sp)
+       std     $t2,`$FRAME+80`($sp)
+       std     $t3,`$FRAME+88`($sp)
+       std     $t4,`$FRAME+96`($sp)
+       std     $t5,`$FRAME+104`($sp)
+       std     $t6,`$FRAME+112`($sp)
+       std     $t7,`$FRAME+120`($sp)
+       ld      $t0,`$FRAME+0`($sp)
+       ld      $t1,`$FRAME+8`($sp)
+       ld      $t2,`$FRAME+16`($sp)
+       ld      $t3,`$FRAME+24`($sp)
+       ld      $t4,`$FRAME+32`($sp)
+       ld      $t5,`$FRAME+40`($sp)
+       ld      $t6,`$FRAME+48`($sp)
+       ld      $t7,`$FRAME+56`($sp)
+       lfd     $A0,`$FRAME+64`($sp)
+       lfd     $A1,`$FRAME+72`($sp)
+       lfd     $A2,`$FRAME+80`($sp)
+       lfd     $A3,`$FRAME+88`($sp)
+       lfd     $N0,`$FRAME+96`($sp)
+       lfd     $N1,`$FRAME+104`($sp)
+       lfd     $N2,`$FRAME+112`($sp)
+       lfd     $N3,`$FRAME+120`($sp)
+       fcfid   $A0,$A0
+       fcfid   $A1,$A1
+       fcfid   $A2,$A2
+       fcfid   $A3,$A3
+       fcfid   $N0,$N0
+       fcfid   $N1,$N1
+       fcfid   $N2,$N2
+       fcfid   $N3,$N3
+       addi    $ap,$ap,16
+       addi    $np,$np,16
+
+       fmul    $T1a,$A1,$ba
+       fmul    $T1b,$A1,$bb
+       fmul    $T2a,$A2,$ba
+       fmul    $T2b,$A2,$bb
+       stfd    $A0,8($nap_d)           ; save a[j] in double format
+       stfd    $A1,16($nap_d)
+       fmul    $T3a,$A3,$ba
+       fmul    $T3b,$A3,$bb
+       fmadd   $T0a,$A0,$ba,$dota
+       fmadd   $T0b,$A0,$bb,$dotb
+       stfd    $A2,24($nap_d)          ; save a[j+1] in double format
+       stfd    $A3,32($nap_d)
+
+       fmadd   $T1a,$A0,$bc,$T1a
+       fmadd   $T1b,$A0,$bd,$T1b
+       fmadd   $T2a,$A1,$bc,$T2a
+       fmadd   $T2b,$A1,$bd,$T2b
+       stfd    $N0,40($nap_d)          ; save n[j] in double format
+       stfd    $N1,48($nap_d)
+       fmadd   $T3a,$A2,$bc,$T3a
+       fmadd   $T3b,$A2,$bd,$T3b
+        add    $t0,$t0,$carry          ; can not overflow
+       fmul    $dota,$A3,$bc
+       fmul    $dotb,$A3,$bd
+       stfd    $N2,56($nap_d)          ; save n[j+1] in double format
+       stfdu   $N3,64($nap_d)
+        srdi   $carry,$t0,16
+        add    $t1,$t1,$carry
+        srdi   $carry,$t1,16
+
+       fmadd   $T1a,$N1,$na,$T1a
+       fmadd   $T1b,$N1,$nb,$T1b
+        insrdi $t0,$t1,16,32
+       fmadd   $T2a,$N2,$na,$T2a
+       fmadd   $T2b,$N2,$nb,$T2b
+        add    $t2,$t2,$carry
+       fmadd   $T3a,$N3,$na,$T3a
+       fmadd   $T3b,$N3,$nb,$T3b
+        srdi   $carry,$t2,16
+       fmadd   $T0a,$N0,$na,$T0a
+       fmadd   $T0b,$N0,$nb,$T0b
+        insrdi $t0,$t2,16,16
+        add    $t3,$t3,$carry
+        srdi   $carry,$t3,16
+
+       fmadd   $T1a,$N0,$nc,$T1a
+       fmadd   $T1b,$N0,$nd,$T1b
+        insrdi $t0,$t3,16,0            ; 0..63 bits
+       fmadd   $T2a,$N1,$nc,$T2a
+       fmadd   $T2b,$N1,$nd,$T2b
+        add    $t4,$t4,$carry
+       fmadd   $T3a,$N2,$nc,$T3a
+       fmadd   $T3b,$N2,$nd,$T3b
+        srdi   $carry,$t4,16
+       fmadd   $dota,$N3,$nc,$dota
+       fmadd   $dotb,$N3,$nd,$dotb
+        add    $t5,$t5,$carry
+        srdi   $carry,$t5,16
+        insrdi $t4,$t5,16,32
+
+       fctid   $T0a,$T0a
+       fctid   $T0b,$T0b
+        add    $t6,$t6,$carry
+       fctid   $T1a,$T1a
+       fctid   $T1b,$T1b
+        srdi   $carry,$t6,16
+       fctid   $T2a,$T2a
+       fctid   $T2b,$T2b
+        insrdi $t4,$t6,16,16
+       fctid   $T3a,$T3a
+       fctid   $T3b,$T3b
+        add    $t7,$t7,$carry
+        insrdi $t4,$t7,16,0            ; 64..127 bits
+        srdi   $carry,$t7,16           ; upper 33 bits
+
+       stfd    $T0a,`$FRAME+0`($sp)
+       stfd    $T0b,`$FRAME+8`($sp)
+       stfd    $T1a,`$FRAME+16`($sp)
+       stfd    $T1b,`$FRAME+24`($sp)
+       stfd    $T2a,`$FRAME+32`($sp)
+       stfd    $T2b,`$FRAME+40`($sp)
+       stfd    $T3a,`$FRAME+48`($sp)
+       stfd    $T3b,`$FRAME+56`($sp)
+        std    $t0,8($tp)              ; tp[j-1]
+        stdu   $t4,16($tp)             ; tp[j]
+       bdnz-   L1st
+\f
+       fctid   $dota,$dota
+       fctid   $dotb,$dotb
+
+       ld      $t0,`$FRAME+0`($sp)
+       ld      $t1,`$FRAME+8`($sp)
+       ld      $t2,`$FRAME+16`($sp)
+       ld      $t3,`$FRAME+24`($sp)
+       ld      $t4,`$FRAME+32`($sp)
+       ld      $t5,`$FRAME+40`($sp)
+       ld      $t6,`$FRAME+48`($sp)
+       ld      $t7,`$FRAME+56`($sp)
+       stfd    $dota,`$FRAME+64`($sp)
+       stfd    $dotb,`$FRAME+72`($sp)
+
+       add     $t0,$t0,$carry          ; can not overflow
+       srdi    $carry,$t0,16
+       add     $t1,$t1,$carry
+       srdi    $carry,$t1,16
+       insrdi  $t0,$t1,16,32
+       add     $t2,$t2,$carry
+       srdi    $carry,$t2,16
+       insrdi  $t0,$t2,16,16
+       add     $t3,$t3,$carry
+       srdi    $carry,$t3,16
+       insrdi  $t0,$t3,16,0            ; 0..63 bits
+       add     $t4,$t4,$carry
+       srdi    $carry,$t4,16
+       add     $t5,$t5,$carry
+       srdi    $carry,$t5,16
+       insrdi  $t4,$t5,16,32
+       add     $t6,$t6,$carry
+       srdi    $carry,$t6,16
+       insrdi  $t4,$t6,16,16
+       add     $t7,$t7,$carry
+       insrdi  $t4,$t7,16,0            ; 64..127 bits
+       srdi    $carry,$t7,16           ; upper 33 bits
+       ld      $t6,`$FRAME+64`($sp)
+       ld      $t7,`$FRAME+72`($sp)
+
+       std     $t0,8($tp)              ; tp[j-1]
+       stdu    $t4,16($tp)             ; tp[j]
+
+       add     $t6,$t6,$carry          ; can not overflow
+       srdi    $carry,$t6,16
+       add     $t7,$t7,$carry
+       insrdi  $t6,$t7,48,0
+       srdi    $ovf,$t7,48
+       std     $t6,8($tp)              ; tp[num-1]
+
+       slwi    $t7,$num,2
+       subf    $nap_d,$t7,$nap_d       ; rewind pointer
+\f
+       li      $i,8                    ; i=1
+.align 5
+Louter:
+       ldx     $t3,$bp,$i      ; bp[i]
+       ld      $t6,`$FRAME+$TRANSFER+8`($sp)   ; tp[0]
+       mulld   $t7,$a0,$t3     ; ap[0]*bp[i]
+
+       addi    $tp,$sp,`$FRAME+$TRANSFER`
+       add     $t7,$t7,$t6     ; ap[0]*bp[i]+tp[0]
+       li      $carry,0
+       mulld   $t7,$t7,$n0     ; tp[0]*n0
+       mtctr   $j
+
+       ; transfer bp[i] to FPU as 4x16-bit values
+       extrdi  $t0,$t3,16,48
+       extrdi  $t1,$t3,16,32
+       extrdi  $t2,$t3,16,16
+       extrdi  $t3,$t3,16,0
+       std     $t0,`$FRAME+0`($sp)
+       std     $t1,`$FRAME+8`($sp)
+       std     $t2,`$FRAME+16`($sp)
+       std     $t3,`$FRAME+24`($sp)
+       ; transfer (ap[0]*bp[i]+tp[0])*n0 to FPU as 4x16-bit values
+       extrdi  $t4,$t7,16,48
+       extrdi  $t5,$t7,16,32
+       extrdi  $t6,$t7,16,16
+       extrdi  $t7,$t7,16,0
+       std     $t4,`$FRAME+32`($sp)
+       std     $t5,`$FRAME+40`($sp)
+       std     $t6,`$FRAME+48`($sp)
+       std     $t7,`$FRAME+56`($sp)
+
+       lfd     $A0,8($nap_d)           ; load a[j] in double format
+       lfd     $A1,16($nap_d)
+       lfd     $A2,24($nap_d)          ; load a[j+1] in double format
+       lfd     $A3,32($nap_d)
+       lfd     $N0,40($nap_d)          ; load n[j] in double format
+       lfd     $N1,48($nap_d)
+       lfd     $N2,56($nap_d)          ; load n[j+1] in double format
+       lfdu    $N3,64($nap_d)
+
+       lfd     $ba,`$FRAME+0`($sp)
+       lfd     $bb,`$FRAME+8`($sp)
+       lfd     $bc,`$FRAME+16`($sp)
+       lfd     $bd,`$FRAME+24`($sp)
+       lfd     $na,`$FRAME+32`($sp)
+       lfd     $nb,`$FRAME+40`($sp)
+       lfd     $nc,`$FRAME+48`($sp)
+       lfd     $nd,`$FRAME+56`($sp)
+
+       fcfid   $ba,$ba
+       fcfid   $bb,$bb
+       fcfid   $bc,$bc
+       fcfid   $bd,$bd
+       fcfid   $na,$na
+       fcfid   $nb,$nb
+       fcfid   $nc,$nc
+       fcfid   $nd,$nd
+
+       fmul    $T1a,$A1,$ba
+       fmul    $T1b,$A1,$bb
+       fmul    $T2a,$A2,$ba
+       fmul    $T2b,$A2,$bb
+       fmul    $T3a,$A3,$ba
+       fmul    $T3b,$A3,$bb
+       fmul    $T0a,$A0,$ba
+       fmul    $T0b,$A0,$bb
+
+       fmadd   $T1a,$A0,$bc,$T1a
+       fmadd   $T1b,$A0,$bd,$T1b
+       fmadd   $T2a,$A1,$bc,$T2a
+       fmadd   $T2b,$A1,$bd,$T2b
+       fmadd   $T3a,$A2,$bc,$T3a
+       fmadd   $T3b,$A2,$bd,$T3b
+       fmul    $dota,$A3,$bc
+       fmul    $dotb,$A3,$bd
+
+       fmadd   $T1a,$N1,$na,$T1a
+       fmadd   $T1b,$N1,$nb,$T1b
+        lfd    $A0,8($nap_d)           ; load a[j] in double format
+        lfd    $A1,16($nap_d)
+       fmadd   $T2a,$N2,$na,$T2a
+       fmadd   $T2b,$N2,$nb,$T2b
+        lfd    $A2,24($nap_d)          ; load a[j+1] in double format
+        lfd    $A3,32($nap_d)
+       fmadd   $T3a,$N3,$na,$T3a
+       fmadd   $T3b,$N3,$nb,$T3b
+       fmadd   $T0a,$N0,$na,$T0a
+       fmadd   $T0b,$N0,$nb,$T0b
+
+       fmadd   $T1a,$N0,$nc,$T1a
+       fmadd   $T1b,$N0,$nd,$T1b
+       fmadd   $T2a,$N1,$nc,$T2a
+       fmadd   $T2b,$N1,$nd,$T2b
+       fmadd   $T3a,$N2,$nc,$T3a
+       fmadd   $T3b,$N2,$nd,$T3b
+       fmadd   $dota,$N3,$nc,$dota
+       fmadd   $dotb,$N3,$nd,$dotb
+
+       fctid   $T0a,$T0a
+       fctid   $T0b,$T0b
+       fctid   $T1a,$T1a
+       fctid   $T1b,$T1b
+       fctid   $T2a,$T2a
+       fctid   $T2b,$T2b
+       fctid   $T3a,$T3a
+       fctid   $T3b,$T3b
+
+       stfd    $T0a,`$FRAME+0`($sp)
+       stfd    $T0b,`$FRAME+8`($sp)
+       stfd    $T1a,`$FRAME+16`($sp)
+       stfd    $T1b,`$FRAME+24`($sp)
+       stfd    $T2a,`$FRAME+32`($sp)
+       stfd    $T2b,`$FRAME+40`($sp)
+       stfd    $T3a,`$FRAME+48`($sp)
+       stfd    $T3b,`$FRAME+56`($sp)
+\f
+.align 5
+Linner:
+       fmul    $T1a,$A1,$ba
+       fmul    $T1b,$A1,$bb
+       fmul    $T2a,$A2,$ba
+       fmul    $T2b,$A2,$bb
+       lfd     $N0,40($nap_d)          ; load n[j] in double format
+       lfd     $N1,48($nap_d)
+       fmul    $T3a,$A3,$ba
+       fmul    $T3b,$A3,$bb
+       fmadd   $T0a,$A0,$ba,$dota
+       fmadd   $T0b,$A0,$bb,$dotb
+       lfd     $N2,56($nap_d)          ; load n[j+1] in double format
+       lfdu    $N3,64($nap_d)
+
+       fmadd   $T1a,$A0,$bc,$T1a
+       fmadd   $T1b,$A0,$bd,$T1b
+       fmadd   $T2a,$A1,$bc,$T2a
+       fmadd   $T2b,$A1,$bd,$T2b
+        lfd    $A0,8($nap_d)           ; load a[j] in double format
+        lfd    $A1,16($nap_d)
+       fmadd   $T3a,$A2,$bc,$T3a
+       fmadd   $T3b,$A2,$bd,$T3b
+       fmul    $dota,$A3,$bc
+       fmul    $dotb,$A3,$bd
+        lfd    $A2,24($nap_d)          ; load a[j+1] in double format
+        lfd    $A3,32($nap_d)
+
+       fmadd   $T1a,$N1,$na,$T1a
+       fmadd   $T1b,$N1,$nb,$T1b
+        ld     $t0,`$FRAME+0`($sp)
+        ld     $t1,`$FRAME+8`($sp)
+       fmadd   $T2a,$N2,$na,$T2a
+       fmadd   $T2b,$N2,$nb,$T2b
+        ld     $t2,`$FRAME+16`($sp)
+        ld     $t3,`$FRAME+24`($sp)
+       fmadd   $T3a,$N3,$na,$T3a
+       fmadd   $T3b,$N3,$nb,$T3b
+        add    $t0,$t0,$carry          ; can not overflow
+        ld     $t4,`$FRAME+32`($sp)
+        ld     $t5,`$FRAME+40`($sp)
+       fmadd   $T0a,$N0,$na,$T0a
+       fmadd   $T0b,$N0,$nb,$T0b
+        srdi   $carry,$t0,16
+        add    $t1,$t1,$carry
+        srdi   $carry,$t1,16
+        ld     $t6,`$FRAME+48`($sp)
+        ld     $t7,`$FRAME+56`($sp)
+
+       fmadd   $T1a,$N0,$nc,$T1a
+       fmadd   $T1b,$N0,$nd,$T1b
+        insrdi $t0,$t1,16,32
+        ld     $t1,8($tp)              ; tp[j]
+       fmadd   $T2a,$N1,$nc,$T2a
+       fmadd   $T2b,$N1,$nd,$T2b
+        add    $t2,$t2,$carry
+       fmadd   $T3a,$N2,$nc,$T3a
+       fmadd   $T3b,$N2,$nd,$T3b
+        srdi   $carry,$t2,16
+        insrdi $t0,$t2,16,16
+       fmadd   $dota,$N3,$nc,$dota
+       fmadd   $dotb,$N3,$nd,$dotb
+        add    $t3,$t3,$carry
+        ldu    $t2,16($tp)             ; tp[j+1]
+        srdi   $carry,$t3,16
+        insrdi $t0,$t3,16,0            ; 0..63 bits
+        add    $t4,$t4,$carry
+
+       fctid   $T0a,$T0a
+       fctid   $T0b,$T0b
+        srdi   $carry,$t4,16
+       fctid   $T1a,$T1a
+       fctid   $T1b,$T1b
+        add    $t5,$t5,$carry
+       fctid   $T2a,$T2a
+       fctid   $T2b,$T2b
+        srdi   $carry,$t5,16
+        insrdi $t4,$t5,16,32
+       fctid   $T3a,$T3a
+       fctid   $T3b,$T3b
+        add    $t6,$t6,$carry
+        srdi   $carry,$t6,16
+        insrdi $t4,$t6,16,16
+
+       stfd    $T0a,`$FRAME+0`($sp)
+       stfd    $T0b,`$FRAME+8`($sp)
+        add    $t7,$t7,$carry
+        addc   $t3,$t0,$t1
+       stfd    $T1a,`$FRAME+16`($sp)
+       stfd    $T1b,`$FRAME+24`($sp)
+        insrdi $t4,$t7,16,0            ; 64..127 bits
+        srdi   $carry,$t7,16           ; upper 33 bits
+       stfd    $T2a,`$FRAME+32`($sp)
+       stfd    $T2b,`$FRAME+40`($sp)
+        adde   $t5,$t4,$t2
+       stfd    $T3a,`$FRAME+48`($sp)
+       stfd    $T3b,`$FRAME+56`($sp)
+        addze  $carry,$carry
+        std    $t3,-16($tp)            ; tp[j-1]
+        std    $t5,-8($tp)             ; tp[j]
+       bdnz-   Linner
+\f
+       fctid   $dota,$dota
+       fctid   $dotb,$dotb
+       ld      $t0,`$FRAME+0`($sp)
+       ld      $t1,`$FRAME+8`($sp)
+       ld      $t2,`$FRAME+16`($sp)
+       ld      $t3,`$FRAME+24`($sp)
+       ld      $t4,`$FRAME+32`($sp)
+       ld      $t5,`$FRAME+40`($sp)
+       ld      $t6,`$FRAME+48`($sp)
+       ld      $t7,`$FRAME+56`($sp)
+       stfd    $dota,`$FRAME+64`($sp)
+       stfd    $dotb,`$FRAME+72`($sp)
+
+       add     $t0,$t0,$carry          ; can not overflow
+       srdi    $carry,$t0,16
+       add     $t1,$t1,$carry
+       srdi    $carry,$t1,16
+       insrdi  $t0,$t1,16,32
+       add     $t2,$t2,$carry
+       ld      $t1,8($tp)              ; tp[j]
+       srdi    $carry,$t2,16
+       insrdi  $t0,$t2,16,16
+       add     $t3,$t3,$carry
+       ldu     $t2,16($tp)             ; tp[j+1]
+       srdi    $carry,$t3,16
+       insrdi  $t0,$t3,16,0            ; 0..63 bits
+       add     $t4,$t4,$carry
+       srdi    $carry,$t4,16
+       add     $t5,$t5,$carry
+       srdi    $carry,$t5,16
+       insrdi  $t4,$t5,16,32
+       add     $t6,$t6,$carry
+       srdi    $carry,$t6,16
+       insrdi  $t4,$t6,16,16
+       add     $t7,$t7,$carry
+       insrdi  $t4,$t7,16,0            ; 64..127 bits
+       srdi    $carry,$t7,16           ; upper 33 bits
+       ld      $t6,`$FRAME+64`($sp)
+       ld      $t7,`$FRAME+72`($sp)
+
+       addc    $t3,$t0,$t1
+       adde    $t5,$t4,$t2
+       addze   $carry,$carry
+
+       std     $t3,-16($tp)            ; tp[j-1]
+       std     $t5,-8($tp)             ; tp[j]
+
+       add     $carry,$carry,$ovf      ; comsume upmost overflow
+       add     $t6,$t6,$carry          ; can not overflow
+       srdi    $carry,$t6,16
+       add     $t7,$t7,$carry
+       insrdi  $t6,$t7,48,0
+       srdi    $ovf,$t7,48
+       std     $t6,0($tp)              ; tp[num-1]
+
+       slwi    $t7,$num,2
+       addi    $i,$i,8
+       subf    $nap_d,$t7,$nap_d       ; rewind pointer
+       cmpw    $i,$num
+       blt-    Louter
+\f
+       subf    $np,$num,$np    ; rewind np
+       addi    $j,$j,1         ; restore counter
+       subfc   $i,$i,$i        ; j=0 and "clear" XER[CA]
+       addi    $tp,$sp,`$FRAME+$TRANSFER+8`
+       addi    $t4,$sp,`$FRAME+$TRANSFER+16`
+       addi    $t5,$np,8
+       addi    $t6,$rp,8
+       mtctr   $j
+
+.align 4
+Lsub:  ldx     $t0,$tp,$i
+       ldx     $t1,$np,$i
+       ldx     $t2,$t4,$i
+       ldx     $t3,$t5,$i
+       subfe   $t0,$t1,$t0     ; tp[j]-np[j]
+       subfe   $t2,$t3,$t2     ; tp[j+1]-np[j+1]
+       stdx    $t0,$rp,$i
+       stdx    $t2,$t6,$i
+       addi    $i,$i,16
+       bdnz-   Lsub
+
+       li      $i,0
+       subfe   $ovf,$i,$ovf    ; handle upmost overflow bit
+       and     $ap,$tp,$ovf
+       andc    $np,$rp,$ovf
+       or      $ap,$ap,$np     ; ap=borrow?tp:rp
+       addi    $t7,$ap,8
+       mtctr   $j
+
+.align 4
+Lcopy:                         ; copy or in-place refresh
+       ldx     $t0,$ap,$i
+       ldx     $t1,$t7,$i
+       std     $i,8($nap_d)    ; zap nap_d
+       std     $i,16($nap_d)
+       std     $i,24($nap_d)
+       std     $i,32($nap_d)
+       std     $i,40($nap_d)
+       std     $i,48($nap_d)
+       std     $i,56($nap_d)
+       stdu    $i,64($nap_d)
+       stdx    $t0,$rp,$i
+       stdx    $t1,$t6,$i
+       stdx    $i,$tp,$i       ; zap tp at once
+       stdx    $i,$t4,$i
+       addi    $i,$i,16
+       bdnz-   Lcopy
+\f
+       $POP    r14,`2*$SIZE_T`($sp)
+       $POP    r15,`3*$SIZE_T`($sp)
+       $POP    r16,`4*$SIZE_T`($sp)
+       $POP    r17,`5*$SIZE_T`($sp)
+       $POP    r18,`6*$SIZE_T`($sp)
+       $POP    r19,`7*$SIZE_T`($sp)
+       $POP    r20,`8*$SIZE_T`($sp)
+       $POP    r21,`9*$SIZE_T`($sp)
+       $POP    r22,`10*$SIZE_T`($sp)
+       $POP    r23,`11*$SIZE_T`($sp)
+       lfd     f14,`12*$SIZE_T+0`($sp)
+       lfd     f15,`12*$SIZE_T+8`($sp)
+       lfd     f16,`12*$SIZE_T+16`($sp)
+       lfd     f17,`12*$SIZE_T+24`($sp)
+       lfd     f18,`12*$SIZE_T+32`($sp)
+       lfd     f19,`12*$SIZE_T+40`($sp)
+       lfd     f20,`12*$SIZE_T+48`($sp)
+       lfd     f21,`12*$SIZE_T+56`($sp)
+       lfd     f22,`12*$SIZE_T+64`($sp)
+       lfd     f23,`12*$SIZE_T+72`($sp)
+       lfd     f24,`12*$SIZE_T+80`($sp)
+       lfd     f25,`12*$SIZE_T+88`($sp)
+       $POP    $sp,0($sp)
+       li      r3,1    ; signal "handled"
+       blr
+       .long   0
+.asciz  "Montgomery Multiplication for PPC64, CRYPTOGAMS by <appro\@fy.chalmers.se>"
+___
+
+$code =~ s/\`([^\`]*)\`/eval $1/gem;
+print $code;
+close STDOUT;
diff --git a/deps/openssl/openssl/crypto/bn/asm/s390x-mont.pl b/deps/openssl/openssl/crypto/bn/asm/s390x-mont.pl
new file mode 100644 (file)
index 0000000..f61246f
--- /dev/null
@@ -0,0 +1,225 @@
+#!/usr/bin/env perl
+
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+
+# April 2007.
+#
+# Performance improvement over vanilla C code varies from 85% to 45%
+# depending on key length and benchmark. Unfortunately in this context
+# these are not very impressive results [for code that utilizes "wide"
+# 64x64=128-bit multiplication, which is not commonly available to C
+# programmers], at least hand-coded bn_asm.c replacement is known to
+# provide 30-40% better results for longest keys. Well, on a second
+# thought it's not very surprising, because z-CPUs are single-issue
+# and _strictly_ in-order execution, while bn_mul_mont is more or less
+# dependent on CPU ability to pipe-line instructions and have several
+# of them "in-flight" at the same time. I mean while other methods,
+# for example Karatsuba, aim to minimize amount of multiplications at
+# the cost of other operations increase, bn_mul_mont aim to neatly
+# "overlap" multiplications and the other operations [and on most
+# platforms even minimize the amount of the other operations, in
+# particular references to memory]. But it's possible to improve this
+# module performance by implementing dedicated squaring code-path and
+# possibly by unrolling loops...
+
+# January 2009.
+#
+# Reschedule to minimize/avoid Address Generation Interlock hazard,
+# make inner loops counter-based.
+
+$mn0="%r0";
+$num="%r1";
+
+# int bn_mul_mont(
+$rp="%r2";             # BN_ULONG *rp,
+$ap="%r3";             # const BN_ULONG *ap,
+$bp="%r4";             # const BN_ULONG *bp,
+$np="%r5";             # const BN_ULONG *np,
+$n0="%r6";             # const BN_ULONG *n0,
+#$num="160(%r15)"      # int num);
+
+$bi="%r2";     # zaps rp
+$j="%r7";
+
+$ahi="%r8";
+$alo="%r9";
+$nhi="%r10";
+$nlo="%r11";
+$AHI="%r12";
+$NHI="%r13";
+$count="%r14";
+$sp="%r15";
+
+$code.=<<___;
+.text
+.globl bn_mul_mont
+.type  bn_mul_mont,\@function
+bn_mul_mont:
+       lgf     $num,164($sp)   # pull $num
+       sla     $num,3          # $num to enumerate bytes
+       la      $bp,0($num,$bp)
+
+       stg     %r2,16($sp)
+
+       cghi    $num,16         #
+       lghi    %r2,0           #
+       blr     %r14            # if($num<16) return 0;
+       cghi    $num,96         #
+       bhr     %r14            # if($num>96) return 0;
+
+       stmg    %r3,%r15,24($sp)
+
+       lghi    $rp,-160-8      # leave room for carry bit
+       lcgr    $j,$num         # -$num
+       lgr     %r0,$sp
+       la      $rp,0($rp,$sp)
+       la      $sp,0($j,$rp)   # alloca
+       stg     %r0,0($sp)      # back chain
+
+       sra     $num,3          # restore $num
+       la      $bp,0($j,$bp)   # restore $bp
+       ahi     $num,-1         # adjust $num for inner loop
+       lg      $n0,0($n0)      # pull n0
+
+       lg      $bi,0($bp)
+       lg      $alo,0($ap)
+       mlgr    $ahi,$bi        # ap[0]*bp[0]
+       lgr     $AHI,$ahi
+
+       lgr     $mn0,$alo       # "tp[0]"*n0
+       msgr    $mn0,$n0
+
+       lg      $nlo,0($np)     #
+       mlgr    $nhi,$mn0       # np[0]*m1
+       algr    $nlo,$alo       # +="tp[0]"
+       lghi    $NHI,0
+       alcgr   $NHI,$nhi
+
+       la      $j,8(%r0)       # j=1
+       lr      $count,$num
+
+.align 16
+.L1st:
+       lg      $alo,0($j,$ap)
+       mlgr    $ahi,$bi        # ap[j]*bp[0]
+       algr    $alo,$AHI
+       lghi    $AHI,0
+       alcgr   $AHI,$ahi
+
+       lg      $nlo,0($j,$np)
+       mlgr    $nhi,$mn0       # np[j]*m1
+       algr    $nlo,$NHI
+       lghi    $NHI,0
+       alcgr   $nhi,$NHI       # +="tp[j]"
+       algr    $nlo,$alo
+       alcgr   $NHI,$nhi
+
+       stg     $nlo,160-8($j,$sp)      # tp[j-1]=
+       la      $j,8($j)        # j++
+       brct    $count,.L1st
+
+       algr    $NHI,$AHI
+       lghi    $AHI,0
+       alcgr   $AHI,$AHI       # upmost overflow bit
+       stg     $NHI,160-8($j,$sp)
+       stg     $AHI,160($j,$sp)
+       la      $bp,8($bp)      # bp++
+
+.Louter:
+       lg      $bi,0($bp)      # bp[i]
+       lg      $alo,0($ap)
+       mlgr    $ahi,$bi        # ap[0]*bp[i]
+       alg     $alo,160($sp)   # +=tp[0]
+       lghi    $AHI,0
+       alcgr   $AHI,$ahi
+
+       lgr     $mn0,$alo
+       msgr    $mn0,$n0        # tp[0]*n0
+
+       lg      $nlo,0($np)     # np[0]
+       mlgr    $nhi,$mn0       # np[0]*m1
+       algr    $nlo,$alo       # +="tp[0]"
+       lghi    $NHI,0
+       alcgr   $NHI,$nhi
+
+       la      $j,8(%r0)       # j=1
+       lr      $count,$num
+
+.align 16
+.Linner:
+       lg      $alo,0($j,$ap)
+       mlgr    $ahi,$bi        # ap[j]*bp[i]
+       algr    $alo,$AHI
+       lghi    $AHI,0
+       alcgr   $ahi,$AHI
+       alg     $alo,160($j,$sp)# +=tp[j]
+       alcgr   $AHI,$ahi
+
+       lg      $nlo,0($j,$np)
+       mlgr    $nhi,$mn0       # np[j]*m1
+       algr    $nlo,$NHI
+       lghi    $NHI,0
+       alcgr   $nhi,$NHI
+       algr    $nlo,$alo       # +="tp[j]"
+       alcgr   $NHI,$nhi
+
+       stg     $nlo,160-8($j,$sp)      # tp[j-1]=
+       la      $j,8($j)        # j++
+       brct    $count,.Linner
+
+       algr    $NHI,$AHI
+       lghi    $AHI,0
+       alcgr   $AHI,$AHI
+       alg     $NHI,160($j,$sp)# accumulate previous upmost overflow bit
+       lghi    $ahi,0
+       alcgr   $AHI,$ahi       # new upmost overflow bit
+       stg     $NHI,160-8($j,$sp)
+       stg     $AHI,160($j,$sp)
+
+       la      $bp,8($bp)      # bp++
+       clg     $bp,160+8+32($j,$sp)    # compare to &bp[num]
+       jne     .Louter
+
+       lg      $rp,160+8+16($j,$sp)    # reincarnate rp
+       la      $ap,160($sp)
+       ahi     $num,1          # restore $num, incidentally clears "borrow"
+
+       la      $j,0(%r0)
+       lr      $count,$num
+.Lsub: lg      $alo,0($j,$ap)
+       slbg    $alo,0($j,$np)
+       stg     $alo,0($j,$rp)
+       la      $j,8($j)
+       brct    $count,.Lsub
+       lghi    $ahi,0
+       slbgr   $AHI,$ahi       # handle upmost carry
+
+       ngr     $ap,$AHI
+       lghi    $np,-1
+       xgr     $np,$AHI
+       ngr     $np,$rp
+       ogr     $ap,$np         # ap=borrow?tp:rp
+
+       la      $j,0(%r0)
+       lgr     $count,$num
+.Lcopy:        lg      $alo,0($j,$ap)  # copy or in-place refresh
+       stg     $j,160($j,$sp)  # zap tp
+       stg     $alo,0($j,$rp)
+       la      $j,8($j)
+       brct    $count,.Lcopy
+
+       la      %r1,160+8+48($j,$sp)
+       lmg     %r6,%r15,0(%r1)
+       lghi    %r2,1           # signal "processed"
+       br      %r14
+.size  bn_mul_mont,.-bn_mul_mont
+.string        "Montgomery Multiplication for s390x, CRYPTOGAMS by <appro\@openssl.org>"
+___
+
+print $code;
+close STDOUT;
diff --git a/deps/openssl/openssl/crypto/bn/asm/s390x.S b/deps/openssl/openssl/crypto/bn/asm/s390x.S
new file mode 100644 (file)
index 0000000..43fcb79
--- /dev/null
@@ -0,0 +1,678 @@
+.ident "s390x.S, version 1.1"
+// ====================================================================
+// Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+// project.
+//
+// Rights for redistribution and usage in source and binary forms are
+// granted according to the OpenSSL license. Warranty of any kind is
+// disclaimed.
+// ====================================================================
+
+.text
+
+#define zero   %r0
+
+// BN_ULONG bn_mul_add_words(BN_ULONG *r2,BN_ULONG *r3,int r4,BN_ULONG r5);
+.globl bn_mul_add_words
+.type  bn_mul_add_words,@function
+.align 4
+bn_mul_add_words:
+       lghi    zero,0          // zero = 0
+       la      %r1,0(%r2)      // put rp aside
+       lghi    %r2,0           // i=0;
+       ltgfr   %r4,%r4
+       bler    %r14            // if (len<=0) return 0;
+
+       stmg    %r6,%r10,48(%r15)
+       lghi    %r10,3
+       lghi    %r8,0           // carry = 0
+       nr      %r10,%r4        // len%4
+       sra     %r4,2           // cnt=len/4
+       jz      .Loop1_madd     // carry is incidentally cleared if branch taken
+       algr    zero,zero       // clear carry
+
+.Loop4_madd:
+       lg      %r7,0(%r2,%r3)  // ap[i]
+       mlgr    %r6,%r5         // *=w
+       alcgr   %r7,%r8         // +=carry
+       alcgr   %r6,zero
+       alg     %r7,0(%r2,%r1)  // +=rp[i]
+       stg     %r7,0(%r2,%r1)  // rp[i]=
+
+       lg      %r9,8(%r2,%r3)
+       mlgr    %r8,%r5
+       alcgr   %r9,%r6
+       alcgr   %r8,zero
+       alg     %r9,8(%r2,%r1)
+       stg     %r9,8(%r2,%r1)
+
+       lg      %r7,16(%r2,%r3)
+       mlgr    %r6,%r5
+       alcgr   %r7,%r8
+       alcgr   %r6,zero
+       alg     %r7,16(%r2,%r1)
+       stg     %r7,16(%r2,%r1)
+
+       lg      %r9,24(%r2,%r3)
+       mlgr    %r8,%r5
+       alcgr   %r9,%r6
+       alcgr   %r8,zero
+       alg     %r9,24(%r2,%r1)
+       stg     %r9,24(%r2,%r1)
+
+       la      %r2,32(%r2)     // i+=4
+       brct    %r4,.Loop4_madd
+
+       la      %r10,1(%r10)            // see if len%4 is zero ...
+       brct    %r10,.Loop1_madd        // without touching condition code:-)
+
+.Lend_madd:
+       alcgr   %r8,zero        // collect carry bit
+       lgr     %r2,%r8
+       lmg     %r6,%r10,48(%r15)
+       br      %r14
+
+.Loop1_madd:
+       lg      %r7,0(%r2,%r3)  // ap[i]
+       mlgr    %r6,%r5         // *=w
+       alcgr   %r7,%r8         // +=carry
+       alcgr   %r6,zero
+       alg     %r7,0(%r2,%r1)  // +=rp[i]
+       stg     %r7,0(%r2,%r1)  // rp[i]=
+
+       lgr     %r8,%r6
+       la      %r2,8(%r2)      // i++
+       brct    %r10,.Loop1_madd
+
+       j       .Lend_madd
+.size  bn_mul_add_words,.-bn_mul_add_words
+
+// BN_ULONG bn_mul_words(BN_ULONG *r2,BN_ULONG *r3,int r4,BN_ULONG r5);
+.globl bn_mul_words
+.type  bn_mul_words,@function
+.align 4
+bn_mul_words:
+       lghi    zero,0          // zero = 0
+       la      %r1,0(%r2)      // put rp aside
+       lghi    %r2,0           // i=0;
+       ltgfr   %r4,%r4
+       bler    %r14            // if (len<=0) return 0;
+
+       stmg    %r6,%r10,48(%r15)
+       lghi    %r10,3
+       lghi    %r8,0           // carry = 0
+       nr      %r10,%r4        // len%4
+       sra     %r4,2           // cnt=len/4
+       jz      .Loop1_mul      // carry is incidentally cleared if branch taken
+       algr    zero,zero       // clear carry
+
+.Loop4_mul:
+       lg      %r7,0(%r2,%r3)  // ap[i]
+       mlgr    %r6,%r5         // *=w
+       alcgr   %r7,%r8         // +=carry
+       stg     %r7,0(%r2,%r1)  // rp[i]=
+
+       lg      %r9,8(%r2,%r3)
+       mlgr    %r8,%r5
+       alcgr   %r9,%r6
+       stg     %r9,8(%r2,%r1)
+
+       lg      %r7,16(%r2,%r3)
+       mlgr    %r6,%r5
+       alcgr   %r7,%r8
+       stg     %r7,16(%r2,%r1)
+
+       lg      %r9,24(%r2,%r3)
+       mlgr    %r8,%r5
+       alcgr   %r9,%r6
+       stg     %r9,24(%r2,%r1)
+
+       la      %r2,32(%r2)     // i+=4
+       brct    %r4,.Loop4_mul
+
+       la      %r10,1(%r10)            // see if len%4 is zero ...
+       brct    %r10,.Loop1_mul         // without touching condition code:-)
+
+.Lend_mul:
+       alcgr   %r8,zero        // collect carry bit
+       lgr     %r2,%r8
+       lmg     %r6,%r10,48(%r15)
+       br      %r14
+
+.Loop1_mul:
+       lg      %r7,0(%r2,%r3)  // ap[i]
+       mlgr    %r6,%r5         // *=w
+       alcgr   %r7,%r8         // +=carry
+       stg     %r7,0(%r2,%r1)  // rp[i]=
+
+       lgr     %r8,%r6
+       la      %r2,8(%r2)      // i++
+       brct    %r10,.Loop1_mul
+
+       j       .Lend_mul
+.size  bn_mul_words,.-bn_mul_words
+
+// void bn_sqr_words(BN_ULONG *r2,BN_ULONG *r2,int r4)
+.globl bn_sqr_words
+.type  bn_sqr_words,@function
+.align 4
+bn_sqr_words:
+       ltgfr   %r4,%r4
+       bler    %r14
+
+       stmg    %r6,%r7,48(%r15)
+       srag    %r1,%r4,2       // cnt=len/4
+       jz      .Loop1_sqr
+
+.Loop4_sqr:
+       lg      %r7,0(%r3)
+       mlgr    %r6,%r7
+       stg     %r7,0(%r2)
+       stg     %r6,8(%r2)
+
+       lg      %r7,8(%r3)
+       mlgr    %r6,%r7
+       stg     %r7,16(%r2)
+       stg     %r6,24(%r2)
+
+       lg      %r7,16(%r3)
+       mlgr    %r6,%r7
+       stg     %r7,32(%r2)
+       stg     %r6,40(%r2)
+
+       lg      %r7,24(%r3)
+       mlgr    %r6,%r7
+       stg     %r7,48(%r2)
+       stg     %r6,56(%r2)
+
+       la      %r3,32(%r3)
+       la      %r2,64(%r2)
+       brct    %r1,.Loop4_sqr
+
+       lghi    %r1,3
+       nr      %r4,%r1         // cnt=len%4
+       jz      .Lend_sqr
+
+.Loop1_sqr:
+       lg      %r7,0(%r3)
+       mlgr    %r6,%r7
+       stg     %r7,0(%r2)
+       stg     %r6,8(%r2)
+
+       la      %r3,8(%r3)
+       la      %r2,16(%r2)
+       brct    %r4,.Loop1_sqr
+
+.Lend_sqr:
+       lmg     %r6,%r7,48(%r15)
+       br      %r14
+.size  bn_sqr_words,.-bn_sqr_words
+
+// BN_ULONG bn_div_words(BN_ULONG h,BN_ULONG l,BN_ULONG d);
+.globl bn_div_words
+.type  bn_div_words,@function
+.align 4
+bn_div_words:
+       dlgr    %r2,%r4
+       lgr     %r2,%r3
+       br      %r14
+.size  bn_div_words,.-bn_div_words
+
+// BN_ULONG bn_add_words(BN_ULONG *r2,BN_ULONG *r3,BN_ULONG *r4,int r5);
+.globl bn_add_words
+.type  bn_add_words,@function
+.align 4
+bn_add_words:
+       la      %r1,0(%r2)      // put rp aside
+       lghi    %r2,0           // i=0
+       ltgfr   %r5,%r5
+       bler    %r14            // if (len<=0) return 0;
+
+       stg     %r6,48(%r15)
+       lghi    %r6,3
+       nr      %r6,%r5         // len%4
+       sra     %r5,2           // len/4, use sra because it sets condition code
+       jz      .Loop1_add      // carry is incidentally cleared if branch taken
+       algr    %r2,%r2         // clear carry
+
+.Loop4_add:
+       lg      %r0,0(%r2,%r3)
+       alcg    %r0,0(%r2,%r4)
+       stg     %r0,0(%r2,%r1)
+       lg      %r0,8(%r2,%r3)
+       alcg    %r0,8(%r2,%r4)
+       stg     %r0,8(%r2,%r1)
+       lg      %r0,16(%r2,%r3)
+       alcg    %r0,16(%r2,%r4)
+       stg     %r0,16(%r2,%r1)
+       lg      %r0,24(%r2,%r3)
+       alcg    %r0,24(%r2,%r4)
+       stg     %r0,24(%r2,%r1)
+
+       la      %r2,32(%r2)     // i+=4
+       brct    %r5,.Loop4_add
+
+       la      %r6,1(%r6)      // see if len%4 is zero ...
+       brct    %r6,.Loop1_add  // without touching condition code:-)
+
+.Lexit_add:
+       lghi    %r2,0
+       alcgr   %r2,%r2
+       lg      %r6,48(%r15)
+       br      %r14
+
+.Loop1_add:
+       lg      %r0,0(%r2,%r3)
+       alcg    %r0,0(%r2,%r4)
+       stg     %r0,0(%r2,%r1)
+
+       la      %r2,8(%r2)      // i++
+       brct    %r6,.Loop1_add
+
+       j       .Lexit_add
+.size  bn_add_words,.-bn_add_words
+
+// BN_ULONG bn_sub_words(BN_ULONG *r2,BN_ULONG *r3,BN_ULONG *r4,int r5);
+.globl bn_sub_words
+.type  bn_sub_words,@function
+.align 4
+bn_sub_words:
+       la      %r1,0(%r2)      // put rp aside
+       lghi    %r2,0           // i=0
+       ltgfr   %r5,%r5
+       bler    %r14            // if (len<=0) return 0;
+
+       stg     %r6,48(%r15)
+       lghi    %r6,3
+       nr      %r6,%r5         // len%4
+       sra     %r5,2           // len/4, use sra because it sets condition code
+       jnz     .Loop4_sub      // borrow is incidentally cleared if branch taken
+       slgr    %r2,%r2         // clear borrow
+
+.Loop1_sub:
+       lg      %r0,0(%r2,%r3)
+       slbg    %r0,0(%r2,%r4)
+       stg     %r0,0(%r2,%r1)
+
+       la      %r2,8(%r2)      // i++
+       brct    %r6,.Loop1_sub
+       j       .Lexit_sub
+
+.Loop4_sub:
+       lg      %r0,0(%r2,%r3)
+       slbg    %r0,0(%r2,%r4)
+       stg     %r0,0(%r2,%r1)
+       lg      %r0,8(%r2,%r3)
+       slbg    %r0,8(%r2,%r4)
+       stg     %r0,8(%r2,%r1)
+       lg      %r0,16(%r2,%r3)
+       slbg    %r0,16(%r2,%r4)
+       stg     %r0,16(%r2,%r1)
+       lg      %r0,24(%r2,%r3)
+       slbg    %r0,24(%r2,%r4)
+       stg     %r0,24(%r2,%r1)
+
+       la      %r2,32(%r2)     // i+=4
+       brct    %r5,.Loop4_sub
+
+       la      %r6,1(%r6)      // see if len%4 is zero ...
+       brct    %r6,.Loop1_sub  // without touching condition code:-)
+
+.Lexit_sub:
+       lghi    %r2,0
+       slbgr   %r2,%r2
+       lcgr    %r2,%r2
+       lg      %r6,48(%r15)
+       br      %r14
+.size  bn_sub_words,.-bn_sub_words
+
+#define c1     %r1
+#define c2     %r5
+#define c3     %r8
+
+#define mul_add_c(ai,bi,c1,c2,c3)      \
+       lg      %r7,ai*8(%r3);          \
+       mlg     %r6,bi*8(%r4);          \
+       algr    c1,%r7;                 \
+       alcgr   c2,%r6;                 \
+       alcgr   c3,zero
+
+// void bn_mul_comba8(BN_ULONG *r2,BN_ULONG *r3,BN_ULONG *r4);
+.globl bn_mul_comba8
+.type  bn_mul_comba8,@function
+.align 4
+bn_mul_comba8:
+       stmg    %r6,%r8,48(%r15)
+
+       lghi    c1,0
+       lghi    c2,0
+       lghi    c3,0
+       lghi    zero,0
+
+       mul_add_c(0,0,c1,c2,c3);
+       stg     c1,0*8(%r2)
+       lghi    c1,0
+
+       mul_add_c(0,1,c2,c3,c1);
+       mul_add_c(1,0,c2,c3,c1);
+       stg     c2,1*8(%r2)
+       lghi    c2,0
+
+       mul_add_c(2,0,c3,c1,c2);
+       mul_add_c(1,1,c3,c1,c2);
+       mul_add_c(0,2,c3,c1,c2);
+       stg     c3,2*8(%r2)
+       lghi    c3,0
+
+       mul_add_c(0,3,c1,c2,c3);
+       mul_add_c(1,2,c1,c2,c3);
+       mul_add_c(2,1,c1,c2,c3);
+       mul_add_c(3,0,c1,c2,c3);
+       stg     c1,3*8(%r2)
+       lghi    c1,0
+
+       mul_add_c(4,0,c2,c3,c1);
+       mul_add_c(3,1,c2,c3,c1);
+       mul_add_c(2,2,c2,c3,c1);
+       mul_add_c(1,3,c2,c3,c1);
+       mul_add_c(0,4,c2,c3,c1);
+       stg     c2,4*8(%r2)
+       lghi    c2,0
+
+       mul_add_c(0,5,c3,c1,c2);
+       mul_add_c(1,4,c3,c1,c2);
+       mul_add_c(2,3,c3,c1,c2);
+       mul_add_c(3,2,c3,c1,c2);
+       mul_add_c(4,1,c3,c1,c2);
+       mul_add_c(5,0,c3,c1,c2);
+       stg     c3,5*8(%r2)
+       lghi    c3,0
+
+       mul_add_c(6,0,c1,c2,c3);
+       mul_add_c(5,1,c1,c2,c3);
+       mul_add_c(4,2,c1,c2,c3);
+       mul_add_c(3,3,c1,c2,c3);
+       mul_add_c(2,4,c1,c2,c3);
+       mul_add_c(1,5,c1,c2,c3);
+       mul_add_c(0,6,c1,c2,c3);
+       stg     c1,6*8(%r2)
+       lghi    c1,0
+
+       mul_add_c(0,7,c2,c3,c1);
+       mul_add_c(1,6,c2,c3,c1);
+       mul_add_c(2,5,c2,c3,c1);
+       mul_add_c(3,4,c2,c3,c1);
+       mul_add_c(4,3,c2,c3,c1);
+       mul_add_c(5,2,c2,c3,c1);
+       mul_add_c(6,1,c2,c3,c1);
+       mul_add_c(7,0,c2,c3,c1);
+       stg     c2,7*8(%r2)
+       lghi    c2,0
+
+       mul_add_c(7,1,c3,c1,c2);
+       mul_add_c(6,2,c3,c1,c2);
+       mul_add_c(5,3,c3,c1,c2);
+       mul_add_c(4,4,c3,c1,c2);
+       mul_add_c(3,5,c3,c1,c2);
+       mul_add_c(2,6,c3,c1,c2);
+       mul_add_c(1,7,c3,c1,c2);
+       stg     c3,8*8(%r2)
+       lghi    c3,0
+
+       mul_add_c(2,7,c1,c2,c3);
+       mul_add_c(3,6,c1,c2,c3);
+       mul_add_c(4,5,c1,c2,c3);
+       mul_add_c(5,4,c1,c2,c3);
+       mul_add_c(6,3,c1,c2,c3);
+       mul_add_c(7,2,c1,c2,c3);
+       stg     c1,9*8(%r2)
+       lghi    c1,0
+
+       mul_add_c(7,3,c2,c3,c1);
+       mul_add_c(6,4,c2,c3,c1);
+       mul_add_c(5,5,c2,c3,c1);
+       mul_add_c(4,6,c2,c3,c1);
+       mul_add_c(3,7,c2,c3,c1);
+       stg     c2,10*8(%r2)
+       lghi    c2,0
+
+       mul_add_c(4,7,c3,c1,c2);
+       mul_add_c(5,6,c3,c1,c2);
+       mul_add_c(6,5,c3,c1,c2);
+       mul_add_c(7,4,c3,c1,c2);
+       stg     c3,11*8(%r2)
+       lghi    c3,0
+
+       mul_add_c(7,5,c1,c2,c3);
+       mul_add_c(6,6,c1,c2,c3);
+       mul_add_c(5,7,c1,c2,c3);
+       stg     c1,12*8(%r2)
+       lghi    c1,0
+
+
+       mul_add_c(6,7,c2,c3,c1);
+       mul_add_c(7,6,c2,c3,c1);
+       stg     c2,13*8(%r2)
+       lghi    c2,0
+
+       mul_add_c(7,7,c3,c1,c2);
+       stg     c3,14*8(%r2)
+       stg     c1,15*8(%r2)
+
+       lmg     %r6,%r8,48(%r15)
+       br      %r14
+.size  bn_mul_comba8,.-bn_mul_comba8
+
+// void bn_mul_comba4(BN_ULONG *r2,BN_ULONG *r3,BN_ULONG *r4);
+.globl bn_mul_comba4
+.type  bn_mul_comba4,@function
+.align 4
+bn_mul_comba4:
+       stmg    %r6,%r8,48(%r15)
+
+       lghi    c1,0
+       lghi    c2,0
+       lghi    c3,0
+       lghi    zero,0
+
+       mul_add_c(0,0,c1,c2,c3);
+       stg     c1,0*8(%r3)
+       lghi    c1,0
+
+       mul_add_c(0,1,c2,c3,c1);
+       mul_add_c(1,0,c2,c3,c1);
+       stg     c2,1*8(%r2)
+       lghi    c2,0
+
+       mul_add_c(2,0,c3,c1,c2);
+       mul_add_c(1,1,c3,c1,c2);
+       mul_add_c(0,2,c3,c1,c2);
+       stg     c3,2*8(%r2)
+       lghi    c3,0
+
+       mul_add_c(0,3,c1,c2,c3);
+       mul_add_c(1,2,c1,c2,c3);
+       mul_add_c(2,1,c1,c2,c3);
+       mul_add_c(3,0,c1,c2,c3);
+       stg     c1,3*8(%r2)
+       lghi    c1,0
+
+       mul_add_c(3,1,c2,c3,c1);
+       mul_add_c(2,2,c2,c3,c1);
+       mul_add_c(1,3,c2,c3,c1);
+       stg     c2,4*8(%r2)
+       lghi    c2,0
+
+       mul_add_c(2,3,c3,c1,c2);
+       mul_add_c(3,2,c3,c1,c2);
+       stg     c3,5*8(%r2)
+       lghi    c3,0
+
+       mul_add_c(3,3,c1,c2,c3);
+       stg     c1,6*8(%r2)
+       stg     c2,7*8(%r2)
+
+       stmg    %r6,%r8,48(%r15)
+       br      %r14
+.size  bn_mul_comba4,.-bn_mul_comba4
+
+#define sqr_add_c(ai,c1,c2,c3)         \
+       lg      %r7,ai*8(%r3);          \
+       mlgr    %r6,%r7;                \
+       algr    c1,%r7;                 \
+       alcgr   c2,%r6;                 \
+       alcgr   c3,zero
+
+#define sqr_add_c2(ai,aj,c1,c2,c3)     \
+       lg      %r7,ai*8(%r3);          \
+       mlg     %r6,aj*8(%r3);          \
+       algr    c1,%r7;                 \
+       alcgr   c2,%r6;                 \
+       alcgr   c3,zero;                \
+       algr    c1,%r7;                 \
+       alcgr   c2,%r6;                 \
+       alcgr   c3,zero
+
+// void bn_sqr_comba8(BN_ULONG *r2,BN_ULONG *r3);
+.globl bn_sqr_comba8
+.type  bn_sqr_comba8,@function
+.align 4
+bn_sqr_comba8:
+       stmg    %r6,%r8,48(%r15)
+
+       lghi    c1,0
+       lghi    c2,0
+       lghi    c3,0
+       lghi    zero,0
+
+       sqr_add_c(0,c1,c2,c3);
+       stg     c1,0*8(%r2)
+       lghi    c1,0
+
+       sqr_add_c2(1,0,c2,c3,c1);
+       stg     c2,1*8(%r2)
+       lghi    c2,0
+
+       sqr_add_c(1,c3,c1,c2);
+       sqr_add_c2(2,0,c3,c1,c2);
+       stg     c3,2*8(%r2)
+       lghi    c3,0
+
+       sqr_add_c2(3,0,c1,c2,c3);
+       sqr_add_c2(2,1,c1,c2,c3);
+       stg     c1,3*8(%r2)
+       lghi    c1,0
+
+       sqr_add_c(2,c2,c3,c1);
+       sqr_add_c2(3,1,c2,c3,c1);
+       sqr_add_c2(4,0,c2,c3,c1);
+       stg     c2,4*8(%r2)
+       lghi    c2,0
+
+       sqr_add_c2(5,0,c3,c1,c2);
+       sqr_add_c2(4,1,c3,c1,c2);
+       sqr_add_c2(3,2,c3,c1,c2);
+       stg     c3,5*8(%r2)
+       lghi    c3,0
+
+       sqr_add_c(3,c1,c2,c3);
+       sqr_add_c2(4,2,c1,c2,c3);
+       sqr_add_c2(5,1,c1,c2,c3);
+       sqr_add_c2(6,0,c1,c2,c3);
+       stg     c1,6*8(%r2)
+       lghi    c1,0
+
+       sqr_add_c2(7,0,c2,c3,c1);
+       sqr_add_c2(6,1,c2,c3,c1);
+       sqr_add_c2(5,2,c2,c3,c1);
+       sqr_add_c2(4,3,c2,c3,c1);
+       stg     c2,7*8(%r2)
+       lghi    c2,0
+
+       sqr_add_c(4,c3,c1,c2);
+       sqr_add_c2(5,3,c3,c1,c2);
+       sqr_add_c2(6,2,c3,c1,c2);
+       sqr_add_c2(7,1,c3,c1,c2);
+       stg     c3,8*8(%r2)
+       lghi    c3,0
+
+       sqr_add_c2(7,2,c1,c2,c3);
+       sqr_add_c2(6,3,c1,c2,c3);
+       sqr_add_c2(5,4,c1,c2,c3);
+       stg     c1,9*8(%r2)
+       lghi    c1,0
+
+       sqr_add_c(5,c2,c3,c1);
+       sqr_add_c2(6,4,c2,c3,c1);
+       sqr_add_c2(7,3,c2,c3,c1);
+       stg     c2,10*8(%r2)
+       lghi    c2,0
+
+       sqr_add_c2(7,4,c3,c1,c2);
+       sqr_add_c2(6,5,c3,c1,c2);
+       stg     c3,11*8(%r2)
+       lghi    c3,0
+
+       sqr_add_c(6,c1,c2,c3);
+       sqr_add_c2(7,5,c1,c2,c3);
+       stg     c1,12*8(%r2)
+       lghi    c1,0
+
+       sqr_add_c2(7,6,c2,c3,c1);
+       stg     c2,13*8(%r2)
+       lghi    c2,0
+
+       sqr_add_c(7,c3,c1,c2);
+       stg     c3,14*8(%r2)
+       stg     c1,15*8(%r2)
+
+       lmg     %r6,%r8,48(%r15)
+       br      %r14
+.size  bn_sqr_comba8,.-bn_sqr_comba8
+
+// void bn_sqr_comba4(BN_ULONG *r2,BN_ULONG *r3);
+.globl bn_sqr_comba4
+.type  bn_sqr_comba4,@function
+.align 4
+bn_sqr_comba4:
+       stmg    %r6,%r8,48(%r15)
+
+       lghi    c1,0
+       lghi    c2,0
+       lghi    c3,0
+       lghi    zero,0
+
+       sqr_add_c(0,c1,c2,c3);
+       stg     c1,0*8(%r2)
+       lghi    c1,0
+
+       sqr_add_c2(1,0,c2,c3,c1);
+       stg     c2,1*8(%r2)
+       lghi    c2,0
+
+       sqr_add_c(1,c3,c1,c2);
+       sqr_add_c2(2,0,c3,c1,c2);
+       stg     c3,2*8(%r2)
+       lghi    c3,0
+
+       sqr_add_c2(3,0,c1,c2,c3);
+       sqr_add_c2(2,1,c1,c2,c3);
+       stg     c1,3*8(%r2)
+       lghi    c1,0
+
+       sqr_add_c(2,c2,c3,c1);
+       sqr_add_c2(3,1,c2,c3,c1);
+       stg     c2,4*8(%r2)
+       lghi    c2,0
+
+       sqr_add_c2(3,2,c3,c1,c2);
+       stg     c3,5*8(%r2)
+       lghi    c3,0
+
+       sqr_add_c(3,c1,c2,c3);
+       stg     c1,6*8(%r2)
+       stg     c2,7*8(%r2)
+
+       lmg     %r6,%r8,48(%r15)
+       br      %r14
+.size  bn_sqr_comba4,.-bn_sqr_comba4
index 8c56e2e..63de186 100644 (file)
  *         }
  */
 
+#if defined(__SUNPRO_C) && defined(__sparcv9)
+  /* They've said -xarch=v9 at command line */
+  .register    %g2,#scratch
+  .register    %g3,#scratch
+# define       FRAME_SIZE      -192
+#elif defined(__GNUC__) && defined(__arch64__)
+  /* They've said -m64 at command line */
+  .register    %g2,#scratch
+  .register    %g3,#scratch
+# define       FRAME_SIZE      -192
+#else 
+# define       FRAME_SIZE      -96
+#endif 
 /*
  * GNU assembler can't stand stuw:-(
  */
@@ -619,8 +632,6 @@ bn_sub_words:
  *                                                     Andy.
  */
 
-#define FRAME_SIZE     -96
-
 /*
  * Here is register usage map for *all* routines below.
  */
diff --git a/deps/openssl/openssl/crypto/bn/asm/sparcv9-mont.pl b/deps/openssl/openssl/crypto/bn/asm/sparcv9-mont.pl
new file mode 100644 (file)
index 0000000..b8fb1e8
--- /dev/null
@@ -0,0 +1,606 @@
+#!/usr/bin/env perl
+
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+
+# December 2005
+#
+# Pure SPARCv9/8+ and IALU-only bn_mul_mont implementation. The reasons
+# for undertaken effort are multiple. First of all, UltraSPARC is not
+# the whole SPARCv9 universe and other VIS-free implementations deserve
+# optimized code as much. Secondly, newly introduced UltraSPARC T1,
+# a.k.a. Niagara, has shared FPU and concurrent FPU-intensive pathes,
+# such as sparcv9a-mont, will simply sink it. Yes, T1 is equipped with
+# several integrated RSA/DSA accelerator circuits accessible through
+# kernel driver [only(*)], but having decent user-land software
+# implementation is important too. Finally, reasons like desire to
+# experiment with dedicated squaring procedure. Yes, this module
+# implements one, because it was easiest to draft it in SPARCv9
+# instructions...
+
+# (*)  Engine accessing the driver in question is on my TODO list.
+#      For reference, acceleator is estimated to give 6 to 10 times
+#      improvement on single-threaded RSA sign. It should be noted
+#      that 6-10x improvement coefficient does not actually mean
+#      something extraordinary in terms of absolute [single-threaded]
+#      performance, as SPARCv9 instruction set is by all means least
+#      suitable for high performance crypto among other 64 bit
+#      platforms. 6-10x factor simply places T1 in same performance
+#      domain as say AMD64 and IA-64. Improvement of RSA verify don't
+#      appear impressive at all, but it's the sign operation which is
+#      far more critical/interesting.
+
+# You might notice that inner loops are modulo-scheduled:-) This has
+# essentially negligible impact on UltraSPARC performance, it's
+# Fujitsu SPARC64 V users who should notice and hopefully appreciate
+# the advantage... Currently this module surpasses sparcv9a-mont.pl
+# by ~20% on UltraSPARC-III and later cores, but recall that sparcv9a
+# module still have hidden potential [see TODO list there], which is
+# estimated to be larger than 20%...
+
+# int bn_mul_mont(
+$rp="%i0";     # BN_ULONG *rp,
+$ap="%i1";     # const BN_ULONG *ap,
+$bp="%i2";     # const BN_ULONG *bp,
+$np="%i3";     # const BN_ULONG *np,
+$n0="%i4";     # const BN_ULONG *n0,
+$num="%i5";    # int num);
+
+$bits=32;
+for (@ARGV)    { $bits=64 if (/\-m64/ || /\-xarch\=v9/); }
+if ($bits==64) { $bias=2047; $frame=192; }
+else           { $bias=0;    $frame=128; }
+
+$car0="%o0";
+$car1="%o1";
+$car2="%o2";   # 1 bit
+$acc0="%o3";
+$acc1="%o4";
+$mask="%g1";   # 32 bits, what a waste...
+$tmp0="%g4";
+$tmp1="%g5";
+
+$i="%l0";
+$j="%l1";
+$mul0="%l2";
+$mul1="%l3";
+$tp="%l4";
+$apj="%l5";
+$npj="%l6";
+$tpj="%l7";
+
+$fname="bn_mul_mont_int";
+
+$code=<<___;
+.section       ".text",#alloc,#execinstr
+
+.global        $fname
+.align 32
+$fname:
+       cmp     %o5,4                   ! 128 bits minimum
+       bge,pt  %icc,.Lenter
+       sethi   %hi(0xffffffff),$mask
+       retl
+       clr     %o0
+.align 32
+.Lenter:
+       save    %sp,-$frame,%sp
+       sll     $num,2,$num             ! num*=4
+       or      $mask,%lo(0xffffffff),$mask
+       ld      [$n0],$n0
+       cmp     $ap,$bp
+       and     $num,$mask,$num
+       ld      [$bp],$mul0             ! bp[0]
+       nop
+
+       add     %sp,$bias,%o7           ! real top of stack
+       ld      [$ap],$car0             ! ap[0] ! redundant in squaring context
+       sub     %o7,$num,%o7
+       ld      [$ap+4],$apj            ! ap[1]
+       and     %o7,-1024,%o7
+       ld      [$np],$car1             ! np[0]
+       sub     %o7,$bias,%sp           ! alloca
+       ld      [$np+4],$npj            ! np[1]
+       be,pt   `$bits==32?"%icc":"%xcc"`,.Lbn_sqr_mont
+       mov     12,$j
+
+       mulx    $car0,$mul0,$car0       ! ap[0]*bp[0]
+       mulx    $apj,$mul0,$tmp0        !prologue! ap[1]*bp[0]
+       and     $car0,$mask,$acc0
+       add     %sp,$bias+$frame,$tp
+       ld      [$ap+8],$apj            !prologue!
+
+       mulx    $n0,$acc0,$mul1         ! "t[0]"*n0
+       and     $mul1,$mask,$mul1
+
+       mulx    $car1,$mul1,$car1       ! np[0]*"t[0]"*n0
+       mulx    $npj,$mul1,$acc1        !prologue! np[1]*"t[0]"*n0
+       srlx    $car0,32,$car0
+       add     $acc0,$car1,$car1
+       ld      [$np+8],$npj            !prologue!
+       srlx    $car1,32,$car1
+       mov     $tmp0,$acc0             !prologue!
+
+.L1st:
+       mulx    $apj,$mul0,$tmp0
+       mulx    $npj,$mul1,$tmp1
+       add     $acc0,$car0,$car0
+       ld      [$ap+$j],$apj           ! ap[j]
+       and     $car0,$mask,$acc0
+       add     $acc1,$car1,$car1
+       ld      [$np+$j],$npj           ! np[j]
+       srlx    $car0,32,$car0
+       add     $acc0,$car1,$car1
+       add     $j,4,$j                 ! j++
+       mov     $tmp0,$acc0
+       st      $car1,[$tp]
+       cmp     $j,$num
+       mov     $tmp1,$acc1
+       srlx    $car1,32,$car1
+       bl      %icc,.L1st
+       add     $tp,4,$tp               ! tp++
+!.L1st
+
+       mulx    $apj,$mul0,$tmp0        !epilogue!
+       mulx    $npj,$mul1,$tmp1
+       add     $acc0,$car0,$car0
+       and     $car0,$mask,$acc0
+       add     $acc1,$car1,$car1
+       srlx    $car0,32,$car0
+       add     $acc0,$car1,$car1
+       st      $car1,[$tp]
+       srlx    $car1,32,$car1
+
+       add     $tmp0,$car0,$car0
+       and     $car0,$mask,$acc0
+       add     $tmp1,$car1,$car1
+       srlx    $car0,32,$car0
+       add     $acc0,$car1,$car1
+       st      $car1,[$tp+4]
+       srlx    $car1,32,$car1
+
+       add     $car0,$car1,$car1
+       st      $car1,[$tp+8]
+       srlx    $car1,32,$car2
+\f
+       mov     4,$i                    ! i++
+       ld      [$bp+4],$mul0           ! bp[1]
+.Louter:
+       add     %sp,$bias+$frame,$tp
+       ld      [$ap],$car0             ! ap[0]
+       ld      [$ap+4],$apj            ! ap[1]
+       ld      [$np],$car1             ! np[0]
+       ld      [$np+4],$npj            ! np[1]
+       ld      [$tp],$tmp1             ! tp[0]
+       ld      [$tp+4],$tpj            ! tp[1]
+       mov     12,$j
+
+       mulx    $car0,$mul0,$car0
+       mulx    $apj,$mul0,$tmp0        !prologue!
+       add     $tmp1,$car0,$car0
+       ld      [$ap+8],$apj            !prologue!
+       and     $car0,$mask,$acc0
+
+       mulx    $n0,$acc0,$mul1
+       and     $mul1,$mask,$mul1
+
+       mulx    $car1,$mul1,$car1
+       mulx    $npj,$mul1,$acc1        !prologue!
+       srlx    $car0,32,$car0
+       add     $acc0,$car1,$car1
+       ld      [$np+8],$npj            !prologue!
+       srlx    $car1,32,$car1
+       mov     $tmp0,$acc0             !prologue!
+
+.Linner:
+       mulx    $apj,$mul0,$tmp0
+       mulx    $npj,$mul1,$tmp1
+       add     $tpj,$car0,$car0
+       ld      [$ap+$j],$apj           ! ap[j]
+       add     $acc0,$car0,$car0
+       add     $acc1,$car1,$car1
+       ld      [$np+$j],$npj           ! np[j]
+       and     $car0,$mask,$acc0
+       ld      [$tp+8],$tpj            ! tp[j]
+       srlx    $car0,32,$car0
+       add     $acc0,$car1,$car1
+       add     $j,4,$j                 ! j++
+       mov     $tmp0,$acc0
+       st      $car1,[$tp]             ! tp[j-1]
+       srlx    $car1,32,$car1
+       mov     $tmp1,$acc1
+       cmp     $j,$num
+       bl      %icc,.Linner
+       add     $tp,4,$tp               ! tp++
+!.Linner
+
+       mulx    $apj,$mul0,$tmp0        !epilogue!
+       mulx    $npj,$mul1,$tmp1
+       add     $tpj,$car0,$car0
+       add     $acc0,$car0,$car0
+       ld      [$tp+8],$tpj            ! tp[j]
+       and     $car0,$mask,$acc0
+       add     $acc1,$car1,$car1
+       srlx    $car0,32,$car0
+       add     $acc0,$car1,$car1
+       st      $car1,[$tp]             ! tp[j-1]
+       srlx    $car1,32,$car1
+
+       add     $tpj,$car0,$car0
+       add     $tmp0,$car0,$car0
+       and     $car0,$mask,$acc0
+       add     $tmp1,$car1,$car1
+       add     $acc0,$car1,$car1
+       st      $car1,[$tp+4]           ! tp[j-1]
+       srlx    $car0,32,$car0
+       add     $i,4,$i                 ! i++
+       srlx    $car1,32,$car1
+
+       add     $car0,$car1,$car1
+       cmp     $i,$num
+       add     $car2,$car1,$car1
+       st      $car1,[$tp+8]
+
+       srlx    $car1,32,$car2
+       bl,a    %icc,.Louter
+       ld      [$bp+$i],$mul0          ! bp[i]
+!.Louter
+
+       add     $tp,12,$tp
+\f
+.Ltail:
+       add     $np,$num,$np
+       add     $rp,$num,$rp
+       mov     $tp,$ap
+       sub     %g0,$num,%o7            ! k=-num
+       ba      .Lsub
+       subcc   %g0,%g0,%g0             ! clear %icc.c
+.align 16
+.Lsub:
+       ld      [$tp+%o7],%o0
+       ld      [$np+%o7],%o1
+       subccc  %o0,%o1,%o1             ! tp[j]-np[j]
+       add     $rp,%o7,$i
+       add     %o7,4,%o7
+       brnz    %o7,.Lsub
+       st      %o1,[$i]
+       subc    $car2,0,$car2           ! handle upmost overflow bit
+       and     $tp,$car2,$ap
+       andn    $rp,$car2,$np
+       or      $ap,$np,$ap
+       sub     %g0,$num,%o7
+
+.Lcopy:
+       ld      [$ap+%o7],%o0           ! copy or in-place refresh
+       st      %g0,[$tp+%o7]           ! zap tp
+       st      %o0,[$rp+%o7]
+       add     %o7,4,%o7
+       brnz    %o7,.Lcopy
+       nop
+       mov     1,%i0
+       ret
+       restore
+___
+\f
+########
+######## .Lbn_sqr_mont gives up to 20% *overall* improvement over
+######## code without following dedicated squaring procedure.
+########
+$sbit="%i2";           # re-use $bp!
+
+$code.=<<___;
+.align 32
+.Lbn_sqr_mont:
+       mulx    $mul0,$mul0,$car0               ! ap[0]*ap[0]
+       mulx    $apj,$mul0,$tmp0                !prologue!
+       and     $car0,$mask,$acc0
+       add     %sp,$bias+$frame,$tp
+       ld      [$ap+8],$apj                    !prologue!
+
+       mulx    $n0,$acc0,$mul1                 ! "t[0]"*n0
+       srlx    $car0,32,$car0
+       and     $mul1,$mask,$mul1
+
+       mulx    $car1,$mul1,$car1               ! np[0]*"t[0]"*n0
+       mulx    $npj,$mul1,$acc1                !prologue!
+       and     $car0,1,$sbit
+       ld      [$np+8],$npj                    !prologue!
+       srlx    $car0,1,$car0
+       add     $acc0,$car1,$car1
+       srlx    $car1,32,$car1
+       mov     $tmp0,$acc0                     !prologue!
+
+.Lsqr_1st:
+       mulx    $apj,$mul0,$tmp0
+       mulx    $npj,$mul1,$tmp1
+       add     $acc0,$car0,$car0               ! ap[j]*a0+c0
+       add     $acc1,$car1,$car1
+       ld      [$ap+$j],$apj                   ! ap[j]
+       and     $car0,$mask,$acc0
+       ld      [$np+$j],$npj                   ! np[j]
+       srlx    $car0,32,$car0
+       add     $acc0,$acc0,$acc0
+       or      $sbit,$acc0,$acc0
+       mov     $tmp1,$acc1
+       srlx    $acc0,32,$sbit
+       add     $j,4,$j                         ! j++
+       and     $acc0,$mask,$acc0
+       cmp     $j,$num
+       add     $acc0,$car1,$car1
+       st      $car1,[$tp]
+       mov     $tmp0,$acc0
+       srlx    $car1,32,$car1
+       bl      %icc,.Lsqr_1st
+       add     $tp,4,$tp                       ! tp++
+!.Lsqr_1st
+
+       mulx    $apj,$mul0,$tmp0                ! epilogue
+       mulx    $npj,$mul1,$tmp1
+       add     $acc0,$car0,$car0               ! ap[j]*a0+c0
+       add     $acc1,$car1,$car1
+       and     $car0,$mask,$acc0
+       srlx    $car0,32,$car0
+       add     $acc0,$acc0,$acc0
+       or      $sbit,$acc0,$acc0
+       srlx    $acc0,32,$sbit
+       and     $acc0,$mask,$acc0
+       add     $acc0,$car1,$car1
+       st      $car1,[$tp]
+       srlx    $car1,32,$car1
+
+       add     $tmp0,$car0,$car0               ! ap[j]*a0+c0
+       add     $tmp1,$car1,$car1
+       and     $car0,$mask,$acc0
+       srlx    $car0,32,$car0
+       add     $acc0,$acc0,$acc0
+       or      $sbit,$acc0,$acc0
+       srlx    $acc0,32,$sbit
+       and     $acc0,$mask,$acc0
+       add     $acc0,$car1,$car1
+       st      $car1,[$tp+4]
+       srlx    $car1,32,$car1
+
+       add     $car0,$car0,$car0
+       or      $sbit,$car0,$car0
+       add     $car0,$car1,$car1
+       st      $car1,[$tp+8]
+       srlx    $car1,32,$car2
+\f
+       ld      [%sp+$bias+$frame],$tmp0        ! tp[0]
+       ld      [%sp+$bias+$frame+4],$tmp1      ! tp[1]
+       ld      [%sp+$bias+$frame+8],$tpj       ! tp[2]
+       ld      [$ap+4],$mul0                   ! ap[1]
+       ld      [$ap+8],$apj                    ! ap[2]
+       ld      [$np],$car1                     ! np[0]
+       ld      [$np+4],$npj                    ! np[1]
+       mulx    $n0,$tmp0,$mul1
+
+       mulx    $mul0,$mul0,$car0
+       and     $mul1,$mask,$mul1
+
+       mulx    $car1,$mul1,$car1
+       mulx    $npj,$mul1,$acc1
+       add     $tmp0,$car1,$car1
+       and     $car0,$mask,$acc0
+       ld      [$np+8],$npj                    ! np[2]
+       srlx    $car1,32,$car1
+       add     $tmp1,$car1,$car1
+       srlx    $car0,32,$car0
+       add     $acc0,$car1,$car1
+       and     $car0,1,$sbit
+       add     $acc1,$car1,$car1
+       srlx    $car0,1,$car0
+       mov     12,$j
+       st      $car1,[%sp+$bias+$frame]        ! tp[0]=
+       srlx    $car1,32,$car1
+       add     %sp,$bias+$frame+4,$tp
+
+.Lsqr_2nd:
+       mulx    $apj,$mul0,$acc0
+       mulx    $npj,$mul1,$acc1
+       add     $acc0,$car0,$car0
+       add     $tpj,$car1,$car1
+       ld      [$ap+$j],$apj                   ! ap[j]
+       and     $car0,$mask,$acc0
+       ld      [$np+$j],$npj                   ! np[j]
+       srlx    $car0,32,$car0
+       add     $acc1,$car1,$car1
+       ld      [$tp+8],$tpj                    ! tp[j]
+       add     $acc0,$acc0,$acc0
+       add     $j,4,$j                         ! j++
+       or      $sbit,$acc0,$acc0
+       srlx    $acc0,32,$sbit
+       and     $acc0,$mask,$acc0
+       cmp     $j,$num
+       add     $acc0,$car1,$car1
+       st      $car1,[$tp]                     ! tp[j-1]
+       srlx    $car1,32,$car1
+       bl      %icc,.Lsqr_2nd
+       add     $tp,4,$tp                       ! tp++
+!.Lsqr_2nd
+
+       mulx    $apj,$mul0,$acc0
+       mulx    $npj,$mul1,$acc1
+       add     $acc0,$car0,$car0
+       add     $tpj,$car1,$car1
+       and     $car0,$mask,$acc0
+       srlx    $car0,32,$car0
+       add     $acc1,$car1,$car1
+       add     $acc0,$acc0,$acc0
+       or      $sbit,$acc0,$acc0
+       srlx    $acc0,32,$sbit
+       and     $acc0,$mask,$acc0
+       add     $acc0,$car1,$car1
+       st      $car1,[$tp]                     ! tp[j-1]
+       srlx    $car1,32,$car1
+
+       add     $car0,$car0,$car0
+       or      $sbit,$car0,$car0
+       add     $car0,$car1,$car1
+       add     $car2,$car1,$car1
+       st      $car1,[$tp+4]
+       srlx    $car1,32,$car2
+\f
+       ld      [%sp+$bias+$frame],$tmp1        ! tp[0]
+       ld      [%sp+$bias+$frame+4],$tpj       ! tp[1]
+       ld      [$ap+8],$mul0                   ! ap[2]
+       ld      [$np],$car1                     ! np[0]
+       ld      [$np+4],$npj                    ! np[1]
+       mulx    $n0,$tmp1,$mul1
+       and     $mul1,$mask,$mul1
+       mov     8,$i
+
+       mulx    $mul0,$mul0,$car0
+       mulx    $car1,$mul1,$car1
+       and     $car0,$mask,$acc0
+       add     $tmp1,$car1,$car1
+       srlx    $car0,32,$car0
+       add     %sp,$bias+$frame,$tp
+       srlx    $car1,32,$car1
+       and     $car0,1,$sbit
+       srlx    $car0,1,$car0
+       mov     4,$j
+
+.Lsqr_outer:
+.Lsqr_inner1:
+       mulx    $npj,$mul1,$acc1
+       add     $tpj,$car1,$car1
+       add     $j,4,$j
+       ld      [$tp+8],$tpj
+       cmp     $j,$i
+       add     $acc1,$car1,$car1
+       ld      [$np+$j],$npj
+       st      $car1,[$tp]
+       srlx    $car1,32,$car1
+       bl      %icc,.Lsqr_inner1
+       add     $tp,4,$tp
+!.Lsqr_inner1
+
+       add     $j,4,$j
+       ld      [$ap+$j],$apj                   ! ap[j]
+       mulx    $npj,$mul1,$acc1
+       add     $tpj,$car1,$car1
+       ld      [$np+$j],$npj                   ! np[j]
+       add     $acc0,$car1,$car1
+       ld      [$tp+8],$tpj                    ! tp[j]
+       add     $acc1,$car1,$car1
+       st      $car1,[$tp]
+       srlx    $car1,32,$car1
+
+       add     $j,4,$j
+       cmp     $j,$num
+       be,pn   %icc,.Lsqr_no_inner2
+       add     $tp,4,$tp
+
+.Lsqr_inner2:
+       mulx    $apj,$mul0,$acc0
+       mulx    $npj,$mul1,$acc1
+       add     $tpj,$car1,$car1
+       add     $acc0,$car0,$car0
+       ld      [$ap+$j],$apj                   ! ap[j]
+       and     $car0,$mask,$acc0
+       ld      [$np+$j],$npj                   ! np[j]
+       srlx    $car0,32,$car0
+       add     $acc0,$acc0,$acc0
+       ld      [$tp+8],$tpj                    ! tp[j]
+       or      $sbit,$acc0,$acc0
+       add     $j,4,$j                         ! j++
+       srlx    $acc0,32,$sbit
+       and     $acc0,$mask,$acc0
+       cmp     $j,$num
+       add     $acc0,$car1,$car1
+       add     $acc1,$car1,$car1
+       st      $car1,[$tp]                     ! tp[j-1]
+       srlx    $car1,32,$car1
+       bl      %icc,.Lsqr_inner2
+       add     $tp,4,$tp                       ! tp++
+
+.Lsqr_no_inner2:
+       mulx    $apj,$mul0,$acc0
+       mulx    $npj,$mul1,$acc1
+       add     $tpj,$car1,$car1
+       add     $acc0,$car0,$car0
+       and     $car0,$mask,$acc0
+       srlx    $car0,32,$car0
+       add     $acc0,$acc0,$acc0
+       or      $sbit,$acc0,$acc0
+       srlx    $acc0,32,$sbit
+       and     $acc0,$mask,$acc0
+       add     $acc0,$car1,$car1
+       add     $acc1,$car1,$car1
+       st      $car1,[$tp]                     ! tp[j-1]
+       srlx    $car1,32,$car1
+
+       add     $car0,$car0,$car0
+       or      $sbit,$car0,$car0
+       add     $car0,$car1,$car1
+       add     $car2,$car1,$car1
+       st      $car1,[$tp+4]
+       srlx    $car1,32,$car2
+\f
+       add     $i,4,$i                         ! i++
+       ld      [%sp+$bias+$frame],$tmp1        ! tp[0]
+       ld      [%sp+$bias+$frame+4],$tpj       ! tp[1]
+       ld      [$ap+$i],$mul0                  ! ap[j]
+       ld      [$np],$car1                     ! np[0]
+       ld      [$np+4],$npj                    ! np[1]
+       mulx    $n0,$tmp1,$mul1
+       and     $mul1,$mask,$mul1
+       add     $i,4,$tmp0
+
+       mulx    $mul0,$mul0,$car0
+       mulx    $car1,$mul1,$car1
+       and     $car0,$mask,$acc0
+       add     $tmp1,$car1,$car1
+       srlx    $car0,32,$car0
+       add     %sp,$bias+$frame,$tp
+       srlx    $car1,32,$car1
+       and     $car0,1,$sbit
+       srlx    $car0,1,$car0
+
+       cmp     $tmp0,$num                      ! i<num-1
+       bl      %icc,.Lsqr_outer
+       mov     4,$j
+\f
+.Lsqr_last:
+       mulx    $npj,$mul1,$acc1
+       add     $tpj,$car1,$car1
+       add     $j,4,$j
+       ld      [$tp+8],$tpj
+       cmp     $j,$i
+       add     $acc1,$car1,$car1
+       ld      [$np+$j],$npj
+       st      $car1,[$tp]
+       srlx    $car1,32,$car1
+       bl      %icc,.Lsqr_last
+       add     $tp,4,$tp
+!.Lsqr_last
+
+       mulx    $npj,$mul1,$acc1
+       add     $tpj,$car1,$car1
+       add     $acc0,$car1,$car1
+       add     $acc1,$car1,$car1
+       st      $car1,[$tp]
+       srlx    $car1,32,$car1
+
+       add     $car0,$car0,$car0               ! recover $car0
+       or      $sbit,$car0,$car0
+       add     $car0,$car1,$car1
+       add     $car2,$car1,$car1
+       st      $car1,[$tp+4]
+       srlx    $car1,32,$car2
+
+       ba      .Ltail
+       add     $tp,8,$tp
+.type  $fname,#function
+.size  $fname,(.-$fname)
+.asciz "Montgomery Multipltication for SPARCv9, CRYPTOGAMS by <appro\@openssl.org>"
+.align 32
+___
+$code =~ s/\`([^\`]*)\`/eval($1)/gem;
+print $code;
+close STDOUT;
diff --git a/deps/openssl/openssl/crypto/bn/asm/sparcv9a-mont.pl b/deps/openssl/openssl/crypto/bn/asm/sparcv9a-mont.pl
new file mode 100644 (file)
index 0000000..a14205f
--- /dev/null
@@ -0,0 +1,882 @@
+#!/usr/bin/env perl
+
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+
+# October 2005
+#
+# "Teaser" Montgomery multiplication module for UltraSPARC. Why FPU?
+# Because unlike integer multiplier, which simply stalls whole CPU,
+# FPU is fully pipelined and can effectively emit 48 bit partial
+# product every cycle. Why not blended SPARC v9? One can argue that
+# making this module dependent on UltraSPARC VIS extension limits its
+# binary compatibility. Well yes, it does exclude SPARC64 prior-V(!)
+# implementations from compatibility matrix. But the rest, whole Sun
+# UltraSPARC family and brand new Fujitsu's SPARC64 V, all support
+# VIS extension instructions used in this module. This is considered
+# good enough to not care about HAL SPARC64 users [if any] who have
+# integer-only pure SPARCv9 module to "fall down" to.
+
+# USI&II cores currently exhibit uniform 2x improvement [over pre-
+# bn_mul_mont codebase] for all key lengths and benchmarks. On USIII
+# performance improves few percents for shorter keys and worsens few
+# percents for longer keys. This is because USIII integer multiplier
+# is >3x faster than USI&II one, which is harder to match [but see
+# TODO list below]. It should also be noted that SPARC64 V features
+# out-of-order execution, which *might* mean that integer multiplier
+# is pipelined, which in turn *might* be impossible to match... On
+# additional note, SPARC64 V implements FP Multiply-Add instruction,
+# which is perfectly usable in this context... In other words, as far
+# as Fujitsu SPARC64 V goes, talk to the author:-)
+
+# The implementation implies following "non-natural" limitations on
+# input arguments:
+# - num may not be less than 4;
+# - num has to be even;
+# Failure to meet either condition has no fatal effects, simply
+# doesn't give any performance gain.
+
+# TODO:
+# - modulo-schedule inner loop for better performance (on in-order
+#   execution core such as UltraSPARC this shall result in further
+#   noticeable(!) improvement);
+# - dedicated squaring procedure[?];
+
+######################################################################
+# November 2006
+#
+# Modulo-scheduled inner loops allow to interleave floating point and
+# integer instructions and minimize Read-After-Write penalties. This
+# results in *further* 20-50% perfromance improvement [depending on
+# key length, more for longer keys] on USI&II cores and 30-80% - on
+# USIII&IV.
+
+$fname="bn_mul_mont_fpu";
+$bits=32;
+for (@ARGV) { $bits=64 if (/\-m64/ || /\-xarch\=v9/); }
+
+if ($bits==64) {
+       $bias=2047;
+       $frame=192;
+} else {
+       $bias=0;
+       $frame=128;     # 96 rounded up to largest known cache-line
+}
+$locals=64;
+
+# In order to provide for 32-/64-bit ABI duality, I keep integers wider
+# than 32 bit in %g1-%g4 and %o0-%o5. %l0-%l7 and %i0-%i5 are used
+# exclusively for pointers, indexes and other small values...
+# int bn_mul_mont(
+$rp="%i0";     # BN_ULONG *rp,
+$ap="%i1";     # const BN_ULONG *ap,
+$bp="%i2";     # const BN_ULONG *bp,
+$np="%i3";     # const BN_ULONG *np,
+$n0="%i4";     # const BN_ULONG *n0,
+$num="%i5";    # int num);
+
+$tp="%l0";     # t[num]
+$ap_l="%l1";   # a[num],n[num] are smashed to 32-bit words and saved
+$ap_h="%l2";   # to these four vectors as double-precision FP values.
+$np_l="%l3";   # This way a bunch of fxtods are eliminated in second
+$np_h="%l4";   # loop and L1-cache aliasing is minimized...
+$i="%l5";
+$j="%l6";
+$mask="%l7";   # 16-bit mask, 0xffff
+
+$n0="%g4";     # reassigned(!) to "64-bit" register
+$carry="%i4";  # %i4 reused(!) for a carry bit
+
+# FP register naming chart
+#
+#     ..HILO
+#       dcba
+#   --------
+#        LOa
+#       LOb
+#      LOc
+#     LOd
+#      HIa
+#     HIb
+#    HIc
+#   HId
+#    ..a
+#   ..b
+$ba="%f0";    $bb="%f2";    $bc="%f4";    $bd="%f6";
+$na="%f8";    $nb="%f10";   $nc="%f12";   $nd="%f14";
+$alo="%f16";  $alo_="%f17"; $ahi="%f18";  $ahi_="%f19";
+$nlo="%f20";  $nlo_="%f21"; $nhi="%f22";  $nhi_="%f23";
+
+$dota="%f24"; $dotb="%f26";
+
+$aloa="%f32"; $alob="%f34"; $aloc="%f36"; $alod="%f38";
+$ahia="%f40"; $ahib="%f42"; $ahic="%f44"; $ahid="%f46";
+$nloa="%f48"; $nlob="%f50"; $nloc="%f52"; $nlod="%f54";
+$nhia="%f56"; $nhib="%f58"; $nhic="%f60"; $nhid="%f62";
+
+$ASI_FL16_P=0xD2;      # magic ASI value to engage 16-bit FP load
+
+$code=<<___;
+.section       ".text",#alloc,#execinstr
+
+.global $fname
+.align  32
+$fname:
+       save    %sp,-$frame-$locals,%sp
+
+       cmp     $num,4
+       bl,a,pn %icc,.Lret
+       clr     %i0
+       andcc   $num,1,%g0              ! $num has to be even...
+       bnz,a,pn %icc,.Lret
+       clr     %i0                     ! signal "unsupported input value"
+
+       srl     $num,1,$num
+       sethi   %hi(0xffff),$mask
+       ld      [%i4+0],$n0             ! $n0 reassigned, remember?
+       or      $mask,%lo(0xffff),$mask
+       ld      [%i4+4],%o0
+       sllx    %o0,32,%o0
+       or      %o0,$n0,$n0             ! $n0=n0[1].n0[0]
+
+       sll     $num,3,$num             ! num*=8
+
+       add     %sp,$bias,%o0           ! real top of stack
+       sll     $num,2,%o1
+       add     %o1,$num,%o1            ! %o1=num*5
+       sub     %o0,%o1,%o0
+       and     %o0,-2048,%o0           ! optimize TLB utilization
+       sub     %o0,$bias,%sp           ! alloca(5*num*8)
+
+       rd      %asi,%o7                ! save %asi
+       add     %sp,$bias+$frame+$locals,$tp
+       add     $tp,$num,$ap_l
+       add     $ap_l,$num,$ap_l        ! [an]p_[lh] point at the vectors' ends !
+       add     $ap_l,$num,$ap_h
+       add     $ap_h,$num,$np_l
+       add     $np_l,$num,$np_h
+
+       wr      %g0,$ASI_FL16_P,%asi    ! setup %asi for 16-bit FP loads
+
+       add     $rp,$num,$rp            ! readjust input pointers to point
+       add     $ap,$num,$ap            ! at the ends too...
+       add     $bp,$num,$bp
+       add     $np,$num,$np
+
+       stx     %o7,[%sp+$bias+$frame+48]       ! save %asi
+\f
+       sub     %g0,$num,$i             ! i=-num
+       sub     %g0,$num,$j             ! j=-num
+
+       add     $ap,$j,%o3
+       add     $bp,$i,%o4
+
+       ld      [%o3+4],%g1             ! bp[0]
+       ld      [%o3+0],%o0
+       ld      [%o4+4],%g5             ! ap[0]
+       sllx    %g1,32,%g1
+       ld      [%o4+0],%o1
+       sllx    %g5,32,%g5
+       or      %g1,%o0,%o0
+       or      %g5,%o1,%o1
+
+       add     $np,$j,%o5
+
+       mulx    %o1,%o0,%o0             ! ap[0]*bp[0]
+       mulx    $n0,%o0,%o0             ! ap[0]*bp[0]*n0
+       stx     %o0,[%sp+$bias+$frame+0]
+
+       ld      [%o3+0],$alo_   ! load a[j] as pair of 32-bit words
+       fzeros  $alo
+       ld      [%o3+4],$ahi_
+       fzeros  $ahi
+       ld      [%o5+0],$nlo_   ! load n[j] as pair of 32-bit words
+       fzeros  $nlo
+       ld      [%o5+4],$nhi_
+       fzeros  $nhi
+
+       ! transfer b[i] to FPU as 4x16-bit values
+       ldda    [%o4+2]%asi,$ba
+       fxtod   $alo,$alo
+       ldda    [%o4+0]%asi,$bb
+       fxtod   $ahi,$ahi
+       ldda    [%o4+6]%asi,$bc
+       fxtod   $nlo,$nlo
+       ldda    [%o4+4]%asi,$bd
+       fxtod   $nhi,$nhi
+
+       ! transfer ap[0]*b[0]*n0 to FPU as 4x16-bit values
+       ldda    [%sp+$bias+$frame+6]%asi,$na
+       fxtod   $ba,$ba
+       ldda    [%sp+$bias+$frame+4]%asi,$nb
+       fxtod   $bb,$bb
+       ldda    [%sp+$bias+$frame+2]%asi,$nc
+       fxtod   $bc,$bc
+       ldda    [%sp+$bias+$frame+0]%asi,$nd
+       fxtod   $bd,$bd
+
+       std     $alo,[$ap_l+$j]         ! save smashed ap[j] in double format
+       fxtod   $na,$na
+       std     $ahi,[$ap_h+$j]
+       fxtod   $nb,$nb
+       std     $nlo,[$np_l+$j]         ! save smashed np[j] in double format
+       fxtod   $nc,$nc
+       std     $nhi,[$np_h+$j]
+       fxtod   $nd,$nd
+
+               fmuld   $alo,$ba,$aloa
+               fmuld   $nlo,$na,$nloa
+               fmuld   $alo,$bb,$alob
+               fmuld   $nlo,$nb,$nlob
+               fmuld   $alo,$bc,$aloc
+       faddd   $aloa,$nloa,$nloa
+               fmuld   $nlo,$nc,$nloc
+               fmuld   $alo,$bd,$alod
+       faddd   $alob,$nlob,$nlob
+               fmuld   $nlo,$nd,$nlod
+               fmuld   $ahi,$ba,$ahia
+       faddd   $aloc,$nloc,$nloc
+               fmuld   $nhi,$na,$nhia
+               fmuld   $ahi,$bb,$ahib
+       faddd   $alod,$nlod,$nlod
+               fmuld   $nhi,$nb,$nhib
+               fmuld   $ahi,$bc,$ahic
+       faddd   $ahia,$nhia,$nhia
+               fmuld   $nhi,$nc,$nhic
+               fmuld   $ahi,$bd,$ahid
+       faddd   $ahib,$nhib,$nhib
+               fmuld   $nhi,$nd,$nhid
+
+       faddd   $ahic,$nhic,$dota       ! $nhic
+       faddd   $ahid,$nhid,$dotb       ! $nhid
+
+       faddd   $nloc,$nhia,$nloc
+       faddd   $nlod,$nhib,$nlod
+
+       fdtox   $nloa,$nloa
+       fdtox   $nlob,$nlob
+       fdtox   $nloc,$nloc
+       fdtox   $nlod,$nlod
+
+       std     $nloa,[%sp+$bias+$frame+0]
+       add     $j,8,$j
+       std     $nlob,[%sp+$bias+$frame+8]
+       add     $ap,$j,%o4
+       std     $nloc,[%sp+$bias+$frame+16]
+       add     $np,$j,%o5
+       std     $nlod,[%sp+$bias+$frame+24]
+\f
+       ld      [%o4+0],$alo_   ! load a[j] as pair of 32-bit words
+       fzeros  $alo
+       ld      [%o4+4],$ahi_
+       fzeros  $ahi
+       ld      [%o5+0],$nlo_   ! load n[j] as pair of 32-bit words
+       fzeros  $nlo
+       ld      [%o5+4],$nhi_
+       fzeros  $nhi
+
+       fxtod   $alo,$alo
+       fxtod   $ahi,$ahi
+       fxtod   $nlo,$nlo
+       fxtod   $nhi,$nhi
+
+       ldx     [%sp+$bias+$frame+0],%o0
+               fmuld   $alo,$ba,$aloa
+       ldx     [%sp+$bias+$frame+8],%o1
+               fmuld   $nlo,$na,$nloa
+       ldx     [%sp+$bias+$frame+16],%o2
+               fmuld   $alo,$bb,$alob
+       ldx     [%sp+$bias+$frame+24],%o3
+               fmuld   $nlo,$nb,$nlob
+
+       srlx    %o0,16,%o7
+       std     $alo,[$ap_l+$j]         ! save smashed ap[j] in double format
+               fmuld   $alo,$bc,$aloc
+       add     %o7,%o1,%o1
+       std     $ahi,[$ap_h+$j]
+               faddd   $aloa,$nloa,$nloa
+               fmuld   $nlo,$nc,$nloc
+       srlx    %o1,16,%o7
+       std     $nlo,[$np_l+$j]         ! save smashed np[j] in double format
+               fmuld   $alo,$bd,$alod
+       add     %o7,%o2,%o2
+       std     $nhi,[$np_h+$j]
+               faddd   $alob,$nlob,$nlob
+               fmuld   $nlo,$nd,$nlod
+       srlx    %o2,16,%o7
+               fmuld   $ahi,$ba,$ahia
+       add     %o7,%o3,%o3             ! %o3.%o2[0..15].%o1[0..15].%o0[0..15]
+               faddd   $aloc,$nloc,$nloc
+               fmuld   $nhi,$na,$nhia
+       !and    %o0,$mask,%o0
+       !and    %o1,$mask,%o1
+       !and    %o2,$mask,%o2
+       !sllx   %o1,16,%o1
+       !sllx   %o2,32,%o2
+       !sllx   %o3,48,%o7
+       !or     %o1,%o0,%o0
+       !or     %o2,%o0,%o0
+       !or     %o7,%o0,%o0             ! 64-bit result
+       srlx    %o3,16,%g1              ! 34-bit carry
+               fmuld   $ahi,$bb,$ahib
+
+       faddd   $alod,$nlod,$nlod
+               fmuld   $nhi,$nb,$nhib
+               fmuld   $ahi,$bc,$ahic
+       faddd   $ahia,$nhia,$nhia
+               fmuld   $nhi,$nc,$nhic
+               fmuld   $ahi,$bd,$ahid
+       faddd   $ahib,$nhib,$nhib
+               fmuld   $nhi,$nd,$nhid
+
+       faddd   $dota,$nloa,$nloa
+       faddd   $dotb,$nlob,$nlob
+       faddd   $ahic,$nhic,$dota       ! $nhic
+       faddd   $ahid,$nhid,$dotb       ! $nhid
+
+       faddd   $nloc,$nhia,$nloc
+       faddd   $nlod,$nhib,$nlod
+
+       fdtox   $nloa,$nloa
+       fdtox   $nlob,$nlob
+       fdtox   $nloc,$nloc
+       fdtox   $nlod,$nlod
+
+       std     $nloa,[%sp+$bias+$frame+0]
+       std     $nlob,[%sp+$bias+$frame+8]
+       addcc   $j,8,$j
+       std     $nloc,[%sp+$bias+$frame+16]
+       bz,pn   %icc,.L1stskip
+       std     $nlod,[%sp+$bias+$frame+24]
+\f
+.align 32                      ! incidentally already aligned !
+.L1st:
+       add     $ap,$j,%o4
+       add     $np,$j,%o5
+       ld      [%o4+0],$alo_   ! load a[j] as pair of 32-bit words
+       fzeros  $alo
+       ld      [%o4+4],$ahi_
+       fzeros  $ahi
+       ld      [%o5+0],$nlo_   ! load n[j] as pair of 32-bit words
+       fzeros  $nlo
+       ld      [%o5+4],$nhi_
+       fzeros  $nhi
+
+       fxtod   $alo,$alo
+       fxtod   $ahi,$ahi
+       fxtod   $nlo,$nlo
+       fxtod   $nhi,$nhi
+
+       ldx     [%sp+$bias+$frame+0],%o0
+               fmuld   $alo,$ba,$aloa
+       ldx     [%sp+$bias+$frame+8],%o1
+               fmuld   $nlo,$na,$nloa
+       ldx     [%sp+$bias+$frame+16],%o2
+               fmuld   $alo,$bb,$alob
+       ldx     [%sp+$bias+$frame+24],%o3
+               fmuld   $nlo,$nb,$nlob
+
+       srlx    %o0,16,%o7
+       std     $alo,[$ap_l+$j]         ! save smashed ap[j] in double format
+               fmuld   $alo,$bc,$aloc
+       add     %o7,%o1,%o1
+       std     $ahi,[$ap_h+$j]
+               faddd   $aloa,$nloa,$nloa
+               fmuld   $nlo,$nc,$nloc
+       srlx    %o1,16,%o7
+       std     $nlo,[$np_l+$j]         ! save smashed np[j] in double format
+               fmuld   $alo,$bd,$alod
+       add     %o7,%o2,%o2
+       std     $nhi,[$np_h+$j]
+               faddd   $alob,$nlob,$nlob
+               fmuld   $nlo,$nd,$nlod
+       srlx    %o2,16,%o7
+               fmuld   $ahi,$ba,$ahia
+       add     %o7,%o3,%o3             ! %o3.%o2[0..15].%o1[0..15].%o0[0..15]
+       and     %o0,$mask,%o0
+               faddd   $aloc,$nloc,$nloc
+               fmuld   $nhi,$na,$nhia
+       and     %o1,$mask,%o1
+       and     %o2,$mask,%o2
+               fmuld   $ahi,$bb,$ahib
+       sllx    %o1,16,%o1
+               faddd   $alod,$nlod,$nlod
+               fmuld   $nhi,$nb,$nhib
+       sllx    %o2,32,%o2
+               fmuld   $ahi,$bc,$ahic
+       sllx    %o3,48,%o7
+       or      %o1,%o0,%o0
+               faddd   $ahia,$nhia,$nhia
+               fmuld   $nhi,$nc,$nhic
+       or      %o2,%o0,%o0
+               fmuld   $ahi,$bd,$ahid
+       or      %o7,%o0,%o0             ! 64-bit result
+               faddd   $ahib,$nhib,$nhib
+               fmuld   $nhi,$nd,$nhid
+       addcc   %g1,%o0,%o0
+               faddd   $dota,$nloa,$nloa
+       srlx    %o3,16,%g1              ! 34-bit carry
+               faddd   $dotb,$nlob,$nlob
+       bcs,a   %xcc,.+8
+       add     %g1,1,%g1
+
+       stx     %o0,[$tp]               ! tp[j-1]=
+
+       faddd   $ahic,$nhic,$dota       ! $nhic
+       faddd   $ahid,$nhid,$dotb       ! $nhid
+
+       faddd   $nloc,$nhia,$nloc
+       faddd   $nlod,$nhib,$nlod
+
+       fdtox   $nloa,$nloa
+       fdtox   $nlob,$nlob
+       fdtox   $nloc,$nloc
+       fdtox   $nlod,$nlod
+
+       std     $nloa,[%sp+$bias+$frame+0]
+       std     $nlob,[%sp+$bias+$frame+8]
+       std     $nloc,[%sp+$bias+$frame+16]
+       std     $nlod,[%sp+$bias+$frame+24]
+
+       addcc   $j,8,$j
+       bnz,pt  %icc,.L1st
+       add     $tp,8,$tp
+\f
+.L1stskip:
+       fdtox   $dota,$dota
+       fdtox   $dotb,$dotb
+
+       ldx     [%sp+$bias+$frame+0],%o0
+       ldx     [%sp+$bias+$frame+8],%o1
+       ldx     [%sp+$bias+$frame+16],%o2
+       ldx     [%sp+$bias+$frame+24],%o3
+
+       srlx    %o0,16,%o7
+       std     $dota,[%sp+$bias+$frame+32]
+       add     %o7,%o1,%o1
+       std     $dotb,[%sp+$bias+$frame+40]
+       srlx    %o1,16,%o7
+       add     %o7,%o2,%o2
+       srlx    %o2,16,%o7
+       add     %o7,%o3,%o3             ! %o3.%o2[0..15].%o1[0..15].%o0[0..15]
+       and     %o0,$mask,%o0
+       and     %o1,$mask,%o1
+       and     %o2,$mask,%o2
+       sllx    %o1,16,%o1
+       sllx    %o2,32,%o2
+       sllx    %o3,48,%o7
+       or      %o1,%o0,%o0
+       or      %o2,%o0,%o0
+       or      %o7,%o0,%o0             ! 64-bit result
+       ldx     [%sp+$bias+$frame+32],%o4
+       addcc   %g1,%o0,%o0
+       ldx     [%sp+$bias+$frame+40],%o5
+       srlx    %o3,16,%g1              ! 34-bit carry
+       bcs,a   %xcc,.+8
+       add     %g1,1,%g1
+
+       stx     %o0,[$tp]               ! tp[j-1]=
+       add     $tp,8,$tp
+
+       srlx    %o4,16,%o7
+       add     %o7,%o5,%o5
+       and     %o4,$mask,%o4
+       sllx    %o5,16,%o7
+       or      %o7,%o4,%o4
+       addcc   %g1,%o4,%o4
+       srlx    %o5,48,%g1
+       bcs,a   %xcc,.+8
+       add     %g1,1,%g1
+
+       mov     %g1,$carry
+       stx     %o4,[$tp]               ! tp[num-1]=
+\f
+       ba      .Louter
+       add     $i,8,$i
+.align 32
+.Louter:
+       sub     %g0,$num,$j             ! j=-num
+       add     %sp,$bias+$frame+$locals,$tp
+
+       add     $ap,$j,%o3
+       add     $bp,$i,%o4
+
+       ld      [%o3+4],%g1             ! bp[i]
+       ld      [%o3+0],%o0
+       ld      [%o4+4],%g5             ! ap[0]
+       sllx    %g1,32,%g1
+       ld      [%o4+0],%o1
+       sllx    %g5,32,%g5
+       or      %g1,%o0,%o0
+       or      %g5,%o1,%o1
+
+       ldx     [$tp],%o2               ! tp[0]
+       mulx    %o1,%o0,%o0
+       addcc   %o2,%o0,%o0
+       mulx    $n0,%o0,%o0             ! (ap[0]*bp[i]+t[0])*n0
+       stx     %o0,[%sp+$bias+$frame+0]
+
+       ! transfer b[i] to FPU as 4x16-bit values
+       ldda    [%o4+2]%asi,$ba
+       ldda    [%o4+0]%asi,$bb
+       ldda    [%o4+6]%asi,$bc
+       ldda    [%o4+4]%asi,$bd
+
+       ! transfer (ap[0]*b[i]+t[0])*n0 to FPU as 4x16-bit values
+       ldda    [%sp+$bias+$frame+6]%asi,$na
+       fxtod   $ba,$ba
+       ldda    [%sp+$bias+$frame+4]%asi,$nb
+       fxtod   $bb,$bb
+       ldda    [%sp+$bias+$frame+2]%asi,$nc
+       fxtod   $bc,$bc
+       ldda    [%sp+$bias+$frame+0]%asi,$nd
+       fxtod   $bd,$bd
+       ldd     [$ap_l+$j],$alo         ! load a[j] in double format
+       fxtod   $na,$na
+       ldd     [$ap_h+$j],$ahi
+       fxtod   $nb,$nb
+       ldd     [$np_l+$j],$nlo         ! load n[j] in double format
+       fxtod   $nc,$nc
+       ldd     [$np_h+$j],$nhi
+       fxtod   $nd,$nd
+
+               fmuld   $alo,$ba,$aloa
+               fmuld   $nlo,$na,$nloa
+               fmuld   $alo,$bb,$alob
+               fmuld   $nlo,$nb,$nlob
+               fmuld   $alo,$bc,$aloc
+       faddd   $aloa,$nloa,$nloa
+               fmuld   $nlo,$nc,$nloc
+               fmuld   $alo,$bd,$alod
+       faddd   $alob,$nlob,$nlob
+               fmuld   $nlo,$nd,$nlod
+               fmuld   $ahi,$ba,$ahia
+       faddd   $aloc,$nloc,$nloc
+               fmuld   $nhi,$na,$nhia
+               fmuld   $ahi,$bb,$ahib
+       faddd   $alod,$nlod,$nlod
+               fmuld   $nhi,$nb,$nhib
+               fmuld   $ahi,$bc,$ahic
+       faddd   $ahia,$nhia,$nhia
+               fmuld   $nhi,$nc,$nhic
+               fmuld   $ahi,$bd,$ahid
+       faddd   $ahib,$nhib,$nhib
+               fmuld   $nhi,$nd,$nhid
+
+       faddd   $ahic,$nhic,$dota       ! $nhic
+       faddd   $ahid,$nhid,$dotb       ! $nhid
+
+       faddd   $nloc,$nhia,$nloc
+       faddd   $nlod,$nhib,$nlod
+
+       fdtox   $nloa,$nloa
+       fdtox   $nlob,$nlob
+       fdtox   $nloc,$nloc
+       fdtox   $nlod,$nlod
+
+       std     $nloa,[%sp+$bias+$frame+0]
+       std     $nlob,[%sp+$bias+$frame+8]
+       std     $nloc,[%sp+$bias+$frame+16]
+       add     $j,8,$j
+       std     $nlod,[%sp+$bias+$frame+24]
+\f
+       ldd     [$ap_l+$j],$alo         ! load a[j] in double format
+       ldd     [$ap_h+$j],$ahi
+       ldd     [$np_l+$j],$nlo         ! load n[j] in double format
+       ldd     [$np_h+$j],$nhi
+
+               fmuld   $alo,$ba,$aloa
+               fmuld   $nlo,$na,$nloa
+               fmuld   $alo,$bb,$alob
+               fmuld   $nlo,$nb,$nlob
+               fmuld   $alo,$bc,$aloc
+       ldx     [%sp+$bias+$frame+0],%o0
+               faddd   $aloa,$nloa,$nloa
+               fmuld   $nlo,$nc,$nloc
+       ldx     [%sp+$bias+$frame+8],%o1
+               fmuld   $alo,$bd,$alod
+       ldx     [%sp+$bias+$frame+16],%o2
+               faddd   $alob,$nlob,$nlob
+               fmuld   $nlo,$nd,$nlod
+       ldx     [%sp+$bias+$frame+24],%o3
+               fmuld   $ahi,$ba,$ahia
+
+       srlx    %o0,16,%o7
+               faddd   $aloc,$nloc,$nloc
+               fmuld   $nhi,$na,$nhia
+       add     %o7,%o1,%o1
+               fmuld   $ahi,$bb,$ahib
+       srlx    %o1,16,%o7
+               faddd   $alod,$nlod,$nlod
+               fmuld   $nhi,$nb,$nhib
+       add     %o7,%o2,%o2
+               fmuld   $ahi,$bc,$ahic
+       srlx    %o2,16,%o7
+               faddd   $ahia,$nhia,$nhia
+               fmuld   $nhi,$nc,$nhic
+       add     %o7,%o3,%o3             ! %o3.%o2[0..15].%o1[0..15].%o0[0..15]
+       ! why?
+       and     %o0,$mask,%o0
+               fmuld   $ahi,$bd,$ahid
+       and     %o1,$mask,%o1
+       and     %o2,$mask,%o2
+               faddd   $ahib,$nhib,$nhib
+               fmuld   $nhi,$nd,$nhid
+       sllx    %o1,16,%o1
+               faddd   $dota,$nloa,$nloa
+       sllx    %o2,32,%o2
+               faddd   $dotb,$nlob,$nlob
+       sllx    %o3,48,%o7
+       or      %o1,%o0,%o0
+               faddd   $ahic,$nhic,$dota       ! $nhic
+       or      %o2,%o0,%o0
+               faddd   $ahid,$nhid,$dotb       ! $nhid
+       or      %o7,%o0,%o0             ! 64-bit result
+       ldx     [$tp],%o7
+               faddd   $nloc,$nhia,$nloc
+       addcc   %o7,%o0,%o0
+       ! end-of-why?
+               faddd   $nlod,$nhib,$nlod
+       srlx    %o3,16,%g1              ! 34-bit carry
+               fdtox   $nloa,$nloa
+       bcs,a   %xcc,.+8
+       add     %g1,1,%g1
+
+       fdtox   $nlob,$nlob
+       fdtox   $nloc,$nloc
+       fdtox   $nlod,$nlod
+
+       std     $nloa,[%sp+$bias+$frame+0]
+       std     $nlob,[%sp+$bias+$frame+8]
+       addcc   $j,8,$j
+       std     $nloc,[%sp+$bias+$frame+16]
+       bz,pn   %icc,.Linnerskip
+       std     $nlod,[%sp+$bias+$frame+24]
+\f
+       ba      .Linner
+       nop
+.align 32
+.Linner:
+       ldd     [$ap_l+$j],$alo         ! load a[j] in double format
+       ldd     [$ap_h+$j],$ahi
+       ldd     [$np_l+$j],$nlo         ! load n[j] in double format
+       ldd     [$np_h+$j],$nhi
+
+               fmuld   $alo,$ba,$aloa
+               fmuld   $nlo,$na,$nloa
+               fmuld   $alo,$bb,$alob
+               fmuld   $nlo,$nb,$nlob
+               fmuld   $alo,$bc,$aloc
+       ldx     [%sp+$bias+$frame+0],%o0
+               faddd   $aloa,$nloa,$nloa
+               fmuld   $nlo,$nc,$nloc
+       ldx     [%sp+$bias+$frame+8],%o1
+               fmuld   $alo,$bd,$alod
+       ldx     [%sp+$bias+$frame+16],%o2
+               faddd   $alob,$nlob,$nlob
+               fmuld   $nlo,$nd,$nlod
+       ldx     [%sp+$bias+$frame+24],%o3
+               fmuld   $ahi,$ba,$ahia
+
+       srlx    %o0,16,%o7
+               faddd   $aloc,$nloc,$nloc
+               fmuld   $nhi,$na,$nhia
+       add     %o7,%o1,%o1
+               fmuld   $ahi,$bb,$ahib
+       srlx    %o1,16,%o7
+               faddd   $alod,$nlod,$nlod
+               fmuld   $nhi,$nb,$nhib
+       add     %o7,%o2,%o2
+               fmuld   $ahi,$bc,$ahic
+       srlx    %o2,16,%o7
+               faddd   $ahia,$nhia,$nhia
+               fmuld   $nhi,$nc,$nhic
+       add     %o7,%o3,%o3             ! %o3.%o2[0..15].%o1[0..15].%o0[0..15]
+       and     %o0,$mask,%o0
+               fmuld   $ahi,$bd,$ahid
+       and     %o1,$mask,%o1
+       and     %o2,$mask,%o2
+               faddd   $ahib,$nhib,$nhib
+               fmuld   $nhi,$nd,$nhid
+       sllx    %o1,16,%o1
+               faddd   $dota,$nloa,$nloa
+       sllx    %o2,32,%o2
+               faddd   $dotb,$nlob,$nlob
+       sllx    %o3,48,%o7
+       or      %o1,%o0,%o0
+               faddd   $ahic,$nhic,$dota       ! $nhic
+       or      %o2,%o0,%o0
+               faddd   $ahid,$nhid,$dotb       ! $nhid
+       or      %o7,%o0,%o0             ! 64-bit result
+               faddd   $nloc,$nhia,$nloc
+       addcc   %g1,%o0,%o0
+       ldx     [$tp+8],%o7             ! tp[j]
+               faddd   $nlod,$nhib,$nlod
+       srlx    %o3,16,%g1              ! 34-bit carry
+               fdtox   $nloa,$nloa
+       bcs,a   %xcc,.+8
+       add     %g1,1,%g1
+               fdtox   $nlob,$nlob
+       addcc   %o7,%o0,%o0
+               fdtox   $nloc,$nloc
+       bcs,a   %xcc,.+8
+       add     %g1,1,%g1
+
+       stx     %o0,[$tp]               ! tp[j-1]
+               fdtox   $nlod,$nlod
+
+       std     $nloa,[%sp+$bias+$frame+0]
+       std     $nlob,[%sp+$bias+$frame+8]
+       std     $nloc,[%sp+$bias+$frame+16]
+       addcc   $j,8,$j
+       std     $nlod,[%sp+$bias+$frame+24]
+       bnz,pt  %icc,.Linner
+       add     $tp,8,$tp
+\f
+.Linnerskip:
+       fdtox   $dota,$dota
+       fdtox   $dotb,$dotb
+
+       ldx     [%sp+$bias+$frame+0],%o0
+       ldx     [%sp+$bias+$frame+8],%o1
+       ldx     [%sp+$bias+$frame+16],%o2
+       ldx     [%sp+$bias+$frame+24],%o3
+
+       srlx    %o0,16,%o7
+       std     $dota,[%sp+$bias+$frame+32]
+       add     %o7,%o1,%o1
+       std     $dotb,[%sp+$bias+$frame+40]
+       srlx    %o1,16,%o7
+       add     %o7,%o2,%o2
+       srlx    %o2,16,%o7
+       add     %o7,%o3,%o3             ! %o3.%o2[0..15].%o1[0..15].%o0[0..15]
+       and     %o0,$mask,%o0
+       and     %o1,$mask,%o1
+       and     %o2,$mask,%o2
+       sllx    %o1,16,%o1
+       sllx    %o2,32,%o2
+       sllx    %o3,48,%o7
+       or      %o1,%o0,%o0
+       or      %o2,%o0,%o0
+       ldx     [%sp+$bias+$frame+32],%o4
+       or      %o7,%o0,%o0             ! 64-bit result
+       ldx     [%sp+$bias+$frame+40],%o5
+       addcc   %g1,%o0,%o0
+       ldx     [$tp+8],%o7             ! tp[j]
+       srlx    %o3,16,%g1              ! 34-bit carry
+       bcs,a   %xcc,.+8
+       add     %g1,1,%g1
+
+       addcc   %o7,%o0,%o0
+       bcs,a   %xcc,.+8
+       add     %g1,1,%g1
+
+       stx     %o0,[$tp]               ! tp[j-1]
+       add     $tp,8,$tp
+
+       srlx    %o4,16,%o7
+       add     %o7,%o5,%o5
+       and     %o4,$mask,%o4
+       sllx    %o5,16,%o7
+       or      %o7,%o4,%o4
+       addcc   %g1,%o4,%o4
+       srlx    %o5,48,%g1
+       bcs,a   %xcc,.+8
+       add     %g1,1,%g1
+
+       addcc   $carry,%o4,%o4
+       stx     %o4,[$tp]               ! tp[num-1]
+       mov     %g1,$carry
+       bcs,a   %xcc,.+8
+       add     $carry,1,$carry
+
+       addcc   $i,8,$i
+       bnz     %icc,.Louter
+       nop
+\f
+       add     $tp,8,$tp               ! adjust tp to point at the end
+       orn     %g0,%g0,%g4
+       sub     %g0,$num,%o7            ! n=-num
+       ba      .Lsub
+       subcc   %g0,%g0,%g0             ! clear %icc.c
+
+.align 32
+.Lsub:
+       ldx     [$tp+%o7],%o0
+       add     $np,%o7,%g1
+       ld      [%g1+0],%o2
+       ld      [%g1+4],%o3
+       srlx    %o0,32,%o1
+       subccc  %o0,%o2,%o2
+       add     $rp,%o7,%g1
+       subccc  %o1,%o3,%o3
+       st      %o2,[%g1+0]
+       add     %o7,8,%o7
+       brnz,pt %o7,.Lsub
+       st      %o3,[%g1+4]
+       subc    $carry,0,%g4
+       sub     %g0,$num,%o7            ! n=-num
+       ba      .Lcopy
+       nop
+
+.align 32
+.Lcopy:
+       ldx     [$tp+%o7],%o0
+       add     $rp,%o7,%g1
+       ld      [%g1+0],%o2
+       ld      [%g1+4],%o3
+       stx     %g0,[$tp+%o7]
+       and     %o0,%g4,%o0
+       srlx    %o0,32,%o1
+       andn    %o2,%g4,%o2
+       andn    %o3,%g4,%o3
+       or      %o2,%o0,%o0
+       or      %o3,%o1,%o1
+       st      %o0,[%g1+0]
+       add     %o7,8,%o7
+       brnz,pt %o7,.Lcopy
+       st      %o1,[%g1+4]
+       sub     %g0,$num,%o7            ! n=-num
+
+.Lzap:
+       stx     %g0,[$ap_l+%o7]
+       stx     %g0,[$ap_h+%o7]
+       stx     %g0,[$np_l+%o7]
+       stx     %g0,[$np_h+%o7]
+       add     %o7,8,%o7
+       brnz,pt %o7,.Lzap
+       nop
+
+       ldx     [%sp+$bias+$frame+48],%o7
+       wr      %g0,%o7,%asi            ! restore %asi
+
+       mov     1,%i0
+.Lret:
+       ret
+       restore
+.type   $fname,#function
+.size  $fname,(.-$fname)
+.asciz "Montgomery Multipltication for UltraSPARC, CRYPTOGAMS by <appro\@openssl.org>"
+.align 32
+___
+
+$code =~ s/\`([^\`]*)\`/eval($1)/gem;
+
+# Below substitution makes it possible to compile without demanding
+# VIS extentions on command line, e.g. -xarch=v9 vs. -xarch=v9a. I
+# dare to do this, because VIS capability is detected at run-time now
+# and this routine is not called on CPU not capable to execute it. Do
+# note that fzeros is not the only VIS dependency! Another dependency
+# is implicit and is just _a_ numerical value loaded to %asi register,
+# which assembler can't recognize as VIS specific...
+$code =~ s/fzeros\s+%f([0-9]+)/
+          sprintf(".word\t0x%x\t! fzeros %%f%d",0x81b00c20|($1<<25),$1)
+         /gem;
+
+print $code;
+# flush
+close STDOUT;
diff --git a/deps/openssl/openssl/crypto/bn/asm/via-mont.pl b/deps/openssl/openssl/crypto/bn/asm/via-mont.pl
new file mode 100644 (file)
index 0000000..c046a51
--- /dev/null
@@ -0,0 +1,242 @@
+#!/usr/bin/env perl
+#
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+#
+# Wrapper around 'rep montmul', VIA-specific instruction accessing
+# PadLock Montgomery Multiplier. The wrapper is designed as drop-in
+# replacement for OpenSSL bn_mul_mont [first implemented in 0.9.9].
+#
+# Below are interleaved outputs from 'openssl speed rsa dsa' for 4
+# different software configurations on 1.5GHz VIA Esther processor.
+# Lines marked with "software integer" denote performance of hand-
+# coded integer-only assembler found in OpenSSL 0.9.7. "Software SSE2"
+# refers to hand-coded SSE2 Montgomery multiplication procedure found
+# OpenSSL 0.9.9. "Hardware VIA SDK" refers to padlock_pmm routine from
+# Padlock SDK 2.0.1 available for download from VIA, which naturally
+# utilizes the magic 'repz montmul' instruction. And finally "hardware
+# this" refers to *this* implementation which also uses 'repz montmul'
+#
+#                   sign    verify    sign/s verify/s
+# rsa  512 bits 0.001720s 0.000140s    581.4   7149.7  software integer
+# rsa  512 bits 0.000690s 0.000086s   1450.3  11606.0  software SSE2
+# rsa  512 bits 0.006136s 0.000201s    163.0   4974.5  hardware VIA SDK
+# rsa  512 bits 0.000712s 0.000050s   1404.9  19858.5  hardware this
+#
+# rsa 1024 bits 0.008518s 0.000413s    117.4   2420.8  software integer
+# rsa 1024 bits 0.004275s 0.000277s    233.9   3609.7  software SSE2
+# rsa 1024 bits 0.012136s 0.000260s     82.4   3844.5  hardware VIA SDK
+# rsa 1024 bits 0.002522s 0.000116s    396.5   8650.9  hardware this
+#
+# rsa 2048 bits 0.050101s 0.001371s     20.0    729.6  software integer
+# rsa 2048 bits 0.030273s 0.001008s     33.0    991.9  software SSE2
+# rsa 2048 bits 0.030833s 0.000976s     32.4   1025.1  hardware VIA SDK
+# rsa 2048 bits 0.011879s 0.000342s     84.2   2921.7  hardware this
+#
+# rsa 4096 bits 0.327097s 0.004859s      3.1    205.8  software integer
+# rsa 4096 bits 0.229318s 0.003859s      4.4    259.2  software SSE2
+# rsa 4096 bits 0.233953s 0.003274s      4.3    305.4  hardware VIA SDK
+# rsa 4096 bits 0.070493s 0.001166s     14.2    857.6  hardware this
+#
+# dsa  512 bits 0.001342s 0.001651s    745.2    605.7  software integer
+# dsa  512 bits 0.000844s 0.000987s   1185.3   1013.1  software SSE2
+# dsa  512 bits 0.001902s 0.002247s    525.6    444.9  hardware VIA SDK
+# dsa  512 bits 0.000458s 0.000524s   2182.2   1909.1  hardware this
+#
+# dsa 1024 bits 0.003964s 0.004926s    252.3    203.0  software integer
+# dsa 1024 bits 0.002686s 0.003166s    372.3    315.8  software SSE2
+# dsa 1024 bits 0.002397s 0.002823s    417.1    354.3  hardware VIA SDK
+# dsa 1024 bits 0.000978s 0.001170s   1022.2    855.0  hardware this
+#
+# dsa 2048 bits 0.013280s 0.016518s     75.3     60.5  software integer
+# dsa 2048 bits 0.009911s 0.011522s    100.9     86.8  software SSE2
+# dsa 2048 bits 0.009542s 0.011763s    104.8     85.0  hardware VIA SDK
+# dsa 2048 bits 0.002884s 0.003352s    346.8    298.3  hardware this
+#
+# To give you some other reference point here is output for 2.4GHz P4
+# running hand-coded SSE2 bn_mul_mont found in 0.9.9, i.e. "software
+# SSE2" in above terms.
+#
+# rsa  512 bits 0.000407s 0.000047s   2454.2  21137.0
+# rsa 1024 bits 0.002426s 0.000141s    412.1   7100.0
+# rsa 2048 bits 0.015046s 0.000491s     66.5   2034.9
+# rsa 4096 bits 0.109770s 0.002379s      9.1    420.3
+# dsa  512 bits 0.000438s 0.000525s   2281.1   1904.1
+# dsa 1024 bits 0.001346s 0.001595s    742.7    627.0
+# dsa 2048 bits 0.004745s 0.005582s    210.7    179.1
+#
+# Conclusions: 
+# - VIA SDK leaves a *lot* of room for improvement (which this
+#   implementation successfully fills:-);
+# - 'rep montmul' gives up to >3x performance improvement depending on
+#   key length;
+# - in terms of absolute performance it delivers approximately as much
+#   as modern out-of-order 32-bit cores [again, for longer keys].
+
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+push(@INC,"${dir}","${dir}../../perlasm");
+require "x86asm.pl";
+
+&asm_init($ARGV[0],"via-mont.pl");
+
+# int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np,const BN_ULONG *n0, int num);
+$func="bn_mul_mont_padlock";
+
+$pad=16*1;     # amount of reserved bytes on top of every vector
+
+# stack layout
+$mZeroPrime=&DWP(0,"esp");             # these are specified by VIA
+$A=&DWP(4,"esp");
+$B=&DWP(8,"esp");
+$T=&DWP(12,"esp");
+$M=&DWP(16,"esp");
+$scratch=&DWP(20,"esp");
+$rp=&DWP(24,"esp");                    # these are mine
+$sp=&DWP(28,"esp");
+# &DWP(32,"esp")                       # 32 byte scratch area
+# &DWP(64+(4*$num+$pad)*0,"esp")       # padded tp[num]
+# &DWP(64+(4*$num+$pad)*1,"esp")       # padded copy of ap[num]
+# &DWP(64+(4*$num+$pad)*2,"esp")       # padded copy of bp[num]
+# &DWP(64+(4*$num+$pad)*3,"esp")       # padded copy of np[num]
+# Note that SDK suggests to unconditionally allocate 2K per vector. This
+# has quite an impact on performance. It naturally depends on key length,
+# but to give an example 1024 bit private RSA key operations suffer >30%
+# penalty. I allocate only as much as actually required...
+
+&function_begin($func);
+       &xor    ("eax","eax");
+       &mov    ("ecx",&wparam(5));     # num
+       # meet VIA's limitations for num [note that the specification
+       # expresses them in bits, while we work with amount of 32-bit words]
+       &test   ("ecx",3);
+       &jnz    (&label("leave"));      # num % 4 != 0
+       &cmp    ("ecx",8);
+       &jb     (&label("leave"));      # num < 8
+       &cmp    ("ecx",1024);
+       &ja     (&label("leave"));      # num > 1024
+
+       &pushf  ();
+       &cld    ();
+
+       &mov    ("edi",&wparam(0));     # rp
+       &mov    ("eax",&wparam(1));     # ap
+       &mov    ("ebx",&wparam(2));     # bp
+       &mov    ("edx",&wparam(3));     # np
+       &mov    ("esi",&wparam(4));     # n0
+       &mov    ("esi",&DWP(0,"esi"));  # *n0
+
+       &lea    ("ecx",&DWP($pad,"","ecx",4));  # ecx becomes vector size in bytes
+       &lea    ("ebp",&DWP(64,"","ecx",4));    # allocate 4 vectors + 64 bytes
+       &neg    ("ebp");
+       &add    ("ebp","esp");
+       &and    ("ebp",-64);            # align to cache-line
+       &xchg   ("ebp","esp");          # alloca
+
+       &mov    ($rp,"edi");            # save rp
+       &mov    ($sp,"ebp");            # save esp
+
+       &mov    ($mZeroPrime,"esi");
+       &lea    ("esi",&DWP(64,"esp")); # tp
+       &mov    ($T,"esi");
+       &lea    ("edi",&DWP(32,"esp")); # scratch area
+       &mov    ($scratch,"edi");
+       &mov    ("esi","eax");
+
+       &lea    ("ebp",&DWP(-$pad,"ecx"));
+       &shr    ("ebp",2);              # restore original num value in ebp
+
+       &xor    ("eax","eax");
+
+       &mov    ("ecx","ebp");
+       &lea    ("ecx",&DWP((32+$pad)/4,"ecx"));# padded tp + scratch
+       &data_byte(0xf3,0xab);          # rep stosl, bzero
+
+       &mov    ("ecx","ebp");
+       &lea    ("edi",&DWP(64+$pad,"esp","ecx",4));# pointer to ap copy
+       &mov    ($A,"edi");
+       &data_byte(0xf3,0xa5);          # rep movsl, memcpy
+       &mov    ("ecx",$pad/4);
+       &data_byte(0xf3,0xab);          # rep stosl, bzero pad
+       # edi points at the end of padded ap copy...
+
+       &mov    ("ecx","ebp");
+       &mov    ("esi","ebx");
+       &mov    ($B,"edi");
+       &data_byte(0xf3,0xa5);          # rep movsl, memcpy
+       &mov    ("ecx",$pad/4);
+       &data_byte(0xf3,0xab);          # rep stosl, bzero pad
+       # edi points at the end of padded bp copy...
+
+       &mov    ("ecx","ebp");
+       &mov    ("esi","edx");
+       &mov    ($M,"edi");
+       &data_byte(0xf3,0xa5);          # rep movsl, memcpy
+       &mov    ("ecx",$pad/4);
+       &data_byte(0xf3,0xab);          # rep stosl, bzero pad
+       # edi points at the end of padded np copy...
+
+       # let magic happen...
+       &mov    ("ecx","ebp");
+       &mov    ("esi","esp");
+       &shl    ("ecx",5);              # convert word counter to bit counter
+       &align  (4);
+       &data_byte(0xf3,0x0f,0xa6,0xc0);# rep montmul
+
+       &mov    ("ecx","ebp");
+       &lea    ("esi",&DWP(64,"esp"));         # tp
+       # edi still points at the end of padded np copy...
+       &neg    ("ebp");
+       &lea    ("ebp",&DWP(-$pad,"edi","ebp",4));      # so just "rewind"
+       &mov    ("edi",$rp);                    # restore rp
+       &xor    ("edx","edx");                  # i=0 and clear CF
+
+&set_label("sub",8);
+       &mov    ("eax",&DWP(0,"esi","edx",4));
+       &sbb    ("eax",&DWP(0,"ebp","edx",4));
+       &mov    (&DWP(0,"edi","edx",4),"eax");  # rp[i]=tp[i]-np[i]
+       &lea    ("edx",&DWP(1,"edx"));          # i++
+       &loop   (&label("sub"));                # doesn't affect CF!
+
+       &mov    ("eax",&DWP(0,"esi","edx",4));  # upmost overflow bit
+       &sbb    ("eax",0);
+       &and    ("esi","eax");
+       &not    ("eax");
+       &mov    ("ebp","edi");
+       &and    ("ebp","eax");
+       &or     ("esi","ebp");                  # tp=carry?tp:rp
+
+       &mov    ("ecx","edx");                  # num
+       &xor    ("edx","edx");                  # i=0
+
+&set_label("copy",8);
+       &mov    ("eax",&DWP(0,"esi","edx",4));
+       &mov    (&DWP(64,"esp","edx",4),"ecx"); # zap tp
+       &mov    (&DWP(0,"edi","edx",4),"eax");
+       &lea    ("edx",&DWP(1,"edx"));          # i++
+       &loop   (&label("copy"));
+
+       &mov    ("ebp",$sp);
+       &xor    ("eax","eax");
+
+       &mov    ("ecx",64/4);
+       &mov    ("edi","esp");          # zap frame including scratch area
+       &data_byte(0xf3,0xab);          # rep stosl, bzero
+
+       # zap copies of ap, bp and np
+       &lea    ("edi",&DWP(64+$pad,"esp","edx",4));# pointer to ap
+       &lea    ("ecx",&DWP(3*$pad/4,"edx","edx",2));
+       &data_byte(0xf3,0xab);          # rep stosl, bzero
+
+       &mov    ("esp","ebp");
+       &inc    ("eax");                # signal "done"
+       &popf   ();
+&set_label("leave");
+&function_end($func);
+
+&asciz("Padlock Montgomery Multiplication, CRYPTOGAMS by <appro\@openssl.org>");
+
+&asm_finish();
@@ -1,18 +1,5 @@
 #!/usr/bin/env perl
 
-# This is crypto/bn/asm/x86-mont.pl (with asciz from crypto/perlasm/x86asm.pl)
-# from OpenSSL 0.9.9-dev 
-
-sub ::asciz
-{ my @str=unpack("C*",shift);
-    push @str,0;
-    while ($#str>15) {
-       &data_byte(@str[0..15]);
-       foreach (0..15) { shift @str; }
-    }
-    &data_byte(@str) if (@str);
-}
-
 # ====================================================================
 # Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
 # project. The module is, however, dual licensed under OpenSSL and
@@ -39,7 +26,8 @@ sub ::asciz
 # Integer-only code [being equipped with dedicated squaring procedure]
 # gives ~40% on rsa512 sign benchmark...
 
-push(@INC,"perlasm","../../perlasm");
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+push(@INC,"${dir}","${dir}../../perlasm");
 require "x86asm.pl";
 
 &asm_init($ARGV[0],$0);
@@ -539,8 +527,10 @@ $sbit=$num;
        &jle    (&label("sqradd"));
 
        &mov    ($carry,"edx");
-       &lea    ("edx",&DWP(0,$sbit,"edx",2));
+       &add    ("edx","edx");
        &shr    ($carry,31);
+       &add    ("edx",$sbit);
+       &adc    ($carry,0);
 &set_label("sqrlast");
        &mov    ($word,$_n0);
        &mov    ($inp,$_np);
index b1b8a11..acb0b40 100644 (file)
@@ -1,5 +1,5 @@
 #include "../bn_lcl.h"
-#ifdef __SUNPRO_C
+#if !(defined(__GNUC__) && __GNUC__>=2)
 # include "../bn_asm.c"        /* kind of dirty hack for Sun Studio */
 #else
 /*
  *    machine.
  */
 
+#ifdef _WIN64
+#define BN_ULONG unsigned long long
+#else
 #define BN_ULONG unsigned long
+#endif
 
 #undef mul
 #undef mul_add
@@ -187,7 +191,7 @@ BN_ULONG bn_add_words (BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int
 
        asm (
        "       subq    %2,%2           \n"
-       ".align 16                      \n"
+       ".p2align 4                     \n"
        "1:     movq    (%4,%2,8),%0    \n"
        "       adcq    (%5,%2,8),%0    \n"
        "       movq    %0,(%3,%2,8)    \n"
@@ -210,7 +214,7 @@ BN_ULONG bn_sub_words (BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int
 
        asm (
        "       subq    %2,%2           \n"
-       ".align 16                      \n"
+       ".p2align 4                     \n"
        "1:     movq    (%4,%2,8),%0    \n"
        "       sbbq    (%5,%2,8),%0    \n"
        "       movq    %0,(%3,%2,8)    \n"
index c43b695..3b7a6f2 100755 (executable)
 # respectful 50%. It remains to be seen if loop unrolling and
 # dedicated squaring routine can provide further improvement...
 
-$output=shift;
+$flavour = shift;
+$output  = shift;
+if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
+
+$win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
 
 $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
 ( $xlate="${dir}x86_64-xlate.pl" and -f $xlate ) or
 ( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
 die "can't locate x86_64-xlate.pl";
 
-open STDOUT,"| $^X $xlate $output";
+open STDOUT,"| $^X $xlate $flavour $output";
 
 # int bn_mul_mont(
 $rp="%rdi";    # BN_ULONG *rp,
@@ -55,13 +59,14 @@ bn_mul_mont:
        push    %r15
 
        mov     ${num}d,${num}d
-       lea     2($num),%rax
-       mov     %rsp,%rbp
-       neg     %rax
-       lea     (%rsp,%rax,8),%rsp      # tp=alloca(8*(num+2))
+       lea     2($num),%r10
+       mov     %rsp,%r11
+       neg     %r10
+       lea     (%rsp,%r10,8),%rsp      # tp=alloca(8*(num+2))
        and     \$-1024,%rsp            # minimize TLB usage
 
-       mov     %rbp,8(%rsp,$num,8)     # tp[num+1]=%rsp
+       mov     %r11,8(%rsp,$num,8)     # tp[num+1]=%rsp
+.Lprologue:
        mov     %rdx,$bp                # $bp reassigned, remember?
 
        mov     ($n0),$n0               # pull n0[0] value
@@ -197,18 +202,129 @@ bn_mul_mont:
        dec     $j
        jge     .Lcopy
 
-       mov     8(%rsp,$num,8),%rsp     # restore %rsp
+       mov     8(%rsp,$num,8),%rsi     # restore %rsp
        mov     \$1,%rax
+       mov     (%rsi),%r15
+       mov     8(%rsi),%r14
+       mov     16(%rsi),%r13
+       mov     24(%rsi),%r12
+       mov     32(%rsi),%rbp
+       mov     40(%rsi),%rbx
+       lea     48(%rsi),%rsp
+.Lepilogue:
+       ret
+.size  bn_mul_mont,.-bn_mul_mont
+.asciz "Montgomery Multiplication for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
+.align 16
+___
+
+# EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
+#              CONTEXT *context,DISPATCHER_CONTEXT *disp)
+if ($win64) {
+$rec="%rcx";
+$frame="%rdx";
+$context="%r8";
+$disp="%r9";
+
+$code.=<<___;
+.extern        __imp_RtlVirtualUnwind
+.type  se_handler,\@abi-omnipotent
+.align 16
+se_handler:
+       push    %rsi
+       push    %rdi
+       push    %rbx
+       push    %rbp
+       push    %r12
+       push    %r13
+       push    %r14
+       push    %r15
+       pushfq
+       sub     \$64,%rsp
+
+       mov     120($context),%rax      # pull context->Rax
+       mov     248($context),%rbx      # pull context->Rip
+
+       lea     .Lprologue(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip<.Lprologue
+       jb      .Lin_prologue
+
+       mov     152($context),%rax      # pull context->Rsp
+
+       lea     .Lepilogue(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip>=.Lepilogue
+       jae     .Lin_prologue
+
+       mov     192($context),%r10      # pull $num
+       mov     8(%rax,%r10,8),%rax     # pull saved stack pointer
+       lea     48(%rax),%rax
+
+       mov     -8(%rax),%rbx
+       mov     -16(%rax),%rbp
+       mov     -24(%rax),%r12
+       mov     -32(%rax),%r13
+       mov     -40(%rax),%r14
+       mov     -48(%rax),%r15
+       mov     %rbx,144($context)      # restore context->Rbx
+       mov     %rbp,160($context)      # restore context->Rbp
+       mov     %r12,216($context)      # restore context->R12
+       mov     %r13,224($context)      # restore context->R13
+       mov     %r14,232($context)      # restore context->R14
+       mov     %r15,240($context)      # restore context->R15
+
+.Lin_prologue:
+       mov     8(%rax),%rdi
+       mov     16(%rax),%rsi
+       mov     %rax,152($context)      # restore context->Rsp
+       mov     %rsi,168($context)      # restore context->Rsi
+       mov     %rdi,176($context)      # restore context->Rdi
+
+       mov     40($disp),%rdi          # disp->ContextRecord
+       mov     $context,%rsi           # context
+       mov     \$154,%ecx              # sizeof(CONTEXT)
+       .long   0xa548f3fc              # cld; rep movsq
+
+       mov     $disp,%rsi
+       xor     %rcx,%rcx               # arg1, UNW_FLAG_NHANDLER
+       mov     8(%rsi),%rdx            # arg2, disp->ImageBase
+       mov     0(%rsi),%r8             # arg3, disp->ControlPc
+       mov     16(%rsi),%r9            # arg4, disp->FunctionEntry
+       mov     40(%rsi),%r10           # disp->ContextRecord
+       lea     56(%rsi),%r11           # &disp->HandlerData
+       lea     24(%rsi),%r12           # &disp->EstablisherFrame
+       mov     %r10,32(%rsp)           # arg5
+       mov     %r11,40(%rsp)           # arg6
+       mov     %r12,48(%rsp)           # arg7
+       mov     %rcx,56(%rsp)           # arg8, (NULL)
+       call    *__imp_RtlVirtualUnwind(%rip)
+
+       mov     \$1,%eax                # ExceptionContinueSearch
+       add     \$64,%rsp
+       popfq
        pop     %r15
        pop     %r14
        pop     %r13
        pop     %r12
        pop     %rbp
        pop     %rbx
+       pop     %rdi
+       pop     %rsi
        ret
-.size  bn_mul_mont,.-bn_mul_mont
-.asciz "Montgomery Multiplication for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
+.size  se_handler,.-se_handler
+
+.section       .pdata
+.align 4
+       .rva    .LSEH_begin_bn_mul_mont
+       .rva    .LSEH_end_bn_mul_mont
+       .rva    .LSEH_info_bn_mul_mont
+
+.section       .xdata
+.align 8
+.LSEH_info_bn_mul_mont:
+       .byte   9,0,0,0
+       .rva    se_handler
 ___
+}
 
 print $code;
 close STDOUT;
index f1719a5..a0bc478 100644 (file)
  * [including the GNU Public Licence.]
  */
 /* ====================================================================
+ * Copyright (c) 1998-2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    openssl-core@openssl.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+/* ====================================================================
  * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
  *
  * Portions of the attached software ("Contribution") are developed by 
 #include <stdio.h> /* FILE */
 #endif
 #include <openssl/ossl_typ.h>
+#include <openssl/crypto.h>
 
 #ifdef  __cplusplus
 extern "C" {
@@ -94,9 +148,11 @@ extern "C" {
 /* #define BN_DEBUG */
 /* #define BN_DEBUG_RAND */
 
+#ifndef OPENSSL_SMALL_FOOTPRINT
 #define BN_MUL_COMBA
 #define BN_SQR_COMBA
 #define BN_RECURSION
+#endif
 
 /* This next option uses the C libraries (2 word)/(1 word) function.
  * If it is not defined, I use my C version (which is slower).
@@ -137,6 +193,8 @@ extern "C" {
 #define BN_DEC_FMT1    "%lu"
 #define BN_DEC_FMT2    "%019lu"
 #define BN_DEC_NUM     19
+#define BN_HEX_FMT1    "%lX"
+#define BN_HEX_FMT2    "%016lX"
 #endif
 
 /* This is where the long long data type is 64 bits, but long is 32.
@@ -162,84 +220,56 @@ extern "C" {
 #define BN_DEC_FMT1    "%llu"
 #define BN_DEC_FMT2    "%019llu"
 #define BN_DEC_NUM     19
+#define BN_HEX_FMT1    "%llX"
+#define BN_HEX_FMT2    "%016llX"
 #endif
 
 #ifdef THIRTY_TWO_BIT
 #ifdef BN_LLONG
-# if defined(OPENSSL_SYS_WIN32) && !defined(__GNUC__)
+# if defined(_WIN32) && !defined(__GNUC__)
 #  define BN_ULLONG    unsigned __int64
+#  define BN_MASK      (0xffffffffffffffffI64)
 # else
 #  define BN_ULLONG    unsigned long long
+#  define BN_MASK      (0xffffffffffffffffLL)
 # endif
 #endif
-#define BN_ULONG       unsigned long
-#define BN_LONG                long
+#define BN_ULONG       unsigned int
+#define BN_LONG                int
 #define BN_BITS                64
 #define BN_BYTES       4
 #define BN_BITS2       32
 #define BN_BITS4       16
-#ifdef OPENSSL_SYS_WIN32
-/* VC++ doesn't like the LL suffix */
-#define BN_MASK                (0xffffffffffffffffL)
-#else
-#define BN_MASK                (0xffffffffffffffffLL)
-#endif
 #define BN_MASK2       (0xffffffffL)
 #define BN_MASK2l      (0xffff)
 #define BN_MASK2h1     (0xffff8000L)
 #define BN_MASK2h      (0xffff0000L)
 #define BN_TBIT                (0x80000000L)
 #define BN_DEC_CONV    (1000000000L)
-#define BN_DEC_FMT1    "%lu"
-#define BN_DEC_FMT2    "%09lu"
-#define BN_DEC_NUM     9
-#endif
-
-#ifdef SIXTEEN_BIT
-#ifndef BN_DIV2W
-#define BN_DIV2W
-#endif
-#define BN_ULLONG      unsigned long
-#define BN_ULONG       unsigned short
-#define BN_LONG                short
-#define BN_BITS                32
-#define BN_BYTES       2
-#define BN_BITS2       16
-#define BN_BITS4       8
-#define BN_MASK                (0xffffffff)
-#define BN_MASK2       (0xffff)
-#define BN_MASK2l      (0xff)
-#define BN_MASK2h1     (0xff80)
-#define BN_MASK2h      (0xff00)
-#define BN_TBIT                (0x8000)
-#define BN_DEC_CONV    (100000)
 #define BN_DEC_FMT1    "%u"
-#define BN_DEC_FMT2    "%05u"
-#define BN_DEC_NUM     5
+#define BN_DEC_FMT2    "%09u"
+#define BN_DEC_NUM     9
+#define BN_HEX_FMT1    "%X"
+#define BN_HEX_FMT2    "%08X"
 #endif
 
-#ifdef EIGHT_BIT
-#ifndef BN_DIV2W
-#define BN_DIV2W
-#endif
-#define BN_ULLONG      unsigned short
-#define BN_ULONG       unsigned char
-#define BN_LONG                char
-#define BN_BITS                16
-#define BN_BYTES       1
-#define BN_BITS2       8
-#define BN_BITS4       4
-#define BN_MASK                (0xffff)
-#define BN_MASK2       (0xff)
-#define BN_MASK2l      (0xf)
-#define BN_MASK2h1     (0xf8)
-#define BN_MASK2h      (0xf0)
-#define BN_TBIT                (0x80)
-#define BN_DEC_CONV    (100)
-#define BN_DEC_FMT1    "%u"
-#define BN_DEC_FMT2    "%02u"
-#define BN_DEC_NUM     2
-#endif
+/* 2011-02-22 SMS.
+ * In various places, a size_t variable or a type cast to size_t was
+ * used to perform integer-only operations on pointers.  This failed on
+ * VMS with 64-bit pointers (CC /POINTER_SIZE = 64) because size_t is
+ * still only 32 bits.  What's needed in these cases is an integer type
+ * with the same size as a pointer, which size_t is not certain to be. 
+ * The only fix here is VMS-specific.
+ */
+#if defined(OPENSSL_SYS_VMS)
+# if __INITIAL_POINTER_SIZE == 64
+#  define PTR_SIZE_INT long long
+# else /* __INITIAL_POINTER_SIZE == 64 */
+#  define PTR_SIZE_INT int
+# endif /* __INITIAL_POINTER_SIZE == 64 [else] */
+#else /* defined(OPENSSL_SYS_VMS) */
+# define PTR_SIZE_INT size_t
+#endif /* defined(OPENSSL_SYS_VMS) [else] */
 
 #define BN_DEFAULT_BITS        1280
 
@@ -303,12 +333,8 @@ struct bn_mont_ctx_st
        BIGNUM N;      /* The modulus */
        BIGNUM Ni;     /* R*(1/R mod N) - N*Ni = 1
                        * (Ni is only stored for bignum algorithm) */
-#if 0
-       /* OpenSSL 0.9.9 preview: */
-       BN_ULONG n0[2];/* least significant word(s) of Ni */
-#else
-       BN_ULONG n0;   /* least significant word of Ni */
-#endif
+       BN_ULONG n0[2];/* least significant word(s) of Ni;
+                         (type changed with 0.9.9, was "BN_ULONG n0;" before) */
        int flags;
        };
 
@@ -504,6 +530,7 @@ char *      BN_bn2hex(const BIGNUM *a);
 char * BN_bn2dec(const BIGNUM *a);
 int    BN_hex2bn(BIGNUM **a, const char *str);
 int    BN_dec2bn(BIGNUM **a, const char *str);
+int    BN_asc2bn(BIGNUM **a, const char *str);
 int    BN_gcd(BIGNUM *r,const BIGNUM *a,const BIGNUM *b,BN_CTX *ctx);
 int    BN_kronecker(const BIGNUM *a,const BIGNUM *b,BN_CTX *ctx); /* returns -2 for error */
 BIGNUM *BN_mod_inverse(BIGNUM *ret,
@@ -531,17 +558,6 @@ int        BN_is_prime_ex(const BIGNUM *p,int nchecks, BN_CTX *ctx, BN_GENCB *cb);
 int    BN_is_prime_fasttest_ex(const BIGNUM *p,int nchecks, BN_CTX *ctx,
                int do_trial_division, BN_GENCB *cb);
 
-int BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx);
-
-int BN_X931_derive_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2,
-                       const BIGNUM *Xp, const BIGNUM *Xp1, const BIGNUM *Xp2,
-                       const BIGNUM *e, BN_CTX *ctx, BN_GENCB *cb);
-int BN_X931_generate_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2,
-                       BIGNUM *Xp1, BIGNUM *Xp2,
-                       const BIGNUM *Xp,
-                       const BIGNUM *e, BN_CTX *ctx,
-                       BN_GENCB *cb);
-
 BN_MONT_CTX *BN_MONT_CTX_new(void );
 void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
 int BN_mod_mul_montgomery(BIGNUM *r,const BIGNUM *a,const BIGNUM *b,
@@ -560,19 +576,22 @@ BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock,
 #define        BN_BLINDING_NO_UPDATE   0x00000001
 #define        BN_BLINDING_NO_RECREATE 0x00000002
 
-BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, /* const */ BIGNUM *mod);
+BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, BIGNUM *mod);
 void BN_BLINDING_free(BN_BLINDING *b);
 int BN_BLINDING_update(BN_BLINDING *b,BN_CTX *ctx);
 int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
 int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
 int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, BN_CTX *);
 int BN_BLINDING_invert_ex(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b, BN_CTX *);
+#ifndef OPENSSL_NO_DEPRECATED
 unsigned long BN_BLINDING_get_thread_id(const BN_BLINDING *);
 void BN_BLINDING_set_thread_id(BN_BLINDING *, unsigned long);
+#endif
+CRYPTO_THREADID *BN_BLINDING_thread_id(BN_BLINDING *);
 unsigned long BN_BLINDING_get_flags(const BN_BLINDING *);
 void BN_BLINDING_set_flags(BN_BLINDING *, unsigned long);
 BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b,
-       const BIGNUM *e, /* const */ BIGNUM *m, BN_CTX *ctx,
+       const BIGNUM *e, BIGNUM *m, BN_CTX *ctx,
        int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
                          const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx),
        BN_MONT_CTX *m_ctx);
@@ -625,24 +644,24 @@ int       BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
  *     t^p[0] + t^p[1] + ... + t^p[k]
  * where m = p[0] > p[1] > ... > p[k] = 0.
  */
-int    BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[]);
+int    BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const int p[]);
        /* r = a mod p */
 int    BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
-       const unsigned int p[], BN_CTX *ctx); /* r = (a * b) mod p */
-int    BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[],
+       const int p[], BN_CTX *ctx); /* r = (a * b) mod p */
+int    BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[],
        BN_CTX *ctx); /* r = (a * a) mod p */
-int    BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *b, const unsigned int p[],
+int    BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *b, const int p[],
        BN_CTX *ctx); /* r = (1 / b) mod p */
 int    BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
-       const unsigned int p[], BN_CTX *ctx); /* r = (a / b) mod p */
+       const int p[], BN_CTX *ctx); /* r = (a / b) mod p */
 int    BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
-       const unsigned int p[], BN_CTX *ctx); /* r = (a ^ b) mod p */
+       const int p[], BN_CTX *ctx); /* r = (a ^ b) mod p */
 int    BN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a,
-       const unsigned int p[], BN_CTX *ctx); /* r = sqrt(a) mod p */
+       const int p[], BN_CTX *ctx); /* r = sqrt(a) mod p */
 int    BN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a,
-       const unsigned int p[], BN_CTX *ctx); /* r^2 + r = a mod p */
-int    BN_GF2m_poly2arr(const BIGNUM *a, unsigned int p[], int max);
-int    BN_GF2m_arr2poly(const unsigned int p[], BIGNUM *a);
+       const int p[], BN_CTX *ctx); /* r^2 + r = a mod p */
+int    BN_GF2m_poly2arr(const BIGNUM *a, int p[], int max);
+int    BN_GF2m_arr2poly(const int p[], BIGNUM *a);
 
 /* faster mod functions for the 'NIST primes' 
  * 0 <= a < p^2 */
@@ -751,10 +770,12 @@ int RAND_pseudo_bytes(unsigned char *buf,int num);
 #define bn_correct_top(a) \
         { \
         BN_ULONG *ftl; \
-       if ((a)->top > 0) \
+       int tmp_top = (a)->top; \
+       if (tmp_top > 0) \
                { \
-               for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \
-               if (*(ftl--)) break; \
+               for (ftl= &((a)->d[tmp_top-1]); tmp_top > 0; tmp_top--) \
+                       if (*(ftl--)) break; \
+               (a)->top = tmp_top; \
                } \
        bn_pollute(a); \
        }
index 99bc2de..c43c91c 100644 (file)
@@ -75,6 +75,7 @@ BN_ULONG bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w)
        assert(num >= 0);
        if (num <= 0) return(c1);
 
+#ifndef OPENSSL_SMALL_FOOTPRINT
        while (num&~3)
                {
                mul_add(rp[0],ap[0],w,c1);
@@ -83,11 +84,11 @@ BN_ULONG bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w)
                mul_add(rp[3],ap[3],w,c1);
                ap+=4; rp+=4; num-=4;
                }
-       if (num)
+#endif
+       while (num)
                {
-               mul_add(rp[0],ap[0],w,c1); if (--num==0) return c1;
-               mul_add(rp[1],ap[1],w,c1); if (--num==0) return c1;
-               mul_add(rp[2],ap[2],w,c1); return c1;
+               mul_add(rp[0],ap[0],w,c1);
+               ap++; rp++; num--;
                }
        
        return(c1);
@@ -100,6 +101,7 @@ BN_ULONG bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w)
        assert(num >= 0);
        if (num <= 0) return(c1);
 
+#ifndef OPENSSL_SMALL_FOOTPRINT
        while (num&~3)
                {
                mul(rp[0],ap[0],w,c1);
@@ -108,11 +110,11 @@ BN_ULONG bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w)
                mul(rp[3],ap[3],w,c1);
                ap+=4; rp+=4; num-=4;
                }
-       if (num)
+#endif
+       while (num)
                {
-               mul(rp[0],ap[0],w,c1); if (--num == 0) return c1;
-               mul(rp[1],ap[1],w,c1); if (--num == 0) return c1;
-               mul(rp[2],ap[2],w,c1);
+               mul(rp[0],ap[0],w,c1);
+               ap++; rp++; num--;
                }
        return(c1);
        } 
@@ -121,6 +123,8 @@ void bn_sqr_words(BN_ULONG *r, const BN_ULONG *a, int n)
         {
        assert(n >= 0);
        if (n <= 0) return;
+
+#ifndef OPENSSL_SMALL_FOOTPRINT
        while (n&~3)
                {
                sqr(r[0],r[1],a[0]);
@@ -129,11 +133,11 @@ void bn_sqr_words(BN_ULONG *r, const BN_ULONG *a, int n)
                sqr(r[6],r[7],a[3]);
                a+=4; r+=8; n-=4;
                }
-       if (n)
+#endif
+       while (n)
                {
-               sqr(r[0],r[1],a[0]); if (--n == 0) return;
-               sqr(r[2],r[3],a[1]); if (--n == 0) return;
-               sqr(r[4],r[5],a[2]);
+               sqr(r[0],r[1],a[0]);
+               a++; r+=2; n--;
                }
        }
 
@@ -150,18 +154,20 @@ BN_ULONG bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w)
        bl=LBITS(w);
        bh=HBITS(w);
 
-       for (;;)
+#ifndef OPENSSL_SMALL_FOOTPRINT
+       while (num&~3)
                {
                mul_add(rp[0],ap[0],bl,bh,c);
-               if (--num == 0) break;
                mul_add(rp[1],ap[1],bl,bh,c);
-               if (--num == 0) break;
                mul_add(rp[2],ap[2],bl,bh,c);
-               if (--num == 0) break;
                mul_add(rp[3],ap[3],bl,bh,c);
-               if (--num == 0) break;
-               ap+=4;
-               rp+=4;
+               ap+=4; rp+=4; num-=4;
+               }
+#endif
+       while (num)
+               {
+               mul_add(rp[0],ap[0],bl,bh,c);
+               ap++; rp++; num--;
                }
        return(c);
        } 
@@ -177,18 +183,20 @@ BN_ULONG bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w)
        bl=LBITS(w);
        bh=HBITS(w);
 
-       for (;;)
+#ifndef OPENSSL_SMALL_FOOTPRINT
+       while (num&~3)
                {
                mul(rp[0],ap[0],bl,bh,carry);
-               if (--num == 0) break;
                mul(rp[1],ap[1],bl,bh,carry);
-               if (--num == 0) break;
                mul(rp[2],ap[2],bl,bh,carry);
-               if (--num == 0) break;
                mul(rp[3],ap[3],bl,bh,carry);
-               if (--num == 0) break;
-               ap+=4;
-               rp+=4;
+               ap+=4; rp+=4; num-=4;
+               }
+#endif
+       while (num)
+               {
+               mul(rp[0],ap[0],bl,bh,carry);
+               ap++; rp++; num--;
                }
        return(carry);
        } 
@@ -197,22 +205,21 @@ void bn_sqr_words(BN_ULONG *r, const BN_ULONG *a, int n)
         {
        assert(n >= 0);
        if (n <= 0) return;
-       for (;;)
+
+#ifndef OPENSSL_SMALL_FOOTPRINT
+       while (n&~3)
                {
                sqr64(r[0],r[1],a[0]);
-               if (--n == 0) break;
-
                sqr64(r[2],r[3],a[1]);
-               if (--n == 0) break;
-
                sqr64(r[4],r[5],a[2]);
-               if (--n == 0) break;
-
                sqr64(r[6],r[7],a[3]);
-               if (--n == 0) break;
-
-               a+=4;
-               r+=8;
+               a+=4; r+=8; n-=4;
+               }
+#endif
+       while (n)
+               {
+               sqr64(r[0],r[1],a[0]);
+               a++; r+=2; n--;
                }
        }
 
@@ -303,31 +310,30 @@ BN_ULONG bn_add_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)
        assert(n >= 0);
        if (n <= 0) return((BN_ULONG)0);
 
-       for (;;)
+#ifndef OPENSSL_SMALL_FOOTPRINT
+       while (n&~3)
                {
                ll+=(BN_ULLONG)a[0]+b[0];
                r[0]=(BN_ULONG)ll&BN_MASK2;
                ll>>=BN_BITS2;
-               if (--n <= 0) break;
-
                ll+=(BN_ULLONG)a[1]+b[1];
                r[1]=(BN_ULONG)ll&BN_MASK2;
                ll>>=BN_BITS2;
-               if (--n <= 0) break;
-
                ll+=(BN_ULLONG)a[2]+b[2];
                r[2]=(BN_ULONG)ll&BN_MASK2;
                ll>>=BN_BITS2;
-               if (--n <= 0) break;
-
                ll+=(BN_ULLONG)a[3]+b[3];
                r[3]=(BN_ULONG)ll&BN_MASK2;
                ll>>=BN_BITS2;
-               if (--n <= 0) break;
-
-               a+=4;
-               b+=4;
-               r+=4;
+               a+=4; b+=4; r+=4; n-=4;
+               }
+#endif
+       while (n)
+               {
+               ll+=(BN_ULLONG)a[0]+b[0];
+               r[0]=(BN_ULONG)ll&BN_MASK2;
+               ll>>=BN_BITS2;
+               a++; b++; r++; n--;
                }
        return((BN_ULONG)ll);
        }
@@ -340,7 +346,8 @@ BN_ULONG bn_add_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)
        if (n <= 0) return((BN_ULONG)0);
 
        c=0;
-       for (;;)
+#ifndef OPENSSL_SMALL_FOOTPRINT
+       while (n&~3)
                {
                t=a[0];
                t=(t+c)&BN_MASK2;
@@ -348,35 +355,36 @@ BN_ULONG bn_add_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)
                l=(t+b[0])&BN_MASK2;
                c+=(l < t);
                r[0]=l;
-               if (--n <= 0) break;
-
                t=a[1];
                t=(t+c)&BN_MASK2;
                c=(t < c);
                l=(t+b[1])&BN_MASK2;
                c+=(l < t);
                r[1]=l;
-               if (--n <= 0) break;
-
                t=a[2];
                t=(t+c)&BN_MASK2;
                c=(t < c);
                l=(t+b[2])&BN_MASK2;
                c+=(l < t);
                r[2]=l;
-               if (--n <= 0) break;
-
                t=a[3];
                t=(t+c)&BN_MASK2;
                c=(t < c);
                l=(t+b[3])&BN_MASK2;
                c+=(l < t);
                r[3]=l;
-               if (--n <= 0) break;
-
-               a+=4;
-               b+=4;
-               r+=4;
+               a+=4; b+=4; r+=4; n-=4;
+               }
+#endif
+       while(n)
+               {
+               t=a[0];
+               t=(t+c)&BN_MASK2;
+               c=(t < c);
+               l=(t+b[0])&BN_MASK2;
+               c+=(l < t);
+               r[0]=l;
+               a++; b++; r++; n--;
                }
        return((BN_ULONG)c);
        }
@@ -390,36 +398,35 @@ BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)
        assert(n >= 0);
        if (n <= 0) return((BN_ULONG)0);
 
-       for (;;)
+#ifndef OPENSSL_SMALL_FOOTPRINT
+       while (n&~3)
                {
                t1=a[0]; t2=b[0];
                r[0]=(t1-t2-c)&BN_MASK2;
                if (t1 != t2) c=(t1 < t2);
-               if (--n <= 0) break;
-
                t1=a[1]; t2=b[1];
                r[1]=(t1-t2-c)&BN_MASK2;
                if (t1 != t2) c=(t1 < t2);
-               if (--n <= 0) break;
-
                t1=a[2]; t2=b[2];
                r[2]=(t1-t2-c)&BN_MASK2;
                if (t1 != t2) c=(t1 < t2);
-               if (--n <= 0) break;
-
                t1=a[3]; t2=b[3];
                r[3]=(t1-t2-c)&BN_MASK2;
                if (t1 != t2) c=(t1 < t2);
-               if (--n <= 0) break;
-
-               a+=4;
-               b+=4;
-               r+=4;
+               a+=4; b+=4; r+=4; n-=4;
+               }
+#endif
+       while (n)
+               {
+               t1=a[0]; t2=b[0];
+               r[0]=(t1-t2-c)&BN_MASK2;
+               if (t1 != t2) c=(t1 < t2);
+               a++; b++; r++; n--;
                }
        return(c);
        }
 
-#ifdef BN_MUL_COMBA
+#if defined(BN_MUL_COMBA) && !defined(OPENSSL_SMALL_FOOTPRINT)
 
 #undef bn_mul_comba8
 #undef bn_mul_comba4
@@ -820,18 +827,134 @@ void bn_sqr_comba4(BN_ULONG *r, const BN_ULONG *a)
        r[6]=c1;
        r[7]=c2;
        }
+
+#ifdef OPENSSL_NO_ASM
+#ifdef OPENSSL_BN_ASM_MONT
+#include <alloca.h>
+/*
+ * This is essentially reference implementation, which may or may not
+ * result in performance improvement. E.g. on IA-32 this routine was
+ * observed to give 40% faster rsa1024 private key operations and 10%
+ * faster rsa4096 ones, while on AMD64 it improves rsa1024 sign only
+ * by 10% and *worsens* rsa4096 sign by 15%. Once again, it's a
+ * reference implementation, one to be used as starting point for
+ * platform-specific assembler. Mentioned numbers apply to compiler
+ * generated code compiled with and without -DOPENSSL_BN_ASM_MONT and
+ * can vary not only from platform to platform, but even for compiler
+ * versions. Assembler vs. assembler improvement coefficients can
+ * [and are known to] differ and are to be documented elsewhere.
+ */
+int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np,const BN_ULONG *n0p, int num)
+       {
+       BN_ULONG c0,c1,ml,*tp,n0;
+#ifdef mul64
+       BN_ULONG mh;
+#endif
+       volatile BN_ULONG *vp;
+       int i=0,j;
+
+#if 0  /* template for platform-specific implementation */
+       if (ap==bp)     return bn_sqr_mont(rp,ap,np,n0p,num);
+#endif
+       vp = tp = alloca((num+2)*sizeof(BN_ULONG));
+
+       n0 = *n0p;
+
+       c0 = 0;
+       ml = bp[0];
+#ifdef mul64
+       mh = HBITS(ml);
+       ml = LBITS(ml);
+       for (j=0;j<num;++j)
+               mul(tp[j],ap[j],ml,mh,c0);
+#else
+       for (j=0;j<num;++j)
+               mul(tp[j],ap[j],ml,c0);
+#endif
+
+       tp[num]   = c0;
+       tp[num+1] = 0;
+       goto enter;
+
+       for(i=0;i<num;i++)
+               {
+               c0 = 0;
+               ml = bp[i];
+#ifdef mul64
+               mh = HBITS(ml);
+               ml = LBITS(ml);
+               for (j=0;j<num;++j)
+                       mul_add(tp[j],ap[j],ml,mh,c0);
+#else
+               for (j=0;j<num;++j)
+                       mul_add(tp[j],ap[j],ml,c0);
+#endif
+               c1 = (tp[num] + c0)&BN_MASK2;
+               tp[num]   = c1;
+               tp[num+1] = (c1<c0?1:0);
+       enter:
+               c1  = tp[0];
+               ml = (c1*n0)&BN_MASK2;
+               c0 = 0;
+#ifdef mul64
+               mh = HBITS(ml);
+               ml = LBITS(ml);
+               mul_add(c1,np[0],ml,mh,c0);
+#else
+               mul_add(c1,ml,np[0],c0);
+#endif
+               for(j=1;j<num;j++)
+                       {
+                       c1 = tp[j];
+#ifdef mul64
+                       mul_add(c1,np[j],ml,mh,c0);
+#else
+                       mul_add(c1,ml,np[j],c0);
+#endif
+                       tp[j-1] = c1&BN_MASK2;
+                       }
+               c1        = (tp[num] + c0)&BN_MASK2;
+               tp[num-1] = c1;
+               tp[num]   = tp[num+1] + (c1<c0?1:0);
+               }
+
+       if (tp[num]!=0 || tp[num-1]>=np[num-1])
+               {
+               c0 = bn_sub_words(rp,tp,np,num);
+               if (tp[num]!=0 || c0==0)
+                       {
+                       for(i=0;i<num+2;i++)    vp[i] = 0;
+                       return 1;
+                       }
+               }
+       for(i=0;i<num;i++)      rp[i] = tp[i],  vp[i] = 0;
+       vp[num]   = 0;
+       vp[num+1] = 0;
+       return 1;
+       }
+#else
+/*
+ * Return value of 0 indicates that multiplication/convolution was not
+ * performed to signal the caller to fall down to alternative/original
+ * code-path.
+ */
+int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np,const BN_ULONG *n0, int num)
+{      return 0;       }
+#endif /* OPENSSL_BN_ASM_MONT */
+#endif
+
 #else /* !BN_MUL_COMBA */
 
 /* hmm... is it faster just to do a multiply? */
 #undef bn_sqr_comba4
-void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
+void bn_sqr_comba4(BN_ULONG *r, const BN_ULONG *a)
        {
        BN_ULONG t[8];
        bn_sqr_normal(r,a,4,t);
        }
 
 #undef bn_sqr_comba8
-void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
+void bn_sqr_comba8(BN_ULONG *r, const BN_ULONG *a)
        {
        BN_ULONG t[16];
        bn_sqr_normal(r,a,8,t);
@@ -857,4 +980,51 @@ void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
        r[15]=bn_mul_add_words(&(r[7]),a,8,b[7]);
        }
 
+#ifdef OPENSSL_NO_ASM
+#ifdef OPENSSL_BN_ASM_MONT
+#include <alloca.h>
+int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np,const BN_ULONG *n0p, int num)
+       {
+       BN_ULONG c0,c1,*tp,n0=*n0p;
+       volatile BN_ULONG *vp;
+       int i=0,j;
+
+       vp = tp = alloca((num+2)*sizeof(BN_ULONG));
+
+       for(i=0;i<=num;i++)     tp[i]=0;
+
+       for(i=0;i<num;i++)
+               {
+               c0         = bn_mul_add_words(tp,ap,num,bp[i]);
+               c1         = (tp[num] + c0)&BN_MASK2;
+               tp[num]    = c1;
+               tp[num+1]  = (c1<c0?1:0);
+
+               c0         = bn_mul_add_words(tp,np,num,tp[0]*n0);
+               c1         = (tp[num] + c0)&BN_MASK2;
+               tp[num]    = c1;
+               tp[num+1] += (c1<c0?1:0);
+               for(j=0;j<=num;j++)     tp[j]=tp[j+1];
+               }
+
+       if (tp[num]!=0 || tp[num-1]>=np[num-1])
+               {
+               c0 = bn_sub_words(rp,tp,np,num);
+               if (tp[num]!=0 || c0==0)
+                       {
+                       for(i=0;i<num+2;i++)    vp[i] = 0;
+                       return 1;
+                       }
+               }
+       for(i=0;i<num;i++)      rp[i] = tp[i],  vp[i] = 0;
+       vp[num]   = 0;
+       vp[num+1] = 0;
+       return 1;
+       }
+#else
+int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np,const BN_ULONG *n0, int num)
+{      return 0;       }
+#endif /* OPENSSL_BN_ASM_MONT */
+#endif
+
 #endif /* !BN_MUL_COMBA */
index c11fb4c..9ed8bc2 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/bn/bn_blind.c */
 /* ====================================================================
- * Copyright (c) 1998-2005 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -121,9 +121,12 @@ struct bn_blinding_st
        BIGNUM *Ai;
        BIGNUM *e;
        BIGNUM *mod; /* just a reference */
+#ifndef OPENSSL_NO_DEPRECATED
        unsigned long thread_id; /* added in OpenSSL 0.9.6j and 0.9.7b;
                                  * used only by crypto/rsa/rsa_eay.c, rsa_lib.c */
-       unsigned int  counter;
+#endif
+       CRYPTO_THREADID tid;
+       int counter;
        unsigned long flags;
        BN_MONT_CTX *m_ctx;
        int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
@@ -131,7 +134,7 @@ struct bn_blinding_st
                          BN_MONT_CTX *m_ctx);
        };
 
-BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, /* const */ BIGNUM *mod)
+BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, BIGNUM *mod)
        {
        BN_BLINDING *ret=NULL;
 
@@ -157,7 +160,11 @@ BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, /* const */ BIGN
        if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)
                BN_set_flags(ret->mod, BN_FLG_CONSTTIME);
 
-       ret->counter = BN_BLINDING_COUNTER;
+       /* Set the counter to the special value -1
+        * to indicate that this is never-used fresh blinding
+        * that does not need updating before first use. */
+       ret->counter = -1;
+       CRYPTO_THREADID_current(&ret->tid);
        return(ret);
 err:
        if (ret != NULL) BN_BLINDING_free(ret);
@@ -186,7 +193,10 @@ int BN_BLINDING_update(BN_BLINDING *b, BN_CTX *ctx)
                goto err;
                }
 
-       if (--(b->counter) == 0 && b->e != NULL &&
+       if (b->counter == -1)
+               b->counter = 0;
+
+       if (++b->counter == BN_BLINDING_COUNTER && b->e != NULL &&
                !(b->flags & BN_BLINDING_NO_RECREATE))
                {
                /* re-create blinding parameters */
@@ -201,8 +211,8 @@ int BN_BLINDING_update(BN_BLINDING *b, BN_CTX *ctx)
 
        ret=1;
 err:
-       if (b->counter == 0)
-               b->counter = BN_BLINDING_COUNTER;
+       if (b->counter == BN_BLINDING_COUNTER)
+               b->counter = 0;
        return(ret);
        }
 
@@ -223,6 +233,12 @@ int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, BN_CTX *ctx)
                return(0);
                }
 
+       if (b->counter == -1)
+               /* Fresh blinding, doesn't need updating. */
+               b->counter = 0;
+       else if (!BN_BLINDING_update(b,ctx))
+               return(0);
+
        if (r != NULL)
                {
                if (!BN_copy(r, b->Ai)) ret=0;
@@ -243,26 +259,24 @@ int BN_BLINDING_invert_ex(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b, BN_CTX *ct
        int ret;
 
        bn_check_top(n);
-       if ((b->A == NULL) || (b->Ai == NULL))
-               {
-               BNerr(BN_F_BN_BLINDING_INVERT_EX,BN_R_NOT_INITIALIZED);
-               return(0);
-               }
 
        if (r != NULL)
                ret = BN_mod_mul(n, n, r, b->mod, ctx);
        else
-               ret = BN_mod_mul(n, n, b->Ai, b->mod, ctx);
-
-       if (ret >= 0)
                {
-               if (!BN_BLINDING_update(b,ctx))
+               if (b->Ai == NULL)
+                       {
+                       BNerr(BN_F_BN_BLINDING_INVERT_EX,BN_R_NOT_INITIALIZED);
                        return(0);
+                       }
+               ret = BN_mod_mul(n, n, b->Ai, b->mod, ctx);
                }
+
        bn_check_top(n);
        return(ret);
        }
 
+#ifndef OPENSSL_NO_DEPRECATED
 unsigned long BN_BLINDING_get_thread_id(const BN_BLINDING *b)
        {
        return b->thread_id;
@@ -272,6 +286,12 @@ void BN_BLINDING_set_thread_id(BN_BLINDING *b, unsigned long n)
        {
        b->thread_id = n;
        }
+#endif
+
+CRYPTO_THREADID *BN_BLINDING_thread_id(BN_BLINDING *b)
+       {
+       return &b->tid;
+       }
 
 unsigned long BN_BLINDING_get_flags(const BN_BLINDING *b)
        {
@@ -284,7 +304,7 @@ void BN_BLINDING_set_flags(BN_BLINDING *b, unsigned long flags)
        }
 
 BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b,
-       const BIGNUM *e, /* const */ BIGNUM *m, BN_CTX *ctx,
+       const BIGNUM *e, BIGNUM *m, BN_CTX *ctx,
        int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
                          const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx),
        BN_MONT_CTX *m_ctx)
index b3452f1..3f2256f 100644 (file)
@@ -161,7 +161,7 @@ static void ctxdbg(BN_CTX *ctx)
        fprintf(stderr,"(%08x): ", (unsigned int)ctx);
        while(bnidx < ctx->used)
                {
-               fprintf(stderr,"%02x ", item->vals[bnidx++ % BN_CTX_POOL_SIZE].dmax);
+               fprintf(stderr,"%03x ", item->vals[bnidx++ % BN_CTX_POOL_SIZE].dmax);
                if(!(bnidx % BN_CTX_POOL_SIZE))
                        item = item->next;
                }
@@ -171,8 +171,8 @@ static void ctxdbg(BN_CTX *ctx)
        while(fpidx < stack->depth)
                {
                while(bnidx++ < stack->indexes[fpidx])
-                       fprintf(stderr,"   ");
-               fprintf(stderr,"^^ ");
+                       fprintf(stderr,"    ");
+               fprintf(stderr,"^^^ ");
                bnidx++;
                fpidx++;
                }
index 78c6507..802a43d 100644 (file)
@@ -338,9 +338,6 @@ X) -> 0x%08X\n",
                                }
 #else /* !BN_LLONG */
                        BN_ULONG t2l,t2h;
-#if !defined(BN_UMULT_LOHI) && !defined(BN_UMULT_HIGH)
-                       BN_ULONG ql,qh;
-#endif
 
                        q=bn_div_words(n0,n1,d0);
 #ifdef BN_DEBUG_LEVITTE
@@ -358,9 +355,12 @@ X) -> 0x%08X\n",
                        t2l = d1 * q;
                        t2h = BN_UMULT_HIGH(d1,q);
 #else
+                       {
+                       BN_ULONG ql, qh;
                        t2l=LBITS(d1); t2h=HBITS(d1);
                        ql =LBITS(q);  qh =HBITS(q);
                        mul64(t2l,t2h,ql,qh); /* t2=(BN_ULLONG)d1*q; */
+                       }
 #endif
 
                        for (;;)
@@ -565,9 +565,6 @@ X) -> 0x%08X\n",
                                }
 #else /* !BN_LLONG */
                        BN_ULONG t2l,t2h;
-#if !defined(BN_UMULT_LOHI) && !defined(BN_UMULT_HIGH)
-                       BN_ULONG ql,qh;
-#endif
 
                        q=bn_div_words(n0,n1,d0);
 #ifdef BN_DEBUG_LEVITTE
@@ -585,9 +582,12 @@ X) -> 0x%08X\n",
                        t2l = d1 * q;
                        t2h = BN_UMULT_HIGH(d1,q);
 #else
+                       {
+                       BN_ULONG ql, qh;
                        t2l=LBITS(d1); t2h=HBITS(d1);
                        ql =LBITS(q);  qh =HBITS(q);
                        mul64(t2l,t2h,ql,qh); /* t2=(BN_ULLONG)d1*q; */
+                       }
 #endif
 
                        for (;;)
index ae642cc..432a3aa 100644 (file)
@@ -121,74 +121,12 @@ static const BN_ULONG SQR_tb[16] =
     SQR_tb[(w) >> 12 & 0xF] << 24 | SQR_tb[(w) >>  8 & 0xF] << 16 | \
     SQR_tb[(w) >>  4 & 0xF] <<  8 | SQR_tb[(w)       & 0xF]
 #endif
-#ifdef SIXTEEN_BIT
-#define SQR1(w) \
-    SQR_tb[(w) >> 12 & 0xF] <<  8 | SQR_tb[(w) >>  8 & 0xF]
-#define SQR0(w) \
-    SQR_tb[(w) >>  4 & 0xF] <<  8 | SQR_tb[(w)       & 0xF]
-#endif
-#ifdef EIGHT_BIT
-#define SQR1(w) \
-    SQR_tb[(w) >>  4 & 0xF]
-#define SQR0(w) \
-    SQR_tb[(w)       & 15]
-#endif
 
 /* Product of two polynomials a, b each with degree < BN_BITS2 - 1,
  * result is a polynomial r with degree < 2 * BN_BITS - 1
  * The caller MUST ensure that the variables have the right amount
  * of space allocated.
  */
-#ifdef EIGHT_BIT
-static void bn_GF2m_mul_1x1(BN_ULONG *r1, BN_ULONG *r0, const BN_ULONG a, const BN_ULONG b)
-       {
-       register BN_ULONG h, l, s;
-       BN_ULONG tab[4], top1b = a >> 7;
-       register BN_ULONG a1, a2;
-
-       a1 = a & (0x7F); a2 = a1 << 1;
-
-       tab[0] = 0; tab[1] = a1; tab[2] = a2; tab[3] = a1^a2;
-
-       s = tab[b      & 0x3]; l  = s;
-       s = tab[b >> 2 & 0x3]; l ^= s << 2; h  = s >> 6;
-       s = tab[b >> 4 & 0x3]; l ^= s << 4; h ^= s >> 4;
-       s = tab[b >> 6      ]; l ^= s << 6; h ^= s >> 2;
-       
-       /* compensate for the top bit of a */
-
-       if (top1b & 01) { l ^= b << 7; h ^= b >> 1; } 
-
-       *r1 = h; *r0 = l;
-       } 
-#endif
-#ifdef SIXTEEN_BIT
-static void bn_GF2m_mul_1x1(BN_ULONG *r1, BN_ULONG *r0, const BN_ULONG a, const BN_ULONG b)
-       {
-       register BN_ULONG h, l, s;
-       BN_ULONG tab[4], top1b = a >> 15; 
-       register BN_ULONG a1, a2;
-
-       a1 = a & (0x7FFF); a2 = a1 << 1;
-
-       tab[0] = 0; tab[1] = a1; tab[2] = a2; tab[3] = a1^a2;
-
-       s = tab[b      & 0x3]; l  = s;
-       s = tab[b >> 2 & 0x3]; l ^= s <<  2; h  = s >> 14;
-       s = tab[b >> 4 & 0x3]; l ^= s <<  4; h ^= s >> 12;
-       s = tab[b >> 6 & 0x3]; l ^= s <<  6; h ^= s >> 10;
-       s = tab[b >> 8 & 0x3]; l ^= s <<  8; h ^= s >>  8;
-       s = tab[b >>10 & 0x3]; l ^= s << 10; h ^= s >>  6;
-       s = tab[b >>12 & 0x3]; l ^= s << 12; h ^= s >>  4;
-       s = tab[b >>14      ]; l ^= s << 14; h ^= s >>  2;
-
-       /* compensate for the top bit of a */
-
-       if (top1b & 01) { l ^= b << 15; h ^= b >> 1; } 
-
-       *r1 = h; *r0 = l;
-       } 
-#endif
 #ifdef THIRTY_TWO_BIT
 static void bn_GF2m_mul_1x1(BN_ULONG *r1, BN_ULONG *r0, const BN_ULONG a, const BN_ULONG b)
        {
@@ -321,7 +259,7 @@ int BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
 
 
 /* Performs modular reduction of a and store result in r.  r could be a. */
-int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[])
+int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const int p[])
        {
        int j, k;
        int n, dN, d0, d1;
@@ -422,11 +360,11 @@ int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[])
 int    BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p)
        {
        int ret = 0;
-       const int max = BN_num_bits(p);
-       unsigned int *arr=NULL;
+       const int max = BN_num_bits(p) + 1;
+       int *arr=NULL;
        bn_check_top(a);
        bn_check_top(p);
-       if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err;
+       if ((arr = (int *)OPENSSL_malloc(sizeof(int) * max)) == NULL) goto err;
        ret = BN_GF2m_poly2arr(p, arr, max);
        if (!ret || ret > max)
                {
@@ -444,7 +382,7 @@ err:
 /* Compute the product of two polynomials a and b, reduce modulo p, and store
  * the result in r.  r could be a or b; a could be b.
  */
-int    BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const unsigned int p[], BN_CTX *ctx)
+int    BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const int p[], BN_CTX *ctx)
        {
        int zlen, i, j, k, ret = 0;
        BIGNUM *s;
@@ -500,12 +438,12 @@ err:
 int    BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *p, BN_CTX *ctx)
        {
        int ret = 0;
-       const int max = BN_num_bits(p);
-       unsigned int *arr=NULL;
+       const int max = BN_num_bits(p) + 1;
+       int *arr=NULL;
        bn_check_top(a);
        bn_check_top(b);
        bn_check_top(p);
-       if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err;
+       if ((arr = (int *)OPENSSL_malloc(sizeof(int) * max)) == NULL) goto err;
        ret = BN_GF2m_poly2arr(p, arr, max);
        if (!ret || ret > max)
                {
@@ -521,7 +459,7 @@ err:
 
 
 /* Square a, reduce the result mod p, and store it in a.  r could be a. */
-int    BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[], BN_CTX *ctx)
+int    BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[], BN_CTX *ctx)
        {
        int i, ret = 0;
        BIGNUM *s;
@@ -556,12 +494,12 @@ err:
 int    BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
        {
        int ret = 0;
-       const int max = BN_num_bits(p);
-       unsigned int *arr=NULL;
+       const int max = BN_num_bits(p) + 1;
+       int *arr=NULL;
 
        bn_check_top(a);
        bn_check_top(p);
-       if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err;
+       if ((arr = (int *)OPENSSL_malloc(sizeof(int) * max)) == NULL) goto err;
        ret = BN_GF2m_poly2arr(p, arr, max);
        if (!ret || ret > max)
                {
@@ -607,6 +545,7 @@ int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
                {
                while (!BN_is_odd(u))
                        {
+                       if (BN_is_zero(u)) goto err;
                        if (!BN_rshift1(u, u)) goto err;
                        if (BN_is_odd(b))
                                {
@@ -643,7 +582,7 @@ err:
  * function is only provided for convenience; for best performance, use the 
  * BN_GF2m_mod_inv function.
  */
-int BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *xx, const unsigned int p[], BN_CTX *ctx)
+int BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *xx, const int p[], BN_CTX *ctx)
        {
        BIGNUM *field;
        int ret = 0;
@@ -769,7 +708,7 @@ err:
  * function is only provided for convenience; for best performance, use the 
  * BN_GF2m_mod_div function.
  */
-int BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *yy, const BIGNUM *xx, const unsigned int p[], BN_CTX *ctx)
+int BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *yy, const BIGNUM *xx, const int p[], BN_CTX *ctx)
        {
        BIGNUM *field;
        int ret = 0;
@@ -794,7 +733,7 @@ err:
  * the result in r.  r could be a.
  * Uses simple square-and-multiply algorithm A.5.1 from IEEE P1363.
  */
-int    BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const unsigned int p[], BN_CTX *ctx)
+int    BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const int p[], BN_CTX *ctx)
        {
        int ret = 0, i, n;
        BIGNUM *u;
@@ -840,12 +779,12 @@ err:
 int BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *p, BN_CTX *ctx)
        {
        int ret = 0;
-       const int max = BN_num_bits(p);
-       unsigned int *arr=NULL;
+       const int max = BN_num_bits(p) + 1;
+       int *arr=NULL;
        bn_check_top(a);
        bn_check_top(b);
        bn_check_top(p);
-       if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err;
+       if ((arr = (int *)OPENSSL_malloc(sizeof(int) * max)) == NULL) goto err;
        ret = BN_GF2m_poly2arr(p, arr, max);
        if (!ret || ret > max)
                {
@@ -863,7 +802,7 @@ err:
  * the result in r.  r could be a.
  * Uses exponentiation as in algorithm A.4.1 from IEEE P1363.
  */
-int    BN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[], BN_CTX *ctx)
+int    BN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a, const int p[], BN_CTX *ctx)
        {
        int ret = 0;
        BIGNUM *u;
@@ -899,11 +838,11 @@ err:
 int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
        {
        int ret = 0;
-       const int max = BN_num_bits(p);
-       unsigned int *arr=NULL;
+       const int max = BN_num_bits(p) + 1;
+       int *arr=NULL;
        bn_check_top(a);
        bn_check_top(p);
-       if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err;
+       if ((arr = (int *)OPENSSL_malloc(sizeof(int) * max)) == NULL) goto err;
        ret = BN_GF2m_poly2arr(p, arr, max);
        if (!ret || ret > max)
                {
@@ -920,10 +859,9 @@ err:
 /* Find r such that r^2 + r = a mod p.  r could be a. If no r exists returns 0.
  * Uses algorithms A.4.7 and A.4.6 from IEEE P1363.
  */
-int BN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a_, const unsigned int p[], BN_CTX *ctx)
+int BN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a_, const int p[], BN_CTX *ctx)
        {
-       int ret = 0, count = 0;
-       unsigned int j;
+       int ret = 0, count = 0, j;
        BIGNUM *a, *z, *rho, *w, *w2, *tmp;
 
        bn_check_top(a_);
@@ -1018,11 +956,11 @@ err:
 int BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
        {
        int ret = 0;
-       const int max = BN_num_bits(p);
-       unsigned int *arr=NULL;
+       const int max = BN_num_bits(p) + 1;
+       int *arr=NULL;
        bn_check_top(a);
        bn_check_top(p);
-       if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) *
+       if ((arr = (int *)OPENSSL_malloc(sizeof(int) *
                                                max)) == NULL) goto err;
        ret = BN_GF2m_poly2arr(p, arr, max);
        if (!ret || ret > max)
@@ -1038,20 +976,17 @@ err:
        }
 
 /* Convert the bit-string representation of a polynomial
- * ( \sum_{i=0}^n a_i * x^i , where a_0 is *not* zero) into an array
- * of integers corresponding to the bits with non-zero coefficient.
+ * ( \sum_{i=0}^n a_i * x^i) into an array of integers corresponding 
+ * to the bits with non-zero coefficient.  Array is terminated with -1.
  * Up to max elements of the array will be filled.  Return value is total
- * number of coefficients that would be extracted if array was large enough.
+ * number of array elements that would be filled if array was large enough.
  */
-int BN_GF2m_poly2arr(const BIGNUM *a, unsigned int p[], int max)
+int BN_GF2m_poly2arr(const BIGNUM *a, int p[], int max)
        {
        int i, j, k = 0;
        BN_ULONG mask;
 
-       if (BN_is_zero(a) || !BN_is_bit_set(a, 0))
-               /* a_0 == 0 => return error (the unsigned int array
-                * must be terminated by 0)
-                */
+       if (BN_is_zero(a))
                return 0;
 
        for (i = a->top - 1; i >= 0; i--)
@@ -1071,24 +1006,28 @@ int BN_GF2m_poly2arr(const BIGNUM *a, unsigned int p[], int max)
                        }
                }
 
+       if (k < max) {
+               p[k] = -1;
+               k++;
+       }
+
        return k;
        }
 
 /* Convert the coefficient array representation of a polynomial to a 
- * bit-string.  The array must be terminated by 0.
+ * bit-string.  The array must be terminated by -1.
  */
-int BN_GF2m_arr2poly(const unsigned int p[], BIGNUM *a)
+int BN_GF2m_arr2poly(const int p[], BIGNUM *a)
        {
        int i;
 
        bn_check_top(a);
        BN_zero(a);
-       for (i = 0; p[i] != 0; i++)
+       for (i = 0; p[i] != -1; i++)
                {
                if (BN_set_bit(a, p[i]) == 0)
                        return 0;
                }
-       BN_set_bit(a, 0);
        bn_check_top(a);
 
        return 1;
index 27ac439..8e5e98e 100644 (file)
@@ -255,7 +255,8 @@ extern "C" {
             : "r"(a), "r"(b));         \
        ret;                    })
 #  endif       /* compiler */
-# elif defined(__x86_64) && defined(SIXTY_FOUR_BIT_LONG)
+# elif (defined(__x86_64) || defined(__x86_64__)) && \
+       (defined(SIXTY_FOUR_BIT_LONG) || defined(SIXTY_FOUR_BIT))
 #  if defined(__GNUC__)
 #   define BN_UMULT_HIGH(a,b)  ({      \
        register BN_ULONG ret,discard;  \
index 32a8fba..5470fbe 100644 (file)
@@ -133,15 +133,34 @@ int BN_get_params(int which)
 
 const BIGNUM *BN_value_one(void)
        {
-       static BN_ULONG data_one=1L;
-       static BIGNUM const_one={&data_one,1,1,0,BN_FLG_STATIC_DATA};
+       static const BN_ULONG data_one=1L;
+       static const BIGNUM const_one={(BN_ULONG *)&data_one,1,1,0,BN_FLG_STATIC_DATA};
 
        return(&const_one);
        }
 
+char *BN_options(void)
+       {
+       static int init=0;
+       static char data[16];
+
+       if (!init)
+               {
+               init++;
+#ifdef BN_LLONG
+               BIO_snprintf(data,sizeof data,"bn(%d,%d)",
+                            (int)sizeof(BN_ULLONG)*8,(int)sizeof(BN_ULONG)*8);
+#else
+               BIO_snprintf(data,sizeof data,"bn(%d,%d)",
+                            (int)sizeof(BN_ULONG)*8,(int)sizeof(BN_ULONG)*8);
+#endif
+               }
+       return(data);
+       }
+
 int BN_num_bits_word(BN_ULONG l)
        {
-       static const char bits[256]={
+       static const unsigned char bits[256]={
                0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,
                5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
                6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
@@ -216,7 +235,7 @@ int BN_num_bits_word(BN_ULONG l)
                else
 #endif
                        {
-#if defined(SIXTEEN_BIT) || defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG)
+#if defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG)
                        if (l & 0xff00L)
                                return(bits[(int)(l>>8)]+8);
                        else    
@@ -744,7 +763,7 @@ int BN_is_bit_set(const BIGNUM *a, int n)
        i=n/BN_BITS2;
        j=n%BN_BITS2;
        if (a->top <= i) return 0;
-       return(((a->d[i])>>j)&((BN_ULONG)1));
+       return (int)(((a->d[i])>>j)&((BN_ULONG)1));
        }
 
 int BN_mask_bits(BIGNUM *a, int n)
index 4799b15..1a86688 100644 (file)
 
 #define MONT_WORD /* use the faster word-based algorithm */
 
-#if defined(MONT_WORD) && defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)
-/* This condition means we have a specific non-default build:
- * In the 0.9.8 branch, OPENSSL_BN_ASM_MONT is normally not set for any
- * BN_BITS2<=32 platform; an explicit "enable-montasm" is required.
- * I.e., if we are here, the user intentionally deviates from the
- * normal stable build to get better Montgomery performance from
- * the 0.9.9-dev backport.
- *
- * In this case only, we also enable BN_from_montgomery_word()
- * (another non-stable feature from 0.9.9-dev).
- */
-#define MONT_FROM_WORD___NON_DEFAULT_0_9_8_BUILD
-#endif
-
-#ifdef MONT_FROM_WORD___NON_DEFAULT_0_9_8_BUILD
+#ifdef MONT_WORD
 static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont);
 #endif
 
-
-
 int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
                          BN_MONT_CTX *mont, BN_CTX *ctx)
        {
@@ -153,11 +137,7 @@ int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
        if (num>1 && a->top==num && b->top==num)
                {
                if (bn_wexpand(r,num) == NULL) return(0);
-#if 0 /* for OpenSSL 0.9.9 mont->n0 */
                if (bn_mul_mont(r->d,a->d,b->d,mont->N.d,mont->n0,num))
-#else
-               if (bn_mul_mont(r->d,a->d,b->d,mont->N.d,&mont->n0,num))
-#endif
                        {
                        r->neg = a->neg^b->neg;
                        r->top = num;
@@ -181,7 +161,7 @@ int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
                if (!BN_mul(tmp,a,b,ctx)) goto err;
                }
        /* reduce from aRR to aR */
-#ifdef MONT_FROM_WORD___NON_DEFAULT_0_9_8_BUILD
+#ifdef MONT_WORD
        if (!BN_from_montgomery_word(r,tmp,mont)) goto err;
 #else
        if (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;
@@ -193,7 +173,7 @@ err:
        return(ret);
        }
 
-#ifdef MONT_FROM_WORD___NON_DEFAULT_0_9_8_BUILD
+#ifdef MONT_WORD
 static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)
        {
        BIGNUM *n;
@@ -217,15 +197,15 @@ static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)
        nrp= &(r->d[nl]);
 
        /* clear the top words of T */
+#if 1
        for (i=r->top; i<max; i++) /* memset? XXX */
                r->d[i]=0;
+#else
+       memset(&(r->d[r->top]),0,(max-r->top)*sizeof(BN_ULONG)); 
+#endif
 
        r->top=max;
-#if 0 /* for OpenSSL 0.9.9 mont->n0 */
        n0=mont->n0[0];
-#else
-       n0=mont->n0;
-#endif
 
 #ifdef BN_COUNT
        fprintf(stderr,"word BN_from_montgomery_word %d * %d\n",nl,nl);
@@ -270,6 +250,8 @@ static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)
                }
        al=r->top-ri;
 
+#define BRANCH_FREE 1
+#if BRANCH_FREE
        if (bn_wexpand(ret,ri) == NULL) return(0);
        x=0-(((al-ri)>>(sizeof(al)*8-1))&1);
        ret->top=x=(ri&~x)|(al&x);      /* min(ri,al) */
@@ -295,7 +277,7 @@ static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)
        m1|=m2;                 /* (al!=ri) */
        m1|=(0-(size_t)v);      /* (al!=ri || v) */
        m1&=~m2;                /* (al!=ri || v) && !al>ri */
-       nrp=(BN_ULONG *)(((size_t)rp&~m1)|((size_t)ap&m1));
+       nrp=(BN_ULONG *)(((PTR_SIZE_INT)rp&~m1)|((PTR_SIZE_INT)ap&m1));
        }
 
        /* 'i<ri' is chosen to eliminate dependency on input data, even
@@ -317,164 +299,8 @@ static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)
                rp[i]=nrp[i], ap[i]=0;
        bn_correct_top(r);
        bn_correct_top(ret);
-       bn_check_top(ret);
-
-       return(1);
-       }
-
-int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
-            BN_CTX *ctx)
-       {
-       int retn=0;
-       BIGNUM *t;
-
-       BN_CTX_start(ctx);
-       if ((t = BN_CTX_get(ctx)) && BN_copy(t,a))
-               retn = BN_from_montgomery_word(ret,t,mont);
-       BN_CTX_end(ctx);
-       return retn;
-       }
-
-#else /* !MONT_FROM_WORD___NON_DEFAULT_0_9_8_BUILD */
-
-int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
-            BN_CTX *ctx)
-       {
-       int retn=0;
-
-#ifdef MONT_WORD
-       BIGNUM *n,*r;
-       BN_ULONG *ap,*np,*rp,n0,v,*nrp;
-       int al,nl,max,i,x,ri;
-
-       BN_CTX_start(ctx);
-       if ((r = BN_CTX_get(ctx)) == NULL) goto err;
-
-       if (!BN_copy(r,a)) goto err;
-       n= &(mont->N);
-
-       ap=a->d;
-       /* mont->ri is the size of mont->N in bits (rounded up
-          to the word size) */
-       al=ri=mont->ri/BN_BITS2;
-       
-       nl=n->top;
-       if ((al == 0) || (nl == 0)) { r->top=0; return(1); }
-
-       max=(nl+al+1); /* allow for overflow (no?) XXX */
-       if (bn_wexpand(r,max) == NULL) goto err;
-
-       r->neg=a->neg^n->neg;
-       np=n->d;
-       rp=r->d;
-       nrp= &(r->d[nl]);
-
-       /* clear the top words of T */
-#if 1
-       for (i=r->top; i<max; i++) /* memset? XXX */
-               r->d[i]=0;
 #else
-       memset(&(r->d[r->top]),0,(max-r->top)*sizeof(BN_ULONG)); 
-#endif
-
-       r->top=max;
-       n0=mont->n0;
-
-#ifdef BN_COUNT
-       fprintf(stderr,"word BN_from_montgomery %d * %d\n",nl,nl);
-#endif
-       for (i=0; i<nl; i++)
-               {
-#ifdef __TANDEM
-                {
-                   long long t1;
-                   long long t2;
-                   long long t3;
-                   t1 = rp[0] * (n0 & 0177777);
-                   t2 = 037777600000l;
-                   t2 = n0 & t2;
-                   t3 = rp[0] & 0177777;
-                   t2 = (t3 * t2) & BN_MASK2;
-                   t1 = t1 + t2;
-                   v=bn_mul_add_words(rp,np,nl,(BN_ULONG) t1);
-                }
-#else
-               v=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2);
-#endif
-               nrp++;
-               rp++;
-               if (((nrp[-1]+=v)&BN_MASK2) >= v)
-                       continue;
-               else
-                       {
-                       if (((++nrp[0])&BN_MASK2) != 0) continue;
-                       if (((++nrp[1])&BN_MASK2) != 0) continue;
-                       for (x=2; (((++nrp[x])&BN_MASK2) == 0); x++) ;
-                       }
-               }
-       bn_correct_top(r);
-       
-       /* mont->ri will be a multiple of the word size and below code
-        * is kind of BN_rshift(ret,r,mont->ri) equivalent */
-       if (r->top <= ri)
-               {
-               ret->top=0;
-               retn=1;
-               goto err;
-               }
-       al=r->top-ri;
-
-# define BRANCH_FREE 1
-# if BRANCH_FREE
-       if (bn_wexpand(ret,ri) == NULL) goto err;
-       x=0-(((al-ri)>>(sizeof(al)*8-1))&1);
-       ret->top=x=(ri&~x)|(al&x);      /* min(ri,al) */
-       ret->neg=r->neg;
-
-       rp=ret->d;
-       ap=&(r->d[ri]);
-
-       {
-       size_t m1,m2;
-
-       v=bn_sub_words(rp,ap,np,ri);
-       /* this ----------------^^ works even in al<ri case
-        * thanks to zealous zeroing of top of the vector in the
-        * beginning. */
-
-       /* if (al==ri && !v) || al>ri) nrp=rp; else nrp=ap; */
-       /* in other words if subtraction result is real, then
-        * trick unconditional memcpy below to perform in-place
-        * "refresh" instead of actual copy. */
-       m1=0-(size_t)(((al-ri)>>(sizeof(al)*8-1))&1);   /* al<ri */
-       m2=0-(size_t)(((ri-al)>>(sizeof(al)*8-1))&1);   /* al>ri */
-       m1|=m2;                 /* (al!=ri) */
-       m1|=(0-(size_t)v);      /* (al!=ri || v) */
-       m1&=~m2;                /* (al!=ri || v) && !al>ri */
-       nrp=(BN_ULONG *)(((size_t)rp&~m1)|((size_t)ap&m1));
-       }
-
-       /* 'i<ri' is chosen to eliminate dependency on input data, even
-        * though it results in redundant copy in al<ri case. */
-       for (i=0,ri-=4; i<ri; i+=4)
-               {
-               BN_ULONG t1,t2,t3,t4;
-               
-               t1=nrp[i+0];
-               t2=nrp[i+1];
-               t3=nrp[i+2];    ap[i+0]=0;
-               t4=nrp[i+3];    ap[i+1]=0;
-               rp[i+0]=t1;     ap[i+2]=0;
-               rp[i+1]=t2;     ap[i+3]=0;
-               rp[i+2]=t3;
-               rp[i+3]=t4;
-               }
-       for (ri+=4; i<ri; i++)
-               rp[i]=nrp[i], ap[i]=0;
-       bn_correct_top(r);
-       bn_correct_top(ret);
-# else
-       if (bn_wexpand(ret,al) == NULL) goto err;
+       if (bn_wexpand(ret,al) == NULL) return(0);
        ret->top=al;
        ret->neg=r->neg;
 
@@ -497,8 +323,30 @@ int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
        al+=4;
        for (; i<al; i++)
                rp[i]=ap[i];
-# endif
-#else /* !MONT_WORD */ 
+
+       if (BN_ucmp(ret, &(mont->N)) >= 0)
+               {
+               if (!BN_usub(ret,ret,&(mont->N))) return(0);
+               }
+#endif
+       bn_check_top(ret);
+
+       return(1);
+       }
+#endif /* MONT_WORD */
+
+int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
+            BN_CTX *ctx)
+       {
+       int retn=0;
+#ifdef MONT_WORD
+       BIGNUM *t;
+
+       BN_CTX_start(ctx);
+       if ((t = BN_CTX_get(ctx)) && BN_copy(t,a))
+               retn = BN_from_montgomery_word(ret,t,mont);
+       BN_CTX_end(ctx);
+#else /* !MONT_WORD */
        BIGNUM *t1,*t2;
 
        BN_CTX_start(ctx);
@@ -515,21 +363,18 @@ int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
        if (!BN_mul(t1,t2,&mont->N,ctx)) goto err;
        if (!BN_add(t2,a,t1)) goto err;
        if (!BN_rshift(ret,t2,mont->ri)) goto err;
-#endif /* MONT_WORD */
 
-#if !defined(BRANCH_FREE) || BRANCH_FREE==0
        if (BN_ucmp(ret, &(mont->N)) >= 0)
                {
                if (!BN_usub(ret,ret,&(mont->N))) goto err;
                }
-#endif
        retn=1;
        bn_check_top(ret);
  err:
        BN_CTX_end(ctx);
+#endif /* MONT_WORD */
        return(retn);
        }
-#endif /* MONT_FROM_WORD___NON_DEFAULT_0_9_8_BUILD */
 
 BN_MONT_CTX *BN_MONT_CTX_new(void)
        {
@@ -549,11 +394,7 @@ void BN_MONT_CTX_init(BN_MONT_CTX *ctx)
        BN_init(&(ctx->RR));
        BN_init(&(ctx->N));
        BN_init(&(ctx->Ni));
-#if 0 /* for OpenSSL 0.9.9 mont->n0 */
        ctx->n0[0] = ctx->n0[1] = 0;
-#else
-       ctx->n0 = 0;
-#endif
        ctx->flags=0;
        }
 
@@ -585,26 +426,22 @@ int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
                BIGNUM tmod;
                BN_ULONG buf[2];
 
-               mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;
-               BN_zero(R);
-#if 0 /* for OpenSSL 0.9.9 mont->n0, would be "#if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)",
-         only certain BN_BITS2<=32 platforms actually need this */
-               if (!(BN_set_bit(R,2*BN_BITS2))) goto err;      /* R */
-#else
-               if (!(BN_set_bit(R,BN_BITS2))) goto err;        /* R */
-#endif
-
-               buf[0]=mod->d[0]; /* tmod = N mod word size */
-               buf[1]=0;
-
                BN_init(&tmod);
                tmod.d=buf;
-               tmod.top = buf[0] != 0 ? 1 : 0;
                tmod.dmax=2;
                tmod.neg=0;
 
-#if 0 /* for OpenSSL 0.9.9 mont->n0, would be "#if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)";
-         only certain BN_BITS2<=32 platforms actually need this */
+               mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;
+
+#if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)
+               /* Only certain BN_BITS2<=32 platforms actually make use of
+                * n0[1], and we could use the #else case (with a shorter R
+                * value) for the others.  However, currently only the assembler
+                * files do know which is which. */
+
+               BN_zero(R);
+               if (!(BN_set_bit(R,2*BN_BITS2))) goto err;
+
                                                                tmod.top=0;
                if ((buf[0] = mod->d[0]))                       tmod.top=1;
                if ((buf[1] = mod->top>1 ? mod->d[1] : 0))      tmod.top=2;
@@ -632,6 +469,12 @@ int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
                mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;
                mont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;
 #else
+               BN_zero(R);
+               if (!(BN_set_bit(R,BN_BITS2))) goto err;        /* R */
+
+               buf[0]=mod->d[0]; /* tmod = N mod word size */
+               buf[1]=0;
+               tmod.top = buf[0] != 0 ? 1 : 0;
                                                        /* Ri = R^-1 mod N*/
                if ((BN_mod_inverse(Ri,R,&tmod,ctx)) == NULL)
                        goto err;
@@ -647,12 +490,8 @@ int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
                if (!BN_div(Ri,NULL,Ri,&tmod,ctx)) goto err;
                /* Ni = (R*Ri-1)/N,
                 * keep only least significant word: */
-# if 0 /* for OpenSSL 0.9.9 mont->n0 */
                mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;
                mont->n0[1] = 0;
-# else
-               mont->n0 = (Ri->top > 0) ? Ri->d[0] : 0;
-# endif
 #endif
                }
 #else /* !MONT_WORD */
@@ -689,12 +528,8 @@ BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from)
        if (!BN_copy(&(to->N),&(from->N))) return NULL;
        if (!BN_copy(&(to->Ni),&(from->Ni))) return NULL;
        to->ri=from->ri;
-#if 0 /* for OpenSSL 0.9.9 mont->n0 */
        to->n0[0]=from->n0[0];
        to->n0[1]=from->n0[1];
-#else
-       to->n0=from->n0;
-#endif
        return(to);
        }
 
index 2ca5b01..c6de032 100644 (file)
@@ -354,7 +354,7 @@ int BN_nist_mod_192(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
                 buf[BN_NIST_192_TOP],
                 c_d[BN_NIST_192_TOP],
                *res;
-       size_t   mask;
+       PTR_SIZE_INT mask;
        static const BIGNUM _bignum_nist_p_192_sqr = {
                (BN_ULONG *)_nist_p_192_sqr,
                sizeof(_nist_p_192_sqr)/sizeof(_nist_p_192_sqr[0]),
@@ -405,9 +405,10 @@ int BN_nist_mod_192(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
         * 'tmp=result-modulus; if (!carry || !borrow) result=tmp;'
         * this is what happens below, but without explicit if:-) a.
         */
-       mask  = 0-(size_t)bn_sub_words(c_d,r_d,_nist_p_192[0],BN_NIST_192_TOP);
-       mask &= 0-(size_t)carry;
-       res   = (BN_ULONG *)(((size_t)c_d&~mask) | ((size_t)r_d&mask));
+       mask  = 0-(PTR_SIZE_INT)bn_sub_words(c_d,r_d,_nist_p_192[0],BN_NIST_192_TOP);
+       mask &= 0-(PTR_SIZE_INT)carry;
+       res   = (BN_ULONG *)
+        (((PTR_SIZE_INT)c_d&~mask) | ((PTR_SIZE_INT)r_d&mask));
        nist_cp_bn(r_d, res, BN_NIST_192_TOP);
        r->top = BN_NIST_192_TOP;
        bn_correct_top(r);
@@ -438,8 +439,8 @@ int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
                 buf[BN_NIST_224_TOP],
                 c_d[BN_NIST_224_TOP],
                *res;
-       size_t   mask;
-       union { bn_addsub_f f; size_t p; } u;
+       PTR_SIZE_INT mask;
+       union { bn_addsub_f f; PTR_SIZE_INT p; } u;
        static const BIGNUM _bignum_nist_p_224_sqr = {
                (BN_ULONG *)_nist_p_224_sqr,
                sizeof(_nist_p_224_sqr)/sizeof(_nist_p_224_sqr[0]),
@@ -510,16 +511,18 @@ int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
                 * to be compared to the modulus and conditionally
                 * adjusted by *subtracting* the latter. */
                carry = (int)bn_add_words(r_d,r_d,_nist_p_224[-carry-1],BN_NIST_224_TOP);
-               mask = 0-(size_t)carry;
-               u.p = ((size_t)bn_sub_words&mask) | ((size_t)bn_add_words&~mask);
+               mask = 0-(PTR_SIZE_INT)carry;
+               u.p = ((PTR_SIZE_INT)bn_sub_words&mask) |
+                ((PTR_SIZE_INT)bn_add_words&~mask);
                }
        else
                carry = 1;
 
        /* otherwise it's effectively same as in BN_nist_mod_192... */
-       mask  = 0-(size_t)(*u.f)(c_d,r_d,_nist_p_224[0],BN_NIST_224_TOP);
-       mask &= 0-(size_t)carry;
-       res   = (BN_ULONG *)(((size_t)c_d&~mask) | ((size_t)r_d&mask));
+       mask  = 0-(PTR_SIZE_INT)(*u.f)(c_d,r_d,_nist_p_224[0],BN_NIST_224_TOP);
+       mask &= 0-(PTR_SIZE_INT)carry;
+       res   = (BN_ULONG *)(((PTR_SIZE_INT)c_d&~mask) |
+        ((PTR_SIZE_INT)r_d&mask));
        nist_cp_bn(r_d, res, BN_NIST_224_TOP);
        r->top = BN_NIST_224_TOP;
        bn_correct_top(r);
@@ -549,8 +552,8 @@ int BN_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
                 buf[BN_NIST_256_TOP],
                 c_d[BN_NIST_256_TOP],
                *res;
-       size_t   mask;
-       union { bn_addsub_f f; size_t p; } u;
+       PTR_SIZE_INT mask;
+       union { bn_addsub_f f; PTR_SIZE_INT p; } u;
        static const BIGNUM _bignum_nist_p_256_sqr = {
                (BN_ULONG *)_nist_p_256_sqr,
                sizeof(_nist_p_256_sqr)/sizeof(_nist_p_256_sqr[0]),
@@ -629,15 +632,17 @@ int BN_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
        else if (carry < 0)
                {
                carry = (int)bn_add_words(r_d,r_d,_nist_p_256[-carry-1],BN_NIST_256_TOP);
-               mask = 0-(size_t)carry;
-               u.p = ((size_t)bn_sub_words&mask) | ((size_t)bn_add_words&~mask);
+               mask = 0-(PTR_SIZE_INT)carry;
+               u.p = ((PTR_SIZE_INT)bn_sub_words&mask) |
+                ((PTR_SIZE_INT)bn_add_words&~mask);
                }
        else
                carry = 1;
 
-       mask  = 0-(size_t)(*u.f)(c_d,r_d,_nist_p_256[0],BN_NIST_256_TOP);
-       mask &= 0-(size_t)carry;
-       res   = (BN_ULONG *)(((size_t)c_d&~mask) | ((size_t)r_d&mask));
+       mask  = 0-(PTR_SIZE_INT)(*u.f)(c_d,r_d,_nist_p_256[0],BN_NIST_256_TOP);
+       mask &= 0-(PTR_SIZE_INT)carry;
+       res   = (BN_ULONG *)(((PTR_SIZE_INT)c_d&~mask) |
+        ((PTR_SIZE_INT)r_d&mask));
        nist_cp_bn(r_d, res, BN_NIST_256_TOP);
        r->top = BN_NIST_256_TOP;
        bn_correct_top(r);
@@ -671,8 +676,8 @@ int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
                 buf[BN_NIST_384_TOP],
                 c_d[BN_NIST_384_TOP],
                *res;
-       size_t   mask;
-       union { bn_addsub_f f; size_t p; } u;
+       PTR_SIZE_INT mask;
+       union { bn_addsub_f f; PTR_SIZE_INT p; } u;
        static const BIGNUM _bignum_nist_p_384_sqr = {
                (BN_ULONG *)_nist_p_384_sqr,
                sizeof(_nist_p_384_sqr)/sizeof(_nist_p_384_sqr[0]),
@@ -754,15 +759,17 @@ int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
        else if (carry < 0)
                {
                carry = (int)bn_add_words(r_d,r_d,_nist_p_384[-carry-1],BN_NIST_384_TOP);
-               mask = 0-(size_t)carry;
-               u.p = ((size_t)bn_sub_words&mask) | ((size_t)bn_add_words&~mask);
+               mask = 0-(PTR_SIZE_INT)carry;
+               u.p = ((PTR_SIZE_INT)bn_sub_words&mask) |
+                ((PTR_SIZE_INT)bn_add_words&~mask);
                }
        else
                carry = 1;
 
-       mask  = 0-(size_t)(*u.f)(c_d,r_d,_nist_p_384[0],BN_NIST_384_TOP);
-       mask &= 0-(size_t)carry;
-       res   = (BN_ULONG *)(((size_t)c_d&~mask) | ((size_t)r_d&mask));
+       mask  = 0-(PTR_SIZE_INT)(*u.f)(c_d,r_d,_nist_p_384[0],BN_NIST_384_TOP);
+       mask &= 0-(PTR_SIZE_INT)carry;
+       res   = (BN_ULONG *)(((PTR_SIZE_INT)c_d&~mask) |
+        ((PTR_SIZE_INT)r_d&mask));
        nist_cp_bn(r_d, res, BN_NIST_384_TOP);
        r->top = BN_NIST_384_TOP;
        bn_correct_top(r);
@@ -781,7 +788,7 @@ int BN_nist_mod_521(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
        BN_ULONG *r_d, *a_d = a->d,
                 t_d[BN_NIST_521_TOP],
                 val,tmp,*res;
-       size_t  mask;
+       PTR_SIZE_INT mask;
        static const BIGNUM _bignum_nist_p_521_sqr = {
                (BN_ULONG *)_nist_p_521_sqr,
                sizeof(_nist_p_521_sqr)/sizeof(_nist_p_521_sqr[0]),
@@ -826,8 +833,9 @@ int BN_nist_mod_521(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
        r_d[i] &= BN_NIST_521_TOP_MASK;
 
        bn_add_words(r_d,r_d,t_d,BN_NIST_521_TOP);
-       mask = 0-(size_t)bn_sub_words(t_d,r_d,_nist_p_521,BN_NIST_521_TOP);
-       res  = (BN_ULONG *)(((size_t)t_d&~mask) | ((size_t)r_d&mask));
+       mask = 0-(PTR_SIZE_INT)bn_sub_words(t_d,r_d,_nist_p_521,BN_NIST_521_TOP);
+       res  = (BN_ULONG *)(((PTR_SIZE_INT)t_d&~mask) |
+        ((PTR_SIZE_INT)r_d&mask));
        nist_cp_bn(r_d,res,BN_NIST_521_TOP);
        r->top = BN_NIST_521_TOP;
        bn_correct_top(r);
index 810dde3..bebb466 100644 (file)
@@ -294,6 +294,27 @@ err:
        return(0);
        }
 
+int BN_asc2bn(BIGNUM **bn, const char *a)
+       {
+       const char *p = a;
+       if (*p == '-')
+               p++;
+
+       if (p[0] == '0' && (p[1] == 'X' || p[1] == 'x'))
+               {               
+               if (!BN_hex2bn(bn, p + 2))
+                       return 0;
+               }
+       else
+               {
+               if (!BN_dec2bn(bn, p))
+                       return 0;
+               }
+       if (*a == '-')
+               (*bn)->neg = 1;
+       return 1;
+       }
+
 #ifndef OPENSSL_NO_BIO
 #ifndef OPENSSL_NO_FP_API
 int BN_print_fp(FILE *fp, const BIGNUM *a)
diff --git a/deps/openssl/openssl/crypto/bn/bn_x931p.c b/deps/openssl/openssl/crypto/bn/bn_x931p.c
deleted file mode 100644 (file)
index 04c5c87..0000000
+++ /dev/null
@@ -1,272 +0,0 @@
-/* bn_x931p.c */
-/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
- * project 2005.
- */
-/* ====================================================================
- * Copyright (c) 2005 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    licensing@OpenSSL.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
- * ====================================================================
- *
- * This product includes cryptographic software written by Eric Young
- * (eay@cryptsoft.com).  This product includes software written by Tim
- * Hudson (tjh@cryptsoft.com).
- *
- */
-
-#include <stdio.h>
-#include <openssl/bn.h>
-
-/* X9.31 routines for prime derivation */
-
-/* X9.31 prime derivation. This is used to generate the primes pi
- * (p1, p2, q1, q2) from a parameter Xpi by checking successive odd
- * integers.
- */
-
-static int bn_x931_derive_pi(BIGNUM *pi, const BIGNUM *Xpi, BN_CTX *ctx,
-                       BN_GENCB *cb)
-       {
-       int i = 0;
-       if (!BN_copy(pi, Xpi))
-               return 0;
-       if (!BN_is_odd(pi) && !BN_add_word(pi, 1))
-               return 0;
-       for(;;)
-               {
-               i++;
-               BN_GENCB_call(cb, 0, i);
-               /* NB 27 MR is specificed in X9.31 */
-               if (BN_is_prime_fasttest_ex(pi, 27, ctx, 1, cb))
-                       break;
-               if (!BN_add_word(pi, 2))
-                       return 0;
-               }
-       BN_GENCB_call(cb, 2, i);
-       return 1;
-       }
-
-/* This is the main X9.31 prime derivation function. From parameters
- * Xp1, Xp2 and Xp derive the prime p. If the parameters p1 or p2 are
- * not NULL they will be returned too: this is needed for testing.
- */
-
-int BN_X931_derive_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2,
-                       const BIGNUM *Xp, const BIGNUM *Xp1, const BIGNUM *Xp2,
-                       const BIGNUM *e, BN_CTX *ctx, BN_GENCB *cb)
-       {
-       int ret = 0;
-
-       BIGNUM *t, *p1p2, *pm1;
-
-       /* Only even e supported */
-       if (!BN_is_odd(e))
-               return 0;
-
-       BN_CTX_start(ctx);
-       if (!p1)
-               p1 = BN_CTX_get(ctx);
-
-       if (!p2)
-               p2 = BN_CTX_get(ctx);
-
-       t = BN_CTX_get(ctx);
-
-       p1p2 = BN_CTX_get(ctx);
-
-       pm1 = BN_CTX_get(ctx);
-
-       if (!bn_x931_derive_pi(p1, Xp1, ctx, cb))
-               goto err;
-
-       if (!bn_x931_derive_pi(p2, Xp2, ctx, cb))
-               goto err;
-
-       if (!BN_mul(p1p2, p1, p2, ctx))
-               goto err;
-
-       /* First set p to value of Rp */
-
-       if (!BN_mod_inverse(p, p2, p1, ctx))
-               goto err;
-
-       if (!BN_mul(p, p, p2, ctx))
-               goto err;
-
-       if (!BN_mod_inverse(t, p1, p2, ctx))
-               goto err;
-
-       if (!BN_mul(t, t, p1, ctx))
-               goto err;
-
-       if (!BN_sub(p, p, t))
-               goto err;
-
-       if (p->neg && !BN_add(p, p, p1p2))
-               goto err;
-
-       /* p now equals Rp */
-
-       if (!BN_mod_sub(p, p, Xp, p1p2, ctx))
-               goto err;
-
-       if (!BN_add(p, p, Xp))
-               goto err;
-
-       /* p now equals Yp0 */
-
-       for (;;)
-               {
-               int i = 1;
-               BN_GENCB_call(cb, 0, i++);
-               if (!BN_copy(pm1, p))
-                       goto err;
-               if (!BN_sub_word(pm1, 1))
-                       goto err;
-               if (!BN_gcd(t, pm1, e, ctx))
-                       goto err;
-               if (BN_is_one(t)
-               /* X9.31 specifies 8 MR and 1 Lucas test or any prime test
-                * offering similar or better guarantees 50 MR is considerably 
-                * better.
-                */
-                       && BN_is_prime_fasttest_ex(p, 50, ctx, 1, cb))
-                       break;
-               if (!BN_add(p, p, p1p2))
-                       goto err;
-               }
-
-       BN_GENCB_call(cb, 3, 0);
-
-       ret = 1;
-
-       err:
-
-       BN_CTX_end(ctx);
-
-       return ret;
-       }
-
-/* Generate pair of paramters Xp, Xq for X9.31 prime generation.
- * Note: nbits paramter is sum of number of bits in both.
- */
-
-int BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx)
-       {
-       BIGNUM *t;
-       int i;
-       /* Number of bits for each prime is of the form
-        * 512+128s for s = 0, 1, ...
-        */
-       if ((nbits < 1024) || (nbits & 0xff))
-               return 0;
-       nbits >>= 1;
-       /* The random value Xp must be between sqrt(2) * 2^(nbits-1) and
-        * 2^nbits - 1. By setting the top two bits we ensure that the lower
-        * bound is exceeded.
-        */
-       if (!BN_rand(Xp, nbits, 1, 0))
-               return 0;
-
-       BN_CTX_start(ctx);
-       t = BN_CTX_get(ctx);
-
-       for (i = 0; i < 1000; i++)
-               {
-               if (!BN_rand(Xq, nbits, 1, 0))
-                       return 0;
-               /* Check that |Xp - Xq| > 2^(nbits - 100) */
-               BN_sub(t, Xp, Xq);
-               if (BN_num_bits(t) > (nbits - 100))
-                       break;
-               }
-
-       BN_CTX_end(ctx);
-
-       if (i < 1000)
-               return 1;
-
-       return 0;
-
-       }
-
-/* Generate primes using X9.31 algorithm. Of the values p, p1, p2, Xp1
- * and Xp2 only 'p' needs to be non-NULL. If any of the others are not NULL
- * the relevant parameter will be stored in it.
- *
- * Due to the fact that |Xp - Xq| > 2^(nbits - 100) must be satisfied Xp and Xq
- * are generated using the previous function and supplied as input.
- */
-
-int BN_X931_generate_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2,
-                       BIGNUM *Xp1, BIGNUM *Xp2,
-                       const BIGNUM *Xp,
-                       const BIGNUM *e, BN_CTX *ctx,
-                       BN_GENCB *cb)
-       {
-       int ret = 0;
-
-       BN_CTX_start(ctx);
-       if (!Xp1)
-               Xp1 = BN_CTX_get(ctx);
-       if (!Xp2)
-               Xp2 = BN_CTX_get(ctx);
-
-       if (!BN_rand(Xp1, 101, 0, 0))
-               goto error;
-       if (!BN_rand(Xp2, 101, 0, 0))
-               goto error;
-       if (!BN_X931_derive_prime_ex(p, p1, p2, Xp, Xp1, Xp2, e, ctx, cb))
-               goto error;
-
-       ret = 1;
-
-       error:
-       BN_CTX_end(ctx);
-
-       return ret;
-
-       }
-
index d41daac..0cd99c5 100644 (file)
@@ -486,7 +486,7 @@ static void print_word(BIO *bp,BN_ULONG w)
                return;
                }
 #endif
-       BIO_printf(bp,"%lX",w);
+       BIO_printf(bp,BN_HEX_FMT1,w);
        }
 
 int test_div_word(BIO *bp)
@@ -732,6 +732,8 @@ int test_mont(BIO *bp, BN_CTX *ctx)
        BN_init(&n);
 
        mont=BN_MONT_CTX_new();
+       if (mont == NULL)
+               return 0;
 
        BN_bntest_rand(&a,100,0,0); /**/
        BN_bntest_rand(&b,100,0,0); /**/
@@ -1116,8 +1118,8 @@ int test_gf2m_mod(BIO *bp)
        {
        BIGNUM *a,*b[2],*c,*d,*e;
        int i, j, ret = 0;
-       unsigned int p0[] = {163,7,6,3,0};
-       unsigned int p1[] = {193,15,0};
+       int p0[] = {163,7,6,3,0,-1};
+       int p1[] = {193,15,0,-1};
 
        a=BN_new();
        b[0]=BN_new();
@@ -1174,8 +1176,8 @@ int test_gf2m_mod_mul(BIO *bp,BN_CTX *ctx)
        {
        BIGNUM *a,*b[2],*c,*d,*e,*f,*g,*h;
        int i, j, ret = 0;
-       unsigned int p0[] = {163,7,6,3,0};
-       unsigned int p1[] = {193,15,0};
+       int p0[] = {163,7,6,3,0,-1};
+       int p1[] = {193,15,0,-1};
 
        a=BN_new();
        b[0]=BN_new();
@@ -1245,8 +1247,8 @@ int test_gf2m_mod_sqr(BIO *bp,BN_CTX *ctx)
        {
        BIGNUM *a,*b[2],*c,*d;
        int i, j, ret = 0;
-       unsigned int p0[] = {163,7,6,3,0};
-       unsigned int p1[] = {193,15,0};
+       int p0[] = {163,7,6,3,0,-1};
+       int p1[] = {193,15,0,-1};
 
        a=BN_new();
        b[0]=BN_new();
@@ -1304,8 +1306,8 @@ int test_gf2m_mod_inv(BIO *bp,BN_CTX *ctx)
        {
        BIGNUM *a,*b[2],*c,*d;
        int i, j, ret = 0;
-       unsigned int p0[] = {163,7,6,3,0};
-       unsigned int p1[] = {193,15,0};
+       int p0[] = {163,7,6,3,0,-1};
+       int p1[] = {193,15,0,-1};
 
        a=BN_new();
        b[0]=BN_new();
@@ -1359,8 +1361,8 @@ int test_gf2m_mod_div(BIO *bp,BN_CTX *ctx)
        {
        BIGNUM *a,*b[2],*c,*d,*e,*f;
        int i, j, ret = 0;
-       unsigned int p0[] = {163,7,6,3,0};
-       unsigned int p1[] = {193,15,0};
+       int p0[] = {163,7,6,3,0,-1};
+       int p1[] = {193,15,0,-1};
 
        a=BN_new();
        b[0]=BN_new();
@@ -1422,8 +1424,8 @@ int test_gf2m_mod_exp(BIO *bp,BN_CTX *ctx)
        {
        BIGNUM *a,*b[2],*c,*d,*e,*f;
        int i, j, ret = 0;
-       unsigned int p0[] = {163,7,6,3,0};
-       unsigned int p1[] = {193,15,0};
+       int p0[] = {163,7,6,3,0,-1};
+       int p1[] = {193,15,0,-1};
 
        a=BN_new();
        b[0]=BN_new();
@@ -1493,8 +1495,8 @@ int test_gf2m_mod_sqrt(BIO *bp,BN_CTX *ctx)
        {
        BIGNUM *a,*b[2],*c,*d,*e,*f;
        int i, j, ret = 0;
-       unsigned int p0[] = {163,7,6,3,0};
-       unsigned int p1[] = {193,15,0};
+       int p0[] = {163,7,6,3,0,-1};
+       int p1[] = {193,15,0,-1};
 
        a=BN_new();
        b[0]=BN_new();
@@ -1552,8 +1554,8 @@ int test_gf2m_mod_solve_quad(BIO *bp,BN_CTX *ctx)
        {
        BIGNUM *a,*b[2],*c,*d,*e;
        int i, j, s = 0, t, ret = 0;
-       unsigned int p0[] = {163,7,6,3,0};
-       unsigned int p1[] = {193,15,0};
+       int p0[] = {163,7,6,3,0,-1};
+       int p1[] = {193,15,0,-1};
 
        a=BN_new();
        b[0]=BN_new();
index f598a07..074a8e8 100644 (file)
@@ -163,7 +163,7 @@ int main(int argc, char *argv[])
                        {
                        if (BN_cmp(r_simple,r_mont) != 0)
                                printf("\nsimple and mont results differ\n");
-                       if (BN_cmp(r_simple,r_mont) != 0)
+                       if (BN_cmp(r_simple,r_mont_const) != 0)
                                printf("\nsimple and mont const time results differ\n");
                        if (BN_cmp(r_simple,r_recp) != 0)
                                printf("\nsimple and recp results differ\n");
@@ -187,7 +187,7 @@ int main(int argc, char *argv[])
        BN_free(b);
        BN_free(m);
        BN_CTX_free(ctx);
-       ERR_remove_state(0);
+       ERR_remove_thread_state(NULL);
        CRYPTO_mem_leaks(out);
        BIO_free(out);
        printf(" done\n");
index 9e0f46e..9f3a88d 100644 (file)
@@ -17,8 +17,8 @@ TEST=
 APPS=
 
 LIB=$(TOP)/libcrypto.a
-LIBSRC= buffer.c buf_str.c buf_err.c
-LIBOBJ= buffer.o buf_str.o buf_err.o
+LIBSRC= buffer.c buf_err.c
+LIBOBJ= buffer.o buf_err.o
 
 SRC= $(LIBSRC)
 
@@ -33,7 +33,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -81,13 +81,6 @@ buf_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
 buf_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
 buf_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
 buf_err.o: buf_err.c
-buf_str.o: ../../e_os.h ../../include/openssl/bio.h
-buf_str.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
-buf_str.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-buf_str.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
-buf_str.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-buf_str.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-buf_str.o: ../../include/openssl/symhacks.h ../cryptlib.h buf_str.c
 buffer.o: ../../e_os.h ../../include/openssl/bio.h
 buffer.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 buffer.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
index 3e25bbe..8f1de61 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/buffer/buf_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
index b3e9477..620ea8d 100644 (file)
@@ -89,10 +89,10 @@ void BUF_MEM_free(BUF_MEM *a)
        OPENSSL_free(a);
        }
 
-int BUF_MEM_grow(BUF_MEM *str, int len)
+int BUF_MEM_grow(BUF_MEM *str, size_t len)
        {
        char *ret;
-       unsigned int n;
+       size_t n;
 
        if (str->length >= len)
                {
@@ -125,10 +125,10 @@ int BUF_MEM_grow(BUF_MEM *str, int len)
        return(len);
        }
 
-int BUF_MEM_grow_clean(BUF_MEM *str, int len)
+int BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
        {
        char *ret;
-       unsigned int n;
+       size_t n;
 
        if (str->length >= len)
                {
@@ -161,3 +161,84 @@ int BUF_MEM_grow_clean(BUF_MEM *str, int len)
                }
        return(len);
        }
+
+char *BUF_strdup(const char *str)
+       {
+       if (str == NULL) return(NULL);
+       return BUF_strndup(str, strlen(str));
+       }
+
+char *BUF_strndup(const char *str, size_t siz)
+       {
+       char *ret;
+
+       if (str == NULL) return(NULL);
+
+       ret=OPENSSL_malloc(siz+1);
+       if (ret == NULL) 
+               {
+               BUFerr(BUF_F_BUF_STRNDUP,ERR_R_MALLOC_FAILURE);
+               return(NULL);
+               }
+       BUF_strlcpy(ret,str,siz+1);
+       return(ret);
+       }
+
+void *BUF_memdup(const void *data, size_t siz)
+       {
+       void *ret;
+
+       if (data == NULL) return(NULL);
+
+       ret=OPENSSL_malloc(siz);
+       if (ret == NULL) 
+               {
+               BUFerr(BUF_F_BUF_MEMDUP,ERR_R_MALLOC_FAILURE);
+               return(NULL);
+               }
+       return memcpy(ret, data, siz);
+       }       
+
+size_t BUF_strlcpy(char *dst, const char *src, size_t size)
+       {
+       size_t l = 0;
+       for(; size > 1 && *src; size--)
+               {
+               *dst++ = *src++;
+               l++;
+               }
+       if (size)
+               *dst = '\0';
+       return l + strlen(src);
+       }
+
+size_t BUF_strlcat(char *dst, const char *src, size_t size)
+       {
+       size_t l = 0;
+       for(; size > 0 && *dst; size--, dst++)
+               l++;
+       return l + BUF_strlcpy(dst, src, size);
+       }
+
+void BUF_reverse(unsigned char *out, unsigned char *in, size_t size)
+       {
+       size_t i;
+       if (in)
+               {
+               out += size - 1;
+               for (i = 0; i < size; i++)
+                       *in++ = *out--;
+               }
+       else
+               {
+               unsigned char *q;
+               char c;
+               q = out + size - 1;
+               for (i = 0; i < size/2; i++)
+                       {
+                       c = *q;
+                       *q-- = *out;
+                       *out++ = c;
+                       }
+               }
+       }
index 1db9607..178e418 100644 (file)
@@ -76,18 +76,19 @@ extern "C" {
 
 struct buf_mem_st
        {
-       int length;     /* current number of bytes */
+       size_t length;  /* current number of bytes */
        char *data;
-       int max;        /* size of buffer */
+       size_t max;     /* size of buffer */
        };
 
 BUF_MEM *BUF_MEM_new(void);
 void   BUF_MEM_free(BUF_MEM *a);
-int    BUF_MEM_grow(BUF_MEM *str, int len);
-int    BUF_MEM_grow_clean(BUF_MEM *str, int len);
+int    BUF_MEM_grow(BUF_MEM *str, size_t len);
+int    BUF_MEM_grow_clean(BUF_MEM *str, size_t len);
 char * BUF_strdup(const char *str);
 char * BUF_strndup(const char *str, size_t siz);
 void * BUF_memdup(const void *data, size_t siz);
+void   BUF_reverse(unsigned char *out, unsigned char *in, size_t siz);
 
 /* safe string functions */
 size_t BUF_strlcpy(char *dst,const char *src,size_t siz);
index dfd1a75..ff5fe4a 100644 (file)
@@ -11,7 +11,7 @@ CFLAG=-g
 MAKEFILE=      Makefile
 AR=            ar r
 
-CAMELLIA_ASM_OBJ=
+CMLL_ENC= camellia.o cmll_misc.o cmll_cbc.o
 
 CFLAGS= $(INCLUDES) $(CFLAG)
 ASFLAGS= $(INCLUDES) $(ASFLAG)
@@ -25,8 +25,7 @@ LIB=$(TOP)/libcrypto.a
 LIBSRC=camellia.c cmll_misc.c cmll_ecb.c cmll_cbc.c cmll_ofb.c \
           cmll_cfb.c cmll_ctr.c 
 
-LIBOBJ= camellia.o cmll_misc.o cmll_ecb.o cmll_cbc.o cmll_ofb.o \
-               cmll_cfb.o cmll_ctr.o $(CAMELLIA_ASM_OBJ)
+LIBOBJ= cmll_ecb.o cmll_ofb.o cmll_cfb.o cmll_ctr.o $(CMLL_ENC)
 
 SRC= $(LIBSRC)
 
@@ -41,12 +40,14 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
-$(LIBOBJ): $(LIBSRC)
-
+cmll-x86.s:    asm/cmll-x86.pl ../perlasm/x86asm.pl
+       $(PERL) asm/cmll-x86.pl $(PERLASM_SCHEME) $(CFLAGS) $(PROCESSOR) > $@
+cmll-x86_64.s:  asm/cmll-x86_64.pl
+       $(PERL) asm/cmll-x86_64.pl $(PERLASM_SCHEME) > $@
 
 files:
        $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
@@ -85,22 +86,18 @@ clean:
 
 # DO NOT DELETE THIS LINE -- make depend depends on it.
 
-camellia.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
-camellia.o: camellia.c camellia.h cmll_locl.h
-cmll_cbc.o: ../../include/openssl/camellia.h ../../include/openssl/e_os2.h
-cmll_cbc.o: ../../include/openssl/opensslconf.h cmll_cbc.c cmll_locl.h
-cmll_cfb.o: ../../e_os.h ../../include/openssl/camellia.h
-cmll_cfb.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
-cmll_cfb.o: cmll_cfb.c cmll_locl.h
-cmll_ctr.o: ../../include/openssl/camellia.h ../../include/openssl/e_os2.h
-cmll_ctr.o: ../../include/openssl/opensslconf.h cmll_ctr.c cmll_locl.h
-cmll_ecb.o: ../../include/openssl/camellia.h ../../include/openssl/e_os2.h
+camellia.o: ../../include/openssl/opensslconf.h camellia.c camellia.h
+camellia.o: cmll_locl.h
+cmll_cbc.o: ../../include/openssl/camellia.h ../../include/openssl/modes.h
+cmll_cbc.o: ../../include/openssl/opensslconf.h cmll_cbc.c
+cmll_cfb.o: ../../include/openssl/camellia.h ../../include/openssl/modes.h
+cmll_cfb.o: ../../include/openssl/opensslconf.h cmll_cfb.c
+cmll_ctr.o: ../../include/openssl/camellia.h ../../include/openssl/modes.h
+cmll_ctr.o: ../../include/openssl/opensslconf.h cmll_ctr.c
+cmll_ecb.o: ../../include/openssl/camellia.h
 cmll_ecb.o: ../../include/openssl/opensslconf.h cmll_ecb.c cmll_locl.h
-cmll_misc.o: ../../include/openssl/camellia.h ../../include/openssl/crypto.h
-cmll_misc.o: ../../include/openssl/e_os2.h ../../include/openssl/fips.h
+cmll_misc.o: ../../include/openssl/camellia.h
 cmll_misc.o: ../../include/openssl/opensslconf.h
-cmll_misc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-cmll_misc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-cmll_misc.o: ../../include/openssl/symhacks.h cmll_locl.h cmll_misc.c
-cmll_ofb.o: ../../include/openssl/camellia.h ../../include/openssl/e_os2.h
-cmll_ofb.o: ../../include/openssl/opensslconf.h cmll_locl.h cmll_ofb.c
+cmll_misc.o: ../../include/openssl/opensslv.h cmll_locl.h cmll_misc.c
+cmll_ofb.o: ../../include/openssl/camellia.h ../../include/openssl/modes.h
+cmll_ofb.o: ../../include/openssl/opensslconf.h cmll_ofb.c
diff --git a/deps/openssl/openssl/crypto/camellia/asm/cmll-x86.pl b/deps/openssl/openssl/crypto/camellia/asm/cmll-x86.pl
new file mode 100644 (file)
index 0000000..027302a
--- /dev/null
@@ -0,0 +1,1138 @@
+#!/usr/bin/env perl
+
+# ====================================================================
+# Copyright (c) 2008 Andy Polyakov <appro@openssl.org>
+#
+# This module may be used under the terms of either the GNU General
+# Public License version 2 or later, the GNU Lesser General Public
+# License version 2.1 or later, the Mozilla Public License version
+# 1.1 or the BSD License. The exact terms of either license are
+# distributed along with this module. For further details see
+# http://www.openssl.org/~appro/camellia/.
+# ====================================================================
+
+# Performance in cycles per processed byte (less is better) in
+# 'openssl speed ...' benchmark:
+#
+#                      AMD K8  Core2   PIII    P4
+# -evp camellia-128-ecb        21.5    22.8    27.0    28.9
+# + over gcc 3.4.6     +90/11% +70/10% +53/4%  +160/64%
+# + over icc 8.0       +48/19% +21/15% +21/17% +55/37%
+#
+# camellia-128-cbc     17.3    21.1    23.9    25.9
+#
+# 128-bit key setup    196     280     256     240     cycles/key
+# + over gcc 3.4.6     +30/0%  +17/11% +11/0%  +63/40%
+# + over icc 8.0       +18/3%  +10/0%  +10/3%  +21/10%
+#
+# Pairs of numbers in "+" rows represent performance improvement over
+# compiler generated position-independent code, PIC, and non-PIC
+# respectively. PIC results are of greater relevance, as this module
+# is position-independent, i.e. suitable for a shared library or PIE.
+# Position independence "costs" one register, which is why compilers
+# are so close with non-PIC results, they have an extra register to
+# spare. CBC results are better than ECB ones thanks to "zero-copy"
+# private _x86_* interface, and are ~30-40% better than with compiler
+# generated cmll_cbc.o, and reach ~80-90% of x86_64 performance on
+# same CPU (where applicable).
+
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+push(@INC,"${dir}","${dir}../../perlasm");
+require "x86asm.pl";
+
+$OPENSSL=1;
+
+&asm_init($ARGV[0],"cmll-586.pl",$ARGV[$#ARGV] eq "386");
+
+@T=("eax","ebx","ecx","edx");
+$idx="esi";
+$key="edi";
+$Tbl="ebp";
+
+# stack frame layout in _x86_Camellia_* routines, frame is allocated
+# by caller
+$__ra=&DWP(0,"esp");   # return address
+$__s0=&DWP(4,"esp");   # s0 backing store
+$__s1=&DWP(8,"esp");   # s1 backing store
+$__s2=&DWP(12,"esp");  # s2 backing store
+$__s3=&DWP(16,"esp");  # s3 backing store
+$__end=&DWP(20,"esp"); # pointer to end/start of key schedule
+
+# stack frame layout in Camellia_[en|crypt] routines, which differs from
+# above by 4 and overlaps by pointer to end/start of key schedule
+$_end=&DWP(16,"esp");
+$_esp=&DWP(20,"esp");
+
+# const unsigned int Camellia_SBOX[4][256];
+# Well, sort of... Camellia_SBOX[0][] is interleaved with [1][],
+# and [2][] - with [3][]. This is done to optimize code size.
+$SBOX1_1110=0;         # Camellia_SBOX[0]
+$SBOX4_4404=4;         # Camellia_SBOX[1]
+$SBOX2_0222=2048;      # Camellia_SBOX[2]
+$SBOX3_3033=2052;      # Camellia_SBOX[3]
+&static_label("Camellia_SIGMA");
+&static_label("Camellia_SBOX");
+
+sub Camellia_Feistel {
+my $i=@_[0];
+my $seed=defined(@_[1])?@_[1]:0;
+my $scale=$seed<0?-8:8;
+my $frame=defined(@_[2])?@_[2]:0;
+my $j=($i&1)*2;
+my $t0=@T[($j)%4],$t1=@T[($j+1)%4],$t2=@T[($j+2)%4],$t3=@T[($j+3)%4];
+
+       &xor    ($t0,$idx);                             # t0^=key[0]
+       &xor    ($t1,&DWP($seed+$i*$scale+4,$key));     # t1^=key[1]
+       &movz   ($idx,&HB($t0));                        # (t0>>8)&0xff
+       &mov    ($t3,&DWP($SBOX3_3033,$Tbl,$idx,8));    # t3=SBOX3_3033[0]
+       &movz   ($idx,&LB($t0));                        # (t0>>0)&0xff
+       &xor    ($t3,&DWP($SBOX4_4404,$Tbl,$idx,8));    # t3^=SBOX4_4404[0]
+       &shr    ($t0,16);
+       &movz   ($idx,&LB($t1));                        # (t1>>0)&0xff
+       &mov    ($t2,&DWP($SBOX1_1110,$Tbl,$idx,8));    # t2=SBOX1_1110[1]
+       &movz   ($idx,&HB($t0));                        # (t0>>24)&0xff
+       &xor    ($t3,&DWP($SBOX1_1110,$Tbl,$idx,8));    # t3^=SBOX1_1110[0]
+       &movz   ($idx,&HB($t1));                        # (t1>>8)&0xff
+       &xor    ($t2,&DWP($SBOX4_4404,$Tbl,$idx,8));    # t2^=SBOX4_4404[1]
+       &shr    ($t1,16);
+       &movz   ($t0,&LB($t0));                         # (t0>>16)&0xff
+       &xor    ($t3,&DWP($SBOX2_0222,$Tbl,$t0,8));     # t3^=SBOX2_0222[0]
+       &movz   ($idx,&HB($t1));                        # (t1>>24)&0xff
+       &mov    ($t0,&DWP($frame+4*(($j+3)%4),"esp"));  # prefetch "s3"
+       &xor    ($t2,$t3);                              # t2^=t3
+       &rotr   ($t3,8);                                # t3=RightRotate(t3,8)
+       &xor    ($t2,&DWP($SBOX2_0222,$Tbl,$idx,8));    # t2^=SBOX2_0222[1]
+       &movz   ($idx,&LB($t1));                        # (t1>>16)&0xff
+       &mov    ($t1,&DWP($frame+4*(($j+2)%4),"esp"));  # prefetch "s2"
+       &xor    ($t3,$t0);                              # t3^=s3
+       &xor    ($t2,&DWP($SBOX3_3033,$Tbl,$idx,8));    # t2^=SBOX3_3033[1]
+       &mov    ($idx,&DWP($seed+($i+1)*$scale,$key));  # prefetch key[i+1]
+       &xor    ($t3,$t2);                              # t3^=t2
+       &mov    (&DWP($frame+4*(($j+3)%4),"esp"),$t3);  # s3=t3
+       &xor    ($t2,$t1);                              # t2^=s2
+       &mov    (&DWP($frame+4*(($j+2)%4),"esp"),$t2);  # s2=t2
+}
+
+# void Camellia_EncryptBlock_Rounds(
+#              int grandRounds,
+#              const Byte plaintext[],
+#              const KEY_TABLE_TYPE keyTable,
+#              Byte ciphertext[])
+&function_begin("Camellia_EncryptBlock_Rounds");
+       &mov    ("eax",&wparam(0));     # load grandRounds
+       &mov    ($idx,&wparam(1));      # load plaintext pointer
+       &mov    ($key,&wparam(2));      # load key schedule pointer
+
+       &mov    ("ebx","esp");
+       &sub    ("esp",7*4);            # place for s[0-3],keyEnd,esp and ra
+       &and    ("esp",-64);
+
+       # place stack frame just "above mod 1024" the key schedule
+       # this ensures that cache associativity of 2 suffices
+       &lea    ("ecx",&DWP(-64-63,$key));
+       &sub    ("ecx","esp");
+       &neg    ("ecx");
+       &and    ("ecx",0x3C0);  # modulo 1024, but aligned to cache-line
+       &sub    ("esp","ecx");
+       &add    ("esp",4);      # 4 is reserved for callee's return address
+
+       &shl    ("eax",6);
+       &lea    ("eax",&DWP(0,$key,"eax"));
+       &mov    ($_esp,"ebx");  # save %esp
+       &mov    ($_end,"eax");  # save keyEnd
+
+       &call   (&label("pic_point"));
+       &set_label("pic_point");
+       &blindpop($Tbl);
+       &lea    ($Tbl,&DWP(&label("Camellia_SBOX")."-".&label("pic_point"),$Tbl));
+
+       &mov    (@T[0],&DWP(0,$idx));   # load plaintext
+       &mov    (@T[1],&DWP(4,$idx));
+       &mov    (@T[2],&DWP(8,$idx));
+       &bswap  (@T[0]);
+       &mov    (@T[3],&DWP(12,$idx));
+       &bswap  (@T[1]);
+       &bswap  (@T[2]);
+       &bswap  (@T[3]);
+
+       &call   ("_x86_Camellia_encrypt");
+
+       &mov    ("esp",$_esp);
+       &bswap  (@T[0]);
+       &mov    ($idx,&wparam(3));      # load ciphertext pointer
+       &bswap  (@T[1]);
+       &bswap  (@T[2]);
+       &bswap  (@T[3]);
+       &mov    (&DWP(0,$idx),@T[0]);   # write ciphertext
+       &mov    (&DWP(4,$idx),@T[1]);
+       &mov    (&DWP(8,$idx),@T[2]);
+       &mov    (&DWP(12,$idx),@T[3]);
+&function_end("Camellia_EncryptBlock_Rounds");
+# V1.x API
+&function_begin_B("Camellia_EncryptBlock");
+       &mov    ("eax",128);
+       &sub    ("eax",&wparam(0));     # load keyBitLength
+       &mov    ("eax",3);
+       &adc    ("eax",0);              # keyBitLength==128?3:4
+       &mov    (&wparam(0),"eax");
+       &jmp    (&label("Camellia_EncryptBlock_Rounds"));
+&function_end_B("Camellia_EncryptBlock");
+
+if ($OPENSSL) {
+# void Camellia_encrypt(
+#              const unsigned char *in,
+#              unsigned char *out,
+#              const CAMELLIA_KEY *key)
+&function_begin("Camellia_encrypt");
+       &mov    ($idx,&wparam(0));      # load plaintext pointer
+       &mov    ($key,&wparam(2));      # load key schedule pointer
+
+       &mov    ("ebx","esp");
+       &sub    ("esp",7*4);            # place for s[0-3],keyEnd,esp and ra
+       &and    ("esp",-64);
+       &mov    ("eax",&DWP(272,$key)); # load grandRounds counter
+
+       # place stack frame just "above mod 1024" the key schedule
+       # this ensures that cache associativity of 2 suffices
+       &lea    ("ecx",&DWP(-64-63,$key));
+       &sub    ("ecx","esp");
+       &neg    ("ecx");
+       &and    ("ecx",0x3C0);  # modulo 1024, but aligned to cache-line
+       &sub    ("esp","ecx");
+       &add    ("esp",4);      # 4 is reserved for callee's return address
+
+       &shl    ("eax",6);
+       &lea    ("eax",&DWP(0,$key,"eax"));
+       &mov    ($_esp,"ebx");  # save %esp
+       &mov    ($_end,"eax");  # save keyEnd
+
+       &call   (&label("pic_point"));
+       &set_label("pic_point");
+       &blindpop($Tbl);
+       &lea    ($Tbl,&DWP(&label("Camellia_SBOX")."-".&label("pic_point"),$Tbl));
+
+       &mov    (@T[0],&DWP(0,$idx));   # load plaintext
+       &mov    (@T[1],&DWP(4,$idx));
+       &mov    (@T[2],&DWP(8,$idx));
+       &bswap  (@T[0]);
+       &mov    (@T[3],&DWP(12,$idx));
+       &bswap  (@T[1]);
+       &bswap  (@T[2]);
+       &bswap  (@T[3]);
+
+       &call   ("_x86_Camellia_encrypt");
+
+       &mov    ("esp",$_esp);
+       &bswap  (@T[0]);
+       &mov    ($idx,&wparam(1));      # load ciphertext pointer
+       &bswap  (@T[1]);
+       &bswap  (@T[2]);
+       &bswap  (@T[3]);
+       &mov    (&DWP(0,$idx),@T[0]);   # write ciphertext
+       &mov    (&DWP(4,$idx),@T[1]);
+       &mov    (&DWP(8,$idx),@T[2]);
+       &mov    (&DWP(12,$idx),@T[3]);
+&function_end("Camellia_encrypt");
+}
+
+&function_begin_B("_x86_Camellia_encrypt");
+       &xor    (@T[0],&DWP(0,$key));   # ^=key[0-3]
+       &xor    (@T[1],&DWP(4,$key));
+       &xor    (@T[2],&DWP(8,$key));
+       &xor    (@T[3],&DWP(12,$key));
+       &mov    ($idx,&DWP(16,$key));   # prefetch key[4]
+
+       &mov    ($__s0,@T[0]);          # save s[0-3]
+       &mov    ($__s1,@T[1]);
+       &mov    ($__s2,@T[2]);
+       &mov    ($__s3,@T[3]);
+
+&set_label("loop",16);
+       for ($i=0;$i<6;$i++) { Camellia_Feistel($i,16,4); }
+
+       &add    ($key,16*4);
+       &cmp    ($key,$__end);
+       &je     (&label("done"));
+
+       # @T[0-1] are preloaded, $idx is preloaded with key[0]
+       &and    ($idx,@T[0]);
+        &mov    (@T[3],$__s3);
+       &rotl   ($idx,1);
+        &mov    (@T[2],@T[3]);
+       &xor    (@T[1],$idx);
+        &or     (@T[2],&DWP(12,$key));
+       &mov    ($__s1,@T[1]);          # s1^=LeftRotate(s0&key[0],1);
+        &xor    (@T[2],$__s2);
+
+       &mov    ($idx,&DWP(4,$key));
+        &mov    ($__s2,@T[2]);         # s2^=s3|key[3];
+       &or     ($idx,@T[1]);
+        &and    (@T[2],&DWP(8,$key));
+       &xor    (@T[0],$idx);
+        &rotl   (@T[2],1);
+       &mov    ($__s0,@T[0]);          # s0^=s1|key[1];
+        &xor    (@T[3],@T[2]);
+       &mov    ($idx,&DWP(16,$key));           # prefetch key[4]
+        &mov    ($__s3,@T[3]);         # s3^=LeftRotate(s2&key[2],1);
+       &jmp    (&label("loop"));
+
+&set_label("done",8);
+       &mov    (@T[2],@T[0]);          # SwapHalf
+       &mov    (@T[3],@T[1]);
+       &mov    (@T[0],$__s2);
+       &mov    (@T[1],$__s3);
+       &xor    (@T[0],$idx);           # $idx is preloaded with key[0]
+       &xor    (@T[1],&DWP(4,$key));
+       &xor    (@T[2],&DWP(8,$key));
+       &xor    (@T[3],&DWP(12,$key));
+       &ret    ();
+&function_end_B("_x86_Camellia_encrypt");
+
+# void Camellia_DecryptBlock_Rounds(
+#              int grandRounds,
+#              const Byte ciphertext[],
+#              const KEY_TABLE_TYPE keyTable,
+#              Byte plaintext[])
+&function_begin("Camellia_DecryptBlock_Rounds");
+       &mov    ("eax",&wparam(0));     # load grandRounds
+       &mov    ($idx,&wparam(1));      # load ciphertext pointer
+       &mov    ($key,&wparam(2));      # load key schedule pointer
+
+       &mov    ("ebx","esp");
+       &sub    ("esp",7*4);            # place for s[0-3],keyEnd,esp and ra
+       &and    ("esp",-64);
+
+       # place stack frame just "above mod 1024" the key schedule
+       # this ensures that cache associativity of 2 suffices
+       &lea    ("ecx",&DWP(-64-63,$key));
+       &sub    ("ecx","esp");
+       &neg    ("ecx");
+       &and    ("ecx",0x3C0);  # modulo 1024, but aligned to cache-line
+       &sub    ("esp","ecx");
+       &add    ("esp",4);      # 4 is reserved for callee's return address
+
+       &shl    ("eax",6);
+       &mov    (&DWP(4*4,"esp"),$key); # save keyStart
+       &lea    ($key,&DWP(0,$key,"eax"));
+       &mov    (&DWP(5*4,"esp"),"ebx");# save %esp
+
+       &call   (&label("pic_point"));
+       &set_label("pic_point");
+       &blindpop($Tbl);
+       &lea    ($Tbl,&DWP(&label("Camellia_SBOX")."-".&label("pic_point"),$Tbl));
+
+       &mov    (@T[0],&DWP(0,$idx));   # load ciphertext
+       &mov    (@T[1],&DWP(4,$idx));
+       &mov    (@T[2],&DWP(8,$idx));
+       &bswap  (@T[0]);
+       &mov    (@T[3],&DWP(12,$idx));
+       &bswap  (@T[1]);
+       &bswap  (@T[2]);
+       &bswap  (@T[3]);
+
+       &call   ("_x86_Camellia_decrypt");
+
+       &mov    ("esp",&DWP(5*4,"esp"));
+       &bswap  (@T[0]);
+       &mov    ($idx,&wparam(3));      # load plaintext pointer
+       &bswap  (@T[1]);
+       &bswap  (@T[2]);
+       &bswap  (@T[3]);
+       &mov    (&DWP(0,$idx),@T[0]);   # write plaintext
+       &mov    (&DWP(4,$idx),@T[1]);
+       &mov    (&DWP(8,$idx),@T[2]);
+       &mov    (&DWP(12,$idx),@T[3]);
+&function_end("Camellia_DecryptBlock_Rounds");
+# V1.x API
+&function_begin_B("Camellia_DecryptBlock");
+       &mov    ("eax",128);
+       &sub    ("eax",&wparam(0));     # load keyBitLength
+       &mov    ("eax",3);
+       &adc    ("eax",0);              # keyBitLength==128?3:4
+       &mov    (&wparam(0),"eax");
+       &jmp    (&label("Camellia_DecryptBlock_Rounds"));
+&function_end_B("Camellia_DecryptBlock");
+
+if ($OPENSSL) {
+# void Camellia_decrypt(
+#              const unsigned char *in,
+#              unsigned char *out,
+#              const CAMELLIA_KEY *key)
+&function_begin("Camellia_decrypt");
+       &mov    ($idx,&wparam(0));      # load ciphertext pointer
+       &mov    ($key,&wparam(2));      # load key schedule pointer
+
+       &mov    ("ebx","esp");
+       &sub    ("esp",7*4);            # place for s[0-3],keyEnd,esp and ra
+       &and    ("esp",-64);
+       &mov    ("eax",&DWP(272,$key)); # load grandRounds counter
+
+       # place stack frame just "above mod 1024" the key schedule
+       # this ensures that cache associativity of 2 suffices
+       &lea    ("ecx",&DWP(-64-63,$key));
+       &sub    ("ecx","esp");
+       &neg    ("ecx");
+       &and    ("ecx",0x3C0);  # modulo 1024, but aligned to cache-line
+       &sub    ("esp","ecx");
+       &add    ("esp",4);      # 4 is reserved for callee's return address
+
+       &shl    ("eax",6);
+       &mov    (&DWP(4*4,"esp"),$key); # save keyStart
+       &lea    ($key,&DWP(0,$key,"eax"));
+       &mov    (&DWP(5*4,"esp"),"ebx");# save %esp
+
+       &call   (&label("pic_point"));
+       &set_label("pic_point");
+       &blindpop($Tbl);
+       &lea    ($Tbl,&DWP(&label("Camellia_SBOX")."-".&label("pic_point"),$Tbl));
+
+       &mov    (@T[0],&DWP(0,$idx));   # load ciphertext
+       &mov    (@T[1],&DWP(4,$idx));
+       &mov    (@T[2],&DWP(8,$idx));
+       &bswap  (@T[0]);
+       &mov    (@T[3],&DWP(12,$idx));
+       &bswap  (@T[1]);
+       &bswap  (@T[2]);
+       &bswap  (@T[3]);
+
+       &call   ("_x86_Camellia_decrypt");
+
+       &mov    ("esp",&DWP(5*4,"esp"));
+       &bswap  (@T[0]);
+       &mov    ($idx,&wparam(1));      # load plaintext pointer
+       &bswap  (@T[1]);
+       &bswap  (@T[2]);
+       &bswap  (@T[3]);
+       &mov    (&DWP(0,$idx),@T[0]);   # write plaintext
+       &mov    (&DWP(4,$idx),@T[1]);
+       &mov    (&DWP(8,$idx),@T[2]);
+       &mov    (&DWP(12,$idx),@T[3]);
+&function_end("Camellia_decrypt");
+}
+
+&function_begin_B("_x86_Camellia_decrypt");
+       &xor    (@T[0],&DWP(0,$key));   # ^=key[0-3]
+       &xor    (@T[1],&DWP(4,$key));
+       &xor    (@T[2],&DWP(8,$key));
+       &xor    (@T[3],&DWP(12,$key));
+       &mov    ($idx,&DWP(-8,$key));   # prefetch key[-2]
+
+       &mov    ($__s0,@T[0]);          # save s[0-3]
+       &mov    ($__s1,@T[1]);
+       &mov    ($__s2,@T[2]);
+       &mov    ($__s3,@T[3]);
+
+&set_label("loop",16);
+       for ($i=0;$i<6;$i++) { Camellia_Feistel($i,-8,4); }
+
+       &sub    ($key,16*4);
+       &cmp    ($key,$__end);
+       &je     (&label("done"));
+
+       # @T[0-1] are preloaded, $idx is preloaded with key[2]
+       &and    ($idx,@T[0]);
+        &mov    (@T[3],$__s3);
+       &rotl   ($idx,1);
+        &mov    (@T[2],@T[3]);
+       &xor    (@T[1],$idx);
+        &or     (@T[2],&DWP(4,$key));
+       &mov    ($__s1,@T[1]);          # s1^=LeftRotate(s0&key[0],1);
+        &xor    (@T[2],$__s2);
+
+       &mov    ($idx,&DWP(12,$key));
+        &mov    ($__s2,@T[2]);         # s2^=s3|key[3];
+       &or     ($idx,@T[1]);
+        &and    (@T[2],&DWP(0,$key));
+       &xor    (@T[0],$idx);
+        &rotl   (@T[2],1);
+       &mov    ($__s0,@T[0]);          # s0^=s1|key[1];
+        &xor    (@T[3],@T[2]);
+       &mov    ($idx,&DWP(-8,$key));   # prefetch key[4]
+        &mov    ($__s3,@T[3]);         # s3^=LeftRotate(s2&key[2],1);
+       &jmp    (&label("loop"));
+
+&set_label("done",8);
+       &mov    (@T[2],@T[0]);          # SwapHalf
+       &mov    (@T[3],@T[1]);
+       &mov    (@T[0],$__s2);
+       &mov    (@T[1],$__s3);
+       &xor    (@T[2],$idx);           # $idx is preloaded with key[2]
+       &xor    (@T[3],&DWP(12,$key));
+       &xor    (@T[0],&DWP(0,$key));
+       &xor    (@T[1],&DWP(4,$key));
+       &ret    ();
+&function_end_B("_x86_Camellia_decrypt");
+
+# shld is very slow on Intel P4 family. Even on AMD it limits
+# instruction decode rate [because it's VectorPath] and consequently
+# performance. PIII, PM and Core[2] seem to be the only ones which
+# execute this code ~7% faster...
+sub __rotl128 {
+  my ($i0,$i1,$i2,$i3,$rot,$rnd,@T)=@_;
+
+    $rnd *= 2;
+    if ($rot) {
+       &mov    ($idx,$i0);
+       &shld   ($i0,$i1,$rot);
+       &shld   ($i1,$i2,$rot);
+       &shld   ($i2,$i3,$rot);
+       &shld   ($i3,$idx,$rot);
+    }
+    &mov       (&DWP(-128+4*$rnd++,$key),shift(@T))    if ($i0 eq @T[0]);
+    &mov       (&DWP(-128+4*$rnd++,$key),shift(@T))    if ($i1 eq @T[0]);
+    &mov       (&DWP(-128+4*$rnd++,$key),shift(@T))    if ($i2 eq @T[0]);
+    &mov       (&DWP(-128+4*$rnd++,$key),shift(@T))    if ($i3 eq @T[0]);
+}
+
+# ... Implementing 128-bit rotate without shld gives >3x performance
+# improvement on P4, only ~7% degradation on other Intel CPUs and
+# not worse performance on AMD. This is therefore preferred.
+sub _rotl128 {
+  my ($i0,$i1,$i2,$i3,$rot,$rnd,@T)=@_;
+
+    $rnd *= 2;
+    if ($rot) {
+       &mov    ($Tbl,$i0);
+       &shl    ($i0,$rot);
+       &mov    ($idx,$i1);
+       &shr    ($idx,32-$rot);
+       &shl    ($i1,$rot);
+       &or     ($i0,$idx);
+       &mov    ($idx,$i2);
+       &shl    ($i2,$rot);
+       &mov    (&DWP(-128+4*$rnd++,$key),shift(@T))    if ($i0 eq @T[0]);
+       &shr    ($idx,32-$rot);
+       &or     ($i1,$idx);
+       &shr    ($Tbl,32-$rot);
+       &mov    ($idx,$i3);
+       &shr    ($idx,32-$rot);
+       &mov    (&DWP(-128+4*$rnd++,$key),shift(@T))    if ($i1 eq @T[0]);
+       &shl    ($i3,$rot);
+       &or     ($i2,$idx);
+       &or     ($i3,$Tbl);
+       &mov    (&DWP(-128+4*$rnd++,$key),shift(@T))    if ($i2 eq @T[0]);
+       &mov    (&DWP(-128+4*$rnd++,$key),shift(@T))    if ($i3 eq @T[0]);
+    } else {
+       &mov    (&DWP(-128+4*$rnd++,$key),shift(@T))    if ($i0 eq @T[0]);
+       &mov    (&DWP(-128+4*$rnd++,$key),shift(@T))    if ($i1 eq @T[0]);
+       &mov    (&DWP(-128+4*$rnd++,$key),shift(@T))    if ($i2 eq @T[0]);
+       &mov    (&DWP(-128+4*$rnd++,$key),shift(@T))    if ($i3 eq @T[0]);
+    }
+}
+
+sub _saveround {
+my ($rnd,$key,@T)=@_;
+my $bias=int(@T[0])?shift(@T):0;
+
+       &mov    (&DWP($bias+$rnd*8+0,$key),@T[0]);
+       &mov    (&DWP($bias+$rnd*8+4,$key),@T[1])       if ($#T>=1);
+       &mov    (&DWP($bias+$rnd*8+8,$key),@T[2])       if ($#T>=2);
+       &mov    (&DWP($bias+$rnd*8+12,$key),@T[3])      if ($#T>=3);
+}
+
+sub _loadround {
+my ($rnd,$key,@T)=@_;
+my $bias=int(@T[0])?shift(@T):0;
+
+       &mov    (@T[0],&DWP($bias+$rnd*8+0,$key));
+       &mov    (@T[1],&DWP($bias+$rnd*8+4,$key))       if ($#T>=1);
+       &mov    (@T[2],&DWP($bias+$rnd*8+8,$key))       if ($#T>=2);
+       &mov    (@T[3],&DWP($bias+$rnd*8+12,$key))      if ($#T>=3);
+}
+
+# void Camellia_Ekeygen(
+#              const int keyBitLength,
+#              const Byte *rawKey,
+#              KEY_TABLE_TYPE keyTable)
+&function_begin("Camellia_Ekeygen");
+{ my $step=0;
+
+       &stack_push(4);                         # place for s[0-3]
+
+       &mov    ($Tbl,&wparam(0));              # load arguments
+       &mov    ($idx,&wparam(1));
+       &mov    ($key,&wparam(2));
+
+       &mov    (@T[0],&DWP(0,$idx));           # load 0-127 bits
+       &mov    (@T[1],&DWP(4,$idx));
+       &mov    (@T[2],&DWP(8,$idx));
+       &mov    (@T[3],&DWP(12,$idx));
+
+       &bswap  (@T[0]);
+       &bswap  (@T[1]);
+       &bswap  (@T[2]);
+       &bswap  (@T[3]);
+
+       &_saveround     (0,$key,@T);            # KL<<<0
+
+       &cmp    ($Tbl,128);
+       &je     (&label("1st128"));
+
+       &mov    (@T[0],&DWP(16,$idx));          # load 128-191 bits
+       &mov    (@T[1],&DWP(20,$idx));
+       &cmp    ($Tbl,192);
+       &je     (&label("1st192"));
+       &mov    (@T[2],&DWP(24,$idx));          # load 192-255 bits
+       &mov    (@T[3],&DWP(28,$idx));
+       &jmp    (&label("1st256"));
+&set_label("1st192",4);
+       &mov    (@T[2],@T[0]);
+       &mov    (@T[3],@T[1]);
+       &not    (@T[2]);
+       &not    (@T[3]);
+&set_label("1st256",4);
+       &bswap  (@T[0]);
+       &bswap  (@T[1]);
+       &bswap  (@T[2]);
+       &bswap  (@T[3]);
+
+       &_saveround     (4,$key,@T);            # temporary storage for KR!
+
+       &xor    (@T[0],&DWP(0*8+0,$key));       # KR^KL
+       &xor    (@T[1],&DWP(0*8+4,$key));
+       &xor    (@T[2],&DWP(1*8+0,$key));
+       &xor    (@T[3],&DWP(1*8+4,$key));
+
+&set_label("1st128",4);
+       &call   (&label("pic_point"));
+       &set_label("pic_point");
+       &blindpop($Tbl);
+       &lea    ($Tbl,&DWP(&label("Camellia_SBOX")."-".&label("pic_point"),$Tbl));
+       &lea    ($key,&DWP(&label("Camellia_SIGMA")."-".&label("Camellia_SBOX"),$Tbl));
+
+       &mov    ($idx,&DWP($step*8,$key));      # prefetch SIGMA[0]
+       &mov    (&swtmp(0),@T[0]);              # save s[0-3]
+       &mov    (&swtmp(1),@T[1]);
+       &mov    (&swtmp(2),@T[2]);
+       &mov    (&swtmp(3),@T[3]);
+       &Camellia_Feistel($step++);
+       &Camellia_Feistel($step++);
+       &mov    (@T[2],&swtmp(2));
+       &mov    (@T[3],&swtmp(3));
+
+       &mov    ($idx,&wparam(2));
+       &xor    (@T[0],&DWP(0*8+0,$idx));       # ^KL
+       &xor    (@T[1],&DWP(0*8+4,$idx));
+       &xor    (@T[2],&DWP(1*8+0,$idx));
+       &xor    (@T[3],&DWP(1*8+4,$idx));
+
+       &mov    ($idx,&DWP($step*8,$key));      # prefetch SIGMA[4]
+       &mov    (&swtmp(0),@T[0]);              # save s[0-3]
+       &mov    (&swtmp(1),@T[1]);
+       &mov    (&swtmp(2),@T[2]);
+       &mov    (&swtmp(3),@T[3]);
+       &Camellia_Feistel($step++);
+       &Camellia_Feistel($step++);
+       &mov    (@T[2],&swtmp(2));
+       &mov    (@T[3],&swtmp(3));
+
+       &mov    ($idx,&wparam(0));
+       &cmp    ($idx,128);
+       &jne    (&label("2nd256"));
+
+       &mov    ($key,&wparam(2));
+       &lea    ($key,&DWP(128,$key));          # size optimization
+
+       ####### process KA
+       &_saveround     (2,$key,-128,@T);       # KA<<<0
+       &_rotl128       (@T,15,6,@T);           # KA<<<15
+       &_rotl128       (@T,15,8,@T);           # KA<<<(15+15=30)
+       &_rotl128       (@T,15,12,@T[0],@T[1]); # KA<<<(30+15=45)
+       &_rotl128       (@T,15,14,@T);          # KA<<<(45+15=60)
+       push            (@T,shift(@T));         # rotl128(@T,32);
+       &_rotl128       (@T,2,20,@T);           # KA<<<(60+32+2=94)
+       &_rotl128       (@T,17,24,@T);          # KA<<<(94+17=111)
+
+       ####### process KL
+       &_loadround     (0,$key,-128,@T);       # load KL
+       &_rotl128       (@T,15,4,@T);           # KL<<<15
+       &_rotl128       (@T,30,10,@T);          # KL<<<(15+30=45)
+       &_rotl128       (@T,15,13,@T[2],@T[3]); # KL<<<(45+15=60)
+       &_rotl128       (@T,17,16,@T);          # KL<<<(60+17=77)
+       &_rotl128       (@T,17,18,@T);          # KL<<<(77+17=94)
+       &_rotl128       (@T,17,22,@T);          # KL<<<(94+17=111)
+
+       while (@T[0] ne "eax")                  # restore order
+       {   unshift     (@T,pop(@T));   }
+
+       &mov    ("eax",3);                      # 3 grandRounds
+       &jmp    (&label("done"));
+
+&set_label("2nd256",16);
+       &mov    ($idx,&wparam(2));
+       &_saveround     (6,$idx,@T);            # temporary storage for KA!
+
+       &xor    (@T[0],&DWP(4*8+0,$idx));       # KA^KR
+       &xor    (@T[1],&DWP(4*8+4,$idx));
+       &xor    (@T[2],&DWP(5*8+0,$idx));
+       &xor    (@T[3],&DWP(5*8+4,$idx));
+
+       &mov    ($idx,&DWP($step*8,$key));      # prefetch SIGMA[8]
+       &mov    (&swtmp(0),@T[0]);              # save s[0-3]
+       &mov    (&swtmp(1),@T[1]);
+       &mov    (&swtmp(2),@T[2]);
+       &mov    (&swtmp(3),@T[3]);
+       &Camellia_Feistel($step++);
+       &Camellia_Feistel($step++);
+       &mov    (@T[2],&swtmp(2));
+       &mov    (@T[3],&swtmp(3));
+
+       &mov    ($key,&wparam(2));
+       &lea    ($key,&DWP(128,$key));          # size optimization
+
+       ####### process KB
+       &_saveround     (2,$key,-128,@T);       # KB<<<0
+       &_rotl128       (@T,30,10,@T);          # KB<<<30
+       &_rotl128       (@T,30,20,@T);          # KB<<<(30+30=60)
+       push            (@T,shift(@T));         # rotl128(@T,32);
+       &_rotl128       (@T,19,32,@T);          # KB<<<(60+32+19=111)
+
+       ####### process KR
+       &_loadround     (4,$key,-128,@T);       # load KR
+       &_rotl128       (@T,15,4,@T);           # KR<<<15
+       &_rotl128       (@T,15,8,@T);           # KR<<<(15+15=30)
+       &_rotl128       (@T,30,18,@T);          # KR<<<(30+30=60)
+       push            (@T,shift(@T));         # rotl128(@T,32);
+       &_rotl128       (@T,2,26,@T);           # KR<<<(60+32+2=94)
+
+       ####### process KA
+       &_loadround     (6,$key,-128,@T);       # load KA
+       &_rotl128       (@T,15,6,@T);           # KA<<<15
+       &_rotl128       (@T,30,14,@T);          # KA<<<(15+30=45)
+       push            (@T,shift(@T));         # rotl128(@T,32);
+       &_rotl128       (@T,0,24,@T);           # KA<<<(45+32+0=77)
+       &_rotl128       (@T,17,28,@T);          # KA<<<(77+17=94)
+
+       ####### process KL
+       &_loadround     (0,$key,-128,@T);       # load KL
+       push            (@T,shift(@T));         # rotl128(@T,32);
+       &_rotl128       (@T,13,12,@T);          # KL<<<(32+13=45)
+       &_rotl128       (@T,15,16,@T);          # KL<<<(45+15=60)
+       &_rotl128       (@T,17,22,@T);          # KL<<<(60+17=77)
+       push            (@T,shift(@T));         # rotl128(@T,32);
+       &_rotl128       (@T,2,30,@T);           # KL<<<(77+32+2=111)
+
+       while (@T[0] ne "eax")                  # restore order
+       {   unshift     (@T,pop(@T));   }
+
+       &mov    ("eax",4);                      # 4 grandRounds
+&set_label("done");
+       &lea    ("edx",&DWP(272-128,$key));     # end of key schedule
+       &stack_pop(4);
+}
+&function_end("Camellia_Ekeygen");
+
+if ($OPENSSL) {
+# int Camellia_set_key (
+#              const unsigned char *userKey,
+#              int bits,
+#              CAMELLIA_KEY *key)
+&function_begin_B("Camellia_set_key");
+       &push   ("ebx");
+       &mov    ("ecx",&wparam(0));     # pull arguments
+       &mov    ("ebx",&wparam(1));
+       &mov    ("edx",&wparam(2));
+
+       &mov    ("eax",-1);
+       &test   ("ecx","ecx");
+       &jz     (&label("done"));       # userKey==NULL?
+       &test   ("edx","edx");
+       &jz     (&label("done"));       # key==NULL?
+
+       &mov    ("eax",-2);
+       &cmp    ("ebx",256);
+       &je     (&label("arg_ok"));     # bits==256?
+       &cmp    ("ebx",192);
+       &je     (&label("arg_ok"));     # bits==192?
+       &cmp    ("ebx",128);
+       &jne    (&label("done"));       # bits!=128?
+&set_label("arg_ok",4);
+
+       &push   ("edx");                # push arguments
+       &push   ("ecx");
+       &push   ("ebx");
+       &call   ("Camellia_Ekeygen");
+       &stack_pop(3);
+
+       # eax holds grandRounds and edx points at where to put it
+       &mov    (&DWP(0,"edx"),"eax");
+       &xor    ("eax","eax");
+&set_label("done",4);
+       &pop    ("ebx");
+       &ret    ();
+&function_end_B("Camellia_set_key");
+}
+
+@SBOX=(
+112,130, 44,236,179, 39,192,229,228,133, 87, 53,234, 12,174, 65,
+ 35,239,107,147, 69, 25,165, 33,237, 14, 79, 78, 29,101,146,189,
+134,184,175,143,124,235, 31,206, 62, 48,220, 95, 94,197, 11, 26,
+166,225, 57,202,213, 71, 93, 61,217,  1, 90,214, 81, 86,108, 77,
+139, 13,154,102,251,204,176, 45,116, 18, 43, 32,240,177,132,153,
+223, 76,203,194, 52,126,118,  5,109,183,169, 49,209, 23,  4,215,
+ 20, 88, 58, 97,222, 27, 17, 28, 50, 15,156, 22, 83, 24,242, 34,
+254, 68,207,178,195,181,122,145, 36,  8,232,168, 96,252,105, 80,
+170,208,160,125,161,137, 98,151, 84, 91, 30,149,224,255,100,210,
+ 16,196,  0, 72,163,247,117,219,138,  3,230,218,  9, 63,221,148,
+135, 92,131,  2,205, 74,144, 51,115,103,246,243,157,127,191,226,
+ 82,155,216, 38,200, 55,198, 59,129,150,111, 75, 19,190, 99, 46,
+233,121,167,140,159,110,188,142, 41,245,249,182, 47,253,180, 89,
+120,152,  6,106,231, 70,113,186,212, 37,171, 66,136,162,141,250,
+114,  7,185, 85,248,238,172, 10, 54, 73, 42,104, 60, 56,241,164,
+ 64, 40,211,123,187,201, 67,193, 21,227,173,244,119,199,128,158);
+
+sub S1110 { my $i=shift; $i=@SBOX[$i]; return $i<<24|$i<<16|$i<<8; }
+sub S4404 { my $i=shift; $i=($i<<1|$i>>7)&0xff; $i=@SBOX[$i]; return $i<<24|$i<<16|$i; }       
+sub S0222 { my $i=shift; $i=@SBOX[$i]; $i=($i<<1|$i>>7)&0xff; return $i<<16|$i<<8|$i; }        
+sub S3033 { my $i=shift; $i=@SBOX[$i]; $i=($i>>1|$i<<7)&0xff; return $i<<24|$i<<8|$i; }        
+
+&set_label("Camellia_SIGMA",64);
+&data_word(
+    0xa09e667f, 0x3bcc908b, 0xb67ae858, 0x4caa73b2,
+    0xc6ef372f, 0xe94f82be, 0x54ff53a5, 0xf1d36f1c,
+    0x10e527fa, 0xde682d1d, 0xb05688c2, 0xb3e6c1fd,
+    0,          0,          0,          0);
+&set_label("Camellia_SBOX",64);
+# tables are interleaved, remember?
+for ($i=0;$i<256;$i++) { &data_word(&S1110($i),&S4404($i)); }
+for ($i=0;$i<256;$i++) { &data_word(&S0222($i),&S3033($i)); }
+
+# void Camellia_cbc_encrypt (const void char *inp, unsigned char *out,
+#                      size_t length, const CAMELLIA_KEY *key,
+#                      unsigned char *ivp,const int enc);
+{
+# stack frame layout
+#             -4(%esp)         # return address         0(%esp)
+#              0(%esp)         # s0                     4(%esp)
+#              4(%esp)         # s1                     8(%esp)
+#              8(%esp)         # s2                    12(%esp)
+#             12(%esp)         # s3                    16(%esp)
+#             16(%esp)         # end of key schedule   20(%esp)
+#             20(%esp)         # %esp backup
+my $_inp=&DWP(24,"esp");       #copy of wparam(0)
+my $_out=&DWP(28,"esp");       #copy of wparam(1)
+my $_len=&DWP(32,"esp");       #copy of wparam(2)
+my $_key=&DWP(36,"esp");       #copy of wparam(3)
+my $_ivp=&DWP(40,"esp");       #copy of wparam(4)
+my $ivec=&DWP(44,"esp");       #ivec[16]
+my $_tmp=&DWP(44,"esp");       #volatile variable [yes, aliases with ivec]
+my ($s0,$s1,$s2,$s3) = @T;
+
+&function_begin("Camellia_cbc_encrypt");
+       &mov    ($s2 eq "ecx"? $s2 : "",&wparam(2));    # load len
+       &cmp    ($s2,0);
+       &je     (&label("enc_out"));
+
+       &pushf  ();
+       &cld    ();
+
+       &mov    ($s0,&wparam(0));       # load inp
+       &mov    ($s1,&wparam(1));       # load out
+       #&mov   ($s2,&wparam(2));       # load len
+       &mov    ($s3,&wparam(3));       # load key
+       &mov    ($Tbl,&wparam(4));      # load ivp
+
+       # allocate aligned stack frame...
+       &lea    ($idx,&DWP(-64,"esp"));
+       &and    ($idx,-64);
+
+       # place stack frame just "above mod 1024" the key schedule
+       # this ensures that cache associativity of 2 suffices
+       &lea    ($key,&DWP(-64-63,$s3));
+       &sub    ($key,$idx);
+       &neg    ($key);
+       &and    ($key,0x3C0);   # modulo 1024, but aligned to cache-line
+       &sub    ($idx,$key);
+
+       &mov    ($key,&wparam(5));      # load enc
+
+       &exch   ("esp",$idx);
+       &add    ("esp",4);              # reserve for return address!
+       &mov    ($_esp,$idx);           # save %esp
+
+       &mov    ($_inp,$s0);            # save copy of inp
+       &mov    ($_out,$s1);            # save copy of out
+       &mov    ($_len,$s2);            # save copy of len
+       &mov    ($_key,$s3);            # save copy of key
+       &mov    ($_ivp,$Tbl);           # save copy of ivp
+
+       &call   (&label("pic_point"));  # make it PIC!
+       &set_label("pic_point");
+       &blindpop($Tbl);
+       &lea    ($Tbl,&DWP(&label("Camellia_SBOX")."-".&label("pic_point"),$Tbl));
+
+       &mov    ($idx,32);
+       &set_label("prefetch_sbox",4);
+               &mov    ($s0,&DWP(0,$Tbl));
+               &mov    ($s1,&DWP(32,$Tbl));
+               &mov    ($s2,&DWP(64,$Tbl));
+               &mov    ($s3,&DWP(96,$Tbl));
+               &lea    ($Tbl,&DWP(128,$Tbl));
+               &dec    ($idx);
+       &jnz    (&label("prefetch_sbox"));
+       &mov    ($s0,$_key);
+       &sub    ($Tbl,4096);
+       &mov    ($idx,$_inp);
+       &mov    ($s3,&DWP(272,$s0));            # load grandRounds
+
+       &cmp    ($key,0);
+       &je     (&label("DECRYPT"));
+
+       &mov    ($s2,$_len);
+       &mov    ($key,$_ivp);
+       &shl    ($s3,6);
+       &lea    ($s3,&DWP(0,$s0,$s3));
+       &mov    ($_end,$s3);
+
+       &test   ($s2,0xFFFFFFF0);
+       &jz     (&label("enc_tail"));           # short input...
+
+       &mov    ($s0,&DWP(0,$key));             # load iv
+       &mov    ($s1,&DWP(4,$key));
+
+       &set_label("enc_loop",4);
+               &mov    ($s2,&DWP(8,$key));
+               &mov    ($s3,&DWP(12,$key));
+
+               &xor    ($s0,&DWP(0,$idx));     # xor input data
+               &xor    ($s1,&DWP(4,$idx));
+               &xor    ($s2,&DWP(8,$idx));
+               &bswap  ($s0);
+               &xor    ($s3,&DWP(12,$idx));
+               &bswap  ($s1);
+               &mov    ($key,$_key);           # load key
+               &bswap  ($s2);
+               &bswap  ($s3);
+
+               &call   ("_x86_Camellia_encrypt");
+
+               &mov    ($idx,$_inp);           # load inp
+               &mov    ($key,$_out);           # load out
+
+               &bswap  ($s0);
+               &bswap  ($s1);
+               &bswap  ($s2);
+               &mov    (&DWP(0,$key),$s0);     # save output data
+               &bswap  ($s3);
+               &mov    (&DWP(4,$key),$s1);
+               &mov    (&DWP(8,$key),$s2);
+               &mov    (&DWP(12,$key),$s3);
+
+               &mov    ($s2,$_len);            # load len
+
+               &lea    ($idx,&DWP(16,$idx));
+               &mov    ($_inp,$idx);           # save inp
+
+               &lea    ($s3,&DWP(16,$key));
+               &mov    ($_out,$s3);            # save out
+
+               &sub    ($s2,16);
+               &test   ($s2,0xFFFFFFF0);
+               &mov    ($_len,$s2);            # save len
+       &jnz    (&label("enc_loop"));
+       &test   ($s2,15);
+       &jnz    (&label("enc_tail"));
+       &mov    ($idx,$_ivp);           # load ivp
+       &mov    ($s2,&DWP(8,$key));     # restore last dwords
+       &mov    ($s3,&DWP(12,$key));
+       &mov    (&DWP(0,$idx),$s0);     # save ivec
+       &mov    (&DWP(4,$idx),$s1);
+       &mov    (&DWP(8,$idx),$s2);
+       &mov    (&DWP(12,$idx),$s3);
+
+       &mov    ("esp",$_esp);
+       &popf   ();
+    &set_label("enc_out");
+       &function_end_A();
+       &pushf  ();                     # kludge, never executed
+
+    &set_label("enc_tail",4);
+       &mov    ($s0,$key eq "edi" ? $key : "");
+       &mov    ($key,$_out);                   # load out
+       &push   ($s0);                          # push ivp
+       &mov    ($s1,16);
+       &sub    ($s1,$s2);
+       &cmp    ($key,$idx);                    # compare with inp
+       &je     (&label("enc_in_place"));
+       &align  (4);
+       &data_word(0xA4F3F689); # rep movsb     # copy input
+       &jmp    (&label("enc_skip_in_place"));
+    &set_label("enc_in_place");
+       &lea    ($key,&DWP(0,$key,$s2));
+    &set_label("enc_skip_in_place");
+       &mov    ($s2,$s1);
+       &xor    ($s0,$s0);
+       &align  (4);
+       &data_word(0xAAF3F689); # rep stosb     # zero tail
+       &pop    ($key);                         # pop ivp
+
+       &mov    ($idx,$_out);                   # output as input
+       &mov    ($s0,&DWP(0,$key));
+       &mov    ($s1,&DWP(4,$key));
+       &mov    ($_len,16);                     # len=16
+       &jmp    (&label("enc_loop"));           # one more spin...
+
+#----------------------------- DECRYPT -----------------------------#
+&set_label("DECRYPT",16);
+       &shl    ($s3,6);
+       &lea    ($s3,&DWP(0,$s0,$s3));
+       &mov    ($_end,$s0);
+       &mov    ($_key,$s3);
+
+       &cmp    ($idx,$_out);
+       &je     (&label("dec_in_place"));       # in-place processing...
+
+       &mov    ($key,$_ivp);                   # load ivp
+       &mov    ($_tmp,$key);
+
+       &set_label("dec_loop",4);
+               &mov    ($s0,&DWP(0,$idx));     # read input
+               &mov    ($s1,&DWP(4,$idx));
+               &mov    ($s2,&DWP(8,$idx));
+               &bswap  ($s0);
+               &mov    ($s3,&DWP(12,$idx));
+               &bswap  ($s1);
+               &mov    ($key,$_key);           # load key
+               &bswap  ($s2);
+               &bswap  ($s3);
+
+               &call   ("_x86_Camellia_decrypt");
+
+               &mov    ($key,$_tmp);           # load ivp
+               &mov    ($idx,$_len);           # load len
+
+               &bswap  ($s0);
+               &bswap  ($s1);
+               &bswap  ($s2);
+               &xor    ($s0,&DWP(0,$key));     # xor iv
+               &bswap  ($s3);
+               &xor    ($s1,&DWP(4,$key));
+               &xor    ($s2,&DWP(8,$key));
+               &xor    ($s3,&DWP(12,$key));
+
+               &sub    ($idx,16);
+               &jc     (&label("dec_partial"));
+               &mov    ($_len,$idx);           # save len
+               &mov    ($idx,$_inp);           # load inp
+               &mov    ($key,$_out);           # load out
+
+               &mov    (&DWP(0,$key),$s0);     # write output
+               &mov    (&DWP(4,$key),$s1);
+               &mov    (&DWP(8,$key),$s2);
+               &mov    (&DWP(12,$key),$s3);
+
+               &mov    ($_tmp,$idx);           # save ivp
+               &lea    ($idx,&DWP(16,$idx));
+               &mov    ($_inp,$idx);           # save inp
+
+               &lea    ($key,&DWP(16,$key));
+               &mov    ($_out,$key);           # save out
+
+       &jnz    (&label("dec_loop"));
+       &mov    ($key,$_tmp);           # load temp ivp
+    &set_label("dec_end");
+       &mov    ($idx,$_ivp);           # load user ivp
+       &mov    ($s0,&DWP(0,$key));     # load iv
+       &mov    ($s1,&DWP(4,$key));
+       &mov    ($s2,&DWP(8,$key));
+       &mov    ($s3,&DWP(12,$key));
+       &mov    (&DWP(0,$idx),$s0);     # copy back to user
+       &mov    (&DWP(4,$idx),$s1);
+       &mov    (&DWP(8,$idx),$s2);
+       &mov    (&DWP(12,$idx),$s3);
+       &jmp    (&label("dec_out"));
+
+    &set_label("dec_partial",4);
+       &lea    ($key,$ivec);
+       &mov    (&DWP(0,$key),$s0);     # dump output to stack
+       &mov    (&DWP(4,$key),$s1);
+       &mov    (&DWP(8,$key),$s2);
+       &mov    (&DWP(12,$key),$s3);
+       &lea    ($s2 eq "ecx" ? $s2 : "",&DWP(16,$idx));
+       &mov    ($idx eq "esi" ? $idx : "",$key);
+       &mov    ($key eq "edi" ? $key : "",$_out);      # load out
+       &data_word(0xA4F3F689); # rep movsb             # copy output
+       &mov    ($key,$_inp);                           # use inp as temp ivp
+       &jmp    (&label("dec_end"));
+
+    &set_label("dec_in_place",4);
+       &set_label("dec_in_place_loop");
+               &lea    ($key,$ivec);
+               &mov    ($s0,&DWP(0,$idx));     # read input
+               &mov    ($s1,&DWP(4,$idx));
+               &mov    ($s2,&DWP(8,$idx));
+               &mov    ($s3,&DWP(12,$idx));
+
+               &mov    (&DWP(0,$key),$s0);     # copy to temp
+               &mov    (&DWP(4,$key),$s1);
+               &mov    (&DWP(8,$key),$s2);
+               &bswap  ($s0);
+               &mov    (&DWP(12,$key),$s3);
+               &bswap  ($s1);
+               &mov    ($key,$_key);           # load key
+               &bswap  ($s2);
+               &bswap  ($s3);
+
+               &call   ("_x86_Camellia_decrypt");
+
+               &mov    ($key,$_ivp);           # load ivp
+               &mov    ($idx,$_out);           # load out
+
+               &bswap  ($s0);
+               &bswap  ($s1);
+               &bswap  ($s2);
+               &xor    ($s0,&DWP(0,$key));     # xor iv
+               &bswap  ($s3);
+               &xor    ($s1,&DWP(4,$key));
+               &xor    ($s2,&DWP(8,$key));
+               &xor    ($s3,&DWP(12,$key));
+
+               &mov    (&DWP(0,$idx),$s0);     # write output
+               &mov    (&DWP(4,$idx),$s1);
+               &mov    (&DWP(8,$idx),$s2);
+               &mov    (&DWP(12,$idx),$s3);
+
+               &lea    ($idx,&DWP(16,$idx));
+               &mov    ($_out,$idx);           # save out
+
+               &lea    ($idx,$ivec);
+               &mov    ($s0,&DWP(0,$idx));     # read temp
+               &mov    ($s1,&DWP(4,$idx));
+               &mov    ($s2,&DWP(8,$idx));
+               &mov    ($s3,&DWP(12,$idx));
+
+               &mov    (&DWP(0,$key),$s0);     # copy iv
+               &mov    (&DWP(4,$key),$s1);
+               &mov    (&DWP(8,$key),$s2);
+               &mov    (&DWP(12,$key),$s3);
+
+               &mov    ($idx,$_inp);           # load inp
+
+               &lea    ($idx,&DWP(16,$idx));
+               &mov    ($_inp,$idx);           # save inp
+
+               &mov    ($s2,$_len);            # load len
+               &sub    ($s2,16);
+               &jc     (&label("dec_in_place_partial"));
+               &mov    ($_len,$s2);            # save len
+       &jnz    (&label("dec_in_place_loop"));
+       &jmp    (&label("dec_out"));
+
+    &set_label("dec_in_place_partial",4);
+       # one can argue if this is actually required...
+       &mov    ($key eq "edi" ? $key : "",$_out);
+       &lea    ($idx eq "esi" ? $idx : "",$ivec);
+       &lea    ($key,&DWP(0,$key,$s2));
+       &lea    ($idx,&DWP(16,$idx,$s2));
+       &neg    ($s2 eq "ecx" ? $s2 : "");
+       &data_word(0xA4F3F689); # rep movsb     # restore tail
+
+    &set_label("dec_out",4);
+    &mov       ("esp",$_esp);
+    &popf      ();
+&function_end("Camellia_cbc_encrypt");
+}
+
+&asciz("Camellia for x86 by <appro\@openssl.org>");
+
+&asm_finish();
diff --git a/deps/openssl/openssl/crypto/camellia/asm/cmll-x86_64.pl b/deps/openssl/openssl/crypto/camellia/asm/cmll-x86_64.pl
new file mode 100644 (file)
index 0000000..76955e4
--- /dev/null
@@ -0,0 +1,1080 @@
+#!/usr/bin/env perl
+
+# ====================================================================
+# Copyright (c) 2008 Andy Polyakov <appro@openssl.org>
+#
+# This module may be used under the terms of either the GNU General
+# Public License version 2 or later, the GNU Lesser General Public
+# License version 2.1 or later, the Mozilla Public License version
+# 1.1 or the BSD License. The exact terms of either license are
+# distributed along with this module. For further details see
+# http://www.openssl.org/~appro/camellia/.
+# ====================================================================
+
+# Performance in cycles per processed byte (less is better) in
+# 'openssl speed ...' benchmark:
+#
+#                      AMD64   Core2   EM64T
+# -evp camellia-128-ecb        16.7    21.0    22.7
+# + over gcc 3.4.6     +25%    +5%     0%
+#
+# camellia-128-cbc     15.7    20.4    21.1
+#
+# 128-bit key setup    128     216     205     cycles/key
+# + over gcc 3.4.6     +54%    +39%    +15%
+#
+# Numbers in "+" rows represent performance improvement over compiler
+# generated code. Key setup timings are impressive on AMD and Core2
+# thanks to 64-bit operations being covertly deployed. Improvement on
+# EM64T, pre-Core2 Intel x86_64 CPU, is not as impressive, because it
+# apparently emulates some of 64-bit operations in [32-bit] microcode.
+
+$flavour = shift;
+$output  = shift;
+if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
+
+$win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
+
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+( $xlate="${dir}x86_64-xlate.pl" and -f $xlate ) or
+( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
+die "can't locate x86_64-xlate.pl";
+
+open STDOUT,"| $^X $xlate $flavour $output";
+
+sub hi() { my $r=shift; $r =~ s/%[er]([a-d])x/%\1h/;    $r; }
+sub lo() { my $r=shift; $r =~ s/%[er]([a-d])x/%\1l/;
+                        $r =~ s/%[er]([sd]i)/%\1l/;
+                        $r =~ s/%(r[0-9]+)[d]?/%\1b/;   $r; }
+
+$t0="%eax";$t1="%ebx";$t2="%ecx";$t3="%edx";
+@S=("%r8d","%r9d","%r10d","%r11d");
+$i0="%esi";
+$i1="%edi";
+$Tbl="%rbp";   # size optimization
+$inp="%r12";
+$out="%r13";
+$key="%r14";
+$keyend="%r15";
+$arg0d=$win64?"%ecx":"%edi";
+
+# const unsigned int Camellia_SBOX[4][256];
+# Well, sort of... Camellia_SBOX[0][] is interleaved with [1][],
+# and [2][] - with [3][]. This is done to minimize code size.
+$SBOX1_1110=0;         # Camellia_SBOX[0]
+$SBOX4_4404=4;         # Camellia_SBOX[1]
+$SBOX2_0222=2048;      # Camellia_SBOX[2]
+$SBOX3_3033=2052;      # Camellia_SBOX[3]
+
+sub Camellia_Feistel {
+my $i=@_[0];
+my $seed=defined(@_[1])?@_[1]:0;
+my $scale=$seed<0?-8:8;
+my $j=($i&1)*2;
+my $s0=@S[($j)%4],$s1=@S[($j+1)%4],$s2=@S[($j+2)%4],$s3=@S[($j+3)%4];
+
+$code.=<<___;
+       xor     $s0,$t0                         # t0^=key[0]
+       xor     $s1,$t1                         # t1^=key[1]
+       movz    `&hi("$t0")`,$i0                # (t0>>8)&0xff
+       movz    `&lo("$t1")`,$i1                # (t1>>0)&0xff
+       mov     $SBOX3_3033($Tbl,$i0,8),$t3     # t3=SBOX3_3033[0]
+       mov     $SBOX1_1110($Tbl,$i1,8),$t2     # t2=SBOX1_1110[1]
+       movz    `&lo("$t0")`,$i0                # (t0>>0)&0xff
+       shr     \$16,$t0
+       movz    `&hi("$t1")`,$i1                # (t1>>8)&0xff
+       xor     $SBOX4_4404($Tbl,$i0,8),$t3     # t3^=SBOX4_4404[0]
+       shr     \$16,$t1
+       xor     $SBOX4_4404($Tbl,$i1,8),$t2     # t2^=SBOX4_4404[1]
+       movz    `&hi("$t0")`,$i0                # (t0>>24)&0xff
+       movz    `&lo("$t1")`,$i1                # (t1>>16)&0xff
+       xor     $SBOX1_1110($Tbl,$i0,8),$t3     # t3^=SBOX1_1110[0]
+       xor     $SBOX3_3033($Tbl,$i1,8),$t2     # t2^=SBOX3_3033[1]
+       movz    `&lo("$t0")`,$i0                # (t0>>16)&0xff
+       movz    `&hi("$t1")`,$i1                # (t1>>24)&0xff
+       xor     $SBOX2_0222($Tbl,$i0,8),$t3     # t3^=SBOX2_0222[0]
+       xor     $SBOX2_0222($Tbl,$i1,8),$t2     # t2^=SBOX2_0222[1]
+       mov     `$seed+($i+1)*$scale`($key),$t1 # prefetch key[i+1]
+       mov     `$seed+($i+1)*$scale+4`($key),$t0
+       xor     $t3,$t2                         # t2^=t3
+       ror     \$8,$t3                         # t3=RightRotate(t3,8)
+       xor     $t2,$s2
+       xor     $t2,$s3
+       xor     $t3,$s3
+___
+}
+
+# void Camellia_EncryptBlock_Rounds(
+#              int grandRounds,
+#              const Byte plaintext[],
+#              const KEY_TABLE_TYPE keyTable,
+#              Byte ciphertext[])
+$code=<<___;
+.text
+
+# V1.x API
+.globl Camellia_EncryptBlock
+.type  Camellia_EncryptBlock,\@abi-omnipotent
+.align 16
+Camellia_EncryptBlock:
+       movl    \$128,%eax
+       subl    $arg0d,%eax
+       movl    \$3,$arg0d
+       adcl    \$0,$arg0d      # keyBitLength==128?3:4
+       jmp     .Lenc_rounds
+.size  Camellia_EncryptBlock,.-Camellia_EncryptBlock
+# V2
+.globl Camellia_EncryptBlock_Rounds
+.type  Camellia_EncryptBlock_Rounds,\@function,4
+.align 16
+.Lenc_rounds:
+Camellia_EncryptBlock_Rounds:
+       push    %rbx
+       push    %rbp
+       push    %r13
+       push    %r14
+       push    %r15
+.Lenc_prologue:
+
+       #mov    %rsi,$inp               # put away arguments
+       mov     %rcx,$out
+       mov     %rdx,$key
+
+       shl     \$6,%edi                # process grandRounds
+       lea     .LCamellia_SBOX(%rip),$Tbl
+       lea     ($key,%rdi),$keyend
+
+       mov     0(%rsi),@S[0]           # load plaintext
+       mov     4(%rsi),@S[1]
+       mov     8(%rsi),@S[2]
+       bswap   @S[0]
+       mov     12(%rsi),@S[3]
+       bswap   @S[1]
+       bswap   @S[2]
+       bswap   @S[3]
+
+       call    _x86_64_Camellia_encrypt
+
+       bswap   @S[0]
+       bswap   @S[1]
+       bswap   @S[2]
+       mov     @S[0],0($out)
+       bswap   @S[3]
+       mov     @S[1],4($out)
+       mov     @S[2],8($out)
+       mov     @S[3],12($out)
+
+       mov     0(%rsp),%r15
+       mov     8(%rsp),%r14
+       mov     16(%rsp),%r13
+       mov     24(%rsp),%rbp
+       mov     32(%rsp),%rbx
+       lea     40(%rsp),%rsp
+.Lenc_epilogue:
+       ret
+.size  Camellia_EncryptBlock_Rounds,.-Camellia_EncryptBlock_Rounds
+
+.type  _x86_64_Camellia_encrypt,\@abi-omnipotent
+.align 16
+_x86_64_Camellia_encrypt:
+       xor     0($key),@S[1]
+       xor     4($key),@S[0]           # ^=key[0-3]
+       xor     8($key),@S[3]
+       xor     12($key),@S[2]
+.align 16
+.Leloop:
+       mov     16($key),$t1            # prefetch key[4-5]
+       mov     20($key),$t0
+
+___
+       for ($i=0;$i<6;$i++) { Camellia_Feistel($i,16); }
+$code.=<<___;
+       lea     16*4($key),$key
+       cmp     $keyend,$key
+       mov     8($key),$t3             # prefetch key[2-3]
+       mov     12($key),$t2
+       je      .Ledone
+
+       and     @S[0],$t0
+       or      @S[3],$t3
+       rol     \$1,$t0
+       xor     $t3,@S[2]               # s2^=s3|key[3];
+       xor     $t0,@S[1]               # s1^=LeftRotate(s0&key[0],1);
+       and     @S[2],$t2
+       or      @S[1],$t1
+       rol     \$1,$t2
+       xor     $t1,@S[0]               # s0^=s1|key[1];
+       xor     $t2,@S[3]               # s3^=LeftRotate(s2&key[2],1);
+       jmp     .Leloop
+
+.align 16
+.Ledone:
+       xor     @S[2],$t0               # SwapHalf
+       xor     @S[3],$t1
+       xor     @S[0],$t2
+       xor     @S[1],$t3
+
+       mov     $t0,@S[0]
+       mov     $t1,@S[1]
+       mov     $t2,@S[2]
+       mov     $t3,@S[3]
+
+       .byte   0xf3,0xc3               # rep ret
+.size  _x86_64_Camellia_encrypt,.-_x86_64_Camellia_encrypt
+
+# V1.x API
+.globl Camellia_DecryptBlock
+.type  Camellia_DecryptBlock,\@abi-omnipotent
+.align 16
+Camellia_DecryptBlock:
+       movl    \$128,%eax
+       subl    $arg0d,%eax
+       movl    \$3,$arg0d
+       adcl    \$0,$arg0d      # keyBitLength==128?3:4
+       jmp     .Ldec_rounds
+.size  Camellia_DecryptBlock,.-Camellia_DecryptBlock
+# V2
+.globl Camellia_DecryptBlock_Rounds
+.type  Camellia_DecryptBlock_Rounds,\@function,4
+.align 16
+.Ldec_rounds:
+Camellia_DecryptBlock_Rounds:
+       push    %rbx
+       push    %rbp
+       push    %r13
+       push    %r14
+       push    %r15
+.Ldec_prologue:
+
+       #mov    %rsi,$inp               # put away arguments
+       mov     %rcx,$out
+       mov     %rdx,$keyend
+
+       shl     \$6,%edi                # process grandRounds
+       lea     .LCamellia_SBOX(%rip),$Tbl
+       lea     ($keyend,%rdi),$key
+
+       mov     0(%rsi),@S[0]           # load plaintext
+       mov     4(%rsi),@S[1]
+       mov     8(%rsi),@S[2]
+       bswap   @S[0]
+       mov     12(%rsi),@S[3]
+       bswap   @S[1]
+       bswap   @S[2]
+       bswap   @S[3]
+
+       call    _x86_64_Camellia_decrypt
+
+       bswap   @S[0]
+       bswap   @S[1]
+       bswap   @S[2]
+       mov     @S[0],0($out)
+       bswap   @S[3]
+       mov     @S[1],4($out)
+       mov     @S[2],8($out)
+       mov     @S[3],12($out)
+
+       mov     0(%rsp),%r15
+       mov     8(%rsp),%r14
+       mov     16(%rsp),%r13
+       mov     24(%rsp),%rbp
+       mov     32(%rsp),%rbx
+       lea     40(%rsp),%rsp
+.Ldec_epilogue:
+       ret
+.size  Camellia_DecryptBlock_Rounds,.-Camellia_DecryptBlock_Rounds
+
+.type  _x86_64_Camellia_decrypt,\@abi-omnipotent
+.align 16
+_x86_64_Camellia_decrypt:
+       xor     0($key),@S[1]
+       xor     4($key),@S[0]           # ^=key[0-3]
+       xor     8($key),@S[3]
+       xor     12($key),@S[2]
+.align 16
+.Ldloop:
+       mov     -8($key),$t1            # prefetch key[4-5]
+       mov     -4($key),$t0
+
+___
+       for ($i=0;$i<6;$i++) { Camellia_Feistel($i,-8); }
+$code.=<<___;
+       lea     -16*4($key),$key
+       cmp     $keyend,$key
+       mov     0($key),$t3             # prefetch key[2-3]
+       mov     4($key),$t2
+       je      .Lddone
+
+       and     @S[0],$t0
+       or      @S[3],$t3
+       rol     \$1,$t0
+       xor     $t3,@S[2]               # s2^=s3|key[3];
+       xor     $t0,@S[1]               # s1^=LeftRotate(s0&key[0],1);
+       and     @S[2],$t2
+       or      @S[1],$t1
+       rol     \$1,$t2
+       xor     $t1,@S[0]               # s0^=s1|key[1];
+       xor     $t2,@S[3]               # s3^=LeftRotate(s2&key[2],1);
+
+       jmp     .Ldloop
+
+.align 16
+.Lddone:
+       xor     @S[2],$t2
+       xor     @S[3],$t3
+       xor     @S[0],$t0
+       xor     @S[1],$t1
+
+       mov     $t2,@S[0]               # SwapHalf
+       mov     $t3,@S[1]
+       mov     $t0,@S[2]
+       mov     $t1,@S[3]
+
+       .byte   0xf3,0xc3               # rep ret
+.size  _x86_64_Camellia_decrypt,.-_x86_64_Camellia_decrypt
+___
+
+sub _saveround {
+my ($rnd,$key,@T)=@_;
+my $bias=int(@T[0])?shift(@T):0;
+
+    if ($#T==3) {
+       $code.=<<___;
+       mov     @T[1],`$bias+$rnd*8+0`($key)
+       mov     @T[0],`$bias+$rnd*8+4`($key)
+       mov     @T[3],`$bias+$rnd*8+8`($key)
+       mov     @T[2],`$bias+$rnd*8+12`($key)
+___
+    } else {
+       $code.="        mov     @T[0],`$bias+$rnd*8+0`($key)\n";
+       $code.="        mov     @T[1],`$bias+$rnd*8+8`($key)\n" if ($#T>=1);
+    }
+}
+
+sub _loadround {
+my ($rnd,$key,@T)=@_;
+my $bias=int(@T[0])?shift(@T):0;
+
+$code.="       mov     `$bias+$rnd*8+0`($key),@T[0]\n";
+$code.="       mov     `$bias+$rnd*8+8`($key),@T[1]\n" if ($#T>=1);
+}
+
+# shld is very slow on Intel EM64T family. Even on AMD it limits
+# instruction decode rate [because it's VectorPath] and consequently
+# performance...
+sub __rotl128 {
+my ($i0,$i1,$rot)=@_;
+
+    if ($rot) {
+       $code.=<<___;
+       mov     $i0,%r11
+       shld    \$$rot,$i1,$i0
+       shld    \$$rot,%r11,$i1
+___
+    }
+}
+
+# ... Implementing 128-bit rotate without shld gives 80% better
+# performance EM64T, +15% on AMD64 and only ~7% degradation on
+# Core2. This is therefore preferred.
+sub _rotl128 {
+my ($i0,$i1,$rot)=@_;
+
+    if ($rot) {
+       $code.=<<___;
+       mov     $i0,%r11
+       shl     \$$rot,$i0
+       mov     $i1,%r9
+       shr     \$`64-$rot`,%r9
+       shr     \$`64-$rot`,%r11
+       or      %r9,$i0
+       shl     \$$rot,$i1
+       or      %r11,$i1
+___
+    }
+}
+
+{ my $step=0;
+
+$code.=<<___;
+.globl Camellia_Ekeygen
+.type  Camellia_Ekeygen,\@function,3
+.align 16
+Camellia_Ekeygen:
+       push    %rbx
+       push    %rbp
+       push    %r13
+       push    %r14
+       push    %r15
+.Lkey_prologue:
+
+       mov     %rdi,$keyend            # put away arguments, keyBitLength
+       mov     %rdx,$out               # keyTable
+
+       mov     0(%rsi),@S[0]           # load 0-127 bits
+       mov     4(%rsi),@S[1]
+       mov     8(%rsi),@S[2]
+       mov     12(%rsi),@S[3]
+
+       bswap   @S[0]
+       bswap   @S[1]
+       bswap   @S[2]
+       bswap   @S[3]
+___
+       &_saveround     (0,$out,@S);    # KL<<<0
+$code.=<<___;
+       cmp     \$128,$keyend           # check keyBitLength
+       je      .L1st128
+
+       mov     16(%rsi),@S[0]          # load 128-191 bits
+       mov     20(%rsi),@S[1]
+       cmp     \$192,$keyend
+       je      .L1st192
+       mov     24(%rsi),@S[2]          # load 192-255 bits
+       mov     28(%rsi),@S[3]
+       jmp     .L1st256
+.L1st192:
+       mov     @S[0],@S[2]
+       mov     @S[1],@S[3]
+       not     @S[2]
+       not     @S[3]
+.L1st256:
+       bswap   @S[0]
+       bswap   @S[1]
+       bswap   @S[2]
+       bswap   @S[3]
+___
+       &_saveround     (4,$out,@S);    # temp storage for KR!
+$code.=<<___;
+       xor     0($out),@S[1]           # KR^KL
+       xor     4($out),@S[0]
+       xor     8($out),@S[3]
+       xor     12($out),@S[2]
+
+.L1st128:
+       lea     .LCamellia_SIGMA(%rip),$key
+       lea     .LCamellia_SBOX(%rip),$Tbl
+
+       mov     0($key),$t1
+       mov     4($key),$t0
+___
+       &Camellia_Feistel($step++);
+       &Camellia_Feistel($step++);
+$code.=<<___;
+       xor     0($out),@S[1]           # ^KL
+       xor     4($out),@S[0]
+       xor     8($out),@S[3]
+       xor     12($out),@S[2]
+___
+       &Camellia_Feistel($step++);
+       &Camellia_Feistel($step++);
+$code.=<<___;
+       cmp     \$128,$keyend
+       jne     .L2nd256
+
+       lea     128($out),$out          # size optimization
+       shl     \$32,%r8                # @S[0]||
+       shl     \$32,%r10               # @S[2]||
+       or      %r9,%r8                 # ||@S[1]
+       or      %r11,%r10               # ||@S[3]
+___
+       &_loadround     (0,$out,-128,"%rax","%rbx");    # KL
+       &_saveround     (2,$out,-128,"%r8","%r10");     # KA<<<0
+       &_rotl128       ("%rax","%rbx",15);
+       &_saveround     (4,$out,-128,"%rax","%rbx");    # KL<<<15
+       &_rotl128       ("%r8","%r10",15);
+       &_saveround     (6,$out,-128,"%r8","%r10");     # KA<<<15
+       &_rotl128       ("%r8","%r10",15);              # 15+15=30
+       &_saveround     (8,$out,-128,"%r8","%r10");     # KA<<<30
+       &_rotl128       ("%rax","%rbx",30);             # 15+30=45
+       &_saveround     (10,$out,-128,"%rax","%rbx");   # KL<<<45
+       &_rotl128       ("%r8","%r10",15);              # 30+15=45
+       &_saveround     (12,$out,-128,"%r8");           # KA<<<45
+       &_rotl128       ("%rax","%rbx",15);             # 45+15=60
+       &_saveround     (13,$out,-128,"%rbx");          # KL<<<60
+       &_rotl128       ("%r8","%r10",15);              # 45+15=60
+       &_saveround     (14,$out,-128,"%r8","%r10");    # KA<<<60
+       &_rotl128       ("%rax","%rbx",17);             # 60+17=77
+       &_saveround     (16,$out,-128,"%rax","%rbx");   # KL<<<77
+       &_rotl128       ("%rax","%rbx",17);             # 77+17=94
+       &_saveround     (18,$out,-128,"%rax","%rbx");   # KL<<<94
+       &_rotl128       ("%r8","%r10",34);              # 60+34=94
+       &_saveround     (20,$out,-128,"%r8","%r10");    # KA<<<94
+       &_rotl128       ("%rax","%rbx",17);             # 94+17=111
+       &_saveround     (22,$out,-128,"%rax","%rbx");   # KL<<<111
+       &_rotl128       ("%r8","%r10",17);              # 94+17=111
+       &_saveround     (24,$out,-128,"%r8","%r10");    # KA<<<111
+$code.=<<___;
+       mov     \$3,%eax
+       jmp     .Ldone
+.align 16
+.L2nd256:
+___
+       &_saveround     (6,$out,@S);    # temp storage for KA!
+$code.=<<___;
+       xor     `4*8+0`($out),@S[1]     # KA^KR
+       xor     `4*8+4`($out),@S[0]
+       xor     `5*8+0`($out),@S[3]
+       xor     `5*8+4`($out),@S[2]
+___
+       &Camellia_Feistel($step++);
+       &Camellia_Feistel($step++);
+
+       &_loadround     (0,$out,"%rax","%rbx"); # KL
+       &_loadround     (4,$out,"%rcx","%rdx"); # KR
+       &_loadround     (6,$out,"%r14","%r15"); # KA
+$code.=<<___;
+       lea     128($out),$out          # size optimization
+       shl     \$32,%r8                # @S[0]||
+       shl     \$32,%r10               # @S[2]||
+       or      %r9,%r8                 # ||@S[1]
+       or      %r11,%r10               # ||@S[3]
+___
+       &_saveround     (2,$out,-128,"%r8","%r10");     # KB<<<0
+       &_rotl128       ("%rcx","%rdx",15);
+       &_saveround     (4,$out,-128,"%rcx","%rdx");    # KR<<<15
+       &_rotl128       ("%r14","%r15",15);
+       &_saveround     (6,$out,-128,"%r14","%r15");    # KA<<<15
+       &_rotl128       ("%rcx","%rdx",15);             # 15+15=30
+       &_saveround     (8,$out,-128,"%rcx","%rdx");    # KR<<<30
+       &_rotl128       ("%r8","%r10",30);
+       &_saveround     (10,$out,-128,"%r8","%r10");    # KB<<<30
+       &_rotl128       ("%rax","%rbx",45);
+       &_saveround     (12,$out,-128,"%rax","%rbx");   # KL<<<45
+       &_rotl128       ("%r14","%r15",30);             # 15+30=45
+       &_saveround     (14,$out,-128,"%r14","%r15");   # KA<<<45
+       &_rotl128       ("%rax","%rbx",15);             # 45+15=60
+       &_saveround     (16,$out,-128,"%rax","%rbx");   # KL<<<60
+       &_rotl128       ("%rcx","%rdx",30);             # 30+30=60
+       &_saveround     (18,$out,-128,"%rcx","%rdx");   # KR<<<60
+       &_rotl128       ("%r8","%r10",30);              # 30+30=60
+       &_saveround     (20,$out,-128,"%r8","%r10");    # KB<<<60
+       &_rotl128       ("%rax","%rbx",17);             # 60+17=77
+       &_saveround     (22,$out,-128,"%rax","%rbx");   # KL<<<77
+       &_rotl128       ("%r14","%r15",32);             # 45+32=77
+       &_saveround     (24,$out,-128,"%r14","%r15");   # KA<<<77
+       &_rotl128       ("%rcx","%rdx",34);             # 60+34=94
+       &_saveround     (26,$out,-128,"%rcx","%rdx");   # KR<<<94
+       &_rotl128       ("%r14","%r15",17);             # 77+17=94
+       &_saveround     (28,$out,-128,"%r14","%r15");   # KA<<<77
+       &_rotl128       ("%rax","%rbx",34);             # 77+34=111
+       &_saveround     (30,$out,-128,"%rax","%rbx");   # KL<<<111
+       &_rotl128       ("%r8","%r10",51);              # 60+51=111
+       &_saveround     (32,$out,-128,"%r8","%r10");    # KB<<<111
+$code.=<<___;
+       mov     \$4,%eax
+.Ldone:
+       mov     0(%rsp),%r15
+       mov     8(%rsp),%r14
+       mov     16(%rsp),%r13
+       mov     24(%rsp),%rbp
+       mov     32(%rsp),%rbx
+       lea     40(%rsp),%rsp
+.Lkey_epilogue:
+       ret
+.size  Camellia_Ekeygen,.-Camellia_Ekeygen
+___
+}
+
+@SBOX=(
+112,130, 44,236,179, 39,192,229,228,133, 87, 53,234, 12,174, 65,
+ 35,239,107,147, 69, 25,165, 33,237, 14, 79, 78, 29,101,146,189,
+134,184,175,143,124,235, 31,206, 62, 48,220, 95, 94,197, 11, 26,
+166,225, 57,202,213, 71, 93, 61,217,  1, 90,214, 81, 86,108, 77,
+139, 13,154,102,251,204,176, 45,116, 18, 43, 32,240,177,132,153,
+223, 76,203,194, 52,126,118,  5,109,183,169, 49,209, 23,  4,215,
+ 20, 88, 58, 97,222, 27, 17, 28, 50, 15,156, 22, 83, 24,242, 34,
+254, 68,207,178,195,181,122,145, 36,  8,232,168, 96,252,105, 80,
+170,208,160,125,161,137, 98,151, 84, 91, 30,149,224,255,100,210,
+ 16,196,  0, 72,163,247,117,219,138,  3,230,218,  9, 63,221,148,
+135, 92,131,  2,205, 74,144, 51,115,103,246,243,157,127,191,226,
+ 82,155,216, 38,200, 55,198, 59,129,150,111, 75, 19,190, 99, 46,
+233,121,167,140,159,110,188,142, 41,245,249,182, 47,253,180, 89,
+120,152,  6,106,231, 70,113,186,212, 37,171, 66,136,162,141,250,
+114,  7,185, 85,248,238,172, 10, 54, 73, 42,104, 60, 56,241,164,
+ 64, 40,211,123,187,201, 67,193, 21,227,173,244,119,199,128,158);
+
+sub S1110 { my $i=shift; $i=@SBOX[$i]; $i=$i<<24|$i<<16|$i<<8; sprintf("0x%08x",$i); }
+sub S4404 { my $i=shift; $i=($i<<1|$i>>7)&0xff; $i=@SBOX[$i]; $i=$i<<24|$i<<16|$i; sprintf("0x%08x",$i); }
+sub S0222 { my $i=shift; $i=@SBOX[$i]; $i=($i<<1|$i>>7)&0xff; $i=$i<<16|$i<<8|$i; sprintf("0x%08x",$i); }
+sub S3033 { my $i=shift; $i=@SBOX[$i]; $i=($i>>1|$i<<7)&0xff; $i=$i<<24|$i<<8|$i; sprintf("0x%08x",$i); }
+
+$code.=<<___;
+.align 64
+.LCamellia_SIGMA:
+.long  0x3bcc908b, 0xa09e667f, 0x4caa73b2, 0xb67ae858
+.long  0xe94f82be, 0xc6ef372f, 0xf1d36f1c, 0x54ff53a5
+.long  0xde682d1d, 0x10e527fa, 0xb3e6c1fd, 0xb05688c2
+.long  0,          0,          0,          0
+.LCamellia_SBOX:
+___
+# tables are interleaved, remember?
+sub data_word { $code.=".long\t".join(',',@_)."\n"; }
+for ($i=0;$i<256;$i++) { &data_word(&S1110($i),&S4404($i)); }
+for ($i=0;$i<256;$i++) { &data_word(&S0222($i),&S3033($i)); }
+
+# void Camellia_cbc_encrypt (const void char *inp, unsigned char *out,
+#                      size_t length, const CAMELLIA_KEY *key,
+#                      unsigned char *ivp,const int enc);
+{
+$_key="0(%rsp)";
+$_end="8(%rsp)";       # inp+len&~15
+$_res="16(%rsp)";      # len&15
+$ivec="24(%rsp)";
+$_ivp="40(%rsp)";
+$_rsp="48(%rsp)";
+
+$code.=<<___;
+.globl Camellia_cbc_encrypt
+.type  Camellia_cbc_encrypt,\@function,6
+.align 16
+Camellia_cbc_encrypt:
+       cmp     \$0,%rdx
+       je      .Lcbc_abort
+       push    %rbx
+       push    %rbp
+       push    %r12
+       push    %r13
+       push    %r14
+       push    %r15
+.Lcbc_prologue:
+
+       mov     %rsp,%rbp
+       sub     \$64,%rsp
+       and     \$-64,%rsp
+
+       # place stack frame just "above mod 1024" the key schedule,
+       # this ensures that cache associativity suffices
+       lea     -64-63(%rcx),%r10
+       sub     %rsp,%r10
+       neg     %r10
+       and     \$0x3C0,%r10
+       sub     %r10,%rsp
+       #add    \$8,%rsp                # 8 is reserved for callee's ra
+
+       mov     %rdi,$inp               # inp argument
+       mov     %rsi,$out               # out argument
+       mov     %r8,%rbx                # ivp argument
+       mov     %rcx,$key               # key argument
+       mov     272(%rcx),${keyend}d    # grandRounds
+
+       mov     %r8,$_ivp
+       mov     %rbp,$_rsp
+
+.Lcbc_body:
+       lea     .LCamellia_SBOX(%rip),$Tbl
+
+       mov     \$32,%ecx
+.align 4
+.Lcbc_prefetch_sbox:
+       mov     0($Tbl),%rax
+       mov     32($Tbl),%rsi
+       mov     64($Tbl),%rdi
+       mov     96($Tbl),%r11
+       lea     128($Tbl),$Tbl
+       loop    .Lcbc_prefetch_sbox
+       sub     \$4096,$Tbl
+       shl     \$6,$keyend
+       mov     %rdx,%rcx               # len argument
+       lea     ($key,$keyend),$keyend
+
+       cmp     \$0,%r9d                # enc argument
+       je      .LCBC_DECRYPT
+
+       and     \$-16,%rdx
+       and     \$15,%rcx               # length residue
+       lea     ($inp,%rdx),%rdx
+       mov     $key,$_key
+       mov     %rdx,$_end
+       mov     %rcx,$_res
+
+       cmp     $inp,%rdx
+       mov     0(%rbx),@S[0]           # load IV
+       mov     4(%rbx),@S[1]
+       mov     8(%rbx),@S[2]
+       mov     12(%rbx),@S[3]
+       je      .Lcbc_enc_tail
+       jmp     .Lcbc_eloop
+
+.align 16
+.Lcbc_eloop:
+       xor     0($inp),@S[0]
+       xor     4($inp),@S[1]
+       xor     8($inp),@S[2]
+       bswap   @S[0]
+       xor     12($inp),@S[3]
+       bswap   @S[1]
+       bswap   @S[2]
+       bswap   @S[3]
+
+       call    _x86_64_Camellia_encrypt
+
+       mov     $_key,$key              # "rewind" the key
+       bswap   @S[0]
+       mov     $_end,%rdx
+       bswap   @S[1]
+       mov     $_res,%rcx
+       bswap   @S[2]
+       mov     @S[0],0($out)
+       bswap   @S[3]
+       mov     @S[1],4($out)
+       mov     @S[2],8($out)
+       lea     16($inp),$inp
+       mov     @S[3],12($out)
+       cmp     %rdx,$inp
+       lea     16($out),$out
+       jne     .Lcbc_eloop
+
+       cmp     \$0,%rcx
+       jne     .Lcbc_enc_tail
+
+       mov     $_ivp,$out
+       mov     @S[0],0($out)           # write out IV residue
+       mov     @S[1],4($out)
+       mov     @S[2],8($out)
+       mov     @S[3],12($out)
+       jmp     .Lcbc_done
+
+.align 16
+.Lcbc_enc_tail:
+       xor     %rax,%rax
+       mov     %rax,0+$ivec
+       mov     %rax,8+$ivec
+       mov     %rax,$_res
+
+.Lcbc_enc_pushf:
+       pushfq
+       cld
+       mov     $inp,%rsi
+       lea     8+$ivec,%rdi
+       .long   0x9066A4F3              # rep movsb
+       popfq
+.Lcbc_enc_popf:
+
+       lea     $ivec,$inp
+       lea     16+$ivec,%rax
+       mov     %rax,$_end
+       jmp     .Lcbc_eloop             # one more time
+
+.align 16
+.LCBC_DECRYPT:
+       xchg    $key,$keyend
+       add     \$15,%rdx
+       and     \$15,%rcx               # length residue
+       and     \$-16,%rdx
+       mov     $key,$_key
+       lea     ($inp,%rdx),%rdx
+       mov     %rdx,$_end
+       mov     %rcx,$_res
+
+       mov     (%rbx),%rax             # load IV
+       mov     8(%rbx),%rbx
+       jmp     .Lcbc_dloop
+.align 16
+.Lcbc_dloop:
+       mov     0($inp),@S[0]
+       mov     4($inp),@S[1]
+       mov     8($inp),@S[2]
+       bswap   @S[0]
+       mov     12($inp),@S[3]
+       bswap   @S[1]
+       mov     %rax,0+$ivec            # save IV to temporary storage
+       bswap   @S[2]
+       mov     %rbx,8+$ivec
+       bswap   @S[3]
+
+       call    _x86_64_Camellia_decrypt
+
+       mov     $_key,$key              # "rewind" the key
+       mov     $_end,%rdx
+       mov     $_res,%rcx
+
+       bswap   @S[0]
+       mov     ($inp),%rax             # load IV for next iteration
+       bswap   @S[1]
+       mov     8($inp),%rbx
+       bswap   @S[2]
+       xor     0+$ivec,@S[0]
+       bswap   @S[3]
+       xor     4+$ivec,@S[1]
+       xor     8+$ivec,@S[2]
+       lea     16($inp),$inp
+       xor     12+$ivec,@S[3]
+       cmp     %rdx,$inp
+       je      .Lcbc_ddone
+
+       mov     @S[0],0($out)
+       mov     @S[1],4($out)
+       mov     @S[2],8($out)
+       mov     @S[3],12($out)
+
+       lea     16($out),$out
+       jmp     .Lcbc_dloop
+
+.align 16
+.Lcbc_ddone:
+       mov     $_ivp,%rdx
+       cmp     \$0,%rcx
+       jne     .Lcbc_dec_tail
+
+       mov     @S[0],0($out)
+       mov     @S[1],4($out)
+       mov     @S[2],8($out)
+       mov     @S[3],12($out)
+
+       mov     %rax,(%rdx)             # write out IV residue
+       mov     %rbx,8(%rdx)
+       jmp     .Lcbc_done
+.align 16
+.Lcbc_dec_tail:
+       mov     @S[0],0+$ivec
+       mov     @S[1],4+$ivec
+       mov     @S[2],8+$ivec
+       mov     @S[3],12+$ivec
+
+.Lcbc_dec_pushf:
+       pushfq
+       cld
+       lea     8+$ivec,%rsi
+       lea     ($out),%rdi
+       .long   0x9066A4F3              # rep movsb
+       popfq
+.Lcbc_dec_popf:
+
+       mov     %rax,(%rdx)             # write out IV residue
+       mov     %rbx,8(%rdx)
+       jmp     .Lcbc_done
+
+.align 16
+.Lcbc_done:
+       mov     $_rsp,%rcx
+       mov     0(%rcx),%r15
+       mov     8(%rcx),%r14
+       mov     16(%rcx),%r13
+       mov     24(%rcx),%r12
+       mov     32(%rcx),%rbp
+       mov     40(%rcx),%rbx
+       lea     48(%rcx),%rsp
+.Lcbc_abort:
+       ret
+.size  Camellia_cbc_encrypt,.-Camellia_cbc_encrypt
+
+.asciz "Camellia for x86_64 by <appro\@openssl.org>"
+___
+}
+
+# EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
+#              CONTEXT *context,DISPATCHER_CONTEXT *disp)
+if ($win64) {
+$rec="%rcx";
+$frame="%rdx";
+$context="%r8";
+$disp="%r9";
+
+$code.=<<___;
+.extern        __imp_RtlVirtualUnwind
+.type  common_se_handler,\@abi-omnipotent
+.align 16
+common_se_handler:
+       push    %rsi
+       push    %rdi
+       push    %rbx
+       push    %rbp
+       push    %r12
+       push    %r13
+       push    %r14
+       push    %r15
+       pushfq
+       lea     -64(%rsp),%rsp
+
+       mov     120($context),%rax      # pull context->Rax
+       mov     248($context),%rbx      # pull context->Rip
+
+       mov     8($disp),%rsi           # disp->ImageBase
+       mov     56($disp),%r11          # disp->HandlerData
+
+       mov     0(%r11),%r10d           # HandlerData[0]
+       lea     (%rsi,%r10),%r10        # prologue label
+       cmp     %r10,%rbx               # context->Rip<prologue label
+       jb      .Lin_prologue
+
+       mov     152($context),%rax      # pull context->Rsp
+
+       mov     4(%r11),%r10d           # HandlerData[1]
+       lea     (%rsi,%r10),%r10        # epilogue label
+       cmp     %r10,%rbx               # context->Rip>=epilogue label
+       jae     .Lin_prologue
+
+       lea     40(%rax),%rax
+       mov     -8(%rax),%rbx
+       mov     -16(%rax),%rbp
+       mov     -24(%rax),%r13
+       mov     -32(%rax),%r14
+       mov     -40(%rax),%r15
+       mov     %rbx,144($context)      # restore context->Rbx
+       mov     %rbp,160($context)      # restore context->Rbp
+       mov     %r13,224($context)      # restore context->R13
+       mov     %r14,232($context)      # restore context->R14
+       mov     %r15,240($context)      # restore context->R15
+
+.Lin_prologue:
+       mov     8(%rax),%rdi
+       mov     16(%rax),%rsi
+       mov     %rax,152($context)      # restore context->Rsp
+       mov     %rsi,168($context)      # restore context->Rsi
+       mov     %rdi,176($context)      # restore context->Rdi
+
+       jmp     .Lcommon_seh_exit
+.size  common_se_handler,.-common_se_handler
+
+.type  cbc_se_handler,\@abi-omnipotent
+.align 16
+cbc_se_handler:
+       push    %rsi
+       push    %rdi
+       push    %rbx
+       push    %rbp
+       push    %r12
+       push    %r13
+       push    %r14
+       push    %r15
+       pushfq
+       lea     -64(%rsp),%rsp
+
+       mov     120($context),%rax      # pull context->Rax
+       mov     248($context),%rbx      # pull context->Rip
+
+       lea     .Lcbc_prologue(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip<.Lcbc_prologue
+       jb      .Lin_cbc_prologue
+
+       lea     .Lcbc_body(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip<.Lcbc_body
+       jb      .Lin_cbc_frame_setup
+
+       mov     152($context),%rax      # pull context->Rsp
+
+       lea     .Lcbc_abort(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip>=.Lcbc_abort
+       jae     .Lin_cbc_prologue
+
+       # handle pushf/popf in Camellia_cbc_encrypt
+       lea     .Lcbc_enc_pushf(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip<=.Lcbc_enc_pushf
+       jbe     .Lin_cbc_no_flag
+       lea     8(%rax),%rax
+       lea     .Lcbc_enc_popf(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip<.Lcbc_enc_popf
+       jb      .Lin_cbc_no_flag
+       lea     -8(%rax),%rax
+       lea     .Lcbc_dec_pushf(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip<=.Lcbc_dec_pushf
+       jbe     .Lin_cbc_no_flag
+       lea     8(%rax),%rax
+       lea     .Lcbc_dec_popf(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip<.Lcbc_dec_popf
+       jb      .Lin_cbc_no_flag
+       lea     -8(%rax),%rax
+
+.Lin_cbc_no_flag:
+       mov     48(%rax),%rax           # $_rsp
+       lea     48(%rax),%rax
+
+.Lin_cbc_frame_setup:
+       mov     -8(%rax),%rbx
+       mov     -16(%rax),%rbp
+       mov     -24(%rax),%r12
+       mov     -32(%rax),%r13
+       mov     -40(%rax),%r14
+       mov     -48(%rax),%r15
+       mov     %rbx,144($context)      # restore context->Rbx
+       mov     %rbp,160($context)      # restore context->Rbp
+       mov     %r12,216($context)      # restore context->R12
+       mov     %r13,224($context)      # restore context->R13
+       mov     %r14,232($context)      # restore context->R14
+       mov     %r15,240($context)      # restore context->R15
+
+.Lin_cbc_prologue:
+       mov     8(%rax),%rdi
+       mov     16(%rax),%rsi
+       mov     %rax,152($context)      # restore context->Rsp
+       mov     %rsi,168($context)      # restore context->Rsi
+       mov     %rdi,176($context)      # restore context->Rdi
+
+.align 4
+.Lcommon_seh_exit:
+
+       mov     40($disp),%rdi          # disp->ContextRecord
+       mov     $context,%rsi           # context
+       mov     \$`1232/8`,%ecx         # sizeof(CONTEXT)
+       .long   0xa548f3fc              # cld; rep movsq
+
+       mov     $disp,%rsi
+       xor     %rcx,%rcx               # arg1, UNW_FLAG_NHANDLER
+       mov     8(%rsi),%rdx            # arg2, disp->ImageBase
+       mov     0(%rsi),%r8             # arg3, disp->ControlPc
+       mov     16(%rsi),%r9            # arg4, disp->FunctionEntry
+       mov     40(%rsi),%r10           # disp->ContextRecord
+       lea     56(%rsi),%r11           # &disp->HandlerData
+       lea     24(%rsi),%r12           # &disp->EstablisherFrame
+       mov     %r10,32(%rsp)           # arg5
+       mov     %r11,40(%rsp)           # arg6
+       mov     %r12,48(%rsp)           # arg7
+       mov     %rcx,56(%rsp)           # arg8, (NULL)
+       call    *__imp_RtlVirtualUnwind(%rip)
+
+       mov     \$1,%eax                # ExceptionContinueSearch
+       lea     64(%rsp),%rsp
+       popfq
+       pop     %r15
+       pop     %r14
+       pop     %r13
+       pop     %r12
+       pop     %rbp
+       pop     %rbx
+       pop     %rdi
+       pop     %rsi
+       ret
+.size  cbc_se_handler,.-cbc_se_handler
+
+.section       .pdata
+.align 4
+       .rva    .LSEH_begin_Camellia_EncryptBlock_Rounds
+       .rva    .LSEH_end_Camellia_EncryptBlock_Rounds
+       .rva    .LSEH_info_Camellia_EncryptBlock_Rounds
+
+       .rva    .LSEH_begin_Camellia_DecryptBlock_Rounds
+       .rva    .LSEH_end_Camellia_DecryptBlock_Rounds
+       .rva    .LSEH_info_Camellia_DecryptBlock_Rounds
+
+       .rva    .LSEH_begin_Camellia_Ekeygen
+       .rva    .LSEH_end_Camellia_Ekeygen
+       .rva    .LSEH_info_Camellia_Ekeygen
+
+       .rva    .LSEH_begin_Camellia_cbc_encrypt
+       .rva    .LSEH_end_Camellia_cbc_encrypt
+       .rva    .LSEH_info_Camellia_cbc_encrypt
+
+.section       .xdata
+.align 8
+.LSEH_info_Camellia_EncryptBlock_Rounds:
+       .byte   9,0,0,0
+       .rva    common_se_handler
+       .rva    .Lenc_prologue,.Lenc_epilogue   # HandlerData[]
+.LSEH_info_Camellia_DecryptBlock_Rounds:
+       .byte   9,0,0,0
+       .rva    common_se_handler
+       .rva    .Ldec_prologue,.Ldec_epilogue   # HandlerData[]
+.LSEH_info_Camellia_Ekeygen:
+       .byte   9,0,0,0
+       .rva    common_se_handler
+       .rva    .Lkey_prologue,.Lkey_epilogue   # HandlerData[]
+.LSEH_info_Camellia_cbc_encrypt:
+       .byte   9,0,0,0
+       .rva    cbc_se_handler
+___
+}
+
+$code =~ s/\`([^\`]*)\`/eval $1/gem;
+print $code;
+close STDOUT;
index 491c26b..75fc899 100644 (file)
 /* Algorithm Specification 
    http://info.isl.ntt.co.jp/crypt/eng/camellia/specifications.html
 */
-
-
-#include <string.h>
-#include <stdlib.h>
+/*
+ * This release balances code size and performance. In particular key
+ * schedule setup is fully unrolled, because doing so *significantly*
+ * reduces amount of instructions per setup round and code increase is
+ * justifiable. In block functions on the other hand only inner loops
+ * are unrolled, as full unroll gives only nominal performance boost,
+ * while code size grows 4 or 7 times. Also, unlike previous versions
+ * this one "encourages" compiler to keep intermediate variables in
+ * registers, which should give better "all round" results, in other
+ * words reasonable performance even with not so modern compilers.
+ */
 
 #include "camellia.h"
 #include "cmll_locl.h"
+#include <string.h>
+#include <stdlib.h>
 
-/* key constants */
-#define CAMELLIA_SIGMA1L (0xA09E667FL)
-#define CAMELLIA_SIGMA1R (0x3BCC908BL)
-#define CAMELLIA_SIGMA2L (0xB67AE858L)
-#define CAMELLIA_SIGMA2R (0x4CAA73B2L)
-#define CAMELLIA_SIGMA3L (0xC6EF372FL)
-#define CAMELLIA_SIGMA3R (0xE94F82BEL)
-#define CAMELLIA_SIGMA4L (0x54FF53A5L)
-#define CAMELLIA_SIGMA4R (0xF1D36F1CL)
-#define CAMELLIA_SIGMA5L (0x10E527FAL)
-#define CAMELLIA_SIGMA5R (0xDE682D1DL)
-#define CAMELLIA_SIGMA6L (0xB05688C2L)
-#define CAMELLIA_SIGMA6R (0xB3E6C1FDL)
-
+/* 32-bit rotations */
+#if !defined(PEDANTIC) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
+# if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64))
+#  define RightRotate(x, s) _lrotr(x, s)
+#  define LeftRotate(x, s)  _lrotl(x, s)
+#  if _MSC_VER >= 1400
+#   define SWAP(x) _byteswap_ulong(x)
+#  else
+#   define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00)
+#  endif
+#  define GETU32(p)   SWAP(*((u32 *)(p)))
+#  define PUTU32(p,v) (*((u32 *)(p)) = SWAP((v)))
+# elif defined(__GNUC__) && __GNUC__>=2
+#  if defined(__i386) || defined(__x86_64)
+#   define RightRotate(x,s) ({u32 ret; asm ("rorl %1,%0":"=r"(ret):"I"(s),"0"(x):"cc"); ret; })
+#   define LeftRotate(x,s)  ({u32 ret; asm ("roll %1,%0":"=r"(ret):"I"(s),"0"(x):"cc"); ret; })
+#   if defined(B_ENDIAN) /* stratus.com does it */
+#    define GETU32(p)   (*(u32 *)(p))
+#    define PUTU32(p,v) (*(u32 *)(p)=(v))
+#   else
+#    define GETU32(p)   ({u32 r=*(const u32 *)(p); asm("bswapl %0":"=r"(r):"0"(r)); r; })
+#    define PUTU32(p,v) ({u32 r=(v); asm("bswapl %0":"=r"(r):"0"(r)); *(u32 *)(p)=r; })
+#   endif
+#  elif defined(_ARCH_PPC) || defined(_ARCH_PPC64) || \
+        defined(__powerpc) || defined(__ppc__) || defined(__powerpc64__)
+#   define LeftRotate(x,s)  ({u32 ret; asm ("rlwinm %0,%1,%2,0,31":"=r"(ret):"r"(x),"I"(s)); ret; })
+#   define RightRotate(x,s) LeftRotate(x,(32-s))
+#  elif defined(__s390x__)
+#   define LeftRotate(x,s)  ({u32 ret; asm ("rll %0,%1,%2":"=r"(ret):"r"(x),"I"(s)); ret; })
+#   define RightRotate(x,s) LeftRotate(x,(32-s))
+#   define GETU32(p)   (*(u32 *)(p))
+#   define PUTU32(p,v) (*(u32 *)(p)=(v))
+#  endif
+# endif
+#endif
+
+#if !defined(RightRotate) && !defined(LeftRotate)
+# define RightRotate(x, s) ( ((x) >> (s)) + ((x) << (32 - s)) )
+# define LeftRotate(x, s)  ( ((x) << (s)) + ((x) >> (32 - s)) )
+#endif
+
+#if !defined(GETU32) && !defined(PUTU32)
+# define GETU32(p)   (((u32)(p)[0] << 24) ^ ((u32)(p)[1] << 16) ^ ((u32)(p)[2] <<  8) ^ ((u32)(p)[3]))
+# define PUTU32(p,v) ((p)[0] = (u8)((v) >> 24), (p)[1] = (u8)((v) >> 16), (p)[2] = (u8)((v) >>  8), (p)[3] = (u8)(v))
+#endif
+
+/* S-box data */
+#define SBOX1_1110 Camellia_SBOX[0]
+#define SBOX4_4404 Camellia_SBOX[1]
+#define SBOX2_0222 Camellia_SBOX[2]
+#define SBOX3_3033 Camellia_SBOX[3]
+static const u32 Camellia_SBOX[][256] = {
+{   0x70707000, 0x82828200, 0x2c2c2c00, 0xececec00, 0xb3b3b300, 0x27272700, 
+    0xc0c0c000, 0xe5e5e500, 0xe4e4e400, 0x85858500, 0x57575700, 0x35353500, 
+    0xeaeaea00, 0x0c0c0c00, 0xaeaeae00, 0x41414100, 0x23232300, 0xefefef00, 
+    0x6b6b6b00, 0x93939300, 0x45454500, 0x19191900, 0xa5a5a500, 0x21212100, 
+    0xededed00, 0x0e0e0e00, 0x4f4f4f00, 0x4e4e4e00, 0x1d1d1d00, 0x65656500, 
+    0x92929200, 0xbdbdbd00, 0x86868600, 0xb8b8b800, 0xafafaf00, 0x8f8f8f00, 
+    0x7c7c7c00, 0xebebeb00, 0x1f1f1f00, 0xcecece00, 0x3e3e3e00, 0x30303000, 
+    0xdcdcdc00, 0x5f5f5f00, 0x5e5e5e00, 0xc5c5c500, 0x0b0b0b00, 0x1a1a1a00, 
+    0xa6a6a600, 0xe1e1e100, 0x39393900, 0xcacaca00, 0xd5d5d500, 0x47474700, 
+    0x5d5d5d00, 0x3d3d3d00, 0xd9d9d900, 0x01010100, 0x5a5a5a00, 0xd6d6d600, 
+    0x51515100, 0x56565600, 0x6c6c6c00, 0x4d4d4d00, 0x8b8b8b00, 0x0d0d0d00, 
+    0x9a9a9a00, 0x66666600, 0xfbfbfb00, 0xcccccc00, 0xb0b0b000, 0x2d2d2d00, 
+    0x74747400, 0x12121200, 0x2b2b2b00, 0x20202000, 0xf0f0f000, 0xb1b1b100, 
+    0x84848400, 0x99999900, 0xdfdfdf00, 0x4c4c4c00, 0xcbcbcb00, 0xc2c2c200, 
+    0x34343400, 0x7e7e7e00, 0x76767600, 0x05050500, 0x6d6d6d00, 0xb7b7b700, 
+    0xa9a9a900, 0x31313100, 0xd1d1d100, 0x17171700, 0x04040400, 0xd7d7d700, 
+    0x14141400, 0x58585800, 0x3a3a3a00, 0x61616100, 0xdedede00, 0x1b1b1b00, 
+    0x11111100, 0x1c1c1c00, 0x32323200, 0x0f0f0f00, 0x9c9c9c00, 0x16161600, 
+    0x53535300, 0x18181800, 0xf2f2f200, 0x22222200, 0xfefefe00, 0x44444400, 
+    0xcfcfcf00, 0xb2b2b200, 0xc3c3c300, 0xb5b5b500, 0x7a7a7a00, 0x91919100, 
+    0x24242400, 0x08080800, 0xe8e8e800, 0xa8a8a800, 0x60606000, 0xfcfcfc00, 
+    0x69696900, 0x50505000, 0xaaaaaa00, 0xd0d0d000, 0xa0a0a000, 0x7d7d7d00, 
+    0xa1a1a100, 0x89898900, 0x62626200, 0x97979700, 0x54545400, 0x5b5b5b00, 
+    0x1e1e1e00, 0x95959500, 0xe0e0e000, 0xffffff00, 0x64646400, 0xd2d2d200, 
+    0x10101000, 0xc4c4c400, 0x00000000, 0x48484800, 0xa3a3a300, 0xf7f7f700, 
+    0x75757500, 0xdbdbdb00, 0x8a8a8a00, 0x03030300, 0xe6e6e600, 0xdadada00, 
+    0x09090900, 0x3f3f3f00, 0xdddddd00, 0x94949400, 0x87878700, 0x5c5c5c00, 
+    0x83838300, 0x02020200, 0xcdcdcd00, 0x4a4a4a00, 0x90909000, 0x33333300, 
+    0x73737300, 0x67676700, 0xf6f6f600, 0xf3f3f300, 0x9d9d9d00, 0x7f7f7f00, 
+    0xbfbfbf00, 0xe2e2e200, 0x52525200, 0x9b9b9b00, 0xd8d8d800, 0x26262600, 
+    0xc8c8c800, 0x37373700, 0xc6c6c600, 0x3b3b3b00, 0x81818100, 0x96969600, 
+    0x6f6f6f00, 0x4b4b4b00, 0x13131300, 0xbebebe00, 0x63636300, 0x2e2e2e00, 
+    0xe9e9e900, 0x79797900, 0xa7a7a700, 0x8c8c8c00, 0x9f9f9f00, 0x6e6e6e00, 
+    0xbcbcbc00, 0x8e8e8e00, 0x29292900, 0xf5f5f500, 0xf9f9f900, 0xb6b6b600, 
+    0x2f2f2f00, 0xfdfdfd00, 0xb4b4b400, 0x59595900, 0x78787800, 0x98989800, 
+    0x06060600, 0x6a6a6a00, 0xe7e7e700, 0x46464600, 0x71717100, 0xbababa00, 
+    0xd4d4d400, 0x25252500, 0xababab00, 0x42424200, 0x88888800, 0xa2a2a200, 
+    0x8d8d8d00, 0xfafafa00, 0x72727200, 0x07070700, 0xb9b9b900, 0x55555500, 
+    0xf8f8f800, 0xeeeeee00, 0xacacac00, 0x0a0a0a00, 0x36363600, 0x49494900, 
+    0x2a2a2a00, 0x68686800, 0x3c3c3c00, 0x38383800, 0xf1f1f100, 0xa4a4a400, 
+    0x40404000, 0x28282800, 0xd3d3d300, 0x7b7b7b00, 0xbbbbbb00, 0xc9c9c900, 
+    0x43434300, 0xc1c1c100, 0x15151500, 0xe3e3e300, 0xadadad00, 0xf4f4f400, 
+    0x77777700, 0xc7c7c700, 0x80808000, 0x9e9e9e00 },
+{   0x70700070, 0x2c2c002c, 0xb3b300b3, 0xc0c000c0, 0xe4e400e4, 0x57570057, 
+    0xeaea00ea, 0xaeae00ae, 0x23230023, 0x6b6b006b, 0x45450045, 0xa5a500a5, 
+    0xeded00ed, 0x4f4f004f, 0x1d1d001d, 0x92920092, 0x86860086, 0xafaf00af, 
+    0x7c7c007c, 0x1f1f001f, 0x3e3e003e, 0xdcdc00dc, 0x5e5e005e, 0x0b0b000b, 
+    0xa6a600a6, 0x39390039, 0xd5d500d5, 0x5d5d005d, 0xd9d900d9, 0x5a5a005a, 
+    0x51510051, 0x6c6c006c, 0x8b8b008b, 0x9a9a009a, 0xfbfb00fb, 0xb0b000b0, 
+    0x74740074, 0x2b2b002b, 0xf0f000f0, 0x84840084, 0xdfdf00df, 0xcbcb00cb, 
+    0x34340034, 0x76760076, 0x6d6d006d, 0xa9a900a9, 0xd1d100d1, 0x04040004, 
+    0x14140014, 0x3a3a003a, 0xdede00de, 0x11110011, 0x32320032, 0x9c9c009c, 
+    0x53530053, 0xf2f200f2, 0xfefe00fe, 0xcfcf00cf, 0xc3c300c3, 0x7a7a007a, 
+    0x24240024, 0xe8e800e8, 0x60600060, 0x69690069, 0xaaaa00aa, 0xa0a000a0, 
+    0xa1a100a1, 0x62620062, 0x54540054, 0x1e1e001e, 0xe0e000e0, 0x64640064, 
+    0x10100010, 0x00000000, 0xa3a300a3, 0x75750075, 0x8a8a008a, 0xe6e600e6, 
+    0x09090009, 0xdddd00dd, 0x87870087, 0x83830083, 0xcdcd00cd, 0x90900090, 
+    0x73730073, 0xf6f600f6, 0x9d9d009d, 0xbfbf00bf, 0x52520052, 0xd8d800d8, 
+    0xc8c800c8, 0xc6c600c6, 0x81810081, 0x6f6f006f, 0x13130013, 0x63630063, 
+    0xe9e900e9, 0xa7a700a7, 0x9f9f009f, 0xbcbc00bc, 0x29290029, 0xf9f900f9, 
+    0x2f2f002f, 0xb4b400b4, 0x78780078, 0x06060006, 0xe7e700e7, 0x71710071, 
+    0xd4d400d4, 0xabab00ab, 0x88880088, 0x8d8d008d, 0x72720072, 0xb9b900b9, 
+    0xf8f800f8, 0xacac00ac, 0x36360036, 0x2a2a002a, 0x3c3c003c, 0xf1f100f1, 
+    0x40400040, 0xd3d300d3, 0xbbbb00bb, 0x43430043, 0x15150015, 0xadad00ad, 
+    0x77770077, 0x80800080, 0x82820082, 0xecec00ec, 0x27270027, 0xe5e500e5, 
+    0x85850085, 0x35350035, 0x0c0c000c, 0x41410041, 0xefef00ef, 0x93930093, 
+    0x19190019, 0x21210021, 0x0e0e000e, 0x4e4e004e, 0x65650065, 0xbdbd00bd, 
+    0xb8b800b8, 0x8f8f008f, 0xebeb00eb, 0xcece00ce, 0x30300030, 0x5f5f005f, 
+    0xc5c500c5, 0x1a1a001a, 0xe1e100e1, 0xcaca00ca, 0x47470047, 0x3d3d003d, 
+    0x01010001, 0xd6d600d6, 0x56560056, 0x4d4d004d, 0x0d0d000d, 0x66660066, 
+    0xcccc00cc, 0x2d2d002d, 0x12120012, 0x20200020, 0xb1b100b1, 0x99990099, 
+    0x4c4c004c, 0xc2c200c2, 0x7e7e007e, 0x05050005, 0xb7b700b7, 0x31310031, 
+    0x17170017, 0xd7d700d7, 0x58580058, 0x61610061, 0x1b1b001b, 0x1c1c001c, 
+    0x0f0f000f, 0x16160016, 0x18180018, 0x22220022, 0x44440044, 0xb2b200b2, 
+    0xb5b500b5, 0x91910091, 0x08080008, 0xa8a800a8, 0xfcfc00fc, 0x50500050, 
+    0xd0d000d0, 0x7d7d007d, 0x89890089, 0x97970097, 0x5b5b005b, 0x95950095, 
+    0xffff00ff, 0xd2d200d2, 0xc4c400c4, 0x48480048, 0xf7f700f7, 0xdbdb00db, 
+    0x03030003, 0xdada00da, 0x3f3f003f, 0x94940094, 0x5c5c005c, 0x02020002, 
+    0x4a4a004a, 0x33330033, 0x67670067, 0xf3f300f3, 0x7f7f007f, 0xe2e200e2, 
+    0x9b9b009b, 0x26260026, 0x37370037, 0x3b3b003b, 0x96960096, 0x4b4b004b, 
+    0xbebe00be, 0x2e2e002e, 0x79790079, 0x8c8c008c, 0x6e6e006e, 0x8e8e008e, 
+    0xf5f500f5, 0xb6b600b6, 0xfdfd00fd, 0x59590059, 0x98980098, 0x6a6a006a, 
+    0x46460046, 0xbaba00ba, 0x25250025, 0x42420042, 0xa2a200a2, 0xfafa00fa, 
+    0x07070007, 0x55550055, 0xeeee00ee, 0x0a0a000a, 0x49490049, 0x68680068, 
+    0x38380038, 0xa4a400a4, 0x28280028, 0x7b7b007b, 0xc9c900c9, 0xc1c100c1, 
+    0xe3e300e3, 0xf4f400f4, 0xc7c700c7, 0x9e9e009e },
+{   0x00e0e0e0, 0x00050505, 0x00585858, 0x00d9d9d9, 0x00676767, 0x004e4e4e, 
+    0x00818181, 0x00cbcbcb, 0x00c9c9c9, 0x000b0b0b, 0x00aeaeae, 0x006a6a6a, 
+    0x00d5d5d5, 0x00181818, 0x005d5d5d, 0x00828282, 0x00464646, 0x00dfdfdf, 
+    0x00d6d6d6, 0x00272727, 0x008a8a8a, 0x00323232, 0x004b4b4b, 0x00424242, 
+    0x00dbdbdb, 0x001c1c1c, 0x009e9e9e, 0x009c9c9c, 0x003a3a3a, 0x00cacaca, 
+    0x00252525, 0x007b7b7b, 0x000d0d0d, 0x00717171, 0x005f5f5f, 0x001f1f1f, 
+    0x00f8f8f8, 0x00d7d7d7, 0x003e3e3e, 0x009d9d9d, 0x007c7c7c, 0x00606060, 
+    0x00b9b9b9, 0x00bebebe, 0x00bcbcbc, 0x008b8b8b, 0x00161616, 0x00343434, 
+    0x004d4d4d, 0x00c3c3c3, 0x00727272, 0x00959595, 0x00ababab, 0x008e8e8e, 
+    0x00bababa, 0x007a7a7a, 0x00b3b3b3, 0x00020202, 0x00b4b4b4, 0x00adadad, 
+    0x00a2a2a2, 0x00acacac, 0x00d8d8d8, 0x009a9a9a, 0x00171717, 0x001a1a1a, 
+    0x00353535, 0x00cccccc, 0x00f7f7f7, 0x00999999, 0x00616161, 0x005a5a5a, 
+    0x00e8e8e8, 0x00242424, 0x00565656, 0x00404040, 0x00e1e1e1, 0x00636363, 
+    0x00090909, 0x00333333, 0x00bfbfbf, 0x00989898, 0x00979797, 0x00858585, 
+    0x00686868, 0x00fcfcfc, 0x00ececec, 0x000a0a0a, 0x00dadada, 0x006f6f6f, 
+    0x00535353, 0x00626262, 0x00a3a3a3, 0x002e2e2e, 0x00080808, 0x00afafaf, 
+    0x00282828, 0x00b0b0b0, 0x00747474, 0x00c2c2c2, 0x00bdbdbd, 0x00363636, 
+    0x00222222, 0x00383838, 0x00646464, 0x001e1e1e, 0x00393939, 0x002c2c2c, 
+    0x00a6a6a6, 0x00303030, 0x00e5e5e5, 0x00444444, 0x00fdfdfd, 0x00888888, 
+    0x009f9f9f, 0x00656565, 0x00878787, 0x006b6b6b, 0x00f4f4f4, 0x00232323, 
+    0x00484848, 0x00101010, 0x00d1d1d1, 0x00515151, 0x00c0c0c0, 0x00f9f9f9, 
+    0x00d2d2d2, 0x00a0a0a0, 0x00555555, 0x00a1a1a1, 0x00414141, 0x00fafafa, 
+    0x00434343, 0x00131313, 0x00c4c4c4, 0x002f2f2f, 0x00a8a8a8, 0x00b6b6b6, 
+    0x003c3c3c, 0x002b2b2b, 0x00c1c1c1, 0x00ffffff, 0x00c8c8c8, 0x00a5a5a5, 
+    0x00202020, 0x00898989, 0x00000000, 0x00909090, 0x00474747, 0x00efefef, 
+    0x00eaeaea, 0x00b7b7b7, 0x00151515, 0x00060606, 0x00cdcdcd, 0x00b5b5b5, 
+    0x00121212, 0x007e7e7e, 0x00bbbbbb, 0x00292929, 0x000f0f0f, 0x00b8b8b8, 
+    0x00070707, 0x00040404, 0x009b9b9b, 0x00949494, 0x00212121, 0x00666666, 
+    0x00e6e6e6, 0x00cecece, 0x00ededed, 0x00e7e7e7, 0x003b3b3b, 0x00fefefe, 
+    0x007f7f7f, 0x00c5c5c5, 0x00a4a4a4, 0x00373737, 0x00b1b1b1, 0x004c4c4c, 
+    0x00919191, 0x006e6e6e, 0x008d8d8d, 0x00767676, 0x00030303, 0x002d2d2d, 
+    0x00dedede, 0x00969696, 0x00262626, 0x007d7d7d, 0x00c6c6c6, 0x005c5c5c, 
+    0x00d3d3d3, 0x00f2f2f2, 0x004f4f4f, 0x00191919, 0x003f3f3f, 0x00dcdcdc, 
+    0x00797979, 0x001d1d1d, 0x00525252, 0x00ebebeb, 0x00f3f3f3, 0x006d6d6d, 
+    0x005e5e5e, 0x00fbfbfb, 0x00696969, 0x00b2b2b2, 0x00f0f0f0, 0x00313131, 
+    0x000c0c0c, 0x00d4d4d4, 0x00cfcfcf, 0x008c8c8c, 0x00e2e2e2, 0x00757575, 
+    0x00a9a9a9, 0x004a4a4a, 0x00575757, 0x00848484, 0x00111111, 0x00454545, 
+    0x001b1b1b, 0x00f5f5f5, 0x00e4e4e4, 0x000e0e0e, 0x00737373, 0x00aaaaaa, 
+    0x00f1f1f1, 0x00dddddd, 0x00595959, 0x00141414, 0x006c6c6c, 0x00929292, 
+    0x00545454, 0x00d0d0d0, 0x00787878, 0x00707070, 0x00e3e3e3, 0x00494949, 
+    0x00808080, 0x00505050, 0x00a7a7a7, 0x00f6f6f6, 0x00777777, 0x00939393, 
+    0x00868686, 0x00838383, 0x002a2a2a, 0x00c7c7c7, 0x005b5b5b, 0x00e9e9e9, 
+    0x00eeeeee, 0x008f8f8f, 0x00010101, 0x003d3d3d },
+{   0x38003838, 0x41004141, 0x16001616, 0x76007676, 0xd900d9d9, 0x93009393, 
+    0x60006060, 0xf200f2f2, 0x72007272, 0xc200c2c2, 0xab00abab, 0x9a009a9a, 
+    0x75007575, 0x06000606, 0x57005757, 0xa000a0a0, 0x91009191, 0xf700f7f7, 
+    0xb500b5b5, 0xc900c9c9, 0xa200a2a2, 0x8c008c8c, 0xd200d2d2, 0x90009090, 
+    0xf600f6f6, 0x07000707, 0xa700a7a7, 0x27002727, 0x8e008e8e, 0xb200b2b2, 
+    0x49004949, 0xde00dede, 0x43004343, 0x5c005c5c, 0xd700d7d7, 0xc700c7c7, 
+    0x3e003e3e, 0xf500f5f5, 0x8f008f8f, 0x67006767, 0x1f001f1f, 0x18001818, 
+    0x6e006e6e, 0xaf00afaf, 0x2f002f2f, 0xe200e2e2, 0x85008585, 0x0d000d0d, 
+    0x53005353, 0xf000f0f0, 0x9c009c9c, 0x65006565, 0xea00eaea, 0xa300a3a3, 
+    0xae00aeae, 0x9e009e9e, 0xec00ecec, 0x80008080, 0x2d002d2d, 0x6b006b6b, 
+    0xa800a8a8, 0x2b002b2b, 0x36003636, 0xa600a6a6, 0xc500c5c5, 0x86008686, 
+    0x4d004d4d, 0x33003333, 0xfd00fdfd, 0x66006666, 0x58005858, 0x96009696, 
+    0x3a003a3a, 0x09000909, 0x95009595, 0x10001010, 0x78007878, 0xd800d8d8, 
+    0x42004242, 0xcc00cccc, 0xef00efef, 0x26002626, 0xe500e5e5, 0x61006161, 
+    0x1a001a1a, 0x3f003f3f, 0x3b003b3b, 0x82008282, 0xb600b6b6, 0xdb00dbdb, 
+    0xd400d4d4, 0x98009898, 0xe800e8e8, 0x8b008b8b, 0x02000202, 0xeb00ebeb, 
+    0x0a000a0a, 0x2c002c2c, 0x1d001d1d, 0xb000b0b0, 0x6f006f6f, 0x8d008d8d, 
+    0x88008888, 0x0e000e0e, 0x19001919, 0x87008787, 0x4e004e4e, 0x0b000b0b, 
+    0xa900a9a9, 0x0c000c0c, 0x79007979, 0x11001111, 0x7f007f7f, 0x22002222, 
+    0xe700e7e7, 0x59005959, 0xe100e1e1, 0xda00dada, 0x3d003d3d, 0xc800c8c8, 
+    0x12001212, 0x04000404, 0x74007474, 0x54005454, 0x30003030, 0x7e007e7e, 
+    0xb400b4b4, 0x28002828, 0x55005555, 0x68006868, 0x50005050, 0xbe00bebe, 
+    0xd000d0d0, 0xc400c4c4, 0x31003131, 0xcb00cbcb, 0x2a002a2a, 0xad00adad, 
+    0x0f000f0f, 0xca00caca, 0x70007070, 0xff00ffff, 0x32003232, 0x69006969, 
+    0x08000808, 0x62006262, 0x00000000, 0x24002424, 0xd100d1d1, 0xfb00fbfb, 
+    0xba00baba, 0xed00eded, 0x45004545, 0x81008181, 0x73007373, 0x6d006d6d, 
+    0x84008484, 0x9f009f9f, 0xee00eeee, 0x4a004a4a, 0xc300c3c3, 0x2e002e2e, 
+    0xc100c1c1, 0x01000101, 0xe600e6e6, 0x25002525, 0x48004848, 0x99009999, 
+    0xb900b9b9, 0xb300b3b3, 0x7b007b7b, 0xf900f9f9, 0xce00cece, 0xbf00bfbf, 
+    0xdf00dfdf, 0x71007171, 0x29002929, 0xcd00cdcd, 0x6c006c6c, 0x13001313, 
+    0x64006464, 0x9b009b9b, 0x63006363, 0x9d009d9d, 0xc000c0c0, 0x4b004b4b, 
+    0xb700b7b7, 0xa500a5a5, 0x89008989, 0x5f005f5f, 0xb100b1b1, 0x17001717, 
+    0xf400f4f4, 0xbc00bcbc, 0xd300d3d3, 0x46004646, 0xcf00cfcf, 0x37003737, 
+    0x5e005e5e, 0x47004747, 0x94009494, 0xfa00fafa, 0xfc00fcfc, 0x5b005b5b, 
+    0x97009797, 0xfe00fefe, 0x5a005a5a, 0xac00acac, 0x3c003c3c, 0x4c004c4c, 
+    0x03000303, 0x35003535, 0xf300f3f3, 0x23002323, 0xb800b8b8, 0x5d005d5d, 
+    0x6a006a6a, 0x92009292, 0xd500d5d5, 0x21002121, 0x44004444, 0x51005151, 
+    0xc600c6c6, 0x7d007d7d, 0x39003939, 0x83008383, 0xdc00dcdc, 0xaa00aaaa, 
+    0x7c007c7c, 0x77007777, 0x56005656, 0x05000505, 0x1b001b1b, 0xa400a4a4, 
+    0x15001515, 0x34003434, 0x1e001e1e, 0x1c001c1c, 0xf800f8f8, 0x52005252, 
+    0x20002020, 0x14001414, 0xe900e9e9, 0xbd00bdbd, 0xdd00dddd, 0xe400e4e4, 
+    0xa100a1a1, 0xe000e0e0, 0x8a008a8a, 0xf100f1f1, 0xd600d6d6, 0x7a007a7a, 
+    0xbb00bbbb, 0xe300e3e3, 0x40004040, 0x4f004f4f }
+};
+
+/* Key generation constants */
+static const u32 SIGMA[] = {
+    0xa09e667f, 0x3bcc908b, 0xb67ae858, 0x4caa73b2, 0xc6ef372f, 0xe94f82be,
+    0x54ff53a5, 0xf1d36f1c, 0x10e527fa, 0xde682d1d, 0xb05688c2, 0xb3e6c1fd
+};
+
+/* The phi algorithm given in C.2.7 of the Camellia spec document. */
 /*
- *  macros
+ * This version does not attempt to minimize amount of temporary
+ * variables, but instead explicitly exposes algorithm's parallelism.
+ * It is therefore most appropriate for platforms with not less than
+ * ~16 registers. For platforms with less registers [well, x86 to be
+ * specific] assembler version should be/is provided anyway...
  */
-
-/* e is pointer of subkey */
-#define CamelliaSubkeyL(INDEX) (subkey[(INDEX)*2])
-#define CamelliaSubkeyR(INDEX) (subkey[(INDEX)*2 + 1])
-
-/* rotation right shift 1byte */
-#define CAMELLIA_RR8(x) (((x) >> 8) + ((x) << 24))
-/* rotation left shift 1bit */
-#define CAMELLIA_RL1(x) (((x) << 1) + ((x) >> 31))
-/* rotation left shift 1byte */
-#define CAMELLIA_RL8(x) (((x) << 8) + ((x) >> 24))
-
-#define CAMELLIA_ROLDQ(ll, lr, rl, rr, w0, w1, bits)   \
-do                                                     \
-       {                                               \
-       w0 = ll;                                        \
-       ll = (ll << bits) + (lr >> (32 - bits));        \
-       lr = (lr << bits) + (rl >> (32 - bits));        \
-       rl = (rl << bits) + (rr >> (32 - bits));        \
-       rr = (rr << bits) + (w0 >> (32 - bits));        \
-       } while(0)
-
-#define CAMELLIA_ROLDQo32(ll, lr, rl, rr, w0, w1, bits)        \
-do                                                     \
-       {                                               \
-       w0 = ll;                                        \
-       w1 = lr;                                        \
-       ll = (lr << (bits - 32)) + (rl >> (64 - bits)); \
-       lr = (rl << (bits - 32)) + (rr >> (64 - bits)); \
-       rl = (rr << (bits - 32)) + (w0 >> (64 - bits)); \
-       rr = (w0 << (bits - 32)) + (w1 >> (64 - bits)); \
-       } while(0)
-
-#define CAMELLIA_SP1110(INDEX) (camellia_sp1110[(INDEX)])
-#define CAMELLIA_SP0222(INDEX) (camellia_sp0222[(INDEX)])
-#define CAMELLIA_SP3033(INDEX) (camellia_sp3033[(INDEX)])
-#define CAMELLIA_SP4404(INDEX) (camellia_sp4404[(INDEX)])
-
-#define CAMELLIA_F(xl, xr, kl, kr, yl, yr, il, ir, t0, t1)             \
-do                                                                     \
-       {                                                               \
-       il = xl ^ kl;                                                   \
-       ir = xr ^ kr;                                                   \
-       t0 = il >> 16;                                                  \
-       t1 = ir >> 16;                                                  \
-       yl = CAMELLIA_SP1110(ir & 0xff)                                 \
-               ^ CAMELLIA_SP0222((t1 >> 8) & 0xff)                     \
-               ^ CAMELLIA_SP3033(t1 & 0xff)                            \
-               ^ CAMELLIA_SP4404((ir >> 8) & 0xff);                    \
-       yr = CAMELLIA_SP1110((t0 >> 8) & 0xff)                          \
-               ^ CAMELLIA_SP0222(t0 & 0xff)                            \
-               ^ CAMELLIA_SP3033((il >> 8) & 0xff)                     \
-               ^ CAMELLIA_SP4404(il & 0xff);                           \
-       yl ^= yr;                                                       \
-       yr = CAMELLIA_RR8(yr);                                          \
-       yr ^= yl;                                                       \
-       } while(0)
-
+#define Camellia_Feistel(_s0,_s1,_s2,_s3,_key) do {\
+       register u32 _t0,_t1,_t2,_t3;\
+\
+       _t0  = _s0 ^ (_key)[0];\
+       _t3  = SBOX4_4404[_t0&0xff];\
+       _t1  = _s1 ^ (_key)[1];\
+       _t3 ^= SBOX3_3033[(_t0 >> 8)&0xff];\
+       _t2  = SBOX1_1110[_t1&0xff];\
+       _t3 ^= SBOX2_0222[(_t0 >> 16)&0xff];\
+       _t2 ^= SBOX4_4404[(_t1 >> 8)&0xff];\
+       _t3 ^= SBOX1_1110[(_t0 >> 24)];\
+       _t2 ^= _t3;\
+       _t3  = RightRotate(_t3,8);\
+       _t2 ^= SBOX3_3033[(_t1 >> 16)&0xff];\
+       _s3 ^= _t3;\
+       _t2 ^= SBOX2_0222[(_t1 >> 24)];\
+       _s2 ^= _t2; \
+       _s3 ^= _t2;\
+} while(0)
 
 /*
- * for speed up
- *
+ * Note that n has to be less than 32. Rotations for larger amount
+ * of bits are achieved by "rotating" order of s-elements and
+ * adjusting n accordingly, e.g. RotLeft128(s1,s2,s3,s0,n-32).
  */
-#define CAMELLIA_FLS(ll, lr, rl, rr, kll, klr, krl, krr, t0, t1, t2, t3) \
-do                                                                     \
-       {                                                               \
-       t0 = kll;                                                       \
-       t0 &= ll;                                                       \
-       lr ^= CAMELLIA_RL1(t0);                                         \
-       t1 = klr;                                                       \
-       t1 |= lr;                                                       \
-       ll ^= t1;                                                       \
-                                                                       \
-       t2 = krr;                                                       \
-       t2 |= rr;                                                       \
-       rl ^= t2;                                                       \
-       t3 = krl;                                                       \
-       t3 &= rl;                                                       \
-       rr ^= CAMELLIA_RL1(t3);                                         \
-       } while(0)
-
-#define CAMELLIA_ROUNDSM(xl, xr, kl, kr, yl, yr, il, ir, t0, t1)       \
-do                                                                     \
-       {                                                               \
-       il = xl;                                                        \
-       ir = xr;                                                        \
-       t0 = il >> 16;                                                  \
-       t1 = ir >> 16;                                                  \
-       ir = CAMELLIA_SP1110(ir & 0xff)                                 \
-               ^ CAMELLIA_SP0222((t1 >> 8) & 0xff)                     \
-               ^ CAMELLIA_SP3033(t1 & 0xff)                            \
-               ^ CAMELLIA_SP4404((ir >> 8) & 0xff);                    \
-       il = CAMELLIA_SP1110((t0 >> 8) & 0xff)                          \
-               ^ CAMELLIA_SP0222(t0 & 0xff)                            \
-               ^ CAMELLIA_SP3033((il >> 8) & 0xff)                     \
-               ^ CAMELLIA_SP4404(il & 0xff);                           \
-       il ^= kl;                                                       \
-       ir ^= kr;                                                       \
-       ir ^= il;                                                       \
-       il = CAMELLIA_RR8(il);                                          \
-       il ^= ir;                                                       \
-       yl ^= ir;                                                       \
-       yr ^= il;                                                       \
-       } while(0)
-
-static const u32 camellia_sp1110[256] =
-       {
-       0x70707000,0x82828200,0x2c2c2c00,0xececec00,
-       0xb3b3b300,0x27272700,0xc0c0c000,0xe5e5e500,
-       0xe4e4e400,0x85858500,0x57575700,0x35353500,
-       0xeaeaea00,0x0c0c0c00,0xaeaeae00,0x41414100,
-       0x23232300,0xefefef00,0x6b6b6b00,0x93939300,
-       0x45454500,0x19191900,0xa5a5a500,0x21212100,
-       0xededed00,0x0e0e0e00,0x4f4f4f00,0x4e4e4e00,
-       0x1d1d1d00,0x65656500,0x92929200,0xbdbdbd00,
-       0x86868600,0xb8b8b800,0xafafaf00,0x8f8f8f00,
-       0x7c7c7c00,0xebebeb00,0x1f1f1f00,0xcecece00,
-       0x3e3e3e00,0x30303000,0xdcdcdc00,0x5f5f5f00,
-       0x5e5e5e00,0xc5c5c500,0x0b0b0b00,0x1a1a1a00,
-       0xa6a6a600,0xe1e1e100,0x39393900,0xcacaca00,
-       0xd5d5d500,0x47474700,0x5d5d5d00,0x3d3d3d00,
-       0xd9d9d900,0x01010100,0x5a5a5a00,0xd6d6d600,
-       0x51515100,0x56565600,0x6c6c6c00,0x4d4d4d00,
-       0x8b8b8b00,0x0d0d0d00,0x9a9a9a00,0x66666600,
-       0xfbfbfb00,0xcccccc00,0xb0b0b000,0x2d2d2d00,
-       0x74747400,0x12121200,0x2b2b2b00,0x20202000,
-       0xf0f0f000,0xb1b1b100,0x84848400,0x99999900,
-       0xdfdfdf00,0x4c4c4c00,0xcbcbcb00,0xc2c2c200,
-       0x34343400,0x7e7e7e00,0x76767600,0x05050500,
-       0x6d6d6d00,0xb7b7b700,0xa9a9a900,0x31313100,
-       0xd1d1d100,0x17171700,0x04040400,0xd7d7d700,
-       0x14141400,0x58585800,0x3a3a3a00,0x61616100,
-       0xdedede00,0x1b1b1b00,0x11111100,0x1c1c1c00,
-       0x32323200,0x0f0f0f00,0x9c9c9c00,0x16161600,
-       0x53535300,0x18181800,0xf2f2f200,0x22222200,
-       0xfefefe00,0x44444400,0xcfcfcf00,0xb2b2b200,
-       0xc3c3c300,0xb5b5b500,0x7a7a7a00,0x91919100,
-       0x24242400,0x08080800,0xe8e8e800,0xa8a8a800,
-       0x60606000,0xfcfcfc00,0x69696900,0x50505000,
-       0xaaaaaa00,0xd0d0d000,0xa0a0a000,0x7d7d7d00,
-       0xa1a1a100,0x89898900,0x62626200,0x97979700,
-       0x54545400,0x5b5b5b00,0x1e1e1e00,0x95959500,
-       0xe0e0e000,0xffffff00,0x64646400,0xd2d2d200,
-       0x10101000,0xc4c4c400,0x00000000,0x48484800,
-       0xa3a3a300,0xf7f7f700,0x75757500,0xdbdbdb00,
-       0x8a8a8a00,0x03030300,0xe6e6e600,0xdadada00,
-       0x09090900,0x3f3f3f00,0xdddddd00,0x94949400,
-       0x87878700,0x5c5c5c00,0x83838300,0x02020200,
-       0xcdcdcd00,0x4a4a4a00,0x90909000,0x33333300,
-       0x73737300,0x67676700,0xf6f6f600,0xf3f3f300,
-       0x9d9d9d00,0x7f7f7f00,0xbfbfbf00,0xe2e2e200,
-       0x52525200,0x9b9b9b00,0xd8d8d800,0x26262600,
-       0xc8c8c800,0x37373700,0xc6c6c600,0x3b3b3b00,
-       0x81818100,0x96969600,0x6f6f6f00,0x4b4b4b00,
-       0x13131300,0xbebebe00,0x63636300,0x2e2e2e00,
-       0xe9e9e900,0x79797900,0xa7a7a700,0x8c8c8c00,
-       0x9f9f9f00,0x6e6e6e00,0xbcbcbc00,0x8e8e8e00,
-       0x29292900,0xf5f5f500,0xf9f9f900,0xb6b6b600,
-       0x2f2f2f00,0xfdfdfd00,0xb4b4b400,0x59595900,
-       0x78787800,0x98989800,0x06060600,0x6a6a6a00,
-       0xe7e7e700,0x46464600,0x71717100,0xbababa00,
-       0xd4d4d400,0x25252500,0xababab00,0x42424200,
-       0x88888800,0xa2a2a200,0x8d8d8d00,0xfafafa00,
-       0x72727200,0x07070700,0xb9b9b900,0x55555500,
-       0xf8f8f800,0xeeeeee00,0xacacac00,0x0a0a0a00,
-       0x36363600,0x49494900,0x2a2a2a00,0x68686800,
-       0x3c3c3c00,0x38383800,0xf1f1f100,0xa4a4a400,
-       0x40404000,0x28282800,0xd3d3d300,0x7b7b7b00,
-       0xbbbbbb00,0xc9c9c900,0x43434300,0xc1c1c100,
-       0x15151500,0xe3e3e300,0xadadad00,0xf4f4f400,
-       0x77777700,0xc7c7c700,0x80808000,0x9e9e9e00,
-       };
-
-static const u32 camellia_sp0222[256] =
+#define RotLeft128(_s0,_s1,_s2,_s3,_n) do {\
+       u32 _t0=_s0>>(32-_n);\
+       _s0 = (_s0<<_n) | (_s1>>(32-_n));\
+       _s1 = (_s1<<_n) | (_s2>>(32-_n));\
+       _s2 = (_s2<<_n) | (_s3>>(32-_n));\
+       _s3 = (_s3<<_n) | _t0;\
+} while (0)
+
+int Camellia_Ekeygen(int keyBitLength, const u8 *rawKey, KEY_TABLE_TYPE k)
        {
-       0x00e0e0e0,0x00050505,0x00585858,0x00d9d9d9,
-       0x00676767,0x004e4e4e,0x00818181,0x00cbcbcb,
-       0x00c9c9c9,0x000b0b0b,0x00aeaeae,0x006a6a6a,
-       0x00d5d5d5,0x00181818,0x005d5d5d,0x00828282,
-       0x00464646,0x00dfdfdf,0x00d6d6d6,0x00272727,
-       0x008a8a8a,0x00323232,0x004b4b4b,0x00424242,
-       0x00dbdbdb,0x001c1c1c,0x009e9e9e,0x009c9c9c,
-       0x003a3a3a,0x00cacaca,0x00252525,0x007b7b7b,
-       0x000d0d0d,0x00717171,0x005f5f5f,0x001f1f1f,
-       0x00f8f8f8,0x00d7d7d7,0x003e3e3e,0x009d9d9d,
-       0x007c7c7c,0x00606060,0x00b9b9b9,0x00bebebe,
-       0x00bcbcbc,0x008b8b8b,0x00161616,0x00343434,
-       0x004d4d4d,0x00c3c3c3,0x00727272,0x00959595,
-       0x00ababab,0x008e8e8e,0x00bababa,0x007a7a7a,
-       0x00b3b3b3,0x00020202,0x00b4b4b4,0x00adadad,
-       0x00a2a2a2,0x00acacac,0x00d8d8d8,0x009a9a9a,
-       0x00171717,0x001a1a1a,0x00353535,0x00cccccc,
-       0x00f7f7f7,0x00999999,0x00616161,0x005a5a5a,
-       0x00e8e8e8,0x00242424,0x00565656,0x00404040,
-       0x00e1e1e1,0x00636363,0x00090909,0x00333333,
-       0x00bfbfbf,0x00989898,0x00979797,0x00858585,
-       0x00686868,0x00fcfcfc,0x00ececec,0x000a0a0a,
-       0x00dadada,0x006f6f6f,0x00535353,0x00626262,
-       0x00a3a3a3,0x002e2e2e,0x00080808,0x00afafaf,
-       0x00282828,0x00b0b0b0,0x00747474,0x00c2c2c2,
-       0x00bdbdbd,0x00363636,0x00222222,0x00383838,
-       0x00646464,0x001e1e1e,0x00393939,0x002c2c2c,
-       0x00a6a6a6,0x00303030,0x00e5e5e5,0x00444444,
-       0x00fdfdfd,0x00888888,0x009f9f9f,0x00656565,
-       0x00878787,0x006b6b6b,0x00f4f4f4,0x00232323,
-       0x00484848,0x00101010,0x00d1d1d1,0x00515151,
-       0x00c0c0c0,0x00f9f9f9,0x00d2d2d2,0x00a0a0a0,
-       0x00555555,0x00a1a1a1,0x00414141,0x00fafafa,
-       0x00434343,0x00131313,0x00c4c4c4,0x002f2f2f,
-       0x00a8a8a8,0x00b6b6b6,0x003c3c3c,0x002b2b2b,
-       0x00c1c1c1,0x00ffffff,0x00c8c8c8,0x00a5a5a5,
-       0x00202020,0x00898989,0x00000000,0x00909090,
-       0x00474747,0x00efefef,0x00eaeaea,0x00b7b7b7,
-       0x00151515,0x00060606,0x00cdcdcd,0x00b5b5b5,
-       0x00121212,0x007e7e7e,0x00bbbbbb,0x00292929,
-       0x000f0f0f,0x00b8b8b8,0x00070707,0x00040404,
-       0x009b9b9b,0x00949494,0x00212121,0x00666666,
-       0x00e6e6e6,0x00cecece,0x00ededed,0x00e7e7e7,
-       0x003b3b3b,0x00fefefe,0x007f7f7f,0x00c5c5c5,
-       0x00a4a4a4,0x00373737,0x00b1b1b1,0x004c4c4c,
-       0x00919191,0x006e6e6e,0x008d8d8d,0x00767676,
-       0x00030303,0x002d2d2d,0x00dedede,0x00969696,
-       0x00262626,0x007d7d7d,0x00c6c6c6,0x005c5c5c,
-       0x00d3d3d3,0x00f2f2f2,0x004f4f4f,0x00191919,
-       0x003f3f3f,0x00dcdcdc,0x00797979,0x001d1d1d,
-       0x00525252,0x00ebebeb,0x00f3f3f3,0x006d6d6d,
-       0x005e5e5e,0x00fbfbfb,0x00696969,0x00b2b2b2,
-       0x00f0f0f0,0x00313131,0x000c0c0c,0x00d4d4d4,
-       0x00cfcfcf,0x008c8c8c,0x00e2e2e2,0x00757575,
-       0x00a9a9a9,0x004a4a4a,0x00575757,0x00848484,
-       0x00111111,0x00454545,0x001b1b1b,0x00f5f5f5,
-       0x00e4e4e4,0x000e0e0e,0x00737373,0x00aaaaaa,
-       0x00f1f1f1,0x00dddddd,0x00595959,0x00141414,
-       0x006c6c6c,0x00929292,0x00545454,0x00d0d0d0,
-       0x00787878,0x00707070,0x00e3e3e3,0x00494949,
-       0x00808080,0x00505050,0x00a7a7a7,0x00f6f6f6,
-       0x00777777,0x00939393,0x00868686,0x00838383,
-       0x002a2a2a,0x00c7c7c7,0x005b5b5b,0x00e9e9e9,
-       0x00eeeeee,0x008f8f8f,0x00010101,0x003d3d3d,
-       };
-
-static const u32 camellia_sp3033[256] =
-       {
-       0x38003838,0x41004141,0x16001616,0x76007676,
-       0xd900d9d9,0x93009393,0x60006060,0xf200f2f2,
-       0x72007272,0xc200c2c2,0xab00abab,0x9a009a9a,
-       0x75007575,0x06000606,0x57005757,0xa000a0a0,
-       0x91009191,0xf700f7f7,0xb500b5b5,0xc900c9c9,
-       0xa200a2a2,0x8c008c8c,0xd200d2d2,0x90009090,
-       0xf600f6f6,0x07000707,0xa700a7a7,0x27002727,
-       0x8e008e8e,0xb200b2b2,0x49004949,0xde00dede,
-       0x43004343,0x5c005c5c,0xd700d7d7,0xc700c7c7,
-       0x3e003e3e,0xf500f5f5,0x8f008f8f,0x67006767,
-       0x1f001f1f,0x18001818,0x6e006e6e,0xaf00afaf,
-       0x2f002f2f,0xe200e2e2,0x85008585,0x0d000d0d,
-       0x53005353,0xf000f0f0,0x9c009c9c,0x65006565,
-       0xea00eaea,0xa300a3a3,0xae00aeae,0x9e009e9e,
-       0xec00ecec,0x80008080,0x2d002d2d,0x6b006b6b,
-       0xa800a8a8,0x2b002b2b,0x36003636,0xa600a6a6,
-       0xc500c5c5,0x86008686,0x4d004d4d,0x33003333,
-       0xfd00fdfd,0x66006666,0x58005858,0x96009696,
-       0x3a003a3a,0x09000909,0x95009595,0x10001010,
-       0x78007878,0xd800d8d8,0x42004242,0xcc00cccc,
-       0xef00efef,0x26002626,0xe500e5e5,0x61006161,
-       0x1a001a1a,0x3f003f3f,0x3b003b3b,0x82008282,
-       0xb600b6b6,0xdb00dbdb,0xd400d4d4,0x98009898,
-       0xe800e8e8,0x8b008b8b,0x02000202,0xeb00ebeb,
-       0x0a000a0a,0x2c002c2c,0x1d001d1d,0xb000b0b0,
-       0x6f006f6f,0x8d008d8d,0x88008888,0x0e000e0e,
-       0x19001919,0x87008787,0x4e004e4e,0x0b000b0b,
-       0xa900a9a9,0x0c000c0c,0x79007979,0x11001111,
-       0x7f007f7f,0x22002222,0xe700e7e7,0x59005959,
-       0xe100e1e1,0xda00dada,0x3d003d3d,0xc800c8c8,
-       0x12001212,0x04000404,0x74007474,0x54005454,
-       0x30003030,0x7e007e7e,0xb400b4b4,0x28002828,
-       0x55005555,0x68006868,0x50005050,0xbe00bebe,
-       0xd000d0d0,0xc400c4c4,0x31003131,0xcb00cbcb,
-       0x2a002a2a,0xad00adad,0x0f000f0f,0xca00caca,
-       0x70007070,0xff00ffff,0x32003232,0x69006969,
-       0x08000808,0x62006262,0x00000000,0x24002424,
-       0xd100d1d1,0xfb00fbfb,0xba00baba,0xed00eded,
-       0x45004545,0x81008181,0x73007373,0x6d006d6d,
-       0x84008484,0x9f009f9f,0xee00eeee,0x4a004a4a,
-       0xc300c3c3,0x2e002e2e,0xc100c1c1,0x01000101,
-       0xe600e6e6,0x25002525,0x48004848,0x99009999,
-       0xb900b9b9,0xb300b3b3,0x7b007b7b,0xf900f9f9,
-       0xce00cece,0xbf00bfbf,0xdf00dfdf,0x71007171,
-       0x29002929,0xcd00cdcd,0x6c006c6c,0x13001313,
-       0x64006464,0x9b009b9b,0x63006363,0x9d009d9d,
-       0xc000c0c0,0x4b004b4b,0xb700b7b7,0xa500a5a5,
-       0x89008989,0x5f005f5f,0xb100b1b1,0x17001717,
-       0xf400f4f4,0xbc00bcbc,0xd300d3d3,0x46004646,
-       0xcf00cfcf,0x37003737,0x5e005e5e,0x47004747,
-       0x94009494,0xfa00fafa,0xfc00fcfc,0x5b005b5b,
-       0x97009797,0xfe00fefe,0x5a005a5a,0xac00acac,
-       0x3c003c3c,0x4c004c4c,0x03000303,0x35003535,
-       0xf300f3f3,0x23002323,0xb800b8b8,0x5d005d5d,
-       0x6a006a6a,0x92009292,0xd500d5d5,0x21002121,
-       0x44004444,0x51005151,0xc600c6c6,0x7d007d7d,
-       0x39003939,0x83008383,0xdc00dcdc,0xaa00aaaa,
-       0x7c007c7c,0x77007777,0x56005656,0x05000505,
-       0x1b001b1b,0xa400a4a4,0x15001515,0x34003434,
-       0x1e001e1e,0x1c001c1c,0xf800f8f8,0x52005252,
-       0x20002020,0x14001414,0xe900e9e9,0xbd00bdbd,
-       0xdd00dddd,0xe400e4e4,0xa100a1a1,0xe000e0e0,
-       0x8a008a8a,0xf100f1f1,0xd600d6d6,0x7a007a7a,
-       0xbb00bbbb,0xe300e3e3,0x40004040,0x4f004f4f,
-       };
-
-static const u32 camellia_sp4404[256] =
-       {
-       0x70700070,0x2c2c002c,0xb3b300b3,0xc0c000c0,
-       0xe4e400e4,0x57570057,0xeaea00ea,0xaeae00ae,
-       0x23230023,0x6b6b006b,0x45450045,0xa5a500a5,
-       0xeded00ed,0x4f4f004f,0x1d1d001d,0x92920092,
-       0x86860086,0xafaf00af,0x7c7c007c,0x1f1f001f,
-       0x3e3e003e,0xdcdc00dc,0x5e5e005e,0x0b0b000b,
-       0xa6a600a6,0x39390039,0xd5d500d5,0x5d5d005d,
-       0xd9d900d9,0x5a5a005a,0x51510051,0x6c6c006c,
-       0x8b8b008b,0x9a9a009a,0xfbfb00fb,0xb0b000b0,
-       0x74740074,0x2b2b002b,0xf0f000f0,0x84840084,
-       0xdfdf00df,0xcbcb00cb,0x34340034,0x76760076,
-       0x6d6d006d,0xa9a900a9,0xd1d100d1,0x04040004,
-       0x14140014,0x3a3a003a,0xdede00de,0x11110011,
-       0x32320032,0x9c9c009c,0x53530053,0xf2f200f2,
-       0xfefe00fe,0xcfcf00cf,0xc3c300c3,0x7a7a007a,
-       0x24240024,0xe8e800e8,0x60600060,0x69690069,
-       0xaaaa00aa,0xa0a000a0,0xa1a100a1,0x62620062,
-       0x54540054,0x1e1e001e,0xe0e000e0,0x64640064,
-       0x10100010,0x00000000,0xa3a300a3,0x75750075,
-       0x8a8a008a,0xe6e600e6,0x09090009,0xdddd00dd,
-       0x87870087,0x83830083,0xcdcd00cd,0x90900090,
-       0x73730073,0xf6f600f6,0x9d9d009d,0xbfbf00bf,
-       0x52520052,0xd8d800d8,0xc8c800c8,0xc6c600c6,
-       0x81810081,0x6f6f006f,0x13130013,0x63630063,
-       0xe9e900e9,0xa7a700a7,0x9f9f009f,0xbcbc00bc,
-       0x29290029,0xf9f900f9,0x2f2f002f,0xb4b400b4,
-       0x78780078,0x06060006,0xe7e700e7,0x71710071,
-       0xd4d400d4,0xabab00ab,0x88880088,0x8d8d008d,
-       0x72720072,0xb9b900b9,0xf8f800f8,0xacac00ac,
-       0x36360036,0x2a2a002a,0x3c3c003c,0xf1f100f1,
-       0x40400040,0xd3d300d3,0xbbbb00bb,0x43430043,
-       0x15150015,0xadad00ad,0x77770077,0x80800080,
-       0x82820082,0xecec00ec,0x27270027,0xe5e500e5,
-       0x85850085,0x35350035,0x0c0c000c,0x41410041,
-       0xefef00ef,0x93930093,0x19190019,0x21210021,
-       0x0e0e000e,0x4e4e004e,0x65650065,0xbdbd00bd,
-       0xb8b800b8,0x8f8f008f,0xebeb00eb,0xcece00ce,
-       0x30300030,0x5f5f005f,0xc5c500c5,0x1a1a001a,
-       0xe1e100e1,0xcaca00ca,0x47470047,0x3d3d003d,
-       0x01010001,0xd6d600d6,0x56560056,0x4d4d004d,
-       0x0d0d000d,0x66660066,0xcccc00cc,0x2d2d002d,
-       0x12120012,0x20200020,0xb1b100b1,0x99990099,
-       0x4c4c004c,0xc2c200c2,0x7e7e007e,0x05050005,
-       0xb7b700b7,0x31310031,0x17170017,0xd7d700d7,
-       0x58580058,0x61610061,0x1b1b001b,0x1c1c001c,
-       0x0f0f000f,0x16160016,0x18180018,0x22220022,
-       0x44440044,0xb2b200b2,0xb5b500b5,0x91910091,
-       0x08080008,0xa8a800a8,0xfcfc00fc,0x50500050,
-       0xd0d000d0,0x7d7d007d,0x89890089,0x97970097,
-       0x5b5b005b,0x95950095,0xffff00ff,0xd2d200d2,
-       0xc4c400c4,0x48480048,0xf7f700f7,0xdbdb00db,
-       0x03030003,0xdada00da,0x3f3f003f,0x94940094,
-       0x5c5c005c,0x02020002,0x4a4a004a,0x33330033,
-       0x67670067,0xf3f300f3,0x7f7f007f,0xe2e200e2,
-       0x9b9b009b,0x26260026,0x37370037,0x3b3b003b,
-       0x96960096,0x4b4b004b,0xbebe00be,0x2e2e002e,
-       0x79790079,0x8c8c008c,0x6e6e006e,0x8e8e008e,
-       0xf5f500f5,0xb6b600b6,0xfdfd00fd,0x59590059,
-       0x98980098,0x6a6a006a,0x46460046,0xbaba00ba,
-       0x25250025,0x42420042,0xa2a200a2,0xfafa00fa,
-       0x07070007,0x55550055,0xeeee00ee,0x0a0a000a,
-       0x49490049,0x68680068,0x38380038,0xa4a400a4,
-       0x28280028,0x7b7b007b,0xc9c900c9,0xc1c100c1,
-       0xe3e300e3,0xf4f400f4,0xc7c700c7,0x9e9e009e,
-       };
-
-/**
- * Stuff related to the Camellia key schedule
- */
-#define subl(x) subL[(x)]
-#define subr(x) subR[(x)]
-
-void camellia_setup128(const u8 *key, u32 *subkey)
-       {
-       u32 kll, klr, krl, krr;
-       u32 il, ir, t0, t1, w0, w1;
-       u32 kw4l, kw4r, dw, tl, tr;
-       u32 subL[26];
-       u32 subR[26];
-
-       /**
-        *  k == kll || klr || krl || krr (|| is concatination)
-        */
-       kll = GETU32(key     );
-       klr = GETU32(key +  4);
-       krl = GETU32(key +  8);
-       krr = GETU32(key + 12);
-       /**
-        * generate KL dependent subkeys
-        */
-       /* kw1 */
-       subl(0) = kll; subr(0) = klr;
-       /* kw2 */
-       subl(1) = krl; subr(1) = krr;
-       /* rotation left shift 15bit */
-       CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15);
-       /* k3 */
-       subl(4) = kll; subr(4) = klr;
-       /* k4 */
-       subl(5) = krl; subr(5) = krr;
-       /* rotation left shift 15+30bit */
-       CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 30);
-       /* k7 */
-       subl(10) = kll; subr(10) = klr;
-       /* k8 */
-       subl(11) = krl; subr(11) = krr;
-       /* rotation left shift 15+30+15bit */
-       CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15);
-       /* k10 */
-       subl(13) = krl; subr(13) = krr;
-       /* rotation left shift 15+30+15+17 bit */
-       CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 17);
-       /* kl3 */
-       subl(16) = kll; subr(16) = klr;
-       /* kl4 */
-       subl(17) = krl; subr(17) = krr;
-       /* rotation left shift 15+30+15+17+17 bit */
-       CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 17);
-       /* k13 */
-       subl(18) = kll; subr(18) = klr;
-       /* k14 */
-       subl(19) = krl; subr(19) = krr;
-       /* rotation left shift 15+30+15+17+17+17 bit */
-       CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 17);
-       /* k17 */
-       subl(22) = kll; subr(22) = klr;
-       /* k18 */
-       subl(23) = krl; subr(23) = krr;
-
-       /* generate KA */
-       kll = subl(0); klr = subr(0);
-       krl = subl(1); krr = subr(1);
-       CAMELLIA_F(kll, klr,
-               CAMELLIA_SIGMA1L, CAMELLIA_SIGMA1R,
-               w0, w1, il, ir, t0, t1);
-       krl ^= w0; krr ^= w1;
-       CAMELLIA_F(krl, krr,
-               CAMELLIA_SIGMA2L, CAMELLIA_SIGMA2R,
-               kll, klr, il, ir, t0, t1);
-       /* current status == (kll, klr, w0, w1) */
-       CAMELLIA_F(kll, klr,
-               CAMELLIA_SIGMA3L, CAMELLIA_SIGMA3R,
-               krl, krr, il, ir, t0, t1);
-       krl ^= w0; krr ^= w1;
-       CAMELLIA_F(krl, krr,
-               CAMELLIA_SIGMA4L, CAMELLIA_SIGMA4R,
-               w0, w1, il, ir, t0, t1);
-       kll ^= w0; klr ^= w1;
-
-       /* generate KA dependent subkeys */
-       /* k1, k2 */
-       subl(2) = kll; subr(2) = klr;
-       subl(3) = krl; subr(3) = krr;
-       CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15);
-       /* k5,k6 */
-       subl(6) = kll; subr(6) = klr;
-       subl(7) = krl; subr(7) = krr;
-       CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15);
-       /* kl1, kl2 */
-       subl(8) = kll; subr(8) = klr;
-       subl(9) = krl; subr(9) = krr;
-       CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15);
-       /* k9 */
-       subl(12) = kll; subr(12) = klr;
-       CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15);
-       /* k11, k12 */
-       subl(14) = kll; subr(14) = klr;
-       subl(15) = krl; subr(15) = krr;
-       CAMELLIA_ROLDQo32(kll, klr, krl, krr, w0, w1, 34);
-       /* k15, k16 */
-       subl(20) = kll; subr(20) = klr;
-       subl(21) = krl; subr(21) = krr;
-       CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 17);
-       /* kw3, kw4 */
-       subl(24) = kll; subr(24) = klr;
-       subl(25) = krl; subr(25) = krr;
-
-
-       /* absorb kw2 to other subkeys */
-/* round 2 */
-       subl(3) ^= subl(1); subr(3) ^= subr(1);
-/* round 4 */
-       subl(5) ^= subl(1); subr(5) ^= subr(1);
-/* round 6 */
-       subl(7) ^= subl(1); subr(7) ^= subr(1);
-       subl(1) ^= subr(1) & ~subr(9);
-       dw = subl(1) & subl(9),
-               subr(1) ^= CAMELLIA_RL1(dw); /* modified for FLinv(kl2) */
-/* round 8 */
-       subl(11) ^= subl(1); subr(11) ^= subr(1);
-/* round 10 */
-       subl(13) ^= subl(1); subr(13) ^= subr(1);
-/* round 12 */
-       subl(15) ^= subl(1); subr(15) ^= subr(1);
-       subl(1) ^= subr(1) & ~subr(17);
-       dw = subl(1) & subl(17),
-               subr(1) ^= CAMELLIA_RL1(dw); /* modified for FLinv(kl4) */
-/* round 14 */
-       subl(19) ^= subl(1); subr(19) ^= subr(1);
-/* round 16 */
-       subl(21) ^= subl(1); subr(21) ^= subr(1);
-/* round 18 */
-       subl(23) ^= subl(1); subr(23) ^= subr(1);
-/* kw3 */
-       subl(24) ^= subl(1); subr(24) ^= subr(1);
-
-       /* absorb kw4 to other subkeys */
-       kw4l = subl(25); kw4r = subr(25);
-/* round 17 */
-       subl(22) ^= kw4l; subr(22) ^= kw4r;
-/* round 15 */
-       subl(20) ^= kw4l; subr(20) ^= kw4r;
-/* round 13 */
-       subl(18) ^= kw4l; subr(18) ^= kw4r;
-       kw4l ^= kw4r & ~subr(16);
-       dw = kw4l & subl(16),
-               kw4r ^= CAMELLIA_RL1(dw); /* modified for FL(kl3) */
-/* round 11 */
-       subl(14) ^= kw4l; subr(14) ^= kw4r;
-/* round 9 */
-       subl(12) ^= kw4l; subr(12) ^= kw4r;
-/* round 7 */
-       subl(10) ^= kw4l; subr(10) ^= kw4r;
-       kw4l ^= kw4r & ~subr(8);
-       dw = kw4l & subl(8),
-               kw4r ^= CAMELLIA_RL1(dw); /* modified for FL(kl1) */
-/* round 5 */
-       subl(6) ^= kw4l; subr(6) ^= kw4r;
-/* round 3 */
-       subl(4) ^= kw4l; subr(4) ^= kw4r;
-/* round 1 */
-       subl(2) ^= kw4l; subr(2) ^= kw4r;
-/* kw1 */
-       subl(0) ^= kw4l; subr(0) ^= kw4r;
-
-
-       /* key XOR is end of F-function */
-       CamelliaSubkeyL(0) = subl(0) ^ subl(2);/* kw1 */
-       CamelliaSubkeyR(0) = subr(0) ^ subr(2);
-       CamelliaSubkeyL(2) = subl(3);       /* round 1 */
-       CamelliaSubkeyR(2) = subr(3);
-       CamelliaSubkeyL(3) = subl(2) ^ subl(4); /* round 2 */
-       CamelliaSubkeyR(3) = subr(2) ^ subr(4);
-       CamelliaSubkeyL(4) = subl(3) ^ subl(5); /* round 3 */
-       CamelliaSubkeyR(4) = subr(3) ^ subr(5);
-       CamelliaSubkeyL(5) = subl(4) ^ subl(6); /* round 4 */
-       CamelliaSubkeyR(5) = subr(4) ^ subr(6);
-       CamelliaSubkeyL(6) = subl(5) ^ subl(7); /* round 5 */
-       CamelliaSubkeyR(6) = subr(5) ^ subr(7);
-       tl = subl(10) ^ (subr(10) & ~subr(8));
-       dw = tl & subl(8),  /* FL(kl1) */
-               tr = subr(10) ^ CAMELLIA_RL1(dw);
-       CamelliaSubkeyL(7) = subl(6) ^ tl; /* round 6 */
-       CamelliaSubkeyR(7) = subr(6) ^ tr;
-       CamelliaSubkeyL(8) = subl(8);       /* FL(kl1) */
-       CamelliaSubkeyR(8) = subr(8);
-       CamelliaSubkeyL(9) = subl(9);       /* FLinv(kl2) */
-       CamelliaSubkeyR(9) = subr(9);
-       tl = subl(7) ^ (subr(7) & ~subr(9));
-       dw = tl & subl(9),  /* FLinv(kl2) */
-               tr = subr(7) ^ CAMELLIA_RL1(dw);
-       CamelliaSubkeyL(10) = tl ^ subl(11); /* round 7 */
-       CamelliaSubkeyR(10) = tr ^ subr(11);
-       CamelliaSubkeyL(11) = subl(10) ^ subl(12); /* round 8 */
-       CamelliaSubkeyR(11) = subr(10) ^ subr(12);
-       CamelliaSubkeyL(12) = subl(11) ^ subl(13); /* round 9 */
-       CamelliaSubkeyR(12) = subr(11) ^ subr(13);
-       CamelliaSubkeyL(13) = subl(12) ^ subl(14); /* round 10 */
-       CamelliaSubkeyR(13) = subr(12) ^ subr(14);
-       CamelliaSubkeyL(14) = subl(13) ^ subl(15); /* round 11 */
-       CamelliaSubkeyR(14) = subr(13) ^ subr(15);
-       tl = subl(18) ^ (subr(18) & ~subr(16));
-       dw = tl & subl(16), /* FL(kl3) */
-               tr = subr(18) ^ CAMELLIA_RL1(dw);
-       CamelliaSubkeyL(15) = subl(14) ^ tl; /* round 12 */
-       CamelliaSubkeyR(15) = subr(14) ^ tr;
-       CamelliaSubkeyL(16) = subl(16);     /* FL(kl3) */
-       CamelliaSubkeyR(16) = subr(16);
-       CamelliaSubkeyL(17) = subl(17);     /* FLinv(kl4) */
-       CamelliaSubkeyR(17) = subr(17);
-       tl = subl(15) ^ (subr(15) & ~subr(17));
-       dw = tl & subl(17), /* FLinv(kl4) */
-               tr = subr(15) ^ CAMELLIA_RL1(dw);
-       CamelliaSubkeyL(18) = tl ^ subl(19); /* round 13 */
-       CamelliaSubkeyR(18) = tr ^ subr(19);
-       CamelliaSubkeyL(19) = subl(18) ^ subl(20); /* round 14 */
-       CamelliaSubkeyR(19) = subr(18) ^ subr(20);
-       CamelliaSubkeyL(20) = subl(19) ^ subl(21); /* round 15 */
-       CamelliaSubkeyR(20) = subr(19) ^ subr(21);
-       CamelliaSubkeyL(21) = subl(20) ^ subl(22); /* round 16 */
-       CamelliaSubkeyR(21) = subr(20) ^ subr(22);
-       CamelliaSubkeyL(22) = subl(21) ^ subl(23); /* round 17 */
-       CamelliaSubkeyR(22) = subr(21) ^ subr(23);
-       CamelliaSubkeyL(23) = subl(22);     /* round 18 */
-       CamelliaSubkeyR(23) = subr(22);
-       CamelliaSubkeyL(24) = subl(24) ^ subl(23); /* kw3 */
-       CamelliaSubkeyR(24) = subr(24) ^ subr(23);
-
-       /* apply the inverse of the last half of P-function */
-       dw = CamelliaSubkeyL(2) ^ CamelliaSubkeyR(2),
-               dw = CAMELLIA_RL8(dw);/* round 1 */
-       CamelliaSubkeyR(2) = CamelliaSubkeyL(2) ^ dw,
-               CamelliaSubkeyL(2) = dw;
-       dw = CamelliaSubkeyL(3) ^ CamelliaSubkeyR(3),
-               dw = CAMELLIA_RL8(dw);/* round 2 */
-       CamelliaSubkeyR(3) = CamelliaSubkeyL(3) ^ dw,
-               CamelliaSubkeyL(3) = dw;
-       dw = CamelliaSubkeyL(4) ^ CamelliaSubkeyR(4),
-               dw = CAMELLIA_RL8(dw);/* round 3 */
-       CamelliaSubkeyR(4) = CamelliaSubkeyL(4) ^ dw,
-               CamelliaSubkeyL(4) = dw;
-       dw = CamelliaSubkeyL(5) ^ CamelliaSubkeyR(5),
-               dw = CAMELLIA_RL8(dw);/* round 4 */
-       CamelliaSubkeyR(5) = CamelliaSubkeyL(5) ^ dw,
-               CamelliaSubkeyL(5) = dw;
-       dw = CamelliaSubkeyL(6) ^ CamelliaSubkeyR(6),
-               dw = CAMELLIA_RL8(dw);/* round 5 */
-       CamelliaSubkeyR(6) = CamelliaSubkeyL(6) ^ dw,
-               CamelliaSubkeyL(6) = dw;
-       dw = CamelliaSubkeyL(7) ^ CamelliaSubkeyR(7),
-               dw = CAMELLIA_RL8(dw);/* round 6 */
-       CamelliaSubkeyR(7) = CamelliaSubkeyL(7) ^ dw,
-               CamelliaSubkeyL(7) = dw;
-       dw = CamelliaSubkeyL(10) ^ CamelliaSubkeyR(10),
-               dw = CAMELLIA_RL8(dw);/* round 7 */
-       CamelliaSubkeyR(10) = CamelliaSubkeyL(10) ^ dw,
-               CamelliaSubkeyL(10) = dw;
-       dw = CamelliaSubkeyL(11) ^ CamelliaSubkeyR(11),
-               dw = CAMELLIA_RL8(dw);/* round 8 */
-       CamelliaSubkeyR(11) = CamelliaSubkeyL(11) ^ dw,
-               CamelliaSubkeyL(11) = dw;
-       dw = CamelliaSubkeyL(12) ^ CamelliaSubkeyR(12),
-               dw = CAMELLIA_RL8(dw);/* round 9 */
-       CamelliaSubkeyR(12) = CamelliaSubkeyL(12) ^ dw,
-               CamelliaSubkeyL(12) = dw;
-       dw = CamelliaSubkeyL(13) ^ CamelliaSubkeyR(13),
-               dw = CAMELLIA_RL8(dw);/* round 10 */
-       CamelliaSubkeyR(13) = CamelliaSubkeyL(13) ^ dw,
-               CamelliaSubkeyL(13) = dw;
-       dw = CamelliaSubkeyL(14) ^ CamelliaSubkeyR(14),
-               dw = CAMELLIA_RL8(dw);/* round 11 */
-       CamelliaSubkeyR(14) = CamelliaSubkeyL(14) ^ dw,
-               CamelliaSubkeyL(14) = dw;
-       dw = CamelliaSubkeyL(15) ^ CamelliaSubkeyR(15),
-               dw = CAMELLIA_RL8(dw);/* round 12 */
-       CamelliaSubkeyR(15) = CamelliaSubkeyL(15) ^ dw,
-               CamelliaSubkeyL(15) = dw;
-       dw = CamelliaSubkeyL(18) ^ CamelliaSubkeyR(18),
-               dw = CAMELLIA_RL8(dw);/* round 13 */
-       CamelliaSubkeyR(18) = CamelliaSubkeyL(18) ^ dw,
-               CamelliaSubkeyL(18) = dw;
-       dw = CamelliaSubkeyL(19) ^ CamelliaSubkeyR(19),
-               dw = CAMELLIA_RL8(dw);/* round 14 */
-       CamelliaSubkeyR(19) = CamelliaSubkeyL(19) ^ dw,
-               CamelliaSubkeyL(19) = dw;
-       dw = CamelliaSubkeyL(20) ^ CamelliaSubkeyR(20),
-               dw = CAMELLIA_RL8(dw);/* round 15 */
-       CamelliaSubkeyR(20) = CamelliaSubkeyL(20) ^ dw,
-               CamelliaSubkeyL(20) = dw;
-       dw = CamelliaSubkeyL(21) ^ CamelliaSubkeyR(21),
-               dw = CAMELLIA_RL8(dw);/* round 16 */
-       CamelliaSubkeyR(21) = CamelliaSubkeyL(21) ^ dw,
-               CamelliaSubkeyL(21) = dw;
-       dw = CamelliaSubkeyL(22) ^ CamelliaSubkeyR(22),
-               dw = CAMELLIA_RL8(dw);/* round 17 */
-       CamelliaSubkeyR(22) = CamelliaSubkeyL(22) ^ dw,
-               CamelliaSubkeyL(22) = dw;
-       dw = CamelliaSubkeyL(23) ^ CamelliaSubkeyR(23),
-               dw = CAMELLIA_RL8(dw);/* round 18 */
-       CamelliaSubkeyR(23) = CamelliaSubkeyL(23) ^ dw,
-               CamelliaSubkeyL(23) = dw;
-
-       return;
+       register u32 s0,s1,s2,s3;
+
+       k[0] = s0 = GETU32(rawKey);
+       k[1] = s1 = GETU32(rawKey+4);
+       k[2] = s2 = GETU32(rawKey+8);
+       k[3] = s3 = GETU32(rawKey+12);
+
+       if (keyBitLength != 128)
+               {
+               k[8] = s0 = GETU32(rawKey+16);
+               k[9] = s1 = GETU32(rawKey+20);
+               if (keyBitLength == 192)
+                       {
+                       k[10] = s2 = ~s0;
+                       k[11] = s3 = ~s1;
+                       }
+               else
+                       {
+                       k[10] = s2 = GETU32(rawKey+24);
+                       k[11] = s3 = GETU32(rawKey+28);
+                       }
+               s0 ^= k[0], s1 ^= k[1], s2 ^= k[2], s3 ^= k[3];
+               }
+
+       /* Use the Feistel routine to scramble the key material */
+       Camellia_Feistel(s0,s1,s2,s3,SIGMA+0);
+       Camellia_Feistel(s2,s3,s0,s1,SIGMA+2);
+
+       s0 ^= k[0], s1 ^= k[1], s2 ^= k[2], s3 ^= k[3];
+       Camellia_Feistel(s0,s1,s2,s3,SIGMA+4);
+       Camellia_Feistel(s2,s3,s0,s1,SIGMA+6);
+
+       /* Fill the keyTable. Requires many block rotations. */
+       if (keyBitLength == 128)
+               {
+               k[ 4] = s0, k[ 5] = s1, k[ 6] = s2, k[ 7] = s3;
+               RotLeft128(s0,s1,s2,s3,15);     /* KA <<< 15 */
+               k[12] = s0, k[13] = s1, k[14] = s2, k[15] = s3;
+               RotLeft128(s0,s1,s2,s3,15);     /* KA <<< 30 */
+               k[16] = s0, k[17] = s1, k[18] = s2, k[19] = s3;
+               RotLeft128(s0,s1,s2,s3,15);     /* KA <<< 45 */
+               k[24] = s0, k[25] = s1;
+               RotLeft128(s0,s1,s2,s3,15);     /* KA <<< 60 */
+               k[28] = s0, k[29] = s1, k[30] = s2, k[31] = s3;
+               RotLeft128(s1,s2,s3,s0,2);      /* KA <<< 94 */
+               k[40] = s1, k[41] = s2, k[42] = s3, k[43] = s0;
+               RotLeft128(s1,s2,s3,s0,17);     /* KA <<<111 */
+               k[48] = s1, k[49] = s2, k[50] = s3, k[51] = s0;
+
+               s0 = k[ 0], s1 = k[ 1], s2 = k[ 2], s3 = k[ 3];
+               RotLeft128(s0,s1,s2,s3,15);     /* KL <<< 15 */
+               k[ 8] = s0, k[ 9] = s1, k[10] = s2, k[11] = s3;
+               RotLeft128(s0,s1,s2,s3,30);     /* KL <<< 45 */
+               k[20] = s0, k[21] = s1, k[22] = s2, k[23] = s3;
+               RotLeft128(s0,s1,s2,s3,15);     /* KL <<< 60 */
+               k[26] = s2, k[27] = s3;
+               RotLeft128(s0,s1,s2,s3,17);     /* KL <<< 77 */
+               k[32] = s0, k[33] = s1, k[34] = s2, k[35] = s3;
+               RotLeft128(s0,s1,s2,s3,17);     /* KL <<< 94 */
+               k[36] = s0, k[37] = s1, k[38] = s2, k[39] = s3;
+               RotLeft128(s0,s1,s2,s3,17);     /* KL <<<111 */
+               k[44] = s0, k[45] = s1, k[46] = s2, k[47] = s3;
+
+               return 3;       /* grand rounds */
+               }
+       else
+               {
+               k[12] = s0, k[13] = s1, k[14] = s2, k[15] = s3;
+               s0 ^= k[8], s1 ^= k[9], s2 ^=k[10], s3 ^=k[11];
+               Camellia_Feistel(s0,s1,s2,s3,(SIGMA+8));
+               Camellia_Feistel(s2,s3,s0,s1,(SIGMA+10));
+
+               k[ 4] = s0, k[ 5] = s1, k[ 6] = s2, k[ 7] = s3;
+               RotLeft128(s0,s1,s2,s3,30);     /* KB <<< 30 */
+               k[20] = s0, k[21] = s1, k[22] = s2, k[23] = s3;
+               RotLeft128(s0,s1,s2,s3,30);     /* KB <<< 60 */
+               k[40] = s0, k[41] = s1, k[42] = s2, k[43] = s3;
+               RotLeft128(s1,s2,s3,s0,19);     /* KB <<<111 */
+               k[64] = s1, k[65] = s2, k[66] = s3, k[67] = s0;
+
+               s0 = k[ 8], s1 = k[ 9], s2 = k[10], s3 = k[11];
+               RotLeft128(s0,s1,s2,s3,15);     /* KR <<< 15 */
+               k[ 8] = s0, k[ 9] = s1, k[10] = s2, k[11] = s3;
+               RotLeft128(s0,s1,s2,s3,15);     /* KR <<< 30 */
+               k[16] = s0, k[17] = s1, k[18] = s2, k[19] = s3;
+               RotLeft128(s0,s1,s2,s3,30);     /* KR <<< 60 */
+               k[36] = s0, k[37] = s1, k[38] = s2, k[39] = s3;
+               RotLeft128(s1,s2,s3,s0,2);      /* KR <<< 94 */
+               k[52] = s1, k[53] = s2, k[54] = s3, k[55] = s0;
+
+               s0 = k[12], s1 = k[13], s2 = k[14], s3 = k[15];
+               RotLeft128(s0,s1,s2,s3,15);     /* KA <<< 15 */
+               k[12] = s0, k[13] = s1, k[14] = s2, k[15] = s3;
+               RotLeft128(s0,s1,s2,s3,30);     /* KA <<< 45 */
+               k[28] = s0, k[29] = s1, k[30] = s2, k[31] = s3;
+                                               /* KA <<< 77 */
+               k[48] = s1, k[49] = s2, k[50] = s3, k[51] = s0;
+               RotLeft128(s1,s2,s3,s0,17);     /* KA <<< 94 */
+               k[56] = s1, k[57] = s2, k[58] = s3, k[59] = s0;
+
+               s0 = k[ 0], s1 = k[ 1], s2 = k[ 2], s3 = k[ 3];
+               RotLeft128(s1,s2,s3,s0,13);     /* KL <<< 45 */
+               k[24] = s1, k[25] = s2, k[26] = s3, k[27] = s0;
+               RotLeft128(s1,s2,s3,s0,15);     /* KL <<< 60 */
+               k[32] = s1, k[33] = s2, k[34] = s3, k[35] = s0;
+               RotLeft128(s1,s2,s3,s0,17);     /* KL <<< 77 */
+               k[44] = s1, k[45] = s2, k[46] = s3, k[47] = s0;
+               RotLeft128(s2,s3,s0,s1,2);      /* KL <<<111 */
+               k[60] = s2, k[61] = s3, k[62] = s0, k[63] = s1;
+
+               return 4;       /* grand rounds */
+               }
+       /*
+        * It is possible to perform certain precalculations, which
+        * would spare few cycles in block procedure. It's not done,
+        * because it upsets the performance balance between key
+        * setup and block procedures, negatively affecting overall
+        * throughput in applications operating on short messages
+        * and volatile keys.
+        */ 
        }
 
-void camellia_setup256(const u8 *key, u32 *subkey)
+void Camellia_EncryptBlock_Rounds(int grandRounds, const u8 plaintext[], 
+               const KEY_TABLE_TYPE keyTable, u8 ciphertext[])
        {
-       u32 kll,klr,krl,krr;           /* left half of key */
-       u32 krll,krlr,krrl,krrr;       /* right half of key */
-       u32 il, ir, t0, t1, w0, w1;    /* temporary variables */
-       u32 kw4l, kw4r, dw, tl, tr;
-       u32 subL[34];
-       u32 subR[34];
-
-       /**
-        *  key = (kll || klr || krl || krr || krll || krlr || krrl || krrr)
-        *  (|| is concatination)
-        */
-
-       kll  = GETU32(key     );
-       klr  = GETU32(key +  4);
-       krl  = GETU32(key +  8);
-       krr  = GETU32(key + 12);
-       krll = GETU32(key + 16);
-       krlr = GETU32(key + 20);
-       krrl = GETU32(key + 24);
-       krrr = GETU32(key + 28);
-
-       /* generate KL dependent subkeys */
-       /* kw1 */
-       subl(0) = kll; subr(0) = klr;
-       /* kw2 */
-       subl(1) = krl; subr(1) = krr;
-       CAMELLIA_ROLDQo32(kll, klr, krl, krr, w0, w1, 45);
-       /* k9 */
-       subl(12) = kll; subr(12) = klr;
-       /* k10 */
-       subl(13) = krl; subr(13) = krr;
-       CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15);
-       /* kl3 */
-       subl(16) = kll; subr(16) = klr;
-       /* kl4 */
-       subl(17) = krl; subr(17) = krr;
-       CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 17);
-       /* k17 */
-       subl(22) = kll; subr(22) = klr;
-       /* k18 */
-       subl(23) = krl; subr(23) = krr;
-       CAMELLIA_ROLDQo32(kll, klr, krl, krr, w0, w1, 34);
-       /* k23 */
-       subl(30) = kll; subr(30) = klr;
-       /* k24 */
-       subl(31) = krl; subr(31) = krr;
-
-       /* generate KR dependent subkeys */
-       CAMELLIA_ROLDQ(krll, krlr, krrl, krrr, w0, w1, 15);
-       /* k3 */
-       subl(4) = krll; subr(4) = krlr;
-       /* k4 */
-       subl(5) = krrl; subr(5) = krrr;
-       CAMELLIA_ROLDQ(krll, krlr, krrl, krrr, w0, w1, 15);
-       /* kl1 */
-       subl(8) = krll; subr(8) = krlr;
-       /* kl2 */
-       subl(9) = krrl; subr(9) = krrr;
-       CAMELLIA_ROLDQ(krll, krlr, krrl, krrr, w0, w1, 30);
-       /* k13 */
-       subl(18) = krll; subr(18) = krlr;
-       /* k14 */
-       subl(19) = krrl; subr(19) = krrr;
-       CAMELLIA_ROLDQo32(krll, krlr, krrl, krrr, w0, w1, 34);
-       /* k19 */
-       subl(26) = krll; subr(26) = krlr;
-       /* k20 */
-       subl(27) = krrl; subr(27) = krrr;
-       CAMELLIA_ROLDQo32(krll, krlr, krrl, krrr, w0, w1, 34);
-
-       /* generate KA */
-       kll = subl(0) ^ krll; klr = subr(0) ^ krlr;
-       krl = subl(1) ^ krrl; krr = subr(1) ^ krrr;
-       CAMELLIA_F(kll, klr,
-               CAMELLIA_SIGMA1L, CAMELLIA_SIGMA1R,
-               w0, w1, il, ir, t0, t1);
-       krl ^= w0; krr ^= w1;
-       CAMELLIA_F(krl, krr,
-               CAMELLIA_SIGMA2L, CAMELLIA_SIGMA2R,
-               kll, klr, il, ir, t0, t1);
-       kll ^= krll; klr ^= krlr;
-       CAMELLIA_F(kll, klr,
-               CAMELLIA_SIGMA3L, CAMELLIA_SIGMA3R,
-               krl, krr, il, ir, t0, t1);
-       krl ^= w0 ^ krrl; krr ^= w1 ^ krrr;
-       CAMELLIA_F(krl, krr,
-               CAMELLIA_SIGMA4L, CAMELLIA_SIGMA4R,
-               w0, w1, il, ir, t0, t1);
-       kll ^= w0; klr ^= w1;
-
-       /* generate KB */
-       krll ^= kll; krlr ^= klr;
-       krrl ^= krl; krrr ^= krr;
-       CAMELLIA_F(krll, krlr,
-               CAMELLIA_SIGMA5L, CAMELLIA_SIGMA5R,
-               w0, w1, il, ir, t0, t1);
-       krrl ^= w0; krrr ^= w1;
-       CAMELLIA_F(krrl, krrr,
-               CAMELLIA_SIGMA6L, CAMELLIA_SIGMA6R,
-               w0, w1, il, ir, t0, t1);
-       krll ^= w0; krlr ^= w1;
-
-       /* generate KA dependent subkeys */
-       CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15);
-       /* k5 */
-       subl(6) = kll; subr(6) = klr;
-       /* k6 */
-       subl(7) = krl; subr(7) = krr;
-       CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 30);
-       /* k11 */
-       subl(14) = kll; subr(14) = klr;
-       /* k12 */
-       subl(15) = krl; subr(15) = krr;
-       /* rotation left shift 32bit */
-       /* kl5 */
-       subl(24) = klr; subr(24) = krl;
-       /* kl6 */
-       subl(25) = krr; subr(25) = kll;
-       /* rotation left shift 49 from k11,k12 -> k21,k22 */
-       CAMELLIA_ROLDQo32(kll, klr, krl, krr, w0, w1, 49);
-       /* k21 */
-       subl(28) = kll; subr(28) = klr;
-       /* k22 */
-       subl(29) = krl; subr(29) = krr;
-
-       /* generate KB dependent subkeys */
-       /* k1 */
-       subl(2) = krll; subr(2) = krlr;
-       /* k2 */
-       subl(3) = krrl; subr(3) = krrr;
-       CAMELLIA_ROLDQ(krll, krlr, krrl, krrr, w0, w1, 30);
-       /* k7 */
-       subl(10) = krll; subr(10) = krlr;
-       /* k8 */
-       subl(11) = krrl; subr(11) = krrr;
-       CAMELLIA_ROLDQ(krll, krlr, krrl, krrr, w0, w1, 30);
-       /* k15 */
-       subl(20) = krll; subr(20) = krlr;
-       /* k16 */
-       subl(21) = krrl; subr(21) = krrr;
-       CAMELLIA_ROLDQo32(krll, krlr, krrl, krrr, w0, w1, 51);
-       /* kw3 */
-       subl(32) = krll; subr(32) = krlr;
-       /* kw4 */
-       subl(33) = krrl; subr(33) = krrr;
-
-       /* absorb kw2 to other subkeys */
-/* round 2 */
-       subl(3) ^= subl(1); subr(3) ^= subr(1);
-/* round 4 */
-       subl(5) ^= subl(1); subr(5) ^= subr(1);
-/* round 6 */
-       subl(7) ^= subl(1); subr(7) ^= subr(1);
-       subl(1) ^= subr(1) & ~subr(9);
-       dw = subl(1) & subl(9),
-               subr(1) ^= CAMELLIA_RL1(dw); /* modified for FLinv(kl2) */
-/* round 8 */
-       subl(11) ^= subl(1); subr(11) ^= subr(1);
-/* round 10 */
-       subl(13) ^= subl(1); subr(13) ^= subr(1);
-/* round 12 */
-       subl(15) ^= subl(1); subr(15) ^= subr(1);
-       subl(1) ^= subr(1) & ~subr(17);
-       dw = subl(1) & subl(17),
-               subr(1) ^= CAMELLIA_RL1(dw); /* modified for FLinv(kl4) */
-/* round 14 */
-       subl(19) ^= subl(1); subr(19) ^= subr(1);
-/* round 16 */
-       subl(21) ^= subl(1); subr(21) ^= subr(1);
-/* round 18 */
-       subl(23) ^= subl(1); subr(23) ^= subr(1);
-       subl(1) ^= subr(1) & ~subr(25);
-       dw = subl(1) & subl(25),
-               subr(1) ^= CAMELLIA_RL1(dw); /* modified for FLinv(kl6) */
-/* round 20 */
-       subl(27) ^= subl(1); subr(27) ^= subr(1);
-/* round 22 */
-       subl(29) ^= subl(1); subr(29) ^= subr(1);
-/* round 24 */
-       subl(31) ^= subl(1); subr(31) ^= subr(1);
-/* kw3 */
-       subl(32) ^= subl(1); subr(32) ^= subr(1);
-
-
-       /* absorb kw4 to other subkeys */
-       kw4l = subl(33); kw4r = subr(33);
-/* round 23 */
-       subl(30) ^= kw4l; subr(30) ^= kw4r;
-/* round 21 */
-       subl(28) ^= kw4l; subr(28) ^= kw4r;
-/* round 19 */
-       subl(26) ^= kw4l; subr(26) ^= kw4r;
-       kw4l ^= kw4r & ~subr(24);
-       dw = kw4l & subl(24),
-               kw4r ^= CAMELLIA_RL1(dw); /* modified for FL(kl5) */
-/* round 17 */
-       subl(22) ^= kw4l; subr(22) ^= kw4r;
-/* round 15 */
-       subl(20) ^= kw4l; subr(20) ^= kw4r;
-/* round 13 */
-       subl(18) ^= kw4l; subr(18) ^= kw4r;
-       kw4l ^= kw4r & ~subr(16);
-       dw = kw4l & subl(16),
-               kw4r ^= CAMELLIA_RL1(dw); /* modified for FL(kl3) */
-/* round 11 */
-       subl(14) ^= kw4l; subr(14) ^= kw4r;
-/* round 9 */
-       subl(12) ^= kw4l; subr(12) ^= kw4r;
-/* round 7 */
-       subl(10) ^= kw4l; subr(10) ^= kw4r;
-       kw4l ^= kw4r & ~subr(8);
-       dw = kw4l & subl(8),
-               kw4r ^= CAMELLIA_RL1(dw); /* modified for FL(kl1) */
-/* round 5 */
-       subl(6) ^= kw4l; subr(6) ^= kw4r;
-/* round 3 */
-       subl(4) ^= kw4l; subr(4) ^= kw4r;
-/* round 1 */
-       subl(2) ^= kw4l; subr(2) ^= kw4r;
-/* kw1 */
-       subl(0) ^= kw4l; subr(0) ^= kw4r;
-
-       /* key XOR is end of F-function */
-       CamelliaSubkeyL(0) = subl(0) ^ subl(2);/* kw1 */
-       CamelliaSubkeyR(0) = subr(0) ^ subr(2);
-       CamelliaSubkeyL(2) = subl(3);       /* round 1 */
-       CamelliaSubkeyR(2) = subr(3);
-       CamelliaSubkeyL(3) = subl(2) ^ subl(4); /* round 2 */
-       CamelliaSubkeyR(3) = subr(2) ^ subr(4);
-       CamelliaSubkeyL(4) = subl(3) ^ subl(5); /* round 3 */
-       CamelliaSubkeyR(4) = subr(3) ^ subr(5);
-       CamelliaSubkeyL(5) = subl(4) ^ subl(6); /* round 4 */
-       CamelliaSubkeyR(5) = subr(4) ^ subr(6);
-       CamelliaSubkeyL(6) = subl(5) ^ subl(7); /* round 5 */
-       CamelliaSubkeyR(6) = subr(5) ^ subr(7);
-       tl = subl(10) ^ (subr(10) & ~subr(8));
-       dw = tl & subl(8),  /* FL(kl1) */
-               tr = subr(10) ^ CAMELLIA_RL1(dw);
-       CamelliaSubkeyL(7) = subl(6) ^ tl; /* round 6 */
-       CamelliaSubkeyR(7) = subr(6) ^ tr;
-       CamelliaSubkeyL(8) = subl(8);       /* FL(kl1) */
-       CamelliaSubkeyR(8) = subr(8);
-       CamelliaSubkeyL(9) = subl(9);       /* FLinv(kl2) */
-       CamelliaSubkeyR(9) = subr(9);
-       tl = subl(7) ^ (subr(7) & ~subr(9));
-       dw = tl & subl(9),  /* FLinv(kl2) */
-               tr = subr(7) ^ CAMELLIA_RL1(dw);
-       CamelliaSubkeyL(10) = tl ^ subl(11); /* round 7 */
-       CamelliaSubkeyR(10) = tr ^ subr(11);
-       CamelliaSubkeyL(11) = subl(10) ^ subl(12); /* round 8 */
-       CamelliaSubkeyR(11) = subr(10) ^ subr(12);
-       CamelliaSubkeyL(12) = subl(11) ^ subl(13); /* round 9 */
-       CamelliaSubkeyR(12) = subr(11) ^ subr(13);
-       CamelliaSubkeyL(13) = subl(12) ^ subl(14); /* round 10 */
-       CamelliaSubkeyR(13) = subr(12) ^ subr(14);
-       CamelliaSubkeyL(14) = subl(13) ^ subl(15); /* round 11 */
-       CamelliaSubkeyR(14) = subr(13) ^ subr(15);
-       tl = subl(18) ^ (subr(18) & ~subr(16));
-       dw = tl & subl(16), /* FL(kl3) */
-               tr = subr(18) ^ CAMELLIA_RL1(dw);
-       CamelliaSubkeyL(15) = subl(14) ^ tl; /* round 12 */
-       CamelliaSubkeyR(15) = subr(14) ^ tr;
-       CamelliaSubkeyL(16) = subl(16);     /* FL(kl3) */
-       CamelliaSubkeyR(16) = subr(16);
-       CamelliaSubkeyL(17) = subl(17);     /* FLinv(kl4) */
-       CamelliaSubkeyR(17) = subr(17);
-       tl = subl(15) ^ (subr(15) & ~subr(17));
-       dw = tl & subl(17), /* FLinv(kl4) */
-               tr = subr(15) ^ CAMELLIA_RL1(dw);
-       CamelliaSubkeyL(18) = tl ^ subl(19); /* round 13 */
-       CamelliaSubkeyR(18) = tr ^ subr(19);
-       CamelliaSubkeyL(19) = subl(18) ^ subl(20); /* round 14 */
-       CamelliaSubkeyR(19) = subr(18) ^ subr(20);
-       CamelliaSubkeyL(20) = subl(19) ^ subl(21); /* round 15 */
-       CamelliaSubkeyR(20) = subr(19) ^ subr(21);
-       CamelliaSubkeyL(21) = subl(20) ^ subl(22); /* round 16 */
-       CamelliaSubkeyR(21) = subr(20) ^ subr(22);
-       CamelliaSubkeyL(22) = subl(21) ^ subl(23); /* round 17 */
-       CamelliaSubkeyR(22) = subr(21) ^ subr(23);
-       tl = subl(26) ^ (subr(26)
-               & ~subr(24));
-       dw = tl & subl(24), /* FL(kl5) */
-               tr = subr(26) ^ CAMELLIA_RL1(dw);
-       CamelliaSubkeyL(23) = subl(22) ^ tl; /* round 18 */
-       CamelliaSubkeyR(23) = subr(22) ^ tr;
-       CamelliaSubkeyL(24) = subl(24);     /* FL(kl5) */
-       CamelliaSubkeyR(24) = subr(24);
-       CamelliaSubkeyL(25) = subl(25);     /* FLinv(kl6) */
-       CamelliaSubkeyR(25) = subr(25);
-       tl = subl(23) ^ (subr(23) &
-               ~subr(25));
-       dw = tl & subl(25), /* FLinv(kl6) */
-               tr = subr(23) ^ CAMELLIA_RL1(dw);
-       CamelliaSubkeyL(26) = tl ^ subl(27); /* round 19 */
-       CamelliaSubkeyR(26) = tr ^ subr(27);
-       CamelliaSubkeyL(27) = subl(26) ^ subl(28); /* round 20 */
-       CamelliaSubkeyR(27) = subr(26) ^ subr(28);
-       CamelliaSubkeyL(28) = subl(27) ^ subl(29); /* round 21 */
-       CamelliaSubkeyR(28) = subr(27) ^ subr(29);
-       CamelliaSubkeyL(29) = subl(28) ^ subl(30); /* round 22 */
-       CamelliaSubkeyR(29) = subr(28) ^ subr(30);
-       CamelliaSubkeyL(30) = subl(29) ^ subl(31); /* round 23 */
-       CamelliaSubkeyR(30) = subr(29) ^ subr(31);
-       CamelliaSubkeyL(31) = subl(30);     /* round 24 */
-       CamelliaSubkeyR(31) = subr(30);
-       CamelliaSubkeyL(32) = subl(32) ^ subl(31); /* kw3 */
-       CamelliaSubkeyR(32) = subr(32) ^ subr(31);
-
-       /* apply the inverse of the last half of P-function */
-       dw = CamelliaSubkeyL(2) ^ CamelliaSubkeyR(2),
-               dw = CAMELLIA_RL8(dw);/* round 1 */
-       CamelliaSubkeyR(2) = CamelliaSubkeyL(2) ^ dw,
-               CamelliaSubkeyL(2) = dw;
-       dw = CamelliaSubkeyL(3) ^ CamelliaSubkeyR(3),
-               dw = CAMELLIA_RL8(dw);/* round 2 */
-       CamelliaSubkeyR(3) = CamelliaSubkeyL(3) ^ dw,
-               CamelliaSubkeyL(3) = dw;
-       dw = CamelliaSubkeyL(4) ^ CamelliaSubkeyR(4),
-               dw = CAMELLIA_RL8(dw);/* round 3 */
-       CamelliaSubkeyR(4) = CamelliaSubkeyL(4) ^ dw,
-               CamelliaSubkeyL(4) = dw;
-       dw = CamelliaSubkeyL(5) ^ CamelliaSubkeyR(5),
-               dw = CAMELLIA_RL8(dw);/* round 4 */
-       CamelliaSubkeyR(5) = CamelliaSubkeyL(5) ^ dw,
-               CamelliaSubkeyL(5) = dw;
-       dw = CamelliaSubkeyL(6) ^ CamelliaSubkeyR(6),
-               dw = CAMELLIA_RL8(dw);/* round 5 */
-       CamelliaSubkeyR(6) = CamelliaSubkeyL(6) ^ dw,
-               CamelliaSubkeyL(6) = dw;
-       dw = CamelliaSubkeyL(7) ^ CamelliaSubkeyR(7),
-               dw = CAMELLIA_RL8(dw);/* round 6 */
-       CamelliaSubkeyR(7) = CamelliaSubkeyL(7) ^ dw,
-               CamelliaSubkeyL(7) = dw;
-       dw = CamelliaSubkeyL(10) ^ CamelliaSubkeyR(10),
-               dw = CAMELLIA_RL8(dw);/* round 7 */
-       CamelliaSubkeyR(10) = CamelliaSubkeyL(10) ^ dw,
-               CamelliaSubkeyL(10) = dw;
-       dw = CamelliaSubkeyL(11) ^ CamelliaSubkeyR(11),
-               dw = CAMELLIA_RL8(dw);/* round 8 */
-       CamelliaSubkeyR(11) = CamelliaSubkeyL(11) ^ dw,
-               CamelliaSubkeyL(11) = dw;
-       dw = CamelliaSubkeyL(12) ^ CamelliaSubkeyR(12),
-               dw = CAMELLIA_RL8(dw);/* round 9 */
-       CamelliaSubkeyR(12) = CamelliaSubkeyL(12) ^ dw,
-               CamelliaSubkeyL(12) = dw;
-       dw = CamelliaSubkeyL(13) ^ CamelliaSubkeyR(13),
-               dw = CAMELLIA_RL8(dw);/* round 10 */
-       CamelliaSubkeyR(13) = CamelliaSubkeyL(13) ^ dw,
-               CamelliaSubkeyL(13) = dw;
-       dw = CamelliaSubkeyL(14) ^ CamelliaSubkeyR(14),
-               dw = CAMELLIA_RL8(dw);/* round 11 */
-       CamelliaSubkeyR(14) = CamelliaSubkeyL(14) ^ dw,
-               CamelliaSubkeyL(14) = dw;
-       dw = CamelliaSubkeyL(15) ^ CamelliaSubkeyR(15),
-               dw = CAMELLIA_RL8(dw);/* round 12 */
-       CamelliaSubkeyR(15) = CamelliaSubkeyL(15) ^ dw,
-               CamelliaSubkeyL(15) = dw;
-       dw = CamelliaSubkeyL(18) ^ CamelliaSubkeyR(18),
-               dw = CAMELLIA_RL8(dw);/* round 13 */
-       CamelliaSubkeyR(18) = CamelliaSubkeyL(18) ^ dw,
-               CamelliaSubkeyL(18) = dw;
-       dw = CamelliaSubkeyL(19) ^ CamelliaSubkeyR(19),
-               dw = CAMELLIA_RL8(dw);/* round 14 */
-       CamelliaSubkeyR(19) = CamelliaSubkeyL(19) ^ dw,
-               CamelliaSubkeyL(19) = dw;
-       dw = CamelliaSubkeyL(20) ^ CamelliaSubkeyR(20),
-               dw = CAMELLIA_RL8(dw);/* round 15 */
-       CamelliaSubkeyR(20) = CamelliaSubkeyL(20) ^ dw,
-               CamelliaSubkeyL(20) = dw;
-       dw = CamelliaSubkeyL(21) ^ CamelliaSubkeyR(21),
-               dw = CAMELLIA_RL8(dw);/* round 16 */
-       CamelliaSubkeyR(21) = CamelliaSubkeyL(21) ^ dw,
-               CamelliaSubkeyL(21) = dw;
-       dw = CamelliaSubkeyL(22) ^ CamelliaSubkeyR(22),
-               dw = CAMELLIA_RL8(dw);/* round 17 */
-       CamelliaSubkeyR(22) = CamelliaSubkeyL(22) ^ dw,
-               CamelliaSubkeyL(22) = dw;
-       dw = CamelliaSubkeyL(23) ^ CamelliaSubkeyR(23),
-               dw = CAMELLIA_RL8(dw);/* round 18 */
-       CamelliaSubkeyR(23) = CamelliaSubkeyL(23) ^ dw,
-               CamelliaSubkeyL(23) = dw;
-       dw = CamelliaSubkeyL(26) ^ CamelliaSubkeyR(26),
-               dw = CAMELLIA_RL8(dw);/* round 19 */
-       CamelliaSubkeyR(26) = CamelliaSubkeyL(26) ^ dw,
-               CamelliaSubkeyL(26) = dw;
-       dw = CamelliaSubkeyL(27) ^ CamelliaSubkeyR(27),
-               dw = CAMELLIA_RL8(dw);/* round 20 */
-       CamelliaSubkeyR(27) = CamelliaSubkeyL(27) ^ dw,
-               CamelliaSubkeyL(27) = dw;
-       dw = CamelliaSubkeyL(28) ^ CamelliaSubkeyR(28),
-               dw = CAMELLIA_RL8(dw);/* round 21 */
-       CamelliaSubkeyR(28) = CamelliaSubkeyL(28) ^ dw,
-               CamelliaSubkeyL(28) = dw;
-       dw = CamelliaSubkeyL(29) ^ CamelliaSubkeyR(29),
-               dw = CAMELLIA_RL8(dw);/* round 22 */
-       CamelliaSubkeyR(29) = CamelliaSubkeyL(29) ^ dw,
-               CamelliaSubkeyL(29) = dw;
-       dw = CamelliaSubkeyL(30) ^ CamelliaSubkeyR(30),
-               dw = CAMELLIA_RL8(dw);/* round 23 */
-       CamelliaSubkeyR(30) = CamelliaSubkeyL(30) ^ dw,
-               CamelliaSubkeyL(30) = dw;
-       dw = CamelliaSubkeyL(31) ^ CamelliaSubkeyR(31),
-               dw = CAMELLIA_RL8(dw);/* round 24 */
-       CamelliaSubkeyR(31) = CamelliaSubkeyL(31) ^ dw,
-               CamelliaSubkeyL(31) = dw;
-
-    
-       return;
+       register u32 s0,s1,s2,s3; 
+       const u32 *k = keyTable,*kend = keyTable+grandRounds*16; 
+
+       s0 = GETU32(plaintext)    ^ k[0];
+       s1 = GETU32(plaintext+4)  ^ k[1];
+       s2 = GETU32(plaintext+8)  ^ k[2];
+       s3 = GETU32(plaintext+12) ^ k[3];
+       k += 4;
+
+       while (1)
+               {
+               /* Camellia makes 6 Feistel rounds */
+               Camellia_Feistel(s0,s1,s2,s3,k+0);
+               Camellia_Feistel(s2,s3,s0,s1,k+2);
+               Camellia_Feistel(s0,s1,s2,s3,k+4);
+               Camellia_Feistel(s2,s3,s0,s1,k+6);
+               Camellia_Feistel(s0,s1,s2,s3,k+8);
+               Camellia_Feistel(s2,s3,s0,s1,k+10);
+               k += 12;
+
+               if (k == kend) break;
+
+               /* This is the same function as the diffusion function D
+                * of the accompanying documentation. See section 3.2
+                * for properties of the FLlayer function. */
+               s1 ^= LeftRotate(s0 & k[0], 1);
+               s2 ^= s3 | k[3];
+               s0 ^= s1 | k[1];
+               s3 ^= LeftRotate(s2 & k[2], 1);
+               k += 4;
+               }
+
+       s2 ^= k[0], s3 ^= k[1], s0 ^= k[2], s1 ^= k[3];
+
+       PUTU32(ciphertext,   s2);
+       PUTU32(ciphertext+4, s3);
+       PUTU32(ciphertext+8, s0);
+       PUTU32(ciphertext+12,s1);
        }
-
-void camellia_setup192(const u8 *key, u32 *subkey)
-       {
-       u8 kk[32];
-       u32 krll, krlr, krrl,krrr;
-
-       memcpy(kk, key, 24);
-       memcpy((u8 *)&krll, key+16,4);
-       memcpy((u8 *)&krlr, key+20,4);
-       krrl = ~krll;
-       krrr = ~krlr;
-       memcpy(kk+24, (u8 *)&krrl, 4);
-       memcpy(kk+28, (u8 *)&krrr, 4);
-       camellia_setup256(kk, subkey);
-       return;
-       }
-
-
-/**
- * Stuff related to camellia encryption/decryption
- */
-void camellia_encrypt128(const u32 *subkey, u32 *io)
-       {
-       u32 il, ir, t0, t1;
-
-       /* pre whitening but absorb kw2*/
-       io[0] ^= CamelliaSubkeyL(0);
-       io[1] ^= CamelliaSubkeyR(0);
-       /* main iteration */
-
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(2),CamelliaSubkeyR(2),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(3),CamelliaSubkeyR(3),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(4),CamelliaSubkeyR(4),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(5),CamelliaSubkeyR(5),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(6),CamelliaSubkeyR(6),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(7),CamelliaSubkeyR(7),
-               io[0],io[1],il,ir,t0,t1);
-
-       CAMELLIA_FLS(io[0],io[1],io[2],io[3],
-               CamelliaSubkeyL(8),CamelliaSubkeyR(8),
-               CamelliaSubkeyL(9),CamelliaSubkeyR(9),
-               t0,t1,il,ir);
-
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(10),CamelliaSubkeyR(10),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(11),CamelliaSubkeyR(11),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(12),CamelliaSubkeyR(12),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(13),CamelliaSubkeyR(13),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(14),CamelliaSubkeyR(14),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(15),CamelliaSubkeyR(15),
-               io[0],io[1],il,ir,t0,t1);
-
-       CAMELLIA_FLS(io[0],io[1],io[2],io[3],
-               CamelliaSubkeyL(16),CamelliaSubkeyR(16),
-               CamelliaSubkeyL(17),CamelliaSubkeyR(17),
-               t0,t1,il,ir);
-
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(18),CamelliaSubkeyR(18),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(19),CamelliaSubkeyR(19),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(20),CamelliaSubkeyR(20),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(21),CamelliaSubkeyR(21),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(22),CamelliaSubkeyR(22),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(23),CamelliaSubkeyR(23),
-               io[0],io[1],il,ir,t0,t1);
-
-       /* post whitening but kw4 */
-       io[2] ^= CamelliaSubkeyL(24);
-       io[3] ^= CamelliaSubkeyR(24);
-
-       t0 = io[0];
-       t1 = io[1];
-       io[0] = io[2];
-       io[1] = io[3];
-       io[2] = t0;
-       io[3] = t1;
-
-       return;
-       }
-
-void camellia_decrypt128(const u32 *subkey, u32 *io)
+void Camellia_EncryptBlock(int keyBitLength, const u8 plaintext[], 
+               const KEY_TABLE_TYPE keyTable, u8 ciphertext[])
        {
-       u32 il,ir,t0,t1;               /* temporary valiables */
-
-       /* pre whitening but absorb kw2*/
-       io[0] ^= CamelliaSubkeyL(24);
-       io[1] ^= CamelliaSubkeyR(24);
-
-       /* main iteration */
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(23),CamelliaSubkeyR(23),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(22),CamelliaSubkeyR(22),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(21),CamelliaSubkeyR(21),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(20),CamelliaSubkeyR(20),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(19),CamelliaSubkeyR(19),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(18),CamelliaSubkeyR(18),
-               io[0],io[1],il,ir,t0,t1);
-
-       CAMELLIA_FLS(io[0],io[1],io[2],io[3],
-               CamelliaSubkeyL(17),CamelliaSubkeyR(17),
-               CamelliaSubkeyL(16),CamelliaSubkeyR(16),
-               t0,t1,il,ir);
-
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(15),CamelliaSubkeyR(15),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(14),CamelliaSubkeyR(14),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(13),CamelliaSubkeyR(13),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(12),CamelliaSubkeyR(12),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(11),CamelliaSubkeyR(11),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(10),CamelliaSubkeyR(10),
-               io[0],io[1],il,ir,t0,t1);
-
-       CAMELLIA_FLS(io[0],io[1],io[2],io[3],
-               CamelliaSubkeyL(9),CamelliaSubkeyR(9),
-               CamelliaSubkeyL(8),CamelliaSubkeyR(8),
-               t0,t1,il,ir);
-
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(7),CamelliaSubkeyR(7),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(6),CamelliaSubkeyR(6),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(5),CamelliaSubkeyR(5),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(4),CamelliaSubkeyR(4),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(3),CamelliaSubkeyR(3),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(2),CamelliaSubkeyR(2),
-               io[0],io[1],il,ir,t0,t1);
-
-       /* post whitening but kw4 */
-       io[2] ^= CamelliaSubkeyL(0);
-       io[3] ^= CamelliaSubkeyR(0);
-
-       t0 = io[0];
-       t1 = io[1];
-       io[0] = io[2];
-       io[1] = io[3];
-       io[2] = t0;
-       io[3] = t1;
-
-       return;
+       Camellia_EncryptBlock_Rounds(keyBitLength==128?3:4,
+                       plaintext,keyTable,ciphertext);
        }
 
-/**
- * stuff for 192 and 256bit encryption/decryption
- */
-void camellia_encrypt256(const u32 *subkey, u32 *io)
+void Camellia_DecryptBlock_Rounds(int grandRounds, const u8 ciphertext[], 
+               const KEY_TABLE_TYPE keyTable, u8 plaintext[])
        {
-       u32 il,ir,t0,t1;           /* temporary valiables */
-
-       /* pre whitening but absorb kw2*/
-       io[0] ^= CamelliaSubkeyL(0);
-       io[1] ^= CamelliaSubkeyR(0);
-
-       /* main iteration */
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(2),CamelliaSubkeyR(2),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(3),CamelliaSubkeyR(3),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(4),CamelliaSubkeyR(4),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(5),CamelliaSubkeyR(5),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(6),CamelliaSubkeyR(6),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(7),CamelliaSubkeyR(7),
-               io[0],io[1],il,ir,t0,t1);
-
-       CAMELLIA_FLS(io[0],io[1],io[2],io[3],
-               CamelliaSubkeyL(8),CamelliaSubkeyR(8),
-               CamelliaSubkeyL(9),CamelliaSubkeyR(9),
-               t0,t1,il,ir);
-
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(10),CamelliaSubkeyR(10),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(11),CamelliaSubkeyR(11),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(12),CamelliaSubkeyR(12),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(13),CamelliaSubkeyR(13),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(14),CamelliaSubkeyR(14),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(15),CamelliaSubkeyR(15),
-               io[0],io[1],il,ir,t0,t1);
-
-       CAMELLIA_FLS(io[0],io[1],io[2],io[3],
-               CamelliaSubkeyL(16),CamelliaSubkeyR(16),
-               CamelliaSubkeyL(17),CamelliaSubkeyR(17),
-               t0,t1,il,ir);
-
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(18),CamelliaSubkeyR(18),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(19),CamelliaSubkeyR(19),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(20),CamelliaSubkeyR(20),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(21),CamelliaSubkeyR(21),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(22),CamelliaSubkeyR(22),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(23),CamelliaSubkeyR(23),
-               io[0],io[1],il,ir,t0,t1);
-
-       CAMELLIA_FLS(io[0],io[1],io[2],io[3],
-               CamelliaSubkeyL(24),CamelliaSubkeyR(24),
-               CamelliaSubkeyL(25),CamelliaSubkeyR(25),
-               t0,t1,il,ir);
-
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(26),CamelliaSubkeyR(26),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(27),CamelliaSubkeyR(27),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(28),CamelliaSubkeyR(28),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(29),CamelliaSubkeyR(29),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(30),CamelliaSubkeyR(30),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(31),CamelliaSubkeyR(31),
-               io[0],io[1],il,ir,t0,t1);
-
-       /* post whitening but kw4 */
-       io[2] ^= CamelliaSubkeyL(32);
-       io[3] ^= CamelliaSubkeyR(32);
-
-       t0 = io[0];
-       t1 = io[1];
-       io[0] = io[2];
-       io[1] = io[3];
-       io[2] = t0;
-       io[3] = t1;
-
-       return;
+       u32 s0,s1,s2,s3; 
+       const u32 *k = keyTable+grandRounds*16,*kend = keyTable+4; 
+
+       s0 = GETU32(ciphertext)    ^ k[0];
+       s1 = GETU32(ciphertext+4)  ^ k[1];
+       s2 = GETU32(ciphertext+8)  ^ k[2];
+       s3 = GETU32(ciphertext+12) ^ k[3];
+
+       while (1)
+               {
+               /* Camellia makes 6 Feistel rounds */
+               k -= 12;
+               Camellia_Feistel(s0,s1,s2,s3,k+10);
+               Camellia_Feistel(s2,s3,s0,s1,k+8);
+               Camellia_Feistel(s0,s1,s2,s3,k+6);
+               Camellia_Feistel(s2,s3,s0,s1,k+4);
+               Camellia_Feistel(s0,s1,s2,s3,k+2);
+               Camellia_Feistel(s2,s3,s0,s1,k+0);
+
+               if (k == kend) break;
+
+               /* This is the same function as the diffusion function D
+                * of the accompanying documentation. See section 3.2
+                * for properties of the FLlayer function. */
+               k -= 4;
+               s1 ^= LeftRotate(s0 & k[2], 1);
+               s2 ^= s3 | k[1];
+               s0 ^= s1 | k[3];
+               s3 ^= LeftRotate(s2 & k[0], 1);
+               }
+
+       k -= 4;
+       s2 ^= k[0], s3 ^= k[1], s0 ^= k[2], s1 ^= k[3];
+
+       PUTU32(plaintext,   s2);
+       PUTU32(plaintext+4, s3);
+       PUTU32(plaintext+8, s0);
+       PUTU32(plaintext+12,s1);
        }
-
-void camellia_decrypt256(const u32 *subkey, u32 *io)
+void Camellia_DecryptBlock(int keyBitLength, const u8 plaintext[], 
+               const KEY_TABLE_TYPE keyTable, u8 ciphertext[])
        {
-       u32 il,ir,t0,t1;           /* temporary valiables */
-
-       /* pre whitening but absorb kw2*/
-       io[0] ^= CamelliaSubkeyL(32);
-       io[1] ^= CamelliaSubkeyR(32);
-       
-       /* main iteration */
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(31),CamelliaSubkeyR(31),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(30),CamelliaSubkeyR(30),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(29),CamelliaSubkeyR(29),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(28),CamelliaSubkeyR(28),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(27),CamelliaSubkeyR(27),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(26),CamelliaSubkeyR(26),
-               io[0],io[1],il,ir,t0,t1);
-
-       CAMELLIA_FLS(io[0],io[1],io[2],io[3],
-               CamelliaSubkeyL(25),CamelliaSubkeyR(25),
-               CamelliaSubkeyL(24),CamelliaSubkeyR(24),
-               t0,t1,il,ir);
-
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(23),CamelliaSubkeyR(23),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(22),CamelliaSubkeyR(22),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(21),CamelliaSubkeyR(21),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(20),CamelliaSubkeyR(20),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(19),CamelliaSubkeyR(19),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(18),CamelliaSubkeyR(18),
-               io[0],io[1],il,ir,t0,t1);
-
-       CAMELLIA_FLS(io[0],io[1],io[2],io[3],
-               CamelliaSubkeyL(17),CamelliaSubkeyR(17),
-               CamelliaSubkeyL(16),CamelliaSubkeyR(16),
-               t0,t1,il,ir);
-
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(15),CamelliaSubkeyR(15),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(14),CamelliaSubkeyR(14),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(13),CamelliaSubkeyR(13),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(12),CamelliaSubkeyR(12),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(11),CamelliaSubkeyR(11),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(10),CamelliaSubkeyR(10),
-               io[0],io[1],il,ir,t0,t1);
-
-       CAMELLIA_FLS(io[0],io[1],io[2],io[3],
-               CamelliaSubkeyL(9),CamelliaSubkeyR(9),
-               CamelliaSubkeyL(8),CamelliaSubkeyR(8),
-               t0,t1,il,ir);
-
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(7),CamelliaSubkeyR(7),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(6),CamelliaSubkeyR(6),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(5),CamelliaSubkeyR(5),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(4),CamelliaSubkeyR(4),
-               io[0],io[1],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[0],io[1],
-               CamelliaSubkeyL(3),CamelliaSubkeyR(3),
-               io[2],io[3],il,ir,t0,t1);
-       CAMELLIA_ROUNDSM(io[2],io[3],
-               CamelliaSubkeyL(2),CamelliaSubkeyR(2),
-               io[0],io[1],il,ir,t0,t1);
-
-       /* post whitening but kw4 */
-       io[2] ^= CamelliaSubkeyL(0);
-       io[3] ^= CamelliaSubkeyR(0);
-
-       t0 = io[0];
-       t1 = io[1];
-       io[0] = io[2];
-       io[1] = io[3];
-       io[2] = t0;
-       io[3] = t1;
-
-       return;
+       Camellia_DecryptBlock_Rounds(keyBitLength==128?3:4,
+                       plaintext,keyTable,ciphertext);
        }
-
index b8a8b6e..cf0457d 100644 (file)
@@ -58,6 +58,8 @@
 #error CAMELLIA is disabled.
 #endif
 
+#include <stddef.h>
+
 #define CAMELLIA_ENCRYPT       1
 #define CAMELLIA_DECRYPT       0
 
@@ -74,24 +76,18 @@ extern "C" {
 #define CAMELLIA_TABLE_BYTE_LEN 272
 #define CAMELLIA_TABLE_WORD_LEN (CAMELLIA_TABLE_BYTE_LEN / 4)
 
- /* to match with WORD */
-typedef unsigned int KEY_TABLE_TYPE[CAMELLIA_TABLE_WORD_LEN];
+typedef unsigned int KEY_TABLE_TYPE[CAMELLIA_TABLE_WORD_LEN]; /* to match with WORD */
 
 struct camellia_key_st 
        {
-       KEY_TABLE_TYPE rd_key;
-       int bitLength;
-       void (*enc)(const unsigned int *subkey, unsigned int *io);
-       void (*dec)(const unsigned int *subkey, unsigned int *io);
+       union   {
+               double d;       /* ensures 64-bit align */
+               KEY_TABLE_TYPE rd_key;
+               } u;
+       int grand_rounds;
        };
-
 typedef struct camellia_key_st CAMELLIA_KEY;
 
-#ifdef OPENSSL_FIPS
-int private_Camellia_set_key(const unsigned char *userKey, const int bits,
-       CAMELLIA_KEY *key);
-#endif
-
 int Camellia_set_key(const unsigned char *userKey, const int bits,
        CAMELLIA_KEY *key);
 
@@ -103,25 +99,22 @@ void Camellia_decrypt(const unsigned char *in, unsigned char *out,
 void Camellia_ecb_encrypt(const unsigned char *in, unsigned char *out,
        const CAMELLIA_KEY *key, const int enc);
 void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
-       const unsigned long length, const CAMELLIA_KEY *key,
+       size_t length, const CAMELLIA_KEY *key,
        unsigned char *ivec, const int enc);
 void Camellia_cfb128_encrypt(const unsigned char *in, unsigned char *out,
-       const unsigned long length, const CAMELLIA_KEY *key,
+       size_t length, const CAMELLIA_KEY *key,
        unsigned char *ivec, int *num, const int enc);
 void Camellia_cfb1_encrypt(const unsigned char *in, unsigned char *out,
-       const unsigned long length, const CAMELLIA_KEY *key,
+       size_t length, const CAMELLIA_KEY *key,
        unsigned char *ivec, int *num, const int enc);
 void Camellia_cfb8_encrypt(const unsigned char *in, unsigned char *out,
-       const unsigned long length, const CAMELLIA_KEY *key,
+       size_t length, const CAMELLIA_KEY *key,
        unsigned char *ivec, int *num, const int enc);
-void Camellia_cfbr_encrypt_block(const unsigned char *in,unsigned char *out,
-       const int nbits,const CAMELLIA_KEY *key,
-       unsigned char *ivec,const int enc);
 void Camellia_ofb128_encrypt(const unsigned char *in, unsigned char *out,
-       const unsigned long length, const CAMELLIA_KEY *key,
+       size_t length, const CAMELLIA_KEY *key,
        unsigned char *ivec, int *num);
 void Camellia_ctr128_encrypt(const unsigned char *in, unsigned char *out,
-       const unsigned long length, const CAMELLIA_KEY *key,
+       size_t length, const CAMELLIA_KEY *key,
        unsigned char ivec[CAMELLIA_BLOCK_SIZE],
        unsigned char ecount_buf[CAMELLIA_BLOCK_SIZE],
        unsigned int *num);
@@ -131,4 +124,3 @@ void Camellia_ctr128_encrypt(const unsigned char *in, unsigned char *out,
 #endif
 
 #endif /* !HEADER_Camellia_H */
-
index 4141a7b..4c8d455 100644 (file)
  *
  */
 
-#ifndef CAMELLIA_DEBUG
-# ifndef NDEBUG
-#  define NDEBUG
-# endif
-#endif
-#include <assert.h>
-#include <stdio.h>
-#include <string.h>
-
 #include <openssl/camellia.h>
-#include "cmll_locl.h"
+#include <openssl/modes.h>
 
 void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
-                    const unsigned long length, const CAMELLIA_KEY *key,
-                    unsigned char *ivec, const int enc) {
-
-       unsigned long n;
-       unsigned long len = length;
-       const unsigned char *iv = ivec;
-       union { u32 t32[CAMELLIA_BLOCK_SIZE/sizeof(u32)];
-               u8  t8 [CAMELLIA_BLOCK_SIZE]; } tmp;
-       const union { long one; char little; } camellia_endian = {1};
-
-
-       assert(in && out && key && ivec);
-       assert((CAMELLIA_ENCRYPT == enc)||(CAMELLIA_DECRYPT == enc));
+       size_t len, const CAMELLIA_KEY *key,
+       unsigned char *ivec, const int enc) 
+       {
 
-       if(((size_t)in|(size_t)out|(size_t)ivec) % sizeof(u32) == 0)
-               {
-               if (CAMELLIA_ENCRYPT == enc)
-                       {
-                       while (len >= CAMELLIA_BLOCK_SIZE)
-                               {
-                               XOR4WORD2((u32 *)out,
-                                       (u32 *)in, (u32 *)iv);
-                               if (camellia_endian.little)
-                                       SWAP4WORD((u32 *)out);
-                               key->enc(key->rd_key, (u32 *)out);
-                               if (camellia_endian.little)
-                                       SWAP4WORD((u32 *)out);
-                               iv = out;
-                               len -= CAMELLIA_BLOCK_SIZE;
-                               in += CAMELLIA_BLOCK_SIZE;
-                               out += CAMELLIA_BLOCK_SIZE;
-                               }
-                       if (len)
-                               {
-                               for(n=0; n < len; ++n)
-                                       out[n] = in[n] ^ iv[n];
-                               for(n=len; n < CAMELLIA_BLOCK_SIZE; ++n)
-                                       out[n] = iv[n];
-                               if (camellia_endian.little)
-                                       SWAP4WORD((u32 *)out);
-                               key->enc(key->rd_key, (u32 *)out);
-                               if (camellia_endian.little)
-                                       SWAP4WORD((u32 *)out);
-                               iv = out;
-                               }
-                       memcpy(ivec,iv,CAMELLIA_BLOCK_SIZE);
-                       }
-               else if (in != out)
-                       {
-                       while (len >= CAMELLIA_BLOCK_SIZE)
-                               {
-                               memcpy(out,in,CAMELLIA_BLOCK_SIZE);
-                               if (camellia_endian.little)
-                                       SWAP4WORD((u32 *)out);
-                               key->dec(key->rd_key,(u32 *)out);
-                               if (camellia_endian.little)
-                                       SWAP4WORD((u32 *)out);
-                               XOR4WORD((u32 *)out, (u32 *)iv);
-                               iv = in;
-                               len -= CAMELLIA_BLOCK_SIZE;
-                               in  += CAMELLIA_BLOCK_SIZE;
-                               out += CAMELLIA_BLOCK_SIZE;
-                               }
-                       if (len)
-                               {
-                               memcpy(tmp.t8, in, CAMELLIA_BLOCK_SIZE);
-                               if (camellia_endian.little)
-                                       SWAP4WORD(tmp.t32);
-                               key->dec(key->rd_key, tmp.t32);
-                               if (camellia_endian.little)
-                                       SWAP4WORD(tmp.t32);
-                               for(n=0; n < len; ++n)
-                                       out[n] = tmp.t8[n] ^ iv[n];
-                               iv = in;
-                               }
-                       memcpy(ivec,iv,CAMELLIA_BLOCK_SIZE);
-                       }
-               else /* in == out */
-                       {
-                       while (len >= CAMELLIA_BLOCK_SIZE)
-                               {
-                               memcpy(tmp.t8, in, CAMELLIA_BLOCK_SIZE);
-                               if (camellia_endian.little)
-                                       SWAP4WORD((u32 *)out);
-                               key->dec(key->rd_key, (u32 *)out);
-                               if (camellia_endian.little)
-                                       SWAP4WORD((u32 *)out);
-                               XOR4WORD((u32 *)out, (u32 *)ivec);
-                               memcpy(ivec, tmp.t8, CAMELLIA_BLOCK_SIZE);
-                               len -= CAMELLIA_BLOCK_SIZE;
-                               in += CAMELLIA_BLOCK_SIZE;
-                               out += CAMELLIA_BLOCK_SIZE;
-                               }
-                       if (len)
-                               {
-                               memcpy(tmp.t8, in, CAMELLIA_BLOCK_SIZE);
-                               if (camellia_endian.little)
-                                       SWAP4WORD((u32 *)out);
-                               key->dec(key->rd_key,(u32 *)out);
-                               if (camellia_endian.little)
-                                       SWAP4WORD((u32 *)out);
-                               for(n=0; n < len; ++n)
-                                       out[n] ^= ivec[n];
-                               for(n=len; n < CAMELLIA_BLOCK_SIZE; ++n)
-                                       out[n] = tmp.t8[n];
-                               memcpy(ivec, tmp.t8, CAMELLIA_BLOCK_SIZE);
-                               }
-                       }
-               }
-       else /* no aligned */
-               {
-               if (CAMELLIA_ENCRYPT == enc)
-                       {
-                       while (len >= CAMELLIA_BLOCK_SIZE)
-                               {
-                               for(n=0; n < CAMELLIA_BLOCK_SIZE; ++n)
-                                       tmp.t8[n] = in[n] ^ iv[n];
-                               if (camellia_endian.little)
-                                       SWAP4WORD(tmp.t32);
-                               key->enc(key->rd_key, tmp.t32);
-                               if (camellia_endian.little)
-                                       SWAP4WORD(tmp.t32);
-                               memcpy(out, tmp.t8, CAMELLIA_BLOCK_SIZE);
-                               iv = out;
-                               len -= CAMELLIA_BLOCK_SIZE;
-                               in += CAMELLIA_BLOCK_SIZE;
-                               out += CAMELLIA_BLOCK_SIZE;
-                               }
-                       if (len)
-                               {
-                               for(n=0; n < len; ++n)
-                                       tmp.t8[n] = in[n] ^ iv[n];
-                               for(n=len; n < CAMELLIA_BLOCK_SIZE; ++n)
-                                       tmp.t8[n] = iv[n];
-                               if (camellia_endian.little)
-                                       SWAP4WORD(tmp.t32);
-                               key->enc(key->rd_key, tmp.t32);
-                               if (camellia_endian.little)
-                                       SWAP4WORD(tmp.t32);
-                               memcpy(out, tmp.t8, CAMELLIA_BLOCK_SIZE);
-                               iv = out;
-                               }
-                       memcpy(ivec,iv,CAMELLIA_BLOCK_SIZE);
-                       }
-               else if (in != out)
-                       {
-                       while (len >= CAMELLIA_BLOCK_SIZE)
-                               {
-                               memcpy(tmp.t8,in,CAMELLIA_BLOCK_SIZE);
-                               if (camellia_endian.little)
-                                       SWAP4WORD(tmp.t32);
-                               key->dec(key->rd_key,tmp.t32);
-                               if (camellia_endian.little)
-                                       SWAP4WORD(tmp.t32);
-                               for(n=0; n < CAMELLIA_BLOCK_SIZE; ++n)
-                                       out[n] = tmp.t8[n] ^ iv[n];
-                               iv = in;
-                               len -= CAMELLIA_BLOCK_SIZE;
-                               in  += CAMELLIA_BLOCK_SIZE;
-                               out += CAMELLIA_BLOCK_SIZE;
-                               }
-                       if (len)
-                               {
-                               memcpy(tmp.t8, in, CAMELLIA_BLOCK_SIZE);
-                               if (camellia_endian.little)
-                                       SWAP4WORD(tmp.t32);
-                               key->dec(key->rd_key, tmp.t32);
-                               if (camellia_endian.little)
-                                       SWAP4WORD(tmp.t32);
-                               for(n=0; n < len; ++n)
-                                       out[n] = tmp.t8[n] ^ iv[n];
-                               iv = in;
-                               }
-                       memcpy(ivec,iv,CAMELLIA_BLOCK_SIZE);
-                       }
-               else
-                       {
-                       while (len >= CAMELLIA_BLOCK_SIZE)
-                               {
-                               memcpy(tmp.t8, in, CAMELLIA_BLOCK_SIZE);
-                               if (camellia_endian.little)
-                                       SWAP4WORD(tmp.t32);
-                               key->dec(key->rd_key, tmp.t32);
-                               if (camellia_endian.little)
-                                       SWAP4WORD(tmp.t32);
-                               for(n=0; n < CAMELLIA_BLOCK_SIZE; ++n)
-                                       tmp.t8[n] ^= ivec[n];
-                               memcpy(ivec, in, CAMELLIA_BLOCK_SIZE);
-                               memcpy(out, tmp.t8, CAMELLIA_BLOCK_SIZE);
-                               len -= CAMELLIA_BLOCK_SIZE;
-                               in += CAMELLIA_BLOCK_SIZE;
-                               out += CAMELLIA_BLOCK_SIZE;
-                               }
-                       if (len)
-                               {
-                               memcpy(tmp.t8, in, CAMELLIA_BLOCK_SIZE);
-                               if (camellia_endian.little)
-                                       SWAP4WORD(tmp.t32);
-                               key->dec(key->rd_key,tmp.t32);
-                               if (camellia_endian.little)
-                                       SWAP4WORD(tmp.t32);
-                               for(n=0; n < len; ++n)
-                                       tmp.t8[n] ^= ivec[n];
-                               memcpy(ivec, in, CAMELLIA_BLOCK_SIZE);
-                               memcpy(out,tmp.t8,len);
-                               }
-                       }
-               }
-}
+       if (enc)
+               CRYPTO_cbc128_encrypt(in,out,len,key,ivec,(block128_f)Camellia_encrypt);
+       else
+               CRYPTO_cbc128_decrypt(in,out,len,key,ivec,(block128_f)Camellia_decrypt);
+       }
index af0f9f4..3d81b51 100644 (file)
  * [including the GNU Public Licence.]
  */
 
-#ifndef CAMELLIA_DEBUG
-# ifndef NDEBUG
-#  define NDEBUG
-# endif
-#endif
-#include <assert.h>
-#include <string.h>
-
 #include <openssl/camellia.h>
-#include "cmll_locl.h"
-#include "e_os.h"
+#include <openssl/modes.h>
 
 
 /* The input and output encrypted as though 128bit cfb mode is being
  */
 
 void Camellia_cfb128_encrypt(const unsigned char *in, unsigned char *out,
-       const unsigned long length, const CAMELLIA_KEY *key,
+       size_t length, const CAMELLIA_KEY *key,
        unsigned char *ivec, int *num, const int enc)
        {
 
-       unsigned int n;
-       unsigned long l = length;
-       unsigned char c;
-
-       assert(in && out && key && ivec && num);
-
-       n = *num;
-
-       if (enc) 
-               {
-               while (l--) 
-                       {
-                       if (n == 0) 
-                               {
-                               Camellia_encrypt(ivec, ivec, key);
-                               }
-                       ivec[n] = *(out++) = *(in++) ^ ivec[n];
-                       n = (n+1) % CAMELLIA_BLOCK_SIZE;
-                       }
-               } 
-       else 
-               {
-               while (l--) 
-                       {
-                       if (n == 0) 
-                               {
-                               Camellia_encrypt(ivec, ivec, key);
-                               }
-                       c = *(in);
-                       *(out++) = *(in++) ^ ivec[n];
-                       ivec[n] = c;
-                       n = (n+1) % CAMELLIA_BLOCK_SIZE;
-                       }
-               }
-
-       *num=n;
-       }
-
-/* This expects a single block of size nbits for both in and out. Note that
-   it corrupts any extra bits in the last byte of out */
-void Camellia_cfbr_encrypt_block(const unsigned char *in,unsigned char *out,
-       const int nbits,const CAMELLIA_KEY *key,
-       unsigned char *ivec,const int enc)
-       {
-       int n,rem,num;
-       unsigned char ovec[CAMELLIA_BLOCK_SIZE*2];
-
-       if (nbits<=0 || nbits>128) return;
-
-       /* fill in the first half of the new IV with the current IV */
-       memcpy(ovec,ivec,CAMELLIA_BLOCK_SIZE);
-       /* construct the new IV */
-       Camellia_encrypt(ivec,ivec,key);
-       num = (nbits+7)/8;
-       if (enc)        /* encrypt the input */
-               for(n=0 ; n < num ; ++n)
-                       out[n] = (ovec[CAMELLIA_BLOCK_SIZE+n] = in[n] ^ ivec[n]);
-       else            /* decrypt the input */
-               for(n=0 ; n < num ; ++n)
-                       out[n] = (ovec[CAMELLIA_BLOCK_SIZE+n] = in[n]) ^ ivec[n];
-       /* shift ovec left... */
-       rem = nbits%8;
-       num = nbits/8;
-       if(rem==0)
-               memcpy(ivec,ovec+num,CAMELLIA_BLOCK_SIZE);
-       else
-               for(n=0 ; n < CAMELLIA_BLOCK_SIZE ; ++n)
-                       ivec[n] = ovec[n+num]<<rem | ovec[n+num+1]>>(8-rem);
-
-       /* it is not necessary to cleanse ovec, since the IV is not secret */
+       CRYPTO_cfb128_encrypt(in,out,length,key,ivec,num,enc,(block128_f)Camellia_encrypt);
        }
 
 /* N.B. This expects the input to be packed, MS bit first */
 void Camellia_cfb1_encrypt(const unsigned char *in, unsigned char *out,
-       const unsigned long length, const CAMELLIA_KEY *key,
+       size_t length, const CAMELLIA_KEY *key,
        unsigned char *ivec, int *num, const int enc)
        {
-       unsigned int n;
-       unsigned char c[1],d[1];
-
-       assert(in && out && key && ivec && num);
-       assert(*num == 0);
-
-       memset(out,0,(length+7)/8);
-       for(n=0 ; n < length ; ++n)
-               {
-               c[0]=(in[n/8]&(1 << (7-n%8))) ? 0x80 : 0;
-               Camellia_cfbr_encrypt_block(c,d,1,key,ivec,enc);
-               out[n/8]=(out[n/8]&~(1 << (7-n%8)))|((d[0]&0x80) >> (n%8));
-               }
+       CRYPTO_cfb128_1_encrypt(in,out,length,key,ivec,num,enc,(block128_f)Camellia_encrypt);
        }
 
 void Camellia_cfb8_encrypt(const unsigned char *in, unsigned char *out,
-       const unsigned long length, const CAMELLIA_KEY *key,
+       size_t length, const CAMELLIA_KEY *key,
        unsigned char *ivec, int *num, const int enc)
        {
-       unsigned int n;
-
-       assert(in && out && key && ivec && num);
-       assert(*num == 0);
-
-       for(n=0 ; n < length ; ++n)
-               Camellia_cfbr_encrypt_block(&in[n],&out[n],8,key,ivec,enc);
+       CRYPTO_cfb128_8_encrypt(in,out,length,key,ivec,num,enc,(block128_f)Camellia_encrypt);
        }
 
index cc21b70..014e621 100644 (file)
  *
  */
 
-#ifndef CAMELLIA_DEBUG
-# ifndef NDEBUG
-#  define NDEBUG
-# endif
-#endif
-#include <assert.h>
-
 #include <openssl/camellia.h>
-#include "cmll_locl.h"
-
-/* NOTE: the IV/counter CTR mode is big-endian.  The rest of the Camellia code
- * is endian-neutral. */
-/* increment counter (128-bit int) by 1 */
-static void Camellia_ctr128_inc(unsigned char *counter) 
-       {
-       unsigned long c;
-
-       /* Grab bottom dword of counter and increment */
-       c = GETU32(counter + 12);
-       c++;    c &= 0xFFFFFFFF;
-       PUTU32(counter + 12, c);
-
-       /* if no overflow, we're done */
-       if (c)
-               return;
-
-       /* Grab 1st dword of counter and increment */
-       c = GETU32(counter +  8);
-       c++;    c &= 0xFFFFFFFF;
-       PUTU32(counter +  8, c);
-
-       /* if no overflow, we're done */
-       if (c)
-               return;
-
-       /* Grab 2nd dword of counter and increment */
-       c = GETU32(counter +  4);
-       c++;    c &= 0xFFFFFFFF;
-       PUTU32(counter +  4, c);
-
-       /* if no overflow, we're done */
-       if (c)
-               return;
+#include <openssl/modes.h>
 
-       /* Grab top dword of counter and increment */
-       c = GETU32(counter +  0);
-       c++;    c &= 0xFFFFFFFF;
-       PUTU32(counter +  0, c);
-       }
-
-/* The input encrypted as though 128bit counter mode is being
- * used.  The extra state information to record how much of the
- * 128bit block we have used is contained in *num, and the
- * encrypted counter is kept in ecount_buf.  Both *num and
- * ecount_buf must be initialised with zeros before the first
- * call to Camellia_ctr128_encrypt().
- *
- * This algorithm assumes that the counter is in the x lower bits
- * of the IV (ivec), and that the application has full control over
- * overflow and the rest of the IV.  This implementation takes NO
- * responsability for checking that the counter doesn't overflow
- * into the rest of the IV when incremented.
- */
 void Camellia_ctr128_encrypt(const unsigned char *in, unsigned char *out,
-       const unsigned long length, const CAMELLIA_KEY *key,
+       size_t length, const CAMELLIA_KEY *key,
        unsigned char ivec[CAMELLIA_BLOCK_SIZE],
        unsigned char ecount_buf[CAMELLIA_BLOCK_SIZE],
        unsigned int *num) 
        {
 
-       unsigned int n;
-       unsigned long l=length;
-
-       assert(in && out && key && counter && num);
-       assert(*num < CAMELLIA_BLOCK_SIZE);
-
-       n = *num;
-
-       while (l--) 
-               {
-               if (n == 0) 
-                       {
-                       Camellia_encrypt(ivec, ecount_buf, key);
-                       Camellia_ctr128_inc(ivec);
-                       }
-               *(out++) = *(in++) ^ ecount_buf[n];
-               n = (n+1) % CAMELLIA_BLOCK_SIZE;
-               }
-
-       *num=n;
+       CRYPTO_ctr128_encrypt(in,out,length,key,ivec,ecount_buf,num,(block128_f)Camellia_encrypt);
        }
 
index 2ac2e95..4a4d880 100644 (file)
 #ifndef HEADER_CAMELLIA_LOCL_H
 #define HEADER_CAMELLIA_LOCL_H
 
-#include "openssl/e_os2.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
+typedef unsigned int  u32;
 typedef unsigned char u8;
-typedef unsigned int u32;
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64))
-# define SWAP(x) ( _lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00 )
-# define GETU32(p) SWAP(*((u32 *)(p)))
-# define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); }
-# define CAMELLIA_SWAP4(x) (x = ( _lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00) )
-
-#else /* not windows */
-# define GETU32(pt) (((u32)(pt)[0] << 24) \
-       ^ ((u32)(pt)[1] << 16) \
-       ^ ((u32)(pt)[2] <<  8) \
-       ^ ((u32)(pt)[3]))
-
-# define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); \
-       (ct)[1] = (u8)((st) >> 16); \
-       (ct)[2] = (u8)((st) >>  8); \
-       (ct)[3] = (u8)(st); }
-
-#if (defined (__GNUC__) && (defined(__x86_64__) || defined(__x86_64)))
-#define CAMELLIA_SWAP4(x) \
-  do{\
-    asm("bswap %1" : "+r" (x));\
-  }while(0)
-#else
-#define CAMELLIA_SWAP4(x) \
-   do{\
-     x = ((u32)x << 16) + ((u32)x >> 16);\
-     x = (((u32)x & 0xff00ff) << 8) + (((u32)x >> 8) & 0xff00ff);\
-   } while(0)
-#endif
-#endif
-
-#define COPY4WORD(dst, src)     \
-            do                  \
-                    {           \
-                    (dst)[0]=(src)[0];         \
-                    (dst)[1]=(src)[1];         \
-                    (dst)[2]=(src)[2];         \
-                    (dst)[3]=(src)[3];         \
-                    }while(0)
-
-#define SWAP4WORD(word)                                \
-   do                                          \
-          {                                    \
-          CAMELLIA_SWAP4((word)[0]);                   \
-          CAMELLIA_SWAP4((word)[1]);                   \
-          CAMELLIA_SWAP4((word)[2]);                   \
-          CAMELLIA_SWAP4((word)[3]);                   \
-          }while(0)
-
-#define XOR4WORD(a, b)/* a = a ^ b */          \
-   do                                          \
-       {                                       \
-       (a)[0]^=(b)[0];                         \
-       (a)[1]^=(b)[1];                         \
-       (a)[2]^=(b)[2];                         \
-       (a)[3]^=(b)[3];                         \
-       }while(0)
-
-#define XOR4WORD2(a, b, c)/* a = b ^ c */      \
-   do                                          \
-       {                                       \
-       (a)[0]=(b)[0]^(c)[0];                   \
-       (a)[1]=(b)[1]^(c)[1];                           \
-       (a)[2]=(b)[2]^(c)[2];                           \
-       (a)[3]=(b)[3]^(c)[3];                           \
-       }while(0)
-
-
-void camellia_setup128(const u8 *key, u32 *subkey);
-void camellia_setup192(const u8 *key, u32 *subkey);
-void camellia_setup256(const u8 *key, u32 *subkey);
-
-void camellia_encrypt128(const u32 *subkey, u32 *io);
-void camellia_decrypt128(const u32 *subkey, u32 *io);
-void camellia_encrypt256(const u32 *subkey, u32 *io);
-void camellia_decrypt256(const u32 *subkey, u32 *io);
-
-#ifdef __cplusplus
-}
-#endif
 
+int Camellia_Ekeygen(int keyBitLength, const u8 *rawKey, KEY_TABLE_TYPE keyTable);
+void Camellia_EncryptBlock_Rounds(int grandRounds, const u8 plaintext[], 
+               const KEY_TABLE_TYPE keyTable, u8 ciphertext[]);
+void Camellia_DecryptBlock_Rounds(int grandRounds, const u8 ciphertext[], 
+               const KEY_TABLE_TYPE keyTable, u8 plaintext[]);
+void Camellia_EncryptBlock(int keyBitLength, const u8 plaintext[], 
+               const KEY_TABLE_TYPE keyTable, u8 ciphertext[]);
+void Camellia_DecryptBlock(int keyBitLength, const u8 ciphertext[], 
+               const KEY_TABLE_TYPE keyTable, u8 plaintext[]);
 #endif /* #ifndef HEADER_CAMELLIA_LOCL_H */
-
index 2cd7aba..f446891 100644 (file)
 #include <openssl/opensslv.h>
 #include <openssl/camellia.h>
 #include "cmll_locl.h"
-#include <openssl/crypto.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
 
 const char CAMELLIA_version[]="CAMELLIA" OPENSSL_VERSION_PTEXT;
 
 int Camellia_set_key(const unsigned char *userKey, const int bits,
        CAMELLIA_KEY *key)
-#ifdef OPENSSL_FIPS
        {
-       if (FIPS_mode())
-               FIPS_BAD_ABORT(CAMELLIA)
-       return private_Camellia_set_key(userKey, bits, key);
-       }
-int private_Camellia_set_key(const unsigned char *userKey, const int bits,
-       CAMELLIA_KEY *key)
-#endif
-       {
-       if (!userKey || !key)
-               {
+       if(!userKey || !key)
                return -1;
-               }
-       
-       switch(bits)
-               {
-       case 128:
-               camellia_setup128(userKey, (unsigned int *)key->rd_key);
-               key->enc = camellia_encrypt128;
-               key->dec = camellia_decrypt128;
-               break;
-       case 192:
-               camellia_setup192(userKey, (unsigned int *)key->rd_key);
-               key->enc = camellia_encrypt256;
-               key->dec = camellia_decrypt256;
-               break;
-       case 256:
-               camellia_setup256(userKey, (unsigned int *)key->rd_key);
-               key->enc = camellia_encrypt256;
-               key->dec = camellia_decrypt256;
-               break;
-       default:
+       if(bits != 128 && bits != 192 && bits != 256)
                return -2;
-               }
-       
-       key->bitLength = bits;
+       key->grand_rounds = Camellia_Ekeygen(bits , userKey, key->u.rd_key);
        return 0;
        }
 
 void Camellia_encrypt(const unsigned char *in, unsigned char *out,
        const CAMELLIA_KEY *key)
        {
-       u32 tmp[CAMELLIA_BLOCK_SIZE/sizeof(u32)];
-       const union { long one; char little; } camellia_endian = {1};
-
-       memcpy(tmp, in, CAMELLIA_BLOCK_SIZE);
-       if (camellia_endian.little) SWAP4WORD(tmp);
-       key->enc(key->rd_key, tmp);
-       if (camellia_endian.little) SWAP4WORD(tmp);
-       memcpy(out, tmp, CAMELLIA_BLOCK_SIZE);
+       Camellia_EncryptBlock_Rounds(key->grand_rounds, in , key->u.rd_key , out);
        }
 
 void Camellia_decrypt(const unsigned char *in, unsigned char *out,
        const CAMELLIA_KEY *key)
        {
-       u32 tmp[CAMELLIA_BLOCK_SIZE/sizeof(u32)];
-       const union { long one; char little; } camellia_endian = {1};
-
-       memcpy(tmp, in, CAMELLIA_BLOCK_SIZE);
-       if (camellia_endian.little) SWAP4WORD(tmp);
-       key->dec(key->rd_key, tmp);
-       if (camellia_endian.little) SWAP4WORD(tmp);
-       memcpy(out, tmp, CAMELLIA_BLOCK_SIZE);
+       Camellia_DecryptBlock_Rounds(key->grand_rounds, in , key->u.rd_key , out);
        }
-
index d89cf9f..a482bef 100644 (file)
  * [including the GNU Public Licence.]
  */
 
-#ifndef CAMELLIA_DEBUG
-# ifndef NDEBUG
-#  define NDEBUG
-# endif
-#endif
-#include <assert.h>
 #include <openssl/camellia.h>
-#include "cmll_locl.h"
+#include <openssl/modes.h>
 
 /* The input and output encrypted as though 128bit ofb mode is being
  * used.  The extra state information to record how much of the
  * 128bit block we have used is contained in *num;
  */
 void Camellia_ofb128_encrypt(const unsigned char *in, unsigned char *out,
-       const unsigned long length, const CAMELLIA_KEY *key,
+       size_t length, const CAMELLIA_KEY *key,
        unsigned char *ivec, int *num) {
-
-       unsigned int n;
-       unsigned long l=length;
-
-       assert(in && out && key && ivec && num);
-
-       n = *num;
-
-       while (l--) {
-               if (n == 0) {
-                       Camellia_encrypt(ivec, ivec, key);
-               }
-               *(out++) = *(in++) ^ ivec[n];
-               n = (n+1) % CAMELLIA_BLOCK_SIZE;
-       }
-
-       *num=n;
+       CRYPTO_ofb128_encrypt(in,out,length,key,ivec,num,(block128_f)Camellia_encrypt);
 }
index 2e026db..0acc38f 100644 (file)
@@ -38,19 +38,12 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
-# ELF
-cx86-elf.s: asm/cast-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
-       (cd asm; $(PERL) cast-586.pl elf $(CLAGS) $(PROCESSOR) > ../$@)
-# COFF
-cx86-cof.s: asm/cast-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
-       (cd asm; $(PERL) cast-586.pl coff $(CLAGS) $(PROCESSOR) > ../$@)
-# a.out
-cx86-out.s: asm/cast-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
-       (cd asm; $(PERL) cast-586.pl a.out $(CLAGS) $(PROCESSOR) > ../$@)
+cast-586.s:    asm/cast-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
+       $(PERL) asm/cast-586.pl $(PERLASM_SCHEME) $(CLAGS) $(PROCESSOR) > $@
 
 files:
        $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
@@ -102,8 +95,5 @@ c_ofb64.o: ../../e_os.h ../../include/openssl/cast.h
 c_ofb64.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
 c_ofb64.o: c_ofb64.c cast_lcl.h
 c_skey.o: ../../e_os.h ../../include/openssl/cast.h
-c_skey.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
-c_skey.o: ../../include/openssl/fips.h ../../include/openssl/opensslconf.h
-c_skey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-c_skey.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-c_skey.o: ../../include/openssl/symhacks.h c_skey.c cast_lcl.h cast_s.h
+c_skey.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
+c_skey.o: c_skey.c cast_lcl.h cast_s.h
index 6be0bfe..bf6810d 100644 (file)
@@ -3,7 +3,8 @@
 # define for pentium pro friendly version
 $ppro=1;
 
-push(@INC,"perlasm","../../perlasm");
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+push(@INC,"${dir}","${dir}../../perlasm");
 require "x86asm.pl";
 require "cbc.pl";
 
index 68e690a..76e4000 100644 (file)
  */
 
 #include <openssl/cast.h>
-#include <openssl/crypto.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
 #include "cast_lcl.h"
 #include "cast_s.h"
 
@@ -77,7 +72,7 @@
 #define S6 CAST_S_table6
 #define S7 CAST_S_table7
 
-FIPS_NON_FIPS_VCIPHER_Init(CAST)
+void CAST_set_key(CAST_KEY *key, int len, const unsigned char *data)
        {
        CAST_LONG x[16];
        CAST_LONG z[16];
index 6e0cd31..1a264f8 100644 (file)
@@ -72,7 +72,7 @@ extern "C" {
 #define CAST_ENCRYPT   1
 #define CAST_DECRYPT   0
 
-#define CAST_LONG unsigned long
+#define CAST_LONG unsigned int
 
 #define CAST_BLOCK     8
 #define CAST_KEY_LENGTH        16
@@ -83,9 +83,7 @@ typedef struct cast_key_st
        int short_key;  /* Use reduced rounds for short key */
        } CAST_KEY;
 
-#ifdef OPENSSL_FIPS 
-void private_CAST_set_key(CAST_KEY *key, int len, const unsigned char *data);
-#endif
 void CAST_set_key(CAST_KEY *key, int len, const unsigned char *data);
 void CAST_ecb_encrypt(const unsigned char *in, unsigned char *out, const CAST_KEY *key,
                      int enc);
index 1c137e0..5837049 100644 (file)
@@ -37,7 +37,7 @@ test:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -108,6 +108,71 @@ cms_att.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
 cms_att.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
 cms_att.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
 cms_att.o: cms.h cms_att.c cms_lcl.h
+cms_cd.o: ../../e_os.h ../../include/openssl/asn1.h
+cms_cd.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
+cms_cd.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h
+cms_cd.o: ../../include/openssl/comp.h ../../include/openssl/conf.h
+cms_cd.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+cms_cd.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+cms_cd.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
+cms_cd.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+cms_cd.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+cms_cd.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+cms_cd.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
+cms_cd.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
+cms_cd.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+cms_cd.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+cms_cd.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+cms_cd.o: ../../include/openssl/x509v3.h ../cryptlib.h cms_cd.c cms_lcl.h
+cms_dd.o: ../../e_os.h ../../include/openssl/asn1.h
+cms_dd.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
+cms_dd.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h
+cms_dd.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
+cms_dd.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+cms_dd.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
+cms_dd.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+cms_dd.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+cms_dd.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+cms_dd.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+cms_dd.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
+cms_dd.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+cms_dd.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+cms_dd.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+cms_dd.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+cms_dd.o: ../cryptlib.h cms_dd.c cms_lcl.h
+cms_enc.o: ../../e_os.h ../../include/openssl/asn1.h
+cms_enc.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
+cms_enc.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h
+cms_enc.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
+cms_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+cms_enc.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
+cms_enc.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+cms_enc.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+cms_enc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+cms_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+cms_enc.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
+cms_enc.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
+cms_enc.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+cms_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+cms_enc.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+cms_enc.o: ../../include/openssl/x509v3.h ../cryptlib.h cms_enc.c cms_lcl.h
+cms_env.o: ../../e_os.h ../../include/openssl/aes.h
+cms_env.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
+cms_env.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
+cms_env.o: ../../include/openssl/cms.h ../../include/openssl/conf.h
+cms_env.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+cms_env.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+cms_env.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
+cms_env.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+cms_env.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+cms_env.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+cms_env.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
+cms_env.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
+cms_env.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
+cms_env.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+cms_env.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+cms_env.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+cms_env.o: ../asn1/asn1_locl.h ../cryptlib.h cms_env.c cms_lcl.h
 cms_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
 cms_err.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h
 cms_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
@@ -121,6 +186,22 @@ cms_err.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
 cms_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
 cms_err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
 cms_err.o: cms_err.c
+cms_ess.o: ../../e_os.h ../../include/openssl/asn1.h
+cms_ess.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
+cms_ess.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h
+cms_ess.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
+cms_ess.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+cms_ess.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
+cms_ess.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+cms_ess.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+cms_ess.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+cms_ess.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+cms_ess.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
+cms_ess.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
+cms_ess.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+cms_ess.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+cms_ess.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+cms_ess.o: ../../include/openssl/x509v3.h ../cryptlib.h cms_ess.c cms_lcl.h
 cms_io.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
 cms_io.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 cms_io.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
@@ -164,7 +245,7 @@ cms_sd.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 cms_sd.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
 cms_sd.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
 cms_sd.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
-cms_sd.o: ../cryptlib.h cms_lcl.h cms_sd.c
+cms_sd.o: ../asn1/asn1_locl.h ../cryptlib.h cms_lcl.h cms_sd.c
 cms_smime.o: ../../e_os.h ../../include/openssl/asn1.h
 cms_smime.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 cms_smime.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h
index 25f8874..09c45d0 100644 (file)
@@ -76,8 +76,9 @@ typedef struct CMS_Receipt_st CMS_Receipt;
 
 DECLARE_STACK_OF(CMS_SignerInfo)
 DECLARE_STACK_OF(GENERAL_NAMES)
-DECLARE_ASN1_FUNCTIONS_const(CMS_ContentInfo)
-DECLARE_ASN1_FUNCTIONS_const(CMS_ReceiptRequest)
+DECLARE_ASN1_FUNCTIONS(CMS_ContentInfo)
+DECLARE_ASN1_FUNCTIONS(CMS_ReceiptRequest)
+DECLARE_ASN1_PRINT_FUNCTION(CMS_ContentInfo)
 
 #define CMS_SIGNERINFO_ISSUER_SERIAL   0
 #define CMS_SIGNERINFO_KEYIDENTIFIER   1
@@ -124,9 +125,13 @@ int CMS_set_detached(CMS_ContentInfo *cms, int detached);
 DECLARE_PEM_rw_const(CMS, CMS_ContentInfo)
 #endif
 
+int CMS_stream(unsigned char ***boundary, CMS_ContentInfo *cms);
 CMS_ContentInfo *d2i_CMS_bio(BIO *bp, CMS_ContentInfo **cms);
 int i2d_CMS_bio(BIO *bp, CMS_ContentInfo *cms);
 
+BIO *BIO_new_CMS(BIO *out, CMS_ContentInfo *cms);
+int i2d_CMS_bio_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags);
+int PEM_write_bio_CMS_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags);
 CMS_ContentInfo *SMIME_read_CMS(BIO *bio, BIO **bcont);
 int SMIME_write_CMS(BIO *bio, CMS_ContentInfo *cms, BIO *data, int flags);
 
@@ -230,6 +235,7 @@ STACK_OF(X509) *CMS_get1_certs(CMS_ContentInfo *cms);
 
 CMS_RevocationInfoChoice *CMS_add0_RevocationInfoChoice(CMS_ContentInfo *cms);
 int CMS_add0_crl(CMS_ContentInfo *cms, X509_CRL *crl);
+int CMS_add1_crl(CMS_ContentInfo *cms, X509_CRL *crl);
 STACK_OF(X509_CRL) *CMS_get1_crls(CMS_ContentInfo *cms);
 
 int CMS_SignedData_init(CMS_ContentInfo *cms);
index b253d54..fcba4dc 100644 (file)
@@ -87,7 +87,8 @@ ASN1_NDEF_SEQUENCE(CMS_EncapsulatedContentInfo) = {
 } ASN1_NDEF_SEQUENCE_END(CMS_EncapsulatedContentInfo)
 
 /* Minor tweak to operation: free up signer key, cert */
-static int cms_si_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
+static int cms_si_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
+                                                       void *exarg)
        {
        if(operation == ASN1_OP_FREE_POST)
                {
@@ -213,7 +214,8 @@ ASN1_SEQUENCE(CMS_OtherRecipientInfo) = {
 } ASN1_SEQUENCE_END(CMS_OtherRecipientInfo)
 
 /* Free up RecipientInfo additional data */
-static int cms_ri_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
+static int cms_ri_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
+                                                       void *exarg)
        {
        if(operation == ASN1_OP_FREE_PRE)
                {
@@ -300,10 +302,42 @@ ASN1_ADB(CMS_ContentInfo) = {
        ADB_ENTRY(NID_id_smime_ct_compressedData, ASN1_NDEF_EXP(CMS_ContentInfo, d.compressedData, CMS_CompressedData, 0)),
 } ASN1_ADB_END(CMS_ContentInfo, 0, contentType, 0, &cms_default_tt, NULL);
 
-ASN1_NDEF_SEQUENCE(CMS_ContentInfo) = {
+/* CMS streaming support */
+static int cms_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
+                                                       void *exarg)
+       {
+       ASN1_STREAM_ARG *sarg = exarg;
+       CMS_ContentInfo *cms = NULL;
+       if (pval)
+               cms = (CMS_ContentInfo *)*pval;
+       else
+               return 1;
+       switch(operation)
+               {
+
+               case ASN1_OP_STREAM_PRE:
+               if (CMS_stream(&sarg->boundary, cms) <= 0)
+                       return 0;
+               case ASN1_OP_DETACHED_PRE:
+               sarg->ndef_bio = CMS_dataInit(cms, sarg->out);
+               if (!sarg->ndef_bio)
+                       return 0;
+               break;
+
+               case ASN1_OP_STREAM_POST:
+               case ASN1_OP_DETACHED_POST:
+               if (CMS_dataFinal(cms, sarg->ndef_bio) <= 0)
+                       return 0;
+               break;
+
+               }
+       return 1;
+       }
+
+ASN1_NDEF_SEQUENCE_cb(CMS_ContentInfo, cms_cb) = {
        ASN1_SIMPLE(CMS_ContentInfo, contentType, ASN1_OBJECT),
        ASN1_ADB_OBJECT(CMS_ContentInfo)
-} ASN1_NDEF_SEQUENCE_END(CMS_ContentInfo)
+} ASN1_NDEF_SEQUENCE_END_cb(CMS_ContentInfo, CMS_ContentInfo)
 
 /* Specials for signed attributes */
 
index d499ae8..b3237d4 100644 (file)
@@ -60,6 +60,7 @@
 #include <openssl/rand.h>
 #include <openssl/aes.h>
 #include "cms_lcl.h"
+#include "asn1_locl.h"
 
 /* CMS EnvelopedData Utilities */
 
@@ -151,7 +152,7 @@ CMS_RecipientInfo *CMS_add1_recipient_cert(CMS_ContentInfo *cms,
        CMS_KeyTransRecipientInfo *ktri;
        CMS_EnvelopedData *env;
        EVP_PKEY *pk = NULL;
-       int type;
+       int i, type;
        env = cms_get0_enveloped(cms);
        if (!env)
                goto err;
@@ -200,21 +201,22 @@ CMS_RecipientInfo *CMS_add1_recipient_cert(CMS_ContentInfo *cms,
        if (!cms_set1_SignerIdentifier(ktri->rid, recip, type))
                goto err;
 
-       /* Since we have no EVP_PKEY_ASN1_METHOD in OpenSSL 0.9.8,
-        * hard code algorithm parameters.
-        */
-
-       if (pk->type == EVP_PKEY_RSA)
-               {
-               X509_ALGOR_set0(ktri->keyEncryptionAlgorithm,
-                                       OBJ_nid2obj(NID_rsaEncryption), 
-                                       V_ASN1_NULL, 0);
-               }
-       else
+       if (pk->ameth && pk->ameth->pkey_ctrl)
                {
-               CMSerr(CMS_F_CMS_ADD1_RECIPIENT_CERT,
+               i = pk->ameth->pkey_ctrl(pk, ASN1_PKEY_CTRL_CMS_ENVELOPE,
+                                               0, ri);
+               if (i == -2)
+                       {
+                       CMSerr(CMS_F_CMS_ADD1_RECIPIENT_CERT,
                                CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);
-               goto err;
+                       goto err;
+                       }
+               if (i <= 0)
+                       {
+                       CMSerr(CMS_F_CMS_ADD1_RECIPIENT_CERT,
+                               CMS_R_CTRL_FAILURE);
+                       goto err;
+                       }
                }
 
        if (!sk_CMS_RecipientInfo_push(env->recipientInfos, ri))
@@ -301,8 +303,9 @@ static int cms_RecipientInfo_ktri_encrypt(CMS_ContentInfo *cms,
        {
        CMS_KeyTransRecipientInfo *ktri;
        CMS_EncryptedContentInfo *ec;
+       EVP_PKEY_CTX *pctx = NULL;
        unsigned char *ek = NULL;
-       int eklen;
+       size_t eklen;
 
        int ret = 0;
 
@@ -315,7 +318,22 @@ static int cms_RecipientInfo_ktri_encrypt(CMS_ContentInfo *cms,
        ktri = ri->d.ktri;
        ec = cms->d.envelopedData->encryptedContentInfo;
 
-       eklen = EVP_PKEY_size(ktri->pkey);
+       pctx = EVP_PKEY_CTX_new(ktri->pkey, NULL);
+       if (!pctx)
+               return 0;
+
+       if (EVP_PKEY_encrypt_init(pctx) <= 0)
+               goto err;
+
+       if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_ENCRYPT,
+                               EVP_PKEY_CTRL_CMS_ENCRYPT, 0, ri) <= 0)
+               {
+               CMSerr(CMS_F_CMS_RECIPIENTINFO_KTRI_ENCRYPT, CMS_R_CTRL_ERROR);
+               goto err;
+               }
+
+       if (EVP_PKEY_encrypt(pctx, NULL, &eklen, ec->key, ec->keylen) <= 0)
+               goto err;
 
        ek = OPENSSL_malloc(eklen);
 
@@ -326,9 +344,7 @@ static int cms_RecipientInfo_ktri_encrypt(CMS_ContentInfo *cms,
                goto err;
                }
 
-       eklen = EVP_PKEY_encrypt(ek, ec->key, ec->keylen, ktri->pkey);
-
-       if (eklen <= 0)
+       if (EVP_PKEY_encrypt(pctx, ek, &eklen, ec->key, ec->keylen) <= 0)
                goto err;
 
        ASN1_STRING_set0(ktri->encryptedKey, ek, eklen);
@@ -337,6 +353,8 @@ static int cms_RecipientInfo_ktri_encrypt(CMS_ContentInfo *cms,
        ret = 1;
 
        err:
+       if (pctx)
+               EVP_PKEY_CTX_free(pctx);
        if (ek)
                OPENSSL_free(ek);
        return ret;
@@ -349,8 +367,9 @@ static int cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms,
                                                        CMS_RecipientInfo *ri)
        {
        CMS_KeyTransRecipientInfo *ktri = ri->d.ktri;
+       EVP_PKEY_CTX *pctx = NULL;
        unsigned char *ek = NULL;
-       int eklen;
+       size_t eklen;
        int ret = 0;
 
        if (ktri->pkey == NULL)
@@ -360,7 +379,24 @@ static int cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms,
                return 0;
                }
 
-       eklen = EVP_PKEY_size(ktri->pkey);
+       pctx = EVP_PKEY_CTX_new(ktri->pkey, NULL);
+       if (!pctx)
+               return 0;
+
+       if (EVP_PKEY_decrypt_init(pctx) <= 0)
+               goto err;
+
+       if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DECRYPT,
+                               EVP_PKEY_CTRL_CMS_DECRYPT, 0, ri) <= 0)
+               {
+               CMSerr(CMS_F_CMS_RECIPIENTINFO_KTRI_DECRYPT, CMS_R_CTRL_ERROR);
+               goto err;
+               }
+
+       if (EVP_PKEY_decrypt(pctx, NULL, &eklen,
+                               ktri->encryptedKey->data,
+                               ktri->encryptedKey->length) <= 0)
+               goto err;
 
        ek = OPENSSL_malloc(eklen);
 
@@ -371,10 +407,9 @@ static int cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms,
                goto err;
                }
 
-       eklen = EVP_PKEY_decrypt(ek, 
+       if (EVP_PKEY_decrypt(pctx, ek, &eklen,
                                ktri->encryptedKey->data,
-                               ktri->encryptedKey->length, ktri->pkey);
-       if (eklen <= 0)
+                               ktri->encryptedKey->length) <= 0)
                {
                CMSerr(CMS_F_CMS_RECIPIENTINFO_KTRI_DECRYPT, CMS_R_CMS_LIB);
                goto err;
@@ -386,6 +421,8 @@ static int cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms,
        cms->d.envelopedData->encryptedContentInfo->keylen = eklen;
 
        err:
+       if (pctx)
+               EVP_PKEY_CTX_free(pctx);
        if (!ret && ek)
                OPENSSL_free(ek);
 
index 52fa539..ff7b030 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/cms/cms_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2008 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2007 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -133,7 +133,7 @@ static ERR_STRING_DATA CMS_str_functs[]=
 {ERR_FUNC(CMS_F_CMS_SIGNERINFO_VERIFY_CERT),   "CMS_SIGNERINFO_VERIFY_CERT"},
 {ERR_FUNC(CMS_F_CMS_SIGNERINFO_VERIFY_CONTENT),        "CMS_SignerInfo_verify_content"},
 {ERR_FUNC(CMS_F_CMS_SIGN_RECEIPT),     "CMS_sign_receipt"},
-{ERR_FUNC(CMS_F_CMS_STREAM),   "CMS_STREAM"},
+{ERR_FUNC(CMS_F_CMS_STREAM),   "CMS_stream"},
 {ERR_FUNC(CMS_F_CMS_UNCOMPRESS),       "CMS_uncompress"},
 {ERR_FUNC(CMS_F_CMS_VERIFY),   "CMS_verify"},
 {0,NULL}
index 65613aa..90c0b82 100644 (file)
@@ -63,7 +63,7 @@
 DECLARE_ASN1_ITEM(CMS_ReceiptRequest)
 DECLARE_ASN1_ITEM(CMS_Receipt)
 
-IMPLEMENT_ASN1_FUNCTIONS_const(CMS_ReceiptRequest)
+IMPLEMENT_ASN1_FUNCTIONS(CMS_ReceiptRequest)
 
 /* ESS services: for now just Signed Receipt related */
 
index 30f5ddf..1cb0264 100644 (file)
 #include "cms.h"
 #include "cms_lcl.h"
 
+int CMS_stream(unsigned char ***boundary, CMS_ContentInfo *cms)
+       {
+       ASN1_OCTET_STRING **pos;
+       pos = CMS_get0_content(cms);
+       if (!pos)
+               return 0;
+       if (!*pos)
+               *pos = ASN1_OCTET_STRING_new();
+       if (*pos)
+               {
+               (*pos)->flags |= ASN1_STRING_FLAG_NDEF;
+               (*pos)->flags &= ~ASN1_STRING_FLAG_CONT;
+               *boundary = &(*pos)->data;
+               return 1;
+               }
+       CMSerr(CMS_F_CMS_STREAM, ERR_R_MALLOC_FAILURE);
+       return 0;
+       }
+
 CMS_ContentInfo *d2i_CMS_bio(BIO *bp, CMS_ContentInfo **cms)
        {
        return ASN1_item_d2i_bio(ASN1_ITEM_rptr(CMS_ContentInfo), bp, cms);
@@ -70,52 +89,26 @@ int i2d_CMS_bio(BIO *bp, CMS_ContentInfo *cms)
 
 IMPLEMENT_PEM_rw_const(CMS, CMS_ContentInfo, PEM_STRING_CMS, CMS_ContentInfo)
 
-/* Callback for int_smime_write_ASN1 */
-
-static int cms_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
-                                       const ASN1_ITEM *it)
+BIO *BIO_new_CMS(BIO *out, CMS_ContentInfo *cms) 
        {
-       CMS_ContentInfo *cms = (CMS_ContentInfo *)val;
-       BIO *tmpbio, *cmsbio;
-       int r = 0;
-
-       if (!(flags & SMIME_DETACHED))
-               {
-               SMIME_crlf_copy(data, out, flags);
-               return 1;
-               }
-
-       /* Let CMS code prepend any needed BIOs */
-
-       cmsbio = CMS_dataInit(cms, out);
-
-       if (!cmsbio)
-               return 0;
-
-       /* Copy data across, passing through filter BIOs for processing */
-       SMIME_crlf_copy(data, cmsbio, flags);
-
-       /* Finalize structure */
-       if (CMS_dataFinal(cms, cmsbio) <= 0)
-               goto err;
-
-       r = 1;
-
-       err:
-
-       /* Now remove any digests prepended to the BIO */
-
-       while (cmsbio != out)
-               {
-               tmpbio = BIO_pop(cmsbio);
-               BIO_free(cmsbio);
-               cmsbio = tmpbio;
-               }
+       return BIO_new_NDEF(out, (ASN1_VALUE *)cms,
+                               ASN1_ITEM_rptr(CMS_ContentInfo));
+       }
 
-       return 1;
+/* CMS wrappers round generalised stream and MIME routines */
 
+int i2d_CMS_bio_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags)
+       {
+       return i2d_ASN1_bio_stream(out, (ASN1_VALUE *)cms, in, flags,
+                                       ASN1_ITEM_rptr(CMS_ContentInfo));
        }
 
+int PEM_write_bio_CMS_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags)
+       {
+       return PEM_write_bio_ASN1_stream(out, (ASN1_VALUE *) cms, in, flags,
+                                       "CMS",
+                                       ASN1_ITEM_rptr(CMS_ContentInfo));
+       }
 
 int SMIME_write_CMS(BIO *bio, CMS_ContentInfo *cms, BIO *data, int flags)
        {
@@ -127,9 +120,8 @@ int SMIME_write_CMS(BIO *bio, CMS_ContentInfo *cms, BIO *data, int flags)
        else
                mdalgs = NULL;
 
-       return int_smime_write_ASN1(bio, (ASN1_VALUE *)cms, data, flags,
+       return SMIME_write_ASN1(bio, (ASN1_VALUE *)cms, data, flags,
                                        ctype_nid, econt_nid, mdalgs,
-                                       cms_output_data,
                                        ASN1_ITEM_rptr(CMS_ContentInfo));       
        }
 
@@ -138,3 +130,4 @@ CMS_ContentInfo *SMIME_read_CMS(BIO *bio, BIO **bcont)
        return (CMS_ContentInfo *)SMIME_read_ASN1(bio, bcont,
                                        ASN1_ITEM_rptr(CMS_ContentInfo));
        }
+
index 7d60fac..c8ecfa7 100644 (file)
@@ -406,6 +406,7 @@ struct CMS_Receipt_st
        ASN1_OCTET_STRING *originatorSignatureValue;
        };
 
+DECLARE_ASN1_FUNCTIONS(CMS_ContentInfo)
 DECLARE_ASN1_ITEM(CMS_SignerInfo)
 DECLARE_ASN1_ITEM(CMS_IssuerAndSerialNumber)
 DECLARE_ASN1_ITEM(CMS_Attributes_Sign)
index cc00526..d00fe0f 100644 (file)
@@ -60,7 +60,8 @@
 #include "cms.h"
 #include "cms_lcl.h"
 
-IMPLEMENT_ASN1_FUNCTIONS_const(CMS_ContentInfo)
+IMPLEMENT_ASN1_FUNCTIONS(CMS_ContentInfo)
+IMPLEMENT_ASN1_PRINT_FUNCTION(CMS_ContentInfo)
 
 DECLARE_ASN1_ITEM(CMS_CertificateChoices)
 DECLARE_ASN1_ITEM(CMS_RevocationInfoChoice)
@@ -346,20 +347,10 @@ void cms_DigestAlgorithm_set(X509_ALGOR *alg, const EVP_MD *md)
        {
        int param_type;
 
-       switch (EVP_MD_type(md))
-               {
-               case NID_sha1:
-               case NID_sha224:
-               case NID_sha256:
-               case NID_sha384:
-               case NID_sha512:
+       if (md->flags & EVP_MD_FLAG_DIGALGID_ABSENT)
                param_type = V_ASN1_UNDEF;
-               break;
-       
-               default:
+       else
                param_type = V_ASN1_NULL;
-               break;
-               }
 
        X509_ALGOR_set0(alg, OBJ_nid2obj(EVP_MD_type(md)), param_type, NULL);
 
@@ -561,6 +552,15 @@ int CMS_add0_crl(CMS_ContentInfo *cms, X509_CRL *crl)
        return 1;
        }
 
+int CMS_add1_crl(CMS_ContentInfo *cms, X509_CRL *crl)
+       {
+       int r;
+       r = CMS_add0_crl(cms, crl);
+       if (r > 0)
+               CRYPTO_add(&crl->references, 1, CRYPTO_LOCK_X509_CRL);
+       return r;
+       }
+
 STACK_OF(X509) *CMS_get1_certs(CMS_ContentInfo *cms)
        {
        STACK_OF(X509) *certs = NULL;
index cdac3b8..e3192b9 100644 (file)
@@ -58,6 +58,7 @@
 #include <openssl/err.h>
 #include <openssl/cms.h>
 #include "cms_lcl.h"
+#include "asn1_locl.h"
 
 /* CMS SignedData Utilities */
 
@@ -218,10 +219,9 @@ int cms_set1_SignerIdentifier(CMS_SignerIdentifier *sid, X509 *cert, int type)
                if (!X509_NAME_set(&sid->d.issuerAndSerialNumber->issuer,
                                        X509_get_issuer_name(cert)))
                        goto merr;
-               ASN1_STRING_free(sid->d.issuerAndSerialNumber->serialNumber);
-               sid->d.issuerAndSerialNumber->serialNumber =
-                               ASN1_STRING_dup(X509_get_serialNumber(cert));
-               if(!sid->d.issuerAndSerialNumber->serialNumber)
+               if (!ASN1_STRING_copy(
+                       sid->d.issuerAndSerialNumber->serialNumber,
+                               X509_get_serialNumber(cert)))
                        goto merr;
                break;
 
@@ -341,16 +341,22 @@ CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
        if (!cms_set1_SignerIdentifier(si->sid, signer, type))
                goto err;
 
-       /* Since no EVP_PKEY_METHOD in 0.9.8 hard code SHA1 as default */
        if (md == NULL)
-               md = EVP_sha1();
-
-       /* OpenSSL 0.9.8 only supports SHA1 with non-RSA keys */
+               {
+               int def_nid;
+               if (EVP_PKEY_get_default_digest_nid(pk, &def_nid) <= 0)
+                       goto err;
+               md = EVP_get_digestbynid(def_nid);
+               if (md == NULL)
+                       {
+                       CMSerr(CMS_F_CMS_ADD1_SIGNER, CMS_R_NO_DEFAULT_DIGEST);
+                       goto err;
+                       }
+               }
 
-       if ((pk->type != EVP_PKEY_RSA) && (EVP_MD_type(md) != NID_sha1))
+       if (!md)
                {
-               CMSerr(CMS_F_CMS_ADD1_SIGNER,
-                               CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);
+               CMSerr(CMS_F_CMS_ADD1_SIGNER, CMS_R_NO_DIGEST_SET);
                goto err;
                }
 
@@ -379,37 +385,21 @@ CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
                        }
                }
 
-       /* Since we have no EVP_PKEY_ASN1_METHOD in OpenSSL 0.9.8,
-        * hard code algorithm parameters.
-        */
-
-       switch (pk->type)
+       if (pk->ameth && pk->ameth->pkey_ctrl)
                {
-
-               case EVP_PKEY_RSA:
-               X509_ALGOR_set0(si->signatureAlgorithm,
-                                       OBJ_nid2obj(NID_rsaEncryption),
-                                       V_ASN1_NULL, 0);
-               break;
-
-               case EVP_PKEY_DSA:
-               X509_ALGOR_set0(si->signatureAlgorithm,
-                                       OBJ_nid2obj(NID_dsaWithSHA1),
-                                       V_ASN1_UNDEF, 0);
-               break;
-
-
-               case EVP_PKEY_EC:
-               X509_ALGOR_set0(si->signatureAlgorithm,
-                                       OBJ_nid2obj(NID_ecdsa_with_SHA1),
-                                       V_ASN1_UNDEF, 0);
-               break;
-
-               default:
-               CMSerr(CMS_F_CMS_ADD1_SIGNER,
+               i = pk->ameth->pkey_ctrl(pk, ASN1_PKEY_CTRL_CMS_SIGN,
+                                               0, si);
+               if (i == -2)
+                       {
+                       CMSerr(CMS_F_CMS_ADD1_SIGNER,
                                CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);
-               goto err;
-
+                       goto err;
+                       }
+               if (i <= 0)
+                       {
+                       CMSerr(CMS_F_CMS_ADD1_SIGNER, CMS_R_CTRL_FAILURE);
+                       goto err;
+                       }
                }
 
        if (!(flags & CMS_NOATTR))
@@ -626,25 +616,6 @@ void CMS_SignerInfo_get0_algs(CMS_SignerInfo *si, EVP_PKEY **pk, X509 **signer,
                *psig = si->signatureAlgorithm;
        }
 
-/* In OpenSSL 0.9.8 we have the link between digest types and public
- * key types so we need to fixup the digest type if the public key
- * type is not appropriate.
- */
-
-static void cms_fixup_mctx(EVP_MD_CTX *mctx, EVP_PKEY *pkey)
-       {
-       if (EVP_MD_CTX_type(mctx) != NID_sha1)
-               return;
-#ifndef OPENSSL_NO_DSA
-       if (pkey->type == EVP_PKEY_DSA)
-               mctx->digest = EVP_dss1();      
-#endif
-#ifndef OPENSSL_NO_ECDSA
-       if (pkey->type == EVP_PKEY_EC)
-               mctx->digest = EVP_ecdsa();     
-#endif
-       }
-
 static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms,
                                        CMS_SignerInfo *si, BIO *chain)
        {
@@ -693,7 +664,6 @@ static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms,
                                        ERR_R_MALLOC_FAILURE);
                        goto err;
                        }
-               cms_fixup_mctx(&mctx, si->pkey);
                if (!EVP_SignFinal(&mctx, sig, &siglen, si->pkey))
                        {
                        CMSerr(CMS_F_CMS_SIGNERINFO_CONTENT_SIGN,
@@ -731,9 +701,10 @@ int cms_SignedData_final(CMS_ContentInfo *cms, BIO *chain)
 int CMS_SignerInfo_sign(CMS_SignerInfo *si)
        {
        EVP_MD_CTX mctx;
+       EVP_PKEY_CTX *pctx;
        unsigned char *abuf = NULL;
        int alen;
-       unsigned int siglen;
+       size_t siglen;
        const EVP_MD *md = NULL;
 
        md = EVP_get_digestbyobj(si->digestAlgorithm->algorithm);
@@ -748,40 +719,38 @@ int CMS_SignerInfo_sign(CMS_SignerInfo *si)
                        goto err;
                }
 
-       if (EVP_SignInit_ex(&mctx, md, NULL) <= 0)
+       if (EVP_DigestSignInit(&mctx, &pctx, md, NULL, si->pkey) <= 0)
                goto err;
 
-#if 0
        if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_SIGN,
                                EVP_PKEY_CTRL_CMS_SIGN, 0, si) <= 0)
                {
                CMSerr(CMS_F_CMS_SIGNERINFO_SIGN, CMS_R_CTRL_ERROR);
                goto err;
                }
-#endif
 
        alen = ASN1_item_i2d((ASN1_VALUE *)si->signedAttrs,&abuf,
                                ASN1_ITEM_rptr(CMS_Attributes_Sign));
        if(!abuf)
                goto err;
-       if (EVP_SignUpdate(&mctx, abuf, alen) <= 0)
+       if (EVP_DigestSignUpdate(&mctx, abuf, alen) <= 0)
+               goto err;
+       if (EVP_DigestSignFinal(&mctx, NULL, &siglen) <= 0)
                goto err;
-       siglen = EVP_PKEY_size(si->pkey);
        OPENSSL_free(abuf);
        abuf = OPENSSL_malloc(siglen);
        if(!abuf)
                goto err;
-       cms_fixup_mctx(&mctx, si->pkey);
-       if (EVP_SignFinal(&mctx, abuf, &siglen, si->pkey) <= 0)
+       if (EVP_DigestSignFinal(&mctx, abuf, &siglen) <= 0)
                goto err;
-#if 0
+
        if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_SIGN,
                                EVP_PKEY_CTRL_CMS_SIGN, 1, si) <= 0)
                {
                CMSerr(CMS_F_CMS_SIGNERINFO_SIGN, CMS_R_CTRL_ERROR);
                goto err;
                }
-#endif
+
        EVP_MD_CTX_cleanup(&mctx);
 
        ASN1_STRING_set0(si->signature, abuf, siglen);
@@ -799,6 +768,7 @@ int CMS_SignerInfo_sign(CMS_SignerInfo *si)
 int CMS_SignerInfo_verify(CMS_SignerInfo *si)
        {
        EVP_MD_CTX mctx;
+       EVP_PKEY_CTX *pctx;
        unsigned char *abuf = NULL;
        int alen, r = -1;
        const EVP_MD *md = NULL;
@@ -813,23 +783,22 @@ int CMS_SignerInfo_verify(CMS_SignerInfo *si)
        if (md == NULL)
                return -1;
        EVP_MD_CTX_init(&mctx);
-       if (EVP_VerifyInit_ex(&mctx, md, NULL) <= 0)
+       if (EVP_DigestVerifyInit(&mctx, &pctx, md, NULL, si->pkey) <= 0)
                goto err;
 
        alen = ASN1_item_i2d((ASN1_VALUE *)si->signedAttrs,&abuf,
                                ASN1_ITEM_rptr(CMS_Attributes_Verify));
        if(!abuf)
                goto err;
-       r = EVP_VerifyUpdate(&mctx, abuf, alen);
+       r = EVP_DigestVerifyUpdate(&mctx, abuf, alen);
        OPENSSL_free(abuf);
        if (r <= 0)
                {
                r = -1;
                goto err;
                }
-       cms_fixup_mctx(&mctx, si->pkey);
-       r = EVP_VerifyFinal(&mctx,
-                       si->signature->data, si->signature->length, si->pkey);
+       r = EVP_DigestVerifyFinal(&mctx,
+                       si->signature->data, si->signature->length);
        if (r <= 0)
                CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY, CMS_R_VERIFICATION_FAILURE);
        err:
@@ -922,7 +891,6 @@ int CMS_SignerInfo_verify_content(CMS_SignerInfo *si, BIO *chain)
                }
        else
                {
-               cms_fixup_mctx(&mctx, si->pkey);
                r = EVP_VerifyFinal(&mctx, si->signature->data,
                                        si->signature->length, si->pkey);
                if (r <= 0)
@@ -991,17 +959,19 @@ static int cms_add_cipher_smcap(STACK_OF(X509_ALGOR) **sk, int nid, int arg)
                return CMS_add_simple_smimecap(sk, nid, arg);
        return 1;
        }
-#if 0
+
 static int cms_add_digest_smcap(STACK_OF(X509_ALGOR) **sk, int nid, int arg)
        {
        if (EVP_get_digestbynid(nid))
                return CMS_add_simple_smimecap(sk, nid, arg);
        return 1;
        }
-#endif
+
 int CMS_add_standard_smimecap(STACK_OF(X509_ALGOR) **smcap)
        {
        if (!cms_add_cipher_smcap(smcap, NID_aes_256_cbc, -1)
+               || !cms_add_digest_smcap(smcap, NID_id_GostR3411_94, -1)
+               || !cms_add_cipher_smcap(smcap, NID_id_Gost28147_89, -1)
                || !cms_add_cipher_smcap(smcap, NID_aes_192_cbc, -1)
                || !cms_add_cipher_smcap(smcap, NID_aes_128_cbc, -1)
                || !cms_add_cipher_smcap(smcap, NID_des_ede3_cbc, -1)
index f35883a..4a799eb 100644 (file)
@@ -171,7 +171,7 @@ CMS_ContentInfo *CMS_data_create(BIO *in, unsigned int flags)
        if (!cms)
                return NULL;
 
-       if (CMS_final(cms, in, NULL, flags))
+       if ((flags & CMS_STREAM) || CMS_final(cms, in, NULL, flags))
                return cms;
 
        CMS_ContentInfo_free(cms);
@@ -214,10 +214,7 @@ CMS_ContentInfo *CMS_digest_create(BIO *in, const EVP_MD *md,
                return NULL;
 
        if(!(flags & CMS_DETACHED))
-               {
-               flags &= ~CMS_STREAM;
                CMS_set_detached(cms, 0);
-               }
 
        if ((flags & CMS_STREAM) || CMS_final(cms, in, NULL, flags))
                return cms;
@@ -269,10 +266,7 @@ CMS_ContentInfo *CMS_EncryptedData_encrypt(BIO *in, const EVP_CIPHER *cipher,
                return NULL;
 
        if(!(flags & CMS_DETACHED))
-               {
-               flags &= ~CMS_STREAM;
                CMS_set_detached(cms, 0);
-               }
 
        if ((flags & (CMS_STREAM|CMS_PARTIAL))
                || CMS_final(cms, in, NULL, flags))
@@ -456,6 +450,7 @@ int CMS_verify_receipt(CMS_ContentInfo *rcms, CMS_ContentInfo *ocms,
                        X509_STORE *store, unsigned int flags)
        {
        int r;
+       flags &= ~(CMS_DETACHED|CMS_TEXT);
        r = CMS_verify(rcms, certs, store, NULL, NULL, flags);
        if (r <= 0)
                return r;
@@ -486,10 +481,7 @@ CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
                }
 
        if(!(flags & CMS_DETACHED))
-               {
-               flags &= ~CMS_STREAM;
                CMS_set_detached(cms, 0);
-               }
 
        if ((flags & (CMS_STREAM|CMS_PARTIAL))
                || CMS_final(cms, data, NULL, flags))
@@ -517,7 +509,7 @@ CMS_ContentInfo *CMS_sign_receipt(CMS_SignerInfo *si,
        BIO *rct_cont = NULL;
        int r = 0;
 
-       flags &= ~CMS_STREAM;
+       flags &= ~(CMS_STREAM|CMS_TEXT);
        /* Not really detached but avoids content being allocated */
        flags |= CMS_PARTIAL|CMS_BINARY|CMS_DETACHED;
        if (!pkey || !signcert)
@@ -598,10 +590,7 @@ CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *data,
                }
 
        if(!(flags & CMS_DETACHED))
-               {
-               flags &= ~CMS_STREAM;
                CMS_set_detached(cms, 0);
-               }
 
        if ((flags & (CMS_STREAM|CMS_PARTIAL))
                || CMS_final(cms, data, NULL, flags))
@@ -781,12 +770,9 @@ CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags)
                return NULL;
 
        if(!(flags & CMS_DETACHED))
-               {
-               flags &= ~CMS_STREAM;
                CMS_set_detached(cms, 0);
-               }
 
-       if (CMS_final(cms, in, NULL, flags))
+       if ((flags & CMS_STREAM) || CMS_final(cms, in, NULL, flags))
                return cms;
 
        CMS_ContentInfo_free(cms);
index 5d364b8..efda832 100644 (file)
@@ -36,7 +36,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
index 8df7792..8adf35f 100644 (file)
@@ -781,6 +781,7 @@ static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr)
        default:
                ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
                break;
+
                }
 
        return ret;
index 187d68b..661c94c 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/comp/comp_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2008 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2007 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
index ccd0721..78bb324 100644 (file)
@@ -36,7 +36,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -114,8 +114,8 @@ conf_mall.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
 conf_mall.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 conf_mall.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
 conf_mall.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-conf_mall.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-conf_mall.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+conf_mall.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+conf_mall.o: ../../include/openssl/objects.h
 conf_mall.o: ../../include/openssl/opensslconf.h
 conf_mall.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 conf_mall.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
@@ -128,9 +128,9 @@ conf_mod.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 conf_mod.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
 conf_mod.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 conf_mod.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-conf_mod.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-conf_mod.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-conf_mod.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+conf_mod.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+conf_mod.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+conf_mod.o: ../../include/openssl/opensslconf.h
 conf_mod.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 conf_mod.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 conf_mod.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -143,9 +143,8 @@ conf_sap.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
 conf_sap.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 conf_sap.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
 conf_sap.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-conf_sap.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-conf_sap.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-conf_sap.o: ../../include/openssl/opensslconf.h
+conf_sap.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+conf_sap.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 conf_sap.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 conf_sap.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 conf_sap.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
index ca58d02..96e53b3 100644 (file)
@@ -1,8 +1,3 @@
-WARNING WARNING WARNING!!!
-
-This stuff is experimental, may change radically or be deleted altogether
-before OpenSSL 0.9.7 release. You have been warned!
-
 Configuration modules. These are a set of modules which can perform
 various configuration functions.
 
@@ -13,7 +8,7 @@ The routines read a configuration file set up like this:
 
 -----
 #default section
-openssl_init=init_section
+openssl_conf=init_section
 
 [init_section]
 
@@ -30,29 +25,27 @@ path=/some/path/to/some/dso.so
 other_stuff=other_value
 ----
 
-When this file is loaded a configuration module with the specified
-string (module* in the above example) is looked up and its init
-function called as:
+When this file is loaded a configuration module with the specified string
+(module* in the above example) is looked up and its init function called as:
 
 int conf_init_func(CONF_IMODULE *md, CONF *cnf);
 
-The function can then take whatever action is appropriate, for example
-further lookups based on the value. Multiple instances of the same 
-config module can be loaded.
+The function can then take whatever action is appropriate, for example further
+lookups based on the value. Multiple instances of the same config module can be
+loaded.
 
-When the application closes down the modules are cleaned up by calling
-an optional finish function:
+When the application closes down the modules are cleaned up by calling an
+optional finish function:
 
 void conf_finish_func(CONF_IMODULE *md);
 
 The finish functions are called in reverse order: that is the last module
 loaded is the first one cleaned up.
 
-If no module exists with a given name then an attempt is made to load
-a DSO with the supplied name. This might mean that "module3" attempts
-to load a DSO called libmodule3.so or module3.dll for example. An explicit
-DSO name can be given by including a separate section as in the module4 example
-above.
+If no module exists with a given name then an attempt is made to load a DSO
+with the supplied name. This might mean that "module3" attempts to load a DSO
+called libmodule3.so or module3.dll for example. An explicit DSO name can be
+given by including a separate section as in the module4 example above.
 
 The DSO is expected to at least contain an initialization function:
 
@@ -64,15 +57,17 @@ void OPENSSL_finish(CONF_IMODULE *md);
 
 Static modules can also be added using,
 
-int CONF_module_add(char *name, dso_mod_init_func *ifunc, dso_mod_finish_func *ffunc);
+int CONF_module_add(char *name, dso_mod_init_func *ifunc, dso_mod_finish_func
+*ffunc);
 
-where "name" is the name in the configuration file this function corresponds to.
+where "name" is the name in the configuration file this function corresponds
+to.
 
-A set of builtin modules (currently only an ASN1 non functional test module) can be 
-added by calling OPENSSL_load_builtin_modules(). 
+A set of builtin modules (currently only an ASN1 non functional test module)
+can be added by calling OPENSSL_load_builtin_modules(). 
 
-The function OPENSSL_config() is intended as a simple configuration function that
-any application can call to perform various default configuration tasks. It uses the
-file openssl.cnf in the usual locations.
+The function OPENSSL_config() is intended as a simple configuration function
+that any application can call to perform various default configuration tasks.
+It uses the file openssl.cnf in the usual locations.
 
 
index 8aa06bc..c219997 100644 (file)
@@ -79,8 +79,7 @@ typedef struct
        } CONF_VALUE;
 
 DECLARE_STACK_OF(CONF_VALUE)
-DECLARE_STACK_OF(CONF_MODULE)
-DECLARE_STACK_OF(CONF_IMODULE)
+DECLARE_LHASH_OF(CONF_VALUE);
 
 struct conf_st;
 struct conf_method_st;
@@ -105,6 +104,9 @@ struct conf_method_st
 typedef struct conf_imodule_st CONF_IMODULE;
 typedef struct conf_module_st CONF_MODULE;
 
+DECLARE_STACK_OF(CONF_MODULE)
+DECLARE_STACK_OF(CONF_IMODULE)
+
 /* DSO module function typedefs */
 typedef int conf_init_func(CONF_IMODULE *md, const CONF *cnf);
 typedef void conf_finish_func(CONF_IMODULE *md);
@@ -117,18 +119,23 @@ typedef void conf_finish_func(CONF_IMODULE *md);
 #define CONF_MFLAGS_DEFAULT_SECTION    0x20
 
 int CONF_set_default_method(CONF_METHOD *meth);
-void CONF_set_nconf(CONF *conf,LHASH *hash);
-LHASH *CONF_load(LHASH *conf,const char *file,long *eline);
+void CONF_set_nconf(CONF *conf,LHASH_OF(CONF_VALUE) *hash);
+LHASH_OF(CONF_VALUE) *CONF_load(LHASH_OF(CONF_VALUE) *conf,const char *file,
+                               long *eline);
 #ifndef OPENSSL_NO_FP_API
-LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline);
+LHASH_OF(CONF_VALUE) *CONF_load_fp(LHASH_OF(CONF_VALUE) *conf, FILE *fp,
+                                  long *eline);
 #endif
-LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline);
-STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,const char *section);
-char *CONF_get_string(LHASH *conf,const char *group,const char *name);
-long CONF_get_number(LHASH *conf,const char *group,const char *name);
-void CONF_free(LHASH *conf);
-int CONF_dump_fp(LHASH *conf, FILE *out);
-int CONF_dump_bio(LHASH *conf, BIO *out);
+LHASH_OF(CONF_VALUE) *CONF_load_bio(LHASH_OF(CONF_VALUE) *conf, BIO *bp,long *eline);
+STACK_OF(CONF_VALUE) *CONF_get_section(LHASH_OF(CONF_VALUE) *conf,
+                                      const char *section);
+char *CONF_get_string(LHASH_OF(CONF_VALUE) *conf,const char *group,
+                     const char *name);
+long CONF_get_number(LHASH_OF(CONF_VALUE) *conf,const char *group,
+                    const char *name);
+void CONF_free(LHASH_OF(CONF_VALUE) *conf);
+int CONF_dump_fp(LHASH_OF(CONF_VALUE) *conf, FILE *out);
+int CONF_dump_bio(LHASH_OF(CONF_VALUE) *conf, BIO *out);
 
 void OPENSSL_config(const char *config_name);
 void OPENSSL_no_config(void);
@@ -140,7 +147,7 @@ struct conf_st
        {
        CONF_METHOD *meth;
        void *meth_data;
-       LHASH *data;
+       LHASH_OF(CONF_VALUE) *data;
        };
 
 CONF *NCONF_new(CONF_METHOD *meth);
@@ -214,6 +221,7 @@ void ERR_load_CONF_strings(void);
 #define CONF_F_CONF_LOAD_BIO                            102
 #define CONF_F_CONF_LOAD_FP                             103
 #define CONF_F_CONF_MODULES_LOAD                        116
+#define CONF_F_CONF_PARSE_LIST                          119
 #define CONF_F_DEF_LOAD                                         120
 #define CONF_F_DEF_LOAD_BIO                             121
 #define CONF_F_MODULE_INIT                              115
@@ -233,6 +241,7 @@ void ERR_load_CONF_strings(void);
 
 /* Reason codes. */
 #define CONF_R_ERROR_LOADING_DSO                        110
+#define CONF_R_LIST_CANNOT_BE_NULL                      115
 #define CONF_R_MISSING_CLOSE_SQUARE_BRACKET             100
 #define CONF_R_MISSING_EQUAL_SIGN                       101
 #define CONF_R_MISSING_FINISH_FUNCTION                  111
index 909d72b..f5fcbb9 100644 (file)
 #endif
 
 #include <assert.h>
+#include <stdlib.h>
 #include <string.h>
 #include <openssl/conf.h>
 #include <openssl/conf_api.h>
 #include "e_os.h"
 
-static void value_free_hash(CONF_VALUE *a, LHASH *conf);
-static void value_free_stack(CONF_VALUE *a,LHASH *conf);
-static IMPLEMENT_LHASH_DOALL_ARG_FN(value_free_hash, CONF_VALUE *, LHASH *)
-static IMPLEMENT_LHASH_DOALL_ARG_FN(value_free_stack, CONF_VALUE *, LHASH *)
-/* We don't use function pointer casting or wrapper functions - but cast each
- * callback parameter inside the callback functions. */
-/* static unsigned long hash(CONF_VALUE *v); */
-static unsigned long hash(const void *v_void);
-/* static int cmp_conf(CONF_VALUE *a,CONF_VALUE *b); */
-static int cmp_conf(const void *a_void,const void *b_void);
+static void value_free_hash_doall_arg(CONF_VALUE *a,
+                                     LHASH_OF(CONF_VALUE) *conf);
+static void value_free_stack_doall(CONF_VALUE *a);
+static IMPLEMENT_LHASH_DOALL_ARG_FN(value_free_hash, CONF_VALUE,
+                                   LHASH_OF(CONF_VALUE))
+static IMPLEMENT_LHASH_DOALL_FN(value_free_stack, CONF_VALUE)
 
 /* Up until OpenSSL 0.9.5a, this was get_section */
 CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section)
@@ -88,7 +85,7 @@ CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section)
        if ((conf == NULL) || (section == NULL)) return(NULL);
        vv.name=NULL;
        vv.section=(char *)section;
-       v=(CONF_VALUE *)lh_retrieve(conf->data,&vv);
+       v=lh_CONF_VALUE_retrieve(conf->data,&vv);
        return(v);
        }
 
@@ -118,7 +115,7 @@ int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value)
                return 0;
                }
 
-       v = (CONF_VALUE *)lh_insert(conf->data, value);
+       v = lh_CONF_VALUE_insert(conf->data, value);
        if (v != NULL)
                {
                (void)sk_CONF_VALUE_delete_ptr(ts,v);
@@ -141,24 +138,24 @@ char *_CONF_get_string(const CONF *conf, const char *section, const char *name)
                        {
                        vv.name=(char *)name;
                        vv.section=(char *)section;
-                       v=(CONF_VALUE *)lh_retrieve(conf->data,&vv);
+                       v=lh_CONF_VALUE_retrieve(conf->data,&vv);
                        if (v != NULL) return(v->value);
                        if (strcmp(section,"ENV") == 0)
                                {
-                               p=Getenv(name);
+                               p=getenv(name);
                                if (p != NULL) return(p);
                                }
                        }
                vv.section="default";
                vv.name=(char *)name;
-               v=(CONF_VALUE *)lh_retrieve(conf->data,&vv);
+               v=lh_CONF_VALUE_retrieve(conf->data,&vv);
                if (v != NULL)
                        return(v->value);
                else
                        return(NULL);
                }
        else
-               return(Getenv(name));
+               return(getenv(name));
        }
 
 #if 0 /* There's no way to provide error checking with this function, so
@@ -182,6 +179,34 @@ long _CONF_get_number(CONF *conf, char *section, char *name)
        }
 #endif
 
+static unsigned long conf_value_hash(const CONF_VALUE *v)
+       {
+       return (lh_strhash(v->section)<<2)^lh_strhash(v->name);
+       }
+static IMPLEMENT_LHASH_HASH_FN(conf_value, CONF_VALUE)
+
+static int conf_value_cmp(const CONF_VALUE *a, const CONF_VALUE *b)
+       {
+       int i;
+
+       if (a->section != b->section)
+               {
+               i=strcmp(a->section,b->section);
+               if (i) return(i);
+               }
+
+       if ((a->name != NULL) && (b->name != NULL))
+               {
+               i=strcmp(a->name,b->name);
+               return(i);
+               }
+       else if (a->name == b->name)
+               return(0);
+       else
+               return((a->name == NULL)?-1:1);
+       }
+static IMPLEMENT_LHASH_COMP_FN(conf_value, CONF_VALUE)
+
 int _CONF_new_data(CONF *conf)
        {
        if (conf == NULL)
@@ -189,7 +214,7 @@ int _CONF_new_data(CONF *conf)
                return 0;
                }
        if (conf->data == NULL)
-               if ((conf->data = lh_new(hash, cmp_conf)) == NULL)
+               if ((conf->data = lh_CONF_VALUE_new()) == NULL)
                        {
                        return 0;
                        }
@@ -200,105 +225,73 @@ void _CONF_free_data(CONF *conf)
        {
        if (conf == NULL || conf->data == NULL) return;
 
-       conf->data->down_load=0; /* evil thing to make sure the 'OPENSSL_free()'
-                                 * works as expected */
-       lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(value_free_hash),
-                       conf->data);
+       lh_CONF_VALUE_down_load(conf->data)=0; /* evil thing to make
+                                 * sure the 'OPENSSL_free()' works as
+                                 * expected */
+       lh_CONF_VALUE_doall_arg(conf->data,
+                               LHASH_DOALL_ARG_FN(value_free_hash),
+                               LHASH_OF(CONF_VALUE), conf->data);
 
        /* We now have only 'section' entries in the hash table.
         * Due to problems with */
 
-       lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(value_free_stack),
-                       conf->data);
-       lh_free(conf->data);
+       lh_CONF_VALUE_doall(conf->data, LHASH_DOALL_FN(value_free_stack));
+       lh_CONF_VALUE_free(conf->data);
        }
 
-static void value_free_hash(CONF_VALUE *a, LHASH *conf)
+static void value_free_hash_doall_arg(CONF_VALUE *a, LHASH_OF(CONF_VALUE) *conf)
        {
        if (a->name != NULL)
-               {
-               a=(CONF_VALUE *)lh_delete(conf,a);
-               }
+               (void)lh_CONF_VALUE_delete(conf,a);
        }
 
-static void value_free_stack(CONF_VALUE *a, LHASH *conf)
+static void value_free_stack_doall(CONF_VALUE *a)
        {
        CONF_VALUE *vv;
-       STACK *sk;
+       STACK_OF(CONF_VALUE) *sk;
        int i;
 
        if (a->name != NULL) return;
 
-       sk=(STACK *)a->value;
-       for (i=sk_num(sk)-1; i>=0; i--)
+       sk=(STACK_OF(CONF_VALUE) *)a->value;
+       for (i=sk_CONF_VALUE_num(sk)-1; i>=0; i--)
                {
-               vv=(CONF_VALUE *)sk_value(sk,i);
+               vv=sk_CONF_VALUE_value(sk,i);
                OPENSSL_free(vv->value);
                OPENSSL_free(vv->name);
                OPENSSL_free(vv);
                }
-       if (sk != NULL) sk_free(sk);
+       if (sk != NULL) sk_CONF_VALUE_free(sk);
        OPENSSL_free(a->section);
        OPENSSL_free(a);
        }
 
-/* static unsigned long hash(CONF_VALUE *v) */
-static unsigned long hash(const void *v_void)
-       {
-       CONF_VALUE *v = (CONF_VALUE *)v_void;
-       return((lh_strhash(v->section)<<2)^lh_strhash(v->name));
-       }
-
-/* static int cmp_conf(CONF_VALUE *a, CONF_VALUE *b) */
-static int cmp_conf(const void *a_void,const  void *b_void)
-       {
-       int i;
-       CONF_VALUE *a = (CONF_VALUE *)a_void;
-       CONF_VALUE *b = (CONF_VALUE *)b_void;
-
-       if (a->section != b->section)
-               {
-               i=strcmp(a->section,b->section);
-               if (i) return(i);
-               }
-
-       if ((a->name != NULL) && (b->name != NULL))
-               {
-               i=strcmp(a->name,b->name);
-               return(i);
-               }
-       else if (a->name == b->name)
-               return(0);
-       else
-               return((a->name == NULL)?-1:1);
-       }
-
 /* Up until OpenSSL 0.9.5a, this was new_section */
 CONF_VALUE *_CONF_new_section(CONF *conf, const char *section)
        {
-       STACK *sk=NULL;
+       STACK_OF(CONF_VALUE) *sk=NULL;
        int ok=0,i;
        CONF_VALUE *v=NULL,*vv;
 
-       if ((sk=sk_new_null()) == NULL)
+       if ((sk=sk_CONF_VALUE_new_null()) == NULL)
                goto err;
-       if ((v=(CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE))) == NULL)
+       if ((v=OPENSSL_malloc(sizeof(CONF_VALUE))) == NULL)
                goto err;
        i=strlen(section)+1;
-       if ((v->section=(char *)OPENSSL_malloc(i)) == NULL)
+       if ((v->section=OPENSSL_malloc(i)) == NULL)
                goto err;
 
        memcpy(v->section,section,i);
        v->name=NULL;
        v->value=(char *)sk;
        
-       vv=(CONF_VALUE *)lh_insert(conf->data,v);
-       assert(vv == NULL);
+       vv=lh_CONF_VALUE_insert(conf->data,v);
+       OPENSSL_assert(vv == NULL);
        ok=1;
 err:
        if (!ok)
                {
-               if (sk != NULL) sk_free(sk);
+               if (sk != NULL) sk_CONF_VALUE_free(sk);
                if (v != NULL) OPENSSL_free(v);
                v=NULL;
                }
index 3c58936..cf95132 100644 (file)
@@ -129,7 +129,7 @@ static CONF *def_create(CONF_METHOD *meth)
        {
        CONF *ret;
 
-       ret = (CONF *)OPENSSL_malloc(sizeof(CONF) + sizeof(unsigned short *));
+       ret = OPENSSL_malloc(sizeof(CONF) + sizeof(unsigned short *));
        if (ret)
                if (meth->init(ret) == 0)
                        {
@@ -145,7 +145,7 @@ static int def_init_default(CONF *conf)
                return 0;
 
        conf->meth = &default_method;
-       conf->meth_data = (void *)CONF_type_default;
+       conf->meth_data = CONF_type_default;
        conf->data = NULL;
 
        return 1;
@@ -219,8 +219,6 @@ static int def_load_bio(CONF *conf, BIO *in, long *line)
        CONF_VALUE *v=NULL,*tv;
        CONF_VALUE *sv=NULL;
        char *section=NULL,*buf;
-/*     STACK_OF(CONF_VALUE) *section_sk=NULL;*/
-/*     STACK_OF(CONF_VALUE) *ts=NULL;*/
        char *start,*psection,*pname;
        void *h = (void *)(conf->data);
 
@@ -251,7 +249,6 @@ static int def_load_bio(CONF *conf, BIO *in, long *line)
                                        CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
                goto err;
                }
-/*     section_sk=(STACK_OF(CONF_VALUE) *)sv->value;*/
 
        bufnum=0;
        again=0;
@@ -343,7 +340,6 @@ again:
                                        CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
                                goto err;
                                }
-/*                     section_sk=(STACK_OF(CONF_VALUE) *)sv->value;*/
                        continue;
                        }
                else
@@ -406,13 +402,9 @@ again:
                                           CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
                                        goto err;
                                        }
-/*                             ts=(STACK_OF(CONF_VALUE) *)tv->value;*/
                                }
                        else
-                               {
                                tv=sv;
-/*                             ts=section_sk;*/
-                               }
 #if 1
                        if (_CONF_add_string(conf, tv, v) == 0)
                                {
@@ -719,7 +711,7 @@ static char *scan_dquote(CONF *conf, char *p)
        return(p);
        }
 
-static void dump_value(CONF_VALUE *a, BIO *out)
+static void dump_value_doall_arg(CONF_VALUE *a, BIO *out)
        {
        if (a->name)
                BIO_printf(out, "[%s] %s=%s\n", a->section, a->name, a->value);
@@ -727,11 +719,12 @@ static void dump_value(CONF_VALUE *a, BIO *out)
                BIO_printf(out, "[[%s]]\n", a->section);
        }
 
-static IMPLEMENT_LHASH_DOALL_ARG_FN(dump_value, CONF_VALUE *, BIO *)
+static IMPLEMENT_LHASH_DOALL_ARG_FN(dump_value, CONF_VALUE, BIO)
 
 static int def_dump(const CONF *conf, BIO *out)
        {
-       lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(dump_value), out);
+       lh_CONF_VALUE_doall_arg(conf->data, LHASH_DOALL_ARG_FN(dump_value),
+                               BIO, out);
        return 1;
        }
 
index a16a5e0..25bb5dc 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/conf/conf_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2007 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -75,6 +75,7 @@ static ERR_STRING_DATA CONF_str_functs[]=
 {ERR_FUNC(CONF_F_CONF_LOAD_BIO),       "CONF_load_bio"},
 {ERR_FUNC(CONF_F_CONF_LOAD_FP),        "CONF_load_fp"},
 {ERR_FUNC(CONF_F_CONF_MODULES_LOAD),   "CONF_modules_load"},
+{ERR_FUNC(CONF_F_CONF_PARSE_LIST),     "CONF_parse_list"},
 {ERR_FUNC(CONF_F_DEF_LOAD),    "DEF_LOAD"},
 {ERR_FUNC(CONF_F_DEF_LOAD_BIO),        "DEF_LOAD_BIO"},
 {ERR_FUNC(CONF_F_MODULE_INIT), "MODULE_INIT"},
@@ -97,6 +98,7 @@ static ERR_STRING_DATA CONF_str_functs[]=
 static ERR_STRING_DATA CONF_str_reasons[]=
        {
 {ERR_REASON(CONF_R_ERROR_LOADING_DSO)    ,"error loading dso"},
+{ERR_REASON(CONF_R_LIST_CANNOT_BE_NULL)  ,"list cannot be null"},
 {ERR_REASON(CONF_R_MISSING_CLOSE_SQUARE_BRACKET),"missing close square bracket"},
 {ERR_REASON(CONF_R_MISSING_EQUAL_SIGN)   ,"missing equal sign"},
 {ERR_REASON(CONF_R_MISSING_FINISH_FUNCTION),"missing finish function"},
index 2a3399d..54046de 100644 (file)
@@ -69,7 +69,7 @@ static CONF_METHOD *default_CONF_method=NULL;
 
 /* Init a 'CONF' structure from an old LHASH */
 
-void CONF_set_nconf(CONF *conf, LHASH *hash)
+void CONF_set_nconf(CONF *conf, LHASH_OF(CONF_VALUE) *hash)
        {
        if (default_CONF_method == NULL)
                default_CONF_method = NCONF_default();
@@ -87,9 +87,10 @@ int CONF_set_default_method(CONF_METHOD *meth)
        return 1;
        }
 
-LHASH *CONF_load(LHASH *conf, const char *file, long *eline)
+LHASH_OF(CONF_VALUE) *CONF_load(LHASH_OF(CONF_VALUE) *conf, const char *file,
+                               long *eline)
        {
-       LHASH *ltmp;
+       LHASH_OF(CONF_VALUE) *ltmp;
        BIO *in=NULL;
 
 #ifdef OPENSSL_SYS_VMS
@@ -110,10 +111,11 @@ LHASH *CONF_load(LHASH *conf, const char *file, long *eline)
        }
 
 #ifndef OPENSSL_NO_FP_API
-LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline)
+LHASH_OF(CONF_VALUE) *CONF_load_fp(LHASH_OF(CONF_VALUE) *conf, FILE *fp,
+                                  long *eline)
        {
        BIO *btmp;
-       LHASH *ltmp;
+       LHASH_OF(CONF_VALUE) *ltmp;
        if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) {
                CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB);
                return NULL;
@@ -124,7 +126,8 @@ LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline)
        }
 #endif
 
-LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline)
+LHASH_OF(CONF_VALUE) *CONF_load_bio(LHASH_OF(CONF_VALUE) *conf, BIO *bp,
+                                   long *eline)
        {
        CONF ctmp;
        int ret;
@@ -137,7 +140,8 @@ LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline)
        return NULL;
        }
 
-STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,const char *section)
+STACK_OF(CONF_VALUE) *CONF_get_section(LHASH_OF(CONF_VALUE) *conf,
+                                      const char *section)
        {
        if (conf == NULL)
                {
@@ -151,7 +155,8 @@ STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,const char *section)
                }
        }
 
-char *CONF_get_string(LHASH *conf,const char *group,const char *name)
+char *CONF_get_string(LHASH_OF(CONF_VALUE) *conf,const char *group,
+                     const char *name)
        {
        if (conf == NULL)
                {
@@ -165,7 +170,8 @@ char *CONF_get_string(LHASH *conf,const char *group,const char *name)
                }
        }
 
-long CONF_get_number(LHASH *conf,const char *group,const char *name)
+long CONF_get_number(LHASH_OF(CONF_VALUE) *conf,const char *group,
+                    const char *name)
        {
        int status;
        long result = 0;
@@ -189,7 +195,7 @@ long CONF_get_number(LHASH *conf,const char *group,const char *name)
        return result;
        }
 
-void CONF_free(LHASH *conf)
+void CONF_free(LHASH_OF(CONF_VALUE) *conf)
        {
        CONF ctmp;
        CONF_set_nconf(&ctmp, conf);
@@ -197,7 +203,7 @@ void CONF_free(LHASH *conf)
        }
 
 #ifndef OPENSSL_NO_FP_API
-int CONF_dump_fp(LHASH *conf, FILE *out)
+int CONF_dump_fp(LHASH_OF(CONF_VALUE) *conf, FILE *out)
        {
        BIO *btmp;
        int ret;
@@ -212,7 +218,7 @@ int CONF_dump_fp(LHASH *conf, FILE *out)
        }
 #endif
 
-int CONF_dump_bio(LHASH *conf, BIO *out)
+int CONF_dump_bio(LHASH_OF(CONF_VALUE) *conf, BIO *out)
        {
        CONF ctmp;
        CONF_set_nconf(&ctmp, conf);
index 1cc1fd5..c6f4cb2 100644 (file)
@@ -63,7 +63,6 @@
 #include <openssl/dso.h>
 #include <openssl/x509.h>
 #include <openssl/asn1.h>
-#include <openssl/evp.h>
 #ifndef OPENSSL_NO_ENGINE
 #include <openssl/engine.h>
 #endif
@@ -77,6 +76,5 @@ void OPENSSL_load_builtin_modules(void)
 #ifndef OPENSSL_NO_ENGINE
        ENGINE_add_conf_module();
 #endif
-       EVP_add_alg_module();
        }
 
index ee9c677..df1642a 100644 (file)
@@ -582,8 +582,14 @@ int CONF_parse_list(const char *list_, int sep, int nospc,
        {
        int ret;
        const char *lstart, *tmpend, *p;
-       lstart = list_;
 
+       if(list_ == NULL)
+               {
+               CONFerr(CONF_F_CONF_PARSE_LIST, CONF_R_LIST_CANNOT_BE_NULL);
+               return 0;
+               }
+
+       lstart = list_;
        for(;;)
                {
                if (nospc)
index 9fd41ff..139b928 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/cpt_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
index 497d003..387a987 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/cryptlib.c */
 /* ====================================================================
- * Copyright (c) 1998-2003 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 static double SSLeay_MSVC5_hack=0.0; /* and for VC1.5 */
 #endif
 
+DECLARE_STACK_OF(CRYPTO_dynlock)
+
+/* real #defines in crypto.h, keep these upto date */
+static const char* const lock_names[CRYPTO_NUM_LOCKS] =
+       {
+       "<<ERROR>>",
+       "err",
+       "ex_data",
+       "x509",
+       "x509_info",
+       "x509_pkey",
+       "x509_crl",
+       "x509_req",
+       "dsa",
+       "rsa",
+       "evp_pkey",
+       "x509_store",
+       "ssl_ctx",
+       "ssl_cert",
+       "ssl_session",
+       "ssl_sess_cert",
+       "ssl",
+       "ssl_method",
+       "rand",
+       "rand2",
+       "debug_malloc",
+       "BIO",
+       "gethostbyname",
+       "getservbyname",
+       "readdir",
+       "RSA_blinding",
+       "dh",
+       "debug_malloc2",
+       "dso",
+       "dynlock",
+       "engine",
+       "ui",
+       "ecdsa",
+       "ec",
+       "ecdh",
+       "bn",
+       "ec_pre_comp",
+       "store",
+       "comp",
+       "fips",
+       "fips2",
+#if CRYPTO_NUM_LOCKS != 41
+# error "Inconsistency between crypto.h and cryptlib.c"
+#endif
+       };
+
+/* This is for applications to allocate new type names in the non-dynamic
+   array of lock names.  These are numbered with positive numbers.  */
+static STACK_OF(OPENSSL_STRING) *app_locks=NULL;
+
+/* For applications that want a more dynamic way of handling threads, the
+   following stack is used.  These are externally numbered with negative
+   numbers.  */
+static STACK_OF(CRYPTO_dynlock) *dyn_locks=NULL;
+
+
 static void (MS_FAR *locking_callback)(int mode,int type,
-       const char *file,int line)=NULL;
+       const char *file,int line)=0;
 static int (MS_FAR *add_lock_callback)(int *pointer,int amount,
-       int type,const char *file,int line)=NULL;
-static unsigned long (MS_FAR *id_callback)(void)=NULL;
+       int type,const char *file,int line)=0;
+#ifndef OPENSSL_NO_DEPRECATED
+static unsigned long (MS_FAR *id_callback)(void)=0;
+#endif
+static void (MS_FAR *threadid_callback)(CRYPTO_THREADID *)=0;
+static struct CRYPTO_dynlock_value *(MS_FAR *dynlock_create_callback)
+       (const char *file,int line)=0;
+static void (MS_FAR *dynlock_lock_callback)(int mode,
+       struct CRYPTO_dynlock_value *l, const char *file,int line)=0;
+static void (MS_FAR *dynlock_destroy_callback)(struct CRYPTO_dynlock_value *l,
+       const char *file,int line)=0;
+
+int CRYPTO_get_new_lockid(char *name)
+       {
+       char *str;
+       int i;
+
+#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16)
+       /* A hack to make Visual C++ 5.0 work correctly when linking as
+        * a DLL using /MT. Without this, the application cannot use
+        * any floating point printf's.
+        * It also seems to be needed for Visual C 1.5 (win16) */
+       SSLeay_MSVC5_hack=(double)name[0]*(double)name[1];
+#endif
+
+       if ((app_locks == NULL) && ((app_locks=sk_OPENSSL_STRING_new_null()) == NULL))
+               {
+               CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID,ERR_R_MALLOC_FAILURE);
+               return(0);
+               }
+       if ((str=BUF_strdup(name)) == NULL)
+               {
+               CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID,ERR_R_MALLOC_FAILURE);
+               return(0);
+               }
+       i=sk_OPENSSL_STRING_push(app_locks,str);
+       if (!i)
+               OPENSSL_free(str);
+       else
+               i+=CRYPTO_NUM_LOCKS; /* gap of one :-) */
+       return(i);
+       }
 
 int CRYPTO_num_locks(void)
        {
        return CRYPTO_NUM_LOCKS;
        }
 
+int CRYPTO_get_new_dynlockid(void)
+       {
+       int i = 0;
+       CRYPTO_dynlock *pointer = NULL;
+
+       if (dynlock_create_callback == NULL)
+               {
+               CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,CRYPTO_R_NO_DYNLOCK_CREATE_CALLBACK);
+               return(0);
+               }
+       CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK);
+       if ((dyn_locks == NULL)
+               && ((dyn_locks=sk_CRYPTO_dynlock_new_null()) == NULL))
+               {
+               CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
+               CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,ERR_R_MALLOC_FAILURE);
+               return(0);
+               }
+       CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
+
+       pointer = (CRYPTO_dynlock *)OPENSSL_malloc(sizeof(CRYPTO_dynlock));
+       if (pointer == NULL)
+               {
+               CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,ERR_R_MALLOC_FAILURE);
+               return(0);
+               }
+       pointer->references = 1;
+       pointer->data = dynlock_create_callback(__FILE__,__LINE__);
+       if (pointer->data == NULL)
+               {
+               OPENSSL_free(pointer);
+               CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,ERR_R_MALLOC_FAILURE);
+               return(0);
+               }
+
+       CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK);
+       /* First, try to find an existing empty slot */
+       i=sk_CRYPTO_dynlock_find(dyn_locks,NULL);
+       /* If there was none, push, thereby creating a new one */
+       if (i == -1)
+               /* Since sk_push() returns the number of items on the
+                  stack, not the location of the pushed item, we need
+                  to transform the returned number into a position,
+                  by decreasing it.  */
+               i=sk_CRYPTO_dynlock_push(dyn_locks,pointer) - 1;
+       else
+               /* If we found a place with a NULL pointer, put our pointer
+                  in it.  */
+               (void)sk_CRYPTO_dynlock_set(dyn_locks,i,pointer);
+       CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
+
+       if (i == -1)
+               {
+               dynlock_destroy_callback(pointer->data,__FILE__,__LINE__);
+               OPENSSL_free(pointer);
+               }
+       else
+               i += 1; /* to avoid 0 */
+       return -i;
+       }
+
+void CRYPTO_destroy_dynlockid(int i)
+       {
+       CRYPTO_dynlock *pointer = NULL;
+       if (i)
+               i = -i-1;
+       if (dynlock_destroy_callback == NULL)
+               return;
+
+       CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK);
+
+       if (dyn_locks == NULL || i >= sk_CRYPTO_dynlock_num(dyn_locks))
+               {
+               CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
+               return;
+               }
+       pointer = sk_CRYPTO_dynlock_value(dyn_locks, i);
+       if (pointer != NULL)
+               {
+               --pointer->references;
+#ifdef REF_CHECK
+               if (pointer->references < 0)
+                       {
+                       fprintf(stderr,"CRYPTO_destroy_dynlockid, bad reference count\n");
+                       abort();
+                       }
+               else
+#endif
+                       if (pointer->references <= 0)
+                               {
+                               (void)sk_CRYPTO_dynlock_set(dyn_locks, i, NULL);
+                               }
+                       else
+                               pointer = NULL;
+               }
+       CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
+
+       if (pointer)
+               {
+               dynlock_destroy_callback(pointer->data,__FILE__,__LINE__);
+               OPENSSL_free(pointer);
+               }
+       }
+
+struct CRYPTO_dynlock_value *CRYPTO_get_dynlock_value(int i)
+       {
+       CRYPTO_dynlock *pointer = NULL;
+       if (i)
+               i = -i-1;
+
+       CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK);
+
+       if (dyn_locks != NULL && i < sk_CRYPTO_dynlock_num(dyn_locks))
+               pointer = sk_CRYPTO_dynlock_value(dyn_locks, i);
+       if (pointer)
+               pointer->references++;
+
+       CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
+
+       if (pointer)
+               return pointer->data;
+       return NULL;
+       }
+
+struct CRYPTO_dynlock_value *(*CRYPTO_get_dynlock_create_callback(void))
+       (const char *file,int line)
+       {
+       return(dynlock_create_callback);
+       }
+
+void (*CRYPTO_get_dynlock_lock_callback(void))(int mode,
+       struct CRYPTO_dynlock_value *l, const char *file,int line)
+       {
+       return(dynlock_lock_callback);
+       }
+
+void (*CRYPTO_get_dynlock_destroy_callback(void))
+       (struct CRYPTO_dynlock_value *l, const char *file,int line)
+       {
+       return(dynlock_destroy_callback);
+       }
+
+void CRYPTO_set_dynlock_create_callback(struct CRYPTO_dynlock_value *(*func)
+       (const char *file, int line))
+       {
+       dynlock_create_callback=func;
+       }
+
+void CRYPTO_set_dynlock_lock_callback(void (*func)(int mode,
+       struct CRYPTO_dynlock_value *l, const char *file, int line))
+       {
+       dynlock_lock_callback=func;
+       }
+
+void CRYPTO_set_dynlock_destroy_callback(void (*func)
+       (struct CRYPTO_dynlock_value *l, const char *file, int line))
+       {
+       dynlock_destroy_callback=func;
+       }
+
+
 void (*CRYPTO_get_locking_callback(void))(int mode,int type,const char *file,
                int line)
        {
@@ -156,6 +418,108 @@ void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,int type,
        add_lock_callback=func;
        }
 
+/* the memset() here and in set_pointer() seem overkill, but for the sake of
+ * CRYPTO_THREADID_cmp() this avoids any platform silliness that might cause two
+ * "equal" THREADID structs to not be memcmp()-identical. */
+void CRYPTO_THREADID_set_numeric(CRYPTO_THREADID *id, unsigned long val)
+       {
+       memset(id, 0, sizeof(*id));
+       id->val = val;
+       }
+
+static const unsigned char hash_coeffs[] = { 3, 5, 7, 11, 13, 17, 19, 23 };
+void CRYPTO_THREADID_set_pointer(CRYPTO_THREADID *id, void *ptr)
+       {
+       unsigned char *dest = (void *)&id->val;
+       unsigned int accum = 0;
+       unsigned char dnum = sizeof(id->val);
+
+       memset(id, 0, sizeof(*id));
+       id->ptr = ptr;
+       if (sizeof(id->val) >= sizeof(id->ptr))
+               {
+               /* 'ptr' can be embedded in 'val' without loss of uniqueness */
+               id->val = (unsigned long)id->ptr;
+               return;
+               }
+       /* hash ptr ==> val. Each byte of 'val' gets the mod-256 total of a
+        * linear function over the bytes in 'ptr', the co-efficients of which
+        * are a sequence of low-primes (hash_coeffs is an 8-element cycle) -
+        * the starting prime for the sequence varies for each byte of 'val'
+        * (unique polynomials unless pointers are >64-bit). For added spice,
+        * the totals accumulate rather than restarting from zero, and the index
+        * of the 'val' byte is added each time (position dependence). If I was
+        * a black-belt, I'd scan big-endian pointers in reverse to give
+        * low-order bits more play, but this isn't crypto and I'd prefer nobody
+        * mistake it as such. Plus I'm lazy. */
+       while (dnum--)
+               {
+               const unsigned char *src = (void *)&id->ptr;
+               unsigned char snum = sizeof(id->ptr);
+               while (snum--)
+                       accum += *(src++) * hash_coeffs[(snum + dnum) & 7];
+               accum += dnum;
+               *(dest++) = accum & 255;
+               }
+       }
+
+int CRYPTO_THREADID_set_callback(void (*func)(CRYPTO_THREADID *))
+       {
+       if (threadid_callback)
+               return 0;
+       threadid_callback = func;
+       return 1;
+       }
+
+void (*CRYPTO_THREADID_get_callback(void))(CRYPTO_THREADID *)
+       {
+       return threadid_callback;
+       }
+
+void CRYPTO_THREADID_current(CRYPTO_THREADID *id)
+       {
+       if (threadid_callback)
+               {
+               threadid_callback(id);
+               return;
+               }
+#ifndef OPENSSL_NO_DEPRECATED
+       /* If the deprecated callback was set, fall back to that */
+       if (id_callback)
+               {
+               CRYPTO_THREADID_set_numeric(id, id_callback());
+               return;
+               }
+#endif
+       /* Else pick a backup */
+#ifdef OPENSSL_SYS_WIN16
+       CRYPTO_THREADID_set_numeric(id, (unsigned long)GetCurrentTask());
+#elif defined(OPENSSL_SYS_WIN32)
+       CRYPTO_THREADID_set_numeric(id, (unsigned long)GetCurrentThreadId());
+#elif defined(OPENSSL_SYS_BEOS)
+       CRYPTO_THREADID_set_numeric(id, (unsigned long)find_thread(NULL));
+#else
+       /* For everything else, default to using the address of 'errno' */
+       CRYPTO_THREADID_set_pointer(id, &errno);
+#endif
+       }
+
+int CRYPTO_THREADID_cmp(const CRYPTO_THREADID *a, const CRYPTO_THREADID *b)
+       {
+       return memcmp(a, b, sizeof(*a));
+       }
+
+void CRYPTO_THREADID_cpy(CRYPTO_THREADID *dest, const CRYPTO_THREADID *src)
+       {
+       memcpy(dest, src, sizeof(*src));
+       }
+
+unsigned long CRYPTO_THREADID_hash(const CRYPTO_THREADID *id)
+       {
+       return id->val;
+       }
+
+#ifndef OPENSSL_NO_DEPRECATED
 unsigned long (*CRYPTO_get_id_callback(void))(void)
        {
        return(id_callback);
@@ -178,6 +542,8 @@ unsigned long CRYPTO_thread_id(void)
                ret=(unsigned long)GetCurrentThreadId();
 #elif defined(GETPID_IS_MEANINGLESS)
                ret=1L;
+#elif defined(OPENSSL_SYS_BEOS)
+               ret=(unsigned long)find_thread(NULL);
 #else
                ret=(unsigned long)getpid();
 #endif
@@ -186,19 +552,13 @@ unsigned long CRYPTO_thread_id(void)
                ret=id_callback();
        return(ret);
        }
-
-static void (*do_dynlock_cb)(int mode, int type, const char *file, int line);
-
-void int_CRYPTO_set_do_dynlock_callback(
-       void (*dyn_cb)(int mode, int type, const char *file, int line))
-       {
-       do_dynlock_cb = dyn_cb;
-       }
+#endif
 
 void CRYPTO_lock(int mode, int type, const char *file, int line)
        {
 #ifdef LOCK_DEBUG
                {
+               CRYPTO_THREADID id;
                char *rw_text,*operation_text;
 
                if (mode & CRYPTO_LOCK)
@@ -215,15 +575,25 @@ void CRYPTO_lock(int mode, int type, const char *file, int line)
                else
                        rw_text="ERROR";
 
+               CRYPTO_THREADID_current(&id);
                fprintf(stderr,"lock:%08lx:(%s)%s %-18s %s:%d\n",
-                       CRYPTO_thread_id(), rw_text, operation_text,
+                       CRYPTO_THREADID_hash(&id), rw_text, operation_text,
                        CRYPTO_get_lock_name(type), file, line);
                }
 #endif
        if (type < 0)
                {
-               if (do_dynlock_cb)
-                       do_dynlock_cb(mode, type, file, line);
+               if (dynlock_lock_callback != NULL)
+                       {
+                       struct CRYPTO_dynlock_value *pointer
+                               = CRYPTO_get_dynlock_value(type);
+
+                       OPENSSL_assert(pointer != NULL);
+
+                       dynlock_lock_callback(mode, pointer, file, line);
+
+                       CRYPTO_destroy_dynlockid(type);
+                       }
                }
        else
                if (locking_callback != NULL)
@@ -243,11 +613,14 @@ int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,
 
                ret=add_lock_callback(pointer,amount,type,file,line);
 #ifdef LOCK_DEBUG
+               {
+               CRYPTO_THREADID id;
+               CRYPTO_THREADID_current(&id);
                fprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",
-                       CRYPTO_thread_id(),
-                       before,amount,ret,
+                       CRYPTO_THREADID_hash(&id), before,amount,ret,
                        CRYPTO_get_lock_name(type),
                        file,line);
+               }
 #endif
                }
        else
@@ -256,11 +629,15 @@ int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,
 
                ret= *pointer+amount;
 #ifdef LOCK_DEBUG
+               {
+               CRYPTO_THREADID id;
+               CRYPTO_THREADID_current(&id);
                fprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",
-                       CRYPTO_thread_id(),
+                       CRYPTO_THREADID_hash(&id),
                        *pointer,amount,ret,
                        CRYPTO_get_lock_name(type),
                        file,line);
+               }
 #endif
                *pointer=ret;
                CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,file,line);
@@ -268,6 +645,18 @@ int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,
        return(ret);
        }
 
+const char *CRYPTO_get_lock_name(int type)
+       {
+       if (type < 0)
+               return("dynamic");
+       else if (type < CRYPTO_NUM_LOCKS)
+               return(lock_names[type]);
+       else if (type-CRYPTO_NUM_LOCKS > sk_OPENSSL_STRING_num(app_locks))
+               return("ERROR");
+       else
+               return(sk_OPENSSL_STRING_value(app_locks,type-CRYPTO_NUM_LOCKS));
+       }
+
 #if    defined(__i386)   || defined(__i386__)   || defined(_M_IX86) || \
        defined(__INTEL__) || \
        defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64)
@@ -306,65 +695,11 @@ void OPENSSL_cpuid_setup(void) {}
 #endif
 
 #if (defined(_WIN32) || defined(__CYGWIN__)) && defined(_WINDLL)
-
-#ifdef OPENSSL_FIPS
-
-#include <tlhelp32.h>
-#if defined(__GNUC__) && __GNUC__>=2
-static int DllInit(void) __attribute__((constructor));
-#elif defined(_MSC_VER)
-static int DllInit(void);
-# ifdef _WIN64
-# pragma section(".CRT$XCU",read)
-  __declspec(allocate(".CRT$XCU"))
-# else
-# pragma data_seg(".CRT$XCU")
-# endif
-  static int (*p)(void) = DllInit;
-# pragma data_seg()
-#endif
-
-static int DllInit(void)
-{
-#if defined(_WIN32_WINNT)
-       union   { int(*f)(void); BYTE *p; } t = { DllInit };
-        HANDLE hModuleSnap = INVALID_HANDLE_VALUE;
-       IMAGE_DOS_HEADER *dos_header;
-       IMAGE_NT_HEADERS *nt_headers;
-       MODULEENTRY32 me32 = {sizeof(me32)};
-
-       hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,0);
-       if (hModuleSnap != INVALID_HANDLE_VALUE &&
-           Module32First(hModuleSnap,&me32)) do
-               {
-               if (t.p >= me32.modBaseAddr &&
-                   t.p <  me32.modBaseAddr+me32.modBaseSize)
-                       {
-                       dos_header=(IMAGE_DOS_HEADER *)me32.modBaseAddr;
-                       if (dos_header->e_magic==IMAGE_DOS_SIGNATURE)
-                               {
-                               nt_headers=(IMAGE_NT_HEADERS *)
-                                       ((BYTE *)dos_header+dos_header->e_lfanew);
-                               if (nt_headers->Signature==IMAGE_NT_SIGNATURE &&
-                                   me32.modBaseAddr!=(BYTE*)nt_headers->OptionalHeader.ImageBase)
-                                       OPENSSL_NONPIC_relocated=1;
-                               }
-                       break;
-                       }
-               } while (Module32Next(hModuleSnap,&me32));
-
-       if (hModuleSnap != INVALID_HANDLE_VALUE)
-               CloseHandle(hModuleSnap);
-#endif
-       OPENSSL_cpuid_setup();
-       return 0;
-}
-
-#else
-
 #ifdef __CYGWIN__
 /* pick DLL_[PROCESS|THREAD]_[ATTACH|DETACH] definitions */
 #include <windows.h>
+/* this has side-effect of _WIN32 getting defined, which otherwise
+ * is mutually exclusive with __CYGWIN__... */
 #endif
 
 /* All we really need to do is remove the 'error' state when a thread
@@ -396,7 +731,6 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
        case DLL_THREAD_ATTACH:
                break;
        case DLL_THREAD_DETACH:
-               ERR_remove_state(0);
                break;
        case DLL_PROCESS_DETACH:
                break;
@@ -405,16 +739,37 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
        }
 #endif
 
-#endif
-
 #if defined(_WIN32) && !defined(__CYGWIN__)
 #include <tchar.h>
+#include <signal.h>
+#ifdef __WATCOMC__
+#if defined(_UNICODE) || defined(__UNICODE__)
+#define _vsntprintf _vsnwprintf
+#else
+#define _vsntprintf _vsnprintf
+#endif
+#endif
+#ifdef _MSC_VER
+#define alloca _alloca
+#endif
 
 #if defined(_WIN32_WINNT) && _WIN32_WINNT>=0x0333
 int OPENSSL_isservice(void)
 { HWINSTA h;
   DWORD len;
   WCHAR *name;
+  static union { void *p; int (*f)(void); } _OPENSSL_isservice = { NULL };
+
+    if (_OPENSSL_isservice.p == NULL) {
+       HANDLE h = GetModuleHandle(NULL);
+       if (h != NULL)
+           _OPENSSL_isservice.p = GetProcAddress(h,"_OPENSSL_isservice");
+       if (_OPENSSL_isservice.p == NULL)
+           _OPENSSL_isservice.p = (void *)-1;
+    }
+
+    if (_OPENSSL_isservice.p != (void *)-1)
+       return (*_OPENSSL_isservice.f)();
 
     (void)GetDesktopWindow(); /* return value is ignored */
 
@@ -427,11 +782,7 @@ int OPENSSL_isservice(void)
 
     if (len>512) return -1;            /* paranoia */
     len++,len&=~1;                     /* paranoia */
-#ifdef _MSC_VER
-    name=(WCHAR *)_alloca(len+sizeof(WCHAR));
-#else
     name=(WCHAR *)alloca(len+sizeof(WCHAR));
-#endif
     if (!GetUserObjectInformationW (h,UOI_NAME,name,len,&len))
        return -1;
 
@@ -476,11 +827,7 @@ void OPENSSL_showfatal (const char *fmta,...)
       size_t len_0=strlen(fmta)+1,i;
       WCHAR *fmtw;
 
-#ifdef _MSC_VER
-       fmtw = (WCHAR *)_alloca (len_0*sizeof(WCHAR));
-#else
-       fmtw = (WCHAR *)alloca (len_0*sizeof(WCHAR));
-#endif
+       fmtw = (WCHAR *)alloca(len_0*sizeof(WCHAR));
        if (fmtw == NULL) { fmt=(const TCHAR *)L"no stack?"; break; }
 
 #ifndef OPENSSL_NO_MULTIBYTE
@@ -539,7 +886,13 @@ void OpenSSLDie(const char *file,int line,const char *assertion)
        OPENSSL_showfatal(
                "%s(%d): OpenSSL internal error, assertion failed: %s\n",
                file,line,assertion);
+#if !defined(_WIN32) || defined(__CYGWIN__)
        abort();
+#else
+       /* Win32 abort() customarily shows a dialog, but we just did that... */
+       raise(SIGABRT);
+       _exit(3);
+#endif
        }
 
 void *OPENSSL_stderr(void)     { return stderr; }
index ff847b5..a29c0af 100644 (file)
@@ -47,11 +47,33 @@ $!  P6, if defined, sets a choice of crypto methods to compile.
 $!  WARNING: this should only be done to recompile some part of an already
 $!  fully compiled library.
 $!
+$!  P7, if defined, specifies the C pointer size.  Ignored on VAX.
+$!      ("64=ARGV" gives more efficient code with HP C V7.3 or newer.)
+$!      Supported values are:
+$!
+$!      ""       Compile with default (/NOPOINTER_SIZE)
+$!      32       Compile with /POINTER_SIZE=32 (SHORT)
+$!      64       Compile with /POINTER_SIZE=64[=ARGV] (LONG[=ARGV]).
+$!               (Automatically select ARGV if compiler supports it.)
+$!      64=      Compile with /POINTER_SIZE=64 (LONG).
+$!      64=ARGV  Compile with /POINTER_SIZE=64=ARGV (LONG=ARGV).
+$!
+$!  P8, if defined, specifies a directory where ZLIB files (zlib.h,
+$!  libz.olb) may be found.  Optionally, a non-default object library
+$!  name may be included ("dev:[dir]libz_64.olb", for example).
+$!
+$!
+$! Announce/identify.
+$!
+$ proc = f$environment( "procedure")
+$ write sys$output "@@@ "+ -
+   f$parse( proc, , , "name")+ f$parse( proc, , , "type")
 $!
 $! Define A TCP/IP Library That We Will Need To Link To.
 $! (That Is, If We Need To Link To One.)
 $!
 $ TCPIP_LIB = ""
+$ ZLIB_LIB = ""
 $!
 $! Check Which Architecture We Are Using.
 $!
@@ -60,7 +82,7 @@ $ THEN
 $!
 $!  The Architecture Is VAX
 $!
-$   ARCH := VAX
+$   ARCH = "VAX"
 $!
 $! Else...
 $!
@@ -75,31 +97,50 @@ $! End The Architecture Check.
 $!
 $ ENDIF
 $!
+$ ARCHD = ARCH
+$ LIB32 = "32"
+$ OPT_FILE = ""
+$ POINTER_SIZE = ""
+$!
 $! Define The Different Encryption Types.
 $! NOTE: Some might think this list ugly.  However, it's made this way to
 $! reflect the SDIRS variable in [-]Makefile.org as closely as possible,
 $! thereby making it fairly easy to verify that the lists are the same.
 $!
+$ ET_WHIRLPOOL = "WHRLPOOL"
+$ IF ARCH .EQS. "VAX" THEN ET_WHIRLPOOL = ""
 $ ENCRYPT_TYPES = "Basic,"+ -
                  "OBJECTS,"+ -
-                 "MD2,MD4,MD5,SHA,MDC2,HMAC,RIPEMD,"+ -
-                 "DES,RC2,RC4,RC5,IDEA,BF,CAST,CAMELLIA,SEED,"+ -
-                 "BN,EC,RSA,DSA,ECDSA,DH,ECDH,DSO,ENGINE,AES,"+ -
+                 "MD2,MD4,MD5,SHA,MDC2,HMAC,RIPEMD,"+ET_WHIRLPOOL+","+ -
+                 "DES,AES,RC2,RC4,RC5,IDEA,BF,CAST,CAMELLIA,SEED,MODES,"+ -
+                 "BN,EC,RSA,DSA,ECDSA,DH,ECDH,DSO,ENGINE,"+ -
                  "BUFFER,BIO,STACK,LHASH,RAND,ERR,"+ -
-                 "EVP,EVP_2,ASN1,ASN1_2,PEM,X509,X509V3,"+ -
+                 "EVP,EVP_2,EVP_3,ASN1,ASN1_2,PEM,X509,X509V3,"+ -
                  "CONF,TXT_DB,PKCS7,PKCS12,COMP,OCSP,UI,KRB5,"+ -
-                 "STORE,CMS,PQUEUE,JPAKE"
-$! Define The OBJ Directory.
+                 "STORE,CMS,PQUEUE,TS,JPAKE"
+$!
+$! Check To Make Sure We Have Valid Command Line Parameters.
 $!
-$ OBJ_DIR := SYS$DISK:[-.'ARCH'.OBJ.CRYPTO]
+$ GOSUB CHECK_OPTIONS
 $!
-$! Define The EXE Directory.
+$! Define The OBJ and EXE Directories.
 $!
-$ EXE_DIR := SYS$DISK:[-.'ARCH'.EXE.CRYPTO]
+$ OBJ_DIR := SYS$DISK:[-.'ARCHD'.OBJ.CRYPTO]
+$ EXE_DIR := SYS$DISK:[-.'ARCHD'.EXE.CRYPTO]
 $!
-$! Check To Make Sure We Have Valid Command Line Parameters.
+$! Specify the destination directory in any /MAP option.
 $!
-$ GOSUB CHECK_OPTIONS
+$ if (LINKMAP .eqs. "MAP")
+$ then
+$   LINKMAP = LINKMAP+ "=''EXE_DIR'"
+$ endif
+$!
+$! Add the location prefix to the linker options file name.
+$!
+$ if (OPT_FILE .nes. "")
+$ then
+$   OPT_FILE = EXE_DIR+ OPT_FILE
+$ endif
 $!
 $! Initialise logical names and such
 $!
@@ -107,7 +148,7 @@ $ GOSUB INITIALISE
 $!
 $! Tell The User What Kind of Machine We Run On.
 $!
-$ WRITE SYS$OUTPUT "Compiling On A ",ARCH," Machine."
+$ WRITE SYS$OUTPUT "Host system architecture: ''ARCHD'"
 $!
 $!
 $! Check To See If The Architecture Specific OBJ Directory Exists.
@@ -138,11 +179,11 @@ $ ENDIF
 $!
 $! Define The Library Name.
 $!
-$ LIB_NAME := 'EXE_DIR'LIBCRYPTO.OLB
+$ LIB_NAME := 'EXE_DIR'SSL_LIBCRYPTO'LIB32'.OLB
 $!
 $! Define The CRYPTO-LIB We Are To Use.
 $!
-$ CRYPTO_LIB := 'EXE_DIR'LIBCRYPTO.OLB
+$ CRYPTO_LIB := 'EXE_DIR'SSL_LIBCRYPTO'LIB32'.OLB
 $!
 $! Check To See If We Already Have A "[.xxx.EXE.CRYPTO]LIBCRYPTO.OLB" Library...
 $!
@@ -166,15 +207,16 @@ $!
 $ APPS_DES = "DES/DES,CBC3_ENC"
 $ APPS_PKCS7 = "ENC/ENC;DEC/DEC;SIGN/SIGN;VERIFY/VERIFY,EXAMPLE"
 $
-$ LIB_ = "cryptlib,dyn_lck,mem,mem_clr,mem_dbg,cversion,ex_data,tmdiff,cpt_err,ebcdic,uid,o_time,o_str,o_dir,o_init,fips_err"
+$ LIB_ = "cryptlib,mem,mem_clr,mem_dbg,cversion,ex_data,cpt_err,ebcdic,uid,o_time,o_str,o_dir"
 $ LIB_MD2 = "md2_dgst,md2_one"
 $ LIB_MD4 = "md4_dgst,md4_one"
 $ LIB_MD5 = "md5_dgst,md5_one"
 $ LIB_SHA = "sha_dgst,sha1dgst,sha_one,sha1_one,sha256,sha512"
 $ LIB_MDC2 = "mdc2dgst,mdc2_one"
-$ LIB_HMAC = "hmac"
+$ LIB_HMAC = "hmac,hm_ameth,hm_pmeth"
 $ LIB_RIPEMD = "rmd_dgst,rmd_one"
-$ LIB_DES = "des_lib,set_key,ecb_enc,cbc_enc,"+ -
+$ LIB_WHRLPOOL = "wp_dgst,wp_block"
+$ LIB_DES = "set_key,ecb_enc,cbc_enc,"+ -
        "ecb3_enc,cfb64enc,cfb64ede,cfb_enc,ofb64ede,"+ -
        "enc_read,enc_writ,ofb64enc,"+ -
        "ofb_enc,str2key,pcbc_enc,qud_cksm,rand_key,"+ -
@@ -189,7 +231,8 @@ $ LIB_BF = "bf_skey,bf_ecb,bf_enc,bf_cfb64,bf_ofb64"
 $ LIB_CAST = "c_skey,c_ecb,c_enc,c_cfb64,c_ofb64"
 $ LIB_CAMELLIA = "camellia,cmll_misc,cmll_ecb,cmll_cbc,cmll_ofb,"+ -
        "cmll_cfb,cmll_ctr"
-$ LIB_SEED = "seed,seed_cbc,seed_ecb,seed_cfb,seed_ofb"
+$ LIB_SEED = "seed,seed_ecb,seed_cbc,seed_cfb,seed_ofb"
+$ LIB_MODES = "cbc128,ctr128,cts128,cfb128,ofb128"
 $ LIB_BN_ASM = "[.asm]vms.mar,vms-helper"
 $ IF F$TRNLNM("OPENSSL_NO_ASM") .OR. ARCH .NES. "VAX" THEN -
      LIB_BN_ASM = "bn_asm"
@@ -197,28 +240,30 @@ $ LIB_BN = "bn_add,bn_div,bn_exp,bn_lib,bn_ctx,bn_mul,bn_mod,"+ -
        "bn_print,bn_rand,bn_shift,bn_word,bn_blind,"+ -
        "bn_kron,bn_sqrt,bn_gcd,bn_prime,bn_err,bn_sqr,"+LIB_BN_ASM+","+ -
        "bn_recp,bn_mont,bn_mpi,bn_exp2,bn_gf2m,bn_nist,"+ -
-       "bn_depr,bn_x931p,bn_const,bn_opt"
+       "bn_depr,bn_const"
 $ LIB_EC = "ec_lib,ecp_smpl,ecp_mont,ecp_nist,ec_cvt,ec_mult,"+ -
        "ec_err,ec_curve,ec_check,ec_print,ec_asn1,ec_key,"+ -
-       "ec2_smpl,ec2_mult"
+       "ec2_smpl,ec2_mult,ec_ameth,ec_pmeth,eck_prn"
 $ LIB_RSA = "rsa_eay,rsa_gen,rsa_lib,rsa_sign,rsa_saos,rsa_err,"+ -
        "rsa_pk1,rsa_ssl,rsa_none,rsa_oaep,rsa_chk,rsa_null,"+ -
-       "rsa_pss,rsa_x931,rsa_x931g,rsa_asn1,rsa_depr,rsa_eng"
+       "rsa_pss,rsa_x931,rsa_asn1,rsa_depr,rsa_ameth,rsa_prn,"+ -
+       "rsa_pmeth"
 $ LIB_DSA = "dsa_gen,dsa_key,dsa_lib,dsa_asn1,dsa_vrf,dsa_sign,"+ -
-       "dsa_err,dsa_ossl,dsa_depr,dsa_utl"
+       "dsa_err,dsa_ossl,dsa_depr,dsa_ameth,dsa_pmeth,dsa_prn"
 $ LIB_ECDSA = "ecs_lib,ecs_asn1,ecs_ossl,ecs_sign,ecs_vrf,ecs_err"
-$ LIB_DH = "dh_asn1,dh_gen,dh_key,dh_lib,dh_check,dh_err,dh_depr"
+$ LIB_DH = "dh_asn1,dh_gen,dh_key,dh_lib,dh_check,dh_err,dh_depr,"+ -
+       "dh_ameth,dh_pmeth,dh_prn"
 $ LIB_ECDH = "ech_lib,ech_ossl,ech_key,ech_err"
 $ LIB_DSO = "dso_dl,dso_dlfcn,dso_err,dso_lib,dso_null,"+ -
-       "dso_openssl,dso_win32,dso_vms"
+       "dso_openssl,dso_win32,dso_vms,dso_beos"
 $ LIB_ENGINE = "eng_err,eng_lib,eng_list,eng_init,eng_ctrl,"+ -
        "eng_table,eng_pkey,eng_fat,eng_all,"+ -
        "tb_rsa,tb_dsa,tb_ecdsa,tb_dh,tb_ecdh,tb_rand,tb_store,"+ -
-       "tb_cipher,tb_digest,"+ -
-       "eng_openssl,eng_dyn,eng_cnf,eng_cryptodev,eng_padlock"
-$ LIB_AES = "aes_core,aes_misc,aes_ecb,aes_cbc,aes_cfb,aes_ofb,"+ -
-       "aes_ctr,aes_ige,aes_wrap"
-$ LIB_BUFFER = "buffer,buf_str,buf_err"
+       "tb_cipher,tb_digest,tb_pkmeth,tb_asnmth,"+ -
+       "eng_openssl,eng_dyn,eng_cnf,eng_cryptodev"
+$ LIB_AES = "aes_core,aes_misc,aes_ecb,aes_cbc,aes_cfb,aes_ofb,aes_ctr,"+ -
+       "aes_ige,aes_wrap"
+$ LIB_BUFFER = "buffer,buf_err"
 $ LIB_BIO = "bio_lib,bio_cb,bio_err,"+ -
        "bss_mem,bss_null,bss_fd,"+ -
        "bss_file,bss_sock,bss_conn,"+ -
@@ -230,33 +275,34 @@ $ LIB_STACK = "stack"
 $ LIB_LHASH = "lhash,lh_stats"
 $ LIB_RAND = "md_rand,randfile,rand_lib,rand_err,rand_egd,"+ -
        "rand_vms"
-$ LIB_ERR = "err,err_def,err_all,err_prn,err_str,err_bio"
-$ LIB_OBJECTS = "o_names,obj_dat,obj_lib,obj_err"
-$ LIB_EVP = "encode,digest,dig_eng,evp_enc,evp_key,evp_acnf,evp_cnf,"+ -
+$ LIB_ERR = "err,err_all,err_prn"
+$ LIB_OBJECTS = "o_names,obj_dat,obj_lib,obj_err,obj_xref"
+$ LIB_EVP = "encode,digest,evp_enc,evp_key,evp_acnf,"+ -
        "e_des,e_bf,e_idea,e_des3,e_camellia,"+ -
        "e_rc4,e_aes,names,e_seed,"+ -
-       "e_xcbc_d,e_rc2,e_cast,e_rc5,enc_min"
-$ LIB_EVP_2 = "m_null,m_md2,m_md4,m_md5,m_sha,m_sha1," + -
+       "e_xcbc_d,e_rc2,e_cast,e_rc5"
+$ LIB_EVP_2 = "m_null,m_md2,m_md4,m_md5,m_sha,m_sha1,m_wp," + -
        "m_dss,m_dss1,m_mdc2,m_ripemd,m_ecdsa,"+ -
        "p_open,p_seal,p_sign,p_verify,p_lib,p_enc,p_dec,"+ -
        "bio_md,bio_b64,bio_enc,evp_err,e_null,"+ -
        "c_all,c_allc,c_alld,evp_lib,bio_ok,"+-
        "evp_pkey,evp_pbe,p5_crpt,p5_crpt2"
-$ LIB_EVP_3 = "e_old"
+$ LIB_EVP_3 = "e_old,pmeth_lib,pmeth_fn,pmeth_gn,m_sigver"
 $ LIB_ASN1 = "a_object,a_bitstr,a_utctm,a_gentm,a_time,a_int,a_octet,"+ -
        "a_print,a_type,a_set,a_dup,a_d2i_fp,a_i2d_fp,"+ -
        "a_enum,a_utf8,a_sign,a_digest,a_verify,a_mbstr,a_strex,"+ -
        "x_algor,x_val,x_pubkey,x_sig,x_req,x_attrib,x_bignum,"+ -
        "x_long,x_name,x_x509,x_x509a,x_crl,x_info,x_spki,nsseq,"+ -
-       "d2i_pu,d2i_pr,i2d_pu,i2d_pr"
+       "x_nx509,d2i_pu,d2i_pr,i2d_pu,i2d_pr"
 $ LIB_ASN1_2 = "t_req,t_x509,t_x509a,t_crl,t_pkey,t_spki,t_bitst,"+ -
        "tasn_new,tasn_fre,tasn_enc,tasn_dec,tasn_utl,tasn_typ,"+ -
+       "tasn_prn,ameth_lib,"+ -
        "f_int,f_string,n_pkey,"+ -
-       "f_enum,a_hdr,x_pkey,a_bool,x_exten,asn_mime,"+ -
-       "asn1_gen,asn1_par,asn1_lib,asn1_err,a_meth,a_bytes,a_strnid,"+ -
+       "f_enum,x_pkey,a_bool,x_exten,bio_asn1,bio_ndef,asn_mime,"+ -
+       "asn1_gen,asn1_par,asn1_lib,asn1_err,a_bytes,a_strnid,"+ -
        "evp_asn1,asn_pack,p5_pbe,p5_pbev2,p8_pkey,asn_moid"
 $ LIB_PEM = "pem_sign,pem_seal,pem_info,pem_lib,pem_all,pem_err,"+ -
-       "pem_x509,pem_xaux,pem_oth,pem_pk8,pem_pkey"
+       "pem_x509,pem_xaux,pem_oth,pem_pk8,pem_pkey,pvkfmt"
 $ LIB_X509 = "x509_def,x509_d2,x509_r2x,x509_cmp,"+ -
        "x509_obj,x509_req,x509spki,x509_vfy,"+ -
        "x509_set,x509cset,x509rset,x509_err,"+ -
@@ -272,7 +318,7 @@ $ LIB_X509V3 = "v3_bcons,v3_bitst,v3_conf,v3_extku,v3_ia5,v3_lib,"+ -
 $ LIB_CONF = "conf_err,conf_lib,conf_api,conf_def,conf_mod,conf_mall,conf_sap"
 $ LIB_TXT_DB = "txt_db"
 $ LIB_PKCS7 = "pk7_asn1,pk7_lib,pkcs7err,pk7_doit,pk7_smime,pk7_attr,"+ -
-       "pk7_mime"
+       "pk7_mime,bio_pk7"
 $ LIB_PKCS12 = "p12_add,p12_asn,p12_attr,p12_crpt,p12_crt,p12_decr,"+ -
        "p12_init,p12_key,p12_kiss,p12_mutl,"+ -
        "p12_utl,p12_npas,pk12err,p12_p8d,p12_p8e"
@@ -287,19 +333,30 @@ $ LIB_STORE = "str_err,str_lib,str_meth,str_mem"
 $ LIB_CMS = "cms_lib,cms_asn1,cms_att,cms_io,cms_smime,cms_err,"+ -
        "cms_sd,cms_dd,cms_cd,cms_env,cms_enc,cms_ess"
 $ LIB_PQUEUE = "pqueue"
+$ LIB_TS = "ts_err,ts_req_utils,ts_req_print,ts_rsp_utils,ts_rsp_print,"+ -
+       "ts_rsp_sign,ts_rsp_verify,ts_verify_ctx,ts_lib,ts_conf,"+ -
+       "ts_asn1"
 $ LIB_JPAKE = "jpake,jpake_err"
 $!
 $! Setup exceptional compilations
 $!
-$ ! Add definitions for no threads on OpenVMS 7.1 and higher
+$ CC3_SHOWN = 0
+$ CC4_SHOWN = 0
+$ CC5_SHOWN = 0
+$ CC6_SHOWN = 0
+$!
+$! The following lists must have leading and trailing commas, and no
+$! embedded spaces.  (They are scanned for ",name,".)
+$!
+$ ! Add definitions for no threads on OpenVMS 7.1 and higher.
 $ COMPILEWITH_CC3 = ",bss_rtcp,"
-$ ! Disable the DOLLARID warning
-$ COMPILEWITH_CC4 = ",a_utctm,bss_log,o_time,o_dir"
-$ ! Disable disjoint optimization
+$ ! Disable the DOLLARID warning.  Not needed with /STANDARD=RELAXED.
+$ COMPILEWITH_CC4 = "" !!! ",a_utctm,bss_log,o_time,o_dir,"
+$ ! Disable disjoint optimization on VAX with DECC.
 $ COMPILEWITH_CC5 = ",md2_dgst,md4_dgst,md5_dgst,mdc2dgst," + -
                     "seed,sha_dgst,sha1dgst,rmd_dgst,bf_enc,"
-$ ! Disable the MIXLINKAGE warning
-$ COMPILEWITH_CC6 = ",enc_read,set_key,"
+$ ! Disable the MIXLINKAGE warning.
+$ COMPILEWITH_CC6 = "" !!! ",enc_read,set_key,"
 $!
 $! Figure Out What Other Modules We Are To Build.
 $!
@@ -359,7 +416,7 @@ $!
 $ IF F$TYPE('LIB_MODULE') .EQS. ""
 $ THEN
 $   WRITE SYS$ERROR ""
-$   WRITE SYS$ERROR "The module ",MODULE_NAME," does not exist.  Continuing..."
+$   WRITE SYS$ERROR "The module ",MODULE_NAME1," does not exist.  Continuing..."
 $   WRITE SYS$ERROR ""
 $   GOTO MODULE_NEXT
 $ ENDIF
@@ -505,31 +562,60 @@ $   WRITE SYS$OUTPUT "Compiling The ",FILE_NAME," File.  (",BUILDALL,",",STATE,"
 $ ENDIF
 $ IF (MODULE_NAME.NES."")
 $ THEN 
-$   WRITE SYS$OUTPUT " ",FILE_NAME,""
+$   WRITE SYS$OUTPUT "        ",FILE_NAME,""
 $ ENDIF
 $!
 $! Compile The File.
 $!
 $ ON ERROR THEN GOTO NEXT_FILE
-$ FILE_NAME0 = F$ELEMENT(0,".",FILE_NAME)
+$ FILE_NAME0 = ","+ F$ELEMENT(0,".",FILE_NAME)+ ","
 $ IF FILE_NAME - ".mar" .NES. FILE_NAME
 $ THEN
 $   MACRO/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
 $ ELSE
 $   IF COMPILEWITH_CC3 - FILE_NAME0 .NES. COMPILEWITH_CC3
 $   THEN
+$     write sys$output "        \Using special rule (3)"
+$     if (.not. CC3_SHOWN)
+$     then
+$       CC3_SHOWN = 1
+$       x = "    "+ CC3
+$       write /symbol sys$output x
+$     endif
 $     CC3/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
 $   ELSE
 $     IF COMPILEWITH_CC4 - FILE_NAME0 .NES. COMPILEWITH_CC4
 $     THEN
+$       write /symbol sys$output "        \Using special rule (4)"
+$       if (.not. CC4_SHOWN)
+$       then
+$         CC4_SHOWN = 1
+$         x = "    "+ CC4
+$         write /symbol sys$output x
+$       endif
 $       CC4/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
 $     ELSE
-$       IF COMPILEWITH_CC5 - FILE_NAME0 .NES. COMPILEWITH_CC5
+$       IF CC5_DIFFERENT .AND. -
+         (COMPILEWITH_CC5 - FILE_NAME0 .NES. COMPILEWITH_CC5)
 $       THEN
+$         write sys$output "        \Using special rule (5)"
+$         if (.not. CC5_SHOWN)
+$         then
+$           CC5_SHOWN = 1
+$           x = "    "+ CC5
+$           write /symbol sys$output x
+$         endif
 $         CC5/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
 $       ELSE
 $         IF COMPILEWITH_CC6 - FILE_NAME0 .NES. COMPILEWITH_CC6
 $         THEN
+$           write sys$output "        \Using special rule (6)"
+$           if (.not. CC6_SHOWN)
+$           then
+$             CC6_SHOWN = 1
+$             x = "    "+ CC6
+$             write /symbol sys$output x
+$           endif
 $           CC6/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
 $         ELSE
 $           CC/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
@@ -576,38 +662,22 @@ $!   SHOW SYMBOL APPLICATION*
 $!
 $! Tell the user what happens
 $!
-$   WRITE SYS$OUTPUT " ",APPLICATION,".exe"
+$   WRITE SYS$OUTPUT "        ",APPLICATION,".exe"
 $!
 $! Link The Program.
 $!
 $   ON ERROR THEN GOTO NEXT_APPLICATION
 $!
-$! Check To See If We Are To Link With A Specific TCP/IP Library.
+$!  Link With A TCP/IP Library.
 $!
-$   IF (TCPIP_LIB.NES."")
-$   THEN
+$   LINK /'DEBUGGER' /'LINKMAP' /'TRACEBACK' -
+     /EXE='EXE_DIR''APPLICATION'.EXE -
+     'OBJ_DIR''APPLICATION_OBJECTS', -
+     'CRYPTO_LIB'/LIBRARY -
+     'TCPIP_LIB' -
+     'ZLIB_LIB' -
+     ,'OPT_FILE' /OPTIONS
 $!
-$!    Link With A TCP/IP Library.
-$!
-$     LINK/'DEBUGGER'/'TRACEBACK'/EXE='EXE_DIR''APPLICATION'.EXE -
-          'OBJ_DIR''APPLICATION_OBJECTS', -
-         'CRYPTO_LIB'/LIBRARY, -
-          'TCPIP_LIB','OPT_FILE'/OPTION
-$!
-$! Else...
-$!
-$   ELSE
-$!
-$!    Don't Link With A TCP/IP Library.
-$!
-$     LINK/'DEBUGGER'/'TRACEBACK'/EXE='EXE_DIR''APPLICATION'.EXE -
-          'OBJ_DIR''APPLICATION_OBJECTS',-
-         'CRYPTO_LIB'/LIBRARY, -
-          'OPT_FILE'/OPTION
-$!
-$! End The TCP/IP Library Check.
-$!
-$   ENDIF
 $   GOTO NEXT_APPLICATION
 $  APPLICATION_DONE:
 $ ENDIF
@@ -646,7 +716,7 @@ $!
 $     CREATE 'OPT_FILE'
 $DECK
 !
-! Default System Options File To Link Agianst 
+! Default System Options File To Link Against 
 ! The Sharable VAX C Runtime Library.
 !
 SYS$SHARE:VAXCRTL.EXE/SHARE
@@ -675,7 +745,7 @@ $!
 $     CREATE 'OPT_FILE'
 $DECK
 !
-! Default System Options File To Link Agianst 
+! Default System Options File To Link Against 
 ! The Sharable C Runtime Library.
 !
 GNU_CC:[000000]GCCLIB/LIBRARY
@@ -710,7 +780,7 @@ $!
 $       CREATE 'OPT_FILE'
 $DECK
 !
-! Default System Options File To Link Agianst 
+! Default System Options File To Link Against 
 ! The Sharable DEC C Runtime Library.
 !
 SYS$SHARE:DECC$SHR.EXE/SHARE
@@ -725,7 +795,7 @@ $!
 $       CREATE 'OPT_FILE'
 $DECK
 !
-! Default System Options File For non-VAX To Link Agianst 
+! Default System Options File For non-VAX To Link Against 
 ! The Sharable C Runtime Library.
 !
 SYS$SHARE:CMA$OPEN_LIB_SHR/SHARE
@@ -746,7 +816,7 @@ $ ENDIF
 $!
 $!  Tell The User What Linker Option File We Are Using.
 $!
-$ WRITE SYS$OUTPUT "Using Linker Option File ",OPT_FILE,"."    
+$ WRITE SYS$OUTPUT "Using Linker Option File ",OPT_FILE,"."
 $!
 $! Time To RETURN.
 $!
@@ -769,12 +839,12 @@ $! Else...
 $!
 $ ELSE
 $!
-$!  Else, Check To See If P1 Has A Valid Arguement.
+$!  Else, Check To See If P1 Has A Valid Argument.
 $!
 $   IF (P1.EQS."LIBRARY").OR.(P1.EQS."APPS")
 $   THEN
 $!
-$!    A Valid Arguement.
+$!    A Valid Argument.
 $!
 $     BUILDALL = P1
 $!
@@ -793,8 +863,8 @@ $     WRITE SYS$OUTPUT "    APPS     :  To Compile Just The [.xxx.EXE.CRYPTO]*.E
 $     WRITE SYS$OUTPUT ""
 $     WRITE SYS$OUTPUT " Where 'xxx' Stands For:"
 $     WRITE SYS$OUTPUT ""
-$     WRITE SYS$OUTPUT "    ALPHA    :  Alpha Architecture."
-$     WRITE SYS$OUTPUT "    IA64     :  IA64 Architecture."
+$     WRITE SYS$OUTPUT "    ALPHA[64]:  Alpha Architecture."
+$     WRITE SYS$OUTPUT "    IA64[64] :  IA64 Architecture."
 $     WRITE SYS$OUTPUT "    VAX      :  VAX Architecture."
 $     WRITE SYS$OUTPUT ""
 $!
@@ -802,7 +872,7 @@ $!    Time To EXIT.
 $!
 $     EXIT
 $!
-$!  End The Valid Arguement Check.
+$!  End The Valid Argument Check.
 $!
 $   ENDIF
 $!
@@ -815,15 +885,16 @@ $!
 $ IF (P2.EQS."NODEBUG")
 $ THEN
 $!
-$!   P2 Is NODEBUG, So Compile Without The Debugger Information.
+$!  P2 Is NODEBUG, So Compile Without The Debugger Information.
 $!
-$    DEBUGGER = "NODEBUG"
-$    TRACEBACK = "NOTRACEBACK" 
-$    GCC_OPTIMIZE = "OPTIMIZE"
-$    CC_OPTIMIZE = "OPTIMIZE"
-$    MACRO_OPTIMIZE = "OPTIMIZE"
-$    WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile."
-$    WRITE SYS$OUTPUT "Compiling With Compiler Optimization."
+$   DEBUGGER = "NODEBUG"
+$   LINKMAP = "NOMAP"
+$   TRACEBACK = "NOTRACEBACK" 
+$   GCC_OPTIMIZE = "OPTIMIZE"
+$   CC_OPTIMIZE = "OPTIMIZE"
+$   MACRO_OPTIMIZE = "OPTIMIZE"
+$   WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile."
+$   WRITE SYS$OUTPUT "Compiling With Compiler Optimization."
 $ ELSE
 $!
 $!  Check To See If We Are To Compile With Debugger Information.
@@ -834,6 +905,7 @@ $!
 $!    Compile With Debugger Information.
 $!
 $     DEBUGGER = "DEBUG"
+$     LINKMAP = "MAP"
 $     TRACEBACK = "TRACEBACK"
 $     GCC_OPTIMIZE = "NOOPTIMIZE"
 $     CC_OPTIMIZE = "NOOPTIMIZE"
@@ -842,7 +914,7 @@ $     WRITE SYS$OUTPUT "Debugger Information Will Be Produced During Compile."
 $     WRITE SYS$OUTPUT "Compiling Without Compiler Optimization."
 $   ELSE 
 $!
-$!    They Entered An Invalid Option..
+$!    They Entered An Invalid Option.
 $!
 $     WRITE SYS$OUTPUT ""
 $     WRITE SYS$OUTPUT "The Option ",P2," Is Invalid.  The Valid Options Are:"
@@ -855,7 +927,7 @@ $!    Time To EXIT.
 $!
 $     EXIT
 $!
-$!  End The Valid Arguement Check.
+$!  End The Valid Argument Check.
 $!
 $   ENDIF
 $!
@@ -897,6 +969,60 @@ $! End The P5 Check.
 $!
 $ ENDIF
 $!
+$! Check P7 (POINTER_SIZE).
+$!
+$ IF (P7 .NES. "") .AND. (ARCH .NES. "VAX")
+$ THEN
+$!
+$   IF (P7 .EQS. "32")
+$   THEN
+$     POINTER_SIZE = " /POINTER_SIZE=32"
+$   ELSE
+$     POINTER_SIZE = F$EDIT( P7, "COLLAPSE, UPCASE")
+$     IF ((POINTER_SIZE .EQS. "64") .OR. -
+       (POINTER_SIZE .EQS. "64=") .OR. -
+       (POINTER_SIZE .EQS. "64=ARGV"))
+$     THEN
+$       ARCHD = ARCH+ "_64"
+$       LIB32 = ""
+$       POINTER_SIZE = " /POINTER_SIZE=64"
+$     ELSE
+$!
+$!      Tell The User Entered An Invalid Option.
+$!
+$       WRITE SYS$OUTPUT ""
+$       WRITE SYS$OUTPUT "The Option ", P7, -
+         " Is Invalid.  The Valid Options Are:"
+$       WRITE SYS$OUTPUT ""
+$       WRITE SYS$OUTPUT -
+         "    """"       :  Compile with default (short) pointers."
+$       WRITE SYS$OUTPUT -
+         "    32       :  Compile with 32-bit (short) pointers."
+$       WRITE SYS$OUTPUT -
+         "    64       :  Compile with 64-bit (long) pointers (auto ARGV)."
+$       WRITE SYS$OUTPUT -
+         "    64=      :  Compile with 64-bit (long) pointers (no ARGV)."
+$       WRITE SYS$OUTPUT -
+         "    64=ARGV  :  Compile with 64-bit (long) pointers (ARGV)."
+$       WRITE SYS$OUTPUT ""
+$! 
+$!      Time To EXIT.
+$!
+$       EXIT
+$!
+$     ENDIF
+$!
+$   ENDIF
+$!
+$! End The P7 (POINTER_SIZE) Check.
+$!
+$ ENDIF
+$!
+$! Set basic C compiler /INCLUDE directories.
+$!
+$ CC_INCLUDES = "SYS$DISK:[.''ARCHD'],SYS$DISK:[],SYS$DISK:[-],"+ -
+   "SYS$DISK:[.ENGINE.VENDOR_DEFNS],SYS$DISK:[.EVP],SYS$DISK:[.ASN1]"
+$!
 $! Check To See If P3 Is Blank.
 $!
 $ IF (P3.EQS."")
@@ -997,11 +1123,64 @@ $ CCDEFS = "TCPIP_TYPE_''P4',DSO_VMS"
 $ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS
 $ CCEXTRAFLAGS = ""
 $ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS
-$ CCDISABLEWARNINGS = "LONGLONGTYPE,LONGLONGSUFX,FOUNDCR"
+$ CCDISABLEWARNINGS = "" !!! "LONGLONGTYPE,LONGLONGSUFX,FOUNDCR"
 $ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN -
        CCDISABLEWARNINGS = CCDISABLEWARNINGS + "," + USER_CCDISABLEWARNINGS
 $!
-$!  Check To See If The User Entered A Valid Paramter.
+$! Check To See If We Have A ZLIB Option.
+$!
+$ ZLIB = P8
+$ IF (ZLIB .NES. "")
+$ THEN
+$!
+$!  Check for expected ZLIB files.
+$!
+$   err = 0
+$   file1 = f$parse( "zlib.h", ZLIB, , , "SYNTAX_ONLY")
+$   if (f$search( file1) .eqs. "")
+$   then
+$     WRITE SYS$OUTPUT ""
+$     WRITE SYS$OUTPUT "The Option ", ZLIB, " Is Invalid."
+$     WRITE SYS$OUTPUT "    Can't find header: ''file1'"
+$     err = 1
+$   endif
+$   file1 = f$parse( "A.;", ZLIB)- "A.;"
+$!
+$   file2 = f$parse( ZLIB, "libz.olb", , , "SYNTAX_ONLY")
+$   if (f$search( file2) .eqs. "")
+$   then
+$     if (err .eq. 0)
+$     then
+$       WRITE SYS$OUTPUT ""
+$       WRITE SYS$OUTPUT "The Option ", ZLIB, " Is Invalid."
+$     endif
+$     WRITE SYS$OUTPUT "    Can't find library: ''file2'"
+$     WRITE SYS$OUTPUT ""
+$     err = err+ 2
+$   endif
+$   if (err .eq. 1)
+$   then
+$     WRITE SYS$OUTPUT ""
+$   endif
+$!
+$   if (err .ne. 0)
+$   then
+$     EXIT
+$   endif
+$!
+$   CCDEFS = """ZLIB=1"", "+ CCDEFS
+$   CC_INCLUDES = CC_INCLUDES+ ", "+ file1
+$   ZLIB_LIB = ", ''file2' /library"
+$!
+$!  Print info
+$!
+$   WRITE SYS$OUTPUT "ZLIB library spec: ", file2
+$!
+$! End The ZLIB Check.
+$!
+$ ENDIF
+$!
+$!  Check To See If The User Entered A Valid Parameter.
 $!
 $ IF (P3.EQS."VAXC").OR.(P3.EQS."DECC").OR.(P3.EQS."GNUC")
 $ THEN
@@ -1024,14 +1203,14 @@ $!
 $     CC = "CC"
 $     IF ARCH.EQS."VAX" .AND. F$TRNLNM("DECC$CC_DEFAULT").NES."/DECC" -
         THEN CC = "CC/DECC"
-$     CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/STANDARD=ANSI89" + -
-           "/NOLIST/PREFIX=ALL" + -
-          "/INCLUDE=(SYS$DISK:[],SYS$DISK:[._''ARCH'],SYS$DISK:[-],SYS$DISK:[.ENGINE.VENDOR_DEFNS],SYS$DISK:[.EVP])" + -
-          CCEXTRAFLAGS
+$     CC = CC + " /''CC_OPTIMIZE' /''DEBUGGER' /STANDARD=RELAXED"+ -
+       "''POINTER_SIZE' /NOLIST /PREFIX=ALL" + -
+       " /INCLUDE=(''CC_INCLUDES')"+ -
+       CCEXTRAFLAGS
 $!
 $!    Define The Linker Options File Name.
 $!
-$     OPT_FILE = "''EXE_DIR'VAX_DECC_OPTIONS.OPT"
+$     OPT_FILE = "VAX_DECC_OPTIONS.OPT"
 $!
 $!  End DECC Check.
 $!
@@ -1060,7 +1239,7 @@ $ EXIT
 $     ENDIF
 $     IF F$TRNLNM("DECC$CC_DEFAULT").EQS."/DECC" THEN CC = "CC/VAXC"
 $     CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/NOLIST" + -
-          "/INCLUDE=(SYS$DISK:[],SYS$DISK:[._''ARCH'],SYS$DISK:[-],SYS$DISK:[.ENGINE.VENDOR_DEFNS])" + -
+       "/INCLUDE=(''CC_INCLUDES')"+ -
           CCEXTRAFLAGS
 $     CCDEFS = """VAXC""," + CCDEFS
 $!
@@ -1070,7 +1249,7 @@ $     DEFINE/NOLOG SYS SYS$COMMON:[SYSLIB]
 $!
 $!    Define The Linker Options File Name.
 $!
-$     OPT_FILE = "''EXE_DIR'VAX_VAXC_OPTIONS.OPT"
+$     OPT_FILE = "VAX_VAXC_OPTIONS.OPT"
 $!
 $!  End VAXC Check
 $!
@@ -1092,12 +1271,12 @@ $!
 $!    Use GNU C...
 $!
 $     CC = "GCC/NOCASE_HACK/''GCC_OPTIMIZE'/''DEBUGGER'/NOLIST" + -
-          "/INCLUDE=(SYS$DISK:[],SYS$DISK:[._''ARCH'],SYS$DISK:[-],SYS$DISK:[.ENGINE.VENDOR_DEFNS])" + -
+       "/INCLUDE=(''CC_INCLUDES')"+ -
           CCEXTRAFLAGS
 $!
 $!    Define The Linker Options File Name.
 $!
-$     OPT_FILE = "''EXE_DIR'VAX_GNUC_OPTIONS.OPT"
+$     OPT_FILE = "VAX_GNUC_OPTIONS.OPT"
 $!
 $!  End The GNU C Check.
 $!
@@ -1118,22 +1297,24 @@ $       CC6DISABLEWARNINGS = "MIXLINKAGE"
 $     ELSE
 $       CC4DISABLEWARNINGS = CCDISABLEWARNINGS + ",DOLLARID"
 $       CC6DISABLEWARNINGS = CCDISABLEWARNINGS + ",MIXLINKAGE"
-$       CCDISABLEWARNINGS = "/WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))"
+$       CCDISABLEWARNINGS = " /WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))"
 $     ENDIF
-$     CC4DISABLEWARNINGS = "/WARNING=(DISABLE=(" + CC4DISABLEWARNINGS + "))"
-$     CC6DISABLEWARNINGS = "/WARNING=(DISABLE=(" + CC6DISABLEWARNINGS + "))"
+$     CC4DISABLEWARNINGS = " /WARNING=(DISABLE=(" + CC4DISABLEWARNINGS + "))"
+$     CC6DISABLEWARNINGS = " /WARNING=(DISABLE=(" + CC6DISABLEWARNINGS + "))"
 $   ELSE
 $     CCDISABLEWARNINGS = ""
 $     CC4DISABLEWARNINGS = ""
 $     CC6DISABLEWARNINGS = ""
 $   ENDIF
-$   CC3 = CC + "/DEFINE=(" + CCDEFS + ISSEVEN + ")" + CCDISABLEWARNINGS
-$   CC = CC + "/DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS
+$   CC3 = CC + " /DEFINE=(" + CCDEFS + ISSEVEN + ")" + CCDISABLEWARNINGS
+$   CC = CC + " /DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS
 $   IF ARCH .EQS. "VAX" .AND. COMPILER .EQS. "DECC" .AND. P2 .NES. "DEBUG"
 $   THEN
-$     CC5 = CC + "/OPTIMIZE=NODISJOINT"
+$     CC5 = CC + " /OPTIMIZE=NODISJOINT"
+$     CC5_DIFFERENT = 1
 $   ELSE
-$     CC5 = CC + "/NOOPTIMIZE"
+$     CC5 = CC
+$     CC5_DIFFERENT = 0
 $   ENDIF
 $   CC4 = CC - CCDISABLEWARNINGS + CC4DISABLEWARNINGS
 $   CC6 = CC - CCDISABLEWARNINGS + CC6DISABLEWARNINGS
@@ -1142,7 +1323,7 @@ $!  Show user the result
 $!
 $   WRITE/SYMBOL SYS$OUTPUT "Main C Compiling Command: ",CC
 $!
-$!  Else The User Entered An Invalid Arguement.
+$!  Else The User Entered An Invalid Argument.
 $!
 $ ELSE
 $!
@@ -1160,7 +1341,7 @@ $!  Time To EXIT.
 $!
 $   EXIT
 $!
-$! End The Valid Arguement Check.
+$! End The Valid Argument Check.
 $!
 $ ENDIF
 $!
@@ -1186,7 +1367,7 @@ $   THEN
 $!
 $!    Set the library to use SOCKETSHR
 $!
-$     TCPIP_LIB = "SYS$DISK:[-.VMS]SOCKETSHR_SHR.OPT/OPT"
+$     TCPIP_LIB = ",SYS$DISK:[-.VMS]SOCKETSHR_SHR.OPT /OPTIONS"
 $!
 $!    Done with SOCKETSHR
 $!
@@ -1212,13 +1393,13 @@ $   THEN
 $!
 $!    Set the library to use UCX.
 $!
-$     TCPIP_LIB = "SYS$DISK:[-.VMS]UCX_SHR_DECC.OPT/OPT"
+$     TCPIP_LIB = ",SYS$DISK:[-.VMS]UCX_SHR_DECC.OPT /OPTIONS"
 $     IF F$TRNLNM("UCX$IPC_SHR") .NES. ""
 $     THEN
-$       TCPIP_LIB = "SYS$DISK:[-.VMS]UCX_SHR_DECC_LOG.OPT/OPT"
+$       TCPIP_LIB = ",SYS$DISK:[-.VMS]UCX_SHR_DECC_LOG.OPT /OPTIONS"
 $     ELSE
 $       IF COMPILER .NES. "DECC" .AND. ARCH .EQS. "VAX" THEN -
-         TCPIP_LIB = "SYS$DISK:[-.VMS]UCX_SHR_VAXC.OPT/OPT"
+         TCPIP_LIB = ",SYS$DISK:[-.VMS]UCX_SHR_VAXC.OPT /OPTIONS"
 $     ENDIF
 $!
 $!    Done with UCX
@@ -1232,7 +1413,7 @@ $   THEN
 $!
 $!    Set the library to use TCPIP (post UCX).
 $!
-$     TCPIP_LIB = "SYS$DISK:[-.VMS]TCPIP_SHR_DECC.OPT/OPT"
+$     TCPIP_LIB = ",SYS$DISK:[-.VMS]TCPIP_SHR_DECC.OPT /OPTIONS"
 $!
 $!    Done with TCPIP
 $!
@@ -1253,9 +1434,9 @@ $   ENDIF
 $!
 $!  Print info
 $!
-$   WRITE SYS$OUTPUT "TCP/IP library spec: ", TCPIP_LIB
+$   WRITE SYS$OUTPUT "TCP/IP library spec: ", TCPIP_LIB- ","
 $!
-$!  Else The User Entered An Invalid Arguement.
+$!  Else The User Entered An Invalid Argument.
 $!
 $ ELSE
 $!
index 0e4fb07..b0360ce 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/crypto.h */
 /* ====================================================================
- * Copyright (c) 1998-2003 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -219,13 +219,9 @@ typedef struct openssl_item_st
 #define CRYPTO_LOCK_EC_PRE_COMP                36
 #define CRYPTO_LOCK_STORE              37
 #define CRYPTO_LOCK_COMP               38
-#ifndef OPENSSL_FIPS
-#define CRYPTO_NUM_LOCKS               39
-#else
 #define CRYPTO_LOCK_FIPS               39
 #define CRYPTO_LOCK_FIPS2              40
 #define CRYPTO_NUM_LOCKS               41
-#endif
 
 #define CRYPTO_LOCK            1
 #define CRYPTO_UNLOCK          2
@@ -288,9 +284,10 @@ typedef struct bio_st BIO_dummy;
 
 struct crypto_ex_data_st
        {
-       STACK *sk;
+       STACK_OF(void) *sk;
        int dummy; /* gcc is screwing up this data structure :-( */
        };
+DECLARE_STACK_OF(void)
 
 /* This stuff is basically class callback functions
  * The current classes are SSL_CTX, SSL, SSL_SESSION, and a few more */
@@ -347,7 +344,14 @@ DECLARE_STACK_OF(CRYPTO_EX_DATA_FUNCS)
 
 /* Set standard debugging functions (not done by default
  * unless CRYPTO_MDEBUG is defined) */
-void CRYPTO_malloc_debug_init(void);
+#define CRYPTO_malloc_debug_init()     do {\
+       CRYPTO_set_mem_debug_functions(\
+               CRYPTO_dbg_malloc,\
+               CRYPTO_dbg_realloc,\
+               CRYPTO_dbg_free,\
+               CRYPTO_dbg_set_options,\
+               CRYPTO_dbg_get_options);\
+       } while(0)
 
 int CRYPTO_mem_ctrl(int mode);
 int CRYPTO_is_mem_check_on(void);
@@ -420,16 +424,32 @@ void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,int type,
                                              const char *file, int line));
 int (*CRYPTO_get_add_lock_callback(void))(int *num,int mount,int type,
                                          const char *file,int line);
+
+/* Don't use this structure directly. */
+typedef struct crypto_threadid_st
+       {
+       void *ptr;
+       unsigned long val;
+       } CRYPTO_THREADID;
+/* Only use CRYPTO_THREADID_set_[numeric|pointer]() within callbacks */
+void CRYPTO_THREADID_set_numeric(CRYPTO_THREADID *id, unsigned long val);
+void CRYPTO_THREADID_set_pointer(CRYPTO_THREADID *id, void *ptr);
+int CRYPTO_THREADID_set_callback(void (*threadid_func)(CRYPTO_THREADID *));
+void (*CRYPTO_THREADID_get_callback(void))(CRYPTO_THREADID *);
+void CRYPTO_THREADID_current(CRYPTO_THREADID *id);
+int CRYPTO_THREADID_cmp(const CRYPTO_THREADID *a, const CRYPTO_THREADID *b);
+void CRYPTO_THREADID_cpy(CRYPTO_THREADID *dest, const CRYPTO_THREADID *src);
+unsigned long CRYPTO_THREADID_hash(const CRYPTO_THREADID *id);
+#ifndef OPENSSL_NO_DEPRECATED
 void CRYPTO_set_id_callback(unsigned long (*func)(void));
 unsigned long (*CRYPTO_get_id_callback(void))(void);
 unsigned long CRYPTO_thread_id(void);
+#endif
+
 const char *CRYPTO_get_lock_name(int type);
 int CRYPTO_add_lock(int *pointer,int amount,int type, const char *file,
                    int line);
 
-void int_CRYPTO_set_do_dynlock_callback(
-       void (*do_dynlock_cb)(int mode, int type, const char *file, int line));
-
 int CRYPTO_get_new_dynlockid(void);
 void CRYPTO_destroy_dynlockid(int i);
 struct CRYPTO_dynlock_value *CRYPTO_get_dynlock_value(int i);
@@ -454,10 +474,6 @@ int CRYPTO_set_mem_debug_functions(void (*m)(void *,int,const char *,int,int),
                                   void (*f)(void *,int),
                                   void (*so)(long),
                                   long (*go)(void));
-void CRYPTO_set_mem_info_functions(
-       int  (*push_info_fn)(const char *info, const char *file, int line),
-       int  (*pop_info_fn)(void),
-       int (*remove_all_info_fn)(void));
 void CRYPTO_get_mem_functions(void *(**m)(size_t),void *(**r)(void *, size_t), void (**f)(void *));
 void CRYPTO_get_locked_mem_functions(void *(**m)(size_t), void (**f)(void *));
 void CRYPTO_get_mem_ex_functions(void *(**m)(size_t,const char *,int),
@@ -514,9 +530,6 @@ void CRYPTO_dbg_free(void *addr,int before_p);
 void CRYPTO_dbg_set_options(long bits);
 long CRYPTO_dbg_get_options(void);
 
-int CRYPTO_dbg_push_info(const char *info, const char *file, int line);
-int CRYPTO_dbg_pop_info(void);
-int CRYPTO_dbg_remove_all_info(void);
 
 #ifndef OPENSSL_NO_FP_API
 void CRYPTO_mem_leaks_fp(FILE *);
@@ -534,69 +547,12 @@ unsigned long *OPENSSL_ia32cap_loc(void);
 #define OPENSSL_ia32cap (*(OPENSSL_ia32cap_loc()))
 int OPENSSL_isservice(void);
 
-#ifdef OPENSSL_FIPS
-#define FIPS_ERROR_IGNORED(alg) OpenSSLDie(__FILE__, __LINE__, \
-               alg " previous FIPS forbidden algorithm error ignored");
-
-#define FIPS_BAD_ABORT(alg) OpenSSLDie(__FILE__, __LINE__, \
-               #alg " Algorithm forbidden in FIPS mode");
-
-#ifdef OPENSSL_FIPS_STRICT
-#define FIPS_BAD_ALGORITHM(alg) FIPS_BAD_ABORT(alg)
-#else
-#define FIPS_BAD_ALGORITHM(alg) \
-       { \
-       FIPSerr(FIPS_F_HASH_FINAL,FIPS_R_NON_FIPS_METHOD); \
-       ERR_add_error_data(2, "Algorithm=", #alg); \
-       return 0; \
-       }
-#endif
-
-/* Low level digest API blocking macro */
-
-#define FIPS_NON_FIPS_MD_Init(alg) \
-       int alg##_Init(alg##_CTX *c) \
-               { \
-               if (FIPS_mode()) \
-                       FIPS_BAD_ALGORITHM(alg) \
-               return private_##alg##_Init(c); \
-               } \
-       int private_##alg##_Init(alg##_CTX *c)
-
-/* For ciphers the API often varies from cipher to cipher and each needs to
- * be treated as a special case. Variable key length ciphers (Blowfish, RC4,
- * CAST) however are very similar and can use a blocking macro.
- */
-
-#define FIPS_NON_FIPS_VCIPHER_Init(alg) \
-       void alg##_set_key(alg##_KEY *key, int len, const unsigned char *data) \
-               { \
-               if (FIPS_mode()) \
-                       FIPS_BAD_ABORT(alg) \
-               private_##alg##_set_key(key, len, data); \
-               } \
-       void private_##alg##_set_key(alg##_KEY *key, int len, \
-                                       const unsigned char *data)
-
-#else
-
-#define FIPS_NON_FIPS_VCIPHER_Init(alg) \
-       void alg##_set_key(alg##_KEY *key, int len, const unsigned char *data)
-
-#define FIPS_NON_FIPS_MD_Init(alg) \
-       int alg##_Init(alg##_CTX *c) 
-
-#endif /* def OPENSSL_FIPS */
-
 /* BEGIN ERROR CODES */
 /* The following lines are auto generated by the script mkerr.pl. Any changes
  * made after this point may be overwritten when the script is next run.
  */
 void ERR_load_CRYPTO_strings(void);
 
-#define OPENSSL_HAVE_INIT      1
-void OPENSSL_init(void);
-
 /* Error codes for the CRYPTO functions. */
 
 /* Function codes. */
index 786e688..ae98226 100644 (file)
@@ -12,8 +12,6 @@ MAKEFILE=     Makefile
 AR=            ar r
 RANLIB=                ranlib
 DES_ENC=       des_enc.o fcrypt_b.o
-# or use
-#DES_ENC=      dx86-elf.o yx86-elf.o
 
 CFLAGS= $(INCLUDES) $(CFLAG)
 ASFLAGS= $(INCLUDES) $(ASFLAG)
@@ -24,7 +22,7 @@ TEST=destest.c
 APPS=
 
 LIB=$(TOP)/libcrypto.a
-LIBSRC=        des_lib.c cbc_cksm.c cbc_enc.c  cfb64enc.c cfb_enc.c  \
+LIBSRC=        cbc_cksm.c cbc_enc.c  cfb64enc.c cfb_enc.c  \
        ecb3_enc.c ecb_enc.c  enc_read.c enc_writ.c \
        fcrypt.c ofb64enc.c ofb_enc.c  pcbc_enc.c \
        qud_cksm.c rand_key.c rpc_enc.c  set_key.c  \
@@ -33,7 +31,7 @@ LIBSRC=       des_lib.c cbc_cksm.c cbc_enc.c  cfb64enc.c cfb_enc.c  \
        str2key.c  cfb64ede.c ofb64ede.c ede_cbcm_enc.c des_old.c des_old2.c \
        read2pwd.c
 
-LIBOBJ= des_lib.o set_key.o  ecb_enc.o  cbc_enc.o \
+LIBOBJ= set_key.o  ecb_enc.o  cbc_enc.o \
        ecb3_enc.o cfb64enc.o cfb64ede.o cfb_enc.o  ofb64ede.o \
        enc_read.o enc_writ.o ofb64enc.o \
        ofb_enc.o  str2key.o  pcbc_enc.o qud_cksm.o rand_key.o \
@@ -54,7 +52,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -64,21 +62,10 @@ des: des.o cbc3_enc.o lib
 des_enc-sparc.S:       asm/des_enc.m4
        m4 -B 8192 asm/des_enc.m4 > des_enc-sparc.S
 
-# ELF
-dx86-elf.s:    asm/des-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
-       (cd asm; $(PERL) des-586.pl elf $(CFLAGS) > ../$@)
-yx86-elf.s:    asm/crypt586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
-       (cd asm; $(PERL) crypt586.pl elf $(CFLAGS) > ../$@)
-# COFF
-dx86-cof.s: asm/des-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
-       (cd asm; $(PERL) des-586.pl coff $(CFLAGS) > ../$@)
-yx86-cof.s: asm/crypt586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
-       (cd asm; $(PERL) crypt586.pl coff $(CFLAGS) > ../$@)
-# a.out
-dx86-out.s: asm/des-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
-       (cd asm; $(PERL) des-586.pl a.out $(CFLAGS) > ../$@)
-yx86-out.s: asm/crypt586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
-       (cd asm; $(PERL) crypt586.pl a.out $(CFLAGS) > ../$@)
+des-586.s:     asm/des-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
+       $(PERL) asm/des-586.pl $(PERLASM_SCHEME) $(CFLAGS) > $@
+crypt586.s:    asm/crypt586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
+       $(PERL) asm/crypt586.pl $(PERLASM_SCHEME) $(CFLAGS) > $@
 
 files:
        $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
@@ -156,14 +143,7 @@ des_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
 des_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
 des_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
 des_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
-des_enc.o: des_enc.c des_locl.h ncbc_enc.c
-des_lib.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
-des_lib.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
-des_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
-des_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-des_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-des_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
-des_lib.o: ../../include/openssl/ui_compat.h des_lib.c des_locl.h des_ver.h
+des_enc.o: des_enc.c des_locl.h ncbc_enc.c spr.h
 des_old.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
 des_old.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
 des_old.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
@@ -182,12 +162,13 @@ ecb3_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
 ecb3_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
 ecb3_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
 ecb3_enc.o: des_locl.h ecb3_enc.c
+ecb_enc.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
 ecb_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
 ecb_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
-ecb_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
-ecb_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-ecb_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
-ecb_enc.o: des_locl.h ecb_enc.c spr.h
+ecb_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+ecb_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+ecb_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
+ecb_enc.o: ../../include/openssl/ui_compat.h des_locl.h des_ver.h ecb_enc.c
 ede_cbcm_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
 ede_cbcm_enc.o: ../../include/openssl/e_os2.h
 ede_cbcm_enc.o: ../../include/openssl/opensslconf.h
@@ -277,11 +258,11 @@ rpc_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
 rpc_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
 rpc_enc.o: des_locl.h des_ver.h rpc_des.h rpc_enc.c
 set_key.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
-set_key.o: ../../include/openssl/e_os2.h ../../include/openssl/fips.h
-set_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/ossl_typ.h
-set_key.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-set_key.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
-set_key.o: ../../include/openssl/ui_compat.h des_locl.h set_key.c
+set_key.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
+set_key.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
+set_key.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+set_key.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
+set_key.o: des_locl.h set_key.c
 str2key.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
 str2key.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
 str2key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
index 1d04ed6..e36f7d4 100644 (file)
@@ -6,7 +6,8 @@
 # things perfect.
 #
 
-push(@INC,"perlasm","../../perlasm");
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+push(@INC,"${dir}","${dir}../../perlasm");
 require "x86asm.pl";
 
 &asm_init($ARGV[0],"crypt586.pl");
@@ -22,7 +23,7 @@ sub fcrypt_body
        {
        local($name,$do_ip)=@_;
 
-       &function_begin($name,"EXTRN   _DES_SPtrans:DWORD");
+       &function_begin($name);
 
        &comment("");
        &comment("Load the 2 words");
index b75d3c6..5b5f39c 100644 (file)
@@ -4,7 +4,8 @@
 # Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>
 #
 
-push(@INC,"perlasm","../../perlasm");
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+push(@INC,"${dir}","${dir}../../perlasm");
 require "x86asm.pl";
 require "cbc.pl";
 require "desboth.pl";
@@ -18,29 +19,110 @@ require "desboth.pl";
 
 $L="edi";
 $R="esi";
+$trans="ebp";
+$small_footprint=1 if (grep(/\-DOPENSSL_SMALL_FOOTPRINT/,@ARGV));
+# one can discuss setting this variable to 1 unconditionally, as
+# the folded loop is only 3% slower than unrolled, but >7 times smaller
 
-&external_label("DES_SPtrans");
+&public_label("DES_SPtrans");
+
+&DES_encrypt_internal();
+&DES_decrypt_internal();
 &DES_encrypt("DES_encrypt1",1);
 &DES_encrypt("DES_encrypt2",0);
 &DES_encrypt3("DES_encrypt3",1);
 &DES_encrypt3("DES_decrypt3",0);
 &cbc("DES_ncbc_encrypt","DES_encrypt1","DES_encrypt1",0,4,5,3,5,-1);
 &cbc("DES_ede3_cbc_encrypt","DES_encrypt3","DES_decrypt3",0,6,7,3,4,5);
+&DES_SPtrans();
 
 &asm_finish();
 
+sub DES_encrypt_internal()
+       {
+       &function_begin_B("_x86_DES_encrypt");
+
+       if ($small_footprint)
+           {
+           &lea("edx",&DWP(128,"ecx"));
+           &push("edx");
+           &push("ecx");
+           &set_label("eloop");
+               &D_ENCRYPT(0,$L,$R,0,$trans,"eax","ebx","ecx","edx",&swtmp(0));
+               &comment("");
+               &D_ENCRYPT(1,$R,$L,2,$trans,"eax","ebx","ecx","edx",&swtmp(0));
+               &comment("");
+               &add("ecx",16);
+               &cmp("ecx",&swtmp(1));
+               &mov(&swtmp(0),"ecx");
+               &jb(&label("eloop"));
+           &add("esp",8);
+           }
+       else
+           {
+           &push("ecx");
+           for ($i=0; $i<16; $i+=2)
+               {
+               &comment("Round $i");
+               &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx",&swtmp(0));
+               &comment("Round ".sprintf("%d",$i+1));
+               &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx",&swtmp(0));
+               }
+           &add("esp",4);
+       }
+       &ret();
+
+       &function_end_B("_x86_DES_encrypt");
+       }
+       
+sub DES_decrypt_internal()
+       {
+       &function_begin_B("_x86_DES_decrypt");
+
+       if ($small_footprint)
+           {
+           &push("ecx");
+           &lea("ecx",&DWP(128,"ecx"));
+           &push("ecx");
+           &set_label("dloop");
+               &D_ENCRYPT(0,$L,$R,-2,$trans,"eax","ebx","ecx","edx",&swtmp(0));
+               &comment("");
+               &D_ENCRYPT(1,$R,$L,-4,$trans,"eax","ebx","ecx","edx",&swtmp(0));
+               &comment("");
+               &sub("ecx",16);
+               &cmp("ecx",&swtmp(1));
+               &mov(&swtmp(0),"ecx");
+               &ja(&label("dloop"));
+           &add("esp",8);
+           }
+       else
+           {
+           &push("ecx");
+           for ($i=15; $i>0; $i-=2)
+               {
+               &comment("Round $i");
+               &D_ENCRYPT(15-$i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx",&swtmp(0));
+               &comment("Round ".sprintf("%d",$i-1));
+               &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$trans,"eax","ebx","ecx","edx",&swtmp(0));
+               }
+           &add("esp",4);
+           }
+       &ret();
+
+       &function_end_B("_x86_DES_decrypt");
+       }
+       
 sub DES_encrypt
        {
        local($name,$do_ip)=@_;
 
-       &function_begin_B($name,"EXTRN   _DES_SPtrans:DWORD");
+       &function_begin_B($name);
 
        &push("esi");
        &push("edi");
 
        &comment("");
        &comment("Load the 2 words");
-       $trans="ebp";
 
        if ($do_ip)
                {
@@ -73,39 +155,20 @@ sub DES_encrypt
                }
 
        # PIC-ification:-)
-       &picmeup($trans,"DES_SPtrans");
-       #if ($cpp)      { &picmeup($trans,"DES_SPtrans");   }
-       #else           { &lea($trans,&DWP("DES_SPtrans")); }
+       &call   (&label("pic_point"));
+       &set_label("pic_point");
+       &blindpop($trans);
+       &lea    ($trans,&DWP(&label("DES_SPtrans")."-".&label("pic_point"),$trans));
 
        &mov(   "ecx",  &wparam(1)      );
-       &cmp("ebx","0");
-       &je(&label("start_decrypt"));
-
-       for ($i=0; $i<16; $i+=2)
-               {
-               &comment("");
-               &comment("Round $i");
-               &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
-
-               &comment("");
-               &comment("Round ".sprintf("%d",$i+1));
-               &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx");
-               }
-       &jmp(&label("end"));
 
-       &set_label("start_decrypt");
-
-       for ($i=15; $i>0; $i-=2)
-               {
-               &comment("");
-               &comment("Round $i");
-               &D_ENCRYPT(15-$i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
-               &comment("");
-               &comment("Round ".sprintf("%d",$i-1));
-               &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$trans,"eax","ebx","ecx","edx");
-               }
-
-       &set_label("end");
+       &cmp("ebx","0");
+       &je(&label("decrypt"));
+       &call("_x86_DES_encrypt");
+       &jmp(&label("done"));
+       &set_label("decrypt");
+       &call("_x86_DES_decrypt");
+       &set_label("done");
 
        if ($do_ip)
                {
@@ -139,7 +202,7 @@ sub DES_encrypt
 
 sub D_ENCRYPT
        {
-       local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_;
+       local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t,$wp1)=@_;
 
         &mov(  $u,             &DWP(&n2a($S*4),$tmp2,"",0));
        &xor(   $tmp1,          $tmp1);
@@ -166,7 +229,7 @@ sub D_ENCRYPT
        &and(   $t,             "0xff"  );
         &xor(  $L,             &DWP("0x600",$trans,$tmp1,0));
         &xor(  $L,             &DWP("0x700",$trans,$tmp2,0));
-       &mov(   $tmp2,          &wparam(1)      );
+       &mov(   $tmp2,          $wp1    );
         &xor(  $L,             &DWP("0x400",$trans,$u,0));
         &xor(  $L,             &DWP("0x500",$trans,$t,0));
        }
@@ -249,3 +312,142 @@ sub FP_new
        &rotr($tt       , 4);
        }
 
+sub DES_SPtrans
+       {
+       &set_label("DES_SPtrans",64);
+       &data_word(0x02080800, 0x00080000, 0x02000002, 0x02080802);
+       &data_word(0x02000000, 0x00080802, 0x00080002, 0x02000002);
+       &data_word(0x00080802, 0x02080800, 0x02080000, 0x00000802);
+       &data_word(0x02000802, 0x02000000, 0x00000000, 0x00080002);
+       &data_word(0x00080000, 0x00000002, 0x02000800, 0x00080800);
+       &data_word(0x02080802, 0x02080000, 0x00000802, 0x02000800);
+       &data_word(0x00000002, 0x00000800, 0x00080800, 0x02080002);
+       &data_word(0x00000800, 0x02000802, 0x02080002, 0x00000000);
+       &data_word(0x00000000, 0x02080802, 0x02000800, 0x00080002);
+       &data_word(0x02080800, 0x00080000, 0x00000802, 0x02000800);
+       &data_word(0x02080002, 0x00000800, 0x00080800, 0x02000002);
+       &data_word(0x00080802, 0x00000002, 0x02000002, 0x02080000);
+       &data_word(0x02080802, 0x00080800, 0x02080000, 0x02000802);
+       &data_word(0x02000000, 0x00000802, 0x00080002, 0x00000000);
+       &data_word(0x00080000, 0x02000000, 0x02000802, 0x02080800);
+       &data_word(0x00000002, 0x02080002, 0x00000800, 0x00080802);
+       # nibble 1
+       &data_word(0x40108010, 0x00000000, 0x00108000, 0x40100000);
+       &data_word(0x40000010, 0x00008010, 0x40008000, 0x00108000);
+       &data_word(0x00008000, 0x40100010, 0x00000010, 0x40008000);
+       &data_word(0x00100010, 0x40108000, 0x40100000, 0x00000010);
+       &data_word(0x00100000, 0x40008010, 0x40100010, 0x00008000);
+       &data_word(0x00108010, 0x40000000, 0x00000000, 0x00100010);
+       &data_word(0x40008010, 0x00108010, 0x40108000, 0x40000010);
+       &data_word(0x40000000, 0x00100000, 0x00008010, 0x40108010);
+       &data_word(0x00100010, 0x40108000, 0x40008000, 0x00108010);
+       &data_word(0x40108010, 0x00100010, 0x40000010, 0x00000000);
+       &data_word(0x40000000, 0x00008010, 0x00100000, 0x40100010);
+       &data_word(0x00008000, 0x40000000, 0x00108010, 0x40008010);
+       &data_word(0x40108000, 0x00008000, 0x00000000, 0x40000010);
+       &data_word(0x00000010, 0x40108010, 0x00108000, 0x40100000);
+       &data_word(0x40100010, 0x00100000, 0x00008010, 0x40008000);
+       &data_word(0x40008010, 0x00000010, 0x40100000, 0x00108000);
+       # nibble 2
+       &data_word(0x04000001, 0x04040100, 0x00000100, 0x04000101);
+       &data_word(0x00040001, 0x04000000, 0x04000101, 0x00040100);
+       &data_word(0x04000100, 0x00040000, 0x04040000, 0x00000001);
+       &data_word(0x04040101, 0x00000101, 0x00000001, 0x04040001);
+       &data_word(0x00000000, 0x00040001, 0x04040100, 0x00000100);
+       &data_word(0x00000101, 0x04040101, 0x00040000, 0x04000001);
+       &data_word(0x04040001, 0x04000100, 0x00040101, 0x04040000);
+       &data_word(0x00040100, 0x00000000, 0x04000000, 0x00040101);
+       &data_word(0x04040100, 0x00000100, 0x00000001, 0x00040000);
+       &data_word(0x00000101, 0x00040001, 0x04040000, 0x04000101);
+       &data_word(0x00000000, 0x04040100, 0x00040100, 0x04040001);
+       &data_word(0x00040001, 0x04000000, 0x04040101, 0x00000001);
+       &data_word(0x00040101, 0x04000001, 0x04000000, 0x04040101);
+       &data_word(0x00040000, 0x04000100, 0x04000101, 0x00040100);
+       &data_word(0x04000100, 0x00000000, 0x04040001, 0x00000101);
+       &data_word(0x04000001, 0x00040101, 0x00000100, 0x04040000);
+       # nibble 3
+       &data_word(0x00401008, 0x10001000, 0x00000008, 0x10401008);
+       &data_word(0x00000000, 0x10400000, 0x10001008, 0x00400008);
+       &data_word(0x10401000, 0x10000008, 0x10000000, 0x00001008);
+       &data_word(0x10000008, 0x00401008, 0x00400000, 0x10000000);
+       &data_word(0x10400008, 0x00401000, 0x00001000, 0x00000008);
+       &data_word(0x00401000, 0x10001008, 0x10400000, 0x00001000);
+       &data_word(0x00001008, 0x00000000, 0x00400008, 0x10401000);
+       &data_word(0x10001000, 0x10400008, 0x10401008, 0x00400000);
+       &data_word(0x10400008, 0x00001008, 0x00400000, 0x10000008);
+       &data_word(0x00401000, 0x10001000, 0x00000008, 0x10400000);
+       &data_word(0x10001008, 0x00000000, 0x00001000, 0x00400008);
+       &data_word(0x00000000, 0x10400008, 0x10401000, 0x00001000);
+       &data_word(0x10000000, 0x10401008, 0x00401008, 0x00400000);
+       &data_word(0x10401008, 0x00000008, 0x10001000, 0x00401008);
+       &data_word(0x00400008, 0x00401000, 0x10400000, 0x10001008);
+       &data_word(0x00001008, 0x10000000, 0x10000008, 0x10401000);
+       # nibble 4
+       &data_word(0x08000000, 0x00010000, 0x00000400, 0x08010420);
+       &data_word(0x08010020, 0x08000400, 0x00010420, 0x08010000);
+       &data_word(0x00010000, 0x00000020, 0x08000020, 0x00010400);
+       &data_word(0x08000420, 0x08010020, 0x08010400, 0x00000000);
+       &data_word(0x00010400, 0x08000000, 0x00010020, 0x00000420);
+       &data_word(0x08000400, 0x00010420, 0x00000000, 0x08000020);
+       &data_word(0x00000020, 0x08000420, 0x08010420, 0x00010020);
+       &data_word(0x08010000, 0x00000400, 0x00000420, 0x08010400);
+       &data_word(0x08010400, 0x08000420, 0x00010020, 0x08010000);
+       &data_word(0x00010000, 0x00000020, 0x08000020, 0x08000400);
+       &data_word(0x08000000, 0x00010400, 0x08010420, 0x00000000);
+       &data_word(0x00010420, 0x08000000, 0x00000400, 0x00010020);
+       &data_word(0x08000420, 0x00000400, 0x00000000, 0x08010420);
+       &data_word(0x08010020, 0x08010400, 0x00000420, 0x00010000);
+       &data_word(0x00010400, 0x08010020, 0x08000400, 0x00000420);
+       &data_word(0x00000020, 0x00010420, 0x08010000, 0x08000020);
+       # nibble 5
+       &data_word(0x80000040, 0x00200040, 0x00000000, 0x80202000);
+       &data_word(0x00200040, 0x00002000, 0x80002040, 0x00200000);
+       &data_word(0x00002040, 0x80202040, 0x00202000, 0x80000000);
+       &data_word(0x80002000, 0x80000040, 0x80200000, 0x00202040);
+       &data_word(0x00200000, 0x80002040, 0x80200040, 0x00000000);
+       &data_word(0x00002000, 0x00000040, 0x80202000, 0x80200040);
+       &data_word(0x80202040, 0x80200000, 0x80000000, 0x00002040);
+       &data_word(0x00000040, 0x00202000, 0x00202040, 0x80002000);
+       &data_word(0x00002040, 0x80000000, 0x80002000, 0x00202040);
+       &data_word(0x80202000, 0x00200040, 0x00000000, 0x80002000);
+       &data_word(0x80000000, 0x00002000, 0x80200040, 0x00200000);
+       &data_word(0x00200040, 0x80202040, 0x00202000, 0x00000040);
+       &data_word(0x80202040, 0x00202000, 0x00200000, 0x80002040);
+       &data_word(0x80000040, 0x80200000, 0x00202040, 0x00000000);
+       &data_word(0x00002000, 0x80000040, 0x80002040, 0x80202000);
+       &data_word(0x80200000, 0x00002040, 0x00000040, 0x80200040);
+       # nibble 6
+       &data_word(0x00004000, 0x00000200, 0x01000200, 0x01000004);
+       &data_word(0x01004204, 0x00004004, 0x00004200, 0x00000000);
+       &data_word(0x01000000, 0x01000204, 0x00000204, 0x01004000);
+       &data_word(0x00000004, 0x01004200, 0x01004000, 0x00000204);
+       &data_word(0x01000204, 0x00004000, 0x00004004, 0x01004204);
+       &data_word(0x00000000, 0x01000200, 0x01000004, 0x00004200);
+       &data_word(0x01004004, 0x00004204, 0x01004200, 0x00000004);
+       &data_word(0x00004204, 0x01004004, 0x00000200, 0x01000000);
+       &data_word(0x00004204, 0x01004000, 0x01004004, 0x00000204);
+       &data_word(0x00004000, 0x00000200, 0x01000000, 0x01004004);
+       &data_word(0x01000204, 0x00004204, 0x00004200, 0x00000000);
+       &data_word(0x00000200, 0x01000004, 0x00000004, 0x01000200);
+       &data_word(0x00000000, 0x01000204, 0x01000200, 0x00004200);
+       &data_word(0x00000204, 0x00004000, 0x01004204, 0x01000000);
+       &data_word(0x01004200, 0x00000004, 0x00004004, 0x01004204);
+       &data_word(0x01000004, 0x01004200, 0x01004000, 0x00004004);
+       # nibble 7
+       &data_word(0x20800080, 0x20820000, 0x00020080, 0x00000000);
+       &data_word(0x20020000, 0x00800080, 0x20800000, 0x20820080);
+       &data_word(0x00000080, 0x20000000, 0x00820000, 0x00020080);
+       &data_word(0x00820080, 0x20020080, 0x20000080, 0x20800000);
+       &data_word(0x00020000, 0x00820080, 0x00800080, 0x20020000);
+       &data_word(0x20820080, 0x20000080, 0x00000000, 0x00820000);
+       &data_word(0x20000000, 0x00800000, 0x20020080, 0x20800080);
+       &data_word(0x00800000, 0x00020000, 0x20820000, 0x00000080);
+       &data_word(0x00800000, 0x00020000, 0x20000080, 0x20820080);
+       &data_word(0x00020080, 0x20000000, 0x00000000, 0x00820000);
+       &data_word(0x20800080, 0x20020080, 0x20020000, 0x00800080);
+       &data_word(0x20820000, 0x00000080, 0x00800080, 0x20020000);
+       &data_word(0x20820080, 0x00800000, 0x20800000, 0x20000080);
+       &data_word(0x00820000, 0x00020080, 0x20020080, 0x20800000);
+       &data_word(0x00000080, 0x20820000, 0x00820080, 0x00000000);
+       &data_word(0x20000000, 0x20800080, 0x00020000, 0x00820080);
+       }
diff --git a/deps/openssl/openssl/crypto/des/asm/des686.pl b/deps/openssl/openssl/crypto/des/asm/des686.pl
deleted file mode 100644 (file)
index d3ad5d5..0000000
+++ /dev/null
@@ -1,230 +0,0 @@
-#!/usr/local/bin/perl
-
-$prog="des686.pl";
-
-# base code is in microsft
-# op dest, source
-# format.
-#
-
-# WILL NOT WORK ANYMORE WITH desboth.pl
-require "desboth.pl";
-
-if (   ($ARGV[0] eq "elf"))
-       { require "x86unix.pl"; }
-elsif (        ($ARGV[0] eq "a.out"))
-       { $aout=1; require "x86unix.pl"; }
-elsif (        ($ARGV[0] eq "sol"))
-       { $sol=1; require "x86unix.pl"; }
-elsif ( ($ARGV[0] eq "cpp"))
-       { $cpp=1; require "x86unix.pl"; }
-elsif (        ($ARGV[0] eq "win32"))
-       { require "x86ms.pl"; }
-else
-       {
-       print STDERR <<"EOF";
-Pick one target type from
-       elf     - linux, FreeBSD etc
-       a.out   - old linux
-       sol     - x86 solaris
-       cpp     - format so x86unix.cpp can be used
-       win32   - Windows 95/Windows NT
-EOF
-       exit(1);
-       }
-
-&comment("Don't even think of reading this code");
-&comment("It was automatically generated by $prog");
-&comment("Which is a perl program used to generate the x86 assember for");
-&comment("any of elf, a.out, Win32, or Solaris");
-&comment("It can be found in SSLeay 0.6.5+ or in libdes 3.26+");
-&comment("eric <eay\@cryptsoft.com>");
-&comment("");
-
-&file("dx86xxxx");
-
-$L="edi";
-$R="esi";
-
-&DES_encrypt("DES_encrypt1",1);
-&DES_encrypt("DES_encrypt2",0);
-
-&DES_encrypt3("DES_encrypt3",1);
-&DES_encrypt3("DES_decrypt3",0);
-
-&file_end();
-
-sub DES_encrypt
-       {
-       local($name,$do_ip)=@_;
-
-       &function_begin($name,"EXTRN   _DES_SPtrans:DWORD");
-
-       &comment("");
-       &comment("Load the 2 words");
-       &mov("eax",&wparam(0));
-       &mov($L,&DWP(0,"eax","",0));
-       &mov($R,&DWP(4,"eax","",0));
-
-       $ksp=&wparam(1);
-
-       if ($do_ip)
-               {
-               &comment("");
-               &comment("IP");
-               &IP_new($L,$R,"eax");
-               }
-
-       &comment("");
-       &comment("fixup rotate");
-       &rotl($R,3);
-       &rotl($L,3);
-       &exch($L,$R);
-
-       &comment("");
-       &comment("load counter, key_schedule and enc flag");
-       &mov("eax",&wparam(2)); # get encrypt flag
-       &mov("ebp",&wparam(1)); # get ks
-       &cmp("eax","0");
-       &je(&label("start_decrypt"));
-
-       # encrypting part
-
-       for ($i=0; $i<16; $i+=2)
-               {
-               &comment("");
-               &comment("Round $i");
-               &D_ENCRYPT($L,$R,$i*2,"ebp","DES_SPtrans","ecx","edx","eax","ebx");
-
-               &comment("");
-               &comment("Round ".sprintf("%d",$i+1));
-               &D_ENCRYPT($R,$L,($i+1)*2,"ebp","DES_SPtrans","ecx","edx","eax","ebx");
-               }
-       &jmp(&label("end"));
-
-       &set_label("start_decrypt");
-
-       for ($i=15; $i>0; $i-=2)
-               {
-               &comment("");
-               &comment("Round $i");
-               &D_ENCRYPT($L,$R,$i*2,"ebp","DES_SPtrans","ecx","edx","eax","ebx");
-               &comment("");
-               &comment("Round ".sprintf("%d",$i-1));
-               &D_ENCRYPT($R,$L,($i-1)*2,"ebp","DES_SPtrans","ecx","edx","eax","ebx");
-               }
-
-       &set_label("end");
-
-       &comment("");
-       &comment("Fixup");
-       &rotr($L,3);            # r
-       &rotr($R,3);            # l
-
-       if ($do_ip)
-               {
-               &comment("");
-               &comment("FP");
-               &FP_new($R,$L,"eax");
-               }
-
-       &mov("eax",&wparam(0));
-       &mov(&DWP(0,"eax","",0),$L);
-       &mov(&DWP(4,"eax","",0),$R);
-
-       &function_end($name);
-       }
-
-
-# The logic is to load R into 2 registers and operate on both at the same time.
-# We also load the 2 R's into 2 more registers so we can do the 'move word down a byte'
-# while also masking the other copy and doing a lookup.  We then also accumulate the
-# L value in 2 registers then combine them at the end.
-sub D_ENCRYPT
-       {
-       local($L,$R,$S,$ks,$desSP,$u,$t,$tmp1,$tmp2,$tmp3)=@_;
-
-       &mov(   $u,             &DWP(&n2a($S*4),$ks,"",0));
-       &mov(   $t,             &DWP(&n2a(($S+1)*4),$ks,"",0));
-       &xor(   $u,             $R              );
-       &xor(   $t,             $R              );
-       &rotr(  $t,             4               );
-
-       # the numbers at the end of the line are origional instruction order
-       &mov(   $tmp2,          $u              );                      # 1 2
-       &mov(   $tmp1,          $t              );                      # 1 1
-       &and(   $tmp2,          "0xfc"          );                      # 1 4
-       &and(   $tmp1,          "0xfc"          );                      # 1 3
-       &shr(   $t,             8               );                      # 1 5
-       &xor(   $L,             &DWP("0x100+$desSP",$tmp1,"",0));       # 1 7
-       &shr(   $u,             8               );                      # 1 6
-       &mov(   $tmp1,          &DWP("      $desSP",$tmp2,"",0));       # 1 8
-
-       &mov(   $tmp2,          $u              );                      # 2 2
-       &xor(   $L,             $tmp1           );                      # 1 9
-       &and(   $tmp2,          "0xfc"          );                      # 2 4
-       &mov(   $tmp1,          $t              );                      # 2 1
-       &and(   $tmp1,          "0xfc"          );                      # 2 3
-       &shr(   $t,             8               );                      # 2 5
-       &xor(   $L,             &DWP("0x300+$desSP",$tmp1,"",0));       # 2 7
-       &shr(   $u,             8               );                      # 2 6
-       &mov(   $tmp1,          &DWP("0x200+$desSP",$tmp2,"",0));       # 2 8
-       &mov(   $tmp2,          $u              );                      # 3 2
-
-       &xor(   $L,             $tmp1           );                      # 2 9
-       &and(   $tmp2,          "0xfc"          );                      # 3 4
-
-       &mov(   $tmp1,          $t              );                      # 3 1 
-       &shr(   $u,             8               );                      # 3 6
-       &and(   $tmp1,          "0xfc"          );                      # 3 3
-       &shr(   $t,             8               );                      # 3 5
-       &xor(   $L,             &DWP("0x500+$desSP",$tmp1,"",0));       # 3 7
-       &mov(   $tmp1,          &DWP("0x400+$desSP",$tmp2,"",0));       # 3 8
-
-       &and(   $t,             "0xfc"          );                      # 4 1
-       &xor(   $L,             $tmp1           );                      # 3 9
-
-       &and(   $u,             "0xfc"          );                      # 4 2
-       &xor(   $L,             &DWP("0x700+$desSP",$t,"",0));          # 4 3
-       &xor(   $L,             &DWP("0x600+$desSP",$u,"",0));          # 4 4
-       }
-
-sub PERM_OP
-       {
-       local($a,$b,$tt,$shift,$mask)=@_;
-
-       &mov(   $tt,            $a              );
-       &shr(   $tt,            $shift          );
-       &xor(   $tt,            $b              );
-       &and(   $tt,            $mask           );
-       &xor(   $b,             $tt             );
-       &shl(   $tt,            $shift          );
-       &xor(   $a,             $tt             );
-       }
-
-sub IP_new
-       {
-       local($l,$r,$tt)=@_;
-
-       &PERM_OP($r,$l,$tt, 4,"0x0f0f0f0f");
-       &PERM_OP($l,$r,$tt,16,"0x0000ffff");
-       &PERM_OP($r,$l,$tt, 2,"0x33333333");
-       &PERM_OP($l,$r,$tt, 8,"0x00ff00ff");
-       &PERM_OP($r,$l,$tt, 1,"0x55555555");
-       }
-
-sub FP_new
-       {
-       local($l,$r,$tt)=@_;
-
-       &PERM_OP($l,$r,$tt, 1,"0x55555555");
-        &PERM_OP($r,$l,$tt, 8,"0x00ff00ff");
-        &PERM_OP($l,$r,$tt, 2,"0x33333333");
-        &PERM_OP($r,$l,$tt,16,"0x0000ffff");
-        &PERM_OP($l,$r,$tt, 4,"0x0f0f0f0f");
-       }
-
-sub n2a
-       {
-       sprintf("%d",$_[0]);
-       }
index f59333a..3280595 100644 (file)
@@ -1954,9 +1954,11 @@ DES_ede3_cbc_encrypt:
        .word   LOOPS                     ! 280
        .word   0x0000FC00                ! 284
 
-       .type   .PIC.DES_SPtrans,#object
-       .size   .PIC.DES_SPtrans,2048
+       .global DES_SPtrans
+       .type   DES_SPtrans,#object
+       .size   DES_SPtrans,2048
 .align 64
+DES_SPtrans:
 .PIC.DES_SPtrans:
        ! nibble 0
        .word   0x02080800, 0x00080000, 0x02000002, 0x02080802
index afc2607..348f1c0 100644 (file)
@@ -659,13 +659,13 @@ $! Else...
 $!
 $ ELSE
 $!
-$!  Else, Check To See If P1 Has A Valid Arguement.
+$!  Else, Check To See If P1 Has A Valid Argument.
 $!
 $   IF (P1.EQS."LIBRARY").OR.(P1.EQS."DESTEST").OR.(P1.EQS."SPEED") -
        .OR.(P1.EQS."RPW").OR.(P1.EQS."DES").OR.(P1.EQS."DES_OPTS")
 $   THEN
 $!
-$!    A Valid Arguement.
+$!    A Valid Argument.
 $!
 $     BUILDALL = P1
 $!
@@ -678,7 +678,7 @@ $!
 $     WRITE SYS$OUTPUT ""
 $     WRITE SYS$OUTPUT "The Option ",P1," Is Invalid.  The Valid Options Are:"
 $     WRITE SYS$OUTPUT ""
-$     WRITE SYS$OUTPUT "    ALL      :  Just Build Everything.
+$     WRITE SYS$OUTPUT "    ALL      :  Just Build Everything."
 $     WRITE SYS$OUTPUT "    LIBRARY  :  To Compile Just The [.xxx.EXE.CRYPTO.DES]LIBDES.OLB Library."
 $     WRITE SYS$OUTPUT "    DESTEST  :  To Compile Just The [.xxx.EXE.CRYPTO.DES]DESTEST.EXE Program."
 $     WRITE SYS$OUTPUT "    SPEED    :  To Compile Just The [.xxx.EXE.CRYPTO.DES]SPEED.EXE Program."
@@ -697,7 +697,7 @@ $!    Time To EXIT.
 $!
 $     EXIT
 $!
-$!  End The Valid Arguement Check.
+$!  End The Valid Argument Check.
 $!
 $   ENDIF
 $!
@@ -754,7 +754,7 @@ $!    Time To EXIT.
 $!
 $     EXIT
 $!
-$!  End The Valid Arguement Check.
+$!  End The Valid Argument Check.
 $!
 $   ENDIF
 $!
@@ -978,7 +978,7 @@ $!  Show user the result
 $!
 $   WRITE SYS$OUTPUT "Main Compiling Command: ",CC
 $!
-$!  Else The User Entered An Invalid Arguement.
+$!  Else The User Entered An Invalid Argument.
 $!
 $ ELSE
 $!
index cf71965..828feba 100644 (file)
@@ -57,6 +57,7 @@
  */
 
 #include "des_locl.h"
+#include "spr.h"
 
 void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc)
        {
@@ -107,12 +108,10 @@ void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc)
                D_ENCRYPT(l,r,28); /*  15 */
                D_ENCRYPT(r,l,30); /*  16 */
 #else
-               for (i=0; i<32; i+=8)
+               for (i=0; i<32; i+=4)
                        {
                        D_ENCRYPT(l,r,i+0); /*  1 */
                        D_ENCRYPT(r,l,i+2); /*  2 */
-                       D_ENCRYPT(l,r,i+4); /*  3 */
-                       D_ENCRYPT(r,l,i+6); /*  4 */
                        }
 #endif
                }
@@ -136,12 +135,10 @@ void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc)
                D_ENCRYPT(l,r, 2); /*  2 */
                D_ENCRYPT(r,l, 0); /*  1 */
 #else
-               for (i=30; i>0; i-=8)
+               for (i=30; i>0; i-=4)
                        {
                        D_ENCRYPT(l,r,i-0); /* 16 */
                        D_ENCRYPT(r,l,i-2); /* 15 */
-                       D_ENCRYPT(l,r,i-4); /* 14 */
-                       D_ENCRYPT(r,l,i-6); /* 13 */
                        }
 #endif
                }
@@ -203,12 +200,10 @@ void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc)
                D_ENCRYPT(l,r,28); /*  15 */
                D_ENCRYPT(r,l,30); /*  16 */
 #else
-               for (i=0; i<32; i+=8)
+               for (i=0; i<32; i+=4)
                        {
                        D_ENCRYPT(l,r,i+0); /*  1 */
                        D_ENCRYPT(r,l,i+2); /*  2 */
-                       D_ENCRYPT(l,r,i+4); /*  3 */
-                       D_ENCRYPT(r,l,i+6); /*  4 */
                        }
 #endif
                }
@@ -232,12 +227,10 @@ void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc)
                D_ENCRYPT(l,r, 2); /*  2 */
                D_ENCRYPT(r,l, 0); /*  1 */
 #else
-               for (i=30; i>0; i-=8)
+               for (i=30; i>0; i-=4)
                        {
                        D_ENCRYPT(l,r,i-0); /* 16 */
                        D_ENCRYPT(r,l,i-2); /* 15 */
-                       D_ENCRYPT(l,r,i-4); /* 14 */
-                       D_ENCRYPT(r,l,i-6); /* 13 */
                        }
 #endif
                }
@@ -289,8 +282,6 @@ void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,
 
 #ifndef DES_DEFAULT_OPTIONS
 
-#if !defined(OPENSSL_FIPS_DES_ASM)
-
 #undef CBC_ENC_C__DONT_UPDATE_IV
 #include "ncbc_enc.c" /* DES_ncbc_encrypt */
 
@@ -406,6 +397,4 @@ void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
        tin[0]=tin[1]=0;
        }
 
-#endif
-
 #endif /* DES_DEFAULT_OPTIONS */
index 4b9ecff..a3b512e 100644 (file)
@@ -61,7 +61,7 @@
 
 #include <openssl/e_os2.h>
 
-#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16)
+#if defined(OPENSSL_SYS_WIN32)
 #ifndef OPENSSL_SYS_MSDOS
 #define OPENSSL_SYS_MSDOS
 #endif
@@ -425,4 +425,8 @@ extern const DES_LONG DES_SPtrans[8][64];
 
 void fcrypt_body(DES_LONG *out,DES_key_schedule *ks,
                 DES_LONG Eswap0, DES_LONG Eswap1);
+
+#ifdef OPENSSL_SMALL_FOOTPRINT
+#undef DES_UNROLL
+#endif
 #endif
index 75ae6cf..0684e76 100644 (file)
  */
 
 #include "des_locl.h"
-#include "spr.h"
+#include "des_ver.h"
+#include <openssl/opensslv.h>
+#include <openssl/bio.h>
+
+OPENSSL_GLOBAL const char libdes_version[]="libdes" OPENSSL_VERSION_PTEXT;
+OPENSSL_GLOBAL const char DES_version[]="DES" OPENSSL_VERSION_PTEXT;
+
+const char *DES_options(void)
+       {
+       static int init=1;
+       static char buf[32];
+
+       if (init)
+               {
+               const char *ptr,*unroll,*risc,*size;
+
+#ifdef DES_PTR
+               ptr="ptr";
+#else
+               ptr="idx";
+#endif
+#if defined(DES_RISC1) || defined(DES_RISC2)
+#ifdef DES_RISC1
+               risc="risc1";
+#endif
+#ifdef DES_RISC2
+               risc="risc2";
+#endif
+#else
+               risc="cisc";
+#endif
+#ifdef DES_UNROLL
+               unroll="16";
+#else
+               unroll="2";
+#endif
+               if (sizeof(DES_LONG) != sizeof(long))
+                       size="int";
+               else
+                       size="long";
+               BIO_snprintf(buf,sizeof buf,"des(%s,%s,%s,%s)",ptr,risc,unroll,
+                            size);
+               init=0;
+               }
+       return(buf);
+       }
+               
 
 void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output,
                     DES_key_schedule *ks, int enc)
index e7da2ec..edb6620 100644 (file)
@@ -63,7 +63,7 @@
 
 /* This has some uglies in it but it works - even over sockets. */
 /*extern int errno;*/
-OPENSSL_IMPLEMENT_GLOBAL(int,DES_rw_mode)=DES_PCBC_MODE;
+OPENSSL_IMPLEMENT_GLOBAL(int,DES_rw_mode,DES_PCBC_MODE)
 
 
 /*
@@ -87,6 +87,9 @@ OPENSSL_IMPLEMENT_GLOBAL(int,DES_rw_mode)=DES_PCBC_MODE;
 int DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched,
                 DES_cblock *iv)
        {
+#if defined(OPENSSL_NO_POSIX_IO)
+       return(0);
+#else
        /* data to be unencrypted */
        int net_num=0;
        static unsigned char *net=NULL;
@@ -147,7 +150,7 @@ int DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched,
        /* first - get the length */
        while (net_num < HDRSIZE) 
                {
-#ifndef _WIN32
+#ifndef OPENSSL_SYS_WIN32
                i=read(fd,(void *)&(net[net_num]),HDRSIZE-net_num);
 #else
                i=_read(fd,(void *)&(net[net_num]),HDRSIZE-net_num);
@@ -173,7 +176,11 @@ int DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched,
        net_num=0;
        while (net_num < rnum)
                {
+#ifndef OPENSSL_SYS_WIN32
                i=read(fd,(void *)&(net[net_num]),rnum-net_num);
+#else
+               i=_read(fd,(void *)&(net[net_num]),rnum-net_num);
+#endif
 #ifdef EINTR
                if ((i == -1) && (errno == EINTR)) continue;
 #endif
@@ -228,5 +235,6 @@ int DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched,
                        }
                }
        return num;
+#endif /* OPENSSL_NO_POSIX_IO */
        }
 
index c2f032c..2353ac1 100644 (file)
@@ -80,6 +80,9 @@
 int DES_enc_write(int fd, const void *_buf, int len,
                  DES_key_schedule *sched, DES_cblock *iv)
        {
+#if defined(OPENSSL_NO_POSIX_IO)
+       return (-1);
+#else
 #ifdef _LIBC
        extern unsigned long time();
        extern int write();
@@ -172,4 +175,5 @@ int DES_enc_write(int fd, const void *_buf, int len,
                }
 
        return(len);
+#endif /* OPENSSL_NO_POSIX_IO */
        }
index 1390138..8822816 100644 (file)
@@ -100,12 +100,10 @@ void fcrypt_body(DES_LONG *out, DES_key_schedule *ks, DES_LONG Eswap0,
 #ifndef DES_UNROLL
                register int i;
 
-               for (i=0; i<32; i+=8)
+               for (i=0; i<32; i+=4)
                        {
                        D_ENCRYPT(l,r,i+0); /*  1 */
                        D_ENCRYPT(r,l,i+2); /*  2 */
-                       D_ENCRYPT(l,r,i+4); /*  1 */
-                       D_ENCRYPT(r,l,i+6); /*  2 */
                        }
 #else
                D_ENCRYPT(l,r, 0); /*  1 */
index c0806d5..3004cc3 100644 (file)
  * 1.0 First working version
  */
 #include "des_locl.h"
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
 
-OPENSSL_IMPLEMENT_GLOBAL(int,DES_check_key);   /* defaults to false */
+OPENSSL_IMPLEMENT_GLOBAL(int,DES_check_key,0)  /* defaults to false */
 
 static const unsigned char odd_parity[256]={
   1,  1,  2,  2,  4,  4,  7,  7,  8,  8, 11, 11, 13, 13, 14, 14,
@@ -340,7 +336,7 @@ int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule)
 
 void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule)
        {
-       static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
+       static const int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
        register DES_LONG c,d,t,s,t2;
        register const unsigned char *in;
        register DES_LONG *k;
@@ -353,10 +349,6 @@ void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule)
        k = &schedule->ks->deslong[0];
        in = &(*key)[0];
 
-#ifdef OPENSSL_FIPS
-       FIPS_selftest_check();
-#endif
-
        c2l(in,c);
        c2l(in,d);
 
@@ -413,4 +405,3 @@ void des_fixup_key_parity(des_cblock *key)
        des_set_odd_parity(key);
        }
 */
-
index dc0c761..058cab6 100644 (file)
@@ -61,7 +61,7 @@
 /* RSA's DESX */
 
 #if 0 /* broken code, preserved just in case anyone specifically looks for this */
-static unsigned char desx_white_in2out[256]={
+static const unsigned char desx_white_in2out[256]={
 0xBD,0x56,0xEA,0xF2,0xA2,0xF1,0xAC,0x2A,0xB0,0x93,0xD1,0x9C,0x1B,0x33,0xFD,0xD0,
 0x30,0x04,0xB6,0xDC,0x7D,0xDF,0x32,0x4B,0xF7,0xCB,0x45,0x9B,0x31,0xBB,0x21,0x5A,
 0x41,0x9F,0xE1,0xD9,0x4A,0x4D,0x9E,0xDA,0xA0,0x68,0x2C,0xC3,0x27,0x5F,0x80,0x36,
index d01fa96..f23b4f7 100644 (file)
@@ -17,8 +17,10 @@ TEST= dhtest.c
 APPS=
 
 LIB=$(TOP)/libcrypto.a
-LIBSRC= dh_asn1.c dh_gen.c dh_key.c dh_lib.c dh_check.c dh_err.c dh_depr.c
-LIBOBJ= dh_asn1.o dh_gen.o dh_key.o dh_lib.o dh_check.o dh_err.o dh_depr.o
+LIBSRC= dh_asn1.c dh_gen.c dh_key.c dh_lib.c dh_check.c dh_err.c dh_depr.c \
+       dh_ameth.c dh_pmeth.c dh_prn.c
+LIBOBJ= dh_asn1.o dh_gen.o dh_key.o dh_lib.o dh_check.o dh_err.o dh_depr.o \
+       dh_ameth.o dh_pmeth.o dh_prn.o
 
 SRC= $(LIBSRC)
 
@@ -33,7 +35,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -74,6 +76,21 @@ clean:
 
 # DO NOT DELETE THIS LINE -- make depend depends on it.
 
+dh_ameth.o: ../../e_os.h ../../include/openssl/asn1.h
+dh_ameth.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
+dh_ameth.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
+dh_ameth.o: ../../include/openssl/dh.h ../../include/openssl/e_os2.h
+dh_ameth.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+dh_ameth.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
+dh_ameth.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+dh_ameth.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+dh_ameth.o: ../../include/openssl/opensslconf.h
+dh_ameth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+dh_ameth.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+dh_ameth.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+dh_ameth.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+dh_ameth.o: ../../include/openssl/x509_vfy.h ../asn1/asn1_locl.h ../cryptlib.h
+dh_ameth.o: dh_ameth.c
 dh_asn1.o: ../../e_os.h ../../include/openssl/asn1.h
 dh_asn1.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 dh_asn1.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
@@ -129,11 +146,35 @@ dh_lib.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
 dh_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 dh_lib.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 dh_lib.o: ../../include/openssl/engine.h ../../include/openssl/err.h
-dh_lib.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-dh_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-dh_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-dh_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-dh_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-dh_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-dh_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-dh_lib.o: ../../include/openssl/x509_vfy.h ../cryptlib.h dh_lib.c
+dh_lib.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+dh_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+dh_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+dh_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+dh_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+dh_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+dh_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+dh_lib.o: ../cryptlib.h dh_lib.c
+dh_pmeth.o: ../../e_os.h ../../include/openssl/asn1.h
+dh_pmeth.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
+dh_pmeth.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
+dh_pmeth.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
+dh_pmeth.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+dh_pmeth.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
+dh_pmeth.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+dh_pmeth.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+dh_pmeth.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+dh_pmeth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+dh_pmeth.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+dh_pmeth.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+dh_pmeth.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+dh_pmeth.o: ../../include/openssl/x509_vfy.h ../cryptlib.h ../evp/evp_locl.h
+dh_pmeth.o: dh_pmeth.c
+dh_prn.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
+dh_prn.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
+dh_prn.o: ../../include/openssl/dh.h ../../include/openssl/e_os2.h
+dh_prn.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+dh_prn.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+dh_prn.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+dh_prn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+dh_prn.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+dh_prn.o: ../../include/openssl/symhacks.h ../cryptlib.h dh_prn.c
index 10475ac..849309a 100644 (file)
@@ -77,8 +77,6 @@
 # define OPENSSL_DH_MAX_MODULUS_BITS   10000
 #endif
 
-#define OPENSSL_DH_FIPS_MIN_MODULUS_BITS 1024
-
 #define DH_FLAG_CACHE_MONT_P     0x01
 #define DH_FLAG_NO_EXP_CONSTTIME 0x02 /* new with 0.9.7h; the built-in DH
                                        * implementation now uses constant time
@@ -159,7 +157,6 @@ struct dh_st
    this for backward compatibility: */
 #define DH_CHECK_P_NOT_STRONG_PRIME    DH_CHECK_P_NOT_SAFE_PRIME
 
-#define DHparams_dup(x) ASN1_dup_of_const(DH,i2d_DHparams,d2i_DHparams,x)
 #define d2i_DHparams_fp(fp,x) (DH *)ASN1_d2i_fp((char *(*)())DH_new, \
                (char *(*)())d2i_DHparams,(fp),(unsigned char **)(x))
 #define i2d_DHparams_fp(fp,x) ASN1_i2d_fp(i2d_DHparams,(fp), \
@@ -167,12 +164,9 @@ struct dh_st
 #define d2i_DHparams_bio(bp,x) ASN1_d2i_bio_of(DH,DH_new,d2i_DHparams,bp,x)
 #define i2d_DHparams_bio(bp,x) ASN1_i2d_bio_of_const(DH,i2d_DHparams,bp,x)
 
-const DH_METHOD *DH_OpenSSL(void);
+DH *DHparams_dup(DH *);
 
-#ifdef OPENSSL_FIPS
-DH *   FIPS_dh_new(void);
-void   FIPS_dh_free(DH *dh);
-#endif
+const DH_METHOD *DH_OpenSSL(void);
 
 void DH_set_default_method(const DH_METHOD *meth);
 const DH_METHOD *DH_get_default_method(void);
@@ -212,6 +206,18 @@ int        DHparams_print(BIO *bp, const DH *x);
 int    DHparams_print(char *bp, const DH *x);
 #endif
 
+#define EVP_PKEY_CTX_set_dh_paramgen_prime_len(ctx, len) \
+       EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_PARAMGEN, \
+                       EVP_PKEY_CTRL_DH_PARAMGEN_PRIME_LEN, len, NULL)
+
+#define EVP_PKEY_CTX_set_dh_paramgen_generator(ctx, gen) \
+       EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_PARAMGEN, \
+                       EVP_PKEY_CTRL_DH_PARAMGEN_GENERATOR, gen, NULL)
+
+#define        EVP_PKEY_CTRL_DH_PARAMGEN_PRIME_LEN     (EVP_PKEY_ALG_CTRL + 1)
+#define        EVP_PKEY_CTRL_DH_PARAMGEN_GENERATOR     (EVP_PKEY_ALG_CTRL + 2)
+               
+
 /* BEGIN ERROR CODES */
 /* The following lines are auto generated by the script mkerr.pl. Any changes
  * made after this point may be overwritten when the script is next run.
@@ -222,22 +228,31 @@ void ERR_load_DH_strings(void);
 
 /* Function codes. */
 #define DH_F_COMPUTE_KEY                                102
-#define DH_F_DHPARAMS_PRINT                             100
 #define DH_F_DHPARAMS_PRINT_FP                          101
 #define DH_F_DH_BUILTIN_GENPARAMS                       106
-#define DH_F_DH_COMPUTE_KEY                             107
-#define DH_F_DH_GENERATE_KEY                            108
-#define DH_F_DH_GENERATE_PARAMETERS                     109
 #define DH_F_DH_NEW_METHOD                              105
+#define DH_F_DH_PARAM_DECODE                            107
+#define DH_F_DH_PRIV_DECODE                             110
+#define DH_F_DH_PRIV_ENCODE                             111
+#define DH_F_DH_PUB_DECODE                              108
+#define DH_F_DH_PUB_ENCODE                              109
+#define DH_F_DO_DH_PRINT                                100
 #define DH_F_GENERATE_KEY                               103
 #define DH_F_GENERATE_PARAMETERS                        104
+#define DH_F_PKEY_DH_DERIVE                             112
+#define DH_F_PKEY_DH_KEYGEN                             113
 
 /* Reason codes. */
 #define DH_R_BAD_GENERATOR                              101
+#define DH_R_BN_DECODE_ERROR                            109
+#define DH_R_BN_ERROR                                   106
+#define DH_R_DECODE_ERROR                               104
 #define DH_R_INVALID_PUBKEY                             102
-#define DH_R_KEY_SIZE_TOO_SMALL                                 104
+#define DH_R_KEYS_NOT_SET                               108
 #define DH_R_MODULUS_TOO_LARGE                          103
+#define DH_R_NO_PARAMETERS_SET                          107
 #define DH_R_NO_PRIVATE_VALUE                           100
+#define DH_R_PARAMETER_ENCODING_ERROR                   105
 
 #ifdef  __cplusplus
 }
diff --git a/deps/openssl/openssl/crypto/dh/dh_ameth.c b/deps/openssl/openssl/crypto/dh/dh_ameth.c
new file mode 100644 (file)
index 0000000..377caf9
--- /dev/null
@@ -0,0 +1,500 @@
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project 2006.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include "cryptlib.h"
+#include <openssl/x509.h>
+#include <openssl/asn1.h>
+#include <openssl/dh.h>
+#include <openssl/bn.h>
+#include "asn1_locl.h"
+
+static void int_dh_free(EVP_PKEY *pkey)
+       {
+       DH_free(pkey->pkey.dh);
+       }
+
+static int dh_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
+       {
+       const unsigned char *p, *pm;
+       int pklen, pmlen;
+       int ptype;
+       void *pval;
+       ASN1_STRING *pstr;
+       X509_ALGOR *palg;
+       ASN1_INTEGER *public_key = NULL;
+
+       DH *dh = NULL;
+
+       if (!X509_PUBKEY_get0_param(NULL, &p, &pklen, &palg, pubkey))
+               return 0;
+       X509_ALGOR_get0(NULL, &ptype, &pval, palg);
+
+       if (ptype != V_ASN1_SEQUENCE)
+               {
+               DHerr(DH_F_DH_PUB_DECODE, DH_R_PARAMETER_ENCODING_ERROR);
+               goto err;
+               }
+
+       pstr = pval;    
+       pm = pstr->data;
+       pmlen = pstr->length;
+
+       if (!(dh = d2i_DHparams(NULL, &pm, pmlen)))
+               {
+               DHerr(DH_F_DH_PUB_DECODE, DH_R_DECODE_ERROR);
+               goto err;
+               }
+
+       if (!(public_key=d2i_ASN1_INTEGER(NULL, &p, pklen)))
+               {
+               DHerr(DH_F_DH_PUB_DECODE, DH_R_DECODE_ERROR);
+               goto err;
+               }
+
+       /* We have parameters now set public key */
+       if (!(dh->pub_key = ASN1_INTEGER_to_BN(public_key, NULL)))
+               {
+               DHerr(DH_F_DH_PUB_DECODE, DH_R_BN_DECODE_ERROR);
+               goto err;
+               }
+
+       ASN1_INTEGER_free(public_key);
+       EVP_PKEY_assign_DH(pkey, dh);
+       return 1;
+
+       err:
+       if (public_key)
+               ASN1_INTEGER_free(public_key);
+       if (dh)
+               DH_free(dh);
+       return 0;
+
+       }
+
+static int dh_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
+       {
+       DH *dh;
+       void *pval = NULL;
+       int ptype;
+       unsigned char *penc = NULL;
+       int penclen;
+       ASN1_STRING *str;
+       ASN1_INTEGER *pub_key = NULL;
+
+       dh=pkey->pkey.dh;
+
+       str = ASN1_STRING_new();
+       str->length = i2d_DHparams(dh, &str->data);
+       if (str->length <= 0)
+               {
+               DHerr(DH_F_DH_PUB_ENCODE, ERR_R_MALLOC_FAILURE);
+               goto err;
+               }
+       pval = str;
+       ptype = V_ASN1_SEQUENCE;
+
+       pub_key = BN_to_ASN1_INTEGER(dh->pub_key, NULL);
+       if (!pub_key)
+               goto err;
+
+       penclen = i2d_ASN1_INTEGER(pub_key, &penc);
+
+       ASN1_INTEGER_free(pub_key);
+
+       if (penclen <= 0)
+               {
+               DHerr(DH_F_DH_PUB_ENCODE, ERR_R_MALLOC_FAILURE);
+               goto err;
+               }
+
+       if (X509_PUBKEY_set0_param(pk, OBJ_nid2obj(EVP_PKEY_DH),
+                               ptype, pval, penc, penclen))
+               return 1;
+
+       err:
+       if (penc)
+               OPENSSL_free(penc);
+       if (pval)
+               ASN1_STRING_free(pval);
+
+       return 0;
+       }
+
+
+/* PKCS#8 DH is defined in PKCS#11 of all places. It is similar to DH in
+ * that the AlgorithmIdentifier contains the paramaters, the private key
+ * is explcitly included and the pubkey must be recalculated.
+ */
+       
+static int dh_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8)
+       {
+       const unsigned char *p, *pm;
+       int pklen, pmlen;
+       int ptype;
+       void *pval;
+       ASN1_STRING *pstr;
+       X509_ALGOR *palg;
+       ASN1_INTEGER *privkey = NULL;
+
+       DH *dh = NULL;
+
+       if (!PKCS8_pkey_get0(NULL, &p, &pklen, &palg, p8))
+               return 0;
+
+       X509_ALGOR_get0(NULL, &ptype, &pval, palg);
+
+       if (ptype != V_ASN1_SEQUENCE)
+                       goto decerr;
+
+       if (!(privkey=d2i_ASN1_INTEGER(NULL, &p, pklen)))
+               goto decerr;
+
+
+       pstr = pval;    
+       pm = pstr->data;
+       pmlen = pstr->length;
+       if (!(dh = d2i_DHparams(NULL, &pm, pmlen)))
+               goto decerr;
+       /* We have parameters now set private key */
+       if (!(dh->priv_key = ASN1_INTEGER_to_BN(privkey, NULL)))
+               {
+               DHerr(DH_F_DH_PRIV_DECODE,DH_R_BN_ERROR);
+               goto dherr;
+               }
+       /* Calculate public key */
+       if (!DH_generate_key(dh))
+               goto dherr;
+
+       EVP_PKEY_assign_DH(pkey, dh);
+
+       ASN1_INTEGER_free(privkey);
+
+       return 1;
+
+       decerr:
+       DHerr(DH_F_DH_PRIV_DECODE, EVP_R_DECODE_ERROR);
+       dherr:
+       DH_free(dh);
+       return 0;
+       }
+
+static int dh_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
+{
+       ASN1_STRING *params = NULL;
+       ASN1_INTEGER *prkey = NULL;
+       unsigned char *dp = NULL;
+       int dplen;
+
+       params = ASN1_STRING_new();
+
+       if (!params)
+               {
+               DHerr(DH_F_DH_PRIV_ENCODE,ERR_R_MALLOC_FAILURE);
+               goto err;
+               }
+
+       params->length = i2d_DHparams(pkey->pkey.dh, &params->data);
+       if (params->length <= 0)
+               {
+               DHerr(DH_F_DH_PRIV_ENCODE,ERR_R_MALLOC_FAILURE);
+               goto err;
+               }
+       params->type = V_ASN1_SEQUENCE;
+
+       /* Get private key into integer */
+       prkey = BN_to_ASN1_INTEGER(pkey->pkey.dh->priv_key, NULL);
+
+       if (!prkey)
+               {
+               DHerr(DH_F_DH_PRIV_ENCODE,DH_R_BN_ERROR);
+               goto err;
+               }
+
+       dplen = i2d_ASN1_INTEGER(prkey, &dp);
+
+       ASN1_INTEGER_free(prkey);
+
+       if (!PKCS8_pkey_set0(p8, OBJ_nid2obj(NID_dhKeyAgreement), 0,
+                               V_ASN1_SEQUENCE, params, dp, dplen))
+               goto err;
+
+       return 1;
+
+err:
+       if (dp != NULL)
+               OPENSSL_free(dp);
+       if (params != NULL)
+               ASN1_STRING_free(params);
+       if (prkey != NULL)
+               ASN1_INTEGER_free(prkey);
+       return 0;
+}
+
+
+static void update_buflen(const BIGNUM *b, size_t *pbuflen)
+       {
+       size_t i;
+       if (!b)
+               return;
+       if (*pbuflen < (i = (size_t)BN_num_bytes(b)))
+                       *pbuflen = i;
+       }
+
+static int dh_param_decode(EVP_PKEY *pkey,
+                                       const unsigned char **pder, int derlen)
+       {
+       DH *dh;
+       if (!(dh = d2i_DHparams(NULL, pder, derlen)))
+               {
+               DHerr(DH_F_DH_PARAM_DECODE, ERR_R_DH_LIB);
+               return 0;
+               }
+       EVP_PKEY_assign_DH(pkey, dh);
+       return 1;
+       }
+
+static int dh_param_encode(const EVP_PKEY *pkey, unsigned char **pder)
+       {
+       return i2d_DHparams(pkey->pkey.dh, pder);
+       }
+
+static int do_dh_print(BIO *bp, const DH *x, int indent,
+                                               ASN1_PCTX *ctx, int ptype)
+       {
+       unsigned char *m=NULL;
+       int reason=ERR_R_BUF_LIB,ret=0;
+       size_t buf_len=0;
+
+       const char *ktype = NULL;
+
+       BIGNUM *priv_key, *pub_key;
+
+       if (ptype == 2)
+               priv_key = x->priv_key;
+       else
+               priv_key = NULL;
+
+       if (ptype > 0)
+               pub_key = x->pub_key;
+       else
+               pub_key = NULL;
+
+       update_buflen(x->p, &buf_len);
+
+       if (buf_len == 0)
+               {
+               reason = ERR_R_PASSED_NULL_PARAMETER;
+               goto err;
+               }
+
+       update_buflen(x->g, &buf_len);
+       update_buflen(pub_key, &buf_len);
+       update_buflen(priv_key, &buf_len);
+
+       if (ptype == 2)
+               ktype = "PKCS#3 DH Private-Key";
+       else if (ptype == 1)
+               ktype = "PKCS#3 DH Public-Key";
+       else
+               ktype = "PKCS#3 DH Parameters";
+
+       m= OPENSSL_malloc(buf_len+10);
+       if (m == NULL)
+               {
+               reason=ERR_R_MALLOC_FAILURE;
+               goto err;
+               }
+
+       BIO_indent(bp, indent, 128);
+       if (BIO_printf(bp,"%s: (%d bit)\n", ktype, BN_num_bits(x->p)) <= 0)
+               goto err;
+       indent += 4;
+
+       if (!ASN1_bn_print(bp,"private-key:",priv_key,m,indent)) goto err;
+       if (!ASN1_bn_print(bp,"public-key:",pub_key,m,indent)) goto err;
+
+       if (!ASN1_bn_print(bp,"prime:",x->p,m,indent)) goto err;
+       if (!ASN1_bn_print(bp,"generator:",x->g,m,indent)) goto err;
+       if (x->length != 0)
+               {
+               BIO_indent(bp, indent, 128);
+               if (BIO_printf(bp,"recommended-private-length: %d bits\n",
+                       (int)x->length) <= 0) goto err;
+               }
+
+
+       ret=1;
+       if (0)
+               {
+err:
+               DHerr(DH_F_DO_DH_PRINT,reason);
+               }
+       if (m != NULL) OPENSSL_free(m);
+       return(ret);
+       }
+
+static int int_dh_size(const EVP_PKEY *pkey)
+       {
+       return(DH_size(pkey->pkey.dh));
+       }
+
+static int dh_bits(const EVP_PKEY *pkey)
+       {
+       return BN_num_bits(pkey->pkey.dh->p);
+       }
+
+static int dh_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b)
+       {
+       if (    BN_cmp(a->pkey.dh->p,b->pkey.dh->p) ||
+               BN_cmp(a->pkey.dh->g,b->pkey.dh->g))
+               return 0;
+       else
+               return 1;
+       }
+
+static int dh_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)
+       {
+       BIGNUM *a;
+
+       if ((a=BN_dup(from->pkey.dh->p)) == NULL)
+               return 0;
+       if (to->pkey.dh->p != NULL)
+               BN_free(to->pkey.dh->p);
+       to->pkey.dh->p=a;
+
+       if ((a=BN_dup(from->pkey.dh->g)) == NULL)
+               return 0;
+       if (to->pkey.dh->g != NULL)
+               BN_free(to->pkey.dh->g);
+       to->pkey.dh->g=a;
+
+       return 1;
+       }
+
+static int dh_missing_parameters(const EVP_PKEY *a)
+       {
+       if (!a->pkey.dh->p || !a->pkey.dh->g)
+               return 1;
+       return 0;
+       }
+
+static int dh_pub_cmp(const EVP_PKEY *a, const EVP_PKEY *b)
+       {
+       if (dh_cmp_parameters(a, b) == 0)
+               return 0;
+       if (BN_cmp(b->pkey.dh->pub_key,a->pkey.dh->pub_key) != 0)
+               return 0;
+       else
+               return 1;
+       }
+
+static int dh_param_print(BIO *bp, const EVP_PKEY *pkey, int indent,
+                                                       ASN1_PCTX *ctx)
+       {
+       return do_dh_print(bp, pkey->pkey.dh, indent, ctx, 0);
+       }
+
+static int dh_public_print(BIO *bp, const EVP_PKEY *pkey, int indent,
+                                                       ASN1_PCTX *ctx)
+       {
+       return do_dh_print(bp, pkey->pkey.dh, indent, ctx, 1);
+       }
+
+static int dh_private_print(BIO *bp, const EVP_PKEY *pkey, int indent,
+                                                       ASN1_PCTX *ctx)
+       {
+       return do_dh_print(bp, pkey->pkey.dh, indent, ctx, 2);
+       }
+
+int DHparams_print(BIO *bp, const DH *x)
+       {
+       return do_dh_print(bp, x, 4, NULL, 0);
+       }
+
+const EVP_PKEY_ASN1_METHOD dh_asn1_meth = 
+       {
+       EVP_PKEY_DH,
+       EVP_PKEY_DH,
+       0,
+
+       "DH",
+       "OpenSSL PKCS#3 DH method",
+
+       dh_pub_decode,
+       dh_pub_encode,
+       dh_pub_cmp,
+       dh_public_print,
+
+       dh_priv_decode,
+       dh_priv_encode,
+       dh_private_print,
+
+       int_dh_size,
+       dh_bits,
+
+       dh_param_decode,
+       dh_param_encode,
+       dh_missing_parameters,
+       dh_copy_parameters,
+       dh_cmp_parameters,
+       dh_param_print,
+
+       int_dh_free,
+       0
+       };
+
index 76740af..0b4357d 100644 (file)
@@ -3,7 +3,7 @@
  * project 2000.
  */
 /* ====================================================================
- * Copyright (c) 2000 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 2000-2005 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -64,7 +64,8 @@
 #include <openssl/asn1t.h>
 
 /* Override the default free and new methods */
-static int dh_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
+static int dh_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
+                                               void *exarg)
 {
        if(operation == ASN1_OP_NEW_PRE) {
                *pval = (ASN1_VALUE *)DH_new();
@@ -85,3 +86,8 @@ ASN1_SEQUENCE_cb(DHparams, dh_cb) = {
 } ASN1_SEQUENCE_END_cb(DH, DHparams)
 
 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DH, DHparams, DHparams)
+
+DH *DHparams_dup(DH *dh)
+       {
+       return ASN1_item_dup(ASN1_ITEM_rptr(DHparams), dh);
+       }
index 316cb92..0668981 100644 (file)
@@ -70,8 +70,6 @@
  * should hold.
  */
 
-#ifndef OPENSSL_FIPS
-
 int DH_check(const DH *dh, int *ret)
        {
        int ok=0;
@@ -130,11 +128,11 @@ int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *ret)
        q=BN_new();
        if (q == NULL) goto err;
        BN_set_word(q,1);
-       if (BN_cmp(pub_key,q) <= 0)
+       if (BN_cmp(pub_key,q)<=0)
                *ret|=DH_CHECK_PUBKEY_TOO_SMALL;
        BN_copy(q,dh->p);
        BN_sub_word(q,1);
-       if (BN_cmp(pub_key,q) >= 0)
+       if (BN_cmp(pub_key,q)>=0)
                *ret|=DH_CHECK_PUBKEY_TOO_LARGE;
 
        ok = 1;
@@ -142,5 +140,3 @@ err:
        if (q != NULL) BN_free(q);
        return(ok);
        }
-
-#endif
index 13263c8..d5cf0c2 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/dh/dh_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2007 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 static ERR_STRING_DATA DH_str_functs[]=
        {
 {ERR_FUNC(DH_F_COMPUTE_KEY),   "COMPUTE_KEY"},
-{ERR_FUNC(DH_F_DHPARAMS_PRINT),        "DHparams_print"},
 {ERR_FUNC(DH_F_DHPARAMS_PRINT_FP),     "DHparams_print_fp"},
 {ERR_FUNC(DH_F_DH_BUILTIN_GENPARAMS),  "DH_BUILTIN_GENPARAMS"},
-{ERR_FUNC(DH_F_DH_COMPUTE_KEY),        "DH_compute_key"},
-{ERR_FUNC(DH_F_DH_GENERATE_KEY),       "DH_generate_key"},
-{ERR_FUNC(DH_F_DH_GENERATE_PARAMETERS),        "DH_generate_parameters"},
 {ERR_FUNC(DH_F_DH_NEW_METHOD), "DH_new_method"},
+{ERR_FUNC(DH_F_DH_PARAM_DECODE),       "DH_PARAM_DECODE"},
+{ERR_FUNC(DH_F_DH_PRIV_DECODE),        "DH_PRIV_DECODE"},
+{ERR_FUNC(DH_F_DH_PRIV_ENCODE),        "DH_PRIV_ENCODE"},
+{ERR_FUNC(DH_F_DH_PUB_DECODE), "DH_PUB_DECODE"},
+{ERR_FUNC(DH_F_DH_PUB_ENCODE), "DH_PUB_ENCODE"},
+{ERR_FUNC(DH_F_DO_DH_PRINT),   "DO_DH_PRINT"},
 {ERR_FUNC(DH_F_GENERATE_KEY),  "GENERATE_KEY"},
 {ERR_FUNC(DH_F_GENERATE_PARAMETERS),   "GENERATE_PARAMETERS"},
+{ERR_FUNC(DH_F_PKEY_DH_DERIVE),        "PKEY_DH_DERIVE"},
+{ERR_FUNC(DH_F_PKEY_DH_KEYGEN),        "PKEY_DH_KEYGEN"},
 {0,NULL}
        };
 
 static ERR_STRING_DATA DH_str_reasons[]=
        {
 {ERR_REASON(DH_R_BAD_GENERATOR)          ,"bad generator"},
+{ERR_REASON(DH_R_BN_DECODE_ERROR)        ,"bn decode error"},
+{ERR_REASON(DH_R_BN_ERROR)               ,"bn error"},
+{ERR_REASON(DH_R_DECODE_ERROR)           ,"decode error"},
 {ERR_REASON(DH_R_INVALID_PUBKEY)         ,"invalid public key"},
-{ERR_REASON(DH_R_KEY_SIZE_TOO_SMALL)     ,"key size too small"},
+{ERR_REASON(DH_R_KEYS_NOT_SET)           ,"keys not set"},
 {ERR_REASON(DH_R_MODULUS_TOO_LARGE)      ,"modulus too large"},
+{ERR_REASON(DH_R_NO_PARAMETERS_SET)      ,"no parameters set"},
 {ERR_REASON(DH_R_NO_PRIVATE_VALUE)       ,"no private value"},
+{ERR_REASON(DH_R_PARAMETER_ENCODING_ERROR),"parameter encoding error"},
 {0,NULL}
        };
 
index 999e1de..cfd5b11 100644 (file)
@@ -66,8 +66,6 @@
 #include <openssl/bn.h>
 #include <openssl/dh.h>
 
-#ifndef OPENSSL_FIPS
-
 static int dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_GENCB *cb);
 
 int DH_generate_parameters_ex(DH *ret, int prime_len, int generator, BN_GENCB *cb)
@@ -175,5 +173,3 @@ err:
                }
        return ok;
        }
-
-#endif
index 79dd331..e7db440 100644 (file)
@@ -62,8 +62,6 @@
 #include <openssl/rand.h>
 #include <openssl/dh.h>
 
-#ifndef OPENSSL_FIPS
-
 static int generate_key(DH *dh);
 static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh);
 static int dh_bn_mod_exp(const DH *dh, BIGNUM *r,
@@ -263,5 +261,3 @@ static int dh_finish(DH *dh)
                BN_MONT_CTX_free(dh->method_mont_p);
        return(1);
        }
-
-#endif
diff --git a/deps/openssl/openssl/crypto/dh/dh_pmeth.c b/deps/openssl/openssl/crypto/dh/dh_pmeth.c
new file mode 100644 (file)
index 0000000..5ae72b7
--- /dev/null
@@ -0,0 +1,254 @@
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project 2006.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include "cryptlib.h"
+#include <openssl/asn1t.h>
+#include <openssl/x509.h>
+#include <openssl/evp.h>
+#include <openssl/dh.h>
+#include <openssl/bn.h>
+#include "evp_locl.h"
+
+/* DH pkey context structure */
+
+typedef struct
+       {
+       /* Parameter gen parameters */
+       int prime_len;
+       int generator;
+       int use_dsa;
+       /* Keygen callback info */
+       int gentmp[2];
+       /* message digest */
+       } DH_PKEY_CTX;
+
+static int pkey_dh_init(EVP_PKEY_CTX *ctx)
+       {
+       DH_PKEY_CTX *dctx;
+       dctx = OPENSSL_malloc(sizeof(DH_PKEY_CTX));
+       if (!dctx)
+               return 0;
+       dctx->prime_len = 1024;
+       dctx->generator = 2;
+       dctx->use_dsa = 0;
+
+       ctx->data = dctx;
+       ctx->keygen_info = dctx->gentmp;
+       ctx->keygen_info_count = 2;
+       
+       return 1;
+       }
+
+static int pkey_dh_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
+       {
+       DH_PKEY_CTX *dctx, *sctx;
+       if (!pkey_dh_init(dst))
+               return 0;
+               sctx = src->data;
+       dctx = dst->data;
+       dctx->prime_len = sctx->prime_len;
+       dctx->generator = sctx->generator;
+       dctx->use_dsa = sctx->use_dsa;
+       return 1;
+       }
+
+static void pkey_dh_cleanup(EVP_PKEY_CTX *ctx)
+       {
+       DH_PKEY_CTX *dctx = ctx->data;
+       if (dctx)
+               OPENSSL_free(dctx);
+       }
+
+static int pkey_dh_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
+       {
+       DH_PKEY_CTX *dctx = ctx->data;
+       switch (type)
+               {
+               case EVP_PKEY_CTRL_DH_PARAMGEN_PRIME_LEN:
+               if (p1 < 256)
+                       return -2;
+               dctx->prime_len = p1;
+               return 1;
+
+               case EVP_PKEY_CTRL_DH_PARAMGEN_GENERATOR:
+               dctx->generator = p1;
+               return 1;
+
+               case EVP_PKEY_CTRL_PEER_KEY:
+               /* Default behaviour is OK */
+               return 1;
+
+               default:
+               return -2;
+
+               }
+       }
+
+                       
+static int pkey_dh_ctrl_str(EVP_PKEY_CTX *ctx,
+                       const char *type, const char *value)
+       {
+       if (!strcmp(type, "dh_paramgen_prime_len"))
+               {
+               int len;
+               len = atoi(value);
+               return EVP_PKEY_CTX_set_dh_paramgen_prime_len(ctx, len);
+               }
+       if (!strcmp(type, "dh_paramgen_generator"))
+               {
+               int len;
+               len = atoi(value);
+               return EVP_PKEY_CTX_set_dh_paramgen_generator(ctx, len);
+               }
+       return -2;
+       }
+
+static int pkey_dh_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
+       {
+       DH *dh = NULL;
+       DH_PKEY_CTX *dctx = ctx->data;
+       BN_GENCB *pcb, cb;
+       int ret;
+       if (ctx->pkey_gencb)
+               {
+               pcb = &cb;
+               evp_pkey_set_cb_translate(pcb, ctx);
+               }
+       else
+               pcb = NULL;
+       dh = DH_new();
+       if (!dh)
+               return 0;
+       ret = DH_generate_parameters_ex(dh,
+                                       dctx->prime_len, dctx->generator, pcb);
+       if (ret)
+               EVP_PKEY_assign_DH(pkey, dh);
+       else
+               DH_free(dh);
+       return ret;
+       }
+
+static int pkey_dh_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
+       {
+       DH *dh = NULL;
+       if (ctx->pkey == NULL)
+               {
+               DHerr(DH_F_PKEY_DH_KEYGEN, DH_R_NO_PARAMETERS_SET);
+               return 0;
+               }
+       dh = DH_new();
+       if (!dh)
+               return 0;
+       EVP_PKEY_assign_DH(pkey, dh);
+       /* Note: if error return, pkey is freed by parent routine */
+       if (!EVP_PKEY_copy_parameters(pkey, ctx->pkey))
+               return 0;
+       return DH_generate_key(pkey->pkey.dh);
+       }
+
+static int pkey_dh_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen)
+       {
+       int ret;
+       if (!ctx->pkey || !ctx->peerkey)
+               {
+               DHerr(DH_F_PKEY_DH_DERIVE, DH_R_KEYS_NOT_SET);
+               return 0;
+               }
+       ret = DH_compute_key(key, ctx->peerkey->pkey.dh->pub_key,
+                                                       ctx->pkey->pkey.dh);
+       if (ret < 0)
+               return ret;
+       *keylen = ret;
+       return 1;
+       }
+
+const EVP_PKEY_METHOD dh_pkey_meth = 
+       {
+       EVP_PKEY_DH,
+       EVP_PKEY_FLAG_AUTOARGLEN,
+       pkey_dh_init,
+       pkey_dh_copy,
+       pkey_dh_cleanup,
+
+       0,
+       pkey_dh_paramgen,
+
+       0,
+       pkey_dh_keygen,
+
+       0,
+       0,
+
+       0,
+       0,
+
+       0,0,
+
+       0,0,0,0,
+
+       0,0,
+
+       0,0,
+
+       0,
+       pkey_dh_derive,
+
+       pkey_dh_ctrl,
+       pkey_dh_ctrl_str
+
+       };
similarity index 86%
rename from deps/openssl/openssl/crypto/bn/bn_opt.c
rename to deps/openssl/openssl/crypto/dh/dh_prn.c
index 21cbb38..ae58c2a 100644 (file)
@@ -1,4 +1,4 @@
-/* crypto/bn/bn_opt.c */
+/* crypto/asn1/t_pkey.c */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
  * [including the GNU Public Licence.]
  */
 
-#ifndef BN_DEBUG
-# undef NDEBUG /* avoid conflicting definitions */
-# define NDEBUG
-#endif
-
-#include <assert.h>
-#include <limits.h>
 #include <stdio.h>
 #include "cryptlib.h"
-#include "bn_lcl.h"
+#include <openssl/evp.h>
+#include <openssl/dh.h>
 
-char *BN_options(void)
+#ifndef OPENSSL_NO_FP_API
+int DHparams_print_fp(FILE *fp, const DH *x)
        {
-       static int init=0;
-       static char data[16];
+       BIO *b;
+       int ret;
 
-       if (!init)
+       if ((b=BIO_new(BIO_s_file())) == NULL)
                {
-               init++;
-#ifdef BN_LLONG
-               BIO_snprintf(data,sizeof data,"bn(%d,%d)",
-                            (int)sizeof(BN_ULLONG)*8,(int)sizeof(BN_ULONG)*8);
-#else
-               BIO_snprintf(data,sizeof data,"bn(%d,%d)",
-                            (int)sizeof(BN_ULONG)*8,(int)sizeof(BN_ULONG)*8);
-#endif
+               DHerr(DH_F_DHPARAMS_PRINT_FP,ERR_R_BUF_LIB);
+               return(0);
                }
-       return(data);
+       BIO_set_fp(b,fp,BIO_NOCLOSE);
+       ret=DHparams_print(b, x);
+       BIO_free(b);
+       return(ret);
        }
+#endif
index 6c9578c..8073c4e 100644 (file)
@@ -18,14 +18,14 @@ APPS=
 
 LIB=$(TOP)/libcrypto.a
 LIBSRC= dsa_gen.c dsa_key.c dsa_lib.c dsa_asn1.c dsa_vrf.c dsa_sign.c \
-       dsa_err.c dsa_ossl.c dsa_depr.c dsa_utl.c
+       dsa_err.c dsa_ossl.c dsa_depr.c dsa_ameth.c dsa_pmeth.c dsa_prn.c
 LIBOBJ= dsa_gen.o dsa_key.o dsa_lib.o dsa_asn1.o dsa_vrf.o dsa_sign.o \
-       dsa_err.o dsa_ossl.o dsa_depr.o dsa_utl.o
+       dsa_err.o dsa_ossl.o dsa_depr.o dsa_ameth.o dsa_pmeth.o dsa_prn.o
 
 SRC= $(LIBSRC)
 
 EXHEADER= dsa.h
-HEADER=        $(EXHEADER)
+HEADER=        dsa_locl.h $(EXHEADER)
 
 ALL=    $(GENERAL) $(SRC) $(HEADER)
 
@@ -35,7 +35,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -76,25 +76,38 @@ clean:
 
 # DO NOT DELETE THIS LINE -- make depend depends on it.
 
+dsa_ameth.o: ../../e_os.h ../../include/openssl/asn1.h
+dsa_ameth.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
+dsa_ameth.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h
+dsa_ameth.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
+dsa_ameth.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+dsa_ameth.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
+dsa_ameth.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+dsa_ameth.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+dsa_ameth.o: ../../include/openssl/objects.h
+dsa_ameth.o: ../../include/openssl/opensslconf.h
+dsa_ameth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+dsa_ameth.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+dsa_ameth.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+dsa_ameth.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+dsa_ameth.o: ../../include/openssl/x509_vfy.h ../asn1/asn1_locl.h ../cryptlib.h
+dsa_ameth.o: dsa_ameth.c
 dsa_asn1.o: ../../e_os.h ../../include/openssl/asn1.h
 dsa_asn1.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
-dsa_asn1.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
-dsa_asn1.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
-dsa_asn1.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-dsa_asn1.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
+dsa_asn1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
+dsa_asn1.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
+dsa_asn1.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
 dsa_asn1.o: ../../include/openssl/opensslconf.h
 dsa_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-dsa_asn1.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
-dsa_asn1.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-dsa_asn1.o: ../cryptlib.h dsa_asn1.c
+dsa_asn1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+dsa_asn1.o: ../../include/openssl/symhacks.h ../cryptlib.h dsa_asn1.c
 dsa_depr.o: ../../e_os.h ../../include/openssl/asn1.h
 dsa_depr.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
 dsa_depr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 dsa_depr.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
 dsa_depr.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-dsa_depr.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-dsa_depr.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-dsa_depr.o: ../../include/openssl/opensslconf.h
+dsa_depr.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+dsa_depr.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 dsa_depr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 dsa_depr.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
 dsa_depr.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -111,13 +124,12 @@ dsa_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
 dsa_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 dsa_gen.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
 dsa_gen.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-dsa_gen.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-dsa_gen.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-dsa_gen.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-dsa_gen.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
-dsa_gen.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-dsa_gen.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-dsa_gen.o: ../cryptlib.h dsa_gen.c
+dsa_gen.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+dsa_gen.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+dsa_gen.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+dsa_gen.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
+dsa_gen.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+dsa_gen.o: ../../include/openssl/symhacks.h ../cryptlib.h dsa_gen.c dsa_locl.h
 dsa_key.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
 dsa_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 dsa_key.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
@@ -133,14 +145,14 @@ dsa_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
 dsa_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 dsa_lib.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 dsa_lib.o: ../../include/openssl/engine.h ../../include/openssl/err.h
-dsa_lib.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-dsa_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-dsa_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-dsa_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-dsa_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-dsa_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-dsa_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-dsa_lib.o: ../../include/openssl/x509_vfy.h ../cryptlib.h dsa_lib.c
+dsa_lib.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+dsa_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+dsa_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+dsa_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+dsa_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+dsa_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+dsa_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+dsa_lib.o: ../cryptlib.h dsa_lib.c
 dsa_ossl.o: ../../e_os.h ../../include/openssl/asn1.h
 dsa_ossl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
 dsa_ossl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
@@ -149,40 +161,48 @@ dsa_ossl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
 dsa_ossl.o: ../../include/openssl/opensslconf.h
 dsa_ossl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 dsa_ossl.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
-dsa_ossl.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-dsa_ossl.o: ../cryptlib.h dsa_ossl.c
-dsa_sign.o: ../../e_os.h ../../include/openssl/asn1.h
-dsa_sign.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
+dsa_ossl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+dsa_ossl.o: ../../include/openssl/symhacks.h ../cryptlib.h dsa_ossl.c
+dsa_pmeth.o: ../../e_os.h ../../include/openssl/asn1.h
+dsa_pmeth.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
+dsa_pmeth.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
+dsa_pmeth.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
+dsa_pmeth.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+dsa_pmeth.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
+dsa_pmeth.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+dsa_pmeth.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+dsa_pmeth.o: ../../include/openssl/objects.h
+dsa_pmeth.o: ../../include/openssl/opensslconf.h
+dsa_pmeth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+dsa_pmeth.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+dsa_pmeth.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+dsa_pmeth.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+dsa_pmeth.o: ../../include/openssl/x509_vfy.h ../cryptlib.h ../evp/evp_locl.h
+dsa_pmeth.o: dsa_locl.h dsa_pmeth.c
+dsa_prn.o: ../../e_os.h ../../include/openssl/asn1.h
+dsa_prn.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
+dsa_prn.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
+dsa_prn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
+dsa_prn.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+dsa_prn.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+dsa_prn.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+dsa_prn.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
+dsa_prn.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+dsa_prn.o: ../cryptlib.h dsa_prn.c
+dsa_sign.o: ../../e_os.h ../../include/openssl/bio.h
 dsa_sign.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 dsa_sign.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
-dsa_sign.o: ../../include/openssl/err.h ../../include/openssl/fips.h
-dsa_sign.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
+dsa_sign.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
+dsa_sign.o: ../../include/openssl/opensslconf.h
 dsa_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 dsa_sign.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
 dsa_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
 dsa_sign.o: ../cryptlib.h dsa_sign.c
-dsa_utl.o: ../../e_os.h ../../include/openssl/asn1.h
-dsa_utl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
-dsa_utl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
-dsa_utl.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
-dsa_utl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-dsa_utl.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
-dsa_utl.o: ../../include/openssl/engine.h ../../include/openssl/err.h
-dsa_utl.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-dsa_utl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-dsa_utl.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-dsa_utl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-dsa_utl.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-dsa_utl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-dsa_utl.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-dsa_utl.o: ../../include/openssl/x509_vfy.h ../cryptlib.h dsa_utl.c
-dsa_vrf.o: ../../e_os.h ../../include/openssl/asn1.h
-dsa_vrf.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
-dsa_vrf.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
-dsa_vrf.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
-dsa_vrf.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-dsa_vrf.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
+dsa_vrf.o: ../../e_os.h ../../include/openssl/bio.h
+dsa_vrf.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
+dsa_vrf.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
+dsa_vrf.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
 dsa_vrf.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-dsa_vrf.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
-dsa_vrf.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-dsa_vrf.o: ../../include/openssl/symhacks.h ../cryptlib.h dsa_vrf.c
+dsa_vrf.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
+dsa_vrf.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+dsa_vrf.o: ../cryptlib.h dsa_vrf.c
index 702c50d..ac50a5c 100644 (file)
@@ -88,8 +88,6 @@
 # define OPENSSL_DSA_MAX_MODULUS_BITS  10000
 #endif
 
-#define OPENSSL_DSA_FIPS_MIN_MODULUS_BITS 1024
-
 #define DSA_FLAG_CACHE_MONT_P  0x01
 #define DSA_FLAG_NO_EXP_CONSTTIME       0x02 /* new with 0.9.7h; the built-in DSA
                                               * implementation now uses constant time
                                               * be used for all exponents.
                                               */
 
-/* If this flag is set the DSA method is FIPS compliant and can be used
- * in FIPS mode. This is set in the validated module method. If an
- * application sets this flag in its own methods it is its reposibility
- * to ensure the result is compliant.
- */
-
-#define DSA_FLAG_FIPS_METHOD                   0x0400
-
-/* If this flag is set the operations normally disabled in FIPS mode are
- * permitted it is then the applications responsibility to ensure that the
- * usage is compliant.
- */
-
-#define DSA_FLAG_NON_FIPS_ALLOW                        0x0400
-
-#ifdef OPENSSL_FIPS
-#define FIPS_DSA_SIZE_T        int
-#endif
-
 #ifdef  __cplusplus
 extern "C" {
 #endif
@@ -139,7 +118,7 @@ struct dsa_method
        int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp,
                                                                BIGNUM **rp);
        int (*dsa_do_verify)(const unsigned char *dgst, int dgst_len,
-                                                       DSA_SIG *sig, DSA *dsa);
+                            DSA_SIG *sig, DSA *dsa);
        int (*dsa_mod_exp)(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
                        BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
                        BN_MONT_CTX *in_mont);
@@ -152,7 +131,7 @@ struct dsa_method
        char *app_data;
        /* If this is non-NULL, it is used to generate DSA parameters */
        int (*dsa_paramgen)(DSA *dsa, int bits,
-                       unsigned char *seed, int seed_len,
+                       const unsigned char *seed, int seed_len,
                        int *counter_ret, unsigned long *h_ret,
                        BN_GENCB *cb);
        /* If this is non-NULL, it is used to generate DSA keys */
@@ -186,7 +165,6 @@ struct dsa_st
        ENGINE *engine;
        };
 
-#define DSAparams_dup(x) ASN1_dup_of_const(DSA,i2d_DSAparams,d2i_DSAparams,x)
 #define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \
                (char *(*)())d2i_DSAparams,(fp),(unsigned char **)(x))
 #define i2d_DSAparams_fp(fp,x) ASN1_i2d_fp(i2d_DSAparams,(fp), \
@@ -195,6 +173,7 @@ struct dsa_st
 #define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio_of_const(DSA,i2d_DSAparams,bp,x)
 
 
+DSA *DSAparams_dup(DSA *x);
 DSA_SIG * DSA_SIG_new(void);
 void   DSA_SIG_free(DSA_SIG *a);
 int    i2d_DSA_SIG(const DSA_SIG *a, unsigned char **pp);
@@ -210,11 +189,6 @@ void       DSA_set_default_method(const DSA_METHOD *);
 const DSA_METHOD *DSA_get_default_method(void);
 int    DSA_set_method(DSA *dsa, const DSA_METHOD *);
 
-#ifdef OPENSSL_FIPS
-DSA *  FIPS_dsa_new(void);
-void   FIPS_dsa_free (DSA *r);
-#endif
-
 DSA *  DSA_new(void);
 DSA *  DSA_new_method(ENGINE *engine);
 void   DSA_free (DSA *r);
@@ -246,7 +220,7 @@ DSA *       DSA_generate_parameters(int bits,
 
 /* New version */
 int    DSA_generate_parameters_ex(DSA *dsa, int bits,
-               unsigned char *seed,int seed_len,
+               const unsigned char *seed,int seed_len,
                int *counter_ret, unsigned long *h_ret, BN_GENCB *cb);
 
 int    DSA_generate_key(DSA *a);
@@ -275,10 +249,13 @@ int       DSA_print_fp(FILE *bp, const DSA *x, int off);
 DH *DSA_dup_DH(const DSA *r);
 #endif
 
-#ifdef OPENSSL_FIPS
-int FIPS_dsa_sig_encode(unsigned char *out, DSA_SIG *sig);
-int FIPS_dsa_sig_decode(DSA_SIG *sig, const unsigned char *in, int inlen);
-#endif
+#define EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits) \
+       EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN, \
+                               EVP_PKEY_CTRL_DSA_PARAMGEN_BITS, nbits, NULL)
+
+#define        EVP_PKEY_CTRL_DSA_PARAMGEN_BITS         (EVP_PKEY_ALG_CTRL + 1)
+#define        EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS       (EVP_PKEY_ALG_CTRL + 2)
+#define        EVP_PKEY_CTRL_DSA_PARAMGEN_MD           (EVP_PKEY_ALG_CTRL + 3)
 
 /* BEGIN ERROR CODES */
 /* The following lines are auto generated by the script mkerr.pl. Any changes
@@ -290,33 +267,39 @@ void ERR_load_DSA_strings(void);
 
 /* Function codes. */
 #define DSA_F_D2I_DSA_SIG                               110
+#define DSA_F_DO_DSA_PRINT                              104
 #define DSA_F_DSAPARAMS_PRINT                           100
 #define DSA_F_DSAPARAMS_PRINT_FP                        101
-#define DSA_F_DSA_BUILTIN_KEYGEN                        119
-#define DSA_F_DSA_BUILTIN_PARAMGEN                      118
 #define DSA_F_DSA_DO_SIGN                               112
 #define DSA_F_DSA_DO_VERIFY                             113
-#define DSA_F_DSA_GENERATE_PARAMETERS                   117
 #define DSA_F_DSA_NEW_METHOD                            103
-#define DSA_F_DSA_PRINT                                         104
+#define DSA_F_DSA_PARAM_DECODE                          119
 #define DSA_F_DSA_PRINT_FP                              105
-#define DSA_F_DSA_SET_DEFAULT_METHOD                    115
-#define DSA_F_DSA_SET_METHOD                            116
+#define DSA_F_DSA_PRIV_DECODE                           115
+#define DSA_F_DSA_PRIV_ENCODE                           116
+#define DSA_F_DSA_PUB_DECODE                            117
+#define DSA_F_DSA_PUB_ENCODE                            118
 #define DSA_F_DSA_SIGN                                  106
 #define DSA_F_DSA_SIGN_SETUP                            107
 #define DSA_F_DSA_SIG_NEW                               109
 #define DSA_F_DSA_VERIFY                                108
 #define DSA_F_I2D_DSA_SIG                               111
+#define DSA_F_OLD_DSA_PRIV_DECODE                       122
+#define DSA_F_PKEY_DSA_CTRL                             120
+#define DSA_F_PKEY_DSA_KEYGEN                           121
 #define DSA_F_SIG_CB                                    114
 
 /* Reason codes. */
 #define DSA_R_BAD_Q_VALUE                               102
+#define DSA_R_BN_DECODE_ERROR                           108
+#define DSA_R_BN_ERROR                                  109
 #define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE               100
-#define DSA_R_KEY_SIZE_TOO_SMALL                        106
+#define DSA_R_DECODE_ERROR                              104
+#define DSA_R_INVALID_DIGEST_TYPE                       106
 #define DSA_R_MISSING_PARAMETERS                        101
 #define DSA_R_MODULUS_TOO_LARGE                                 103
-#define DSA_R_NON_FIPS_METHOD                           104
-#define DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE        105
+#define DSA_R_NO_PARAMETERS_SET                                 107
+#define DSA_R_PARAMETER_ENCODING_ERROR                  105
 
 #ifdef  __cplusplus
 }
diff --git a/deps/openssl/openssl/crypto/dsa/dsa_ameth.c b/deps/openssl/openssl/crypto/dsa/dsa_ameth.c
new file mode 100644 (file)
index 0000000..6413aae
--- /dev/null
@@ -0,0 +1,657 @@
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project 2006.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include "cryptlib.h"
+#include <openssl/x509.h>
+#include <openssl/asn1.h>
+#include <openssl/dsa.h>
+#include <openssl/bn.h>
+#ifndef OPENSSL_NO_CMS
+#include <openssl/cms.h>
+#endif
+#include "asn1_locl.h"
+
+static int dsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
+       {
+       const unsigned char *p, *pm;
+       int pklen, pmlen;
+       int ptype;
+       void *pval;
+       ASN1_STRING *pstr;
+       X509_ALGOR *palg;
+       ASN1_INTEGER *public_key = NULL;
+
+       DSA *dsa = NULL;
+
+       if (!X509_PUBKEY_get0_param(NULL, &p, &pklen, &palg, pubkey))
+               return 0;
+       X509_ALGOR_get0(NULL, &ptype, &pval, palg);
+
+
+       if (ptype == V_ASN1_SEQUENCE)
+               {
+               pstr = pval;    
+               pm = pstr->data;
+               pmlen = pstr->length;
+
+               if (!(dsa = d2i_DSAparams(NULL, &pm, pmlen)))
+                       {
+                       DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_DECODE_ERROR);
+                       goto err;
+                       }
+
+               }
+       else if ((ptype == V_ASN1_NULL) || (ptype == V_ASN1_UNDEF))
+               {
+               if (!(dsa = DSA_new()))
+                       {
+                       DSAerr(DSA_F_DSA_PUB_DECODE, ERR_R_MALLOC_FAILURE);
+                       goto err;
+                       }
+               }
+       else
+               {
+               DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_PARAMETER_ENCODING_ERROR);
+               goto err;
+               }
+
+       if (!(public_key=d2i_ASN1_INTEGER(NULL, &p, pklen)))
+               {
+               DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_DECODE_ERROR);
+               goto err;
+               }
+
+       if (!(dsa->pub_key = ASN1_INTEGER_to_BN(public_key, NULL)))
+               {
+               DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_BN_DECODE_ERROR);
+               goto err;
+               }
+
+       ASN1_INTEGER_free(public_key);
+       EVP_PKEY_assign_DSA(pkey, dsa);
+       return 1;
+
+       err:
+       if (public_key)
+               ASN1_INTEGER_free(public_key);
+       if (dsa)
+               DSA_free(dsa);
+       return 0;
+
+       }
+
+static int dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
+       {
+       DSA *dsa;
+       void *pval = NULL;
+       int ptype;
+       unsigned char *penc = NULL;
+       int penclen;
+
+       dsa=pkey->pkey.dsa;
+       if (pkey->save_parameters && dsa->p && dsa->q && dsa->g)
+               {
+               ASN1_STRING *str;
+               str = ASN1_STRING_new();
+               str->length = i2d_DSAparams(dsa, &str->data);
+               if (str->length <= 0)
+                       {
+                       DSAerr(DSA_F_DSA_PUB_ENCODE, ERR_R_MALLOC_FAILURE);
+                       goto err;
+                       }
+               pval = str;
+               ptype = V_ASN1_SEQUENCE;
+               }
+       else
+               ptype = V_ASN1_UNDEF;
+
+       dsa->write_params=0;
+
+       penclen = i2d_DSAPublicKey(dsa, &penc);
+
+       if (penclen <= 0)
+               {
+               DSAerr(DSA_F_DSA_PUB_ENCODE, ERR_R_MALLOC_FAILURE);
+               goto err;
+               }
+
+       if (X509_PUBKEY_set0_param(pk, OBJ_nid2obj(EVP_PKEY_DSA),
+                               ptype, pval, penc, penclen))
+               return 1;
+
+       err:
+       if (penc)
+               OPENSSL_free(penc);
+       if (pval)
+               ASN1_STRING_free(pval);
+
+       return 0;
+       }
+
+/* In PKCS#8 DSA: you just get a private key integer and parameters in the
+ * AlgorithmIdentifier the pubkey must be recalculated.
+ */
+       
+static int dsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8)
+       {
+       const unsigned char *p, *pm;
+       int pklen, pmlen;
+       int ptype;
+       void *pval;
+       ASN1_STRING *pstr;
+       X509_ALGOR *palg;
+       ASN1_INTEGER *privkey = NULL;
+       BN_CTX *ctx = NULL;
+
+       STACK_OF(ASN1_TYPE) *ndsa = NULL;
+       DSA *dsa = NULL;
+
+       if (!PKCS8_pkey_get0(NULL, &p, &pklen, &palg, p8))
+               return 0;
+       X509_ALGOR_get0(NULL, &ptype, &pval, palg);
+
+       /* Check for broken DSA PKCS#8, UGH! */
+       if (*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED))
+               {
+               ASN1_TYPE *t1, *t2;
+               if(!(ndsa = d2i_ASN1_SEQUENCE_ANY(NULL, &p, pklen)))
+                       goto decerr;
+               if (sk_ASN1_TYPE_num(ndsa) != 2)
+                       goto decerr;
+               /* Handle Two broken types:
+                * SEQUENCE {parameters, priv_key}
+                * SEQUENCE {pub_key, priv_key}
+                */
+
+               t1 = sk_ASN1_TYPE_value(ndsa, 0);
+               t2 = sk_ASN1_TYPE_value(ndsa, 1);
+               if (t1->type == V_ASN1_SEQUENCE)
+                       {
+                       p8->broken = PKCS8_EMBEDDED_PARAM;
+                       pval = t1->value.ptr;
+                       }
+               else if (ptype == V_ASN1_SEQUENCE)
+                       p8->broken = PKCS8_NS_DB;
+               else
+                       goto decerr;
+
+               if (t2->type != V_ASN1_INTEGER)
+                       goto decerr;
+
+               privkey = t2->value.integer;
+               }
+       else
+               {
+               const unsigned char *q = p;
+               if (!(privkey=d2i_ASN1_INTEGER(NULL, &p, pklen)))
+                       goto decerr;
+               if (privkey->type == V_ASN1_NEG_INTEGER)
+                       {
+                       p8->broken = PKCS8_NEG_PRIVKEY;
+                       ASN1_INTEGER_free(privkey);
+                       if (!(privkey=d2i_ASN1_UINTEGER(NULL, &q, pklen)))
+                               goto decerr;
+                       }
+               if (ptype != V_ASN1_SEQUENCE)
+                       goto decerr;
+               }
+
+       pstr = pval;    
+       pm = pstr->data;
+       pmlen = pstr->length;
+       if (!(dsa = d2i_DSAparams(NULL, &pm, pmlen)))
+               goto decerr;
+       /* We have parameters now set private key */
+       if (!(dsa->priv_key = ASN1_INTEGER_to_BN(privkey, NULL)))
+               {
+               DSAerr(DSA_F_DSA_PRIV_DECODE,DSA_R_BN_ERROR);
+               goto dsaerr;
+               }
+       /* Calculate public key */
+       if (!(dsa->pub_key = BN_new()))
+               {
+               DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE);
+               goto dsaerr;
+               }
+       if (!(ctx = BN_CTX_new()))
+               {
+               DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE);
+               goto dsaerr;
+               }
+                       
+       if (!BN_mod_exp(dsa->pub_key, dsa->g, dsa->priv_key, dsa->p, ctx))
+               {
+               DSAerr(DSA_F_DSA_PRIV_DECODE,DSA_R_BN_ERROR);
+               goto dsaerr;
+               }
+
+       EVP_PKEY_assign_DSA(pkey, dsa);
+       BN_CTX_free (ctx);
+       if(ndsa)
+               sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
+       else
+               ASN1_INTEGER_free(privkey);
+
+       return 1;
+
+       decerr:
+       DSAerr(DSA_F_DSA_PRIV_DECODE, EVP_R_DECODE_ERROR);
+       dsaerr:
+       BN_CTX_free (ctx);
+       if (privkey)
+               ASN1_INTEGER_free(privkey);
+       sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
+       DSA_free(dsa);
+       return 0;
+       }
+
+static int dsa_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
+{
+       ASN1_STRING *params = NULL;
+       ASN1_INTEGER *prkey = NULL;
+       unsigned char *dp = NULL;
+       int dplen;
+
+       params = ASN1_STRING_new();
+
+       if (!params)
+               {
+               DSAerr(DSA_F_DSA_PRIV_ENCODE,ERR_R_MALLOC_FAILURE);
+               goto err;
+               }
+
+       params->length = i2d_DSAparams(pkey->pkey.dsa, &params->data);
+       if (params->length <= 0)
+               {
+               DSAerr(DSA_F_DSA_PRIV_ENCODE,ERR_R_MALLOC_FAILURE);
+               goto err;
+               }
+       params->type = V_ASN1_SEQUENCE;
+
+       /* Get private key into integer */
+       prkey = BN_to_ASN1_INTEGER(pkey->pkey.dsa->priv_key, NULL);
+
+       if (!prkey)
+               {
+               DSAerr(DSA_F_DSA_PRIV_ENCODE,DSA_R_BN_ERROR);
+               goto err;
+               }
+
+       dplen = i2d_ASN1_INTEGER(prkey, &dp);
+
+       ASN1_INTEGER_free(prkey);
+
+       if (!PKCS8_pkey_set0(p8, OBJ_nid2obj(NID_dsa), 0,
+                               V_ASN1_SEQUENCE, params, dp, dplen))
+               goto err;
+
+       return 1;
+
+err:
+       if (dp != NULL)
+               OPENSSL_free(dp);
+       if (params != NULL)
+               ASN1_STRING_free(params);
+       if (prkey != NULL)
+               ASN1_INTEGER_free(prkey);
+       return 0;
+}
+
+static int int_dsa_size(const EVP_PKEY *pkey)
+       {
+       return(DSA_size(pkey->pkey.dsa));
+       }
+
+static int dsa_bits(const EVP_PKEY *pkey)
+       {
+       return BN_num_bits(pkey->pkey.dsa->p);
+       }
+
+static int dsa_missing_parameters(const EVP_PKEY *pkey)
+       {
+       DSA *dsa;
+       dsa=pkey->pkey.dsa;
+       if ((dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL))
+                       return 1;
+       return 0;
+       }
+
+static int dsa_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)
+       {
+       BIGNUM *a;
+
+       if ((a=BN_dup(from->pkey.dsa->p)) == NULL)
+               return 0;
+       if (to->pkey.dsa->p != NULL)
+               BN_free(to->pkey.dsa->p);
+       to->pkey.dsa->p=a;
+
+       if ((a=BN_dup(from->pkey.dsa->q)) == NULL)
+               return 0;
+       if (to->pkey.dsa->q != NULL)
+               BN_free(to->pkey.dsa->q);
+       to->pkey.dsa->q=a;
+
+       if ((a=BN_dup(from->pkey.dsa->g)) == NULL)
+               return 0;
+       if (to->pkey.dsa->g != NULL)
+               BN_free(to->pkey.dsa->g);
+       to->pkey.dsa->g=a;
+       return 1;
+       }
+
+static int dsa_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b)
+       {
+       if (    BN_cmp(a->pkey.dsa->p,b->pkey.dsa->p) ||
+               BN_cmp(a->pkey.dsa->q,b->pkey.dsa->q) ||
+               BN_cmp(a->pkey.dsa->g,b->pkey.dsa->g))
+               return 0;
+       else
+               return 1;
+       }
+
+static int dsa_pub_cmp(const EVP_PKEY *a, const EVP_PKEY *b)
+       {
+       if (BN_cmp(b->pkey.dsa->pub_key,a->pkey.dsa->pub_key) != 0)
+               return 0;
+       else
+               return 1;
+       }
+
+static void int_dsa_free(EVP_PKEY *pkey)
+       {
+       DSA_free(pkey->pkey.dsa);
+       }
+
+static void update_buflen(const BIGNUM *b, size_t *pbuflen)
+       {
+       size_t i;
+       if (!b)
+               return;
+       if (*pbuflen < (i = (size_t)BN_num_bytes(b)))
+                       *pbuflen = i;
+       }
+
+static int do_dsa_print(BIO *bp, const DSA *x, int off, int ptype)
+       {
+       unsigned char *m=NULL;
+       int ret=0;
+       size_t buf_len=0;
+       const char *ktype = NULL;
+
+       const BIGNUM *priv_key, *pub_key;
+
+       if (ptype == 2)
+               priv_key = x->priv_key;
+       else
+               priv_key = NULL;
+
+       if (ptype > 0)
+               pub_key = x->pub_key;
+       else
+               pub_key = NULL;
+
+       if (ptype == 2)
+               ktype = "Private-Key";
+       else if (ptype == 1)
+               ktype = "Public-Key";
+       else
+               ktype = "DSA-Parameters";
+
+       update_buflen(x->p, &buf_len);
+       update_buflen(x->q, &buf_len);
+       update_buflen(x->g, &buf_len);
+       update_buflen(priv_key, &buf_len);
+       update_buflen(pub_key, &buf_len);
+
+       m=(unsigned char *)OPENSSL_malloc(buf_len+10);
+       if (m == NULL)
+               {
+               DSAerr(DSA_F_DO_DSA_PRINT,ERR_R_MALLOC_FAILURE);
+               goto err;
+               }
+
+       if (priv_key)
+               {
+               if(!BIO_indent(bp,off,128))
+                  goto err;
+               if (BIO_printf(bp,"%s: (%d bit)\n",ktype, BN_num_bits(x->p))
+                       <= 0) goto err;
+               }
+
+       if (!ASN1_bn_print(bp,"priv:",priv_key,m,off))
+               goto err;
+       if (!ASN1_bn_print(bp,"pub: ",pub_key,m,off))
+               goto err;
+       if (!ASN1_bn_print(bp,"P:   ",x->p,m,off)) goto err;
+       if (!ASN1_bn_print(bp,"Q:   ",x->q,m,off)) goto err;
+       if (!ASN1_bn_print(bp,"G:   ",x->g,m,off)) goto err;
+       ret=1;
+err:
+       if (m != NULL) OPENSSL_free(m);
+       return(ret);
+       }
+
+static int dsa_param_decode(EVP_PKEY *pkey,
+                                       const unsigned char **pder, int derlen)
+       {
+       DSA *dsa;
+       if (!(dsa = d2i_DSAparams(NULL, pder, derlen)))
+               {
+               DSAerr(DSA_F_DSA_PARAM_DECODE, ERR_R_DSA_LIB);
+               return 0;
+               }
+       EVP_PKEY_assign_DSA(pkey, dsa);
+       return 1;
+       }
+
+static int dsa_param_encode(const EVP_PKEY *pkey, unsigned char **pder)
+       {
+       return i2d_DSAparams(pkey->pkey.dsa, pder);
+       }
+
+static int dsa_param_print(BIO *bp, const EVP_PKEY *pkey, int indent,
+                                                       ASN1_PCTX *ctx)
+       {
+       return do_dsa_print(bp, pkey->pkey.dsa, indent, 0);
+       }
+
+static int dsa_pub_print(BIO *bp, const EVP_PKEY *pkey, int indent,
+                                                       ASN1_PCTX *ctx)
+       {
+       return do_dsa_print(bp, pkey->pkey.dsa, indent, 1);
+       }
+
+
+static int dsa_priv_print(BIO *bp, const EVP_PKEY *pkey, int indent,
+                                                       ASN1_PCTX *ctx)
+       {
+       return do_dsa_print(bp, pkey->pkey.dsa, indent, 2);
+       }
+
+static int old_dsa_priv_decode(EVP_PKEY *pkey,
+                                       const unsigned char **pder, int derlen)
+       {
+       DSA *dsa;
+       if (!(dsa = d2i_DSAPrivateKey (NULL, pder, derlen)))
+               {
+               DSAerr(DSA_F_OLD_DSA_PRIV_DECODE, ERR_R_DSA_LIB);
+               return 0;
+               }
+       EVP_PKEY_assign_DSA(pkey, dsa);
+       return 1;
+       }
+
+static int old_dsa_priv_encode(const EVP_PKEY *pkey, unsigned char **pder)
+       {
+       return i2d_DSAPrivateKey(pkey->pkey.dsa, pder);
+       }
+
+static int dsa_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
+       {
+       switch (op)
+               {
+               case ASN1_PKEY_CTRL_PKCS7_SIGN:
+               if (arg1 == 0)
+                       {
+                       int snid, hnid;
+                       X509_ALGOR *alg1, *alg2;
+                       PKCS7_SIGNER_INFO_get0_algs(arg2, NULL, &alg1, &alg2);
+                       if (alg1 == NULL || alg1->algorithm == NULL)
+                               return -1;
+                       hnid = OBJ_obj2nid(alg1->algorithm);
+                       if (hnid == NID_undef)
+                               return -1;
+                       if (!OBJ_find_sigid_by_algs(&snid, hnid, EVP_PKEY_id(pkey)))
+                               return -1; 
+                       X509_ALGOR_set0(alg2, OBJ_nid2obj(snid), V_ASN1_UNDEF, 0);
+                       }
+               return 1;
+#ifndef OPENSSL_NO_CMS
+               case ASN1_PKEY_CTRL_CMS_SIGN:
+               if (arg1 == 0)
+                       {
+                       int snid, hnid;
+                       X509_ALGOR *alg1, *alg2;
+                       CMS_SignerInfo_get0_algs(arg2, NULL, NULL, &alg1, &alg2);
+                       if (alg1 == NULL || alg1->algorithm == NULL)
+                               return -1;
+                       hnid = OBJ_obj2nid(alg1->algorithm);
+                       if (hnid == NID_undef)
+                               return -1;
+                       if (!OBJ_find_sigid_by_algs(&snid, hnid, EVP_PKEY_id(pkey)))
+                               return -1; 
+                       X509_ALGOR_set0(alg2, OBJ_nid2obj(snid), V_ASN1_UNDEF, 0);
+                       }
+               return 1;
+#endif
+
+               case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
+               *(int *)arg2 = NID_sha1;
+               return 2;
+
+               default:
+               return -2;
+
+               }
+
+       }
+
+/* NB these are sorted in pkey_id order, lowest first */
+
+const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[] = 
+       {
+
+               {
+               EVP_PKEY_DSA2,
+               EVP_PKEY_DSA,
+               ASN1_PKEY_ALIAS
+               },
+
+               {
+               EVP_PKEY_DSA1,
+               EVP_PKEY_DSA,
+               ASN1_PKEY_ALIAS
+               },
+
+               {
+               EVP_PKEY_DSA4,
+               EVP_PKEY_DSA,
+               ASN1_PKEY_ALIAS
+               },
+
+               {
+               EVP_PKEY_DSA3,
+               EVP_PKEY_DSA,
+               ASN1_PKEY_ALIAS
+               },
+
+               {
+               EVP_PKEY_DSA,
+               EVP_PKEY_DSA,
+               0,
+
+               "DSA",
+               "OpenSSL DSA method",
+
+               dsa_pub_decode,
+               dsa_pub_encode,
+               dsa_pub_cmp,
+               dsa_pub_print,
+
+               dsa_priv_decode,
+               dsa_priv_encode,
+               dsa_priv_print,
+
+               int_dsa_size,
+               dsa_bits,
+
+               dsa_param_decode,
+               dsa_param_encode,
+               dsa_missing_parameters,
+               dsa_copy_parameters,
+               dsa_cmp_parameters,
+               dsa_param_print,
+
+               int_dsa_free,
+               dsa_pkey_ctrl,
+               old_dsa_priv_decode,
+               old_dsa_priv_encode
+               }
+       };
+
index bc7d7a0..c37460b 100644 (file)
@@ -3,7 +3,7 @@
  * project 2000.
  */
 /* ====================================================================
- * Copyright (c) 2000 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 2000-2005 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include <openssl/dsa.h>
 #include <openssl/asn1.h>
 #include <openssl/asn1t.h>
-#include <openssl/bn.h>
-#include <openssl/rand.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
 
 /* Override the default new methods */
-static int sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
+static int sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
+                                                               void *exarg)
 {
        if(operation == ASN1_OP_NEW_PRE) {
                DSA_SIG *sig;
                sig = OPENSSL_malloc(sizeof(DSA_SIG));
+               if (!sig)
+                       {
+                       DSAerr(DSA_F_SIG_CB, ERR_R_MALLOC_FAILURE);
+                       return 0;
+                       }
                sig->r = NULL;
                sig->s = NULL;
                *pval = (ASN1_VALUE *)sig;
-               if(sig) return 2;
-               DSAerr(DSA_F_SIG_CB, ERR_R_MALLOC_FAILURE);
-               return 0;
+               return 2;
        }
        return 1;
 }
@@ -89,10 +87,11 @@ ASN1_SEQUENCE_cb(DSA_SIG, sig_cb) = {
        ASN1_SIMPLE(DSA_SIG, s, CBIGNUM)
 } ASN1_SEQUENCE_END_cb(DSA_SIG, DSA_SIG)
 
-IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA_SIG,DSA_SIG,DSA_SIG)
+IMPLEMENT_ASN1_FUNCTIONS_const(DSA_SIG)
 
 /* Override the default free and new methods */
-static int dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
+static int dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
+                                                       void *exarg)
 {
        if(operation == ASN1_OP_NEW_PRE) {
                *pval = (ASN1_VALUE *)DSA_new();
@@ -145,76 +144,7 @@ ASN1_CHOICE_cb(DSAPublicKey, dsa_cb) = {
 
 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAPublicKey, DSAPublicKey)
 
-int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig,
-            unsigned int *siglen, DSA *dsa)
-       {
-       DSA_SIG *s;
-#ifdef OPENSSL_FIPS
-       if(FIPS_mode() && !(dsa->flags & DSA_FLAG_NON_FIPS_ALLOW))
-               {
-               DSAerr(DSA_F_DSA_SIGN, DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE);
-               return 0;
-               }
-#endif
-       RAND_seed(dgst, dlen);
-       s=DSA_do_sign(dgst,dlen,dsa);
-       if (s == NULL)
-               {
-               *siglen=0;
-               return(0);
-               }
-       *siglen=i2d_DSA_SIG(s,&sig);
-       DSA_SIG_free(s);
-       return(1);
-       }
-
-int DSA_size(const DSA *r)
-       {
-       int ret,i;
-       ASN1_INTEGER bs;
-       unsigned char buf[4];   /* 4 bytes looks really small.
-                                  However, i2d_ASN1_INTEGER() will not look
-                                  beyond the first byte, as long as the second
-                                  parameter is NULL. */
-
-       i=BN_num_bits(r->q);
-       bs.length=(i+7)/8;
-       bs.data=buf;
-       bs.type=V_ASN1_INTEGER;
-       /* If the top bit is set the asn1 encoding is 1 larger. */
-       buf[0]=0xff;    
-
-       i=i2d_ASN1_INTEGER(&bs,NULL);
-       i+=i; /* r and s */
-       ret=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
-       return(ret);
-       }
-
-/* data has already been hashed (probably with SHA or SHA-1). */
-/* returns
- *      1: correct signature
- *      0: incorrect signature
- *     -1: error
- */
-int DSA_verify(int type, const unsigned char *dgst, int dgst_len,
-            const unsigned char *sigbuf, int siglen, DSA *dsa)
+DSA *DSAparams_dup(DSA *dsa)
        {
-       DSA_SIG *s;
-       int ret=-1;
-#ifdef OPENSSL_FIPS
-       if(FIPS_mode() && !(dsa->flags & DSA_FLAG_NON_FIPS_ALLOW))
-               {
-               DSAerr(DSA_F_DSA_VERIFY, DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE);
-               return 0;
-               }
-#endif
-
-       s = DSA_SIG_new();
-       if (s == NULL) return(ret);
-       if (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err;
-       ret=DSA_do_verify(dgst,dgst_len,s,dsa);
-err:
-       DSA_SIG_free(s);
-       return(ret);
+       return ASN1_item_dup(ASN1_ITEM_rptr(DSAparams), dsa);
        }
-
index 872839a..bba984e 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/dsa/dsa_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2007 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 static ERR_STRING_DATA DSA_str_functs[]=
        {
 {ERR_FUNC(DSA_F_D2I_DSA_SIG),  "d2i_DSA_SIG"},
+{ERR_FUNC(DSA_F_DO_DSA_PRINT), "DO_DSA_PRINT"},
 {ERR_FUNC(DSA_F_DSAPARAMS_PRINT),      "DSAparams_print"},
 {ERR_FUNC(DSA_F_DSAPARAMS_PRINT_FP),   "DSAparams_print_fp"},
-{ERR_FUNC(DSA_F_DSA_BUILTIN_KEYGEN),   "DSA_BUILTIN_KEYGEN"},
-{ERR_FUNC(DSA_F_DSA_BUILTIN_PARAMGEN), "DSA_BUILTIN_PARAMGEN"},
 {ERR_FUNC(DSA_F_DSA_DO_SIGN),  "DSA_do_sign"},
 {ERR_FUNC(DSA_F_DSA_DO_VERIFY),        "DSA_do_verify"},
-{ERR_FUNC(DSA_F_DSA_GENERATE_PARAMETERS),      "DSA_generate_parameters"},
 {ERR_FUNC(DSA_F_DSA_NEW_METHOD),       "DSA_new_method"},
-{ERR_FUNC(DSA_F_DSA_PRINT),    "DSA_print"},
+{ERR_FUNC(DSA_F_DSA_PARAM_DECODE),     "DSA_PARAM_DECODE"},
 {ERR_FUNC(DSA_F_DSA_PRINT_FP), "DSA_print_fp"},
-{ERR_FUNC(DSA_F_DSA_SET_DEFAULT_METHOD),       "DSA_set_default_method"},
-{ERR_FUNC(DSA_F_DSA_SET_METHOD),       "DSA_set_method"},
+{ERR_FUNC(DSA_F_DSA_PRIV_DECODE),      "DSA_PRIV_DECODE"},
+{ERR_FUNC(DSA_F_DSA_PRIV_ENCODE),      "DSA_PRIV_ENCODE"},
+{ERR_FUNC(DSA_F_DSA_PUB_DECODE),       "DSA_PUB_DECODE"},
+{ERR_FUNC(DSA_F_DSA_PUB_ENCODE),       "DSA_PUB_ENCODE"},
 {ERR_FUNC(DSA_F_DSA_SIGN),     "DSA_sign"},
 {ERR_FUNC(DSA_F_DSA_SIGN_SETUP),       "DSA_sign_setup"},
 {ERR_FUNC(DSA_F_DSA_SIG_NEW),  "DSA_SIG_new"},
 {ERR_FUNC(DSA_F_DSA_VERIFY),   "DSA_verify"},
 {ERR_FUNC(DSA_F_I2D_DSA_SIG),  "i2d_DSA_SIG"},
+{ERR_FUNC(DSA_F_OLD_DSA_PRIV_DECODE),  "OLD_DSA_PRIV_DECODE"},
+{ERR_FUNC(DSA_F_PKEY_DSA_CTRL),        "PKEY_DSA_CTRL"},
+{ERR_FUNC(DSA_F_PKEY_DSA_KEYGEN),      "PKEY_DSA_KEYGEN"},
 {ERR_FUNC(DSA_F_SIG_CB),       "SIG_CB"},
 {0,NULL}
        };
@@ -95,12 +98,15 @@ static ERR_STRING_DATA DSA_str_functs[]=
 static ERR_STRING_DATA DSA_str_reasons[]=
        {
 {ERR_REASON(DSA_R_BAD_Q_VALUE)           ,"bad q value"},
+{ERR_REASON(DSA_R_BN_DECODE_ERROR)       ,"bn decode error"},
+{ERR_REASON(DSA_R_BN_ERROR)              ,"bn error"},
 {ERR_REASON(DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE),"data too large for key size"},
-{ERR_REASON(DSA_R_KEY_SIZE_TOO_SMALL)    ,"key size too small"},
+{ERR_REASON(DSA_R_DECODE_ERROR)          ,"decode error"},
+{ERR_REASON(DSA_R_INVALID_DIGEST_TYPE)   ,"invalid digest type"},
 {ERR_REASON(DSA_R_MISSING_PARAMETERS)    ,"missing parameters"},
 {ERR_REASON(DSA_R_MODULUS_TOO_LARGE)     ,"modulus too large"},
-{ERR_REASON(DSA_R_NON_FIPS_METHOD)       ,"non fips method"},
-{ERR_REASON(DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE),"operation not allowed in fips mode"},
+{ERR_REASON(DSA_R_NO_PARAMETERS_SET)     ,"no parameters set"},
+{ERR_REASON(DSA_R_PARAMETER_ENCODING_ERROR),"parameter encoding error"},
 {0,NULL}
        };
 
index 7a9d188..cb0b453 100644 (file)
 #ifndef OPENSSL_NO_SHA
 
 #include <stdio.h>
-#include <time.h>
 #include "cryptlib.h"
 #include <openssl/evp.h>
 #include <openssl/bn.h>
-#include <openssl/dsa.h>
 #include <openssl/rand.h>
 #include <openssl/sha.h>
-
-#ifndef OPENSSL_FIPS
-
-static int dsa_builtin_paramgen(DSA *ret, int bits,
-               unsigned char *seed_in, int seed_len,
-               int *counter_ret, unsigned long *h_ret, BN_GENCB *cb);
+#include "dsa_locl.h"
 
 int DSA_generate_parameters_ex(DSA *ret, int bits,
-               unsigned char *seed_in, int seed_len,
+               const unsigned char *seed_in, int seed_len,
                int *counter_ret, unsigned long *h_ret, BN_GENCB *cb)
        {
        if(ret->meth->dsa_paramgen)
                return ret->meth->dsa_paramgen(ret, bits, seed_in, seed_len,
                                counter_ret, h_ret, cb);
-       return dsa_builtin_paramgen(ret, bits, seed_in, seed_len,
-                       counter_ret, h_ret, cb);
+       else
+               {
+               const EVP_MD *evpmd;
+               size_t qbits = bits >= 2048 ? 256 : 160;
+
+               if (bits >= 2048)
+                       {
+                       qbits = 256;
+                       evpmd = EVP_sha256();
+                       }
+               else
+                       {
+                       qbits = 160;
+                       evpmd = EVP_sha1();
+                       }
+
+               return dsa_builtin_paramgen(ret, bits, qbits, evpmd,
+                               seed_in, seed_len, counter_ret, h_ret, cb);
+               }
        }
 
-static int dsa_builtin_paramgen(DSA *ret, int bits,
-               unsigned char *seed_in, int seed_len,
-               int *counter_ret, unsigned long *h_ret, BN_GENCB *cb)
+int dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits,
+       const EVP_MD *evpmd, const unsigned char *seed_in, size_t seed_len,
+       int *counter_ret, unsigned long *h_ret, BN_GENCB *cb)
        {
        int ok=0;
-       unsigned char seed[SHA_DIGEST_LENGTH];
-       unsigned char md[SHA_DIGEST_LENGTH];
-       unsigned char buf[SHA_DIGEST_LENGTH],buf2[SHA_DIGEST_LENGTH];
+       unsigned char seed[SHA256_DIGEST_LENGTH];
+       unsigned char md[SHA256_DIGEST_LENGTH];
+       unsigned char buf[SHA256_DIGEST_LENGTH],buf2[SHA256_DIGEST_LENGTH];
        BIGNUM *r0,*W,*X,*c,*test;
        BIGNUM *g=NULL,*q=NULL,*p=NULL;
        BN_MONT_CTX *mont=NULL;
-       int k,n=0,i,m=0;
+       int i, k, n=0, m=0, qsize = qbits >> 3;
        int counter=0;
        int r=0;
        BN_CTX *ctx=NULL;
        unsigned int h=2;
 
-       if (bits < 512) bits=512;
-       bits=(bits+63)/64*64;
+       if (qsize != SHA_DIGEST_LENGTH && qsize != SHA224_DIGEST_LENGTH &&
+           qsize != SHA256_DIGEST_LENGTH)
+               /* invalid q size */
+               return 0;
+
+       if (evpmd == NULL)
+               /* use SHA1 as default */
+               evpmd = EVP_sha1();
+
+       if (bits < 512)
+               bits = 512;
+
+       bits = (bits+63)/64*64;
 
        /* NB: seed_len == 0 is special case: copy generated seed to
         * seed_in if it is not NULL.
         */
-       if (seed_len && (seed_len < 20))
-               seed_in = NULL; /* seed buffer too small -- ignore */
-       if (seed_len > 20) 
-               seed_len = 20; /* App. 2.2 of FIPS PUB 186 allows larger SEED,
-                               * but our internal buffers are restricted to 160 bits*/
-       if ((seed_in != NULL) && (seed_len == 20))
-               {
-               memcpy(seed,seed_in,seed_len);
-               /* set seed_in to NULL to avoid it being copied back */
-               seed_in = NULL;
-               }
-
-       if ((ctx=BN_CTX_new()) == NULL) goto err;
+       if (seed_len && (seed_len < (size_t)qsize))
+               seed_in = NULL;         /* seed buffer too small -- ignore */
+       if (seed_len > (size_t)qsize) 
+               seed_len = qsize;       /* App. 2.2 of FIPS PUB 186 allows larger SEED,
+                                        * but our internal buffers are restricted to 160 bits*/
+       if (seed_in != NULL)
+               memcpy(seed, seed_in, seed_len);
+
+       if ((ctx=BN_CTX_new()) == NULL)
+               goto err;
 
-       if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
+       if ((mont=BN_MONT_CTX_new()) == NULL)
+               goto err;
 
        BN_CTX_start(ctx);
        r0 = BN_CTX_get(ctx);
@@ -163,7 +182,7 @@ static int dsa_builtin_paramgen(DSA *ret, int bits,
 
                        if (!seed_len)
                                {
-                               RAND_pseudo_bytes(seed,SHA_DIGEST_LENGTH);
+                               RAND_pseudo_bytes(seed, qsize);
                                seed_is_random = 1;
                                }
                        else
@@ -171,25 +190,27 @@ static int dsa_builtin_paramgen(DSA *ret, int bits,
                                seed_is_random = 0;
                                seed_len=0; /* use random seed if 'seed_in' turns out to be bad*/
                                }
-                       memcpy(buf,seed,SHA_DIGEST_LENGTH);
-                       memcpy(buf2,seed,SHA_DIGEST_LENGTH);
+                       memcpy(buf , seed, qsize);
+                       memcpy(buf2, seed, qsize);
                        /* precompute "SEED + 1" for step 7: */
-                       for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--)
+                       for (i = qsize-1; i >= 0; i--)
                                {
                                buf[i]++;
-                               if (buf[i] != 0) break;
+                               if (buf[i] != 0)
+                                       break;
                                }
 
                        /* step 2 */
-                       EVP_Digest(seed,SHA_DIGEST_LENGTH,md,NULL,HASH, NULL);
-                       EVP_Digest(buf,SHA_DIGEST_LENGTH,buf2,NULL,HASH, NULL);
-                       for (i=0; i<SHA_DIGEST_LENGTH; i++)
+                       EVP_Digest(seed, qsize, md,   NULL, evpmd, NULL);
+                       EVP_Digest(buf,  qsize, buf2, NULL, evpmd, NULL);
+                       for (i = 0; i < qsize; i++)
                                md[i]^=buf2[i];
 
                        /* step 3 */
-                       md[0]|=0x80;
-                       md[SHA_DIGEST_LENGTH-1]|=0x01;
-                       if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,q)) goto err;
+                       md[0] |= 0x80;
+                       md[qsize-1] |= 0x01;
+                       if (!BN_bin2bn(md, qsize, q))
+                               goto err;
 
                        /* step 4 */
                        r = BN_is_prime_fasttest_ex(q, DSS_prime_checks, ctx,
@@ -223,18 +244,19 @@ static int dsa_builtin_paramgen(DSA *ret, int bits,
                        for (k=0; k<=n; k++)
                                {
                                /* obtain "SEED + offset + k" by incrementing: */
-                               for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--)
+                               for (i = qsize-1; i >= 0; i--)
                                        {
                                        buf[i]++;
-                                       if (buf[i] != 0) break;
+                                       if (buf[i] != 0)
+                                               break;
                                        }
 
-                               EVP_Digest(buf,SHA_DIGEST_LENGTH,md,NULL,HASH, NULL);
+                               EVP_Digest(buf, qsize, md ,NULL, evpmd, NULL);
 
                                /* step 8 */
-                               if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,r0))
+                               if (!BN_bin2bn(md, qsize, r0))
                                        goto err;
-                               if (!BN_lshift(r0,r0,160*k)) goto err;
+                               if (!BN_lshift(r0,r0,(qsize << 3)*k)) goto err;
                                if (!BN_add(W,W,r0)) goto err;
                                }
 
@@ -308,7 +330,6 @@ err:
                        ok=0;
                        goto err;
                        }
-               if (seed_in != NULL) memcpy(seed_in,seed,20);
                if (counter_ret != NULL) *counter_ret=counter;
                if (h_ret != NULL) *h_ret=h;
                }
@@ -321,4 +342,3 @@ err:
        return ok;
        }
 #endif
-#endif
index 5e39124..c4aa86b 100644 (file)
@@ -64,8 +64,6 @@
 #include <openssl/dsa.h>
 #include <openssl/rand.h>
 
-#ifndef OPENSSL_FIPS
-
 static int dsa_builtin_keygen(DSA *dsa);
 
 int DSA_generate_key(DSA *dsa)
@@ -128,5 +126,3 @@ err:
        return(ok);
        }
 #endif
-
-#endif
index 85556d1..e9b7590 100644 (file)
@@ -76,14 +76,6 @@ static const DSA_METHOD *default_DSA_method = NULL;
 
 void DSA_set_default_method(const DSA_METHOD *meth)
        {
-#ifdef OPENSSL_FIPS
-       if (FIPS_mode() && !(meth->flags & DSA_FLAG_FIPS_METHOD))
-               {
-               DSAerr(DSA_F_DSA_SET_DEFAULT_METHOD, DSA_R_NON_FIPS_METHOD);
-               return;
-               }
-#endif
-               
        default_DSA_method = meth;
        }
 
@@ -104,13 +96,6 @@ int DSA_set_method(DSA *dsa, const DSA_METHOD *meth)
        /* NB: The caller is specifically setting a method, so it's not up to us
         * to deal with which ENGINE it comes from. */
         const DSA_METHOD *mtmp;
-#ifdef OPENSSL_FIPS
-       if (FIPS_mode() && !(meth->flags & DSA_FLAG_FIPS_METHOD))
-               {
-               DSAerr(DSA_F_DSA_SET_METHOD, DSA_R_NON_FIPS_METHOD);
-               return 0;
-               }
-#endif
         mtmp = dsa->meth;
         if (mtmp->finish) mtmp->finish(dsa);
 #ifndef OPENSSL_NO_ENGINE
@@ -162,18 +147,6 @@ DSA *DSA_new_method(ENGINE *engine)
                        }
                }
 #endif
-#ifdef OPENSSL_FIPS
-       if (FIPS_mode() && !(ret->meth->flags & DSA_FLAG_FIPS_METHOD))
-               {
-               DSAerr(DSA_F_DSA_NEW_METHOD, DSA_R_NON_FIPS_METHOD);
-#ifndef OPENSSL_NO_ENGINE
-               if (ret->engine)
-                       ENGINE_finish(ret->engine);
-#endif
-               OPENSSL_free(ret);
-               return NULL;
-               }
-#endif
 
        ret->pad=0;
        ret->version=0;
@@ -190,7 +163,7 @@ DSA *DSA_new_method(ENGINE *engine)
        ret->method_mont_p=NULL;
 
        ret->references=1;
-       ret->flags=ret->meth->flags & ~DSA_FLAG_NON_FIPS_ALLOW;
+       ret->flags=ret->meth->flags;
        CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data);
        if ((ret->meth->init != NULL) && !ret->meth->init(ret))
                {
@@ -260,6 +233,28 @@ int DSA_up_ref(DSA *r)
        return ((i > 1) ? 1 : 0);
        }
 
+int DSA_size(const DSA *r)
+       {
+       int ret,i;
+       ASN1_INTEGER bs;
+       unsigned char buf[4];   /* 4 bytes looks really small.
+                                  However, i2d_ASN1_INTEGER() will not look
+                                  beyond the first byte, as long as the second
+                                  parameter is NULL. */
+
+       i=BN_num_bits(r->q);
+       bs.length=(i+7)/8;
+       bs.data=buf;
+       bs.type=V_ASN1_INTEGER;
+       /* If the top bit is set the asn1 encoding is 1 larger. */
+       buf[0]=0xff;    
+
+       i=i2d_ASN1_INTEGER(&bs,NULL);
+       i+=i; /* r and s */
+       ret=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
+       return(ret);
+       }
+
 int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
             CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
         {
similarity index 79%
rename from deps/openssl/openssl/fips/rand/fips_rand.h
rename to deps/openssl/openssl/crypto/dsa/dsa_locl.h
index a175aaf..2b8cfee 100644 (file)
@@ -1,5 +1,5 @@
 /* ====================================================================
- * Copyright (c) 2003 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 2007 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
  *
  */
 
-#ifndef HEADER_FIPS_RAND_H
-#define HEADER_FIPS_RAND_H
-
-#include "des.h"
-
-#ifdef OPENSSL_FIPS
-
-#ifdef  __cplusplus
-extern "C" {
-#endif
-
-int FIPS_rand_set_key(const unsigned char *key, FIPS_RAND_SIZE_T keylen);
-int FIPS_rand_seed(const void *buf, FIPS_RAND_SIZE_T num);
-int FIPS_rand_bytes(unsigned char *out, FIPS_RAND_SIZE_T outlen);
-
-int FIPS_rand_test_mode(void);
-void FIPS_rand_reset(void);
-int FIPS_rand_set_dt(unsigned char *dt);
-
-int FIPS_rand_status(void);
-
-const RAND_METHOD *FIPS_rand_method(void);
+#include <openssl/dsa.h>
 
-#ifdef  __cplusplus
-}
-#endif
-#endif
-#endif
+int dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits,
+       const EVP_MD *evpmd, const unsigned char *seed_in, size_t seed_len,
+       int *counter_ret, unsigned long *h_ret, BN_GENCB *cb);
index 1727760..a3ddd7d 100644 (file)
 #include <stdio.h>
 #include "cryptlib.h"
 #include <openssl/bn.h>
+#include <openssl/sha.h>
 #include <openssl/dsa.h>
 #include <openssl/rand.h>
 #include <openssl/asn1.h>
 
-#ifndef OPENSSL_FIPS
-
 static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
 static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp);
 static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
-                 DSA *dsa);
+                        DSA *dsa);
 static int dsa_init(DSA *dsa);
 static int dsa_finish(DSA *dsa);
 
@@ -135,7 +134,7 @@ static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
        BIGNUM m;
        BIGNUM xr;
        BN_CTX *ctx=NULL;
-       int i,reason=ERR_R_BN_LIB;
+       int reason=ERR_R_BN_LIB;
        DSA_SIG *ret=NULL;
 
        BN_init(&m);
@@ -149,14 +148,6 @@ static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
 
        s=BN_new();
        if (s == NULL) goto err;
-
-       i=BN_num_bytes(dsa->q); /* should be 20 */
-       if ((dlen > i) || (dlen > 50))
-               {
-               reason=DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE;
-               goto err;
-               }
-
        ctx=BN_CTX_new();
        if (ctx == NULL) goto err;
 
@@ -172,14 +163,20 @@ static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
                dsa->r=NULL;
                }
 
-       if (BN_bin2bn(dgst,dlen,&m) == NULL) goto err;
+       
+       if (dlen > BN_num_bytes(dsa->q))
+               /* if the digest length is greater than the size of q use the
+                * BN_num_bits(dsa->q) leftmost bits of the digest, see
+                * fips 186-3, 4.2 */
+               dlen = BN_num_bytes(dsa->q);
+       if (BN_bin2bn(dgst,dlen,&m) == NULL)
+               goto err;
 
        /* Compute  s = inv(k) (m + xr) mod q */
        if (!BN_mod_mul(&xr,dsa->priv_key,r,dsa->q,ctx)) goto err;/* s = xr */
        if (!BN_add(s, &xr, &m)) goto err;              /* s = m + xr */
        if (BN_cmp(s,dsa->q) > 0)
-               if (!BN_sub(s,s,dsa->q))
-                       goto err;
+               if (!BN_sub(s,s,dsa->q)) goto err;
        if (!BN_mod_mul(s,s,kinv,dsa->q,ctx)) goto err;
 
        ret=DSA_SIG_new();
@@ -284,30 +281,31 @@ err:
        if (!ret)
                {
                DSAerr(DSA_F_DSA_SIGN_SETUP,ERR_R_BN_LIB);
-               if (kinv != NULL) BN_clear_free(kinv);
-               if (r != NULL) BN_clear_free(r);
+               if (r != NULL)
+                       BN_clear_free(r);
                }
        if (ctx_in == NULL) BN_CTX_free(ctx);
-       if (kinv != NULL) BN_clear_free(kinv);
        BN_clear_free(&k);
        BN_clear_free(&kq);
        return(ret);
        }
 
 static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
-                 DSA *dsa)
+                        DSA *dsa)
        {
        BN_CTX *ctx;
        BIGNUM u1,u2,t1;
        BN_MONT_CTX *mont=NULL;
-       int ret = -1;
+       int ret = -1, i;
        if (!dsa->p || !dsa->q || !dsa->g)
                {
                DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_MISSING_PARAMETERS);
                return -1;
                }
 
-       if (BN_num_bits(dsa->q) != 160)
+       i = BN_num_bits(dsa->q);
+       /* fips 186-3 allows only different sizes for q */
+       if (i != 160 && i != 224 && i != 256)
                {
                DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_BAD_Q_VALUE);
                return -1;
@@ -318,7 +316,6 @@ static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
                DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_MODULUS_TOO_LARGE);
                return -1;
                }
-
        BN_init(&u1);
        BN_init(&u2);
        BN_init(&t1);
@@ -343,6 +340,11 @@ static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
        if ((BN_mod_inverse(&u2,sig->s,dsa->q,ctx)) == NULL) goto err;
 
        /* save M in u1 */
+       if (dgst_len > (i >> 3))
+               /* if the digest length is greater than the size of q use the
+                * BN_num_bits(dsa->q) leftmost bits of the digest, see
+                * fips 186-3, 4.2 */
+               dgst_len = (i >> 3);
        if (BN_bin2bn(dgst,dgst_len,&u1) == NULL) goto err;
 
        /* u1 = M * w mod q */
@@ -394,4 +396,3 @@ static int dsa_finish(DSA *dsa)
        return(1);
 }
 
-#endif
diff --git a/deps/openssl/openssl/crypto/dsa/dsa_pmeth.c b/deps/openssl/openssl/crypto/dsa/dsa_pmeth.c
new file mode 100644 (file)
index 0000000..e2df54f
--- /dev/null
@@ -0,0 +1,316 @@
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project 2006.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include "cryptlib.h"
+#include <openssl/asn1t.h>
+#include <openssl/x509.h>
+#include <openssl/evp.h>
+#include <openssl/bn.h>
+#include "evp_locl.h"
+#include "dsa_locl.h"
+
+/* DSA pkey context structure */
+
+typedef struct
+       {
+       /* Parameter gen parameters */
+       int nbits;              /* size of p in bits (default: 1024) */
+       int qbits;              /* size of q in bits (default: 160)  */
+       const EVP_MD *pmd;      /* MD for parameter generation */
+       /* Keygen callback info */
+       int gentmp[2];
+       /* message digest */
+       const EVP_MD *md;       /* MD for the signature */
+       } DSA_PKEY_CTX;
+
+static int pkey_dsa_init(EVP_PKEY_CTX *ctx)
+       {
+       DSA_PKEY_CTX *dctx;
+       dctx = OPENSSL_malloc(sizeof(DSA_PKEY_CTX));
+       if (!dctx)
+               return 0;
+       dctx->nbits = 1024;
+       dctx->qbits = 160;
+       dctx->pmd = NULL;
+       dctx->md = NULL;
+
+       ctx->data = dctx;
+       ctx->keygen_info = dctx->gentmp;
+       ctx->keygen_info_count = 2;
+       
+       return 1;
+       }
+
+static int pkey_dsa_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
+       {
+       DSA_PKEY_CTX *dctx, *sctx;
+       if (!pkey_dsa_init(dst))
+               return 0;
+               sctx = src->data;
+       dctx = dst->data;
+       dctx->nbits = sctx->nbits;
+       dctx->qbits = sctx->qbits;
+       dctx->pmd = sctx->pmd;
+       dctx->md  = sctx->md;
+       return 1;
+       }
+
+static void pkey_dsa_cleanup(EVP_PKEY_CTX *ctx)
+       {
+       DSA_PKEY_CTX *dctx = ctx->data;
+       if (dctx)
+               OPENSSL_free(dctx);
+       }
+
+static int pkey_dsa_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
+                                       const unsigned char *tbs, size_t tbslen)
+       {
+       int ret, type;
+       unsigned int sltmp;
+       DSA_PKEY_CTX *dctx = ctx->data;
+       DSA *dsa = ctx->pkey->pkey.dsa;
+
+       if (dctx->md)
+               type = EVP_MD_type(dctx->md);
+       else
+               type = NID_sha1;
+
+       ret = DSA_sign(type, tbs, tbslen, sig, &sltmp, dsa);
+
+       if (ret <= 0)
+               return ret;
+       *siglen = sltmp;
+       return 1;
+       }
+
+static int pkey_dsa_verify(EVP_PKEY_CTX *ctx,
+                                       const unsigned char *sig, size_t siglen,
+                                       const unsigned char *tbs, size_t tbslen)
+       {
+       int ret, type;
+       DSA_PKEY_CTX *dctx = ctx->data;
+       DSA *dsa = ctx->pkey->pkey.dsa;
+
+       if (dctx->md)
+               type = EVP_MD_type(dctx->md);
+       else
+               type = NID_sha1;
+
+       ret = DSA_verify(type, tbs, tbslen, sig, siglen, dsa);
+
+       return ret;
+       }
+
+static int pkey_dsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
+       {
+       DSA_PKEY_CTX *dctx = ctx->data;
+       switch (type)
+               {
+               case EVP_PKEY_CTRL_DSA_PARAMGEN_BITS:
+               if (p1 < 256)
+                       return -2;
+               dctx->nbits = p1;
+               return 1;
+
+               case EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS:
+               if (p1 != 160 && p1 != 224 && p1 && p1 != 256)
+                       return -2;
+               dctx->qbits = p1;
+               return 1;
+
+               case EVP_PKEY_CTRL_DSA_PARAMGEN_MD:
+               if (EVP_MD_type((const EVP_MD *)p2) != NID_sha1   &&
+                   EVP_MD_type((const EVP_MD *)p2) != NID_sha224 &&
+                   EVP_MD_type((const EVP_MD *)p2) != NID_sha256)
+                       {
+                       DSAerr(DSA_F_PKEY_DSA_CTRL, DSA_R_INVALID_DIGEST_TYPE);
+                       return 0;
+                       }
+               dctx->md = p2;
+               return 1;
+
+               case EVP_PKEY_CTRL_MD:
+               if (EVP_MD_type((const EVP_MD *)p2) != NID_sha1   &&
+                   EVP_MD_type((const EVP_MD *)p2) != NID_dsa    &&
+                   EVP_MD_type((const EVP_MD *)p2) != NID_dsaWithSHA    &&
+                   EVP_MD_type((const EVP_MD *)p2) != NID_sha224 &&
+                   EVP_MD_type((const EVP_MD *)p2) != NID_sha256)
+                       {
+                       DSAerr(DSA_F_PKEY_DSA_CTRL, DSA_R_INVALID_DIGEST_TYPE);
+                       return 0;
+                       }
+               dctx->md = p2;
+               return 1;
+
+               case EVP_PKEY_CTRL_DIGESTINIT:
+               case EVP_PKEY_CTRL_PKCS7_SIGN:
+               case EVP_PKEY_CTRL_CMS_SIGN:
+               return 1;
+               
+               case EVP_PKEY_CTRL_PEER_KEY:
+                       DSAerr(DSA_F_PKEY_DSA_CTRL,
+                       EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
+                       return -2;      
+               default:
+               return -2;
+
+               }
+       }
+                       
+static int pkey_dsa_ctrl_str(EVP_PKEY_CTX *ctx,
+                       const char *type, const char *value)
+       {
+       if (!strcmp(type, "dsa_paramgen_bits"))
+               {
+               int nbits;
+               nbits = atoi(value);
+               return EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits);
+               }
+       if (!strcmp(type, "dsa_paramgen_q_bits"))
+               {
+               int qbits = atoi(value);
+               return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN,
+                                        EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS, qbits, NULL);
+               }
+       if (!strcmp(type, "dsa_paramgen_md"))
+               {
+               return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN,
+                                        EVP_PKEY_CTRL_DSA_PARAMGEN_MD, 0, 
+                                        (void *)EVP_get_digestbyname(value));
+               }
+       return -2;
+       }
+
+static int pkey_dsa_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
+       {
+       DSA *dsa = NULL;
+       DSA_PKEY_CTX *dctx = ctx->data;
+       BN_GENCB *pcb, cb;
+       int ret;
+       if (ctx->pkey_gencb)
+               {
+               pcb = &cb;
+               evp_pkey_set_cb_translate(pcb, ctx);
+               }
+       else
+               pcb = NULL;
+       dsa = DSA_new();
+       if (!dsa)
+               return 0;
+       ret = dsa_builtin_paramgen(dsa, dctx->nbits, dctx->qbits, dctx->pmd,
+                                  NULL, 0, NULL, NULL, pcb);
+       if (ret)
+               EVP_PKEY_assign_DSA(pkey, dsa);
+       else
+               DSA_free(dsa);
+       return ret;
+       }
+
+static int pkey_dsa_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
+       {
+       DSA *dsa = NULL;
+       if (ctx->pkey == NULL)
+               {
+               DSAerr(DSA_F_PKEY_DSA_KEYGEN, DSA_R_NO_PARAMETERS_SET);
+               return 0;
+               }
+       dsa = DSA_new();
+       if (!dsa)
+               return 0;
+       EVP_PKEY_assign_DSA(pkey, dsa);
+       /* Note: if error return, pkey is freed by parent routine */
+       if (!EVP_PKEY_copy_parameters(pkey, ctx->pkey))
+               return 0;
+       return DSA_generate_key(pkey->pkey.dsa);
+       }
+
+const EVP_PKEY_METHOD dsa_pkey_meth = 
+       {
+       EVP_PKEY_DSA,
+       EVP_PKEY_FLAG_AUTOARGLEN,
+       pkey_dsa_init,
+       pkey_dsa_copy,
+       pkey_dsa_cleanup,
+
+       0,
+       pkey_dsa_paramgen,
+
+       0,
+       pkey_dsa_keygen,
+
+       0,
+       pkey_dsa_sign,
+
+       0,
+       pkey_dsa_verify,
+
+       0,0,
+
+       0,0,0,0,
+
+       0,0,
+
+       0,0,
+
+       0,0,
+
+       pkey_dsa_ctrl,
+       pkey_dsa_ctrl_str
+
+
+       };
similarity index 69%
rename from deps/openssl/openssl/fips/rsa/fips_rsa_lib.c
rename to deps/openssl/openssl/crypto/dsa/dsa_prn.c
index a37ad3e..6f29f5e 100644 (file)
@@ -1,9 +1,9 @@
-/* fips_rsa_sign.c */
+/* crypto/dsa/dsa_prn.c */
 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
- * project 2007.
+ * project 2006.
  */
 /* ====================================================================
- * Copyright (c) 2007 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  *
  */
 
-#include <string.h>
+#include <stdio.h>
+#include "cryptlib.h"
 #include <openssl/evp.h>
-#include <openssl/rsa.h>
-#include <openssl/bn.h>
-#include <openssl/err.h>
+#include <openssl/dsa.h>
 
-/* Minimal FIPS versions of FIPS_rsa_new() and FIPS_rsa_free: to
- * reduce external dependencies. 
- */
+#ifndef OPENSSL_NO_FP_API
+int DSA_print_fp(FILE *fp, const DSA *x, int off)
+       {
+       BIO *b;
+       int ret;
 
-RSA *FIPS_rsa_new(void)
+       if ((b=BIO_new(BIO_s_file())) == NULL)
+               {
+               DSAerr(DSA_F_DSA_PRINT_FP,ERR_R_BUF_LIB);
+               return(0);
+               }
+       BIO_set_fp(b,fp,BIO_NOCLOSE);
+       ret=DSA_print(b,x,off);
+       BIO_free(b);
+       return(ret);
+       }
+
+int DSAparams_print_fp(FILE *fp, const DSA *x)
        {
-       RSA *ret;
-       ret = OPENSSL_malloc(sizeof(RSA));
-       if (!ret)
-               return NULL;
-       memset(ret, 0, sizeof(RSA));
-       ret->meth = RSA_PKCS1_SSLeay();
-       if (ret->meth->init)
-               ret->meth->init(ret);
+       BIO *b;
+       int ret;
+
+       if ((b=BIO_new(BIO_s_file())) == NULL)
+               {
+               DSAerr(DSA_F_DSAPARAMS_PRINT_FP,ERR_R_BUF_LIB);
+               return(0);
+               }
+       BIO_set_fp(b,fp,BIO_NOCLOSE);
+       ret=DSAparams_print(b, x);
+       BIO_free(b);
+       return(ret);
+       }
+#endif
+
+int DSA_print(BIO *bp, const DSA *x, int off)
+       {
+       EVP_PKEY *pk;
+       int ret;
+       pk = EVP_PKEY_new();
+       if (!pk || !EVP_PKEY_set1_DSA(pk, (DSA *)x))
+               return 0;
+       ret = EVP_PKEY_print_private(bp, pk, off, NULL);
+       EVP_PKEY_free(pk);
        return ret;
        }
 
-void FIPS_rsa_free(RSA *r)
+int DSAparams_print(BIO *bp, const DSA *x)
        {
-       if (!r)
-               return;
-       if (r->meth->finish)
-               r->meth->finish(r);
-       if (r->n != NULL) BN_clear_free(r->n);
-       if (r->e != NULL) BN_clear_free(r->e);
-       if (r->d != NULL) BN_clear_free(r->d);
-       if (r->p != NULL) BN_clear_free(r->p);
-       if (r->q != NULL) BN_clear_free(r->q);
-       if (r->dmp1 != NULL) BN_clear_free(r->dmp1);
-       if (r->dmq1 != NULL) BN_clear_free(r->dmq1);
-       if (r->iqmp != NULL) BN_clear_free(r->iqmp);
-       if (r->blinding != NULL) BN_BLINDING_free(r->blinding);
-       if (r->mt_blinding != NULL) BN_BLINDING_free(r->mt_blinding);
-       if (r->bignum_data != NULL) OPENSSL_free_locked(r->bignum_data);
-       OPENSSL_free(r);
+       EVP_PKEY *pk;
+       int ret;
+       pk = EVP_PKEY_new();
+       if (!pk || !EVP_PKEY_set1_DSA(pk, (DSA *)x))
+               return 0;
+       ret = EVP_PKEY_print_params(bp, pk, 4, NULL);
+       EVP_PKEY_free(pk);
+       return ret;
        }
 
index 4cfbbe5..17555e5 100644 (file)
 
 /* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
 
-#include <stdio.h>
 #include "cryptlib.h"
-#include <openssl/bn.h>
 #include <openssl/dsa.h>
 #include <openssl/rand.h>
-#include <openssl/asn1.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
 
 DSA_SIG * DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
        {
-#ifdef OPENSSL_FIPS
-       if(FIPS_mode() && !(dsa->flags & DSA_FLAG_NON_FIPS_ALLOW))
-               {
-               DSAerr(DSA_F_DSA_DO_SIGN, DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE);
-               return NULL;
-               }
-#endif
        return dsa->meth->dsa_do_sign(dgst, dlen, dsa);
        }
 
-int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
+int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig,
+            unsigned int *siglen, DSA *dsa)
        {
-#ifdef OPENSSL_FIPS
-       if(FIPS_mode() && !(dsa->flags & DSA_FLAG_NON_FIPS_ALLOW))
+       DSA_SIG *s;
+       RAND_seed(dgst, dlen);
+       s=DSA_do_sign(dgst,dlen,dsa);
+       if (s == NULL)
                {
-               DSAerr(DSA_F_DSA_SIGN_SETUP, DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE);
-               return 0;
+               *siglen=0;
+               return(0);
                }
-#endif
+       *siglen=i2d_DSA_SIG(s,&sig);
+       DSA_SIG_free(s);
+       return(1);
+       }
+
+int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
+       {
        return dsa->meth->dsa_sign_setup(dsa, ctx_in, kinvp, rp);
        }
 
index c75e423..226a75f 100644 (file)
 
 /* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
 
-#include <stdio.h>
 #include "cryptlib.h"
-#include <openssl/bn.h>
 #include <openssl/dsa.h>
-#include <openssl/rand.h>
-#include <openssl/asn1.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
-#include <openssl/asn1_mac.h>
 
 int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
                  DSA *dsa)
        {
-#ifdef OPENSSL_FIPS
-       if(FIPS_mode() && !(dsa->flags & DSA_FLAG_NON_FIPS_ALLOW))
-               {
-               DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE);
-               return 0;
-               }
-#endif
        return dsa->meth->dsa_do_verify(dgst, dgst_len, sig, dsa);
        }
+
+/* data has already been hashed (probably with SHA or SHA-1). */
+/* returns
+ *      1: correct signature
+ *      0: incorrect signature
+ *     -1: error
+ */
+int DSA_verify(int type, const unsigned char *dgst, int dgst_len,
+            const unsigned char *sigbuf, int siglen, DSA *dsa)
+       {
+       DSA_SIG *s;
+       int ret=-1;
+
+       s = DSA_SIG_new();
+       if (s == NULL) return(ret);
+       if (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err;
+       ret=DSA_do_verify(dgst,dgst_len,s,dsa);
+err:
+       DSA_SIG_free(s);
+       return(ret);
+       }
index 912317b..edffd24 100644 (file)
@@ -169,7 +169,6 @@ int main(int argc, char **argv)
                }
        BIO_printf(bio_err,"\ncounter=%d h=%ld\n",counter,h);
                
-       if (dsa == NULL) goto end;
        DSA_print(bio_err,dsa,0);
        if (counter != 105) 
                {
@@ -223,7 +222,7 @@ end:
                ERR_print_errors(bio_err);
        if (dsa != NULL) DSA_free(dsa);
        CRYPTO_cleanup_all_ex_data();
-       ERR_remove_state(0);
+       ERR_remove_thread_state(NULL);
        ERR_free_strings();
        CRYPTO_mem_leaks(bio_err);
        if (bio_err != NULL)
index 52f1528..fb2709e 100644 (file)
@@ -18,9 +18,9 @@ APPS=
 
 LIB=$(TOP)/libcrypto.a
 LIBSRC= dso_dl.c dso_dlfcn.c dso_err.c dso_lib.c dso_null.c \
-       dso_openssl.c dso_win32.c dso_vms.c
+       dso_openssl.c dso_win32.c dso_vms.c dso_beos.c
 LIBOBJ= dso_dl.o dso_dlfcn.o dso_err.o dso_lib.o dso_null.o \
-       dso_openssl.o dso_win32.o dso_vms.o
+       dso_openssl.o dso_win32.o dso_vms.o dso_beos.o
 
 SRC= $(LIBSRC)
 
@@ -35,7 +35,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -76,6 +76,14 @@ clean:
 
 # DO NOT DELETE THIS LINE -- make depend depends on it.
 
+dso_beos.o: ../../e_os.h ../../include/openssl/bio.h
+dso_beos.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
+dso_beos.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
+dso_beos.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
+dso_beos.o: ../../include/openssl/opensslconf.h
+dso_beos.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+dso_beos.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+dso_beos.o: ../../include/openssl/symhacks.h ../cryptlib.h dso_beos.c
 dso_dl.o: ../../e_os.h ../../include/openssl/bio.h
 dso_dl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 dso_dl.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
index 3e51913..839f2e0 100644 (file)
@@ -170,6 +170,11 @@ typedef struct dso_meth_st
        /* [De]Initialisation handlers. */
        int (*init)(DSO *dso);
        int (*finish)(DSO *dso);
+
+       /* Return pathname of the module containing location */
+       int (*pathbyaddr)(void *addr,char *path,int sz);
+       /* Perform global symbol lookup, i.e. among *all* modules */
+       void *(*globallookup)(const char *symname);
        } DSO_METHOD;
 
 /**********************************************************************/
@@ -183,7 +188,7 @@ struct dso_st
         * for use in the dso_bind handler. All in all, let each
         * method control its own destiny. "Handles" and such go in
         * a STACK. */
-       STACK *meth_data;
+       STACK_OF(void) *meth_data;
        int references;
        int flags;
        /* For use by applications etc ... use this for your bits'n'pieces,
@@ -296,6 +301,30 @@ DSO_METHOD *DSO_METHOD_win32(void);
 /* If VMS is defined, use shared images. If not, return NULL. */
 DSO_METHOD *DSO_METHOD_vms(void);
 
+/* This function writes null-terminated pathname of DSO module
+ * containing 'addr' into 'sz' large caller-provided 'path' and
+ * returns the number of characters [including trailing zero]
+ * written to it. If 'sz' is 0 or negative, 'path' is ignored and
+ * required amount of charachers [including trailing zero] to
+ * accomodate pathname is returned. If 'addr' is NULL, then
+ * pathname of cryptolib itself is returned. Negative or zero
+ * return value denotes error.
+ */
+int DSO_pathbyaddr(void *addr,char *path,int sz);
+
+/* This function should be used with caution! It looks up symbols in
+ * *all* loaded modules and if module gets unloaded by somebody else
+ * attempt to dereference the pointer is doomed to have fatal
+ * consequences. Primary usage for this function is to probe *core*
+ * system functionality, e.g. check if getnameinfo(3) is available
+ * at run-time without bothering about OS-specific details such as
+ * libc.so.versioning or where does it actually reside: in libc
+ * itself or libsocket. */
+void *DSO_global_lookup(const char *name);
+
+/* If BeOS is defined, use shared images. If not, return NULL. */
+DSO_METHOD *DSO_METHOD_beos(void);
+
 /* BEGIN ERROR CODES */
 /* The following lines are auto generated by the script mkerr.pl. Any changes
  * made after this point may be overwritten when the script is next run.
@@ -305,6 +334,11 @@ void ERR_load_DSO_strings(void);
 /* Error codes for the DSO functions. */
 
 /* Function codes. */
+#define DSO_F_BEOS_BIND_FUNC                            144
+#define DSO_F_BEOS_BIND_VAR                             145
+#define DSO_F_BEOS_LOAD                                         146
+#define DSO_F_BEOS_NAME_CONVERTER                       147
+#define DSO_F_BEOS_UNLOAD                               148
 #define DSO_F_DLFCN_BIND_FUNC                           100
 #define DSO_F_DLFCN_BIND_VAR                            101
 #define DSO_F_DLFCN_LOAD                                102
@@ -324,22 +358,29 @@ void ERR_load_DSO_strings(void);
 #define DSO_F_DSO_FREE                                  111
 #define DSO_F_DSO_GET_FILENAME                          127
 #define DSO_F_DSO_GET_LOADED_FILENAME                   128
+#define DSO_F_DSO_GLOBAL_LOOKUP                                 139
 #define DSO_F_DSO_LOAD                                  112
 #define DSO_F_DSO_MERGE                                         132
 #define DSO_F_DSO_NEW_METHOD                            113
+#define DSO_F_DSO_PATHBYADDR                            140
 #define DSO_F_DSO_SET_FILENAME                          129
 #define DSO_F_DSO_SET_NAME_CONVERTER                    122
 #define DSO_F_DSO_UP_REF                                114
+#define DSO_F_GLOBAL_LOOKUP_FUNC                        138
+#define DSO_F_PATHBYADDR                                137
 #define DSO_F_VMS_BIND_SYM                              115
 #define DSO_F_VMS_LOAD                                  116
 #define DSO_F_VMS_MERGER                                133
 #define DSO_F_VMS_UNLOAD                                117
 #define DSO_F_WIN32_BIND_FUNC                           118
 #define DSO_F_WIN32_BIND_VAR                            119
+#define DSO_F_WIN32_GLOBALLOOKUP                        142
+#define DSO_F_WIN32_GLOBALLOOKUP_FUNC                   143
 #define DSO_F_WIN32_JOINER                              135
 #define DSO_F_WIN32_LOAD                                120
 #define DSO_F_WIN32_MERGER                              134
 #define DSO_F_WIN32_NAME_CONVERTER                      125
+#define DSO_F_WIN32_PATHBYADDR                          141
 #define DSO_F_WIN32_SPLITTER                            136
 #define DSO_F_WIN32_UNLOAD                              121
 
diff --git a/deps/openssl/openssl/crypto/dso/dso_beos.c b/deps/openssl/openssl/crypto/dso/dso_beos.c
new file mode 100644 (file)
index 0000000..553966e
--- /dev/null
@@ -0,0 +1,270 @@
+/* dso_beos.c */
+/* Written by Marcin Konicki (ahwayakchih@neoni.net) for the OpenSSL
+ * project 2000.
+ */
+/* ====================================================================
+ * Copyright (c) 2000 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include "cryptlib.h"
+#include <openssl/dso.h>
+
+#if !defined(OPENSSL_SYS_BEOS)
+DSO_METHOD *DSO_METHOD_beos(void)
+       {
+       return NULL;
+       }
+#else
+
+#include <kernel/image.h>
+
+static int beos_load(DSO *dso);
+static int beos_unload(DSO *dso);
+static void *beos_bind_var(DSO *dso, const char *symname);
+static DSO_FUNC_TYPE beos_bind_func(DSO *dso, const char *symname);
+#if 0
+static int beos_unbind_var(DSO *dso, char *symname, void *symptr);
+static int beos_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr);
+static int beos_init(DSO *dso);
+static int beos_finish(DSO *dso);
+static long beos_ctrl(DSO *dso, int cmd, long larg, void *parg);
+#endif
+static char *beos_name_converter(DSO *dso, const char *filename);
+
+static DSO_METHOD dso_meth_beos = {
+       "OpenSSL 'beos' shared library method",
+       beos_load,
+       beos_unload,
+       beos_bind_var,
+       beos_bind_func,
+/* For now, "unbind" doesn't exist */
+#if 0
+       NULL, /* unbind_var */
+       NULL, /* unbind_func */
+#endif
+       NULL, /* ctrl */
+       beos_name_converter,
+       NULL, /* init */
+       NULL  /* finish */
+       };
+
+DSO_METHOD *DSO_METHOD_beos(void)
+       {
+       return(&dso_meth_beos);
+       }
+
+/* For this DSO_METHOD, our meth_data STACK will contain;
+ * (i) a pointer to the handle (image_id) returned from
+ *     load_add_on().
+ */
+
+static int beos_load(DSO *dso)
+       {
+       image_id id;
+       /* See applicable comments from dso_dl.c */
+       char *filename = DSO_convert_filename(dso, NULL);
+
+       if(filename == NULL)
+               {
+               DSOerr(DSO_F_BEOS_LOAD,DSO_R_NO_FILENAME);
+               goto err;
+               }
+       id = load_add_on(filename);
+       if(id < 1)
+               {
+               DSOerr(DSO_F_BEOS_LOAD,DSO_R_LOAD_FAILED);
+               ERR_add_error_data(3, "filename(", filename, ")");
+               goto err;
+               }
+       if(!sk_push(dso->meth_data, (char *)id))
+               {
+               DSOerr(DSO_F_BEOS_LOAD,DSO_R_STACK_ERROR);
+               goto err;
+               }
+       /* Success */
+       dso->loaded_filename = filename;
+       return(1);
+err:
+       /* Cleanup !*/
+       if(filename != NULL)
+               OPENSSL_free(filename);
+       if(id > 0)
+               unload_add_on(id);
+       return(0);
+       }
+
+static int beos_unload(DSO *dso)
+       {
+       image_id id;
+       if(dso == NULL)
+               {
+               DSOerr(DSO_F_BEOS_UNLOAD,ERR_R_PASSED_NULL_PARAMETER);
+               return(0);
+               }
+       if(sk_num(dso->meth_data) < 1)
+               return(1);
+       id = (image_id)sk_pop(dso->meth_data);
+       if(id < 1)
+               {
+               DSOerr(DSO_F_BEOS_UNLOAD,DSO_R_NULL_HANDLE);
+               return(0);
+               }
+       if(unload_add_on(id) != B_OK)
+               {
+               DSOerr(DSO_F_BEOS_UNLOAD,DSO_R_UNLOAD_FAILED);
+               /* We should push the value back onto the stack in
+                * case of a retry. */
+               sk_push(dso->meth_data, (char *)id);
+               return(0);
+               }
+       return(1);
+       }
+
+static void *beos_bind_var(DSO *dso, const char *symname)
+       {
+       image_id id;
+       void *sym;
+
+       if((dso == NULL) || (symname == NULL))
+               {
+               DSOerr(DSO_F_BEOS_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
+               return(NULL);
+               }
+       if(sk_num(dso->meth_data) < 1)
+               {
+               DSOerr(DSO_F_BEOS_BIND_VAR,DSO_R_STACK_ERROR);
+               return(NULL);
+               }
+       id = (image_id)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
+       if(id < 1)
+               {
+               DSOerr(DSO_F_BEOS_BIND_VAR,DSO_R_NULL_HANDLE);
+               return(NULL);
+               }
+       if(get_image_symbol(id, symname, B_SYMBOL_TYPE_DATA, &sym) != B_OK)
+               {
+               DSOerr(DSO_F_BEOS_BIND_VAR,DSO_R_SYM_FAILURE);
+               ERR_add_error_data(3, "symname(", symname, ")");
+               return(NULL);
+               }
+       return(sym);
+       }
+
+static DSO_FUNC_TYPE beos_bind_func(DSO *dso, const char *symname)
+       {
+       image_id id;
+       void *sym;
+
+       if((dso == NULL) || (symname == NULL))
+               {
+               DSOerr(DSO_F_BEOS_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER);
+               return(NULL);
+               }
+       if(sk_num(dso->meth_data) < 1)
+               {
+               DSOerr(DSO_F_BEOS_BIND_FUNC,DSO_R_STACK_ERROR);
+               return(NULL);
+               }
+       id = (image_id)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
+       if(id < 1)
+               {
+               DSOerr(DSO_F_BEOS_BIND_FUNC,DSO_R_NULL_HANDLE);
+               return(NULL);
+               }
+       if(get_image_symbol(id, symname, B_SYMBOL_TYPE_TEXT, &sym) != B_OK)
+               {
+               DSOerr(DSO_F_BEOS_BIND_FUNC,DSO_R_SYM_FAILURE);
+               ERR_add_error_data(3, "symname(", symname, ")");
+               return(NULL);
+               }
+       return((DSO_FUNC_TYPE)sym);
+       }
+
+/* This one is the same as the one in dlfcn */
+static char *beos_name_converter(DSO *dso, const char *filename)
+       {
+       char *translated;
+       int len, rsize, transform;
+
+       len = strlen(filename);
+       rsize = len + 1;
+       transform = (strstr(filename, "/") == NULL);
+       if(transform)
+               {
+               /* We will convert this to "%s.so" or "lib%s.so" */
+               rsize += 3;     /* The length of ".so" */
+               if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0)
+                       rsize += 3; /* The length of "lib" */
+               }
+       translated = OPENSSL_malloc(rsize);
+       if(translated == NULL)
+               {
+               DSOerr(DSO_F_BEOS_NAME_CONVERTER,
+                               DSO_R_NAME_TRANSLATION_FAILED);
+               return(NULL);
+               }
+       if(transform)
+               {
+               if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0)
+                       sprintf(translated, "lib%s.so", filename);
+               else
+                       sprintf(translated, "%s.so", filename);
+               }
+       else
+               sprintf(translated, "%s", filename);
+       return(translated);
+       }
+
+#endif
index 417abb6..fc4236b 100644 (file)
@@ -85,6 +85,8 @@ static int dl_ctrl(DSO *dso, int cmd, long larg, void *parg);
 #endif
 static char *dl_name_converter(DSO *dso, const char *filename);
 static char *dl_merger(DSO *dso, const char *filespec1, const char *filespec2);
+static int dl_pathbyaddr(void *addr,char *path,int sz);
+static void *dl_globallookup(const char *name);
 
 static DSO_METHOD dso_meth_dl = {
        "OpenSSL 'dl' shared library method",
@@ -101,7 +103,9 @@ static DSO_METHOD dso_meth_dl = {
        dl_name_converter,
        dl_merger,
        NULL, /* init */
-       NULL  /* finish */
+       NULL, /* finish */
+       dl_pathbyaddr,
+       dl_globallookup
        };
 
 DSO_METHOD *DSO_METHOD_dl(void)
@@ -350,4 +354,40 @@ static char *dl_name_converter(DSO *dso, const char *filename)
        return(translated);
        }
 
+static int dl_pathbyaddr(void *addr,char *path,int sz)
+       {
+       struct shl_descriptor inf;
+       int i,len;
+
+       if (addr == NULL)
+               {
+               union   { int(*f)(void*,char*,int); void *p; } t =
+                       { dl_pathbyaddr };
+               addr = t.p;
+               }
+
+       for (i=-1;shl_get_r(i,&inf)==0;i++)
+               {
+               if (((size_t)addr >= inf.tstart && (size_t)addr < inf.tend) ||
+                   ((size_t)addr >= inf.dstart && (size_t)addr < inf.dend))
+                       {
+                       len = (int)strlen(inf.filename);
+                       if (sz <= 0) return len+1;
+                       if (len >= sz) len=sz-1;
+                       memcpy(path,inf.filename,len);
+                       path[len++] = 0;
+                       return len;
+                       }
+               }
+
+       return -1;
+       }
+
+static void *dl_globallookup(const char *name)
+       {
+       void *ret;
+       shl_t h = NULL;
+
+       return shl_findsym(&h,name,TYPE_UNDEFINED,&ret) ? NULL : ret;
+       }
 #endif /* DSO_DL */
index d91e821..c2bc617 100644 (file)
  *
  */
 
+/* We need to do this early, because stdio.h includes the header files
+   that handle _GNU_SOURCE and other similar macros.  Defining it later
+   is simply too late, because those headers are protected from re-
+   inclusion.  */
+#ifdef __linux
+# ifndef _GNU_SOURCE
+#  define _GNU_SOURCE  /* make sure dladdr is declared */
+# endif
+#endif
+
 #include <stdio.h>
 #include "cryptlib.h"
 #include <openssl/dso.h>
@@ -68,7 +78,17 @@ DSO_METHOD *DSO_METHOD_dlfcn(void)
 #else
 
 #ifdef HAVE_DLFCN_H
-#include <dlfcn.h>
+# ifdef __osf__
+#  define __EXTENSIONS__
+# endif
+# include <dlfcn.h>
+# define HAVE_DLINFO 1
+# if defined(_AIX) || defined(__CYGWIN__) || \
+     defined(__SCO_VERSION__) || defined(_SCO_ELF) || \
+     (defined(__osf__) && !defined(RTLD_NEXT))     || \
+     (defined(__OpenBSD__) && !defined(RTLD_SELF))
+#  undef HAVE_DLINFO
+# endif
 #endif
 
 /* Part of the hack in "dlfcn_load" ... */
@@ -87,6 +107,8 @@ static long dlfcn_ctrl(DSO *dso, int cmd, long larg, void *parg);
 static char *dlfcn_name_converter(DSO *dso, const char *filename);
 static char *dlfcn_merger(DSO *dso, const char *filespec1,
        const char *filespec2);
+static int dlfcn_pathbyaddr(void *addr,char *path,int sz);
+static void *dlfcn_globallookup(const char *name);
 
 static DSO_METHOD dso_meth_dlfcn = {
        "OpenSSL 'dlfcn' shared library method",
@@ -103,7 +125,9 @@ static DSO_METHOD dso_meth_dlfcn = {
        dlfcn_name_converter,
        dlfcn_merger,
        NULL, /* init */
-       NULL  /* finish */
+       NULL, /* finish */
+       dlfcn_pathbyaddr,
+       dlfcn_globallookup
        };
 
 DSO_METHOD *DSO_METHOD_dlfcn(void)
@@ -163,7 +187,7 @@ static int dlfcn_load(DSO *dso)
                ERR_add_error_data(4, "filename(", filename, "): ", dlerror());
                goto err;
                }
-       if(!sk_push(dso->meth_data, (char *)ptr))
+       if(!sk_void_push(dso->meth_data, (char *)ptr))
                {
                DSOerr(DSO_F_DLFCN_LOAD,DSO_R_STACK_ERROR);
                goto err;
@@ -188,15 +212,15 @@ static int dlfcn_unload(DSO *dso)
                DSOerr(DSO_F_DLFCN_UNLOAD,ERR_R_PASSED_NULL_PARAMETER);
                return(0);
                }
-       if(sk_num(dso->meth_data) < 1)
+       if(sk_void_num(dso->meth_data) < 1)
                return(1);
-       ptr = (void *)sk_pop(dso->meth_data);
+       ptr = sk_void_pop(dso->meth_data);
        if(ptr == NULL)
                {
                DSOerr(DSO_F_DLFCN_UNLOAD,DSO_R_NULL_HANDLE);
                /* Should push the value back onto the stack in
                 * case of a retry. */
-               sk_push(dso->meth_data, (char *)ptr);
+               sk_void_push(dso->meth_data, ptr);
                return(0);
                }
        /* For now I'm not aware of any errors associated with dlclose() */
@@ -213,12 +237,12 @@ static void *dlfcn_bind_var(DSO *dso, const char *symname)
                DSOerr(DSO_F_DLFCN_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
                return(NULL);
                }
-       if(sk_num(dso->meth_data) < 1)
+       if(sk_void_num(dso->meth_data) < 1)
                {
                DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_STACK_ERROR);
                return(NULL);
                }
-       ptr = (void *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
+       ptr = sk_void_value(dso->meth_data, sk_void_num(dso->meth_data) - 1);
        if(ptr == NULL)
                {
                DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_NULL_HANDLE);
@@ -247,12 +271,12 @@ static DSO_FUNC_TYPE dlfcn_bind_func(DSO *dso, const char *symname)
                DSOerr(DSO_F_DLFCN_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER);
                return(NULL);
                }
-       if(sk_num(dso->meth_data) < 1)
+       if(sk_void_num(dso->meth_data) < 1)
                {
                DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_STACK_ERROR);
                return(NULL);
                }
-       ptr = (void *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
+       ptr = sk_void_value(dso->meth_data, sk_void_num(dso->meth_data) - 1);
        if(ptr == NULL)
                {
                DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_NULL_HANDLE);
@@ -281,13 +305,12 @@ static char *dlfcn_merger(DSO *dso, const char *filespec1,
                }
        /* If the first file specification is a rooted path, it rules.
           same goes if the second file specification is missing. */
-       if (!filespec2 || filespec1[0] == '/')
+       if (!filespec2 || (filespec1 != NULL && filespec1[0] == '/'))
                {
                merged = OPENSSL_malloc(strlen(filespec1) + 1);
                if(!merged)
                        {
-                       DSOerr(DSO_F_DLFCN_MERGER,
-                               ERR_R_MALLOC_FAILURE);
+                       DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE);
                        return(NULL);
                        }
                strcpy(merged, filespec1);
@@ -313,7 +336,7 @@ static char *dlfcn_merger(DSO *dso, const char *filespec1,
                {
                int spec2len, len;
 
-               spec2len = (filespec2 ? strlen(filespec2) : 0);
+               spec2len = strlen(filespec2);
                len = spec2len + (filespec1 ? strlen(filespec1) : 0);
 
                if(filespec2 && filespec2[spec2len - 1] == '/')
@@ -378,4 +401,83 @@ static char *dlfcn_name_converter(DSO *dso, const char *filename)
        return(translated);
        }
 
+#ifdef __sgi
+/*
+This is a quote from IRIX manual for dladdr(3c):
+
+     <dlfcn.h> does not contain a prototype for dladdr or definition of
+     Dl_info.  The #include <dlfcn.h>  in the SYNOPSIS line is traditional,
+     but contains no dladdr prototype and no IRIX library contains an
+     implementation.  Write your own declaration based on the code below.
+
+     The following code is dependent on internal interfaces that are not
+     part of the IRIX compatibility guarantee; however, there is no future
+     intention to change this interface, so on a practical level, the code
+     below is safe to use on IRIX.
+*/
+#include <rld_interface.h>
+#ifndef _RLD_INTERFACE_DLFCN_H_DLADDR
+#define _RLD_INTERFACE_DLFCN_H_DLADDR
+typedef struct Dl_info {
+    const char * dli_fname;
+    void       * dli_fbase;
+    const char * dli_sname;
+    void       * dli_saddr;
+    int          dli_version;
+    int          dli_reserved1;
+    long         dli_reserved[4];
+} Dl_info;
+#else
+typedef struct Dl_info Dl_info;
+#endif
+#define _RLD_DLADDR             14
+
+static int dladdr(void *address, Dl_info *dl)
+{
+       void *v;
+       v = _rld_new_interface(_RLD_DLADDR,address,dl);
+       return (int)v;
+}
+#endif /* __sgi */
+
+static int dlfcn_pathbyaddr(void *addr,char *path,int sz)
+       {
+#ifdef HAVE_DLINFO
+       Dl_info dli;
+       int len;
+
+       if (addr == NULL)
+               {
+               union   { int(*f)(void*,char*,int); void *p; } t =
+                       { dlfcn_pathbyaddr };
+               addr = t.p;
+               }
+
+       if (dladdr(addr,&dli))
+               {
+               len = (int)strlen(dli.dli_fname);
+               if (sz <= 0) return len+1;
+               if (len >= sz) len=sz-1;
+               memcpy(path,dli.dli_fname,len);
+               path[len++]=0;
+               return len;
+               }
+
+       ERR_add_error_data(4, "dlfcn_pathbyaddr(): ", dlerror());
+#endif
+       return -1;
+       }
+
+static void *dlfcn_globallookup(const char *name)
+       {
+       void *ret = NULL,*handle = dlopen(NULL,RTLD_LAZY);
+       
+       if (handle)
+               {
+               ret = dlsym(handle,name);
+               dlclose(handle);
+               }
+
+       return ret;
+       }
 #endif /* DSO_DLFCN */
index a8b0a21..2bb07c2 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/dso/dso_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 static ERR_STRING_DATA DSO_str_functs[]=
        {
+{ERR_FUNC(DSO_F_BEOS_BIND_FUNC),       "BEOS_BIND_FUNC"},
+{ERR_FUNC(DSO_F_BEOS_BIND_VAR),        "BEOS_BIND_VAR"},
+{ERR_FUNC(DSO_F_BEOS_LOAD),    "BEOS_LOAD"},
+{ERR_FUNC(DSO_F_BEOS_NAME_CONVERTER),  "BEOS_NAME_CONVERTER"},
+{ERR_FUNC(DSO_F_BEOS_UNLOAD),  "BEOS_UNLOAD"},
 {ERR_FUNC(DSO_F_DLFCN_BIND_FUNC),      "DLFCN_BIND_FUNC"},
 {ERR_FUNC(DSO_F_DLFCN_BIND_VAR),       "DLFCN_BIND_VAR"},
 {ERR_FUNC(DSO_F_DLFCN_LOAD),   "DLFCN_LOAD"},
@@ -89,22 +94,29 @@ static ERR_STRING_DATA DSO_str_functs[]=
 {ERR_FUNC(DSO_F_DSO_FREE),     "DSO_free"},
 {ERR_FUNC(DSO_F_DSO_GET_FILENAME),     "DSO_get_filename"},
 {ERR_FUNC(DSO_F_DSO_GET_LOADED_FILENAME),      "DSO_get_loaded_filename"},
+{ERR_FUNC(DSO_F_DSO_GLOBAL_LOOKUP),    "DSO_global_lookup"},
 {ERR_FUNC(DSO_F_DSO_LOAD),     "DSO_load"},
 {ERR_FUNC(DSO_F_DSO_MERGE),    "DSO_merge"},
 {ERR_FUNC(DSO_F_DSO_NEW_METHOD),       "DSO_new_method"},
+{ERR_FUNC(DSO_F_DSO_PATHBYADDR),       "DSO_pathbyaddr"},
 {ERR_FUNC(DSO_F_DSO_SET_FILENAME),     "DSO_set_filename"},
 {ERR_FUNC(DSO_F_DSO_SET_NAME_CONVERTER),       "DSO_set_name_converter"},
 {ERR_FUNC(DSO_F_DSO_UP_REF),   "DSO_up_ref"},
+{ERR_FUNC(DSO_F_GLOBAL_LOOKUP_FUNC),   "GLOBAL_LOOKUP_FUNC"},
+{ERR_FUNC(DSO_F_PATHBYADDR),   "PATHBYADDR"},
 {ERR_FUNC(DSO_F_VMS_BIND_SYM), "VMS_BIND_SYM"},
 {ERR_FUNC(DSO_F_VMS_LOAD),     "VMS_LOAD"},
 {ERR_FUNC(DSO_F_VMS_MERGER),   "VMS_MERGER"},
 {ERR_FUNC(DSO_F_VMS_UNLOAD),   "VMS_UNLOAD"},
 {ERR_FUNC(DSO_F_WIN32_BIND_FUNC),      "WIN32_BIND_FUNC"},
 {ERR_FUNC(DSO_F_WIN32_BIND_VAR),       "WIN32_BIND_VAR"},
+{ERR_FUNC(DSO_F_WIN32_GLOBALLOOKUP),   "WIN32_GLOBALLOOKUP"},
+{ERR_FUNC(DSO_F_WIN32_GLOBALLOOKUP_FUNC),      "WIN32_GLOBALLOOKUP_FUNC"},
 {ERR_FUNC(DSO_F_WIN32_JOINER), "WIN32_JOINER"},
 {ERR_FUNC(DSO_F_WIN32_LOAD),   "WIN32_LOAD"},
 {ERR_FUNC(DSO_F_WIN32_MERGER), "WIN32_MERGER"},
 {ERR_FUNC(DSO_F_WIN32_NAME_CONVERTER), "WIN32_NAME_CONVERTER"},
+{ERR_FUNC(DSO_F_WIN32_PATHBYADDR),     "WIN32_PATHBYADDR"},
 {ERR_FUNC(DSO_F_WIN32_SPLITTER),       "WIN32_SPLITTER"},
 {ERR_FUNC(DSO_F_WIN32_UNLOAD), "WIN32_UNLOAD"},
 {0,NULL}
index 49bdd71..8a15b79 100644 (file)
@@ -107,7 +107,7 @@ DSO *DSO_new_method(DSO_METHOD *meth)
                return(NULL);
                }
        memset(ret, 0, sizeof(DSO));
-       ret->meth_data = sk_new_null();
+       ret->meth_data = sk_void_new_null();
        if(ret->meth_data == NULL)
                {
                /* sk_new doesn't generate any errors so we do */
@@ -163,7 +163,7 @@ int DSO_free(DSO *dso)
                return(0);
                }
        
-       sk_free(dso->meth_data);
+       sk_void_free(dso->meth_data);
        if(dso->filename != NULL)
                OPENSSL_free(dso->filename);
        if(dso->loaded_filename != NULL)
@@ -399,13 +399,6 @@ char *DSO_merge(DSO *dso, const char *filespec1, const char *filespec2)
                DSOerr(DSO_F_DSO_MERGE,ERR_R_PASSED_NULL_PARAMETER);
                return(NULL);
                }
-       if(filespec1 == NULL)
-               filespec1 = dso->filename;
-       if(filespec1 == NULL)
-               {
-               DSOerr(DSO_F_DSO_MERGE,DSO_R_NO_FILE_SPECIFICATION);
-               return(NULL);
-               }
        if((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0)
                {
                if(dso->merger != NULL)
@@ -464,3 +457,27 @@ const char *DSO_get_loaded_filename(DSO *dso)
                }
        return(dso->loaded_filename);
        }
+
+int DSO_pathbyaddr(void *addr,char *path,int sz)
+       {
+       DSO_METHOD *meth = default_DSO_meth;
+       if (meth == NULL) meth = DSO_METHOD_openssl();
+       if (meth->pathbyaddr == NULL)
+               {
+               DSOerr(DSO_F_DSO_PATHBYADDR,DSO_R_UNSUPPORTED);
+               return -1;
+               }
+       return (*meth->pathbyaddr)(addr,path,sz);
+       }
+
+void *DSO_global_lookup(const char *name)
+       {
+       DSO_METHOD *meth = default_DSO_meth;
+       if (meth == NULL) meth = DSO_METHOD_openssl();
+       if (meth->globallookup == NULL)
+               {
+               DSOerr(DSO_F_DSO_GLOBAL_LOOKUP,DSO_R_UNSUPPORTED);
+               return NULL;
+               }
+       return (*meth->globallookup)(name);
+       }
index 4972984..49d842d 100644 (file)
@@ -78,7 +78,9 @@ static DSO_METHOD dso_meth_null = {
        NULL, /* dso_name_converter */
        NULL, /* dso_merger */
        NULL, /* init */
-       NULL  /* finish */
+       NULL, /* finish */
+       NULL, /* pathbyaddr */
+       NULL  /* globallookup */
        };
 
 DSO_METHOD *DSO_METHOD_null(void)
index a4395eb..b17e8e8 100644 (file)
@@ -74,6 +74,8 @@ DSO_METHOD *DSO_METHOD_openssl(void)
        return(DSO_METHOD_win32());
 #elif defined(DSO_VMS)
        return(DSO_METHOD_vms());
+#elif defined(DSO_BEOS)
+       return(DSO_METHOD_beos());
 #else
        return(DSO_METHOD_null());
 #endif
index 2c434ee..eee20d1 100644 (file)
 #include <stsdef.h>
 #include <descrip.h>
 #include <starlet.h>
+#include "vms_rms.h"
 #endif
 
+/* Some compiler options may mask the declaration of "_malloc32". */
+#if __INITIAL_POINTER_SIZE && defined _ANSI_C_SOURCE
+# if __INITIAL_POINTER_SIZE == 64
+#  pragma pointer_size save
+#  pragma pointer_size 32
+    void * _malloc32  (__size_t);
+#  pragma pointer_size restore
+# endif /* __INITIAL_POINTER_SIZE == 64 */
+#endif /* __INITIAL_POINTER_SIZE && defined _ANSI_C_SOURCE */
+
+
 #ifndef OPENSSL_SYS_VMS
 DSO_METHOD *DSO_METHOD_vms(void)
        {
@@ -121,14 +133,13 @@ typedef struct dso_internal_st
        /* This should contain the name only, no directory,
         * no extension, nothing but a name. */
        struct dsc$descriptor_s filename_dsc;
-       char filename[FILENAME_MAX+1];
+       char filename[ NAMX_MAXRSS+ 1];
        /* This contains whatever is not in filename, if needed.
         * Normally not defined. */
        struct dsc$descriptor_s imagename_dsc;
-       char imagename[FILENAME_MAX+1];
+       char imagename[ NAMX_MAXRSS+ 1];
        } DSO_VMS_INTERNAL;
 
-
 DSO_METHOD *DSO_METHOD_vms(void)
        {
        return(&dso_meth_vms);
@@ -139,7 +150,22 @@ static int vms_load(DSO *dso)
        void *ptr = NULL;
        /* See applicable comments in dso_dl.c */
        char *filename = DSO_convert_filename(dso, NULL);
-       DSO_VMS_INTERNAL *p;
+
+/* Ensure 32-bit pointer for "p", and appropriate malloc() function. */
+#if __INITIAL_POINTER_SIZE == 64
+# define DSO_MALLOC _malloc32
+# pragma pointer_size save
+# pragma pointer_size 32
+#else /* __INITIAL_POINTER_SIZE == 64 */
+# define DSO_MALLOC OPENSSL_malloc
+#endif /* __INITIAL_POINTER_SIZE == 64 [else] */
+
+       DSO_VMS_INTERNAL *p = NULL;
+
+#if __INITIAL_POINTER_SIZE == 64
+# pragma pointer_size restore
+#endif /* __INITIAL_POINTER_SIZE == 64 */
+
        const char *sp1, *sp2;  /* Search result */
 
        if(filename == NULL)
@@ -192,7 +218,7 @@ static int vms_load(DSO *dso)
                goto err;
                }
 
-       p = (DSO_VMS_INTERNAL *)OPENSSL_malloc(sizeof(DSO_VMS_INTERNAL));
+       p = DSO_MALLOC(sizeof(DSO_VMS_INTERNAL));
        if(p == NULL)
                {
                DSOerr(DSO_F_VMS_LOAD,ERR_R_MALLOC_FAILURE);
@@ -215,7 +241,7 @@ static int vms_load(DSO *dso)
        p->imagename_dsc.dsc$b_class = DSC$K_CLASS_S;
        p->imagename_dsc.dsc$a_pointer = p->imagename;
 
-       if(!sk_push(dso->meth_data, (char *)p))
+       if(!sk_void_push(dso->meth_data, (char *)p))
                {
                DSOerr(DSO_F_VMS_LOAD,DSO_R_STACK_ERROR);
                goto err;
@@ -245,9 +271,9 @@ static int vms_unload(DSO *dso)
                DSOerr(DSO_F_VMS_UNLOAD,ERR_R_PASSED_NULL_PARAMETER);
                return(0);
                }
-       if(sk_num(dso->meth_data) < 1)
+       if(sk_void_num(dso->meth_data) < 1)
                return(1);
-       p = (DSO_VMS_INTERNAL *)sk_pop(dso->meth_data);
+       p = (DSO_VMS_INTERNAL *)sk_void_pop(dso->meth_data);
        if(p == NULL)
                {
                DSOerr(DSO_F_VMS_UNLOAD,DSO_R_NULL_HANDLE);
@@ -290,25 +316,45 @@ void vms_bind_sym(DSO *dso, const char *symname, void **sym)
        int flags = 0;
 #endif
        struct dsc$descriptor_s symname_dsc;
-       *sym = NULL;
 
-       symname_dsc.dsc$w_length = strlen(symname);
-       symname_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
-       symname_dsc.dsc$b_class = DSC$K_CLASS_S;
-       symname_dsc.dsc$a_pointer = (char *)symname; /* The cast is needed */
+/* Arrange 32-bit pointer to (copied) string storage, if needed. */
+#if __INITIAL_POINTER_SIZE == 64
+# define SYMNAME symname_32p
+# pragma pointer_size save
+# pragma pointer_size 32
+       char *symname_32p;
+# pragma pointer_size restore
+       char symname_32[ NAMX_MAXRSS+ 1];
+#else /* __INITIAL_POINTER_SIZE == 64 */
+# define SYMNAME ((char *) symname)
+#endif /* __INITIAL_POINTER_SIZE == 64 [else] */
+
+       *sym = NULL;
 
        if((dso == NULL) || (symname == NULL))
                {
                DSOerr(DSO_F_VMS_BIND_SYM,ERR_R_PASSED_NULL_PARAMETER);
                return;
                }
-       if(sk_num(dso->meth_data) < 1)
+
+#if __INITIAL_POINTER_SIZE == 64
+       /* Copy the symbol name to storage with a 32-bit pointer. */
+       symname_32p = symname_32;
+       strcpy( symname_32p, symname);
+#endif /* __INITIAL_POINTER_SIZE == 64 [else] */
+
+       symname_dsc.dsc$w_length = strlen(SYMNAME);
+       symname_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
+       symname_dsc.dsc$b_class = DSC$K_CLASS_S;
+       symname_dsc.dsc$a_pointer = SYMNAME;
+
+       if(sk_void_num(dso->meth_data) < 1)
                {
                DSOerr(DSO_F_VMS_BIND_SYM,DSO_R_STACK_ERROR);
                return;
                }
-       ptr = (DSO_VMS_INTERNAL *)sk_value(dso->meth_data,
-               sk_num(dso->meth_data) - 1);
+       ptr = (DSO_VMS_INTERNAL *)sk_void_value(dso->meth_data,
+               sk_void_num(dso->meth_data) - 1);
        if(ptr == NULL)
                {
                DSOerr(DSO_F_VMS_BIND_SYM,DSO_R_NULL_HANDLE);
@@ -372,64 +418,60 @@ static DSO_FUNC_TYPE vms_bind_func(DSO *dso, const char *symname)
        return sym;
        }
 
+
 static char *vms_merger(DSO *dso, const char *filespec1, const char *filespec2)
        {
        int status;
        int filespec1len, filespec2len;
        struct FAB fab;
-#ifdef NAML$C_MAXRSS
-       struct NAML nam;
-       char esa[NAML$C_MAXRSS];
-#else
-       struct NAM nam;
-       char esa[NAM$C_MAXRSS];
-#endif
+       struct NAMX_STRUCT nam;
+       char esa[ NAMX_MAXRSS+ 1];
        char *merged;
 
+/* Arrange 32-bit pointer to (copied) string storage, if needed. */
+#if __INITIAL_POINTER_SIZE == 64
+# define FILESPEC1 filespec1_32p;
+# define FILESPEC2 filespec2_32p;
+# pragma pointer_size save
+# pragma pointer_size 32
+       char *filespec1_32p;
+       char *filespec2_32p;
+# pragma pointer_size restore
+       char filespec1_32[ NAMX_MAXRSS+ 1];
+       char filespec2_32[ NAMX_MAXRSS+ 1];
+#else /* __INITIAL_POINTER_SIZE == 64 */
+# define FILESPEC1 ((char *) filespec1)
+# define FILESPEC2 ((char *) filespec2)
+#endif /* __INITIAL_POINTER_SIZE == 64 [else] */
+
        if (!filespec1) filespec1 = "";
        if (!filespec2) filespec2 = "";
        filespec1len = strlen(filespec1);
        filespec2len = strlen(filespec2);
 
+#if __INITIAL_POINTER_SIZE == 64
+       /* Copy the file names to storage with a 32-bit pointer. */
+       filespec1_32p = filespec1_32;
+       filespec2_32p = filespec2_32;
+       strcpy( filespec1_32p, filespec1);
+       strcpy( filespec2_32p, filespec2);
+#endif /* __INITIAL_POINTER_SIZE == 64 [else] */
+
        fab = cc$rms_fab;
-#ifdef NAML$C_MAXRSS
-       nam = cc$rms_naml;
-#else
-       nam = cc$rms_nam;
-#endif
+       nam = CC_RMS_NAMX;
 
-       fab.fab$l_fna = (char *)filespec1;
-       fab.fab$b_fns = filespec1len;
-       fab.fab$l_dna = (char *)filespec2;
-       fab.fab$b_dns = filespec2len;
-#ifdef NAML$C_MAXRSS
-       if (filespec1len > NAM$C_MAXRSS)
-               {
-               fab.fab$l_fna = 0;
-               fab.fab$b_fns = 0;
-               nam.naml$l_long_filename = (char *)filespec1;
-               nam.naml$l_long_filename_size = filespec1len;
-               }
-       if (filespec2len > NAM$C_MAXRSS)
-               {
-               fab.fab$l_dna = 0;
-               fab.fab$b_dns = 0;
-               nam.naml$l_long_defname = (char *)filespec2;
-               nam.naml$l_long_defname_size = filespec2len;
-               }
-       nam.naml$l_esa = esa;
-       nam.naml$b_ess = NAM$C_MAXRSS;
-       nam.naml$l_long_expand = esa;
-       nam.naml$l_long_expand_alloc = sizeof(esa);
-       nam.naml$b_nop = NAM$M_SYNCHK | NAM$M_PWD;
-       nam.naml$v_no_short_upcase = 1;
-       fab.fab$l_naml = &nam;
-#else
-       nam.nam$l_esa = esa;
-       nam.nam$b_ess = NAM$C_MAXRSS;
-       nam.nam$b_nop = NAM$M_SYNCHK | NAM$M_PWD;
-       fab.fab$l_nam = &nam;
-#endif
+       FAB_OR_NAML( fab, nam).FAB_OR_NAML_FNA = FILESPEC1;
+       FAB_OR_NAML( fab, nam).FAB_OR_NAML_FNS = filespec1len;
+       FAB_OR_NAML( fab, nam).FAB_OR_NAML_DNA = FILESPEC2;
+       FAB_OR_NAML( fab, nam).FAB_OR_NAML_DNS = filespec2len;
+       NAMX_DNA_FNA_SET( fab)
+
+       nam.NAMX_ESA = esa;
+       nam.NAMX_ESS = NAMX_MAXRSS;
+       nam.NAMX_NOP = NAM$M_SYNCHK | NAM$M_PWD;
+       SET_NAMX_NO_SHORT_UPCASE( nam);
+
+       fab.FAB_NAMX = &nam;
 
        status = sys$parse(&fab, 0, 0);
 
@@ -460,33 +502,12 @@ static char *vms_merger(DSO *dso, const char *filespec1, const char *filespec2)
                        }
                return(NULL);
                }
-#ifdef NAML$C_MAXRSS
-       if (nam.naml$l_long_expand_size)
-               {
-               merged = OPENSSL_malloc(nam.naml$l_long_expand_size + 1);
-               if(!merged)
-                       goto malloc_err;
-               strncpy(merged, nam.naml$l_long_expand,
-                       nam.naml$l_long_expand_size);
-               merged[nam.naml$l_long_expand_size] = '\0';
-               }
-       else
-               {
-               merged = OPENSSL_malloc(nam.naml$b_esl + 1);
-               if(!merged)
-                       goto malloc_err;
-               strncpy(merged, nam.naml$l_esa,
-                       nam.naml$b_esl);
-               merged[nam.naml$b_esl] = '\0';
-               }
-#else
-       merged = OPENSSL_malloc(nam.nam$b_esl + 1);
+
+       merged = OPENSSL_malloc( nam.NAMX_ESL+ 1);
        if(!merged)
                goto malloc_err;
-       strncpy(merged, nam.nam$l_esa,
-               nam.nam$b_esl);
-       merged[nam.nam$b_esl] = '\0';
-#endif
+       strncpy( merged, nam.NAMX_ESA, nam.NAMX_ESL);
+       merged[ nam.NAMX_ESL] = '\0';
        return(merged);
  malloc_err:
        DSOerr(DSO_F_VMS_MERGER,
index f340052..6fb6c54 100644 (file)
@@ -96,7 +96,11 @@ static HINSTANCE LoadLibraryA(LPCSTR lpLibFileName)
 #else
        fnamw = (WCHAR *)alloca (len_0*sizeof(WCHAR));
 #endif
-       if (fnamw == NULL) return NULL;
+       if (fnamw == NULL)
+               {
+               SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+               return NULL;
+               }
 
 #if defined(_WIN32_WCE) && _WIN32_WCE>=101
        if (!MultiByteToWideChar(CP_ACP,0,lpLibFileName,len_0,fnamw,len_0))
@@ -124,6 +128,8 @@ static long win32_ctrl(DSO *dso, int cmd, long larg, void *parg);
 static char *win32_name_converter(DSO *dso, const char *filename);
 static char *win32_merger(DSO *dso, const char *filespec1,
        const char *filespec2);
+static int win32_pathbyaddr(void *addr,char *path,int sz);
+static void *win32_globallookup(const char *name);
 
 static const char *openssl_strnchr(const char *string, int c, size_t len);
 
@@ -142,7 +148,9 @@ static DSO_METHOD dso_meth_win32 = {
        win32_name_converter,
        win32_merger,
        NULL, /* init */
-       NULL  /* finish */
+       NULL, /* finish */
+       win32_pathbyaddr,
+       win32_globallookup
        };
 
 DSO_METHOD *DSO_METHOD_win32(void)
@@ -180,7 +188,7 @@ static int win32_load(DSO *dso)
                goto err;
                }
        *p = h;
-       if(!sk_push(dso->meth_data, (char *)p))
+       if(!sk_void_push(dso->meth_data, p))
                {
                DSOerr(DSO_F_WIN32_LOAD,DSO_R_STACK_ERROR);
                goto err;
@@ -207,9 +215,9 @@ static int win32_unload(DSO *dso)
                DSOerr(DSO_F_WIN32_UNLOAD,ERR_R_PASSED_NULL_PARAMETER);
                return(0);
                }
-       if(sk_num(dso->meth_data) < 1)
+       if(sk_void_num(dso->meth_data) < 1)
                return(1);
-       p = (HINSTANCE *)sk_pop(dso->meth_data);
+       p = sk_void_pop(dso->meth_data);
        if(p == NULL)
                {
                DSOerr(DSO_F_WIN32_UNLOAD,DSO_R_NULL_HANDLE);
@@ -220,7 +228,7 @@ static int win32_unload(DSO *dso)
                DSOerr(DSO_F_WIN32_UNLOAD,DSO_R_UNLOAD_FAILED);
                /* We should push the value back onto the stack in
                 * case of a retry. */
-               sk_push(dso->meth_data, (char *)p);
+               sk_void_push(dso->meth_data, p);
                return(0);
                }
        /* Cleanup */
@@ -240,12 +248,12 @@ static void *win32_bind_var(DSO *dso, const char *symname)
                DSOerr(DSO_F_WIN32_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
                return(NULL);
                }
-       if(sk_num(dso->meth_data) < 1)
+       if(sk_void_num(dso->meth_data) < 1)
                {
                DSOerr(DSO_F_WIN32_BIND_VAR,DSO_R_STACK_ERROR);
                return(NULL);
                }
-       ptr = (HINSTANCE *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
+       ptr = sk_void_value(dso->meth_data, sk_void_num(dso->meth_data) - 1);
        if(ptr == NULL)
                {
                DSOerr(DSO_F_WIN32_BIND_VAR,DSO_R_NULL_HANDLE);
@@ -271,12 +279,12 @@ static DSO_FUNC_TYPE win32_bind_func(DSO *dso, const char *symname)
                DSOerr(DSO_F_WIN32_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER);
                return(NULL);
                }
-       if(sk_num(dso->meth_data) < 1)
+       if(sk_void_num(dso->meth_data) < 1)
                {
                DSOerr(DSO_F_WIN32_BIND_FUNC,DSO_R_STACK_ERROR);
                return(NULL);
                }
-       ptr = (HINSTANCE *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
+       ptr = sk_void_value(dso->meth_data, sk_void_num(dso->meth_data) - 1);
        if(ptr == NULL)
                {
                DSOerr(DSO_F_WIN32_BIND_FUNC,DSO_R_NULL_HANDLE);
@@ -351,7 +359,7 @@ static struct file_st *win32_splitter(DSO *dso, const char *filename,
                                return(NULL);
                                }
                        result->device = start;
-                       result->devicelen = filename - start;
+                       result->devicelen = (int)(filename - start);
                        position = IN_FILE;
                        start = ++filename;
                        result->dir = start;
@@ -360,7 +368,7 @@ static struct file_st *win32_splitter(DSO *dso, const char *filename,
                case '/':
                        if(position == IN_NODE)
                                {
-                               result->nodelen = filename - start;
+                               result->nodelen = (int)(filename - start);
                                position = IN_FILE;
                                start = ++filename;
                                result->dir = start;
@@ -370,20 +378,20 @@ static struct file_st *win32_splitter(DSO *dso, const char *filename,
                                position = IN_FILE;
                                filename++;
                                result->dir = start;
-                               result->dirlen = filename - start;
+                               result->dirlen = (int)(filename - start);
                                start = filename;
                                }
                        else
                                {
                                filename++;
-                               result->dirlen += filename - start;
+                               result->dirlen += (int)(filename - start);
                                start = filename;
                                }
                        break;
                case '\0':
                        if(position == IN_NODE)
                                {
-                               result->nodelen = filename - start;
+                               result->nodelen = (int)(filename - start);
                                }
                        else
                                {
@@ -397,13 +405,13 @@ static struct file_st *win32_splitter(DSO *dso, const char *filename,
                                                        result->dirlen = 0;
                                                        }
                                                result->dirlen +=
-                                                       filename - start;
+                                                       (int)(filename - start);
                                                }
                                        else
                                                {
                                                result->file = start;
                                                result->filelen =
-                                                       filename - start;
+                                                       (int)(filename - start);
                                                }
                                        }
                                }
@@ -497,7 +505,7 @@ static char *win32_joiner(DSO *dso, const struct file_st *file_split)
                                + file_split->predirlen
                                - (start - file_split->predir);
                strncpy(&result[offset], start,
-                       end - start); offset += end - start;
+                       end - start); offset += (int)(end - start);
                result[offset] = '\\'; offset++;
                start = end + 1;
                }
@@ -518,7 +526,7 @@ static char *win32_joiner(DSO *dso, const struct file_st *file_split)
                                + file_split->dirlen
                                - (start - file_split->dir);
                strncpy(&result[offset], start,
-                       end - start); offset += end - start;
+                       end - start); offset += (int)(end - start);
                result[offset] = '\\'; offset++;
                start = end + 1;
                }
@@ -659,5 +667,178 @@ static const char *openssl_strnchr(const char *string, int c, size_t len)
        return NULL;
        }
 
+#include <tlhelp32.h>
+#ifdef _WIN32_WCE
+# define DLLNAME "TOOLHELP.DLL"
+#else
+# ifdef MODULEENTRY32
+# undef MODULEENTRY32  /* unmask the ASCII version! */
+# endif
+# define DLLNAME "KERNEL32.DLL"
+#endif
+
+typedef HANDLE (WINAPI *CREATETOOLHELP32SNAPSHOT)(DWORD, DWORD);
+typedef BOOL (WINAPI *CLOSETOOLHELP32SNAPSHOT)(HANDLE);
+typedef BOOL (WINAPI *MODULE32)(HANDLE, MODULEENTRY32 *);
 
-#endif /* OPENSSL_SYS_WIN32 */
+static int win32_pathbyaddr(void *addr,char *path,int sz)
+       {
+       HMODULE dll;
+       HANDLE hModuleSnap = INVALID_HANDLE_VALUE; 
+       MODULEENTRY32 me32; 
+       CREATETOOLHELP32SNAPSHOT create_snap;
+       CLOSETOOLHELP32SNAPSHOT  close_snap;
+       MODULE32 module_first, module_next;
+       int len;
+       if (addr == NULL)
+               {
+               union   { int(*f)(void*,char*,int); void *p; } t =
+                       { win32_pathbyaddr };
+               addr = t.p;
+               }
+
+       dll = LoadLibrary(TEXT(DLLNAME));
+       if (dll == NULL)
+               {
+               DSOerr(DSO_F_WIN32_PATHBYADDR,DSO_R_UNSUPPORTED);
+               return -1;
+               }
+
+       create_snap = (CREATETOOLHELP32SNAPSHOT)
+               GetProcAddress(dll,"CreateToolhelp32Snapshot");
+       if (create_snap == NULL)
+               {
+               FreeLibrary(dll);
+               DSOerr(DSO_F_WIN32_PATHBYADDR,DSO_R_UNSUPPORTED);
+               return -1;
+               }
+       /* We take the rest for granted... */
+#ifdef _WIN32_WCE
+       close_snap = (CLOSETOOLHELP32SNAPSHOT)
+               GetProcAddress(dll,"CloseToolhelp32Snapshot");
+#else
+       close_snap = (CLOSETOOLHELP32SNAPSHOT)CloseHandle;
+#endif
+       module_first = (MODULE32)GetProcAddress(dll,"Module32First");
+       module_next  = (MODULE32)GetProcAddress(dll,"Module32Next");
+
+       hModuleSnap = (*create_snap)(TH32CS_SNAPMODULE,0); 
+       if( hModuleSnap == INVALID_HANDLE_VALUE ) 
+               { 
+               FreeLibrary(dll);
+               DSOerr(DSO_F_WIN32_PATHBYADDR,DSO_R_UNSUPPORTED);
+               return -1;
+               } 
+       me32.dwSize = sizeof(me32); 
+       if(!(*module_first)(hModuleSnap,&me32)) 
+               { 
+               (*close_snap)(hModuleSnap);
+               FreeLibrary(dll);
+               DSOerr(DSO_F_WIN32_PATHBYADDR,DSO_R_FAILURE);
+               return -1;
+               }
+       do      { 
+               if ((BYTE *)addr >= me32.modBaseAddr &&
+                   (BYTE *)addr <  me32.modBaseAddr+me32.modBaseSize)
+                       {
+                       (*close_snap)(hModuleSnap);
+                       FreeLibrary(dll);
+#ifdef _WIN32_WCE
+# if _WIN32_WCE >= 101
+                       return WideCharToMultiByte(CP_ACP,0,me32.szExePath,-1,
+                                                       path,sz,NULL,NULL);
+# else
+                       len = (int)wcslen(me32.szExePath);
+                       if (sz <= 0) return len+1;
+                       if (len >= sz) len=sz-1;
+                       for(i=0;i<len;i++)
+                               path[i] = (char)me32.szExePath[i];
+                       path[len++] = 0;
+                       return len;
+# endif
+#else
+                       len = (int)strlen(me32.szExePath);
+                       if (sz <= 0) return len+1;
+                       if (len >= sz) len=sz-1;
+                       memcpy(path,me32.szExePath,len);
+                       path[len++] = 0;
+                       return len;
+#endif
+                       } 
+               } while((*module_next)(hModuleSnap, &me32)); 
+       (*close_snap)(hModuleSnap); 
+       FreeLibrary(dll);
+       return 0;
+       }
+
+static void *win32_globallookup(const char *name)
+       {
+       HMODULE dll;
+       HANDLE hModuleSnap = INVALID_HANDLE_VALUE;
+       MODULEENTRY32 me32;
+       CREATETOOLHELP32SNAPSHOT create_snap;
+       CLOSETOOLHELP32SNAPSHOT  close_snap;
+       MODULE32 module_first, module_next;
+       FARPROC ret=NULL;
+
+       dll = LoadLibrary(TEXT(DLLNAME));
+       if (dll == NULL)
+               {
+               DSOerr(DSO_F_WIN32_GLOBALLOOKUP,DSO_R_UNSUPPORTED);
+               return NULL;
+               }
+
+       create_snap = (CREATETOOLHELP32SNAPSHOT)
+               GetProcAddress(dll,"CreateToolhelp32Snapshot");
+       if (create_snap == NULL)
+               {
+               FreeLibrary(dll);
+               DSOerr(DSO_F_WIN32_GLOBALLOOKUP,DSO_R_UNSUPPORTED);
+               return NULL;
+               }
+       /* We take the rest for granted... */
+#ifdef _WIN32_WCE
+       close_snap = (CLOSETOOLHELP32SNAPSHOT)
+               GetProcAddress(dll,"CloseToolhelp32Snapshot");
+#else
+       close_snap = (CLOSETOOLHELP32SNAPSHOT)CloseHandle;
+#endif
+       module_first = (MODULE32)GetProcAddress(dll,"Module32First");
+       module_next  = (MODULE32)GetProcAddress(dll,"Module32Next");
+
+       hModuleSnap = (*create_snap)(TH32CS_SNAPMODULE,0);
+       if( hModuleSnap == INVALID_HANDLE_VALUE )
+               {
+               FreeLibrary(dll);
+               DSOerr(DSO_F_WIN32_GLOBALLOOKUP,DSO_R_UNSUPPORTED);
+               return NULL;
+               }
+
+       me32.dwSize = sizeof(me32);
+
+       if (!(*module_first)(hModuleSnap,&me32))
+               {
+               (*close_snap)(hModuleSnap);
+               FreeLibrary(dll);
+               return NULL;
+               }
+
+       do      {
+               if ((ret = GetProcAddress(me32.hModule,name)))
+                       {
+                       (*close_snap)(hModuleSnap);
+                       FreeLibrary(dll);
+                       return ret;
+                       }
+               } while((*module_next)(hModuleSnap,&me32));
+
+       (*close_snap)(hModuleSnap); 
+       FreeLibrary(dll);
+       return NULL;
+       }
+#endif /* DSO_WIN32 */
diff --git a/deps/openssl/openssl/crypto/dyn_lck.c b/deps/openssl/openssl/crypto/dyn_lck.c
deleted file mode 100644 (file)
index 7f82c41..0000000
+++ /dev/null
@@ -1,428 +0,0 @@
-/* crypto/cryptlib.c */
-/* ====================================================================
- * Copyright (c) 1998-2003 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    openssl-core@openssl.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
- * ====================================================================
- *
- * This product includes cryptographic software written by Eric Young
- * (eay@cryptsoft.com).  This product includes software written by Tim
- * Hudson (tjh@cryptsoft.com).
- *
- */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-/* ====================================================================
- * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
- * ECDH support in OpenSSL originally developed by 
- * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
- */
-
-#include "cryptlib.h"
-#include <openssl/safestack.h>
-
-#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16)
-static double SSLeay_MSVC5_hack=0.0; /* and for VC1.5 */
-#endif
-
-DECLARE_STACK_OF(CRYPTO_dynlock)
-IMPLEMENT_STACK_OF(CRYPTO_dynlock)
-
-/* real #defines in crypto.h, keep these upto date */
-static const char* const lock_names[CRYPTO_NUM_LOCKS] =
-       {
-       "<<ERROR>>",
-       "err",
-       "ex_data",
-       "x509",
-       "x509_info",
-       "x509_pkey",
-       "x509_crl",
-       "x509_req",
-       "dsa",
-       "rsa",
-       "evp_pkey",
-       "x509_store",
-       "ssl_ctx",
-       "ssl_cert",
-       "ssl_session",
-       "ssl_sess_cert",
-       "ssl",
-       "ssl_method",
-       "rand",
-       "rand2",
-       "debug_malloc",
-       "BIO",
-       "gethostbyname",
-       "getservbyname",
-       "readdir",
-       "RSA_blinding",
-       "dh",
-       "debug_malloc2",
-       "dso",
-       "dynlock",
-       "engine",
-       "ui",
-       "ecdsa",
-       "ec",
-       "ecdh",
-       "bn",
-       "ec_pre_comp",
-       "store",
-       "comp",
-#ifndef OPENSSL_FIPS
-# if CRYPTO_NUM_LOCKS != 39
-#  error "Inconsistency between crypto.h and cryptlib.c"
-# endif
-#else
-       "fips",
-       "fips2",
-# if CRYPTO_NUM_LOCKS != 41
-#  error "Inconsistency between crypto.h and cryptlib.c"
-# endif
-#endif
-       };
-
-/* This is for applications to allocate new type names in the non-dynamic
-   array of lock names.  These are numbered with positive numbers.  */
-static STACK *app_locks=NULL;
-
-/* For applications that want a more dynamic way of handling threads, the
-   following stack is used.  These are externally numbered with negative
-   numbers.  */
-static STACK_OF(CRYPTO_dynlock) *dyn_locks=NULL;
-
-
-static struct CRYPTO_dynlock_value *(MS_FAR *dynlock_create_callback)
-       (const char *file,int line)=NULL;
-static void (MS_FAR *dynlock_lock_callback)(int mode,
-       struct CRYPTO_dynlock_value *l, const char *file,int line)=NULL;
-static void (MS_FAR *dynlock_destroy_callback)(struct CRYPTO_dynlock_value *l,
-       const char *file,int line)=NULL;
-
-int CRYPTO_get_new_lockid(char *name)
-       {
-       char *str;
-       int i;
-
-#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16)
-       /* A hack to make Visual C++ 5.0 work correctly when linking as
-        * a DLL using /MT. Without this, the application cannot use
-        * and floating point printf's.
-        * It also seems to be needed for Visual C 1.5 (win16) */
-       SSLeay_MSVC5_hack=(double)name[0]*(double)name[1];
-#endif
-
-       if ((app_locks == NULL) && ((app_locks=sk_new_null()) == NULL))
-               {
-               CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID,ERR_R_MALLOC_FAILURE);
-               return(0);
-               }
-       if ((str=BUF_strdup(name)) == NULL)
-               {
-               CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID,ERR_R_MALLOC_FAILURE);
-               return(0);
-               }
-       i=sk_push(app_locks,str);
-       if (!i)
-               OPENSSL_free(str);
-       else
-               i+=CRYPTO_NUM_LOCKS; /* gap of one :-) */
-       return(i);
-       }
-
-int CRYPTO_get_new_dynlockid(void)
-       {
-       int i = 0;
-       CRYPTO_dynlock *pointer = NULL;
-
-       if (dynlock_create_callback == NULL)
-               {
-               CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,CRYPTO_R_NO_DYNLOCK_CREATE_CALLBACK);
-               return(0);
-               }
-       CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK);
-       if ((dyn_locks == NULL)
-               && ((dyn_locks=sk_CRYPTO_dynlock_new_null()) == NULL))
-               {
-               CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
-               CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,ERR_R_MALLOC_FAILURE);
-               return(0);
-               }
-       CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
-
-       pointer = (CRYPTO_dynlock *)OPENSSL_malloc(sizeof(CRYPTO_dynlock));
-       if (pointer == NULL)
-               {
-               CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,ERR_R_MALLOC_FAILURE);
-               return(0);
-               }
-       pointer->references = 1;
-       pointer->data = dynlock_create_callback(__FILE__,__LINE__);
-       if (pointer->data == NULL)
-               {
-               OPENSSL_free(pointer);
-               CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,ERR_R_MALLOC_FAILURE);
-               return(0);
-               }
-
-       CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK);
-       /* First, try to find an existing empty slot */
-       i=sk_CRYPTO_dynlock_find(dyn_locks,NULL);
-       /* If there was none, push, thereby creating a new one */
-       if (i == -1)
-               /* Since sk_push() returns the number of items on the
-                  stack, not the location of the pushed item, we need
-                  to transform the returned number into a position,
-                  by decreasing it.  */
-               i=sk_CRYPTO_dynlock_push(dyn_locks,pointer) - 1;
-       else
-               /* If we found a place with a NULL pointer, put our pointer
-                  in it.  */
-               (void)sk_CRYPTO_dynlock_set(dyn_locks,i,pointer);
-       CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
-
-       if (i == -1)
-               {
-               dynlock_destroy_callback(pointer->data,__FILE__,__LINE__);
-               OPENSSL_free(pointer);
-               }
-       else
-               i += 1; /* to avoid 0 */
-       return -i;
-       }
-
-void CRYPTO_destroy_dynlockid(int i)
-       {
-       CRYPTO_dynlock *pointer = NULL;
-       if (i)
-               i = -i-1;
-       if (dynlock_destroy_callback == NULL)
-               return;
-
-       CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK);
-
-       if (dyn_locks == NULL || i >= sk_CRYPTO_dynlock_num(dyn_locks))
-               {
-               CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
-               return;
-               }
-       pointer = sk_CRYPTO_dynlock_value(dyn_locks, i);
-       if (pointer != NULL)
-               {
-               --pointer->references;
-#ifdef REF_CHECK
-               if (pointer->references < 0)
-                       {
-                       fprintf(stderr,"CRYPTO_destroy_dynlockid, bad reference count\n");
-                       abort();
-                       }
-               else
-#endif
-                       if (pointer->references <= 0)
-                               {
-                               (void)sk_CRYPTO_dynlock_set(dyn_locks, i, NULL);
-                               }
-                       else
-                               pointer = NULL;
-               }
-       CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
-
-       if (pointer)
-               {
-               dynlock_destroy_callback(pointer->data,__FILE__,__LINE__);
-               OPENSSL_free(pointer);
-               }
-       }
-
-struct CRYPTO_dynlock_value *CRYPTO_get_dynlock_value(int i)
-       {
-       CRYPTO_dynlock *pointer = NULL;
-       if (i)
-               i = -i-1;
-
-       CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK);
-
-       if (dyn_locks != NULL && i < sk_CRYPTO_dynlock_num(dyn_locks))
-               pointer = sk_CRYPTO_dynlock_value(dyn_locks, i);
-       if (pointer)
-               pointer->references++;
-
-       CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
-
-       if (pointer)
-               return pointer->data;
-       return NULL;
-       }
-
-struct CRYPTO_dynlock_value *(*CRYPTO_get_dynlock_create_callback(void))
-       (const char *file,int line)
-       {
-       return(dynlock_create_callback);
-       }
-
-void (*CRYPTO_get_dynlock_lock_callback(void))(int mode,
-       struct CRYPTO_dynlock_value *l, const char *file,int line)
-       {
-       return(dynlock_lock_callback);
-       }
-
-void (*CRYPTO_get_dynlock_destroy_callback(void))
-       (struct CRYPTO_dynlock_value *l, const char *file,int line)
-       {
-       return(dynlock_destroy_callback);
-       }
-
-void CRYPTO_set_dynlock_create_callback(struct CRYPTO_dynlock_value *(*func)
-       (const char *file, int line))
-       {
-       dynlock_create_callback=func;
-       }
-
-static void do_dynlock(int mode, int type, const char *file, int line)
-       {
-       if (dynlock_lock_callback != NULL)
-               {
-               struct CRYPTO_dynlock_value *pointer
-                               = CRYPTO_get_dynlock_value(type);
-
-               OPENSSL_assert(pointer != NULL);
-
-               dynlock_lock_callback(mode, pointer, file, line);
-
-               CRYPTO_destroy_dynlockid(type);
-               }
-       }
-
-void CRYPTO_set_dynlock_lock_callback(void (*func)(int mode,
-       struct CRYPTO_dynlock_value *l, const char *file, int line))
-       {
-       /* Set callback so CRYPTO_lock() can now handle dynamic locks.
-        * This is OK because at this point and application shouldn't be using
-        * OpenSSL from multiple threads because it is setting up the locking
-        * callbacks.
-        */
-       static int done = 0;
-       if (!done)
-               {
-               int_CRYPTO_set_do_dynlock_callback(do_dynlock);
-               done = 1;
-               }
-               
-       dynlock_lock_callback=func;
-       }
-
-void CRYPTO_set_dynlock_destroy_callback(void (*func)
-       (struct CRYPTO_dynlock_value *l, const char *file, int line))
-       {
-       dynlock_destroy_callback=func;
-       }
-
-const char *CRYPTO_get_lock_name(int type)
-       {
-       if (type < 0)
-               return("dynamic");
-       else if (type < CRYPTO_NUM_LOCKS)
-               return(lock_names[type]);
-       else if (type-CRYPTO_NUM_LOCKS > sk_num(app_locks))
-               return("ERROR");
-       else
-               return(sk_value(app_locks,type-CRYPTO_NUM_LOCKS));
-       }
-
index b5bbc9f..db380ed 100644 (file)
@@ -19,11 +19,11 @@ APPS=
 LIB=$(TOP)/libcrypto.a
 LIBSRC=        ec_lib.c ecp_smpl.c ecp_mont.c ecp_nist.c ec_cvt.c ec_mult.c\
        ec_err.c ec_curve.c ec_check.c ec_print.c ec_asn1.c ec_key.c\
-       ec2_smpl.c ec2_smpt.c ec2_mult.c
+       ec2_smpl.c ec2_mult.c ec_ameth.c ec_pmeth.c eck_prn.c
 
 LIBOBJ=        ec_lib.o ecp_smpl.o ecp_mont.o ecp_nist.o ec_cvt.o ec_mult.o\
        ec_err.o ec_curve.o ec_check.o ec_print.o ec_asn1.o ec_key.o\
-       ec2_smpl.o ec2_mult.o
+       ec2_smpl.o ec2_mult.o ec_ameth.o ec_pmeth.o eck_prn.o
 
 SRC= $(LIBSRC)
 
@@ -38,7 +38,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -94,8 +94,22 @@ ec2_smpl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
 ec2_smpl.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
 ec2_smpl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 ec2_smpl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-ec2_smpl.o: ../../include/openssl/symhacks.h ec2_smpl.c ec2_smpt.c ec_lcl.h
-ec2_smpt.o: ec2_smpt.c
+ec2_smpl.o: ../../include/openssl/symhacks.h ec2_smpl.c ec_lcl.h
+ec_ameth.o: ../../e_os.h ../../include/openssl/asn1.h
+ec_ameth.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
+ec_ameth.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h
+ec_ameth.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+ec_ameth.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+ec_ameth.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
+ec_ameth.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+ec_ameth.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+ec_ameth.o: ../../include/openssl/opensslconf.h
+ec_ameth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+ec_ameth.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+ec_ameth.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+ec_ameth.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+ec_ameth.o: ../../include/openssl/x509_vfy.h ../asn1/asn1_locl.h ../cryptlib.h
+ec_ameth.o: ec_ameth.c
 ec_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
 ec_asn1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
 ec_asn1.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
@@ -160,6 +174,20 @@ ec_mult.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
 ec_mult.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 ec_mult.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
 ec_mult.o: ../../include/openssl/symhacks.h ec_lcl.h ec_mult.c
+ec_pmeth.o: ../../e_os.h ../../include/openssl/asn1.h
+ec_pmeth.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
+ec_pmeth.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
+ec_pmeth.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+ec_pmeth.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
+ec_pmeth.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+ec_pmeth.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+ec_pmeth.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+ec_pmeth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+ec_pmeth.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+ec_pmeth.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+ec_pmeth.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+ec_pmeth.o: ../../include/openssl/x509_vfy.h ../cryptlib.h ../evp/evp_locl.h
+ec_pmeth.o: ec_pmeth.c
 ec_print.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
 ec_print.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
 ec_print.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
@@ -167,6 +195,16 @@ ec_print.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
 ec_print.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 ec_print.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
 ec_print.o: ../../include/openssl/symhacks.h ec_lcl.h ec_print.c
+eck_prn.o: ../../e_os.h ../../include/openssl/asn1.h
+eck_prn.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
+eck_prn.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
+eck_prn.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+eck_prn.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+eck_prn.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+eck_prn.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+eck_prn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+eck_prn.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+eck_prn.o: ../../include/openssl/symhacks.h ../cryptlib.h eck_prn.c
 ecp_mont.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
 ecp_mont.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
 ecp_mont.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
index 8bc2a23..ee70781 100644 (file)
@@ -2,8 +2,12 @@
 /*
  * Originally written by Bodo Moeller for the OpenSSL project.
  */
+/**
+ * \file crypto/ec/ec.h Include file for the OpenSSL EC functions
+ * \author Originally written by Bodo Moeller for the OpenSSL project
+ */
 /* ====================================================================
- * Copyright (c) 1998-2003 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2005 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -92,15 +96,21 @@ extern "C" {
 # endif
 #endif
 
-
+  
 #ifndef OPENSSL_ECC_MAX_FIELD_BITS
 # define OPENSSL_ECC_MAX_FIELD_BITS 661
 #endif
 
+/** Enum for the point conversion form as defined in X9.62 (ECDSA)
+ *  for the encoding of a elliptic curve point (x,y) */
 typedef enum {
-       /* values as defined in X9.62 (ECDSA) and elsewhere */
+       /** the point is encoded as z||x, where the octet z specifies 
+        *  which solution of the quadratic equation y is  */
        POINT_CONVERSION_COMPRESSED = 2,
+       /** the point is encoded as z||x||y, where z is the octet 0x02  */
        POINT_CONVERSION_UNCOMPRESSED = 4,
+       /** the point is encoded as z||x||y, where the octet z specifies
+         *  which solution of the quadratic equation y is  */
        POINT_CONVERSION_HYBRID = 6
 } point_conversion_form_t;
 
@@ -121,37 +131,129 @@ typedef struct ec_group_st
 typedef struct ec_point_st EC_POINT;
 
 
-/* EC_METHODs for curves over GF(p).
- * EC_GFp_simple_method provides the basis for the optimized methods.
+/********************************************************************/
+/*               EC_METHODs for curves over GF(p)                   */       
+/********************************************************************/
+
+/** Returns the basic GFp ec methods which provides the basis for the
+ *  optimized methods. 
+ *  \return  EC_METHOD object
  */
 const EC_METHOD *EC_GFp_simple_method(void);
+
+/** Returns GFp methods using montgomery multiplication.
+ *  \return  EC_METHOD object
+ */
 const EC_METHOD *EC_GFp_mont_method(void);
+
+/** Returns GFp methods using optimized methods for NIST recommended curves
+ *  \return  EC_METHOD object
+ */
 const EC_METHOD *EC_GFp_nist_method(void);
 
-/* EC_METHOD for curves over GF(2^m).
+
+/********************************************************************/ 
+/*           EC_METHOD for curves over GF(2^m)                      */
+/********************************************************************/
+
+/** Returns the basic GF2m ec method 
+ *  \return  EC_METHOD object
  */
 const EC_METHOD *EC_GF2m_simple_method(void);
 
 
-EC_GROUP *EC_GROUP_new(const EC_METHOD *);
-void EC_GROUP_free(EC_GROUP *);
-void EC_GROUP_clear_free(EC_GROUP *);
-int EC_GROUP_copy(EC_GROUP *, const EC_GROUP *);
-EC_GROUP *EC_GROUP_dup(const EC_GROUP *);
+/********************************************************************/
+/*                   EC_GROUP functions                             */
+/********************************************************************/
 
-const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *);
-int EC_METHOD_get_field_type(const EC_METHOD *);
+/** Creates a new EC_GROUP object
+ *  \param   meth  EC_METHOD to use
+ *  \return  newly created EC_GROUP object or NULL in case of an error.
+ */
+EC_GROUP *EC_GROUP_new(const EC_METHOD *meth);
 
-int EC_GROUP_set_generator(EC_GROUP *, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor);
-const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *);
-int EC_GROUP_get_order(const EC_GROUP *, BIGNUM *order, BN_CTX *);
-int EC_GROUP_get_cofactor(const EC_GROUP *, BIGNUM *cofactor, BN_CTX *);
+/** Frees a EC_GROUP object
+ *  \param  group  EC_GROUP object to be freed.
+ */
+void EC_GROUP_free(EC_GROUP *group);
 
-void EC_GROUP_set_curve_name(EC_GROUP *, int nid);
-int EC_GROUP_get_curve_name(const EC_GROUP *);
+/** Clears and frees a EC_GROUP object
+ *  \param  group  EC_GROUP object to be cleared and freed.
+ */
+void EC_GROUP_clear_free(EC_GROUP *group);
 
-void EC_GROUP_set_asn1_flag(EC_GROUP *, int flag);
-int EC_GROUP_get_asn1_flag(const EC_GROUP *);
+/** Copies EC_GROUP objects. Note: both EC_GROUPs must use the same EC_METHOD.
+ *  \param  dst  destination EC_GROUP object
+ *  \param  src  source EC_GROUP object
+ *  \return 1 on success and 0 if an error occurred.
+ */
+int EC_GROUP_copy(EC_GROUP *dst, const EC_GROUP *src);
+
+/** Creates a new EC_GROUP object and copies the copies the content
+ *  form src to the newly created EC_KEY object
+ *  \param  src  source EC_GROUP object
+ *  \return newly created EC_GROUP object or NULL in case of an error.
+ */
+EC_GROUP *EC_GROUP_dup(const EC_GROUP *src);
+
+/** Returns the EC_METHOD of the EC_GROUP object.
+ *  \param  group  EC_GROUP object 
+ *  \return EC_METHOD used in this EC_GROUP object.
+ */
+const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group);
+
+/** Returns the field type of the EC_METHOD.
+ *  \param  meth  EC_METHOD object
+ *  \return NID of the underlying field type OID.
+ */
+int EC_METHOD_get_field_type(const EC_METHOD *meth);
+
+/** Sets the generator and it's order/cofactor of a EC_GROUP object.
+ *  \param  group      EC_GROUP object 
+ *  \param  generator  EC_POINT object with the generator.
+ *  \param  order      the order of the group generated by the generator.
+ *  \param  cofactor   the index of the sub-group generated by the generator
+ *                     in the group of all points on the elliptic curve.
+ *  \return 1 on success and 0 if an error occured
+ */
+int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor);
+
+/** Returns the generator of a EC_GROUP object.
+ *  \param  group  EC_GROUP object
+ *  \return the currently used generator (possibly NULL).
+ */
+const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group);
+
+/** Gets the order of a EC_GROUP
+ *  \param  group  EC_GROUP object
+ *  \param  order  BIGNUM to which the order is copied
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return 1 on success and 0 if an error occured
+ */
+int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx);
+
+/** Gets the cofactor of a EC_GROUP
+ *  \param  group     EC_GROUP object
+ *  \param  cofactor  BIGNUM to which the cofactor is copied
+ *  \param  ctx       BN_CTX object (optional)
+ *  \return 1 on success and 0 if an error occured
+ */
+int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx);
+
+/** Sets the name of a EC_GROUP object
+ *  \param  group  EC_GROUP object
+ *  \param  nid    NID of the curve name OID
+ */
+void EC_GROUP_set_curve_name(EC_GROUP *group, int nid);
+
+/** Returns the curve name of a EC_GROUP object
+ *  \param  group  EC_GROUP object
+ *  \return NID of the curve name OID or 0 if not set.
+ */
+int EC_GROUP_get_curve_name(const EC_GROUP *group);
+
+void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag);
+int EC_GROUP_get_asn1_flag(const EC_GROUP *group);
 
 void EC_GROUP_set_point_conversion_form(EC_GROUP *, point_conversion_form_t);
 point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *);
@@ -160,36 +262,114 @@ unsigned char *EC_GROUP_get0_seed(const EC_GROUP *);
 size_t EC_GROUP_get_seed_len(const EC_GROUP *);
 size_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len);
 
-int EC_GROUP_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
-int EC_GROUP_get_curve_GFp(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
-int EC_GROUP_set_curve_GF2m(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
-int EC_GROUP_get_curve_GF2m(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
+/** Sets the parameter of a ec over GFp defined by y^2 = x^3 + a*x + b
+ *  \param  group  EC_GROUP object
+ *  \param  p      BIGNUM with the prime number
+ *  \param  a      BIGNUM with parameter a of the equation
+ *  \param  b      BIGNUM with parameter b of the equation
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return 1 on success and 0 if an error occured
+ */
+int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
+
+/** Gets the parameter of the ec over GFp defined by y^2 = x^3 + a*x + b
+ *  \param  group  EC_GROUP object
+ *  \param  p      BIGNUM for the prime number
+ *  \param  a      BIGNUM for parameter a of the equation
+ *  \param  b      BIGNUM for parameter b of the equation
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return 1 on success and 0 if an error occured
+ */
+int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
+
+/** Sets the parameter of a ec over GF2m defined by y^2 + x*y = x^3 + a*x^2 + b
+ *  \param  group  EC_GROUP object
+ *  \param  p      BIGNUM with the polynomial defining the underlying field
+ *  \param  a      BIGNUM with parameter a of the equation
+ *  \param  b      BIGNUM with parameter b of the equation
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return 1 on success and 0 if an error occured
+ */
+int EC_GROUP_set_curve_GF2m(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
+
+/** Gets the parameter of the ec over GF2m defined by y^2 + x*y = x^3 + a*x^2 + b
+ *  \param  group  EC_GROUP object
+ *  \param  p      BIGNUM for the polynomial defining the underlying field
+ *  \param  a      BIGNUM for parameter a of the equation
+ *  \param  b      BIGNUM for parameter b of the equation
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return 1 on success and 0 if an error occured
+ */
+int EC_GROUP_get_curve_GF2m(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
 
-/* returns the number of bits needed to represent a field element */
-int EC_GROUP_get_degree(const EC_GROUP *);
+/** Returns the number of bits needed to represent a field element 
+ *  \param  group  EC_GROUP object
+ *  \return number of bits needed to represent a field element
+ */
+int EC_GROUP_get_degree(const EC_GROUP *group);
 
-/* EC_GROUP_check() returns 1 if 'group' defines a valid group, 0 otherwise */
+/** Checks whether the parameter in the EC_GROUP define a valid ec group
+ *  \param  group  EC_GROUP object
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return 1 if group is a valid ec group and 0 otherwise
+ */
 int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx);
-/* EC_GROUP_check_discriminant() returns 1 if the discriminant of the
- * elliptic curve is not zero, 0 otherwise */
-int EC_GROUP_check_discriminant(const EC_GROUP *, BN_CTX *);
 
-/* EC_GROUP_cmp() returns 0 if both groups are equal and 1 otherwise */
-int EC_GROUP_cmp(const EC_GROUP *, const EC_GROUP *, BN_CTX *);
+/** Checks whether the discriminant of the elliptic curve is zero or not
+ *  \param  group  EC_GROUP object
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return 1 if the discriminant is not zero and 0 otherwise
+ */
+int EC_GROUP_check_discriminant(const EC_GROUP *group, BN_CTX *ctx);
+
+/** Compares two EC_GROUP objects
+ *  \param  a    first EC_GROUP object
+ *  \param  b    second EC_GROUP object
+ *  \param  ctx  BN_CTX object (optional)
+ *  \return 0 if both groups are equal and 1 otherwise
+ */
+int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx);
 
 /* EC_GROUP_new_GF*() calls EC_GROUP_new() and EC_GROUP_set_GF*()
  * after choosing an appropriate EC_METHOD */
-EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
-EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
 
-/* EC_GROUP_new_by_curve_name() creates a EC_GROUP structure
- * specified by a curve name (in form of a NID) */
+/** Creates a new EC_GROUP object with the specified parameters defined
+ *  over GFp (defined by the equation y^2 = x^3 + a*x + b)
+ *  \param  p    BIGNUM with the prime number
+ *  \param  a    BIGNUM with the parameter a of the equation
+ *  \param  b    BIGNUM with the parameter b of the equation
+ *  \param  ctx  BN_CTX object (optional)
+ *  \return newly created EC_GROUP object with the specified parameters
+ */
+EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
+
+/** Creates a new EC_GROUP object with the specified parameters defined
+ *  over GF2m (defined by the equation y^2 + x*y = x^3 + a*x^2 + b)
+ *  \param  p    BIGNUM with the polynomial defining the underlying field
+ *  \param  a    BIGNUM with the parameter a of the equation
+ *  \param  b    BIGNUM with the parameter b of the equation
+ *  \param  ctx  BN_CTX object (optional)
+ *  \return newly created EC_GROUP object with the specified parameters
+ */
+EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
+
+/** Creates a EC_GROUP object with a curve specified by a NID
+ *  \param  nid  NID of the OID of the curve name
+ *  \return newly created EC_GROUP object with specified curve or NULL
+ *          if an error occurred
+ */
 EC_GROUP *EC_GROUP_new_by_curve_name(int nid);
-/* handling of internal curves */
+
+
+/********************************************************************/
+/*               handling of internal curves                        */
+/********************************************************************/
+
 typedef struct { 
        int nid;
        const char *comment;
        } EC_builtin_curve;
+
 /* EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number 
  * of all available curves or zero if a error occurred. 
  * In case r ist not zero nitems EC_builtin_curve structures 
@@ -197,39 +377,168 @@ typedef struct {
 size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems);
 
 
-/* EC_POINT functions */
+/********************************************************************/
+/*                    EC_POINT functions                            */
+/********************************************************************/
+
+/** Creates a new EC_POINT object for the specified EC_GROUP
+ *  \param  group  EC_GROUP the underlying EC_GROUP object
+ *  \return newly created EC_POINT object or NULL if an error occurred
+ */
+EC_POINT *EC_POINT_new(const EC_GROUP *group);
+
+/** Frees a EC_POINT object
+ *  \param  point  EC_POINT object to be freed
+ */
+void EC_POINT_free(EC_POINT *point);
+
+/** Clears and frees a EC_POINT object
+ *  \param  point  EC_POINT object to be cleared and freed
+ */
+void EC_POINT_clear_free(EC_POINT *point);
+
+/** Copies EC_POINT object
+ *  \param  dst  destination EC_POINT object
+ *  \param  src  source EC_POINT object
+ *  \return 1 on success and 0 if an error occured
+ */
+int EC_POINT_copy(EC_POINT *dst, const EC_POINT *src);
 
-EC_POINT *EC_POINT_new(const EC_GROUP *);
-void EC_POINT_free(EC_POINT *);
-void EC_POINT_clear_free(EC_POINT *);
-int EC_POINT_copy(EC_POINT *, const EC_POINT *);
-EC_POINT *EC_POINT_dup(const EC_POINT *, const EC_GROUP *);
+/** Creates a new EC_POINT object and copies the content of the supplied
+ *  EC_POINT
+ *  \param  src    source EC_POINT object
+ *  \param  group  underlying the EC_GROUP object
+ *  \return newly created EC_POINT object or NULL if an error occurred 
+ */
+EC_POINT *EC_POINT_dup(const EC_POINT *src, const EC_GROUP *group);
  
-const EC_METHOD *EC_POINT_method_of(const EC_POINT *);
-
-int EC_POINT_set_to_infinity(const EC_GROUP *, EC_POINT *);
-int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *, EC_POINT *,
-       const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *);
-int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
-       BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *);
-int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *, EC_POINT *,
-       const BIGNUM *x, const BIGNUM *y, BN_CTX *);
-int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
-       BIGNUM *x, BIGNUM *y, BN_CTX *);
-int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *, EC_POINT *,
-       const BIGNUM *x, int y_bit, BN_CTX *);
-
-int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *, EC_POINT *,
-       const BIGNUM *x, const BIGNUM *y, BN_CTX *);
-int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *, const EC_POINT *,
-       BIGNUM *x, BIGNUM *y, BN_CTX *);
-int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *, EC_POINT *,
-       const BIGNUM *x, int y_bit, BN_CTX *);
-
-size_t EC_POINT_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form,
-        unsigned char *buf, size_t len, BN_CTX *);
-int EC_POINT_oct2point(const EC_GROUP *, EC_POINT *,
-        const unsigned char *buf, size_t len, BN_CTX *);
+/** Returns the EC_METHOD used in EC_POINT object 
+ *  \param  point  EC_POINT object
+ *  \return the EC_METHOD used
+ */
+const EC_METHOD *EC_POINT_method_of(const EC_POINT *point);
+
+/** Sets a point to infinity (neutral element)
+ *  \param  group  underlying EC_GROUP object
+ *  \param  point  EC_POINT to set to infinity
+ *  \return 1 on success and 0 if an error occured
+ */
+int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point);
+
+/** Sets the jacobian projective coordinates of a EC_POINT over GFp
+ *  \param  group  underlying EC_GROUP object
+ *  \param  p      EC_POINT object
+ *  \param  x      BIGNUM with the x-coordinate
+ *  \param  y      BIGNUM with the y-coordinate
+ *  \param  z      BIGNUM with the z-coordinate
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return 1 on success and 0 if an error occured
+ */
+int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group, EC_POINT *p,
+       const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx);
+
+/** Gets the jacobian projective coordinates of a EC_POINT over GFp
+ *  \param  group  underlying EC_GROUP object
+ *  \param  p      EC_POINT object
+ *  \param  x      BIGNUM for the x-coordinate
+ *  \param  y      BIGNUM for the y-coordinate
+ *  \param  z      BIGNUM for the z-coordinate
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return 1 on success and 0 if an error occured
+ */
+int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group,
+       const EC_POINT *p, BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx);
+
+/** Sets the affine coordinates of a EC_POINT over GFp
+ *  \param  group  underlying EC_GROUP object
+ *  \param  p      EC_POINT object
+ *  \param  x      BIGNUM with the x-coordinate
+ *  \param  y      BIGNUM with the y-coordinate
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return 1 on success and 0 if an error occured
+ */
+int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *p,
+       const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx);
+
+/** Gets the affine coordinates of a EC_POINT over GFp
+ *  \param  group  underlying EC_GROUP object
+ *  \param  p      EC_POINT object
+ *  \param  x      BIGNUM for the x-coordinate
+ *  \param  y      BIGNUM for the y-coordinate
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return 1 on success and 0 if an error occured
+ */
+int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group,
+       const EC_POINT *p, BIGNUM *x, BIGNUM *y, BN_CTX *ctx);
+
+/** Sets the x9.62 compressed coordinates of a EC_POINT over GFp
+ *  \param  group  underlying EC_GROUP object
+ *  \param  p      EC_POINT object
+ *  \param  x      BIGNUM with x-coordinate
+ *  \param  y_bit  integer with the y-Bit (either 0 or 1)
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return 1 on success and 0 if an error occured
+ */
+int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *p,
+       const BIGNUM *x, int y_bit, BN_CTX *ctx);
+
+/** Sets the affine coordinates of a EC_POINT over GF2m
+ *  \param  group  underlying EC_GROUP object
+ *  \param  p      EC_POINT object
+ *  \param  x      BIGNUM with the x-coordinate
+ *  \param  y      BIGNUM with the y-coordinate
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return 1 on success and 0 if an error occured
+ */
+int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *group, EC_POINT *p,
+       const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx);
+
+/** Gets the affine coordinates of a EC_POINT over GF2m
+ *  \param  group  underlying EC_GROUP object
+ *  \param  p      EC_POINT object
+ *  \param  x      BIGNUM for the x-coordinate
+ *  \param  y      BIGNUM for the y-coordinate
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return 1 on success and 0 if an error occured
+ */
+int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *group,
+       const EC_POINT *p, BIGNUM *x, BIGNUM *y, BN_CTX *ctx);
+
+/** Sets the x9.62 compressed coordinates of a EC_POINT over GF2m
+ *  \param  group  underlying EC_GROUP object
+ *  \param  p      EC_POINT object
+ *  \param  x      BIGNUM with x-coordinate
+ *  \param  y_bit  integer with the y-Bit (either 0 or 1)
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return 1 on success and 0 if an error occured
+ */
+int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group, EC_POINT *p,
+       const BIGNUM *x, int y_bit, BN_CTX *ctx);
+
+/** Encodes a EC_POINT object to a octet string
+ *  \param  group  underlying EC_GROUP object
+ *  \param  p      EC_POINT object
+ *  \param  form   point conversion form
+ *  \param  buf    memory buffer for the result. If NULL the function returns
+ *                 required buffer size.
+ *  \param  len    length of the memory buffer
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return the length of the encoded octet string or 0 if an error occurred
+ */
+size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *p,
+       point_conversion_form_t form,
+        unsigned char *buf, size_t len, BN_CTX *ctx);
+
+/** Decodes a EC_POINT from a octet string
+ *  \param  group  underlying EC_GROUP object
+ *  \param  p      EC_POINT object
+ *  \param  buf    memory buffer with the encoded ec point
+ *  \param  len    length of the encoded ec point
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return 1 on success and 0 if an error occured
+ */
+int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *p,
+        const unsigned char *buf, size_t len, BN_CTX *ctx);
 
 /* other interfaces to point2oct/oct2point: */
 BIGNUM *EC_POINT_point2bn(const EC_GROUP *, const EC_POINT *,
@@ -241,29 +550,105 @@ char *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *,
 EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *,
        EC_POINT *, BN_CTX *);
 
-int EC_POINT_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
-int EC_POINT_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
-int EC_POINT_invert(const EC_GROUP *, EC_POINT *, BN_CTX *);
 
-int EC_POINT_is_at_infinity(const EC_GROUP *, const EC_POINT *);
-int EC_POINT_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *);
-int EC_POINT_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
+/********************************************************************/
+/*         functions for doing EC_POINT arithmetic                  */
+/********************************************************************/
+
+/** Computes the sum of two EC_POINT 
+ *  \param  group  underlying EC_GROUP object
+ *  \param  r      EC_POINT object for the result (r = a + b)
+ *  \param  a      EC_POINT object with the first summand
+ *  \param  b      EC_POINT object with the second summand
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return 1 on success and 0 if an error occured
+ */
+int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx);
+
+/** Computes the double of a EC_POINT
+ *  \param  group  underlying EC_GROUP object
+ *  \param  r      EC_POINT object for the result (r = 2 * a)
+ *  \param  a      EC_POINT object 
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return 1 on success and 0 if an error occured
+ */
+int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx);
+
+/** Computes the inverse of a EC_POINT
+ *  \param  group  underlying EC_GROUP object
+ *  \param  a      EC_POINT object to be inverted (it's used for the result as well)
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return 1 on success and 0 if an error occured
+ */
+int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx);
+
+/** Checks whether the point is the neutral element of the group
+ *  \param  group  the underlying EC_GROUP object
+ *  \param  p      EC_POINT object
+ *  \return 1 if the point is the neutral element and 0 otherwise
+ */
+int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *p);
+
+/** Checks whether the point is on the curve 
+ *  \param  group  underlying EC_GROUP object
+ *  \param  point  EC_POINT object to check
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return 1 if point if on the curve and 0 otherwise
+ */
+int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx);
+
+/** Compares two EC_POINTs 
+ *  \param  group  underlying EC_GROUP object
+ *  \param  a      first EC_POINT object
+ *  \param  b      second EC_POINT object
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return 0 if both points are equal and a value != 0 otherwise
+ */
+int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx);
 
 int EC_POINT_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *);
 int EC_POINTs_make_affine(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *);
 
+/** Computes r = generator * n sum_{i=0}^num p[i] * m[i]
+ *  \param  group  underlying EC_GROUP object
+ *  \param  r      EC_POINT object for the result
+ *  \param  n      BIGNUM with the multiplier for the group generator (optional)
+ *  \param  num    number futher summands
+ *  \param  p      array of size num of EC_POINT objects
+ *  \param  m      array of size num of BIGNUM objects
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return 1 on success and 0 if an error occured
+ */
+int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, size_t num, const EC_POINT *p[], const BIGNUM *m[], BN_CTX *ctx);
+
+/** Computes r = generator * n + q * m
+ *  \param  group  underlying EC_GROUP object
+ *  \param  r      EC_POINT object for the result
+ *  \param  n      BIGNUM with the multiplier for the group generator (optional)
+ *  \param  q      EC_POINT object with the first factor of the second summand
+ *  \param  m      BIGNUM with the second factor of the second summand
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return 1 on success and 0 if an error occured
+ */
+int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, const EC_POINT *q, const BIGNUM *m, BN_CTX *ctx);
 
-int EC_POINTs_mul(const EC_GROUP *, EC_POINT *r, const BIGNUM *, size_t num, const EC_POINT *[], const BIGNUM *[], BN_CTX *);
-int EC_POINT_mul(const EC_GROUP *, EC_POINT *r, const BIGNUM *, const EC_POINT *, const BIGNUM *, BN_CTX *);
-
-/* EC_GROUP_precompute_mult() stores multiples of generator for faster point multiplication */
-int EC_GROUP_precompute_mult(EC_GROUP *, BN_CTX *);
-/* EC_GROUP_have_precompute_mult() reports whether such precomputation has been done */
-int EC_GROUP_have_precompute_mult(const EC_GROUP *);
+/** Stores multiples of generator for faster point multiplication
+ *  \param  group  EC_GROUP object
+ *  \param  ctx    BN_CTX object (optional)
+ *  \return 1 on success and 0 if an error occured
+ */
+int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx);
 
+/** Reports whether a precomputation has been done
+ *  \param  group  EC_GROUP object
+ *  \return 1 if a pre-computation has been done and 0 otherwise
+ */
+int EC_GROUP_have_precompute_mult(const EC_GROUP *group);
 
 
-/* ASN1 stuff */
+/********************************************************************/
+/*                       ASN1 stuff                                 */
+/********************************************************************/
 
 /* EC_GROUP_get_basis_type() returns the NID of the basis type
  * used to represent the field elements */
@@ -293,28 +678,96 @@ int     ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off);
 int     ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off);
 #endif
 
-/* the EC_KEY stuff */
+
+/********************************************************************/
+/*                      EC_KEY functions                            */
+/********************************************************************/
+
 typedef struct ec_key_st EC_KEY;
 
 /* some values for the encoding_flag */
 #define EC_PKEY_NO_PARAMETERS  0x001
 #define EC_PKEY_NO_PUBKEY      0x002
 
+/** Creates a new EC_KEY object.
+ *  \return EC_KEY object or NULL if an error occurred.
+ */
 EC_KEY *EC_KEY_new(void);
+
+/** Creates a new EC_KEY object using a named curve as underlying
+ *  EC_GROUP object.
+ *  \param  nid  NID of the named curve.
+ *  \return EC_KEY object or NULL if an error occurred. 
+ */
 EC_KEY *EC_KEY_new_by_curve_name(int nid);
-void EC_KEY_free(EC_KEY *);
-EC_KEY *EC_KEY_copy(EC_KEY *, const EC_KEY *);
-EC_KEY *EC_KEY_dup(const EC_KEY *);
-
-int EC_KEY_up_ref(EC_KEY *);
-
-const EC_GROUP *EC_KEY_get0_group(const EC_KEY *);
-int EC_KEY_set_group(EC_KEY *, const EC_GROUP *);
-const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *);
-int EC_KEY_set_private_key(EC_KEY *, const BIGNUM *);
-const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *);
-int EC_KEY_set_public_key(EC_KEY *, const EC_POINT *);
-unsigned EC_KEY_get_enc_flags(const EC_KEY *);
+
+/** Frees a EC_KEY object.
+ *  \param  key  EC_KEY object to be freed.
+ */
+void EC_KEY_free(EC_KEY *key);
+
+/** Copies a EC_KEY object.
+ *  \param  dst  destination EC_KEY object
+ *  \param  src  src EC_KEY object
+ *  \return dst or NULL if an error occurred.
+ */
+EC_KEY *EC_KEY_copy(EC_KEY *dst, const EC_KEY *src);
+
+/** Creates a new EC_KEY object and copies the content from src to it.
+ *  \param  src  the source EC_KEY object
+ *  \return newly created EC_KEY object or NULL if an error occurred.
+ */
+EC_KEY *EC_KEY_dup(const EC_KEY *src);
+
+/** Increases the internal reference count of a EC_KEY object.
+ *  \param  key  EC_KEY object
+ *  \return 1 on success and 0 if an error occurred.
+ */
+int EC_KEY_up_ref(EC_KEY *key);
+
+/** Returns the EC_GROUP object of a EC_KEY object
+ *  \param  key  EC_KEY object
+ *  \return the EC_GROUP object (possibly NULL).
+ */
+const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key);
+
+/** Sets the EC_GROUP of a EC_KEY object.
+ *  \param  key    EC_KEY object
+ *  \param  group  EC_GROUP to use in the EC_KEY object (note: the EC_KEY
+ *                 object will use an own copy of the EC_GROUP).
+ *  \return 1 on success and 0 if an error occurred.
+ */
+int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group);
+
+/** Returns the private key of a EC_KEY object.
+ *  \param  key  EC_KEY object
+ *  \return a BIGNUM with the private key (possibly NULL).
+ */
+const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key);
+
+/** Sets the private key of a EC_KEY object.
+ *  \param  key  EC_KEY object
+ *  \param  prv  BIGNUM with the private key (note: the EC_KEY object
+ *               will use an own copy of the BIGNUM).
+ *  \return 1 on success and 0 if an error occurred.
+ */
+int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *prv);
+
+/** Returns the public key of a EC_KEY object.
+ *  \param  key  the EC_KEY object
+ *  \return a EC_POINT object with the public key (possibly NULL)
+ */
+const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key);
+
+/** Sets the public key of a EC_KEY object.
+ *  \param  key  EC_KEY object
+ *  \param  pub  EC_POINT object with the public key (note: the EC_KEY object
+ *               will use an own copy of the EC_POINT object).
+ *  \return 1 on success and 0 if an error occurred.
+ */
+int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub);
+
+unsigned EC_KEY_get_enc_flags(const EC_KEY *key);
 void EC_KEY_set_enc_flags(EC_KEY *, unsigned int);
 point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *);
 void EC_KEY_set_conv_form(EC_KEY *, point_conversion_form_t);
@@ -325,31 +778,126 @@ void EC_KEY_insert_key_method_data(EC_KEY *, void *data,
        void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *));
 /* wrapper functions for the underlying EC_GROUP object */
 void EC_KEY_set_asn1_flag(EC_KEY *, int);
-int EC_KEY_precompute_mult(EC_KEY *, BN_CTX *ctx);
-
-/* EC_KEY_generate_key() creates a ec private (public) key */
-int EC_KEY_generate_key(EC_KEY *);
-/* EC_KEY_check_key() */
-int EC_KEY_check_key(const EC_KEY *);
-
-/* de- and encoding functions for SEC1 ECPrivateKey */
-EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len);
-int i2d_ECPrivateKey(EC_KEY *a, unsigned char **out);
-/* de- and encoding functions for EC parameters */
-EC_KEY *d2i_ECParameters(EC_KEY **a, const unsigned char **in, long len);
-int i2d_ECParameters(EC_KEY *a, unsigned char **out);
-/* de- and encoding functions for EC public key
- * (octet string, not DER -- hence 'o2i' and 'i2o') */
-EC_KEY *o2i_ECPublicKey(EC_KEY **a, const unsigned char **in, long len);
-int i2o_ECPublicKey(EC_KEY *a, unsigned char **out);
+
+/** Creates a table of pre-computed multiples of the generator to 
+ *  accelerate further EC_KEY operations.
+ *  \param  key  EC_KEY object
+ *  \param  ctx  BN_CTX object (optional)
+ *  \return 1 on success and 0 if an error occurred.
+ */
+int EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx);
+
+/** Creates a new ec private (and optional a new public) key.
+ *  \param  key  EC_KEY object
+ *  \return 1 on success and 0 if an error occurred.
+ */
+int EC_KEY_generate_key(EC_KEY *key);
+
+/** Verifies that a private and/or public key is valid.
+ *  \param  key  the EC_KEY object
+ *  \return 1 on success and 0 otherwise.
+ */
+int EC_KEY_check_key(const EC_KEY *key);
+
+
+/********************************************************************/
+/*        de- and encoding functions for SEC1 ECPrivateKey          */
+/********************************************************************/
+
+/** Decodes a private key from a memory buffer.
+ *  \param  key  a pointer to a EC_KEY object which should be used (or NULL)
+ *  \param  in   pointer to memory with the DER encoded private key
+ *  \param  len  length of the DER encoded private key
+ *  \return the decoded private key or NULL if an error occurred.
+ */
+EC_KEY *d2i_ECPrivateKey(EC_KEY **key, const unsigned char **in, long len);
+
+/** Encodes a private key object and stores the result in a buffer.
+ *  \param  key  the EC_KEY object to encode
+ *  \param  out  the buffer for the result (if NULL the function returns number
+ *               of bytes needed).
+ *  \return 1 on success and 0 if an error occurred.
+ */
+int i2d_ECPrivateKey(EC_KEY *key, unsigned char **out);
+
+
+/********************************************************************/
+/*        de- and encoding functions for EC parameters              */
+/********************************************************************/
+
+/** Decodes ec parameter from a memory buffer.
+ *  \param  key  a pointer to a EC_KEY object which should be used (or NULL)
+ *  \param  in   pointer to memory with the DER encoded ec parameters
+ *  \param  len  length of the DER encoded ec parameters
+ *  \return a EC_KEY object with the decoded parameters or NULL if an error
+ *          occurred.
+ */
+EC_KEY *d2i_ECParameters(EC_KEY **key, const unsigned char **in, long len);
+
+/** Encodes ec parameter and stores the result in a buffer.
+ *  \param  key  the EC_KEY object with ec paramters to encode
+ *  \param  out  the buffer for the result (if NULL the function returns number
+ *               of bytes needed).
+ *  \return 1 on success and 0 if an error occurred.
+ */
+int i2d_ECParameters(EC_KEY *key, unsigned char **out);
+
+
+/********************************************************************/
+/*         de- and encoding functions for EC public key             */
+/*         (octet string, not DER -- hence 'o2i' and 'i2o')         */
+/********************************************************************/
+
+/** Decodes a ec public key from a octet string.
+ *  \param  key  a pointer to a EC_KEY object which should be used
+ *  \param  in   memory buffer with the encoded public key
+ *  \param  len  length of the encoded public key
+ *  \return EC_KEY object with decoded public key or NULL if an error
+ *          occurred.
+ */
+EC_KEY *o2i_ECPublicKey(EC_KEY **key, const unsigned char **in, long len);
+
+/** Encodes a ec public key in an octet string.
+ *  \param  key  the EC_KEY object with the public key
+ *  \param  out  the buffer for the result (if NULL the function returns number
+ *               of bytes needed).
+ *  \return 1 on success and 0 if an error occurred
+ */
+int i2o_ECPublicKey(EC_KEY *key, unsigned char **out);
 
 #ifndef OPENSSL_NO_BIO
-int    ECParameters_print(BIO *bp, const EC_KEY *x);
-int    EC_KEY_print(BIO *bp, const EC_KEY *x, int off);
+/** Prints out the ec parameters on human readable form.
+ *  \param  bp   BIO object to which the information is printed
+ *  \param  key  EC_KEY object
+ *  \return 1 on success and 0 if an error occurred
+ */
+int    ECParameters_print(BIO *bp, const EC_KEY *key);
+
+/** Prints out the contents of a EC_KEY object
+ *  \param  bp   BIO object to which the information is printed
+ *  \param  key  EC_KEY object
+ *  \param  off  line offset 
+ *  \return 1 on success and 0 if an error occurred
+ */
+int    EC_KEY_print(BIO *bp, const EC_KEY *key, int off);
+
 #endif
 #ifndef OPENSSL_NO_FP_API
-int    ECParameters_print_fp(FILE *fp, const EC_KEY *x);
-int    EC_KEY_print_fp(FILE *fp, const EC_KEY *x, int off);
+/** Prints out the ec parameters on human readable form.
+ *  \param  fp   file descriptor to which the information is printed
+ *  \param  key  EC_KEY object
+ *  \return 1 on success and 0 if an error occurred
+ */
+int    ECParameters_print_fp(FILE *fp, const EC_KEY *key);
+
+/** Prints out the contents of a EC_KEY object
+ *  \param  fp   file descriptor to which the information is printed
+ *  \param  key  EC_KEY object
+ *  \param  off  line offset 
+ *  \return 1 on success and 0 if an error occurred
+ */
+int    EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off);
+
 #endif
 
 #define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x)
@@ -362,6 +910,13 @@ int        EC_KEY_print_fp(FILE *fp, const EC_KEY *x, int off);
 # endif
 #endif
 
+#define EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid) \
+       EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, EVP_PKEY_OP_PARAMGEN, \
+                               EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID, nid, NULL)
+
+
+#define EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID            (EVP_PKEY_ALG_CTRL + 1)
+
 /* BEGIN ERROR CODES */
 /* The following lines are auto generated by the script mkerr.pl. Any changes
  * made after this point may be overwritten when the script is next run.
@@ -375,6 +930,14 @@ void ERR_load_EC_strings(void);
 #define EC_F_D2I_ECPARAMETERS                           144
 #define EC_F_D2I_ECPKPARAMETERS                                 145
 #define EC_F_D2I_ECPRIVATEKEY                           146
+#define EC_F_DO_EC_KEY_PRINT                            221
+#define EC_F_ECKEY_PARAM2TYPE                           223
+#define EC_F_ECKEY_PARAM_DECODE                                 212
+#define EC_F_ECKEY_PRIV_DECODE                          213
+#define EC_F_ECKEY_PRIV_ENCODE                          214
+#define EC_F_ECKEY_PUB_DECODE                           215
+#define EC_F_ECKEY_PUB_ENCODE                           216
+#define EC_F_ECKEY_TYPE2PARAM                           220
 #define EC_F_ECPARAMETERS_PRINT                                 147
 #define EC_F_ECPARAMETERS_PRINT_FP                      148
 #define EC_F_ECPKPARAMETERS_PRINT                       149
@@ -448,7 +1011,6 @@ void ERR_load_EC_strings(void);
 #define EC_F_EC_KEY_PRINT                               180
 #define EC_F_EC_KEY_PRINT_FP                            181
 #define EC_F_EC_POINTS_MAKE_AFFINE                      136
-#define EC_F_EC_POINTS_MUL                              138
 #define EC_F_EC_POINT_ADD                               112
 #define EC_F_EC_POINT_CMP                               113
 #define EC_F_EC_POINT_COPY                              114
@@ -479,21 +1041,31 @@ void ERR_load_EC_strings(void);
 #define EC_F_I2D_ECPRIVATEKEY                           192
 #define EC_F_I2O_ECPUBLICKEY                            151
 #define EC_F_O2I_ECPUBLICKEY                            152
+#define EC_F_OLD_EC_PRIV_DECODE                                 222
+#define EC_F_PKEY_EC_CTRL                               197
+#define EC_F_PKEY_EC_CTRL_STR                           198
+#define EC_F_PKEY_EC_DERIVE                             217
+#define EC_F_PKEY_EC_KEYGEN                             199
+#define EC_F_PKEY_EC_PARAMGEN                           219
+#define EC_F_PKEY_EC_SIGN                               218
 
 /* Reason codes. */
 #define EC_R_ASN1_ERROR                                         115
 #define EC_R_ASN1_UNKNOWN_FIELD                                 116
 #define EC_R_BUFFER_TOO_SMALL                           100
 #define EC_R_D2I_ECPKPARAMETERS_FAILURE                         117
+#define EC_R_DECODE_ERROR                               142
 #define EC_R_DISCRIMINANT_IS_ZERO                       118
 #define EC_R_EC_GROUP_NEW_BY_NAME_FAILURE               119
-#define EC_R_FIELD_TOO_LARGE                            138
+#define EC_R_FIELD_TOO_LARGE                            143
 #define EC_R_GROUP2PKPARAMETERS_FAILURE                         120
 #define EC_R_I2D_ECPKPARAMETERS_FAILURE                         121
 #define EC_R_INCOMPATIBLE_OBJECTS                       101
 #define EC_R_INVALID_ARGUMENT                           112
 #define EC_R_INVALID_COMPRESSED_POINT                   110
 #define EC_R_INVALID_COMPRESSION_BIT                    109
+#define EC_R_INVALID_CURVE                              141
+#define EC_R_INVALID_DIGEST_TYPE                        138
 #define EC_R_INVALID_ENCODING                           102
 #define EC_R_INVALID_FIELD                              103
 #define EC_R_INVALID_FORM                               104
@@ -501,6 +1073,7 @@ void ERR_load_EC_strings(void);
 #define EC_R_INVALID_PENTANOMIAL_BASIS                  132
 #define EC_R_INVALID_PRIVATE_KEY                        123
 #define EC_R_INVALID_TRINOMIAL_BASIS                    137
+#define EC_R_KEYS_NOT_SET                               140
 #define EC_R_MISSING_PARAMETERS                                 124
 #define EC_R_MISSING_PRIVATE_KEY                        125
 #define EC_R_NOT_A_NIST_PRIME                           135
@@ -508,6 +1081,7 @@ void ERR_load_EC_strings(void);
 #define EC_R_NOT_IMPLEMENTED                            126
 #define EC_R_NOT_INITIALIZED                            111
 #define EC_R_NO_FIELD_MOD                               133
+#define EC_R_NO_PARAMETERS_SET                          139
 #define EC_R_PASSED_NULL_PARAMETER                      134
 #define EC_R_PKPARAMETERS2GROUP_FAILURE                         127
 #define EC_R_POINT_AT_INFINITY                          106
index 7dca5e4..e12b9b2 100644 (file)
@@ -76,7 +76,7 @@
  * coordinates.
  * Uses algorithm Mdouble in appendix of 
  *     Lopez, J. and Dahab, R.  "Fast multiplication on elliptic curves over 
- *     GF(2^m) without precomputation".
+ *     GF(2^m) without precomputation" (CHES '99, LNCS 1717).
  * modified to not require precomputation of c=b^{2^{m-1}}.
  */
 static int gf2m_Mdouble(const EC_GROUP *group, BIGNUM *x, BIGNUM *z, BN_CTX *ctx)
@@ -107,8 +107,8 @@ static int gf2m_Mdouble(const EC_GROUP *group, BIGNUM *x, BIGNUM *z, BN_CTX *ctx
 /* Compute the x-coordinate x1/z1 for the point (x1/z1)+(x2/x2) in Montgomery 
  * projective coordinates.
  * Uses algorithm Madd in appendix of 
- *     Lopex, J. and Dahab, R.  "Fast multiplication on elliptic curves over 
- *     GF(2^m) without precomputation".
+ *     Lopez, J. and Dahab, R.  "Fast multiplication on elliptic curves over 
+ *     GF(2^m) without precomputation" (CHES '99, LNCS 1717).
  */
 static int gf2m_Madd(const EC_GROUP *group, const BIGNUM *x, BIGNUM *x1, BIGNUM *z1, 
        const BIGNUM *x2, const BIGNUM *z2, BN_CTX *ctx)
@@ -140,8 +140,8 @@ static int gf2m_Madd(const EC_GROUP *group, const BIGNUM *x, BIGNUM *x1, BIGNUM
 
 /* Compute the x, y affine coordinates from the point (x1, z1) (x2, z2) 
  * using Montgomery point multiplication algorithm Mxy() in appendix of 
- *     Lopex, J. and Dahab, R.  "Fast multiplication on elliptic curves over 
- *     GF(2^m) without precomputation".
+ *     Lopez, J. and Dahab, R.  "Fast multiplication on elliptic curves over 
+ *     GF(2^m) without precomputation" (CHES '99, LNCS 1717).
  * Returns:
  *     0 on error
  *     1 if return value should be the point at infinity
@@ -209,15 +209,15 @@ static int gf2m_Mxy(const EC_GROUP *group, const BIGNUM *x, const BIGNUM *y, BIG
 /* Computes scalar*point and stores the result in r.
  * point can not equal r.
  * Uses algorithm 2P of
- *     Lopex, J. and Dahab, R.  "Fast multiplication on elliptic curves over 
- *     GF(2^m) without precomputation".
+ *     Lopez, J. and Dahab, R.  "Fast multiplication on elliptic curves over 
+ *     GF(2^m) without precomputation" (CHES '99, LNCS 1717).
  */
 static int ec_GF2m_montgomery_point_multiply(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
        const EC_POINT *point, BN_CTX *ctx)
        {
        BIGNUM *x1, *x2, *z1, *z2;
-       int ret = 0, i, j;
-       BN_ULONG mask;
+       int ret = 0, i;
+       BN_ULONG mask,word;
 
        if (r == point)
                {
@@ -251,22 +251,24 @@ static int ec_GF2m_montgomery_point_multiply(const EC_GROUP *group, EC_POINT *r,
        if (!BN_GF2m_add(x2, x2, &group->b)) goto err; /* x2 = x^4 + b */
 
        /* find top most bit and go one past it */
-       i = scalar->top - 1; j = BN_BITS2 - 1;
+       i = scalar->top - 1;
        mask = BN_TBIT;
-       while (!(scalar->d[i] & mask)) { mask >>= 1; j--; }
-       mask >>= 1; j--;
+       word = scalar->d[i];
+       while (!(word & mask)) mask >>= 1;
+       mask >>= 1;
        /* if top most bit was at word break, go to next word */
        if (!mask) 
                {
-               i--; j = BN_BITS2 - 1;
+               i--;
                mask = BN_TBIT;
                }
 
        for (; i >= 0; i--)
                {
-               for (; j >= 0; j--)
+               word = scalar->d[i];
+               while (mask)
                        {
-                       if (scalar->d[i] & mask)
+                       if (word & mask)
                                {
                                if (!gf2m_Madd(group, &point->X, x1, z1, x2, z2, ctx)) goto err;
                                if (!gf2m_Mdouble(group, x2, z2, ctx)) goto err;
@@ -278,7 +280,6 @@ static int ec_GF2m_montgomery_point_multiply(const EC_GROUP *group, EC_POINT *r,
                                }
                        mask >>= 1;
                        }
-               j = BN_BITS2 - 1;
                mask = BN_TBIT;
                }
 
index 1aae199..03deae6 100644 (file)
@@ -14,7 +14,7 @@
  *
  */
 /* ====================================================================
- * Copyright (c) 1998-2003 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2005 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -157,6 +157,7 @@ void ec_GF2m_simple_group_clear_finish(EC_GROUP *group)
        group->poly[2] = 0;
        group->poly[3] = 0;
        group->poly[4] = 0;
+       group->poly[5] = -1;
        }
 
 
@@ -174,10 +175,9 @@ int ec_GF2m_simple_group_copy(EC_GROUP *dest, const EC_GROUP *src)
        dest->poly[2] = src->poly[2];
        dest->poly[3] = src->poly[3];
        dest->poly[4] = src->poly[4];
-       if(bn_wexpand(&dest->a, (int)(dest->poly[0] + BN_BITS2 - 1) / BN_BITS2) == NULL)
-               return 0;
-       if(bn_wexpand(&dest->b, (int)(dest->poly[0] + BN_BITS2 - 1) / BN_BITS2) == NULL)
-               return 0;
+       dest->poly[5] = src->poly[5];
+       if (bn_wexpand(&dest->a, (int)(dest->poly[0] + BN_BITS2 - 1) / BN_BITS2) == NULL) return 0;
+       if (bn_wexpand(&dest->b, (int)(dest->poly[0] + BN_BITS2 - 1) / BN_BITS2) == NULL) return 0;
        for (i = dest->a.top; i < dest->a.dmax; i++) dest->a.d[i] = 0;
        for (i = dest->b.top; i < dest->b.dmax; i++) dest->b.d[i] = 0;
        return 1;
@@ -192,7 +192,7 @@ int ec_GF2m_simple_group_set_curve(EC_GROUP *group,
 
        /* group->field */
        if (!BN_copy(&group->field, p)) goto err;
-       i = BN_GF2m_poly2arr(&group->field, group->poly, 5);
+       i = BN_GF2m_poly2arr(&group->field, group->poly, 6) - 1;
        if ((i != 5) && (i != 3))
                {
                ECerr(EC_F_EC_GF2M_SIMPLE_GROUP_SET_CURVE, EC_R_UNSUPPORTED_FIELD);
@@ -406,18 +406,94 @@ int ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *group, const EC_
        }
 
 
-/* Include patented algorithms. */
-#include "ec2_smpt.c"
+/* Calculates and sets the affine coordinates of an EC_POINT from the given
+ * compressed coordinates.  Uses algorithm 2.3.4 of SEC 1. 
+ * Note that the simple implementation only uses affine coordinates.
+ *
+ * The method is from the following publication:
+ * 
+ *     Harper, Menezes, Vanstone:
+ *     "Public-Key Cryptosystems with Very Small Key Lengths",
+ *     EUROCRYPT '92, Springer-Verlag LNCS 658,
+ *     published February 1993
+ *
+ * US Patents 6,141,420 and 6,618,483 (Vanstone, Mullin, Agnew) describe
+ * the same method, but claim no priority date earlier than July 29, 1994
+ * (and additionally fail to cite the EUROCRYPT '92 publication as prior art).
+ */
+int ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *point,
+       const BIGNUM *x_, int y_bit, BN_CTX *ctx)
+       {
+       BN_CTX *new_ctx = NULL;
+       BIGNUM *tmp, *x, *y, *z;
+       int ret = 0, z0;
+
+       /* clear error queue */
+       ERR_clear_error();
+
+       if (ctx == NULL)
+               {
+               ctx = new_ctx = BN_CTX_new();
+               if (ctx == NULL)
+                       return 0;
+               }
+
+       y_bit = (y_bit != 0) ? 1 : 0;
+
+       BN_CTX_start(ctx);
+       tmp = BN_CTX_get(ctx);
+       x = BN_CTX_get(ctx);
+       y = BN_CTX_get(ctx);
+       z = BN_CTX_get(ctx);
+       if (z == NULL) goto err;
+
+       if (!BN_GF2m_mod_arr(x, x_, group->poly)) goto err;
+       if (BN_is_zero(x))
+               {
+               if (!BN_GF2m_mod_sqrt_arr(y, &group->b, group->poly, ctx)) goto err;
+               }
+       else
+               {
+               if (!group->meth->field_sqr(group, tmp, x, ctx)) goto err;
+               if (!group->meth->field_div(group, tmp, &group->b, tmp, ctx)) goto err;
+               if (!BN_GF2m_add(tmp, &group->a, tmp)) goto err;
+               if (!BN_GF2m_add(tmp, x, tmp)) goto err;
+               if (!BN_GF2m_mod_solve_quad_arr(z, tmp, group->poly, ctx))
+                       {
+                       unsigned long err = ERR_peek_last_error();
+                       
+                       if (ERR_GET_LIB(err) == ERR_LIB_BN && ERR_GET_REASON(err) == BN_R_NO_SOLUTION)
+                               {
+                               ERR_clear_error();
+                               ECerr(EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES, EC_R_INVALID_COMPRESSED_POINT);
+                               }
+                       else
+                               ECerr(EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES, ERR_R_BN_LIB);
+                       goto err;
+                       }
+               z0 = (BN_is_odd(z)) ? 1 : 0;
+               if (!group->meth->field_mul(group, y, x, z, ctx)) goto err;
+               if (z0 != y_bit)
+                       {
+                       if (!BN_GF2m_add(y, y, x)) goto err;
+                       }
+               }
+
+       if (!EC_POINT_set_affine_coordinates_GF2m(group, point, x, y, ctx)) goto err;
+
+       ret = 1;
+
+ err:
+       BN_CTX_end(ctx);
+       if (new_ctx != NULL)
+               BN_CTX_free(new_ctx);
+       return ret;
+       }
 
 
 /* Converts an EC_POINT to an octet string.  
  * If buf is NULL, the encoded length will be returned.
  * If the length len of buf is smaller than required an error will be returned.
- *
- * The point compression section of this function is patented by Certicom Corp. 
- * under US Patent 6,141,420.  Point compression is disabled by default and can 
- * be enabled by defining the preprocessor macro OPENSSL_EC_BIN_PT_COMP at 
- * Configure-time.
  */
 size_t ec_GF2m_simple_point2oct(const EC_GROUP *group, const EC_POINT *point, point_conversion_form_t form,
        unsigned char *buf, size_t len, BN_CTX *ctx)
@@ -428,14 +504,6 @@ size_t ec_GF2m_simple_point2oct(const EC_GROUP *group, const EC_POINT *point, po
        BIGNUM *x, *y, *yxi;
        size_t field_len, i, skip;
 
-#ifndef OPENSSL_EC_BIN_PT_COMP
-       if ((form == POINT_CONVERSION_COMPRESSED) || (form == POINT_CONVERSION_HYBRID)) 
-               {
-               ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, ERR_R_DISABLED);
-               goto err;
-               }
-#endif
-
        if ((form != POINT_CONVERSION_COMPRESSED)
                && (form != POINT_CONVERSION_UNCOMPRESSED)
                && (form != POINT_CONVERSION_HYBRID))
@@ -490,13 +558,11 @@ size_t ec_GF2m_simple_point2oct(const EC_GROUP *group, const EC_POINT *point, po
                if (!EC_POINT_get_affine_coordinates_GF2m(group, point, x, y, ctx)) goto err;
 
                buf[0] = form;
-#ifdef OPENSSL_EC_BIN_PT_COMP
                if ((form != POINT_CONVERSION_UNCOMPRESSED) && !BN_is_zero(x))
                        {
                        if (!group->meth->field_div(group, yxi, y, x, ctx)) goto err;
                        if (BN_is_odd(yxi)) buf[0]++;
                        }
-#endif
 
                i = 1;
                
@@ -821,7 +887,7 @@ int ec_GF2m_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_
        field_sqr = group->meth->field_sqr;     
 
        /* only support affine coordinates */
-       if (!point->Z_is_one) goto err;
+       if (!point->Z_is_one) return -1;
 
        if (ctx == NULL)
                {
diff --git a/deps/openssl/openssl/crypto/ec/ec2_smpt.c b/deps/openssl/openssl/crypto/ec/ec2_smpt.c
deleted file mode 100644 (file)
index 72a8d57..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-/* crypto/ec/ec2_smpt.c */
-/* This code was originally written by Douglas Stebila 
- * <dstebila@student.math.uwaterloo.ca> for the OpenSSL project.
- */
-/* ====================================================================
- * Copyright (c) 1998-2002 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    openssl-core@openssl.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
- * ====================================================================
- *
- * This product includes cryptographic software written by Eric Young
- * (eay@cryptsoft.com).  This product includes software written by Tim
- * Hudson (tjh@cryptsoft.com).
- *
- */
-
-
-/* Calaculates and sets the affine coordinates of an EC_POINT from the given
- * compressed coordinates.  Uses algorithm 2.3.4 of SEC 1. 
- * Note that the simple implementation only uses affine coordinates.
- *
- * This algorithm is patented by Certicom Corp. under US Patent 6,141,420
- * (for licensing information, contact licensing@certicom.com).
- * This function is disabled by default and can be enabled by defining the 
- * preprocessor macro OPENSSL_EC_BIN_PT_COMP at Configure-time.
- */
-int ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *point,
-       const BIGNUM *x_, int y_bit, BN_CTX *ctx)
-       {
-#ifndef OPENSSL_EC_BIN_PT_COMP 
-       ECerr(EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES, ERR_R_DISABLED);
-       return 0;
-#else
-       BN_CTX *new_ctx = NULL;
-       BIGNUM *tmp, *x, *y, *z;
-       int ret = 0, z0;
-
-       /* clear error queue */
-       ERR_clear_error();
-
-       if (ctx == NULL)
-               {
-               ctx = new_ctx = BN_CTX_new();
-               if (ctx == NULL)
-                       return 0;
-               }
-
-       y_bit = (y_bit != 0) ? 1 : 0;
-
-       BN_CTX_start(ctx);
-       tmp = BN_CTX_get(ctx);
-       x = BN_CTX_get(ctx);
-       y = BN_CTX_get(ctx);
-       z = BN_CTX_get(ctx);
-       if (z == NULL) goto err;
-
-       if (!BN_GF2m_mod_arr(x, x_, group->poly)) goto err;
-       if (BN_is_zero(x))
-               {
-               if (!BN_GF2m_mod_sqrt_arr(y, &group->b, group->poly, ctx)) goto err;
-               }
-       else
-               {
-               if (!group->meth->field_sqr(group, tmp, x, ctx)) goto err;
-               if (!group->meth->field_div(group, tmp, &group->b, tmp, ctx)) goto err;
-               if (!BN_GF2m_add(tmp, &group->a, tmp)) goto err;
-               if (!BN_GF2m_add(tmp, x, tmp)) goto err;
-               if (!BN_GF2m_mod_solve_quad_arr(z, tmp, group->poly, ctx))
-                       {
-                       unsigned long err = ERR_peek_last_error();
-                       
-                       if (ERR_GET_LIB(err) == ERR_LIB_BN && ERR_GET_REASON(err) == BN_R_NO_SOLUTION)
-                               {
-                               ERR_clear_error();
-                               ECerr(EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES, EC_R_INVALID_COMPRESSED_POINT);
-                               }
-                       else
-                               ECerr(EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES, ERR_R_BN_LIB);
-                       goto err;
-                       }
-               z0 = (BN_is_odd(z)) ? 1 : 0;
-               if (!group->meth->field_mul(group, y, x, z, ctx)) goto err;
-               if (z0 != y_bit)
-                       {
-                       if (!BN_GF2m_add(y, y, x)) goto err;
-                       }
-               }
-
-       if (!EC_POINT_set_affine_coordinates_GF2m(group, point, x, y, ctx)) goto err;
-
-       ret = 1;
-
- err:
-       BN_CTX_end(ctx);
-       if (new_ctx != NULL)
-               BN_CTX_free(new_ctx);
-       return ret;
-#endif
-       }
diff --git a/deps/openssl/openssl/crypto/ec/ec_ameth.c b/deps/openssl/openssl/crypto/ec/ec_ameth.c
new file mode 100644 (file)
index 0000000..c00f7d7
--- /dev/null
@@ -0,0 +1,659 @@
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project 2006.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include "cryptlib.h"
+#include <openssl/x509.h>
+#include <openssl/ec.h>
+#include <openssl/bn.h>
+#ifndef OPENSSL_NO_CMS
+#include <openssl/cms.h>
+#endif
+#include "asn1_locl.h"
+
+static int eckey_param2type(int *pptype, void **ppval, EC_KEY *ec_key)
+       {
+       const EC_GROUP  *group;
+       int nid;
+       if (ec_key == NULL || (group = EC_KEY_get0_group(ec_key)) == NULL) 
+       {
+               ECerr(EC_F_ECKEY_PARAM2TYPE, EC_R_MISSING_PARAMETERS);
+               return 0;
+       }
+       if (EC_GROUP_get_asn1_flag(group)
+                     && (nid = EC_GROUP_get_curve_name(group)))
+               /* we have a 'named curve' => just set the OID */
+               {
+               *ppval = OBJ_nid2obj(nid);
+               *pptype = V_ASN1_OBJECT;
+               }
+       else    /* explicit parameters */
+               {
+               ASN1_STRING *pstr = NULL;
+               pstr = ASN1_STRING_new();
+               if (!pstr)
+                       return 0;
+               pstr->length = i2d_ECParameters(ec_key, &pstr->data);
+               if (pstr->length < 0)
+                       {
+                       ASN1_STRING_free(pstr);
+                       ECerr(EC_F_ECKEY_PARAM2TYPE, ERR_R_EC_LIB);
+                       return 0;
+                       }
+               *ppval = pstr;
+               *pptype = V_ASN1_SEQUENCE;
+               }
+       return 1;
+       }
+
+static int eckey_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
+       {
+       EC_KEY *ec_key = pkey->pkey.ec;
+       void *pval = NULL;
+       int ptype;
+       unsigned char *penc = NULL, *p;
+       int penclen;
+
+       if (!eckey_param2type(&ptype, &pval, ec_key))
+               {
+               ECerr(EC_F_ECKEY_PUB_ENCODE, ERR_R_EC_LIB);
+               return 0;
+               }
+       penclen = i2o_ECPublicKey(ec_key, NULL);
+       if (penclen <= 0)
+               goto err;
+       penc = OPENSSL_malloc(penclen);
+       if (!penc)
+               goto err;
+       p = penc;
+       penclen = i2o_ECPublicKey(ec_key, &p);
+       if (penclen <= 0)
+               goto err;
+       if (X509_PUBKEY_set0_param(pk, OBJ_nid2obj(EVP_PKEY_EC),
+                               ptype, pval, penc, penclen))
+               return 1;
+       err:
+       if (ptype == V_ASN1_OBJECT)
+               ASN1_OBJECT_free(pval);
+       else
+               ASN1_STRING_free(pval);
+       if (penc)
+               OPENSSL_free(penc);
+       return 0;
+       }
+
+static EC_KEY *eckey_type2param(int ptype, void *pval)
+       {
+       EC_KEY *eckey = NULL;
+       if (ptype == V_ASN1_SEQUENCE)
+               {
+               ASN1_STRING *pstr = pval;
+               const unsigned char *pm = NULL;
+               int pmlen;
+               pm = pstr->data;
+               pmlen = pstr->length;
+               if (!(eckey = d2i_ECParameters(NULL, &pm, pmlen)))
+                       {
+                       ECerr(EC_F_ECKEY_TYPE2PARAM, EC_R_DECODE_ERROR);
+                       goto ecerr;
+                       }
+               }
+       else if (ptype == V_ASN1_OBJECT)
+               {
+               ASN1_OBJECT *poid = pval;
+               EC_GROUP *group;
+
+               /* type == V_ASN1_OBJECT => the parameters are given
+                * by an asn1 OID
+                */
+               if ((eckey = EC_KEY_new()) == NULL)
+                       {
+                       ECerr(EC_F_ECKEY_TYPE2PARAM, ERR_R_MALLOC_FAILURE);
+                       goto ecerr;
+                       }
+               group = EC_GROUP_new_by_curve_name(OBJ_obj2nid(poid));
+               if (group == NULL)
+                       goto ecerr;
+               EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE);
+               if (EC_KEY_set_group(eckey, group) == 0)
+                       goto ecerr;
+               EC_GROUP_free(group);
+               }
+       else
+               {
+               ECerr(EC_F_ECKEY_TYPE2PARAM, EC_R_DECODE_ERROR);
+               goto ecerr;
+               }
+
+       return eckey;
+
+       ecerr:
+       if (eckey)
+               EC_KEY_free(eckey);
+       return NULL;
+       }
+
+static int eckey_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
+       {
+       const unsigned char *p = NULL;
+       void *pval;
+       int ptype, pklen;
+       EC_KEY *eckey = NULL;
+       X509_ALGOR *palg;
+
+       if (!X509_PUBKEY_get0_param(NULL, &p, &pklen, &palg, pubkey))
+               return 0;
+       X509_ALGOR_get0(NULL, &ptype, &pval, palg);
+
+       eckey = eckey_type2param(ptype, pval);
+
+       if (!eckey)
+               {
+               ECerr(EC_F_ECKEY_PUB_DECODE, ERR_R_EC_LIB);
+               return 0;
+               }
+
+       /* We have parameters now set public key */
+       if (!o2i_ECPublicKey(&eckey, &p, pklen))
+               {
+               ECerr(EC_F_ECKEY_PUB_DECODE, EC_R_DECODE_ERROR);
+               goto ecerr;
+               }
+
+       EVP_PKEY_assign_EC_KEY(pkey, eckey);
+       return 1;
+
+       ecerr:
+       if (eckey)
+               EC_KEY_free(eckey);
+       return 0;
+       }
+
+static int eckey_pub_cmp(const EVP_PKEY *a, const EVP_PKEY *b)
+       {
+       int  r;
+       const EC_GROUP *group = EC_KEY_get0_group(b->pkey.ec);
+       const EC_POINT *pa = EC_KEY_get0_public_key(a->pkey.ec),
+                      *pb = EC_KEY_get0_public_key(b->pkey.ec);
+       r = EC_POINT_cmp(group, pa, pb, NULL);
+       if (r == 0)
+               return 1;
+       if (r == 1)
+               return 0;
+       return -2;
+       }
+
+static int eckey_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8)
+       {
+       const unsigned char *p = NULL;
+       void *pval;
+       int ptype, pklen;
+       EC_KEY *eckey = NULL;
+       X509_ALGOR *palg;
+
+       if (!PKCS8_pkey_get0(NULL, &p, &pklen, &palg, p8))
+               return 0;
+       X509_ALGOR_get0(NULL, &ptype, &pval, palg);
+
+       eckey = eckey_type2param(ptype, pval);
+
+       if (!eckey)
+               goto ecliberr;
+
+       /* We have parameters now set private key */
+       if (!d2i_ECPrivateKey(&eckey, &p, pklen))
+               {
+               ECerr(EC_F_ECKEY_PRIV_DECODE, EC_R_DECODE_ERROR);
+               goto ecerr;
+               }
+
+       /* calculate public key (if necessary) */
+       if (EC_KEY_get0_public_key(eckey) == NULL)
+               {
+               const BIGNUM *priv_key;
+               const EC_GROUP *group;
+               EC_POINT *pub_key;
+               /* the public key was not included in the SEC1 private
+                * key => calculate the public key */
+               group   = EC_KEY_get0_group(eckey);
+               pub_key = EC_POINT_new(group);
+               if (pub_key == NULL)
+                       {
+                       ECerr(EC_F_ECKEY_PRIV_DECODE, ERR_R_EC_LIB);
+                       goto ecliberr;
+                       }
+               if (!EC_POINT_copy(pub_key, EC_GROUP_get0_generator(group)))
+                       {
+                       EC_POINT_free(pub_key);
+                       ECerr(EC_F_ECKEY_PRIV_DECODE, ERR_R_EC_LIB);
+                       goto ecliberr;
+                       }
+               priv_key = EC_KEY_get0_private_key(eckey);
+               if (!EC_POINT_mul(group, pub_key, priv_key, NULL, NULL, NULL))
+                       {
+                       EC_POINT_free(pub_key);
+                       ECerr(EC_F_ECKEY_PRIV_DECODE, ERR_R_EC_LIB);
+                       goto ecliberr;
+                       }
+               if (EC_KEY_set_public_key(eckey, pub_key) == 0)
+                       {
+                       EC_POINT_free(pub_key);
+                       ECerr(EC_F_ECKEY_PRIV_DECODE, ERR_R_EC_LIB);
+                       goto ecliberr;
+                       }
+               EC_POINT_free(pub_key);
+               }
+
+       EVP_PKEY_assign_EC_KEY(pkey, eckey);
+       return 1;
+
+       ecliberr:
+       ECerr(EC_F_ECKEY_PRIV_DECODE, ERR_R_EC_LIB);
+       ecerr:
+       if (eckey)
+               EC_KEY_free(eckey);
+       return 0;
+       }
+
+static int eckey_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
+{
+       EC_KEY          *ec_key;
+       unsigned char   *ep, *p;
+       int             eplen, ptype;
+       void            *pval;
+       unsigned int    tmp_flags, old_flags;
+
+       ec_key = pkey->pkey.ec;
+
+       if (!eckey_param2type(&ptype, &pval, ec_key))
+               {
+               ECerr(EC_F_ECKEY_PRIV_ENCODE, EC_R_DECODE_ERROR);
+               return 0;
+               }
+
+       /* set the private key */
+
+       /* do not include the parameters in the SEC1 private key
+        * see PKCS#11 12.11 */
+       old_flags = EC_KEY_get_enc_flags(ec_key);
+       tmp_flags = old_flags | EC_PKEY_NO_PARAMETERS;
+       EC_KEY_set_enc_flags(ec_key, tmp_flags);
+       eplen = i2d_ECPrivateKey(ec_key, NULL);
+       if (!eplen)
+       {
+               EC_KEY_set_enc_flags(ec_key, old_flags);
+               ECerr(EC_F_ECKEY_PRIV_ENCODE, ERR_R_EC_LIB);
+               return 0;
+       }
+       ep = (unsigned char *) OPENSSL_malloc(eplen);
+       if (!ep)
+       {
+               EC_KEY_set_enc_flags(ec_key, old_flags);
+               ECerr(EC_F_ECKEY_PRIV_ENCODE, ERR_R_MALLOC_FAILURE);
+               return 0;
+       }
+       p = ep;
+       if (!i2d_ECPrivateKey(ec_key, &p))
+       {
+               EC_KEY_set_enc_flags(ec_key, old_flags);
+               OPENSSL_free(ep);
+               ECerr(EC_F_ECKEY_PRIV_ENCODE, ERR_R_EC_LIB);
+       }
+       /* restore old encoding flags */
+       EC_KEY_set_enc_flags(ec_key, old_flags);
+
+       if (!PKCS8_pkey_set0(p8, OBJ_nid2obj(NID_X9_62_id_ecPublicKey), 0,
+                               ptype, pval, ep, eplen))
+               return 0;
+
+       return 1;
+}
+
+static int int_ec_size(const EVP_PKEY *pkey)
+       {
+       return ECDSA_size(pkey->pkey.ec);
+       }
+
+static int ec_bits(const EVP_PKEY *pkey)
+       {
+       BIGNUM *order = BN_new();
+       const EC_GROUP *group;
+       int ret;
+
+       if (!order)
+               {
+               ERR_clear_error();
+               return 0;
+               }
+       group = EC_KEY_get0_group(pkey->pkey.ec);
+       if (!EC_GROUP_get_order(group, order, NULL))
+               {
+               ERR_clear_error();
+               return 0;
+               }
+
+       ret = BN_num_bits(order);
+       BN_free(order);
+       return ret;
+       }
+
+static int ec_missing_parameters(const EVP_PKEY *pkey)
+       {
+       if (EC_KEY_get0_group(pkey->pkey.ec) == NULL)
+               return 1;
+       return 0;
+       }
+
+static int ec_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)
+       {
+       EC_GROUP *group = EC_GROUP_dup(EC_KEY_get0_group(from->pkey.ec));
+       if (group == NULL)
+               return 0;
+       if (EC_KEY_set_group(to->pkey.ec, group) == 0)
+               return 0;
+       EC_GROUP_free(group);
+       return 1;
+       }
+
+static int ec_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b)
+       {
+       const EC_GROUP *group_a = EC_KEY_get0_group(a->pkey.ec),
+                      *group_b = EC_KEY_get0_group(b->pkey.ec);
+       if (EC_GROUP_cmp(group_a, group_b, NULL))
+               return 0;
+       else
+               return 1;
+       }
+
+static void int_ec_free(EVP_PKEY *pkey)
+       {
+       EC_KEY_free(pkey->pkey.ec);
+       }
+
+static int do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype)
+       {
+       unsigned char *buffer=NULL;
+       const char *ecstr;
+       size_t  buf_len=0, i;
+       int     ret=0, reason=ERR_R_BIO_LIB;
+       BIGNUM  *pub_key=NULL, *order=NULL;
+       BN_CTX  *ctx=NULL;
+       const EC_GROUP *group;
+       const EC_POINT *public_key;
+       const BIGNUM *priv_key;
+       if (x == NULL || (group = EC_KEY_get0_group(x)) == NULL)
+               {
+               reason = ERR_R_PASSED_NULL_PARAMETER;
+               goto err;
+               }
+
+       ctx = BN_CTX_new();
+       if (ctx == NULL)
+               {
+               reason = ERR_R_MALLOC_FAILURE;
+               goto err;
+               }
+
+       if (ktype > 0)
+               {
+               public_key = EC_KEY_get0_public_key(x);
+               if ((pub_key = EC_POINT_point2bn(group, public_key,
+                       EC_KEY_get_conv_form(x), NULL, ctx)) == NULL)
+                       {
+                       reason = ERR_R_EC_LIB;
+                       goto err;
+                       }
+               if (pub_key)
+                       buf_len = (size_t)BN_num_bytes(pub_key);
+               }
+
+       if (ktype == 2)
+               {
+               priv_key = EC_KEY_get0_private_key(x);
+               if (priv_key && (i = (size_t)BN_num_bytes(priv_key)) > buf_len)
+                       buf_len = i;
+               }
+       else
+               priv_key = NULL;
+
+       if (ktype > 0)
+               {
+               buf_len += 10;
+               if ((buffer = OPENSSL_malloc(buf_len)) == NULL)
+                       {
+                       reason = ERR_R_MALLOC_FAILURE;
+                       goto err;
+                       }
+               }
+       if (ktype == 2)
+               ecstr = "Private-Key";
+       else if (ktype == 1)
+               ecstr = "Public-Key";
+       else
+               ecstr = "ECDSA-Parameters";
+
+       if (!BIO_indent(bp, off, 128))
+               goto err;
+       if ((order = BN_new()) == NULL)
+               goto err;
+       if (!EC_GROUP_get_order(group, order, NULL))
+               goto err;
+       if (BIO_printf(bp, "%s: (%d bit)\n", ecstr,
+               BN_num_bits(order)) <= 0) goto err;
+  
+       if ((priv_key != NULL) && !ASN1_bn_print(bp, "priv:", priv_key, 
+               buffer, off))
+               goto err;
+       if ((pub_key != NULL) && !ASN1_bn_print(bp, "pub: ", pub_key,
+               buffer, off))
+               goto err;
+       if (!ECPKParameters_print(bp, group, off))
+               goto err;
+       ret=1;
+err:
+       if (!ret)
+               ECerr(EC_F_DO_EC_KEY_PRINT, reason);
+       if (pub_key) 
+               BN_free(pub_key);
+       if (order)
+               BN_free(order);
+       if (ctx)
+               BN_CTX_free(ctx);
+       if (buffer != NULL)
+               OPENSSL_free(buffer);
+       return(ret);
+       }
+
+static int eckey_param_decode(EVP_PKEY *pkey,
+                                       const unsigned char **pder, int derlen)
+       {
+       EC_KEY *eckey;
+       if (!(eckey = d2i_ECParameters(NULL, pder, derlen)))
+               {
+               ECerr(EC_F_ECKEY_PARAM_DECODE, ERR_R_EC_LIB);
+               return 0;
+               }
+       EVP_PKEY_assign_EC_KEY(pkey, eckey);
+       return 1;
+       }
+
+static int eckey_param_encode(const EVP_PKEY *pkey, unsigned char **pder)
+       {
+       return i2d_ECParameters(pkey->pkey.ec, pder);
+       }
+
+static int eckey_param_print(BIO *bp, const EVP_PKEY *pkey, int indent,
+                                                       ASN1_PCTX *ctx)
+       {
+       return do_EC_KEY_print(bp, pkey->pkey.ec, indent, 0);
+       }
+
+static int eckey_pub_print(BIO *bp, const EVP_PKEY *pkey, int indent,
+                                                       ASN1_PCTX *ctx)
+       {
+       return do_EC_KEY_print(bp, pkey->pkey.ec, indent, 1);
+       }
+
+
+static int eckey_priv_print(BIO *bp, const EVP_PKEY *pkey, int indent,
+                                                       ASN1_PCTX *ctx)
+       {
+       return do_EC_KEY_print(bp, pkey->pkey.ec, indent, 2);
+       }
+
+static int old_ec_priv_decode(EVP_PKEY *pkey,
+                                       const unsigned char **pder, int derlen)
+       {
+       EC_KEY *ec;
+       if (!(ec = d2i_ECPrivateKey (NULL, pder, derlen)))
+               {
+               ECerr(EC_F_OLD_EC_PRIV_DECODE, EC_R_DECODE_ERROR);
+               return 0;
+               }
+       EVP_PKEY_assign_EC_KEY(pkey, ec);
+       return 1;
+       }
+
+static int old_ec_priv_encode(const EVP_PKEY *pkey, unsigned char **pder)
+       {
+       return i2d_ECPrivateKey(pkey->pkey.ec, pder);
+       }
+
+static int ec_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
+       {
+       switch (op)
+               {
+               case ASN1_PKEY_CTRL_PKCS7_SIGN:
+               if (arg1 == 0)
+                       {
+                       int snid, hnid;
+                       X509_ALGOR *alg1, *alg2;
+                       PKCS7_SIGNER_INFO_get0_algs(arg2, NULL, &alg1, &alg2);
+                       if (alg1 == NULL || alg1->algorithm == NULL)
+                               return -1;
+                       hnid = OBJ_obj2nid(alg1->algorithm);
+                       if (hnid == NID_undef)
+                               return -1;
+                       if (!OBJ_find_sigid_by_algs(&snid, hnid, EVP_PKEY_id(pkey)))
+                               return -1; 
+                       X509_ALGOR_set0(alg2, OBJ_nid2obj(snid), V_ASN1_UNDEF, 0);
+                       }
+               return 1;
+#ifndef OPENSSL_NO_CMS
+               case ASN1_PKEY_CTRL_CMS_SIGN:
+               if (arg1 == 0)
+                       {
+                       int snid, hnid;
+                       X509_ALGOR *alg1, *alg2;
+                       CMS_SignerInfo_get0_algs(arg2, NULL, NULL,
+                                                               &alg1, &alg2);
+                       if (alg1 == NULL || alg1->algorithm == NULL)
+                               return -1;
+                       hnid = OBJ_obj2nid(alg1->algorithm);
+                       if (hnid == NID_undef)
+                               return -1;
+                       if (!OBJ_find_sigid_by_algs(&snid, hnid, EVP_PKEY_id(pkey)))
+                               return -1; 
+                       X509_ALGOR_set0(alg2, OBJ_nid2obj(snid), V_ASN1_UNDEF, 0);
+                       }
+               return 1;
+#endif
+
+               case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
+               *(int *)arg2 = NID_sha1;
+               return 2;
+
+               default:
+               return -2;
+
+               }
+
+       }
+
+const EVP_PKEY_ASN1_METHOD eckey_asn1_meth = 
+       {
+       EVP_PKEY_EC,
+       EVP_PKEY_EC,
+       0,
+       "EC",
+       "OpenSSL EC algorithm",
+
+       eckey_pub_decode,
+       eckey_pub_encode,
+       eckey_pub_cmp,
+       eckey_pub_print,
+
+       eckey_priv_decode,
+       eckey_priv_encode,
+       eckey_priv_print,
+
+       int_ec_size,
+       ec_bits,
+
+       eckey_param_decode,
+       eckey_param_encode,
+       ec_missing_parameters,
+       ec_copy_parameters,
+       ec_cmp_parameters,
+       eckey_param_print,
+
+       int_ec_free,
+       ec_pkey_ctrl,
+       old_ec_priv_decode,
+       old_ec_priv_encode
+       };
index beac209..23274e4 100644 (file)
 #include <openssl/err.h>
 #include <openssl/obj_mac.h>
 
-typedef struct ec_curve_data_st {
-       int     field_type;     /* either NID_X9_62_prime_field or
+typedef struct {
+       int     field_type,     /* either NID_X9_62_prime_field or
                                 * NID_X9_62_characteristic_two_field */
-       const char *p;          /* either a prime number or a polynomial */
-       const char *a;
-       const char *b;
-       const char *x;          /* the x coordinate of the generator */
-       const char *y;          /* the y coordinate of the generator */
-       const char *order;      /* the order of the group generated by the
-                                * generator */
-       const BN_ULONG cofactor;/* the cofactor */
-       const unsigned char *seed;/* the seed (optional) */
-       size_t  seed_len;
-       const char *comment;    /* a short description of the curve */
+               seed_len,
+               param_len;
+       unsigned int cofactor;  /* promoted to BN_ULONG */
 } EC_CURVE_DATA;
 
 /* the nist prime curves */
-static const unsigned char _EC_NIST_PRIME_192_SEED[] = {
-       0x30,0x45,0xAE,0x6F,0xC8,0x42,0x2F,0x64,0xED,0x57,
-       0x95,0x28,0xD3,0x81,0x20,0xEA,0xE1,0x21,0x96,0xD5};
-static const EC_CURVE_DATA _EC_NIST_PRIME_192 = {
-       NID_X9_62_prime_field,
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF",
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC",
-       "64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1",
-       "188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012",
-       "07192b95ffc8da78631011ed6b24cdd573f977a11e794811",
-       "FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831",1,
-       _EC_NIST_PRIME_192_SEED, 20,
-       "NIST/X9.62/SECG curve over a 192 bit prime field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+24*6]; }
+       _EC_NIST_PRIME_192 = {
+       { NID_X9_62_prime_field,20,24,1 },
+       { 0x30,0x45,0xAE,0x6F,0xC8,0x42,0x2F,0x64,0xED,0x57,    /* seed */
+         0x95,0x28,0xD3,0x81,0x20,0xEA,0xE1,0x21,0x96,0xD5,
+
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* p */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* a */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFC,
+         0x64,0x21,0x05,0x19,0xE5,0x9C,0x80,0xE7,0x0F,0xA7,    /* b */
+         0xE9,0xAB,0x72,0x24,0x30,0x49,0xFE,0xB8,0xDE,0xEC,
+         0xC1,0x46,0xB9,0xB1,
+         0x18,0x8D,0xA8,0x0E,0xB0,0x30,0x90,0xF6,0x7C,0xBF,    /* x */
+         0x20,0xEB,0x43,0xA1,0x88,0x00,0xF4,0xFF,0x0A,0xFD,
+         0x82,0xFF,0x10,0x12,
+         0x07,0x19,0x2b,0x95,0xff,0xc8,0xda,0x78,0x63,0x10,    /* y */
+         0x11,0xed,0x6b,0x24,0xcd,0xd5,0x73,0xf9,0x77,0xa1,
+         0x1e,0x79,0x48,0x11,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* order */
+         0xFF,0xFF,0x99,0xDE,0xF8,0x36,0x14,0x6B,0xC9,0xB1,
+         0xB4,0xD2,0x28,0x31 }
        };
 
-static const unsigned char _EC_NIST_PRIME_224_SEED[] = {
-       0xBD,0x71,0x34,0x47,0x99,0xD5,0xC7,0xFC,0xDC,0x45,
-       0xB5,0x9F,0xA3,0xB9,0xAB,0x8F,0x6A,0x94,0x8B,0xC5};
-static const EC_CURVE_DATA _EC_NIST_PRIME_224 = {
-       NID_X9_62_prime_field,
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001",
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE",
-       "B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4",
-       "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21",
-       "bd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34",
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D",1,
-       _EC_NIST_PRIME_224_SEED, 20,
-       "NIST/SECG curve over a 224 bit prime field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+28*6]; }
+       _EC_NIST_PRIME_224 = {
+       { NID_X9_62_prime_field,20,28,1 },
+       { 0xBD,0x71,0x34,0x47,0x99,0xD5,0xC7,0xFC,0xDC,0x45,    /* seed */
+         0xB5,0x9F,0xA3,0xB9,0xAB,0x8F,0x6A,0x94,0x8B,0xC5,
+
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* p */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* a */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,
+         0xB4,0x05,0x0A,0x85,0x0C,0x04,0xB3,0xAB,0xF5,0x41,    /* b */
+         0x32,0x56,0x50,0x44,0xB0,0xB7,0xD7,0xBF,0xD8,0xBA,
+         0x27,0x0B,0x39,0x43,0x23,0x55,0xFF,0xB4,
+         0xB7,0x0E,0x0C,0xBD,0x6B,0xB4,0xBF,0x7F,0x32,0x13,    /* x */
+         0x90,0xB9,0x4A,0x03,0xC1,0xD3,0x56,0xC2,0x11,0x22,
+         0x34,0x32,0x80,0xD6,0x11,0x5C,0x1D,0x21,
+         0xbd,0x37,0x63,0x88,0xb5,0xf7,0x23,0xfb,0x4c,0x22,    /* y */
+         0xdf,0xe6,0xcd,0x43,0x75,0xa0,0x5a,0x07,0x47,0x64,
+         0x44,0xd5,0x81,0x99,0x85,0x00,0x7e,0x34,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* order */
+         0xFF,0xFF,0xFF,0xFF,0x16,0xA2,0xE0,0xB8,0xF0,0x3E,
+         0x13,0xDD,0x29,0x45,0x5C,0x5C,0x2A,0x3D }
        };
 
-static const unsigned char _EC_NIST_PRIME_384_SEED[] = {
-       0xA3,0x35,0x92,0x6A,0xA3,0x19,0xA2,0x7A,0x1D,0x00,
-       0x89,0x6A,0x67,0x73,0xA4,0x82,0x7A,0xCD,0xAC,0x73};
-static const EC_CURVE_DATA _EC_NIST_PRIME_384 = {
-       NID_X9_62_prime_field,
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFF"
-       "FFF0000000000000000FFFFFFFF",
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFF"
-       "FFF0000000000000000FFFFFFFC",
-       "B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141120314088F5013875AC6563"
-       "98D8A2ED19D2A85C8EDD3EC2AEF",
-       "AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B9859F741E082542A385502F"
-       "25DBF55296C3A545E3872760AB7",
-       "3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b"
-       "1ce1d7e819d7a431d7c90ea0e5f",
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0"
-       "DB248B0A77AECEC196ACCC52973",1,
-       _EC_NIST_PRIME_384_SEED, 20,
-       "NIST/SECG curve over a 384 bit prime field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+48*6]; }
+       _EC_NIST_PRIME_384 = {
+       { NID_X9_62_prime_field,20,48,1 },
+       { 0xA3,0x35,0x92,0x6A,0xA3,0x19,0xA2,0x7A,0x1D,0x00,    /* seed */
+         0x89,0x6A,0x67,0x73,0xA4,0x82,0x7A,0xCD,0xAC,0x73,
+
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* p */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFE,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* a */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFE,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFC,
+         0xB3,0x31,0x2F,0xA7,0xE2,0x3E,0xE7,0xE4,0x98,0x8E,    /* b */
+         0x05,0x6B,0xE3,0xF8,0x2D,0x19,0x18,0x1D,0x9C,0x6E,
+         0xFE,0x81,0x41,0x12,0x03,0x14,0x08,0x8F,0x50,0x13,
+         0x87,0x5A,0xC6,0x56,0x39,0x8D,0x8A,0x2E,0xD1,0x9D,
+         0x2A,0x85,0xC8,0xED,0xD3,0xEC,0x2A,0xEF,
+         0xAA,0x87,0xCA,0x22,0xBE,0x8B,0x05,0x37,0x8E,0xB1,    /* x */
+         0xC7,0x1E,0xF3,0x20,0xAD,0x74,0x6E,0x1D,0x3B,0x62,
+         0x8B,0xA7,0x9B,0x98,0x59,0xF7,0x41,0xE0,0x82,0x54,
+         0x2A,0x38,0x55,0x02,0xF2,0x5D,0xBF,0x55,0x29,0x6C,
+         0x3A,0x54,0x5E,0x38,0x72,0x76,0x0A,0xB7,
+         0x36,0x17,0xde,0x4a,0x96,0x26,0x2c,0x6f,0x5d,0x9e,    /* y */
+         0x98,0xbf,0x92,0x92,0xdc,0x29,0xf8,0xf4,0x1d,0xbd,
+         0x28,0x9a,0x14,0x7c,0xe9,0xda,0x31,0x13,0xb5,0xf0,
+         0xb8,0xc0,0x0a,0x60,0xb1,0xce,0x1d,0x7e,0x81,0x9d,
+         0x7a,0x43,0x1d,0x7c,0x90,0xea,0x0e,0x5f,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* order */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xC7,0x63,0x4D,0x81,0xF4,0x37,
+         0x2D,0xDF,0x58,0x1A,0x0D,0xB2,0x48,0xB0,0xA7,0x7A,
+         0xEC,0xEC,0x19,0x6A,0xCC,0xC5,0x29,0x73 }
        };
 
-static const unsigned char _EC_NIST_PRIME_521_SEED[] = {
-       0xD0,0x9E,0x88,0x00,0x29,0x1C,0xB8,0x53,0x96,0xCC,
-       0x67,0x17,0x39,0x32,0x84,0xAA,0xA0,0xDA,0x64,0xBA};
-static const EC_CURVE_DATA _EC_NIST_PRIME_521 = {
-       NID_X9_62_prime_field,
-       "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
-       "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC",
-       "051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156"
-       "193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00",
-       "C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14"
-       "B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66",
-       "011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c9"
-       "7ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650",
-       "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51"
-       "868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409",1,
-       _EC_NIST_PRIME_521_SEED, 20,
-       "NIST/SECG curve over a 521 bit prime field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+66*6]; }
+       _EC_NIST_PRIME_521 = {
+       { NID_X9_62_prime_field,20,66,1 },
+       { 0xD0,0x9E,0x88,0x00,0x29,0x1C,0xB8,0x53,0x96,0xCC,    /* seed */
+         0x67,0x17,0x39,0x32,0x84,0xAA,0xA0,0xDA,0x64,0xBA,
+
+         0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* p */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* a */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,
+         0x00,0x51,0x95,0x3E,0xB9,0x61,0x8E,0x1C,0x9A,0x1F,    /* b */
+         0x92,0x9A,0x21,0xA0,0xB6,0x85,0x40,0xEE,0xA2,0xDA,
+         0x72,0x5B,0x99,0xB3,0x15,0xF3,0xB8,0xB4,0x89,0x91,
+         0x8E,0xF1,0x09,0xE1,0x56,0x19,0x39,0x51,0xEC,0x7E,
+         0x93,0x7B,0x16,0x52,0xC0,0xBD,0x3B,0xB1,0xBF,0x07,
+         0x35,0x73,0xDF,0x88,0x3D,0x2C,0x34,0xF1,0xEF,0x45,
+         0x1F,0xD4,0x6B,0x50,0x3F,0x00,
+         0x00,0xC6,0x85,0x8E,0x06,0xB7,0x04,0x04,0xE9,0xCD,    /* x */
+         0x9E,0x3E,0xCB,0x66,0x23,0x95,0xB4,0x42,0x9C,0x64,
+         0x81,0x39,0x05,0x3F,0xB5,0x21,0xF8,0x28,0xAF,0x60,
+         0x6B,0x4D,0x3D,0xBA,0xA1,0x4B,0x5E,0x77,0xEF,0xE7,
+         0x59,0x28,0xFE,0x1D,0xC1,0x27,0xA2,0xFF,0xA8,0xDE,
+         0x33,0x48,0xB3,0xC1,0x85,0x6A,0x42,0x9B,0xF9,0x7E,
+         0x7E,0x31,0xC2,0xE5,0xBD,0x66,
+         0x01,0x18,0x39,0x29,0x6a,0x78,0x9a,0x3b,0xc0,0x04,    /* y */
+         0x5c,0x8a,0x5f,0xb4,0x2c,0x7d,0x1b,0xd9,0x98,0xf5,
+         0x44,0x49,0x57,0x9b,0x44,0x68,0x17,0xaf,0xbd,0x17,
+         0x27,0x3e,0x66,0x2c,0x97,0xee,0x72,0x99,0x5e,0xf4,
+         0x26,0x40,0xc5,0x50,0xb9,0x01,0x3f,0xad,0x07,0x61,
+         0x35,0x3c,0x70,0x86,0xa2,0x72,0xc2,0x40,0x88,0xbe,
+         0x94,0x76,0x9f,0xd1,0x66,0x50,
+         0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* order */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFA,0x51,0x86,0x87,0x83,0xBF,0x2F,
+         0x96,0x6B,0x7F,0xCC,0x01,0x48,0xF7,0x09,0xA5,0xD0,
+         0x3B,0xB5,0xC9,0xB8,0x89,0x9C,0x47,0xAE,0xBB,0x6F,
+         0xB7,0x1E,0x91,0x38,0x64,0x09 }
        };
+
 /* the x9.62 prime curves (minus the nist prime curves) */
-static const unsigned char _EC_X9_62_PRIME_192V2_SEED[] = {
-       0x31,0xA9,0x2E,0xE2,0x02,0x9F,0xD1,0x0D,0x90,0x1B,
-       0x11,0x3E,0x99,0x07,0x10,0xF0,0xD2,0x1A,0xC6,0xB6};
-static const EC_CURVE_DATA _EC_X9_62_PRIME_192V2 = {
-       NID_X9_62_prime_field,
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF",
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC",
-       "CC22D6DFB95C6B25E49C0D6364A4E5980C393AA21668D953",
-       "EEA2BAE7E1497842F2DE7769CFE9C989C072AD696F48034A",
-       "6574d11d69b6ec7a672bb82a083df2f2b0847de970b2de15",
-       "FFFFFFFFFFFFFFFFFFFFFFFE5FB1A724DC80418648D8DD31",1,
-       _EC_X9_62_PRIME_192V2_SEED, 20,
-       "X9.62 curve over a 192 bit prime field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+24*6]; }
+       _EC_X9_62_PRIME_192V2 = {
+       { NID_X9_62_prime_field,20,24,1 },
+       { 0x31,0xA9,0x2E,0xE2,0x02,0x9F,0xD1,0x0D,0x90,0x1B,    /* seed */
+         0x11,0x3E,0x99,0x07,0x10,0xF0,0xD2,0x1A,0xC6,0xB6,
+
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* p */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* a */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFC,
+         0xCC,0x22,0xD6,0xDF,0xB9,0x5C,0x6B,0x25,0xE4,0x9C,    /* b */
+         0x0D,0x63,0x64,0xA4,0xE5,0x98,0x0C,0x39,0x3A,0xA2,
+         0x16,0x68,0xD9,0x53,
+         0xEE,0xA2,0xBA,0xE7,0xE1,0x49,0x78,0x42,0xF2,0xDE,    /* x */
+         0x77,0x69,0xCF,0xE9,0xC9,0x89,0xC0,0x72,0xAD,0x69,
+         0x6F,0x48,0x03,0x4A,
+         0x65,0x74,0xd1,0x1d,0x69,0xb6,0xec,0x7a,0x67,0x2b,    /* y */
+         0xb8,0x2a,0x08,0x3d,0xf2,0xf2,0xb0,0x84,0x7d,0xe9,
+         0x70,0xb2,0xde,0x15,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* order */
+         0xFF,0xFE,0x5F,0xB1,0xA7,0x24,0xDC,0x80,0x41,0x86,
+         0x48,0xD8,0xDD,0x31 }
        };
 
-static const unsigned char _EC_X9_62_PRIME_192V3_SEED[] = {
-       0xC4,0x69,0x68,0x44,0x35,0xDE,0xB3,0x78,0xC4,0xB6,
-       0x5C,0xA9,0x59,0x1E,0x2A,0x57,0x63,0x05,0x9A,0x2E};
-static const EC_CURVE_DATA _EC_X9_62_PRIME_192V3 = {
-       NID_X9_62_prime_field,
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF",
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC",
-       "22123DC2395A05CAA7423DAECCC94760A7D462256BD56916",
-       "7D29778100C65A1DA1783716588DCE2B8B4AEE8E228F1896",
-       "38a90f22637337334b49dcb66a6dc8f9978aca7648a943b0",
-       "FFFFFFFFFFFFFFFFFFFFFFFF7A62D031C83F4294F640EC13",1,
-       _EC_X9_62_PRIME_192V3_SEED, 20,
-       "X9.62 curve over a 192 bit prime field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+24*6]; }
+       _EC_X9_62_PRIME_192V3 = {
+       { NID_X9_62_prime_field,20,24,1 },
+       { 0xC4,0x69,0x68,0x44,0x35,0xDE,0xB3,0x78,0xC4,0xB6,    /* seed */
+         0x5C,0xA9,0x59,0x1E,0x2A,0x57,0x63,0x05,0x9A,0x2E,
+
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* p */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* a */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFC,
+         0x22,0x12,0x3D,0xC2,0x39,0x5A,0x05,0xCA,0xA7,0x42,    /* b */
+         0x3D,0xAE,0xCC,0xC9,0x47,0x60,0xA7,0xD4,0x62,0x25,
+         0x6B,0xD5,0x69,0x16,
+         0x7D,0x29,0x77,0x81,0x00,0xC6,0x5A,0x1D,0xA1,0x78,    /* x */
+         0x37,0x16,0x58,0x8D,0xCE,0x2B,0x8B,0x4A,0xEE,0x8E,
+         0x22,0x8F,0x18,0x96,
+         0x38,0xa9,0x0f,0x22,0x63,0x73,0x37,0x33,0x4b,0x49,    /* y */
+         0xdc,0xb6,0x6a,0x6d,0xc8,0xf9,0x97,0x8a,0xca,0x76,
+         0x48,0xa9,0x43,0xb0,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* order */
+         0xFF,0xFF,0x7A,0x62,0xD0,0x31,0xC8,0x3F,0x42,0x94,
+         0xF6,0x40,0xEC,0x13 }
        };
 
-static const unsigned char _EC_X9_62_PRIME_239V1_SEED[] = {
-       0xE4,0x3B,0xB4,0x60,0xF0,0xB8,0x0C,0xC0,0xC0,0xB0,
-       0x75,0x79,0x8E,0x94,0x80,0x60,0xF8,0x32,0x1B,0x7D};
-static const EC_CURVE_DATA _EC_X9_62_PRIME_239V1 = {
-       NID_X9_62_prime_field,
-       "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFF",
-       "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFC",
-       "6B016C3BDCF18941D0D654921475CA71A9DB2FB27D1D37796185C2942C0A",
-       "0FFA963CDCA8816CCC33B8642BEDF905C3D358573D3F27FBBD3B3CB9AAAF",
-       "7debe8e4e90a5dae6e4054ca530ba04654b36818ce226b39fccb7b02f1ae",
-       "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFF9E5E9A9F5D9071FBD1522688909D0B",1,
-       _EC_X9_62_PRIME_239V1_SEED, 20,
-       "X9.62 curve over a 239 bit prime field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+30*6]; }
+       _EC_X9_62_PRIME_239V1 = {
+       { NID_X9_62_prime_field,20,30,1 },
+       { 0xE4,0x3B,0xB4,0x60,0xF0,0xB8,0x0C,0xC0,0xC0,0xB0,    /* seed */
+         0x75,0x79,0x8E,0x94,0x80,0x60,0xF8,0x32,0x1B,0x7D,
+
+         0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* p */
+         0xFF,0xFF,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,
+         0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,
+
+         0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* a */
+         0xFF,0xFF,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,
+         0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFC,
+
+         0x6B,0x01,0x6C,0x3B,0xDC,0xF1,0x89,0x41,0xD0,0xD6,    /* b */
+         0x54,0x92,0x14,0x75,0xCA,0x71,0xA9,0xDB,0x2F,0xB2,
+         0x7D,0x1D,0x37,0x79,0x61,0x85,0xC2,0x94,0x2C,0x0A,
+
+         0x0F,0xFA,0x96,0x3C,0xDC,0xA8,0x81,0x6C,0xCC,0x33,    /* x */
+         0xB8,0x64,0x2B,0xED,0xF9,0x05,0xC3,0xD3,0x58,0x57,
+         0x3D,0x3F,0x27,0xFB,0xBD,0x3B,0x3C,0xB9,0xAA,0xAF,
+
+         0x7d,0xeb,0xe8,0xe4,0xe9,0x0a,0x5d,0xae,0x6e,0x40,    /* y */
+         0x54,0xca,0x53,0x0b,0xa0,0x46,0x54,0xb3,0x68,0x18,
+         0xce,0x22,0x6b,0x39,0xfc,0xcb,0x7b,0x02,0xf1,0xae,
+
+         0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* order */
+         0xFF,0xFF,0x7F,0xFF,0xFF,0x9E,0x5E,0x9A,0x9F,0x5D,
+         0x90,0x71,0xFB,0xD1,0x52,0x26,0x88,0x90,0x9D,0x0B }
        };
 
-static const unsigned char _EC_X9_62_PRIME_239V2_SEED[] = {
-       0xE8,0xB4,0x01,0x16,0x04,0x09,0x53,0x03,0xCA,0x3B,
-       0x80,0x99,0x98,0x2B,0xE0,0x9F,0xCB,0x9A,0xE6,0x16};
-static const EC_CURVE_DATA _EC_X9_62_PRIME_239V2 = {
-       NID_X9_62_prime_field,
-       "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFF",
-       "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFC",
-       "617FAB6832576CBBFED50D99F0249C3FEE58B94BA0038C7AE84C8C832F2C",
-       "38AF09D98727705120C921BB5E9E26296A3CDCF2F35757A0EAFD87B830E7",
-       "5b0125e4dbea0ec7206da0fc01d9b081329fb555de6ef460237dff8be4ba",
-       "7FFFFFFFFFFFFFFFFFFFFFFF800000CFA7E8594377D414C03821BC582063",1,
-       _EC_X9_62_PRIME_239V2_SEED, 20,
-       "X9.62 curve over a 239 bit prime field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+30*6]; }
+       _EC_X9_62_PRIME_239V2 = {
+       { NID_X9_62_prime_field,20,30,1 },
+       { 0xE8,0xB4,0x01,0x16,0x04,0x09,0x53,0x03,0xCA,0x3B,    /* seed */
+         0x80,0x99,0x98,0x2B,0xE0,0x9F,0xCB,0x9A,0xE6,0x16,
+
+         0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* p */
+         0xFF,0xFF,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,
+         0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,
+
+         0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* a */
+         0xFF,0xFF,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,
+         0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFC,
+
+         0x61,0x7F,0xAB,0x68,0x32,0x57,0x6C,0xBB,0xFE,0xD5,    /* b */
+         0x0D,0x99,0xF0,0x24,0x9C,0x3F,0xEE,0x58,0xB9,0x4B,
+         0xA0,0x03,0x8C,0x7A,0xE8,0x4C,0x8C,0x83,0x2F,0x2C,
+
+         0x38,0xAF,0x09,0xD9,0x87,0x27,0x70,0x51,0x20,0xC9,    /* x */
+         0x21,0xBB,0x5E,0x9E,0x26,0x29,0x6A,0x3C,0xDC,0xF2,
+         0xF3,0x57,0x57,0xA0,0xEA,0xFD,0x87,0xB8,0x30,0xE7,
+
+         0x5b,0x01,0x25,0xe4,0xdb,0xea,0x0e,0xc7,0x20,0x6d,    /* y */
+         0xa0,0xfc,0x01,0xd9,0xb0,0x81,0x32,0x9f,0xb5,0x55,
+         0xde,0x6e,0xf4,0x60,0x23,0x7d,0xff,0x8b,0xe4,0xba,
+
+         0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* order */
+         0xFF,0xFF,0x80,0x00,0x00,0xCF,0xA7,0xE8,0x59,0x43,
+         0x77,0xD4,0x14,0xC0,0x38,0x21,0xBC,0x58,0x20,0x63 }
        };
 
-static const unsigned char _EC_X9_62_PRIME_239V3_SEED[] = {
-       0x7D,0x73,0x74,0x16,0x8F,0xFE,0x34,0x71,0xB6,0x0A,
-       0x85,0x76,0x86,0xA1,0x94,0x75,0xD3,0xBF,0xA2,0xFF};
-static const EC_CURVE_DATA _EC_X9_62_PRIME_239V3 = {
-       NID_X9_62_prime_field,
-       "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFF",
-       "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFC",
-       "255705FA2A306654B1F4CB03D6A750A30C250102D4988717D9BA15AB6D3E",
-       "6768AE8E18BB92CFCF005C949AA2C6D94853D0E660BBF854B1C9505FE95A",
-       "1607e6898f390c06bc1d552bad226f3b6fcfe48b6e818499af18e3ed6cf3",
-       "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFF975DEB41B3A6057C3C432146526551",1,
-       _EC_X9_62_PRIME_239V3_SEED, 20,
-       "X9.62 curve over a 239 bit prime field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+30*6]; }
+       _EC_X9_62_PRIME_239V3 = {
+       { NID_X9_62_prime_field,20,30,1 },
+       { 0x7D,0x73,0x74,0x16,0x8F,0xFE,0x34,0x71,0xB6,0x0A,    /* seed */
+         0x85,0x76,0x86,0xA1,0x94,0x75,0xD3,0xBF,0xA2,0xFF,
+
+         0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* p */
+         0xFF,0xFF,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,
+         0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,
+
+         0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* a */
+         0xFF,0xFF,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,
+         0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFC,
+
+         0x25,0x57,0x05,0xFA,0x2A,0x30,0x66,0x54,0xB1,0xF4,    /* b */
+         0xCB,0x03,0xD6,0xA7,0x50,0xA3,0x0C,0x25,0x01,0x02,
+         0xD4,0x98,0x87,0x17,0xD9,0xBA,0x15,0xAB,0x6D,0x3E,
+
+         0x67,0x68,0xAE,0x8E,0x18,0xBB,0x92,0xCF,0xCF,0x00,    /* x */
+         0x5C,0x94,0x9A,0xA2,0xC6,0xD9,0x48,0x53,0xD0,0xE6,
+         0x60,0xBB,0xF8,0x54,0xB1,0xC9,0x50,0x5F,0xE9,0x5A,
+
+         0x16,0x07,0xe6,0x89,0x8f,0x39,0x0c,0x06,0xbc,0x1d,    /* y */
+         0x55,0x2b,0xad,0x22,0x6f,0x3b,0x6f,0xcf,0xe4,0x8b,
+         0x6e,0x81,0x84,0x99,0xaf,0x18,0xe3,0xed,0x6c,0xf3,
+
+         0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* order */
+         0xFF,0xFF,0x7F,0xFF,0xFF,0x97,0x5D,0xEB,0x41,0xB3,
+         0xA6,0x05,0x7C,0x3C,0x43,0x21,0x46,0x52,0x65,0x51 }
        };
 
-static const unsigned char _EC_X9_62_PRIME_256V1_SEED[] = {
-       0xC4,0x9D,0x36,0x08,0x86,0xE7,0x04,0x93,0x6A,0x66,
-       0x78,0xE1,0x13,0x9D,0x26,0xB7,0x81,0x9F,0x7E,0x90};
-static const EC_CURVE_DATA _EC_X9_62_PRIME_256V1 = {
-       NID_X9_62_prime_field,
-       "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF",
-       "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC",
-       "5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B",
-       "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296",
-       "4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5",
-       "FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551",1,
-       _EC_X9_62_PRIME_256V1_SEED, 20,
-       "X9.62/SECG curve over a 256 bit prime field"
+
+static const struct { EC_CURVE_DATA h; unsigned char data[20+32*6]; }
+       _EC_X9_62_PRIME_256V1 = {
+       { NID_X9_62_prime_field,20,32,1 },
+       { 0xC4,0x9D,0x36,0x08,0x86,0xE7,0x04,0x93,0x6A,0x66,    /* seed */
+         0x78,0xE1,0x13,0x9D,0x26,0xB7,0x81,0x9F,0x7E,0x90,
+
+         0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x01,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x01,0x00,0x00,    /* a */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFC,
+         0x5A,0xC6,0x35,0xD8,0xAA,0x3A,0x93,0xE7,0xB3,0xEB,    /* b */
+         0xBD,0x55,0x76,0x98,0x86,0xBC,0x65,0x1D,0x06,0xB0,
+         0xCC,0x53,0xB0,0xF6,0x3B,0xCE,0x3C,0x3E,0x27,0xD2,
+         0x60,0x4B,
+         0x6B,0x17,0xD1,0xF2,0xE1,0x2C,0x42,0x47,0xF8,0xBC,    /* x */
+         0xE6,0xE5,0x63,0xA4,0x40,0xF2,0x77,0x03,0x7D,0x81,
+         0x2D,0xEB,0x33,0xA0,0xF4,0xA1,0x39,0x45,0xD8,0x98,
+         0xC2,0x96,
+         0x4f,0xe3,0x42,0xe2,0xfe,0x1a,0x7f,0x9b,0x8e,0xe7,    /* y */
+         0xeb,0x4a,0x7c,0x0f,0x9e,0x16,0x2b,0xce,0x33,0x57,
+         0x6b,0x31,0x5e,0xce,0xcb,0xb6,0x40,0x68,0x37,0xbf,
+         0x51,0xf5,
+         0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0xFF,0xFF,    /* order */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xBC,0xE6,0xFA,0xAD,
+         0xA7,0x17,0x9E,0x84,0xF3,0xB9,0xCA,0xC2,0xFC,0x63,
+         0x25,0x51 }
        };
+
 /* the secg prime curves (minus the nist and x9.62 prime curves) */
-static const unsigned char _EC_SECG_PRIME_112R1_SEED[] = {
-       0x00,0xF5,0x0B,0x02,0x8E,0x4D,0x69,0x6E,0x67,0x68,
-       0x75,0x61,0x51,0x75,0x29,0x04,0x72,0x78,0x3F,0xB1};
-static const EC_CURVE_DATA _EC_SECG_PRIME_112R1 = {
-       NID_X9_62_prime_field,
-       "DB7C2ABF62E35E668076BEAD208B",
-       "DB7C2ABF62E35E668076BEAD2088",
-       "659EF8BA043916EEDE8911702B22",
-       "09487239995A5EE76B55F9C2F098",
-       "a89ce5af8724c0a23e0e0ff77500",
-       "DB7C2ABF62E35E7628DFAC6561C5",1,
-       _EC_SECG_PRIME_112R1_SEED, 20,
-       "SECG/WTLS curve over a 112 bit prime field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+14*6]; }
+       _EC_SECG_PRIME_112R1 = {
+       { NID_X9_62_prime_field,20,14,1 },
+       { 0x00,0xF5,0x0B,0x02,0x8E,0x4D,0x69,0x6E,0x67,0x68,    /* seed */
+         0x75,0x61,0x51,0x75,0x29,0x04,0x72,0x78,0x3F,0xB1,
+
+         0xDB,0x7C,0x2A,0xBF,0x62,0xE3,0x5E,0x66,0x80,0x76,    /* p */
+         0xBE,0xAD,0x20,0x8B,
+         0xDB,0x7C,0x2A,0xBF,0x62,0xE3,0x5E,0x66,0x80,0x76,    /* a */
+         0xBE,0xAD,0x20,0x88,
+         0x65,0x9E,0xF8,0xBA,0x04,0x39,0x16,0xEE,0xDE,0x89,    /* b */
+         0x11,0x70,0x2B,0x22,
+         0x09,0x48,0x72,0x39,0x99,0x5A,0x5E,0xE7,0x6B,0x55,    /* x */
+         0xF9,0xC2,0xF0,0x98,
+         0xa8,0x9c,0xe5,0xaf,0x87,0x24,0xc0,0xa2,0x3e,0x0e,    /* y */
+         0x0f,0xf7,0x75,0x00,
+         0xDB,0x7C,0x2A,0xBF,0x62,0xE3,0x5E,0x76,0x28,0xDF,    /* order */
+         0xAC,0x65,0x61,0xC5 }
        };
 
-static const unsigned char _EC_SECG_PRIME_112R2_SEED[] = {
-       0x00,0x27,0x57,0xA1,0x11,0x4D,0x69,0x6E,0x67,0x68,
-       0x75,0x61,0x51,0x75,0x53,0x16,0xC0,0x5E,0x0B,0xD4};
-static const EC_CURVE_DATA _EC_SECG_PRIME_112R2 = {
-       NID_X9_62_prime_field,
-       "DB7C2ABF62E35E668076BEAD208B",
-       "6127C24C05F38A0AAAF65C0EF02C",
-       "51DEF1815DB5ED74FCC34C85D709",
-       "4BA30AB5E892B4E1649DD0928643",
-       "adcd46f5882e3747def36e956e97",
-       "36DF0AAFD8B8D7597CA10520D04B",4, 
-       _EC_SECG_PRIME_112R2_SEED, 20,
-       "SECG curve over a 112 bit prime field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+14*6]; }
+       _EC_SECG_PRIME_112R2 = {
+       { NID_X9_62_prime_field,20,14,4 },
+       { 0x00,0x27,0x57,0xA1,0x11,0x4D,0x69,0x6E,0x67,0x68,    /* seed */
+         0x75,0x61,0x51,0x75,0x53,0x16,0xC0,0x5E,0x0B,0xD4,
+
+         0xDB,0x7C,0x2A,0xBF,0x62,0xE3,0x5E,0x66,0x80,0x76,    /* p */
+         0xBE,0xAD,0x20,0x8B,
+         0x61,0x27,0xC2,0x4C,0x05,0xF3,0x8A,0x0A,0xAA,0xF6,    /* a */
+         0x5C,0x0E,0xF0,0x2C,
+         0x51,0xDE,0xF1,0x81,0x5D,0xB5,0xED,0x74,0xFC,0xC3,    /* b */
+         0x4C,0x85,0xD7,0x09,
+         0x4B,0xA3,0x0A,0xB5,0xE8,0x92,0xB4,0xE1,0x64,0x9D,    /* x */
+         0xD0,0x92,0x86,0x43,
+         0xad,0xcd,0x46,0xf5,0x88,0x2e,0x37,0x47,0xde,0xf3,    /* y */
+         0x6e,0x95,0x6e,0x97,
+         0x36,0xDF,0x0A,0xAF,0xD8,0xB8,0xD7,0x59,0x7C,0xA1,    /* order */
+         0x05,0x20,0xD0,0x4B }
        };
 
-static const unsigned char _EC_SECG_PRIME_128R1_SEED[] = {
-       0x00,0x0E,0x0D,0x4D,0x69,0x6E,0x67,0x68,0x75,0x61,
-       0x51,0x75,0x0C,0xC0,0x3A,0x44,0x73,0xD0,0x36,0x79};
-static const EC_CURVE_DATA _EC_SECG_PRIME_128R1 = {
-       NID_X9_62_prime_field,
-       "FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF",
-       "FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFC",
-       "E87579C11079F43DD824993C2CEE5ED3",
-       "161FF7528B899B2D0C28607CA52C5B86",
-       "cf5ac8395bafeb13c02da292dded7a83",
-       "FFFFFFFE0000000075A30D1B9038A115",1,
-       _EC_SECG_PRIME_128R1_SEED, 20,
-       "SECG curve over a 128 bit prime field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+16*6]; }
+       _EC_SECG_PRIME_128R1 = {
+       { NID_X9_62_prime_field,20,16,1 },
+       { 0x00,0x0E,0x0D,0x4D,0x69,0x6E,0x67,0x68,0x75,0x61,    /* seed */
+         0x51,0x75,0x0C,0xC0,0x3A,0x44,0x73,0xD0,0x36,0x79,
+
+         0xFF,0xFF,0xFF,0xFD,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* p */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFD,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* a */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,
+         0xE8,0x75,0x79,0xC1,0x10,0x79,0xF4,0x3D,0xD8,0x24,    /* b */
+         0x99,0x3C,0x2C,0xEE,0x5E,0xD3,
+         0x16,0x1F,0xF7,0x52,0x8B,0x89,0x9B,0x2D,0x0C,0x28,    /* x */
+         0x60,0x7C,0xA5,0x2C,0x5B,0x86,
+         0xcf,0x5a,0xc8,0x39,0x5b,0xaf,0xeb,0x13,0xc0,0x2d,    /* y */
+         0xa2,0x92,0xdd,0xed,0x7a,0x83,
+         0xFF,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x75,0xA3,    /* order */
+         0x0D,0x1B,0x90,0x38,0xA1,0x15 }
        };
 
-static const unsigned char _EC_SECG_PRIME_128R2_SEED[] = {
-       0x00,0x4D,0x69,0x6E,0x67,0x68,0x75,0x61,0x51,0x75,
-       0x12,0xD8,0xF0,0x34,0x31,0xFC,0xE6,0x3B,0x88,0xF4};
-static const EC_CURVE_DATA _EC_SECG_PRIME_128R2 = {
-       NID_X9_62_prime_field,
-       "FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF",
-       "D6031998D1B3BBFEBF59CC9BBFF9AEE1",
-       "5EEEFCA380D02919DC2C6558BB6D8A5D",
-       "7B6AA5D85E572983E6FB32A7CDEBC140",
-       "27b6916a894d3aee7106fe805fc34b44",
-       "3FFFFFFF7FFFFFFFBE0024720613B5A3",4,
-       _EC_SECG_PRIME_128R2_SEED, 20,
-       "SECG curve over a 128 bit prime field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+16*6]; }
+       _EC_SECG_PRIME_128R2 = {
+       { NID_X9_62_prime_field,20,16,4 },
+       { 0x00,0x4D,0x69,0x6E,0x67,0x68,0x75,0x61,0x51,0x75,    /* seed */
+         0x12,0xD8,0xF0,0x34,0x31,0xFC,0xE6,0x3B,0x88,0xF4,
+
+         0xFF,0xFF,0xFF,0xFD,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* p */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xD6,0x03,0x19,0x98,0xD1,0xB3,0xBB,0xFE,0xBF,0x59,    /* a */
+         0xCC,0x9B,0xBF,0xF9,0xAE,0xE1,
+         0x5E,0xEE,0xFC,0xA3,0x80,0xD0,0x29,0x19,0xDC,0x2C,    /* b */
+         0x65,0x58,0xBB,0x6D,0x8A,0x5D,
+         0x7B,0x6A,0xA5,0xD8,0x5E,0x57,0x29,0x83,0xE6,0xFB,    /* x */
+         0x32,0xA7,0xCD,0xEB,0xC1,0x40,
+         0x27,0xb6,0x91,0x6a,0x89,0x4d,0x3a,0xee,0x71,0x06,    /* y */
+         0xfe,0x80,0x5f,0xc3,0x4b,0x44,
+         0x3F,0xFF,0xFF,0xFF,0x7F,0xFF,0xFF,0xFF,0xBE,0x00,    /* order */
+         0x24,0x72,0x06,0x13,0xB5,0xA3 }
        };
 
-static const EC_CURVE_DATA _EC_SECG_PRIME_160K1 = {
-       NID_X9_62_prime_field,
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73",
-       "0",
-       "7",
-       "3B4C382CE37AA192A4019E763036F4F5DD4D7EBB",
-       "938cf935318fdced6bc28286531733c3f03c4fee",
-       "0100000000000000000001B8FA16DFAB9ACA16B6B3",1,
-       NULL, 0,
-       "SECG curve over a 160 bit prime field"
+static const struct { EC_CURVE_DATA h; unsigned char data[0+21*6]; }
+       _EC_SECG_PRIME_160K1 = {
+       { NID_X9_62_prime_field,0,21,1 },
+       {                                                       /* no seed */
+         0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* p */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xAC,
+         0x73,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* a */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* b */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x07,
+         0x00,0x3B,0x4C,0x38,0x2C,0xE3,0x7A,0xA1,0x92,0xA4,    /* x */
+         0x01,0x9E,0x76,0x30,0x36,0xF4,0xF5,0xDD,0x4D,0x7E,
+         0xBB,
+         0x00,0x93,0x8c,0xf9,0x35,0x31,0x8f,0xdc,0xed,0x6b,    /* y */
+         0xc2,0x82,0x86,0x53,0x17,0x33,0xc3,0xf0,0x3c,0x4f,
+         0xee,
+         0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* order */
+         0x01,0xB8,0xFA,0x16,0xDF,0xAB,0x9A,0xCA,0x16,0xB6,
+         0xB3 }
        };
 
-static const unsigned char _EC_SECG_PRIME_160R1_SEED[] = {
-       0x10,0x53,0xCD,0xE4,0x2C,0x14,0xD6,0x96,0xE6,0x76,
-       0x87,0x56,0x15,0x17,0x53,0x3B,0xF3,0xF8,0x33,0x45};
-static const EC_CURVE_DATA _EC_SECG_PRIME_160R1 = {
-       NID_X9_62_prime_field,
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF",
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC",
-       "1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45",
-       "4A96B5688EF573284664698968C38BB913CBFC82",
-       "23a628553168947d59dcc912042351377ac5fb32",
-       "0100000000000000000001F4C8F927AED3CA752257",1,
-       _EC_SECG_PRIME_160R1_SEED, 20,
-       "SECG curve over a 160 bit prime field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+21*6]; }
+       _EC_SECG_PRIME_160R1 = {
+       { NID_X9_62_prime_field,20,21,1 },
+       { 0x10,0x53,0xCD,0xE4,0x2C,0x14,0xD6,0x96,0xE6,0x76,    /* seed */
+         0x87,0x56,0x15,0x17,0x53,0x3B,0xF3,0xF8,0x33,0x45,
+
+         0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* p */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0xFF,0xFF,
+         0xFF,
+         0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* a */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0xFF,0xFF,
+         0xFC,
+         0x00,0x1C,0x97,0xBE,0xFC,0x54,0xBD,0x7A,0x8B,0x65,    /* b */
+         0xAC,0xF8,0x9F,0x81,0xD4,0xD4,0xAD,0xC5,0x65,0xFA,
+         0x45,
+         0x00,0x4A,0x96,0xB5,0x68,0x8E,0xF5,0x73,0x28,0x46,    /* x */
+         0x64,0x69,0x89,0x68,0xC3,0x8B,0xB9,0x13,0xCB,0xFC,
+         0x82,
+         0x00,0x23,0xa6,0x28,0x55,0x31,0x68,0x94,0x7d,0x59,    /* y */
+         0xdc,0xc9,0x12,0x04,0x23,0x51,0x37,0x7a,0xc5,0xfb,
+         0x32,
+         0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* order */
+         0x01,0xF4,0xC8,0xF9,0x27,0xAE,0xD3,0xCA,0x75,0x22,
+         0x57 }
        };
 
-static const unsigned char _EC_SECG_PRIME_160R2_SEED[] = {
-       0xB9,0x9B,0x99,0xB0,0x99,0xB3,0x23,0xE0,0x27,0x09,
-       0xA4,0xD6,0x96,0xE6,0x76,0x87,0x56,0x15,0x17,0x51};
-static const EC_CURVE_DATA _EC_SECG_PRIME_160R2 = {
-       NID_X9_62_prime_field,
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73",
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC70",
-       "B4E134D3FB59EB8BAB57274904664D5AF50388BA",
-       "52DCB034293A117E1F4FF11B30F7199D3144CE6D",
-       "feaffef2e331f296e071fa0df9982cfea7d43f2e",
-       "0100000000000000000000351EE786A818F3A1A16B",1,
-       _EC_SECG_PRIME_160R2_SEED, 20,
-       "SECG/WTLS curve over a 160 bit prime field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+21*6]; }
+       _EC_SECG_PRIME_160R2 = {
+       { NID_X9_62_prime_field,20,21,1 },
+       { 0xB9,0x9B,0x99,0xB0,0x99,0xB3,0x23,0xE0,0x27,0x09,    /* seed */
+         0xA4,0xD6,0x96,0xE6,0x76,0x87,0x56,0x15,0x17,0x51,
+
+         0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* p */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xAC,
+         0x73,
+         0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* a */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xAC,
+         0x70,
+         0x00,0xB4,0xE1,0x34,0xD3,0xFB,0x59,0xEB,0x8B,0xAB,    /* b */
+         0x57,0x27,0x49,0x04,0x66,0x4D,0x5A,0xF5,0x03,0x88,
+         0xBA,
+         0x00,0x52,0xDC,0xB0,0x34,0x29,0x3A,0x11,0x7E,0x1F,    /* x */
+         0x4F,0xF1,0x1B,0x30,0xF7,0x19,0x9D,0x31,0x44,0xCE,
+         0x6D,
+         0x00,0xfe,0xaf,0xfe,0xf2,0xe3,0x31,0xf2,0x96,0xe0,    /* y */
+         0x71,0xfa,0x0d,0xf9,0x98,0x2c,0xfe,0xa7,0xd4,0x3f,
+         0x2e,
+         0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* order */
+         0x00,0x35,0x1E,0xE7,0x86,0xA8,0x18,0xF3,0xA1,0xA1,
+         0x6B }
        };
 
-static const EC_CURVE_DATA _EC_SECG_PRIME_192K1 = {
-       NID_X9_62_prime_field,
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFEE37",
-       "0",
-       "3",
-       "DB4FF10EC057E9AE26B07D0280B7F4341DA5D1B1EAE06C7D",
-       "9b2f2f6d9c5628a7844163d015be86344082aa88d95e2f9d",
-       "FFFFFFFFFFFFFFFFFFFFFFFE26F2FC170F69466A74DEFD8D",1,
-       NULL, 20,
-       "SECG curve over a 192 bit prime field"
+static const struct { EC_CURVE_DATA h; unsigned char data[0+24*6]; }
+       _EC_SECG_PRIME_192K1 = {
+       { NID_X9_62_prime_field,0,24,1 },
+       {                                                       /* no seed */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* p */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,
+         0xFF,0xFF,0xEE,0x37,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* a */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* b */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x03,
+         0xDB,0x4F,0xF1,0x0E,0xC0,0x57,0xE9,0xAE,0x26,0xB0,    /* x */
+         0x7D,0x02,0x80,0xB7,0xF4,0x34,0x1D,0xA5,0xD1,0xB1,
+         0xEA,0xE0,0x6C,0x7D,
+         0x9b,0x2f,0x2f,0x6d,0x9c,0x56,0x28,0xa7,0x84,0x41,    /* y */
+         0x63,0xd0,0x15,0xbe,0x86,0x34,0x40,0x82,0xaa,0x88,
+         0xd9,0x5e,0x2f,0x9d,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* order */
+         0xFF,0xFE,0x26,0xF2,0xFC,0x17,0x0F,0x69,0x46,0x6A,
+         0x74,0xDE,0xFD,0x8D }
        };
 
-static const EC_CURVE_DATA _EC_SECG_PRIME_224K1 = {
-       NID_X9_62_prime_field,
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFE56D",
-       "0",
-       "5",
-       "A1455B334DF099DF30FC28A169A467E9E47075A90F7E650EB6B7A45C",
-       "7e089fed7fba344282cafbd6f7e319f7c0b0bd59e2ca4bdb556d61a5",
-       "010000000000000000000000000001DCE8D2EC6184CAF0A971769FB1F7",1,
-       NULL, 20,
-       "SECG curve over a 224 bit prime field"
+static const struct { EC_CURVE_DATA h; unsigned char data[0+29*6]; }
+       _EC_SECG_PRIME_224K1 = {
+       { NID_X9_62_prime_field,0,29,1 },
+       {                                                       /* no seed */
+         0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* p */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xE5,0x6D,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* a */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* b */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,
+         0x00,0xA1,0x45,0x5B,0x33,0x4D,0xF0,0x99,0xDF,0x30,    /* x */
+         0xFC,0x28,0xA1,0x69,0xA4,0x67,0xE9,0xE4,0x70,0x75,
+         0xA9,0x0F,0x7E,0x65,0x0E,0xB6,0xB7,0xA4,0x5C,
+         0x00,0x7e,0x08,0x9f,0xed,0x7f,0xba,0x34,0x42,0x82,    /* y */
+         0xca,0xfb,0xd6,0xf7,0xe3,0x19,0xf7,0xc0,0xb0,0xbd,
+         0x59,0xe2,0xca,0x4b,0xdb,0x55,0x6d,0x61,0xa5,
+         0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* order */
+         0x00,0x00,0x00,0x00,0x01,0xDC,0xE8,0xD2,0xEC,0x61,
+         0x84,0xCA,0xF0,0xA9,0x71,0x76,0x9F,0xB1,0xF7 }
        };
 
-static const EC_CURVE_DATA _EC_SECG_PRIME_256K1 = {
-       NID_X9_62_prime_field,
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F",
-       "0",
-       "7",
-       "79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798",
-       "483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8",
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141",1,
-       NULL, 20,
-       "SECG curve over a 256 bit prime field"
+static const struct { EC_CURVE_DATA h; unsigned char data[0+32*6]; }
+       _EC_SECG_PRIME_256K1 = {
+       { NID_X9_62_prime_field,0,32,1 },
+       {                                                       /* no seed */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* p */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,
+         0xFC,0x2F,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* a */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* b */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x07,
+         0x79,0xBE,0x66,0x7E,0xF9,0xDC,0xBB,0xAC,0x55,0xA0,    /* x */
+         0x62,0x95,0xCE,0x87,0x0B,0x07,0x02,0x9B,0xFC,0xDB,
+         0x2D,0xCE,0x28,0xD9,0x59,0xF2,0x81,0x5B,0x16,0xF8,
+         0x17,0x98,
+         0x48,0x3a,0xda,0x77,0x26,0xa3,0xc4,0x65,0x5d,0xa4,    /* y */
+         0xfb,0xfc,0x0e,0x11,0x08,0xa8,0xfd,0x17,0xb4,0x48,
+         0xa6,0x85,0x54,0x19,0x9c,0x47,0xd0,0x8f,0xfb,0x10,
+         0xd4,0xb8,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* order */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xBA,0xAE,0xDC,0xE6,
+         0xAF,0x48,0xA0,0x3B,0xBF,0xD2,0x5E,0x8C,0xD0,0x36,
+         0x41,0x41 }
        };
 
 /* some wap/wtls curves */
-static const EC_CURVE_DATA _EC_WTLS_8 = {
-       NID_X9_62_prime_field,
-       "FFFFFFFFFFFFFFFFFFFFFFFFFDE7",
-       "0",
-       "3",
-       "1",
-       "2",
-       "0100000000000001ECEA551AD837E9",1,
-       NULL, 20,
-       "WTLS curve over a 112 bit prime field"
+static const struct { EC_CURVE_DATA h; unsigned char data[0+15*6]; }
+       _EC_WTLS_8 = {
+       { NID_X9_62_prime_field,0,15,1 },
+       {                                                       /* no seed */
+         0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* p */
+         0xFF,0xFF,0xFF,0xFD,0xE7,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* a */
+         0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* b */
+         0x00,0x00,0x00,0x00,0x03,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* x */
+         0x00,0x00,0x00,0x00,0x01,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* y */
+         0x00,0x00,0x00,0x00,0x02,
+         0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xEC,0xEA,    /* order */
+         0x55,0x1A,0xD8,0x37,0xE9 }
        };
 
-static const EC_CURVE_DATA _EC_WTLS_9 = {
-       NID_X9_62_prime_field,
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC808F",
-       "0",
-       "3",
-       "1",
-       "2",
-       "0100000000000000000001CDC98AE0E2DE574ABF33",1,
-       NULL, 20,
-       "WTLS curve over a 160 bit prime field"
+static const struct { EC_CURVE_DATA h; unsigned char data[0+21*6]; }
+       _EC_WTLS_9 = {
+       { NID_X9_62_prime_field,0,21,1 },
+       {                                                       /* no seed */
+         0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* p */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x80,
+         0x8F,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* a */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* b */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x03,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* x */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x01,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* y */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x02,
+         0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* order */
+         0x01,0xCD,0xC9,0x8A,0xE0,0xE2,0xDE,0x57,0x4A,0xBF,
+         0x33 }
        };
 
-static const EC_CURVE_DATA _EC_WTLS_12 = {
-       NID_X9_62_prime_field,
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001",
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE",
-       "B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4",
-       "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21",
-       "bd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34",
-       "FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D", 1,
-       NULL, 0,
-       "WTLS curvs over a 224 bit prime field"
+static const struct { EC_CURVE_DATA h; unsigned char data[0+28*6]; }
+       _EC_WTLS_12 = {
+       { NID_X9_62_prime_field,0,28,1 },
+       {                                                       /* no seed */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* p */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* a */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,
+         0xB4,0x05,0x0A,0x85,0x0C,0x04,0xB3,0xAB,0xF5,0x41,    /* b */
+         0x32,0x56,0x50,0x44,0xB0,0xB7,0xD7,0xBF,0xD8,0xBA,
+         0x27,0x0B,0x39,0x43,0x23,0x55,0xFF,0xB4,
+         0xB7,0x0E,0x0C,0xBD,0x6B,0xB4,0xBF,0x7F,0x32,0x13,    /* x */
+         0x90,0xB9,0x4A,0x03,0xC1,0xD3,0x56,0xC2,0x11,0x22,
+         0x34,0x32,0x80,0xD6,0x11,0x5C,0x1D,0x21,
+         0xbd,0x37,0x63,0x88,0xb5,0xf7,0x23,0xfb,0x4c,0x22,    /* y */
+         0xdf,0xe6,0xcd,0x43,0x75,0xa0,0x5a,0x07,0x47,0x64,
+         0x44,0xd5,0x81,0x99,0x85,0x00,0x7e,0x34,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* order */
+         0xFF,0xFF,0xFF,0xFF,0x16,0xA2,0xE0,0xB8,0xF0,0x3E,
+         0x13,0xDD,0x29,0x45,0x5C,0x5C,0x2A,0x3D }
        };
 
 /* characteristic two curves */
-static const unsigned char _EC_SECG_CHAR2_113R1_SEED[] = {
-       0x10,0xE7,0x23,0xAB,0x14,0xD6,0x96,0xE6,0x76,0x87,
-       0x56,0x15,0x17,0x56,0xFE,0xBF,0x8F,0xCB,0x49,0xA9};
-static const EC_CURVE_DATA _EC_SECG_CHAR2_113R1 = {
-       NID_X9_62_characteristic_two_field,
-       "020000000000000000000000000201",
-       "003088250CA6E7C7FE649CE85820F7",
-       "00E8BEE4D3E2260744188BE0E9C723",
-       "009D73616F35F4AB1407D73562C10F",
-       "00A52830277958EE84D1315ED31886",
-       "0100000000000000D9CCEC8A39E56F", 2,
-       _EC_SECG_CHAR2_113R1_SEED, 20,
-       "SECG curve over a 113 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+15*6]; }
+       _EC_SECG_CHAR2_113R1 = {
+       { NID_X9_62_characteristic_two_field,20,15,2 },
+       { 0x10,0xE7,0x23,0xAB,0x14,0xD6,0x96,0xE6,0x76,0x87,    /* seed */
+         0x56,0x15,0x17,0x56,0xFE,0xBF,0x8F,0xCB,0x49,0xA9,
+
+         0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x02,0x01,
+         0x00,0x30,0x88,0x25,0x0C,0xA6,0xE7,0xC7,0xFE,0x64,    /* a */
+         0x9C,0xE8,0x58,0x20,0xF7,
+         0x00,0xE8,0xBE,0xE4,0xD3,0xE2,0x26,0x07,0x44,0x18,    /* b */
+         0x8B,0xE0,0xE9,0xC7,0x23,
+         0x00,0x9D,0x73,0x61,0x6F,0x35,0xF4,0xAB,0x14,0x07,    /* x */
+         0xD7,0x35,0x62,0xC1,0x0F,
+         0x00,0xA5,0x28,0x30,0x27,0x79,0x58,0xEE,0x84,0xD1,    /* y */
+         0x31,0x5E,0xD3,0x18,0x86,
+         0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xD9,0xCC,    /* order */
+         0xEC,0x8A,0x39,0xE5,0x6F }
        };
 
-static const unsigned char _EC_SECG_CHAR2_113R2_SEED[] = {
-       0x10,0xC0,0xFB,0x15,0x76,0x08,0x60,0xDE,0xF1,0xEE,
-       0xF4,0xD6,0x96,0xE6,0x76,0x87,0x56,0x15,0x17,0x5D};
-static const EC_CURVE_DATA _EC_SECG_CHAR2_113R2 = {
-       NID_X9_62_characteristic_two_field,
-       "020000000000000000000000000201",
-       "00689918DBEC7E5A0DD6DFC0AA55C7",
-       "0095E9A9EC9B297BD4BF36E059184F",
-       "01A57A6A7B26CA5EF52FCDB8164797",
-       "00B3ADC94ED1FE674C06E695BABA1D",
-       "010000000000000108789B2496AF93", 2,
-       _EC_SECG_CHAR2_113R2_SEED, 20,
-       "SECG curve over a 113 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+15*6]; }
+       _EC_SECG_CHAR2_113R2 = {
+       { NID_X9_62_characteristic_two_field,20,15,2 },
+       { 0x10,0xC0,0xFB,0x15,0x76,0x08,0x60,0xDE,0xF1,0xEE,    /* seed */
+         0xF4,0xD6,0x96,0xE6,0x76,0x87,0x56,0x15,0x17,0x5D,
+
+         0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x02,0x01,
+         0x00,0x68,0x99,0x18,0xDB,0xEC,0x7E,0x5A,0x0D,0xD6,    /* a */
+         0xDF,0xC0,0xAA,0x55,0xC7,
+         0x00,0x95,0xE9,0xA9,0xEC,0x9B,0x29,0x7B,0xD4,0xBF,    /* b */
+         0x36,0xE0,0x59,0x18,0x4F,
+         0x01,0xA5,0x7A,0x6A,0x7B,0x26,0xCA,0x5E,0xF5,0x2F,    /* x */
+         0xCD,0xB8,0x16,0x47,0x97,
+         0x00,0xB3,0xAD,0xC9,0x4E,0xD1,0xFE,0x67,0x4C,0x06,    /* y */
+         0xE6,0x95,0xBA,0xBA,0x1D,
+         0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x08,0x78,    /* order */
+         0x9B,0x24,0x96,0xAF,0x93 }
        };
 
-static const unsigned char _EC_SECG_CHAR2_131R1_SEED[] = {
-       0x4D,0x69,0x6E,0x67,0x68,0x75,0x61,0x51,0x75,0x98,
-       0x5B,0xD3,0xAD,0xBA,0xDA,0x21,0xB4,0x3A,0x97,0xE2};
-static const EC_CURVE_DATA _EC_SECG_CHAR2_131R1 = {
-       NID_X9_62_characteristic_two_field,
-       "080000000000000000000000000000010D",
-       "07A11B09A76B562144418FF3FF8C2570B8",
-       "0217C05610884B63B9C6C7291678F9D341",
-       "0081BAF91FDF9833C40F9C181343638399",
-       "078C6E7EA38C001F73C8134B1B4EF9E150",
-       "0400000000000000023123953A9464B54D", 2,
-       _EC_SECG_CHAR2_131R1_SEED, 20,
-       "SECG/WTLS curve over a 131 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+17*6]; }
+       _EC_SECG_CHAR2_131R1 = {
+       { NID_X9_62_characteristic_two_field,20,17,2 },
+       { 0x4D,0x69,0x6E,0x67,0x68,0x75,0x61,0x51,0x75,0x98,    /* seed */
+         0x5B,0xD3,0xAD,0xBA,0xDA,0x21,0xB4,0x3A,0x97,0xE2,
+
+         0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x01,0x0D,
+         0x07,0xA1,0x1B,0x09,0xA7,0x6B,0x56,0x21,0x44,0x41,    /* a */
+         0x8F,0xF3,0xFF,0x8C,0x25,0x70,0xB8,
+         0x02,0x17,0xC0,0x56,0x10,0x88,0x4B,0x63,0xB9,0xC6,    /* b */
+         0xC7,0x29,0x16,0x78,0xF9,0xD3,0x41,
+         0x00,0x81,0xBA,0xF9,0x1F,0xDF,0x98,0x33,0xC4,0x0F,    /* x */
+         0x9C,0x18,0x13,0x43,0x63,0x83,0x99,
+         0x07,0x8C,0x6E,0x7E,0xA3,0x8C,0x00,0x1F,0x73,0xC8,    /* y */
+         0x13,0x4B,0x1B,0x4E,0xF9,0xE1,0x50,
+         0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x31,    /* order */
+         0x23,0x95,0x3A,0x94,0x64,0xB5,0x4D }
        };
 
-static const unsigned char _EC_SECG_CHAR2_131R2_SEED[] = {
-       0x98,0x5B,0xD3,0xAD,0xBA,0xD4,0xD6,0x96,0xE6,0x76,
-       0x87,0x56,0x15,0x17,0x5A,0x21,0xB4,0x3A,0x97,0xE3};
-static const EC_CURVE_DATA _EC_SECG_CHAR2_131R2 = {
-       NID_X9_62_characteristic_two_field,
-       "080000000000000000000000000000010D",
-       "03E5A88919D7CAFCBF415F07C2176573B2",
-       "04B8266A46C55657AC734CE38F018F2192",
-       "0356DCD8F2F95031AD652D23951BB366A8",
-       "0648F06D867940A5366D9E265DE9EB240F",
-       "0400000000000000016954A233049BA98F", 2,
-       _EC_SECG_CHAR2_131R2_SEED, 20,
-       "SECG curve over a 131 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+17*6]; }
+       _EC_SECG_CHAR2_131R2 = {
+       { NID_X9_62_characteristic_two_field,20,17,2 },
+       { 0x98,0x5B,0xD3,0xAD,0xBA,0xD4,0xD6,0x96,0xE6,0x76,    /* seed */
+         0x87,0x56,0x15,0x17,0x5A,0x21,0xB4,0x3A,0x97,0xE3,
+
+         0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x01,0x0D,
+         0x03,0xE5,0xA8,0x89,0x19,0xD7,0xCA,0xFC,0xBF,0x41,    /* a */
+         0x5F,0x07,0xC2,0x17,0x65,0x73,0xB2,
+         0x04,0xB8,0x26,0x6A,0x46,0xC5,0x56,0x57,0xAC,0x73,    /* b */
+         0x4C,0xE3,0x8F,0x01,0x8F,0x21,0x92,
+         0x03,0x56,0xDC,0xD8,0xF2,0xF9,0x50,0x31,0xAD,0x65,    /* x */
+         0x2D,0x23,0x95,0x1B,0xB3,0x66,0xA8,
+         0x06,0x48,0xF0,0x6D,0x86,0x79,0x40,0xA5,0x36,0x6D,    /* y */
+         0x9E,0x26,0x5D,0xE9,0xEB,0x24,0x0F,
+         0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x69,    /* order */
+         0x54,0xA2,0x33,0x04,0x9B,0xA9,0x8F }
        };
 
-static const EC_CURVE_DATA _EC_NIST_CHAR2_163K = {
-       NID_X9_62_characteristic_two_field,
-       "0800000000000000000000000000000000000000C9",
-       "1",
-       "1",
-       "02FE13C0537BBC11ACAA07D793DE4E6D5E5C94EEE8",
-       "0289070FB05D38FF58321F2E800536D538CCDAA3D9",
-       "04000000000000000000020108A2E0CC0D99F8A5EF", 2,
-       NULL, 0,
-       "NIST/SECG/WTLS curve over a 163 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[0+21*6]; }
+       _EC_NIST_CHAR2_163K = {
+       { NID_X9_62_characteristic_two_field,0,21,2 },
+       {                                                       /* no seed */
+         0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0xC9,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* a */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x01,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* b */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x01,
+         0x02,0xFE,0x13,0xC0,0x53,0x7B,0xBC,0x11,0xAC,0xAA,    /* x */
+         0x07,0xD7,0x93,0xDE,0x4E,0x6D,0x5E,0x5C,0x94,0xEE,
+         0xE8,
+         0x02,0x89,0x07,0x0F,0xB0,0x5D,0x38,0xFF,0x58,0x32,    /* y */
+         0x1F,0x2E,0x80,0x05,0x36,0xD5,0x38,0xCC,0xDA,0xA3,
+         0xD9,
+         0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* order */
+         0x02,0x01,0x08,0xA2,0xE0,0xCC,0x0D,0x99,0xF8,0xA5,
+         0xEF }
        };
 
-static const unsigned char _EC_SECG_CHAR2_163R1_SEED[] = {
-       0x24,0xB7,0xB1,0x37,0xC8,0xA1,0x4D,0x69,0x6E,0x67,
-       0x68,0x75,0x61,0x51,0x75,0x6F,0xD0,0xDA,0x2E,0x5C};
-static const EC_CURVE_DATA _EC_SECG_CHAR2_163R1 = {
-       NID_X9_62_characteristic_two_field,
-       "0800000000000000000000000000000000000000C9",
-       "07B6882CAAEFA84F9554FF8428BD88E246D2782AE2",
-       "0713612DCDDCB40AAB946BDA29CA91F73AF958AFD9",
-       "0369979697AB43897789566789567F787A7876A654",
-       "00435EDB42EFAFB2989D51FEFCE3C80988F41FF883",
-       "03FFFFFFFFFFFFFFFFFFFF48AAB689C29CA710279B", 2,
+static const struct { EC_CURVE_DATA h; unsigned char data[0+21*6]; }
+       _EC_SECG_CHAR2_163R1 = {
+       { NID_X9_62_characteristic_two_field,0,21,2 },
+       {                                                       /* no seed */
+#if 0
 /* The algorithm used to derive the curve parameters from
  * the seed used here is slightly different than the
- * algorithm described in X9.62 .
- */
-#if 0
-       _EC_SECG_CHAR2_163R1_SEED, 20,
-#else
-       NULL, 0,
+ * algorithm described in X9.62 . */
+         0x24,0xB7,0xB1,0x37,0xC8,0xA1,0x4D,0x69,0x6E,0x67,
+         0x68,0x75,0x61,0x51,0x75,0x6F,0xD0,0xDA,0x2E,0x5C,
 #endif
-       "SECG curve over a 163 bit binary field"
+         0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0xC9,
+         0x07,0xB6,0x88,0x2C,0xAA,0xEF,0xA8,0x4F,0x95,0x54,    /* a */
+         0xFF,0x84,0x28,0xBD,0x88,0xE2,0x46,0xD2,0x78,0x2A,
+         0xE2,
+         0x07,0x13,0x61,0x2D,0xCD,0xDC,0xB4,0x0A,0xAB,0x94,    /* b */
+         0x6B,0xDA,0x29,0xCA,0x91,0xF7,0x3A,0xF9,0x58,0xAF,
+         0xD9,
+         0x03,0x69,0x97,0x96,0x97,0xAB,0x43,0x89,0x77,0x89,    /* x */
+         0x56,0x67,0x89,0x56,0x7F,0x78,0x7A,0x78,0x76,0xA6,
+         0x54,
+         0x00,0x43,0x5E,0xDB,0x42,0xEF,0xAF,0xB2,0x98,0x9D,    /* y */
+         0x51,0xFE,0xFC,0xE3,0xC8,0x09,0x88,0xF4,0x1F,0xF8,
+         0x83,
+         0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* order */
+         0xFF,0x48,0xAA,0xB6,0x89,0xC2,0x9C,0xA7,0x10,0x27,
+         0x9B }
        };
 
-static const unsigned char _EC_NIST_CHAR2_163B_SEED[] = {
-       0x85,0xE2,0x5B,0xFE,0x5C,0x86,0x22,0x6C,0xDB,0x12,
-       0x01,0x6F,0x75,0x53,0xF9,0xD0,0xE6,0x93,0xA2,0x68};
-static const EC_CURVE_DATA _EC_NIST_CHAR2_163B ={
-       NID_X9_62_characteristic_two_field,
-       "0800000000000000000000000000000000000000C9",
-       "1",
-       "020A601907B8C953CA1481EB10512F78744A3205FD",
-       "03F0EBA16286A2D57EA0991168D4994637E8343E36",
-       "00D51FBC6C71A0094FA2CDD545B11C5C0C797324F1",
-       "040000000000000000000292FE77E70C12A4234C33", 2,
-/* The seed here was used to created the curve parameters in normal
- * basis representation (and not the polynomial representation used here) 
- */
+static const struct { EC_CURVE_DATA h; unsigned char data[0+21*6]; }
+       _EC_NIST_CHAR2_163B = {
+       { NID_X9_62_characteristic_two_field,0,21,2 },
+       {                                                       /* no seed */
 #if 0
-       _EC_NIST_CHAR2_163B_SEED, 20,
-#else
-       NULL, 0,
+/* The seed here was used to created the curve parameters in normal
+ * basis representation (and not the polynomial representation used here) */
+         0x85,0xE2,0x5B,0xFE,0x5C,0x86,0x22,0x6C,0xDB,0x12,
+         0x01,0x6F,0x75,0x53,0xF9,0xD0,0xE6,0x93,0xA2,0x68,
 #endif
-       "NIST/SECG curve over a 163 bit binary field"
+         0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0xC9,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* a */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x01,
+         0x02,0x0A,0x60,0x19,0x07,0xB8,0xC9,0x53,0xCA,0x14,    /* b */
+         0x81,0xEB,0x10,0x51,0x2F,0x78,0x74,0x4A,0x32,0x05,
+         0xFD,
+         0x03,0xF0,0xEB,0xA1,0x62,0x86,0xA2,0xD5,0x7E,0xA0,    /* x */
+         0x99,0x11,0x68,0xD4,0x99,0x46,0x37,0xE8,0x34,0x3E,
+         0x36,
+         0x00,0xD5,0x1F,0xBC,0x6C,0x71,0xA0,0x09,0x4F,0xA2,    /* y */
+         0xCD,0xD5,0x45,0xB1,0x1C,0x5C,0x0C,0x79,0x73,0x24,
+         0xF1,
+         0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* order */
+         0x02,0x92,0xFE,0x77,0xE7,0x0C,0x12,0xA4,0x23,0x4C,
+         0x33 }
        };
 
-static const unsigned char _EC_SECG_CHAR2_193R1_SEED[] = {
-       0x10,0x3F,0xAE,0xC7,0x4D,0x69,0x6E,0x67,0x68,0x75,
-       0x61,0x51,0x75,0x77,0x7F,0xC5,0xB1,0x91,0xEF,0x30};
-static const EC_CURVE_DATA _EC_SECG_CHAR2_193R1 = {
-       NID_X9_62_characteristic_two_field,
-       "02000000000000000000000000000000000000000000008001",
-       "0017858FEB7A98975169E171F77B4087DE098AC8A911DF7B01",
-       "00FDFB49BFE6C3A89FACADAA7A1E5BBC7CC1C2E5D831478814",
-       "01F481BC5F0FF84A74AD6CDF6FDEF4BF6179625372D8C0C5E1",
-       "0025E399F2903712CCF3EA9E3A1AD17FB0B3201B6AF7CE1B05",
-       "01000000000000000000000000C7F34A778F443ACC920EBA49", 2,
-       _EC_SECG_CHAR2_193R1_SEED, 20,
-       "SECG curve over a 193 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+25*6]; }
+       _EC_SECG_CHAR2_193R1 = {
+       { NID_X9_62_characteristic_two_field,20,25,2 },
+       { 0x10,0x3F,0xAE,0xC7,0x4D,0x69,0x6E,0x67,0x68,0x75,    /* seed */
+         0x61,0x51,0x75,0x77,0x7F,0xC5,0xB1,0x91,0xEF,0x30,
+
+         0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x80,0x01,
+         0x00,0x17,0x85,0x8F,0xEB,0x7A,0x98,0x97,0x51,0x69,    /* a */
+         0xE1,0x71,0xF7,0x7B,0x40,0x87,0xDE,0x09,0x8A,0xC8,
+         0xA9,0x11,0xDF,0x7B,0x01,
+         0x00,0xFD,0xFB,0x49,0xBF,0xE6,0xC3,0xA8,0x9F,0xAC,    /* b */
+         0xAD,0xAA,0x7A,0x1E,0x5B,0xBC,0x7C,0xC1,0xC2,0xE5,
+         0xD8,0x31,0x47,0x88,0x14,
+         0x01,0xF4,0x81,0xBC,0x5F,0x0F,0xF8,0x4A,0x74,0xAD,    /* x */
+         0x6C,0xDF,0x6F,0xDE,0xF4,0xBF,0x61,0x79,0x62,0x53,
+         0x72,0xD8,0xC0,0xC5,0xE1,
+         0x00,0x25,0xE3,0x99,0xF2,0x90,0x37,0x12,0xCC,0xF3,    /* y */
+         0xEA,0x9E,0x3A,0x1A,0xD1,0x7F,0xB0,0xB3,0x20,0x1B,
+         0x6A,0xF7,0xCE,0x1B,0x05,
+         0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* order */
+         0x00,0x00,0x00,0xC7,0xF3,0x4A,0x77,0x8F,0x44,0x3A,
+         0xCC,0x92,0x0E,0xBA,0x49 }
        };
 
-static const unsigned char _EC_SECG_CHAR2_193R2_SEED[] = {
-       0x10,0xB7,0xB4,0xD6,0x96,0xE6,0x76,0x87,0x56,0x15,
-       0x17,0x51,0x37,0xC8,0xA1,0x6F,0xD0,0xDA,0x22,0x11};
-static const EC_CURVE_DATA _EC_SECG_CHAR2_193R2 = {
-       NID_X9_62_characteristic_two_field,
-       "02000000000000000000000000000000000000000000008001",
-       "0163F35A5137C2CE3EA6ED8667190B0BC43ECD69977702709B",
-       "00C9BB9E8927D4D64C377E2AB2856A5B16E3EFB7F61D4316AE",
-       "00D9B67D192E0367C803F39E1A7E82CA14A651350AAE617E8F",
-       "01CE94335607C304AC29E7DEFBD9CA01F596F927224CDECF6C",
-       "010000000000000000000000015AAB561B005413CCD4EE99D5", 2,
-       _EC_SECG_CHAR2_193R2_SEED, 20,
-       "SECG curve over a 193 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+25*6]; }
+       _EC_SECG_CHAR2_193R2 = {
+       { NID_X9_62_characteristic_two_field,20,25,2 },
+       { 0x10,0xB7,0xB4,0xD6,0x96,0xE6,0x76,0x87,0x56,0x15,    /* seed */
+         0x17,0x51,0x37,0xC8,0xA1,0x6F,0xD0,0xDA,0x22,0x11,
+
+         0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x80,0x01,
+         0x01,0x63,0xF3,0x5A,0x51,0x37,0xC2,0xCE,0x3E,0xA6,    /* a */
+         0xED,0x86,0x67,0x19,0x0B,0x0B,0xC4,0x3E,0xCD,0x69,
+         0x97,0x77,0x02,0x70,0x9B,
+         0x00,0xC9,0xBB,0x9E,0x89,0x27,0xD4,0xD6,0x4C,0x37,    /* b */
+         0x7E,0x2A,0xB2,0x85,0x6A,0x5B,0x16,0xE3,0xEF,0xB7,
+         0xF6,0x1D,0x43,0x16,0xAE,
+         0x00,0xD9,0xB6,0x7D,0x19,0x2E,0x03,0x67,0xC8,0x03,    /* x */
+         0xF3,0x9E,0x1A,0x7E,0x82,0xCA,0x14,0xA6,0x51,0x35,
+         0x0A,0xAE,0x61,0x7E,0x8F,
+         0x01,0xCE,0x94,0x33,0x56,0x07,0xC3,0x04,0xAC,0x29,    /* y */
+         0xE7,0xDE,0xFB,0xD9,0xCA,0x01,0xF5,0x96,0xF9,0x27,
+         0x22,0x4C,0xDE,0xCF,0x6C,
+         0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* order */
+         0x00,0x00,0x01,0x5A,0xAB,0x56,0x1B,0x00,0x54,0x13,
+         0xCC,0xD4,0xEE,0x99,0xD5 }
        };
 
-static const EC_CURVE_DATA _EC_NIST_CHAR2_233K = {
-       NID_X9_62_characteristic_two_field,
-       "020000000000000000000000000000000000000004000000000000000001",
-       "0",
-       "1",
-       "017232BA853A7E731AF129F22FF4149563A419C26BF50A4C9D6EEFAD6126",
-       "01DB537DECE819B7F70F555A67C427A8CD9BF18AEB9B56E0C11056FAE6A3",
-       "008000000000000000000000000000069D5BB915BCD46EFB1AD5F173ABDF", 4,
-       NULL, 0,
-       "NIST/SECG/WTLS curve over a 233 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[0+30*6]; }
+       _EC_NIST_CHAR2_233K = {
+       { NID_X9_62_characteristic_two_field,0,30,4 },
+       {                                                       /* no seed */
+         0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
+
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* a */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* b */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
+
+         0x01,0x72,0x32,0xBA,0x85,0x3A,0x7E,0x73,0x1A,0xF1,    /* x */
+         0x29,0xF2,0x2F,0xF4,0x14,0x95,0x63,0xA4,0x19,0xC2,
+         0x6B,0xF5,0x0A,0x4C,0x9D,0x6E,0xEF,0xAD,0x61,0x26,
+
+         0x01,0xDB,0x53,0x7D,0xEC,0xE8,0x19,0xB7,0xF7,0x0F,    /* y */
+         0x55,0x5A,0x67,0xC4,0x27,0xA8,0xCD,0x9B,0xF1,0x8A,
+         0xEB,0x9B,0x56,0xE0,0xC1,0x10,0x56,0xFA,0xE6,0xA3,
+
+         0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* order */
+         0x00,0x00,0x00,0x00,0x00,0x06,0x9D,0x5B,0xB9,0x15,
+         0xBC,0xD4,0x6E,0xFB,0x1A,0xD5,0xF1,0x73,0xAB,0xDF }
        };
 
-static const unsigned char _EC_NIST_CHAR2_233B_SEED[] = {
-       0x74,0xD5,0x9F,0xF0,0x7F,0x6B,0x41,0x3D,0x0E,0xA1,
-       0x4B,0x34,0x4B,0x20,0xA2,0xDB,0x04,0x9B,0x50,0xC3};
-static const EC_CURVE_DATA _EC_NIST_CHAR2_233B = {
-       NID_X9_62_characteristic_two_field,
-       "020000000000000000000000000000000000000004000000000000000001",
-       "000000000000000000000000000000000000000000000000000000000001",
-       "0066647EDE6C332C7F8C0923BB58213B333B20E9CE4281FE115F7D8F90AD",
-       "00FAC9DFCBAC8313BB2139F1BB755FEF65BC391F8B36F8F8EB7371FD558B",
-       "01006A08A41903350678E58528BEBF8A0BEFF867A7CA36716F7E01F81052",
-       "01000000000000000000000000000013E974E72F8A6922031D2603CFE0D7", 2,
-       _EC_NIST_CHAR2_233B_SEED, 20,
-       "NIST/SECG/WTLS curve over a 233 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+30*6]; }
+       _EC_NIST_CHAR2_233B = {
+       { NID_X9_62_characteristic_two_field,20,30,2 },
+       { 0x74,0xD5,0x9F,0xF0,0x7F,0x6B,0x41,0x3D,0x0E,0xA1,    /* seed */
+         0x4B,0x34,0x4B,0x20,0xA2,0xDB,0x04,0x9B,0x50,0xC3,
+
+         0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
+
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* a */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
+
+         0x00,0x66,0x64,0x7E,0xDE,0x6C,0x33,0x2C,0x7F,0x8C,    /* b */
+         0x09,0x23,0xBB,0x58,0x21,0x3B,0x33,0x3B,0x20,0xE9,
+         0xCE,0x42,0x81,0xFE,0x11,0x5F,0x7D,0x8F,0x90,0xAD,
+
+         0x00,0xFA,0xC9,0xDF,0xCB,0xAC,0x83,0x13,0xBB,0x21,    /* x */
+         0x39,0xF1,0xBB,0x75,0x5F,0xEF,0x65,0xBC,0x39,0x1F,
+         0x8B,0x36,0xF8,0xF8,0xEB,0x73,0x71,0xFD,0x55,0x8B,
+
+         0x01,0x00,0x6A,0x08,0xA4,0x19,0x03,0x35,0x06,0x78,    /* y */
+         0xE5,0x85,0x28,0xBE,0xBF,0x8A,0x0B,0xEF,0xF8,0x67,
+         0xA7,0xCA,0x36,0x71,0x6F,0x7E,0x01,0xF8,0x10,0x52,
+
+         0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* order */
+         0x00,0x00,0x00,0x00,0x00,0x13,0xE9,0x74,0xE7,0x2F,
+         0x8A,0x69,0x22,0x03,0x1D,0x26,0x03,0xCF,0xE0,0xD7 }
        };
 
-static const EC_CURVE_DATA _EC_SECG_CHAR2_239K1 = {
-       NID_X9_62_characteristic_two_field,
-       "800000000000000000004000000000000000000000000000000000000001",
-       "0",
-       "1",
-       "29A0B6A887A983E9730988A68727A8B2D126C44CC2CC7B2A6555193035DC",
-       "76310804F12E549BDB011C103089E73510ACB275FC312A5DC6B76553F0CA",
-       "2000000000000000000000000000005A79FEC67CB6E91F1C1DA800E478A5", 4,
-       NULL, 0,
-       "SECG curve over a 239 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[0+30*6]; }
+       _EC_SECG_CHAR2_239K1 = {
+       { NID_X9_62_characteristic_two_field,0,30,4 },
+       {                                                       /* no seed */
+         0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
+
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* a */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* b */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
+
+         0x29,0xA0,0xB6,0xA8,0x87,0xA9,0x83,0xE9,0x73,0x09,    /* x */
+         0x88,0xA6,0x87,0x27,0xA8,0xB2,0xD1,0x26,0xC4,0x4C,
+         0xC2,0xCC,0x7B,0x2A,0x65,0x55,0x19,0x30,0x35,0xDC,
+
+         0x76,0x31,0x08,0x04,0xF1,0x2E,0x54,0x9B,0xDB,0x01,    /* y */
+         0x1C,0x10,0x30,0x89,0xE7,0x35,0x10,0xAC,0xB2,0x75,
+         0xFC,0x31,0x2A,0x5D,0xC6,0xB7,0x65,0x53,0xF0,0xCA,
+
+         0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* order */
+         0x00,0x00,0x00,0x00,0x00,0x5A,0x79,0xFE,0xC6,0x7C,
+         0xB6,0xE9,0x1F,0x1C,0x1D,0xA8,0x00,0xE4,0x78,0xA5 }
        };
 
-static const EC_CURVE_DATA _EC_NIST_CHAR2_283K = {
-       NID_X9_62_characteristic_two_field,
-       "080000000000000000000000000000000000000000000000000000000000000000001"
-       "0A1",
-       "0",
-       "1",
-       "0503213F78CA44883F1A3B8162F188E553CD265F23C1567A16876913B0C2AC2458492"
-       "836",
-       "01CCDA380F1C9E318D90F95D07E5426FE87E45C0E8184698E45962364E34116177DD2"
-       "259",
-       "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE9AE2ED07577265DFF7F94451E061E163"
-       "C61", 4,
-       NULL, 20,
-       "NIST/SECG curve over a 283 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[0+36*6]; }
+       _EC_NIST_CHAR2_283K = {
+       { NID_X9_62_characteristic_two_field,0,36,4 },
+       {                                                       /* no seed */
+         0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x10,0xA1,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* a */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* b */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x01,
+         0x05,0x03,0x21,0x3F,0x78,0xCA,0x44,0x88,0x3F,0x1A,    /* x */
+         0x3B,0x81,0x62,0xF1,0x88,0xE5,0x53,0xCD,0x26,0x5F,
+         0x23,0xC1,0x56,0x7A,0x16,0x87,0x69,0x13,0xB0,0xC2,
+         0xAC,0x24,0x58,0x49,0x28,0x36,
+         0x01,0xCC,0xDA,0x38,0x0F,0x1C,0x9E,0x31,0x8D,0x90,    /* y */
+         0xF9,0x5D,0x07,0xE5,0x42,0x6F,0xE8,0x7E,0x45,0xC0,
+         0xE8,0x18,0x46,0x98,0xE4,0x59,0x62,0x36,0x4E,0x34,
+         0x11,0x61,0x77,0xDD,0x22,0x59,
+         0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* order */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE9,0xAE,
+         0x2E,0xD0,0x75,0x77,0x26,0x5D,0xFF,0x7F,0x94,0x45,
+         0x1E,0x06,0x1E,0x16,0x3C,0x61 }
        };
 
-static const unsigned char _EC_NIST_CHAR2_283B_SEED[] = {
-       0x77,0xE2,0xB0,0x73,0x70,0xEB,0x0F,0x83,0x2A,0x6D,
-       0xD5,0xB6,0x2D,0xFC,0x88,0xCD,0x06,0xBB,0x84,0xBE};
-static const EC_CURVE_DATA _EC_NIST_CHAR2_283B = {
-       NID_X9_62_characteristic_two_field,
-       "080000000000000000000000000000000000000000000000000000000000000000001"
-       "0A1",
-       "000000000000000000000000000000000000000000000000000000000000000000000"
-       "001",
-       "027B680AC8B8596DA5A4AF8A19A0303FCA97FD7645309FA2A581485AF6263E313B79A"
-       "2F5",
-       "05F939258DB7DD90E1934F8C70B0DFEC2EED25B8557EAC9C80E2E198F8CDBECD86B12"
-       "053",
-       "03676854FE24141CB98FE6D4B20D02B4516FF702350EDDB0826779C813F0DF45BE811"
-       "2F4",
-       "03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEF90399660FC938A90165B042A7CEFADB"
-       "307", 2,
-       _EC_NIST_CHAR2_283B_SEED, 20,
-       "NIST/SECG curve over a 283 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+36*6]; }
+       _EC_NIST_CHAR2_283B = {
+       { NID_X9_62_characteristic_two_field,20,36,2 },
+       { 0x77,0xE2,0xB0,0x73,0x70,0xEB,0x0F,0x83,0x2A,0x6D,    /* no seed */
+         0xD5,0xB6,0x2D,0xFC,0x88,0xCD,0x06,0xBB,0x84,0xBE,
+
+         0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x10,0xA1,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* a */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x01,
+         0x02,0x7B,0x68,0x0A,0xC8,0xB8,0x59,0x6D,0xA5,0xA4,    /* b */
+         0xAF,0x8A,0x19,0xA0,0x30,0x3F,0xCA,0x97,0xFD,0x76,
+         0x45,0x30,0x9F,0xA2,0xA5,0x81,0x48,0x5A,0xF6,0x26,
+         0x3E,0x31,0x3B,0x79,0xA2,0xF5,
+         0x05,0xF9,0x39,0x25,0x8D,0xB7,0xDD,0x90,0xE1,0x93,    /* x */
+         0x4F,0x8C,0x70,0xB0,0xDF,0xEC,0x2E,0xED,0x25,0xB8,
+         0x55,0x7E,0xAC,0x9C,0x80,0xE2,0xE1,0x98,0xF8,0xCD,
+         0xBE,0xCD,0x86,0xB1,0x20,0x53,
+         0x03,0x67,0x68,0x54,0xFE,0x24,0x14,0x1C,0xB9,0x8F,    /* y */
+         0xE6,0xD4,0xB2,0x0D,0x02,0xB4,0x51,0x6F,0xF7,0x02,
+         0x35,0x0E,0xDD,0xB0,0x82,0x67,0x79,0xC8,0x13,0xF0,
+         0xDF,0x45,0xBE,0x81,0x12,0xF4,
+         0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* order */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xEF,0x90,
+         0x39,0x96,0x60,0xFC,0x93,0x8A,0x90,0x16,0x5B,0x04,
+         0x2A,0x7C,0xEF,0xAD,0xB3,0x07 }
        };
 
-static const EC_CURVE_DATA _EC_NIST_CHAR2_409K = {
-       NID_X9_62_characteristic_two_field,
-       "020000000000000000000000000000000000000000000000000000000000000000000"
-       "00000000000008000000000000000000001",
-       "0",
-       "1",
-       "0060F05F658F49C1AD3AB1890F7184210EFD0987E307C84C27ACCFB8F9F67CC2C4601"
-       "89EB5AAAA62EE222EB1B35540CFE9023746",
-       "01E369050B7C4E42ACBA1DACBF04299C3460782F918EA427E6325165E9EA10E3DA5F6"
-       "C42E9C55215AA9CA27A5863EC48D8E0286B",
-       "007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE5F83B2D4EA20400"
-       "EC4557D5ED3E3E7CA5B4B5C83B8E01E5FCF", 4,
-       NULL, 0,
-       "NIST/SECG curve over a 409 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[0+52*6]; }
+       _EC_NIST_CHAR2_409K = {
+       { NID_X9_62_characteristic_two_field,0,52,4 },
+       {                                                       /* no seed */
+         0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x01,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* a */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* b */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x01,
+         0x00,0x60,0xF0,0x5F,0x65,0x8F,0x49,0xC1,0xAD,0x3A,    /* x */
+         0xB1,0x89,0x0F,0x71,0x84,0x21,0x0E,0xFD,0x09,0x87,
+         0xE3,0x07,0xC8,0x4C,0x27,0xAC,0xCF,0xB8,0xF9,0xF6,
+         0x7C,0xC2,0xC4,0x60,0x18,0x9E,0xB5,0xAA,0xAA,0x62,
+         0xEE,0x22,0x2E,0xB1,0xB3,0x55,0x40,0xCF,0xE9,0x02,
+         0x37,0x46,
+         0x01,0xE3,0x69,0x05,0x0B,0x7C,0x4E,0x42,0xAC,0xBA,    /* y */
+         0x1D,0xAC,0xBF,0x04,0x29,0x9C,0x34,0x60,0x78,0x2F,
+         0x91,0x8E,0xA4,0x27,0xE6,0x32,0x51,0x65,0xE9,0xEA,
+         0x10,0xE3,0xDA,0x5F,0x6C,0x42,0xE9,0xC5,0x52,0x15,
+         0xAA,0x9C,0xA2,0x7A,0x58,0x63,0xEC,0x48,0xD8,0xE0,
+         0x28,0x6B,
+         0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* order */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x5F,0x83,0xB2,
+         0xD4,0xEA,0x20,0x40,0x0E,0xC4,0x55,0x7D,0x5E,0xD3,
+         0xE3,0xE7,0xCA,0x5B,0x4B,0x5C,0x83,0xB8,0xE0,0x1E,
+         0x5F,0xCF }
        };
 
-static const unsigned char _EC_NIST_CHAR2_409B_SEED[] = {
-       0x40,0x99,0xB5,0xA4,0x57,0xF9,0xD6,0x9F,0x79,0x21,
-       0x3D,0x09,0x4C,0x4B,0xCD,0x4D,0x42,0x62,0x21,0x0B};
-static const EC_CURVE_DATA _EC_NIST_CHAR2_409B = {
-       NID_X9_62_characteristic_two_field,
-       "020000000000000000000000000000000000000000000000000000000000000000000"
-       "00000000000008000000000000000000001",
-       "000000000000000000000000000000000000000000000000000000000000000000000"
-       "00000000000000000000000000000000001",
-       "0021A5C2C8EE9FEB5C4B9A753B7B476B7FD6422EF1F3DD674761FA99D6AC27C8A9A19"
-       "7B272822F6CD57A55AA4F50AE317B13545F",
-       "015D4860D088DDB3496B0C6064756260441CDE4AF1771D4DB01FFE5B34E59703DC255"
-       "A868A1180515603AEAB60794E54BB7996A7",
-       "0061B1CFAB6BE5F32BBFA78324ED106A7636B9C5A7BD198D0158AA4F5488D08F38514"
-       "F1FDF4B4F40D2181B3681C364BA0273C706",
-       "010000000000000000000000000000000000000000000000000001E2AAD6A612F3330"
-       "7BE5FA47C3C9E052F838164CD37D9A21173", 2,
-       _EC_NIST_CHAR2_409B_SEED, 20,
-       "NIST/SECG curve over a 409 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+52*6]; }
+       _EC_NIST_CHAR2_409B = {
+       { NID_X9_62_characteristic_two_field,20,52,2 },
+       { 0x40,0x99,0xB5,0xA4,0x57,0xF9,0xD6,0x9F,0x79,0x21,    /* seed */
+         0x3D,0x09,0x4C,0x4B,0xCD,0x4D,0x42,0x62,0x21,0x0B,
+
+         0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x01,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* a */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x01,
+         0x00,0x21,0xA5,0xC2,0xC8,0xEE,0x9F,0xEB,0x5C,0x4B,    /* b */
+         0x9A,0x75,0x3B,0x7B,0x47,0x6B,0x7F,0xD6,0x42,0x2E,
+         0xF1,0xF3,0xDD,0x67,0x47,0x61,0xFA,0x99,0xD6,0xAC,
+         0x27,0xC8,0xA9,0xA1,0x97,0xB2,0x72,0x82,0x2F,0x6C,
+         0xD5,0x7A,0x55,0xAA,0x4F,0x50,0xAE,0x31,0x7B,0x13,
+         0x54,0x5F,
+         0x01,0x5D,0x48,0x60,0xD0,0x88,0xDD,0xB3,0x49,0x6B,    /* x */
+         0x0C,0x60,0x64,0x75,0x62,0x60,0x44,0x1C,0xDE,0x4A,
+         0xF1,0x77,0x1D,0x4D,0xB0,0x1F,0xFE,0x5B,0x34,0xE5,
+         0x97,0x03,0xDC,0x25,0x5A,0x86,0x8A,0x11,0x80,0x51,
+         0x56,0x03,0xAE,0xAB,0x60,0x79,0x4E,0x54,0xBB,0x79,
+         0x96,0xA7,
+         0x00,0x61,0xB1,0xCF,0xAB,0x6B,0xE5,0xF3,0x2B,0xBF,    /* y */
+         0xA7,0x83,0x24,0xED,0x10,0x6A,0x76,0x36,0xB9,0xC5,
+         0xA7,0xBD,0x19,0x8D,0x01,0x58,0xAA,0x4F,0x54,0x88,
+         0xD0,0x8F,0x38,0x51,0x4F,0x1F,0xDF,0x4B,0x4F,0x40,
+         0xD2,0x18,0x1B,0x36,0x81,0xC3,0x64,0xBA,0x02,0x73,
+         0xC7,0x06,
+         0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* order */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xE2,0xAA,0xD6,
+         0xA6,0x12,0xF3,0x33,0x07,0xBE,0x5F,0xA4,0x7C,0x3C,
+         0x9E,0x05,0x2F,0x83,0x81,0x64,0xCD,0x37,0xD9,0xA2,
+         0x11,0x73 }
        };
 
-static const EC_CURVE_DATA _EC_NIST_CHAR2_571K = {
-       NID_X9_62_characteristic_two_field,
-       "800000000000000000000000000000000000000000000000000000000000000000000"
-       "000000000000000000000000000000000000000000000000000000000000000000000"
-       "00425",
-       "0",
-       "1",
-       "026EB7A859923FBC82189631F8103FE4AC9CA2970012D5D46024804801841CA443709"
-       "58493B205E647DA304DB4CEB08CBBD1BA39494776FB988B47174DCA88C7E2945283A0"
-       "1C8972",
-       "0349DC807F4FBF374F4AEADE3BCA95314DD58CEC9F307A54FFC61EFC006D8A2C9D497"
-       "9C0AC44AEA74FBEBBB9F772AEDCB620B01A7BA7AF1B320430C8591984F601CD4C143E"
-       "F1C7A3",
-       "020000000000000000000000000000000000000000000000000000000000000000000"
-       "000131850E1F19A63E4B391A8DB917F4138B630D84BE5D639381E91DEB45CFE778F63"
-       "7C1001", 4,
-       NULL, 0,
-       "NIST/SECG curve over a 571 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[0+72*6]; }
+       _EC_NIST_CHAR2_571K = {
+       { NID_X9_62_characteristic_two_field,0,72,4 },
+       {                                                       /* no seed */
+         0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x04,0x25,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* a */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* b */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x01,
+         0x02,0x6E,0xB7,0xA8,0x59,0x92,0x3F,0xBC,0x82,0x18,    /* x */
+         0x96,0x31,0xF8,0x10,0x3F,0xE4,0xAC,0x9C,0xA2,0x97,
+         0x00,0x12,0xD5,0xD4,0x60,0x24,0x80,0x48,0x01,0x84,
+         0x1C,0xA4,0x43,0x70,0x95,0x84,0x93,0xB2,0x05,0xE6,
+         0x47,0xDA,0x30,0x4D,0xB4,0xCE,0xB0,0x8C,0xBB,0xD1,
+         0xBA,0x39,0x49,0x47,0x76,0xFB,0x98,0x8B,0x47,0x17,
+         0x4D,0xCA,0x88,0xC7,0xE2,0x94,0x52,0x83,0xA0,0x1C,
+         0x89,0x72,
+         0x03,0x49,0xDC,0x80,0x7F,0x4F,0xBF,0x37,0x4F,0x4A,    /* y */
+         0xEA,0xDE,0x3B,0xCA,0x95,0x31,0x4D,0xD5,0x8C,0xEC,
+         0x9F,0x30,0x7A,0x54,0xFF,0xC6,0x1E,0xFC,0x00,0x6D,
+         0x8A,0x2C,0x9D,0x49,0x79,0xC0,0xAC,0x44,0xAE,0xA7,
+         0x4F,0xBE,0xBB,0xB9,0xF7,0x72,0xAE,0xDC,0xB6,0x20,
+         0xB0,0x1A,0x7B,0xA7,0xAF,0x1B,0x32,0x04,0x30,0xC8,
+         0x59,0x19,0x84,0xF6,0x01,0xCD,0x4C,0x14,0x3E,0xF1,
+         0xC7,0xA3,
+         0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* order */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x13,0x18,0x50,0xE1,
+         0xF1,0x9A,0x63,0xE4,0xB3,0x91,0xA8,0xDB,0x91,0x7F,
+         0x41,0x38,0xB6,0x30,0xD8,0x4B,0xE5,0xD6,0x39,0x38,
+         0x1E,0x91,0xDE,0xB4,0x5C,0xFE,0x77,0x8F,0x63,0x7C,
+         0x10,0x01 }
        };
 
-static const unsigned char _EC_NIST_CHAR2_571B_SEED[] = {
-       0x2A,0xA0,0x58,0xF7,0x3A,0x0E,0x33,0xAB,0x48,0x6B,
-       0x0F,0x61,0x04,0x10,0xC5,0x3A,0x7F,0x13,0x23,0x10};
-static const EC_CURVE_DATA _EC_NIST_CHAR2_571B = {
-       NID_X9_62_characteristic_two_field,
-       "800000000000000000000000000000000000000000000000000000000000000000000"
-       "000000000000000000000000000000000000000000000000000000000000000000000"
-       "00425",
-       "000000000000000000000000000000000000000000000000000000000000000000000"
-       "000000000000000000000000000000000000000000000000000000000000000000000"
-       "000001",
-       "02F40E7E2221F295DE297117B7F3D62F5C6A97FFCB8CEFF1CD6BA8CE4A9A18AD84FFA"
-       "BBD8EFA59332BE7AD6756A66E294AFD185A78FF12AA520E4DE739BACA0C7FFEFF7F29"
-       "55727A",
-       "0303001D34B856296C16C0D40D3CD7750A93D1D2955FA80AA5F40FC8DB7B2ABDBDE53"
-       "950F4C0D293CDD711A35B67FB1499AE60038614F1394ABFA3B4C850D927E1E7769C8E"
-       "EC2D19",
-       "037BF27342DA639B6DCCFFFEB73D69D78C6C27A6009CBBCA1980F8533921E8A684423"
-       "E43BAB08A576291AF8F461BB2A8B3531D2F0485C19B16E2F1516E23DD3C1A4827AF1B"
-       "8AC15B",
-       "03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-       "FFFE661CE18FF55987308059B186823851EC7DD9CA1161DE93D5174D66E8382E9BB2F"
-       "E84E47", 2,
-       _EC_NIST_CHAR2_571B_SEED, 20,
-       "NIST/SECG curve over a 571 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+72*6]; }
+       _EC_NIST_CHAR2_571B = {
+       { NID_X9_62_characteristic_two_field,20,72,2 },
+       { 0x2A,0xA0,0x58,0xF7,0x3A,0x0E,0x33,0xAB,0x48,0x6B,    /* seed */
+         0x0F,0x61,0x04,0x10,0xC5,0x3A,0x7F,0x13,0x23,0x10,
+
+         0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x04,0x25,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* a */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x01,
+         0x02,0xF4,0x0E,0x7E,0x22,0x21,0xF2,0x95,0xDE,0x29,    /* b */
+         0x71,0x17,0xB7,0xF3,0xD6,0x2F,0x5C,0x6A,0x97,0xFF,
+         0xCB,0x8C,0xEF,0xF1,0xCD,0x6B,0xA8,0xCE,0x4A,0x9A,
+         0x18,0xAD,0x84,0xFF,0xAB,0xBD,0x8E,0xFA,0x59,0x33,
+         0x2B,0xE7,0xAD,0x67,0x56,0xA6,0x6E,0x29,0x4A,0xFD,
+         0x18,0x5A,0x78,0xFF,0x12,0xAA,0x52,0x0E,0x4D,0xE7,
+         0x39,0xBA,0xCA,0x0C,0x7F,0xFE,0xFF,0x7F,0x29,0x55,
+         0x72,0x7A,
+         0x03,0x03,0x00,0x1D,0x34,0xB8,0x56,0x29,0x6C,0x16,    /* x */
+         0xC0,0xD4,0x0D,0x3C,0xD7,0x75,0x0A,0x93,0xD1,0xD2,
+         0x95,0x5F,0xA8,0x0A,0xA5,0xF4,0x0F,0xC8,0xDB,0x7B,
+         0x2A,0xBD,0xBD,0xE5,0x39,0x50,0xF4,0xC0,0xD2,0x93,
+         0xCD,0xD7,0x11,0xA3,0x5B,0x67,0xFB,0x14,0x99,0xAE,
+         0x60,0x03,0x86,0x14,0xF1,0x39,0x4A,0xBF,0xA3,0xB4,
+         0xC8,0x50,0xD9,0x27,0xE1,0xE7,0x76,0x9C,0x8E,0xEC,
+         0x2D,0x19,
+         0x03,0x7B,0xF2,0x73,0x42,0xDA,0x63,0x9B,0x6D,0xCC,    /* y */
+         0xFF,0xFE,0xB7,0x3D,0x69,0xD7,0x8C,0x6C,0x27,0xA6,
+         0x00,0x9C,0xBB,0xCA,0x19,0x80,0xF8,0x53,0x39,0x21,
+         0xE8,0xA6,0x84,0x42,0x3E,0x43,0xBA,0xB0,0x8A,0x57,
+         0x62,0x91,0xAF,0x8F,0x46,0x1B,0xB2,0xA8,0xB3,0x53,
+         0x1D,0x2F,0x04,0x85,0xC1,0x9B,0x16,0xE2,0xF1,0x51,
+         0x6E,0x23,0xDD,0x3C,0x1A,0x48,0x27,0xAF,0x1B,0x8A,
+         0xC1,0x5B,
+         0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* order */
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE6,0x61,0xCE,0x18,
+         0xFF,0x55,0x98,0x73,0x08,0x05,0x9B,0x18,0x68,0x23,
+         0x85,0x1E,0xC7,0xDD,0x9C,0xA1,0x16,0x1D,0xE9,0x3D,
+         0x51,0x74,0xD6,0x6E,0x83,0x82,0xE9,0xBB,0x2F,0xE8,
+         0x4E,0x47 }
        };
 
-static const unsigned char _EC_X9_62_CHAR2_163V1_SEED[] = {
-       0xD2,0xC0,0xFB,0x15,0x76,0x08,0x60,0xDE,0xF1,0xEE,
-       0xF4,0xD6,0x96,0xE6,0x76,0x87,0x56,0x15,0x17,0x54};
-static const EC_CURVE_DATA _EC_X9_62_CHAR2_163V1 = {
-       NID_X9_62_characteristic_two_field,
-       "080000000000000000000000000000000000000107",
-       "072546B5435234A422E0789675F432C89435DE5242",
-       "00C9517D06D5240D3CFF38C74B20B6CD4D6F9DD4D9",
-       "07AF69989546103D79329FCC3D74880F33BBE803CB",
-       "01EC23211B5966ADEA1D3F87F7EA5848AEF0B7CA9F",
-       "0400000000000000000001E60FC8821CC74DAEAFC1", 2,
-       _EC_X9_62_CHAR2_163V1_SEED, 20,
-       "X9.62 curve over a 163 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+21*6]; }
+       _EC_X9_62_CHAR2_163V1 = {
+       { NID_X9_62_characteristic_two_field,20,21,2 },
+       { 0xD2,0xC0,0xFB,0x15,0x76,0x08,0x60,0xDE,0xF1,0xEE,
+         0xF4,0xD6,0x96,0xE6,0x76,0x87,0x56,0x15,0x17,0x54,    /* seed */
+
+         0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
+         0x07,
+         0x07,0x25,0x46,0xB5,0x43,0x52,0x34,0xA4,0x22,0xE0,    /* a */
+         0x78,0x96,0x75,0xF4,0x32,0xC8,0x94,0x35,0xDE,0x52,
+         0x42,
+         0x00,0xC9,0x51,0x7D,0x06,0xD5,0x24,0x0D,0x3C,0xFF,    /* b */
+         0x38,0xC7,0x4B,0x20,0xB6,0xCD,0x4D,0x6F,0x9D,0xD4,
+         0xD9,
+         0x07,0xAF,0x69,0x98,0x95,0x46,0x10,0x3D,0x79,0x32,    /* x */
+         0x9F,0xCC,0x3D,0x74,0x88,0x0F,0x33,0xBB,0xE8,0x03,
+         0xCB,
+         0x01,0xEC,0x23,0x21,0x1B,0x59,0x66,0xAD,0xEA,0x1D,    /* y */
+         0x3F,0x87,0xF7,0xEA,0x58,0x48,0xAE,0xF0,0xB7,0xCA,
+         0x9F,
+         0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* order */
+         0x01,0xE6,0x0F,0xC8,0x82,0x1C,0xC7,0x4D,0xAE,0xAF,
+         0xC1 }
        };
 
-static const unsigned char _EC_X9_62_CHAR2_163V2_SEED[] = {
-       0x53,0x81,0x4C,0x05,0x0D,0x44,0xD6,0x96,0xE6,0x76,
-       0x87,0x56,0x15,0x17,0x58,0x0C,0xA4,0xE2,0x9F,0xFD};
-static const EC_CURVE_DATA _EC_X9_62_CHAR2_163V2 = {
-       NID_X9_62_characteristic_two_field,
-       "080000000000000000000000000000000000000107",
-       "0108B39E77C4B108BED981ED0E890E117C511CF072",
-       "0667ACEB38AF4E488C407433FFAE4F1C811638DF20",
-       "0024266E4EB5106D0A964D92C4860E2671DB9B6CC5",
-       "079F684DDF6684C5CD258B3890021B2386DFD19FC5",
-       "03FFFFFFFFFFFFFFFFFFFDF64DE1151ADBB78F10A7", 2,
-       _EC_X9_62_CHAR2_163V2_SEED, 20,
-       "X9.62 curve over a 163 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+21*6]; }
+       _EC_X9_62_CHAR2_163V2 = {
+       { NID_X9_62_characteristic_two_field,20,21,2 },
+       { 0x53,0x81,0x4C,0x05,0x0D,0x44,0xD6,0x96,0xE6,0x76,    /* seed */
+         0x87,0x56,0x15,0x17,0x58,0x0C,0xA4,0xE2,0x9F,0xFD,
+
+         0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
+         0x07,
+         0x01,0x08,0xB3,0x9E,0x77,0xC4,0xB1,0x08,0xBE,0xD9,    /* a */
+         0x81,0xED,0x0E,0x89,0x0E,0x11,0x7C,0x51,0x1C,0xF0,
+         0x72,
+         0x06,0x67,0xAC,0xEB,0x38,0xAF,0x4E,0x48,0x8C,0x40,    /* b */
+         0x74,0x33,0xFF,0xAE,0x4F,0x1C,0x81,0x16,0x38,0xDF,
+         0x20,
+         0x00,0x24,0x26,0x6E,0x4E,0xB5,0x10,0x6D,0x0A,0x96,    /* x */
+         0x4D,0x92,0xC4,0x86,0x0E,0x26,0x71,0xDB,0x9B,0x6C,
+         0xC5,
+         0x07,0x9F,0x68,0x4D,0xDF,0x66,0x84,0xC5,0xCD,0x25,    /* y */
+         0x8B,0x38,0x90,0x02,0x1B,0x23,0x86,0xDF,0xD1,0x9F,
+         0xC5,
+         0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* order */
+         0xFD,0xF6,0x4D,0xE1,0x15,0x1A,0xDB,0xB7,0x8F,0x10,
+         0xA7 }
        };
 
-static const unsigned char _EC_X9_62_CHAR2_163V3_SEED[] = {
-       0x50,0xCB,0xF1,0xD9,0x5C,0xA9,0x4D,0x69,0x6E,0x67,
-       0x68,0x75,0x61,0x51,0x75,0xF1,0x6A,0x36,0xA3,0xB8};
-static const EC_CURVE_DATA _EC_X9_62_CHAR2_163V3 = {
-       NID_X9_62_characteristic_two_field,
-       "080000000000000000000000000000000000000107",
-       "07A526C63D3E25A256A007699F5447E32AE456B50E",
-       "03F7061798EB99E238FD6F1BF95B48FEEB4854252B",
-       "02F9F87B7C574D0BDECF8A22E6524775F98CDEBDCB",
-       "05B935590C155E17EA48EB3FF3718B893DF59A05D0",
-       "03FFFFFFFFFFFFFFFFFFFE1AEE140F110AFF961309", 2,
-       _EC_X9_62_CHAR2_163V3_SEED, 20,
-       "X9.62 curve over a 163 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+21*6]; }
+       _EC_X9_62_CHAR2_163V3 = {
+       { NID_X9_62_characteristic_two_field,20,21,2 },
+       { 0x50,0xCB,0xF1,0xD9,0x5C,0xA9,0x4D,0x69,0x6E,0x67,    /* seed */
+         0x68,0x75,0x61,0x51,0x75,0xF1,0x6A,0x36,0xA3,0xB8,
+
+         0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
+         0x07,
+         0x07,0xA5,0x26,0xC6,0x3D,0x3E,0x25,0xA2,0x56,0xA0,    /* a */
+         0x07,0x69,0x9F,0x54,0x47,0xE3,0x2A,0xE4,0x56,0xB5,
+         0x0E,
+         0x03,0xF7,0x06,0x17,0x98,0xEB,0x99,0xE2,0x38,0xFD,    /* b */
+         0x6F,0x1B,0xF9,0x5B,0x48,0xFE,0xEB,0x48,0x54,0x25,
+         0x2B,
+         0x02,0xF9,0xF8,0x7B,0x7C,0x57,0x4D,0x0B,0xDE,0xCF,    /* x */
+         0x8A,0x22,0xE6,0x52,0x47,0x75,0xF9,0x8C,0xDE,0xBD,
+         0xCB,
+         0x05,0xB9,0x35,0x59,0x0C,0x15,0x5E,0x17,0xEA,0x48,    /* y */
+         0xEB,0x3F,0xF3,0x71,0x8B,0x89,0x3D,0xF5,0x9A,0x05,
+         0xD0,
+         0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* order */
+         0xFE,0x1A,0xEE,0x14,0x0F,0x11,0x0A,0xFF,0x96,0x13,
+         0x09 }
        };
 
-static const EC_CURVE_DATA _EC_X9_62_CHAR2_176V1 = {
-       NID_X9_62_characteristic_two_field,
-       "0100000000000000000000000000000000080000000007",
-       "E4E6DB2995065C407D9D39B8D0967B96704BA8E9C90B",
-       "5DDA470ABE6414DE8EC133AE28E9BBD7FCEC0AE0FFF2",
-       "8D16C2866798B600F9F08BB4A8E860F3298CE04A5798",
-       "6FA4539C2DADDDD6BAB5167D61B436E1D92BB16A562C",
-       "00010092537397ECA4F6145799D62B0A19CE06FE26AD", 0xFF6E,
-       NULL, 0,
-       "X9.62 curve over a 176 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[0+23*6]; }
+       _EC_X9_62_CHAR2_176V1 = {
+       { NID_X9_62_characteristic_two_field,0,23,0xFF6E },
+       {                                                       /* no seed */
+         0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,
+         0x00,0x00,0x07,
+         0x00,0xE4,0xE6,0xDB,0x29,0x95,0x06,0x5C,0x40,0x7D,    /* a */
+         0x9D,0x39,0xB8,0xD0,0x96,0x7B,0x96,0x70,0x4B,0xA8,
+         0xE9,0xC9,0x0B,
+         0x00,0x5D,0xDA,0x47,0x0A,0xBE,0x64,0x14,0xDE,0x8E,    /* b */
+         0xC1,0x33,0xAE,0x28,0xE9,0xBB,0xD7,0xFC,0xEC,0x0A,
+         0xE0,0xFF,0xF2,
+         0x00,0x8D,0x16,0xC2,0x86,0x67,0x98,0xB6,0x00,0xF9,    /* x */
+         0xF0,0x8B,0xB4,0xA8,0xE8,0x60,0xF3,0x29,0x8C,0xE0,
+         0x4A,0x57,0x98,
+         0x00,0x6F,0xA4,0x53,0x9C,0x2D,0xAD,0xDD,0xD6,0xBA,    /* y */
+         0xB5,0x16,0x7D,0x61,0xB4,0x36,0xE1,0xD9,0x2B,0xB1,
+         0x6A,0x56,0x2C,
+         0x00,0x00,0x01,0x00,0x92,0x53,0x73,0x97,0xEC,0xA4,    /* order */
+         0xF6,0x14,0x57,0x99,0xD6,0x2B,0x0A,0x19,0xCE,0x06,
+         0xFE,0x26,0xAD }
        };
 
-static const unsigned char _EC_X9_62_CHAR2_191V1_SEED[] = {
-       0x4E,0x13,0xCA,0x54,0x27,0x44,0xD6,0x96,0xE6,0x76,
-       0x87,0x56,0x15,0x17,0x55,0x2F,0x27,0x9A,0x8C,0x84};
-static const EC_CURVE_DATA _EC_X9_62_CHAR2_191V1 = {
-       NID_X9_62_characteristic_two_field,
-       "800000000000000000000000000000000000000000000201",
-       "2866537B676752636A68F56554E12640276B649EF7526267",
-       "2E45EF571F00786F67B0081B9495A3D95462F5DE0AA185EC",
-       "36B3DAF8A23206F9C4F299D7B21A9C369137F2C84AE1AA0D",
-       "765BE73433B3F95E332932E70EA245CA2418EA0EF98018FB",
-       "40000000000000000000000004A20E90C39067C893BBB9A5", 2,
-       _EC_X9_62_CHAR2_191V1_SEED, 20,
-       "X9.62 curve over a 191 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+24*6]; }
+       _EC_X9_62_CHAR2_191V1 = {
+       { NID_X9_62_characteristic_two_field,20,24,2 },
+       { 0x4E,0x13,0xCA,0x54,0x27,0x44,0xD6,0x96,0xE6,0x76,    /* seed */
+         0x87,0x56,0x15,0x17,0x55,0x2F,0x27,0x9A,0x8C,0x84,
+
+         0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x02,0x01,
+         0x28,0x66,0x53,0x7B,0x67,0x67,0x52,0x63,0x6A,0x68,    /* a */
+         0xF5,0x65,0x54,0xE1,0x26,0x40,0x27,0x6B,0x64,0x9E,
+         0xF7,0x52,0x62,0x67,
+         0x2E,0x45,0xEF,0x57,0x1F,0x00,0x78,0x6F,0x67,0xB0,    /* b */
+         0x08,0x1B,0x94,0x95,0xA3,0xD9,0x54,0x62,0xF5,0xDE,
+         0x0A,0xA1,0x85,0xEC,
+         0x36,0xB3,0xDA,0xF8,0xA2,0x32,0x06,0xF9,0xC4,0xF2,    /* x */
+         0x99,0xD7,0xB2,0x1A,0x9C,0x36,0x91,0x37,0xF2,0xC8,
+         0x4A,0xE1,0xAA,0x0D,
+         0x76,0x5B,0xE7,0x34,0x33,0xB3,0xF9,0x5E,0x33,0x29,    /* y */
+         0x32,0xE7,0x0E,0xA2,0x45,0xCA,0x24,0x18,0xEA,0x0E,
+         0xF9,0x80,0x18,0xFB,
+         0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* order */
+         0x00,0x00,0x04,0xA2,0x0E,0x90,0xC3,0x90,0x67,0xC8,
+         0x93,0xBB,0xB9,0xA5 }
        };
 
-static const unsigned char _EC_X9_62_CHAR2_191V2_SEED[] = {
-       0x08,0x71,0xEF,0x2F,0xEF,0x24,0xD6,0x96,0xE6,0x76,
-       0x87,0x56,0x15,0x17,0x58,0xBE,0xE0,0xD9,0x5C,0x15};
-static const EC_CURVE_DATA _EC_X9_62_CHAR2_191V2 = {
-       NID_X9_62_characteristic_two_field,
-       "800000000000000000000000000000000000000000000201",
-       "401028774D7777C7B7666D1366EA432071274F89FF01E718",
-       "0620048D28BCBD03B6249C99182B7C8CD19700C362C46A01",
-       "3809B2B7CC1B28CC5A87926AAD83FD28789E81E2C9E3BF10",
-       "17434386626D14F3DBF01760D9213A3E1CF37AEC437D668A",
-       "20000000000000000000000050508CB89F652824E06B8173", 4,
-       _EC_X9_62_CHAR2_191V2_SEED, 20,
-       "X9.62 curve over a 191 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+24*6]; }
+       _EC_X9_62_CHAR2_191V2 = {
+       { NID_X9_62_characteristic_two_field,20,24,4 },
+       { 0x08,0x71,0xEF,0x2F,0xEF,0x24,0xD6,0x96,0xE6,0x76,    /* seed */
+         0x87,0x56,0x15,0x17,0x58,0xBE,0xE0,0xD9,0x5C,0x15,
+
+         0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x02,0x01,
+         0x40,0x10,0x28,0x77,0x4D,0x77,0x77,0xC7,0xB7,0x66,    /* a */
+         0x6D,0x13,0x66,0xEA,0x43,0x20,0x71,0x27,0x4F,0x89,
+         0xFF,0x01,0xE7,0x18,
+         0x06,0x20,0x04,0x8D,0x28,0xBC,0xBD,0x03,0xB6,0x24,    /* b */
+         0x9C,0x99,0x18,0x2B,0x7C,0x8C,0xD1,0x97,0x00,0xC3,
+         0x62,0xC4,0x6A,0x01,
+         0x38,0x09,0xB2,0xB7,0xCC,0x1B,0x28,0xCC,0x5A,0x87,    /* x */
+         0x92,0x6A,0xAD,0x83,0xFD,0x28,0x78,0x9E,0x81,0xE2,
+         0xC9,0xE3,0xBF,0x10,
+         0x17,0x43,0x43,0x86,0x62,0x6D,0x14,0xF3,0xDB,0xF0,    /* y */
+         0x17,0x60,0xD9,0x21,0x3A,0x3E,0x1C,0xF3,0x7A,0xEC,
+         0x43,0x7D,0x66,0x8A,
+         0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* order */
+         0x00,0x00,0x50,0x50,0x8C,0xB8,0x9F,0x65,0x28,0x24,
+         0xE0,0x6B,0x81,0x73 }
        };
 
-static const unsigned char _EC_X9_62_CHAR2_191V3_SEED[] = {
-       0xE0,0x53,0x51,0x2D,0xC6,0x84,0xD6,0x96,0xE6,0x76,
-       0x87,0x56,0x15,0x17,0x50,0x67,0xAE,0x78,0x6D,0x1F};
-static const EC_CURVE_DATA _EC_X9_62_CHAR2_191V3 = {
-       NID_X9_62_characteristic_two_field,
-       "800000000000000000000000000000000000000000000201",
-       "6C01074756099122221056911C77D77E77A777E7E7E77FCB",
-       "71FE1AF926CF847989EFEF8DB459F66394D90F32AD3F15E8",
-       "375D4CE24FDE434489DE8746E71786015009E66E38A926DD",
-       "545A39176196575D985999366E6AD34CE0A77CD7127B06BE",
-       "155555555555555555555555610C0B196812BFB6288A3EA3", 6,
-       _EC_X9_62_CHAR2_191V3_SEED, 20,
-       "X9.62 curve over a 191 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+24*6]; }
+       _EC_X9_62_CHAR2_191V3 = {
+       { NID_X9_62_characteristic_two_field,20,24,6 },
+       { 0xE0,0x53,0x51,0x2D,0xC6,0x84,0xD6,0x96,0xE6,0x76,    /* seed */
+         0x87,0x56,0x15,0x17,0x50,0x67,0xAE,0x78,0x6D,0x1F,
+
+         0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x02,0x01,
+         0x6C,0x01,0x07,0x47,0x56,0x09,0x91,0x22,0x22,0x10,    /* a */
+         0x56,0x91,0x1C,0x77,0xD7,0x7E,0x77,0xA7,0x77,0xE7,
+         0xE7,0xE7,0x7F,0xCB,
+         0x71,0xFE,0x1A,0xF9,0x26,0xCF,0x84,0x79,0x89,0xEF,    /* b */
+         0xEF,0x8D,0xB4,0x59,0xF6,0x63,0x94,0xD9,0x0F,0x32,
+         0xAD,0x3F,0x15,0xE8,
+         0x37,0x5D,0x4C,0xE2,0x4F,0xDE,0x43,0x44,0x89,0xDE,    /* x */
+         0x87,0x46,0xE7,0x17,0x86,0x01,0x50,0x09,0xE6,0x6E,
+         0x38,0xA9,0x26,0xDD,
+         0x54,0x5A,0x39,0x17,0x61,0x96,0x57,0x5D,0x98,0x59,    /* y */
+         0x99,0x36,0x6E,0x6A,0xD3,0x4C,0xE0,0xA7,0x7C,0xD7,
+         0x12,0x7B,0x06,0xBE,
+         0x15,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,    /* order */
+         0x55,0x55,0x61,0x0C,0x0B,0x19,0x68,0x12,0xBF,0xB6,
+         0x28,0x8A,0x3E,0xA3 }
        };
 
-static const EC_CURVE_DATA _EC_X9_62_CHAR2_208W1 = {
-       NID_X9_62_characteristic_two_field,
-       "010000000000000000000000000000000800000000000000000007",
-       "0000000000000000000000000000000000000000000000000000",
-       "C8619ED45A62E6212E1160349E2BFA844439FAFC2A3FD1638F9E",
-       "89FDFBE4ABE193DF9559ECF07AC0CE78554E2784EB8C1ED1A57A",
-       "0F55B51A06E78E9AC38A035FF520D8B01781BEB1A6BB08617DE3",
-       "000101BAF95C9723C57B6C21DA2EFF2D5ED588BDD5717E212F9D", 0xFE48,
-       NULL, 0,
-       "X9.62 curve over a 208 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[0+27*6]; }
+       _EC_X9_62_CHAR2_208W1 = {
+       { NID_X9_62_characteristic_two_field,0,27,0xFE48 },
+       {                                                       /* no seed */
+         0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x07,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* a */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0xC8,0x61,0x9E,0xD4,0x5A,0x62,0xE6,0x21,0x2E,    /* b */
+         0x11,0x60,0x34,0x9E,0x2B,0xFA,0x84,0x44,0x39,0xFA,
+         0xFC,0x2A,0x3F,0xD1,0x63,0x8F,0x9E,
+         0x00,0x89,0xFD,0xFB,0xE4,0xAB,0xE1,0x93,0xDF,0x95,    /* x */
+         0x59,0xEC,0xF0,0x7A,0xC0,0xCE,0x78,0x55,0x4E,0x27,
+         0x84,0xEB,0x8C,0x1E,0xD1,0xA5,0x7A,
+         0x00,0x0F,0x55,0xB5,0x1A,0x06,0xE7,0x8E,0x9A,0xC3,    /* y */
+         0x8A,0x03,0x5F,0xF5,0x20,0xD8,0xB0,0x17,0x81,0xBE,
+         0xB1,0xA6,0xBB,0x08,0x61,0x7D,0xE3,
+         0x00,0x00,0x01,0x01,0xBA,0xF9,0x5C,0x97,0x23,0xC5,    /* order */
+         0x7B,0x6C,0x21,0xDA,0x2E,0xFF,0x2D,0x5E,0xD5,0x88,
+         0xBD,0xD5,0x71,0x7E,0x21,0x2F,0x9D }
        };
 
-static const unsigned char _EC_X9_62_CHAR2_239V1_SEED[] = {
-       0xD3,0x4B,0x9A,0x4D,0x69,0x6E,0x67,0x68,0x75,0x61,
-       0x51,0x75,0xCA,0x71,0xB9,0x20,0xBF,0xEF,0xB0,0x5D};
-static const EC_CURVE_DATA _EC_X9_62_CHAR2_239V1 = {
-       NID_X9_62_characteristic_two_field,
-       "800000000000000000000000000000000000000000000000001000000001",
-       "32010857077C5431123A46B808906756F543423E8D27877578125778AC76",
-       "790408F2EEDAF392B012EDEFB3392F30F4327C0CA3F31FC383C422AA8C16",
-       "57927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D",
-       "61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305",
-       "2000000000000000000000000000000F4D42FFE1492A4993F1CAD666E447", 4,
-       _EC_X9_62_CHAR2_239V1_SEED, 20,
-       "X9.62 curve over a 239 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+30*6]; }
+       _EC_X9_62_CHAR2_239V1 = {
+       { NID_X9_62_characteristic_two_field,20,30,4 },
+       { 0xD3,0x4B,0x9A,0x4D,0x69,0x6E,0x67,0x68,0x75,0x61,    /* seed */
+         0x51,0x75,0xCA,0x71,0xB9,0x20,0xBF,0xEF,0xB0,0x5D,
+
+         0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x01,
+
+         0x32,0x01,0x08,0x57,0x07,0x7C,0x54,0x31,0x12,0x3A,    /* a */
+         0x46,0xB8,0x08,0x90,0x67,0x56,0xF5,0x43,0x42,0x3E,
+         0x8D,0x27,0x87,0x75,0x78,0x12,0x57,0x78,0xAC,0x76,
+
+         0x79,0x04,0x08,0xF2,0xEE,0xDA,0xF3,0x92,0xB0,0x12,    /* b */
+         0xED,0xEF,0xB3,0x39,0x2F,0x30,0xF4,0x32,0x7C,0x0C,
+         0xA3,0xF3,0x1F,0xC3,0x83,0xC4,0x22,0xAA,0x8C,0x16,
+
+         0x57,0x92,0x70,0x98,0xFA,0x93,0x2E,0x7C,0x0A,0x96,    /* x */
+         0xD3,0xFD,0x5B,0x70,0x6E,0xF7,0xE5,0xF5,0xC1,0x56,
+         0xE1,0x6B,0x7E,0x7C,0x86,0x03,0x85,0x52,0xE9,0x1D,
+
+         0x61,0xD8,0xEE,0x50,0x77,0xC3,0x3F,0xEC,0xF6,0xF1,    /* y */
+         0xA1,0x6B,0x26,0x8D,0xE4,0x69,0xC3,0xC7,0x74,0x4E,
+         0xA9,0xA9,0x71,0x64,0x9F,0xC7,0xA9,0x61,0x63,0x05,
+
+         0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* order */
+         0x00,0x00,0x00,0x00,0x00,0x0F,0x4D,0x42,0xFF,0xE1,
+         0x49,0x2A,0x49,0x93,0xF1,0xCA,0xD6,0x66,0xE4,0x47 }
        };
 
-static const unsigned char _EC_X9_62_CHAR2_239V2_SEED[] = {
-       0x2A,0xA6,0x98,0x2F,0xDF,0xA4,0xD6,0x96,0xE6,0x76,
-       0x87,0x56,0x15,0x17,0x5D,0x26,0x67,0x27,0x27,0x7D};
-static const EC_CURVE_DATA _EC_X9_62_CHAR2_239V2 = {
-       NID_X9_62_characteristic_two_field,
-       "800000000000000000000000000000000000000000000000001000000001",
-       "4230017757A767FAE42398569B746325D45313AF0766266479B75654E65F",
-       "5037EA654196CFF0CD82B2C14A2FCF2E3FF8775285B545722F03EACDB74B",
-       "28F9D04E900069C8DC47A08534FE76D2B900B7D7EF31F5709F200C4CA205",
-       "5667334C45AFF3B5A03BAD9DD75E2C71A99362567D5453F7FA6E227EC833",
-       "1555555555555555555555555555553C6F2885259C31E3FCDF154624522D", 6,
-       _EC_X9_62_CHAR2_239V2_SEED, 20,
-       "X9.62 curve over a 239 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+30*6]; }
+       _EC_X9_62_CHAR2_239V2 = {
+       { NID_X9_62_characteristic_two_field,20,30,6 },
+       { 0x2A,0xA6,0x98,0x2F,0xDF,0xA4,0xD6,0x96,0xE6,0x76,    /* seed */
+         0x87,0x56,0x15,0x17,0x5D,0x26,0x67,0x27,0x27,0x7D,
+
+         0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x01,
+
+         0x42,0x30,0x01,0x77,0x57,0xA7,0x67,0xFA,0xE4,0x23,    /* a */
+         0x98,0x56,0x9B,0x74,0x63,0x25,0xD4,0x53,0x13,0xAF,
+         0x07,0x66,0x26,0x64,0x79,0xB7,0x56,0x54,0xE6,0x5F,
+
+         0x50,0x37,0xEA,0x65,0x41,0x96,0xCF,0xF0,0xCD,0x82,    /* b */
+         0xB2,0xC1,0x4A,0x2F,0xCF,0x2E,0x3F,0xF8,0x77,0x52,
+         0x85,0xB5,0x45,0x72,0x2F,0x03,0xEA,0xCD,0xB7,0x4B,
+
+         0x28,0xF9,0xD0,0x4E,0x90,0x00,0x69,0xC8,0xDC,0x47,    /* x */
+         0xA0,0x85,0x34,0xFE,0x76,0xD2,0xB9,0x00,0xB7,0xD7,
+         0xEF,0x31,0xF5,0x70,0x9F,0x20,0x0C,0x4C,0xA2,0x05,
+
+         0x56,0x67,0x33,0x4C,0x45,0xAF,0xF3,0xB5,0xA0,0x3B,    /* y */
+         0xAD,0x9D,0xD7,0x5E,0x2C,0x71,0xA9,0x93,0x62,0x56,
+         0x7D,0x54,0x53,0xF7,0xFA,0x6E,0x22,0x7E,0xC8,0x33,
+
+         0x15,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,    /* order */
+         0x55,0x55,0x55,0x55,0x55,0x3C,0x6F,0x28,0x85,0x25,
+         0x9C,0x31,0xE3,0xFC,0xDF,0x15,0x46,0x24,0x52,0x2D }
        };
 
-static const unsigned char _EC_X9_62_CHAR2_239V3_SEED[] = {
-       0x9E,0x07,0x6F,0x4D,0x69,0x6E,0x67,0x68,0x75,0x61,
-       0x51,0x75,0xE1,0x1E,0x9F,0xDD,0x77,0xF9,0x20,0x41};
-static const EC_CURVE_DATA _EC_X9_62_CHAR2_239V3 = {
-       NID_X9_62_characteristic_two_field,
-       "800000000000000000000000000000000000000000000000001000000001",
-       "01238774666A67766D6676F778E676B66999176666E687666D8766C66A9F",
-       "6A941977BA9F6A435199ACFC51067ED587F519C5ECB541B8E44111DE1D40",
-       "70F6E9D04D289C4E89913CE3530BFDE903977D42B146D539BF1BDE4E9C92",
-       "2E5A0EAF6E5E1305B9004DCE5C0ED7FE59A35608F33837C816D80B79F461",
-       "0CCCCCCCCCCCCCCCCCCCCCCCCCCCCCAC4912D2D9DF903EF9888B8A0E4CFF", 0xA,
-       _EC_X9_62_CHAR2_239V3_SEED, 20,
-       "X9.62 curve over a 239 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+30*6]; }
+       _EC_X9_62_CHAR2_239V3 = {
+       { NID_X9_62_characteristic_two_field,20,30,0xA },
+       { 0x9E,0x07,0x6F,0x4D,0x69,0x6E,0x67,0x68,0x75,0x61,    /* seed */
+         0x51,0x75,0xE1,0x1E,0x9F,0xDD,0x77,0xF9,0x20,0x41,
+
+         0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x01,
+
+         0x01,0x23,0x87,0x74,0x66,0x6A,0x67,0x76,0x6D,0x66,    /* a */
+         0x76,0xF7,0x78,0xE6,0x76,0xB6,0x69,0x99,0x17,0x66,
+         0x66,0xE6,0x87,0x66,0x6D,0x87,0x66,0xC6,0x6A,0x9F,
+
+         0x6A,0x94,0x19,0x77,0xBA,0x9F,0x6A,0x43,0x51,0x99,    /* b */
+         0xAC,0xFC,0x51,0x06,0x7E,0xD5,0x87,0xF5,0x19,0xC5,
+         0xEC,0xB5,0x41,0xB8,0xE4,0x41,0x11,0xDE,0x1D,0x40,
+
+         0x70,0xF6,0xE9,0xD0,0x4D,0x28,0x9C,0x4E,0x89,0x91,    /* x */
+         0x3C,0xE3,0x53,0x0B,0xFD,0xE9,0x03,0x97,0x7D,0x42,
+         0xB1,0x46,0xD5,0x39,0xBF,0x1B,0xDE,0x4E,0x9C,0x92,
+
+         0x2E,0x5A,0x0E,0xAF,0x6E,0x5E,0x13,0x05,0xB9,0x00,    /* y */
+         0x4D,0xCE,0x5C,0x0E,0xD7,0xFE,0x59,0xA3,0x56,0x08,
+         0xF3,0x38,0x37,0xC8,0x16,0xD8,0x0B,0x79,0xF4,0x61,
+
+         0x0C,0xCC,0xCC,0xCC,0xCC,0xCC,0xCC,0xCC,0xCC,0xCC,    /* order */
+         0xCC,0xCC,0xCC,0xCC,0xCC,0xAC,0x49,0x12,0xD2,0xD9,
+         0xDF,0x90,0x3E,0xF9,0x88,0x8B,0x8A,0x0E,0x4C,0xFF }
        };
 
-static const EC_CURVE_DATA _EC_X9_62_CHAR2_272W1 = {
-       NID_X9_62_characteristic_two_field,
-       "010000000000000000000000000000000000000000000000000000010000000000000"
-       "B",
-       "91A091F03B5FBA4AB2CCF49C4EDD220FB028712D42BE752B2C40094DBACDB586FB20",
-       "7167EFC92BB2E3CE7C8AAAFF34E12A9C557003D7C73A6FAF003F99F6CC8482E540F7",
-       "6108BABB2CEEBCF787058A056CBE0CFE622D7723A289E08A07AE13EF0D10D171DD8D",
-       "10C7695716851EEF6BA7F6872E6142FBD241B830FF5EFCACECCAB05E02005DDE9D23",
-       "000100FAF51354E0E39E4892DF6E319C72C8161603FA45AA7B998A167B8F1E629521",
-       0xFF06,
-       NULL, 0,
-       "X9.62 curve over a 272 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[0+35*6]; }
+       _EC_X9_62_CHAR2_272W1 = {
+       { NID_X9_62_characteristic_two_field,0,35,0xFF06 },
+       {                                                       /* no seed */
+         0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x0B,
+         0x00,0x91,0xA0,0x91,0xF0,0x3B,0x5F,0xBA,0x4A,0xB2,    /* a */
+         0xCC,0xF4,0x9C,0x4E,0xDD,0x22,0x0F,0xB0,0x28,0x71,
+         0x2D,0x42,0xBE,0x75,0x2B,0x2C,0x40,0x09,0x4D,0xBA,
+         0xCD,0xB5,0x86,0xFB,0x20,
+         0x00,0x71,0x67,0xEF,0xC9,0x2B,0xB2,0xE3,0xCE,0x7C,    /* b */
+         0x8A,0xAA,0xFF,0x34,0xE1,0x2A,0x9C,0x55,0x70,0x03,
+         0xD7,0xC7,0x3A,0x6F,0xAF,0x00,0x3F,0x99,0xF6,0xCC,
+         0x84,0x82,0xE5,0x40,0xF7,
+         0x00,0x61,0x08,0xBA,0xBB,0x2C,0xEE,0xBC,0xF7,0x87,    /* x */
+         0x05,0x8A,0x05,0x6C,0xBE,0x0C,0xFE,0x62,0x2D,0x77,
+         0x23,0xA2,0x89,0xE0,0x8A,0x07,0xAE,0x13,0xEF,0x0D,
+         0x10,0xD1,0x71,0xDD,0x8D,
+         0x00,0x10,0xC7,0x69,0x57,0x16,0x85,0x1E,0xEF,0x6B,    /* y */
+         0xA7,0xF6,0x87,0x2E,0x61,0x42,0xFB,0xD2,0x41,0xB8,
+         0x30,0xFF,0x5E,0xFC,0xAC,0xEC,0xCA,0xB0,0x5E,0x02,
+         0x00,0x5D,0xDE,0x9D,0x23,
+         0x00,0x00,0x01,0x00,0xFA,0xF5,0x13,0x54,0xE0,0xE3,    /* order */
+         0x9E,0x48,0x92,0xDF,0x6E,0x31,0x9C,0x72,0xC8,0x16,
+         0x16,0x03,0xFA,0x45,0xAA,0x7B,0x99,0x8A,0x16,0x7B,
+         0x8F,0x1E,0x62,0x95,0x21 }
        };
 
-static const EC_CURVE_DATA _EC_X9_62_CHAR2_304W1 = {
-       NID_X9_62_characteristic_two_field,
-       "010000000000000000000000000000000000000000000000000000000000000000000"
-       "000000807",
-       "FD0D693149A118F651E6DCE6802085377E5F882D1B510B44160074C1288078365A039"
-       "6C8E681",
-       "BDDB97E555A50A908E43B01C798EA5DAA6788F1EA2794EFCF57166B8C14039601E558"
-       "27340BE",
-       "197B07845E9BE2D96ADB0F5F3C7F2CFFBD7A3EB8B6FEC35C7FD67F26DDF6285A644F7"
-       "40A2614",
-       "E19FBEB76E0DA171517ECF401B50289BF014103288527A9B416A105E80260B549FDC1"
-       "B92C03B",
-       "000101D556572AABAC800101D556572AABAC8001022D5C91DD173F8FB561DA6899164"
-       "443051D", 0xFE2E,
-       NULL, 0,
-       "X9.62 curve over a 304 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[0+39*6]; }
+       _EC_X9_62_CHAR2_304W1 = {
+       { NID_X9_62_characteristic_two_field,0,39,0xFE2E },
+       {                                                       /* no seed */
+         0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x07,
+         0x00,0xFD,0x0D,0x69,0x31,0x49,0xA1,0x18,0xF6,0x51,    /* a */
+         0xE6,0xDC,0xE6,0x80,0x20,0x85,0x37,0x7E,0x5F,0x88,
+         0x2D,0x1B,0x51,0x0B,0x44,0x16,0x00,0x74,0xC1,0x28,
+         0x80,0x78,0x36,0x5A,0x03,0x96,0xC8,0xE6,0x81,
+         0x00,0xBD,0xDB,0x97,0xE5,0x55,0xA5,0x0A,0x90,0x8E,    /* b */
+         0x43,0xB0,0x1C,0x79,0x8E,0xA5,0xDA,0xA6,0x78,0x8F,
+         0x1E,0xA2,0x79,0x4E,0xFC,0xF5,0x71,0x66,0xB8,0xC1,
+         0x40,0x39,0x60,0x1E,0x55,0x82,0x73,0x40,0xBE,
+         0x00,0x19,0x7B,0x07,0x84,0x5E,0x9B,0xE2,0xD9,0x6A,    /* x */
+         0xDB,0x0F,0x5F,0x3C,0x7F,0x2C,0xFF,0xBD,0x7A,0x3E,
+         0xB8,0xB6,0xFE,0xC3,0x5C,0x7F,0xD6,0x7F,0x26,0xDD,
+         0xF6,0x28,0x5A,0x64,0x4F,0x74,0x0A,0x26,0x14,
+         0x00,0xE1,0x9F,0xBE,0xB7,0x6E,0x0D,0xA1,0x71,0x51,    /* y */
+         0x7E,0xCF,0x40,0x1B,0x50,0x28,0x9B,0xF0,0x14,0x10,
+         0x32,0x88,0x52,0x7A,0x9B,0x41,0x6A,0x10,0x5E,0x80,
+         0x26,0x0B,0x54,0x9F,0xDC,0x1B,0x92,0xC0,0x3B,
+         0x00,0x00,0x01,0x01,0xD5,0x56,0x57,0x2A,0xAB,0xAC,    /* order */
+         0x80,0x01,0x01,0xD5,0x56,0x57,0x2A,0xAB,0xAC,0x80,
+         0x01,0x02,0x2D,0x5C,0x91,0xDD,0x17,0x3F,0x8F,0xB5,
+         0x61,0xDA,0x68,0x99,0x16,0x44,0x43,0x05,0x1D }
        };
 
-static const unsigned char _EC_X9_62_CHAR2_359V1_SEED[] = {
-       0x2B,0x35,0x49,0x20,0xB7,0x24,0xD6,0x96,0xE6,0x76,
-       0x87,0x56,0x15,0x17,0x58,0x5B,0xA1,0x33,0x2D,0xC6};
-static const EC_CURVE_DATA _EC_X9_62_CHAR2_359V1 = {
-       NID_X9_62_characteristic_two_field,
-       "800000000000000000000000000000000000000000000000000000000000000000000"
-       "000100000000000000001",
-       "5667676A654B20754F356EA92017D946567C46675556F19556A04616B567D223A5E05"
-       "656FB549016A96656A557",
-       "2472E2D0197C49363F1FE7F5B6DB075D52B6947D135D8CA445805D39BC34562608968"
-       "7742B6329E70680231988",
-       "3C258EF3047767E7EDE0F1FDAA79DAEE3841366A132E163ACED4ED2401DF9C6BDCDE9"
-       "8E8E707C07A2239B1B097",
-       "53D7E08529547048121E9C95F3791DD804963948F34FAE7BF44EA82365DC7868FE57E"
-       "4AE2DE211305A407104BD",
-       "01AF286BCA1AF286BCA1AF286BCA1AF286BCA1AF286BC9FB8F6B85C556892C20A7EB9"
-       "64FE7719E74F490758D3B", 0x4C,
-       _EC_X9_62_CHAR2_359V1_SEED, 20,
-       "X9.62 curve over a 359 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[20+45*6]; }
+       _EC_X9_62_CHAR2_359V1 = {
+       { NID_X9_62_characteristic_two_field,20,45,0x4C },
+       { 0x2B,0x35,0x49,0x20,0xB7,0x24,0xD6,0x96,0xE6,0x76,    /* seed */
+         0x87,0x56,0x15,0x17,0x58,0x5B,0xA1,0x33,0x2D,0xC6,
+
+         0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x01,
+         0x56,0x67,0x67,0x6A,0x65,0x4B,0x20,0x75,0x4F,0x35,    /* a */
+         0x6E,0xA9,0x20,0x17,0xD9,0x46,0x56,0x7C,0x46,0x67,
+         0x55,0x56,0xF1,0x95,0x56,0xA0,0x46,0x16,0xB5,0x67,
+         0xD2,0x23,0xA5,0xE0,0x56,0x56,0xFB,0x54,0x90,0x16,
+         0xA9,0x66,0x56,0xA5,0x57,
+         0x24,0x72,0xE2,0xD0,0x19,0x7C,0x49,0x36,0x3F,0x1F,    /* b */
+         0xE7,0xF5,0xB6,0xDB,0x07,0x5D,0x52,0xB6,0x94,0x7D,
+         0x13,0x5D,0x8C,0xA4,0x45,0x80,0x5D,0x39,0xBC,0x34,
+         0x56,0x26,0x08,0x96,0x87,0x74,0x2B,0x63,0x29,0xE7,
+         0x06,0x80,0x23,0x19,0x88,
+         0x3C,0x25,0x8E,0xF3,0x04,0x77,0x67,0xE7,0xED,0xE0,    /* x */
+         0xF1,0xFD,0xAA,0x79,0xDA,0xEE,0x38,0x41,0x36,0x6A,
+         0x13,0x2E,0x16,0x3A,0xCE,0xD4,0xED,0x24,0x01,0xDF,
+         0x9C,0x6B,0xDC,0xDE,0x98,0xE8,0xE7,0x07,0xC0,0x7A,
+         0x22,0x39,0xB1,0xB0,0x97,
+         0x53,0xD7,0xE0,0x85,0x29,0x54,0x70,0x48,0x12,0x1E,    /* y */
+         0x9C,0x95,0xF3,0x79,0x1D,0xD8,0x04,0x96,0x39,0x48,
+         0xF3,0x4F,0xAE,0x7B,0xF4,0x4E,0xA8,0x23,0x65,0xDC,
+         0x78,0x68,0xFE,0x57,0xE4,0xAE,0x2D,0xE2,0x11,0x30,
+         0x5A,0x40,0x71,0x04,0xBD,
+         0x01,0xAF,0x28,0x6B,0xCA,0x1A,0xF2,0x86,0xBC,0xA1,    /* order */
+         0xAF,0x28,0x6B,0xCA,0x1A,0xF2,0x86,0xBC,0xA1,0xAF,
+         0x28,0x6B,0xC9,0xFB,0x8F,0x6B,0x85,0xC5,0x56,0x89,
+         0x2C,0x20,0xA7,0xEB,0x96,0x4F,0xE7,0x71,0x9E,0x74,
+         0xF4,0x90,0x75,0x8D,0x3B }
        };
 
-static const EC_CURVE_DATA _EC_X9_62_CHAR2_368W1 = {
-       NID_X9_62_characteristic_two_field,
-       "010000000000000000000000000000000000000000000000000000000000000000000"
-       "0002000000000000000000007",
-       "E0D2EE25095206F5E2A4F9ED229F1F256E79A0E2B455970D8D0D865BD94778C576D62"
-       "F0AB7519CCD2A1A906AE30D",
-       "FC1217D4320A90452C760A58EDCD30C8DD069B3C34453837A34ED50CB54917E1C2112"
-       "D84D164F444F8F74786046A",
-       "1085E2755381DCCCE3C1557AFA10C2F0C0C2825646C5B34A394CBCFA8BC16B22E7E78"
-       "9E927BE216F02E1FB136A5F",
-       "7B3EB1BDDCBA62D5D8B2059B525797FC73822C59059C623A45FF3843CEE8F87CD1855"
-       "ADAA81E2A0750B80FDA2310",
-       "00010090512DA9AF72B08349D98A5DD4C7B0532ECA51CE03E2D10F3B7AC579BD87E90"
-       "9AE40A6F131E9CFCE5BD967", 0xFF70,
-       NULL, 0,
-       "X9.62 curve over a 368 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[0+47*6]; }
+       _EC_X9_62_CHAR2_368W1 = {
+       { NID_X9_62_characteristic_two_field,0,47,0xFF70 },
+       {                                                       /* no seed */
+         0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x07,
+         0x00,0xE0,0xD2,0xEE,0x25,0x09,0x52,0x06,0xF5,0xE2,    /* a */
+         0xA4,0xF9,0xED,0x22,0x9F,0x1F,0x25,0x6E,0x79,0xA0,
+         0xE2,0xB4,0x55,0x97,0x0D,0x8D,0x0D,0x86,0x5B,0xD9,
+         0x47,0x78,0xC5,0x76,0xD6,0x2F,0x0A,0xB7,0x51,0x9C,
+         0xCD,0x2A,0x1A,0x90,0x6A,0xE3,0x0D,
+         0x00,0xFC,0x12,0x17,0xD4,0x32,0x0A,0x90,0x45,0x2C,    /* b */
+         0x76,0x0A,0x58,0xED,0xCD,0x30,0xC8,0xDD,0x06,0x9B,
+         0x3C,0x34,0x45,0x38,0x37,0xA3,0x4E,0xD5,0x0C,0xB5,
+         0x49,0x17,0xE1,0xC2,0x11,0x2D,0x84,0xD1,0x64,0xF4,
+         0x44,0xF8,0xF7,0x47,0x86,0x04,0x6A,
+         0x00,0x10,0x85,0xE2,0x75,0x53,0x81,0xDC,0xCC,0xE3,    /* x */
+         0xC1,0x55,0x7A,0xFA,0x10,0xC2,0xF0,0xC0,0xC2,0x82,
+         0x56,0x46,0xC5,0xB3,0x4A,0x39,0x4C,0xBC,0xFA,0x8B,
+         0xC1,0x6B,0x22,0xE7,0xE7,0x89,0xE9,0x27,0xBE,0x21,
+         0x6F,0x02,0xE1,0xFB,0x13,0x6A,0x5F,
+         0x00,0x7B,0x3E,0xB1,0xBD,0xDC,0xBA,0x62,0xD5,0xD8,    /* y */
+         0xB2,0x05,0x9B,0x52,0x57,0x97,0xFC,0x73,0x82,0x2C,
+         0x59,0x05,0x9C,0x62,0x3A,0x45,0xFF,0x38,0x43,0xCE,
+         0xE8,0xF8,0x7C,0xD1,0x85,0x5A,0xDA,0xA8,0x1E,0x2A,
+         0x07,0x50,0xB8,0x0F,0xDA,0x23,0x10,
+         0x00,0x00,0x01,0x00,0x90,0x51,0x2D,0xA9,0xAF,0x72,    /* order */
+         0xB0,0x83,0x49,0xD9,0x8A,0x5D,0xD4,0xC7,0xB0,0x53,
+         0x2E,0xCA,0x51,0xCE,0x03,0xE2,0xD1,0x0F,0x3B,0x7A,
+         0xC5,0x79,0xBD,0x87,0xE9,0x09,0xAE,0x40,0xA6,0xF1,
+         0x31,0xE9,0xCF,0xCE,0x5B,0xD9,0x67 }
        };
 
-static const EC_CURVE_DATA _EC_X9_62_CHAR2_431R1 = {
-       NID_X9_62_characteristic_two_field,
-       "800000000000000000000000000000000000000000000000000000000000000000000"
-       "000000001000000000000000000000000000001",
-       "1A827EF00DD6FC0E234CAF046C6A5D8A85395B236CC4AD2CF32A0CADBDC9DDF620B0E"
-       "B9906D0957F6C6FEACD615468DF104DE296CD8F",
-       "10D9B4A3D9047D8B154359ABFB1B7F5485B04CEB868237DDC9DEDA982A679A5A919B6"
-       "26D4E50A8DD731B107A9962381FB5D807BF2618",
-       "120FC05D3C67A99DE161D2F4092622FECA701BE4F50F4758714E8A87BBF2A658EF8C2"
-       "1E7C5EFE965361F6C2999C0C247B0DBD70CE6B7",
-       "20D0AF8903A96F8D5FA2C255745D3C451B302C9346D9B7E485E7BCE41F6B591F3E8F6"
-       "ADDCBB0BC4C2F947A7DE1A89B625D6A598B3760",
-       "0340340340340340340340340340340340340340340340340340340323C313FAB5058"
-       "9703B5EC68D3587FEC60D161CC149C1AD4A91", 0x2760,
-       NULL, 0,
-       "X9.62 curve over a 431 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[0+54*6]; }
+       _EC_X9_62_CHAR2_431R1 = {
+       { NID_X9_62_characteristic_two_field,0,54,0x2760 },
+       {                                                       /* no seed */
+         0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x01,
+         0x1A,0x82,0x7E,0xF0,0x0D,0xD6,0xFC,0x0E,0x23,0x4C,    /* a */
+         0xAF,0x04,0x6C,0x6A,0x5D,0x8A,0x85,0x39,0x5B,0x23,
+         0x6C,0xC4,0xAD,0x2C,0xF3,0x2A,0x0C,0xAD,0xBD,0xC9,
+         0xDD,0xF6,0x20,0xB0,0xEB,0x99,0x06,0xD0,0x95,0x7F,
+         0x6C,0x6F,0xEA,0xCD,0x61,0x54,0x68,0xDF,0x10,0x4D,
+         0xE2,0x96,0xCD,0x8F,
+         0x10,0xD9,0xB4,0xA3,0xD9,0x04,0x7D,0x8B,0x15,0x43,    /* b */
+         0x59,0xAB,0xFB,0x1B,0x7F,0x54,0x85,0xB0,0x4C,0xEB,
+         0x86,0x82,0x37,0xDD,0xC9,0xDE,0xDA,0x98,0x2A,0x67,
+         0x9A,0x5A,0x91,0x9B,0x62,0x6D,0x4E,0x50,0xA8,0xDD,
+         0x73,0x1B,0x10,0x7A,0x99,0x62,0x38,0x1F,0xB5,0xD8,
+         0x07,0xBF,0x26,0x18,
+         0x12,0x0F,0xC0,0x5D,0x3C,0x67,0xA9,0x9D,0xE1,0x61,    /* x */
+         0xD2,0xF4,0x09,0x26,0x22,0xFE,0xCA,0x70,0x1B,0xE4,
+         0xF5,0x0F,0x47,0x58,0x71,0x4E,0x8A,0x87,0xBB,0xF2,
+         0xA6,0x58,0xEF,0x8C,0x21,0xE7,0xC5,0xEF,0xE9,0x65,
+         0x36,0x1F,0x6C,0x29,0x99,0xC0,0xC2,0x47,0xB0,0xDB,
+         0xD7,0x0C,0xE6,0xB7,
+         0x20,0xD0,0xAF,0x89,0x03,0xA9,0x6F,0x8D,0x5F,0xA2,    /* y */
+         0xC2,0x55,0x74,0x5D,0x3C,0x45,0x1B,0x30,0x2C,0x93,
+         0x46,0xD9,0xB7,0xE4,0x85,0xE7,0xBC,0xE4,0x1F,0x6B,
+         0x59,0x1F,0x3E,0x8F,0x6A,0xDD,0xCB,0xB0,0xBC,0x4C,
+         0x2F,0x94,0x7A,0x7D,0xE1,0xA8,0x9B,0x62,0x5D,0x6A,
+         0x59,0x8B,0x37,0x60,
+         0x00,0x03,0x40,0x34,0x03,0x40,0x34,0x03,0x40,0x34,    /* order */
+         0x03,0x40,0x34,0x03,0x40,0x34,0x03,0x40,0x34,0x03,
+         0x40,0x34,0x03,0x40,0x34,0x03,0x40,0x34,0x03,0x23,
+         0xC3,0x13,0xFA,0xB5,0x05,0x89,0x70,0x3B,0x5E,0xC6,
+         0x8D,0x35,0x87,0xFE,0xC6,0x0D,0x16,0x1C,0xC1,0x49,
+         0xC1,0xAD,0x4A,0x91 }
        };
 
-static const EC_CURVE_DATA _EC_WTLS_1 = {
-       NID_X9_62_characteristic_two_field,
-       "020000000000000000000000000201",
-       "1",
-       "1",
-       "01667979A40BA497E5D5C270780617",
-       "00F44B4AF1ECC2630E08785CEBCC15",
-       "00FFFFFFFFFFFFFFFDBF91AF6DEA73", 2,
-       NULL, 0,
-       "WTLS curve over a 113 bit binary field"
+static const struct { EC_CURVE_DATA h; unsigned char data[0+15*6]; }
+       _EC_WTLS_1 = {
+       { NID_X9_62_characteristic_two_field,0,15,2 },
+       {                                                       /* no seed */
+         0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x02,0x01,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* a */
+         0x00,0x00,0x00,0x00,0x01,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* b */
+         0x00,0x00,0x00,0x00,0x01,
+         0x01,0x66,0x79,0x79,0xA4,0x0B,0xA4,0x97,0xE5,0xD5,    /* x */
+         0xC2,0x70,0x78,0x06,0x17,
+         0x00,0xF4,0x4B,0x4A,0xF1,0xEC,0xC2,0x63,0x0E,0x08,    /* y */
+         0x78,0x5C,0xEB,0xCC,0x15,
+         0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFD,0xBF,    /* order */
+         0x91,0xAF,0x6D,0xEA,0x73 }
        };
 
 /* IPSec curves */
@@ -1001,17 +1765,27 @@ static const EC_CURVE_DATA _EC_WTLS_1 = {
  * As the group order is not a prime this curve is not suitable
  * for ECDSA.
  */
-static const EC_CURVE_DATA _EC_IPSEC_155_ID3 = {
-       NID_X9_62_characteristic_two_field,
-       "0800000000000000000000004000000000000001",
-       "0",
-       "07338f",
-       "7b",
-       "1c8",
-       "2AAAAAAAAAAAAAAAAAAC7F3C7881BD0868FA86C",3,
-       NULL, 0,
-       "\n\tIPSec/IKE/Oakley curve #3 over a 155 bit binary field.\n"
-       "\tNot suitable for ECDSA.\n\tQuestionable extension field!"
+static const struct { EC_CURVE_DATA h; unsigned char data[0+20*6]; }
+       _EC_IPSEC_155_ID3 = {
+       { NID_X9_62_characteristic_two_field,0,20,3 },
+       {                                                       /* no seed */
+         0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
+
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* a */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* b */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x33,0x8f,
+
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* x */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7b,
+
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* y */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xc8,
+
+         0x02,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,    /* order */
+         0xC7,0xF3,0xC7,0x88,0x1B,0xD0,0x86,0x8F,0xA8,0x6C }
        };
 
 /* NOTE: The of curves over a extension field of non prime degree
@@ -1019,106 +1793,118 @@ static const EC_CURVE_DATA _EC_IPSEC_155_ID3 = {
  * As the group order is not a prime this curve is not suitable
  * for ECDSA.
  */
-static const EC_CURVE_DATA _EC_IPSEC_185_ID4 = {
-       NID_X9_62_characteristic_two_field,
-       "020000000000000000000000000000200000000000000001",
-       "0",
-       "1ee9",
-       "18",
-       "0d",
-       "FFFFFFFFFFFFFFFFFFFFFFEDF97C44DB9F2420BAFCA75E",2,
-       NULL, 0,
-       "\n\tIPSec/IKE/Oakley curve #4 over a 185 bit binary field.\n"
-       "\tNot suitable for ECDSA.\n\tQuestionable extension field!"
+static const struct { EC_CURVE_DATA h; unsigned char data[0+24*6]; }
+       _EC_IPSEC_185_ID4 = {
+       { NID_X9_62_characteristic_two_field,0,24,2 },
+       {                                                       /* no seed */
+         0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* p */
+         0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x01,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* a */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* b */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x1e,0xe9,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* x */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x18,
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /* y */
+         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+         0x00,0x00,0x00,0x0d,
+         0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,    /* order */
+         0xFF,0xFF,0xED,0xF9,0x7C,0x44,0xDB,0x9F,0x24,0x20,
+         0xBA,0xFC,0xA7,0x5E }
        };
 
 typedef struct _ec_list_element_st {
        int     nid;
        const EC_CURVE_DATA *data;
+       const char *comment;
        } ec_list_element;
 
 static const ec_list_element curve_list[] = {
        /* prime field curves */        
        /* secg curves */
-       { NID_secp112r1, &_EC_SECG_PRIME_112R1},
-       { NID_secp112r2, &_EC_SECG_PRIME_112R2},
-       { NID_secp128r1, &_EC_SECG_PRIME_128R1},
-       { NID_secp128r2, &_EC_SECG_PRIME_128R2},
-       { NID_secp160k1, &_EC_SECG_PRIME_160K1},
-       { NID_secp160r1, &_EC_SECG_PRIME_160R1},
-       { NID_secp160r2, &_EC_SECG_PRIME_160R2},
+       { NID_secp112r1, &_EC_SECG_PRIME_112R1.h, "SECG/WTLS curve over a 112 bit prime field"},
+       { NID_secp112r2, &_EC_SECG_PRIME_112R2.h, "SECG curve over a 112 bit prime field"},
+       { NID_secp128r1, &_EC_SECG_PRIME_128R1.h, "SECG curve over a 128 bit prime field"},
+       { NID_secp128r2, &_EC_SECG_PRIME_128R2.h, "SECG curve over a 128 bit prime field"},
+       { NID_secp160k1, &_EC_SECG_PRIME_160K1.h, "SECG curve over a 160 bit prime field"},
+       { NID_secp160r1, &_EC_SECG_PRIME_160R1.h, "SECG curve over a 160 bit prime field"},
+       { NID_secp160r2, &_EC_SECG_PRIME_160R2.h, "SECG/WTLS curve over a 160 bit prime field"},
        /* SECG secp192r1 is the same as X9.62 prime192v1 and hence omitted */
-       { NID_secp192k1, &_EC_SECG_PRIME_192K1},
-       { NID_secp224k1, &_EC_SECG_PRIME_224K1},
-       { NID_secp224r1, &_EC_NIST_PRIME_224},
-       { NID_secp256k1, &_EC_SECG_PRIME_256K1},
+       { NID_secp192k1, &_EC_SECG_PRIME_192K1.h, "SECG curve over a 192 bit prime field"},
+       { NID_secp224k1, &_EC_SECG_PRIME_224K1.h, "SECG curve over a 224 bit prime field"},
+       { NID_secp224r1, &_EC_NIST_PRIME_224.h,   "NIST/SECG curve over a 224 bit prime field"},
+       { NID_secp256k1, &_EC_SECG_PRIME_256K1.h, "SECG curve over a 256 bit prime field"},
        /* SECG secp256r1 is the same as X9.62 prime256v1 and hence omitted */
-       { NID_secp384r1, &_EC_NIST_PRIME_384},
-       { NID_secp521r1, &_EC_NIST_PRIME_521},
+       { NID_secp384r1, &_EC_NIST_PRIME_384.h, "NIST/SECG curve over a 384 bit prime field"},
+       { NID_secp521r1, &_EC_NIST_PRIME_521.h, "NIST/SECG curve over a 521 bit prime field"},
        /* X9.62 curves */
-       { NID_X9_62_prime192v1, &_EC_NIST_PRIME_192},
-       { NID_X9_62_prime192v2, &_EC_X9_62_PRIME_192V2},
-       { NID_X9_62_prime192v3, &_EC_X9_62_PRIME_192V3},
-       { NID_X9_62_prime239v1, &_EC_X9_62_PRIME_239V1},
-       { NID_X9_62_prime239v2, &_EC_X9_62_PRIME_239V2},
-       { NID_X9_62_prime239v3, &_EC_X9_62_PRIME_239V3},
-       { NID_X9_62_prime256v1, &_EC_X9_62_PRIME_256V1},
+       { NID_X9_62_prime192v1, &_EC_NIST_PRIME_192.h, "NIST/X9.62/SECG curve over a 192 bit prime field"},
+       { NID_X9_62_prime192v2, &_EC_X9_62_PRIME_192V2.h, "X9.62 curve over a 192 bit prime field"},
+       { NID_X9_62_prime192v3, &_EC_X9_62_PRIME_192V3.h, "X9.62 curve over a 192 bit prime field"},
+       { NID_X9_62_prime239v1, &_EC_X9_62_PRIME_239V1.h, "X9.62 curve over a 239 bit prime field"},
+       { NID_X9_62_prime239v2, &_EC_X9_62_PRIME_239V2.h, "X9.62 curve over a 239 bit prime field"},
+       { NID_X9_62_prime239v3, &_EC_X9_62_PRIME_239V3.h, "X9.62 curve over a 239 bit prime field"},
+       { NID_X9_62_prime256v1, &_EC_X9_62_PRIME_256V1.h, "X9.62/SECG curve over a 256 bit prime field"},
        /* characteristic two field curves */
        /* NIST/SECG curves */
-       { NID_sect113r1, &_EC_SECG_CHAR2_113R1},
-       { NID_sect113r2, &_EC_SECG_CHAR2_113R2},
-       { NID_sect131r1, &_EC_SECG_CHAR2_131R1},
-       { NID_sect131r2, &_EC_SECG_CHAR2_131R2},
-       { NID_sect163k1, &_EC_NIST_CHAR2_163K },
-       { NID_sect163r1, &_EC_SECG_CHAR2_163R1},
-       { NID_sect163r2, &_EC_NIST_CHAR2_163B },
-       { NID_sect193r1, &_EC_SECG_CHAR2_193R1},
-       { NID_sect193r2, &_EC_SECG_CHAR2_193R2},
-       { NID_sect233k1, &_EC_NIST_CHAR2_233K },
-       { NID_sect233r1, &_EC_NIST_CHAR2_233B },
-       { NID_sect239k1, &_EC_SECG_CHAR2_239K1},
-       { NID_sect283k1, &_EC_NIST_CHAR2_283K },
-       { NID_sect283r1, &_EC_NIST_CHAR2_283B },
-       { NID_sect409k1, &_EC_NIST_CHAR2_409K },
-       { NID_sect409r1, &_EC_NIST_CHAR2_409B },
-       { NID_sect571k1, &_EC_NIST_CHAR2_571K },
-       { NID_sect571r1, &_EC_NIST_CHAR2_571B },
+       { NID_sect113r1, &_EC_SECG_CHAR2_113R1.h, "SECG curve over a 113 bit binary field"},
+       { NID_sect113r2, &_EC_SECG_CHAR2_113R2.h, "SECG curve over a 113 bit binary field"},
+       { NID_sect131r1, &_EC_SECG_CHAR2_131R1.h, "SECG/WTLS curve over a 131 bit binary field"},
+       { NID_sect131r2, &_EC_SECG_CHAR2_131R2.h, "SECG curve over a 131 bit binary field"},
+       { NID_sect163k1, &_EC_NIST_CHAR2_163K.h,  "NIST/SECG/WTLS curve over a 163 bit binary field" },
+       { NID_sect163r1, &_EC_SECG_CHAR2_163R1.h, "SECG curve over a 163 bit binary field"},
+       { NID_sect163r2, &_EC_NIST_CHAR2_163B.h,  "NIST/SECG curve over a 163 bit binary field" },
+       { NID_sect193r1, &_EC_SECG_CHAR2_193R1.h, "SECG curve over a 193 bit binary field"},
+       { NID_sect193r2, &_EC_SECG_CHAR2_193R2.h, "SECG curve over a 193 bit binary field"},
+       { NID_sect233k1, &_EC_NIST_CHAR2_233K.h,  "NIST/SECG/WTLS curve over a 233 bit binary field" },
+       { NID_sect233r1, &_EC_NIST_CHAR2_233B.h,  "NIST/SECG/WTLS curve over a 233 bit binary field" },
+       { NID_sect239k1, &_EC_SECG_CHAR2_239K1.h, "SECG curve over a 239 bit binary field"},
+       { NID_sect283k1, &_EC_NIST_CHAR2_283K.h,  "NIST/SECG curve over a 283 bit binary field" },
+       { NID_sect283r1, &_EC_NIST_CHAR2_283B.h,  "NIST/SECG curve over a 283 bit binary field" },
+       { NID_sect409k1, &_EC_NIST_CHAR2_409K.h,  "NIST/SECG curve over a 409 bit binary field" },
+       { NID_sect409r1, &_EC_NIST_CHAR2_409B.h,  "NIST/SECG curve over a 409 bit binary field" },
+       { NID_sect571k1, &_EC_NIST_CHAR2_571K.h,  "NIST/SECG curve over a 571 bit binary field" },
+       { NID_sect571r1, &_EC_NIST_CHAR2_571B.h,  "NIST/SECG curve over a 571 bit binary field" },
        /* X9.62 curves */
-       { NID_X9_62_c2pnb163v1, &_EC_X9_62_CHAR2_163V1},
-       { NID_X9_62_c2pnb163v2, &_EC_X9_62_CHAR2_163V2},
-       { NID_X9_62_c2pnb163v3, &_EC_X9_62_CHAR2_163V3},
-       { NID_X9_62_c2pnb176v1, &_EC_X9_62_CHAR2_176V1},
-       { NID_X9_62_c2tnb191v1, &_EC_X9_62_CHAR2_191V1},
-       { NID_X9_62_c2tnb191v2, &_EC_X9_62_CHAR2_191V2},
-       { NID_X9_62_c2tnb191v3, &_EC_X9_62_CHAR2_191V3},
-       { NID_X9_62_c2pnb208w1, &_EC_X9_62_CHAR2_208W1},
-       { NID_X9_62_c2tnb239v1, &_EC_X9_62_CHAR2_239V1},
-       { NID_X9_62_c2tnb239v2, &_EC_X9_62_CHAR2_239V2},
-       { NID_X9_62_c2tnb239v3, &_EC_X9_62_CHAR2_239V3},
-       { NID_X9_62_c2pnb272w1, &_EC_X9_62_CHAR2_272W1},
-       { NID_X9_62_c2pnb304w1, &_EC_X9_62_CHAR2_304W1},
-       { NID_X9_62_c2tnb359v1, &_EC_X9_62_CHAR2_359V1},
-       { NID_X9_62_c2pnb368w1, &_EC_X9_62_CHAR2_368W1},
-       { NID_X9_62_c2tnb431r1, &_EC_X9_62_CHAR2_431R1},
+       { NID_X9_62_c2pnb163v1, &_EC_X9_62_CHAR2_163V1.h, "X9.62 curve over a 163 bit binary field"},
+       { NID_X9_62_c2pnb163v2, &_EC_X9_62_CHAR2_163V2.h, "X9.62 curve over a 163 bit binary field"},
+       { NID_X9_62_c2pnb163v3, &_EC_X9_62_CHAR2_163V3.h, "X9.62 curve over a 163 bit binary field"},
+       { NID_X9_62_c2pnb176v1, &_EC_X9_62_CHAR2_176V1.h, "X9.62 curve over a 176 bit binary field"},
+       { NID_X9_62_c2tnb191v1, &_EC_X9_62_CHAR2_191V1.h, "X9.62 curve over a 191 bit binary field"},
+       { NID_X9_62_c2tnb191v2, &_EC_X9_62_CHAR2_191V2.h, "X9.62 curve over a 191 bit binary field"},
+       { NID_X9_62_c2tnb191v3, &_EC_X9_62_CHAR2_191V3.h, "X9.62 curve over a 191 bit binary field"},
+       { NID_X9_62_c2pnb208w1, &_EC_X9_62_CHAR2_208W1.h, "X9.62 curve over a 208 bit binary field"},
+       { NID_X9_62_c2tnb239v1, &_EC_X9_62_CHAR2_239V1.h, "X9.62 curve over a 239 bit binary field"},
+       { NID_X9_62_c2tnb239v2, &_EC_X9_62_CHAR2_239V2.h, "X9.62 curve over a 239 bit binary field"},
+       { NID_X9_62_c2tnb239v3, &_EC_X9_62_CHAR2_239V3.h, "X9.62 curve over a 239 bit binary field"},
+       { NID_X9_62_c2pnb272w1, &_EC_X9_62_CHAR2_272W1.h, "X9.62 curve over a 272 bit binary field"},
+       { NID_X9_62_c2pnb304w1, &_EC_X9_62_CHAR2_304W1.h, "X9.62 curve over a 304 bit binary field"},
+       { NID_X9_62_c2tnb359v1, &_EC_X9_62_CHAR2_359V1.h, "X9.62 curve over a 359 bit binary field"},
+       { NID_X9_62_c2pnb368w1, &_EC_X9_62_CHAR2_368W1.h, "X9.62 curve over a 368 bit binary field"},
+       { NID_X9_62_c2tnb431r1, &_EC_X9_62_CHAR2_431R1.h, "X9.62 curve over a 431 bit binary field"},
        /* the WAP/WTLS curves
         * [unlike SECG, spec has its own OIDs for curves from X9.62] */
-       { NID_wap_wsg_idm_ecid_wtls1, &_EC_WTLS_1},
-       { NID_wap_wsg_idm_ecid_wtls3, &_EC_NIST_CHAR2_163K},
-       { NID_wap_wsg_idm_ecid_wtls4, &_EC_SECG_CHAR2_113R1},
-       { NID_wap_wsg_idm_ecid_wtls5, &_EC_X9_62_CHAR2_163V1},
-       { NID_wap_wsg_idm_ecid_wtls6, &_EC_SECG_PRIME_112R1},
-       { NID_wap_wsg_idm_ecid_wtls7, &_EC_SECG_PRIME_160R2},
-       { NID_wap_wsg_idm_ecid_wtls8, &_EC_WTLS_8},
-       { NID_wap_wsg_idm_ecid_wtls9, &_EC_WTLS_9 },
-       { NID_wap_wsg_idm_ecid_wtls10, &_EC_NIST_CHAR2_233K},
-       { NID_wap_wsg_idm_ecid_wtls11, &_EC_NIST_CHAR2_233B},
-       { NID_wap_wsg_idm_ecid_wtls12, &_EC_WTLS_12},
+       { NID_wap_wsg_idm_ecid_wtls1, &_EC_WTLS_1.h, "WTLS curve over a 113 bit binary field"},
+       { NID_wap_wsg_idm_ecid_wtls3, &_EC_NIST_CHAR2_163K.h,   "NIST/SECG/WTLS curve over a 163 bit binary field"},
+       { NID_wap_wsg_idm_ecid_wtls4, &_EC_SECG_CHAR2_113R1.h,  "SECG curve over a 113 bit binary field"},
+       { NID_wap_wsg_idm_ecid_wtls5, &_EC_X9_62_CHAR2_163V1.h, "X9.62 curve over a 163 bit binary field"},
+       { NID_wap_wsg_idm_ecid_wtls6, &_EC_SECG_PRIME_112R1.h,  "SECG/WTLS curve over a 112 bit prime field"},
+       { NID_wap_wsg_idm_ecid_wtls7, &_EC_SECG_PRIME_160R2.h,  "SECG/WTLS curve over a 160 bit prime field"},
+       { NID_wap_wsg_idm_ecid_wtls8, &_EC_WTLS_8.h, "WTLS curve over a 112 bit prime field"},
+       { NID_wap_wsg_idm_ecid_wtls9, &_EC_WTLS_9.h, "WTLS curve over a 160 bit prime field" },
+       { NID_wap_wsg_idm_ecid_wtls10, &_EC_NIST_CHAR2_233K.h, "NIST/SECG/WTLS curve over a 233 bit binary field"},
+       { NID_wap_wsg_idm_ecid_wtls11, &_EC_NIST_CHAR2_233B.h, "NIST/SECG/WTLS curve over a 233 bit binary field"},
+       { NID_wap_wsg_idm_ecid_wtls12, &_EC_WTLS_12.h, "WTLS curvs over a 224 bit prime field"},
        /* IPSec curves */
-       { NID_ipsec3, &_EC_IPSEC_155_ID3},
-       { NID_ipsec4, &_EC_IPSEC_185_ID4},
+       { NID_ipsec3, &_EC_IPSEC_155_ID3.h, "\n\tIPSec/IKE/Oakley curve #3 over a 155 bit binary field.\n""\tNot suitable for ECDSA.\n\tQuestionable extension field!"},
+       { NID_ipsec4, &_EC_IPSEC_185_ID4.h, "\n\tIPSec/IKE/Oakley curve #4 over a 185 bit binary field.\n""\tNot suitable for ECDSA.\n\tQuestionable extension field!"},
 };
 
-static size_t curve_list_length = sizeof(curve_list)/sizeof(ec_list_element);
+#define curve_list_length (sizeof(curve_list)/sizeof(ec_list_element))
 
 static EC_GROUP *ec_group_new_from_data(const EC_CURVE_DATA *data)
        {
@@ -1127,22 +1913,23 @@ static EC_GROUP *ec_group_new_from_data(const EC_CURVE_DATA *data)
        BN_CTX   *ctx=NULL;
        BIGNUM   *p=NULL, *a=NULL, *b=NULL, *x=NULL, *y=NULL, *order=NULL;
        int      ok=0;
+       int      seed_len,param_len;
+       const unsigned char *params;
 
        if ((ctx = BN_CTX_new()) == NULL)
                {
                ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_MALLOC_FAILURE);
                goto err;
                }
-       if ((p = BN_new()) == NULL || (a = BN_new()) == NULL || 
-               (b = BN_new()) == NULL || (x = BN_new()) == NULL ||
-               (y = BN_new()) == NULL || (order = BN_new()) == NULL)
-               {
-               ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_MALLOC_FAILURE);
-               goto err;
-               }
-       
-       if (!BN_hex2bn(&p, data->p) || !BN_hex2bn(&a, data->a)
-               || !BN_hex2bn(&b, data->b))
+
+       seed_len  = data->seed_len;
+       param_len = data->param_len;
+       params    = (const unsigned char *)(data+1);    /* skip header */
+       params   += seed_len;                           /* skip seed   */
+
+       if (!(p = BN_bin2bn(params+0*param_len, param_len, NULL))
+               || !(a = BN_bin2bn(params+1*param_len, param_len, NULL))
+               || !(b = BN_bin2bn(params+2*param_len, param_len, NULL)))
                {
                ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_BN_LIB);
                goto err;
@@ -1156,8 +1943,8 @@ static EC_GROUP *ec_group_new_from_data(const EC_CURVE_DATA *data)
                        goto err;
                        }
                }
-               else
-               { /* field_type == NID_X9_62_characteristic_two_field */
+       else    /* field_type == NID_X9_62_characteristic_two_field */
+               {
                if ((group = EC_GROUP_new_curve_GF2m(p, a, b, ctx)) == NULL)
                        {
                        ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);
@@ -1171,7 +1958,8 @@ static EC_GROUP *ec_group_new_from_data(const EC_CURVE_DATA *data)
                goto err;
                }
        
-       if (!BN_hex2bn(&x, data->x) || !BN_hex2bn(&y, data->y))
+       if (!(x = BN_bin2bn(params+3*param_len, param_len, NULL))
+               || !(y = BN_bin2bn(params+4*param_len, param_len, NULL)))
                {
                ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_BN_LIB);
                goto err;
@@ -1181,7 +1969,8 @@ static EC_GROUP *ec_group_new_from_data(const EC_CURVE_DATA *data)
                ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);
                goto err;
                }
-       if (!BN_hex2bn(&order, data->order) || !BN_set_word(x, data->cofactor))
+       if (!(order = BN_bin2bn(params+5*param_len, param_len, NULL))
+               || !BN_set_word(x, (BN_ULONG)data->cofactor))
                {
                ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_BN_LIB);
                goto err;
@@ -1191,9 +1980,9 @@ static EC_GROUP *ec_group_new_from_data(const EC_CURVE_DATA *data)
                ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);
                goto err;
                }
-       if (data->seed)
+       if (seed_len)
                {
-               if (!EC_GROUP_set_seed(group, data->seed, data->seed_len))
+               if (!EC_GROUP_set_seed(group, params-seed_len, seed_len))
                        {
                        ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);
                        goto err;
@@ -1263,7 +2052,7 @@ size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems)
        for (i = 0; i < min; i++)
                {
                r[i].nid = curve_list[i].nid;
-               r[i].comment = curve_list[i].data->comment;
+               r[i].comment = curve_list[i].comment;
                }
 
        return curve_list_length;
index d04c895..84b4833 100644 (file)
@@ -74,6 +74,14 @@ static ERR_STRING_DATA EC_str_functs[]=
 {ERR_FUNC(EC_F_D2I_ECPARAMETERS),      "d2i_ECParameters"},
 {ERR_FUNC(EC_F_D2I_ECPKPARAMETERS),    "d2i_ECPKParameters"},
 {ERR_FUNC(EC_F_D2I_ECPRIVATEKEY),      "d2i_ECPrivateKey"},
+{ERR_FUNC(EC_F_DO_EC_KEY_PRINT),       "DO_EC_KEY_PRINT"},
+{ERR_FUNC(EC_F_ECKEY_PARAM2TYPE),      "ECKEY_PARAM2TYPE"},
+{ERR_FUNC(EC_F_ECKEY_PARAM_DECODE),    "ECKEY_PARAM_DECODE"},
+{ERR_FUNC(EC_F_ECKEY_PRIV_DECODE),     "ECKEY_PRIV_DECODE"},
+{ERR_FUNC(EC_F_ECKEY_PRIV_ENCODE),     "ECKEY_PRIV_ENCODE"},
+{ERR_FUNC(EC_F_ECKEY_PUB_DECODE),      "ECKEY_PUB_DECODE"},
+{ERR_FUNC(EC_F_ECKEY_PUB_ENCODE),      "ECKEY_PUB_ENCODE"},
+{ERR_FUNC(EC_F_ECKEY_TYPE2PARAM),      "ECKEY_TYPE2PARAM"},
 {ERR_FUNC(EC_F_ECPARAMETERS_PRINT),    "ECParameters_print"},
 {ERR_FUNC(EC_F_ECPARAMETERS_PRINT_FP), "ECParameters_print_fp"},
 {ERR_FUNC(EC_F_ECPKPARAMETERS_PRINT),  "ECPKParameters_print"},
@@ -147,7 +155,6 @@ static ERR_STRING_DATA EC_str_functs[]=
 {ERR_FUNC(EC_F_EC_KEY_PRINT),  "EC_KEY_print"},
 {ERR_FUNC(EC_F_EC_KEY_PRINT_FP),       "EC_KEY_print_fp"},
 {ERR_FUNC(EC_F_EC_POINTS_MAKE_AFFINE), "EC_POINTs_make_affine"},
-{ERR_FUNC(EC_F_EC_POINTS_MUL), "EC_POINTs_mul"},
 {ERR_FUNC(EC_F_EC_POINT_ADD),  "EC_POINT_add"},
 {ERR_FUNC(EC_F_EC_POINT_CMP),  "EC_POINT_cmp"},
 {ERR_FUNC(EC_F_EC_POINT_COPY), "EC_POINT_copy"},
@@ -178,6 +185,13 @@ static ERR_STRING_DATA EC_str_functs[]=
 {ERR_FUNC(EC_F_I2D_ECPRIVATEKEY),      "i2d_ECPrivateKey"},
 {ERR_FUNC(EC_F_I2O_ECPUBLICKEY),       "i2o_ECPublicKey"},
 {ERR_FUNC(EC_F_O2I_ECPUBLICKEY),       "o2i_ECPublicKey"},
+{ERR_FUNC(EC_F_OLD_EC_PRIV_DECODE),    "OLD_EC_PRIV_DECODE"},
+{ERR_FUNC(EC_F_PKEY_EC_CTRL),  "PKEY_EC_CTRL"},
+{ERR_FUNC(EC_F_PKEY_EC_CTRL_STR),      "PKEY_EC_CTRL_STR"},
+{ERR_FUNC(EC_F_PKEY_EC_DERIVE),        "PKEY_EC_DERIVE"},
+{ERR_FUNC(EC_F_PKEY_EC_KEYGEN),        "PKEY_EC_KEYGEN"},
+{ERR_FUNC(EC_F_PKEY_EC_PARAMGEN),      "PKEY_EC_PARAMGEN"},
+{ERR_FUNC(EC_F_PKEY_EC_SIGN),  "PKEY_EC_SIGN"},
 {0,NULL}
        };
 
@@ -187,6 +201,7 @@ static ERR_STRING_DATA EC_str_reasons[]=
 {ERR_REASON(EC_R_ASN1_UNKNOWN_FIELD)     ,"asn1 unknown field"},
 {ERR_REASON(EC_R_BUFFER_TOO_SMALL)       ,"buffer too small"},
 {ERR_REASON(EC_R_D2I_ECPKPARAMETERS_FAILURE),"d2i ecpkparameters failure"},
+{ERR_REASON(EC_R_DECODE_ERROR)           ,"decode error"},
 {ERR_REASON(EC_R_DISCRIMINANT_IS_ZERO)   ,"discriminant is zero"},
 {ERR_REASON(EC_R_EC_GROUP_NEW_BY_NAME_FAILURE),"ec group new by name failure"},
 {ERR_REASON(EC_R_FIELD_TOO_LARGE)        ,"field too large"},
@@ -196,6 +211,8 @@ static ERR_STRING_DATA EC_str_reasons[]=
 {ERR_REASON(EC_R_INVALID_ARGUMENT)       ,"invalid argument"},
 {ERR_REASON(EC_R_INVALID_COMPRESSED_POINT),"invalid compressed point"},
 {ERR_REASON(EC_R_INVALID_COMPRESSION_BIT),"invalid compression bit"},
+{ERR_REASON(EC_R_INVALID_CURVE)          ,"invalid curve"},
+{ERR_REASON(EC_R_INVALID_DIGEST_TYPE)    ,"invalid digest type"},
 {ERR_REASON(EC_R_INVALID_ENCODING)       ,"invalid encoding"},
 {ERR_REASON(EC_R_INVALID_FIELD)          ,"invalid field"},
 {ERR_REASON(EC_R_INVALID_FORM)           ,"invalid form"},
@@ -203,6 +220,7 @@ static ERR_STRING_DATA EC_str_reasons[]=
 {ERR_REASON(EC_R_INVALID_PENTANOMIAL_BASIS),"invalid pentanomial basis"},
 {ERR_REASON(EC_R_INVALID_PRIVATE_KEY)    ,"invalid private key"},
 {ERR_REASON(EC_R_INVALID_TRINOMIAL_BASIS),"invalid trinomial basis"},
+{ERR_REASON(EC_R_KEYS_NOT_SET)           ,"keys not set"},
 {ERR_REASON(EC_R_MISSING_PARAMETERS)     ,"missing parameters"},
 {ERR_REASON(EC_R_MISSING_PRIVATE_KEY)    ,"missing private key"},
 {ERR_REASON(EC_R_NOT_A_NIST_PRIME)       ,"not a NIST prime"},
@@ -210,6 +228,7 @@ static ERR_STRING_DATA EC_str_reasons[]=
 {ERR_REASON(EC_R_NOT_IMPLEMENTED)        ,"not implemented"},
 {ERR_REASON(EC_R_NOT_INITIALIZED)        ,"not initialized"},
 {ERR_REASON(EC_R_NO_FIELD_MOD)           ,"no field mod"},
+{ERR_REASON(EC_R_NO_PARAMETERS_SET)      ,"no parameters set"},
 {ERR_REASON(EC_R_PASSED_NULL_PARAMETER)  ,"passed null parameter"},
 {ERR_REASON(EC_R_PKPARAMETERS2GROUP_FAILURE),"pkparameters2group failure"},
 {ERR_REASON(EC_R_POINT_AT_INFINITY)      ,"point at infinity"},
index fdd7aa2..3e2c34b 100644 (file)
@@ -205,11 +205,14 @@ struct ec_group_st {
                       * irreducible polynomial defining the field.
                       */
 
-       unsigned int poly[5]; /* Field specification for curves over GF(2^m).
-                              * The irreducible f(t) is then of the form:
-                              *     t^poly[0] + t^poly[1] + ... + t^poly[k]
-                              * where m = poly[0] > poly[1] > ... > poly[k] = 0.
-                              */
+       int poly[6]; /* Field specification for curves over GF(2^m).
+                     * The irreducible f(t) is then of the form:
+                     *     t^poly[0] + t^poly[1] + ... + t^poly[k]
+                     * where m = poly[0] > poly[1] > ... > poly[k] = 0.
+                     * The array is terminated with poly[k+1]=-1.
+                     * All elliptic curve irreducibles have at most 5
+                     * non-zero terms.
+                     */
 
        BIGNUM a, b; /* Curve coefficients.
                      * (Here the assumption is that BIGNUMs can be used
index 5af8437..dd7da0f 100644 (file)
@@ -79,7 +79,7 @@ EC_GROUP *EC_GROUP_new(const EC_METHOD *meth)
 
        if (meth == NULL)
                {
-               ECerr(EC_F_EC_GROUP_NEW, ERR_R_PASSED_NULL_PARAMETER);
+               ECerr(EC_F_EC_GROUP_NEW, EC_R_SLOT_FULL);
                return NULL;
                }
        if (meth->group_init == 0)
@@ -740,7 +740,7 @@ void EC_POINT_clear_free(EC_POINT *point)
 
        if (point->meth->point_clear_finish != 0)
                point->meth->point_clear_finish(point);
-       else if (point->meth != NULL && point->meth->point_finish != 0)
+       else if (point->meth->point_finish != 0)
                point->meth->point_finish(point);
        OPENSSL_cleanse(point, sizeof *point);
        OPENSSL_free(point);
index ee42269..19f2167 100644 (file)
@@ -226,6 +226,12 @@ static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len)
                sign = -1;
                }
 
+       if (scalar->d == NULL || scalar->top == 0)
+               {
+               ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
+               goto err;
+               }
+
        len = BN_num_bits(scalar);
        r = OPENSSL_malloc(len + 1); /* modified wNAF may be one digit longer than binary representation
                                      * (*ret_len will be set to the actual length, i.e. at most
@@ -235,12 +241,6 @@ static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len)
                ECerr(EC_F_COMPUTE_WNAF, ERR_R_MALLOC_FAILURE);
                goto err;
                }
-
-       if (scalar->d == NULL || scalar->top == 0)
-               {
-               ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
-               goto err;
-               }
        window_val = scalar->d[0] & mask;
        j = 0;
        while ((window_val != 0) || (j + w + 1 < len)) /* if j+w+1 >= len, window_val will not increase */
@@ -421,7 +421,7 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
                        if (numblocks > pre_comp->numblocks)
                                numblocks = pre_comp->numblocks;
 
-                       pre_points_per_block = 1u << (pre_comp->w - 1);
+                       pre_points_per_block = (size_t)1 << (pre_comp->w - 1);
 
                        /* check that pre_comp looks sane */
                        if (pre_comp->num != (pre_comp->numblocks * pre_points_per_block))
@@ -463,7 +463,7 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
 
                bits = i < num ? BN_num_bits(scalars[i]) : BN_num_bits(scalar);
                wsize[i] = EC_window_bits_for_scalar_size(bits);
-               num_val += 1u << (wsize[i] - 1);
+               num_val += (size_t)1 << (wsize[i] - 1);
                wNAF[i + 1] = NULL; /* make sure we always have a pivot */
                wNAF[i] = compute_wNAF((i < num ? scalars[i] : scalar), wsize[i], &wNAF_len[i]);
                if (wNAF[i] == NULL)
@@ -602,7 +602,7 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
        for (i = 0; i < num + num_scalar; i++)
                {
                val_sub[i] = v;
-               for (j = 0; j < (1u << (wsize[i] - 1)); j++)
+               for (j = 0; j < ((size_t)1 << (wsize[i] - 1)); j++)
                        {
                        *v = EC_POINT_new(group);
                        if (*v == NULL) goto err;
@@ -638,7 +638,7 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
                if (wsize[i] > 1)
                        {
                        if (!EC_POINT_dbl(group, tmp, val_sub[i][0], ctx)) goto err;
-                       for (j = 1; j < (1u << (wsize[i] - 1)); j++)
+                       for (j = 1; j < ((size_t)1 << (wsize[i] - 1)); j++)
                                {
                                if (!EC_POINT_add(group, val_sub[i][j], val_sub[i][j - 1], tmp, ctx)) goto err;
                                }
@@ -822,7 +822,7 @@ int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
 
        numblocks = (bits + blocksize - 1) / blocksize; /* max. number of blocks to use for wNAF splitting */
        
-       pre_points_per_block = 1u << (w - 1);
+       pre_points_per_block = (size_t)1 << (w - 1);
        num = pre_points_per_block * numblocks; /* number of points to compute and store */
 
        points = OPENSSL_malloc(sizeof (EC_POINT*)*(num + 1));
diff --git a/deps/openssl/openssl/crypto/ec/ec_pmeth.c b/deps/openssl/openssl/crypto/ec/ec_pmeth.c
new file mode 100644 (file)
index 0000000..f433076
--- /dev/null
@@ -0,0 +1,340 @@
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project 2006.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include "cryptlib.h"
+#include <openssl/asn1t.h>
+#include <openssl/x509.h>
+#include <openssl/ec.h>
+#include <openssl/ecdsa.h>
+#include <openssl/evp.h>
+#include "evp_locl.h"
+
+/* EC pkey context structure */
+
+typedef struct
+       {
+       /* Key and paramgen group */
+       EC_GROUP *gen_group;
+       /* message digest */
+       const EVP_MD *md;
+       } EC_PKEY_CTX;
+
+static int pkey_ec_init(EVP_PKEY_CTX *ctx)
+       {
+       EC_PKEY_CTX *dctx;
+       dctx = OPENSSL_malloc(sizeof(EC_PKEY_CTX));
+       if (!dctx)
+               return 0;
+       dctx->gen_group = NULL;
+       dctx->md = NULL;
+
+       ctx->data = dctx;
+
+       return 1;
+       }
+
+static int pkey_ec_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
+       {
+       EC_PKEY_CTX *dctx, *sctx;
+       if (!pkey_ec_init(dst))
+               return 0;
+               sctx = src->data;
+       dctx = dst->data;
+       if (sctx->gen_group)
+               {
+               dctx->gen_group = EC_GROUP_dup(sctx->gen_group);
+               if (!dctx->gen_group)
+                       return 0;
+               }
+       dctx->md = sctx->md;
+       return 1;
+       }
+
+static void pkey_ec_cleanup(EVP_PKEY_CTX *ctx)
+       {
+       EC_PKEY_CTX *dctx = ctx->data;
+       if (dctx)
+               {
+               if (dctx->gen_group)
+                       EC_GROUP_free(dctx->gen_group);
+               OPENSSL_free(dctx);
+               }
+       }
+
+static int pkey_ec_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
+                                       const unsigned char *tbs, size_t tbslen)
+       {
+       int ret, type;
+       unsigned int sltmp;
+       EC_PKEY_CTX *dctx = ctx->data;
+       EC_KEY *ec = ctx->pkey->pkey.ec;
+
+       if (!sig)
+               {
+               *siglen = ECDSA_size(ec);
+               return 1;
+               }
+       else if(*siglen < (size_t)ECDSA_size(ec))
+               {
+               ECerr(EC_F_PKEY_EC_SIGN, EC_R_BUFFER_TOO_SMALL);
+               return 0;
+               }
+
+       if (dctx->md)
+               type = EVP_MD_type(dctx->md);
+       else
+               type = NID_sha1;
+
+
+       ret = ECDSA_sign(type, tbs, tbslen, sig, &sltmp, ec);
+
+       if (ret <= 0)
+               return ret;
+       *siglen = (size_t)sltmp;
+       return 1;
+       }
+
+static int pkey_ec_verify(EVP_PKEY_CTX *ctx,
+                                       const unsigned char *sig, size_t siglen,
+                                       const unsigned char *tbs, size_t tbslen)
+       {
+       int ret, type;
+       EC_PKEY_CTX *dctx = ctx->data;
+       EC_KEY *ec = ctx->pkey->pkey.ec;
+
+       if (dctx->md)
+               type = EVP_MD_type(dctx->md);
+       else
+               type = NID_sha1;
+
+       ret = ECDSA_verify(type, tbs, tbslen, sig, siglen, ec);
+
+       return ret;
+       }
+
+static int pkey_ec_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen)
+       {
+       int ret;
+       size_t outlen;
+       const EC_POINT *pubkey = NULL;
+       if (!ctx->pkey || !ctx->peerkey)
+               {
+               ECerr(EC_F_PKEY_EC_DERIVE, EC_R_KEYS_NOT_SET);
+               return 0;
+               }
+
+       if (!key)
+               {
+               const EC_GROUP *group;
+               group = EC_KEY_get0_group(ctx->pkey->pkey.ec);
+               *keylen = (EC_GROUP_get_degree(group) + 7)/8;
+               return 1;
+               }
+
+       pubkey = EC_KEY_get0_public_key(ctx->peerkey->pkey.ec);
+
+       /* NB: unlike PKS#3 DH, if *outlen is less than maximum size this is
+        * not an error, the result is truncated.
+        */
+
+       outlen = *keylen;
+               
+       ret = ECDH_compute_key(key, outlen, pubkey, ctx->pkey->pkey.ec, 0);
+       if (ret < 0)
+               return ret;
+       *keylen = ret;
+       return 1;
+       }
+
+static int pkey_ec_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
+       {
+       EC_PKEY_CTX *dctx = ctx->data;
+       EC_GROUP *group;
+       switch (type)
+               {
+               case EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID:
+               group = EC_GROUP_new_by_curve_name(p1);
+               if (group == NULL)
+                       {
+                       ECerr(EC_F_PKEY_EC_CTRL, EC_R_INVALID_CURVE);
+                       return 0;
+                       }
+               if (dctx->gen_group)
+                       EC_GROUP_free(dctx->gen_group);
+               dctx->gen_group = group;
+               return 1;
+
+               case EVP_PKEY_CTRL_MD:
+               if (EVP_MD_type((const EVP_MD *)p2) != NID_sha1 &&
+                   EVP_MD_type((const EVP_MD *)p2) != NID_sha224 &&
+                   EVP_MD_type((const EVP_MD *)p2) != NID_sha256 &&
+                   EVP_MD_type((const EVP_MD *)p2) != NID_sha384 &&
+                   EVP_MD_type((const EVP_MD *)p2) != NID_sha512)
+                       {
+                       ECerr(EC_F_PKEY_EC_CTRL, EC_R_INVALID_DIGEST_TYPE);
+                       return 0;
+                       }
+               dctx->md = p2;
+               return 1;
+
+               case EVP_PKEY_CTRL_PEER_KEY:
+               /* Default behaviour is OK */
+               case EVP_PKEY_CTRL_DIGESTINIT:
+               case EVP_PKEY_CTRL_PKCS7_SIGN:
+               case EVP_PKEY_CTRL_CMS_SIGN:
+               return 1;
+
+               default:
+               return -2;
+
+               }
+       }
+                       
+static int pkey_ec_ctrl_str(EVP_PKEY_CTX *ctx,
+                       const char *type, const char *value)
+       {
+       if (!strcmp(type, "ec_paramgen_curve"))
+               {
+               int nid;
+               nid = OBJ_sn2nid(value);
+               if (nid == NID_undef)
+                       nid = OBJ_ln2nid(value);
+               if (nid == NID_undef)
+                       {
+                       ECerr(EC_F_PKEY_EC_CTRL_STR, EC_R_INVALID_CURVE);
+                       return 0;
+                       }
+               return EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid);
+               }
+       return -2;
+       }
+
+static int pkey_ec_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
+       {
+       EC_KEY *ec = NULL;
+       EC_PKEY_CTX *dctx = ctx->data;
+       int ret = 0;
+       if (dctx->gen_group == NULL)
+               {
+               ECerr(EC_F_PKEY_EC_PARAMGEN, EC_R_NO_PARAMETERS_SET);
+               return 0;
+               }
+       ec = EC_KEY_new();
+       if (!ec)
+               return 0;
+       ret = EC_KEY_set_group(ec, dctx->gen_group);
+       if (ret)
+               EVP_PKEY_assign_EC_KEY(pkey, ec);
+       else
+               EC_KEY_free(ec);
+       return ret;
+       }
+
+static int pkey_ec_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
+       {
+       EC_KEY *ec = NULL;
+       if (ctx->pkey == NULL)
+               {
+               ECerr(EC_F_PKEY_EC_KEYGEN, EC_R_NO_PARAMETERS_SET);
+               return 0;
+               }
+       ec = EC_KEY_new();
+       if (!ec)
+               return 0;
+       EVP_PKEY_assign_EC_KEY(pkey, ec);
+       /* Note: if error return, pkey is freed by parent routine */
+       if (!EVP_PKEY_copy_parameters(pkey, ctx->pkey))
+               return 0;
+       return EC_KEY_generate_key(pkey->pkey.ec);
+       }
+
+const EVP_PKEY_METHOD ec_pkey_meth = 
+       {
+       EVP_PKEY_EC,
+       0,
+       pkey_ec_init,
+       pkey_ec_copy,
+       pkey_ec_cleanup,
+
+       0,
+       pkey_ec_paramgen,
+
+       0,
+       pkey_ec_keygen,
+
+       0,
+       pkey_ec_sign,
+
+       0,
+       pkey_ec_verify,
+
+       0,0,
+
+       0,0,0,0,
+
+       0,0,
+
+       0,0,
+
+       0,
+       pkey_ec_derive,
+
+       pkey_ec_ctrl,
+       pkey_ec_ctrl_str
+
+       };
diff --git a/deps/openssl/openssl/crypto/ec/eck_prn.c b/deps/openssl/openssl/crypto/ec/eck_prn.c
new file mode 100644 (file)
index 0000000..7d3e175
--- /dev/null
@@ -0,0 +1,391 @@
+/* crypto/ec/eck_prn.c */
+/*
+ * Written by Nils Larsch for the OpenSSL project.
+ */
+/* ====================================================================
+ * Copyright (c) 1998-2005 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    openssl-core@openssl.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+/* ====================================================================
+ * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
+ * Portions originally developed by SUN MICROSYSTEMS, INC., and 
+ * contributed to the OpenSSL project.
+ */
+
+#include <stdio.h>
+#include "cryptlib.h"
+#include <openssl/evp.h>
+#include <openssl/ec.h>
+#include <openssl/bn.h>
+
+#ifndef OPENSSL_NO_FP_API
+int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off)
+       {
+       BIO *b;
+       int ret;
+
+       if ((b=BIO_new(BIO_s_file())) == NULL)
+               {
+               ECerr(EC_F_ECPKPARAMETERS_PRINT_FP,ERR_R_BUF_LIB);
+               return(0);
+               }
+       BIO_set_fp(b, fp, BIO_NOCLOSE);
+       ret = ECPKParameters_print(b, x, off);
+       BIO_free(b);
+       return(ret);
+       }
+
+int EC_KEY_print_fp(FILE *fp, const EC_KEY *x, int off)
+       {
+       BIO *b;
+       int ret;
+       if ((b=BIO_new(BIO_s_file())) == NULL)
+               {
+               ECerr(EC_F_EC_KEY_PRINT_FP, ERR_R_BIO_LIB);
+               return(0);
+               }
+       BIO_set_fp(b, fp, BIO_NOCLOSE);
+       ret = EC_KEY_print(b, x, off);
+       BIO_free(b);
+       return(ret);
+       }
+
+int ECParameters_print_fp(FILE *fp, const EC_KEY *x)
+       {
+       BIO *b;
+       int ret;
+       if ((b=BIO_new(BIO_s_file())) == NULL)
+               {
+               ECerr(EC_F_ECPARAMETERS_PRINT_FP, ERR_R_BIO_LIB);
+               return(0);
+               }
+       BIO_set_fp(b, fp, BIO_NOCLOSE);
+       ret = ECParameters_print(b, x);
+       BIO_free(b);
+       return(ret);
+       }
+#endif
+
+int EC_KEY_print(BIO *bp, const EC_KEY *x, int off)
+       {
+       EVP_PKEY *pk;
+       int ret;
+       pk = EVP_PKEY_new();
+       if (!pk || !EVP_PKEY_set1_EC_KEY(pk, (EC_KEY *)x))
+               return 0;
+       ret = EVP_PKEY_print_private(bp, pk, off, NULL);
+       EVP_PKEY_free(pk);
+       return ret;
+       }
+
+int ECParameters_print(BIO *bp, const EC_KEY *x)
+       {
+       EVP_PKEY *pk;
+       int ret;
+       pk = EVP_PKEY_new();
+       if (!pk || !EVP_PKEY_set1_EC_KEY(pk, (EC_KEY *)x))
+               return 0;
+       ret = EVP_PKEY_print_params(bp, pk, 4, NULL);
+       EVP_PKEY_free(pk);
+       return ret;
+       }
+
+static int print_bin(BIO *fp, const char *str, const unsigned char *num,
+               size_t len, int off);
+
+int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off)
+       {
+       unsigned char *buffer=NULL;
+       size_t  buf_len=0, i;
+       int     ret=0, reason=ERR_R_BIO_LIB;
+       BN_CTX  *ctx=NULL;
+       const EC_POINT *point=NULL;
+       BIGNUM  *p=NULL, *a=NULL, *b=NULL, *gen=NULL,
+               *order=NULL, *cofactor=NULL;
+       const unsigned char *seed;
+       size_t  seed_len=0;
+       
+       static const char *gen_compressed = "Generator (compressed):";
+       static const char *gen_uncompressed = "Generator (uncompressed):";
+       static const char *gen_hybrid = "Generator (hybrid):";
+       if (!x)
+               {
+               reason = ERR_R_PASSED_NULL_PARAMETER;
+               goto err;
+               }
+
+       ctx = BN_CTX_new();
+       if (ctx == NULL)
+               {
+               reason = ERR_R_MALLOC_FAILURE;
+               goto err;
+               }
+
+       if (EC_GROUP_get_asn1_flag(x))
+               {
+               /* the curve parameter are given by an asn1 OID */
+               int nid;
+
+               if (!BIO_indent(bp, off, 128))
+                       goto err;
+
+               nid = EC_GROUP_get_curve_name(x);
+               if (nid == 0)
+                       goto err;
+
+               if (BIO_printf(bp, "ASN1 OID: %s", OBJ_nid2sn(nid)) <= 0)
+                       goto err;
+               if (BIO_printf(bp, "\n") <= 0)
+                       goto err;
+               }
+       else
+               {
+               /* explicit parameters */
+               int is_char_two = 0;
+               point_conversion_form_t form;
+               int tmp_nid = EC_METHOD_get_field_type(EC_GROUP_method_of(x));
+
+               if (tmp_nid == NID_X9_62_characteristic_two_field)
+                       is_char_two = 1;
+
+               if ((p = BN_new()) == NULL || (a = BN_new()) == NULL ||
+                       (b = BN_new()) == NULL || (order = BN_new()) == NULL ||
+                       (cofactor = BN_new()) == NULL)
+                       {
+                       reason = ERR_R_MALLOC_FAILURE;
+                       goto err;
+                       }
+
+               if (is_char_two)
+                       {
+                       if (!EC_GROUP_get_curve_GF2m(x, p, a, b, ctx))
+                               {
+                               reason = ERR_R_EC_LIB;
+                               goto err;
+                               }
+                       }
+               else /* prime field */
+                       {
+                       if (!EC_GROUP_get_curve_GFp(x, p, a, b, ctx))
+                               {
+                               reason = ERR_R_EC_LIB;
+                               goto err;
+                               }
+                       }
+
+               if ((point = EC_GROUP_get0_generator(x)) == NULL)
+                       {
+                       reason = ERR_R_EC_LIB;
+                       goto err;
+                       }
+               if (!EC_GROUP_get_order(x, order, NULL) || 
+                       !EC_GROUP_get_cofactor(x, cofactor, NULL))
+                       {
+                       reason = ERR_R_EC_LIB;
+                       goto err;
+                       }
+               
+               form = EC_GROUP_get_point_conversion_form(x);
+
+               if ((gen = EC_POINT_point2bn(x, point, 
+                               form, NULL, ctx)) == NULL)
+                       {
+                       reason = ERR_R_EC_LIB;
+                       goto err;
+                       }
+
+               buf_len = (size_t)BN_num_bytes(p);
+               if (buf_len < (i = (size_t)BN_num_bytes(a)))
+                       buf_len = i;
+               if (buf_len < (i = (size_t)BN_num_bytes(b)))
+                       buf_len = i;
+               if (buf_len < (i = (size_t)BN_num_bytes(gen)))
+                       buf_len = i;
+               if (buf_len < (i = (size_t)BN_num_bytes(order)))
+                       buf_len = i;
+               if (buf_len < (i = (size_t)BN_num_bytes(cofactor))) 
+                       buf_len = i;
+
+               if ((seed = EC_GROUP_get0_seed(x)) != NULL)
+                       seed_len = EC_GROUP_get_seed_len(x);
+
+               buf_len += 10;
+               if ((buffer = OPENSSL_malloc(buf_len)) == NULL)
+                       {
+                       reason = ERR_R_MALLOC_FAILURE;
+                       goto err;
+                       }
+
+               if (!BIO_indent(bp, off, 128))
+                       goto err;
+
+               /* print the 'short name' of the field type */
+               if (BIO_printf(bp, "Field Type: %s\n", OBJ_nid2sn(tmp_nid))
+                       <= 0)
+                       goto err;  
+
+               if (is_char_two)
+                       {
+                       /* print the 'short name' of the base type OID */
+                       int basis_type = EC_GROUP_get_basis_type(x);
+                       if (basis_type == 0)
+                               goto err;
+
+                       if (!BIO_indent(bp, off, 128))
+                               goto err;
+
+                       if (BIO_printf(bp, "Basis Type: %s\n", 
+                               OBJ_nid2sn(basis_type)) <= 0)
+                               goto err;
+
+                       /* print the polynomial */
+                       if ((p != NULL) && !ASN1_bn_print(bp, "Polynomial:", p, buffer,
+                               off))
+                               goto err;
+                       }
+               else
+                       {
+                       if ((p != NULL) && !ASN1_bn_print(bp, "Prime:", p, buffer,off))
+                               goto err;
+                       }
+               if ((a != NULL) && !ASN1_bn_print(bp, "A:   ", a, buffer, off)) 
+                       goto err;
+               if ((b != NULL) && !ASN1_bn_print(bp, "B:   ", b, buffer, off))
+                       goto err;
+               if (form == POINT_CONVERSION_COMPRESSED)
+                       {
+                       if ((gen != NULL) && !ASN1_bn_print(bp, gen_compressed, gen,
+                               buffer, off))
+                               goto err;
+                       }
+               else if (form == POINT_CONVERSION_UNCOMPRESSED)
+                       {
+                       if ((gen != NULL) && !ASN1_bn_print(bp, gen_uncompressed, gen,
+                               buffer, off))
+                               goto err;
+                       }
+               else /* form == POINT_CONVERSION_HYBRID */
+                       {
+                       if ((gen != NULL) && !ASN1_bn_print(bp, gen_hybrid, gen,
+                               buffer, off))
+                               goto err;
+                       }
+               if ((order != NULL) && !ASN1_bn_print(bp, "Order: ", order, 
+                       buffer, off)) goto err;
+               if ((cofactor != NULL) && !ASN1_bn_print(bp, "Cofactor: ", cofactor, 
+                       buffer, off)) goto err;
+               if (seed && !print_bin(bp, "Seed:", seed, seed_len, off))
+                       goto err;
+               }
+       ret=1;
+err:
+       if (!ret)
+               ECerr(EC_F_ECPKPARAMETERS_PRINT, reason);
+       if (p) 
+               BN_free(p);
+       if (a) 
+               BN_free(a);
+       if (b)
+               BN_free(b);
+       if (gen)
+               BN_free(gen);
+       if (order)
+               BN_free(order);
+       if (cofactor)
+               BN_free(cofactor);
+       if (ctx)
+               BN_CTX_free(ctx);
+       if (buffer != NULL) 
+               OPENSSL_free(buffer);
+       return(ret);    
+       }
+
+static int print_bin(BIO *fp, const char *name, const unsigned char *buf,
+               size_t len, int off)
+       {
+       size_t i;
+       char str[128];
+
+       if (buf == NULL)
+               return 1;
+       if (off)
+               {
+               if (off > 128)
+                       off=128;
+               memset(str,' ',off);
+               if (BIO_write(fp, str, off) <= 0)
+                       return 0;
+               }
+
+       if (BIO_printf(fp,"%s", name) <= 0)
+               return 0;
+
+       for (i=0; i<len; i++)
+               {
+               if ((i%15) == 0)
+                       {
+                       str[0]='\n';
+                       memset(&(str[1]),' ',off+4);
+                       if (BIO_write(fp, str, off+1+4) <= 0)
+                               return 0;
+                       }
+               if (BIO_printf(fp,"%02x%s",buf[i],((i+1) == len)?"":":") <= 0)
+                       return 0;
+               }
+       if (BIO_write(fp,"\n",1) <= 0)
+               return 0;
+
+       return 1;
+       }
index 71893d5..2a5682e 100644 (file)
@@ -112,10 +112,6 @@ const EC_METHOD *EC_GFp_nist_method(void)
        return &ret;
        }
 
-#if BN_BITS2 == 64
-#define        NO_32_BIT_TYPE
-#endif
-
 int ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src)
        {
        dest->field_mod_func = src->field_mod_func;
@@ -139,34 +135,12 @@ int ec_GFp_nist_group_set_curve(EC_GROUP *group, const BIGNUM *p,
        if (BN_ucmp(BN_get0_nist_prime_192(), p) == 0)
                group->field_mod_func = BN_nist_mod_192;
        else if (BN_ucmp(BN_get0_nist_prime_224(), p) == 0)
-               {
-#ifndef NO_32_BIT_TYPE
                group->field_mod_func = BN_nist_mod_224;
-#else
-               ECerr(EC_F_EC_GFP_NIST_GROUP_SET_CURVE, EC_R_NOT_A_SUPPORTED_NIST_PRIME);
-               goto err;
-#endif
-               }
        else if (BN_ucmp(BN_get0_nist_prime_256(), p) == 0)
-               {
-#ifndef NO_32_BIT_TYPE
                group->field_mod_func = BN_nist_mod_256;
-#else
-               ECerr(EC_F_EC_GFP_NIST_GROUP_SET_CURVE, EC_R_NOT_A_SUPPORTED_NIST_PRIME);
-               goto err;
-#endif
-               }
        else if (BN_ucmp(BN_get0_nist_prime_384(), p) == 0)
-               {
-#ifndef NO_32_BIT_TYPE
                group->field_mod_func = BN_nist_mod_384;
-#else
-               ECerr(EC_F_EC_GFP_NIST_GROUP_SET_CURVE, EC_R_NOT_A_SUPPORTED_NIST_PRIME);
-               goto err;
-#endif
-               }
        else if (BN_ucmp(BN_get0_nist_prime_521(), p) == 0)
-               /* this one works in the NO_32_BIT_TYPE case */
                group->field_mod_func = BN_nist_mod_521;
        else
                {
index 6148d55..7509cb9 100644 (file)
@@ -432,9 +432,7 @@ void prime_field_tests()
        if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
        fprintf(stdout, ".");
        fflush(stdout);
-#if 0
        if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
-#endif
        if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
        if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
        fprintf(stdout, " ok\n");
@@ -478,9 +476,7 @@ void prime_field_tests()
        if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
        fprintf(stdout, ".");
        fflush(stdout);
-#if 0
        if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
-#endif
        if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
        if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
        fprintf(stdout, " ok\n");
@@ -525,9 +521,7 @@ void prime_field_tests()
        if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
        fprintf(stdout, ".");
        fflush(stdout);
-#if 0
        if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
-#endif
        if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
        if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
        fprintf(stdout, " ok\n");
@@ -577,9 +571,7 @@ void prime_field_tests()
        if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
        fprintf(stdout, ".");
        fflush(stdout);
-#if 0
        if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
-#endif
        if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
        if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
        fprintf(stdout, " ok\n");
@@ -635,9 +627,7 @@ void prime_field_tests()
        if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
        fprintf(stdout, ".");
        fflush(stdout);
-#if 0
        if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
-#endif
        if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
        if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
        fprintf(stdout, " ok\n");
@@ -809,7 +799,7 @@ void prime_field_tests()
        if (!EC_POINT_is_at_infinity(group, Q)) ABORT; \
        fprintf(stdout, "."); \
        fflush(stdout); \
-       /* if (!EC_GROUP_precompute_mult(group, ctx)) ABORT; */ \
+       if (!EC_GROUP_precompute_mult(group, ctx)) ABORT; \
        if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT; \
        if (!EC_POINT_is_at_infinity(group, Q)) ABORT; \
        fprintf(stdout, " ok\n"); \
@@ -1336,7 +1326,7 @@ int main(int argc, char *argv[])
 #endif
        CRYPTO_cleanup_all_ex_data();
        ERR_free_strings();
-       ERR_remove_state(0);
+       ERR_remove_thread_state(NULL);
        CRYPTO_mem_leaks_fp(stderr);
        
        return 0;
index 7a7b618..65d8904 100644 (file)
@@ -34,7 +34,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -88,27 +88,26 @@ ech_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 ech_key.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 ech_key.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 ech_key.o: ../../include/openssl/engine.h ../../include/openssl/evp.h
-ech_key.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-ech_key.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-ech_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-ech_key.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-ech_key.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-ech_key.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-ech_key.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-ech_key.o: ech_key.c ech_locl.h
+ech_key.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+ech_key.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+ech_key.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+ech_key.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+ech_key.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+ech_key.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+ech_key.o: ../../include/openssl/x509_vfy.h ech_key.c ech_locl.h
 ech_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
 ech_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 ech_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 ech_lib.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 ech_lib.o: ../../include/openssl/engine.h ../../include/openssl/err.h
-ech_lib.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-ech_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-ech_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-ech_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-ech_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-ech_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-ech_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-ech_lib.o: ../../include/openssl/x509_vfy.h ech_lib.c ech_locl.h
+ech_lib.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+ech_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+ech_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+ech_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+ech_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+ech_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+ech_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+ech_lib.o: ech_lib.c ech_locl.h
 ech_ossl.o: ../../e_os.h ../../include/openssl/asn1.h
 ech_ossl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
 ech_ossl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
index 1575006..212a87e 100644 (file)
@@ -343,7 +343,7 @@ err:
        if (ctx) BN_CTX_free(ctx);
        BIO_free(out);
        CRYPTO_cleanup_all_ex_data();
-       ERR_remove_state(0);
+       ERR_remove_thread_state(NULL);
        CRYPTO_mem_leaks_fp(stderr);
        EXIT(ret);
        return(ret);
index 4d2ede7..6f4b0c9 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/ecdh/ech_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -71,7 +71,7 @@
 static ERR_STRING_DATA ECDH_str_functs[]=
        {
 {ERR_FUNC(ECDH_F_ECDH_COMPUTE_KEY),    "ECDH_compute_key"},
-{ERR_FUNC(ECDH_F_ECDH_DATA_NEW_METHOD),        "ECDH_DATA_NEW_METHOD"},
+{ERR_FUNC(ECDH_F_ECDH_DATA_NEW_METHOD),        "ECDH_DATA_new_method"},
 {0,NULL}
        };
 
index bf22234..4d8ea03 100644 (file)
@@ -103,6 +103,11 @@ int ECDH_set_method(EC_KEY *eckey, const ECDH_METHOD *meth)
        if (ecdh == NULL)
                return 0;
 
+#if 0
+        mtmp = ecdh->meth;
+        if (mtmp->finish)
+               mtmp->finish(eckey);
+#endif
 #ifndef OPENSSL_NO_ENGINE
        if (ecdh->engine)
                {
index 49e2681..e89e0c0 100644 (file)
@@ -34,7 +34,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -97,14 +97,13 @@ 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/fips.h ../../include/openssl/lhash.h
-ecs_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-ecs_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-ecs_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-ecs_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-ecs_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-ecs_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-ecs_lib.o: ecs_lib.c ecs_locl.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
@@ -119,9 +118,8 @@ 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/fips.h ../../include/openssl/lhash.h
-ecs_sign.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-ecs_sign.o: ../../include/openssl/opensslconf.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
@@ -133,11 +131,10 @@ 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/fips.h ../../include/openssl/lhash.h
-ecs_vrf.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-ecs_vrf.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-ecs_vrf.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-ecs_vrf.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-ecs_vrf.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-ecs_vrf.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-ecs_vrf.o: ecs_locl.h ecs_vrf.c
+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
index f20c8ee..e61c539 100644 (file)
@@ -4,7 +4,7 @@
  * \author Written by Nils Larsch for the OpenSSL project
  */
 /* ====================================================================
- * Copyright (c) 2000-2003 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 2000-2005 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -81,156 +81,143 @@ typedef struct ECDSA_SIG_st
        BIGNUM *s;
        } ECDSA_SIG;
 
-/** ECDSA_SIG *ECDSA_SIG_new(void)
- * allocates and initialize a ECDSA_SIG structure
- * \return pointer to a ECDSA_SIG structure or NULL if an error occurred
+/** Allocates and initialize a ECDSA_SIG structure
+ *  \return pointer to a ECDSA_SIG structure or NULL if an error occurred
  */
 ECDSA_SIG *ECDSA_SIG_new(void);
 
-/** ECDSA_SIG_free
- * frees a ECDSA_SIG structure
- * \param a pointer to the ECDSA_SIG structure
+/** frees a ECDSA_SIG structure
+ *  \param  sig  pointer to the ECDSA_SIG structure
  */
-void     ECDSA_SIG_free(ECDSA_SIG *a);
+void     ECDSA_SIG_free(ECDSA_SIG *sig);
 
-/** i2d_ECDSA_SIG
- * DER encode content of ECDSA_SIG object (note: this function modifies *pp
- * (*pp += length of the DER encoded signature)).
- * \param a  pointer to the ECDSA_SIG object
- * \param pp pointer to a unsigned char pointer for the output or NULL
- * \return the length of the DER encoded ECDSA_SIG object or 0 
+/** DER encode content of ECDSA_SIG object (note: this function modifies *pp
+ *  (*pp += length of the DER encoded signature)).
+ *  \param  sig  pointer to the ECDSA_SIG object
+ *  \param  pp   pointer to a unsigned char pointer for the output or NULL
+ *  \return the length of the DER encoded ECDSA_SIG object or 0 
  */
-int      i2d_ECDSA_SIG(const ECDSA_SIG *a, unsigned char **pp);
+int      i2d_ECDSA_SIG(const ECDSA_SIG *sig, unsigned char **pp);
 
-/** d2i_ECDSA_SIG
- * decodes a DER encoded ECDSA signature (note: this function changes *pp
- * (*pp += len)). 
- * \param v pointer to ECDSA_SIG pointer (may be NULL)
- * \param pp buffer with the DER encoded signature
- * \param len bufferlength
- * \return pointer to the decoded ECDSA_SIG structure (or NULL)
+/** Decodes a DER encoded ECDSA signature (note: this function changes *pp
+ *  (*pp += len)). 
+ *  \param  sig  pointer to ECDSA_SIG pointer (may be NULL)
+ *  \param  pp   memory buffer with the DER encoded signature
+ *  \param  len  length of the buffer
+ *  \return pointer to the decoded ECDSA_SIG structure (or NULL)
  */
-ECDSA_SIG *d2i_ECDSA_SIG(ECDSA_SIG **v, const unsigned char **pp, long len);
+ECDSA_SIG *d2i_ECDSA_SIG(ECDSA_SIG **sig, const unsigned char **pp, long len);
 
-/** ECDSA_do_sign
- * computes the ECDSA signature of the given hash value using
- * the supplied private key and returns the created signature.
- * \param dgst pointer to the hash value
- * \param dgst_len length of the hash value
- * \param eckey pointer to the EC_KEY object containing a private EC key
- * \return pointer to a ECDSA_SIG structure or NULL
+/** Computes the ECDSA signature of the given hash value using
+ *  the supplied private key and returns the created signature.
+ *  \param  dgst      pointer to the hash value
+ *  \param  dgst_len  length of the hash value
+ *  \param  eckey     EC_KEY object containing a private EC key
+ *  \return pointer to a ECDSA_SIG structure or NULL if an error occurred
  */
 ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst,int dgst_len,EC_KEY *eckey);
 
-/** ECDSA_do_sign_ex
- * computes ECDSA signature of a given hash value using the supplied
- * private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
- * \param dgst pointer to the hash value to sign
- * \param dgstlen length of the hash value
- * \param kinv optional pointer to a pre-computed inverse k
- * \param rp optional pointer to the pre-computed rp value (see 
- *        ECDSA_sign_setup
- * \param eckey pointer to the EC_KEY object containing a private EC key
- * \return pointer to a ECDSA_SIG structure or NULL
+/** Computes ECDSA signature of a given hash value using the supplied
+ *  private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
+ *  \param  dgst     pointer to the hash value to sign
+ *  \param  dgstlen  length of the hash value
+ *  \param  kinv     BIGNUM with a pre-computed inverse k (optional)
+ *  \param  rp       BIGNUM with a pre-computed rp value (optioanl), 
+ *                   see ECDSA_sign_setup
+ *  \param  eckey    EC_KEY object containing a private EC key
+ *  \return pointer to a ECDSA_SIG structure or NULL if an error occurred
  */
 ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen, 
                const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey);
 
-/** ECDSA_do_verify
- * verifies that the supplied signature is a valid ECDSA
- * signature of the supplied hash value using the supplied public key.
- * \param dgst pointer to the hash value
- * \param dgst_len length of the hash value
- * \param sig  pointer to the ECDSA_SIG structure
- * \param eckey pointer to the EC_KEY object containing a public EC key
- * \return 1 if the signature is valid, 0 if the signature is invalid and -1 on error
+/** Verifies that the supplied signature is a valid ECDSA
+ *  signature of the supplied hash value using the supplied public key.
+ *  \param  dgst      pointer to the hash value
+ *  \param  dgst_len  length of the hash value
+ *  \param  sig       ECDSA_SIG structure
+ *  \param  eckey     EC_KEY object containing a public EC key
+ *  \return 1 if the signature is valid, 0 if the signature is invalid
+ *          and -1 on error
  */
 int      ECDSA_do_verify(const unsigned char *dgst, int dgst_len,
                const ECDSA_SIG *sig, EC_KEY* eckey);
 
 const ECDSA_METHOD *ECDSA_OpenSSL(void);
 
-/** ECDSA_set_default_method
- * sets the default ECDSA method
- * \param meth the new default ECDSA_METHOD
+/** Sets the default ECDSA method
+ *  \param  meth  new default ECDSA_METHOD
  */
 void     ECDSA_set_default_method(const ECDSA_METHOD *meth);
 
-/** ECDSA_get_default_method
- * returns the default ECDSA method
- * \return pointer to ECDSA_METHOD structure containing the default method
+/** Returns the default ECDSA method
+ *  \return pointer to ECDSA_METHOD structure containing the default method
  */
 const ECDSA_METHOD *ECDSA_get_default_method(void);
 
-/** ECDSA_set_method
- * sets method to be used for the ECDSA operations
- * \param eckey pointer to the EC_KEY object
- * \param meth  pointer to the new method
- * \return 1 on success and 0 otherwise 
+/** Sets method to be used for the ECDSA operations
+ *  \param  eckey  EC_KEY object
+ *  \param  meth   new method
+ *  \return 1 on success and 0 otherwise 
  */
 int      ECDSA_set_method(EC_KEY *eckey, const ECDSA_METHOD *meth);
 
-/** ECDSA_size
- * returns the maximum length of the DER encoded signature
- * \param  eckey pointer to a EC_KEY object
- * \return numbers of bytes required for the DER encoded signature
+/** Returns the maximum length of the DER encoded signature
+ *  \param  eckey  EC_KEY object
+ *  \return numbers of bytes required for the DER encoded signature
  */
 int      ECDSA_size(const EC_KEY *eckey);
 
-/** ECDSA_sign_setup
- * precompute parts of the signing operation. 
- * \param eckey pointer to the EC_KEY object containing a private EC key
- * \param ctx  pointer to a BN_CTX object (may be NULL)
- * \param kinv pointer to a BIGNUM pointer for the inverse of k
- * \param rp   pointer to a BIGNUM pointer for x coordinate of k * generator
- * \return 1 on success and 0 otherwise
+/** Precompute parts of the signing operation
+ *  \param  eckey  EC_KEY object containing a private EC key
+ *  \param  ctx    BN_CTX object (optional)
+ *  \param  kinv   BIGNUM pointer for the inverse of k
+ *  \param  rp     BIGNUM pointer for x coordinate of k * generator
+ *  \return 1 on success and 0 otherwise
  */
 int      ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, 
                BIGNUM **rp);
 
-/** ECDSA_sign
- * computes ECDSA signature of a given hash value using the supplied
- * private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
- * \param type this parameter is ignored
- * \param dgst pointer to the hash value to sign
- * \param dgstlen length of the hash value
- * \param sig buffer to hold the DER encoded signature
- * \param siglen pointer to the length of the returned signature
- * \param eckey pointer to the EC_KEY object containing a private EC key
- * \return 1 on success and 0 otherwise
+/** Computes ECDSA signature of a given hash value using the supplied
+ *  private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
+ *  \param  type     this parameter is ignored
+ *  \param  dgst     pointer to the hash value to sign
+ *  \param  dgstlen  length of the hash value
+ *  \param  sig      memory for the DER encoded created signature
+ *  \param  siglen   pointer to the length of the returned signature
+ *  \param  eckey    EC_KEY object containing a private EC key
+ *  \return 1 on success and 0 otherwise
  */
 int      ECDSA_sign(int type, const unsigned char *dgst, int dgstlen, 
                unsigned char *sig, unsigned int *siglen, EC_KEY *eckey);
 
 
-/** ECDSA_sign_ex
- * computes ECDSA signature of a given hash value using the supplied
- * private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
- * \param type this parameter is ignored
- * \param dgst pointer to the hash value to sign
- * \param dgstlen length of the hash value
- * \param sig buffer to hold the DER encoded signature
- * \param siglen pointer to the length of the returned signature
- * \param kinv optional pointer to a pre-computed inverse k
- * \param rp optional pointer to the pre-computed rp value (see 
- *        ECDSA_sign_setup
- * \param eckey pointer to the EC_KEY object containing a private EC key
- * \return 1 on success and 0 otherwise
+/** Computes ECDSA signature of a given hash value using the supplied
+ *  private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
+ *  \param  type     this parameter is ignored
+ *  \param  dgst     pointer to the hash value to sign
+ *  \param  dgstlen  length of the hash value
+ *  \param  sig      buffer to hold the DER encoded signature
+ *  \param  siglen   pointer to the length of the returned signature
+ *  \param  kinv     BIGNUM with a pre-computed inverse k (optional)
+ *  \param  rp       BIGNUM with a pre-computed rp value (optioanl), 
+ *                   see ECDSA_sign_setup
+ *  \param  eckey    EC_KEY object containing a private EC key
+ *  \return 1 on success and 0 otherwise
  */
 int      ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen, 
                unsigned char *sig, unsigned int *siglen, const BIGNUM *kinv,
                const BIGNUM *rp, EC_KEY *eckey);
 
-/** ECDSA_verify
- * verifies that the given signature is valid ECDSA signature
- * of the supplied hash value using the specified public key.
- * \param type this parameter is ignored
- * \param dgst pointer to the hash value 
- * \param dgstlen length of the hash value
- * \param sig  pointer to the DER encoded signature
- * \param siglen length of the DER encoded signature
- * \param eckey pointer to the EC_KEY object containing a public EC key
- * \return 1 if the signature is valid, 0 if the signature is invalid and -1 on error
+/** Verifies that the given signature is valid ECDSA signature
+ *  of the supplied hash value using the specified public key.
+ *  \param  type     this parameter is ignored
+ *  \param  dgst     pointer to the hash value 
+ *  \param  dgstlen  length of the hash value
+ *  \param  sig      pointer to the DER encoded signature
+ *  \param  siglen   length of the DER encoded signature
+ *  \param  eckey    EC_KEY object containing a public EC key
+ *  \return 1 if the signature is valid, 0 if the signature is invalid
+ *          and -1 on error
  */
 int      ECDSA_verify(int type, const unsigned char *dgst, int dgstlen, 
                const unsigned char *sig, int siglen, EC_KEY *eckey);
index b07e312..54cfb8c 100644 (file)
@@ -168,10 +168,9 @@ int fbytes(unsigned char *buf, int num)
                return 0;
                }
        fbytes_counter ++;
-       ret = BN_bn2bin(tmp, buf);      
-       if (ret == 0 || ret != num)
+       if (num != BN_num_bytes(tmp) || !BN_bn2bin(tmp, buf))
                ret = 0;
-       else
+       else 
                ret = 1;
        if (tmp)
                BN_free(tmp);
@@ -287,9 +286,12 @@ int test_builtin(BIO *out)
        size_t          crv_len = 0, n = 0;
        EC_KEY          *eckey = NULL, *wrong_eckey = NULL;
        EC_GROUP        *group;
+       ECDSA_SIG       *ecdsa_sig = NULL;
        unsigned char   digest[20], wrong_digest[20];
-       unsigned char   *signature = NULL; 
-       unsigned int    sig_len;
+       unsigned char   *signature = NULL;
+       unsigned char   *sig_ptr;
+       unsigned char   *raw_buf = NULL;
+       unsigned int    sig_len, degree, r_len, s_len, bn_len, buf_len;
        int             nid, ret =  0;
        
        /* fill digest values with some random data */
@@ -339,7 +341,8 @@ int test_builtin(BIO *out)
                if (EC_KEY_set_group(eckey, group) == 0)
                        goto builtin_err;
                EC_GROUP_free(group);
-               if (EC_GROUP_get_degree(EC_KEY_get0_group(eckey)) < 160)
+               degree = EC_GROUP_get_degree(EC_KEY_get0_group(eckey));
+               if (degree < 160)
                        /* drop the curve */ 
                        {
                        EC_KEY_free(eckey);
@@ -415,26 +418,89 @@ int test_builtin(BIO *out)
                        }
                BIO_printf(out, ".");
                (void)BIO_flush(out);
-               /* modify a single byte of the signature */
-               offset = signature[10] % sig_len;
-               dirt   = signature[11];
-               signature[offset] ^= dirt ? dirt : 1; 
+               /* wrong length */
+               if (ECDSA_verify(0, digest, 20, signature, sig_len - 1,
+                       eckey) == 1)
+                       {
+                       BIO_printf(out, " failed\n");
+                       goto builtin_err;
+                       }
+               BIO_printf(out, ".");
+               (void)BIO_flush(out);
+
+               /* Modify a single byte of the signature: to ensure we don't
+                * garble the ASN1 structure, we read the raw signature and
+                * modify a byte in one of the bignums directly. */
+               sig_ptr = signature;
+               if ((ecdsa_sig = d2i_ECDSA_SIG(NULL, &sig_ptr, sig_len)) == NULL)
+                       {
+                       BIO_printf(out, " failed\n");
+                       goto builtin_err;
+                       }
+
+               /* Store the two BIGNUMs in raw_buf. */
+               r_len = BN_num_bytes(ecdsa_sig->r);
+               s_len = BN_num_bytes(ecdsa_sig->s);
+               bn_len = (degree + 7) / 8;
+               if ((r_len > bn_len) || (s_len > bn_len))
+                       {
+                       BIO_printf(out, " failed\n");
+                       goto builtin_err;
+                       }
+               buf_len = 2 * bn_len;
+               if ((raw_buf = OPENSSL_malloc(buf_len)) == NULL)
+                       goto builtin_err;
+               /* Pad the bignums with leading zeroes. */
+               memset(raw_buf, 0, buf_len);
+               BN_bn2bin(ecdsa_sig->r, raw_buf + bn_len - r_len);
+               BN_bn2bin(ecdsa_sig->s, raw_buf + buf_len - s_len);
+
+               /* Modify a single byte in the buffer. */
+               offset = raw_buf[10] % buf_len;
+               dirt   = raw_buf[11] ? raw_buf[11] : 1;
+               raw_buf[offset] ^= dirt;
+               /* Now read the BIGNUMs back in from raw_buf. */
+               if ((BN_bin2bn(raw_buf, bn_len, ecdsa_sig->r) == NULL) ||
+                       (BN_bin2bn(raw_buf + bn_len, bn_len, ecdsa_sig->s) == NULL))
+                       goto builtin_err;
+
+               sig_ptr = signature;
+               sig_len = i2d_ECDSA_SIG(ecdsa_sig, &sig_ptr);
                if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) == 1)
                        {
                        BIO_printf(out, " failed\n");
                        goto builtin_err;
                        }
+               /* Sanity check: undo the modification and verify signature. */
+               raw_buf[offset] ^= dirt;
+               if ((BN_bin2bn(raw_buf, bn_len, ecdsa_sig->r) == NULL) ||
+                       (BN_bin2bn(raw_buf + bn_len, bn_len, ecdsa_sig->s) == NULL))
+                       goto builtin_err;
+
+               sig_ptr = signature;
+               sig_len = i2d_ECDSA_SIG(ecdsa_sig, &sig_ptr);
+               if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) != 1)
+                       {
+                       BIO_printf(out, " failed\n");
+                       goto builtin_err;
+                       }
                BIO_printf(out, ".");
                (void)BIO_flush(out);
                
                BIO_printf(out, " ok\n");
                /* cleanup */
+               /* clean bogus errors */
+               ERR_clear_error();
                OPENSSL_free(signature);
                signature = NULL;
                EC_KEY_free(eckey);
                eckey = NULL;
                EC_KEY_free(wrong_eckey);
                wrong_eckey = NULL;
+               ECDSA_SIG_free(ecdsa_sig);
+               ecdsa_sig = NULL;
+               OPENSSL_free(raw_buf);
+               raw_buf = NULL;
                }
 
        ret = 1;        
@@ -443,8 +509,12 @@ builtin_err:
                EC_KEY_free(eckey);
        if (wrong_eckey)
                EC_KEY_free(wrong_eckey);
+       if (ecdsa_sig)
+               ECDSA_SIG_free(ecdsa_sig);
        if (signature)
                OPENSSL_free(signature);
+       if (raw_buf)
+               OPENSSL_free(raw_buf);
        if (curves)
                OPENSSL_free(curves);
 
@@ -490,7 +560,7 @@ err:
        if (ret)
                ERR_print_errors(out);
        CRYPTO_cleanup_all_ex_data();
-       ERR_remove_state(0);
+       ERR_remove_thread_state(NULL);
        ERR_free_strings();
        CRYPTO_mem_leaks(out);
        if (out != NULL)
index d2a5373..98e38d5 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/ecdsa/ecs_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
index 551cf50..1bbf328 100644 (file)
@@ -144,6 +144,14 @@ static int ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp,
                        }
                while (BN_is_zero(k));
 
+               /* We do not want timing information to leak the length of k,
+                * so we compute G*k using an equivalent scalar of fixed
+                * bit-length. */
+
+               if (!BN_add(k, k, order)) goto err;
+               if (BN_num_bits(k) <= BN_num_bits(order))
+                       if (!BN_add(k, k, order)) goto err;
+
                /* compute r the x-coordinate of generator * k */
                if (!EC_POINT_mul(group, tmp_point, k, NULL, NULL, ctx))
                {
index b52fa48..9c21482 100644 (file)
@@ -20,13 +20,13 @@ LIB=$(TOP)/libcrypto.a
 LIBSRC= eng_err.c eng_lib.c eng_list.c eng_init.c eng_ctrl.c \
        eng_table.c eng_pkey.c eng_fat.c eng_all.c \
        tb_rsa.c tb_dsa.c tb_ecdsa.c tb_dh.c tb_ecdh.c tb_rand.c tb_store.c \
-       tb_cipher.c tb_digest.c \
-       eng_openssl.c eng_cnf.c eng_dyn.c eng_cryptodev.c eng_padlock.c
+       tb_cipher.c tb_digest.c tb_pkmeth.c tb_asnmth.c \
+       eng_openssl.c eng_cnf.c eng_dyn.c eng_cryptodev.c
 LIBOBJ= eng_err.o eng_lib.o eng_list.o eng_init.o eng_ctrl.o \
        eng_table.o eng_pkey.o eng_fat.o eng_all.o \
        tb_rsa.o tb_dsa.o tb_ecdsa.o tb_dh.o tb_ecdh.o tb_rand.o tb_store.o \
-       tb_cipher.o tb_digest.o \
-       eng_openssl.o eng_cnf.o eng_dyn.o eng_cryptodev.o eng_padlock.o
+       tb_cipher.o tb_digest.o tb_pkmeth.o tb_asnmth.o \
+       eng_openssl.o eng_cnf.o eng_dyn.o eng_cryptodev.o
 
 SRC= $(LIBSRC)
 
@@ -41,7 +41,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -88,54 +88,50 @@ eng_all.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 eng_all.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 eng_all.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
 eng_all.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-eng_all.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-eng_all.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-eng_all.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-eng_all.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-eng_all.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-eng_all.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-eng_all.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-eng_all.o: ../cryptlib.h eng_all.c eng_int.h
+eng_all.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+eng_all.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+eng_all.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+eng_all.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+eng_all.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+eng_all.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+eng_all.o: ../../include/openssl/x509_vfy.h ../cryptlib.h eng_all.c eng_int.h
 eng_cnf.o: ../../e_os.h ../../include/openssl/asn1.h
 eng_cnf.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 eng_cnf.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 eng_cnf.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 eng_cnf.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 eng_cnf.o: ../../include/openssl/engine.h ../../include/openssl/err.h
-eng_cnf.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-eng_cnf.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-eng_cnf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-eng_cnf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-eng_cnf.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-eng_cnf.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-eng_cnf.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-eng_cnf.o: ../../include/openssl/x509_vfy.h ../cryptlib.h eng_cnf.c eng_int.h
+eng_cnf.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+eng_cnf.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+eng_cnf.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+eng_cnf.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+eng_cnf.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+eng_cnf.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+eng_cnf.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+eng_cnf.o: ../cryptlib.h eng_cnf.c eng_int.h
 eng_cryptodev.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
 eng_cryptodev.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
-eng_cryptodev.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
-eng_cryptodev.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
+eng_cryptodev.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 eng_cryptodev.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 eng_cryptodev.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
-eng_cryptodev.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-eng_cryptodev.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
+eng_cryptodev.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
 eng_cryptodev.o: ../../include/openssl/obj_mac.h
 eng_cryptodev.o: ../../include/openssl/objects.h
 eng_cryptodev.o: ../../include/openssl/opensslconf.h
 eng_cryptodev.o: ../../include/openssl/opensslv.h
 eng_cryptodev.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-eng_cryptodev.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
-eng_cryptodev.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-eng_cryptodev.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-eng_cryptodev.o: ../../include/openssl/x509_vfy.h eng_cryptodev.c
+eng_cryptodev.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+eng_cryptodev.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+eng_cryptodev.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+eng_cryptodev.o: eng_cryptodev.c
 eng_ctrl.o: ../../e_os.h ../../include/openssl/asn1.h
 eng_ctrl.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 eng_ctrl.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 eng_ctrl.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 eng_ctrl.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
 eng_ctrl.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-eng_ctrl.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-eng_ctrl.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-eng_ctrl.o: ../../include/openssl/opensslconf.h
+eng_ctrl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+eng_ctrl.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 eng_ctrl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 eng_ctrl.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 eng_ctrl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -147,50 +143,49 @@ eng_dyn.o: ../../include/openssl/crypto.h ../../include/openssl/dso.h
 eng_dyn.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 eng_dyn.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 eng_dyn.o: ../../include/openssl/engine.h ../../include/openssl/err.h
-eng_dyn.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-eng_dyn.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-eng_dyn.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-eng_dyn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-eng_dyn.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-eng_dyn.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-eng_dyn.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-eng_dyn.o: ../../include/openssl/x509_vfy.h ../cryptlib.h eng_dyn.c eng_int.h
+eng_dyn.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+eng_dyn.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+eng_dyn.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+eng_dyn.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+eng_dyn.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+eng_dyn.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+eng_dyn.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+eng_dyn.o: ../cryptlib.h eng_dyn.c eng_int.h
 eng_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
 eng_err.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 eng_err.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 eng_err.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 eng_err.o: ../../include/openssl/engine.h ../../include/openssl/err.h
-eng_err.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-eng_err.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-eng_err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-eng_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-eng_err.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-eng_err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-eng_err.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-eng_err.o: ../../include/openssl/x509_vfy.h eng_err.c
+eng_err.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+eng_err.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+eng_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+eng_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+eng_err.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+eng_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+eng_err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+eng_err.o: eng_err.c
 eng_fat.o: ../../e_os.h ../../include/openssl/asn1.h
 eng_fat.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 eng_fat.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 eng_fat.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 eng_fat.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 eng_fat.o: ../../include/openssl/engine.h ../../include/openssl/err.h
-eng_fat.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-eng_fat.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-eng_fat.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-eng_fat.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-eng_fat.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-eng_fat.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-eng_fat.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-eng_fat.o: ../../include/openssl/x509_vfy.h ../cryptlib.h eng_fat.c eng_int.h
+eng_fat.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+eng_fat.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+eng_fat.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+eng_fat.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+eng_fat.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+eng_fat.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+eng_fat.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+eng_fat.o: ../cryptlib.h eng_fat.c eng_int.h
 eng_init.o: ../../e_os.h ../../include/openssl/asn1.h
 eng_init.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 eng_init.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 eng_init.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 eng_init.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
 eng_init.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-eng_init.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-eng_init.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-eng_init.o: ../../include/openssl/opensslconf.h
+eng_init.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+eng_init.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 eng_init.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 eng_init.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 eng_init.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -202,23 +197,22 @@ eng_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 eng_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 eng_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
 eng_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-eng_lib.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-eng_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-eng_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-eng_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-eng_lib.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
-eng_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-eng_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-eng_lib.o: ../../include/openssl/x509_vfy.h ../cryptlib.h eng_int.h eng_lib.c
+eng_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+eng_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+eng_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+eng_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
+eng_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+eng_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+eng_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+eng_lib.o: ../cryptlib.h eng_int.h eng_lib.c
 eng_list.o: ../../e_os.h ../../include/openssl/asn1.h
 eng_list.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 eng_list.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 eng_list.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 eng_list.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
 eng_list.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-eng_list.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-eng_list.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-eng_list.o: ../../include/openssl/opensslconf.h
+eng_list.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+eng_list.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 eng_list.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 eng_list.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 eng_list.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -231,9 +225,8 @@ eng_openssl.o: ../../include/openssl/dsa.h ../../include/openssl/dso.h
 eng_openssl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 eng_openssl.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 eng_openssl.o: ../../include/openssl/engine.h ../../include/openssl/err.h
-eng_openssl.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-eng_openssl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-eng_openssl.o: ../../include/openssl/objects.h
+eng_openssl.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+eng_openssl.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
 eng_openssl.o: ../../include/openssl/opensslconf.h
 eng_openssl.o: ../../include/openssl/opensslv.h
 eng_openssl.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
@@ -243,31 +236,14 @@ eng_openssl.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
 eng_openssl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
 eng_openssl.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
 eng_openssl.o: ../../include/openssl/x509_vfy.h ../cryptlib.h eng_openssl.c
-eng_padlock.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
-eng_padlock.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
-eng_padlock.o: ../../include/openssl/crypto.h ../../include/openssl/dso.h
-eng_padlock.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-eng_padlock.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
-eng_padlock.o: ../../include/openssl/engine.h ../../include/openssl/err.h
-eng_padlock.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-eng_padlock.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-eng_padlock.o: ../../include/openssl/objects.h
-eng_padlock.o: ../../include/openssl/opensslconf.h
-eng_padlock.o: ../../include/openssl/opensslv.h
-eng_padlock.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-eng_padlock.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
-eng_padlock.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-eng_padlock.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-eng_padlock.o: ../../include/openssl/x509_vfy.h eng_padlock.c
 eng_pkey.o: ../../e_os.h ../../include/openssl/asn1.h
 eng_pkey.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 eng_pkey.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 eng_pkey.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 eng_pkey.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
 eng_pkey.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-eng_pkey.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-eng_pkey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-eng_pkey.o: ../../include/openssl/opensslconf.h
+eng_pkey.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+eng_pkey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 eng_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 eng_pkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 eng_pkey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -279,8 +255,8 @@ eng_table.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 eng_table.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 eng_table.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
 eng_table.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-eng_table.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-eng_table.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+eng_table.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+eng_table.o: ../../include/openssl/objects.h
 eng_table.o: ../../include/openssl/opensslconf.h
 eng_table.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 eng_table.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
@@ -288,14 +264,29 @@ eng_table.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
 eng_table.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
 eng_table.o: ../../include/openssl/x509_vfy.h ../cryptlib.h eng_int.h
 eng_table.o: eng_table.c
+tb_asnmth.o: ../../e_os.h ../../include/openssl/asn1.h
+tb_asnmth.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
+tb_asnmth.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+tb_asnmth.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+tb_asnmth.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
+tb_asnmth.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+tb_asnmth.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+tb_asnmth.o: ../../include/openssl/objects.h
+tb_asnmth.o: ../../include/openssl/opensslconf.h
+tb_asnmth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+tb_asnmth.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+tb_asnmth.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+tb_asnmth.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+tb_asnmth.o: ../../include/openssl/x509_vfy.h ../asn1/asn1_locl.h ../cryptlib.h
+tb_asnmth.o: eng_int.h tb_asnmth.c
 tb_cipher.o: ../../e_os.h ../../include/openssl/asn1.h
 tb_cipher.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 tb_cipher.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 tb_cipher.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 tb_cipher.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
 tb_cipher.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-tb_cipher.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-tb_cipher.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+tb_cipher.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+tb_cipher.o: ../../include/openssl/objects.h
 tb_cipher.o: ../../include/openssl/opensslconf.h
 tb_cipher.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 tb_cipher.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
@@ -308,22 +299,22 @@ tb_dh.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 tb_dh.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 tb_dh.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 tb_dh.o: ../../include/openssl/engine.h ../../include/openssl/err.h
-tb_dh.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-tb_dh.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-tb_dh.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-tb_dh.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-tb_dh.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-tb_dh.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-tb_dh.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-tb_dh.o: ../../include/openssl/x509_vfy.h ../cryptlib.h eng_int.h tb_dh.c
+tb_dh.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+tb_dh.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+tb_dh.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+tb_dh.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+tb_dh.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+tb_dh.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+tb_dh.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+tb_dh.o: ../cryptlib.h eng_int.h tb_dh.c
 tb_digest.o: ../../e_os.h ../../include/openssl/asn1.h
 tb_digest.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 tb_digest.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 tb_digest.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 tb_digest.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
 tb_digest.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-tb_digest.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-tb_digest.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+tb_digest.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+tb_digest.o: ../../include/openssl/objects.h
 tb_digest.o: ../../include/openssl/opensslconf.h
 tb_digest.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 tb_digest.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
@@ -336,78 +327,89 @@ tb_dsa.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 tb_dsa.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 tb_dsa.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 tb_dsa.o: ../../include/openssl/engine.h ../../include/openssl/err.h
-tb_dsa.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-tb_dsa.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-tb_dsa.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-tb_dsa.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-tb_dsa.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-tb_dsa.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-tb_dsa.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-tb_dsa.o: ../../include/openssl/x509_vfy.h ../cryptlib.h eng_int.h tb_dsa.c
+tb_dsa.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+tb_dsa.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+tb_dsa.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+tb_dsa.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+tb_dsa.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+tb_dsa.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+tb_dsa.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+tb_dsa.o: ../cryptlib.h eng_int.h tb_dsa.c
 tb_ecdh.o: ../../e_os.h ../../include/openssl/asn1.h
 tb_ecdh.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 tb_ecdh.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 tb_ecdh.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 tb_ecdh.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
 tb_ecdh.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-tb_ecdh.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-tb_ecdh.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-tb_ecdh.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-tb_ecdh.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-tb_ecdh.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-tb_ecdh.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-tb_ecdh.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-tb_ecdh.o: ../cryptlib.h eng_int.h tb_ecdh.c
+tb_ecdh.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+tb_ecdh.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+tb_ecdh.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+tb_ecdh.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+tb_ecdh.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+tb_ecdh.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+tb_ecdh.o: ../../include/openssl/x509_vfy.h ../cryptlib.h eng_int.h tb_ecdh.c
 tb_ecdsa.o: ../../e_os.h ../../include/openssl/asn1.h
 tb_ecdsa.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 tb_ecdsa.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 tb_ecdsa.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 tb_ecdsa.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
 tb_ecdsa.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-tb_ecdsa.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-tb_ecdsa.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-tb_ecdsa.o: ../../include/openssl/opensslconf.h
+tb_ecdsa.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+tb_ecdsa.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 tb_ecdsa.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 tb_ecdsa.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 tb_ecdsa.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
 tb_ecdsa.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
 tb_ecdsa.o: ../../include/openssl/x509_vfy.h ../cryptlib.h eng_int.h tb_ecdsa.c
+tb_pkmeth.o: ../../e_os.h ../../include/openssl/asn1.h
+tb_pkmeth.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
+tb_pkmeth.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+tb_pkmeth.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+tb_pkmeth.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
+tb_pkmeth.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+tb_pkmeth.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+tb_pkmeth.o: ../../include/openssl/objects.h
+tb_pkmeth.o: ../../include/openssl/opensslconf.h
+tb_pkmeth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+tb_pkmeth.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+tb_pkmeth.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+tb_pkmeth.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+tb_pkmeth.o: ../../include/openssl/x509_vfy.h ../cryptlib.h eng_int.h
+tb_pkmeth.o: tb_pkmeth.c
 tb_rand.o: ../../e_os.h ../../include/openssl/asn1.h
 tb_rand.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 tb_rand.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 tb_rand.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 tb_rand.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
 tb_rand.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-tb_rand.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-tb_rand.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-tb_rand.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-tb_rand.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-tb_rand.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-tb_rand.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-tb_rand.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-tb_rand.o: ../cryptlib.h eng_int.h tb_rand.c
+tb_rand.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+tb_rand.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+tb_rand.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+tb_rand.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+tb_rand.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+tb_rand.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+tb_rand.o: ../../include/openssl/x509_vfy.h ../cryptlib.h eng_int.h tb_rand.c
 tb_rsa.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 tb_rsa.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 tb_rsa.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 tb_rsa.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 tb_rsa.o: ../../include/openssl/engine.h ../../include/openssl/err.h
-tb_rsa.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-tb_rsa.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-tb_rsa.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-tb_rsa.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-tb_rsa.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-tb_rsa.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-tb_rsa.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-tb_rsa.o: ../../include/openssl/x509_vfy.h ../cryptlib.h eng_int.h tb_rsa.c
+tb_rsa.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+tb_rsa.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+tb_rsa.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+tb_rsa.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+tb_rsa.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+tb_rsa.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+tb_rsa.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+tb_rsa.o: ../cryptlib.h eng_int.h tb_rsa.c
 tb_store.o: ../../e_os.h ../../include/openssl/asn1.h
 tb_store.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 tb_store.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 tb_store.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 tb_store.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
 tb_store.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-tb_store.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-tb_store.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-tb_store.o: ../../include/openssl/opensslconf.h
+tb_store.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+tb_store.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 tb_store.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 tb_store.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 tb_store.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
index f29c167..22c1204 100644 (file)
 
 void ENGINE_load_builtin_engines(void)
        {
+#if 0
        /* There's no longer any need for an "openssl" ENGINE unless, one day,
         * it is the *only* way for standard builtin implementations to be be
         * accessed (ie. it would be possible to statically link binaries with
         * *no* builtin implementations). */
-#if 0
        ENGINE_load_openssl();
 #endif
-#if !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_PADLOCK)
-       ENGINE_load_padlock();
+#if !defined(OPENSSL_NO_HW) && (defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV))
+       ENGINE_load_cryptodev();
 #endif
        ENGINE_load_dynamic();
 #ifndef OPENSSL_NO_STATIC_ENGINE
@@ -98,14 +98,15 @@ void ENGINE_load_builtin_engines(void)
 #ifndef OPENSSL_NO_HW_UBSEC
        ENGINE_load_ubsec();
 #endif
+#ifndef OPENSSL_NO_HW_PADLOCK
+       ENGINE_load_padlock();
 #endif
-#if !defined(OPENSSL_NO_GMP) && !defined(OPENSSL_NO_HW_GMP)
-       ENGINE_load_gmp();
 #endif
+#ifndef OPENSSL_NO_GOST
+       ENGINE_load_gost();
 #endif
-#ifndef OPENSSL_NO_HW
-#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV)
-       ENGINE_load_cryptodev();
+#ifndef OPENSSL_NO_GMP
+       ENGINE_load_gmp();
 #endif
 #if defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_NO_CAPIENG)
        ENGINE_load_capi();
@@ -113,7 +114,7 @@ void ENGINE_load_builtin_engines(void)
 #endif
        }
 
-#if defined(__OpenBSD__) || defined(__FreeBSD__)
+#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV)
 void ENGINE_setup_bsd_cryptodev(void) {
        static int bsd_cryptodev_default_loaded = 0;
        if (!bsd_cryptodev_default_loaded) {
index eef1e2d..52f4ca3 100644 (file)
 #include <openssl/engine.h>
 #include <openssl/evp.h>
 #include <openssl/bn.h>
-#include <openssl/dsa.h>
-#include <openssl/rsa.h>
-#include <openssl/dh.h>
-#include <openssl/err.h>
 
 #if (defined(__unix__) || defined(unix)) && !defined(USG) && \
        (defined(OpenBSD) || defined(__FreeBSD__))
@@ -59,6 +55,10 @@ ENGINE_load_cryptodev(void)
  
 #include <sys/types.h>
 #include <crypto/cryptodev.h>
+#include <crypto/dh/dh.h>
+#include <crypto/dsa/dsa.h>
+#include <crypto/err/err.h>
+#include <crypto/rsa/rsa.h>
 #include <sys/ioctl.h>
 #include <errno.h>
 #include <stdio.h>
@@ -72,6 +72,16 @@ ENGINE_load_cryptodev(void)
 struct dev_crypto_state {
        struct session_op d_sess;
        int d_fd;
+
+#ifdef USE_CRYPTODEV_DIGESTS
+       char dummy_mac_key[HASH_MAX_LEN];
+
+       unsigned char digest_res[HASH_MAX_LEN];
+       char *mac_data;
+       int mac_len;
+
+       int copy;
+#endif
 };
 
 static u_int32_t cryptodev_asymfeat = 0;
@@ -79,15 +89,14 @@ static u_int32_t cryptodev_asymfeat = 0;
 static int get_asym_dev_crypto(void);
 static int open_dev_crypto(void);
 static int get_dev_crypto(void);
-static int cryptodev_max_iv(int cipher);
-static int cryptodev_key_length_valid(int cipher, int len);
-static int cipher_nid_to_cryptodev(int nid);
 static int get_cryptodev_ciphers(const int **cnids);
-/*static int get_cryptodev_digests(const int **cnids);*/
+#ifdef USE_CRYPTODEV_DIGESTS
+static int get_cryptodev_digests(const int **cnids);
+#endif
 static int cryptodev_usable_ciphers(const int **nids);
 static int cryptodev_usable_digests(const int **nids);
 static int cryptodev_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-    const unsigned char *in, unsigned int inl);
+    const unsigned char *in, size_t inl);
 static int cryptodev_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
     const unsigned char *iv, int enc);
 static int cryptodev_cleanup(EVP_CIPHER_CTX *ctx);
@@ -121,7 +130,7 @@ static int cryptodev_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a,
 static int cryptodev_dh_compute_key(unsigned char *key,
     const BIGNUM *pub_key, DH *dh);
 static int cryptodev_ctrl(ENGINE *e, int cmd, long i, void *p,
-    void (*f)());
+    void (*f)(void));
 void ENGINE_load_cryptodev(void);
 
 static const ENGINE_CMD_DEFN cryptodev_defns[] = {
@@ -134,27 +143,32 @@ static struct {
        int     ivmax;
        int     keylen;
 } ciphers[] = {
+       { CRYPTO_ARC4,                  NID_rc4,                0,      16, },
        { CRYPTO_DES_CBC,               NID_des_cbc,            8,       8, },
        { CRYPTO_3DES_CBC,              NID_des_ede3_cbc,       8,      24, },
        { CRYPTO_AES_CBC,               NID_aes_128_cbc,        16,     16, },
+       { CRYPTO_AES_CBC,               NID_aes_192_cbc,        16,     24, },
+       { CRYPTO_AES_CBC,               NID_aes_256_cbc,        16,     32, },
        { CRYPTO_BLF_CBC,               NID_bf_cbc,             8,      16, },
        { CRYPTO_CAST_CBC,              NID_cast5_cbc,          8,      16, },
        { CRYPTO_SKIPJACK_CBC,          NID_undef,              0,       0, },
        { 0,                            NID_undef,              0,       0, },
 };
 
-#if 0
+#ifdef USE_CRYPTODEV_DIGESTS
 static struct {
        int     id;
        int     nid;
+       int     keylen;
 } digests[] = {
-       { CRYPTO_SHA1_HMAC,             NID_hmacWithSHA1,       },
-       { CRYPTO_RIPEMD160_HMAC,        NID_ripemd160,          },
-       { CRYPTO_MD5_KPDK,              NID_undef,              },
-       { CRYPTO_SHA1_KPDK,             NID_undef,              },
-       { CRYPTO_MD5,                   NID_md5,                },
-       { CRYPTO_SHA1,                  NID_undef,              },
-       { 0,                            NID_undef,              },
+       { CRYPTO_MD5_HMAC,              NID_hmacWithMD5,        16},
+       { CRYPTO_SHA1_HMAC,             NID_hmacWithSHA1,       20},
+       { CRYPTO_RIPEMD160_HMAC,        NID_ripemd160,          16/*?*/},
+       { CRYPTO_MD5_KPDK,              NID_undef,              0},
+       { CRYPTO_SHA1_KPDK,             NID_undef,              0},
+       { CRYPTO_MD5,                   NID_md5,                16},
+       { CRYPTO_SHA1,                  NID_sha1,               20},
+       { 0,                            NID_undef,              0},
 };
 #endif
 
@@ -209,50 +223,6 @@ get_asym_dev_crypto(void)
 }
 
 /*
- * XXXX this needs to be set for each alg - and determined from
- * a running card.
- */
-static int
-cryptodev_max_iv(int cipher)
-{
-       int i;
-
-       for (i = 0; ciphers[i].id; i++)
-               if (ciphers[i].id == cipher)
-                       return (ciphers[i].ivmax);
-       return (0);
-}
-
-/*
- * XXXX this needs to be set for each alg - and determined from
- * a running card. For now, fake it out - but most of these
- * for real devices should return 1 for the supported key
- * sizes the device can handle.
- */
-static int
-cryptodev_key_length_valid(int cipher, int len)
-{
-       int i;
-
-       for (i = 0; ciphers[i].id; i++)
-               if (ciphers[i].id == cipher)
-                       return (ciphers[i].keylen == len);
-       return (0);
-}
-
-/* convert libcrypto nids to cryptodev */
-static int
-cipher_nid_to_cryptodev(int nid)
-{
-       int i;
-
-       for (i = 0; ciphers[i].id; i++)
-               if (ciphers[i].nid == nid)
-                       return (ciphers[i].id);
-       return (0);
-}
-
-/*
  * Find out what ciphers /dev/crypto will let us have a session for.
  * XXX note, that some of these openssl doesn't deal with yet!
  * returning them here is harmless, as long as we return NULL
@@ -270,7 +240,7 @@ get_cryptodev_ciphers(const int **cnids)
                return (0);
        }
        memset(&sess, 0, sizeof(sess));
-       sess.key = (caddr_t)"123456781234567812345678";
+       sess.key = (caddr_t)"123456789abcdefghijklmno";
 
        for (i = 0; ciphers[i].id && count < CRYPTO_ALGORITHM_MAX; i++) {
                if (ciphers[i].nid == NID_undef)
@@ -291,7 +261,7 @@ get_cryptodev_ciphers(const int **cnids)
        return (count);
 }
 
-#if 0  /* unused */
+#ifdef USE_CRYPTODEV_DIGESTS
 /*
  * Find out what digests /dev/crypto will let us have a session for.
  * XXX note, that some of these openssl doesn't deal with yet!
@@ -310,10 +280,12 @@ get_cryptodev_digests(const int **cnids)
                return (0);
        }
        memset(&sess, 0, sizeof(sess));
+       sess.mackey = (caddr_t)"123456789abcdefghijklmno";
        for (i = 0; digests[i].id && count < CRYPTO_ALGORITHM_MAX; i++) {
                if (digests[i].nid == NID_undef)
                        continue;
                sess.mac = digests[i].id;
+               sess.mackeylen = digests[i].keylen;
                sess.cipher = 0;
                if (ioctl(fd, CIOCGSESSION, &sess) != -1 &&
                    ioctl(fd, CIOCFSESSION, &sess.ses) != -1)
@@ -327,8 +299,7 @@ get_cryptodev_digests(const int **cnids)
                *cnids = NULL;
        return (count);
 }
-
-#endif
+#endif  /* 0 */
 
 /*
  * Find the useable ciphers|digests from dev/crypto - this is the first
@@ -360,6 +331,9 @@ cryptodev_usable_ciphers(const int **nids)
 static int
 cryptodev_usable_digests(const int **nids)
 {
+#ifdef USE_CRYPTODEV_DIGESTS
+       return (get_cryptodev_digests(nids));
+#else
        /*
         * XXXX just disable all digests for now, because it sucks.
         * we need a better way to decide this - i.e. I may not
@@ -374,11 +348,12 @@ cryptodev_usable_digests(const int **nids)
         */
        *nids = NULL;
        return (0);
+#endif
 }
 
 static int
 cryptodev_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-    const unsigned char *in, unsigned int inl)
+    const unsigned char *in, size_t inl)
 {
        struct crypt_op cryp;
        struct dev_crypto_state *state = ctx->cipher_data;
@@ -436,23 +411,27 @@ cryptodev_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
 {
        struct dev_crypto_state *state = ctx->cipher_data;
        struct session_op *sess = &state->d_sess;
-       int cipher;
+       int cipher = -1, i;
 
-       if ((cipher = cipher_nid_to_cryptodev(ctx->cipher->nid)) == NID_undef)
-               return (0);
-
-       if (ctx->cipher->iv_len > cryptodev_max_iv(cipher))
-               return (0);
+       for (i = 0; ciphers[i].id; i++)
+               if (ctx->cipher->nid == ciphers[i].nid &&
+                   ctx->cipher->iv_len <= ciphers[i].ivmax &&
+                   ctx->key_len == ciphers[i].keylen) {
+                       cipher = ciphers[i].id;
+                       break;
+               }
 
-       if (!cryptodev_key_length_valid(cipher, ctx->key_len))
+       if (!ciphers[i].id) {
+               state->d_fd = -1;
                return (0);
+       }
 
        memset(sess, 0, sizeof(struct session_op));
 
        if ((state->d_fd = get_dev_crypto()) < 0)
                return (0);
 
-       sess->key = (char *)key;
+       sess->key = (caddr_t)key;
        sess->keylen = ctx->key_len;
        sess->cipher = cipher;
 
@@ -505,6 +484,20 @@ cryptodev_cleanup(EVP_CIPHER_CTX *ctx)
  * gets called when libcrypto requests a cipher NID.
  */
 
+/* RC4 */
+const EVP_CIPHER cryptodev_rc4 = {
+       NID_rc4,
+       1, 16, 0,
+       EVP_CIPH_VARIABLE_LENGTH,
+       cryptodev_init_key,
+       cryptodev_cipher,
+       cryptodev_cleanup,
+       sizeof(struct dev_crypto_state),
+       NULL,
+       NULL,
+       NULL
+};
+
 /* DES CBC EVP */
 const EVP_CIPHER cryptodev_des_cbc = {
        NID_des_cbc,
@@ -572,6 +565,32 @@ const EVP_CIPHER cryptodev_aes_cbc = {
        NULL
 };
 
+const EVP_CIPHER cryptodev_aes_192_cbc = {
+       NID_aes_192_cbc,
+       16, 24, 16,
+       EVP_CIPH_CBC_MODE,
+       cryptodev_init_key,
+       cryptodev_cipher,
+       cryptodev_cleanup,
+       sizeof(struct dev_crypto_state),
+       EVP_CIPHER_set_asn1_iv,
+       EVP_CIPHER_get_asn1_iv,
+       NULL
+};
+
+const EVP_CIPHER cryptodev_aes_256_cbc = {
+       NID_aes_256_cbc,
+       16, 32, 16,
+       EVP_CIPH_CBC_MODE,
+       cryptodev_init_key,
+       cryptodev_cipher,
+       cryptodev_cleanup,
+       sizeof(struct dev_crypto_state),
+       EVP_CIPHER_set_asn1_iv,
+       EVP_CIPHER_get_asn1_iv,
+       NULL
+};
+
 /*
  * Registered by the ENGINE when used to find out how to deal with
  * a particular NID in the ENGINE. this says what we'll do at the
@@ -585,6 +604,9 @@ cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
                return (cryptodev_usable_ciphers(nids));
 
        switch (nid) {
+       case NID_rc4:
+               *cipher = &cryptodev_rc4;
+               break;
        case NID_des_ede3_cbc:
                *cipher = &cryptodev_3des_cbc;
                break;
@@ -600,6 +622,12 @@ cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
        case NID_aes_128_cbc:
                *cipher = &cryptodev_aes_cbc;
                break;
+       case NID_aes_192_cbc:
+               *cipher = &cryptodev_aes_192_cbc;
+               break;
+       case NID_aes_256_cbc:
+               *cipher = &cryptodev_aes_256_cbc;
+               break;
        default:
                *cipher = NULL;
                break;
@@ -607,6 +635,234 @@ cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
        return (*cipher != NULL);
 }
 
+
+#ifdef USE_CRYPTODEV_DIGESTS
+
+/* convert digest type to cryptodev */
+static int
+digest_nid_to_cryptodev(int nid)
+{
+       int i;
+
+       for (i = 0; digests[i].id; i++)
+               if (digests[i].nid == nid)
+                       return (digests[i].id);
+       return (0);
+}
+
+
+static int
+digest_key_length(int nid)
+{
+       int i;
+
+       for (i = 0; digests[i].id; i++)
+               if (digests[i].nid == nid)
+                       return digests[i].keylen;
+       return (0);
+}
+
+
+static int cryptodev_digest_init(EVP_MD_CTX *ctx)
+{
+       struct dev_crypto_state *state = ctx->md_data;
+       struct session_op *sess = &state->d_sess;
+       int digest;
+
+       if ((digest = digest_nid_to_cryptodev(ctx->digest->type)) == NID_undef){
+               printf("cryptodev_digest_init: Can't get digest \n");
+               return (0);
+       }
+
+       memset(state, 0, sizeof(struct dev_crypto_state));
+
+       if ((state->d_fd = get_dev_crypto()) < 0) {
+               printf("cryptodev_digest_init: Can't get Dev \n");
+               return (0);
+       }
+
+       sess->mackey = state->dummy_mac_key;
+       sess->mackeylen = digest_key_length(ctx->digest->type);
+       sess->mac = digest;
+
+       if (ioctl(state->d_fd, CIOCGSESSION, sess) < 0) {
+               close(state->d_fd);
+               state->d_fd = -1;
+               printf("cryptodev_digest_init: Open session failed\n");
+               return (0);
+       }
+
+       return (1);
+}
+
+static int cryptodev_digest_update(EVP_MD_CTX *ctx, const void *data,
+               size_t count)
+{
+       struct crypt_op cryp;
+       struct dev_crypto_state *state = ctx->md_data;
+       struct session_op *sess = &state->d_sess;
+
+       if (!data || state->d_fd < 0) {
+               printf("cryptodev_digest_update: illegal inputs \n");
+               return (0);
+       }
+
+       if (!count) {
+               return (0);
+       }
+
+       if (!(ctx->flags & EVP_MD_CTX_FLAG_ONESHOT)) {
+               /* if application doesn't support one buffer */
+               state->mac_data = OPENSSL_realloc(state->mac_data, state->mac_len + count);
+
+               if (!state->mac_data) {
+                       printf("cryptodev_digest_update: realloc failed\n");
+                       return (0);
+               }
+
+               memcpy(state->mac_data + state->mac_len, data, count);
+               state->mac_len += count;
+       
+               return (1);
+       }
+
+       memset(&cryp, 0, sizeof(cryp));
+
+       cryp.ses = sess->ses;
+       cryp.flags = 0;
+       cryp.len = count;
+       cryp.src = (caddr_t) data;
+       cryp.dst = NULL;
+       cryp.mac = (caddr_t) state->digest_res;
+       if (ioctl(state->d_fd, CIOCCRYPT, &cryp) < 0) {
+               printf("cryptodev_digest_update: digest failed\n");
+               return (0);
+       }
+       return (1);
+}
+
+
+static int cryptodev_digest_final(EVP_MD_CTX *ctx, unsigned char *md)
+{
+       struct crypt_op cryp;
+       struct dev_crypto_state *state = ctx->md_data;
+       struct session_op *sess = &state->d_sess;
+
+       int ret = 1;
+
+       if (!md || state->d_fd < 0) {
+               printf("cryptodev_digest_final: illegal input\n");
+               return(0);
+       }
+
+       if (! (ctx->flags & EVP_MD_CTX_FLAG_ONESHOT) ) {
+               /* if application doesn't support one buffer */
+               memset(&cryp, 0, sizeof(cryp));
+
+               cryp.ses = sess->ses;
+               cryp.flags = 0;
+               cryp.len = state->mac_len;
+               cryp.src = state->mac_data;
+               cryp.dst = NULL;
+               cryp.mac = (caddr_t)md;
+
+               if (ioctl(state->d_fd, CIOCCRYPT, &cryp) < 0) {
+                       printf("cryptodev_digest_final: digest failed\n");
+                       return (0);
+               }
+
+               return 1;
+       }
+
+       memcpy(md, state->digest_res, ctx->digest->md_size);
+
+       return (ret);
+}
+
+
+static int cryptodev_digest_cleanup(EVP_MD_CTX *ctx)
+{
+       int ret = 1;
+       struct dev_crypto_state *state = ctx->md_data;
+       struct session_op *sess = &state->d_sess;
+
+       if (state->d_fd < 0) {
+               printf("cryptodev_digest_cleanup: illegal input\n");
+               return (0);
+       }
+
+       if (state->mac_data) {
+               OPENSSL_free(state->mac_data);
+               state->mac_data = NULL;
+               state->mac_len = 0;
+       }
+
+       if (state->copy)
+               return 1;
+
+       if (ioctl(state->d_fd, CIOCFSESSION, &sess->ses) < 0) {
+               printf("cryptodev_digest_cleanup: failed to close session\n");
+               ret = 0;
+       } else {
+               ret = 1;
+       }
+       close(state->d_fd);     
+       state->d_fd = -1;
+
+       return (ret);
+}
+
+static int cryptodev_digest_copy(EVP_MD_CTX *to,const EVP_MD_CTX *from)
+{
+       struct dev_crypto_state *fstate = from->md_data;
+       struct dev_crypto_state *dstate = to->md_data;
+
+       memcpy(dstate, fstate, sizeof(struct dev_crypto_state));
+
+       if (fstate->mac_len != 0) {
+               dstate->mac_data = OPENSSL_malloc(fstate->mac_len);
+               memcpy(dstate->mac_data, fstate->mac_data, fstate->mac_len);
+       }
+
+       dstate->copy = 1;
+
+       return 1;
+}
+
+
+const EVP_MD cryptodev_sha1 = {
+       NID_sha1,
+       NID_undef, 
+       SHA_DIGEST_LENGTH, 
+       EVP_MD_FLAG_ONESHOT,
+       cryptodev_digest_init,
+       cryptodev_digest_update,
+       cryptodev_digest_final,
+       cryptodev_digest_copy,
+       cryptodev_digest_cleanup,
+       EVP_PKEY_NULL_method,
+       SHA_CBLOCK,
+       sizeof(struct dev_crypto_state),
+};
+
+const EVP_MD cryptodev_md5 = {
+       NID_md5,
+       NID_undef, 
+       16 /* MD5_DIGEST_LENGTH */, 
+       EVP_MD_FLAG_ONESHOT,
+       cryptodev_digest_init,
+       cryptodev_digest_update,
+       cryptodev_digest_final,
+       cryptodev_digest_copy,
+       cryptodev_digest_cleanup,
+       EVP_PKEY_NULL_method,
+       64 /* MD5_CBLOCK */,
+       sizeof(struct dev_crypto_state),
+};
+
+#endif /* USE_CRYPTODEV_DIGESTS */
+
+
 static int
 cryptodev_engine_digests(ENGINE *e, const EVP_MD **digest,
     const int **nids, int nid)
@@ -615,10 +871,15 @@ cryptodev_engine_digests(ENGINE *e, const EVP_MD **digest,
                return (cryptodev_usable_digests(nids));
 
        switch (nid) {
+#ifdef USE_CRYPTODEV_DIGESTS
        case NID_md5:
-               *digest = NULL; /* need to make a clean md5 critter */
+               *digest = &cryptodev_md5; 
                break;
+       case NID_sha1:
+               *digest = &cryptodev_sha1;
+               break;
        default:
+#endif /* USE_CRYPTODEV_DIGESTS */
                *digest = NULL;
                break;
        }
@@ -646,8 +907,9 @@ bn2crparam(const BIGNUM *a, struct crparam *crp)
        b = malloc(bytes);
        if (b == NULL)
                return (1);
+       memset(b, 0, bytes);
 
-       crp->crp_p = (char *)b;
+       crp->crp_p = (caddr_t) b;
        crp->crp_nbits = bits;
 
        for (i = 0, j = 0; i < a->top; i++) {
@@ -690,7 +952,7 @@ zapparams(struct crypt_kop *kop)
 {
        int i;
 
-       for (i = 0; i <= kop->crk_iparams + kop->crk_oparams; i++) {
+       for (i = 0; i < kop->crk_iparams + kop->crk_oparams; i++) {
                if (kop->crk_param[i].crp_p)
                        free(kop->crk_param[i].crp_p);
                kop->crk_param[i].crp_p = NULL;
@@ -776,8 +1038,9 @@ static int
 cryptodev_rsa_nocrt_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
 {
        int r;
-
+       ctx = BN_CTX_new();
        r = cryptodev_bn_mod_exp(r0, I, rsa->d, rsa->n, ctx, NULL);
+       BN_CTX_free(ctx);
        return (r);
 }
 
@@ -1017,7 +1280,7 @@ cryptodev_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
                goto err;
        kop.crk_iparams = 3;
 
-       kop.crk_param[3].crp_p = (char *)key;
+       kop.crk_param[3].crp_p = (caddr_t) key;
        kop.crk_param[3].crp_nbits = keylen * 8;
        kop.crk_oparams = 1;
 
@@ -1048,7 +1311,7 @@ static DH_METHOD cryptodev_dh = {
  * but I expect we'll want some options soon.
  */
 static int
-cryptodev_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
+cryptodev_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
 {
 #ifdef HAVE_SYSLOG_R
        struct syslog_data sd = SYSLOG_DATA_INIT;
index acb30c3..807da7a 100644 (file)
@@ -146,14 +146,14 @@ struct st_dynamic_data_ctx
         * 'dirs' for loading. Default is to use 'dirs' as a fallback. */
        int dir_load;
        /* A stack of directories from which ENGINEs could be loaded */
-       STACK *dirs;
+       STACK_OF(OPENSSL_STRING) *dirs;
        };
 
 /* This is the "ex_data" index we obtain and reserve for use with our context
  * structure. */
 static int dynamic_ex_data_idx = -1;
 
-static void int_free_str(void *s) { OPENSSL_free(s); }
+static void int_free_str(char *s) { OPENSSL_free(s); }
 /* Because our ex_data element may or may not get allocated depending on whether
  * a "first-use" occurs before the ENGINE is freed, we have a memory leak
  * problem to solve. We can't declare a "new" handler for the ex_data as we
@@ -174,7 +174,7 @@ static void dynamic_data_ctx_free_func(void *parent, void *ptr,
                if(ctx->engine_id)
                        OPENSSL_free((void*)ctx->engine_id);
                if(ctx->dirs)
-                       sk_pop_free(ctx->dirs, int_free_str);
+                       sk_OPENSSL_STRING_pop_free(ctx->dirs, int_free_str);
                OPENSSL_free(ctx);
                }
        }
@@ -203,7 +203,7 @@ static int dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx)
        c->DYNAMIC_F1 = "v_check";
        c->DYNAMIC_F2 = "bind_engine";
        c->dir_load = 1;
-       c->dirs = sk_new_null();
+       c->dirs = sk_OPENSSL_STRING_new_null();
        if(!c->dirs)
                {
                ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX,ERR_R_MALLOC_FAILURE);
@@ -393,7 +393,7 @@ static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
                                ERR_R_MALLOC_FAILURE);
                        return 0;
                        }
-               sk_insert(ctx->dirs, tmp_str, -1);
+               sk_OPENSSL_STRING_insert(ctx->dirs, tmp_str, -1);
                }
                return 1;
        default:
@@ -411,11 +411,11 @@ static int int_load(dynamic_data_ctx *ctx)
                                ctx->DYNAMIC_LIBNAME, NULL, 0)) != NULL)
                return 1;
        /* If we're not allowed to use 'dirs' or we have none, fail */
-       if(!ctx->dir_load || ((num = sk_num(ctx->dirs)) < 1))
+       if(!ctx->dir_load || (num = sk_OPENSSL_STRING_num(ctx->dirs)) < 1)
                return 0;
        for(loop = 0; loop < num; loop++)
                {
-               const char *s = sk_value(ctx->dirs, loop);
+               const char *s = sk_OPENSSL_STRING_value(ctx->dirs, loop);
                char *merge = DSO_merge(ctx->dynamic_dso, ctx->DYNAMIC_LIBNAME, s);
                if(!merge)
                        return 0;
index ac74dd1..81c70ac 100644 (file)
@@ -86,6 +86,8 @@ static ERR_STRING_DATA ENGINE_str_functs[]=
 {ERR_FUNC(ENGINE_F_ENGINE_GET_DEFAULT_TYPE),   "ENGINE_GET_DEFAULT_TYPE"},
 {ERR_FUNC(ENGINE_F_ENGINE_GET_DIGEST), "ENGINE_get_digest"},
 {ERR_FUNC(ENGINE_F_ENGINE_GET_NEXT),   "ENGINE_get_next"},
+{ERR_FUNC(ENGINE_F_ENGINE_GET_PKEY_ASN1_METH), "ENGINE_get_pkey_asn1_meth"},
+{ERR_FUNC(ENGINE_F_ENGINE_GET_PKEY_METH),      "ENGINE_get_pkey_meth"},
 {ERR_FUNC(ENGINE_F_ENGINE_GET_PREV),   "ENGINE_get_prev"},
 {ERR_FUNC(ENGINE_F_ENGINE_INIT),       "ENGINE_init"},
 {ERR_FUNC(ENGINE_F_ENGINE_LIST_ADD),   "ENGINE_LIST_ADD"},
@@ -151,6 +153,7 @@ static ERR_STRING_DATA ENGINE_str_reasons[]=
 {ERR_REASON(ENGINE_R_RSA_NOT_IMPLEMENTED),"rsa not implemented"},
 {ERR_REASON(ENGINE_R_UNIMPLEMENTED_CIPHER),"unimplemented cipher"},
 {ERR_REASON(ENGINE_R_UNIMPLEMENTED_DIGEST),"unimplemented digest"},
+{ERR_REASON(ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD),"unimplemented public key method"},
 {ERR_REASON(ENGINE_R_VERSION_INCOMPATIBILITY),"version incompatibility"},
 {0,NULL}
        };
index 27c1662..db66e62 100644 (file)
@@ -89,6 +89,12 @@ int ENGINE_set_default(ENGINE *e, unsigned int flags)
 #endif
        if((flags & ENGINE_METHOD_RAND) && !ENGINE_set_default_RAND(e))
                return 0;
+       if((flags & ENGINE_METHOD_PKEY_METHS)
+                               && !ENGINE_set_default_pkey_meths(e))
+               return 0;
+       if((flags & ENGINE_METHOD_PKEY_ASN1_METHS)
+                               && !ENGINE_set_default_pkey_asn1_meths(e))
+               return 0;
        return 1;
        }
 
@@ -115,6 +121,13 @@ static int int_def_cb(const char *alg, int len, void *arg)
                *pflags |= ENGINE_METHOD_CIPHERS;
        else if (!strncmp(alg, "DIGESTS", len))
                *pflags |= ENGINE_METHOD_DIGESTS;
+       else if (!strncmp(alg, "PKEY", len))
+               *pflags |=
+                       ENGINE_METHOD_PKEY_METHS|ENGINE_METHOD_PKEY_ASN1_METHS;
+       else if (!strncmp(alg, "PKEY_CRYPTO", len))
+               *pflags |= ENGINE_METHOD_PKEY_METHS;
+       else if (!strncmp(alg, "PKEY_ASN1", len))
+               *pflags |= ENGINE_METHOD_PKEY_ASN1_METHS;
        else
                return 0;
        return 1;
@@ -154,6 +167,7 @@ int ENGINE_register_complete(ENGINE *e)
        ENGINE_register_ECDSA(e);
 #endif
        ENGINE_register_RAND(e);
+       ENGINE_register_pkey_meths(e);
        return 1;
        }
 
index a66f107..451ef8f 100644 (file)
@@ -127,6 +127,8 @@ ENGINE *engine_table_select(ENGINE_TABLE **table, int nid);
 ENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f, int l);
 #define engine_table_select(t,n) engine_table_select_tmp(t,n,__FILE__,__LINE__)
 #endif
+typedef void (engine_table_doall_cb)(int nid, STACK_OF(ENGINE) *sk, ENGINE *def, void *arg);
+void engine_table_doall(ENGINE_TABLE *table, engine_table_doall_cb *cb, void *arg);
 
 /* Internal versions of API functions that have control over locking. These are
  * used between C files when functionality needs to be shared but the caller may
@@ -143,6 +145,11 @@ void engine_set_all_null(ENGINE *e);
 /* NB: Bitwise OR-able values for the "flags" variable in ENGINE are now exposed
  * in engine.h. */
 
+/* Free up dynamically allocated public key methods associated with ENGINE */
+
+void engine_pkey_meths_free(ENGINE *e);
+void engine_pkey_asn1_meths_free(ENGINE *e);
+
 /* This is a structure for storing implementations of various crypto
  * algorithms and functions. */
 struct engine_st
@@ -160,7 +167,10 @@ struct engine_st
        ENGINE_CIPHERS_PTR ciphers;
        /* Digest handling is via this callback */
        ENGINE_DIGESTS_PTR digests;
-
+       /* Public key handling via this callback */
+       ENGINE_PKEY_METHS_PTR pkey_meths;
+       /* ASN1 public key handling via this callback */
+       ENGINE_PKEY_ASN1_METHS_PTR pkey_asn1_meths;
 
        ENGINE_GEN_INT_FUNC_PTR destroy;
 
index 5815b86..18a6664 100644 (file)
@@ -125,6 +125,9 @@ int engine_free_util(ENGINE *e, int locked)
                abort();
                }
 #endif
+       /* Free up any dynamically allocated public key methods */
+       engine_pkey_meths_free(e);
+       engine_pkey_asn1_meths_free(e);
        /* Give the ENGINE a chance to do any structural cleanup corresponding
         * to allocation it did in its constructor (eg. unload error strings) */
        if(e->destroy)
index fa2ab97..27846ed 100644 (file)
@@ -336,6 +336,7 @@ static void engine_cpy(ENGINE *dest, const ENGINE *src)
        dest->store_meth = src->store_meth;
        dest->ciphers = src->ciphers;
        dest->digests = src->digests;
+       dest->pkey_meths = src->pkey_meths;
        dest->destroy = src->destroy;
        dest->init = src->init;
        dest->finish = src->finish;
index 7c139ae..9abb95c 100644 (file)
@@ -238,7 +238,7 @@ static int test_rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
        return 1;
        }
 static int test_rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-                     const unsigned char *in, unsigned int inl)
+                     const unsigned char *in, size_t inl)
        {
 #ifdef TEST_ENG_OPENSSL_RC4_P_CIPHER
        fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) test_cipher() called\n");
index 8fc47b3..4fde948 100644 (file)
@@ -70,12 +70,22 @@ typedef struct st_engine_pile
        int uptodate;
        } ENGINE_PILE;
 
+DECLARE_LHASH_OF(ENGINE_PILE);
+
 /* The type exposed in eng_int.h */
 struct st_engine_table
        {
-       LHASH piles;
+       LHASH_OF(ENGINE_PILE) piles;
        }; /* ENGINE_TABLE */
 
+
+typedef struct st_engine_pile_doall
+       {
+       engine_table_doall_cb *cb;
+       void *arg;
+       } ENGINE_PILE_DOALL;
+       
+
 /* Global flags (ENGINE_TABLE_FLAG_***). */
 static unsigned int table_flags = 0;
 
@@ -84,6 +94,7 @@ unsigned int ENGINE_get_table_flags(void)
        {
        return table_flags;
        }
+
 void ENGINE_set_table_flags(unsigned int flags)
        {
        table_flags = flags;
@@ -94,19 +105,21 @@ static unsigned long engine_pile_hash(const ENGINE_PILE *c)
        {
        return c->nid;
        }
+
 static int engine_pile_cmp(const ENGINE_PILE *a, const ENGINE_PILE *b)
        {
        return a->nid - b->nid;
        }
-static IMPLEMENT_LHASH_HASH_FN(engine_pile_hash, const ENGINE_PILE *)
-static IMPLEMENT_LHASH_COMP_FN(engine_pile_cmp, const ENGINE_PILE *)
+static IMPLEMENT_LHASH_HASH_FN(engine_pile, ENGINE_PILE)
+static IMPLEMENT_LHASH_COMP_FN(engine_pile, ENGINE_PILE)
+
 static int int_table_check(ENGINE_TABLE **t, int create)
        {
-       LHASH *lh;
+       LHASH_OF(ENGINE_PILE) *lh;
+
        if(*t) return 1;
        if(!create) return 0;
-       if((lh = lh_new(LHASH_HASH_FN(engine_pile_hash),
-                       LHASH_COMP_FN(engine_pile_cmp))) == NULL)
+       if((lh = lh_ENGINE_PILE_new()) == NULL)
                return 0;
        *t = (ENGINE_TABLE *)lh;
        return 1;
@@ -130,7 +143,7 @@ int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
        while(num_nids--)
                {
                tmplate.nid = *nids;
-               fnd = lh_retrieve(&(*table)->piles, &tmplate);
+               fnd = lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate);
                if(!fnd)
                        {
                        fnd = OPENSSL_malloc(sizeof(ENGINE_PILE));
@@ -144,7 +157,7 @@ int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
                                goto end;
                                }
                        fnd->funct = NULL;
-                       lh_insert(&(*table)->piles, fnd);
+                       (void)lh_ENGINE_PILE_insert(&(*table)->piles, fnd);
                        }
                /* A registration shouldn't add duplciate entries */
                (void)sk_ENGINE_delete_ptr(fnd->sk, e);
@@ -173,7 +186,7 @@ end:
        CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
        return ret;
        }
-static void int_unregister_cb(ENGINE_PILE *pile, ENGINE *e)
+static void int_unregister_cb_doall_arg(ENGINE_PILE *pile, ENGINE *e)
        {
        int n;
        /* Iterate the 'c->sk' stack removing any occurance of 'e' */
@@ -188,31 +201,35 @@ static void int_unregister_cb(ENGINE_PILE *pile, ENGINE *e)
                pile->funct = NULL;
                }
        }
-static IMPLEMENT_LHASH_DOALL_ARG_FN(int_unregister_cb,ENGINE_PILE *,ENGINE *)
+static IMPLEMENT_LHASH_DOALL_ARG_FN(int_unregister_cb, ENGINE_PILE, ENGINE)
+
 void engine_table_unregister(ENGINE_TABLE **table, ENGINE *e)
        {
        CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
        if(int_table_check(table, 0))
-               lh_doall_arg(&(*table)->piles,
-                       LHASH_DOALL_ARG_FN(int_unregister_cb), e);
+               lh_ENGINE_PILE_doall_arg(&(*table)->piles,
+                                        LHASH_DOALL_ARG_FN(int_unregister_cb),
+                                        ENGINE, e);
        CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
        }
 
-static void int_cleanup_cb(ENGINE_PILE *p)
+static void int_cleanup_cb_doall(ENGINE_PILE *p)
        {
        sk_ENGINE_free(p->sk);
        if(p->funct)
                engine_unlocked_finish(p->funct, 0);
        OPENSSL_free(p);
        }
-static IMPLEMENT_LHASH_DOALL_FN(int_cleanup_cb,ENGINE_PILE *)
+static IMPLEMENT_LHASH_DOALL_FN(int_cleanup_cb, ENGINE_PILE)
+
 void engine_table_cleanup(ENGINE_TABLE **table)
        {
        CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
        if(*table)
                {
-               lh_doall(&(*table)->piles, LHASH_DOALL_FN(int_cleanup_cb));
-               lh_free(&(*table)->piles);
+               lh_ENGINE_PILE_doall(&(*table)->piles,
+                                    LHASH_DOALL_FN(int_cleanup_cb));
+               lh_ENGINE_PILE_free(&(*table)->piles);
                *table = NULL;
                }
        CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
@@ -243,7 +260,7 @@ ENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f, in
         * operations. But don't worry about a fprintf(stderr). */
        if(!int_table_check(table, 0)) goto end;
        tmplate.nid = nid;
-       fnd = lh_retrieve(&(*table)->piles, &tmplate);
+       fnd = lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate);
        if(!fnd) goto end;
        if(fnd->funct && engine_unlocked_init(fnd->funct))
                {
@@ -314,3 +331,21 @@ end:
        ERR_pop_to_mark();
        return ret;
        }
+
+/* Table enumeration */
+
+static void int_cb_doall_arg(ENGINE_PILE *pile, ENGINE_PILE_DOALL *dall)
+       {
+       dall->cb(pile->nid, pile->sk, pile->funct, dall->arg);
+       }
+static IMPLEMENT_LHASH_DOALL_ARG_FN(int_cb, ENGINE_PILE,ENGINE_PILE_DOALL)
+
+void engine_table_doall(ENGINE_TABLE *table, engine_table_doall_cb *cb,
+                                                               void *arg)
+       {
+       ENGINE_PILE_DOALL dall;
+       dall.cb = cb;
+       dall.arg = arg;
+       lh_ENGINE_PILE_doall_arg(&table->piles, LHASH_DOALL_ARG_FN(int_cb),
+                                ENGINE_PILE_DOALL, &dall);
+       }
index d4bc1ef..943aeae 100644 (file)
 #include <openssl/ecdsa.h>
 #endif
 #include <openssl/rand.h>
-#include <openssl/store.h>
 #include <openssl/ui.h>
 #include <openssl/err.h>
 #endif
 
-#include <openssl/x509.h>
-
 #include <openssl/ossl_typ.h>
 #include <openssl/symhacks.h>
 
+#include <openssl/x509.h>
+
 #ifdef  __cplusplus
 extern "C" {
 #endif
@@ -113,6 +112,8 @@ extern "C" {
 #define ENGINE_METHOD_CIPHERS          (unsigned int)0x0040
 #define ENGINE_METHOD_DIGESTS          (unsigned int)0x0080
 #define ENGINE_METHOD_STORE            (unsigned int)0x0100
+#define ENGINE_METHOD_PKEY_METHS       (unsigned int)0x0200
+#define ENGINE_METHOD_PKEY_ASN1_METHS  (unsigned int)0x0400
 /* Obvious all-or-nothing cases. */
 #define ENGINE_METHOD_ALL              (unsigned int)0xFFFF
 #define ENGINE_METHOD_NONE             (unsigned int)0x0000
@@ -297,7 +298,8 @@ typedef int (*ENGINE_SSL_CLIENT_CERT_PTR)(ENGINE *, SSL *ssl,
  * parameter is non-NULL it is set to the size of the returned array. */
 typedef int (*ENGINE_CIPHERS_PTR)(ENGINE *, const EVP_CIPHER **, const int **, int);
 typedef int (*ENGINE_DIGESTS_PTR)(ENGINE *, const EVP_MD **, const int **, int);
-
+typedef int (*ENGINE_PKEY_METHS_PTR)(ENGINE *, EVP_PKEY_METHOD **, const int **, int);
+typedef int (*ENGINE_PKEY_ASN1_METHS_PTR)(ENGINE *, EVP_PKEY_ASN1_METHOD **, const int **, int);
 /* STRUCTURE functions ... all of these functions deal with pointers to ENGINE
  * structures where the pointers have a "structural reference". This means that
  * their reference is to allowed access to the structure but it does not imply
@@ -329,21 +331,20 @@ void ENGINE_load_aep(void);
 void ENGINE_load_atalla(void);
 void ENGINE_load_chil(void);
 void ENGINE_load_cswift(void);
-#ifndef OPENSSL_NO_GMP
-void ENGINE_load_gmp(void);
-#endif
 void ENGINE_load_nuron(void);
 void ENGINE_load_sureware(void);
 void ENGINE_load_ubsec(void);
-#endif
-void ENGINE_load_cryptodev(void);
 void ENGINE_load_padlock(void);
-void ENGINE_load_builtin_engines(void);
-#ifdef OPENSSL_SYS_WIN32
-#ifndef OPENSSL_NO_CAPIENG
 void ENGINE_load_capi(void);
+#ifndef OPENSSL_NO_GMP
+void ENGINE_load_gmp(void);
 #endif
+#ifndef OPENSSL_NO_GOST
+void ENGINE_load_gost(void);
 #endif
+#endif
+void ENGINE_load_cryptodev(void);
+void ENGINE_load_builtin_engines(void);
 
 /* Get and set global flags (ENGINE_TABLE_FLAG_***) for the implementation
  * "registry" handling. */
@@ -394,6 +395,14 @@ int ENGINE_register_digests(ENGINE *e);
 void ENGINE_unregister_digests(ENGINE *e);
 void ENGINE_register_all_digests(void);
 
+int ENGINE_register_pkey_meths(ENGINE *e);
+void ENGINE_unregister_pkey_meths(ENGINE *e);
+void ENGINE_register_all_pkey_meths(void);
+
+int ENGINE_register_pkey_asn1_meths(ENGINE *e);
+void ENGINE_unregister_pkey_asn1_meths(ENGINE *e);
+void ENGINE_register_all_pkey_asn1_meths(void);
+
 /* These functions register all support from the above categories. Note, use of
  * these functions can result in static linkage of code your application may not
  * need. If you only need a subset of functionality, consider using more
@@ -473,6 +482,8 @@ int ENGINE_set_load_ssl_client_cert_function(ENGINE *e,
                                ENGINE_SSL_CLIENT_CERT_PTR loadssl_f);
 int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f);
 int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f);
+int ENGINE_set_pkey_meths(ENGINE *e, ENGINE_PKEY_METHS_PTR f);
+int ENGINE_set_pkey_asn1_meths(ENGINE *e, ENGINE_PKEY_ASN1_METHS_PTR f);
 int ENGINE_set_flags(ENGINE *e, int flags);
 int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns);
 /* These functions allow control over any per-structure ENGINE data. */
@@ -509,8 +520,16 @@ ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e);
 ENGINE_SSL_CLIENT_CERT_PTR ENGINE_get_ssl_client_cert_function(const ENGINE *e);
 ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e);
 ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e);
+ENGINE_PKEY_METHS_PTR ENGINE_get_pkey_meths(const ENGINE *e);
+ENGINE_PKEY_ASN1_METHS_PTR ENGINE_get_pkey_asn1_meths(const ENGINE *e);
 const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid);
 const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid);
+const EVP_PKEY_METHOD *ENGINE_get_pkey_meth(ENGINE *e, int nid);
+const EVP_PKEY_ASN1_METHOD *ENGINE_get_pkey_asn1_meth(ENGINE *e, int nid);
+const EVP_PKEY_ASN1_METHOD *ENGINE_get_pkey_asn1_meth_str(ENGINE *e,
+                                       const char *str, int len);
+const EVP_PKEY_ASN1_METHOD *ENGINE_pkey_asn1_find_str(ENGINE **pe,
+                                       const char *str, int len);
 const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e);
 int ENGINE_get_flags(const ENGINE *e);
 
@@ -562,6 +581,8 @@ ENGINE *ENGINE_get_default_RAND(void);
  * ciphering or digesting corresponding to "nid". */
 ENGINE *ENGINE_get_cipher_engine(int nid);
 ENGINE *ENGINE_get_digest_engine(int nid);
+ENGINE *ENGINE_get_pkey_meth_engine(int nid);
+ENGINE *ENGINE_get_pkey_asn1_meth_engine(int nid);
 
 /* This sets a new default ENGINE structure for performing RSA
  * operations. If the result is non-zero (success) then the ENGINE
@@ -577,6 +598,8 @@ int ENGINE_set_default_DH(ENGINE *e);
 int ENGINE_set_default_RAND(ENGINE *e);
 int ENGINE_set_default_ciphers(ENGINE *e);
 int ENGINE_set_default_digests(ENGINE *e);
+int ENGINE_set_default_pkey_meths(ENGINE *e);
+int ENGINE_set_default_pkey_asn1_meths(ENGINE *e);
 
 /* The combination "set" - the flags are bitwise "OR"d from the
  * ENGINE_METHOD_*** defines above. As with the "ENGINE_register_complete()"
@@ -654,6 +677,7 @@ typedef struct st_dynamic_fns {
  * can be fully instantiated with IMPLEMENT_DYNAMIC_CHECK_FN(). */
 typedef unsigned long (*dynamic_v_check_fn)(unsigned long ossl_version);
 #define IMPLEMENT_DYNAMIC_CHECK_FN() \
+       OPENSSL_EXPORT unsigned long v_check(unsigned long v); \
        OPENSSL_EXPORT unsigned long v_check(unsigned long v) { \
                if(v >= OSSL_DYNAMIC_OLDEST) return OSSL_DYNAMIC_VERSION; \
                return 0; }
@@ -677,6 +701,8 @@ typedef int (*dynamic_bind_engine)(ENGINE *e, const char *id,
                                const dynamic_fns *fns);
 #define IMPLEMENT_DYNAMIC_BIND_FN(fn) \
        OPENSSL_EXPORT \
+       int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns); \
+       OPENSSL_EXPORT \
        int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) { \
                if(ENGINE_get_static_state() == fns->static_state) goto skip_cbs; \
                if(!CRYPTO_set_mem_functions(fns->mem_fns.malloc_cb, \
@@ -705,7 +731,7 @@ typedef int (*dynamic_bind_engine)(ENGINE *e, const char *id,
  * values. */
 void *ENGINE_get_static_state(void);
 
-#if defined(__OpenBSD__) || defined(__FreeBSD__)
+#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV)
 void ENGINE_setup_bsd_cryptodev(void);
 #endif
 
@@ -734,13 +760,15 @@ void ERR_load_ENGINE_strings(void);
 #define ENGINE_F_ENGINE_GET_DEFAULT_TYPE                177
 #define ENGINE_F_ENGINE_GET_DIGEST                      186
 #define ENGINE_F_ENGINE_GET_NEXT                        115
+#define ENGINE_F_ENGINE_GET_PKEY_ASN1_METH              193
+#define ENGINE_F_ENGINE_GET_PKEY_METH                   192
 #define ENGINE_F_ENGINE_GET_PREV                        116
 #define ENGINE_F_ENGINE_INIT                            119
 #define ENGINE_F_ENGINE_LIST_ADD                        120
 #define ENGINE_F_ENGINE_LIST_REMOVE                     121
 #define ENGINE_F_ENGINE_LOAD_PRIVATE_KEY                150
 #define ENGINE_F_ENGINE_LOAD_PUBLIC_KEY                         151
-#define ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT            192
+#define ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT            194
 #define ENGINE_F_ENGINE_NEW                             122
 #define ENGINE_F_ENGINE_REMOVE                          123
 #define ENGINE_F_ENGINE_SET_DEFAULT_STRING              189
@@ -769,7 +797,7 @@ void ERR_load_ENGINE_strings(void);
 #define ENGINE_R_DSO_FAILURE                            104
 #define ENGINE_R_DSO_NOT_FOUND                          132
 #define ENGINE_R_ENGINES_SECTION_ERROR                  148
-#define ENGINE_R_ENGINE_CONFIGURATION_ERROR             101
+#define ENGINE_R_ENGINE_CONFIGURATION_ERROR             102
 #define ENGINE_R_ENGINE_IS_NOT_IN_LIST                  105
 #define ENGINE_R_ENGINE_SECTION_ERROR                   149
 #define ENGINE_R_FAILED_LOADING_PRIVATE_KEY             128
@@ -796,6 +824,7 @@ void ERR_load_ENGINE_strings(void);
 #define ENGINE_R_RSA_NOT_IMPLEMENTED                    141
 #define ENGINE_R_UNIMPLEMENTED_CIPHER                   146
 #define ENGINE_R_UNIMPLEMENTED_DIGEST                   147
+#define ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD        101
 #define ENGINE_R_VERSION_INCOMPATIBILITY                145
 
 #ifdef  __cplusplus
index e383461..f4d70e7 100644 (file)
@@ -276,7 +276,7 @@ end:
        ENGINE_cleanup();
        CRYPTO_cleanup_all_ex_data();
        ERR_free_strings();
-       ERR_remove_state(0);
+       ERR_remove_thread_state(NULL);
        CRYPTO_mem_leaks_fp(stderr);
        return to_return;
        }
diff --git a/deps/openssl/openssl/crypto/engine/tb_asnmth.c b/deps/openssl/openssl/crypto/engine/tb_asnmth.c
new file mode 100644 (file)
index 0000000..7509033
--- /dev/null
@@ -0,0 +1,246 @@
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include "eng_int.h"
+#include "asn1_locl.h"
+#include <openssl/evp.h>
+
+/* If this symbol is defined then ENGINE_get_pkey_asn1_meth_engine(), the
+ * function that is used by EVP to hook in pkey_asn1_meth code and cache
+ * defaults (etc), will display brief debugging summaries to stderr with the
+ * 'nid'. */
+/* #define ENGINE_PKEY_ASN1_METH_DEBUG */
+
+static ENGINE_TABLE *pkey_asn1_meth_table = NULL;
+
+void ENGINE_unregister_pkey_asn1_meths(ENGINE *e)
+       {
+       engine_table_unregister(&pkey_asn1_meth_table, e);
+       }
+
+static void engine_unregister_all_pkey_asn1_meths(void)
+       {
+       engine_table_cleanup(&pkey_asn1_meth_table);
+       }
+
+int ENGINE_register_pkey_asn1_meths(ENGINE *e)
+       {
+       if(e->pkey_asn1_meths)
+               {
+               const int *nids;
+               int num_nids = e->pkey_asn1_meths(e, NULL, &nids, 0);
+               if(num_nids > 0)
+                       return engine_table_register(&pkey_asn1_meth_table,
+                               engine_unregister_all_pkey_asn1_meths, e, nids,
+                                       num_nids, 0);
+               }
+       return 1;
+       }
+
+void ENGINE_register_all_pkey_asn1_meths(void)
+       {
+       ENGINE *e;
+
+       for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
+               ENGINE_register_pkey_asn1_meths(e);
+       }
+
+int ENGINE_set_default_pkey_asn1_meths(ENGINE *e)
+       {
+       if(e->pkey_asn1_meths)
+               {
+               const int *nids;
+               int num_nids = e->pkey_asn1_meths(e, NULL, &nids, 0);
+               if(num_nids > 0)
+                       return engine_table_register(&pkey_asn1_meth_table,
+                               engine_unregister_all_pkey_asn1_meths, e, nids,
+                                       num_nids, 1);
+               }
+       return 1;
+       }
+
+/* Exposed API function to get a functional reference from the implementation
+ * table (ie. try to get a functional reference from the tabled structural
+ * references) for a given pkey_asn1_meth 'nid' */
+ENGINE *ENGINE_get_pkey_asn1_meth_engine(int nid)
+       {
+       return engine_table_select(&pkey_asn1_meth_table, nid);
+       }
+
+/* Obtains a pkey_asn1_meth implementation from an ENGINE functional reference */
+const EVP_PKEY_ASN1_METHOD *ENGINE_get_pkey_asn1_meth(ENGINE *e, int nid)
+       {
+       EVP_PKEY_ASN1_METHOD *ret;
+       ENGINE_PKEY_ASN1_METHS_PTR fn = ENGINE_get_pkey_asn1_meths(e);
+       if(!fn || !fn(e, &ret, NULL, nid))
+               {
+               ENGINEerr(ENGINE_F_ENGINE_GET_PKEY_ASN1_METH,
+                               ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD);
+               return NULL;
+               }
+       return ret;
+       }
+
+/* Gets the pkey_asn1_meth callback from an ENGINE structure */
+ENGINE_PKEY_ASN1_METHS_PTR ENGINE_get_pkey_asn1_meths(const ENGINE *e)
+       {
+       return e->pkey_asn1_meths;
+       }
+
+/* Sets the pkey_asn1_meth callback in an ENGINE structure */
+int ENGINE_set_pkey_asn1_meths(ENGINE *e, ENGINE_PKEY_ASN1_METHS_PTR f)
+       {
+       e->pkey_asn1_meths = f;
+       return 1;
+       }
+
+/* Internal function to free up EVP_PKEY_ASN1_METHOD structures before an
+ * ENGINE is destroyed
+ */
+
+void engine_pkey_asn1_meths_free(ENGINE *e)
+       {
+       int i;
+       EVP_PKEY_ASN1_METHOD *pkm;
+       if (e->pkey_asn1_meths)
+               {
+               const int *pknids;
+               int npknids;
+               npknids = e->pkey_asn1_meths(e, NULL, &pknids, 0);
+               for (i = 0; i < npknids; i++)
+                       {
+                       if (e->pkey_asn1_meths(e, &pkm, NULL, pknids[i]))
+                               {
+                               EVP_PKEY_asn1_free(pkm);
+                               }
+                       }
+               }
+       }
+
+/* Find a method based on a string. This does a linear search through
+ * all implemented algorithms. This is OK in practice because only
+ * a small number of algorithms are likely to be implemented in an engine
+ * and it is not used for speed critical operations.
+ */
+
+const EVP_PKEY_ASN1_METHOD *ENGINE_get_pkey_asn1_meth_str(ENGINE *e,
+                                       const char *str, int len)
+       {
+       int i, nidcount;
+       const int *nids;
+       EVP_PKEY_ASN1_METHOD *ameth;
+       if (!e->pkey_asn1_meths)
+               return NULL;
+       if (len == -1)
+               len = strlen(str);
+       nidcount = e->pkey_asn1_meths(e, NULL, &nids, 0);
+       for (i = 0; i < nidcount; i++)
+               {
+               e->pkey_asn1_meths(e, &ameth, NULL, nids[i]);
+               if (((int)strlen(ameth->pem_str) == len) && 
+                                       !strncasecmp(ameth->pem_str, str, len))
+                       return ameth;
+               }
+       return NULL;
+       }
+
+typedef struct 
+       {
+       ENGINE *e;
+       const EVP_PKEY_ASN1_METHOD *ameth;
+       const char *str;
+       int len;
+       } ENGINE_FIND_STR;
+
+static void look_str_cb(int nid, STACK_OF(ENGINE) *sk, ENGINE *def, void *arg)
+       {
+       ENGINE_FIND_STR *lk = arg;
+       int i;
+       if (lk->ameth)
+               return;
+       for (i = 0; i < sk_ENGINE_num(sk); i++)
+               {
+               ENGINE *e = sk_ENGINE_value(sk, i);
+               EVP_PKEY_ASN1_METHOD *ameth;
+               e->pkey_asn1_meths(e, &ameth, NULL, nid);
+               if (((int)strlen(ameth->pem_str) == lk->len) && 
+                               !strncasecmp(ameth->pem_str, lk->str, lk->len))
+                       {
+                       lk->e = e;
+                       lk->ameth = ameth;
+                       return;
+                       }
+               }
+       }
+
+const EVP_PKEY_ASN1_METHOD *ENGINE_pkey_asn1_find_str(ENGINE **pe,
+                                       const char *str, int len)
+       {
+       ENGINE_FIND_STR fstr;
+       fstr.e = NULL;
+       fstr.ameth = NULL;
+       fstr.str = str;
+       fstr.len = len;
+       CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
+       engine_table_doall(pkey_asn1_meth_table, look_str_cb, &fstr);
+       /* If found obtain a structural reference to engine */
+       if (fstr.e)
+               {
+               fstr.e->struct_ref++;
+               engine_ref_debug(fstr.e, 0, 1)
+               }
+       *pe = fstr.e;
+       CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
+       return fstr.ameth;
+       }
diff --git a/deps/openssl/openssl/crypto/engine/tb_pkmeth.c b/deps/openssl/openssl/crypto/engine/tb_pkmeth.c
new file mode 100644 (file)
index 0000000..1cdb967
--- /dev/null
@@ -0,0 +1,167 @@
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include "eng_int.h"
+#include <openssl/evp.h>
+
+/* If this symbol is defined then ENGINE_get_pkey_meth_engine(), the function
+ * that is used by EVP to hook in pkey_meth code and cache defaults (etc), will
+ * display brief debugging summaries to stderr with the 'nid'. */
+/* #define ENGINE_PKEY_METH_DEBUG */
+
+static ENGINE_TABLE *pkey_meth_table = NULL;
+
+void ENGINE_unregister_pkey_meths(ENGINE *e)
+       {
+       engine_table_unregister(&pkey_meth_table, e);
+       }
+
+static void engine_unregister_all_pkey_meths(void)
+       {
+       engine_table_cleanup(&pkey_meth_table);
+       }
+
+int ENGINE_register_pkey_meths(ENGINE *e)
+       {
+       if(e->pkey_meths)
+               {
+               const int *nids;
+               int num_nids = e->pkey_meths(e, NULL, &nids, 0);
+               if(num_nids > 0)
+                       return engine_table_register(&pkey_meth_table,
+                               engine_unregister_all_pkey_meths, e, nids,
+                                       num_nids, 0);
+               }
+       return 1;
+       }
+
+void ENGINE_register_all_pkey_meths()
+       {
+       ENGINE *e;
+
+       for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
+               ENGINE_register_pkey_meths(e);
+       }
+
+int ENGINE_set_default_pkey_meths(ENGINE *e)
+       {
+       if(e->pkey_meths)
+               {
+               const int *nids;
+               int num_nids = e->pkey_meths(e, NULL, &nids, 0);
+               if(num_nids > 0)
+                       return engine_table_register(&pkey_meth_table,
+                               engine_unregister_all_pkey_meths, e, nids,
+                                       num_nids, 1);
+               }
+       return 1;
+       }
+
+/* Exposed API function to get a functional reference from the implementation
+ * table (ie. try to get a functional reference from the tabled structural
+ * references) for a given pkey_meth 'nid' */
+ENGINE *ENGINE_get_pkey_meth_engine(int nid)
+       {
+       return engine_table_select(&pkey_meth_table, nid);
+       }
+
+/* Obtains a pkey_meth implementation from an ENGINE functional reference */
+const EVP_PKEY_METHOD *ENGINE_get_pkey_meth(ENGINE *e, int nid)
+       {
+       EVP_PKEY_METHOD *ret;
+       ENGINE_PKEY_METHS_PTR fn = ENGINE_get_pkey_meths(e);
+       if(!fn || !fn(e, &ret, NULL, nid))
+               {
+               ENGINEerr(ENGINE_F_ENGINE_GET_PKEY_METH,
+                               ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD);
+               return NULL;
+               }
+       return ret;
+       }
+
+/* Gets the pkey_meth callback from an ENGINE structure */
+ENGINE_PKEY_METHS_PTR ENGINE_get_pkey_meths(const ENGINE *e)
+       {
+       return e->pkey_meths;
+       }
+
+/* Sets the pkey_meth callback in an ENGINE structure */
+int ENGINE_set_pkey_meths(ENGINE *e, ENGINE_PKEY_METHS_PTR f)
+       {
+       e->pkey_meths = f;
+       return 1;
+       }
+
+/* Internal function to free up EVP_PKEY_METHOD structures before an
+ * ENGINE is destroyed
+ */
+
+void engine_pkey_meths_free(ENGINE *e)
+       {
+       int i;
+       EVP_PKEY_METHOD *pkm;
+       if (e->pkey_meths)
+               {
+               const int *pknids;
+               int npknids;
+               npknids = e->pkey_meths(e, NULL, &pknids, 0);
+               for (i = 0; i < npknids; i++)
+                       {
+                       if (e->pkey_meths(e, &pkm, NULL, pknids[i]))
+                               {
+                               EVP_PKEY_meth_free(pkm);
+                               }
+                       }
+               }
+       }
index 96d8a1a..862b23b 100644 (file)
@@ -17,8 +17,8 @@ TEST=
 APPS=
 
 LIB=$(TOP)/libcrypto.a
-LIBSRC=err.c err_def.c err_all.c err_prn.c err_str.c err_bio.c
-LIBOBJ=err.o err_def.o err_all.o err_prn.o err_str.o err_bio.o
+LIBSRC=err.c err_all.c err_prn.c
+LIBOBJ=err.o err_all.o err_prn.o
 
 SRC= $(LIBSRC)
 
@@ -33,7 +33,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -83,13 +83,13 @@ err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
 err.o: ../cryptlib.h err.c
 err_all.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
 err_all.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
-err_all.o: ../../include/openssl/comp.h ../../include/openssl/conf.h
-err_all.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
-err_all.o: ../../include/openssl/dsa.h ../../include/openssl/dso.h
-err_all.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-err_all.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
-err_all.o: ../../include/openssl/engine.h ../../include/openssl/err.h
-err_all.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
+err_all.o: ../../include/openssl/cms.h ../../include/openssl/comp.h
+err_all.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
+err_all.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
+err_all.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
+err_all.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+err_all.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
+err_all.o: ../../include/openssl/err.h ../../include/openssl/evp.h
 err_all.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
 err_all.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h
 err_all.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
@@ -98,23 +98,9 @@ err_all.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
 err_all.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
 err_all.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
 err_all.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-err_all.o: ../../include/openssl/ui.h ../../include/openssl/x509.h
-err_all.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
-err_all.o: err_all.c
-err_bio.o: ../../e_os.h ../../include/openssl/bio.h
-err_bio.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
-err_bio.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-err_bio.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
-err_bio.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-err_bio.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-err_bio.o: ../../include/openssl/symhacks.h ../cryptlib.h err_bio.c
-err_def.o: ../../e_os.h ../../include/openssl/bio.h
-err_def.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
-err_def.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-err_def.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
-err_def.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-err_def.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-err_def.o: ../../include/openssl/symhacks.h ../cryptlib.h err_def.c
+err_all.o: ../../include/openssl/ts.h ../../include/openssl/ui.h
+err_all.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+err_all.o: ../../include/openssl/x509v3.h err_all.c
 err_prn.o: ../../e_os.h ../../include/openssl/bio.h
 err_prn.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 err_prn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
@@ -122,10 +108,3 @@ err_prn.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
 err_prn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 err_prn.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
 err_prn.o: ../../include/openssl/symhacks.h ../cryptlib.h err_prn.c
-err_str.o: ../../e_os.h ../../include/openssl/bio.h
-err_str.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
-err_str.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-err_str.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
-err_str.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-err_str.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-err_str.o: ../../include/openssl/symhacks.h ../cryptlib.h err_str.c
index 292404a..69713a6 100644 (file)
@@ -56,7 +56,7 @@
  * [including the GNU Public Licence.]
  */
 /* ====================================================================
- * Copyright (c) 1998-2001 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include <openssl/bio.h>
 #include <openssl/err.h>
 
-static unsigned long get_error_values(int inc,int top,
-                                       const char **file,int *line,
-                                       const char **data,int *flags);
+DECLARE_LHASH_OF(ERR_STRING_DATA);
+DECLARE_LHASH_OF(ERR_STATE);
+
+static void err_load_strings(int lib, ERR_STRING_DATA *str);
+
+static void ERR_STATE_free(ERR_STATE *s);
+#ifndef OPENSSL_NO_ERR
+static ERR_STRING_DATA ERR_str_libraries[]=
+       {
+{ERR_PACK(ERR_LIB_NONE,0,0)            ,"unknown library"},
+{ERR_PACK(ERR_LIB_SYS,0,0)             ,"system library"},
+{ERR_PACK(ERR_LIB_BN,0,0)              ,"bignum routines"},
+{ERR_PACK(ERR_LIB_RSA,0,0)             ,"rsa routines"},
+{ERR_PACK(ERR_LIB_DH,0,0)              ,"Diffie-Hellman routines"},
+{ERR_PACK(ERR_LIB_EVP,0,0)             ,"digital envelope routines"},
+{ERR_PACK(ERR_LIB_BUF,0,0)             ,"memory buffer routines"},
+{ERR_PACK(ERR_LIB_OBJ,0,0)             ,"object identifier routines"},
+{ERR_PACK(ERR_LIB_PEM,0,0)             ,"PEM routines"},
+{ERR_PACK(ERR_LIB_DSA,0,0)             ,"dsa routines"},
+{ERR_PACK(ERR_LIB_X509,0,0)            ,"x509 certificate routines"},
+{ERR_PACK(ERR_LIB_ASN1,0,0)            ,"asn1 encoding routines"},
+{ERR_PACK(ERR_LIB_CONF,0,0)            ,"configuration file routines"},
+{ERR_PACK(ERR_LIB_CRYPTO,0,0)          ,"common libcrypto routines"},
+{ERR_PACK(ERR_LIB_EC,0,0)              ,"elliptic curve routines"},
+{ERR_PACK(ERR_LIB_SSL,0,0)             ,"SSL routines"},
+{ERR_PACK(ERR_LIB_BIO,0,0)             ,"BIO routines"},
+{ERR_PACK(ERR_LIB_PKCS7,0,0)           ,"PKCS7 routines"},
+{ERR_PACK(ERR_LIB_X509V3,0,0)          ,"X509 V3 routines"},
+{ERR_PACK(ERR_LIB_PKCS12,0,0)          ,"PKCS12 routines"},
+{ERR_PACK(ERR_LIB_RAND,0,0)            ,"random number generator"},
+{ERR_PACK(ERR_LIB_DSO,0,0)             ,"DSO support routines"},
+{ERR_PACK(ERR_LIB_TS,0,0)              ,"time stamp routines"},
+{ERR_PACK(ERR_LIB_ENGINE,0,0)          ,"engine routines"},
+{ERR_PACK(ERR_LIB_OCSP,0,0)            ,"OCSP routines"},
+{ERR_PACK(ERR_LIB_FIPS,0,0)            ,"FIPS routines"},
+{ERR_PACK(ERR_LIB_CMS,0,0)             ,"CMS routines"},
+{ERR_PACK(ERR_LIB_HMAC,0,0)            ,"HMAC routines"},
+{0,NULL},
+       };
+
+static ERR_STRING_DATA ERR_str_functs[]=
+       {
+       {ERR_PACK(0,SYS_F_FOPEN,0),             "fopen"},
+       {ERR_PACK(0,SYS_F_CONNECT,0),           "connect"},
+       {ERR_PACK(0,SYS_F_GETSERVBYNAME,0),     "getservbyname"},
+       {ERR_PACK(0,SYS_F_SOCKET,0),            "socket"}, 
+       {ERR_PACK(0,SYS_F_IOCTLSOCKET,0),       "ioctlsocket"},
+       {ERR_PACK(0,SYS_F_BIND,0),              "bind"},
+       {ERR_PACK(0,SYS_F_LISTEN,0),            "listen"},
+       {ERR_PACK(0,SYS_F_ACCEPT,0),            "accept"},
+#ifdef OPENSSL_SYS_WINDOWS
+       {ERR_PACK(0,SYS_F_WSASTARTUP,0),        "WSAstartup"},
+#endif
+       {ERR_PACK(0,SYS_F_OPENDIR,0),           "opendir"},
+       {ERR_PACK(0,SYS_F_FREAD,0),             "fread"},
+       {0,NULL},
+       };
+
+static ERR_STRING_DATA ERR_str_reasons[]=
+       {
+{ERR_R_SYS_LIB                         ,"system lib"},
+{ERR_R_BN_LIB                          ,"BN lib"},
+{ERR_R_RSA_LIB                         ,"RSA lib"},
+{ERR_R_DH_LIB                          ,"DH lib"},
+{ERR_R_EVP_LIB                         ,"EVP lib"},
+{ERR_R_BUF_LIB                         ,"BUF lib"},
+{ERR_R_OBJ_LIB                         ,"OBJ lib"},
+{ERR_R_PEM_LIB                         ,"PEM lib"},
+{ERR_R_DSA_LIB                         ,"DSA lib"},
+{ERR_R_X509_LIB                                ,"X509 lib"},
+{ERR_R_ASN1_LIB                                ,"ASN1 lib"},
+{ERR_R_CONF_LIB                                ,"CONF lib"},
+{ERR_R_CRYPTO_LIB                      ,"CRYPTO lib"},
+{ERR_R_EC_LIB                          ,"EC lib"},
+{ERR_R_SSL_LIB                         ,"SSL lib"},
+{ERR_R_BIO_LIB                         ,"BIO lib"},
+{ERR_R_PKCS7_LIB                       ,"PKCS7 lib"},
+{ERR_R_X509V3_LIB                      ,"X509V3 lib"},
+{ERR_R_PKCS12_LIB                      ,"PKCS12 lib"},
+{ERR_R_RAND_LIB                                ,"RAND lib"},
+{ERR_R_DSO_LIB                         ,"DSO lib"},
+{ERR_R_ENGINE_LIB                      ,"ENGINE lib"},
+{ERR_R_OCSP_LIB                                ,"OCSP lib"},
+{ERR_R_TS_LIB                          ,"TS lib"},
+
+{ERR_R_NESTED_ASN1_ERROR               ,"nested asn1 error"},
+{ERR_R_BAD_ASN1_OBJECT_HEADER          ,"bad asn1 object header"},
+{ERR_R_BAD_GET_ASN1_OBJECT_CALL                ,"bad get asn1 object call"},
+{ERR_R_EXPECTING_AN_ASN1_SEQUENCE      ,"expecting an asn1 sequence"},
+{ERR_R_ASN1_LENGTH_MISMATCH            ,"asn1 length mismatch"},
+{ERR_R_MISSING_ASN1_EOS                        ,"missing asn1 eos"},
+
+{ERR_R_FATAL                            ,"fatal"},
+{ERR_R_MALLOC_FAILURE                  ,"malloc failure"},
+{ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED     ,"called a function you should not call"},
+{ERR_R_PASSED_NULL_PARAMETER           ,"passed a null parameter"},
+{ERR_R_INTERNAL_ERROR                  ,"internal error"},
+{ERR_R_DISABLED                                ,"called a function that was disabled at compile-time"},
+
+{0,NULL},
+       };
+#endif
+
+
+/* Define the predeclared (but externally opaque) "ERR_FNS" type */
+struct st_ERR_FNS
+       {
+       /* Works on the "error_hash" string table */
+       LHASH_OF(ERR_STRING_DATA) *(*cb_err_get)(int create);
+       void (*cb_err_del)(void);
+       ERR_STRING_DATA *(*cb_err_get_item)(const ERR_STRING_DATA *);
+       ERR_STRING_DATA *(*cb_err_set_item)(ERR_STRING_DATA *);
+       ERR_STRING_DATA *(*cb_err_del_item)(ERR_STRING_DATA *);
+       /* Works on the "thread_hash" error-state table */
+       LHASH_OF(ERR_STATE) *(*cb_thread_get)(int create);
+       void (*cb_thread_release)(LHASH_OF(ERR_STATE) **hash);
+       ERR_STATE *(*cb_thread_get_item)(const ERR_STATE *);
+       ERR_STATE *(*cb_thread_set_item)(ERR_STATE *);
+       void (*cb_thread_del_item)(const ERR_STATE *);
+       /* Returns the next available error "library" numbers */
+       int (*cb_get_next_lib)(void);
+       };
+
+/* Predeclarations of the "err_defaults" functions */
+static LHASH_OF(ERR_STRING_DATA) *int_err_get(int create);
+static void int_err_del(void);
+static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *);
+static ERR_STRING_DATA *int_err_set_item(ERR_STRING_DATA *);
+static ERR_STRING_DATA *int_err_del_item(ERR_STRING_DATA *);
+static LHASH_OF(ERR_STATE) *int_thread_get(int create);
+static void int_thread_release(LHASH_OF(ERR_STATE) **hash);
+static ERR_STATE *int_thread_get_item(const ERR_STATE *);
+static ERR_STATE *int_thread_set_item(ERR_STATE *);
+static void int_thread_del_item(const ERR_STATE *);
+static int int_err_get_next_lib(void);
+/* The static ERR_FNS table using these defaults functions */
+static const ERR_FNS err_defaults =
+       {
+       int_err_get,
+       int_err_del,
+       int_err_get_item,
+       int_err_set_item,
+       int_err_del_item,
+       int_thread_get,
+       int_thread_release,
+       int_thread_get_item,
+       int_thread_set_item,
+       int_thread_del_item,
+       int_err_get_next_lib
+       };
+
+/* The replacable table of ERR_FNS functions we use at run-time */
+static const ERR_FNS *err_fns = NULL;
+
+/* Eg. rather than using "err_get()", use "ERRFN(err_get)()". */
+#define ERRFN(a) err_fns->cb_##a
+
+/* The internal state used by "err_defaults" - as such, the setting, reading,
+ * creating, and deleting of this data should only be permitted via the
+ * "err_defaults" functions. This way, a linked module can completely defer all
+ * ERR state operation (together with requisite locking) to the implementations
+ * and state in the loading application. */
+static LHASH_OF(ERR_STRING_DATA) *int_error_hash = NULL;
+static LHASH_OF(ERR_STATE) *int_thread_hash = NULL;
+static int int_thread_hash_references = 0;
+static int int_err_library_number= ERR_LIB_USER;
+
+/* Internal function that checks whether "err_fns" is set and if not, sets it to
+ * the defaults. */
+static void err_fns_check(void)
+       {
+       if (err_fns) return;
+       
+       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
+       if (!err_fns)
+               err_fns = &err_defaults;
+       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
+       }
+
+/* API functions to get or set the underlying ERR functions. */
+
+const ERR_FNS *ERR_get_implementation(void)
+       {
+       err_fns_check();
+       return err_fns;
+       }
+
+int ERR_set_implementation(const ERR_FNS *fns)
+       {
+       int ret = 0;
+
+       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
+       /* It's too late if 'err_fns' is non-NULL. BTW: not much point setting
+        * an error is there?! */
+       if (!err_fns)
+               {
+               err_fns = fns;
+               ret = 1;
+               }
+       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
+       return ret;
+       }
+
+/* These are the callbacks provided to "lh_new()" when creating the LHASH tables
+ * internal to the "err_defaults" implementation. */
+
+static unsigned long get_error_values(int inc,int top,const char **file,int *line,
+                                     const char **data,int *flags);
+
+/* The internal functions used in the "err_defaults" implementation */
+
+static unsigned long err_string_data_hash(const ERR_STRING_DATA *a)
+       {
+       unsigned long ret,l;
+
+       l=a->error;
+       ret=l^ERR_GET_LIB(l)^ERR_GET_FUNC(l);
+       return(ret^ret%19*13);
+       }
+static IMPLEMENT_LHASH_HASH_FN(err_string_data, ERR_STRING_DATA)
+
+static int err_string_data_cmp(const ERR_STRING_DATA *a,
+                              const ERR_STRING_DATA *b)
+       {
+       return (int)(a->error - b->error);
+       }
+static IMPLEMENT_LHASH_COMP_FN(err_string_data, ERR_STRING_DATA)
+
+static LHASH_OF(ERR_STRING_DATA) *int_err_get(int create)
+       {
+       LHASH_OF(ERR_STRING_DATA) *ret = NULL;
+
+       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
+       if (!int_error_hash && create)
+               {
+               CRYPTO_push_info("int_err_get (err.c)");
+               int_error_hash = lh_ERR_STRING_DATA_new();
+               CRYPTO_pop_info();
+               }
+       if (int_error_hash)
+               ret = int_error_hash;
+       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
+
+       return ret;
+       }
+
+static void int_err_del(void)
+       {
+       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
+       if (int_error_hash)
+               {
+               lh_ERR_STRING_DATA_free(int_error_hash);
+               int_error_hash = NULL;
+               }
+       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
+       }
+
+static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *d)
+       {
+       ERR_STRING_DATA *p;
+       LHASH_OF(ERR_STRING_DATA) *hash;
+
+       err_fns_check();
+       hash = ERRFN(err_get)(0);
+       if (!hash)
+               return NULL;
+
+       CRYPTO_r_lock(CRYPTO_LOCK_ERR);
+       p = lh_ERR_STRING_DATA_retrieve(hash, d);
+       CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
+
+       return p;
+       }
+
+static ERR_STRING_DATA *int_err_set_item(ERR_STRING_DATA *d)
+       {
+       ERR_STRING_DATA *p;
+       LHASH_OF(ERR_STRING_DATA) *hash;
+
+       err_fns_check();
+       hash = ERRFN(err_get)(1);
+       if (!hash)
+               return NULL;
+
+       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
+       p = lh_ERR_STRING_DATA_insert(hash, d);
+       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
+
+       return p;
+       }
+
+static ERR_STRING_DATA *int_err_del_item(ERR_STRING_DATA *d)
+       {
+       ERR_STRING_DATA *p;
+       LHASH_OF(ERR_STRING_DATA) *hash;
+
+       err_fns_check();
+       hash = ERRFN(err_get)(0);
+       if (!hash)
+               return NULL;
+
+       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
+       p = lh_ERR_STRING_DATA_delete(hash, d);
+       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
+
+       return p;
+       }
+
+static unsigned long err_state_hash(const ERR_STATE *a)
+       {
+       return CRYPTO_THREADID_hash(&a->tid) * 13;
+       }
+static IMPLEMENT_LHASH_HASH_FN(err_state, ERR_STATE)
+
+static int err_state_cmp(const ERR_STATE *a, const ERR_STATE *b)
+       {
+       return CRYPTO_THREADID_cmp(&a->tid, &b->tid);
+       }
+static IMPLEMENT_LHASH_COMP_FN(err_state, ERR_STATE)
+
+static LHASH_OF(ERR_STATE) *int_thread_get(int create)
+       {
+       LHASH_OF(ERR_STATE) *ret = NULL;
+
+       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
+       if (!int_thread_hash && create)
+               {
+               CRYPTO_push_info("int_thread_get (err.c)");
+               int_thread_hash = lh_ERR_STATE_new();
+               CRYPTO_pop_info();
+               }
+       if (int_thread_hash)
+               {
+               int_thread_hash_references++;
+               ret = int_thread_hash;
+               }
+       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
+       return ret;
+       }
+
+static void int_thread_release(LHASH_OF(ERR_STATE) **hash)
+       {
+       int i;
+
+       if (hash == NULL || *hash == NULL)
+               return;
+
+       i = CRYPTO_add(&int_thread_hash_references, -1, CRYPTO_LOCK_ERR);
+
+#ifdef REF_PRINT
+       fprintf(stderr,"%4d:%s\n",int_thread_hash_references,"ERR");
+#endif
+       if (i > 0) return;
+#ifdef REF_CHECK
+       if (i < 0)
+               {
+               fprintf(stderr,"int_thread_release, bad reference count\n");
+               abort(); /* ok */
+               }
+#endif
+       *hash = NULL;
+       }
+
+static ERR_STATE *int_thread_get_item(const ERR_STATE *d)
+       {
+       ERR_STATE *p;
+       LHASH_OF(ERR_STATE) *hash;
+
+       err_fns_check();
+       hash = ERRFN(thread_get)(0);
+       if (!hash)
+               return NULL;
+
+       CRYPTO_r_lock(CRYPTO_LOCK_ERR);
+       p = lh_ERR_STATE_retrieve(hash, d);
+       CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
+
+       ERRFN(thread_release)(&hash);
+       return p;
+       }
+
+static ERR_STATE *int_thread_set_item(ERR_STATE *d)
+       {
+       ERR_STATE *p;
+       LHASH_OF(ERR_STATE) *hash;
+
+       err_fns_check();
+       hash = ERRFN(thread_get)(1);
+       if (!hash)
+               return NULL;
+
+       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
+       p = lh_ERR_STATE_insert(hash, d);
+       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
+
+       ERRFN(thread_release)(&hash);
+       return p;
+       }
+
+static void int_thread_del_item(const ERR_STATE *d)
+       {
+       ERR_STATE *p;
+       LHASH_OF(ERR_STATE) *hash;
+
+       err_fns_check();
+       hash = ERRFN(thread_get)(0);
+       if (!hash)
+               return;
+
+       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
+       p = lh_ERR_STATE_delete(hash, d);
+       /* make sure we don't leak memory */
+       if (int_thread_hash_references == 1
+           && int_thread_hash && lh_ERR_STATE_num_items(int_thread_hash) == 0)
+               {
+               lh_ERR_STATE_free(int_thread_hash);
+               int_thread_hash = NULL;
+               }
+       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
+
+       ERRFN(thread_release)(&hash);
+       if (p)
+               ERR_STATE_free(p);
+       }
+
+static int int_err_get_next_lib(void)
+       {
+       int ret;
+
+       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
+       ret = int_err_library_number++;
+       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
+
+       return ret;
+       }
+
+
+#ifndef OPENSSL_NO_ERR
+#define NUM_SYS_STR_REASONS 127
+#define LEN_SYS_STR_REASON 32
+
+static ERR_STRING_DATA SYS_str_reasons[NUM_SYS_STR_REASONS + 1];
+/* SYS_str_reasons is filled with copies of strerror() results at
+ * initialization.
+ * 'errno' values up to 127 should cover all usual errors,
+ * others will be displayed numerically by ERR_error_string.
+ * It is crucial that we have something for each reason code
+ * that occurs in ERR_str_reasons, or bogus reason strings
+ * will be returned for SYSerr(), which always gets an errno
+ * value and never one of those 'standard' reason codes. */
+
+static void build_SYS_str_reasons(void)
+       {
+       /* OPENSSL_malloc cannot be used here, use static storage instead */
+       static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON];
+       int i;
+       static int init = 1;
+
+       CRYPTO_r_lock(CRYPTO_LOCK_ERR);
+       if (!init)
+               {
+               CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
+               return;
+               }
+       
+       CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
+       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
+       if (!init)
+               {
+               CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
+               return;
+               }
+
+       for (i = 1; i <= NUM_SYS_STR_REASONS; i++)
+               {
+               ERR_STRING_DATA *str = &SYS_str_reasons[i - 1];
+
+               str->error = (unsigned long)i;
+               if (str->string == NULL)
+                       {
+                       char (*dest)[LEN_SYS_STR_REASON] = &(strerror_tab[i - 1]);
+                       char *src = strerror(i);
+                       if (src != NULL)
+                               {
+                               strncpy(*dest, src, sizeof *dest);
+                               (*dest)[sizeof *dest - 1] = '\0';
+                               str->string = *dest;
+                               }
+                       }
+               if (str->string == NULL)
+                       str->string = "unknown";
+               }
+
+       /* Now we still have SYS_str_reasons[NUM_SYS_STR_REASONS] = {0, NULL},
+        * as required by ERR_load_strings. */
+
+       init = 0;
+       
+       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
+       }
+#endif
 
 #define err_clear_data(p,i) \
        do { \
@@ -143,6 +641,68 @@ static unsigned long get_error_values(int inc,int top,
        (p)->err_line[i]= -1; \
        } while(0)
 
+static void ERR_STATE_free(ERR_STATE *s)
+       {
+       int i;
+
+       if (s == NULL)
+           return;
+
+       for (i=0; i<ERR_NUM_ERRORS; i++)
+               {
+               err_clear_data(s,i);
+               }
+       OPENSSL_free(s);
+       }
+
+void ERR_load_ERR_strings(void)
+       {
+       err_fns_check();
+#ifndef OPENSSL_NO_ERR
+       err_load_strings(0,ERR_str_libraries);
+       err_load_strings(0,ERR_str_reasons);
+       err_load_strings(ERR_LIB_SYS,ERR_str_functs);
+       build_SYS_str_reasons();
+       err_load_strings(ERR_LIB_SYS,SYS_str_reasons);
+#endif
+       }
+
+static void err_load_strings(int lib, ERR_STRING_DATA *str)
+       {
+       while (str->error)
+               {
+               if (lib)
+                       str->error|=ERR_PACK(lib,0,0);
+               ERRFN(err_set_item)(str);
+               str++;
+               }
+       }
+
+void ERR_load_strings(int lib, ERR_STRING_DATA *str)
+       {
+       ERR_load_ERR_strings();
+       err_load_strings(lib, str);
+       }
+
+void ERR_unload_strings(int lib, ERR_STRING_DATA *str)
+       {
+       while (str->error)
+               {
+               if (lib)
+                       str->error|=ERR_PACK(lib,0,0);
+               ERRFN(err_del_item)(str);
+               str++;
+               }
+       }
+
+void ERR_free_strings(void)
+       {
+       err_fns_check();
+       ERRFN(err_del)();
+       }
+
+/********************************************************/
+
 void ERR_put_error(int lib, int func, int reason, const char *file,
             int line)
        {
@@ -297,6 +857,196 @@ static unsigned long get_error_values(int inc, int top, const char **file, int *
        return ret;
        }
 
+void ERR_error_string_n(unsigned long e, char *buf, size_t len)
+       {
+       char lsbuf[64], fsbuf[64], rsbuf[64];
+       const char *ls,*fs,*rs;
+       unsigned long l,f,r;
+
+       l=ERR_GET_LIB(e);
+       f=ERR_GET_FUNC(e);
+       r=ERR_GET_REASON(e);
+
+       ls=ERR_lib_error_string(e);
+       fs=ERR_func_error_string(e);
+       rs=ERR_reason_error_string(e);
+
+       if (ls == NULL) 
+               BIO_snprintf(lsbuf, sizeof(lsbuf), "lib(%lu)", l);
+       if (fs == NULL)
+               BIO_snprintf(fsbuf, sizeof(fsbuf), "func(%lu)", f);
+       if (rs == NULL)
+               BIO_snprintf(rsbuf, sizeof(rsbuf), "reason(%lu)", r);
+
+       BIO_snprintf(buf, len,"error:%08lX:%s:%s:%s", e, ls?ls:lsbuf, 
+               fs?fs:fsbuf, rs?rs:rsbuf);
+       if (strlen(buf) == len-1)
+               {
+               /* output may be truncated; make sure we always have 5 
+                * colon-separated fields, i.e. 4 colons ... */
+#define NUM_COLONS 4
+               if (len > NUM_COLONS) /* ... if possible */
+                       {
+                       int i;
+                       char *s = buf;
+                       
+                       for (i = 0; i < NUM_COLONS; i++)
+                               {
+                               char *colon = strchr(s, ':');
+                               if (colon == NULL || colon > &buf[len-1] - NUM_COLONS + i)
+                                       {
+                                       /* set colon no. i at last possible position
+                                        * (buf[len-1] is the terminating 0)*/
+                                       colon = &buf[len-1] - NUM_COLONS + i;
+                                       *colon = ':';
+                                       }
+                               s = colon + 1;
+                               }
+                       }
+               }
+       }
+
+/* BAD for multi-threading: uses a local buffer if ret == NULL */
+/* ERR_error_string_n should be used instead for ret != NULL
+ * as ERR_error_string cannot know how large the buffer is */
+char *ERR_error_string(unsigned long e, char *ret)
+       {
+       static char buf[256];
+
+       if (ret == NULL) ret=buf;
+       ERR_error_string_n(e, ret, 256);
+
+       return ret;
+       }
+
+LHASH_OF(ERR_STRING_DATA) *ERR_get_string_table(void)
+       {
+       err_fns_check();
+       return ERRFN(err_get)(0);
+       }
+
+LHASH_OF(ERR_STATE) *ERR_get_err_state_table(void)
+       {
+       err_fns_check();
+       return ERRFN(thread_get)(0);
+       }
+
+void ERR_release_err_state_table(LHASH_OF(ERR_STATE) **hash)
+       {
+       err_fns_check();
+       ERRFN(thread_release)(hash);
+       }
+
+const char *ERR_lib_error_string(unsigned long e)
+       {
+       ERR_STRING_DATA d,*p;
+       unsigned long l;
+
+       err_fns_check();
+       l=ERR_GET_LIB(e);
+       d.error=ERR_PACK(l,0,0);
+       p=ERRFN(err_get_item)(&d);
+       return((p == NULL)?NULL:p->string);
+       }
+
+const char *ERR_func_error_string(unsigned long e)
+       {
+       ERR_STRING_DATA d,*p;
+       unsigned long l,f;
+
+       err_fns_check();
+       l=ERR_GET_LIB(e);
+       f=ERR_GET_FUNC(e);
+       d.error=ERR_PACK(l,f,0);
+       p=ERRFN(err_get_item)(&d);
+       return((p == NULL)?NULL:p->string);
+       }
+
+const char *ERR_reason_error_string(unsigned long e)
+       {
+       ERR_STRING_DATA d,*p=NULL;
+       unsigned long l,r;
+
+       err_fns_check();
+       l=ERR_GET_LIB(e);
+       r=ERR_GET_REASON(e);
+       d.error=ERR_PACK(l,0,r);
+       p=ERRFN(err_get_item)(&d);
+       if (!p)
+               {
+               d.error=ERR_PACK(0,0,r);
+               p=ERRFN(err_get_item)(&d);
+               }
+       return((p == NULL)?NULL:p->string);
+       }
+
+void ERR_remove_thread_state(const CRYPTO_THREADID *id)
+       {
+       ERR_STATE tmp;
+
+       if (id)
+               CRYPTO_THREADID_cpy(&tmp.tid, id);
+       else
+               CRYPTO_THREADID_current(&tmp.tid);
+       err_fns_check();
+       /* thread_del_item automatically destroys the LHASH if the number of
+        * items reaches zero. */
+       ERRFN(thread_del_item)(&tmp);
+       }
+
+#ifndef OPENSSL_NO_DEPRECATED
+void ERR_remove_state(unsigned long pid)
+       {
+       ERR_remove_thread_state(NULL);
+       }
+#endif
+
+ERR_STATE *ERR_get_state(void)
+       {
+       static ERR_STATE fallback;
+       ERR_STATE *ret,tmp,*tmpp=NULL;
+       int i;
+       CRYPTO_THREADID tid;
+
+       err_fns_check();
+       CRYPTO_THREADID_current(&tid);
+       CRYPTO_THREADID_cpy(&tmp.tid, &tid);
+       ret=ERRFN(thread_get_item)(&tmp);
+
+       /* ret == the error state, if NULL, make a new one */
+       if (ret == NULL)
+               {
+               ret=(ERR_STATE *)OPENSSL_malloc(sizeof(ERR_STATE));
+               if (ret == NULL) return(&fallback);
+               CRYPTO_THREADID_cpy(&ret->tid, &tid);
+               ret->top=0;
+               ret->bottom=0;
+               for (i=0; i<ERR_NUM_ERRORS; i++)
+                       {
+                       ret->err_data[i]=NULL;
+                       ret->err_data_flags[i]=0;
+                       }
+               tmpp = ERRFN(thread_set_item)(ret);
+               /* To check if insertion failed, do a get. */
+               if (ERRFN(thread_get_item)(ret) != ret)
+                       {
+                       ERR_STATE_free(ret); /* could not insert it */
+                       return(&fallback);
+                       }
+               /* If a race occured in this function and we came second, tmpp
+                * is the first one that we just replaced. */
+               if (tmpp)
+                       ERR_STATE_free(tmpp);
+               }
+       return ret;
+       }
+
+int ERR_get_next_error_library(void)
+       {
+       err_fns_check();
+       return ERRFN(get_next_lib)();
+       }
+
 void ERR_set_error_data(char *data, int flags)
        {
        ERR_STATE *es;
@@ -383,34 +1133,3 @@ int ERR_pop_to_mark(void)
        es->err_flags[es->top]&=~ERR_FLAG_MARK;
        return 1;
        }
-
-#ifdef OPENSSL_FIPS
-
-static ERR_STATE *fget_state(void)
-       {
-       static ERR_STATE fstate;
-       return &fstate;
-       }
-
-ERR_STATE *(*get_state_func)(void) = fget_state;
-void (*remove_state_func)(unsigned long pid);
-
-ERR_STATE *ERR_get_state(void)
-       {
-       return get_state_func();
-       }
-
-void int_ERR_set_state_func(ERR_STATE *(*get_func)(void),
-                               void (*remove_func)(unsigned long pid))
-       {
-       get_state_func = get_func;
-       remove_state_func = remove_func;
-       }
-
-void ERR_remove_state(unsigned long pid)
-       {
-       if (remove_state_func)
-               remove_state_func(pid);
-       }
-
-#endif
index dcac415..b9f8c16 100644 (file)
  * copied and put under another distribution licence
  * [including the GNU Public Licence.]
  */
+/* ====================================================================
+ * Copyright (c) 1998-2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    openssl-core@openssl.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
 
 #ifndef HEADER_ERR_H
 #define HEADER_ERR_H
@@ -94,7 +147,7 @@ extern "C" {
 #define ERR_NUM_ERRORS 16
 typedef struct err_state_st
        {
-       unsigned long pid;
+       CRYPTO_THREADID tid;
        int err_flags[ERR_NUM_ERRORS];
        unsigned long err_buffer[ERR_NUM_ERRORS];
        char *err_data[ERR_NUM_ERRORS];
@@ -142,7 +195,9 @@ typedef struct err_state_st
 #define ERR_LIB_STORE           44
 #define ERR_LIB_FIPS           45
 #define ERR_LIB_CMS            46
-#define ERR_LIB_JPAKE          47
+#define ERR_LIB_TS             47
+#define ERR_LIB_HMAC           48
+#define ERR_LIB_JPAKE          49
 
 #define ERR_LIB_USER           128
 
@@ -176,6 +231,8 @@ typedef struct err_state_st
 #define STOREerr(f,r) ERR_PUT_error(ERR_LIB_STORE,(f),(r),__FILE__,__LINE__)
 #define FIPSerr(f,r) ERR_PUT_error(ERR_LIB_FIPS,(f),(r),__FILE__,__LINE__)
 #define CMSerr(f,r) ERR_PUT_error(ERR_LIB_CMS,(f),(r),__FILE__,__LINE__)
+#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__)
 
 /* Borland C seems too stupid to be able to shift and do longs in
@@ -232,6 +289,7 @@ typedef struct err_state_st
 #define ERR_R_ECDSA_LIB ERR_LIB_ECDSA   /* 42 */
 #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_NESTED_ASN1_ERROR                        58
 #define ERR_R_BAD_ASN1_OBJECT_HEADER           59
@@ -294,13 +352,16 @@ void ERR_load_ERR_strings(void);
 void ERR_load_crypto_strings(void);
 void ERR_free_strings(void);
 
+void ERR_remove_thread_state(const CRYPTO_THREADID *tid);
+#ifndef OPENSSL_NO_DEPRECATED
 void ERR_remove_state(unsigned long pid); /* if zero we look it up */
+#endif
 ERR_STATE *ERR_get_state(void);
 
 #ifndef OPENSSL_NO_LHASH
-LHASH *ERR_get_string_table(void);
-LHASH *ERR_get_err_state_table(void);
-void ERR_release_err_state_table(LHASH **hash);
+LHASH_OF(ERR_STRING_DATA) *ERR_get_string_table(void);
+LHASH_OF(ERR_STATE) *ERR_get_err_state_table(void);
+void ERR_release_err_state_table(LHASH_OF(ERR_STATE) **hash);
 #endif
 
 int ERR_get_next_error_library(void);
@@ -308,12 +369,6 @@ int ERR_get_next_error_library(void);
 int ERR_set_mark(void);
 int ERR_pop_to_mark(void);
 
-#ifdef OPENSSL_FIPS
-void int_ERR_set_state_func(ERR_STATE *(*get_func)(void),
-                               void (*remove_func)(unsigned long pid));
-void int_ERR_lib_init(void);
-#endif
-
 /* Already defined in ossl_typ.h */
 /* typedef struct st_ERR_FNS ERR_FNS; */
 /* An application can use this function and provide the return value to loaded
index 39796f7..fc049e8 100644 (file)
@@ -64,6 +64,7 @@
 #endif
 #include <openssl/buffer.h>
 #include <openssl/bio.h>
+#include <openssl/comp.h>
 #ifndef OPENSSL_NO_RSA
 #include <openssl/rsa.h>
 #endif
 #include <openssl/ui.h>
 #include <openssl/ocsp.h>
 #include <openssl/err.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
+#include <openssl/ts.h>
 #ifndef OPENSSL_NO_CMS
 #include <openssl/cms.h>
 #endif
@@ -128,6 +126,7 @@ void ERR_load_crypto_strings(void)
        ERR_load_ASN1_strings();
        ERR_load_CONF_strings();
        ERR_load_CRYPTO_strings();
+       ERR_load_COMP_strings();
 #ifndef OPENSSL_NO_EC
        ERR_load_EC_strings();
 #endif
@@ -144,14 +143,12 @@ void ERR_load_crypto_strings(void)
        ERR_load_PKCS12_strings();
        ERR_load_RAND_strings();
        ERR_load_DSO_strings();
+       ERR_load_TS_strings();
 #ifndef OPENSSL_NO_ENGINE
        ERR_load_ENGINE_strings();
 #endif
        ERR_load_OCSP_strings();
        ERR_load_UI_strings();
-#ifdef OPENSSL_FIPS
-       ERR_load_FIPS_strings();
-#endif
 #ifndef OPENSSL_NO_CMS
        ERR_load_CMS_strings();
 #endif
diff --git a/deps/openssl/openssl/crypto/err/err_def.c b/deps/openssl/openssl/crypto/err/err_def.c
deleted file mode 100644 (file)
index 7ed3d84..0000000
+++ /dev/null
@@ -1,665 +0,0 @@
-/* crypto/err/err_def.c */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-/* ====================================================================
- * Copyright (c) 1998-2001 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    openssl-core@openssl.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
- * ====================================================================
- *
- * This product includes cryptographic software written by Eric Young
- * (eay@cryptsoft.com).  This product includes software written by Tim
- * Hudson (tjh@cryptsoft.com).
- *
- */
-
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
-#include "cryptlib.h"
-#include <openssl/lhash.h>
-#include <openssl/crypto.h>
-#include <openssl/buffer.h>
-#include <openssl/bio.h>
-#include <openssl/err.h>
-
-#define err_clear_data(p,i) \
-       do { \
-       if (((p)->err_data[i] != NULL) && \
-               (p)->err_data_flags[i] & ERR_TXT_MALLOCED) \
-               {  \
-               OPENSSL_free((p)->err_data[i]); \
-               (p)->err_data[i]=NULL; \
-               } \
-       (p)->err_data_flags[i]=0; \
-       } while(0)
-
-#define err_clear(p,i) \
-       do { \
-       (p)->err_flags[i]=0; \
-       (p)->err_buffer[i]=0; \
-       err_clear_data(p,i); \
-       (p)->err_file[i]=NULL; \
-       (p)->err_line[i]= -1; \
-       } while(0)
-
-static void err_load_strings(int lib, ERR_STRING_DATA *str);
-
-static void ERR_STATE_free(ERR_STATE *s);
-
-/* Define the predeclared (but externally opaque) "ERR_FNS" type */
-struct st_ERR_FNS
-       {
-       /* Works on the "error_hash" string table */
-       LHASH *(*cb_err_get)(int create);
-       void (*cb_err_del)(void);
-       ERR_STRING_DATA *(*cb_err_get_item)(const ERR_STRING_DATA *);
-       ERR_STRING_DATA *(*cb_err_set_item)(ERR_STRING_DATA *);
-       ERR_STRING_DATA *(*cb_err_del_item)(ERR_STRING_DATA *);
-       /* Works on the "thread_hash" error-state table */
-       LHASH *(*cb_thread_get)(int create);
-       void (*cb_thread_release)(LHASH **hash);
-       ERR_STATE *(*cb_thread_get_item)(const ERR_STATE *);
-       ERR_STATE *(*cb_thread_set_item)(ERR_STATE *);
-       void (*cb_thread_del_item)(const ERR_STATE *);
-       /* Returns the next available error "library" numbers */
-       int (*cb_get_next_lib)(void);
-       };
-
-/* Predeclarations of the "err_defaults" functions */
-static LHASH *int_err_get(int create);
-static void int_err_del(void);
-static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *);
-static ERR_STRING_DATA *int_err_set_item(ERR_STRING_DATA *);
-static ERR_STRING_DATA *int_err_del_item(ERR_STRING_DATA *);
-static LHASH *int_thread_get(int create);
-static void int_thread_release(LHASH **hash);
-static ERR_STATE *int_thread_get_item(const ERR_STATE *);
-static ERR_STATE *int_thread_set_item(ERR_STATE *);
-static void int_thread_del_item(const ERR_STATE *);
-static int int_err_get_next_lib(void);
-/* The static ERR_FNS table using these defaults functions */
-static const ERR_FNS err_defaults =
-       {
-       int_err_get,
-       int_err_del,
-       int_err_get_item,
-       int_err_set_item,
-       int_err_del_item,
-       int_thread_get,
-       int_thread_release,
-       int_thread_get_item,
-       int_thread_set_item,
-       int_thread_del_item,
-       int_err_get_next_lib
-       };
-
-/* The replacable table of ERR_FNS functions we use at run-time */
-static const ERR_FNS *err_fns = NULL;
-
-/* Eg. rather than using "err_get()", use "ERRFN(err_get)()". */
-#define ERRFN(a) err_fns->cb_##a
-
-/* The internal state used by "err_defaults" - as such, the setting, reading,
- * creating, and deleting of this data should only be permitted via the
- * "err_defaults" functions. This way, a linked module can completely defer all
- * ERR state operation (together with requisite locking) to the implementations
- * and state in the loading application. */
-static LHASH *int_error_hash = NULL;
-static LHASH *int_thread_hash = NULL;
-static int int_thread_hash_references = 0;
-static int int_err_library_number= ERR_LIB_USER;
-
-/* Internal function that checks whether "err_fns" is set and if not, sets it to
- * the defaults. */
-static void err_fns_check(void)
-       {
-       if (err_fns) return;
-       
-       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
-       if (!err_fns)
-               err_fns = &err_defaults;
-       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
-       }
-
-/* API functions to get or set the underlying ERR functions. */
-
-const ERR_FNS *ERR_get_implementation(void)
-       {
-       err_fns_check();
-       return err_fns;
-       }
-
-int ERR_set_implementation(const ERR_FNS *fns)
-       {
-       int ret = 0;
-
-       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
-       /* It's too late if 'err_fns' is non-NULL. BTW: not much point setting
-        * an error is there?! */
-       if (!err_fns)
-               {
-               err_fns = fns;
-               ret = 1;
-               }
-       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
-       return ret;
-       }
-
-/* These are the callbacks provided to "lh_new()" when creating the LHASH tables
- * internal to the "err_defaults" implementation. */
-
-/* static unsigned long err_hash(ERR_STRING_DATA *a); */
-static unsigned long err_hash(const void *a_void);
-/* static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b); */
-static int err_cmp(const void *a_void, const void *b_void);
-/* static unsigned long pid_hash(ERR_STATE *pid); */
-static unsigned long pid_hash(const void *pid_void);
-/* static int pid_cmp(ERR_STATE *a,ERR_STATE *pid); */
-static int pid_cmp(const void *a_void,const void *pid_void);
-
-/* The internal functions used in the "err_defaults" implementation */
-
-static LHASH *int_err_get(int create)
-       {
-       LHASH *ret = NULL;
-
-       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
-       if (!int_error_hash && create)
-               {
-               CRYPTO_push_info("int_err_get (err.c)");
-               int_error_hash = lh_new(err_hash, err_cmp);
-               CRYPTO_pop_info();
-               }
-       if (int_error_hash)
-               ret = int_error_hash;
-       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
-
-       return ret;
-       }
-
-static void int_err_del(void)
-       {
-       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
-       if (int_error_hash)
-               {
-               lh_free(int_error_hash);
-               int_error_hash = NULL;
-               }
-       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
-       }
-
-static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *d)
-       {
-       ERR_STRING_DATA *p;
-       LHASH *hash;
-
-       err_fns_check();
-       hash = ERRFN(err_get)(0);
-       if (!hash)
-               return NULL;
-
-       CRYPTO_r_lock(CRYPTO_LOCK_ERR);
-       p = (ERR_STRING_DATA *)lh_retrieve(hash, d);
-       CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
-
-       return p;
-       }
-
-static ERR_STRING_DATA *int_err_set_item(ERR_STRING_DATA *d)
-       {
-       ERR_STRING_DATA *p;
-       LHASH *hash;
-
-       err_fns_check();
-       hash = ERRFN(err_get)(1);
-       if (!hash)
-               return NULL;
-
-       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
-       p = (ERR_STRING_DATA *)lh_insert(hash, d);
-       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
-
-       return p;
-       }
-
-static ERR_STRING_DATA *int_err_del_item(ERR_STRING_DATA *d)
-       {
-       ERR_STRING_DATA *p;
-       LHASH *hash;
-
-       err_fns_check();
-       hash = ERRFN(err_get)(0);
-       if (!hash)
-               return NULL;
-
-       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
-       p = (ERR_STRING_DATA *)lh_delete(hash, d);
-       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
-
-       return p;
-       }
-
-static LHASH *int_thread_get(int create)
-       {
-       LHASH *ret = NULL;
-
-       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
-       if (!int_thread_hash && create)
-               {
-               CRYPTO_push_info("int_thread_get (err.c)");
-               int_thread_hash = lh_new(pid_hash, pid_cmp);
-               CRYPTO_pop_info();
-               }
-       if (int_thread_hash)
-               {
-               int_thread_hash_references++;
-               ret = int_thread_hash;
-               }
-       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
-       return ret;
-       }
-
-static void int_thread_release(LHASH **hash)
-       {
-       int i;
-
-       if (hash == NULL || *hash == NULL)
-               return;
-
-       i = CRYPTO_add(&int_thread_hash_references, -1, CRYPTO_LOCK_ERR);
-
-#ifdef REF_PRINT
-       fprintf(stderr,"%4d:%s\n",int_thread_hash_references,"ERR");
-#endif
-       if (i > 0) return;
-#ifdef REF_CHECK
-       if (i < 0)
-               {
-               fprintf(stderr,"int_thread_release, bad reference count\n");
-               abort(); /* ok */
-               }
-#endif
-       *hash = NULL;
-       }
-
-static ERR_STATE *int_thread_get_item(const ERR_STATE *d)
-       {
-       ERR_STATE *p;
-       LHASH *hash;
-
-       err_fns_check();
-       hash = ERRFN(thread_get)(0);
-       if (!hash)
-               return NULL;
-
-       CRYPTO_r_lock(CRYPTO_LOCK_ERR);
-       p = (ERR_STATE *)lh_retrieve(hash, d);
-       CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
-
-       ERRFN(thread_release)(&hash);
-       return p;
-       }
-
-static ERR_STATE *int_thread_set_item(ERR_STATE *d)
-       {
-       ERR_STATE *p;
-       LHASH *hash;
-
-       err_fns_check();
-       hash = ERRFN(thread_get)(1);
-       if (!hash)
-               return NULL;
-
-       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
-       p = (ERR_STATE *)lh_insert(hash, d);
-       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
-
-       ERRFN(thread_release)(&hash);
-       return p;
-       }
-
-static void int_thread_del_item(const ERR_STATE *d)
-       {
-       ERR_STATE *p;
-       LHASH *hash;
-
-       err_fns_check();
-       hash = ERRFN(thread_get)(0);
-       if (!hash)
-               return;
-
-       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
-       p = (ERR_STATE *)lh_delete(hash, d);
-       /* make sure we don't leak memory */
-       if (int_thread_hash_references == 1
-               && int_thread_hash && (lh_num_items(int_thread_hash) == 0))
-               {
-               lh_free(int_thread_hash);
-               int_thread_hash = NULL;
-               }
-       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
-
-       ERRFN(thread_release)(&hash);
-       if (p)
-               ERR_STATE_free(p);
-       }
-
-static int int_err_get_next_lib(void)
-       {
-       int ret;
-
-       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
-       ret = int_err_library_number++;
-       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
-
-       return ret;
-       }
-
-static void ERR_STATE_free(ERR_STATE *s)
-       {
-       int i;
-
-       if (s == NULL)
-           return;
-
-       for (i=0; i<ERR_NUM_ERRORS; i++)
-               {
-               err_clear_data(s,i);
-               }
-       OPENSSL_free(s);
-       }
-
-static void err_load_strings(int lib, ERR_STRING_DATA *str)
-       {
-       while (str->error)
-               {
-               if (lib)
-                       str->error|=ERR_PACK(lib,0,0);
-               ERRFN(err_set_item)(str);
-               str++;
-               }
-       }
-
-void ERR_load_strings(int lib, ERR_STRING_DATA *str)
-       {
-       err_fns_check();
-       err_load_strings(lib, str);
-       }
-
-void ERR_unload_strings(int lib, ERR_STRING_DATA *str)
-       {
-       while (str->error)
-               {
-               if (lib)
-                       str->error|=ERR_PACK(lib,0,0);
-               ERRFN(err_del_item)(str);
-               str++;
-               }
-       }
-
-void ERR_free_strings(void)
-       {
-       err_fns_check();
-       ERRFN(err_del)();
-       }
-
-LHASH *ERR_get_string_table(void)
-       {
-       err_fns_check();
-       return ERRFN(err_get)(0);
-       }
-
-LHASH *ERR_get_err_state_table(void)
-       {
-       err_fns_check();
-       return ERRFN(thread_get)(0);
-       }
-
-void ERR_release_err_state_table(LHASH **hash)
-       {
-       err_fns_check();
-       ERRFN(thread_release)(hash);
-       }
-
-const char *ERR_lib_error_string(unsigned long e)
-       {
-       ERR_STRING_DATA d,*p;
-       unsigned long l;
-
-       err_fns_check();
-       l=ERR_GET_LIB(e);
-       d.error=ERR_PACK(l,0,0);
-       p=ERRFN(err_get_item)(&d);
-       return((p == NULL)?NULL:p->string);
-       }
-
-const char *ERR_func_error_string(unsigned long e)
-       {
-       ERR_STRING_DATA d,*p;
-       unsigned long l,f;
-
-       err_fns_check();
-       l=ERR_GET_LIB(e);
-       f=ERR_GET_FUNC(e);
-       d.error=ERR_PACK(l,f,0);
-       p=ERRFN(err_get_item)(&d);
-       return((p == NULL)?NULL:p->string);
-       }
-
-const char *ERR_reason_error_string(unsigned long e)
-       {
-       ERR_STRING_DATA d,*p=NULL;
-       unsigned long l,r;
-
-       err_fns_check();
-       l=ERR_GET_LIB(e);
-       r=ERR_GET_REASON(e);
-       d.error=ERR_PACK(l,0,r);
-       p=ERRFN(err_get_item)(&d);
-       if (!p)
-               {
-               d.error=ERR_PACK(0,0,r);
-               p=ERRFN(err_get_item)(&d);
-               }
-       return((p == NULL)?NULL:p->string);
-       }
-
-/* static unsigned long err_hash(ERR_STRING_DATA *a) */
-static unsigned long err_hash(const void *a_void)
-       {
-       unsigned long ret,l;
-
-       l=((const ERR_STRING_DATA *)a_void)->error;
-       ret=l^ERR_GET_LIB(l)^ERR_GET_FUNC(l);
-       return(ret^ret%19*13);
-       }
-
-/* static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b) */
-static int err_cmp(const void *a_void, const void *b_void)
-       {
-       return((int)(((const ERR_STRING_DATA *)a_void)->error -
-                       ((const ERR_STRING_DATA *)b_void)->error));
-       }
-
-/* static unsigned long pid_hash(ERR_STATE *a) */
-static unsigned long pid_hash(const void *a_void)
-       {
-       return(((const ERR_STATE *)a_void)->pid*13);
-       }
-
-/* static int pid_cmp(ERR_STATE *a, ERR_STATE *b) */
-static int pid_cmp(const void *a_void, const void *b_void)
-       {
-       return((int)((long)((const ERR_STATE *)a_void)->pid -
-                       (long)((const ERR_STATE *)b_void)->pid));
-       }
-#ifdef OPENSSL_FIPS
-static void int_err_remove_state(unsigned long pid)
-#else
-void ERR_remove_state(unsigned long pid)
-#endif
-       {
-       ERR_STATE tmp;
-
-       err_fns_check();
-       if (pid == 0)
-               pid=(unsigned long)CRYPTO_thread_id();
-       tmp.pid=pid;
-       /* thread_del_item automatically destroys the LHASH if the number of
-        * items reaches zero. */
-       ERRFN(thread_del_item)(&tmp);
-       }
-
-#ifdef OPENSSL_FIPS
-       static ERR_STATE *int_err_get_state(void)
-#else
-ERR_STATE *ERR_get_state(void)
-#endif
-       {
-       static ERR_STATE fallback;
-       ERR_STATE *ret,tmp,*tmpp=NULL;
-       int i;
-       unsigned long pid;
-
-       err_fns_check();
-       pid=(unsigned long)CRYPTO_thread_id();
-       tmp.pid=pid;
-       ret=ERRFN(thread_get_item)(&tmp);
-
-       /* ret == the error state, if NULL, make a new one */
-       if (ret == NULL)
-               {
-               ret=(ERR_STATE *)OPENSSL_malloc(sizeof(ERR_STATE));
-               if (ret == NULL) return(&fallback);
-               ret->pid=pid;
-               ret->top=0;
-               ret->bottom=0;
-               for (i=0; i<ERR_NUM_ERRORS; i++)
-                       {
-                       ret->err_data[i]=NULL;
-                       ret->err_data_flags[i]=0;
-                       }
-               tmpp = ERRFN(thread_set_item)(ret);
-               /* To check if insertion failed, do a get. */
-               if (ERRFN(thread_get_item)(ret) != ret)
-                       {
-                       ERR_STATE_free(ret); /* could not insert it */
-                       return(&fallback);
-                       }
-               /* If a race occured in this function and we came second, tmpp
-                * is the first one that we just replaced. */
-               if (tmpp)
-                       ERR_STATE_free(tmpp);
-               }
-       return ret;
-       }
-
-#ifdef OPENSSL_FIPS
-void int_ERR_lib_init(void)
-       {
-       int_ERR_set_state_func(int_err_get_state, int_err_remove_state);
-       }
-#endif
-
-int ERR_get_next_error_library(void)
-       {
-       err_fns_check();
-       return ERRFN(get_next_lib)();
-       }
index 1e46f93..a0168ac 100644 (file)
@@ -72,8 +72,10 @@ void ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u),
        const char *file,*data;
        int line,flags;
        unsigned long es;
+       CRYPTO_THREADID cur;
 
-       es=CRYPTO_thread_id();
+       CRYPTO_THREADID_current(&cur);
+       es=CRYPTO_THREADID_hash(&cur);
        while ((l=ERR_get_error_line_data(&file,&line,&data,&flags)) != 0)
                {
                ERR_error_string_n(l, buf, sizeof buf);
@@ -100,64 +102,13 @@ void ERR_print_errors_fp(FILE *fp)
        }
 #endif
 
-void ERR_error_string_n(unsigned long e, char *buf, size_t len)
+static int print_bio(const char *str, size_t len, void *bp)
        {
-       char lsbuf[64], fsbuf[64], rsbuf[64];
-       const char *ls,*fs,*rs;
-       unsigned long l,f,r;
-
-       l=ERR_GET_LIB(e);
-       f=ERR_GET_FUNC(e);
-       r=ERR_GET_REASON(e);
-
-       ls=ERR_lib_error_string(e);
-       fs=ERR_func_error_string(e);
-       rs=ERR_reason_error_string(e);
-
-       if (ls == NULL) 
-               BIO_snprintf(lsbuf, sizeof(lsbuf), "lib(%lu)", l);
-       if (fs == NULL)
-               BIO_snprintf(fsbuf, sizeof(fsbuf), "func(%lu)", f);
-       if (rs == NULL)
-               BIO_snprintf(rsbuf, sizeof(rsbuf), "reason(%lu)", r);
-
-       BIO_snprintf(buf, len,"error:%08lX:%s:%s:%s", e, ls?ls:lsbuf, 
-               fs?fs:fsbuf, rs?rs:rsbuf);
-       if (strlen(buf) == len-1)
-               {
-               /* output may be truncated; make sure we always have 5 
-                * colon-separated fields, i.e. 4 colons ... */
-#define NUM_COLONS 4
-               if (len > NUM_COLONS) /* ... if possible */
-                       {
-                       int i;
-                       char *s = buf;
-                       
-                       for (i = 0; i < NUM_COLONS; i++)
-                               {
-                               char *colon = strchr(s, ':');
-                               if (colon == NULL || colon > &buf[len-1] - NUM_COLONS + i)
-                                       {
-                                       /* set colon no. i at last possible position
-                                        * (buf[len-1] is the terminating 0)*/
-                                       colon = &buf[len-1] - NUM_COLONS + i;
-                                       *colon = ':';
-                                       }
-                               s = colon + 1;
-                               }
-                       }
-               }
+       return BIO_write((BIO *)bp, str, len);
        }
-
-/* BAD for multi-threading: uses a local buffer if ret == NULL */
-/* ERR_error_string_n should be used instead for ret != NULL
- * as ERR_error_string cannot know how large the buffer is */
-char *ERR_error_string(unsigned long e, char *ret)
+void ERR_print_errors(BIO *bp)
        {
-       static char buf[256];
-
-       if (ret == NULL) ret=buf;
-       ERR_error_string_n(e, ret, 256);
-
-       return ret;
+       ERR_print_errors_cb(print_bio, bp);
        }
+
+       
diff --git a/deps/openssl/openssl/crypto/err/err_str.c b/deps/openssl/openssl/crypto/err/err_str.c
deleted file mode 100644 (file)
index d390408..0000000
+++ /dev/null
@@ -1,295 +0,0 @@
-/* crypto/err/err_str.c */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-/* ====================================================================
- * Copyright (c) 1998-2001 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    openssl-core@openssl.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
- * ====================================================================
- *
- * This product includes cryptographic software written by Eric Young
- * (eay@cryptsoft.com).  This product includes software written by Tim
- * Hudson (tjh@cryptsoft.com).
- *
- */
-
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
-#include "cryptlib.h"
-#include <openssl/lhash.h>
-#include <openssl/crypto.h>
-#include <openssl/buffer.h>
-#include <openssl/bio.h>
-#include <openssl/err.h>
-
-#ifndef OPENSSL_NO_ERR
-static ERR_STRING_DATA ERR_str_libraries[]=
-       {
-{ERR_PACK(ERR_LIB_NONE,0,0)            ,"unknown library"},
-{ERR_PACK(ERR_LIB_SYS,0,0)             ,"system library"},
-{ERR_PACK(ERR_LIB_BN,0,0)              ,"bignum routines"},
-{ERR_PACK(ERR_LIB_RSA,0,0)             ,"rsa routines"},
-{ERR_PACK(ERR_LIB_DH,0,0)              ,"Diffie-Hellman routines"},
-{ERR_PACK(ERR_LIB_EVP,0,0)             ,"digital envelope routines"},
-{ERR_PACK(ERR_LIB_BUF,0,0)             ,"memory buffer routines"},
-{ERR_PACK(ERR_LIB_OBJ,0,0)             ,"object identifier routines"},
-{ERR_PACK(ERR_LIB_PEM,0,0)             ,"PEM routines"},
-{ERR_PACK(ERR_LIB_DSA,0,0)             ,"dsa routines"},
-{ERR_PACK(ERR_LIB_X509,0,0)            ,"x509 certificate routines"},
-{ERR_PACK(ERR_LIB_ASN1,0,0)            ,"asn1 encoding routines"},
-{ERR_PACK(ERR_LIB_CONF,0,0)            ,"configuration file routines"},
-{ERR_PACK(ERR_LIB_CRYPTO,0,0)          ,"common libcrypto routines"},
-{ERR_PACK(ERR_LIB_EC,0,0)              ,"elliptic curve routines"},
-{ERR_PACK(ERR_LIB_SSL,0,0)             ,"SSL routines"},
-{ERR_PACK(ERR_LIB_BIO,0,0)             ,"BIO routines"},
-{ERR_PACK(ERR_LIB_PKCS7,0,0)           ,"PKCS7 routines"},
-{ERR_PACK(ERR_LIB_X509V3,0,0)          ,"X509 V3 routines"},
-{ERR_PACK(ERR_LIB_PKCS12,0,0)          ,"PKCS12 routines"},
-{ERR_PACK(ERR_LIB_RAND,0,0)            ,"random number generator"},
-{ERR_PACK(ERR_LIB_DSO,0,0)             ,"DSO support routines"},
-{ERR_PACK(ERR_LIB_ENGINE,0,0)          ,"engine routines"},
-{ERR_PACK(ERR_LIB_OCSP,0,0)            ,"OCSP routines"},
-{ERR_PACK(ERR_LIB_FIPS,0,0)            ,"FIPS routines"},
-{ERR_PACK(ERR_LIB_CMS,0,0)             ,"CMS routines"},
-{ERR_PACK(ERR_LIB_JPAKE,0,0)           ,"JPAKE routines"},
-{0,NULL},
-       };
-
-static ERR_STRING_DATA ERR_str_functs[]=
-       {
-       {ERR_PACK(0,SYS_F_FOPEN,0),             "fopen"},
-       {ERR_PACK(0,SYS_F_CONNECT,0),           "connect"},
-       {ERR_PACK(0,SYS_F_GETSERVBYNAME,0),     "getservbyname"},
-       {ERR_PACK(0,SYS_F_SOCKET,0),            "socket"}, 
-       {ERR_PACK(0,SYS_F_IOCTLSOCKET,0),       "ioctlsocket"},
-       {ERR_PACK(0,SYS_F_BIND,0),              "bind"},
-       {ERR_PACK(0,SYS_F_LISTEN,0),            "listen"},
-       {ERR_PACK(0,SYS_F_ACCEPT,0),            "accept"},
-#ifdef OPENSSL_SYS_WINDOWS
-       {ERR_PACK(0,SYS_F_WSASTARTUP,0),        "WSAstartup"},
-#endif
-       {ERR_PACK(0,SYS_F_OPENDIR,0),           "opendir"},
-       {ERR_PACK(0,SYS_F_FREAD,0),             "fread"},
-       {0,NULL},
-       };
-
-static ERR_STRING_DATA ERR_str_reasons[]=
-       {
-{ERR_R_SYS_LIB                         ,"system lib"},
-{ERR_R_BN_LIB                          ,"BN lib"},
-{ERR_R_RSA_LIB                         ,"RSA lib"},
-{ERR_R_DH_LIB                          ,"DH lib"},
-{ERR_R_EVP_LIB                         ,"EVP lib"},
-{ERR_R_BUF_LIB                         ,"BUF lib"},
-{ERR_R_OBJ_LIB                         ,"OBJ lib"},
-{ERR_R_PEM_LIB                         ,"PEM lib"},
-{ERR_R_DSA_LIB                         ,"DSA lib"},
-{ERR_R_X509_LIB                                ,"X509 lib"},
-{ERR_R_ASN1_LIB                                ,"ASN1 lib"},
-{ERR_R_CONF_LIB                                ,"CONF lib"},
-{ERR_R_CRYPTO_LIB                      ,"CRYPTO lib"},
-{ERR_R_EC_LIB                          ,"EC lib"},
-{ERR_R_SSL_LIB                         ,"SSL lib"},
-{ERR_R_BIO_LIB                         ,"BIO lib"},
-{ERR_R_PKCS7_LIB                       ,"PKCS7 lib"},
-{ERR_R_X509V3_LIB                      ,"X509V3 lib"},
-{ERR_R_PKCS12_LIB                      ,"PKCS12 lib"},
-{ERR_R_RAND_LIB                                ,"RAND lib"},
-{ERR_R_DSO_LIB                         ,"DSO lib"},
-{ERR_R_ENGINE_LIB                      ,"ENGINE lib"},
-{ERR_R_OCSP_LIB                                ,"OCSP lib"},
-
-{ERR_R_NESTED_ASN1_ERROR               ,"nested asn1 error"},
-{ERR_R_BAD_ASN1_OBJECT_HEADER          ,"bad asn1 object header"},
-{ERR_R_BAD_GET_ASN1_OBJECT_CALL                ,"bad get asn1 object call"},
-{ERR_R_EXPECTING_AN_ASN1_SEQUENCE      ,"expecting an asn1 sequence"},
-{ERR_R_ASN1_LENGTH_MISMATCH            ,"asn1 length mismatch"},
-{ERR_R_MISSING_ASN1_EOS                        ,"missing asn1 eos"},
-
-{ERR_R_FATAL                            ,"fatal"},
-{ERR_R_MALLOC_FAILURE                  ,"malloc failure"},
-{ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED     ,"called a function you should not call"},
-{ERR_R_PASSED_NULL_PARAMETER           ,"passed a null parameter"},
-{ERR_R_INTERNAL_ERROR                  ,"internal error"},
-{ERR_R_DISABLED                                ,"called a function that was disabled at compile-time"},
-
-{0,NULL},
-       };
-#endif
-
-#ifndef OPENSSL_NO_ERR
-#define NUM_SYS_STR_REASONS 127
-#define LEN_SYS_STR_REASON 32
-
-static ERR_STRING_DATA SYS_str_reasons[NUM_SYS_STR_REASONS + 1];
-/* SYS_str_reasons is filled with copies of strerror() results at
- * initialization.
- * 'errno' values up to 127 should cover all usual errors,
- * others will be displayed numerically by ERR_error_string.
- * It is crucial that we have something for each reason code
- * that occurs in ERR_str_reasons, or bogus reason strings
- * will be returned for SYSerr, which always gets an errno
- * value and never one of those 'standard' reason codes. */
-
-static void build_SYS_str_reasons(void)
-       {
-       /* OPENSSL_malloc cannot be used here, use static storage instead */
-       static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON];
-       int i;
-       static int init = 1;
-
-       CRYPTO_r_lock(CRYPTO_LOCK_ERR);
-       if (!init)
-               {
-               CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
-               return;
-               }
-       
-       CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
-       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
-       if (!init)
-               {
-               CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
-               return;
-               }
-
-       for (i = 1; i <= NUM_SYS_STR_REASONS; i++)
-               {
-               ERR_STRING_DATA *str = &SYS_str_reasons[i - 1];
-
-               str->error = (unsigned long)i;
-               if (str->string == NULL)
-                       {
-                       char (*dest)[LEN_SYS_STR_REASON] = &(strerror_tab[i - 1]);
-                       char *src = strerror(i);
-                       if (src != NULL)
-                               {
-                               strncpy(*dest, src, sizeof *dest);
-                               (*dest)[sizeof *dest - 1] = '\0';
-                               str->string = *dest;
-                               }
-                       }
-               if (str->string == NULL)
-                       str->string = "unknown";
-               }
-
-       /* Now we still have SYS_str_reasons[NUM_SYS_STR_REASONS] = {0, NULL},
-        * as required by ERR_load_strings. */
-
-       init = 0;
-       
-       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
-       }
-#endif
-
-void ERR_load_ERR_strings(void)
-       {
-#ifndef OPENSSL_NO_ERR
-       if (ERR_func_error_string(ERR_str_functs[0].error) == NULL)
-               {
-               ERR_load_strings(0,ERR_str_libraries);
-               ERR_load_strings(0,ERR_str_reasons);
-               ERR_load_strings(ERR_LIB_SYS,ERR_str_functs);
-               build_SYS_str_reasons();
-               ERR_load_strings(ERR_LIB_SYS,SYS_str_reasons);
-               }
-#endif
-       }
-
index 8688266..e0554b4 100644 (file)
@@ -31,13 +31,15 @@ L COMP              crypto/comp/comp.h              crypto/comp/comp_err.c
 L ECDSA                crypto/ecdsa/ecdsa.h            crypto/ecdsa/ecs_err.c
 L ECDH         crypto/ecdh/ecdh.h              crypto/ecdh/ech_err.c
 L STORE                crypto/store/store.h            crypto/store/str_err.c
-L FIPS         fips/fips.h                     crypto/fips_err.h
+L TS           crypto/ts/ts.h                  crypto/ts/ts_err.c
+L HMAC         crypto/hmac/hmac.h              crypto/hmac/hmac_err.c
 L CMS          crypto/cms/cms.h                crypto/cms/cms_err.c
 L JPAKE                crypto/jpake/jpake.h            crypto/jpake/jpake_err.c
 
 # additional header files to be scanned for function names
 L NONE         crypto/x509/x509_vfy.h          NONE
 L NONE         crypto/ec/ec_lcl.h              NONE
+L NONE         crypto/asn1/asn_lcl.h           NONE
 L NONE         crypto/cms/cms_lcl.h            NONE
 
 
@@ -71,6 +73,11 @@ R SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY    1071
 R SSL_R_TLSV1_ALERT_INTERNAL_ERROR             1080
 R SSL_R_TLSV1_ALERT_USER_CANCELLED             1090
 R SSL_R_TLSV1_ALERT_NO_RENEGOTIATION           1100
+R SSL_R_TLSV1_UNSUPPORTED_EXTENSION            1110
+R SSL_R_TLSV1_CERTIFICATE_UNOBTAINABLE         1111
+R SSL_R_TLSV1_UNRECOGNIZED_NAME                        1112
+R SSL_R_TLSV1_BAD_CERTIFICATE_STATUS_RESPONSE  1113
+R SSL_R_TLSV1_BAD_CERTIFICATE_HASH_VALUE       1114
 
 R RSAREF_R_CONTENT_ENCODING                    0x0400
 R RSAREF_R_DATA                                        0x0401
index c204f84..82825e5 100644 (file)
@@ -18,34 +18,34 @@ TESTDATA=evptests.txt
 APPS=
 
 LIB=$(TOP)/libcrypto.a
-LIBSRC= encode.c digest.c dig_eng.c evp_enc.c evp_key.c evp_acnf.c evp_cnf.c \
+LIBSRC= encode.c digest.c evp_enc.c evp_key.c evp_acnf.c \
        e_des.c e_bf.c e_idea.c e_des3.c e_camellia.c\
        e_rc4.c e_aes.c names.c e_seed.c \
-       e_xcbc_d.c e_rc2.c e_cast.c e_rc5.c enc_min.c \
-       m_null.c m_md2.c m_md4.c m_md5.c m_sha.c m_sha1.c \
+       e_xcbc_d.c e_rc2.c e_cast.c e_rc5.c \
+       m_null.c m_md2.c m_md4.c m_md5.c m_sha.c m_sha1.c m_wp.c \
        m_dss.c m_dss1.c m_mdc2.c m_ripemd.c m_ecdsa.c\
        p_open.c p_seal.c p_sign.c p_verify.c p_lib.c p_enc.c p_dec.c \
        bio_md.c bio_b64.c bio_enc.c evp_err.c e_null.c \
        c_all.c c_allc.c c_alld.c evp_lib.c bio_ok.c \
        evp_pkey.c evp_pbe.c p5_crpt.c p5_crpt2.c \
-       e_old.c
+       e_old.c pmeth_lib.c pmeth_fn.c pmeth_gn.c m_sigver.c
 
-LIBOBJ=        encode.o digest.o dig_eng.o evp_enc.o evp_key.o evp_acnf.o evp_cnf.o \
+LIBOBJ=        encode.o digest.o evp_enc.o evp_key.o evp_acnf.o \
        e_des.o e_bf.o e_idea.o e_des3.o e_camellia.o\
        e_rc4.o e_aes.o names.o e_seed.o \
-       e_xcbc_d.o e_rc2.o e_cast.o e_rc5.o enc_min.o \
-       m_null.o m_md2.o m_md4.o m_md5.o m_sha.o m_sha1.o \
+       e_xcbc_d.o e_rc2.o e_cast.o e_rc5.o \
+       m_null.o m_md2.o m_md4.o m_md5.o m_sha.o m_sha1.o m_wp.o \
        m_dss.o m_dss1.o m_mdc2.o m_ripemd.o m_ecdsa.o\
        p_open.o p_seal.o p_sign.o p_verify.o p_lib.o p_enc.o p_dec.o \
        bio_md.o bio_b64.o bio_enc.o evp_err.o e_null.o \
        c_all.o c_allc.o c_alld.o evp_lib.o bio_ok.o \
        evp_pkey.o evp_pbe.o p5_crpt.o p5_crpt2.o \
-       e_old.o
+       e_old.o pmeth_lib.o pmeth_fn.o pmeth_gn.o m_sigver.o
 
 SRC= $(LIBSRC)
 
 EXHEADER= evp.h
-HEADER=        $(EXHEADER)
+HEADER=        evp_locl.h $(EXHEADER)
 
 ALL=    $(GENERAL) $(SRC) $(HEADER)
 
@@ -55,7 +55,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -101,201 +101,185 @@ bio_b64.o: ../../e_os.h ../../include/openssl/asn1.h
 bio_b64.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 bio_b64.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 bio_b64.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-bio_b64.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-bio_b64.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-bio_b64.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-bio_b64.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
-bio_b64.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-bio_b64.o: ../cryptlib.h bio_b64.c
+bio_b64.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+bio_b64.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+bio_b64.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+bio_b64.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+bio_b64.o: ../../include/openssl/symhacks.h ../cryptlib.h bio_b64.c
 bio_enc.o: ../../e_os.h ../../include/openssl/asn1.h
 bio_enc.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 bio_enc.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 bio_enc.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-bio_enc.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-bio_enc.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-bio_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-bio_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
-bio_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-bio_enc.o: ../cryptlib.h bio_enc.c
+bio_enc.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+bio_enc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+bio_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+bio_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+bio_enc.o: ../../include/openssl/symhacks.h ../cryptlib.h bio_enc.c
 bio_md.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 bio_md.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 bio_md.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-bio_md.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-bio_md.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-bio_md.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-bio_md.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-bio_md.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-bio_md.o: ../../include/openssl/symhacks.h ../cryptlib.h bio_md.c
+bio_md.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+bio_md.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+bio_md.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+bio_md.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
+bio_md.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+bio_md.o: ../cryptlib.h bio_md.c
 bio_ok.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 bio_ok.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 bio_ok.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-bio_ok.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-bio_ok.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-bio_ok.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-bio_ok.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-bio_ok.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
-bio_ok.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-bio_ok.o: ../cryptlib.h bio_ok.c
+bio_ok.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+bio_ok.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+bio_ok.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+bio_ok.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
+bio_ok.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+bio_ok.o: ../../include/openssl/symhacks.h ../cryptlib.h bio_ok.c
 c_all.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 c_all.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 c_all.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 c_all.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 c_all.o: ../../include/openssl/engine.h ../../include/openssl/err.h
-c_all.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-c_all.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-c_all.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-c_all.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-c_all.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-c_all.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-c_all.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-c_all.o: ../../include/openssl/x509_vfy.h ../cryptlib.h c_all.c
+c_all.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+c_all.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+c_all.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+c_all.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+c_all.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+c_all.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+c_all.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+c_all.o: ../cryptlib.h c_all.c
 c_allc.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 c_allc.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 c_allc.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 c_allc.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 c_allc.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-c_allc.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-c_allc.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-c_allc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-c_allc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h
-c_allc.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-c_allc.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-c_allc.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-c_allc.o: ../../include/openssl/x509_vfy.h ../cryptlib.h c_allc.c
+c_allc.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+c_allc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+c_allc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+c_allc.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
+c_allc.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+c_allc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+c_allc.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+c_allc.o: ../cryptlib.h c_allc.c
 c_alld.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 c_alld.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 c_alld.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 c_alld.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 c_alld.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-c_alld.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-c_alld.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-c_alld.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-c_alld.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h
-c_alld.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-c_alld.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-c_alld.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-c_alld.o: ../../include/openssl/x509_vfy.h ../cryptlib.h c_alld.c
-dig_eng.o: ../../e_os.h ../../include/openssl/asn1.h
-dig_eng.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
-dig_eng.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
-dig_eng.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
-dig_eng.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
-dig_eng.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-dig_eng.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-dig_eng.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-dig_eng.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-dig_eng.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-dig_eng.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-dig_eng.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-dig_eng.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-dig_eng.o: ../cryptlib.h dig_eng.c evp_locl.h
+c_alld.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+c_alld.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+c_alld.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+c_alld.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
+c_alld.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+c_alld.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+c_alld.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+c_alld.o: ../cryptlib.h c_alld.c
 digest.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 digest.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 digest.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 digest.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 digest.o: ../../include/openssl/engine.h ../../include/openssl/err.h
-digest.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-digest.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-digest.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-digest.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-digest.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-digest.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-digest.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-digest.o: ../../include/openssl/x509_vfy.h ../cryptlib.h digest.c evp_locl.h
+digest.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+digest.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+digest.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+digest.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+digest.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+digest.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+digest.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+digest.o: ../cryptlib.h digest.c
 e_aes.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
 e_aes.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
 e_aes.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-e_aes.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-e_aes.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-e_aes.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-e_aes.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-e_aes.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-e_aes.o: ../../include/openssl/symhacks.h e_aes.c evp_locl.h
+e_aes.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+e_aes.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+e_aes.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+e_aes.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
+e_aes.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h e_aes.c
+e_aes.o: evp_locl.h
 e_bf.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 e_bf.o: ../../include/openssl/blowfish.h ../../include/openssl/buffer.h
 e_bf.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 e_bf.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-e_bf.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-e_bf.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-e_bf.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-e_bf.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
-e_bf.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-e_bf.o: ../cryptlib.h e_bf.c evp_locl.h
-e_camellia.o: ../../include/openssl/opensslconf.h e_camellia.c
+e_bf.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+e_bf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+e_bf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+e_bf.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+e_bf.o: ../../include/openssl/symhacks.h ../cryptlib.h e_bf.c evp_locl.h
+e_camellia.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
+e_camellia.o: ../../include/openssl/camellia.h ../../include/openssl/crypto.h
+e_camellia.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
+e_camellia.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+e_camellia.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+e_camellia.o: ../../include/openssl/opensslconf.h
+e_camellia.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+e_camellia.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+e_camellia.o: ../../include/openssl/symhacks.h e_camellia.c evp_locl.h
 e_cast.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 e_cast.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
 e_cast.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 e_cast.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-e_cast.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-e_cast.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-e_cast.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-e_cast.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
-e_cast.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-e_cast.o: ../cryptlib.h e_cast.c evp_locl.h
+e_cast.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+e_cast.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+e_cast.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+e_cast.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+e_cast.o: ../../include/openssl/symhacks.h ../cryptlib.h e_cast.c evp_locl.h
 e_des.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 e_des.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 e_des.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
 e_des.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-e_des.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-e_des.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-e_des.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-e_des.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-e_des.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
-e_des.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-e_des.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
-e_des.o: ../cryptlib.h e_des.c evp_locl.h
+e_des.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+e_des.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+e_des.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+e_des.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
+e_des.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+e_des.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
+e_des.o: ../../include/openssl/ui_compat.h ../cryptlib.h e_des.c evp_locl.h
 e_des3.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 e_des3.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 e_des3.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
 e_des3.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-e_des3.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-e_des3.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-e_des3.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-e_des3.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-e_des3.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
-e_des3.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-e_des3.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
-e_des3.o: ../cryptlib.h e_des3.c evp_locl.h
+e_des3.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+e_des3.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+e_des3.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+e_des3.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
+e_des3.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+e_des3.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
+e_des3.o: ../../include/openssl/ui_compat.h ../cryptlib.h e_des3.c evp_locl.h
 e_idea.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 e_idea.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 e_idea.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-e_idea.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-e_idea.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
-e_idea.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-e_idea.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-e_idea.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
-e_idea.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-e_idea.o: ../cryptlib.h e_idea.c evp_locl.h
+e_idea.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
+e_idea.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+e_idea.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+e_idea.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+e_idea.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+e_idea.o: ../../include/openssl/symhacks.h ../cryptlib.h e_idea.c evp_locl.h
 e_null.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 e_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 e_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-e_null.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-e_null.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-e_null.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-e_null.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-e_null.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-e_null.o: ../../include/openssl/symhacks.h ../cryptlib.h e_null.c
+e_null.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+e_null.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+e_null.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+e_null.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
+e_null.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+e_null.o: ../cryptlib.h e_null.c
 e_old.o: e_old.c
 e_rc2.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 e_rc2.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 e_rc2.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-e_rc2.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-e_rc2.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-e_rc2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-e_rc2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-e_rc2.o: ../../include/openssl/rc2.h ../../include/openssl/safestack.h
-e_rc2.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-e_rc2.o: ../cryptlib.h e_rc2.c evp_locl.h
+e_rc2.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+e_rc2.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+e_rc2.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+e_rc2.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rc2.h
+e_rc2.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+e_rc2.o: ../../include/openssl/symhacks.h ../cryptlib.h e_rc2.c evp_locl.h
 e_rc4.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 e_rc4.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 e_rc4.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-e_rc4.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-e_rc4.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-e_rc4.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-e_rc4.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-e_rc4.o: ../../include/openssl/rc4.h ../../include/openssl/safestack.h
-e_rc4.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-e_rc4.o: ../cryptlib.h e_rc4.c evp_locl.h
+e_rc4.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+e_rc4.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+e_rc4.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+e_rc4.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rc4.h
+e_rc4.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+e_rc4.o: ../../include/openssl/symhacks.h ../cryptlib.h e_rc4.c
 e_rc5.o: ../../e_os.h ../../include/openssl/bio.h
 e_rc5.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 e_rc5.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
@@ -306,256 +290,221 @@ e_rc5.o: ../../include/openssl/symhacks.h ../cryptlib.h e_rc5.c
 e_seed.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
 e_seed.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 e_seed.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-e_seed.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-e_seed.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-e_seed.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-e_seed.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
+e_seed.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+e_seed.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+e_seed.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+e_seed.o: ../../include/openssl/safestack.h ../../include/openssl/seed.h
 e_seed.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-e_seed.o: e_seed.c
+e_seed.o: e_seed.c evp_locl.h
 e_xcbc_d.o: ../../e_os.h ../../include/openssl/asn1.h
 e_xcbc_d.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 e_xcbc_d.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
 e_xcbc_d.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
 e_xcbc_d.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-e_xcbc_d.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-e_xcbc_d.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-e_xcbc_d.o: ../../include/openssl/opensslconf.h
+e_xcbc_d.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+e_xcbc_d.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 e_xcbc_d.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 e_xcbc_d.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
 e_xcbc_d.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
 e_xcbc_d.o: ../../include/openssl/ui_compat.h ../cryptlib.h e_xcbc_d.c
-enc_min.o: ../../e_os.h ../../include/openssl/asn1.h
-enc_min.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
-enc_min.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
-enc_min.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
-enc_min.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
-enc_min.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-enc_min.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-enc_min.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-enc_min.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-enc_min.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-enc_min.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
-enc_min.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-enc_min.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-enc_min.o: ../../include/openssl/x509_vfy.h ../cryptlib.h enc_min.c evp_locl.h
+e_xcbc_d.o: evp_locl.h
 encode.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 encode.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 encode.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-encode.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-encode.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-encode.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-encode.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-encode.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-encode.o: ../../include/openssl/symhacks.h ../cryptlib.h encode.c
+encode.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+encode.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+encode.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+encode.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
+encode.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+encode.o: ../cryptlib.h encode.c
 evp_acnf.o: ../../e_os.h ../../include/openssl/asn1.h
 evp_acnf.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 evp_acnf.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 evp_acnf.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-evp_acnf.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-evp_acnf.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-evp_acnf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+evp_acnf.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+evp_acnf.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+evp_acnf.o: ../../include/openssl/opensslconf.h
 evp_acnf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 evp_acnf.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
 evp_acnf.o: ../../include/openssl/symhacks.h ../cryptlib.h evp_acnf.c
-evp_cnf.o: ../../e_os.h ../../include/openssl/asn1.h
-evp_cnf.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
-evp_cnf.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
-evp_cnf.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
-evp_cnf.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
-evp_cnf.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-evp_cnf.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-evp_cnf.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-evp_cnf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-evp_cnf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-evp_cnf.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-evp_cnf.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-evp_cnf.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-evp_cnf.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
-evp_cnf.o: ../cryptlib.h evp_cnf.c
 evp_enc.o: ../../e_os.h ../../include/openssl/asn1.h
 evp_enc.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 evp_enc.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 evp_enc.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 evp_enc.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
 evp_enc.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-evp_enc.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-evp_enc.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-evp_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-evp_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-evp_enc.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
-evp_enc.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-evp_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-evp_enc.o: ../../include/openssl/x509_vfy.h ../cryptlib.h evp_enc.c evp_locl.h
+evp_enc.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+evp_enc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+evp_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+evp_enc.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
+evp_enc.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+evp_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+evp_enc.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+evp_enc.o: ../cryptlib.h evp_enc.c evp_locl.h
 evp_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
 evp_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 evp_err.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-evp_err.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-evp_err.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-evp_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-evp_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
-evp_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-evp_err.o: evp_err.c
+evp_err.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+evp_err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+evp_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+evp_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+evp_err.o: ../../include/openssl/symhacks.h evp_err.c
 evp_key.o: ../../e_os.h ../../include/openssl/asn1.h
 evp_key.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 evp_key.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 evp_key.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 evp_key.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-evp_key.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-evp_key.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-evp_key.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-evp_key.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-evp_key.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-evp_key.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-evp_key.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
-evp_key.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-evp_key.o: ../cryptlib.h evp_key.c
+evp_key.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+evp_key.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+evp_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+evp_key.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+evp_key.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+evp_key.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+evp_key.o: ../../include/openssl/ui.h ../../include/openssl/x509.h
+evp_key.o: ../../include/openssl/x509_vfy.h ../cryptlib.h evp_key.c
 evp_lib.o: ../../e_os.h ../../include/openssl/asn1.h
 evp_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 evp_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 evp_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-evp_lib.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-evp_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-evp_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-evp_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
-evp_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-evp_lib.o: ../cryptlib.h evp_lib.c
+evp_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+evp_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+evp_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+evp_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+evp_lib.o: ../../include/openssl/symhacks.h ../cryptlib.h evp_lib.c
 evp_pbe.o: ../../e_os.h ../../include/openssl/asn1.h
 evp_pbe.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 evp_pbe.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 evp_pbe.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 evp_pbe.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-evp_pbe.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-evp_pbe.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-evp_pbe.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-evp_pbe.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+evp_pbe.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+evp_pbe.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+evp_pbe.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+evp_pbe.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h
 evp_pbe.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 evp_pbe.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
 evp_pbe.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
 evp_pbe.o: ../../include/openssl/x509_vfy.h ../cryptlib.h evp_pbe.c
 evp_pkey.o: ../../e_os.h ../../include/openssl/asn1.h
-evp_pkey.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
-evp_pkey.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
-evp_pkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
+evp_pkey.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
+evp_pkey.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 evp_pkey.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 evp_pkey.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-evp_pkey.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-evp_pkey.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-evp_pkey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+evp_pkey.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+evp_pkey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+evp_pkey.o: ../../include/openssl/opensslconf.h
 evp_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 evp_pkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
-evp_pkey.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
-evp_pkey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-evp_pkey.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-evp_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h evp_pkey.c
+evp_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+evp_pkey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+evp_pkey.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+evp_pkey.o: ../asn1/asn1_locl.h ../cryptlib.h evp_pkey.c
 m_dss.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 m_dss.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 m_dss.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
 m_dss.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 m_dss.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-m_dss.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-m_dss.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-m_dss.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-m_dss.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-m_dss.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-m_dss.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-m_dss.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-m_dss.o: ../../include/openssl/x509_vfy.h ../cryptlib.h m_dss.c
+m_dss.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+m_dss.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+m_dss.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+m_dss.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+m_dss.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+m_dss.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+m_dss.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+m_dss.o: ../cryptlib.h m_dss.c
 m_dss1.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 m_dss1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 m_dss1.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
 m_dss1.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 m_dss1.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-m_dss1.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-m_dss1.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-m_dss1.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-m_dss1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-m_dss1.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-m_dss1.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-m_dss1.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-m_dss1.o: ../../include/openssl/x509_vfy.h ../cryptlib.h m_dss1.c
+m_dss1.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+m_dss1.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+m_dss1.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+m_dss1.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+m_dss1.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+m_dss1.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+m_dss1.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+m_dss1.o: ../cryptlib.h m_dss1.c
 m_ecdsa.o: ../../e_os.h ../../include/openssl/asn1.h
 m_ecdsa.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 m_ecdsa.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 m_ecdsa.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 m_ecdsa.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-m_ecdsa.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-m_ecdsa.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-m_ecdsa.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-m_ecdsa.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-m_ecdsa.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-m_ecdsa.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-m_ecdsa.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-m_ecdsa.o: ../../include/openssl/x509_vfy.h ../cryptlib.h m_ecdsa.c
-m_md2.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
+m_ecdsa.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+m_ecdsa.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+m_ecdsa.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+m_ecdsa.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+m_ecdsa.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+m_ecdsa.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+m_ecdsa.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+m_ecdsa.o: ../cryptlib.h m_ecdsa.c
+m_md2.o: ../../e_os.h ../../include/openssl/bio.h
 m_md2.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
-m_md2.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-m_md2.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
-m_md2.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-m_md2.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-m_md2.o: ../../include/openssl/md2.h ../../include/openssl/obj_mac.h
-m_md2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+m_md2.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
+m_md2.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
 m_md2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-m_md2.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
-m_md2.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-m_md2.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-m_md2.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-m_md2.o: ../cryptlib.h evp_locl.h m_md2.c
+m_md2.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+m_md2.o: ../../include/openssl/symhacks.h ../cryptlib.h m_md2.c
 m_md4.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 m_md4.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 m_md4.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 m_md4.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 m_md4.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-m_md4.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-m_md4.o: ../../include/openssl/md4.h ../../include/openssl/obj_mac.h
-m_md4.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-m_md4.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-m_md4.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
-m_md4.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-m_md4.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-m_md4.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-m_md4.o: ../cryptlib.h evp_locl.h m_md4.c
+m_md4.o: ../../include/openssl/lhash.h ../../include/openssl/md4.h
+m_md4.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+m_md4.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+m_md4.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+m_md4.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+m_md4.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+m_md4.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+m_md4.o: ../../include/openssl/x509_vfy.h ../cryptlib.h m_md4.c
 m_md5.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 m_md5.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 m_md5.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 m_md5.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 m_md5.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-m_md5.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-m_md5.o: ../../include/openssl/md5.h ../../include/openssl/obj_mac.h
-m_md5.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-m_md5.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-m_md5.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
-m_md5.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-m_md5.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-m_md5.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-m_md5.o: ../cryptlib.h evp_locl.h m_md5.c
-m_mdc2.o: ../../e_os.h ../../include/openssl/bio.h
+m_md5.o: ../../include/openssl/lhash.h ../../include/openssl/md5.h
+m_md5.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+m_md5.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+m_md5.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+m_md5.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+m_md5.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+m_md5.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+m_md5.o: ../../include/openssl/x509_vfy.h ../cryptlib.h m_md5.c
+m_mdc2.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 m_mdc2.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
-m_mdc2.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-m_mdc2.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
-m_mdc2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-m_mdc2.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-m_mdc2.o: ../../include/openssl/symhacks.h ../cryptlib.h evp_locl.h m_mdc2.c
+m_mdc2.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
+m_mdc2.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+m_mdc2.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
+m_mdc2.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+m_mdc2.o: ../../include/openssl/lhash.h ../../include/openssl/mdc2.h
+m_mdc2.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+m_mdc2.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+m_mdc2.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+m_mdc2.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+m_mdc2.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+m_mdc2.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
+m_mdc2.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
+m_mdc2.o: ../../include/openssl/x509_vfy.h ../cryptlib.h m_mdc2.c
 m_null.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 m_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 m_null.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 m_null.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 m_null.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-m_null.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-m_null.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-m_null.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-m_null.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-m_null.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-m_null.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-m_null.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-m_null.o: ../cryptlib.h m_null.c
+m_null.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+m_null.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+m_null.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+m_null.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+m_null.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+m_null.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+m_null.o: ../../include/openssl/x509_vfy.h ../cryptlib.h m_null.c
 m_ripemd.o: ../../e_os.h ../../include/openssl/asn1.h
 m_ripemd.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 m_ripemd.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 m_ripemd.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 m_ripemd.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-m_ripemd.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-m_ripemd.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-m_ripemd.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+m_ripemd.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+m_ripemd.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+m_ripemd.o: ../../include/openssl/opensslconf.h
 m_ripemd.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 m_ripemd.o: ../../include/openssl/pkcs7.h ../../include/openssl/ripemd.h
 m_ripemd.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
@@ -567,62 +516,87 @@ m_sha.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 m_sha.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 m_sha.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 m_sha.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-m_sha.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-m_sha.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-m_sha.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-m_sha.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-m_sha.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
-m_sha.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-m_sha.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-m_sha.o: ../../include/openssl/x509_vfy.h ../cryptlib.h evp_locl.h m_sha.c
+m_sha.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+m_sha.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+m_sha.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+m_sha.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
+m_sha.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+m_sha.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+m_sha.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+m_sha.o: ../cryptlib.h m_sha.c
 m_sha1.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 m_sha1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 m_sha1.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 m_sha1.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 m_sha1.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-m_sha1.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-m_sha1.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-m_sha1.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-m_sha1.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-m_sha1.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
-m_sha1.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-m_sha1.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-m_sha1.o: ../../include/openssl/x509_vfy.h ../cryptlib.h m_sha1.c
+m_sha1.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+m_sha1.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+m_sha1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+m_sha1.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
+m_sha1.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+m_sha1.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+m_sha1.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+m_sha1.o: ../cryptlib.h m_sha1.c
+m_sigver.o: ../../e_os.h ../../include/openssl/asn1.h
+m_sigver.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
+m_sigver.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+m_sigver.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+m_sigver.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
+m_sigver.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+m_sigver.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+m_sigver.o: ../../include/openssl/opensslconf.h
+m_sigver.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+m_sigver.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+m_sigver.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+m_sigver.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+m_sigver.o: ../../include/openssl/x509_vfy.h ../cryptlib.h evp_locl.h
+m_sigver.o: m_sigver.c
+m_wp.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
+m_wp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
+m_wp.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+m_wp.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
+m_wp.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+m_wp.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+m_wp.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+m_wp.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+m_wp.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+m_wp.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+m_wp.o: ../../include/openssl/symhacks.h ../../include/openssl/whrlpool.h
+m_wp.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+m_wp.o: ../cryptlib.h m_wp.c
 names.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 names.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 names.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 names.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 names.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-names.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-names.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-names.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-names.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-names.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-names.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-names.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-names.o: ../cryptlib.h names.c
+names.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+names.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+names.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+names.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+names.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+names.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+names.o: ../../include/openssl/x509_vfy.h ../cryptlib.h names.c
 p5_crpt.o: ../../e_os.h ../../include/openssl/asn1.h
 p5_crpt.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 p5_crpt.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 p5_crpt.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 p5_crpt.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-p5_crpt.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-p5_crpt.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-p5_crpt.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-p5_crpt.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-p5_crpt.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-p5_crpt.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-p5_crpt.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-p5_crpt.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p5_crpt.c
+p5_crpt.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+p5_crpt.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+p5_crpt.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+p5_crpt.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+p5_crpt.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+p5_crpt.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+p5_crpt.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+p5_crpt.o: ../cryptlib.h p5_crpt.c
 p5_crpt2.o: ../../e_os.h ../../include/openssl/asn1.h
 p5_crpt2.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 p5_crpt2.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 p5_crpt2.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 p5_crpt2.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-p5_crpt2.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-p5_crpt2.o: ../../include/openssl/hmac.h ../../include/openssl/lhash.h
-p5_crpt2.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-p5_crpt2.o: ../../include/openssl/opensslconf.h
+p5_crpt2.o: ../../include/openssl/evp.h ../../include/openssl/hmac.h
+p5_crpt2.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+p5_crpt2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 p5_crpt2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 p5_crpt2.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 p5_crpt2.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -633,37 +607,35 @@ p_dec.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 p_dec.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 p_dec.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 p_dec.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-p_dec.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-p_dec.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-p_dec.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-p_dec.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-p_dec.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
-p_dec.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-p_dec.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-p_dec.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-p_dec.o: ../cryptlib.h p_dec.c
+p_dec.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+p_dec.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+p_dec.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+p_dec.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
+p_dec.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+p_dec.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+p_dec.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+p_dec.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p_dec.c
 p_enc.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 p_enc.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 p_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 p_enc.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 p_enc.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-p_enc.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-p_enc.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-p_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-p_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-p_enc.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
-p_enc.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-p_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-p_enc.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-p_enc.o: ../cryptlib.h p_enc.c
+p_enc.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+p_enc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+p_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+p_enc.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
+p_enc.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+p_enc.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+p_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+p_enc.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p_enc.c
 p_lib.o: ../../e_os.h ../../include/openssl/asn1.h
 p_lib.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
 p_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
 p_lib.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
 p_lib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
 p_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
-p_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-p_lib.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
+p_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
+p_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
 p_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
 p_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 p_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
@@ -671,57 +643,91 @@ p_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
 p_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
 p_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
 p_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-p_lib.o: ../cryptlib.h p_lib.c
+p_lib.o: ../asn1/asn1_locl.h ../cryptlib.h p_lib.c
 p_open.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 p_open.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 p_open.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 p_open.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 p_open.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-p_open.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-p_open.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-p_open.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-p_open.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-p_open.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
-p_open.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-p_open.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-p_open.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p_open.c
+p_open.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+p_open.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+p_open.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+p_open.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
+p_open.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+p_open.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+p_open.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+p_open.o: ../cryptlib.h p_open.c
 p_seal.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 p_seal.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 p_seal.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 p_seal.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 p_seal.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-p_seal.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-p_seal.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-p_seal.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-p_seal.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-p_seal.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
-p_seal.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-p_seal.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-p_seal.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-p_seal.o: ../cryptlib.h p_seal.c
+p_seal.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+p_seal.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+p_seal.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+p_seal.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
+p_seal.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+p_seal.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+p_seal.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+p_seal.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p_seal.c
 p_sign.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 p_sign.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 p_sign.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 p_sign.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 p_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-p_sign.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-p_sign.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-p_sign.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-p_sign.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-p_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-p_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-p_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-p_sign.o: ../cryptlib.h p_sign.c
+p_sign.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+p_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+p_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+p_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+p_sign.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+p_sign.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+p_sign.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p_sign.c
 p_verify.o: ../../e_os.h ../../include/openssl/asn1.h
 p_verify.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 p_verify.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 p_verify.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 p_verify.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-p_verify.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-p_verify.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-p_verify.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+p_verify.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+p_verify.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+p_verify.o: ../../include/openssl/opensslconf.h
 p_verify.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 p_verify.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 p_verify.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
 p_verify.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
 p_verify.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p_verify.c
+pmeth_fn.o: ../../e_os.h ../../include/openssl/asn1.h
+pmeth_fn.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
+pmeth_fn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+pmeth_fn.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+pmeth_fn.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+pmeth_fn.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+pmeth_fn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+pmeth_fn.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+pmeth_fn.o: ../../include/openssl/symhacks.h ../cryptlib.h evp_locl.h
+pmeth_fn.o: pmeth_fn.c
+pmeth_gn.o: ../../e_os.h ../../include/openssl/asn1.h
+pmeth_gn.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
+pmeth_gn.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
+pmeth_gn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
+pmeth_gn.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+pmeth_gn.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+pmeth_gn.o: ../../include/openssl/opensslconf.h
+pmeth_gn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+pmeth_gn.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+pmeth_gn.o: ../../include/openssl/symhacks.h ../cryptlib.h evp_locl.h
+pmeth_gn.o: pmeth_gn.c
+pmeth_lib.o: ../../e_os.h ../../include/openssl/asn1.h
+pmeth_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
+pmeth_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+pmeth_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+pmeth_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
+pmeth_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+pmeth_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+pmeth_lib.o: ../../include/openssl/objects.h
+pmeth_lib.o: ../../include/openssl/opensslconf.h
+pmeth_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+pmeth_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+pmeth_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+pmeth_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+pmeth_lib.o: ../../include/openssl/x509_vfy.h ../asn1/asn1_locl.h ../cryptlib.h
+pmeth_lib.o: evp_locl.h pmeth_lib.c
index f6ac94c..b6efb5f 100644 (file)
@@ -361,8 +361,10 @@ again:
        case BIO_CTRL_DUP:
                dbio=(BIO *)ptr;
                dctx=(BIO_ENC_CTX *)dbio->ptr;
-               memcpy(&(dctx->cipher),&(ctx->cipher),sizeof(ctx->cipher));
-               dbio->init=1;
+               EVP_CIPHER_CTX_init(&dctx->cipher);
+               ret = EVP_CIPHER_CTX_copy(&dctx->cipher,&ctx->cipher);
+               if (ret)
+                       dbio->init=1;
                break;
        default:
                ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
index ed5c113..9841e32 100644 (file)
@@ -130,8 +130,8 @@ static int md_read(BIO *b, char *out, int outl)
                {
                if (ret > 0)
                        {
-                       EVP_DigestUpdate(ctx,(unsigned char *)out,
-                               (unsigned int)ret);
+                       if (EVP_DigestUpdate(ctx,(unsigned char *)out,
+                               (unsigned int)ret)<=0) return (-1);
                        }
                }
        BIO_clear_retry_flags(b);
@@ -157,8 +157,11 @@ static int md_write(BIO *b, const char *in, int inl)
                                (unsigned int)ret);
                        }
                }
-       BIO_clear_retry_flags(b);
-       BIO_copy_next_retry(b);
+       if(b->next_bio != NULL)
+               {
+               BIO_clear_retry_flags(b);
+               BIO_copy_next_retry(b);
+               }
        return(ret);
        }
 
@@ -194,6 +197,7 @@ static long md_ctrl(BIO *b, int cmd, long num, void *ptr)
        case BIO_C_GET_MD_CTX:
                pctx=ptr;
                *pctx=ctx;
+               b->init = 1;
                break;
        case BIO_C_SET_MD_CTX:
                if (b->init)
@@ -249,7 +253,9 @@ static int md_gets(BIO *bp, char *buf, int size)
        ctx=bp->ptr;
        if (size < ctx->digest->md_size)
                return(0);
-       EVP_DigestFinal_ex(ctx,(unsigned char *)buf,&ret);
+       if (EVP_DigestFinal_ex(ctx,(unsigned char *)buf,&ret)<=0) 
+               return -1;
+               
        return((int)ret);
        }
 
index a5da52e..766c4ce 100644 (file)
@@ -83,7 +83,7 @@ void OPENSSL_add_all_algorithms_noconf(void)
        OpenSSL_add_all_ciphers();
        OpenSSL_add_all_digests();
 #ifndef OPENSSL_NO_ENGINE
-# if defined(__OpenBSD__) || defined(__FreeBSD__)
+# if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV)
        ENGINE_setup_bsd_cryptodev();
 # endif
 #endif
index e45cee8..c5f9268 100644 (file)
@@ -221,7 +221,4 @@ void OpenSSL_add_all_ciphers(void)
        EVP_add_cipher_alias(SN_camellia_256_cbc,"CAMELLIA256");
        EVP_add_cipher_alias(SN_camellia_256_cbc,"camellia256");
 #endif
-
-       PKCS12_PBE_add();
-       PKCS5_PBE_add();
        }
index e0841d1..311e1fe 100644 (file)
@@ -78,7 +78,7 @@ void OpenSSL_add_all_digests(void)
        EVP_add_digest(EVP_dss());
 #endif
 #endif
-#ifndef OPENSSL_NO_SHA
+#if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA1)
        EVP_add_digest(EVP_sha1());
        EVP_add_digest_alias(SN_sha1,"ssl3-sha1");
        EVP_add_digest_alias(SN_sha1WithRSAEncryption,SN_sha1WithRSA);
@@ -108,4 +108,7 @@ void OpenSSL_add_all_digests(void)
        EVP_add_digest(EVP_sha384());
        EVP_add_digest(EVP_sha512());
 #endif
+#ifndef OPENSSL_NO_WHIRLPOOL
+       EVP_add_digest(EVP_whirlpool());
+#endif
        }
diff --git a/deps/openssl/openssl/crypto/evp/dig_eng.c b/deps/openssl/openssl/crypto/evp/dig_eng.c
deleted file mode 100644 (file)
index 64cdf93..0000000
+++ /dev/null
@@ -1,180 +0,0 @@
-/* crypto/evp/digest.c */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-/* ====================================================================
- * Copyright (c) 1998-2001 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    openssl-core@openssl.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
- * ====================================================================
- *
- * This product includes cryptographic software written by Eric Young
- * (eay@cryptsoft.com).  This product includes software written by Tim
- * Hudson (tjh@cryptsoft.com).
- *
- */
-
-#include <stdio.h>
-#include "cryptlib.h"
-#include <openssl/objects.h>
-#include <openssl/evp.h>
-#ifndef OPENSSL_NO_ENGINE
-#include <openssl/engine.h>
-#endif
-#include "evp_locl.h"
-
-#ifndef OPENSSL_NO_ENGINE
-
-#ifdef OPENSSL_FIPS
-
-static int do_evp_md_engine_full(EVP_MD_CTX *ctx, const EVP_MD **ptype, ENGINE *impl)
-       {
-       if (*ptype)
-               {
-               /* Ensure an ENGINE left lying around from last time is cleared
-                * (the previous check attempted to avoid this if the same
-                * ENGINE and EVP_MD could be used). */
-               if(ctx->engine)
-                       ENGINE_finish(ctx->engine);
-               if(impl)
-                       {
-                       if (!ENGINE_init(impl))
-                               {
-                               EVPerr(EVP_F_DO_EVP_MD_ENGINE_FULL,EVP_R_INITIALIZATION_ERROR);
-                               return 0;
-                               }
-                       }
-               else
-                       /* Ask if an ENGINE is reserved for this job */
-                       impl = ENGINE_get_digest_engine((*ptype)->type);
-               if(impl)
-                       {
-                       /* There's an ENGINE for this job ... (apparently) */
-                       const EVP_MD *d = ENGINE_get_digest(impl, (*ptype)->type);
-                       if(!d)
-                               {
-                               /* Same comment from evp_enc.c */
-                               EVPerr(EVP_F_DO_EVP_MD_ENGINE_FULL,EVP_R_INITIALIZATION_ERROR);
-                               return 0;
-                               }
-                       /* We'll use the ENGINE's private digest definition */
-                       *ptype = d;
-                       /* Store the ENGINE functional reference so we know
-                        * 'type' came from an ENGINE and we need to release
-                        * it when done. */
-                       ctx->engine = impl;
-                       }
-               else
-                       ctx->engine = NULL;
-               }
-       else
-       if(!ctx->digest)
-               {
-               EVPerr(EVP_F_DO_EVP_MD_ENGINE_FULL,EVP_R_NO_DIGEST_SET);
-               return 0;
-               }
-       return 1;
-       }
-
-void int_EVP_MD_init_engine_callbacks(void)
-       {
-       int_EVP_MD_set_engine_callbacks(
-               ENGINE_init, ENGINE_finish, do_evp_md_engine_full);
-       }
-#endif
-#endif
index 10a3607..982ba2b 100644 (file)
 #ifndef OPENSSL_NO_ENGINE
 #include <openssl/engine.h>
 #endif
-#include "evp_locl.h"
 
 void EVP_MD_CTX_init(EVP_MD_CTX *ctx)
        {
@@ -139,77 +138,18 @@ int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)
        return EVP_DigestInit_ex(ctx, type, NULL);
        }
 
-#ifdef OPENSSL_FIPS
-
-/* The purpose of these is to trap programs that attempt to use non FIPS
- * algorithms in FIPS mode and ignore the errors.
- */
-
-static int bad_init(EVP_MD_CTX *ctx)
-       { FIPS_ERROR_IGNORED("Digest init"); return 0;}
-
-static int bad_update(EVP_MD_CTX *ctx,const void *data,size_t count)
-       { FIPS_ERROR_IGNORED("Digest update"); return 0;}
-
-static int bad_final(EVP_MD_CTX *ctx,unsigned char *md)
-       { FIPS_ERROR_IGNORED("Digest Final"); return 0;}
-
-static const EVP_MD bad_md =
+int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
        {
-       0,
-       0,
-       0,
-       0,
-       bad_init,
-       bad_update,
-       bad_final,
-       NULL,
-       NULL,
-       NULL,
-       0,
-       {0,0,0,0},
-       };
-
-#endif
-
+       EVP_MD_CTX_clear_flags(ctx,EVP_MD_CTX_FLAG_CLEANED);
 #ifndef OPENSSL_NO_ENGINE
-
-#ifdef OPENSSL_FIPS
-
-static int do_engine_null(ENGINE *impl) { return 0;}
-static int do_evp_md_engine_null(EVP_MD_CTX *ctx,
-                               const EVP_MD **ptype, ENGINE *impl)
-       { return 1; }
-
-static int (*do_engine_init)(ENGINE *impl)
-               = do_engine_null;
-
-static int (*do_engine_finish)(ENGINE *impl)
-               = do_engine_null;
-
-static int (*do_evp_md_engine)
-       (EVP_MD_CTX *ctx, const EVP_MD **ptype, ENGINE *impl)
-               = do_evp_md_engine_null;
-
-void int_EVP_MD_set_engine_callbacks(
-       int (*eng_md_init)(ENGINE *impl),
-       int (*eng_md_fin)(ENGINE *impl),
-       int (*eng_md_evp)
-               (EVP_MD_CTX *ctx, const EVP_MD **ptype, ENGINE *impl))
-       {
-       do_engine_init = eng_md_init;
-       do_engine_finish = eng_md_fin;
-       do_evp_md_engine = eng_md_evp;
-       }
-
-#else
-
-#define do_engine_init ENGINE_init
-#define do_engine_finish ENGINE_finish
-
-static int do_evp_md_engine(EVP_MD_CTX *ctx, const EVP_MD **ptype, ENGINE *impl)
-       {
-       if (*ptype)
+       /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts
+        * so this context may already have an ENGINE! Try to avoid releasing
+        * the previous handle, re-querying for an ENGINE, and having a
+        * reinitialisation, when it may all be unecessary. */
+       if (ctx->engine && ctx->digest && (!type ||
+                       (type && (type->type == ctx->digest->type))))
+               goto skip_to_init;
+       if (type)
                {
                /* Ensure an ENGINE left lying around from last time is cleared
                 * (the previous check attempted to avoid this if the same
@@ -220,26 +160,26 @@ static int do_evp_md_engine(EVP_MD_CTX *ctx, const EVP_MD **ptype, ENGINE *impl)
                        {
                        if (!ENGINE_init(impl))
                                {
-                               EVPerr(EVP_F_DO_EVP_MD_ENGINE,EVP_R_INITIALIZATION_ERROR);
+                               EVPerr(EVP_F_EVP_DIGESTINIT_EX,EVP_R_INITIALIZATION_ERROR);
                                return 0;
                                }
                        }
                else
                        /* Ask if an ENGINE is reserved for this job */
-                       impl = ENGINE_get_digest_engine((*ptype)->type);
+                       impl = ENGINE_get_digest_engine(type->type);
                if(impl)
                        {
                        /* There's an ENGINE for this job ... (apparently) */
-                       const EVP_MD *d = ENGINE_get_digest(impl, (*ptype)->type);
+                       const EVP_MD *d = ENGINE_get_digest(impl, type->type);
                        if(!d)
                                {
                                /* Same comment from evp_enc.c */
-                               EVPerr(EVP_F_DO_EVP_MD_ENGINE,EVP_R_INITIALIZATION_ERROR);
+                               EVPerr(EVP_F_EVP_DIGESTINIT_EX,EVP_R_INITIALIZATION_ERROR);
                                ENGINE_finish(impl);
                                return 0;
                                }
                        /* We'll use the ENGINE's private digest definition */
-                       *ptype = d;
+                       type = d;
                        /* Store the ENGINE functional reference so we know
                         * 'type' came from an ENGINE and we need to release
                         * it when done. */
@@ -251,78 +191,46 @@ static int do_evp_md_engine(EVP_MD_CTX *ctx, const EVP_MD **ptype, ENGINE *impl)
        else
        if(!ctx->digest)
                {
-               EVPerr(EVP_F_DO_EVP_MD_ENGINE,EVP_R_NO_DIGEST_SET);
+               EVPerr(EVP_F_EVP_DIGESTINIT_EX,EVP_R_NO_DIGEST_SET);
                return 0;
                }
-       return 1;
-       }
-
-#endif
-
-#endif
-
-int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
-       {
-       M_EVP_MD_CTX_clear_flags(ctx,EVP_MD_CTX_FLAG_CLEANED);
-#ifdef OPENSSL_FIPS
-       if(FIPS_selftest_failed())
-               {
-               FIPSerr(FIPS_F_EVP_DIGESTINIT_EX,FIPS_R_FIPS_SELFTEST_FAILED);
-               ctx->digest = &bad_md;
-               return 0;
-               }
-#endif
-#ifndef OPENSSL_NO_ENGINE
-       /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts
-        * so this context may already have an ENGINE! Try to avoid releasing
-        * the previous handle, re-querying for an ENGINE, and having a
-        * reinitialisation, when it may all be unecessary. */
-       if (ctx->engine && ctx->digest && (!type ||
-                       (type && (type->type == ctx->digest->type))))
-               goto skip_to_init;
-       if (!do_evp_md_engine(ctx, &type, impl))
-               return 0;
 #endif
        if (ctx->digest != type)
                {
-#ifdef OPENSSL_FIPS
-               if (FIPS_mode())
-                       {
-                       if (!(type->flags & EVP_MD_FLAG_FIPS) 
-                        && !(ctx->flags & EVP_MD_CTX_FLAG_NON_FIPS_ALLOW))
-                               {
-                               EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_DISABLED_FOR_FIPS);
-                               ctx->digest = &bad_md;
-                               return 0;
-                               }
-                       }
-#endif
                if (ctx->digest && ctx->digest->ctx_size)
                        OPENSSL_free(ctx->md_data);
                ctx->digest=type;
-               if (type->ctx_size)
+               if (!(ctx->flags & EVP_MD_CTX_FLAG_NO_INIT) && type->ctx_size)
                        {
+                       ctx->update = type->update;
                        ctx->md_data=OPENSSL_malloc(type->ctx_size);
-                       if (!ctx->md_data)
+                       if (ctx->md_data == NULL)
                                {
-                               EVPerr(EVP_F_EVP_DIGESTINIT_EX, ERR_R_MALLOC_FAILURE);
+                               EVPerr(EVP_F_EVP_DIGESTINIT_EX,
+                                                       ERR_R_MALLOC_FAILURE);
                                return 0;
                                }
                        }
                }
 #ifndef OPENSSL_NO_ENGINE
-       skip_to_init:
+skip_to_init:
 #endif
+       if (ctx->pctx)
+               {
+               int r;
+               r = EVP_PKEY_CTX_ctrl(ctx->pctx, -1, EVP_PKEY_OP_TYPE_SIG,
+                                       EVP_PKEY_CTRL_DIGESTINIT, 0, ctx);
+               if (r <= 0 && (r != -2))
+                       return 0;
+               }
+       if (ctx->flags & EVP_MD_CTX_FLAG_NO_INIT)
+               return 1;
        return ctx->digest->init(ctx);
        }
 
-int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data,
-            size_t count)
+int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t count)
        {
-#ifdef OPENSSL_FIPS
-       FIPS_selftest_check();
-#endif
-       return ctx->digest->update(ctx,data,count);
+       return ctx->update(ctx,data,count);
        }
 
 /* The caller can assume that this removes any secret data from the context */
@@ -338,9 +246,6 @@ int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
 int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
        {
        int ret;
-#ifdef OPENSSL_FIPS
-       FIPS_selftest_check();
-#endif
 
        OPENSSL_assert(ctx->digest->md_size <= EVP_MAX_MD_SIZE);
        ret=ctx->digest->final(ctx,md);
@@ -349,7 +254,7 @@ int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
        if (ctx->digest->cleanup)
                {
                ctx->digest->cleanup(ctx);
-               M_EVP_MD_CTX_set_flags(ctx,EVP_MD_CTX_FLAG_CLEANED);
+               EVP_MD_CTX_set_flags(ctx,EVP_MD_CTX_FLAG_CLEANED);
                }
        memset(ctx->md_data,0,ctx->digest->ctx_size);
        return ret;
@@ -371,7 +276,7 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
                }
 #ifndef OPENSSL_NO_ENGINE
        /* Make sure it's safe to copy a digest context using an ENGINE */
-       if (in->engine && !do_engine_init(in->engine))
+       if (in->engine && !ENGINE_init(in->engine))
                {
                EVPerr(EVP_F_EVP_MD_CTX_COPY_EX,ERR_R_ENGINE_LIB);
                return 0;
@@ -381,13 +286,13 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
        if (out->digest == in->digest)
                {
                tmp_buf = out->md_data;
-               M_EVP_MD_CTX_set_flags(out,EVP_MD_CTX_FLAG_REUSE);
+               EVP_MD_CTX_set_flags(out,EVP_MD_CTX_FLAG_REUSE);
                }
        else tmp_buf = NULL;
        EVP_MD_CTX_cleanup(out);
        memcpy(out,in,sizeof *out);
 
-       if (out->digest->ctx_size)
+       if (in->md_data && out->digest->ctx_size)
                {
                if (tmp_buf)
                        out->md_data = tmp_buf;
@@ -403,6 +308,18 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
                memcpy(out->md_data,in->md_data,out->digest->ctx_size);
                }
 
+       out->update = in->update;
+
+       if (in->pctx)
+               {
+               out->pctx = EVP_PKEY_CTX_dup(in->pctx);
+               if (!out->pctx)
+                       {
+                       EVP_MD_CTX_cleanup(out);
+                       return 0;
+                       }
+               }
+
        if (out->digest->copy)
                return out->digest->copy(out,in);
        
@@ -416,7 +333,7 @@ int EVP_Digest(const void *data, size_t count,
        int ret;
 
        EVP_MD_CTX_init(&ctx);
-       M_EVP_MD_CTX_set_flags(&ctx,EVP_MD_CTX_FLAG_ONESHOT);
+       EVP_MD_CTX_set_flags(&ctx,EVP_MD_CTX_FLAG_ONESHOT);
        ret=EVP_DigestInit_ex(&ctx, type, impl)
          && EVP_DigestUpdate(&ctx, data, count)
          && EVP_DigestFinal_ex(&ctx, md, size);
@@ -438,19 +355,21 @@ int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
         * because sometimes only copies of the context are ever finalised.
         */
        if (ctx->digest && ctx->digest->cleanup
-           && !M_EVP_MD_CTX_test_flags(ctx,EVP_MD_CTX_FLAG_CLEANED))
+           && !EVP_MD_CTX_test_flags(ctx,EVP_MD_CTX_FLAG_CLEANED))
                ctx->digest->cleanup(ctx);
        if (ctx->digest && ctx->digest->ctx_size && ctx->md_data
-           && !M_EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE))
+           && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE))
                {
                OPENSSL_cleanse(ctx->md_data,ctx->digest->ctx_size);
                OPENSSL_free(ctx->md_data);
                }
+       if (ctx->pctx)
+               EVP_PKEY_CTX_free(ctx->pctx);
 #ifndef OPENSSL_NO_ENGINE
        if(ctx->engine)
                /* The EVP_MD we used belongs to an ENGINE, release the
                 * functional reference we held for this reason. */
-               do_engine_finish(ctx->engine);
+               ENGINE_finish(ctx->engine);
 #endif
        memset(ctx,'\0',sizeof *ctx);
 
index c9a5ee8..bd6c0a3 100644 (file)
@@ -69,29 +69,32 @@ typedef struct
 
 IMPLEMENT_BLOCK_CIPHER(aes_128, ks, AES, EVP_AES_KEY,
                       NID_aes_128, 16, 16, 16, 128,
-                      EVP_CIPH_FLAG_FIPS|EVP_CIPH_FLAG_DEFAULT_ASN1,
-                      aes_init_key,
-                      NULL, NULL, NULL, NULL)
+                      0, aes_init_key, NULL, 
+                      EVP_CIPHER_set_asn1_iv,
+                      EVP_CIPHER_get_asn1_iv,
+                      NULL)
 IMPLEMENT_BLOCK_CIPHER(aes_192, ks, AES, EVP_AES_KEY,
                       NID_aes_192, 16, 24, 16, 128,
-                      EVP_CIPH_FLAG_FIPS|EVP_CIPH_FLAG_DEFAULT_ASN1,
-                      aes_init_key,
-                      NULL, NULL, NULL, NULL)
+                      0, aes_init_key, NULL, 
+                      EVP_CIPHER_set_asn1_iv,
+                      EVP_CIPHER_get_asn1_iv,
+                      NULL)
 IMPLEMENT_BLOCK_CIPHER(aes_256, ks, AES, EVP_AES_KEY,
                       NID_aes_256, 16, 32, 16, 128,
-                      EVP_CIPH_FLAG_FIPS|EVP_CIPH_FLAG_DEFAULT_ASN1,
-                      aes_init_key,
-                      NULL, NULL, NULL, NULL)
+                      0, aes_init_key, NULL, 
+                      EVP_CIPHER_set_asn1_iv,
+                      EVP_CIPHER_get_asn1_iv,
+                      NULL)
 
-#define IMPLEMENT_AES_CFBR(ksize,cbits,flags)  IMPLEMENT_CFBR(aes,AES,EVP_AES_KEY,ks,ksize,cbits,16,flags)
+#define IMPLEMENT_AES_CFBR(ksize,cbits)        IMPLEMENT_CFBR(aes,AES,EVP_AES_KEY,ks,ksize,cbits,16)
 
-IMPLEMENT_AES_CFBR(128,1,EVP_CIPH_FLAG_FIPS)
-IMPLEMENT_AES_CFBR(192,1,EVP_CIPH_FLAG_FIPS)
-IMPLEMENT_AES_CFBR(256,1,EVP_CIPH_FLAG_FIPS)
+IMPLEMENT_AES_CFBR(128,1)
+IMPLEMENT_AES_CFBR(192,1)
+IMPLEMENT_AES_CFBR(256,1)
 
-IMPLEMENT_AES_CFBR(128,8,EVP_CIPH_FLAG_FIPS)
-IMPLEMENT_AES_CFBR(192,8,EVP_CIPH_FLAG_FIPS)
-IMPLEMENT_AES_CFBR(256,8,EVP_CIPH_FLAG_FIPS)
+IMPLEMENT_AES_CFBR(128,8)
+IMPLEMENT_AES_CFBR(192,8)
+IMPLEMENT_AES_CFBR(256,8)
 
 static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
                   const unsigned char *iv, int enc)
index 365d397..a7b40d1 100644 (file)
@@ -93,7 +93,7 @@ IMPLEMENT_BLOCK_CIPHER(camellia_256, ks, Camellia, EVP_CAMELLIA_KEY,
        EVP_CIPHER_get_asn1_iv,
        NULL)
 
-#define IMPLEMENT_CAMELLIA_CFBR(ksize,cbits)   IMPLEMENT_CFBR(camellia,Camellia,EVP_CAMELLIA_KEY,ks,ksize,cbits,16,0)
+#define IMPLEMENT_CAMELLIA_CFBR(ksize,cbits)   IMPLEMENT_CFBR(camellia,Camellia,EVP_CAMELLIA_KEY,ks,ksize,cbits,16)
 
 IMPLEMENT_CAMELLIA_CFBR(128,1)
 IMPLEMENT_CAMELLIA_CFBR(192,1)
index 04376df..ca009f2 100644 (file)
@@ -72,7 +72,7 @@ static int des_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr);
 /* Because of various casts and different names can't use IMPLEMENT_BLOCK_CIPHER */
 
 static int des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-                         const unsigned char *in, unsigned int inl)
+                         const unsigned char *in, size_t inl)
 {
        BLOCK_CIPHER_ecb_loop()
                DES_ecb_encrypt((DES_cblock *)(in + i), (DES_cblock *)(out + i), ctx->cipher_data, ctx->encrypt);
@@ -80,24 +80,52 @@ static int des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
 }
 
 static int des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-                         const unsigned char *in, unsigned int inl)
+                         const unsigned char *in, size_t inl)
 {
-       DES_ofb64_encrypt(in, out, (long)inl, ctx->cipher_data, (DES_cblock *)ctx->iv, &ctx->num);
+       while(inl>=EVP_MAXCHUNK)
+               {
+               DES_ofb64_encrypt(in, out, (long)EVP_MAXCHUNK, ctx->cipher_data,
+                               (DES_cblock *)ctx->iv, &ctx->num);
+               inl-=EVP_MAXCHUNK;
+               in +=EVP_MAXCHUNK;
+               out+=EVP_MAXCHUNK;
+               }
+       if (inl)
+               DES_ofb64_encrypt(in, out, (long)inl, ctx->cipher_data,
+                               (DES_cblock *)ctx->iv, &ctx->num);
        return 1;
 }
 
 static int des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-                         const unsigned char *in, unsigned int inl)
+                         const unsigned char *in, size_t inl)
 {
-       DES_ncbc_encrypt(in, out, (long)inl, ctx->cipher_data,
-                        (DES_cblock *)ctx->iv, ctx->encrypt);
+       while(inl>=EVP_MAXCHUNK)
+               {
+               DES_ncbc_encrypt(in, out, (long)EVP_MAXCHUNK, ctx->cipher_data,
+                               (DES_cblock *)ctx->iv, ctx->encrypt);
+               inl-=EVP_MAXCHUNK;
+               in +=EVP_MAXCHUNK;
+               out+=EVP_MAXCHUNK;
+               }
+       if (inl)
+               DES_ncbc_encrypt(in, out, (long)inl, ctx->cipher_data,
+                               (DES_cblock *)ctx->iv, ctx->encrypt);
        return 1;
 }
 
 static int des_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-                           const unsigned char *in, unsigned int inl)
+                           const unsigned char *in, size_t inl)
 {
-       DES_cfb64_encrypt(in, out, (long)inl, ctx->cipher_data,
+       while(inl>=EVP_MAXCHUNK)
+               {
+               DES_cfb64_encrypt(in,out, (long)EVP_MAXCHUNK, ctx->cipher_data,
+                               (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt);
+               inl-=EVP_MAXCHUNK;
+               in +=EVP_MAXCHUNK;
+               out+=EVP_MAXCHUNK;
+               }
+       if (inl)
+               DES_cfb64_encrypt(in, out, (long)inl, ctx->cipher_data,
                          (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt);
        return 1;
 }
@@ -105,45 +133,62 @@ static int des_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
 /* Although we have a CFB-r implementation for DES, it doesn't pack the right
    way, so wrap it here */
 static int des_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-                          const unsigned char *in, unsigned int inl)
+                          const unsigned char *in, size_t inl)
     {
-    unsigned int n;
+    size_t n,chunk=EVP_MAXCHUNK/8;
     unsigned char c[1],d[1];
 
-    for(n=0 ; n < inl ; ++n)
+    if (inl<chunk) chunk=inl;
+
+    while (inl && inl>=chunk)
        {
-       c[0]=(in[n/8]&(1 << (7-n%8))) ? 0x80 : 0;
-       DES_cfb_encrypt(c,d,1,1,ctx->cipher_data,(DES_cblock *)ctx->iv,
+       for(n=0 ; n < chunk*8; ++n)
+           {
+           c[0]=(in[n/8]&(1 << (7-n%8))) ? 0x80 : 0;
+           DES_cfb_encrypt(c,d,1,1,ctx->cipher_data,(DES_cblock *)ctx->iv,
                        ctx->encrypt);
-       out[n/8]=(out[n/8]&~(0x80 >> (n%8)))|((d[0]&0x80) >> (n%8));
+           out[n/8]=(out[n/8]&~(0x80 >> (unsigned int)(n%8))) |
+                    ((d[0]&0x80) >> (unsigned int)(n%8));
+           }
+       inl-=chunk;
+       in +=chunk;
+       out+=chunk;
+       if (inl<chunk) chunk=inl;
        }
+
     return 1;
     }
 
 static int des_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-                          const unsigned char *in, unsigned int inl)
+                          const unsigned char *in, size_t inl)
     {
-    DES_cfb_encrypt(in,out,8,inl,ctx->cipher_data,(DES_cblock *)ctx->iv,
-                   ctx->encrypt);
+    while (inl>=EVP_MAXCHUNK)
+       {
+       DES_cfb_encrypt(in,out,8,(long)EVP_MAXCHUNK,ctx->cipher_data,
+                       (DES_cblock *)ctx->iv,ctx->encrypt);
+       inl-=EVP_MAXCHUNK;
+       in +=EVP_MAXCHUNK;
+       out+=EVP_MAXCHUNK;
+       }
+    if (inl)
+       DES_cfb_encrypt(in,out,8,(long)inl,ctx->cipher_data,
+                       (DES_cblock *)ctx->iv,ctx->encrypt);
     return 1;
     }
 
 BLOCK_CIPHER_defs(des, DES_key_schedule, NID_des, 8, 8, 8, 64,
-                       EVP_CIPH_RAND_KEY,
-                       des_init_key, NULL,
+                       EVP_CIPH_RAND_KEY, des_init_key, NULL,
                        EVP_CIPHER_set_asn1_iv,
                        EVP_CIPHER_get_asn1_iv,
                        des_ctrl)
 
 BLOCK_CIPHER_def_cfb(des,DES_key_schedule,NID_des,8,8,1,
-                    EVP_CIPH_RAND_KEY,
-                    des_init_key, NULL,
+                    EVP_CIPH_RAND_KEY, des_init_key,NULL,
                     EVP_CIPHER_set_asn1_iv,
                     EVP_CIPHER_get_asn1_iv,des_ctrl)
 
 BLOCK_CIPHER_def_cfb(des,DES_key_schedule,NID_des,8,8,8,
-                    EVP_CIPH_RAND_KEY,
-                    des_init_key,NULL,
+                    EVP_CIPH_RAND_KEY,des_init_key,NULL,
                     EVP_CIPHER_set_asn1_iv,
                     EVP_CIPHER_get_asn1_iv,des_ctrl)
 
index f910af1..3232cfe 100644 (file)
@@ -85,7 +85,7 @@ typedef struct
 /* Because of various casts and different args can't use IMPLEMENT_BLOCK_CIPHER */
 
 static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-                             const unsigned char *in, unsigned int inl)
+                             const unsigned char *in, size_t inl)
 {
        BLOCK_CIPHER_ecb_loop()
                DES_ecb3_encrypt((const_DES_cblock *)(in + i),
@@ -97,48 +97,80 @@ static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
 }
 
 static int des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-                             const unsigned char *in, unsigned int inl)
+                             const unsigned char *in, size_t inl)
 {
-       DES_ede3_ofb64_encrypt(in, out, (long)inl,
+       if (inl>=EVP_MAXCHUNK)
+               {
+               DES_ede3_ofb64_encrypt(in, out, (long)EVP_MAXCHUNK,
                               &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
                               (DES_cblock *)ctx->iv, &ctx->num);
+               inl-=EVP_MAXCHUNK;
+               in +=EVP_MAXCHUNK;
+               out+=EVP_MAXCHUNK;
+               }
+       if (inl)
+               DES_ede3_ofb64_encrypt(in, out, (long)inl,
+                               &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
+                               (DES_cblock *)ctx->iv, &ctx->num);
+
        return 1;
 }
 
 static int des_ede_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-                             const unsigned char *in, unsigned int inl)
+                             const unsigned char *in, size_t inl)
 {
 #ifdef KSSL_DEBUG
        {
         int i;
-       printf("des_ede_cbc_cipher(ctx=%lx, buflen=%d)\n", (unsigned long)ctx, ctx->buf_len);
+        char *cp;
+       printf("des_ede_cbc_cipher(ctx=%lx, buflen=%d)\n", ctx, ctx->buf_len);
        printf("\t iv= ");
         for(i=0;i<8;i++)
                 printf("%02X",ctx->iv[i]);
        printf("\n");
        }
 #endif    /* KSSL_DEBUG */
-       DES_ede3_cbc_encrypt(in, out, (long)inl,
+       if (inl>=EVP_MAXCHUNK)
+               {
+               DES_ede3_cbc_encrypt(in, out, (long)EVP_MAXCHUNK,
                             &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
                             (DES_cblock *)ctx->iv, ctx->encrypt);
+               inl-=EVP_MAXCHUNK;
+               in +=EVP_MAXCHUNK;
+               out+=EVP_MAXCHUNK;
+               }
+       if (inl)
+               DES_ede3_cbc_encrypt(in, out, (long)inl,
+                            &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
+                             (DES_cblock *)ctx->iv, ctx->encrypt);
        return 1;
 }
 
 static int des_ede_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-                             const unsigned char *in, unsigned int inl)
+                             const unsigned char *in, size_t inl)
 {
-       DES_ede3_cfb64_encrypt(in, out, (long)inl, 
+       if (inl>=EVP_MAXCHUNK)
+               {
+               DES_ede3_cfb64_encrypt(in, out, (long)EVP_MAXCHUNK, 
                               &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
                               (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt);
+               inl-=EVP_MAXCHUNK;
+               in +=EVP_MAXCHUNK;
+               out+=EVP_MAXCHUNK;
+               }
+       if (inl)
+               DES_ede3_cfb64_encrypt(in, out, (long)inl,
+                              &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
+                               (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt);
        return 1;
 }
 
 /* Although we have a CFB-r implementation for 3-DES, it doesn't pack the right
    way, so wrap it here */
 static int des_ede3_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-                               const unsigned char *in, unsigned int inl)
+                               const unsigned char *in, size_t inl)
     {
-    unsigned int n;
+    size_t n;
     unsigned char c[1],d[1];
 
     for(n=0 ; n < inl ; ++n)
@@ -147,25 +179,36 @@ static int des_ede3_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
        DES_ede3_cfb_encrypt(c,d,1,1,
                             &data(ctx)->ks1,&data(ctx)->ks2,&data(ctx)->ks3,
                             (DES_cblock *)ctx->iv,ctx->encrypt);
-       out[n/8]=(out[n/8]&~(0x80 >> (n%8)))|((d[0]&0x80) >> (n%8));
+       out[n/8]=(out[n/8]&~(0x80 >> (unsigned int)(n%8))) |
+                ((d[0]&0x80) >> (unsigned int)(n%8));
        }
 
     return 1;
     }
 
 static int des_ede3_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-                               const unsigned char *in, unsigned int inl)
+                               const unsigned char *in, size_t inl)
     {
-    DES_ede3_cfb_encrypt(in,out,8,inl,
+    while (inl>=EVP_MAXCHUNK)
+       {
+       DES_ede3_cfb_encrypt(in,out,8,(long)EVP_MAXCHUNK,
                         &data(ctx)->ks1,&data(ctx)->ks2,&data(ctx)->ks3,
                         (DES_cblock *)ctx->iv,ctx->encrypt);
+       inl-=EVP_MAXCHUNK;
+       in +=EVP_MAXCHUNK;
+       out+=EVP_MAXCHUNK;
+       }
+    if (inl)
+       DES_ede3_cfb_encrypt(in,out,8,(long)inl,
+                       &data(ctx)->ks1,&data(ctx)->ks2,&data(ctx)->ks3,
+                       (DES_cblock *)ctx->iv,ctx->encrypt);
     return 1;
     }
 
 BLOCK_CIPHER_defs(des_ede, DES_EDE_KEY, NID_des_ede, 8, 16, 8, 64,
-               EVP_CIPH_RAND_KEY|EVP_CIPH_FLAG_FIPS|EVP_CIPH_FLAG_DEFAULT_ASN1,
-                       des_ede_init_key,
-                       NULL, NULL, NULL,
+                       EVP_CIPH_RAND_KEY, des_ede_init_key, NULL, 
+                       EVP_CIPHER_set_asn1_iv,
+                       EVP_CIPHER_get_asn1_iv,
                        des3_ctrl)
 
 #define des_ede3_cfb64_cipher des_ede_cfb64_cipher
@@ -174,21 +217,21 @@ BLOCK_CIPHER_defs(des_ede, DES_EDE_KEY, NID_des_ede, 8, 16, 8, 64,
 #define des_ede3_ecb_cipher des_ede_ecb_cipher
 
 BLOCK_CIPHER_defs(des_ede3, DES_EDE_KEY, NID_des_ede3, 8, 24, 8, 64,
-               EVP_CIPH_RAND_KEY|EVP_CIPH_FLAG_FIPS|EVP_CIPH_FLAG_DEFAULT_ASN1,
-                       des_ede3_init_key,
-                       NULL, NULL, NULL,
+                       EVP_CIPH_RAND_KEY, des_ede3_init_key, NULL, 
+                       EVP_CIPHER_set_asn1_iv,
+                       EVP_CIPHER_get_asn1_iv,
                        des3_ctrl)
 
 BLOCK_CIPHER_def_cfb(des_ede3,DES_EDE_KEY,NID_des_ede3,24,8,1,
-               EVP_CIPH_RAND_KEY|EVP_CIPH_FLAG_FIPS|EVP_CIPH_FLAG_DEFAULT_ASN1,
-                    des_ede3_init_key,
-                    NULL, NULL, NULL,
+                    EVP_CIPH_RAND_KEY, des_ede3_init_key,NULL,
+                    EVP_CIPHER_set_asn1_iv,
+                    EVP_CIPHER_get_asn1_iv,
                     des3_ctrl)
 
 BLOCK_CIPHER_def_cfb(des_ede3,DES_EDE_KEY,NID_des_ede3,24,8,8,
-               EVP_CIPH_RAND_KEY|EVP_CIPH_FLAG_FIPS|EVP_CIPH_FLAG_DEFAULT_ASN1,
-                    des_ede3_init_key,
-                    NULL, NULL, NULL,
+                    EVP_CIPH_RAND_KEY, des_ede3_init_key,NULL,
+                    EVP_CIPHER_set_asn1_iv,
+                    EVP_CIPHER_get_asn1_iv,
                     des3_ctrl)
 
 static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
@@ -215,7 +258,7 @@ static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
 #ifdef KSSL_DEBUG
        {
         int i;
-        printf("des_ede3_init_key(ctx=%lx)\n", (unsigned long)ctx);
+        printf("des_ede3_init_key(ctx=%lx)\n", ctx);
        printf("\tKEY= ");
         for(i=0;i<24;i++) printf("%02X",key[i]); printf("\n");
        printf("\t IV= ");
index 48c33a7..806b080 100644 (file)
@@ -73,7 +73,7 @@ static int idea_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
  */
 
 static int idea_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-                          const unsigned char *in, unsigned int inl)
+                          const unsigned char *in, size_t inl)
 {
        BLOCK_CIPHER_ecb_loop()
                idea_ecb_encrypt(in + i, out + i, ctx->cipher_data);
index 0872d73..7cf50e1 100644 (file)
 static int null_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
        const unsigned char *iv,int enc);
 static int null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-       const unsigned char *in, unsigned int inl);
+       const unsigned char *in, size_t inl);
 static const EVP_CIPHER n_cipher=
        {
        NID_undef,
        1,0,0,
-       EVP_CIPH_FLAG_FIPS,
+       0,
        null_init_key,
        null_cipher,
        NULL,
@@ -93,10 +93,10 @@ static int null_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
        }
 
 static int null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-            const unsigned char *in, unsigned int inl)
+            const unsigned char *in, size_t inl)
        {
        if (in != out)
-               memcpy((char *)out,(const char *)in,(size_t)inl);
+               memcpy((char *)out,(const char *)in,inl);
        return 1;
        }
 
index d37726f..f78d781 100644 (file)
@@ -223,6 +223,11 @@ static int rc2_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
                        return 1;
                        }
                return 0;
+#ifdef PBE_PRF_TEST
+       case EVP_CTRL_PBE_PRF_NID:
+               *(int *)ptr = NID_hmacWithMD5;
+               return 1;
+#endif
 
        default:
                return -1;
index 55baad7..8b5175e 100644 (file)
@@ -64,7 +64,6 @@
 #include <openssl/evp.h>
 #include <openssl/objects.h>
 #include <openssl/rc4.h>
-#include "evp_locl.h"
 
 /* FIXME: surely this is available elsewhere? */
 #define EVP_RC4_KEY_SIZE               16
@@ -79,7 +78,7 @@ typedef struct
 static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
                        const unsigned char *iv,int enc);
 static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-                     const unsigned char *in, unsigned int inl);
+                     const unsigned char *in, size_t inl);
 static const EVP_CIPHER r4_cipher=
        {
        NID_rc4,
@@ -129,7 +128,7 @@ static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
        }
 
 static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-                     const unsigned char *in, unsigned int inl)
+                     const unsigned char *in, size_t inl)
        {
        RC4(&data(ctx)->ks,inl,in,out);
        return 1;
index 8c1ec0d..2d1759d 100644 (file)
  */
 
 #include <openssl/opensslconf.h>
+#ifndef OPENSSL_NO_SEED
 #include <openssl/evp.h>
 #include <openssl/err.h>
 #include <string.h>
 #include <assert.h>
-#ifndef OPENSSL_NO_SEED
 #include <openssl/seed.h>
 #include "evp_locl.h"
 
index 8832da2..250e88c 100644 (file)
 
 #include <openssl/evp.h>
 #include <openssl/objects.h>
+#include "evp_locl.h"
 #include <openssl/des.h>
 
 static int desx_cbc_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
                             const unsigned char *iv,int enc);
 static int desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-                          const unsigned char *in, unsigned int inl);
+                          const unsigned char *in, size_t inl);
 
 
 typedef struct
@@ -113,13 +114,25 @@ static int desx_cbc_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
        }
 
 static int desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-                          const unsigned char *in, unsigned int inl)
+                          const unsigned char *in, size_t inl)
        {
-       DES_xcbc_encrypt(in,out,inl,&data(ctx)->ks,
+       while (inl>=EVP_MAXCHUNK)
+               {
+               DES_xcbc_encrypt(in,out,(long)EVP_MAXCHUNK,&data(ctx)->ks,
                         (DES_cblock *)&(ctx->iv[0]),
                         &data(ctx)->inw,
                         &data(ctx)->outw,
                         ctx->encrypt);
+               inl-=EVP_MAXCHUNK;
+               in +=EVP_MAXCHUNK;
+               out+=EVP_MAXCHUNK;
+               }
+       if (inl)
+               DES_xcbc_encrypt(in,out,(long)inl,&data(ctx)->ks,
+                       (DES_cblock *)&(ctx->iv[0]),
+                       &data(ctx)->inw,
+                       &data(ctx)->outw,
+                       ctx->encrypt);
        return 1;
        }
 #endif
diff --git a/deps/openssl/openssl/crypto/evp/enc_min.c b/deps/openssl/openssl/crypto/evp/enc_min.c
deleted file mode 100644 (file)
index a8c176f..0000000
+++ /dev/null
@@ -1,391 +0,0 @@
-/* crypto/evp/enc_min.c */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-#include <stdio.h>
-#include "cryptlib.h"
-#include <openssl/evp.h>
-#include <openssl/err.h>
-#include <openssl/rand.h>
-#ifndef OPENSSL_NO_ENGINE
-#include <openssl/engine.h>
-#endif
-#include "evp_locl.h"
-
-void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx)
-       {
-#ifdef OPENSSL_FIPS
-       FIPS_selftest_check();
-#endif
-       memset(ctx,0,sizeof(EVP_CIPHER_CTX));
-       /* ctx->cipher=NULL; */
-       }
-
-#ifdef OPENSSL_FIPS
-
-/* The purpose of these is to trap programs that attempt to use non FIPS
- * algorithms in FIPS mode and ignore the errors.
- */
-
-static int bad_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
-                   const unsigned char *iv, int enc)
-       { FIPS_ERROR_IGNORED("Cipher init"); return 0;}
-
-static int bad_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-                        const unsigned char *in, unsigned int inl)
-       { FIPS_ERROR_IGNORED("Cipher update"); return 0;}
-
-/* NB: no cleanup because it is allowed after failed init */
-
-static int bad_set_asn1(EVP_CIPHER_CTX *ctx, ASN1_TYPE *typ)
-       { FIPS_ERROR_IGNORED("Cipher set_asn1"); return 0;}
-static int bad_get_asn1(EVP_CIPHER_CTX *ctx, ASN1_TYPE *typ)
-       { FIPS_ERROR_IGNORED("Cipher get_asn1"); return 0;}
-static int bad_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
-       { FIPS_ERROR_IGNORED("Cipher ctrl"); return 0;}
-
-static const EVP_CIPHER bad_cipher =
-       {
-       0,
-       0,
-       0,
-       0,
-       0,
-       bad_init,
-       bad_do_cipher,
-       NULL,
-       0,
-       bad_set_asn1,
-       bad_get_asn1,
-       bad_ctrl,
-       NULL
-       };
-
-#endif
-
-#ifndef OPENSSL_NO_ENGINE
-
-#ifdef OPENSSL_FIPS
-
-static int do_engine_null(ENGINE *impl) { return 0;}
-static int do_evp_enc_engine_null(EVP_CIPHER_CTX *ctx,
-                               const EVP_CIPHER **pciph, ENGINE *impl)
-       { return 1; }
-
-static int (*do_engine_finish)(ENGINE *impl)
-               = do_engine_null;
-
-static int (*do_evp_enc_engine)
-       (EVP_CIPHER_CTX *ctx, const EVP_CIPHER **pciph, ENGINE *impl)
-               = do_evp_enc_engine_null;
-
-void int_EVP_CIPHER_set_engine_callbacks(
-       int (*eng_ciph_fin)(ENGINE *impl),
-       int (*eng_ciph_evp)
-               (EVP_CIPHER_CTX *ctx, const EVP_CIPHER **pciph, ENGINE *impl))
-       {
-       do_engine_finish = eng_ciph_fin;
-       do_evp_enc_engine = eng_ciph_evp;
-       }
-
-#else
-
-#define do_engine_finish ENGINE_finish
-
-static int do_evp_enc_engine(EVP_CIPHER_CTX *ctx, const EVP_CIPHER **pcipher, ENGINE *impl)
-       {
-       if(impl)
-               {
-               if (!ENGINE_init(impl))
-                       {
-                       EVPerr(EVP_F_DO_EVP_ENC_ENGINE, EVP_R_INITIALIZATION_ERROR);
-                       return 0;
-                       }
-               }
-       else
-               /* Ask if an ENGINE is reserved for this job */
-               impl = ENGINE_get_cipher_engine((*pcipher)->nid);
-       if(impl)
-               {
-               /* There's an ENGINE for this job ... (apparently) */
-               const EVP_CIPHER *c = ENGINE_get_cipher(impl, (*pcipher)->nid);
-               if(!c)
-                       {
-                       /* One positive side-effect of US's export
-                        * control history, is that we should at least
-                        * be able to avoid using US mispellings of
-                        * "initialisation"? */
-                       EVPerr(EVP_F_DO_EVP_ENC_ENGINE, EVP_R_INITIALIZATION_ERROR);
-                       return 0;
-                       }
-               /* We'll use the ENGINE's private cipher definition */
-               *pcipher = c;
-               /* Store the ENGINE functional reference so we know
-                * 'cipher' came from an ENGINE and we need to release
-                * it when done. */
-               ctx->engine = impl;
-               }
-       else
-               ctx->engine = NULL;
-       return 1;
-       }
-
-#endif
-
-#endif
-
-int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl,
-            const unsigned char *key, const unsigned char *iv, int enc)
-       {
-       if (enc == -1)
-               enc = ctx->encrypt;
-       else
-               {
-               if (enc)
-                       enc = 1;
-               ctx->encrypt = enc;
-               }
-#ifdef OPENSSL_FIPS
-       if(FIPS_selftest_failed())
-               {
-               FIPSerr(FIPS_F_EVP_CIPHERINIT_EX,FIPS_R_FIPS_SELFTEST_FAILED);
-               ctx->cipher = &bad_cipher;
-               return 0;
-               }
-#endif
-#ifndef OPENSSL_NO_ENGINE
-       /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts
-        * so this context may already have an ENGINE! Try to avoid releasing
-        * the previous handle, re-querying for an ENGINE, and having a
-        * reinitialisation, when it may all be unecessary. */
-       if (ctx->engine && ctx->cipher && (!cipher ||
-                       (cipher && (cipher->nid == ctx->cipher->nid))))
-               goto skip_to_init;
-#endif
-       if (cipher)
-               {
-               /* Ensure a context left lying around from last time is cleared
-                * (the previous check attempted to avoid this if the same
-                * ENGINE and EVP_CIPHER could be used). */
-               EVP_CIPHER_CTX_cleanup(ctx);
-
-               /* Restore encrypt field: it is zeroed by cleanup */
-               ctx->encrypt = enc;
-#ifndef OPENSSL_NO_ENGINE
-               if (!do_evp_enc_engine(ctx, &cipher, impl))
-                       return 0;
-#endif
-
-               ctx->cipher=cipher;
-               if (ctx->cipher->ctx_size)
-                       {
-                       ctx->cipher_data=OPENSSL_malloc(ctx->cipher->ctx_size);
-                       if (!ctx->cipher_data)
-                               {
-                               EVPerr(EVP_F_EVP_CIPHERINIT_EX, ERR_R_MALLOC_FAILURE);
-                               return 0;
-                               }
-                       }
-               else
-                       {
-                       ctx->cipher_data = NULL;
-                       }
-               ctx->key_len = cipher->key_len;
-               ctx->flags = 0;
-               if(ctx->cipher->flags & EVP_CIPH_CTRL_INIT)
-                       {
-                       if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_INIT, 0, NULL))
-                               {
-                               EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_INITIALIZATION_ERROR);
-                               return 0;
-                               }
-                       }
-               }
-       else if(!ctx->cipher)
-               {
-               EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_NO_CIPHER_SET);
-               return 0;
-               }
-#ifndef OPENSSL_NO_ENGINE
-skip_to_init:
-#endif
-       /* we assume block size is a power of 2 in *cryptUpdate */
-       OPENSSL_assert(ctx->cipher->block_size == 1
-           || ctx->cipher->block_size == 8
-           || ctx->cipher->block_size == 16);
-
-       if(!(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_CUSTOM_IV)) {
-               switch(EVP_CIPHER_CTX_mode(ctx)) {
-
-                       case EVP_CIPH_STREAM_CIPHER:
-                       case EVP_CIPH_ECB_MODE:
-                       break;
-
-                       case EVP_CIPH_CFB_MODE:
-                       case EVP_CIPH_OFB_MODE:
-
-                       ctx->num = 0;
-                       /* fall-through */
-
-                       case EVP_CIPH_CBC_MODE:
-
-                       OPENSSL_assert(EVP_CIPHER_CTX_iv_length(ctx) <=
-                                       (int)sizeof(ctx->iv));
-                       if(iv) memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx));
-                       memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx));
-                       break;
-
-                       default:
-                       return 0;
-                       break;
-               }
-       }
-
-#ifdef OPENSSL_FIPS
-       /* After 'key' is set no further parameters changes are permissible.
-        * So only check for non FIPS enabling at this point.
-        */
-       if (key && FIPS_mode())
-               {
-               if (!(ctx->cipher->flags & EVP_CIPH_FLAG_FIPS)
-                       & !(ctx->flags & EVP_CIPH_FLAG_NON_FIPS_ALLOW))
-                       {
-                       EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_DISABLED_FOR_FIPS);
-#if 0
-                       ERR_add_error_data(2, "cipher=",
-                                               EVP_CIPHER_name(ctx->cipher));
-#endif
-                       ctx->cipher = &bad_cipher;
-                       return 0;
-                       }
-               }
-#endif
-
-       if(key || (ctx->cipher->flags & EVP_CIPH_ALWAYS_CALL_INIT)) {
-               if(!ctx->cipher->init(ctx,key,iv,enc)) return 0;
-       }
-       ctx->buf_len=0;
-       ctx->final_used=0;
-       ctx->block_mask=ctx->cipher->block_size-1;
-       return 1;
-       }
-
-int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c)
-       {
-       if (c->cipher != NULL)
-               {
-               if(c->cipher->cleanup && !c->cipher->cleanup(c))
-                       return 0;
-               /* Cleanse cipher context data */
-               if (c->cipher_data)
-                       OPENSSL_cleanse(c->cipher_data, c->cipher->ctx_size);
-               }
-       if (c->cipher_data)
-               OPENSSL_free(c->cipher_data);
-#ifndef OPENSSL_NO_ENGINE
-       if (c->engine)
-               /* The EVP_CIPHER we used belongs to an ENGINE, release the
-                * functional reference we held for this reason. */
-               do_engine_finish(c->engine);
-#endif
-       memset(c,0,sizeof(EVP_CIPHER_CTX));
-       return 1;
-       }
-
-int EVP_Cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl)
-       {
-#ifdef OPENSSL_FIPS
-       FIPS_selftest_check();
-#endif
-       return ctx->cipher->do_cipher(ctx,out,in,inl);
-       }
-
-int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
-{
-       int ret;
-       if(!ctx->cipher) {
-               EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_NO_CIPHER_SET);
-               return 0;
-       }
-
-       if(!ctx->cipher->ctrl) {
-               EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_CTRL_NOT_IMPLEMENTED);
-               return 0;
-       }
-
-       ret = ctx->cipher->ctrl(ctx, type, arg, ptr);
-       if(ret == -1) {
-               EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED);
-               return 0;
-       }
-       return ret;
-}
-
-unsigned long EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *ctx)
-       {
-       return ctx->cipher->flags;
-       }
-
-int EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx)
-       {
-       return ctx->cipher->iv_len;
-       }
-
-int EVP_CIPHER_nid(const EVP_CIPHER *cipher)
-       {
-       return cipher->nid;
-       }
index e8a5218..28546a8 100644 (file)
@@ -85,7 +85,7 @@
 #define CHUNKS_PER_LINE (64/4)
 #define CHAR_PER_LINE   (64+1)
 
-static unsigned char data_bin2ascii[65]="ABCDEFGHIJKLMNOPQRSTUVWXYZ\
+static const unsigned char data_bin2ascii[65]="ABCDEFGHIJKLMNOPQRSTUVWXYZ\
 abcdefghijklmnopqrstuvwxyz0123456789+/";
 
 /* 0xF0 is a EOLN
@@ -102,7 +102,7 @@ abcdefghijklmnopqrstuvwxyz0123456789+/";
 #define B64_ERROR              0xFF
 #define B64_NOT_BASE64(a)      (((a)|0x13) == 0xF3)
 
-static unsigned char data_ascii2bin[128]={
+static const unsigned char data_ascii2bin[128]={
        0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
        0xFF,0xE0,0xF0,0xFF,0xFF,0xF1,0xFF,0xFF,
        0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
index 79c0971..9f9795e 100644 (file)
 #include <openssl/bio.h>
 #endif
 
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
 /*
 #define EVP_RC2_KEY_SIZE               16
 #define EVP_RC4_KEY_SIZE               16
 #define EVP_PKEY_DSA4  NID_dsaWithSHA1_2
 #define EVP_PKEY_DH    NID_dhKeyAgreement
 #define EVP_PKEY_EC    NID_X9_62_id_ecPublicKey
+#define EVP_PKEY_HMAC  NID_hmac
 
 #ifdef __cplusplus
 extern "C" {
@@ -132,6 +129,8 @@ struct evp_pkey_st
        int type;
        int save_type;
        int references;
+       const EVP_PKEY_ASN1_METHOD *ameth;
+       ENGINE *engine;
        union   {
                char *ptr;
 #ifndef OPENSSL_NO_RSA
@@ -156,73 +155,6 @@ struct evp_pkey_st
 #define EVP_PKEY_MO_ENCRYPT    0x0004
 #define EVP_PKEY_MO_DECRYPT    0x0008
 
-#if 0
-/* This structure is required to tie the message digest and signing together.
- * The lookup can be done by md/pkey_method, oid, oid/pkey_method, or
- * oid, md and pkey.
- * This is required because for various smart-card perform the digest and
- * signing/verification on-board.  To handle this case, the specific
- * EVP_MD and EVP_PKEY_METHODs need to be closely associated.
- * When a PKEY is created, it will have a EVP_PKEY_METHOD associated with it.
- * This can either be software or a token to provide the required low level
- * routines.
- */
-typedef struct evp_pkey_md_st
-       {
-       int oid;
-       EVP_MD *md;
-       EVP_PKEY_METHOD *pkey;
-       } EVP_PKEY_MD;
-
-#define EVP_rsa_md2() \
-               EVP_PKEY_MD_add(NID_md2WithRSAEncryption,\
-                       EVP_rsa_pkcs1(),EVP_md2())
-#define EVP_rsa_md5() \
-               EVP_PKEY_MD_add(NID_md5WithRSAEncryption,\
-                       EVP_rsa_pkcs1(),EVP_md5())
-#define EVP_rsa_sha0() \
-               EVP_PKEY_MD_add(NID_shaWithRSAEncryption,\
-                       EVP_rsa_pkcs1(),EVP_sha())
-#define EVP_rsa_sha1() \
-               EVP_PKEY_MD_add(NID_sha1WithRSAEncryption,\
-                       EVP_rsa_pkcs1(),EVP_sha1())
-#define EVP_rsa_ripemd160() \
-               EVP_PKEY_MD_add(NID_ripemd160WithRSA,\
-                       EVP_rsa_pkcs1(),EVP_ripemd160())
-#define EVP_rsa_mdc2() \
-               EVP_PKEY_MD_add(NID_mdc2WithRSA,\
-                       EVP_rsa_octet_string(),EVP_mdc2())
-#define EVP_dsa_sha() \
-               EVP_PKEY_MD_add(NID_dsaWithSHA,\
-                       EVP_dsa(),EVP_sha())
-#define EVP_dsa_sha1() \
-               EVP_PKEY_MD_add(NID_dsaWithSHA1,\
-                       EVP_dsa(),EVP_sha1())
-
-typedef struct evp_pkey_method_st
-       {
-       char *name;
-       int flags;
-       int type;               /* RSA, DSA, an SSLeay specific constant */
-       int oid;                /* For the pub-key type */
-       int encrypt_oid;        /* pub/priv key encryption */
-
-       int (*sign)();
-       int (*verify)();
-       struct  {
-               int (*set)();   /* get and/or set the underlying type */
-               int (*get)();
-               int (*encrypt)();
-               int (*decrypt)();
-               int (*i2d)();
-               int (*d2i)();
-               int (*dup)();
-               } pub,priv;
-       int (*set_asn1_parameters)();
-       int (*get_asn1_parameters)();
-       } EVP_PKEY_METHOD;
-#endif
-
 #ifndef EVP_MD
 struct env_md_st
        {
@@ -245,6 +177,8 @@ struct env_md_st
        int required_pkey_type[5]; /*EVP_PKEY_xxx */
        int block_size;
        int ctx_size; /* how big does the ctx->md_data need to be */
+       /* control function */
+       int (*md_ctrl)(EVP_MD_CTX *ctx, int cmd, int p1, void *p2);
        } /* EVP_MD */;
 
 typedef int evp_sign_method(int type,const unsigned char *m,
@@ -254,18 +188,42 @@ typedef int evp_verify_method(int type,const unsigned char *m,
                            unsigned int m_length,const unsigned char *sigbuf,
                            unsigned int siglen, void *key);
 
-typedef struct
-       {
-       EVP_MD_CTX *mctx;
-       void *key;
-       } EVP_MD_SVCTX;
-
 #define EVP_MD_FLAG_ONESHOT    0x0001 /* digest can only handle a single
                                        * block */
 
-#define EVP_MD_FLAG_FIPS       0x0400 /* Note if suitable for use in FIPS mode */
+#define EVP_MD_FLAG_PKEY_DIGEST        0x0002 /* digest is a "clone" digest used
+                                       * which is a copy of an existing
+                                       * one for a specific public key type.
+                                       * EVP_dss1() etc */
+
+/* Digest uses EVP_PKEY_METHOD for signing instead of MD specific signing */
+
+#define EVP_MD_FLAG_PKEY_METHOD_SIGNATURE      0x0004
+
+/* DigestAlgorithmIdentifier flags... */
+
+#define EVP_MD_FLAG_DIGALGID_MASK              0x0018
 
-#define EVP_MD_FLAG_SVCTX      0x0800 /* pass EVP_MD_SVCTX to sign/verify */
+/* NULL or absent parameter accepted. Use NULL */
+
+#define EVP_MD_FLAG_DIGALGID_NULL              0x0000
+
+/* NULL or absent parameter accepted. Use NULL for PKCS#1 otherwise absent */
+
+#define EVP_MD_FLAG_DIGALGID_ABSENT            0x0008
+
+/* Custom handling via ctrl */
+
+#define EVP_MD_FLAG_DIGALGID_CUSTOM            0x0018
+
+/* Digest ctrls */
+
+#define        EVP_MD_CTRL_DIGALGID                    0x1
+#define        EVP_MD_CTRL_MICALG                      0x2
+
+/* Minimum Algorithm specific ctrl value */
+
+#define        EVP_MD_CTRL_ALG_CTRL                    0x1000
 
 #define EVP_PKEY_NULL_method   NULL,NULL,{0,0,0,0}
 
@@ -307,6 +265,10 @@ struct env_md_ctx_st
        ENGINE *engine; /* functional reference if 'digest' is ENGINE-provided */
        unsigned long flags;
        void *md_data;
+       /* Public key context for sign/verify */
+       EVP_PKEY_CTX *pctx;
+       /* Update function: usually copied from EVP_MD */
+       int (*update)(EVP_MD_CTX *ctx,const void *data,size_t count);
        } /* EVP_MD_CTX */;
 
 /* values for EVP_MD_CTX flags */
@@ -317,17 +279,23 @@ struct env_md_ctx_st
                                                * cleaned */
 #define EVP_MD_CTX_FLAG_REUSE          0x0004 /* Don't free up ctx->md_data
                                                * in EVP_MD_CTX_cleanup */
+/* FIPS and pad options are ignored in 1.0.0, definitions are here
+ * so we don't accidentally reuse the values for other purposes.
+ */
+
 #define EVP_MD_CTX_FLAG_NON_FIPS_ALLOW 0x0008  /* Allow use of non FIPS digest
                                                 * in FIPS mode */
 
+/* The following PAD options are also currently ignored in 1.0.0, digest
+ * parameters are handled through EVP_DigestSign*() and EVP_DigestVerify*()
+ * instead.
+ */
 #define EVP_MD_CTX_FLAG_PAD_MASK       0xF0    /* RSA mode to use */
 #define EVP_MD_CTX_FLAG_PAD_PKCS1      0x00    /* PKCS#1 v1.5 mode */
 #define EVP_MD_CTX_FLAG_PAD_X931       0x10    /* X9.31 mode */
 #define EVP_MD_CTX_FLAG_PAD_PSS                0x20    /* PSS mode */
-#define M_EVP_MD_CTX_FLAG_PSS_SALT(ctx) \
-               ((ctx->flags>>16) &0xFFFF) /* seed length */
-#define EVP_MD_CTX_FLAG_PSS_MDLEN      0xFFFF  /* salt len same as digest */
-#define EVP_MD_CTX_FLAG_PSS_MREC       0xFFFE  /* salt max or auto recovered */
+
+#define EVP_MD_CTX_FLAG_NO_INIT                0x0100 /* Don't initialize md_data */
 
 struct evp_cipher_st
        {
@@ -339,7 +307,7 @@ struct evp_cipher_st
        int (*init)(EVP_CIPHER_CTX *ctx, const unsigned char *key,
                    const unsigned char *iv, int enc);  /* init key */
        int (*do_cipher)(EVP_CIPHER_CTX *ctx, unsigned char *out,
-                        const unsigned char *in, unsigned int inl);/* encrypt/decrypt data */
+                        const unsigned char *in, size_t inl);/* encrypt/decrypt data */
        int (*cleanup)(EVP_CIPHER_CTX *); /* cleanup ctx */
        int ctx_size;           /* how big ctx->cipher_data needs to be */
        int (*set_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Populate a ASN1_TYPE with parameters */
@@ -357,7 +325,7 @@ struct evp_cipher_st
 #define                EVP_CIPH_CBC_MODE               0x2
 #define                EVP_CIPH_CFB_MODE               0x3
 #define                EVP_CIPH_OFB_MODE               0x4
-#define        EVP_CIPH_MODE                   0x7
+#define        EVP_CIPH_MODE                   0xF0007
 /* Set if variable length cipher */
 #define        EVP_CIPH_VARIABLE_LENGTH        0x8
 /* Set if the iv handling should be done by the cipher itself */
@@ -372,10 +340,8 @@ struct evp_cipher_st
 #define        EVP_CIPH_NO_PADDING             0x100
 /* cipher handles random key generation */
 #define        EVP_CIPH_RAND_KEY               0x200
-/* Note if suitable for use in FIPS mode */
-#define                EVP_CIPH_FLAG_FIPS              0x400
-/* Allow non FIPS cipher in FIPS mode */
-#define                EVP_CIPH_FLAG_NON_FIPS_ALLOW    0x800
+/* cipher has its own additional copying logic */
+#define        EVP_CIPH_CUSTOM_COPY            0x400
 /* Allow use default ASN1 get/set iv */
 #define                EVP_CIPH_FLAG_DEFAULT_ASN1      0x1000
 /* Buffer length in bits not bytes: CFB1 mode only */
@@ -390,6 +356,8 @@ struct evp_cipher_st
 #define        EVP_CTRL_GET_RC5_ROUNDS         0x4
 #define        EVP_CTRL_SET_RC5_ROUNDS         0x5
 #define        EVP_CTRL_RAND_KEY               0x6
+#define        EVP_CTRL_PBE_PRF_NID            0x7
+#define        EVP_CTRL_COPY                   0x8
 
 typedef struct evp_cipher_info_st
        {
@@ -462,26 +430,15 @@ typedef int (EVP_PBE_KEYGEN)(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
 #define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a))
 #define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a))
 
-/* Macros to reduce FIPS dependencies: do NOT use in applications */
-#define M_EVP_MD_size(e)               ((e)->md_size)
-#define M_EVP_MD_block_size(e)         ((e)->block_size)
-#define M_EVP_MD_CTX_set_flags(ctx,flgs) ((ctx)->flags|=(flgs))
-#define M_EVP_MD_CTX_clear_flags(ctx,flgs) ((ctx)->flags&=~(flgs))
-#define M_EVP_MD_CTX_test_flags(ctx,flgs) ((ctx)->flags&(flgs))
-#define M_EVP_MD_type(e)                       ((e)->type)
-#define M_EVP_MD_CTX_type(e)           M_EVP_MD_type(M_EVP_MD_CTX_md(e))
-#define M_EVP_MD_CTX_md(e)                     ((e)->digest)
-
-#define M_EVP_CIPHER_CTX_set_flags(ctx,flgs) ((ctx)->flags|=(flgs))
-
 int EVP_MD_type(const EVP_MD *md);
 #define EVP_MD_nid(e)                  EVP_MD_type(e)
 #define EVP_MD_name(e)                 OBJ_nid2sn(EVP_MD_nid(e))
 int EVP_MD_pkey_type(const EVP_MD *md);        
 int EVP_MD_size(const EVP_MD *md);
 int EVP_MD_block_size(const EVP_MD *md);
+unsigned long EVP_MD_flags(const EVP_MD *md);
 
-const EVP_MD * EVP_MD_CTX_md(const EVP_MD_CTX *ctx);
+const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx);
 #define EVP_MD_CTX_size(e)             EVP_MD_size(EVP_MD_CTX_md(e))
 #define EVP_MD_CTX_block_size(e)       EVP_MD_block_size(EVP_MD_CTX_md(e))
 #define EVP_MD_CTX_type(e)             EVP_MD_type(EVP_MD_CTX_md(e))
@@ -499,6 +456,7 @@ int EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx);
 int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx);
 int EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx);
 int EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx);
+int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in);
 void * EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx);
 void EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *ctx, void *data);
 #define EVP_CIPHER_CTX_type(c)         EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c))
@@ -516,6 +474,8 @@ unsigned long EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *ctx);
 #define        EVP_VerifyUpdate(a,b,c)         EVP_DigestUpdate(a,b,c)
 #define EVP_OpenUpdate(a,b,c,d,e)      EVP_DecryptUpdate(a,b,c,d,e)
 #define EVP_SealUpdate(a,b,c,d,e)      EVP_EncryptUpdate(a,b,c,d,e)    
+#define EVP_DigestSignUpdate(a,b,c)    EVP_DigestUpdate(a,b,c)
+#define EVP_DigestVerifyUpdate(a,b,c)  EVP_DigestUpdate(a,b,c)
 
 #ifdef CONST_STRICT
 void BIO_set_md(BIO *,const EVP_MD *md);
@@ -562,6 +522,7 @@ int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
 int    EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s);
 
 int    EVP_read_pw_string(char *buf,int length,const char *prompt,int verify);
+int    EVP_read_pw_string_min(char *buf,int minlen,int maxlen,const char *prompt,int verify);
 void   EVP_set_pw_prompt(const char *prompt);
 char * EVP_get_pw_prompt(void);
 
@@ -608,6 +569,16 @@ int        EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s,
 int    EVP_VerifyFinal(EVP_MD_CTX *ctx,const unsigned char *sigbuf,
                unsigned int siglen,EVP_PKEY *pkey);
 
+int    EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
+                       const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey);
+int    EVP_DigestSignFinal(EVP_MD_CTX *ctx,
+                       unsigned char *sigret, size_t *siglen);
+
+int    EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
+                       const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey);
+int    EVP_DigestVerifyFinal(EVP_MD_CTX *ctx,
+                       unsigned char *sig, size_t siglen);
+
 int    EVP_OpenInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,
                const unsigned char *ek, int ekl, const unsigned char *iv,
                EVP_PKEY *priv);
@@ -680,6 +651,9 @@ const EVP_MD *EVP_mdc2(void);
 #ifndef OPENSSL_NO_RIPEMD
 const EVP_MD *EVP_ripemd160(void);
 #endif
+#ifndef OPENSSL_NO_WHIRLPOOL
+const EVP_MD *EVP_whirlpool(void);
+#endif
 const EVP_CIPHER *EVP_enc_null(void);          /* does nothing :-) */
 #ifndef OPENSSL_NO_DES
 const EVP_CIPHER *EVP_des_ecb(void);
@@ -847,16 +821,31 @@ const EVP_CIPHER *EVP_get_cipherbyname(const char *name);
 const EVP_MD *EVP_get_digestbyname(const char *name);
 void EVP_cleanup(void);
 
-int            EVP_PKEY_decrypt(unsigned char *dec_key,
+void EVP_CIPHER_do_all(void (*fn)(const EVP_CIPHER *ciph,
+               const char *from, const char *to, void *x), void *arg);
+void EVP_CIPHER_do_all_sorted(void (*fn)(const EVP_CIPHER *ciph,
+               const char *from, const char *to, void *x), void *arg);
+
+void EVP_MD_do_all(void (*fn)(const EVP_MD *ciph,
+               const char *from, const char *to, void *x), void *arg);
+void EVP_MD_do_all_sorted(void (*fn)(const EVP_MD *ciph,
+               const char *from, const char *to, void *x), void *arg);
+
+int            EVP_PKEY_decrypt_old(unsigned char *dec_key,
                        const unsigned char *enc_key,int enc_key_len,
                        EVP_PKEY *private_key);
-int            EVP_PKEY_encrypt(unsigned char *enc_key,
+int            EVP_PKEY_encrypt_old(unsigned char *enc_key,
                        const unsigned char *key,int key_len,
                        EVP_PKEY *pub_key);
 int            EVP_PKEY_type(int type);
+int            EVP_PKEY_id(const EVP_PKEY *pkey);
+int            EVP_PKEY_base_id(const EVP_PKEY *pkey);
 int            EVP_PKEY_bits(EVP_PKEY *pkey);
 int            EVP_PKEY_size(EVP_PKEY *pkey);
-int            EVP_PKEY_assign(EVP_PKEY *pkey,int type,char *key);
+int            EVP_PKEY_set_type(EVP_PKEY *pkey,int type);
+int            EVP_PKEY_set_type_str(EVP_PKEY *pkey, const char *str, int len);
+int            EVP_PKEY_assign(EVP_PKEY *pkey,int type,void *key);
+void *         EVP_PKEY_get0(EVP_PKEY *pkey);
 
 #ifndef OPENSSL_NO_RSA
 struct rsa_st;
@@ -899,6 +888,15 @@ int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b);
 
 int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b);
 
+int EVP_PKEY_print_public(BIO *out, const EVP_PKEY *pkey,
+                               int indent, ASN1_PCTX *pctx);
+int EVP_PKEY_print_private(BIO *out, const EVP_PKEY *pkey,
+                               int indent, ASN1_PCTX *pctx);
+int EVP_PKEY_print_params(BIO *out, const EVP_PKEY *pkey,
+                               int indent, ASN1_PCTX *pctx);
+
+int EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid);
+
 int EVP_CIPHER_type(const EVP_CIPHER *ctx);
 
 /* calls methods */
@@ -916,6 +914,10 @@ int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
 int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
                           const unsigned char *salt, int saltlen, int iter,
                           int keylen, unsigned char *out);
+int PKCS5_PBKDF2_HMAC(const char *pass, int passlen,
+                          const unsigned char *salt, int saltlen, int iter,
+                          const EVP_MD *digest,
+                     int keylen, unsigned char *out);
 int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
                         ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md,
                         int en_de);
@@ -924,27 +926,260 @@ void PKCS5_PBE_add(void);
 
 int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
             ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de);
+
+/* PBE type */
+
+/* Can appear as the outermost AlgorithmIdentifier */
+#define EVP_PBE_TYPE_OUTER     0x0
+/* Is an PRF type OID */
+#define EVP_PBE_TYPE_PRF       0x1
+
+int EVP_PBE_alg_add_type(int pbe_type, int pbe_nid, int cipher_nid, int md_nid,
+            EVP_PBE_KEYGEN *keygen);
 int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md,
                    EVP_PBE_KEYGEN *keygen);
+int EVP_PBE_find(int type, int pbe_nid,
+                       int *pcnid, int *pmnid, EVP_PBE_KEYGEN **pkeygen);
 void EVP_PBE_cleanup(void);
 
-#ifdef OPENSSL_FIPS
-#ifndef OPENSSL_NO_ENGINE
-void int_EVP_MD_set_engine_callbacks(
-       int (*eng_md_init)(ENGINE *impl),
-       int (*eng_md_fin)(ENGINE *impl),
-       int (*eng_md_evp)
-               (EVP_MD_CTX *ctx, const EVP_MD **ptype, ENGINE *impl));
-void int_EVP_MD_init_engine_callbacks(void);
-void int_EVP_CIPHER_set_engine_callbacks(
-       int (*eng_ciph_fin)(ENGINE *impl),
-       int (*eng_ciph_evp)
-               (EVP_CIPHER_CTX *ctx, const EVP_CIPHER **pciph, ENGINE *impl));
-void int_EVP_CIPHER_init_engine_callbacks(void);
-#endif
-#endif
+#define ASN1_PKEY_ALIAS                0x1
+#define ASN1_PKEY_DYNAMIC      0x2
+#define ASN1_PKEY_SIGPARAM_NULL        0x4
+
+#define ASN1_PKEY_CTRL_PKCS7_SIGN      0x1
+#define ASN1_PKEY_CTRL_PKCS7_ENCRYPT   0x2
+#define ASN1_PKEY_CTRL_DEFAULT_MD_NID  0x3
+#define ASN1_PKEY_CTRL_CMS_SIGN                0x5
+#define ASN1_PKEY_CTRL_CMS_ENVELOPE    0x7
+
+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 EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth);
+int EVP_PKEY_asn1_add_alias(int to, int from);
+int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *pkey_base_id, int *ppkey_flags,
+                               const char **pinfo, const char **ppem_str,
+                                       const EVP_PKEY_ASN1_METHOD *ameth);
+
+const EVP_PKEY_ASN1_METHOD* EVP_PKEY_get0_asn1(EVP_PKEY *pkey);
+EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags,
+                                       const char *pem_str, const char *info);
+void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst, 
+                       const EVP_PKEY_ASN1_METHOD *src);
+void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth);
+void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth,
+               int (*pub_decode)(EVP_PKEY *pk, X509_PUBKEY *pub),
+               int (*pub_encode)(X509_PUBKEY *pub, const EVP_PKEY *pk),
+               int (*pub_cmp)(const EVP_PKEY *a, const EVP_PKEY *b),
+               int (*pub_print)(BIO *out, const EVP_PKEY *pkey, int indent,
+                                                       ASN1_PCTX *pctx),
+               int (*pkey_size)(const EVP_PKEY *pk),
+               int (*pkey_bits)(const EVP_PKEY *pk));
+void EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth,
+               int (*priv_decode)(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf),
+               int (*priv_encode)(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk),
+               int (*priv_print)(BIO *out, const EVP_PKEY *pkey, int indent,
+                                                       ASN1_PCTX *pctx));
+void EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth,
+               int (*param_decode)(EVP_PKEY *pkey,
+                               const unsigned char **pder, int derlen),
+               int (*param_encode)(const EVP_PKEY *pkey, unsigned char **pder),
+               int (*param_missing)(const EVP_PKEY *pk),
+               int (*param_copy)(EVP_PKEY *to, const EVP_PKEY *from),
+               int (*param_cmp)(const EVP_PKEY *a, const EVP_PKEY *b),
+               int (*param_print)(BIO *out, const EVP_PKEY *pkey, int indent,
+                                                       ASN1_PCTX *pctx));
+
+void EVP_PKEY_asn1_set_free(EVP_PKEY_ASN1_METHOD *ameth,
+               void (*pkey_free)(EVP_PKEY *pkey));
+void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth,
+               int (*pkey_ctrl)(EVP_PKEY *pkey, int op,
+                                                       long arg1, void *arg2));
+
+
+#define EVP_PKEY_OP_UNDEFINED          0
+#define EVP_PKEY_OP_PARAMGEN           (1<<1)
+#define EVP_PKEY_OP_KEYGEN             (1<<2)
+#define EVP_PKEY_OP_SIGN               (1<<3)
+#define EVP_PKEY_OP_VERIFY             (1<<4)
+#define EVP_PKEY_OP_VERIFYRECOVER      (1<<5)
+#define EVP_PKEY_OP_SIGNCTX            (1<<6)
+#define EVP_PKEY_OP_VERIFYCTX          (1<<7)
+#define EVP_PKEY_OP_ENCRYPT            (1<<8)
+#define EVP_PKEY_OP_DECRYPT            (1<<9)
+#define EVP_PKEY_OP_DERIVE             (1<<10)
+
+#define EVP_PKEY_OP_TYPE_SIG   \
+       (EVP_PKEY_OP_SIGN | EVP_PKEY_OP_VERIFY | EVP_PKEY_OP_VERIFYRECOVER \
+               | EVP_PKEY_OP_SIGNCTX | EVP_PKEY_OP_VERIFYCTX)
+
+#define EVP_PKEY_OP_TYPE_CRYPT \
+       (EVP_PKEY_OP_ENCRYPT | EVP_PKEY_OP_DECRYPT)
+
+#define EVP_PKEY_OP_TYPE_NOGEN \
+       (EVP_PKEY_OP_SIG | EVP_PKEY_OP_CRYPT | EVP_PKEY_OP_DERIVE)
+
+#define EVP_PKEY_OP_TYPE_GEN \
+               (EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN)
+
+#define         EVP_PKEY_CTX_set_signature_md(ctx, md) \
+               EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_TYPE_SIG,  \
+                                       EVP_PKEY_CTRL_MD, 0, (void *)md)
+
+#define EVP_PKEY_CTRL_MD               1
+#define EVP_PKEY_CTRL_PEER_KEY         2
+
+#define EVP_PKEY_CTRL_PKCS7_ENCRYPT    3
+#define EVP_PKEY_CTRL_PKCS7_DECRYPT    4
+
+#define EVP_PKEY_CTRL_PKCS7_SIGN       5
+
+#define EVP_PKEY_CTRL_SET_MAC_KEY      6
+
+#define EVP_PKEY_CTRL_DIGESTINIT       7
+
+/* Used by GOST key encryption in TLS */
+#define EVP_PKEY_CTRL_SET_IV           8
+
+#define EVP_PKEY_CTRL_CMS_ENCRYPT      9
+#define EVP_PKEY_CTRL_CMS_DECRYPT      10
+#define EVP_PKEY_CTRL_CMS_SIGN         11
+
+#define EVP_PKEY_ALG_CTRL              0x1000
+
+
+#define EVP_PKEY_FLAG_AUTOARGLEN       2
+
+const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type);
+EVP_PKEY_METHOD* EVP_PKEY_meth_new(int id, int flags);
+void EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth);
+int EVP_PKEY_meth_add0(const EVP_PKEY_METHOD *pmeth);
+
+EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e);
+EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e);
+EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *ctx);
+void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx);
+
+int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,
+                               int cmd, int p1, void *p2);
+int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *type,
+                                               const char *value);
+
+int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx);
+void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX *ctx, int *dat, int datlen);
+
+EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e,
+                               unsigned char *key, int keylen);
+
+void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX *ctx, void *data);
+void *EVP_PKEY_CTX_get_data(EVP_PKEY_CTX *ctx);
+EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx);
+
+EVP_PKEY *EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX *ctx);
+
+void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data);
+void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx);
+
+int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx);
+int EVP_PKEY_sign(EVP_PKEY_CTX *ctx,
+                       unsigned char *sig, size_t *siglen,
+                       const unsigned char *tbs, size_t tbslen);
+int EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx);
+int EVP_PKEY_verify(EVP_PKEY_CTX *ctx,
+                       const unsigned char *sig, size_t siglen,
+                       const unsigned char *tbs, size_t tbslen);
+int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx);
+int EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx,
+                       unsigned char *rout, size_t *routlen,
+                       const unsigned char *sig, size_t siglen);
+int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx);
+int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx,
+                       unsigned char *out, size_t *outlen,
+                       const unsigned char *in, size_t inlen);
+int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx);
+int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx,
+                       unsigned char *out, size_t *outlen,
+                       const unsigned char *in, size_t inlen);
+
+int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx);
+int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer);
+int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen);
+
+typedef int EVP_PKEY_gen_cb(EVP_PKEY_CTX *ctx);
+
+int EVP_PKEY_paramgen_init(EVP_PKEY_CTX *ctx);
+int EVP_PKEY_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey);
+int EVP_PKEY_keygen_init(EVP_PKEY_CTX *ctx);
+int EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey);
+
+void EVP_PKEY_CTX_set_cb(EVP_PKEY_CTX *ctx, EVP_PKEY_gen_cb *cb);
+EVP_PKEY_gen_cb *EVP_PKEY_CTX_get_cb(EVP_PKEY_CTX *ctx);
+
+int EVP_PKEY_CTX_get_keygen_info(EVP_PKEY_CTX *ctx, int idx);
+
+void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD *pmeth,
+       int (*init)(EVP_PKEY_CTX *ctx));
+
+void EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD *pmeth,
+       int (*copy)(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src));
+
+void EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD *pmeth,
+       void (*cleanup)(EVP_PKEY_CTX *ctx));
+
+void EVP_PKEY_meth_set_paramgen(EVP_PKEY_METHOD *pmeth,
+       int (*paramgen_init)(EVP_PKEY_CTX *ctx),
+       int (*paramgen)(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey));
+
+void EVP_PKEY_meth_set_keygen(EVP_PKEY_METHOD *pmeth,
+       int (*keygen_init)(EVP_PKEY_CTX *ctx),
+       int (*keygen)(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey));
 
-void EVP_add_alg_module(void);
+void EVP_PKEY_meth_set_sign(EVP_PKEY_METHOD *pmeth,
+       int (*sign_init)(EVP_PKEY_CTX *ctx),
+       int (*sign)(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
+                                       const unsigned char *tbs, size_t tbslen));
+
+void EVP_PKEY_meth_set_verify(EVP_PKEY_METHOD *pmeth,
+       int (*verify_init)(EVP_PKEY_CTX *ctx),
+       int (*verify)(EVP_PKEY_CTX *ctx, const unsigned char *sig, size_t siglen,
+                                       const unsigned char *tbs, size_t tbslen));
+
+void EVP_PKEY_meth_set_verify_recover(EVP_PKEY_METHOD *pmeth,
+       int (*verify_recover_init)(EVP_PKEY_CTX *ctx),
+       int (*verify_recover)(EVP_PKEY_CTX *ctx,
+                                       unsigned char *sig, size_t *siglen,
+                                       const unsigned char *tbs, size_t tbslen));
+
+void EVP_PKEY_meth_set_signctx(EVP_PKEY_METHOD *pmeth,
+       int (*signctx_init)(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx),
+       int (*signctx)(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
+                                       EVP_MD_CTX *mctx));
+
+void EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD *pmeth,
+       int (*verifyctx_init)(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx),
+       int (*verifyctx)(EVP_PKEY_CTX *ctx, const unsigned char *sig,int siglen,
+                                       EVP_MD_CTX *mctx));
+
+void EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD *pmeth,
+       int (*encrypt_init)(EVP_PKEY_CTX *ctx),
+       int (*encryptfn)(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
+                                       const unsigned char *in, size_t inlen));
+
+void EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD *pmeth,
+       int (*decrypt_init)(EVP_PKEY_CTX *ctx),
+       int (*decrypt)(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
+                                       const unsigned char *in, size_t inlen));
+
+void EVP_PKEY_meth_set_derive(EVP_PKEY_METHOD *pmeth,
+       int (*derive_init)(EVP_PKEY_CTX *ctx),
+       int (*derive)(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen));
+
+void EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD *pmeth,
+       int (*ctrl)(EVP_PKEY_CTX *ctx, int type, int p1, void *p2),
+       int (*ctrl_str)(EVP_PKEY_CTX *ctx,
+                                       const char *type, const char *value));
 
 /* BEGIN ERROR CODES */
 /* The following lines are auto generated by the script mkerr.pl. Any changes
@@ -956,46 +1191,66 @@ void ERR_load_EVP_strings(void);
 
 /* Function codes. */
 #define EVP_F_AES_INIT_KEY                              133
-#define EVP_F_ALG_MODULE_INIT                           138
 #define EVP_F_CAMELLIA_INIT_KEY                                 159
 #define EVP_F_D2I_PKEY                                  100
-#define EVP_F_DO_EVP_ENC_ENGINE                                 140
-#define EVP_F_DO_EVP_ENC_ENGINE_FULL                    141
-#define EVP_F_DO_EVP_MD_ENGINE                          139
-#define EVP_F_DO_EVP_MD_ENGINE_FULL                     142
+#define EVP_F_DO_SIGVER_INIT                            161
 #define EVP_F_DSAPKEY2PKCS8                             134
 #define EVP_F_DSA_PKEY2PKCS8                            135
 #define EVP_F_ECDSA_PKEY2PKCS8                          129
 #define EVP_F_ECKEY_PKEY2PKCS8                          132
-#define EVP_F_EVP_CIPHERINIT                            137
 #define EVP_F_EVP_CIPHERINIT_EX                                 123
+#define EVP_F_EVP_CIPHER_CTX_COPY                       163
 #define EVP_F_EVP_CIPHER_CTX_CTRL                       124
 #define EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH             122
 #define EVP_F_EVP_DECRYPTFINAL_EX                       101
-#define EVP_F_EVP_DIGESTINIT                            136
 #define EVP_F_EVP_DIGESTINIT_EX                                 128
 #define EVP_F_EVP_ENCRYPTFINAL_EX                       127
 #define EVP_F_EVP_MD_CTX_COPY_EX                        110
+#define EVP_F_EVP_MD_SIZE                               162
 #define EVP_F_EVP_OPENINIT                              102
 #define EVP_F_EVP_PBE_ALG_ADD                           115
+#define EVP_F_EVP_PBE_ALG_ADD_TYPE                      160
 #define EVP_F_EVP_PBE_CIPHERINIT                        116
 #define EVP_F_EVP_PKCS82PKEY                            111
+#define EVP_F_EVP_PKCS82PKEY_BROKEN                     136
 #define EVP_F_EVP_PKEY2PKCS8_BROKEN                     113
 #define EVP_F_EVP_PKEY_COPY_PARAMETERS                  103
+#define EVP_F_EVP_PKEY_CTX_CTRL                                 137
+#define EVP_F_EVP_PKEY_CTX_CTRL_STR                     150
+#define EVP_F_EVP_PKEY_CTX_DUP                          156
 #define EVP_F_EVP_PKEY_DECRYPT                          104
+#define EVP_F_EVP_PKEY_DECRYPT_INIT                     138
+#define EVP_F_EVP_PKEY_DECRYPT_OLD                      151
+#define EVP_F_EVP_PKEY_DERIVE                           153
+#define EVP_F_EVP_PKEY_DERIVE_INIT                      154
+#define EVP_F_EVP_PKEY_DERIVE_SET_PEER                  155
 #define EVP_F_EVP_PKEY_ENCRYPT                          105
+#define EVP_F_EVP_PKEY_ENCRYPT_INIT                     139
+#define EVP_F_EVP_PKEY_ENCRYPT_OLD                      152
 #define EVP_F_EVP_PKEY_GET1_DH                          119
 #define EVP_F_EVP_PKEY_GET1_DSA                                 120
 #define EVP_F_EVP_PKEY_GET1_ECDSA                       130
 #define EVP_F_EVP_PKEY_GET1_EC_KEY                      131
 #define EVP_F_EVP_PKEY_GET1_RSA                                 121
+#define EVP_F_EVP_PKEY_KEYGEN                           146
+#define EVP_F_EVP_PKEY_KEYGEN_INIT                      147
 #define EVP_F_EVP_PKEY_NEW                              106
+#define EVP_F_EVP_PKEY_PARAMGEN                                 148
+#define EVP_F_EVP_PKEY_PARAMGEN_INIT                    149
+#define EVP_F_EVP_PKEY_SIGN                             140
+#define EVP_F_EVP_PKEY_SIGN_INIT                        141
+#define EVP_F_EVP_PKEY_VERIFY                           142
+#define EVP_F_EVP_PKEY_VERIFY_INIT                      143
+#define EVP_F_EVP_PKEY_VERIFY_RECOVER                   144
+#define EVP_F_EVP_PKEY_VERIFY_RECOVER_INIT              145
 #define EVP_F_EVP_RIJNDAEL                              126
 #define EVP_F_EVP_SIGNFINAL                             107
 #define EVP_F_EVP_VERIFYFINAL                           108
+#define EVP_F_INT_CTX_NEW                               157
 #define EVP_F_PKCS5_PBE_KEYIVGEN                        117
 #define EVP_F_PKCS5_V2_PBE_KEYIVGEN                     118
 #define EVP_F_PKCS8_SET_BROKEN                          112
+#define EVP_F_PKEY_SET_TYPE                             158
 #define EVP_F_RC2_MAGIC_TO_METH                                 109
 #define EVP_F_RC5_CTRL                                  125
 
@@ -1007,41 +1262,52 @@ void ERR_load_EVP_strings(void);
 #define EVP_R_BAD_KEY_LENGTH                            137
 #define EVP_R_BN_DECODE_ERROR                           112
 #define EVP_R_BN_PUBKEY_ERROR                           113
+#define EVP_R_BUFFER_TOO_SMALL                          155
 #define EVP_R_CAMELLIA_KEY_SETUP_FAILED                         157
 #define EVP_R_CIPHER_PARAMETER_ERROR                    122
+#define EVP_R_COMMAND_NOT_SUPPORTED                     147
 #define EVP_R_CTRL_NOT_IMPLEMENTED                      132
 #define EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED            133
 #define EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH                 138
 #define EVP_R_DECODE_ERROR                              114
 #define EVP_R_DIFFERENT_KEY_TYPES                       101
-#define EVP_R_DISABLED_FOR_FIPS                                 144
+#define EVP_R_DIFFERENT_PARAMETERS                      153
 #define EVP_R_ENCODE_ERROR                              115
-#define EVP_R_ERROR_LOADING_SECTION                     145
-#define EVP_R_ERROR_SETTING_FIPS_MODE                   146
 #define EVP_R_EVP_PBE_CIPHERINIT_ERROR                  119
 #define EVP_R_EXPECTING_AN_RSA_KEY                      127
 #define EVP_R_EXPECTING_A_DH_KEY                        128
 #define EVP_R_EXPECTING_A_DSA_KEY                       129
 #define EVP_R_EXPECTING_A_ECDSA_KEY                     141
 #define EVP_R_EXPECTING_A_EC_KEY                        142
-#define EVP_R_FIPS_MODE_NOT_SUPPORTED                   147
 #define EVP_R_INITIALIZATION_ERROR                      134
 #define EVP_R_INPUT_NOT_INITIALIZED                     111
-#define EVP_R_INVALID_FIPS_MODE                                 148
+#define EVP_R_INVALID_DIGEST                            152
 #define EVP_R_INVALID_KEY_LENGTH                        130
+#define EVP_R_INVALID_OPERATION                                 148
 #define EVP_R_IV_TOO_LARGE                              102
 #define EVP_R_KEYGEN_FAILURE                            120
+#define EVP_R_MESSAGE_DIGEST_IS_NULL                    159
+#define EVP_R_METHOD_NOT_SUPPORTED                      144
 #define EVP_R_MISSING_PARAMETERS                        103
 #define EVP_R_NO_CIPHER_SET                             131
+#define EVP_R_NO_DEFAULT_DIGEST                                 158
 #define EVP_R_NO_DIGEST_SET                             139
 #define EVP_R_NO_DSA_PARAMETERS                                 116
+#define EVP_R_NO_KEY_SET                                154
+#define EVP_R_NO_OPERATION_SET                          149
 #define EVP_R_NO_SIGN_FUNCTION_CONFIGURED               104
 #define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED             105
+#define EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE  150
+#define EVP_R_OPERATON_NOT_INITIALIZED                  151
 #define EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE                         117
+#define EVP_R_PRIVATE_KEY_DECODE_ERROR                  145
+#define EVP_R_PRIVATE_KEY_ENCODE_ERROR                  146
 #define EVP_R_PUBLIC_KEY_NOT_RSA                        106
-#define EVP_R_UNKNOWN_OPTION                            149
+#define EVP_R_UNKNOWN_CIPHER                            160
+#define EVP_R_UNKNOWN_DIGEST                            161
 #define EVP_R_UNKNOWN_PBE_ALGORITHM                     121
 #define EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS               135
+#define EVP_R_UNSUPPORTED_ALGORITHM                     156
 #define EVP_R_UNSUPPORTED_CIPHER                        107
 #define EVP_R_UNSUPPORTED_KEYLENGTH                     123
 #define EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION       124
@@ -1051,7 +1317,6 @@ void ERR_load_EVP_strings(void);
 #define EVP_R_UNSUPPORTED_SALT_TYPE                     126
 #define EVP_R_WRONG_FINAL_BLOCK_LENGTH                  109
 #define EVP_R_WRONG_PUBLIC_KEY_TYPE                     110
-#define EVP_R_SEED_KEY_SETUP_FAILED                     162
 
 #ifdef  __cplusplus
 }
index 30e0ca4..c268d25 100644 (file)
 #endif
 #include "evp_locl.h"
 
-#ifdef OPENSSL_FIPS
-       #define M_do_cipher(ctx, out, in, inl) \
-               EVP_Cipher(ctx,out,in,inl)
-#else
-       #define M_do_cipher(ctx, out, in, inl) \
-               ctx->cipher->do_cipher(ctx,out,in,inl)
-#endif
-
 const char EVP_version[]="EVP" OPENSSL_VERSION_PTEXT;
 
+void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx)
+       {
+       memset(ctx,0,sizeof(EVP_CIPHER_CTX));
+       /* ctx->cipher=NULL; */
+       }
+
 EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void)
        {
        EVP_CIPHER_CTX *ctx=OPENSSL_malloc(sizeof *ctx);
@@ -92,6 +90,145 @@ int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
        return EVP_CipherInit_ex(ctx,cipher,NULL,key,iv,enc);
        }
 
+int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl,
+            const unsigned char *key, const unsigned char *iv, int enc)
+       {
+       if (enc == -1)
+               enc = ctx->encrypt;
+       else
+               {
+               if (enc)
+                       enc = 1;
+               ctx->encrypt = enc;
+               }
+#ifndef OPENSSL_NO_ENGINE
+       /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts
+        * so this context may already have an ENGINE! Try to avoid releasing
+        * the previous handle, re-querying for an ENGINE, and having a
+        * reinitialisation, when it may all be unecessary. */
+       if (ctx->engine && ctx->cipher && (!cipher ||
+                       (cipher && (cipher->nid == ctx->cipher->nid))))
+               goto skip_to_init;
+#endif
+       if (cipher)
+               {
+               /* Ensure a context left lying around from last time is cleared
+                * (the previous check attempted to avoid this if the same
+                * ENGINE and EVP_CIPHER could be used). */
+               EVP_CIPHER_CTX_cleanup(ctx);
+
+               /* Restore encrypt field: it is zeroed by cleanup */
+               ctx->encrypt = enc;
+#ifndef OPENSSL_NO_ENGINE
+               if(impl)
+                       {
+                       if (!ENGINE_init(impl))
+                               {
+                               EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_INITIALIZATION_ERROR);
+                               return 0;
+                               }
+                       }
+               else
+                       /* Ask if an ENGINE is reserved for this job */
+                       impl = ENGINE_get_cipher_engine(cipher->nid);
+               if(impl)
+                       {
+                       /* There's an ENGINE for this job ... (apparently) */
+                       const EVP_CIPHER *c = ENGINE_get_cipher(impl, cipher->nid);
+                       if(!c)
+                               {
+                               /* One positive side-effect of US's export
+                                * control history, is that we should at least
+                                * be able to avoid using US mispellings of
+                                * "initialisation"? */
+                               EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_INITIALIZATION_ERROR);
+                               return 0;
+                               }
+                       /* We'll use the ENGINE's private cipher definition */
+                       cipher = c;
+                       /* Store the ENGINE functional reference so we know
+                        * 'cipher' came from an ENGINE and we need to release
+                        * it when done. */
+                       ctx->engine = impl;
+                       }
+               else
+                       ctx->engine = NULL;
+#endif
+
+               ctx->cipher=cipher;
+               if (ctx->cipher->ctx_size)
+                       {
+                       ctx->cipher_data=OPENSSL_malloc(ctx->cipher->ctx_size);
+                       if (!ctx->cipher_data)
+                               {
+                               EVPerr(EVP_F_EVP_CIPHERINIT_EX, ERR_R_MALLOC_FAILURE);
+                               return 0;
+                               }
+                       }
+               else
+                       {
+                       ctx->cipher_data = NULL;
+                       }
+               ctx->key_len = cipher->key_len;
+               ctx->flags = 0;
+               if(ctx->cipher->flags & EVP_CIPH_CTRL_INIT)
+                       {
+                       if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_INIT, 0, NULL))
+                               {
+                               EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_INITIALIZATION_ERROR);
+                               return 0;
+                               }
+                       }
+               }
+       else if(!ctx->cipher)
+               {
+               EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_NO_CIPHER_SET);
+               return 0;
+               }
+#ifndef OPENSSL_NO_ENGINE
+skip_to_init:
+#endif
+       /* we assume block size is a power of 2 in *cryptUpdate */
+       OPENSSL_assert(ctx->cipher->block_size == 1
+           || ctx->cipher->block_size == 8
+           || ctx->cipher->block_size == 16);
+
+       if(!(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_CUSTOM_IV)) {
+               switch(EVP_CIPHER_CTX_mode(ctx)) {
+
+                       case EVP_CIPH_STREAM_CIPHER:
+                       case EVP_CIPH_ECB_MODE:
+                       break;
+
+                       case EVP_CIPH_CFB_MODE:
+                       case EVP_CIPH_OFB_MODE:
+
+                       ctx->num = 0;
+                       /* fall-through */
+
+                       case EVP_CIPH_CBC_MODE:
+
+                       OPENSSL_assert(EVP_CIPHER_CTX_iv_length(ctx) <=
+                                       (int)sizeof(ctx->iv));
+                       if(iv) memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx));
+                       memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx));
+                       break;
+
+                       default:
+                       return 0;
+                       break;
+               }
+       }
+
+       if(key || (ctx->cipher->flags & EVP_CIPH_ALWAYS_CALL_INIT)) {
+               if(!ctx->cipher->init(ctx,key,iv,enc)) return 0;
+       }
+       ctx->buf_len=0;
+       ctx->final_used=0;
+       ctx->block_mask=ctx->cipher->block_size-1;
+       return 1;
+       }
+
 int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
             const unsigned char *in, int inl)
        {
@@ -151,7 +288,7 @@ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
 
        if(ctx->buf_len == 0 && (inl&(ctx->block_mask)) == 0)
                {
-               if(M_do_cipher(ctx,out,in,inl))
+               if(ctx->cipher->do_cipher(ctx,out,in,inl))
                        {
                        *outl=inl;
                        return 1;
@@ -178,7 +315,7 @@ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
                        {
                        j=bl-i;
                        memcpy(&(ctx->buf[i]),in,j);
-                       if(!M_do_cipher(ctx,out,ctx->buf,bl)) return 0;
+                       if(!ctx->cipher->do_cipher(ctx,out,ctx->buf,bl)) return 0;
                        inl-=j;
                        in+=j;
                        out+=bl;
@@ -191,7 +328,7 @@ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
        inl-=i;
        if (inl > 0)
                {
-               if(!M_do_cipher(ctx,out,in,inl)) return 0;
+               if(!ctx->cipher->do_cipher(ctx,out,in,inl)) return 0;
                *outl+=inl;
                }
 
@@ -235,7 +372,7 @@ int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
        n=b-bl;
        for (i=bl; i<b; i++)
                ctx->buf[i]=n;
-       ret=M_do_cipher(ctx,out,ctx->buf,b);
+       ret=ctx->cipher->do_cipher(ctx,out,ctx->buf,b);
 
 
        if(ret)
@@ -357,6 +494,28 @@ void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx)
                }
        }
 
+int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c)
+       {
+       if (c->cipher != NULL)
+               {
+               if(c->cipher->cleanup && !c->cipher->cleanup(c))
+                       return 0;
+               /* Cleanse cipher context data */
+               if (c->cipher_data)
+                       OPENSSL_cleanse(c->cipher_data, c->cipher->ctx_size);
+               }
+       if (c->cipher_data)
+               OPENSSL_free(c->cipher_data);
+#ifndef OPENSSL_NO_ENGINE
+       if (c->engine)
+               /* The EVP_CIPHER we used belongs to an ENGINE, release the
+                * functional reference we held for this reason. */
+               ENGINE_finish(c->engine);
+#endif
+       memset(c,0,sizeof(EVP_CIPHER_CTX));
+       return 1;
+       }
+
 int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, int keylen)
        {
        if(c->cipher->flags & EVP_CIPH_CUSTOM_KEY_LENGTH) 
@@ -378,6 +537,27 @@ int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *ctx, int pad)
        return 1;
        }
 
+int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
+{
+       int ret;
+       if(!ctx->cipher) {
+               EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_NO_CIPHER_SET);
+               return 0;
+       }
+
+       if(!ctx->cipher->ctrl) {
+               EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_CTRL_NOT_IMPLEMENTED);
+               return 0;
+       }
+
+       ret = ctx->cipher->ctrl(ctx, type, arg, ptr);
+       if(ret == -1) {
+               EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED);
+               return 0;
+       }
+       return ret;
+}
+
 int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key)
        {
        if (ctx->cipher->flags & EVP_CIPH_RAND_KEY)
@@ -387,54 +567,38 @@ int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key)
        return 1;
        }
 
-#ifndef OPENSSL_NO_ENGINE
-
-#ifdef OPENSSL_FIPS
-
-static int do_evp_enc_engine_full(EVP_CIPHER_CTX *ctx, const EVP_CIPHER **pcipher, ENGINE *impl)
+int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in)
        {
-       if(impl)
+       if ((in == NULL) || (in->cipher == NULL))
                {
-               if (!ENGINE_init(impl))
-                       {
-                       EVPerr(EVP_F_DO_EVP_ENC_ENGINE_FULL, EVP_R_INITIALIZATION_ERROR);
-                       return 0;
-                       }
+               EVPerr(EVP_F_EVP_CIPHER_CTX_COPY,EVP_R_INPUT_NOT_INITIALIZED);
+               return 0;
                }
-       else
-               /* Ask if an ENGINE is reserved for this job */
-               impl = ENGINE_get_cipher_engine((*pcipher)->nid);
-       if(impl)
+#ifndef OPENSSL_NO_ENGINE
+       /* Make sure it's safe to copy a cipher context using an ENGINE */
+       if (in->engine && !ENGINE_init(in->engine))
+               {
+               EVPerr(EVP_F_EVP_CIPHER_CTX_COPY,ERR_R_ENGINE_LIB);
+               return 0;
+               }
+#endif
+
+       EVP_CIPHER_CTX_cleanup(out);
+       memcpy(out,in,sizeof *out);
+
+       if (in->cipher_data && in->cipher->ctx_size)
                {
-               /* There's an ENGINE for this job ... (apparently) */
-               const EVP_CIPHER *c = ENGINE_get_cipher(impl, (*pcipher)->nid);
-               if(!c)
+               out->cipher_data=OPENSSL_malloc(in->cipher->ctx_size);
+               if (!out->cipher_data)
                        {
-                       /* One positive side-effect of US's export
-                        * control history, is that we should at least
-                        * be able to avoid using US mispellings of
-                        * "initialisation"? */
-                       EVPerr(EVP_F_DO_EVP_ENC_ENGINE_FULL, EVP_R_INITIALIZATION_ERROR);
+                       EVPerr(EVP_F_EVP_CIPHER_CTX_COPY,ERR_R_MALLOC_FAILURE);
                        return 0;
                        }
-               /* We'll use the ENGINE's private cipher definition */
-               *pcipher = c;
-               /* Store the ENGINE functional reference so we know
-                * 'cipher' came from an ENGINE and we need to release
-                * it when done. */
-               ctx->engine = impl;
+               memcpy(out->cipher_data,in->cipher_data,in->cipher->ctx_size);
                }
-       else
-               ctx->engine = NULL;
-       return 1;
-       }
 
-void int_EVP_CIPHER_init_engine_callbacks(void)
-       {
-       int_EVP_CIPHER_set_engine_callbacks(
-               ENGINE_finish, do_evp_enc_engine_full);
+       if (in->cipher->flags & EVP_CIPH_CUSTOM_COPY)
+               return in->cipher->ctrl((EVP_CIPHER_CTX *)in, EVP_CTRL_COPY, 0, out);
+       return 1;
        }
 
-#endif
-
-#endif
index b5b900d..d8bfec0 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/evp/evp_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2007 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2008 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 static ERR_STRING_DATA EVP_str_functs[]=
        {
 {ERR_FUNC(EVP_F_AES_INIT_KEY), "AES_INIT_KEY"},
-{ERR_FUNC(EVP_F_ALG_MODULE_INIT),      "ALG_MODULE_INIT"},
 {ERR_FUNC(EVP_F_CAMELLIA_INIT_KEY),    "CAMELLIA_INIT_KEY"},
 {ERR_FUNC(EVP_F_D2I_PKEY),     "D2I_PKEY"},
-{ERR_FUNC(EVP_F_DO_EVP_ENC_ENGINE),    "DO_EVP_ENC_ENGINE"},
-{ERR_FUNC(EVP_F_DO_EVP_ENC_ENGINE_FULL),       "DO_EVP_ENC_ENGINE_FULL"},
-{ERR_FUNC(EVP_F_DO_EVP_MD_ENGINE),     "DO_EVP_MD_ENGINE"},
-{ERR_FUNC(EVP_F_DO_EVP_MD_ENGINE_FULL),        "DO_EVP_MD_ENGINE_FULL"},
+{ERR_FUNC(EVP_F_DO_SIGVER_INIT),       "DO_SIGVER_INIT"},
 {ERR_FUNC(EVP_F_DSAPKEY2PKCS8),        "DSAPKEY2PKCS8"},
 {ERR_FUNC(EVP_F_DSA_PKEY2PKCS8),       "DSA_PKEY2PKCS8"},
 {ERR_FUNC(EVP_F_ECDSA_PKEY2PKCS8),     "ECDSA_PKEY2PKCS8"},
 {ERR_FUNC(EVP_F_ECKEY_PKEY2PKCS8),     "ECKEY_PKEY2PKCS8"},
-{ERR_FUNC(EVP_F_EVP_CIPHERINIT),       "EVP_CipherInit"},
 {ERR_FUNC(EVP_F_EVP_CIPHERINIT_EX),    "EVP_CipherInit_ex"},
+{ERR_FUNC(EVP_F_EVP_CIPHER_CTX_COPY),  "EVP_CIPHER_CTX_copy"},
 {ERR_FUNC(EVP_F_EVP_CIPHER_CTX_CTRL),  "EVP_CIPHER_CTX_ctrl"},
 {ERR_FUNC(EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH),        "EVP_CIPHER_CTX_set_key_length"},
 {ERR_FUNC(EVP_F_EVP_DECRYPTFINAL_EX),  "EVP_DecryptFinal_ex"},
-{ERR_FUNC(EVP_F_EVP_DIGESTINIT),       "EVP_DigestInit"},
 {ERR_FUNC(EVP_F_EVP_DIGESTINIT_EX),    "EVP_DigestInit_ex"},
 {ERR_FUNC(EVP_F_EVP_ENCRYPTFINAL_EX),  "EVP_EncryptFinal_ex"},
 {ERR_FUNC(EVP_F_EVP_MD_CTX_COPY_EX),   "EVP_MD_CTX_copy_ex"},
+{ERR_FUNC(EVP_F_EVP_MD_SIZE),  "EVP_MD_SIZE"},
 {ERR_FUNC(EVP_F_EVP_OPENINIT), "EVP_OpenInit"},
 {ERR_FUNC(EVP_F_EVP_PBE_ALG_ADD),      "EVP_PBE_alg_add"},
+{ERR_FUNC(EVP_F_EVP_PBE_ALG_ADD_TYPE), "EVP_PBE_alg_add_type"},
 {ERR_FUNC(EVP_F_EVP_PBE_CIPHERINIT),   "EVP_PBE_CipherInit"},
 {ERR_FUNC(EVP_F_EVP_PKCS82PKEY),       "EVP_PKCS82PKEY"},
+{ERR_FUNC(EVP_F_EVP_PKCS82PKEY_BROKEN),        "EVP_PKCS82PKEY_BROKEN"},
 {ERR_FUNC(EVP_F_EVP_PKEY2PKCS8_BROKEN),        "EVP_PKEY2PKCS8_broken"},
 {ERR_FUNC(EVP_F_EVP_PKEY_COPY_PARAMETERS),     "EVP_PKEY_copy_parameters"},
+{ERR_FUNC(EVP_F_EVP_PKEY_CTX_CTRL),    "EVP_PKEY_CTX_ctrl"},
+{ERR_FUNC(EVP_F_EVP_PKEY_CTX_CTRL_STR),        "EVP_PKEY_CTX_ctrl_str"},
+{ERR_FUNC(EVP_F_EVP_PKEY_CTX_DUP),     "EVP_PKEY_CTX_dup"},
 {ERR_FUNC(EVP_F_EVP_PKEY_DECRYPT),     "EVP_PKEY_decrypt"},
+{ERR_FUNC(EVP_F_EVP_PKEY_DECRYPT_INIT),        "EVP_PKEY_decrypt_init"},
+{ERR_FUNC(EVP_F_EVP_PKEY_DECRYPT_OLD), "EVP_PKEY_decrypt_old"},
+{ERR_FUNC(EVP_F_EVP_PKEY_DERIVE),      "EVP_PKEY_derive"},
+{ERR_FUNC(EVP_F_EVP_PKEY_DERIVE_INIT), "EVP_PKEY_derive_init"},
+{ERR_FUNC(EVP_F_EVP_PKEY_DERIVE_SET_PEER),     "EVP_PKEY_derive_set_peer"},
 {ERR_FUNC(EVP_F_EVP_PKEY_ENCRYPT),     "EVP_PKEY_encrypt"},
+{ERR_FUNC(EVP_F_EVP_PKEY_ENCRYPT_INIT),        "EVP_PKEY_encrypt_init"},
+{ERR_FUNC(EVP_F_EVP_PKEY_ENCRYPT_OLD), "EVP_PKEY_encrypt_old"},
 {ERR_FUNC(EVP_F_EVP_PKEY_GET1_DH),     "EVP_PKEY_get1_DH"},
 {ERR_FUNC(EVP_F_EVP_PKEY_GET1_DSA),    "EVP_PKEY_get1_DSA"},
 {ERR_FUNC(EVP_F_EVP_PKEY_GET1_ECDSA),  "EVP_PKEY_GET1_ECDSA"},
 {ERR_FUNC(EVP_F_EVP_PKEY_GET1_EC_KEY), "EVP_PKEY_get1_EC_KEY"},
 {ERR_FUNC(EVP_F_EVP_PKEY_GET1_RSA),    "EVP_PKEY_get1_RSA"},
+{ERR_FUNC(EVP_F_EVP_PKEY_KEYGEN),      "EVP_PKEY_keygen"},
+{ERR_FUNC(EVP_F_EVP_PKEY_KEYGEN_INIT), "EVP_PKEY_keygen_init"},
 {ERR_FUNC(EVP_F_EVP_PKEY_NEW), "EVP_PKEY_new"},
+{ERR_FUNC(EVP_F_EVP_PKEY_PARAMGEN),    "EVP_PKEY_paramgen"},
+{ERR_FUNC(EVP_F_EVP_PKEY_PARAMGEN_INIT),       "EVP_PKEY_paramgen_init"},
+{ERR_FUNC(EVP_F_EVP_PKEY_SIGN),        "EVP_PKEY_sign"},
+{ERR_FUNC(EVP_F_EVP_PKEY_SIGN_INIT),   "EVP_PKEY_sign_init"},
+{ERR_FUNC(EVP_F_EVP_PKEY_VERIFY),      "EVP_PKEY_verify"},
+{ERR_FUNC(EVP_F_EVP_PKEY_VERIFY_INIT), "EVP_PKEY_verify_init"},
+{ERR_FUNC(EVP_F_EVP_PKEY_VERIFY_RECOVER),      "EVP_PKEY_verify_recover"},
+{ERR_FUNC(EVP_F_EVP_PKEY_VERIFY_RECOVER_INIT), "EVP_PKEY_verify_recover_init"},
 {ERR_FUNC(EVP_F_EVP_RIJNDAEL), "EVP_RIJNDAEL"},
 {ERR_FUNC(EVP_F_EVP_SIGNFINAL),        "EVP_SignFinal"},
 {ERR_FUNC(EVP_F_EVP_VERIFYFINAL),      "EVP_VerifyFinal"},
+{ERR_FUNC(EVP_F_INT_CTX_NEW),  "INT_CTX_NEW"},
 {ERR_FUNC(EVP_F_PKCS5_PBE_KEYIVGEN),   "PKCS5_PBE_keyivgen"},
 {ERR_FUNC(EVP_F_PKCS5_V2_PBE_KEYIVGEN),        "PKCS5_v2_PBE_keyivgen"},
 {ERR_FUNC(EVP_F_PKCS8_SET_BROKEN),     "PKCS8_set_broken"},
+{ERR_FUNC(EVP_F_PKEY_SET_TYPE),        "PKEY_SET_TYPE"},
 {ERR_FUNC(EVP_F_RC2_MAGIC_TO_METH),    "RC2_MAGIC_TO_METH"},
 {ERR_FUNC(EVP_F_RC5_CTRL),     "RC5_CTRL"},
 {0,NULL}
@@ -125,42 +145,52 @@ static ERR_STRING_DATA EVP_str_reasons[]=
 {ERR_REASON(EVP_R_BAD_KEY_LENGTH)        ,"bad key length"},
 {ERR_REASON(EVP_R_BN_DECODE_ERROR)       ,"bn decode error"},
 {ERR_REASON(EVP_R_BN_PUBKEY_ERROR)       ,"bn pubkey error"},
+{ERR_REASON(EVP_R_BUFFER_TOO_SMALL)      ,"buffer too small"},
 {ERR_REASON(EVP_R_CAMELLIA_KEY_SETUP_FAILED),"camellia key setup failed"},
 {ERR_REASON(EVP_R_CIPHER_PARAMETER_ERROR),"cipher parameter error"},
+{ERR_REASON(EVP_R_COMMAND_NOT_SUPPORTED) ,"command not supported"},
 {ERR_REASON(EVP_R_CTRL_NOT_IMPLEMENTED)  ,"ctrl not implemented"},
 {ERR_REASON(EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED),"ctrl operation not implemented"},
 {ERR_REASON(EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH),"data not multiple of block length"},
 {ERR_REASON(EVP_R_DECODE_ERROR)          ,"decode error"},
 {ERR_REASON(EVP_R_DIFFERENT_KEY_TYPES)   ,"different key types"},
-{ERR_REASON(EVP_R_DISABLED_FOR_FIPS)     ,"disabled for fips"},
+{ERR_REASON(EVP_R_DIFFERENT_PARAMETERS)  ,"different parameters"},
 {ERR_REASON(EVP_R_ENCODE_ERROR)          ,"encode error"},
-{ERR_REASON(EVP_R_ERROR_LOADING_SECTION) ,"error loading section"},
-{ERR_REASON(EVP_R_ERROR_SETTING_FIPS_MODE),"error setting fips mode"},
 {ERR_REASON(EVP_R_EVP_PBE_CIPHERINIT_ERROR),"evp pbe cipherinit error"},
 {ERR_REASON(EVP_R_EXPECTING_AN_RSA_KEY)  ,"expecting an rsa key"},
 {ERR_REASON(EVP_R_EXPECTING_A_DH_KEY)    ,"expecting a dh key"},
 {ERR_REASON(EVP_R_EXPECTING_A_DSA_KEY)   ,"expecting a dsa key"},
 {ERR_REASON(EVP_R_EXPECTING_A_ECDSA_KEY) ,"expecting a ecdsa key"},
 {ERR_REASON(EVP_R_EXPECTING_A_EC_KEY)    ,"expecting a ec key"},
-{ERR_REASON(EVP_R_FIPS_MODE_NOT_SUPPORTED),"fips mode not supported"},
 {ERR_REASON(EVP_R_INITIALIZATION_ERROR)  ,"initialization error"},
 {ERR_REASON(EVP_R_INPUT_NOT_INITIALIZED) ,"input not initialized"},
-{ERR_REASON(EVP_R_INVALID_FIPS_MODE)     ,"invalid fips mode"},
+{ERR_REASON(EVP_R_INVALID_DIGEST)        ,"invalid digest"},
 {ERR_REASON(EVP_R_INVALID_KEY_LENGTH)    ,"invalid key length"},
+{ERR_REASON(EVP_R_INVALID_OPERATION)     ,"invalid operation"},
 {ERR_REASON(EVP_R_IV_TOO_LARGE)          ,"iv too large"},
 {ERR_REASON(EVP_R_KEYGEN_FAILURE)        ,"keygen failure"},
+{ERR_REASON(EVP_R_MESSAGE_DIGEST_IS_NULL),"message digest is null"},
+{ERR_REASON(EVP_R_METHOD_NOT_SUPPORTED)  ,"method not supported"},
 {ERR_REASON(EVP_R_MISSING_PARAMETERS)    ,"missing parameters"},
 {ERR_REASON(EVP_R_NO_CIPHER_SET)         ,"no cipher set"},
+{ERR_REASON(EVP_R_NO_DEFAULT_DIGEST)     ,"no default digest"},
 {ERR_REASON(EVP_R_NO_DIGEST_SET)         ,"no digest set"},
 {ERR_REASON(EVP_R_NO_DSA_PARAMETERS)     ,"no dsa parameters"},
+{ERR_REASON(EVP_R_NO_KEY_SET)            ,"no key set"},
+{ERR_REASON(EVP_R_NO_OPERATION_SET)      ,"no operation set"},
 {ERR_REASON(EVP_R_NO_SIGN_FUNCTION_CONFIGURED),"no sign function configured"},
 {ERR_REASON(EVP_R_NO_VERIFY_FUNCTION_CONFIGURED),"no verify function configured"},
+{ERR_REASON(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE),"operation not supported for this keytype"},
+{ERR_REASON(EVP_R_OPERATON_NOT_INITIALIZED),"operaton not initialized"},
 {ERR_REASON(EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE),"pkcs8 unknown broken type"},
+{ERR_REASON(EVP_R_PRIVATE_KEY_DECODE_ERROR),"private key decode error"},
+{ERR_REASON(EVP_R_PRIVATE_KEY_ENCODE_ERROR),"private key encode error"},
 {ERR_REASON(EVP_R_PUBLIC_KEY_NOT_RSA)    ,"public key not rsa"},
-{ERR_REASON(EVP_R_SEED_KEY_SETUP_FAILED) ,"seed key setup failed"},
-{ERR_REASON(EVP_R_UNKNOWN_OPTION)        ,"unknown option"},
+{ERR_REASON(EVP_R_UNKNOWN_CIPHER)        ,"unknown cipher"},
+{ERR_REASON(EVP_R_UNKNOWN_DIGEST)        ,"unknown digest"},
 {ERR_REASON(EVP_R_UNKNOWN_PBE_ALGORITHM) ,"unknown pbe algorithm"},
 {ERR_REASON(EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS),"unsuported number of rounds"},
+{ERR_REASON(EVP_R_UNSUPPORTED_ALGORITHM) ,"unsupported algorithm"},
 {ERR_REASON(EVP_R_UNSUPPORTED_CIPHER)    ,"unsupported cipher"},
 {ERR_REASON(EVP_R_UNSUPPORTED_KEYLENGTH) ,"unsupported keylength"},
 {ERR_REASON(EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION),"unsupported key derivation function"},
index 361ea69..839d6a3 100644 (file)
@@ -90,6 +90,11 @@ char *EVP_get_pw_prompt(void)
  * this function will fail */
 int EVP_read_pw_string(char *buf, int len, const char *prompt, int verify)
        {
+       return EVP_read_pw_string_min(buf, 0, len, prompt, verify);
+       }
+
+int EVP_read_pw_string_min(char *buf, int min, int len, const char *prompt, int verify)
+       {
        int ret;
        char buff[BUFSIZ];
        UI *ui;
@@ -97,10 +102,10 @@ int EVP_read_pw_string(char *buf, int len, const char *prompt, int verify)
        if ((prompt == NULL) && (prompt_string[0] != '\0'))
                prompt=prompt_string;
        ui = UI_new();
-       UI_add_input_string(ui,prompt,0,buf,0,(len>=BUFSIZ)?BUFSIZ-1:len);
+       UI_add_input_string(ui,prompt,0,buf,min,(len>=BUFSIZ)?BUFSIZ-1:len);
        if (verify)
                UI_add_verify_string(ui,prompt,0,
-                       buff,0,(len>=BUFSIZ)?BUFSIZ-1:len,buf);
+                       buff,min,(len>=BUFSIZ)?BUFSIZ-1:len,buf);
        ret = UI_process(ui);
        UI_free(ui);
        OPENSSL_cleanse(buff,BUFSIZ);
index 9c20061..40951a0 100644 (file)
@@ -67,8 +67,6 @@ int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
 
        if (c->cipher->set_asn1_parameters != NULL)
                ret=c->cipher->set_asn1_parameters(c,type);
-       else if (c->cipher->flags & EVP_CIPH_FLAG_DEFAULT_ASN1)
-               ret=EVP_CIPHER_set_asn1_iv(c, type);
        else
                ret=-1;
        return(ret);
@@ -80,8 +78,6 @@ int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
 
        if (c->cipher->get_asn1_parameters != NULL)
                ret=c->cipher->get_asn1_parameters(c,type);
-       else if (c->cipher->flags & EVP_CIPH_FLAG_DEFAULT_ASN1)
-               ret=EVP_CIPHER_get_asn1_iv(c, type);
        else
                ret=-1;
        return(ret);
@@ -188,6 +184,11 @@ int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx)
        return ctx->cipher->block_size;
        }
 
+int EVP_Cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl)
+       {
+       return ctx->cipher->do_cipher(ctx,out,in,inl);
+       }
+
 const EVP_CIPHER *EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *ctx)
        {
        return ctx->cipher;
@@ -198,6 +199,11 @@ unsigned long EVP_CIPHER_flags(const EVP_CIPHER *cipher)
        return cipher->flags;
        }
 
+unsigned long EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *ctx)
+       {
+       return ctx->cipher->flags;
+       }
+
 void *EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx)
        {
        return ctx->app_data;
@@ -213,6 +219,11 @@ int EVP_CIPHER_iv_length(const EVP_CIPHER *cipher)
        return cipher->iv_len;
        }
 
+int EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx)
+       {
+       return ctx->cipher->iv_len;
+       }
+
 int EVP_CIPHER_key_length(const EVP_CIPHER *cipher)
        {
        return cipher->key_len;
@@ -223,6 +234,11 @@ int EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx)
        return ctx->key_len;
        }
 
+int EVP_CIPHER_nid(const EVP_CIPHER *cipher)
+       {
+       return cipher->nid;
+       }
+
 int EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx)
        {
        return ctx->cipher->nid;
@@ -245,11 +261,23 @@ int EVP_MD_pkey_type(const EVP_MD *md)
 
 int EVP_MD_size(const EVP_MD *md)
        {
+       if (!md)
+               {
+               EVPerr(EVP_F_EVP_MD_SIZE, EVP_R_MESSAGE_DIGEST_IS_NULL);
+               return -1;
+               }
        return md->md_size;
        }
 
-const EVP_MD * EVP_MD_CTX_md(const EVP_MD_CTX *ctx)
+unsigned long EVP_MD_flags(const EVP_MD *md)
+       {
+       return md->flags;
+       }
+
+const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx)
        {
+       if (!ctx)
+               return NULL;
        return ctx->digest;
        }
 
index ef6c432..292d74c 100644 (file)
 /* Wrapper functions for each cipher mode */
 
 #define BLOCK_CIPHER_ecb_loop() \
-       unsigned int i, bl; \
+       size_t i, bl; \
        bl = ctx->cipher->block_size;\
        if(inl < bl) return 1;\
        inl -= bl; \
        for(i=0; i <= inl; i+=bl) 
 
 #define BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \
-static int cname##_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
+static int cname##_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \
 {\
        BLOCK_CIPHER_ecb_loop() \
                cprefix##_ecb_encrypt(in + i, out + i, &((kstruct *)ctx->cipher_data)->ksched, ctx->encrypt);\
        return 1;\
 }
 
+#define EVP_MAXCHUNK ((size_t)1<<(sizeof(long)*8-2))
+
 #define BLOCK_CIPHER_func_ofb(cname, cprefix, cbits, kstruct, ksched) \
-static int cname##_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
+static int cname##_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \
 {\
-       cprefix##_ofb##cbits##_encrypt(in, out, (long)inl, &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, &ctx->num);\
+       while(inl>=EVP_MAXCHUNK)\
+           {\
+           cprefix##_ofb##cbits##_encrypt(in, out, (long)EVP_MAXCHUNK, &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, &ctx->num);\
+           inl-=EVP_MAXCHUNK;\
+           in +=EVP_MAXCHUNK;\
+           out+=EVP_MAXCHUNK;\
+           }\
+       if (inl)\
+           cprefix##_ofb##cbits##_encrypt(in, out, (long)inl, &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, &ctx->num);\
        return 1;\
 }
 
 #define BLOCK_CIPHER_func_cbc(cname, cprefix, kstruct, ksched) \
-static int cname##_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
+static int cname##_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \
 {\
-       cprefix##_cbc_encrypt(in, out, (long)inl, &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, ctx->encrypt);\
+       while(inl>=EVP_MAXCHUNK) \
+           {\
+           cprefix##_cbc_encrypt(in, out, (long)EVP_MAXCHUNK, &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, ctx->encrypt);\
+           inl-=EVP_MAXCHUNK;\
+           in +=EVP_MAXCHUNK;\
+           out+=EVP_MAXCHUNK;\
+           }\
+       if (inl)\
+           cprefix##_cbc_encrypt(in, out, (long)inl, &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, ctx->encrypt);\
        return 1;\
 }
 
 #define BLOCK_CIPHER_func_cfb(cname, cprefix, cbits, kstruct, ksched) \
-static int cname##_cfb##cbits##_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
+static int cname##_cfb##cbits##_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \
 {\
-       cprefix##_cfb##cbits##_encrypt(in, out, (long)((cbits==1) && !(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS) ?inl*8:inl), &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, &ctx->num, ctx->encrypt);\
+       size_t chunk=EVP_MAXCHUNK;\
+       if (cbits==1)  chunk>>=3;\
+       if (inl<chunk) chunk=inl;\
+       while(inl && inl>=chunk)\
+           {\
+            cprefix##_cfb##cbits##_encrypt(in, out, (long)((cbits==1) && !(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS) ?inl*8:inl), &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, &ctx->num, ctx->encrypt);\
+           inl-=chunk;\
+           in +=chunk;\
+           out+=chunk;\
+           if(inl<chunk) chunk=inl;\
+           }\
        return 1;\
 }
 
@@ -226,27 +254,92 @@ const EVP_CIPHER *EVP_##cname##_ecb(void) { return &cname##_ecb; }
 
 #define EVP_C_DATA(kstruct, ctx)       ((kstruct *)(ctx)->cipher_data)
 
-#define IMPLEMENT_CFBR(cipher,cprefix,kstruct,ksched,keysize,cbits,iv_len,fl) \
+#define IMPLEMENT_CFBR(cipher,cprefix,kstruct,ksched,keysize,cbits,iv_len) \
        BLOCK_CIPHER_func_cfb(cipher##_##keysize,cprefix,cbits,kstruct,ksched) \
        BLOCK_CIPHER_def_cfb(cipher##_##keysize,kstruct, \
                             NID_##cipher##_##keysize, keysize/8, iv_len, cbits, \
-                            (fl)|EVP_CIPH_FLAG_DEFAULT_ASN1, \
-                            cipher##_init_key, NULL, NULL, NULL, NULL)
-
-#ifdef OPENSSL_FIPS
-#define RC2_set_key    private_RC2_set_key
-#define RC4_set_key    private_RC4_set_key
-#define CAST_set_key   private_CAST_set_key
-#define RC5_32_set_key private_RC5_32_set_key
-#define BF_set_key     private_BF_set_key
-#define Camellia_set_key private_Camellia_set_key
-#define idea_set_encrypt_key private_idea_set_encrypt_key
-
-#define MD5_Init       private_MD5_Init
-#define MD4_Init       private_MD4_Init
-#define MD2_Init       private_MD2_Init
-#define MDC2_Init      private_MDC2_Init
-#define SHA_Init       private_SHA_Init
-
-#endif
+                            0, cipher##_init_key, NULL, \
+                            EVP_CIPHER_set_asn1_iv, \
+                            EVP_CIPHER_get_asn1_iv, \
+                            NULL)
+
+struct evp_pkey_ctx_st
+       {
+       /* Method associated with this operation */
+       const EVP_PKEY_METHOD *pmeth;
+       /* Engine that implements this method or NULL if builtin */
+       ENGINE *engine;
+       /* Key: may be NULL */
+       EVP_PKEY *pkey;
+       /* Peer key for key agreement, may be NULL */
+       EVP_PKEY *peerkey;
+       /* Actual operation */
+       int operation;
+       /* Algorithm specific data */
+       void *data;
+       /* Application specific data */
+       void *app_data;
+       /* Keygen callback */
+       EVP_PKEY_gen_cb *pkey_gencb;
+       /* implementation specific keygen data */
+       int *keygen_info;
+       int keygen_info_count;
+       } /* EVP_PKEY_CTX */;
+
+#define EVP_PKEY_FLAG_DYNAMIC  1
+
+struct evp_pkey_method_st
+       {
+       int pkey_id;
+       int flags;
+
+       int (*init)(EVP_PKEY_CTX *ctx);
+       int (*copy)(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src);
+       void (*cleanup)(EVP_PKEY_CTX *ctx);
+
+       int (*paramgen_init)(EVP_PKEY_CTX *ctx);
+       int (*paramgen)(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey);
+
+       int (*keygen_init)(EVP_PKEY_CTX *ctx);
+       int (*keygen)(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey);
+
+       int (*sign_init)(EVP_PKEY_CTX *ctx);
+       int (*sign)(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
+                               const unsigned char *tbs, size_t tbslen);
+
+       int (*verify_init)(EVP_PKEY_CTX *ctx);
+       int (*verify)(EVP_PKEY_CTX *ctx,
+                               const unsigned char *sig, size_t siglen,
+                               const unsigned char *tbs, size_t tbslen);
+
+       int (*verify_recover_init)(EVP_PKEY_CTX *ctx);
+       int (*verify_recover)(EVP_PKEY_CTX *ctx,
+                               unsigned char *rout, size_t *routlen,
+                               const unsigned char *sig, size_t siglen);
+
+       int (*signctx_init)(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx);
+       int (*signctx)(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
+                                       EVP_MD_CTX *mctx);
+
+       int (*verifyctx_init)(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx);
+       int (*verifyctx)(EVP_PKEY_CTX *ctx, const unsigned char *sig,int siglen,
+                                       EVP_MD_CTX *mctx);
+
+       int (*encrypt_init)(EVP_PKEY_CTX *ctx);
+       int (*encrypt)(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
+                                       const unsigned char *in, size_t inlen);
+
+       int (*decrypt_init)(EVP_PKEY_CTX *ctx);
+       int (*decrypt)(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
+                                       const unsigned char *in, size_t inlen);
+
+       int (*derive_init)(EVP_PKEY_CTX *ctx);
+       int (*derive)(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen);
+
+       int (*ctrl)(EVP_PKEY_CTX *ctx, int type, int p1, void *p2);
+       int (*ctrl_str)(EVP_PKEY_CTX *ctx, const char *type, const char *value);
+
+
+       } /* EVP_PKEY_METHOD */;
 
+void evp_pkey_set_cb_translate(BN_GENCB *cb, EVP_PKEY_CTX *ctx);
index 766ea42..c9d932d 100644 (file)
@@ -3,7 +3,7 @@
  * project 1999.
  */
 /* ====================================================================
- * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include <stdio.h>
 #include "cryptlib.h"
 #include <openssl/evp.h>
+#include <openssl/pkcs12.h>
 #include <openssl/x509.h>
 
 /* Password based encryption (PBE) functions */
 
-static STACK *pbe_algs;
+DECLARE_STACK_OF(EVP_PBE_CTL)
+static STACK_OF(EVP_PBE_CTL) *pbe_algs;
 
 /* Setup a cipher context from a PBE algorithm */
 
-typedef struct {
-int pbe_nid;
-const EVP_CIPHER *cipher;
-const EVP_MD *md;
-EVP_PBE_KEYGEN *keygen;
-} EVP_PBE_CTL;
+typedef struct
+       {
+       int pbe_type;
+       int pbe_nid;
+       int cipher_nid;
+       int md_nid;
+       EVP_PBE_KEYGEN *keygen;
+       } EVP_PBE_CTL;
 
-int EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
-            ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de)
-{
+static const EVP_PBE_CTL builtin_pbe[] = 
+       {
+       {EVP_PBE_TYPE_OUTER, NID_pbeWithMD2AndDES_CBC,
+                       NID_des_cbc, NID_md2, PKCS5_PBE_keyivgen},
+       {EVP_PBE_TYPE_OUTER, NID_pbeWithMD5AndDES_CBC,
+                       NID_des_cbc, NID_md5, PKCS5_PBE_keyivgen},
+       {EVP_PBE_TYPE_OUTER, NID_pbeWithSHA1AndRC2_CBC,
+                       NID_rc2_64_cbc, NID_sha1, PKCS5_PBE_keyivgen},
 
-       EVP_PBE_CTL *pbetmp, pbelu;
-       int i;
-       pbelu.pbe_nid = OBJ_obj2nid(pbe_obj);
-       if (pbelu.pbe_nid != NID_undef) i = sk_find(pbe_algs, (char *)&pbelu);
-       else i = -1;
+       {EVP_PBE_TYPE_OUTER, NID_pbe_WithSHA1And128BitRC4,
+                       NID_rc4, NID_sha1, PKCS12_PBE_keyivgen},
+       {EVP_PBE_TYPE_OUTER, NID_pbe_WithSHA1And40BitRC4,
+                       NID_rc4_40, NID_sha1, PKCS12_PBE_keyivgen},
+       {EVP_PBE_TYPE_OUTER, NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
+                       NID_des_ede3_cbc, NID_sha1, PKCS12_PBE_keyivgen},
+       {EVP_PBE_TYPE_OUTER, NID_pbe_WithSHA1And2_Key_TripleDES_CBC, 
+                       NID_des_ede_cbc, NID_sha1, PKCS12_PBE_keyivgen},
+       {EVP_PBE_TYPE_OUTER, NID_pbe_WithSHA1And128BitRC2_CBC,
+                       NID_rc2_cbc, NID_sha1, PKCS12_PBE_keyivgen},
+       {EVP_PBE_TYPE_OUTER, NID_pbe_WithSHA1And40BitRC2_CBC,
+                       NID_rc2_40_cbc, NID_sha1, PKCS12_PBE_keyivgen},
+
+#ifndef OPENSSL_NO_HMAC
+       {EVP_PBE_TYPE_OUTER, NID_pbes2, -1, -1, PKCS5_v2_PBE_keyivgen},
+#endif
+       {EVP_PBE_TYPE_OUTER, NID_pbeWithMD2AndRC2_CBC,
+                       NID_rc2_64_cbc, NID_md2, PKCS5_PBE_keyivgen},
+       {EVP_PBE_TYPE_OUTER, NID_pbeWithMD5AndRC2_CBC,
+                       NID_rc2_64_cbc, NID_md5, PKCS5_PBE_keyivgen},
+       {EVP_PBE_TYPE_OUTER, NID_pbeWithSHA1AndDES_CBC,
+                       NID_des_cbc, NID_sha1, PKCS5_PBE_keyivgen},
+
+
+       {EVP_PBE_TYPE_PRF, NID_hmacWithSHA1, -1, NID_sha1, 0},
+       {EVP_PBE_TYPE_PRF, NID_hmacWithMD5, -1, NID_md5, 0},
+       {EVP_PBE_TYPE_PRF, NID_hmacWithSHA224, -1, NID_sha224, 0},
+       {EVP_PBE_TYPE_PRF, NID_hmacWithSHA256, -1, NID_sha256, 0},
+       {EVP_PBE_TYPE_PRF, NID_hmacWithSHA384, -1, NID_sha384, 0},
+       {EVP_PBE_TYPE_PRF, NID_hmacWithSHA512, -1, NID_sha512, 0},
+       {EVP_PBE_TYPE_PRF, NID_id_HMACGostR3411_94, -1, NID_id_GostR3411_94, 0},
+       };
+
+#ifdef TEST
+int main(int argc, char **argv)
+       {
+       int i, nid_md, nid_cipher;
+       EVP_PBE_CTL *tpbe, *tpbe2;
+       /*OpenSSL_add_all_algorithms();*/
+
+       for (i = 0; i < sizeof(builtin_pbe)/sizeof(EVP_PBE_CTL); i++)
+               {
+               tpbe = builtin_pbe + i;
+               fprintf(stderr, "%d %d %s ", tpbe->pbe_type, tpbe->pbe_nid,
+                                               OBJ_nid2sn(tpbe->pbe_nid));
+               if (EVP_PBE_find(tpbe->pbe_type, tpbe->pbe_nid,
+                                       &nid_cipher ,&nid_md,0))
+                       fprintf(stderr, "Found %s %s\n",
+                                       OBJ_nid2sn(nid_cipher),
+                                       OBJ_nid2sn(nid_md));
+               else
+                       fprintf(stderr, "Find ERROR!!\n");
+               }
+
+       return 0;
+       }
+#endif
+               
+
+
+int EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
+                      ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de)
+       {
+       const EVP_CIPHER *cipher;
+       const EVP_MD *md;
+       int cipher_nid, md_nid;
+       EVP_PBE_KEYGEN *keygen;
 
-       if (i == -1) {
+       if (!EVP_PBE_find(EVP_PBE_TYPE_OUTER, OBJ_obj2nid(pbe_obj),
+                                       &cipher_nid, &md_nid, &keygen))
+               {
                char obj_tmp[80];
                EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_UNKNOWN_PBE_ALGORITHM);
                if (!pbe_obj) BUF_strlcpy (obj_tmp, "NULL", sizeof obj_tmp);
                else i2t_ASN1_OBJECT(obj_tmp, sizeof obj_tmp, pbe_obj);
                ERR_add_error_data(2, "TYPE=", obj_tmp);
                return 0;
-       }
-       if(!pass) passlen = 0;
-       else if (passlen == -1) passlen = strlen(pass);
-       pbetmp = (EVP_PBE_CTL *)sk_value (pbe_algs, i);
-       i = (*pbetmp->keygen)(ctx, pass, passlen, param, pbetmp->cipher,
-                                                pbetmp->md, en_de);
-       if (!i) {
-               EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_KEYGEN_FAILURE);
-               return 0;
-       }
-       return 1;       
-}
-
-static int pbe_cmp(const char * const *a, const char * const *b)
-{
-       const EVP_PBE_CTL * const *pbe1 = (const EVP_PBE_CTL * const *) a,
-                       * const *pbe2 = (const EVP_PBE_CTL * const *)b;
-       return ((*pbe1)->pbe_nid - (*pbe2)->pbe_nid);
-}
+               }
 
-/* Add a PBE algorithm */
+       if(!pass)
+               passlen = 0;
+       else if (passlen == -1)
+               passlen = strlen(pass);
 
-int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md,
-            EVP_PBE_KEYGEN *keygen)
-{
-       EVP_PBE_CTL *pbe_tmp = NULL, pbelu;
-       int i;
-       if (!pbe_algs)
+       if (cipher_nid == -1)
+               cipher = NULL;
+       else
                {
-               pbe_algs = sk_new(pbe_cmp);
-               if (!pbe_algs)
+               cipher = EVP_get_cipherbynid(cipher_nid);
+               if (!cipher)
                        {
-                       EVPerr(EVP_F_EVP_PBE_ALG_ADD,ERR_R_MALLOC_FAILURE);
+                       EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_UNKNOWN_CIPHER);
                        return 0;
                        }
                }
+
+       if (md_nid == -1)
+               md = NULL;
        else
                {
-               /* Check if already present */
-               pbelu.pbe_nid = nid;
-               i = sk_find(pbe_algs, (char *)&pbelu);
-               if (i >= 0)
+               md = EVP_get_digestbynid(md_nid);
+               if (!md)
                        {
-                       pbe_tmp = (EVP_PBE_CTL *)sk_value(pbe_algs, i);
-                       /* If everything identical leave alone */
-                       if (pbe_tmp->cipher == cipher
-                               && pbe_tmp->md == md
-                               && pbe_tmp->keygen == keygen)
-                               return 1;
+                       EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_UNKNOWN_DIGEST);
+                       return 0;
                        }
                }
 
-       if (!pbe_tmp)
+       if (!keygen(ctx, pass, passlen, param, cipher, md, en_de))
                {
-               pbe_tmp = OPENSSL_malloc (sizeof(EVP_PBE_CTL));
-               if (!pbe_tmp)
-                       {
-                       EVPerr(EVP_F_EVP_PBE_ALG_ADD,ERR_R_MALLOC_FAILURE);
-                       return 0;
-                       }
-               /* If adding a new PBE, set nid, append and sort */
-               pbe_tmp->pbe_nid = nid;
-               sk_push (pbe_algs, (char *)pbe_tmp);
-               sk_sort(pbe_algs);
+               EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_KEYGEN_FAILURE);
+               return 0;
                }
-               
-       pbe_tmp->cipher = cipher;
-       pbe_tmp->md = md;
+       return 1;       
+}
+
+DECLARE_OBJ_BSEARCH_CMP_FN(EVP_PBE_CTL, EVP_PBE_CTL, pbe2);
+
+static int pbe2_cmp(const EVP_PBE_CTL *pbe1, const EVP_PBE_CTL *pbe2)
+       {
+       int ret = pbe1->pbe_type - pbe2->pbe_type;
+       if (ret)
+               return ret;
+       else
+               return pbe1->pbe_nid - pbe2->pbe_nid;
+       }
+
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(EVP_PBE_CTL, EVP_PBE_CTL, pbe2);
+
+static int pbe_cmp(const EVP_PBE_CTL * const *a, const EVP_PBE_CTL * const *b)
+       {
+       int ret = (*a)->pbe_type - (*b)->pbe_type;
+       if (ret)
+               return ret;
+       else
+               return (*a)->pbe_nid - (*b)->pbe_nid;
+       }
+
+/* Add a PBE algorithm */
+
+int EVP_PBE_alg_add_type(int pbe_type, int pbe_nid, int cipher_nid, int md_nid,
+                        EVP_PBE_KEYGEN *keygen)
+       {
+       EVP_PBE_CTL *pbe_tmp;
+       if (!pbe_algs)
+               pbe_algs = sk_EVP_PBE_CTL_new(pbe_cmp);
+       if (!(pbe_tmp = (EVP_PBE_CTL*) OPENSSL_malloc (sizeof(EVP_PBE_CTL))))
+               {
+               EVPerr(EVP_F_EVP_PBE_ALG_ADD_TYPE,ERR_R_MALLOC_FAILURE);
+               return 0;
+               }
+       pbe_tmp->pbe_type = pbe_type;
+       pbe_tmp->pbe_nid = pbe_nid;
+       pbe_tmp->cipher_nid = cipher_nid;
+       pbe_tmp->md_nid = md_nid;
        pbe_tmp->keygen = keygen;
+
+
+       sk_EVP_PBE_CTL_push (pbe_algs, pbe_tmp);
        return 1;
-}
+       }
+
+int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md,
+                   EVP_PBE_KEYGEN *keygen)
+       {
+       int cipher_nid, md_nid;
+       if (cipher)
+               cipher_nid = EVP_CIPHER_type(cipher);
+       else
+               cipher_nid = -1;
+       if (md)
+               md_nid = EVP_MD_type(md);
+       else
+               md_nid = -1;
+
+       return EVP_PBE_alg_add_type(EVP_PBE_TYPE_OUTER, nid,
+                                       cipher_nid, md_nid, keygen);
+       }
+
+int EVP_PBE_find(int type, int pbe_nid,
+                int *pcnid, int *pmnid, EVP_PBE_KEYGEN **pkeygen)
+       {
+       EVP_PBE_CTL *pbetmp = NULL, pbelu;
+       int i;
+       if (pbe_nid == NID_undef)
+               return 0;
+
+       pbelu.pbe_type = type;
+       pbelu.pbe_nid = pbe_nid;
+
+       if (pbe_algs)
+               {
+               i = sk_EVP_PBE_CTL_find(pbe_algs, &pbelu);
+               if (i != -1)
+                       pbetmp = sk_EVP_PBE_CTL_value (pbe_algs, i);
+               }
+       if (pbetmp == NULL)
+               {
+               pbetmp = OBJ_bsearch_pbe2(&pbelu, builtin_pbe,
+                                    sizeof(builtin_pbe)/sizeof(EVP_PBE_CTL));
+               }
+       if (pbetmp == NULL)
+               return 0;
+       if (pcnid)
+               *pcnid = pbetmp->cipher_nid;
+       if (pmnid)
+               *pmnid = pbetmp->md_nid;
+       if (pkeygen)
+               *pkeygen = pbetmp->keygen;
+       return 1;
+       }
+
+static void free_evp_pbe_ctl(EVP_PBE_CTL *pbe)
+        {
+        OPENSSL_freeFunc(pbe);
+        }
 
 void EVP_PBE_cleanup(void)
-{
-       sk_pop_free(pbe_algs, OPENSSL_freeFunc);
+       {
+       sk_EVP_PBE_CTL_pop_free(pbe_algs, free_evp_pbe_ctl);
        pbe_algs = NULL;
-}
+       }
index 10d9e9e..ceebf69 100644 (file)
@@ -3,7 +3,7 @@
  * project 1999.
  */
 /* ====================================================================
- * Copyright (c) 1999-2002 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include "cryptlib.h"
 #include <openssl/x509.h>
 #include <openssl/rand.h>
-#ifndef OPENSSL_NO_RSA
-#include <openssl/rsa.h>
-#endif
-#ifndef OPENSSL_NO_DSA
-#include <openssl/dsa.h>
-#endif
-#include <openssl/bn.h>
-
-#ifndef OPENSSL_NO_DSA
-static int dsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8inf, EVP_PKEY *pkey);
-#endif
-#ifndef OPENSSL_NO_EC
-static int eckey_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8inf, EVP_PKEY *pkey);
-#endif
+#include "asn1_locl.h"
 
 /* Extract a private key from a PKCS8 structure */
 
 EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8)
 {
        EVP_PKEY *pkey = NULL;
-#ifndef OPENSSL_NO_RSA
-       RSA *rsa = NULL;
-#endif
-#ifndef OPENSSL_NO_DSA
-       DSA *dsa = NULL;
-       ASN1_TYPE *t1, *t2;
-       ASN1_INTEGER *privkey;
-       STACK_OF(ASN1_TYPE) *ndsa = NULL;
-#endif
-#ifndef OPENSSL_NO_EC
-       EC_KEY *eckey = NULL;
-       const unsigned char *p_tmp;
-#endif
-#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_EC)
-       ASN1_TYPE    *param = NULL;     
-       BN_CTX *ctx = NULL;
-       int plen;
-#endif
-       X509_ALGOR *a;
-       const unsigned char *p;
-       const unsigned char *cp;
-       int pkeylen;
-       int  nid;
+       ASN1_OBJECT *algoid;
        char obj_tmp[80];
 
-       if(p8->pkey->type == V_ASN1_OCTET_STRING) {
-               p8->broken = PKCS8_OK;
-               p = p8->pkey->value.octet_string->data;
-               pkeylen = p8->pkey->value.octet_string->length;
-       } else {
-               p8->broken = PKCS8_NO_OCTET;
-               p = p8->pkey->value.sequence->data;
-               pkeylen = p8->pkey->value.sequence->length;
-       }
+       if (!PKCS8_pkey_get0(&algoid, NULL, NULL, NULL, p8))
+               return NULL;
+
        if (!(pkey = EVP_PKEY_new())) {
                EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
                return NULL;
        }
-       a = p8->pkeyalg;
-       nid = OBJ_obj2nid(a->algorithm);
-       switch(nid)
-       {
-#ifndef OPENSSL_NO_RSA
-               case NID_rsaEncryption:
-               cp = p;
-               if (!(rsa = d2i_RSAPrivateKey (NULL,&cp, pkeylen))) {
-                       EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
-                       return NULL;
-               }
-               EVP_PKEY_assign_RSA (pkey, rsa);
-               break;
-#endif
-#ifndef OPENSSL_NO_DSA
-               case NID_dsa:
-               /* PKCS#8 DSA is weird: you just get a private key integer
-                * and parameters in the AlgorithmIdentifier the pubkey must
-                * be recalculated.
-                */
-       
-               /* Check for broken DSA PKCS#8, UGH! */
-               if(*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED)) {
-                   if(!(ndsa = ASN1_seq_unpack_ASN1_TYPE(p, pkeylen, 
-                                                         d2i_ASN1_TYPE,
-                                                         ASN1_TYPE_free))) {
-                       EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
-                       goto dsaerr;
-                   }
-                   if(sk_ASN1_TYPE_num(ndsa) != 2 ) {
-                       EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
-                       goto dsaerr;
-                   }
-                   /* Handle Two broken types:
-                    * SEQUENCE {parameters, priv_key}
-                    * SEQUENCE {pub_key, priv_key}
-                    */
-
-                   t1 = sk_ASN1_TYPE_value(ndsa, 0);
-                   t2 = sk_ASN1_TYPE_value(ndsa, 1);
-                   if(t1->type == V_ASN1_SEQUENCE) {
-                       p8->broken = PKCS8_EMBEDDED_PARAM;
-                       param = t1;
-                   } else if(a->parameter->type == V_ASN1_SEQUENCE) {
-                       p8->broken = PKCS8_NS_DB;
-                       param = a->parameter;
-                   } else {
-                       EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
-                       goto dsaerr;
-                   }
-
-                   if(t2->type != V_ASN1_INTEGER) {
-                       EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
-                       goto dsaerr;
-                   }
-                   privkey = t2->value.integer;
-               } else {
-                       if (!(privkey=d2i_ASN1_INTEGER (NULL, &p, pkeylen))) {
-                               EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
-                               goto dsaerr;
-                       }
-                       param = p8->pkeyalg->parameter;
-               }
-               if (!param || (param->type != V_ASN1_SEQUENCE)) {
-                       EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
-                       goto dsaerr;
-               }
-               cp = p = param->value.sequence->data;
-               plen = param->value.sequence->length;
-               if (!(dsa = d2i_DSAparams (NULL, &cp, plen))) {
-                       EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
-                       goto dsaerr;
-               }
-               /* We have parameters now set private key */
-               if (!(dsa->priv_key = ASN1_INTEGER_to_BN(privkey, NULL))) {
-                       EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_DECODE_ERROR);
-                       goto dsaerr;
-               }
-               /* Calculate public key (ouch!) */
-               if (!(dsa->pub_key = BN_new())) {
-                       EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
-                       goto dsaerr;
-               }
-               if (!(ctx = BN_CTX_new())) {
-                       EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
-                       goto dsaerr;
-               }
-                       
-               if (!BN_mod_exp(dsa->pub_key, dsa->g,
-                                                dsa->priv_key, dsa->p, ctx)) {
-                       
-                       EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_PUBKEY_ERROR);
-                       goto dsaerr;
-               }
 
-               EVP_PKEY_assign_DSA(pkey, dsa);
-               BN_CTX_free (ctx);
-               if(ndsa) sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
-               else ASN1_INTEGER_free(privkey);
-               break;
-               dsaerr:
-               BN_CTX_free (ctx);
-               sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
-               DSA_free(dsa);
-               EVP_PKEY_free(pkey);
-               return NULL;
-               break;
-#endif
-#ifndef OPENSSL_NO_EC
-               case NID_X9_62_id_ecPublicKey:
-               p_tmp = p;
-               /* extract the ec parameters */
-               param = p8->pkeyalg->parameter;
-
-               if (!param || ((param->type != V_ASN1_SEQUENCE) &&
-                   (param->type != V_ASN1_OBJECT)))
+       if (!EVP_PKEY_set_type(pkey, OBJ_obj2nid(algoid)))
                {
-                       EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
-                       goto ecerr;
+               EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
+               i2t_ASN1_OBJECT(obj_tmp, 80, algoid);
+               ERR_add_error_data(2, "TYPE=", obj_tmp);
+               goto error;
                }
 
-               if (param->type == V_ASN1_SEQUENCE)
+       if (pkey->ameth->priv_decode)
                {
-                       cp = p = param->value.sequence->data;
-                       plen = param->value.sequence->length;
-
-                       if (!(eckey = d2i_ECParameters(NULL, &cp, plen)))
+               if (!pkey->ameth->priv_decode(pkey, p8))
                        {
-                               EVPerr(EVP_F_EVP_PKCS82PKEY,
-                                       EVP_R_DECODE_ERROR);
-                               goto ecerr;
+                       EVPerr(EVP_F_EVP_PKCS82PKEY,
+                                       EVP_R_PRIVATE_KEY_DECODE_ERROR);
+                       goto error;
                        }
                }
-               else
+       else
                {
-                       EC_GROUP *group;
-                       cp = p = param->value.object->data;
-                       plen = param->value.object->length;
-
-                       /* type == V_ASN1_OBJECT => the parameters are given
-                        * by an asn1 OID
-                        */
-                       if ((eckey = EC_KEY_new()) == NULL)
-                       {
-                               EVPerr(EVP_F_EVP_PKCS82PKEY,
-                                       ERR_R_MALLOC_FAILURE);
-                               goto ecerr;
-                       }
-                       group = EC_GROUP_new_by_curve_name(OBJ_obj2nid(a->parameter->value.object));
-                       if (group == NULL)
-                               goto ecerr;
-                       EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE);
-                       if (EC_KEY_set_group(eckey, group) == 0)
-                               goto ecerr;
-                       EC_GROUP_free(group);
-               }
-
-               /* We have parameters now set private key */
-               if (!d2i_ECPrivateKey(&eckey, &p_tmp, pkeylen))
-               {
-                       EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
-                       goto ecerr;
-               }
-
-               /* calculate public key (if necessary) */
-               if (EC_KEY_get0_public_key(eckey) == NULL)
-               {
-                       const BIGNUM *priv_key;
-                       const EC_GROUP *group;
-                       EC_POINT *pub_key;
-                       /* the public key was not included in the SEC1 private
-                        * key => calculate the public key */
-                       group   = EC_KEY_get0_group(eckey);
-                       pub_key = EC_POINT_new(group);
-                       if (pub_key == NULL)
-                       {
-                               EVPerr(EVP_F_EVP_PKCS82PKEY, ERR_R_EC_LIB);
-                               goto ecerr;
-                       }
-                       if (!EC_POINT_copy(pub_key, EC_GROUP_get0_generator(group)))
-                       {
-                               EC_POINT_free(pub_key);
-                               EVPerr(EVP_F_EVP_PKCS82PKEY, ERR_R_EC_LIB);
-                               goto ecerr;
-                       }
-                       priv_key = EC_KEY_get0_private_key(eckey);
-                       if (!EC_POINT_mul(group, pub_key, priv_key, NULL, NULL, ctx))
-                       {
-                               EC_POINT_free(pub_key);
-                               EVPerr(EVP_F_EVP_PKCS82PKEY, ERR_R_EC_LIB);
-                               goto ecerr;
-                       }
-                       if (EC_KEY_set_public_key(eckey, pub_key) == 0)
-                       {
-                               EC_POINT_free(pub_key);
-                               EVPerr(EVP_F_EVP_PKCS82PKEY, ERR_R_EC_LIB);
-                               goto ecerr;
-                       }
-                       EC_POINT_free(pub_key);
+               EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_METHOD_NOT_SUPPORTED);
+               goto error;
                }
 
-               EVP_PKEY_assign_EC_KEY(pkey, eckey);
-               if (ctx)
-                       BN_CTX_free(ctx);
-               break;
-ecerr:
-               if (ctx)
-                       BN_CTX_free(ctx);
-               if (eckey)
-                       EC_KEY_free(eckey);
-               if (pkey)
-                       EVP_PKEY_free(pkey);
-               return NULL;
-#endif
-               default:
-               EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
-               if (!a->algorithm) BUF_strlcpy (obj_tmp, "NULL", sizeof obj_tmp);
-               else i2t_ASN1_OBJECT(obj_tmp, 80, a->algorithm);
-               ERR_add_error_data(2, "TYPE=", obj_tmp);
-               EVP_PKEY_free (pkey);
-               return NULL;
-       }
        return pkey;
+
+       error:
+       EVP_PKEY_free (pkey);
+       return NULL;
 }
 
 PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey)
@@ -360,59 +125,37 @@ PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken)
                return NULL;
        }
        p8->broken = broken;
-       if (!ASN1_INTEGER_set(p8->version, 0)) {
-               EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN,ERR_R_MALLOC_FAILURE);
-               PKCS8_PRIV_KEY_INFO_free (p8);
-               return NULL;
-       }
-       if (!(p8->pkeyalg->parameter = ASN1_TYPE_new ())) {
-               EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN,ERR_R_MALLOC_FAILURE);
-               PKCS8_PRIV_KEY_INFO_free (p8);
-               return NULL;
-       }
-       p8->pkey->type = V_ASN1_OCTET_STRING;
-       switch (EVP_PKEY_type(pkey->type)) {
-#ifndef OPENSSL_NO_RSA
-               case EVP_PKEY_RSA:
 
-               if(p8->broken == PKCS8_NO_OCTET) p8->pkey->type = V_ASN1_SEQUENCE;
-
-               p8->pkeyalg->algorithm = OBJ_nid2obj(NID_rsaEncryption);
-               p8->pkeyalg->parameter->type = V_ASN1_NULL;
-               if (!ASN1_pack_string_of (EVP_PKEY,pkey, i2d_PrivateKey,
-                                        &p8->pkey->value.octet_string)) {
-                       EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN,ERR_R_MALLOC_FAILURE);
-                       PKCS8_PRIV_KEY_INFO_free (p8);
-                       return NULL;
-               }
-               break;
-#endif
-#ifndef OPENSSL_NO_DSA
-               case EVP_PKEY_DSA:
-               if(!dsa_pkey2pkcs8(p8, pkey)) {
-                       PKCS8_PRIV_KEY_INFO_free (p8);
-                       return NULL;
+       if (pkey->ameth)
+               {
+               if (pkey->ameth->priv_encode)
+                       {
+                       if (!pkey->ameth->priv_encode(p8, pkey))
+                               {
+                               EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN,
+                                       EVP_R_PRIVATE_KEY_ENCODE_ERROR);
+                               goto error;
+                               }
+                       }
+               else
+                       {
+                       EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN,
+                                       EVP_R_METHOD_NOT_SUPPORTED);
+                       goto error;
+                       }
                }
-
-               break;
-#endif
-#ifndef OPENSSL_NO_EC
-               case EVP_PKEY_EC:
-               if (!eckey_pkey2pkcs8(p8, pkey))
+       else
                {
-                       PKCS8_PRIV_KEY_INFO_free(p8);
-                       return(NULL);
+               EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN,
+                               EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
+               goto error;
                }
-               break;
-#endif
-               default:
-               EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
-               PKCS8_PRIV_KEY_INFO_free (p8);
-               return NULL;
-       }
        RAND_add(p8->pkey->value.octet_string->data,
                 p8->pkey->value.octet_string->length, 0.0);
        return p8;
+       error:
+       PKCS8_PRIV_KEY_INFO_free(p8);
+       return NULL;
 }
 
 PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken)
@@ -436,301 +179,6 @@ PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken)
        }
 }
 
-#ifndef OPENSSL_NO_DSA
-static int dsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8, EVP_PKEY *pkey)
-{
-       ASN1_STRING *params = NULL;
-       ASN1_INTEGER *prkey = NULL;
-       ASN1_TYPE *ttmp = NULL;
-       STACK_OF(ASN1_TYPE) *ndsa = NULL;
-       unsigned char *p = NULL, *q;
-       int len;
-
-       p8->pkeyalg->algorithm = OBJ_nid2obj(NID_dsa);
-       len = i2d_DSAparams (pkey->pkey.dsa, NULL);
-       if (!(p = OPENSSL_malloc(len))) {
-               EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
-               goto err;
-       }
-       q = p;
-       i2d_DSAparams (pkey->pkey.dsa, &q);
-       if (!(params = ASN1_STRING_new())) {
-               EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
-               goto err;
-       }
-       if (!ASN1_STRING_set(params, p, len)) {
-               EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
-               goto err;
-       }
-       OPENSSL_free(p);
-       p = NULL;
-       /* Get private key into integer */
-       if (!(prkey = BN_to_ASN1_INTEGER (pkey->pkey.dsa->priv_key, NULL))) {
-               EVPerr(EVP_F_DSA_PKEY2PKCS8,EVP_R_ENCODE_ERROR);
-               goto err;
-       }
-
-       switch(p8->broken) {
-
-               case PKCS8_OK:
-               case PKCS8_NO_OCTET:
-
-               if (!ASN1_pack_string_of(ASN1_INTEGER,prkey, i2d_ASN1_INTEGER,
-                                        &p8->pkey->value.octet_string)) {
-                       EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
-                       goto err;
-               }
-
-               M_ASN1_INTEGER_free (prkey);
-               prkey = NULL;
-               p8->pkeyalg->parameter->value.sequence = params;
-               params = NULL;
-               p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;
-
-               break;
-
-               case PKCS8_NS_DB:
-
-               p8->pkeyalg->parameter->value.sequence = params;
-               params = NULL;
-               p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;
-               if (!(ndsa = sk_ASN1_TYPE_new_null())) {
-                       EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
-                       goto err;
-               }
-               if (!(ttmp = ASN1_TYPE_new())) {
-                       EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
-                       goto err;
-               }
-               if (!(ttmp->value.integer =
-                       BN_to_ASN1_INTEGER(pkey->pkey.dsa->pub_key, NULL))) {
-                       EVPerr(EVP_F_DSA_PKEY2PKCS8,EVP_R_ENCODE_ERROR);
-                       goto err;
-               }
-               ttmp->type = V_ASN1_INTEGER;
-               if (!sk_ASN1_TYPE_push(ndsa, ttmp)) {
-                       EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
-                       goto err;
-               }
-
-               if (!(ttmp = ASN1_TYPE_new())) {
-                       EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
-                       goto err;
-               }
-               ttmp->value.integer = prkey;
-               prkey = NULL;
-               ttmp->type = V_ASN1_INTEGER;
-               if (!sk_ASN1_TYPE_push(ndsa, ttmp)) {
-                       EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
-                       goto err;
-               }
-               ttmp = NULL;
-
-               if (!(p8->pkey->value.octet_string = ASN1_OCTET_STRING_new())) {
-                       EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
-                       goto err;
-               }
-
-               if (!ASN1_seq_pack_ASN1_TYPE(ndsa, i2d_ASN1_TYPE,
-                                        &p8->pkey->value.octet_string->data,
-                                        &p8->pkey->value.octet_string->length)) {
-
-                       EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
-                       goto err;
-               }
-               sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
-               break;
-
-               case PKCS8_EMBEDDED_PARAM:
-
-               p8->pkeyalg->parameter->type = V_ASN1_NULL;
-               if (!(ndsa = sk_ASN1_TYPE_new_null())) {
-                       EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
-                       goto err;
-               }
-               if (!(ttmp = ASN1_TYPE_new())) {
-                       EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
-                       goto err;
-               }
-               ttmp->value.sequence = params;
-               params = NULL;
-               ttmp->type = V_ASN1_SEQUENCE;
-               if (!sk_ASN1_TYPE_push(ndsa, ttmp)) {
-                       EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
-                       goto err;
-               }
-
-               if (!(ttmp = ASN1_TYPE_new())) {
-                       EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
-                       goto err;
-               }
-               ttmp->value.integer = prkey;
-               prkey = NULL;
-               ttmp->type = V_ASN1_INTEGER;
-               if (!sk_ASN1_TYPE_push(ndsa, ttmp)) {
-                       EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
-                       goto err;
-               }
-               ttmp = NULL;
-
-               if (!(p8->pkey->value.octet_string = ASN1_OCTET_STRING_new())) {
-                       EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
-                       goto err;
-               }
-
-               if (!ASN1_seq_pack_ASN1_TYPE(ndsa, i2d_ASN1_TYPE,
-                                        &p8->pkey->value.octet_string->data,
-                                        &p8->pkey->value.octet_string->length)) {
-
-                       EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
-                       goto err;
-               }
-               sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
-               break;
-       }
-       return 1;
-err:
-       if (p != NULL) OPENSSL_free(p);
-       if (params != NULL) ASN1_STRING_free(params);
-       if (prkey != NULL) M_ASN1_INTEGER_free(prkey);
-       if (ttmp != NULL) ASN1_TYPE_free(ttmp);
-       if (ndsa != NULL) sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
-       return 0;
-}
-#endif
-
-#ifndef OPENSSL_NO_EC
-static int eckey_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8, EVP_PKEY *pkey)
-{
-       EC_KEY          *ec_key;
-       const EC_GROUP  *group;
-       unsigned char   *p, *pp;
-       int             nid, i, ret = 0;
-       unsigned int    tmp_flags, old_flags;
-
-       ec_key = pkey->pkey.ec;
-       if (ec_key == NULL || (group = EC_KEY_get0_group(ec_key)) == NULL) 
-       {
-               EVPerr(EVP_F_ECKEY_PKEY2PKCS8, EVP_R_MISSING_PARAMETERS);
-               return 0;
-       }
-
-       /* set the ec parameters OID */
-       if (p8->pkeyalg->algorithm)
-               ASN1_OBJECT_free(p8->pkeyalg->algorithm);
-
-       p8->pkeyalg->algorithm = OBJ_nid2obj(NID_X9_62_id_ecPublicKey);
-
-       /* set the ec parameters */
-
-       if (p8->pkeyalg->parameter)
-       {
-               ASN1_TYPE_free(p8->pkeyalg->parameter);
-               p8->pkeyalg->parameter = NULL;
-       }
-
-       if ((p8->pkeyalg->parameter = ASN1_TYPE_new()) == NULL)
-       {
-               EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);
-               return 0;
-       }
-       
-       if (EC_GROUP_get_asn1_flag(group)
-                     && (nid = EC_GROUP_get_curve_name(group)))
-       {
-               /* we have a 'named curve' => just set the OID */
-               p8->pkeyalg->parameter->type = V_ASN1_OBJECT;
-               p8->pkeyalg->parameter->value.object = OBJ_nid2obj(nid);
-       }
-       else    /* explicit parameters */
-       {
-               if ((i = i2d_ECParameters(ec_key, NULL)) == 0)
-               {
-                       EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_EC_LIB);
-                       return 0;
-               }
-               if ((p = (unsigned char *) OPENSSL_malloc(i)) == NULL)
-               {
-                       EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);
-                       return 0;
-               }       
-               pp = p;
-               if (!i2d_ECParameters(ec_key, &pp))
-               {
-                       EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_EC_LIB);
-                       OPENSSL_free(p);
-                       return 0;
-               }
-               p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;
-               if ((p8->pkeyalg->parameter->value.sequence 
-                       = ASN1_STRING_new()) == NULL)
-               {
-                       EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_ASN1_LIB);
-                       OPENSSL_free(p);
-                       return 0;
-               }
-               ASN1_STRING_set(p8->pkeyalg->parameter->value.sequence, p, i);
-               OPENSSL_free(p);
-       }
-
-       /* set the private key */
-
-       /* do not include the parameters in the SEC1 private key
-        * see PKCS#11 12.11 */
-       old_flags = EC_KEY_get_enc_flags(pkey->pkey.ec);
-       tmp_flags = old_flags | EC_PKEY_NO_PARAMETERS;
-       EC_KEY_set_enc_flags(pkey->pkey.ec, tmp_flags);
-       i = i2d_ECPrivateKey(pkey->pkey.ec, NULL);
-       if (!i)
-       {
-               EC_KEY_set_enc_flags(pkey->pkey.ec, old_flags);
-               EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_EC_LIB);
-               return 0;
-       }
-       p = (unsigned char *) OPENSSL_malloc(i);
-       if (!p)
-       {
-               EC_KEY_set_enc_flags(pkey->pkey.ec, old_flags);
-               EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);
-               return 0;
-       }
-       pp = p;
-       if (!i2d_ECPrivateKey(pkey->pkey.ec, &pp))
-       {
-               EC_KEY_set_enc_flags(pkey->pkey.ec, old_flags);
-               EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_EC_LIB);
-               OPENSSL_free(p);
-               return 0;
-       }
-       /* restore old encoding flags */
-       EC_KEY_set_enc_flags(pkey->pkey.ec, old_flags);
-
-       switch(p8->broken) {
-
-               case PKCS8_OK:
-               p8->pkey->value.octet_string = ASN1_OCTET_STRING_new();
-               if (!p8->pkey->value.octet_string ||
-                   !M_ASN1_OCTET_STRING_set(p8->pkey->value.octet_string,
-                   (const void *)p, i))
-
-               {
-                       EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);
-               }
-               else
-                       ret = 1;
-               break;
-               case PKCS8_NO_OCTET:            /* RSA specific */
-               case PKCS8_NS_DB:               /* DSA specific */
-               case PKCS8_EMBEDDED_PARAM:      /* DSA specific */
-               default:
-                       EVPerr(EVP_F_ECKEY_PKEY2PKCS8,EVP_R_ENCODE_ERROR);
-       }
-       OPENSSL_cleanse(p, (size_t)i);
-       OPENSSL_free(p);
-       return ret;
-}
-#endif
-
 /* EVP_PKEY attribute functions */
 
 int EVP_PKEY_get_attr_count(const EVP_PKEY *key)
index 436be20..55c7cdf 100644 (file)
@@ -153,8 +153,8 @@ static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn,
     
     if(kn != c->key_len)
        {
-       fprintf(stderr,"Key length doesn't match, got %d expected %d\n",kn,
-               c->key_len);
+       fprintf(stderr,"Key length doesn't match, got %d expected %lu\n",kn,
+               (unsigned long)c->key_len);
        test1_exit(5);
        }
     EVP_CIPHER_CTX_init(&ctx);
@@ -435,13 +435,14 @@ int main(int argc,char **argv)
            EXIT(3);
            }
        }
+       fclose(f);
 
 #ifndef OPENSSL_NO_ENGINE
     ENGINE_cleanup();
 #endif
     EVP_cleanup();
     CRYPTO_cleanup_all_ex_data();
-    ERR_remove_state(0);
+    ERR_remove_thread_state(NULL);
     ERR_free_strings();
     CRYPTO_mem_leaks_fp(stderr);
 
index 6b0c0aa..48c2689 100644 (file)
@@ -81,7 +81,7 @@ static const EVP_MD dsa_md=
        NID_dsaWithSHA,
        NID_dsaWithSHA,
        SHA_DIGEST_LENGTH,
-       EVP_MD_FLAG_FIPS,
+       EVP_MD_FLAG_PKEY_DIGEST,
        init,
        update,
        final,
index da8babc..4f03fb7 100644 (file)
@@ -68,8 +68,6 @@
 #include <openssl/dsa.h>
 #endif
 
-#ifndef OPENSSL_FIPS
-
 static int init(EVP_MD_CTX *ctx)
        { return SHA1_Init(ctx->md_data); }
 
@@ -84,7 +82,7 @@ static const EVP_MD dss1_md=
        NID_dsa,
        NID_dsaWithSHA1,
        SHA_DIGEST_LENGTH,
-       0,
+       EVP_MD_FLAG_PKEY_DIGEST,
        init,
        update,
        final,
@@ -100,4 +98,3 @@ const EVP_MD *EVP_dss1(void)
        return(&dss1_md);
        }
 #endif
-#endif
index fad270f..8d87a49 100644 (file)
@@ -130,7 +130,7 @@ static const EVP_MD ecdsa_md=
        NID_ecdsa_with_SHA1,
        NID_ecdsa_with_SHA1,
        SHA_DIGEST_LENGTH,
-       0,
+       EVP_MD_FLAG_PKEY_DIGEST,
        init,
        update,
        final,
index 8eee623..5ce849f 100644 (file)
@@ -58,7 +58,6 @@
 
 #include <stdio.h>
 #include "cryptlib.h"
-#include "evp_locl.h"
 
 #ifndef OPENSSL_NO_MD2
 
index 5cd2ab5..1e0b7c5 100644 (file)
@@ -58,7 +58,6 @@
 
 #include <stdio.h>
 #include "cryptlib.h"
-#include "evp_locl.h"
 
 #ifndef OPENSSL_NO_MD4
 
index 6455829..63c1421 100644 (file)
@@ -62,7 +62,6 @@
 #ifndef OPENSSL_NO_MD5
 
 #include <openssl/evp.h>
-#include "evp_locl.h"
 #include <openssl/objects.h>
 #include <openssl/x509.h>
 #include <openssl/md5.h>
index 9f9bcf0..b08d559 100644 (file)
@@ -58,7 +58,6 @@
 
 #include <stdio.h>
 #include "cryptlib.h"
-#include "evp_locl.h"
 
 #ifndef OPENSSL_NO_MDC2
 
@@ -66,7 +65,9 @@
 #include <openssl/objects.h>
 #include <openssl/x509.h>
 #include <openssl/mdc2.h>
+#ifndef OPENSSL_NO_RSA
 #include <openssl/rsa.h>
+#endif
 
 static int init(EVP_MD_CTX *ctx)
        { return MDC2_Init(ctx->md_data); }
index 3f30dfc..acccc8f 100644 (file)
@@ -58,7 +58,6 @@
 
 #include <stdio.h>
 #include "cryptlib.h"
-#include "evp_locl.h"
 
 #if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA0)
 
index 471ec30..9a2790f 100644 (file)
@@ -68,8 +68,6 @@
 #include <openssl/rsa.h>
 #endif
 
-#ifndef OPENSSL_FIPS
-
 static int init(EVP_MD_CTX *ctx)
        { return SHA1_Init(ctx->md_data); }
 
@@ -84,7 +82,7 @@ static const EVP_MD sha1_md=
        NID_sha1,
        NID_sha1WithRSAEncryption,
        SHA_DIGEST_LENGTH,
-       0,
+       EVP_MD_FLAG_PKEY_METHOD_SIGNATURE|EVP_MD_FLAG_DIGALGID_ABSENT,
        init,
        update,
        final,
@@ -99,6 +97,7 @@ const EVP_MD *EVP_sha1(void)
        {
        return(&sha1_md);
        }
+#endif
 
 #ifndef OPENSSL_NO_SHA256
 static int init224(EVP_MD_CTX *ctx)
@@ -120,7 +119,7 @@ static const EVP_MD sha224_md=
        NID_sha224,
        NID_sha224WithRSAEncryption,
        SHA224_DIGEST_LENGTH,
-       0,
+       EVP_MD_FLAG_PKEY_METHOD_SIGNATURE|EVP_MD_FLAG_DIGALGID_ABSENT,
        init224,
        update256,
        final256,
@@ -139,7 +138,7 @@ static const EVP_MD sha256_md=
        NID_sha256,
        NID_sha256WithRSAEncryption,
        SHA256_DIGEST_LENGTH,
-       0,
+       EVP_MD_FLAG_PKEY_METHOD_SIGNATURE|EVP_MD_FLAG_DIGALGID_ABSENT,
        init256,
        update256,
        final256,
@@ -170,7 +169,7 @@ static const EVP_MD sha384_md=
        NID_sha384,
        NID_sha384WithRSAEncryption,
        SHA384_DIGEST_LENGTH,
-       0,
+       EVP_MD_FLAG_PKEY_METHOD_SIGNATURE|EVP_MD_FLAG_DIGALGID_ABSENT,
        init384,
        update512,
        final512,
@@ -189,7 +188,7 @@ static const EVP_MD sha512_md=
        NID_sha512,
        NID_sha512WithRSAEncryption,
        SHA512_DIGEST_LENGTH,
-       0,
+       EVP_MD_FLAG_PKEY_METHOD_SIGNATURE|EVP_MD_FLAG_DIGALGID_ABSENT,
        init512,
        update512,
        final512,
@@ -203,7 +202,3 @@ static const EVP_MD sha512_md=
 const EVP_MD *EVP_sha512(void)
        { return(&sha512_md); }
 #endif /* ifndef OPENSSL_NO_SHA512 */
-
-#endif
-
-#endif
diff --git a/deps/openssl/openssl/crypto/evp/m_sigver.c b/deps/openssl/openssl/crypto/evp/m_sigver.c
new file mode 100644 (file)
index 0000000..7e2731f
--- /dev/null
@@ -0,0 +1,200 @@
+/* m_sigver.c */
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project 2006.
+ */
+/* ====================================================================
+ * Copyright (c) 2006,2007 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include "cryptlib.h"
+#include <openssl/evp.h>
+#include <openssl/objects.h>
+#include <openssl/x509.h>
+#include "evp_locl.h"
+
+static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
+                         const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey,
+                         int ver)
+       {
+       if (ctx->pctx == NULL)
+               ctx->pctx = EVP_PKEY_CTX_new(pkey, e);
+       if (ctx->pctx == NULL)
+               return 0;
+
+       if (type == NULL)
+               {
+               int def_nid;
+               if (EVP_PKEY_get_default_digest_nid(pkey, &def_nid) > 0)
+                       type = EVP_get_digestbynid(def_nid);
+               }
+
+       if (type == NULL)
+               {
+               EVPerr(EVP_F_DO_SIGVER_INIT, EVP_R_NO_DEFAULT_DIGEST);
+               return 0;
+               }
+
+       if (ver)
+               {
+               if (ctx->pctx->pmeth->verifyctx_init)
+                       {
+                       if (ctx->pctx->pmeth->verifyctx_init(ctx->pctx, ctx) <=0)
+                               return 0;
+                       ctx->pctx->operation = EVP_PKEY_OP_VERIFYCTX;
+                       }
+               else if (EVP_PKEY_verify_init(ctx->pctx) <= 0)
+                       return 0;
+               }
+       else
+               {
+               if (ctx->pctx->pmeth->signctx_init)
+                       {
+                       if (ctx->pctx->pmeth->signctx_init(ctx->pctx, ctx) <= 0)
+                               return 0;
+                       ctx->pctx->operation = EVP_PKEY_OP_SIGNCTX;
+                       }
+               else if (EVP_PKEY_sign_init(ctx->pctx) <= 0)
+                       return 0;
+               }
+       if (EVP_PKEY_CTX_set_signature_md(ctx->pctx, type) <= 0)
+               return 0;
+       if (pctx)
+               *pctx = ctx->pctx;
+       if (!EVP_DigestInit_ex(ctx, type, e))
+               return 0;
+       return 1;
+       }
+
+int EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
+                       const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey)
+       {
+       return do_sigver_init(ctx, pctx, type, e, pkey, 0);
+       }
+
+int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
+                       const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey)
+       {
+       return do_sigver_init(ctx, pctx, type, e, pkey, 1);
+       }
+
+int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen)
+       {
+       int sctx, r = 0;
+       if (ctx->pctx->pmeth->signctx)
+               sctx = 1;
+       else
+               sctx = 0;
+       if (sigret)
+               {
+               EVP_MD_CTX tmp_ctx;
+               unsigned char md[EVP_MAX_MD_SIZE];
+               unsigned int mdlen;
+               EVP_MD_CTX_init(&tmp_ctx);
+               if (!EVP_MD_CTX_copy_ex(&tmp_ctx,ctx))
+                       return 0;
+               if (sctx)
+                       r = tmp_ctx.pctx->pmeth->signctx(tmp_ctx.pctx,
+                                       sigret, siglen, &tmp_ctx);
+               else
+                       r = EVP_DigestFinal_ex(&tmp_ctx,md,&mdlen);
+               EVP_MD_CTX_cleanup(&tmp_ctx);
+               if (sctx || !r)
+                       return r;
+               if (EVP_PKEY_sign(ctx->pctx, sigret, siglen, md, mdlen) <= 0)
+                       return 0;
+               }
+       else
+               {
+               if (sctx)
+                       {
+                       if (ctx->pctx->pmeth->signctx(ctx->pctx, sigret, siglen, ctx) <= 0)
+                               return 0;
+                       }
+               else
+                       {
+                       int s = EVP_MD_size(ctx->digest);
+                       if (s < 0 || EVP_PKEY_sign(ctx->pctx, sigret, siglen, NULL, s) <= 0)
+                               return 0;
+                       }
+               }
+       return 1;
+       }
+
+int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, unsigned char *sig, size_t siglen)
+       {
+       EVP_MD_CTX tmp_ctx;
+       unsigned char md[EVP_MAX_MD_SIZE];
+       int r;
+       unsigned int mdlen;
+       int vctx;
+
+       if (ctx->pctx->pmeth->verifyctx)
+               vctx = 1;
+       else
+               vctx = 0;
+       EVP_MD_CTX_init(&tmp_ctx);
+       if (!EVP_MD_CTX_copy_ex(&tmp_ctx,ctx))
+               return -1;      
+       if (vctx)
+               {
+               r = tmp_ctx.pctx->pmeth->verifyctx(tmp_ctx.pctx,
+                                       sig, siglen, &tmp_ctx);
+               }
+       else
+               r = EVP_DigestFinal_ex(&tmp_ctx,md,&mdlen);
+       EVP_MD_CTX_cleanup(&tmp_ctx);
+       if (vctx || !r)
+               return r;
+       return EVP_PKEY_verify(ctx->pctx, sig, siglen, md, mdlen);
+       }
diff --git a/deps/openssl/openssl/crypto/evp/m_wp.c b/deps/openssl/openssl/crypto/evp/m_wp.c
new file mode 100644 (file)
index 0000000..1ce47c0
--- /dev/null
@@ -0,0 +1,42 @@
+/* crypto/evp/m_wp.c */
+
+#include <stdio.h>
+#include "cryptlib.h"
+
+#ifndef OPENSSL_NO_WHIRLPOOL
+
+#include <openssl/evp.h>
+#include <openssl/objects.h>
+#include <openssl/x509.h>
+#include <openssl/whrlpool.h>
+
+static int init(EVP_MD_CTX *ctx)
+       { return WHIRLPOOL_Init(ctx->md_data); }
+
+static int update(EVP_MD_CTX *ctx,const void *data,size_t count)
+       { return WHIRLPOOL_Update(ctx->md_data,data,count); }
+
+static int final(EVP_MD_CTX *ctx,unsigned char *md)
+       { return WHIRLPOOL_Final(md,ctx->md_data); }
+
+static const EVP_MD whirlpool_md=
+       {
+       NID_whirlpool,
+       0,
+       WHIRLPOOL_DIGEST_LENGTH,
+       0,
+       init,
+       update,
+       final,
+       NULL,
+       NULL,
+       EVP_PKEY_NULL_method,
+       WHIRLPOOL_BBLOCK/8,
+       sizeof(EVP_MD *)+sizeof(WHIRLPOOL_CTX),
+       };
+
+const EVP_MD *EVP_whirlpool(void)
+       {
+       return(&whirlpool_md);
+       }
+#endif
index 945879d..f2869f5 100644 (file)
@@ -66,27 +66,23 @@ int EVP_add_cipher(const EVP_CIPHER *c)
        {
        int r;
 
-#ifdef OPENSSL_FIPS
-       OPENSSL_init();
-#endif
-
        r=OBJ_NAME_add(OBJ_nid2sn(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(const char *)c);
        if (r == 0) return(0);
+       check_defer(c->nid);
        r=OBJ_NAME_add(OBJ_nid2ln(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(const char *)c);
        return(r);
        }
 
+
 int EVP_add_digest(const EVP_MD *md)
        {
        int r;
        const char *name;
 
-#ifdef OPENSSL_FIPS
-       OPENSSL_init();
-#endif
        name=OBJ_nid2sn(md->type);
        r=OBJ_NAME_add(name,OBJ_NAME_TYPE_MD_METH,(const char *)md);
        if (r == 0) return(0);
+       check_defer(md->type);
        r=OBJ_NAME_add(OBJ_nid2ln(md->type),OBJ_NAME_TYPE_MD_METH,(const char *)md);
        if (r == 0) return(0);
 
@@ -95,6 +91,7 @@ int EVP_add_digest(const EVP_MD *md)
                r=OBJ_NAME_add(OBJ_nid2sn(md->pkey_type),
                        OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,name);
                if (r == 0) return(0);
+               check_defer(md->pkey_type);
                r=OBJ_NAME_add(OBJ_nid2ln(md->pkey_type),
                        OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,name);
                }
@@ -127,4 +124,78 @@ void EVP_cleanup(void)
        OBJ_NAME_cleanup(-1);
 
        EVP_PBE_cleanup();
+       if (obj_cleanup_defer == 2)
+               {
+               obj_cleanup_defer = 0;
+               OBJ_cleanup();
+               }
+       OBJ_sigid_free();
+       }
+
+struct doall_cipher
+       {
+       void *arg;
+       void (*fn)(const EVP_CIPHER *ciph,
+                       const char *from, const char *to, void *arg);
+       };
+
+static void do_all_cipher_fn(const OBJ_NAME *nm, void *arg)
+       {
+       struct doall_cipher *dc = arg;
+       if (nm->alias)
+               dc->fn(NULL, nm->name, nm->data, dc->arg);
+       else
+               dc->fn((const EVP_CIPHER *)nm->data, nm->name, NULL, dc->arg);
+       }
+
+void EVP_CIPHER_do_all(void (*fn)(const EVP_CIPHER *ciph,
+               const char *from, const char *to, void *x), void *arg)
+       {
+       struct doall_cipher dc;
+       dc.fn = fn;
+       dc.arg = arg;
+       OBJ_NAME_do_all(OBJ_NAME_TYPE_CIPHER_METH, do_all_cipher_fn, &dc);
+       }
+
+void EVP_CIPHER_do_all_sorted(void (*fn)(const EVP_CIPHER *ciph,
+               const char *from, const char *to, void *x), void *arg)
+       {
+       struct doall_cipher dc;
+       dc.fn = fn;
+       dc.arg = arg;
+       OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_CIPHER_METH, do_all_cipher_fn,&dc);
+       }
+
+struct doall_md
+       {
+       void *arg;
+       void (*fn)(const EVP_MD *ciph,
+                       const char *from, const char *to, void *arg);
+       };
+
+static void do_all_md_fn(const OBJ_NAME *nm, void *arg)
+       {
+       struct doall_md *dc = arg;
+       if (nm->alias)
+               dc->fn(NULL, nm->name, nm->data, dc->arg);
+       else
+               dc->fn((const EVP_MD *)nm->data, nm->name, NULL, dc->arg);
+       }
+
+void EVP_MD_do_all(void (*fn)(const EVP_MD *md,
+               const char *from, const char *to, void *x), void *arg)
+       {
+       struct doall_md dc;
+       dc.fn = fn;
+       dc.arg = arg;
+       OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH, do_all_md_fn, &dc);
+       }
+
+void EVP_MD_do_all_sorted(void (*fn)(const EVP_MD *md,
+               const char *from, const char *to, void *x), void *arg)
+       {
+       struct doall_md dc;
+       dc.fn = fn;
+       dc.arg = arg;
+       OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_MD_METH, do_all_md_fn, &dc);
        }
index 2a265fd..7ecfa8d 100644 (file)
 #include <openssl/x509.h>
 #include <openssl/evp.h>
 
-/* PKCS#5 v1.5 compatible PBE functions: see PKCS#5 v2.0 for more info.
+/* Doesn't do anything now: Builtin PBE algorithms in static table.
  */
 
 void PKCS5_PBE_add(void)
 {
-#ifndef OPENSSL_NO_DES
-#  ifndef OPENSSL_NO_MD5
-EVP_PBE_alg_add(NID_pbeWithMD5AndDES_CBC, EVP_des_cbc(), EVP_md5(),
-                                                        PKCS5_PBE_keyivgen);
-#  endif
-#  ifndef OPENSSL_NO_MD2
-EVP_PBE_alg_add(NID_pbeWithMD2AndDES_CBC, EVP_des_cbc(), EVP_md2(),
-                                                        PKCS5_PBE_keyivgen);
-#  endif
-#  ifndef OPENSSL_NO_SHA
-EVP_PBE_alg_add(NID_pbeWithSHA1AndDES_CBC, EVP_des_cbc(), EVP_sha1(),
-                                                        PKCS5_PBE_keyivgen);
-#  endif
-#endif
-#ifndef OPENSSL_NO_RC2
-#  ifndef OPENSSL_NO_MD5
-EVP_PBE_alg_add(NID_pbeWithMD5AndRC2_CBC, EVP_rc2_64_cbc(), EVP_md5(),
-                                                        PKCS5_PBE_keyivgen);
-#  endif
-#  ifndef OPENSSL_NO_MD2
-EVP_PBE_alg_add(NID_pbeWithMD2AndRC2_CBC, EVP_rc2_64_cbc(), EVP_md2(),
-                                                        PKCS5_PBE_keyivgen);
-#  endif
-#  ifndef OPENSSL_NO_SHA
-EVP_PBE_alg_add(NID_pbeWithSHA1AndRC2_CBC, EVP_rc2_64_cbc(), EVP_sha1(),
-                                                        PKCS5_PBE_keyivgen);
-#  endif
-#endif
-#ifndef OPENSSL_NO_HMAC
-EVP_PBE_alg_add(NID_pbes2, NULL, NULL, PKCS5_v2_PBE_keyivgen);
-#endif
 }
 
 int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
@@ -112,6 +81,7 @@ int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
        int saltlen, iter;
        unsigned char *salt;
        const unsigned char *pbuf;
+       int mdsize;
 
        /* Extract useful info from parameter */
        if (param == NULL || param->type != V_ASN1_SEQUENCE ||
@@ -140,9 +110,12 @@ int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
        EVP_DigestUpdate(&ctx, salt, saltlen);
        PBEPARAM_free(pbe);
        EVP_DigestFinal_ex(&ctx, md_tmp, NULL);
+       mdsize = EVP_MD_size(md);
+       if (mdsize < 0)
+           return 0;
        for (i = 1; i < iter; i++) {
                EVP_DigestInit_ex(&ctx, md, NULL);
-               EVP_DigestUpdate(&ctx, md_tmp, EVP_MD_size(md));
+               EVP_DigestUpdate(&ctx, md_tmp, mdsize);
                EVP_DigestFinal_ex (&ctx, md_tmp, NULL);
        }
        EVP_MD_CTX_cleanup(&ctx);
index 6bec77b..334379f 100644 (file)
@@ -3,7 +3,7 @@
  * project 1999.
  */
 /* ====================================================================
- * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #endif
 
 /* This is an implementation of PKCS#5 v2.0 password based encryption key
- * derivation function PBKDF2 using the only currently defined function HMAC
- * with SHA1. Verified against test vectors posted by Peter Gutmann
+ * derivation function PBKDF2.
+ * SHA1 version verified against test vectors posted by Peter Gutmann
  * <pgut001@cs.auckland.ac.nz> to the PKCS-TNG <pkcs-tng@rsa.com> mailing list.
  */
 
-int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
+int PKCS5_PBKDF2_HMAC(const char *pass, int passlen,
                           const unsigned char *salt, int saltlen, int iter,
+                          const EVP_MD *digest,
                           int keylen, unsigned char *out)
-{
-       unsigned char digtmp[SHA_DIGEST_LENGTH], *p, itmp[4];
-       int cplen, j, k, tkeylen;
+       {
+       unsigned char digtmp[EVP_MAX_MD_SIZE], *p, itmp[4];
+       int cplen, j, k, tkeylen, mdlen;
        unsigned long i = 1;
        HMAC_CTX hctx;
 
+       mdlen = EVP_MD_size(digest);
+       if (mdlen < 0)
+               return 0;
+
        HMAC_CTX_init(&hctx);
        p = out;
        tkeylen = keylen;
-       if(!pass) passlen = 0;
-       else if(passlen == -1) passlen = strlen(pass);
-       while(tkeylen) {
-               if(tkeylen > SHA_DIGEST_LENGTH) cplen = SHA_DIGEST_LENGTH;
-               else cplen = tkeylen;
+       if(!pass)
+               passlen = 0;
+       else if(passlen == -1)
+               passlen = strlen(pass);
+       while(tkeylen)
+               {
+               if(tkeylen > mdlen)
+                       cplen = mdlen;
+               else
+                       cplen = tkeylen;
                /* We are unlikely to ever use more than 256 blocks (5120 bits!)
                 * but just in case...
                 */
@@ -100,20 +110,22 @@ int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
                itmp[1] = (unsigned char)((i >> 16) & 0xff);
                itmp[2] = (unsigned char)((i >> 8) & 0xff);
                itmp[3] = (unsigned char)(i & 0xff);
-               HMAC_Init_ex(&hctx, pass, passlen, EVP_sha1(), NULL);
+               HMAC_Init_ex(&hctx, pass, passlen, digest, NULL);
                HMAC_Update(&hctx, salt, saltlen);
                HMAC_Update(&hctx, itmp, 4);
                HMAC_Final(&hctx, digtmp, NULL);
                memcpy(p, digtmp, cplen);
-               for(j = 1; j < iter; j++) {
-                       HMAC(EVP_sha1(), pass, passlen,
-                                digtmp, SHA_DIGEST_LENGTH, digtmp, NULL);
-                       for(k = 0; k < cplen; k++) p[k] ^= digtmp[k];
-               }
+               for(j = 1; j < iter; j++)
+                       {
+                       HMAC(digest, pass, passlen,
+                                digtmp, mdlen, digtmp, NULL);
+                       for(k = 0; k < cplen; k++)
+                               p[k] ^= digtmp[k];
+                       }
                tkeylen-= cplen;
                i++;
                p+= cplen;
-       }
+               }
        HMAC_CTX_cleanup(&hctx);
 #ifdef DEBUG_PKCS5V2
        fprintf(stderr, "Password:\n");
@@ -125,7 +137,15 @@ int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
        h__dump (out, keylen);
 #endif
        return 1;
-}
+       }
+
+int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
+                          const unsigned char *salt, int saltlen, int iter,
+                          int keylen, unsigned char *out)
+       {
+       return PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, iter, EVP_sha1(),
+                                       keylen, out);
+       }
 
 #ifdef DO_TEST
 main()
@@ -155,6 +175,8 @@ int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
        PBE2PARAM *pbe2 = NULL;
        const EVP_CIPHER *cipher;
        PBKDF2PARAM *kdf = NULL;
+       const EVP_MD *prfmd;
+       int prf_nid, hmac_md_nid;
 
        if (param == NULL || param->type != V_ASN1_SEQUENCE ||
            param->value.sequence == NULL) {
@@ -180,8 +202,7 @@ int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
        /* lets see if we recognise the encryption algorithm.
         */
 
-       cipher = EVP_get_cipherbyname(
-                       OBJ_nid2sn(OBJ_obj2nid(pbe2->encryption->algorithm)));
+       cipher = EVP_get_cipherbyobj(pbe2->encryption->algorithm);
 
        if(!cipher) {
                EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
@@ -226,10 +247,23 @@ int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
                goto err;
        }
 
-       if(kdf->prf && (OBJ_obj2nid(kdf->prf->algorithm) != NID_hmacWithSHA1)) {
+       if (kdf->prf)
+               prf_nid = OBJ_obj2nid(kdf->prf->algorithm);
+       else
+               prf_nid = NID_hmacWithSHA1;
+
+       if (!EVP_PBE_find(EVP_PBE_TYPE_PRF, prf_nid, NULL, &hmac_md_nid, 0))
+               {
                EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, EVP_R_UNSUPPORTED_PRF);
                goto err;
-       }
+               }
+
+       prfmd = EVP_get_digestbynid(hmac_md_nid);
+       if (prfmd == NULL)
+               {
+               EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, EVP_R_UNSUPPORTED_PRF);
+               goto err;
+               }
 
        if(kdf->salt->type != V_ASN1_OCTET_STRING) {
                EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
@@ -241,7 +275,9 @@ int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
        salt = kdf->salt->value.octet_string->data;
        saltlen = kdf->salt->value.octet_string->length;
        iter = ASN1_INTEGER_get(kdf->iter);
-       PKCS5_PBKDF2_HMAC_SHA1(pass, passlen, salt, saltlen, iter, keylen, key);
+       if(!PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, iter, prfmd,
+                                                  keylen, key))
+               goto err;
        EVP_CipherInit_ex(ctx, NULL, NULL, key, NULL, en_de);
        OPENSSL_cleanse(key, keylen);
        PBKDF2PARAM_free(kdf);
index f64901f..4201dcb 100644 (file)
@@ -66,7 +66,7 @@
 #include <openssl/objects.h>
 #include <openssl/x509.h>
 
-int EVP_PKEY_decrypt(unsigned char *key, const unsigned char *ek, int ekl,
+int EVP_PKEY_decrypt_old(unsigned char *key, const unsigned char *ek, int ekl,
             EVP_PKEY *priv)
        {
        int ret= -1;
@@ -75,7 +75,7 @@ int EVP_PKEY_decrypt(unsigned char *key, const unsigned char *ek, int ekl,
        if (priv->type != EVP_PKEY_RSA)
                {
 #endif
-               EVPerr(EVP_F_EVP_PKEY_DECRYPT,EVP_R_PUBLIC_KEY_NOT_RSA);
+               EVPerr(EVP_F_EVP_PKEY_DECRYPT_OLD,EVP_R_PUBLIC_KEY_NOT_RSA);
 #ifndef OPENSSL_NO_RSA
                goto err;
                 }
index c2dfdc5..b5a3a84 100644 (file)
@@ -66,7 +66,7 @@
 #include <openssl/objects.h>
 #include <openssl/x509.h>
 
-int EVP_PKEY_encrypt(unsigned char *ek, const unsigned char *key, int key_len,
+int EVP_PKEY_encrypt_old(unsigned char *ek, const unsigned char *key, int key_len,
             EVP_PKEY *pubk)
        {
        int ret=0;
@@ -75,7 +75,7 @@ int EVP_PKEY_encrypt(unsigned char *ek, const unsigned char *key, int key_len,
        if (pubk->type != EVP_PKEY_RSA)
                {
 #endif
-               EVPerr(EVP_F_EVP_PKEY_ENCRYPT,EVP_R_PUBLIC_KEY_NOT_RSA);
+               EVPerr(EVP_F_EVP_PKEY_ENCRYPT_OLD,EVP_R_PUBLIC_KEY_NOT_RSA);
 #ifndef OPENSSL_NO_RSA
                goto err;
                }
index 22155ec..e26ccd0 100644 (file)
 #include <openssl/dh.h>
 #endif
 
+#ifndef OPENSSL_NO_ENGINE
+#include <openssl/engine.h>
+#endif
+
+#include "asn1_locl.h"
+
 static void EVP_PKEY_free_it(EVP_PKEY *x);
 
 int EVP_PKEY_bits(EVP_PKEY *pkey)
        {
-       if (0)
-               return 0;
-#ifndef OPENSSL_NO_RSA
-       else if (pkey->type == EVP_PKEY_RSA)
-               return(BN_num_bits(pkey->pkey.rsa->n));
-#endif
-#ifndef OPENSSL_NO_DSA
-       else if (pkey->type == EVP_PKEY_DSA)
-               return(BN_num_bits(pkey->pkey.dsa->p));
-#endif
-#ifndef OPENSSL_NO_EC
-       else if (pkey->type == EVP_PKEY_EC)
-               {
-               BIGNUM *order = BN_new();
-               const EC_GROUP *group;
-               int ret;
-
-               if (!order)
-                       {
-                       ERR_clear_error();
-                       return 0;
-                       }
-               group = EC_KEY_get0_group(pkey->pkey.ec);
-               if (!EC_GROUP_get_order(group, order, NULL))
-                       {
-                       ERR_clear_error();
-                       return 0;
-                       }
-
-               ret = BN_num_bits(order);
-               BN_free(order);
-               return ret;
-               }
-#endif
-       return(0);
+       if (pkey && pkey->ameth && pkey->ameth->pkey_bits)
+               return pkey->ameth->pkey_bits(pkey);
+       return 0;
        }
 
 int EVP_PKEY_size(EVP_PKEY *pkey)
        {
-       if (pkey == NULL)
-               return(0);
-#ifndef OPENSSL_NO_RSA
-       if (pkey->type == EVP_PKEY_RSA)
-               return(RSA_size(pkey->pkey.rsa));
-       else
-#endif
-#ifndef OPENSSL_NO_DSA
-               if (pkey->type == EVP_PKEY_DSA)
-               return(DSA_size(pkey->pkey.dsa));
-#endif
-#ifndef OPENSSL_NO_ECDSA
-               if (pkey->type == EVP_PKEY_EC)
-               return(ECDSA_size(pkey->pkey.ec));
-#endif
-
-       return(0);
+       if (pkey && pkey->ameth && pkey->ameth->pkey_size)
+               return pkey->ameth->pkey_size(pkey);
+       return 0;
        }
 
 int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode)
@@ -174,88 +134,26 @@ int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)
                EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_MISSING_PARAMETERS);
                goto err;
                }
-#ifndef OPENSSL_NO_DSA
-       if (to->type == EVP_PKEY_DSA)
-               {
-               BIGNUM *a;
-
-               if ((a=BN_dup(from->pkey.dsa->p)) == NULL) goto err;
-               if (to->pkey.dsa->p != NULL) BN_free(to->pkey.dsa->p);
-               to->pkey.dsa->p=a;
-
-               if ((a=BN_dup(from->pkey.dsa->q)) == NULL) goto err;
-               if (to->pkey.dsa->q != NULL) BN_free(to->pkey.dsa->q);
-               to->pkey.dsa->q=a;
-
-               if ((a=BN_dup(from->pkey.dsa->g)) == NULL) goto err;
-               if (to->pkey.dsa->g != NULL) BN_free(to->pkey.dsa->g);
-               to->pkey.dsa->g=a;
-               }
-#endif
-#ifndef OPENSSL_NO_EC
-       if (to->type == EVP_PKEY_EC)
-               {
-               EC_GROUP *group = EC_GROUP_dup(EC_KEY_get0_group(from->pkey.ec));
-               if (group == NULL)
-                       goto err;
-               if (EC_KEY_set_group(to->pkey.ec, group) == 0)
-                       goto err;
-               EC_GROUP_free(group);
-               }
-#endif
-       return(1);
+       if (from->ameth && from->ameth->param_copy)
+               return from->ameth->param_copy(to, from);
 err:
-       return(0);
+       return 0;
        }
 
 int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey)
        {
-#ifndef OPENSSL_NO_DSA
-       if (pkey->type == EVP_PKEY_DSA)
-               {
-               DSA *dsa;
-
-               dsa=pkey->pkey.dsa;
-               if ((dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL))
-                       return(1);
-               }
-#endif
-#ifndef OPENSSL_NO_EC
-       if (pkey->type == EVP_PKEY_EC)
-               {
-               if (EC_KEY_get0_group(pkey->pkey.ec) == NULL)
-                       return(1);
-               }
-#endif
-
-       return(0);
+       if (pkey->ameth && pkey->ameth->param_missing)
+               return pkey->ameth->param_missing(pkey);
+       return 0;
        }
 
 int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b)
        {
-#ifndef OPENSSL_NO_DSA
-       if ((a->type == EVP_PKEY_DSA) && (b->type == EVP_PKEY_DSA))
-               {
-               if (    BN_cmp(a->pkey.dsa->p,b->pkey.dsa->p) ||
-                       BN_cmp(a->pkey.dsa->q,b->pkey.dsa->q) ||
-                       BN_cmp(a->pkey.dsa->g,b->pkey.dsa->g))
-                       return(0);
-               else
-                       return(1);
-               }
-#endif
-#ifndef OPENSSL_NO_EC
-       if (a->type == EVP_PKEY_EC && b->type == EVP_PKEY_EC)
-               {
-               const EC_GROUP *group_a = EC_KEY_get0_group(a->pkey.ec),
-                              *group_b = EC_KEY_get0_group(b->pkey.ec);
-               if (EC_GROUP_cmp(group_a, group_b, NULL))
-                       return 0;
-               else
-                       return 1;
-               }
-#endif
-       return(-1);
+       if (a->type != b->type)
+               return -1;
+       if (a->ameth && a->ameth->param_cmp)
+               return a->ameth->param_cmp(a, b);
+       return -2;
        }
 
 int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b)
@@ -263,51 +161,22 @@ int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b)
        if (a->type != b->type)
                return -1;
 
-       if (EVP_PKEY_cmp_parameters(a, b) == 0)
-               return 0;
-
-       switch (a->type)
+       if (a->ameth)
                {
-#ifndef OPENSSL_NO_RSA
-       case EVP_PKEY_RSA:
-               if (BN_cmp(b->pkey.rsa->n,a->pkey.rsa->n) != 0
-                       || BN_cmp(b->pkey.rsa->e,a->pkey.rsa->e) != 0)
-                       return 0;
-               break;
-#endif
-#ifndef OPENSSL_NO_DSA
-       case EVP_PKEY_DSA:
-               if (BN_cmp(b->pkey.dsa->pub_key,a->pkey.dsa->pub_key) != 0)
-                       return 0;
-               break;
-#endif
-#ifndef OPENSSL_NO_EC
-       case EVP_PKEY_EC:
-               {
-               int  r;
-               const EC_GROUP *group = EC_KEY_get0_group(b->pkey.ec);
-               const EC_POINT *pa = EC_KEY_get0_public_key(a->pkey.ec),
-                              *pb = EC_KEY_get0_public_key(b->pkey.ec);
-               r = EC_POINT_cmp(group, pa, pb, NULL);
-               if (r != 0)
+               int ret;
+               /* Compare parameters if the algorithm has them */
+               if (a->ameth->param_cmp)
                        {
-                       if (r == 1)
-                               return 0;
-                       else
-                               return -2;
+                       ret = a->ameth->param_cmp(a, b);
+                       if (ret <= 0)
+                               return ret;
                        }
-               }
-               break;
-#endif
-#ifndef OPENSSL_NO_DH
-       case EVP_PKEY_DH:
-               return -2;
-#endif
-       default:
-               return -2;
+
+               if (a->ameth->pub_cmp)
+                       return a->ameth->pub_cmp(a, b);
                }
 
-       return 1;
+       return -2;
        }
 
 EVP_PKEY *EVP_PKEY_new(void)
@@ -321,22 +190,87 @@ EVP_PKEY *EVP_PKEY_new(void)
                return(NULL);
                }
        ret->type=EVP_PKEY_NONE;
+       ret->save_type=EVP_PKEY_NONE;
        ret->references=1;
+       ret->ameth=NULL;
+       ret->engine=NULL;
        ret->pkey.ptr=NULL;
        ret->attributes=NULL;
        ret->save_parameters=1;
        return(ret);
        }
 
-int EVP_PKEY_assign(EVP_PKEY *pkey, int type, char *key)
+/* Setup a public key ASN1 method and ENGINE from a NID or a string.
+ * If pkey is NULL just return 1 or 0 if the algorithm exists.
+ */
+
+static int pkey_set_type(EVP_PKEY *pkey, int type, const char *str, int len)
+       {
+       const EVP_PKEY_ASN1_METHOD *ameth;
+       ENGINE *e = NULL;
+       if (pkey)
+               {
+               if (pkey->pkey.ptr)
+                       EVP_PKEY_free_it(pkey);
+               /* If key type matches and a method exists then this
+                * lookup has succeeded once so just indicate success.
+                */
+               if ((type == pkey->save_type) && pkey->ameth)
+                       return 1;
+#ifndef OPENSSL_NO_ENGINE
+               /* If we have an ENGINE release it */
+               if (pkey->engine)
+                       {
+                       ENGINE_finish(pkey->engine);
+                       pkey->engine = NULL;
+                       }
+#endif
+               }
+       if (str)
+               ameth = EVP_PKEY_asn1_find_str(&e, str, len);
+       else
+               ameth = EVP_PKEY_asn1_find(&e, type);
+#ifndef OPENSSL_NO_ENGINE
+       if (!pkey && e)
+               ENGINE_finish(e);
+#endif
+       if (!ameth)
+               {
+               EVPerr(EVP_F_PKEY_SET_TYPE, EVP_R_UNSUPPORTED_ALGORITHM);
+               return 0;
+               }
+       if (pkey)
+               {
+               pkey->ameth = ameth;
+               pkey->engine = e;
+
+               pkey->type = pkey->ameth->pkey_id;
+               pkey->save_type=type;
+               }
+       return 1;
+       }
+
+int EVP_PKEY_set_type(EVP_PKEY *pkey, int type)
+       {
+       return pkey_set_type(pkey, type, NULL, -1);
+       }
+
+int EVP_PKEY_set_type_str(EVP_PKEY *pkey, const char *str, int len)
        {
-       if (pkey == NULL) return(0);
-       if (pkey->pkey.ptr != NULL)
-               EVP_PKEY_free_it(pkey);
-       pkey->type=EVP_PKEY_type(type);
-       pkey->save_type=type;
+       return pkey_set_type(pkey, EVP_PKEY_NONE, str, len);
+       }
+
+int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key)
+       {
+       if (!EVP_PKEY_set_type(pkey, type))
+               return 0;
        pkey->pkey.ptr=key;
-       return(key != NULL);
+       return (key != NULL);
+       }
+
+void *EVP_PKEY_get0(EVP_PKEY *pkey)
+       {
+       return pkey->pkey.ptr;
        }
 
 #ifndef OPENSSL_NO_RSA
@@ -425,24 +359,29 @@ DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey)
 
 int EVP_PKEY_type(int type)
        {
-       switch (type)
-               {
-       case EVP_PKEY_RSA:
-       case EVP_PKEY_RSA2:
-               return(EVP_PKEY_RSA);
-       case EVP_PKEY_DSA:
-       case EVP_PKEY_DSA1:
-       case EVP_PKEY_DSA2:
-       case EVP_PKEY_DSA3:
-       case EVP_PKEY_DSA4:
-               return(EVP_PKEY_DSA);
-       case EVP_PKEY_DH:
-               return(EVP_PKEY_DH);
-       case EVP_PKEY_EC:
-               return(EVP_PKEY_EC);
-       default:
-               return(NID_undef);
-               }
+       int ret;
+       const EVP_PKEY_ASN1_METHOD *ameth;
+       ENGINE *e;
+       ameth = EVP_PKEY_asn1_find(&e, type);
+       if (ameth)
+               ret = ameth->pkey_id;
+       else
+               ret = NID_undef;
+#ifndef OPENSSL_NO_ENGINE
+       if (e)
+               ENGINE_finish(e);
+#endif
+       return ret;
+       }
+
+int EVP_PKEY_id(const EVP_PKEY *pkey)
+       {
+       return pkey->type;
+       }
+
+int EVP_PKEY_base_id(const EVP_PKEY *pkey)
+       {
+       return EVP_PKEY_type(pkey->type);
        }
 
 void EVP_PKEY_free(EVP_PKEY *x)
@@ -471,32 +410,60 @@ void EVP_PKEY_free(EVP_PKEY *x)
 
 static void EVP_PKEY_free_it(EVP_PKEY *x)
        {
-       switch (x->type)
+       if (x->ameth && x->ameth->pkey_free)
                {
-#ifndef OPENSSL_NO_RSA
-       case EVP_PKEY_RSA:
-       case EVP_PKEY_RSA2:
-               RSA_free(x->pkey.rsa);
-               break;
-#endif
-#ifndef OPENSSL_NO_DSA
-       case EVP_PKEY_DSA:
-       case EVP_PKEY_DSA2:
-       case EVP_PKEY_DSA3:
-       case EVP_PKEY_DSA4:
-               DSA_free(x->pkey.dsa);
-               break;
-#endif
-#ifndef OPENSSL_NO_EC
-       case EVP_PKEY_EC:
-               EC_KEY_free(x->pkey.ec);
-               break;
-#endif
-#ifndef OPENSSL_NO_DH
-       case EVP_PKEY_DH:
-               DH_free(x->pkey.dh);
-               break;
-#endif
+               x->ameth->pkey_free(x);
+               x->pkey.ptr = NULL;
+               }
+#ifndef OPENSSL_NO_ENGINE
+       if (x->engine)
+               {
+               ENGINE_finish(x->engine);
+               x->engine = NULL;
                }
+#endif
+       }
+
+static int unsup_alg(BIO *out, const EVP_PKEY *pkey, int indent,
+                               const char *kstr)
+       {
+       BIO_indent(out, indent, 128);
+       BIO_printf(out, "%s algorithm \"%s\" unsupported\n",
+                                               kstr, OBJ_nid2ln(pkey->type));
+       return 1;
+       }
+
+int EVP_PKEY_print_public(BIO *out, const EVP_PKEY *pkey,
+                               int indent, ASN1_PCTX *pctx)
+       {
+       if (pkey->ameth && pkey->ameth->pub_print)
+               return pkey->ameth->pub_print(out, pkey, indent, pctx);
+       
+       return unsup_alg(out, pkey, indent, "Public Key");
+       }
+
+int EVP_PKEY_print_private(BIO *out, const EVP_PKEY *pkey,
+                               int indent, ASN1_PCTX *pctx)
+       {
+       if (pkey->ameth && pkey->ameth->priv_print)
+               return pkey->ameth->priv_print(out, pkey, indent, pctx);
+       
+       return unsup_alg(out, pkey, indent, "Private Key");
+       }
+
+int EVP_PKEY_print_params(BIO *out, const EVP_PKEY *pkey,
+                               int indent, ASN1_PCTX *pctx)
+       {
+       if (pkey->ameth && pkey->ameth->param_print)
+               return pkey->ameth->param_print(out, pkey, indent, pctx);
+       return unsup_alg(out, pkey, indent, "Parameters");
+       }
+
+int EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid)
+       {
+       if (!pkey->ameth || !pkey->ameth->pkey_ctrl)
+               return -2;
+       return pkey->ameth->pkey_ctrl(pkey, ASN1_PKEY_CTRL_DEFAULT_MD_NID,
+                                               0, pnid);
        }
 
index 9935206..53a59a2 100644 (file)
@@ -95,7 +95,7 @@ int EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
                goto err;
                }
 
-       i=EVP_PKEY_decrypt(key,ek,ekl,priv);
+       i=EVP_PKEY_decrypt_old(key,ek,ekl,priv);
        if ((i <= 0) || !EVP_CIPHER_CTX_set_key_length(ctx, i))
                {
                /* ERROR */
index 8cc8fcb..d832452 100644 (file)
@@ -87,7 +87,7 @@ int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, unsigned char **ek
 
        for (i=0; i<npubk; i++)
                {
-               ekl[i]=EVP_PKEY_encrypt(ek[i],key,EVP_CIPHER_CTX_key_length(ctx),
+               ekl[i]=EVP_PKEY_encrypt_old(ek[i],key,EVP_CIPHER_CTX_key_length(ctx),
                        pubk[i]);
                if (ekl[i] <= 0) return(-1);
                }
index 782d140..bb893f5 100644 (file)
@@ -84,6 +84,32 @@ int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen,
        EVP_MD_CTX tmp_ctx;
 
        *siglen=0;
+       EVP_MD_CTX_init(&tmp_ctx);
+       EVP_MD_CTX_copy_ex(&tmp_ctx,ctx);   
+       EVP_DigestFinal_ex(&tmp_ctx,&(m[0]),&m_len);
+       EVP_MD_CTX_cleanup(&tmp_ctx);
+
+       if (ctx->digest->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE)
+               {
+               EVP_PKEY_CTX *pkctx = NULL;
+               size_t sltmp = (size_t)EVP_PKEY_size(pkey);
+               i = 0;
+               pkctx = EVP_PKEY_CTX_new(pkey, NULL);
+               if (!pkctx)
+                       goto err;
+               if (EVP_PKEY_sign_init(pkctx) <= 0)
+                       goto err;
+               if (EVP_PKEY_CTX_set_signature_md(pkctx, ctx->digest) <= 0)
+                       goto err;
+               if (EVP_PKEY_sign(pkctx, sigret, &sltmp, m, m_len) <= 0)
+                       goto err;
+               *siglen = sltmp;
+               i = 1;
+               err:
+               EVP_PKEY_CTX_free(pkctx);
+               return i;
+               }
+
        for (i=0; i<4; i++)
                {
                v=ctx->digest->required_pkey_type[i];
@@ -99,28 +125,13 @@ int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen,
                EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE);
                return(0);
                }
+
        if (ctx->digest->sign == NULL)
                {
                EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_NO_SIGN_FUNCTION_CONFIGURED);
                return(0);
                }
-       EVP_MD_CTX_init(&tmp_ctx);
-       EVP_MD_CTX_copy_ex(&tmp_ctx,ctx);
-       if (ctx->digest->flags & EVP_MD_FLAG_SVCTX)
-               {
-               EVP_MD_SVCTX sctmp;
-               sctmp.mctx = &tmp_ctx;
-               sctmp.key = pkey->pkey.ptr;
-               i = ctx->digest->sign(ctx->digest->type,
-                       NULL, -1, sigret, siglen, &sctmp);
-               }
-       else
-               {
-               EVP_DigestFinal_ex(&tmp_ctx,&(m[0]),&m_len);
-               i = ctx->digest->sign(ctx->digest->type,m,m_len,sigret,siglen,
-                                       pkey->pkey.ptr);
-               }
-       EVP_MD_CTX_cleanup(&tmp_ctx);
-       return i;
+       return(ctx->digest->sign(ctx->digest->type,m,m_len,sigret,siglen,
+               pkey->pkey.ptr));
        }
 
index 072c127..41d4b67 100644 (file)
@@ -70,6 +70,28 @@ int EVP_VerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sigbuf,
        int i,ok=0,v;
        EVP_MD_CTX tmp_ctx;
 
+       EVP_MD_CTX_init(&tmp_ctx);
+       EVP_MD_CTX_copy_ex(&tmp_ctx,ctx);     
+       EVP_DigestFinal_ex(&tmp_ctx,&(m[0]),&m_len);
+       EVP_MD_CTX_cleanup(&tmp_ctx);
+
+       if (ctx->digest->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE)
+               {
+               EVP_PKEY_CTX *pkctx = NULL;
+               i = -1;
+               pkctx = EVP_PKEY_CTX_new(pkey, NULL);
+               if (!pkctx)
+                       goto err;
+               if (EVP_PKEY_verify_init(pkctx) <= 0)
+                       goto err;
+               if (EVP_PKEY_CTX_set_signature_md(pkctx, ctx->digest) <= 0)
+                       goto err;
+               i = EVP_PKEY_verify(pkctx, sigbuf, siglen, m, m_len);
+               err:
+               EVP_PKEY_CTX_free(pkctx);
+               return i;
+               }
+
        for (i=0; i<4; i++)
                {
                v=ctx->digest->required_pkey_type[i];
@@ -85,29 +107,13 @@ int EVP_VerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sigbuf,
                EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE);
                return(-1);
                }
-       if (ctx->digest->verify == NULL)
+        if (ctx->digest->verify == NULL)
                 {
                EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_NO_VERIFY_FUNCTION_CONFIGURED);
                return(0);
                }
 
-       EVP_MD_CTX_init(&tmp_ctx);
-       EVP_MD_CTX_copy_ex(&tmp_ctx,ctx);     
-       if (ctx->digest->flags & EVP_MD_FLAG_SVCTX)
-               {
-               EVP_MD_SVCTX sctmp;
-               sctmp.mctx = &tmp_ctx;
-               sctmp.key = pkey->pkey.ptr;
-               i = ctx->digest->verify(ctx->digest->type,
-                       NULL, -1, sigbuf, siglen, &sctmp);
-               }
-       else
-               {
-               EVP_DigestFinal_ex(&tmp_ctx,&(m[0]),&m_len);
-               i = ctx->digest->verify(ctx->digest->type,m,m_len,
-                                       sigbuf,siglen,pkey->pkey.ptr);
-               }
-       EVP_MD_CTX_cleanup(&tmp_ctx);
-       return i;
+       return(ctx->digest->verify(ctx->digest->type,m,m_len,
+               sigbuf,siglen,pkey->pkey.ptr));
        }
 
diff --git a/deps/openssl/openssl/crypto/evp/pmeth_fn.c b/deps/openssl/openssl/crypto/evp/pmeth_fn.c
new file mode 100644 (file)
index 0000000..c4676f2
--- /dev/null
@@ -0,0 +1,368 @@
+/* pmeth_fn.c */
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project 2006.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "cryptlib.h"
+#include <openssl/objects.h>
+#include <openssl/evp.h>
+#include "evp_locl.h"
+
+#define M_check_autoarg(ctx, arg, arglen, err) \
+       if (ctx->pmeth->flags & EVP_PKEY_FLAG_AUTOARGLEN) \
+               { \
+               size_t pksize = (size_t)EVP_PKEY_size(ctx->pkey); \
+               if (!arg) \
+                       { \
+                       *arglen = pksize; \
+                       return 1; \
+                       } \
+               else if (*arglen < pksize) \
+                       { \
+                       EVPerr(err, EVP_R_BUFFER_TOO_SMALL); /*ckerr_ignore*/\
+                       return 0; \
+                       } \
+               }
+
+int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx)
+       {
+       int ret;
+       if (!ctx || !ctx->pmeth || !ctx->pmeth->sign)
+               {
+               EVPerr(EVP_F_EVP_PKEY_SIGN_INIT,
+                       EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
+               return -2;
+               }
+       ctx->operation = EVP_PKEY_OP_SIGN;
+       if (!ctx->pmeth->sign_init)
+               return 1;
+       ret = ctx->pmeth->sign_init(ctx);
+       if (ret <= 0)
+               ctx->operation = EVP_PKEY_OP_UNDEFINED;
+       return ret;
+       }
+
+int EVP_PKEY_sign(EVP_PKEY_CTX *ctx,
+                       unsigned char *sig, size_t *siglen,
+                       const unsigned char *tbs, size_t tbslen)
+       {
+       if (!ctx || !ctx->pmeth || !ctx->pmeth->sign)
+               {
+               EVPerr(EVP_F_EVP_PKEY_SIGN,
+                       EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
+               return -2;
+               }
+       if (ctx->operation != EVP_PKEY_OP_SIGN)
+               {
+               EVPerr(EVP_F_EVP_PKEY_SIGN, EVP_R_OPERATON_NOT_INITIALIZED);
+               return -1;
+               }
+       M_check_autoarg(ctx, sig, siglen, EVP_F_EVP_PKEY_SIGN)
+       return ctx->pmeth->sign(ctx, sig, siglen, tbs, tbslen);
+       }
+
+int EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx)
+       {
+       int ret;
+       if (!ctx || !ctx->pmeth || !ctx->pmeth->verify)
+               {
+               EVPerr(EVP_F_EVP_PKEY_VERIFY_INIT,
+                       EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
+               return -2;
+               }
+       ctx->operation = EVP_PKEY_OP_VERIFY;
+       if (!ctx->pmeth->verify_init)
+               return 1;
+       ret = ctx->pmeth->verify_init(ctx);
+       if (ret <= 0)
+               ctx->operation = EVP_PKEY_OP_UNDEFINED;
+       return ret;
+       }
+
+int EVP_PKEY_verify(EVP_PKEY_CTX *ctx,
+                       const unsigned char *sig, size_t siglen,
+                       const unsigned char *tbs, size_t tbslen)
+       {
+       if (!ctx || !ctx->pmeth || !ctx->pmeth->verify)
+               {
+               EVPerr(EVP_F_EVP_PKEY_VERIFY,
+                       EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
+               return -2;
+               }
+       if (ctx->operation != EVP_PKEY_OP_VERIFY)
+               {
+               EVPerr(EVP_F_EVP_PKEY_VERIFY, EVP_R_OPERATON_NOT_INITIALIZED);
+               return -1;
+               }
+       return ctx->pmeth->verify(ctx, sig, siglen, tbs, tbslen);
+       }
+
+int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx)
+       {
+       int ret;
+       if (!ctx || !ctx->pmeth || !ctx->pmeth->verify_recover)
+               {
+               EVPerr(EVP_F_EVP_PKEY_VERIFY_RECOVER_INIT,
+                       EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
+               return -2;
+               }
+       ctx->operation = EVP_PKEY_OP_VERIFYRECOVER;
+       if (!ctx->pmeth->verify_recover_init)
+               return 1;
+       ret = ctx->pmeth->verify_recover_init(ctx);
+       if (ret <= 0)
+               ctx->operation = EVP_PKEY_OP_UNDEFINED;
+       return ret;
+       }
+
+int EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx,
+                       unsigned char *rout, size_t *routlen,
+                       const unsigned char *sig, size_t siglen)
+       {
+       if (!ctx || !ctx->pmeth || !ctx->pmeth->verify_recover)
+               {
+               EVPerr(EVP_F_EVP_PKEY_VERIFY_RECOVER,
+                       EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
+               return -2;
+               }
+       if (ctx->operation != EVP_PKEY_OP_VERIFYRECOVER)
+               {
+               EVPerr(EVP_F_EVP_PKEY_VERIFY_RECOVER, EVP_R_OPERATON_NOT_INITIALIZED);
+               return -1;
+               }
+       M_check_autoarg(ctx, rout, routlen, EVP_F_EVP_PKEY_VERIFY_RECOVER)
+       return ctx->pmeth->verify_recover(ctx, rout, routlen, sig, siglen);
+       }
+
+int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx)
+       {
+       int ret;
+       if (!ctx || !ctx->pmeth || !ctx->pmeth->encrypt)
+               {
+               EVPerr(EVP_F_EVP_PKEY_ENCRYPT_INIT,
+                       EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
+               return -2;
+               }
+       ctx->operation = EVP_PKEY_OP_ENCRYPT;
+       if (!ctx->pmeth->encrypt_init)
+               return 1;
+       ret = ctx->pmeth->encrypt_init(ctx);
+       if (ret <= 0)
+               ctx->operation = EVP_PKEY_OP_UNDEFINED;
+       return ret;
+       }
+
+int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx,
+                       unsigned char *out, size_t *outlen,
+                       const unsigned char *in, size_t inlen)
+       {
+       if (!ctx || !ctx->pmeth || !ctx->pmeth->encrypt)
+               {
+               EVPerr(EVP_F_EVP_PKEY_ENCRYPT,
+                       EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
+               return -2;
+               }
+       if (ctx->operation != EVP_PKEY_OP_ENCRYPT)
+               {
+               EVPerr(EVP_F_EVP_PKEY_ENCRYPT, EVP_R_OPERATON_NOT_INITIALIZED);
+               return -1;
+               }
+       M_check_autoarg(ctx, out, outlen, EVP_F_EVP_PKEY_ENCRYPT)
+       return ctx->pmeth->encrypt(ctx, out, outlen, in, inlen);
+       }
+
+int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx)
+       {
+       int ret;
+       if (!ctx || !ctx->pmeth || !ctx->pmeth->decrypt)
+               {
+               EVPerr(EVP_F_EVP_PKEY_DECRYPT_INIT,
+                       EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
+               return -2;
+               }
+       ctx->operation = EVP_PKEY_OP_DECRYPT;
+       if (!ctx->pmeth->decrypt_init)
+               return 1;
+       ret = ctx->pmeth->decrypt_init(ctx);
+       if (ret <= 0)
+               ctx->operation = EVP_PKEY_OP_UNDEFINED;
+       return ret;
+       }
+
+int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx,
+                       unsigned char *out, size_t *outlen,
+                       const unsigned char *in, size_t inlen)
+       {
+       if (!ctx || !ctx->pmeth || !ctx->pmeth->decrypt)
+               {
+               EVPerr(EVP_F_EVP_PKEY_DECRYPT,
+                       EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
+               return -2;
+               }
+       if (ctx->operation != EVP_PKEY_OP_DECRYPT)
+               {
+               EVPerr(EVP_F_EVP_PKEY_DECRYPT, EVP_R_OPERATON_NOT_INITIALIZED);
+               return -1;
+               }
+       M_check_autoarg(ctx, out, outlen, EVP_F_EVP_PKEY_DECRYPT)
+       return ctx->pmeth->decrypt(ctx, out, outlen, in, inlen);
+       }
+
+
+int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx)
+       {
+       int ret;
+       if (!ctx || !ctx->pmeth || !ctx->pmeth->derive)
+               {
+               EVPerr(EVP_F_EVP_PKEY_DERIVE_INIT,
+                       EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
+               return -2;
+               }
+       ctx->operation = EVP_PKEY_OP_DERIVE;
+       if (!ctx->pmeth->derive_init)
+               return 1;
+       ret = ctx->pmeth->derive_init(ctx);
+       if (ret <= 0)
+               ctx->operation = EVP_PKEY_OP_UNDEFINED;
+       return ret;
+       }
+
+int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer)
+       {
+       int ret;
+       if (!ctx || !ctx->pmeth || !(ctx->pmeth->derive||ctx->pmeth->encrypt||ctx->pmeth->decrypt) || !ctx->pmeth->ctrl)
+               {
+               EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER,
+                       EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
+               return -2;
+               }
+       if (ctx->operation != EVP_PKEY_OP_DERIVE && ctx->operation != EVP_PKEY_OP_ENCRYPT && ctx->operation != EVP_PKEY_OP_DECRYPT)
+               {
+               EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER,
+                                       EVP_R_OPERATON_NOT_INITIALIZED);
+               return -1;
+               }
+
+       ret = ctx->pmeth->ctrl(ctx, EVP_PKEY_CTRL_PEER_KEY, 0, peer);
+
+       if (ret <= 0)
+               return ret;
+
+       if (ret == 2)
+               return 1;
+
+       if (!ctx->pkey)
+               {
+               EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER, EVP_R_NO_KEY_SET);
+               return -1;
+               }
+
+       if (ctx->pkey->type != peer->type)
+               {
+               EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER,
+                                               EVP_R_DIFFERENT_KEY_TYPES);
+               return -1;
+               }
+
+       /* ran@cryptocom.ru: For clarity.  The error is if parameters in peer are
+        * present (!missing) but don't match.  EVP_PKEY_cmp_parameters may return
+        * 1 (match), 0 (don't match) and -2 (comparison is not defined).  -1
+        * (different key types) is impossible here because it is checked earlier.
+        * -2 is OK for us here, as well as 1, so we can check for 0 only. */
+       if (!EVP_PKEY_missing_parameters(peer) &&
+               !EVP_PKEY_cmp_parameters(ctx->pkey, peer))
+               {
+               EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER,
+                                               EVP_R_DIFFERENT_PARAMETERS);
+               return -1;
+               }
+
+       if (ctx->peerkey)
+               EVP_PKEY_free(ctx->peerkey);
+       ctx->peerkey = peer;
+
+       ret = ctx->pmeth->ctrl(ctx, EVP_PKEY_CTRL_PEER_KEY, 1, peer);
+
+       if (ret <= 0)
+               {
+               ctx->peerkey = NULL;
+               return ret;
+               }
+
+       CRYPTO_add(&peer->references,1,CRYPTO_LOCK_EVP_PKEY);
+       return 1;
+       }
+
+
+int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *pkeylen)
+       {
+       if (!ctx || !ctx->pmeth || !ctx->pmeth->derive)
+               {
+               EVPerr(EVP_F_EVP_PKEY_DERIVE,
+                       EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
+               return -2;
+               }
+       if (ctx->operation != EVP_PKEY_OP_DERIVE)
+               {
+               EVPerr(EVP_F_EVP_PKEY_DERIVE, EVP_R_OPERATON_NOT_INITIALIZED);
+               return -1;
+               }
+       M_check_autoarg(ctx, key, pkeylen, EVP_F_EVP_PKEY_DERIVE)
+       return ctx->pmeth->derive(ctx, key, pkeylen);
+       }
+
diff --git a/deps/openssl/openssl/crypto/evp/pmeth_gn.c b/deps/openssl/openssl/crypto/evp/pmeth_gn.c
new file mode 100644 (file)
index 0000000..5d74161
--- /dev/null
@@ -0,0 +1,220 @@
+/* pmeth_gn.c */
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project 2006.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "cryptlib.h"
+#include <openssl/objects.h>
+#include <openssl/evp.h>
+#include <openssl/bn.h>
+#include "evp_locl.h"
+
+int EVP_PKEY_paramgen_init(EVP_PKEY_CTX *ctx)
+       {
+       int ret;
+       if (!ctx || !ctx->pmeth || !ctx->pmeth->paramgen)
+               {
+               EVPerr(EVP_F_EVP_PKEY_PARAMGEN_INIT,
+                       EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
+               return -2;
+               }
+       ctx->operation = EVP_PKEY_OP_PARAMGEN;
+       if (!ctx->pmeth->paramgen_init)
+               return 1;
+       ret = ctx->pmeth->paramgen_init(ctx);
+       if (ret <= 0)
+               ctx->operation = EVP_PKEY_OP_UNDEFINED;
+       return ret;
+       }
+
+int EVP_PKEY_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey)
+       {
+       int ret;
+       if (!ctx || !ctx->pmeth || !ctx->pmeth->paramgen)
+               {
+               EVPerr(EVP_F_EVP_PKEY_PARAMGEN,
+                       EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
+               return -2;
+               }
+
+       if (ctx->operation != EVP_PKEY_OP_PARAMGEN)
+               {
+               EVPerr(EVP_F_EVP_PKEY_PARAMGEN, EVP_R_OPERATON_NOT_INITIALIZED);
+               return -1;
+               }
+
+       if (!ppkey)
+               return -1;
+
+       if (!*ppkey)
+               *ppkey = EVP_PKEY_new();
+
+       ret = ctx->pmeth->paramgen(ctx, *ppkey);
+       if (ret <= 0)
+               {
+               EVP_PKEY_free(*ppkey);
+               *ppkey = NULL;
+               }
+       return ret;
+       }
+
+int EVP_PKEY_keygen_init(EVP_PKEY_CTX *ctx)
+       {
+       int ret;
+       if (!ctx || !ctx->pmeth || !ctx->pmeth->keygen)
+               {
+               EVPerr(EVP_F_EVP_PKEY_KEYGEN_INIT,
+                       EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
+               return -2;
+               }
+       ctx->operation = EVP_PKEY_OP_KEYGEN;
+       if (!ctx->pmeth->keygen_init)
+               return 1;
+       ret = ctx->pmeth->keygen_init(ctx);
+       if (ret <= 0)
+               ctx->operation = EVP_PKEY_OP_UNDEFINED;
+       return ret;
+       }
+
+int EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey)
+       {
+       int ret;
+
+       if (!ctx || !ctx->pmeth || !ctx->pmeth->keygen)
+               {
+               EVPerr(EVP_F_EVP_PKEY_KEYGEN,
+                       EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
+               return -2;
+               }
+       if (ctx->operation != EVP_PKEY_OP_KEYGEN)
+               {
+               EVPerr(EVP_F_EVP_PKEY_KEYGEN, EVP_R_OPERATON_NOT_INITIALIZED);
+               return -1;
+               }
+
+       if (!ppkey)
+               return -1;
+
+       if (!*ppkey)
+               *ppkey = EVP_PKEY_new();
+
+       ret = ctx->pmeth->keygen(ctx, *ppkey);
+       if (ret <= 0)
+               {
+               EVP_PKEY_free(*ppkey);
+               *ppkey = NULL;
+               }
+       return ret;
+       }
+
+void EVP_PKEY_CTX_set_cb(EVP_PKEY_CTX *ctx, EVP_PKEY_gen_cb *cb)
+       {
+       ctx->pkey_gencb = cb;
+       }
+
+EVP_PKEY_gen_cb *EVP_PKEY_CTX_get_cb(EVP_PKEY_CTX *ctx)
+       {
+       return ctx->pkey_gencb;
+       }
+
+/* "translation callback" to call EVP_PKEY_CTX callbacks using BN_GENCB
+ * style callbacks.
+ */
+
+static int trans_cb(int a, int b, BN_GENCB *gcb)
+       {
+       EVP_PKEY_CTX *ctx = gcb->arg;
+       ctx->keygen_info[0] = a;
+       ctx->keygen_info[1] = b;
+       return ctx->pkey_gencb(ctx);
+       }       
+
+void evp_pkey_set_cb_translate(BN_GENCB *cb, EVP_PKEY_CTX *ctx)
+       {
+       BN_GENCB_set(cb, trans_cb, ctx)
+       }
+
+int EVP_PKEY_CTX_get_keygen_info(EVP_PKEY_CTX *ctx, int idx)
+       {
+       if (idx == -1)
+               return ctx->keygen_info_count; 
+       if (idx < 0 || idx > ctx->keygen_info_count)
+               return 0;
+       return ctx->keygen_info[idx];
+       }
+
+EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e,
+                               unsigned char *key, int keylen)
+       {
+       EVP_PKEY_CTX *mac_ctx = NULL;
+       EVP_PKEY *mac_key = NULL;
+       mac_ctx = EVP_PKEY_CTX_new_id(type, e);
+       if (!mac_ctx)
+               return NULL;
+       if (EVP_PKEY_keygen_init(mac_ctx) <= 0)
+               goto merr;
+       if (EVP_PKEY_CTX_ctrl(mac_ctx, -1, EVP_PKEY_OP_KEYGEN,
+                               EVP_PKEY_CTRL_SET_MAC_KEY, keylen, key) <= 0)
+               goto merr;
+       if (EVP_PKEY_keygen(mac_ctx, &mac_key) <= 0)
+               goto merr;
+       merr:
+       if (mac_ctx)
+               EVP_PKEY_CTX_free(mac_ctx);
+       return mac_key;
+       }
diff --git a/deps/openssl/openssl/crypto/evp/pmeth_lib.c b/deps/openssl/openssl/crypto/evp/pmeth_lib.c
new file mode 100644 (file)
index 0000000..5481d4b
--- /dev/null
@@ -0,0 +1,540 @@
+/* pmeth_lib.c */
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project 2006.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "cryptlib.h"
+#include <openssl/objects.h>
+#include <openssl/evp.h>
+#ifndef OPENSSL_NO_ENGINE
+#include <openssl/engine.h>
+#endif
+#include "asn1_locl.h"
+#include "evp_locl.h"
+
+typedef int sk_cmp_fn_type(const char * const *a, const char * const *b);
+
+DECLARE_STACK_OF(EVP_PKEY_METHOD)
+STACK_OF(EVP_PKEY_METHOD) *app_pkey_methods = NULL;
+
+extern const EVP_PKEY_METHOD rsa_pkey_meth, dh_pkey_meth, dsa_pkey_meth;
+extern const EVP_PKEY_METHOD ec_pkey_meth, hmac_pkey_meth;
+
+static const EVP_PKEY_METHOD *standard_methods[] =
+       {
+#ifndef OPENSSL_NO_RSA
+       &rsa_pkey_meth,
+#endif
+#ifndef OPENSSL_NO_DH
+       &dh_pkey_meth,
+#endif
+#ifndef OPENSSL_NO_DSA
+       &dsa_pkey_meth,
+#endif
+#ifndef OPENSSL_NO_EC
+       &ec_pkey_meth,
+#endif
+       &hmac_pkey_meth,
+       };
+
+DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *,
+                          pmeth);
+
+static int pmeth_cmp(const EVP_PKEY_METHOD * const *a,
+                    const EVP_PKEY_METHOD * const *b)
+       {
+        return ((*a)->pkey_id - (*b)->pkey_id);
+       }
+
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *,
+                            pmeth);
+
+const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type)
+       {
+       EVP_PKEY_METHOD tmp;
+       const EVP_PKEY_METHOD *t = &tmp, **ret;
+       tmp.pkey_id = type;
+       if (app_pkey_methods)
+               {
+               int idx;
+               idx = sk_EVP_PKEY_METHOD_find(app_pkey_methods, &tmp);
+               if (idx >= 0)
+                       return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx);
+               }
+       ret = OBJ_bsearch_pmeth(&t, standard_methods,
+                         sizeof(standard_methods)/sizeof(EVP_PKEY_METHOD *));
+       if (!ret || !*ret)
+               return NULL;
+       return *ret;
+       }
+
+static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
+       {
+       EVP_PKEY_CTX *ret;
+       const EVP_PKEY_METHOD *pmeth;
+       if (id == -1)
+               {
+               if (!pkey || !pkey->ameth)
+                       return NULL;
+               id = pkey->ameth->pkey_id;
+               }
+#ifndef OPENSSL_NO_ENGINE
+       if (pkey && pkey->engine)
+               e = pkey->engine;
+       /* Try to find an ENGINE which implements this method */
+       if (e)
+               {
+               if (!ENGINE_init(e))
+                       {
+                       EVPerr(EVP_F_INT_CTX_NEW,ERR_R_ENGINE_LIB);
+                       return NULL;
+                       }
+               }
+       else
+               e = ENGINE_get_pkey_meth_engine(id);
+
+       /* If an ENGINE handled this method look it up. Othewise
+        * use internal tables.
+        */
+
+       if (e)
+               pmeth = ENGINE_get_pkey_meth(e, id);
+       else
+#endif
+               pmeth = EVP_PKEY_meth_find(id);
+
+       if (pmeth == NULL)
+               {
+               EVPerr(EVP_F_INT_CTX_NEW,EVP_R_UNSUPPORTED_ALGORITHM);
+               return NULL;
+               }
+
+       ret = OPENSSL_malloc(sizeof(EVP_PKEY_CTX));
+       if (!ret)
+               {
+#ifndef OPENSSL_NO_ENGINE
+               if (e)
+                       ENGINE_finish(e);
+#endif
+               EVPerr(EVP_F_INT_CTX_NEW,ERR_R_MALLOC_FAILURE);
+               return NULL;
+               }
+       ret->engine = e;
+       ret->pmeth = pmeth;
+       ret->operation = EVP_PKEY_OP_UNDEFINED;
+       ret->pkey = pkey;
+       ret->peerkey = NULL;
+       ret->pkey_gencb = 0;
+       if (pkey)
+               CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
+       ret->data = NULL;
+
+       if (pmeth->init)
+               {
+               if (pmeth->init(ret) <= 0)
+                       {
+                       EVP_PKEY_CTX_free(ret);
+                       return NULL;
+                       }
+               }
+
+       return ret;
+       }
+
+EVP_PKEY_METHOD* EVP_PKEY_meth_new(int id, int flags)
+       {
+       EVP_PKEY_METHOD *pmeth;
+       pmeth = OPENSSL_malloc(sizeof(EVP_PKEY_METHOD));
+       if (!pmeth)
+               return NULL;
+
+       pmeth->pkey_id = id;
+       pmeth->flags = flags | EVP_PKEY_FLAG_DYNAMIC;
+
+       pmeth->init = 0;
+       pmeth->copy = 0;
+       pmeth->cleanup = 0;
+       pmeth->paramgen_init = 0;
+       pmeth->paramgen = 0;
+       pmeth->keygen_init = 0;
+       pmeth->keygen = 0;
+       pmeth->sign_init = 0;
+       pmeth->sign = 0;
+       pmeth->verify_init = 0;
+       pmeth->verify = 0;
+       pmeth->verify_recover_init = 0;
+       pmeth->verify_recover = 0;
+       pmeth->signctx_init = 0;
+       pmeth->signctx = 0;
+       pmeth->verifyctx_init = 0;
+       pmeth->verifyctx = 0;
+       pmeth->encrypt_init = 0;
+       pmeth->encrypt = 0;
+       pmeth->decrypt_init = 0;
+       pmeth->decrypt = 0;
+       pmeth->derive_init = 0;
+       pmeth->derive = 0;
+       pmeth->ctrl = 0;
+       pmeth->ctrl_str = 0;
+
+       return pmeth;
+       }
+
+void EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth)
+       {
+       if (pmeth && (pmeth->flags & EVP_PKEY_FLAG_DYNAMIC))
+               OPENSSL_free(pmeth);
+       }
+
+EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e)
+       {
+       return int_ctx_new(pkey, e, -1);
+       }
+
+EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e)
+       {
+       return int_ctx_new(NULL, e, id);
+       }
+
+EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *pctx)
+       {
+       EVP_PKEY_CTX *rctx;
+       if (!pctx->pmeth || !pctx->pmeth->copy)
+               return NULL;
+#ifndef OPENSSL_NO_ENGINE
+       /* Make sure it's safe to copy a pkey context using an ENGINE */
+       if (pctx->engine && !ENGINE_init(pctx->engine))
+               {
+               EVPerr(EVP_F_EVP_PKEY_CTX_DUP,ERR_R_ENGINE_LIB);
+               return 0;
+               }
+#endif
+       rctx = OPENSSL_malloc(sizeof(EVP_PKEY_CTX));
+       if (!rctx)
+               return NULL;
+
+       rctx->pmeth = pctx->pmeth;
+#ifndef OPENSSL_NO_ENGINE
+       rctx->engine = pctx->engine;
+#endif
+
+       if (pctx->pkey)
+               CRYPTO_add(&pctx->pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
+
+       rctx->pkey = pctx->pkey;
+
+       if (pctx->peerkey)
+               CRYPTO_add(&pctx->peerkey->references,1,CRYPTO_LOCK_EVP_PKEY);
+
+       rctx->peerkey = pctx->peerkey;
+
+       rctx->data = NULL;
+       rctx->app_data = NULL;
+       rctx->operation = pctx->operation;
+
+       if (pctx->pmeth->copy(rctx, pctx) > 0)
+               return rctx;
+
+       EVP_PKEY_CTX_free(rctx);
+       return NULL;
+
+       }
+
+int EVP_PKEY_meth_add0(const EVP_PKEY_METHOD *pmeth)
+       {
+       if (app_pkey_methods == NULL)
+               {
+               app_pkey_methods = sk_EVP_PKEY_METHOD_new(pmeth_cmp);
+               if (!app_pkey_methods)
+                       return 0;
+               }
+       if (!sk_EVP_PKEY_METHOD_push(app_pkey_methods, pmeth))
+               return 0;
+       sk_EVP_PKEY_METHOD_sort(app_pkey_methods);
+       return 1;
+       }
+
+void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx)
+       {
+       if (ctx == NULL)
+               return;
+       if (ctx->pmeth && ctx->pmeth->cleanup)
+               ctx->pmeth->cleanup(ctx);
+       if (ctx->pkey)
+               EVP_PKEY_free(ctx->pkey);
+       if (ctx->peerkey)
+               EVP_PKEY_free(ctx->peerkey);
+#ifndef OPENSSL_NO_ENGINE
+       if(ctx->engine)
+               /* The EVP_PKEY_CTX we used belongs to an ENGINE, release the
+                * functional reference we held for this reason. */
+               ENGINE_finish(ctx->engine);
+#endif
+       OPENSSL_free(ctx);
+       }
+
+int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,
+                               int cmd, int p1, void *p2)
+       {
+       int ret;
+       if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl)
+               {
+               EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED);
+               return -2;
+               }
+       if ((keytype != -1) && (ctx->pmeth->pkey_id != keytype))
+               return -1;
+
+       if (ctx->operation == EVP_PKEY_OP_UNDEFINED)
+               {
+               EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_NO_OPERATION_SET);
+               return -1;
+               }
+
+       if ((optype != -1) && !(ctx->operation & optype))
+               {
+               EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_INVALID_OPERATION);
+               return -1;
+               }
+
+       ret = ctx->pmeth->ctrl(ctx, cmd, p1, p2);
+
+       if (ret == -2)
+               EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED);
+
+       return ret;
+
+       }
+
+int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx,
+                                       const char *name, const char *value)
+       {
+       if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl_str)
+               {
+               EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR,
+                                               EVP_R_COMMAND_NOT_SUPPORTED);
+               return -2;
+               }
+       if (!strcmp(name, "digest"))
+               {
+               const EVP_MD *md;
+               if (!value || !(md = EVP_get_digestbyname(value)))
+                       {
+                       EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR,
+                                               EVP_R_INVALID_DIGEST);
+                       return 0;
+                       }
+               return EVP_PKEY_CTX_set_signature_md(ctx, md);
+               }
+       return ctx->pmeth->ctrl_str(ctx, name, value);
+       }
+
+int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx)
+       {
+       return ctx->operation;
+       }
+
+void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX *ctx, int *dat, int datlen)
+       {
+       ctx->keygen_info = dat;
+       ctx->keygen_info_count = datlen;
+       }
+
+void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX *ctx, void *data)
+       {
+       ctx->data = data;
+       }
+
+void *EVP_PKEY_CTX_get_data(EVP_PKEY_CTX *ctx)
+       {
+       return ctx->data;
+       }
+
+EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx)
+       {
+       return ctx->pkey;
+       }
+
+EVP_PKEY *EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX *ctx)
+       {
+       return ctx->peerkey;
+       }
+       
+void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data)
+       {
+       ctx->app_data = data;
+       }
+
+void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx)
+       {
+       return ctx->app_data;
+       }
+
+void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD *pmeth,
+       int (*init)(EVP_PKEY_CTX *ctx))
+       {
+       pmeth->init = init;
+       }
+
+void EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD *pmeth,
+       int (*copy)(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src))
+       {
+       pmeth->copy = copy;
+       }
+
+void EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD *pmeth,
+       void (*cleanup)(EVP_PKEY_CTX *ctx))
+       {
+       pmeth->cleanup = cleanup;
+       }
+
+void EVP_PKEY_meth_set_paramgen(EVP_PKEY_METHOD *pmeth,
+       int (*paramgen_init)(EVP_PKEY_CTX *ctx),
+       int (*paramgen)(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey))
+       {
+       pmeth->paramgen_init = paramgen_init;
+       pmeth->paramgen = paramgen;
+       }
+
+void EVP_PKEY_meth_set_keygen(EVP_PKEY_METHOD *pmeth,
+       int (*keygen_init)(EVP_PKEY_CTX *ctx),
+       int (*keygen)(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey))
+       {
+       pmeth->keygen_init = keygen_init;
+       pmeth->keygen = keygen;
+       }
+
+void EVP_PKEY_meth_set_sign(EVP_PKEY_METHOD *pmeth,
+       int (*sign_init)(EVP_PKEY_CTX *ctx),
+       int (*sign)(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
+                                       const unsigned char *tbs, size_t tbslen))
+       {
+       pmeth->sign_init = sign_init;
+       pmeth->sign = sign;
+       }
+
+void EVP_PKEY_meth_set_verify(EVP_PKEY_METHOD *pmeth,
+       int (*verify_init)(EVP_PKEY_CTX *ctx),
+       int (*verify)(EVP_PKEY_CTX *ctx, const unsigned char *sig, size_t siglen,
+                                       const unsigned char *tbs, size_t tbslen))
+       {
+       pmeth->verify_init = verify_init;
+       pmeth->verify = verify;
+       }
+
+void EVP_PKEY_meth_set_verify_recover(EVP_PKEY_METHOD *pmeth,
+       int (*verify_recover_init)(EVP_PKEY_CTX *ctx),
+       int (*verify_recover)(EVP_PKEY_CTX *ctx,
+                                       unsigned char *sig, size_t *siglen,
+                                       const unsigned char *tbs, size_t tbslen))
+       {
+       pmeth->verify_recover_init = verify_recover_init;
+       pmeth->verify_recover = verify_recover;
+       }
+
+void EVP_PKEY_meth_set_signctx(EVP_PKEY_METHOD *pmeth,
+       int (*signctx_init)(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx),
+       int (*signctx)(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
+                                       EVP_MD_CTX *mctx))
+       {
+       pmeth->signctx_init = signctx_init;
+       pmeth->signctx = signctx;
+       }
+
+void EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD *pmeth,
+       int (*verifyctx_init)(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx),
+       int (*verifyctx)(EVP_PKEY_CTX *ctx, const unsigned char *sig,int siglen,
+                                       EVP_MD_CTX *mctx))
+       {
+       pmeth->verifyctx_init = verifyctx_init;
+       pmeth->verifyctx = verifyctx;
+       }
+
+void EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD *pmeth,
+       int (*encrypt_init)(EVP_PKEY_CTX *ctx),
+       int (*encryptfn)(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
+                                       const unsigned char *in, size_t inlen))
+       {
+       pmeth->encrypt_init = encrypt_init;
+       pmeth->encrypt = encryptfn;
+       }
+
+void EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD *pmeth,
+       int (*decrypt_init)(EVP_PKEY_CTX *ctx),
+       int (*decrypt)(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
+                                       const unsigned char *in, size_t inlen))
+       {
+       pmeth->decrypt_init = decrypt_init;
+       pmeth->decrypt = decrypt;
+       }
+
+void EVP_PKEY_meth_set_derive(EVP_PKEY_METHOD *pmeth,
+       int (*derive_init)(EVP_PKEY_CTX *ctx),
+       int (*derive)(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen))
+       {
+       pmeth->derive_init = derive_init;
+       pmeth->derive = derive;
+       }
+
+void EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD *pmeth,
+       int (*ctrl)(EVP_PKEY_CTX *ctx, int type, int p1, void *p2),
+       int (*ctrl_str)(EVP_PKEY_CTX *ctx, const char *type, const char *value))
+       {
+       pmeth->ctrl = ctrl;
+       pmeth->ctrl_str = ctrl_str;
+       }
index 3b11e7a..e2bc829 100644 (file)
@@ -245,18 +245,21 @@ typedef struct st_ex_class_item {
 static int ex_class = CRYPTO_EX_INDEX_USER;
 
 /* The global hash table of EX_CLASS_ITEM items */
-static LHASH *ex_data = NULL;
+DECLARE_LHASH_OF(EX_CLASS_ITEM);
+static LHASH_OF(EX_CLASS_ITEM) *ex_data = NULL;
 
 /* The callbacks required in the "ex_data" hash table */
-static unsigned long ex_hash_cb(const void *a_void)
+static unsigned long ex_class_item_hash(const EX_CLASS_ITEM *a)
        {
-       return ((const EX_CLASS_ITEM *)a_void)->class_index;
+       return a->class_index;
        }
-static int ex_cmp_cb(const void *a_void, const void *b_void)
+static IMPLEMENT_LHASH_HASH_FN(ex_class_item, EX_CLASS_ITEM)
+
+static int ex_class_item_cmp(const EX_CLASS_ITEM *a, const EX_CLASS_ITEM *b)
        {
-       return (((const EX_CLASS_ITEM *)a_void)->class_index -
-               ((const EX_CLASS_ITEM *)b_void)->class_index);
+       return a->class_index - b->class_index;
        }
+static IMPLEMENT_LHASH_COMP_FN(ex_class_item, EX_CLASS_ITEM)
 
 /* Internal functions used by the "impl_default" implementation to access the
  * state */
@@ -265,7 +268,8 @@ static int ex_data_check(void)
        {
        int toret = 1;
        CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA);
-       if(!ex_data && ((ex_data = lh_new(ex_hash_cb, ex_cmp_cb)) == NULL))
+       if(!ex_data
+          && (ex_data = lh_EX_CLASS_ITEM_new()) == NULL)
                toret = 0;
        CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA);
        return toret;
@@ -298,7 +302,7 @@ static EX_CLASS_ITEM *def_get_class(int class_index)
        EX_DATA_CHECK(return NULL;)
        d.class_index = class_index;
        CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA);
-       p = lh_retrieve(ex_data, &d);
+       p = lh_EX_CLASS_ITEM_retrieve(ex_data, &d);
        if(!p)
                {
                gen = OPENSSL_malloc(sizeof(EX_CLASS_ITEM));
@@ -313,7 +317,7 @@ static EX_CLASS_ITEM *def_get_class(int class_index)
                                {
                                /* Because we're inside the ex_data lock, the
                                 * return value from the insert will be NULL */
-                               lh_insert(ex_data, gen);
+                               (void)lh_EX_CLASS_ITEM_insert(ex_data, gen);
                                p = gen;
                                }
                        }
@@ -375,8 +379,8 @@ static int int_new_class(void)
 static void int_cleanup(void)
        {
        EX_DATA_CHECK(return;)
-       lh_doall(ex_data, def_cleanup_cb);
-       lh_free(ex_data);
+       lh_EX_CLASS_ITEM_doall(ex_data, def_cleanup_cb);
+       lh_EX_CLASS_ITEM_free(ex_data);
        ex_data = NULL;
        impl = NULL;
        }
@@ -452,7 +456,7 @@ static int int_dup_ex_data(int class_index, CRYPTO_EX_DATA *to,
                return 0;
        CRYPTO_r_lock(CRYPTO_LOCK_EX_DATA);
        mx = sk_CRYPTO_EX_DATA_FUNCS_num(item->meth);
-       j = sk_num(from->sk);
+       j = sk_void_num(from->sk);
        if(j < mx)
                mx = j;
        if(mx > 0)
@@ -523,7 +527,7 @@ skip:
                OPENSSL_free(storage);
        if(ad->sk)
                {
-               sk_free(ad->sk);
+               sk_void_free(ad->sk);
                ad->sk=NULL;
                }
        }
@@ -596,24 +600,24 @@ int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val)
 
        if (ad->sk == NULL)
                {
-               if ((ad->sk=sk_new_null()) == NULL)
+               if ((ad->sk=sk_void_new_null()) == NULL)
                        {
                        CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA,ERR_R_MALLOC_FAILURE);
                        return(0);
                        }
                }
-       i=sk_num(ad->sk);
+       i=sk_void_num(ad->sk);
 
        while (i <= idx)
                {
-               if (!sk_push(ad->sk,NULL))
+               if (!sk_void_push(ad->sk,NULL))
                        {
                        CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA,ERR_R_MALLOC_FAILURE);
                        return(0);
                        }
                i++;
                }
-       sk_set(ad->sk,idx,val);
+       sk_void_set(ad->sk,idx,val);
        return(1);
        }
 
@@ -623,10 +627,10 @@ void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)
        {
        if (ad->sk == NULL)
                return(0);
-       else if (idx >= sk_num(ad->sk))
+       else if (idx >= sk_void_num(ad->sk))
                return(0);
        else
-               return(sk_value(ad->sk,idx));
+               return(sk_void_value(ad->sk,idx));
        }
 
 IMPLEMENT_STACK_OF(CRYPTO_EX_DATA_FUNCS)
diff --git a/deps/openssl/openssl/crypto/fips_err.c b/deps/openssl/openssl/crypto/fips_err.c
deleted file mode 100644 (file)
index 09f1174..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#include <openssl/opensslconf.h>
-
-#ifdef OPENSSL_FIPS
-# include "fips_err.h"
-#else
-static void *dummy=&dummy;
-#endif
diff --git a/deps/openssl/openssl/crypto/fips_err.h b/deps/openssl/openssl/crypto/fips_err.h
deleted file mode 100644 (file)
index b328616..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-/* crypto/fips_err.h */
-/* ====================================================================
- * Copyright (c) 1999-2007 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    openssl-core@OpenSSL.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
- * ====================================================================
- *
- * This product includes cryptographic software written by Eric Young
- * (eay@cryptsoft.com).  This product includes software written by Tim
- * Hudson (tjh@cryptsoft.com).
- *
- */
-
-/* NOTE: this file was auto generated by the mkerr.pl script: any changes
- * made to it will be overwritten when the script next updates this file,
- * only reason strings will be preserved.
- */
-
-#include <stdio.h>
-#include <openssl/err.h>
-#include <openssl/fips.h>
-
-/* BEGIN ERROR CODES */
-#ifndef OPENSSL_NO_ERR
-
-#define ERR_FUNC(func) ERR_PACK(ERR_LIB_FIPS,func,0)
-#define ERR_REASON(reason) ERR_PACK(ERR_LIB_FIPS,0,reason)
-
-static ERR_STRING_DATA FIPS_str_functs[]=
-       {
-{ERR_FUNC(FIPS_F_DH_BUILTIN_GENPARAMS),        "DH_BUILTIN_GENPARAMS"},
-{ERR_FUNC(FIPS_F_DSA_BUILTIN_PARAMGEN),        "DSA_BUILTIN_PARAMGEN"},
-{ERR_FUNC(FIPS_F_DSA_DO_SIGN), "DSA_do_sign"},
-{ERR_FUNC(FIPS_F_DSA_DO_VERIFY),       "DSA_do_verify"},
-{ERR_FUNC(FIPS_F_EVP_CIPHERINIT_EX),   "EVP_CipherInit_ex"},
-{ERR_FUNC(FIPS_F_EVP_DIGESTINIT_EX),   "EVP_DigestInit_ex"},
-{ERR_FUNC(FIPS_F_FIPS_CHECK_DSA),      "FIPS_CHECK_DSA"},
-{ERR_FUNC(FIPS_F_FIPS_CHECK_INCORE_FINGERPRINT),       "FIPS_CHECK_INCORE_FINGERPRINT"},
-{ERR_FUNC(FIPS_F_FIPS_CHECK_RSA),      "FIPS_CHECK_RSA"},
-{ERR_FUNC(FIPS_F_FIPS_DSA_CHECK),      "FIPS_DSA_CHECK"},
-{ERR_FUNC(FIPS_F_FIPS_MODE_SET),       "FIPS_mode_set"},
-{ERR_FUNC(FIPS_F_FIPS_PKEY_SIGNATURE_TEST),    "fips_pkey_signature_test"},
-{ERR_FUNC(FIPS_F_FIPS_SELFTEST_AES),   "FIPS_selftest_aes"},
-{ERR_FUNC(FIPS_F_FIPS_SELFTEST_DES),   "FIPS_selftest_des"},
-{ERR_FUNC(FIPS_F_FIPS_SELFTEST_DSA),   "FIPS_selftest_dsa"},
-{ERR_FUNC(FIPS_F_FIPS_SELFTEST_HMAC),  "FIPS_selftest_hmac"},
-{ERR_FUNC(FIPS_F_FIPS_SELFTEST_RNG),   "FIPS_selftest_rng"},
-{ERR_FUNC(FIPS_F_FIPS_SELFTEST_SHA1),  "FIPS_selftest_sha1"},
-{ERR_FUNC(FIPS_F_HASH_FINAL),  "HASH_FINAL"},
-{ERR_FUNC(FIPS_F_RSA_BUILTIN_KEYGEN),  "RSA_BUILTIN_KEYGEN"},
-{ERR_FUNC(FIPS_F_RSA_EAY_PRIVATE_DECRYPT),     "RSA_EAY_PRIVATE_DECRYPT"},
-{ERR_FUNC(FIPS_F_RSA_EAY_PRIVATE_ENCRYPT),     "RSA_EAY_PRIVATE_ENCRYPT"},
-{ERR_FUNC(FIPS_F_RSA_EAY_PUBLIC_DECRYPT),      "RSA_EAY_PUBLIC_DECRYPT"},
-{ERR_FUNC(FIPS_F_RSA_EAY_PUBLIC_ENCRYPT),      "RSA_EAY_PUBLIC_ENCRYPT"},
-{ERR_FUNC(FIPS_F_RSA_X931_GENERATE_KEY_EX),    "RSA_X931_generate_key_ex"},
-{ERR_FUNC(FIPS_F_SSLEAY_RAND_BYTES),   "SSLEAY_RAND_BYTES"},
-{0,NULL}
-       };
-
-static ERR_STRING_DATA FIPS_str_reasons[]=
-       {
-{ERR_REASON(FIPS_R_CANNOT_READ_EXE)      ,"cannot read exe"},
-{ERR_REASON(FIPS_R_CANNOT_READ_EXE_DIGEST),"cannot read exe digest"},
-{ERR_REASON(FIPS_R_CONTRADICTING_EVIDENCE),"contradicting evidence"},
-{ERR_REASON(FIPS_R_EXE_DIGEST_DOES_NOT_MATCH),"exe digest does not match"},
-{ERR_REASON(FIPS_R_FINGERPRINT_DOES_NOT_MATCH),"fingerprint does not match"},
-{ERR_REASON(FIPS_R_FINGERPRINT_DOES_NOT_MATCH_NONPIC_RELOCATED),"fingerprint does not match nonpic relocated"},
-{ERR_REASON(FIPS_R_FINGERPRINT_DOES_NOT_MATCH_SEGMENT_ALIASING),"fingerprint does not match segment aliasing"},
-{ERR_REASON(FIPS_R_FIPS_MODE_ALREADY_SET),"fips mode already set"},
-{ERR_REASON(FIPS_R_FIPS_SELFTEST_FAILED) ,"fips selftest failed"},
-{ERR_REASON(FIPS_R_INVALID_KEY_LENGTH)   ,"invalid key length"},
-{ERR_REASON(FIPS_R_KEY_TOO_SHORT)        ,"key too short"},
-{ERR_REASON(FIPS_R_NON_FIPS_METHOD)      ,"non fips method"},
-{ERR_REASON(FIPS_R_PAIRWISE_TEST_FAILED) ,"pairwise test failed"},
-{ERR_REASON(FIPS_R_RSA_DECRYPT_ERROR)    ,"rsa decrypt error"},
-{ERR_REASON(FIPS_R_RSA_ENCRYPT_ERROR)    ,"rsa encrypt error"},
-{ERR_REASON(FIPS_R_SELFTEST_FAILED)      ,"selftest failed"},
-{ERR_REASON(FIPS_R_TEST_FAILURE)         ,"test failure"},
-{ERR_REASON(FIPS_R_UNSUPPORTED_PLATFORM) ,"unsupported platform"},
-{0,NULL}
-       };
-
-#endif
-
-void ERR_load_FIPS_strings(void)
-       {
-#ifndef OPENSSL_NO_ERR
-
-       if (ERR_func_error_string(FIPS_str_functs[0].error) == NULL)
-               {
-               ERR_load_strings(0,FIPS_str_functs);
-               ERR_load_strings(0,FIPS_str_reasons);
-               }
-#endif
-       }
index 5cfa37d..0e91709 100644 (file)
@@ -17,8 +17,8 @@ TEST=hmactest.c
 APPS=
 
 LIB=$(TOP)/libcrypto.a
-LIBSRC=hmac.c
-LIBOBJ=hmac.o
+LIBSRC=hmac.c hm_ameth.c hm_pmeth.c
+LIBOBJ=hmac.o hm_ameth.o hm_pmeth.o
 
 SRC= $(LIBSRC)
 
@@ -33,7 +33,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -74,13 +74,37 @@ clean:
 
 # DO NOT DELETE THIS LINE -- make depend depends on it.
 
+hm_ameth.o: ../../e_os.h ../../include/openssl/asn1.h
+hm_ameth.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
+hm_ameth.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+hm_ameth.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+hm_ameth.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+hm_ameth.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+hm_ameth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+hm_ameth.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+hm_ameth.o: ../../include/openssl/symhacks.h ../asn1/asn1_locl.h ../cryptlib.h
+hm_ameth.o: hm_ameth.c
+hm_pmeth.o: ../../e_os.h ../../include/openssl/asn1.h
+hm_pmeth.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
+hm_pmeth.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
+hm_pmeth.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+hm_pmeth.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
+hm_pmeth.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+hm_pmeth.o: ../../include/openssl/hmac.h ../../include/openssl/lhash.h
+hm_pmeth.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+hm_pmeth.o: ../../include/openssl/opensslconf.h
+hm_pmeth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+hm_pmeth.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+hm_pmeth.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+hm_pmeth.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+hm_pmeth.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+hm_pmeth.o: ../cryptlib.h ../evp/evp_locl.h hm_pmeth.c
 hmac.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 hmac.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 hmac.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-hmac.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-hmac.o: ../../include/openssl/hmac.h ../../include/openssl/lhash.h
-hmac.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-hmac.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-hmac.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
-hmac.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-hmac.o: ../cryptlib.h hmac.c
+hmac.o: ../../include/openssl/evp.h ../../include/openssl/hmac.h
+hmac.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+hmac.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+hmac.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+hmac.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+hmac.o: ../../include/openssl/symhacks.h ../cryptlib.h hmac.c
similarity index 59%
rename from deps/openssl/openssl/crypto/evp/evp_cnf.c
rename to deps/openssl/openssl/crypto/hmac/hm_ameth.c
index 2e4db30..6d8a891 100644 (file)
@@ -1,5 +1,4 @@
-/* evp_cnf.c */
-/* Written by Stephen Henson (steve@openssl.org) for the OpenSSL
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
  * project 2007.
  */
 /* ====================================================================
  */
 
 #include <stdio.h>
-#include <ctype.h>
-#include <openssl/crypto.h>
 #include "cryptlib.h"
-#include <openssl/conf.h>
-#include <openssl/dso.h>
-#include <openssl/x509.h>
-#include <openssl/x509v3.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
+#include <openssl/evp.h>
+#include "asn1_locl.h"
+
+#define HMAC_TEST_PRIVATE_KEY_FORMAT
 
+/* HMAC "ASN1" method. This is just here to indicate the
+ * maximum HMAC output length and to free up an HMAC
+ * key.
+ */
 
-/* Algorithm configuration module. */
+static int hmac_size(const EVP_PKEY *pkey)
+       {
+       return EVP_MAX_MD_SIZE;
+       }
 
-static int alg_module_init(CONF_IMODULE *md, const CONF *cnf)
+static void hmac_key_free(EVP_PKEY *pkey)
        {
-       int i;
-       const char *oid_section;
-       STACK_OF(CONF_VALUE) *sktmp;
-       CONF_VALUE *oval;
-       oid_section = CONF_imodule_get_value(md);
-       if(!(sktmp = NCONF_get_section(cnf, oid_section)))
+       ASN1_OCTET_STRING *os = (ASN1_OCTET_STRING *)pkey->pkey.ptr;
+       if (os)
                {
-               EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_ERROR_LOADING_SECTION);
-               return 0;
+               if (os->data)
+                       OPENSSL_cleanse(os->data, os->length);
+               ASN1_OCTET_STRING_free(os);
                }
-       for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++)
+       }
+
+
+static int hmac_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
+       {
+       switch (op)
                {
-               oval = sk_CONF_VALUE_value(sktmp, i);
-               if (!strcmp(oval->name, "fips_mode"))
-                       {
-                       int m;
-                       if (!X509V3_get_value_bool(oval, &m))
-                               {
-                               EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_INVALID_FIPS_MODE);
-                               return 0;
-                               }
-                       if (m > 0)
-                               {
-#ifdef OPENSSL_FIPS
-                               if (!FIPS_mode() && !FIPS_mode_set(1))
-                                       {
-                                       EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_ERROR_SETTING_FIPS_MODE);
-                                       return 0;
-                                       }
-#else
-                               EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_FIPS_MODE_NOT_SUPPORTED);
-                               return 0;
-#endif
-                               }
-                       }
-               else
-                       {
-                       EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_UNKNOWN_OPTION);
-                       ERR_add_error_data(4, "name=", oval->name,
-                                               ", value=", oval->value);
-                       }
-                               
+               case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
+               *(int *)arg2 = NID_sha1;
+               return 1;
+
+               default:
+               return -2;
                }
+       }
+
+#ifdef HMAC_TEST_PRIVATE_KEY_FORMAT
+/* A bogus private key format for test purposes. This is simply the
+ * HMAC key with "HMAC PRIVATE KEY" in the headers. When enabled the
+ * genpkey utility can be used to "generate" HMAC keys.
+ */
+
+static int old_hmac_decode(EVP_PKEY *pkey,
+                                       const unsigned char **pder, int derlen)
+       {
+       ASN1_OCTET_STRING *os;
+       os = ASN1_OCTET_STRING_new();
+       if (!os || !ASN1_OCTET_STRING_set(os, *pder, derlen))
+               return 0;
+       EVP_PKEY_assign(pkey, EVP_PKEY_HMAC, os);
        return 1;
        }
 
-void EVP_add_alg_module(void)
+static int old_hmac_encode(const EVP_PKEY *pkey, unsigned char **pder)
        {
-       CONF_module_add("alg_section", alg_module_init, 0);
+       int inc;
+       ASN1_OCTET_STRING *os = (ASN1_OCTET_STRING *)pkey->pkey.ptr;
+       if (pder)
+               {
+               if (!*pder)
+                       {
+                       *pder = OPENSSL_malloc(os->length);
+                       inc = 0;
+                       }
+               else inc = 1;
+
+               memcpy(*pder, os->data, os->length);
+
+               if (inc)
+                       *pder += os->length;
+               }
+                       
+       return os->length;
        }
+
+#endif
+
+const EVP_PKEY_ASN1_METHOD hmac_asn1_meth = 
+       {
+       EVP_PKEY_HMAC,
+       EVP_PKEY_HMAC,
+       0,
+
+       "HMAC",
+       "OpenSSL HMAC method",
+
+       0,0,0,0,
+
+       0,0,0,
+
+       hmac_size,
+       0,
+       0,0,0,0,0,0,
+
+       hmac_key_free,
+       hmac_pkey_ctrl,
+#ifdef HMAC_TEST_PRIVATE_KEY_FORMAT
+       old_hmac_decode,
+       old_hmac_encode
+#else
+       0,0
+#endif
+       };
+
diff --git a/deps/openssl/openssl/crypto/hmac/hm_pmeth.c b/deps/openssl/openssl/crypto/hmac/hm_pmeth.c
new file mode 100644 (file)
index 0000000..71e8567
--- /dev/null
@@ -0,0 +1,267 @@
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project 2007.
+ */
+/* ====================================================================
+ * Copyright (c) 2007 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include "cryptlib.h"
+#include <openssl/x509.h>
+#include <openssl/x509v3.h>
+#include <openssl/evp.h>
+#include <openssl/hmac.h>
+#include "evp_locl.h"
+
+/* HMAC pkey context structure */
+
+typedef struct
+       {
+       const EVP_MD *md;       /* MD for HMAC use */
+       ASN1_OCTET_STRING ktmp; /* Temp storage for key */
+       HMAC_CTX ctx;
+       } HMAC_PKEY_CTX;
+
+static int pkey_hmac_init(EVP_PKEY_CTX *ctx)
+       {
+       HMAC_PKEY_CTX *hctx;
+       hctx = OPENSSL_malloc(sizeof(HMAC_PKEY_CTX));
+       if (!hctx)
+               return 0;
+       hctx->md = NULL;
+       hctx->ktmp.data = NULL;
+       hctx->ktmp.length = 0;
+       hctx->ktmp.flags = 0;
+       hctx->ktmp.type = V_ASN1_OCTET_STRING;
+       HMAC_CTX_init(&hctx->ctx);
+
+       ctx->data = hctx;
+       ctx->keygen_info_count = 0;
+
+       return 1;
+       }
+
+static int pkey_hmac_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
+       {
+       HMAC_PKEY_CTX *sctx, *dctx;
+       if (!pkey_hmac_init(dst))
+               return 0;
+               sctx = src->data;
+       dctx = dst->data;
+       dctx->md = sctx->md;
+       HMAC_CTX_init(&dctx->ctx);
+       HMAC_CTX_copy(&dctx->ctx, &sctx->ctx);
+       if (sctx->ktmp.data)
+               {
+               if (!ASN1_OCTET_STRING_set(&dctx->ktmp,
+                                       sctx->ktmp.data, sctx->ktmp.length))
+                       return 0;
+               }
+       return 1;
+       }
+
+static void pkey_hmac_cleanup(EVP_PKEY_CTX *ctx)
+       {
+       HMAC_PKEY_CTX *hctx = ctx->data;
+       HMAC_CTX_cleanup(&hctx->ctx);
+       if (hctx->ktmp.data)
+               {
+               if (hctx->ktmp.length)
+                       OPENSSL_cleanse(hctx->ktmp.data, hctx->ktmp.length);
+               OPENSSL_free(hctx->ktmp.data);
+               hctx->ktmp.data = NULL;
+               }
+       OPENSSL_free(hctx);
+       }
+
+static int pkey_hmac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
+       {
+       ASN1_OCTET_STRING *hkey = NULL;
+       HMAC_PKEY_CTX *hctx = ctx->data;
+       if (!hctx->ktmp.data)
+               return 0;
+       hkey = ASN1_OCTET_STRING_dup(&hctx->ktmp);
+       if (!hkey)
+               return 0;
+       EVP_PKEY_assign(pkey, EVP_PKEY_HMAC, hkey);
+       
+       return 1;
+       }
+
+static int int_update(EVP_MD_CTX *ctx,const void *data,size_t count)
+       {
+       HMAC_PKEY_CTX *hctx = ctx->pctx->data;
+       HMAC_Update(&hctx->ctx, data, count);
+       return 1;
+       }
+
+static int hmac_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)
+       {
+       HMAC_PKEY_CTX *hctx = ctx->data;
+       HMAC_CTX_set_flags(&hctx->ctx, mctx->flags & ~EVP_MD_CTX_FLAG_NO_INIT);
+       EVP_MD_CTX_set_flags(mctx, EVP_MD_CTX_FLAG_NO_INIT);
+       mctx->update = int_update;
+       return 1;
+       }
+
+static int hmac_signctx(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
+                                       EVP_MD_CTX *mctx)
+       {
+       unsigned int hlen;
+       HMAC_PKEY_CTX *hctx = ctx->data;
+       int l = EVP_MD_CTX_size(mctx);
+
+       if (l < 0)
+               return 0;
+       *siglen = l;
+       if (!sig)
+               return 1;
+
+       HMAC_Final(&hctx->ctx, sig, &hlen);
+       *siglen = (size_t)hlen;
+       return 1;
+       }
+
+static int pkey_hmac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
+       {
+       HMAC_PKEY_CTX *hctx = ctx->data;
+       ASN1_OCTET_STRING *key;
+       switch (type)
+               {
+
+               case EVP_PKEY_CTRL_SET_MAC_KEY:
+               if ((!p2 && p1 > 0) || (p1 < -1))
+                       return 0;
+               if (!ASN1_OCTET_STRING_set(&hctx->ktmp, p2, p1))
+                       return 0;
+               break;
+
+               case EVP_PKEY_CTRL_MD:
+               hctx->md = p2;
+               break;
+
+               case EVP_PKEY_CTRL_DIGESTINIT:
+               key = (ASN1_OCTET_STRING *)ctx->pkey->pkey.ptr;
+               HMAC_Init_ex(&hctx->ctx, key->data, key->length, hctx->md,
+                               ctx->engine);
+               break;
+
+               default:
+               return -2;
+
+               }
+       return 1;
+       }
+
+static int pkey_hmac_ctrl_str(EVP_PKEY_CTX *ctx,
+                       const char *type, const char *value)
+       {
+       if (!value)
+               {
+               return 0;
+               }
+       if (!strcmp(type, "key"))
+               {
+               void *p = (void *)value;
+               return pkey_hmac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY,
+                               -1, p);
+               }
+       if (!strcmp(type, "hexkey"))
+               {
+               unsigned char *key;
+               int r;
+               long keylen;
+               key = string_to_hex(value, &keylen);
+               if (!key)
+                       return 0;
+               r = pkey_hmac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, keylen, key);
+               OPENSSL_free(key);
+               return r;
+               }
+       return -2;
+       }
+
+const EVP_PKEY_METHOD hmac_pkey_meth = 
+       {
+       EVP_PKEY_HMAC,
+       0,
+       pkey_hmac_init,
+       pkey_hmac_copy,
+       pkey_hmac_cleanup,
+
+       0, 0,
+
+       0,
+       pkey_hmac_keygen,
+
+       0, 0,
+
+       0, 0,
+
+       0,0,
+
+       hmac_signctx_init,
+       hmac_signctx,
+
+       0,0,
+
+       0,0,
+
+       0,0,
+
+       0,0,
+
+       pkey_hmac_ctrl,
+       pkey_hmac_ctrl_str
+
+       };
index 6899be6..6c98fc4 100644 (file)
@@ -61,9 +61,7 @@
 #include "cryptlib.h"
 #include <openssl/hmac.h>
 
-#ifndef OPENSSL_FIPS
-
-void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
+int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
                  const EVP_MD *md, ENGINE *impl)
        {
        int i,j,reset=0;
@@ -84,10 +82,13 @@ void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
                OPENSSL_assert(j <= (int)sizeof(ctx->key));
                if (j < len)
                        {
-                       EVP_DigestInit_ex(&ctx->md_ctx,md, impl);
-                       EVP_DigestUpdate(&ctx->md_ctx,key,len);
-                       EVP_DigestFinal_ex(&(ctx->md_ctx),ctx->key,
-                               &ctx->key_length);
+                       if (!EVP_DigestInit_ex(&ctx->md_ctx,md, impl))
+                               goto err;
+                       if (!EVP_DigestUpdate(&ctx->md_ctx,key,len))
+                               goto err;
+                       if (!EVP_DigestFinal_ex(&(ctx->md_ctx),ctx->key,
+                               &ctx->key_length))
+                               goto err;
                        }
                else
                        {
@@ -104,39 +105,53 @@ void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
                {
                for (i=0; i<HMAC_MAX_MD_CBLOCK; i++)
                        pad[i]=0x36^ctx->key[i];
-               EVP_DigestInit_ex(&ctx->i_ctx,md, impl);
-               EVP_DigestUpdate(&ctx->i_ctx,pad,EVP_MD_block_size(md));
+               if (!EVP_DigestInit_ex(&ctx->i_ctx,md, impl))
+                       goto err;
+               if (!EVP_DigestUpdate(&ctx->i_ctx,pad,EVP_MD_block_size(md)))
+                       goto err;
 
                for (i=0; i<HMAC_MAX_MD_CBLOCK; i++)
                        pad[i]=0x5c^ctx->key[i];
-               EVP_DigestInit_ex(&ctx->o_ctx,md, impl);
-               EVP_DigestUpdate(&ctx->o_ctx,pad,EVP_MD_block_size(md));
+               if (!EVP_DigestInit_ex(&ctx->o_ctx,md, impl))
+                       goto err;
+               if (!EVP_DigestUpdate(&ctx->o_ctx,pad,EVP_MD_block_size(md)))
+                       goto err;
                }
-       EVP_MD_CTX_copy_ex(&ctx->md_ctx,&ctx->i_ctx);
+       if (!EVP_MD_CTX_copy_ex(&ctx->md_ctx,&ctx->i_ctx))
+                       goto err;
+       return 1;
+       err:
+       return 0;
        }
 
-void HMAC_Init(HMAC_CTX *ctx, const void *key, int len,
-              const EVP_MD *md)
+int HMAC_Init(HMAC_CTX *ctx, const void *key, int len, const EVP_MD *md)
        {
        if(key && md)
            HMAC_CTX_init(ctx);
-       HMAC_Init_ex(ctx,key,len,md, NULL);
+       return HMAC_Init_ex(ctx,key,len,md, NULL);
        }
 
-void HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len)
+int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len)
        {
-       EVP_DigestUpdate(&ctx->md_ctx,data,len);
+       return EVP_DigestUpdate(&ctx->md_ctx,data,len);
        }
 
-void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len)
+int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len)
        {
        unsigned int i;
        unsigned char buf[EVP_MAX_MD_SIZE];
 
-       EVP_DigestFinal_ex(&ctx->md_ctx,buf,&i);
-       EVP_MD_CTX_copy_ex(&ctx->md_ctx,&ctx->o_ctx);
-       EVP_DigestUpdate(&ctx->md_ctx,buf,i);
-       EVP_DigestFinal_ex(&ctx->md_ctx,md,len);
+       if (!EVP_DigestFinal_ex(&ctx->md_ctx,buf,&i))
+               goto err;
+       if (!EVP_MD_CTX_copy_ex(&ctx->md_ctx,&ctx->o_ctx))
+               goto err;
+       if (!EVP_DigestUpdate(&ctx->md_ctx,buf,i))
+               goto err;
+       if (!EVP_DigestFinal_ex(&ctx->md_ctx,md,len))
+               goto err;
+       return 1;
+       err:
+       return 0;
        }
 
 void HMAC_CTX_init(HMAC_CTX *ctx)
@@ -146,6 +161,22 @@ void HMAC_CTX_init(HMAC_CTX *ctx)
        EVP_MD_CTX_init(&ctx->md_ctx);
        }
 
+int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx)
+       {
+       if (!EVP_MD_CTX_copy(&dctx->i_ctx, &sctx->i_ctx))
+               goto err;
+       if (!EVP_MD_CTX_copy(&dctx->o_ctx, &sctx->o_ctx))
+               goto err;
+       if (!EVP_MD_CTX_copy(&dctx->md_ctx, &sctx->md_ctx))
+               goto err;
+       memcpy(dctx->key, sctx->key, HMAC_MAX_MD_CBLOCK);
+       dctx->key_length = sctx->key_length;
+       dctx->md = sctx->md;
+       return 1;
+       err:
+       return 0;
+       }
+
 void HMAC_CTX_cleanup(HMAC_CTX *ctx)
        {
        EVP_MD_CTX_cleanup(&ctx->i_ctx);
@@ -163,11 +194,16 @@ unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
 
        if (md == NULL) md=m;
        HMAC_CTX_init(&c);
-       HMAC_Init(&c,key,key_len,evp_md);
-       HMAC_Update(&c,d,n);
-       HMAC_Final(&c,md,md_len);
+       if (!HMAC_Init(&c,key,key_len,evp_md))
+               goto err;
+       if (!HMAC_Update(&c,d,n))
+               goto err;
+       if (!HMAC_Final(&c,md,md_len))
+               goto err;
        HMAC_CTX_cleanup(&c);
-       return(md);
+       return md;
+       err:
+       return NULL;
        }
 
 void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags)
@@ -176,5 +212,3 @@ void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags)
        EVP_MD_CTX_set_flags(&ctx->o_ctx, flags);
        EVP_MD_CTX_set_flags(&ctx->md_ctx, flags);
        }
-
-#endif
index fc38ffb..1be0022 100644 (file)
@@ -90,15 +90,16 @@ void HMAC_CTX_cleanup(HMAC_CTX *ctx);
 
 #define HMAC_cleanup(ctx) HMAC_CTX_cleanup(ctx) /* deprecated */
 
-void HMAC_Init(HMAC_CTX *ctx, const void *key, int len,
+int HMAC_Init(HMAC_CTX *ctx, const void *key, int len,
               const EVP_MD *md); /* deprecated */
-void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
+int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
                  const EVP_MD *md, ENGINE *impl);
-void HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len);
-void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
+int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len);
+int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
 unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
                    const unsigned char *d, size_t n, unsigned char *md,
                    unsigned int *md_len);
+int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx);
 
 void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags);
 
index 04fbb34..d705fff 100644 (file)
@@ -1,6 +1,13 @@
 // Works on all IA-64 platforms: Linux, HP-UX, Win64i...
 // On Win64i compile with ias.exe.
 .text
+
+.global        OPENSSL_cpuid_setup#
+.proc  OPENSSL_cpuid_setup#
+OPENSSL_cpuid_setup:
+{ .mib;        br.ret.sptk.many        b0              };;
+.endp  OPENSSL_cpuid_setup#
+
 .global        OPENSSL_rdtsc#
 .proc  OPENSSL_rdtsc#
 OPENSSL_rdtsc:
@@ -119,3 +126,42 @@ OPENSSL_wipe_cpu:
        mov             ar.lc=r3
        br.ret.sptk     b0              };;
 .endp  OPENSSL_wipe_cpu#
+
+.global        OPENSSL_cleanse#
+.proc  OPENSSL_cleanse#
+OPENSSL_cleanse:
+{ .mib;        cmp.eq          p6,p0=0,r33         // len==0
+#if defined(_HPUX_SOURCE) && !defined(_LP64)
+       addp4           r32=0,r32
+#endif
+(p6)   br.ret.spnt     b0              };;
+{ .mib;        and             r2=7,r32
+       cmp.leu         p6,p0=15,r33        // len>=15
+(p6)   br.cond.dptk    .Lot            };;
+
+.Little:
+{ .mib;        st1             [r32]=r0,1
+       cmp.ltu         p6,p7=1,r33     }  // len>1
+{ .mbb;        add             r33=-1,r33         // len--
+(p6)   br.cond.dptk    .Little
+(p7)   br.ret.sptk.many        b0      };;
+
+.Lot:
+{ .mib;        cmp.eq          p6,p0=0,r2
+(p6)   br.cond.dptk    .Laligned       };;
+{ .mmi;        st1             [r32]=r0,1;;
+       and             r2=7,r32        }
+{ .mib;        add             r33=-1,r33
+       br              .Lot            };;
+
+.Laligned:
+{ .mmi;        st8             [r32]=r0,8
+       and             r2=-8,r33           // len&~7
+       add             r33=-8,r33      };; // len-=8
+{ .mib;        cmp.ltu         p6,p0=8,r2          // ((len+8)&~7)>8
+(p6)   br.cond.dptk    .Laligned       };;
+
+{ .mbb;        cmp.eq          p6,p7=r0,r33
+(p7)   br.cond.dpnt    .Little
+(p6)   br.ret.sptk.many        b0      };;
+.endp  OPENSSL_cleanse#
index 55c0d4d..b2e7add 100644 (file)
@@ -33,7 +33,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -82,9 +82,5 @@ i_ecb.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h
 i_ecb.o: ../../include/openssl/opensslv.h i_ecb.c idea_lcl.h
 i_ofb64.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h
 i_ofb64.o: i_ofb64.c idea_lcl.h
-i_skey.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
-i_skey.o: ../../include/openssl/fips.h ../../include/openssl/idea.h
-i_skey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-i_skey.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
-i_skey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+i_skey.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h
 i_skey.o: i_skey.c idea_lcl.h
index fa75b14..1c95bc9 100644 (file)
  */
 
 #include <openssl/idea.h>
-#include <openssl/crypto.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
 #include "idea_lcl.h"
 
 static IDEA_INT inverse(unsigned int xin);
-
-#ifdef OPENSSL_FIPS
-void idea_set_encrypt_key(const unsigned char *key, IDEA_KEY_SCHEDULE *ks)
-       {
-       if (FIPS_mode())
-               FIPS_BAD_ABORT(IDEA)
-       private_idea_set_encrypt_key(key, ks);
-       }
-void private_idea_set_encrypt_key(const unsigned char *key,
-                                               IDEA_KEY_SCHEDULE *ks)
-#else
 void idea_set_encrypt_key(const unsigned char *key, IDEA_KEY_SCHEDULE *ks)
-#endif
        {
        int i;
        register IDEA_INT *kt,*kf,r0,r1,r2;
@@ -111,11 +94,10 @@ void idea_set_encrypt_key(const unsigned char *key, IDEA_KEY_SCHEDULE *ks)
                }
        }
 
-void idea_set_decrypt_key(const IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk)
+void idea_set_decrypt_key(IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk)
        {
        int r;
-       register IDEA_INT *tp,t;
-       const IDEA_INT *fp;
+       register IDEA_INT *fp,*tp,t;
 
        tp= &(dk->data[0][0]);
        fp= &(ek->data[8][0]);
index a137d4c..5782e54 100644 (file)
@@ -83,11 +83,8 @@ typedef struct idea_key_st
 const char *idea_options(void);
 void idea_ecb_encrypt(const unsigned char *in, unsigned char *out,
        IDEA_KEY_SCHEDULE *ks);
-#ifdef OPENSSL_FIPS
-void private_idea_set_encrypt_key(const unsigned char *key, IDEA_KEY_SCHEDULE *ks);
-#endif
 void idea_set_encrypt_key(const unsigned char *key, IDEA_KEY_SCHEDULE *ks);
-void idea_set_decrypt_key(const IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk);
+void idea_set_decrypt_key(IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk);
 void idea_cbc_encrypt(const unsigned char *in, unsigned char *out,
        long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv,int enc);
 void idea_cfb64_encrypt(const unsigned char *in, unsigned char *out,
diff --git a/deps/openssl/openssl/crypto/install-crypto.com b/deps/openssl/openssl/crypto/install-crypto.com
new file mode 100644 (file)
index 0000000..85b3d58
--- /dev/null
@@ -0,0 +1,196 @@
+$! INSTALL.COM -- Installs the files in a given directory tree
+$!
+$! Author: Richard Levitte <richard@levitte.org>
+$! Time of creation: 22-MAY-1998 10:13
+$!
+$! Changes by Zoltan Arpadffy <zoli@polarhome.com>
+$!
+$! P1  root of the directory tree
+$! P2  "64" for 64-bit pointers.
+$!
+$!
+$! Announce/identify.
+$!
+$ proc = f$environment( "procedure")
+$ write sys$output "@@@ "+ -
+   f$parse( proc, , , "name")+ f$parse( proc, , , "type")
+$!
+$ on error then goto tidy
+$ on control_c then goto tidy
+$!
+$ if (p1 .eqs. "")
+$ then
+$   write sys$output "First argument missing."
+$   write sys$output -
+     "It should be the directory where you want things installed."
+$     exit
+$ endif
+$!
+$ if (f$getsyi( "cpu") .lt. 128)
+$ then
+$   arch = "VAX"
+$ else
+$   arch = f$edit( f$getsyi( "arch_name"), "upcase")
+$   if (arch .eqs. "") then arch = "UNK"
+$ endif
+$!
+$ archd = arch
+$ lib32 = "32"
+$ shr = "_SHR32"
+$!
+$ if (p2 .nes. "")
+$ then
+$   if (p2 .eqs. "64")
+$   then
+$     archd = arch+ "_64"
+$     lib32 = ""
+$     shr = "_SHR"
+$   else
+$     if (p2 .nes. "32")
+$     then
+$       write sys$output "Second argument invalid."
+$       write sys$output "It should be "32", "64", or nothing."
+$       exit
+$     endif
+$   endif
+$ endif
+$!
+$ root = f$parse( p1, "[]A.;0", , , "syntax_only, no_conceal") - "A.;0"
+$ root_dev = f$parse( root, , , "device", "syntax_only")
+$ root_dir = f$parse( root, , , "directory", "syntax_only") - -
+   "[000000." - "][" - "[" - "]"
+$ root = root_dev + "[" + root_dir
+$!
+$ define /nolog wrk_sslroot 'root'.] /trans=conc
+$ define /nolog wrk_sslinclude wrk_sslroot:[include]
+$ define /nolog wrk_sslxlib wrk_sslroot:['arch'_lib]
+$!
+$ if f$parse("wrk_sslroot:[000000]") .eqs. "" then -
+   create /directory /log wrk_sslroot:[000000]
+$ if f$parse("wrk_sslinclude:") .eqs. "" then -
+   create /directory /log wrk_sslinclude:
+$ if f$parse("wrk_sslxlib:") .eqs. "" then -
+   create /directory /log wrk_sslxlib:
+$!
+$ sdirs := , -
+   'archd', -
+   objects, -
+   md2, md4, md5, sha, mdc2, hmac, ripemd, whrlpool, -
+   des, aes, rc2, rc4, rc5, idea, bf, cast, camellia, seed, -
+   bn, ec, rsa, dsa, ecdsa, dh, ecdh, dso, engine, -
+   buffer, bio, stack, lhash, rand, err, -
+   evp, asn1, pem, x509, x509v3, conf, txt_db, pkcs7, pkcs12, comp, ocsp, -
+   ui, krb5, -
+   store, cms, pqueue, ts, jpake
+$!
+$ exheader_ := crypto.h, opensslv.h, ebcdic.h, symhacks.h, ossl_typ.h
+$ exheader_'archd' := opensslconf.h
+$ exheader_objects := objects.h, obj_mac.h
+$ exheader_md2 := md2.h
+$ exheader_md4 := md4.h
+$ exheader_md5 := md5.h
+$ exheader_sha := sha.h
+$ exheader_mdc2 := mdc2.h
+$ exheader_hmac := hmac.h
+$ exheader_ripemd := ripemd.h
+$ exheader_whrlpool := whrlpool.h
+$ exheader_des := des.h, des_old.h
+$ exheader_aes := aes.h
+$ exheader_rc2 := rc2.h
+$ exheader_rc4 := rc4.h
+$ exheader_rc5 := rc5.h
+$ exheader_idea := idea.h
+$ exheader_bf := blowfish.h
+$ exheader_cast := cast.h
+$ exheader_camellia := camellia.h
+$ exheader_seed := seed.h
+$ exheader_modes := modes.h
+$ exheader_bn := bn.h
+$ exheader_ec := ec.h
+$ exheader_rsa := rsa.h
+$ exheader_dsa := dsa.h
+$ exheader_ecdsa := ecdsa.h
+$ exheader_dh := dh.h
+$ exheader_ecdh := ecdh.h
+$ exheader_dso := dso.h
+$ exheader_engine := engine.h
+$ exheader_buffer := buffer.h
+$ exheader_bio := bio.h
+$ exheader_stack := stack.h, safestack.h
+$ exheader_lhash := lhash.h
+$ exheader_rand := rand.h
+$ exheader_err := err.h
+$ exheader_evp := evp.h
+$ exheader_asn1 := asn1.h, asn1_mac.h, asn1t.h
+$ exheader_pem := pem.h, pem2.h
+$ exheader_x509 := x509.h, x509_vfy.h
+$ exheader_x509v3 := x509v3.h
+$ exheader_conf := conf.h, conf_api.h
+$ exheader_txt_db := txt_db.h
+$ exheader_pkcs7 := pkcs7.h
+$ exheader_pkcs12 := pkcs12.h
+$ exheader_comp := comp.h
+$ exheader_ocsp := ocsp.h
+$ exheader_ui := ui.h, ui_compat.h
+$ exheader_krb5 := krb5_asn.h
+$! exheader_store := store.h, str_compat.h
+$ exheader_store := store.h
+$ exheader_cms := cms.h
+$ exheader_pqueue := pqueue.h
+$ exheader_ts := ts.h
+$ exheader_jpake := jpake.h
+$ libs := ssl_libcrypto
+$!
+$ exe_dir := [-.'archd'.exe.crypto]
+$!
+$! Header files.
+$!
+$ i = 0
+$ loop_sdirs: 
+$   d = f$edit( f$element( i, ",", sdirs), "trim")
+$   i = i + 1
+$   if d .eqs. "," then goto loop_sdirs_end
+$   tmp = exheader_'d'
+$   if (d .nes. "") then d = "."+ d
+$   copy /protection = w:re ['d']'tmp' wrk_sslinclude: /log
+$ goto loop_sdirs
+$ loop_sdirs_end:
+$!
+$! Object libraries, shareable images.
+$!
+$ i = 0
+$ loop_lib: 
+$   e = f$edit( f$element( i, ",", libs), "trim")
+$   i = i + 1
+$   if e .eqs. "," then goto loop_lib_end
+$   set noon
+$   file = exe_dir+ e+ lib32+ ".olb"
+$   if f$search( file) .nes. ""
+$   then
+$     copy /protection = w:re 'file' wrk_sslxlib: /log
+$   endif
+$!
+$   file = exe_dir+ e+ shr+ ".exe"
+$   if f$search( file) .nes. ""
+$   then
+$     copy /protection = w:re 'file' wrk_sslxlib: /log
+$   endif
+$   set on
+$ goto loop_lib
+$ loop_lib_end:
+$!
+$ tidy:
+$!
+$ call deass wrk_sslroot
+$ call deass wrk_sslinclude
+$ call deass wrk_sslxlib
+$!
+$ exit
+$!
+$ deass: subroutine
+$ if (f$trnlnm( p1, "LNM$PROCESS") .nes. "")
+$ then
+$   deassign /process 'p1'
+$ endif
+$ endsubroutine
+$!
diff --git a/deps/openssl/openssl/crypto/install.com b/deps/openssl/openssl/crypto/install.com
deleted file mode 100644 (file)
index 5e6d97e..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-$! INSTALL.COM -- Installs the files in a given directory tree
-$!
-$! Author: Richard Levitte <richard@levitte.org>
-$! Time of creation: 22-MAY-1998 10:13
-$!
-$! Changes by Zoltan Arpadffy <zoli@polarhome.com>
-$!
-$! P1  root of the directory tree
-$!
-$      IF P1 .EQS. ""
-$      THEN
-$          WRITE SYS$OUTPUT "First argument missing."
-$          WRITE SYS$OUTPUT -
-                 "It should be the directory where you want things installed."
-$          EXIT
-$      ENDIF
-$
-$      IF (F$GETSYI("CPU").LT.128)
-$      THEN
-$          ARCH := VAX
-$      ELSE
-$          ARCH = F$EDIT( F$GETSYI( "ARCH_NAME"), "UPCASE")
-$          IF (ARCH .EQS. "") THEN ARCH = "UNK"
-$      ENDIF
-$
-$      ROOT = F$PARSE(P1,"[]A.;0",,,"SYNTAX_ONLY,NO_CONCEAL") - "A.;0"
-$      ROOT_DEV = F$PARSE(ROOT,,,"DEVICE","SYNTAX_ONLY")
-$      ROOT_DIR = F$PARSE(ROOT,,,"DIRECTORY","SYNTAX_ONLY") -
-                  - "[000000." - "][" - "[" - "]"
-$      ROOT = ROOT_DEV + "[" + ROOT_DIR
-$
-$      DEFINE/NOLOG WRK_SSLROOT 'ROOT'.] /TRANS=CONC
-$      DEFINE/NOLOG WRK_SSLLIB WRK_SSLROOT:['ARCH'_LIB]
-$      DEFINE/NOLOG WRK_SSLINCLUDE WRK_SSLROOT:[INCLUDE]
-$
-$      IF F$PARSE("WRK_SSLROOT:[000000]") .EQS. "" THEN -
-          CREATE/DIR/LOG WRK_SSLROOT:[000000]
-$      IF F$PARSE("WRK_SSLLIB:") .EQS. "" THEN -
-          CREATE/DIR/LOG WRK_SSLLIB:
-$      IF F$PARSE("WRK_SSLINCLUDE:") .EQS. "" THEN -
-          CREATE/DIR/LOG WRK_SSLINCLUDE:
-$
-$      SDIRS := ,-
-                OBJECTS,-
-                MD2,MD4,MD5,SHA,MDC2,HMAC,RIPEMD,-
-                DES,AES,RC2,RC4,RC5,IDEA,BF,CAST,CAMELLIA,SEED,-
-                BN,EC,RSA,DSA,ECDSA,DH,ECDH,DSO,ENGINE,-
-                BUFFER,BIO,STACK,LHASH,RAND,ERR,-
-                EVP,ASN1,PEM,X509,X509V3,CONF,TXT_DB,PKCS7,PKCS12,COMP,OCSP,-
-                UI,KRB5,-
-                STORE,PQUEUE,JPAKE
-$      EXHEADER_ := crypto.h,tmdiff.h,opensslv.h,opensslconf.h,ebcdic.h,-
-               symhacks.h,ossl_typ.h
-$      EXHEADER_OBJECTS := objects.h,obj_mac.h
-$      EXHEADER_MD2 := md2.h
-$      EXHEADER_MD4 := md4.h
-$      EXHEADER_MD5 := md5.h
-$      EXHEADER_SHA := sha.h
-$      EXHEADER_MDC2 := mdc2.h
-$      EXHEADER_HMAC := hmac.h
-$      EXHEADER_RIPEMD := ripemd.h
-$      EXHEADER_DES := des.h,des_old.h
-$      EXHEADER_AES := aes.h
-$      EXHEADER_RC2 := rc2.h
-$      EXHEADER_RC4 := rc4.h
-$      EXHEADER_RC5 := rc5.h
-$      EXHEADER_IDEA := idea.h
-$      EXHEADER_BF := blowfish.h
-$      EXHEADER_CAST := cast.h
-$      EXHEADER_CAMELLIA := camellia.h
-$      EXHEADER_SEED := seed.h
-$      EXHEADER_BN := bn.h
-$      EXHEADER_EC := ec.h
-$      EXHEADER_RSA := rsa.h
-$      EXHEADER_DSA := dsa.h
-$      EXHEADER_ECDSA := ecdsa.h
-$      EXHEADER_DH := dh.h
-$      EXHEADER_ECDH := ecdh.h
-$      EXHEADER_DSO := dso.h
-$      EXHEADER_ENGINE := engine.h
-$      EXHEADER_BUFFER := buffer.h
-$      EXHEADER_BIO := bio.h
-$      EXHEADER_STACK := stack.h,safestack.h
-$      EXHEADER_LHASH := lhash.h
-$      EXHEADER_RAND := rand.h
-$      EXHEADER_ERR := err.h
-$      EXHEADER_EVP := evp.h
-$      EXHEADER_ASN1 := asn1.h,asn1_mac.h,asn1t.h
-$      EXHEADER_PEM := pem.h,pem2.h
-$      EXHEADER_X509 := x509.h,x509_vfy.h
-$      EXHEADER_X509V3 := x509v3.h
-$      EXHEADER_CONF := conf.h,conf_api.h
-$      EXHEADER_TXT_DB := txt_db.h
-$      EXHEADER_PKCS7 := pkcs7.h
-$      EXHEADER_PKCS12 := pkcs12.h
-$      EXHEADER_COMP := comp.h
-$      EXHEADER_OCSP := ocsp.h
-$      EXHEADER_UI := ui.h,ui_compat.h
-$      EXHEADER_KRB5 := krb5_asn.h
-$!     EXHEADER_STORE := store.h,str_compat.h
-$      EXHEADER_STORE := store.h
-$      EXHEADER_PQUEUE := pqueue.h,pq_compat.h
-$      EXHEADER_JPAKE := jpake.h
-$      LIBS := LIBCRYPTO
-$
-$      EXE_DIR := [-.'ARCH'.EXE.CRYPTO]
-$
-$      I = 0
-$ LOOP_SDIRS: 
-$      D = F$EDIT(F$ELEMENT(I, ",", SDIRS),"TRIM")
-$      I = I + 1
-$      IF D .EQS. "," THEN GOTO LOOP_SDIRS_END
-$      tmp = EXHEADER_'D'
-$      IF D .EQS. ""
-$      THEN
-$        COPY 'tmp' WRK_SSLINCLUDE: /LOG
-$      ELSE
-$        COPY [.'D']'tmp' WRK_SSLINCLUDE: /LOG
-$      ENDIF
-$      SET FILE/PROT=WORLD:RE WRK_SSLINCLUDE:'tmp'
-$      GOTO LOOP_SDIRS
-$ LOOP_SDIRS_END:
-$
-$      I = 0
-$ LOOP_LIB: 
-$      E = F$EDIT(F$ELEMENT(I, ",", LIBS),"TRIM")
-$      I = I + 1
-$      IF E .EQS. "," THEN GOTO LOOP_LIB_END
-$      SET NOON
-$      IF F$SEARCH(EXE_DIR+E+".OLB") .NES. ""
-$      THEN
-$        COPY 'EXE_DIR''E'.OLB WRK_SSLLIB:'E'.OLB/log
-$        SET FILE/PROT=W:RE WRK_SSLLIB:'E'.OLB
-$      ENDIF
-$      ! Preparing for the time when we have shareable images
-$      IF F$SEARCH(EXE_DIR+E+".EXE") .NES. ""
-$      THEN
-$        COPY 'EXE_DIR''E'.EXE WRK_SSLLIB:'E'.EXE/log
-$        SET FILE/PROT=W:RE WRK_SSLLIB:'E'.EXE
-$      ENDIF
-$      SET ON
-$      GOTO LOOP_LIB
-$ LOOP_LIB_END:
-$
-$      EXIT
index a4a1402..110c49c 100644 (file)
@@ -16,7 +16,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
index 9736f89..8e4b633 100644 (file)
@@ -4,7 +4,6 @@
 #include <openssl/sha.h>
 #include <openssl/err.h>
 #include <memory.h>
-#include <assert.h>
 
 /*
  * In the definition, (xa, xb, xc, xd) are Alice's (x1, x2, x3, x4) or
@@ -134,7 +133,7 @@ static void hashlength(SHA_CTX *sha, size_t l)
     {
     unsigned char b[2];
 
-    assert(l <= 0xffff);
+    OPENSSL_assert(l <= 0xffff);
     b[0] = l >> 8;
     b[1] = l&0xff;
     SHA1_Update(sha, b, 2);
@@ -172,7 +171,7 @@ static void zkp_hash(BIGNUM *h, const BIGNUM *zkpg, const JPAKE_STEP_PART *p,
     */
     SHA1_Init(&sha);
     hashbn(&sha, zkpg);
-    assert(!BN_is_zero(p->zkpx.gr));
+    OPENSSL_assert(!BN_is_zero(p->zkpx.gr));
     hashbn(&sha, p->zkpx.gr);
     hashbn(&sha, p->gx);
     hashstring(&sha, proof_name);
@@ -314,22 +313,21 @@ int JPAKE_STEP1_process(JPAKE_CTX *ctx, const JPAKE_STEP1 *received)
        return 0;
        }
 
-
-    /* verify their ZKP(xc) */
+   /* verify their ZKP(xc) */
     if(!verify_zkp(&received->p1, ctx->p.g, ctx))
        {
        JPAKEerr(JPAKE_F_JPAKE_STEP1_PROCESS, JPAKE_R_VERIFY_X3_FAILED);
        return 0;
        }
 
-    /* verify their ZKP(xd) */
+   /* verify their ZKP(xd) */
     if(!verify_zkp(&received->p2, ctx->p.g, ctx))
        {
        JPAKEerr(JPAKE_F_JPAKE_STEP1_PROCESS, JPAKE_R_VERIFY_X4_FAILED);
        return 0;
        }
 
-    /* g^xd != 1 */
+   /* g^xd != 1 */
     if(BN_is_one(received->p2.gx))
        {
        JPAKEerr(JPAKE_F_JPAKE_STEP1_PROCESS, JPAKE_R_G_TO_THE_X4_IS_ONE);
index 792fc49..eaba75e 100644 (file)
@@ -182,7 +182,7 @@ int main(int argc, char **argv)
     BN_free(p);
 
     CRYPTO_cleanup_all_ex_data();
-    ERR_remove_state(0);
+    ERR_remove_thread_state(NULL);
     ERR_free_strings();
     CRYPTO_mem_leaks(bio_err);
 
index 8efb9e8..1407739 100644 (file)
@@ -34,7 +34,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
index 35f0932..82bddac 100644 (file)
@@ -33,7 +33,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
index 5aa7766..815615e 100644 (file)
@@ -139,7 +139,7 @@ void lh_node_usage_stats(LHASH *lh, FILE *out)
 #else
 
 #ifndef OPENSSL_NO_FP_API
-void lh_stats(const LHASH *lh, FILE *fp)
+void lh_stats(const _LHASH *lh, FILE *fp)
        {
        BIO *bp;
 
@@ -151,7 +151,7 @@ void lh_stats(const LHASH *lh, FILE *fp)
 end:;
        }
 
-void lh_node_stats(const LHASH *lh, FILE *fp)
+void lh_node_stats(const _LHASH *lh, FILE *fp)
        {
        BIO *bp;
 
@@ -163,7 +163,7 @@ void lh_node_stats(const LHASH *lh, FILE *fp)
 end:;
        }
 
-void lh_node_usage_stats(const LHASH *lh, FILE *fp)
+void lh_node_usage_stats(const _LHASH *lh, FILE *fp)
        {
        BIO *bp;
 
@@ -177,7 +177,7 @@ end:;
 
 #endif
 
-void lh_stats_bio(const LHASH *lh, BIO *out)
+void lh_stats_bio(const _LHASH *lh, BIO *out)
        {
        BIO_printf(out,"num_items             = %lu\n",lh->num_items);
        BIO_printf(out,"num_nodes             = %u\n",lh->num_nodes);
@@ -205,7 +205,7 @@ void lh_stats_bio(const LHASH *lh, BIO *out)
 #endif
        }
 
-void lh_node_stats_bio(const LHASH *lh, BIO *out)
+void lh_node_stats_bio(const _LHASH *lh, BIO *out)
        {
        LHASH_NODE *n;
        unsigned int i,num;
@@ -218,7 +218,7 @@ void lh_node_stats_bio(const LHASH *lh, BIO *out)
                }
        }
 
-void lh_node_usage_stats_bio(const LHASH *lh, BIO *out)
+void lh_node_usage_stats_bio(const _LHASH *lh, BIO *out)
        {
        LHASH_NODE *n;
        unsigned long num;
index 0b41f87..47f7480 100644 (file)
@@ -107,18 +107,18 @@ const char lh_version[]="lhash" OPENSSL_VERSION_PTEXT;
 #define UP_LOAD                (2*LH_LOAD_MULT) /* load times 256  (default 2) */
 #define DOWN_LOAD      (LH_LOAD_MULT)   /* load times 256  (default 1) */
 
-static void expand(LHASH *lh);
-static void contract(LHASH *lh);
-static LHASH_NODE **getrn(LHASH *lh, const void *data, unsigned long *rhash);
+static void expand(_LHASH *lh);
+static void contract(_LHASH *lh);
+static LHASH_NODE **getrn(_LHASH *lh, const void *data, unsigned long *rhash);
 
-LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c)
+_LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c)
        {
-       LHASH *ret;
+       _LHASH *ret;
        int i;
 
-       if ((ret=(LHASH *)OPENSSL_malloc(sizeof(LHASH))) == NULL)
+       if ((ret=OPENSSL_malloc(sizeof(_LHASH))) == NULL)
                goto err0;
-       if ((ret->b=(LHASH_NODE **)OPENSSL_malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL)
+       if ((ret->b=OPENSSL_malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL)
                goto err1;
        for (i=0; i<MIN_NODES; i++)
                ret->b[i]=NULL;
@@ -154,7 +154,7 @@ err0:
        return(NULL);
        }
 
-void lh_free(LHASH *lh)
+void lh_free(_LHASH *lh)
        {
        unsigned int i;
        LHASH_NODE *n,*nn;
@@ -176,7 +176,7 @@ void lh_free(LHASH *lh)
        OPENSSL_free(lh);
        }
 
-void *lh_insert(LHASH *lh, void *data)
+void *lh_insert(_LHASH *lh, void *data)
        {
        unsigned long hash;
        LHASH_NODE *nn,**rn;
@@ -214,7 +214,7 @@ void *lh_insert(LHASH *lh, void *data)
        return(ret);
        }
 
-void *lh_delete(LHASH *lh, const void *data)
+void *lh_delete(_LHASH *lh, const void *data)
        {
        unsigned long hash;
        LHASH_NODE *nn,**rn;
@@ -245,7 +245,7 @@ void *lh_delete(LHASH *lh, const void *data)
        return(ret);
        }
 
-void *lh_retrieve(LHASH *lh, const void *data)
+void *lh_retrieve(_LHASH *lh, const void *data)
        {
        unsigned long hash;
        LHASH_NODE **rn;
@@ -267,12 +267,15 @@ void *lh_retrieve(LHASH *lh, const void *data)
        return(ret);
        }
 
-static void doall_util_fn(LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func,
+static void doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func,
                          LHASH_DOALL_ARG_FN_TYPE func_arg, void *arg)
        {
        int i;
        LHASH_NODE *a,*n;
 
+       if (lh == NULL)
+               return;
+
        /* reverse the order so we search from 'top to bottom'
         * We were having memory leaks otherwise */
        for (i=lh->num_nodes-1; i>=0; i--)
@@ -282,6 +285,8 @@ static void doall_util_fn(LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func,
                        {
                        /* 28/05/91 - eay - n added so items can be deleted
                         * via lh_doall */
+                       /* 22/05/08 - ben - eh? since a is not passed,
+                        * this should not be needed */
                        n=a->next;
                        if(use_arg)
                                func_arg(a->data,arg);
@@ -292,53 +297,29 @@ static void doall_util_fn(LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func,
                }
        }
 
-void lh_doall(LHASH *lh, LHASH_DOALL_FN_TYPE func)
+void lh_doall(_LHASH *lh, LHASH_DOALL_FN_TYPE func)
        {
        doall_util_fn(lh, 0, func, (LHASH_DOALL_ARG_FN_TYPE)0, NULL);
        }
 
-void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg)
+void lh_doall_arg(_LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg)
        {
        doall_util_fn(lh, 1, (LHASH_DOALL_FN_TYPE)0, func, arg);
        }
 
-static void expand(LHASH *lh)
+static void expand(_LHASH *lh)
        {
        LHASH_NODE **n,**n1,**n2,*np;
-       unsigned int p,i,j,pmax;
+       unsigned int p,i,j;
        unsigned long hash,nni;
 
-       p=(int)lh->p++;
-       nni=lh->num_alloc_nodes;
-       pmax=lh->pmax;
-
-       if ((lh->p) >= lh->pmax)
-               {
-               j=(int)lh->num_alloc_nodes*2;
-               n=(LHASH_NODE **)OPENSSL_realloc(lh->b,
-                       (int)sizeof(LHASH_NODE *)*j);
-               if (n == NULL)
-                       {
-/*                     fputs("realloc error in lhash",stderr); */
-                       lh->error++;
-                       lh->p=0;
-                       return;
-                       }
-               /* else */
-               for (i=(int)lh->num_alloc_nodes; i<j; i++)/* 26/02/92 eay */
-                       n[i]=NULL;                        /* 02/03/92 eay */
-               lh->pmax=lh->num_alloc_nodes;
-               lh->num_alloc_nodes=j;
-               lh->num_expand_reallocs++;
-               lh->p=0;
-               lh->b=n;
-               }
-
        lh->num_nodes++;
        lh->num_expands++;
+       p=(int)lh->p++;
        n1= &(lh->b[p]);
-       n2= &(lh->b[p+pmax]);
+       n2= &(lh->b[p+(int)lh->pmax]);
        *n2=NULL;        /* 27/07/92 - eay - undefined pointer bug */
+       nni=lh->num_alloc_nodes;
        
        for (np= *n1; np != NULL; )
                {
@@ -359,14 +340,35 @@ static void expand(LHASH *lh)
                np= *n1;
                }
 
+       if ((lh->p) >= lh->pmax)
+               {
+               j=(int)lh->num_alloc_nodes*2;
+               n=(LHASH_NODE **)OPENSSL_realloc(lh->b,
+                       (int)(sizeof(LHASH_NODE *)*j));
+               if (n == NULL)
+                       {
+/*                     fputs("realloc error in lhash",stderr); */
+                       lh->error++;
+                       lh->p=0;
+                       return;
+                       }
+               /* else */
+               for (i=(int)lh->num_alloc_nodes; i<j; i++)/* 26/02/92 eay */
+                       n[i]=NULL;                        /* 02/03/92 eay */
+               lh->pmax=lh->num_alloc_nodes;
+               lh->num_alloc_nodes=j;
+               lh->num_expand_reallocs++;
+               lh->p=0;
+               lh->b=n;
+               }
        }
 
-static void contract(LHASH *lh)
+static void contract(_LHASH *lh)
        {
        LHASH_NODE **n,*n1,*np;
-       int idx = lh->p+lh->pmax-1;
 
-       np=lh->b[idx];
+       np=lh->b[lh->p+lh->pmax-1];
+       lh->b[lh->p+lh->pmax-1]=NULL; /* 24/07-92 - eay - weird but :-( */
        if (lh->p == 0)
                {
                n=(LHASH_NODE **)OPENSSL_realloc(lh->b,
@@ -386,7 +388,6 @@ static void contract(LHASH *lh)
        else
                lh->p--;
 
-       lh->b[idx] = NULL;
        lh->num_nodes--;
        lh->num_contracts++;
 
@@ -401,7 +402,7 @@ static void contract(LHASH *lh)
                }
        }
 
-static LHASH_NODE **getrn(LHASH *lh, const void *data, unsigned long *rhash)
+static LHASH_NODE **getrn(_LHASH *lh, const void *data, unsigned long *rhash)
        {
        LHASH_NODE **ret,*n1;
        unsigned long hash,nn;
@@ -468,7 +469,7 @@ unsigned long lh_strhash(const char *c)
        return((ret>>16)^ret);
        }
 
-unsigned long lh_num_items(const LHASH *lh)
+unsigned long lh_num_items(const _LHASH *lh)
        {
        return lh ? lh->num_items : 0;
        }
index d392d0c..e7d8763 100644 (file)
@@ -98,42 +98,42 @@ typedef void (*LHASH_DOALL_ARG_FN_TYPE)(void *, void *);
  * macros if the functions are strictly internal. */
 
 /* First: "hash" functions */
-#define DECLARE_LHASH_HASH_FN(f_name,o_type) \
-       unsigned long f_name##_LHASH_HASH(const void *);
-#define IMPLEMENT_LHASH_HASH_FN(f_name,o_type) \
-       unsigned long f_name##_LHASH_HASH(const void *arg) { \
-               o_type a = (o_type)arg; \
-               return f_name(a); }
-#define LHASH_HASH_FN(f_name) f_name##_LHASH_HASH
+#define DECLARE_LHASH_HASH_FN(name, o_type) \
+       unsigned long name##_LHASH_HASH(const void *);
+#define IMPLEMENT_LHASH_HASH_FN(name, o_type) \
+       unsigned long name##_LHASH_HASH(const void *arg) { \
+               const o_type *a = arg; \
+               return name##_hash(a); }
+#define LHASH_HASH_FN(name) name##_LHASH_HASH
 
 /* Second: "compare" functions */
-#define DECLARE_LHASH_COMP_FN(f_name,o_type) \
-       int f_name##_LHASH_COMP(const void *, const void *);
-#define IMPLEMENT_LHASH_COMP_FN(f_name,o_type) \
-       int f_name##_LHASH_COMP(const void *arg1, const void *arg2) { \
-               o_type a = (o_type)arg1; \
-               o_type b = (o_type)arg2; \
-               return f_name(a,b); }
-#define LHASH_COMP_FN(f_name) f_name##_LHASH_COMP
+#define DECLARE_LHASH_COMP_FN(name, o_type) \
+       int name##_LHASH_COMP(const void *, const void *);
+#define IMPLEMENT_LHASH_COMP_FN(name, o_type) \
+       int name##_LHASH_COMP(const void *arg1, const void *arg2) { \
+               const o_type *a = arg1;             \
+               const o_type *b = arg2; \
+               return name##_cmp(a,b); }
+#define LHASH_COMP_FN(name) name##_LHASH_COMP
 
 /* Third: "doall" functions */
-#define DECLARE_LHASH_DOALL_FN(f_name,o_type) \
-       void f_name##_LHASH_DOALL(void *);
-#define IMPLEMENT_LHASH_DOALL_FN(f_name,o_type) \
-       void f_name##_LHASH_DOALL(void *arg) { \
-               o_type a = (o_type)arg; \
-               f_name(a); }
-#define LHASH_DOALL_FN(f_name) f_name##_LHASH_DOALL
+#define DECLARE_LHASH_DOALL_FN(name, o_type) \
+       void name##_LHASH_DOALL(void *);
+#define IMPLEMENT_LHASH_DOALL_FN(name, o_type) \
+       void name##_LHASH_DOALL(void *arg) { \
+               o_type *a = arg; \
+               name##_doall(a); }
+#define LHASH_DOALL_FN(name) name##_LHASH_DOALL
 
 /* Fourth: "doall_arg" functions */
-#define DECLARE_LHASH_DOALL_ARG_FN(f_name,o_type,a_type) \
-       void f_name##_LHASH_DOALL_ARG(void *, void *);
-#define IMPLEMENT_LHASH_DOALL_ARG_FN(f_name,o_type,a_type) \
-       void f_name##_LHASH_DOALL_ARG(void *arg1, void *arg2) { \
-               o_type a = (o_type)arg1; \
-               a_type b = (a_type)arg2; \
-               f_name(a,b); }
-#define LHASH_DOALL_ARG_FN(f_name) f_name##_LHASH_DOALL_ARG
+#define DECLARE_LHASH_DOALL_ARG_FN(name, o_type, a_type) \
+       void name##_LHASH_DOALL_ARG(void *, void *);
+#define IMPLEMENT_LHASH_DOALL_ARG_FN(name, o_type, a_type) \
+       void name##_LHASH_DOALL_ARG(void *arg1, void *arg2) { \
+               o_type *a = arg1; \
+               a_type *b = arg2; \
+               name##_doall_arg(a, b); }
+#define LHASH_DOALL_ARG_FN(name) name##_LHASH_DOALL_ARG
 
 typedef struct lhash_st
        {
@@ -163,7 +163,8 @@ typedef struct lhash_st
        unsigned long num_hash_comps;
 
        int error;
-       } LHASH;
+       } _LHASH;       /* Do not use _LHASH directly, use LHASH_OF
+                        * and friends */
 
 #define LH_LOAD_MULT   256
 
@@ -171,27 +172,67 @@ typedef struct lhash_st
  * in lh_insert(). */
 #define lh_error(lh)   ((lh)->error)
 
-LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c);
-void lh_free(LHASH *lh);
-void *lh_insert(LHASH *lh, void *data);
-void *lh_delete(LHASH *lh, const void *data);
-void *lh_retrieve(LHASH *lh, const void *data);
-void lh_doall(LHASH *lh, LHASH_DOALL_FN_TYPE func);
-void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg);
+_LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c);
+void lh_free(_LHASH *lh);
+void *lh_insert(_LHASH *lh, void *data);
+void *lh_delete(_LHASH *lh, const void *data);
+void *lh_retrieve(_LHASH *lh, const void *data);
+void lh_doall(_LHASH *lh, LHASH_DOALL_FN_TYPE func);
+void lh_doall_arg(_LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg);
 unsigned long lh_strhash(const char *c);
-unsigned long lh_num_items(const LHASH *lh);
+unsigned long lh_num_items(const _LHASH *lh);
 
 #ifndef OPENSSL_NO_FP_API
-void lh_stats(const LHASH *lh, FILE *out);
-void lh_node_stats(const LHASH *lh, FILE *out);
-void lh_node_usage_stats(const LHASH *lh, FILE *out);
+void lh_stats(const _LHASH *lh, FILE *out);
+void lh_node_stats(const _LHASH *lh, FILE *out);
+void lh_node_usage_stats(const _LHASH *lh, FILE *out);
 #endif
 
 #ifndef OPENSSL_NO_BIO
-void lh_stats_bio(const LHASH *lh, BIO *out);
-void lh_node_stats_bio(const LHASH *lh, BIO *out);
-void lh_node_usage_stats_bio(const LHASH *lh, BIO *out);
+void lh_stats_bio(const _LHASH *lh, BIO *out);
+void lh_node_stats_bio(const _LHASH *lh, BIO *out);
+void lh_node_usage_stats_bio(const _LHASH *lh, BIO *out);
 #endif
+
+/* Type checking... */
+
+#define LHASH_OF(type) struct lhash_st_##type
+
+#define DECLARE_LHASH_OF(type) LHASH_OF(type) { int dummy; }
+
+#define CHECKED_LHASH_OF(type,lh) \
+  ((_LHASH *)CHECKED_PTR_OF(LHASH_OF(type),lh))
+
+/* Define wrapper functions. */
+#define LHM_lh_new(type, name) \
+  ((LHASH_OF(type) *)lh_new(LHASH_HASH_FN(name), LHASH_COMP_FN(name)))
+#define LHM_lh_error(type, lh) \
+  lh_error(CHECKED_LHASH_OF(type,lh))
+#define LHM_lh_insert(type, lh, inst) \
+  ((type *)lh_insert(CHECKED_LHASH_OF(type, lh), \
+                    CHECKED_PTR_OF(type, inst)))
+#define LHM_lh_retrieve(type, lh, inst) \
+  ((type *)lh_retrieve(CHECKED_LHASH_OF(type, lh), \
+                      CHECKED_PTR_OF(type, inst)))
+#define LHM_lh_delete(type, lh, inst) \
+  ((type *)lh_delete(CHECKED_LHASH_OF(type, lh),                       \
+                    CHECKED_PTR_OF(type, inst)))
+#define LHM_lh_doall(type, lh,fn) lh_doall(CHECKED_LHASH_OF(type, lh), fn)
+#define LHM_lh_doall_arg(type, lh, fn, arg_type, arg) \
+  lh_doall_arg(CHECKED_LHASH_OF(type, lh), fn, CHECKED_PTR_OF(arg_type, arg))
+#define LHM_lh_num_items(type, lh) lh_num_items(CHECKED_LHASH_OF(type, lh))
+#define LHM_lh_down_load(type, lh) (CHECKED_LHASH_OF(type, lh)->down_load)
+#define LHM_lh_node_stats_bio(type, lh, out) \
+  lh_node_stats_bio(CHECKED_LHASH_OF(type, lh), out)
+#define LHM_lh_node_usage_stats_bio(type, lh, out) \
+  lh_node_usage_stats_bio(CHECKED_LHASH_OF(type, lh), out)
+#define LHM_lh_stats_bio(type, lh, out) \
+  lh_stats_bio(CHECKED_LHASH_OF(type, lh), out)
+#define LHM_lh_free(type, lh) lh_free(CHECKED_LHASH_OF(type, lh))
+
+DECLARE_LHASH_OF(OPENSSL_STRING);
+DECLARE_LHASH_OF(OPENSSL_CSTRING);
+
 #ifdef  __cplusplus
 }
 #endif
index 7f43321..17f878a 100644 (file)
@@ -33,7 +33,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -74,9 +74,7 @@ clean:
 
 # DO NOT DELETE THIS LINE -- make depend depends on it.
 
-md2_dgst.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
-md2_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-md2_dgst.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
+md2_dgst.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 md2_dgst.o: ../../include/openssl/md2.h ../../include/openssl/opensslconf.h
 md2_dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 md2_dgst.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
index d59c9f2..a46120e 100644 (file)
@@ -81,9 +81,6 @@ typedef struct MD2state_st
        } MD2_CTX;
 
 const char *MD2_options(void);
-#ifdef OPENSSL_FIPS
-int private_MD2_Init(MD2_CTX *c);
-#endif
 int MD2_Init(MD2_CTX *c);
 int MD2_Update(MD2_CTX *c, const unsigned char *data, size_t len);
 int MD2_Final(unsigned char *md, MD2_CTX *c);
index cc4eeaf..c57b3da 100644 (file)
 #include <openssl/md2.h>
 #include <openssl/opensslv.h>
 #include <openssl/crypto.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
-#include <openssl/err.h>
 
 const char MD2_version[]="MD2" OPENSSL_VERSION_PTEXT;
 
@@ -78,7 +73,7 @@ const char MD2_version[]="MD2" OPENSSL_VERSION_PTEXT;
 static void md2_block(MD2_CTX *c, const unsigned char *d);
 /* The magic S table - I have converted it to hex since it is
  * basically just a random byte string. */
-static MD2_INT S[256]={
+static const MD2_INT S[256]={
        0x29, 0x2E, 0x43, 0xC9, 0xA2, 0xD8, 0x7C, 0x01,
        0x3D, 0x36, 0x54, 0xA1, 0xEC, 0xF0, 0x06, 0x13,
        0x62, 0xA7, 0x05, 0xF3, 0xC0, 0xC7, 0x73, 0x8C,
@@ -121,7 +116,7 @@ const char *MD2_options(void)
                return("md2(int)");
        }
 
-FIPS_NON_FIPS_MD_Init(MD2)
+int MD2_Init(MD2_CTX *c)
        {
        c->num=0;
        memset(c->state,0,sizeof c->state);
index e0deb78..bb73819 100644 (file)
                                asm (                   \
                                "roll %1,%0"            \
                                : "=r"(ret)             \
-                               : "I"(n), "0"(a)        \
+                               : "I"(n), "0"((unsigned int)(a))        \
                                : "cc");                \
                           ret;                         \
                        })
@@ -293,7 +293,7 @@ int HASH_UPDATE (HASH_CTX *c, const void *data_, size_t len)
         * Wei Dai <weidai@eskimo.com> for pointing it out. */
        if (l < c->Nl) /* overflow */
                c->Nh++;
-       c->Nh+=(len>>29);       /* might cause compiler warning on 16-bit */
+       c->Nh+=(HASH_LONG)(len>>29);    /* might cause compiler warning on 16-bit */
        c->Nl=l;
 
        n = c->num;
@@ -331,7 +331,7 @@ int HASH_UPDATE (HASH_CTX *c, const void *data_, size_t len)
        if (len != 0)
                {
                p = (unsigned char *)c->data;
-               c->num = len;
+               c->num = (unsigned int)len;
                memcpy (p,data,len);
                }
        return 1;
@@ -383,6 +383,7 @@ int HASH_FINAL (unsigned char *md, HASH_CTX *c)
        }
 
 #ifndef MD32_REG_T
+#if defined(__alpha) || defined(__sparcv9) || defined(__mips)
 #define MD32_REG_T long
 /*
  * This comment was originaly written for MD5, which is why it
@@ -400,9 +401,15 @@ int HASH_FINAL (unsigned char *md, HASH_CTX *c)
  * Well, to be honest it should say that this *prevents* 
  * performance degradation.
  *                             <appro@fy.chalmers.se>
- * Apparently there're LP64 compilers that generate better
- * code if A-D are declared int. Most notably GCC-x86_64
- * generates better code.
+ */
+#else
+/*
+ * Above is not absolute and there are LP64 compilers that
+ * generate better code if MD32_REG_T is defined int. The above
+ * pre-processor condition reflects the circumstances under which
+ * the conclusion was made and is subject to further extension.
  *                             <appro@fy.chalmers.se>
  */
+#define MD32_REG_T int
+#endif
 #endif
index 0bc4896..c94a139 100644 (file)
@@ -34,7 +34,7 @@ top:
 all:    lib
 
 lib:    $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -69,19 +69,16 @@ depend:
 dclean:
        $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
        mv -f Makefile.new $(MAKEFILE)
+       rm -f ../../include/openssl/$(EXHEADER) ../../test/$(TEST) ../../apps/$(APPS)
 
 clean:
        rm -f asm/mx86unix.cpp *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
 
 # DO NOT DELETE THIS LINE -- make depend depends on it.
 
-md4_dgst.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
-md4_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-md4_dgst.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-md4_dgst.o: ../../include/openssl/md4.h ../../include/openssl/opensslconf.h
-md4_dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-md4_dgst.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-md4_dgst.o: ../../include/openssl/symhacks.h ../md32_common.h md4_dgst.c
+md4_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/md4.h
+md4_dgst.o: ../../include/openssl/opensslconf.h
+md4_dgst.o: ../../include/openssl/opensslv.h ../md32_common.h md4_dgst.c
 md4_dgst.o: md4_locl.h
 md4_one.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 md4_one.o: ../../include/openssl/md4.h ../../include/openssl/opensslconf.h
index ba1fe4a..c3ed9b3 100644 (file)
@@ -77,7 +77,7 @@ extern "C" {
  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  */
 
-#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)
+#if defined(__LP32__)
 #define MD4_LONG unsigned long
 #elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
 #define MD4_LONG unsigned long
@@ -105,9 +105,6 @@ typedef struct MD4state_st
        unsigned int num;
        } MD4_CTX;
 
-#ifdef OPENSSL_FIPS
-int private_MD4_Init(MD4_CTX *c);
-#endif
 int MD4_Init(MD4_CTX *c);
 int MD4_Update(MD4_CTX *c, const void *data, size_t len);
 int MD4_Final(unsigned char *md, MD4_CTX *c);
index 0f54486..e0c42e8 100644 (file)
 #include <stdio.h>
 #include "md4_locl.h"
 #include <openssl/opensslv.h>
-#include <openssl/err.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
 
 const char MD4_version[]="MD4" OPENSSL_VERSION_PTEXT;
 
@@ -75,15 +70,13 @@ const char MD4_version[]="MD4" OPENSSL_VERSION_PTEXT;
 #define INIT_DATA_C (unsigned long)0x98badcfeL
 #define INIT_DATA_D (unsigned long)0x10325476L
 
-FIPS_NON_FIPS_MD_Init(MD4)
+int MD4_Init(MD4_CTX *c)
        {
+       memset (c,0,sizeof(*c));
        c->A=INIT_DATA_A;
        c->B=INIT_DATA_B;
        c->C=INIT_DATA_C;
        c->D=INIT_DATA_D;
-       c->Nl=0;
-       c->Nh=0;
-       c->num=0;
        return 1;
        }
 
index 3c450fc..9858d53 100644 (file)
@@ -38,21 +38,19 @@ top:
 all:    lib
 
 lib:    $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
-# ELF
-mx86-elf.s: asm/md5-586.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) md5-586.pl elf $(CFLAGS) > ../$@)
-# COFF
-mx86-cof.s: asm/md5-586.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) md5-586.pl coff $(CFLAGS) > ../$@)
-# a.out
-mx86-out.s: asm/md5-586.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) md5-586.pl a.out $(CFLAGS) > ../$@)
+md5-586.s:     asm/md5-586.pl ../perlasm/x86asm.pl
+       $(PERL) asm/md5-586.pl $(PERLASM_SCHEME) $(CFLAGS) > $@
 
-md5-x86_64.s:  asm/md5-x86_64.pl;      $(PERL) asm/md5-x86_64.pl $@
+md5-x86_64.s:  asm/md5-x86_64.pl
+       $(PERL) asm/md5-x86_64.pl $(PERLASM_SCHEME) > $@
+
+md5-ia64.s: asm/md5-ia64.S
+       $(CC) $(CFLAGS) -E asm/md5-ia64.S | \
+       $(PERL) -ne 's/;\s+/;\n/g; print;' > $@
 
 files:
        $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
@@ -91,13 +89,9 @@ clean:
 
 # DO NOT DELETE THIS LINE -- make depend depends on it.
 
-md5_dgst.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
-md5_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-md5_dgst.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-md5_dgst.o: ../../include/openssl/md5.h ../../include/openssl/opensslconf.h
-md5_dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-md5_dgst.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-md5_dgst.o: ../../include/openssl/symhacks.h ../md32_common.h md5_dgst.c
+md5_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/md5.h
+md5_dgst.o: ../../include/openssl/opensslconf.h
+md5_dgst.o: ../../include/openssl/opensslv.h ../md32_common.h md5_dgst.c
 md5_dgst.o: md5_locl.h
 md5_one.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 md5_one.o: ../../include/openssl/md5.h ../../include/openssl/opensslconf.h
index 76ac235..6cb66bb 100644 (file)
@@ -7,7 +7,8 @@
 
 $normal=0;
 
-push(@INC,"perlasm","../../perlasm");
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+push(@INC,"${dir}","${dir}../../perlasm");
 require "x86asm.pl";
 
 &asm_init($ARGV[0],$0);
diff --git a/deps/openssl/openssl/crypto/md5/asm/md5-ia64.S b/deps/openssl/openssl/crypto/md5/asm/md5-ia64.S
new file mode 100644 (file)
index 0000000..e7de08d
--- /dev/null
@@ -0,0 +1,992 @@
+/* Copyright (c) 2005 Hewlett-Packard Development Company, L.P.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
+
+//     Common registers are assigned as follows:
+//
+//     COMMON
+//
+//     t0              Const Tbl Ptr   TPtr
+//     t1              Round Constant  TRound
+//     t4              Block residual  LenResid
+//     t5              Residual Data   DTmp
+//
+//     {in,out}0       Block 0 Cycle   RotateM0
+//     {in,out}1       Block Value 12  M12
+//     {in,out}2       Block Value 8   M8
+//     {in,out}3       Block Value 4   M4
+//     {in,out}4       Block Value 0   M0
+//     {in,out}5       Block 1 Cycle   RotateM1
+//     {in,out}6       Block Value 13  M13
+//     {in,out}7       Block Value 9   M9
+//     {in,out}8       Block Value 5   M5
+//     {in,out}9       Block Value 1   M1
+//     {in,out}10      Block 2 Cycle   RotateM2
+//     {in,out}11      Block Value 14  M14
+//     {in,out}12      Block Value 10  M10
+//     {in,out}13      Block Value 6   M6
+//     {in,out}14      Block Value 2   M2
+//     {in,out}15      Block 3 Cycle   RotateM3
+//     {in,out}16      Block Value 15  M15
+//     {in,out}17      Block Value 11  M11
+//     {in,out}18      Block Value 7   M7
+//     {in,out}19      Block Value 3   M3
+//     {in,out}20      Scratch                 Z
+//     {in,out}21      Scratch                 Y
+//     {in,out}22      Scratch                 X
+//     {in,out}23      Scratch                 W
+//     {in,out}24      Digest A                A
+//     {in,out}25      Digest B                B
+//     {in,out}26      Digest C                C
+//     {in,out}27      Digest D                D
+//     {in,out}28      Active Data Ptr DPtr
+//     in28            Dummy Value             -
+//     out28           Dummy Value             -
+//     bt0                     Coroutine Link  QUICK_RTN
+//
+///    These predicates are used for computing the padding block(s) and
+///    are shared between the driver and digest co-routines
+//
+//     pt0                     Extra Pad Block pExtra
+//     pt1                     Load next word  pLoad
+//     pt2                     Skip next word  pSkip
+//     pt3                     Search for Pad  pNoPad
+//     pt4                     Pad Word 0              pPad0
+//     pt5                     Pad Word 1              pPad1
+//     pt6                     Pad Word 2              pPad2
+//     pt7                     Pad Word 3              pPad3
+
+#define        DTmp            r19
+#define        LenResid        r18
+#define        QUICK_RTN       b6
+#define        TPtr            r14
+#define        TRound          r15
+#define        pExtra          p6
+#define        pLoad           p7
+#define        pNoPad          p9
+#define        pPad0           p10
+#define        pPad1           p11
+#define        pPad2           p12
+#define        pPad3           p13
+#define        pSkip           p8
+
+#define        A_              out24
+#define        B_              out25
+#define        C_              out26
+#define        D_              out27
+#define        DPtr_           out28
+#define        M0_             out4
+#define        M1_             out9
+#define        M10_            out12
+#define        M11_            out17
+#define        M12_            out1
+#define        M13_            out6
+#define        M14_            out11
+#define        M15_            out16
+#define        M2_             out14
+#define        M3_             out19
+#define        M4_             out3
+#define        M5_             out8
+#define        M6_             out13
+#define        M7_             out18
+#define        M8_             out2
+#define        M9_             out7
+#define        RotateM0_       out0
+#define        RotateM1_       out5
+#define        RotateM2_       out10
+#define        RotateM3_       out15
+#define        W_              out23
+#define        X_              out22
+#define        Y_              out21
+#define        Z_              out20
+
+#define        A               in24
+#define        B               in25
+#define        C               in26
+#define        D               in27
+#define        DPtr            in28
+#define        M0              in4
+#define        M1              in9
+#define        M10             in12
+#define        M11             in17
+#define        M12             in1
+#define        M13             in6
+#define        M14             in11
+#define        M15             in16
+#define        M2              in14
+#define        M3              in19
+#define        M4              in3
+#define        M5              in8
+#define        M6              in13
+#define        M7              in18
+#define        M8              in2
+#define        M9              in7
+#define        RotateM0        in0
+#define        RotateM1        in5
+#define        RotateM2        in10
+#define        RotateM3        in15
+#define        W               in23
+#define        X               in22
+#define        Y               in21
+#define        Z               in20
+
+/* register stack configuration for md5_block_asm_data_order(): */
+#define        MD5_NINP        3
+#define        MD5_NLOC        0
+#define MD5_NOUT       29
+#define MD5_NROT       0
+
+/* register stack configuration for helpers: */
+#define        _NINPUTS        MD5_NOUT
+#define        _NLOCALS        0
+#define _NOUTPUT       0
+#define        _NROTATE        24      /* this must be <= _NINPUTS */
+
+#if defined(_HPUX_SOURCE) && !defined(_LP64)
+#define        ADDP    addp4
+#else
+#define        ADDP    add
+#endif
+
+#if defined(_HPUX_SOURCE) || defined(B_ENDIAN)
+#define HOST_IS_BIG_ENDIAN
+#endif
+
+//     Macros for getting the left and right portions of little-endian words
+
+#define        GETLW(dst, src, align)  dep.z dst = src, 32 - 8 * align, 8 * align
+#define        GETRW(dst, src, align)  extr.u dst = src, 8 * align, 32 - 8 * align
+
+//     MD5 driver
+//
+//             Reads an input block, then calls the digest block
+//             subroutine and adds the results to the accumulated
+//             digest.  It allocates 32 outs which the subroutine
+//             uses as it's inputs and rotating
+//             registers. Initializes the round constant pointer and
+//             takes care of saving/restoring ar.lc
+//
+///    INPUT
+//
+//     in0             Context Ptr             CtxPtr0
+//     in1             Input Data Ptr          DPtrIn
+//     in2             Integral Blocks         BlockCount
+//     rp              Return Address          -
+//
+///    CODE
+//
+//     v2              Input Align             InAlign
+//     t0              Shared w/digest         -
+//     t1              Shared w/digest         -
+//     t2              Shared w/digest         -
+//     t3              Shared w/digest         -
+//     t4              Shared w/digest         -
+//     t5              Shared w/digest         -
+//     t6              PFS Save                PFSSave
+//     t7              ar.lc Save              LCSave
+//     t8              Saved PR                PRSave
+//     t9              2nd CtxPtr              CtxPtr1
+//     t10             Table Base              CTable
+//     t11             Table[0]                CTable0
+//     t13             Accumulator A           AccumA
+//     t14             Accumulator B           AccumB
+//     t15             Accumulator C           AccumC
+//     t16             Accumulator D           AccumD
+//     pt0             Shared w/digest         -
+//     pt1             Shared w/digest         -
+//     pt2             Shared w/digest         -
+//     pt3             Shared w/digest         -
+//     pt4             Shared w/digest         -
+//     pt5             Shared w/digest         -
+//     pt6             Shared w/digest         -
+//     pt7             Shared w/digest         -
+//     pt8             Not Aligned             pOff
+//     pt8             Blocks Left             pAgain
+
+#define        AccumA          r27
+#define        AccumB          r28
+#define        AccumC          r29
+#define        AccumD          r30
+#define        CTable          r24
+#define        CTable0         r25
+#define        CtxPtr0         in0
+#define        CtxPtr1         r23
+#define        DPtrIn          in1
+#define        BlockCount      in2
+#define        InAlign         r10
+#define        LCSave          r21
+#define        PFSSave         r20
+#define        PRSave          r22
+#define        pAgain          p63
+#define        pOff            p63
+
+       .text
+
+/* md5_block_asm_data_order(MD5_CTX *c, const void *data, size_t num)
+
+     where:
+      c: a pointer to a structure of this type:
+
+          typedef struct MD5state_st
+            {
+              MD5_LONG A,B,C,D;
+              MD5_LONG Nl,Nh;
+              MD5_LONG data[MD5_LBLOCK];
+              unsigned int num;
+            }
+          MD5_CTX;
+
+      data: a pointer to the input data (may be misaligned)
+      num:  the number of 16-byte blocks to hash (i.e., the length
+            of DATA is 16*NUM.
+
+   */
+
+       .type   md5_block_asm_data_order, @function
+       .global md5_block_asm_data_order
+       .align  32
+       .proc   md5_block_asm_data_order
+md5_block_asm_data_order:
+.md5_block:
+       .prologue
+{      .mmi
+       .save   ar.pfs, PFSSave
+       alloc   PFSSave = ar.pfs, MD5_NINP, MD5_NLOC, MD5_NOUT, MD5_NROT
+       ADDP    CtxPtr1 = 8, CtxPtr0
+       mov     CTable = ip
+}
+{      .mmi
+       ADDP    DPtrIn = 0, DPtrIn
+       ADDP    CtxPtr0 = 0, CtxPtr0
+       .save   ar.lc, LCSave
+       mov     LCSave = ar.lc
+}
+;;
+{      .mmi
+       add     CTable = .md5_tbl_data_order#-.md5_block#, CTable
+       and     InAlign = 0x3, DPtrIn
+}
+
+{      .mmi
+       ld4     AccumA = [CtxPtr0], 4
+       ld4     AccumC = [CtxPtr1], 4
+       .save pr, PRSave
+       mov     PRSave = pr
+       .body
+}
+;;
+{      .mmi
+       ld4     AccumB = [CtxPtr0]
+       ld4     AccumD = [CtxPtr1]
+       dep     DPtr_ = 0, DPtrIn, 0, 2
+} ;;
+#ifdef HOST_IS_BIG_ENDIAN
+       rum     psr.be;;        // switch to little-endian
+#endif
+{      .mmb
+       ld4     CTable0 = [CTable], 4
+       cmp.ne  pOff, p0 = 0, InAlign
+(pOff) br.cond.spnt.many .md5_unaligned
+} ;;
+
+//     The FF load/compute loop rotates values three times, so that
+//     loading into M12 here produces the M0 value, M13 -> M1, etc.
+
+.md5_block_loop0:
+{      .mmi
+       ld4     M12_ = [DPtr_], 4
+       mov     TPtr = CTable
+       mov     TRound = CTable0
+} ;;
+{      .mmi
+       ld4     M13_ = [DPtr_], 4
+       mov     A_ = AccumA
+       mov     B_ = AccumB
+} ;;
+{      .mmi
+       ld4     M14_ = [DPtr_], 4
+       mov     C_ = AccumC
+       mov     D_ = AccumD
+} ;;
+{      .mmb
+       ld4     M15_ = [DPtr_], 4
+       add     BlockCount = -1, BlockCount
+       br.call.sptk.many QUICK_RTN = md5_digest_block0
+} ;;
+
+//     Now, we add the new digest values and do some clean-up
+//     before checking if there's another full block to process
+
+{      .mmi
+       add     AccumA = AccumA, A_
+       add     AccumB = AccumB, B_
+       cmp.ne  pAgain, p0 = 0, BlockCount
+}
+{      .mib
+       add     AccumC = AccumC, C_
+       add     AccumD = AccumD, D_
+(pAgain) br.cond.dptk.many .md5_block_loop0
+} ;;
+
+.md5_exit:
+#ifdef HOST_IS_BIG_ENDIAN
+       sum     psr.be;;        // switch back to big-endian mode
+#endif
+{      .mmi
+       st4     [CtxPtr0] = AccumB, -4
+       st4     [CtxPtr1] = AccumD, -4
+       mov     pr = PRSave, 0x1ffff ;;
+}
+{      .mmi
+       st4     [CtxPtr0] = AccumA
+       st4     [CtxPtr1] = AccumC
+       mov     ar.lc = LCSave
+} ;;
+{      .mib
+       mov     ar.pfs = PFSSave
+       br.ret.sptk.few rp
+} ;;
+
+#define        MD5UNALIGNED(offset)                                            \
+.md5_process##offset:                                                  \
+{      .mib ;                                                          \
+       nop     0x0     ;                                               \
+       GETRW(DTmp, DTmp, offset) ;                                     \
+} ;;                                                                   \
+.md5_block_loop##offset:                                               \
+{      .mmi ;                                                          \
+       ld4     Y_ = [DPtr_], 4 ;                                       \
+       mov     TPtr = CTable ;                                         \
+       mov     TRound = CTable0 ;                                      \
+} ;;                                                                   \
+{      .mmi ;                                                          \
+       ld4     M13_ = [DPtr_], 4 ;                                     \
+       mov     A_ = AccumA ;                                           \
+       mov     B_ = AccumB ;                                           \
+} ;;                                                                   \
+{      .mii ;                                                          \
+       ld4     M14_ = [DPtr_], 4 ;                                     \
+       GETLW(W_, Y_, offset) ;                                         \
+       mov     C_ = AccumC ;                                           \
+}                                                                      \
+{      .mmi ;                                                          \
+       mov     D_ = AccumD ;;                                          \
+       or      M12_ = W_, DTmp ;                                       \
+       GETRW(DTmp, Y_, offset) ;                                       \
+}                                                                      \
+{      .mib ;                                                          \
+       ld4     M15_ = [DPtr_], 4 ;                                     \
+       add     BlockCount = -1, BlockCount ;                           \
+       br.call.sptk.many QUICK_RTN = md5_digest_block##offset;         \
+} ;;                                                                   \
+{      .mmi ;                                                          \
+       add     AccumA = AccumA, A_ ;                                   \
+       add     AccumB = AccumB, B_ ;                                   \
+       cmp.ne  pAgain, p0 = 0, BlockCount ;                            \
+}                                                                      \
+{      .mib ;                                                          \
+       add     AccumC = AccumC, C_ ;                                   \
+       add     AccumD = AccumD, D_ ;                                   \
+(pAgain) br.cond.dptk.many .md5_block_loop##offset ;                   \
+} ;;                                                                   \
+{      .mib ;                                                          \
+       nop     0x0 ;                                                   \
+       nop     0x0 ;                                                   \
+       br.cond.sptk.many .md5_exit ;                                   \
+} ;;
+
+       .align  32
+.md5_unaligned:
+//
+//     Because variable shifts are expensive, we special case each of
+//     the four alignements. In practice, this won't hurt too much
+//     since only one working set of code will be loaded.
+//
+{      .mib
+       ld4     DTmp = [DPtr_], 4
+       cmp.eq  pOff, p0 = 1, InAlign
+(pOff) br.cond.dpnt.many .md5_process1
+} ;;
+{      .mib
+       cmp.eq  pOff, p0 = 2, InAlign
+       nop     0x0
+(pOff) br.cond.dpnt.many .md5_process2
+} ;;
+       MD5UNALIGNED(3)
+       MD5UNALIGNED(1)
+       MD5UNALIGNED(2)
+
+       .endp md5_block_asm_data_order
+
+
+// MD5 Perform the F function and load
+//
+// Passed the first 4 words (M0 - M3) and initial (A, B, C, D) values,
+// computes the FF() round of functions, then branches to the common
+// digest code to finish up with GG(), HH, and II().
+//
+// INPUT
+//
+// rp Return Address -
+//
+// CODE
+//
+// v0 PFS bit bucket PFS
+// v1 Loop Trip Count LTrip
+// pt0 Load next word pMore
+
+/* For F round: */
+#define LTrip  r9
+#define PFS    r8
+#define pMore  p6
+
+/* For GHI rounds: */
+#define T      r9
+#define U      r10
+#define V      r11
+
+#define COMPUTE(a, b, s, M, R)                 \
+{                                              \
+       .mii ;                                  \
+       ld4 TRound = [TPtr], 4 ;                \
+       dep.z Y = Z, 32, 32 ;;                  \
+       shrp Z = Z, Y, 64 - s ;                 \
+} ;;                                           \
+{                                              \
+       .mmi ;                                  \
+       add a = Z, b ;                          \
+       mov R = M ;                             \
+       nop 0x0 ;                               \
+} ;;
+
+#define LOOP(a, b, s, M, R, label)             \
+{      .mii ;                                  \
+       ld4 TRound = [TPtr], 4 ;                \
+       dep.z Y = Z, 32, 32 ;;                  \
+       shrp Z = Z, Y, 64 - s ;                 \
+} ;;                                           \
+{      .mib ;                                  \
+       add a = Z, b ;                          \
+       mov R = M ;                             \
+       br.ctop.sptk.many label ;               \
+} ;;
+
+// G(B, C, D) = (B & D) | (C & ~D)
+
+#define G(a, b, c, d, M)                       \
+{      .mmi ;                                  \
+       add Z = M, TRound ;                     \
+       and Y = b, d ;                          \
+       andcm X = c, d ;                        \
+} ;;                                           \
+{      .mii ;                                  \
+       add Z = Z, a ;                          \
+       or Y = Y, X ;;                          \
+       add Z = Z, Y ;                          \
+} ;;
+
+// H(B, C, D) = B ^ C ^ D
+
+#define H(a, b, c, d, M)                       \
+{      .mmi ;                                  \
+       add Z = M, TRound ;                     \
+       xor Y = b, c ;                          \
+       nop 0x0 ;                               \
+} ;;                                           \
+{      .mii ;                                  \
+       add Z = Z, a ;                          \
+       xor Y = Y, d ;;                         \
+       add Z = Z, Y ;                          \
+} ;;
+
+// I(B, C, D) = C ^ (B | ~D)
+//
+// However, since we have an andcm operator, we use the fact that
+//
+// Y ^ Z == ~Y ^ ~Z
+//
+// to rewrite the expression as
+//
+// I(B, C, D) = ~C ^ (~B & D)
+
+#define I(a, b, c, d, M)                       \
+{      .mmi ;                                  \
+       add Z = M, TRound ;                     \
+       andcm Y = d, b ;                        \
+       andcm X = -1, c ;                       \
+} ;;                                           \
+{      .mii ;                                  \
+       add Z = Z, a ;                          \
+       xor Y = Y, X ;;                         \
+       add Z = Z, Y ;                          \
+} ;;
+
+#define GG4(label)                             \
+       G(A, B, C, D, M0)                       \
+       COMPUTE(A, B, 5, M0, RotateM0)          \
+       G(D, A, B, C, M1)                       \
+       COMPUTE(D, A, 9, M1, RotateM1)          \
+       G(C, D, A, B, M2)                       \
+       COMPUTE(C, D, 14, M2, RotateM2)         \
+       G(B, C, D, A, M3)                       \
+       LOOP(B, C, 20, M3, RotateM3, label)
+
+#define HH4(label)                             \
+       H(A, B, C, D, M0)                       \
+       COMPUTE(A, B, 4, M0, RotateM0)          \
+       H(D, A, B, C, M1)                       \
+       COMPUTE(D, A, 11, M1, RotateM1)         \
+       H(C, D, A, B, M2)                       \
+       COMPUTE(C, D, 16, M2, RotateM2)         \
+       H(B, C, D, A, M3)                       \
+       LOOP(B, C, 23, M3, RotateM3, label)
+
+#define II4(label)                             \
+       I(A, B, C, D, M0)                       \
+       COMPUTE(A, B, 6, M0, RotateM0)          \
+       I(D, A, B, C, M1)                       \
+       COMPUTE(D, A, 10, M1, RotateM1)         \
+       I(C, D, A, B, M2)                       \
+       COMPUTE(C, D, 15, M2, RotateM2)         \
+       I(B, C, D, A, M3)                       \
+       LOOP(B, C, 21, M3, RotateM3, label)
+
+#define FFLOAD(a, b, c, d, M, N, s)            \
+{      .mii ;                                  \
+(pMore) ld4 N = [DPtr], 4 ;                    \
+       add Z = M, TRound ;                     \
+       and Y = c, b ;                          \
+}                                              \
+{      .mmi ;                                  \
+       andcm X = d, b ;;                       \
+       add Z = Z, a ;                          \
+       or Y = Y, X ;                           \
+} ;;                                           \
+{      .mii ;                                  \
+       ld4 TRound = [TPtr], 4 ;                \
+       add Z = Z, Y ;;                         \
+       dep.z Y = Z, 32, 32 ;                   \
+} ;;                                           \
+{      .mii ;                                  \
+       nop 0x0 ;                               \
+       shrp Z = Z, Y, 64 - s ;;                \
+       add a = Z, b ;                          \
+} ;;
+
+#define FFLOOP(a, b, c, d, M, N, s, dest)      \
+{      .mii ;                                  \
+(pMore)        ld4 N = [DPtr], 4 ;                     \
+       add Z = M, TRound ;                     \
+       and Y = c, b ;                          \
+}                                              \
+{      .mmi ;                                  \
+       andcm X = d, b ;;                       \
+       add Z = Z, a ;                          \
+       or Y = Y, X ;                           \
+} ;;                                           \
+{      .mii ;                                  \
+       ld4 TRound = [TPtr], 4 ;                \
+       add Z = Z, Y ;;                         \
+       dep.z Y = Z, 32, 32 ;                   \
+} ;;                                           \
+{      .mii ;                                  \
+       nop 0x0 ;                               \
+       shrp Z = Z, Y, 64 - s ;;                \
+       add a = Z, b ;                          \
+}                                              \
+{      .mib ;                                  \
+       cmp.ne pMore, p0 = 0, LTrip ;           \
+       add LTrip = -1, LTrip ;                 \
+       br.ctop.dptk.many dest ;                \
+} ;;
+
+       .type md5_digest_block0, @function
+       .align 32
+
+       .proc md5_digest_block0
+       .prologue
+md5_digest_block0:
+       .altrp QUICK_RTN
+       .body
+{      .mmi
+       alloc PFS = ar.pfs, _NINPUTS, _NLOCALS, _NOUTPUT, _NROTATE
+       mov LTrip = 2
+       mov ar.lc = 3
+} ;;
+{      .mii
+       cmp.eq pMore, p0 = r0, r0
+       mov ar.ec = 0
+       nop 0x0
+} ;;
+
+.md5_FF_round0:
+       FFLOAD(A, B, C, D, M12, RotateM0, 7)
+       FFLOAD(D, A, B, C, M13, RotateM1, 12)
+       FFLOAD(C, D, A, B, M14, RotateM2, 17)
+       FFLOOP(B, C, D, A, M15, RotateM3, 22, .md5_FF_round0)
+       //
+       // !!! Fall through to md5_digest_GHI
+       //
+       .endp md5_digest_block0
+
+       .type md5_digest_GHI, @function
+       .align 32
+
+       .proc md5_digest_GHI
+       .prologue
+       .regstk _NINPUTS, _NLOCALS, _NOUTPUT, _NROTATE
+md5_digest_GHI:
+       .altrp QUICK_RTN
+       .body
+//
+// The following sequence shuffles the block counstants round for the
+// next round:
+//
+// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
+// 1 6 11 0 5 10 14 4 9 14 3 8 13 2 7 12
+//
+{      .mmi
+       mov Z = M0
+       mov Y = M15
+       mov ar.lc = 3
+}
+{      .mmi
+       mov X = M2
+       mov W = M9
+       mov V = M4
+} ;;
+
+{      .mmi
+       mov M0 = M1
+       mov M15 = M12
+       mov ar.ec = 1
+}
+{      .mmi
+       mov M2 = M11
+       mov M9 = M14
+       mov M4 = M5
+} ;;
+
+{      .mmi
+       mov M1 = M6
+       mov M12 = M13
+       mov U = M3
+}
+{      .mmi
+       mov M11 = M8
+       mov M14 = M7
+       mov M5 = M10
+} ;;
+
+{      .mmi
+       mov M6 = Y
+       mov M13 = X
+       mov M3 = Z
+}
+{      .mmi
+       mov M8 = W
+       mov M7 = V
+       mov M10 = U
+} ;;
+
+.md5_GG_round:
+       GG4(.md5_GG_round)
+
+// The following sequence shuffles the block constants round for the
+// next round:
+//
+// 1 6 11 0 5 10 14 4 9 14 3 8 13 2 7 12
+// 5 8 11 14 1 4 7 10 13 0 3 6 9 12 15 2
+
+{      .mmi
+       mov Z = M0
+       mov Y = M1
+       mov ar.lc = 3
+}
+{      .mmi
+       mov X = M3
+       mov W = M5
+       mov V = M6
+} ;;
+
+{      .mmi
+       mov M0 = M4
+       mov M1 = M11
+       mov ar.ec = 1
+}
+{      .mmi
+       mov M3 = M9
+       mov U = M8
+       mov T = M13
+} ;;
+
+{      .mmi
+       mov M4 = Z
+       mov M11 = Y
+       mov M5 = M7
+}
+{      .mmi
+       mov M6 = M14
+       mov M8 = M12
+       mov M13 = M15
+} ;;
+
+{      .mmi
+       mov M7 = W
+       mov M14 = V
+       nop 0x0
+}
+{      .mmi
+       mov M9 = X
+       mov M12 = U
+       mov M15 = T
+} ;;
+
+.md5_HH_round:
+       HH4(.md5_HH_round)
+
+// The following sequence shuffles the block constants round for the
+// next round:
+//
+// 5 8 11 14 1 4 7 10 13 0 3 6 9 12 15 2
+// 0 7 14 5 12 3 10 1 8 15 6 13 4 11 2 9
+
+{      .mmi
+       mov Z = M0
+       mov Y = M15
+       mov ar.lc = 3
+}
+{      .mmi
+       mov X = M10
+       mov W = M1
+       mov V = M4
+} ;;
+
+{      .mmi
+       mov M0 = M9
+       mov M15 = M12
+       mov ar.ec = 1
+}
+{      .mmi
+       mov M10 = M11
+       mov M1 = M6
+       mov M4 = M13
+} ;;
+
+{      .mmi
+       mov M9 = M14
+       mov M12 = M5
+       mov U = M3
+}
+{      .mmi
+       mov M11 = M8
+       mov M6 = M7
+       mov M13 = M2
+} ;;
+
+{      .mmi
+       mov M14 = Y
+       mov M5 = X
+       mov M3 = Z
+}
+{      .mmi
+       mov M8 = W
+       mov M7 = V
+       mov M2 = U
+} ;;
+
+.md5_II_round:
+       II4(.md5_II_round)
+
+{      .mib
+       nop 0x0
+       nop 0x0
+       br.ret.sptk.many QUICK_RTN
+} ;;
+
+       .endp md5_digest_GHI
+
+#define FFLOADU(a, b, c, d, M, P, N, s, offset)        \
+{      .mii ;                                  \
+(pMore) ld4 N = [DPtr], 4 ;                    \
+       add Z = M, TRound ;                     \
+       and Y = c, b ;                          \
+}                                              \
+{      .mmi ;                                  \
+       andcm X = d, b ;;                       \
+       add Z = Z, a ;                          \
+       or Y = Y, X ;                           \
+} ;;                                           \
+{      .mii ;                                  \
+       ld4 TRound = [TPtr], 4 ;                \
+       GETLW(W, P, offset) ;                   \
+       add Z = Z, Y ;                          \
+} ;;                                           \
+{      .mii ;                                  \
+       or W = W, DTmp ;                        \
+       dep.z Y = Z, 32, 32 ;;                  \
+       shrp Z = Z, Y, 64 - s ;                 \
+} ;;                                           \
+{      .mii ;                                  \
+       add a = Z, b ;                          \
+       GETRW(DTmp, P, offset) ;                \
+       mov P = W ;                             \
+} ;;
+
+#define FFLOOPU(a, b, c, d, M, P, N, s, offset)                \
+{      .mii ;                                          \
+(pMore) ld4 N = [DPtr], 4 ;                            \
+       add Z = M, TRound ;                             \
+       and Y = c, b ;                                  \
+}                                                      \
+{      .mmi ;                                          \
+       andcm X = d, b ;;                               \
+       add Z = Z, a ;                                  \
+       or Y = Y, X ;                                   \
+} ;;                                                   \
+{      .mii ;                                          \
+       ld4 TRound = [TPtr], 4 ;                        \
+(pMore) GETLW(W, P, offset)    ;                       \
+       add Z = Z, Y ;                                  \
+} ;;                                                   \
+{      .mii ;                                          \
+(pMore) or W = W, DTmp ;                               \
+       dep.z Y = Z, 32, 32 ;;                          \
+       shrp Z = Z, Y, 64 - s ;                         \
+} ;;                                                   \
+{      .mii ;                                          \
+       add a = Z, b ;                                  \
+(pMore) GETRW(DTmp, P, offset)         ;                       \
+(pMore) mov P = W ;                                    \
+}                                                      \
+{      .mib ;                                          \
+       cmp.ne pMore, p0 = 0, LTrip ;                   \
+       add LTrip = -1, LTrip ;                         \
+       br.ctop.sptk.many .md5_FF_round##offset ;       \
+} ;;
+
+#define MD5FBLOCK(offset)                                              \
+       .type md5_digest_block##offset, @function ;                     \
+                                                                       \
+       .align 32 ;                                                     \
+       .proc md5_digest_block##offset ;                                \
+       .prologue ;                                                     \
+       .altrp QUICK_RTN ;                                              \
+       .body ;                                                         \
+md5_digest_block##offset:                                              \
+{      .mmi ;                                                          \
+       alloc PFS = ar.pfs, _NINPUTS, _NLOCALS, _NOUTPUT, _NROTATE ;    \
+       mov LTrip = 2 ;                                                 \
+       mov ar.lc = 3 ;                                                 \
+} ;;                                                                   \
+{      .mii ;                                                          \
+       cmp.eq pMore, p0 = r0, r0 ;                                     \
+       mov ar.ec = 0 ;                                                 \
+       nop 0x0 ;                                                       \
+} ;;                                                                   \
+                                                                       \
+       .pred.rel "mutex", pLoad, pSkip ;                               \
+.md5_FF_round##offset:                                                 \
+       FFLOADU(A, B, C, D, M12, M13, RotateM0, 7, offset)              \
+       FFLOADU(D, A, B, C, M13, M14, RotateM1, 12, offset)             \
+       FFLOADU(C, D, A, B, M14, M15, RotateM2, 17, offset)             \
+       FFLOOPU(B, C, D, A, M15, RotateM0, RotateM3, 22, offset)        \
+                                                                       \
+{      .mib ;                                                          \
+       nop 0x0 ;                                                       \
+       nop 0x0 ;                                                       \
+       br.cond.sptk.many md5_digest_GHI ;                              \
+} ;;                                                                   \
+       .endp md5_digest_block##offset
+
+MD5FBLOCK(1)
+MD5FBLOCK(2)
+MD5FBLOCK(3)
+
+       .align 64
+       .type md5_constants, @object
+md5_constants:
+.md5_tbl_data_order:                   // To ensure little-endian data
+                                       // order, code as bytes.
+       data1 0x78, 0xa4, 0x6a, 0xd7    //     0
+       data1 0x56, 0xb7, 0xc7, 0xe8    //     1
+       data1 0xdb, 0x70, 0x20, 0x24    //     2
+       data1 0xee, 0xce, 0xbd, 0xc1    //     3
+       data1 0xaf, 0x0f, 0x7c, 0xf5    //     4
+       data1 0x2a, 0xc6, 0x87, 0x47    //     5
+       data1 0x13, 0x46, 0x30, 0xa8    //     6
+       data1 0x01, 0x95, 0x46, 0xfd    //     7
+       data1 0xd8, 0x98, 0x80, 0x69    //     8
+       data1 0xaf, 0xf7, 0x44, 0x8b    //     9
+       data1 0xb1, 0x5b, 0xff, 0xff    //    10
+       data1 0xbe, 0xd7, 0x5c, 0x89    //    11
+       data1 0x22, 0x11, 0x90, 0x6b    //    12
+       data1 0x93, 0x71, 0x98, 0xfd    //    13
+       data1 0x8e, 0x43, 0x79, 0xa6    //    14
+       data1 0x21, 0x08, 0xb4, 0x49    //    15
+       data1 0x62, 0x25, 0x1e, 0xf6    //    16
+       data1 0x40, 0xb3, 0x40, 0xc0    //    17
+       data1 0x51, 0x5a, 0x5e, 0x26    //    18
+       data1 0xaa, 0xc7, 0xb6, 0xe9    //    19
+       data1 0x5d, 0x10, 0x2f, 0xd6    //    20
+       data1 0x53, 0x14, 0x44, 0x02    //    21
+       data1 0x81, 0xe6, 0xa1, 0xd8    //    22
+       data1 0xc8, 0xfb, 0xd3, 0xe7    //    23
+       data1 0xe6, 0xcd, 0xe1, 0x21    //    24
+       data1 0xd6, 0x07, 0x37, 0xc3    //    25
+       data1 0x87, 0x0d, 0xd5, 0xf4    //    26
+       data1 0xed, 0x14, 0x5a, 0x45    //    27
+       data1 0x05, 0xe9, 0xe3, 0xa9    //    28
+       data1 0xf8, 0xa3, 0xef, 0xfc    //    29
+       data1 0xd9, 0x02, 0x6f, 0x67    //    30
+       data1 0x8a, 0x4c, 0x2a, 0x8d    //    31
+       data1 0x42, 0x39, 0xfa, 0xff    //    32
+       data1 0x81, 0xf6, 0x71, 0x87    //    33
+       data1 0x22, 0x61, 0x9d, 0x6d    //    34
+       data1 0x0c, 0x38, 0xe5, 0xfd    //    35
+       data1 0x44, 0xea, 0xbe, 0xa4    //    36
+       data1 0xa9, 0xcf, 0xde, 0x4b    //    37
+       data1 0x60, 0x4b, 0xbb, 0xf6    //    38
+       data1 0x70, 0xbc, 0xbf, 0xbe    //    39
+       data1 0xc6, 0x7e, 0x9b, 0x28    //    40
+       data1 0xfa, 0x27, 0xa1, 0xea    //    41
+       data1 0x85, 0x30, 0xef, 0xd4    //    42
+       data1 0x05, 0x1d, 0x88, 0x04    //    43
+       data1 0x39, 0xd0, 0xd4, 0xd9    //    44
+       data1 0xe5, 0x99, 0xdb, 0xe6    //    45
+       data1 0xf8, 0x7c, 0xa2, 0x1f    //    46
+       data1 0x65, 0x56, 0xac, 0xc4    //    47
+       data1 0x44, 0x22, 0x29, 0xf4    //    48
+       data1 0x97, 0xff, 0x2a, 0x43    //    49
+       data1 0xa7, 0x23, 0x94, 0xab    //    50
+       data1 0x39, 0xa0, 0x93, 0xfc    //    51
+       data1 0xc3, 0x59, 0x5b, 0x65    //    52
+       data1 0x92, 0xcc, 0x0c, 0x8f    //    53
+       data1 0x7d, 0xf4, 0xef, 0xff    //    54
+       data1 0xd1, 0x5d, 0x84, 0x85    //    55
+       data1 0x4f, 0x7e, 0xa8, 0x6f    //    56
+       data1 0xe0, 0xe6, 0x2c, 0xfe    //    57
+       data1 0x14, 0x43, 0x01, 0xa3    //    58
+       data1 0xa1, 0x11, 0x08, 0x4e    //    59
+       data1 0x82, 0x7e, 0x53, 0xf7    //    60
+       data1 0x35, 0xf2, 0x3a, 0xbd    //    61
+       data1 0xbb, 0xd2, 0xd7, 0x2a    //    62
+       data1 0x91, 0xd3, 0x86, 0xeb    //    63
+.size  md5_constants#,64*4
index 05d040f..8678854 100755 (executable)
@@ -15,11 +15,10 @@ my $code;
 #   dst = x + ((dst + F(x,y,z) + X[k] + T_i) <<< s)
 #   %r10d = X[k_next]
 #   %r11d = z' (copy of z for the next step)
-# Each round1_step() takes about 5.71 clocks (9 instructions, 1.58 IPC)
+# Each round1_step() takes about 5.3 clocks (9 instructions, 1.7 IPC)
 sub round1_step
 {
     my ($pos, $dst, $x, $y, $z, $k_next, $T_i, $s) = @_;
-    $T_i = unpack("l",pack("l", hex($T_i))); # convert to 32-bit signed decimal
     $code .= " mov     0*4(%rsi),      %r10d           /* (NEXT STEP) X[0] */\n" if ($pos == -1);
     $code .= " mov     %edx,           %r11d           /* (NEXT STEP) z' = %edx */\n" if ($pos == -1);
     $code .= <<EOF;
@@ -38,23 +37,26 @@ EOF
 # round2_step() does:
 #   dst = x + ((dst + G(x,y,z) + X[k] + T_i) <<< s)
 #   %r10d = X[k_next]
-#   %r11d = y' (copy of y for the next step)
-# Each round2_step() takes about 6.22 clocks (9 instructions, 1.45 IPC)
+#   %r11d = z' (copy of z for the next step)
+#   %r12d = z' (copy of z for the next step)
+# Each round2_step() takes about 5.4 clocks (11 instructions, 2.0 IPC)
 sub round2_step
 {
     my ($pos, $dst, $x, $y, $z, $k_next, $T_i, $s) = @_;
-    $T_i = unpack("l",pack("l", hex($T_i))); # convert to 32-bit signed decimal
     $code .= " mov     1*4(%rsi),      %r10d           /* (NEXT STEP) X[1] */\n" if ($pos == -1);
-    $code .= " mov     %ecx,           %r11d           /* (NEXT STEP) y' = %ecx */\n" if ($pos == -1);
+    $code .= " mov     %edx,           %r11d           /* (NEXT STEP) z' = %edx */\n" if ($pos == -1);
+    $code .= " mov     %edx,           %r12d           /* (NEXT STEP) z' = %edx */\n" if ($pos == -1);
     $code .= <<EOF;
-       xor     $x,             %r11d           /* x ^ ... */
+       not     %r11d                           /* not z */
        lea     $T_i($dst,%r10d),$dst           /* Const + dst + ... */
-       and     $z,             %r11d           /* z & ... */
-       xor     $y,             %r11d           /* y ^ ... */
+       and     $x,             %r12d           /* x & z */
+       and     $y,             %r11d           /* y & (not z) */
        mov     $k_next*4(%rsi),%r10d           /* (NEXT STEP) X[$k_next] */
-       add     %r11d,          $dst            /* dst += ... */
+       or      %r11d,          %r12d           /* (y & (not z)) | (x & z) */
+       mov     $y,             %r11d           /* (NEXT STEP) z' = $y */
+       add     %r12d,          $dst            /* dst += ... */
+       mov     $y,             %r12d           /* (NEXT STEP) z' = $y */
        rol     \$$s,           $dst            /* dst <<< s */
-       mov     $x,             %r11d           /* (NEXT STEP) y' = $x */
        add     $x,             $dst            /* dst += x */
 EOF
 }
@@ -63,11 +65,10 @@ EOF
 #   dst = x + ((dst + H(x,y,z) + X[k] + T_i) <<< s)
 #   %r10d = X[k_next]
 #   %r11d = y' (copy of y for the next step)
-# Each round3_step() takes about 4.26 clocks (8 instructions, 1.88 IPC)
+# Each round3_step() takes about 4.2 clocks (8 instructions, 1.9 IPC)
 sub round3_step
 {
     my ($pos, $dst, $x, $y, $z, $k_next, $T_i, $s) = @_;
-    $T_i = unpack("l",pack("l", hex($T_i))); # convert to 32-bit signed decimal
     $code .= " mov     5*4(%rsi),      %r10d           /* (NEXT STEP) X[5] */\n" if ($pos == -1);
     $code .= " mov     %ecx,           %r11d           /* (NEXT STEP) y' = %ecx */\n" if ($pos == -1);
     $code .= <<EOF;
@@ -86,11 +87,10 @@ EOF
 #   dst = x + ((dst + I(x,y,z) + X[k] + T_i) <<< s)
 #   %r10d = X[k_next]
 #   %r11d = not z' (copy of not z for the next step)
-# Each round4_step() takes about 5.27 clocks (9 instructions, 1.71 IPC)
+# Each round4_step() takes about 5.2 clocks (9 instructions, 1.7 IPC)
 sub round4_step
 {
     my ($pos, $dst, $x, $y, $z, $k_next, $T_i, $s) = @_;
-    $T_i = unpack("l",pack("l", hex($T_i))); # convert to 32-bit signed decimal
     $code .= " mov     0*4(%rsi),      %r10d           /* (NEXT STEP) X[0] */\n" if ($pos == -1);
     $code .= " mov     \$0xffffffff,   %r11d\n" if ($pos == -1);
     $code .= " xor     %edx,           %r11d           /* (NEXT STEP) not z' = not %edx*/\n"
@@ -108,8 +108,19 @@ sub round4_step
 EOF
 }
 
-my $output = shift;
-open STDOUT,"| $^X ../perlasm/x86_64-xlate.pl $output";
+my $flavour = shift;
+my $output  = shift;
+if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
+
+my $win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
+
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; my $dir=$1; my $xlate;
+( $xlate="${dir}x86_64-xlate.pl" and -f $xlate ) or
+( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
+die "can't locate x86_64-xlate.pl";
+
+no warnings qw(uninitialized);
+open STDOUT,"| $^X $xlate $flavour $output";
 
 $code .= <<EOF;
 .text
@@ -120,8 +131,10 @@ $code .= <<EOF;
 md5_block_asm_data_order:
        push    %rbp
        push    %rbx
+       push    %r12
        push    %r14
        push    %r15
+.Lprologue:
 
        # rdi = arg #1 (ctx, MD5_CTX pointer)
        # rsi = arg #2 (ptr, data pointer)
@@ -236,13 +249,120 @@ $code .= <<EOF;
        mov     %ecx,           2*4(%rbp)       # ctx->C = C
        mov     %edx,           3*4(%rbp)       # ctx->D = D
 
+       mov     (%rsp),%r15
+       mov     8(%rsp),%r14
+       mov     16(%rsp),%r12
+       mov     24(%rsp),%rbx
+       mov     32(%rsp),%rbp
+       add     \$40,%rsp
+.Lepilogue:
+       ret
+.size md5_block_asm_data_order,.-md5_block_asm_data_order
+EOF
+
+# EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
+#              CONTEXT *context,DISPATCHER_CONTEXT *disp)
+if ($win64) {
+my $rec="%rcx";
+my $frame="%rdx";
+my $context="%r8";
+my $disp="%r9";
+
+$code.=<<___;
+.extern        __imp_RtlVirtualUnwind
+.type  se_handler,\@abi-omnipotent
+.align 16
+se_handler:
+       push    %rsi
+       push    %rdi
+       push    %rbx
+       push    %rbp
+       push    %r12
+       push    %r13
+       push    %r14
+       push    %r15
+       pushfq
+       sub     \$64,%rsp
+
+       mov     120($context),%rax      # pull context->Rax
+       mov     248($context),%rbx      # pull context->Rip
+
+       lea     .Lprologue(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip<.Lprologue
+       jb      .Lin_prologue
+
+       mov     152($context),%rax      # pull context->Rsp
+
+       lea     .Lepilogue(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip>=.Lepilogue
+       jae     .Lin_prologue
+
+       lea     40(%rax),%rax
+
+       mov     -8(%rax),%rbp
+       mov     -16(%rax),%rbx
+       mov     -24(%rax),%r12
+       mov     -32(%rax),%r14
+       mov     -40(%rax),%r15
+       mov     %rbx,144($context)      # restore context->Rbx
+       mov     %rbp,160($context)      # restore context->Rbp
+       mov     %r12,216($context)      # restore context->R12
+       mov     %r14,232($context)      # restore context->R14
+       mov     %r15,240($context)      # restore context->R15
+
+.Lin_prologue:
+       mov     8(%rax),%rdi
+       mov     16(%rax),%rsi
+       mov     %rax,152($context)      # restore context->Rsp
+       mov     %rsi,168($context)      # restore context->Rsi
+       mov     %rdi,176($context)      # restore context->Rdi
+
+       mov     40($disp),%rdi          # disp->ContextRecord
+       mov     $context,%rsi           # context
+       mov     \$154,%ecx              # sizeof(CONTEXT)
+       .long   0xa548f3fc              # cld; rep movsq
+
+       mov     $disp,%rsi
+       xor     %rcx,%rcx               # arg1, UNW_FLAG_NHANDLER
+       mov     8(%rsi),%rdx            # arg2, disp->ImageBase
+       mov     0(%rsi),%r8             # arg3, disp->ControlPc
+       mov     16(%rsi),%r9            # arg4, disp->FunctionEntry
+       mov     40(%rsi),%r10           # disp->ContextRecord
+       lea     56(%rsi),%r11           # &disp->HandlerData
+       lea     24(%rsi),%r12           # &disp->EstablisherFrame
+       mov     %r10,32(%rsp)           # arg5
+       mov     %r11,40(%rsp)           # arg6
+       mov     %r12,48(%rsp)           # arg7
+       mov     %rcx,56(%rsp)           # arg8, (NULL)
+       call    *__imp_RtlVirtualUnwind(%rip)
+
+       mov     \$1,%eax                # ExceptionContinueSearch
+       add     \$64,%rsp
+       popfq
        pop     %r15
        pop     %r14
-       pop     %rbx
+       pop     %r13
+       pop     %r12
        pop     %rbp
+       pop     %rbx
+       pop     %rdi
+       pop     %rsi
        ret
-.size md5_block_asm_data_order,.-md5_block_asm_data_order
-EOF
+.size  se_handler,.-se_handler
+
+.section       .pdata
+.align 4
+       .rva    .LSEH_begin_md5_block_asm_data_order
+       .rva    .LSEH_end_md5_block_asm_data_order
+       .rva    .LSEH_info_md5_block_asm_data_order
+
+.section       .xdata
+.align 8
+.LSEH_info_md5_block_asm_data_order:
+       .byte   9,0,0,0
+       .rva    se_handler
+___
+}
 
 print $code;
 
index 0761f84..4cbf843 100644 (file)
@@ -77,7 +77,7 @@ extern "C" {
  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  */
 
-#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)
+#if defined(__LP32__)
 #define MD5_LONG unsigned long
 #elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
 #define MD5_LONG unsigned long
@@ -105,9 +105,6 @@ typedef struct MD5state_st
        unsigned int num;
        } MD5_CTX;
 
-#ifdef OPENSSL_FIPS
-int private_MD5_Init(MD5_CTX *c);
-#endif
 int MD5_Init(MD5_CTX *c);
 int MD5_Update(MD5_CTX *c, const void *data, size_t len);
 int MD5_Final(unsigned char *md, MD5_CTX *c);
index 47bb902..beace63 100644 (file)
 #include <stdio.h>
 #include "md5_locl.h"
 #include <openssl/opensslv.h>
-#include <openssl/err.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
 
 const char MD5_version[]="MD5" OPENSSL_VERSION_PTEXT;
 
@@ -75,15 +70,13 @@ const char MD5_version[]="MD5" OPENSSL_VERSION_PTEXT;
 #define INIT_DATA_C (unsigned long)0x98badcfeL
 #define INIT_DATA_D (unsigned long)0x10325476L
 
-FIPS_NON_FIPS_MD_Init(MD5)
+int MD5_Init(MD5_CTX *c)
        {
+       memset (c,0,sizeof(*c));
        c->A=INIT_DATA_A;
        c->B=INIT_DATA_B;
        c->C=INIT_DATA_C;
        c->D=INIT_DATA_D;
-       c->Nl=0;
-       c->Nh=0;
-       c->num=0;
        return 1;
        }
 
index 84e81b9..968d577 100644 (file)
@@ -69,6 +69,8 @@
 # if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__) || \
      defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64)
 #  define md5_block_data_order md5_block_asm_data_order
+# elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
+#  define md5_block_data_order md5_block_asm_data_order
 # endif
 #endif
 
index ea25688..1d064f1 100644 (file)
@@ -33,7 +33,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
index 7e13541..72778a5 100644 (file)
@@ -80,9 +80,7 @@ typedef struct mdc2_ctx_st
        int pad_type; /* either 1 or 2, default 1 */
        } MDC2_CTX;
 
-#ifdef OPENSSL_FIPS
-int private_MDC2_Init(MDC2_CTX *c);
-#endif
+
 int MDC2_Init(MDC2_CTX *c);
 int MDC2_Update(MDC2_CTX *c, const unsigned char *data, size_t len);
 int MDC2_Final(unsigned char *md, MDC2_CTX *c);
index a36b3f5..4aa406e 100644 (file)
 #include <string.h>
 #include <openssl/des.h>
 #include <openssl/mdc2.h>
-#include <openssl/err.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
 
 #undef c2l
 #define c2l(c,l)       (l =((DES_LONG)(*((c)++)))    , \
@@ -80,7 +75,7 @@
                        *((c)++)=(unsigned char)(((l)>>24L)&0xff))
 
 static void mdc2_body(MDC2_CTX *c, const unsigned char *in, size_t len);
-FIPS_NON_FIPS_MD_Init(MDC2)
+int MDC2_Init(MDC2_CTX *c)
        {
        c->num=0;
        c->pad_type=1;
index 00ebaf0..6f80dd3 100644 (file)
@@ -101,7 +101,7 @@ static void (*free_locked_func)(void *)     = free;
 
 /* may be changed as long as 'allow_customize_debug' is set */
 /* XXX use correct function pointer types */
-#if defined(CRYPTO_MDEBUG) && !defined(OPENSSL_FIPS)
+#ifdef CRYPTO_MDEBUG
 /* use default functions from mem_dbg.c */
 static void (*malloc_debug_func)(void *,int,const char *,int,int)
        = CRYPTO_dbg_malloc;
@@ -110,14 +110,6 @@ static void (*realloc_debug_func)(void *,void *,int,const char *,int,int)
 static void (*free_debug_func)(void *,int) = CRYPTO_dbg_free;
 static void (*set_debug_options_func)(long) = CRYPTO_dbg_set_options;
 static long (*get_debug_options_func)(void) = CRYPTO_dbg_get_options;
-
-static int  (*push_info_func)(const char *info, const char *file, int line)
-       = CRYPTO_dbg_push_info;
-static int  (*pop_info_func)(void)
-       = CRYPTO_dbg_pop_info;
-static int (*remove_all_info_func)(void)
-       = CRYPTO_dbg_remove_all_info;
-
 #else
 /* applications can use CRYPTO_malloc_debug_init() to select above case
  * at run-time */
@@ -127,13 +119,6 @@ static void (*realloc_debug_func)(void *,void *,int,const char *,int,int)
 static void (*free_debug_func)(void *,int) = NULL;
 static void (*set_debug_options_func)(long) = NULL;
 static long (*get_debug_options_func)(void) = NULL;
-
-
-static int  (*push_info_func)(const char *info, const char *file, int line)
-       = NULL;
-static int  (*pop_info_func)(void) = NULL;
-static int (*remove_all_info_func)(void) = NULL;
-
 #endif
 
 
@@ -209,15 +194,6 @@ int CRYPTO_set_mem_debug_functions(void (*m)(void *,int,const char *,int,int),
        return 1;
        }
 
-void CRYPTO_set_mem_info_functions(
-       int  (*push_info_fn)(const char *info, const char *file, int line),
-       int  (*pop_info_fn)(void),
-       int (*remove_all_info_fn)(void))
-       {
-       push_info_func = push_info_fn;
-       pop_info_func = pop_info_fn;
-       remove_all_info_func = remove_all_info_fn;
-       }
 
 void CRYPTO_get_mem_functions(void *(**m)(size_t), void *(**r)(void *, size_t),
        void (**f)(void *))
@@ -274,7 +250,6 @@ void CRYPTO_get_mem_debug_functions(void (**m)(void *,int,const char *,int,int),
 void *CRYPTO_malloc_locked(int num, const char *file, int line)
        {
        void *ret = NULL;
-       extern unsigned char cleanse_ctr;
 
        if (num <= 0) return NULL;
 
@@ -291,11 +266,15 @@ void *CRYPTO_malloc_locked(int num, const char *file, int line)
        if (malloc_debug_func != NULL)
                malloc_debug_func(ret, num, file, line, 1);
 
+#ifndef OPENSSL_CPUID_OBJ
         /* Create a dependency on the value of 'cleanse_ctr' so our memory
          * sanitisation function can't be optimised out. NB: We only do
          * this for >2Kb so the overhead doesn't bother us. */
         if(ret && (num > 2048))
+       {       extern unsigned char cleanse_ctr;
                ((unsigned char *)ret)[0] = cleanse_ctr;
+       }
+#endif
 
        return ret;
        }
@@ -315,7 +294,6 @@ void CRYPTO_free_locked(void *str)
 void *CRYPTO_malloc(int num, const char *file, int line)
        {
        void *ret = NULL;
-       extern unsigned char cleanse_ctr;
 
        if (num <= 0) return NULL;
 
@@ -332,12 +310,23 @@ void *CRYPTO_malloc(int num, const char *file, int line)
        if (malloc_debug_func != NULL)
                malloc_debug_func(ret, num, file, line, 1);
 
+#ifndef OPENSSL_CPUID_OBJ
         /* Create a dependency on the value of 'cleanse_ctr' so our memory
          * sanitisation function can't be optimised out. NB: We only do
          * this for >2Kb so the overhead doesn't bother us. */
         if(ret && (num > 2048))
+       {       extern unsigned char cleanse_ctr;
                 ((unsigned char *)ret)[0] = cleanse_ctr;
+       }
+#endif
+
+       return ret;
+       }
+char *CRYPTO_strdup(const char *str, const char *file, int line)
+       {
+       char *ret = CRYPTO_malloc(strlen(str)+1, file, line);
 
+       strcpy(ret, str);
        return ret;
        }
 
@@ -423,24 +412,3 @@ long CRYPTO_get_mem_debug_options(void)
                return get_debug_options_func();
        return 0;
        }
-
-int CRYPTO_push_info_(const char *info, const char *file, int line)
-       {
-       if (push_info_func)
-               return push_info_func(info, file, line);
-       return 1;
-       }
-
-int CRYPTO_pop_info(void)
-       {
-       if (pop_info_func)
-               return pop_info_func();
-       return 1;
-       }
-
-int CRYPTO_remove_all_info(void)
-       {
-       if (remove_all_info_func)
-               return remove_all_info_func();
-       return 1;
-       }
index dfeb084..ac79339 100644 (file)
  * copied and put under another distribution licence
  * [including the GNU Public Licence.]
  */
+/* ====================================================================
+ * Copyright (c) 1998-2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    openssl-core@openssl.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -81,8 +134,11 @@ static int mh_mode=CRYPTO_MEM_CHECK_OFF;
  */
 
 static unsigned long order = 0; /* number of memory requests */
-static LHASH *mh=NULL; /* hash-table of memory requests (address as key);
-                        * access requires MALLOC2 lock */
+
+DECLARE_LHASH_OF(MEM);
+static LHASH_OF(MEM) *mh=NULL; /* hash-table of memory requests
+                               * (address as key); access requires
+                               * MALLOC2 lock */
 
 
 typedef struct app_mem_info_st
@@ -93,8 +149,8 @@ typedef struct app_mem_info_st
  *   CRYPTO_pop_info()           to pop an entry,
  *   CRYPTO_remove_all_info()    to pop all entries.
  */
-       {       
-       unsigned long thread;
+       {
+       CRYPTO_THREADID threadid;
        const char *file;
        int line;
        const char *info;
@@ -104,10 +160,13 @@ typedef struct app_mem_info_st
 
 static void app_info_free(APP_INFO *);
 
-static LHASH *amih=NULL; /* hash-table with those app_mem_info_st's
-                          * that are at the top of their thread's stack
-                          * (with `thread' as key);
-                          * access requires MALLOC2 lock */
+DECLARE_LHASH_OF(APP_INFO);
+static LHASH_OF(APP_INFO) *amih=NULL; /* hash-table with those
+                                      * app_mem_info_st's that are at
+                                      * the top of their thread's
+                                      * stack (with `thread' as key);
+                                      * access requires MALLOC2
+                                      * lock */
 
 typedef struct mem_st
 /* memory-block description */
@@ -116,7 +175,7 @@ typedef struct mem_st
        int num;
        const char *file;
        int line;
-       unsigned long thread;
+       CRYPTO_THREADID threadid;
        unsigned long order;
        time_t time;
        APP_INFO *app_info;
@@ -136,11 +195,11 @@ static unsigned int num_disable = 0; /* num_disable > 0
                                       *     iff
                                       * mh_mode == CRYPTO_MEM_CHECK_ON (w/o ..._ENABLE)
                                       */
-static unsigned long disabling_thread = 0; /* Valid iff num_disable > 0.
-                                            * CRYPTO_LOCK_MALLOC2 is locked
-                                            * exactly in this case (by the
-                                            * thread named in disabling_thread).
-                                            */
+
+/* Valid iff num_disable > 0.  CRYPTO_LOCK_MALLOC2 is locked exactly in this
+ * case (by the thread named in disabling_thread).
+ */
+static CRYPTO_THREADID disabling_threadid;
 
 static void app_info_free(APP_INFO *inf)
        {
@@ -177,7 +236,9 @@ int CRYPTO_mem_ctrl(int mode)
        case CRYPTO_MEM_CHECK_DISABLE: /* aka MemCheck_off() */
                if (mh_mode & CRYPTO_MEM_CHECK_ON)
                        {
-                       if (!num_disable || (disabling_thread != CRYPTO_thread_id())) /* otherwise we already have the MALLOC2 lock */
+                       CRYPTO_THREADID cur;
+                       CRYPTO_THREADID_current(&cur);
+                       if (!num_disable || CRYPTO_THREADID_cmp(&disabling_threadid, &cur)) /* otherwise we already have the MALLOC2 lock */
                                {
                                /* Long-time lock CRYPTO_LOCK_MALLOC2 must not be claimed while
                                 * we're holding CRYPTO_LOCK_MALLOC, or we'll deadlock if
@@ -195,7 +256,7 @@ int CRYPTO_mem_ctrl(int mode)
                                CRYPTO_w_lock(CRYPTO_LOCK_MALLOC2);
                                CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
                                mh_mode &= ~CRYPTO_MEM_CHECK_ENABLE;
-                               disabling_thread=CRYPTO_thread_id();
+                               CRYPTO_THREADID_cpy(&disabling_threadid, &cur);
                                }
                        num_disable++;
                        }
@@ -228,10 +289,12 @@ int CRYPTO_is_mem_check_on(void)
 
        if (mh_mode & CRYPTO_MEM_CHECK_ON)
                {
+               CRYPTO_THREADID cur;
+               CRYPTO_THREADID_current(&cur);
                CRYPTO_r_lock(CRYPTO_LOCK_MALLOC);
 
                ret = (mh_mode & CRYPTO_MEM_CHECK_ENABLE)
-                       || (disabling_thread != CRYPTO_thread_id());
+                       || CRYPTO_THREADID_cmp(&disabling_threadid, &cur);
 
                CRYPTO_r_unlock(CRYPTO_LOCK_MALLOC);
                }
@@ -249,49 +312,49 @@ long CRYPTO_dbg_get_options(void)
        return options;
        }
 
-/* static int mem_cmp(MEM *a, MEM *b) */
-static int mem_cmp(const void *a_void, const void *b_void)
+static int mem_cmp(const MEM *a, const MEM *b)
        {
 #ifdef _WIN64
-       const char *a=(const char *)((const MEM *)a_void)->addr,
-                  *b=(const char *)((const MEM *)b_void)->addr;
-       if (a==b)       return 0;
-       else if (a>b)   return 1;
+       const char *ap=(const char *)a->addr,
+                  *bp=(const char *)b->addr;
+       if (ap==bp)     return 0;
+       else if (ap>bp) return 1;
        else            return -1;
 #else
-       return((const char *)((const MEM *)a_void)->addr
-               - (const char *)((const MEM *)b_void)->addr);
+       return (const char *)a->addr - (const char *)b->addr;
 #endif
        }
+static IMPLEMENT_LHASH_COMP_FN(mem, MEM)
 
-/* static unsigned long mem_hash(MEM *a) */
-static unsigned long mem_hash(const void *a_void)
+static unsigned long mem_hash(const MEM *a)
        {
        unsigned long ret;
 
-       ret=(unsigned long)((const MEM *)a_void)->addr;
+       ret=(unsigned long)a->addr;
 
        ret=ret*17851+(ret>>14)*7+(ret>>4)*251;
        return(ret);
        }
+static IMPLEMENT_LHASH_HASH_FN(mem, MEM)
 
 /* static int app_info_cmp(APP_INFO *a, APP_INFO *b) */
 static int app_info_cmp(const void *a_void, const void *b_void)
        {
-       return(((const APP_INFO *)a_void)->thread
-               != ((const APP_INFO *)b_void)->thread);
+       return CRYPTO_THREADID_cmp(&((const APP_INFO *)a_void)->threadid,
+                               &((const APP_INFO *)b_void)->threadid);
        }
+static IMPLEMENT_LHASH_COMP_FN(app_info, APP_INFO)
 
-/* static unsigned long app_info_hash(APP_INFO *a) */
-static unsigned long app_info_hash(const void *a_void)
+static unsigned long app_info_hash(const APP_INFO *a)
        {
        unsigned long ret;
 
-       ret=(unsigned long)((const APP_INFO *)a_void)->thread;
-
+       ret = CRYPTO_THREADID_hash(&a->threadid);
+       /* This is left in as a "who am I to question legacy?" measure */
        ret=ret*17851+(ret>>14)*7+(ret>>4)*251;
        return(ret);
        }
+static IMPLEMENT_LHASH_HASH_FN(app_info, APP_INFO)
 
 static APP_INFO *pop_info(void)
        {
@@ -300,21 +363,22 @@ static APP_INFO *pop_info(void)
 
        if (amih != NULL)
                {
-               tmp.thread=CRYPTO_thread_id();
-               if ((ret=(APP_INFO *)lh_delete(amih,&tmp)) != NULL)
+               CRYPTO_THREADID_current(&tmp.threadid);
+               if ((ret=lh_APP_INFO_delete(amih,&tmp)) != NULL)
                        {
                        APP_INFO *next=ret->next;
 
                        if (next != NULL)
                                {
                                next->references++;
-                               lh_insert(amih,(char *)next);
+                               (void)lh_APP_INFO_insert(amih,next);
                                }
 #ifdef LEVITTE_DEBUG_MEM
-                       if (ret->thread != tmp.thread)
+                       if (CRYPTO_THREADID_cmp(&ret->threadid, &tmp.threadid))
                                {
                                fprintf(stderr, "pop_info(): deleted info has other thread ID (%lu) than the current thread (%lu)!!!!\n",
-                                       ret->thread, tmp.thread);
+                                       CRYPTO_THREADID_hash(&ret->threadid),
+                                       CRYPTO_THREADID_hash(&tmp.threadid));
                                abort();
                                }
 #endif
@@ -330,7 +394,7 @@ static APP_INFO *pop_info(void)
        return(ret);
        }
 
-int CRYPTO_dbg_push_info(const char *info, const char *file, int line)
+int CRYPTO_push_info_(const char *info, const char *file, int line)
        {
        APP_INFO *ami, *amim;
        int ret=0;
@@ -346,7 +410,7 @@ int CRYPTO_dbg_push_info(const char *info, const char *file, int line)
                        }
                if (amih == NULL)
                        {
-                       if ((amih=lh_new(app_info_hash, app_info_cmp)) == NULL)
+                       if ((amih=lh_APP_INFO_new()) == NULL)
                                {
                                OPENSSL_free(ami);
                                ret=0;
@@ -354,20 +418,21 @@ int CRYPTO_dbg_push_info(const char *info, const char *file, int line)
                                }
                        }
 
-               ami->thread=CRYPTO_thread_id();
+               CRYPTO_THREADID_current(&ami->threadid);
                ami->file=file;
                ami->line=line;
                ami->info=info;
                ami->references=1;
                ami->next=NULL;
 
-               if ((amim=(APP_INFO *)lh_insert(amih,(char *)ami)) != NULL)
+               if ((amim=lh_APP_INFO_insert(amih,ami)) != NULL)
                        {
 #ifdef LEVITTE_DEBUG_MEM
-                       if (ami->thread != amim->thread)
+                       if (CRYPTO_THREADID_cmp(&ami->threadid, &amim->threadid))
                                {
                                fprintf(stderr, "CRYPTO_push_info(): previous info has other thread ID (%lu) than the current thread (%lu)!!!!\n",
-                                       amim->thread, ami->thread);
+                                       CRYPTO_THREADID_hash(&amim->threadid),
+                                       CRYPTO_THREADID_hash(&ami->threadid));
                                abort();
                                }
 #endif
@@ -380,7 +445,7 @@ int CRYPTO_dbg_push_info(const char *info, const char *file, int line)
        return(ret);
        }
 
-int CRYPTO_dbg_pop_info(void)
+int CRYPTO_pop_info(void)
        {
        int ret=0;
 
@@ -395,7 +460,7 @@ int CRYPTO_dbg_pop_info(void)
        return(ret);
        }
 
-int CRYPTO_dbg_remove_all_info(void)
+int CRYPTO_remove_all_info(void)
        {
        int ret=0;
 
@@ -439,7 +504,7 @@ void CRYPTO_dbg_malloc(void *addr, int num, const char *file, int line,
                                }
                        if (mh == NULL)
                                {
-                               if ((mh=lh_new(mem_hash, mem_cmp)) == NULL)
+                               if ((mh=lh_MEM_new()) == NULL)
                                        {
                                        OPENSSL_free(addr);
                                        OPENSSL_free(m);
@@ -453,9 +518,9 @@ void CRYPTO_dbg_malloc(void *addr, int num, const char *file, int line,
                        m->line=line;
                        m->num=num;
                        if (options & V_CRYPTO_MDEBUG_THREAD)
-                               m->thread=CRYPTO_thread_id();
+                               CRYPTO_THREADID_current(&m->threadid);
                        else
-                               m->thread=0;
+                               memset(&m->threadid, 0, sizeof(m->threadid));
 
                        if (order == break_order_num)
                                {
@@ -464,7 +529,7 @@ void CRYPTO_dbg_malloc(void *addr, int num, const char *file, int line,
                                }
                        m->order=order++;
 #ifdef LEVITTE_DEBUG_MEM
-                       fprintf(stderr, "LEVITTE_DEBUG_MEM: [%5d] %c 0x%p (%d)\n",
+                       fprintf(stderr, "LEVITTE_DEBUG_MEM: [%5ld] %c 0x%p (%d)\n",
                                m->order,
                                (before_p & 128) ? '*' : '+',
                                m->addr, m->num);
@@ -474,16 +539,16 @@ void CRYPTO_dbg_malloc(void *addr, int num, const char *file, int line,
                        else
                                m->time=0;
 
-                       tmp.thread=CRYPTO_thread_id();
+                       CRYPTO_THREADID_current(&tmp.threadid);
                        m->app_info=NULL;
                        if (amih != NULL
-                               && (amim=(APP_INFO *)lh_retrieve(amih,(char *)&tmp)) != NULL)
+                           && (amim=lh_APP_INFO_retrieve(amih,&tmp)) != NULL)
                                {
                                m->app_info = amim;
                                amim->references++;
                                }
 
-                       if ((mm=(MEM *)lh_insert(mh,(char *)m)) != NULL)
+                       if ((mm=lh_MEM_insert(mh, m)) != NULL)
                                {
                                /* Not good, but don't sweat it */
                                if (mm->app_info != NULL)
@@ -516,11 +581,11 @@ void CRYPTO_dbg_free(void *addr, int before_p)
                        MemCheck_off(); /* make sure we hold MALLOC2 lock */
 
                        m.addr=addr;
-                       mp=(MEM *)lh_delete(mh,(char *)&m);
+                       mp=lh_MEM_delete(mh,&m);
                        if (mp != NULL)
                                {
 #ifdef LEVITTE_DEBUG_MEM
-                       fprintf(stderr, "LEVITTE_DEBUG_MEM: [%5d] - 0x%p (%d)\n",
+                       fprintf(stderr, "LEVITTE_DEBUG_MEM: [%5ld] - 0x%p (%d)\n",
                                mp->order, mp->addr, mp->num);
 #endif
                                if (mp->app_info != NULL)
@@ -566,18 +631,18 @@ void CRYPTO_dbg_realloc(void *addr1, void *addr2, int num,
                        MemCheck_off(); /* make sure we hold MALLOC2 lock */
 
                        m.addr=addr1;
-                       mp=(MEM *)lh_delete(mh,(char *)&m);
+                       mp=lh_MEM_delete(mh,&m);
                        if (mp != NULL)
                                {
 #ifdef LEVITTE_DEBUG_MEM
-                               fprintf(stderr, "LEVITTE_DEBUG_MEM: [%5d] * 0x%p (%d) -> 0x%p (%d)\n",
+                               fprintf(stderr, "LEVITTE_DEBUG_MEM: [%5ld] * 0x%p (%d) -> 0x%p (%d)\n",
                                        mp->order,
                                        mp->addr, mp->num,
                                        addr2, num);
 #endif
                                mp->addr=addr2;
                                mp->num=num;
-                               lh_insert(mh,(char *)mp);
+                               (void)lh_MEM_insert(mh,mp);
                                }
 
                        MemCheck_on(); /* release MALLOC2 lock
@@ -596,14 +661,14 @@ typedef struct mem_leak_st
        long bytes;
        } MEM_LEAK;
 
-static void print_leak(const MEM *m, MEM_LEAK *l)
+static void print_leak_doall_arg(const MEM *m, MEM_LEAK *l)
        {
        char buf[1024];
        char *bufp = buf;
        APP_INFO *amip;
        int ami_cnt;
        struct tm *lcl = NULL;
-       unsigned long ti;
+       CRYPTO_THREADID ti;
 
 #define BUF_REMAIN (sizeof buf - (size_t)(bufp - buf))
 
@@ -625,7 +690,8 @@ static void print_leak(const MEM *m, MEM_LEAK *l)
 
        if (options & V_CRYPTO_MDEBUG_THREAD)
                {
-               BIO_snprintf(bufp, BUF_REMAIN, "thread=%lu, ", m->thread);
+               BIO_snprintf(bufp, BUF_REMAIN, "thread=%lu, ",
+                       CRYPTO_THREADID_hash(&m->threadid));
                bufp += strlen(bufp);
                }
 
@@ -642,8 +708,8 @@ static void print_leak(const MEM *m, MEM_LEAK *l)
        ami_cnt=0;
        if (!amip)
                return;
-       ti=amip->thread;
-       
+       CRYPTO_THREADID_cpy(&ti, &amip->threadid);
+
        do
                {
                int buf_len;
@@ -653,7 +719,8 @@ static void print_leak(const MEM *m, MEM_LEAK *l)
                memset(buf,'>',ami_cnt);
                BIO_snprintf(buf + ami_cnt, sizeof buf - ami_cnt,
                        " thread=%lu, file=%s, line=%d, info=\"",
-                       amip->thread, amip->file, amip->line);
+                       CRYPTO_THREADID_hash(&amip->threadid), amip->file,
+                       amip->line);
                buf_len=strlen(buf);
                info_len=strlen(amip->info);
                if (128 - buf_len - 3 < info_len)
@@ -673,8 +740,8 @@ static void print_leak(const MEM *m, MEM_LEAK *l)
 
                amip = amip->next;
                }
-       while(amip && amip->thread == ti);
-               
+       while(amip && !CRYPTO_THREADID_cmp(&amip->threadid, &ti));
+
 #ifdef LEVITTE_DEBUG_MEM
        if (amip)
                {
@@ -684,7 +751,7 @@ static void print_leak(const MEM *m, MEM_LEAK *l)
 #endif
        }
 
-static IMPLEMENT_LHASH_DOALL_ARG_FN(print_leak, const MEM *, MEM_LEAK *)
+static IMPLEMENT_LHASH_DOALL_ARG_FN(print_leak, const MEM, MEM_LEAK)
 
 void CRYPTO_mem_leaks(BIO *b)
        {
@@ -699,12 +766,15 @@ void CRYPTO_mem_leaks(BIO *b)
        ml.bytes=0;
        ml.chunks=0;
        if (mh != NULL)
-               lh_doall_arg(mh, LHASH_DOALL_ARG_FN(print_leak),
-                               (char *)&ml);
+               lh_MEM_doall_arg(mh, LHASH_DOALL_ARG_FN(print_leak), MEM_LEAK,
+                                &ml);
        if (ml.chunks != 0)
                {
                BIO_printf(b,"%ld bytes leaked in %d chunks\n",
                           ml.bytes,ml.chunks);
+#ifdef CRYPTO_MDEBUG_ABORT
+               abort();
+#endif
                }
        else
                {
@@ -717,7 +787,7 @@ void CRYPTO_mem_leaks(BIO *b)
                 * XXX    This should be in CRYPTO_mem_leaks_cb,
                 * and CRYPTO_mem_leaks should be implemented by
                 * using CRYPTO_mem_leaks_cb.
-                * (Also their should be a variant of lh_doall_arg
+                * (Also there should be a variant of lh_doall_arg
                 * that takes a function pointer instead of a void *;
                 * this would obviate the ugly and illegal
                 * void_fn_to_char kludge in CRYPTO_mem_leaks_cb.
@@ -734,14 +804,14 @@ void CRYPTO_mem_leaks(BIO *b)
 
                if (mh != NULL)
                        {
-                       lh_free(mh);
+                       lh_MEM_free(mh);
                        mh = NULL;
                        }
                if (amih != NULL)
                        {
-                       if (lh_num_items(amih) == 0) 
+                       if (lh_APP_INFO_num_items(amih) == 0) 
                                {
-                               lh_free(amih);
+                               lh_APP_INFO_free(amih);
                                amih = NULL;
                                }
                        }
@@ -779,39 +849,26 @@ void CRYPTO_mem_leaks_fp(FILE *fp)
 /* NB: The prototypes have been typedef'd to CRYPTO_MEM_LEAK_CB inside crypto.h
  * If this code is restructured, remove the callback type if it is no longer
  * needed. -- Geoff Thorpe */
-static void cb_leak(const MEM *m, CRYPTO_MEM_LEAK_CB **cb)
+
+/* Can't pass CRYPTO_MEM_LEAK_CB directly to lh_MEM_doall_arg because it
+ * is a function pointer and conversion to void * is prohibited. Instead
+ * pass its address
+ */
+
+typedef CRYPTO_MEM_LEAK_CB *PCRYPTO_MEM_LEAK_CB;
+
+static void cb_leak_doall_arg(const MEM *m, PCRYPTO_MEM_LEAK_CB *cb)
        {
-       (**cb)(m->order,m->file,m->line,m->num,m->addr);
+       (*cb)(m->order,m->file,m->line,m->num,m->addr);
        }
 
-static IMPLEMENT_LHASH_DOALL_ARG_FN(cb_leak, const MEM *, CRYPTO_MEM_LEAK_CB **)
+static IMPLEMENT_LHASH_DOALL_ARG_FN(cb_leak, const MEM, PCRYPTO_MEM_LEAK_CB)
 
 void CRYPTO_mem_leaks_cb(CRYPTO_MEM_LEAK_CB *cb)
        {
        if (mh == NULL) return;
        CRYPTO_w_lock(CRYPTO_LOCK_MALLOC2);
-       lh_doall_arg(mh, LHASH_DOALL_ARG_FN(cb_leak), &cb);
+       lh_MEM_doall_arg(mh, LHASH_DOALL_ARG_FN(cb_leak), PCRYPTO_MEM_LEAK_CB,
+                        &cb);
        CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC2);
        }
-
-void CRYPTO_malloc_debug_init(void)
-       {
-       CRYPTO_set_mem_debug_functions(
-               CRYPTO_dbg_malloc,
-               CRYPTO_dbg_realloc,
-               CRYPTO_dbg_free,
-               CRYPTO_dbg_set_options,
-               CRYPTO_dbg_get_options);
-       CRYPTO_set_mem_info_functions(
-               CRYPTO_dbg_push_info,
-               CRYPTO_dbg_pop_info,
-               CRYPTO_dbg_remove_all_info);
-       }
-
-char *CRYPTO_strdup(const char *str, const char *file, int line)
-       {
-       char *ret = CRYPTO_malloc(strlen(str)+1, file, line);
-
-       strcpy(ret, str);
-       return ret;
-       }
diff --git a/deps/openssl/openssl/crypto/modes/Makefile b/deps/openssl/openssl/crypto/modes/Makefile
new file mode 100644 (file)
index 0000000..6c85861
--- /dev/null
@@ -0,0 +1,82 @@
+#
+# OpenSSL/crypto/modes/Makefile
+#
+
+DIR=   modes
+TOP=   ../..
+CC=    cc
+INCLUDES= -I.. -I$(TOP) -I../../include
+CFLAG=-g
+MAKEFILE=      Makefile
+AR=            ar r
+
+CFLAGS= $(INCLUDES) $(CFLAG)
+
+GENERAL=Makefile
+TEST=
+APPS=
+
+LIB=$(TOP)/libcrypto.a
+LIBSRC= cbc128.c ctr128.c cts128.c cfb128.c ofb128.c
+LIBOBJ= cbc128.o ctr128.o cts128.o cfb128.o ofb128.o
+
+SRC= $(LIBSRC)
+
+#EXHEADER= store.h str_compat.h
+EXHEADER= modes.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
+
+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.
+
+cbc128.o: cbc128.c modes.h
+cfb128.o: cfb128.c modes.h
+ctr128.o: ctr128.c modes.h
+cts128.o: cts128.c modes.h
+ofb128.o: modes.h ofb128.c
diff --git a/deps/openssl/openssl/crypto/modes/cbc128.c b/deps/openssl/openssl/crypto/modes/cbc128.c
new file mode 100644 (file)
index 0000000..8f8bd56
--- /dev/null
@@ -0,0 +1,206 @@
+/* ====================================================================
+ * Copyright (c) 2008 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    openssl-core@openssl.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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 "modes.h"
+#include <string.h>
+
+#ifndef MODES_DEBUG
+# ifndef NDEBUG
+#  define NDEBUG
+# endif
+#endif
+#include <assert.h>
+
+#define STRICT_ALIGNMENT 1
+#if defined(__i386) || defined(__i386__) || \
+    defined(__x86_64) || defined(__x86_64__) || \
+    defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64) || \
+    defined(__s390__) || defined(__s390x__)
+#  undef STRICT_ALIGNMENT
+#  define STRICT_ALIGNMENT 0
+#endif
+
+void CRYPTO_cbc128_encrypt(const unsigned char *in, unsigned char *out,
+                       size_t len, const void *key,
+                       unsigned char ivec[16], block128_f block)
+{
+       size_t n;
+       const unsigned char *iv = ivec;
+
+       assert(in && out && key && ivec);
+
+#if !defined(OPENSSL_SMALL_FOOTPRINT)
+       if (STRICT_ALIGNMENT &&
+           ((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0) {
+               while (len>=16) {
+                       for(n=0; n<16; ++n)
+                               out[n] = in[n] ^ iv[n];
+                       (*block)(out, out, key);
+                       iv = out;
+                       len -= 16;
+                       in  += 16;
+                       out += 16;
+               }
+       } else {
+               while (len>=16) {
+                       for(n=0; n<16; n+=sizeof(size_t))
+                               *(size_t*)(out+n) =
+                               *(size_t*)(in+n) ^ *(size_t*)(iv+n);
+                       (*block)(out, out, key);
+                       iv = out;
+                       len -= 16;
+                       in  += 16;
+                       out += 16;
+               }
+       }
+#endif
+       while (len) {
+               for(n=0; n<16 && n<len; ++n)
+                       out[n] = in[n] ^ iv[n];
+               for(; n<16; ++n)
+                       out[n] = iv[n];
+               (*block)(out, out, key);
+               iv = out;
+               if (len<=16) break;
+               len -= 16;
+               in  += 16;
+               out += 16;
+       }
+       memcpy(ivec,iv,16);
+}
+
+void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out,
+                       size_t len, const void *key,
+                       unsigned char ivec[16], block128_f block)
+{
+       size_t n;
+       union { size_t align; unsigned char c[16]; } tmp;
+
+       assert(in && out && key && ivec);
+
+#if !defined(OPENSSL_SMALL_FOOTPRINT)
+       if (in != out) {
+               const unsigned char *iv = ivec;
+
+               if (STRICT_ALIGNMENT &&
+                   ((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0) {
+                       while (len>=16) {
+                               (*block)(in, out, key);
+                               for(n=0; n<16; ++n)
+                                       out[n] ^= iv[n];
+                               iv = in;
+                               len -= 16;
+                               in  += 16;
+                               out += 16;
+                       }
+               }
+               else {
+                       while (len>=16) {
+                               (*block)(in, out, key);
+                               for(n=0; n<16; n+=sizeof(size_t))
+                                       *(size_t *)(out+n) ^= *(size_t *)(iv+n);
+                               iv = in;
+                               len -= 16;
+                               in  += 16;
+                               out += 16;
+                       }
+               }
+               memcpy(ivec,iv,16);
+       } else {
+               if (STRICT_ALIGNMENT &&
+                   ((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0) {
+                       unsigned char c;
+                       while (len>=16) {
+                               (*block)(in, tmp.c, key);
+                               for(n=0; n<16; ++n) {
+                                       c = in[n];
+                                       out[n] = tmp.c[n] ^ ivec[n];
+                                       ivec[n] = c;
+                               }
+                               len -= 16;
+                               in  += 16;
+                               out += 16;
+                       }
+               }
+               else {
+                       size_t c;
+                       while (len>=16) {
+                               (*block)(in, tmp.c, key);
+                               for(n=0; n<16; n+=sizeof(size_t)) {
+                                       c = *(size_t *)(in+n);
+                                       *(size_t *)(out+n) =
+                                       *(size_t *)(tmp.c+n) ^ *(size_t *)(ivec+n);
+                                       *(size_t *)(ivec+n) = c;
+                               }
+                               len -= 16;
+                               in  += 16;
+                               out += 16;
+                       }
+               }
+       }
+#endif
+       while (len) {
+               unsigned char c;
+               (*block)(in, tmp.c, key);
+               for(n=0; n<16 && n<len; ++n) {
+                       c = in[n];
+                       out[n] = tmp.c[n] ^ ivec[n];
+                       ivec[n] = c;
+               }
+               if (len<=16) {
+                       for (; n<16; ++n)
+                               ivec[n] = in[n];
+                       break;
+               }
+               len -= 16;
+               in  += 16;
+               out += 16;
+       }
+}
diff --git a/deps/openssl/openssl/crypto/modes/cfb128.c b/deps/openssl/openssl/crypto/modes/cfb128.c
new file mode 100644 (file)
index 0000000..e5938c6
--- /dev/null
@@ -0,0 +1,249 @@
+/* ====================================================================
+ * Copyright (c) 2008 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    openssl-core@openssl.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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 "modes.h"
+#include <string.h>
+
+#ifndef MODES_DEBUG
+# ifndef NDEBUG
+#  define NDEBUG
+# endif
+#endif
+#include <assert.h>
+
+#define STRICT_ALIGNMENT
+#if defined(__i386) || defined(__i386__) || \
+    defined(__x86_64) || defined(__x86_64__) || \
+    defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64) || \
+    defined(__s390__) || defined(__s390x__)
+#  undef STRICT_ALIGNMENT
+#endif
+
+/* The input and output encrypted as though 128bit cfb mode is being
+ * used.  The extra state information to record how much of the
+ * 128bit block we have used is contained in *num;
+ */
+void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out,
+                       size_t len, const void *key,
+                       unsigned char ivec[16], int *num,
+                       int enc, block128_f block)
+{
+    unsigned int n;
+    size_t l = 0;
+
+    assert(in && out && key && ivec && num);
+
+    n = *num;
+
+    if (enc) {
+#if !defined(OPENSSL_SMALL_FOOTPRINT)
+       if (16%sizeof(size_t) == 0) do {        /* always true actually */
+               while (n && len) {
+                       *(out++) = ivec[n] ^= *(in++);
+                       --len;
+                       n = (n+1) % 16;
+               }
+#if defined(STRICT_ALIGNMENT)
+               if (((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0)
+                       break;
+#endif
+               while (len>=16) {
+                       (*block)(ivec, ivec, key);
+                       for (; n<16; n+=sizeof(size_t)) {
+                               *(size_t*)(out+n) =
+                               *(size_t*)(ivec+n) ^= *(size_t*)(in+n);
+                       }
+                       len -= 16;
+                       out += 16;
+                       in  += 16;
+                       n = 0;
+               }
+               if (len) {
+                       (*block)(ivec, ivec, key);
+                       while (len--) {
+                               out[n] = ivec[n] ^= in[n];
+                               ++n;
+                       }
+               }
+               *num = n;
+               return;
+       } while (0);
+       /* the rest would be commonly eliminated by x86* compiler */
+#endif
+       while (l<len) {
+               if (n == 0) {
+                       (*block)(ivec, ivec, key);
+               }
+               out[l] = ivec[n] ^= in[l];
+               ++l;
+               n = (n+1) % 16;
+       }
+       *num = n;
+    } else {
+#if !defined(OPENSSL_SMALL_FOOTPRINT)
+       if (16%sizeof(size_t) == 0) do {        /* always true actually */
+               while (n && len) {
+                       unsigned char c;
+                       *(out++) = ivec[n] ^ (c = *(in++)); ivec[n] = c;
+                       --len;
+                       n = (n+1) % 16;
+               }
+#if defined(STRICT_ALIGNMENT)
+               if (((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0)
+                       break;
+#endif
+               while (len>=16) {
+                       (*block)(ivec, ivec, key);
+                       for (; n<16; n+=sizeof(size_t)) {
+                               size_t t = *(size_t*)(in+n);
+                               *(size_t*)(out+n) = *(size_t*)(ivec+n) ^ t;
+                               *(size_t*)(ivec+n) = t;
+                       }
+                       len -= 16;
+                       out += 16;
+                       in  += 16;
+                       n = 0;
+               }
+               if (len) {
+                       (*block)(ivec, ivec, key);
+                       while (len--) {
+                               unsigned char c;
+                               out[n] = ivec[n] ^ (c = in[n]); ivec[n] = c;
+                               ++n;
+                       }
+               }
+               *num = n;
+               return;
+       } while (0);
+       /* the rest would be commonly eliminated by x86* compiler */
+#endif
+       while (l<len) {
+               unsigned char c;
+               if (n == 0) {
+                       (*block)(ivec, ivec, key);
+               }
+               out[l] = ivec[n] ^ (c = in[l]); ivec[n] = c;
+               ++l;
+               n = (n+1) % 16;
+       }
+       *num=n;
+    }
+}
+
+/* This expects a single block of size nbits for both in and out. Note that
+   it corrupts any extra bits in the last byte of out */
+static void cfbr_encrypt_block(const unsigned char *in,unsigned char *out,
+                           int nbits,const void *key,
+                           unsigned char ivec[16],int enc,
+                           block128_f block)
+{
+    int n,rem,num;
+    unsigned char ovec[16*2 + 1];  /* +1 because we dererefence (but don't use) one byte off the end */
+
+    if (nbits<=0 || nbits>128) return;
+
+       /* fill in the first half of the new IV with the current IV */
+       memcpy(ovec,ivec,16);
+       /* construct the new IV */
+       (*block)(ivec,ivec,key);
+       num = (nbits+7)/8;
+       if (enc)        /* encrypt the input */
+           for(n=0 ; n < num ; ++n)
+               out[n] = (ovec[16+n] = in[n] ^ ivec[n]);
+       else            /* decrypt the input */
+           for(n=0 ; n < num ; ++n)
+               out[n] = (ovec[16+n] = in[n]) ^ ivec[n];
+       /* shift ovec left... */
+       rem = nbits%8;
+       num = nbits/8;
+       if(rem==0)
+           memcpy(ivec,ovec+num,16);
+       else
+           for(n=0 ; n < 16 ; ++n)
+               ivec[n] = ovec[n+num]<<rem | ovec[n+num+1]>>(8-rem);
+
+    /* it is not necessary to cleanse ovec, since the IV is not secret */
+}
+
+/* N.B. This expects the input to be packed, MS bit first */
+void CRYPTO_cfb128_1_encrypt(const unsigned char *in, unsigned char *out,
+                       size_t bits, const void *key,
+                       unsigned char ivec[16], int *num,
+                       int enc, block128_f block)
+{
+    size_t n;
+    unsigned char c[1],d[1];
+
+    assert(in && out && key && ivec && num);
+    assert(*num == 0);
+
+    for(n=0 ; n<bits ; ++n)
+       {
+       c[0]=(in[n/8]&(1 << (7-n%8))) ? 0x80 : 0;
+       cfbr_encrypt_block(c,d,1,key,ivec,enc,block);
+       out[n/8]=(out[n/8]&~(1 << (unsigned int)(7-n%8))) |
+                ((d[0]&0x80) >> (unsigned int)(n%8));
+       }
+}
+
+void CRYPTO_cfb128_8_encrypt(const unsigned char *in, unsigned char *out,
+                       size_t length, const void *key,
+                       unsigned char ivec[16], int *num,
+                       int enc, block128_f block)
+{
+    size_t n;
+
+    assert(in && out && key && ivec && num);
+    assert(*num == 0);
+
+    for(n=0 ; n<length ; ++n)
+       cfbr_encrypt_block(&in[n],&out[n],8,key,ivec,enc,block);
+}
+
diff --git a/deps/openssl/openssl/crypto/modes/ctr128.c b/deps/openssl/openssl/crypto/modes/ctr128.c
new file mode 100644 (file)
index 0000000..932037f
--- /dev/null
@@ -0,0 +1,184 @@
+/* ====================================================================
+ * Copyright (c) 2008 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    openssl-core@openssl.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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 "modes.h"
+#include <string.h>
+
+#ifndef MODES_DEBUG
+# ifndef NDEBUG
+#  define NDEBUG
+# endif
+#endif
+#include <assert.h>
+
+typedef unsigned int u32;
+typedef unsigned char u8;
+
+#define STRICT_ALIGNMENT
+#if defined(__i386)    || defined(__i386__)    || \
+    defined(__x86_64)  || defined(__x86_64__)  || \
+    defined(_M_IX86)   || defined(_M_AMD64)    || defined(_M_X64) || \
+    defined(__s390__)  || defined(__s390x__)
+#  undef STRICT_ALIGNMENT
+#endif
+
+/* NOTE: the IV/counter CTR mode is big-endian.  The code itself
+ * is endian-neutral. */
+
+/* increment counter (128-bit int) by 1 */
+static void ctr128_inc(unsigned char *counter) {
+       u32 n=16;
+       u8  c;
+
+       do {
+               --n;
+               c = counter[n];
+               ++c;
+               counter[n] = c;
+               if (c) return;
+       } while (n);
+}
+
+#if !defined(OPENSSL_SMALL_FOOTPRINT)
+static void ctr128_inc_aligned(unsigned char *counter) {
+       size_t *data,c,n;
+       const union { long one; char little; } is_endian = {1};
+
+       if (is_endian.little) {
+               ctr128_inc(counter);
+               return;
+       }
+
+       data = (size_t *)counter;
+       n = 16/sizeof(size_t);
+       do {
+               --n;
+               c = data[n];
+               ++c;
+               data[n] = c;
+               if (c) return;
+       } while (n);
+}
+#endif
+
+/* The input encrypted as though 128bit counter mode is being
+ * used.  The extra state information to record how much of the
+ * 128bit block we have used is contained in *num, and the
+ * encrypted counter is kept in ecount_buf.  Both *num and
+ * ecount_buf must be initialised with zeros before the first
+ * call to CRYPTO_ctr128_encrypt().
+ *
+ * This algorithm assumes that the counter is in the x lower bits
+ * of the IV (ivec), and that the application has full control over
+ * overflow and the rest of the IV.  This implementation takes NO
+ * responsability for checking that the counter doesn't overflow
+ * into the rest of the IV when incremented.
+ */
+void CRYPTO_ctr128_encrypt(const unsigned char *in, unsigned char *out,
+                       size_t len, const void *key,
+                       unsigned char ivec[16], unsigned char ecount_buf[16],
+                       unsigned int *num, block128_f block)
+{
+       unsigned int n;
+       size_t l=0;
+
+       assert(in && out && key && ecount_buf && num);
+       assert(*num < 16);
+
+       n = *num;
+
+#if !defined(OPENSSL_SMALL_FOOTPRINT)
+       if (16%sizeof(size_t) == 0) do { /* always true actually */
+               while (n && len) {
+                       *(out++) = *(in++) ^ ecount_buf[n];
+                       --len;
+                       n = (n+1) % 16;
+               }
+
+#if defined(STRICT_ALIGNMENT)
+               if (((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0)
+                       break;
+#endif
+               while (len>=16) {
+                       (*block)(ivec, ecount_buf, key);
+                       ctr128_inc_aligned(ivec);
+                       for (; n<16; n+=sizeof(size_t))
+                               *(size_t *)(out+n) =
+                               *(size_t *)(in+n) ^ *(size_t *)(ecount_buf+n);
+                       len -= 16;
+                       out += 16;
+                       in  += 16;
+                       n = 0;
+               }
+               if (len) {
+                       (*block)(ivec, ecount_buf, key);
+                       ctr128_inc_aligned(ivec);
+                       while (len--) {
+                               out[n] = in[n] ^ ecount_buf[n];
+                               ++n;
+                       }
+               }
+               *num = n;
+               return;
+       } while(0);
+       /* the rest would be commonly eliminated by x86* compiler */
+#endif
+       while (l<len) {
+               if (n==0) {
+                       (*block)(ivec, ecount_buf, key);
+                       ctr128_inc(ivec);
+               }
+               out[l] = in[l] ^ ecount_buf[n];
+               ++l;
+               n = (n+1) % 16;
+       }
+
+       *num=n;
+}
diff --git a/deps/openssl/openssl/crypto/modes/cts128.c b/deps/openssl/openssl/crypto/modes/cts128.c
new file mode 100644 (file)
index 0000000..e0430f9
--- /dev/null
@@ -0,0 +1,259 @@
+/* ====================================================================
+ * Copyright (c) 2008 The OpenSSL Project. All rights reserved.
+ *
+ * Rights for redistribution and usage in source and binary
+ * forms are granted according to the OpenSSL license.
+ */
+
+#include "modes.h"
+#include <string.h>
+
+#ifndef MODES_DEBUG
+# ifndef NDEBUG
+#  define NDEBUG
+# endif
+#endif
+#include <assert.h>
+
+/*
+ * Trouble with Ciphertext Stealing, CTS, mode is that there is no
+ * common official specification, but couple of cipher/application
+ * specific ones: RFC2040 and RFC3962. Then there is 'Proposal to
+ * Extend CBC Mode By "Ciphertext Stealing"' at NIST site, which
+ * deviates from mentioned RFCs. Most notably it allows input to be
+ * of block length and it doesn't flip the order of the last two
+ * blocks. CTS is being discussed even in ECB context, but it's not
+ * adopted for any known application. This implementation complies
+ * with mentioned RFCs and [as such] extends CBC mode.
+ */
+
+size_t CRYPTO_cts128_encrypt_block(const unsigned char *in, unsigned char *out,
+                       size_t len, const void *key,
+                       unsigned char ivec[16], block128_f block)
+{      size_t residue, n;
+
+       assert (in && out && key && ivec);
+
+       if (len <= 16) return 0;
+
+       if ((residue=len%16) == 0) residue = 16;
+
+       len -= residue;
+
+       CRYPTO_cbc128_encrypt(in,out,len,key,ivec,block);
+
+       in  += len;
+       out += len;
+
+       for (n=0; n<residue; ++n)
+               ivec[n] ^= in[n];
+       (*block)(ivec,ivec,key);
+       memcpy(out,out-16,residue);
+       memcpy(out-16,ivec,16); 
+
+       return len+residue;
+}
+
+size_t CRYPTO_cts128_encrypt(const unsigned char *in, unsigned char *out,
+                       size_t len, const void *key,
+                       unsigned char ivec[16], cbc128_f cbc)
+{      size_t residue;
+       union { size_t align; unsigned char c[16]; } tmp;
+
+       assert (in && out && key && ivec);
+
+       if (len <= 16) return 0;
+
+       if ((residue=len%16) == 0) residue = 16;
+
+       len -= residue;
+
+       (*cbc)(in,out,len,key,ivec,1);
+
+       in  += len;
+       out += len;
+
+#if defined(CBC_HANDLES_TRUNCATED_IO)
+       memcpy(tmp.c,out-16,16);
+       (*cbc)(in,out-16,residue,key,ivec,1);
+       memcpy(out,tmp.c,residue);
+#else
+       {
+       size_t n;
+       for (n=0; n<16; n+=sizeof(size_t))
+               *(size_t *)(tmp.c+n) = 0;
+       memcpy(tmp.c,in,residue);
+       }
+       memcpy(out,out-16,residue);
+       (*cbc)(tmp.c,out-16,16,key,ivec,1);
+#endif
+       return len+residue;
+}
+
+size_t CRYPTO_cts128_decrypt_block(const unsigned char *in, unsigned char *out,
+                       size_t len, const void *key,
+                       unsigned char ivec[16], block128_f block)
+{      size_t residue, n;
+       union { size_t align; unsigned char c[32]; } tmp;
+
+       assert (in && out && key && ivec);
+
+       if (len<=16) return 0;
+
+       if ((residue=len%16) == 0) residue = 16;
+
+       len -= 16+residue;
+
+       if (len) {
+               CRYPTO_cbc128_decrypt(in,out,len,key,ivec,block);
+               in  += len;
+               out += len;
+       }
+
+       (*block)(in,tmp.c+16,key);
+
+       for (n=0; n<16; n+=sizeof(size_t))
+               *(size_t *)(tmp.c+n) = *(size_t *)(tmp.c+16+n);
+       memcpy(tmp.c,in+16,residue);
+       (*block)(tmp.c,tmp.c,key);
+
+       for(n=0; n<16; ++n) {
+               unsigned char c = in[n];
+               out[n] = tmp.c[n] ^ ivec[n];
+               ivec[n] = c;
+       }
+       for(residue+=16; n<residue; ++n)
+               out[n] = tmp.c[n] ^ in[n];
+
+       return len+residue-16;
+}
+
+size_t CRYPTO_cts128_decrypt(const unsigned char *in, unsigned char *out,
+                       size_t len, const void *key,
+                       unsigned char ivec[16], cbc128_f cbc)
+{      size_t residue, n;
+       union { size_t align; unsigned char c[32]; } tmp;
+
+       assert (in && out && key && ivec);
+
+       if (len<=16) return 0;
+
+       if ((residue=len%16) == 0) residue = 16;
+
+       len -= 16+residue;
+
+       if (len) {
+               (*cbc)(in,out,len,key,ivec,0);
+               in  += len;
+               out += len;
+       }
+
+       for (n=16; n<32; n+=sizeof(size_t))
+               *(size_t *)(tmp.c+n) = 0;
+       /* this places in[16] at &tmp.c[16] and decrypted block at &tmp.c[0] */
+       (*cbc)(in,tmp.c,16,key,tmp.c+16,0);
+
+       memcpy(tmp.c,in+16,residue);
+#if defined(CBC_HANDLES_TRUNCATED_IO)
+       (*cbc)(tmp.c,out,16+residue,key,ivec,0);
+#else
+       (*cbc)(tmp.c,tmp.c,32,key,ivec,0);
+       memcpy(out,tmp.c,16+residue);
+#endif
+       return len+residue;
+}
+
+#if defined(SELFTEST)
+#include <stdio.h>
+#include <openssl/aes.h>
+
+/* test vectors from RFC 3962 */
+static const unsigned char test_key[16] = "chicken teriyaki";
+static const unsigned char test_input[64] =
+               "I would like the" " General Gau's C"
+               "hicken, please, " "and wonton soup.";
+static const unsigned char test_iv[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+
+static const unsigned char vector_17[17] =
+{0xc6,0x35,0x35,0x68,0xf2,0xbf,0x8c,0xb4, 0xd8,0xa5,0x80,0x36,0x2d,0xa7,0xff,0x7f,
+ 0x97};
+static const unsigned char vector_31[31] =
+{0xfc,0x00,0x78,0x3e,0x0e,0xfd,0xb2,0xc1, 0xd4,0x45,0xd4,0xc8,0xef,0xf7,0xed,0x22,
+ 0x97,0x68,0x72,0x68,0xd6,0xec,0xcc,0xc0, 0xc0,0x7b,0x25,0xe2,0x5e,0xcf,0xe5};
+static const unsigned char vector_32[32] =
+{0x39,0x31,0x25,0x23,0xa7,0x86,0x62,0xd5, 0xbe,0x7f,0xcb,0xcc,0x98,0xeb,0xf5,0xa8,
+ 0x97,0x68,0x72,0x68,0xd6,0xec,0xcc,0xc0, 0xc0,0x7b,0x25,0xe2,0x5e,0xcf,0xe5,0x84};
+static const unsigned char vector_47[47] =
+{0x97,0x68,0x72,0x68,0xd6,0xec,0xcc,0xc0, 0xc0,0x7b,0x25,0xe2,0x5e,0xcf,0xe5,0x84,
+ 0xb3,0xff,0xfd,0x94,0x0c,0x16,0xa1,0x8c, 0x1b,0x55,0x49,0xd2,0xf8,0x38,0x02,0x9e,
+ 0x39,0x31,0x25,0x23,0xa7,0x86,0x62,0xd5, 0xbe,0x7f,0xcb,0xcc,0x98,0xeb,0xf5};
+static const unsigned char vector_48[48] =
+{0x97,0x68,0x72,0x68,0xd6,0xec,0xcc,0xc0, 0xc0,0x7b,0x25,0xe2,0x5e,0xcf,0xe5,0x84,
+ 0x9d,0xad,0x8b,0xbb,0x96,0xc4,0xcd,0xc0, 0x3b,0xc1,0x03,0xe1,0xa1,0x94,0xbb,0xd8,
+ 0x39,0x31,0x25,0x23,0xa7,0x86,0x62,0xd5, 0xbe,0x7f,0xcb,0xcc,0x98,0xeb,0xf5,0xa8};
+static const unsigned char vector_64[64] =
+{0x97,0x68,0x72,0x68,0xd6,0xec,0xcc,0xc0, 0xc0,0x7b,0x25,0xe2,0x5e,0xcf,0xe5,0x84,
+ 0x39,0x31,0x25,0x23,0xa7,0x86,0x62,0xd5, 0xbe,0x7f,0xcb,0xcc,0x98,0xeb,0xf5,0xa8,
+ 0x48,0x07,0xef,0xe8,0x36,0xee,0x89,0xa5, 0x26,0x73,0x0d,0xbc,0x2f,0x7b,0xc8,0x40,
+ 0x9d,0xad,0x8b,0xbb,0x96,0xc4,0xcd,0xc0, 0x3b,0xc1,0x03,0xe1,0xa1,0x94,0xbb,0xd8};
+
+static AES_KEY encks, decks;
+
+void test_vector(const unsigned char *vector,size_t len)
+{      unsigned char cleartext[64];
+       unsigned char iv[sizeof(test_iv)];
+       unsigned char ciphertext[64];
+       size_t tail;
+
+       printf("vector_%d\n",len); fflush(stdout);
+
+       if ((tail=len%16) == 0) tail = 16;
+       tail += 16;
+
+       /* test block-based encryption */
+       memcpy(iv,test_iv,sizeof(test_iv));
+       CRYPTO_cts128_encrypt_block(test_input,ciphertext,len,&encks,iv,(block128_f)AES_encrypt);
+       if (memcmp(ciphertext,vector,len))
+               fprintf(stderr,"output_%d mismatch\n",len), exit(1);
+       if (memcmp(iv,vector+len-tail,sizeof(iv)))
+               fprintf(stderr,"iv_%d mismatch\n",len), exit(1);
+
+       /* test block-based decryption */
+       memcpy(iv,test_iv,sizeof(test_iv));
+       CRYPTO_cts128_decrypt_block(ciphertext,cleartext,len,&decks,iv,(block128_f)AES_decrypt);
+       if (memcmp(cleartext,test_input,len))
+               fprintf(stderr,"input_%d mismatch\n",len), exit(2);
+       if (memcmp(iv,vector+len-tail,sizeof(iv)))
+               fprintf(stderr,"iv_%d mismatch\n",len), exit(2);
+
+       /* test streamed encryption */
+       memcpy(iv,test_iv,sizeof(test_iv));
+       CRYPTO_cts128_encrypt(test_input,ciphertext,len,&encks,iv,(cbc128_f)AES_cbc_encrypt);
+       if (memcmp(ciphertext,vector,len))
+               fprintf(stderr,"output_%d mismatch\n",len), exit(3);
+       if (memcmp(iv,vector+len-tail,sizeof(iv)))
+               fprintf(stderr,"iv_%d mismatch\n",len), exit(3);
+
+       /* test streamed decryption */
+       memcpy(iv,test_iv,sizeof(test_iv));
+       CRYPTO_cts128_decrypt(ciphertext,cleartext,len,&decks,iv,(cbc128_f)AES_cbc_encrypt);
+       if (memcmp(cleartext,test_input,len))
+               fprintf(stderr,"input_%d mismatch\n",len), exit(4);
+       if (memcmp(iv,vector+len-tail,sizeof(iv)))
+               fprintf(stderr,"iv_%d mismatch\n",len), exit(4);
+}
+
+main()
+{
+       AES_set_encrypt_key(test_key,128,&encks);
+       AES_set_decrypt_key(test_key,128,&decks);
+
+       test_vector(vector_17,sizeof(vector_17));
+       test_vector(vector_31,sizeof(vector_31));
+       test_vector(vector_32,sizeof(vector_32));
+       test_vector(vector_47,sizeof(vector_47));
+       test_vector(vector_48,sizeof(vector_48));
+       test_vector(vector_64,sizeof(vector_64));
+       exit(0);
+}
+#endif
diff --git a/deps/openssl/openssl/crypto/modes/modes.h b/deps/openssl/openssl/crypto/modes/modes.h
new file mode 100644 (file)
index 0000000..af8d97d
--- /dev/null
@@ -0,0 +1,59 @@
+/* ====================================================================
+ * Copyright (c) 2008 The OpenSSL Project. All rights reserved.
+ *
+ * Rights for redistribution and usage in source and binary
+ * forms are granted according to the OpenSSL license.
+ */
+
+#include <stddef.h>
+
+typedef void (*block128_f)(const unsigned char in[16],
+                       unsigned char out[16],
+                       const void *key);
+
+typedef void (*cbc128_f)(const unsigned char *in, unsigned char *out,
+                       size_t len, const void *key,
+                       unsigned char ivec[16], int enc);
+
+void CRYPTO_cbc128_encrypt(const unsigned char *in, unsigned char *out,
+                       size_t len, const void *key,
+                       unsigned char ivec[16], block128_f block);
+void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out,
+                       size_t len, const void *key,
+                       unsigned char ivec[16], block128_f block);
+
+void CRYPTO_ctr128_encrypt(const unsigned char *in, unsigned char *out,
+                       size_t len, const void *key,
+                       unsigned char ivec[16], unsigned char ecount_buf[16],
+                       unsigned int *num, block128_f block);
+
+void CRYPTO_ofb128_encrypt(const unsigned char *in, unsigned char *out,
+                       size_t len, const void *key,
+                       unsigned char ivec[16], int *num,
+                       block128_f block);
+
+void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out,
+                       size_t len, const void *key,
+                       unsigned char ivec[16], int *num,
+                       int enc, block128_f block);
+void CRYPTO_cfb128_8_encrypt(const unsigned char *in, unsigned char *out,
+                       size_t length, const void *key,
+                       unsigned char ivec[16], int *num,
+                       int enc, block128_f block);
+void CRYPTO_cfb128_1_encrypt(const unsigned char *in, unsigned char *out,
+                       size_t bits, const void *key,
+                       unsigned char ivec[16], int *num,
+                       int enc, block128_f block);
+
+size_t CRYPTO_cts128_encrypt_block(const unsigned char *in, unsigned char *out,
+                       size_t len, const void *key,
+                       unsigned char ivec[16], block128_f block);
+size_t CRYPTO_cts128_encrypt(const unsigned char *in, unsigned char *out,
+                       size_t len, const void *key,
+                       unsigned char ivec[16], cbc128_f cbc);
+size_t CRYPTO_cts128_decrypt_block(const unsigned char *in, unsigned char *out,
+                       size_t len, const void *key,
+                       unsigned char ivec[16], block128_f block);
+size_t CRYPTO_cts128_decrypt(const unsigned char *in, unsigned char *out,
+                       size_t len, const void *key,
+                       unsigned char ivec[16], cbc128_f cbc);
similarity index 58%
rename from deps/openssl/openssl/crypto/o_init.c
rename to deps/openssl/openssl/crypto/modes/ofb128.c
index d767a90..c732e2e 100644 (file)
@@ -1,9 +1,5 @@
-/* o_init.c */
-/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
- * project.
- */
 /* ====================================================================
- * Copyright (c) 2007 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 2008 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * OF THE POSSIBILITY OF SUCH DAMAGE.
  * ====================================================================
  *
- * This product includes cryptographic software written by Eric Young
- * (eay@cryptsoft.com).  This product includes software written by Tim
- * Hudson (tjh@cryptsoft.com).
- *
  */
 
-#include <e_os.h>
-#include <openssl/err.h>
+#include "modes.h"
+#include <string.h>
 
-/* Internal only functions: only ever used here */
-#ifdef OPENSSL_FIPS
-extern void int_ERR_lib_init(void);
-# ifndef OPENSSL_NO_ENGINE
-extern void int_EVP_MD_init_engine_callbacks(void );
-extern void int_EVP_CIPHER_init_engine_callbacks(void );
-extern void int_RAND_init_engine_callbacks(void );
+#ifndef MODES_DEBUG
+# ifndef NDEBUG
+#  define NDEBUG
 # endif
 #endif
+#include <assert.h>
 
-/* Perform any essential OpenSSL initialization operations.
- * Currently only sets FIPS callbacks
+#define STRICT_ALIGNMENT
+#if defined(__i386) || defined(__i386__) || \
+    defined(__x86_64) || defined(__x86_64__) || \
+    defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64) || \
+    defined(__s390__) || defined(__s390x__)
+#  undef STRICT_ALIGNMENT
+#endif
+
+/* The input and output encrypted as though 128bit ofb mode is being
+ * used.  The extra state information to record how much of the
+ * 128bit block we have used is contained in *num;
  */
+void CRYPTO_ofb128_encrypt(const unsigned char *in, unsigned char *out,
+                       size_t len, const void *key,
+                       unsigned char ivec[16], int *num,
+                       block128_f block)
+{
+       unsigned int n;
+       size_t l=0;
 
-void OPENSSL_init(void)
-       {
-#ifdef OPENSSL_FIPS
-       static int done = 0;
-       if (!done)
-               {
-               int_ERR_lib_init();
-#ifdef CRYPTO_MDEBUG
-               CRYPTO_malloc_debug_init();
-#endif
-#ifndef OPENSSL_NO_ENGINE
-               int_EVP_MD_init_engine_callbacks();
-               int_EVP_CIPHER_init_engine_callbacks();
-               int_RAND_init_engine_callbacks();
+       assert(in && out && key && ivec && num);
+
+       n = *num;
+
+#if !defined(OPENSSL_SMALL_FOOTPRINT)
+       if (16%sizeof(size_t) == 0) do { /* always true actually */
+               while (n && len) {
+                       *(out++) = *(in++) ^ ivec[n];
+                       --len;
+                       n = (n+1) % 16;
+               }
+#if defined(STRICT_ALIGNMENT)
+               if (((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0)
+                       break;
 #endif
-               done = 1;
+               while (len>=16) {
+                       (*block)(ivec, ivec, key);
+                       for (; n<16; n+=sizeof(size_t))
+                               *(size_t*)(out+n) =
+                               *(size_t*)(in+n) ^ *(size_t*)(ivec+n);
+                       len -= 16;
+                       out += 16;
+                       in  += 16;
+                       n = 0;
                }
+               if (len) {
+                       (*block)(ivec, ivec, key);
+                       while (len--) {
+                               out[n] = in[n] ^ ivec[n];
+                               ++n;
+                       }
+               }
+               *num = n;
+               return;
+       } while(0);
+       /* the rest would be commonly eliminated by x86* compiler */
 #endif
+       while (l<len) {
+               if (n==0) {
+                       (*block)(ivec, ivec, key);
+               }
+               out[l] = in[l] ^ ivec[n];
+               ++l;
+               n = (n+1) % 16;
        }
-               
 
+       *num=n;
+}
index e29091d..9030fde 100644 (file)
@@ -2,6 +2,9 @@
 /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
  * project 2001.
  */
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project 2008.
+ */
 /* ====================================================================
  * Copyright (c) 2001 The OpenSSL Project.  All rights reserved.
  *
 #include "o_time.h"
 
 #ifdef OPENSSL_SYS_VMS
-# include <libdtdef.h>
-# include <lib$routines.h>
-# include <lnmdef.h>
-# include <starlet.h>
-# include <descrip.h>
-# include <stdlib.h>
+# if __CRTL_VER >= 70000000 && \
+     (defined _POSIX_C_SOURCE || !defined _ANSI_C_SOURCE)
+#  define VMS_GMTIME_OK
+# endif
+# ifndef VMS_GMTIME_OK
+#  include <libdtdef.h>
+#  include <lib$routines.h>
+#  include <lnmdef.h>
+#  include <starlet.h>
+#  include <descrip.h>
+#  include <stdlib.h>
+# endif /* ndef VMS_GMTIME_OK */
 #endif
 
 struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result)
        {
        struct tm *ts = NULL;
 
-#if defined(OPENSSL_THREADS) && !defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_SYS_OS2) && !defined(__CYGWIN32__) && (!defined(OPENSSL_SYS_VMS) || defined(gmtime_r)) && !defined(OPENSSL_SYS_MACOSX) && !defined(OPENSSL_SYS_SUNOS)
+#if defined(OPENSSL_THREADS) && !defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_SYS_OS2) && (!defined(OPENSSL_SYS_VMS) || defined(gmtime_r)) && !defined(OPENSSL_SYS_MACOSX) && !defined(OPENSSL_SYS_SUNOS)
        /* should return &data, but doesn't on some systems,
           so we don't even look at the return value */
        gmtime_r(timer,result);
        ts = result;
-#elif !defined(OPENSSL_SYS_VMS)
+#elif !defined(OPENSSL_SYS_VMS) || defined(VMS_GMTIME_OK)
        ts = gmtime(timer);
        if (ts == NULL)
                return NULL;
@@ -86,7 +95,7 @@ struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result)
        memcpy(result, ts, sizeof(struct tm));
        ts = result;
 #endif
-#ifdef OPENSSL_SYS_VMS
+#if defined( OPENSSL_SYS_VMS) && !defined( VMS_GMTIME_OK)
        if (ts == NULL)
                {
                static $DESCRIPTOR(tabnam,"LNM$DCL_LOGICAL");
@@ -214,4 +223,150 @@ struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result)
                }
 #endif
        return ts;
-       }       
+       }
+
+/* Take a tm structure and add an offset to it. This avoids any OS issues
+ * with restricted date types and overflows which cause the year 2038
+ * problem.
+ */
+
+#define SECS_PER_DAY (24 * 60 * 60)
+
+static long date_to_julian(int y, int m, int d);
+static void julian_to_date(long jd, int *y, int *m, int *d);
+
+int OPENSSL_gmtime_adj(struct tm *tm, int off_day, long offset_sec)
+       {
+       int offset_hms, offset_day;
+       long time_jd;
+       int time_year, time_month, time_day;
+       /* split offset into days and day seconds */
+       offset_day = offset_sec / SECS_PER_DAY;
+       /* Avoid sign issues with % operator */
+       offset_hms  = offset_sec - (offset_day * SECS_PER_DAY);
+       offset_day += off_day;
+       /* Add current time seconds to offset */
+       offset_hms += tm->tm_hour * 3600 + tm->tm_min * 60 + tm->tm_sec;
+       /* Adjust day seconds if overflow */
+       if (offset_hms >= SECS_PER_DAY)
+               {
+               offset_day++;
+               offset_hms -= SECS_PER_DAY;
+               }
+       else if (offset_hms < 0)
+               {
+               offset_day--;
+               offset_hms += SECS_PER_DAY;
+               }
+
+       /* Convert date of time structure into a Julian day number.
+        */
+
+       time_year = tm->tm_year + 1900;
+       time_month = tm->tm_mon + 1;
+       time_day = tm->tm_mday;
+
+       time_jd = date_to_julian(time_year, time_month, time_day);
+
+       /* Work out Julian day of new date */
+       time_jd += offset_day;
+
+       if (time_jd < 0)
+               return 0;
+
+       /* Convert Julian day back to date */
+
+       julian_to_date(time_jd, &time_year, &time_month, &time_day);
+
+       if (time_year < 1900 || time_year > 9999)
+               return 0;
+
+       /* Update tm structure */
+
+       tm->tm_year = time_year - 1900;
+       tm->tm_mon = time_month - 1;
+       tm->tm_mday = time_day;
+
+       tm->tm_hour = offset_hms / 3600;
+       tm->tm_min = (offset_hms / 60) % 60;
+       tm->tm_sec = offset_hms % 60;
+
+       return 1;
+               
+}
+
+/* Convert date to and from julian day
+ * Uses Fliegel & Van Flandern algorithm
+ */
+static long date_to_julian(int y, int m, int d)
+{
+       return (1461 * (y + 4800 + (m - 14) / 12)) / 4 +
+               (367 * (m - 2 - 12 * ((m - 14) / 12))) / 12 -
+               (3 * ((y + 4900 + (m - 14) / 12) / 100)) / 4 +
+               d - 32075;
+}
+
+static void julian_to_date(long jd, int *y, int *m, int *d)
+       {
+       long  L = jd + 68569;
+       long  n = (4 * L) / 146097;
+       long  i, j;
+
+       L = L - (146097 * n + 3) / 4;
+       i = (4000 * (L + 1)) / 1461001;
+       L = L - (1461 * i) / 4 + 31;
+       j = (80 * L) / 2447;
+       *d = L - (2447 * j) / 80;
+       L = j / 11;
+       *m = j + 2 - (12 * L);
+       *y = 100 * (n - 49) + i + L;
+       }
+
+#ifdef OPENSSL_TIME_TEST
+
+#include <stdio.h>
+
+/* Time checking test code. Check times are identical for a wide range of
+ * offsets. This should be run on a machine with 64 bit time_t or it will
+ * trigger the very errors the routines fix.
+ */
+
+int main(int argc, char **argv)
+       {
+       long offset;
+       for (offset = 0; offset < 1000000; offset++)
+               {
+               check_time(offset);
+               check_time(-offset);
+               check_time(offset * 1000);
+               check_time(-offset * 1000);
+               }
+       }
+
+int check_time(long offset)
+       {
+       struct tm tm1, tm2;
+       time_t t1, t2;
+       time(&t1);
+       t2 = t1 + offset;
+       OPENSSL_gmtime(&t2, &tm2);
+       OPENSSL_gmtime(&t1, &tm1);
+       OPENSSL_gmtime_adj(&tm1, 0, offset);
+       if ((tm1.tm_year == tm2.tm_year) &&
+           (tm1.tm_mon == tm2.tm_mon) &&
+           (tm1.tm_mday == tm2.tm_mday) &&
+           (tm1.tm_hour == tm2.tm_hour) &&
+           (tm1.tm_min == tm2.tm_min) &&
+           (tm1.tm_sec == tm2.tm_sec))
+               return 1;
+       fprintf(stderr, "TIME ERROR!!\n");
+       fprintf(stderr, "Time1: %d/%d/%d, %d:%02d:%02d\n",
+                       tm2.tm_mday, tm2.tm_mon + 1, tm2.tm_year + 1900,
+                       tm2.tm_hour, tm2.tm_min, tm2.tm_sec);
+       fprintf(stderr, "Time2: %d/%d/%d, %d:%02d:%02d\n",
+                       tm1.tm_mday, tm1.tm_mon + 1, tm1.tm_year + 1900,
+                       tm1.tm_hour, tm1.tm_min, tm1.tm_sec);
+       return 0;
+       }
+
+#endif
index e660446..e391da7 100644 (file)
@@ -62,5 +62,6 @@
 #include <time.h>
 
 struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result);
+int OPENSSL_gmtime_adj(struct tm *tm, int offset_day, long offset_sec);
 
 #endif
index 25e8b23..a8aedbd 100644 (file)
@@ -18,23 +18,23 @@ TEST=
 APPS=
 
 LIB=$(TOP)/libcrypto.a
-LIBSRC=        o_names.c obj_dat.c obj_lib.c obj_err.c
-LIBOBJ= o_names.o obj_dat.o obj_lib.o obj_err.o
+LIBSRC=        o_names.c obj_dat.c obj_lib.c obj_err.c obj_xref.c
+LIBOBJ= o_names.o obj_dat.o obj_lib.o obj_err.o obj_xref.o
 
 SRC= $(LIBSRC)
 
 EXHEADER= objects.h obj_mac.h
-HEADER=        $(EXHEADER) obj_dat.h
+HEADER=        $(EXHEADER) obj_dat.h obj_xref.h
 
 ALL=    $(GENERAL) $(SRC) $(HEADER)
 
 top:
        (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
 
-all:   obj_dat.h lib
+all:   obj_dat.h obj_xref.h lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -46,6 +46,10 @@ obj_mac.h: objects.pl objects.txt obj_mac.num
        $(PERL) objects.pl objects.txt obj_mac.num obj_mac.h
        @sleep 1; touch obj_mac.h; sleep 1
 
+obj_xref.h: objxref.pl obj_xref.txt obj_mac.num
+       $(PERL) objxref.pl obj_mac.num obj_xref.txt > obj_xref.h
+       @sleep 1; touch obj_xref.h; sleep 1
+
 files:
        $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
 
@@ -117,3 +121,10 @@ obj_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
 obj_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
 obj_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
 obj_lib.o: ../cryptlib.h obj_lib.c
+obj_xref.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
+obj_xref.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+obj_xref.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+obj_xref.o: ../../include/openssl/opensslconf.h
+obj_xref.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+obj_xref.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+obj_xref.o: ../../include/openssl/symhacks.h obj_xref.c obj_xref.h
index adb5731..84380a9 100644 (file)
@@ -22,7 +22,8 @@
 /* I use the ex_data stuff to manage the identifiers for the obj_name_types
  * that applications may define.  I only really use the free function field.
  */
-static LHASH *names_lh=NULL;
+DECLARE_LHASH_OF(OBJ_NAME);
+static LHASH_OF(OBJ_NAME) *names_lh=NULL;
 static int names_type_num=OBJ_NAME_TYPE_NUM;
 
 typedef struct name_funcs_st
@@ -46,11 +47,14 @@ static unsigned long obj_name_hash(const void *a_void);
 /* static int obj_name_cmp(OBJ_NAME *a,OBJ_NAME *b); */
 static int obj_name_cmp(const void *a_void,const void *b_void);
 
+static IMPLEMENT_LHASH_HASH_FN(obj_name, OBJ_NAME)
+static IMPLEMENT_LHASH_COMP_FN(obj_name, OBJ_NAME)
+
 int OBJ_NAME_init(void)
        {
        if (names_lh != NULL) return(1);
        MemCheck_off();
-       names_lh=lh_new(obj_name_hash, obj_name_cmp);
+       names_lh=lh_OBJ_NAME_new();
        MemCheck_on();
        return(names_lh != NULL);
        }
@@ -164,7 +168,7 @@ const char *OBJ_NAME_get(const char *name, int type)
 
        for (;;)
        {
-               ret=(OBJ_NAME *)lh_retrieve(names_lh,&on);
+               ret=lh_OBJ_NAME_retrieve(names_lh,&on);
                if (ret == NULL) return(NULL);
                if ((ret->alias) && !alias)
                        {
@@ -200,7 +204,7 @@ int OBJ_NAME_add(const char *name, int type, const char *data)
        onp->type=type;
        onp->data=data;
 
-       ret=(OBJ_NAME *)lh_insert(names_lh,onp);
+       ret=lh_OBJ_NAME_insert(names_lh,onp);
        if (ret != NULL)
                {
                /* free things */
@@ -217,7 +221,7 @@ int OBJ_NAME_add(const char *name, int type, const char *data)
                }
        else
                {
-               if (lh_error(names_lh))
+               if (lh_OBJ_NAME_error(names_lh))
                        {
                        /* ERROR */
                        return(0);
@@ -235,7 +239,7 @@ int OBJ_NAME_remove(const char *name, int type)
        type&= ~OBJ_NAME_ALIAS;
        on.name=name;
        on.type=type;
-       ret=(OBJ_NAME *)lh_delete(names_lh,&on);
+       ret=lh_OBJ_NAME_delete(names_lh,&on);
        if (ret != NULL)
                {
                /* free things */
@@ -262,13 +266,13 @@ struct doall
        void *arg;
        };
 
-static void do_all_fn(const OBJ_NAME *name,struct doall *d)
+static void do_all_fn_doall_arg(const OBJ_NAME *name,struct doall *d)
        {
        if(name->type == d->type)
                d->fn(name,d->arg);
        }
 
-static IMPLEMENT_LHASH_DOALL_ARG_FN(do_all_fn, const OBJ_NAME *, struct doall *)
+static IMPLEMENT_LHASH_DOALL_ARG_FN(do_all_fn, const OBJ_NAME, struct doall)
 
 void OBJ_NAME_do_all(int type,void (*fn)(const OBJ_NAME *,void *arg),void *arg)
        {
@@ -278,7 +282,8 @@ void OBJ_NAME_do_all(int type,void (*fn)(const OBJ_NAME *,void *arg),void *arg)
        d.fn=fn;
        d.arg=arg;
 
-       lh_doall_arg(names_lh,LHASH_DOALL_ARG_FN(do_all_fn),&d);
+       lh_OBJ_NAME_doall_arg(names_lh, LHASH_DOALL_ARG_FN(do_all_fn),
+                             struct doall, &d);
        }
 
 struct doall_sorted
@@ -313,7 +318,7 @@ void OBJ_NAME_do_all_sorted(int type,void (*fn)(const OBJ_NAME *,void *arg),
        int n;
 
        d.type=type;
-       d.names=OPENSSL_malloc(lh_num_items(names_lh)*sizeof *d.names);
+       d.names=OPENSSL_malloc(lh_OBJ_NAME_num_items(names_lh)*sizeof *d.names);
        d.n=0;
        OBJ_NAME_do_all(type,do_all_sorted_fn,&d);
 
@@ -327,18 +332,16 @@ void OBJ_NAME_do_all_sorted(int type,void (*fn)(const OBJ_NAME *,void *arg),
 
 static int free_type;
 
-static void names_lh_free(OBJ_NAME *onp)
-{
-       if(onp == NULL)
+static void names_lh_free_doall(OBJ_NAME *onp)
+       {
+       if (onp == NULL)
                return;
 
-       if ((free_type < 0) || (free_type == onp->type))
-               {
+       if (free_type < 0 || free_type == onp->type)
                OBJ_NAME_remove(onp->name,onp->type);
-               }
        }
 
-static IMPLEMENT_LHASH_DOALL_FN(names_lh_free, OBJ_NAME *)
+static IMPLEMENT_LHASH_DOALL_FN(names_lh_free, OBJ_NAME)
 
 static void name_funcs_free(NAME_FUNCS *ptr)
        {
@@ -352,18 +355,18 @@ void OBJ_NAME_cleanup(int type)
        if (names_lh == NULL) return;
 
        free_type=type;
-       down_load=names_lh->down_load;
-       names_lh->down_load=0;
+       down_load=lh_OBJ_NAME_down_load(names_lh);
+       lh_OBJ_NAME_down_load(names_lh)=0;
 
-       lh_doall(names_lh,LHASH_DOALL_FN(names_lh_free));
+       lh_OBJ_NAME_doall(names_lh,LHASH_DOALL_FN(names_lh_free));
        if (type < 0)
                {
-               lh_free(names_lh);
+               lh_OBJ_NAME_free(names_lh);
                sk_NAME_FUNCS_pop_free(name_funcs_stack,name_funcs_free);
                names_lh=NULL;
                name_funcs_stack = NULL;
                }
        else
-               names_lh->down_load=down_load;
+               lh_OBJ_NAME_down_load(names_lh)=down_load;
        }
 
index 760af16..8a342ba 100644 (file)
 #define NUM_SN 0
 #define NUM_LN 0
 #define NUM_OBJ 0
-static unsigned char lvalues[1];
-static ASN1_OBJECT nid_objs[1];
-static ASN1_OBJECT *sn_objs[1];
-static ASN1_OBJECT *ln_objs[1];
-static ASN1_OBJECT *obj_objs[1];
+static const unsigned char lvalues[1];
+static const ASN1_OBJECT nid_objs[1];
+static const unsigned int sn_objs[1];
+static const unsigned int ln_objs[1];
+static const unsigned int obj_objs[1];
 #endif
 
-static int sn_cmp(const void *a, const void *b);
-static int ln_cmp(const void *a, const void *b);
-static int obj_cmp(const void *a, const void *b);
+DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, sn);
+DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, ln);
+DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, obj);
+
 #define ADDED_DATA     0
 #define ADDED_SNAME    1
 #define ADDED_LNAME    2
@@ -94,30 +95,27 @@ typedef struct added_obj_st
        int type;
        ASN1_OBJECT *obj;
        } ADDED_OBJ;
+DECLARE_LHASH_OF(ADDED_OBJ);
 
 static int new_nid=NUM_NID;
-static LHASH *added=NULL;
+static LHASH_OF(ADDED_OBJ) *added=NULL;
 
-static int sn_cmp(const void *a, const void *b)
-       {
-       const ASN1_OBJECT * const *ap = a, * const *bp = b;
-       return(strcmp((*ap)->sn,(*bp)->sn));
-       }
+static int sn_cmp(const ASN1_OBJECT * const *a, const unsigned int *b)
+       { return(strcmp((*a)->sn,nid_objs[*b].sn)); }
 
-static int ln_cmp(const void *a, const void *b)
-       { 
-       const ASN1_OBJECT * const *ap = a, * const *bp = b;
-       return(strcmp((*ap)->ln,(*bp)->ln));
-       }
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, sn);
 
-/* static unsigned long add_hash(ADDED_OBJ *ca) */
-static unsigned long add_hash(const void *ca_void)
+static int ln_cmp(const ASN1_OBJECT * const *a, const unsigned int *b)
+       { return(strcmp((*a)->ln,nid_objs[*b].ln)); }
+
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, ln);
+
+static unsigned long added_obj_hash(const ADDED_OBJ *ca)
        {
        const ASN1_OBJECT *a;
        int i;
        unsigned long ret=0;
        unsigned char *p;
-       const ADDED_OBJ *ca = (const ADDED_OBJ *)ca_void;
 
        a=ca->obj;
        switch (ca->type)
@@ -145,14 +143,12 @@ static unsigned long add_hash(const void *ca_void)
        ret|=ca->type<<30L;
        return(ret);
        }
+static IMPLEMENT_LHASH_HASH_FN(added_obj, ADDED_OBJ)
 
-/* static int add_cmp(ADDED_OBJ *ca, ADDED_OBJ *cb) */
-static int add_cmp(const void *ca_void, const void *cb_void)
+static int added_obj_cmp(const ADDED_OBJ *ca, const ADDED_OBJ *cb)
        {
        ASN1_OBJECT *a,*b;
        int i;
-       const ADDED_OBJ *ca = (const ADDED_OBJ *)ca_void;
-       const ADDED_OBJ *cb = (const ADDED_OBJ *)cb_void;
 
        i=ca->type-cb->type;
        if (i) return(i);
@@ -179,15 +175,16 @@ static int add_cmp(const void *ca_void, const void *cb_void)
                return 0;
                }
        }
+static IMPLEMENT_LHASH_COMP_FN(added_obj, ADDED_OBJ)
 
 static int init_added(void)
        {
        if (added != NULL) return(1);
-       added=lh_new(add_hash,add_cmp);
+       added=lh_ADDED_OBJ_new();
        return(added != NULL);
        }
 
-static void cleanup1(ADDED_OBJ *a)
+static void cleanup1_doall(ADDED_OBJ *a)
        {
        a->obj->nid=0;
        a->obj->flags|=ASN1_OBJECT_FLAG_DYNAMIC|
@@ -195,28 +192,46 @@ static void cleanup1(ADDED_OBJ *a)
                        ASN1_OBJECT_FLAG_DYNAMIC_DATA;
        }
 
-static void cleanup2(ADDED_OBJ *a)
+static void cleanup2_doall(ADDED_OBJ *a)
        { a->obj->nid++; }
 
-static void cleanup3(ADDED_OBJ *a)
+static void cleanup3_doall(ADDED_OBJ *a)
        {
        if (--a->obj->nid == 0)
                ASN1_OBJECT_free(a->obj);
        OPENSSL_free(a);
        }
 
-static IMPLEMENT_LHASH_DOALL_FN(cleanup1, ADDED_OBJ *)
-static IMPLEMENT_LHASH_DOALL_FN(cleanup2, ADDED_OBJ *)
-static IMPLEMENT_LHASH_DOALL_FN(cleanup3, ADDED_OBJ *)
+static IMPLEMENT_LHASH_DOALL_FN(cleanup1, ADDED_OBJ)
+static IMPLEMENT_LHASH_DOALL_FN(cleanup2, ADDED_OBJ)
+static IMPLEMENT_LHASH_DOALL_FN(cleanup3, ADDED_OBJ)
+
+/* The purpose of obj_cleanup_defer is to avoid EVP_cleanup() attempting
+ * to use freed up OIDs. If neccessary the actual freeing up of OIDs is
+ * delayed.
+ */
+
+int obj_cleanup_defer = 0;
+
+void check_defer(int nid)
+       {
+       if (!obj_cleanup_defer && nid >= NUM_NID)
+                       obj_cleanup_defer = 1;
+       }
 
 void OBJ_cleanup(void)
        {
+       if (obj_cleanup_defer)
+               {
+               obj_cleanup_defer = 2;
+               return ;
+               }
        if (added == NULL) return;
-       added->down_load=0;
-       lh_doall(added,LHASH_DOALL_FN(cleanup1)); /* zero counters */
-       lh_doall(added,LHASH_DOALL_FN(cleanup2)); /* set counters */
-       lh_doall(added,LHASH_DOALL_FN(cleanup3)); /* free objects */
-       lh_free(added);
+       lh_ADDED_OBJ_down_load(added) = 0;
+       lh_ADDED_OBJ_doall(added,LHASH_DOALL_FN(cleanup1)); /* zero counters */
+       lh_ADDED_OBJ_doall(added,LHASH_DOALL_FN(cleanup2)); /* set counters */
+       lh_ADDED_OBJ_doall(added,LHASH_DOALL_FN(cleanup3)); /* free objects */
+       lh_ADDED_OBJ_free(added);
        added=NULL;
        }
 
@@ -252,7 +267,7 @@ int OBJ_add_object(const ASN1_OBJECT *obj)
                        {
                        ao[i]->type=i;
                        ao[i]->obj=o;
-                       aop=(ADDED_OBJ *)lh_insert(added,ao[i]);
+                       aop=lh_ADDED_OBJ_insert(added,ao[i]);
                        /* memory leak, buit should not normally matter */
                        if (aop != NULL)
                                OPENSSL_free(aop);
@@ -292,7 +307,7 @@ ASN1_OBJECT *OBJ_nid2obj(int n)
                ad.type=ADDED_NID;
                ad.obj= &ob;
                ob.nid=n;
-               adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
+               adp=lh_ADDED_OBJ_retrieve(added,&ad);
                if (adp != NULL)
                        return(adp->obj);
                else
@@ -324,7 +339,7 @@ const char *OBJ_nid2sn(int n)
                ad.type=ADDED_NID;
                ad.obj= &ob;
                ob.nid=n;
-               adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
+               adp=lh_ADDED_OBJ_retrieve(added,&ad);
                if (adp != NULL)
                        return(adp->obj->sn);
                else
@@ -356,7 +371,7 @@ const char *OBJ_nid2ln(int n)
                ad.type=ADDED_NID;
                ad.obj= &ob;
                ob.nid=n;
-               adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
+               adp=lh_ADDED_OBJ_retrieve(added,&ad);
                if (adp != NULL)
                        return(adp->obj->ln);
                else
@@ -367,9 +382,22 @@ const char *OBJ_nid2ln(int n)
                }
        }
 
+static int obj_cmp(const ASN1_OBJECT * const *ap, const unsigned int *bp)
+       {
+       int j;
+       const ASN1_OBJECT *a= *ap;
+       const ASN1_OBJECT *b= &nid_objs[*bp];
+
+       j=(a->length - b->length);
+        if (j) return(j);
+       return(memcmp(a->data,b->data,a->length));
+       }
+
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, obj);
+
 int OBJ_obj2nid(const ASN1_OBJECT *a)
        {
-       ASN1_OBJECT **op;
+       const unsigned int *op;
        ADDED_OBJ ad,*adp;
 
        if (a == NULL)
@@ -381,14 +409,13 @@ int OBJ_obj2nid(const ASN1_OBJECT *a)
                {
                ad.type=ADDED_DATA;
                ad.obj=(ASN1_OBJECT *)a; /* XXX: ugly but harmless */
-               adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
+               adp=lh_ADDED_OBJ_retrieve(added,&ad);
                if (adp != NULL) return (adp->obj->nid);
                }
-       op=(ASN1_OBJECT **)OBJ_bsearch((const char *)&a,(const char *)obj_objs,
-               NUM_OBJ, sizeof(ASN1_OBJECT *),obj_cmp);
+       op=OBJ_bsearch_obj(&a, obj_objs, NUM_OBJ);
        if (op == NULL)
                return(NID_undef);
-       return((*op)->nid);
+       return(nid_objs[*op].nid);
        }
 
 /* Convert an object name into an ASN1_OBJECT
@@ -441,7 +468,7 @@ int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
        int i,n=0,len,nid, first, use_bn;
        BIGNUM *bl;
        unsigned long l;
-       unsigned char *p;
+       const unsigned char *p;
        char tbuf[DECIMAL_SIZE(i)+DECIMAL_SIZE(l)+2];
 
        if ((a == NULL) || (a->data == NULL)) {
@@ -610,62 +637,56 @@ int OBJ_txt2nid(const char *s)
 
 int OBJ_ln2nid(const char *s)
        {
-       ASN1_OBJECT o,*oo= &o,**op;
+       ASN1_OBJECT o;
+       const ASN1_OBJECT *oo= &o;
        ADDED_OBJ ad,*adp;
+       const unsigned int *op;
 
        o.ln=s;
        if (added != NULL)
                {
                ad.type=ADDED_LNAME;
                ad.obj= &o;
-               adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
+               adp=lh_ADDED_OBJ_retrieve(added,&ad);
                if (adp != NULL) return (adp->obj->nid);
                }
-       op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)ln_objs, NUM_LN,
-               sizeof(ASN1_OBJECT *),ln_cmp);
+       op=OBJ_bsearch_ln(&oo, ln_objs, NUM_LN);
        if (op == NULL) return(NID_undef);
-       return((*op)->nid);
+       return(nid_objs[*op].nid);
        }
 
 int OBJ_sn2nid(const char *s)
        {
-       ASN1_OBJECT o,*oo= &o,**op;
+       ASN1_OBJECT o;
+       const ASN1_OBJECT *oo= &o;
        ADDED_OBJ ad,*adp;
+       const unsigned int *op;
 
        o.sn=s;
        if (added != NULL)
                {
                ad.type=ADDED_SNAME;
                ad.obj= &o;
-               adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
+               adp=lh_ADDED_OBJ_retrieve(added,&ad);
                if (adp != NULL) return (adp->obj->nid);
                }
-       op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)sn_objs,NUM_SN,
-               sizeof(ASN1_OBJECT *),sn_cmp);
+       op=OBJ_bsearch_sn(&oo, sn_objs, NUM_SN);
        if (op == NULL) return(NID_undef);
-       return((*op)->nid);
+       return(nid_objs[*op].nid);
        }
 
-static int obj_cmp(const void *ap, const void *bp)
-       {
-       int j;
-       const ASN1_OBJECT *a= *(ASN1_OBJECT * const *)ap;
-       const ASN1_OBJECT *b= *(ASN1_OBJECT * const *)bp;
-
-       j=(a->length - b->length);
-        if (j) return(j);
-       return(memcmp(a->data,b->data,a->length));
-        }
-
-const char *OBJ_bsearch(const char *key, const char *base, int num, int size,
-       int (*cmp)(const void *, const void *))
+const void *OBJ_bsearch_(const void *key, const void *base, int num, int size,
+                        int (*cmp)(const void *, const void *))
        {
-       return OBJ_bsearch_ex(key, base, num, size, cmp, 0);
+       return OBJ_bsearch_ex_(key, base, num, size, cmp, 0);
        }
 
-const char *OBJ_bsearch_ex(const char *key, const char *base, int num,
-       int size, int (*cmp)(const void *, const void *), int flags)
+const void *OBJ_bsearch_ex_(const void *key, const void *base_, int num,
+                           int size,
+                           int (*cmp)(const void *, const void *),
+                           int flags)
        {
+       const char *base=base_;
        int l,h,i=0,c=0;
        const char *p = NULL;
 
index 23bdb46..6449be6 100644 (file)
@@ -67,7 +67,7 @@
 #define NUM_LN 886
 #define NUM_OBJ 840
 
-static unsigned char lvalues[5824]={
+static const unsigned char lvalues[5824]={
 0x00,                                        /* [  0] OBJ_undef */
 0x2A,0x86,0x48,0x86,0xF7,0x0D,               /* [  1] OBJ_rsadsi */
 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,          /* [  7] OBJ_pkcs */
@@ -910,7 +910,7 @@ static unsigned char lvalues[5824]={
 0x55,0x04,0x36,                              /* [5820] OBJ_dmdName */
 };
 
-static ASN1_OBJECT nid_objs[NUM_NID]={
+static const ASN1_OBJECT nid_objs[NUM_NID]={
 {"UNDEF","undefined",NID_undef,1,&(lvalues[0]),0},
 {"rsadsi","RSA Data Security, Inc.",NID_rsadsi,6,&(lvalues[1]),0},
 {"pkcs","RSA Data Security, Inc. PKCS",NID_pkcs,7,&(lvalues[7]),0},
@@ -2353,2624 +2353,2624 @@ static ASN1_OBJECT nid_objs[NUM_NID]={
 {"dmdName","dmdName",NID_dmdName,3,&(lvalues[5820]),0},
 };
 
-static ASN1_OBJECT *sn_objs[NUM_SN]={
-&(nid_objs[364]),/* "AD_DVCS" */
-&(nid_objs[419]),/* "AES-128-CBC" */
-&(nid_objs[421]),/* "AES-128-CFB" */
-&(nid_objs[650]),/* "AES-128-CFB1" */
-&(nid_objs[653]),/* "AES-128-CFB8" */
-&(nid_objs[418]),/* "AES-128-ECB" */
-&(nid_objs[420]),/* "AES-128-OFB" */
-&(nid_objs[423]),/* "AES-192-CBC" */
-&(nid_objs[425]),/* "AES-192-CFB" */
-&(nid_objs[651]),/* "AES-192-CFB1" */
-&(nid_objs[654]),/* "AES-192-CFB8" */
-&(nid_objs[422]),/* "AES-192-ECB" */
-&(nid_objs[424]),/* "AES-192-OFB" */
-&(nid_objs[427]),/* "AES-256-CBC" */
-&(nid_objs[429]),/* "AES-256-CFB" */
-&(nid_objs[652]),/* "AES-256-CFB1" */
-&(nid_objs[655]),/* "AES-256-CFB8" */
-&(nid_objs[426]),/* "AES-256-ECB" */
-&(nid_objs[428]),/* "AES-256-OFB" */
-&(nid_objs[91]),/* "BF-CBC" */
-&(nid_objs[93]),/* "BF-CFB" */
-&(nid_objs[92]),/* "BF-ECB" */
-&(nid_objs[94]),/* "BF-OFB" */
-&(nid_objs[14]),/* "C" */
-&(nid_objs[751]),/* "CAMELLIA-128-CBC" */
-&(nid_objs[757]),/* "CAMELLIA-128-CFB" */
-&(nid_objs[760]),/* "CAMELLIA-128-CFB1" */
-&(nid_objs[763]),/* "CAMELLIA-128-CFB8" */
-&(nid_objs[754]),/* "CAMELLIA-128-ECB" */
-&(nid_objs[766]),/* "CAMELLIA-128-OFB" */
-&(nid_objs[752]),/* "CAMELLIA-192-CBC" */
-&(nid_objs[758]),/* "CAMELLIA-192-CFB" */
-&(nid_objs[761]),/* "CAMELLIA-192-CFB1" */
-&(nid_objs[764]),/* "CAMELLIA-192-CFB8" */
-&(nid_objs[755]),/* "CAMELLIA-192-ECB" */
-&(nid_objs[767]),/* "CAMELLIA-192-OFB" */
-&(nid_objs[753]),/* "CAMELLIA-256-CBC" */
-&(nid_objs[759]),/* "CAMELLIA-256-CFB" */
-&(nid_objs[762]),/* "CAMELLIA-256-CFB1" */
-&(nid_objs[765]),/* "CAMELLIA-256-CFB8" */
-&(nid_objs[756]),/* "CAMELLIA-256-ECB" */
-&(nid_objs[768]),/* "CAMELLIA-256-OFB" */
-&(nid_objs[108]),/* "CAST5-CBC" */
-&(nid_objs[110]),/* "CAST5-CFB" */
-&(nid_objs[109]),/* "CAST5-ECB" */
-&(nid_objs[111]),/* "CAST5-OFB" */
-&(nid_objs[13]),/* "CN" */
-&(nid_objs[141]),/* "CRLReason" */
-&(nid_objs[417]),/* "CSPName" */
-&(nid_objs[367]),/* "CrlID" */
-&(nid_objs[391]),/* "DC" */
-&(nid_objs[31]),/* "DES-CBC" */
-&(nid_objs[643]),/* "DES-CDMF" */
-&(nid_objs[30]),/* "DES-CFB" */
-&(nid_objs[656]),/* "DES-CFB1" */
-&(nid_objs[657]),/* "DES-CFB8" */
-&(nid_objs[29]),/* "DES-ECB" */
-&(nid_objs[32]),/* "DES-EDE" */
-&(nid_objs[43]),/* "DES-EDE-CBC" */
-&(nid_objs[60]),/* "DES-EDE-CFB" */
-&(nid_objs[62]),/* "DES-EDE-OFB" */
-&(nid_objs[33]),/* "DES-EDE3" */
-&(nid_objs[44]),/* "DES-EDE3-CBC" */
-&(nid_objs[61]),/* "DES-EDE3-CFB" */
-&(nid_objs[658]),/* "DES-EDE3-CFB1" */
-&(nid_objs[659]),/* "DES-EDE3-CFB8" */
-&(nid_objs[63]),/* "DES-EDE3-OFB" */
-&(nid_objs[45]),/* "DES-OFB" */
-&(nid_objs[80]),/* "DESX-CBC" */
-&(nid_objs[380]),/* "DOD" */
-&(nid_objs[116]),/* "DSA" */
-&(nid_objs[66]),/* "DSA-SHA" */
-&(nid_objs[113]),/* "DSA-SHA1" */
-&(nid_objs[70]),/* "DSA-SHA1-old" */
-&(nid_objs[67]),/* "DSA-old" */
-&(nid_objs[297]),/* "DVCS" */
-&(nid_objs[99]),/* "GN" */
-&(nid_objs[855]),/* "HMAC" */
-&(nid_objs[780]),/* "HMAC-MD5" */
-&(nid_objs[781]),/* "HMAC-SHA1" */
-&(nid_objs[381]),/* "IANA" */
-&(nid_objs[34]),/* "IDEA-CBC" */
-&(nid_objs[35]),/* "IDEA-CFB" */
-&(nid_objs[36]),/* "IDEA-ECB" */
-&(nid_objs[46]),/* "IDEA-OFB" */
-&(nid_objs[181]),/* "ISO" */
-&(nid_objs[183]),/* "ISO-US" */
-&(nid_objs[645]),/* "ITU-T" */
-&(nid_objs[646]),/* "JOINT-ISO-ITU-T" */
-&(nid_objs[773]),/* "KISA" */
-&(nid_objs[15]),/* "L" */
-&(nid_objs[856]),/* "LocalKeySet" */
-&(nid_objs[ 3]),/* "MD2" */
-&(nid_objs[257]),/* "MD4" */
-&(nid_objs[ 4]),/* "MD5" */
-&(nid_objs[114]),/* "MD5-SHA1" */
-&(nid_objs[95]),/* "MDC2" */
-&(nid_objs[388]),/* "Mail" */
-&(nid_objs[393]),/* "NULL" */
-&(nid_objs[404]),/* "NULL" */
-&(nid_objs[57]),/* "Netscape" */
-&(nid_objs[366]),/* "Nonce" */
-&(nid_objs[17]),/* "O" */
-&(nid_objs[178]),/* "OCSP" */
-&(nid_objs[180]),/* "OCSPSigning" */
-&(nid_objs[379]),/* "ORG" */
-&(nid_objs[18]),/* "OU" */
-&(nid_objs[749]),/* "Oakley-EC2N-3" */
-&(nid_objs[750]),/* "Oakley-EC2N-4" */
-&(nid_objs[ 9]),/* "PBE-MD2-DES" */
-&(nid_objs[168]),/* "PBE-MD2-RC2-64" */
-&(nid_objs[10]),/* "PBE-MD5-DES" */
-&(nid_objs[169]),/* "PBE-MD5-RC2-64" */
-&(nid_objs[147]),/* "PBE-SHA1-2DES" */
-&(nid_objs[146]),/* "PBE-SHA1-3DES" */
-&(nid_objs[170]),/* "PBE-SHA1-DES" */
-&(nid_objs[148]),/* "PBE-SHA1-RC2-128" */
-&(nid_objs[149]),/* "PBE-SHA1-RC2-40" */
-&(nid_objs[68]),/* "PBE-SHA1-RC2-64" */
-&(nid_objs[144]),/* "PBE-SHA1-RC4-128" */
-&(nid_objs[145]),/* "PBE-SHA1-RC4-40" */
-&(nid_objs[161]),/* "PBES2" */
-&(nid_objs[69]),/* "PBKDF2" */
-&(nid_objs[162]),/* "PBMAC1" */
-&(nid_objs[127]),/* "PKIX" */
-&(nid_objs[98]),/* "RC2-40-CBC" */
-&(nid_objs[166]),/* "RC2-64-CBC" */
-&(nid_objs[37]),/* "RC2-CBC" */
-&(nid_objs[39]),/* "RC2-CFB" */
-&(nid_objs[38]),/* "RC2-ECB" */
-&(nid_objs[40]),/* "RC2-OFB" */
-&(nid_objs[ 5]),/* "RC4" */
-&(nid_objs[97]),/* "RC4-40" */
-&(nid_objs[120]),/* "RC5-CBC" */
-&(nid_objs[122]),/* "RC5-CFB" */
-&(nid_objs[121]),/* "RC5-ECB" */
-&(nid_objs[123]),/* "RC5-OFB" */
-&(nid_objs[117]),/* "RIPEMD160" */
-&(nid_objs[124]),/* "RLE" */
-&(nid_objs[19]),/* "RSA" */
-&(nid_objs[ 7]),/* "RSA-MD2" */
-&(nid_objs[396]),/* "RSA-MD4" */
-&(nid_objs[ 8]),/* "RSA-MD5" */
-&(nid_objs[96]),/* "RSA-MDC2" */
-&(nid_objs[104]),/* "RSA-NP-MD5" */
-&(nid_objs[119]),/* "RSA-RIPEMD160" */
-&(nid_objs[42]),/* "RSA-SHA" */
-&(nid_objs[65]),/* "RSA-SHA1" */
-&(nid_objs[115]),/* "RSA-SHA1-2" */
-&(nid_objs[671]),/* "RSA-SHA224" */
-&(nid_objs[668]),/* "RSA-SHA256" */
-&(nid_objs[669]),/* "RSA-SHA384" */
-&(nid_objs[670]),/* "RSA-SHA512" */
-&(nid_objs[777]),/* "SEED-CBC" */
-&(nid_objs[779]),/* "SEED-CFB" */
-&(nid_objs[776]),/* "SEED-ECB" */
-&(nid_objs[778]),/* "SEED-OFB" */
-&(nid_objs[41]),/* "SHA" */
-&(nid_objs[64]),/* "SHA1" */
-&(nid_objs[675]),/* "SHA224" */
-&(nid_objs[672]),/* "SHA256" */
-&(nid_objs[673]),/* "SHA384" */
-&(nid_objs[674]),/* "SHA512" */
-&(nid_objs[188]),/* "SMIME" */
-&(nid_objs[167]),/* "SMIME-CAPS" */
-&(nid_objs[100]),/* "SN" */
-&(nid_objs[16]),/* "ST" */
-&(nid_objs[143]),/* "SXNetID" */
-&(nid_objs[458]),/* "UID" */
-&(nid_objs[ 0]),/* "UNDEF" */
-&(nid_objs[11]),/* "X500" */
-&(nid_objs[378]),/* "X500algorithms" */
-&(nid_objs[12]),/* "X509" */
-&(nid_objs[184]),/* "X9-57" */
-&(nid_objs[185]),/* "X9cm" */
-&(nid_objs[125]),/* "ZLIB" */
-&(nid_objs[478]),/* "aRecord" */
-&(nid_objs[289]),/* "aaControls" */
-&(nid_objs[287]),/* "ac-auditEntity" */
-&(nid_objs[397]),/* "ac-proxying" */
-&(nid_objs[288]),/* "ac-targeting" */
-&(nid_objs[368]),/* "acceptableResponses" */
-&(nid_objs[446]),/* "account" */
-&(nid_objs[363]),/* "ad_timestamping" */
-&(nid_objs[376]),/* "algorithm" */
-&(nid_objs[405]),/* "ansi-X9-62" */
-&(nid_objs[746]),/* "anyPolicy" */
-&(nid_objs[370]),/* "archiveCutoff" */
-&(nid_objs[484]),/* "associatedDomain" */
-&(nid_objs[485]),/* "associatedName" */
-&(nid_objs[501]),/* "audio" */
-&(nid_objs[177]),/* "authorityInfoAccess" */
-&(nid_objs[90]),/* "authorityKeyIdentifier" */
-&(nid_objs[882]),/* "authorityRevocationList" */
-&(nid_objs[87]),/* "basicConstraints" */
-&(nid_objs[365]),/* "basicOCSPResponse" */
-&(nid_objs[285]),/* "biometricInfo" */
-&(nid_objs[494]),/* "buildingName" */
-&(nid_objs[860]),/* "businessCategory" */
-&(nid_objs[691]),/* "c2onb191v4" */
-&(nid_objs[692]),/* "c2onb191v5" */
-&(nid_objs[697]),/* "c2onb239v4" */
-&(nid_objs[698]),/* "c2onb239v5" */
-&(nid_objs[684]),/* "c2pnb163v1" */
-&(nid_objs[685]),/* "c2pnb163v2" */
-&(nid_objs[686]),/* "c2pnb163v3" */
-&(nid_objs[687]),/* "c2pnb176v1" */
-&(nid_objs[693]),/* "c2pnb208w1" */
-&(nid_objs[699]),/* "c2pnb272w1" */
-&(nid_objs[700]),/* "c2pnb304w1" */
-&(nid_objs[702]),/* "c2pnb368w1" */
-&(nid_objs[688]),/* "c2tnb191v1" */
-&(nid_objs[689]),/* "c2tnb191v2" */
-&(nid_objs[690]),/* "c2tnb191v3" */
-&(nid_objs[694]),/* "c2tnb239v1" */
-&(nid_objs[695]),/* "c2tnb239v2" */
-&(nid_objs[696]),/* "c2tnb239v3" */
-&(nid_objs[701]),/* "c2tnb359v1" */
-&(nid_objs[703]),/* "c2tnb431r1" */
-&(nid_objs[881]),/* "cACertificate" */
-&(nid_objs[483]),/* "cNAMERecord" */
-&(nid_objs[179]),/* "caIssuers" */
-&(nid_objs[785]),/* "caRepository" */
-&(nid_objs[443]),/* "caseIgnoreIA5StringSyntax" */
-&(nid_objs[152]),/* "certBag" */
-&(nid_objs[677]),/* "certicom-arc" */
-&(nid_objs[771]),/* "certificateIssuer" */
-&(nid_objs[89]),/* "certificatePolicies" */
-&(nid_objs[883]),/* "certificateRevocationList" */
-&(nid_objs[54]),/* "challengePassword" */
-&(nid_objs[407]),/* "characteristic-two-field" */
-&(nid_objs[395]),/* "clearance" */
-&(nid_objs[130]),/* "clientAuth" */
-&(nid_objs[131]),/* "codeSigning" */
-&(nid_objs[50]),/* "contentType" */
-&(nid_objs[53]),/* "countersignature" */
-&(nid_objs[153]),/* "crlBag" */
-&(nid_objs[103]),/* "crlDistributionPoints" */
-&(nid_objs[88]),/* "crlNumber" */
-&(nid_objs[884]),/* "crossCertificatePair" */
-&(nid_objs[806]),/* "cryptocom" */
-&(nid_objs[805]),/* "cryptopro" */
-&(nid_objs[500]),/* "dITRedirect" */
-&(nid_objs[451]),/* "dNSDomain" */
-&(nid_objs[495]),/* "dSAQuality" */
-&(nid_objs[434]),/* "data" */
-&(nid_objs[390]),/* "dcobject" */
-&(nid_objs[140]),/* "deltaCRL" */
-&(nid_objs[891]),/* "deltaRevocationList" */
-&(nid_objs[107]),/* "description" */
-&(nid_objs[871]),/* "destinationIndicator" */
-&(nid_objs[28]),/* "dhKeyAgreement" */
-&(nid_objs[382]),/* "directory" */
-&(nid_objs[887]),/* "distinguishedName" */
-&(nid_objs[892]),/* "dmdName" */
-&(nid_objs[174]),/* "dnQualifier" */
-&(nid_objs[447]),/* "document" */
-&(nid_objs[471]),/* "documentAuthor" */
-&(nid_objs[468]),/* "documentIdentifier" */
-&(nid_objs[472]),/* "documentLocation" */
-&(nid_objs[502]),/* "documentPublisher" */
-&(nid_objs[449]),/* "documentSeries" */
-&(nid_objs[469]),/* "documentTitle" */
-&(nid_objs[470]),/* "documentVersion" */
-&(nid_objs[392]),/* "domain" */
-&(nid_objs[452]),/* "domainRelatedObject" */
-&(nid_objs[802]),/* "dsa_with_SHA224" */
-&(nid_objs[803]),/* "dsa_with_SHA256" */
-&(nid_objs[791]),/* "ecdsa-with-Recommended" */
-&(nid_objs[416]),/* "ecdsa-with-SHA1" */
-&(nid_objs[793]),/* "ecdsa-with-SHA224" */
-&(nid_objs[794]),/* "ecdsa-with-SHA256" */
-&(nid_objs[795]),/* "ecdsa-with-SHA384" */
-&(nid_objs[796]),/* "ecdsa-with-SHA512" */
-&(nid_objs[792]),/* "ecdsa-with-Specified" */
-&(nid_objs[48]),/* "emailAddress" */
-&(nid_objs[132]),/* "emailProtection" */
-&(nid_objs[885]),/* "enhancedSearchGuide" */
-&(nid_objs[389]),/* "enterprises" */
-&(nid_objs[384]),/* "experimental" */
-&(nid_objs[172]),/* "extReq" */
-&(nid_objs[56]),/* "extendedCertificateAttributes" */
-&(nid_objs[126]),/* "extendedKeyUsage" */
-&(nid_objs[372]),/* "extendedStatus" */
-&(nid_objs[867]),/* "facsimileTelephoneNumber" */
-&(nid_objs[462]),/* "favouriteDrink" */
-&(nid_objs[857]),/* "freshestCRL" */
-&(nid_objs[453]),/* "friendlyCountry" */
-&(nid_objs[490]),/* "friendlyCountryName" */
-&(nid_objs[156]),/* "friendlyName" */
-&(nid_objs[509]),/* "generationQualifier" */
-&(nid_objs[815]),/* "gost-mac" */
-&(nid_objs[811]),/* "gost2001" */
-&(nid_objs[851]),/* "gost2001cc" */
-&(nid_objs[813]),/* "gost89" */
-&(nid_objs[814]),/* "gost89-cnt" */
-&(nid_objs[812]),/* "gost94" */
-&(nid_objs[850]),/* "gost94cc" */
-&(nid_objs[797]),/* "hmacWithMD5" */
-&(nid_objs[163]),/* "hmacWithSHA1" */
-&(nid_objs[798]),/* "hmacWithSHA224" */
-&(nid_objs[799]),/* "hmacWithSHA256" */
-&(nid_objs[800]),/* "hmacWithSHA384" */
-&(nid_objs[801]),/* "hmacWithSHA512" */
-&(nid_objs[432]),/* "holdInstructionCallIssuer" */
-&(nid_objs[430]),/* "holdInstructionCode" */
-&(nid_objs[431]),/* "holdInstructionNone" */
-&(nid_objs[433]),/* "holdInstructionReject" */
-&(nid_objs[486]),/* "homePostalAddress" */
-&(nid_objs[473]),/* "homeTelephoneNumber" */
-&(nid_objs[466]),/* "host" */
-&(nid_objs[889]),/* "houseIdentifier" */
-&(nid_objs[442]),/* "iA5StringSyntax" */
-&(nid_objs[783]),/* "id-DHBasedMac" */
-&(nid_objs[824]),/* "id-Gost28147-89-CryptoPro-A-ParamSet" */
-&(nid_objs[825]),/* "id-Gost28147-89-CryptoPro-B-ParamSet" */
-&(nid_objs[826]),/* "id-Gost28147-89-CryptoPro-C-ParamSet" */
-&(nid_objs[827]),/* "id-Gost28147-89-CryptoPro-D-ParamSet" */
-&(nid_objs[819]),/* "id-Gost28147-89-CryptoPro-KeyMeshing" */
-&(nid_objs[829]),/* "id-Gost28147-89-CryptoPro-Oscar-1-0-ParamSet" */
-&(nid_objs[828]),/* "id-Gost28147-89-CryptoPro-Oscar-1-1-ParamSet" */
-&(nid_objs[830]),/* "id-Gost28147-89-CryptoPro-RIC-1-ParamSet" */
-&(nid_objs[820]),/* "id-Gost28147-89-None-KeyMeshing" */
-&(nid_objs[823]),/* "id-Gost28147-89-TestParamSet" */
-&(nid_objs[849]),/* "id-Gost28147-89-cc" */
-&(nid_objs[840]),/* "id-GostR3410-2001-CryptoPro-A-ParamSet" */
-&(nid_objs[841]),/* "id-GostR3410-2001-CryptoPro-B-ParamSet" */
-&(nid_objs[842]),/* "id-GostR3410-2001-CryptoPro-C-ParamSet" */
-&(nid_objs[843]),/* "id-GostR3410-2001-CryptoPro-XchA-ParamSet" */
-&(nid_objs[844]),/* "id-GostR3410-2001-CryptoPro-XchB-ParamSet" */
-&(nid_objs[854]),/* "id-GostR3410-2001-ParamSet-cc" */
-&(nid_objs[839]),/* "id-GostR3410-2001-TestParamSet" */
-&(nid_objs[817]),/* "id-GostR3410-2001DH" */
-&(nid_objs[832]),/* "id-GostR3410-94-CryptoPro-A-ParamSet" */
-&(nid_objs[833]),/* "id-GostR3410-94-CryptoPro-B-ParamSet" */
-&(nid_objs[834]),/* "id-GostR3410-94-CryptoPro-C-ParamSet" */
-&(nid_objs[835]),/* "id-GostR3410-94-CryptoPro-D-ParamSet" */
-&(nid_objs[836]),/* "id-GostR3410-94-CryptoPro-XchA-ParamSet" */
-&(nid_objs[837]),/* "id-GostR3410-94-CryptoPro-XchB-ParamSet" */
-&(nid_objs[838]),/* "id-GostR3410-94-CryptoPro-XchC-ParamSet" */
-&(nid_objs[831]),/* "id-GostR3410-94-TestParamSet" */
-&(nid_objs[845]),/* "id-GostR3410-94-a" */
-&(nid_objs[846]),/* "id-GostR3410-94-aBis" */
-&(nid_objs[847]),/* "id-GostR3410-94-b" */
-&(nid_objs[848]),/* "id-GostR3410-94-bBis" */
-&(nid_objs[818]),/* "id-GostR3410-94DH" */
-&(nid_objs[822]),/* "id-GostR3411-94-CryptoProParamSet" */
-&(nid_objs[821]),/* "id-GostR3411-94-TestParamSet" */
-&(nid_objs[807]),/* "id-GostR3411-94-with-GostR3410-2001" */
-&(nid_objs[853]),/* "id-GostR3411-94-with-GostR3410-2001-cc" */
-&(nid_objs[808]),/* "id-GostR3411-94-with-GostR3410-94" */
-&(nid_objs[852]),/* "id-GostR3411-94-with-GostR3410-94-cc" */
-&(nid_objs[810]),/* "id-HMACGostR3411-94" */
-&(nid_objs[782]),/* "id-PasswordBasedMAC" */
-&(nid_objs[266]),/* "id-aca" */
-&(nid_objs[355]),/* "id-aca-accessIdentity" */
-&(nid_objs[354]),/* "id-aca-authenticationInfo" */
-&(nid_objs[356]),/* "id-aca-chargingIdentity" */
-&(nid_objs[399]),/* "id-aca-encAttrs" */
-&(nid_objs[357]),/* "id-aca-group" */
-&(nid_objs[358]),/* "id-aca-role" */
-&(nid_objs[176]),/* "id-ad" */
-&(nid_objs[788]),/* "id-aes128-wrap" */
-&(nid_objs[789]),/* "id-aes192-wrap" */
-&(nid_objs[790]),/* "id-aes256-wrap" */
-&(nid_objs[262]),/* "id-alg" */
-&(nid_objs[323]),/* "id-alg-des40" */
-&(nid_objs[326]),/* "id-alg-dh-pop" */
-&(nid_objs[325]),/* "id-alg-dh-sig-hmac-sha1" */
-&(nid_objs[324]),/* "id-alg-noSignature" */
-&(nid_objs[268]),/* "id-cct" */
-&(nid_objs[361]),/* "id-cct-PKIData" */
-&(nid_objs[362]),/* "id-cct-PKIResponse" */
-&(nid_objs[360]),/* "id-cct-crs" */
-&(nid_objs[81]),/* "id-ce" */
-&(nid_objs[680]),/* "id-characteristic-two-basis" */
-&(nid_objs[263]),/* "id-cmc" */
-&(nid_objs[334]),/* "id-cmc-addExtensions" */
-&(nid_objs[346]),/* "id-cmc-confirmCertAcceptance" */
-&(nid_objs[330]),/* "id-cmc-dataReturn" */
-&(nid_objs[336]),/* "id-cmc-decryptedPOP" */
-&(nid_objs[335]),/* "id-cmc-encryptedPOP" */
-&(nid_objs[339]),/* "id-cmc-getCRL" */
-&(nid_objs[338]),/* "id-cmc-getCert" */
-&(nid_objs[328]),/* "id-cmc-identification" */
-&(nid_objs[329]),/* "id-cmc-identityProof" */
-&(nid_objs[337]),/* "id-cmc-lraPOPWitness" */
-&(nid_objs[344]),/* "id-cmc-popLinkRandom" */
-&(nid_objs[345]),/* "id-cmc-popLinkWitness" */
-&(nid_objs[343]),/* "id-cmc-queryPending" */
-&(nid_objs[333]),/* "id-cmc-recipientNonce" */
-&(nid_objs[341]),/* "id-cmc-regInfo" */
-&(nid_objs[342]),/* "id-cmc-responseInfo" */
-&(nid_objs[340]),/* "id-cmc-revokeRequest" */
-&(nid_objs[332]),/* "id-cmc-senderNonce" */
-&(nid_objs[327]),/* "id-cmc-statusInfo" */
-&(nid_objs[331]),/* "id-cmc-transactionId" */
-&(nid_objs[787]),/* "id-ct-asciiTextWithCRLF" */
-&(nid_objs[408]),/* "id-ecPublicKey" */
-&(nid_objs[508]),/* "id-hex-multipart-message" */
-&(nid_objs[507]),/* "id-hex-partial-message" */
-&(nid_objs[260]),/* "id-it" */
-&(nid_objs[302]),/* "id-it-caKeyUpdateInfo" */
-&(nid_objs[298]),/* "id-it-caProtEncCert" */
-&(nid_objs[311]),/* "id-it-confirmWaitTime" */
-&(nid_objs[303]),/* "id-it-currentCRL" */
-&(nid_objs[300]),/* "id-it-encKeyPairTypes" */
-&(nid_objs[310]),/* "id-it-implicitConfirm" */
-&(nid_objs[308]),/* "id-it-keyPairParamRep" */
-&(nid_objs[307]),/* "id-it-keyPairParamReq" */
-&(nid_objs[312]),/* "id-it-origPKIMessage" */
-&(nid_objs[301]),/* "id-it-preferredSymmAlg" */
-&(nid_objs[309]),/* "id-it-revPassphrase" */
-&(nid_objs[299]),/* "id-it-signKeyPairTypes" */
-&(nid_objs[305]),/* "id-it-subscriptionRequest" */
-&(nid_objs[306]),/* "id-it-subscriptionResponse" */
-&(nid_objs[784]),/* "id-it-suppLangTags" */
-&(nid_objs[304]),/* "id-it-unsupportedOIDs" */
-&(nid_objs[128]),/* "id-kp" */
-&(nid_objs[280]),/* "id-mod-attribute-cert" */
-&(nid_objs[274]),/* "id-mod-cmc" */
-&(nid_objs[277]),/* "id-mod-cmp" */
-&(nid_objs[284]),/* "id-mod-cmp2000" */
-&(nid_objs[273]),/* "id-mod-crmf" */
-&(nid_objs[283]),/* "id-mod-dvcs" */
-&(nid_objs[275]),/* "id-mod-kea-profile-88" */
-&(nid_objs[276]),/* "id-mod-kea-profile-93" */
-&(nid_objs[282]),/* "id-mod-ocsp" */
-&(nid_objs[278]),/* "id-mod-qualified-cert-88" */
-&(nid_objs[279]),/* "id-mod-qualified-cert-93" */
-&(nid_objs[281]),/* "id-mod-timestamp-protocol" */
-&(nid_objs[264]),/* "id-on" */
-&(nid_objs[858]),/* "id-on-permanentIdentifier" */
-&(nid_objs[347]),/* "id-on-personalData" */
-&(nid_objs[265]),/* "id-pda" */
-&(nid_objs[352]),/* "id-pda-countryOfCitizenship" */
-&(nid_objs[353]),/* "id-pda-countryOfResidence" */
-&(nid_objs[348]),/* "id-pda-dateOfBirth" */
-&(nid_objs[351]),/* "id-pda-gender" */
-&(nid_objs[349]),/* "id-pda-placeOfBirth" */
-&(nid_objs[175]),/* "id-pe" */
-&(nid_objs[261]),/* "id-pkip" */
-&(nid_objs[258]),/* "id-pkix-mod" */
-&(nid_objs[269]),/* "id-pkix1-explicit-88" */
-&(nid_objs[271]),/* "id-pkix1-explicit-93" */
-&(nid_objs[270]),/* "id-pkix1-implicit-88" */
-&(nid_objs[272]),/* "id-pkix1-implicit-93" */
-&(nid_objs[662]),/* "id-ppl" */
-&(nid_objs[664]),/* "id-ppl-anyLanguage" */
-&(nid_objs[667]),/* "id-ppl-independent" */
-&(nid_objs[665]),/* "id-ppl-inheritAll" */
-&(nid_objs[267]),/* "id-qcs" */
-&(nid_objs[359]),/* "id-qcs-pkixQCSyntax-v1" */
-&(nid_objs[259]),/* "id-qt" */
-&(nid_objs[164]),/* "id-qt-cps" */
-&(nid_objs[165]),/* "id-qt-unotice" */
-&(nid_objs[313]),/* "id-regCtrl" */
-&(nid_objs[316]),/* "id-regCtrl-authenticator" */
-&(nid_objs[319]),/* "id-regCtrl-oldCertID" */
-&(nid_objs[318]),/* "id-regCtrl-pkiArchiveOptions" */
-&(nid_objs[317]),/* "id-regCtrl-pkiPublicationInfo" */
-&(nid_objs[320]),/* "id-regCtrl-protocolEncrKey" */
-&(nid_objs[315]),/* "id-regCtrl-regToken" */
-&(nid_objs[314]),/* "id-regInfo" */
-&(nid_objs[322]),/* "id-regInfo-certReq" */
-&(nid_objs[321]),/* "id-regInfo-utf8Pairs" */
-&(nid_objs[512]),/* "id-set" */
-&(nid_objs[191]),/* "id-smime-aa" */
-&(nid_objs[215]),/* "id-smime-aa-contentHint" */
-&(nid_objs[218]),/* "id-smime-aa-contentIdentifier" */
-&(nid_objs[221]),/* "id-smime-aa-contentReference" */
-&(nid_objs[240]),/* "id-smime-aa-dvcs-dvc" */
-&(nid_objs[217]),/* "id-smime-aa-encapContentType" */
-&(nid_objs[222]),/* "id-smime-aa-encrypKeyPref" */
-&(nid_objs[220]),/* "id-smime-aa-equivalentLabels" */
-&(nid_objs[232]),/* "id-smime-aa-ets-CertificateRefs" */
-&(nid_objs[233]),/* "id-smime-aa-ets-RevocationRefs" */
-&(nid_objs[238]),/* "id-smime-aa-ets-archiveTimeStamp" */
-&(nid_objs[237]),/* "id-smime-aa-ets-certCRLTimestamp" */
-&(nid_objs[234]),/* "id-smime-aa-ets-certValues" */
-&(nid_objs[227]),/* "id-smime-aa-ets-commitmentType" */
-&(nid_objs[231]),/* "id-smime-aa-ets-contentTimestamp" */
-&(nid_objs[236]),/* "id-smime-aa-ets-escTimeStamp" */
-&(nid_objs[230]),/* "id-smime-aa-ets-otherSigCert" */
-&(nid_objs[235]),/* "id-smime-aa-ets-revocationValues" */
-&(nid_objs[226]),/* "id-smime-aa-ets-sigPolicyId" */
-&(nid_objs[229]),/* "id-smime-aa-ets-signerAttr" */
-&(nid_objs[228]),/* "id-smime-aa-ets-signerLocation" */
-&(nid_objs[219]),/* "id-smime-aa-macValue" */
-&(nid_objs[214]),/* "id-smime-aa-mlExpandHistory" */
-&(nid_objs[216]),/* "id-smime-aa-msgSigDigest" */
-&(nid_objs[212]),/* "id-smime-aa-receiptRequest" */
-&(nid_objs[213]),/* "id-smime-aa-securityLabel" */
-&(nid_objs[239]),/* "id-smime-aa-signatureType" */
-&(nid_objs[223]),/* "id-smime-aa-signingCertificate" */
-&(nid_objs[224]),/* "id-smime-aa-smimeEncryptCerts" */
-&(nid_objs[225]),/* "id-smime-aa-timeStampToken" */
-&(nid_objs[192]),/* "id-smime-alg" */
-&(nid_objs[243]),/* "id-smime-alg-3DESwrap" */
-&(nid_objs[246]),/* "id-smime-alg-CMS3DESwrap" */
-&(nid_objs[247]),/* "id-smime-alg-CMSRC2wrap" */
-&(nid_objs[245]),/* "id-smime-alg-ESDH" */
-&(nid_objs[241]),/* "id-smime-alg-ESDHwith3DES" */
-&(nid_objs[242]),/* "id-smime-alg-ESDHwithRC2" */
-&(nid_objs[244]),/* "id-smime-alg-RC2wrap" */
-&(nid_objs[193]),/* "id-smime-cd" */
-&(nid_objs[248]),/* "id-smime-cd-ldap" */
-&(nid_objs[190]),/* "id-smime-ct" */
-&(nid_objs[210]),/* "id-smime-ct-DVCSRequestData" */
-&(nid_objs[211]),/* "id-smime-ct-DVCSResponseData" */
-&(nid_objs[208]),/* "id-smime-ct-TDTInfo" */
-&(nid_objs[207]),/* "id-smime-ct-TSTInfo" */
-&(nid_objs[205]),/* "id-smime-ct-authData" */
-&(nid_objs[786]),/* "id-smime-ct-compressedData" */
-&(nid_objs[209]),/* "id-smime-ct-contentInfo" */
-&(nid_objs[206]),/* "id-smime-ct-publishCert" */
-&(nid_objs[204]),/* "id-smime-ct-receipt" */
-&(nid_objs[195]),/* "id-smime-cti" */
-&(nid_objs[255]),/* "id-smime-cti-ets-proofOfApproval" */
-&(nid_objs[256]),/* "id-smime-cti-ets-proofOfCreation" */
-&(nid_objs[253]),/* "id-smime-cti-ets-proofOfDelivery" */
-&(nid_objs[251]),/* "id-smime-cti-ets-proofOfOrigin" */
-&(nid_objs[252]),/* "id-smime-cti-ets-proofOfReceipt" */
-&(nid_objs[254]),/* "id-smime-cti-ets-proofOfSender" */
-&(nid_objs[189]),/* "id-smime-mod" */
-&(nid_objs[196]),/* "id-smime-mod-cms" */
-&(nid_objs[197]),/* "id-smime-mod-ess" */
-&(nid_objs[202]),/* "id-smime-mod-ets-eSigPolicy-88" */
-&(nid_objs[203]),/* "id-smime-mod-ets-eSigPolicy-97" */
-&(nid_objs[200]),/* "id-smime-mod-ets-eSignature-88" */
-&(nid_objs[201]),/* "id-smime-mod-ets-eSignature-97" */
-&(nid_objs[199]),/* "id-smime-mod-msg-v3" */
-&(nid_objs[198]),/* "id-smime-mod-oid" */
-&(nid_objs[194]),/* "id-smime-spq" */
-&(nid_objs[250]),/* "id-smime-spq-ets-sqt-unotice" */
-&(nid_objs[249]),/* "id-smime-spq-ets-sqt-uri" */
-&(nid_objs[676]),/* "identified-organization" */
-&(nid_objs[461]),/* "info" */
-&(nid_objs[748]),/* "inhibitAnyPolicy" */
-&(nid_objs[101]),/* "initials" */
-&(nid_objs[647]),/* "international-organizations" */
-&(nid_objs[869]),/* "internationaliSDNNumber" */
-&(nid_objs[142]),/* "invalidityDate" */
-&(nid_objs[294]),/* "ipsecEndSystem" */
-&(nid_objs[295]),/* "ipsecTunnel" */
-&(nid_objs[296]),/* "ipsecUser" */
-&(nid_objs[86]),/* "issuerAltName" */
-&(nid_objs[770]),/* "issuingDistributionPoint" */
-&(nid_objs[492]),/* "janetMailbox" */
-&(nid_objs[150]),/* "keyBag" */
-&(nid_objs[83]),/* "keyUsage" */
-&(nid_objs[477]),/* "lastModifiedBy" */
-&(nid_objs[476]),/* "lastModifiedTime" */
-&(nid_objs[157]),/* "localKeyID" */
-&(nid_objs[480]),/* "mXRecord" */
-&(nid_objs[460]),/* "mail" */
-&(nid_objs[493]),/* "mailPreferenceOption" */
-&(nid_objs[467]),/* "manager" */
-&(nid_objs[809]),/* "md_gost94" */
-&(nid_objs[875]),/* "member" */
-&(nid_objs[182]),/* "member-body" */
-&(nid_objs[51]),/* "messageDigest" */
-&(nid_objs[383]),/* "mgmt" */
-&(nid_objs[504]),/* "mime-mhs" */
-&(nid_objs[506]),/* "mime-mhs-bodies" */
-&(nid_objs[505]),/* "mime-mhs-headings" */
-&(nid_objs[488]),/* "mobileTelephoneNumber" */
-&(nid_objs[136]),/* "msCTLSign" */
-&(nid_objs[135]),/* "msCodeCom" */
-&(nid_objs[134]),/* "msCodeInd" */
-&(nid_objs[138]),/* "msEFS" */
-&(nid_objs[171]),/* "msExtReq" */
-&(nid_objs[137]),/* "msSGC" */
-&(nid_objs[648]),/* "msSmartcardLogin" */
-&(nid_objs[649]),/* "msUPN" */
-&(nid_objs[481]),/* "nSRecord" */
-&(nid_objs[173]),/* "name" */
-&(nid_objs[666]),/* "nameConstraints" */
-&(nid_objs[369]),/* "noCheck" */
-&(nid_objs[403]),/* "noRevAvail" */
-&(nid_objs[72]),/* "nsBaseUrl" */
-&(nid_objs[76]),/* "nsCaPolicyUrl" */
-&(nid_objs[74]),/* "nsCaRevocationUrl" */
-&(nid_objs[58]),/* "nsCertExt" */
-&(nid_objs[79]),/* "nsCertSequence" */
-&(nid_objs[71]),/* "nsCertType" */
-&(nid_objs[78]),/* "nsComment" */
-&(nid_objs[59]),/* "nsDataType" */
-&(nid_objs[75]),/* "nsRenewalUrl" */
-&(nid_objs[73]),/* "nsRevocationUrl" */
-&(nid_objs[139]),/* "nsSGC" */
-&(nid_objs[77]),/* "nsSslServerName" */
-&(nid_objs[681]),/* "onBasis" */
-&(nid_objs[491]),/* "organizationalStatus" */
-&(nid_objs[475]),/* "otherMailbox" */
-&(nid_objs[876]),/* "owner" */
-&(nid_objs[489]),/* "pagerTelephoneNumber" */
-&(nid_objs[374]),/* "path" */
-&(nid_objs[112]),/* "pbeWithMD5AndCast5CBC" */
-&(nid_objs[499]),/* "personalSignature" */
-&(nid_objs[487]),/* "personalTitle" */
-&(nid_objs[464]),/* "photo" */
-&(nid_objs[863]),/* "physicalDeliveryOfficeName" */
-&(nid_objs[437]),/* "pilot" */
-&(nid_objs[439]),/* "pilotAttributeSyntax" */
-&(nid_objs[438]),/* "pilotAttributeType" */
-&(nid_objs[479]),/* "pilotAttributeType27" */
-&(nid_objs[456]),/* "pilotDSA" */
-&(nid_objs[441]),/* "pilotGroups" */
-&(nid_objs[444]),/* "pilotObject" */
-&(nid_objs[440]),/* "pilotObjectClass" */
-&(nid_objs[455]),/* "pilotOrganization" */
-&(nid_objs[445]),/* "pilotPerson" */
-&(nid_objs[ 2]),/* "pkcs" */
-&(nid_objs[186]),/* "pkcs1" */
-&(nid_objs[27]),/* "pkcs3" */
-&(nid_objs[187]),/* "pkcs5" */
-&(nid_objs[20]),/* "pkcs7" */
-&(nid_objs[21]),/* "pkcs7-data" */
-&(nid_objs[25]),/* "pkcs7-digestData" */
-&(nid_objs[26]),/* "pkcs7-encryptedData" */
-&(nid_objs[23]),/* "pkcs7-envelopedData" */
-&(nid_objs[24]),/* "pkcs7-signedAndEnvelopedData" */
-&(nid_objs[22]),/* "pkcs7-signedData" */
-&(nid_objs[151]),/* "pkcs8ShroudedKeyBag" */
-&(nid_objs[47]),/* "pkcs9" */
-&(nid_objs[401]),/* "policyConstraints" */
-&(nid_objs[747]),/* "policyMappings" */
-&(nid_objs[862]),/* "postOfficeBox" */
-&(nid_objs[861]),/* "postalAddress" */
-&(nid_objs[661]),/* "postalCode" */
-&(nid_objs[683]),/* "ppBasis" */
-&(nid_objs[872]),/* "preferredDeliveryMethod" */
-&(nid_objs[873]),/* "presentationAddress" */
-&(nid_objs[816]),/* "prf-gostr3411-94" */
-&(nid_objs[406]),/* "prime-field" */
-&(nid_objs[409]),/* "prime192v1" */
-&(nid_objs[410]),/* "prime192v2" */
-&(nid_objs[411]),/* "prime192v3" */
-&(nid_objs[412]),/* "prime239v1" */
-&(nid_objs[413]),/* "prime239v2" */
-&(nid_objs[414]),/* "prime239v3" */
-&(nid_objs[415]),/* "prime256v1" */
-&(nid_objs[385]),/* "private" */
-&(nid_objs[84]),/* "privateKeyUsagePeriod" */
-&(nid_objs[886]),/* "protocolInformation" */
-&(nid_objs[663]),/* "proxyCertInfo" */
-&(nid_objs[510]),/* "pseudonym" */
-&(nid_objs[435]),/* "pss" */
-&(nid_objs[286]),/* "qcStatements" */
-&(nid_objs[457]),/* "qualityLabelledData" */
-&(nid_objs[450]),/* "rFC822localPart" */
-&(nid_objs[870]),/* "registeredAddress" */
-&(nid_objs[400]),/* "role" */
-&(nid_objs[877]),/* "roleOccupant" */
-&(nid_objs[448]),/* "room" */
-&(nid_objs[463]),/* "roomNumber" */
-&(nid_objs[ 6]),/* "rsaEncryption" */
-&(nid_objs[644]),/* "rsaOAEPEncryptionSET" */
-&(nid_objs[377]),/* "rsaSignature" */
-&(nid_objs[ 1]),/* "rsadsi" */
-&(nid_objs[482]),/* "sOARecord" */
-&(nid_objs[155]),/* "safeContentsBag" */
-&(nid_objs[291]),/* "sbgp-autonomousSysNum" */
-&(nid_objs[290]),/* "sbgp-ipAddrBlock" */
-&(nid_objs[292]),/* "sbgp-routerIdentifier" */
-&(nid_objs[159]),/* "sdsiCertificate" */
-&(nid_objs[859]),/* "searchGuide" */
-&(nid_objs[704]),/* "secp112r1" */
-&(nid_objs[705]),/* "secp112r2" */
-&(nid_objs[706]),/* "secp128r1" */
-&(nid_objs[707]),/* "secp128r2" */
-&(nid_objs[708]),/* "secp160k1" */
-&(nid_objs[709]),/* "secp160r1" */
-&(nid_objs[710]),/* "secp160r2" */
-&(nid_objs[711]),/* "secp192k1" */
-&(nid_objs[712]),/* "secp224k1" */
-&(nid_objs[713]),/* "secp224r1" */
-&(nid_objs[714]),/* "secp256k1" */
-&(nid_objs[715]),/* "secp384r1" */
-&(nid_objs[716]),/* "secp521r1" */
-&(nid_objs[154]),/* "secretBag" */
-&(nid_objs[474]),/* "secretary" */
-&(nid_objs[717]),/* "sect113r1" */
-&(nid_objs[718]),/* "sect113r2" */
-&(nid_objs[719]),/* "sect131r1" */
-&(nid_objs[720]),/* "sect131r2" */
-&(nid_objs[721]),/* "sect163k1" */
-&(nid_objs[722]),/* "sect163r1" */
-&(nid_objs[723]),/* "sect163r2" */
-&(nid_objs[724]),/* "sect193r1" */
-&(nid_objs[725]),/* "sect193r2" */
-&(nid_objs[726]),/* "sect233k1" */
-&(nid_objs[727]),/* "sect233r1" */
-&(nid_objs[728]),/* "sect239k1" */
-&(nid_objs[729]),/* "sect283k1" */
-&(nid_objs[730]),/* "sect283r1" */
-&(nid_objs[731]),/* "sect409k1" */
-&(nid_objs[732]),/* "sect409r1" */
-&(nid_objs[733]),/* "sect571k1" */
-&(nid_objs[734]),/* "sect571r1" */
-&(nid_objs[386]),/* "security" */
-&(nid_objs[878]),/* "seeAlso" */
-&(nid_objs[394]),/* "selected-attribute-types" */
-&(nid_objs[105]),/* "serialNumber" */
-&(nid_objs[129]),/* "serverAuth" */
-&(nid_objs[371]),/* "serviceLocator" */
-&(nid_objs[625]),/* "set-addPolicy" */
-&(nid_objs[515]),/* "set-attr" */
-&(nid_objs[518]),/* "set-brand" */
-&(nid_objs[638]),/* "set-brand-AmericanExpress" */
-&(nid_objs[637]),/* "set-brand-Diners" */
-&(nid_objs[636]),/* "set-brand-IATA-ATA" */
-&(nid_objs[639]),/* "set-brand-JCB" */
-&(nid_objs[641]),/* "set-brand-MasterCard" */
-&(nid_objs[642]),/* "set-brand-Novus" */
-&(nid_objs[640]),/* "set-brand-Visa" */
-&(nid_objs[517]),/* "set-certExt" */
-&(nid_objs[513]),/* "set-ctype" */
-&(nid_objs[514]),/* "set-msgExt" */
-&(nid_objs[516]),/* "set-policy" */
-&(nid_objs[607]),/* "set-policy-root" */
-&(nid_objs[624]),/* "set-rootKeyThumb" */
-&(nid_objs[620]),/* "setAttr-Cert" */
-&(nid_objs[631]),/* "setAttr-GenCryptgrm" */
-&(nid_objs[623]),/* "setAttr-IssCap" */
-&(nid_objs[628]),/* "setAttr-IssCap-CVM" */
-&(nid_objs[630]),/* "setAttr-IssCap-Sig" */
-&(nid_objs[629]),/* "setAttr-IssCap-T2" */
-&(nid_objs[621]),/* "setAttr-PGWYcap" */
-&(nid_objs[635]),/* "setAttr-SecDevSig" */
-&(nid_objs[632]),/* "setAttr-T2Enc" */
-&(nid_objs[633]),/* "setAttr-T2cleartxt" */
-&(nid_objs[634]),/* "setAttr-TokICCsig" */
-&(nid_objs[627]),/* "setAttr-Token-B0Prime" */
-&(nid_objs[626]),/* "setAttr-Token-EMV" */
-&(nid_objs[622]),/* "setAttr-TokenType" */
-&(nid_objs[619]),/* "setCext-IssuerCapabilities" */
-&(nid_objs[615]),/* "setCext-PGWYcapabilities" */
-&(nid_objs[616]),/* "setCext-TokenIdentifier" */
-&(nid_objs[618]),/* "setCext-TokenType" */
-&(nid_objs[617]),/* "setCext-Track2Data" */
-&(nid_objs[611]),/* "setCext-cCertRequired" */
-&(nid_objs[609]),/* "setCext-certType" */
-&(nid_objs[608]),/* "setCext-hashedRoot" */
-&(nid_objs[610]),/* "setCext-merchData" */
-&(nid_objs[613]),/* "setCext-setExt" */
-&(nid_objs[614]),/* "setCext-setQualf" */
-&(nid_objs[612]),/* "setCext-tunneling" */
-&(nid_objs[540]),/* "setct-AcqCardCodeMsg" */
-&(nid_objs[576]),/* "setct-AcqCardCodeMsgTBE" */
-&(nid_objs[570]),/* "setct-AuthReqTBE" */
-&(nid_objs[534]),/* "setct-AuthReqTBS" */
-&(nid_objs[527]),/* "setct-AuthResBaggage" */
-&(nid_objs[571]),/* "setct-AuthResTBE" */
-&(nid_objs[572]),/* "setct-AuthResTBEX" */
-&(nid_objs[535]),/* "setct-AuthResTBS" */
-&(nid_objs[536]),/* "setct-AuthResTBSX" */
-&(nid_objs[528]),/* "setct-AuthRevReqBaggage" */
-&(nid_objs[577]),/* "setct-AuthRevReqTBE" */
-&(nid_objs[541]),/* "setct-AuthRevReqTBS" */
-&(nid_objs[529]),/* "setct-AuthRevResBaggage" */
-&(nid_objs[542]),/* "setct-AuthRevResData" */
-&(nid_objs[578]),/* "setct-AuthRevResTBE" */
-&(nid_objs[579]),/* "setct-AuthRevResTBEB" */
-&(nid_objs[543]),/* "setct-AuthRevResTBS" */
-&(nid_objs[573]),/* "setct-AuthTokenTBE" */
-&(nid_objs[537]),/* "setct-AuthTokenTBS" */
-&(nid_objs[600]),/* "setct-BCIDistributionTBS" */
-&(nid_objs[558]),/* "setct-BatchAdminReqData" */
-&(nid_objs[592]),/* "setct-BatchAdminReqTBE" */
-&(nid_objs[559]),/* "setct-BatchAdminResData" */
-&(nid_objs[593]),/* "setct-BatchAdminResTBE" */
-&(nid_objs[599]),/* "setct-CRLNotificationResTBS" */
-&(nid_objs[598]),/* "setct-CRLNotificationTBS" */
-&(nid_objs[580]),/* "setct-CapReqTBE" */
-&(nid_objs[581]),/* "setct-CapReqTBEX" */
-&(nid_objs[544]),/* "setct-CapReqTBS" */
-&(nid_objs[545]),/* "setct-CapReqTBSX" */
-&(nid_objs[546]),/* "setct-CapResData" */
-&(nid_objs[582]),/* "setct-CapResTBE" */
-&(nid_objs[583]),/* "setct-CapRevReqTBE" */
-&(nid_objs[584]),/* "setct-CapRevReqTBEX" */
-&(nid_objs[547]),/* "setct-CapRevReqTBS" */
-&(nid_objs[548]),/* "setct-CapRevReqTBSX" */
-&(nid_objs[549]),/* "setct-CapRevResData" */
-&(nid_objs[585]),/* "setct-CapRevResTBE" */
-&(nid_objs[538]),/* "setct-CapTokenData" */
-&(nid_objs[530]),/* "setct-CapTokenSeq" */
-&(nid_objs[574]),/* "setct-CapTokenTBE" */
-&(nid_objs[575]),/* "setct-CapTokenTBEX" */
-&(nid_objs[539]),/* "setct-CapTokenTBS" */
-&(nid_objs[560]),/* "setct-CardCInitResTBS" */
-&(nid_objs[566]),/* "setct-CertInqReqTBS" */
-&(nid_objs[563]),/* "setct-CertReqData" */
-&(nid_objs[595]),/* "setct-CertReqTBE" */
-&(nid_objs[596]),/* "setct-CertReqTBEX" */
-&(nid_objs[564]),/* "setct-CertReqTBS" */
-&(nid_objs[565]),/* "setct-CertResData" */
-&(nid_objs[597]),/* "setct-CertResTBE" */
-&(nid_objs[586]),/* "setct-CredReqTBE" */
-&(nid_objs[587]),/* "setct-CredReqTBEX" */
-&(nid_objs[550]),/* "setct-CredReqTBS" */
-&(nid_objs[551]),/* "setct-CredReqTBSX" */
-&(nid_objs[552]),/* "setct-CredResData" */
-&(nid_objs[588]),/* "setct-CredResTBE" */
-&(nid_objs[589]),/* "setct-CredRevReqTBE" */
-&(nid_objs[590]),/* "setct-CredRevReqTBEX" */
-&(nid_objs[553]),/* "setct-CredRevReqTBS" */
-&(nid_objs[554]),/* "setct-CredRevReqTBSX" */
-&(nid_objs[555]),/* "setct-CredRevResData" */
-&(nid_objs[591]),/* "setct-CredRevResTBE" */
-&(nid_objs[567]),/* "setct-ErrorTBS" */
-&(nid_objs[526]),/* "setct-HODInput" */
-&(nid_objs[561]),/* "setct-MeAqCInitResTBS" */
-&(nid_objs[522]),/* "setct-OIData" */
-&(nid_objs[519]),/* "setct-PANData" */
-&(nid_objs[521]),/* "setct-PANOnly" */
-&(nid_objs[520]),/* "setct-PANToken" */
-&(nid_objs[556]),/* "setct-PCertReqData" */
-&(nid_objs[557]),/* "setct-PCertResTBS" */
-&(nid_objs[523]),/* "setct-PI" */
-&(nid_objs[532]),/* "setct-PI-TBS" */
-&(nid_objs[524]),/* "setct-PIData" */
-&(nid_objs[525]),/* "setct-PIDataUnsigned" */
-&(nid_objs[568]),/* "setct-PIDualSignedTBE" */
-&(nid_objs[569]),/* "setct-PIUnsignedTBE" */
-&(nid_objs[531]),/* "setct-PInitResData" */
-&(nid_objs[533]),/* "setct-PResData" */
-&(nid_objs[594]),/* "setct-RegFormReqTBE" */
-&(nid_objs[562]),/* "setct-RegFormResTBS" */
-&(nid_objs[606]),/* "setext-cv" */
-&(nid_objs[601]),/* "setext-genCrypt" */
-&(nid_objs[602]),/* "setext-miAuth" */
-&(nid_objs[604]),/* "setext-pinAny" */
-&(nid_objs[603]),/* "setext-pinSecure" */
-&(nid_objs[605]),/* "setext-track2" */
-&(nid_objs[52]),/* "signingTime" */
-&(nid_objs[454]),/* "simpleSecurityObject" */
-&(nid_objs[496]),/* "singleLevelQuality" */
-&(nid_objs[387]),/* "snmpv2" */
-&(nid_objs[660]),/* "street" */
-&(nid_objs[85]),/* "subjectAltName" */
-&(nid_objs[769]),/* "subjectDirectoryAttributes" */
-&(nid_objs[398]),/* "subjectInfoAccess" */
-&(nid_objs[82]),/* "subjectKeyIdentifier" */
-&(nid_objs[498]),/* "subtreeMaximumQuality" */
-&(nid_objs[497]),/* "subtreeMinimumQuality" */
-&(nid_objs[890]),/* "supportedAlgorithms" */
-&(nid_objs[874]),/* "supportedApplicationContext" */
-&(nid_objs[402]),/* "targetInformation" */
-&(nid_objs[864]),/* "telephoneNumber" */
-&(nid_objs[866]),/* "teletexTerminalIdentifier" */
-&(nid_objs[865]),/* "telexNumber" */
-&(nid_objs[459]),/* "textEncodedORAddress" */
-&(nid_objs[293]),/* "textNotice" */
-&(nid_objs[133]),/* "timeStamping" */
-&(nid_objs[106]),/* "title" */
-&(nid_objs[682]),/* "tpBasis" */
-&(nid_objs[375]),/* "trustRoot" */
-&(nid_objs[436]),/* "ucl" */
-&(nid_objs[888]),/* "uniqueMember" */
-&(nid_objs[55]),/* "unstructuredAddress" */
-&(nid_objs[49]),/* "unstructuredName" */
-&(nid_objs[880]),/* "userCertificate" */
-&(nid_objs[465]),/* "userClass" */
-&(nid_objs[879]),/* "userPassword" */
-&(nid_objs[373]),/* "valid" */
-&(nid_objs[678]),/* "wap" */
-&(nid_objs[679]),/* "wap-wsg" */
-&(nid_objs[735]),/* "wap-wsg-idm-ecid-wtls1" */
-&(nid_objs[743]),/* "wap-wsg-idm-ecid-wtls10" */
-&(nid_objs[744]),/* "wap-wsg-idm-ecid-wtls11" */
-&(nid_objs[745]),/* "wap-wsg-idm-ecid-wtls12" */
-&(nid_objs[736]),/* "wap-wsg-idm-ecid-wtls3" */
-&(nid_objs[737]),/* "wap-wsg-idm-ecid-wtls4" */
-&(nid_objs[738]),/* "wap-wsg-idm-ecid-wtls5" */
-&(nid_objs[739]),/* "wap-wsg-idm-ecid-wtls6" */
-&(nid_objs[740]),/* "wap-wsg-idm-ecid-wtls7" */
-&(nid_objs[741]),/* "wap-wsg-idm-ecid-wtls8" */
-&(nid_objs[742]),/* "wap-wsg-idm-ecid-wtls9" */
-&(nid_objs[804]),/* "whirlpool" */
-&(nid_objs[868]),/* "x121Address" */
-&(nid_objs[503]),/* "x500UniqueIdentifier" */
-&(nid_objs[158]),/* "x509Certificate" */
-&(nid_objs[160]),/* "x509Crl" */
+static const unsigned int sn_objs[NUM_SN]={
+364,   /* "AD_DVCS" */
+419,   /* "AES-128-CBC" */
+421,   /* "AES-128-CFB" */
+650,   /* "AES-128-CFB1" */
+653,   /* "AES-128-CFB8" */
+418,   /* "AES-128-ECB" */
+420,   /* "AES-128-OFB" */
+423,   /* "AES-192-CBC" */
+425,   /* "AES-192-CFB" */
+651,   /* "AES-192-CFB1" */
+654,   /* "AES-192-CFB8" */
+422,   /* "AES-192-ECB" */
+424,   /* "AES-192-OFB" */
+427,   /* "AES-256-CBC" */
+429,   /* "AES-256-CFB" */
+652,   /* "AES-256-CFB1" */
+655,   /* "AES-256-CFB8" */
+426,   /* "AES-256-ECB" */
+428,   /* "AES-256-OFB" */
+91,    /* "BF-CBC" */
+93,    /* "BF-CFB" */
+92,    /* "BF-ECB" */
+94,    /* "BF-OFB" */
+14,    /* "C" */
+751,   /* "CAMELLIA-128-CBC" */
+757,   /* "CAMELLIA-128-CFB" */
+760,   /* "CAMELLIA-128-CFB1" */
+763,   /* "CAMELLIA-128-CFB8" */
+754,   /* "CAMELLIA-128-ECB" */
+766,   /* "CAMELLIA-128-OFB" */
+752,   /* "CAMELLIA-192-CBC" */
+758,   /* "CAMELLIA-192-CFB" */
+761,   /* "CAMELLIA-192-CFB1" */
+764,   /* "CAMELLIA-192-CFB8" */
+755,   /* "CAMELLIA-192-ECB" */
+767,   /* "CAMELLIA-192-OFB" */
+753,   /* "CAMELLIA-256-CBC" */
+759,   /* "CAMELLIA-256-CFB" */
+762,   /* "CAMELLIA-256-CFB1" */
+765,   /* "CAMELLIA-256-CFB8" */
+756,   /* "CAMELLIA-256-ECB" */
+768,   /* "CAMELLIA-256-OFB" */
+108,   /* "CAST5-CBC" */
+110,   /* "CAST5-CFB" */
+109,   /* "CAST5-ECB" */
+111,   /* "CAST5-OFB" */
+13,    /* "CN" */
+141,   /* "CRLReason" */
+417,   /* "CSPName" */
+367,   /* "CrlID" */
+391,   /* "DC" */
+31,    /* "DES-CBC" */
+643,   /* "DES-CDMF" */
+30,    /* "DES-CFB" */
+656,   /* "DES-CFB1" */
+657,   /* "DES-CFB8" */
+29,    /* "DES-ECB" */
+32,    /* "DES-EDE" */
+43,    /* "DES-EDE-CBC" */
+60,    /* "DES-EDE-CFB" */
+62,    /* "DES-EDE-OFB" */
+33,    /* "DES-EDE3" */
+44,    /* "DES-EDE3-CBC" */
+61,    /* "DES-EDE3-CFB" */
+658,   /* "DES-EDE3-CFB1" */
+659,   /* "DES-EDE3-CFB8" */
+63,    /* "DES-EDE3-OFB" */
+45,    /* "DES-OFB" */
+80,    /* "DESX-CBC" */
+380,   /* "DOD" */
+116,   /* "DSA" */
+66,    /* "DSA-SHA" */
+113,   /* "DSA-SHA1" */
+70,    /* "DSA-SHA1-old" */
+67,    /* "DSA-old" */
+297,   /* "DVCS" */
+99,    /* "GN" */
+855,   /* "HMAC" */
+780,   /* "HMAC-MD5" */
+781,   /* "HMAC-SHA1" */
+381,   /* "IANA" */
+34,    /* "IDEA-CBC" */
+35,    /* "IDEA-CFB" */
+36,    /* "IDEA-ECB" */
+46,    /* "IDEA-OFB" */
+181,   /* "ISO" */
+183,   /* "ISO-US" */
+645,   /* "ITU-T" */
+646,   /* "JOINT-ISO-ITU-T" */
+773,   /* "KISA" */
+15,    /* "L" */
+856,   /* "LocalKeySet" */
+ 3,    /* "MD2" */
+257,   /* "MD4" */
+ 4,    /* "MD5" */
+114,   /* "MD5-SHA1" */
+95,    /* "MDC2" */
+388,   /* "Mail" */
+393,   /* "NULL" */
+404,   /* "NULL" */
+57,    /* "Netscape" */
+366,   /* "Nonce" */
+17,    /* "O" */
+178,   /* "OCSP" */
+180,   /* "OCSPSigning" */
+379,   /* "ORG" */
+18,    /* "OU" */
+749,   /* "Oakley-EC2N-3" */
+750,   /* "Oakley-EC2N-4" */
+ 9,    /* "PBE-MD2-DES" */
+168,   /* "PBE-MD2-RC2-64" */
+10,    /* "PBE-MD5-DES" */
+169,   /* "PBE-MD5-RC2-64" */
+147,   /* "PBE-SHA1-2DES" */
+146,   /* "PBE-SHA1-3DES" */
+170,   /* "PBE-SHA1-DES" */
+148,   /* "PBE-SHA1-RC2-128" */
+149,   /* "PBE-SHA1-RC2-40" */
+68,    /* "PBE-SHA1-RC2-64" */
+144,   /* "PBE-SHA1-RC4-128" */
+145,   /* "PBE-SHA1-RC4-40" */
+161,   /* "PBES2" */
+69,    /* "PBKDF2" */
+162,   /* "PBMAC1" */
+127,   /* "PKIX" */
+98,    /* "RC2-40-CBC" */
+166,   /* "RC2-64-CBC" */
+37,    /* "RC2-CBC" */
+39,    /* "RC2-CFB" */
+38,    /* "RC2-ECB" */
+40,    /* "RC2-OFB" */
+ 5,    /* "RC4" */
+97,    /* "RC4-40" */
+120,   /* "RC5-CBC" */
+122,   /* "RC5-CFB" */
+121,   /* "RC5-ECB" */
+123,   /* "RC5-OFB" */
+117,   /* "RIPEMD160" */
+124,   /* "RLE" */
+19,    /* "RSA" */
+ 7,    /* "RSA-MD2" */
+396,   /* "RSA-MD4" */
+ 8,    /* "RSA-MD5" */
+96,    /* "RSA-MDC2" */
+104,   /* "RSA-NP-MD5" */
+119,   /* "RSA-RIPEMD160" */
+42,    /* "RSA-SHA" */
+65,    /* "RSA-SHA1" */
+115,   /* "RSA-SHA1-2" */
+671,   /* "RSA-SHA224" */
+668,   /* "RSA-SHA256" */
+669,   /* "RSA-SHA384" */
+670,   /* "RSA-SHA512" */
+777,   /* "SEED-CBC" */
+779,   /* "SEED-CFB" */
+776,   /* "SEED-ECB" */
+778,   /* "SEED-OFB" */
+41,    /* "SHA" */
+64,    /* "SHA1" */
+675,   /* "SHA224" */
+672,   /* "SHA256" */
+673,   /* "SHA384" */
+674,   /* "SHA512" */
+188,   /* "SMIME" */
+167,   /* "SMIME-CAPS" */
+100,   /* "SN" */
+16,    /* "ST" */
+143,   /* "SXNetID" */
+458,   /* "UID" */
+ 0,    /* "UNDEF" */
+11,    /* "X500" */
+378,   /* "X500algorithms" */
+12,    /* "X509" */
+184,   /* "X9-57" */
+185,   /* "X9cm" */
+125,   /* "ZLIB" */
+478,   /* "aRecord" */
+289,   /* "aaControls" */
+287,   /* "ac-auditEntity" */
+397,   /* "ac-proxying" */
+288,   /* "ac-targeting" */
+368,   /* "acceptableResponses" */
+446,   /* "account" */
+363,   /* "ad_timestamping" */
+376,   /* "algorithm" */
+405,   /* "ansi-X9-62" */
+746,   /* "anyPolicy" */
+370,   /* "archiveCutoff" */
+484,   /* "associatedDomain" */
+485,   /* "associatedName" */
+501,   /* "audio" */
+177,   /* "authorityInfoAccess" */
+90,    /* "authorityKeyIdentifier" */
+882,   /* "authorityRevocationList" */
+87,    /* "basicConstraints" */
+365,   /* "basicOCSPResponse" */
+285,   /* "biometricInfo" */
+494,   /* "buildingName" */
+860,   /* "businessCategory" */
+691,   /* "c2onb191v4" */
+692,   /* "c2onb191v5" */
+697,   /* "c2onb239v4" */
+698,   /* "c2onb239v5" */
+684,   /* "c2pnb163v1" */
+685,   /* "c2pnb163v2" */
+686,   /* "c2pnb163v3" */
+687,   /* "c2pnb176v1" */
+693,   /* "c2pnb208w1" */
+699,   /* "c2pnb272w1" */
+700,   /* "c2pnb304w1" */
+702,   /* "c2pnb368w1" */
+688,   /* "c2tnb191v1" */
+689,   /* "c2tnb191v2" */
+690,   /* "c2tnb191v3" */
+694,   /* "c2tnb239v1" */
+695,   /* "c2tnb239v2" */
+696,   /* "c2tnb239v3" */
+701,   /* "c2tnb359v1" */
+703,   /* "c2tnb431r1" */
+881,   /* "cACertificate" */
+483,   /* "cNAMERecord" */
+179,   /* "caIssuers" */
+785,   /* "caRepository" */
+443,   /* "caseIgnoreIA5StringSyntax" */
+152,   /* "certBag" */
+677,   /* "certicom-arc" */
+771,   /* "certificateIssuer" */
+89,    /* "certificatePolicies" */
+883,   /* "certificateRevocationList" */
+54,    /* "challengePassword" */
+407,   /* "characteristic-two-field" */
+395,   /* "clearance" */
+130,   /* "clientAuth" */
+131,   /* "codeSigning" */
+50,    /* "contentType" */
+53,    /* "countersignature" */
+153,   /* "crlBag" */
+103,   /* "crlDistributionPoints" */
+88,    /* "crlNumber" */
+884,   /* "crossCertificatePair" */
+806,   /* "cryptocom" */
+805,   /* "cryptopro" */
+500,   /* "dITRedirect" */
+451,   /* "dNSDomain" */
+495,   /* "dSAQuality" */
+434,   /* "data" */
+390,   /* "dcobject" */
+140,   /* "deltaCRL" */
+891,   /* "deltaRevocationList" */
+107,   /* "description" */
+871,   /* "destinationIndicator" */
+28,    /* "dhKeyAgreement" */
+382,   /* "directory" */
+887,   /* "distinguishedName" */
+892,   /* "dmdName" */
+174,   /* "dnQualifier" */
+447,   /* "document" */
+471,   /* "documentAuthor" */
+468,   /* "documentIdentifier" */
+472,   /* "documentLocation" */
+502,   /* "documentPublisher" */
+449,   /* "documentSeries" */
+469,   /* "documentTitle" */
+470,   /* "documentVersion" */
+392,   /* "domain" */
+452,   /* "domainRelatedObject" */
+802,   /* "dsa_with_SHA224" */
+803,   /* "dsa_with_SHA256" */
+791,   /* "ecdsa-with-Recommended" */
+416,   /* "ecdsa-with-SHA1" */
+793,   /* "ecdsa-with-SHA224" */
+794,   /* "ecdsa-with-SHA256" */
+795,   /* "ecdsa-with-SHA384" */
+796,   /* "ecdsa-with-SHA512" */
+792,   /* "ecdsa-with-Specified" */
+48,    /* "emailAddress" */
+132,   /* "emailProtection" */
+885,   /* "enhancedSearchGuide" */
+389,   /* "enterprises" */
+384,   /* "experimental" */
+172,   /* "extReq" */
+56,    /* "extendedCertificateAttributes" */
+126,   /* "extendedKeyUsage" */
+372,   /* "extendedStatus" */
+867,   /* "facsimileTelephoneNumber" */
+462,   /* "favouriteDrink" */
+857,   /* "freshestCRL" */
+453,   /* "friendlyCountry" */
+490,   /* "friendlyCountryName" */
+156,   /* "friendlyName" */
+509,   /* "generationQualifier" */
+815,   /* "gost-mac" */
+811,   /* "gost2001" */
+851,   /* "gost2001cc" */
+813,   /* "gost89" */
+814,   /* "gost89-cnt" */
+812,   /* "gost94" */
+850,   /* "gost94cc" */
+797,   /* "hmacWithMD5" */
+163,   /* "hmacWithSHA1" */
+798,   /* "hmacWithSHA224" */
+799,   /* "hmacWithSHA256" */
+800,   /* "hmacWithSHA384" */
+801,   /* "hmacWithSHA512" */
+432,   /* "holdInstructionCallIssuer" */
+430,   /* "holdInstructionCode" */
+431,   /* "holdInstructionNone" */
+433,   /* "holdInstructionReject" */
+486,   /* "homePostalAddress" */
+473,   /* "homeTelephoneNumber" */
+466,   /* "host" */
+889,   /* "houseIdentifier" */
+442,   /* "iA5StringSyntax" */
+783,   /* "id-DHBasedMac" */
+824,   /* "id-Gost28147-89-CryptoPro-A-ParamSet" */
+825,   /* "id-Gost28147-89-CryptoPro-B-ParamSet" */
+826,   /* "id-Gost28147-89-CryptoPro-C-ParamSet" */
+827,   /* "id-Gost28147-89-CryptoPro-D-ParamSet" */
+819,   /* "id-Gost28147-89-CryptoPro-KeyMeshing" */
+829,   /* "id-Gost28147-89-CryptoPro-Oscar-1-0-ParamSet" */
+828,   /* "id-Gost28147-89-CryptoPro-Oscar-1-1-ParamSet" */
+830,   /* "id-Gost28147-89-CryptoPro-RIC-1-ParamSet" */
+820,   /* "id-Gost28147-89-None-KeyMeshing" */
+823,   /* "id-Gost28147-89-TestParamSet" */
+849,   /* "id-Gost28147-89-cc" */
+840,   /* "id-GostR3410-2001-CryptoPro-A-ParamSet" */
+841,   /* "id-GostR3410-2001-CryptoPro-B-ParamSet" */
+842,   /* "id-GostR3410-2001-CryptoPro-C-ParamSet" */
+843,   /* "id-GostR3410-2001-CryptoPro-XchA-ParamSet" */
+844,   /* "id-GostR3410-2001-CryptoPro-XchB-ParamSet" */
+854,   /* "id-GostR3410-2001-ParamSet-cc" */
+839,   /* "id-GostR3410-2001-TestParamSet" */
+817,   /* "id-GostR3410-2001DH" */
+832,   /* "id-GostR3410-94-CryptoPro-A-ParamSet" */
+833,   /* "id-GostR3410-94-CryptoPro-B-ParamSet" */
+834,   /* "id-GostR3410-94-CryptoPro-C-ParamSet" */
+835,   /* "id-GostR3410-94-CryptoPro-D-ParamSet" */
+836,   /* "id-GostR3410-94-CryptoPro-XchA-ParamSet" */
+837,   /* "id-GostR3410-94-CryptoPro-XchB-ParamSet" */
+838,   /* "id-GostR3410-94-CryptoPro-XchC-ParamSet" */
+831,   /* "id-GostR3410-94-TestParamSet" */
+845,   /* "id-GostR3410-94-a" */
+846,   /* "id-GostR3410-94-aBis" */
+847,   /* "id-GostR3410-94-b" */
+848,   /* "id-GostR3410-94-bBis" */
+818,   /* "id-GostR3410-94DH" */
+822,   /* "id-GostR3411-94-CryptoProParamSet" */
+821,   /* "id-GostR3411-94-TestParamSet" */
+807,   /* "id-GostR3411-94-with-GostR3410-2001" */
+853,   /* "id-GostR3411-94-with-GostR3410-2001-cc" */
+808,   /* "id-GostR3411-94-with-GostR3410-94" */
+852,   /* "id-GostR3411-94-with-GostR3410-94-cc" */
+810,   /* "id-HMACGostR3411-94" */
+782,   /* "id-PasswordBasedMAC" */
+266,   /* "id-aca" */
+355,   /* "id-aca-accessIdentity" */
+354,   /* "id-aca-authenticationInfo" */
+356,   /* "id-aca-chargingIdentity" */
+399,   /* "id-aca-encAttrs" */
+357,   /* "id-aca-group" */
+358,   /* "id-aca-role" */
+176,   /* "id-ad" */
+788,   /* "id-aes128-wrap" */
+789,   /* "id-aes192-wrap" */
+790,   /* "id-aes256-wrap" */
+262,   /* "id-alg" */
+323,   /* "id-alg-des40" */
+326,   /* "id-alg-dh-pop" */
+325,   /* "id-alg-dh-sig-hmac-sha1" */
+324,   /* "id-alg-noSignature" */
+268,   /* "id-cct" */
+361,   /* "id-cct-PKIData" */
+362,   /* "id-cct-PKIResponse" */
+360,   /* "id-cct-crs" */
+81,    /* "id-ce" */
+680,   /* "id-characteristic-two-basis" */
+263,   /* "id-cmc" */
+334,   /* "id-cmc-addExtensions" */
+346,   /* "id-cmc-confirmCertAcceptance" */
+330,   /* "id-cmc-dataReturn" */
+336,   /* "id-cmc-decryptedPOP" */
+335,   /* "id-cmc-encryptedPOP" */
+339,   /* "id-cmc-getCRL" */
+338,   /* "id-cmc-getCert" */
+328,   /* "id-cmc-identification" */
+329,   /* "id-cmc-identityProof" */
+337,   /* "id-cmc-lraPOPWitness" */
+344,   /* "id-cmc-popLinkRandom" */
+345,   /* "id-cmc-popLinkWitness" */
+343,   /* "id-cmc-queryPending" */
+333,   /* "id-cmc-recipientNonce" */
+341,   /* "id-cmc-regInfo" */
+342,   /* "id-cmc-responseInfo" */
+340,   /* "id-cmc-revokeRequest" */
+332,   /* "id-cmc-senderNonce" */
+327,   /* "id-cmc-statusInfo" */
+331,   /* "id-cmc-transactionId" */
+787,   /* "id-ct-asciiTextWithCRLF" */
+408,   /* "id-ecPublicKey" */
+508,   /* "id-hex-multipart-message" */
+507,   /* "id-hex-partial-message" */
+260,   /* "id-it" */
+302,   /* "id-it-caKeyUpdateInfo" */
+298,   /* "id-it-caProtEncCert" */
+311,   /* "id-it-confirmWaitTime" */
+303,   /* "id-it-currentCRL" */
+300,   /* "id-it-encKeyPairTypes" */
+310,   /* "id-it-implicitConfirm" */
+308,   /* "id-it-keyPairParamRep" */
+307,   /* "id-it-keyPairParamReq" */
+312,   /* "id-it-origPKIMessage" */
+301,   /* "id-it-preferredSymmAlg" */
+309,   /* "id-it-revPassphrase" */
+299,   /* "id-it-signKeyPairTypes" */
+305,   /* "id-it-subscriptionRequest" */
+306,   /* "id-it-subscriptionResponse" */
+784,   /* "id-it-suppLangTags" */
+304,   /* "id-it-unsupportedOIDs" */
+128,   /* "id-kp" */
+280,   /* "id-mod-attribute-cert" */
+274,   /* "id-mod-cmc" */
+277,   /* "id-mod-cmp" */
+284,   /* "id-mod-cmp2000" */
+273,   /* "id-mod-crmf" */
+283,   /* "id-mod-dvcs" */
+275,   /* "id-mod-kea-profile-88" */
+276,   /* "id-mod-kea-profile-93" */
+282,   /* "id-mod-ocsp" */
+278,   /* "id-mod-qualified-cert-88" */
+279,   /* "id-mod-qualified-cert-93" */
+281,   /* "id-mod-timestamp-protocol" */
+264,   /* "id-on" */
+858,   /* "id-on-permanentIdentifier" */
+347,   /* "id-on-personalData" */
+265,   /* "id-pda" */
+352,   /* "id-pda-countryOfCitizenship" */
+353,   /* "id-pda-countryOfResidence" */
+348,   /* "id-pda-dateOfBirth" */
+351,   /* "id-pda-gender" */
+349,   /* "id-pda-placeOfBirth" */
+175,   /* "id-pe" */
+261,   /* "id-pkip" */
+258,   /* "id-pkix-mod" */
+269,   /* "id-pkix1-explicit-88" */
+271,   /* "id-pkix1-explicit-93" */
+270,   /* "id-pkix1-implicit-88" */
+272,   /* "id-pkix1-implicit-93" */
+662,   /* "id-ppl" */
+664,   /* "id-ppl-anyLanguage" */
+667,   /* "id-ppl-independent" */
+665,   /* "id-ppl-inheritAll" */
+267,   /* "id-qcs" */
+359,   /* "id-qcs-pkixQCSyntax-v1" */
+259,   /* "id-qt" */
+164,   /* "id-qt-cps" */
+165,   /* "id-qt-unotice" */
+313,   /* "id-regCtrl" */
+316,   /* "id-regCtrl-authenticator" */
+319,   /* "id-regCtrl-oldCertID" */
+318,   /* "id-regCtrl-pkiArchiveOptions" */
+317,   /* "id-regCtrl-pkiPublicationInfo" */
+320,   /* "id-regCtrl-protocolEncrKey" */
+315,   /* "id-regCtrl-regToken" */
+314,   /* "id-regInfo" */
+322,   /* "id-regInfo-certReq" */
+321,   /* "id-regInfo-utf8Pairs" */
+512,   /* "id-set" */
+191,   /* "id-smime-aa" */
+215,   /* "id-smime-aa-contentHint" */
+218,   /* "id-smime-aa-contentIdentifier" */
+221,   /* "id-smime-aa-contentReference" */
+240,   /* "id-smime-aa-dvcs-dvc" */
+217,   /* "id-smime-aa-encapContentType" */
+222,   /* "id-smime-aa-encrypKeyPref" */
+220,   /* "id-smime-aa-equivalentLabels" */
+232,   /* "id-smime-aa-ets-CertificateRefs" */
+233,   /* "id-smime-aa-ets-RevocationRefs" */
+238,   /* "id-smime-aa-ets-archiveTimeStamp" */
+237,   /* "id-smime-aa-ets-certCRLTimestamp" */
+234,   /* "id-smime-aa-ets-certValues" */
+227,   /* "id-smime-aa-ets-commitmentType" */
+231,   /* "id-smime-aa-ets-contentTimestamp" */
+236,   /* "id-smime-aa-ets-escTimeStamp" */
+230,   /* "id-smime-aa-ets-otherSigCert" */
+235,   /* "id-smime-aa-ets-revocationValues" */
+226,   /* "id-smime-aa-ets-sigPolicyId" */
+229,   /* "id-smime-aa-ets-signerAttr" */
+228,   /* "id-smime-aa-ets-signerLocation" */
+219,   /* "id-smime-aa-macValue" */
+214,   /* "id-smime-aa-mlExpandHistory" */
+216,   /* "id-smime-aa-msgSigDigest" */
+212,   /* "id-smime-aa-receiptRequest" */
+213,   /* "id-smime-aa-securityLabel" */
+239,   /* "id-smime-aa-signatureType" */
+223,   /* "id-smime-aa-signingCertificate" */
+224,   /* "id-smime-aa-smimeEncryptCerts" */
+225,   /* "id-smime-aa-timeStampToken" */
+192,   /* "id-smime-alg" */
+243,   /* "id-smime-alg-3DESwrap" */
+246,   /* "id-smime-alg-CMS3DESwrap" */
+247,   /* "id-smime-alg-CMSRC2wrap" */
+245,   /* "id-smime-alg-ESDH" */
+241,   /* "id-smime-alg-ESDHwith3DES" */
+242,   /* "id-smime-alg-ESDHwithRC2" */
+244,   /* "id-smime-alg-RC2wrap" */
+193,   /* "id-smime-cd" */
+248,   /* "id-smime-cd-ldap" */
+190,   /* "id-smime-ct" */
+210,   /* "id-smime-ct-DVCSRequestData" */
+211,   /* "id-smime-ct-DVCSResponseData" */
+208,   /* "id-smime-ct-TDTInfo" */
+207,   /* "id-smime-ct-TSTInfo" */
+205,   /* "id-smime-ct-authData" */
+786,   /* "id-smime-ct-compressedData" */
+209,   /* "id-smime-ct-contentInfo" */
+206,   /* "id-smime-ct-publishCert" */
+204,   /* "id-smime-ct-receipt" */
+195,   /* "id-smime-cti" */
+255,   /* "id-smime-cti-ets-proofOfApproval" */
+256,   /* "id-smime-cti-ets-proofOfCreation" */
+253,   /* "id-smime-cti-ets-proofOfDelivery" */
+251,   /* "id-smime-cti-ets-proofOfOrigin" */
+252,   /* "id-smime-cti-ets-proofOfReceipt" */
+254,   /* "id-smime-cti-ets-proofOfSender" */
+189,   /* "id-smime-mod" */
+196,   /* "id-smime-mod-cms" */
+197,   /* "id-smime-mod-ess" */
+202,   /* "id-smime-mod-ets-eSigPolicy-88" */
+203,   /* "id-smime-mod-ets-eSigPolicy-97" */
+200,   /* "id-smime-mod-ets-eSignature-88" */
+201,   /* "id-smime-mod-ets-eSignature-97" */
+199,   /* "id-smime-mod-msg-v3" */
+198,   /* "id-smime-mod-oid" */
+194,   /* "id-smime-spq" */
+250,   /* "id-smime-spq-ets-sqt-unotice" */
+249,   /* "id-smime-spq-ets-sqt-uri" */
+676,   /* "identified-organization" */
+461,   /* "info" */
+748,   /* "inhibitAnyPolicy" */
+101,   /* "initials" */
+647,   /* "international-organizations" */
+869,   /* "internationaliSDNNumber" */
+142,   /* "invalidityDate" */
+294,   /* "ipsecEndSystem" */
+295,   /* "ipsecTunnel" */
+296,   /* "ipsecUser" */
+86,    /* "issuerAltName" */
+770,   /* "issuingDistributionPoint" */
+492,   /* "janetMailbox" */
+150,   /* "keyBag" */
+83,    /* "keyUsage" */
+477,   /* "lastModifiedBy" */
+476,   /* "lastModifiedTime" */
+157,   /* "localKeyID" */
+480,   /* "mXRecord" */
+460,   /* "mail" */
+493,   /* "mailPreferenceOption" */
+467,   /* "manager" */
+809,   /* "md_gost94" */
+875,   /* "member" */
+182,   /* "member-body" */
+51,    /* "messageDigest" */
+383,   /* "mgmt" */
+504,   /* "mime-mhs" */
+506,   /* "mime-mhs-bodies" */
+505,   /* "mime-mhs-headings" */
+488,   /* "mobileTelephoneNumber" */
+136,   /* "msCTLSign" */
+135,   /* "msCodeCom" */
+134,   /* "msCodeInd" */
+138,   /* "msEFS" */
+171,   /* "msExtReq" */
+137,   /* "msSGC" */
+648,   /* "msSmartcardLogin" */
+649,   /* "msUPN" */
+481,   /* "nSRecord" */
+173,   /* "name" */
+666,   /* "nameConstraints" */
+369,   /* "noCheck" */
+403,   /* "noRevAvail" */
+72,    /* "nsBaseUrl" */
+76,    /* "nsCaPolicyUrl" */
+74,    /* "nsCaRevocationUrl" */
+58,    /* "nsCertExt" */
+79,    /* "nsCertSequence" */
+71,    /* "nsCertType" */
+78,    /* "nsComment" */
+59,    /* "nsDataType" */
+75,    /* "nsRenewalUrl" */
+73,    /* "nsRevocationUrl" */
+139,   /* "nsSGC" */
+77,    /* "nsSslServerName" */
+681,   /* "onBasis" */
+491,   /* "organizationalStatus" */
+475,   /* "otherMailbox" */
+876,   /* "owner" */
+489,   /* "pagerTelephoneNumber" */
+374,   /* "path" */
+112,   /* "pbeWithMD5AndCast5CBC" */
+499,   /* "personalSignature" */
+487,   /* "personalTitle" */
+464,   /* "photo" */
+863,   /* "physicalDeliveryOfficeName" */
+437,   /* "pilot" */
+439,   /* "pilotAttributeSyntax" */
+438,   /* "pilotAttributeType" */
+479,   /* "pilotAttributeType27" */
+456,   /* "pilotDSA" */
+441,   /* "pilotGroups" */
+444,   /* "pilotObject" */
+440,   /* "pilotObjectClass" */
+455,   /* "pilotOrganization" */
+445,   /* "pilotPerson" */
+ 2,    /* "pkcs" */
+186,   /* "pkcs1" */
+27,    /* "pkcs3" */
+187,   /* "pkcs5" */
+20,    /* "pkcs7" */
+21,    /* "pkcs7-data" */
+25,    /* "pkcs7-digestData" */
+26,    /* "pkcs7-encryptedData" */
+23,    /* "pkcs7-envelopedData" */
+24,    /* "pkcs7-signedAndEnvelopedData" */
+22,    /* "pkcs7-signedData" */
+151,   /* "pkcs8ShroudedKeyBag" */
+47,    /* "pkcs9" */
+401,   /* "policyConstraints" */
+747,   /* "policyMappings" */
+862,   /* "postOfficeBox" */
+861,   /* "postalAddress" */
+661,   /* "postalCode" */
+683,   /* "ppBasis" */
+872,   /* "preferredDeliveryMethod" */
+873,   /* "presentationAddress" */
+816,   /* "prf-gostr3411-94" */
+406,   /* "prime-field" */
+409,   /* "prime192v1" */
+410,   /* "prime192v2" */
+411,   /* "prime192v3" */
+412,   /* "prime239v1" */
+413,   /* "prime239v2" */
+414,   /* "prime239v3" */
+415,   /* "prime256v1" */
+385,   /* "private" */
+84,    /* "privateKeyUsagePeriod" */
+886,   /* "protocolInformation" */
+663,   /* "proxyCertInfo" */
+510,   /* "pseudonym" */
+435,   /* "pss" */
+286,   /* "qcStatements" */
+457,   /* "qualityLabelledData" */
+450,   /* "rFC822localPart" */
+870,   /* "registeredAddress" */
+400,   /* "role" */
+877,   /* "roleOccupant" */
+448,   /* "room" */
+463,   /* "roomNumber" */
+ 6,    /* "rsaEncryption" */
+644,   /* "rsaOAEPEncryptionSET" */
+377,   /* "rsaSignature" */
+ 1,    /* "rsadsi" */
+482,   /* "sOARecord" */
+155,   /* "safeContentsBag" */
+291,   /* "sbgp-autonomousSysNum" */
+290,   /* "sbgp-ipAddrBlock" */
+292,   /* "sbgp-routerIdentifier" */
+159,   /* "sdsiCertificate" */
+859,   /* "searchGuide" */
+704,   /* "secp112r1" */
+705,   /* "secp112r2" */
+706,   /* "secp128r1" */
+707,   /* "secp128r2" */
+708,   /* "secp160k1" */
+709,   /* "secp160r1" */
+710,   /* "secp160r2" */
+711,   /* "secp192k1" */
+712,   /* "secp224k1" */
+713,   /* "secp224r1" */
+714,   /* "secp256k1" */
+715,   /* "secp384r1" */
+716,   /* "secp521r1" */
+154,   /* "secretBag" */
+474,   /* "secretary" */
+717,   /* "sect113r1" */
+718,   /* "sect113r2" */
+719,   /* "sect131r1" */
+720,   /* "sect131r2" */
+721,   /* "sect163k1" */
+722,   /* "sect163r1" */
+723,   /* "sect163r2" */
+724,   /* "sect193r1" */
+725,   /* "sect193r2" */
+726,   /* "sect233k1" */
+727,   /* "sect233r1" */
+728,   /* "sect239k1" */
+729,   /* "sect283k1" */
+730,   /* "sect283r1" */
+731,   /* "sect409k1" */
+732,   /* "sect409r1" */
+733,   /* "sect571k1" */
+734,   /* "sect571r1" */
+386,   /* "security" */
+878,   /* "seeAlso" */
+394,   /* "selected-attribute-types" */
+105,   /* "serialNumber" */
+129,   /* "serverAuth" */
+371,   /* "serviceLocator" */
+625,   /* "set-addPolicy" */
+515,   /* "set-attr" */
+518,   /* "set-brand" */
+638,   /* "set-brand-AmericanExpress" */
+637,   /* "set-brand-Diners" */
+636,   /* "set-brand-IATA-ATA" */
+639,   /* "set-brand-JCB" */
+641,   /* "set-brand-MasterCard" */
+642,   /* "set-brand-Novus" */
+640,   /* "set-brand-Visa" */
+517,   /* "set-certExt" */
+513,   /* "set-ctype" */
+514,   /* "set-msgExt" */
+516,   /* "set-policy" */
+607,   /* "set-policy-root" */
+624,   /* "set-rootKeyThumb" */
+620,   /* "setAttr-Cert" */
+631,   /* "setAttr-GenCryptgrm" */
+623,   /* "setAttr-IssCap" */
+628,   /* "setAttr-IssCap-CVM" */
+630,   /* "setAttr-IssCap-Sig" */
+629,   /* "setAttr-IssCap-T2" */
+621,   /* "setAttr-PGWYcap" */
+635,   /* "setAttr-SecDevSig" */
+632,   /* "setAttr-T2Enc" */
+633,   /* "setAttr-T2cleartxt" */
+634,   /* "setAttr-TokICCsig" */
+627,   /* "setAttr-Token-B0Prime" */
+626,   /* "setAttr-Token-EMV" */
+622,   /* "setAttr-TokenType" */
+619,   /* "setCext-IssuerCapabilities" */
+615,   /* "setCext-PGWYcapabilities" */
+616,   /* "setCext-TokenIdentifier" */
+618,   /* "setCext-TokenType" */
+617,   /* "setCext-Track2Data" */
+611,   /* "setCext-cCertRequired" */
+609,   /* "setCext-certType" */
+608,   /* "setCext-hashedRoot" */
+610,   /* "setCext-merchData" */
+613,   /* "setCext-setExt" */
+614,   /* "setCext-setQualf" */
+612,   /* "setCext-tunneling" */
+540,   /* "setct-AcqCardCodeMsg" */
+576,   /* "setct-AcqCardCodeMsgTBE" */
+570,   /* "setct-AuthReqTBE" */
+534,   /* "setct-AuthReqTBS" */
+527,   /* "setct-AuthResBaggage" */
+571,   /* "setct-AuthResTBE" */
+572,   /* "setct-AuthResTBEX" */
+535,   /* "setct-AuthResTBS" */
+536,   /* "setct-AuthResTBSX" */
+528,   /* "setct-AuthRevReqBaggage" */
+577,   /* "setct-AuthRevReqTBE" */
+541,   /* "setct-AuthRevReqTBS" */
+529,   /* "setct-AuthRevResBaggage" */
+542,   /* "setct-AuthRevResData" */
+578,   /* "setct-AuthRevResTBE" */
+579,   /* "setct-AuthRevResTBEB" */
+543,   /* "setct-AuthRevResTBS" */
+573,   /* "setct-AuthTokenTBE" */
+537,   /* "setct-AuthTokenTBS" */
+600,   /* "setct-BCIDistributionTBS" */
+558,   /* "setct-BatchAdminReqData" */
+592,   /* "setct-BatchAdminReqTBE" */
+559,   /* "setct-BatchAdminResData" */
+593,   /* "setct-BatchAdminResTBE" */
+599,   /* "setct-CRLNotificationResTBS" */
+598,   /* "setct-CRLNotificationTBS" */
+580,   /* "setct-CapReqTBE" */
+581,   /* "setct-CapReqTBEX" */
+544,   /* "setct-CapReqTBS" */
+545,   /* "setct-CapReqTBSX" */
+546,   /* "setct-CapResData" */
+582,   /* "setct-CapResTBE" */
+583,   /* "setct-CapRevReqTBE" */
+584,   /* "setct-CapRevReqTBEX" */
+547,   /* "setct-CapRevReqTBS" */
+548,   /* "setct-CapRevReqTBSX" */
+549,   /* "setct-CapRevResData" */
+585,   /* "setct-CapRevResTBE" */
+538,   /* "setct-CapTokenData" */
+530,   /* "setct-CapTokenSeq" */
+574,   /* "setct-CapTokenTBE" */
+575,   /* "setct-CapTokenTBEX" */
+539,   /* "setct-CapTokenTBS" */
+560,   /* "setct-CardCInitResTBS" */
+566,   /* "setct-CertInqReqTBS" */
+563,   /* "setct-CertReqData" */
+595,   /* "setct-CertReqTBE" */
+596,   /* "setct-CertReqTBEX" */
+564,   /* "setct-CertReqTBS" */
+565,   /* "setct-CertResData" */
+597,   /* "setct-CertResTBE" */
+586,   /* "setct-CredReqTBE" */
+587,   /* "setct-CredReqTBEX" */
+550,   /* "setct-CredReqTBS" */
+551,   /* "setct-CredReqTBSX" */
+552,   /* "setct-CredResData" */
+588,   /* "setct-CredResTBE" */
+589,   /* "setct-CredRevReqTBE" */
+590,   /* "setct-CredRevReqTBEX" */
+553,   /* "setct-CredRevReqTBS" */
+554,   /* "setct-CredRevReqTBSX" */
+555,   /* "setct-CredRevResData" */
+591,   /* "setct-CredRevResTBE" */
+567,   /* "setct-ErrorTBS" */
+526,   /* "setct-HODInput" */
+561,   /* "setct-MeAqCInitResTBS" */
+522,   /* "setct-OIData" */
+519,   /* "setct-PANData" */
+521,   /* "setct-PANOnly" */
+520,   /* "setct-PANToken" */
+556,   /* "setct-PCertReqData" */
+557,   /* "setct-PCertResTBS" */
+523,   /* "setct-PI" */
+532,   /* "setct-PI-TBS" */
+524,   /* "setct-PIData" */
+525,   /* "setct-PIDataUnsigned" */
+568,   /* "setct-PIDualSignedTBE" */
+569,   /* "setct-PIUnsignedTBE" */
+531,   /* "setct-PInitResData" */
+533,   /* "setct-PResData" */
+594,   /* "setct-RegFormReqTBE" */
+562,   /* "setct-RegFormResTBS" */
+606,   /* "setext-cv" */
+601,   /* "setext-genCrypt" */
+602,   /* "setext-miAuth" */
+604,   /* "setext-pinAny" */
+603,   /* "setext-pinSecure" */
+605,   /* "setext-track2" */
+52,    /* "signingTime" */
+454,   /* "simpleSecurityObject" */
+496,   /* "singleLevelQuality" */
+387,   /* "snmpv2" */
+660,   /* "street" */
+85,    /* "subjectAltName" */
+769,   /* "subjectDirectoryAttributes" */
+398,   /* "subjectInfoAccess" */
+82,    /* "subjectKeyIdentifier" */
+498,   /* "subtreeMaximumQuality" */
+497,   /* "subtreeMinimumQuality" */
+890,   /* "supportedAlgorithms" */
+874,   /* "supportedApplicationContext" */
+402,   /* "targetInformation" */
+864,   /* "telephoneNumber" */
+866,   /* "teletexTerminalIdentifier" */
+865,   /* "telexNumber" */
+459,   /* "textEncodedORAddress" */
+293,   /* "textNotice" */
+133,   /* "timeStamping" */
+106,   /* "title" */
+682,   /* "tpBasis" */
+375,   /* "trustRoot" */
+436,   /* "ucl" */
+888,   /* "uniqueMember" */
+55,    /* "unstructuredAddress" */
+49,    /* "unstructuredName" */
+880,   /* "userCertificate" */
+465,   /* "userClass" */
+879,   /* "userPassword" */
+373,   /* "valid" */
+678,   /* "wap" */
+679,   /* "wap-wsg" */
+735,   /* "wap-wsg-idm-ecid-wtls1" */
+743,   /* "wap-wsg-idm-ecid-wtls10" */
+744,   /* "wap-wsg-idm-ecid-wtls11" */
+745,   /* "wap-wsg-idm-ecid-wtls12" */
+736,   /* "wap-wsg-idm-ecid-wtls3" */
+737,   /* "wap-wsg-idm-ecid-wtls4" */
+738,   /* "wap-wsg-idm-ecid-wtls5" */
+739,   /* "wap-wsg-idm-ecid-wtls6" */
+740,   /* "wap-wsg-idm-ecid-wtls7" */
+741,   /* "wap-wsg-idm-ecid-wtls8" */
+742,   /* "wap-wsg-idm-ecid-wtls9" */
+804,   /* "whirlpool" */
+868,   /* "x121Address" */
+503,   /* "x500UniqueIdentifier" */
+158,   /* "x509Certificate" */
+160,   /* "x509Crl" */
 };
 
-static ASN1_OBJECT *ln_objs[NUM_LN]={
-&(nid_objs[363]),/* "AD Time Stamping" */
-&(nid_objs[405]),/* "ANSI X9.62" */
-&(nid_objs[368]),/* "Acceptable OCSP Responses" */
-&(nid_objs[664]),/* "Any language" */
-&(nid_objs[177]),/* "Authority Information Access" */
-&(nid_objs[365]),/* "Basic OCSP Response" */
-&(nid_objs[285]),/* "Biometric Info" */
-&(nid_objs[179]),/* "CA Issuers" */
-&(nid_objs[785]),/* "CA Repository" */
-&(nid_objs[131]),/* "Code Signing" */
-&(nid_objs[783]),/* "Diffie-Hellman based MAC" */
-&(nid_objs[382]),/* "Directory" */
-&(nid_objs[392]),/* "Domain" */
-&(nid_objs[132]),/* "E-mail Protection" */
-&(nid_objs[389]),/* "Enterprises" */
-&(nid_objs[384]),/* "Experimental" */
-&(nid_objs[372]),/* "Extended OCSP Status" */
-&(nid_objs[172]),/* "Extension Request" */
-&(nid_objs[813]),/* "GOST 28147-89" */
-&(nid_objs[849]),/* "GOST 28147-89 Cryptocom ParamSet" */
-&(nid_objs[815]),/* "GOST 28147-89 MAC" */
-&(nid_objs[851]),/* "GOST 34.10-2001 Cryptocom" */
-&(nid_objs[850]),/* "GOST 34.10-94 Cryptocom" */
-&(nid_objs[811]),/* "GOST R 34.10-2001" */
-&(nid_objs[817]),/* "GOST R 34.10-2001 DH" */
-&(nid_objs[812]),/* "GOST R 34.10-94" */
-&(nid_objs[818]),/* "GOST R 34.10-94 DH" */
-&(nid_objs[809]),/* "GOST R 34.11-94" */
-&(nid_objs[816]),/* "GOST R 34.11-94 PRF" */
-&(nid_objs[807]),/* "GOST R 34.11-94 with GOST R 34.10-2001" */
-&(nid_objs[853]),/* "GOST R 34.11-94 with GOST R 34.10-2001 Cryptocom" */
-&(nid_objs[808]),/* "GOST R 34.11-94 with GOST R 34.10-94" */
-&(nid_objs[852]),/* "GOST R 34.11-94 with GOST R 34.10-94 Cryptocom" */
-&(nid_objs[854]),/* "GOST R 3410-2001 Parameter Set Cryptocom" */
-&(nid_objs[810]),/* "HMAC GOST 34.11-94" */
-&(nid_objs[432]),/* "Hold Instruction Call Issuer" */
-&(nid_objs[430]),/* "Hold Instruction Code" */
-&(nid_objs[431]),/* "Hold Instruction None" */
-&(nid_objs[433]),/* "Hold Instruction Reject" */
-&(nid_objs[634]),/* "ICC or token signature" */
-&(nid_objs[294]),/* "IPSec End System" */
-&(nid_objs[295]),/* "IPSec Tunnel" */
-&(nid_objs[296]),/* "IPSec User" */
-&(nid_objs[182]),/* "ISO Member Body" */
-&(nid_objs[183]),/* "ISO US Member Body" */
-&(nid_objs[667]),/* "Independent" */
-&(nid_objs[665]),/* "Inherit all" */
-&(nid_objs[647]),/* "International Organizations" */
-&(nid_objs[142]),/* "Invalidity Date" */
-&(nid_objs[504]),/* "MIME MHS" */
-&(nid_objs[388]),/* "Mail" */
-&(nid_objs[383]),/* "Management" */
-&(nid_objs[417]),/* "Microsoft CSP Name" */
-&(nid_objs[135]),/* "Microsoft Commercial Code Signing" */
-&(nid_objs[138]),/* "Microsoft Encrypted File System" */
-&(nid_objs[171]),/* "Microsoft Extension Request" */
-&(nid_objs[134]),/* "Microsoft Individual Code Signing" */
-&(nid_objs[856]),/* "Microsoft Local Key set" */
-&(nid_objs[137]),/* "Microsoft Server Gated Crypto" */
-&(nid_objs[648]),/* "Microsoft Smartcardlogin" */
-&(nid_objs[136]),/* "Microsoft Trust List Signing" */
-&(nid_objs[649]),/* "Microsoft Universal Principal Name" */
-&(nid_objs[393]),/* "NULL" */
-&(nid_objs[404]),/* "NULL" */
-&(nid_objs[72]),/* "Netscape Base Url" */
-&(nid_objs[76]),/* "Netscape CA Policy Url" */
-&(nid_objs[74]),/* "Netscape CA Revocation Url" */
-&(nid_objs[71]),/* "Netscape Cert Type" */
-&(nid_objs[58]),/* "Netscape Certificate Extension" */
-&(nid_objs[79]),/* "Netscape Certificate Sequence" */
-&(nid_objs[78]),/* "Netscape Comment" */
-&(nid_objs[57]),/* "Netscape Communications Corp." */
-&(nid_objs[59]),/* "Netscape Data Type" */
-&(nid_objs[75]),/* "Netscape Renewal Url" */
-&(nid_objs[73]),/* "Netscape Revocation Url" */
-&(nid_objs[77]),/* "Netscape SSL Server Name" */
-&(nid_objs[139]),/* "Netscape Server Gated Crypto" */
-&(nid_objs[178]),/* "OCSP" */
-&(nid_objs[370]),/* "OCSP Archive Cutoff" */
-&(nid_objs[367]),/* "OCSP CRL ID" */
-&(nid_objs[369]),/* "OCSP No Check" */
-&(nid_objs[366]),/* "OCSP Nonce" */
-&(nid_objs[371]),/* "OCSP Service Locator" */
-&(nid_objs[180]),/* "OCSP Signing" */
-&(nid_objs[161]),/* "PBES2" */
-&(nid_objs[69]),/* "PBKDF2" */
-&(nid_objs[162]),/* "PBMAC1" */
-&(nid_objs[127]),/* "PKIX" */
-&(nid_objs[858]),/* "Permanent Identifier" */
-&(nid_objs[164]),/* "Policy Qualifier CPS" */
-&(nid_objs[165]),/* "Policy Qualifier User Notice" */
-&(nid_objs[385]),/* "Private" */
-&(nid_objs[663]),/* "Proxy Certificate Information" */
-&(nid_objs[ 1]),/* "RSA Data Security, Inc." */
-&(nid_objs[ 2]),/* "RSA Data Security, Inc. PKCS" */
-&(nid_objs[188]),/* "S/MIME" */
-&(nid_objs[167]),/* "S/MIME Capabilities" */
-&(nid_objs[387]),/* "SNMPv2" */
-&(nid_objs[512]),/* "Secure Electronic Transactions" */
-&(nid_objs[386]),/* "Security" */
-&(nid_objs[394]),/* "Selected Attribute Types" */
-&(nid_objs[143]),/* "Strong Extranet ID" */
-&(nid_objs[398]),/* "Subject Information Access" */
-&(nid_objs[130]),/* "TLS Web Client Authentication" */
-&(nid_objs[129]),/* "TLS Web Server Authentication" */
-&(nid_objs[133]),/* "Time Stamping" */
-&(nid_objs[375]),/* "Trust Root" */
-&(nid_objs[12]),/* "X509" */
-&(nid_objs[402]),/* "X509v3 AC Targeting" */
-&(nid_objs[746]),/* "X509v3 Any Policy" */
-&(nid_objs[90]),/* "X509v3 Authority Key Identifier" */
-&(nid_objs[87]),/* "X509v3 Basic Constraints" */
-&(nid_objs[103]),/* "X509v3 CRL Distribution Points" */
-&(nid_objs[88]),/* "X509v3 CRL Number" */
-&(nid_objs[141]),/* "X509v3 CRL Reason Code" */
-&(nid_objs[771]),/* "X509v3 Certificate Issuer" */
-&(nid_objs[89]),/* "X509v3 Certificate Policies" */
-&(nid_objs[140]),/* "X509v3 Delta CRL Indicator" */
-&(nid_objs[126]),/* "X509v3 Extended Key Usage" */
-&(nid_objs[857]),/* "X509v3 Freshest CRL" */
-&(nid_objs[748]),/* "X509v3 Inhibit Any Policy" */
-&(nid_objs[86]),/* "X509v3 Issuer Alternative Name" */
-&(nid_objs[770]),/* "X509v3 Issuing Distrubution Point" */
-&(nid_objs[83]),/* "X509v3 Key Usage" */
-&(nid_objs[666]),/* "X509v3 Name Constraints" */
-&(nid_objs[403]),/* "X509v3 No Revocation Available" */
-&(nid_objs[401]),/* "X509v3 Policy Constraints" */
-&(nid_objs[747]),/* "X509v3 Policy Mappings" */
-&(nid_objs[84]),/* "X509v3 Private Key Usage Period" */
-&(nid_objs[85]),/* "X509v3 Subject Alternative Name" */
-&(nid_objs[769]),/* "X509v3 Subject Directory Attributes" */
-&(nid_objs[82]),/* "X509v3 Subject Key Identifier" */
-&(nid_objs[184]),/* "X9.57" */
-&(nid_objs[185]),/* "X9.57 CM ?" */
-&(nid_objs[478]),/* "aRecord" */
-&(nid_objs[289]),/* "aaControls" */
-&(nid_objs[287]),/* "ac-auditEntity" */
-&(nid_objs[397]),/* "ac-proxying" */
-&(nid_objs[288]),/* "ac-targeting" */
-&(nid_objs[446]),/* "account" */
-&(nid_objs[364]),/* "ad dvcs" */
-&(nid_objs[606]),/* "additional verification" */
-&(nid_objs[419]),/* "aes-128-cbc" */
-&(nid_objs[421]),/* "aes-128-cfb" */
-&(nid_objs[650]),/* "aes-128-cfb1" */
-&(nid_objs[653]),/* "aes-128-cfb8" */
-&(nid_objs[418]),/* "aes-128-ecb" */
-&(nid_objs[420]),/* "aes-128-ofb" */
-&(nid_objs[423]),/* "aes-192-cbc" */
-&(nid_objs[425]),/* "aes-192-cfb" */
-&(nid_objs[651]),/* "aes-192-cfb1" */
-&(nid_objs[654]),/* "aes-192-cfb8" */
-&(nid_objs[422]),/* "aes-192-ecb" */
-&(nid_objs[424]),/* "aes-192-ofb" */
-&(nid_objs[427]),/* "aes-256-cbc" */
-&(nid_objs[429]),/* "aes-256-cfb" */
-&(nid_objs[652]),/* "aes-256-cfb1" */
-&(nid_objs[655]),/* "aes-256-cfb8" */
-&(nid_objs[426]),/* "aes-256-ecb" */
-&(nid_objs[428]),/* "aes-256-ofb" */
-&(nid_objs[376]),/* "algorithm" */
-&(nid_objs[484]),/* "associatedDomain" */
-&(nid_objs[485]),/* "associatedName" */
-&(nid_objs[501]),/* "audio" */
-&(nid_objs[882]),/* "authorityRevocationList" */
-&(nid_objs[91]),/* "bf-cbc" */
-&(nid_objs[93]),/* "bf-cfb" */
-&(nid_objs[92]),/* "bf-ecb" */
-&(nid_objs[94]),/* "bf-ofb" */
-&(nid_objs[494]),/* "buildingName" */
-&(nid_objs[860]),/* "businessCategory" */
-&(nid_objs[691]),/* "c2onb191v4" */
-&(nid_objs[692]),/* "c2onb191v5" */
-&(nid_objs[697]),/* "c2onb239v4" */
-&(nid_objs[698]),/* "c2onb239v5" */
-&(nid_objs[684]),/* "c2pnb163v1" */
-&(nid_objs[685]),/* "c2pnb163v2" */
-&(nid_objs[686]),/* "c2pnb163v3" */
-&(nid_objs[687]),/* "c2pnb176v1" */
-&(nid_objs[693]),/* "c2pnb208w1" */
-&(nid_objs[699]),/* "c2pnb272w1" */
-&(nid_objs[700]),/* "c2pnb304w1" */
-&(nid_objs[702]),/* "c2pnb368w1" */
-&(nid_objs[688]),/* "c2tnb191v1" */
-&(nid_objs[689]),/* "c2tnb191v2" */
-&(nid_objs[690]),/* "c2tnb191v3" */
-&(nid_objs[694]),/* "c2tnb239v1" */
-&(nid_objs[695]),/* "c2tnb239v2" */
-&(nid_objs[696]),/* "c2tnb239v3" */
-&(nid_objs[701]),/* "c2tnb359v1" */
-&(nid_objs[703]),/* "c2tnb431r1" */
-&(nid_objs[881]),/* "cACertificate" */
-&(nid_objs[483]),/* "cNAMERecord" */
-&(nid_objs[751]),/* "camellia-128-cbc" */
-&(nid_objs[757]),/* "camellia-128-cfb" */
-&(nid_objs[760]),/* "camellia-128-cfb1" */
-&(nid_objs[763]),/* "camellia-128-cfb8" */
-&(nid_objs[754]),/* "camellia-128-ecb" */
-&(nid_objs[766]),/* "camellia-128-ofb" */
-&(nid_objs[752]),/* "camellia-192-cbc" */
-&(nid_objs[758]),/* "camellia-192-cfb" */
-&(nid_objs[761]),/* "camellia-192-cfb1" */
-&(nid_objs[764]),/* "camellia-192-cfb8" */
-&(nid_objs[755]),/* "camellia-192-ecb" */
-&(nid_objs[767]),/* "camellia-192-ofb" */
-&(nid_objs[753]),/* "camellia-256-cbc" */
-&(nid_objs[759]),/* "camellia-256-cfb" */
-&(nid_objs[762]),/* "camellia-256-cfb1" */
-&(nid_objs[765]),/* "camellia-256-cfb8" */
-&(nid_objs[756]),/* "camellia-256-ecb" */
-&(nid_objs[768]),/* "camellia-256-ofb" */
-&(nid_objs[443]),/* "caseIgnoreIA5StringSyntax" */
-&(nid_objs[108]),/* "cast5-cbc" */
-&(nid_objs[110]),/* "cast5-cfb" */
-&(nid_objs[109]),/* "cast5-ecb" */
-&(nid_objs[111]),/* "cast5-ofb" */
-&(nid_objs[152]),/* "certBag" */
-&(nid_objs[677]),/* "certicom-arc" */
-&(nid_objs[517]),/* "certificate extensions" */
-&(nid_objs[883]),/* "certificateRevocationList" */
-&(nid_objs[54]),/* "challengePassword" */
-&(nid_objs[407]),/* "characteristic-two-field" */
-&(nid_objs[395]),/* "clearance" */
-&(nid_objs[633]),/* "cleartext track 2" */
-&(nid_objs[13]),/* "commonName" */
-&(nid_objs[513]),/* "content types" */
-&(nid_objs[50]),/* "contentType" */
-&(nid_objs[53]),/* "countersignature" */
-&(nid_objs[14]),/* "countryName" */
-&(nid_objs[153]),/* "crlBag" */
-&(nid_objs[884]),/* "crossCertificatePair" */
-&(nid_objs[806]),/* "cryptocom" */
-&(nid_objs[805]),/* "cryptopro" */
-&(nid_objs[500]),/* "dITRedirect" */
-&(nid_objs[451]),/* "dNSDomain" */
-&(nid_objs[495]),/* "dSAQuality" */
-&(nid_objs[434]),/* "data" */
-&(nid_objs[390]),/* "dcObject" */
-&(nid_objs[891]),/* "deltaRevocationList" */
-&(nid_objs[31]),/* "des-cbc" */
-&(nid_objs[643]),/* "des-cdmf" */
-&(nid_objs[30]),/* "des-cfb" */
-&(nid_objs[656]),/* "des-cfb1" */
-&(nid_objs[657]),/* "des-cfb8" */
-&(nid_objs[29]),/* "des-ecb" */
-&(nid_objs[32]),/* "des-ede" */
-&(nid_objs[43]),/* "des-ede-cbc" */
-&(nid_objs[60]),/* "des-ede-cfb" */
-&(nid_objs[62]),/* "des-ede-ofb" */
-&(nid_objs[33]),/* "des-ede3" */
-&(nid_objs[44]),/* "des-ede3-cbc" */
-&(nid_objs[61]),/* "des-ede3-cfb" */
-&(nid_objs[658]),/* "des-ede3-cfb1" */
-&(nid_objs[659]),/* "des-ede3-cfb8" */
-&(nid_objs[63]),/* "des-ede3-ofb" */
-&(nid_objs[45]),/* "des-ofb" */
-&(nid_objs[107]),/* "description" */
-&(nid_objs[871]),/* "destinationIndicator" */
-&(nid_objs[80]),/* "desx-cbc" */
-&(nid_objs[28]),/* "dhKeyAgreement" */
-&(nid_objs[11]),/* "directory services (X.500)" */
-&(nid_objs[378]),/* "directory services - algorithms" */
-&(nid_objs[887]),/* "distinguishedName" */
-&(nid_objs[892]),/* "dmdName" */
-&(nid_objs[174]),/* "dnQualifier" */
-&(nid_objs[447]),/* "document" */
-&(nid_objs[471]),/* "documentAuthor" */
-&(nid_objs[468]),/* "documentIdentifier" */
-&(nid_objs[472]),/* "documentLocation" */
-&(nid_objs[502]),/* "documentPublisher" */
-&(nid_objs[449]),/* "documentSeries" */
-&(nid_objs[469]),/* "documentTitle" */
-&(nid_objs[470]),/* "documentVersion" */
-&(nid_objs[380]),/* "dod" */
-&(nid_objs[391]),/* "domainComponent" */
-&(nid_objs[452]),/* "domainRelatedObject" */
-&(nid_objs[116]),/* "dsaEncryption" */
-&(nid_objs[67]),/* "dsaEncryption-old" */
-&(nid_objs[66]),/* "dsaWithSHA" */
-&(nid_objs[113]),/* "dsaWithSHA1" */
-&(nid_objs[70]),/* "dsaWithSHA1-old" */
-&(nid_objs[802]),/* "dsa_with_SHA224" */
-&(nid_objs[803]),/* "dsa_with_SHA256" */
-&(nid_objs[297]),/* "dvcs" */
-&(nid_objs[791]),/* "ecdsa-with-Recommended" */
-&(nid_objs[416]),/* "ecdsa-with-SHA1" */
-&(nid_objs[793]),/* "ecdsa-with-SHA224" */
-&(nid_objs[794]),/* "ecdsa-with-SHA256" */
-&(nid_objs[795]),/* "ecdsa-with-SHA384" */
-&(nid_objs[796]),/* "ecdsa-with-SHA512" */
-&(nid_objs[792]),/* "ecdsa-with-Specified" */
-&(nid_objs[48]),/* "emailAddress" */
-&(nid_objs[632]),/* "encrypted track 2" */
-&(nid_objs[885]),/* "enhancedSearchGuide" */
-&(nid_objs[56]),/* "extendedCertificateAttributes" */
-&(nid_objs[867]),/* "facsimileTelephoneNumber" */
-&(nid_objs[462]),/* "favouriteDrink" */
-&(nid_objs[453]),/* "friendlyCountry" */
-&(nid_objs[490]),/* "friendlyCountryName" */
-&(nid_objs[156]),/* "friendlyName" */
-&(nid_objs[631]),/* "generate cryptogram" */
-&(nid_objs[509]),/* "generationQualifier" */
-&(nid_objs[601]),/* "generic cryptogram" */
-&(nid_objs[99]),/* "givenName" */
-&(nid_objs[814]),/* "gost89-cnt" */
-&(nid_objs[855]),/* "hmac" */
-&(nid_objs[780]),/* "hmac-md5" */
-&(nid_objs[781]),/* "hmac-sha1" */
-&(nid_objs[797]),/* "hmacWithMD5" */
-&(nid_objs[163]),/* "hmacWithSHA1" */
-&(nid_objs[798]),/* "hmacWithSHA224" */
-&(nid_objs[799]),/* "hmacWithSHA256" */
-&(nid_objs[800]),/* "hmacWithSHA384" */
-&(nid_objs[801]),/* "hmacWithSHA512" */
-&(nid_objs[486]),/* "homePostalAddress" */
-&(nid_objs[473]),/* "homeTelephoneNumber" */
-&(nid_objs[466]),/* "host" */
-&(nid_objs[889]),/* "houseIdentifier" */
-&(nid_objs[442]),/* "iA5StringSyntax" */
-&(nid_objs[381]),/* "iana" */
-&(nid_objs[824]),/* "id-Gost28147-89-CryptoPro-A-ParamSet" */
-&(nid_objs[825]),/* "id-Gost28147-89-CryptoPro-B-ParamSet" */
-&(nid_objs[826]),/* "id-Gost28147-89-CryptoPro-C-ParamSet" */
-&(nid_objs[827]),/* "id-Gost28147-89-CryptoPro-D-ParamSet" */
-&(nid_objs[819]),/* "id-Gost28147-89-CryptoPro-KeyMeshing" */
-&(nid_objs[829]),/* "id-Gost28147-89-CryptoPro-Oscar-1-0-ParamSet" */
-&(nid_objs[828]),/* "id-Gost28147-89-CryptoPro-Oscar-1-1-ParamSet" */
-&(nid_objs[830]),/* "id-Gost28147-89-CryptoPro-RIC-1-ParamSet" */
-&(nid_objs[820]),/* "id-Gost28147-89-None-KeyMeshing" */
-&(nid_objs[823]),/* "id-Gost28147-89-TestParamSet" */
-&(nid_objs[840]),/* "id-GostR3410-2001-CryptoPro-A-ParamSet" */
-&(nid_objs[841]),/* "id-GostR3410-2001-CryptoPro-B-ParamSet" */
-&(nid_objs[842]),/* "id-GostR3410-2001-CryptoPro-C-ParamSet" */
-&(nid_objs[843]),/* "id-GostR3410-2001-CryptoPro-XchA-ParamSet" */
-&(nid_objs[844]),/* "id-GostR3410-2001-CryptoPro-XchB-ParamSet" */
-&(nid_objs[839]),/* "id-GostR3410-2001-TestParamSet" */
-&(nid_objs[832]),/* "id-GostR3410-94-CryptoPro-A-ParamSet" */
-&(nid_objs[833]),/* "id-GostR3410-94-CryptoPro-B-ParamSet" */
-&(nid_objs[834]),/* "id-GostR3410-94-CryptoPro-C-ParamSet" */
-&(nid_objs[835]),/* "id-GostR3410-94-CryptoPro-D-ParamSet" */
-&(nid_objs[836]),/* "id-GostR3410-94-CryptoPro-XchA-ParamSet" */
-&(nid_objs[837]),/* "id-GostR3410-94-CryptoPro-XchB-ParamSet" */
-&(nid_objs[838]),/* "id-GostR3410-94-CryptoPro-XchC-ParamSet" */
-&(nid_objs[831]),/* "id-GostR3410-94-TestParamSet" */
-&(nid_objs[845]),/* "id-GostR3410-94-a" */
-&(nid_objs[846]),/* "id-GostR3410-94-aBis" */
-&(nid_objs[847]),/* "id-GostR3410-94-b" */
-&(nid_objs[848]),/* "id-GostR3410-94-bBis" */
-&(nid_objs[822]),/* "id-GostR3411-94-CryptoProParamSet" */
-&(nid_objs[821]),/* "id-GostR3411-94-TestParamSet" */
-&(nid_objs[266]),/* "id-aca" */
-&(nid_objs[355]),/* "id-aca-accessIdentity" */
-&(nid_objs[354]),/* "id-aca-authenticationInfo" */
-&(nid_objs[356]),/* "id-aca-chargingIdentity" */
-&(nid_objs[399]),/* "id-aca-encAttrs" */
-&(nid_objs[357]),/* "id-aca-group" */
-&(nid_objs[358]),/* "id-aca-role" */
-&(nid_objs[176]),/* "id-ad" */
-&(nid_objs[788]),/* "id-aes128-wrap" */
-&(nid_objs[789]),/* "id-aes192-wrap" */
-&(nid_objs[790]),/* "id-aes256-wrap" */
-&(nid_objs[262]),/* "id-alg" */
-&(nid_objs[323]),/* "id-alg-des40" */
-&(nid_objs[326]),/* "id-alg-dh-pop" */
-&(nid_objs[325]),/* "id-alg-dh-sig-hmac-sha1" */
-&(nid_objs[324]),/* "id-alg-noSignature" */
-&(nid_objs[268]),/* "id-cct" */
-&(nid_objs[361]),/* "id-cct-PKIData" */
-&(nid_objs[362]),/* "id-cct-PKIResponse" */
-&(nid_objs[360]),/* "id-cct-crs" */
-&(nid_objs[81]),/* "id-ce" */
-&(nid_objs[680]),/* "id-characteristic-two-basis" */
-&(nid_objs[263]),/* "id-cmc" */
-&(nid_objs[334]),/* "id-cmc-addExtensions" */
-&(nid_objs[346]),/* "id-cmc-confirmCertAcceptance" */
-&(nid_objs[330]),/* "id-cmc-dataReturn" */
-&(nid_objs[336]),/* "id-cmc-decryptedPOP" */
-&(nid_objs[335]),/* "id-cmc-encryptedPOP" */
-&(nid_objs[339]),/* "id-cmc-getCRL" */
-&(nid_objs[338]),/* "id-cmc-getCert" */
-&(nid_objs[328]),/* "id-cmc-identification" */
-&(nid_objs[329]),/* "id-cmc-identityProof" */
-&(nid_objs[337]),/* "id-cmc-lraPOPWitness" */
-&(nid_objs[344]),/* "id-cmc-popLinkRandom" */
-&(nid_objs[345]),/* "id-cmc-popLinkWitness" */
-&(nid_objs[343]),/* "id-cmc-queryPending" */
-&(nid_objs[333]),/* "id-cmc-recipientNonce" */
-&(nid_objs[341]),/* "id-cmc-regInfo" */
-&(nid_objs[342]),/* "id-cmc-responseInfo" */
-&(nid_objs[340]),/* "id-cmc-revokeRequest" */
-&(nid_objs[332]),/* "id-cmc-senderNonce" */
-&(nid_objs[327]),/* "id-cmc-statusInfo" */
-&(nid_objs[331]),/* "id-cmc-transactionId" */
-&(nid_objs[787]),/* "id-ct-asciiTextWithCRLF" */
-&(nid_objs[408]),/* "id-ecPublicKey" */
-&(nid_objs[508]),/* "id-hex-multipart-message" */
-&(nid_objs[507]),/* "id-hex-partial-message" */
-&(nid_objs[260]),/* "id-it" */
-&(nid_objs[302]),/* "id-it-caKeyUpdateInfo" */
-&(nid_objs[298]),/* "id-it-caProtEncCert" */
-&(nid_objs[311]),/* "id-it-confirmWaitTime" */
-&(nid_objs[303]),/* "id-it-currentCRL" */
-&(nid_objs[300]),/* "id-it-encKeyPairTypes" */
-&(nid_objs[310]),/* "id-it-implicitConfirm" */
-&(nid_objs[308]),/* "id-it-keyPairParamRep" */
-&(nid_objs[307]),/* "id-it-keyPairParamReq" */
-&(nid_objs[312]),/* "id-it-origPKIMessage" */
-&(nid_objs[301]),/* "id-it-preferredSymmAlg" */
-&(nid_objs[309]),/* "id-it-revPassphrase" */
-&(nid_objs[299]),/* "id-it-signKeyPairTypes" */
-&(nid_objs[305]),/* "id-it-subscriptionRequest" */
-&(nid_objs[306]),/* "id-it-subscriptionResponse" */
-&(nid_objs[784]),/* "id-it-suppLangTags" */
-&(nid_objs[304]),/* "id-it-unsupportedOIDs" */
-&(nid_objs[128]),/* "id-kp" */
-&(nid_objs[280]),/* "id-mod-attribute-cert" */
-&(nid_objs[274]),/* "id-mod-cmc" */
-&(nid_objs[277]),/* "id-mod-cmp" */
-&(nid_objs[284]),/* "id-mod-cmp2000" */
-&(nid_objs[273]),/* "id-mod-crmf" */
-&(nid_objs[283]),/* "id-mod-dvcs" */
-&(nid_objs[275]),/* "id-mod-kea-profile-88" */
-&(nid_objs[276]),/* "id-mod-kea-profile-93" */
-&(nid_objs[282]),/* "id-mod-ocsp" */
-&(nid_objs[278]),/* "id-mod-qualified-cert-88" */
-&(nid_objs[279]),/* "id-mod-qualified-cert-93" */
-&(nid_objs[281]),/* "id-mod-timestamp-protocol" */
-&(nid_objs[264]),/* "id-on" */
-&(nid_objs[347]),/* "id-on-personalData" */
-&(nid_objs[265]),/* "id-pda" */
-&(nid_objs[352]),/* "id-pda-countryOfCitizenship" */
-&(nid_objs[353]),/* "id-pda-countryOfResidence" */
-&(nid_objs[348]),/* "id-pda-dateOfBirth" */
-&(nid_objs[351]),/* "id-pda-gender" */
-&(nid_objs[349]),/* "id-pda-placeOfBirth" */
-&(nid_objs[175]),/* "id-pe" */
-&(nid_objs[261]),/* "id-pkip" */
-&(nid_objs[258]),/* "id-pkix-mod" */
-&(nid_objs[269]),/* "id-pkix1-explicit-88" */
-&(nid_objs[271]),/* "id-pkix1-explicit-93" */
-&(nid_objs[270]),/* "id-pkix1-implicit-88" */
-&(nid_objs[272]),/* "id-pkix1-implicit-93" */
-&(nid_objs[662]),/* "id-ppl" */
-&(nid_objs[267]),/* "id-qcs" */
-&(nid_objs[359]),/* "id-qcs-pkixQCSyntax-v1" */
-&(nid_objs[259]),/* "id-qt" */
-&(nid_objs[313]),/* "id-regCtrl" */
-&(nid_objs[316]),/* "id-regCtrl-authenticator" */
-&(nid_objs[319]),/* "id-regCtrl-oldCertID" */
-&(nid_objs[318]),/* "id-regCtrl-pkiArchiveOptions" */
-&(nid_objs[317]),/* "id-regCtrl-pkiPublicationInfo" */
-&(nid_objs[320]),/* "id-regCtrl-protocolEncrKey" */
-&(nid_objs[315]),/* "id-regCtrl-regToken" */
-&(nid_objs[314]),/* "id-regInfo" */
-&(nid_objs[322]),/* "id-regInfo-certReq" */
-&(nid_objs[321]),/* "id-regInfo-utf8Pairs" */
-&(nid_objs[191]),/* "id-smime-aa" */
-&(nid_objs[215]),/* "id-smime-aa-contentHint" */
-&(nid_objs[218]),/* "id-smime-aa-contentIdentifier" */
-&(nid_objs[221]),/* "id-smime-aa-contentReference" */
-&(nid_objs[240]),/* "id-smime-aa-dvcs-dvc" */
-&(nid_objs[217]),/* "id-smime-aa-encapContentType" */
-&(nid_objs[222]),/* "id-smime-aa-encrypKeyPref" */
-&(nid_objs[220]),/* "id-smime-aa-equivalentLabels" */
-&(nid_objs[232]),/* "id-smime-aa-ets-CertificateRefs" */
-&(nid_objs[233]),/* "id-smime-aa-ets-RevocationRefs" */
-&(nid_objs[238]),/* "id-smime-aa-ets-archiveTimeStamp" */
-&(nid_objs[237]),/* "id-smime-aa-ets-certCRLTimestamp" */
-&(nid_objs[234]),/* "id-smime-aa-ets-certValues" */
-&(nid_objs[227]),/* "id-smime-aa-ets-commitmentType" */
-&(nid_objs[231]),/* "id-smime-aa-ets-contentTimestamp" */
-&(nid_objs[236]),/* "id-smime-aa-ets-escTimeStamp" */
-&(nid_objs[230]),/* "id-smime-aa-ets-otherSigCert" */
-&(nid_objs[235]),/* "id-smime-aa-ets-revocationValues" */
-&(nid_objs[226]),/* "id-smime-aa-ets-sigPolicyId" */
-&(nid_objs[229]),/* "id-smime-aa-ets-signerAttr" */
-&(nid_objs[228]),/* "id-smime-aa-ets-signerLocation" */
-&(nid_objs[219]),/* "id-smime-aa-macValue" */
-&(nid_objs[214]),/* "id-smime-aa-mlExpandHistory" */
-&(nid_objs[216]),/* "id-smime-aa-msgSigDigest" */
-&(nid_objs[212]),/* "id-smime-aa-receiptRequest" */
-&(nid_objs[213]),/* "id-smime-aa-securityLabel" */
-&(nid_objs[239]),/* "id-smime-aa-signatureType" */
-&(nid_objs[223]),/* "id-smime-aa-signingCertificate" */
-&(nid_objs[224]),/* "id-smime-aa-smimeEncryptCerts" */
-&(nid_objs[225]),/* "id-smime-aa-timeStampToken" */
-&(nid_objs[192]),/* "id-smime-alg" */
-&(nid_objs[243]),/* "id-smime-alg-3DESwrap" */
-&(nid_objs[246]),/* "id-smime-alg-CMS3DESwrap" */
-&(nid_objs[247]),/* "id-smime-alg-CMSRC2wrap" */
-&(nid_objs[245]),/* "id-smime-alg-ESDH" */
-&(nid_objs[241]),/* "id-smime-alg-ESDHwith3DES" */
-&(nid_objs[242]),/* "id-smime-alg-ESDHwithRC2" */
-&(nid_objs[244]),/* "id-smime-alg-RC2wrap" */
-&(nid_objs[193]),/* "id-smime-cd" */
-&(nid_objs[248]),/* "id-smime-cd-ldap" */
-&(nid_objs[190]),/* "id-smime-ct" */
-&(nid_objs[210]),/* "id-smime-ct-DVCSRequestData" */
-&(nid_objs[211]),/* "id-smime-ct-DVCSResponseData" */
-&(nid_objs[208]),/* "id-smime-ct-TDTInfo" */
-&(nid_objs[207]),/* "id-smime-ct-TSTInfo" */
-&(nid_objs[205]),/* "id-smime-ct-authData" */
-&(nid_objs[786]),/* "id-smime-ct-compressedData" */
-&(nid_objs[209]),/* "id-smime-ct-contentInfo" */
-&(nid_objs[206]),/* "id-smime-ct-publishCert" */
-&(nid_objs[204]),/* "id-smime-ct-receipt" */
-&(nid_objs[195]),/* "id-smime-cti" */
-&(nid_objs[255]),/* "id-smime-cti-ets-proofOfApproval" */
-&(nid_objs[256]),/* "id-smime-cti-ets-proofOfCreation" */
-&(nid_objs[253]),/* "id-smime-cti-ets-proofOfDelivery" */
-&(nid_objs[251]),/* "id-smime-cti-ets-proofOfOrigin" */
-&(nid_objs[252]),/* "id-smime-cti-ets-proofOfReceipt" */
-&(nid_objs[254]),/* "id-smime-cti-ets-proofOfSender" */
-&(nid_objs[189]),/* "id-smime-mod" */
-&(nid_objs[196]),/* "id-smime-mod-cms" */
-&(nid_objs[197]),/* "id-smime-mod-ess" */
-&(nid_objs[202]),/* "id-smime-mod-ets-eSigPolicy-88" */
-&(nid_objs[203]),/* "id-smime-mod-ets-eSigPolicy-97" */
-&(nid_objs[200]),/* "id-smime-mod-ets-eSignature-88" */
-&(nid_objs[201]),/* "id-smime-mod-ets-eSignature-97" */
-&(nid_objs[199]),/* "id-smime-mod-msg-v3" */
-&(nid_objs[198]),/* "id-smime-mod-oid" */
-&(nid_objs[194]),/* "id-smime-spq" */
-&(nid_objs[250]),/* "id-smime-spq-ets-sqt-unotice" */
-&(nid_objs[249]),/* "id-smime-spq-ets-sqt-uri" */
-&(nid_objs[34]),/* "idea-cbc" */
-&(nid_objs[35]),/* "idea-cfb" */
-&(nid_objs[36]),/* "idea-ecb" */
-&(nid_objs[46]),/* "idea-ofb" */
-&(nid_objs[676]),/* "identified-organization" */
-&(nid_objs[461]),/* "info" */
-&(nid_objs[101]),/* "initials" */
-&(nid_objs[869]),/* "internationaliSDNNumber" */
-&(nid_objs[749]),/* "ipsec3" */
-&(nid_objs[750]),/* "ipsec4" */
-&(nid_objs[181]),/* "iso" */
-&(nid_objs[623]),/* "issuer capabilities" */
-&(nid_objs[645]),/* "itu-t" */
-&(nid_objs[492]),/* "janetMailbox" */
-&(nid_objs[646]),/* "joint-iso-itu-t" */
-&(nid_objs[150]),/* "keyBag" */
-&(nid_objs[773]),/* "kisa" */
-&(nid_objs[477]),/* "lastModifiedBy" */
-&(nid_objs[476]),/* "lastModifiedTime" */
-&(nid_objs[157]),/* "localKeyID" */
-&(nid_objs[15]),/* "localityName" */
-&(nid_objs[480]),/* "mXRecord" */
-&(nid_objs[493]),/* "mailPreferenceOption" */
-&(nid_objs[467]),/* "manager" */
-&(nid_objs[ 3]),/* "md2" */
-&(nid_objs[ 7]),/* "md2WithRSAEncryption" */
-&(nid_objs[257]),/* "md4" */
-&(nid_objs[396]),/* "md4WithRSAEncryption" */
-&(nid_objs[ 4]),/* "md5" */
-&(nid_objs[114]),/* "md5-sha1" */
-&(nid_objs[104]),/* "md5WithRSA" */
-&(nid_objs[ 8]),/* "md5WithRSAEncryption" */
-&(nid_objs[95]),/* "mdc2" */
-&(nid_objs[96]),/* "mdc2WithRSA" */
-&(nid_objs[875]),/* "member" */
-&(nid_objs[602]),/* "merchant initiated auth" */
-&(nid_objs[514]),/* "message extensions" */
-&(nid_objs[51]),/* "messageDigest" */
-&(nid_objs[506]),/* "mime-mhs-bodies" */
-&(nid_objs[505]),/* "mime-mhs-headings" */
-&(nid_objs[488]),/* "mobileTelephoneNumber" */
-&(nid_objs[481]),/* "nSRecord" */
-&(nid_objs[173]),/* "name" */
-&(nid_objs[681]),/* "onBasis" */
-&(nid_objs[379]),/* "org" */
-&(nid_objs[17]),/* "organizationName" */
-&(nid_objs[491]),/* "organizationalStatus" */
-&(nid_objs[18]),/* "organizationalUnitName" */
-&(nid_objs[475]),/* "otherMailbox" */
-&(nid_objs[876]),/* "owner" */
-&(nid_objs[489]),/* "pagerTelephoneNumber" */
-&(nid_objs[782]),/* "password based MAC" */
-&(nid_objs[374]),/* "path" */
-&(nid_objs[621]),/* "payment gateway capabilities" */
-&(nid_objs[ 9]),/* "pbeWithMD2AndDES-CBC" */
-&(nid_objs[168]),/* "pbeWithMD2AndRC2-CBC" */
-&(nid_objs[112]),/* "pbeWithMD5AndCast5CBC" */
-&(nid_objs[10]),/* "pbeWithMD5AndDES-CBC" */
-&(nid_objs[169]),/* "pbeWithMD5AndRC2-CBC" */
-&(nid_objs[148]),/* "pbeWithSHA1And128BitRC2-CBC" */
-&(nid_objs[144]),/* "pbeWithSHA1And128BitRC4" */
-&(nid_objs[147]),/* "pbeWithSHA1And2-KeyTripleDES-CBC" */
-&(nid_objs[146]),/* "pbeWithSHA1And3-KeyTripleDES-CBC" */
-&(nid_objs[149]),/* "pbeWithSHA1And40BitRC2-CBC" */
-&(nid_objs[145]),/* "pbeWithSHA1And40BitRC4" */
-&(nid_objs[170]),/* "pbeWithSHA1AndDES-CBC" */
-&(nid_objs[68]),/* "pbeWithSHA1AndRC2-CBC" */
-&(nid_objs[499]),/* "personalSignature" */
-&(nid_objs[487]),/* "personalTitle" */
-&(nid_objs[464]),/* "photo" */
-&(nid_objs[863]),/* "physicalDeliveryOfficeName" */
-&(nid_objs[437]),/* "pilot" */
-&(nid_objs[439]),/* "pilotAttributeSyntax" */
-&(nid_objs[438]),/* "pilotAttributeType" */
-&(nid_objs[479]),/* "pilotAttributeType27" */
-&(nid_objs[456]),/* "pilotDSA" */
-&(nid_objs[441]),/* "pilotGroups" */
-&(nid_objs[444]),/* "pilotObject" */
-&(nid_objs[440]),/* "pilotObjectClass" */
-&(nid_objs[455]),/* "pilotOrganization" */
-&(nid_objs[445]),/* "pilotPerson" */
-&(nid_objs[186]),/* "pkcs1" */
-&(nid_objs[27]),/* "pkcs3" */
-&(nid_objs[187]),/* "pkcs5" */
-&(nid_objs[20]),/* "pkcs7" */
-&(nid_objs[21]),/* "pkcs7-data" */
-&(nid_objs[25]),/* "pkcs7-digestData" */
-&(nid_objs[26]),/* "pkcs7-encryptedData" */
-&(nid_objs[23]),/* "pkcs7-envelopedData" */
-&(nid_objs[24]),/* "pkcs7-signedAndEnvelopedData" */
-&(nid_objs[22]),/* "pkcs7-signedData" */
-&(nid_objs[151]),/* "pkcs8ShroudedKeyBag" */
-&(nid_objs[47]),/* "pkcs9" */
-&(nid_objs[862]),/* "postOfficeBox" */
-&(nid_objs[861]),/* "postalAddress" */
-&(nid_objs[661]),/* "postalCode" */
-&(nid_objs[683]),/* "ppBasis" */
-&(nid_objs[872]),/* "preferredDeliveryMethod" */
-&(nid_objs[873]),/* "presentationAddress" */
-&(nid_objs[406]),/* "prime-field" */
-&(nid_objs[409]),/* "prime192v1" */
-&(nid_objs[410]),/* "prime192v2" */
-&(nid_objs[411]),/* "prime192v3" */
-&(nid_objs[412]),/* "prime239v1" */
-&(nid_objs[413]),/* "prime239v2" */
-&(nid_objs[414]),/* "prime239v3" */
-&(nid_objs[415]),/* "prime256v1" */
-&(nid_objs[886]),/* "protocolInformation" */
-&(nid_objs[510]),/* "pseudonym" */
-&(nid_objs[435]),/* "pss" */
-&(nid_objs[286]),/* "qcStatements" */
-&(nid_objs[457]),/* "qualityLabelledData" */
-&(nid_objs[450]),/* "rFC822localPart" */
-&(nid_objs[98]),/* "rc2-40-cbc" */
-&(nid_objs[166]),/* "rc2-64-cbc" */
-&(nid_objs[37]),/* "rc2-cbc" */
-&(nid_objs[39]),/* "rc2-cfb" */
-&(nid_objs[38]),/* "rc2-ecb" */
-&(nid_objs[40]),/* "rc2-ofb" */
-&(nid_objs[ 5]),/* "rc4" */
-&(nid_objs[97]),/* "rc4-40" */
-&(nid_objs[120]),/* "rc5-cbc" */
-&(nid_objs[122]),/* "rc5-cfb" */
-&(nid_objs[121]),/* "rc5-ecb" */
-&(nid_objs[123]),/* "rc5-ofb" */
-&(nid_objs[870]),/* "registeredAddress" */
-&(nid_objs[460]),/* "rfc822Mailbox" */
-&(nid_objs[117]),/* "ripemd160" */
-&(nid_objs[119]),/* "ripemd160WithRSA" */
-&(nid_objs[400]),/* "role" */
-&(nid_objs[877]),/* "roleOccupant" */
-&(nid_objs[448]),/* "room" */
-&(nid_objs[463]),/* "roomNumber" */
-&(nid_objs[19]),/* "rsa" */
-&(nid_objs[ 6]),/* "rsaEncryption" */
-&(nid_objs[644]),/* "rsaOAEPEncryptionSET" */
-&(nid_objs[377]),/* "rsaSignature" */
-&(nid_objs[124]),/* "run length compression" */
-&(nid_objs[482]),/* "sOARecord" */
-&(nid_objs[155]),/* "safeContentsBag" */
-&(nid_objs[291]),/* "sbgp-autonomousSysNum" */
-&(nid_objs[290]),/* "sbgp-ipAddrBlock" */
-&(nid_objs[292]),/* "sbgp-routerIdentifier" */
-&(nid_objs[159]),/* "sdsiCertificate" */
-&(nid_objs[859]),/* "searchGuide" */
-&(nid_objs[704]),/* "secp112r1" */
-&(nid_objs[705]),/* "secp112r2" */
-&(nid_objs[706]),/* "secp128r1" */
-&(nid_objs[707]),/* "secp128r2" */
-&(nid_objs[708]),/* "secp160k1" */
-&(nid_objs[709]),/* "secp160r1" */
-&(nid_objs[710]),/* "secp160r2" */
-&(nid_objs[711]),/* "secp192k1" */
-&(nid_objs[712]),/* "secp224k1" */
-&(nid_objs[713]),/* "secp224r1" */
-&(nid_objs[714]),/* "secp256k1" */
-&(nid_objs[715]),/* "secp384r1" */
-&(nid_objs[716]),/* "secp521r1" */
-&(nid_objs[154]),/* "secretBag" */
-&(nid_objs[474]),/* "secretary" */
-&(nid_objs[717]),/* "sect113r1" */
-&(nid_objs[718]),/* "sect113r2" */
-&(nid_objs[719]),/* "sect131r1" */
-&(nid_objs[720]),/* "sect131r2" */
-&(nid_objs[721]),/* "sect163k1" */
-&(nid_objs[722]),/* "sect163r1" */
-&(nid_objs[723]),/* "sect163r2" */
-&(nid_objs[724]),/* "sect193r1" */
-&(nid_objs[725]),/* "sect193r2" */
-&(nid_objs[726]),/* "sect233k1" */
-&(nid_objs[727]),/* "sect233r1" */
-&(nid_objs[728]),/* "sect239k1" */
-&(nid_objs[729]),/* "sect283k1" */
-&(nid_objs[730]),/* "sect283r1" */
-&(nid_objs[731]),/* "sect409k1" */
-&(nid_objs[732]),/* "sect409r1" */
-&(nid_objs[733]),/* "sect571k1" */
-&(nid_objs[734]),/* "sect571r1" */
-&(nid_objs[635]),/* "secure device signature" */
-&(nid_objs[878]),/* "seeAlso" */
-&(nid_objs[777]),/* "seed-cbc" */
-&(nid_objs[779]),/* "seed-cfb" */
-&(nid_objs[776]),/* "seed-ecb" */
-&(nid_objs[778]),/* "seed-ofb" */
-&(nid_objs[105]),/* "serialNumber" */
-&(nid_objs[625]),/* "set-addPolicy" */
-&(nid_objs[515]),/* "set-attr" */
-&(nid_objs[518]),/* "set-brand" */
-&(nid_objs[638]),/* "set-brand-AmericanExpress" */
-&(nid_objs[637]),/* "set-brand-Diners" */
-&(nid_objs[636]),/* "set-brand-IATA-ATA" */
-&(nid_objs[639]),/* "set-brand-JCB" */
-&(nid_objs[641]),/* "set-brand-MasterCard" */
-&(nid_objs[642]),/* "set-brand-Novus" */
-&(nid_objs[640]),/* "set-brand-Visa" */
-&(nid_objs[516]),/* "set-policy" */
-&(nid_objs[607]),/* "set-policy-root" */
-&(nid_objs[624]),/* "set-rootKeyThumb" */
-&(nid_objs[620]),/* "setAttr-Cert" */
-&(nid_objs[628]),/* "setAttr-IssCap-CVM" */
-&(nid_objs[630]),/* "setAttr-IssCap-Sig" */
-&(nid_objs[629]),/* "setAttr-IssCap-T2" */
-&(nid_objs[627]),/* "setAttr-Token-B0Prime" */
-&(nid_objs[626]),/* "setAttr-Token-EMV" */
-&(nid_objs[622]),/* "setAttr-TokenType" */
-&(nid_objs[619]),/* "setCext-IssuerCapabilities" */
-&(nid_objs[615]),/* "setCext-PGWYcapabilities" */
-&(nid_objs[616]),/* "setCext-TokenIdentifier" */
-&(nid_objs[618]),/* "setCext-TokenType" */
-&(nid_objs[617]),/* "setCext-Track2Data" */
-&(nid_objs[611]),/* "setCext-cCertRequired" */
-&(nid_objs[609]),/* "setCext-certType" */
-&(nid_objs[608]),/* "setCext-hashedRoot" */
-&(nid_objs[610]),/* "setCext-merchData" */
-&(nid_objs[613]),/* "setCext-setExt" */
-&(nid_objs[614]),/* "setCext-setQualf" */
-&(nid_objs[612]),/* "setCext-tunneling" */
-&(nid_objs[540]),/* "setct-AcqCardCodeMsg" */
-&(nid_objs[576]),/* "setct-AcqCardCodeMsgTBE" */
-&(nid_objs[570]),/* "setct-AuthReqTBE" */
-&(nid_objs[534]),/* "setct-AuthReqTBS" */
-&(nid_objs[527]),/* "setct-AuthResBaggage" */
-&(nid_objs[571]),/* "setct-AuthResTBE" */
-&(nid_objs[572]),/* "setct-AuthResTBEX" */
-&(nid_objs[535]),/* "setct-AuthResTBS" */
-&(nid_objs[536]),/* "setct-AuthResTBSX" */
-&(nid_objs[528]),/* "setct-AuthRevReqBaggage" */
-&(nid_objs[577]),/* "setct-AuthRevReqTBE" */
-&(nid_objs[541]),/* "setct-AuthRevReqTBS" */
-&(nid_objs[529]),/* "setct-AuthRevResBaggage" */
-&(nid_objs[542]),/* "setct-AuthRevResData" */
-&(nid_objs[578]),/* "setct-AuthRevResTBE" */
-&(nid_objs[579]),/* "setct-AuthRevResTBEB" */
-&(nid_objs[543]),/* "setct-AuthRevResTBS" */
-&(nid_objs[573]),/* "setct-AuthTokenTBE" */
-&(nid_objs[537]),/* "setct-AuthTokenTBS" */
-&(nid_objs[600]),/* "setct-BCIDistributionTBS" */
-&(nid_objs[558]),/* "setct-BatchAdminReqData" */
-&(nid_objs[592]),/* "setct-BatchAdminReqTBE" */
-&(nid_objs[559]),/* "setct-BatchAdminResData" */
-&(nid_objs[593]),/* "setct-BatchAdminResTBE" */
-&(nid_objs[599]),/* "setct-CRLNotificationResTBS" */
-&(nid_objs[598]),/* "setct-CRLNotificationTBS" */
-&(nid_objs[580]),/* "setct-CapReqTBE" */
-&(nid_objs[581]),/* "setct-CapReqTBEX" */
-&(nid_objs[544]),/* "setct-CapReqTBS" */
-&(nid_objs[545]),/* "setct-CapReqTBSX" */
-&(nid_objs[546]),/* "setct-CapResData" */
-&(nid_objs[582]),/* "setct-CapResTBE" */
-&(nid_objs[583]),/* "setct-CapRevReqTBE" */
-&(nid_objs[584]),/* "setct-CapRevReqTBEX" */
-&(nid_objs[547]),/* "setct-CapRevReqTBS" */
-&(nid_objs[548]),/* "setct-CapRevReqTBSX" */
-&(nid_objs[549]),/* "setct-CapRevResData" */
-&(nid_objs[585]),/* "setct-CapRevResTBE" */
-&(nid_objs[538]),/* "setct-CapTokenData" */
-&(nid_objs[530]),/* "setct-CapTokenSeq" */
-&(nid_objs[574]),/* "setct-CapTokenTBE" */
-&(nid_objs[575]),/* "setct-CapTokenTBEX" */
-&(nid_objs[539]),/* "setct-CapTokenTBS" */
-&(nid_objs[560]),/* "setct-CardCInitResTBS" */
-&(nid_objs[566]),/* "setct-CertInqReqTBS" */
-&(nid_objs[563]),/* "setct-CertReqData" */
-&(nid_objs[595]),/* "setct-CertReqTBE" */
-&(nid_objs[596]),/* "setct-CertReqTBEX" */
-&(nid_objs[564]),/* "setct-CertReqTBS" */
-&(nid_objs[565]),/* "setct-CertResData" */
-&(nid_objs[597]),/* "setct-CertResTBE" */
-&(nid_objs[586]),/* "setct-CredReqTBE" */
-&(nid_objs[587]),/* "setct-CredReqTBEX" */
-&(nid_objs[550]),/* "setct-CredReqTBS" */
-&(nid_objs[551]),/* "setct-CredReqTBSX" */
-&(nid_objs[552]),/* "setct-CredResData" */
-&(nid_objs[588]),/* "setct-CredResTBE" */
-&(nid_objs[589]),/* "setct-CredRevReqTBE" */
-&(nid_objs[590]),/* "setct-CredRevReqTBEX" */
-&(nid_objs[553]),/* "setct-CredRevReqTBS" */
-&(nid_objs[554]),/* "setct-CredRevReqTBSX" */
-&(nid_objs[555]),/* "setct-CredRevResData" */
-&(nid_objs[591]),/* "setct-CredRevResTBE" */
-&(nid_objs[567]),/* "setct-ErrorTBS" */
-&(nid_objs[526]),/* "setct-HODInput" */
-&(nid_objs[561]),/* "setct-MeAqCInitResTBS" */
-&(nid_objs[522]),/* "setct-OIData" */
-&(nid_objs[519]),/* "setct-PANData" */
-&(nid_objs[521]),/* "setct-PANOnly" */
-&(nid_objs[520]),/* "setct-PANToken" */
-&(nid_objs[556]),/* "setct-PCertReqData" */
-&(nid_objs[557]),/* "setct-PCertResTBS" */
-&(nid_objs[523]),/* "setct-PI" */
-&(nid_objs[532]),/* "setct-PI-TBS" */
-&(nid_objs[524]),/* "setct-PIData" */
-&(nid_objs[525]),/* "setct-PIDataUnsigned" */
-&(nid_objs[568]),/* "setct-PIDualSignedTBE" */
-&(nid_objs[569]),/* "setct-PIUnsignedTBE" */
-&(nid_objs[531]),/* "setct-PInitResData" */
-&(nid_objs[533]),/* "setct-PResData" */
-&(nid_objs[594]),/* "setct-RegFormReqTBE" */
-&(nid_objs[562]),/* "setct-RegFormResTBS" */
-&(nid_objs[604]),/* "setext-pinAny" */
-&(nid_objs[603]),/* "setext-pinSecure" */
-&(nid_objs[605]),/* "setext-track2" */
-&(nid_objs[41]),/* "sha" */
-&(nid_objs[64]),/* "sha1" */
-&(nid_objs[115]),/* "sha1WithRSA" */
-&(nid_objs[65]),/* "sha1WithRSAEncryption" */
-&(nid_objs[675]),/* "sha224" */
-&(nid_objs[671]),/* "sha224WithRSAEncryption" */
-&(nid_objs[672]),/* "sha256" */
-&(nid_objs[668]),/* "sha256WithRSAEncryption" */
-&(nid_objs[673]),/* "sha384" */
-&(nid_objs[669]),/* "sha384WithRSAEncryption" */
-&(nid_objs[674]),/* "sha512" */
-&(nid_objs[670]),/* "sha512WithRSAEncryption" */
-&(nid_objs[42]),/* "shaWithRSAEncryption" */
-&(nid_objs[52]),/* "signingTime" */
-&(nid_objs[454]),/* "simpleSecurityObject" */
-&(nid_objs[496]),/* "singleLevelQuality" */
-&(nid_objs[16]),/* "stateOrProvinceName" */
-&(nid_objs[660]),/* "streetAddress" */
-&(nid_objs[498]),/* "subtreeMaximumQuality" */
-&(nid_objs[497]),/* "subtreeMinimumQuality" */
-&(nid_objs[890]),/* "supportedAlgorithms" */
-&(nid_objs[874]),/* "supportedApplicationContext" */
-&(nid_objs[100]),/* "surname" */
-&(nid_objs[864]),/* "telephoneNumber" */
-&(nid_objs[866]),/* "teletexTerminalIdentifier" */
-&(nid_objs[865]),/* "telexNumber" */
-&(nid_objs[459]),/* "textEncodedORAddress" */
-&(nid_objs[293]),/* "textNotice" */
-&(nid_objs[106]),/* "title" */
-&(nid_objs[682]),/* "tpBasis" */
-&(nid_objs[436]),/* "ucl" */
-&(nid_objs[ 0]),/* "undefined" */
-&(nid_objs[888]),/* "uniqueMember" */
-&(nid_objs[55]),/* "unstructuredAddress" */
-&(nid_objs[49]),/* "unstructuredName" */
-&(nid_objs[880]),/* "userCertificate" */
-&(nid_objs[465]),/* "userClass" */
-&(nid_objs[458]),/* "userId" */
-&(nid_objs[879]),/* "userPassword" */
-&(nid_objs[373]),/* "valid" */
-&(nid_objs[678]),/* "wap" */
-&(nid_objs[679]),/* "wap-wsg" */
-&(nid_objs[735]),/* "wap-wsg-idm-ecid-wtls1" */
-&(nid_objs[743]),/* "wap-wsg-idm-ecid-wtls10" */
-&(nid_objs[744]),/* "wap-wsg-idm-ecid-wtls11" */
-&(nid_objs[745]),/* "wap-wsg-idm-ecid-wtls12" */
-&(nid_objs[736]),/* "wap-wsg-idm-ecid-wtls3" */
-&(nid_objs[737]),/* "wap-wsg-idm-ecid-wtls4" */
-&(nid_objs[738]),/* "wap-wsg-idm-ecid-wtls5" */
-&(nid_objs[739]),/* "wap-wsg-idm-ecid-wtls6" */
-&(nid_objs[740]),/* "wap-wsg-idm-ecid-wtls7" */
-&(nid_objs[741]),/* "wap-wsg-idm-ecid-wtls8" */
-&(nid_objs[742]),/* "wap-wsg-idm-ecid-wtls9" */
-&(nid_objs[804]),/* "whirlpool" */
-&(nid_objs[868]),/* "x121Address" */
-&(nid_objs[503]),/* "x500UniqueIdentifier" */
-&(nid_objs[158]),/* "x509Certificate" */
-&(nid_objs[160]),/* "x509Crl" */
-&(nid_objs[125]),/* "zlib compression" */
+static const unsigned int ln_objs[NUM_LN]={
+363,   /* "AD Time Stamping" */
+405,   /* "ANSI X9.62" */
+368,   /* "Acceptable OCSP Responses" */
+664,   /* "Any language" */
+177,   /* "Authority Information Access" */
+365,   /* "Basic OCSP Response" */
+285,   /* "Biometric Info" */
+179,   /* "CA Issuers" */
+785,   /* "CA Repository" */
+131,   /* "Code Signing" */
+783,   /* "Diffie-Hellman based MAC" */
+382,   /* "Directory" */
+392,   /* "Domain" */
+132,   /* "E-mail Protection" */
+389,   /* "Enterprises" */
+384,   /* "Experimental" */
+372,   /* "Extended OCSP Status" */
+172,   /* "Extension Request" */
+813,   /* "GOST 28147-89" */
+849,   /* "GOST 28147-89 Cryptocom ParamSet" */
+815,   /* "GOST 28147-89 MAC" */
+851,   /* "GOST 34.10-2001 Cryptocom" */
+850,   /* "GOST 34.10-94 Cryptocom" */
+811,   /* "GOST R 34.10-2001" */
+817,   /* "GOST R 34.10-2001 DH" */
+812,   /* "GOST R 34.10-94" */
+818,   /* "GOST R 34.10-94 DH" */
+809,   /* "GOST R 34.11-94" */
+816,   /* "GOST R 34.11-94 PRF" */
+807,   /* "GOST R 34.11-94 with GOST R 34.10-2001" */
+853,   /* "GOST R 34.11-94 with GOST R 34.10-2001 Cryptocom" */
+808,   /* "GOST R 34.11-94 with GOST R 34.10-94" */
+852,   /* "GOST R 34.11-94 with GOST R 34.10-94 Cryptocom" */
+854,   /* "GOST R 3410-2001 Parameter Set Cryptocom" */
+810,   /* "HMAC GOST 34.11-94" */
+432,   /* "Hold Instruction Call Issuer" */
+430,   /* "Hold Instruction Code" */
+431,   /* "Hold Instruction None" */
+433,   /* "Hold Instruction Reject" */
+634,   /* "ICC or token signature" */
+294,   /* "IPSec End System" */
+295,   /* "IPSec Tunnel" */
+296,   /* "IPSec User" */
+182,   /* "ISO Member Body" */
+183,   /* "ISO US Member Body" */
+667,   /* "Independent" */
+665,   /* "Inherit all" */
+647,   /* "International Organizations" */
+142,   /* "Invalidity Date" */
+504,   /* "MIME MHS" */
+388,   /* "Mail" */
+383,   /* "Management" */
+417,   /* "Microsoft CSP Name" */
+135,   /* "Microsoft Commercial Code Signing" */
+138,   /* "Microsoft Encrypted File System" */
+171,   /* "Microsoft Extension Request" */
+134,   /* "Microsoft Individual Code Signing" */
+856,   /* "Microsoft Local Key set" */
+137,   /* "Microsoft Server Gated Crypto" */
+648,   /* "Microsoft Smartcardlogin" */
+136,   /* "Microsoft Trust List Signing" */
+649,   /* "Microsoft Universal Principal Name" */
+393,   /* "NULL" */
+404,   /* "NULL" */
+72,    /* "Netscape Base Url" */
+76,    /* "Netscape CA Policy Url" */
+74,    /* "Netscape CA Revocation Url" */
+71,    /* "Netscape Cert Type" */
+58,    /* "Netscape Certificate Extension" */
+79,    /* "Netscape Certificate Sequence" */
+78,    /* "Netscape Comment" */
+57,    /* "Netscape Communications Corp." */
+59,    /* "Netscape Data Type" */
+75,    /* "Netscape Renewal Url" */
+73,    /* "Netscape Revocation Url" */
+77,    /* "Netscape SSL Server Name" */
+139,   /* "Netscape Server Gated Crypto" */
+178,   /* "OCSP" */
+370,   /* "OCSP Archive Cutoff" */
+367,   /* "OCSP CRL ID" */
+369,   /* "OCSP No Check" */
+366,   /* "OCSP Nonce" */
+371,   /* "OCSP Service Locator" */
+180,   /* "OCSP Signing" */
+161,   /* "PBES2" */
+69,    /* "PBKDF2" */
+162,   /* "PBMAC1" */
+127,   /* "PKIX" */
+858,   /* "Permanent Identifier" */
+164,   /* "Policy Qualifier CPS" */
+165,   /* "Policy Qualifier User Notice" */
+385,   /* "Private" */
+663,   /* "Proxy Certificate Information" */
+ 1,    /* "RSA Data Security, Inc." */
+ 2,    /* "RSA Data Security, Inc. PKCS" */
+188,   /* "S/MIME" */
+167,   /* "S/MIME Capabilities" */
+387,   /* "SNMPv2" */
+512,   /* "Secure Electronic Transactions" */
+386,   /* "Security" */
+394,   /* "Selected Attribute Types" */
+143,   /* "Strong Extranet ID" */
+398,   /* "Subject Information Access" */
+130,   /* "TLS Web Client Authentication" */
+129,   /* "TLS Web Server Authentication" */
+133,   /* "Time Stamping" */
+375,   /* "Trust Root" */
+12,    /* "X509" */
+402,   /* "X509v3 AC Targeting" */
+746,   /* "X509v3 Any Policy" */
+90,    /* "X509v3 Authority Key Identifier" */
+87,    /* "X509v3 Basic Constraints" */
+103,   /* "X509v3 CRL Distribution Points" */
+88,    /* "X509v3 CRL Number" */
+141,   /* "X509v3 CRL Reason Code" */
+771,   /* "X509v3 Certificate Issuer" */
+89,    /* "X509v3 Certificate Policies" */
+140,   /* "X509v3 Delta CRL Indicator" */
+126,   /* "X509v3 Extended Key Usage" */
+857,   /* "X509v3 Freshest CRL" */
+748,   /* "X509v3 Inhibit Any Policy" */
+86,    /* "X509v3 Issuer Alternative Name" */
+770,   /* "X509v3 Issuing Distrubution Point" */
+83,    /* "X509v3 Key Usage" */
+666,   /* "X509v3 Name Constraints" */
+403,   /* "X509v3 No Revocation Available" */
+401,   /* "X509v3 Policy Constraints" */
+747,   /* "X509v3 Policy Mappings" */
+84,    /* "X509v3 Private Key Usage Period" */
+85,    /* "X509v3 Subject Alternative Name" */
+769,   /* "X509v3 Subject Directory Attributes" */
+82,    /* "X509v3 Subject Key Identifier" */
+184,   /* "X9.57" */
+185,   /* "X9.57 CM ?" */
+478,   /* "aRecord" */
+289,   /* "aaControls" */
+287,   /* "ac-auditEntity" */
+397,   /* "ac-proxying" */
+288,   /* "ac-targeting" */
+446,   /* "account" */
+364,   /* "ad dvcs" */
+606,   /* "additional verification" */
+419,   /* "aes-128-cbc" */
+421,   /* "aes-128-cfb" */
+650,   /* "aes-128-cfb1" */
+653,   /* "aes-128-cfb8" */
+418,   /* "aes-128-ecb" */
+420,   /* "aes-128-ofb" */
+423,   /* "aes-192-cbc" */
+425,   /* "aes-192-cfb" */
+651,   /* "aes-192-cfb1" */
+654,   /* "aes-192-cfb8" */
+422,   /* "aes-192-ecb" */
+424,   /* "aes-192-ofb" */
+427,   /* "aes-256-cbc" */
+429,   /* "aes-256-cfb" */
+652,   /* "aes-256-cfb1" */
+655,   /* "aes-256-cfb8" */
+426,   /* "aes-256-ecb" */
+428,   /* "aes-256-ofb" */
+376,   /* "algorithm" */
+484,   /* "associatedDomain" */
+485,   /* "associatedName" */
+501,   /* "audio" */
+882,   /* "authorityRevocationList" */
+91,    /* "bf-cbc" */
+93,    /* "bf-cfb" */
+92,    /* "bf-ecb" */
+94,    /* "bf-ofb" */
+494,   /* "buildingName" */
+860,   /* "businessCategory" */
+691,   /* "c2onb191v4" */
+692,   /* "c2onb191v5" */
+697,   /* "c2onb239v4" */
+698,   /* "c2onb239v5" */
+684,   /* "c2pnb163v1" */
+685,   /* "c2pnb163v2" */
+686,   /* "c2pnb163v3" */
+687,   /* "c2pnb176v1" */
+693,   /* "c2pnb208w1" */
+699,   /* "c2pnb272w1" */
+700,   /* "c2pnb304w1" */
+702,   /* "c2pnb368w1" */
+688,   /* "c2tnb191v1" */
+689,   /* "c2tnb191v2" */
+690,   /* "c2tnb191v3" */
+694,   /* "c2tnb239v1" */
+695,   /* "c2tnb239v2" */
+696,   /* "c2tnb239v3" */
+701,   /* "c2tnb359v1" */
+703,   /* "c2tnb431r1" */
+881,   /* "cACertificate" */
+483,   /* "cNAMERecord" */
+751,   /* "camellia-128-cbc" */
+757,   /* "camellia-128-cfb" */
+760,   /* "camellia-128-cfb1" */
+763,   /* "camellia-128-cfb8" */
+754,   /* "camellia-128-ecb" */
+766,   /* "camellia-128-ofb" */
+752,   /* "camellia-192-cbc" */
+758,   /* "camellia-192-cfb" */
+761,   /* "camellia-192-cfb1" */
+764,   /* "camellia-192-cfb8" */
+755,   /* "camellia-192-ecb" */
+767,   /* "camellia-192-ofb" */
+753,   /* "camellia-256-cbc" */
+759,   /* "camellia-256-cfb" */
+762,   /* "camellia-256-cfb1" */
+765,   /* "camellia-256-cfb8" */
+756,   /* "camellia-256-ecb" */
+768,   /* "camellia-256-ofb" */
+443,   /* "caseIgnoreIA5StringSyntax" */
+108,   /* "cast5-cbc" */
+110,   /* "cast5-cfb" */
+109,   /* "cast5-ecb" */
+111,   /* "cast5-ofb" */
+152,   /* "certBag" */
+677,   /* "certicom-arc" */
+517,   /* "certificate extensions" */
+883,   /* "certificateRevocationList" */
+54,    /* "challengePassword" */
+407,   /* "characteristic-two-field" */
+395,   /* "clearance" */
+633,   /* "cleartext track 2" */
+13,    /* "commonName" */
+513,   /* "content types" */
+50,    /* "contentType" */
+53,    /* "countersignature" */
+14,    /* "countryName" */
+153,   /* "crlBag" */
+884,   /* "crossCertificatePair" */
+806,   /* "cryptocom" */
+805,   /* "cryptopro" */
+500,   /* "dITRedirect" */
+451,   /* "dNSDomain" */
+495,   /* "dSAQuality" */
+434,   /* "data" */
+390,   /* "dcObject" */
+891,   /* "deltaRevocationList" */
+31,    /* "des-cbc" */
+643,   /* "des-cdmf" */
+30,    /* "des-cfb" */
+656,   /* "des-cfb1" */
+657,   /* "des-cfb8" */
+29,    /* "des-ecb" */
+32,    /* "des-ede" */
+43,    /* "des-ede-cbc" */
+60,    /* "des-ede-cfb" */
+62,    /* "des-ede-ofb" */
+33,    /* "des-ede3" */
+44,    /* "des-ede3-cbc" */
+61,    /* "des-ede3-cfb" */
+658,   /* "des-ede3-cfb1" */
+659,   /* "des-ede3-cfb8" */
+63,    /* "des-ede3-ofb" */
+45,    /* "des-ofb" */
+107,   /* "description" */
+871,   /* "destinationIndicator" */
+80,    /* "desx-cbc" */
+28,    /* "dhKeyAgreement" */
+11,    /* "directory services (X.500)" */
+378,   /* "directory services - algorithms" */
+887,   /* "distinguishedName" */
+892,   /* "dmdName" */
+174,   /* "dnQualifier" */
+447,   /* "document" */
+471,   /* "documentAuthor" */
+468,   /* "documentIdentifier" */
+472,   /* "documentLocation" */
+502,   /* "documentPublisher" */
+449,   /* "documentSeries" */
+469,   /* "documentTitle" */
+470,   /* "documentVersion" */
+380,   /* "dod" */
+391,   /* "domainComponent" */
+452,   /* "domainRelatedObject" */
+116,   /* "dsaEncryption" */
+67,    /* "dsaEncryption-old" */
+66,    /* "dsaWithSHA" */
+113,   /* "dsaWithSHA1" */
+70,    /* "dsaWithSHA1-old" */
+802,   /* "dsa_with_SHA224" */
+803,   /* "dsa_with_SHA256" */
+297,   /* "dvcs" */
+791,   /* "ecdsa-with-Recommended" */
+416,   /* "ecdsa-with-SHA1" */
+793,   /* "ecdsa-with-SHA224" */
+794,   /* "ecdsa-with-SHA256" */
+795,   /* "ecdsa-with-SHA384" */
+796,   /* "ecdsa-with-SHA512" */
+792,   /* "ecdsa-with-Specified" */
+48,    /* "emailAddress" */
+632,   /* "encrypted track 2" */
+885,   /* "enhancedSearchGuide" */
+56,    /* "extendedCertificateAttributes" */
+867,   /* "facsimileTelephoneNumber" */
+462,   /* "favouriteDrink" */
+453,   /* "friendlyCountry" */
+490,   /* "friendlyCountryName" */
+156,   /* "friendlyName" */
+631,   /* "generate cryptogram" */
+509,   /* "generationQualifier" */
+601,   /* "generic cryptogram" */
+99,    /* "givenName" */
+814,   /* "gost89-cnt" */
+855,   /* "hmac" */
+780,   /* "hmac-md5" */
+781,   /* "hmac-sha1" */
+797,   /* "hmacWithMD5" */
+163,   /* "hmacWithSHA1" */
+798,   /* "hmacWithSHA224" */
+799,   /* "hmacWithSHA256" */
+800,   /* "hmacWithSHA384" */
+801,   /* "hmacWithSHA512" */
+486,   /* "homePostalAddress" */
+473,   /* "homeTelephoneNumber" */
+466,   /* "host" */
+889,   /* "houseIdentifier" */
+442,   /* "iA5StringSyntax" */
+381,   /* "iana" */
+824,   /* "id-Gost28147-89-CryptoPro-A-ParamSet" */
+825,   /* "id-Gost28147-89-CryptoPro-B-ParamSet" */
+826,   /* "id-Gost28147-89-CryptoPro-C-ParamSet" */
+827,   /* "id-Gost28147-89-CryptoPro-D-ParamSet" */
+819,   /* "id-Gost28147-89-CryptoPro-KeyMeshing" */
+829,   /* "id-Gost28147-89-CryptoPro-Oscar-1-0-ParamSet" */
+828,   /* "id-Gost28147-89-CryptoPro-Oscar-1-1-ParamSet" */
+830,   /* "id-Gost28147-89-CryptoPro-RIC-1-ParamSet" */
+820,   /* "id-Gost28147-89-None-KeyMeshing" */
+823,   /* "id-Gost28147-89-TestParamSet" */
+840,   /* "id-GostR3410-2001-CryptoPro-A-ParamSet" */
+841,   /* "id-GostR3410-2001-CryptoPro-B-ParamSet" */
+842,   /* "id-GostR3410-2001-CryptoPro-C-ParamSet" */
+843,   /* "id-GostR3410-2001-CryptoPro-XchA-ParamSet" */
+844,   /* "id-GostR3410-2001-CryptoPro-XchB-ParamSet" */
+839,   /* "id-GostR3410-2001-TestParamSet" */
+832,   /* "id-GostR3410-94-CryptoPro-A-ParamSet" */
+833,   /* "id-GostR3410-94-CryptoPro-B-ParamSet" */
+834,   /* "id-GostR3410-94-CryptoPro-C-ParamSet" */
+835,   /* "id-GostR3410-94-CryptoPro-D-ParamSet" */
+836,   /* "id-GostR3410-94-CryptoPro-XchA-ParamSet" */
+837,   /* "id-GostR3410-94-CryptoPro-XchB-ParamSet" */
+838,   /* "id-GostR3410-94-CryptoPro-XchC-ParamSet" */
+831,   /* "id-GostR3410-94-TestParamSet" */
+845,   /* "id-GostR3410-94-a" */
+846,   /* "id-GostR3410-94-aBis" */
+847,   /* "id-GostR3410-94-b" */
+848,   /* "id-GostR3410-94-bBis" */
+822,   /* "id-GostR3411-94-CryptoProParamSet" */
+821,   /* "id-GostR3411-94-TestParamSet" */
+266,   /* "id-aca" */
+355,   /* "id-aca-accessIdentity" */
+354,   /* "id-aca-authenticationInfo" */
+356,   /* "id-aca-chargingIdentity" */
+399,   /* "id-aca-encAttrs" */
+357,   /* "id-aca-group" */
+358,   /* "id-aca-role" */
+176,   /* "id-ad" */
+788,   /* "id-aes128-wrap" */
+789,   /* "id-aes192-wrap" */
+790,   /* "id-aes256-wrap" */
+262,   /* "id-alg" */
+323,   /* "id-alg-des40" */
+326,   /* "id-alg-dh-pop" */
+325,   /* "id-alg-dh-sig-hmac-sha1" */
+324,   /* "id-alg-noSignature" */
+268,   /* "id-cct" */
+361,   /* "id-cct-PKIData" */
+362,   /* "id-cct-PKIResponse" */
+360,   /* "id-cct-crs" */
+81,    /* "id-ce" */
+680,   /* "id-characteristic-two-basis" */
+263,   /* "id-cmc" */
+334,   /* "id-cmc-addExtensions" */
+346,   /* "id-cmc-confirmCertAcceptance" */
+330,   /* "id-cmc-dataReturn" */
+336,   /* "id-cmc-decryptedPOP" */
+335,   /* "id-cmc-encryptedPOP" */
+339,   /* "id-cmc-getCRL" */
+338,   /* "id-cmc-getCert" */
+328,   /* "id-cmc-identification" */
+329,   /* "id-cmc-identityProof" */
+337,   /* "id-cmc-lraPOPWitness" */
+344,   /* "id-cmc-popLinkRandom" */
+345,   /* "id-cmc-popLinkWitness" */
+343,   /* "id-cmc-queryPending" */
+333,   /* "id-cmc-recipientNonce" */
+341,   /* "id-cmc-regInfo" */
+342,   /* "id-cmc-responseInfo" */
+340,   /* "id-cmc-revokeRequest" */
+332,   /* "id-cmc-senderNonce" */
+327,   /* "id-cmc-statusInfo" */
+331,   /* "id-cmc-transactionId" */
+787,   /* "id-ct-asciiTextWithCRLF" */
+408,   /* "id-ecPublicKey" */
+508,   /* "id-hex-multipart-message" */
+507,   /* "id-hex-partial-message" */
+260,   /* "id-it" */
+302,   /* "id-it-caKeyUpdateInfo" */
+298,   /* "id-it-caProtEncCert" */
+311,   /* "id-it-confirmWaitTime" */
+303,   /* "id-it-currentCRL" */
+300,   /* "id-it-encKeyPairTypes" */
+310,   /* "id-it-implicitConfirm" */
+308,   /* "id-it-keyPairParamRep" */
+307,   /* "id-it-keyPairParamReq" */
+312,   /* "id-it-origPKIMessage" */
+301,   /* "id-it-preferredSymmAlg" */
+309,   /* "id-it-revPassphrase" */
+299,   /* "id-it-signKeyPairTypes" */
+305,   /* "id-it-subscriptionRequest" */
+306,   /* "id-it-subscriptionResponse" */
+784,   /* "id-it-suppLangTags" */
+304,   /* "id-it-unsupportedOIDs" */
+128,   /* "id-kp" */
+280,   /* "id-mod-attribute-cert" */
+274,   /* "id-mod-cmc" */
+277,   /* "id-mod-cmp" */
+284,   /* "id-mod-cmp2000" */
+273,   /* "id-mod-crmf" */
+283,   /* "id-mod-dvcs" */
+275,   /* "id-mod-kea-profile-88" */
+276,   /* "id-mod-kea-profile-93" */
+282,   /* "id-mod-ocsp" */
+278,   /* "id-mod-qualified-cert-88" */
+279,   /* "id-mod-qualified-cert-93" */
+281,   /* "id-mod-timestamp-protocol" */
+264,   /* "id-on" */
+347,   /* "id-on-personalData" */
+265,   /* "id-pda" */
+352,   /* "id-pda-countryOfCitizenship" */
+353,   /* "id-pda-countryOfResidence" */
+348,   /* "id-pda-dateOfBirth" */
+351,   /* "id-pda-gender" */
+349,   /* "id-pda-placeOfBirth" */
+175,   /* "id-pe" */
+261,   /* "id-pkip" */
+258,   /* "id-pkix-mod" */
+269,   /* "id-pkix1-explicit-88" */
+271,   /* "id-pkix1-explicit-93" */
+270,   /* "id-pkix1-implicit-88" */
+272,   /* "id-pkix1-implicit-93" */
+662,   /* "id-ppl" */
+267,   /* "id-qcs" */
+359,   /* "id-qcs-pkixQCSyntax-v1" */
+259,   /* "id-qt" */
+313,   /* "id-regCtrl" */
+316,   /* "id-regCtrl-authenticator" */
+319,   /* "id-regCtrl-oldCertID" */
+318,   /* "id-regCtrl-pkiArchiveOptions" */
+317,   /* "id-regCtrl-pkiPublicationInfo" */
+320,   /* "id-regCtrl-protocolEncrKey" */
+315,   /* "id-regCtrl-regToken" */
+314,   /* "id-regInfo" */
+322,   /* "id-regInfo-certReq" */
+321,   /* "id-regInfo-utf8Pairs" */
+191,   /* "id-smime-aa" */
+215,   /* "id-smime-aa-contentHint" */
+218,   /* "id-smime-aa-contentIdentifier" */
+221,   /* "id-smime-aa-contentReference" */
+240,   /* "id-smime-aa-dvcs-dvc" */
+217,   /* "id-smime-aa-encapContentType" */
+222,   /* "id-smime-aa-encrypKeyPref" */
+220,   /* "id-smime-aa-equivalentLabels" */
+232,   /* "id-smime-aa-ets-CertificateRefs" */
+233,   /* "id-smime-aa-ets-RevocationRefs" */
+238,   /* "id-smime-aa-ets-archiveTimeStamp" */
+237,   /* "id-smime-aa-ets-certCRLTimestamp" */
+234,   /* "id-smime-aa-ets-certValues" */
+227,   /* "id-smime-aa-ets-commitmentType" */
+231,   /* "id-smime-aa-ets-contentTimestamp" */
+236,   /* "id-smime-aa-ets-escTimeStamp" */
+230,   /* "id-smime-aa-ets-otherSigCert" */
+235,   /* "id-smime-aa-ets-revocationValues" */
+226,   /* "id-smime-aa-ets-sigPolicyId" */
+229,   /* "id-smime-aa-ets-signerAttr" */
+228,   /* "id-smime-aa-ets-signerLocation" */
+219,   /* "id-smime-aa-macValue" */
+214,   /* "id-smime-aa-mlExpandHistory" */
+216,   /* "id-smime-aa-msgSigDigest" */
+212,   /* "id-smime-aa-receiptRequest" */
+213,   /* "id-smime-aa-securityLabel" */
+239,   /* "id-smime-aa-signatureType" */
+223,   /* "id-smime-aa-signingCertificate" */
+224,   /* "id-smime-aa-smimeEncryptCerts" */
+225,   /* "id-smime-aa-timeStampToken" */
+192,   /* "id-smime-alg" */
+243,   /* "id-smime-alg-3DESwrap" */
+246,   /* "id-smime-alg-CMS3DESwrap" */
+247,   /* "id-smime-alg-CMSRC2wrap" */
+245,   /* "id-smime-alg-ESDH" */
+241,   /* "id-smime-alg-ESDHwith3DES" */
+242,   /* "id-smime-alg-ESDHwithRC2" */
+244,   /* "id-smime-alg-RC2wrap" */
+193,   /* "id-smime-cd" */
+248,   /* "id-smime-cd-ldap" */
+190,   /* "id-smime-ct" */
+210,   /* "id-smime-ct-DVCSRequestData" */
+211,   /* "id-smime-ct-DVCSResponseData" */
+208,   /* "id-smime-ct-TDTInfo" */
+207,   /* "id-smime-ct-TSTInfo" */
+205,   /* "id-smime-ct-authData" */
+786,   /* "id-smime-ct-compressedData" */
+209,   /* "id-smime-ct-contentInfo" */
+206,   /* "id-smime-ct-publishCert" */
+204,   /* "id-smime-ct-receipt" */
+195,   /* "id-smime-cti" */
+255,   /* "id-smime-cti-ets-proofOfApproval" */
+256,   /* "id-smime-cti-ets-proofOfCreation" */
+253,   /* "id-smime-cti-ets-proofOfDelivery" */
+251,   /* "id-smime-cti-ets-proofOfOrigin" */
+252,   /* "id-smime-cti-ets-proofOfReceipt" */
+254,   /* "id-smime-cti-ets-proofOfSender" */
+189,   /* "id-smime-mod" */
+196,   /* "id-smime-mod-cms" */
+197,   /* "id-smime-mod-ess" */
+202,   /* "id-smime-mod-ets-eSigPolicy-88" */
+203,   /* "id-smime-mod-ets-eSigPolicy-97" */
+200,   /* "id-smime-mod-ets-eSignature-88" */
+201,   /* "id-smime-mod-ets-eSignature-97" */
+199,   /* "id-smime-mod-msg-v3" */
+198,   /* "id-smime-mod-oid" */
+194,   /* "id-smime-spq" */
+250,   /* "id-smime-spq-ets-sqt-unotice" */
+249,   /* "id-smime-spq-ets-sqt-uri" */
+34,    /* "idea-cbc" */
+35,    /* "idea-cfb" */
+36,    /* "idea-ecb" */
+46,    /* "idea-ofb" */
+676,   /* "identified-organization" */
+461,   /* "info" */
+101,   /* "initials" */
+869,   /* "internationaliSDNNumber" */
+749,   /* "ipsec3" */
+750,   /* "ipsec4" */
+181,   /* "iso" */
+623,   /* "issuer capabilities" */
+645,   /* "itu-t" */
+492,   /* "janetMailbox" */
+646,   /* "joint-iso-itu-t" */
+150,   /* "keyBag" */
+773,   /* "kisa" */
+477,   /* "lastModifiedBy" */
+476,   /* "lastModifiedTime" */
+157,   /* "localKeyID" */
+15,    /* "localityName" */
+480,   /* "mXRecord" */
+493,   /* "mailPreferenceOption" */
+467,   /* "manager" */
+ 3,    /* "md2" */
+ 7,    /* "md2WithRSAEncryption" */
+257,   /* "md4" */
+396,   /* "md4WithRSAEncryption" */
+ 4,    /* "md5" */
+114,   /* "md5-sha1" */
+104,   /* "md5WithRSA" */
+ 8,    /* "md5WithRSAEncryption" */
+95,    /* "mdc2" */
+96,    /* "mdc2WithRSA" */
+875,   /* "member" */
+602,   /* "merchant initiated auth" */
+514,   /* "message extensions" */
+51,    /* "messageDigest" */
+506,   /* "mime-mhs-bodies" */
+505,   /* "mime-mhs-headings" */
+488,   /* "mobileTelephoneNumber" */
+481,   /* "nSRecord" */
+173,   /* "name" */
+681,   /* "onBasis" */
+379,   /* "org" */
+17,    /* "organizationName" */
+491,   /* "organizationalStatus" */
+18,    /* "organizationalUnitName" */
+475,   /* "otherMailbox" */
+876,   /* "owner" */
+489,   /* "pagerTelephoneNumber" */
+782,   /* "password based MAC" */
+374,   /* "path" */
+621,   /* "payment gateway capabilities" */
+ 9,    /* "pbeWithMD2AndDES-CBC" */
+168,   /* "pbeWithMD2AndRC2-CBC" */
+112,   /* "pbeWithMD5AndCast5CBC" */
+10,    /* "pbeWithMD5AndDES-CBC" */
+169,   /* "pbeWithMD5AndRC2-CBC" */
+148,   /* "pbeWithSHA1And128BitRC2-CBC" */
+144,   /* "pbeWithSHA1And128BitRC4" */
+147,   /* "pbeWithSHA1And2-KeyTripleDES-CBC" */
+146,   /* "pbeWithSHA1And3-KeyTripleDES-CBC" */
+149,   /* "pbeWithSHA1And40BitRC2-CBC" */
+145,   /* "pbeWithSHA1And40BitRC4" */
+170,   /* "pbeWithSHA1AndDES-CBC" */
+68,    /* "pbeWithSHA1AndRC2-CBC" */
+499,   /* "personalSignature" */
+487,   /* "personalTitle" */
+464,   /* "photo" */
+863,   /* "physicalDeliveryOfficeName" */
+437,   /* "pilot" */
+439,   /* "pilotAttributeSyntax" */
+438,   /* "pilotAttributeType" */
+479,   /* "pilotAttributeType27" */
+456,   /* "pilotDSA" */
+441,   /* "pilotGroups" */
+444,   /* "pilotObject" */
+440,   /* "pilotObjectClass" */
+455,   /* "pilotOrganization" */
+445,   /* "pilotPerson" */
+186,   /* "pkcs1" */
+27,    /* "pkcs3" */
+187,   /* "pkcs5" */
+20,    /* "pkcs7" */
+21,    /* "pkcs7-data" */
+25,    /* "pkcs7-digestData" */
+26,    /* "pkcs7-encryptedData" */
+23,    /* "pkcs7-envelopedData" */
+24,    /* "pkcs7-signedAndEnvelopedData" */
+22,    /* "pkcs7-signedData" */
+151,   /* "pkcs8ShroudedKeyBag" */
+47,    /* "pkcs9" */
+862,   /* "postOfficeBox" */
+861,   /* "postalAddress" */
+661,   /* "postalCode" */
+683,   /* "ppBasis" */
+872,   /* "preferredDeliveryMethod" */
+873,   /* "presentationAddress" */
+406,   /* "prime-field" */
+409,   /* "prime192v1" */
+410,   /* "prime192v2" */
+411,   /* "prime192v3" */
+412,   /* "prime239v1" */
+413,   /* "prime239v2" */
+414,   /* "prime239v3" */
+415,   /* "prime256v1" */
+886,   /* "protocolInformation" */
+510,   /* "pseudonym" */
+435,   /* "pss" */
+286,   /* "qcStatements" */
+457,   /* "qualityLabelledData" */
+450,   /* "rFC822localPart" */
+98,    /* "rc2-40-cbc" */
+166,   /* "rc2-64-cbc" */
+37,    /* "rc2-cbc" */
+39,    /* "rc2-cfb" */
+38,    /* "rc2-ecb" */
+40,    /* "rc2-ofb" */
+ 5,    /* "rc4" */
+97,    /* "rc4-40" */
+120,   /* "rc5-cbc" */
+122,   /* "rc5-cfb" */
+121,   /* "rc5-ecb" */
+123,   /* "rc5-ofb" */
+870,   /* "registeredAddress" */
+460,   /* "rfc822Mailbox" */
+117,   /* "ripemd160" */
+119,   /* "ripemd160WithRSA" */
+400,   /* "role" */
+877,   /* "roleOccupant" */
+448,   /* "room" */
+463,   /* "roomNumber" */
+19,    /* "rsa" */
+ 6,    /* "rsaEncryption" */
+644,   /* "rsaOAEPEncryptionSET" */
+377,   /* "rsaSignature" */
+124,   /* "run length compression" */
+482,   /* "sOARecord" */
+155,   /* "safeContentsBag" */
+291,   /* "sbgp-autonomousSysNum" */
+290,   /* "sbgp-ipAddrBlock" */
+292,   /* "sbgp-routerIdentifier" */
+159,   /* "sdsiCertificate" */
+859,   /* "searchGuide" */
+704,   /* "secp112r1" */
+705,   /* "secp112r2" */
+706,   /* "secp128r1" */
+707,   /* "secp128r2" */
+708,   /* "secp160k1" */
+709,   /* "secp160r1" */
+710,   /* "secp160r2" */
+711,   /* "secp192k1" */
+712,   /* "secp224k1" */
+713,   /* "secp224r1" */
+714,   /* "secp256k1" */
+715,   /* "secp384r1" */
+716,   /* "secp521r1" */
+154,   /* "secretBag" */
+474,   /* "secretary" */
+717,   /* "sect113r1" */
+718,   /* "sect113r2" */
+719,   /* "sect131r1" */
+720,   /* "sect131r2" */
+721,   /* "sect163k1" */
+722,   /* "sect163r1" */
+723,   /* "sect163r2" */
+724,   /* "sect193r1" */
+725,   /* "sect193r2" */
+726,   /* "sect233k1" */
+727,   /* "sect233r1" */
+728,   /* "sect239k1" */
+729,   /* "sect283k1" */
+730,   /* "sect283r1" */
+731,   /* "sect409k1" */
+732,   /* "sect409r1" */
+733,   /* "sect571k1" */
+734,   /* "sect571r1" */
+635,   /* "secure device signature" */
+878,   /* "seeAlso" */
+777,   /* "seed-cbc" */
+779,   /* "seed-cfb" */
+776,   /* "seed-ecb" */
+778,   /* "seed-ofb" */
+105,   /* "serialNumber" */
+625,   /* "set-addPolicy" */
+515,   /* "set-attr" */
+518,   /* "set-brand" */
+638,   /* "set-brand-AmericanExpress" */
+637,   /* "set-brand-Diners" */
+636,   /* "set-brand-IATA-ATA" */
+639,   /* "set-brand-JCB" */
+641,   /* "set-brand-MasterCard" */
+642,   /* "set-brand-Novus" */
+640,   /* "set-brand-Visa" */
+516,   /* "set-policy" */
+607,   /* "set-policy-root" */
+624,   /* "set-rootKeyThumb" */
+620,   /* "setAttr-Cert" */
+628,   /* "setAttr-IssCap-CVM" */
+630,   /* "setAttr-IssCap-Sig" */
+629,   /* "setAttr-IssCap-T2" */
+627,   /* "setAttr-Token-B0Prime" */
+626,   /* "setAttr-Token-EMV" */
+622,   /* "setAttr-TokenType" */
+619,   /* "setCext-IssuerCapabilities" */
+615,   /* "setCext-PGWYcapabilities" */
+616,   /* "setCext-TokenIdentifier" */
+618,   /* "setCext-TokenType" */
+617,   /* "setCext-Track2Data" */
+611,   /* "setCext-cCertRequired" */
+609,   /* "setCext-certType" */
+608,   /* "setCext-hashedRoot" */
+610,   /* "setCext-merchData" */
+613,   /* "setCext-setExt" */
+614,   /* "setCext-setQualf" */
+612,   /* "setCext-tunneling" */
+540,   /* "setct-AcqCardCodeMsg" */
+576,   /* "setct-AcqCardCodeMsgTBE" */
+570,   /* "setct-AuthReqTBE" */
+534,   /* "setct-AuthReqTBS" */
+527,   /* "setct-AuthResBaggage" */
+571,   /* "setct-AuthResTBE" */
+572,   /* "setct-AuthResTBEX" */
+535,   /* "setct-AuthResTBS" */
+536,   /* "setct-AuthResTBSX" */
+528,   /* "setct-AuthRevReqBaggage" */
+577,   /* "setct-AuthRevReqTBE" */
+541,   /* "setct-AuthRevReqTBS" */
+529,   /* "setct-AuthRevResBaggage" */
+542,   /* "setct-AuthRevResData" */
+578,   /* "setct-AuthRevResTBE" */
+579,   /* "setct-AuthRevResTBEB" */
+543,   /* "setct-AuthRevResTBS" */
+573,   /* "setct-AuthTokenTBE" */
+537,   /* "setct-AuthTokenTBS" */
+600,   /* "setct-BCIDistributionTBS" */
+558,   /* "setct-BatchAdminReqData" */
+592,   /* "setct-BatchAdminReqTBE" */
+559,   /* "setct-BatchAdminResData" */
+593,   /* "setct-BatchAdminResTBE" */
+599,   /* "setct-CRLNotificationResTBS" */
+598,   /* "setct-CRLNotificationTBS" */
+580,   /* "setct-CapReqTBE" */
+581,   /* "setct-CapReqTBEX" */
+544,   /* "setct-CapReqTBS" */
+545,   /* "setct-CapReqTBSX" */
+546,   /* "setct-CapResData" */
+582,   /* "setct-CapResTBE" */
+583,   /* "setct-CapRevReqTBE" */
+584,   /* "setct-CapRevReqTBEX" */
+547,   /* "setct-CapRevReqTBS" */
+548,   /* "setct-CapRevReqTBSX" */
+549,   /* "setct-CapRevResData" */
+585,   /* "setct-CapRevResTBE" */
+538,   /* "setct-CapTokenData" */
+530,   /* "setct-CapTokenSeq" */
+574,   /* "setct-CapTokenTBE" */
+575,   /* "setct-CapTokenTBEX" */
+539,   /* "setct-CapTokenTBS" */
+560,   /* "setct-CardCInitResTBS" */
+566,   /* "setct-CertInqReqTBS" */
+563,   /* "setct-CertReqData" */
+595,   /* "setct-CertReqTBE" */
+596,   /* "setct-CertReqTBEX" */
+564,   /* "setct-CertReqTBS" */
+565,   /* "setct-CertResData" */
+597,   /* "setct-CertResTBE" */
+586,   /* "setct-CredReqTBE" */
+587,   /* "setct-CredReqTBEX" */
+550,   /* "setct-CredReqTBS" */
+551,   /* "setct-CredReqTBSX" */
+552,   /* "setct-CredResData" */
+588,   /* "setct-CredResTBE" */
+589,   /* "setct-CredRevReqTBE" */
+590,   /* "setct-CredRevReqTBEX" */
+553,   /* "setct-CredRevReqTBS" */
+554,   /* "setct-CredRevReqTBSX" */
+555,   /* "setct-CredRevResData" */
+591,   /* "setct-CredRevResTBE" */
+567,   /* "setct-ErrorTBS" */
+526,   /* "setct-HODInput" */
+561,   /* "setct-MeAqCInitResTBS" */
+522,   /* "setct-OIData" */
+519,   /* "setct-PANData" */
+521,   /* "setct-PANOnly" */
+520,   /* "setct-PANToken" */
+556,   /* "setct-PCertReqData" */
+557,   /* "setct-PCertResTBS" */
+523,   /* "setct-PI" */
+532,   /* "setct-PI-TBS" */
+524,   /* "setct-PIData" */
+525,   /* "setct-PIDataUnsigned" */
+568,   /* "setct-PIDualSignedTBE" */
+569,   /* "setct-PIUnsignedTBE" */
+531,   /* "setct-PInitResData" */
+533,   /* "setct-PResData" */
+594,   /* "setct-RegFormReqTBE" */
+562,   /* "setct-RegFormResTBS" */
+604,   /* "setext-pinAny" */
+603,   /* "setext-pinSecure" */
+605,   /* "setext-track2" */
+41,    /* "sha" */
+64,    /* "sha1" */
+115,   /* "sha1WithRSA" */
+65,    /* "sha1WithRSAEncryption" */
+675,   /* "sha224" */
+671,   /* "sha224WithRSAEncryption" */
+672,   /* "sha256" */
+668,   /* "sha256WithRSAEncryption" */
+673,   /* "sha384" */
+669,   /* "sha384WithRSAEncryption" */
+674,   /* "sha512" */
+670,   /* "sha512WithRSAEncryption" */
+42,    /* "shaWithRSAEncryption" */
+52,    /* "signingTime" */
+454,   /* "simpleSecurityObject" */
+496,   /* "singleLevelQuality" */
+16,    /* "stateOrProvinceName" */
+660,   /* "streetAddress" */
+498,   /* "subtreeMaximumQuality" */
+497,   /* "subtreeMinimumQuality" */
+890,   /* "supportedAlgorithms" */
+874,   /* "supportedApplicationContext" */
+100,   /* "surname" */
+864,   /* "telephoneNumber" */
+866,   /* "teletexTerminalIdentifier" */
+865,   /* "telexNumber" */
+459,   /* "textEncodedORAddress" */
+293,   /* "textNotice" */
+106,   /* "title" */
+682,   /* "tpBasis" */
+436,   /* "ucl" */
+ 0,    /* "undefined" */
+888,   /* "uniqueMember" */
+55,    /* "unstructuredAddress" */
+49,    /* "unstructuredName" */
+880,   /* "userCertificate" */
+465,   /* "userClass" */
+458,   /* "userId" */
+879,   /* "userPassword" */
+373,   /* "valid" */
+678,   /* "wap" */
+679,   /* "wap-wsg" */
+735,   /* "wap-wsg-idm-ecid-wtls1" */
+743,   /* "wap-wsg-idm-ecid-wtls10" */
+744,   /* "wap-wsg-idm-ecid-wtls11" */
+745,   /* "wap-wsg-idm-ecid-wtls12" */
+736,   /* "wap-wsg-idm-ecid-wtls3" */
+737,   /* "wap-wsg-idm-ecid-wtls4" */
+738,   /* "wap-wsg-idm-ecid-wtls5" */
+739,   /* "wap-wsg-idm-ecid-wtls6" */
+740,   /* "wap-wsg-idm-ecid-wtls7" */
+741,   /* "wap-wsg-idm-ecid-wtls8" */
+742,   /* "wap-wsg-idm-ecid-wtls9" */
+804,   /* "whirlpool" */
+868,   /* "x121Address" */
+503,   /* "x500UniqueIdentifier" */
+158,   /* "x509Certificate" */
+160,   /* "x509Crl" */
+125,   /* "zlib compression" */
 };
 
-static ASN1_OBJECT *obj_objs[NUM_OBJ]={
-&(nid_objs[ 0]),/* OBJ_undef                        0 */
-&(nid_objs[393]),/* OBJ_joint_iso_ccitt              OBJ_joint_iso_itu_t */
-&(nid_objs[404]),/* OBJ_ccitt                        OBJ_itu_t */
-&(nid_objs[645]),/* OBJ_itu_t                        0 */
-&(nid_objs[434]),/* OBJ_data                         0 9 */
-&(nid_objs[181]),/* OBJ_iso                          1 */
-&(nid_objs[182]),/* OBJ_member_body                  1 2 */
-&(nid_objs[379]),/* OBJ_org                          1 3 */
-&(nid_objs[676]),/* OBJ_identified_organization      1 3 */
-&(nid_objs[646]),/* OBJ_joint_iso_itu_t              2 */
-&(nid_objs[11]),/* OBJ_X500                         2 5 */
-&(nid_objs[647]),/* OBJ_international_organizations  2 23 */
-&(nid_objs[380]),/* OBJ_dod                          1 3 6 */
-&(nid_objs[12]),/* OBJ_X509                         2 5 4 */
-&(nid_objs[378]),/* OBJ_X500algorithms               2 5 8 */
-&(nid_objs[81]),/* OBJ_id_ce                        2 5 29 */
-&(nid_objs[512]),/* OBJ_id_set                       2 23 42 */
-&(nid_objs[678]),/* OBJ_wap                          2 23 43 */
-&(nid_objs[435]),/* OBJ_pss                          0 9 2342 */
-&(nid_objs[183]),/* OBJ_ISO_US                       1 2 840 */
-&(nid_objs[381]),/* OBJ_iana                         1 3 6 1 */
-&(nid_objs[677]),/* OBJ_certicom_arc                 1 3 132 */
-&(nid_objs[394]),/* OBJ_selected_attribute_types     2 5 1 5 */
-&(nid_objs[13]),/* OBJ_commonName                   2 5 4 3 */
-&(nid_objs[100]),/* OBJ_surname                      2 5 4 4 */
-&(nid_objs[105]),/* OBJ_serialNumber                 2 5 4 5 */
-&(nid_objs[14]),/* OBJ_countryName                  2 5 4 6 */
-&(nid_objs[15]),/* OBJ_localityName                 2 5 4 7 */
-&(nid_objs[16]),/* OBJ_stateOrProvinceName          2 5 4 8 */
-&(nid_objs[660]),/* OBJ_streetAddress                2 5 4 9 */
-&(nid_objs[17]),/* OBJ_organizationName             2 5 4 10 */
-&(nid_objs[18]),/* OBJ_organizationalUnitName       2 5 4 11 */
-&(nid_objs[106]),/* OBJ_title                        2 5 4 12 */
-&(nid_objs[107]),/* OBJ_description                  2 5 4 13 */
-&(nid_objs[859]),/* OBJ_searchGuide                  2 5 4 14 */
-&(nid_objs[860]),/* OBJ_businessCategory             2 5 4 15 */
-&(nid_objs[861]),/* OBJ_postalAddress                2 5 4 16 */
-&(nid_objs[661]),/* OBJ_postalCode                   2 5 4 17 */
-&(nid_objs[862]),/* OBJ_postOfficeBox                2 5 4 18 */
-&(nid_objs[863]),/* OBJ_physicalDeliveryOfficeName   2 5 4 19 */
-&(nid_objs[864]),/* OBJ_telephoneNumber              2 5 4 20 */
-&(nid_objs[865]),/* OBJ_telexNumber                  2 5 4 21 */
-&(nid_objs[866]),/* OBJ_teletexTerminalIdentifier    2 5 4 22 */
-&(nid_objs[867]),/* OBJ_facsimileTelephoneNumber     2 5 4 23 */
-&(nid_objs[868]),/* OBJ_x121Address                  2 5 4 24 */
-&(nid_objs[869]),/* OBJ_internationaliSDNNumber      2 5 4 25 */
-&(nid_objs[870]),/* OBJ_registeredAddress            2 5 4 26 */
-&(nid_objs[871]),/* OBJ_destinationIndicator         2 5 4 27 */
-&(nid_objs[872]),/* OBJ_preferredDeliveryMethod      2 5 4 28 */
-&(nid_objs[873]),/* OBJ_presentationAddress          2 5 4 29 */
-&(nid_objs[874]),/* OBJ_supportedApplicationContext  2 5 4 30 */
-&(nid_objs[875]),/* OBJ_member                       2 5 4 31 */
-&(nid_objs[876]),/* OBJ_owner                        2 5 4 32 */
-&(nid_objs[877]),/* OBJ_roleOccupant                 2 5 4 33 */
-&(nid_objs[878]),/* OBJ_seeAlso                      2 5 4 34 */
-&(nid_objs[879]),/* OBJ_userPassword                 2 5 4 35 */
-&(nid_objs[880]),/* OBJ_userCertificate              2 5 4 36 */
-&(nid_objs[881]),/* OBJ_cACertificate                2 5 4 37 */
-&(nid_objs[882]),/* OBJ_authorityRevocationList      2 5 4 38 */
-&(nid_objs[883]),/* OBJ_certificateRevocationList    2 5 4 39 */
-&(nid_objs[884]),/* OBJ_crossCertificatePair         2 5 4 40 */
-&(nid_objs[173]),/* OBJ_name                         2 5 4 41 */
-&(nid_objs[99]),/* OBJ_givenName                    2 5 4 42 */
-&(nid_objs[101]),/* OBJ_initials                     2 5 4 43 */
-&(nid_objs[509]),/* OBJ_generationQualifier          2 5 4 44 */
-&(nid_objs[503]),/* OBJ_x500UniqueIdentifier         2 5 4 45 */
-&(nid_objs[174]),/* OBJ_dnQualifier                  2 5 4 46 */
-&(nid_objs[885]),/* OBJ_enhancedSearchGuide          2 5 4 47 */
-&(nid_objs[886]),/* OBJ_protocolInformation          2 5 4 48 */
-&(nid_objs[887]),/* OBJ_distinguishedName            2 5 4 49 */
-&(nid_objs[888]),/* OBJ_uniqueMember                 2 5 4 50 */
-&(nid_objs[889]),/* OBJ_houseIdentifier              2 5 4 51 */
-&(nid_objs[890]),/* OBJ_supportedAlgorithms          2 5 4 52 */
-&(nid_objs[891]),/* OBJ_deltaRevocationList          2 5 4 53 */
-&(nid_objs[892]),/* OBJ_dmdName                      2 5 4 54 */
-&(nid_objs[510]),/* OBJ_pseudonym                    2 5 4 65 */
-&(nid_objs[400]),/* OBJ_role                         2 5 4 72 */
-&(nid_objs[769]),/* OBJ_subject_directory_attributes 2 5 29 9 */
-&(nid_objs[82]),/* OBJ_subject_key_identifier       2 5 29 14 */
-&(nid_objs[83]),/* OBJ_key_usage                    2 5 29 15 */
-&(nid_objs[84]),/* OBJ_private_key_usage_period     2 5 29 16 */
-&(nid_objs[85]),/* OBJ_subject_alt_name             2 5 29 17 */
-&(nid_objs[86]),/* OBJ_issuer_alt_name              2 5 29 18 */
-&(nid_objs[87]),/* OBJ_basic_constraints            2 5 29 19 */
-&(nid_objs[88]),/* OBJ_crl_number                   2 5 29 20 */
-&(nid_objs[141]),/* OBJ_crl_reason                   2 5 29 21 */
-&(nid_objs[430]),/* OBJ_hold_instruction_code        2 5 29 23 */
-&(nid_objs[142]),/* OBJ_invalidity_date              2 5 29 24 */
-&(nid_objs[140]),/* OBJ_delta_crl                    2 5 29 27 */
-&(nid_objs[770]),/* OBJ_issuing_distribution_point   2 5 29 28 */
-&(nid_objs[771]),/* OBJ_certificate_issuer           2 5 29 29 */
-&(nid_objs[666]),/* OBJ_name_constraints             2 5 29 30 */
-&(nid_objs[103]),/* OBJ_crl_distribution_points      2 5 29 31 */
-&(nid_objs[89]),/* OBJ_certificate_policies         2 5 29 32 */
-&(nid_objs[747]),/* OBJ_policy_mappings              2 5 29 33 */
-&(nid_objs[90]),/* OBJ_authority_key_identifier     2 5 29 35 */
-&(nid_objs[401]),/* OBJ_policy_constraints           2 5 29 36 */
-&(nid_objs[126]),/* OBJ_ext_key_usage                2 5 29 37 */
-&(nid_objs[857]),/* OBJ_freshest_crl                 2 5 29 46 */
-&(nid_objs[748]),/* OBJ_inhibit_any_policy           2 5 29 54 */
-&(nid_objs[402]),/* OBJ_target_information           2 5 29 55 */
-&(nid_objs[403]),/* OBJ_no_rev_avail                 2 5 29 56 */
-&(nid_objs[513]),/* OBJ_set_ctype                    2 23 42 0 */
-&(nid_objs[514]),/* OBJ_set_msgExt                   2 23 42 1 */
-&(nid_objs[515]),/* OBJ_set_attr                     2 23 42 3 */
-&(nid_objs[516]),/* OBJ_set_policy                   2 23 42 5 */
-&(nid_objs[517]),/* OBJ_set_certExt                  2 23 42 7 */
-&(nid_objs[518]),/* OBJ_set_brand                    2 23 42 8 */
-&(nid_objs[679]),/* OBJ_wap_wsg                      2 23 43 1 */
-&(nid_objs[382]),/* OBJ_Directory                    1 3 6 1 1 */
-&(nid_objs[383]),/* OBJ_Management                   1 3 6 1 2 */
-&(nid_objs[384]),/* OBJ_Experimental                 1 3 6 1 3 */
-&(nid_objs[385]),/* OBJ_Private                      1 3 6 1 4 */
-&(nid_objs[386]),/* OBJ_Security                     1 3 6 1 5 */
-&(nid_objs[387]),/* OBJ_SNMPv2                       1 3 6 1 6 */
-&(nid_objs[388]),/* OBJ_Mail                         1 3 6 1 7 */
-&(nid_objs[376]),/* OBJ_algorithm                    1 3 14 3 2 */
-&(nid_objs[395]),/* OBJ_clearance                    2 5 1 5 55 */
-&(nid_objs[19]),/* OBJ_rsa                          2 5 8 1 1 */
-&(nid_objs[96]),/* OBJ_mdc2WithRSA                  2 5 8 3 100 */
-&(nid_objs[95]),/* OBJ_mdc2                         2 5 8 3 101 */
-&(nid_objs[746]),/* OBJ_any_policy                   2 5 29 32 0 */
-&(nid_objs[519]),/* OBJ_setct_PANData                2 23 42 0 0 */
-&(nid_objs[520]),/* OBJ_setct_PANToken               2 23 42 0 1 */
-&(nid_objs[521]),/* OBJ_setct_PANOnly                2 23 42 0 2 */
-&(nid_objs[522]),/* OBJ_setct_OIData                 2 23 42 0 3 */
-&(nid_objs[523]),/* OBJ_setct_PI                     2 23 42 0 4 */
-&(nid_objs[524]),/* OBJ_setct_PIData                 2 23 42 0 5 */
-&(nid_objs[525]),/* OBJ_setct_PIDataUnsigned         2 23 42 0 6 */
-&(nid_objs[526]),/* OBJ_setct_HODInput               2 23 42 0 7 */
-&(nid_objs[527]),/* OBJ_setct_AuthResBaggage         2 23 42 0 8 */
-&(nid_objs[528]),/* OBJ_setct_AuthRevReqBaggage      2 23 42 0 9 */
-&(nid_objs[529]),/* OBJ_setct_AuthRevResBaggage      2 23 42 0 10 */
-&(nid_objs[530]),/* OBJ_setct_CapTokenSeq            2 23 42 0 11 */
-&(nid_objs[531]),/* OBJ_setct_PInitResData           2 23 42 0 12 */
-&(nid_objs[532]),/* OBJ_setct_PI_TBS                 2 23 42 0 13 */
-&(nid_objs[533]),/* OBJ_setct_PResData               2 23 42 0 14 */
-&(nid_objs[534]),/* OBJ_setct_AuthReqTBS             2 23 42 0 16 */
-&(nid_objs[535]),/* OBJ_setct_AuthResTBS             2 23 42 0 17 */
-&(nid_objs[536]),/* OBJ_setct_AuthResTBSX            2 23 42 0 18 */
-&(nid_objs[537]),/* OBJ_setct_AuthTokenTBS           2 23 42 0 19 */
-&(nid_objs[538]),/* OBJ_setct_CapTokenData           2 23 42 0 20 */
-&(nid_objs[539]),/* OBJ_setct_CapTokenTBS            2 23 42 0 21 */
-&(nid_objs[540]),/* OBJ_setct_AcqCardCodeMsg         2 23 42 0 22 */
-&(nid_objs[541]),/* OBJ_setct_AuthRevReqTBS          2 23 42 0 23 */
-&(nid_objs[542]),/* OBJ_setct_AuthRevResData         2 23 42 0 24 */
-&(nid_objs[543]),/* OBJ_setct_AuthRevResTBS          2 23 42 0 25 */
-&(nid_objs[544]),/* OBJ_setct_CapReqTBS              2 23 42 0 26 */
-&(nid_objs[545]),/* OBJ_setct_CapReqTBSX             2 23 42 0 27 */
-&(nid_objs[546]),/* OBJ_setct_CapResData             2 23 42 0 28 */
-&(nid_objs[547]),/* OBJ_setct_CapRevReqTBS           2 23 42 0 29 */
-&(nid_objs[548]),/* OBJ_setct_CapRevReqTBSX          2 23 42 0 30 */
-&(nid_objs[549]),/* OBJ_setct_CapRevResData          2 23 42 0 31 */
-&(nid_objs[550]),/* OBJ_setct_CredReqTBS             2 23 42 0 32 */
-&(nid_objs[551]),/* OBJ_setct_CredReqTBSX            2 23 42 0 33 */
-&(nid_objs[552]),/* OBJ_setct_CredResData            2 23 42 0 34 */
-&(nid_objs[553]),/* OBJ_setct_CredRevReqTBS          2 23 42 0 35 */
-&(nid_objs[554]),/* OBJ_setct_CredRevReqTBSX         2 23 42 0 36 */
-&(nid_objs[555]),/* OBJ_setct_CredRevResData         2 23 42 0 37 */
-&(nid_objs[556]),/* OBJ_setct_PCertReqData           2 23 42 0 38 */
-&(nid_objs[557]),/* OBJ_setct_PCertResTBS            2 23 42 0 39 */
-&(nid_objs[558]),/* OBJ_setct_BatchAdminReqData      2 23 42 0 40 */
-&(nid_objs[559]),/* OBJ_setct_BatchAdminResData      2 23 42 0 41 */
-&(nid_objs[560]),/* OBJ_setct_CardCInitResTBS        2 23 42 0 42 */
-&(nid_objs[561]),/* OBJ_setct_MeAqCInitResTBS        2 23 42 0 43 */
-&(nid_objs[562]),/* OBJ_setct_RegFormResTBS          2 23 42 0 44 */
-&(nid_objs[563]),/* OBJ_setct_CertReqData            2 23 42 0 45 */
-&(nid_objs[564]),/* OBJ_setct_CertReqTBS             2 23 42 0 46 */
-&(nid_objs[565]),/* OBJ_setct_CertResData            2 23 42 0 47 */
-&(nid_objs[566]),/* OBJ_setct_CertInqReqTBS          2 23 42 0 48 */
-&(nid_objs[567]),/* OBJ_setct_ErrorTBS               2 23 42 0 49 */
-&(nid_objs[568]),/* OBJ_setct_PIDualSignedTBE        2 23 42 0 50 */
-&(nid_objs[569]),/* OBJ_setct_PIUnsignedTBE          2 23 42 0 51 */
-&(nid_objs[570]),/* OBJ_setct_AuthReqTBE             2 23 42 0 52 */
-&(nid_objs[571]),/* OBJ_setct_AuthResTBE             2 23 42 0 53 */
-&(nid_objs[572]),/* OBJ_setct_AuthResTBEX            2 23 42 0 54 */
-&(nid_objs[573]),/* OBJ_setct_AuthTokenTBE           2 23 42 0 55 */
-&(nid_objs[574]),/* OBJ_setct_CapTokenTBE            2 23 42 0 56 */
-&(nid_objs[575]),/* OBJ_setct_CapTokenTBEX           2 23 42 0 57 */
-&(nid_objs[576]),/* OBJ_setct_AcqCardCodeMsgTBE      2 23 42 0 58 */
-&(nid_objs[577]),/* OBJ_setct_AuthRevReqTBE          2 23 42 0 59 */
-&(nid_objs[578]),/* OBJ_setct_AuthRevResTBE          2 23 42 0 60 */
-&(nid_objs[579]),/* OBJ_setct_AuthRevResTBEB         2 23 42 0 61 */
-&(nid_objs[580]),/* OBJ_setct_CapReqTBE              2 23 42 0 62 */
-&(nid_objs[581]),/* OBJ_setct_CapReqTBEX             2 23 42 0 63 */
-&(nid_objs[582]),/* OBJ_setct_CapResTBE              2 23 42 0 64 */
-&(nid_objs[583]),/* OBJ_setct_CapRevReqTBE           2 23 42 0 65 */
-&(nid_objs[584]),/* OBJ_setct_CapRevReqTBEX          2 23 42 0 66 */
-&(nid_objs[585]),/* OBJ_setct_CapRevResTBE           2 23 42 0 67 */
-&(nid_objs[586]),/* OBJ_setct_CredReqTBE             2 23 42 0 68 */
-&(nid_objs[587]),/* OBJ_setct_CredReqTBEX            2 23 42 0 69 */
-&(nid_objs[588]),/* OBJ_setct_CredResTBE             2 23 42 0 70 */
-&(nid_objs[589]),/* OBJ_setct_CredRevReqTBE          2 23 42 0 71 */
-&(nid_objs[590]),/* OBJ_setct_CredRevReqTBEX         2 23 42 0 72 */
-&(nid_objs[591]),/* OBJ_setct_CredRevResTBE          2 23 42 0 73 */
-&(nid_objs[592]),/* OBJ_setct_BatchAdminReqTBE       2 23 42 0 74 */
-&(nid_objs[593]),/* OBJ_setct_BatchAdminResTBE       2 23 42 0 75 */
-&(nid_objs[594]),/* OBJ_setct_RegFormReqTBE          2 23 42 0 76 */
-&(nid_objs[595]),/* OBJ_setct_CertReqTBE             2 23 42 0 77 */
-&(nid_objs[596]),/* OBJ_setct_CertReqTBEX            2 23 42 0 78 */
-&(nid_objs[597]),/* OBJ_setct_CertResTBE             2 23 42 0 79 */
-&(nid_objs[598]),/* OBJ_setct_CRLNotificationTBS     2 23 42 0 80 */
-&(nid_objs[599]),/* OBJ_setct_CRLNotificationResTBS  2 23 42 0 81 */
-&(nid_objs[600]),/* OBJ_setct_BCIDistributionTBS     2 23 42 0 82 */
-&(nid_objs[601]),/* OBJ_setext_genCrypt              2 23 42 1 1 */
-&(nid_objs[602]),/* OBJ_setext_miAuth                2 23 42 1 3 */
-&(nid_objs[603]),/* OBJ_setext_pinSecure             2 23 42 1 4 */
-&(nid_objs[604]),/* OBJ_setext_pinAny                2 23 42 1 5 */
-&(nid_objs[605]),/* OBJ_setext_track2                2 23 42 1 7 */
-&(nid_objs[606]),/* OBJ_setext_cv                    2 23 42 1 8 */
-&(nid_objs[620]),/* OBJ_setAttr_Cert                 2 23 42 3 0 */
-&(nid_objs[621]),/* OBJ_setAttr_PGWYcap              2 23 42 3 1 */
-&(nid_objs[622]),/* OBJ_setAttr_TokenType            2 23 42 3 2 */
-&(nid_objs[623]),/* OBJ_setAttr_IssCap               2 23 42 3 3 */
-&(nid_objs[607]),/* OBJ_set_policy_root              2 23 42 5 0 */
-&(nid_objs[608]),/* OBJ_setCext_hashedRoot           2 23 42 7 0 */
-&(nid_objs[609]),/* OBJ_setCext_certType             2 23 42 7 1 */
-&(nid_objs[610]),/* OBJ_setCext_merchData            2 23 42 7 2 */
-&(nid_objs[611]),/* OBJ_setCext_cCertRequired        2 23 42 7 3 */
-&(nid_objs[612]),/* OBJ_setCext_tunneling            2 23 42 7 4 */
-&(nid_objs[613]),/* OBJ_setCext_setExt               2 23 42 7 5 */
-&(nid_objs[614]),/* OBJ_setCext_setQualf             2 23 42 7 6 */
-&(nid_objs[615]),/* OBJ_setCext_PGWYcapabilities     2 23 42 7 7 */
-&(nid_objs[616]),/* OBJ_setCext_TokenIdentifier      2 23 42 7 8 */
-&(nid_objs[617]),/* OBJ_setCext_Track2Data           2 23 42 7 9 */
-&(nid_objs[618]),/* OBJ_setCext_TokenType            2 23 42 7 10 */
-&(nid_objs[619]),/* OBJ_setCext_IssuerCapabilities   2 23 42 7 11 */
-&(nid_objs[636]),/* OBJ_set_brand_IATA_ATA           2 23 42 8 1 */
-&(nid_objs[640]),/* OBJ_set_brand_Visa               2 23 42 8 4 */
-&(nid_objs[641]),/* OBJ_set_brand_MasterCard         2 23 42 8 5 */
-&(nid_objs[637]),/* OBJ_set_brand_Diners             2 23 42 8 30 */
-&(nid_objs[638]),/* OBJ_set_brand_AmericanExpress    2 23 42 8 34 */
-&(nid_objs[639]),/* OBJ_set_brand_JCB                2 23 42 8 35 */
-&(nid_objs[805]),/* OBJ_cryptopro                    1 2 643 2 2 */
-&(nid_objs[806]),/* OBJ_cryptocom                    1 2 643 2 9 */
-&(nid_objs[184]),/* OBJ_X9_57                        1 2 840 10040 */
-&(nid_objs[405]),/* OBJ_ansi_X9_62                   1 2 840 10045 */
-&(nid_objs[389]),/* OBJ_Enterprises                  1 3 6 1 4 1 */
-&(nid_objs[504]),/* OBJ_mime_mhs                     1 3 6 1 7 1 */
-&(nid_objs[104]),/* OBJ_md5WithRSA                   1 3 14 3 2 3 */
-&(nid_objs[29]),/* OBJ_des_ecb                      1 3 14 3 2 6 */
-&(nid_objs[31]),/* OBJ_des_cbc                      1 3 14 3 2 7 */
-&(nid_objs[45]),/* OBJ_des_ofb64                    1 3 14 3 2 8 */
-&(nid_objs[30]),/* OBJ_des_cfb64                    1 3 14 3 2 9 */
-&(nid_objs[377]),/* OBJ_rsaSignature                 1 3 14 3 2 11 */
-&(nid_objs[67]),/* OBJ_dsa_2                        1 3 14 3 2 12 */
-&(nid_objs[66]),/* OBJ_dsaWithSHA                   1 3 14 3 2 13 */
-&(nid_objs[42]),/* OBJ_shaWithRSAEncryption         1 3 14 3 2 15 */
-&(nid_objs[32]),/* OBJ_des_ede_ecb                  1 3 14 3 2 17 */
-&(nid_objs[41]),/* OBJ_sha                          1 3 14 3 2 18 */
-&(nid_objs[64]),/* OBJ_sha1                         1 3 14 3 2 26 */
-&(nid_objs[70]),/* OBJ_dsaWithSHA1_2                1 3 14 3 2 27 */
-&(nid_objs[115]),/* OBJ_sha1WithRSA                  1 3 14 3 2 29 */
-&(nid_objs[117]),/* OBJ_ripemd160                    1 3 36 3 2 1 */
-&(nid_objs[143]),/* OBJ_sxnet                        1 3 101 1 4 1 */
-&(nid_objs[721]),/* OBJ_sect163k1                    1 3 132 0 1 */
-&(nid_objs[722]),/* OBJ_sect163r1                    1 3 132 0 2 */
-&(nid_objs[728]),/* OBJ_sect239k1                    1 3 132 0 3 */
-&(nid_objs[717]),/* OBJ_sect113r1                    1 3 132 0 4 */
-&(nid_objs[718]),/* OBJ_sect113r2                    1 3 132 0 5 */
-&(nid_objs[704]),/* OBJ_secp112r1                    1 3 132 0 6 */
-&(nid_objs[705]),/* OBJ_secp112r2                    1 3 132 0 7 */
-&(nid_objs[709]),/* OBJ_secp160r1                    1 3 132 0 8 */
-&(nid_objs[708]),/* OBJ_secp160k1                    1 3 132 0 9 */
-&(nid_objs[714]),/* OBJ_secp256k1                    1 3 132 0 10 */
-&(nid_objs[723]),/* OBJ_sect163r2                    1 3 132 0 15 */
-&(nid_objs[729]),/* OBJ_sect283k1                    1 3 132 0 16 */
-&(nid_objs[730]),/* OBJ_sect283r1                    1 3 132 0 17 */
-&(nid_objs[719]),/* OBJ_sect131r1                    1 3 132 0 22 */
-&(nid_objs[720]),/* OBJ_sect131r2                    1 3 132 0 23 */
-&(nid_objs[724]),/* OBJ_sect193r1                    1 3 132 0 24 */
-&(nid_objs[725]),/* OBJ_sect193r2                    1 3 132 0 25 */
-&(nid_objs[726]),/* OBJ_sect233k1                    1 3 132 0 26 */
-&(nid_objs[727]),/* OBJ_sect233r1                    1 3 132 0 27 */
-&(nid_objs[706]),/* OBJ_secp128r1                    1 3 132 0 28 */
-&(nid_objs[707]),/* OBJ_secp128r2                    1 3 132 0 29 */
-&(nid_objs[710]),/* OBJ_secp160r2                    1 3 132 0 30 */
-&(nid_objs[711]),/* OBJ_secp192k1                    1 3 132 0 31 */
-&(nid_objs[712]),/* OBJ_secp224k1                    1 3 132 0 32 */
-&(nid_objs[713]),/* OBJ_secp224r1                    1 3 132 0 33 */
-&(nid_objs[715]),/* OBJ_secp384r1                    1 3 132 0 34 */
-&(nid_objs[716]),/* OBJ_secp521r1                    1 3 132 0 35 */
-&(nid_objs[731]),/* OBJ_sect409k1                    1 3 132 0 36 */
-&(nid_objs[732]),/* OBJ_sect409r1                    1 3 132 0 37 */
-&(nid_objs[733]),/* OBJ_sect571k1                    1 3 132 0 38 */
-&(nid_objs[734]),/* OBJ_sect571r1                    1 3 132 0 39 */
-&(nid_objs[624]),/* OBJ_set_rootKeyThumb             2 23 42 3 0 0 */
-&(nid_objs[625]),/* OBJ_set_addPolicy                2 23 42 3 0 1 */
-&(nid_objs[626]),/* OBJ_setAttr_Token_EMV            2 23 42 3 2 1 */
-&(nid_objs[627]),/* OBJ_setAttr_Token_B0Prime        2 23 42 3 2 2 */
-&(nid_objs[628]),/* OBJ_setAttr_IssCap_CVM           2 23 42 3 3 3 */
-&(nid_objs[629]),/* OBJ_setAttr_IssCap_T2            2 23 42 3 3 4 */
-&(nid_objs[630]),/* OBJ_setAttr_IssCap_Sig           2 23 42 3 3 5 */
-&(nid_objs[642]),/* OBJ_set_brand_Novus              2 23 42 8 6011 */
-&(nid_objs[735]),/* OBJ_wap_wsg_idm_ecid_wtls1       2 23 43 1 4 1 */
-&(nid_objs[736]),/* OBJ_wap_wsg_idm_ecid_wtls3       2 23 43 1 4 3 */
-&(nid_objs[737]),/* OBJ_wap_wsg_idm_ecid_wtls4       2 23 43 1 4 4 */
-&(nid_objs[738]),/* OBJ_wap_wsg_idm_ecid_wtls5       2 23 43 1 4 5 */
-&(nid_objs[739]),/* OBJ_wap_wsg_idm_ecid_wtls6       2 23 43 1 4 6 */
-&(nid_objs[740]),/* OBJ_wap_wsg_idm_ecid_wtls7       2 23 43 1 4 7 */
-&(nid_objs[741]),/* OBJ_wap_wsg_idm_ecid_wtls8       2 23 43 1 4 8 */
-&(nid_objs[742]),/* OBJ_wap_wsg_idm_ecid_wtls9       2 23 43 1 4 9 */
-&(nid_objs[743]),/* OBJ_wap_wsg_idm_ecid_wtls10      2 23 43 1 4 10 */
-&(nid_objs[744]),/* OBJ_wap_wsg_idm_ecid_wtls11      2 23 43 1 4 11 */
-&(nid_objs[745]),/* OBJ_wap_wsg_idm_ecid_wtls12      2 23 43 1 4 12 */
-&(nid_objs[804]),/* OBJ_whirlpool                    1 0 10118 3 0 55 */
-&(nid_objs[124]),/* OBJ_rle_compression              1 1 1 1 666 1 */
-&(nid_objs[773]),/* OBJ_kisa                         1 2 410 200004 */
-&(nid_objs[807]),/* OBJ_id_GostR3411_94_with_GostR3410_2001 1 2 643 2 2 3 */
-&(nid_objs[808]),/* OBJ_id_GostR3411_94_with_GostR3410_94 1 2 643 2 2 4 */
-&(nid_objs[809]),/* OBJ_id_GostR3411_94              1 2 643 2 2 9 */
-&(nid_objs[810]),/* OBJ_id_HMACGostR3411_94          1 2 643 2 2 10 */
-&(nid_objs[811]),/* OBJ_id_GostR3410_2001            1 2 643 2 2 19 */
-&(nid_objs[812]),/* OBJ_id_GostR3410_94              1 2 643 2 2 20 */
-&(nid_objs[813]),/* OBJ_id_Gost28147_89              1 2 643 2 2 21 */
-&(nid_objs[815]),/* OBJ_id_Gost28147_89_MAC          1 2 643 2 2 22 */
-&(nid_objs[816]),/* OBJ_id_GostR3411_94_prf          1 2 643 2 2 23 */
-&(nid_objs[817]),/* OBJ_id_GostR3410_2001DH          1 2 643 2 2 98 */
-&(nid_objs[818]),/* OBJ_id_GostR3410_94DH            1 2 643 2 2 99 */
-&(nid_objs[ 1]),/* OBJ_rsadsi                       1 2 840 113549 */
-&(nid_objs[185]),/* OBJ_X9cm                         1 2 840 10040 4 */
-&(nid_objs[127]),/* OBJ_id_pkix                      1 3 6 1 5 5 7 */
-&(nid_objs[505]),/* OBJ_mime_mhs_headings            1 3 6 1 7 1 1 */
-&(nid_objs[506]),/* OBJ_mime_mhs_bodies              1 3 6 1 7 1 2 */
-&(nid_objs[119]),/* OBJ_ripemd160WithRSA             1 3 36 3 3 1 2 */
-&(nid_objs[631]),/* OBJ_setAttr_GenCryptgrm          2 23 42 3 3 3 1 */
-&(nid_objs[632]),/* OBJ_setAttr_T2Enc                2 23 42 3 3 4 1 */
-&(nid_objs[633]),/* OBJ_setAttr_T2cleartxt           2 23 42 3 3 4 2 */
-&(nid_objs[634]),/* OBJ_setAttr_TokICCsig            2 23 42 3 3 5 1 */
-&(nid_objs[635]),/* OBJ_setAttr_SecDevSig            2 23 42 3 3 5 2 */
-&(nid_objs[436]),/* OBJ_ucl                          0 9 2342 19200300 */
-&(nid_objs[820]),/* OBJ_id_Gost28147_89_None_KeyMeshing 1 2 643 2 2 14 0 */
-&(nid_objs[819]),/* OBJ_id_Gost28147_89_CryptoPro_KeyMeshing 1 2 643 2 2 14 1 */
-&(nid_objs[845]),/* OBJ_id_GostR3410_94_a            1 2 643 2 2 20 1 */
-&(nid_objs[846]),/* OBJ_id_GostR3410_94_aBis         1 2 643 2 2 20 2 */
-&(nid_objs[847]),/* OBJ_id_GostR3410_94_b            1 2 643 2 2 20 3 */
-&(nid_objs[848]),/* OBJ_id_GostR3410_94_bBis         1 2 643 2 2 20 4 */
-&(nid_objs[821]),/* OBJ_id_GostR3411_94_TestParamSet 1 2 643 2 2 30 0 */
-&(nid_objs[822]),/* OBJ_id_GostR3411_94_CryptoProParamSet 1 2 643 2 2 30 1 */
-&(nid_objs[823]),/* OBJ_id_Gost28147_89_TestParamSet 1 2 643 2 2 31 0 */
-&(nid_objs[824]),/* OBJ_id_Gost28147_89_CryptoPro_A_ParamSet 1 2 643 2 2 31 1 */
-&(nid_objs[825]),/* OBJ_id_Gost28147_89_CryptoPro_B_ParamSet 1 2 643 2 2 31 2 */
-&(nid_objs[826]),/* OBJ_id_Gost28147_89_CryptoPro_C_ParamSet 1 2 643 2 2 31 3 */
-&(nid_objs[827]),/* OBJ_id_Gost28147_89_CryptoPro_D_ParamSet 1 2 643 2 2 31 4 */
-&(nid_objs[828]),/* OBJ_id_Gost28147_89_CryptoPro_Oscar_1_1_ParamSet 1 2 643 2 2 31 5 */
-&(nid_objs[829]),/* OBJ_id_Gost28147_89_CryptoPro_Oscar_1_0_ParamSet 1 2 643 2 2 31 6 */
-&(nid_objs[830]),/* OBJ_id_Gost28147_89_CryptoPro_RIC_1_ParamSet 1 2 643 2 2 31 7 */
-&(nid_objs[831]),/* OBJ_id_GostR3410_94_TestParamSet 1 2 643 2 2 32 0 */
-&(nid_objs[832]),/* OBJ_id_GostR3410_94_CryptoPro_A_ParamSet 1 2 643 2 2 32 2 */
-&(nid_objs[833]),/* OBJ_id_GostR3410_94_CryptoPro_B_ParamSet 1 2 643 2 2 32 3 */
-&(nid_objs[834]),/* OBJ_id_GostR3410_94_CryptoPro_C_ParamSet 1 2 643 2 2 32 4 */
-&(nid_objs[835]),/* OBJ_id_GostR3410_94_CryptoPro_D_ParamSet 1 2 643 2 2 32 5 */
-&(nid_objs[836]),/* OBJ_id_GostR3410_94_CryptoPro_XchA_ParamSet 1 2 643 2 2 33 1 */
-&(nid_objs[837]),/* OBJ_id_GostR3410_94_CryptoPro_XchB_ParamSet 1 2 643 2 2 33 2 */
-&(nid_objs[838]),/* OBJ_id_GostR3410_94_CryptoPro_XchC_ParamSet 1 2 643 2 2 33 3 */
-&(nid_objs[839]),/* OBJ_id_GostR3410_2001_TestParamSet 1 2 643 2 2 35 0 */
-&(nid_objs[840]),/* OBJ_id_GostR3410_2001_CryptoPro_A_ParamSet 1 2 643 2 2 35 1 */
-&(nid_objs[841]),/* OBJ_id_GostR3410_2001_CryptoPro_B_ParamSet 1 2 643 2 2 35 2 */
-&(nid_objs[842]),/* OBJ_id_GostR3410_2001_CryptoPro_C_ParamSet 1 2 643 2 2 35 3 */
-&(nid_objs[843]),/* OBJ_id_GostR3410_2001_CryptoPro_XchA_ParamSet 1 2 643 2 2 36 0 */
-&(nid_objs[844]),/* OBJ_id_GostR3410_2001_CryptoPro_XchB_ParamSet 1 2 643 2 2 36 1 */
-&(nid_objs[ 2]),/* OBJ_pkcs                         1 2 840 113549 1 */
-&(nid_objs[431]),/* OBJ_hold_instruction_none        1 2 840 10040 2 1 */
-&(nid_objs[432]),/* OBJ_hold_instruction_call_issuer 1 2 840 10040 2 2 */
-&(nid_objs[433]),/* OBJ_hold_instruction_reject      1 2 840 10040 2 3 */
-&(nid_objs[116]),/* OBJ_dsa                          1 2 840 10040 4 1 */
-&(nid_objs[113]),/* OBJ_dsaWithSHA1                  1 2 840 10040 4 3 */
-&(nid_objs[406]),/* OBJ_X9_62_prime_field            1 2 840 10045 1 1 */
-&(nid_objs[407]),/* OBJ_X9_62_characteristic_two_field 1 2 840 10045 1 2 */
-&(nid_objs[408]),/* OBJ_X9_62_id_ecPublicKey         1 2 840 10045 2 1 */
-&(nid_objs[416]),/* OBJ_ecdsa_with_SHA1              1 2 840 10045 4 1 */
-&(nid_objs[791]),/* OBJ_ecdsa_with_Recommended       1 2 840 10045 4 2 */
-&(nid_objs[792]),/* OBJ_ecdsa_with_Specified         1 2 840 10045 4 3 */
-&(nid_objs[258]),/* OBJ_id_pkix_mod                  1 3 6 1 5 5 7 0 */
-&(nid_objs[175]),/* OBJ_id_pe                        1 3 6 1 5 5 7 1 */
-&(nid_objs[259]),/* OBJ_id_qt                        1 3 6 1 5 5 7 2 */
-&(nid_objs[128]),/* OBJ_id_kp                        1 3 6 1 5 5 7 3 */
-&(nid_objs[260]),/* OBJ_id_it                        1 3 6 1 5 5 7 4 */
-&(nid_objs[261]),/* OBJ_id_pkip                      1 3 6 1 5 5 7 5 */
-&(nid_objs[262]),/* OBJ_id_alg                       1 3 6 1 5 5 7 6 */
-&(nid_objs[263]),/* OBJ_id_cmc                       1 3 6 1 5 5 7 7 */
-&(nid_objs[264]),/* OBJ_id_on                        1 3 6 1 5 5 7 8 */
-&(nid_objs[265]),/* OBJ_id_pda                       1 3 6 1 5 5 7 9 */
-&(nid_objs[266]),/* OBJ_id_aca                       1 3 6 1 5 5 7 10 */
-&(nid_objs[267]),/* OBJ_id_qcs                       1 3 6 1 5 5 7 11 */
-&(nid_objs[268]),/* OBJ_id_cct                       1 3 6 1 5 5 7 12 */
-&(nid_objs[662]),/* OBJ_id_ppl                       1 3 6 1 5 5 7 21 */
-&(nid_objs[176]),/* OBJ_id_ad                        1 3 6 1 5 5 7 48 */
-&(nid_objs[507]),/* OBJ_id_hex_partial_message       1 3 6 1 7 1 1 1 */
-&(nid_objs[508]),/* OBJ_id_hex_multipart_message     1 3 6 1 7 1 1 2 */
-&(nid_objs[57]),/* OBJ_netscape                     2 16 840 1 113730 */
-&(nid_objs[754]),/* OBJ_camellia_128_ecb             0 3 4401 5 3 1 9 1 */
-&(nid_objs[766]),/* OBJ_camellia_128_ofb128          0 3 4401 5 3 1 9 3 */
-&(nid_objs[757]),/* OBJ_camellia_128_cfb128          0 3 4401 5 3 1 9 4 */
-&(nid_objs[755]),/* OBJ_camellia_192_ecb             0 3 4401 5 3 1 9 21 */
-&(nid_objs[767]),/* OBJ_camellia_192_ofb128          0 3 4401 5 3 1 9 23 */
-&(nid_objs[758]),/* OBJ_camellia_192_cfb128          0 3 4401 5 3 1 9 24 */
-&(nid_objs[756]),/* OBJ_camellia_256_ecb             0 3 4401 5 3 1 9 41 */
-&(nid_objs[768]),/* OBJ_camellia_256_ofb128          0 3 4401 5 3 1 9 43 */
-&(nid_objs[759]),/* OBJ_camellia_256_cfb128          0 3 4401 5 3 1 9 44 */
-&(nid_objs[437]),/* OBJ_pilot                        0 9 2342 19200300 100 */
-&(nid_objs[776]),/* OBJ_seed_ecb                     1 2 410 200004 1 3 */
-&(nid_objs[777]),/* OBJ_seed_cbc                     1 2 410 200004 1 4 */
-&(nid_objs[779]),/* OBJ_seed_cfb128                  1 2 410 200004 1 5 */
-&(nid_objs[778]),/* OBJ_seed_ofb128                  1 2 410 200004 1 6 */
-&(nid_objs[852]),/* OBJ_id_GostR3411_94_with_GostR3410_94_cc 1 2 643 2 9 1 3 3 */
-&(nid_objs[853]),/* OBJ_id_GostR3411_94_with_GostR3410_2001_cc 1 2 643 2 9 1 3 4 */
-&(nid_objs[850]),/* OBJ_id_GostR3410_94_cc           1 2 643 2 9 1 5 3 */
-&(nid_objs[851]),/* OBJ_id_GostR3410_2001_cc         1 2 643 2 9 1 5 4 */
-&(nid_objs[849]),/* OBJ_id_Gost28147_89_cc           1 2 643 2 9 1 6 1 */
-&(nid_objs[854]),/* OBJ_id_GostR3410_2001_ParamSet_cc 1 2 643 2 9 1 8 1 */
-&(nid_objs[186]),/* OBJ_pkcs1                        1 2 840 113549 1 1 */
-&(nid_objs[27]),/* OBJ_pkcs3                        1 2 840 113549 1 3 */
-&(nid_objs[187]),/* OBJ_pkcs5                        1 2 840 113549 1 5 */
-&(nid_objs[20]),/* OBJ_pkcs7                        1 2 840 113549 1 7 */
-&(nid_objs[47]),/* OBJ_pkcs9                        1 2 840 113549 1 9 */
-&(nid_objs[ 3]),/* OBJ_md2                          1 2 840 113549 2 2 */
-&(nid_objs[257]),/* OBJ_md4                          1 2 840 113549 2 4 */
-&(nid_objs[ 4]),/* OBJ_md5                          1 2 840 113549 2 5 */
-&(nid_objs[797]),/* OBJ_hmacWithMD5                  1 2 840 113549 2 6 */
-&(nid_objs[163]),/* OBJ_hmacWithSHA1                 1 2 840 113549 2 7 */
-&(nid_objs[798]),/* OBJ_hmacWithSHA224               1 2 840 113549 2 8 */
-&(nid_objs[799]),/* OBJ_hmacWithSHA256               1 2 840 113549 2 9 */
-&(nid_objs[800]),/* OBJ_hmacWithSHA384               1 2 840 113549 2 10 */
-&(nid_objs[801]),/* OBJ_hmacWithSHA512               1 2 840 113549 2 11 */
-&(nid_objs[37]),/* OBJ_rc2_cbc                      1 2 840 113549 3 2 */
-&(nid_objs[ 5]),/* OBJ_rc4                          1 2 840 113549 3 4 */
-&(nid_objs[44]),/* OBJ_des_ede3_cbc                 1 2 840 113549 3 7 */
-&(nid_objs[120]),/* OBJ_rc5_cbc                      1 2 840 113549 3 8 */
-&(nid_objs[643]),/* OBJ_des_cdmf                     1 2 840 113549 3 10 */
-&(nid_objs[680]),/* OBJ_X9_62_id_characteristic_two_basis 1 2 840 10045 1 2 3 */
-&(nid_objs[684]),/* OBJ_X9_62_c2pnb163v1             1 2 840 10045 3 0 1 */
-&(nid_objs[685]),/* OBJ_X9_62_c2pnb163v2             1 2 840 10045 3 0 2 */
-&(nid_objs[686]),/* OBJ_X9_62_c2pnb163v3             1 2 840 10045 3 0 3 */
-&(nid_objs[687]),/* OBJ_X9_62_c2pnb176v1             1 2 840 10045 3 0 4 */
-&(nid_objs[688]),/* OBJ_X9_62_c2tnb191v1             1 2 840 10045 3 0 5 */
-&(nid_objs[689]),/* OBJ_X9_62_c2tnb191v2             1 2 840 10045 3 0 6 */
-&(nid_objs[690]),/* OBJ_X9_62_c2tnb191v3             1 2 840 10045 3 0 7 */
-&(nid_objs[691]),/* OBJ_X9_62_c2onb191v4             1 2 840 10045 3 0 8 */
-&(nid_objs[692]),/* OBJ_X9_62_c2onb191v5             1 2 840 10045 3 0 9 */
-&(nid_objs[693]),/* OBJ_X9_62_c2pnb208w1             1 2 840 10045 3 0 10 */
-&(nid_objs[694]),/* OBJ_X9_62_c2tnb239v1             1 2 840 10045 3 0 11 */
-&(nid_objs[695]),/* OBJ_X9_62_c2tnb239v2             1 2 840 10045 3 0 12 */
-&(nid_objs[696]),/* OBJ_X9_62_c2tnb239v3             1 2 840 10045 3 0 13 */
-&(nid_objs[697]),/* OBJ_X9_62_c2onb239v4             1 2 840 10045 3 0 14 */
-&(nid_objs[698]),/* OBJ_X9_62_c2onb239v5             1 2 840 10045 3 0 15 */
-&(nid_objs[699]),/* OBJ_X9_62_c2pnb272w1             1 2 840 10045 3 0 16 */
-&(nid_objs[700]),/* OBJ_X9_62_c2pnb304w1             1 2 840 10045 3 0 17 */
-&(nid_objs[701]),/* OBJ_X9_62_c2tnb359v1             1 2 840 10045 3 0 18 */
-&(nid_objs[702]),/* OBJ_X9_62_c2pnb368w1             1 2 840 10045 3 0 19 */
-&(nid_objs[703]),/* OBJ_X9_62_c2tnb431r1             1 2 840 10045 3 0 20 */
-&(nid_objs[409]),/* OBJ_X9_62_prime192v1             1 2 840 10045 3 1 1 */
-&(nid_objs[410]),/* OBJ_X9_62_prime192v2             1 2 840 10045 3 1 2 */
-&(nid_objs[411]),/* OBJ_X9_62_prime192v3             1 2 840 10045 3 1 3 */
-&(nid_objs[412]),/* OBJ_X9_62_prime239v1             1 2 840 10045 3 1 4 */
-&(nid_objs[413]),/* OBJ_X9_62_prime239v2             1 2 840 10045 3 1 5 */
-&(nid_objs[414]),/* OBJ_X9_62_prime239v3             1 2 840 10045 3 1 6 */
-&(nid_objs[415]),/* OBJ_X9_62_prime256v1             1 2 840 10045 3 1 7 */
-&(nid_objs[793]),/* OBJ_ecdsa_with_SHA224            1 2 840 10045 4 3 1 */
-&(nid_objs[794]),/* OBJ_ecdsa_with_SHA256            1 2 840 10045 4 3 2 */
-&(nid_objs[795]),/* OBJ_ecdsa_with_SHA384            1 2 840 10045 4 3 3 */
-&(nid_objs[796]),/* OBJ_ecdsa_with_SHA512            1 2 840 10045 4 3 4 */
-&(nid_objs[269]),/* OBJ_id_pkix1_explicit_88         1 3 6 1 5 5 7 0 1 */
-&(nid_objs[270]),/* OBJ_id_pkix1_implicit_88         1 3 6 1 5 5 7 0 2 */
-&(nid_objs[271]),/* OBJ_id_pkix1_explicit_93         1 3 6 1 5 5 7 0 3 */
-&(nid_objs[272]),/* OBJ_id_pkix1_implicit_93         1 3 6 1 5 5 7 0 4 */
-&(nid_objs[273]),/* OBJ_id_mod_crmf                  1 3 6 1 5 5 7 0 5 */
-&(nid_objs[274]),/* OBJ_id_mod_cmc                   1 3 6 1 5 5 7 0 6 */
-&(nid_objs[275]),/* OBJ_id_mod_kea_profile_88        1 3 6 1 5 5 7 0 7 */
-&(nid_objs[276]),/* OBJ_id_mod_kea_profile_93        1 3 6 1 5 5 7 0 8 */
-&(nid_objs[277]),/* OBJ_id_mod_cmp                   1 3 6 1 5 5 7 0 9 */
-&(nid_objs[278]),/* OBJ_id_mod_qualified_cert_88     1 3 6 1 5 5 7 0 10 */
-&(nid_objs[279]),/* OBJ_id_mod_qualified_cert_93     1 3 6 1 5 5 7 0 11 */
-&(nid_objs[280]),/* OBJ_id_mod_attribute_cert        1 3 6 1 5 5 7 0 12 */
-&(nid_objs[281]),/* OBJ_id_mod_timestamp_protocol    1 3 6 1 5 5 7 0 13 */
-&(nid_objs[282]),/* OBJ_id_mod_ocsp                  1 3 6 1 5 5 7 0 14 */
-&(nid_objs[283]),/* OBJ_id_mod_dvcs                  1 3 6 1 5 5 7 0 15 */
-&(nid_objs[284]),/* OBJ_id_mod_cmp2000               1 3 6 1 5 5 7 0 16 */
-&(nid_objs[177]),/* OBJ_info_access                  1 3 6 1 5 5 7 1 1 */
-&(nid_objs[285]),/* OBJ_biometricInfo                1 3 6 1 5 5 7 1 2 */
-&(nid_objs[286]),/* OBJ_qcStatements                 1 3 6 1 5 5 7 1 3 */
-&(nid_objs[287]),/* OBJ_ac_auditEntity               1 3 6 1 5 5 7 1 4 */
-&(nid_objs[288]),/* OBJ_ac_targeting                 1 3 6 1 5 5 7 1 5 */
-&(nid_objs[289]),/* OBJ_aaControls                   1 3 6 1 5 5 7 1 6 */
-&(nid_objs[290]),/* OBJ_sbgp_ipAddrBlock             1 3 6 1 5 5 7 1 7 */
-&(nid_objs[291]),/* OBJ_sbgp_autonomousSysNum        1 3 6 1 5 5 7 1 8 */
-&(nid_objs[292]),/* OBJ_sbgp_routerIdentifier        1 3 6 1 5 5 7 1 9 */
-&(nid_objs[397]),/* OBJ_ac_proxying                  1 3 6 1 5 5 7 1 10 */
-&(nid_objs[398]),/* OBJ_sinfo_access                 1 3 6 1 5 5 7 1 11 */
-&(nid_objs[663]),/* OBJ_proxyCertInfo                1 3 6 1 5 5 7 1 14 */
-&(nid_objs[164]),/* OBJ_id_qt_cps                    1 3 6 1 5 5 7 2 1 */
-&(nid_objs[165]),/* OBJ_id_qt_unotice                1 3 6 1 5 5 7 2 2 */
-&(nid_objs[293]),/* OBJ_textNotice                   1 3 6 1 5 5 7 2 3 */
-&(nid_objs[129]),/* OBJ_server_auth                  1 3 6 1 5 5 7 3 1 */
-&(nid_objs[130]),/* OBJ_client_auth                  1 3 6 1 5 5 7 3 2 */
-&(nid_objs[131]),/* OBJ_code_sign                    1 3 6 1 5 5 7 3 3 */
-&(nid_objs[132]),/* OBJ_email_protect                1 3 6 1 5 5 7 3 4 */
-&(nid_objs[294]),/* OBJ_ipsecEndSystem               1 3 6 1 5 5 7 3 5 */
-&(nid_objs[295]),/* OBJ_ipsecTunnel                  1 3 6 1 5 5 7 3 6 */
-&(nid_objs[296]),/* OBJ_ipsecUser                    1 3 6 1 5 5 7 3 7 */
-&(nid_objs[133]),/* OBJ_time_stamp                   1 3 6 1 5 5 7 3 8 */
-&(nid_objs[180]),/* OBJ_OCSP_sign                    1 3 6 1 5 5 7 3 9 */
-&(nid_objs[297]),/* OBJ_dvcs                         1 3 6 1 5 5 7 3 10 */
-&(nid_objs[298]),/* OBJ_id_it_caProtEncCert          1 3 6 1 5 5 7 4 1 */
-&(nid_objs[299]),/* OBJ_id_it_signKeyPairTypes       1 3 6 1 5 5 7 4 2 */
-&(nid_objs[300]),/* OBJ_id_it_encKeyPairTypes        1 3 6 1 5 5 7 4 3 */
-&(nid_objs[301]),/* OBJ_id_it_preferredSymmAlg       1 3 6 1 5 5 7 4 4 */
-&(nid_objs[302]),/* OBJ_id_it_caKeyUpdateInfo        1 3 6 1 5 5 7 4 5 */
-&(nid_objs[303]),/* OBJ_id_it_currentCRL             1 3 6 1 5 5 7 4 6 */
-&(nid_objs[304]),/* OBJ_id_it_unsupportedOIDs        1 3 6 1 5 5 7 4 7 */
-&(nid_objs[305]),/* OBJ_id_it_subscriptionRequest    1 3 6 1 5 5 7 4 8 */
-&(nid_objs[306]),/* OBJ_id_it_subscriptionResponse   1 3 6 1 5 5 7 4 9 */
-&(nid_objs[307]),/* OBJ_id_it_keyPairParamReq        1 3 6 1 5 5 7 4 10 */
-&(nid_objs[308]),/* OBJ_id_it_keyPairParamRep        1 3 6 1 5 5 7 4 11 */
-&(nid_objs[309]),/* OBJ_id_it_revPassphrase          1 3 6 1 5 5 7 4 12 */
-&(nid_objs[310]),/* OBJ_id_it_implicitConfirm        1 3 6 1 5 5 7 4 13 */
-&(nid_objs[311]),/* OBJ_id_it_confirmWaitTime        1 3 6 1 5 5 7 4 14 */
-&(nid_objs[312]),/* OBJ_id_it_origPKIMessage         1 3 6 1 5 5 7 4 15 */
-&(nid_objs[784]),/* OBJ_id_it_suppLangTags           1 3 6 1 5 5 7 4 16 */
-&(nid_objs[313]),/* OBJ_id_regCtrl                   1 3 6 1 5 5 7 5 1 */
-&(nid_objs[314]),/* OBJ_id_regInfo                   1 3 6 1 5 5 7 5 2 */
-&(nid_objs[323]),/* OBJ_id_alg_des40                 1 3 6 1 5 5 7 6 1 */
-&(nid_objs[324]),/* OBJ_id_alg_noSignature           1 3 6 1 5 5 7 6 2 */
-&(nid_objs[325]),/* OBJ_id_alg_dh_sig_hmac_sha1      1 3 6 1 5 5 7 6 3 */
-&(nid_objs[326]),/* OBJ_id_alg_dh_pop                1 3 6 1 5 5 7 6 4 */
-&(nid_objs[327]),/* OBJ_id_cmc_statusInfo            1 3 6 1 5 5 7 7 1 */
-&(nid_objs[328]),/* OBJ_id_cmc_identification        1 3 6 1 5 5 7 7 2 */
-&(nid_objs[329]),/* OBJ_id_cmc_identityProof         1 3 6 1 5 5 7 7 3 */
-&(nid_objs[330]),/* OBJ_id_cmc_dataReturn            1 3 6 1 5 5 7 7 4 */
-&(nid_objs[331]),/* OBJ_id_cmc_transactionId         1 3 6 1 5 5 7 7 5 */
-&(nid_objs[332]),/* OBJ_id_cmc_senderNonce           1 3 6 1 5 5 7 7 6 */
-&(nid_objs[333]),/* OBJ_id_cmc_recipientNonce        1 3 6 1 5 5 7 7 7 */
-&(nid_objs[334]),/* OBJ_id_cmc_addExtensions         1 3 6 1 5 5 7 7 8 */
-&(nid_objs[335]),/* OBJ_id_cmc_encryptedPOP          1 3 6 1 5 5 7 7 9 */
-&(nid_objs[336]),/* OBJ_id_cmc_decryptedPOP          1 3 6 1 5 5 7 7 10 */
-&(nid_objs[337]),/* OBJ_id_cmc_lraPOPWitness         1 3 6 1 5 5 7 7 11 */
-&(nid_objs[338]),/* OBJ_id_cmc_getCert               1 3 6 1 5 5 7 7 15 */
-&(nid_objs[339]),/* OBJ_id_cmc_getCRL                1 3 6 1 5 5 7 7 16 */
-&(nid_objs[340]),/* OBJ_id_cmc_revokeRequest         1 3 6 1 5 5 7 7 17 */
-&(nid_objs[341]),/* OBJ_id_cmc_regInfo               1 3 6 1 5 5 7 7 18 */
-&(nid_objs[342]),/* OBJ_id_cmc_responseInfo          1 3 6 1 5 5 7 7 19 */
-&(nid_objs[343]),/* OBJ_id_cmc_queryPending          1 3 6 1 5 5 7 7 21 */
-&(nid_objs[344]),/* OBJ_id_cmc_popLinkRandom         1 3 6 1 5 5 7 7 22 */
-&(nid_objs[345]),/* OBJ_id_cmc_popLinkWitness        1 3 6 1 5 5 7 7 23 */
-&(nid_objs[346]),/* OBJ_id_cmc_confirmCertAcceptance 1 3 6 1 5 5 7 7 24 */
-&(nid_objs[347]),/* OBJ_id_on_personalData           1 3 6 1 5 5 7 8 1 */
-&(nid_objs[858]),/* OBJ_id_on_permanentIdentifier    1 3 6 1 5 5 7 8 3 */
-&(nid_objs[348]),/* OBJ_id_pda_dateOfBirth           1 3 6 1 5 5 7 9 1 */
-&(nid_objs[349]),/* OBJ_id_pda_placeOfBirth          1 3 6 1 5 5 7 9 2 */
-&(nid_objs[351]),/* OBJ_id_pda_gender                1 3 6 1 5 5 7 9 3 */
-&(nid_objs[352]),/* OBJ_id_pda_countryOfCitizenship  1 3 6 1 5 5 7 9 4 */
-&(nid_objs[353]),/* OBJ_id_pda_countryOfResidence    1 3 6 1 5 5 7 9 5 */
-&(nid_objs[354]),/* OBJ_id_aca_authenticationInfo    1 3 6 1 5 5 7 10 1 */
-&(nid_objs[355]),/* OBJ_id_aca_accessIdentity        1 3 6 1 5 5 7 10 2 */
-&(nid_objs[356]),/* OBJ_id_aca_chargingIdentity      1 3 6 1 5 5 7 10 3 */
-&(nid_objs[357]),/* OBJ_id_aca_group                 1 3 6 1 5 5 7 10 4 */
-&(nid_objs[358]),/* OBJ_id_aca_role                  1 3 6 1 5 5 7 10 5 */
-&(nid_objs[399]),/* OBJ_id_aca_encAttrs              1 3 6 1 5 5 7 10 6 */
-&(nid_objs[359]),/* OBJ_id_qcs_pkixQCSyntax_v1       1 3 6 1 5 5 7 11 1 */
-&(nid_objs[360]),/* OBJ_id_cct_crs                   1 3 6 1 5 5 7 12 1 */
-&(nid_objs[361]),/* OBJ_id_cct_PKIData               1 3 6 1 5 5 7 12 2 */
-&(nid_objs[362]),/* OBJ_id_cct_PKIResponse           1 3 6 1 5 5 7 12 3 */
-&(nid_objs[664]),/* OBJ_id_ppl_anyLanguage           1 3 6 1 5 5 7 21 0 */
-&(nid_objs[665]),/* OBJ_id_ppl_inheritAll            1 3 6 1 5 5 7 21 1 */
-&(nid_objs[667]),/* OBJ_Independent                  1 3 6 1 5 5 7 21 2 */
-&(nid_objs[178]),/* OBJ_ad_OCSP                      1 3 6 1 5 5 7 48 1 */
-&(nid_objs[179]),/* OBJ_ad_ca_issuers                1 3 6 1 5 5 7 48 2 */
-&(nid_objs[363]),/* OBJ_ad_timeStamping              1 3 6 1 5 5 7 48 3 */
-&(nid_objs[364]),/* OBJ_ad_dvcs                      1 3 6 1 5 5 7 48 4 */
-&(nid_objs[785]),/* OBJ_caRepository                 1 3 6 1 5 5 7 48 5 */
-&(nid_objs[780]),/* OBJ_hmac_md5                     1 3 6 1 5 5 8 1 1 */
-&(nid_objs[781]),/* OBJ_hmac_sha1                    1 3 6 1 5 5 8 1 2 */
-&(nid_objs[58]),/* OBJ_netscape_cert_extension      2 16 840 1 113730 1 */
-&(nid_objs[59]),/* OBJ_netscape_data_type           2 16 840 1 113730 2 */
-&(nid_objs[438]),/* OBJ_pilotAttributeType           0 9 2342 19200300 100 1 */
-&(nid_objs[439]),/* OBJ_pilotAttributeSyntax         0 9 2342 19200300 100 3 */
-&(nid_objs[440]),/* OBJ_pilotObjectClass             0 9 2342 19200300 100 4 */
-&(nid_objs[441]),/* OBJ_pilotGroups                  0 9 2342 19200300 100 10 */
-&(nid_objs[108]),/* OBJ_cast5_cbc                    1 2 840 113533 7 66 10 */
-&(nid_objs[112]),/* OBJ_pbeWithMD5AndCast5_CBC       1 2 840 113533 7 66 12 */
-&(nid_objs[782]),/* OBJ_id_PasswordBasedMAC          1 2 840 113533 7 66 13 */
-&(nid_objs[783]),/* OBJ_id_DHBasedMac                1 2 840 113533 7 66 30 */
-&(nid_objs[ 6]),/* OBJ_rsaEncryption                1 2 840 113549 1 1 1 */
-&(nid_objs[ 7]),/* OBJ_md2WithRSAEncryption         1 2 840 113549 1 1 2 */
-&(nid_objs[396]),/* OBJ_md4WithRSAEncryption         1 2 840 113549 1 1 3 */
-&(nid_objs[ 8]),/* OBJ_md5WithRSAEncryption         1 2 840 113549 1 1 4 */
-&(nid_objs[65]),/* OBJ_sha1WithRSAEncryption        1 2 840 113549 1 1 5 */
-&(nid_objs[644]),/* OBJ_rsaOAEPEncryptionSET         1 2 840 113549 1 1 6 */
-&(nid_objs[668]),/* OBJ_sha256WithRSAEncryption      1 2 840 113549 1 1 11 */
-&(nid_objs[669]),/* OBJ_sha384WithRSAEncryption      1 2 840 113549 1 1 12 */
-&(nid_objs[670]),/* OBJ_sha512WithRSAEncryption      1 2 840 113549 1 1 13 */
-&(nid_objs[671]),/* OBJ_sha224WithRSAEncryption      1 2 840 113549 1 1 14 */
-&(nid_objs[28]),/* OBJ_dhKeyAgreement               1 2 840 113549 1 3 1 */
-&(nid_objs[ 9]),/* OBJ_pbeWithMD2AndDES_CBC         1 2 840 113549 1 5 1 */
-&(nid_objs[10]),/* OBJ_pbeWithMD5AndDES_CBC         1 2 840 113549 1 5 3 */
-&(nid_objs[168]),/* OBJ_pbeWithMD2AndRC2_CBC         1 2 840 113549 1 5 4 */
-&(nid_objs[169]),/* OBJ_pbeWithMD5AndRC2_CBC         1 2 840 113549 1 5 6 */
-&(nid_objs[170]),/* OBJ_pbeWithSHA1AndDES_CBC        1 2 840 113549 1 5 10 */
-&(nid_objs[68]),/* OBJ_pbeWithSHA1AndRC2_CBC        1 2 840 113549 1 5 11 */
-&(nid_objs[69]),/* OBJ_id_pbkdf2                    1 2 840 113549 1 5 12 */
-&(nid_objs[161]),/* OBJ_pbes2                        1 2 840 113549 1 5 13 */
-&(nid_objs[162]),/* OBJ_pbmac1                       1 2 840 113549 1 5 14 */
-&(nid_objs[21]),/* OBJ_pkcs7_data                   1 2 840 113549 1 7 1 */
-&(nid_objs[22]),/* OBJ_pkcs7_signed                 1 2 840 113549 1 7 2 */
-&(nid_objs[23]),/* OBJ_pkcs7_enveloped              1 2 840 113549 1 7 3 */
-&(nid_objs[24]),/* OBJ_pkcs7_signedAndEnveloped     1 2 840 113549 1 7 4 */
-&(nid_objs[25]),/* OBJ_pkcs7_digest                 1 2 840 113549 1 7 5 */
-&(nid_objs[26]),/* OBJ_pkcs7_encrypted              1 2 840 113549 1 7 6 */
-&(nid_objs[48]),/* OBJ_pkcs9_emailAddress           1 2 840 113549 1 9 1 */
-&(nid_objs[49]),/* OBJ_pkcs9_unstructuredName       1 2 840 113549 1 9 2 */
-&(nid_objs[50]),/* OBJ_pkcs9_contentType            1 2 840 113549 1 9 3 */
-&(nid_objs[51]),/* OBJ_pkcs9_messageDigest          1 2 840 113549 1 9 4 */
-&(nid_objs[52]),/* OBJ_pkcs9_signingTime            1 2 840 113549 1 9 5 */
-&(nid_objs[53]),/* OBJ_pkcs9_countersignature       1 2 840 113549 1 9 6 */
-&(nid_objs[54]),/* OBJ_pkcs9_challengePassword      1 2 840 113549 1 9 7 */
-&(nid_objs[55]),/* OBJ_pkcs9_unstructuredAddress    1 2 840 113549 1 9 8 */
-&(nid_objs[56]),/* OBJ_pkcs9_extCertAttributes      1 2 840 113549 1 9 9 */
-&(nid_objs[172]),/* OBJ_ext_req                      1 2 840 113549 1 9 14 */
-&(nid_objs[167]),/* OBJ_SMIMECapabilities            1 2 840 113549 1 9 15 */
-&(nid_objs[188]),/* OBJ_SMIME                        1 2 840 113549 1 9 16 */
-&(nid_objs[156]),/* OBJ_friendlyName                 1 2 840 113549 1 9 20 */
-&(nid_objs[157]),/* OBJ_localKeyID                   1 2 840 113549 1 9 21 */
-&(nid_objs[681]),/* OBJ_X9_62_onBasis                1 2 840 10045 1 2 3 1 */
-&(nid_objs[682]),/* OBJ_X9_62_tpBasis                1 2 840 10045 1 2 3 2 */
-&(nid_objs[683]),/* OBJ_X9_62_ppBasis                1 2 840 10045 1 2 3 3 */
-&(nid_objs[417]),/* OBJ_ms_csp_name                  1 3 6 1 4 1 311 17 1 */
-&(nid_objs[856]),/* OBJ_LocalKeySet                  1 3 6 1 4 1 311 17 2 */
-&(nid_objs[390]),/* OBJ_dcObject                     1 3 6 1 4 1 1466 344 */
-&(nid_objs[91]),/* OBJ_bf_cbc                       1 3 6 1 4 1 3029 1 2 */
-&(nid_objs[315]),/* OBJ_id_regCtrl_regToken          1 3 6 1 5 5 7 5 1 1 */
-&(nid_objs[316]),/* OBJ_id_regCtrl_authenticator     1 3 6 1 5 5 7 5 1 2 */
-&(nid_objs[317]),/* OBJ_id_regCtrl_pkiPublicationInfo 1 3 6 1 5 5 7 5 1 3 */
-&(nid_objs[318]),/* OBJ_id_regCtrl_pkiArchiveOptions 1 3 6 1 5 5 7 5 1 4 */
-&(nid_objs[319]),/* OBJ_id_regCtrl_oldCertID         1 3 6 1 5 5 7 5 1 5 */
-&(nid_objs[320]),/* OBJ_id_regCtrl_protocolEncrKey   1 3 6 1 5 5 7 5 1 6 */
-&(nid_objs[321]),/* OBJ_id_regInfo_utf8Pairs         1 3 6 1 5 5 7 5 2 1 */
-&(nid_objs[322]),/* OBJ_id_regInfo_certReq           1 3 6 1 5 5 7 5 2 2 */
-&(nid_objs[365]),/* OBJ_id_pkix_OCSP_basic           1 3 6 1 5 5 7 48 1 1 */
-&(nid_objs[366]),/* OBJ_id_pkix_OCSP_Nonce           1 3 6 1 5 5 7 48 1 2 */
-&(nid_objs[367]),/* OBJ_id_pkix_OCSP_CrlID           1 3 6 1 5 5 7 48 1 3 */
-&(nid_objs[368]),/* OBJ_id_pkix_OCSP_acceptableResponses 1 3 6 1 5 5 7 48 1 4 */
-&(nid_objs[369]),/* OBJ_id_pkix_OCSP_noCheck         1 3 6 1 5 5 7 48 1 5 */
-&(nid_objs[370]),/* OBJ_id_pkix_OCSP_archiveCutoff   1 3 6 1 5 5 7 48 1 6 */
-&(nid_objs[371]),/* OBJ_id_pkix_OCSP_serviceLocator  1 3 6 1 5 5 7 48 1 7 */
-&(nid_objs[372]),/* OBJ_id_pkix_OCSP_extendedStatus  1 3 6 1 5 5 7 48 1 8 */
-&(nid_objs[373]),/* OBJ_id_pkix_OCSP_valid           1 3 6 1 5 5 7 48 1 9 */
-&(nid_objs[374]),/* OBJ_id_pkix_OCSP_path            1 3 6 1 5 5 7 48 1 10 */
-&(nid_objs[375]),/* OBJ_id_pkix_OCSP_trustRoot       1 3 6 1 5 5 7 48 1 11 */
-&(nid_objs[418]),/* OBJ_aes_128_ecb                  2 16 840 1 101 3 4 1 1 */
-&(nid_objs[419]),/* OBJ_aes_128_cbc                  2 16 840 1 101 3 4 1 2 */
-&(nid_objs[420]),/* OBJ_aes_128_ofb128               2 16 840 1 101 3 4 1 3 */
-&(nid_objs[421]),/* OBJ_aes_128_cfb128               2 16 840 1 101 3 4 1 4 */
-&(nid_objs[788]),/* OBJ_id_aes128_wrap               2 16 840 1 101 3 4 1 5 */
-&(nid_objs[422]),/* OBJ_aes_192_ecb                  2 16 840 1 101 3 4 1 21 */
-&(nid_objs[423]),/* OBJ_aes_192_cbc                  2 16 840 1 101 3 4 1 22 */
-&(nid_objs[424]),/* OBJ_aes_192_ofb128               2 16 840 1 101 3 4 1 23 */
-&(nid_objs[425]),/* OBJ_aes_192_cfb128               2 16 840 1 101 3 4 1 24 */
-&(nid_objs[789]),/* OBJ_id_aes192_wrap               2 16 840 1 101 3 4 1 25 */
-&(nid_objs[426]),/* OBJ_aes_256_ecb                  2 16 840 1 101 3 4 1 41 */
-&(nid_objs[427]),/* OBJ_aes_256_cbc                  2 16 840 1 101 3 4 1 42 */
-&(nid_objs[428]),/* OBJ_aes_256_ofb128               2 16 840 1 101 3 4 1 43 */
-&(nid_objs[429]),/* OBJ_aes_256_cfb128               2 16 840 1 101 3 4 1 44 */
-&(nid_objs[790]),/* OBJ_id_aes256_wrap               2 16 840 1 101 3 4 1 45 */
-&(nid_objs[672]),/* OBJ_sha256                       2 16 840 1 101 3 4 2 1 */
-&(nid_objs[673]),/* OBJ_sha384                       2 16 840 1 101 3 4 2 2 */
-&(nid_objs[674]),/* OBJ_sha512                       2 16 840 1 101 3 4 2 3 */
-&(nid_objs[675]),/* OBJ_sha224                       2 16 840 1 101 3 4 2 4 */
-&(nid_objs[802]),/* OBJ_dsa_with_SHA224              2 16 840 1 101 3 4 3 1 */
-&(nid_objs[803]),/* OBJ_dsa_with_SHA256              2 16 840 1 101 3 4 3 2 */
-&(nid_objs[71]),/* OBJ_netscape_cert_type           2 16 840 1 113730 1 1 */
-&(nid_objs[72]),/* OBJ_netscape_base_url            2 16 840 1 113730 1 2 */
-&(nid_objs[73]),/* OBJ_netscape_revocation_url      2 16 840 1 113730 1 3 */
-&(nid_objs[74]),/* OBJ_netscape_ca_revocation_url   2 16 840 1 113730 1 4 */
-&(nid_objs[75]),/* OBJ_netscape_renewal_url         2 16 840 1 113730 1 7 */
-&(nid_objs[76]),/* OBJ_netscape_ca_policy_url       2 16 840 1 113730 1 8 */
-&(nid_objs[77]),/* OBJ_netscape_ssl_server_name     2 16 840 1 113730 1 12 */
-&(nid_objs[78]),/* OBJ_netscape_comment             2 16 840 1 113730 1 13 */
-&(nid_objs[79]),/* OBJ_netscape_cert_sequence       2 16 840 1 113730 2 5 */
-&(nid_objs[139]),/* OBJ_ns_sgc                       2 16 840 1 113730 4 1 */
-&(nid_objs[458]),/* OBJ_userId                       0 9 2342 19200300 100 1 1 */
-&(nid_objs[459]),/* OBJ_textEncodedORAddress         0 9 2342 19200300 100 1 2 */
-&(nid_objs[460]),/* OBJ_rfc822Mailbox                0 9 2342 19200300 100 1 3 */
-&(nid_objs[461]),/* OBJ_info                         0 9 2342 19200300 100 1 4 */
-&(nid_objs[462]),/* OBJ_favouriteDrink               0 9 2342 19200300 100 1 5 */
-&(nid_objs[463]),/* OBJ_roomNumber                   0 9 2342 19200300 100 1 6 */
-&(nid_objs[464]),/* OBJ_photo                        0 9 2342 19200300 100 1 7 */
-&(nid_objs[465]),/* OBJ_userClass                    0 9 2342 19200300 100 1 8 */
-&(nid_objs[466]),/* OBJ_host                         0 9 2342 19200300 100 1 9 */
-&(nid_objs[467]),/* OBJ_manager                      0 9 2342 19200300 100 1 10 */
-&(nid_objs[468]),/* OBJ_documentIdentifier           0 9 2342 19200300 100 1 11 */
-&(nid_objs[469]),/* OBJ_documentTitle                0 9 2342 19200300 100 1 12 */
-&(nid_objs[470]),/* OBJ_documentVersion              0 9 2342 19200300 100 1 13 */
-&(nid_objs[471]),/* OBJ_documentAuthor               0 9 2342 19200300 100 1 14 */
-&(nid_objs[472]),/* OBJ_documentLocation             0 9 2342 19200300 100 1 15 */
-&(nid_objs[473]),/* OBJ_homeTelephoneNumber          0 9 2342 19200300 100 1 20 */
-&(nid_objs[474]),/* OBJ_secretary                    0 9 2342 19200300 100 1 21 */
-&(nid_objs[475]),/* OBJ_otherMailbox                 0 9 2342 19200300 100 1 22 */
-&(nid_objs[476]),/* OBJ_lastModifiedTime             0 9 2342 19200300 100 1 23 */
-&(nid_objs[477]),/* OBJ_lastModifiedBy               0 9 2342 19200300 100 1 24 */
-&(nid_objs[391]),/* OBJ_domainComponent              0 9 2342 19200300 100 1 25 */
-&(nid_objs[478]),/* OBJ_aRecord                      0 9 2342 19200300 100 1 26 */
-&(nid_objs[479]),/* OBJ_pilotAttributeType27         0 9 2342 19200300 100 1 27 */
-&(nid_objs[480]),/* OBJ_mXRecord                     0 9 2342 19200300 100 1 28 */
-&(nid_objs[481]),/* OBJ_nSRecord                     0 9 2342 19200300 100 1 29 */
-&(nid_objs[482]),/* OBJ_sOARecord                    0 9 2342 19200300 100 1 30 */
-&(nid_objs[483]),/* OBJ_cNAMERecord                  0 9 2342 19200300 100 1 31 */
-&(nid_objs[484]),/* OBJ_associatedDomain             0 9 2342 19200300 100 1 37 */
-&(nid_objs[485]),/* OBJ_associatedName               0 9 2342 19200300 100 1 38 */
-&(nid_objs[486]),/* OBJ_homePostalAddress            0 9 2342 19200300 100 1 39 */
-&(nid_objs[487]),/* OBJ_personalTitle                0 9 2342 19200300 100 1 40 */
-&(nid_objs[488]),/* OBJ_mobileTelephoneNumber        0 9 2342 19200300 100 1 41 */
-&(nid_objs[489]),/* OBJ_pagerTelephoneNumber         0 9 2342 19200300 100 1 42 */
-&(nid_objs[490]),/* OBJ_friendlyCountryName          0 9 2342 19200300 100 1 43 */
-&(nid_objs[491]),/* OBJ_organizationalStatus         0 9 2342 19200300 100 1 45 */
-&(nid_objs[492]),/* OBJ_janetMailbox                 0 9 2342 19200300 100 1 46 */
-&(nid_objs[493]),/* OBJ_mailPreferenceOption         0 9 2342 19200300 100 1 47 */
-&(nid_objs[494]),/* OBJ_buildingName                 0 9 2342 19200300 100 1 48 */
-&(nid_objs[495]),/* OBJ_dSAQuality                   0 9 2342 19200300 100 1 49 */
-&(nid_objs[496]),/* OBJ_singleLevelQuality           0 9 2342 19200300 100 1 50 */
-&(nid_objs[497]),/* OBJ_subtreeMinimumQuality        0 9 2342 19200300 100 1 51 */
-&(nid_objs[498]),/* OBJ_subtreeMaximumQuality        0 9 2342 19200300 100 1 52 */
-&(nid_objs[499]),/* OBJ_personalSignature            0 9 2342 19200300 100 1 53 */
-&(nid_objs[500]),/* OBJ_dITRedirect                  0 9 2342 19200300 100 1 54 */
-&(nid_objs[501]),/* OBJ_audio                        0 9 2342 19200300 100 1 55 */
-&(nid_objs[502]),/* OBJ_documentPublisher            0 9 2342 19200300 100 1 56 */
-&(nid_objs[442]),/* OBJ_iA5StringSyntax              0 9 2342 19200300 100 3 4 */
-&(nid_objs[443]),/* OBJ_caseIgnoreIA5StringSyntax    0 9 2342 19200300 100 3 5 */
-&(nid_objs[444]),/* OBJ_pilotObject                  0 9 2342 19200300 100 4 3 */
-&(nid_objs[445]),/* OBJ_pilotPerson                  0 9 2342 19200300 100 4 4 */
-&(nid_objs[446]),/* OBJ_account                      0 9 2342 19200300 100 4 5 */
-&(nid_objs[447]),/* OBJ_document                     0 9 2342 19200300 100 4 6 */
-&(nid_objs[448]),/* OBJ_room                         0 9 2342 19200300 100 4 7 */
-&(nid_objs[449]),/* OBJ_documentSeries               0 9 2342 19200300 100 4 9 */
-&(nid_objs[392]),/* OBJ_Domain                       0 9 2342 19200300 100 4 13 */
-&(nid_objs[450]),/* OBJ_rFC822localPart              0 9 2342 19200300 100 4 14 */
-&(nid_objs[451]),/* OBJ_dNSDomain                    0 9 2342 19200300 100 4 15 */
-&(nid_objs[452]),/* OBJ_domainRelatedObject          0 9 2342 19200300 100 4 17 */
-&(nid_objs[453]),/* OBJ_friendlyCountry              0 9 2342 19200300 100 4 18 */
-&(nid_objs[454]),/* OBJ_simpleSecurityObject         0 9 2342 19200300 100 4 19 */
-&(nid_objs[455]),/* OBJ_pilotOrganization            0 9 2342 19200300 100 4 20 */
-&(nid_objs[456]),/* OBJ_pilotDSA                     0 9 2342 19200300 100 4 21 */
-&(nid_objs[457]),/* OBJ_qualityLabelledData          0 9 2342 19200300 100 4 22 */
-&(nid_objs[189]),/* OBJ_id_smime_mod                 1 2 840 113549 1 9 16 0 */
-&(nid_objs[190]),/* OBJ_id_smime_ct                  1 2 840 113549 1 9 16 1 */
-&(nid_objs[191]),/* OBJ_id_smime_aa                  1 2 840 113549 1 9 16 2 */
-&(nid_objs[192]),/* OBJ_id_smime_alg                 1 2 840 113549 1 9 16 3 */
-&(nid_objs[193]),/* OBJ_id_smime_cd                  1 2 840 113549 1 9 16 4 */
-&(nid_objs[194]),/* OBJ_id_smime_spq                 1 2 840 113549 1 9 16 5 */
-&(nid_objs[195]),/* OBJ_id_smime_cti                 1 2 840 113549 1 9 16 6 */
-&(nid_objs[158]),/* OBJ_x509Certificate              1 2 840 113549 1 9 22 1 */
-&(nid_objs[159]),/* OBJ_sdsiCertificate              1 2 840 113549 1 9 22 2 */
-&(nid_objs[160]),/* OBJ_x509Crl                      1 2 840 113549 1 9 23 1 */
-&(nid_objs[144]),/* OBJ_pbe_WithSHA1And128BitRC4     1 2 840 113549 1 12 1 1 */
-&(nid_objs[145]),/* OBJ_pbe_WithSHA1And40BitRC4      1 2 840 113549 1 12 1 2 */
-&(nid_objs[146]),/* OBJ_pbe_WithSHA1And3_Key_TripleDES_CBC 1 2 840 113549 1 12 1 3 */
-&(nid_objs[147]),/* OBJ_pbe_WithSHA1And2_Key_TripleDES_CBC 1 2 840 113549 1 12 1 4 */
-&(nid_objs[148]),/* OBJ_pbe_WithSHA1And128BitRC2_CBC 1 2 840 113549 1 12 1 5 */
-&(nid_objs[149]),/* OBJ_pbe_WithSHA1And40BitRC2_CBC  1 2 840 113549 1 12 1 6 */
-&(nid_objs[171]),/* OBJ_ms_ext_req                   1 3 6 1 4 1 311 2 1 14 */
-&(nid_objs[134]),/* OBJ_ms_code_ind                  1 3 6 1 4 1 311 2 1 21 */
-&(nid_objs[135]),/* OBJ_ms_code_com                  1 3 6 1 4 1 311 2 1 22 */
-&(nid_objs[136]),/* OBJ_ms_ctl_sign                  1 3 6 1 4 1 311 10 3 1 */
-&(nid_objs[137]),/* OBJ_ms_sgc                       1 3 6 1 4 1 311 10 3 3 */
-&(nid_objs[138]),/* OBJ_ms_efs                       1 3 6 1 4 1 311 10 3 4 */
-&(nid_objs[648]),/* OBJ_ms_smartcard_login           1 3 6 1 4 1 311 20 2 2 */
-&(nid_objs[649]),/* OBJ_ms_upn                       1 3 6 1 4 1 311 20 2 3 */
-&(nid_objs[751]),/* OBJ_camellia_128_cbc             1 2 392 200011 61 1 1 1 2 */
-&(nid_objs[752]),/* OBJ_camellia_192_cbc             1 2 392 200011 61 1 1 1 3 */
-&(nid_objs[753]),/* OBJ_camellia_256_cbc             1 2 392 200011 61 1 1 1 4 */
-&(nid_objs[196]),/* OBJ_id_smime_mod_cms             1 2 840 113549 1 9 16 0 1 */
-&(nid_objs[197]),/* OBJ_id_smime_mod_ess             1 2 840 113549 1 9 16 0 2 */
-&(nid_objs[198]),/* OBJ_id_smime_mod_oid             1 2 840 113549 1 9 16 0 3 */
-&(nid_objs[199]),/* OBJ_id_smime_mod_msg_v3          1 2 840 113549 1 9 16 0 4 */
-&(nid_objs[200]),/* OBJ_id_smime_mod_ets_eSignature_88 1 2 840 113549 1 9 16 0 5 */
-&(nid_objs[201]),/* OBJ_id_smime_mod_ets_eSignature_97 1 2 840 113549 1 9 16 0 6 */
-&(nid_objs[202]),/* OBJ_id_smime_mod_ets_eSigPolicy_88 1 2 840 113549 1 9 16 0 7 */
-&(nid_objs[203]),/* OBJ_id_smime_mod_ets_eSigPolicy_97 1 2 840 113549 1 9 16 0 8 */
-&(nid_objs[204]),/* OBJ_id_smime_ct_receipt          1 2 840 113549 1 9 16 1 1 */
-&(nid_objs[205]),/* OBJ_id_smime_ct_authData         1 2 840 113549 1 9 16 1 2 */
-&(nid_objs[206]),/* OBJ_id_smime_ct_publishCert      1 2 840 113549 1 9 16 1 3 */
-&(nid_objs[207]),/* OBJ_id_smime_ct_TSTInfo          1 2 840 113549 1 9 16 1 4 */
-&(nid_objs[208]),/* OBJ_id_smime_ct_TDTInfo          1 2 840 113549 1 9 16 1 5 */
-&(nid_objs[209]),/* OBJ_id_smime_ct_contentInfo      1 2 840 113549 1 9 16 1 6 */
-&(nid_objs[210]),/* OBJ_id_smime_ct_DVCSRequestData  1 2 840 113549 1 9 16 1 7 */
-&(nid_objs[211]),/* OBJ_id_smime_ct_DVCSResponseData 1 2 840 113549 1 9 16 1 8 */
-&(nid_objs[786]),/* OBJ_id_smime_ct_compressedData   1 2 840 113549 1 9 16 1 9 */
-&(nid_objs[787]),/* OBJ_id_ct_asciiTextWithCRLF      1 2 840 113549 1 9 16 1 27 */
-&(nid_objs[212]),/* OBJ_id_smime_aa_receiptRequest   1 2 840 113549 1 9 16 2 1 */
-&(nid_objs[213]),/* OBJ_id_smime_aa_securityLabel    1 2 840 113549 1 9 16 2 2 */
-&(nid_objs[214]),/* OBJ_id_smime_aa_mlExpandHistory  1 2 840 113549 1 9 16 2 3 */
-&(nid_objs[215]),/* OBJ_id_smime_aa_contentHint      1 2 840 113549 1 9 16 2 4 */
-&(nid_objs[216]),/* OBJ_id_smime_aa_msgSigDigest     1 2 840 113549 1 9 16 2 5 */
-&(nid_objs[217]),/* OBJ_id_smime_aa_encapContentType 1 2 840 113549 1 9 16 2 6 */
-&(nid_objs[218]),/* OBJ_id_smime_aa_contentIdentifier 1 2 840 113549 1 9 16 2 7 */
-&(nid_objs[219]),/* OBJ_id_smime_aa_macValue         1 2 840 113549 1 9 16 2 8 */
-&(nid_objs[220]),/* OBJ_id_smime_aa_equivalentLabels 1 2 840 113549 1 9 16 2 9 */
-&(nid_objs[221]),/* OBJ_id_smime_aa_contentReference 1 2 840 113549 1 9 16 2 10 */
-&(nid_objs[222]),/* OBJ_id_smime_aa_encrypKeyPref    1 2 840 113549 1 9 16 2 11 */
-&(nid_objs[223]),/* OBJ_id_smime_aa_signingCertificate 1 2 840 113549 1 9 16 2 12 */
-&(nid_objs[224]),/* OBJ_id_smime_aa_smimeEncryptCerts 1 2 840 113549 1 9 16 2 13 */
-&(nid_objs[225]),/* OBJ_id_smime_aa_timeStampToken   1 2 840 113549 1 9 16 2 14 */
-&(nid_objs[226]),/* OBJ_id_smime_aa_ets_sigPolicyId  1 2 840 113549 1 9 16 2 15 */
-&(nid_objs[227]),/* OBJ_id_smime_aa_ets_commitmentType 1 2 840 113549 1 9 16 2 16 */
-&(nid_objs[228]),/* OBJ_id_smime_aa_ets_signerLocation 1 2 840 113549 1 9 16 2 17 */
-&(nid_objs[229]),/* OBJ_id_smime_aa_ets_signerAttr   1 2 840 113549 1 9 16 2 18 */
-&(nid_objs[230]),/* OBJ_id_smime_aa_ets_otherSigCert 1 2 840 113549 1 9 16 2 19 */
-&(nid_objs[231]),/* OBJ_id_smime_aa_ets_contentTimestamp 1 2 840 113549 1 9 16 2 20 */
-&(nid_objs[232]),/* OBJ_id_smime_aa_ets_CertificateRefs 1 2 840 113549 1 9 16 2 21 */
-&(nid_objs[233]),/* OBJ_id_smime_aa_ets_RevocationRefs 1 2 840 113549 1 9 16 2 22 */
-&(nid_objs[234]),/* OBJ_id_smime_aa_ets_certValues   1 2 840 113549 1 9 16 2 23 */
-&(nid_objs[235]),/* OBJ_id_smime_aa_ets_revocationValues 1 2 840 113549 1 9 16 2 24 */
-&(nid_objs[236]),/* OBJ_id_smime_aa_ets_escTimeStamp 1 2 840 113549 1 9 16 2 25 */
-&(nid_objs[237]),/* OBJ_id_smime_aa_ets_certCRLTimestamp 1 2 840 113549 1 9 16 2 26 */
-&(nid_objs[238]),/* OBJ_id_smime_aa_ets_archiveTimeStamp 1 2 840 113549 1 9 16 2 27 */
-&(nid_objs[239]),/* OBJ_id_smime_aa_signatureType    1 2 840 113549 1 9 16 2 28 */
-&(nid_objs[240]),/* OBJ_id_smime_aa_dvcs_dvc         1 2 840 113549 1 9 16 2 29 */
-&(nid_objs[241]),/* OBJ_id_smime_alg_ESDHwith3DES    1 2 840 113549 1 9 16 3 1 */
-&(nid_objs[242]),/* OBJ_id_smime_alg_ESDHwithRC2     1 2 840 113549 1 9 16 3 2 */
-&(nid_objs[243]),/* OBJ_id_smime_alg_3DESwrap        1 2 840 113549 1 9 16 3 3 */
-&(nid_objs[244]),/* OBJ_id_smime_alg_RC2wrap         1 2 840 113549 1 9 16 3 4 */
-&(nid_objs[245]),/* OBJ_id_smime_alg_ESDH            1 2 840 113549 1 9 16 3 5 */
-&(nid_objs[246]),/* OBJ_id_smime_alg_CMS3DESwrap     1 2 840 113549 1 9 16 3 6 */
-&(nid_objs[247]),/* OBJ_id_smime_alg_CMSRC2wrap      1 2 840 113549 1 9 16 3 7 */
-&(nid_objs[125]),/* OBJ_zlib_compression             1 2 840 113549 1 9 16 3 8 */
-&(nid_objs[248]),/* OBJ_id_smime_cd_ldap             1 2 840 113549 1 9 16 4 1 */
-&(nid_objs[249]),/* OBJ_id_smime_spq_ets_sqt_uri     1 2 840 113549 1 9 16 5 1 */
-&(nid_objs[250]),/* OBJ_id_smime_spq_ets_sqt_unotice 1 2 840 113549 1 9 16 5 2 */
-&(nid_objs[251]),/* OBJ_id_smime_cti_ets_proofOfOrigin 1 2 840 113549 1 9 16 6 1 */
-&(nid_objs[252]),/* OBJ_id_smime_cti_ets_proofOfReceipt 1 2 840 113549 1 9 16 6 2 */
-&(nid_objs[253]),/* OBJ_id_smime_cti_ets_proofOfDelivery 1 2 840 113549 1 9 16 6 3 */
-&(nid_objs[254]),/* OBJ_id_smime_cti_ets_proofOfSender 1 2 840 113549 1 9 16 6 4 */
-&(nid_objs[255]),/* OBJ_id_smime_cti_ets_proofOfApproval 1 2 840 113549 1 9 16 6 5 */
-&(nid_objs[256]),/* OBJ_id_smime_cti_ets_proofOfCreation 1 2 840 113549 1 9 16 6 6 */
-&(nid_objs[150]),/* OBJ_keyBag                       1 2 840 113549 1 12 10 1 1 */
-&(nid_objs[151]),/* OBJ_pkcs8ShroudedKeyBag          1 2 840 113549 1 12 10 1 2 */
-&(nid_objs[152]),/* OBJ_certBag                      1 2 840 113549 1 12 10 1 3 */
-&(nid_objs[153]),/* OBJ_crlBag                       1 2 840 113549 1 12 10 1 4 */
-&(nid_objs[154]),/* OBJ_secretBag                    1 2 840 113549 1 12 10 1 5 */
-&(nid_objs[155]),/* OBJ_safeContentsBag              1 2 840 113549 1 12 10 1 6 */
-&(nid_objs[34]),/* OBJ_idea_cbc                     1 3 6 1 4 1 188 7 1 1 2 */
+static const unsigned int obj_objs[NUM_OBJ]={
+ 0,    /* OBJ_undef                        0 */
+393,   /* OBJ_joint_iso_ccitt              OBJ_joint_iso_itu_t */
+404,   /* OBJ_ccitt                        OBJ_itu_t */
+645,   /* OBJ_itu_t                        0 */
+434,   /* OBJ_data                         0 9 */
+181,   /* OBJ_iso                          1 */
+182,   /* OBJ_member_body                  1 2 */
+379,   /* OBJ_org                          1 3 */
+676,   /* OBJ_identified_organization      1 3 */
+646,   /* OBJ_joint_iso_itu_t              2 */
+11,    /* OBJ_X500                         2 5 */
+647,   /* OBJ_international_organizations  2 23 */
+380,   /* OBJ_dod                          1 3 6 */
+12,    /* OBJ_X509                         2 5 4 */
+378,   /* OBJ_X500algorithms               2 5 8 */
+81,    /* OBJ_id_ce                        2 5 29 */
+512,   /* OBJ_id_set                       2 23 42 */
+678,   /* OBJ_wap                          2 23 43 */
+435,   /* OBJ_pss                          0 9 2342 */
+183,   /* OBJ_ISO_US                       1 2 840 */
+381,   /* OBJ_iana                         1 3 6 1 */
+677,   /* OBJ_certicom_arc                 1 3 132 */
+394,   /* OBJ_selected_attribute_types     2 5 1 5 */
+13,    /* OBJ_commonName                   2 5 4 3 */
+100,   /* OBJ_surname                      2 5 4 4 */
+105,   /* OBJ_serialNumber                 2 5 4 5 */
+14,    /* OBJ_countryName                  2 5 4 6 */
+15,    /* OBJ_localityName                 2 5 4 7 */
+16,    /* OBJ_stateOrProvinceName          2 5 4 8 */
+660,   /* OBJ_streetAddress                2 5 4 9 */
+17,    /* OBJ_organizationName             2 5 4 10 */
+18,    /* OBJ_organizationalUnitName       2 5 4 11 */
+106,   /* OBJ_title                        2 5 4 12 */
+107,   /* OBJ_description                  2 5 4 13 */
+859,   /* OBJ_searchGuide                  2 5 4 14 */
+860,   /* OBJ_businessCategory             2 5 4 15 */
+861,   /* OBJ_postalAddress                2 5 4 16 */
+661,   /* OBJ_postalCode                   2 5 4 17 */
+862,   /* OBJ_postOfficeBox                2 5 4 18 */
+863,   /* OBJ_physicalDeliveryOfficeName   2 5 4 19 */
+864,   /* OBJ_telephoneNumber              2 5 4 20 */
+865,   /* OBJ_telexNumber                  2 5 4 21 */
+866,   /* OBJ_teletexTerminalIdentifier    2 5 4 22 */
+867,   /* OBJ_facsimileTelephoneNumber     2 5 4 23 */
+868,   /* OBJ_x121Address                  2 5 4 24 */
+869,   /* OBJ_internationaliSDNNumber      2 5 4 25 */
+870,   /* OBJ_registeredAddress            2 5 4 26 */
+871,   /* OBJ_destinationIndicator         2 5 4 27 */
+872,   /* OBJ_preferredDeliveryMethod      2 5 4 28 */
+873,   /* OBJ_presentationAddress          2 5 4 29 */
+874,   /* OBJ_supportedApplicationContext  2 5 4 30 */
+875,   /* OBJ_member                       2 5 4 31 */
+876,   /* OBJ_owner                        2 5 4 32 */
+877,   /* OBJ_roleOccupant                 2 5 4 33 */
+878,   /* OBJ_seeAlso                      2 5 4 34 */
+879,   /* OBJ_userPassword                 2 5 4 35 */
+880,   /* OBJ_userCertificate              2 5 4 36 */
+881,   /* OBJ_cACertificate                2 5 4 37 */
+882,   /* OBJ_authorityRevocationList      2 5 4 38 */
+883,   /* OBJ_certificateRevocationList    2 5 4 39 */
+884,   /* OBJ_crossCertificatePair         2 5 4 40 */
+173,   /* OBJ_name                         2 5 4 41 */
+99,    /* OBJ_givenName                    2 5 4 42 */
+101,   /* OBJ_initials                     2 5 4 43 */
+509,   /* OBJ_generationQualifier          2 5 4 44 */
+503,   /* OBJ_x500UniqueIdentifier         2 5 4 45 */
+174,   /* OBJ_dnQualifier                  2 5 4 46 */
+885,   /* OBJ_enhancedSearchGuide          2 5 4 47 */
+886,   /* OBJ_protocolInformation          2 5 4 48 */
+887,   /* OBJ_distinguishedName            2 5 4 49 */
+888,   /* OBJ_uniqueMember                 2 5 4 50 */
+889,   /* OBJ_houseIdentifier              2 5 4 51 */
+890,   /* OBJ_supportedAlgorithms          2 5 4 52 */
+891,   /* OBJ_deltaRevocationList          2 5 4 53 */
+892,   /* OBJ_dmdName                      2 5 4 54 */
+510,   /* OBJ_pseudonym                    2 5 4 65 */
+400,   /* OBJ_role                         2 5 4 72 */
+769,   /* OBJ_subject_directory_attributes 2 5 29 9 */
+82,    /* OBJ_subject_key_identifier       2 5 29 14 */
+83,    /* OBJ_key_usage                    2 5 29 15 */
+84,    /* OBJ_private_key_usage_period     2 5 29 16 */
+85,    /* OBJ_subject_alt_name             2 5 29 17 */
+86,    /* OBJ_issuer_alt_name              2 5 29 18 */
+87,    /* OBJ_basic_constraints            2 5 29 19 */
+88,    /* OBJ_crl_number                   2 5 29 20 */
+141,   /* OBJ_crl_reason                   2 5 29 21 */
+430,   /* OBJ_hold_instruction_code        2 5 29 23 */
+142,   /* OBJ_invalidity_date              2 5 29 24 */
+140,   /* OBJ_delta_crl                    2 5 29 27 */
+770,   /* OBJ_issuing_distribution_point   2 5 29 28 */
+771,   /* OBJ_certificate_issuer           2 5 29 29 */
+666,   /* OBJ_name_constraints             2 5 29 30 */
+103,   /* OBJ_crl_distribution_points      2 5 29 31 */
+89,    /* OBJ_certificate_policies         2 5 29 32 */
+747,   /* OBJ_policy_mappings              2 5 29 33 */
+90,    /* OBJ_authority_key_identifier     2 5 29 35 */
+401,   /* OBJ_policy_constraints           2 5 29 36 */
+126,   /* OBJ_ext_key_usage                2 5 29 37 */
+857,   /* OBJ_freshest_crl                 2 5 29 46 */
+748,   /* OBJ_inhibit_any_policy           2 5 29 54 */
+402,   /* OBJ_target_information           2 5 29 55 */
+403,   /* OBJ_no_rev_avail                 2 5 29 56 */
+513,   /* OBJ_set_ctype                    2 23 42 0 */
+514,   /* OBJ_set_msgExt                   2 23 42 1 */
+515,   /* OBJ_set_attr                     2 23 42 3 */
+516,   /* OBJ_set_policy                   2 23 42 5 */
+517,   /* OBJ_set_certExt                  2 23 42 7 */
+518,   /* OBJ_set_brand                    2 23 42 8 */
+679,   /* OBJ_wap_wsg                      2 23 43 1 */
+382,   /* OBJ_Directory                    1 3 6 1 1 */
+383,   /* OBJ_Management                   1 3 6 1 2 */
+384,   /* OBJ_Experimental                 1 3 6 1 3 */
+385,   /* OBJ_Private                      1 3 6 1 4 */
+386,   /* OBJ_Security                     1 3 6 1 5 */
+387,   /* OBJ_SNMPv2                       1 3 6 1 6 */
+388,   /* OBJ_Mail                         1 3 6 1 7 */
+376,   /* OBJ_algorithm                    1 3 14 3 2 */
+395,   /* OBJ_clearance                    2 5 1 5 55 */
+19,    /* OBJ_rsa                          2 5 8 1 1 */
+96,    /* OBJ_mdc2WithRSA                  2 5 8 3 100 */
+95,    /* OBJ_mdc2                         2 5 8 3 101 */
+746,   /* OBJ_any_policy                   2 5 29 32 0 */
+519,   /* OBJ_setct_PANData                2 23 42 0 0 */
+520,   /* OBJ_setct_PANToken               2 23 42 0 1 */
+521,   /* OBJ_setct_PANOnly                2 23 42 0 2 */
+522,   /* OBJ_setct_OIData                 2 23 42 0 3 */
+523,   /* OBJ_setct_PI                     2 23 42 0 4 */
+524,   /* OBJ_setct_PIData                 2 23 42 0 5 */
+525,   /* OBJ_setct_PIDataUnsigned         2 23 42 0 6 */
+526,   /* OBJ_setct_HODInput               2 23 42 0 7 */
+527,   /* OBJ_setct_AuthResBaggage         2 23 42 0 8 */
+528,   /* OBJ_setct_AuthRevReqBaggage      2 23 42 0 9 */
+529,   /* OBJ_setct_AuthRevResBaggage      2 23 42 0 10 */
+530,   /* OBJ_setct_CapTokenSeq            2 23 42 0 11 */
+531,   /* OBJ_setct_PInitResData           2 23 42 0 12 */
+532,   /* OBJ_setct_PI_TBS                 2 23 42 0 13 */
+533,   /* OBJ_setct_PResData               2 23 42 0 14 */
+534,   /* OBJ_setct_AuthReqTBS             2 23 42 0 16 */
+535,   /* OBJ_setct_AuthResTBS             2 23 42 0 17 */
+536,   /* OBJ_setct_AuthResTBSX            2 23 42 0 18 */
+537,   /* OBJ_setct_AuthTokenTBS           2 23 42 0 19 */
+538,   /* OBJ_setct_CapTokenData           2 23 42 0 20 */
+539,   /* OBJ_setct_CapTokenTBS            2 23 42 0 21 */
+540,   /* OBJ_setct_AcqCardCodeMsg         2 23 42 0 22 */
+541,   /* OBJ_setct_AuthRevReqTBS          2 23 42 0 23 */
+542,   /* OBJ_setct_AuthRevResData         2 23 42 0 24 */
+543,   /* OBJ_setct_AuthRevResTBS          2 23 42 0 25 */
+544,   /* OBJ_setct_CapReqTBS              2 23 42 0 26 */
+545,   /* OBJ_setct_CapReqTBSX             2 23 42 0 27 */
+546,   /* OBJ_setct_CapResData             2 23 42 0 28 */
+547,   /* OBJ_setct_CapRevReqTBS           2 23 42 0 29 */
+548,   /* OBJ_setct_CapRevReqTBSX          2 23 42 0 30 */
+549,   /* OBJ_setct_CapRevResData          2 23 42 0 31 */
+550,   /* OBJ_setct_CredReqTBS             2 23 42 0 32 */
+551,   /* OBJ_setct_CredReqTBSX            2 23 42 0 33 */
+552,   /* OBJ_setct_CredResData            2 23 42 0 34 */
+553,   /* OBJ_setct_CredRevReqTBS          2 23 42 0 35 */
+554,   /* OBJ_setct_CredRevReqTBSX         2 23 42 0 36 */
+555,   /* OBJ_setct_CredRevResData         2 23 42 0 37 */
+556,   /* OBJ_setct_PCertReqData           2 23 42 0 38 */
+557,   /* OBJ_setct_PCertResTBS            2 23 42 0 39 */
+558,   /* OBJ_setct_BatchAdminReqData      2 23 42 0 40 */
+559,   /* OBJ_setct_BatchAdminResData      2 23 42 0 41 */
+560,   /* OBJ_setct_CardCInitResTBS        2 23 42 0 42 */
+561,   /* OBJ_setct_MeAqCInitResTBS        2 23 42 0 43 */
+562,   /* OBJ_setct_RegFormResTBS          2 23 42 0 44 */
+563,   /* OBJ_setct_CertReqData            2 23 42 0 45 */
+564,   /* OBJ_setct_CertReqTBS             2 23 42 0 46 */
+565,   /* OBJ_setct_CertResData            2 23 42 0 47 */
+566,   /* OBJ_setct_CertInqReqTBS          2 23 42 0 48 */
+567,   /* OBJ_setct_ErrorTBS               2 23 42 0 49 */
+568,   /* OBJ_setct_PIDualSignedTBE        2 23 42 0 50 */
+569,   /* OBJ_setct_PIUnsignedTBE          2 23 42 0 51 */
+570,   /* OBJ_setct_AuthReqTBE             2 23 42 0 52 */
+571,   /* OBJ_setct_AuthResTBE             2 23 42 0 53 */
+572,   /* OBJ_setct_AuthResTBEX            2 23 42 0 54 */
+573,   /* OBJ_setct_AuthTokenTBE           2 23 42 0 55 */
+574,   /* OBJ_setct_CapTokenTBE            2 23 42 0 56 */
+575,   /* OBJ_setct_CapTokenTBEX           2 23 42 0 57 */
+576,   /* OBJ_setct_AcqCardCodeMsgTBE      2 23 42 0 58 */
+577,   /* OBJ_setct_AuthRevReqTBE          2 23 42 0 59 */
+578,   /* OBJ_setct_AuthRevResTBE          2 23 42 0 60 */
+579,   /* OBJ_setct_AuthRevResTBEB         2 23 42 0 61 */
+580,   /* OBJ_setct_CapReqTBE              2 23 42 0 62 */
+581,   /* OBJ_setct_CapReqTBEX             2 23 42 0 63 */
+582,   /* OBJ_setct_CapResTBE              2 23 42 0 64 */
+583,   /* OBJ_setct_CapRevReqTBE           2 23 42 0 65 */
+584,   /* OBJ_setct_CapRevReqTBEX          2 23 42 0 66 */
+585,   /* OBJ_setct_CapRevResTBE           2 23 42 0 67 */
+586,   /* OBJ_setct_CredReqTBE             2 23 42 0 68 */
+587,   /* OBJ_setct_CredReqTBEX            2 23 42 0 69 */
+588,   /* OBJ_setct_CredResTBE             2 23 42 0 70 */
+589,   /* OBJ_setct_CredRevReqTBE          2 23 42 0 71 */
+590,   /* OBJ_setct_CredRevReqTBEX         2 23 42 0 72 */
+591,   /* OBJ_setct_CredRevResTBE          2 23 42 0 73 */
+592,   /* OBJ_setct_BatchAdminReqTBE       2 23 42 0 74 */
+593,   /* OBJ_setct_BatchAdminResTBE       2 23 42 0 75 */
+594,   /* OBJ_setct_RegFormReqTBE          2 23 42 0 76 */
+595,   /* OBJ_setct_CertReqTBE             2 23 42 0 77 */
+596,   /* OBJ_setct_CertReqTBEX            2 23 42 0 78 */
+597,   /* OBJ_setct_CertResTBE             2 23 42 0 79 */
+598,   /* OBJ_setct_CRLNotificationTBS     2 23 42 0 80 */
+599,   /* OBJ_setct_CRLNotificationResTBS  2 23 42 0 81 */
+600,   /* OBJ_setct_BCIDistributionTBS     2 23 42 0 82 */
+601,   /* OBJ_setext_genCrypt              2 23 42 1 1 */
+602,   /* OBJ_setext_miAuth                2 23 42 1 3 */
+603,   /* OBJ_setext_pinSecure             2 23 42 1 4 */
+604,   /* OBJ_setext_pinAny                2 23 42 1 5 */
+605,   /* OBJ_setext_track2                2 23 42 1 7 */
+606,   /* OBJ_setext_cv                    2 23 42 1 8 */
+620,   /* OBJ_setAttr_Cert                 2 23 42 3 0 */
+621,   /* OBJ_setAttr_PGWYcap              2 23 42 3 1 */
+622,   /* OBJ_setAttr_TokenType            2 23 42 3 2 */
+623,   /* OBJ_setAttr_IssCap               2 23 42 3 3 */
+607,   /* OBJ_set_policy_root              2 23 42 5 0 */
+608,   /* OBJ_setCext_hashedRoot           2 23 42 7 0 */
+609,   /* OBJ_setCext_certType             2 23 42 7 1 */
+610,   /* OBJ_setCext_merchData            2 23 42 7 2 */
+611,   /* OBJ_setCext_cCertRequired        2 23 42 7 3 */
+612,   /* OBJ_setCext_tunneling            2 23 42 7 4 */
+613,   /* OBJ_setCext_setExt               2 23 42 7 5 */
+614,   /* OBJ_setCext_setQualf             2 23 42 7 6 */
+615,   /* OBJ_setCext_PGWYcapabilities     2 23 42 7 7 */
+616,   /* OBJ_setCext_TokenIdentifier      2 23 42 7 8 */
+617,   /* OBJ_setCext_Track2Data           2 23 42 7 9 */
+618,   /* OBJ_setCext_TokenType            2 23 42 7 10 */
+619,   /* OBJ_setCext_IssuerCapabilities   2 23 42 7 11 */
+636,   /* OBJ_set_brand_IATA_ATA           2 23 42 8 1 */
+640,   /* OBJ_set_brand_Visa               2 23 42 8 4 */
+641,   /* OBJ_set_brand_MasterCard         2 23 42 8 5 */
+637,   /* OBJ_set_brand_Diners             2 23 42 8 30 */
+638,   /* OBJ_set_brand_AmericanExpress    2 23 42 8 34 */
+639,   /* OBJ_set_brand_JCB                2 23 42 8 35 */
+805,   /* OBJ_cryptopro                    1 2 643 2 2 */
+806,   /* OBJ_cryptocom                    1 2 643 2 9 */
+184,   /* OBJ_X9_57                        1 2 840 10040 */
+405,   /* OBJ_ansi_X9_62                   1 2 840 10045 */
+389,   /* OBJ_Enterprises                  1 3 6 1 4 1 */
+504,   /* OBJ_mime_mhs                     1 3 6 1 7 1 */
+104,   /* OBJ_md5WithRSA                   1 3 14 3 2 3 */
+29,    /* OBJ_des_ecb                      1 3 14 3 2 6 */
+31,    /* OBJ_des_cbc                      1 3 14 3 2 7 */
+45,    /* OBJ_des_ofb64                    1 3 14 3 2 8 */
+30,    /* OBJ_des_cfb64                    1 3 14 3 2 9 */
+377,   /* OBJ_rsaSignature                 1 3 14 3 2 11 */
+67,    /* OBJ_dsa_2                        1 3 14 3 2 12 */
+66,    /* OBJ_dsaWithSHA                   1 3 14 3 2 13 */
+42,    /* OBJ_shaWithRSAEncryption         1 3 14 3 2 15 */
+32,    /* OBJ_des_ede_ecb                  1 3 14 3 2 17 */
+41,    /* OBJ_sha                          1 3 14 3 2 18 */
+64,    /* OBJ_sha1                         1 3 14 3 2 26 */
+70,    /* OBJ_dsaWithSHA1_2                1 3 14 3 2 27 */
+115,   /* OBJ_sha1WithRSA                  1 3 14 3 2 29 */
+117,   /* OBJ_ripemd160                    1 3 36 3 2 1 */
+143,   /* OBJ_sxnet                        1 3 101 1 4 1 */
+721,   /* OBJ_sect163k1                    1 3 132 0 1 */
+722,   /* OBJ_sect163r1                    1 3 132 0 2 */
+728,   /* OBJ_sect239k1                    1 3 132 0 3 */
+717,   /* OBJ_sect113r1                    1 3 132 0 4 */
+718,   /* OBJ_sect113r2                    1 3 132 0 5 */
+704,   /* OBJ_secp112r1                    1 3 132 0 6 */
+705,   /* OBJ_secp112r2                    1 3 132 0 7 */
+709,   /* OBJ_secp160r1                    1 3 132 0 8 */
+708,   /* OBJ_secp160k1                    1 3 132 0 9 */
+714,   /* OBJ_secp256k1                    1 3 132 0 10 */
+723,   /* OBJ_sect163r2                    1 3 132 0 15 */
+729,   /* OBJ_sect283k1                    1 3 132 0 16 */
+730,   /* OBJ_sect283r1                    1 3 132 0 17 */
+719,   /* OBJ_sect131r1                    1 3 132 0 22 */
+720,   /* OBJ_sect131r2                    1 3 132 0 23 */
+724,   /* OBJ_sect193r1                    1 3 132 0 24 */
+725,   /* OBJ_sect193r2                    1 3 132 0 25 */
+726,   /* OBJ_sect233k1                    1 3 132 0 26 */
+727,   /* OBJ_sect233r1                    1 3 132 0 27 */
+706,   /* OBJ_secp128r1                    1 3 132 0 28 */
+707,   /* OBJ_secp128r2                    1 3 132 0 29 */
+710,   /* OBJ_secp160r2                    1 3 132 0 30 */
+711,   /* OBJ_secp192k1                    1 3 132 0 31 */
+712,   /* OBJ_secp224k1                    1 3 132 0 32 */
+713,   /* OBJ_secp224r1                    1 3 132 0 33 */
+715,   /* OBJ_secp384r1                    1 3 132 0 34 */
+716,   /* OBJ_secp521r1                    1 3 132 0 35 */
+731,   /* OBJ_sect409k1                    1 3 132 0 36 */
+732,   /* OBJ_sect409r1                    1 3 132 0 37 */
+733,   /* OBJ_sect571k1                    1 3 132 0 38 */
+734,   /* OBJ_sect571r1                    1 3 132 0 39 */
+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 */
+627,   /* OBJ_setAttr_Token_B0Prime        2 23 42 3 2 2 */
+628,   /* OBJ_setAttr_IssCap_CVM           2 23 42 3 3 3 */
+629,   /* OBJ_setAttr_IssCap_T2            2 23 42 3 3 4 */
+630,   /* OBJ_setAttr_IssCap_Sig           2 23 42 3 3 5 */
+642,   /* OBJ_set_brand_Novus              2 23 42 8 6011 */
+735,   /* OBJ_wap_wsg_idm_ecid_wtls1       2 23 43 1 4 1 */
+736,   /* OBJ_wap_wsg_idm_ecid_wtls3       2 23 43 1 4 3 */
+737,   /* OBJ_wap_wsg_idm_ecid_wtls4       2 23 43 1 4 4 */
+738,   /* OBJ_wap_wsg_idm_ecid_wtls5       2 23 43 1 4 5 */
+739,   /* OBJ_wap_wsg_idm_ecid_wtls6       2 23 43 1 4 6 */
+740,   /* OBJ_wap_wsg_idm_ecid_wtls7       2 23 43 1 4 7 */
+741,   /* OBJ_wap_wsg_idm_ecid_wtls8       2 23 43 1 4 8 */
+742,   /* OBJ_wap_wsg_idm_ecid_wtls9       2 23 43 1 4 9 */
+743,   /* OBJ_wap_wsg_idm_ecid_wtls10      2 23 43 1 4 10 */
+744,   /* OBJ_wap_wsg_idm_ecid_wtls11      2 23 43 1 4 11 */
+745,   /* OBJ_wap_wsg_idm_ecid_wtls12      2 23 43 1 4 12 */
+804,   /* OBJ_whirlpool                    1 0 10118 3 0 55 */
+124,   /* OBJ_rle_compression              1 1 1 1 666 1 */
+773,   /* OBJ_kisa                         1 2 410 200004 */
+807,   /* OBJ_id_GostR3411_94_with_GostR3410_2001 1 2 643 2 2 3 */
+808,   /* OBJ_id_GostR3411_94_with_GostR3410_94 1 2 643 2 2 4 */
+809,   /* OBJ_id_GostR3411_94              1 2 643 2 2 9 */
+810,   /* OBJ_id_HMACGostR3411_94          1 2 643 2 2 10 */
+811,   /* OBJ_id_GostR3410_2001            1 2 643 2 2 19 */
+812,   /* OBJ_id_GostR3410_94              1 2 643 2 2 20 */
+813,   /* OBJ_id_Gost28147_89              1 2 643 2 2 21 */
+815,   /* OBJ_id_Gost28147_89_MAC          1 2 643 2 2 22 */
+816,   /* OBJ_id_GostR3411_94_prf          1 2 643 2 2 23 */
+817,   /* OBJ_id_GostR3410_2001DH          1 2 643 2 2 98 */
+818,   /* OBJ_id_GostR3410_94DH            1 2 643 2 2 99 */
+ 1,    /* OBJ_rsadsi                       1 2 840 113549 */
+185,   /* OBJ_X9cm                         1 2 840 10040 4 */
+127,   /* OBJ_id_pkix                      1 3 6 1 5 5 7 */
+505,   /* OBJ_mime_mhs_headings            1 3 6 1 7 1 1 */
+506,   /* OBJ_mime_mhs_bodies              1 3 6 1 7 1 2 */
+119,   /* OBJ_ripemd160WithRSA             1 3 36 3 3 1 2 */
+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 */
+634,   /* OBJ_setAttr_TokICCsig            2 23 42 3 3 5 1 */
+635,   /* OBJ_setAttr_SecDevSig            2 23 42 3 3 5 2 */
+436,   /* OBJ_ucl                          0 9 2342 19200300 */
+820,   /* OBJ_id_Gost28147_89_None_KeyMeshing 1 2 643 2 2 14 0 */
+819,   /* OBJ_id_Gost28147_89_CryptoPro_KeyMeshing 1 2 643 2 2 14 1 */
+845,   /* OBJ_id_GostR3410_94_a            1 2 643 2 2 20 1 */
+846,   /* OBJ_id_GostR3410_94_aBis         1 2 643 2 2 20 2 */
+847,   /* OBJ_id_GostR3410_94_b            1 2 643 2 2 20 3 */
+848,   /* OBJ_id_GostR3410_94_bBis         1 2 643 2 2 20 4 */
+821,   /* OBJ_id_GostR3411_94_TestParamSet 1 2 643 2 2 30 0 */
+822,   /* OBJ_id_GostR3411_94_CryptoProParamSet 1 2 643 2 2 30 1 */
+823,   /* OBJ_id_Gost28147_89_TestParamSet 1 2 643 2 2 31 0 */
+824,   /* OBJ_id_Gost28147_89_CryptoPro_A_ParamSet 1 2 643 2 2 31 1 */
+825,   /* OBJ_id_Gost28147_89_CryptoPro_B_ParamSet 1 2 643 2 2 31 2 */
+826,   /* OBJ_id_Gost28147_89_CryptoPro_C_ParamSet 1 2 643 2 2 31 3 */
+827,   /* OBJ_id_Gost28147_89_CryptoPro_D_ParamSet 1 2 643 2 2 31 4 */
+828,   /* OBJ_id_Gost28147_89_CryptoPro_Oscar_1_1_ParamSet 1 2 643 2 2 31 5 */
+829,   /* OBJ_id_Gost28147_89_CryptoPro_Oscar_1_0_ParamSet 1 2 643 2 2 31 6 */
+830,   /* OBJ_id_Gost28147_89_CryptoPro_RIC_1_ParamSet 1 2 643 2 2 31 7 */
+831,   /* OBJ_id_GostR3410_94_TestParamSet 1 2 643 2 2 32 0 */
+832,   /* OBJ_id_GostR3410_94_CryptoPro_A_ParamSet 1 2 643 2 2 32 2 */
+833,   /* OBJ_id_GostR3410_94_CryptoPro_B_ParamSet 1 2 643 2 2 32 3 */
+834,   /* OBJ_id_GostR3410_94_CryptoPro_C_ParamSet 1 2 643 2 2 32 4 */
+835,   /* OBJ_id_GostR3410_94_CryptoPro_D_ParamSet 1 2 643 2 2 32 5 */
+836,   /* OBJ_id_GostR3410_94_CryptoPro_XchA_ParamSet 1 2 643 2 2 33 1 */
+837,   /* OBJ_id_GostR3410_94_CryptoPro_XchB_ParamSet 1 2 643 2 2 33 2 */
+838,   /* OBJ_id_GostR3410_94_CryptoPro_XchC_ParamSet 1 2 643 2 2 33 3 */
+839,   /* OBJ_id_GostR3410_2001_TestParamSet 1 2 643 2 2 35 0 */
+840,   /* OBJ_id_GostR3410_2001_CryptoPro_A_ParamSet 1 2 643 2 2 35 1 */
+841,   /* OBJ_id_GostR3410_2001_CryptoPro_B_ParamSet 1 2 643 2 2 35 2 */
+842,   /* OBJ_id_GostR3410_2001_CryptoPro_C_ParamSet 1 2 643 2 2 35 3 */
+843,   /* OBJ_id_GostR3410_2001_CryptoPro_XchA_ParamSet 1 2 643 2 2 36 0 */
+844,   /* OBJ_id_GostR3410_2001_CryptoPro_XchB_ParamSet 1 2 643 2 2 36 1 */
+ 2,    /* OBJ_pkcs                         1 2 840 113549 1 */
+431,   /* OBJ_hold_instruction_none        1 2 840 10040 2 1 */
+432,   /* OBJ_hold_instruction_call_issuer 1 2 840 10040 2 2 */
+433,   /* OBJ_hold_instruction_reject      1 2 840 10040 2 3 */
+116,   /* OBJ_dsa                          1 2 840 10040 4 1 */
+113,   /* OBJ_dsaWithSHA1                  1 2 840 10040 4 3 */
+406,   /* OBJ_X9_62_prime_field            1 2 840 10045 1 1 */
+407,   /* OBJ_X9_62_characteristic_two_field 1 2 840 10045 1 2 */
+408,   /* OBJ_X9_62_id_ecPublicKey         1 2 840 10045 2 1 */
+416,   /* OBJ_ecdsa_with_SHA1              1 2 840 10045 4 1 */
+791,   /* OBJ_ecdsa_with_Recommended       1 2 840 10045 4 2 */
+792,   /* OBJ_ecdsa_with_Specified         1 2 840 10045 4 3 */
+258,   /* OBJ_id_pkix_mod                  1 3 6 1 5 5 7 0 */
+175,   /* OBJ_id_pe                        1 3 6 1 5 5 7 1 */
+259,   /* OBJ_id_qt                        1 3 6 1 5 5 7 2 */
+128,   /* OBJ_id_kp                        1 3 6 1 5 5 7 3 */
+260,   /* OBJ_id_it                        1 3 6 1 5 5 7 4 */
+261,   /* OBJ_id_pkip                      1 3 6 1 5 5 7 5 */
+262,   /* OBJ_id_alg                       1 3 6 1 5 5 7 6 */
+263,   /* OBJ_id_cmc                       1 3 6 1 5 5 7 7 */
+264,   /* OBJ_id_on                        1 3 6 1 5 5 7 8 */
+265,   /* OBJ_id_pda                       1 3 6 1 5 5 7 9 */
+266,   /* OBJ_id_aca                       1 3 6 1 5 5 7 10 */
+267,   /* OBJ_id_qcs                       1 3 6 1 5 5 7 11 */
+268,   /* OBJ_id_cct                       1 3 6 1 5 5 7 12 */
+662,   /* OBJ_id_ppl                       1 3 6 1 5 5 7 21 */
+176,   /* OBJ_id_ad                        1 3 6 1 5 5 7 48 */
+507,   /* OBJ_id_hex_partial_message       1 3 6 1 7 1 1 1 */
+508,   /* OBJ_id_hex_multipart_message     1 3 6 1 7 1 1 2 */
+57,    /* OBJ_netscape                     2 16 840 1 113730 */
+754,   /* OBJ_camellia_128_ecb             0 3 4401 5 3 1 9 1 */
+766,   /* OBJ_camellia_128_ofb128          0 3 4401 5 3 1 9 3 */
+757,   /* OBJ_camellia_128_cfb128          0 3 4401 5 3 1 9 4 */
+755,   /* OBJ_camellia_192_ecb             0 3 4401 5 3 1 9 21 */
+767,   /* OBJ_camellia_192_ofb128          0 3 4401 5 3 1 9 23 */
+758,   /* OBJ_camellia_192_cfb128          0 3 4401 5 3 1 9 24 */
+756,   /* OBJ_camellia_256_ecb             0 3 4401 5 3 1 9 41 */
+768,   /* OBJ_camellia_256_ofb128          0 3 4401 5 3 1 9 43 */
+759,   /* OBJ_camellia_256_cfb128          0 3 4401 5 3 1 9 44 */
+437,   /* OBJ_pilot                        0 9 2342 19200300 100 */
+776,   /* OBJ_seed_ecb                     1 2 410 200004 1 3 */
+777,   /* OBJ_seed_cbc                     1 2 410 200004 1 4 */
+779,   /* OBJ_seed_cfb128                  1 2 410 200004 1 5 */
+778,   /* OBJ_seed_ofb128                  1 2 410 200004 1 6 */
+852,   /* OBJ_id_GostR3411_94_with_GostR3410_94_cc 1 2 643 2 9 1 3 3 */
+853,   /* OBJ_id_GostR3411_94_with_GostR3410_2001_cc 1 2 643 2 9 1 3 4 */
+850,   /* OBJ_id_GostR3410_94_cc           1 2 643 2 9 1 5 3 */
+851,   /* OBJ_id_GostR3410_2001_cc         1 2 643 2 9 1 5 4 */
+849,   /* OBJ_id_Gost28147_89_cc           1 2 643 2 9 1 6 1 */
+854,   /* OBJ_id_GostR3410_2001_ParamSet_cc 1 2 643 2 9 1 8 1 */
+186,   /* OBJ_pkcs1                        1 2 840 113549 1 1 */
+27,    /* OBJ_pkcs3                        1 2 840 113549 1 3 */
+187,   /* OBJ_pkcs5                        1 2 840 113549 1 5 */
+20,    /* OBJ_pkcs7                        1 2 840 113549 1 7 */
+47,    /* OBJ_pkcs9                        1 2 840 113549 1 9 */
+ 3,    /* OBJ_md2                          1 2 840 113549 2 2 */
+257,   /* OBJ_md4                          1 2 840 113549 2 4 */
+ 4,    /* OBJ_md5                          1 2 840 113549 2 5 */
+797,   /* OBJ_hmacWithMD5                  1 2 840 113549 2 6 */
+163,   /* OBJ_hmacWithSHA1                 1 2 840 113549 2 7 */
+798,   /* OBJ_hmacWithSHA224               1 2 840 113549 2 8 */
+799,   /* OBJ_hmacWithSHA256               1 2 840 113549 2 9 */
+800,   /* OBJ_hmacWithSHA384               1 2 840 113549 2 10 */
+801,   /* OBJ_hmacWithSHA512               1 2 840 113549 2 11 */
+37,    /* OBJ_rc2_cbc                      1 2 840 113549 3 2 */
+ 5,    /* OBJ_rc4                          1 2 840 113549 3 4 */
+44,    /* OBJ_des_ede3_cbc                 1 2 840 113549 3 7 */
+120,   /* OBJ_rc5_cbc                      1 2 840 113549 3 8 */
+643,   /* OBJ_des_cdmf                     1 2 840 113549 3 10 */
+680,   /* OBJ_X9_62_id_characteristic_two_basis 1 2 840 10045 1 2 3 */
+684,   /* OBJ_X9_62_c2pnb163v1             1 2 840 10045 3 0 1 */
+685,   /* OBJ_X9_62_c2pnb163v2             1 2 840 10045 3 0 2 */
+686,   /* OBJ_X9_62_c2pnb163v3             1 2 840 10045 3 0 3 */
+687,   /* OBJ_X9_62_c2pnb176v1             1 2 840 10045 3 0 4 */
+688,   /* OBJ_X9_62_c2tnb191v1             1 2 840 10045 3 0 5 */
+689,   /* OBJ_X9_62_c2tnb191v2             1 2 840 10045 3 0 6 */
+690,   /* OBJ_X9_62_c2tnb191v3             1 2 840 10045 3 0 7 */
+691,   /* OBJ_X9_62_c2onb191v4             1 2 840 10045 3 0 8 */
+692,   /* OBJ_X9_62_c2onb191v5             1 2 840 10045 3 0 9 */
+693,   /* OBJ_X9_62_c2pnb208w1             1 2 840 10045 3 0 10 */
+694,   /* OBJ_X9_62_c2tnb239v1             1 2 840 10045 3 0 11 */
+695,   /* OBJ_X9_62_c2tnb239v2             1 2 840 10045 3 0 12 */
+696,   /* OBJ_X9_62_c2tnb239v3             1 2 840 10045 3 0 13 */
+697,   /* OBJ_X9_62_c2onb239v4             1 2 840 10045 3 0 14 */
+698,   /* OBJ_X9_62_c2onb239v5             1 2 840 10045 3 0 15 */
+699,   /* OBJ_X9_62_c2pnb272w1             1 2 840 10045 3 0 16 */
+700,   /* OBJ_X9_62_c2pnb304w1             1 2 840 10045 3 0 17 */
+701,   /* OBJ_X9_62_c2tnb359v1             1 2 840 10045 3 0 18 */
+702,   /* OBJ_X9_62_c2pnb368w1             1 2 840 10045 3 0 19 */
+703,   /* OBJ_X9_62_c2tnb431r1             1 2 840 10045 3 0 20 */
+409,   /* OBJ_X9_62_prime192v1             1 2 840 10045 3 1 1 */
+410,   /* OBJ_X9_62_prime192v2             1 2 840 10045 3 1 2 */
+411,   /* OBJ_X9_62_prime192v3             1 2 840 10045 3 1 3 */
+412,   /* OBJ_X9_62_prime239v1             1 2 840 10045 3 1 4 */
+413,   /* OBJ_X9_62_prime239v2             1 2 840 10045 3 1 5 */
+414,   /* OBJ_X9_62_prime239v3             1 2 840 10045 3 1 6 */
+415,   /* OBJ_X9_62_prime256v1             1 2 840 10045 3 1 7 */
+793,   /* OBJ_ecdsa_with_SHA224            1 2 840 10045 4 3 1 */
+794,   /* OBJ_ecdsa_with_SHA256            1 2 840 10045 4 3 2 */
+795,   /* OBJ_ecdsa_with_SHA384            1 2 840 10045 4 3 3 */
+796,   /* OBJ_ecdsa_with_SHA512            1 2 840 10045 4 3 4 */
+269,   /* OBJ_id_pkix1_explicit_88         1 3 6 1 5 5 7 0 1 */
+270,   /* OBJ_id_pkix1_implicit_88         1 3 6 1 5 5 7 0 2 */
+271,   /* OBJ_id_pkix1_explicit_93         1 3 6 1 5 5 7 0 3 */
+272,   /* OBJ_id_pkix1_implicit_93         1 3 6 1 5 5 7 0 4 */
+273,   /* OBJ_id_mod_crmf                  1 3 6 1 5 5 7 0 5 */
+274,   /* OBJ_id_mod_cmc                   1 3 6 1 5 5 7 0 6 */
+275,   /* OBJ_id_mod_kea_profile_88        1 3 6 1 5 5 7 0 7 */
+276,   /* OBJ_id_mod_kea_profile_93        1 3 6 1 5 5 7 0 8 */
+277,   /* OBJ_id_mod_cmp                   1 3 6 1 5 5 7 0 9 */
+278,   /* OBJ_id_mod_qualified_cert_88     1 3 6 1 5 5 7 0 10 */
+279,   /* OBJ_id_mod_qualified_cert_93     1 3 6 1 5 5 7 0 11 */
+280,   /* OBJ_id_mod_attribute_cert        1 3 6 1 5 5 7 0 12 */
+281,   /* OBJ_id_mod_timestamp_protocol    1 3 6 1 5 5 7 0 13 */
+282,   /* OBJ_id_mod_ocsp                  1 3 6 1 5 5 7 0 14 */
+283,   /* OBJ_id_mod_dvcs                  1 3 6 1 5 5 7 0 15 */
+284,   /* OBJ_id_mod_cmp2000               1 3 6 1 5 5 7 0 16 */
+177,   /* OBJ_info_access                  1 3 6 1 5 5 7 1 1 */
+285,   /* OBJ_biometricInfo                1 3 6 1 5 5 7 1 2 */
+286,   /* OBJ_qcStatements                 1 3 6 1 5 5 7 1 3 */
+287,   /* OBJ_ac_auditEntity               1 3 6 1 5 5 7 1 4 */
+288,   /* OBJ_ac_targeting                 1 3 6 1 5 5 7 1 5 */
+289,   /* OBJ_aaControls                   1 3 6 1 5 5 7 1 6 */
+290,   /* OBJ_sbgp_ipAddrBlock             1 3 6 1 5 5 7 1 7 */
+291,   /* OBJ_sbgp_autonomousSysNum        1 3 6 1 5 5 7 1 8 */
+292,   /* OBJ_sbgp_routerIdentifier        1 3 6 1 5 5 7 1 9 */
+397,   /* OBJ_ac_proxying                  1 3 6 1 5 5 7 1 10 */
+398,   /* OBJ_sinfo_access                 1 3 6 1 5 5 7 1 11 */
+663,   /* OBJ_proxyCertInfo                1 3 6 1 5 5 7 1 14 */
+164,   /* OBJ_id_qt_cps                    1 3 6 1 5 5 7 2 1 */
+165,   /* OBJ_id_qt_unotice                1 3 6 1 5 5 7 2 2 */
+293,   /* OBJ_textNotice                   1 3 6 1 5 5 7 2 3 */
+129,   /* OBJ_server_auth                  1 3 6 1 5 5 7 3 1 */
+130,   /* OBJ_client_auth                  1 3 6 1 5 5 7 3 2 */
+131,   /* OBJ_code_sign                    1 3 6 1 5 5 7 3 3 */
+132,   /* OBJ_email_protect                1 3 6 1 5 5 7 3 4 */
+294,   /* OBJ_ipsecEndSystem               1 3 6 1 5 5 7 3 5 */
+295,   /* OBJ_ipsecTunnel                  1 3 6 1 5 5 7 3 6 */
+296,   /* OBJ_ipsecUser                    1 3 6 1 5 5 7 3 7 */
+133,   /* OBJ_time_stamp                   1 3 6 1 5 5 7 3 8 */
+180,   /* OBJ_OCSP_sign                    1 3 6 1 5 5 7 3 9 */
+297,   /* OBJ_dvcs                         1 3 6 1 5 5 7 3 10 */
+298,   /* OBJ_id_it_caProtEncCert          1 3 6 1 5 5 7 4 1 */
+299,   /* OBJ_id_it_signKeyPairTypes       1 3 6 1 5 5 7 4 2 */
+300,   /* OBJ_id_it_encKeyPairTypes        1 3 6 1 5 5 7 4 3 */
+301,   /* OBJ_id_it_preferredSymmAlg       1 3 6 1 5 5 7 4 4 */
+302,   /* OBJ_id_it_caKeyUpdateInfo        1 3 6 1 5 5 7 4 5 */
+303,   /* OBJ_id_it_currentCRL             1 3 6 1 5 5 7 4 6 */
+304,   /* OBJ_id_it_unsupportedOIDs        1 3 6 1 5 5 7 4 7 */
+305,   /* OBJ_id_it_subscriptionRequest    1 3 6 1 5 5 7 4 8 */
+306,   /* OBJ_id_it_subscriptionResponse   1 3 6 1 5 5 7 4 9 */
+307,   /* OBJ_id_it_keyPairParamReq        1 3 6 1 5 5 7 4 10 */
+308,   /* OBJ_id_it_keyPairParamRep        1 3 6 1 5 5 7 4 11 */
+309,   /* OBJ_id_it_revPassphrase          1 3 6 1 5 5 7 4 12 */
+310,   /* OBJ_id_it_implicitConfirm        1 3 6 1 5 5 7 4 13 */
+311,   /* OBJ_id_it_confirmWaitTime        1 3 6 1 5 5 7 4 14 */
+312,   /* OBJ_id_it_origPKIMessage         1 3 6 1 5 5 7 4 15 */
+784,   /* OBJ_id_it_suppLangTags           1 3 6 1 5 5 7 4 16 */
+313,   /* OBJ_id_regCtrl                   1 3 6 1 5 5 7 5 1 */
+314,   /* OBJ_id_regInfo                   1 3 6 1 5 5 7 5 2 */
+323,   /* OBJ_id_alg_des40                 1 3 6 1 5 5 7 6 1 */
+324,   /* OBJ_id_alg_noSignature           1 3 6 1 5 5 7 6 2 */
+325,   /* OBJ_id_alg_dh_sig_hmac_sha1      1 3 6 1 5 5 7 6 3 */
+326,   /* OBJ_id_alg_dh_pop                1 3 6 1 5 5 7 6 4 */
+327,   /* OBJ_id_cmc_statusInfo            1 3 6 1 5 5 7 7 1 */
+328,   /* OBJ_id_cmc_identification        1 3 6 1 5 5 7 7 2 */
+329,   /* OBJ_id_cmc_identityProof         1 3 6 1 5 5 7 7 3 */
+330,   /* OBJ_id_cmc_dataReturn            1 3 6 1 5 5 7 7 4 */
+331,   /* OBJ_id_cmc_transactionId         1 3 6 1 5 5 7 7 5 */
+332,   /* OBJ_id_cmc_senderNonce           1 3 6 1 5 5 7 7 6 */
+333,   /* OBJ_id_cmc_recipientNonce        1 3 6 1 5 5 7 7 7 */
+334,   /* OBJ_id_cmc_addExtensions         1 3 6 1 5 5 7 7 8 */
+335,   /* OBJ_id_cmc_encryptedPOP          1 3 6 1 5 5 7 7 9 */
+336,   /* OBJ_id_cmc_decryptedPOP          1 3 6 1 5 5 7 7 10 */
+337,   /* OBJ_id_cmc_lraPOPWitness         1 3 6 1 5 5 7 7 11 */
+338,   /* OBJ_id_cmc_getCert               1 3 6 1 5 5 7 7 15 */
+339,   /* OBJ_id_cmc_getCRL                1 3 6 1 5 5 7 7 16 */
+340,   /* OBJ_id_cmc_revokeRequest         1 3 6 1 5 5 7 7 17 */
+341,   /* OBJ_id_cmc_regInfo               1 3 6 1 5 5 7 7 18 */
+342,   /* OBJ_id_cmc_responseInfo          1 3 6 1 5 5 7 7 19 */
+343,   /* OBJ_id_cmc_queryPending          1 3 6 1 5 5 7 7 21 */
+344,   /* OBJ_id_cmc_popLinkRandom         1 3 6 1 5 5 7 7 22 */
+345,   /* OBJ_id_cmc_popLinkWitness        1 3 6 1 5 5 7 7 23 */
+346,   /* OBJ_id_cmc_confirmCertAcceptance 1 3 6 1 5 5 7 7 24 */
+347,   /* OBJ_id_on_personalData           1 3 6 1 5 5 7 8 1 */
+858,   /* OBJ_id_on_permanentIdentifier    1 3 6 1 5 5 7 8 3 */
+348,   /* OBJ_id_pda_dateOfBirth           1 3 6 1 5 5 7 9 1 */
+349,   /* OBJ_id_pda_placeOfBirth          1 3 6 1 5 5 7 9 2 */
+351,   /* OBJ_id_pda_gender                1 3 6 1 5 5 7 9 3 */
+352,   /* OBJ_id_pda_countryOfCitizenship  1 3 6 1 5 5 7 9 4 */
+353,   /* OBJ_id_pda_countryOfResidence    1 3 6 1 5 5 7 9 5 */
+354,   /* OBJ_id_aca_authenticationInfo    1 3 6 1 5 5 7 10 1 */
+355,   /* OBJ_id_aca_accessIdentity        1 3 6 1 5 5 7 10 2 */
+356,   /* OBJ_id_aca_chargingIdentity      1 3 6 1 5 5 7 10 3 */
+357,   /* OBJ_id_aca_group                 1 3 6 1 5 5 7 10 4 */
+358,   /* OBJ_id_aca_role                  1 3 6 1 5 5 7 10 5 */
+399,   /* OBJ_id_aca_encAttrs              1 3 6 1 5 5 7 10 6 */
+359,   /* OBJ_id_qcs_pkixQCSyntax_v1       1 3 6 1 5 5 7 11 1 */
+360,   /* OBJ_id_cct_crs                   1 3 6 1 5 5 7 12 1 */
+361,   /* OBJ_id_cct_PKIData               1 3 6 1 5 5 7 12 2 */
+362,   /* OBJ_id_cct_PKIResponse           1 3 6 1 5 5 7 12 3 */
+664,   /* OBJ_id_ppl_anyLanguage           1 3 6 1 5 5 7 21 0 */
+665,   /* OBJ_id_ppl_inheritAll            1 3 6 1 5 5 7 21 1 */
+667,   /* OBJ_Independent                  1 3 6 1 5 5 7 21 2 */
+178,   /* OBJ_ad_OCSP                      1 3 6 1 5 5 7 48 1 */
+179,   /* OBJ_ad_ca_issuers                1 3 6 1 5 5 7 48 2 */
+363,   /* OBJ_ad_timeStamping              1 3 6 1 5 5 7 48 3 */
+364,   /* OBJ_ad_dvcs                      1 3 6 1 5 5 7 48 4 */
+785,   /* OBJ_caRepository                 1 3 6 1 5 5 7 48 5 */
+780,   /* OBJ_hmac_md5                     1 3 6 1 5 5 8 1 1 */
+781,   /* OBJ_hmac_sha1                    1 3 6 1 5 5 8 1 2 */
+58,    /* OBJ_netscape_cert_extension      2 16 840 1 113730 1 */
+59,    /* OBJ_netscape_data_type           2 16 840 1 113730 2 */
+438,   /* OBJ_pilotAttributeType           0 9 2342 19200300 100 1 */
+439,   /* OBJ_pilotAttributeSyntax         0 9 2342 19200300 100 3 */
+440,   /* OBJ_pilotObjectClass             0 9 2342 19200300 100 4 */
+441,   /* OBJ_pilotGroups                  0 9 2342 19200300 100 10 */
+108,   /* OBJ_cast5_cbc                    1 2 840 113533 7 66 10 */
+112,   /* OBJ_pbeWithMD5AndCast5_CBC       1 2 840 113533 7 66 12 */
+782,   /* OBJ_id_PasswordBasedMAC          1 2 840 113533 7 66 13 */
+783,   /* OBJ_id_DHBasedMac                1 2 840 113533 7 66 30 */
+ 6,    /* OBJ_rsaEncryption                1 2 840 113549 1 1 1 */
+ 7,    /* OBJ_md2WithRSAEncryption         1 2 840 113549 1 1 2 */
+396,   /* OBJ_md4WithRSAEncryption         1 2 840 113549 1 1 3 */
+ 8,    /* OBJ_md5WithRSAEncryption         1 2 840 113549 1 1 4 */
+65,    /* OBJ_sha1WithRSAEncryption        1 2 840 113549 1 1 5 */
+644,   /* OBJ_rsaOAEPEncryptionSET         1 2 840 113549 1 1 6 */
+668,   /* OBJ_sha256WithRSAEncryption      1 2 840 113549 1 1 11 */
+669,   /* OBJ_sha384WithRSAEncryption      1 2 840 113549 1 1 12 */
+670,   /* OBJ_sha512WithRSAEncryption      1 2 840 113549 1 1 13 */
+671,   /* OBJ_sha224WithRSAEncryption      1 2 840 113549 1 1 14 */
+28,    /* OBJ_dhKeyAgreement               1 2 840 113549 1 3 1 */
+ 9,    /* OBJ_pbeWithMD2AndDES_CBC         1 2 840 113549 1 5 1 */
+10,    /* OBJ_pbeWithMD5AndDES_CBC         1 2 840 113549 1 5 3 */
+168,   /* OBJ_pbeWithMD2AndRC2_CBC         1 2 840 113549 1 5 4 */
+169,   /* OBJ_pbeWithMD5AndRC2_CBC         1 2 840 113549 1 5 6 */
+170,   /* OBJ_pbeWithSHA1AndDES_CBC        1 2 840 113549 1 5 10 */
+68,    /* OBJ_pbeWithSHA1AndRC2_CBC        1 2 840 113549 1 5 11 */
+69,    /* OBJ_id_pbkdf2                    1 2 840 113549 1 5 12 */
+161,   /* OBJ_pbes2                        1 2 840 113549 1 5 13 */
+162,   /* OBJ_pbmac1                       1 2 840 113549 1 5 14 */
+21,    /* OBJ_pkcs7_data                   1 2 840 113549 1 7 1 */
+22,    /* OBJ_pkcs7_signed                 1 2 840 113549 1 7 2 */
+23,    /* OBJ_pkcs7_enveloped              1 2 840 113549 1 7 3 */
+24,    /* OBJ_pkcs7_signedAndEnveloped     1 2 840 113549 1 7 4 */
+25,    /* OBJ_pkcs7_digest                 1 2 840 113549 1 7 5 */
+26,    /* OBJ_pkcs7_encrypted              1 2 840 113549 1 7 6 */
+48,    /* OBJ_pkcs9_emailAddress           1 2 840 113549 1 9 1 */
+49,    /* OBJ_pkcs9_unstructuredName       1 2 840 113549 1 9 2 */
+50,    /* OBJ_pkcs9_contentType            1 2 840 113549 1 9 3 */
+51,    /* OBJ_pkcs9_messageDigest          1 2 840 113549 1 9 4 */
+52,    /* OBJ_pkcs9_signingTime            1 2 840 113549 1 9 5 */
+53,    /* OBJ_pkcs9_countersignature       1 2 840 113549 1 9 6 */
+54,    /* OBJ_pkcs9_challengePassword      1 2 840 113549 1 9 7 */
+55,    /* OBJ_pkcs9_unstructuredAddress    1 2 840 113549 1 9 8 */
+56,    /* OBJ_pkcs9_extCertAttributes      1 2 840 113549 1 9 9 */
+172,   /* OBJ_ext_req                      1 2 840 113549 1 9 14 */
+167,   /* OBJ_SMIMECapabilities            1 2 840 113549 1 9 15 */
+188,   /* OBJ_SMIME                        1 2 840 113549 1 9 16 */
+156,   /* OBJ_friendlyName                 1 2 840 113549 1 9 20 */
+157,   /* OBJ_localKeyID                   1 2 840 113549 1 9 21 */
+681,   /* OBJ_X9_62_onBasis                1 2 840 10045 1 2 3 1 */
+682,   /* OBJ_X9_62_tpBasis                1 2 840 10045 1 2 3 2 */
+683,   /* OBJ_X9_62_ppBasis                1 2 840 10045 1 2 3 3 */
+417,   /* OBJ_ms_csp_name                  1 3 6 1 4 1 311 17 1 */
+856,   /* OBJ_LocalKeySet                  1 3 6 1 4 1 311 17 2 */
+390,   /* OBJ_dcObject                     1 3 6 1 4 1 1466 344 */
+91,    /* OBJ_bf_cbc                       1 3 6 1 4 1 3029 1 2 */
+315,   /* OBJ_id_regCtrl_regToken          1 3 6 1 5 5 7 5 1 1 */
+316,   /* OBJ_id_regCtrl_authenticator     1 3 6 1 5 5 7 5 1 2 */
+317,   /* OBJ_id_regCtrl_pkiPublicationInfo 1 3 6 1 5 5 7 5 1 3 */
+318,   /* OBJ_id_regCtrl_pkiArchiveOptions 1 3 6 1 5 5 7 5 1 4 */
+319,   /* OBJ_id_regCtrl_oldCertID         1 3 6 1 5 5 7 5 1 5 */
+320,   /* OBJ_id_regCtrl_protocolEncrKey   1 3 6 1 5 5 7 5 1 6 */
+321,   /* OBJ_id_regInfo_utf8Pairs         1 3 6 1 5 5 7 5 2 1 */
+322,   /* OBJ_id_regInfo_certReq           1 3 6 1 5 5 7 5 2 2 */
+365,   /* OBJ_id_pkix_OCSP_basic           1 3 6 1 5 5 7 48 1 1 */
+366,   /* OBJ_id_pkix_OCSP_Nonce           1 3 6 1 5 5 7 48 1 2 */
+367,   /* OBJ_id_pkix_OCSP_CrlID           1 3 6 1 5 5 7 48 1 3 */
+368,   /* OBJ_id_pkix_OCSP_acceptableResponses 1 3 6 1 5 5 7 48 1 4 */
+369,   /* OBJ_id_pkix_OCSP_noCheck         1 3 6 1 5 5 7 48 1 5 */
+370,   /* OBJ_id_pkix_OCSP_archiveCutoff   1 3 6 1 5 5 7 48 1 6 */
+371,   /* OBJ_id_pkix_OCSP_serviceLocator  1 3 6 1 5 5 7 48 1 7 */
+372,   /* OBJ_id_pkix_OCSP_extendedStatus  1 3 6 1 5 5 7 48 1 8 */
+373,   /* OBJ_id_pkix_OCSP_valid           1 3 6 1 5 5 7 48 1 9 */
+374,   /* OBJ_id_pkix_OCSP_path            1 3 6 1 5 5 7 48 1 10 */
+375,   /* OBJ_id_pkix_OCSP_trustRoot       1 3 6 1 5 5 7 48 1 11 */
+418,   /* OBJ_aes_128_ecb                  2 16 840 1 101 3 4 1 1 */
+419,   /* OBJ_aes_128_cbc                  2 16 840 1 101 3 4 1 2 */
+420,   /* OBJ_aes_128_ofb128               2 16 840 1 101 3 4 1 3 */
+421,   /* OBJ_aes_128_cfb128               2 16 840 1 101 3 4 1 4 */
+788,   /* OBJ_id_aes128_wrap               2 16 840 1 101 3 4 1 5 */
+422,   /* OBJ_aes_192_ecb                  2 16 840 1 101 3 4 1 21 */
+423,   /* OBJ_aes_192_cbc                  2 16 840 1 101 3 4 1 22 */
+424,   /* OBJ_aes_192_ofb128               2 16 840 1 101 3 4 1 23 */
+425,   /* OBJ_aes_192_cfb128               2 16 840 1 101 3 4 1 24 */
+789,   /* OBJ_id_aes192_wrap               2 16 840 1 101 3 4 1 25 */
+426,   /* OBJ_aes_256_ecb                  2 16 840 1 101 3 4 1 41 */
+427,   /* OBJ_aes_256_cbc                  2 16 840 1 101 3 4 1 42 */
+428,   /* OBJ_aes_256_ofb128               2 16 840 1 101 3 4 1 43 */
+429,   /* OBJ_aes_256_cfb128               2 16 840 1 101 3 4 1 44 */
+790,   /* OBJ_id_aes256_wrap               2 16 840 1 101 3 4 1 45 */
+672,   /* OBJ_sha256                       2 16 840 1 101 3 4 2 1 */
+673,   /* OBJ_sha384                       2 16 840 1 101 3 4 2 2 */
+674,   /* OBJ_sha512                       2 16 840 1 101 3 4 2 3 */
+675,   /* OBJ_sha224                       2 16 840 1 101 3 4 2 4 */
+802,   /* OBJ_dsa_with_SHA224              2 16 840 1 101 3 4 3 1 */
+803,   /* OBJ_dsa_with_SHA256              2 16 840 1 101 3 4 3 2 */
+71,    /* OBJ_netscape_cert_type           2 16 840 1 113730 1 1 */
+72,    /* OBJ_netscape_base_url            2 16 840 1 113730 1 2 */
+73,    /* OBJ_netscape_revocation_url      2 16 840 1 113730 1 3 */
+74,    /* OBJ_netscape_ca_revocation_url   2 16 840 1 113730 1 4 */
+75,    /* OBJ_netscape_renewal_url         2 16 840 1 113730 1 7 */
+76,    /* OBJ_netscape_ca_policy_url       2 16 840 1 113730 1 8 */
+77,    /* OBJ_netscape_ssl_server_name     2 16 840 1 113730 1 12 */
+78,    /* OBJ_netscape_comment             2 16 840 1 113730 1 13 */
+79,    /* OBJ_netscape_cert_sequence       2 16 840 1 113730 2 5 */
+139,   /* OBJ_ns_sgc                       2 16 840 1 113730 4 1 */
+458,   /* OBJ_userId                       0 9 2342 19200300 100 1 1 */
+459,   /* OBJ_textEncodedORAddress         0 9 2342 19200300 100 1 2 */
+460,   /* OBJ_rfc822Mailbox                0 9 2342 19200300 100 1 3 */
+461,   /* OBJ_info                         0 9 2342 19200300 100 1 4 */
+462,   /* OBJ_favouriteDrink               0 9 2342 19200300 100 1 5 */
+463,   /* OBJ_roomNumber                   0 9 2342 19200300 100 1 6 */
+464,   /* OBJ_photo                        0 9 2342 19200300 100 1 7 */
+465,   /* OBJ_userClass                    0 9 2342 19200300 100 1 8 */
+466,   /* OBJ_host                         0 9 2342 19200300 100 1 9 */
+467,   /* OBJ_manager                      0 9 2342 19200300 100 1 10 */
+468,   /* OBJ_documentIdentifier           0 9 2342 19200300 100 1 11 */
+469,   /* OBJ_documentTitle                0 9 2342 19200300 100 1 12 */
+470,   /* OBJ_documentVersion              0 9 2342 19200300 100 1 13 */
+471,   /* OBJ_documentAuthor               0 9 2342 19200300 100 1 14 */
+472,   /* OBJ_documentLocation             0 9 2342 19200300 100 1 15 */
+473,   /* OBJ_homeTelephoneNumber          0 9 2342 19200300 100 1 20 */
+474,   /* OBJ_secretary                    0 9 2342 19200300 100 1 21 */
+475,   /* OBJ_otherMailbox                 0 9 2342 19200300 100 1 22 */
+476,   /* OBJ_lastModifiedTime             0 9 2342 19200300 100 1 23 */
+477,   /* OBJ_lastModifiedBy               0 9 2342 19200300 100 1 24 */
+391,   /* OBJ_domainComponent              0 9 2342 19200300 100 1 25 */
+478,   /* OBJ_aRecord                      0 9 2342 19200300 100 1 26 */
+479,   /* OBJ_pilotAttributeType27         0 9 2342 19200300 100 1 27 */
+480,   /* OBJ_mXRecord                     0 9 2342 19200300 100 1 28 */
+481,   /* OBJ_nSRecord                     0 9 2342 19200300 100 1 29 */
+482,   /* OBJ_sOARecord                    0 9 2342 19200300 100 1 30 */
+483,   /* OBJ_cNAMERecord                  0 9 2342 19200300 100 1 31 */
+484,   /* OBJ_associatedDomain             0 9 2342 19200300 100 1 37 */
+485,   /* OBJ_associatedName               0 9 2342 19200300 100 1 38 */
+486,   /* OBJ_homePostalAddress            0 9 2342 19200300 100 1 39 */
+487,   /* OBJ_personalTitle                0 9 2342 19200300 100 1 40 */
+488,   /* OBJ_mobileTelephoneNumber        0 9 2342 19200300 100 1 41 */
+489,   /* OBJ_pagerTelephoneNumber         0 9 2342 19200300 100 1 42 */
+490,   /* OBJ_friendlyCountryName          0 9 2342 19200300 100 1 43 */
+491,   /* OBJ_organizationalStatus         0 9 2342 19200300 100 1 45 */
+492,   /* OBJ_janetMailbox                 0 9 2342 19200300 100 1 46 */
+493,   /* OBJ_mailPreferenceOption         0 9 2342 19200300 100 1 47 */
+494,   /* OBJ_buildingName                 0 9 2342 19200300 100 1 48 */
+495,   /* OBJ_dSAQuality                   0 9 2342 19200300 100 1 49 */
+496,   /* OBJ_singleLevelQuality           0 9 2342 19200300 100 1 50 */
+497,   /* OBJ_subtreeMinimumQuality        0 9 2342 19200300 100 1 51 */
+498,   /* OBJ_subtreeMaximumQuality        0 9 2342 19200300 100 1 52 */
+499,   /* OBJ_personalSignature            0 9 2342 19200300 100 1 53 */
+500,   /* OBJ_dITRedirect                  0 9 2342 19200300 100 1 54 */
+501,   /* OBJ_audio                        0 9 2342 19200300 100 1 55 */
+502,   /* OBJ_documentPublisher            0 9 2342 19200300 100 1 56 */
+442,   /* OBJ_iA5StringSyntax              0 9 2342 19200300 100 3 4 */
+443,   /* OBJ_caseIgnoreIA5StringSyntax    0 9 2342 19200300 100 3 5 */
+444,   /* OBJ_pilotObject                  0 9 2342 19200300 100 4 3 */
+445,   /* OBJ_pilotPerson                  0 9 2342 19200300 100 4 4 */
+446,   /* OBJ_account                      0 9 2342 19200300 100 4 5 */
+447,   /* OBJ_document                     0 9 2342 19200300 100 4 6 */
+448,   /* OBJ_room                         0 9 2342 19200300 100 4 7 */
+449,   /* OBJ_documentSeries               0 9 2342 19200300 100 4 9 */
+392,   /* OBJ_Domain                       0 9 2342 19200300 100 4 13 */
+450,   /* OBJ_rFC822localPart              0 9 2342 19200300 100 4 14 */
+451,   /* OBJ_dNSDomain                    0 9 2342 19200300 100 4 15 */
+452,   /* OBJ_domainRelatedObject          0 9 2342 19200300 100 4 17 */
+453,   /* OBJ_friendlyCountry              0 9 2342 19200300 100 4 18 */
+454,   /* OBJ_simpleSecurityObject         0 9 2342 19200300 100 4 19 */
+455,   /* OBJ_pilotOrganization            0 9 2342 19200300 100 4 20 */
+456,   /* OBJ_pilotDSA                     0 9 2342 19200300 100 4 21 */
+457,   /* OBJ_qualityLabelledData          0 9 2342 19200300 100 4 22 */
+189,   /* OBJ_id_smime_mod                 1 2 840 113549 1 9 16 0 */
+190,   /* OBJ_id_smime_ct                  1 2 840 113549 1 9 16 1 */
+191,   /* OBJ_id_smime_aa                  1 2 840 113549 1 9 16 2 */
+192,   /* OBJ_id_smime_alg                 1 2 840 113549 1 9 16 3 */
+193,   /* OBJ_id_smime_cd                  1 2 840 113549 1 9 16 4 */
+194,   /* OBJ_id_smime_spq                 1 2 840 113549 1 9 16 5 */
+195,   /* OBJ_id_smime_cti                 1 2 840 113549 1 9 16 6 */
+158,   /* OBJ_x509Certificate              1 2 840 113549 1 9 22 1 */
+159,   /* OBJ_sdsiCertificate              1 2 840 113549 1 9 22 2 */
+160,   /* OBJ_x509Crl                      1 2 840 113549 1 9 23 1 */
+144,   /* OBJ_pbe_WithSHA1And128BitRC4     1 2 840 113549 1 12 1 1 */
+145,   /* OBJ_pbe_WithSHA1And40BitRC4      1 2 840 113549 1 12 1 2 */
+146,   /* OBJ_pbe_WithSHA1And3_Key_TripleDES_CBC 1 2 840 113549 1 12 1 3 */
+147,   /* OBJ_pbe_WithSHA1And2_Key_TripleDES_CBC 1 2 840 113549 1 12 1 4 */
+148,   /* OBJ_pbe_WithSHA1And128BitRC2_CBC 1 2 840 113549 1 12 1 5 */
+149,   /* OBJ_pbe_WithSHA1And40BitRC2_CBC  1 2 840 113549 1 12 1 6 */
+171,   /* OBJ_ms_ext_req                   1 3 6 1 4 1 311 2 1 14 */
+134,   /* OBJ_ms_code_ind                  1 3 6 1 4 1 311 2 1 21 */
+135,   /* OBJ_ms_code_com                  1 3 6 1 4 1 311 2 1 22 */
+136,   /* OBJ_ms_ctl_sign                  1 3 6 1 4 1 311 10 3 1 */
+137,   /* OBJ_ms_sgc                       1 3 6 1 4 1 311 10 3 3 */
+138,   /* OBJ_ms_efs                       1 3 6 1 4 1 311 10 3 4 */
+648,   /* OBJ_ms_smartcard_login           1 3 6 1 4 1 311 20 2 2 */
+649,   /* OBJ_ms_upn                       1 3 6 1 4 1 311 20 2 3 */
+751,   /* OBJ_camellia_128_cbc             1 2 392 200011 61 1 1 1 2 */
+752,   /* OBJ_camellia_192_cbc             1 2 392 200011 61 1 1 1 3 */
+753,   /* OBJ_camellia_256_cbc             1 2 392 200011 61 1 1 1 4 */
+196,   /* OBJ_id_smime_mod_cms             1 2 840 113549 1 9 16 0 1 */
+197,   /* OBJ_id_smime_mod_ess             1 2 840 113549 1 9 16 0 2 */
+198,   /* OBJ_id_smime_mod_oid             1 2 840 113549 1 9 16 0 3 */
+199,   /* OBJ_id_smime_mod_msg_v3          1 2 840 113549 1 9 16 0 4 */
+200,   /* OBJ_id_smime_mod_ets_eSignature_88 1 2 840 113549 1 9 16 0 5 */
+201,   /* OBJ_id_smime_mod_ets_eSignature_97 1 2 840 113549 1 9 16 0 6 */
+202,   /* OBJ_id_smime_mod_ets_eSigPolicy_88 1 2 840 113549 1 9 16 0 7 */
+203,   /* OBJ_id_smime_mod_ets_eSigPolicy_97 1 2 840 113549 1 9 16 0 8 */
+204,   /* OBJ_id_smime_ct_receipt          1 2 840 113549 1 9 16 1 1 */
+205,   /* OBJ_id_smime_ct_authData         1 2 840 113549 1 9 16 1 2 */
+206,   /* OBJ_id_smime_ct_publishCert      1 2 840 113549 1 9 16 1 3 */
+207,   /* OBJ_id_smime_ct_TSTInfo          1 2 840 113549 1 9 16 1 4 */
+208,   /* OBJ_id_smime_ct_TDTInfo          1 2 840 113549 1 9 16 1 5 */
+209,   /* OBJ_id_smime_ct_contentInfo      1 2 840 113549 1 9 16 1 6 */
+210,   /* OBJ_id_smime_ct_DVCSRequestData  1 2 840 113549 1 9 16 1 7 */
+211,   /* OBJ_id_smime_ct_DVCSResponseData 1 2 840 113549 1 9 16 1 8 */
+786,   /* OBJ_id_smime_ct_compressedData   1 2 840 113549 1 9 16 1 9 */
+787,   /* OBJ_id_ct_asciiTextWithCRLF      1 2 840 113549 1 9 16 1 27 */
+212,   /* OBJ_id_smime_aa_receiptRequest   1 2 840 113549 1 9 16 2 1 */
+213,   /* OBJ_id_smime_aa_securityLabel    1 2 840 113549 1 9 16 2 2 */
+214,   /* OBJ_id_smime_aa_mlExpandHistory  1 2 840 113549 1 9 16 2 3 */
+215,   /* OBJ_id_smime_aa_contentHint      1 2 840 113549 1 9 16 2 4 */
+216,   /* OBJ_id_smime_aa_msgSigDigest     1 2 840 113549 1 9 16 2 5 */
+217,   /* OBJ_id_smime_aa_encapContentType 1 2 840 113549 1 9 16 2 6 */
+218,   /* OBJ_id_smime_aa_contentIdentifier 1 2 840 113549 1 9 16 2 7 */
+219,   /* OBJ_id_smime_aa_macValue         1 2 840 113549 1 9 16 2 8 */
+220,   /* OBJ_id_smime_aa_equivalentLabels 1 2 840 113549 1 9 16 2 9 */
+221,   /* OBJ_id_smime_aa_contentReference 1 2 840 113549 1 9 16 2 10 */
+222,   /* OBJ_id_smime_aa_encrypKeyPref    1 2 840 113549 1 9 16 2 11 */
+223,   /* OBJ_id_smime_aa_signingCertificate 1 2 840 113549 1 9 16 2 12 */
+224,   /* OBJ_id_smime_aa_smimeEncryptCerts 1 2 840 113549 1 9 16 2 13 */
+225,   /* OBJ_id_smime_aa_timeStampToken   1 2 840 113549 1 9 16 2 14 */
+226,   /* OBJ_id_smime_aa_ets_sigPolicyId  1 2 840 113549 1 9 16 2 15 */
+227,   /* OBJ_id_smime_aa_ets_commitmentType 1 2 840 113549 1 9 16 2 16 */
+228,   /* OBJ_id_smime_aa_ets_signerLocation 1 2 840 113549 1 9 16 2 17 */
+229,   /* OBJ_id_smime_aa_ets_signerAttr   1 2 840 113549 1 9 16 2 18 */
+230,   /* OBJ_id_smime_aa_ets_otherSigCert 1 2 840 113549 1 9 16 2 19 */
+231,   /* OBJ_id_smime_aa_ets_contentTimestamp 1 2 840 113549 1 9 16 2 20 */
+232,   /* OBJ_id_smime_aa_ets_CertificateRefs 1 2 840 113549 1 9 16 2 21 */
+233,   /* OBJ_id_smime_aa_ets_RevocationRefs 1 2 840 113549 1 9 16 2 22 */
+234,   /* OBJ_id_smime_aa_ets_certValues   1 2 840 113549 1 9 16 2 23 */
+235,   /* OBJ_id_smime_aa_ets_revocationValues 1 2 840 113549 1 9 16 2 24 */
+236,   /* OBJ_id_smime_aa_ets_escTimeStamp 1 2 840 113549 1 9 16 2 25 */
+237,   /* OBJ_id_smime_aa_ets_certCRLTimestamp 1 2 840 113549 1 9 16 2 26 */
+238,   /* OBJ_id_smime_aa_ets_archiveTimeStamp 1 2 840 113549 1 9 16 2 27 */
+239,   /* OBJ_id_smime_aa_signatureType    1 2 840 113549 1 9 16 2 28 */
+240,   /* OBJ_id_smime_aa_dvcs_dvc         1 2 840 113549 1 9 16 2 29 */
+241,   /* OBJ_id_smime_alg_ESDHwith3DES    1 2 840 113549 1 9 16 3 1 */
+242,   /* OBJ_id_smime_alg_ESDHwithRC2     1 2 840 113549 1 9 16 3 2 */
+243,   /* OBJ_id_smime_alg_3DESwrap        1 2 840 113549 1 9 16 3 3 */
+244,   /* OBJ_id_smime_alg_RC2wrap         1 2 840 113549 1 9 16 3 4 */
+245,   /* OBJ_id_smime_alg_ESDH            1 2 840 113549 1 9 16 3 5 */
+246,   /* OBJ_id_smime_alg_CMS3DESwrap     1 2 840 113549 1 9 16 3 6 */
+247,   /* OBJ_id_smime_alg_CMSRC2wrap      1 2 840 113549 1 9 16 3 7 */
+125,   /* OBJ_zlib_compression             1 2 840 113549 1 9 16 3 8 */
+248,   /* OBJ_id_smime_cd_ldap             1 2 840 113549 1 9 16 4 1 */
+249,   /* OBJ_id_smime_spq_ets_sqt_uri     1 2 840 113549 1 9 16 5 1 */
+250,   /* OBJ_id_smime_spq_ets_sqt_unotice 1 2 840 113549 1 9 16 5 2 */
+251,   /* OBJ_id_smime_cti_ets_proofOfOrigin 1 2 840 113549 1 9 16 6 1 */
+252,   /* OBJ_id_smime_cti_ets_proofOfReceipt 1 2 840 113549 1 9 16 6 2 */
+253,   /* OBJ_id_smime_cti_ets_proofOfDelivery 1 2 840 113549 1 9 16 6 3 */
+254,   /* OBJ_id_smime_cti_ets_proofOfSender 1 2 840 113549 1 9 16 6 4 */
+255,   /* OBJ_id_smime_cti_ets_proofOfApproval 1 2 840 113549 1 9 16 6 5 */
+256,   /* OBJ_id_smime_cti_ets_proofOfCreation 1 2 840 113549 1 9 16 6 6 */
+150,   /* OBJ_keyBag                       1 2 840 113549 1 12 10 1 1 */
+151,   /* OBJ_pkcs8ShroudedKeyBag          1 2 840 113549 1 12 10 1 2 */
+152,   /* OBJ_certBag                      1 2 840 113549 1 12 10 1 3 */
+153,   /* OBJ_crlBag                       1 2 840 113549 1 12 10 1 4 */
+154,   /* OBJ_secretBag                    1 2 840 113549 1 12 10 1 5 */
+155,   /* OBJ_safeContentsBag              1 2 840 113549 1 12 10 1 6 */
+34,    /* OBJ_idea_cbc                     1 3 6 1 4 1 188 7 1 1 2 */
 };
 
index 7de2f77..c67f71c 100644 (file)
@@ -2,9 +2,7 @@
 
 # fixes bug in floating point emulation on sparc64 when
 # this script produces off-by-one output on sparc64
-eval 'use integer;';
-
-print STDERR "Warning: perl module integer not found.\n" if ($@);
+use integer;
 
 sub obj_cmp
        {
@@ -150,13 +148,13 @@ for ($i=0; $i<$n; $i++)
 @a=grep(defined($sn{$nid{$_}}),0 .. $n);
 foreach (sort { $sn{$nid{$a}} cmp $sn{$nid{$b}} } @a)
        {
-       push(@sn,sprintf("&(nid_objs[%2d]),/* \"$sn{$nid{$_}}\" */\n",$_));
+       push(@sn,sprintf("%2d,\t/* \"$sn{$nid{$_}}\" */\n",$_));
        }
 
 @a=grep(defined($ln{$nid{$_}}),0 .. $n);
 foreach (sort { $ln{$nid{$a}} cmp $ln{$nid{$b}} } @a)
        {
-       push(@ln,sprintf("&(nid_objs[%2d]),/* \"$ln{$nid{$_}}\" */\n",$_));
+       push(@ln,sprintf("%2d,\t/* \"$ln{$nid{$_}}\" */\n",$_));
        }
 
 @a=grep(defined($obj{$nid{$_}}),0 .. $n);
@@ -166,7 +164,7 @@ foreach (sort obj_cmp @a)
        $v=$objd{$m};
        $v =~ s/L//g;
        $v =~ s/,/ /g;
-       push(@ob,sprintf("&(nid_objs[%2d]),/* %-32s %s */\n",$_,$m,$v));
+       push(@ob,sprintf("%2d,\t/* %-32s %s */\n",$_,$m,$v));
        }
 
 print OUT <<'EOF';
@@ -241,11 +239,11 @@ printf OUT "#define NUM_SN %d\n",$#sn+1;
 printf OUT "#define NUM_LN %d\n",$#ln+1;
 printf OUT "#define NUM_OBJ %d\n\n",$#ob+1;
 
-printf OUT "static unsigned char lvalues[%d]={\n",$lvalues+1;
+printf OUT "static const unsigned char lvalues[%d]={\n",$lvalues+1;
 print OUT @lvalues;
 print OUT "};\n\n";
 
-printf OUT "static ASN1_OBJECT nid_objs[NUM_NID]={\n";
+printf OUT "static const ASN1_OBJECT nid_objs[NUM_NID]={\n";
 foreach (@out)
        {
        if (length($_) > 75)
@@ -269,15 +267,15 @@ foreach (@out)
        }
 print  OUT "};\n\n";
 
-printf OUT "static ASN1_OBJECT *sn_objs[NUM_SN]={\n";
+printf OUT "static const unsigned int sn_objs[NUM_SN]={\n";
 print  OUT @sn;
 print  OUT "};\n\n";
 
-printf OUT "static ASN1_OBJECT *ln_objs[NUM_LN]={\n";
+printf OUT "static const unsigned int ln_objs[NUM_LN]={\n";
 print  OUT @ln;
 print  OUT "};\n\n";
 
-printf OUT "static ASN1_OBJECT *obj_objs[NUM_OBJ]={\n";
+printf OUT "static const unsigned int obj_objs[NUM_OBJ]={\n";
 print  OUT @ob;
 print  OUT "};\n\n";
 
index 12b4885..2e7a034 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/objects/obj_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
index 706fa0b..23e9d48 100644 (file)
@@ -66,7 +66,8 @@ ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o)
        {
        ASN1_OBJECT *r;
        int i;
-       char *ln=NULL;
+       char *ln=NULL,*sn=NULL;
+       unsigned char *data=NULL;
 
        if (o == NULL) return(NULL);
        if (!(o->flags & ASN1_OBJECT_FLAG_DYNAMIC))
@@ -79,42 +80,42 @@ ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o)
                OBJerr(OBJ_F_OBJ_DUP,ERR_R_ASN1_LIB);
                return(NULL);
                }
-       r->data=OPENSSL_malloc(o->length);
-       if (r->data == NULL)
+       data=OPENSSL_malloc(o->length);
+       if (data == NULL)
                goto err;
        if (o->data != NULL)
-               memcpy(r->data,o->data,o->length);
+               memcpy(data,o->data,o->length);
+       /* once data attached to object it remains const */
+       r->data = data;
        r->length=o->length;
        r->nid=o->nid;
        r->ln=r->sn=NULL;
        if (o->ln != NULL)
                {
                i=strlen(o->ln)+1;
-               r->ln=ln=OPENSSL_malloc(i);
-               if (r->ln == NULL) goto err;
+               ln=OPENSSL_malloc(i);
+               if (ln == NULL) goto err;
                memcpy(ln,o->ln,i);
+               r->ln=ln;
                }
 
        if (o->sn != NULL)
                {
-               char *s;
-
                i=strlen(o->sn)+1;
-               r->sn=s=OPENSSL_malloc(i);
-               if (r->sn == NULL) goto err;
-               memcpy(s,o->sn,i);
+               sn=OPENSSL_malloc(i);
+               if (sn == NULL) goto err;
+               memcpy(sn,o->sn,i);
+               r->sn=sn;
                }
        r->flags=o->flags|(ASN1_OBJECT_FLAG_DYNAMIC|
                ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|ASN1_OBJECT_FLAG_DYNAMIC_DATA);
        return(r);
 err:
        OBJerr(OBJ_F_OBJ_DUP,ERR_R_MALLOC_FAILURE);
-       if (r != NULL)
-               {
-               if (ln != NULL) OPENSSL_free(ln);
-               if (r->data != NULL) OPENSSL_free(r->data);
-               OPENSSL_free(r);
-               }
+       if (ln != NULL)         OPENSSL_free(ln);
+       if (sn != NULL)         OPENSSL_free(sn);
+       if (data != NULL)       OPENSSL_free(data);
+       if (r != NULL)          OPENSSL_free(r);
        return(NULL);
        }
 
diff --git a/deps/openssl/openssl/crypto/objects/obj_xref.c b/deps/openssl/openssl/crypto/objects/obj_xref.c
new file mode 100644 (file)
index 0000000..152eca5
--- /dev/null
@@ -0,0 +1,231 @@
+/* crypto/objects/obj_xref.c */
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project 2006.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <openssl/objects.h>
+#include "obj_xref.h"
+
+DECLARE_STACK_OF(nid_triple)
+STACK_OF(nid_triple) *sig_app, *sigx_app;
+
+static int sig_cmp(const nid_triple *a, const nid_triple *b)
+       {
+       return a->sign_id - b->sign_id;
+       }
+
+DECLARE_OBJ_BSEARCH_CMP_FN(nid_triple, nid_triple, sig);
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(nid_triple, nid_triple, sig);
+
+static int sig_sk_cmp(const nid_triple * const *a, const nid_triple * const *b)
+       {
+       return (*a)->sign_id - (*b)->sign_id;
+       }
+
+DECLARE_OBJ_BSEARCH_CMP_FN(const nid_triple *, const nid_triple *, sigx);
+
+static int sigx_cmp(const nid_triple * const *a, const nid_triple * const *b)
+       {
+       int ret;
+       ret = (*a)->hash_id - (*b)->hash_id;
+       if (ret)
+               return ret;
+       return (*a)->pkey_id - (*b)->pkey_id;
+       }
+
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(const nid_triple *, const nid_triple *, sigx);
+
+int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid)
+       {
+       nid_triple tmp;
+       const nid_triple *rv = NULL;
+       tmp.sign_id = signid;
+
+       if (sig_app)
+               {
+               int idx = sk_nid_triple_find(sig_app, &tmp);
+               if (idx >= 0)
+                       rv = sk_nid_triple_value(sig_app, idx);
+               }
+
+#ifndef OBJ_XREF_TEST2
+       if (rv == NULL)
+               {
+               rv = OBJ_bsearch_sig(&tmp, sigoid_srt,
+                                sizeof(sigoid_srt) / sizeof(nid_triple));
+               }
+#endif
+       if (rv == NULL)
+               return 0;
+       *pdig_nid = rv->hash_id;
+       *ppkey_nid = rv->pkey_id;
+       return 1;
+       }
+
+int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid)
+       {
+       nid_triple tmp;
+       const nid_triple *t=&tmp;
+       const nid_triple **rv = NULL;
+
+       tmp.hash_id = dig_nid;
+       tmp.pkey_id = pkey_nid;
+
+       if (sigx_app)
+               {
+               int idx = sk_nid_triple_find(sigx_app, &tmp);
+               if (idx >= 0)
+                       {
+                       t = sk_nid_triple_value(sigx_app, idx);
+                       rv = &t;
+                       }
+               }
+
+#ifndef OBJ_XREF_TEST2
+       if (rv == NULL)
+               {
+               rv = OBJ_bsearch_sigx(&t, sigoid_srt_xref,
+                                sizeof(sigoid_srt_xref) / sizeof(nid_triple *)
+                                );
+               }
+#endif
+       if (rv == NULL)
+               return 0;
+       *psignid = (*rv)->sign_id;
+       return 1;
+       }
+
+int OBJ_add_sigid(int signid, int dig_id, int pkey_id)
+       {
+       nid_triple *ntr;
+       if (!sig_app)
+               sig_app = sk_nid_triple_new(sig_sk_cmp);
+       if (!sig_app)
+               return 0;
+       if (!sigx_app)
+               sigx_app = sk_nid_triple_new(sigx_cmp);
+       if (!sigx_app)
+               return 0;
+       ntr = OPENSSL_malloc(sizeof(int) * 3);
+       if (!ntr)
+               return 0;
+       ntr->sign_id = signid;
+       ntr->hash_id = dig_id;
+       ntr->pkey_id = pkey_id;
+
+       if (!sk_nid_triple_push(sig_app, ntr))
+               {
+               OPENSSL_free(ntr);
+               return 0;
+               }
+
+       if (!sk_nid_triple_push(sigx_app, ntr))
+               return 0;
+
+       sk_nid_triple_sort(sig_app);
+       sk_nid_triple_sort(sigx_app);
+
+       return 1;
+       }
+
+static void sid_free(nid_triple *tt)
+       {
+       OPENSSL_free(tt);
+       }
+
+void OBJ_sigid_free(void)
+       {
+       if (sig_app)
+               {
+               sk_nid_triple_pop_free(sig_app, sid_free);
+               sig_app = NULL;
+               }
+       if (sigx_app)
+               {
+               sk_nid_triple_free(sigx_app);
+               sigx_app = NULL;
+               }
+       }
+               
+#ifdef OBJ_XREF_TEST
+
+main()
+       {
+       int n1, n2, n3;
+
+       int i, rv;
+#ifdef OBJ_XREF_TEST2
+       for (i = 0; i < sizeof(sigoid_srt) / sizeof(nid_triple); i++)
+               {
+               OBJ_add_sigid(sigoid_srt[i][0], sigoid_srt[i][1],
+                               sigoid_srt[i][2]);
+               }
+#endif
+
+       for (i = 0; i < sizeof(sigoid_srt) / sizeof(nid_triple); i++)
+               {
+               n1 = sigoid_srt[i][0];
+               rv = OBJ_find_sigid_algs(n1, &n2, &n3);
+               printf("Forward: %d, %s %s %s\n", rv,
+                       OBJ_nid2ln(n1), OBJ_nid2ln(n2), OBJ_nid2ln(n3));
+               n1=0;
+               rv = OBJ_find_sigid_by_algs(&n1, n2, n3);
+               printf("Reverse: %d, %s %s %s\n", rv,
+                       OBJ_nid2ln(n1), OBJ_nid2ln(n2), OBJ_nid2ln(n3));
+               }
+       }
+       
+#endif
diff --git a/deps/openssl/openssl/crypto/objects/obj_xref.h b/deps/openssl/openssl/crypto/objects/obj_xref.h
new file mode 100644 (file)
index 0000000..d5b9b8e
--- /dev/null
@@ -0,0 +1,75 @@
+/* AUTOGENERATED BY objxref.pl, DO NOT EDIT */
+
+typedef struct
+       {
+       int sign_id;
+       int hash_id;
+       int pkey_id;
+       } nid_triple;
+
+static const nid_triple sigoid_srt[] =
+       {
+       {NID_md2WithRSAEncryption, NID_md2, NID_rsaEncryption},
+       {NID_md5WithRSAEncryption, NID_md5, NID_rsaEncryption},
+       {NID_shaWithRSAEncryption, NID_sha, NID_rsaEncryption},
+       {NID_sha1WithRSAEncryption, NID_sha1, NID_rsaEncryption},
+       {NID_dsaWithSHA, NID_sha, NID_dsa},
+       {NID_dsaWithSHA1_2, NID_sha1, NID_dsa_2},
+       {NID_mdc2WithRSA, NID_mdc2, NID_rsaEncryption},
+       {NID_md5WithRSA, NID_md5, NID_rsa},
+       {NID_dsaWithSHA1, NID_sha1, NID_dsa},
+       {NID_sha1WithRSA, NID_sha1, NID_rsa},
+       {NID_ripemd160WithRSA, NID_ripemd160, NID_rsaEncryption},
+       {NID_md4WithRSAEncryption, NID_md4, NID_rsaEncryption},
+       {NID_ecdsa_with_SHA1, NID_sha1, NID_X9_62_id_ecPublicKey},
+       {NID_sha256WithRSAEncryption, NID_sha256, NID_rsaEncryption},
+       {NID_sha384WithRSAEncryption, NID_sha384, NID_rsaEncryption},
+       {NID_sha512WithRSAEncryption, NID_sha512, NID_rsaEncryption},
+       {NID_sha224WithRSAEncryption, NID_sha224, NID_rsaEncryption},
+       {NID_ecdsa_with_Recommended, NID_undef, NID_X9_62_id_ecPublicKey},
+       {NID_ecdsa_with_Specified, NID_undef, NID_X9_62_id_ecPublicKey},
+       {NID_ecdsa_with_SHA224, NID_sha224, NID_X9_62_id_ecPublicKey},
+       {NID_ecdsa_with_SHA256, NID_sha256, NID_X9_62_id_ecPublicKey},
+       {NID_ecdsa_with_SHA384, NID_sha384, NID_X9_62_id_ecPublicKey},
+       {NID_ecdsa_with_SHA512, NID_sha512, NID_X9_62_id_ecPublicKey},
+       {NID_dsa_with_SHA224, NID_sha224, NID_dsa},
+       {NID_dsa_with_SHA256, NID_sha256, NID_dsa},
+       {NID_id_GostR3411_94_with_GostR3410_2001, NID_id_GostR3411_94, NID_id_GostR3410_2001},
+       {NID_id_GostR3411_94_with_GostR3410_94, NID_id_GostR3411_94, NID_id_GostR3410_94},
+       {NID_id_GostR3411_94_with_GostR3410_94_cc, NID_id_GostR3411_94, NID_id_GostR3410_94_cc},
+       {NID_id_GostR3411_94_with_GostR3410_2001_cc, NID_id_GostR3411_94, NID_id_GostR3410_2001_cc},
+       };
+
+static const nid_triple * const sigoid_srt_xref[] =
+       {
+       &sigoid_srt[17],
+       &sigoid_srt[18],
+       &sigoid_srt[0],
+       &sigoid_srt[1],
+       &sigoid_srt[7],
+       &sigoid_srt[2],
+       &sigoid_srt[4],
+       &sigoid_srt[3],
+       &sigoid_srt[9],
+       &sigoid_srt[5],
+       &sigoid_srt[8],
+       &sigoid_srt[12],
+       &sigoid_srt[6],
+       &sigoid_srt[10],
+       &sigoid_srt[11],
+       &sigoid_srt[13],
+       &sigoid_srt[24],
+       &sigoid_srt[20],
+       &sigoid_srt[14],
+       &sigoid_srt[21],
+       &sigoid_srt[15],
+       &sigoid_srt[22],
+       &sigoid_srt[16],
+       &sigoid_srt[23],
+       &sigoid_srt[19],
+       &sigoid_srt[25],
+       &sigoid_srt[26],
+       &sigoid_srt[27],
+       &sigoid_srt[28],
+       };
+
diff --git a/deps/openssl/openssl/crypto/objects/obj_xref.txt b/deps/openssl/openssl/crypto/objects/obj_xref.txt
new file mode 100644 (file)
index 0000000..e45b3d3
--- /dev/null
@@ -0,0 +1,42 @@
+# OID cross reference table.
+# Links signatures OIDs to their corresponding public key algorithms
+# and digests.
+
+md2WithRSAEncryption   md2     rsaEncryption
+md5WithRSAEncryption   md5     rsaEncryption
+shaWithRSAEncryption   sha     rsaEncryption
+sha1WithRSAEncryption  sha1    rsaEncryption
+md4WithRSAEncryption   md4     rsaEncryption
+sha256WithRSAEncryption sha256 rsaEncryption
+sha384WithRSAEncryption        sha384  rsaEncryption
+sha512WithRSAEncryption        sha512  rsaEncryption
+sha224WithRSAEncryption        sha224  rsaEncryption
+mdc2WithRSA            mdc2    rsaEncryption
+ripemd160WithRSA       ripemd160 rsaEncryption
+
+# Alternative deprecated OIDs. By using the older "rsa" OID this
+# type will be recognized by not normally used.
+
+md5WithRSA             md5     rsa
+sha1WithRSA            sha1    rsa
+
+dsaWithSHA             sha     dsa
+dsaWithSHA1            sha1    dsa
+
+dsaWithSHA1_2          sha1    dsa_2
+
+ecdsa_with_SHA1                sha1    X9_62_id_ecPublicKey
+ecdsa_with_SHA224      sha224  X9_62_id_ecPublicKey
+ecdsa_with_SHA256      sha256  X9_62_id_ecPublicKey
+ecdsa_with_SHA384      sha384  X9_62_id_ecPublicKey
+ecdsa_with_SHA512      sha512  X9_62_id_ecPublicKey
+ecdsa_with_Recommended undef   X9_62_id_ecPublicKey
+ecdsa_with_Specified   undef   X9_62_id_ecPublicKey
+
+dsa_with_SHA224                sha224  dsa
+dsa_with_SHA256                sha256  dsa
+
+id_GostR3411_94_with_GostR3410_2001    id_GostR3411_94 id_GostR3410_2001
+id_GostR3411_94_with_GostR3410_94      id_GostR3411_94 id_GostR3410_94
+id_GostR3411_94_with_GostR3410_94_cc   id_GostR3411_94 id_GostR3410_94_cc
+id_GostR3411_94_with_GostR3410_2001_cc id_GostR3411_94 id_GostR3410_2001_cc
index 7242f76..bd0ee52 100644 (file)
@@ -1011,10 +1011,91 @@ int             OBJ_txt2nid(const char *s);
 int            OBJ_ln2nid(const char *s);
 int            OBJ_sn2nid(const char *s);
 int            OBJ_cmp(const ASN1_OBJECT *a,const ASN1_OBJECT *b);
-const char *   OBJ_bsearch(const char *key,const char *base,int num,int size,
-       int (*cmp)(const void *, const void *));
-const char *   OBJ_bsearch_ex(const char *key,const char *base,int num,
-       int size, int (*cmp)(const void *, const void *), int flags);
+const void *   OBJ_bsearch_(const void *key,const void *base,int num,int size,
+                            int (*cmp)(const void *, const void *));
+const void *   OBJ_bsearch_ex_(const void *key,const void *base,int num,
+                               int size,
+                               int (*cmp)(const void *, const void *),
+                               int flags);
+
+#define _DECLARE_OBJ_BSEARCH_CMP_FN(scope, type1, type2, nm)   \
+  static int nm##_cmp_BSEARCH_CMP_FN(const void *, const void *); \
+  static int nm##_cmp(type1 const *, type2 const *); \
+  scope type2 * OBJ_bsearch_##nm(type1 *key, type2 const *base, int num)
+
+#define DECLARE_OBJ_BSEARCH_CMP_FN(type1, type2, cmp)  \
+  _DECLARE_OBJ_BSEARCH_CMP_FN(static, type1, type2, cmp)
+#define DECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, nm)    \
+  type2 * OBJ_bsearch_##nm(type1 *key, type2 const *base, int num)
+
+/*
+ * Unsolved problem: if a type is actually a pointer type, like
+ * nid_triple is, then its impossible to get a const where you need
+ * it. Consider:
+ *
+ * typedef int nid_triple[3];
+ * const void *a_;
+ * const nid_triple const *a = a_;
+ *
+ * The assignement discards a const because what you really want is:
+ *
+ * const int const * const *a = a_;
+ *
+ * But if you do that, you lose the fact that a is an array of 3 ints,
+ * which breaks comparison functions.
+ *
+ * Thus we end up having to cast, sadly, or unpack the
+ * declarations. Or, as I finally did in this case, delcare nid_triple
+ * to be a struct, which it should have been in the first place.
+ *
+ * Ben, August 2008.
+ *
+ * Also, strictly speaking not all types need be const, but handling
+ * the non-constness means a lot of complication, and in practice
+ * comparison routines do always not touch their arguments.
+ */
+
+#define IMPLEMENT_OBJ_BSEARCH_CMP_FN(type1, type2, nm) \
+  static int nm##_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_)   \
+      { \
+      type1 const *a = a_; \
+      type2 const *b = b_; \
+      return nm##_cmp(a,b); \
+      } \
+  static type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) \
+      { \
+      return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \
+                                       nm##_cmp_BSEARCH_CMP_FN); \
+      } \
+      extern void dummy_prototype(void)
+
+#define IMPLEMENT_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, nm)  \
+  static int nm##_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_)   \
+      { \
+      type1 const *a = a_; \
+      type2 const *b = b_; \
+      return nm##_cmp(a,b); \
+      } \
+  type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) \
+      { \
+      return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \
+                                       nm##_cmp_BSEARCH_CMP_FN); \
+      } \
+      extern void dummy_prototype(void)
+
+#define OBJ_bsearch(type1,key,type2,base,num,cmp)                             \
+  ((type2 *)OBJ_bsearch_(CHECKED_PTR_OF(type1,key),CHECKED_PTR_OF(type2,base), \
+                        num,sizeof(type2),                             \
+                        ((void)CHECKED_PTR_OF(type1,cmp##_type_1),     \
+                         (void)CHECKED_PTR_OF(type2,cmp##_type_2),     \
+                         cmp##_BSEARCH_CMP_FN)))
+
+#define OBJ_bsearch_ex(type1,key,type2,base,num,cmp,flags)                     \
+  ((type2 *)OBJ_bsearch_ex_(CHECKED_PTR_OF(type1,key),CHECKED_PTR_OF(type2,base), \
+                        num,sizeof(type2),                             \
+                        ((void)CHECKED_PTR_OF(type1,cmp##_type_1),     \
+                         (void)type_2=CHECKED_PTR_OF(type2,cmp##_type_2), \
+                         cmp##_BSEARCH_CMP_FN)),flags)
 
 int            OBJ_new_nid(int num);
 int            OBJ_add_object(const ASN1_OBJECT *obj);
@@ -1022,6 +1103,14 @@ int              OBJ_create(const char *oid,const char *sn,const char *ln);
 void           OBJ_cleanup(void );
 int            OBJ_create_objects(BIO *in);
 
+int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid);
+int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid);
+int OBJ_add_sigid(int signid, int dig_id, int pkey_id);
+void OBJ_sigid_free(void);
+
+extern int obj_cleanup_defer;
+void check_defer(int nid);
+
 /* BEGIN ERROR CODES */
 /* The following lines are auto generated by the script mkerr.pl. Any changes
  * made after this point may be overwritten when the script is next run.
index 76c06cc..15c00bb 100644 (file)
@@ -14,6 +14,8 @@ while(<NUMIN>)
        $Cname =~ s/^X//;
        if (defined($nidn{$mynum}))
                { die "$ARGV[1]:$o:There's already an object with NID ",$mynum," on line ",$order{$mynum},"\n"; }
+       if (defined($nid{$Cname}))
+               { die "$ARGV[1]:$o:There's already an object with name ",$Cname," on line ",$order{$nid{$Cname}},"\n"; }
        $nid{$Cname} = $mynum;
        $nidn{$mynum} = $Cname;
        $order{$mynum} = $o;
@@ -102,6 +104,7 @@ while (<IN>)
                $max_nid++;
                $nid{$Cname} = $max_nid;
                $nidn{$max_nid} = $Cname;
+print STDERR "Added OID $Cname\n";
                }
        $Cname="";
        }
diff --git a/deps/openssl/openssl/crypto/objects/objxref.pl b/deps/openssl/openssl/crypto/objects/objxref.pl
new file mode 100644 (file)
index 0000000..731d3ae
--- /dev/null
@@ -0,0 +1,107 @@
+#!/usr/local/bin/perl
+
+use strict;
+
+my %xref_tbl;
+my %oid_tbl;
+
+my ($mac_file, $xref_file) = @ARGV;
+
+open(IN, $mac_file) || die "Can't open $mac_file";
+
+# Read in OID nid values for a lookup table.
+
+while (<IN>)
+       {
+       chomp;
+       my ($name, $num) = /^(\S+)\s+(\S+)$/;
+       $oid_tbl{$name} = $num;
+       }
+close IN;
+
+open(IN, $xref_file) || die "Can't open $xref_file";
+
+my $ln = 1;
+
+while (<IN>)
+       {
+       chomp;
+       s/#.*$//;
+       next if (/^\S*$/);
+       my ($xr, $p1, $p2) = /^(\S+)\s+(\S+)\s+(\S+)/;
+       check_oid($xr);
+       check_oid($p1);
+       check_oid($p2);
+       $xref_tbl{$xr} = [$p1, $p2, $ln];
+       }
+
+my @xrkeys = keys %xref_tbl;
+
+my @srt1 = sort { $oid_tbl{$a} <=> $oid_tbl{$b}} @xrkeys;
+
+for(my $i = 0; $i <= $#srt1; $i++)
+       {
+       $xref_tbl{$srt1[$i]}[2] = $i;
+       }
+
+my @srt2 = sort
+       {
+       my$ap1 = $oid_tbl{$xref_tbl{$a}[0]};
+       my$bp1 = $oid_tbl{$xref_tbl{$b}[0]};
+       return $ap1 - $bp1 if ($ap1 != $bp1);
+       my$ap2 = $oid_tbl{$xref_tbl{$a}[1]};
+       my$bp2 = $oid_tbl{$xref_tbl{$b}[1]};
+
+       return $ap2 - $bp2;
+       } @xrkeys;
+
+my $pname = $0;
+
+$pname =~ s|^.[^/]/||;
+
+print <<EOF;
+/* AUTOGENERATED BY $pname, DO NOT EDIT */
+
+typedef struct
+       {
+       int sign_id;
+       int hash_id;
+       int pkey_id;
+       } nid_triple;
+
+static const nid_triple sigoid_srt[] =
+       {
+EOF
+
+foreach (@srt1)
+       {
+       my $xr = $_;
+       my ($p1, $p2) = @{$xref_tbl{$_}};
+       print "\t{NID_$xr, NID_$p1, NID_$p2},\n";
+       }
+
+print "\t};";
+print <<EOF;
+
+
+static const nid_triple * const sigoid_srt_xref[] =
+       {
+EOF
+
+foreach (@srt2)
+       {
+       my $x = $xref_tbl{$_}[2];
+       print "\t\&sigoid_srt\[$x\],\n";
+       }
+
+print "\t};\n\n";
+
+sub check_oid
+       {
+       my ($chk) = @_;
+       if (!exists $oid_tbl{$chk})
+               {
+               die "Not Found \"$chk\"\n";
+               }
+       }
+
index 30a00b3..60c414c 100644 (file)
@@ -36,7 +36,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -82,10 +82,9 @@ ocsp_asn.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 ocsp_asn.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 ocsp_asn.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 ocsp_asn.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
-ocsp_asn.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-ocsp_asn.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-ocsp_asn.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h
-ocsp_asn.o: ../../include/openssl/opensslconf.h
+ocsp_asn.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+ocsp_asn.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+ocsp_asn.o: ../../include/openssl/ocsp.h ../../include/openssl/opensslconf.h
 ocsp_asn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 ocsp_asn.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 ocsp_asn.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -98,25 +97,24 @@ ocsp_cl.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 ocsp_cl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 ocsp_cl.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 ocsp_cl.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-ocsp_cl.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-ocsp_cl.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-ocsp_cl.o: ../../include/openssl/ocsp.h ../../include/openssl/opensslconf.h
-ocsp_cl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-ocsp_cl.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
-ocsp_cl.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
-ocsp_cl.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-ocsp_cl.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-ocsp_cl.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-ocsp_cl.o: ../../include/openssl/x509v3.h ../cryptlib.h ocsp_cl.c
+ocsp_cl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+ocsp_cl.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h
+ocsp_cl.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+ocsp_cl.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
+ocsp_cl.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
+ocsp_cl.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
+ocsp_cl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+ocsp_cl.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+ocsp_cl.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+ocsp_cl.o: ../cryptlib.h ocsp_cl.c
 ocsp_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
 ocsp_err.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 ocsp_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 ocsp_err.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 ocsp_err.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-ocsp_err.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-ocsp_err.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-ocsp_err.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h
-ocsp_err.o: ../../include/openssl/opensslconf.h
+ocsp_err.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+ocsp_err.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+ocsp_err.o: ../../include/openssl/ocsp.h ../../include/openssl/opensslconf.h
 ocsp_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 ocsp_err.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 ocsp_err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -129,9 +127,9 @@ ocsp_ext.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 ocsp_ext.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 ocsp_ext.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 ocsp_ext.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-ocsp_ext.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-ocsp_ext.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-ocsp_ext.o: ../../include/openssl/ocsp.h ../../include/openssl/opensslconf.h
+ocsp_ext.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+ocsp_ext.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h
+ocsp_ext.o: ../../include/openssl/opensslconf.h
 ocsp_ext.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 ocsp_ext.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
 ocsp_ext.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
@@ -144,22 +142,21 @@ ocsp_ht.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 ocsp_ht.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 ocsp_ht.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 ocsp_ht.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-ocsp_ht.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-ocsp_ht.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-ocsp_ht.o: ../../include/openssl/ocsp.h ../../include/openssl/opensslconf.h
-ocsp_ht.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-ocsp_ht.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-ocsp_ht.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-ocsp_ht.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-ocsp_ht.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
-ocsp_ht.o: ocsp_ht.c
+ocsp_ht.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+ocsp_ht.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h
+ocsp_ht.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+ocsp_ht.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+ocsp_ht.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+ocsp_ht.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+ocsp_ht.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+ocsp_ht.o: ../../include/openssl/x509v3.h ocsp_ht.c
 ocsp_lib.o: ../../e_os.h ../../include/openssl/asn1.h
-ocsp_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
-ocsp_lib.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
-ocsp_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-ocsp_lib.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
-ocsp_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-ocsp_lib.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
+ocsp_lib.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
+ocsp_lib.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
+ocsp_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+ocsp_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+ocsp_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
+ocsp_lib.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
 ocsp_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
 ocsp_lib.o: ../../include/openssl/ocsp.h ../../include/openssl/opensslconf.h
 ocsp_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
@@ -174,10 +171,9 @@ ocsp_prn.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 ocsp_prn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 ocsp_prn.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 ocsp_prn.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-ocsp_prn.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-ocsp_prn.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-ocsp_prn.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h
-ocsp_prn.o: ../../include/openssl/opensslconf.h
+ocsp_prn.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+ocsp_prn.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+ocsp_prn.o: ../../include/openssl/ocsp.h ../../include/openssl/opensslconf.h
 ocsp_prn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 ocsp_prn.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
 ocsp_prn.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
@@ -191,9 +187,9 @@ ocsp_srv.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 ocsp_srv.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 ocsp_srv.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 ocsp_srv.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-ocsp_srv.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-ocsp_srv.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-ocsp_srv.o: ../../include/openssl/ocsp.h ../../include/openssl/opensslconf.h
+ocsp_srv.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+ocsp_srv.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h
+ocsp_srv.o: ../../include/openssl/opensslconf.h
 ocsp_srv.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 ocsp_srv.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
 ocsp_srv.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
@@ -206,10 +202,9 @@ ocsp_vfy.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 ocsp_vfy.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 ocsp_vfy.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 ocsp_vfy.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-ocsp_vfy.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-ocsp_vfy.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-ocsp_vfy.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h
-ocsp_vfy.o: ../../include/openssl/opensslconf.h
+ocsp_vfy.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+ocsp_vfy.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+ocsp_vfy.o: ../../include/openssl/ocsp.h ../../include/openssl/opensslconf.h
 ocsp_vfy.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 ocsp_vfy.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 ocsp_vfy.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
index a0577a7..31e4574 100644 (file)
@@ -64,6 +64,7 @@
 #ifndef HEADER_OCSP_H
 #define HEADER_OCSP_H
 
+#include <openssl/ossl_typ.h>
 #include <openssl/x509.h>
 #include <openssl/x509v3.h>
 #include <openssl/safestack.h>
@@ -394,17 +395,20 @@ typedef struct ocsp_service_locator_st
 #define ASN1_BIT_STRING_digest(data,type,md,len) \
        ASN1_item_digest(ASN1_ITEM_rptr(ASN1_BIT_STRING),type,data,md,len)
 
-#define OCSP_CERTID_dup(cid) ASN1_dup_of(OCSP_CERTID,i2d_OCSP_CERTID,d2i_OCSP_CERTID,cid)
-
 #define OCSP_CERTSTATUS_dup(cs)\
                 (OCSP_CERTSTATUS*)ASN1_dup((int(*)())i2d_OCSP_CERTSTATUS,\
                (char *(*)())d2i_OCSP_CERTSTATUS,(char *)(cs))
 
+OCSP_CERTID *OCSP_CERTID_dup(OCSP_CERTID *id);
+
 OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, char *path, OCSP_REQUEST *req);
 OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, char *path, OCSP_REQUEST *req,
                                                                int maxline);
 int OCSP_sendreq_nbio(OCSP_RESPONSE **presp, OCSP_REQ_CTX *rctx);
 void OCSP_REQ_CTX_free(OCSP_REQ_CTX *rctx);
+int OCSP_REQ_CTX_set1_req(OCSP_REQ_CTX *rctx, OCSP_REQUEST *req);
+int OCSP_REQ_CTX_add1_header(OCSP_REQ_CTX *rctx,
+               const char *name, const char *value);
 
 OCSP_CERTID *OCSP_cert_to_id(const EVP_MD *dgst, X509 *subject, X509 *issuer);
 
@@ -474,11 +478,6 @@ int OCSP_basic_sign(OCSP_BASICRESP *brsp,
                        X509 *signer, EVP_PKEY *key, const EVP_MD *dgst,
                        STACK_OF(X509) *certs, unsigned long flags);
 
-ASN1_STRING *ASN1_STRING_encode(ASN1_STRING *s, i2d_of_void *i2d,
-                               void *data, STACK_OF(ASN1_OBJECT) *sk);
-#define ASN1_STRING_encode_of(type,s,i2d,data,sk) \
-       ASN1_STRING_encode(s, CHECKED_I2D_OF(type, i2d), data, sk)
-
 X509_EXTENSION *OCSP_crlID_new(char *url, long *n, char *tim);
 
 X509_EXTENSION *OCSP_accept_responses_new(char **oids);
@@ -547,9 +546,9 @@ DECLARE_ASN1_FUNCTIONS(OCSP_REQINFO)
 DECLARE_ASN1_FUNCTIONS(OCSP_CRLID)
 DECLARE_ASN1_FUNCTIONS(OCSP_SERVICELOC)
 
-char *OCSP_response_status_str(long s);
-char *OCSP_cert_status_str(long s);
-char *OCSP_crl_reason_str(long s);
+const char *OCSP_response_status_str(long s);
+const char *OCSP_cert_status_str(long s);
+const char *OCSP_crl_reason_str(long s);
 
 int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST* a, unsigned long flags);
 int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE* o, unsigned long flags);
@@ -582,7 +581,8 @@ void ERR_load_OCSP_strings(void);
 #define OCSP_F_OCSP_REQUEST_VERIFY                      116
 #define OCSP_F_OCSP_RESPONSE_GET1_BASIC                         111
 #define OCSP_F_OCSP_SENDREQ_BIO                                 112
-#define OCSP_F_PARSE_HTTP_LINE1                                 117
+#define OCSP_F_OCSP_SENDREQ_NBIO                        117
+#define OCSP_F_PARSE_HTTP_LINE1                                 118
 #define OCSP_F_REQUEST_VERIFY                           113
 
 /* Reason codes. */
index 17bab5f..9c14d9d 100644 (file)
@@ -155,7 +155,6 @@ int OCSP_request_sign(OCSP_REQUEST   *req,
                        goto err;
 
        if (!(req->optionalSignature = sig = OCSP_SIGNATURE_new())) goto err;
-       if (!dgst) dgst = EVP_sha1();
        if (key)
                {
                if (!X509_check_private_key(signer, key))
index d2f2e79..0cedcea 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/ocsp/ocsp_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2007 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -86,6 +86,7 @@ static ERR_STRING_DATA OCSP_str_functs[]=
 {ERR_FUNC(OCSP_F_OCSP_REQUEST_VERIFY), "OCSP_request_verify"},
 {ERR_FUNC(OCSP_F_OCSP_RESPONSE_GET1_BASIC),    "OCSP_response_get1_basic"},
 {ERR_FUNC(OCSP_F_OCSP_SENDREQ_BIO),    "OCSP_sendreq_bio"},
+{ERR_FUNC(OCSP_F_OCSP_SENDREQ_NBIO),   "OCSP_sendreq_nbio"},
 {ERR_FUNC(OCSP_F_PARSE_HTTP_LINE1),    "PARSE_HTTP_LINE1"},
 {ERR_FUNC(OCSP_F_REQUEST_VERIFY),      "REQUEST_VERIFY"},
 {0,NULL}
index 815cc29..ec884cb 100644 (file)
@@ -264,7 +264,7 @@ int OCSP_SINGLERESP_add_ext(OCSP_SINGLERESP *x, X509_EXTENSION *ex, int loc)
        }
 
 /* also CRL Entry Extensions */
-
+#if 0
 ASN1_STRING *ASN1_STRING_encode(ASN1_STRING *s, i2d_of_void *i2d,
                                void *data, STACK_OF(ASN1_OBJECT) *sk)
         {
@@ -305,6 +305,7 @@ err:
        if (b) OPENSSL_free(b);
        return NULL;
        }
+#endif
 
 /* Nonce handling functions */
 
@@ -442,17 +443,10 @@ X509_EXTENSION *OCSP_crlID_new(char *url, long *n, char *tim)
                if (!(ASN1_GENERALIZEDTIME_set_string(cid->crlTime, tim))) 
                        goto err;
                }
-       if (!(x = X509_EXTENSION_new())) goto err;
-       if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_CrlID))) goto err;
-       if (!(ASN1_STRING_encode_of(OCSP_CRLID,x->value,i2d_OCSP_CRLID,cid,
-                                   NULL)))
-               goto err;
-       OCSP_CRLID_free(cid);
-       return x;
+       x = X509V3_EXT_i2d(NID_id_pkix_OCSP_CrlID, 0, cid);
 err:
-       if (x) X509_EXTENSION_free(x);
        if (cid) OCSP_CRLID_free(cid);
-       return NULL;
+       return x;
        }
 
 /*   AcceptableResponses ::= SEQUENCE OF OBJECT IDENTIFIER */
@@ -470,18 +464,10 @@ X509_EXTENSION *OCSP_accept_responses_new(char **oids)
                        sk_ASN1_OBJECT_push(sk, o);
                oids++;
                }
-       if (!(x = X509_EXTENSION_new())) goto err;
-       if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_acceptableResponses)))
-               goto err;
-       if (!(ASN1_STRING_encode_of(ASN1_OBJECT,x->value,i2d_ASN1_OBJECT,NULL,
-                                   sk)))
-               goto err;
-       sk_ASN1_OBJECT_pop_free(sk, ASN1_OBJECT_free);
-       return x;
+       x = X509V3_EXT_i2d(NID_id_pkix_OCSP_acceptableResponses, 0, sk);
 err:
-       if (x) X509_EXTENSION_free(x);
        if (sk) sk_ASN1_OBJECT_pop_free(sk, ASN1_OBJECT_free);
-       return NULL;
+       return x;
         }
 
 /*  ArchiveCutoff ::= GeneralizedTime */
@@ -492,16 +478,10 @@ X509_EXTENSION *OCSP_archive_cutoff_new(char* tim)
 
        if (!(gt = ASN1_GENERALIZEDTIME_new())) goto err;
        if (!(ASN1_GENERALIZEDTIME_set_string(gt, tim))) goto err;
-       if (!(x = X509_EXTENSION_new())) goto err;
-       if (!(x->object=OBJ_nid2obj(NID_id_pkix_OCSP_archiveCutoff)))goto err;
-       if (!(ASN1_STRING_encode_of(ASN1_GENERALIZEDTIME,x->value,
-                                   i2d_ASN1_GENERALIZEDTIME,gt,NULL))) goto err;
-       ASN1_GENERALIZEDTIME_free(gt);
-       return x;
+       x = X509V3_EXT_i2d(NID_id_pkix_OCSP_archiveCutoff, 0, gt);
 err:
        if (gt) ASN1_GENERALIZEDTIME_free(gt);
-       if (x) X509_EXTENSION_free(x);
-       return NULL;
+       return x;
        }
 
 /* per ACCESS_DESCRIPTION parameter are oids, of which there are currently
@@ -530,16 +510,9 @@ X509_EXTENSION *OCSP_url_svcloc_new(X509_NAME* issuer, char **urls)
                if (!sk_ACCESS_DESCRIPTION_push(sloc->locator, ad)) goto err;
                urls++;
                }
-       if (!(x = X509_EXTENSION_new())) goto err;
-       if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_serviceLocator))) 
-               goto err;
-       if (!(ASN1_STRING_encode_of(OCSP_SERVICELOC,x->value,
-                                   i2d_OCSP_SERVICELOC,sloc,NULL))) goto err;
-       OCSP_SERVICELOC_free(sloc);
-       return x;
+       x = X509V3_EXT_i2d(NID_id_pkix_OCSP_serviceLocator, 0, sloc);
 err:
-       if (x) X509_EXTENSION_free(x);
        if (sloc) OCSP_SERVICELOC_free(sloc);
-       return NULL;
+       return x;
        }
 
index 92aba08..af5fc16 100644 (file)
@@ -118,39 +118,65 @@ void OCSP_REQ_CTX_free(OCSP_REQ_CTX *rctx)
        OPENSSL_free(rctx);
        }
 
-OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, char *path, OCSP_REQUEST *req,
-                                                               int maxline)
+int OCSP_REQ_CTX_set1_req(OCSP_REQ_CTX *rctx, OCSP_REQUEST *req)
        {
-       static char post_hdr[] = "POST %s HTTP/1.0\r\n"
+       static const char req_hdr[] =
        "Content-Type: application/ocsp-request\r\n"
        "Content-Length: %d\r\n\r\n";
+        if (BIO_printf(rctx->mem, req_hdr, i2d_OCSP_REQUEST(req, NULL)) <= 0)
+               return 0;
+        if (i2d_OCSP_REQUEST_bio(rctx->mem, req) <= 0)
+               return 0;
+       rctx->state = OHS_ASN1_WRITE;
+       rctx->asn1_len = BIO_get_mem_data(rctx->mem, NULL);
+       return 1;
+       }
+
+int OCSP_REQ_CTX_add1_header(OCSP_REQ_CTX *rctx,
+               const char *name, const char *value)
+       {
+       if (!name)
+               return 0;
+       if (BIO_puts(rctx->mem, name) <= 0)
+               return 0;
+       if (value)
+               {
+               if (BIO_write(rctx->mem, ": ", 2) != 2)
+                       return 0;
+               if (BIO_puts(rctx->mem, value) <= 0)
+                       return 0;
+               }
+       if (BIO_write(rctx->mem, "\r\n", 2) != 2)
+               return 0;
+       return 1;
+       }
+
+OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, char *path, OCSP_REQUEST *req,
+                                                               int maxline)
+       {
+       static const char post_hdr[] = "POST %s HTTP/1.0\r\n";
 
        OCSP_REQ_CTX *rctx;
        rctx = OPENSSL_malloc(sizeof(OCSP_REQ_CTX));
-       rctx->state = OHS_FIRSTLINE;
+       rctx->state = OHS_ERROR;
        rctx->mem = BIO_new(BIO_s_mem());
        rctx->io = io;
+       rctx->asn1_len = 0;
        if (maxline > 0)
                rctx->iobuflen = maxline;
        else
                rctx->iobuflen = OCSP_MAX_LINE_LEN;
        rctx->iobuf = OPENSSL_malloc(rctx->iobuflen);
+       if (!rctx->iobuf)
+               return 0;
        if (!path)
                path = "/";
 
-        if (BIO_printf(rctx->mem, post_hdr, path,
-                               i2d_OCSP_REQUEST(req, NULL)) <= 0)
-               {
-               rctx->state = OHS_ERROR;
+        if (BIO_printf(rctx->mem, post_hdr, path) <= 0)
                return 0;
-               }
-        if (i2d_OCSP_REQUEST_bio(rctx->mem, req) <= 0)
-               {
-               rctx->state = OHS_ERROR;
+
+       if (req && !OCSP_REQ_CTX_set1_req(rctx, req))
                return 0;
-               }
-       rctx->state = OHS_ASN1_WRITE;
-       rctx->asn1_len = BIO_get_mem_data(rctx->mem, NULL);
 
        return rctx;
        }
index 2745081..e92b86c 100644 (file)
@@ -69,6 +69,7 @@
 #include <openssl/pem.h>
 #include <openssl/x509v3.h>
 #include <openssl/ocsp.h>
+#include <openssl/asn1t.h>
 
 /* Convert a certificate and its issuer to an OCSP_CERTID */
 
@@ -169,14 +170,14 @@ int OCSP_parse_url(char *url, char **phost, char **pport, char **ppath, int *pss
 
        char *host, *port;
 
-       /* dup the buffer since we are going to mess with it */
-       buf = BUF_strdup(url);
-       if (!buf) goto mem_err;
-
        *phost = NULL;
        *pport = NULL;
        *ppath = NULL;
 
+       /* dup the buffer since we are going to mess with it */
+       buf = BUF_strdup(url);
+       if (!buf) goto mem_err;
+
        /* Check for initial colon */
        p = strchr(buf, ':');
 
@@ -260,3 +261,5 @@ int OCSP_parse_url(char *url, char **phost, char **pport, char **ppath, int *pss
        return 0;
 
        }
+
+IMPLEMENT_ASN1_DUP_FUNCTION(OCSP_CERTID)
index b8b7871..87608ff 100644 (file)
@@ -85,21 +85,21 @@ static int ocsp_certid_print(BIO *bp, OCSP_CERTID* a, int indent)
 typedef struct
        {
        long t;
-       char *m;
+       const char *m;
        } OCSP_TBLSTR;
 
-static char *table2string(long s, OCSP_TBLSTR *ts, int len)
+static const char *table2string(long s, const OCSP_TBLSTR *ts, int len)
 {
-       OCSP_TBLSTR *p;
+       const OCSP_TBLSTR *p;
        for (p=ts; p < ts + len; p++)
                if (p->t == s)
                         return p->m;
        return "(UNKNOWN)";
 }
 
-char *OCSP_response_status_str(long s)
+const char *OCSP_response_status_str(long s)
         {
-       static OCSP_TBLSTR rstat_tbl[] = {
+       static const OCSP_TBLSTR rstat_tbl[] = {
                { OCSP_RESPONSE_STATUS_SUCCESSFUL, "successful" },
                { OCSP_RESPONSE_STATUS_MALFORMEDREQUEST, "malformedrequest" },
                { OCSP_RESPONSE_STATUS_INTERNALERROR, "internalerror" },
@@ -109,18 +109,18 @@ char *OCSP_response_status_str(long s)
        return table2string(s, rstat_tbl, 6);
        } 
 
-char *OCSP_cert_status_str(long s)
+const char *OCSP_cert_status_str(long s)
         {
-       static OCSP_TBLSTR cstat_tbl[] = {
+       static const OCSP_TBLSTR cstat_tbl[] = {
                { V_OCSP_CERTSTATUS_GOOD, "good" },
                { V_OCSP_CERTSTATUS_REVOKED, "revoked" },
                { V_OCSP_CERTSTATUS_UNKNOWN, "unknown" } };
        return table2string(s, cstat_tbl, 3);
        } 
 
-char *OCSP_crl_reason_str(long s)
+const char *OCSP_crl_reason_str(long s)
         {
-       OCSP_TBLSTR reason_tbl[] = {
+       static const OCSP_TBLSTR reason_tbl[] = {
          { OCSP_REVOKED_STATUS_UNSPECIFIED, "unspecified" },
           { OCSP_REVOKED_STATUS_KEYCOMPROMISE, "keyCompromise" },
           { OCSP_REVOKED_STATUS_CACOMPROMISE, "cACompromise" },
index 4a0c387..415d67e 100644 (file)
@@ -308,6 +308,8 @@ static int ocsp_match_issuerid(X509 *cert, OCSP_CERTID *cid,
                        }
 
                mdlen = EVP_MD_size(dgst);
+               if (mdlen < 0)
+                   return -1;
                if ((cid->issuerNameHash->length != mdlen) ||
                   (cid->issuerKeyHash->length != mdlen))
                        return 0;
@@ -316,7 +318,7 @@ static int ocsp_match_issuerid(X509 *cert, OCSP_CERTID *cid,
                        return -1;
                if (memcmp(md, cid->issuerNameHash->data, mdlen))
                        return 0;
-               X509_pubkey_digest(cert, EVP_sha1(), md, NULL);
+               X509_pubkey_digest(cert, dgst, md, NULL);
                if (memcmp(md, cid->issuerKeyHash->data, mdlen))
                        return 0;
 
index 1c77f03..97e3745 100644 (file)
@@ -1,20 +1,5 @@
 /* crypto/opensslconf.h.in */
 
-#ifdef OPENSSL_DOING_MAKEDEPEND
-
-/* Include any symbols here that have to be explicitly set to enable a feature
- * that should be visible to makedepend.
- *
- * [Our "make depend" doesn't actually look at this, we use actual build settings
- * instead; we want to make it easy to remove subdirectories with disabled algorithms.]
- */
-
-#ifndef OPENSSL_FIPS
-#define OPENSSL_FIPS
-#endif
-
-#endif
-
 /* Generate 80386 code? */
 #undef I386_ONLY
 
 /* Should we define BN_DIV2W here? */
 
 /* Only one for the following should be defined */
-/* The prime number generation stuff may not work when
- * EIGHT_BIT but I don't care since I've only used this mode
- * for debuging the bignum libraries */
 #undef SIXTY_FOUR_BIT_LONG
 #undef SIXTY_FOUR_BIT
 #define THIRTY_TWO_BIT
-#undef SIXTEEN_BIT
-#undef EIGHT_BIT
 #endif
 
 #if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H)
index 385e1f6..d6d61a0 100644 (file)
@@ -12,7 +12,7 @@
  * 0.9.3-beta2    0x00903002 (same as ...beta2-dev)
  * 0.9.3         0x0090300f
  * 0.9.3a        0x0090301f
- * 0.9.4         0x0090400f
+ * 0.9.4         0x0090400f
  * 1.2.3z        0x102031af
  *
  * For continuity reasons (because 0.9.5 is already out, and is coded
  * (Prior to 0.9.5a beta1, a different scheme was used: MMNNFFRBB for
  *  major minor fix final patch/beta)
  */
-#define OPENSSL_VERSION_NUMBER 0x0090812fL
+#define OPENSSL_VERSION_NUMBER 0x1000006fL
 #ifdef OPENSSL_FIPS
-#define OPENSSL_VERSION_TEXT   "OpenSSL 0.9.8r-fips 8 Feb 2011"
+#define OPENSSL_VERSION_TEXT   "OpenSSL 1.0.0f-fips 4 Jan 2012"
 #else
-#define OPENSSL_VERSION_TEXT   "OpenSSL 0.9.8r 8 Feb 2011"
+#define OPENSSL_VERSION_TEXT   "OpenSSL 1.0.0f 4 Jan 2012"
 #endif
 #define OPENSSL_VERSION_PTEXT  " part of " OPENSSL_VERSION_TEXT
 
@@ -83,7 +83,7 @@
  * should only keep the versions that are binary compatible with the current.
  */
 #define SHLIB_VERSION_HISTORY ""
-#define SHLIB_VERSION_NUMBER "0.9.8"
+#define SHLIB_VERSION_NUMBER "1.0.0"
 
 
 #endif /* HEADER_OPENSSLV_H */
index 0e7a380..12bd701 100644 (file)
@@ -95,6 +95,8 @@ typedef int ASN1_BOOLEAN;
 typedef int ASN1_NULL;
 #endif
 
+typedef struct asn1_pctx_st ASN1_PCTX;
+
 #ifdef OPENSSL_SYS_WIN32
 #undef X509_NAME
 #undef X509_EXTENSIONS
@@ -122,6 +124,11 @@ typedef struct env_md_st EVP_MD;
 typedef struct env_md_ctx_st EVP_MD_CTX;
 typedef struct evp_pkey_st EVP_PKEY;
 
+typedef struct evp_pkey_asn1_method_st EVP_PKEY_ASN1_METHOD;
+
+typedef struct evp_pkey_method_st EVP_PKEY_METHOD;
+typedef struct evp_pkey_ctx_st EVP_PKEY_CTX;
+
 typedef struct dh_st DH;
 typedef struct dh_method DH_METHOD;
 
@@ -139,11 +146,14 @@ typedef struct ecdsa_method ECDSA_METHOD;
 typedef struct x509_st X509;
 typedef struct X509_algor_st X509_ALGOR;
 typedef struct X509_crl_st X509_CRL;
+typedef struct x509_crl_method_st X509_CRL_METHOD;
+typedef struct x509_revoked_st X509_REVOKED;
 typedef struct X509_name_st X509_NAME;
+typedef struct X509_pubkey_st X509_PUBKEY;
 typedef struct x509_store_st X509_STORE;
 typedef struct x509_store_ctx_st X509_STORE_CTX;
-typedef struct ssl_st SSL;
-typedef struct ssl_ctx_st SSL_CTX;
+
+typedef struct pkcs8_priv_key_info_st PKCS8_PRIV_KEY_INFO;
 
 typedef struct v3_ext_ctx X509V3_CTX;
 typedef struct conf_st CONF;
@@ -157,12 +167,19 @@ typedef struct ui_method_st UI_METHOD;
 typedef struct st_ERR_FNS ERR_FNS;
 
 typedef struct engine_st ENGINE;
+typedef struct ssl_st SSL;
+typedef struct ssl_ctx_st SSL_CTX;
 
 typedef struct X509_POLICY_NODE_st X509_POLICY_NODE;
 typedef struct X509_POLICY_LEVEL_st X509_POLICY_LEVEL;
 typedef struct X509_POLICY_TREE_st X509_POLICY_TREE;
 typedef struct X509_POLICY_CACHE_st X509_POLICY_CACHE;
 
+typedef struct AUTHORITY_KEYID_st AUTHORITY_KEYID;
+typedef struct DIST_POINT_st DIST_POINT;
+typedef struct ISSUING_DIST_POINT_st ISSUING_DIST_POINT;
+typedef struct NAME_CONSTRAINTS_st NAME_CONSTRAINTS;
+
   /* If placed in pkcs12.h, we end up with a circular depency with pkcs7.h */
 #define DECLARE_PKCS12_STACK_OF(type) /* Nothing */
 #define IMPLEMENT_PKCS12_STACK_OF(type) /* Nothing */
index 669f366..2cc7801 100644 (file)
@@ -18,10 +18,10 @@ APPS=
 
 LIB=$(TOP)/libcrypto.a
 LIBSRC= pem_sign.c pem_seal.c pem_info.c pem_lib.c pem_all.c pem_err.c \
-       pem_x509.c pem_xaux.c pem_oth.c pem_pk8.c pem_pkey.c
+       pem_x509.c pem_xaux.c pem_oth.c pem_pk8.c pem_pkey.c pvkfmt.c
 
 LIBOBJ=        pem_sign.o pem_seal.o pem_info.o pem_lib.o pem_all.o pem_err.o \
-       pem_x509.o pem_xaux.o pem_oth.o pem_pk8.o pem_pkey.o
+       pem_x509.o pem_xaux.o pem_oth.o pem_pk8.o pem_pkey.o pvkfmt.o
 
 SRC= $(LIBSRC)
 
@@ -36,7 +36,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -83,39 +83,36 @@ pem_all.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
 pem_all.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
 pem_all.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 pem_all.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-pem_all.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-pem_all.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-pem_all.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-pem_all.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-pem_all.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
-pem_all.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
-pem_all.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-pem_all.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-pem_all.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-pem_all.o: ../cryptlib.h pem_all.c
+pem_all.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+pem_all.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+pem_all.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+pem_all.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
+pem_all.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
+pem_all.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+pem_all.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+pem_all.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+pem_all.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_all.c
 pem_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
 pem_err.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 pem_err.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 pem_err.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 pem_err.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-pem_err.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-pem_err.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-pem_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-pem_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
-pem_err.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
-pem_err.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-pem_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-pem_err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-pem_err.o: pem_err.c
+pem_err.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+pem_err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+pem_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+pem_err.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
+pem_err.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+pem_err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+pem_err.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+pem_err.o: ../../include/openssl/x509_vfy.h pem_err.c
 pem_info.o: ../../e_os.h ../../include/openssl/asn1.h
 pem_info.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 pem_info.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
 pem_info.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 pem_info.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 pem_info.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-pem_info.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-pem_info.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-pem_info.o: ../../include/openssl/opensslconf.h
+pem_info.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+pem_info.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 pem_info.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 pem_info.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
 pem_info.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
@@ -128,8 +125,8 @@ pem_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 pem_lib.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
 pem_lib.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
 pem_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
-pem_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-pem_lib.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
+pem_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
+pem_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
 pem_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
 pem_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 pem_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
@@ -139,43 +136,43 @@ pem_lib.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
 pem_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
 pem_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
 pem_lib.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
-pem_lib.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_lib.c
+pem_lib.o: ../../include/openssl/x509_vfy.h ../asn1/asn1_locl.h ../cryptlib.h
+pem_lib.o: pem_lib.c
 pem_oth.o: ../../e_os.h ../../include/openssl/asn1.h
 pem_oth.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 pem_oth.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 pem_oth.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 pem_oth.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-pem_oth.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-pem_oth.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-pem_oth.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-pem_oth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-pem_oth.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
-pem_oth.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
-pem_oth.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-pem_oth.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-pem_oth.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-pem_oth.o: ../cryptlib.h pem_oth.c
+pem_oth.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+pem_oth.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+pem_oth.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+pem_oth.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
+pem_oth.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
+pem_oth.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
+pem_oth.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+pem_oth.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+pem_oth.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_oth.c
 pem_pk8.o: ../../e_os.h ../../include/openssl/asn1.h
 pem_pk8.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 pem_pk8.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 pem_pk8.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 pem_pk8.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-pem_pk8.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-pem_pk8.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-pem_pk8.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-pem_pk8.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-pem_pk8.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
-pem_pk8.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
-pem_pk8.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
-pem_pk8.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-pem_pk8.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-pem_pk8.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_pk8.c
+pem_pk8.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+pem_pk8.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+pem_pk8.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+pem_pk8.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
+pem_pk8.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs12.h
+pem_pk8.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
+pem_pk8.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+pem_pk8.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+pem_pk8.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+pem_pk8.o: ../cryptlib.h pem_pk8.c
 pem_pkey.o: ../../e_os.h ../../include/openssl/asn1.h
 pem_pkey.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 pem_pkey.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 pem_pkey.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
-pem_pkey.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-pem_pkey.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
+pem_pkey.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
+pem_pkey.o: ../../include/openssl/err.h ../../include/openssl/evp.h
 pem_pkey.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
 pem_pkey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 pem_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
@@ -184,15 +181,16 @@ pem_pkey.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
 pem_pkey.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
 pem_pkey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
 pem_pkey.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-pem_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_pkey.c
+pem_pkey.o: ../../include/openssl/x509_vfy.h ../asn1/asn1_locl.h ../cryptlib.h
+pem_pkey.o: pem_pkey.c
 pem_seal.o: ../../e_os.h ../../include/openssl/asn1.h
 pem_seal.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 pem_seal.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 pem_seal.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 pem_seal.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-pem_seal.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-pem_seal.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-pem_seal.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+pem_seal.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+pem_seal.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+pem_seal.o: ../../include/openssl/opensslconf.h
 pem_seal.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 pem_seal.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
 pem_seal.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
@@ -205,9 +203,9 @@ pem_sign.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 pem_sign.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 pem_sign.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 pem_sign.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-pem_sign.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-pem_sign.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-pem_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+pem_sign.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+pem_sign.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+pem_sign.o: ../../include/openssl/opensslconf.h
 pem_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 pem_sign.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
 pem_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
@@ -220,9 +218,9 @@ pem_x509.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 pem_x509.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 pem_x509.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 pem_x509.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-pem_x509.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-pem_x509.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-pem_x509.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+pem_x509.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+pem_x509.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+pem_x509.o: ../../include/openssl/opensslconf.h
 pem_x509.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 pem_x509.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
 pem_x509.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
@@ -234,12 +232,27 @@ pem_xaux.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 pem_xaux.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 pem_xaux.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 pem_xaux.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-pem_xaux.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-pem_xaux.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-pem_xaux.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+pem_xaux.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+pem_xaux.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+pem_xaux.o: ../../include/openssl/opensslconf.h
 pem_xaux.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 pem_xaux.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
 pem_xaux.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 pem_xaux.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
 pem_xaux.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
 pem_xaux.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_xaux.c
+pvkfmt.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
+pvkfmt.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
+pvkfmt.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
+pvkfmt.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+pvkfmt.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
+pvkfmt.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+pvkfmt.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+pvkfmt.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+pvkfmt.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+pvkfmt.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
+pvkfmt.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
+pvkfmt.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+pvkfmt.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+pvkfmt.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+pvkfmt.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pvkfmt.c
index 6c193f1..8a6abab 100644 (file)
@@ -134,6 +134,7 @@ extern "C" {
 #define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY"
 #define PEM_STRING_ECPARAMETERS "EC PARAMETERS"
 #define PEM_STRING_ECPRIVATEKEY        "EC PRIVATE KEY"
+#define PEM_STRING_PARAMETERS  "PARAMETERS"
 #define PEM_STRING_CMS         "CMS"
 
   /* Note that this structure is initialised by PEM_SealInit and cleaned up
@@ -183,11 +184,8 @@ typedef struct pem_ctx_st
        int num_recipient;
        PEM_USER **recipient;
 
-#ifndef OPENSSL_NO_STACK
-       STACK *x509_chain;      /* certificate chain */
-#else
-       char *x509_chain;       /* certificate chain */
-#endif
+       /* XXX(ben): don#t think this is used! 
+               STACK *x509_chain;      / * certificate chain */
        EVP_MD *md;             /* signature type */
 
        int md_enc;             /* is the md encrypted or not? */
@@ -224,28 +222,19 @@ typedef struct pem_ctx_st
 #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \
 type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\
 { \
-    return (type*)PEM_ASN1_read(CHECKED_D2I_OF(type, d2i_##asn1), \
-                               str, fp, \
-                               CHECKED_PPTR_OF(type, x), \
-                               cb, u); \
+return PEM_ASN1_read((d2i_of_void *)d2i_##asn1, str,fp,(void **)x,cb,u); \
 } 
 
 #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \
 int PEM_write_##name(FILE *fp, type *x) \
 { \
-    return PEM_ASN1_write(CHECKED_I2D_OF(type, i2d_##asn1), \
-                         str, fp, \
-                         CHECKED_PTR_OF(type, x), \
-                         NULL, NULL, 0, NULL, NULL); \
+return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,NULL,NULL,0,NULL,NULL); \
 }
 
 #define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \
 int PEM_write_##name(FILE *fp, const type *x) \
 { \
-    return PEM_ASN1_write(CHECKED_I2D_OF(const type, i2d_##asn1), \
-                         str, fp, \
-                         CHECKED_PTR_OF(const type, x), \
-                         NULL, NULL, 0, NULL, NULL); \
+return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,(void *)x,NULL,NULL,0,NULL,NULL); \
 }
 
 #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \
@@ -253,10 +242,7 @@ int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
             unsigned char *kstr, int klen, pem_password_cb *cb, \
                  void *u) \
        { \
-           return PEM_ASN1_write(CHECKED_I2D_OF(type, i2d_##asn1), \
-                                 str, fp, \
-                                 CHECKED_PTR_OF(type, x), \
-                                 enc, kstr, klen, cb, u); \
+       return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \
        }
 
 #define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \
@@ -264,10 +250,7 @@ int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
             unsigned char *kstr, int klen, pem_password_cb *cb, \
                  void *u) \
        { \
-           return PEM_ASN1_write(CHECKED_I2D_OF(const type, i2d_##asn1), \
-                                 str, fp, \
-                                 CHECKED_PTR_OF(const type, x), \
-                                 enc, kstr, klen, cb, u); \
+       return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \
        }
 
 #endif
@@ -275,48 +258,33 @@ int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
 #define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
 type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\
 { \
-    return (type*)PEM_ASN1_read_bio(CHECKED_D2I_OF(type, d2i_##asn1), \
-                                   str, bp, \
-                                   CHECKED_PPTR_OF(type, x), \
-                                   cb, u); \
+return PEM_ASN1_read_bio((d2i_of_void *)d2i_##asn1, str,bp,(void **)x,cb,u); \
 }
 
 #define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
 int PEM_write_bio_##name(BIO *bp, type *x) \
 { \
-    return PEM_ASN1_write_bio(CHECKED_I2D_OF(type, i2d_##asn1), \
-                             str, bp, \
-                             CHECKED_PTR_OF(type, x), \
-                             NULL, NULL, 0, NULL, NULL); \
+return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,NULL,NULL,0,NULL,NULL); \
 }
 
 #define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
 int PEM_write_bio_##name(BIO *bp, const type *x) \
 { \
-    return PEM_ASN1_write_bio(CHECKED_I2D_OF(const type, i2d_##asn1), \
-                             str, bp, \
-                             CHECKED_PTR_OF(const type, x), \
-                             NULL, NULL, 0, NULL, NULL); \
+return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,NULL,NULL,0,NULL,NULL); \
 }
 
 #define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
 int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
             unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
        { \
-           return PEM_ASN1_write_bio(CHECKED_I2D_OF(type, i2d_##asn1), \
-                                     str, bp, \
-                                     CHECKED_PTR_OF(type, x), \
-                                     enc, kstr, klen, cb, u); \
+       return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,enc,kstr,klen,cb,u); \
        }
 
 #define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
 int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
             unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
        { \
-           return PEM_ASN1_write_bio(CHECKED_I2D_OF(const type, i2d_##asn1), \
-                                     str, bp, \
-                                     CHECKED_PTR_OF(const type, x), \
-                                     enc, kstr, klen, cb, u); \
+       return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,enc,kstr,klen,cb,u); \
        }
 
 #define IMPLEMENT_PEM_write(name, type, str, asn1) \
@@ -353,11 +321,10 @@ int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
 
 /* These are the same except they are for the declarations */
 
-#if defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_NO_FP_API)
+#if defined(OPENSSL_NO_FP_API)
 
 #define DECLARE_PEM_read_fp(name, type) /**/
 #define DECLARE_PEM_write_fp(name, type) /**/
-#define DECLARE_PEM_write_fp_const(name, type) /**/
 #define DECLARE_PEM_write_cb_fp(name, type) /**/
 
 #else
@@ -428,138 +395,6 @@ int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
        DECLARE_PEM_read(name, type) \
        DECLARE_PEM_write_cb(name, type)
 
-#ifdef SSLEAY_MACROS
-
-#define PEM_write_SSL_SESSION(fp,x) \
-               PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \
-                       PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL)
-#define PEM_write_X509(fp,x) \
-               PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \
-                       (char *)x, NULL,NULL,0,NULL,NULL)
-#define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \
-               (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \
-                       NULL,NULL,0,NULL,NULL)
-#define PEM_write_X509_CRL(fp,x) \
-               PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \
-                       fp,(char *)x, NULL,NULL,0,NULL,NULL)
-#define        PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \
-               PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\
-                       (char *)x,enc,kstr,klen,cb,u)
-#define        PEM_write_RSAPublicKey(fp,x) \
-               PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\
-                       PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL,NULL)
-#define        PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \
-               PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\
-                       (char *)x,enc,kstr,klen,cb,u)
-#define        PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb,u) \
-               PEM_ASN1_write((int (*)())i2d_PrivateKey,\
-               (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
-                       bp,(char *)x,enc,kstr,klen,cb,u)
-#define PEM_write_PKCS7(fp,x) \
-               PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \
-                       (char *)x, NULL,NULL,0,NULL,NULL)
-#define PEM_write_DHparams(fp,x) \
-               PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\
-                       (char *)x,NULL,NULL,0,NULL,NULL)
-
-#define PEM_write_NETSCAPE_CERT_SEQUENCE(fp,x) \
-                PEM_ASN1_write((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \
-                       PEM_STRING_X509,fp, \
-                        (char *)x, NULL,NULL,0,NULL,NULL)
-
-#define        PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \
-       (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u)
-#define        PEM_read_X509(fp,x,cb,u) (X509 *)PEM_ASN1_read( \
-       (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb,u)
-#define        PEM_read_X509_REQ(fp,x,cb,u) (X509_REQ *)PEM_ASN1_read( \
-       (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb,u)
-#define        PEM_read_X509_CRL(fp,x,cb,u) (X509_CRL *)PEM_ASN1_read( \
-       (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb,u)
-#define        PEM_read_RSAPrivateKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \
-       (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb,u)
-#define        PEM_read_RSAPublicKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \
-       (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb,u)
-#define        PEM_read_DSAPrivateKey(fp,x,cb,u) (DSA *)PEM_ASN1_read( \
-       (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb,u)
-#define        PEM_read_PrivateKey(fp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read( \
-       (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb,u)
-#define        PEM_read_PKCS7(fp,x,cb,u) (PKCS7 *)PEM_ASN1_read( \
-       (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb,u)
-#define        PEM_read_DHparams(fp,x,cb,u) (DH *)PEM_ASN1_read( \
-       (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb,u)
-
-#define PEM_read_NETSCAPE_CERT_SEQUENCE(fp,x,cb,u) \
-               (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read( \
-        (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,fp,\
-                                                       (char **)x,cb,u)
-
-#define PEM_write_bio_X509(bp,x) \
-               PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \
-                       (char *)x, NULL,NULL,0,NULL,NULL)
-#define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \
-               (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \
-                       NULL,NULL,0,NULL,NULL)
-#define PEM_write_bio_X509_CRL(bp,x) \
-               PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\
-                       bp,(char *)x, NULL,NULL,0,NULL,NULL)
-#define        PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
-               PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\
-                       bp,(char *)x,enc,kstr,klen,cb,u)
-#define        PEM_write_bio_RSAPublicKey(bp,x) \
-               PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \
-                       PEM_STRING_RSA_PUBLIC,\
-                       bp,(char *)x,NULL,NULL,0,NULL,NULL)
-#define        PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
-               PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\
-                       bp,(char *)x,enc,kstr,klen,cb,u)
-#define        PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb,u) \
-               PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\
-               (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
-                       bp,(char *)x,enc,kstr,klen,cb,u)
-#define PEM_write_bio_PKCS7(bp,x) \
-               PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \
-                       (char *)x, NULL,NULL,0,NULL,NULL)
-#define PEM_write_bio_DHparams(bp,x) \
-               PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\
-                       bp,(char *)x,NULL,NULL,0,NULL,NULL)
-#define PEM_write_bio_DSAparams(bp,x) \
-               PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \
-                       PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL,NULL)
-
-#define PEM_write_bio_NETSCAPE_CERT_SEQUENCE(bp,x) \
-                PEM_ASN1_write_bio((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \
-                       PEM_STRING_X509,bp, \
-                        (char *)x, NULL,NULL,0,NULL,NULL)
-
-#define        PEM_read_bio_X509(bp,x,cb,u) (X509 *)PEM_ASN1_read_bio( \
-       (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb,u)
-#define        PEM_read_bio_X509_REQ(bp,x,cb,u) (X509_REQ *)PEM_ASN1_read_bio( \
-       (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb,u)
-#define        PEM_read_bio_X509_CRL(bp,x,cb,u) (X509_CRL *)PEM_ASN1_read_bio( \
-       (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb,u)
-#define        PEM_read_bio_RSAPrivateKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \
-       (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb,u)
-#define        PEM_read_bio_RSAPublicKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \
-       (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb,u)
-#define        PEM_read_bio_DSAPrivateKey(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \
-       (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb,u)
-#define        PEM_read_bio_PrivateKey(bp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read_bio( \
-       (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb,u)
-
-#define        PEM_read_bio_PKCS7(bp,x,cb,u) (PKCS7 *)PEM_ASN1_read_bio( \
-       (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb,u)
-#define        PEM_read_bio_DHparams(bp,x,cb,u) (DH *)PEM_ASN1_read_bio( \
-       (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb,u)
-#define        PEM_read_bio_DSAparams(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \
-       (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb,u)
-
-#define PEM_read_bio_NETSCAPE_CERT_SEQUENCE(bp,x,cb,u) \
-               (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read_bio( \
-        (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,bp,\
-                                                       (char **)x,cb,u)
-
-#endif
-
 #if 1
 /* "userdata": new with OpenSSL 0.9.4 */
 typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata);
@@ -581,40 +416,25 @@ int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char
             pem_password_cb *cb, void *u);
 void * PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp,
                          void **x, pem_password_cb *cb, void *u);
-
-#define PEM_ASN1_read_bio_of(type,d2i,name,bp,x,cb,u) \
-    ((type*)PEM_ASN1_read_bio(CHECKED_D2I_OF(type, d2i), \
-                             name, bp,                 \
-                             CHECKED_PPTR_OF(type, x), \
-                             cb, u))
-
-int    PEM_ASN1_write_bio(i2d_of_void *i2d,const char *name,BIO *bp,char *x,
+int    PEM_ASN1_write_bio(i2d_of_void *i2d,const char *name,BIO *bp, void *x,
                           const EVP_CIPHER *enc,unsigned char *kstr,int klen,
                           pem_password_cb *cb, void *u);
 
-#define PEM_ASN1_write_bio_of(type,i2d,name,bp,x,enc,kstr,klen,cb,u) \
-    (PEM_ASN1_write_bio(CHECKED_I2D_OF(type, i2d), \
-                       name, bp,                  \
-                       CHECKED_PTR_OF(type, x), \
-                       enc, kstr, klen, cb, u))
-
 STACK_OF(X509_INFO) *  PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
 int    PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc,
                unsigned char *kstr, int klen, pem_password_cb *cd, void *u);
 #endif
 
-#ifndef OPENSSL_SYS_WIN16
 int    PEM_read(FILE *fp, char **name, char **header,
                unsigned char **data,long *len);
 int    PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len);
 void *  PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x,
                      pem_password_cb *cb, void *u);
 int    PEM_ASN1_write(i2d_of_void *i2d,const char *name,FILE *fp,
-                      char *x,const EVP_CIPHER *enc,unsigned char *kstr,
+                      void *x,const EVP_CIPHER *enc,unsigned char *kstr,
                       int klen,pem_password_cb *callback, void *u);
 STACK_OF(X509_INFO) *  PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk,
        pem_password_cb *cb, void *u);
-#endif
 
 int    PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type,
                EVP_MD *md_type, unsigned char **ek, int *ekl,
@@ -633,7 +453,6 @@ int PEM_def_callback(char *buf, int num, int w, void *key);
 void   PEM_proc_type(char *buf, int type);
 void   PEM_dek_info(char *buf, const char *type, int len, char *str);
 
-#ifndef SSLEAY_MACROS
 
 #include <openssl/symhacks.h>
 
@@ -719,7 +538,21 @@ EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, vo
 int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc,
                              char *kstr,int klen, pem_password_cb *cd, void *u);
 
-#endif /* SSLEAY_MACROS */
+EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x);
+int PEM_write_bio_Parameters(BIO *bp, EVP_PKEY *x);
+
+
+EVP_PKEY *b2i_PrivateKey(const unsigned char **in, long length);
+EVP_PKEY *b2i_PublicKey(const unsigned char **in, long length);
+EVP_PKEY *b2i_PrivateKey_bio(BIO *in);
+EVP_PKEY *b2i_PublicKey_bio(BIO *in);
+int i2b_PrivateKey_bio(BIO *out, EVP_PKEY *pk);
+int i2b_PublicKey_bio(BIO *out, EVP_PKEY *pk);
+#ifndef OPENSSL_NO_RC4
+EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u);
+int i2b_PVK_bio(BIO *out, EVP_PKEY *pk, int enclevel,
+               pem_password_cb *cb, void *u);
+#endif
 
 
 /* BEGIN ERROR CODES */
@@ -731,10 +564,22 @@ void ERR_load_PEM_strings(void);
 /* Error codes for the PEM functions. */
 
 /* Function codes. */
+#define PEM_F_B2I_DSS                                   127
+#define PEM_F_B2I_PVK_BIO                               128
+#define PEM_F_B2I_RSA                                   129
+#define PEM_F_CHECK_BITLEN_DSA                          130
+#define PEM_F_CHECK_BITLEN_RSA                          131
 #define PEM_F_D2I_PKCS8PRIVATEKEY_BIO                   120
 #define PEM_F_D2I_PKCS8PRIVATEKEY_FP                    121
+#define PEM_F_DO_B2I                                    132
+#define PEM_F_DO_B2I_BIO                                133
+#define PEM_F_DO_BLOB_HEADER                            134
 #define PEM_F_DO_PK8PKEY                                126
 #define PEM_F_DO_PK8PKEY_FP                             125
+#define PEM_F_DO_PVK_BODY                               135
+#define PEM_F_DO_PVK_HEADER                             136
+#define PEM_F_I2B_PVK                                   137
+#define PEM_F_I2B_PVK_BIO                               138
 #define PEM_F_LOAD_IV                                   101
 #define PEM_F_PEM_ASN1_READ                             102
 #define PEM_F_PEM_ASN1_READ_BIO                                 103
@@ -747,6 +592,7 @@ void ERR_load_PEM_strings(void);
 #define PEM_F_PEM_PK8PKEY                               119
 #define PEM_F_PEM_READ                                  108
 #define PEM_F_PEM_READ_BIO                              109
+#define PEM_F_PEM_READ_BIO_PARAMETERS                   140
 #define PEM_F_PEM_READ_BIO_PRIVATEKEY                   123
 #define PEM_F_PEM_READ_PRIVATEKEY                       124
 #define PEM_F_PEM_SEALFINAL                             110
@@ -754,6 +600,7 @@ void ERR_load_PEM_strings(void);
 #define PEM_F_PEM_SIGNFINAL                             112
 #define PEM_F_PEM_WRITE                                         113
 #define PEM_F_PEM_WRITE_BIO                             114
+#define PEM_F_PEM_WRITE_PRIVATEKEY                      139
 #define PEM_F_PEM_X509_INFO_READ                        115
 #define PEM_F_PEM_X509_INFO_READ_BIO                    116
 #define PEM_F_PEM_X509_INFO_WRITE_BIO                   117
@@ -763,18 +610,30 @@ void ERR_load_PEM_strings(void);
 #define PEM_R_BAD_DECRYPT                               101
 #define PEM_R_BAD_END_LINE                              102
 #define PEM_R_BAD_IV_CHARS                              103
+#define PEM_R_BAD_MAGIC_NUMBER                          116
 #define PEM_R_BAD_PASSWORD_READ                                 104
+#define PEM_R_BAD_VERSION_NUMBER                        117
+#define PEM_R_BIO_WRITE_FAILURE                                 118
+#define PEM_R_CIPHER_IS_NULL                            127
 #define PEM_R_ERROR_CONVERTING_PRIVATE_KEY              115
+#define PEM_R_EXPECTING_PRIVATE_KEY_BLOB                119
+#define PEM_R_EXPECTING_PUBLIC_KEY_BLOB                         120
+#define PEM_R_INCONSISTENT_HEADER                       121
+#define PEM_R_KEYBLOB_HEADER_PARSE_ERROR                122
+#define PEM_R_KEYBLOB_TOO_SHORT                                 123
 #define PEM_R_NOT_DEK_INFO                              105
 #define PEM_R_NOT_ENCRYPTED                             106
 #define PEM_R_NOT_PROC_TYPE                             107
 #define PEM_R_NO_START_LINE                             108
 #define PEM_R_PROBLEMS_GETTING_PASSWORD                         109
 #define PEM_R_PUBLIC_KEY_NO_RSA                                 110
+#define PEM_R_PVK_DATA_TOO_SHORT                        124
+#define PEM_R_PVK_TOO_SHORT                             125
 #define PEM_R_READ_KEY                                  111
 #define PEM_R_SHORT_HEADER                              112
 #define PEM_R_UNSUPPORTED_CIPHER                        113
 #define PEM_R_UNSUPPORTED_ENCRYPTION                    114
+#define PEM_R_UNSUPPORTED_KEY_COMPONENTS                126
 
 #ifdef  __cplusplus
 }
index 69dd19b..3e7a609 100644 (file)
  */
 
 #include <stdio.h>
-#undef SSLEAY_MACROS
 #include "cryptlib.h"
 #include <openssl/bio.h>
 #include <openssl/evp.h>
@@ -194,49 +193,7 @@ RSA *PEM_read_RSAPrivateKey(FILE *fp, RSA **rsa, pem_password_cb *cb,
 
 #endif
 
-#ifdef OPENSSL_FIPS
-
-int PEM_write_bio_RSAPrivateKey(BIO *bp, RSA *x, const EVP_CIPHER *enc,
-                                               unsigned char *kstr, int klen,
-                                               pem_password_cb *cb, void *u)
-{
-       EVP_PKEY *k;
-       int ret;
-       k = EVP_PKEY_new();
-       if (!k)
-               return 0;
-       EVP_PKEY_set1_RSA(k, x);
-
-       ret = PEM_write_bio_PrivateKey(bp, k, enc, kstr, klen, cb, u);
-       EVP_PKEY_free(k);
-       return ret;
-}
-
-#ifndef OPENSSL_NO_FP_API
-int PEM_write_RSAPrivateKey(FILE *fp, RSA *x, const EVP_CIPHER *enc,
-                                               unsigned char *kstr, int klen,
-                                               pem_password_cb *cb, void *u)
-{
-       EVP_PKEY *k;
-       int ret;
-       k = EVP_PKEY_new();
-       if (!k)
-               return 0;
-
-       EVP_PKEY_set1_RSA(k, x);
-
-       ret = PEM_write_PrivateKey(fp, k, enc, kstr, klen, cb, u);
-       EVP_PKEY_free(k);
-       return ret;
-}
-#endif
-
-#else
-
 IMPLEMENT_PEM_write_cb_const(RSAPrivateKey, RSA, PEM_STRING_RSA, RSAPrivateKey)
-
-#endif
-
 IMPLEMENT_PEM_rw_const(RSAPublicKey, RSA, PEM_STRING_RSA_PUBLIC, RSAPublicKey)
 IMPLEMENT_PEM_rw(RSA_PUBKEY, RSA, PEM_STRING_PUBLIC, RSA_PUBKEY)
 
@@ -263,50 +220,10 @@ DSA *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **dsa, pem_password_cb *cb,
 {
        EVP_PKEY *pktmp;
        pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);
-       return pkey_get_dsa(pktmp, dsa);
+       return pkey_get_dsa(pktmp, dsa);        /* will free pktmp */
 }
 
-#ifdef OPENSSL_FIPS
-
-int PEM_write_bio_DSAPrivateKey(BIO *bp, DSA *x, const EVP_CIPHER *enc,
-                                               unsigned char *kstr, int klen,
-                                               pem_password_cb *cb, void *u)
-{
-       EVP_PKEY *k;
-       int ret;
-       k = EVP_PKEY_new();
-       if (!k)
-               return 0;
-       EVP_PKEY_set1_DSA(k, x);
-
-       ret = PEM_write_bio_PrivateKey(bp, k, enc, kstr, klen, cb, u);
-       EVP_PKEY_free(k);
-       return ret;
-}
-
-#ifndef OPENSSL_NO_FP_API
-int PEM_write_DSAPrivateKey(FILE *fp, DSA *x, const EVP_CIPHER *enc,
-                                               unsigned char *kstr, int klen,
-                                               pem_password_cb *cb, void *u)
-{
-       EVP_PKEY *k;
-       int ret;
-       k = EVP_PKEY_new();
-       if (!k)
-               return 0;
-       EVP_PKEY_set1_DSA(k, x);
-       ret = PEM_write_PrivateKey(fp, k, enc, kstr, klen, cb, u);
-       EVP_PKEY_free(k);
-       return ret;
-}
-#endif
-
-#else
-
 IMPLEMENT_PEM_write_cb_const(DSAPrivateKey, DSA, PEM_STRING_DSA, DSAPrivateKey)
-
-#endif
-
 IMPLEMENT_PEM_rw(DSA_PUBKEY, DSA, PEM_STRING_PUBLIC, DSA_PUBKEY)
 
 #ifndef OPENSSL_NO_FP_API
@@ -316,7 +233,7 @@ DSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **dsa, pem_password_cb *cb,
 {
        EVP_PKEY *pktmp;
        pktmp = PEM_read_PrivateKey(fp, NULL, cb, u);
-       return pkey_get_dsa(pktmp, dsa);
+       return pkey_get_dsa(pktmp, dsa);        /* will free pktmp */
 }
 
 #endif
@@ -347,54 +264,13 @@ EC_KEY *PEM_read_bio_ECPrivateKey(BIO *bp, EC_KEY **key, pem_password_cb *cb,
 {
        EVP_PKEY *pktmp;
        pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);
-       return pkey_get_eckey(pktmp, key);
+       return pkey_get_eckey(pktmp, key);      /* will free pktmp */
 }
 
 IMPLEMENT_PEM_rw_const(ECPKParameters, EC_GROUP, PEM_STRING_ECPARAMETERS, ECPKParameters)
 
-
-
-#ifdef OPENSSL_FIPS
-
-int PEM_write_bio_ECPrivateKey(BIO *bp, EC_KEY *x, const EVP_CIPHER *enc,
-                                               unsigned char *kstr, int klen,
-                                               pem_password_cb *cb, void *u)
-{
-       EVP_PKEY *k;
-       int ret;
-       k = EVP_PKEY_new();
-       if (!k)
-               return 0;
-       EVP_PKEY_set1_EC_KEY(k, x);
-
-       ret = PEM_write_bio_PrivateKey(bp, k, enc, kstr, klen, cb, u);
-       EVP_PKEY_free(k);
-       return ret;
-}
-
-#ifndef OPENSSL_NO_FP_API
-int PEM_write_ECPrivateKey(FILE *fp, EC_KEY *x, const EVP_CIPHER *enc,
-                                               unsigned char *kstr, int klen,
-                                               pem_password_cb *cb, void *u)
-{
-       EVP_PKEY *k;
-       int ret;
-       k = EVP_PKEY_new();
-       if (!k)
-               return 0;
-       EVP_PKEY_set1_EC_KEY(k, x);
-       ret = PEM_write_PrivateKey(fp, k, enc, kstr, klen, cb, u);
-       EVP_PKEY_free(k);
-       return ret;
-}
-#endif
-
-#else
-
 IMPLEMENT_PEM_write_cb(ECPrivateKey, EC_KEY, PEM_STRING_ECPRIVATEKEY, ECPrivateKey)
 
-#endif
-
 IMPLEMENT_PEM_rw(EC_PUBKEY, EC_KEY, PEM_STRING_PUBLIC, EC_PUBKEY)
 
 #ifndef OPENSSL_NO_FP_API
@@ -404,7 +280,7 @@ EC_KEY *PEM_read_ECPrivateKey(FILE *fp, EC_KEY **eckey, pem_password_cb *cb,
 {
        EVP_PKEY *pktmp;
        pktmp = PEM_read_PrivateKey(fp, NULL, cb, u);
-       return pkey_get_eckey(pktmp, eckey);
+       return pkey_get_eckey(pktmp, eckey);    /* will free pktmp */
 }
 
 #endif
@@ -417,66 +293,4 @@ IMPLEMENT_PEM_rw_const(DHparams, DH, PEM_STRING_DHPARAMS, DHparams)
 
 #endif
 
-
-/* The PrivateKey case is not that straightforward.
- *   IMPLEMENT_PEM_rw_cb(PrivateKey, EVP_PKEY, PEM_STRING_EVP_PKEY, PrivateKey)
- * does not work, RSA and DSA keys have specific strings.
- * (When reading, parameter PEM_STRING_EVP_PKEY is a wildcard for anything
- * appropriate.)
- */
-
-#ifdef OPENSSL_FIPS
-
-static const char *pkey_str(EVP_PKEY *x)
-       {
-       switch (x->type)
-               {
-               case EVP_PKEY_RSA:
-               return PEM_STRING_RSA;
-
-               case EVP_PKEY_DSA:
-               return PEM_STRING_DSA;
-
-               case EVP_PKEY_EC:
-               return PEM_STRING_ECPRIVATEKEY;
-
-               default:
-               return NULL;
-               }
-       }
-
-
-int PEM_write_bio_PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
-                                               unsigned char *kstr, int klen,
-                                               pem_password_cb *cb, void *u)
-       {
-               if (FIPS_mode())
-                       return PEM_write_bio_PKCS8PrivateKey(bp, x, enc,
-                                               (char *)kstr, klen, cb, u);
-               else
-                       return PEM_ASN1_write_bio((i2d_of_void *)i2d_PrivateKey,
-                       pkey_str(x), bp,(char *)x,enc,kstr,klen,cb,u);
-       }
-
-#ifndef OPENSSL_NO_FP_API
-int PEM_write_PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
-                                               unsigned char *kstr, int klen,
-                                               pem_password_cb *cb, void *u)
-       {
-               if (FIPS_mode())
-                       return PEM_write_PKCS8PrivateKey(fp, x, enc,
-                                               (char *)kstr, klen, cb, u);
-               else
-                       return PEM_ASN1_write((i2d_of_void *)i2d_PrivateKey,
-                       pkey_str(x), fp,(char *)x,enc,kstr,klen,cb,u);
-       }
-#endif
-
-#else
-IMPLEMENT_PEM_write_cb(PrivateKey, EVP_PKEY, ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:\
-                       (x->type == EVP_PKEY_RSA)?PEM_STRING_RSA:PEM_STRING_ECPRIVATEKEY), PrivateKey)
-
-#endif
-
 IMPLEMENT_PEM_rw(PUBKEY, EVP_PKEY, PEM_STRING_PUBLIC, PUBKEY)
-
index 3133563..d644aee 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/pem/pem_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2007 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 static ERR_STRING_DATA PEM_str_functs[]=
        {
+{ERR_FUNC(PEM_F_B2I_DSS),      "B2I_DSS"},
+{ERR_FUNC(PEM_F_B2I_PVK_BIO),  "b2i_PVK_bio"},
+{ERR_FUNC(PEM_F_B2I_RSA),      "B2I_RSA"},
+{ERR_FUNC(PEM_F_CHECK_BITLEN_DSA),     "CHECK_BITLEN_DSA"},
+{ERR_FUNC(PEM_F_CHECK_BITLEN_RSA),     "CHECK_BITLEN_RSA"},
 {ERR_FUNC(PEM_F_D2I_PKCS8PRIVATEKEY_BIO),      "d2i_PKCS8PrivateKey_bio"},
 {ERR_FUNC(PEM_F_D2I_PKCS8PRIVATEKEY_FP),       "d2i_PKCS8PrivateKey_fp"},
+{ERR_FUNC(PEM_F_DO_B2I),       "DO_B2I"},
+{ERR_FUNC(PEM_F_DO_B2I_BIO),   "DO_B2I_BIO"},
+{ERR_FUNC(PEM_F_DO_BLOB_HEADER),       "DO_BLOB_HEADER"},
 {ERR_FUNC(PEM_F_DO_PK8PKEY),   "DO_PK8PKEY"},
 {ERR_FUNC(PEM_F_DO_PK8PKEY_FP),        "DO_PK8PKEY_FP"},
+{ERR_FUNC(PEM_F_DO_PVK_BODY),  "DO_PVK_BODY"},
+{ERR_FUNC(PEM_F_DO_PVK_HEADER),        "DO_PVK_HEADER"},
+{ERR_FUNC(PEM_F_I2B_PVK),      "I2B_PVK"},
+{ERR_FUNC(PEM_F_I2B_PVK_BIO),  "i2b_PVK_bio"},
 {ERR_FUNC(PEM_F_LOAD_IV),      "LOAD_IV"},
 {ERR_FUNC(PEM_F_PEM_ASN1_READ),        "PEM_ASN1_read"},
 {ERR_FUNC(PEM_F_PEM_ASN1_READ_BIO),    "PEM_ASN1_read_bio"},
@@ -86,6 +98,7 @@ static ERR_STRING_DATA PEM_str_functs[]=
 {ERR_FUNC(PEM_F_PEM_PK8PKEY),  "PEM_PK8PKEY"},
 {ERR_FUNC(PEM_F_PEM_READ),     "PEM_read"},
 {ERR_FUNC(PEM_F_PEM_READ_BIO), "PEM_read_bio"},
+{ERR_FUNC(PEM_F_PEM_READ_BIO_PARAMETERS),      "PEM_read_bio_Parameters"},
 {ERR_FUNC(PEM_F_PEM_READ_BIO_PRIVATEKEY),      "PEM_READ_BIO_PRIVATEKEY"},
 {ERR_FUNC(PEM_F_PEM_READ_PRIVATEKEY),  "PEM_READ_PRIVATEKEY"},
 {ERR_FUNC(PEM_F_PEM_SEALFINAL),        "PEM_SealFinal"},
@@ -93,6 +106,7 @@ static ERR_STRING_DATA PEM_str_functs[]=
 {ERR_FUNC(PEM_F_PEM_SIGNFINAL),        "PEM_SignFinal"},
 {ERR_FUNC(PEM_F_PEM_WRITE),    "PEM_write"},
 {ERR_FUNC(PEM_F_PEM_WRITE_BIO),        "PEM_write_bio"},
+{ERR_FUNC(PEM_F_PEM_WRITE_PRIVATEKEY), "PEM_WRITE_PRIVATEKEY"},
 {ERR_FUNC(PEM_F_PEM_X509_INFO_READ),   "PEM_X509_INFO_read"},
 {ERR_FUNC(PEM_F_PEM_X509_INFO_READ_BIO),       "PEM_X509_INFO_read_bio"},
 {ERR_FUNC(PEM_F_PEM_X509_INFO_WRITE_BIO),      "PEM_X509_INFO_write_bio"},
@@ -105,18 +119,30 @@ static ERR_STRING_DATA PEM_str_reasons[]=
 {ERR_REASON(PEM_R_BAD_DECRYPT)           ,"bad decrypt"},
 {ERR_REASON(PEM_R_BAD_END_LINE)          ,"bad end line"},
 {ERR_REASON(PEM_R_BAD_IV_CHARS)          ,"bad iv chars"},
+{ERR_REASON(PEM_R_BAD_MAGIC_NUMBER)      ,"bad magic number"},
 {ERR_REASON(PEM_R_BAD_PASSWORD_READ)     ,"bad password read"},
+{ERR_REASON(PEM_R_BAD_VERSION_NUMBER)    ,"bad version number"},
+{ERR_REASON(PEM_R_BIO_WRITE_FAILURE)     ,"bio write failure"},
+{ERR_REASON(PEM_R_CIPHER_IS_NULL)        ,"cipher is null"},
 {ERR_REASON(PEM_R_ERROR_CONVERTING_PRIVATE_KEY),"error converting private key"},
+{ERR_REASON(PEM_R_EXPECTING_PRIVATE_KEY_BLOB),"expecting private key blob"},
+{ERR_REASON(PEM_R_EXPECTING_PUBLIC_KEY_BLOB),"expecting public key blob"},
+{ERR_REASON(PEM_R_INCONSISTENT_HEADER)   ,"inconsistent header"},
+{ERR_REASON(PEM_R_KEYBLOB_HEADER_PARSE_ERROR),"keyblob header parse error"},
+{ERR_REASON(PEM_R_KEYBLOB_TOO_SHORT)     ,"keyblob too short"},
 {ERR_REASON(PEM_R_NOT_DEK_INFO)          ,"not dek info"},
 {ERR_REASON(PEM_R_NOT_ENCRYPTED)         ,"not encrypted"},
 {ERR_REASON(PEM_R_NOT_PROC_TYPE)         ,"not proc type"},
 {ERR_REASON(PEM_R_NO_START_LINE)         ,"no start line"},
 {ERR_REASON(PEM_R_PROBLEMS_GETTING_PASSWORD),"problems getting password"},
 {ERR_REASON(PEM_R_PUBLIC_KEY_NO_RSA)     ,"public key no rsa"},
+{ERR_REASON(PEM_R_PVK_DATA_TOO_SHORT)    ,"pvk data too short"},
+{ERR_REASON(PEM_R_PVK_TOO_SHORT)         ,"pvk too short"},
 {ERR_REASON(PEM_R_READ_KEY)              ,"read key"},
 {ERR_REASON(PEM_R_SHORT_HEADER)          ,"short header"},
 {ERR_REASON(PEM_R_UNSUPPORTED_CIPHER)    ,"unsupported cipher"},
 {ERR_REASON(PEM_R_UNSUPPORTED_ENCRYPTION),"unsupported encryption"},
+{ERR_REASON(PEM_R_UNSUPPORTED_KEY_COMPONENTS),"unsupported key components"},
 {0,NULL}
        };
 
index 3a273f6..1b2be52 100644 (file)
@@ -98,8 +98,8 @@ STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pe
        long len,error=0;
        int ok=0;
        STACK_OF(X509_INFO) *ret=NULL;
-       unsigned int i,raw;
-       d2i_of_void *d2i;
+       unsigned int i,raw,ptype;
+       d2i_of_void *d2i = 0;
 
        if (sk == NULL)
                {
@@ -116,6 +116,7 @@ STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pe
        for (;;)
                {
                raw=0;
+               ptype = 0;
                i=PEM_read_bio(bp,&name,&header,&data,&len);
                if (i == 0)
                        {
@@ -166,7 +167,6 @@ start:
 #ifndef OPENSSL_NO_RSA
                        if (strcmp(name,PEM_STRING_RSA) == 0)
                        {
-                       d2i=(D2I_OF(void))d2i_RSAPrivateKey;
                        if (xi->x_pkey != NULL) 
                                {
                                if (!sk_X509_INFO_push(ret,xi)) goto err;
@@ -178,10 +178,8 @@ start:
                        xi->enc_len=0;
 
                        xi->x_pkey=X509_PKEY_new();
-                       if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL)
-                               goto err;
-                       xi->x_pkey->dec_pkey->type=EVP_PKEY_RSA;
-                       pp=&(xi->x_pkey->dec_pkey->pkey.rsa);
+                       ptype=EVP_PKEY_RSA;
+                       pp=&xi->x_pkey->dec_pkey;
                        if ((int)strlen(header) > 10) /* assume encrypted */
                                raw=1;
                        }
@@ -202,10 +200,8 @@ start:
                        xi->enc_len=0;
 
                        xi->x_pkey=X509_PKEY_new();
-                       if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL)
-                               goto err;
-                       xi->x_pkey->dec_pkey->type=EVP_PKEY_DSA;
-                       pp=&xi->x_pkey->dec_pkey->pkey.dsa;
+                       ptype = EVP_PKEY_DSA;
+                       pp=&xi->x_pkey->dec_pkey;
                        if ((int)strlen(header) > 10) /* assume encrypted */
                                raw=1;
                        }
@@ -226,10 +222,8 @@ start:
                        xi->enc_len=0;
  
                        xi->x_pkey=X509_PKEY_new();
-                       if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL)
-                               goto err;
-                       xi->x_pkey->dec_pkey->type=EVP_PKEY_EC;
-                       pp=&(xi->x_pkey->dec_pkey->pkey.ec);
+                       ptype = EVP_PKEY_EC;
+                       pp=&xi->x_pkey->dec_pkey;
                        if ((int)strlen(header) > 10) /* assume encrypted */
                                raw=1;
                        }
@@ -251,7 +245,15 @@ start:
                                if (!PEM_do_header(&cipher,data,&len,cb,u))
                                        goto err;
                                p=data;
-                               if (d2i(pp,&p,len) == NULL)
+                               if (ptype)
+                                       {
+                                       if (!d2i_PrivateKey(ptype, pp, &p, len))
+                                               {
+                                               PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_ASN1_LIB);
+                                               goto err;
+                                               }
+                                       }
+                               else if (d2i(pp,&p,len) == NULL)
                                        {
                                        PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_ASN1_LIB);
                                        goto err;
@@ -337,6 +339,12 @@ int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc,
                {
                if ( (xi->enc_data!=NULL) && (xi->enc_len>0) )
                        {
+                       if (enc == NULL)
+                               {
+                               PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_CIPHER_IS_NULL);
+                               goto err;
+                               }
+
                        /* copy from weirdo names into more normal things */
                        iv=xi->enc_cipher.iv;
                        data=(unsigned char *)xi->enc_data;
index 22bb791..cfc89a9 100644 (file)
@@ -57,6 +57,7 @@
  */
 
 #include <stdio.h>
+#include <ctype.h>
 #include "cryptlib.h"
 #include <openssl/buffer.h>
 #include <openssl/objects.h>
 #include <openssl/x509.h>
 #include <openssl/pem.h>
 #include <openssl/pkcs12.h>
+#include "asn1_locl.h"
 #ifndef OPENSSL_NO_DES
 #include <openssl/des.h>
 #endif
+#ifndef OPENSSL_NO_ENGINE
+#include <openssl/engine.h>
+#endif
 
 const char PEM_version[]="PEM" OPENSSL_VERSION_PTEXT;
 
@@ -75,6 +80,7 @@ const char PEM_version[]="PEM" OPENSSL_VERSION_PTEXT;
 
 static int load_iv(char **fromp,unsigned char *to, int num);
 static int check_pem(const char *nm, const char *name);
+int pem_check_suffix(const char *pem_str, const char *suffix);
 
 int PEM_def_callback(char *buf, int num, int w, void *key)
        {
@@ -99,7 +105,7 @@ int PEM_def_callback(char *buf, int num, int w, void *key)
 
        for (;;)
                {
-               i=EVP_read_pw_string(buf,num,prompt,w);
+               i=EVP_read_pw_string_min(buf,MIN_LENGTH,num,prompt,w);
                if (i != 0)
                        {
                        PEMerr(PEM_F_PEM_DEF_CALLBACK,PEM_R_PROBLEMS_GETTING_PASSWORD);
@@ -183,20 +189,54 @@ static int check_pem(const char *nm, const char *name)
 
        /* Make PEM_STRING_EVP_PKEY match any private key */
 
-       if(!strcmp(nm,PEM_STRING_PKCS8) &&
-               !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
-
-       if(!strcmp(nm,PEM_STRING_PKCS8INF) &&
-                !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
-
-       if(!strcmp(nm,PEM_STRING_RSA) &&
-               !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
+       if(!strcmp(name,PEM_STRING_EVP_PKEY))
+               {
+               int slen;
+               const EVP_PKEY_ASN1_METHOD *ameth;
+               if(!strcmp(nm,PEM_STRING_PKCS8))
+                       return 1;
+               if(!strcmp(nm,PEM_STRING_PKCS8INF))
+                       return 1;
+               slen = pem_check_suffix(nm, "PRIVATE KEY"); 
+               if (slen > 0)
+                       {
+                       /* NB: ENGINE implementations wont contain
+                        * a deprecated old private key decode function
+                        * so don't look for them.
+                        */
+                       ameth = EVP_PKEY_asn1_find_str(NULL, nm, slen);
+                       if (ameth && ameth->old_priv_decode)
+                               return 1;
+                       }
+               return 0;
+               }
 
-       if(!strcmp(nm,PEM_STRING_DSA) &&
-                !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
+       if(!strcmp(name,PEM_STRING_PARAMETERS))
+               {
+               int slen;
+               const EVP_PKEY_ASN1_METHOD *ameth;
+               slen = pem_check_suffix(nm, "PARAMETERS"); 
+               if (slen > 0)
+                       {
+                       ENGINE *e;
+                       ameth = EVP_PKEY_asn1_find_str(&e, nm, slen);
+                       if (ameth)
+                               {
+                               int r;
+                               if (ameth->param_decode)
+                                       r = 1;
+                               else
+                                       r = 0;
+#ifndef OPENSSL_NO_ENGINE
+                               if (e)
+                                       ENGINE_finish(e);
+#endif
+                               return r;
+                               }
+                       }
+               return 0;
+               }
 
-       if(!strcmp(nm,PEM_STRING_ECPRIVATEKEY) &&
-                !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
        /* Permit older strings */
 
        if(!strcmp(nm,PEM_STRING_X509_OLD) &&
@@ -219,6 +259,14 @@ static int check_pem(const char *nm, const char *name)
        if(!strcmp(nm, PEM_STRING_PKCS7_SIGNED) &&
                !strcmp(name, PEM_STRING_PKCS7)) return 1;
 
+#ifndef OPENSSL_NO_CMS
+       if(!strcmp(nm, PEM_STRING_X509) &&
+               !strcmp(name, PEM_STRING_CMS)) return 1;
+       /* Allow CMS to be read from PKCS#7 headers */
+       if(!strcmp(nm, PEM_STRING_PKCS7) &&
+               !strcmp(name, PEM_STRING_CMS)) return 1;
+#endif
+
        return 0;
 }
 
@@ -264,7 +312,7 @@ err:
 
 #ifndef OPENSSL_NO_FP_API
 int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp,
-                  char *x, const EVP_CIPHER *enc, unsigned char *kstr,
+                  void *x, const EVP_CIPHER *enc, unsigned char *kstr,
                   int klen, pem_password_cb *callback, void *u)
         {
         BIO *b;
@@ -283,7 +331,7 @@ int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp,
 #endif
 
 int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp,
-                      char *x, const EVP_CIPHER *enc, unsigned char *kstr,
+                      void *x, const EVP_CIPHER *enc, unsigned char *kstr,
                       int klen, pem_password_cb *callback, void *u)
        {
        EVP_CIPHER_CTX ctx;
@@ -780,3 +828,25 @@ err:
        BUF_MEM_free(dataB);
        return(0);
        }
+
+/* Check pem string and return prefix length.
+ * If for example the pem_str == "RSA PRIVATE KEY" and suffix = "PRIVATE KEY"
+ * the return value is 3 for the string "RSA".
+ */
+
+int pem_check_suffix(const char *pem_str, const char *suffix)
+       {
+       int pem_len = strlen(pem_str);
+       int suffix_len = strlen(suffix);
+       const char *p;
+       if (suffix_len + 1 >= pem_len)
+               return 0;
+       p = pem_str + pem_len - suffix_len;
+       if (strcmp(p, suffix))
+               return 0;
+       p--;
+       if (*p != ' ')
+               return 0;
+       return p - pem_str;
+       }
+
index 4da4c31..8ecf249 100644 (file)
 #include <openssl/x509.h>
 #include <openssl/pkcs12.h>
 #include <openssl/pem.h>
+#ifndef OPENSSL_NO_ENGINE
+#include <openssl/engine.h>
+#endif
+#include "asn1_locl.h"
 
+int pem_check_suffix(const char *pem_str, const char *suffix);
 
 EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u)
        {
@@ -73,19 +78,14 @@ EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, vo
        const unsigned char *p=NULL;
        unsigned char *data=NULL;
        long len;
+       int slen;
        EVP_PKEY *ret=NULL;
 
        if (!PEM_bytes_read_bio(&data, &len, &nm, PEM_STRING_EVP_PKEY, bp, cb, u))
                return NULL;
        p = data;
 
-       if (strcmp(nm,PEM_STRING_RSA) == 0)
-               ret=d2i_PrivateKey(EVP_PKEY_RSA,x,&p,len);
-       else if (strcmp(nm,PEM_STRING_DSA) == 0)
-               ret=d2i_PrivateKey(EVP_PKEY_DSA,x,&p,len);
-       else if (strcmp(nm,PEM_STRING_ECPRIVATEKEY) == 0)
-               ret=d2i_PrivateKey(EVP_PKEY_EC,x,&p,len);
-       else if (strcmp(nm,PEM_STRING_PKCS8INF) == 0) {
+       if (strcmp(nm,PEM_STRING_PKCS8INF) == 0) {
                PKCS8_PRIV_KEY_INFO *p8inf;
                p8inf=d2i_PKCS8_PRIV_KEY_INFO(NULL, &p, len);
                if(!p8inf) goto p8err;
@@ -119,7 +119,14 @@ EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, vo
                        *x = ret;
                }
                PKCS8_PRIV_KEY_INFO_free(p8inf);
-       }
+       } else if ((slen = pem_check_suffix(nm, "PRIVATE KEY")) > 0)
+               {
+               const EVP_PKEY_ASN1_METHOD *ameth;
+               ameth = EVP_PKEY_asn1_find_str(NULL, nm, slen);
+               if (!ameth || !ameth->old_priv_decode)
+                       goto p8err;
+               ret=d2i_PrivateKey(ameth->pkey_id,x,&p,len);
+               }
 p8err:
        if (ret == NULL)
                PEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY,ERR_R_ASN1_LIB);
@@ -130,6 +137,74 @@ err:
        return(ret);
        }
 
+int PEM_write_bio_PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
+                                               unsigned char *kstr, int klen,
+                                               pem_password_cb *cb, void *u)
+       {
+       char pem_str[80];
+       if (!x->ameth || x->ameth->priv_encode)
+               return PEM_write_bio_PKCS8PrivateKey(bp, x, enc,
+                                                       (char *)kstr, klen,
+                                                       cb, u);
+
+       BIO_snprintf(pem_str, 80, "%s PRIVATE KEY", x->ameth->pem_str);
+       return PEM_ASN1_write_bio((i2d_of_void *)i2d_PrivateKey,
+                               pem_str,bp,x,enc,kstr,klen,cb,u);
+       }
+
+EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x)
+       {
+       char *nm=NULL;
+       const unsigned char *p=NULL;
+       unsigned char *data=NULL;
+       long len;
+       int slen;
+       EVP_PKEY *ret=NULL;
+
+       if (!PEM_bytes_read_bio(&data, &len, &nm, PEM_STRING_PARAMETERS,
+                                                               bp, 0, NULL))
+               return NULL;
+       p = data;
+
+       if ((slen = pem_check_suffix(nm, "PARAMETERS")) > 0)
+               {
+               ret = EVP_PKEY_new();
+               if (!ret)
+                       goto err;
+               if (!EVP_PKEY_set_type_str(ret, nm, slen)
+                       || !ret->ameth->param_decode
+                       || !ret->ameth->param_decode(ret, &p, len))
+                       {
+                       EVP_PKEY_free(ret);
+                       ret = NULL;
+                       goto err;
+                       }
+               if(x)
+                       {
+                       if(*x) EVP_PKEY_free((EVP_PKEY *)*x);
+                       *x = ret;
+                       }
+               }
+err:
+       if (ret == NULL)
+               PEMerr(PEM_F_PEM_READ_BIO_PARAMETERS,ERR_R_ASN1_LIB);
+       OPENSSL_free(nm);
+       OPENSSL_free(data);
+       return(ret);
+       }
+
+int PEM_write_bio_Parameters(BIO *bp, EVP_PKEY *x)
+       {
+       char pem_str[80];
+       if (!x->ameth || !x->ameth->param_encode)
+               return 0;
+
+       BIO_snprintf(pem_str, 80, "%s PARAMETERS", x->ameth->pem_str);
+       return PEM_ASN1_write_bio(
+               (i2d_of_void *)x->ameth->param_encode,
+                               pem_str,bp,x,NULL,NULL,0,0,NULL);
+       }
+
 #ifndef OPENSSL_NO_FP_API
 EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u)
        {
@@ -146,4 +221,22 @@ EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void
         BIO_free(b);
         return(ret);
        }
+
+int PEM_write_PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
+                                               unsigned char *kstr, int klen,
+                                               pem_password_cb *cb, void *u)
+       {
+        BIO *b;
+        int ret;
+
+        if ((b=BIO_new_fp(fp, BIO_NOCLOSE)) == NULL)
+               {
+               PEMerr(PEM_F_PEM_WRITE_PRIVATEKEY,ERR_R_BUF_LIB);
+                return 0;
+               }
+        ret=PEM_write_bio_PrivateKey(b, x, enc, kstr, klen, cb, u);
+        BIO_free(b);
+        return ret;
+       }
+
 #endif
index 3f709f1..b531057 100644 (file)
@@ -57,7 +57,6 @@
  */
 
 #include <stdio.h>
-#undef SSLEAY_MACROS
 #include "cryptlib.h"
 #include <openssl/bio.h>
 #include <openssl/evp.h>
index 7cc7491..328f796 100644 (file)
@@ -57,7 +57,6 @@
  */
 
 #include <stdio.h>
-#undef SSLEAY_MACROS
 #include "cryptlib.h"
 #include <openssl/bio.h>
 #include <openssl/evp.h>
diff --git a/deps/openssl/openssl/crypto/pem/pvkfmt.c b/deps/openssl/openssl/crypto/pem/pvkfmt.c
new file mode 100644 (file)
index 0000000..5f130c4
--- /dev/null
@@ -0,0 +1,938 @@
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project 2005.
+ */
+/* ====================================================================
+ * Copyright (c) 2005 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+/* Support for PVK format keys and related structures (such a PUBLICKEYBLOB
+ * and PRIVATEKEYBLOB).
+ */
+
+#include "cryptlib.h"
+#include <openssl/pem.h>
+#include <openssl/rand.h>
+#include <openssl/bn.h>
+#if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DSA)
+#include <openssl/dsa.h>
+#include <openssl/rsa.h>
+
+/* Utility function: read a DWORD (4 byte unsigned integer) in little endian
+ * format
+ */
+
+static unsigned int read_ledword(const unsigned char **in)
+       {
+       const unsigned char *p = *in;
+       unsigned int ret;
+       ret = *p++;
+       ret |= (*p++ << 8);
+       ret |= (*p++ << 16);
+       ret |= (*p++ << 24);
+       *in = p;
+       return ret;
+       }
+
+/* Read a BIGNUM in little endian format. The docs say that this should take up 
+ * bitlen/8 bytes.
+ */
+
+static int read_lebn(const unsigned char **in, unsigned int nbyte, BIGNUM **r)
+       {
+       const unsigned char *p;
+       unsigned char *tmpbuf, *q;
+       unsigned int i;
+       p = *in + nbyte - 1;
+       tmpbuf = OPENSSL_malloc(nbyte);
+       if (!tmpbuf)
+               return 0;
+       q = tmpbuf;
+       for (i = 0; i < nbyte; i++)
+               *q++ = *p--;
+       *r = BN_bin2bn(tmpbuf, nbyte, NULL);
+       OPENSSL_free(tmpbuf);
+       if (*r)
+               {
+               *in += nbyte;
+               return 1;
+               }
+       else
+               return 0;
+       }
+
+
+/* Convert private key blob to EVP_PKEY: RSA and DSA keys supported */
+
+#define MS_PUBLICKEYBLOB       0x6
+#define MS_PRIVATEKEYBLOB      0x7
+#define MS_RSA1MAGIC           0x31415352L
+#define MS_RSA2MAGIC           0x32415352L
+#define MS_DSS1MAGIC           0x31535344L
+#define MS_DSS2MAGIC           0x32535344L
+
+#define MS_KEYALG_RSA_KEYX     0xa400
+#define MS_KEYALG_DSS_SIGN     0x2200
+
+#define MS_KEYTYPE_KEYX                0x1
+#define MS_KEYTYPE_SIGN                0x2
+
+/* The PVK file magic number: seems to spell out "bobsfile", who is Bob? */
+#define MS_PVKMAGIC            0xb0b5f11eL
+/* Salt length for PVK files */
+#define PVK_SALTLEN            0x10
+
+static EVP_PKEY *b2i_rsa(const unsigned char **in, unsigned int length,
+                                               unsigned int bitlen, int ispub);
+static EVP_PKEY *b2i_dss(const unsigned char **in, unsigned int length,
+                                               unsigned int bitlen, int ispub);
+
+static int do_blob_header(const unsigned char **in, unsigned int length,
+                               unsigned int *pmagic, unsigned int *pbitlen,
+                               int *pisdss, int *pispub)
+       {
+       const unsigned char *p = *in;
+       if (length < 16)
+               return 0;
+       /* bType */
+       if (*p == MS_PUBLICKEYBLOB)
+               {
+               if (*pispub == 0)
+                       {
+                       PEMerr(PEM_F_DO_BLOB_HEADER,
+                                       PEM_R_EXPECTING_PRIVATE_KEY_BLOB);
+                       return 0;
+                       }
+               *pispub = 1;
+               }
+       else if (*p == MS_PRIVATEKEYBLOB)
+               {
+               if (*pispub == 1)
+                       {
+                       PEMerr(PEM_F_DO_BLOB_HEADER,
+                                       PEM_R_EXPECTING_PUBLIC_KEY_BLOB);
+                       return 0;
+                       }
+               *pispub = 0;
+               }
+       else
+               return 0;
+       p++;
+       /* Version */
+       if (*p++ != 0x2)
+               {
+               PEMerr(PEM_F_DO_BLOB_HEADER, PEM_R_BAD_VERSION_NUMBER);
+               return 0;
+               }
+       /* Ignore reserved, aiKeyAlg */
+       p+= 6;
+       *pmagic = read_ledword(&p);
+       *pbitlen = read_ledword(&p);
+       *pisdss = 0;
+       switch (*pmagic)
+               {
+
+               case MS_DSS1MAGIC:
+               *pisdss = 1;
+               case MS_RSA1MAGIC:
+               if (*pispub == 0)
+                       {
+                       PEMerr(PEM_F_DO_BLOB_HEADER,
+                                       PEM_R_EXPECTING_PRIVATE_KEY_BLOB);
+                       return 0;
+                       }
+               break;
+
+               case MS_DSS2MAGIC:
+               *pisdss = 1;
+               case MS_RSA2MAGIC:
+               if (*pispub == 1)
+                       {
+                       PEMerr(PEM_F_DO_BLOB_HEADER,
+                                       PEM_R_EXPECTING_PUBLIC_KEY_BLOB);
+                       return 0;
+                       }
+               break;
+
+               default:
+               PEMerr(PEM_F_DO_BLOB_HEADER, PEM_R_BAD_MAGIC_NUMBER);
+               return -1;
+               }
+       *in = p;
+       return 1;
+       }
+
+static unsigned int blob_length(unsigned bitlen, int isdss, int ispub)
+       {
+       unsigned int nbyte, hnbyte;
+       nbyte = (bitlen + 7) >> 3;
+       hnbyte = (bitlen + 15) >> 4;
+       if (isdss)
+               {
+
+               /* Expected length: 20 for q + 3 components bitlen each + 24
+                * for seed structure.
+                */
+               if (ispub)
+                       return  44 + 3 * nbyte;
+               /* Expected length: 20 for q, priv, 2 bitlen components + 24
+                * for seed structure.
+                */
+               else
+                       return 64 + 2 * nbyte;
+               }
+       else
+               {
+               /* Expected length: 4 for 'e' + 'n' */
+               if (ispub)
+                       return 4 + nbyte;
+               else
+               /* Expected length: 4 for 'e' and 7 other components.
+                * 2 components are bitlen size, 5 are bitlen/2
+                */
+                       return 4 + 2*nbyte + 5*hnbyte;
+               }
+
+       }
+
+static EVP_PKEY *do_b2i(const unsigned char **in, unsigned int length,
+                                                               int ispub)
+       {
+       const unsigned char *p = *in;
+       unsigned int bitlen, magic;
+       int isdss;
+       if (do_blob_header(&p, length, &magic, &bitlen, &isdss, &ispub) <= 0)
+               {
+               PEMerr(PEM_F_DO_B2I, PEM_R_KEYBLOB_HEADER_PARSE_ERROR);
+               return NULL;
+               }
+       length -= 16;
+       if (length < blob_length(bitlen, isdss, ispub))
+               {
+               PEMerr(PEM_F_DO_B2I, PEM_R_KEYBLOB_TOO_SHORT);
+               return NULL;
+               }
+       if (isdss)
+               return b2i_dss(&p, length, bitlen, ispub);
+       else
+               return b2i_rsa(&p, length, bitlen, ispub);
+       }
+
+static EVP_PKEY *do_b2i_bio(BIO *in, int ispub)
+       {
+       const unsigned char *p;
+       unsigned char hdr_buf[16], *buf = NULL;
+       unsigned int bitlen, magic, length;
+       int isdss;
+       EVP_PKEY *ret = NULL;
+       if (BIO_read(in, hdr_buf, 16) != 16)
+               {
+               PEMerr(PEM_F_DO_B2I_BIO, PEM_R_KEYBLOB_TOO_SHORT);
+               return NULL;
+               }
+       p = hdr_buf;
+       if (do_blob_header(&p, 16, &magic, &bitlen, &isdss, &ispub) <= 0)
+               return NULL;
+
+       length = blob_length(bitlen, isdss, ispub);
+       buf = OPENSSL_malloc(length);
+       if (!buf)
+               {
+               PEMerr(PEM_F_DO_B2I_BIO, ERR_R_MALLOC_FAILURE);
+               goto err;
+               }
+       p = buf;
+       if (BIO_read(in, buf, length) != (int)length)
+               {
+               PEMerr(PEM_F_DO_B2I_BIO, PEM_R_KEYBLOB_TOO_SHORT);
+               goto err;
+               }
+
+       if (isdss)
+               ret = b2i_dss(&p, length, bitlen, ispub);
+       else
+               ret = b2i_rsa(&p, length, bitlen, ispub);
+
+       err:
+       if (buf)
+               OPENSSL_free(buf);
+       return ret;
+       }
+
+static EVP_PKEY *b2i_dss(const unsigned char **in, unsigned int length,
+                                               unsigned int bitlen, int ispub)
+       {
+       const unsigned char *p = *in;
+       EVP_PKEY *ret = NULL;
+       DSA *dsa = NULL;
+       BN_CTX *ctx = NULL;
+       unsigned int nbyte;
+       nbyte = (bitlen + 7) >> 3;
+
+       dsa = DSA_new();
+       ret = EVP_PKEY_new();
+       if (!dsa || !ret)
+               goto memerr;
+       if (!read_lebn(&p, nbyte, &dsa->p))
+               goto memerr;
+       if (!read_lebn(&p, 20, &dsa->q))
+               goto memerr;
+       if (!read_lebn(&p, nbyte, &dsa->g))
+               goto memerr;
+       if (ispub)
+               {
+               if (!read_lebn(&p, nbyte, &dsa->pub_key))
+                       goto memerr;
+               }
+       else
+               {
+               if (!read_lebn(&p, 20, &dsa->priv_key))
+                       goto memerr;
+               /* Calculate public key */
+               if (!(dsa->pub_key = BN_new()))
+                       goto memerr;
+               if (!(ctx = BN_CTX_new()))
+                       goto memerr;
+                       
+               if (!BN_mod_exp(dsa->pub_key, dsa->g,
+                                                dsa->priv_key, dsa->p, ctx))
+                       
+                       goto memerr;
+               BN_CTX_free(ctx);
+               }
+
+       EVP_PKEY_set1_DSA(ret, dsa);
+       DSA_free(dsa);
+       *in = p;
+       return ret;
+
+       memerr:
+       PEMerr(PEM_F_B2I_DSS, ERR_R_MALLOC_FAILURE);
+       if (dsa)
+               DSA_free(dsa);
+       if (ret)
+               EVP_PKEY_free(ret);
+       if (ctx)
+               BN_CTX_free(ctx);
+       return NULL;
+       }
+
+static EVP_PKEY *b2i_rsa(const unsigned char **in, unsigned int length,
+                                               unsigned int bitlen, int ispub)
+               
+       {
+       const unsigned char *p = *in;
+       EVP_PKEY *ret = NULL;
+       RSA *rsa = NULL;
+       unsigned int nbyte, hnbyte;
+       nbyte = (bitlen + 7) >> 3;
+       hnbyte = (bitlen + 15) >> 4;
+       rsa = RSA_new();
+       ret = EVP_PKEY_new();
+       if (!rsa || !ret)
+               goto memerr;
+       rsa->e = BN_new();
+       if (!rsa->e)
+               goto memerr;
+       if (!BN_set_word(rsa->e, read_ledword(&p)))
+               goto memerr;
+       if (!read_lebn(&p, nbyte, &rsa->n))
+               goto memerr;
+       if (!ispub)
+               {
+               if (!read_lebn(&p, hnbyte, &rsa->p))
+                       goto memerr;
+               if (!read_lebn(&p, hnbyte, &rsa->q))
+                       goto memerr;
+               if (!read_lebn(&p, hnbyte, &rsa->dmp1))
+                       goto memerr;
+               if (!read_lebn(&p, hnbyte, &rsa->dmq1))
+                       goto memerr;
+               if (!read_lebn(&p, hnbyte, &rsa->iqmp))
+                       goto memerr;
+               if (!read_lebn(&p, nbyte, &rsa->d))
+                       goto memerr;
+               }
+
+       EVP_PKEY_set1_RSA(ret, rsa);
+       RSA_free(rsa);
+       *in = p;
+       return ret;
+       memerr:
+       PEMerr(PEM_F_B2I_RSA, ERR_R_MALLOC_FAILURE);
+       if (rsa)
+               RSA_free(rsa);
+       if (ret)
+               EVP_PKEY_free(ret);
+       return NULL;
+       }
+
+EVP_PKEY *b2i_PrivateKey(const unsigned char **in, long length)
+       {
+       return do_b2i(in, length, 0);
+       }
+
+EVP_PKEY *b2i_PublicKey(const unsigned char **in, long length)
+       {
+       return do_b2i(in, length, 1);
+       }
+
+
+EVP_PKEY *b2i_PrivateKey_bio(BIO *in)
+       {
+       return do_b2i_bio(in, 0);
+       }
+
+EVP_PKEY *b2i_PublicKey_bio(BIO *in)
+       {
+       return do_b2i_bio(in, 1);
+       }
+
+static void write_ledword(unsigned char **out, unsigned int dw)
+       {
+       unsigned char *p = *out;
+       *p++ = dw & 0xff;
+       *p++ = (dw>>8) & 0xff;
+       *p++ = (dw>>16) & 0xff;
+       *p++ = (dw>>24) & 0xff;
+       *out = p;
+       }
+
+static void write_lebn(unsigned char **out, const BIGNUM *bn, int len)
+       {
+       int nb, i;
+       unsigned char *p = *out, *q, c;
+       nb = BN_num_bytes(bn);
+       BN_bn2bin(bn, p);
+       q = p + nb - 1;
+       /* In place byte order reversal */
+       for (i = 0; i < nb/2; i++)
+               {
+               c = *p;
+               *p++ = *q;
+               *q-- = c;
+               }
+       *out += nb;
+       /* Pad with zeroes if we have to */
+       if (len > 0)
+               {
+               len -= nb;
+               if (len > 0)
+                       {
+                       memset(*out, 0, len);
+                       *out += len;
+                       }
+               }
+       }
+
+
+static int check_bitlen_rsa(RSA *rsa, int ispub, unsigned int *magic);
+static int check_bitlen_dsa(DSA *dsa, int ispub, unsigned int *magic);
+
+static void write_rsa(unsigned char **out, RSA *rsa, int ispub);
+static void write_dsa(unsigned char **out, DSA *dsa, int ispub);
+       
+static int do_i2b(unsigned char **out, EVP_PKEY *pk, int ispub)
+       {
+       unsigned char *p;
+       unsigned int bitlen, magic = 0, keyalg;
+       int outlen, noinc = 0;
+       if (pk->type == EVP_PKEY_DSA)
+               {
+               bitlen = check_bitlen_dsa(pk->pkey.dsa, ispub, &magic);
+               keyalg = MS_KEYALG_DSS_SIGN;
+               }
+       else if (pk->type == EVP_PKEY_RSA)
+               {
+               bitlen = check_bitlen_rsa(pk->pkey.rsa, ispub, &magic);
+               keyalg = MS_KEYALG_RSA_KEYX;
+               }
+       else
+               return -1;
+       if (bitlen == 0)
+               return -1;
+       outlen = 16 + blob_length(bitlen,
+                       keyalg == MS_KEYALG_DSS_SIGN ? 1 : 0, ispub);
+       if (out == NULL)
+               return outlen;
+       if (*out)
+               p = *out;
+       else
+               {
+               p = OPENSSL_malloc(outlen);
+               if (!p)
+                       return -1;
+               *out = p;
+               noinc = 1;
+               }
+       if (ispub)
+               *p++ = MS_PUBLICKEYBLOB;
+       else
+               *p++ = MS_PRIVATEKEYBLOB;
+       *p++ = 0x2;
+       *p++ = 0;
+       *p++ = 0;
+       write_ledword(&p, keyalg);
+       write_ledword(&p, magic);
+       write_ledword(&p, bitlen);
+       if (keyalg == MS_KEYALG_DSS_SIGN)
+               write_dsa(&p, pk->pkey.dsa, ispub);
+       else
+               write_rsa(&p, pk->pkey.rsa, ispub);
+       if (!noinc)
+               *out += outlen;
+       return outlen;
+       }
+
+static int do_i2b_bio(BIO *out, EVP_PKEY *pk, int ispub)
+       {
+       unsigned char *tmp = NULL;
+       int outlen, wrlen;
+       outlen = do_i2b(&tmp, pk, ispub);
+       if (outlen < 0)
+               return -1;
+       wrlen = BIO_write(out, tmp, outlen);
+       OPENSSL_free(tmp);
+       if (wrlen == outlen)
+               return outlen;
+       return -1;
+       }
+
+static int check_bitlen_dsa(DSA *dsa, int ispub, unsigned int *pmagic)
+       {
+       int bitlen;
+       bitlen = BN_num_bits(dsa->p);
+       if ((bitlen & 7) || (BN_num_bits(dsa->q) != 160)
+               || (BN_num_bits(dsa->g) > bitlen))
+               goto badkey;
+       if (ispub)
+               {
+               if (BN_num_bits(dsa->pub_key) > bitlen)
+                       goto badkey;
+               *pmagic = MS_DSS1MAGIC;
+               }
+       else
+               {
+               if (BN_num_bits(dsa->priv_key) > 160)
+                       goto badkey;
+               *pmagic = MS_DSS2MAGIC;
+               }
+       
+       return bitlen;
+       badkey:
+       PEMerr(PEM_F_CHECK_BITLEN_DSA, PEM_R_UNSUPPORTED_KEY_COMPONENTS);
+       return 0;
+       }
+
+static int check_bitlen_rsa(RSA *rsa, int ispub, unsigned int *pmagic)
+       {
+       int nbyte, hnbyte, bitlen;
+       if (BN_num_bits(rsa->e) > 32)
+               goto badkey;
+       bitlen = BN_num_bits(rsa->n);
+       nbyte = BN_num_bytes(rsa->n);
+       hnbyte = (BN_num_bits(rsa->n) + 15) >> 4;
+       if (ispub)
+               {
+               *pmagic = MS_RSA1MAGIC;
+               return bitlen;
+               }
+       else
+       {
+               *pmagic = MS_RSA2MAGIC;
+               /* For private key each component must fit within nbyte or
+                * hnbyte.
+                */
+               if (BN_num_bytes(rsa->d) > nbyte)
+                       goto badkey;
+               if ((BN_num_bytes(rsa->iqmp) > hnbyte)
+                       || (BN_num_bytes(rsa->p) > hnbyte)
+                       || (BN_num_bytes(rsa->q) > hnbyte)
+                       || (BN_num_bytes(rsa->dmp1) > hnbyte)
+                       || (BN_num_bytes(rsa->dmq1) > hnbyte))
+                       goto badkey;
+       }
+       return bitlen;
+       badkey:
+       PEMerr(PEM_F_CHECK_BITLEN_RSA, PEM_R_UNSUPPORTED_KEY_COMPONENTS);
+       return 0;
+       }
+
+
+static void write_rsa(unsigned char **out, RSA *rsa, int ispub)
+       {
+       int nbyte, hnbyte;
+       nbyte = BN_num_bytes(rsa->n);
+       hnbyte = (BN_num_bits(rsa->n) + 15) >> 4;
+       write_lebn(out, rsa->e, 4);
+       write_lebn(out, rsa->n, -1);
+       if (ispub)
+               return;
+       write_lebn(out, rsa->p, hnbyte);
+       write_lebn(out, rsa->q, hnbyte);
+       write_lebn(out, rsa->dmp1, hnbyte);
+       write_lebn(out, rsa->dmq1, hnbyte);
+       write_lebn(out, rsa->iqmp, hnbyte);
+       write_lebn(out, rsa->d, nbyte);
+       }
+
+       
+static void write_dsa(unsigned char **out, DSA *dsa, int ispub)
+       {
+       int nbyte;
+       nbyte = BN_num_bytes(dsa->p);
+       write_lebn(out, dsa->p, nbyte);
+       write_lebn(out, dsa->q, 20);
+       write_lebn(out, dsa->g, nbyte);
+       if (ispub)
+               write_lebn(out, dsa->pub_key, nbyte);
+       else
+               write_lebn(out, dsa->priv_key, 20);
+       /* Set "invalid" for seed structure values */
+       memset(*out, 0xff, 24);
+       *out += 24;
+       return;
+       }
+       
+
+int i2b_PrivateKey_bio(BIO *out, EVP_PKEY *pk)
+       {
+       return do_i2b_bio(out, pk, 0);
+       }
+
+int i2b_PublicKey_bio(BIO *out, EVP_PKEY *pk)
+       {
+       return do_i2b_bio(out, pk, 1);
+       }
+
+#ifndef OPENSSL_NO_RC4
+
+static int do_PVK_header(const unsigned char **in, unsigned int length,
+               int skip_magic,
+               unsigned int *psaltlen, unsigned int *pkeylen)
+               
+       {
+       const unsigned char *p = *in;
+       unsigned int pvk_magic, is_encrypted;
+       if (skip_magic)
+               {
+               if (length < 20)
+                       {
+                       PEMerr(PEM_F_DO_PVK_HEADER, PEM_R_PVK_TOO_SHORT);
+                       return 0;
+                       }
+               length -= 20;
+               }
+       else
+               {
+               if (length < 24)
+                       {
+                       PEMerr(PEM_F_DO_PVK_HEADER, PEM_R_PVK_TOO_SHORT);
+                       return 0;
+                       }
+               length -= 24;
+               pvk_magic = read_ledword(&p);
+               if (pvk_magic != MS_PVKMAGIC)
+                       {
+                       PEMerr(PEM_F_DO_PVK_HEADER, PEM_R_BAD_MAGIC_NUMBER);
+                       return 0;
+                       }
+               }
+       /* Skip reserved */
+       p += 4;
+       /*keytype = */read_ledword(&p);
+       is_encrypted = read_ledword(&p);
+       *psaltlen = read_ledword(&p);
+       *pkeylen = read_ledword(&p);
+
+       if (is_encrypted && !*psaltlen)
+               {
+               PEMerr(PEM_F_DO_PVK_HEADER, PEM_R_INCONSISTENT_HEADER);
+               return 0;
+               }
+
+       *in = p;
+       return 1;
+       }
+
+static int derive_pvk_key(unsigned char *key, 
+                       const unsigned char *salt, unsigned int saltlen,
+                       const unsigned char *pass, int passlen)
+       {
+       EVP_MD_CTX mctx;
+       EVP_MD_CTX_init(&mctx);
+       EVP_DigestInit_ex(&mctx, EVP_sha1(), NULL);
+       EVP_DigestUpdate(&mctx, salt, saltlen);
+       EVP_DigestUpdate(&mctx, pass, passlen);
+       EVP_DigestFinal_ex(&mctx, key, NULL);
+       EVP_MD_CTX_cleanup(&mctx);
+       return 1;
+       }
+       
+
+static EVP_PKEY *do_PVK_body(const unsigned char **in,
+               unsigned int saltlen, unsigned int keylen,
+               pem_password_cb *cb, void *u)
+       {
+       EVP_PKEY *ret = NULL;
+       const unsigned char *p = *in;
+       unsigned int magic;
+       unsigned char *enctmp = NULL, *q;
+       if (saltlen)
+               {
+               char psbuf[PEM_BUFSIZE];
+               unsigned char keybuf[20];
+               EVP_CIPHER_CTX cctx;
+               int enctmplen, inlen;
+               if (cb)
+                       inlen=cb(psbuf,PEM_BUFSIZE,0,u);
+               else
+                       inlen=PEM_def_callback(psbuf,PEM_BUFSIZE,0,u);
+               if (inlen <= 0)
+                       {
+                       PEMerr(PEM_F_DO_PVK_BODY,PEM_R_BAD_PASSWORD_READ);
+                       return NULL;
+                       }
+               enctmp = OPENSSL_malloc(keylen + 8);
+               if (!enctmp)
+                       {
+                       PEMerr(PEM_F_DO_PVK_BODY, ERR_R_MALLOC_FAILURE);
+                       return NULL;
+                       }
+               if (!derive_pvk_key(keybuf, p, saltlen,
+                           (unsigned char *)psbuf, inlen))
+                       return NULL;
+               p += saltlen;
+               /* Copy BLOBHEADER across, decrypt rest */
+               memcpy(enctmp, p, 8);
+               p += 8;
+               inlen = keylen - 8;
+               q = enctmp + 8;
+               EVP_CIPHER_CTX_init(&cctx);
+               EVP_DecryptInit_ex(&cctx, EVP_rc4(), NULL, keybuf, NULL);
+               EVP_DecryptUpdate(&cctx, q, &enctmplen, p, inlen);
+               EVP_DecryptFinal_ex(&cctx, q + enctmplen, &enctmplen);
+               magic = read_ledword((const unsigned char **)&q);
+               if (magic != MS_RSA2MAGIC && magic != MS_DSS2MAGIC)
+                       {
+                       q = enctmp + 8;
+                       memset(keybuf + 5, 0, 11);
+                       EVP_DecryptInit_ex(&cctx, EVP_rc4(), NULL, keybuf,
+                                                               NULL);
+                       OPENSSL_cleanse(keybuf, 20);
+                       EVP_DecryptUpdate(&cctx, q, &enctmplen, p, inlen);
+                       EVP_DecryptFinal_ex(&cctx, q + enctmplen,
+                                                               &enctmplen);
+                       magic = read_ledword((const unsigned char **)&q);
+                       if (magic != MS_RSA2MAGIC && magic != MS_DSS2MAGIC)
+                               {
+                               EVP_CIPHER_CTX_cleanup(&cctx);
+                               PEMerr(PEM_F_DO_PVK_BODY, PEM_R_BAD_DECRYPT);
+                               goto err;
+                               }
+                       }
+               else
+                       OPENSSL_cleanse(keybuf, 20);
+               EVP_CIPHER_CTX_cleanup(&cctx);
+               p = enctmp;
+               }
+
+       ret = b2i_PrivateKey(&p, keylen);
+       err:
+       if (enctmp && saltlen)
+               OPENSSL_free(enctmp);
+       return ret;
+       }
+
+
+EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u)
+       {
+       unsigned char pvk_hdr[24], *buf = NULL;
+       const unsigned char *p;
+       int buflen;
+       EVP_PKEY *ret = NULL;
+       unsigned int saltlen, keylen;
+       if (BIO_read(in, pvk_hdr, 24) != 24)
+               {
+               PEMerr(PEM_F_B2I_PVK_BIO, PEM_R_PVK_DATA_TOO_SHORT);
+               return NULL;
+               }
+       p = pvk_hdr;
+
+       if (!do_PVK_header(&p, 24, 0, &saltlen, &keylen))
+               return 0;
+       buflen = (int) keylen + saltlen;
+       buf = OPENSSL_malloc(buflen);
+       if (!buf)
+               {
+               PEMerr(PEM_F_B2I_PVK_BIO, ERR_R_MALLOC_FAILURE);
+               return 0;
+               }
+       p = buf;
+       if (BIO_read(in, buf, buflen) != buflen)
+               {
+               PEMerr(PEM_F_B2I_PVK_BIO, PEM_R_PVK_DATA_TOO_SHORT);
+               goto err;
+               }
+       ret = do_PVK_body(&p, saltlen, keylen, cb, u);
+
+       err:
+       if (buf)
+               {
+               OPENSSL_cleanse(buf, buflen);
+               OPENSSL_free(buf);
+               }
+       return ret;
+       }
+
+       
+       
+static int i2b_PVK(unsigned char **out, EVP_PKEY*pk, int enclevel,
+               pem_password_cb *cb, void *u)
+       {
+       int outlen = 24, pklen;
+       unsigned char *p, *salt = NULL;
+       if (enclevel)
+               outlen += PVK_SALTLEN;
+       pklen = do_i2b(NULL, pk, 0);
+       if (pklen < 0)
+               return -1;
+       outlen += pklen;
+       if (!out)
+               return outlen;
+       if (*out)
+               p = *out;
+       else
+               {
+               p = OPENSSL_malloc(outlen);
+               if (!p)
+                       {
+                       PEMerr(PEM_F_I2B_PVK,ERR_R_MALLOC_FAILURE);
+                       return -1;
+                       }
+               *out = p;
+               }
+
+       write_ledword(&p, MS_PVKMAGIC);
+       write_ledword(&p, 0);
+       if (pk->type == EVP_PKEY_DSA)
+               write_ledword(&p, MS_KEYTYPE_SIGN);
+       else
+               write_ledword(&p, MS_KEYTYPE_KEYX);
+       write_ledword(&p, enclevel ? 1 : 0);
+       write_ledword(&p, enclevel ? PVK_SALTLEN: 0);
+       write_ledword(&p, pklen);
+       if (enclevel)
+               {
+               if (RAND_bytes(p, PVK_SALTLEN) <= 0)
+                       goto error;
+               salt = p;
+               p += PVK_SALTLEN;
+               }
+       do_i2b(&p, pk, 0);
+       if (enclevel == 0)
+               return outlen;
+       else
+               {
+               char psbuf[PEM_BUFSIZE];
+               unsigned char keybuf[20];
+               EVP_CIPHER_CTX cctx;
+               int enctmplen, inlen;
+               if (cb)
+                       inlen=cb(psbuf,PEM_BUFSIZE,1,u);
+               else
+                       inlen=PEM_def_callback(psbuf,PEM_BUFSIZE,1,u);
+               if (inlen <= 0)
+                       {
+                       PEMerr(PEM_F_I2B_PVK,PEM_R_BAD_PASSWORD_READ);
+                       goto error;
+                       }
+               if (!derive_pvk_key(keybuf, salt, PVK_SALTLEN,
+                           (unsigned char *)psbuf, inlen))
+                       goto error;
+               if (enclevel == 1)
+                       memset(keybuf + 5, 0, 11);
+               p = salt + PVK_SALTLEN + 8;
+               EVP_CIPHER_CTX_init(&cctx);
+               EVP_EncryptInit_ex(&cctx, EVP_rc4(), NULL, keybuf, NULL);
+               OPENSSL_cleanse(keybuf, 20);
+               EVP_DecryptUpdate(&cctx, p, &enctmplen, p, pklen - 8);
+               EVP_DecryptFinal_ex(&cctx, p + enctmplen, &enctmplen);
+               EVP_CIPHER_CTX_cleanup(&cctx);
+               }
+       return outlen;
+
+       error:
+       return -1;
+       }
+
+int i2b_PVK_bio(BIO *out, EVP_PKEY *pk, int enclevel,
+               pem_password_cb *cb, void *u)
+       {
+       unsigned char *tmp = NULL;
+       int outlen, wrlen;
+       outlen = i2b_PVK(&tmp, pk, enclevel, cb, u);
+       if (outlen < 0)
+               return -1;
+       wrlen = BIO_write(out, tmp, outlen);
+       OPENSSL_free(tmp);
+       if (wrlen == outlen)
+               {
+               PEMerr(PEM_F_I2B_PVK_BIO, PEM_R_BIO_WRITE_FAILURE);
+               return outlen;
+               }
+       return -1;
+       }
+
+#endif
+
+#endif
index e43dc9a..6fc2510 100644 (file)
@@ -158,7 +158,6 @@ sub cbc
        &jmp_ptr($count);
 
 &set_label("ej7");
-       &xor("edx",             "edx") if $ppro; # ppro friendly
        &movb(&HB("edx"),       &BP(6,$in,"",0));
        &shl("edx",8);
 &set_label("ej6");
@@ -170,7 +169,6 @@ sub cbc
        &jmp(&label("ejend"));
 &set_label("ej3");
        &movb(&HB("ecx"),       &BP(2,$in,"",0));
-       &xor("ecx",             "ecx") if $ppro; # ppro friendly
        &shl("ecx",8);
 &set_label("ej2");
        &movb(&HB("ecx"),       &BP(1,$in,"",0));
diff --git a/deps/openssl/openssl/crypto/perlasm/ppc-xlate.pl b/deps/openssl/openssl/crypto/perlasm/ppc-xlate.pl
new file mode 100644 (file)
index 0000000..4579671
--- /dev/null
@@ -0,0 +1,152 @@
+#!/usr/bin/env perl
+
+# PowerPC assembler distiller by <appro>.
+
+my $flavour = shift;
+my $output = shift;
+open STDOUT,">$output" || die "can't open $output: $!";
+
+my %GLOBALS;
+my $dotinlocallabels=($flavour=~/linux/)?1:0;
+
+################################################################
+# directives which need special treatment on different platforms
+################################################################
+my $globl = sub {
+    my $junk = shift;
+    my $name = shift;
+    my $global = \$GLOBALS{$name};
+    my $ret;
+
+    $name =~ s|^[\.\_]||;
+    SWITCH: for ($flavour) {
+       /aix/           && do { $name = ".$name";
+                               last;
+                             };
+       /osx/           && do { $name = "_$name";
+                               last;
+                             };
+       /linux.*32/     && do { $ret .= ".globl $name\n";
+                               $ret .= ".type  $name,\@function";
+                               last;
+                             };
+       /linux.*64/     && do { $ret .= ".globl .$name\n";
+                               $ret .= ".type  .$name,\@function\n";
+                               $ret .= ".section       \".opd\",\"aw\"\n";
+                               $ret .= ".globl $name\n";
+                               $ret .= ".align 3\n";
+                               $ret .= "$name:\n";
+                               $ret .= ".quad  .$name,.TOC.\@tocbase,0\n";
+                               $ret .= ".size  $name,24\n";
+                               $ret .= ".previous\n";
+
+                               $name = ".$name";
+                               last;
+                             };
+    }
+
+    $ret = ".globl     $name" if (!$ret);
+    $$global = $name;
+    $ret;
+};
+my $text = sub {
+    ($flavour =~ /aix/) ? ".csect" : ".text";
+};
+my $machine = sub {
+    my $junk = shift;
+    my $arch = shift;
+    if ($flavour =~ /osx/)
+    {  $arch =~ s/\"//g;
+       $arch = ($flavour=~/64/) ? "ppc970-64" : "ppc970" if ($arch eq "any");
+    }
+    ".machine  $arch";
+};
+my $asciz = sub {
+    shift;
+    my $line = join(",",@_);
+    if ($line =~ /^"(.*)"$/)
+    {  ".byte  " . join(",",unpack("C*",$1),0) . "\n.align     2";     }
+    else
+    {  "";     }
+};
+
+################################################################
+# simplified mnemonics not handled by at least one assembler
+################################################################
+my $cmplw = sub {
+    my $f = shift;
+    my $cr = 0; $cr = shift if ($#_>1);
+    # Some out-of-date 32-bit GNU assembler just can't handle cmplw...
+    ($flavour =~ /linux.*32/) ?
+       "       .long   ".sprintf "0x%x",31<<26|$cr<<23|$_[0]<<16|$_[1]<<11|64 :
+       "       cmplw   ".join(',',$cr,@_);
+};
+my $bdnz = sub {
+    my $f = shift;
+    my $bo = $f=~/[\+\-]/ ? 16+9 : 16; # optional "to be taken" hint
+    "  bc      $bo,0,".shift;
+} if ($flavour!~/linux/);
+my $bltlr = sub {
+    my $f = shift;
+    my $bo = $f=~/\-/ ? 12+2 : 12;     # optional "not to be taken" hint
+    ($flavour =~ /linux/) ?            # GNU as doesn't allow most recent hints
+       "       .long   ".sprintf "0x%x",19<<26|$bo<<21|16<<1 :
+       "       bclr    $bo,0";
+};
+my $bnelr = sub {
+    my $f = shift;
+    my $bo = $f=~/\-/ ? 4+2 : 4;       # optional "not to be taken" hint
+    ($flavour =~ /linux/) ?            # GNU as doesn't allow most recent hints
+       "       .long   ".sprintf "0x%x",19<<26|$bo<<21|2<<16|16<<1 :
+       "       bclr    $bo,2";
+};
+my $beqlr = sub {
+    my $f = shift;
+    my $bo = $f=~/-/ ? 12+2 : 12;      # optional "not to be taken" hint
+    ($flavour =~ /linux/) ?            # GNU as doesn't allow most recent hints
+       "       .long   ".sprintf "0x%X",19<<26|$bo<<21|2<<16|16<<1 :
+       "       bclr    $bo,2";
+};
+# GNU assembler can't handle extrdi rA,rS,16,48, or when sum of last two
+# arguments is 64, with "operand out of range" error.
+my $extrdi = sub {
+    my ($f,$ra,$rs,$n,$b) = @_;
+    $b = ($b+$n)&63; $n = 64-$n;
+    "  rldicl  $ra,$rs,$b,$n";
+};
+
+while($line=<>) {
+
+    $line =~ s|[#!;].*$||;     # get rid of asm-style comments...
+    $line =~ s|/\*.*\*/||;     # ... and C-style comments...
+    $line =~ s|^\s+||;         # ... and skip white spaces in beginning...
+    $line =~ s|\s+$||;         # ... and at the end
+
+    {
+       $line =~ s|\b\.L(\w+)|L$1|g;    # common denominator for Locallabel
+       $line =~ s|\bL(\w+)|\.L$1|g     if ($dotinlocallabels);
+    }
+
+    {
+       $line =~ s|(^[\.\w]+)\:\s*||;
+       my $label = $1;
+       printf "%s:",($GLOBALS{$label} or $label) if ($label);
+    }
+
+    {
+       $line =~ s|^\s*(\.?)(\w+)([\.\+\-]?)\s*||;
+       my $c = $1; $c = "\t" if ($c eq "");
+       my $mnemonic = $2;
+       my $f = $3;
+       my $opcode = eval("\$$mnemonic");
+       $line =~ s|\bc?[rf]([0-9]+)\b|$1|g if ($c ne "." and $flavour !~ /osx/);
+       if (ref($opcode) eq 'CODE') { $line = &$opcode($f,split(',',$line)); }
+       elsif ($mnemonic)           { $line = $c.$mnemonic.$f."\t".$line; }
+    }
+
+    print $line if ($line);
+    print "\n";
+}
+
+close STDOUT;
index fe348b9..e47116b 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env perl
 
-# Ascetic x86_64 AT&T to MASM assembler translator by <appro>.
+# Ascetic x86_64 AT&T to MASM/NASM assembler translator by <appro>.
 #
 # Why AT&T to MASM and not vice versa? Several reasons. Because AT&T
 # format is way easier to parse. Because it's simpler to "gear" from
 # Currently recognized limitations:
 #
 # - can't use multiple ops per line;
-# - indirect calls and jumps are not supported;
 #
 # Dual-ABI styling rules.
 #
-# 1. Adhere to Unix register and stack layout [see the end for
-#    explanation].
+# 1. Adhere to Unix register and stack layout [see cross-reference
+#    ABI "card" at the end for explanation].
 # 2. Forget about "red zone," stick to more traditional blended
 #    stack frame allocation. If volatile storage is actually required
 #    that is. If not, just leave the stack as is.
 # 6. Don't use [or hand-code with .byte] "rep ret." "ret" mnemonic is
 #    required to identify the spots, where to inject Win64 epilogue!
 #    But on the pros, it's then prefixed with rep automatically:-)
-# 7. Due to MASM limitations [and certain general counter-intuitivity
-#    of ip-relative addressing] generation of position-independent
-#    code is assisted by synthetic directive, .picmeup, which puts
-#    address of the *next* instruction into target register.
+# 7. Stick to explicit ip-relative addressing. If you have to use
+#    GOTPCREL addressing, stick to mov symbol@GOTPCREL(%rip),%r??.
+#    Both are recognized and translated to proper Win64 addressing
+#    modes. To support legacy code a synthetic directive, .picmeup,
+#    is implemented. It puts address of the *next* instruction into
+#    target register, e.g.:
 #
-#    Example 1:
 #              .picmeup        %rax
 #              lea             .Label-.(%rax),%rax
-#    Example 2:
-#              .picmeup        %rcx
-#      .Lpic_point:
-#              ...
-#              lea             .Label-.Lpic_point(%rcx),%rbp
-
-my $output = shift;
+#
+# 8. In order to provide for structured exception handling unified
+#    Win64 prologue copies %rsp value to %rax. For further details
+#    see SEH paragraph at the end.
+# 9. .init segment is allowed to contain calls to functions only.
+# a. If function accepts more than 4 arguments *and* >4th argument
+#    is declared as non 64-bit value, do clear its upper part.
+\f
+my $flavour = shift;
+my $output  = shift;
+if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
 
 { my ($stddev,$stdino,@junk)=stat(STDOUT);
   my ($outdev,$outino,@junk)=stat($output);
@@ -65,13 +69,40 @@ my $output = shift;
        if ($stddev!=$outdev || $stdino!=$outino);
 }
 
+my $gas=1;     $gas=0 if ($output =~ /\.asm$/);
+my $elf=1;     $elf=0 if (!$gas);
+my $win64=0;
+my $prefix="";
+my $decor=".L";
+
 my $masmref=8 + 50727*2**-32;  # 8.00.50727 shipped with VS2005
-my $masm=$masmref if ($output =~ /\.asm/);
-if ($masm && `ml64 2>&1` =~ m/Version ([0-9]+)\.([0-9]+)(\.([0-9]+))?/)
-{   $masm=$1 + $2*2**-16 + $4*2**-32;   }
+my $masm=0;
+my $PTR=" PTR";
+
+my $nasmref=2.03;
+my $nasm=0;
+
+if    ($flavour eq "mingw64")  { $gas=1; $elf=0; $win64=1;
+                                 $prefix=`echo __USER_LABEL_PREFIX__ | $ENV{CC} -E -P -`;
+                                 chomp($prefix);
+                               }
+elsif ($flavour eq "macosx")   { $gas=1; $elf=0; $prefix="_"; $decor="L\$"; }
+elsif ($flavour eq "masm")     { $gas=0; $elf=0; $masm=$masmref; $win64=1; $decor="\$L\$"; }
+elsif ($flavour eq "nasm")     { $gas=0; $elf=0; $nasm=$nasmref; $win64=1; $decor="\$L\$"; $PTR=""; }
+elsif (!$gas)
+{   if ($ENV{ASM} =~ m/nasm/ && `nasm -v` =~ m/version ([0-9]+)\.([0-9]+)/i)
+    {  $nasm = $1 + $2*0.01; $PTR="";  }
+    elsif (`ml64 2>&1` =~ m/Version ([0-9]+)\.([0-9]+)(\.([0-9]+))?/)
+    {  $masm = $1 + $2*2**-16 + $4*2**-32;   }
+    die "no assembler found on %PATH" if (!($nasm || $masm));
+    $win64=1;
+    $elf=0;
+    $decor="\$L\$";
+}
 
 my $current_segment;
 my $current_function;
+my %globals;
 
 { package opcode;      # pick up opcodes
     sub re {
@@ -88,8 +119,10 @@ my $current_function;
            if ($self->{op} =~ /^(movz)b.*/) {  # movz is pain...
                $self->{op} = $1;
                $self->{sz} = "b";
-           } elsif ($self->{op} =~ /call/) {
-               $self->{sz} = ""
+           } elsif ($self->{op} =~ /call|jmp/) {
+               $self->{sz} = "";
+           } elsif ($self->{op} =~ /^p/ && $' !~ /^(ush|op)/) { # SSEn
+               $self->{sz} = "";
            } elsif ($self->{op} =~ /([a-z]{3,})([qlwb])$/) {
                $self->{op} = $1;
                $self->{sz} = $2;
@@ -105,13 +138,20 @@ my $current_function;
     }
     sub out {
        my $self = shift;
-       if (!$masm) {
+       if ($gas) {
            if ($self->{op} eq "movz") {        # movz is pain...
                sprintf "%s%s%s",$self->{op},$self->{sz},shift;
            } elsif ($self->{op} =~ /^set/) { 
                "$self->{op}";
            } elsif ($self->{op} eq "ret") {
-               ".byte  0xf3,0xc3";
+               my $epilogue = "";
+               if ($win64 && $current_function->{abi} eq "svr4") {
+                   $epilogue = "movq   8(%rsp),%rdi\n\t" .
+                               "movq   16(%rsp),%rsi\n\t";
+               }
+               $epilogue . ".byte      0xf3,0xc3";
+           } elsif ($self->{op} eq "call" && !$elf && $current_segment eq ".init") {
+               ".p2align\t3\n\t.quad";
            } else {
                "$self->{op}$self->{sz}";
            }
@@ -119,15 +159,25 @@ my $current_function;
            $self->{op} =~ s/^movz/movzx/;
            if ($self->{op} eq "ret") {
                $self->{op} = "";
-               if ($current_function->{abi} eq "svr4") {
-                   $self->{op} = "mov  rdi,QWORD PTR 8[rsp]\t;WIN64 epilogue\n\t".
-                                 "mov  rsi,QWORD PTR 16[rsp]\n\t";
+               if ($win64 && $current_function->{abi} eq "svr4") {
+                   $self->{op} = "mov  rdi,QWORD${PTR}[8+rsp]\t;WIN64 epilogue\n\t".
+                                 "mov  rsi,QWORD${PTR}[16+rsp]\n\t";
                }
                $self->{op} .= "DB\t0F3h,0C3h\t\t;repret";
-           }
+           } elsif ($self->{op} =~ /^(pop|push)f/) {
+               $self->{op} .= $self->{sz};
+           } elsif ($self->{op} eq "call" && $current_segment eq ".CRT\$XCU") {
+               $self->{op} = "\tDQ";
+           } 
            $self->{op};
        }
     }
+    sub mnemonic {
+       my $self=shift;
+       my $op=shift;
+       $self->{op}=$op if (defined($op));
+       $self->{op};
+    }
 }
 { package const;       # pick up constants, which start with $
     sub re {
@@ -145,14 +195,15 @@ my $current_function;
     sub out {
        my $self = shift;
 
-       if (!$masm) {
+       if ($gas) {
            # Solaris /usr/ccs/bin/as can't handle multiplications
            # in $self->{value}
-           $self->{value} =~ s/(?<![0-9a-f])(0[x0-9a-f]+)/oct($1)/egi;
+           $self->{value} =~ s/(?<![\w\$\.])(0x?[0-9a-f]+)/oct($1)/egi;
            $self->{value} =~ s/([0-9]+\s*[\*\/\%]\s*[0-9]+)/eval($1)/eg;
            sprintf "\$%s",$self->{value};
        } else {
-           $self->{value} =~ s/0x([0-9a-f]+)/0$1h/ig;
+           $self->{value} =~ s/(0b[0-1]+)/oct($1)/eig;
+           $self->{value} =~ s/0x([0-9a-f]+)/0$1h/ig if ($masm);
            sprintf "%s",$self->{value};
        }
     }
@@ -163,13 +214,19 @@ my $current_function;
        local   *line = shift;
        undef   $ret;
 
-       if ($line =~ /^([^\(,]*)\(([%\w,]+)\)/) {
-           $self->{label} = $1;
-           ($self->{base},$self->{index},$self->{scale})=split(/,/,$2);
+       # optional * ---vvv--- appears in indirect jmp/call
+       if ($line =~ /^(\*?)([^\(,]*)\(([%\w,]+)\)/) {
+           $self->{asterisk} = $1;
+           $self->{label} = $2;
+           ($self->{base},$self->{index},$self->{scale})=split(/,/,$3);
            $self->{scale} = 1 if (!defined($self->{scale}));
            $ret = $self;
            $line = substr($line,@+[0]); $line =~ s/^\s+//;
 
+           if ($win64 && $self->{label} =~ s/\@GOTPCREL//) {
+               die if (opcode->mnemonic() ne "mov");
+               opcode->mnemonic("lea");
+           }
            $self->{base}  =~ s/^%//;
            $self->{index} =~ s/^%// if (defined($self->{index}));
        }
@@ -180,44 +237,50 @@ my $current_function;
        my $self = shift;
        my $sz = shift;
 
+       $self->{label} =~ s/([_a-z][_a-z0-9]*)/$globals{$1} or $1/gei;
+       $self->{label} =~ s/\.L/$decor/g;
+
        # Silently convert all EAs to 64-bit. This is required for
        # elder GNU assembler and results in more compact code,
        # *but* most importantly AES module depends on this feature!
        $self->{index} =~ s/^[er](.?[0-9xpi])[d]?$/r\1/;
        $self->{base}  =~ s/^[er](.?[0-9xpi])[d]?$/r\1/;
 
-       if (!$masm) {
+       if ($gas) {
            # Solaris /usr/ccs/bin/as can't handle multiplications
-           # in $self->{label}
+           # in $self->{label}, new gas requires sign extension...
            use integer;
-           $self->{label} =~ s/(?<![0-9a-f])(0[x0-9a-f]+)/oct($1)/egi;
+           $self->{label} =~ s/(?<![\w\$\.])(0x?[0-9a-f]+)/oct($1)/egi;
            $self->{label} =~ s/([0-9]+\s*[\*\/\%]\s*[0-9]+)/eval($1)/eg;
            $self->{label} =~ s/([0-9]+)/$1<<32>>32/eg;
+           $self->{label} =~ s/^___imp_/__imp__/   if ($flavour eq "mingw64");
 
            if (defined($self->{index})) {
-               sprintf "%s(%%%s,%%%s,%d)",
+               sprintf "%s%s(%%%s,%%%s,%d)",$self->{asterisk},
                                        $self->{label},$self->{base},
                                        $self->{index},$self->{scale};
            } else {
-               sprintf "%s(%%%s)",     $self->{label},$self->{base};
+               sprintf "%s%s(%%%s)",   $self->{asterisk},$self->{label},$self->{base};
            }
        } else {
-           %szmap = ( b=>"BYTE", w=>"WORD", l=>"DWORD", q=>"QWORD" );
+           %szmap = ( b=>"BYTE$PTR", w=>"WORD$PTR", l=>"DWORD$PTR", q=>"QWORD$PTR" );
 
            $self->{label} =~ s/\./\$/g;
-           $self->{label} =~ s/0x([0-9a-f]+)/0$1h/ig;
+           $self->{label} =~ s/(?<![\w\$\.])0x([0-9a-f]+)/0$1h/ig;
            $self->{label} = "($self->{label})" if ($self->{label} =~ /[\*\+\-\/]/);
+           $sz="q" if ($self->{asterisk});
 
            if (defined($self->{index})) {
-               sprintf "%s PTR %s[%s*%d+%s]",$szmap{$sz},
-                                       $self->{label},
+               sprintf "%s[%s%s*%d+%s]",$szmap{$sz},
+                                       $self->{label}?"$self->{label}+":"",
                                        $self->{index},$self->{scale},
                                        $self->{base};
            } elsif ($self->{base} eq "rip") {
-               sprintf "%s PTR %s",$szmap{$sz},$self->{label};
+               sprintf "%s[%s]",$szmap{$sz},$self->{label};
            } else {
-               sprintf "%s PTR %s[%s]",$szmap{$sz},
-                                       $self->{label},$self->{base};
+               sprintf "%s[%s%s]",$szmap{$sz},
+                                       $self->{label}?"$self->{label}+":"",
+                                       $self->{base};
            }
        }
     }
@@ -229,9 +292,11 @@ my $current_function;
        local   *line = shift;
        undef   $ret;
 
-       if ($line =~ /^%(\w+)/) {
+       # optional * ---vvv--- appears in indirect jmp/call
+       if ($line =~ /^(\*?)%(\w+)/) {
            bless $self,$class;
-           $self->{value} = $1;
+           $self->{asterisk} = $1;
+           $self->{value} = $2;
            $ret = $self;
            $line = substr($line,@+[0]); $line =~ s/^\s+//;
        }
@@ -254,7 +319,8 @@ my $current_function;
     }
     sub out {
        my $self = shift;
-       sprintf $masm?"%s":"%%%s",$self->{value};
+       if ($gas)       { sprintf "%s%%%s",$self->{asterisk},$self->{value}; }
+       else            { $self->{value}; }
     }
 }
 { package label;       # pick up labels, which end with :
@@ -263,37 +329,63 @@ my $current_function;
        local   *line = shift;
        undef   $ret;
 
-       if ($line =~ /(^[\.\w]+\:)/) {
+       if ($line =~ /(^[\.\w]+)\:/) {
            $self->{value} = $1;
            $ret = $self;
            $line = substr($line,@+[0]); $line =~ s/^\s+//;
 
-           $self->{value} =~ s/\.L/\$L/ if ($masm);
+           $self->{value} =~ s/^\.L/$decor/;
        }
        $ret;
     }
     sub out {
        my $self = shift;
 
-       if (!$masm) {
-           $self->{value};
-       } elsif ($self->{value} ne "$current_function->{name}:") {
-           $self->{value};
-       } elsif ($current_function->{abi} eq "svr4") {
-           my $func =  "$current_function->{name}      PROC\n".
-                       "       mov     QWORD PTR 8[rsp],rdi\t;WIN64 prologue\n".
-                       "       mov     QWORD PTR 16[rsp],rsi\n";
+       if ($gas) {
+           my $func = ($globals{$self->{value}} or $self->{value}) . ":";
+           if ($win64  &&
+                       $current_function->{name} eq $self->{value} &&
+                       $current_function->{abi} eq "svr4") {
+               $func .= "\n";
+               $func .= "      movq    %rdi,8(%rsp)\n";
+               $func .= "      movq    %rsi,16(%rsp)\n";
+               $func .= "      movq    %rsp,%rax\n";
+               $func .= "${decor}SEH_begin_$current_function->{name}:\n";
+               my $narg = $current_function->{narg};
+               $narg=6 if (!defined($narg));
+               $func .= "      movq    %rcx,%rdi\n" if ($narg>0);
+               $func .= "      movq    %rdx,%rsi\n" if ($narg>1);
+               $func .= "      movq    %r8,%rdx\n"  if ($narg>2);
+               $func .= "      movq    %r9,%rcx\n"  if ($narg>3);
+               $func .= "      movq    40(%rsp),%r8\n" if ($narg>4);
+               $func .= "      movq    48(%rsp),%r9\n" if ($narg>5);
+           }
+           $func;
+       } elsif ($self->{value} ne "$current_function->{name}") {
+           $self->{value} .= ":" if ($masm && $ret!~m/^\$/);
+           $self->{value} . ":";
+       } elsif ($win64 && $current_function->{abi} eq "svr4") {
+           my $func =  "$current_function->{name}" .
+                       ($nasm ? ":" : "\tPROC $current_function->{scope}") .
+                       "\n";
+           $func .= "  mov     QWORD${PTR}[8+rsp],rdi\t;WIN64 prologue\n";
+           $func .= "  mov     QWORD${PTR}[16+rsp],rsi\n";
+           $func .= "  mov     rax,rsp\n";
+           $func .= "${decor}SEH_begin_$current_function->{name}:";
+           $func .= ":" if ($masm);
+           $func .= "\n";
            my $narg = $current_function->{narg};
            $narg=6 if (!defined($narg));
            $func .= "  mov     rdi,rcx\n" if ($narg>0);
            $func .= "  mov     rsi,rdx\n" if ($narg>1);
            $func .= "  mov     rdx,r8\n"  if ($narg>2);
            $func .= "  mov     rcx,r9\n"  if ($narg>3);
-           $func .= "  mov     r8,QWORD PTR 40[rsp]\n" if ($narg>4);
-           $func .= "  mov     r9,QWORD PTR 48[rsp]\n" if ($narg>5);
+           $func .= "  mov     r8,QWORD${PTR}[40+rsp]\n" if ($narg>4);
+           $func .= "  mov     r9,QWORD${PTR}[48+rsp]\n" if ($narg>5);
            $func .= "\n";
        } else {
-          "$current_function->{name}   PROC";
+          "$current_function->{name}".
+                       ($nasm ? ":" : "\tPROC $current_function->{scope}");
        }
     }
 }
@@ -308,13 +400,19 @@ my $current_function;
            $ret = $self;
            $line = substr($line,@+[0]); $line =~ s/^\s+//;
 
-           $self->{value} =~ s/\.L/\$L/g if ($masm);
+           $self->{value} =~ s/\@PLT// if (!$elf);
+           $self->{value} =~ s/([_a-z][_a-z0-9]*)/$globals{$1} or $1/gei;
+           $self->{value} =~ s/\.L/$decor/g;
        }
        $ret;
     }
     sub out {
        my $self = shift;
-       $self->{value};
+       if ($nasm && opcode->mnemonic()=~m/^j/) {
+           "NEAR ".$self->{value};
+       } else {
+           $self->{value};
+       }
     }
 }
 { package directive;   # pick up directives, which start with .
@@ -334,89 +432,185 @@ my $current_function;
                        "%r14"=>0x01358d4c,     "%r15"=>0x013d8d4c      );
 
        if ($line =~ /^\s*(\.\w+)/) {
-           if (!$masm) {
-               $self->{value} = $1;
-               $line =~ s/\@abi\-omnipotent/\@function/;
-               $line =~ s/\@function.*/\@function/;
-               if ($line =~ /\.picmeup\s+(%r[\w]+)/i) {
-                   $self->{value} = sprintf "\t.long\t0x%x,0x90000000",$opcode{$1};
-               } elsif ($line =~ /\.asciz\s+"(.*)"$/) {
-                   $self->{value} = ".byte\t".join(",",unpack("C*",$1),0);
-               } elsif ($line =~ /\.extern/) {
-                   $self->{value} = ""; # swallow extern
-               } else {
-                   $self->{value} = $line;
-               }
-               $line = "";
-               return $self;
-           }
-
            $dir = $1;
            $ret = $self;
            undef $self->{value};
            $line = substr($line,@+[0]); $line =~ s/^\s+//;
+
            SWITCH: for ($dir) {
-               /\.(text)/
-                           && do { my $v=undef;
-                                   $v="$current_segment\tENDS\n" if ($current_segment);
-                                   $current_segment = "_$1\$";
-                                   $current_segment =~ tr/[a-z]/[A-Z]/;
-                                   $v.="$current_segment\tSEGMENT ";
-                                   $v.=$masm>=$masmref ? "ALIGN(64)" : "PAGE";
-                                   $v.=" 'CODE'";
-                                   $self->{value} = $v;
+               /\.picmeup/ && do { if ($line =~ /(%r[\w]+)/i) {
+                                       $dir="\t.long";
+                                       $line=sprintf "0x%x,0x90000000",$opcode{$1};
+                                   }
+                                   last;
+                                 };
+               /\.global|\.globl|\.extern/
+                           && do { $globals{$line} = $prefix . $line;
+                                   $line = $globals{$line} if ($prefix);
                                    last;
                                  };
-               /\.extern/  && do { $self->{value} = "EXTRN\t".$line.":BYTE"; last;  };
-               /\.globl/   && do { $self->{value} = "PUBLIC\t".$line; last; };
                /\.type/    && do { ($sym,$type,$narg) = split(',',$line);
                                    if ($type eq "\@function") {
                                        undef $current_function;
                                        $current_function->{name} = $sym;
                                        $current_function->{abi}  = "svr4";
                                        $current_function->{narg} = $narg;
+                                       $current_function->{scope} = defined($globals{$sym})?"PUBLIC":"PRIVATE";
                                    } elsif ($type eq "\@abi-omnipotent") {
                                        undef $current_function;
                                        $current_function->{name} = $sym;
+                                       $current_function->{scope} = defined($globals{$sym})?"PUBLIC":"PRIVATE";
+                                   }
+                                   $line =~ s/\@abi\-omnipotent/\@function/;
+                                   $line =~ s/\@function.*/\@function/;
+                                   last;
+                                 };
+               /\.asciz/   && do { if ($line =~ /^"(.*)"$/) {
+                                       $dir  = ".byte";
+                                       $line = join(",",unpack("C*",$1),0);
                                    }
                                    last;
                                  };
+               /\.rva|\.long|\.quad/
+                           && do { $line =~ s/([_a-z][_a-z0-9]*)/$globals{$1} or $1/gei;
+                                   $line =~ s/\.L/$decor/g;
+                                   last;
+                                 };
+           }
+
+           if ($gas) {
+               $self->{value} = $dir . "\t" . $line;
+
+               if ($dir =~ /\.extern/) {
+                   $self->{value} = ""; # swallow extern
+               } elsif (!$elf && $dir =~ /\.type/) {
+                   $self->{value} = "";
+                   $self->{value} = ".def\t" . ($globals{$1} or $1) . ";\t" .
+                               (defined($globals{$1})?".scl 2;":".scl 3;") .
+                               "\t.type 32;\t.endef"
+                               if ($win64 && $line =~ /([^,]+),\@function/);
+               } elsif (!$elf && $dir =~ /\.size/) {
+                   $self->{value} = "";
+                   if (defined($current_function)) {
+                       $self->{value} .= "${decor}SEH_end_$current_function->{name}:"
+                               if ($win64 && $current_function->{abi} eq "svr4");
+                       undef $current_function;
+                   }
+               } elsif (!$elf && $dir =~ /\.align/) {
+                   $self->{value} = ".p2align\t" . (log($line)/log(2));
+               } elsif ($dir eq ".section") {
+                   $current_segment=$line;
+                   if (!$elf && $current_segment eq ".init") {
+                       if      ($flavour eq "macosx")  { $self->{value} = ".mod_init_func"; }
+                       elsif   ($flavour eq "mingw64") { $self->{value} = ".section\t.ctors"; }
+                   }
+               } elsif ($dir =~ /\.(text|data)/) {
+                   $current_segment=".$1";
+               }
+               $line = "";
+               return $self;
+           }
+
+           # non-gas case or nasm/masm
+           SWITCH: for ($dir) {
+               /\.text/    && do { my $v=undef;
+                                   if ($nasm) {
+                                       $v="section     .text code align=64\n";
+                                   } else {
+                                       $v="$current_segment\tENDS\n" if ($current_segment);
+                                       $current_segment = ".text\$";
+                                       $v.="$current_segment\tSEGMENT ";
+                                       $v.=$masm>=$masmref ? "ALIGN(64)" : "PAGE";
+                                       $v.=" 'CODE'";
+                                   }
+                                   $self->{value} = $v;
+                                   last;
+                                 };
+               /\.data/    && do { my $v=undef;
+                                   if ($nasm) {
+                                       $v="section     .data data align=8\n";
+                                   } else {
+                                       $v="$current_segment\tENDS\n" if ($current_segment);
+                                       $current_segment = "_DATA";
+                                       $v.="$current_segment\tSEGMENT";
+                                   }
+                                   $self->{value} = $v;
+                                   last;
+                                 };
+               /\.section/ && do { my $v=undef;
+                                   $line =~ s/([^,]*).*/$1/;
+                                   $line = ".CRT\$XCU" if ($line eq ".init");
+                                   if ($nasm) {
+                                       $v="section     $line";
+                                       if ($line=~/\.([px])data/) {
+                                           $v.=" rdata align=";
+                                           $v.=$1 eq "p"? 4 : 8;
+                                       } elsif ($line=~/\.CRT\$/i) {
+                                           $v.=" rdata align=8";
+                                       }
+                                   } else {
+                                       $v="$current_segment\tENDS\n" if ($current_segment);
+                                       $v.="$line\tSEGMENT";
+                                       if ($line=~/\.([px])data/) {
+                                           $v.=" READONLY";
+                                           $v.=" ALIGN(".($1 eq "p" ? 4 : 8).")" if ($masm>=$masmref);
+                                       } elsif ($line=~/\.CRT\$/i) {
+                                           $v.=" READONLY DWORD";
+                                       }
+                                   }
+                                   $current_segment = $line;
+                                   $self->{value} = $v;
+                                   last;
+                                 };
+               /\.extern/  && do { $self->{value}  = "EXTERN\t".$line;
+                                   $self->{value} .= ":NEAR" if ($masm);
+                                   last;
+                                 };
+               /\.globl|.global/
+                           && do { $self->{value}  = $masm?"PUBLIC":"global";
+                                   $self->{value} .= "\t".$line;
+                                   last;
+                                 };
                /\.size/    && do { if (defined($current_function)) {
-                                       $self->{value}="$current_function->{name}\tENDP";
+                                       undef $self->{value};
+                                       if ($current_function->{abi} eq "svr4") {
+                                           $self->{value}="${decor}SEH_end_$current_function->{name}:";
+                                           $self->{value}.=":\n" if($masm);
+                                       }
+                                       $self->{value}.="$current_function->{name}\tENDP" if($masm);
                                        undef $current_function;
                                    }
                                    last;
                                  };
                /\.align/   && do { $self->{value} = "ALIGN\t".$line; last; };
-               /\.(byte|value|long|quad)/
-                           && do { my @arr = split(',',$line);
-                                   my $sz  = substr($1,0,1);
+               /\.(value|long|rva|quad)/
+                           && do { my $sz  = substr($1,0,1);
+                                   my @arr = split(/,\s*/,$line);
                                    my $last = pop(@arr);
                                    my $conv = sub  {   my $var=shift;
-                                                       if ($var=~s/0x([0-9a-f]+)/0$1h/i) { $var; }
-                                                       else { sprintf"0%Xh",$var; }
+                                                       $var=~s/^(0b[0-1]+)/oct($1)/eig;
+                                                       $var=~s/^0x([0-9a-f]+)/0$1h/ig if ($masm);
+                                                       if ($sz eq "D" && ($current_segment=~/.[px]data/ || $dir eq ".rva"))
+                                                       { $var=~s/([_a-z\$\@][_a-z0-9\$\@]*)/$nasm?"$1 wrt ..imagebase":"imagerel $1"/egi; }
+                                                       $var;
                                                    };  
 
-                                   $sz =~ tr/bvlq/BWDQ/;
+                                   $sz =~ tr/bvlrq/BWDDQ/;
                                    $self->{value} = "\tD$sz\t";
                                    for (@arr) { $self->{value} .= &$conv($_).","; }
                                    $self->{value} .= &$conv($last);
                                    last;
                                  };
-               /\.picmeup/ && do { $self->{value} = sprintf"\tDD\t 0%Xh,090000000h",$opcode{$line};
-                                   last;
-                                 };
-               /\.asciz/   && do { if ($line =~ /^"(.*)"$/) {
-                                       my @str=unpack("C*",$1);
-                                       push @str,0;
-                                       while ($#str>15) {
-                                           $self->{value}.="DB\t"
-                                               .join(",",@str[0..15])."\n";
-                                           foreach (0..15) { shift @str; }
-                                       }
+               /\.byte/    && do { my @str=split(/,\s*/,$line);
+                                   map(s/(0b[0-1]+)/oct($1)/eig,@str);
+                                   map(s/0x([0-9a-f]+)/0$1h/ig,@str) if ($masm);       
+                                   while ($#str>15) {
                                        $self->{value}.="DB\t"
-                                               .join(",",@str) if (@str);
+                                               .join(",",@str[0..15])."\n";
+                                       foreach (0..15) { shift @str; }
                                    }
+                                   $self->{value}.="DB\t"
+                                               .join(",",@str) if (@str);
                                    last;
                                  };
            }
@@ -431,6 +625,15 @@ my $current_function;
     }
 }
 
+if ($nasm) {
+    print <<___;
+default        rel
+___
+} elsif ($masm) {
+    print <<___;
+OPTION DOTNAME
+___
+}
 while($line=<>) {
 
     chomp($line);
@@ -441,43 +644,42 @@ while($line=<>) {
 
     undef $label;
     undef $opcode;
-    undef $dst;
-    undef $src;
     undef $sz;
+    undef @args;
 
     if ($label=label->re(\$line))      { print $label->out(); }
 
     if (directive->re(\$line)) {
        printf "%s",directive->out();
-    } elsif ($opcode=opcode->re(\$line)) { ARGUMENT: {
-
-       if ($src=register->re(\$line))  { opcode->size($src->size()); }
-       elsif ($src=const->re(\$line))  { }
-       elsif ($src=ea->re(\$line))     { }
-       elsif ($src=expr->re(\$line))   { }
+    } elsif ($opcode=opcode->re(\$line)) { ARGUMENT: while (1) {
+       my $arg;
 
-       last ARGUMENT if ($line !~ /^,/);
+       if ($arg=register->re(\$line))  { opcode->size($arg->size()); }
+       elsif ($arg=const->re(\$line))  { }
+       elsif ($arg=ea->re(\$line))     { }
+       elsif ($arg=expr->re(\$line))   { }
+       else                            { last ARGUMENT; }
 
-       $line = substr($line,1); $line =~ s/^\s+//;
+       push @args,$arg;
 
-       if ($dst=register->re(\$line))  { opcode->size($dst->size()); }
-       elsif ($dst=const->re(\$line))  { }
-       elsif ($dst=ea->re(\$line))     { }
+       last ARGUMENT if ($line !~ /^,/);
 
+       $line =~ s/^,\s*//;
        } # ARGUMENT:
 
        $sz=opcode->size();
 
-       if (defined($dst)) {
-           if (!$masm) {
-               printf "\t%s\t%s,%s",   $opcode->out($dst->size()),
-                                       $src->out($sz),$dst->out($sz);
+       if ($#args>=0) {
+           my $insn;
+           if ($gas) {
+               $insn = $opcode->out($#args>=1?$args[$#args]->size():$sz);
            } else {
-               printf "\t%s\t%s,%s",   $opcode->out(),
-                                       $dst->out($sz),$src->out($sz);
+               $insn = $opcode->out();
+               $insn .= $sz if (map($_->out() =~ /x?mm/,@args));
+               @args = reverse(@args);
+               undef $sz if ($nasm && $opcode->mnemonic() eq "lea");
            }
-       } elsif (defined($src)) {
-           printf "\t%s\t%s",$opcode->out(),$src->out($sz);
+           printf "\t%s\t%s",$insn,join(",",map($_->out($sz),@args));
        } else {
            printf "\t%s",$opcode->out();
        }
@@ -486,11 +688,12 @@ while($line=<>) {
     print $line,"\n";
 }
 
-print "\n$current_segment\tENDS\nEND\n" if ($masm);
+print "\n$current_segment\tENDS\n"     if ($current_segment && $masm);
+print "END\n"                          if ($masm);
 
 close STDOUT;
 
-#################################################
+\f#################################################
 # Cross-reference x86_64 ABI "card"
 #
 #              Unix            Win64
@@ -554,3 +757,161 @@ close STDOUT;
 #      movq    16(%rsp),%rsi
 # endif
 #      ret
+#
+\f#################################################
+# Win64 SEH, Structured Exception Handling.
+#
+# Unlike on Unix systems(*) lack of Win64 stack unwinding information
+# has undesired side-effect at run-time: if an exception is raised in
+# assembler subroutine such as those in question (basically we're
+# referring to segmentation violations caused by malformed input
+# parameters), the application is briskly terminated without invoking
+# any exception handlers, most notably without generating memory dump
+# or any user notification whatsoever. This poses a problem. It's
+# possible to address it by registering custom language-specific
+# handler that would restore processor context to the state at
+# subroutine entry point and return "exception is not handled, keep
+# unwinding" code. Writing such handler can be a challenge... But it's
+# doable, though requires certain coding convention. Consider following
+# snippet:
+#
+# .type        function,@function
+# function:
+#      movq    %rsp,%rax       # copy rsp to volatile register
+#      pushq   %r15            # save non-volatile registers
+#      pushq   %rbx
+#      pushq   %rbp
+#      movq    %rsp,%r11
+#      subq    %rdi,%r11       # prepare [variable] stack frame
+#      andq    $-64,%r11
+#      movq    %rax,0(%r11)    # check for exceptions
+#      movq    %r11,%rsp       # allocate [variable] stack frame
+#      movq    %rax,0(%rsp)    # save original rsp value
+# magic_point:
+#      ...
+#      movq    0(%rsp),%rcx    # pull original rsp value
+#      movq    -24(%rcx),%rbp  # restore non-volatile registers
+#      movq    -16(%rcx),%rbx
+#      movq    -8(%rcx),%r15
+#      movq    %rcx,%rsp       # restore original rsp
+#      ret
+# .size function,.-function
+#
+# The key is that up to magic_point copy of original rsp value remains
+# in chosen volatile register and no non-volatile register, except for
+# rsp, is modified. While past magic_point rsp remains constant till
+# the very end of the function. In this case custom language-specific
+# exception handler would look like this:
+#
+# EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
+#              CONTEXT *context,DISPATCHER_CONTEXT *disp)
+# {    ULONG64 *rsp = (ULONG64 *)context->Rax;
+#      if (context->Rip >= magic_point)
+#      {   rsp = ((ULONG64 **)context->Rsp)[0];
+#          context->Rbp = rsp[-3];
+#          context->Rbx = rsp[-2];
+#          context->R15 = rsp[-1];
+#      }
+#      context->Rsp = (ULONG64)rsp;
+#      context->Rdi = rsp[1];
+#      context->Rsi = rsp[2];
+#
+#      memcpy (disp->ContextRecord,context,sizeof(CONTEXT));
+#      RtlVirtualUnwind(UNW_FLAG_NHANDLER,disp->ImageBase,
+#              dips->ControlPc,disp->FunctionEntry,disp->ContextRecord,
+#              &disp->HandlerData,&disp->EstablisherFrame,NULL);
+#      return ExceptionContinueSearch;
+# }
+#
+# It's appropriate to implement this handler in assembler, directly in
+# function's module. In order to do that one has to know members'
+# offsets in CONTEXT and DISPATCHER_CONTEXT structures and some constant
+# values. Here they are:
+#
+#      CONTEXT.Rax                             120
+#      CONTEXT.Rcx                             128
+#      CONTEXT.Rdx                             136
+#      CONTEXT.Rbx                             144
+#      CONTEXT.Rsp                             152
+#      CONTEXT.Rbp                             160
+#      CONTEXT.Rsi                             168
+#      CONTEXT.Rdi                             176
+#      CONTEXT.R8                              184
+#      CONTEXT.R9                              192
+#      CONTEXT.R10                             200
+#      CONTEXT.R11                             208
+#      CONTEXT.R12                             216
+#      CONTEXT.R13                             224
+#      CONTEXT.R14                             232
+#      CONTEXT.R15                             240
+#      CONTEXT.Rip                             248
+#      CONTEXT.Xmm6                            512
+#      sizeof(CONTEXT)                         1232
+#      DISPATCHER_CONTEXT.ControlPc            0
+#      DISPATCHER_CONTEXT.ImageBase            8
+#      DISPATCHER_CONTEXT.FunctionEntry        16
+#      DISPATCHER_CONTEXT.EstablisherFrame     24
+#      DISPATCHER_CONTEXT.TargetIp             32
+#      DISPATCHER_CONTEXT.ContextRecord        40
+#      DISPATCHER_CONTEXT.LanguageHandler      48
+#      DISPATCHER_CONTEXT.HandlerData          56
+#      UNW_FLAG_NHANDLER                       0
+#      ExceptionContinueSearch                 1
+#
+# In order to tie the handler to the function one has to compose
+# couple of structures: one for .xdata segment and one for .pdata.
+#
+# UNWIND_INFO structure for .xdata segment would be
+#
+# function_unwind_info:
+#      .byte   9,0,0,0
+#      .rva    handler
+#
+# This structure designates exception handler for a function with
+# zero-length prologue, no stack frame or frame register.
+#
+# To facilitate composing of .pdata structures, auto-generated "gear"
+# prologue copies rsp value to rax and denotes next instruction with
+# .LSEH_begin_{function_name} label. This essentially defines the SEH
+# styling rule mentioned in the beginning. Position of this label is
+# chosen in such manner that possible exceptions raised in the "gear"
+# prologue would be accounted to caller and unwound from latter's frame.
+# End of function is marked with respective .LSEH_end_{function_name}
+# label. To summarize, .pdata segment would contain
+#
+#      .rva    .LSEH_begin_function
+#      .rva    .LSEH_end_function
+#      .rva    function_unwind_info
+#
+# Reference to functon_unwind_info from .xdata segment is the anchor.
+# In case you wonder why references are 32-bit .rvas and not 64-bit
+# .quads. References put into these two segments are required to be
+# *relative* to the base address of the current binary module, a.k.a.
+# image base. No Win64 module, be it .exe or .dll, can be larger than
+# 2GB and thus such relative references can be and are accommodated in
+# 32 bits.
+#
+# Having reviewed the example function code, one can argue that "movq
+# %rsp,%rax" above is redundant. It is not! Keep in mind that on Unix
+# rax would contain an undefined value. If this "offends" you, use
+# another register and refrain from modifying rax till magic_point is
+# reached, i.e. as if it was a non-volatile register. If more registers
+# are required prior [variable] frame setup is completed, note that
+# nobody says that you can have only one "magic point." You can
+# "liberate" non-volatile registers by denoting last stack off-load
+# instruction and reflecting it in finer grade unwind logic in handler.
+# After all, isn't it why it's called *language-specific* handler...
+#
+# Attentive reader can notice that exceptions would be mishandled in
+# auto-generated "gear" epilogue. Well, exception effectively can't
+# occur there, because if memory area used by it was subject to
+# segmentation violation, then it would be raised upon call to the
+# function (and as already mentioned be accounted to caller, which is
+# not a problem). If you're still not comfortable, then define tail
+# "magic point" just prior ret instruction and have handler treat it...
+#
+# (*)  Note that we're talking about run-time, not debug-time. Lack of
+#      unwind information makes debugging hard on both Windows and
+#      Unix. "Unlike" referes to the fact that on Unix signal handler
+#      will always be invoked, core dumped and appropriate exit code
+#      returned to parent (for user notification).
index 5979122..28080ca 100644 (file)
-#!/usr/local/bin/perl
+#!/usr/bin/env perl
 
 # require 'x86asm.pl';
-# &asm_init("cpp","des-586.pl");
-# XXX
-# XXX
-# main'asm_finish
-
-sub main'asm_finish
-       {
-       &file_end();
-       &asm_finish_cpp() if $cpp;
-       print &asm_get_output();
-       }
-
-sub main'asm_init
-       {
-       ($type,$fn,$i386)=@_;
-       $filename=$fn;
-
-       $elf=$cpp=$coff=$aout=$win32=$netware=$mwerks=0;
-       if (    ($type eq "elf"))
-               { $elf=1; require "x86unix.pl"; }
-       elsif ( ($type eq "a.out"))
-               { $aout=1; require "x86unix.pl"; }
-       elsif ( ($type eq "coff" or $type eq "gaswin"))
-               { $coff=1; require "x86unix.pl"; }
-       elsif ( ($type eq "cpp"))
-               { $cpp=1; require "x86unix.pl"; }
-       elsif ( ($type eq "win32"))
-               { $win32=1; require "x86ms.pl"; }
-       elsif ( ($type eq "win32n"))
-               { $win32=1; require "x86nasm.pl"; }
-       elsif ( ($type eq "nw-nasm"))
-               { $netware=1; require "x86nasm.pl"; }
-       elsif ( ($type eq "nw-mwasm"))
-               { $netware=1; $mwerks=1; require "x86nasm.pl"; }
-       else
-               {
-               print STDERR <<"EOF";
+# &asm_init(<flavor>,"des-586.pl"[,$i386only]);
+# &function_begin("foo");
+# ...
+# &function_end("foo");
+# &asm_finish
+
+$out=();
+$i386=0;
+
+# AUTOLOAD is this context has quite unpleasant side effect, namely
+# that typos in function calls effectively go to assembler output,
+# but on the pros side we don't have to implement one subroutine per
+# each opcode...
+sub ::AUTOLOAD
+{ my $opcode = $AUTOLOAD;
+
+    die "more than 4 arguments passed to $opcode" if ($#_>3);
+
+    $opcode =~ s/.*:://;
+    if    ($opcode =~ /^push/) { $stack+=4; }
+    elsif ($opcode =~ /^pop/)  { $stack-=4; }
+
+    &generic($opcode,@_) or die "undefined subroutine \&$AUTOLOAD";
+}
+
+sub ::emit
+{ my $opcode=shift;
+
+    if ($#_==-1)    { push(@out,"\t$opcode\n");                                }
+    else            { push(@out,"\t$opcode\t".join(',',@_)."\n");      }
+}
+
+sub ::LB
+{   $_[0] =~ m/^e?([a-d])x$/o or die "$_[0] does not have a 'low byte'";
+  $1."l";
+}
+sub ::HB
+{   $_[0] =~ m/^e?([a-d])x$/o or die "$_[0] does not have a 'high byte'";
+  $1."h";
+}
+sub ::stack_push{ my $num=$_[0]*4; $stack+=$num; &sub("esp",$num);     }
+sub ::stack_pop        { my $num=$_[0]*4; $stack-=$num; &add("esp",$num);      }
+sub ::blindpop { &pop($_[0]); $stack+=4;                               }
+sub ::wparam   { &DWP($stack+4*$_[0],"esp");                           }
+sub ::swtmp    { &DWP(4*$_[0],"esp");                                  }
+
+sub ::bswap
+{   if ($i386) # emulate bswap for i386
+    {  &comment("bswap @_");
+       &xchg(&HB(@_),&LB(@_));
+       &ror (@_,16);
+       &xchg(&HB(@_),&LB(@_));
+    }
+    else
+    {  &generic("bswap",@_);   }
+}
+# These are made-up opcodes introduced over the years essentially
+# by ignorance, just alias them to real ones...
+sub ::movb     { &mov(@_);     }
+sub ::xorb     { &xor(@_);     }
+sub ::rotl     { &rol(@_);     }
+sub ::rotr     { &ror(@_);     }
+sub ::exch     { &xchg(@_);    }
+sub ::halt     { &hlt;         }
+sub ::movz     { &movzx(@_);   }
+sub ::pushf    { &pushfd;      }
+sub ::popf     { &popfd;       }
+
+# 3 argument instructions
+sub ::movq
+{ my($p1,$p2,$optimize)=@_;
+
+    if ($optimize && $p1=~/^mm[0-7]$/ && $p2=~/^mm[0-7]$/)
+    # movq between mmx registers can sink Intel CPUs
+    {  &::pshufw($p1,$p2,0xe4);                }
+    else
+    {  &::generic("movq",@_);                  }
+}
+
+# label management
+$lbdecor="L";          # local label decoration, set by package
+$label="000";
+
+sub ::islabel          # see is argument is a known label
+{ my $i;
+    foreach $i (values %label) { return $i if ($i eq $_[0]); }
+  $label{$_[0]};       # can be undef
+}
+
+sub ::label            # instantiate a function-scope label
+{   if (!defined($label{$_[0]}))
+    {  $label{$_[0]}="${lbdecor}${label}${_[0]}"; $label++;   }
+  $label{$_[0]};
+}
+
+sub ::LABEL            # instantiate a file-scope label
+{   $label{$_[0]}=$_[1] if (!defined($label{$_[0]}));
+  $label{$_[0]};
+}
+
+sub ::static_label     { &::LABEL($_[0],$lbdecor.$_[0]); }
+
+sub ::set_label_B      { push(@out,"@_:\n"); }
+sub ::set_label
+{ my $label=&::label($_[0]);
+    &::align($_[1]) if ($_[1]>1);
+    &::set_label_B($label);
+  $label;
+}
+
+sub ::wipe_labels      # wipes function-scope labels
+{   foreach $i (keys %label)
+    {  delete $label{$i} if ($label{$i} =~ /^\Q${lbdecor}\E[0-9]{3}/); }
+}
+
+# subroutine management
+sub ::function_begin
+{   &function_begin_B(@_);
+    $stack=4;
+    &push("ebp");
+    &push("ebx");
+    &push("esi");
+    &push("edi");
+}
+
+sub ::function_end
+{   &pop("edi");
+    &pop("esi");
+    &pop("ebx");
+    &pop("ebp");
+    &ret();
+    &function_end_B(@_);
+    $stack=0;
+    &wipe_labels();
+}
+
+sub ::function_end_A
+{   &pop("edi");
+    &pop("esi");
+    &pop("ebx");
+    &pop("ebp");
+    &ret();
+    $stack+=16;        # readjust esp as if we didn't pop anything
+}
+
+sub ::asciz
+{ my @str=unpack("C*",shift);
+    push @str,0;
+    while ($#str>15) {
+       &data_byte(@str[0..15]);
+       foreach (0..15) { shift @str; }
+    }
+    &data_byte(@str) if (@str);
+}
+
+sub ::asm_finish
+{   &file_end();
+    print @out;
+}
+
+sub ::asm_init
+{ my ($type,$fn,$cpu)=@_;
+
+    $filename=$fn;
+    $i386=$cpu;
+
+    $elf=$cpp=$coff=$aout=$macosx=$win32=$netware=$mwerks=0;
+    if    (($type eq "elf"))
+    {  $elf=1;                 require "x86gas.pl";    }
+    elsif (($type eq "a\.out"))
+    {  $aout=1;                require "x86gas.pl";    }
+    elsif (($type eq "coff" or $type eq "gaswin"))
+    {  $coff=1;                require "x86gas.pl";    }
+    elsif (($type eq "win32n"))
+    {  $win32=1;               require "x86nasm.pl";   }
+    elsif (($type eq "nw-nasm"))
+    {  $netware=1;             require "x86nasm.pl";   }
+    #elsif (($type eq "nw-mwasm"))
+    #{ $netware=1; $mwerks=1;  require "x86nasm.pl";   }
+    elsif (($type eq "win32"))
+    {  $win32=1;               require "x86masm.pl";   }
+    elsif (($type eq "macosx"))
+    {  $aout=1; $macosx=1;     require "x86gas.pl";    }
+    else
+    {  print STDERR <<"EOF";
 Pick one target type from
        elf     - Linux, FreeBSD, Solaris x86, etc.
-       a.out   - OpenBSD, DJGPP, etc.
+       a.out   - DJGPP, elder OpenBSD, etc.
        coff    - GAS/COFF such as Win32 targets
-       win32   - Windows 95/Windows NT
        win32n  - Windows 95/Windows NT NASM format
        nw-nasm - NetWare NASM format
-       nw-mwasm- NetWare Metrowerks Assembler
+       macosx  - Mac OS X
 EOF
-               exit(1);
-               }
-
-       $pic=0;
-       for (@ARGV) {   $pic=1 if (/\-[fK]PIC/i);       }
-
-       &asm_init_output();
-
-&comment("Don't even think of reading this code");
-&comment("It was automatically generated by $filename");
-&comment("Which is a perl program used to generate the x86 assember for");
-&comment("any of ELF, a.out, COFF, Win32, ...");
-&comment("eric <eay\@cryptsoft.com>");
-&comment("");
-
-       $filename =~ s/\.pl$//;
-       &file($filename);
-       }
-
-sub asm_finish_cpp
-       {
-       return unless $cpp;
-
-       local($tmp,$i);
-       foreach $i (&get_labels())
-               {
-               $tmp.="#define $i _$i\n";
-               }
-       print <<"EOF";
-/* Run the C pre-processor over this file with one of the following defined
- * ELF - elf object files,
- * OUT - a.out object files,
- * BSDI - BSDI style a.out object files
- * SOL - Solaris style elf
- */
-
-#define TYPE(a,b)       .type   a,b
-#define SIZE(a,b)       .size   a,b
-
-#if defined(OUT) || (defined(BSDI) && !defined(ELF))
-$tmp
-#endif
-
-#ifdef OUT
-#define OK     1
-#define ALIGN  4
-#if defined(__CYGWIN__) || defined(__DJGPP__) || (__MINGW32__)
-#undef SIZE
-#undef TYPE
-#define SIZE(a,b)
-#define TYPE(a,b)      .def a; .scl 2; .type 32; .endef
-#endif /* __CYGWIN || __DJGPP */
-#endif
-
-#if defined(BSDI) && !defined(ELF)
-#define OK              1
-#define ALIGN           4
-#undef SIZE
-#undef TYPE
-#define SIZE(a,b)
-#define TYPE(a,b)
-#endif
-
-#if defined(ELF) || defined(SOL)
-#define OK              1
-#define ALIGN           16
-#endif
-
-#ifndef OK
-You need to define one of
-ELF - elf systems - linux-elf, NetBSD and DG-UX
-OUT - a.out systems - linux-a.out and FreeBSD
-SOL - solaris systems, which are elf with strange comment lines
-BSDI - a.out with a very primative version of as.
-#endif
-
-/* Let the Assembler begin :-) */
-EOF
-       }
+       exit(1);
+    }
+
+    $pic=0;
+    for (@ARGV) { $pic=1 if (/\-[fK]PIC/i); }
+
+    $filename =~ s/\.pl$//;
+    &file($filename);
+}
 
 1;
diff --git a/deps/openssl/openssl/crypto/perlasm/x86gas.pl b/deps/openssl/openssl/crypto/perlasm/x86gas.pl
new file mode 100644 (file)
index 0000000..6eab727
--- /dev/null
@@ -0,0 +1,247 @@
+#!/usr/bin/env perl
+
+package x86gas;
+
+*out=\@::out;
+
+$::lbdecor=$::aout?"L":".L";           # local label decoration
+$nmdecor=($::aout or $::coff)?"_":"";  # external name decoration
+
+$initseg="";
+
+$align=16;
+$align=log($align)/log(2) if ($::aout);
+$com_start="#" if ($::aout or $::coff);
+
+sub opsize()
+{ my $reg=shift;
+    if    ($reg =~ m/^%e/o)            { "l"; }
+    elsif ($reg =~ m/^%[a-d][hl]$/o)   { "b"; }
+    elsif ($reg =~ m/^%[xm]/o)         { undef; }
+    else                               { "w"; }
+}
+
+# swap arguments;
+# expand opcode with size suffix;
+# prefix numeric constants with $;
+sub ::generic
+{ my($opcode,@arg)=@_;
+  my($suffix,$dst,$src);
+
+    @arg=reverse(@arg);
+
+    for (@arg)
+    {  s/^(\*?)(e?[a-dsixphl]{2})$/$1%$2/o;    # gp registers
+       s/^([xy]?mm[0-7])$/%$1/o;               # xmm/mmx registers
+       s/^(\-?[0-9]+)$/\$$1/o;                 # constants
+       s/^(\-?0x[0-9a-f]+)$/\$$1/o;            # constants
+    }
+
+    $dst = $arg[$#arg]         if ($#arg>=0);
+    $src = $arg[$#arg-1]       if ($#arg>=1);
+    if    ($dst =~ m/^%/o)     { $suffix=&opsize($dst); }
+    elsif ($src =~ m/^%/o)     { $suffix=&opsize($src); }
+    else                       { $suffix="l";           }
+    undef $suffix if ($dst =~ m/^%[xm]/o || $src =~ m/^%[xm]/o);
+
+    if ($#_==0)                                { &::emit($opcode);             }
+    elsif ($opcode =~ m/^j/o && $#_==1)        { &::emit($opcode,@arg);        }
+    elsif ($opcode eq "call" && $#_==1)        { &::emit($opcode,@arg);        }
+    elsif ($opcode =~ m/^set/&& $#_==1)        { &::emit($opcode,@arg);        }
+    else                               { &::emit($opcode.$suffix,@arg);}
+
+  1;
+}
+#
+# opcodes not covered by ::generic above, mostly inconsistent namings...
+#
+sub ::movzx    { &::movzb(@_);                 }
+sub ::pushfd   { &::pushfl;                    }
+sub ::popfd    { &::popfl;                     }
+sub ::cpuid    { &::emit(".byte\t0x0f,0xa2");  }
+sub ::rdtsc    { &::emit(".byte\t0x0f,0x31");  }
+
+sub ::call     { &::emit("call",(&::islabel($_[0]) or "$nmdecor$_[0]")); }
+sub ::call_ptr { &::generic("call","*$_[0]");  }
+sub ::jmp_ptr  { &::generic("jmp","*$_[0]");   }
+
+*::bswap = sub { &::emit("bswap","%$_[0]");    } if (!$::i386);
+
+sub ::DWP
+{ my($addr,$reg1,$reg2,$idx)=@_;
+  my $ret="";
+
+    $addr =~ s/^\s+//;
+    # prepend global references with optional underscore
+    $addr =~ s/^([^\+\-0-9][^\+\-]*)/&::islabel($1) or "$nmdecor$1"/ige;
+
+    $reg1 = "%$reg1" if ($reg1);
+    $reg2 = "%$reg2" if ($reg2);
+
+    $ret .= $addr if (($addr ne "") && ($addr ne 0));
+
+    if ($reg2)
+    {  $idx!= 0 or $idx=1;
+       $ret .= "($reg1,$reg2,$idx)";
+    }
+    elsif ($reg1)
+    {  $ret .= "($reg1)";      }
+
+  $ret;
+}
+sub ::QWP      { &::DWP(@_);   }
+sub ::BP       { &::DWP(@_);   }
+sub ::BC       { @_;           }
+sub ::DWC      { @_;           }
+
+sub ::file
+{   push(@out,".file\t\"$_[0].s\"\n.text\n");  }
+
+sub ::function_begin_B
+{ my $func=shift;
+  my $global=($func !~ /^_/);
+  my $begin="${::lbdecor}_${func}_begin";
+
+    &::LABEL($func,$global?"$begin":"$nmdecor$func");
+    $func=$nmdecor.$func;
+
+    push(@out,".globl\t$func\n")       if ($global);
+    if ($::coff)
+    {  push(@out,".def\t$func;\t.scl\t".(3-$global).";\t.type\t32;\t.endef\n"); }
+    elsif (($::aout and !$::pic) or $::macosx)
+    { }
+    else
+    {  push(@out,".type        $func,\@function\n"); }
+    push(@out,".align\t$align\n");
+    push(@out,"$func:\n");
+    push(@out,"$begin:\n")             if ($global);
+    $::stack=4;
+}
+
+sub ::function_end_B
+{ my $func=shift;
+    push(@out,".size\t$nmdecor$func,.-".&::LABEL($func)."\n") if ($::elf);
+    $::stack=0;
+    &::wipe_labels();
+}
+
+sub ::comment
+       {
+       if (!defined($com_start) or $::elf)
+               {       # Regarding $::elf above...
+                       # GNU and SVR4 as'es use different comment delimiters,
+               push(@out,"\n");        # so we just skip ELF comments...
+               return;
+               }
+       foreach (@_)
+               {
+               if (/^\s*$/)
+                       { push(@out,"\n"); }
+               else
+                       { push(@out,"\t$com_start $_ $com_end\n"); }
+               }
+       }
+
+sub ::external_label
+{   foreach(@_) { &::LABEL($_,$nmdecor.$_); }   }
+
+sub ::public_label
+{   push(@out,".globl\t".&::LABEL($_[0],$nmdecor.$_[0])."\n");   }
+
+sub ::file_end
+{   if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out) {
+       my $tmp=".comm\t${nmdecor}OPENSSL_ia32cap_P,4";
+       if ($::elf)     { push (@out,"$tmp,4\n"); }
+       else            { push (@out,"$tmp\n"); }
+    }
+    if ($::macosx)
+    {  if (%non_lazy_ptr)
+       {   push(@out,".section __IMPORT,__pointers,non_lazy_symbol_pointers\n");
+           foreach $i (keys %non_lazy_ptr)
+           {   push(@out,"$non_lazy_ptr{$i}:\n.indirect_symbol\t$i\n.long\t0\n");   }
+       }
+    }
+    push(@out,$initseg) if ($initseg);
+}
+
+sub ::data_byte        {   push(@out,".byte\t".join(',',@_)."\n");   }
+sub ::data_word {   push(@out,".long\t".join(',',@_)."\n");   }
+
+sub ::align
+{ my $val=$_[0],$p2,$i;
+    if ($::aout)
+    {  for ($p2=0;$val!=0;$val>>=1) { $p2++; }
+       $val=$p2-1;
+       $val.=",0x90";
+    }
+    push(@out,".align\t$val\n");
+}
+
+sub ::picmeup
+{ my($dst,$sym,$base,$reflabel)=@_;
+
+    if ($::pic && ($::elf || $::aout))
+    {  if (!defined($base))
+       {   &::call(&::label("PIC_me_up"));
+           &::set_label("PIC_me_up");
+           &::blindpop($dst);
+           $base=$dst;
+           $reflabel=&::label("PIC_me_up");
+       }
+       if ($::macosx)
+       {   my $indirect=&::static_label("$nmdecor$sym\$non_lazy_ptr");
+           &::mov($dst,&::DWP("$indirect-$reflabel",$base));
+           $non_lazy_ptr{"$nmdecor$sym"}=$indirect;
+       }
+       else
+       {   &::lea($dst,&::DWP("_GLOBAL_OFFSET_TABLE_+[.-$reflabel]",
+                           $base));
+           &::mov($dst,&::DWP("$sym\@GOT",$dst));
+       }
+    }
+    else
+    {  &::lea($dst,&::DWP($sym));      }
+}
+
+sub ::initseg
+{ my $f=$nmdecor.shift;
+
+    if ($::elf)
+    {  $initseg.=<<___;
+.section       .init
+       call    $f
+       jmp     .Linitalign
+.align $align
+.Linitalign:
+___
+    }
+    elsif ($::coff)
+    {   $initseg.=<<___;       # applies to both Cygwin and Mingw
+.section       .ctors
+.long  $f
+___
+    }
+    elsif ($::macosx)
+    {  $initseg.=<<___;
+.mod_init_func
+.align 2
+.long   $f
+___
+    }
+    elsif ($::aout)
+    {  my $ctor="${nmdecor}_GLOBAL_\$I\$$f";
+       $initseg.=".text\n";
+       $initseg.=".type        $ctor,\@function\n" if ($::pic);
+       $initseg.=<<___;        # OpenBSD way...
+.globl $ctor
+.align 2
+$ctor:
+       jmp     $f
+___
+    }
+}
+
+sub ::dataseg
+{   push(@out,".data\n");   }
+
+1;
diff --git a/deps/openssl/openssl/crypto/perlasm/x86masm.pl b/deps/openssl/openssl/crypto/perlasm/x86masm.pl
new file mode 100644 (file)
index 0000000..3d50e4a
--- /dev/null
@@ -0,0 +1,184 @@
+#!/usr/bin/env perl
+
+package x86masm;
+
+*out=\@::out;
+
+$::lbdecor="\$L";      # local label decoration
+$nmdecor="_";          # external name decoration
+
+$initseg="";
+$segment="";
+
+sub ::generic
+{ my ($opcode,@arg)=@_;
+
+    # fix hexadecimal constants
+    for (@arg) { s/0x([0-9a-f]+)/0$1h/oi; }
+
+    if ($opcode !~ /movq/)
+    {  # fix xmm references
+       $arg[0] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[1]=~/\bxmm[0-7]\b/i);
+       $arg[1] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[0]=~/\bxmm[0-7]\b/i);
+    }
+
+    &::emit($opcode,@arg);
+  1;
+}
+#
+# opcodes not covered by ::generic above, mostly inconsistent namings...
+#
+sub ::call     { &::emit("call",(&::islabel($_[0]) or "$nmdecor$_[0]")); }
+sub ::call_ptr { &::emit("call",@_);   }
+sub ::jmp_ptr  { &::emit("jmp",@_);    }
+
+sub get_mem
+{ my($size,$addr,$reg1,$reg2,$idx)=@_;
+  my($post,$ret);
+
+    $ret .= "$size PTR " if ($size ne "");
+
+    $addr =~ s/^\s+//;
+    # prepend global references with optional underscore
+    $addr =~ s/^([^\+\-0-9][^\+\-]*)/&::islabel($1) or "$nmdecor$1"/ige;
+    # put address arithmetic expression in parenthesis
+    $addr="($addr)" if ($addr =~ /^.+[\-\+].+$/);
+
+    if (($addr ne "") && ($addr ne 0))
+    {  if ($addr !~ /^-/)      { $ret .= "$addr";  }
+       else                    { $post=$addr;      }
+    }
+    $ret .= "[";
+
+    if ($reg2 ne "")
+    {  $idx!=0 or $idx=1;
+       $ret .= "$reg2*$idx";
+       $ret .= "+$reg1" if ($reg1 ne "");
+    }
+    else
+    {  $ret .= "$reg1";   }
+
+    $ret .= "$post]";
+    $ret =~ s/\+\]/]/; # in case $addr was the only argument
+    $ret =~ s/\[\s*\]//;
+
+  $ret;
+}
+sub ::BP       { &get_mem("BYTE",@_);  }
+sub ::DWP      { &get_mem("DWORD",@_); }
+sub ::QWP      { &get_mem("QWORD",@_); }
+sub ::BC       { "@_";  }
+sub ::DWC      { "@_"; }
+
+sub ::file
+{ my $tmp=<<___;
+TITLE  $_[0].asm
+IF \@Version LT 800
+ECHO MASM version 8.00 or later is strongly recommended.
+ENDIF
+.486
+.MODEL FLAT
+OPTION DOTNAME
+IF \@Version LT 800
+.text\$        SEGMENT PAGE 'CODE'
+ELSE
+.text\$        SEGMENT ALIGN(64) 'CODE'
+ENDIF
+___
+    push(@out,$tmp);
+    $segment = ".text\$";
+}
+
+sub ::function_begin_B
+{ my $func=shift;
+  my $global=($func !~ /^_/);
+  my $begin="${::lbdecor}_${func}_begin";
+
+    &::LABEL($func,$global?"$begin":"$nmdecor$func");
+    $func="ALIGN\t16\n".$nmdecor.$func."\tPROC";
+
+    if ($global)    { $func.=" PUBLIC\n${begin}::\n"; }
+    else           { $func.=" PRIVATE\n";            }
+    push(@out,$func);
+    $::stack=4;
+}
+sub ::function_end_B
+{ my $func=shift;
+
+    push(@out,"$nmdecor$func ENDP\n");
+    $::stack=0;
+    &::wipe_labels();
+}
+
+sub ::file_end
+{ my $xmmheader=<<___;
+.686
+.XMM
+IF \@Version LT 800
+XMMWORD STRUCT 16
+DQ     2 dup (?)
+XMMWORD        ENDS
+ENDIF
+___
+    if (grep {/\b[x]?mm[0-7]\b/i} @out) {
+       grep {s/\.[3-7]86/$xmmheader/} @out;
+    }
+
+    push(@out,"$segment        ENDS\n");
+
+    if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out)
+    {  my $comm=<<___;
+.bss   SEGMENT 'BSS'
+COMM   ${nmdecor}OPENSSL_ia32cap_P:DWORD
+.bss   ENDS
+___
+       # comment out OPENSSL_ia32cap_P declarations
+       grep {s/(^EXTERN\s+${nmdecor}OPENSSL_ia32cap_P)/\;$1/} @out;
+       push (@out,$comm);
+    }
+    push (@out,$initseg) if ($initseg);
+    push (@out,"END\n");
+}
+
+sub ::comment {   foreach (@_) { push(@out,"\t; $_\n"); }   }
+
+*::set_label_B = sub
+{ my $l=shift; push(@out,$l.($l=~/^\Q${::lbdecor}\E[0-9]{3}/?":\n":"::\n")); };
+
+sub ::external_label
+{   foreach(@_)
+    {  push(@out, "EXTERN\t".&::LABEL($_,$nmdecor.$_).":NEAR\n");   }
+}
+
+sub ::public_label
+{   push(@out,"PUBLIC\t".&::LABEL($_[0],$nmdecor.$_[0])."\n");   }
+
+sub ::data_byte
+{   push(@out,("DB\t").join(',',@_)."\n");     }
+
+sub ::data_word
+{   push(@out,("DD\t").join(',',@_)."\n");     }
+
+sub ::align
+{   push(@out,"ALIGN\t$_[0]\n");       }
+
+sub ::picmeup
+{ my($dst,$sym)=@_;
+    &::lea($dst,&::DWP($sym));
+}
+
+sub ::initseg
+{ my $f=$nmdecor.shift;
+
+    $initseg.=<<___;
+.CRT\$XCU      SEGMENT DWORD PUBLIC 'DATA'
+EXTERN $f:NEAR
+DD     $f
+.CRT\$XCU      ENDS
+___
+}
+
+sub ::dataseg
+{   push(@out,"$segment\tENDS\n_DATA\tSEGMENT\n"); $segment="_DATA";   }
+
+1;
diff --git a/deps/openssl/openssl/crypto/perlasm/x86ms.pl b/deps/openssl/openssl/crypto/perlasm/x86ms.pl
deleted file mode 100644 (file)
index a0be293..0000000
+++ /dev/null
@@ -1,472 +0,0 @@
-#!/usr/local/bin/perl
-
-package x86ms;
-
-$label="L000";
-
-%lb=(  'eax',  'al',
-       'ebx',  'bl',
-       'ecx',  'cl',
-       'edx',  'dl',
-       'ax',   'al',
-       'bx',   'bl',
-       'cx',   'cl',
-       'dx',   'dl',
-       );
-
-%hb=(  'eax',  'ah',
-       'ebx',  'bh',
-       'ecx',  'ch',
-       'edx',  'dh',
-       'ax',   'ah',
-       'bx',   'bh',
-       'cx',   'ch',
-       'dx',   'dh',
-       );
-
-sub main'asm_init_output { @out=(); }
-sub main'asm_get_output { return(@out); }
-sub main'get_labels { return(@labels); }
-sub main'external_label
-{
-       push(@labels,@_);
-       foreach (@_) {
-               push(@out, "EXTRN\t_$_:DWORD\n");
-       }
-}
-
-sub main'LB
-       {
-       (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n";
-       return($lb{$_[0]});
-       }
-
-sub main'HB
-       {
-       (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n";
-       return($hb{$_[0]});
-       }
-
-sub main'BP
-       {
-       &get_mem("BYTE",@_);
-       }
-
-sub main'DWP
-       {
-       &get_mem("DWORD",@_);
-       }
-
-sub main'QWP
-       {
-       &get_mem("QWORD",@_);
-       }
-
-sub main'BC
-       {
-       return @_;
-       }
-
-sub main'DWC
-       {
-       return @_;
-       }
-
-sub main'stack_push
-       {
-       local($num)=@_;
-       $stack+=$num*4;
-       &main'sub("esp",$num*4);
-       }
-
-sub main'stack_pop
-       {
-       local($num)=@_;
-       $stack-=$num*4;
-       &main'add("esp",$num*4);
-       }
-
-sub get_mem
-       {
-       local($size,$addr,$reg1,$reg2,$idx)=@_;
-       local($t,$post);
-       local($ret)="$size PTR ";
-
-       $addr =~ s/^\s+//;
-       if ($addr =~ /^(.+)\+(.+)$/)
-               {
-               $reg2=&conv($1);
-               $addr="_$2";
-               }
-       elsif ($addr =~ /^[_a-z][_a-z0-9]*$/i)
-               {
-               $addr="_$addr";
-               }
-
-       if ($addr =~ /^.+\-.+$/) { $addr="($addr)"; }
-
-       $reg1="$regs{$reg1}" if defined($regs{$reg1});
-       $reg2="$regs{$reg2}" if defined($regs{$reg2});
-       if (($addr ne "") && ($addr ne 0))
-               {
-               if ($addr !~ /^-/)
-                       { $ret.=$addr; }
-               else    { $post=$addr; }
-               }
-       if ($reg2 ne "")
-               {
-               $t="";
-               $t="*$idx" if ($idx != 0);
-               $reg1="+".$reg1 if ("$reg1$post" ne "");
-               $ret.="[$reg2$t$reg1$post]";
-               }
-       else
-               {
-               $ret.="[$reg1$post]"
-               }
-       $ret =~ s/\[\]//;       # in case $addr was the only argument
-       return($ret);
-       }
-
-sub main'mov   { &out2("mov",@_); }
-sub main'movb  { &out2("mov",@_); }
-sub main'and   { &out2("and",@_); }
-sub main'or    { &out2("or",@_); }
-sub main'shl   { &out2("shl",@_); }
-sub main'shr   { &out2("shr",@_); }
-sub main'xor   { &out2("xor",@_); }
-sub main'xorb  { &out2("xor",@_); }
-sub main'add   { &out2("add",@_); }
-sub main'adc   { &out2("adc",@_); }
-sub main'sub   { &out2("sub",@_); }
-sub main'sbb   { &out2("sbb",@_); }
-sub main'rotl  { &out2("rol",@_); }
-sub main'rotr  { &out2("ror",@_); }
-sub main'exch  { &out2("xchg",@_); }
-sub main'cmp   { &out2("cmp",@_); }
-sub main'lea   { &out2("lea",@_); }
-sub main'mul   { &out1("mul",@_); }
-sub main'imul  { &out2("imul",@_); }
-sub main'div   { &out1("div",@_); }
-sub main'dec   { &out1("dec",@_); }
-sub main'inc   { &out1("inc",@_); }
-sub main'jmp   { &out1("jmp",@_); }
-sub main'jmp_ptr { &out1p("jmp",@_); }
-sub main'je    { &out1("je",@_); }
-sub main'jle   { &out1("jle",@_); }
-sub main'jz    { &out1("jz",@_); }
-sub main'jge   { &out1("jge",@_); }
-sub main'jl    { &out1("jl",@_); }
-sub main'ja    { &out1("ja",@_); }
-sub main'jae   { &out1("jae",@_); }
-sub main'jb    { &out1("jb",@_); }
-sub main'jbe   { &out1("jbe",@_); }
-sub main'jc    { &out1("jc",@_); }
-sub main'jnc   { &out1("jnc",@_); }
-sub main'jnz   { &out1("jnz",@_); }
-sub main'jne   { &out1("jne",@_); }
-sub main'jno   { &out1("jno",@_); }
-sub main'push  { &out1("push",@_); $stack+=4; }
-sub main'pop   { &out1("pop",@_); $stack-=4; }
-sub main'pushf { &out0("pushfd"); $stack+=4; }
-sub main'popf  { &out0("popfd"); $stack-=4; }
-sub main'bswap { &out1("bswap",@_); &using486(); }
-sub main'not   { &out1("not",@_); }
-sub main'call  { &out1("call",($_[0]=~/^\$L/?'':'_').$_[0]); }
-sub main'call_ptr { &out1p("call",@_); }
-sub main'ret   { &out0("ret"); }
-sub main'nop   { &out0("nop"); }
-sub main'test  { &out2("test",@_); }
-sub main'bt    { &out2("bt",@_); }
-sub main'leave { &out0("leave"); }
-sub main'cpuid  { &out0("DW\t0A20Fh"); }
-sub main'rdtsc  { &out0("DW\t0310Fh"); }
-sub main'halt  { &out0("hlt"); }
-sub main'movz  { &out2("movzx",@_); }
-sub main'neg   { &out1("neg",@_); }
-sub main'cld   { &out0("cld"); }
-
-# SSE2
-sub main'emms  { &out0("emms"); }
-sub main'movd  { &out2("movd",@_); }
-sub main'movq  { &out2("movq",@_); }
-sub main'movdqu        { &out2("movdqu",@_); }
-sub main'movdqa        { &out2("movdqa",@_); }
-sub main'movdq2q{ &out2("movdq2q",@_); }
-sub main'movq2dq{ &out2("movq2dq",@_); }
-sub main'paddq { &out2("paddq",@_); }
-sub main'pmuludq{ &out2("pmuludq",@_); }
-sub main'psrlq { &out2("psrlq",@_); }
-sub main'psllq { &out2("psllq",@_); }
-sub main'pxor  { &out2("pxor",@_); }
-sub main'por   { &out2("por",@_); }
-sub main'pand  { &out2("pand",@_); }
-
-sub out2
-       {
-       local($name,$p1,$p2)=@_;
-       local($l,$t,$line);
-
-       $line="\t$name\t";
-       $t=&conv($p1).",";
-       $l=length($t);
-       $line.="$t";
-       $l=4-($l+9)/8;
-       $line.="\t" x $l;
-       $line.=&conv($p2);
-       if ($line=~/\bxmm[0-7]\b/i) { $line=~s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i; }
-       push(@out,$line."\n");
-       }
-
-sub out0
-       {
-       local($name)=@_;
-
-       push(@out,"\t$name\n");
-       }
-
-sub out1
-       {
-       local($name,$p1)=@_;
-       local($l,$t);
-
-       push(@out,"\t$name\t".&conv($p1)."\n");
-       }
-
-sub conv
-       {
-       local($p)=@_;
-
-       $p =~ s/0x([0-9A-Fa-f]+)/0$1h/;
-       return $p;
-       }
-
-sub using486
-       {
-       return if $using486;
-       $using486++;
-       grep(s/\.386/\.486/,@out);
-       }
-
-sub main'file
-       {
-       local($file)=@_;
-
-       local($tmp)=<<"EOF";
-       TITLE   $file.asm
-        .386
-.model FLAT
-_TEXT\$        SEGMENT PAGE 'CODE'
-
-EOF
-       push(@out,$tmp);
-       }
-
-sub main'function_begin
-       {
-       local($func,$extra)=@_;
-
-       push(@labels,$func);
-
-       local($tmp)=<<"EOF";
-PUBLIC _$func
-$extra
-_$func PROC NEAR
-       push    ebp
-       push    ebx
-       push    esi
-       push    edi
-EOF
-       push(@out,$tmp);
-       $stack=20;
-       }
-
-sub main'function_begin_B
-       {
-       local($func,$extra)=@_;
-
-       local($tmp)=<<"EOF";
-PUBLIC _$func
-$extra
-_$func PROC NEAR
-EOF
-       push(@out,$tmp);
-       $stack=4;
-       }
-
-sub main'function_end
-       {
-       local($func)=@_;
-
-       local($tmp)=<<"EOF";
-       pop     edi
-       pop     esi
-       pop     ebx
-       pop     ebp
-       ret
-_$func ENDP
-EOF
-       push(@out,$tmp);
-       $stack=0;
-       %label=();
-       }
-
-sub main'function_end_B
-       {
-       local($func)=@_;
-
-       local($tmp)=<<"EOF";
-_$func ENDP
-EOF
-       push(@out,$tmp);
-       $stack=0;
-       %label=();
-       }
-
-sub main'function_end_A
-       {
-       local($func)=@_;
-
-       local($tmp)=<<"EOF";
-       pop     edi
-       pop     esi
-       pop     ebx
-       pop     ebp
-       ret
-EOF
-       push(@out,$tmp);
-       }
-
-sub main'file_end
-       {
-       # try to detect if SSE2 or MMX extensions were used...
-       my $xmmheader=<<___;
-.686
-.XMM
-IF \@Version LT 800
-XMMWORD STRUCT 16
-       DQ  2 dup (?)
-XMMWORD ENDS
-ENDIF
-___
-       if (grep {/\b[x]?mm[0-7]\b/i} @out) {
-               grep {s/\.[3-7]86/$xmmheader/} @out;
-               }
-       push(@out,"_TEXT\$      ENDS\n");
-       push(@out,"END\n");
-       }
-
-sub main'wparam
-       {
-       local($num)=@_;
-
-       return(&main'DWP($stack+$num*4,"esp","",0));
-       }
-
-sub main'swtmp
-       {
-       return(&main'DWP($_[0]*4,"esp","",0));
-       }
-
-# Should use swtmp, which is above esp.  Linix can trash the stack above esp
-#sub main'wtmp
-#      {
-#      local($num)=@_;
-#
-#      return(&main'DWP(-(($num+1)*4),"esp","",0));
-#      }
-
-sub main'comment
-       {
-       foreach (@_)
-               {
-               push(@out,"\t; $_\n");
-               }
-       }
-
-sub main'public_label
-       {
-       $label{$_[0]}="_$_[0]"  if (!defined($label{$_[0]}));
-       push(@out,"PUBLIC\t$label{$_[0]}\n");
-       }
-
-sub main'label
-       {
-       if (!defined($label{$_[0]}))
-               {
-               $label{$_[0]}="\$${label}${_[0]}";
-               $label++;
-               }
-       return($label{$_[0]});
-       }
-
-sub main'set_label
-       {
-       if (!defined($label{$_[0]}))
-               {
-               $label{$_[0]}="\$${label}${_[0]}";
-               $label++;
-               }
-       if ($_[1]!=0 && $_[1]>1)
-               {
-               main'align($_[1]);
-               }
-       if((defined $_[2]) && ($_[2] == 1))
-               {
-               push(@out,"$label{$_[0]}::\n");
-               }
-       elsif ($label{$_[0]} !~ /^\$/)
-               {
-               push(@out,"$label{$_[0]}\tLABEL PTR\n");
-               }
-       else
-               {
-               push(@out,"$label{$_[0]}:\n");
-               }
-       }
-
-sub main'data_byte
-       {
-       push(@out,"\tDB\t".join(',',@_)."\n");
-       }
-
-sub main'data_word
-       {
-       push(@out,"\tDD\t".join(',',@_)."\n");
-       }
-
-sub main'align
-       {
-       push(@out,"\tALIGN\t$_[0]\n");
-       }
-
-sub out1p
-       {
-       local($name,$p1)=@_;
-       local($l,$t);
-
-       push(@out,"\t$name\t".&conv($p1)."\n");
-       }
-
-sub main'picmeup
-       {
-       local($dst,$sym)=@_;
-       &main'lea($dst,&main'DWP($sym));
-       }
-
-sub main'blindpop { &out1("pop",@_); }
-
-sub main'initseg 
-       {
-       local($f)=@_;
-       local($tmp)=<<___;
-OPTION DOTNAME
-.CRT\$XCU      SEGMENT DWORD PUBLIC 'DATA'
-EXTRN  _$f:NEAR
-DD     _$f
-.CRT\$XCU      ENDS
-___
-       push(@out,$tmp);
-       }
-
-1;
index fa38f89..ce2bed9 100644 (file)
-#!/usr/local/bin/perl
+#!/usr/bin/env perl
 
 package x86nasm;
 
-$label="L000";
-$under=($main'netware)?'':'_';
+*out=\@::out;
 
-%lb=(  'eax',  'al',
-       'ebx',  'bl',
-       'ecx',  'cl',
-       'edx',  'dl',
-       'ax',   'al',
-       'bx',   'bl',
-       'cx',   'cl',
-       'dx',   'dl',
-       );
+$::lbdecor="L\$";              # local label decoration
+$nmdecor=$::netware?"":"_";    # external name decoration
+$drdecor=$::mwerks?".":"";     # directive decoration
 
-%hb=(  'eax',  'ah',
-       'ebx',  'bh',
-       'ecx',  'ch',
-       'edx',  'dh',
-       'ax',   'ah',
-       'bx',   'bh',
-       'cx',   'ch',
-       'dx',   'dh',
-       );
+$initseg="";
 
-sub main'asm_init_output { @out=(); }
-sub main'asm_get_output { return(@out); }
-sub main'get_labels { return(@labels); }
+sub ::generic
+{ my $opcode=shift;
+  my $tmp;
 
-sub main'external_label
-{
-       push(@labels,@_);
-       foreach (@_) {
-               push(@out,".") if ($main'mwerks);
-               push(@out, "extern\t${under}$_\n");
-       }
+    if (!$::mwerks)
+    {   if    ($opcode =~ m/^j/o && $#_==0) # optimize jumps
+       {   $_[0] = "NEAR $_[0]";       }
+       elsif ($opcode eq "lea" && $#_==1)  # wipe storage qualifier from lea
+       {   $_[1] =~ s/^[^\[]*\[/\[/o;  }
+    }
+    &::emit($opcode,@_);
+  1;
 }
-
-sub main'LB
-       {
-       (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n";
-       return($lb{$_[0]});
-       }
-
-sub main'HB
-       {
-       (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n";
-       return($hb{$_[0]});
-       }
-
-sub main'BP
-       {
-       &get_mem("BYTE",@_);
-       }
-
-sub main'DWP
-       {
-       &get_mem("DWORD",@_);
-       }
-
-sub main'QWP
-       {
-       &get_mem("",@_);
-       }
-
-sub main'BC
-       {
-       return (($main'mwerks)?"":"BYTE ")."@_";
-       }
-
-sub main'DWC
-       {
-       return (($main'mwerks)?"":"DWORD ")."@_";
-       }
-
-sub main'stack_push
-       {
-       my($num)=@_;
-       $stack+=$num*4;
-       &main'sub("esp",$num*4);
-       }
-
-sub main'stack_pop
-       {
-       my($num)=@_;
-       $stack-=$num*4;
-       &main'add("esp",$num*4);
-       }
+#
+# opcodes not covered by ::generic above, mostly inconsistent namings...
+#
+sub ::call     { &::emit("call",(&::islabel($_[0]) or "$nmdecor$_[0]")); }
+sub ::call_ptr { &::emit("call",@_);   }
+sub ::jmp_ptr  { &::emit("jmp",@_);    }
 
 sub get_mem
-       {
-       my($size,$addr,$reg1,$reg2,$idx)=@_;
-       my($t,$post);
-       my($ret)=$size;
-       if ($ret ne "")
-               {
-               $ret .= " PTR" if ($main'mwerks);
-               $ret .= " ";
-               }
-       $ret .= "[";
-       $addr =~ s/^\s+//;
-       if ($addr =~ /^(.+)\+(.+)$/)
-               {
-               $reg2=&conv($1);
-               $addr="$under$2";
-               }
-       elsif ($addr =~ /^[_a-z][_a-z0-9]*$/i)
-               {
-               $addr="$under$addr";
-               }
-
-       if ($addr =~ /^.+\-.+$/) { $addr="($addr)"; }
-
-       $reg1="$regs{$reg1}" if defined($regs{$reg1});
-       $reg2="$regs{$reg2}" if defined($regs{$reg2});
-       if (($addr ne "") && ($addr ne 0))
-               {
-               if ($addr !~ /^-/)
-                       { $ret.="${addr}+"; }
-               else    { $post=$addr; }
-               }
-       if ($reg2 ne "")
-               {
-               $t="";
-               $t="*$idx" if ($idx != 0);
-               $reg1="+".$reg1 if ("$reg1$post" ne "");
-               $ret.="$reg2$t$reg1$post]";
-               }
-       else
-               {
-               $ret.="$reg1$post]"
-               }
-       $ret =~ s/\+\]/]/; # in case $addr was the only argument
-       return($ret);
-       }
-
-sub main'mov   { &out2("mov",@_); }
-sub main'movb  { &out2("mov",@_); }
-sub main'and   { &out2("and",@_); }
-sub main'or    { &out2("or",@_); }
-sub main'shl   { &out2("shl",@_); }
-sub main'shr   { &out2("shr",@_); }
-sub main'xor   { &out2("xor",@_); }
-sub main'xorb  { &out2("xor",@_); }
-sub main'add   { &out2("add",@_); }
-sub main'adc   { &out2("adc",@_); }
-sub main'sub   { &out2("sub",@_); }
-sub main'sbb   { &out2("sbb",@_); }
-sub main'rotl  { &out2("rol",@_); }
-sub main'rotr  { &out2("ror",@_); }
-sub main'exch  { &out2("xchg",@_); }
-sub main'cmp   { &out2("cmp",@_); }
-sub main'lea   { &out2("lea",@_); }
-sub main'mul   { &out1("mul",@_); }
-sub main'imul  { &out2("imul",@_); }
-sub main'div   { &out1("div",@_); }
-sub main'dec   { &out1("dec",@_); }
-sub main'inc   { &out1("inc",@_); }
-sub main'jmp   { &out1("jmp",@_); }
-sub main'jmp_ptr { &out1p("jmp",@_); }
-
-# This is a bit of a kludge: declare all branches as NEAR.
-$near=($main'mwerks)?'':'NEAR';
-sub main'je    { &out1("je $near",@_); }
-sub main'jle   { &out1("jle $near",@_); }
-sub main'jz    { &out1("jz $near",@_); }
-sub main'jge   { &out1("jge $near",@_); }
-sub main'jl    { &out1("jl $near",@_); }
-sub main'ja    { &out1("ja $near",@_); }
-sub main'jae   { &out1("jae $near",@_); }
-sub main'jb    { &out1("jb $near",@_); }
-sub main'jbe   { &out1("jbe $near",@_); }
-sub main'jc    { &out1("jc $near",@_); }
-sub main'jnc   { &out1("jnc $near",@_); }
-sub main'jnz   { &out1("jnz $near",@_); }
-sub main'jne   { &out1("jne $near",@_); }
-sub main'jno   { &out1("jno $near",@_); }
-
-sub main'push  { &out1("push",@_); $stack+=4; }
-sub main'pop   { &out1("pop",@_); $stack-=4; }
-sub main'pushf { &out0("pushfd"); $stack+=4; }
-sub main'popf  { &out0("popfd"); $stack-=4; }
-sub main'bswap { &out1("bswap",@_); &using486(); }
-sub main'not   { &out1("not",@_); }
-sub main'call  { &out1("call",($_[0]=~/^\@L/?'':$under).$_[0]); }
-sub main'call_ptr { &out1p("call",@_); }
-sub main'ret   { &out0("ret"); }
-sub main'nop   { &out0("nop"); }
-sub main'test  { &out2("test",@_); }
-sub main'bt    { &out2("bt",@_); }
-sub main'leave { &out0("leave"); }
-sub main'cpuid { &out0("cpuid"); }
-sub main'rdtsc { &out0("rdtsc"); }
-sub main'halt  { &out0("hlt"); }
-sub main'movz  { &out2("movzx",@_); }
-sub main'neg   { &out1("neg",@_); }
-sub main'cld   { &out0("cld"); }
-
-# SSE2
-sub main'emms  { &out0("emms"); }
-sub main'movd  { &out2("movd",@_); }
-sub main'movq  { &out2("movq",@_); }
-sub main'movdqu        { &out2("movdqu",@_); }
-sub main'movdqa        { &out2("movdqa",@_); }
-sub main'movdq2q{ &out2("movdq2q",@_); }
-sub main'movq2dq{ &out2("movq2dq",@_); }
-sub main'paddq { &out2("paddq",@_); }
-sub main'pmuludq{ &out2("pmuludq",@_); }
-sub main'psrlq { &out2("psrlq",@_); }
-sub main'psllq { &out2("psllq",@_); }
-sub main'pxor  { &out2("pxor",@_); }
-sub main'por   { &out2("por",@_); }
-sub main'pand  { &out2("pand",@_); }
-
-sub out2
-       {
-       my($name,$p1,$p2)=@_;
-       my($l,$t);
-
-       push(@out,"\t$name\t");
-       if (!$main'mwerks and $name eq "lea")
-               {
-               $p1 =~ s/^[^\[]*\[/\[/;
-               $p2 =~ s/^[^\[]*\[/\[/;
-               }
-       $t=&conv($p1).",";
-       $l=length($t);
-       push(@out,$t);
-       $l=4-($l+9)/8;
-       push(@out,"\t" x $l);
-       push(@out,&conv($p2));
-       push(@out,"\n");
-       }
-
-sub out0
-       {
-       my($name)=@_;
-
-       push(@out,"\t$name\n");
-       }
-
-sub out1
-       {
-       my($name,$p1)=@_;
-       my($l,$t);
-       push(@out,"\t$name\t".&conv($p1)."\n");
-       }
-
-sub conv
-       {
-       my($p)=@_;
-       $p =~ s/0x([0-9A-Fa-f]+)/0$1h/;
-       return $p;
-       }
-
-sub using486
-       {
-       return if $using486;
-       $using486++;
-       grep(s/\.386/\.486/,@out);
-       }
-
-sub main'file
-       {
-       if ($main'mwerks)       { push(@out,".section\t.text\n"); }
-       else    {
-               local $tmp=<<___;
-%ifdef __omf__
-section        code    use32 class=code
+{ my($size,$addr,$reg1,$reg2,$idx)=@_;
+  my($post,$ret);
+
+    if ($size ne "")
+    {  $ret .= "$size";
+       $ret .= " PTR" if ($::mwerks);
+       $ret .= " ";
+    }
+    $ret .= "[";
+
+    $addr =~ s/^\s+//;
+    # prepend global references with optional underscore
+    $addr =~ s/^([^\+\-0-9][^\+\-]*)/::islabel($1) or "$nmdecor$1"/ige;
+    # put address arithmetic expression in parenthesis
+    $addr="($addr)" if ($addr =~ /^.+[\-\+].+$/);
+
+    if (($addr ne "") && ($addr ne 0))
+    {  if ($addr !~ /^-/)      { $ret .= "$addr+"; }
+       else                    { $post=$addr;      }
+    }
+
+    if ($reg2 ne "")
+    {  $idx!=0 or $idx=1;
+       $ret .= "$reg2*$idx";
+       $ret .= "+$reg1" if ($reg1 ne "");
+    }
+    else
+    {  $ret .= "$reg1";   }
+
+    $ret .= "$post]";
+    $ret =~ s/\+\]/]/; # in case $addr was the only argument
+
+  $ret;
+}
+sub ::BP       { &get_mem("BYTE",@_);  }
+sub ::DWP      { &get_mem("DWORD",@_); }
+sub ::QWP      { &get_mem("",@_);      }
+sub ::BC       { (($::mwerks)?"":"BYTE ")."@_";  }
+sub ::DWC      { (($::mwerks)?"":"DWORD ")."@_"; }
+
+sub ::file
+{   if ($::mwerks)     { push(@out,".section\t.text,64\n"); }
+    else
+    { my $tmp=<<___;
+%ifidn __OUTPUT_FORMAT__,obj
+section        code    use32 class=code align=64
+%elifidn __OUTPUT_FORMAT__,win32
+\$\@feat.00 equ 1
+section        .text   code align=64
 %else
-section        .text
+section        .text   code
 %endif
 ___
-               push(@out,$tmp);
-               }
-       }
-
-sub main'function_begin
-       {
-       my($func,$extra)=@_;
-
-       push(@labels,$func);
-       push(@out,".") if ($main'mwerks);
-       my($tmp)=<<"EOF";
-global $under$func
-$under$func:
-       push    ebp
-       push    ebx
-       push    esi
-       push    edi
-EOF
-       push(@out,$tmp);
-       $stack=20;
-       }
-
-sub main'function_begin_B
-       {
-       my($func,$extra)=@_;
-       push(@out,".") if ($main'mwerks);
-       my($tmp)=<<"EOF";
-global $under$func
-$under$func:
-EOF
-       push(@out,$tmp);
-       $stack=4;
-       }
-
-sub main'function_end
-       {
-       my($func)=@_;
-
-       my($tmp)=<<"EOF";
-       pop     edi
-       pop     esi
-       pop     ebx
-       pop     ebp
-       ret
-EOF
        push(@out,$tmp);
-       $stack=0;
-       %label=();
-       }
-
-sub main'function_end_B
-       {
-       $stack=0;
-       %label=();
-       }
-
-sub main'function_end_A
-       {
-       my($func)=@_;
-
-       my($tmp)=<<"EOF";
-       pop     edi
-       pop     esi
-       pop     ebx
-       pop     ebp
-       ret
-EOF
-       push(@out,$tmp);
-       }
-
-sub main'file_end
-       {
-       }
-
-sub main'wparam
-       {
-       my($num)=@_;
-
-       return(&main'DWP($stack+$num*4,"esp","",0));
-       }
+    }
+}
 
-sub main'swtmp
-       {
-       return(&main'DWP($_[0]*4,"esp","",0));
-       }
+sub ::function_begin_B
+{ my $func=shift;
+  my $global=($func !~ /^_/);
+  my $begin="${::lbdecor}_${func}_begin";
 
-# Should use swtmp, which is above esp.  Linix can trash the stack above esp
-#sub main'wtmp
-#      {
-#      my($num)=@_;
-#
-#      return(&main'DWP(-(($num+1)*4),"esp","",0));
-#      }
+    $begin =~ s/^\@/./ if ($::mwerks); # the torture never stops
 
-sub main'comment
-       {
-       foreach (@_)
-               {
-               push(@out,"\t; $_\n");
-               }
-       }
+    &::LABEL($func,$global?"$begin":"$nmdecor$func");
+    $func=$nmdecor.$func;
 
-sub main'public_label
-       {
-       $label{$_[0]}="${under}${_[0]}" if (!defined($label{$_[0]}));
-       push(@out,".") if ($main'mwerks);
-       push(@out,"global\t$label{$_[0]}\n");
-       }
+    push(@out,"${drdecor}global        $func\n")       if ($global);
+    push(@out,"${drdecor}align 16\n");
+    push(@out,"$func:\n");
+    push(@out,"$begin:\n")                     if ($global);
+    $::stack=4;
+}
 
-sub main'label
-       {
-       if (!defined($label{$_[0]}))
-               {
-               $label{$_[0]}="\@${label}${_[0]}";
-               $label++;
-               }
-       return($label{$_[0]});
-       }
+sub ::function_end_B
+{   $::stack=0;
+    &::wipe_labels();
+}
 
-sub main'set_label
-       {
-       if (!defined($label{$_[0]}))
-               {
-               $label{$_[0]}="\@${label}${_[0]}";
-               $label++;
-               }
-       if ($_[1]!=0 && $_[1]>1)
-               {
-               main'align($_[1]);
-               }
-       push(@out,"$label{$_[0]}:\n");
-       }
+sub ::file_end
+{   if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out)
+    {  my $comm=<<___;
+${drdecor}segment      .bss
+${drdecor}common       ${nmdecor}OPENSSL_ia32cap_P 4
+___
+       # comment out OPENSSL_ia32cap_P declarations
+       grep {s/(^extern\s+${nmdecor}OPENSSL_ia32cap_P)/\;$1/} @out;
+       push (@out,$comm)
+    }
+    push (@out,$initseg) if ($initseg);                
+}
 
-sub main'data_byte
-       {
-       push(@out,(($main'mwerks)?".byte\t":"DB\t").join(',',@_)."\n");
-       }
+sub ::comment {   foreach (@_) { push(@out,"\t; $_\n"); }   }
 
-sub main'data_word
-       {
-       push(@out,(($main'mwerks)?".long\t":"DD\t").join(',',@_)."\n");
-       }
+sub ::external_label
+{   foreach(@_)
+    {  push(@out,"${drdecor}extern\t".&::LABEL($_,$nmdecor.$_)."\n");   }
+}
 
-sub main'align
-       {
-       push(@out,".") if ($main'mwerks);
-       push(@out,"align\t$_[0]\n");
-       }
+sub ::public_label
+{   push(@out,"${drdecor}global\t".&::LABEL($_[0],$nmdecor.$_[0])."\n");  }
 
-sub out1p
-       {
-       my($name,$p1)=@_;
-       my($l,$t);
+sub ::data_byte
+{   push(@out,(($::mwerks)?".byte\t":"db\t").join(',',@_)."\n");       }
 
-       push(@out,"\t$name\t".&conv($p1)."\n");
-       }
+sub ::data_word
+{   push(@out,(($::mwerks)?".long\t":"dd\t").join(',',@_)."\n");       }
 
-sub main'picmeup
-       {
-       local($dst,$sym)=@_;
-       &main'lea($dst,&main'DWP($sym));
-       }
+sub ::align
+{   push(@out,"${drdecor}align\t$_[0]\n");     }
 
-sub main'blindpop { &out1("pop",@_); }
+sub ::picmeup
+{ my($dst,$sym)=@_;
+    &::lea($dst,&::DWP($sym));
+}
 
-sub main'initseg
-       {
-       local($f)=@_;
-       if ($main'win32)
-               {
-               local($tmp)=<<___;
-segment        .CRT\$XCU data
-extern $under$f
-DD     $under$f
+sub ::initseg
+{ my $f=$nmdecor.shift;
+    if ($::win32)
+    {  $initseg=<<___;
+segment        .CRT\$XCU data align=4
+extern $f
+dd     $f
 ___
-               push(@out,$tmp);
-               }
-       }
+    }
+}
+
+sub ::dataseg
+{   if ($mwerks)       { push(@out,".section\t.data,4\n");   }
+    else               { push(@out,"section\t.data align=4\n"); }
+}
 
 1;
diff --git a/deps/openssl/openssl/crypto/perlasm/x86unix.pl b/deps/openssl/openssl/crypto/perlasm/x86unix.pl
deleted file mode 100644 (file)
index a4c9471..0000000
+++ /dev/null
@@ -1,725 +0,0 @@
-#!/usr/local/bin/perl
-
-package x86unix;       # GAS actually...
-
-$label="L000";
-$const="";
-$constl=0;
-
-$align=($main'aout)?"4":"16";
-$under=($main'aout or $main'coff)?"_":"";
-$dot=($main'aout)?"":".";
-$com_start="#" if ($main'aout or $main'coff);
-
-sub main'asm_init_output { @out=(); }
-sub main'asm_get_output { return(@out); }
-sub main'get_labels { return(@labels); }
-sub main'external_label { push(@labels,@_); }
-
-if ($main'cpp)
-       {
-       $align="ALIGN";
-       $under="";
-       $com_start='/*';
-       $com_end='*/';
-       }
-
-%lb=(  'eax',  '%al',
-       'ebx',  '%bl',
-       'ecx',  '%cl',
-       'edx',  '%dl',
-       'ax',   '%al',
-       'bx',   '%bl',
-       'cx',   '%cl',
-       'dx',   '%dl',
-       );
-
-%hb=(  'eax',  '%ah',
-       'ebx',  '%bh',
-       'ecx',  '%ch',
-       'edx',  '%dh',
-       'ax',   '%ah',
-       'bx',   '%bh',
-       'cx',   '%ch',
-       'dx',   '%dh',
-       );
-
-%regs=(        'eax',  '%eax',
-       'ebx',  '%ebx',
-       'ecx',  '%ecx',
-       'edx',  '%edx',
-       'esi',  '%esi',
-       'edi',  '%edi',
-       'ebp',  '%ebp',
-       'esp',  '%esp',
-
-       'mm0',  '%mm0',
-       'mm1',  '%mm1',
-       'mm2',  '%mm2',
-       'mm3',  '%mm3',
-       'mm4',  '%mm4',
-       'mm5',  '%mm5',
-       'mm6',  '%mm6',
-       'mm7',  '%mm7',
-
-       'xmm0', '%xmm0',
-       'xmm1', '%xmm1',
-       'xmm2', '%xmm2',
-       'xmm3', '%xmm3',
-       'xmm4', '%xmm4',
-       'xmm5', '%xmm5',
-       'xmm6', '%xmm6',
-       'xmm7', '%xmm7',
-       );
-
-%reg_val=(
-       'eax',  0x00,
-       'ebx',  0x03,
-       'ecx',  0x01,
-       'edx',  0x02,
-       'esi',  0x06,
-       'edi',  0x07,
-       'ebp',  0x05,
-       'esp',  0x04,
-       );
-
-sub main'LB
-       {
-       (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n";
-       return($lb{$_[0]});
-       }
-
-sub main'HB
-       {
-       (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n";
-       return($hb{$_[0]});
-       }
-
-sub main'DWP
-       {
-       local($addr,$reg1,$reg2,$idx)=@_;
-
-       $ret="";
-       $addr =~ s/(^|[+ \t])([A-Za-z_]+[A-Za-z0-9_]+)($|[+ \t])/$1$under$2$3/;
-       $reg1="$regs{$reg1}" if defined($regs{$reg1});
-       $reg2="$regs{$reg2}" if defined($regs{$reg2});
-       $ret.=$addr if ($addr ne "") && ($addr ne 0);
-       if ($reg2 ne "")
-               {
-               if($idx ne "" && $idx != 0)
-                   { $ret.="($reg1,$reg2,$idx)"; }
-               else
-                   { $ret.="($reg1,$reg2)"; }
-               }
-       elsif ($reg1 ne "")
-               { $ret.="($reg1)" }
-       return($ret);
-       }
-
-sub main'QWP
-       {
-       return(&main'DWP(@_));
-       }
-
-sub main'BP
-       {
-       return(&main'DWP(@_));
-       }
-
-sub main'BC
-       {
-       return @_;
-       }
-
-sub main'DWC
-       {
-       return @_;
-       }
-
-#sub main'BP
-#      {
-#      local($addr,$reg1,$reg2,$idx)=@_;
-#
-#      $ret="";
-#
-#      $addr =~ s/(^|[+ \t])([A-Za-z_]+)($|[+ \t])/$1$under$2$3/;
-#      $reg1="$regs{$reg1}" if defined($regs{$reg1});
-#      $reg2="$regs{$reg2}" if defined($regs{$reg2});
-#      $ret.=$addr if ($addr ne "") && ($addr ne 0);
-#      if ($reg2 ne "")
-#              { $ret.="($reg1,$reg2,$idx)"; }
-#      else
-#              { $ret.="($reg1)" }
-#      return($ret);
-#      }
-
-sub main'mov   { &out2("movl",@_); }
-sub main'movb  { &out2("movb",@_); }
-sub main'and   { &out2("andl",@_); }
-sub main'or    { &out2("orl",@_); }
-sub main'shl   { &out2("sall",@_); }
-sub main'shr   { &out2("shrl",@_); }
-sub main'xor   { &out2("xorl",@_); }
-sub main'xorb  { &out2("xorb",@_); }
-sub main'add   { &out2($_[0]=~/%[a-d][lh]/?"addb":"addl",@_); }
-sub main'adc   { &out2("adcl",@_); }
-sub main'sub   { &out2("subl",@_); }
-sub main'sbb   { &out2("sbbl",@_); }
-sub main'rotl  { &out2("roll",@_); }
-sub main'rotr  { &out2("rorl",@_); }
-sub main'exch  { &out2($_[0]=~/%[a-d][lh]/?"xchgb":"xchgl",@_); }
-sub main'cmp   { &out2("cmpl",@_); }
-sub main'lea   { &out2("leal",@_); }
-sub main'mul   { &out1("mull",@_); }
-sub main'imul  { &out2("imull",@_); }
-sub main'div   { &out1("divl",@_); }
-sub main'jmp   { &out1("jmp",@_); }
-sub main'jmp_ptr { &out1p("jmp",@_); }
-sub main'je    { &out1("je",@_); }
-sub main'jle   { &out1("jle",@_); }
-sub main'jne   { &out1("jne",@_); }
-sub main'jnz   { &out1("jnz",@_); }
-sub main'jz    { &out1("jz",@_); }
-sub main'jge   { &out1("jge",@_); }
-sub main'jl    { &out1("jl",@_); }
-sub main'ja    { &out1("ja",@_); }
-sub main'jae   { &out1("jae",@_); }
-sub main'jb    { &out1("jb",@_); }
-sub main'jbe   { &out1("jbe",@_); }
-sub main'jc    { &out1("jc",@_); }
-sub main'jnc   { &out1("jnc",@_); }
-sub main'jno   { &out1("jno",@_); }
-sub main'dec   { &out1("decl",@_); }
-sub main'inc   { &out1($_[0]=~/%[a-d][hl]/?"incb":"incl",@_); }
-sub main'push  { &out1("pushl",@_); $stack+=4; }
-sub main'pop   { &out1("popl",@_); $stack-=4; }
-sub main'pushf { &out0("pushfl"); $stack+=4; }
-sub main'popf  { &out0("popfl"); $stack-=4; }
-sub main'not   { &out1("notl",@_); }
-sub main'call  {       my $pre=$under;
-                       foreach $i (%label)
-                       { if ($label{$i} eq $_[0]) { $pre=''; last; } }
-                       &out1("call",$pre.$_[0]);
-               }
-sub main'call_ptr { &out1p("call",@_); }
-sub main'ret   { &out0("ret"); }
-sub main'nop   { &out0("nop"); }
-sub main'test  { &out2("testl",@_); }
-sub main'bt    { &out2("btl",@_); }
-sub main'leave { &out0("leave"); }
-sub main'cpuid { &out0(".byte\t0x0f,0xa2"); }
-sub main'rdtsc { &out0(".byte\t0x0f,0x31"); }
-sub main'halt  { &out0("hlt"); }
-sub main'movz  { &out2("movzbl",@_); }
-sub main'neg   { &out1("negl",@_); }
-sub main'cld   { &out0("cld"); }
-
-# SSE2
-sub main'emms  { &out0("emms"); }
-sub main'movd  { &out2("movd",@_); }
-sub main'movdqu        { &out2("movdqu",@_); }
-sub main'movdqa        { &out2("movdqa",@_); }
-sub main'movdq2q{ &out2("movdq2q",@_); }
-sub main'movq2dq{ &out2("movq2dq",@_); }
-sub main'paddq { &out2("paddq",@_); }
-sub main'pmuludq{ &out2("pmuludq",@_); }
-sub main'psrlq { &out2("psrlq",@_); }
-sub main'psllq { &out2("psllq",@_); }
-sub main'pxor  { &out2("pxor",@_); }
-sub main'por   { &out2("por",@_); }
-sub main'pand  { &out2("pand",@_); }
-sub main'movq  {
-       local($p1,$p2,$optimize)=@_;
-       if ($optimize && $p1=~/^mm[0-7]$/ && $p2=~/^mm[0-7]$/)
-               # movq between mmx registers can sink Intel CPUs
-               {       push(@out,"\tpshufw\t\$0xe4,%$p2,%$p1\n");      }
-       else    {       &out2("movq",@_);                               }
-       }
-
-# The bswapl instruction is new for the 486. Emulate if i386.
-sub main'bswap
-       {
-       if ($main'i386)
-               {
-               &main'comment("bswapl @_");
-               &main'exch(main'HB(@_),main'LB(@_));
-               &main'rotr(@_,16);
-               &main'exch(main'HB(@_),main'LB(@_));
-               }
-       else
-               {
-               &out1("bswapl",@_);
-               }
-       }
-
-sub out2
-       {
-       local($name,$p1,$p2)=@_;
-       local($l,$ll,$t);
-       local(%special)=(       "roll",0xD1C0,"rorl",0xD1C8,
-                               "rcll",0xD1D0,"rcrl",0xD1D8,
-                               "shll",0xD1E0,"shrl",0xD1E8,
-                               "sarl",0xD1F8);
-       
-       if ((defined($special{$name})) && defined($regs{$p1}) && ($p2 == 1))
-               {
-               $op=$special{$name}|$reg_val{$p1};
-               $tmp1=sprintf(".byte %d\n",($op>>8)&0xff);
-               $tmp2=sprintf(".byte %d\t",$op     &0xff);
-               push(@out,$tmp1);
-               push(@out,$tmp2);
-
-               $p2=&conv($p2);
-               $p1=&conv($p1);
-               &main'comment("$name $p2 $p1");
-               return;
-               }
-
-       push(@out,"\t$name\t");
-       $t=&conv($p2).",";
-       $l=length($t);
-       push(@out,$t);
-       $ll=4-($l+9)/8;
-       $tmp1=sprintf("\t" x $ll);
-       push(@out,$tmp1);
-       push(@out,&conv($p1)."\n");
-       }
-
-sub out1
-       {
-       local($name,$p1)=@_;
-       local($l,$t);
-       local(%special)=("bswapl",0x0FC8);
-
-       if ((defined($special{$name})) && defined($regs{$p1}))
-               {
-               $op=$special{$name}|$reg_val{$p1};
-               $tmp1=sprintf(".byte %d\n",($op>>8)&0xff);
-               $tmp2=sprintf(".byte %d\t",$op     &0xff);
-               push(@out,$tmp1);
-               push(@out,$tmp2);
-
-               $p2=&conv($p2);
-               $p1=&conv($p1);
-               &main'comment("$name $p2 $p1");
-               return;
-               }
-
-       push(@out,"\t$name\t".&conv($p1)."\n");
-       }
-
-sub out1p
-       {
-       local($name,$p1)=@_;
-       local($l,$t);
-
-       push(@out,"\t$name\t*".&conv($p1)."\n");
-       }
-
-sub out0
-       {
-       push(@out,"\t$_[0]\n");
-       }
-
-sub conv
-       {
-       local($p)=@_;
-
-#      $p =~ s/0x([0-9A-Fa-f]+)/0$1h/;
-
-       $p=$regs{$p} if (defined($regs{$p}));
-
-       $p =~ s/^(-{0,1}[0-9A-Fa-f]+)$/\$$1/;
-       $p =~ s/^(0x[0-9A-Fa-f]+)$/\$$1/;
-       return $p;
-       }
-
-sub main'file
-       {
-       local($file)=@_;
-
-       local($tmp)=<<"EOF";
-       .file   "$file.s"
-EOF
-       push(@out,$tmp);
-       }
-
-sub main'function_begin
-       {
-       local($func)=@_;
-
-       &main'external_label($func);
-       $func=$under.$func;
-
-       local($tmp)=<<"EOF";
-.text
-.globl $func
-EOF
-       push(@out,$tmp);
-       if ($main'cpp)
-               { $tmp=push(@out,"TYPE($func,\@function)\n"); }
-       elsif ($main'coff)
-               { $tmp=push(@out,".def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
-       elsif ($main'aout and !$main'pic)
-               { }
-       else    { $tmp=push(@out,".type\t$func,\@function\n"); }
-       push(@out,".align\t$align\n");
-       push(@out,"$func:\n");
-       $tmp=<<"EOF";
-       pushl   %ebp
-       pushl   %ebx
-       pushl   %esi
-       pushl   %edi
-
-EOF
-       push(@out,$tmp);
-       $stack=20;
-       }
-
-sub main'function_begin_B
-       {
-       local($func,$extra)=@_;
-
-       &main'external_label($func);
-       $func=$under.$func;
-
-       local($tmp)=<<"EOF";
-.text
-.globl $func
-EOF
-       push(@out,$tmp);
-       if ($main'cpp)
-               { push(@out,"TYPE($func,\@function)\n"); }
-       elsif ($main'coff)
-               { $tmp=push(@out,".def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
-       elsif ($main'aout and !$main'pic)
-               { }
-       else    { push(@out,".type      $func,\@function\n"); }
-       push(@out,".align\t$align\n");
-       push(@out,"$func:\n");
-       $stack=4;
-       }
-
-sub main'function_end
-       {
-       local($func)=@_;
-
-       $func=$under.$func;
-
-       local($tmp)=<<"EOF";
-       popl    %edi
-       popl    %esi
-       popl    %ebx
-       popl    %ebp
-       ret
-${dot}L_${func}_end:
-EOF
-       push(@out,$tmp);
-
-       if ($main'cpp)
-               { push(@out,"SIZE($func,${dot}L_${func}_end-$func)\n"); }
-       elsif ($main'coff or $main'aout)
-                { }
-       else    { push(@out,".size\t$func,${dot}L_${func}_end-$func\n"); }
-       push(@out,".ident       \"$func\"\n");
-       $stack=0;
-       %label=();
-       }
-
-sub main'function_end_A
-       {
-       local($func)=@_;
-
-       local($tmp)=<<"EOF";
-       popl    %edi
-       popl    %esi
-       popl    %ebx
-       popl    %ebp
-       ret
-EOF
-       push(@out,$tmp);
-       }
-
-sub main'function_end_B
-       {
-       local($func)=@_;
-
-       $func=$under.$func;
-
-       push(@out,"${dot}L_${func}_end:\n");
-       if ($main'cpp)
-               { push(@out,"SIZE($func,${dot}L_${func}_end-$func)\n"); }
-        elsif ($main'coff or $main'aout)
-                { }
-       else    { push(@out,".size\t$func,${dot}L_${func}_end-$func\n"); }
-       push(@out,".ident       \"$func\"\n");
-       $stack=0;
-       %label=();
-       }
-
-sub main'wparam
-       {
-       local($num)=@_;
-
-       return(&main'DWP($stack+$num*4,"esp","",0));
-       }
-
-sub main'stack_push
-       {
-       local($num)=@_;
-       $stack+=$num*4;
-       &main'sub("esp",$num*4);
-       }
-
-sub main'stack_pop
-       {
-       local($num)=@_;
-       $stack-=$num*4;
-       &main'add("esp",$num*4);
-       }
-
-sub main'swtmp
-       {
-       return(&main'DWP($_[0]*4,"esp","",0));
-       }
-
-# Should use swtmp, which is above esp.  Linix can trash the stack above esp
-#sub main'wtmp
-#      {
-#      local($num)=@_;
-#
-#      return(&main'DWP(-($num+1)*4,"esp","",0));
-#      }
-
-sub main'comment
-       {
-       if (!defined($com_start) or $main'elf)
-               {       # Regarding $main'elf above...
-                       # GNU and SVR4 as'es use different comment delimiters,
-               push(@out,"\n");        # so we just skip ELF comments...
-               return;
-               }
-       foreach (@_)
-               {
-               if (/^\s*$/)
-                       { push(@out,"\n"); }
-               else
-                       { push(@out,"\t$com_start $_ $com_end\n"); }
-               }
-       }
-
-sub main'public_label
-       {
-       $label{$_[0]}="${under}${_[0]}" if (!defined($label{$_[0]}));
-       push(@out,".globl\t$label{$_[0]}\n");
-       }
-
-sub main'label
-       {
-       if (!defined($label{$_[0]}))
-               {
-               $label{$_[0]}="${dot}${label}${_[0]}";
-               $label++;
-               }
-       return($label{$_[0]});
-       }
-
-sub main'set_label
-       {
-       if (!defined($label{$_[0]}))
-               {
-               $label{$_[0]}="${dot}${label}${_[0]}";
-               $label++;
-               }
-       if ($_[1]!=0)
-               {
-               if ($_[1]>1)    { main'align($_[1]);            }
-               else            { push(@out,".align $align\n"); }
-               }
-       push(@out,"$label{$_[0]}:\n");
-       }
-
-sub main'file_end
-       {
-       # try to detect if SSE2 or MMX extensions were used on ELF platform...
-       if ($main'elf && grep {/\b%[x]*mm[0-7]\b|OPENSSL_ia32cap_P\b/i} @out) {
-               local($tmp);
-
-               push (@out,"\n.section\t.bss\n");
-               push (@out,".comm\t${under}OPENSSL_ia32cap_P,4,4\n");
-
-               return;
-       }
-
-       if ($const ne "")
-               {
-               push(@out,".section .rodata\n");
-               push(@out,$const);
-               $const="";
-               }
-       }
-
-sub main'data_byte
-       {
-       push(@out,"\t.byte\t".join(',',@_)."\n");
-       }
-
-sub main'data_word
-       {
-       push(@out,"\t.long\t".join(',',@_)."\n");
-       }
-
-sub main'align
-       {
-       my $val=$_[0],$p2,$i;
-       if ($main'aout) {
-               for ($p2=0;$val!=0;$val>>=1) { $p2++; }
-               $val=$p2-1;
-               $val.=",0x90";
-       }
-       push(@out,".align\t$val\n");
-       }
-
-# debug output functions: puts, putx, printf
-
-sub main'puts
-       {
-       &pushvars();
-       &main'push('$Lstring' . ++$constl);
-       &main'call('puts');
-       $stack-=4;
-       &main'add("esp",4);
-       &popvars();
-
-       $const .= "Lstring$constl:\n\t.string \"@_[0]\"\n";
-       }
-
-sub main'putx
-       {
-       &pushvars();
-       &main'push($_[0]);
-       &main'push('$Lstring' . ++$constl);
-       &main'call('printf');
-       &main'add("esp",8);
-       $stack-=8;
-       &popvars();
-
-       $const .= "Lstring$constl:\n\t.string \"\%X\"\n";
-       }
-
-sub main'printf
-       {
-       $ostack = $stack;
-       &pushvars();
-       for ($i = @_ - 1; $i >= 0; $i--)
-               {
-               if ($i == 0) # change this to support %s format strings
-                       {
-                       &main'push('$Lstring' . ++$constl);
-                       $const .= "Lstring$constl:\n\t.string \"@_[$i]\"\n";
-                       }
-               else
-                       {
-                       if ($_[$i] =~ /([0-9]*)\(%esp\)/)
-                               {
-                               &main'push(($1 + $stack - $ostack) . '(%esp)');
-                               }
-                       else
-                               {
-                               &main'push($_[$i]);
-                               }
-                       }
-               }
-       &main'call('printf');
-       $stack-=4*@_;
-       &main'add("esp",4*@_);
-       &popvars();
-       }
-
-sub pushvars
-       {
-       &main'pushf();
-       &main'push("edx");
-       &main'push("ecx");
-       &main'push("eax");
-       }
-
-sub popvars
-       {
-       &main'pop("eax");
-       &main'pop("ecx");
-       &main'pop("edx");
-       &main'popf();
-       }
-
-sub main'picmeup
-       {
-       local($dst,$sym)=@_;
-       if ($main'cpp)
-               {
-               local($tmp)=<<___;
-#if (defined(ELF) || defined(SOL)) && defined(PIC)
-       call    1f
-1:     popl    $regs{$dst}
-       addl    \$_GLOBAL_OFFSET_TABLE_+[.-1b],$regs{$dst}
-       movl    $sym\@GOT($regs{$dst}),$regs{$dst}
-#else
-       leal    $sym,$regs{$dst}
-#endif
-___
-               push(@out,$tmp);
-               }
-       elsif ($main'pic && ($main'elf || $main'aout))
-               {
-               &main'call(&main'label("PIC_me_up"));
-               &main'set_label("PIC_me_up");
-               &main'blindpop($dst);
-               &main'add($dst,"\$${under}_GLOBAL_OFFSET_TABLE_+[.-".
-                               &main'label("PIC_me_up") . "]");
-               &main'mov($dst,&main'DWP($under.$sym."\@GOT",$dst));
-               }
-       else
-               {
-               &main'lea($dst,&main'DWP($sym));
-               }
-       }
-
-sub main'blindpop { &out1("popl",@_); }
-
-sub main'initseg
-       {
-       local($f)=@_;
-       local($tmp);
-       if ($main'elf)
-               {
-               $tmp=<<___;
-.section       .init
-       call    $under$f
-       jmp     .Linitalign
-.align $align
-.Linitalign:
-___
-               }
-       elsif ($main'coff)
-               {
-               $tmp=<<___;     # applies to both Cygwin and Mingw
-.section       .ctors
-.long  $under$f
-___
-               }
-       elsif ($main'aout)
-               {
-               local($ctor)="${under}_GLOBAL_\$I\$$f";
-               $tmp=".text\n";
-               $tmp.=".type    $ctor,\@function\n" if ($main'pic);
-               $tmp.=<<___;    # OpenBSD way...
-.globl $ctor
-.align 2
-$ctor:
-       jmp     $under$f
-___
-               }
-       push(@out,$tmp) if ($tmp);
-       }
-
-1;
index eed226b..3a7498f 100644 (file)
@@ -39,7 +39,7 @@ test:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -85,37 +85,36 @@ p12_add.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 p12_add.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 p12_add.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 p12_add.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-p12_add.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-p12_add.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-p12_add.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-p12_add.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-p12_add.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
-p12_add.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-p12_add.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-p12_add.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-p12_add.o: ../cryptlib.h p12_add.c
+p12_add.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+p12_add.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+p12_add.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+p12_add.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h
+p12_add.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+p12_add.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+p12_add.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+p12_add.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_add.c
 p12_asn.o: ../../e_os.h ../../include/openssl/asn1.h
 p12_asn.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 p12_asn.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 p12_asn.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 p12_asn.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 p12_asn.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-p12_asn.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-p12_asn.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-p12_asn.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-p12_asn.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h
-p12_asn.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-p12_asn.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-p12_asn.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-p12_asn.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_asn.c
+p12_asn.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+p12_asn.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+p12_asn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+p12_asn.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
+p12_asn.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+p12_asn.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+p12_asn.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+p12_asn.o: ../cryptlib.h p12_asn.c
 p12_attr.o: ../../e_os.h ../../include/openssl/asn1.h
 p12_attr.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 p12_attr.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 p12_attr.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 p12_attr.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-p12_attr.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-p12_attr.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-p12_attr.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+p12_attr.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+p12_attr.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+p12_attr.o: ../../include/openssl/opensslconf.h
 p12_attr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 p12_attr.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
 p12_attr.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
@@ -127,9 +126,9 @@ p12_crpt.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 p12_crpt.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 p12_crpt.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 p12_crpt.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-p12_crpt.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-p12_crpt.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-p12_crpt.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+p12_crpt.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+p12_crpt.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+p12_crpt.o: ../../include/openssl/opensslconf.h
 p12_crpt.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 p12_crpt.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
 p12_crpt.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
@@ -141,23 +140,22 @@ p12_crt.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 p12_crt.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 p12_crt.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 p12_crt.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-p12_crt.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-p12_crt.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-p12_crt.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-p12_crt.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-p12_crt.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
-p12_crt.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-p12_crt.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-p12_crt.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-p12_crt.o: ../cryptlib.h p12_crt.c
+p12_crt.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+p12_crt.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+p12_crt.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+p12_crt.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h
+p12_crt.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+p12_crt.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+p12_crt.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+p12_crt.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_crt.c
 p12_decr.o: ../../e_os.h ../../include/openssl/asn1.h
 p12_decr.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 p12_decr.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 p12_decr.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 p12_decr.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-p12_decr.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-p12_decr.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-p12_decr.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+p12_decr.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+p12_decr.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+p12_decr.o: ../../include/openssl/opensslconf.h
 p12_decr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 p12_decr.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
 p12_decr.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
@@ -169,9 +167,9 @@ p12_init.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 p12_init.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 p12_init.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 p12_init.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-p12_init.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-p12_init.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-p12_init.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+p12_init.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+p12_init.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+p12_init.o: ../../include/openssl/opensslconf.h
 p12_init.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 p12_init.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
 p12_init.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
@@ -184,22 +182,22 @@ p12_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 p12_key.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 p12_key.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 p12_key.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-p12_key.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-p12_key.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-p12_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-p12_key.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h
-p12_key.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-p12_key.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-p12_key.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-p12_key.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_key.c
+p12_key.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+p12_key.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+p12_key.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+p12_key.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
+p12_key.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+p12_key.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+p12_key.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+p12_key.o: ../cryptlib.h p12_key.c
 p12_kiss.o: ../../e_os.h ../../include/openssl/asn1.h
 p12_kiss.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 p12_kiss.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 p12_kiss.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 p12_kiss.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-p12_kiss.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-p12_kiss.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-p12_kiss.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+p12_kiss.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+p12_kiss.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+p12_kiss.o: ../../include/openssl/opensslconf.h
 p12_kiss.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 p12_kiss.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
 p12_kiss.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
@@ -211,10 +209,9 @@ p12_mutl.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 p12_mutl.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 p12_mutl.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 p12_mutl.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-p12_mutl.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-p12_mutl.o: ../../include/openssl/hmac.h ../../include/openssl/lhash.h
-p12_mutl.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-p12_mutl.o: ../../include/openssl/opensslconf.h
+p12_mutl.o: ../../include/openssl/evp.h ../../include/openssl/hmac.h
+p12_mutl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+p12_mutl.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 p12_mutl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 p12_mutl.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
 p12_mutl.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
@@ -226,9 +223,8 @@ p12_npas.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 p12_npas.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 p12_npas.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 p12_npas.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-p12_npas.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-p12_npas.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-p12_npas.o: ../../include/openssl/opensslconf.h
+p12_npas.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+p12_npas.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 p12_npas.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 p12_npas.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
 p12_npas.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
@@ -241,53 +237,50 @@ p12_p8d.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 p12_p8d.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 p12_p8d.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 p12_p8d.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-p12_p8d.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-p12_p8d.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-p12_p8d.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-p12_p8d.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-p12_p8d.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
-p12_p8d.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-p12_p8d.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-p12_p8d.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-p12_p8d.o: ../cryptlib.h p12_p8d.c
+p12_p8d.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+p12_p8d.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+p12_p8d.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+p12_p8d.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h
+p12_p8d.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+p12_p8d.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+p12_p8d.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+p12_p8d.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_p8d.c
 p12_p8e.o: ../../e_os.h ../../include/openssl/asn1.h
 p12_p8e.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 p12_p8e.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 p12_p8e.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 p12_p8e.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-p12_p8e.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-p12_p8e.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-p12_p8e.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-p12_p8e.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-p12_p8e.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
-p12_p8e.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-p12_p8e.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-p12_p8e.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-p12_p8e.o: ../cryptlib.h p12_p8e.c
+p12_p8e.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+p12_p8e.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+p12_p8e.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+p12_p8e.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h
+p12_p8e.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+p12_p8e.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+p12_p8e.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+p12_p8e.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_p8e.c
 p12_utl.o: ../../e_os.h ../../include/openssl/asn1.h
 p12_utl.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 p12_utl.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 p12_utl.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 p12_utl.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-p12_utl.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-p12_utl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-p12_utl.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-p12_utl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-p12_utl.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
-p12_utl.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-p12_utl.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-p12_utl.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-p12_utl.o: ../cryptlib.h p12_utl.c
+p12_utl.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+p12_utl.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+p12_utl.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+p12_utl.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h
+p12_utl.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+p12_utl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+p12_utl.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+p12_utl.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_utl.c
 pk12err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
 pk12err.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 pk12err.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 pk12err.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 pk12err.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-pk12err.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-pk12err.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-pk12err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-pk12err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h
-pk12err.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-pk12err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-pk12err.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-pk12err.o: ../../include/openssl/x509_vfy.h pk12err.c
+pk12err.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+pk12err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+pk12err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+pk12err.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
+pk12err.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+pk12err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+pk12err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+pk12err.o: pk12err.c
index 1f3e378..27ac5fa 100644 (file)
@@ -106,6 +106,7 @@ PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, const char *pass,
             PKCS8_PRIV_KEY_INFO *p8)
 {
        PKCS12_SAFEBAG *bag;
+       const EVP_CIPHER *pbe_ciph;
 
        /* Set up the safe bag */
        if (!(bag = PKCS12_SAFEBAG_new())) {
@@ -114,8 +115,14 @@ PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, const char *pass,
        }
 
        bag->type = OBJ_nid2obj(NID_pkcs8ShroudedKeyBag);
+
+       pbe_ciph = EVP_get_cipherbynid(pbe_nid);
+
+       if (pbe_ciph)
+               pbe_nid = -1;
+
        if (!(bag->value.shkeybag = 
-         PKCS8_encrypt(pbe_nid, NULL, pass, passlen, salt, saltlen, iter,
+         PKCS8_encrypt(pbe_nid, pbe_ciph, pass, passlen, salt, saltlen, iter,
                                                                         p8))) {
                PKCS12err(PKCS12_F_PKCS12_MAKE_SHKEYBAG, ERR_R_MALLOC_FAILURE);
                return NULL;
@@ -164,6 +171,7 @@ PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen,
 {
        PKCS7 *p7;
        X509_ALGOR *pbe;
+       const EVP_CIPHER *pbe_ciph;
        if (!(p7 = PKCS7_new())) {
                PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE);
                return NULL;
@@ -173,7 +181,15 @@ PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen,
                                PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE);
                return NULL;
        }
-       if (!(pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen))) {
+
+       pbe_ciph = EVP_get_cipherbynid(pbe_nid);
+
+       if (pbe_ciph)
+               pbe = PKCS5_pbe2_set(pbe_ciph, iter, salt, saltlen);
+       else
+               pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen);
+
+       if (!pbe) {
                PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE);
                return NULL;
        }
index 856933d..e4d9c25 100644 (file)
 #include "cryptlib.h"
 #include <openssl/pkcs12.h>
 
-#ifdef OPENSSL_SYS_NETWARE
-/* Rename these functions to avoid name clashes on NetWare OS */
-#define uni2asc OPENSSL_uni2asc
-#define asc2uni OPENSSL_asc2uni
-#endif
-
 /* Add a local keyid to a safebag */
 
 int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name,
@@ -145,7 +139,7 @@ char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag)
        ASN1_TYPE *atype;
        if (!(atype = PKCS12_get_attr(bag, NID_friendlyName))) return NULL;
        if (atype->type != V_ASN1_BMPSTRING) return NULL;
-       return uni2asc(atype->value.bmpstring->data,
+       return OPENSSL_uni2asc(atype->value.bmpstring->data,
                                 atype->value.bmpstring->length);
 }
 
index f8b952e..b71d07b 100644 (file)
 #include "cryptlib.h"
 #include <openssl/pkcs12.h>
 
-/* PKCS#12 specific PBE functions */
+/* PKCS#12 PBE algorithms now in static table */
 
 void PKCS12_PBE_add(void)
 {
-#ifndef OPENSSL_NO_RC4
-EVP_PBE_alg_add(NID_pbe_WithSHA1And128BitRC4, EVP_rc4(), EVP_sha1(),
-                                                        PKCS12_PBE_keyivgen);
-EVP_PBE_alg_add(NID_pbe_WithSHA1And40BitRC4, EVP_rc4_40(), EVP_sha1(),
-                                                        PKCS12_PBE_keyivgen);
-#endif
-#ifndef OPENSSL_NO_DES
-EVP_PBE_alg_add(NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
-                       EVP_des_ede3_cbc(), EVP_sha1(), PKCS12_PBE_keyivgen);
-EVP_PBE_alg_add(NID_pbe_WithSHA1And2_Key_TripleDES_CBC, 
-                       EVP_des_ede_cbc(), EVP_sha1(), PKCS12_PBE_keyivgen);
-#endif
-#ifndef OPENSSL_NO_RC2
-EVP_PBE_alg_add(NID_pbe_WithSHA1And128BitRC2_CBC, EVP_rc2_cbc(),
-                                       EVP_sha1(), PKCS12_PBE_keyivgen);
-EVP_PBE_alg_add(NID_pbe_WithSHA1And40BitRC2_CBC, EVP_rc2_40_cbc(),
-                                       EVP_sha1(), PKCS12_PBE_keyivgen);
-#endif
 }
 
 int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
index 9522342..96b131d 100644 (file)
 #include <stdio.h>
 #include "cryptlib.h"
 #include <openssl/pkcs12.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
 
 
 static int pkcs12_add_bag(STACK_OF(PKCS12_SAFEBAG) **pbags, PKCS12_SAFEBAG *bag);
@@ -94,14 +90,7 @@ PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,
 
        /* Set defaults */
        if (!nid_cert)
-               {
-#ifdef OPENSSL_FIPS
-               if (FIPS_mode())
-                       nid_cert = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
-               else
-#endif
                nid_cert = NID_pbe_WithSHA1And40BitRC2_CBC;
-               }
        if (!nid_key)
                nid_key = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
        if (!iter)
index 03cbcd8..424203f 100644 (file)
@@ -69,12 +69,6 @@ extern BIO *bio_err;
 void h__dump (unsigned char *p, int len);
 #endif
 
-#ifdef OPENSSL_SYS_NETWARE
-/* Rename these functions to avoid name clashes on NetWare OS */
-#define uni2asc OPENSSL_uni2asc
-#define asc2uni OPENSSL_asc2uni
-#endif
-
 /* PKCS12 compatible key/IV generation */
 #ifndef min
 #define min(a,b) ((a) < (b) ? (a) : (b))
@@ -87,15 +81,18 @@ int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt,
        int ret;
        unsigned char *unipass;
        int uniplen;
+
        if(!pass) {
                unipass = NULL;
                uniplen = 0;
-       } else if (!asc2uni(pass, passlen, &unipass, &uniplen)) {
+       } else if (!OPENSSL_asc2uni(pass, passlen, &unipass, &uniplen)) {
                PKCS12err(PKCS12_F_PKCS12_KEY_GEN_ASC,ERR_R_MALLOC_FAILURE);
                return 0;
        }
        ret = PKCS12_key_gen_uni(unipass, uniplen, salt, saltlen,
                                                 id, iter, n, out, md_type);
+       if (ret <= 0)
+           return 0;
        if(unipass) {
                OPENSSL_cleanse(unipass, uniplen);      /* Clear password from memory */
                OPENSSL_free(unipass);
@@ -136,6 +133,8 @@ int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt,
 #endif
        v = EVP_MD_block_size (md_type);
        u = EVP_MD_size (md_type);
+       if (u < 0)
+           return 0;
        D = OPENSSL_malloc (v);
        Ai = OPENSSL_malloc (u);
        B = OPENSSL_malloc (v + 1);
index 5c4c6ec..292cc3e 100644 (file)
 /* Simplified PKCS#12 routines */
 
 static int parse_pk12( PKCS12 *p12, const char *pass, int passlen,
-               EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca);
+               EVP_PKEY **pkey, STACK_OF(X509) *ocerts);
 
 static int parse_bags( STACK_OF(PKCS12_SAFEBAG) *bags, const char *pass,
-                      int passlen, EVP_PKEY **pkey, X509 **cert,
-                      STACK_OF(X509) **ca, ASN1_OCTET_STRING **keyid,
-                      char *keymatch);
+                      int passlen, EVP_PKEY **pkey, STACK_OF(X509) *ocerts);
 
 static int parse_bag( PKCS12_SAFEBAG *bag, const char *pass, int passlen,
-                       EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca,
-                       ASN1_OCTET_STRING **keyid, char *keymatch);
+                       EVP_PKEY **pkey, STACK_OF(X509) *ocerts);
 
 /* Parse and decrypt a PKCS#12 structure returning user key, user cert
  * and other (CA) certs. Note either ca should be NULL, *ca should be NULL,
@@ -83,24 +80,20 @@ static int parse_bag( PKCS12_SAFEBAG *bag, const char *pass, int passlen,
 int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
             STACK_OF(X509) **ca)
 {
-
+       STACK_OF(X509) *ocerts = NULL;
+       X509 *x = NULL;
        /* Check for NULL PKCS12 structure */
 
-       if(!p12) {
+       if(!p12)
+               {
                PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_INVALID_NULL_PKCS12_POINTER);
                return 0;
-       }
-
-       /* Allocate stack for ca certificates if needed */
-       if ((ca != NULL) && (*ca == NULL)) {
-               if (!(*ca = sk_X509_new_null())) {
-                       PKCS12err(PKCS12_F_PKCS12_PARSE,ERR_R_MALLOC_FAILURE);
-                       return 0;
                }
-       }
 
-       if(pkey) *pkey = NULL;
-       if(cert) *cert = NULL;
+       if(pkey)
+               *pkey = NULL;
+       if(cert)
+               *cert = NULL;
 
        /* Check the mac */
 
@@ -122,19 +115,61 @@ int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
                goto err;
        }
 
-       if (!parse_pk12 (p12, pass, -1, pkey, cert, ca))
+       /* Allocate stack for other certificates */
+       ocerts = sk_X509_new_null();
+
+       if (!ocerts)
+               {
+               PKCS12err(PKCS12_F_PKCS12_PARSE,ERR_R_MALLOC_FAILURE);
+               return 0;
+               }
+
+       if (!parse_pk12 (p12, pass, -1, pkey, ocerts))
                {
                PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_PARSE_ERROR);
                goto err;
                }
 
+       while ((x = sk_X509_pop(ocerts)))
+               {
+               if (pkey && *pkey && cert && !*cert)
+                       {
+                       if (X509_check_private_key(x, *pkey))
+                               {
+                               *cert = x;
+                               x = NULL;
+                               }
+                       }
+
+               if (ca && x)
+                       {
+                       if (!*ca)
+                               *ca = sk_X509_new_null();
+                       if (!*ca)
+                               goto err;
+                       if (!sk_X509_push(*ca, x))
+                               goto err;
+                       x = NULL;
+                       }
+               if (x)
+                       X509_free(x);
+               }
+
+       if (ocerts)
+               sk_X509_pop_free(ocerts, X509_free);
+
        return 1;
 
  err:
 
-       if (pkey && *pkey) EVP_PKEY_free(*pkey);
-       if (cert && *cert) X509_free(*cert);
-       if (ca) sk_X509_pop_free(*ca, X509_free);
+       if (pkey && *pkey)
+               EVP_PKEY_free(*pkey);
+       if (cert && *cert)
+               X509_free(*cert);
+       if (x)
+               X509_free(*cert);
+       if (ocerts)
+               sk_X509_pop_free(ocerts, X509_free);
        return 0;
 
 }
@@ -142,15 +177,13 @@ int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
 /* Parse the outer PKCS#12 structure */
 
 static int parse_pk12(PKCS12 *p12, const char *pass, int passlen,
-            EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca)
+            EVP_PKEY **pkey, STACK_OF(X509) *ocerts)
 {
        STACK_OF(PKCS7) *asafes;
        STACK_OF(PKCS12_SAFEBAG) *bags;
        int i, bagnid;
        PKCS7 *p7;
-       ASN1_OCTET_STRING *keyid = NULL;
 
-       char keymatch = 0;
        if (!(asafes = PKCS12_unpack_authsafes (p12))) return 0;
        for (i = 0; i < sk_PKCS7_num (asafes); i++) {
                p7 = sk_PKCS7_value (asafes, i);
@@ -164,8 +197,7 @@ static int parse_pk12(PKCS12 *p12, const char *pass, int passlen,
                        sk_PKCS7_pop_free(asafes, PKCS7_free);
                        return 0;
                }
-               if (!parse_bags(bags, pass, passlen, pkey, cert, ca,
-                                                        &keyid, &keymatch)) {
+               if (!parse_bags(bags, pass, passlen, pkey, ocerts)) {
                        sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
                        sk_PKCS7_pop_free(asafes, PKCS7_free);
                        return 0;
@@ -173,89 +205,65 @@ static int parse_pk12(PKCS12 *p12, const char *pass, int passlen,
                sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
        }
        sk_PKCS7_pop_free(asafes, PKCS7_free);
-       if (keyid) M_ASN1_OCTET_STRING_free(keyid);
        return 1;
 }
 
 
 static int parse_bags(STACK_OF(PKCS12_SAFEBAG) *bags, const char *pass,
-                     int passlen, EVP_PKEY **pkey, X509 **cert,
-                     STACK_OF(X509) **ca, ASN1_OCTET_STRING **keyid,
-                     char *keymatch)
+                     int passlen, EVP_PKEY **pkey, STACK_OF(X509) *ocerts)
 {
        int i;
        for (i = 0; i < sk_PKCS12_SAFEBAG_num(bags); i++) {
                if (!parse_bag(sk_PKCS12_SAFEBAG_value (bags, i),
-                        pass, passlen, pkey, cert, ca, keyid,
-                                                        keymatch)) return 0;
+                                pass, passlen, pkey, ocerts))
+                       return 0;
        }
        return 1;
 }
 
-#define MATCH_KEY  0x1
-#define MATCH_CERT 0x2
-#define MATCH_ALL  0x3
-
 static int parse_bag(PKCS12_SAFEBAG *bag, const char *pass, int passlen,
-                    EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca,
-                    ASN1_OCTET_STRING **keyid,
-                    char *keymatch)
+                    EVP_PKEY **pkey, STACK_OF(X509) *ocerts)
 {
        PKCS8_PRIV_KEY_INFO *p8;
        X509 *x509;
-       ASN1_OCTET_STRING *lkey = NULL, *ckid = NULL;
        ASN1_TYPE *attrib;
        ASN1_BMPSTRING *fname = NULL;
+       ASN1_OCTET_STRING *lkid = NULL;
 
        if ((attrib = PKCS12_get_attr (bag, NID_friendlyName)))
                fname = attrib->value.bmpstring;
 
-       if ((attrib = PKCS12_get_attr (bag, NID_localKeyID))) {
-               lkey = attrib->value.octet_string;
-               ckid = lkey;
-       }
+       if ((attrib = PKCS12_get_attr (bag, NID_localKeyID)))
+               lkid = attrib->value.octet_string;
 
-       /* Check for any local key id matching (if needed) */
-       if (lkey && ((*keymatch & MATCH_ALL) != MATCH_ALL)) {
-               if (*keyid) {
-                       if (M_ASN1_OCTET_STRING_cmp(*keyid, lkey)) lkey = NULL;
-               } else {
-                       if (!(*keyid = M_ASN1_OCTET_STRING_dup(lkey))) {
-                               PKCS12err(PKCS12_F_PARSE_BAG,ERR_R_MALLOC_FAILURE);
-                               return 0;
-                   }
-               }
-       }
-       
        switch (M_PKCS12_bag_type(bag))
        {
        case NID_keyBag:
-               if (!lkey || !pkey) return 1;   
-               if (!(*pkey = EVP_PKCS82PKEY(bag->value.keybag))) return 0;
-               *keymatch |= MATCH_KEY;
+               if (!pkey || *pkey)
+                       return 1;       
+               if (!(*pkey = EVP_PKCS82PKEY(bag->value.keybag)))
+                       return 0;
        break;
 
        case NID_pkcs8ShroudedKeyBag:
-               if (!lkey || !pkey) return 1;   
+               if (!pkey || *pkey)
+                       return 1;       
                if (!(p8 = PKCS12_decrypt_skey(bag, pass, passlen)))
                                return 0;
                *pkey = EVP_PKCS82PKEY(p8);
                PKCS8_PRIV_KEY_INFO_free(p8);
                if (!(*pkey)) return 0;
-               *keymatch |= MATCH_KEY;
        break;
 
        case NID_certBag:
                if (M_PKCS12_cert_bag_type(bag) != NID_x509Certificate )
-                                                                return 1;
-               if (!(x509 = PKCS12_certbag2x509(bag))) return 0;
-               if(ckid)
+                       return 1;
+               if (!(x509 = PKCS12_certbag2x509(bag)))
+                       return 0;
+               if(lkid && !X509_keyid_set1(x509, lkid->data, lkid->length))
                        {
-                       if (!X509_keyid_set1(x509, ckid->data, ckid->length))
-                               {
-                               X509_free(x509);
-                               return 0;
-                               }
+                       X509_free(x509);
+                       return 0;
                        }
                if(fname) {
                        int len, r;
@@ -272,20 +280,17 @@ static int parse_bag(PKCS12_SAFEBAG *bag, const char *pass, int passlen,
                        }
                }
 
+               if(!sk_X509_push(ocerts, x509))
+                       {
+                       X509_free(x509);
+                       return 0;
+                       }
 
-               if (lkey) {
-                       *keymatch |= MATCH_CERT;
-                       if (cert) *cert = x509;
-                       else X509_free(x509);
-               } else {
-                       if(ca) sk_X509_push (*ca, x509);
-                       else X509_free(x509);
-               }
        break;
 
        case NID_safeContentsBag:
                return parse_bags(bag->value.safes, pass, passlen,
-                                       pkey, cert, ca, keyid, keymatch);
+                                       pkey, ocerts);
        break;
 
        default:
index 70bfef6..9ab740d 100644 (file)
@@ -71,6 +71,7 @@ int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
        HMAC_CTX hmac;
        unsigned char key[EVP_MAX_MD_SIZE], *salt;
        int saltlen, iter;
+       int md_size;
 
        if (!PKCS7_type_is_data(p12->authsafes))
                {
@@ -87,13 +88,16 @@ int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
                PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_UNKNOWN_DIGEST_ALGORITHM);
                return 0;
        }
+       md_size = EVP_MD_size(md_type);
+       if (md_size < 0)
+           return 0;
        if(!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_MAC_ID, iter,
-                                EVP_MD_size(md_type), key, md_type)) {
+                                md_size, key, md_type)) {
                PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_KEY_GEN_ERROR);
                return 0;
        }
        HMAC_CTX_init(&hmac);
-       HMAC_Init_ex(&hmac, key, EVP_MD_size(md_type), md_type, NULL);
+       HMAC_Init_ex(&hmac, key, md_size, md_type, NULL);
        HMAC_Update(&hmac, p12->authsafes->d.data->data,
                                         p12->authsafes->d.data->length);
        HMAC_Final(&hmac, mac, maclen);
index 2edbf90..59c6f45 100644 (file)
 #include "cryptlib.h"
 #include <openssl/pkcs12.h>
 
-#ifdef OPENSSL_SYS_NETWARE
-/* Rename these functions to avoid name clashes on NetWare OS */
-#define uni2asc OPENSSL_uni2asc
-#define asc2uni OPENSSL_asc2uni
-#endif
-
 /* Cheap and nasty Unicode stuff */
 
-unsigned char *asc2uni(const char *asc, int asclen, unsigned char **uni, int *unilen)
+unsigned char *OPENSSL_asc2uni(const char *asc, int asclen, unsigned char **uni, int *unilen)
 {
        int ulen, i;
        unsigned char *unitmp;
@@ -87,7 +81,7 @@ unsigned char *asc2uni(const char *asc, int asclen, unsigned char **uni, int *un
        return unitmp;
 }
 
-char *uni2asc(unsigned char *uni, int unilen)
+char *OPENSSL_uni2asc(unsigned char *uni, int unilen)
 {
        int asclen, i;
        char *asctmp;
index 07a1fb6..f6ddf2d 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/pkcs12/pk12err.c */
 /* ====================================================================
- * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
index 78317fb..b17eb9f 100644 (file)
@@ -108,8 +108,6 @@ PKCS12_MAC_DATA *mac;
 PKCS7 *authsafes;
 } PKCS12;
 
-PREDECLARE_STACK_OF(PKCS12_SAFEBAG)
-
 typedef struct {
 ASN1_OBJECT *type;
 union {
@@ -232,14 +230,9 @@ int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen,
                   const EVP_MD *md_type);
 int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt,
                                         int saltlen, const EVP_MD *md_type);
-#if defined(NETWARE) || defined(OPENSSL_SYS_NETWARE)
-/* Rename these functions to avoid name clashes on NetWare OS */
 unsigned char *OPENSSL_asc2uni(const char *asc, int asclen, unsigned char **uni, int *unilen);
 char *OPENSSL_uni2asc(unsigned char *uni, int unilen);
-#else
-unsigned char *asc2uni(const char *asc, int asclen, unsigned char **uni, int *unilen);
-char *uni2asc(unsigned char *uni, int unilen);
-#endif
+
 DECLARE_ASN1_FUNCTIONS(PKCS12)
 DECLARE_ASN1_FUNCTIONS(PKCS12_MAC_DATA)
 DECLARE_ASN1_FUNCTIONS(PKCS12_SAFEBAG)
index 790d8ed..56dc682 100644 (file)
@@ -21,9 +21,9 @@ APPS=
 
 LIB=$(TOP)/libcrypto.a
 LIBSRC=        pk7_asn1.c pk7_lib.c pkcs7err.c pk7_doit.c pk7_smime.c pk7_attr.c \
-       pk7_mime.c
+       pk7_mime.c bio_pk7.c
 LIBOBJ= pk7_asn1.o pk7_lib.o pkcs7err.o pk7_doit.o pk7_smime.o pk7_attr.o \
-       pk7_mime.o
+       pk7_mime.o bio_pk7.o
 
 SRC= $(LIBSRC)
 
@@ -54,7 +54,7 @@ verify: verify.o example.o lib
        $(CC) $(CFLAGS) -o verify verify.o $(PEX_LIBS) example.o $(LIB) $(EX_LIBS)
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -95,26 +95,31 @@ clean:
 
 # DO NOT DELETE THIS LINE -- make depend depends on it.
 
+bio_pk7.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
+bio_pk7.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+bio_pk7.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+bio_pk7.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+bio_pk7.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+bio_pk7.o: ../../include/openssl/symhacks.h bio_pk7.c
 pk7_asn1.o: ../../e_os.h ../../include/openssl/asn1.h
 pk7_asn1.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 pk7_asn1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 pk7_asn1.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 pk7_asn1.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 pk7_asn1.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-pk7_asn1.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-pk7_asn1.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-pk7_asn1.o: ../../include/openssl/opensslconf.h
+pk7_asn1.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+pk7_asn1.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 pk7_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 pk7_asn1.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 pk7_asn1.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
 pk7_asn1.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
 pk7_asn1.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pk7_asn1.c
-pk7_attr.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-pk7_attr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
-pk7_attr.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-pk7_attr.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
-pk7_attr.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-pk7_attr.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
+pk7_attr.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
+pk7_attr.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
+pk7_attr.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+pk7_attr.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+pk7_attr.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
+pk7_attr.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
 pk7_attr.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
 pk7_attr.o: ../../include/openssl/opensslconf.h
 pk7_attr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
@@ -129,9 +134,8 @@ pk7_doit.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 pk7_doit.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 pk7_doit.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 pk7_doit.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-pk7_doit.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-pk7_doit.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-pk7_doit.o: ../../include/openssl/opensslconf.h
+pk7_doit.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+pk7_doit.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 pk7_doit.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 pk7_doit.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
 pk7_doit.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
@@ -143,22 +147,22 @@ pk7_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 pk7_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 pk7_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 pk7_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-pk7_lib.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-pk7_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-pk7_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-pk7_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-pk7_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-pk7_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-pk7_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-pk7_lib.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pk7_lib.c
+pk7_lib.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+pk7_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+pk7_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+pk7_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+pk7_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+pk7_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+pk7_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+pk7_lib.o: ../asn1/asn1_locl.h ../cryptlib.h pk7_lib.c
 pk7_mime.o: ../../e_os.h ../../include/openssl/asn1.h
 pk7_mime.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 pk7_mime.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 pk7_mime.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 pk7_mime.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-pk7_mime.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-pk7_mime.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-pk7_mime.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+pk7_mime.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+pk7_mime.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+pk7_mime.o: ../../include/openssl/opensslconf.h
 pk7_mime.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 pk7_mime.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
 pk7_mime.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
@@ -171,8 +175,8 @@ pk7_smime.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 pk7_smime.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 pk7_smime.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 pk7_smime.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-pk7_smime.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-pk7_smime.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+pk7_smime.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+pk7_smime.o: ../../include/openssl/objects.h
 pk7_smime.o: ../../include/openssl/opensslconf.h
 pk7_smime.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 pk7_smime.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
similarity index 84%
rename from deps/openssl/openssl/crypto/rc4/rc4_fblk.c
rename to deps/openssl/openssl/crypto/pkcs7/bio_pk7.c
index 1b2a429..c8d06d6 100644 (file)
@@ -1,4 +1,4 @@
-/* crypto/rc4/rc4_fblk.c */
+/* bio_pk7.c */
 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
  * project.
  */
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  * OF THE POSSIBILITY OF SUCH DAMAGE.
  * ====================================================================
+ *
  */
 
+#include <openssl/asn1.h>
+#include <openssl/pkcs7.h>
+#include <openssl/bio.h>
 
-#include <openssl/rc4.h>
-#include "rc4_locl.h"
-#include <openssl/opensslv.h>
-#include <openssl/crypto.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
+#ifndef OPENSSL_SYSNAME_NETWARE
+#include <memory.h>
 #endif
+#include <stdio.h>
 
-/* FIPS mode blocking for RC4 has to be done separately since RC4_set_key
- * may be implemented in an assembly language file.
- */
+/* Streaming encode support for PKCS#7 */
 
-#ifdef OPENSSL_FIPS
-void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data)
+BIO *BIO_new_PKCS7(BIO *out, PKCS7 *p7) 
        {
-       if (FIPS_mode())
-               FIPS_BAD_ABORT(RC4)
-       private_RC4_set_key(key, len, data);
+       return BIO_new_NDEF(out, (ASN1_VALUE *)p7, ASN1_ITEM_rptr(PKCS7));
        }
-#endif
-
index 1f70d31..b7ec288 100644 (file)
@@ -77,10 +77,39 @@ ASN1_ADB(PKCS7) = {
        ADB_ENTRY(NID_pkcs7_encrypted, ASN1_NDEF_EXP_OPT(PKCS7, d.encrypted, PKCS7_ENCRYPT, 0))
 } ASN1_ADB_END(PKCS7, 0, type, 0, &p7default_tt, NULL);
 
-ASN1_NDEF_SEQUENCE(PKCS7) = {
+/* PKCS#7 streaming support */
+static int pk7_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
+                                                       void *exarg)
+{
+       ASN1_STREAM_ARG *sarg = exarg;
+       PKCS7 **pp7 = (PKCS7 **)pval;
+
+       switch(operation)
+               {
+
+               case ASN1_OP_STREAM_PRE:
+               if (PKCS7_stream(&sarg->boundary, *pp7) <= 0)
+                       return 0;
+               case ASN1_OP_DETACHED_PRE:
+               sarg->ndef_bio = PKCS7_dataInit(*pp7, sarg->out);
+               if (!sarg->ndef_bio)
+                       return 0;
+               break;
+
+               case ASN1_OP_STREAM_POST:
+               case ASN1_OP_DETACHED_POST:
+               if (PKCS7_dataFinal(*pp7, sarg->ndef_bio) <= 0)
+                       return 0;
+               break;
+
+               }
+       return 1;
+}
+
+ASN1_NDEF_SEQUENCE_cb(PKCS7, pk7_cb) = {
        ASN1_SIMPLE(PKCS7, type, ASN1_OBJECT),
        ASN1_ADB_OBJECT(PKCS7)
-}ASN1_NDEF_SEQUENCE_END(PKCS7)
+}ASN1_NDEF_SEQUENCE_END_cb(PKCS7, PKCS7)
 
 IMPLEMENT_ASN1_FUNCTIONS(PKCS7)
 IMPLEMENT_ASN1_NDEF_FUNCTION(PKCS7)
@@ -98,7 +127,8 @@ ASN1_NDEF_SEQUENCE(PKCS7_SIGNED) = {
 IMPLEMENT_ASN1_FUNCTIONS(PKCS7_SIGNED)
 
 /* Minor tweak to operation: free up EVP_PKEY */
-static int si_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
+static int si_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
+                                                       void *exarg)
 {
        if(operation == ASN1_OP_FREE_POST) {
                PKCS7_SIGNER_INFO *si = (PKCS7_SIGNER_INFO *)*pval;
@@ -140,7 +170,8 @@ ASN1_NDEF_SEQUENCE(PKCS7_ENVELOPE) = {
 IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ENVELOPE)
 
 /* Minor tweak to operation: free up X509 */
-static int ri_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
+static int ri_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
+                                                               void *exarg)
 {
        if(operation == ASN1_OP_FREE_POST) {
                PKCS7_RECIP_INFO *ri = (PKCS7_RECIP_INFO *)*pval;
@@ -161,7 +192,7 @@ IMPLEMENT_ASN1_FUNCTIONS(PKCS7_RECIP_INFO)
 ASN1_NDEF_SEQUENCE(PKCS7_ENC_CONTENT) = {
        ASN1_SIMPLE(PKCS7_ENC_CONTENT, content_type, ASN1_OBJECT),
        ASN1_SIMPLE(PKCS7_ENC_CONTENT, algorithm, X509_ALGOR),
-       ASN1_IMP_OPT(PKCS7_ENC_CONTENT, enc_data, ASN1_OCTET_STRING, 0)
+       ASN1_IMP_OPT(PKCS7_ENC_CONTENT, enc_data, ASN1_OCTET_STRING_NDEF, 0)
 } ASN1_NDEF_SEQUENCE_END(PKCS7_ENC_CONTENT)
 
 IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ENC_CONTENT)
@@ -212,3 +243,5 @@ ASN1_ITEM_TEMPLATE(PKCS7_ATTR_VERIFY) =
        ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_IMPTAG | ASN1_TFLG_UNIVERSAL,
                                V_ASN1_SET, PKCS7_ATTRIBUTES, X509_ATTRIBUTE)
 ASN1_ITEM_TEMPLATE_END(PKCS7_ATTR_VERIFY)
+
+IMPLEMENT_ASN1_PRINT_FUNCTION(PKCS7)
index d549717..a97db51 100644 (file)
@@ -60,6 +60,7 @@
 #include <stdlib.h>
 #include <openssl/bio.h>
 #include <openssl/asn1.h>
+#include <openssl/asn1t.h>
 #include <openssl/pem.h>
 #include <openssl/pkcs7.h>
 #include <openssl/x509.h>
 int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, STACK_OF(X509_ALGOR) *cap)
 {
        ASN1_STRING *seq;
-       unsigned char *p, *pp;
-       int len;
-       len=i2d_ASN1_SET_OF_X509_ALGOR(cap,NULL,i2d_X509_ALGOR,
-                                      V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL,
-                                      IS_SEQUENCE);
-       if(!(pp=(unsigned char *)OPENSSL_malloc(len))) {
-               PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE);
-               return 0;
-       }
-       p=pp;
-       i2d_ASN1_SET_OF_X509_ALGOR(cap,&p,i2d_X509_ALGOR, V_ASN1_SEQUENCE,
-                                  V_ASN1_UNIVERSAL, IS_SEQUENCE);
        if(!(seq = ASN1_STRING_new())) {
                PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE);
                return 0;
        }
-       if(!ASN1_STRING_set (seq, pp, len)) {
-               PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE);
-               return 0;
-       }
-       OPENSSL_free (pp);
+       seq->length = ASN1_item_i2d((ASN1_VALUE *)cap,&seq->data,
+                               ASN1_ITEM_rptr(X509_ALGORS));
         return PKCS7_add_signed_attribute(si, NID_SMIMECapabilities,
                                                        V_ASN1_SEQUENCE, seq);
 }
@@ -102,10 +88,9 @@ STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si)
        if (!cap || (cap->type != V_ASN1_SEQUENCE))
                return NULL;
        p = cap->value.sequence->data;
-       return d2i_ASN1_SET_OF_X509_ALGOR(NULL, &p,
-                                         cap->value.sequence->length,
-                                         d2i_X509_ALGOR, X509_ALGOR_free,
-                                         V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
+       return (STACK_OF(X509_ALGOR) *)
+               ASN1_item_d2i(NULL, &p, cap->value.sequence->length,
+                               ASN1_ITEM_rptr(X509_ALGORS));
        }
 
 /* Basic smime-capabilities OID and optional integer arg */
@@ -139,3 +124,42 @@ int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg)
        sk_X509_ALGOR_push (sk, alg);
        return 1;
 }
+
+int PKCS7_add_attrib_content_type(PKCS7_SIGNER_INFO *si, ASN1_OBJECT *coid)
+       {
+       if (PKCS7_get_signed_attribute(si, NID_pkcs9_contentType))
+               return 0;
+       if (!coid)
+               coid = OBJ_nid2obj(NID_pkcs7_data);
+       return PKCS7_add_signed_attribute(si, NID_pkcs9_contentType,
+                               V_ASN1_OBJECT, coid);
+       }
+
+int PKCS7_add0_attrib_signing_time(PKCS7_SIGNER_INFO *si, ASN1_TIME *t)
+       {
+       if (!t && !(t=X509_gmtime_adj(NULL,0)))
+               {
+               PKCS7err(PKCS7_F_PKCS7_ADD0_ATTRIB_SIGNING_TIME,
+                               ERR_R_MALLOC_FAILURE);
+               return 0;
+               }
+       return PKCS7_add_signed_attribute(si, NID_pkcs9_signingTime,
+                                               V_ASN1_UTCTIME, t);
+       }
+
+int PKCS7_add1_attrib_digest(PKCS7_SIGNER_INFO *si,
+                               const unsigned char *md, int mdlen)
+       {
+       ASN1_OCTET_STRING *os;
+       os = ASN1_OCTET_STRING_new();
+       if (!os)
+               return 0;
+       if (!ASN1_STRING_set(os, md, mdlen)
+               || !PKCS7_add_signed_attribute(si, NID_pkcs9_messageDigest,
+                                               V_ASN1_OCTET_STRING, os))
+               {
+               ASN1_OCTET_STRING_free(os);
+               return 0;
+               }
+       return 1;
+       }
index c8f1eb1..3bf1a36 100644 (file)
@@ -138,6 +138,121 @@ static int PKCS7_bio_add_digest(BIO **pbio, X509_ALGOR *alg)
 
        }
 
+static int pkcs7_encode_rinfo(PKCS7_RECIP_INFO *ri,
+                                       unsigned char *key, int keylen)
+       {
+       EVP_PKEY_CTX *pctx = NULL;
+       EVP_PKEY *pkey = NULL;
+       unsigned char *ek = NULL;
+       int ret = 0;
+       size_t eklen;
+
+       pkey = X509_get_pubkey(ri->cert);
+
+       if (!pkey)
+               return 0;
+
+       pctx = EVP_PKEY_CTX_new(pkey, NULL);
+       if (!pctx)
+               return 0;
+
+       if (EVP_PKEY_encrypt_init(pctx) <= 0)
+               goto err;
+
+       if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_ENCRYPT,
+                               EVP_PKEY_CTRL_PKCS7_ENCRYPT, 0, ri) <= 0)
+               {
+               PKCS7err(PKCS7_F_PKCS7_ENCODE_RINFO, PKCS7_R_CTRL_ERROR);
+               goto err;
+               }
+
+       if (EVP_PKEY_encrypt(pctx, NULL, &eklen, key, keylen) <= 0)
+               goto err;
+
+       ek = OPENSSL_malloc(eklen);
+
+       if (ek == NULL)
+               {
+               PKCS7err(PKCS7_F_PKCS7_ENCODE_RINFO, ERR_R_MALLOC_FAILURE);
+               goto err;
+               }
+
+       if (EVP_PKEY_encrypt(pctx, ek, &eklen, key, keylen) <= 0)
+               goto err;
+
+       ASN1_STRING_set0(ri->enc_key, ek, eklen);
+       ek = NULL;
+
+       ret = 1;
+
+       err:
+       if (pkey)
+               EVP_PKEY_free(pkey);
+       if (pctx)
+               EVP_PKEY_CTX_free(pctx);
+       if (ek)
+               OPENSSL_free(ek);
+       return ret;
+
+       }
+
+
+static int pkcs7_decrypt_rinfo(unsigned char **pek, int *peklen,
+                              PKCS7_RECIP_INFO *ri, EVP_PKEY *pkey)
+       {
+       EVP_PKEY_CTX *pctx = NULL;
+       unsigned char *ek = NULL;
+       size_t eklen;
+
+       int ret = 0;
+
+       pctx = EVP_PKEY_CTX_new(pkey, NULL);
+       if (!pctx)
+               return 0;
+
+       if (EVP_PKEY_decrypt_init(pctx) <= 0)
+               goto err;
+
+       if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DECRYPT,
+                               EVP_PKEY_CTRL_PKCS7_DECRYPT, 0, ri) <= 0)
+               {
+               PKCS7err(PKCS7_F_PKCS7_DECRYPT_RINFO, PKCS7_R_CTRL_ERROR);
+               goto err;
+               }
+
+       if (EVP_PKEY_decrypt(pctx, NULL, &eklen,
+                               ri->enc_key->data, ri->enc_key->length) <= 0)
+               goto err;
+
+       ek = OPENSSL_malloc(eklen);
+
+       if (ek == NULL)
+               {
+               PKCS7err(PKCS7_F_PKCS7_DECRYPT_RINFO, ERR_R_MALLOC_FAILURE);
+               goto err;
+               }
+
+       if (EVP_PKEY_decrypt(pctx, ek, &eklen,
+                               ri->enc_key->data, ri->enc_key->length) <= 0)
+               {
+               PKCS7err(PKCS7_F_PKCS7_DECRYPT_RINFO, ERR_R_EVP_LIB);
+               goto err;
+               }
+
+       ret = 1;
+
+       *pek = ek;
+       *peklen = eklen;
+
+       err:
+       if (pctx)
+               EVP_PKEY_CTX_free(pctx);
+       if (!ret && ek)
+               OPENSSL_free(ek);
+
+       return ret;
+       }
+
 BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
        {
        int i;
@@ -148,7 +263,6 @@ BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
        STACK_OF(PKCS7_RECIP_INFO) *rsk=NULL;
        X509_ALGOR *xalg=NULL;
        PKCS7_RECIP_INFO *ri=NULL;
-       EVP_PKEY *pkey;
        ASN1_OCTET_STRING *os=NULL;
 
        i=OBJ_obj2nid(p7->type);
@@ -187,6 +301,8 @@ BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
                xa = p7->d.digest->md;
                os = PKCS7_get_octet_string(p7->d.digest->contents);
                break;
+       case NID_pkcs7_data:
+               break;
        default:
                PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
                goto err;
@@ -204,8 +320,6 @@ BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
                unsigned char key[EVP_MAX_KEY_LENGTH];
                unsigned char iv[EVP_MAX_IV_LENGTH];
                int keylen,ivlen;
-               int jj,max;
-               unsigned char *tmp;
                EVP_CIPHER_CTX *ctx;
 
                if ((btmp=BIO_new(BIO_f_cipher())) == NULL)
@@ -234,52 +348,16 @@ BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
                                        goto err;
                        }
                        if(EVP_CIPHER_param_to_asn1(ctx, xalg->parameter) < 0)
-                              goto err;
+                               goto err;
                }
 
                /* Lets do the pub key stuff :-) */
-               max=0;
                for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)
                        {
                        ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
-                       if (ri->cert == NULL)
-                               {
-                               PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_MISSING_CERIPEND_INFO);
-                               goto err;
-                               }
-                       if ((pkey=X509_get_pubkey(ri->cert)) == NULL)
-                               goto err;
-                       jj=EVP_PKEY_size(pkey);
-                       EVP_PKEY_free(pkey);
-                       if (max < jj) max=jj;
-                       }
-               if ((tmp=(unsigned char *)OPENSSL_malloc(max)) == NULL)
-                       {
-                       PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_MALLOC_FAILURE);
-                       goto err;
-                       }
-               for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)
-                       {
-                       ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
-                       if ((pkey=X509_get_pubkey(ri->cert)) == NULL)
-                               goto err;
-                       jj=EVP_PKEY_encrypt(tmp,key,keylen,pkey);
-                       EVP_PKEY_free(pkey);
-                       if (jj <= 0)
-                               {
-                               PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_EVP_LIB);
-                               OPENSSL_free(tmp);
+                       if (pkcs7_encode_rinfo(ri, key, keylen) <= 0)
                                goto err;
-                               }
-                       if (!M_ASN1_OCTET_STRING_set(ri->enc_key,tmp,jj))
-                               {
-                               PKCS7err(PKCS7_F_PKCS7_DATAINIT,
-                                       ERR_R_MALLOC_FAILURE);
-                               OPENSSL_free(tmp);
-                               goto err;
-                               }
                        }
-               OPENSSL_free(tmp);
                OPENSSL_cleanse(key, keylen);
 
                if (out == NULL)
@@ -303,7 +381,10 @@ BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
                        BIO_set_mem_eof_return(bio,0);
                        }
                }
-       BIO_push(out,bio);
+       if (out)
+               BIO_push(out,bio);
+       else
+               out = bio;
        bio=NULL;
        if (0)
                {
@@ -333,7 +414,6 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
        {
        int i,j;
        BIO *out=NULL,*btmp=NULL,*etmp=NULL,*bio=NULL;
-       unsigned char *tmp=NULL;
        X509_ALGOR *xa;
        ASN1_OCTET_STRING *data_body=NULL;
        const EVP_MD *evp_md;
@@ -420,7 +500,8 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
                int max;
                X509_OBJECT ret;
 #endif
-               int jj;
+               unsigned char *ek = NULL;
+               int eklen;
 
                if ((etmp=BIO_new(BIO_f_cipher())) == NULL)
                        {
@@ -435,26 +516,21 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
                 * (if any)
                 */
 
-               if (pcert) {
-                       for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++) {
+               if (pcert)
+                       {
+                       for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)
+                               {
                                ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
                                if (!pkcs7_cmp_ri(ri, pcert))
                                        break;
                                ri=NULL;
-                       }
-                       if (ri == NULL) {
+                               }
+                       if (ri == NULL)
+                               {
                                PKCS7err(PKCS7_F_PKCS7_DATADECODE,
                                      PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE);
                                goto err;
-                       }
-               }
-
-               jj=EVP_PKEY_size(pkey);
-               tmp=(unsigned char *)OPENSSL_malloc(jj+10);
-               if (tmp == NULL)
-                       {
-                       PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_MALLOC_FAILURE);
-                       goto err;
+                               }
                        }
 
                /* If we haven't got a certificate try each ri in turn */
@@ -464,11 +540,8 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
                        for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)
                                {
                                ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
-                               jj=EVP_PKEY_decrypt(tmp,
-                                       M_ASN1_STRING_data(ri->enc_key),
-                                       M_ASN1_STRING_length(ri->enc_key),
-                                               pkey);
-                               if (jj > 0)
+                               if (pkcs7_decrypt_rinfo(&ek, &eklen,
+                                                       ri, pkey) > 0)
                                        break;
                                ERR_clear_error();
                                ri = NULL;
@@ -482,15 +555,8 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
                        }
                else
                        {
-                       jj=EVP_PKEY_decrypt(tmp,
-                               M_ASN1_STRING_data(ri->enc_key),
-                               M_ASN1_STRING_length(ri->enc_key), pkey);
-                       if (jj <= 0)
-                               {
-                               PKCS7err(PKCS7_F_PKCS7_DATADECODE,
-                                                               ERR_R_EVP_LIB);
+                       if (pkcs7_decrypt_rinfo(&ek, &eklen, ri, pkey) <= 0)
                                goto err;
-                               }
                        }
 
                evp_ctx=NULL;
@@ -500,22 +566,26 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
                if (EVP_CIPHER_asn1_to_param(evp_ctx,enc_alg->parameter) < 0)
                        goto err;
 
-               if (jj != EVP_CIPHER_CTX_key_length(evp_ctx)) {
+               if (eklen != EVP_CIPHER_CTX_key_length(evp_ctx)) {
                        /* Some S/MIME clients don't use the same key
                         * and effective key length. The key length is
                         * determined by the size of the decrypted RSA key.
                         */
-                       if(!EVP_CIPHER_CTX_set_key_length(evp_ctx, jj))
+                       if(!EVP_CIPHER_CTX_set_key_length(evp_ctx, eklen))
                                {
                                PKCS7err(PKCS7_F_PKCS7_DATADECODE,
                                        PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH);
                                goto err;
                                }
                } 
-               if (EVP_CipherInit_ex(evp_ctx,NULL,NULL,tmp,NULL,0) <= 0)
+               if (EVP_CipherInit_ex(evp_ctx,NULL,NULL,ek,NULL,0) <= 0)
                        goto err;
 
-               OPENSSL_cleanse(tmp,jj);
+               if (ek)
+                       {
+                       OPENSSL_cleanse(ek,eklen);
+                       OPENSSL_free(ek);
+                       }
 
                if (out == NULL)
                        out=etmp;
@@ -563,8 +633,6 @@ err:
                if (bio != NULL) BIO_free_all(bio);
                out=NULL;
                }
-       if (tmp != NULL)
-               OPENSSL_free(tmp);
        return(out);
        }
 
@@ -591,13 +659,43 @@ static BIO *PKCS7_find_digest(EVP_MD_CTX **pmd, BIO *bio, int nid)
        return NULL;
        }
 
+static int do_pkcs7_signed_attrib(PKCS7_SIGNER_INFO *si, EVP_MD_CTX *mctx)
+       {
+       unsigned char md_data[EVP_MAX_MD_SIZE];
+       unsigned int md_len;
+
+       /* Add signing time if not already present */
+       if (!PKCS7_get_signed_attribute(si, NID_pkcs9_signingTime))
+               {
+               if (!PKCS7_add0_attrib_signing_time(si, NULL))
+                       {
+                       PKCS7err(PKCS7_F_DO_PKCS7_SIGNED_ATTRIB,
+                                       ERR_R_MALLOC_FAILURE);
+                       return 0;
+                       }
+               }
+
+       /* Add digest */
+       EVP_DigestFinal_ex(mctx, md_data,&md_len);
+       if (!PKCS7_add1_attrib_digest(si, md_data, md_len))
+               {
+               PKCS7err(PKCS7_F_DO_PKCS7_SIGNED_ATTRIB, ERR_R_MALLOC_FAILURE);
+               return 0;
+               }
+
+       /* Now sign the attributes */
+       if (!PKCS7_SIGNER_INFO_sign(si))
+                       return 0;
+
+       return 1;
+       }
+       
+                               
 int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
        {
        int ret=0;
        int i,j;
        BIO *btmp;
-       BUF_MEM *buf_mem=NULL;
-       BUF_MEM *buf=NULL;
        PKCS7_SIGNER_INFO *si;
        EVP_MD_CTX *mdc,ctx_tmp;
        STACK_OF(X509_ATTRIBUTE) *sk;
@@ -610,24 +708,37 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
 
        switch (i)
                {
+       case NID_pkcs7_data:
+               os = p7->d.data;
+               break;
        case NID_pkcs7_signedAndEnveloped:
                /* XXXXXXXXXXXXXXXX */
                si_sk=p7->d.signed_and_enveloped->signer_info;
-               if (!(os=M_ASN1_OCTET_STRING_new()))
+               os = p7->d.signed_and_enveloped->enc_data->enc_data;
+               if (!os)
                        {
-                       PKCS7err(PKCS7_F_PKCS7_DATAFINAL,ERR_R_MALLOC_FAILURE);
-                       goto err;
+                       os=M_ASN1_OCTET_STRING_new();
+                       if (!os)
+                               {
+                               PKCS7err(PKCS7_F_PKCS7_DATAFINAL,ERR_R_MALLOC_FAILURE);
+                               goto err;
+                               }
+                       p7->d.signed_and_enveloped->enc_data->enc_data=os;
                        }
-               p7->d.signed_and_enveloped->enc_data->enc_data=os;
                break;
        case NID_pkcs7_enveloped:
                /* XXXXXXXXXXXXXXXX */
-               if (!(os=M_ASN1_OCTET_STRING_new()))
+               os = p7->d.enveloped->enc_data->enc_data;
+               if (!os)
                        {
-                       PKCS7err(PKCS7_F_PKCS7_DATAFINAL,ERR_R_MALLOC_FAILURE);
-                       goto err;
+                       os=M_ASN1_OCTET_STRING_new();
+                       if (!os)
+                               {
+                               PKCS7err(PKCS7_F_PKCS7_DATAFINAL,ERR_R_MALLOC_FAILURE);
+                               goto err;
+                               }
+                       p7->d.enveloped->enc_data->enc_data=os;
                        }
-               p7->d.enveloped->enc_data->enc_data=os;
                break;
        case NID_pkcs7_signed:
                si_sk=p7->d.sign->signer_info;
@@ -649,21 +760,20 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
                        }
                break;
 
+       default:
+               PKCS7err(PKCS7_F_PKCS7_DATAFINAL,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
+               goto err;
                }
 
        if (si_sk != NULL)
                {
-               if ((buf=BUF_MEM_new()) == NULL)
-                       {
-                       PKCS7err(PKCS7_F_PKCS7_DATAFINAL,ERR_R_BIO_LIB);
-                       goto err;
-                       }
                for (i=0; i<sk_PKCS7_SIGNER_INFO_num(si_sk); i++)
                        {
                        si=sk_PKCS7_SIGNER_INFO_value(si_sk,i);
-                       if (si->pkey == NULL) continue;
+                       if (si->pkey == NULL)
+                               continue;
 
-                       j=OBJ_obj2nid(si->digest_alg->algorithm);
+                       j = OBJ_obj2nid(si->digest_alg->algorithm);
 
                        btmp=bio;
 
@@ -675,97 +785,33 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
                        /* We now have the EVP_MD_CTX, lets do the
                         * signing. */
                        EVP_MD_CTX_copy_ex(&ctx_tmp,mdc);
-                       if (!BUF_MEM_grow_clean(buf,EVP_PKEY_size(si->pkey)))
-                               {
-                               PKCS7err(PKCS7_F_PKCS7_DATAFINAL,ERR_R_BIO_LIB);
-                               goto err;
-                               }
 
                        sk=si->auth_attr;
 
                        /* If there are attributes, we add the digest
                         * attribute and only sign the attributes */
-                       if ((sk != NULL) && (sk_X509_ATTRIBUTE_num(sk) != 0))
+                       if (sk_X509_ATTRIBUTE_num(sk) > 0)
                                {
-                               unsigned char md_data[EVP_MAX_MD_SIZE], *abuf=NULL;
-                               unsigned int md_len, alen;
-                               ASN1_OCTET_STRING *digest;
-                               ASN1_UTCTIME *sign_time;
-                               const EVP_MD *md_tmp;
-
-                               /* Add signing time if not already present */
-                               if (!PKCS7_get_signed_attribute(si,
-                                                       NID_pkcs9_signingTime))
-                                       {
-                                       if (!(sign_time=X509_gmtime_adj(NULL,0)))
-                                               {
-                                               PKCS7err(PKCS7_F_PKCS7_DATAFINAL,
-                                                       ERR_R_MALLOC_FAILURE);
-                                               goto err;
-                                               }
-                                       if (!PKCS7_add_signed_attribute(si,
-                                               NID_pkcs9_signingTime,
-                                               V_ASN1_UTCTIME,sign_time))
-                                               {
-                                               M_ASN1_UTCTIME_free(sign_time);
-                                               goto err;
-                                               }
-                                       }
-
-                               /* Add digest */
-                               md_tmp=EVP_MD_CTX_md(&ctx_tmp);
-                               EVP_DigestFinal_ex(&ctx_tmp,md_data,&md_len);
-                               if (!(digest=M_ASN1_OCTET_STRING_new()))
-                                       {
-                                       PKCS7err(PKCS7_F_PKCS7_DATAFINAL,
-                                               ERR_R_MALLOC_FAILURE);
+                               if (!do_pkcs7_signed_attrib(si, &ctx_tmp))
                                        goto err;
-                                       }
-                               if (!M_ASN1_OCTET_STRING_set(digest,md_data,
-                                                               md_len))
-                                       {
-                                       PKCS7err(PKCS7_F_PKCS7_DATAFINAL,
-                                               ERR_R_MALLOC_FAILURE);
-                                       M_ASN1_OCTET_STRING_free(digest);
+                               }
+                       else
+                               {
+                               unsigned char *abuf = NULL;
+                               unsigned int abuflen;
+                               abuflen = EVP_PKEY_size(si->pkey);
+                               abuf = OPENSSL_malloc(abuflen);
+                               if (!abuf)
                                        goto err;
-                                       }
-                               if (!PKCS7_add_signed_attribute(si,
-                                       NID_pkcs9_messageDigest,
-                                       V_ASN1_OCTET_STRING,digest))
+
+                               if (!EVP_SignFinal(&ctx_tmp, abuf, &abuflen,
+                                                       si->pkey))
                                        {
-                                       M_ASN1_OCTET_STRING_free(digest);
+                                       PKCS7err(PKCS7_F_PKCS7_DATAFINAL,
+                                                       ERR_R_EVP_LIB);
                                        goto err;
                                        }
-
-                               /* Now sign the attributes */
-                               EVP_SignInit_ex(&ctx_tmp,md_tmp,NULL);
-                               alen = ASN1_item_i2d((ASN1_VALUE *)sk,&abuf,
-                                                       ASN1_ITEM_rptr(PKCS7_ATTR_SIGN));
-                               if(!abuf) goto err;
-                               EVP_SignUpdate(&ctx_tmp,abuf,alen);
-                               OPENSSL_free(abuf);
-                               }
-
-#ifndef OPENSSL_NO_DSA
-                       if (si->pkey->type == EVP_PKEY_DSA)
-                               ctx_tmp.digest=EVP_dss1();
-#endif
-#ifndef OPENSSL_NO_ECDSA
-                       if (si->pkey->type == EVP_PKEY_EC)
-                               ctx_tmp.digest=EVP_ecdsa();
-#endif
-
-                       if (!EVP_SignFinal(&ctx_tmp,(unsigned char *)buf->data,
-                               (unsigned int *)&buf->length,si->pkey))
-                               {
-                               PKCS7err(PKCS7_F_PKCS7_DATAFINAL,ERR_R_EVP_LIB);
-                               goto err;
-                               }
-                       if (!ASN1_STRING_set(si->enc_digest,
-                               (unsigned char *)buf->data,buf->length))
-                               {
-                               PKCS7err(PKCS7_F_PKCS7_DATAFINAL,ERR_R_ASN1_LIB);
-                               goto err;
+                               ASN1_STRING_set0(si->enc_digest, abuf, abuflen);
                                }
                        }
                }
@@ -780,34 +826,90 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
                M_ASN1_OCTET_STRING_set(p7->d.digest->digest, md_data, md_len);
                }
 
-       if (!PKCS7_is_detached(p7))
+       if (!PKCS7_is_detached(p7) && !(os->flags & ASN1_STRING_FLAG_NDEF))
                {
+               char *cont;
+               long contlen;
                btmp=BIO_find_type(bio,BIO_TYPE_MEM);
                if (btmp == NULL)
                        {
                        PKCS7err(PKCS7_F_PKCS7_DATAFINAL,PKCS7_R_UNABLE_TO_FIND_MEM_BIO);
                        goto err;
                        }
-               BIO_get_mem_ptr(btmp,&buf_mem);
+               contlen = BIO_get_mem_data(btmp, &cont);
                /* Mark the BIO read only then we can use its copy of the data
                 * instead of making an extra copy.
                 */
                BIO_set_flags(btmp, BIO_FLAGS_MEM_RDONLY);
                BIO_set_mem_eof_return(btmp, 0);
-               os->data = (unsigned char *)buf_mem->data;
-               os->length = buf_mem->length;
-#if 0
-               M_ASN1_OCTET_STRING_set(os,
-                       (unsigned char *)buf_mem->data,buf_mem->length);
-#endif
+               ASN1_STRING_set0(os, (unsigned char *)cont, contlen);
                }
        ret=1;
 err:
        EVP_MD_CTX_cleanup(&ctx_tmp);
-       if (buf != NULL) BUF_MEM_free(buf);
        return(ret);
        }
 
+int PKCS7_SIGNER_INFO_sign(PKCS7_SIGNER_INFO *si)
+       {
+       EVP_MD_CTX mctx;
+       EVP_PKEY_CTX *pctx;
+       unsigned char *abuf = NULL;
+       int alen;
+       size_t siglen;
+       const EVP_MD *md = NULL;
+
+       md = EVP_get_digestbyobj(si->digest_alg->algorithm);
+       if (md == NULL)
+               return 0;
+
+       EVP_MD_CTX_init(&mctx);
+       if (EVP_DigestSignInit(&mctx, &pctx, md,NULL, si->pkey) <= 0)
+               goto err;
+
+       if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_SIGN,
+                               EVP_PKEY_CTRL_PKCS7_SIGN, 0, si) <= 0)
+               {
+               PKCS7err(PKCS7_F_PKCS7_SIGNER_INFO_SIGN, PKCS7_R_CTRL_ERROR);
+               goto err;
+               }
+
+       alen = ASN1_item_i2d((ASN1_VALUE *)si->auth_attr,&abuf,
+                               ASN1_ITEM_rptr(PKCS7_ATTR_SIGN));
+       if(!abuf)
+               goto err;
+       if (EVP_DigestSignUpdate(&mctx,abuf,alen) <= 0)
+               goto err;
+       OPENSSL_free(abuf);
+       if (EVP_DigestSignFinal(&mctx, NULL, &siglen) <= 0)
+               goto err;
+       abuf = OPENSSL_malloc(siglen);
+       if(!abuf)
+               goto err;
+       if (EVP_DigestSignFinal(&mctx, abuf, &siglen) <= 0)
+               goto err;
+
+       if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_SIGN,
+                               EVP_PKEY_CTRL_PKCS7_SIGN, 1, si) <= 0)
+               {
+               PKCS7err(PKCS7_F_PKCS7_SIGNER_INFO_SIGN, PKCS7_R_CTRL_ERROR);
+               goto err;
+               }
+
+       EVP_MD_CTX_cleanup(&mctx);
+
+       ASN1_STRING_set0(si->enc_digest, abuf, siglen);
+
+       return 1;
+
+       err:
+       if (abuf)
+               OPENSSL_free(abuf);
+       EVP_MD_CTX_cleanup(&mctx);
+       return 0;
+
+       }
+
 int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio,
             PKCS7 *p7, PKCS7_SIGNER_INFO *si)
        {
@@ -919,7 +1021,8 @@ int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
        if ((sk != NULL) && (sk_X509_ATTRIBUTE_num(sk) != 0))
                {
                unsigned char md_dat[EVP_MAX_MD_SIZE], *abuf = NULL;
-                unsigned int md_len, alen;
+                unsigned int md_len;
+               int alen;
                ASN1_OCTET_STRING *message_digest;
 
                EVP_DigestFinal_ex(&mdc_tmp,md_dat,&md_len);
@@ -951,6 +1054,12 @@ for (ii=0; ii<md_len; ii++) printf("%02X",md_dat[ii]); printf(" calc\n");
 
                alen = ASN1_item_i2d((ASN1_VALUE *)sk, &abuf,
                                                ASN1_ITEM_rptr(PKCS7_ATTR_VERIFY));
+               if (alen <= 0) 
+                       {
+                       PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,ERR_R_ASN1_LIB);
+                       ret = -1;
+                       goto err;
+                       }
                EVP_VerifyUpdate(&mdc_tmp, abuf, alen);
 
                OPENSSL_free(abuf);
@@ -963,12 +1072,6 @@ for (ii=0; ii<md_len; ii++) printf("%02X",md_dat[ii]); printf(" calc\n");
                ret = -1;
                goto err;
                }
-#ifndef OPENSSL_NO_DSA
-       if(pkey->type == EVP_PKEY_DSA) mdc_tmp.digest=EVP_dss1();
-#endif
-#ifndef OPENSSL_NO_ECDSA
-       if (pkey->type == EVP_PKEY_EC) mdc_tmp.digest=EVP_ecdsa();
-#endif
 
        i=EVP_VerifyFinal(&mdc_tmp,os->data,os->length, pkey);
        EVP_PKEY_free(pkey);
@@ -1104,8 +1207,9 @@ static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype,
 
        if (*sk == NULL)
                {
-               if (!(*sk = sk_X509_ATTRIBUTE_new_null()))
-                       return 0;
+               *sk = sk_X509_ATTRIBUTE_new_null();
+               if (*sk == NULL)
+                       return 0;       
 new_attrib:
                if (!(attr=X509_ATTRIBUTE_create(nid,atrtype,value)))
                        return 0;
index 898cdda..d411269 100644 (file)
@@ -60,6 +60,7 @@
 #include "cryptlib.h"
 #include <openssl/objects.h>
 #include <openssl/x509.h>
+#include "asn1_locl.h"
 
 long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg)
        {
@@ -314,7 +315,7 @@ int PKCS7_add_certificate(PKCS7 *p7, X509 *x509)
                *sk=sk_X509_new_null();
        if (*sk == NULL)
                {
-               PKCS7err(PKCS7_F_PKCS7_ADD_CERTIFICATE,ERR_R_MALLOC_FAILURE);
+               PKCS7err(PKCS7_F_PKCS7_ADD_CERTIFICATE, ERR_R_MALLOC_FAILURE);
                return 0;
                }
        CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);
@@ -365,13 +366,8 @@ int PKCS7_add_crl(PKCS7 *p7, X509_CRL *crl)
 int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
             const EVP_MD *dgst)
        {
-       int nid;
-       char is_dsa;
+       int ret;
 
-       if (pkey->type == EVP_PKEY_DSA || pkey->type == EVP_PKEY_EC)
-               is_dsa = 1;
-       else
-               is_dsa = 0;
        /* We now need to add another PKCS7_SIGNER_INFO entry */
        if (!ASN1_INTEGER_set(p7i->version,1))
                goto err;
@@ -391,65 +387,55 @@ int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
        p7i->pkey=pkey;
 
        /* Set the algorithms */
-       if (is_dsa) p7i->digest_alg->algorithm=OBJ_nid2obj(NID_sha1);
-       else    
-               p7i->digest_alg->algorithm=OBJ_nid2obj(EVP_MD_type(dgst));
 
-       if (p7i->digest_alg->parameter != NULL)
-               ASN1_TYPE_free(p7i->digest_alg->parameter);
-       if ((p7i->digest_alg->parameter=ASN1_TYPE_new()) == NULL)
-               goto err;
-       p7i->digest_alg->parameter->type=V_ASN1_NULL;
+       X509_ALGOR_set0(p7i->digest_alg, OBJ_nid2obj(EVP_MD_type(dgst)),
+                               V_ASN1_NULL, NULL);
 
-       if (p7i->digest_enc_alg->parameter != NULL)
-               ASN1_TYPE_free(p7i->digest_enc_alg->parameter);
-       nid = EVP_PKEY_type(pkey->type);
-       if (nid == EVP_PKEY_RSA)
+       if (pkey->ameth && pkey->ameth->pkey_ctrl)
                {
-               p7i->digest_enc_alg->algorithm=OBJ_nid2obj(NID_rsaEncryption);
-               if (!(p7i->digest_enc_alg->parameter=ASN1_TYPE_new()))
-                       goto err;
-               p7i->digest_enc_alg->parameter->type=V_ASN1_NULL;
-               }
-       else if (nid == EVP_PKEY_DSA)
-               {
-#if 1
-               /* use 'dsaEncryption' OID for compatibility with other software
-                * (PKCS #7 v1.5 does specify how to handle DSA) ... */
-               p7i->digest_enc_alg->algorithm=OBJ_nid2obj(NID_dsa);
-#else
-               /* ... although the 'dsaWithSHA1' OID (as required by RFC 2630 for CMS)
-                * would make more sense. */
-               p7i->digest_enc_alg->algorithm=OBJ_nid2obj(NID_dsaWithSHA1);
-#endif
-               p7i->digest_enc_alg->parameter = NULL; /* special case for DSA: omit 'parameter'! */
-               }
-       else if (nid == EVP_PKEY_EC)
-               {
-               p7i->digest_enc_alg->algorithm=OBJ_nid2obj(NID_ecdsa_with_SHA1);
-               if (!(p7i->digest_enc_alg->parameter=ASN1_TYPE_new()))
-                       goto err;
-               p7i->digest_enc_alg->parameter->type=V_ASN1_NULL;
+               ret = pkey->ameth->pkey_ctrl(pkey, ASN1_PKEY_CTRL_PKCS7_SIGN,
+                                               0, p7i);
+               if (ret > 0)
+                       return 1;
+               if (ret != -2)
+                       {
+                       PKCS7err(PKCS7_F_PKCS7_SIGNER_INFO_SET,
+                                       PKCS7_R_SIGNING_CTRL_FAILURE);
+                       return 0;
+                       }
                }
-       else
-               return(0);
-
-       return(1);
+       PKCS7err(PKCS7_F_PKCS7_SIGNER_INFO_SET,
+                       PKCS7_R_SIGNING_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);
 err:
-       return(0);
+       return 0;
        }
 
 PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509, EVP_PKEY *pkey,
             const EVP_MD *dgst)
        {
-       PKCS7_SIGNER_INFO *si;
+       PKCS7_SIGNER_INFO *si = NULL;
+
+       if (dgst == NULL)
+               {
+               int def_nid;
+               if (EVP_PKEY_get_default_digest_nid(pkey, &def_nid) <= 0)
+                       goto err;
+               dgst = EVP_get_digestbynid(def_nid);
+               if (dgst == NULL)
+                       {
+                       PKCS7err(PKCS7_F_PKCS7_ADD_SIGNATURE,
+                                               PKCS7_R_NO_DEFAULT_DIGEST);
+                       goto err;
+                       }
+               }
 
        if ((si=PKCS7_SIGNER_INFO_new()) == NULL) goto err;
        if (!PKCS7_SIGNER_INFO_set(si,x509,pkey,dgst)) goto err;
        if (!PKCS7_add_signer(p7,si)) goto err;
        return(si);
 err:
-       PKCS7_SIGNER_INFO_free(si);
+       if (si)
+               PKCS7_SIGNER_INFO_free(si);
        return(NULL);
        }
 
@@ -485,6 +471,23 @@ STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7)
                return(NULL);
        }
 
+void PKCS7_SIGNER_INFO_get0_algs(PKCS7_SIGNER_INFO *si, EVP_PKEY **pk,
+                                       X509_ALGOR **pdig, X509_ALGOR **psig)
+       {
+       if (pk)
+               *pk = si->pkey;
+       if (pdig)
+               *pdig = si->digest_alg;
+       if (psig)
+               *psig = si->digest_enc_alg;
+       }
+
+void PKCS7_RECIP_INFO_get0_alg(PKCS7_RECIP_INFO *ri, X509_ALGOR **penc)
+       {
+       if (penc)
+               *penc = ri->key_enc_algor;
+       }
+
 PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509)
        {
        PKCS7_RECIP_INFO *ri;
@@ -492,10 +495,11 @@ PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509)
        if ((ri=PKCS7_RECIP_INFO_new()) == NULL) goto err;
        if (!PKCS7_RECIP_INFO_set(ri,x509)) goto err;
        if (!PKCS7_add_recipient_info(p7,ri)) goto err;
-       return(ri);
+       return ri;
 err:
-       PKCS7_RECIP_INFO_free(ri);
-       return(NULL);
+       if (ri)
+               PKCS7_RECIP_INFO_free(ri);
+       return NULL;
        }
 
 int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri)
@@ -524,6 +528,8 @@ int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri)
 
 int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509)
        {
+       int ret;
+       EVP_PKEY *pkey = NULL;
        if (!ASN1_INTEGER_set(p7i->version,0))
                return 0;
        if (!X509_NAME_set(&p7i->issuer_and_serial->issuer,
@@ -535,14 +541,41 @@ int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509)
                M_ASN1_INTEGER_dup(X509_get_serialNumber(x509))))
                return 0;
 
-       X509_ALGOR_free(p7i->key_enc_algor);
-       if (!(p7i->key_enc_algor= X509_ALGOR_dup(x509->cert_info->key->algor)))
-               return 0;
+       pkey = X509_get_pubkey(x509);
+
+       if (!pkey || !pkey->ameth || !pkey->ameth->pkey_ctrl)
+               {
+               PKCS7err(PKCS7_F_PKCS7_RECIP_INFO_SET,
+                       PKCS7_R_ENCRYPTION_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);
+               goto err;
+               }
+
+       ret = pkey->ameth->pkey_ctrl(pkey, ASN1_PKEY_CTRL_PKCS7_ENCRYPT,
+                                               0, p7i);
+       if (ret == -2)
+               {
+               PKCS7err(PKCS7_F_PKCS7_RECIP_INFO_SET,
+                       PKCS7_R_ENCRYPTION_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);
+               goto err;
+               }
+       if (ret <= 0)
+               {
+               PKCS7err(PKCS7_F_PKCS7_RECIP_INFO_SET,
+                               PKCS7_R_ENCRYPTION_CTRL_FAILURE);
+               goto err;
+               }
+
+       EVP_PKEY_free(pkey);
 
        CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);
        p7i->cert=x509;
 
-       return(1);
+       return 1;
+
+       err:
+       if (pkey)
+               EVP_PKEY_free(pkey);
+       return 0;
        }
 
 X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si)
@@ -585,3 +618,48 @@ int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher)
        return 1;
        }
 
+int PKCS7_stream(unsigned char ***boundary, PKCS7 *p7)
+       {
+       ASN1_OCTET_STRING *os = NULL;
+
+       switch (OBJ_obj2nid(p7->type))
+               {
+               case NID_pkcs7_data:
+               os = p7->d.data;
+               break;
+
+               case NID_pkcs7_signedAndEnveloped:
+               os = p7->d.signed_and_enveloped->enc_data->enc_data;
+               if (os == NULL)
+                       {
+                       os=M_ASN1_OCTET_STRING_new();
+                       p7->d.signed_and_enveloped->enc_data->enc_data=os;
+                       }
+               break;
+
+               case NID_pkcs7_enveloped:
+               os = p7->d.enveloped->enc_data->enc_data;
+               if (os == NULL)
+                       {
+                       os=M_ASN1_OCTET_STRING_new();
+                       p7->d.enveloped->enc_data->enc_data=os;
+                       }
+               break;
+
+               case NID_pkcs7_signed:
+               os=p7->d.sign->contents->d.data;
+               break;
+
+               default:
+               os = NULL;
+               break;
+               }
+       
+       if (os == NULL)
+               return 0;
+
+       os->flags |= ASN1_STRING_FLAG_NDEF;
+       *boundary = &os->data;
+
+       return 1;
+       }
index 831b47d..938f79a 100644 (file)
 #include <openssl/x509.h>
 #include <openssl/asn1.h>
 
-/* PKCS#7 wrappers round generalised MIME routines */
+/* PKCS#7 wrappers round generalised stream and MIME routines */
 
-PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont)
+int i2d_PKCS7_bio_stream(BIO *out, PKCS7 *p7, BIO *in, int flags)
        {
-       return (PKCS7 *)SMIME_read_ASN1(bio, bcont, ASN1_ITEM_rptr(PKCS7));
+       return i2d_ASN1_bio_stream(out, (ASN1_VALUE *)p7, in, flags,
+                                       ASN1_ITEM_rptr(PKCS7));
        }
 
-/* Callback for int_smime_write_ASN1 */
-
-static int pk7_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
-                                       const ASN1_ITEM *it)
+int PEM_write_bio_PKCS7_stream(BIO *out, PKCS7 *p7, BIO *in, int flags)
        {
-       PKCS7 *p7 = (PKCS7 *)val;
-       BIO *tmpbio, *p7bio;
-
-       if (!(flags & SMIME_DETACHED))
-               {
-               SMIME_crlf_copy(data, out, flags);
-               return 1;
-               }
-
-       /* Let PKCS7 code prepend any needed BIOs */
-
-       p7bio = PKCS7_dataInit(p7, out);
-
-       if (!p7bio)
-               return 0;
-
-       /* Copy data across, passing through filter BIOs for processing */
-       SMIME_crlf_copy(data, p7bio, flags);
-
-       /* Finalize structure */
-       if (PKCS7_dataFinal(p7, p7bio) <= 0)
-               goto err;
-
-       err:
-
-       /* Now remove any digests prepended to the BIO */
-
-       while (p7bio != out)
-               {
-               tmpbio = BIO_pop(p7bio);
-               BIO_free(p7bio);
-               p7bio = tmpbio;
-               }
-
-       return 1;
-
+       return PEM_write_bio_ASN1_stream(out, (ASN1_VALUE *) p7, in, flags,
+                                               "PKCS7",
+                                               ASN1_ITEM_rptr(PKCS7));
        }
 
 int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags)
@@ -118,8 +83,15 @@ int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags)
        else
                mdalgs = NULL;
 
-       return int_smime_write_ASN1(bio, (ASN1_VALUE *)p7, data, flags,
+       flags ^= SMIME_OLDMIME;
+
+
+       return SMIME_write_ASN1(bio, (ASN1_VALUE *)p7, data, flags,
                                        ctype_nid, NID_undef, mdalgs,
-                                       pk7_output_data,
                                        ASN1_ITEM_rptr(PKCS7)); 
        }
+
+PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont)
+       {
+       return (PKCS7 *)SMIME_read_ASN1(bio, bcont, ASN1_ITEM_rptr(PKCS7));
+       }
index fd18ec3..86742d0 100644 (file)
 #include <openssl/x509.h>
 #include <openssl/x509v3.h>
 
+static int pkcs7_copy_existing_digest(PKCS7 *p7, PKCS7_SIGNER_INFO *si);
+
 PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
                  BIO *data, int flags)
 {
-       PKCS7 *p7 = NULL;
-       PKCS7_SIGNER_INFO *si;
-       BIO *p7bio = NULL;
-       STACK_OF(X509_ALGOR) *smcap = NULL;
+       PKCS7 *p7;
        int i;
 
-       if(!X509_check_private_key(signcert, pkey)) {
-               PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
-                return NULL;
-       }
-
-       if(!(p7 = PKCS7_new())) {
+       if(!(p7 = PKCS7_new()))
+               {
                PKCS7err(PKCS7_F_PKCS7_SIGN,ERR_R_MALLOC_FAILURE);
                return NULL;
-       }
+               }
 
        if (!PKCS7_set_type(p7, NID_pkcs7_signed))
                goto err;
@@ -88,82 +83,185 @@ PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
        if (!PKCS7_content_new(p7, NID_pkcs7_data))
                goto err;
 
-       if (!(si = PKCS7_add_signature(p7,signcert,pkey,EVP_sha1()))) {
-               PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR);
+       if (pkey && !PKCS7_sign_add_signer(p7, signcert, pkey, NULL, flags))
+               {
+               PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PKCS7_ADD_SIGNER_ERROR);
                goto err;
-       }
+               }
 
-       if(!(flags & PKCS7_NOCERTS)) {
-               if (!PKCS7_add_certificate(p7, signcert))
-                       goto err;
-               if(certs) for(i = 0; i < sk_X509_num(certs); i++)
+       if(!(flags & PKCS7_NOCERTS))
+               {
+               for(i = 0; i < sk_X509_num(certs); i++)
+                       {
                        if (!PKCS7_add_certificate(p7, sk_X509_value(certs, i)))
                                goto err;
-       }
+                       }
+               }
 
-       if(!(flags & PKCS7_NOATTR)) {
-               if (!PKCS7_add_signed_attribute(si, NID_pkcs9_contentType,
-                               V_ASN1_OBJECT, OBJ_nid2obj(NID_pkcs7_data)))
-                       goto err;
-               /* Add SMIMECapabilities */
-               if(!(flags & PKCS7_NOSMIMECAP))
+       if(flags & PKCS7_DETACHED)
+               PKCS7_set_detached(p7, 1);
+
+       if (flags & (PKCS7_STREAM|PKCS7_PARTIAL))
+               return p7;
+
+       if (PKCS7_final(p7, data, flags))
+               return p7;
+
+       err:
+       PKCS7_free(p7);
+       return NULL;
+}
+
+int PKCS7_final(PKCS7 *p7, BIO *data, int flags)
+       {
+       BIO *p7bio;
+       int ret = 0;
+       if (!(p7bio = PKCS7_dataInit(p7, NULL)))
                {
-               if(!(smcap = sk_X509_ALGOR_new_null())) {
-                       PKCS7err(PKCS7_F_PKCS7_SIGN,ERR_R_MALLOC_FAILURE);
-                       goto err;
-               }
-#ifndef OPENSSL_NO_DES
-               if (!PKCS7_simple_smimecap (smcap, NID_des_ede3_cbc, -1))
-                       goto err;
-#endif
-#ifndef OPENSSL_NO_RC2
-               if (!PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 128))
-                       goto err;
-               if (!PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 64))
-                       goto err;
-#endif
-#ifndef OPENSSL_NO_DES
-               if (!PKCS7_simple_smimecap (smcap, NID_des_cbc, -1))
-                       goto err;
-#endif
-#ifndef OPENSSL_NO_RC2
-               if (!PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 40))
-                       goto err;
-#endif
-               if (!PKCS7_add_attrib_smimecap (si, smcap))
-                       goto err;
-               sk_X509_ALGOR_pop_free(smcap, X509_ALGOR_free);
-               smcap = NULL;
+               PKCS7err(PKCS7_F_PKCS7_FINAL,ERR_R_MALLOC_FAILURE);
+               return 0;
                }
-       }
 
-       if(flags & PKCS7_DETACHED)PKCS7_set_detached(p7, 1);
+       SMIME_crlf_copy(data, p7bio, flags);
 
-       if (flags & PKCS7_STREAM)
-               return p7;
+       (void)BIO_flush(p7bio);
 
 
-       if (!(p7bio = PKCS7_dataInit(p7, NULL))) {
-               PKCS7err(PKCS7_F_PKCS7_SIGN,ERR_R_MALLOC_FAILURE);
+        if (!PKCS7_dataFinal(p7,p7bio))
+               {
+               PKCS7err(PKCS7_F_PKCS7_FINAL,PKCS7_R_PKCS7_DATASIGN);
                goto err;
+               }
+
+       ret = 1;
+
+       err:
+       BIO_free_all(p7bio);
+
+       return ret;
+
        }
 
-       SMIME_crlf_copy(data, p7bio, flags);
+/* Check to see if a cipher exists and if so add S/MIME capabilities */
 
+static int add_cipher_smcap(STACK_OF(X509_ALGOR) *sk, int nid, int arg)
+       {
+       if (EVP_get_cipherbynid(nid))
+               return PKCS7_simple_smimecap(sk, nid, arg);
+       return 1;
+       }
 
-       if (!PKCS7_dataFinal(p7,p7bio)) {
-               PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PKCS7_DATASIGN);
-               goto err;
+static int add_digest_smcap(STACK_OF(X509_ALGOR) *sk, int nid, int arg)
+       {
+       if (EVP_get_digestbynid(nid))
+               return PKCS7_simple_smimecap(sk, nid, arg);
+       return 1;
        }
 
-       BIO_free_all(p7bio);
-       return p7;
-err:
-       sk_X509_ALGOR_pop_free(smcap, X509_ALGOR_free);
-       BIO_free_all(p7bio);
-       PKCS7_free(p7);
+PKCS7_SIGNER_INFO *PKCS7_sign_add_signer(PKCS7 *p7, X509 *signcert,
+                                       EVP_PKEY *pkey, const EVP_MD *md,
+                                       int flags)
+       {
+       PKCS7_SIGNER_INFO *si = NULL;
+       STACK_OF(X509_ALGOR) *smcap = NULL;
+       if(!X509_check_private_key(signcert, pkey))
+               {
+               PKCS7err(PKCS7_F_PKCS7_SIGN_ADD_SIGNER,
+                       PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
+                return NULL;
+               }
+
+       if (!(si = PKCS7_add_signature(p7,signcert,pkey, md)))
+               {
+               PKCS7err(PKCS7_F_PKCS7_SIGN_ADD_SIGNER,
+                               PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR);
+               return NULL;
+               }
+
+       if(!(flags & PKCS7_NOCERTS))
+               {
+               if (!PKCS7_add_certificate(p7, signcert))
+                       goto err;
+               }
+
+       if(!(flags & PKCS7_NOATTR))
+               {
+               if (!PKCS7_add_attrib_content_type(si, NULL))
+                       goto err;
+               /* Add SMIMECapabilities */
+               if(!(flags & PKCS7_NOSMIMECAP))
+                       {
+                       if(!(smcap = sk_X509_ALGOR_new_null()))
+                               {
+                               PKCS7err(PKCS7_F_PKCS7_SIGN_ADD_SIGNER,
+                                       ERR_R_MALLOC_FAILURE);
+                               goto err;
+                               }
+                       if (!add_cipher_smcap(smcap, NID_aes_256_cbc, -1)
+                       || !add_digest_smcap(smcap, NID_id_GostR3411_94, -1)
+                       || !add_cipher_smcap(smcap, NID_id_Gost28147_89, -1)
+                               || !add_cipher_smcap(smcap, NID_aes_192_cbc, -1)
+                               || !add_cipher_smcap(smcap, NID_aes_128_cbc, -1)
+                       || !add_cipher_smcap(smcap, NID_des_ede3_cbc, -1)
+                               || !add_cipher_smcap(smcap, NID_rc2_cbc, 128)
+                               || !add_cipher_smcap(smcap, NID_rc2_cbc, 64)
+                               || !add_cipher_smcap(smcap, NID_des_cbc, -1)
+                               || !add_cipher_smcap(smcap, NID_rc2_cbc, 40)
+                               || !PKCS7_add_attrib_smimecap (si, smcap))
+                               goto err;
+                       sk_X509_ALGOR_pop_free(smcap, X509_ALGOR_free);
+                       smcap = NULL;
+                       }
+               if (flags & PKCS7_REUSE_DIGEST)
+                       {
+                       if (!pkcs7_copy_existing_digest(p7, si))
+                               goto err;
+                       if (!(flags & PKCS7_PARTIAL) &&
+                                       !PKCS7_SIGNER_INFO_sign(si))
+                               goto err;
+                       }
+               }
+       return si;
+       err:
+       if (smcap)
+               sk_X509_ALGOR_pop_free(smcap, X509_ALGOR_free);
        return NULL;
-}
+       }
+
+/* Search for a digest matching SignerInfo digest type and if found
+ * copy across.
+ */
+
+static int pkcs7_copy_existing_digest(PKCS7 *p7, PKCS7_SIGNER_INFO *si)
+       {
+       int i;
+       STACK_OF(PKCS7_SIGNER_INFO) *sinfos;
+       PKCS7_SIGNER_INFO *sitmp;
+       ASN1_OCTET_STRING *osdig = NULL;
+       sinfos = PKCS7_get_signer_info(p7);
+       for (i = 0; i < sk_PKCS7_SIGNER_INFO_num(sinfos); i++)
+               {
+               sitmp = sk_PKCS7_SIGNER_INFO_value(sinfos, i);
+               if (si == sitmp)
+                       break;
+               if (sk_X509_ATTRIBUTE_num(sitmp->auth_attr) <= 0)
+                       continue;
+               if (!OBJ_cmp(si->digest_alg->algorithm,
+                               sitmp->digest_alg->algorithm))
+                       {
+                       osdig = PKCS7_digest_from_attributes(sitmp->auth_attr);
+                       break;
+                       }
+
+               }
+
+       if (osdig)
+               return PKCS7_add1_attrib_digest(si, osdig->data, osdig->length);
+
+       PKCS7err(PKCS7_F_PKCS7_COPY_EXISTING_DIGEST,
+                       PKCS7_R_NO_MATCHING_DIGEST_TYPE_FOUND);
+       return 0;
+       }
 
 int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
                                        BIO *indata, BIO *out, int flags)
@@ -354,7 +452,7 @@ STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags)
 
        if(sk_PKCS7_SIGNER_INFO_num(sinfos) <= 0) {
                PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_NO_SIGNERS);
-               return NULL;
+               return 0;
        }
 
        if(!(signers = sk_X509_new_null())) {
@@ -377,12 +475,12 @@ STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags)
            if (!signer) {
                        PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND);
                        sk_X509_free(signers);
-                       return NULL;
+                       return 0;
            }
 
            if (!sk_X509_push(signers, signer)) {
-                       sk_X509_free(signers);
-                       return NULL;
+               sk_X509_free(signers);
+               return NULL;
            }
        }
        return signers;
@@ -405,7 +503,7 @@ PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher,
 
        if (!PKCS7_set_type(p7, NID_pkcs7_enveloped))
                goto err;
-       if(!PKCS7_set_cipher(p7, cipher)) {
+       if (!PKCS7_set_cipher(p7, cipher)) {
                PKCS7err(PKCS7_F_PKCS7_ENCRYPT,PKCS7_R_ERROR_SETTING_CIPHER);
                goto err;
        }
@@ -419,22 +517,11 @@ PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher,
                }
        }
 
-       if(!(p7bio = PKCS7_dataInit(p7, NULL))) {
-               PKCS7err(PKCS7_F_PKCS7_ENCRYPT,ERR_R_MALLOC_FAILURE);
-               goto err;
-       }
-
-       SMIME_crlf_copy(in, p7bio, flags);
-
-       (void)BIO_flush(p7bio);
-
-        if (!PKCS7_dataFinal(p7,p7bio)) {
-               PKCS7err(PKCS7_F_PKCS7_ENCRYPT,PKCS7_R_PKCS7_DATAFINAL_ERROR);
-               goto err;
-       }
-        BIO_free_all(p7bio);
+       if (flags & PKCS7_STREAM)
+               return p7;
 
-       return p7;
+       if (PKCS7_final(p7, in, flags))
+               return p7;
 
        err:
 
index cc092d2..e4d4431 100644 (file)
@@ -232,6 +232,9 @@ DECLARE_PKCS12_STACK_OF(PKCS7)
 #define PKCS7_type_is_signedAndEnveloped(a) \
                (OBJ_obj2nid((a)->type) == NID_pkcs7_signedAndEnveloped)
 #define PKCS7_type_is_data(a)   (OBJ_obj2nid((a)->type) == NID_pkcs7_data)
+#define PKCS7_type_is_digest(a)   (OBJ_obj2nid((a)->type) == NID_pkcs7_digest)
+#define PKCS7_type_is_encrypted(a) \
+               (OBJ_obj2nid((a)->type) == NID_pkcs7_encrypted)
 
 #define PKCS7_type_is_digest(a)   (OBJ_obj2nid((a)->type) == NID_pkcs7_digest)
 
@@ -242,14 +245,6 @@ DECLARE_PKCS12_STACK_OF(PKCS7)
 
 #define PKCS7_is_detached(p7) (PKCS7_type_is_signed(p7) && PKCS7_get_detached(p7))
 
-#ifdef SSLEAY_MACROS
-#ifndef PKCS7_ISSUER_AND_SERIAL_digest
-#define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \
-        ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\
-                       (char *)data,md,len)
-#endif
-#endif
-
 /* S/MIME related flags */
 
 #define PKCS7_TEXT             0x1
@@ -266,6 +261,8 @@ DECLARE_PKCS12_STACK_OF(PKCS7)
 #define PKCS7_CRLFEOL          0x800
 #define PKCS7_STREAM           0x1000
 #define PKCS7_NOCRL            0x2000
+#define PKCS7_PARTIAL          0x4000
+#define PKCS7_REUSE_DIGEST     0x8000
 
 /* Flags: for compatibility with older code */
 
@@ -281,7 +278,6 @@ DECLARE_PKCS12_STACK_OF(PKCS7)
 
 DECLARE_ASN1_FUNCTIONS(PKCS7_ISSUER_AND_SERIAL)
 
-#ifndef SSLEAY_MACROS
 int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data,const EVP_MD *type,
        unsigned char *md,unsigned int *len);
 #ifndef OPENSSL_NO_FP_API
@@ -291,7 +287,8 @@ int i2d_PKCS7_fp(FILE *fp,PKCS7 *p7);
 PKCS7 *PKCS7_dup(PKCS7 *p7);
 PKCS7 *d2i_PKCS7_bio(BIO *bp,PKCS7 **p7);
 int i2d_PKCS7_bio(BIO *bp,PKCS7 *p7);
-#endif
+int i2d_PKCS7_bio_stream(BIO *out, PKCS7 *p7, BIO *in, int flags);
+int PEM_write_bio_PKCS7_stream(BIO *out, PKCS7 *p7, BIO *in, int flags);
 
 DECLARE_ASN1_FUNCTIONS(PKCS7_SIGNER_INFO)
 DECLARE_ASN1_FUNCTIONS(PKCS7_RECIP_INFO)
@@ -307,6 +304,7 @@ DECLARE_ASN1_ITEM(PKCS7_ATTR_SIGN)
 DECLARE_ASN1_ITEM(PKCS7_ATTR_VERIFY)
 
 DECLARE_ASN1_NDEF_FUNCTION(PKCS7)
+DECLARE_ASN1_PRINT_FUNCTION(PKCS7)
 
 long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg);
 
@@ -315,6 +313,7 @@ int PKCS7_set0_type_other(PKCS7 *p7, int type, ASN1_TYPE *other);
 int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data);
 int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
        const EVP_MD *dgst);
+int PKCS7_SIGNER_INFO_sign(PKCS7_SIGNER_INFO *si);
 int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i);
 int PKCS7_add_certificate(PKCS7 *p7, X509 *x509);
 int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509);
@@ -336,9 +335,13 @@ int PKCS7_set_digest(PKCS7 *p7, const EVP_MD *md);
 STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7);
 
 PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509);
+void PKCS7_SIGNER_INFO_get0_algs(PKCS7_SIGNER_INFO *si, EVP_PKEY **pk,
+                                       X509_ALGOR **pdig, X509_ALGOR **psig);
+void PKCS7_RECIP_INFO_get0_alg(PKCS7_RECIP_INFO *ri, X509_ALGOR **penc);
 int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri);
 int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509);
 int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher);
+int PKCS7_stream(unsigned char ***boundary, PKCS7 *p7);
 
 PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx);
 ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk);
@@ -355,6 +358,12 @@ int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si,STACK_OF(X509_ATTRIBUTE) *sk);
 
 PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
                                                        BIO *data, int flags);
+
+PKCS7_SIGNER_INFO *PKCS7_sign_add_signer(PKCS7 *p7,
+                       X509 *signcert, EVP_PKEY *pkey, const EVP_MD *md,
+                       int flags);
+
+int PKCS7_final(PKCS7 *p7, BIO *data, int flags);
 int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
                                        BIO *indata, BIO *out, int flags);
 STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags);
@@ -367,10 +376,16 @@ int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si,
 STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si);
 int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg);
 
+int PKCS7_add_attrib_content_type(PKCS7_SIGNER_INFO *si, ASN1_OBJECT *coid);
+int PKCS7_add0_attrib_signing_time(PKCS7_SIGNER_INFO *si, ASN1_TIME *t);
+int PKCS7_add1_attrib_digest(PKCS7_SIGNER_INFO *si,
+                               const unsigned char *md, int mdlen);
+
 int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags);
 PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont);
-int SMIME_crlf_copy(BIO *in, BIO *out, int flags);
-int SMIME_text(BIO *in, BIO *out);
+
+BIO *BIO_new_PKCS7(BIO *out, PKCS7 *p7);
+
 
 /* BEGIN ERROR CODES */
 /* The following lines are auto generated by the script mkerr.pl. Any changes
@@ -383,12 +398,17 @@ void ERR_load_PKCS7_strings(void);
 /* Function codes. */
 #define PKCS7_F_B64_READ_PKCS7                          120
 #define PKCS7_F_B64_WRITE_PKCS7                                 121
+#define PKCS7_F_DO_PKCS7_SIGNED_ATTRIB                  136
+#define PKCS7_F_I2D_PKCS7_BIO_STREAM                    140
+#define PKCS7_F_PKCS7_ADD0_ATTRIB_SIGNING_TIME          135
 #define PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP               118
 #define PKCS7_F_PKCS7_ADD_CERTIFICATE                   100
 #define PKCS7_F_PKCS7_ADD_CRL                           101
 #define PKCS7_F_PKCS7_ADD_RECIPIENT_INFO                102
+#define PKCS7_F_PKCS7_ADD_SIGNATURE                     131
 #define PKCS7_F_PKCS7_ADD_SIGNER                        103
 #define PKCS7_F_PKCS7_BIO_ADD_DIGEST                    125
+#define PKCS7_F_PKCS7_COPY_EXISTING_DIGEST              138
 #define PKCS7_F_PKCS7_CTRL                              104
 #define PKCS7_F_PKCS7_DATADECODE                        112
 #define PKCS7_F_PKCS7_DATAFINAL                                 128
@@ -396,15 +416,22 @@ void ERR_load_PKCS7_strings(void);
 #define PKCS7_F_PKCS7_DATASIGN                          106
 #define PKCS7_F_PKCS7_DATAVERIFY                        107
 #define PKCS7_F_PKCS7_DECRYPT                           114
+#define PKCS7_F_PKCS7_DECRYPT_RINFO                     133
+#define PKCS7_F_PKCS7_ENCODE_RINFO                      132
 #define PKCS7_F_PKCS7_ENCRYPT                           115
+#define PKCS7_F_PKCS7_FINAL                             134
 #define PKCS7_F_PKCS7_FIND_DIGEST                       127
 #define PKCS7_F_PKCS7_GET0_SIGNERS                      124
+#define PKCS7_F_PKCS7_RECIP_INFO_SET                    130
 #define PKCS7_F_PKCS7_SET_CIPHER                        108
 #define PKCS7_F_PKCS7_SET_CONTENT                       109
 #define PKCS7_F_PKCS7_SET_DIGEST                        126
 #define PKCS7_F_PKCS7_SET_TYPE                          110
 #define PKCS7_F_PKCS7_SIGN                              116
 #define PKCS7_F_PKCS7_SIGNATUREVERIFY                   113
+#define PKCS7_F_PKCS7_SIGNER_INFO_SET                   129
+#define PKCS7_F_PKCS7_SIGNER_INFO_SIGN                  139
+#define PKCS7_F_PKCS7_SIGN_ADD_SIGNER                   137
 #define PKCS7_F_PKCS7_SIMPLE_SMIMECAP                   119
 #define PKCS7_F_PKCS7_VERIFY                            117
 #define PKCS7_F_SMIME_READ_PKCS7                        122
@@ -415,10 +442,13 @@ void ERR_load_PKCS7_strings(void);
 #define PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER                 144
 #define PKCS7_R_CIPHER_NOT_INITIALIZED                  116
 #define PKCS7_R_CONTENT_AND_DATA_PRESENT                118
+#define PKCS7_R_CTRL_ERROR                              152
 #define PKCS7_R_DECODE_ERROR                            130
 #define PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH           100
 #define PKCS7_R_DECRYPT_ERROR                           119
 #define PKCS7_R_DIGEST_FAILURE                          101
+#define PKCS7_R_ENCRYPTION_CTRL_FAILURE                         149
+#define PKCS7_R_ENCRYPTION_NOT_SUPPORTED_FOR_THIS_KEY_TYPE 150
 #define PKCS7_R_ERROR_ADDING_RECIPIENT                  120
 #define PKCS7_R_ERROR_SETTING_CIPHER                    121
 #define PKCS7_R_INVALID_MIME_TYPE                       131
@@ -429,6 +459,8 @@ void ERR_load_PKCS7_strings(void);
 #define PKCS7_R_MISSING_CERIPEND_INFO                   103
 #define PKCS7_R_NO_CONTENT                              122
 #define PKCS7_R_NO_CONTENT_TYPE                                 135
+#define PKCS7_R_NO_DEFAULT_DIGEST                       151
+#define PKCS7_R_NO_MATCHING_DIGEST_TYPE_FOUND           154
 #define PKCS7_R_NO_MULTIPART_BODY_FAILURE               136
 #define PKCS7_R_NO_MULTIPART_BOUNDARY                   137
 #define PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE        115
@@ -438,6 +470,7 @@ void ERR_load_PKCS7_strings(void);
 #define PKCS7_R_NO_SIG_CONTENT_TYPE                     138
 #define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE    104
 #define PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR               124
+#define PKCS7_R_PKCS7_ADD_SIGNER_ERROR                  153
 #define PKCS7_R_PKCS7_DATAFINAL                                 126
 #define PKCS7_R_PKCS7_DATAFINAL_ERROR                   125
 #define PKCS7_R_PKCS7_DATASIGN                          145
@@ -446,6 +479,8 @@ void ERR_load_PKCS7_strings(void);
 #define PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE  127
 #define PKCS7_R_SIGNATURE_FAILURE                       105
 #define PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND            128
+#define PKCS7_R_SIGNING_CTRL_FAILURE                    147
+#define PKCS7_R_SIGNING_NOT_SUPPORTED_FOR_THIS_KEY_TYPE         148
 #define PKCS7_R_SIG_INVALID_MIME_TYPE                   141
 #define PKCS7_R_SMIME_TEXT_ERROR                        129
 #define PKCS7_R_UNABLE_TO_FIND_CERTIFICATE              106
index c0e3d4c..d0af32a 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/pkcs7/pkcs7err.c */
 /* ====================================================================
- * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2007 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -72,12 +72,17 @@ static ERR_STRING_DATA PKCS7_str_functs[]=
        {
 {ERR_FUNC(PKCS7_F_B64_READ_PKCS7),     "B64_READ_PKCS7"},
 {ERR_FUNC(PKCS7_F_B64_WRITE_PKCS7),    "B64_WRITE_PKCS7"},
+{ERR_FUNC(PKCS7_F_DO_PKCS7_SIGNED_ATTRIB),     "DO_PKCS7_SIGNED_ATTRIB"},
+{ERR_FUNC(PKCS7_F_I2D_PKCS7_BIO_STREAM),       "i2d_PKCS7_bio_stream"},
+{ERR_FUNC(PKCS7_F_PKCS7_ADD0_ATTRIB_SIGNING_TIME),     "PKCS7_add0_attrib_signing_time"},
 {ERR_FUNC(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP),  "PKCS7_add_attrib_smimecap"},
 {ERR_FUNC(PKCS7_F_PKCS7_ADD_CERTIFICATE),      "PKCS7_add_certificate"},
 {ERR_FUNC(PKCS7_F_PKCS7_ADD_CRL),      "PKCS7_add_crl"},
 {ERR_FUNC(PKCS7_F_PKCS7_ADD_RECIPIENT_INFO),   "PKCS7_add_recipient_info"},
+{ERR_FUNC(PKCS7_F_PKCS7_ADD_SIGNATURE),        "PKCS7_add_signature"},
 {ERR_FUNC(PKCS7_F_PKCS7_ADD_SIGNER),   "PKCS7_add_signer"},
 {ERR_FUNC(PKCS7_F_PKCS7_BIO_ADD_DIGEST),       "PKCS7_BIO_ADD_DIGEST"},
+{ERR_FUNC(PKCS7_F_PKCS7_COPY_EXISTING_DIGEST), "PKCS7_COPY_EXISTING_DIGEST"},
 {ERR_FUNC(PKCS7_F_PKCS7_CTRL), "PKCS7_ctrl"},
 {ERR_FUNC(PKCS7_F_PKCS7_DATADECODE),   "PKCS7_dataDecode"},
 {ERR_FUNC(PKCS7_F_PKCS7_DATAFINAL),    "PKCS7_dataFinal"},
@@ -85,15 +90,22 @@ static ERR_STRING_DATA PKCS7_str_functs[]=
 {ERR_FUNC(PKCS7_F_PKCS7_DATASIGN),     "PKCS7_DATASIGN"},
 {ERR_FUNC(PKCS7_F_PKCS7_DATAVERIFY),   "PKCS7_dataVerify"},
 {ERR_FUNC(PKCS7_F_PKCS7_DECRYPT),      "PKCS7_decrypt"},
+{ERR_FUNC(PKCS7_F_PKCS7_DECRYPT_RINFO),        "PKCS7_DECRYPT_RINFO"},
+{ERR_FUNC(PKCS7_F_PKCS7_ENCODE_RINFO), "PKCS7_ENCODE_RINFO"},
 {ERR_FUNC(PKCS7_F_PKCS7_ENCRYPT),      "PKCS7_encrypt"},
+{ERR_FUNC(PKCS7_F_PKCS7_FINAL),        "PKCS7_final"},
 {ERR_FUNC(PKCS7_F_PKCS7_FIND_DIGEST),  "PKCS7_FIND_DIGEST"},
 {ERR_FUNC(PKCS7_F_PKCS7_GET0_SIGNERS), "PKCS7_get0_signers"},
+{ERR_FUNC(PKCS7_F_PKCS7_RECIP_INFO_SET),       "PKCS7_RECIP_INFO_set"},
 {ERR_FUNC(PKCS7_F_PKCS7_SET_CIPHER),   "PKCS7_set_cipher"},
 {ERR_FUNC(PKCS7_F_PKCS7_SET_CONTENT),  "PKCS7_set_content"},
 {ERR_FUNC(PKCS7_F_PKCS7_SET_DIGEST),   "PKCS7_set_digest"},
 {ERR_FUNC(PKCS7_F_PKCS7_SET_TYPE),     "PKCS7_set_type"},
 {ERR_FUNC(PKCS7_F_PKCS7_SIGN), "PKCS7_sign"},
 {ERR_FUNC(PKCS7_F_PKCS7_SIGNATUREVERIFY),      "PKCS7_signatureVerify"},
+{ERR_FUNC(PKCS7_F_PKCS7_SIGNER_INFO_SET),      "PKCS7_SIGNER_INFO_set"},
+{ERR_FUNC(PKCS7_F_PKCS7_SIGNER_INFO_SIGN),     "PKCS7_SIGNER_INFO_sign"},
+{ERR_FUNC(PKCS7_F_PKCS7_SIGN_ADD_SIGNER),      "PKCS7_sign_add_signer"},
 {ERR_FUNC(PKCS7_F_PKCS7_SIMPLE_SMIMECAP),      "PKCS7_simple_smimecap"},
 {ERR_FUNC(PKCS7_F_PKCS7_VERIFY),       "PKCS7_verify"},
 {ERR_FUNC(PKCS7_F_SMIME_READ_PKCS7),   "SMIME_read_PKCS7"},
@@ -107,10 +119,13 @@ static ERR_STRING_DATA PKCS7_str_reasons[]=
 {ERR_REASON(PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER),"cipher has no object identifier"},
 {ERR_REASON(PKCS7_R_CIPHER_NOT_INITIALIZED),"cipher not initialized"},
 {ERR_REASON(PKCS7_R_CONTENT_AND_DATA_PRESENT),"content and data present"},
+{ERR_REASON(PKCS7_R_CTRL_ERROR)          ,"ctrl error"},
 {ERR_REASON(PKCS7_R_DECODE_ERROR)        ,"decode error"},
 {ERR_REASON(PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH),"decrypted key is wrong length"},
 {ERR_REASON(PKCS7_R_DECRYPT_ERROR)       ,"decrypt error"},
 {ERR_REASON(PKCS7_R_DIGEST_FAILURE)      ,"digest failure"},
+{ERR_REASON(PKCS7_R_ENCRYPTION_CTRL_FAILURE),"encryption ctrl failure"},
+{ERR_REASON(PKCS7_R_ENCRYPTION_NOT_SUPPORTED_FOR_THIS_KEY_TYPE),"encryption not supported for this key type"},
 {ERR_REASON(PKCS7_R_ERROR_ADDING_RECIPIENT),"error adding recipient"},
 {ERR_REASON(PKCS7_R_ERROR_SETTING_CIPHER),"error setting cipher"},
 {ERR_REASON(PKCS7_R_INVALID_MIME_TYPE)   ,"invalid mime type"},
@@ -121,6 +136,8 @@ static ERR_STRING_DATA PKCS7_str_reasons[]=
 {ERR_REASON(PKCS7_R_MISSING_CERIPEND_INFO),"missing ceripend info"},
 {ERR_REASON(PKCS7_R_NO_CONTENT)          ,"no content"},
 {ERR_REASON(PKCS7_R_NO_CONTENT_TYPE)     ,"no content type"},
+{ERR_REASON(PKCS7_R_NO_DEFAULT_DIGEST)   ,"no default digest"},
+{ERR_REASON(PKCS7_R_NO_MATCHING_DIGEST_TYPE_FOUND),"no matching digest type found"},
 {ERR_REASON(PKCS7_R_NO_MULTIPART_BODY_FAILURE),"no multipart body failure"},
 {ERR_REASON(PKCS7_R_NO_MULTIPART_BOUNDARY),"no multipart boundary"},
 {ERR_REASON(PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE),"no recipient matches certificate"},
@@ -130,6 +147,7 @@ static ERR_STRING_DATA PKCS7_str_reasons[]=
 {ERR_REASON(PKCS7_R_NO_SIG_CONTENT_TYPE) ,"no sig content type"},
 {ERR_REASON(PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE),"operation not supported on this type"},
 {ERR_REASON(PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR),"pkcs7 add signature error"},
+{ERR_REASON(PKCS7_R_PKCS7_ADD_SIGNER_ERROR),"pkcs7 add signer error"},
 {ERR_REASON(PKCS7_R_PKCS7_DATAFINAL)     ,"pkcs7 datafinal"},
 {ERR_REASON(PKCS7_R_PKCS7_DATAFINAL_ERROR),"pkcs7 datafinal error"},
 {ERR_REASON(PKCS7_R_PKCS7_DATASIGN)      ,"pkcs7 datasign"},
@@ -138,6 +156,8 @@ static ERR_STRING_DATA PKCS7_str_reasons[]=
 {ERR_REASON(PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE),"private key does not match certificate"},
 {ERR_REASON(PKCS7_R_SIGNATURE_FAILURE)   ,"signature failure"},
 {ERR_REASON(PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND),"signer certificate not found"},
+{ERR_REASON(PKCS7_R_SIGNING_CTRL_FAILURE),"signing ctrl failure"},
+{ERR_REASON(PKCS7_R_SIGNING_NOT_SUPPORTED_FOR_THIS_KEY_TYPE),"signing not supported for this key type"},
 {ERR_REASON(PKCS7_R_SIG_INVALID_MIME_TYPE),"sig invalid mime type"},
 {ERR_REASON(PKCS7_R_SMIME_TEXT_ERROR)    ,"smime text error"},
 {ERR_REASON(PKCS7_R_UNABLE_TO_FIND_CERTIFICATE),"unable to find certificate"},
diff --git a/deps/openssl/openssl/crypto/ppccpuid.pl b/deps/openssl/openssl/crypto/ppccpuid.pl
new file mode 100644 (file)
index 0000000..369e1d0
--- /dev/null
@@ -0,0 +1,96 @@
+#!/usr/bin/env perl
+
+$flavour = shift;
+
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+( $xlate="${dir}ppc-xlate.pl" and -f $xlate ) or
+( $xlate="${dir}perlasm/ppc-xlate.pl" and -f $xlate) or
+die "can't locate ppc-xlate.pl";
+
+open STDOUT,"| $^X $xlate $flavour ".shift || die "can't call $xlate: $!";
+
+if ($flavour=~/64/) {
+    $CMPLI="cmpldi";
+    $SHRLI="srdi";
+    $SIGNX="extsw";
+} else {
+    $CMPLI="cmplwi";
+    $SHRLI="srwi";
+    $SIGNX="mr";
+}
+
+$code=<<___;
+.machine       "any"
+.text
+
+.globl .OPENSSL_cpuid_setup
+.align 4
+.OPENSSL_cpuid_setup:
+       blr
+
+.globl .OPENSSL_wipe_cpu
+.align 4
+.OPENSSL_wipe_cpu:
+       xor     r0,r0,r0
+       mr      r3,r1
+       xor     r4,r4,r4
+       xor     r5,r5,r5
+       xor     r6,r6,r6
+       xor     r7,r7,r7
+       xor     r8,r8,r8
+       xor     r9,r9,r9
+       xor     r10,r10,r10
+       xor     r11,r11,r11
+       xor     r12,r12,r12
+       blr
+
+.globl .OPENSSL_atomic_add
+.align 4
+.OPENSSL_atomic_add:
+Loop:  lwarx   r5,0,r3
+       add     r0,r4,r5
+       stwcx.  r0,0,r3
+       bne-    Loop
+       $SIGNX  r3,r0
+       blr
+
+.globl .OPENSSL_rdtsc
+.align 4
+.OPENSSL_rdtsc:
+       mftb    r3
+       mftbu   r4
+       blr
+
+.globl .OPENSSL_cleanse
+.align 4
+.OPENSSL_cleanse:
+       $CMPLI  r4,7
+       li      r0,0
+       bge     Lot
+       $CMPLI  r4,0
+       beqlr-
+Little:        mtctr   r4
+       stb     r0,0(r3)
+       addi    r3,r3,1
+       bdnz-   \$-8
+       blr
+Lot:   andi.   r5,r3,3
+       beq     Laligned
+       stb     r0,0(r3)
+       subi    r4,r4,1
+       addi    r3,r3,1
+       b       Lot
+Laligned:
+       $SHRLI  r5,r4,2
+       mtctr   r5
+       stw     r0,0(r3)
+       addi    r3,r3,4
+       bdnz-   \$-8
+       andi.   r4,r4,3
+       bne     Little
+       blr
+___
+
+$code =~ s/\`([^\`]*)\`/eval $1/gem;
+print $code;
+close STDOUT;
index 36bfc34..fb36a0c 100644 (file)
@@ -22,7 +22,7 @@ LIBOBJ=pqueue.o
 
 SRC= $(LIBSRC)
 
-EXHEADER= pqueue.h pq_compat.h
+EXHEADER= pqueue.h
 HEADER=        $(EXHEADER)
 
 ALL=    $(GENERAL) $(SRC) $(HEADER)
@@ -33,7 +33,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -79,6 +79,5 @@ pqueue.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 pqueue.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
 pqueue.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
 pqueue.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-pqueue.o: ../../include/openssl/pq_compat.h ../../include/openssl/safestack.h
-pqueue.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-pqueue.o: ../cryptlib.h pqueue.c pqueue.h
+pqueue.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+pqueue.o: ../../include/openssl/symhacks.h ../cryptlib.h pqueue.c pqueue.h
diff --git a/deps/openssl/openssl/crypto/pqueue/pq_compat.h b/deps/openssl/openssl/crypto/pqueue/pq_compat.h
deleted file mode 100644 (file)
index 7b2c327..0000000
+++ /dev/null
@@ -1,152 +0,0 @@
-/* crypto/pqueue/pqueue_compat.h */
-/* 
- * DTLS implementation written by Nagendra Modadugu
- * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.  
- */
-/* ====================================================================
- * Copyright (c) 1999-2005 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    openssl-core@OpenSSL.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
- * ====================================================================
- *
- * This product includes cryptographic software written by Eric Young
- * (eay@cryptsoft.com).  This product includes software written by Tim
- * Hudson (tjh@cryptsoft.com).
- *
- */
-
-#ifndef HEADER_PQ_COMPAT_H
-#define HEADER_PQ_COMPAT_H
-
-#include <openssl/opensslconf.h>
-#include <openssl/bn.h>
-
-/* 
- * The purpose of this header file is for supporting 64-bit integer
- * manipulation on 32-bit (and lower) machines.  Currently the only
- * such environment is VMS, Utrix and those with smaller default integer
- * sizes than 32 bits.  For all such environment, we fall back to using
- * BIGNUM.  We may need to fine tune the conditions for systems that
- * are incorrectly configured.
- *
- * The only clients of this code are (1) pqueue for priority, and
- * (2) DTLS, for sequence number manipulation.
- */
-
-#if (defined(THIRTY_TWO_BIT) && !defined(BN_LLONG)) || defined(SIXTEEN_BIT) || defined(EIGHT_BIT)
-
-#define PQ_64BIT_IS_INTEGER 0
-#define PQ_64BIT_IS_BIGNUM 1
-
-#define PQ_64BIT     BIGNUM
-#define PQ_64BIT_CTX BN_CTX
-
-#define pq_64bit_init(x)           BN_init(x)
-#define pq_64bit_free(x)           BN_free(x)
-
-#define pq_64bit_ctx_new(ctx)      BN_CTX_new()
-#define pq_64bit_ctx_free(x)       BN_CTX_free(x)
-
-#define pq_64bit_assign(x, y)      BN_copy(x, y)
-#define pq_64bit_assign_word(x, y) BN_set_word(x, y)
-#define pq_64bit_gt(x, y)          BN_ucmp(x, y) >= 1 ? 1 : 0
-#define pq_64bit_eq(x, y)          BN_ucmp(x, y) == 0 ? 1 : 0
-#define pq_64bit_add_word(x, w)    BN_add_word(x, w)
-#define pq_64bit_sub(r, x, y)      BN_sub(r, x, y)
-#define pq_64bit_sub_word(x, w)    BN_sub_word(x, w)
-#define pq_64bit_mod(r, x, n, ctx) BN_mod(r, x, n, ctx)
-
-#define pq_64bit_bin2num(bn, bytes, len)   BN_bin2bn(bytes, len, bn)
-#define pq_64bit_num2bin(bn, bytes)        BN_bn2bin(bn, bytes)
-#define pq_64bit_get_word(x)               BN_get_word(x)
-#define pq_64bit_is_bit_set(x, offset)     BN_is_bit_set(x, offset)
-#define pq_64bit_lshift(r, x, shift)       BN_lshift(r, x, shift)
-#define pq_64bit_set_bit(x, num)           BN_set_bit(x, num)
-#define pq_64bit_get_length(x)             BN_num_bits((x))
-
-#else
-
-#define PQ_64BIT_IS_INTEGER 1
-#define PQ_64BIT_IS_BIGNUM 0
-
-#if defined(SIXTY_FOUR_BIT)
-#define PQ_64BIT BN_ULONG
-#define PQ_64BIT_PRINT "%lld"
-#elif defined(SIXTY_FOUR_BIT_LONG)
-#define PQ_64BIT BN_ULONG
-#define PQ_64BIT_PRINT "%ld"
-#elif defined(THIRTY_TWO_BIT)
-#define PQ_64BIT BN_ULLONG
-#define PQ_64BIT_PRINT "%lld"
-#endif
-
-#define PQ_64BIT_CTX      void
-
-#define pq_64bit_init(x)
-#define pq_64bit_free(x)
-#define pq_64bit_ctx_new(ctx)        (ctx)
-#define pq_64bit_ctx_free(x)
-
-#define pq_64bit_assign(x, y)        (*(x) = *(y))
-#define pq_64bit_assign_word(x, y)   (*(x) = y)
-#define pq_64bit_gt(x, y)               (*(x) > *(y))
-#define pq_64bit_eq(x, y)            (*(x) == *(y))
-#define pq_64bit_add_word(x, w)      (*(x) = (*(x) + (w)))
-#define pq_64bit_sub(r, x, y)        (*(r) = (*(x) - *(y)))
-#define pq_64bit_sub_word(x, w)      (*(x) = (*(x) - (w)))
-#define pq_64bit_mod(r, x, n, ctx)
-
-#define pq_64bit_bin2num(num, bytes, len) bytes_to_long_long(bytes, num)
-#define pq_64bit_num2bin(num, bytes)      long_long_to_bytes(num, bytes)
-#define pq_64bit_get_word(x)              *(x)
-#define pq_64bit_lshift(r, x, shift)      (*(r) = (*(x) << (shift)))
-#define pq_64bit_set_bit(x, num)          do { \
-                                              PQ_64BIT mask = 1; \
-                                              mask = mask << (num); \
-                                              *(x) |= mask; \
-                                          } while(0)
-#endif /* OPENSSL_SYS_VMS */
-
-#endif
index 8ebba8a..eab13a1 100644 (file)
@@ -68,13 +68,12 @@ typedef struct _pqueue
        } pqueue_s;
 
 pitem *
-pitem_new(PQ_64BIT priority, void *data)
+pitem_new(unsigned char *prio64be, void *data)
        {
        pitem *item = (pitem *) OPENSSL_malloc(sizeof(pitem));
        if (item == NULL) return NULL;
 
-       pq_64bit_init(&(item->priority));
-       pq_64bit_assign(&item->priority, &priority);
+       memcpy(item->priority,prio64be,sizeof(item->priority));
 
        item->data = data;
        item->next = NULL;
@@ -87,7 +86,6 @@ pitem_free(pitem *item)
        {
        if (item == NULL) return;
 
-       pq_64bit_free(&(item->priority));
        OPENSSL_free(item);
        }
 
@@ -124,7 +122,10 @@ pqueue_insert(pqueue_s *pq, pitem *item)
                next != NULL;
                curr = next, next = next->next)
                {
-               if (pq_64bit_gt(&(next->priority), &(item->priority)))
+               /* we can compare 64-bit value in big-endian encoding
+                * with memcmp:-) */
+               int cmp = memcmp(next->priority, item->priority,8);
+               if (cmp > 0)            /* next > item */
                        {
                        item->next = next;
 
@@ -135,8 +136,8 @@ pqueue_insert(pqueue_s *pq, pitem *item)
 
                        return item;
                        }
-               /* duplicates not allowed */
-               if (pq_64bit_eq(&(item->priority), &(next->priority)))
+               
+               else if (cmp == 0)      /* duplicates not allowed */
                        return NULL;
                }
 
@@ -164,7 +165,7 @@ pqueue_pop(pqueue_s *pq)
        }
 
 pitem *
-pqueue_find(pqueue_s *pq, PQ_64BIT priority)
+pqueue_find(pqueue_s *pq, unsigned char *prio64be)
        {
        pitem *next;
        pitem *found = NULL;
@@ -174,7 +175,7 @@ pqueue_find(pqueue_s *pq, PQ_64BIT priority)
 
        for ( next = pq->items; next->next != NULL; next = next->next)
                {
-               if ( pq_64bit_eq(&(next->priority), &priority))
+               if ( memcmp(next->priority, prio64be,8) == 0)
                        {
                        found = next;
                        break;
@@ -182,16 +183,22 @@ pqueue_find(pqueue_s *pq, PQ_64BIT priority)
                }
        
        /* check the one last node */
-       if ( pq_64bit_eq(&(next->priority), &priority))
+       if ( memcmp(next->priority, prio64be,8) ==0)
                found = next;
 
        if ( ! found)
                return NULL;
 
+#if 0 /* find works in peek mode */
+       if ( prev == NULL)
+               pq->items = next->next;
+       else
+               prev->next = next->next;
+#endif
+
        return found;
        }
 
-#if PQ_64BIT_IS_INTEGER
 void
 pqueue_print(pqueue_s *pq)
        {
@@ -199,11 +206,14 @@ pqueue_print(pqueue_s *pq)
 
        while(item != NULL)
                {
-               printf("item\t" PQ_64BIT_PRINT "\n", item->priority);
+               printf("item\t%02x%02x%02x%02x%02x%02x%02x%02x\n",
+                       item->priority[0],item->priority[1],
+                       item->priority[2],item->priority[3],
+                       item->priority[4],item->priority[5],
+                       item->priority[6],item->priority[7]);
                item = item->next;
                }
        }
-#endif
 
 pitem *
 pqueue_iterator(pqueue_s *pq)
index 16c4072..87fc903 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
-#include <openssl/pq_compat.h>
-
 typedef struct _pqueue *pqueue;
 
 typedef struct _pitem
        {
-       PQ_64BIT priority;
+       unsigned char priority[8]; /* 64-bit value in big-endian encoding */
        void *data;
        struct _pitem *next;
        } pitem;
 
 typedef struct _pitem *piterator;
 
-pitem *pitem_new(PQ_64BIT priority, void *data);
+pitem *pitem_new(unsigned char *prio64be, void *data);
 void   pitem_free(pitem *item);
 
 pqueue pqueue_new(void);
@@ -86,7 +84,7 @@ void   pqueue_free(pqueue pq);
 pitem *pqueue_insert(pqueue pq, pitem *item);
 pitem *pqueue_peek(pqueue pq);
 pitem *pqueue_pop(pqueue pq);
-pitem *pqueue_find(pqueue pq, PQ_64BIT priority);
+pitem *pqueue_find(pqueue pq, unsigned char *prio64be);
 pitem *pqueue_iterator(pqueue pq);
 pitem *pqueue_next(piterator *iter);
 
index 3079430..27694aa 100644 (file)
@@ -17,9 +17,9 @@ TEST= randtest.c
 APPS=
 
 LIB=$(TOP)/libcrypto.a
-LIBSRC=md_rand.c randfile.c rand_lib.c rand_eng.c rand_err.c rand_egd.c \
+LIBSRC=md_rand.c randfile.c rand_lib.c rand_err.c rand_egd.c \
        rand_win.c rand_unix.c rand_os2.c rand_nw.c
-LIBOBJ=md_rand.o randfile.o rand_lib.o rand_eng.o rand_err.o rand_egd.o \
+LIBOBJ=md_rand.o randfile.o rand_lib.o rand_err.o rand_egd.o \
        rand_win.o rand_unix.o rand_os2.o rand_nw.o
 
 SRC= $(LIBSRC)
@@ -35,7 +35,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -79,34 +79,17 @@ clean:
 md_rand.o: ../../e_os.h ../../include/openssl/asn1.h
 md_rand.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
 md_rand.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-md_rand.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-md_rand.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-md_rand.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-md_rand.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-md_rand.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
-md_rand.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-md_rand.o: ../../include/openssl/symhacks.h md_rand.c rand_lcl.h
+md_rand.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+md_rand.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+md_rand.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+md_rand.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
+md_rand.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+md_rand.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+md_rand.o: md_rand.c rand_lcl.h
 rand_egd.o: ../../include/openssl/buffer.h ../../include/openssl/e_os2.h
 rand_egd.o: ../../include/openssl/opensslconf.h
 rand_egd.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
 rand_egd.o: rand_egd.c
-rand_eng.o: ../../e_os.h ../../include/openssl/asn1.h
-rand_eng.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
-rand_eng.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
-rand_eng.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
-rand_eng.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
-rand_eng.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
-rand_eng.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-rand_eng.o: ../../include/openssl/fips.h ../../include/openssl/fips_rand.h
-rand_eng.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-rand_eng.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-rand_eng.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-rand_eng.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
-rand_eng.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-rand_eng.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-rand_eng.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
-rand_eng.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-rand_eng.o: ../cryptlib.h rand_eng.c rand_lcl.h
 rand_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
 rand_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
 rand_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
@@ -116,39 +99,34 @@ rand_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
 rand_err.o: rand_err.c
 rand_lib.o: ../../e_os.h ../../include/openssl/asn1.h
 rand_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
-rand_lib.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
-rand_lib.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
+rand_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 rand_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 rand_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
 rand_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-rand_lib.o: ../../include/openssl/fips.h ../../include/openssl/fips_rand.h
 rand_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
 rand_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 rand_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 rand_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
 rand_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
 rand_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-rand_lib.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
 rand_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-rand_lib.o: ../cryptlib.h rand_lcl.h rand_lib.c
+rand_lib.o: ../cryptlib.h rand_lib.c
 rand_nw.o: ../../e_os.h ../../include/openssl/asn1.h
 rand_nw.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 rand_nw.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 rand_nw.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-rand_nw.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-rand_nw.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-rand_nw.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-rand_nw.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
-rand_nw.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-rand_nw.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-rand_nw.o: ../cryptlib.h rand_lcl.h rand_nw.c
+rand_nw.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+rand_nw.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+rand_nw.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+rand_nw.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
+rand_nw.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+rand_nw.o: ../../include/openssl/symhacks.h ../cryptlib.h rand_lcl.h rand_nw.c
 rand_os2.o: ../../e_os.h ../../include/openssl/asn1.h
 rand_os2.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 rand_os2.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 rand_os2.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-rand_os2.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-rand_os2.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-rand_os2.o: ../../include/openssl/opensslconf.h
+rand_os2.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+rand_os2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 rand_os2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 rand_os2.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
 rand_os2.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -158,8 +136,8 @@ rand_unix.o: ../../e_os.h ../../include/openssl/asn1.h
 rand_unix.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 rand_unix.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 rand_unix.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-rand_unix.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-rand_unix.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+rand_unix.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+rand_unix.o: ../../include/openssl/objects.h
 rand_unix.o: ../../include/openssl/opensslconf.h
 rand_unix.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 rand_unix.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
@@ -170,9 +148,8 @@ rand_win.o: ../../e_os.h ../../include/openssl/asn1.h
 rand_win.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 rand_win.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 rand_win.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-rand_win.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-rand_win.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-rand_win.o: ../../include/openssl/opensslconf.h
+rand_win.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+rand_win.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 rand_win.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 rand_win.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
 rand_win.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
index 0f8dd3e..b2f04ff 100644 (file)
 
 #include <openssl/crypto.h>
 #include <openssl/err.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
 
 #ifdef BN_DEBUG
 # define PREDICT
@@ -149,7 +145,7 @@ static unsigned int crypto_lock_rand = 0; /* may be set only when a thread
                                            * holds CRYPTO_LOCK_RAND
                                            * (to prevent double locking) */
 /* access to lockin_thread is synchronized by CRYPTO_LOCK_RAND2 */
-static unsigned long locking_thread = 0; /* valid iff crypto_lock_rand is set */
+static CRYPTO_THREADID locking_threadid; /* valid iff crypto_lock_rand is set */
 
 
 #ifdef PREDICT
@@ -217,8 +213,10 @@ static void ssleay_rand_add(const void *buf, int num, double add)
        /* check if we already have the lock */
        if (crypto_lock_rand)
                {
+               CRYPTO_THREADID cur;
+               CRYPTO_THREADID_current(&cur);
                CRYPTO_r_lock(CRYPTO_LOCK_RAND2);
-               do_not_lock = (locking_thread == CRYPTO_thread_id());
+               do_not_lock = !CRYPTO_THREADID_cmp(&locking_threadid, &cur);
                CRYPTO_r_unlock(CRYPTO_LOCK_RAND2);
                }
        else
@@ -274,8 +272,16 @@ static void ssleay_rand_add(const void *buf, int num, double add)
                        }
                else
                        MD_Update(&m,&(state[st_idx]),j);
-                       
+
+               /* DO NOT REMOVE THE FOLLOWING CALL TO MD_Update()! */
                MD_Update(&m,buf,j);
+               /* We know that line may cause programs such as
+                  purify and valgrind to complain about use of
+                  uninitialized data.  The problem is not, it's
+                  with the caller.  Removing that line will make
+                  sure you get really bad randomness and thereby
+                  other problems such as very insecure keys. */
+
                MD_Update(&m,(unsigned char *)&(md_c[0]),sizeof(md_c));
                MD_Final(&m,local_md);
                md_c[1]++;
@@ -336,14 +342,6 @@ static int ssleay_rand_bytes(unsigned char *buf, int num)
 #endif
        int do_stir_pool = 0;
 
-#ifdef OPENSSL_FIPS
-       if(FIPS_mode())
-           {
-           FIPSerr(FIPS_F_SSLEAY_RAND_BYTES,FIPS_R_NON_FIPS_METHOD);
-           return 0;
-           }
-#endif
-
 #ifdef PREDICT
        if (rand_predictable)
                {
@@ -384,7 +382,7 @@ static int ssleay_rand_bytes(unsigned char *buf, int num)
 
        /* prevent ssleay_rand_bytes() from trying to obtain the lock again */
        CRYPTO_w_lock(CRYPTO_LOCK_RAND2);
-       locking_thread = CRYPTO_thread_id();
+       CRYPTO_THREADID_current(&locking_threadid);
        CRYPTO_w_unlock(CRYPTO_LOCK_RAND2);
        crypto_lock_rand = 1;
 
@@ -476,9 +474,18 @@ static int ssleay_rand_bytes(unsigned char *buf, int num)
 #endif
                MD_Update(&m,local_md,MD_DIGEST_LENGTH);
                MD_Update(&m,(unsigned char *)&(md_c[0]),sizeof(md_c));
-#ifndef PURIFY
-               MD_Update(&m,buf,j); /* purify complains */
+
+#ifndef PURIFY /* purify complains */
+               /* The following line uses the supplied buffer as a small
+                * source of entropy: since this buffer is often uninitialised
+                * it may cause programs such as purify or valgrind to
+                * complain. So for those builds it is not used: the removal
+                * of such a small source of entropy has negligible impact on
+                * security.
+                */
+               MD_Update(&m,buf,j);
 #endif
+
                k=(st_idx+MD_DIGEST_LENGTH/2)-st_num;
                if (k > 0)
                        {
@@ -539,15 +546,17 @@ static int ssleay_rand_pseudo_bytes(unsigned char *buf, int num)
 
 static int ssleay_rand_status(void)
        {
+       CRYPTO_THREADID cur;
        int ret;
        int do_not_lock;
 
+       CRYPTO_THREADID_current(&cur);
        /* check if we already have the lock
         * (could happen if a RAND_poll() implementation calls RAND_status()) */
        if (crypto_lock_rand)
                {
                CRYPTO_r_lock(CRYPTO_LOCK_RAND2);
-               do_not_lock = (locking_thread == CRYPTO_thread_id());
+               do_not_lock = !CRYPTO_THREADID_cmp(&locking_threadid, &cur);
                CRYPTO_r_unlock(CRYPTO_LOCK_RAND2);
                }
        else
@@ -559,7 +568,7 @@ static int ssleay_rand_status(void)
                
                /* prevent ssleay_rand_bytes() from trying to obtain the lock again */
                CRYPTO_w_lock(CRYPTO_LOCK_RAND2);
-               locking_thread = CRYPTO_thread_id();
+               CRYPTO_THREADID_cpy(&locking_threadid, &cur);
                CRYPTO_w_unlock(CRYPTO_LOCK_RAND2);
                crypto_lock_rand = 1;
                }
index ea89153..ac6c021 100644 (file)
@@ -72,7 +72,7 @@ extern "C" {
 #endif
 
 #if defined(OPENSSL_FIPS)
-#define FIPS_RAND_SIZE_T int
+#define FIPS_RAND_SIZE_T size_t
 #endif
 
 /* Already defined in ossl_typ.h */
@@ -111,15 +111,6 @@ int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes);
 int RAND_egd(const char *path);
 int RAND_egd_bytes(const char *path,int bytes);
 int RAND_poll(void);
-#ifndef OPENSSL_NO_ENGINE
-#ifdef OPENSSL_FIPS
-void int_RAND_init_engine_callbacks(void);
-void int_RAND_set_callbacks(
-       int (*set_rand_func)(const RAND_METHOD *meth,
-                                               const RAND_METHOD **pmeth),
-       const RAND_METHOD *(*get_rand_func)(const RAND_METHOD **pmeth));
-#endif
-#endif
 
 #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
 
@@ -137,29 +128,11 @@ void ERR_load_RAND_strings(void);
 /* Error codes for the RAND functions. */
 
 /* Function codes. */
-#define RAND_F_ENG_RAND_GET_RAND_METHOD                         108
-#define RAND_F_FIPS_RAND                                103
-#define RAND_F_FIPS_RAND_BYTES                          102
-#define RAND_F_FIPS_RAND_GET_RAND_METHOD                109
-#define RAND_F_FIPS_RAND_SET_DT                                 106
-#define RAND_F_FIPS_SET_DT                              104
-#define RAND_F_FIPS_SET_PRNG_SEED                       107
-#define RAND_F_FIPS_SET_TEST_MODE                       105
 #define RAND_F_RAND_GET_RAND_METHOD                     101
 #define RAND_F_SSLEAY_RAND_BYTES                        100
 
 /* Reason codes. */
-#define RAND_R_NON_FIPS_METHOD                          105
-#define RAND_R_NOT_IN_TEST_MODE                                 106
-#define RAND_R_NO_KEY_SET                               107
-#define RAND_R_PRNG_ASKING_FOR_TOO_MUCH                         101
-#define RAND_R_PRNG_ERROR                               108
-#define RAND_R_PRNG_KEYED                               109
-#define RAND_R_PRNG_NOT_REKEYED                                 102
-#define RAND_R_PRNG_NOT_RESEEDED                        103
 #define RAND_R_PRNG_NOT_SEEDED                          100
-#define RAND_R_PRNG_SEED_MUST_NOT_MATCH_KEY             110
-#define RAND_R_PRNG_STUCK                               104
 
 #ifdef  __cplusplus
 }
index 50bce6c..d53b916 100644 (file)
@@ -95,7 +95,7 @@
  *   RAND_egd() is a wrapper for RAND_egd_bytes() with numbytes=255.
  */
 
-#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_NETWARE) || defined(OPENSSL_SYS_VOS)
+#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_NETWARE) || defined(OPENSSL_SYS_VOS) || defined(OPENSSL_SYS_BEOS)
 int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes)
        {
        return(-1);
diff --git a/deps/openssl/openssl/crypto/rand/rand_eng.c b/deps/openssl/openssl/crypto/rand/rand_eng.c
deleted file mode 100644 (file)
index 1669cef..0000000
+++ /dev/null
@@ -1,152 +0,0 @@
-/* crypto/rand/rand_lib.c */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-#include <stdio.h>
-#include <time.h>
-#include "cryptlib.h"
-#include "rand_lcl.h"
-#include <openssl/rand.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#include <openssl/fips_rand.h>
-#endif
-
-#ifndef OPENSSL_NO_ENGINE
-#include <openssl/engine.h>
-#endif
-
-#if defined(OPENSSL_FIPS) && !defined(OPENSSL_NO_ENGINE)
-
-/* non-NULL if default_RAND_meth is ENGINE-provided */
-static ENGINE *funct_ref =NULL;
-
-int eng_RAND_set_rand_method(const RAND_METHOD *meth, const RAND_METHOD **pmeth)
-       {
-       if(funct_ref)
-               {
-               ENGINE_finish(funct_ref);
-               funct_ref = NULL;
-               }
-       *pmeth = meth;
-       return 1;
-       }
-
-const RAND_METHOD *eng_RAND_get_rand_method(const RAND_METHOD **pmeth)
-       {
-       if (!*pmeth)
-               {
-               ENGINE *e = ENGINE_get_default_RAND();
-               if(e)
-                       {
-                       *pmeth = ENGINE_get_RAND(e);
-                       if(!*pmeth)
-                               {
-                               ENGINE_finish(e);
-                               e = NULL;
-                               }
-                       }
-               if(e)
-                       funct_ref = e;
-               else
-                       if(FIPS_mode())
-                               *pmeth=FIPS_rand_method();
-                       else
-                       *pmeth = RAND_SSLeay();
-               }
-
-       if(FIPS_mode()
-               && *pmeth != FIPS_rand_check())
-           {
-           RANDerr(RAND_F_ENG_RAND_GET_RAND_METHOD,RAND_R_NON_FIPS_METHOD);
-           return 0;
-           }
-
-       return *pmeth;
-       }
-
-int RAND_set_rand_engine(ENGINE *engine)
-       {
-       const RAND_METHOD *tmp_meth = NULL;
-       if(engine)
-               {
-               if(!ENGINE_init(engine))
-                       return 0;
-               tmp_meth = ENGINE_get_RAND(engine);
-               if(!tmp_meth)
-                       {
-                       ENGINE_finish(engine);
-                       return 0;
-                       }
-               }
-       /* This function releases any prior ENGINE so call it first */
-       RAND_set_rand_method(tmp_meth);
-       funct_ref = engine;
-       return 1;
-       }
-
-void int_RAND_init_engine_callbacks(void)
-       {
-       static int done = 0;
-       if (done)
-               return;
-       int_RAND_set_callbacks(eng_RAND_set_rand_method,
-                                eng_RAND_get_rand_method);
-       done = 1;
-       }
-
-#endif
index 829fb44..03cda4d 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/rand/rand_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2007 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 static ERR_STRING_DATA RAND_str_functs[]=
        {
-{ERR_FUNC(RAND_F_ENG_RAND_GET_RAND_METHOD),    "ENG_RAND_GET_RAND_METHOD"},
-{ERR_FUNC(RAND_F_FIPS_RAND),   "FIPS_RAND"},
-{ERR_FUNC(RAND_F_FIPS_RAND_BYTES),     "FIPS_RAND_BYTES"},
-{ERR_FUNC(RAND_F_FIPS_RAND_GET_RAND_METHOD),   "FIPS_RAND_GET_RAND_METHOD"},
-{ERR_FUNC(RAND_F_FIPS_RAND_SET_DT),    "FIPS_RAND_SET_DT"},
-{ERR_FUNC(RAND_F_FIPS_SET_DT), "FIPS_SET_DT"},
-{ERR_FUNC(RAND_F_FIPS_SET_PRNG_SEED),  "FIPS_SET_PRNG_SEED"},
-{ERR_FUNC(RAND_F_FIPS_SET_TEST_MODE),  "FIPS_SET_TEST_MODE"},
 {ERR_FUNC(RAND_F_RAND_GET_RAND_METHOD),        "RAND_get_rand_method"},
 {ERR_FUNC(RAND_F_SSLEAY_RAND_BYTES),   "SSLEAY_RAND_BYTES"},
 {0,NULL}
@@ -85,17 +77,7 @@ static ERR_STRING_DATA RAND_str_functs[]=
 
 static ERR_STRING_DATA RAND_str_reasons[]=
        {
-{ERR_REASON(RAND_R_NON_FIPS_METHOD)      ,"non fips method"},
-{ERR_REASON(RAND_R_NOT_IN_TEST_MODE)     ,"not in test mode"},
-{ERR_REASON(RAND_R_NO_KEY_SET)           ,"no key set"},
-{ERR_REASON(RAND_R_PRNG_ASKING_FOR_TOO_MUCH),"prng asking for too much"},
-{ERR_REASON(RAND_R_PRNG_ERROR)           ,"prng error"},
-{ERR_REASON(RAND_R_PRNG_KEYED)           ,"prng keyed"},
-{ERR_REASON(RAND_R_PRNG_NOT_REKEYED)     ,"prng not rekeyed"},
-{ERR_REASON(RAND_R_PRNG_NOT_RESEEDED)    ,"prng not reseeded"},
 {ERR_REASON(RAND_R_PRNG_NOT_SEEDED)      ,"PRNG not seeded"},
-{ERR_REASON(RAND_R_PRNG_SEED_MUST_NOT_MATCH_KEY),"prng seed must not match key"},
-{ERR_REASON(RAND_R_PRNG_STUCK)           ,"prng stuck"},
 {0,NULL}
        };
 
index 18cc9b1..618a8ec 100644 (file)
 #define        MD(a,b,c)               EVP_Digest(a,b,c,NULL,EVP_md2(), NULL)
 #endif
 
-#ifndef OPENSSL_NO_ENGINE
-void int_RAND_set_callbacks(
-       int (*set_rand_func)(const RAND_METHOD *meth,
-                                               const RAND_METHOD **pmeth),
-       const RAND_METHOD *(*get_rand_func)
-                                               (const RAND_METHOD **pmeth));
-int eng_RAND_set_rand_method(const RAND_METHOD *meth,
-                               const RAND_METHOD **pmeth);
-const RAND_METHOD *eng_RAND_get_rand_method(const RAND_METHOD **pmeth);
-#endif
-
 
 #endif
index da6b4e0..513e338 100644 (file)
 #include <time.h>
 #include "cryptlib.h"
 #include <openssl/rand.h>
-#include "rand_lcl.h"
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#include <openssl/fips_rand.h>
-#endif
-
 #ifndef OPENSSL_NO_ENGINE
 #include <openssl/engine.h>
 #endif
 
-static const RAND_METHOD *default_RAND_meth = NULL;
-
-#ifdef OPENSSL_FIPS
-
-static int fips_RAND_set_rand_method(const RAND_METHOD *meth,
-                                       const RAND_METHOD **pmeth)
-       {
-       *pmeth = meth;
-       return 1;
-       }
-
-static const RAND_METHOD *fips_RAND_get_rand_method(const RAND_METHOD **pmeth)
-       {
-       if (!*pmeth)
-               {
-               if(FIPS_mode())
-                       *pmeth=FIPS_rand_method();
-               else
-                       *pmeth = RAND_SSLeay();
-               }
-
-       if(FIPS_mode()
-               && *pmeth != FIPS_rand_check())
-           {
-           RANDerr(RAND_F_FIPS_RAND_GET_RAND_METHOD,RAND_R_NON_FIPS_METHOD);
-           return 0;
-           }
-
-       return *pmeth;
-       }
-
-static int (*RAND_set_rand_method_func)(const RAND_METHOD *meth,
-                                               const RAND_METHOD **pmeth)
-       = fips_RAND_set_rand_method;
-static const RAND_METHOD *(*RAND_get_rand_method_func)
-                                               (const RAND_METHOD **pmeth)
-       = fips_RAND_get_rand_method;
-
-#ifndef OPENSSL_NO_ENGINE
-void int_RAND_set_callbacks(
-       int (*set_rand_func)(const RAND_METHOD *meth,
-                                               const RAND_METHOD **pmeth),
-       const RAND_METHOD *(*get_rand_func)
-                                               (const RAND_METHOD **pmeth))
-       {
-       RAND_set_rand_method_func = set_rand_func;
-       RAND_get_rand_method_func = get_rand_func;
-       }
-#endif
-
-int RAND_set_rand_method(const RAND_METHOD *meth)
-       {
-       return RAND_set_rand_method_func(meth, &default_RAND_meth);
-       }
-
-const RAND_METHOD *RAND_get_rand_method(void)
-       {
-       return RAND_get_rand_method_func(&default_RAND_meth);
-       }
-
-#else
-
 #ifndef OPENSSL_NO_ENGINE
 /* non-NULL if default_RAND_meth is ENGINE-provided */
 static ENGINE *funct_ref =NULL;
 #endif
+static const RAND_METHOD *default_RAND_meth = NULL;
 
 int RAND_set_rand_method(const RAND_METHOD *meth)
        {
@@ -196,8 +129,6 @@ int RAND_set_rand_engine(ENGINE *engine)
        }
 #endif
 
-#endif
-
 void RAND_cleanup(void)
        {
        const RAND_METHOD *meth = RAND_get_rand_method();
index c3e36d4..fc1e78b 100644 (file)
@@ -78,8 +78,10 @@ typedef struct _CPUUTIL {
     ULONG ulIntrHigh;           /* High 32 bits of interrupt time */
 } CPUUTIL;
 
+#ifndef __KLIBC__
 APIRET APIENTRY(*DosPerfSysCall) (ULONG ulCommand, ULONG ulParm1, ULONG ulParm2, ULONG ulParm3) = NULL;
 APIRET APIENTRY(*DosQuerySysState) (ULONG func, ULONG arg1, ULONG pid, ULONG _res_, PVOID buf, ULONG bufsz) = NULL;
+#endif
 HMODULE hDoscalls = 0;
 
 int RAND_poll(void)
@@ -91,6 +93,7 @@ int RAND_poll(void)
     if (hDoscalls == 0) {
         ULONG rc = DosLoadModule(failed_module, sizeof(failed_module), "DOSCALLS", &hDoscalls);
 
+#ifndef __KLIBC__
         if (rc == 0) {
             rc = DosQueryProcAddr(hDoscalls, 976, NULL, (PFN *)&DosPerfSysCall);
 
@@ -102,6 +105,7 @@ int RAND_poll(void)
             if (rc)
                 DosQuerySysState = NULL;
         }
+#endif
     }
 
     /* Sample the hi-res timer, runs at around 1.1 MHz */
@@ -122,7 +126,9 @@ int RAND_poll(void)
             RAND_add(&util, sizeof(util), 10);
         }
         else {
+#ifndef __KLIBC__
             DosPerfSysCall = NULL;
+#endif
         }
     }
 
index 71b98ec..e3a6557 100644 (file)
 # define FD_SETSIZE (8*sizeof(fd_set))
 #endif
 
-#ifdef __OpenBSD__
+#if defined(OPENSSL_SYS_VOS)
+
+/* The following algorithm repeatedly samples the real-time clock
+   (RTC) to generate a sequence of unpredictable data.  The algorithm
+   relies upon the uneven execution speed of the code (due to factors
+   such as cache misses, interrupts, bus activity, and scheduling) and
+   upon the rather large relative difference between the speed of the
+   clock and the rate at which it can be read.
+
+   If this code is ported to an environment where execution speed is
+   more constant or where the RTC ticks at a much slower rate, or the
+   clock can be read with fewer instructions, it is likely that the
+   results would be far more predictable.
+
+   As a precaution, we generate 4 times the minimum required amount of
+   seed data.  */
+
+int RAND_poll(void)
+{
+       short int code;
+       gid_t curr_gid;
+       pid_t curr_pid;
+       uid_t curr_uid;
+       int i, k;
+       struct timespec ts;
+       unsigned char v;
+
+#ifdef OPENSSL_SYS_VOS_HPPA
+       long duration;
+       extern void s$sleep (long *_duration, short int *_code);
+#else
+#ifdef OPENSSL_SYS_VOS_IA32
+       long long duration;
+       extern void s$sleep2 (long long *_duration, short int *_code);
+#else
+#error "Unsupported Platform."
+#endif /* OPENSSL_SYS_VOS_IA32 */
+#endif /* OPENSSL_SYS_VOS_HPPA */
+
+       /* Seed with the gid, pid, and uid, to ensure *some*
+          variation between different processes.  */
+
+       curr_gid = getgid();
+       RAND_add (&curr_gid, sizeof curr_gid, 1);
+       curr_gid = 0;
+
+       curr_pid = getpid();
+       RAND_add (&curr_pid, sizeof curr_pid, 1);
+       curr_pid = 0;
+
+       curr_uid = getuid();
+       RAND_add (&curr_uid, sizeof curr_uid, 1);
+       curr_uid = 0;
+
+       for (i=0; i<(ENTROPY_NEEDED*4); i++)
+       {
+               /* burn some cpu; hope for interrupts, cache
+                  collisions, bus interference, etc.  */
+               for (k=0; k<99; k++)
+                       ts.tv_nsec = random ();
+
+#ifdef OPENSSL_SYS_VOS_HPPA
+               /* sleep for 1/1024 of a second (976 us).  */
+               duration = 1;
+               s$sleep (&duration, &code);
+#else
+#ifdef OPENSSL_SYS_VOS_IA32
+               /* sleep for 1/65536 of a second (15 us).  */
+               duration = 1;
+               s$sleep2 (&duration, &code);
+#endif /* OPENSSL_SYS_VOS_IA32 */
+#endif /* OPENSSL_SYS_VOS_HPPA */
+
+               /* get wall clock time.  */
+               clock_gettime (CLOCK_REALTIME, &ts);
+
+               /* take 8 bits */
+               v = (unsigned char) (ts.tv_nsec % 256);
+               RAND_add (&v, sizeof v, 1);
+               v = 0;
+       }
+       return 1;
+}
+#elif defined __OpenBSD__
 int RAND_poll(void)
 {
        u_int32_t rnd = 0, i;
@@ -163,7 +246,7 @@ int RAND_poll(void)
        static const char *randomfiles[] = { DEVRANDOM };
        struct stat randomstats[sizeof(randomfiles)/sizeof(randomfiles[0])];
        int fd;
-       size_t i;
+       unsigned int i;
 #endif
 #ifdef DEVRANDOM_EGD
        static const char *egdsockets[] = { DEVRANDOM_EGD, NULL };
@@ -176,7 +259,8 @@ int RAND_poll(void)
         * have this. Use /dev/urandom if you can as /dev/random may block
         * if it runs out of random entries.  */
 
-       for (i=0; i<sizeof(randomfiles)/sizeof(randomfiles[0]) && n < ENTROPY_NEEDED; i++)
+       for (i = 0; (i < sizeof(randomfiles)/sizeof(randomfiles[0])) &&
+                       (n < ENTROPY_NEEDED); i++)
                {
                if ((fd = open(randomfiles[i], O_RDONLY
 #ifdef O_NONBLOCK
@@ -193,7 +277,7 @@ int RAND_poll(void)
                        {
                        int usec = 10*1000; /* spend 10ms on each file */
                        int r;
-                       size_t j;
+                       unsigned int j;
                        struct stat *st=&randomstats[i];
 
                        /* Avoid using same input... Used to be O_NOFOLLOW
@@ -211,7 +295,12 @@ int RAND_poll(void)
                                {
                                int try_read = 0;
 
-#if defined(OPENSSL_SYS_LINUX)
+#if defined(OPENSSL_SYS_BEOS_R5)
+                               /* select() is broken in BeOS R5, so we simply
+                                *  try to read something and snooze if we couldn't */
+                               try_read = 1;
+
+#elif defined(OPENSSL_SYS_LINUX)
                                /* use poll() */
                                struct pollfd pset;
                                
@@ -258,6 +347,10 @@ int RAND_poll(void)
                                        r = read(fd,(unsigned char *)tmpbuf+n, ENTROPY_NEEDED-n);
                                        if (r > 0)
                                                n += r;
+#if defined(OPENSSL_SYS_BEOS_R5)
+                                       if (r == 0)
+                                               snooze(t.tv_usec);
+#endif
                                        }
                                else
                                        r = -1;
@@ -311,6 +404,14 @@ int RAND_poll(void)
        l=time(NULL);
        RAND_add(&l,sizeof(l),0.0);
 
+#if defined(OPENSSL_SYS_BEOS)
+       {
+       system_info sysInfo;
+       get_system_info(&sysInfo);
+       RAND_add(&sysInfo,sizeof(sysInfo),0);
+       }
+#endif
+
 #if defined(DEVRANDOM) || defined(DEVRANDOM_EGD)
        return 1;
 #else
index 1267a3a..0bfd8ff 100644 (file)
 # pragma message disable DOLLARID
 #endif
 
+/* Use 32-bit pointers almost everywhere.  Define the type to which to
+ * cast a pointer passed to an external function.
+ */
+#if __INITIAL_POINTER_SIZE == 64
+# define PTR_T __void_ptr64
+# pragma pointer_size save
+# pragma pointer_size 32
+#else /* __INITIAL_POINTER_SIZE == 64 */
+# define PTR_T void *
+#endif /* __INITIAL_POINTER_SIZE == 64 [else] */
+
 static struct items_data_st
        {
        short length, code;     /* length is amount of bytes */
@@ -125,11 +136,12 @@ int RAND_poll(void)
                {
                if (status == SS$_NORMAL)
                        {
-                       RAND_add(data_buffer, total_length, total_length/2);
+                       RAND_add( (PTR_T)data_buffer, total_length,
+                        total_length/2);
                        }
                }
        sys$gettim(iosb);
-       RAND_add((unsigned char *)iosb, sizeof(iosb), sizeof(iosb)/2);
+       RAND_add( (PTR_T)iosb, sizeof(iosb), sizeof(iosb)/2);
        return 1;
 }
 
index 1810568..bc7d9c5 100644 (file)
@@ -75,9 +75,7 @@
 #ifndef NO_SYS_TYPES_H
 # include <sys/types.h>
 #endif
-#ifdef MAC_OS_pre_X
-# include <stat.h>
-#else
+#ifndef OPENSSL_NO_POSIX_IO
 # include <sys/stat.h>
 #endif
 
@@ -111,12 +109,15 @@ int RAND_load_file(const char *file, long bytes)
         * if bytes == -1, read complete file. */
 
        MS_STATIC unsigned char buf[BUFSIZE];
+#ifndef OPENSSL_NO_POSIX_IO
        struct stat sb;
+#endif
        int i,ret=0,n;
        FILE *in;
 
        if (file == NULL) return(0);
 
+#ifndef OPENSSL_NO_POSIX_IO
 #ifdef PURIFY
        /* struct stat can have padding and unused fields that may not be
         * initialized in the call to stat(). We need to clear the entire
@@ -125,9 +126,9 @@ int RAND_load_file(const char *file, long bytes)
         */
        memset(&sb, 0, sizeof(sb));
 #endif
-
        if (stat(file,&sb) < 0) return(0);
        RAND_add(&sb,sizeof(sb),0.0);
+#endif
        if (bytes == 0) return(ret);
 
 #ifdef OPENSSL_SYS_VMS
@@ -136,14 +137,16 @@ int RAND_load_file(const char *file, long bytes)
        in=fopen(file,"rb");
 #endif
        if (in == NULL) goto err;
-#if defined(S_ISBLK) && defined(S_ISCHR)
-       if (S_ISBLK(sb.st_mode) || S_ISCHR(sb.st_mode)) {
+#if defined(S_IFBLK) && defined(S_IFCHR) && !defined(OPNESSL_NO_POSIX_IO)
+       if (sb.st_mode & (S_IFBLK | S_IFCHR)) {
          /* this file is a device. we don't want read an infinite number
           * of bytes from a random device, nor do we want to use buffered
           * I/O because we will waste system entropy. 
           */
          bytes = (bytes == -1) ? 2048 : bytes; /* ok, is 2048 enough? */
+#ifndef OPENSSL_NO_SETVBUF_IONBF
          setvbuf(in, NULL, _IONBF, 0); /* don't do buffered reads */
+#endif /* ndef OPENSSL_NO_SETVBUF_IONBF */
        }
 #endif
        for (;;)
@@ -179,6 +182,7 @@ int RAND_write_file(const char *file)
        int i,ret=0,rand_err=0;
        FILE *out = NULL;
        int n;
+#ifndef OPENSSL_NO_POSIX_IO
        struct stat sb;
        
        i=stat(file,&sb);
@@ -194,14 +198,16 @@ int RAND_write_file(const char *file)
          }
 #endif
        }
+#endif
 
-#if defined(O_CREAT) && !defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_SYS_VMS)
+#if defined(O_CREAT) && !defined(OPENSSL_NO_POSIX_IO) && !defined(OPENSSL_SYS_VMS)
        {
-       /* For some reason Win32 can't write to files created this way */
-       
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
        /* chmod(..., 0600) is too late to protect the file,
         * permissions should be restrictive from the start */
-       int fd = open(file, O_CREAT, 0600);
+       int fd = open(file, O_WRONLY|O_CREAT|O_BINARY, 0600);
        if (fd != -1)
                out = fdopen(fd, "wb");
        }
@@ -266,7 +272,6 @@ const char *RAND_file_name(char *buf, size_t size)
        {
        char *s=NULL;
 #ifdef __OpenBSD__
-       int ok = 0;
        struct stat sb;
 #endif
 
@@ -294,9 +299,6 @@ const char *RAND_file_name(char *buf, size_t size)
                        BUF_strlcat(buf,"/",size);
 #endif
                        BUF_strlcat(buf,RFILE,size);
-#ifdef __OpenBSD__
-                       ok = 1;
-#endif
                        }
                else
                        buf[0] = '\0'; /* no file name */
@@ -310,7 +312,7 @@ const char *RAND_file_name(char *buf, size_t size)
         * to something hopefully decent if that isn't available. 
         */
 
-       if (!ok)
+       if (!buf[0])
                if (BUF_strlcpy(buf,"/dev/arandom",size) >= size) {
                        return(NULL);
                }       
index 4b6292b..73eac34 100644 (file)
@@ -33,7 +33,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -78,11 +78,7 @@ rc2_cbc.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc2.h
 rc2_cbc.o: rc2_cbc.c rc2_locl.h
 rc2_ecb.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
 rc2_ecb.o: ../../include/openssl/rc2.h rc2_ecb.c rc2_locl.h
-rc2_skey.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
-rc2_skey.o: ../../include/openssl/fips.h ../../include/openssl/opensslconf.h
-rc2_skey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-rc2_skey.o: ../../include/openssl/rc2.h ../../include/openssl/safestack.h
-rc2_skey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+rc2_skey.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc2.h
 rc2_skey.o: rc2_locl.h rc2_skey.c
 rc2cfb64.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc2.h
 rc2cfb64.o: rc2_locl.h rc2cfb64.c
index e542ec9..34c8362 100644 (file)
@@ -79,9 +79,7 @@ typedef struct rc2_key_st
        RC2_INT data[64];
        } RC2_KEY;
 
-#ifdef OPENSSL_FIPS 
-void private_RC2_set_key(RC2_KEY *key, int len, const unsigned char *data,int bits);
-#endif
 void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data,int bits);
 void RC2_ecb_encrypt(const unsigned char *in,unsigned char *out,RC2_KEY *key,
                     int enc);
index 4e000e5..0150b0e 100644 (file)
  */
 
 #include <openssl/rc2.h>
-#include <openssl/crypto.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
 #include "rc2_locl.h"
 
-static unsigned char key_table[256]={
+static const unsigned char key_table[256]={
        0xd9,0x78,0xf9,0xc4,0x19,0xdd,0xb5,0xed,0x28,0xe9,0xfd,0x79,
        0x4a,0xa0,0xd8,0x9d,0xc6,0x7e,0x37,0x83,0x2b,0x76,0x53,0x8e,
        0x62,0x4c,0x64,0x88,0x44,0x8b,0xfb,0xa2,0x17,0x9a,0x59,0xf5,
@@ -99,20 +94,8 @@ static unsigned char key_table[256]={
  * BSAFE uses the 'retarded' version.  What I previously shipped is
  * the same as specifying 1024 for the 'bits' parameter.  Bsafe uses
  * a version where the bits parameter is the same as len*8 */
-
-#ifdef OPENSSL_FIPS
 void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data, int bits)
        {
-       if (FIPS_mode())
-               FIPS_BAD_ABORT(RC2)
-       private_RC2_set_key(key, len, data, bits);
-       }
-void private_RC2_set_key(RC2_KEY *key, int len, const unsigned char *data,
-                                                               int bits)
-#else
-void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data, int bits)
-#endif
-       {
        int i,j;
        unsigned char *k;
        RC2_INT *ki;
index f0bd767..264451a 100644 (file)
@@ -21,8 +21,8 @@ TEST=rc4test.c
 APPS=
 
 LIB=$(TOP)/libcrypto.a
-LIBSRC=rc4_skey.c rc4_enc.c rc4_fblk.c
-LIBOBJ=$(RC4_ENC) rc4_fblk.o
+LIBSRC=rc4_skey.c rc4_enc.c
+LIBOBJ=$(RC4_ENC)
 
 SRC= $(LIBSRC)
 
@@ -37,26 +37,26 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
-# ELF
-rx86-elf.s: asm/rc4-586.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) rc4-586.pl elf $(CFLAGS) > ../$@)
-# COFF
-rx86-cof.s: asm/rc4-586.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) rc4-586.pl coff $(CFLAGS) > ../$@)
-# a.out
-rx86-out.s: asm/rc4-586.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) rc4-586.pl a.out $(CFLAGS) > ../$@)
+rc4-586.s:     asm/rc4-586.pl ../perlasm/x86asm.pl
+       $(PERL) asm/rc4-586.pl $(PERLASM_SCHEME) $(CFLAGS) > $@
 
-rc4-x86_64.s: asm/rc4-x86_64.pl;       $(PERL) asm/rc4-x86_64.pl $@
+rc4-x86_64.s: asm/rc4-x86_64.pl
+       $(PERL) asm/rc4-x86_64.pl $(PERLASM_SCHEME) > $@
 
-rc4-ia64.s: asm/rc4-ia64.S
+rc4-ia64.S: asm/rc4-ia64.pl
+       $(PERL) asm/rc4-ia64.pl $(CFLAGS) > $@
+
+rc4-s390x.s:   asm/rc4-s390x.pl
+       $(PERL) asm/rc4-s390x.pl > $@
+
+rc4-ia64.s: rc4-ia64.S
        @case `awk '/^#define RC4_INT/{print$$NF}' $(TOP)/include/openssl/opensslconf.h` in \
-       int)    set -x; $(CC) $(CFLAGS) -DSZ=4 -E asm/rc4-ia64.S > $@ ;; \
-       char)   set -x; $(CC) $(CFLAGS) -DSZ=1 -E asm/rc4-ia64.S > $@ ;; \
+       int)    set -x; $(CC) $(CFLAGS) -DSZ=4 -E rc4-ia64.S > $@ ;; \
+       char)   set -x; $(CC) $(CFLAGS) -DSZ=1 -E rc4-ia64.S > $@ ;; \
        *)      exit 1 ;; \
        esac
 
@@ -105,20 +105,10 @@ rc4_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 rc4_enc.o: ../../include/openssl/rc4.h ../../include/openssl/safestack.h
 rc4_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
 rc4_enc.o: ../cryptlib.h rc4_enc.c rc4_locl.h
-rc4_fblk.o: ../../e_os.h ../../include/openssl/bio.h
-rc4_fblk.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
-rc4_fblk.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-rc4_fblk.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-rc4_fblk.o: ../../include/openssl/opensslconf.h
-rc4_fblk.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-rc4_fblk.o: ../../include/openssl/rc4.h ../../include/openssl/safestack.h
-rc4_fblk.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-rc4_fblk.o: ../cryptlib.h rc4_fblk.c rc4_locl.h
 rc4_skey.o: ../../e_os.h ../../include/openssl/bio.h
 rc4_skey.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 rc4_skey.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-rc4_skey.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-rc4_skey.o: ../../include/openssl/opensslconf.h
+rc4_skey.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
 rc4_skey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 rc4_skey.o: ../../include/openssl/rc4.h ../../include/openssl/safestack.h
 rc4_skey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
index ef7eee7..38a44a7 100644 (file)
@@ -1,14 +1,21 @@
-#!/usr/local/bin/perl
+#!/usr/bin/env perl
+
+# ====================================================================
+# [Re]written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
 
 # At some point it became apparent that the original SSLeay RC4
-# assembler implementation performs suboptimaly on latest IA-32
+# assembler implementation performs suboptimally on latest IA-32
 # microarchitectures. After re-tuning performance has changed as
 # following:
 #
-# Pentium      +0%
-# Pentium III  +17%
-# AMD          +52%(*)
-# P4           +180%(**)
+# Pentium      -10%
+# Pentium III  +12%
+# AMD          +50%(*)
+# P4           +250%(**)
 #
 # (*)  This number is actually a trade-off:-) It's possible to
 #      achieve +72%, but at the cost of -48% off PIII performance.
 #      For reference! This code delivers ~80% of rc4-amd64.pl
 #      performance on the same Opteron machine.
 # (**) This number requires compressed key schedule set up by
-#      RC4_set_key and therefore doesn't apply to 0.9.7 [option for
-#      compressed key schedule is implemented in 0.9.8 and later,
-#      see commentary section in rc4_skey.c for further details].
+#      RC4_set_key [see commentary below for further details].
 #
 #                                      <appro@fy.chalmers.se>
 
-push(@INC,"perlasm","../../perlasm");
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+push(@INC,"${dir}","${dir}../../perlasm");
 require "x86asm.pl";
 
 &asm_init($ARGV[0],"rc4-586.pl");
 
-$x="eax";
-$y="ebx";
+$xx="eax";
+$yy="ebx";
 $tx="ecx";
 $ty="edx";
-$in="esi";
-$out="edi";
-$d="ebp";
-
-&RC4("RC4");
-
-&asm_finish();
-
-sub RC4_loop
-       {
-       local($n,$p,$char)=@_;
-
-       &comment("Round $n");
-
-       if ($char)
-               {
-               if ($p >= 0)
-                       {
-                        &mov($ty,      &swtmp(2));
-                       &cmp($ty,       $in);
-                        &jbe(&label("finished"));
-                       &inc($in);
-                       }
-               else
-                       {
-                       &add($ty,       8);
-                        &inc($in);
-                       &cmp($ty,       $in);
-                        &jb(&label("finished"));
-                       &mov(&swtmp(2), $ty);
-                       }
-               }
-       # Moved out
-       # &mov( $tx,            &DWP(0,$d,$x,4)) if $p < 0;
-
-       &add(   &LB($y),        &LB($tx));
-       &mov(   $ty,            &DWP(0,$d,$y,4));
-        # XXX
-       &mov(   &DWP(0,$d,$x,4),$ty);
-        &add(  $ty,            $tx);
-       &mov(   &DWP(0,$d,$y,4),$tx);
-        &and(  $ty,            0xff);
-        &inc(  &LB($x));                       # NEXT ROUND
-       &mov(   $tx,            &DWP(0,$d,$x,4)) if $p < 1; # NEXT ROUND
-        &mov(  $ty,            &DWP(0,$d,$ty,4));
-
-       if (!$char)
-               {
-               #moved up into last round
-               if ($p >= 1)
-                       {
-                       &add(   $out,   8)
-                       }
-               &movb(  &BP($n,"esp","",0),     &LB($ty));
-               }
-       else
-               {
-               # Note in+=8 has occured
-               &movb(  &HB($ty),       &BP(-1,$in,"",0));
-                # XXX
-               &xorb(&LB($ty),         &HB($ty));
-                # XXX
-               &movb(&BP($n,$out,"",0),&LB($ty));
-               }
+$inp="esi";
+$out="ebp";
+$dat="edi";
+
+sub RC4_loop {
+  my $i=shift;
+  my $func = ($i==0)?*mov:*or;
+
+       &add    (&LB($yy),&LB($tx));
+       &mov    ($ty,&DWP(0,$dat,$yy,4));
+       &mov    (&DWP(0,$dat,$yy,4),$tx);
+       &mov    (&DWP(0,$dat,$xx,4),$ty);
+       &add    ($ty,$tx);
+       &inc    (&LB($xx));
+       &and    ($ty,0xff);
+       &ror    ($out,8)        if ($i!=0);
+       if ($i<3) {
+         &mov  ($tx,&DWP(0,$dat,$xx,4));
+       } else {
+         &mov  ($tx,&wparam(3));       # reload [re-biased] out
        }
-
-
-sub RC4
-       {
-       local($name)=@_;
-
-       &function_begin_B($name,"");
-
-       &mov($ty,&wparam(1));           # len
-       &cmp($ty,0);
-       &jne(&label("proceed"));
-       &ret();
-       &set_label("proceed");
-
-       &comment("");
-
-       &push("ebp");
-        &push("ebx");
-       &push("esi");
-        &xor(  $x,     $x);            # avoid partial register stalls
-       &push("edi");
-        &xor(  $y,     $y);            # avoid partial register stalls
-       &mov(   $d,     &wparam(0));    # key
-        &mov(  $in,    &wparam(2));
-
-       &movb(  &LB($x),        &BP(0,$d,"",1));
-        &movb( &LB($y),        &BP(4,$d,"",1));
-
-       &mov(   $out,   &wparam(3));
-        &inc(  &LB($x));
-
-       &stack_push(3); # 3 temp variables
-        &add(  $d,     8);
-
-       # detect compressed schedule, see commentary section in rc4_skey.c...
-       # in 0.9.7 context ~50 bytes below RC4_CHAR label remain redundant,
-       # as compressed key schedule is set up in 0.9.8 and later.
-       &cmp(&DWP(256,$d),-1);
-       &je(&label("RC4_CHAR"));
-
-        &lea(  $ty,    &DWP(-8,$ty,$in));
-
-       # check for 0 length input
-
-        &mov(  &swtmp(2),      $ty);   # this is now address to exit at
-       &mov(   $tx,    &DWP(0,$d,$x,4));
-
-        &cmp(  $ty,    $in);
-       &jb(    &label("end")); # less than 8 bytes
-
-       &set_label("start");
-
-       # filling DELAY SLOT
-       &add(   $in,    8);
-
-       &RC4_loop(0,-1,0);
-       &RC4_loop(1,0,0);
-       &RC4_loop(2,0,0);
-       &RC4_loop(3,0,0);
-       &RC4_loop(4,0,0);
-       &RC4_loop(5,0,0);
-       &RC4_loop(6,0,0);
-       &RC4_loop(7,1,0);
-       
-       &comment("apply the cipher text");
-       # xor the cipher data with input
-
-       #&add(  $out,   8); #moved up into last round
-
-       &mov(   $tx,    &swtmp(0));
-        &mov(  $ty,    &DWP(-8,$in,"",0));
-       &xor(   $tx,    $ty);
-        &mov(  $ty,    &DWP(-4,$in,"",0)); 
-       &mov(   &DWP(-8,$out,"",0),     $tx);
-        &mov(  $tx,    &swtmp(1));
-       &xor(   $tx,    $ty);
-        &mov(  $ty,    &swtmp(2));     # load end ptr;
-       &mov(   &DWP(-4,$out,"",0),     $tx);
-        &mov(  $tx,            &DWP(0,$d,$x,4));
-       &cmp($in,       $ty);
-        &jbe(&label("start"));
-
-       &set_label("end");
-
-       # There is quite a bit of extra crap in RC4_loop() for this
-       # first round
-       &RC4_loop(0,-1,1);
-       &RC4_loop(1,0,1);
-       &RC4_loop(2,0,1);
-       &RC4_loop(3,0,1);
-       &RC4_loop(4,0,1);
-       &RC4_loop(5,0,1);
-       &RC4_loop(6,1,1);
-
-       &jmp(&label("finished"));
-
-       &align(16);
-       # this is essentially Intel P4 specific codepath, see rc4_skey.c,
-       # and is engaged in 0.9.8 and later context...
-       &set_label("RC4_CHAR");
-
-       &lea    ($ty,&DWP(0,$in,$ty));
-       &mov    (&swtmp(2),$ty);
-       &movz   ($tx,&BP(0,$d,$x));
-
+       &$func  ($out,&DWP(0,$dat,$ty,4));
+}
+
+# void RC4(RC4_KEY *key,size_t len,const unsigned char *inp,unsigned char *out);
+&function_begin("RC4");
+       &mov    ($dat,&wparam(0));      # load key schedule pointer
+       &mov    ($ty, &wparam(1));      # load len
+       &mov    ($inp,&wparam(2));      # load inp
+       &mov    ($out,&wparam(3));      # load out
+
+       &xor    ($xx,$xx);              # avoid partial register stalls
+       &xor    ($yy,$yy);
+
+       &cmp    ($ty,0);                # safety net
+       &je     (&label("abort"));
+
+       &mov    (&LB($xx),&BP(0,$dat)); # load key->x
+       &mov    (&LB($yy),&BP(4,$dat)); # load key->y
+       &add    ($dat,8);
+
+       &lea    ($tx,&DWP(0,$inp,$ty));
+       &sub    ($out,$inp);            # re-bias out
+       &mov    (&wparam(1),$tx);       # save input+len
+
+       &inc    (&LB($xx));
+
+       # detect compressed key schedule...
+       &cmp    (&DWP(256,$dat),-1);
+       &je     (&label("RC4_CHAR"));
+
+       &mov    ($tx,&DWP(0,$dat,$xx,4));
+
+       &and    ($ty,-4);               # how many 4-byte chunks?
+       &jz     (&label("loop1"));
+
+       &lea    ($ty,&DWP(-4,$inp,$ty));
+       &mov    (&wparam(2),$ty);       # save input+(len/4)*4-4
+       &mov    (&wparam(3),$out);      # $out as accumulator in this loop
+
+       &set_label("loop4",16);
+               for ($i=0;$i<4;$i++) { RC4_loop($i); }
+               &ror    ($out,8);
+               &xor    ($out,&DWP(0,$inp));
+               &cmp    ($inp,&wparam(2));      # compare to input+(len/4)*4-4
+               &mov    (&DWP(0,$tx,$inp),$out);# $tx holds re-biased out here
+               &lea    ($inp,&DWP(4,$inp));
+               &mov    ($tx,&DWP(0,$dat,$xx,4));
+       &jb     (&label("loop4"));
+
+       &cmp    ($inp,&wparam(1));      # compare to input+len
+       &je     (&label("done"));
+       &mov    ($out,&wparam(3));      # restore $out
+
+       &set_label("loop1",16);
+               &add    (&LB($yy),&LB($tx));
+               &mov    ($ty,&DWP(0,$dat,$yy,4));
+               &mov    (&DWP(0,$dat,$yy,4),$tx);
+               &mov    (&DWP(0,$dat,$xx,4),$ty);
+               &add    ($ty,$tx);
+               &inc    (&LB($xx));
+               &and    ($ty,0xff);
+               &mov    ($ty,&DWP(0,$dat,$ty,4));
+               &xor    (&LB($ty),&BP(0,$inp));
+               &lea    ($inp,&DWP(1,$inp));
+               &mov    ($tx,&DWP(0,$dat,$xx,4));
+               &cmp    ($inp,&wparam(1));      # compare to input+len
+               &mov    (&BP(-1,$out,$inp),&LB($ty));
+       &jb     (&label("loop1"));
+
+       &jmp    (&label("done"));
+
+# this is essentially Intel P4 specific codepath...
+&set_label("RC4_CHAR",16);
+       &movz   ($tx,&BP(0,$dat,$xx));
        # strangely enough unrolled loop performs over 20% slower...
-       &set_label("RC4_CHAR_loop");
-               &add    (&LB($y),&LB($tx));
-               &movz   ($ty,&BP(0,$d,$y));
-               &movb   (&BP(0,$d,$y),&LB($tx));
-               &movb   (&BP(0,$d,$x),&LB($ty));
+       &set_label("cloop1");
+               &add    (&LB($yy),&LB($tx));
+               &movz   ($ty,&BP(0,$dat,$yy));
+               &mov    (&BP(0,$dat,$yy),&LB($tx));
+               &mov    (&BP(0,$dat,$xx),&LB($ty));
                &add    (&LB($ty),&LB($tx));
-               &movz   ($ty,&BP(0,$d,$ty));
-               &add    (&LB($x),1);
-               &xorb   (&LB($ty),&BP(0,$in));
-               &lea    ($in,&DWP(1,$in));
-               &movz   ($tx,&BP(0,$d,$x));
-               &cmp    ($in,&swtmp(2));
-               &movb   (&BP(0,$out),&LB($ty));
-               &lea    ($out,&DWP(1,$out));
-       &jb     (&label("RC4_CHAR_loop"));
-
-       &set_label("finished");
-       &dec(   $x);
-        &stack_pop(3);
-       &movb(  &BP(-4,$d,"",0),&LB($y));
-        &movb( &BP(-8,$d,"",0),&LB($x));
-
-       &function_end($name);
-       }
+               &movz   ($ty,&BP(0,$dat,$ty));
+               &add    (&LB($xx),1);
+               &xor    (&LB($ty),&BP(0,$inp));
+               &lea    ($inp,&DWP(1,$inp));
+               &movz   ($tx,&BP(0,$dat,$xx));
+               &cmp    ($inp,&wparam(1));
+               &mov    (&BP(-1,$out,$inp),&LB($ty));
+       &jb     (&label("cloop1"));
+
+&set_label("done");
+       &dec    (&LB($xx));
+       &mov    (&BP(-4,$dat),&LB($yy));        # save key->y
+       &mov    (&BP(-8,$dat),&LB($xx));        # save key->x
+&set_label("abort");
+&function_end("RC4");
+
+########################################################################
+
+$inp="esi";
+$out="edi";
+$idi="ebp";
+$ido="ecx";
+$idx="edx";
+
+&external_label("OPENSSL_ia32cap_P");
+
+# void RC4_set_key(RC4_KEY *key,int len,const unsigned char *data);
+&function_begin("RC4_set_key");
+       &mov    ($out,&wparam(0));              # load key
+       &mov    ($idi,&wparam(1));              # load len
+       &mov    ($inp,&wparam(2));              # load data
+       &picmeup($idx,"OPENSSL_ia32cap_P");
+
+       &lea    ($out,&DWP(2*4,$out));          # &key->data
+       &lea    ($inp,&DWP(0,$inp,$idi));       # $inp to point at the end
+       &neg    ($idi);
+       &xor    ("eax","eax");
+       &mov    (&DWP(-4,$out),$idi);           # borrow key->y
+
+       &bt     (&DWP(0,$idx),20);              # check for bit#20
+       &jc     (&label("c1stloop"));
+
+&set_label("w1stloop",16);
+       &mov    (&DWP(0,$out,"eax",4),"eax");   # key->data[i]=i;
+       &add    (&LB("eax"),1);                 # i++;
+       &jnc    (&label("w1stloop"));
+
+       &xor    ($ido,$ido);
+       &xor    ($idx,$idx);
+
+&set_label("w2ndloop",16);
+       &mov    ("eax",&DWP(0,$out,$ido,4));
+       &add    (&LB($idx),&BP(0,$inp,$idi));
+       &add    (&LB($idx),&LB("eax"));
+       &add    ($idi,1);
+       &mov    ("ebx",&DWP(0,$out,$idx,4));
+       &jnz    (&label("wnowrap"));
+         &mov  ($idi,&DWP(-4,$out));
+       &set_label("wnowrap");
+       &mov    (&DWP(0,$out,$idx,4),"eax");
+       &mov    (&DWP(0,$out,$ido,4),"ebx");
+       &add    (&LB($ido),1);
+       &jnc    (&label("w2ndloop"));
+&jmp   (&label("exit"));
+
+# Unlike all other x86 [and x86_64] implementations, Intel P4 core
+# [including EM64T] was found to perform poorly with above "32-bit" key
+# schedule, a.k.a. RC4_INT. Performance improvement for IA-32 hand-coded
+# assembler turned out to be 3.5x if re-coded for compressed 8-bit one,
+# a.k.a. RC4_CHAR! It's however inappropriate to just switch to 8-bit
+# schedule for x86[_64], because non-P4 implementations suffer from
+# significant performance losses then, e.g. PIII exhibits >2x
+# deterioration, and so does Opteron. In order to assure optimal
+# all-round performance, we detect P4 at run-time and set up compressed
+# key schedule, which is recognized by RC4 procedure.
+
+&set_label("c1stloop",16);
+       &mov    (&BP(0,$out,"eax"),&LB("eax")); # key->data[i]=i;
+       &add    (&LB("eax"),1);                 # i++;
+       &jnc    (&label("c1stloop"));
+
+       &xor    ($ido,$ido);
+       &xor    ($idx,$idx);
+       &xor    ("ebx","ebx");
+
+&set_label("c2ndloop",16);
+       &mov    (&LB("eax"),&BP(0,$out,$ido));
+       &add    (&LB($idx),&BP(0,$inp,$idi));
+       &add    (&LB($idx),&LB("eax"));
+       &add    ($idi,1);
+       &mov    (&LB("ebx"),&BP(0,$out,$idx));
+       &jnz    (&label("cnowrap"));
+         &mov  ($idi,&DWP(-4,$out));
+       &set_label("cnowrap");
+       &mov    (&BP(0,$out,$idx),&LB("eax"));
+       &mov    (&BP(0,$out,$ido),&LB("ebx"));
+       &add    (&LB($ido),1);
+       &jnc    (&label("c2ndloop"));
+
+       &mov    (&DWP(256,$out),-1);            # mark schedule as compressed
+
+&set_label("exit");
+       &xor    ("eax","eax");
+       &mov    (&DWP(-8,$out),"eax");          # key->x=0;
+       &mov    (&DWP(-4,$out),"eax");          # key->y=0;
+&function_end("RC4_set_key");
+
+# const char *RC4_options(void);
+&function_begin_B("RC4_options");
+       &call   (&label("pic_point"));
+&set_label("pic_point");
+       &blindpop("eax");
+       &lea    ("eax",&DWP(&label("opts")."-".&label("pic_point"),"eax"));
+       &picmeup("edx","OPENSSL_ia32cap_P");
+       &bt     (&DWP(0,"edx"),20);
+       &jnc    (&label("skip"));
+         &add  ("eax",12);
+       &set_label("skip");
+       &ret    ();
+&set_label("opts",64);
+&asciz ("rc4(4x,int)");
+&asciz ("rc4(1x,char)");
+&asciz ("RC4 for x86, CRYPTOGAMS by <appro\@openssl.org>");
+&align (64);
+&function_end_B("RC4_options");
+
+&asm_finish();
 
diff --git a/deps/openssl/openssl/crypto/rc4/asm/rc4-ia64.S b/deps/openssl/openssl/crypto/rc4/asm/rc4-ia64.S
deleted file mode 100644 (file)
index 8210c47..0000000
+++ /dev/null
@@ -1,159 +0,0 @@
-// ====================================================================
-// Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
-// project.
-//
-// Rights for redistribution and usage in source and binary forms are
-// granted according to the OpenSSL license. Warranty of any kind is
-// disclaimed.
-// ====================================================================
-
-.ident  "rc4-ia64.S, Version 2.0"
-.ident  "IA-64 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>"
-
-// What's wrong with compiler generated code? Because of the nature of
-// C language, compiler doesn't [dare to] reorder load and stores. But
-// being memory-bound, RC4 should benefit from reorder [on in-order-
-// execution core such as IA-64]. But what can we reorder? At the very
-// least we can safely reorder references to key schedule in respect
-// to input and output streams. Secondly, from the first [close] glance
-// it appeared that it's possible to pull up some references to
-// elements of the key schedule itself. Original rationale ["prior
-// loads are not safe only for "degenerated" key schedule, when some
-// elements equal to the same value"] was kind of sloppy. I should have
-// formulated as it really was: if we assume that pulling up reference
-// to key[x+1] is not safe, then it would mean that key schedule would
-// "degenerate," which is never the case. The problem is that this
-// holds true in respect to references to key[x], but not to key[y].
-// Legitimate "collisions" do occur within every 256^2 bytes window.
-// Fortunately there're enough free instruction slots to keep prior
-// reference to key[x+1], detect "collision" and compensate for it.
-// All this without sacrificing a single clock cycle:-) Throughput is
-// ~210MBps on 900MHz CPU, which is is >3x faster than gcc generated
-// code and +30% - if compared to HP-UX C. Unrolling loop below should
-// give >30% on top of that...
-
-.text
-.explicit
-
-#if defined(_HPUX_SOURCE) && !defined(_LP64)
-# define ADDP  addp4
-#else
-# define ADDP  add
-#endif
-
-#ifndef SZ
-#define SZ     4       // this is set to sizeof(RC4_INT)
-#endif
-// SZ==4 seems to be optimal. At least SZ==8 is not any faster, not for
-// assembler implementation, while SZ==1 code is ~30% slower.
-#if SZ==1      // RC4_INT is unsigned char
-# define       LDKEY   ld1
-# define       STKEY   st1
-# define       OFF     0
-#elif SZ==4    // RC4_INT is unsigned int
-# define       LDKEY   ld4
-# define       STKEY   st4
-# define       OFF     2
-#elif SZ==8    // RC4_INT is unsigned long
-# define       LDKEY   ld8
-# define       STKEY   st8
-# define       OFF     3
-#endif
-
-out=r8;                // [expanded] output pointer
-inp=r9;                // [expanded] output pointer
-prsave=r10;
-key=r28;       // [expanded] pointer to RC4_KEY
-ksch=r29;      // (key->data+255)[&~(sizeof(key->data)-1)]
-xx=r30;
-yy=r31;
-
-// void RC4(RC4_KEY *key,size_t len,const void *inp,void *out);
-.global        RC4#
-.proc  RC4#
-.align 32
-.skip  16
-RC4:
-       .prologue
-       .save   ar.pfs,r2
-{ .mii;        alloc   r2=ar.pfs,4,12,0,16
-       .save   pr,prsave
-       mov     prsave=pr
-       ADDP    key=0,in0               };;
-{ .mib;        cmp.eq  p6,p0=0,in1                     // len==0?
-       .save   ar.lc,r3
-       mov     r3=ar.lc
-(p6)   br.ret.spnt.many        b0      };;     // emergency exit
-
-       .body
-       .rotr   dat[4],key_x[4],tx[2],rnd[2],key_y[2],ty[1];
-
-{ .mib;        LDKEY   xx=[key],SZ                     // load key->x
-       add     in1=-1,in1                      // adjust len for loop counter
-       nop.b   0                       }
-{ .mib;        ADDP    inp=0,in2
-       ADDP    out=0,in3
-       brp.loop.imp    .Ltop,.Lexit-16 };;
-{ .mmi;        LDKEY   yy=[key]                        // load key->y
-       add     ksch=SZ,key
-       mov     ar.lc=in1               }
-{ .mmi;        mov     key_y[1]=r0                     // guarantee inequality
-                                               // in first iteration
-       add     xx=1,xx
-       mov     pr.rot=1<<16            };;
-{ .mii;        nop.m   0
-       dep     key_x[1]=xx,r0,OFF,8
-       mov     ar.ec=3                 };;     // note that epilogue counter
-                                               // is off by 1. I compensate
-                                               // for this at exit...
-.Ltop:
-// The loop is scheduled for 4*(n+2) spin-rate on Itanium 2, which
-// theoretically gives asymptotic performance of clock frequency
-// divided by 4 bytes per seconds, or 400MBps on 1.6GHz CPU. This is
-// for sizeof(RC4_INT)==4. For smaller RC4_INT STKEY inadvertently
-// splits the last bundle and you end up with 5*n spin-rate:-(
-// Originally the loop was scheduled for 3*n and relied on key
-// schedule to be aligned at 256*sizeof(RC4_INT) boundary. But
-// *(out++)=dat, which maps to st1, had same effect [inadvertent
-// bundle split] and holded the loop back. Rescheduling for 4*n
-// made it possible to eliminate dependence on specific alignment
-// and allow OpenSSH keep "abusing" our API. Reaching for 3*n would
-// require unrolling, sticking to variable shift instruction for
-// collecting output [to avoid starvation for integer shifter] and
-// copying of key schedule to controlled place in stack [so that
-// deposit instruction can serve as substitute for whole
-// key->data+((x&255)<<log2(sizeof(key->data[0])))]...
-{ .mmi;        (p19)   st1     [out]=dat[3],1                  // *(out++)=dat
-       (p16)   add     xx=1,xx                         // x++
-       (p18)   dep     rnd[1]=rnd[1],r0,OFF,8  }       // ((tx+ty)&255)<<OFF
-{ .mmi;        (p16)   add     key_x[1]=ksch,key_x[1]          // &key[xx&255]
-       (p17)   add     key_y[1]=ksch,key_y[1]  };;     // &key[yy&255] 
-{ .mmi;        (p16)   LDKEY   tx[0]=[key_x[1]]                // tx=key[xx]
-       (p17)   LDKEY   ty[0]=[key_y[1]]                // ty=key[yy]   
-       (p16)   dep     key_x[0]=xx,r0,OFF,8    }       // (xx&255)<<OFF
-{ .mmi;        (p18)   add     rnd[1]=ksch,rnd[1]              // &key[(tx+ty)&255]
-       (p16)   cmp.ne.unc p20,p21=key_x[1],key_y[1] };;
-{ .mmi;        (p18)   LDKEY   rnd[1]=[rnd[1]]                 // rnd=key[(tx+ty)&255]
-       (p16)   ld1     dat[0]=[inp],1          }       // dat=*(inp++)
-.pred.rel      "mutex",p20,p21
-{ .mmi;        (p21)   add     yy=yy,tx[1]                     // (p16)
-       (p20)   add     yy=yy,tx[0]                     // (p16) y+=tx
-       (p21)   mov     tx[0]=tx[1]             };;     // (p16)
-{ .mmi;        (p17)   STKEY   [key_y[1]]=tx[1]                // key[yy]=tx
-       (p17)   STKEY   [key_x[2]]=ty[0]                // key[xx]=ty
-       (p16)   dep     key_y[0]=yy,r0,OFF,8    }       // &key[yy&255]
-{ .mmb;        (p17)   add     rnd[0]=tx[1],ty[0]              // tx+=ty
-       (p18)   xor     dat[2]=dat[2],rnd[1]            // dat^=rnd
-       br.ctop.sptk    .Ltop                   };;
-.Lexit:
-{ .mib;        STKEY   [key]=yy,-SZ                    // save key->y
-       mov     pr=prsave,0x1ffff
-       nop.b   0                       }
-{ .mib;        st1     [out]=dat[3],1                  // compensate for truncated
-                                               // epilogue counter
-       add     xx=-1,xx
-       nop.b   0                       };;
-{ .mib;        STKEY   [key]=xx                        // save key->x
-       mov     ar.lc=r3
-       br.ret.sptk.many        b0      };;
-.endp  RC4#
diff --git a/deps/openssl/openssl/crypto/rc4/asm/rc4-ia64.pl b/deps/openssl/openssl/crypto/rc4/asm/rc4-ia64.pl
new file mode 100644 (file)
index 0000000..49cd5b5
--- /dev/null
@@ -0,0 +1,755 @@
+#!/usr/bin/env perl
+#
+# ====================================================================
+# Written by David Mosberger <David.Mosberger@acm.org> based on the
+# Itanium optimized Crypto code which was released by HP Labs at
+# http://www.hpl.hp.com/research/linux/crypto/.
+#
+# Copyright (c) 2005 Hewlett-Packard Development Company, L.P.
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
+
+
+
+# This is a little helper program which generates a software-pipelined
+# for RC4 encryption.  The basic algorithm looks like this:
+#
+#   for (counter = 0; counter < len; ++counter)
+#     {
+#       in = inp[counter];
+#       SI = S[I];
+#       J = (SI + J) & 0xff;
+#       SJ = S[J];
+#       T = (SI + SJ) & 0xff;
+#       S[I] = SJ, S[J] = SI;
+#       ST = S[T];
+#       outp[counter] = in ^ ST;
+#       I = (I + 1) & 0xff;
+#     }
+#
+# Pipelining this loop isn't easy, because the stores to the S[] array
+# need to be observed in the right order.  The loop generated by the
+# code below has the following pipeline diagram:
+#
+#      cycle
+#     | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |10 |11 |12 |13 |14 |15 |16 |17 |
+# iter
+#   1: xxx LDI xxx xxx xxx LDJ xxx SWP xxx LDT xxx xxx
+#   2:             xxx LDI xxx xxx xxx LDJ xxx SWP xxx LDT xxx xxx
+#   3:                         xxx LDI xxx xxx xxx LDJ xxx SWP xxx LDT xxx xxx
+#
+#   where:
+#      LDI = load of S[I]
+#      LDJ = load of S[J]
+#      SWP = swap of S[I] and S[J]
+#      LDT = load of S[T]
+#
+# Note that in the above diagram, the major trouble-spot is that LDI
+# of the 2nd iteration is performed BEFORE the SWP of the first
+# iteration.  Fortunately, this is easy to detect (I of the 1st
+# iteration will be equal to J of the 2nd iteration) and when this
+# happens, we simply forward the proper value from the 1st iteration
+# to the 2nd one.  The proper value in this case is simply the value
+# of S[I] from the first iteration (thanks to the fact that SWP
+# simply swaps the contents of S[I] and S[J]).
+#
+# Another potential trouble-spot is in cycle 7, where SWP of the 1st
+# iteration issues at the same time as the LDI of the 3rd iteration.
+# However, thanks to IA-64 execution semantics, this can be taken
+# care of simply by placing LDI later in the instruction-group than
+# SWP.  IA-64 CPUs will automatically forward the value if they
+# detect that the SWP and LDI are accessing the same memory-location.
+
+# The core-loop that can be pipelined then looks like this (annotated
+# with McKinley/Madison issue port & latency numbers, assuming L1
+# cache hits for the most part):
+
+# operation:       instruction:                    issue-ports:  latency
+# ------------------  -----------------------------   ------------- -------
+
+# Data = *inp++       ld1 data = [inp], 1             M0-M1         1 cyc     c0
+#                     shladd Iptr = I, KeyTable, 3    M0-M3, I0, I1 1 cyc
+# I = (I + 1) & 0xff  padd1 nextI = I, one            M0-M3, I0, I1 3 cyc
+#                     ;;
+# SI = S[I]           ld8 SI = [Iptr]                 M0-M1         1 cyc     c1 * after SWAP!
+#                     ;;
+#                     cmp.eq.unc pBypass = I, J                                  * after J is valid!
+# J = SI + J          add J = J, SI                   M0-M3, I0, I1 1 cyc     c2
+#                     (pBypass) br.cond.spnt Bypass
+#                     ;;
+# ---------------------------------------------------------------------------------------
+# J = J & 0xff        zxt1 J = J                      I0, I1, 1 cyc           c3
+#                     ;;
+#                     shladd Jptr = J, KeyTable, 3    M0-M3, I0, I1 1 cyc     c4
+#                     ;;
+# SJ = S[J]           ld8 SJ = [Jptr]                 M0-M1         1 cyc     c5
+#                     ;;
+# ---------------------------------------------------------------------------------------
+# T = (SI + SJ)       add T = SI, SJ                  M0-M3, I0, I1 1 cyc     c6
+#                     ;;
+# T = T & 0xff        zxt1 T = T                      I0, I1        1 cyc
+# S[I] = SJ           st8 [Iptr] = SJ                 M2-M3                   c7
+# S[J] = SI           st8 [Jptr] = SI                 M2-M3
+#                     ;;
+#                     shladd Tptr = T, KeyTable, 3    M0-M3, I0, I1 1 cyc     c8
+#                     ;;
+# ---------------------------------------------------------------------------------------
+# T = S[T]            ld8 T = [Tptr]                  M0-M1         1 cyc     c9
+#                     ;;
+# data ^= T           xor data = data, T              M0-M3, I0, I1 1 cyc     c10
+#                     ;;
+# *out++ = Data ^ T   dep word = word, data, 8, POS   I0, I1        1 cyc     c11
+#                     ;;
+# ---------------------------------------------------------------------------------------
+
+# There are several points worth making here:
+
+#   - Note that due to the bypass/forwarding-path, the first two
+#     phases of the loop are strangly mingled together.  In
+#     particular, note that the first stage of the pipeline is
+#     using the value of "J", as calculated by the second stage.
+#   - Each bundle-pair will have exactly 6 instructions.
+#   - Pipelined, the loop can execute in 3 cycles/iteration and
+#     4 stages.  However, McKinley/Madison can issue "st1" to
+#     the same bank at a rate of at most one per 4 cycles.  Thus,
+#     instead of storing each byte, we accumulate them in a word
+#     and then write them back at once with a single "st8" (this
+#     implies that the setup code needs to ensure that the output
+#     buffer is properly aligned, if need be, by encoding the
+#     first few bytes separately).
+#   - There is no space for a "br.ctop" instruction.  For this
+#     reason we can't use module-loop support in IA-64 and have
+#     to do a traditional, purely software-pipelined loop.
+#   - We can't replace any of the remaining "add/zxt1" pairs with
+#     "padd1" because the latency for that instruction is too high
+#     and would push the loop to the point where more bypasses
+#     would be needed, which we don't have space for.
+#   - The above loop runs at around 3.26 cycles/byte, or roughly
+#     440 MByte/sec on a 1.5GHz Madison.  This is well below the
+#     system bus bandwidth and hence with judicious use of
+#     "lfetch" this loop can run at (almost) peak speed even when
+#     the input and output data reside in memory.  The
+#     max. latency that can be tolerated is (PREFETCH_DISTANCE *
+#     L2_LINE_SIZE * 3 cyc), or about 384 cycles assuming (at
+#     least) 1-ahead prefetching of 128 byte cache-lines.  Note
+#     that we do NOT prefetch into L1, since that would only
+#     interfere with the S[] table values stored there.  This is
+#     acceptable because there is a 10 cycle latency between
+#     load and first use of the input data.
+#   - We use a branch to out-of-line bypass-code of cycle-pressure:
+#     we calculate the next J, check for the need to activate the
+#     bypass path, and activate the bypass path ALL IN THE SAME
+#     CYCLE.  If we didn't have these constraints, we could do
+#     the bypass with a simple conditional move instruction.
+#     Fortunately, the bypass paths get activated relatively
+#     infrequently, so the extra branches don't cost all that much
+#     (about 0.04 cycles/byte, measured on a 16396 byte file with
+#     random input data).
+#
+
+$phases = 4;           # number of stages/phases in the pipelined-loop
+$unroll_count = 6;     # number of times we unrolled it
+$pComI = (1 << 0);
+$pComJ = (1 << 1);
+$pComT = (1 << 2);
+$pOut  = (1 << 3);
+
+$NData = 4;
+$NIP = 3;
+$NJP = 2;
+$NI = 2;
+$NSI = 3;
+$NSJ = 2;
+$NT = 2;
+$NOutWord = 2;
+
+#
+# $threshold is the minimum length before we attempt to use the
+# big software-pipelined loop.  It MUST be greater-or-equal
+# to:
+#              PHASES * (UNROLL_COUNT + 1) + 7
+#
+# The "+ 7" comes from the fact we may have to encode up to
+#   7 bytes separately before the output pointer is aligned.
+#
+$threshold = (3 * ($phases * ($unroll_count + 1)) + 7);
+
+sub I {
+    local *code = shift;
+    local $format = shift;
+    $code .= sprintf ("\t\t".$format."\n", @_);
+}
+
+sub P {
+    local *code = shift;
+    local $format = shift;
+    $code .= sprintf ($format."\n", @_);
+}
+
+sub STOP {
+    local *code = shift;
+    $code .=<<___;
+               ;;
+___
+}
+
+sub emit_body {
+    local *c = shift;
+    local *bypass = shift;
+    local ($iteration, $p) = @_;
+
+    local $i0 = $iteration;
+    local $i1 = $iteration - 1;
+    local $i2 = $iteration - 2;
+    local $i3 = $iteration - 3;
+    local $iw0 = ($iteration - 3) / 8;
+    local $iw1 = ($iteration > 3) ? ($iteration - 4) / 8 : 1;
+    local $byte_num = ($iteration - 3) % 8;
+    local $label = $iteration + 1;
+    local $pAny = ($p & 0xf) == 0xf;
+    local $pByp = (($p & $pComI) && ($iteration > 0));
+
+    $c.=<<___;
+//////////////////////////////////////////////////
+___
+
+    if (($p & 0xf) == 0) {
+       $c.="#ifdef HOST_IS_BIG_ENDIAN\n";
+       &I(\$c,"shr.u   OutWord[%u] = OutWord[%u], 32;;",
+                               $iw1 % $NOutWord, $iw1 % $NOutWord);
+       $c.="#endif\n";
+       &I(\$c, "st4 [OutPtr] = OutWord[%u], 4", $iw1 % $NOutWord);
+       return;
+    }
+
+    # Cycle 0
+    &I(\$c, "{ .mmi")                                        if ($pAny);
+    &I(\$c, "ld1    Data[%u] = [InPtr], 1", $i0 % $NData)     if ($p & $pComI);
+    &I(\$c, "padd1  I[%u] = One, I[%u]", $i0 % $NI, $i1 % $NI)if ($p & $pComI);
+    &I(\$c, "zxt1   J = J")                                  if ($p & $pComJ);
+    &I(\$c, "}")                                             if ($pAny);
+    &I(\$c, "{ .mmi")                                        if ($pAny);
+    &I(\$c, "LKEY   T[%u] = [T[%u]]", $i1 % $NT, $i1 % $NT)   if ($p & $pOut);
+    &I(\$c, "add    T[%u] = SI[%u], SJ[%u]",
+       $i0 % $NT, $i2 % $NSI, $i1 % $NSJ)                    if ($p & $pComT);
+    &I(\$c, "KEYADDR(IPr[%u], I[%u])", $i0 % $NIP, $i1 % $NI) if ($p & $pComI);
+    &I(\$c, "}")                                             if ($pAny);
+    &STOP(\$c);
+
+    # Cycle 1
+    &I(\$c, "{ .mmi")                                        if ($pAny);
+    &I(\$c, "SKEY   [IPr[%u]] = SJ[%u]", $i2 % $NIP, $i1%$NSJ)if ($p & $pComT);
+    &I(\$c, "SKEY   [JP[%u]] = SI[%u]", $i1 % $NJP, $i2%$NSI) if ($p & $pComT);
+    &I(\$c, "zxt1   T[%u] = T[%u]", $i0 % $NT, $i0 % $NT)     if ($p & $pComT);
+    &I(\$c, "}")                                             if ($pAny);
+    &I(\$c, "{ .mmi")                                        if ($pAny);
+    &I(\$c, "LKEY   SI[%u] = [IPr[%u]]", $i0 % $NSI, $i0%$NIP)if ($p & $pComI);
+    &I(\$c, "KEYADDR(JP[%u], J)", $i0 % $NJP)                if ($p & $pComJ);
+    &I(\$c, "xor    Data[%u] = Data[%u], T[%u]",
+       $i3 % $NData, $i3 % $NData, $i1 % $NT)                if ($p & $pOut);
+    &I(\$c, "}")                                             if ($pAny);
+    &STOP(\$c);
+
+    # Cycle 2
+    &I(\$c, "{ .mmi")                                        if ($pAny);
+    &I(\$c, "LKEY   SJ[%u] = [JP[%u]]", $i0 % $NSJ, $i0%$NJP) if ($p & $pComJ);
+    &I(\$c, "cmp.eq pBypass, p0 = I[%u], J", $i1 % $NI)              if ($pByp);
+    &I(\$c, "dep OutWord[%u] = Data[%u], OutWord[%u], BYTE_POS(%u), 8",
+       $iw0%$NOutWord, $i3%$NData, $iw1%$NOutWord, $byte_num) if ($p & $pOut);
+    &I(\$c, "}")                                             if ($pAny);
+    &I(\$c, "{ .mmb")                                        if ($pAny);
+    &I(\$c, "add    J = J, SI[%u]", $i0 % $NSI)                      if ($p & $pComI);
+    &I(\$c, "KEYADDR(T[%u], T[%u])", $i0 % $NT, $i0 % $NT)    if ($p & $pComT);
+    &P(\$c, "(pBypass)\tbr.cond.spnt.many .rc4Bypass%u",$label)if ($pByp);
+    &I(\$c, "}") if ($pAny);
+    &STOP(\$c);
+
+    &P(\$c, ".rc4Resume%u:", $label)                         if ($pByp);
+    if ($byte_num == 0 && $iteration >= $phases) {
+       &I(\$c, "st8 [OutPtr] = OutWord[%u], 8",
+          $iw1 % $NOutWord)                                  if ($p & $pOut);
+       if ($iteration == (1 + $unroll_count) * $phases - 1) {
+           if ($unroll_count == 6) {
+               &I(\$c, "mov OutWord[%u] = OutWord[%u]",
+                  $iw1 % $NOutWord, $iw0 % $NOutWord);
+           }
+           &I(\$c, "lfetch.nt1 [InPrefetch], %u",
+              $unroll_count * $phases);
+           &I(\$c, "lfetch.excl.nt1 [OutPrefetch], %u",
+              $unroll_count * $phases);
+           &I(\$c, "br.cloop.sptk.few .rc4Loop");
+       }
+    }
+
+    if ($pByp) {
+       &P(\$bypass, ".rc4Bypass%u:", $label);
+       &I(\$bypass, "sub J = J, SI[%u]", $i0 % $NSI);
+       &I(\$bypass, "nop 0");
+       &I(\$bypass, "nop 0");
+       &I(\$bypass, ";;");
+       &I(\$bypass, "add J = J, SI[%u]", $i1 % $NSI);
+       &I(\$bypass, "mov SI[%u] = SI[%u]", $i0 % $NSI, $i1 % $NSI);
+       &I(\$bypass, "br.sptk.many .rc4Resume%u\n", $label);
+       &I(\$bypass, ";;");
+    }
+}
+
+$code=<<___;
+.ident \"rc4-ia64.s, version 3.0\"
+.ident \"Copyright (c) 2005 Hewlett-Packard Development Company, L.P.\"
+
+#define LCSave         r8
+#define PRSave         r9
+
+/* Inputs become invalid once rotation begins!  */
+
+#define StateTable     in0
+#define DataLen                in1
+#define InputBuffer    in2
+#define OutputBuffer   in3
+
+#define KTable         r14
+#define J              r15
+#define InPtr          r16
+#define OutPtr         r17
+#define InPrefetch     r18
+#define OutPrefetch    r19
+#define One            r20
+#define LoopCount      r21
+#define Remainder      r22
+#define IFinal         r23
+#define EndPtr         r24
+
+#define tmp0           r25
+#define tmp1           r26
+
+#define pBypass                p6
+#define pDone          p7
+#define pSmall         p8
+#define pAligned       p9
+#define pUnaligned     p10
+
+#define pComputeI      pPhase[0]
+#define pComputeJ      pPhase[1]
+#define pComputeT      pPhase[2]
+#define pOutput                pPhase[3]
+
+#define RetVal         r8
+#define L_OK           p7
+#define L_NOK          p8
+
+#define        _NINPUTS        4
+#define        _NOUTPUT        0
+
+#define        _NROTATE        24
+#define        _NLOCALS        (_NROTATE - _NINPUTS - _NOUTPUT)
+
+#ifndef SZ
+# define SZ    4       // this must be set to sizeof(RC4_INT)
+#endif
+
+#if SZ == 1
+# define LKEY                  ld1
+# define SKEY                  st1
+# define KEYADDR(dst, i)       add dst = i, KTable
+#elif SZ == 2
+# define LKEY                  ld2
+# define SKEY                  st2
+# define KEYADDR(dst, i)       shladd dst = i, 1, KTable
+#elif SZ == 4
+# define LKEY                  ld4
+# define SKEY                  st4
+# define KEYADDR(dst, i)       shladd dst = i, 2, KTable
+#else
+# define LKEY                  ld8
+# define SKEY                  st8
+# define KEYADDR(dst, i)       shladd dst = i, 3, KTable
+#endif
+
+#if defined(_HPUX_SOURCE) && !defined(_LP64)
+# define ADDP  addp4
+#else
+# define ADDP  add
+#endif
+
+/* Define a macro for the bit number of the n-th byte: */
+
+#if defined(_HPUX_SOURCE) || defined(B_ENDIAN)
+# define HOST_IS_BIG_ENDIAN
+# define BYTE_POS(n)   (56 - (8 * (n)))
+#else
+# define BYTE_POS(n)   (8 * (n))
+#endif
+
+/*
+   We must perform the first phase of the pipeline explicitly since
+   we will always load from the stable the first time. The br.cexit
+   will never be taken since regardless of the number of bytes because
+   the epilogue count is 4.
+*/
+/* MODSCHED_RC4 macro was split to _PROLOGUE and _LOOP, because HP-UX
+   assembler failed on original macro with syntax error. <appro> */
+#define MODSCHED_RC4_PROLOGUE                                             \\
+       {                                                                  \\
+                               ld1             Data[0] = [InPtr], 1;      \\
+                               add             IFinal = 1, I[1];          \\
+                               KEYADDR(IPr[0], I[1]);                     \\
+       } ;;                                                               \\
+       {                                                                  \\
+                               LKEY            SI[0] = [IPr[0]];          \\
+                               mov             pr.rot = 0x10000;          \\
+                               mov             ar.ec = 4;                 \\
+       } ;;                                                               \\
+       {                                                                  \\
+                               add             J = J, SI[0];              \\
+                               zxt1            I[0] = IFinal;             \\
+                               br.cexit.spnt.few .+16; /* never taken */  \\
+       } ;;
+#define MODSCHED_RC4_LOOP(label)                                          \\
+label:                                                                    \\
+       {       .mmi;                                                      \\
+               (pComputeI)     ld1             Data[0] = [InPtr], 1;      \\
+               (pComputeI)     add             IFinal = 1, I[1];          \\
+               (pComputeJ)     zxt1            J = J;                     \\
+       }{      .mmi;                                                      \\
+               (pOutput)       LKEY            T[1] = [T[1]];             \\
+               (pComputeT)     add             T[0] = SI[2], SJ[1];       \\
+               (pComputeI)     KEYADDR(IPr[0], I[1]);                     \\
+       } ;;                                                               \\
+       {       .mmi;                                                      \\
+               (pComputeT)     SKEY            [IPr[2]] = SJ[1];          \\
+               (pComputeT)     SKEY            [JP[1]] = SI[2];           \\
+               (pComputeT)     zxt1            T[0] = T[0];               \\
+       }{      .mmi;                                                      \\
+               (pComputeI)     LKEY            SI[0] = [IPr[0]];          \\
+               (pComputeJ)     KEYADDR(JP[0], J);                         \\
+               (pComputeI)     cmp.eq.unc      pBypass, p0 = I[1], J;     \\
+       } ;;                                                               \\
+       {       .mmi;                                                      \\
+               (pComputeJ)     LKEY            SJ[0] = [JP[0]];           \\
+               (pOutput)       xor             Data[3] = Data[3], T[1];   \\
+                               nop             0x0;                       \\
+       }{      .mmi;                                                      \\
+               (pComputeT)     KEYADDR(T[0], T[0]);                       \\
+               (pBypass)       mov             SI[0] = SI[1];             \\
+               (pComputeI)     zxt1            I[0] = IFinal;             \\
+       } ;;                                                               \\
+       {       .mmb;                                                      \\
+               (pOutput)       st1             [OutPtr] = Data[3], 1;     \\
+               (pComputeI)     add             J = J, SI[0];              \\
+                               br.ctop.sptk.few label;                    \\
+       } ;;
+
+       .text
+
+       .align  32
+
+       .type   RC4, \@function
+       .global RC4
+
+       .proc   RC4
+       .prologue
+
+RC4:
+       {
+               .mmi
+               alloc   r2 = ar.pfs, _NINPUTS, _NLOCALS, _NOUTPUT, _NROTATE
+
+               .rotr Data[4], I[2], IPr[3], SI[3], JP[2], SJ[2], T[2], \\
+                     OutWord[2]
+               .rotp pPhase[4]
+
+               ADDP            InPrefetch = 0, InputBuffer
+               ADDP            KTable = 0, StateTable
+       }
+       {
+               .mmi
+               ADDP            InPtr = 0, InputBuffer
+               ADDP            OutPtr = 0, OutputBuffer
+               mov             RetVal = r0
+       }
+       ;;
+       {
+               .mmi
+               lfetch.nt1      [InPrefetch], 0x80
+               ADDP            OutPrefetch = 0, OutputBuffer
+       }
+       {               // Return 0 if the input length is nonsensical
+               .mib
+               ADDP            StateTable = 0, StateTable
+               cmp.ge.unc      L_NOK, L_OK = r0, DataLen
+       (L_NOK) br.ret.sptk.few rp
+       }
+       ;;
+       {
+               .mib
+               cmp.eq.or       L_NOK, L_OK = r0, InPtr
+               cmp.eq.or       L_NOK, L_OK = r0, OutPtr
+               nop             0x0
+       }
+       {
+               .mib
+               cmp.eq.or       L_NOK, L_OK = r0, StateTable
+               nop             0x0
+       (L_NOK) br.ret.sptk.few rp
+       }
+       ;;
+               LKEY            I[1] = [KTable], SZ
+/* Prefetch the state-table. It contains 256 elements of size SZ */
+
+#if SZ == 1
+               ADDP            tmp0 = 1*128, StateTable
+#elif SZ == 2
+               ADDP            tmp0 = 3*128, StateTable
+               ADDP            tmp1 = 2*128, StateTable
+#elif SZ == 4
+               ADDP            tmp0 = 7*128, StateTable
+               ADDP            tmp1 = 6*128, StateTable
+#elif SZ == 8
+               ADDP            tmp0 = 15*128, StateTable
+               ADDP            tmp1 = 14*128, StateTable
+#endif
+               ;;
+#if SZ >= 8
+               lfetch.fault.nt1                [tmp0], -256    // 15
+               lfetch.fault.nt1                [tmp1], -256;;
+               lfetch.fault.nt1                [tmp0], -256    // 13
+               lfetch.fault.nt1                [tmp1], -256;;
+               lfetch.fault.nt1                [tmp0], -256    // 11
+               lfetch.fault.nt1                [tmp1], -256;;
+               lfetch.fault.nt1                [tmp0], -256    //  9
+               lfetch.fault.nt1                [tmp1], -256;;
+#endif
+#if SZ >= 4
+               lfetch.fault.nt1                [tmp0], -256    //  7
+               lfetch.fault.nt1                [tmp1], -256;;
+               lfetch.fault.nt1                [tmp0], -256    //  5
+               lfetch.fault.nt1                [tmp1], -256;;
+#endif
+#if SZ >= 2
+               lfetch.fault.nt1                [tmp0], -256    //  3
+               lfetch.fault.nt1                [tmp1], -256;;
+#endif
+       {
+               .mii
+               lfetch.fault.nt1                [tmp0]          //  1
+               add             I[1]=1,I[1];;
+               zxt1            I[1]=I[1]
+       }
+       {
+               .mmi
+               lfetch.nt1      [InPrefetch], 0x80
+               lfetch.excl.nt1 [OutPrefetch], 0x80
+               .save           pr, PRSave
+               mov             PRSave = pr
+       } ;;
+       {
+               .mmi
+               lfetch.excl.nt1 [OutPrefetch], 0x80
+               LKEY            J = [KTable], SZ
+               ADDP            EndPtr = DataLen, InPtr
+       }  ;;
+       {
+               .mmi
+               ADDP            EndPtr = -1, EndPtr     // Make it point to
+                                                       // last data byte.
+               mov             One = 1
+               .save           ar.lc, LCSave
+               mov             LCSave = ar.lc
+               .body
+       } ;;
+       {
+               .mmb
+               sub             Remainder = 0, OutPtr
+               cmp.gtu         pSmall, p0 = $threshold, DataLen
+(pSmall)       br.cond.dpnt    .rc4Remainder           // Data too small for
+                                                       // big loop.
+       } ;;
+       {
+               .mmi
+               and             Remainder = 0x7, Remainder
+               ;;
+               cmp.eq          pAligned, pUnaligned = Remainder, r0
+               nop             0x0
+       } ;;
+       {
+               .mmb
+.pred.rel      "mutex",pUnaligned,pAligned
+(pUnaligned)   add             Remainder = -1, Remainder
+(pAligned)     sub             Remainder = EndPtr, InPtr
+(pAligned)     br.cond.dptk.many .rc4Aligned
+       } ;;
+       {
+               .mmi
+               nop             0x0
+               nop             0x0
+               mov.i           ar.lc = Remainder
+       }
+
+/* Do the initial few bytes via the compact, modulo-scheduled loop
+   until the output pointer is 8-byte-aligned.  */
+
+               MODSCHED_RC4_PROLOGUE
+               MODSCHED_RC4_LOOP(.RC4AlignLoop)
+
+       {
+               .mib
+               sub             Remainder = EndPtr, InPtr
+               zxt1            IFinal = IFinal
+               clrrrb                          // Clear CFM.rrb.pr so
+               ;;                              // next "mov pr.rot = N"
+                                               // does the right thing.
+       }
+       {
+               .mmi
+               mov             I[1] = IFinal
+               nop             0x0
+               nop             0x0
+       } ;;
+
+
+.rc4Aligned:
+
+/*
+   Unrolled loop count = (Remainder - ($unroll_count+1)*$phases)/($unroll_count*$phases)
+ */
+
+       {
+               .mlx
+               add     LoopCount = 1 - ($unroll_count + 1)*$phases, Remainder
+               movl            Remainder = 0xaaaaaaaaaaaaaaab
+       } ;;
+       {
+               .mmi
+               setf.sig        f6 = LoopCount          // M2, M3       6 cyc
+               setf.sig        f7 = Remainder          // M2, M3       6 cyc
+               nop             0x0
+       } ;;
+       {
+               .mfb
+               nop             0x0
+               xmpy.hu         f6 = f6, f7
+               nop             0x0
+       } ;;
+       {
+               .mmi
+               getf.sig        LoopCount = f6;;        // M2           5 cyc
+               nop             0x0
+               shr.u           LoopCount = LoopCount, 4
+       } ;;
+       {
+               .mmi
+               nop             0x0
+               nop             0x0
+               mov.i           ar.lc = LoopCount
+       } ;;
+
+/* Now comes the unrolled loop: */
+
+.rc4Prologue:
+___
+
+$iteration = 0;
+
+# Generate the prologue:
+$predicates = 1;
+for ($i = 0; $i < $phases; ++$i) {
+    &emit_body (\$code, \$bypass, $iteration++, $predicates);
+    $predicates = ($predicates << 1) | 1;
+}
+
+$code.=<<___;
+.rc4Loop:
+___
+
+# Generate the body:
+for ($i = 0; $i < $unroll_count*$phases; ++$i) {
+    &emit_body (\$code, \$bypass, $iteration++, $predicates);
+}
+
+$code.=<<___;
+.rc4Epilogue:
+___
+
+# Generate the epilogue:
+for ($i = 0; $i < $phases; ++$i) {
+    $predicates <<= 1;
+    &emit_body (\$code, \$bypass, $iteration++, $predicates);
+}
+
+$code.=<<___;
+       {
+               .mmi
+               lfetch.nt1      [EndPtr]        // fetch line with last byte
+               mov             IFinal = I[1]
+               nop             0x0
+       }
+
+.rc4Remainder:
+       {
+               .mmi
+               sub             Remainder = EndPtr, InPtr       // Calculate
+                                                               // # of bytes
+                                                               // left - 1
+               nop             0x0
+               nop             0x0
+       } ;;
+       {
+               .mib
+               cmp.eq          pDone, p0 = -1, Remainder // done already?
+               mov.i           ar.lc = Remainder
+(pDone)                br.cond.dptk.few .rc4Complete
+       }
+
+/* Do the remaining bytes via the compact, modulo-scheduled loop */
+
+               MODSCHED_RC4_PROLOGUE
+               MODSCHED_RC4_LOOP(.RC4RestLoop)
+
+.rc4Complete:
+       {
+               .mmi
+               add             KTable = -SZ, KTable
+               add             IFinal = -1, IFinal
+               mov             ar.lc = LCSave
+       } ;;
+       {
+               .mii
+               SKEY            [KTable] = J,-SZ
+               zxt1            IFinal = IFinal
+               mov             pr = PRSave, 0x1FFFF
+       } ;;
+       {
+               .mib
+               SKEY            [KTable] = IFinal
+               add             RetVal = 1, r0
+               br.ret.sptk.few rp
+       } ;;
+___
+
+# Last but not least, emit the code for the bypass-code of the unrolled loop:
+
+$code.=$bypass;
+
+$code.=<<___;
+       .endp RC4
+___
+
+print $code;
diff --git a/deps/openssl/openssl/crypto/rc4/asm/rc4-s390x.pl b/deps/openssl/openssl/crypto/rc4/asm/rc4-s390x.pl
new file mode 100644 (file)
index 0000000..96681fa
--- /dev/null
@@ -0,0 +1,205 @@
+#!/usr/bin/env perl
+#
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+#
+# February 2009
+#
+# Performance is 2x of gcc 3.4.6 on z10. Coding "secret" is to
+# "cluster" Address Generation Interlocks, so that one pipeline stall
+# resolves several dependencies.
+
+$rp="%r14";
+$sp="%r15";
+$code=<<___;
+.text
+
+___
+
+# void RC4(RC4_KEY *key,size_t len,const void *inp,void *out)
+{
+$acc="%r0";
+$cnt="%r1";
+$key="%r2";
+$len="%r3";
+$inp="%r4";
+$out="%r5";
+
+@XX=("%r6","%r7");
+@TX=("%r8","%r9");
+$YY="%r10";
+$TY="%r11";
+
+$code.=<<___;
+.globl RC4
+.type  RC4,\@function
+.align 64
+RC4:
+       stmg    %r6,%r11,48($sp)
+       llgc    $XX[0],0($key)
+       llgc    $YY,1($key)
+       la      $XX[0],1($XX[0])
+       nill    $XX[0],0xff
+       srlg    $cnt,$len,3
+       ltgr    $cnt,$cnt
+       llgc    $TX[0],2($XX[0],$key)
+       jz      .Lshort
+       j       .Loop8
+
+.align 64
+.Loop8:
+___
+for ($i=0;$i<8;$i++) {
+$code.=<<___;
+       la      $YY,0($YY,$TX[0])       # $i
+       nill    $YY,255
+       la      $XX[1],1($XX[0])
+       nill    $XX[1],255
+___
+$code.=<<___ if ($i==1);
+       llgc    $acc,2($TY,$key)
+___
+$code.=<<___ if ($i>1);
+       sllg    $acc,$acc,8
+       ic      $acc,2($TY,$key)
+___
+$code.=<<___;
+       llgc    $TY,2($YY,$key)
+       stc     $TX[0],2($YY,$key)
+       llgc    $TX[1],2($XX[1],$key)
+       stc     $TY,2($XX[0],$key)
+       cr      $XX[1],$YY
+       jne     .Lcmov$i
+       la      $TX[1],0($TX[0])
+.Lcmov$i:
+       la      $TY,0($TY,$TX[0])
+       nill    $TY,255
+___
+push(@TX,shift(@TX)); push(@XX,shift(@XX));     # "rotate" registers
+}
+
+$code.=<<___;
+       lg      $TX[1],0($inp)
+       sllg    $acc,$acc,8
+       la      $inp,8($inp)
+       ic      $acc,2($TY,$key)
+       xgr     $acc,$TX[1]
+       stg     $acc,0($out)
+       la      $out,8($out)
+       brct    $cnt,.Loop8
+
+.Lshort:
+       lghi    $acc,7
+       ngr     $len,$acc
+       jz      .Lexit
+       j       .Loop1
+
+.align 16
+.Loop1:
+       la      $YY,0($YY,$TX[0])
+       nill    $YY,255
+       llgc    $TY,2($YY,$key)
+       stc     $TX[0],2($YY,$key)
+       stc     $TY,2($XX[0],$key)
+       ar      $TY,$TX[0]
+       ahi     $XX[0],1
+       nill    $TY,255
+       nill    $XX[0],255
+       llgc    $acc,0($inp)
+       la      $inp,1($inp)
+       llgc    $TY,2($TY,$key)
+       llgc    $TX[0],2($XX[0],$key)
+       xr      $acc,$TY
+       stc     $acc,0($out)
+       la      $out,1($out)
+       brct    $len,.Loop1
+
+.Lexit:
+       ahi     $XX[0],-1
+       stc     $XX[0],0($key)
+       stc     $YY,1($key)
+       lmg     %r6,%r11,48($sp)
+       br      $rp
+.size  RC4,.-RC4
+.string        "RC4 for s390x, CRYPTOGAMS by <appro\@openssl.org>"
+
+___
+}
+
+# void RC4_set_key(RC4_KEY *key,unsigned int len,const void *inp)
+{
+$cnt="%r0";
+$idx="%r1";
+$key="%r2";
+$len="%r3";
+$inp="%r4";
+$acc="%r5";
+$dat="%r6";
+$ikey="%r7";
+$iinp="%r8";
+
+$code.=<<___;
+.globl RC4_set_key
+.type  RC4_set_key,\@function
+.align 64
+RC4_set_key:
+       stmg    %r6,%r8,48($sp)
+       lhi     $cnt,256
+       la      $idx,0(%r0)
+       sth     $idx,0($key)
+.align 4
+.L1stloop:
+       stc     $idx,2($idx,$key)
+       la      $idx,1($idx)
+       brct    $cnt,.L1stloop
+
+       lghi    $ikey,-256
+       lr      $cnt,$len
+       la      $iinp,0(%r0)
+       la      $idx,0(%r0)
+.align 16
+.L2ndloop:
+       llgc    $acc,2+256($ikey,$key)
+       llgc    $dat,0($iinp,$inp)
+       la      $idx,0($idx,$acc)
+       la      $ikey,1($ikey)
+       la      $idx,0($idx,$dat)
+       nill    $idx,255
+       la      $iinp,1($iinp)
+       tml     $ikey,255
+       llgc    $dat,2($idx,$key)
+       stc     $dat,2+256-1($ikey,$key)
+       stc     $acc,2($idx,$key)
+       jz      .Ldone
+       brct    $cnt,.L2ndloop
+       lr      $cnt,$len
+       la      $iinp,0(%r0)
+       j       .L2ndloop
+.Ldone:
+       lmg     %r6,%r8,48($sp)
+       br      $rp
+.size  RC4_set_key,.-RC4_set_key
+
+___
+}
+
+# const char *RC4_options()
+$code.=<<___;
+.globl RC4_options
+.type  RC4_options,\@function
+.align 16
+RC4_options:
+       larl    %r2,.Loptions
+       br      %r14
+.size  RC4_options,.-RC4_options
+.section       .rodata
+.Loptions:
+.align 8
+.string        "rc4(8x,char)"
+___
+
+print $code;
index 53ce20e..677be5f 100755 (executable)
 # fit for Core2 and therefore the code was modified to skip cloop8 on
 # this CPU.
 
-$output=shift;
+$flavour = shift;
+$output  = shift;
+if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
+
+$win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
 
 $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
 ( $xlate="${dir}x86_64-xlate.pl" and -f $xlate ) or
 ( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
 die "can't locate x86_64-xlate.pl";
 
-open STDOUT,"| $^X $xlate $output";
+open STDOUT,"| $^X $xlate $flavour $output";
 
 $dat="%rdi";       # arg1
 $len="%rsi";       # arg2
@@ -87,8 +91,10 @@ RC4: or      $len,$len
        jne     .Lentry
        ret
 .Lentry:
+       push    %rbx
        push    %r12
        push    %r13
+.Lprologue:
 
        add     \$8,$dat
        movl    -8($dat),$XX[0]#d
@@ -133,16 +139,8 @@ $code.=<<___;
        jnz     .Lloop8
        cmp     \$0,$len
        jne     .Lloop1
-___
-$code.=<<___;
-.Lexit:
-       sub     \$1,$XX[0]#b
-       movl    $XX[0]#d,-8($dat)
-       movl    $YY#d,-4($dat)
+       jmp     .Lexit
 
-       pop     %r13
-       pop     %r12
-       ret
 .align 16
 .Lloop1:
        add     $TX[0]#b,$YY#b
@@ -169,7 +167,6 @@ $code.=<<___;
        jz      .Lcloop1
        cmpl    \$0,260($dat)
        jnz     .Lcloop1
-       push    %rbx
        jmp     .Lcloop8
 .align 16
 .Lcloop8:
@@ -224,7 +221,6 @@ $code.=<<___;
 
        test    \$-8,$len
        jnz     .Lcloop8
-       pop     %rbx
        cmp     \$0,$len
        jne     .Lcloop1
        jmp     .Lexit
@@ -249,6 +245,19 @@ $code.=<<___;
        sub     \$1,$len
        jnz     .Lcloop1
        jmp     .Lexit
+
+.align 16
+.Lexit:
+       sub     \$1,$XX[0]#b
+       movl    $XX[0]#d,-8($dat)
+       movl    $YY#d,-4($dat)
+
+       mov     (%rsp),%r13
+       mov     8(%rsp),%r12
+       mov     16(%rsp),%rbx
+       add     \$24,%rsp
+.Lepilogue:
+       ret
 .size  RC4,.-RC4
 ___
 
@@ -333,11 +342,10 @@ RC4_set_key:
 .size  RC4_set_key,.-RC4_set_key
 
 .globl RC4_options
-.type  RC4_options,\@function,0
+.type  RC4_options,\@abi-omnipotent
 .align 16
 RC4_options:
-       .picmeup %rax
-       lea     .Lopts-.(%rax),%rax
+       lea     .Lopts(%rip),%rax
        mov     OPENSSL_ia32cap_P(%rip),%edx
        bt      \$20,%edx
        jnc     .Ldone
@@ -357,9 +365,139 @@ RC4_options:
 .size  RC4_options,.-RC4_options
 ___
 
-$code =~ s/#([bwd])/$1/gm;
+# EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
+#              CONTEXT *context,DISPATCHER_CONTEXT *disp)
+if ($win64) {
+$rec="%rcx";
+$frame="%rdx";
+$context="%r8";
+$disp="%r9";
+
+$code.=<<___;
+.extern        __imp_RtlVirtualUnwind
+.type  stream_se_handler,\@abi-omnipotent
+.align 16
+stream_se_handler:
+       push    %rsi
+       push    %rdi
+       push    %rbx
+       push    %rbp
+       push    %r12
+       push    %r13
+       push    %r14
+       push    %r15
+       pushfq
+       sub     \$64,%rsp
 
-$code =~ s/RC4_set_key/private_RC4_set_key/g if ($ENV{FIPSCANLIB} ne "");
+       mov     120($context),%rax      # pull context->Rax
+       mov     248($context),%rbx      # pull context->Rip
+
+       lea     .Lprologue(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip<prologue label
+       jb      .Lin_prologue
+
+       mov     152($context),%rax      # pull context->Rsp
+
+       lea     .Lepilogue(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip>=epilogue label
+       jae     .Lin_prologue
+
+       lea     24(%rax),%rax
+
+       mov     -8(%rax),%rbx
+       mov     -16(%rax),%r12
+       mov     -24(%rax),%r13
+       mov     %rbx,144($context)      # restore context->Rbx
+       mov     %r12,216($context)      # restore context->R12
+       mov     %r13,224($context)      # restore context->R13
+
+.Lin_prologue:
+       mov     8(%rax),%rdi
+       mov     16(%rax),%rsi
+       mov     %rax,152($context)      # restore context->Rsp
+       mov     %rsi,168($context)      # restore context->Rsi
+       mov     %rdi,176($context)      # restore context->Rdi
+
+       jmp     .Lcommon_seh_exit
+.size  stream_se_handler,.-stream_se_handler
+
+.type  key_se_handler,\@abi-omnipotent
+.align 16
+key_se_handler:
+       push    %rsi
+       push    %rdi
+       push    %rbx
+       push    %rbp
+       push    %r12
+       push    %r13
+       push    %r14
+       push    %r15
+       pushfq
+       sub     \$64,%rsp
+
+       mov     152($context),%rax      # pull context->Rsp
+       mov     8(%rax),%rdi
+       mov     16(%rax),%rsi
+       mov     %rsi,168($context)      # restore context->Rsi
+       mov     %rdi,176($context)      # restore context->Rdi
+
+.Lcommon_seh_exit:
+
+       mov     40($disp),%rdi          # disp->ContextRecord
+       mov     $context,%rsi           # context
+       mov     \$154,%ecx              # sizeof(CONTEXT)
+       .long   0xa548f3fc              # cld; rep movsq
+
+       mov     $disp,%rsi
+       xor     %rcx,%rcx               # arg1, UNW_FLAG_NHANDLER
+       mov     8(%rsi),%rdx            # arg2, disp->ImageBase
+       mov     0(%rsi),%r8             # arg3, disp->ControlPc
+       mov     16(%rsi),%r9            # arg4, disp->FunctionEntry
+       mov     40(%rsi),%r10           # disp->ContextRecord
+       lea     56(%rsi),%r11           # &disp->HandlerData
+       lea     24(%rsi),%r12           # &disp->EstablisherFrame
+       mov     %r10,32(%rsp)           # arg5
+       mov     %r11,40(%rsp)           # arg6
+       mov     %r12,48(%rsp)           # arg7
+       mov     %rcx,56(%rsp)           # arg8, (NULL)
+       call    *__imp_RtlVirtualUnwind(%rip)
+
+       mov     \$1,%eax                # ExceptionContinueSearch
+       add     \$64,%rsp
+       popfq
+       pop     %r15
+       pop     %r14
+       pop     %r13
+       pop     %r12
+       pop     %rbp
+       pop     %rbx
+       pop     %rdi
+       pop     %rsi
+       ret
+.size  key_se_handler,.-key_se_handler
+
+.section       .pdata
+.align 4
+       .rva    .LSEH_begin_RC4
+       .rva    .LSEH_end_RC4
+       .rva    .LSEH_info_RC4
+
+       .rva    .LSEH_begin_RC4_set_key
+       .rva    .LSEH_end_RC4_set_key
+       .rva    .LSEH_info_RC4_set_key
+
+.section       .xdata
+.align 8
+.LSEH_info_RC4:
+       .byte   9,0,0,0
+       .rva    stream_se_handler
+.LSEH_info_RC4_set_key:
+       .byte   9,0,0,0
+       .rva    key_se_handler
+___
+}
+
+$code =~ s/#([bwd])/$1/gm;
 
 print $code;
 
index 2d8620d..29d1acc 100644 (file)
@@ -64,6 +64,8 @@
 #error RC4 is disabled.
 #endif
 
+#include <stddef.h>
+
 #ifdef  __cplusplus
 extern "C" {
 #endif
@@ -76,11 +78,8 @@ typedef struct rc4_key_st
 
  
 const char *RC4_options(void);
-#ifdef OPENSSL_FIPS
-void private_RC4_set_key(RC4_KEY *key, int len, const unsigned char *data);
-#endif
 void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data);
-void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
+void RC4(RC4_KEY *key, size_t len, const unsigned char *indata,
                unsigned char *outdata);
 
 #ifdef  __cplusplus
index 0660ea6..8c4fc6c 100644 (file)
  * Date: Wed, 14 Sep 1994 06:35:31 GMT
  */
 
-void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
+void RC4(RC4_KEY *key, size_t len, const unsigned char *indata,
             unsigned char *outdata)
        {
         register RC4_INT *d;
         register RC4_INT x,y,tx,ty;
-       int i;
+       size_t i;
         
         x=key->x;     
         y=key->y;     
@@ -120,8 +120,8 @@ void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
                        (RC4_CHUNK)d[(tx+ty)&0xff]\
                        )
 
-       if ( ( ((unsigned long)indata  & (sizeof(RC4_CHUNK)-1)) | 
-              ((unsigned long)outdata & (sizeof(RC4_CHUNK)-1)) ) == 0 )
+       if ( ( ((size_t)indata  & (sizeof(RC4_CHUNK)-1)) | 
+              ((size_t)outdata & (sizeof(RC4_CHUNK)-1)) ) == 0 )
                {
                RC4_CHUNK ichunk,otp;
                const union { long one; char little; } is_endian = {1};
@@ -157,7 +157,7 @@ void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
                if (!is_endian.little)
                        {       /* BIG-ENDIAN CASE */
 # define BESHFT(c)     (((sizeof(RC4_CHUNK)-(c)-1)*8)&(sizeof(RC4_CHUNK)*8-1))
-                       for (;len&~(sizeof(RC4_CHUNK)-1);len-=sizeof(RC4_CHUNK))
+                       for (;len&(0-sizeof(RC4_CHUNK));len-=sizeof(RC4_CHUNK))
                                {
                                ichunk  = *(RC4_CHUNK *)indata;
                                otp  = RC4_STEP<<BESHFT(0);
@@ -210,7 +210,7 @@ void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
                else
                        {       /* LITTLE-ENDIAN CASE */
 # define LESHFT(c)     (((c)*8)&(sizeof(RC4_CHUNK)*8-1))
-                       for (;len&~(sizeof(RC4_CHUNK)-1);len-=sizeof(RC4_CHUNK))
+                       for (;len&(0-sizeof(RC4_CHUNK));len-=sizeof(RC4_CHUNK))
                                {
                                ichunk  = *(RC4_CHUNK *)indata;
                                otp  = RC4_STEP;
@@ -276,7 +276,7 @@ void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
 #define RC4_LOOP(a,b,i)        LOOP(a[i],b[i])
 #endif
 
-       i=(int)(len>>3L);
+       i=len>>3;
        if (i)
                {
                for (;;)
@@ -296,7 +296,7 @@ void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
                        if (--i == 0) break;
                        }
                }
-       i=(int)len&0x07;
+       i=len&0x07;
        if (i)
                {
                for (;;)
index 4478d1a..b22c40b 100644 (file)
 #include <openssl/rc4.h>
 #include "rc4_locl.h"
 #include <openssl/opensslv.h>
-#include <openssl/crypto.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
 
 const char RC4_version[]="RC4" OPENSSL_VERSION_PTEXT;
 
@@ -90,11 +85,7 @@ const char *RC4_options(void)
  * Date: Wed, 14 Sep 1994 06:35:31 GMT
  */
 
-#ifdef OPENSSL_FIPS
-void private_RC4_set_key(RC4_KEY *key, int len, const unsigned char *data)
-#else
 void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data)
-#endif
        {
         register RC4_INT tmp;
         register int id1,id2;
@@ -128,20 +119,14 @@ void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data)
                 * implementations suffer from significant performance
                 * losses then, e.g. PIII exhibits >2x deterioration,
                 * and so does Opteron. In order to assure optimal
-                * all-round performance, we detect P4 at run-time by
-                * checking upon reserved bit 20 in CPU capability
+                * all-round performance, let us [try to] detect P4 at
+                * run-time by checking upon HTT bit in CPU capability
                 * vector and set up compressed key schedule, which is
                 * recognized by correspondingly updated assembler
-                * module... Bit 20 is set up by OPENSSL_ia32_cpuid.
-                *
+                * module...
                 *                              <appro@fy.chalmers.se>
                 */
-#ifdef OPENSSL_FIPS
-               unsigned long *ia32cap_ptr = OPENSSL_ia32cap_loc();
-               if (ia32cap_ptr && (*ia32cap_ptr & (1<<28))) {
-#else
                if (OPENSSL_ia32cap_P & (1<<28)) {
-#endif
                        unsigned char *cp=(unsigned char *)d;
 
                        for (i=0;i<256;i++) cp[i]=i;
index 54b597f..633a79e 100644 (file)
@@ -114,8 +114,8 @@ static unsigned char output[7][30]={
 
 int main(int argc, char *argv[])
        {
-       int err=0;
-       unsigned int i, j;
+       int i,err=0;
+       int j;
        unsigned char *p;
        RC4_KEY key;
        unsigned char obuf[512];
@@ -129,12 +129,12 @@ int main(int argc, char *argv[])
                        {
                        printf("error calculating RC4\n");
                        printf("output:");
-                       for (j=0; j<data_len[i]+1U; j++)
+                       for (j=0; j<data_len[i]+1; j++)
                                printf(" %02x",obuf[j]);
                        printf("\n");
                        printf("expect:");
                        p= &(output[i][0]);
-                       for (j=0; j<data_len[i]+1U; j++)
+                       for (j=0; j<data_len[i]+1; j++)
                                printf(" %02x",*(p++));
                        printf("\n");
                        err++;
@@ -180,12 +180,12 @@ int main(int argc, char *argv[])
                        {
                        printf("error in RC4 multi-call processing\n");
                        printf("output:");
-                       for (j=0; j<data_len[3]+1U; j++)
+                       for (j=0; j<data_len[3]+1; j++)
                                printf(" %02x",obuf[j]);
                        printf("\n");
                        printf("expect:");
                        p= &(output[3][0]);
-                       for (j=0; j<data_len[3]+1U; j++)
+                       for (j=0; j<data_len[3]+1; j++)
                                printf(" %02x",*(p++));
                        err++;
                        }
@@ -216,11 +216,11 @@ int main(int argc, char *argv[])
                if (memcmp(md,expected,sizeof(md))) {
                        printf("error in RC4 bulk test\n");
                        printf("output:");
-                       for (j=0; j<sizeof(md); j++)
+                       for (j=0; j<(int)sizeof(md); j++)
                                printf(" %02x",md[j]);
                        printf("\n");
                        printf("expect:");
-                       for (j=0; j<sizeof(md); j++)
+                       for (j=0; j<(int)sizeof(md); j++)
                                printf(" %02x",expected[j]);
                        printf("\n");
                        err++;
index b4e21c9..8a8b00e 100644 (file)
@@ -12,8 +12,6 @@ MAKEFILE=     Makefile
 AR=            ar r
 
 RC5_ENC=               rc5_enc.o
-# or use
-#DES_ENC=      r586-elf.o
 
 CFLAGS= $(INCLUDES) $(CFLAG)
 ASFLAGS= $(INCLUDES) $(ASFLAG)
@@ -40,19 +38,12 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
-# ELF
-r586-elf.s: asm/rc5-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
-       (cd asm; $(PERL) rc5-586.pl elf $(CFLAGS) > ../$@)
-# COFF
-r586-cof.s: asm/rc5-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
-       (cd asm; $(PERL) rc5-586.pl coff $(CFLAGS) > ../$@)
-# a.out
-r586-out.s: asm/rc5-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
-       (cd asm; $(PERL) rc5-586.pl a.out $(CFLAGS) > ../$@)
+rc5-586.s: asm/rc5-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
+       $(PERL) asm/rc5-586.pl $(PERLASM_SCHEME) $(CFLAGS) > $@
 
 files:
        $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
index edff1d1..61ac6ef 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/local/bin/perl
 
-push(@INC,"perlasm","../../perlasm");
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+push(@INC,"${dir}","${dir}../../perlasm");
 require "x86asm.pl";
 require "cbc.pl";
 
index f73a2a0..4b3c153 100644 (file)
@@ -94,10 +94,7 @@ typedef struct rc5_key_st
        RC5_32_INT data[2*(RC5_16_ROUNDS+1)];
        } RC5_32_KEY;
 
-#ifdef OPENSSL_FIPS 
-void private_RC5_32_set_key(RC5_32_KEY *key, int len, const unsigned char *data,
-       int rounds);
-#endif
 void RC5_32_set_key(RC5_32_KEY *key, int len, const unsigned char *data,
        int rounds);
 void RC5_32_ecb_encrypt(const unsigned char *in,unsigned char *out,RC5_32_KEY *key,
index 282dd38..d337f73 100644 (file)
 #  define ROTATE_l32(a,n)      ({ register unsigned int ret;   \
                                        asm ("roll %%cl,%0"     \
                                                : "=r"(ret)     \
-                                               : "c"(n),"0"(a) \
+                                               : "c"(n),"0"((unsigned int)(a)) \
                                                : "cc");        \
                                        ret;                    \
                                })
 #  define ROTATE_r32(a,n)      ({ register unsigned int ret;   \
                                        asm ("rorl %%cl,%0"     \
                                                : "=r"(ret)     \
-                                               : "c"(n),"0"(a) \
+                                               : "c"(n),"0"((unsigned int)(a)) \
                                                : "cc");        \
                                        ret;                    \
                                })
index 247fa65..a2e00a4 100644 (file)
  * [including the GNU Public Licence.]
  */
 
-#include <openssl/crypto.h>
 #include <openssl/rc5.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
 #include "rc5_locl.h"
 
-#ifdef OPENSSL_FIPS
-void RC5_32_set_key(RC5_32_KEY *key, int len, const unsigned char *data,
-                   int rounds)
-       {
-       if (FIPS_mode())
-               FIPS_BAD_ABORT(RC5)
-       private_RC5_32_set_key(key, len, data, rounds);
-       }
-void private_RC5_32_set_key(RC5_32_KEY *key, int len, const unsigned char *data,
-                   int rounds)
-#else
 void RC5_32_set_key(RC5_32_KEY *key, int len, const unsigned char *data,
                    int rounds)
-#endif
        {
        RC5_32_INT L[64],l,ll,A,B,*S,k;
        int i,j,m,c,t,ii,jj;
index 6145f13..d5b1067 100644 (file)
@@ -38,19 +38,12 @@ top:
 all:    lib
 
 lib:    $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
-# ELF
-rm86-elf.s: asm/rmd-586.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) rmd-586.pl elf $(CFLAGS) > ../$@)
-# COFF
-rm86-cof.s: asm/rmd-586.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) rmd-586.pl coff $(CFLAGS) > ../$@)
-# a.out
-rm86-out.s: asm/rmd-586.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) rmd-586.pl a.out $(CFLAGS) > ../$@)
+rmd-586.s:     asm/rmd-586.pl ../perlasm/x86asm.pl
+       $(PERL) asm/rmd-586.pl $(PERLASM_SCHEME) $(CFLAGS) > $@
 
 files:
        $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
@@ -89,13 +82,8 @@ clean:
 
 # DO NOT DELETE THIS LINE -- make depend depends on it.
 
-rmd_dgst.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
-rmd_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-rmd_dgst.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-rmd_dgst.o: ../../include/openssl/opensslconf.h
-rmd_dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-rmd_dgst.o: ../../include/openssl/ripemd.h ../../include/openssl/safestack.h
-rmd_dgst.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+rmd_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
+rmd_dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/ripemd.h
 rmd_dgst.o: ../md32_common.h rmd_dgst.c rmd_locl.h rmdconst.h
 rmd_one.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 rmd_one.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
index 4f3c4c9..e8b2bc2 100644 (file)
@@ -5,7 +5,8 @@
 
 $normal=0;
 
-push(@INC,"perlasm","../../perlasm");
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+push(@INC,"${dir}","${dir}../../perlasm");
 require "x86asm.pl";
 
 &asm_init($ARGV[0],$0);
index 3b6d043..5942eb6 100644 (file)
@@ -70,7 +70,7 @@ extern "C" {
 #error RIPEMD is disabled.
 #endif
 
-#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)
+#if defined(__LP32__)
 #define RIPEMD160_LONG unsigned long
 #elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
 #define RIPEMD160_LONG unsigned long
@@ -90,9 +90,7 @@ typedef struct RIPEMD160state_st
        RIPEMD160_LONG data[RIPEMD160_LBLOCK];
        unsigned int   num;
        } RIPEMD160_CTX;
-#ifdef OPENSSL_FIPS
-int private_RIPEMD160_Init(RIPEMD160_CTX *c);
-#endif
+
 int RIPEMD160_Init(RIPEMD160_CTX *c);
 int RIPEMD160_Update(RIPEMD160_CTX *c, const void *data, size_t len);
 int RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c);
index ead11d0..59b017f 100644 (file)
 #include <stdio.h>
 #include "rmd_locl.h"
 #include <openssl/opensslv.h>
-#include <openssl/err.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
 
 const char RMD160_version[]="RIPE-MD160" OPENSSL_VERSION_PTEXT;
 
@@ -74,16 +69,14 @@ const char RMD160_version[]="RIPE-MD160" OPENSSL_VERSION_PTEXT;
      void ripemd160_block(RIPEMD160_CTX *c, unsigned long *p,size_t num);
 #  endif
 
-FIPS_NON_FIPS_MD_Init(RIPEMD160)
+int RIPEMD160_Init(RIPEMD160_CTX *c)
        {
+       memset (c,0,sizeof(*c));
        c->A=RIPEMD160_A;
        c->B=RIPEMD160_B;
        c->C=RIPEMD160_C;
        c->D=RIPEMD160_D;
        c->E=RIPEMD160_E;
-       c->Nl=0;
-       c->Nh=0;
-       c->num=0;
        return 1;
        }
 
index ce12a80..f14b346 100644 (file)
@@ -72,7 +72,7 @@
  */
 #ifdef RMD160_ASM
 # if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__)
-#  define ripemd160_block_host_order ripemd160_block_asm_data_order
+#  define ripemd160_block_data_order ripemd160_block_asm_data_order
 # endif
 #endif
 
index 7b1fd64..bb64223 100644 (file)
@@ -19,10 +19,12 @@ APPS=
 LIB=$(TOP)/libcrypto.a
 LIBSRC= rsa_eay.c rsa_gen.c rsa_lib.c rsa_sign.c rsa_saos.c rsa_err.c \
        rsa_pk1.c rsa_ssl.c rsa_none.c rsa_oaep.c rsa_chk.c rsa_null.c \
-       rsa_pss.c rsa_x931.c rsa_x931g.c rsa_asn1.c rsa_depr.c rsa_eng.c
+       rsa_pss.c rsa_x931.c rsa_asn1.c rsa_depr.c rsa_ameth.c rsa_prn.c \
+       rsa_pmeth.c
 LIBOBJ= rsa_eay.o rsa_gen.o rsa_lib.o rsa_sign.o rsa_saos.o rsa_err.o \
        rsa_pk1.o rsa_ssl.o rsa_none.o rsa_oaep.o rsa_chk.o rsa_null.o \
-       rsa_pss.o rsa_x931.o rsa_x931g.o rsa_asn1.o rsa_depr.o rsa_eng.o
+       rsa_pss.o rsa_x931.o rsa_asn1.o rsa_depr.o rsa_ameth.o rsa_prn.o \
+       rsa_pmeth.o
 
 SRC= $(LIBSRC)
 
@@ -37,7 +39,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -78,6 +80,22 @@ clean:
 
 # DO NOT DELETE THIS LINE -- make depend depends on it.
 
+rsa_ameth.o: ../../e_os.h ../../include/openssl/asn1.h
+rsa_ameth.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
+rsa_ameth.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
+rsa_ameth.o: ../../include/openssl/cms.h ../../include/openssl/crypto.h
+rsa_ameth.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+rsa_ameth.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
+rsa_ameth.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+rsa_ameth.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+rsa_ameth.o: ../../include/openssl/objects.h
+rsa_ameth.o: ../../include/openssl/opensslconf.h
+rsa_ameth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+rsa_ameth.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
+rsa_ameth.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+rsa_ameth.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+rsa_ameth.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+rsa_ameth.o: ../asn1/asn1_locl.h ../cryptlib.h rsa_ameth.c
 rsa_asn1.o: ../../e_os.h ../../include/openssl/asn1.h
 rsa_asn1.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 rsa_asn1.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
@@ -114,21 +132,6 @@ rsa_eay.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 rsa_eay.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
 rsa_eay.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
 rsa_eay.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_eay.c
-rsa_eng.o: ../../e_os.h ../../include/openssl/asn1.h
-rsa_eng.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
-rsa_eng.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
-rsa_eng.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-rsa_eng.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
-rsa_eng.o: ../../include/openssl/engine.h ../../include/openssl/err.h
-rsa_eng.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-rsa_eng.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-rsa_eng.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-rsa_eng.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-rsa_eng.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
-rsa_eng.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
-rsa_eng.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-rsa_eng.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-rsa_eng.o: ../../include/openssl/x509_vfy.h ../cryptlib.h rsa_eng.c
 rsa_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
 rsa_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 rsa_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
@@ -151,15 +154,15 @@ rsa_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 rsa_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 rsa_lib.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 rsa_lib.o: ../../include/openssl/engine.h ../../include/openssl/err.h
-rsa_lib.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-rsa_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-rsa_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-rsa_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-rsa_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
-rsa_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
-rsa_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-rsa_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-rsa_lib.o: ../../include/openssl/x509_vfy.h ../cryptlib.h rsa_lib.c
+rsa_lib.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+rsa_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+rsa_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+rsa_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+rsa_lib.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
+rsa_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+rsa_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+rsa_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+rsa_lib.o: ../cryptlib.h rsa_lib.c
 rsa_none.o: ../../e_os.h ../../include/openssl/asn1.h
 rsa_none.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
 rsa_none.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
@@ -182,9 +185,9 @@ rsa_oaep.o: ../../e_os.h ../../include/openssl/asn1.h
 rsa_oaep.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
 rsa_oaep.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 rsa_oaep.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-rsa_oaep.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-rsa_oaep.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-rsa_oaep.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+rsa_oaep.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+rsa_oaep.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+rsa_oaep.o: ../../include/openssl/opensslconf.h
 rsa_oaep.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 rsa_oaep.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
 rsa_oaep.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
@@ -199,27 +202,50 @@ rsa_pk1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 rsa_pk1.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
 rsa_pk1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
 rsa_pk1.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_pk1.c
+rsa_pmeth.o: ../../e_os.h ../../include/openssl/asn1.h
+rsa_pmeth.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
+rsa_pmeth.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
+rsa_pmeth.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+rsa_pmeth.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+rsa_pmeth.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
+rsa_pmeth.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+rsa_pmeth.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+rsa_pmeth.o: ../../include/openssl/opensslconf.h
+rsa_pmeth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+rsa_pmeth.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
+rsa_pmeth.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+rsa_pmeth.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+rsa_pmeth.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+rsa_pmeth.o: ../cryptlib.h ../evp/evp_locl.h rsa_locl.h rsa_pmeth.c
+rsa_prn.o: ../../e_os.h ../../include/openssl/asn1.h
+rsa_prn.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
+rsa_prn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+rsa_prn.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+rsa_prn.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+rsa_prn.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+rsa_prn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+rsa_prn.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+rsa_prn.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+rsa_prn.o: ../cryptlib.h rsa_prn.c
 rsa_pss.o: ../../e_os.h ../../include/openssl/asn1.h
 rsa_pss.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
 rsa_pss.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 rsa_pss.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-rsa_pss.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-rsa_pss.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-rsa_pss.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-rsa_pss.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-rsa_pss.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
-rsa_pss.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-rsa_pss.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-rsa_pss.o: ../cryptlib.h rsa_pss.c
+rsa_pss.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+rsa_pss.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+rsa_pss.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+rsa_pss.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
+rsa_pss.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+rsa_pss.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+rsa_pss.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_pss.c
 rsa_saos.o: ../../e_os.h ../../include/openssl/asn1.h
 rsa_saos.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
 rsa_saos.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 rsa_saos.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 rsa_saos.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 rsa_saos.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-rsa_saos.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-rsa_saos.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-rsa_saos.o: ../../include/openssl/opensslconf.h
+rsa_saos.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+rsa_saos.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 rsa_saos.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 rsa_saos.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
 rsa_saos.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
@@ -232,15 +258,14 @@ rsa_sign.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 rsa_sign.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 rsa_sign.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 rsa_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-rsa_sign.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-rsa_sign.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-rsa_sign.o: ../../include/openssl/opensslconf.h
+rsa_sign.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+rsa_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 rsa_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 rsa_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
 rsa_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
 rsa_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
 rsa_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-rsa_sign.o: ../cryptlib.h rsa_sign.c
+rsa_sign.o: ../cryptlib.h rsa_locl.h rsa_sign.c
 rsa_ssl.o: ../../e_os.h ../../include/openssl/asn1.h
 rsa_ssl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
 rsa_ssl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
@@ -260,11 +285,3 @@ rsa_x931.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 rsa_x931.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
 rsa_x931.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
 rsa_x931.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_x931.c
-rsa_x931g.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-rsa_x931g.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
-rsa_x931g.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-rsa_x931g.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
-rsa_x931g.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-rsa_x931g.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
-rsa_x931g.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-rsa_x931g.o: rsa_x931g.c
index 5bb932a..cf74343 100644 (file)
 #error RSA is disabled.
 #endif
 
-/* If this flag is set the RSA method is FIPS compliant and can be used
- * in FIPS mode. This is set in the validated module method. If an
- * application sets this flag in its own methods it is its reposibility
- * to ensure the result is compliant.
- */
-
-#define RSA_FLAG_FIPS_METHOD                   0x0400
-
-/* If this flag is set the operations normally disabled in FIPS mode are
- * permitted it is then the applications responsibility to ensure that the
- * usage is compliant.
- */
-
-#define RSA_FLAG_NON_FIPS_ALLOW                        0x0400
-
-#ifdef OPENSSL_FIPS
-#define FIPS_RSA_SIZE_T        int
-#endif
-
 #ifdef  __cplusplus
 extern "C" {
 #endif
@@ -136,7 +117,8 @@ struct rsa_meth_st
                unsigned char *sigret, unsigned int *siglen, const RSA *rsa);
        int (*rsa_verify)(int dtype,
                const unsigned char *m, unsigned int m_length,
-               unsigned char *sigbuf, unsigned int siglen, const RSA *rsa);
+               const unsigned char *sigbuf, unsigned int siglen,
+                                                               const RSA *rsa);
 /* If this callback is NULL, the builtin software RSA key-gen will be used. This
  * is for behavioural compatibility whilst the code gets rewired, but one day
  * it would be nice to assume there are no such things as "builtin software"
@@ -182,8 +164,6 @@ struct rsa_st
 # define OPENSSL_RSA_MAX_MODULUS_BITS  16384
 #endif
 
-#define OPENSSL_RSA_FIPS_MIN_MODULUS_BITS 1024
-
 #ifndef OPENSSL_RSA_SMALL_MODULUS_BITS
 # define OPENSSL_RSA_SMALL_MODULUS_BITS        3072
 #endif
@@ -238,11 +218,37 @@ struct rsa_st
 #endif
 
 
+#define EVP_PKEY_CTX_set_rsa_padding(ctx, pad) \
+       EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, -1, EVP_PKEY_CTRL_RSA_PADDING, \
+                               pad, NULL)
+
+#define EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, len) \
+       EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, \
+                               (EVP_PKEY_OP_SIGN|EVP_PKEY_OP_VERIFY), \
+                               EVP_PKEY_CTRL_RSA_PSS_SALTLEN, \
+                               len, NULL)
+
+#define EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, bits) \
+       EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_KEYGEN, \
+                               EVP_PKEY_CTRL_RSA_KEYGEN_BITS, bits, NULL)
+
+#define EVP_PKEY_CTX_set_rsa_keygen_pubexp(ctx, pubexp) \
+       EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_KEYGEN, \
+                               EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP, 0, pubexp)
+
+#define EVP_PKEY_CTRL_RSA_PADDING      (EVP_PKEY_ALG_CTRL + 1)
+#define EVP_PKEY_CTRL_RSA_PSS_SALTLEN  (EVP_PKEY_ALG_CTRL + 2)
+
+#define EVP_PKEY_CTRL_RSA_KEYGEN_BITS  (EVP_PKEY_ALG_CTRL + 3)
+#define EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP        (EVP_PKEY_ALG_CTRL + 4)
+
 #define RSA_PKCS1_PADDING      1
 #define RSA_SSLV23_PADDING     2
 #define RSA_NO_PADDING         3
 #define RSA_PKCS1_OAEP_PADDING 4
 #define RSA_X931_PADDING       5
+/* EVP_PKEY_ only */
+#define RSA_PKCS1_PSS_PADDING  6
 
 #define RSA_PKCS1_PADDING_SIZE 11
 
@@ -261,11 +267,6 @@ RSA *      RSA_generate_key(int bits, unsigned long e,void
 
 /* New version */
 int    RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
-int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1, BIGNUM *q2,
-                       const BIGNUM *Xp1, const BIGNUM *Xp2, const BIGNUM *Xp,
-                       const BIGNUM *Xq1, const BIGNUM *Xq2, const BIGNUM *Xq,
-                       const BIGNUM *e, BN_GENCB *cb);
-int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e, BN_GENCB *cb);
 
 int    RSA_check_key(const RSA *);
        /* next 4 return -1 on error */
@@ -283,11 +284,6 @@ int        RSA_up_ref(RSA *r);
 
 int    RSA_flags(const RSA *r);
 
-#ifdef OPENSSL_FIPS
-RSA *FIPS_rsa_new(void);
-void FIPS_rsa_free(RSA *r);
-#endif
-
 void RSA_set_default_method(const RSA_METHOD *meth);
 const RSA_METHOD *RSA_get_default_method(void);
 const RSA_METHOD *RSA_get_method(const RSA *rsa);
@@ -333,7 +329,7 @@ RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length,
 int RSA_sign(int type, const unsigned char *m, unsigned int m_length,
        unsigned char *sigret, unsigned int *siglen, RSA *rsa);
 int RSA_verify(int type, const unsigned char *m, unsigned int m_length,
-       unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
+       const unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
 
 /* The following 2 function sign and verify a ASN1_OCTET_STRING
  * object inside PKCS#1 padded RSA encryption */
@@ -401,9 +397,15 @@ void ERR_load_RSA_strings(void);
 /* Error codes for the RSA functions. */
 
 /* Function codes. */
-#define RSA_F_FIPS_RSA_SIGN                             140
-#define RSA_F_FIPS_RSA_VERIFY                           141
+#define RSA_F_CHECK_PADDING_MD                          140
+#define RSA_F_DO_RSA_PRINT                              146
+#define RSA_F_INT_RSA_VERIFY                            145
 #define RSA_F_MEMORY_LOCK                               100
+#define RSA_F_OLD_RSA_PRIV_DECODE                       147
+#define RSA_F_PKEY_RSA_CTRL                             143
+#define RSA_F_PKEY_RSA_CTRL_STR                                 144
+#define RSA_F_PKEY_RSA_SIGN                             142
+#define RSA_F_PKEY_RSA_VERIFYRECOVER                    141
 #define RSA_F_RSA_BUILTIN_KEYGEN                        129
 #define RSA_F_RSA_CHECK_KEY                             123
 #define RSA_F_RSA_EAY_PRIVATE_DECRYPT                   101
@@ -434,11 +436,10 @@ void ERR_load_RSA_strings(void);
 #define RSA_F_RSA_PADDING_CHECK_X931                    128
 #define RSA_F_RSA_PRINT                                         115
 #define RSA_F_RSA_PRINT_FP                              116
-#define RSA_F_RSA_PRIVATE_ENCRYPT                       137
-#define RSA_F_RSA_PUBLIC_DECRYPT                        138
+#define RSA_F_RSA_PRIV_DECODE                           137
+#define RSA_F_RSA_PRIV_ENCODE                           138
+#define RSA_F_RSA_PUB_DECODE                            139
 #define RSA_F_RSA_SETUP_BLINDING                        136
-#define RSA_F_RSA_SET_DEFAULT_METHOD                    139
-#define RSA_F_RSA_SET_METHOD                            142
 #define RSA_F_RSA_SIGN                                  117
 #define RSA_F_RSA_SIGN_ASN1_OCTET_STRING                118
 #define RSA_F_RSA_VERIFY                                119
@@ -464,20 +465,25 @@ void ERR_load_RSA_strings(void);
 #define RSA_R_DMQ1_NOT_CONGRUENT_TO_D                   125
 #define RSA_R_D_E_NOT_CONGRUENT_TO_1                    123
 #define RSA_R_FIRST_OCTET_INVALID                       133
+#define RSA_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE       144
+#define RSA_R_INVALID_DIGEST_LENGTH                     143
 #define RSA_R_INVALID_HEADER                            137
+#define RSA_R_INVALID_KEYBITS                           145
 #define RSA_R_INVALID_MESSAGE_LENGTH                    131
 #define RSA_R_INVALID_PADDING                           138
+#define RSA_R_INVALID_PADDING_MODE                      141
+#define RSA_R_INVALID_PSS_SALTLEN                       146
 #define RSA_R_INVALID_TRAILER                           139
+#define RSA_R_INVALID_X931_DIGEST                       142
 #define RSA_R_IQMP_NOT_INVERSE_OF_Q                     126
 #define RSA_R_KEY_SIZE_TOO_SMALL                        120
 #define RSA_R_LAST_OCTET_INVALID                        134
 #define RSA_R_MODULUS_TOO_LARGE                                 105
-#define RSA_R_NON_FIPS_METHOD                           141
 #define RSA_R_NO_PUBLIC_EXPONENT                        140
 #define RSA_R_NULL_BEFORE_BLOCK_MISSING                         113
 #define RSA_R_N_DOES_NOT_EQUAL_P_Q                      127
 #define RSA_R_OAEP_DECODING_ERROR                       121
-#define RSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE        142
+#define RSA_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE  148
 #define RSA_R_PADDING_CHECK_FAILED                      114
 #define RSA_R_P_NOT_PRIME                               128
 #define RSA_R_Q_NOT_PRIME                               129
@@ -488,6 +494,7 @@ void ERR_load_RSA_strings(void);
 #define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116
 #define RSA_R_UNKNOWN_ALGORITHM_TYPE                    117
 #define RSA_R_UNKNOWN_PADDING_TYPE                      118
+#define RSA_R_VALUE_MISSING                             147
 #define RSA_R_WRONG_SIGNATURE_LENGTH                    119
 
 #ifdef  __cplusplus
diff --git a/deps/openssl/openssl/crypto/rsa/rsa_ameth.c b/deps/openssl/openssl/crypto/rsa/rsa_ameth.c
new file mode 100644 (file)
index 0000000..8c32098
--- /dev/null
@@ -0,0 +1,349 @@
+/* crypto/rsa/rsa_ameth.c */
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project 2006.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include "cryptlib.h"
+#include <openssl/asn1t.h>
+#include <openssl/x509.h>
+#include <openssl/rsa.h>
+#include <openssl/bn.h>
+#ifndef OPENSSL_NO_CMS
+#include <openssl/cms.h>
+#endif
+#include "asn1_locl.h"
+
+static int rsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
+       {
+       unsigned char *penc = NULL;
+       int penclen;
+       penclen = i2d_RSAPublicKey(pkey->pkey.rsa, &penc);
+       if (penclen <= 0)
+               return 0;
+       if (X509_PUBKEY_set0_param(pk, OBJ_nid2obj(EVP_PKEY_RSA),
+                               V_ASN1_NULL, NULL, penc, penclen))
+               return 1;
+
+       OPENSSL_free(penc);
+       return 0;
+       }
+
+static int rsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
+       {
+       const unsigned char *p;
+       int pklen;
+       RSA *rsa = NULL;
+       if (!X509_PUBKEY_get0_param(NULL, &p, &pklen, NULL, pubkey))
+               return 0;
+       if (!(rsa = d2i_RSAPublicKey(NULL, &p, pklen)))
+               {
+               RSAerr(RSA_F_RSA_PUB_DECODE, ERR_R_RSA_LIB);
+               return 0;
+               }
+       EVP_PKEY_assign_RSA (pkey, rsa);
+       return 1;
+       }
+
+static int rsa_pub_cmp(const EVP_PKEY *a, const EVP_PKEY *b)
+       {
+       if (BN_cmp(b->pkey.rsa->n,a->pkey.rsa->n) != 0
+               || BN_cmp(b->pkey.rsa->e,a->pkey.rsa->e) != 0)
+                       return 0;
+       return 1;
+       }
+
+static int old_rsa_priv_decode(EVP_PKEY *pkey,
+                                       const unsigned char **pder, int derlen)
+       {
+       RSA *rsa;
+       if (!(rsa = d2i_RSAPrivateKey (NULL, pder, derlen)))
+               {
+               RSAerr(RSA_F_OLD_RSA_PRIV_DECODE, ERR_R_RSA_LIB);
+               return 0;
+               }
+       EVP_PKEY_assign_RSA(pkey, rsa);
+       return 1;
+       }
+
+static int old_rsa_priv_encode(const EVP_PKEY *pkey, unsigned char **pder)
+       {
+       return i2d_RSAPrivateKey(pkey->pkey.rsa, pder);
+       }
+
+static int rsa_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
+       {
+       unsigned char *rk = NULL;
+       int rklen;
+       rklen = i2d_RSAPrivateKey(pkey->pkey.rsa, &rk);
+
+       if (rklen <= 0)
+               {
+               RSAerr(RSA_F_RSA_PRIV_ENCODE,ERR_R_MALLOC_FAILURE);
+               return 0;
+               }
+
+       if (!PKCS8_pkey_set0(p8, OBJ_nid2obj(NID_rsaEncryption), 0,
+                               V_ASN1_NULL, NULL, rk, rklen))
+               {
+               RSAerr(RSA_F_RSA_PRIV_ENCODE,ERR_R_MALLOC_FAILURE);
+               return 0;
+               }
+
+       return 1;
+       }
+
+static int rsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8)
+       {
+       const unsigned char *p;
+       int pklen;
+       if (!PKCS8_pkey_get0(NULL, &p, &pklen, NULL, p8))
+               return 0;
+       return old_rsa_priv_decode(pkey, &p, pklen);
+       }
+
+static int int_rsa_size(const EVP_PKEY *pkey)
+       {
+       return RSA_size(pkey->pkey.rsa);
+       }
+
+static int rsa_bits(const EVP_PKEY *pkey)
+       {
+       return BN_num_bits(pkey->pkey.rsa->n);
+       }
+
+static void int_rsa_free(EVP_PKEY *pkey)
+       {
+       RSA_free(pkey->pkey.rsa);
+       }
+
+
+static void update_buflen(const BIGNUM *b, size_t *pbuflen)
+       {
+       size_t i;
+       if (!b)
+               return;
+       if (*pbuflen < (i = (size_t)BN_num_bytes(b)))
+                       *pbuflen = i;
+       }
+
+static int do_rsa_print(BIO *bp, const RSA *x, int off, int priv)
+       {
+       char *str;
+       const char *s;
+       unsigned char *m=NULL;
+       int ret=0, mod_len = 0;
+       size_t buf_len=0;
+
+       update_buflen(x->n, &buf_len);
+       update_buflen(x->e, &buf_len);
+
+       if (priv)
+               {
+               update_buflen(x->d, &buf_len);
+               update_buflen(x->p, &buf_len);
+               update_buflen(x->q, &buf_len);
+               update_buflen(x->dmp1, &buf_len);
+               update_buflen(x->dmq1, &buf_len);
+               update_buflen(x->iqmp, &buf_len);
+               }
+
+       m=(unsigned char *)OPENSSL_malloc(buf_len+10);
+       if (m == NULL)
+               {
+               RSAerr(RSA_F_DO_RSA_PRINT,ERR_R_MALLOC_FAILURE);
+               goto err;
+               }
+
+       if (x->n != NULL)
+               mod_len = BN_num_bits(x->n);
+
+       if(!BIO_indent(bp,off,128))
+               goto err;
+
+       if (priv && x->d)
+               {
+               if (BIO_printf(bp,"Private-Key: (%d bit)\n", mod_len)
+                       <= 0) goto err;
+               str = "modulus:";
+               s = "publicExponent:";
+               }
+       else
+               {
+               if (BIO_printf(bp,"Public-Key: (%d bit)\n", mod_len)
+                       <= 0) goto err;
+               str = "Modulus:";
+               s= "Exponent:";
+               }
+       if (!ASN1_bn_print(bp,str,x->n,m,off)) goto err;
+       if (!ASN1_bn_print(bp,s,x->e,m,off))
+               goto err;
+       if (priv)
+               {
+               if (!ASN1_bn_print(bp,"privateExponent:",x->d,m,off))
+                       goto err;
+               if (!ASN1_bn_print(bp,"prime1:",x->p,m,off))
+                       goto err;
+               if (!ASN1_bn_print(bp,"prime2:",x->q,m,off))
+                       goto err;
+               if (!ASN1_bn_print(bp,"exponent1:",x->dmp1,m,off))
+                       goto err;
+               if (!ASN1_bn_print(bp,"exponent2:",x->dmq1,m,off))
+                       goto err;
+               if (!ASN1_bn_print(bp,"coefficient:",x->iqmp,m,off))
+                       goto err;
+               }
+       ret=1;
+err:
+       if (m != NULL) OPENSSL_free(m);
+       return(ret);
+       }
+
+static int rsa_pub_print(BIO *bp, const EVP_PKEY *pkey, int indent,
+                                                       ASN1_PCTX *ctx)
+       {
+       return do_rsa_print(bp, pkey->pkey.rsa, indent, 0);
+       }
+
+
+static int rsa_priv_print(BIO *bp, const EVP_PKEY *pkey, int indent,
+                                                       ASN1_PCTX *ctx)
+       {
+       return do_rsa_print(bp, pkey->pkey.rsa, indent, 1);
+       }
+
+
+static int rsa_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
+       {
+       X509_ALGOR *alg = NULL;
+       switch (op)
+               {
+
+               case ASN1_PKEY_CTRL_PKCS7_SIGN:
+               if (arg1 == 0)
+                       PKCS7_SIGNER_INFO_get0_algs(arg2, NULL, NULL, &alg);
+               break;
+
+               case ASN1_PKEY_CTRL_PKCS7_ENCRYPT:
+               if (arg1 == 0)
+                       PKCS7_RECIP_INFO_get0_alg(arg2, &alg);
+               break;
+#ifndef OPENSSL_NO_CMS
+               case ASN1_PKEY_CTRL_CMS_SIGN:
+               if (arg1 == 0)
+                       CMS_SignerInfo_get0_algs(arg2, NULL, NULL, NULL, &alg);
+               break;
+
+               case ASN1_PKEY_CTRL_CMS_ENVELOPE:
+               if (arg1 == 0)
+                       CMS_RecipientInfo_ktri_get0_algs(arg2, NULL, NULL, &alg);
+               break;
+#endif
+
+               case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
+               *(int *)arg2 = NID_sha1;
+               return 1;
+
+               default:
+               return -2;
+
+               }
+
+       if (alg)
+               X509_ALGOR_set0(alg, OBJ_nid2obj(NID_rsaEncryption),
+                                                       V_ASN1_NULL, 0);
+
+       return 1;
+
+       }
+
+
+const EVP_PKEY_ASN1_METHOD rsa_asn1_meths[] = 
+       {
+               {
+               EVP_PKEY_RSA,
+               EVP_PKEY_RSA,
+               ASN1_PKEY_SIGPARAM_NULL,
+
+               "RSA",
+               "OpenSSL RSA method",
+
+               rsa_pub_decode,
+               rsa_pub_encode,
+               rsa_pub_cmp,
+               rsa_pub_print,
+
+               rsa_priv_decode,
+               rsa_priv_encode,
+               rsa_priv_print,
+
+               int_rsa_size,
+               rsa_bits,
+
+               0,0,0,0,0,0,
+
+               int_rsa_free,
+               rsa_pkey_ctrl,
+               old_rsa_priv_decode,
+               old_rsa_priv_encode
+               },
+
+               {
+               EVP_PKEY_RSA2,
+               EVP_PKEY_RSA,
+               ASN1_PKEY_ALIAS
+               }
+       };
index 6e8a803..4efca8c 100644 (file)
@@ -3,7 +3,7 @@
  * project 2000.
  */
 /* ====================================================================
- * Copyright (c) 2000 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 2000-2005 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include <openssl/rsa.h>
 #include <openssl/asn1t.h>
 
-static ASN1_METHOD method={
-        (I2D_OF(void))     i2d_RSAPrivateKey,
-        (D2I_OF(void))     d2i_RSAPrivateKey,
-        (void *(*)(void))  RSA_new,
-        (void (*)(void *)) RSA_free};
-
-ASN1_METHOD *RSAPrivateKey_asn1_meth(void)
-       {
-       return(&method);
-       }
-
 /* Override the default free and new methods */
-static int rsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
+static int rsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
+                                                               void *exarg)
 {
        if(operation == ASN1_OP_NEW_PRE) {
                *pval = (ASN1_VALUE *)RSA_new();
index 412d0ea..2e1ddd4 100644 (file)
 #include <openssl/rsa.h>
 #include <openssl/rand.h>
 
-#if !defined(RSA_NULL) && !defined(OPENSSL_FIPS)
+#ifndef RSA_NULL
 
 static int RSA_eay_public_encrypt(int flen, const unsigned char *from,
                unsigned char *to, RSA *rsa,int padding);
@@ -256,6 +256,7 @@ static BN_BLINDING *rsa_get_blinding(RSA *rsa, int *local, BN_CTX *ctx)
 {
        BN_BLINDING *ret;
        int got_write_lock = 0;
+       CRYPTO_THREADID cur;
 
        CRYPTO_r_lock(CRYPTO_LOCK_RSA);
 
@@ -273,7 +274,8 @@ static BN_BLINDING *rsa_get_blinding(RSA *rsa, int *local, BN_CTX *ctx)
        if (ret == NULL)
                goto err;
 
-       if (BN_BLINDING_get_thread_id(ret) == CRYPTO_thread_id())
+       CRYPTO_THREADID_current(&cur);
+       if (!CRYPTO_THREADID_cmp(&cur, BN_BLINDING_thread_id(ret)))
                {
                /* rsa->blinding is ours! */
 
@@ -312,51 +314,56 @@ static BN_BLINDING *rsa_get_blinding(RSA *rsa, int *local, BN_CTX *ctx)
        return ret;
 }
 
-static int rsa_blinding_convert(BN_BLINDING *b, int local, BIGNUM *f,
-       BIGNUM *r, BN_CTX *ctx)
-{
-       if (local)
+static int rsa_blinding_convert(BN_BLINDING *b, BIGNUM *f, BIGNUM *unblind,
+       BN_CTX *ctx)
+       {
+       if (unblind == NULL)
+               /* Local blinding: store the unblinding factor
+                * in BN_BLINDING. */
                return BN_BLINDING_convert_ex(f, NULL, b, ctx);
        else
                {
-               int ret;
-               CRYPTO_r_lock(CRYPTO_LOCK_RSA_BLINDING);
-               ret = BN_BLINDING_convert_ex(f, r, b, ctx);
-               CRYPTO_r_unlock(CRYPTO_LOCK_RSA_BLINDING);
-               return ret;
-               }
-}
-
-static int rsa_blinding_invert(BN_BLINDING *b, int local, BIGNUM *f,
-       BIGNUM *r, BN_CTX *ctx)
-{
-       if (local)
-               return BN_BLINDING_invert_ex(f, NULL, b, ctx);
-       else
-               {
+               /* Shared blinding: store the unblinding factor
+                * outside BN_BLINDING. */
                int ret;
                CRYPTO_w_lock(CRYPTO_LOCK_RSA_BLINDING);
-               ret = BN_BLINDING_invert_ex(f, r, b, ctx);
+               ret = BN_BLINDING_convert_ex(f, unblind, b, ctx);
                CRYPTO_w_unlock(CRYPTO_LOCK_RSA_BLINDING);
                return ret;
                }
-}
+       }
+
+static int rsa_blinding_invert(BN_BLINDING *b, BIGNUM *f, BIGNUM *unblind,
+       BN_CTX *ctx)
+       {
+       /* For local blinding, unblind is set to NULL, and BN_BLINDING_invert_ex
+        * will use the unblinding factor stored in BN_BLINDING.
+        * If BN_BLINDING is shared between threads, unblind must be non-null:
+        * BN_BLINDING_invert_ex will then use the local unblinding factor,
+        * and will only read the modulus from BN_BLINDING.
+        * In both cases it's safe to access the blinding without a lock.
+        */
+       return BN_BLINDING_invert_ex(f, unblind, b, ctx);
+       }
 
 /* signing */
 static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
             unsigned char *to, RSA *rsa, int padding)
        {
-       BIGNUM *f, *ret, *br, *res;
+       BIGNUM *f, *ret, *res;
        int i,j,k,num=0,r= -1;
        unsigned char *buf=NULL;
        BN_CTX *ctx=NULL;
        int local_blinding = 0;
+       /* Used only if the blinding structure is shared. A non-NULL unblind
+        * instructs rsa_blinding_convert() and rsa_blinding_invert() to store
+        * the unblinding factor outside the blinding structure. */
+       BIGNUM *unblind = NULL;
        BN_BLINDING *blinding = NULL;
 
        if ((ctx=BN_CTX_new()) == NULL) goto err;
        BN_CTX_start(ctx);
        f   = BN_CTX_get(ctx);
-       br  = BN_CTX_get(ctx);
        ret = BN_CTX_get(ctx);
        num = BN_num_bytes(rsa->n);
        buf = OPENSSL_malloc(num);
@@ -404,8 +411,15 @@ static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
                }
        
        if (blinding != NULL)
-               if (!rsa_blinding_convert(blinding, local_blinding, f, br, ctx))
+               {
+               if (!local_blinding && ((unblind = BN_CTX_get(ctx)) == NULL))
+                       {
+                       RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,ERR_R_MALLOC_FAILURE);
+                       goto err;
+                       }
+               if (!rsa_blinding_convert(blinding, f, unblind, ctx))
                        goto err;
+               }
 
        if ( (rsa->flags & RSA_FLAG_EXT_PKEY) ||
                ((rsa->p != NULL) &&
@@ -439,7 +453,7 @@ static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
                }
 
        if (blinding)
-               if (!rsa_blinding_invert(blinding, local_blinding, ret, br, ctx))
+               if (!rsa_blinding_invert(blinding, ret, unblind, ctx))
                        goto err;
 
        if (padding == RSA_X931_PADDING)
@@ -478,18 +492,21 @@ err:
 static int RSA_eay_private_decrypt(int flen, const unsigned char *from,
             unsigned char *to, RSA *rsa, int padding)
        {
-       BIGNUM *f, *ret, *br;
+       BIGNUM *f, *ret;
        int j,num=0,r= -1;
        unsigned char *p;
        unsigned char *buf=NULL;
        BN_CTX *ctx=NULL;
        int local_blinding = 0;
+       /* Used only if the blinding structure is shared. A non-NULL unblind
+        * instructs rsa_blinding_convert() and rsa_blinding_invert() to store
+        * the unblinding factor outside the blinding structure. */
+       BIGNUM *unblind = NULL;
        BN_BLINDING *blinding = NULL;
 
        if((ctx = BN_CTX_new()) == NULL) goto err;
        BN_CTX_start(ctx);
        f   = BN_CTX_get(ctx);
-       br  = BN_CTX_get(ctx);
        ret = BN_CTX_get(ctx);
        num = BN_num_bytes(rsa->n);
        buf = OPENSSL_malloc(num);
@@ -527,8 +544,15 @@ static int RSA_eay_private_decrypt(int flen, const unsigned char *from,
                }
        
        if (blinding != NULL)
-               if (!rsa_blinding_convert(blinding, local_blinding, f, br, ctx))
+               {
+               if (!local_blinding && ((unblind = BN_CTX_get(ctx)) == NULL))
+                       {
+                       RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,ERR_R_MALLOC_FAILURE);
                        goto err;
+                       }
+               if (!rsa_blinding_convert(blinding, f, unblind, ctx))
+                       goto err;
+               }
 
        /* do the decrypt */
        if ( (rsa->flags & RSA_FLAG_EXT_PKEY) ||
@@ -562,7 +586,7 @@ static int RSA_eay_private_decrypt(int flen, const unsigned char *from,
                }
 
        if (blinding)
-               if (!rsa_blinding_invert(blinding, local_blinding, ret, br, ctx))
+               if (!rsa_blinding_invert(blinding, ret, unblind, ctx))
                        goto err;
 
        p=buf;
diff --git a/deps/openssl/openssl/crypto/rsa/rsa_eng.c b/deps/openssl/openssl/crypto/rsa/rsa_eng.c
deleted file mode 100644 (file)
index 2f21ddb..0000000
+++ /dev/null
@@ -1,357 +0,0 @@
-/* crypto/rsa/rsa_lib.c */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-#include <stdio.h>
-#include <openssl/crypto.h>
-#include "cryptlib.h"
-#include <openssl/lhash.h>
-#include <openssl/bn.h>
-#include <openssl/rsa.h>
-#include <openssl/rand.h>
-#ifndef OPENSSL_NO_ENGINE
-#include <openssl/engine.h>
-#endif
-
-const char RSA_version[]="RSA" OPENSSL_VERSION_PTEXT;
-
-static const RSA_METHOD *default_RSA_meth=NULL;
-
-RSA *RSA_new(void)
-       {
-       RSA *r=RSA_new_method(NULL);
-
-       return r;
-       }
-
-void RSA_set_default_method(const RSA_METHOD *meth)
-       {
-#ifdef OPENSSL_FIPS
-       if (FIPS_mode() && !(meth->flags & RSA_FLAG_FIPS_METHOD))
-               {
-               RSAerr(RSA_F_RSA_SET_DEFAULT_METHOD, RSA_R_NON_FIPS_METHOD);
-               return;
-               }
-#endif
-       default_RSA_meth = meth;
-       }
-
-const RSA_METHOD *RSA_get_default_method(void)
-       {
-       if (default_RSA_meth == NULL)
-               {
-#ifdef RSA_NULL
-               default_RSA_meth=RSA_null_method();
-#else
-#if 0 /* was: #ifdef RSAref */
-               default_RSA_meth=RSA_PKCS1_RSAref();
-#else
-               default_RSA_meth=RSA_PKCS1_SSLeay();
-#endif
-#endif
-               }
-
-       return default_RSA_meth;
-       }
-
-const RSA_METHOD *RSA_get_method(const RSA *rsa)
-       {
-       return rsa->meth;
-       }
-
-int RSA_set_method(RSA *rsa, const RSA_METHOD *meth)
-       {
-       /* NB: The caller is specifically setting a method, so it's not up to us
-        * to deal with which ENGINE it comes from. */
-       const RSA_METHOD *mtmp;
-#ifdef OPENSSL_FIPS
-       if (FIPS_mode() && !(meth->flags & RSA_FLAG_FIPS_METHOD))
-               {
-               RSAerr(RSA_F_RSA_SET_METHOD, RSA_R_NON_FIPS_METHOD);
-               return 0;
-               }
-#endif
-       mtmp = rsa->meth;
-       if (mtmp->finish) mtmp->finish(rsa);
-#ifndef OPENSSL_NO_ENGINE
-       if (rsa->engine)
-               {
-               ENGINE_finish(rsa->engine);
-               rsa->engine = NULL;
-               }
-#endif
-       rsa->meth = meth;
-       if (meth->init) meth->init(rsa);
-       return 1;
-       }
-
-RSA *RSA_new_method(ENGINE *engine)
-       {
-       RSA *ret;
-
-       ret=(RSA *)OPENSSL_malloc(sizeof(RSA));
-       if (ret == NULL)
-               {
-               RSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);
-               return NULL;
-               }
-
-       ret->meth = RSA_get_default_method();
-#ifndef OPENSSL_NO_ENGINE
-       if (engine)
-               {
-               if (!ENGINE_init(engine))
-                       {
-                       RSAerr(RSA_F_RSA_NEW_METHOD, ERR_R_ENGINE_LIB);
-                       OPENSSL_free(ret);
-                       return NULL;
-                       }
-               ret->engine = engine;
-               }
-       else
-               ret->engine = ENGINE_get_default_RSA();
-       if(ret->engine)
-               {
-               ret->meth = ENGINE_get_RSA(ret->engine);
-               if(!ret->meth)
-                       {
-                       RSAerr(RSA_F_RSA_NEW_METHOD,
-                               ERR_R_ENGINE_LIB);
-                       ENGINE_finish(ret->engine);
-                       OPENSSL_free(ret);
-                       return NULL;
-                       }
-               }
-#endif
-#ifdef OPENSSL_FIPS
-       if (FIPS_mode() && !(ret->meth->flags & RSA_FLAG_FIPS_METHOD))
-               {
-               RSAerr(RSA_F_RSA_NEW_METHOD, RSA_R_NON_FIPS_METHOD);
-#ifndef OPENSSL_NO_ENGINE
-               if (ret->engine)
-                       ENGINE_finish(ret->engine);
-#endif
-               OPENSSL_free(ret);
-               return NULL;
-               }
-#endif
-
-       ret->pad=0;
-       ret->version=0;
-       ret->n=NULL;
-       ret->e=NULL;
-       ret->d=NULL;
-       ret->p=NULL;
-       ret->q=NULL;
-       ret->dmp1=NULL;
-       ret->dmq1=NULL;
-       ret->iqmp=NULL;
-       ret->references=1;
-       ret->_method_mod_n=NULL;
-       ret->_method_mod_p=NULL;
-       ret->_method_mod_q=NULL;
-       ret->blinding=NULL;
-       ret->mt_blinding=NULL;
-       ret->bignum_data=NULL;
-       ret->flags=ret->meth->flags & ~RSA_FLAG_NON_FIPS_ALLOW;
-       if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data))
-               {
-#ifndef OPENSSL_NO_ENGINE
-       if (ret->engine)
-               ENGINE_finish(ret->engine);
-#endif
-               OPENSSL_free(ret);
-               return(NULL);
-               }
-
-       if ((ret->meth->init != NULL) && !ret->meth->init(ret))
-               {
-#ifndef OPENSSL_NO_ENGINE
-               if (ret->engine)
-                       ENGINE_finish(ret->engine);
-#endif
-               CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);
-               OPENSSL_free(ret);
-               ret=NULL;
-               }
-       return(ret);
-       }
-
-void RSA_free(RSA *r)
-       {
-       int i;
-
-       if (r == NULL) return;
-
-       i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_RSA);
-#ifdef REF_PRINT
-       REF_PRINT("RSA",r);
-#endif
-       if (i > 0) return;
-#ifdef REF_CHECK
-       if (i < 0)
-               {
-               fprintf(stderr,"RSA_free, bad reference count\n");
-               abort();
-               }
-#endif
-
-       if (r->meth->finish)
-               r->meth->finish(r);
-#ifndef OPENSSL_NO_ENGINE
-       if (r->engine)
-               ENGINE_finish(r->engine);
-#endif
-
-       CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, r, &r->ex_data);
-
-       if (r->n != NULL) BN_clear_free(r->n);
-       if (r->e != NULL) BN_clear_free(r->e);
-       if (r->d != NULL) BN_clear_free(r->d);
-       if (r->p != NULL) BN_clear_free(r->p);
-       if (r->q != NULL) BN_clear_free(r->q);
-       if (r->dmp1 != NULL) BN_clear_free(r->dmp1);
-       if (r->dmq1 != NULL) BN_clear_free(r->dmq1);
-       if (r->iqmp != NULL) BN_clear_free(r->iqmp);
-       if (r->blinding != NULL) BN_BLINDING_free(r->blinding);
-       if (r->mt_blinding != NULL) BN_BLINDING_free(r->mt_blinding);
-       if (r->bignum_data != NULL) OPENSSL_free_locked(r->bignum_data);
-       OPENSSL_free(r);
-       }
-
-int RSA_up_ref(RSA *r)
-       {
-       int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_RSA);
-#ifdef REF_PRINT
-       REF_PRINT("RSA",r);
-#endif
-#ifdef REF_CHECK
-       if (i < 2)
-               {
-               fprintf(stderr, "RSA_up_ref, bad reference count\n");
-               abort();
-               }
-#endif
-       return ((i > 1) ? 1 : 0);
-       }
-
-int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
-            CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
-        {
-       return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_RSA, argl, argp,
-                               new_func, dup_func, free_func);
-        }
-
-int RSA_set_ex_data(RSA *r, int idx, void *arg)
-       {
-       return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
-       }
-
-void *RSA_get_ex_data(const RSA *r, int idx)
-       {
-       return(CRYPTO_get_ex_data(&r->ex_data,idx));
-       }
-
-int RSA_flags(const RSA *r)
-       {
-       return((r == NULL)?0:r->meth->flags);
-       }
-
-int RSA_memory_lock(RSA *r)
-       {
-       int i,j,k,off;
-       char *p;
-       BIGNUM *bn,**t[6],*b;
-       BN_ULONG *ul;
-
-       if (r->d == NULL) return(1);
-       t[0]= &r->d;
-       t[1]= &r->p;
-       t[2]= &r->q;
-       t[3]= &r->dmp1;
-       t[4]= &r->dmq1;
-       t[5]= &r->iqmp;
-       k=sizeof(BIGNUM)*6;
-       off=k/sizeof(BN_ULONG)+1;
-       j=1;
-       for (i=0; i<6; i++)
-               j+= (*t[i])->top;
-       if ((p=OPENSSL_malloc_locked((off+j)*sizeof(BN_ULONG))) == NULL)
-               {
-               RSAerr(RSA_F_RSA_MEMORY_LOCK,ERR_R_MALLOC_FAILURE);
-               return(0);
-               }
-       bn=(BIGNUM *)p;
-       ul=(BN_ULONG *)&(p[off]);
-       for (i=0; i<6; i++)
-               {
-               b= *(t[i]);
-               *(t[i])= &(bn[i]);
-               memcpy((char *)&(bn[i]),(char *)b,sizeof(BIGNUM));
-               bn[i].flags=BN_FLG_STATIC_DATA;
-               bn[i].d=ul;
-               memcpy((char *)ul,b->d,sizeof(BN_ULONG)*b->top);
-               ul+=b->top;
-               BN_clear_free(b);
-               }
-       
-       /* I should fix this so it can still be done */
-       r->flags&= ~(RSA_FLAG_CACHE_PRIVATE|RSA_FLAG_CACHE_PUBLIC);
-
-       r->bignum_data=p;
-       return(1);
-       }
index 501f5ea..cf9f110 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/rsa/rsa_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2007 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2008 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 static ERR_STRING_DATA RSA_str_functs[]=
        {
-{ERR_FUNC(RSA_F_FIPS_RSA_SIGN),        "FIPS_RSA_SIGN"},
-{ERR_FUNC(RSA_F_FIPS_RSA_VERIFY),      "FIPS_RSA_VERIFY"},
+{ERR_FUNC(RSA_F_CHECK_PADDING_MD),     "CHECK_PADDING_MD"},
+{ERR_FUNC(RSA_F_DO_RSA_PRINT), "DO_RSA_PRINT"},
+{ERR_FUNC(RSA_F_INT_RSA_VERIFY),       "INT_RSA_VERIFY"},
 {ERR_FUNC(RSA_F_MEMORY_LOCK),  "MEMORY_LOCK"},
+{ERR_FUNC(RSA_F_OLD_RSA_PRIV_DECODE),  "OLD_RSA_PRIV_DECODE"},
+{ERR_FUNC(RSA_F_PKEY_RSA_CTRL),        "PKEY_RSA_CTRL"},
+{ERR_FUNC(RSA_F_PKEY_RSA_CTRL_STR),    "PKEY_RSA_CTRL_STR"},
+{ERR_FUNC(RSA_F_PKEY_RSA_SIGN),        "PKEY_RSA_SIGN"},
+{ERR_FUNC(RSA_F_PKEY_RSA_VERIFYRECOVER),       "PKEY_RSA_VERIFYRECOVER"},
 {ERR_FUNC(RSA_F_RSA_BUILTIN_KEYGEN),   "RSA_BUILTIN_KEYGEN"},
 {ERR_FUNC(RSA_F_RSA_CHECK_KEY),        "RSA_check_key"},
 {ERR_FUNC(RSA_F_RSA_EAY_PRIVATE_DECRYPT),      "RSA_EAY_PRIVATE_DECRYPT"},
@@ -103,11 +109,10 @@ static ERR_STRING_DATA RSA_str_functs[]=
 {ERR_FUNC(RSA_F_RSA_PADDING_CHECK_X931),       "RSA_padding_check_X931"},
 {ERR_FUNC(RSA_F_RSA_PRINT),    "RSA_print"},
 {ERR_FUNC(RSA_F_RSA_PRINT_FP), "RSA_print_fp"},
-{ERR_FUNC(RSA_F_RSA_PRIVATE_ENCRYPT),  "RSA_private_encrypt"},
-{ERR_FUNC(RSA_F_RSA_PUBLIC_DECRYPT),   "RSA_public_decrypt"},
+{ERR_FUNC(RSA_F_RSA_PRIV_DECODE),      "RSA_PRIV_DECODE"},
+{ERR_FUNC(RSA_F_RSA_PRIV_ENCODE),      "RSA_PRIV_ENCODE"},
+{ERR_FUNC(RSA_F_RSA_PUB_DECODE),       "RSA_PUB_DECODE"},
 {ERR_FUNC(RSA_F_RSA_SETUP_BLINDING),   "RSA_setup_blinding"},
-{ERR_FUNC(RSA_F_RSA_SET_DEFAULT_METHOD),       "RSA_set_default_method"},
-{ERR_FUNC(RSA_F_RSA_SET_METHOD),       "RSA_set_method"},
 {ERR_FUNC(RSA_F_RSA_SIGN),     "RSA_sign"},
 {ERR_FUNC(RSA_F_RSA_SIGN_ASN1_OCTET_STRING),   "RSA_sign_ASN1_OCTET_STRING"},
 {ERR_FUNC(RSA_F_RSA_VERIFY),   "RSA_verify"},
@@ -136,20 +141,25 @@ static ERR_STRING_DATA RSA_str_reasons[]=
 {ERR_REASON(RSA_R_DMQ1_NOT_CONGRUENT_TO_D),"dmq1 not congruent to d"},
 {ERR_REASON(RSA_R_D_E_NOT_CONGRUENT_TO_1),"d e not congruent to 1"},
 {ERR_REASON(RSA_R_FIRST_OCTET_INVALID)   ,"first octet invalid"},
+{ERR_REASON(RSA_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE),"illegal or unsupported padding mode"},
+{ERR_REASON(RSA_R_INVALID_DIGEST_LENGTH) ,"invalid digest length"},
 {ERR_REASON(RSA_R_INVALID_HEADER)        ,"invalid header"},
+{ERR_REASON(RSA_R_INVALID_KEYBITS)       ,"invalid keybits"},
 {ERR_REASON(RSA_R_INVALID_MESSAGE_LENGTH),"invalid message length"},
 {ERR_REASON(RSA_R_INVALID_PADDING)       ,"invalid padding"},
+{ERR_REASON(RSA_R_INVALID_PADDING_MODE)  ,"invalid padding mode"},
+{ERR_REASON(RSA_R_INVALID_PSS_SALTLEN)   ,"invalid pss saltlen"},
 {ERR_REASON(RSA_R_INVALID_TRAILER)       ,"invalid trailer"},
+{ERR_REASON(RSA_R_INVALID_X931_DIGEST)   ,"invalid x931 digest"},
 {ERR_REASON(RSA_R_IQMP_NOT_INVERSE_OF_Q) ,"iqmp not inverse of q"},
 {ERR_REASON(RSA_R_KEY_SIZE_TOO_SMALL)    ,"key size too small"},
 {ERR_REASON(RSA_R_LAST_OCTET_INVALID)    ,"last octet invalid"},
 {ERR_REASON(RSA_R_MODULUS_TOO_LARGE)     ,"modulus too large"},
-{ERR_REASON(RSA_R_NON_FIPS_METHOD)       ,"non fips method"},
 {ERR_REASON(RSA_R_NO_PUBLIC_EXPONENT)    ,"no public exponent"},
 {ERR_REASON(RSA_R_NULL_BEFORE_BLOCK_MISSING),"null before block missing"},
 {ERR_REASON(RSA_R_N_DOES_NOT_EQUAL_P_Q)  ,"n does not equal p q"},
 {ERR_REASON(RSA_R_OAEP_DECODING_ERROR)   ,"oaep decoding error"},
-{ERR_REASON(RSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE),"operation not allowed in fips mode"},
+{ERR_REASON(RSA_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE),"operation not supported for this keytype"},
 {ERR_REASON(RSA_R_PADDING_CHECK_FAILED)  ,"padding check failed"},
 {ERR_REASON(RSA_R_P_NOT_PRIME)           ,"p not prime"},
 {ERR_REASON(RSA_R_Q_NOT_PRIME)           ,"q not prime"},
@@ -160,6 +170,7 @@ static ERR_STRING_DATA RSA_str_reasons[]=
 {ERR_REASON(RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD),"the asn1 object identifier is not known for this md"},
 {ERR_REASON(RSA_R_UNKNOWN_ALGORITHM_TYPE),"unknown algorithm type"},
 {ERR_REASON(RSA_R_UNKNOWN_PADDING_TYPE)  ,"unknown padding type"},
+{ERR_REASON(RSA_R_VALUE_MISSING)         ,"value missing"},
 {ERR_REASON(RSA_R_WRONG_SIGNATURE_LENGTH),"wrong signature length"},
 {0,NULL}
        };
index 41278f8..767f7ab 100644 (file)
@@ -68,8 +68,6 @@
 #include <openssl/bn.h>
 #include <openssl/rsa.h>
 
-#ifndef OPENSSL_FIPS
-
 static int rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb);
 
 /* NB: this wrapper would normally be placed in rsa_lib.c and the static
@@ -219,4 +217,3 @@ err:
        return ok;
        }
 
-#endif
index 5714841..de45088 100644 (file)
 #include <openssl/engine.h>
 #endif
 
+const char RSA_version[]="RSA" OPENSSL_VERSION_PTEXT;
+
+static const RSA_METHOD *default_RSA_meth=NULL;
+
+RSA *RSA_new(void)
+       {
+       RSA *r=RSA_new_method(NULL);
+
+       return r;
+       }
+
+void RSA_set_default_method(const RSA_METHOD *meth)
+       {
+       default_RSA_meth = meth;
+       }
+
+const RSA_METHOD *RSA_get_default_method(void)
+       {
+       if (default_RSA_meth == NULL)
+               {
+#ifdef RSA_NULL
+               default_RSA_meth=RSA_null_method();
+#else
+#if 0 /* was: #ifdef RSAref */
+               default_RSA_meth=RSA_PKCS1_RSAref();
+#else
+               default_RSA_meth=RSA_PKCS1_SSLeay();
+#endif
+#endif
+               }
+
+       return default_RSA_meth;
+       }
+
+const RSA_METHOD *RSA_get_method(const RSA *rsa)
+       {
+       return rsa->meth;
+       }
+
+int RSA_set_method(RSA *rsa, const RSA_METHOD *meth)
+       {
+       /* NB: The caller is specifically setting a method, so it's not up to us
+        * to deal with which ENGINE it comes from. */
+       const RSA_METHOD *mtmp;
+       mtmp = rsa->meth;
+       if (mtmp->finish) mtmp->finish(rsa);
+#ifndef OPENSSL_NO_ENGINE
+       if (rsa->engine)
+               {
+               ENGINE_finish(rsa->engine);
+               rsa->engine = NULL;
+               }
+#endif
+       rsa->meth = meth;
+       if (meth->init) meth->init(rsa);
+       return 1;
+       }
+
+RSA *RSA_new_method(ENGINE *engine)
+       {
+       RSA *ret;
+
+       ret=(RSA *)OPENSSL_malloc(sizeof(RSA));
+       if (ret == NULL)
+               {
+               RSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);
+               return NULL;
+               }
+
+       ret->meth = RSA_get_default_method();
+#ifndef OPENSSL_NO_ENGINE
+       if (engine)
+               {
+               if (!ENGINE_init(engine))
+                       {
+                       RSAerr(RSA_F_RSA_NEW_METHOD, ERR_R_ENGINE_LIB);
+                       OPENSSL_free(ret);
+                       return NULL;
+                       }
+               ret->engine = engine;
+               }
+       else
+               ret->engine = ENGINE_get_default_RSA();
+       if(ret->engine)
+               {
+               ret->meth = ENGINE_get_RSA(ret->engine);
+               if(!ret->meth)
+                       {
+                       RSAerr(RSA_F_RSA_NEW_METHOD,
+                               ERR_R_ENGINE_LIB);
+                       ENGINE_finish(ret->engine);
+                       OPENSSL_free(ret);
+                       return NULL;
+                       }
+               }
+#endif
+
+       ret->pad=0;
+       ret->version=0;
+       ret->n=NULL;
+       ret->e=NULL;
+       ret->d=NULL;
+       ret->p=NULL;
+       ret->q=NULL;
+       ret->dmp1=NULL;
+       ret->dmq1=NULL;
+       ret->iqmp=NULL;
+       ret->references=1;
+       ret->_method_mod_n=NULL;
+       ret->_method_mod_p=NULL;
+       ret->_method_mod_q=NULL;
+       ret->blinding=NULL;
+       ret->mt_blinding=NULL;
+       ret->bignum_data=NULL;
+       ret->flags=ret->meth->flags;
+       if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data))
+               {
+#ifndef OPENSSL_NO_ENGINE
+       if (ret->engine)
+               ENGINE_finish(ret->engine);
+#endif
+               OPENSSL_free(ret);
+               return(NULL);
+               }
+
+       if ((ret->meth->init != NULL) && !ret->meth->init(ret))
+               {
+#ifndef OPENSSL_NO_ENGINE
+               if (ret->engine)
+                       ENGINE_finish(ret->engine);
+#endif
+               CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);
+               OPENSSL_free(ret);
+               ret=NULL;
+               }
+       return(ret);
+       }
+
+void RSA_free(RSA *r)
+       {
+       int i;
+
+       if (r == NULL) return;
+
+       i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_RSA);
+#ifdef REF_PRINT
+       REF_PRINT("RSA",r);
+#endif
+       if (i > 0) return;
+#ifdef REF_CHECK
+       if (i < 0)
+               {
+               fprintf(stderr,"RSA_free, bad reference count\n");
+               abort();
+               }
+#endif
+
+       if (r->meth->finish)
+               r->meth->finish(r);
+#ifndef OPENSSL_NO_ENGINE
+       if (r->engine)
+               ENGINE_finish(r->engine);
+#endif
+
+       CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, r, &r->ex_data);
+
+       if (r->n != NULL) BN_clear_free(r->n);
+       if (r->e != NULL) BN_clear_free(r->e);
+       if (r->d != NULL) BN_clear_free(r->d);
+       if (r->p != NULL) BN_clear_free(r->p);
+       if (r->q != NULL) BN_clear_free(r->q);
+       if (r->dmp1 != NULL) BN_clear_free(r->dmp1);
+       if (r->dmq1 != NULL) BN_clear_free(r->dmq1);
+       if (r->iqmp != NULL) BN_clear_free(r->iqmp);
+       if (r->blinding != NULL) BN_BLINDING_free(r->blinding);
+       if (r->mt_blinding != NULL) BN_BLINDING_free(r->mt_blinding);
+       if (r->bignum_data != NULL) OPENSSL_free_locked(r->bignum_data);
+       OPENSSL_free(r);
+       }
+
+int RSA_up_ref(RSA *r)
+       {
+       int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_RSA);
+#ifdef REF_PRINT
+       REF_PRINT("RSA",r);
+#endif
+#ifdef REF_CHECK
+       if (i < 2)
+               {
+               fprintf(stderr, "RSA_up_ref, bad reference count\n");
+               abort();
+               }
+#endif
+       return ((i > 1) ? 1 : 0);
+       }
+
+int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
+            CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
+        {
+       return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_RSA, argl, argp,
+                               new_func, dup_func, free_func);
+        }
+
+int RSA_set_ex_data(RSA *r, int idx, void *arg)
+       {
+       return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
+       }
+
+void *RSA_get_ex_data(const RSA *r, int idx)
+       {
+       return(CRYPTO_get_ex_data(&r->ex_data,idx));
+       }
+
+int RSA_size(const RSA *r)
+       {
+       return(BN_num_bytes(r->n));
+       }
+
 int RSA_public_encrypt(int flen, const unsigned char *from, unsigned char *to,
             RSA *rsa, int padding)
        {
@@ -76,13 +294,6 @@ int RSA_public_encrypt(int flen, const unsigned char *from, unsigned char *to,
 int RSA_private_encrypt(int flen, const unsigned char *from, unsigned char *to,
             RSA *rsa, int padding)
        {
-#ifdef OPENSSL_FIPS
-       if(FIPS_mode() && !(rsa->flags & RSA_FLAG_NON_FIPS_ALLOW))
-               {
-               RSAerr(RSA_F_RSA_PRIVATE_ENCRYPT, RSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE);
-               return 0;
-               }
-#endif
        return(rsa->meth->rsa_priv_enc(flen, from, to, rsa, padding));
        }
 
@@ -95,19 +306,12 @@ int RSA_private_decrypt(int flen, const unsigned char *from, unsigned char *to,
 int RSA_public_decrypt(int flen, const unsigned char *from, unsigned char *to,
             RSA *rsa, int padding)
        {
-#ifdef OPENSSL_FIPS
-       if(FIPS_mode() && !(rsa->flags & RSA_FLAG_NON_FIPS_ALLOW))
-               {
-               RSAerr(RSA_F_RSA_PUBLIC_DECRYPT, RSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE);
-               return 0;
-               }
-#endif
        return(rsa->meth->rsa_pub_dec(flen, from, to, rsa, padding));
        }
 
-int RSA_size(const RSA *r)
+int RSA_flags(const RSA *r)
        {
-       return(BN_num_bytes(r->n));
+       return((r == NULL)?0:r->meth->flags);
        }
 
 void RSA_blinding_off(RSA *rsa)
@@ -222,7 +426,7 @@ BN_BLINDING *RSA_setup_blinding(RSA *rsa, BN_CTX *in_ctx)
                RSAerr(RSA_F_RSA_SETUP_BLINDING, ERR_R_BN_LIB);
                goto err;
                }
-       BN_BLINDING_set_thread_id(ret, CRYPTO_thread_id());
+       CRYPTO_THREADID_current(BN_BLINDING_thread_id(ret));
 err:
        BN_CTX_end(ctx);
        if (in_ctx == NULL)
@@ -232,3 +436,48 @@ err:
 
        return ret;
 }
+
+int RSA_memory_lock(RSA *r)
+       {
+       int i,j,k,off;
+       char *p;
+       BIGNUM *bn,**t[6],*b;
+       BN_ULONG *ul;
+
+       if (r->d == NULL) return(1);
+       t[0]= &r->d;
+       t[1]= &r->p;
+       t[2]= &r->q;
+       t[3]= &r->dmp1;
+       t[4]= &r->dmq1;
+       t[5]= &r->iqmp;
+       k=sizeof(BIGNUM)*6;
+       off=k/sizeof(BN_ULONG)+1;
+       j=1;
+       for (i=0; i<6; i++)
+               j+= (*t[i])->top;
+       if ((p=OPENSSL_malloc_locked((off+j)*sizeof(BN_ULONG))) == NULL)
+               {
+               RSAerr(RSA_F_RSA_MEMORY_LOCK,ERR_R_MALLOC_FAILURE);
+               return(0);
+               }
+       bn=(BIGNUM *)p;
+       ul=(BN_ULONG *)&(p[off]);
+       for (i=0; i<6; i++)
+               {
+               b= *(t[i]);
+               *(t[i])= &(bn[i]);
+               memcpy((char *)&(bn[i]),(char *)b,sizeof(BIGNUM));
+               bn[i].flags=BN_FLG_STATIC_DATA;
+               bn[i].d=ul;
+               memcpy((char *)ul,b->d,sizeof(BN_ULONG)*b->top);
+               ul+=b->top;
+               BN_clear_free(b);
+               }
+       
+       /* I should fix this so it can still be done */
+       r->flags&= ~(RSA_FLAG_CACHE_PRIVATE|RSA_FLAG_CACHE_PUBLIC);
+
+       r->bignum_data=p;
+       return(1);
+       }
diff --git a/deps/openssl/openssl/crypto/rsa/rsa_locl.h b/deps/openssl/openssl/crypto/rsa/rsa_locl.h
new file mode 100644 (file)
index 0000000..f5d2d56
--- /dev/null
@@ -0,0 +1,4 @@
+extern int int_rsa_verify(int dtype, const unsigned char *m, unsigned int m_len,
+               unsigned char *rm, size_t *prm_len,
+               const unsigned char *sigbuf, size_t siglen,
+               RSA *rsa);
index 546ae5f..18d307e 100644 (file)
@@ -28,7 +28,7 @@
 #include <openssl/rand.h>
 #include <openssl/sha.h>
 
-int MGF1(unsigned char *mask, long len,
+static int MGF1(unsigned char *mask, long len,
        const unsigned char *seed, long seedlen);
 
 int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
@@ -76,11 +76,13 @@ int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
                return 0;
                }
 
-       MGF1(dbmask, emlen - SHA_DIGEST_LENGTH, seed, SHA_DIGEST_LENGTH);
+       if (MGF1(dbmask, emlen - SHA_DIGEST_LENGTH, seed, SHA_DIGEST_LENGTH) < 0)
+               return 0;
        for (i = 0; i < emlen - SHA_DIGEST_LENGTH; i++)
                db[i] ^= dbmask[i];
 
-       MGF1(seedmask, SHA_DIGEST_LENGTH, db, emlen - SHA_DIGEST_LENGTH);
+       if (MGF1(seedmask, SHA_DIGEST_LENGTH, db, emlen - SHA_DIGEST_LENGTH) < 0)
+               return 0;
        for (i = 0; i < SHA_DIGEST_LENGTH; i++)
                seed[i] ^= seedmask[i];
 
@@ -133,11 +135,13 @@ int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
 
        maskeddb = padded_from + SHA_DIGEST_LENGTH;
 
-       MGF1(seed, SHA_DIGEST_LENGTH, maskeddb, dblen);
+       if (MGF1(seed, SHA_DIGEST_LENGTH, maskeddb, dblen))
+               return -1;
        for (i = 0; i < SHA_DIGEST_LENGTH; i++)
                seed[i] ^= padded_from[i];
   
-       MGF1(db, dblen, seed, SHA_DIGEST_LENGTH);
+       if (MGF1(db, dblen, seed, SHA_DIGEST_LENGTH))
+               return -1;
        for (i = 0; i < dblen; i++)
                db[i] ^= maskeddb[i];
 
@@ -185,35 +189,44 @@ int PKCS1_MGF1(unsigned char *mask, long len,
        EVP_MD_CTX c;
        unsigned char md[EVP_MAX_MD_SIZE];
        int mdlen;
+       int rv = -1;
 
        EVP_MD_CTX_init(&c);
-       mdlen = M_EVP_MD_size(dgst);
+       mdlen = EVP_MD_size(dgst);
+       if (mdlen < 0)
+               goto err;
        for (i = 0; outlen < len; i++)
                {
                cnt[0] = (unsigned char)((i >> 24) & 255);
                cnt[1] = (unsigned char)((i >> 16) & 255);
                cnt[2] = (unsigned char)((i >> 8)) & 255;
                cnt[3] = (unsigned char)(i & 255);
-               EVP_DigestInit_ex(&c,dgst, NULL);
-               EVP_DigestUpdate(&c, seed, seedlen);
-               EVP_DigestUpdate(&c, cnt, 4);
+               if (!EVP_DigestInit_ex(&c,dgst, NULL)
+                       || !EVP_DigestUpdate(&c, seed, seedlen)
+                       || !EVP_DigestUpdate(&c, cnt, 4))
+                       goto err;
                if (outlen + mdlen <= len)
                        {
-                       EVP_DigestFinal_ex(&c, mask + outlen, NULL);
+                       if (!EVP_DigestFinal_ex(&c, mask + outlen, NULL))
+                               goto err;
                        outlen += mdlen;
                        }
                else
                        {
-                       EVP_DigestFinal_ex(&c, md, NULL);
+                       if (!EVP_DigestFinal_ex(&c, md, NULL))
+                               goto err;
                        memcpy(mask + outlen, md, len - outlen);
                        outlen = len;
                        }
                }
+       rv = 0;
+       err:
        EVP_MD_CTX_cleanup(&c);
-       return 0;
+       return rv;
        }
 
-int MGF1(unsigned char *mask, long len, const unsigned char *seed, long seedlen)
+static int MGF1(unsigned char *mask, long len, const unsigned char *seed,
+                long seedlen)
        {
        return PKCS1_MGF1(mask, len, seed, seedlen, EVP_sha1());
        }
diff --git a/deps/openssl/openssl/crypto/rsa/rsa_pmeth.c b/deps/openssl/openssl/crypto/rsa/rsa_pmeth.c
new file mode 100644 (file)
index 0000000..c6892ec
--- /dev/null
@@ -0,0 +1,587 @@
+/* crypto/rsa/rsa_pmeth.c */
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project 2006.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include "cryptlib.h"
+#include <openssl/asn1t.h>
+#include <openssl/x509.h>
+#include <openssl/rsa.h>
+#include <openssl/bn.h>
+#include <openssl/evp.h>
+#include "evp_locl.h"
+#include "rsa_locl.h"
+
+/* RSA pkey context structure */
+
+typedef struct
+       {
+       /* Key gen parameters */
+       int nbits;
+       BIGNUM *pub_exp;
+       /* Keygen callback info */
+       int gentmp[2];
+       /* RSA padding mode */
+       int pad_mode;
+       /* message digest */
+       const EVP_MD *md;
+       /* PSS/OAEP salt length */
+       int saltlen;
+       /* Temp buffer */
+       unsigned char *tbuf;
+       } RSA_PKEY_CTX;
+
+static int pkey_rsa_init(EVP_PKEY_CTX *ctx)
+       {
+       RSA_PKEY_CTX *rctx;
+       rctx = OPENSSL_malloc(sizeof(RSA_PKEY_CTX));
+       if (!rctx)
+               return 0;
+       rctx->nbits = 1024;
+       rctx->pub_exp = NULL;
+       rctx->pad_mode = RSA_PKCS1_PADDING;
+       rctx->md = NULL;
+       rctx->tbuf = NULL;
+
+       rctx->saltlen = -2;
+
+       ctx->data = rctx;
+       ctx->keygen_info = rctx->gentmp;
+       ctx->keygen_info_count = 2;
+       
+       return 1;
+       }
+
+static int pkey_rsa_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
+       {
+       RSA_PKEY_CTX *dctx, *sctx;
+       if (!pkey_rsa_init(dst))
+               return 0;
+               sctx = src->data;
+       dctx = dst->data;
+       dctx->nbits = sctx->nbits;
+       if (sctx->pub_exp)
+               {
+               dctx->pub_exp = BN_dup(sctx->pub_exp);
+               if (!dctx->pub_exp)
+                       return 0;
+               }
+       dctx->pad_mode = sctx->pad_mode;
+       dctx->md = sctx->md;
+       return 1;
+       }
+
+static int setup_tbuf(RSA_PKEY_CTX *ctx, EVP_PKEY_CTX *pk)
+       {
+       if (ctx->tbuf)
+               return 1;
+       ctx->tbuf = OPENSSL_malloc(EVP_PKEY_size(pk->pkey));
+       if (!ctx->tbuf)
+               return 0;
+       return 1;
+       }
+
+static void pkey_rsa_cleanup(EVP_PKEY_CTX *ctx)
+       {
+       RSA_PKEY_CTX *rctx = ctx->data;
+       if (rctx)
+               {
+               if (rctx->pub_exp)
+                       BN_free(rctx->pub_exp);
+               if (rctx->tbuf)
+                       OPENSSL_free(rctx->tbuf);
+               OPENSSL_free(rctx);
+               }
+       }
+
+static int pkey_rsa_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
+                                       const unsigned char *tbs, size_t tbslen)
+       {
+       int ret;
+       RSA_PKEY_CTX *rctx = ctx->data;
+       RSA *rsa = ctx->pkey->pkey.rsa;
+
+       if (rctx->md)
+               {
+               if (tbslen != (size_t)EVP_MD_size(rctx->md))
+                       {
+                       RSAerr(RSA_F_PKEY_RSA_SIGN,
+                                       RSA_R_INVALID_DIGEST_LENGTH);
+                       return -1;
+                       }
+               if (rctx->pad_mode == RSA_X931_PADDING)
+                       {
+                       if (!setup_tbuf(rctx, ctx))
+                               return -1;
+                       memcpy(rctx->tbuf, tbs, tbslen);
+                       rctx->tbuf[tbslen] =
+                               RSA_X931_hash_id(EVP_MD_type(rctx->md));
+                       ret = RSA_private_encrypt(tbslen + 1, rctx->tbuf,
+                                               sig, rsa, RSA_X931_PADDING);
+                       }
+               else if (rctx->pad_mode == RSA_PKCS1_PADDING)
+                       {
+                       unsigned int sltmp;
+                       ret = RSA_sign(EVP_MD_type(rctx->md),
+                                               tbs, tbslen, sig, &sltmp, rsa);
+                       if (ret <= 0)
+                               return ret;
+                       ret = sltmp;
+                       }
+               else if (rctx->pad_mode == RSA_PKCS1_PSS_PADDING)
+                       {
+                       if (!setup_tbuf(rctx, ctx))
+                               return -1;
+                       if (!RSA_padding_add_PKCS1_PSS(rsa, rctx->tbuf, tbs,
+                                               rctx->md, rctx->saltlen))
+                               return -1;
+                       ret = RSA_private_encrypt(RSA_size(rsa), rctx->tbuf,
+                                               sig, rsa, RSA_NO_PADDING);
+                       }
+               else
+                       return -1;
+               }
+       else
+               ret = RSA_private_encrypt(tbslen, tbs, sig, ctx->pkey->pkey.rsa,
+                                                       rctx->pad_mode);
+       if (ret < 0)
+               return ret;
+       *siglen = ret;
+       return 1;
+       }
+
+
+static int pkey_rsa_verifyrecover(EVP_PKEY_CTX *ctx,
+                                       unsigned char *rout, size_t *routlen,
+                                       const unsigned char *sig, size_t siglen)
+       {
+       int ret;
+       RSA_PKEY_CTX *rctx = ctx->data;
+
+       if (rctx->md)
+               {
+               if (rctx->pad_mode == RSA_X931_PADDING)
+                       {
+                       if (!setup_tbuf(rctx, ctx))
+                               return -1;
+                       ret = RSA_public_decrypt(siglen, sig,
+                                               rctx->tbuf, ctx->pkey->pkey.rsa,
+                                               RSA_X931_PADDING);
+                       if (ret < 1)
+                               return 0;
+                       ret--;
+                       if (rctx->tbuf[ret] !=
+                               RSA_X931_hash_id(EVP_MD_type(rctx->md)))
+                               {
+                               RSAerr(RSA_F_PKEY_RSA_VERIFYRECOVER,
+                                               RSA_R_ALGORITHM_MISMATCH);
+                               return 0;
+                               }
+                       if (ret != EVP_MD_size(rctx->md))
+                               {
+                               RSAerr(RSA_F_PKEY_RSA_VERIFYRECOVER,
+                                       RSA_R_INVALID_DIGEST_LENGTH);
+                               return 0;
+                               }
+                       if (rout)
+                               memcpy(rout, rctx->tbuf, ret);
+                       }
+               else if (rctx->pad_mode == RSA_PKCS1_PADDING)
+                       {
+                       size_t sltmp;
+                       ret = int_rsa_verify(EVP_MD_type(rctx->md),
+                                               NULL, 0, rout, &sltmp,
+                                       sig, siglen, ctx->pkey->pkey.rsa);
+                       if (ret <= 0)
+                               return 0;
+                       ret = sltmp;
+                       }
+               else
+                       return -1;
+               }
+       else
+               ret = RSA_public_decrypt(siglen, sig, rout, ctx->pkey->pkey.rsa,
+                                                       rctx->pad_mode);
+       if (ret < 0)
+               return ret;
+       *routlen = ret;
+       return 1;
+       }
+
+static int pkey_rsa_verify(EVP_PKEY_CTX *ctx,
+                                       const unsigned char *sig, size_t siglen,
+                                       const unsigned char *tbs, size_t tbslen)
+       {
+       RSA_PKEY_CTX *rctx = ctx->data;
+       RSA *rsa = ctx->pkey->pkey.rsa;
+       size_t rslen;
+       if (rctx->md)
+               {
+               if (rctx->pad_mode == RSA_PKCS1_PADDING)
+                       return RSA_verify(EVP_MD_type(rctx->md), tbs, tbslen,
+                                       sig, siglen, rsa);
+               if (rctx->pad_mode == RSA_X931_PADDING)
+                       {
+                       if (pkey_rsa_verifyrecover(ctx, NULL, &rslen,
+                                       sig, siglen) <= 0)
+                               return 0;
+                       }
+               else if (rctx->pad_mode == RSA_PKCS1_PSS_PADDING)
+                       {
+                       int ret;
+                       if (!setup_tbuf(rctx, ctx))
+                               return -1;
+                       ret = RSA_public_decrypt(siglen, sig, rctx->tbuf,
+                                                       rsa, RSA_NO_PADDING);
+                       if (ret <= 0)
+                               return 0;
+                       ret = RSA_verify_PKCS1_PSS(rsa, tbs, rctx->md,
+                                               rctx->tbuf, rctx->saltlen);
+                       if (ret <= 0)
+                               return 0;
+                       return 1;
+                       }
+               else
+                       return -1;
+               }
+       else
+               {
+               if (!setup_tbuf(rctx, ctx))
+                       return -1;
+               rslen = RSA_public_decrypt(siglen, sig, rctx->tbuf,
+                                               rsa, rctx->pad_mode);
+               if (rslen == 0)
+                       return 0;
+               }
+
+       if ((rslen != tbslen) || memcmp(tbs, rctx->tbuf, rslen))
+               return 0;
+
+       return 1;
+                       
+       }
+       
+
+static int pkey_rsa_encrypt(EVP_PKEY_CTX *ctx,
+                                       unsigned char *out, size_t *outlen,
+                                       const unsigned char *in, size_t inlen)
+       {
+       int ret;
+       RSA_PKEY_CTX *rctx = ctx->data;
+       ret = RSA_public_encrypt(inlen, in, out, ctx->pkey->pkey.rsa,
+                                                       rctx->pad_mode);
+       if (ret < 0)
+               return ret;
+       *outlen = ret;
+       return 1;
+       }
+
+static int pkey_rsa_decrypt(EVP_PKEY_CTX *ctx,
+                                       unsigned char *out, size_t *outlen,
+                                       const unsigned char *in, size_t inlen)
+       {
+       int ret;
+       RSA_PKEY_CTX *rctx = ctx->data;
+       ret = RSA_private_decrypt(inlen, in, out, ctx->pkey->pkey.rsa,
+                                                       rctx->pad_mode);
+       if (ret < 0)
+               return ret;
+       *outlen = ret;
+       return 1;
+       }
+
+static int check_padding_md(const EVP_MD *md, int padding)
+       {
+       if (!md)
+               return 1;
+
+       if (padding == RSA_NO_PADDING)
+               {
+               RSAerr(RSA_F_CHECK_PADDING_MD, RSA_R_INVALID_PADDING_MODE);
+               return 0;
+               }
+
+       if (padding == RSA_X931_PADDING)
+               {
+               if (RSA_X931_hash_id(EVP_MD_type(md)) == -1)
+                       {
+                       RSAerr(RSA_F_CHECK_PADDING_MD,
+                                               RSA_R_INVALID_X931_DIGEST);
+                       return 0;
+                       }
+               return 1;
+               }
+
+       return 1;
+       }
+                       
+
+static int pkey_rsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
+       {
+       RSA_PKEY_CTX *rctx = ctx->data;
+       switch (type)
+               {
+               case EVP_PKEY_CTRL_RSA_PADDING:
+               if ((p1 >= RSA_PKCS1_PADDING) && (p1 <= RSA_PKCS1_PSS_PADDING))
+                       {
+                       if (!check_padding_md(rctx->md, p1))
+                               return 0;
+                       if (p1 == RSA_PKCS1_PSS_PADDING) 
+                               {
+                               if (!(ctx->operation &
+                                    (EVP_PKEY_OP_SIGN | EVP_PKEY_OP_VERIFY)))
+                                       goto bad_pad;
+                               if (!rctx->md)
+                                       rctx->md = EVP_sha1();
+                               }
+                       if (p1 == RSA_PKCS1_OAEP_PADDING) 
+                               {
+                               if (!(ctx->operation & EVP_PKEY_OP_TYPE_CRYPT))
+                                       goto bad_pad;
+                               if (!rctx->md)
+                                       rctx->md = EVP_sha1();
+                               }
+                       rctx->pad_mode = p1;
+                       return 1;
+                       }
+               bad_pad:
+               RSAerr(RSA_F_PKEY_RSA_CTRL,
+                               RSA_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE);
+               return -2;
+
+               case EVP_PKEY_CTRL_RSA_PSS_SALTLEN:
+               if (p1 < -2)
+                       return -2;
+               if (rctx->pad_mode != RSA_PKCS1_PSS_PADDING)
+                       {
+                       RSAerr(RSA_F_PKEY_RSA_CTRL, RSA_R_INVALID_PSS_SALTLEN);
+                       return -2;
+                       }
+               rctx->saltlen = p1;
+               return 1;
+
+               case EVP_PKEY_CTRL_RSA_KEYGEN_BITS:
+               if (p1 < 256)
+                       {
+                       RSAerr(RSA_F_PKEY_RSA_CTRL, RSA_R_INVALID_KEYBITS);
+                       return -2;
+                       }
+               rctx->nbits = p1;
+               return 1;
+
+               case EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP:
+               if (!p2)
+                       return -2;
+               rctx->pub_exp = p2;
+               return 1;
+
+               case EVP_PKEY_CTRL_MD:
+               if (!check_padding_md(p2, rctx->pad_mode))
+                       return 0;
+               rctx->md = p2;
+               return 1;
+
+               case EVP_PKEY_CTRL_DIGESTINIT:
+               case EVP_PKEY_CTRL_PKCS7_ENCRYPT:
+               case EVP_PKEY_CTRL_PKCS7_DECRYPT:
+               case EVP_PKEY_CTRL_PKCS7_SIGN:
+#ifndef OPENSSL_NO_CMS
+               case EVP_PKEY_CTRL_CMS_ENCRYPT:
+               case EVP_PKEY_CTRL_CMS_DECRYPT:
+               case EVP_PKEY_CTRL_CMS_SIGN:
+#endif
+               return 1;
+               case EVP_PKEY_CTRL_PEER_KEY:
+                       RSAerr(RSA_F_PKEY_RSA_CTRL,
+                       RSA_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
+                       return -2;      
+
+               default:
+               return -2;
+
+               }
+       }
+                       
+static int pkey_rsa_ctrl_str(EVP_PKEY_CTX *ctx,
+                       const char *type, const char *value)
+       {
+       if (!value)
+               {
+               RSAerr(RSA_F_PKEY_RSA_CTRL_STR, RSA_R_VALUE_MISSING);
+               return 0;
+               }
+       if (!strcmp(type, "rsa_padding_mode"))
+               {
+               int pm;
+               if (!strcmp(value, "pkcs1"))
+                       pm = RSA_PKCS1_PADDING;
+               else if (!strcmp(value, "sslv23"))
+                       pm = RSA_SSLV23_PADDING;
+               else if (!strcmp(value, "none"))
+                       pm = RSA_NO_PADDING;
+               else if (!strcmp(value, "oeap"))
+                       pm = RSA_PKCS1_OAEP_PADDING;
+               else if (!strcmp(value, "x931"))
+                       pm = RSA_X931_PADDING;
+               else if (!strcmp(value, "pss"))
+                       pm = RSA_PKCS1_PSS_PADDING;
+               else
+                       {
+                       RSAerr(RSA_F_PKEY_RSA_CTRL_STR,
+                                               RSA_R_UNKNOWN_PADDING_TYPE);
+                       return -2;
+                       }
+               return EVP_PKEY_CTX_set_rsa_padding(ctx, pm);
+               }
+
+       if (!strcmp(type, "rsa_pss_saltlen"))
+               {
+               int saltlen;
+               saltlen = atoi(value);
+               return EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, saltlen);
+               }
+
+       if (!strcmp(type, "rsa_keygen_bits"))
+               {
+               int nbits;
+               nbits = atoi(value);
+               return EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, nbits);
+               }
+
+       if (!strcmp(type, "rsa_keygen_pubexp"))
+               {
+               int ret;
+               BIGNUM *pubexp = NULL;
+               if (!BN_asc2bn(&pubexp, value))
+                       return 0;
+               ret = EVP_PKEY_CTX_set_rsa_keygen_pubexp(ctx, pubexp);
+               if (ret <= 0)
+                       BN_free(pubexp);
+               return ret;
+               }
+
+       return -2;
+       }
+
+static int pkey_rsa_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
+       {
+       RSA *rsa = NULL;
+       RSA_PKEY_CTX *rctx = ctx->data;
+       BN_GENCB *pcb, cb;
+       int ret;
+       if (!rctx->pub_exp)
+               {
+               rctx->pub_exp = BN_new();
+               if (!rctx->pub_exp || !BN_set_word(rctx->pub_exp, RSA_F4))
+                       return 0;
+               }
+       rsa = RSA_new();
+       if (!rsa)
+               return 0;
+       if (ctx->pkey_gencb)
+               {
+               pcb = &cb;
+               evp_pkey_set_cb_translate(pcb, ctx);
+               }
+       else
+               pcb = NULL;
+       ret = RSA_generate_key_ex(rsa, rctx->nbits, rctx->pub_exp, pcb);
+       if (ret > 0)
+               EVP_PKEY_assign_RSA(pkey, rsa);
+       else
+               RSA_free(rsa);
+       return ret;
+       }
+
+const EVP_PKEY_METHOD rsa_pkey_meth = 
+       {
+       EVP_PKEY_RSA,
+       EVP_PKEY_FLAG_AUTOARGLEN,
+       pkey_rsa_init,
+       pkey_rsa_copy,
+       pkey_rsa_cleanup,
+
+       0,0,
+
+       0,
+       pkey_rsa_keygen,
+
+       0,
+       pkey_rsa_sign,
+
+       0,
+       pkey_rsa_verify,
+
+       0,
+       pkey_rsa_verifyrecover,
+
+
+       0,0,0,0,
+
+       0,
+       pkey_rsa_encrypt,
+
+       0,
+       pkey_rsa_decrypt,
+
+       0,0,
+
+       pkey_rsa_ctrl,
+       pkey_rsa_ctrl_str
+
+
+       };
similarity index 74%
rename from deps/openssl/openssl/fips/dsa/fips_dsa_lib.c
rename to deps/openssl/openssl/crypto/rsa/rsa_prn.c
index 2545966..224db0f 100644 (file)
@@ -1,9 +1,9 @@
-/* fips_dsa_lib.c */
+/* crypto/rsa/rsa_prn.c */
 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
- * project 2007.
+ * project 2006.
  */
 /* ====================================================================
- * Copyright (c) 2007 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  *
  */
 
-#include <string.h>
-#include <openssl/dsa.h>
-#include <openssl/bn.h>
+#include <stdio.h>
+#include "cryptlib.h"
+#include <openssl/rsa.h>
+#include <openssl/evp.h>
 
-/* Minimal FIPS versions of FIPS_dsa_new() and FIPS_dsa_free: to
- * reduce external dependencies. 
- */
-
-DSA *FIPS_dsa_new(void)
+#ifndef OPENSSL_NO_FP_API
+int RSA_print_fp(FILE *fp, const RSA *x, int off)
        {
-       DSA *ret;
-       ret = OPENSSL_malloc(sizeof(DSA));
-       if (!ret)
-               return NULL;
-       memset(ret, 0, sizeof(DSA));
-       ret->meth = DSA_OpenSSL();
-       if (ret->meth->init)
-               ret->meth->init(ret);
-       return ret;
+       BIO *b;
+       int ret;
+
+       if ((b=BIO_new(BIO_s_file())) == NULL)
+               {
+               RSAerr(RSA_F_RSA_PRINT_FP,ERR_R_BUF_LIB);
+               return(0);
+               }
+       BIO_set_fp(b,fp,BIO_NOCLOSE);
+       ret=RSA_print(b,x,off);
+       BIO_free(b);
+       return(ret);
        }
+#endif
 
-void FIPS_dsa_free(DSA *r)
+int RSA_print(BIO *bp, const RSA *x, int off)
        {
-       if (!r)
-               return;
-       if (r->meth->finish)
-               r->meth->finish(r);
-       if (r->p != NULL) BN_clear_free(r->p);
-       if (r->q != NULL) BN_clear_free(r->q);
-       if (r->g != NULL) BN_clear_free(r->g);
-       if (r->pub_key != NULL) BN_clear_free(r->pub_key);
-       if (r->priv_key != NULL) BN_clear_free(r->priv_key);
-       if (r->kinv != NULL) BN_clear_free(r->kinv);
-       if (r->r != NULL) BN_clear_free(r->r);
-       OPENSSL_free(r);
+       EVP_PKEY *pk;
+       int ret;
+       pk = EVP_PKEY_new();
+       if (!pk || !EVP_PKEY_set1_RSA(pk, (RSA *)x))
+               return 0;
+       ret = EVP_PKEY_print_private(bp, pk, off, NULL);
+       EVP_PKEY_free(pk);
+       return ret;
        }
 
index 2bda491..ac211e2 100644 (file)
@@ -81,7 +81,9 @@ int RSA_verify_PKCS1_PSS(RSA *rsa, const unsigned char *mHash,
        EVP_MD_CTX ctx;
        unsigned char H_[EVP_MAX_MD_SIZE];
 
-       hLen = M_EVP_MD_size(Hash);
+       hLen = EVP_MD_size(Hash);
+       if (hLen < 0)
+               goto err;
        /*
         * Negative sLen has special meanings:
         *      -1      sLen == hLen
@@ -126,7 +128,8 @@ int RSA_verify_PKCS1_PSS(RSA *rsa, const unsigned char *mHash,
                RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS, ERR_R_MALLOC_FAILURE);
                goto err;
                }
-       PKCS1_MGF1(DB, maskedDBLen, H, hLen, Hash);
+       if (PKCS1_MGF1(DB, maskedDBLen, H, hLen, Hash) < 0)
+               goto err;
        for (i = 0; i < maskedDBLen; i++)
                DB[i] ^= EM[i];
        if (MSBits)
@@ -176,7 +179,9 @@ int RSA_padding_add_PKCS1_PSS(RSA *rsa, unsigned char *EM,
        unsigned char *H, *salt = NULL, *p;
        EVP_MD_CTX ctx;
 
-       hLen = M_EVP_MD_size(Hash);
+       hLen = EVP_MD_size(Hash);
+       if (hLen < 0)
+               goto err;
        /*
         * Negative sLen has special meanings:
         *      -1      sLen == hLen
@@ -232,7 +237,8 @@ int RSA_padding_add_PKCS1_PSS(RSA *rsa, unsigned char *EM,
        EVP_MD_CTX_cleanup(&ctx);
 
        /* Generate dbMask in place then perform XOR on it */
-       PKCS1_MGF1(EM, maskedDBLen, H, hLen, Hash);
+       if (PKCS1_MGF1(EM, maskedDBLen, H, hLen, Hash))
+               goto err;
 
        p = EM;
 
index 743dfd7..0be4ec7 100644 (file)
@@ -62,6 +62,7 @@
 #include <openssl/rsa.h>
 #include <openssl/objects.h>
 #include <openssl/x509.h>
+#include "rsa_locl.h"
 
 /* Size of an SSL signature: MD5+SHA1 */
 #define SSL_SIG_LENGTH 36
@@ -90,14 +91,6 @@ int RSA_sign(int type, const unsigned char *m, unsigned int m_len,
                i = SSL_SIG_LENGTH;
                s = m;
        } else {
-       /* NB: in FIPS mode block anything that isn't a TLS signature */
-#ifdef OPENSSL_FIPS
-               if(FIPS_mode() && !(rsa->flags & RSA_FLAG_NON_FIPS_ALLOW))
-                       {
-                       RSAerr(RSA_F_RSA_SIGN, RSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE);
-                       return 0;
-                       }
-#endif
                sig.algor= &algor;
                sig.algor->algorithm=OBJ_nid2obj(type);
                if (sig.algor->algorithm == NULL)
@@ -137,12 +130,7 @@ int RSA_sign(int type, const unsigned char *m, unsigned int m_len,
                i2d_X509_SIG(&sig,&p);
                s=tmps;
        }
-#ifdef OPENSSL_FIPS
-       /* Bypass algorithm blocking: this is allowed if we get this far */
-       i=rsa->meth->rsa_priv_enc(i,s,sigret,rsa,RSA_PKCS1_PADDING);
-#else
        i=RSA_private_encrypt(i,s,sigret,rsa,RSA_PKCS1_PADDING);
-#endif
        if (i <= 0)
                ret=0;
        else
@@ -155,8 +143,11 @@ int RSA_sign(int type, const unsigned char *m, unsigned int m_len,
        return(ret);
        }
 
-int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len,
-            unsigned char *sigbuf, unsigned int siglen, RSA *rsa)
+int int_rsa_verify(int dtype, const unsigned char *m,
+                         unsigned int m_len,
+                         unsigned char *rm, size_t *prm_len,
+                         const unsigned char *sigbuf, size_t siglen,
+                         RSA *rsa)
        {
        int i,ret=0,sigtype;
        unsigned char *s;
@@ -164,49 +155,38 @@ int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len,
 
        if (siglen != (unsigned int)RSA_size(rsa))
                {
-               RSAerr(RSA_F_RSA_VERIFY,RSA_R_WRONG_SIGNATURE_LENGTH);
+               RSAerr(RSA_F_INT_RSA_VERIFY,RSA_R_WRONG_SIGNATURE_LENGTH);
                return(0);
                }
 
-       if((rsa->flags & RSA_FLAG_SIGN_VER) && rsa->meth->rsa_verify)
+       if((dtype == NID_md5_sha1) && rm)
                {
-               return rsa->meth->rsa_verify(dtype, m, m_len,
-                       sigbuf, siglen, rsa);
+               i = RSA_public_decrypt((int)siglen,
+                                       sigbuf,rm,rsa,RSA_PKCS1_PADDING);
+               if (i <= 0)
+                       return 0;
+               *prm_len = i;
+               return 1;
                }
 
        s=(unsigned char *)OPENSSL_malloc((unsigned int)siglen);
        if (s == NULL)
                {
-               RSAerr(RSA_F_RSA_VERIFY,ERR_R_MALLOC_FAILURE);
+               RSAerr(RSA_F_INT_RSA_VERIFY,ERR_R_MALLOC_FAILURE);
                goto err;
                }
-       if(dtype == NID_md5_sha1)
-               {
-               if (m_len != SSL_SIG_LENGTH)
-                       {
-                       RSAerr(RSA_F_RSA_VERIFY,RSA_R_INVALID_MESSAGE_LENGTH);
+       if((dtype == NID_md5_sha1) && (m_len != SSL_SIG_LENGTH) ) {
+                       RSAerr(RSA_F_INT_RSA_VERIFY,RSA_R_INVALID_MESSAGE_LENGTH);
                        goto err;
-                       }
-               }
-       /* NB: in FIPS mode block anything that isn't a TLS signature */
-#ifdef OPENSSL_FIPS
-       else if(FIPS_mode() && !(rsa->flags & RSA_FLAG_NON_FIPS_ALLOW))
-               {
-               RSAerr(RSA_F_RSA_VERIFY, RSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE);
-               return 0;
-               }
-       /* Bypass algorithm blocking: this is allowed */
-       i=rsa->meth->rsa_pub_dec((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING);
-#else
+       }
        i=RSA_public_decrypt((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING);
-#endif
 
        if (i <= 0) goto err;
 
        /* Special case: SSL signature */
        if(dtype == NID_md5_sha1) {
                if((i != SSL_SIG_LENGTH) || memcmp(s, m, SSL_SIG_LENGTH))
-                               RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
+                               RSAerr(RSA_F_INT_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
                else ret = 1;
        } else {
                const unsigned char *p=s;
@@ -217,7 +197,7 @@ int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len,
                /* Excess data can be used to create forgeries */
                if(p != s+i)
                        {
-                       RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
+                       RSAerr(RSA_F_INT_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
                        goto err;
                        }
 
@@ -226,7 +206,7 @@ int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len,
                if(sig->algor->parameter
                   && ASN1_TYPE_get(sig->algor->parameter) != V_ASN1_NULL)
                        {
-                       RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
+                       RSAerr(RSA_F_INT_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
                        goto err;
                        }
 
@@ -252,15 +232,30 @@ int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len,
                                }
                        else
                                {
-                               RSAerr(RSA_F_RSA_VERIFY,
+                               RSAerr(RSA_F_INT_RSA_VERIFY,
                                                RSA_R_ALGORITHM_MISMATCH);
                                goto err;
                                }
                        }
-               if (    ((unsigned int)sig->digest->length != m_len) ||
+               if (rm)
+                       {
+                       const EVP_MD *md;
+                       md = EVP_get_digestbynid(dtype);
+                       if (md && (EVP_MD_size(md) != sig->digest->length))
+                               RSAerr(RSA_F_INT_RSA_VERIFY,
+                                               RSA_R_INVALID_DIGEST_LENGTH);
+                       else
+                               {
+                               memcpy(rm, sig->digest->data,
+                                                       sig->digest->length);
+                               *prm_len = sig->digest->length;
+                               ret = 1;
+                               }
+                       }
+               else if (((unsigned int)sig->digest->length != m_len) ||
                        (memcmp(m,sig->digest->data,m_len) != 0))
                        {
-                       RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
+                       RSAerr(RSA_F_INT_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
                        }
                else
                        ret=1;
@@ -275,3 +270,16 @@ err:
        return(ret);
        }
 
+int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len,
+               const unsigned char *sigbuf, unsigned int siglen,
+               RSA *rsa)
+       {
+
+       if((rsa->flags & RSA_FLAG_SIGN_VER) && rsa->meth->rsa_verify)
+               {
+               return rsa->meth->rsa_verify(dtype, m, m_len,
+                       sigbuf, siglen, rsa);
+               }
+
+       return int_rsa_verify(dtype, m, m_len, NULL, NULL, sigbuf, siglen, rsa);
+       }
index 4080de8..c8705a0 100644 (file)
@@ -328,7 +328,7 @@ int main(int argc, char *argv[])
        }
 
     CRYPTO_cleanup_all_ex_data();
-    ERR_remove_state(0);
+    ERR_remove_thread_state(NULL);
 
     CRYPTO_mem_leaks_fp(stderr);
 
diff --git a/deps/openssl/openssl/crypto/rsa/rsa_x931g.c b/deps/openssl/openssl/crypto/rsa/rsa_x931g.c
deleted file mode 100644 (file)
index bf94f8b..0000000
+++ /dev/null
@@ -1,255 +0,0 @@
-/* crypto/rsa/rsa_gen.c */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-#include <openssl/err.h>
-#include <openssl/bn.h>
-#include <openssl/rsa.h>
-
-#ifndef OPENSSL_FIPS
-
-/* X9.31 RSA key derivation and generation */
-
-int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1, BIGNUM *q2,
-                       const BIGNUM *Xp1, const BIGNUM *Xp2, const BIGNUM *Xp,
-                       const BIGNUM *Xq1, const BIGNUM *Xq2, const BIGNUM *Xq,
-                       const BIGNUM *e, BN_GENCB *cb)
-       {
-       BIGNUM *r0=NULL,*r1=NULL,*r2=NULL,*r3=NULL;
-       BN_CTX *ctx=NULL,*ctx2=NULL;
-
-       if (!rsa) 
-               goto err;
-
-       ctx = BN_CTX_new();
-       if (!ctx) 
-               goto err;
-       BN_CTX_start(ctx);
-
-       r0 = BN_CTX_get(ctx);
-       r1 = BN_CTX_get(ctx);
-       r2 = BN_CTX_get(ctx);
-       r3 = BN_CTX_get(ctx);
-
-       if (r3 == NULL)
-               goto err;
-       if (!rsa->e)
-               {
-               rsa->e = BN_dup(e);
-               if (!rsa->e)
-                       goto err;
-               }
-       else
-               e = rsa->e;
-
-       /* If not all parameters present only calculate what we can.
-        * This allows test programs to output selective parameters.
-        */
-
-       if (Xp && !rsa->p)
-               {
-               rsa->p = BN_new();
-               if (!rsa->p)
-                       goto err;
-
-               if (!BN_X931_derive_prime_ex(rsa->p, p1, p2,
-                                       Xp, Xp1, Xp2, e, ctx, cb))
-                       goto err;
-               }
-
-       if (Xq && !rsa->q)
-               {
-               rsa->q = BN_new();
-               if (!rsa->q)
-                       goto err;
-               if (!BN_X931_derive_prime_ex(rsa->q, q1, q2,
-                                       Xq, Xq1, Xq2, e, ctx, cb))
-                       goto err;
-               }
-
-       if (!rsa->p || !rsa->q)
-               {
-               BN_CTX_end(ctx);
-               BN_CTX_free(ctx);
-               return 2;
-               }
-
-       /* Since both primes are set we can now calculate all remaining 
-        * components.
-        */
-
-       /* calculate n */
-       rsa->n=BN_new();
-       if (rsa->n == NULL)
-               goto err;
-       if (!BN_mul(rsa->n,rsa->p,rsa->q,ctx))
-               goto err;
-
-       /* calculate d */
-       if (!BN_sub(r1,rsa->p,BN_value_one()))
-               goto err;       /* p-1 */
-       if (!BN_sub(r2,rsa->q,BN_value_one()))
-               goto err;       /* q-1 */
-       if (!BN_mul(r0,r1,r2,ctx))
-               goto err;       /* (p-1)(q-1) */
-
-       if (!BN_gcd(r3, r1, r2, ctx))
-               goto err;
-
-       if (!BN_div(r0, NULL, r0, r3, ctx))
-               goto err;       /* LCM((p-1)(q-1)) */
-
-       ctx2 = BN_CTX_new();
-       if (!ctx2)
-               goto err;
-
-       rsa->d=BN_mod_inverse(NULL,rsa->e,r0,ctx2);     /* d */
-       if (rsa->d == NULL)
-               goto err;
-
-       /* calculate d mod (p-1) */
-       rsa->dmp1=BN_new();
-       if (rsa->dmp1 == NULL)
-               goto err;
-       if (!BN_mod(rsa->dmp1,rsa->d,r1,ctx))
-               goto err;
-
-       /* calculate d mod (q-1) */
-       rsa->dmq1=BN_new();
-       if (rsa->dmq1 == NULL)
-               goto err;
-       if (!BN_mod(rsa->dmq1,rsa->d,r2,ctx))
-               goto err;
-
-       /* calculate inverse of q mod p */
-       rsa->iqmp=BN_mod_inverse(NULL,rsa->q,rsa->p,ctx2);
-
-       err:
-       if (ctx)
-               {
-               BN_CTX_end(ctx);
-               BN_CTX_free(ctx);
-               }
-       if (ctx2)
-               BN_CTX_free(ctx2);
-       /* If this is set all calls successful */
-       if (rsa && rsa->iqmp != NULL)
-               return 1;
-
-       return 0;
-
-       }
-
-int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e, BN_GENCB *cb)
-       {
-       int ok = 0;
-       BIGNUM *Xp = NULL, *Xq = NULL;
-       BN_CTX *ctx = NULL;
-       
-       ctx = BN_CTX_new();
-       if (!ctx)
-               goto error;
-
-       BN_CTX_start(ctx);
-       Xp = BN_CTX_get(ctx);
-       Xq = BN_CTX_get(ctx);
-       if (!BN_X931_generate_Xpq(Xp, Xq, bits, ctx))
-               goto error;
-
-       rsa->p = BN_new();
-       rsa->q = BN_new();
-       if (!rsa->p || !rsa->q)
-               goto error;
-
-       /* Generate two primes from Xp, Xq */
-
-       if (!BN_X931_generate_prime_ex(rsa->p, NULL, NULL, NULL, NULL, Xp,
-                                       e, ctx, cb))
-               goto error;
-
-       if (!BN_X931_generate_prime_ex(rsa->q, NULL, NULL, NULL, NULL, Xq,
-                                       e, ctx, cb))
-               goto error;
-
-       /* Since rsa->p and rsa->q are valid this call will just derive
-        * remaining RSA components.
-        */
-
-       if (!RSA_X931_derive_ex(rsa, NULL, NULL, NULL, NULL,
-                               NULL, NULL, NULL, NULL, NULL, NULL, e, cb))
-               goto error;
-
-       ok = 1;
-
-       error:
-       if (ctx)
-               {
-               BN_CTX_end(ctx);
-               BN_CTX_free(ctx);
-               }
-
-       if (ok)
-               return 1;
-
-       return 0;
-
-       }
-
-#endif
diff --git a/deps/openssl/openssl/crypto/s390xcap.c b/deps/openssl/openssl/crypto/s390xcap.c
new file mode 100644 (file)
index 0000000..ffbe023
--- /dev/null
@@ -0,0 +1,37 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <setjmp.h>
+#include <signal.h>
+
+extern unsigned long OPENSSL_s390xcap_P;
+
+static sigjmp_buf ill_jmp;
+static void ill_handler (int sig) { siglongjmp(ill_jmp,sig); }
+
+unsigned long OPENSSL_s390x_facilities(void);
+
+void OPENSSL_cpuid_setup(void)
+       {
+       sigset_t oset;
+       struct sigaction ill_act,oact;
+
+       if (OPENSSL_s390xcap_P) return;
+
+       memset(&ill_act,0,sizeof(ill_act));
+       ill_act.sa_handler = ill_handler;
+       sigfillset(&ill_act.sa_mask);
+       sigdelset(&ill_act.sa_mask,SIGILL);
+       sigdelset(&ill_act.sa_mask,SIGTRAP);
+       sigprocmask(SIG_SETMASK,&ill_act.sa_mask,&oset);
+       sigaction (SIGILL,&ill_act,&oact);
+
+       /* protection against missing store-facility-list-extended */
+       if (sigsetjmp(ill_jmp,0) == 0)
+               OPENSSL_s390xcap_P = OPENSSL_s390x_facilities();
+       else
+               OPENSSL_s390xcap_P = 1UL<<63;
+
+       sigaction (SIGILL,&oact,NULL);
+       sigprocmask(SIG_SETMASK,&oset,NULL);
+       }
diff --git a/deps/openssl/openssl/crypto/s390xcpuid.S b/deps/openssl/openssl/crypto/s390xcpuid.S
new file mode 100644 (file)
index 0000000..b053c6a
--- /dev/null
@@ -0,0 +1,92 @@
+.text
+
+.globl OPENSSL_s390x_facilities
+.type  OPENSSL_s390x_facilities,@function
+.align 16
+OPENSSL_s390x_facilities:
+       lghi    %r0,0
+       .long   0xb2b0f010      # stfle 16(%r15)
+       lg      %r2,16(%r15)
+       larl    %r1,OPENSSL_s390xcap_P
+       stg     %r2,0(%r1)
+       br      %r14
+.size  OPENSSL_s390x_facilities,.-OPENSSL_s390x_facilities
+
+.globl OPENSSL_rdtsc
+.type  OPENSSL_rdtsc,@function
+.align 16
+OPENSSL_rdtsc:
+       stck    16(%r15)
+       lg      %r2,16(%r15)
+       br      %r14
+.size  OPENSSL_rdtsc,.-OPENSSL_rdtsc
+
+.globl OPENSSL_atomic_add
+.type  OPENSSL_atomic_add,@function
+.align 16
+OPENSSL_atomic_add:
+       l       %r1,0(%r2)
+.Lspin:        lr      %r0,%r1
+       ar      %r0,%r3
+       cs      %r1,%r0,0(%r2)
+       brc     4,.Lspin
+       lgfr    %r2,%r0         # OpenSSL expects the new value
+       br      %r14
+.size  OPENSSL_atomic_add,.-OPENSSL_atomic_add
+
+.globl OPENSSL_wipe_cpu
+.type  OPENSSL_wipe_cpu,@function
+.align 16
+OPENSSL_wipe_cpu:
+       xgr     %r0,%r0
+       xgr     %r1,%r1
+       lgr     %r2,%r15
+       xgr     %r3,%r3
+       xgr     %r4,%r4
+       lzdr    %f0
+       lzdr    %f1
+       lzdr    %f2
+       lzdr    %f3
+       lzdr    %f4
+       lzdr    %f5
+       lzdr    %f6
+       lzdr    %f7
+       br      %r14
+.size  OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
+
+.globl OPENSSL_cleanse
+.type  OPENSSL_cleanse,@function
+.align 16
+OPENSSL_cleanse:
+       lghi    %r4,15
+       lghi    %r0,0
+       clgr    %r3,%r4
+       jh      .Lot
+       clgr    %r3,%r0
+       bcr     8,%r14
+.Little:
+       stc     %r0,0(%r2)
+       la      %r2,1(%r2)
+       brctg   %r3,.Little
+       br      %r14
+.align 4
+.Lot:  tmll    %r2,7
+       jz      .Laligned
+       stc     %r0,0(%r2)
+       la      %r2,1(%r2)
+       brctg   %r3,.Lot
+.Laligned:
+       srlg    %r4,%r3,3
+.Loop: stg     %r0,0(%r2)
+       la      %r2,8(%r2)
+       brctg   %r4,.Loop
+       lghi    %r4,7
+       ngr     %r3,%r4
+       jnz     .Little
+       br      %r14
+.size  OPENSSL_cleanse,.-OPENSSL_cleanse
+
+.section       .init
+       brasl   %r14,OPENSSL_cpuid_setup
+
+.comm  OPENSSL_s390xcap_P,8,8
index ffaeb84..4bc55e4 100644 (file)
@@ -34,7 +34,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -75,13 +75,32 @@ clean:
 
 # DO NOT DELETE THIS LINE -- make depend depends on it.
 
-seed.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
-seed.o: ../../include/openssl/seed.h seed.c seed_locl.h
-seed_cbc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
-seed_cbc.o: ../../include/openssl/seed.h seed_cbc.c seed_locl.h
-seed_cfb.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
-seed_cfb.o: ../../include/openssl/seed.h seed_cfb.c seed_locl.h
-seed_ecb.o: ../../include/openssl/opensslconf.h ../../include/openssl/seed.h
+seed.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+seed.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+seed.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
+seed.o: ../../include/openssl/seed.h ../../include/openssl/stack.h
+seed.o: ../../include/openssl/symhacks.h seed.c seed_locl.h
+seed_cbc.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+seed_cbc.o: ../../include/openssl/modes.h ../../include/openssl/opensslconf.h
+seed_cbc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+seed_cbc.o: ../../include/openssl/safestack.h ../../include/openssl/seed.h
+seed_cbc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+seed_cbc.o: seed_cbc.c
+seed_cfb.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+seed_cfb.o: ../../include/openssl/modes.h ../../include/openssl/opensslconf.h
+seed_cfb.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+seed_cfb.o: ../../include/openssl/safestack.h ../../include/openssl/seed.h
+seed_cfb.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+seed_cfb.o: seed_cfb.c
+seed_ecb.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+seed_ecb.o: ../../include/openssl/opensslconf.h
+seed_ecb.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+seed_ecb.o: ../../include/openssl/safestack.h ../../include/openssl/seed.h
+seed_ecb.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
 seed_ecb.o: seed_ecb.c
-seed_ofb.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
-seed_ofb.o: ../../include/openssl/seed.h seed_locl.h seed_ofb.c
+seed_ofb.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+seed_ofb.o: ../../include/openssl/modes.h ../../include/openssl/opensslconf.h
+seed_ofb.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+seed_ofb.o: ../../include/openssl/safestack.h ../../include/openssl/seed.h
+seed_ofb.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+seed_ofb.o: seed_ofb.c
index 125dd7d..2bc384a 100644 (file)
@@ -35,7 +35,7 @@
 #include <openssl/seed.h>
 #include "seed_locl.h"
 
-static seed_word SS[4][256] = {        {
+static const seed_word SS[4][256] = {  {
        0x2989a1a8, 0x05858184, 0x16c6d2d4, 0x13c3d3d0, 0x14445054, 0x1d0d111c, 0x2c8ca0ac, 0x25052124,
        0x1d4d515c, 0x03434340, 0x18081018, 0x1e0e121c, 0x11415150, 0x3cccf0fc, 0x0acac2c8, 0x23436360,
        0x28082028, 0x04444044, 0x20002020, 0x1d8d919c, 0x20c0e0e0, 0x22c2e2e0, 0x08c8c0c8, 0x17071314,
@@ -187,6 +187,11 @@ static seed_word SS[4][256] = {    {
 #define KC14    0xde6e678d
 #define KC15    0xbcdccf1b
 
+#if defined(OPENSSL_SMALL_FOOTPRINT)
+static const seed_word KC[] = {
+       KC0,    KC1,    KC2,    KC3,    KC4,    KC5,    KC6,    KC7,
+       KC8,    KC9,    KC10,   KC11,   KC12,   KC13,   KC14,   KC15    };
+#endif
 
 void SEED_set_key(const unsigned char rawkey[SEED_KEY_LENGTH], SEED_KEY_SCHEDULE *ks)
 {
@@ -201,6 +206,8 @@ void SEED_set_key(const unsigned char rawkey[SEED_KEY_LENGTH], SEED_KEY_SCHEDULE
        t0 = (x1 + x3 - KC0) & 0xffffffff;
        t1 = (x2 - x4 + KC0) & 0xffffffff;                     KEYUPDATE_TEMP(t0, t1, &ks->data[0]);
        KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC1);      KEYUPDATE_TEMP(t0, t1, &ks->data[2]);
+
+#if !defined(OPENSSL_SMALL_FOOTPRINT)
        KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC2);      KEYUPDATE_TEMP(t0, t1, &ks->data[4]);
        KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC3);      KEYUPDATE_TEMP(t0, t1, &ks->data[6]);
        KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC4);      KEYUPDATE_TEMP(t0, t1, &ks->data[8]);
@@ -215,6 +222,17 @@ void SEED_set_key(const unsigned char rawkey[SEED_KEY_LENGTH], SEED_KEY_SCHEDULE
        KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC13);     KEYUPDATE_TEMP(t0, t1, &ks->data[26]);
        KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC14);     KEYUPDATE_TEMP(t0, t1, &ks->data[28]);
        KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC15);     KEYUPDATE_TEMP(t0, t1, &ks->data[30]);
+#else
+       {
+           int i;
+           for (i=2; i<16; i+=2) {
+               KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC[i]);
+               KEYUPDATE_TEMP(t0, t1, &ks->data[i*2]);
+               KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC[i+1]);
+               KEYUPDATE_TEMP(t0, t1, &ks->data[i*2+2]);
+           }
+       }
+#endif
 }
 
 void SEED_encrypt(const unsigned char s[SEED_BLOCK_SIZE], unsigned char d[SEED_BLOCK_SIZE], const SEED_KEY_SCHEDULE *ks)
@@ -226,7 +244,8 @@ void SEED_encrypt(const unsigned char s[SEED_BLOCK_SIZE], unsigned char d[SEED_B
        char2word(s+4,  x2);
        char2word(s+8,  x3);
        char2word(s+12, x4);
-       
+
+#if !defined(OPENSSL_SMALL_FOOTPRINT)  
        E_SEED(t0, t1, x1, x2, x3, x4, 0);
        E_SEED(t0, t1, x3, x4, x1, x2, 2);
        E_SEED(t0, t1, x1, x2, x3, x4, 4);
@@ -243,6 +262,15 @@ void SEED_encrypt(const unsigned char s[SEED_BLOCK_SIZE], unsigned char d[SEED_B
        E_SEED(t0, t1, x3, x4, x1, x2, 26);
        E_SEED(t0, t1, x1, x2, x3, x4, 28);
        E_SEED(t0, t1, x3, x4, x1, x2, 30);
+#else
+       {
+           int i;
+           for (i=0;i<30;i+=4) {
+               E_SEED(t0,t1,x1,x2,x3,x4,i);
+               E_SEED(t0,t1,x3,x4,x1,x2,i+2);
+           }
+       }
+#endif
 
        word2char(x3, d);
        word2char(x4, d+4);
@@ -259,7 +287,8 @@ void SEED_decrypt(const unsigned char s[SEED_BLOCK_SIZE], unsigned char d[SEED_B
        char2word(s+4,  x2);
        char2word(s+8,  x3);
        char2word(s+12, x4);
-       
+
+#if !defined(OPENSSL_SMALL_FOOTPRINT)
        E_SEED(t0, t1, x1, x2, x3, x4, 30);
        E_SEED(t0, t1, x3, x4, x1, x2, 28);
        E_SEED(t0, t1, x1, x2, x3, x4, 26);
@@ -276,6 +305,16 @@ void SEED_decrypt(const unsigned char s[SEED_BLOCK_SIZE], unsigned char d[SEED_B
        E_SEED(t0, t1, x3, x4, x1, x2, 4);
        E_SEED(t0, t1, x1, x2, x3, x4, 2);
        E_SEED(t0, t1, x3, x4, x1, x2, 0);
+#else
+       {
+           int i;
+           for (i=30; i>0; i-=4) {
+               E_SEED(t0, t1, x1, x2, x3, x4, i);
+               E_SEED(t0, t1, x3, x4, x1, x2, i-2);
+
+           }
+       }
+#endif
 
        word2char(x3, d);
        word2char(x4, d+4);
index 427915e..6ffa5f0 100644 (file)
@@ -82,6 +82,8 @@
 #define HEADER_SEED_H
 
 #include <openssl/opensslconf.h>
+#include <openssl/e_os2.h>
+#include <openssl/crypto.h>
 
 #ifdef OPENSSL_NO_SEED
 #error SEED is disabled.
index 4f718cc..6c3f9b5 100644 (file)
  *
  */
 
-#include "seed_locl.h"
-#include <string.h>
+#include <openssl/seed.h>
+#include <openssl/modes.h>
 
 void SEED_cbc_encrypt(const unsigned char *in, unsigned char *out,
                       size_t len, const SEED_KEY_SCHEDULE *ks,
                       unsigned char ivec[SEED_BLOCK_SIZE], int enc)
        {
-       size_t n;
-       unsigned char tmp[SEED_BLOCK_SIZE];
-       const unsigned char *iv = ivec;
-
        if (enc)
-               {
-               while (len >= SEED_BLOCK_SIZE)
-                       {
-                       for (n = 0; n < SEED_BLOCK_SIZE; ++n)
-                               out[n] = in[n] ^ iv[n];
-                       SEED_encrypt(out, out, ks);
-                       iv = out;
-                       len -= SEED_BLOCK_SIZE;
-                       in  += SEED_BLOCK_SIZE;
-                       out += SEED_BLOCK_SIZE;
-                       }
-               if (len)
-                       {
-                       for (n = 0; n < len; ++n)
-                               out[n] = in[n] ^ iv[n];
-                       for (n = len; n < SEED_BLOCK_SIZE; ++n)
-                               out[n] = iv[n];
-                       SEED_encrypt(out, out, ks);
-                       iv = out;
-                       }
-               memcpy(ivec, iv, SEED_BLOCK_SIZE);
-               }
-       else if (in != out) /* decrypt */
-               {
-               while (len >= SEED_BLOCK_SIZE)
-                       {
-                       SEED_decrypt(in, out, ks);
-                       for (n = 0; n < SEED_BLOCK_SIZE; ++n)
-                               out[n] ^= iv[n];
-                       iv = in;
-                       len -= SEED_BLOCK_SIZE;
-                       in  += SEED_BLOCK_SIZE;
-                       out += SEED_BLOCK_SIZE;
-                       }
-               if (len)
-                       {
-                       SEED_decrypt(in, tmp, ks);
-                       for (n = 0; n < len; ++n)
-                               out[n] = tmp[n] ^ iv[n];
-                       iv = in;
-                       }
-               memcpy(ivec, iv, SEED_BLOCK_SIZE);
-               }
-       else /* decrypt, overlap */
-               {
-               while (len >= SEED_BLOCK_SIZE)
-                       {
-                       memcpy(tmp, in, SEED_BLOCK_SIZE);
-                       SEED_decrypt(in, out, ks);
-                       for (n = 0; n < SEED_BLOCK_SIZE; ++n)
-                               out[n] ^= ivec[n];
-                       memcpy(ivec, tmp, SEED_BLOCK_SIZE);
-                       len -= SEED_BLOCK_SIZE;
-                       in  += SEED_BLOCK_SIZE;
-                       out += SEED_BLOCK_SIZE;
-                       }
-               if (len)
-                       {
-                       memcpy(tmp, in, SEED_BLOCK_SIZE);
-                       SEED_decrypt(tmp, tmp, ks);
-                       for (n = 0; n < len; ++n)
-                               out[n] = tmp[n] ^ ivec[n];
-                       memcpy(ivec, tmp, SEED_BLOCK_SIZE);
-                       }
-               }
+               CRYPTO_cbc128_encrypt(in,out,len,ks,ivec,(block128_f)SEED_encrypt);
+       else
+               CRYPTO_cbc128_decrypt(in,out,len,ks,ivec,(block128_f)SEED_decrypt);
        }
index 07d878a..694597d 100644 (file)
  * [including the GNU Public Licence.]
  */
 
-#include "seed_locl.h"
-#include <string.h>
+#include <openssl/seed.h>
+#include <openssl/modes.h>
 
 void SEED_cfb128_encrypt(const unsigned char *in, unsigned char *out,
                          size_t len, const SEED_KEY_SCHEDULE *ks,
                          unsigned char ivec[SEED_BLOCK_SIZE], int *num, int enc)
        {
-       int n;
-       unsigned char c;
-
-       n = *num;
-
-       if (enc)
-               {
-               while (len--)
-                       {
-                       if (n == 0)
-                               SEED_encrypt(ivec, ivec, ks);
-                       ivec[n] = *(out++) = *(in++) ^ ivec[n];
-                       n = (n+1) % SEED_BLOCK_SIZE;
-                       }
-               }
-       else
-               {
-               while (len--)
-                       {
-                       if (n == 0)
-                               SEED_encrypt(ivec, ivec, ks);
-                       c = *(in);
-                       *(out++) = *(in++) ^ ivec[n];
-                       ivec[n] = c;
-                       n = (n+1) % SEED_BLOCK_SIZE;
-                       }
-               }
-
-       *num = n;
+       CRYPTO_cfb128_encrypt(in,out,len,ks,ivec,num,enc,(block128_f)SEED_encrypt);
        }
index e2f3f57..3c8ba33 100644 (file)
  * [including the GNU Public Licence.]
  */
 
-#include "seed_locl.h"
-#include <string.h>
+#include <openssl/seed.h>
+#include <openssl/modes.h>
 
 void SEED_ofb128_encrypt(const unsigned char *in, unsigned char *out,
                          size_t len, const SEED_KEY_SCHEDULE *ks,
                          unsigned char ivec[SEED_BLOCK_SIZE], int *num)
        {
-       int n;
-
-       n = *num;
-       
-       while (len--)
-               {
-               if (n == 0)
-                       SEED_encrypt(ivec, ivec, ks);
-               *(out++) = *(in++) ^ ivec[n];
-               n = (n+1) % SEED_BLOCK_SIZE;
-               }
-
-       *num = n;
+       CRYPTO_ofb128_encrypt(in,out,len,ks,ivec,num,(block128_f)SEED_encrypt);
        }
index f4741b9..e6eccb0 100644 (file)
@@ -38,25 +38,16 @@ top:
 all:    lib
 
 lib:    $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
-# ELF
-sx86-elf.s: asm/sha1-586.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) sha1-586.pl elf $(CFLAGS) $(PROCESSOR) > ../$@)
-s512sse2-elf.s:        asm/sha512-sse2.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) sha512-sse2.pl elf $(CFLAGS) $(PROCESSOR) > ../$@)
-# COFF
-sx86-cof.s: asm/sha1-586.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) sha1-586.pl coff $(CFLAGS) $(PROCESSOR) > ../$@)
-s512sse2-cof.s:     asm/sha512-sse2.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) sha512-sse2.pl coff $(CFLAGS) $(PROCESSOR) > ../$@)
-# a.out
-sx86-out.s: asm/sha1-586.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) sha1-586.pl a.out $(CFLAGS) $(PROCESSOR) > ../$@)
-s512sse2-out.s:     asm/sha512-sse2.pl ../perlasm/x86asm.pl
-       (cd asm; $(PERL) sha512-sse2.pl a.out $(CFLAGS) $(PROCESSOR) > ../$@)
+sha1-586.s:    asm/sha1-586.pl ../perlasm/x86asm.pl
+       $(PERL) asm/sha1-586.pl $(PERLASM_SCHEME) $(CFLAGS) $(PROCESSOR) > $@
+sha256-586.s:  asm/sha256-586.pl ../perlasm/x86asm.pl
+       $(PERL) asm/sha256-586.pl $(PERLASM_SCHEME) $(CFLAGS) $(PROCESSOR) > $@
+sha512-586.s:  asm/sha512-586.pl ../perlasm/x86asm.pl
+       $(PERL) asm/sha512-586.pl $(PERLASM_SCHEME) $(CFLAGS) $(PROCESSOR) > $@
 
 sha1-ia64.s:   asm/sha1-ia64.pl
        (cd asm; $(PERL) sha1-ia64.pl ../$@ $(CFLAGS))
@@ -65,10 +56,25 @@ sha256-ia64.s: asm/sha512-ia64.pl
 sha512-ia64.s: asm/sha512-ia64.pl
        (cd asm; $(PERL) sha512-ia64.pl ../$@ $(CFLAGS))
 
+sha256-armv4.s: asm/sha256-armv4.pl
+       $(PERL) $< $@
+
 # Solaris make has to be explicitly told
-sha1-x86_64.s: asm/sha1-x86_64.pl;     $(PERL) asm/sha1-x86_64.pl $@
-sha256-x86_64.s:asm/sha512-x86_64.pl;  $(PERL) asm/sha512-x86_64.pl $@
-sha512-x86_64.s:asm/sha512-x86_64.pl;  $(PERL) asm/sha512-x86_64.pl $@
+sha1-x86_64.s: asm/sha1-x86_64.pl;     $(PERL) asm/sha1-x86_64.pl $(PERLASM_SCHEME) > $@
+sha256-x86_64.s:asm/sha512-x86_64.pl;  $(PERL) asm/sha512-x86_64.pl $(PERLASM_SCHEME) $@
+sha512-x86_64.s:asm/sha512-x86_64.pl;  $(PERL) asm/sha512-x86_64.pl $(PERLASM_SCHEME) $@
+sha1-sparcv9.s:        asm/sha1-sparcv9.pl;    $(PERL) asm/sha1-sparcv9.pl $@ $(CFLAGS)
+sha256-sparcv9.s:asm/sha512-sparcv9.pl;        $(PERL) asm/sha512-sparcv9.pl $@ $(CFLAGS)
+sha512-sparcv9.s:asm/sha512-sparcv9.pl;        $(PERL) asm/sha512-sparcv9.pl $@ $(CFLAGS)
+
+sha1-ppc.s:    asm/sha1-ppc.pl;        $(PERL) asm/sha1-ppc.pl $(PERLASM_SCHEME) $@
+sha256-ppc.s:  asm/sha512-ppc.pl;      $(PERL) asm/sha512-ppc.pl $(PERLASM_SCHEME) $@
+sha512-ppc.s:  asm/sha512-ppc.pl;      $(PERL) asm/sha512-ppc.pl $(PERLASM_SCHEME) $@
+
+# GNU make "catch all"
+sha1-%.s:      asm/sha1-%.pl;          $(PERL) $< $@
+sha256-%.s:    asm/sha512-%.pl;        $(PERL) $< $@
+sha512-%.s:    asm/sha512-%.pl;        $(PERL) $< $@
 
 files:
        $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
@@ -113,31 +119,24 @@ sha1_one.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 sha1_one.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
 sha1_one.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
 sha1_one.o: sha1_one.c
-sha1dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/fips.h
-sha1dgst.o: ../../include/openssl/opensslconf.h
+sha1dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
 sha1dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/sha.h
 sha1dgst.o: ../md32_common.h sha1dgst.c sha_locl.h
 sha256.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
-sha256.o: ../../include/openssl/fips.h ../../include/openssl/opensslconf.h
-sha256.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-sha256.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-sha256.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-sha256.o: ../md32_common.h sha256.c
+sha256.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+sha256.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
+sha256.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+sha256.o: ../../include/openssl/symhacks.h ../md32_common.h sha256.c
 sha512.o: ../../e_os.h ../../include/openssl/bio.h
 sha512.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 sha512.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-sha512.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-sha512.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-sha512.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
-sha512.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-sha512.o: ../../include/openssl/symhacks.h ../cryptlib.h sha512.c
-sha_dgst.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
-sha_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-sha_dgst.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-sha_dgst.o: ../../include/openssl/opensslconf.h
-sha_dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-sha_dgst.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-sha_dgst.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+sha512.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
+sha512.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+sha512.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+sha512.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+sha512.o: ../cryptlib.h sha512.c
+sha_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
+sha_dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/sha.h
 sha_dgst.o: ../md32_common.h sha_dgst.c sha_locl.h
 sha_one.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 sha_one.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
index a787dd3..a1f8762 100644 (file)
@@ -215,5 +215,6 @@ sub BODY_40_59
 
        &stack_pop(16);
 &function_end("sha1_block_data_order");
+&asciz("SHA1 block transform for x86, CRYPTOGAMS by <appro\@openssl.org>");
 
 &asm_finish();
diff --git a/deps/openssl/openssl/crypto/sha/asm/sha1-armv4-large.pl b/deps/openssl/openssl/crypto/sha/asm/sha1-armv4-large.pl
new file mode 100644 (file)
index 0000000..79e3f61
--- /dev/null
@@ -0,0 +1,229 @@
+#!/usr/bin/env perl
+
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+
+# sha1_block procedure for ARMv4.
+#
+# January 2007.
+
+# Size/performance trade-off
+# ====================================================================
+# impl         size in bytes   comp cycles[*]  measured performance
+# ====================================================================
+# thumb                304             3212            4420
+# armv4-small  392/+29%        1958/+64%       2250/+96%
+# armv4-compact        740/+89%        1552/+26%       1840/+22%
+# armv4-large  1420/+92%       1307/+19%       1370/+34%[***]
+# full unroll  ~5100/+260%     ~1260/+4%       ~1300/+5%
+# ====================================================================
+# thumb                = same as 'small' but in Thumb instructions[**] and
+#                with recurring code in two private functions;
+# small                = detached Xload/update, loops are folded;
+# compact      = detached Xload/update, 5x unroll;
+# large                = interleaved Xload/update, 5x unroll;
+# full unroll  = interleaved Xload/update, full unroll, estimated[!];
+#
+# [*]  Manually counted instructions in "grand" loop body. Measured
+#      performance is affected by prologue and epilogue overhead,
+#      i-cache availability, branch penalties, etc.
+# [**] While each Thumb instruction is twice smaller, they are not as
+#      diverse as ARM ones: e.g., there are only two arithmetic
+#      instructions with 3 arguments, no [fixed] rotate, addressing
+#      modes are limited. As result it takes more instructions to do
+#      the same job in Thumb, therefore the code is never twice as
+#      small and always slower.
+# [***]        which is also ~35% better than compiler generated code. Dual-
+#      issue Cortex A8 core was measured to process input block in
+#      ~990 cycles.
+
+# August 2010.
+#
+# Rescheduling for dual-issue pipeline resulted in 13% improvement on
+# Cortex A8 core and in absolute terms ~870 cycles per input block
+# [or 13.6 cycles per byte].
+
+
+while (($output=shift) && ($output!~/^\w[\w\-]*\.\w+$/)) {}
+open STDOUT,">$output";
+
+$ctx="r0";
+$inp="r1";
+$len="r2";
+$a="r3";
+$b="r4";
+$c="r5";
+$d="r6";
+$e="r7";
+$K="r8";
+$t0="r9";
+$t1="r10";
+$t2="r11";
+$t3="r12";
+$Xi="r14";
+@V=($a,$b,$c,$d,$e);
+
+sub Xupdate {
+my ($a,$b,$c,$d,$e,$opt1,$opt2)=@_;
+$code.=<<___;
+       ldr     $t0,[$Xi,#15*4]
+       ldr     $t1,[$Xi,#13*4]
+       ldr     $t2,[$Xi,#7*4]
+       add     $e,$K,$e,ror#2                  @ E+=K_xx_xx
+       ldr     $t3,[$Xi,#2*4]
+       eor     $t0,$t0,$t1
+       eor     $t2,$t2,$t3
+       eor     $t1,$c,$d                       @ F_xx_xx
+       mov     $t0,$t0,ror#31
+       add     $e,$e,$a,ror#27                 @ E+=ROR(A,27)
+       eor     $t0,$t0,$t2,ror#31
+       $opt1                                   @ F_xx_xx
+       $opt2                                   @ F_xx_xx
+       add     $e,$e,$t0                       @ E+=X[i]
+       str     $t0,[$Xi,#-4]!
+___
+}
+
+sub BODY_00_15 {
+my ($a,$b,$c,$d,$e)=@_;
+$code.=<<___;
+       ldrb    $t0,[$inp],#4
+       ldrb    $t1,[$inp,#-1]
+       ldrb    $t2,[$inp,#-2]
+       add     $e,$K,$e,ror#2                  @ E+=K_00_19
+       ldrb    $t3,[$inp,#-3]
+       add     $e,$e,$a,ror#27                 @ E+=ROR(A,27)
+       orr     $t0,$t1,$t0,lsl#24
+       eor     $t1,$c,$d                       @ F_xx_xx
+       orr     $t0,$t0,$t2,lsl#8
+       orr     $t0,$t0,$t3,lsl#16
+       and     $t1,$b,$t1,ror#2
+       add     $e,$e,$t0                       @ E+=X[i]
+       eor     $t1,$t1,$d,ror#2                @ F_00_19(B,C,D)
+       str     $t0,[$Xi,#-4]!
+       add     $e,$e,$t1                       @ E+=F_00_19(B,C,D)
+___
+}
+
+sub BODY_16_19 {
+my ($a,$b,$c,$d,$e)=@_;
+       &Xupdate(@_,"and $t1,$b,$t1,ror#2");
+$code.=<<___;
+       eor     $t1,$t1,$d,ror#2                @ F_00_19(B,C,D)
+       add     $e,$e,$t1                       @ E+=F_00_19(B,C,D)
+___
+}
+
+sub BODY_20_39 {
+my ($a,$b,$c,$d,$e)=@_;
+       &Xupdate(@_,"eor $t1,$b,$t1,ror#2");
+$code.=<<___;
+       add     $e,$e,$t1                       @ E+=F_20_39(B,C,D)
+___
+}
+
+sub BODY_40_59 {
+my ($a,$b,$c,$d,$e)=@_;
+       &Xupdate(@_,"and $t1,$b,$t1,ror#2","and $t2,$c,$d");
+$code.=<<___;
+       add     $e,$e,$t1                       @ E+=F_40_59(B,C,D)
+       add     $e,$e,$t2,ror#2
+___
+}
+
+$code=<<___;
+.text
+
+.global        sha1_block_data_order
+.type  sha1_block_data_order,%function
+
+.align 2
+sha1_block_data_order:
+       stmdb   sp!,{r4-r12,lr}
+       add     $len,$inp,$len,lsl#6    @ $len to point at the end of $inp
+       ldmia   $ctx,{$a,$b,$c,$d,$e}
+.Lloop:
+       ldr     $K,.LK_00_19
+       mov     $Xi,sp
+       sub     sp,sp,#15*4
+       mov     $c,$c,ror#30
+       mov     $d,$d,ror#30
+       mov     $e,$e,ror#30            @ [6]
+.L_00_15:
+___
+for($i=0;$i<5;$i++) {
+       &BODY_00_15(@V);        unshift(@V,pop(@V));
+}
+$code.=<<___;
+       teq     $Xi,sp
+       bne     .L_00_15                @ [((11+4)*5+2)*3]
+       sub     sp,sp,#5*4
+___
+       &BODY_00_15(@V);        unshift(@V,pop(@V));
+       &BODY_16_19(@V);        unshift(@V,pop(@V));
+       &BODY_16_19(@V);        unshift(@V,pop(@V));
+       &BODY_16_19(@V);        unshift(@V,pop(@V));
+       &BODY_16_19(@V);        unshift(@V,pop(@V));
+$code.=<<___;
+
+       ldr     $K,.LK_20_39            @ [+15+16*4]
+       sub     sp,sp,#20*4
+       cmn     sp,#0                   @ [+3], clear carry to denote 20_39
+.L_20_39_or_60_79:
+___
+for($i=0;$i<5;$i++) {
+       &BODY_20_39(@V);        unshift(@V,pop(@V));
+}
+$code.=<<___;
+       teq     $Xi,sp                  @ preserve carry
+       bne     .L_20_39_or_60_79       @ [+((12+3)*5+2)*4]
+       bcs     .L_done                 @ [+((12+3)*5+2)*4], spare 300 bytes
+
+       ldr     $K,.LK_40_59
+       sub     sp,sp,#20*4             @ [+2]
+.L_40_59:
+___
+for($i=0;$i<5;$i++) {
+       &BODY_40_59(@V);        unshift(@V,pop(@V));
+}
+$code.=<<___;
+       teq     $Xi,sp
+       bne     .L_40_59                @ [+((12+5)*5+2)*4]
+
+       ldr     $K,.LK_60_79
+       sub     sp,sp,#20*4
+       cmp     sp,#0                   @ set carry to denote 60_79
+       b       .L_20_39_or_60_79       @ [+4], spare 300 bytes
+.L_done:
+       add     sp,sp,#80*4             @ "deallocate" stack frame
+       ldmia   $ctx,{$K,$t0,$t1,$t2,$t3}
+       add     $a,$K,$a
+       add     $b,$t0,$b
+       add     $c,$t1,$c,ror#2
+       add     $d,$t2,$d,ror#2
+       add     $e,$t3,$e,ror#2
+       stmia   $ctx,{$a,$b,$c,$d,$e}
+       teq     $inp,$len
+       bne     .Lloop                  @ [+18], total 1307
+
+       ldmia   sp!,{r4-r12,lr}
+       tst     lr,#1
+       moveq   pc,lr                   @ be binary compatible with V4, yet
+       bx      lr                      @ interoperable with Thumb ISA:-)
+.align 2
+.LK_00_19:     .word   0x5a827999
+.LK_20_39:     .word   0x6ed9eba1
+.LK_40_59:     .word   0x8f1bbcdc
+.LK_60_79:     .word   0xca62c1d6
+.size  sha1_block_data_order,.-sha1_block_data_order
+.asciz "SHA1 block transform for ARMv4, CRYPTOGAMS by <appro\@openssl.org>"
+.align 2
+___
+
+$code =~ s/\bbx\s+lr\b/.word\t0xe12fff1e/gm;   # make it possible to compile with -march=armv4
+print $code;
+close STDOUT; # enforce flush
diff --git a/deps/openssl/openssl/crypto/sha/asm/sha1-ppc.pl b/deps/openssl/openssl/crypto/sha/asm/sha1-ppc.pl
new file mode 100644 (file)
index 0000000..dcd0fcd
--- /dev/null
@@ -0,0 +1,319 @@
+#!/usr/bin/env perl
+
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+
+# I let hardware handle unaligned input(*), except on page boundaries
+# (see below for details). Otherwise straightforward implementation
+# with X vector in register bank. The module is big-endian [which is
+# not big deal as there're no little-endian targets left around].
+#
+# (*) this means that this module is inappropriate for PPC403? Does
+#     anybody know if pre-POWER3 can sustain unaligned load?
+
+#                      -m64    -m32
+# ----------------------------------
+# PPC970,gcc-4.0.0     +76%    +59%
+# Power6,xlc-7         +68%    +33%
+
+$flavour = shift;
+
+if ($flavour =~ /64/) {
+       $SIZE_T =8;
+       $UCMP   ="cmpld";
+       $STU    ="stdu";
+       $POP    ="ld";
+       $PUSH   ="std";
+} elsif ($flavour =~ /32/) {
+       $SIZE_T =4;
+       $UCMP   ="cmplw";
+       $STU    ="stwu";
+       $POP    ="lwz";
+       $PUSH   ="stw";
+} else { die "nonsense $flavour"; }
+
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+( $xlate="${dir}ppc-xlate.pl" and -f $xlate ) or
+( $xlate="${dir}../../perlasm/ppc-xlate.pl" and -f $xlate) or
+die "can't locate ppc-xlate.pl";
+
+open STDOUT,"| $^X $xlate $flavour ".shift || die "can't call $xlate: $!";
+
+$FRAME=24*$SIZE_T;
+
+$K  ="r0";
+$sp ="r1";
+$toc="r2";
+$ctx="r3";
+$inp="r4";
+$num="r5";
+$t0 ="r15";
+$t1 ="r6";
+
+$A  ="r7";
+$B  ="r8";
+$C  ="r9";
+$D  ="r10";
+$E  ="r11";
+$T  ="r12";
+
+@V=($A,$B,$C,$D,$E,$T);
+@X=("r16","r17","r18","r19","r20","r21","r22","r23",
+    "r24","r25","r26","r27","r28","r29","r30","r31");
+
+sub BODY_00_19 {
+my ($i,$a,$b,$c,$d,$e,$f)=@_;
+my $j=$i+1;
+$code.=<<___ if ($i==0);
+       lwz     @X[$i],`$i*4`($inp)
+___
+$code.=<<___ if ($i<15);
+       lwz     @X[$j],`$j*4`($inp)
+       add     $f,$K,$e
+       rotlwi  $e,$a,5
+       add     $f,$f,@X[$i]
+       and     $t0,$c,$b
+       add     $f,$f,$e
+       andc    $t1,$d,$b
+       rotlwi  $b,$b,30
+       or      $t0,$t0,$t1
+       add     $f,$f,$t0
+___
+$code.=<<___ if ($i>=15);
+       add     $f,$K,$e
+       rotlwi  $e,$a,5
+       xor     @X[$j%16],@X[$j%16],@X[($j+2)%16]
+       add     $f,$f,@X[$i%16]
+       and     $t0,$c,$b
+       xor     @X[$j%16],@X[$j%16],@X[($j+8)%16]
+       add     $f,$f,$e
+       andc    $t1,$d,$b
+       rotlwi  $b,$b,30
+       or      $t0,$t0,$t1
+       xor     @X[$j%16],@X[$j%16],@X[($j+13)%16]
+       add     $f,$f,$t0
+       rotlwi  @X[$j%16],@X[$j%16],1
+___
+}
+
+sub BODY_20_39 {
+my ($i,$a,$b,$c,$d,$e,$f)=@_;
+my $j=$i+1;
+$code.=<<___ if ($i<79);
+       add     $f,$K,$e
+       rotlwi  $e,$a,5
+       xor     @X[$j%16],@X[$j%16],@X[($j+2)%16]
+       add     $f,$f,@X[$i%16]
+       xor     $t0,$b,$c
+       xor     @X[$j%16],@X[$j%16],@X[($j+8)%16]
+       add     $f,$f,$e
+       rotlwi  $b,$b,30
+       xor     $t0,$t0,$d
+       xor     @X[$j%16],@X[$j%16],@X[($j+13)%16]
+       add     $f,$f,$t0
+       rotlwi  @X[$j%16],@X[$j%16],1
+___
+$code.=<<___ if ($i==79);
+       add     $f,$K,$e
+       rotlwi  $e,$a,5
+       lwz     r16,0($ctx)
+       add     $f,$f,@X[$i%16]
+       xor     $t0,$b,$c
+       lwz     r17,4($ctx)
+       add     $f,$f,$e
+       rotlwi  $b,$b,30
+       lwz     r18,8($ctx)
+       xor     $t0,$t0,$d
+       lwz     r19,12($ctx)
+       add     $f,$f,$t0
+       lwz     r20,16($ctx)
+___
+}
+
+sub BODY_40_59 {
+my ($i,$a,$b,$c,$d,$e,$f)=@_;
+my $j=$i+1;
+$code.=<<___;
+       add     $f,$K,$e
+       rotlwi  $e,$a,5
+       xor     @X[$j%16],@X[$j%16],@X[($j+2)%16]
+       add     $f,$f,@X[$i%16]
+       and     $t0,$b,$c
+       xor     @X[$j%16],@X[$j%16],@X[($j+8)%16]
+       add     $f,$f,$e
+       or      $t1,$b,$c
+       rotlwi  $b,$b,30
+       xor     @X[$j%16],@X[$j%16],@X[($j+13)%16]
+       and     $t1,$t1,$d
+       or      $t0,$t0,$t1
+       rotlwi  @X[$j%16],@X[$j%16],1
+       add     $f,$f,$t0
+___
+}
+
+$code=<<___;
+.machine       "any"
+.text
+
+.globl .sha1_block_data_order
+.align 4
+.sha1_block_data_order:
+       mflr    r0
+       $STU    $sp,`-($FRAME+64)`($sp)
+       $PUSH   r0,`$FRAME-$SIZE_T*18`($sp)
+       $PUSH   r15,`$FRAME-$SIZE_T*17`($sp)
+       $PUSH   r16,`$FRAME-$SIZE_T*16`($sp)
+       $PUSH   r17,`$FRAME-$SIZE_T*15`($sp)
+       $PUSH   r18,`$FRAME-$SIZE_T*14`($sp)
+       $PUSH   r19,`$FRAME-$SIZE_T*13`($sp)
+       $PUSH   r20,`$FRAME-$SIZE_T*12`($sp)
+       $PUSH   r21,`$FRAME-$SIZE_T*11`($sp)
+       $PUSH   r22,`$FRAME-$SIZE_T*10`($sp)
+       $PUSH   r23,`$FRAME-$SIZE_T*9`($sp)
+       $PUSH   r24,`$FRAME-$SIZE_T*8`($sp)
+       $PUSH   r25,`$FRAME-$SIZE_T*7`($sp)
+       $PUSH   r26,`$FRAME-$SIZE_T*6`($sp)
+       $PUSH   r27,`$FRAME-$SIZE_T*5`($sp)
+       $PUSH   r28,`$FRAME-$SIZE_T*4`($sp)
+       $PUSH   r29,`$FRAME-$SIZE_T*3`($sp)
+       $PUSH   r30,`$FRAME-$SIZE_T*2`($sp)
+       $PUSH   r31,`$FRAME-$SIZE_T*1`($sp)
+       lwz     $A,0($ctx)
+       lwz     $B,4($ctx)
+       lwz     $C,8($ctx)
+       lwz     $D,12($ctx)
+       lwz     $E,16($ctx)
+       andi.   r0,$inp,3
+       bne     Lunaligned
+Laligned:
+       mtctr   $num
+       bl      Lsha1_block_private
+Ldone:
+       $POP    r0,`$FRAME-$SIZE_T*18`($sp)
+       $POP    r15,`$FRAME-$SIZE_T*17`($sp)
+       $POP    r16,`$FRAME-$SIZE_T*16`($sp)
+       $POP    r17,`$FRAME-$SIZE_T*15`($sp)
+       $POP    r18,`$FRAME-$SIZE_T*14`($sp)
+       $POP    r19,`$FRAME-$SIZE_T*13`($sp)
+       $POP    r20,`$FRAME-$SIZE_T*12`($sp)
+       $POP    r21,`$FRAME-$SIZE_T*11`($sp)
+       $POP    r22,`$FRAME-$SIZE_T*10`($sp)
+       $POP    r23,`$FRAME-$SIZE_T*9`($sp)
+       $POP    r24,`$FRAME-$SIZE_T*8`($sp)
+       $POP    r25,`$FRAME-$SIZE_T*7`($sp)
+       $POP    r26,`$FRAME-$SIZE_T*6`($sp)
+       $POP    r27,`$FRAME-$SIZE_T*5`($sp)
+       $POP    r28,`$FRAME-$SIZE_T*4`($sp)
+       $POP    r29,`$FRAME-$SIZE_T*3`($sp)
+       $POP    r30,`$FRAME-$SIZE_T*2`($sp)
+       $POP    r31,`$FRAME-$SIZE_T*1`($sp)
+       mtlr    r0
+       addi    $sp,$sp,`$FRAME+64`
+       blr
+___
+
+# PowerPC specification allows an implementation to be ill-behaved
+# upon unaligned access which crosses page boundary. "Better safe
+# than sorry" principle makes me treat it specially. But I don't
+# look for particular offending word, but rather for 64-byte input
+# block which crosses the boundary. Once found that block is aligned
+# and hashed separately...
+$code.=<<___;
+.align 4
+Lunaligned:
+       subfic  $t1,$inp,4096
+       andi.   $t1,$t1,4095    ; distance to closest page boundary
+       srwi.   $t1,$t1,6       ; t1/=64
+       beq     Lcross_page
+       $UCMP   $num,$t1
+       ble-    Laligned        ; didn't cross the page boundary
+       mtctr   $t1
+       subfc   $num,$t1,$num
+       bl      Lsha1_block_private
+Lcross_page:
+       li      $t1,16
+       mtctr   $t1
+       addi    r20,$sp,$FRAME  ; spot below the frame
+Lmemcpy:
+       lbz     r16,0($inp)
+       lbz     r17,1($inp)
+       lbz     r18,2($inp)
+       lbz     r19,3($inp)
+       addi    $inp,$inp,4
+       stb     r16,0(r20)
+       stb     r17,1(r20)
+       stb     r18,2(r20)
+       stb     r19,3(r20)
+       addi    r20,r20,4
+       bdnz    Lmemcpy
+
+       $PUSH   $inp,`$FRAME-$SIZE_T*19`($sp)
+       li      $t1,1
+       addi    $inp,$sp,$FRAME
+       mtctr   $t1
+       bl      Lsha1_block_private
+       $POP    $inp,`$FRAME-$SIZE_T*19`($sp)
+       addic.  $num,$num,-1
+       bne-    Lunaligned
+       b       Ldone
+___
+
+# This is private block function, which uses tailored calling
+# interface, namely upon entry SHA_CTX is pre-loaded to given
+# registers and counter register contains amount of chunks to
+# digest...
+$code.=<<___;
+.align 4
+Lsha1_block_private:
+___
+$code.=<<___;  # load K_00_19
+       lis     $K,0x5a82
+       ori     $K,$K,0x7999
+___
+for($i=0;$i<20;$i++)   { &BODY_00_19($i,@V); unshift(@V,pop(@V)); }
+$code.=<<___;  # load K_20_39
+       lis     $K,0x6ed9
+       ori     $K,$K,0xeba1
+___
+for(;$i<40;$i++)       { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
+$code.=<<___;  # load K_40_59
+       lis     $K,0x8f1b
+       ori     $K,$K,0xbcdc
+___
+for(;$i<60;$i++)       { &BODY_40_59($i,@V); unshift(@V,pop(@V)); }
+$code.=<<___;  # load K_60_79
+       lis     $K,0xca62
+       ori     $K,$K,0xc1d6
+___
+for(;$i<80;$i++)       { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
+$code.=<<___;
+       add     r16,r16,$E
+       add     r17,r17,$T
+       add     r18,r18,$A
+       add     r19,r19,$B
+       add     r20,r20,$C
+       stw     r16,0($ctx)
+       mr      $A,r16
+       stw     r17,4($ctx)
+       mr      $B,r17
+       stw     r18,8($ctx)
+       mr      $C,r18
+       stw     r19,12($ctx)
+       mr      $D,r19
+       stw     r20,16($ctx)
+       mr      $E,r20
+       addi    $inp,$inp,`16*4`
+       bdnz-   Lsha1_block_private
+       blr
+___
+$code.=<<___;
+.asciz "SHA1 block transform for PPC, CRYPTOGAMS by <appro\@fy.chalmers.se>"
+___
+
+$code =~ s/\`([^\`]*)\`/eval $1/gem;
+print $code;
+close STDOUT;
diff --git a/deps/openssl/openssl/crypto/sha/asm/sha1-s390x.pl b/deps/openssl/openssl/crypto/sha/asm/sha1-s390x.pl
new file mode 100644 (file)
index 0000000..4b17848
--- /dev/null
@@ -0,0 +1,226 @@
+#!/usr/bin/env perl
+
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+
+# SHA1 block procedure for s390x.
+
+# April 2007.
+#
+# Performance is >30% better than gcc 3.3 generated code. But the real
+# twist is that SHA1 hardware support is detected and utilized. In
+# which case performance can reach further >4.5x for larger chunks.
+
+# January 2009.
+#
+# Optimize Xupdate for amount of memory references and reschedule
+# instructions to favour dual-issue z10 pipeline. On z10 hardware is
+# "only" ~2.3x faster than software.
+
+$kimdfunc=1;   # magic function code for kimd instruction
+
+$output=shift;
+open STDOUT,">$output";
+
+$K_00_39="%r0"; $K=$K_00_39;
+$K_40_79="%r1";
+$ctx="%r2";    $prefetch="%r2";
+$inp="%r3";
+$len="%r4";
+
+$A="%r5";
+$B="%r6";
+$C="%r7";
+$D="%r8";
+$E="%r9";      @V=($A,$B,$C,$D,$E);
+$t0="%r10";
+$t1="%r11";
+@X=("%r12","%r13","%r14");
+$sp="%r15";
+
+$frame=160+16*4;
+
+sub Xupdate {
+my $i=shift;
+
+$code.=<<___ if ($i==15);
+       lg      $prefetch,160($sp)      ### Xupdate(16) warm-up
+       lr      $X[0],$X[2]
+___
+return if ($i&1);      # Xupdate is vectorized and executed every 2nd cycle
+$code.=<<___ if ($i<16);
+       lg      $X[0],`$i*4`($inp)      ### Xload($i)
+       rllg    $X[1],$X[0],32
+___
+$code.=<<___ if ($i>=16);
+       xgr     $X[0],$prefetch         ### Xupdate($i)
+       lg      $prefetch,`160+4*(($i+2)%16)`($sp)
+       xg      $X[0],`160+4*(($i+8)%16)`($sp)
+       xgr     $X[0],$prefetch
+       rll     $X[0],$X[0],1
+       rllg    $X[1],$X[0],32
+       rll     $X[1],$X[1],1
+       rllg    $X[0],$X[1],32
+       lr      $X[2],$X[1]             # feedback
+___
+$code.=<<___ if ($i<=70);
+       stg     $X[0],`160+4*($i%16)`($sp)
+___
+unshift(@X,pop(@X));
+}
+
+sub BODY_00_19 {
+my ($i,$a,$b,$c,$d,$e)=@_;
+my $xi=$X[1];
+
+       &Xupdate($i);
+$code.=<<___;
+       alr     $e,$K           ### $i
+       rll     $t1,$a,5
+       lr      $t0,$d
+       xr      $t0,$c
+       alr     $e,$t1
+       nr      $t0,$b
+       alr     $e,$xi
+       xr      $t0,$d
+       rll     $b,$b,30
+       alr     $e,$t0
+___
+}
+
+sub BODY_20_39 {
+my ($i,$a,$b,$c,$d,$e)=@_;
+my $xi=$X[1];
+
+       &Xupdate($i);
+$code.=<<___;
+       alr     $e,$K           ### $i
+       rll     $t1,$a,5
+       lr      $t0,$b
+       alr     $e,$t1
+       xr      $t0,$c
+       alr     $e,$xi
+       xr      $t0,$d
+       rll     $b,$b,30
+       alr     $e,$t0
+___
+}
+
+sub BODY_40_59 {
+my ($i,$a,$b,$c,$d,$e)=@_;
+my $xi=$X[1];
+
+       &Xupdate($i);
+$code.=<<___;
+       alr     $e,$K           ### $i
+       rll     $t1,$a,5
+       lr      $t0,$b
+       alr     $e,$t1
+       or      $t0,$c
+       lr      $t1,$b
+       nr      $t0,$d
+       nr      $t1,$c
+       alr     $e,$xi
+       or      $t0,$t1
+       rll     $b,$b,30
+       alr     $e,$t0
+___
+}
+
+$code.=<<___;
+.text
+.align 64
+.type  Ktable,\@object
+Ktable: .long  0x5a827999,0x6ed9eba1,0x8f1bbcdc,0xca62c1d6
+       .skip   48      #.long  0,0,0,0,0,0,0,0,0,0,0,0
+.size  Ktable,.-Ktable
+.globl sha1_block_data_order
+.type  sha1_block_data_order,\@function
+sha1_block_data_order:
+___
+$code.=<<___ if ($kimdfunc);
+       larl    %r1,OPENSSL_s390xcap_P
+       lg      %r0,0(%r1)
+       tmhl    %r0,0x4000      # check for message-security assist
+       jz      .Lsoftware
+       lghi    %r0,0
+       la      %r1,16($sp)
+       .long   0xb93e0002      # kimd %r0,%r2
+       lg      %r0,16($sp)
+       tmhh    %r0,`0x8000>>$kimdfunc`
+       jz      .Lsoftware
+       lghi    %r0,$kimdfunc
+       lgr     %r1,$ctx
+       lgr     %r2,$inp
+       sllg    %r3,$len,6
+       .long   0xb93e0002      # kimd %r0,%r2
+       brc     1,.-4           # pay attention to "partial completion"
+       br      %r14
+.align 16
+.Lsoftware:
+___
+$code.=<<___;
+       lghi    %r1,-$frame
+       stg     $ctx,16($sp)
+       stmg    %r6,%r15,48($sp)
+       lgr     %r0,$sp
+       la      $sp,0(%r1,$sp)
+       stg     %r0,0($sp)
+
+       larl    $t0,Ktable
+       llgf    $A,0($ctx)
+       llgf    $B,4($ctx)
+       llgf    $C,8($ctx)
+       llgf    $D,12($ctx)
+       llgf    $E,16($ctx)
+
+       lg      $K_00_39,0($t0)
+       lg      $K_40_79,8($t0)
+
+.Lloop:
+       rllg    $K_00_39,$K_00_39,32
+___
+for ($i=0;$i<20;$i++)  { &BODY_00_19($i,@V); unshift(@V,pop(@V)); }
+$code.=<<___;
+       rllg    $K_00_39,$K_00_39,32
+___
+for (;$i<40;$i++)      { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
+$code.=<<___;  $K=$K_40_79;
+       rllg    $K_40_79,$K_40_79,32
+___
+for (;$i<60;$i++)      { &BODY_40_59($i,@V); unshift(@V,pop(@V)); }
+$code.=<<___;
+       rllg    $K_40_79,$K_40_79,32
+___
+for (;$i<80;$i++)      { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
+$code.=<<___;
+
+       lg      $ctx,`$frame+16`($sp)
+       la      $inp,64($inp)
+       al      $A,0($ctx)
+       al      $B,4($ctx)
+       al      $C,8($ctx)
+       al      $D,12($ctx)
+       al      $E,16($ctx)
+       st      $A,0($ctx)
+       st      $B,4($ctx)
+       st      $C,8($ctx)
+       st      $D,12($ctx)
+       st      $E,16($ctx)
+       brct    $len,.Lloop
+
+       lmg     %r6,%r15,`$frame+48`($sp)
+       br      %r14
+.size  sha1_block_data_order,.-sha1_block_data_order
+.string        "SHA1 block transform for s390x, CRYPTOGAMS by <appro\@openssl.org>"
+.comm  OPENSSL_s390xcap_P,8,8
+___
+
+$code =~ s/\`([^\`]*)\`/eval $1/gem;
+
+print $code;
+close STDOUT;
diff --git a/deps/openssl/openssl/crypto/sha/asm/sha1-sparcv9.pl b/deps/openssl/openssl/crypto/sha/asm/sha1-sparcv9.pl
new file mode 100644 (file)
index 0000000..5c161ce
--- /dev/null
@@ -0,0 +1,284 @@
+#!/usr/bin/env perl
+
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+
+# Performance improvement is not really impressive on pre-T1 CPU: +8%
+# over Sun C and +25% over gcc [3.3]. While on T1, a.k.a. Niagara, it
+# turned to be 40% faster than 64-bit code generated by Sun C 5.8 and
+# >2x than 64-bit code generated by gcc 3.4. And there is a gimmick.
+# X[16] vector is packed to 8 64-bit registers and as result nothing
+# is spilled on stack. In addition input data is loaded in compact
+# instruction sequence, thus minimizing the window when the code is
+# subject to [inter-thread] cache-thrashing hazard. The goal is to
+# ensure scalability on UltraSPARC T1, or rather to avoid decay when
+# amount of active threads exceeds the number of physical cores.
+
+$bits=32;
+for (@ARGV)    { $bits=64 if (/\-m64/ || /\-xarch\=v9/); }
+if ($bits==64) { $bias=2047; $frame=192; }
+else           { $bias=0;    $frame=112; }
+
+$output=shift;
+open STDOUT,">$output";
+
+@X=("%o0","%o1","%o2","%o3","%o4","%o5","%g1","%o7");
+$rot1m="%g2";
+$tmp64="%g3";
+$Xi="%g4";
+$A="%l0";
+$B="%l1";
+$C="%l2";
+$D="%l3";
+$E="%l4";
+@V=($A,$B,$C,$D,$E);
+$K_00_19="%l5";
+$K_20_39="%l6";
+$K_40_59="%l7";
+$K_60_79="%g5";
+@K=($K_00_19,$K_20_39,$K_40_59,$K_60_79);
+
+$ctx="%i0";
+$inp="%i1";
+$len="%i2";
+$tmp0="%i3";
+$tmp1="%i4";
+$tmp2="%i5";
+
+sub BODY_00_15 {
+my ($i,$a,$b,$c,$d,$e)=@_;
+my $xi=($i&1)?@X[($i/2)%8]:$Xi;
+
+$code.=<<___;
+       sll     $a,5,$tmp0              !! $i
+       add     @K[$i/20],$e,$e
+       srl     $a,27,$tmp1
+       add     $tmp0,$e,$e
+       and     $c,$b,$tmp0
+       add     $tmp1,$e,$e
+       sll     $b,30,$tmp2
+       andn    $d,$b,$tmp1
+       srl     $b,2,$b
+       or      $tmp1,$tmp0,$tmp1
+       or      $tmp2,$b,$b
+       add     $xi,$e,$e
+___
+if ($i&1 && $i<15) {
+       $code.=
+       "       srlx    @X[(($i+1)/2)%8],32,$Xi\n";
+}
+$code.=<<___;
+       add     $tmp1,$e,$e
+___
+}
+
+sub Xupdate {
+my ($i,$a,$b,$c,$d,$e)=@_;
+my $j=$i/2;
+
+if ($i&1) {
+$code.=<<___;
+       sll     $a,5,$tmp0              !! $i
+       add     @K[$i/20],$e,$e
+       srl     $a,27,$tmp1
+___
+} else {
+$code.=<<___;
+       sllx    @X[($j+6)%8],32,$Xi     ! Xupdate($i)
+       xor     @X[($j+1)%8],@X[$j%8],@X[$j%8]
+       srlx    @X[($j+7)%8],32,$tmp1
+       xor     @X[($j+4)%8],@X[$j%8],@X[$j%8]
+       sll     $a,5,$tmp0              !! $i
+       or      $tmp1,$Xi,$Xi
+       add     @K[$i/20],$e,$e         !!
+       xor     $Xi,@X[$j%8],@X[$j%8]
+       srlx    @X[$j%8],31,$Xi
+       add     @X[$j%8],@X[$j%8],@X[$j%8]
+       and     $Xi,$rot1m,$Xi
+       andn    @X[$j%8],$rot1m,@X[$j%8]
+       srl     $a,27,$tmp1             !!
+       or      $Xi,@X[$j%8],@X[$j%8]
+___
+}
+}
+
+sub BODY_16_19 {
+my ($i,$a,$b,$c,$d,$e)=@_;
+
+       &Xupdate(@_);
+    if ($i&1) {
+       $xi=@X[($i/2)%8];
+    } else {
+       $xi=$Xi;
+       $code.="\tsrlx  @X[($i/2)%8],32,$xi\n";
+    }
+$code.=<<___;
+       add     $tmp0,$e,$e             !!
+       and     $c,$b,$tmp0
+       add     $tmp1,$e,$e
+       sll     $b,30,$tmp2
+       add     $xi,$e,$e
+       andn    $d,$b,$tmp1
+       srl     $b,2,$b
+       or      $tmp1,$tmp0,$tmp1
+       or      $tmp2,$b,$b
+       add     $tmp1,$e,$e
+___
+}
+
+sub BODY_20_39 {
+my ($i,$a,$b,$c,$d,$e)=@_;
+my $xi;
+       &Xupdate(@_);
+    if ($i&1) {
+       $xi=@X[($i/2)%8];
+    } else {
+       $xi=$Xi;
+       $code.="\tsrlx  @X[($i/2)%8],32,$xi\n";
+    }
+$code.=<<___;
+       add     $tmp0,$e,$e             !!
+       xor     $c,$b,$tmp0
+       add     $tmp1,$e,$e
+       sll     $b,30,$tmp2
+       xor     $d,$tmp0,$tmp1
+       srl     $b,2,$b
+       add     $tmp1,$e,$e
+       or      $tmp2,$b,$b
+       add     $xi,$e,$e
+___
+}
+
+sub BODY_40_59 {
+my ($i,$a,$b,$c,$d,$e)=@_;
+my $xi;
+       &Xupdate(@_);
+    if ($i&1) {
+       $xi=@X[($i/2)%8];
+    } else {
+       $xi=$Xi;
+       $code.="\tsrlx  @X[($i/2)%8],32,$xi\n";
+    }
+$code.=<<___;
+       add     $tmp0,$e,$e             !!
+       and     $c,$b,$tmp0
+       add     $tmp1,$e,$e
+       sll     $b,30,$tmp2
+       or      $c,$b,$tmp1
+       srl     $b,2,$b
+       and     $d,$tmp1,$tmp1
+       add     $xi,$e,$e
+       or      $tmp1,$tmp0,$tmp1
+       or      $tmp2,$b,$b
+       add     $tmp1,$e,$e
+___
+}
+
+$code.=<<___ if ($bits==64);
+.register      %g2,#scratch
+.register      %g3,#scratch
+___
+$code.=<<___;
+.section       ".text",#alloc,#execinstr
+
+.align 32
+.globl sha1_block_data_order
+sha1_block_data_order:
+       save    %sp,-$frame,%sp
+       sllx    $len,6,$len
+       add     $inp,$len,$len
+
+       or      %g0,1,$rot1m
+       sllx    $rot1m,32,$rot1m
+       or      $rot1m,1,$rot1m
+
+       ld      [$ctx+0],$A
+       ld      [$ctx+4],$B
+       ld      [$ctx+8],$C
+       ld      [$ctx+12],$D
+       ld      [$ctx+16],$E
+       andn    $inp,7,$tmp0
+
+       sethi   %hi(0x5a827999),$K_00_19
+       or      $K_00_19,%lo(0x5a827999),$K_00_19
+       sethi   %hi(0x6ed9eba1),$K_20_39
+       or      $K_20_39,%lo(0x6ed9eba1),$K_20_39
+       sethi   %hi(0x8f1bbcdc),$K_40_59
+       or      $K_40_59,%lo(0x8f1bbcdc),$K_40_59
+       sethi   %hi(0xca62c1d6),$K_60_79
+       or      $K_60_79,%lo(0xca62c1d6),$K_60_79
+
+.Lloop:
+       ldx     [$tmp0+0],@X[0]
+       ldx     [$tmp0+16],@X[2]
+       ldx     [$tmp0+32],@X[4]
+       ldx     [$tmp0+48],@X[6]
+       and     $inp,7,$tmp1
+       ldx     [$tmp0+8],@X[1]
+       sll     $tmp1,3,$tmp1
+       ldx     [$tmp0+24],@X[3]
+       subcc   %g0,$tmp1,$tmp2 ! should be 64-$tmp1, but -$tmp1 works too
+       ldx     [$tmp0+40],@X[5]
+       bz,pt   %icc,.Laligned
+       ldx     [$tmp0+56],@X[7]
+
+       sllx    @X[0],$tmp1,@X[0]
+       ldx     [$tmp0+64],$tmp64
+___
+for($i=0;$i<7;$i++)
+{   $code.=<<___;
+       srlx    @X[$i+1],$tmp2,$Xi
+       sllx    @X[$i+1],$tmp1,@X[$i+1]
+       or      $Xi,@X[$i],@X[$i]
+___
+}
+$code.=<<___;
+       srlx    $tmp64,$tmp2,$tmp64
+       or      $tmp64,@X[7],@X[7]
+.Laligned:
+       srlx    @X[0],32,$Xi
+___
+for ($i=0;$i<16;$i++)  { &BODY_00_15($i,@V); unshift(@V,pop(@V)); }
+for (;$i<20;$i++)      { &BODY_16_19($i,@V); unshift(@V,pop(@V)); }
+for (;$i<40;$i++)      { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
+for (;$i<60;$i++)      { &BODY_40_59($i,@V); unshift(@V,pop(@V)); }
+for (;$i<80;$i++)      { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
+$code.=<<___;
+
+       ld      [$ctx+0],@X[0]
+       ld      [$ctx+4],@X[1]
+       ld      [$ctx+8],@X[2]
+       ld      [$ctx+12],@X[3]
+       add     $inp,64,$inp
+       ld      [$ctx+16],@X[4]
+       cmp     $inp,$len
+
+       add     $A,@X[0],$A
+       st      $A,[$ctx+0]
+       add     $B,@X[1],$B
+       st      $B,[$ctx+4]
+       add     $C,@X[2],$C
+       st      $C,[$ctx+8]
+       add     $D,@X[3],$D
+       st      $D,[$ctx+12]
+       add     $E,@X[4],$E
+       st      $E,[$ctx+16]
+
+       bne     `$bits==64?"%xcc":"%icc"`,.Lloop
+       andn    $inp,7,$tmp0
+
+       ret
+       restore
+.type  sha1_block_data_order,#function
+.size  sha1_block_data_order,(.-sha1_block_data_order)
+.asciz "SHA1 block transform for SPARCv9, CRYPTOGAMS by <appro\@openssl.org>"
+.align 4
+___
+
+$code =~ s/\`([^\`]*)\`/eval $1/gem;
+print $code;
+close STDOUT;
diff --git a/deps/openssl/openssl/crypto/sha/asm/sha1-sparcv9a.pl b/deps/openssl/openssl/crypto/sha/asm/sha1-sparcv9a.pl
new file mode 100644 (file)
index 0000000..85e8d68
--- /dev/null
@@ -0,0 +1,601 @@
+#!/usr/bin/env perl
+
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+
+# January 2009
+#
+# Provided that UltraSPARC VIS instructions are pipe-lined(*) and
+# pairable(*) with IALU ones, offloading of Xupdate to the UltraSPARC
+# Graphic Unit would make it possible to achieve higher instruction-
+# level parallelism, ILP, and thus higher performance. It should be
+# explicitly noted that ILP is the keyword, and it means that this
+# code would be unsuitable for cores like UltraSPARC-Tx. The idea is
+# not really novel, Sun had VIS-powered implementation for a while.
+# Unlike Sun's implementation this one can process multiple unaligned
+# input blocks, and as such works as drop-in replacement for OpenSSL
+# sha1_block_data_order. Performance improvement was measured to be
+# 40% over pure IALU sha1-sparcv9.pl on UltraSPARC-IIi, but 12% on
+# UltraSPARC-III. See below for discussion...
+#
+# The module does not present direct interest for OpenSSL, because
+# it doesn't provide better performance on contemporary SPARCv9 CPUs,
+# UltraSPARC-Tx and SPARC64-V[II] to be specific. Those who feel they
+# absolutely must score on UltraSPARC-I-IV can simply replace
+# crypto/sha/asm/sha1-sparcv9.pl with this module.
+#
+# (*)  "Pipe-lined" means that even if it takes several cycles to
+#      complete, next instruction using same functional unit [but not
+#      depending on the result of the current instruction] can start
+#      execution without having to wait for the unit. "Pairable"
+#      means that two [or more] independent instructions can be
+#      issued at the very same time.
+
+$bits=32;
+for (@ARGV)    { $bits=64 if (/\-m64/ || /\-xarch\=v9/); }
+if ($bits==64) { $bias=2047; $frame=192; }
+else           { $bias=0;    $frame=112; }
+
+$output=shift;
+open STDOUT,">$output";
+
+$ctx="%i0";
+$inp="%i1";
+$len="%i2";
+$tmp0="%i3";
+$tmp1="%i4";
+$tmp2="%i5";
+$tmp3="%g5";
+
+$base="%g1";
+$align="%g4";
+$Xfer="%o5";
+$nXfer=$tmp3;
+$Xi="%o7";
+
+$A="%l0";
+$B="%l1";
+$C="%l2";
+$D="%l3";
+$E="%l4";
+@V=($A,$B,$C,$D,$E);
+
+$Actx="%o0";
+$Bctx="%o1";
+$Cctx="%o2";
+$Dctx="%o3";
+$Ectx="%o4";
+
+$fmul="%f32";
+$VK_00_19="%f34";
+$VK_20_39="%f36";
+$VK_40_59="%f38";
+$VK_60_79="%f40";
+@VK=($VK_00_19,$VK_20_39,$VK_40_59,$VK_60_79);
+@X=("%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
+    "%f8", "%f9","%f10","%f11","%f12","%f13","%f14","%f15","%f16");
+
+# This is reference 2x-parallelized VIS-powered Xupdate procedure. It
+# covers even K_NN_MM addition...
+sub Xupdate {
+my ($i)=@_;
+my $K=@VK[($i+16)/20];
+my $j=($i+16)%16;
+
+#      [ provided that GSR.alignaddr_offset is 5, $mul contains
+#        0x100ULL<<32|0x100 value and K_NN_MM are pre-loaded to
+#        chosen registers... ]
+$code.=<<___;
+       fxors           @X[($j+13)%16],@X[$j],@X[$j]    !-1/-1/-1:X[0]^=X[13]
+       fxors           @X[($j+14)%16],@X[$j+1],@X[$j+1]! 0/ 0/ 0:X[1]^=X[14]
+       fxor            @X[($j+2)%16],@X[($j+8)%16],%f18! 1/ 1/ 1:Tmp=X[2,3]^X[8,9]
+       fxor            %f18,@X[$j],@X[$j]              ! 2/ 4/ 3:X[0,1]^=X[2,3]^X[8,9]
+       faligndata      @X[$j],@X[$j],%f18              ! 3/ 7/ 5:Tmp=X[0,1]>>>24
+       fpadd32         @X[$j],@X[$j],@X[$j]            ! 4/ 8/ 6:X[0,1]<<=1
+       fmul8ulx16      %f18,$fmul,%f18                 ! 5/10/ 7:Tmp>>=7, Tmp&=1
+       ![fxors         %f15,%f2,%f2]
+       for             %f18,@X[$j],@X[$j]              ! 8/14/10:X[0,1]|=Tmp
+       ![fxors         %f0,%f3,%f3]                    !10/17/12:X[0] dependency
+       fpadd32         $K,@X[$j],%f20
+       std             %f20,[$Xfer+`4*$j`]
+___
+# The numbers delimited with slash are the earliest possible dispatch
+# cycles for given instruction assuming 1 cycle latency for simple VIS
+# instructions, such as on UltraSPARC-I&II, 3 cycles latency, such as
+# on UltraSPARC-III&IV, and 2 cycles latency(*), respectively. Being
+# 2x-parallelized the procedure is "worth" 5, 8.5 or 6 ticks per SHA1
+# round. As [long as] FPU/VIS instructions are perfectly pairable with
+# IALU ones, the round timing is defined by the maximum between VIS
+# and IALU timings. The latter varies from round to round and averages
+# out at 6.25 ticks. This means that USI&II should operate at IALU
+# rate, while USIII&IV - at VIS rate. This explains why performance
+# improvement varies among processors. Well, given that pure IALU
+# sha1-sparcv9.pl module exhibits virtually uniform performance of
+# ~9.3 cycles per SHA1 round. Timings mentioned above are theoretical
+# lower limits. Real-life performance was measured to be 6.6 cycles
+# per SHA1 round on USIIi and 8.3 on USIII. The latter is lower than
+# half-round VIS timing, because there are 16 Xupdate-free rounds,
+# which "push down" average theoretical timing to 8 cycles...
+
+# (*)  SPARC64-V[II] was originally believed to have 2 cycles VIS
+#      latency. Well, it might have, but it doesn't have dedicated
+#      VIS-unit. Instead, VIS instructions are executed by other
+#      functional units, ones used here - by IALU. This doesn't
+#      improve effective ILP...
+}
+
+# The reference Xupdate procedure is then "strained" over *pairs* of
+# BODY_NN_MM and kind of modulo-scheduled in respect to X[n]^=X[n+13]
+# and K_NN_MM addition. It's "running" 15 rounds ahead, which leaves
+# plenty of room to amortize for read-after-write hazard, as well as
+# to fetch and align input for the next spin. The VIS instructions are
+# scheduled for latency of 2 cycles, because there are not enough IALU
+# instructions to schedule for latency of 3, while scheduling for 1
+# would give no gain on USI&II anyway.
+
+sub BODY_00_19 {
+my ($i,$a,$b,$c,$d,$e)=@_;
+my $j=$i&~1;
+my $k=($j+16+2)%16;    # ahead reference
+my $l=($j+16-2)%16;    # behind reference
+my $K=@VK[($j+16-2)/20];
+
+$j=($j+16)%16;
+
+$code.=<<___ if (!($i&1));
+       sll             $a,5,$tmp0                      !! $i
+       and             $c,$b,$tmp3
+       ld              [$Xfer+`4*($i%16)`],$Xi
+        fxors          @X[($j+14)%16],@X[$j+1],@X[$j+1]! 0/ 0/ 0:X[1]^=X[14]
+       srl             $a,27,$tmp1
+       add             $tmp0,$e,$e
+        fxor           @X[($j+2)%16],@X[($j+8)%16],%f18! 1/ 1/ 1:Tmp=X[2,3]^X[8,9]
+       sll             $b,30,$tmp2
+       add             $tmp1,$e,$e
+       andn            $d,$b,$tmp1
+       add             $Xi,$e,$e
+        fxor           %f18,@X[$j],@X[$j]              ! 2/ 4/ 3:X[0,1]^=X[2,3]^X[8,9]
+       srl             $b,2,$b
+       or              $tmp1,$tmp3,$tmp1
+       or              $tmp2,$b,$b
+       add             $tmp1,$e,$e
+        faligndata     @X[$j],@X[$j],%f18              ! 3/ 7/ 5:Tmp=X[0,1]>>>24
+___
+$code.=<<___ if ($i&1);
+       sll             $a,5,$tmp0                      !! $i
+       and             $c,$b,$tmp3
+       ld              [$Xfer+`4*($i%16)`],$Xi
+        fpadd32        @X[$j],@X[$j],@X[$j]            ! 4/ 8/ 6:X[0,1]<<=1
+       srl             $a,27,$tmp1
+       add             $tmp0,$e,$e
+        fmul8ulx16     %f18,$fmul,%f18                 ! 5/10/ 7:Tmp>>=7, Tmp&=1
+       sll             $b,30,$tmp2
+       add             $tmp1,$e,$e
+        fpadd32        $K,@X[$l],%f20                  !
+       andn            $d,$b,$tmp1
+       add             $Xi,$e,$e
+        fxors          @X[($k+13)%16],@X[$k],@X[$k]    !-1/-1/-1:X[0]^=X[13]
+       srl             $b,2,$b
+       or              $tmp1,$tmp3,$tmp1
+        fxor           %f18,@X[$j],@X[$j]              ! 8/14/10:X[0,1]|=Tmp
+       or              $tmp2,$b,$b
+       add             $tmp1,$e,$e
+___
+$code.=<<___ if ($i&1 && $i>=2);
+        std            %f20,[$Xfer+`4*$l`]             !
+___
+}
+
+sub BODY_20_39 {
+my ($i,$a,$b,$c,$d,$e)=@_;
+my $j=$i&~1;
+my $k=($j+16+2)%16;    # ahead reference
+my $l=($j+16-2)%16;    # behind reference
+my $K=@VK[($j+16-2)/20];
+
+$j=($j+16)%16;
+
+$code.=<<___ if (!($i&1) && $i<64);
+       sll             $a,5,$tmp0                      !! $i
+       ld              [$Xfer+`4*($i%16)`],$Xi
+        fxors          @X[($j+14)%16],@X[$j+1],@X[$j+1]! 0/ 0/ 0:X[1]^=X[14]
+       srl             $a,27,$tmp1
+       add             $tmp0,$e,$e
+        fxor           @X[($j+2)%16],@X[($j+8)%16],%f18! 1/ 1/ 1:Tmp=X[2,3]^X[8,9]
+       xor             $c,$b,$tmp0
+       add             $tmp1,$e,$e
+       sll             $b,30,$tmp2
+       xor             $d,$tmp0,$tmp1
+        fxor           %f18,@X[$j],@X[$j]              ! 2/ 4/ 3:X[0,1]^=X[2,3]^X[8,9]
+       srl             $b,2,$b
+       add             $tmp1,$e,$e
+       or              $tmp2,$b,$b
+       add             $Xi,$e,$e
+        faligndata     @X[$j],@X[$j],%f18              ! 3/ 7/ 5:Tmp=X[0,1]>>>24
+___
+$code.=<<___ if ($i&1 && $i<64);
+       sll             $a,5,$tmp0                      !! $i
+       ld              [$Xfer+`4*($i%16)`],$Xi
+        fpadd32        @X[$j],@X[$j],@X[$j]            ! 4/ 8/ 6:X[0,1]<<=1
+       srl             $a,27,$tmp1
+       add             $tmp0,$e,$e
+        fmul8ulx16     %f18,$fmul,%f18                 ! 5/10/ 7:Tmp>>=7, Tmp&=1
+       xor             $c,$b,$tmp0
+       add             $tmp1,$e,$e
+        fpadd32        $K,@X[$l],%f20                  !
+       sll             $b,30,$tmp2
+       xor             $d,$tmp0,$tmp1
+        fxors          @X[($k+13)%16],@X[$k],@X[$k]    !-1/-1/-1:X[0]^=X[13]
+       srl             $b,2,$b
+       add             $tmp1,$e,$e
+        fxor           %f18,@X[$j],@X[$j]              ! 8/14/10:X[0,1]|=Tmp
+       or              $tmp2,$b,$b
+       add             $Xi,$e,$e
+        std            %f20,[$Xfer+`4*$l`]             !
+___
+$code.=<<___ if ($i==64);
+       sll             $a,5,$tmp0                      !! $i
+       ld              [$Xfer+`4*($i%16)`],$Xi
+        fpadd32        $K,@X[$l],%f20
+       srl             $a,27,$tmp1
+       add             $tmp0,$e,$e
+       xor             $c,$b,$tmp0
+       add             $tmp1,$e,$e
+       sll             $b,30,$tmp2
+       xor             $d,$tmp0,$tmp1
+        std            %f20,[$Xfer+`4*$l`]
+       srl             $b,2,$b
+       add             $tmp1,$e,$e
+       or              $tmp2,$b,$b
+       add             $Xi,$e,$e
+___
+$code.=<<___ if ($i>64);
+       sll             $a,5,$tmp0                      !! $i
+       ld              [$Xfer+`4*($i%16)`],$Xi
+       srl             $a,27,$tmp1
+       add             $tmp0,$e,$e
+       xor             $c,$b,$tmp0
+       add             $tmp1,$e,$e
+       sll             $b,30,$tmp2
+       xor             $d,$tmp0,$tmp1
+       srl             $b,2,$b
+       add             $tmp1,$e,$e
+       or              $tmp2,$b,$b
+       add             $Xi,$e,$e
+___
+}
+
+sub BODY_40_59 {
+my ($i,$a,$b,$c,$d,$e)=@_;
+my $j=$i&~1;
+my $k=($j+16+2)%16;    # ahead reference
+my $l=($j+16-2)%16;    # behind reference
+my $K=@VK[($j+16-2)/20];
+
+$j=($j+16)%16;
+
+$code.=<<___ if (!($i&1));
+       sll             $a,5,$tmp0                      !! $i
+       ld              [$Xfer+`4*($i%16)`],$Xi
+        fxors          @X[($j+14)%16],@X[$j+1],@X[$j+1]! 0/ 0/ 0:X[1]^=X[14]
+       srl             $a,27,$tmp1
+       add             $tmp0,$e,$e
+        fxor           @X[($j+2)%16],@X[($j+8)%16],%f18! 1/ 1/ 1:Tmp=X[2,3]^X[8,9]
+       and             $c,$b,$tmp0
+       add             $tmp1,$e,$e
+       sll             $b,30,$tmp2
+       or              $c,$b,$tmp1
+        fxor           %f18,@X[$j],@X[$j]              ! 2/ 4/ 3:X[0,1]^=X[2,3]^X[8,9]
+       srl             $b,2,$b
+       and             $d,$tmp1,$tmp1
+       add             $Xi,$e,$e
+       or              $tmp1,$tmp0,$tmp1
+        faligndata     @X[$j],@X[$j],%f18              ! 3/ 7/ 5:Tmp=X[0,1]>>>24
+       or              $tmp2,$b,$b
+       add             $tmp1,$e,$e
+        fpadd32        @X[$j],@X[$j],@X[$j]            ! 4/ 8/ 6:X[0,1]<<=1
+___
+$code.=<<___ if ($i&1);
+       sll             $a,5,$tmp0                      !! $i
+       ld              [$Xfer+`4*($i%16)`],$Xi
+       srl             $a,27,$tmp1
+       add             $tmp0,$e,$e
+        fmul8ulx16     %f18,$fmul,%f18                 ! 5/10/ 7:Tmp>>=7, Tmp&=1
+       and             $c,$b,$tmp0
+       add             $tmp1,$e,$e
+        fpadd32        $K,@X[$l],%f20                  !
+       sll             $b,30,$tmp2
+       or              $c,$b,$tmp1
+        fxors          @X[($k+13)%16],@X[$k],@X[$k]    !-1/-1/-1:X[0]^=X[13]
+       srl             $b,2,$b
+       and             $d,$tmp1,$tmp1
+        fxor           %f18,@X[$j],@X[$j]              ! 8/14/10:X[0,1]|=Tmp
+       add             $Xi,$e,$e
+       or              $tmp1,$tmp0,$tmp1
+       or              $tmp2,$b,$b
+       add             $tmp1,$e,$e
+        std            %f20,[$Xfer+`4*$l`]             !
+___
+}
+
+# If there is more data to process, then we pre-fetch the data for
+# next iteration in last ten rounds...
+sub BODY_70_79 {
+my ($i,$a,$b,$c,$d,$e)=@_;
+my $j=$i&~1;
+my $m=($i%8)*2;
+
+$j=($j+16)%16;
+
+$code.=<<___ if ($i==70);
+       sll             $a,5,$tmp0                      !! $i
+       ld              [$Xfer+`4*($i%16)`],$Xi
+       srl             $a,27,$tmp1
+       add             $tmp0,$e,$e
+        ldd            [$inp+64],@X[0]
+       xor             $c,$b,$tmp0
+       add             $tmp1,$e,$e
+       sll             $b,30,$tmp2
+       xor             $d,$tmp0,$tmp1
+       srl             $b,2,$b
+       add             $tmp1,$e,$e
+       or              $tmp2,$b,$b
+       add             $Xi,$e,$e
+
+       and             $inp,-64,$nXfer
+       inc             64,$inp
+       and             $nXfer,255,$nXfer
+       alignaddr       %g0,$align,%g0
+       add             $base,$nXfer,$nXfer
+___
+$code.=<<___ if ($i==71);
+       sll             $a,5,$tmp0                      !! $i
+       ld              [$Xfer+`4*($i%16)`],$Xi
+       srl             $a,27,$tmp1
+       add             $tmp0,$e,$e
+       xor             $c,$b,$tmp0
+       add             $tmp1,$e,$e
+       sll             $b,30,$tmp2
+       xor             $d,$tmp0,$tmp1
+       srl             $b,2,$b
+       add             $tmp1,$e,$e
+       or              $tmp2,$b,$b
+       add             $Xi,$e,$e
+___
+$code.=<<___ if ($i>=72);
+        faligndata     @X[$m],@X[$m+2],@X[$m]
+       sll             $a,5,$tmp0                      !! $i
+       ld              [$Xfer+`4*($i%16)`],$Xi
+       srl             $a,27,$tmp1
+       add             $tmp0,$e,$e
+       xor             $c,$b,$tmp0
+       add             $tmp1,$e,$e
+        fpadd32        $VK_00_19,@X[$m],%f20
+       sll             $b,30,$tmp2
+       xor             $d,$tmp0,$tmp1
+       srl             $b,2,$b
+       add             $tmp1,$e,$e
+       or              $tmp2,$b,$b
+       add             $Xi,$e,$e
+___
+$code.=<<___ if ($i<77);
+        ldd            [$inp+`8*($i+1-70)`],@X[2*($i+1-70)]
+___
+$code.=<<___ if ($i==77);      # redundant if $inp was aligned
+        add            $align,63,$tmp0
+        and            $tmp0,-8,$tmp0
+        ldd            [$inp+$tmp0],@X[16]
+___
+$code.=<<___ if ($i>=72);
+        std            %f20,[$nXfer+`4*$m`]
+___
+}
+
+$code.=<<___;
+.section       ".text",#alloc,#execinstr
+
+.align 64
+vis_const:
+.long  0x5a827999,0x5a827999   ! K_00_19
+.long  0x6ed9eba1,0x6ed9eba1   ! K_20_39
+.long  0x8f1bbcdc,0x8f1bbcdc   ! K_40_59
+.long  0xca62c1d6,0xca62c1d6   ! K_60_79
+.long  0x00000100,0x00000100
+.align 64
+.type  vis_const,#object
+.size  vis_const,(.-vis_const)
+
+.globl sha1_block_data_order
+sha1_block_data_order:
+       save    %sp,-$frame,%sp
+       add     %fp,$bias-256,$base
+
+1:     call    .+8
+       add     %o7,vis_const-1b,$tmp0
+
+       ldd     [$tmp0+0],$VK_00_19
+       ldd     [$tmp0+8],$VK_20_39
+       ldd     [$tmp0+16],$VK_40_59
+       ldd     [$tmp0+24],$VK_60_79
+       ldd     [$tmp0+32],$fmul
+
+       ld      [$ctx+0],$Actx
+       and     $base,-256,$base
+       ld      [$ctx+4],$Bctx
+       sub     $base,$bias+$frame,%sp
+       ld      [$ctx+8],$Cctx
+       and     $inp,7,$align
+       ld      [$ctx+12],$Dctx
+       and     $inp,-8,$inp
+       ld      [$ctx+16],$Ectx
+
+       ! X[16] is maintained in FP register bank
+       alignaddr       %g0,$align,%g0
+       ldd             [$inp+0],@X[0]
+       sub             $inp,-64,$Xfer
+       ldd             [$inp+8],@X[2]
+       and             $Xfer,-64,$Xfer
+       ldd             [$inp+16],@X[4]
+       and             $Xfer,255,$Xfer
+       ldd             [$inp+24],@X[6]
+       add             $base,$Xfer,$Xfer
+       ldd             [$inp+32],@X[8]
+       ldd             [$inp+40],@X[10]
+       ldd             [$inp+48],@X[12]
+       brz,pt          $align,.Laligned
+       ldd             [$inp+56],@X[14]
+
+       ldd             [$inp+64],@X[16]
+       faligndata      @X[0],@X[2],@X[0]
+       faligndata      @X[2],@X[4],@X[2]
+       faligndata      @X[4],@X[6],@X[4]
+       faligndata      @X[6],@X[8],@X[6]
+       faligndata      @X[8],@X[10],@X[8]
+       faligndata      @X[10],@X[12],@X[10]
+       faligndata      @X[12],@X[14],@X[12]
+       faligndata      @X[14],@X[16],@X[14]
+
+.Laligned:
+       mov             5,$tmp0
+       dec             1,$len
+       alignaddr       %g0,$tmp0,%g0
+       fpadd32         $VK_00_19,@X[0],%f16
+       fpadd32         $VK_00_19,@X[2],%f18
+       fpadd32         $VK_00_19,@X[4],%f20
+       fpadd32         $VK_00_19,@X[6],%f22
+       fpadd32         $VK_00_19,@X[8],%f24
+       fpadd32         $VK_00_19,@X[10],%f26
+       fpadd32         $VK_00_19,@X[12],%f28
+       fpadd32         $VK_00_19,@X[14],%f30
+       std             %f16,[$Xfer+0]
+       mov             $Actx,$A
+       std             %f18,[$Xfer+8]
+       mov             $Bctx,$B
+       std             %f20,[$Xfer+16]
+       mov             $Cctx,$C
+       std             %f22,[$Xfer+24]
+       mov             $Dctx,$D
+       std             %f24,[$Xfer+32]
+       mov             $Ectx,$E
+       std             %f26,[$Xfer+40]
+       fxors           @X[13],@X[0],@X[0]
+       std             %f28,[$Xfer+48]
+       ba              .Loop
+       std             %f30,[$Xfer+56]
+.align 32
+.Loop:
+___
+for ($i=0;$i<20;$i++)  { &BODY_00_19($i,@V); unshift(@V,pop(@V)); }
+for (;$i<40;$i++)      { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
+for (;$i<60;$i++)      { &BODY_40_59($i,@V); unshift(@V,pop(@V)); }
+for (;$i<70;$i++)      { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
+$code.=<<___;
+       tst             $len
+       bz,pn           `$bits==32?"%icc":"%xcc"`,.Ltail
+       nop
+___
+for (;$i<80;$i++)      { &BODY_70_79($i,@V); unshift(@V,pop(@V)); }
+$code.=<<___;
+       add             $A,$Actx,$Actx
+       add             $B,$Bctx,$Bctx
+       add             $C,$Cctx,$Cctx
+       add             $D,$Dctx,$Dctx
+       add             $E,$Ectx,$Ectx
+       mov             5,$tmp0
+       fxors           @X[13],@X[0],@X[0]
+       mov             $Actx,$A
+       mov             $Bctx,$B
+       mov             $Cctx,$C
+       mov             $Dctx,$D
+       mov             $Ectx,$E
+       alignaddr       %g0,$tmp0,%g0   
+       dec             1,$len
+       ba              .Loop
+       mov             $nXfer,$Xfer
+
+.align 32
+.Ltail:
+___
+for($i=70;$i<80;$i++)  { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
+$code.=<<___;
+       add     $A,$Actx,$Actx
+       add     $B,$Bctx,$Bctx
+       add     $C,$Cctx,$Cctx
+       add     $D,$Dctx,$Dctx
+       add     $E,$Ectx,$Ectx
+
+       st      $Actx,[$ctx+0]
+       st      $Bctx,[$ctx+4]
+       st      $Cctx,[$ctx+8]
+       st      $Dctx,[$ctx+12]
+       st      $Ectx,[$ctx+16]
+
+       ret
+       restore
+.type  sha1_block_data_order,#function
+.size  sha1_block_data_order,(.-sha1_block_data_order)
+.asciz "SHA1 block transform for SPARCv9a, CRYPTOGAMS by <appro\@openssl.org>"
+.align 4
+___
+
+# Purpose of these subroutines is to explicitly encode VIS instructions,
+# so that one can compile the module without having to specify VIS
+# extentions on compiler command line, e.g. -xarch=v9 vs. -xarch=v9a.
+# Idea is to reserve for option to produce "universal" binary and let
+# programmer detect if current CPU is VIS capable at run-time.
+sub unvis {
+my ($mnemonic,$rs1,$rs2,$rd)=@_;
+my $ref,$opf;
+my %visopf = ( "fmul8ulx16"    => 0x037,
+               "faligndata"    => 0x048,
+               "fpadd32"       => 0x052,
+               "fxor"          => 0x06c,
+               "fxors"         => 0x06d        );
+
+    $ref = "$mnemonic\t$rs1,$rs2,$rd";
+
+    if ($opf=$visopf{$mnemonic}) {
+       foreach ($rs1,$rs2,$rd) {
+           return $ref if (!/%f([0-9]{1,2})/);
+           $_=$1;
+           if ($1>=32) {
+               return $ref if ($1&1);
+               # re-encode for upper double register addressing
+               $_=($1|$1>>5)&31;
+           }
+       }
+
+       return  sprintf ".word\t0x%08x !%s",
+                       0x81b00000|$rd<<25|$rs1<<14|$opf<<5|$rs2,
+                       $ref;
+    } else {
+       return $ref;
+    }
+}
+sub unalignaddr {
+my ($mnemonic,$rs1,$rs2,$rd)=@_;
+my %bias = ( "g" => 0, "o" => 8, "l" => 16, "i" => 24 );
+my $ref="$mnemonic\t$rs1,$rs2,$rd";
+
+    foreach ($rs1,$rs2,$rd) {
+       if (/%([goli])([0-7])/) { $_=$bias{$1}+$2; }
+       else                    { return $ref; }
+    }
+    return  sprintf ".word\t0x%08x !%s",
+                   0x81b00300|$rd<<25|$rs1<<14|$rs2,
+                   $ref;
+}
+
+$code =~ s/\`([^\`]*)\`/eval $1/gem;
+$code =~ s/\b(f[^\s]*)\s+(%f[0-9]{1,2}),(%f[0-9]{1,2}),(%f[0-9]{1,2})/
+               &unvis($1,$2,$3,$4)
+         /gem;
+$code =~ s/\b(alignaddr)\s+(%[goli][0-7]),(%[goli][0-7]),(%[goli][0-7])/
+               &unalignaddr($1,$2,$3,$4)
+         /gem;
+print $code;
+close STDOUT;
diff --git a/deps/openssl/openssl/crypto/sha/asm/sha1-thumb.pl b/deps/openssl/openssl/crypto/sha/asm/sha1-thumb.pl
new file mode 100644 (file)
index 0000000..7c9ea9b
--- /dev/null
@@ -0,0 +1,259 @@
+#!/usr/bin/env perl
+
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+
+# sha1_block for Thumb.
+#
+# January 2007.
+#
+# The code does not present direct interest to OpenSSL, because of low
+# performance. Its purpose is to establish _size_ benchmark. Pretty
+# useless one I must say, because 30% or 88 bytes larger ARMv4 code
+# [avialable on demand] is almost _twice_ as fast. It should also be
+# noted that in-lining of .Lcommon and .Lrotate improves performance
+# by over 40%, while code increases by only 10% or 32 bytes. But once
+# again, the goal was to establish _size_ benchmark, not performance.
+
+$output=shift;
+open STDOUT,">$output";
+
+$inline=0;
+#$cheat_on_binutils=1;
+
+$t0="r0";
+$t1="r1";
+$t2="r2";
+$a="r3";
+$b="r4";
+$c="r5";
+$d="r6";
+$e="r7";
+$K="r8";       # "upper" registers can be used in add/sub and mov insns
+$ctx="r9";
+$inp="r10";
+$len="r11";
+$Xi="r12";
+
+sub common {
+<<___;
+       sub     $t0,#4
+       ldr     $t1,[$t0]
+       add     $e,$K                   @ E+=K_xx_xx
+       lsl     $t2,$a,#5
+       add     $t2,$e
+       lsr     $e,$a,#27
+       add     $t2,$e                  @ E+=ROR(A,27)
+       add     $t2,$t1                 @ E+=X[i]
+___
+}
+sub rotate {
+<<___;
+       mov     $e,$d                   @ E=D
+       mov     $d,$c                   @ D=C
+       lsl     $c,$b,#30
+       lsr     $b,$b,#2
+       orr     $c,$b                   @ C=ROR(B,2)
+       mov     $b,$a                   @ B=A
+       add     $a,$t2,$t1              @ A=E+F_xx_xx(B,C,D)
+___
+}
+
+sub BODY_00_19 {
+$code.=$inline?&common():"\tbl .Lcommon\n";
+$code.=<<___;
+       mov     $t1,$c
+       eor     $t1,$d
+       and     $t1,$b
+       eor     $t1,$d                  @ F_00_19(B,C,D)
+___
+$code.=$inline?&rotate():"\tbl .Lrotate\n";
+}
+
+sub BODY_20_39 {
+$code.=$inline?&common():"\tbl .Lcommon\n";
+$code.=<<___;
+       mov     $t1,$b
+       eor     $t1,$c
+       eor     $t1,$d                  @ F_20_39(B,C,D)
+___
+$code.=$inline?&rotate():"\tbl .Lrotate\n";
+}
+
+sub BODY_40_59 {
+$code.=$inline?&common():"\tbl .Lcommon\n";
+$code.=<<___;
+       mov     $t1,$b
+       and     $t1,$c
+       mov     $e,$b
+       orr     $e,$c
+       and     $e,$d
+       orr     $t1,$e                  @ F_40_59(B,C,D)
+___
+$code.=$inline?&rotate():"\tbl .Lrotate\n";
+}
+
+$code=<<___;
+.text
+.code  16
+
+.global        sha1_block_data_order
+.type  sha1_block_data_order,%function
+
+.align 2
+sha1_block_data_order:
+___
+if ($cheat_on_binutils) {
+$code.=<<___;
+.code  32
+       add     r3,pc,#1
+       bx      r3                      @ switch to Thumb ISA
+.code  16
+___
+}
+$code.=<<___;
+       push    {r4-r7}
+       mov     r3,r8
+       mov     r4,r9
+       mov     r5,r10
+       mov     r6,r11
+       mov     r7,r12
+       push    {r3-r7,lr}
+       lsl     r2,#6
+       mov     $ctx,r0                 @ save context
+       mov     $inp,r1                 @ save inp
+       mov     $len,r2                 @ save len
+       add     $len,$inp               @ $len to point at inp end
+
+.Lloop:
+       mov     $Xi,sp
+       mov     $t2,sp
+       sub     $t2,#16*4               @ [3]
+.LXload:
+       ldrb    $a,[$t1,#0]             @ $t1 is r1 and holds inp
+       ldrb    $b,[$t1,#1]
+       ldrb    $c,[$t1,#2]
+       ldrb    $d,[$t1,#3]
+       lsl     $a,#24
+       lsl     $b,#16
+       lsl     $c,#8
+       orr     $a,$b
+       orr     $a,$c
+       orr     $a,$d
+       add     $t1,#4
+       push    {$a}
+       cmp     sp,$t2
+       bne     .LXload                 @ [+14*16]
+
+       mov     $inp,$t1                @ update $inp
+       sub     $t2,#32*4
+       sub     $t2,#32*4
+       mov     $e,#31                  @ [+4]
+.LXupdate:
+       ldr     $a,[sp,#15*4]
+       ldr     $b,[sp,#13*4]
+       ldr     $c,[sp,#7*4]
+       ldr     $d,[sp,#2*4]
+       eor     $a,$b
+       eor     $a,$c
+       eor     $a,$d
+       ror     $a,$e
+       push    {$a}
+       cmp     sp,$t2
+       bne     .LXupdate               @ [+(11+1)*64]
+
+       ldmia   $t0!,{$a,$b,$c,$d,$e}   @ $t0 is r0 and holds ctx
+       mov     $t0,$Xi
+
+       ldr     $t2,.LK_00_19
+       mov     $t1,$t0
+       sub     $t1,#20*4
+       mov     $Xi,$t1
+       mov     $K,$t2                  @ [+7+4]
+.L_00_19:
+___
+       &BODY_00_19();
+$code.=<<___;
+       cmp     $Xi,$t0
+       bne     .L_00_19                @ [+(2+9+4+2+8+2)*20]
+
+       ldr     $t2,.LK_20_39
+       mov     $t1,$t0
+       sub     $t1,#20*4
+       mov     $Xi,$t1
+       mov     $K,$t2                  @ [+5]
+.L_20_39_or_60_79:
+___
+       &BODY_20_39();
+$code.=<<___;
+       cmp     $Xi,$t0
+       bne     .L_20_39_or_60_79       @ [+(2+9+3+2+8+2)*20*2]
+       cmp     sp,$t0
+       beq     .Ldone                  @ [+2]
+
+       ldr     $t2,.LK_40_59
+       mov     $t1,$t0
+       sub     $t1,#20*4
+       mov     $Xi,$t1
+       mov     $K,$t2                  @ [+5]
+.L_40_59:
+___
+       &BODY_40_59();
+$code.=<<___;
+       cmp     $Xi,$t0
+       bne     .L_40_59                @ [+(2+9+6+2+8+2)*20]
+
+       ldr     $t2,.LK_60_79
+       mov     $Xi,sp
+       mov     $K,$t2
+       b       .L_20_39_or_60_79       @ [+4]
+.Ldone:
+       mov     $t0,$ctx
+       ldr     $t1,[$t0,#0]
+       ldr     $t2,[$t0,#4]
+       add     $a,$t1
+       ldr     $t1,[$t0,#8]
+       add     $b,$t2
+       ldr     $t2,[$t0,#12]
+       add     $c,$t1
+       ldr     $t1,[$t0,#16]
+       add     $d,$t2
+       add     $e,$t1
+       stmia   $t0!,{$a,$b,$c,$d,$e}   @ [+20]
+
+       add     sp,#80*4                @ deallocate stack frame
+       mov     $t0,$ctx                @ restore ctx
+       mov     $t1,$inp                @ restore inp
+       cmp     $t1,$len
+       beq     .Lexit
+       b       .Lloop                  @ [+6] total 3212 cycles
+.Lexit:
+       pop     {r2-r7}
+       mov     r8,r2
+       mov     r9,r3
+       mov     r10,r4
+       mov     r11,r5
+       mov     r12,r6
+       mov     lr,r7
+       pop     {r4-r7}
+       bx      lr
+.align 2
+___
+$code.=".Lcommon:\n".&common()."\tmov  pc,lr\n" if (!$inline);
+$code.=".Lrotate:\n".&rotate()."\tmov  pc,lr\n" if (!$inline);
+$code.=<<___;
+.align 2
+.LK_00_19:     .word   0x5a827999
+.LK_20_39:     .word   0x6ed9eba1
+.LK_40_59:     .word   0x8f1bbcdc
+.LK_60_79:     .word   0xca62c1d6
+.size  sha1_block_data_order,.-sha1_block_data_order
+.asciz "SHA1 block transform for Thumb, CRYPTOGAMS by <appro\@openssl.org>"
+___
+
+print $code;
+close STDOUT; # enforce flush
index f7ed67a..4edc5ea 100755 (executable)
 # Xeon P4      +65%            +0%             9.9
 # Core2                +60%            +10%            7.0
 
-$output=shift;
+$flavour = shift;
+$output  = shift;
+if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
+
+$win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
 
 $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
 ( $xlate="${dir}x86_64-xlate.pl" and -f $xlate ) or
 ( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
 die "can't locate x86_64-xlate.pl";
 
-open STDOUT,"| $^X $xlate $output";
+open STDOUT,"| $^X $xlate $flavour $output";
 
 $ctx="%rdi";   # 1st arg
 $inp="%rsi";   # 2nd arg
@@ -69,13 +73,14 @@ $func:
        push    %rbx
        push    %rbp
        push    %r12
-       mov     %rsp,%rax
+       mov     %rsp,%r11
        mov     %rdi,$ctx       # reassigned argument
        sub     \$`8+16*4`,%rsp
        mov     %rsi,$inp       # reassigned argument
        and     \$-64,%rsp
        mov     %rdx,$num       # reassigned argument
-       mov     %rax,`16*4`(%rsp)
+       mov     %r11,`16*4`(%rsp)
+.Lprologue:
 
        mov     0($ctx),$A
        mov     4($ctx),$B
@@ -88,10 +93,12 @@ ___
 sub EPILOGUE {
 my $func=shift;
 $code.=<<___;
-       mov     `16*4`(%rsp),%rsp
-       pop     %r12
-       pop     %rbp
-       pop     %rbx
+       mov     `16*4`(%rsp),%rsi
+       mov     (%rsi),%r12
+       mov     8(%rsi),%rbp
+       mov     16(%rsi),%rbx
+       lea     24(%rsi),%rsp
+.Lepilogue:
        ret
 .size  $func,.-$func
 ___
@@ -233,7 +240,109 @@ ___
 &EPILOGUE("sha1_block_data_order");
 $code.=<<___;
 .asciz "SHA1 block transform for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
+.align 16
+___
+
+# EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
+#              CONTEXT *context,DISPATCHER_CONTEXT *disp)
+if ($win64) {
+$rec="%rcx";
+$frame="%rdx";
+$context="%r8";
+$disp="%r9";
+
+$code.=<<___;
+.extern        __imp_RtlVirtualUnwind
+.type  se_handler,\@abi-omnipotent
+.align 16
+se_handler:
+       push    %rsi
+       push    %rdi
+       push    %rbx
+       push    %rbp
+       push    %r12
+       push    %r13
+       push    %r14
+       push    %r15
+       pushfq
+       sub     \$64,%rsp
+
+       mov     120($context),%rax      # pull context->Rax
+       mov     248($context),%rbx      # pull context->Rip
+
+       lea     .Lprologue(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip<.Lprologue
+       jb      .Lin_prologue
+
+       mov     152($context),%rax      # pull context->Rsp
+
+       lea     .Lepilogue(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip>=.Lepilogue
+       jae     .Lin_prologue
+
+       mov     `16*4`(%rax),%rax       # pull saved stack pointer
+       lea     24(%rax),%rax
+
+       mov     -8(%rax),%rbx
+       mov     -16(%rax),%rbp
+       mov     -24(%rax),%r12
+       mov     %rbx,144($context)      # restore context->Rbx
+       mov     %rbp,160($context)      # restore context->Rbp
+       mov     %r12,216($context)      # restore context->R12
+
+.Lin_prologue:
+       mov     8(%rax),%rdi
+       mov     16(%rax),%rsi
+       mov     %rax,152($context)      # restore context->Rsp
+       mov     %rsi,168($context)      # restore context->Rsi
+       mov     %rdi,176($context)      # restore context->Rdi
+
+       mov     40($disp),%rdi          # disp->ContextRecord
+       mov     $context,%rsi           # context
+       mov     \$154,%ecx              # sizeof(CONTEXT)
+       .long   0xa548f3fc              # cld; rep movsq
+
+       mov     $disp,%rsi
+       xor     %rcx,%rcx               # arg1, UNW_FLAG_NHANDLER
+       mov     8(%rsi),%rdx            # arg2, disp->ImageBase
+       mov     0(%rsi),%r8             # arg3, disp->ControlPc
+       mov     16(%rsi),%r9            # arg4, disp->FunctionEntry
+       mov     40(%rsi),%r10           # disp->ContextRecord
+       lea     56(%rsi),%r11           # &disp->HandlerData
+       lea     24(%rsi),%r12           # &disp->EstablisherFrame
+       mov     %r10,32(%rsp)           # arg5
+       mov     %r11,40(%rsp)           # arg6
+       mov     %r12,48(%rsp)           # arg7
+       mov     %rcx,56(%rsp)           # arg8, (NULL)
+       call    *__imp_RtlVirtualUnwind(%rip)
+
+       mov     \$1,%eax                # ExceptionContinueSearch
+       add     \$64,%rsp
+       popfq
+       pop     %r15
+       pop     %r14
+       pop     %r13
+       pop     %r12
+       pop     %rbp
+       pop     %rbx
+       pop     %rdi
+       pop     %rsi
+       ret
+.size  se_handler,.-se_handler
+
+.section       .pdata
+.align 4
+       .rva    .LSEH_begin_sha1_block_data_order
+       .rva    .LSEH_end_sha1_block_data_order
+       .rva    .LSEH_info_sha1_block_data_order
+
+.section       .xdata
+.align 8
+.LSEH_info_sha1_block_data_order:
+       .byte   9,0,0,0
+       .rva    se_handler
 ___
+}
 
 ####################################################################
 
diff --git a/deps/openssl/openssl/crypto/sha/asm/sha256-586.pl b/deps/openssl/openssl/crypto/sha/asm/sha256-586.pl
new file mode 100644 (file)
index 0000000..ecc8b69
--- /dev/null
@@ -0,0 +1,251 @@
+#!/usr/bin/env perl
+#
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+#
+# SHA256 block transform for x86. September 2007.
+#
+# Performance in clock cycles per processed byte (less is better):
+#
+#              Pentium PIII    P4      AMD K8  Core2
+# gcc          46      36      41      27      26
+# icc          57      33      38      25      23      
+# x86 asm      40      30      35      20      20
+# x86_64 asm(*)        -       -       21      15.8    16.5
+#
+# (*) x86_64 assembler performance is presented for reference
+#     purposes.
+#
+# Performance improvement over compiler generated code varies from
+# 10% to 40% [see above]. Not very impressive on some Âµ-archs, but
+# it's 5 times smaller and optimizies amount of writes.
+
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+push(@INC,"${dir}","${dir}../../perlasm");
+require "x86asm.pl";
+
+&asm_init($ARGV[0],"sha512-586.pl",$ARGV[$#ARGV] eq "386");
+
+$A="eax";
+$E="edx";
+$T="ebx";
+$Aoff=&DWP(0,"esp");
+$Boff=&DWP(4,"esp");
+$Coff=&DWP(8,"esp");
+$Doff=&DWP(12,"esp");
+$Eoff=&DWP(16,"esp");
+$Foff=&DWP(20,"esp");
+$Goff=&DWP(24,"esp");
+$Hoff=&DWP(28,"esp");
+$Xoff=&DWP(32,"esp");
+$K256="ebp";
+
+sub BODY_00_15() {
+    my $in_16_63=shift;
+
+       &mov    ("ecx",$E);
+        &add   ($T,&DWP(4*(8+15+16-9),"esp"))  if ($in_16_63); # T += X[-7]
+       &ror    ("ecx",6);
+       &mov    ("edi",$E);
+       &ror    ("edi",11);
+        &mov   ("esi",$Foff);
+       &xor    ("ecx","edi");
+       &ror    ("edi",25-11);
+        &mov   (&DWP(4*(8+15),"esp"),$T)       if ($in_16_63); # save X[0]
+       &xor    ("ecx","edi");  # Sigma1(e)
+        &mov   ("edi",$Goff);
+       &add    ($T,"ecx");     # T += Sigma1(e)
+        &mov   ($Eoff,$E);     # modulo-scheduled
+
+       &xor    ("esi","edi");
+        &mov   ("ecx",$A);
+       &and    ("esi",$E);
+        &mov   ($E,$Doff);     # e becomes d, which is e in next iteration
+       &xor    ("esi","edi");  # Ch(e,f,g)
+        &mov   ("edi",$A);
+       &add    ($T,"esi");     # T += Ch(e,f,g)
+
+       &ror    ("ecx",2);
+        &add   ($T,$Hoff);     # T += h
+       &ror    ("edi",13);
+        &mov   ("esi",$Boff);
+       &xor    ("ecx","edi");
+       &ror    ("edi",22-13);
+        &add   ($E,$T);        # d += T
+       &xor    ("ecx","edi");  # Sigma0(a)
+        &mov   ("edi",$Coff);
+
+       &add    ($T,"ecx");     # T += Sigma0(a)
+        &mov   ($Aoff,$A);     # modulo-scheduled
+
+       &mov    ("ecx",$A);
+        &sub   ("esp",4);
+       &or     ($A,"esi");     # a becomes h, which is a in next iteration
+       &and    ("ecx","esi");
+       &and    ($A,"edi");
+        &mov   ("esi",&DWP(0,$K256));
+       &or     ($A,"ecx");     # h=Maj(a,b,c)
+
+       &add    ($K256,4);
+       &add    ($A,$T);        # h += T
+        &mov   ($T,&DWP(4*(8+15+16-1),"esp"))  if ($in_16_63); # preload T
+       &add    ($E,"esi");     # d += K256[i]
+       &add    ($A,"esi");     # h += K256[i]
+}
+
+&function_begin("sha256_block_data_order");
+       &mov    ("esi",wparam(0));      # ctx
+       &mov    ("edi",wparam(1));      # inp
+       &mov    ("eax",wparam(2));      # num
+       &mov    ("ebx","esp");          # saved sp
+
+       &call   (&label("pic_point"));  # make it PIC!
+&set_label("pic_point");
+       &blindpop($K256);
+       &lea    ($K256,&DWP(&label("K256")."-".&label("pic_point"),$K256));
+
+       &sub    ("esp",16);
+       &and    ("esp",-64);
+
+       &shl    ("eax",6);
+       &add    ("eax","edi");
+       &mov    (&DWP(0,"esp"),"esi");  # ctx
+       &mov    (&DWP(4,"esp"),"edi");  # inp
+       &mov    (&DWP(8,"esp"),"eax");  # inp+num*128
+       &mov    (&DWP(12,"esp"),"ebx"); # saved sp
+
+&set_label("loop",16);
+    # copy input block to stack reversing byte and dword order
+    for($i=0;$i<4;$i++) {
+       &mov    ("eax",&DWP($i*16+0,"edi"));
+       &mov    ("ebx",&DWP($i*16+4,"edi"));
+       &mov    ("ecx",&DWP($i*16+8,"edi"));
+       &mov    ("edx",&DWP($i*16+12,"edi"));
+       &bswap  ("eax");
+       &bswap  ("ebx");
+       &bswap  ("ecx");
+       &bswap  ("edx");
+       &push   ("eax");
+       &push   ("ebx");
+       &push   ("ecx");
+       &push   ("edx");
+    }
+       &add    ("edi",64);
+       &sub    ("esp",4*8);            # place for A,B,C,D,E,F,G,H
+       &mov    (&DWP(4*(8+16)+4,"esp"),"edi");
+
+       # copy ctx->h[0-7] to A,B,C,D,E,F,G,H on stack
+       &mov    ($A,&DWP(0,"esi"));
+       &mov    ("ebx",&DWP(4,"esi"));
+       &mov    ("ecx",&DWP(8,"esi"));
+       &mov    ("edi",&DWP(12,"esi"));
+       # &mov  ($Aoff,$A);
+       &mov    ($Boff,"ebx");
+       &mov    ($Coff,"ecx");
+       &mov    ($Doff,"edi");
+       &mov    ($E,&DWP(16,"esi"));    
+       &mov    ("ebx",&DWP(20,"esi"));
+       &mov    ("ecx",&DWP(24,"esi"));
+       &mov    ("edi",&DWP(28,"esi"));
+       # &mov  ($Eoff,$E);
+       &mov    ($Foff,"ebx");
+       &mov    ($Goff,"ecx");
+       &mov    ($Hoff,"edi");
+
+&set_label("00_15",16);
+       &mov    ($T,&DWP(4*(8+15),"esp"));
+
+       &BODY_00_15();
+
+       &cmp    ("esi",0xc19bf174);
+       &jne    (&label("00_15"));
+
+       &mov    ($T,&DWP(4*(8+15+16-1),"esp")); # preloaded in BODY_00_15(1)
+&set_label("16_63",16);
+       &mov    ("esi",$T);
+        &mov   ("ecx",&DWP(4*(8+15+16-14),"esp"));
+       &shr    ($T,3);
+       &ror    ("esi",7);
+       &xor    ($T,"esi");
+       &ror    ("esi",18-7);
+        &mov   ("edi","ecx");
+       &xor    ($T,"esi");                     # T = sigma0(X[-15])
+
+       &shr    ("ecx",10);
+        &mov   ("esi",&DWP(4*(8+15+16),"esp"));
+       &ror    ("edi",17);
+       &xor    ("ecx","edi");
+       &ror    ("edi",19-17);
+        &add   ($T,"esi");                     # T += X[-16]
+       &xor    ("edi","ecx")                   # sigma1(X[-2])
+
+       &add    ($T,"edi");                     # T += sigma1(X[-2])
+       # &add  ($T,&DWP(4*(8+15+16-9),"esp")); # T += X[-7], moved to BODY_00_15(1)
+       # &mov  (&DWP(4*(8+15),"esp"),$T);      # save X[0]
+
+       &BODY_00_15(1);
+
+       &cmp    ("esi",0xc67178f2);
+       &jne    (&label("16_63"));
+
+       &mov    ("esi",&DWP(4*(8+16+64)+0,"esp"));#ctx
+       # &mov  ($A,$Aoff);
+       &mov    ("ebx",$Boff);
+       &mov    ("ecx",$Coff);
+       &mov    ("edi",$Doff);
+       &add    ($A,&DWP(0,"esi"));
+       &add    ("ebx",&DWP(4,"esi"));
+       &add    ("ecx",&DWP(8,"esi"));
+       &add    ("edi",&DWP(12,"esi"));
+       &mov    (&DWP(0,"esi"),$A);
+       &mov    (&DWP(4,"esi"),"ebx");
+       &mov    (&DWP(8,"esi"),"ecx");
+       &mov    (&DWP(12,"esi"),"edi");
+       # &mov  ($E,$Eoff);
+       &mov    ("eax",$Foff);
+       &mov    ("ebx",$Goff);
+       &mov    ("ecx",$Hoff);
+       &mov    ("edi",&DWP(4*(8+16+64)+4,"esp"));#inp
+       &add    ($E,&DWP(16,"esi"));
+       &add    ("eax",&DWP(20,"esi"));
+       &add    ("ebx",&DWP(24,"esi"));
+       &add    ("ecx",&DWP(28,"esi"));
+       &mov    (&DWP(16,"esi"),$E);
+       &mov    (&DWP(20,"esi"),"eax");
+       &mov    (&DWP(24,"esi"),"ebx");
+       &mov    (&DWP(28,"esi"),"ecx");
+
+       &add    ("esp",4*(8+16+64));            # destroy frame
+       &sub    ($K256,4*64);                   # rewind K
+
+       &cmp    ("edi",&DWP(8,"esp"));          # are we done yet?
+       &jb     (&label("loop"));
+
+       &mov    ("esp",&DWP(12,"esp"));         # restore sp
+&function_end_A();
+
+&set_label("K256",64); # Yes! I keep it in the code segment!
+       &data_word(0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5);
+       &data_word(0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5);
+       &data_word(0xd807aa98,0x12835b01,0x243185be,0x550c7dc3);
+       &data_word(0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174);
+       &data_word(0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc);
+       &data_word(0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da);
+       &data_word(0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7);
+       &data_word(0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967);
+       &data_word(0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13);
+       &data_word(0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85);
+       &data_word(0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3);
+       &data_word(0xd192e819,0xd6990624,0xf40e3585,0x106aa070);
+       &data_word(0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5);
+       &data_word(0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3);
+       &data_word(0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208);
+       &data_word(0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2);
+&function_end_B("sha256_block_data_order");
+&asciz("SHA256 block transform for x86, CRYPTOGAMS by <appro\@openssl.org>");
+
+&asm_finish();
diff --git a/deps/openssl/openssl/crypto/sha/asm/sha256-armv4.pl b/deps/openssl/openssl/crypto/sha/asm/sha256-armv4.pl
new file mode 100644 (file)
index 0000000..492cb62
--- /dev/null
@@ -0,0 +1,186 @@
+#!/usr/bin/env perl
+
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+
+# SHA256 block procedure for ARMv4. May 2007.
+
+# Performance is ~2x better than gcc 3.4 generated code and in "abso-
+# lute" terms is ~2250 cycles per 64-byte block or ~35 cycles per
+# byte [on single-issue Xscale PXA250 core].
+
+# July 2010.
+#
+# Rescheduling for dual-issue pipeline resulted in 22% improvement on
+# Cortex A8 core and ~20 cycles per processed byte.
+
+while (($output=shift) && ($output!~/^\w[\w\-]*\.\w+$/)) {}
+open STDOUT,">$output";
+
+$ctx="r0";     $t0="r0";
+$inp="r1";
+$len="r2";     $t1="r2";
+$T1="r3";
+$A="r4";
+$B="r5";
+$C="r6";
+$D="r7";
+$E="r8";
+$F="r9";
+$G="r10";
+$H="r11";
+@V=($A,$B,$C,$D,$E,$F,$G,$H);
+$t2="r12";
+$Ktbl="r14";
+
+@Sigma0=( 2,13,22);
+@Sigma1=( 6,11,25);
+@sigma0=( 7,18, 3);
+@sigma1=(17,19,10);
+
+sub BODY_00_15 {
+my ($i,$a,$b,$c,$d,$e,$f,$g,$h) = @_;
+
+$code.=<<___ if ($i<16);
+       ldrb    $T1,[$inp,#3]                   @ $i
+       ldrb    $t2,[$inp,#2]
+       ldrb    $t1,[$inp,#1]
+       ldrb    $t0,[$inp],#4
+       orr     $T1,$T1,$t2,lsl#8
+       orr     $T1,$T1,$t1,lsl#16
+       orr     $T1,$T1,$t0,lsl#24
+       `"str   $inp,[sp,#17*4]"        if ($i==15)`
+___
+$code.=<<___;
+       ldr     $t2,[$Ktbl],#4                  @ *K256++
+       mov     $t0,$e,ror#$Sigma1[0]
+       str     $T1,[sp,#`$i%16`*4]
+       eor     $t0,$t0,$e,ror#$Sigma1[1]
+       eor     $t1,$f,$g
+       eor     $t0,$t0,$e,ror#$Sigma1[2]       @ Sigma1(e)
+       and     $t1,$t1,$e
+       add     $T1,$T1,$t0
+       eor     $t1,$t1,$g                      @ Ch(e,f,g)
+       add     $T1,$T1,$h
+       mov     $h,$a,ror#$Sigma0[0]
+       add     $T1,$T1,$t1
+       eor     $h,$h,$a,ror#$Sigma0[1]
+       add     $T1,$T1,$t2
+       eor     $h,$h,$a,ror#$Sigma0[2]         @ Sigma0(a)
+       orr     $t0,$a,$b
+       and     $t1,$a,$b
+       and     $t0,$t0,$c
+       add     $h,$h,$T1
+       orr     $t0,$t0,$t1                     @ Maj(a,b,c)
+       add     $d,$d,$T1
+       add     $h,$h,$t0
+___
+}
+
+sub BODY_16_XX {
+my ($i,$a,$b,$c,$d,$e,$f,$g,$h) = @_;
+
+$code.=<<___;
+       ldr     $t1,[sp,#`($i+1)%16`*4]         @ $i
+       ldr     $t2,[sp,#`($i+14)%16`*4]
+       ldr     $T1,[sp,#`($i+0)%16`*4]
+       mov     $t0,$t1,ror#$sigma0[0]
+       ldr     $inp,[sp,#`($i+9)%16`*4]
+       eor     $t0,$t0,$t1,ror#$sigma0[1]
+       eor     $t0,$t0,$t1,lsr#$sigma0[2]      @ sigma0(X[i+1])
+       mov     $t1,$t2,ror#$sigma1[0]
+       add     $T1,$T1,$t0
+       eor     $t1,$t1,$t2,ror#$sigma1[1]
+       add     $T1,$T1,$inp
+       eor     $t1,$t1,$t2,lsr#$sigma1[2]      @ sigma1(X[i+14])
+       add     $T1,$T1,$t1
+___
+       &BODY_00_15(@_);
+}
+
+$code=<<___;
+.text
+.code  32
+
+.type  K256,%object
+.align 5
+K256:
+.word  0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5
+.word  0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5
+.word  0xd807aa98,0x12835b01,0x243185be,0x550c7dc3
+.word  0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174
+.word  0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc
+.word  0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da
+.word  0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7
+.word  0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967
+.word  0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13
+.word  0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85
+.word  0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3
+.word  0xd192e819,0xd6990624,0xf40e3585,0x106aa070
+.word  0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5
+.word  0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3
+.word  0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208
+.word  0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2
+.size  K256,.-K256
+
+.global        sha256_block_data_order
+.type  sha256_block_data_order,%function
+sha256_block_data_order:
+       sub     r3,pc,#8                @ sha256_block_data_order
+       add     $len,$inp,$len,lsl#6    @ len to point at the end of inp
+       stmdb   sp!,{$ctx,$inp,$len,r4-r12,lr}
+       ldmia   $ctx,{$A,$B,$C,$D,$E,$F,$G,$H}
+       sub     $Ktbl,r3,#256           @ K256
+       sub     sp,sp,#16*4             @ alloca(X[16])
+.Loop:
+___
+for($i=0;$i<16;$i++)   { &BODY_00_15($i,@V); unshift(@V,pop(@V)); }
+$code.=".Lrounds_16_xx:\n";
+for (;$i<32;$i++)      { &BODY_16_XX($i,@V); unshift(@V,pop(@V)); }
+$code.=<<___;
+       and     $t2,$t2,#0xff
+       cmp     $t2,#0xf2
+       bne     .Lrounds_16_xx
+
+       ldr     $T1,[sp,#16*4]          @ pull ctx
+       ldr     $t0,[$T1,#0]
+       ldr     $t1,[$T1,#4]
+       ldr     $t2,[$T1,#8]
+       add     $A,$A,$t0
+       ldr     $t0,[$T1,#12]
+       add     $B,$B,$t1
+       ldr     $t1,[$T1,#16]
+       add     $C,$C,$t2
+       ldr     $t2,[$T1,#20]
+       add     $D,$D,$t0
+       ldr     $t0,[$T1,#24]
+       add     $E,$E,$t1
+       ldr     $t1,[$T1,#28]
+       add     $F,$F,$t2
+       ldr     $inp,[sp,#17*4]         @ pull inp
+       ldr     $t2,[sp,#18*4]          @ pull inp+len
+       add     $G,$G,$t0
+       add     $H,$H,$t1
+       stmia   $T1,{$A,$B,$C,$D,$E,$F,$G,$H}
+       cmp     $inp,$t2
+       sub     $Ktbl,$Ktbl,#256        @ rewind Ktbl
+       bne     .Loop
+
+       add     sp,sp,#`16+3`*4 @ destroy frame
+       ldmia   sp!,{r4-r12,lr}
+       tst     lr,#1
+       moveq   pc,lr                   @ be binary compatible with V4, yet
+       bx      lr                      @ interoperable with Thumb ISA:-)
+.size   sha256_block_data_order,.-sha256_block_data_order
+.asciz  "SHA256 block transform for ARMv4, CRYPTOGAMS by <appro\@openssl.org>"
+.align 2
+___
+
+$code =~ s/\`([^\`]*)\`/eval $1/gem;
+$code =~ s/\bbx\s+lr\b/.word\t0xe12fff1e/gm;   # make it possible to compile with -march=armv4
+print $code;
+close STDOUT; # enforce flush
diff --git a/deps/openssl/openssl/crypto/sha/asm/sha512-586.pl b/deps/openssl/openssl/crypto/sha/asm/sha512-586.pl
new file mode 100644 (file)
index 0000000..5b9f333
--- /dev/null
@@ -0,0 +1,644 @@
+#!/usr/bin/env perl
+#
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+#
+# SHA512 block transform for x86. September 2007.
+#
+# Performance in clock cycles per processed byte (less is better):
+#
+#              Pentium PIII    P4      AMD K8  Core2
+# gcc          100     75      116     54      66
+# icc          97      77      95      55      57
+# x86 asm      61      56      82      36      40
+# SSE2 asm     -       -       38      24      20
+# x86_64 asm(*)        -       -       30      10.0    10.5
+#
+# (*) x86_64 assembler performance is presented for reference
+#     purposes.
+#
+# IALU code-path is optimized for elder Pentiums. On vanilla Pentium
+# performance improvement over compiler generated code reaches ~60%,
+# while on PIII - ~35%. On newer Âµ-archs improvement varies from 15%
+# to 50%, but it's less important as they are expected to execute SSE2
+# code-path, which is commonly ~2-3x faster [than compiler generated
+# code]. SSE2 code-path is as fast as original sha512-sse2.pl, even
+# though it does not use 128-bit operations. The latter means that
+# SSE2-aware kernel is no longer required to execute the code. Another
+# difference is that new code optimizes amount of writes, but at the
+# cost of increased data cache "footprint" by 1/2KB.
+
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+push(@INC,"${dir}","${dir}../../perlasm");
+require "x86asm.pl";
+
+&asm_init($ARGV[0],"sha512-586.pl",$ARGV[$#ARGV] eq "386");
+
+$sse2=0;
+for (@ARGV) { $sse2=1 if (/-DOPENSSL_IA32_SSE2/); }
+
+&external_label("OPENSSL_ia32cap_P") if ($sse2);
+
+$Tlo=&DWP(0,"esp");    $Thi=&DWP(4,"esp");
+$Alo=&DWP(8,"esp");    $Ahi=&DWP(8+4,"esp");
+$Blo=&DWP(16,"esp");   $Bhi=&DWP(16+4,"esp");
+$Clo=&DWP(24,"esp");   $Chi=&DWP(24+4,"esp");
+$Dlo=&DWP(32,"esp");   $Dhi=&DWP(32+4,"esp");
+$Elo=&DWP(40,"esp");   $Ehi=&DWP(40+4,"esp");
+$Flo=&DWP(48,"esp");   $Fhi=&DWP(48+4,"esp");
+$Glo=&DWP(56,"esp");   $Ghi=&DWP(56+4,"esp");
+$Hlo=&DWP(64,"esp");   $Hhi=&DWP(64+4,"esp");
+$K512="ebp";
+
+$Asse2=&QWP(0,"esp");
+$Bsse2=&QWP(8,"esp");
+$Csse2=&QWP(16,"esp");
+$Dsse2=&QWP(24,"esp");
+$Esse2=&QWP(32,"esp");
+$Fsse2=&QWP(40,"esp");
+$Gsse2=&QWP(48,"esp");
+$Hsse2=&QWP(56,"esp");
+
+$A="mm0";      # B-D and
+$E="mm4";      # F-H are commonly loaded to respectively mm1-mm3 and
+               # mm5-mm7, but it's done on on-demand basis...
+
+sub BODY_00_15_sse2 {
+    my $prefetch=shift;
+
+       &movq   ("mm5",$Fsse2);                 # load f
+       &movq   ("mm6",$Gsse2);                 # load g
+       &movq   ("mm7",$Hsse2);                 # load h
+
+       &movq   ("mm1",$E);                     # %mm1 is sliding right
+       &movq   ("mm2",$E);                     # %mm2 is sliding left
+       &psrlq  ("mm1",14);
+       &movq   ($Esse2,$E);                    # modulo-scheduled save e
+       &psllq  ("mm2",23);
+       &movq   ("mm3","mm1");                  # %mm3 is T1
+       &psrlq  ("mm1",4);
+       &pxor   ("mm3","mm2");
+       &psllq  ("mm2",23);
+       &pxor   ("mm3","mm1");
+       &psrlq  ("mm1",23);
+       &pxor   ("mm3","mm2");
+       &psllq  ("mm2",4);
+       &pxor   ("mm3","mm1");
+       &paddq  ("mm7",QWP(0,$K512));           # h+=K512[i]
+       &pxor   ("mm3","mm2");                  # T1=Sigma1_512(e)
+
+       &pxor   ("mm5","mm6");                  # f^=g
+       &movq   ("mm1",$Bsse2);                 # load b
+       &pand   ("mm5",$E);                     # f&=e
+       &movq   ("mm2",$Csse2);                 # load c
+       &pxor   ("mm5","mm6");                  # f^=g
+       &movq   ($E,$Dsse2);                    # e = load d
+       &paddq  ("mm3","mm5");                  # T1+=Ch(e,f,g)
+       &movq   (&QWP(0,"esp"),$A);             # modulo-scheduled save a
+       &paddq  ("mm3","mm7");                  # T1+=h
+
+       &movq   ("mm5",$A);                     # %mm5 is sliding right
+       &movq   ("mm6",$A);                     # %mm6 is sliding left
+       &paddq  ("mm3",&QWP(8*9,"esp"));        # T1+=X[0]
+       &psrlq  ("mm5",28);
+       &paddq  ($E,"mm3");                     # e += T1
+       &psllq  ("mm6",25);
+       &movq   ("mm7","mm5");                  # %mm7 is T2
+       &psrlq  ("mm5",6);
+       &pxor   ("mm7","mm6");
+       &psllq  ("mm6",5);
+       &pxor   ("mm7","mm5");
+       &psrlq  ("mm5",5);
+       &pxor   ("mm7","mm6");
+       &psllq  ("mm6",6);
+       &pxor   ("mm7","mm5");
+       &sub    ("esp",8);
+       &pxor   ("mm7","mm6");                  # T2=Sigma0_512(a)
+
+       &movq   ("mm5",$A);                     # %mm5=a
+       &por    ($A,"mm2");                     # a=a|c
+       &movq   ("mm6",&QWP(8*(9+16-14),"esp")) if ($prefetch);
+       &pand   ("mm5","mm2");                  # %mm5=a&c
+       &pand   ($A,"mm1");                     # a=(a|c)&b
+       &movq   ("mm2",&QWP(8*(9+16-1),"esp"))  if ($prefetch);
+       &por    ("mm5",$A);                     # %mm5=(a&c)|((a|c)&b)
+       &paddq  ("mm7","mm5");                  # T2+=Maj(a,b,c)
+       &movq   ($A,"mm3");                     # a=T1
+
+       &mov    (&LB("edx"),&BP(0,$K512));
+       &paddq  ($A,"mm7");                     # a+=T2
+       &add    ($K512,8);
+}
+
+sub BODY_00_15_x86 {
+       #define Sigma1(x)       (ROTR((x),14) ^ ROTR((x),18)  ^ ROTR((x),41))
+       #       LO              lo>>14^hi<<18 ^ lo>>18^hi<<14 ^ hi>>9^lo<<23
+       #       HI              hi>>14^lo<<18 ^ hi>>18^lo<<14 ^ lo>>9^hi<<23
+       &mov    ("ecx",$Elo);
+       &mov    ("edx",$Ehi);
+       &mov    ("esi","ecx");
+
+       &shr    ("ecx",9)       # lo>>9
+       &mov    ("edi","edx");
+       &shr    ("edx",9)       # hi>>9
+       &mov    ("ebx","ecx");
+       &shl    ("esi",14);     # lo<<14
+       &mov    ("eax","edx");
+       &shl    ("edi",14);     # hi<<14
+       &xor    ("ebx","esi");
+
+       &shr    ("ecx",14-9);   # lo>>14
+       &xor    ("eax","edi");
+       &shr    ("edx",14-9);   # hi>>14
+       &xor    ("eax","ecx");
+       &shl    ("esi",18-14);  # lo<<18
+       &xor    ("ebx","edx");
+       &shl    ("edi",18-14);  # hi<<18
+       &xor    ("ebx","esi");
+
+       &shr    ("ecx",18-14);  # lo>>18
+       &xor    ("eax","edi");
+       &shr    ("edx",18-14);  # hi>>18
+       &xor    ("eax","ecx");
+       &shl    ("esi",23-18);  # lo<<23
+       &xor    ("ebx","edx");
+       &shl    ("edi",23-18);  # hi<<23
+       &xor    ("eax","esi");
+       &xor    ("ebx","edi");                  # T1 = Sigma1(e)
+
+       &mov    ("ecx",$Flo);
+       &mov    ("edx",$Fhi);
+       &mov    ("esi",$Glo);
+       &mov    ("edi",$Ghi);
+        &add   ("eax",$Hlo);
+        &adc   ("ebx",$Hhi);                   # T1 += h
+       &xor    ("ecx","esi");
+       &xor    ("edx","edi");
+       &and    ("ecx",$Elo);
+       &and    ("edx",$Ehi);
+        &add   ("eax",&DWP(8*(9+15)+0,"esp"));
+        &adc   ("ebx",&DWP(8*(9+15)+4,"esp")); # T1 += X[0]
+       &xor    ("ecx","esi");
+       &xor    ("edx","edi");                  # Ch(e,f,g) = (f^g)&e)^g
+
+       &mov    ("esi",&DWP(0,$K512));
+       &mov    ("edi",&DWP(4,$K512));          # K[i]
+       &add    ("eax","ecx");
+       &adc    ("ebx","edx");                  # T1 += Ch(e,f,g)
+       &mov    ("ecx",$Dlo);
+       &mov    ("edx",$Dhi);
+       &add    ("eax","esi");
+       &adc    ("ebx","edi");                  # T1 += K[i]
+       &mov    ($Tlo,"eax");
+       &mov    ($Thi,"ebx");                   # put T1 away
+       &add    ("eax","ecx");
+       &adc    ("ebx","edx");                  # d += T1
+
+       #define Sigma0(x)       (ROTR((x),28) ^ ROTR((x),34) ^ ROTR((x),39))
+       #       LO              lo>>28^hi<<4  ^ hi>>2^lo<<30 ^ hi>>7^lo<<25
+       #       HI              hi>>28^lo<<4  ^ lo>>2^hi<<30 ^ lo>>7^hi<<25
+       &mov    ("ecx",$Alo);
+       &mov    ("edx",$Ahi);
+       &mov    ($Dlo,"eax");
+       &mov    ($Dhi,"ebx");
+       &mov    ("esi","ecx");
+
+       &shr    ("ecx",2)       # lo>>2
+       &mov    ("edi","edx");
+       &shr    ("edx",2)       # hi>>2
+       &mov    ("ebx","ecx");
+       &shl    ("esi",4);      # lo<<4
+       &mov    ("eax","edx");
+       &shl    ("edi",4);      # hi<<4
+       &xor    ("ebx","esi");
+
+       &shr    ("ecx",7-2);    # lo>>7
+       &xor    ("eax","edi");
+       &shr    ("edx",7-2);    # hi>>7
+       &xor    ("ebx","ecx");
+       &shl    ("esi",25-4);   # lo<<25
+       &xor    ("eax","edx");
+       &shl    ("edi",25-4);   # hi<<25
+       &xor    ("eax","esi");
+
+       &shr    ("ecx",28-7);   # lo>>28
+       &xor    ("ebx","edi");
+       &shr    ("edx",28-7);   # hi>>28
+       &xor    ("eax","ecx");
+       &shl    ("esi",30-25);  # lo<<30
+       &xor    ("ebx","edx");
+       &shl    ("edi",30-25);  # hi<<30
+       &xor    ("eax","esi");
+       &xor    ("ebx","edi");                  # Sigma0(a)
+
+       &mov    ("ecx",$Alo);
+       &mov    ("edx",$Ahi);
+       &mov    ("esi",$Blo);
+       &mov    ("edi",$Bhi);
+       &add    ("eax",$Tlo);
+       &adc    ("ebx",$Thi);                   # T1 = Sigma0(a)+T1
+       &or     ("ecx","esi");
+       &or     ("edx","edi");
+       &and    ("ecx",$Clo);
+       &and    ("edx",$Chi);
+       &and    ("esi",$Alo);
+       &and    ("edi",$Ahi);
+       &or     ("ecx","esi");
+       &or     ("edx","edi");                  # Maj(a,b,c) = ((a|b)&c)|(a&b)
+
+       &add    ("eax","ecx");
+       &adc    ("ebx","edx");                  # T1 += Maj(a,b,c)
+       &mov    ($Tlo,"eax");
+       &mov    ($Thi,"ebx");
+
+       &mov    (&LB("edx"),&BP(0,$K512));      # pre-fetch LSB of *K
+       &sub    ("esp",8);
+       &lea    ($K512,&DWP(8,$K512));          # K++
+}
+
+
+&function_begin("sha512_block_data_order");
+       &mov    ("esi",wparam(0));      # ctx
+       &mov    ("edi",wparam(1));      # inp
+       &mov    ("eax",wparam(2));      # num
+       &mov    ("ebx","esp");          # saved sp
+
+       &call   (&label("pic_point"));  # make it PIC!
+&set_label("pic_point");
+       &blindpop($K512);
+       &lea    ($K512,&DWP(&label("K512")."-".&label("pic_point"),$K512));
+
+       &sub    ("esp",16);
+       &and    ("esp",-64);
+
+       &shl    ("eax",7);
+       &add    ("eax","edi");
+       &mov    (&DWP(0,"esp"),"esi");  # ctx
+       &mov    (&DWP(4,"esp"),"edi");  # inp
+       &mov    (&DWP(8,"esp"),"eax");  # inp+num*128
+       &mov    (&DWP(12,"esp"),"ebx"); # saved sp
+
+if ($sse2) {
+       &picmeup("edx","OPENSSL_ia32cap_P",$K512,&label("K512"));
+       &bt     (&DWP(0,"edx"),26);
+       &jnc    (&label("loop_x86"));
+
+       # load ctx->h[0-7]
+       &movq   ($A,&QWP(0,"esi"));
+       &movq   ("mm1",&QWP(8,"esi"));
+       &movq   ("mm2",&QWP(16,"esi"));
+       &movq   ("mm3",&QWP(24,"esi"));
+       &movq   ($E,&QWP(32,"esi"));
+       &movq   ("mm5",&QWP(40,"esi"));
+       &movq   ("mm6",&QWP(48,"esi"));
+       &movq   ("mm7",&QWP(56,"esi"));
+       &sub    ("esp",8*10);
+
+&set_label("loop_sse2",16);
+       # &movq ($Asse2,$A);
+       &movq   ($Bsse2,"mm1");
+       &movq   ($Csse2,"mm2");
+       &movq   ($Dsse2,"mm3");
+       # &movq ($Esse2,$E);
+       &movq   ($Fsse2,"mm5");
+       &movq   ($Gsse2,"mm6");
+       &movq   ($Hsse2,"mm7");
+
+       &mov    ("ecx",&DWP(0,"edi"));
+       &mov    ("edx",&DWP(4,"edi"));
+       &add    ("edi",8);
+       &bswap  ("ecx");
+       &bswap  ("edx");
+       &mov    (&DWP(8*9+4,"esp"),"ecx");
+       &mov    (&DWP(8*9+0,"esp"),"edx");
+
+&set_label("00_14_sse2",16);
+       &mov    ("eax",&DWP(0,"edi"));
+       &mov    ("ebx",&DWP(4,"edi"));
+       &add    ("edi",8);
+       &bswap  ("eax");
+       &bswap  ("ebx");
+       &mov    (&DWP(8*8+4,"esp"),"eax");
+       &mov    (&DWP(8*8+0,"esp"),"ebx");
+
+       &BODY_00_15_sse2();
+
+       &cmp    (&LB("edx"),0x35);
+       &jne    (&label("00_14_sse2"));
+
+       &BODY_00_15_sse2(1);
+
+&set_label("16_79_sse2",16);
+       #&movq  ("mm2",&QWP(8*(9+16-1),"esp")); #prefetched in BODY_00_15 
+       #&movq  ("mm6",&QWP(8*(9+16-14),"esp"));
+       &movq   ("mm1","mm2");
+
+       &psrlq  ("mm2",1);
+       &movq   ("mm7","mm6");
+       &psrlq  ("mm6",6);
+       &movq   ("mm3","mm2");
+
+       &psrlq  ("mm2",7-1);
+       &movq   ("mm5","mm6");
+       &psrlq  ("mm6",19-6);
+       &pxor   ("mm3","mm2");
+
+       &psrlq  ("mm2",8-7);
+       &pxor   ("mm5","mm6");
+       &psrlq  ("mm6",61-19);
+       &pxor   ("mm3","mm2");
+
+       &movq   ("mm2",&QWP(8*(9+16),"esp"));
+
+       &psllq  ("mm1",56);
+       &pxor   ("mm5","mm6");
+       &psllq  ("mm7",3);
+       &pxor   ("mm3","mm1");
+
+       &paddq  ("mm2",&QWP(8*(9+16-9),"esp"));
+
+       &psllq  ("mm1",63-56);
+       &pxor   ("mm5","mm7");
+       &psllq  ("mm7",45-3);
+       &pxor   ("mm3","mm1");
+       &pxor   ("mm5","mm7");
+
+       &paddq  ("mm3","mm5");
+       &paddq  ("mm3","mm2");
+       &movq   (&QWP(8*9,"esp"),"mm3");
+
+       &BODY_00_15_sse2(1);
+
+       &cmp    (&LB("edx"),0x17);
+       &jne    (&label("16_79_sse2"));
+
+       # &movq ($A,$Asse2);
+       &movq   ("mm1",$Bsse2);
+       &movq   ("mm2",$Csse2);
+       &movq   ("mm3",$Dsse2);
+       # &movq ($E,$Esse2);
+       &movq   ("mm5",$Fsse2);
+       &movq   ("mm6",$Gsse2);
+       &movq   ("mm7",$Hsse2);
+
+       &paddq  ($A,&QWP(0,"esi"));
+       &paddq  ("mm1",&QWP(8,"esi"));
+       &paddq  ("mm2",&QWP(16,"esi"));
+       &paddq  ("mm3",&QWP(24,"esi"));
+       &paddq  ($E,&QWP(32,"esi"));
+       &paddq  ("mm5",&QWP(40,"esi"));
+       &paddq  ("mm6",&QWP(48,"esi"));
+       &paddq  ("mm7",&QWP(56,"esi"));
+
+       &movq   (&QWP(0,"esi"),$A);
+       &movq   (&QWP(8,"esi"),"mm1");
+       &movq   (&QWP(16,"esi"),"mm2");
+       &movq   (&QWP(24,"esi"),"mm3");
+       &movq   (&QWP(32,"esi"),$E);
+       &movq   (&QWP(40,"esi"),"mm5");
+       &movq   (&QWP(48,"esi"),"mm6");
+       &movq   (&QWP(56,"esi"),"mm7");
+
+       &add    ("esp",8*80);                   # destroy frame
+       &sub    ($K512,8*80);                   # rewind K
+
+       &cmp    ("edi",&DWP(8*10+8,"esp"));     # are we done yet?
+       &jb     (&label("loop_sse2"));
+
+       &emms   ();
+       &mov    ("esp",&DWP(8*10+12,"esp"));    # restore sp
+&function_end_A();
+}
+&set_label("loop_x86",16);
+    # copy input block to stack reversing byte and qword order
+    for ($i=0;$i<8;$i++) {
+       &mov    ("eax",&DWP($i*16+0,"edi"));
+       &mov    ("ebx",&DWP($i*16+4,"edi"));
+       &mov    ("ecx",&DWP($i*16+8,"edi"));
+       &mov    ("edx",&DWP($i*16+12,"edi"));
+       &bswap  ("eax");
+       &bswap  ("ebx");
+       &bswap  ("ecx");
+       &bswap  ("edx");
+       &push   ("eax");
+       &push   ("ebx");
+       &push   ("ecx");
+       &push   ("edx");
+    }
+       &add    ("edi",128);
+       &sub    ("esp",9*8);            # place for T,A,B,C,D,E,F,G,H
+       &mov    (&DWP(8*(9+16)+4,"esp"),"edi");
+
+       # copy ctx->h[0-7] to A,B,C,D,E,F,G,H on stack
+       &lea    ("edi",&DWP(8,"esp"));
+       &mov    ("ecx",16);
+       &data_word(0xA5F3F689);         # rep movsd
+
+&set_label("00_15_x86",16);
+       &BODY_00_15_x86();
+
+       &cmp    (&LB("edx"),0x94);
+       &jne    (&label("00_15_x86"));
+
+&set_label("16_79_x86",16);
+       #define sigma0(x)       (ROTR((x),1)  ^ ROTR((x),8)  ^ ((x)>>7))
+       #       LO              lo>>1^hi<<31  ^ lo>>8^hi<<24 ^ lo>>7^hi<<25
+       #       HI              hi>>1^lo<<31  ^ hi>>8^lo<<24 ^ hi>>7
+       &mov    ("ecx",&DWP(8*(9+15+16-1)+0,"esp"));
+       &mov    ("edx",&DWP(8*(9+15+16-1)+4,"esp"));
+       &mov    ("esi","ecx");
+
+       &shr    ("ecx",1)       # lo>>1
+       &mov    ("edi","edx");
+       &shr    ("edx",1)       # hi>>1
+       &mov    ("eax","ecx");
+       &shl    ("esi",24);     # lo<<24
+       &mov    ("ebx","edx");
+       &shl    ("edi",24);     # hi<<24
+       &xor    ("ebx","esi");
+
+       &shr    ("ecx",7-1);    # lo>>7
+       &xor    ("eax","edi");
+       &shr    ("edx",7-1);    # hi>>7
+       &xor    ("eax","ecx");
+       &shl    ("esi",31-24);  # lo<<31
+       &xor    ("ebx","edx");
+       &shl    ("edi",25-24);  # hi<<25
+       &xor    ("ebx","esi");
+
+       &shr    ("ecx",8-7);    # lo>>8
+       &xor    ("eax","edi");
+       &shr    ("edx",8-7);    # hi>>8
+       &xor    ("eax","ecx");
+       &shl    ("edi",31-25);  # hi<<31
+       &xor    ("ebx","edx");
+       &xor    ("eax","edi");                  # T1 = sigma0(X[-15])
+
+       &mov    (&DWP(0,"esp"),"eax");
+       &mov    (&DWP(4,"esp"),"ebx");          # put T1 away
+
+       #define sigma1(x)       (ROTR((x),19) ^ ROTR((x),61) ^ ((x)>>6))
+       #       LO              lo>>19^hi<<13 ^ hi>>29^lo<<3 ^ lo>>6^hi<<26
+       #       HI              hi>>19^lo<<13 ^ lo>>29^hi<<3 ^ hi>>6
+       &mov    ("ecx",&DWP(8*(9+15+16-14)+0,"esp"));
+       &mov    ("edx",&DWP(8*(9+15+16-14)+4,"esp"));
+       &mov    ("esi","ecx");
+
+       &shr    ("ecx",6)       # lo>>6
+       &mov    ("edi","edx");
+       &shr    ("edx",6)       # hi>>6
+       &mov    ("eax","ecx");
+       &shl    ("esi",3);      # lo<<3
+       &mov    ("ebx","edx");
+       &shl    ("edi",3);      # hi<<3
+       &xor    ("eax","esi");
+
+       &shr    ("ecx",19-6);   # lo>>19
+       &xor    ("ebx","edi");
+       &shr    ("edx",19-6);   # hi>>19
+       &xor    ("eax","ecx");
+       &shl    ("esi",13-3);   # lo<<13
+       &xor    ("ebx","edx");
+       &shl    ("edi",13-3);   # hi<<13
+       &xor    ("ebx","esi");
+
+       &shr    ("ecx",29-19);  # lo>>29
+       &xor    ("eax","edi");
+       &shr    ("edx",29-19);  # hi>>29
+       &xor    ("ebx","ecx");
+       &shl    ("edi",26-13);  # hi<<26
+       &xor    ("eax","edx");
+       &xor    ("eax","edi");                  # sigma1(X[-2])
+
+       &mov    ("ecx",&DWP(8*(9+15+16)+0,"esp"));
+       &mov    ("edx",&DWP(8*(9+15+16)+4,"esp"));
+       &add    ("eax",&DWP(0,"esp"));
+       &adc    ("ebx",&DWP(4,"esp"));          # T1 = sigma1(X[-2])+T1
+       &mov    ("esi",&DWP(8*(9+15+16-9)+0,"esp"));
+       &mov    ("edi",&DWP(8*(9+15+16-9)+4,"esp"));
+       &add    ("eax","ecx");
+       &adc    ("ebx","edx");                  # T1 += X[-16]
+       &add    ("eax","esi");
+       &adc    ("ebx","edi");                  # T1 += X[-7]
+       &mov    (&DWP(8*(9+15)+0,"esp"),"eax");
+       &mov    (&DWP(8*(9+15)+4,"esp"),"ebx"); # save X[0]
+
+       &BODY_00_15_x86();
+
+       &cmp    (&LB("edx"),0x17);
+       &jne    (&label("16_79_x86"));
+
+       &mov    ("esi",&DWP(8*(9+16+80)+0,"esp"));# ctx
+       &mov    ("edi",&DWP(8*(9+16+80)+4,"esp"));# inp
+    for($i=0;$i<4;$i++) {
+       &mov    ("eax",&DWP($i*16+0,"esi"));
+       &mov    ("ebx",&DWP($i*16+4,"esi"));
+       &mov    ("ecx",&DWP($i*16+8,"esi"));
+       &mov    ("edx",&DWP($i*16+12,"esi"));
+       &add    ("eax",&DWP(8+($i*16)+0,"esp"));
+       &adc    ("ebx",&DWP(8+($i*16)+4,"esp"));
+       &mov    (&DWP($i*16+0,"esi"),"eax");
+       &mov    (&DWP($i*16+4,"esi"),"ebx");
+       &add    ("ecx",&DWP(8+($i*16)+8,"esp"));
+       &adc    ("edx",&DWP(8+($i*16)+12,"esp"));
+       &mov    (&DWP($i*16+8,"esi"),"ecx");
+       &mov    (&DWP($i*16+12,"esi"),"edx");
+    }
+       &add    ("esp",8*(9+16+80));            # destroy frame
+       &sub    ($K512,8*80);                   # rewind K
+
+       &cmp    ("edi",&DWP(8,"esp"));          # are we done yet?
+       &jb     (&label("loop_x86"));
+
+       &mov    ("esp",&DWP(12,"esp"));         # restore sp
+&function_end_A();
+
+&set_label("K512",64); # Yes! I keep it in the code segment!
+       &data_word(0xd728ae22,0x428a2f98);      # u64
+       &data_word(0x23ef65cd,0x71374491);      # u64
+       &data_word(0xec4d3b2f,0xb5c0fbcf);      # u64
+       &data_word(0x8189dbbc,0xe9b5dba5);      # u64
+       &data_word(0xf348b538,0x3956c25b);      # u64
+       &data_word(0xb605d019,0x59f111f1);      # u64
+       &data_word(0xaf194f9b,0x923f82a4);      # u64
+       &data_word(0xda6d8118,0xab1c5ed5);      # u64
+       &data_word(0xa3030242,0xd807aa98);      # u64
+       &data_word(0x45706fbe,0x12835b01);      # u64
+       &data_word(0x4ee4b28c,0x243185be);      # u64
+       &data_word(0xd5ffb4e2,0x550c7dc3);      # u64
+       &data_word(0xf27b896f,0x72be5d74);      # u64
+       &data_word(0x3b1696b1,0x80deb1fe);      # u64
+       &data_word(0x25c71235,0x9bdc06a7);      # u64
+       &data_word(0xcf692694,0xc19bf174);      # u64
+       &data_word(0x9ef14ad2,0xe49b69c1);      # u64
+       &data_word(0x384f25e3,0xefbe4786);      # u64
+       &data_word(0x8b8cd5b5,0x0fc19dc6);      # u64
+       &data_word(0x77ac9c65,0x240ca1cc);      # u64
+       &data_word(0x592b0275,0x2de92c6f);      # u64
+       &data_word(0x6ea6e483,0x4a7484aa);      # u64
+       &data_word(0xbd41fbd4,0x5cb0a9dc);      # u64
+       &data_word(0x831153b5,0x76f988da);      # u64
+       &data_word(0xee66dfab,0x983e5152);      # u64
+       &data_word(0x2db43210,0xa831c66d);      # u64
+       &data_word(0x98fb213f,0xb00327c8);      # u64
+       &data_word(0xbeef0ee4,0xbf597fc7);      # u64
+       &data_word(0x3da88fc2,0xc6e00bf3);      # u64
+       &data_word(0x930aa725,0xd5a79147);      # u64
+       &data_word(0xe003826f,0x06ca6351);      # u64
+       &data_word(0x0a0e6e70,0x14292967);      # u64
+       &data_word(0x46d22ffc,0x27b70a85);      # u64
+       &data_word(0x5c26c926,0x2e1b2138);      # u64
+       &data_word(0x5ac42aed,0x4d2c6dfc);      # u64
+       &data_word(0x9d95b3df,0x53380d13);      # u64
+       &data_word(0x8baf63de,0x650a7354);      # u64
+       &data_word(0x3c77b2a8,0x766a0abb);      # u64
+       &data_word(0x47edaee6,0x81c2c92e);      # u64
+       &data_word(0x1482353b,0x92722c85);      # u64
+       &data_word(0x4cf10364,0xa2bfe8a1);      # u64
+       &data_word(0xbc423001,0xa81a664b);      # u64
+       &data_word(0xd0f89791,0xc24b8b70);      # u64
+       &data_word(0x0654be30,0xc76c51a3);      # u64
+       &data_word(0xd6ef5218,0xd192e819);      # u64
+       &data_word(0x5565a910,0xd6990624);      # u64
+       &data_word(0x5771202a,0xf40e3585);      # u64
+       &data_word(0x32bbd1b8,0x106aa070);      # u64
+       &data_word(0xb8d2d0c8,0x19a4c116);      # u64
+       &data_word(0x5141ab53,0x1e376c08);      # u64
+       &data_word(0xdf8eeb99,0x2748774c);      # u64
+       &data_word(0xe19b48a8,0x34b0bcb5);      # u64
+       &data_word(0xc5c95a63,0x391c0cb3);      # u64
+       &data_word(0xe3418acb,0x4ed8aa4a);      # u64
+       &data_word(0x7763e373,0x5b9cca4f);      # u64
+       &data_word(0xd6b2b8a3,0x682e6ff3);      # u64
+       &data_word(0x5defb2fc,0x748f82ee);      # u64
+       &data_word(0x43172f60,0x78a5636f);      # u64
+       &data_word(0xa1f0ab72,0x84c87814);      # u64
+       &data_word(0x1a6439ec,0x8cc70208);      # u64
+       &data_word(0x23631e28,0x90befffa);      # u64
+       &data_word(0xde82bde9,0xa4506ceb);      # u64
+       &data_word(0xb2c67915,0xbef9a3f7);      # u64
+       &data_word(0xe372532b,0xc67178f2);      # u64
+       &data_word(0xea26619c,0xca273ece);      # u64
+       &data_word(0x21c0c207,0xd186b8c7);      # u64
+       &data_word(0xcde0eb1e,0xeada7dd6);      # u64
+       &data_word(0xee6ed178,0xf57d4f7f);      # u64
+       &data_word(0x72176fba,0x06f067aa);      # u64
+       &data_word(0xa2c898a6,0x0a637dc5);      # u64
+       &data_word(0xbef90dae,0x113f9804);      # u64
+       &data_word(0x131c471b,0x1b710b35);      # u64
+       &data_word(0x23047d84,0x28db77f5);      # u64
+       &data_word(0x40c72493,0x32caab7b);      # u64
+       &data_word(0x15c9bebc,0x3c9ebe0a);      # u64
+       &data_word(0x9c100d4c,0x431d67c4);      # u64
+       &data_word(0xcb3e42b6,0x4cc5d4be);      # u64
+       &data_word(0xfc657e2a,0x597f299c);      # u64
+       &data_word(0x3ad6faec,0x5fcb6fab);      # u64
+       &data_word(0x4a475817,0x6c44198c);      # u64
+&function_end_B("sha512_block_data_order");
+&asciz("SHA512 block transform for x86, CRYPTOGAMS by <appro\@openssl.org>");
+
+&asm_finish();
diff --git a/deps/openssl/openssl/crypto/sha/asm/sha512-armv4.pl b/deps/openssl/openssl/crypto/sha/asm/sha512-armv4.pl
new file mode 100644 (file)
index 0000000..3a35861
--- /dev/null
@@ -0,0 +1,403 @@
+#!/usr/bin/env perl
+
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+
+# SHA512 block procedure for ARMv4. September 2007.
+
+# This code is ~4.5 (four and a half) times faster than code generated
+# by gcc 3.4 and it spends ~72 clock cycles per byte [on single-issue
+# Xscale PXA250 core].
+#
+# July 2010.
+#
+# Rescheduling for dual-issue pipeline resulted in 6% improvement on
+# Cortex A8 core and ~40 cycles per processed byte.
+
+# Byte order [in]dependence. =========================================
+#
+# Caller is expected to maintain specific *dword* order in h[0-7],
+# namely with most significant dword at *lower* address, which is
+# reflected in below two parameters. *Byte* order within these dwords
+# in turn is whatever *native* byte order on current platform.
+$hi=0;
+$lo=4;
+# ====================================================================
+
+while (($output=shift) && ($output!~/^\w[\w\-]*\.\w+$/)) {}
+open STDOUT,">$output";
+
+$ctx="r0";
+$inp="r1";
+$len="r2";
+$Tlo="r3";
+$Thi="r4";
+$Alo="r5";
+$Ahi="r6";
+$Elo="r7";
+$Ehi="r8";
+$t0="r9";
+$t1="r10";
+$t2="r11";
+$t3="r12";
+############   r13 is stack pointer
+$Ktbl="r14";
+############   r15 is program counter
+
+$Aoff=8*0;
+$Boff=8*1;
+$Coff=8*2;
+$Doff=8*3;
+$Eoff=8*4;
+$Foff=8*5;
+$Goff=8*6;
+$Hoff=8*7;
+$Xoff=8*8;
+
+sub BODY_00_15() {
+my $magic = shift;
+$code.=<<___;
+       ldr     $t2,[sp,#$Hoff+0]       @ h.lo
+       ldr     $t3,[sp,#$Hoff+4]       @ h.hi
+       @ Sigma1(x)     (ROTR((x),14) ^ ROTR((x),18)  ^ ROTR((x),41))
+       @ LO            lo>>14^hi<<18 ^ lo>>18^hi<<14 ^ hi>>9^lo<<23
+       @ HI            hi>>14^lo<<18 ^ hi>>18^lo<<14 ^ lo>>9^hi<<23
+       mov     $t0,$Elo,lsr#14
+       mov     $t1,$Ehi,lsr#14
+       eor     $t0,$t0,$Ehi,lsl#18
+       eor     $t1,$t1,$Elo,lsl#18
+       eor     $t0,$t0,$Elo,lsr#18
+       eor     $t1,$t1,$Ehi,lsr#18
+       eor     $t0,$t0,$Ehi,lsl#14
+       eor     $t1,$t1,$Elo,lsl#14
+       eor     $t0,$t0,$Ehi,lsr#9
+       eor     $t1,$t1,$Elo,lsr#9
+       eor     $t0,$t0,$Elo,lsl#23
+       eor     $t1,$t1,$Ehi,lsl#23     @ Sigma1(e)
+       adds    $Tlo,$Tlo,$t0
+       ldr     $t0,[sp,#$Foff+0]       @ f.lo
+       adc     $Thi,$Thi,$t1           @ T += Sigma1(e)
+       ldr     $t1,[sp,#$Foff+4]       @ f.hi
+       adds    $Tlo,$Tlo,$t2
+       ldr     $t2,[sp,#$Goff+0]       @ g.lo
+       adc     $Thi,$Thi,$t3           @ T += h
+       ldr     $t3,[sp,#$Goff+4]       @ g.hi
+
+       eor     $t0,$t0,$t2
+       str     $Elo,[sp,#$Eoff+0]
+       eor     $t1,$t1,$t3
+       str     $Ehi,[sp,#$Eoff+4]
+       and     $t0,$t0,$Elo
+       str     $Alo,[sp,#$Aoff+0]
+       and     $t1,$t1,$Ehi
+       str     $Ahi,[sp,#$Aoff+4]
+       eor     $t0,$t0,$t2
+       ldr     $t2,[$Ktbl,#4]          @ K[i].lo
+       eor     $t1,$t1,$t3             @ Ch(e,f,g)
+       ldr     $t3,[$Ktbl,#0]          @ K[i].hi
+
+       adds    $Tlo,$Tlo,$t0
+       ldr     $Elo,[sp,#$Doff+0]      @ d.lo
+       adc     $Thi,$Thi,$t1           @ T += Ch(e,f,g)
+       ldr     $Ehi,[sp,#$Doff+4]      @ d.hi
+       adds    $Tlo,$Tlo,$t2
+       adc     $Thi,$Thi,$t3           @ T += K[i]
+       adds    $Elo,$Elo,$Tlo
+       adc     $Ehi,$Ehi,$Thi          @ d += T
+
+       and     $t0,$t2,#0xff
+       teq     $t0,#$magic
+       orreq   $Ktbl,$Ktbl,#1
+
+       ldr     $t2,[sp,#$Boff+0]       @ b.lo
+       ldr     $t3,[sp,#$Coff+0]       @ c.lo
+       @ Sigma0(x)     (ROTR((x),28) ^ ROTR((x),34) ^ ROTR((x),39))
+       @ LO            lo>>28^hi<<4  ^ hi>>2^lo<<30 ^ hi>>7^lo<<25
+       @ HI            hi>>28^lo<<4  ^ lo>>2^hi<<30 ^ lo>>7^hi<<25
+       mov     $t0,$Alo,lsr#28
+       mov     $t1,$Ahi,lsr#28
+       eor     $t0,$t0,$Ahi,lsl#4
+       eor     $t1,$t1,$Alo,lsl#4
+       eor     $t0,$t0,$Ahi,lsr#2
+       eor     $t1,$t1,$Alo,lsr#2
+       eor     $t0,$t0,$Alo,lsl#30
+       eor     $t1,$t1,$Ahi,lsl#30
+       eor     $t0,$t0,$Ahi,lsr#7
+       eor     $t1,$t1,$Alo,lsr#7
+       eor     $t0,$t0,$Alo,lsl#25
+       eor     $t1,$t1,$Ahi,lsl#25     @ Sigma0(a)
+       adds    $Tlo,$Tlo,$t0
+       adc     $Thi,$Thi,$t1           @ T += Sigma0(a)
+
+       and     $t0,$Alo,$t2
+       orr     $Alo,$Alo,$t2
+       ldr     $t1,[sp,#$Boff+4]       @ b.hi
+       ldr     $t2,[sp,#$Coff+4]       @ c.hi
+       and     $Alo,$Alo,$t3
+       orr     $Alo,$Alo,$t0           @ Maj(a,b,c).lo
+       and     $t3,$Ahi,$t1
+       orr     $Ahi,$Ahi,$t1
+       and     $Ahi,$Ahi,$t2
+       orr     $Ahi,$Ahi,$t3           @ Maj(a,b,c).hi
+       adds    $Alo,$Alo,$Tlo
+       adc     $Ahi,$Ahi,$Thi          @ h += T
+
+       sub     sp,sp,#8
+       add     $Ktbl,$Ktbl,#8
+___
+}
+$code=<<___;
+.text
+.code  32
+.type  K512,%object
+.align 5
+K512:
+.word  0x428a2f98,0xd728ae22, 0x71374491,0x23ef65cd
+.word  0xb5c0fbcf,0xec4d3b2f, 0xe9b5dba5,0x8189dbbc
+.word  0x3956c25b,0xf348b538, 0x59f111f1,0xb605d019
+.word  0x923f82a4,0xaf194f9b, 0xab1c5ed5,0xda6d8118
+.word  0xd807aa98,0xa3030242, 0x12835b01,0x45706fbe
+.word  0x243185be,0x4ee4b28c, 0x550c7dc3,0xd5ffb4e2
+.word  0x72be5d74,0xf27b896f, 0x80deb1fe,0x3b1696b1
+.word  0x9bdc06a7,0x25c71235, 0xc19bf174,0xcf692694
+.word  0xe49b69c1,0x9ef14ad2, 0xefbe4786,0x384f25e3
+.word  0x0fc19dc6,0x8b8cd5b5, 0x240ca1cc,0x77ac9c65
+.word  0x2de92c6f,0x592b0275, 0x4a7484aa,0x6ea6e483
+.word  0x5cb0a9dc,0xbd41fbd4, 0x76f988da,0x831153b5
+.word  0x983e5152,0xee66dfab, 0xa831c66d,0x2db43210
+.word  0xb00327c8,0x98fb213f, 0xbf597fc7,0xbeef0ee4
+.word  0xc6e00bf3,0x3da88fc2, 0xd5a79147,0x930aa725
+.word  0x06ca6351,0xe003826f, 0x14292967,0x0a0e6e70
+.word  0x27b70a85,0x46d22ffc, 0x2e1b2138,0x5c26c926
+.word  0x4d2c6dfc,0x5ac42aed, 0x53380d13,0x9d95b3df
+.word  0x650a7354,0x8baf63de, 0x766a0abb,0x3c77b2a8
+.word  0x81c2c92e,0x47edaee6, 0x92722c85,0x1482353b
+.word  0xa2bfe8a1,0x4cf10364, 0xa81a664b,0xbc423001
+.word  0xc24b8b70,0xd0f89791, 0xc76c51a3,0x0654be30
+.word  0xd192e819,0xd6ef5218, 0xd6990624,0x5565a910
+.word  0xf40e3585,0x5771202a, 0x106aa070,0x32bbd1b8
+.word  0x19a4c116,0xb8d2d0c8, 0x1e376c08,0x5141ab53
+.word  0x2748774c,0xdf8eeb99, 0x34b0bcb5,0xe19b48a8
+.word  0x391c0cb3,0xc5c95a63, 0x4ed8aa4a,0xe3418acb
+.word  0x5b9cca4f,0x7763e373, 0x682e6ff3,0xd6b2b8a3
+.word  0x748f82ee,0x5defb2fc, 0x78a5636f,0x43172f60
+.word  0x84c87814,0xa1f0ab72, 0x8cc70208,0x1a6439ec
+.word  0x90befffa,0x23631e28, 0xa4506ceb,0xde82bde9
+.word  0xbef9a3f7,0xb2c67915, 0xc67178f2,0xe372532b
+.word  0xca273ece,0xea26619c, 0xd186b8c7,0x21c0c207
+.word  0xeada7dd6,0xcde0eb1e, 0xf57d4f7f,0xee6ed178
+.word  0x06f067aa,0x72176fba, 0x0a637dc5,0xa2c898a6
+.word  0x113f9804,0xbef90dae, 0x1b710b35,0x131c471b
+.word  0x28db77f5,0x23047d84, 0x32caab7b,0x40c72493
+.word  0x3c9ebe0a,0x15c9bebc, 0x431d67c4,0x9c100d4c
+.word  0x4cc5d4be,0xcb3e42b6, 0x597f299c,0xfc657e2a
+.word  0x5fcb6fab,0x3ad6faec, 0x6c44198c,0x4a475817
+.size  K512,.-K512
+
+.global        sha512_block_data_order
+.type  sha512_block_data_order,%function
+sha512_block_data_order:
+       sub     r3,pc,#8                @ sha512_block_data_order
+       add     $len,$inp,$len,lsl#7    @ len to point at the end of inp
+       stmdb   sp!,{r4-r12,lr}
+       sub     $Ktbl,r3,#640           @ K512
+       sub     sp,sp,#9*8
+
+       ldr     $Elo,[$ctx,#$Eoff+$lo]
+       ldr     $Ehi,[$ctx,#$Eoff+$hi]
+       ldr     $t0, [$ctx,#$Goff+$lo]
+       ldr     $t1, [$ctx,#$Goff+$hi]
+       ldr     $t2, [$ctx,#$Hoff+$lo]
+       ldr     $t3, [$ctx,#$Hoff+$hi]
+.Loop:
+       str     $t0, [sp,#$Goff+0]
+       str     $t1, [sp,#$Goff+4]
+       str     $t2, [sp,#$Hoff+0]
+       str     $t3, [sp,#$Hoff+4]
+       ldr     $Alo,[$ctx,#$Aoff+$lo]
+       ldr     $Ahi,[$ctx,#$Aoff+$hi]
+       ldr     $Tlo,[$ctx,#$Boff+$lo]
+       ldr     $Thi,[$ctx,#$Boff+$hi]
+       ldr     $t0, [$ctx,#$Coff+$lo]
+       ldr     $t1, [$ctx,#$Coff+$hi]
+       ldr     $t2, [$ctx,#$Doff+$lo]
+       ldr     $t3, [$ctx,#$Doff+$hi]
+       str     $Tlo,[sp,#$Boff+0]
+       str     $Thi,[sp,#$Boff+4]
+       str     $t0, [sp,#$Coff+0]
+       str     $t1, [sp,#$Coff+4]
+       str     $t2, [sp,#$Doff+0]
+       str     $t3, [sp,#$Doff+4]
+       ldr     $Tlo,[$ctx,#$Foff+$lo]
+       ldr     $Thi,[$ctx,#$Foff+$hi]
+       str     $Tlo,[sp,#$Foff+0]
+       str     $Thi,[sp,#$Foff+4]
+
+.L00_15:
+       ldrb    $Tlo,[$inp,#7]
+       ldrb    $t0, [$inp,#6]
+       ldrb    $t1, [$inp,#5]
+       ldrb    $t2, [$inp,#4]
+       ldrb    $Thi,[$inp,#3]
+       ldrb    $t3, [$inp,#2]
+       orr     $Tlo,$Tlo,$t0,lsl#8
+       ldrb    $t0, [$inp,#1]
+       orr     $Tlo,$Tlo,$t1,lsl#16
+       ldrb    $t1, [$inp],#8
+       orr     $Tlo,$Tlo,$t2,lsl#24
+       orr     $Thi,$Thi,$t3,lsl#8
+       orr     $Thi,$Thi,$t0,lsl#16
+       orr     $Thi,$Thi,$t1,lsl#24
+       str     $Tlo,[sp,#$Xoff+0]
+       str     $Thi,[sp,#$Xoff+4]
+___
+       &BODY_00_15(0x94);
+$code.=<<___;
+       tst     $Ktbl,#1
+       beq     .L00_15
+       bic     $Ktbl,$Ktbl,#1
+
+.L16_79:
+       ldr     $t0,[sp,#`$Xoff+8*(16-1)`+0]
+       ldr     $t1,[sp,#`$Xoff+8*(16-1)`+4]
+       ldr     $t2,[sp,#`$Xoff+8*(16-14)`+0]
+       ldr     $t3,[sp,#`$Xoff+8*(16-14)`+4]
+
+       @ sigma0(x)     (ROTR((x),1)  ^ ROTR((x),8)  ^ ((x)>>7))
+       @ LO            lo>>1^hi<<31  ^ lo>>8^hi<<24 ^ lo>>7^hi<<25
+       @ HI            hi>>1^lo<<31  ^ hi>>8^lo<<24 ^ hi>>7
+       mov     $Tlo,$t0,lsr#1
+       mov     $Thi,$t1,lsr#1
+       eor     $Tlo,$Tlo,$t1,lsl#31
+       eor     $Thi,$Thi,$t0,lsl#31
+       eor     $Tlo,$Tlo,$t0,lsr#8
+       eor     $Thi,$Thi,$t1,lsr#8
+       eor     $Tlo,$Tlo,$t1,lsl#24
+       eor     $Thi,$Thi,$t0,lsl#24
+       eor     $Tlo,$Tlo,$t0,lsr#7
+       eor     $Thi,$Thi,$t1,lsr#7
+       eor     $Tlo,$Tlo,$t1,lsl#25
+
+       @ sigma1(x)     (ROTR((x),19) ^ ROTR((x),61) ^ ((x)>>6))
+       @ LO            lo>>19^hi<<13 ^ hi>>29^lo<<3 ^ lo>>6^hi<<26
+       @ HI            hi>>19^lo<<13 ^ lo>>29^hi<<3 ^ hi>>6
+       mov     $t0,$t2,lsr#19
+       mov     $t1,$t3,lsr#19
+       eor     $t0,$t0,$t3,lsl#13
+       eor     $t1,$t1,$t2,lsl#13
+       eor     $t0,$t0,$t3,lsr#29
+       eor     $t1,$t1,$t2,lsr#29
+       eor     $t0,$t0,$t2,lsl#3
+       eor     $t1,$t1,$t3,lsl#3
+       eor     $t0,$t0,$t2,lsr#6
+       eor     $t1,$t1,$t3,lsr#6
+       eor     $t0,$t0,$t3,lsl#26
+
+       ldr     $t2,[sp,#`$Xoff+8*(16-9)`+0]
+       ldr     $t3,[sp,#`$Xoff+8*(16-9)`+4]
+       adds    $Tlo,$Tlo,$t0
+       adc     $Thi,$Thi,$t1
+
+       ldr     $t0,[sp,#`$Xoff+8*16`+0]
+       ldr     $t1,[sp,#`$Xoff+8*16`+4]
+       adds    $Tlo,$Tlo,$t2
+       adc     $Thi,$Thi,$t3
+       adds    $Tlo,$Tlo,$t0
+       adc     $Thi,$Thi,$t1
+       str     $Tlo,[sp,#$Xoff+0]
+       str     $Thi,[sp,#$Xoff+4]
+___
+       &BODY_00_15(0x17);
+$code.=<<___;
+       tst     $Ktbl,#1
+       beq     .L16_79
+       bic     $Ktbl,$Ktbl,#1
+
+       ldr     $Tlo,[sp,#$Boff+0]
+       ldr     $Thi,[sp,#$Boff+4]
+       ldr     $t0, [$ctx,#$Aoff+$lo]
+       ldr     $t1, [$ctx,#$Aoff+$hi]
+       ldr     $t2, [$ctx,#$Boff+$lo]
+       ldr     $t3, [$ctx,#$Boff+$hi]
+       adds    $t0,$Alo,$t0
+       adc     $t1,$Ahi,$t1
+       adds    $t2,$Tlo,$t2
+       adc     $t3,$Thi,$t3
+       str     $t0, [$ctx,#$Aoff+$lo]
+       str     $t1, [$ctx,#$Aoff+$hi]
+       str     $t2, [$ctx,#$Boff+$lo]
+       str     $t3, [$ctx,#$Boff+$hi]
+
+       ldr     $Alo,[sp,#$Coff+0]
+       ldr     $Ahi,[sp,#$Coff+4]
+       ldr     $Tlo,[sp,#$Doff+0]
+       ldr     $Thi,[sp,#$Doff+4]
+       ldr     $t0, [$ctx,#$Coff+$lo]
+       ldr     $t1, [$ctx,#$Coff+$hi]
+       ldr     $t2, [$ctx,#$Doff+$lo]
+       ldr     $t3, [$ctx,#$Doff+$hi]
+       adds    $t0,$Alo,$t0
+       adc     $t1,$Ahi,$t1
+       adds    $t2,$Tlo,$t2
+       adc     $t3,$Thi,$t3
+       str     $t0, [$ctx,#$Coff+$lo]
+       str     $t1, [$ctx,#$Coff+$hi]
+       str     $t2, [$ctx,#$Doff+$lo]
+       str     $t3, [$ctx,#$Doff+$hi]
+
+       ldr     $Tlo,[sp,#$Foff+0]
+       ldr     $Thi,[sp,#$Foff+4]
+       ldr     $t0, [$ctx,#$Eoff+$lo]
+       ldr     $t1, [$ctx,#$Eoff+$hi]
+       ldr     $t2, [$ctx,#$Foff+$lo]
+       ldr     $t3, [$ctx,#$Foff+$hi]
+       adds    $Elo,$Elo,$t0
+       adc     $Ehi,$Ehi,$t1
+       adds    $t2,$Tlo,$t2
+       adc     $t3,$Thi,$t3
+       str     $Elo,[$ctx,#$Eoff+$lo]
+       str     $Ehi,[$ctx,#$Eoff+$hi]
+       str     $t2, [$ctx,#$Foff+$lo]
+       str     $t3, [$ctx,#$Foff+$hi]
+
+       ldr     $Alo,[sp,#$Goff+0]
+       ldr     $Ahi,[sp,#$Goff+4]
+       ldr     $Tlo,[sp,#$Hoff+0]
+       ldr     $Thi,[sp,#$Hoff+4]
+       ldr     $t0, [$ctx,#$Goff+$lo]
+       ldr     $t1, [$ctx,#$Goff+$hi]
+       ldr     $t2, [$ctx,#$Hoff+$lo]
+       ldr     $t3, [$ctx,#$Hoff+$hi]
+       adds    $t0,$Alo,$t0
+       adc     $t1,$Ahi,$t1
+       adds    $t2,$Tlo,$t2
+       adc     $t3,$Thi,$t3
+       str     $t0, [$ctx,#$Goff+$lo]
+       str     $t1, [$ctx,#$Goff+$hi]
+       str     $t2, [$ctx,#$Hoff+$lo]
+       str     $t3, [$ctx,#$Hoff+$hi]
+
+       add     sp,sp,#640
+       sub     $Ktbl,$Ktbl,#640
+
+       teq     $inp,$len
+       bne     .Loop
+
+       add     sp,sp,#8*9              @ destroy frame
+       ldmia   sp!,{r4-r12,lr}
+       tst     lr,#1
+       moveq   pc,lr                   @ be binary compatible with V4, yet
+       bx      lr                      @ interoperable with Thumb ISA:-)
+.size   sha512_block_data_order,.-sha512_block_data_order
+.asciz  "SHA512 block transform for ARMv4, CRYPTOGAMS by <appro\@openssl.org>"
+.align 2
+___
+
+$code =~ s/\`([^\`]*)\`/eval $1/gem;
+$code =~ s/\bbx\s+lr\b/.word\t0xe12fff1e/gm;   # make it possible to compile with -march=armv4
+print $code;
+close STDOUT; # enforce flush
diff --git a/deps/openssl/openssl/crypto/sha/asm/sha512-ppc.pl b/deps/openssl/openssl/crypto/sha/asm/sha512-ppc.pl
new file mode 100644 (file)
index 0000000..768a6a6
--- /dev/null
@@ -0,0 +1,462 @@
+#!/usr/bin/env perl
+
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+
+# I let hardware handle unaligned input, except on page boundaries
+# (see below for details). Otherwise straightforward implementation
+# with X vector in register bank. The module is big-endian [which is
+# not big deal as there're no little-endian targets left around].
+
+#                      sha256          |       sha512
+#                      -m64    -m32    |       -m64    -m32
+# --------------------------------------+-----------------------
+# PPC970,gcc-4.0.0     +50%    +38%    |       +40%    +410%(*)
+# Power6,xlc-7         +150%   +90%    |       +100%   +430%(*)
+#
+# (*)  64-bit code in 32-bit application context, which actually is
+#      on TODO list. It should be noted that for safe deployment in
+#      32-bit *mutli-threaded* context asyncronous signals should be
+#      blocked upon entry to SHA512 block routine. This is because
+#      32-bit signaling procedure invalidates upper halves of GPRs.
+#      Context switch procedure preserves them, but not signaling:-(
+
+# Second version is true multi-thread safe. Trouble with the original
+# version was that it was using thread local storage pointer register.
+# Well, it scrupulously preserved it, but the problem would arise the
+# moment asynchronous signal was delivered and signal handler would
+# dereference the TLS pointer. While it's never the case in openssl
+# application or test suite, we have to respect this scenario and not
+# use TLS pointer register. Alternative would be to require caller to
+# block signals prior calling this routine. For the record, in 32-bit
+# context R2 serves as TLS pointer, while in 64-bit context - R13.
+
+$flavour=shift;
+$output =shift;
+
+if ($flavour =~ /64/) {
+       $SIZE_T=8;
+       $STU="stdu";
+       $UCMP="cmpld";
+       $SHL="sldi";
+       $POP="ld";
+       $PUSH="std";
+} elsif ($flavour =~ /32/) {
+       $SIZE_T=4;
+       $STU="stwu";
+       $UCMP="cmplw";
+       $SHL="slwi";
+       $POP="lwz";
+       $PUSH="stw";
+} else { die "nonsense $flavour"; }
+
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+( $xlate="${dir}ppc-xlate.pl" and -f $xlate ) or
+( $xlate="${dir}../../perlasm/ppc-xlate.pl" and -f $xlate) or
+die "can't locate ppc-xlate.pl";
+
+open STDOUT,"| $^X $xlate $flavour $output" || die "can't call $xlate: $!";
+
+if ($output =~ /512/) {
+       $func="sha512_block_data_order";
+       $SZ=8;
+       @Sigma0=(28,34,39);
+       @Sigma1=(14,18,41);
+       @sigma0=(1,  8, 7);
+       @sigma1=(19,61, 6);
+       $rounds=80;
+       $LD="ld";
+       $ST="std";
+       $ROR="rotrdi";
+       $SHR="srdi";
+} else {
+       $func="sha256_block_data_order";
+       $SZ=4;
+       @Sigma0=( 2,13,22);
+       @Sigma1=( 6,11,25);
+       @sigma0=( 7,18, 3);
+       @sigma1=(17,19,10);
+       $rounds=64;
+       $LD="lwz";
+       $ST="stw";
+       $ROR="rotrwi";
+       $SHR="srwi";
+}
+
+$FRAME=32*$SIZE_T;
+
+$sp ="r1";
+$toc="r2";
+$ctx="r3";     # zapped by $a0
+$inp="r4";     # zapped by $a1
+$num="r5";     # zapped by $t0
+
+$T  ="r0";
+$a0 ="r3";
+$a1 ="r4";
+$t0 ="r5";
+$t1 ="r6";
+$Tbl="r7";
+
+$A  ="r8";
+$B  ="r9";
+$C  ="r10";
+$D  ="r11";
+$E  ="r12";
+$F  ="r13";    $F="r2" if ($SIZE_T==8);# reassigned to exempt TLS pointer
+$G  ="r14";
+$H  ="r15";
+
+@V=($A,$B,$C,$D,$E,$F,$G,$H);
+@X=("r16","r17","r18","r19","r20","r21","r22","r23",
+    "r24","r25","r26","r27","r28","r29","r30","r31");
+
+$inp="r31";    # reassigned $inp! aliases with @X[15]
+
+sub ROUND_00_15 {
+my ($i,$a,$b,$c,$d,$e,$f,$g,$h)=@_;
+$code.=<<___;
+       $LD     $T,`$i*$SZ`($Tbl)
+       $ROR    $a0,$e,$Sigma1[0]
+       $ROR    $a1,$e,$Sigma1[1]
+       and     $t0,$f,$e
+       andc    $t1,$g,$e
+       add     $T,$T,$h
+       xor     $a0,$a0,$a1
+       $ROR    $a1,$a1,`$Sigma1[2]-$Sigma1[1]`
+       or      $t0,$t0,$t1             ; Ch(e,f,g)
+       add     $T,$T,@X[$i]
+       xor     $a0,$a0,$a1             ; Sigma1(e)
+       add     $T,$T,$t0
+       add     $T,$T,$a0
+
+       $ROR    $a0,$a,$Sigma0[0]
+       $ROR    $a1,$a,$Sigma0[1]
+       and     $t0,$a,$b
+       and     $t1,$a,$c
+       xor     $a0,$a0,$a1
+       $ROR    $a1,$a1,`$Sigma0[2]-$Sigma0[1]`
+       xor     $t0,$t0,$t1
+       and     $t1,$b,$c
+       xor     $a0,$a0,$a1             ; Sigma0(a)
+       add     $d,$d,$T
+       xor     $t0,$t0,$t1             ; Maj(a,b,c)
+       add     $h,$T,$a0
+       add     $h,$h,$t0
+
+___
+}
+
+sub ROUND_16_xx {
+my ($i,$a,$b,$c,$d,$e,$f,$g,$h)=@_;
+$i-=16;
+$code.=<<___;
+       $ROR    $a0,@X[($i+1)%16],$sigma0[0]
+       $ROR    $a1,@X[($i+1)%16],$sigma0[1]
+       $ROR    $t0,@X[($i+14)%16],$sigma1[0]
+       $ROR    $t1,@X[($i+14)%16],$sigma1[1]
+       xor     $a0,$a0,$a1
+       $SHR    $a1,@X[($i+1)%16],$sigma0[2]
+       xor     $t0,$t0,$t1
+       $SHR    $t1,@X[($i+14)%16],$sigma1[2]
+       add     @X[$i],@X[$i],@X[($i+9)%16]
+       xor     $a0,$a0,$a1             ; sigma0(X[(i+1)&0x0f])
+       xor     $t0,$t0,$t1             ; sigma1(X[(i+14)&0x0f])
+       add     @X[$i],@X[$i],$a0
+       add     @X[$i],@X[$i],$t0
+___
+&ROUND_00_15($i,$a,$b,$c,$d,$e,$f,$g,$h);
+}
+
+$code=<<___;
+.machine       "any"
+.text
+
+.globl $func
+.align 6
+$func:
+       mflr    r0
+       $STU    $sp,`-($FRAME+16*$SZ)`($sp)
+       $SHL    $num,$num,`log(16*$SZ)/log(2)`
+
+       $PUSH   $ctx,`$FRAME-$SIZE_T*22`($sp)
+
+       $PUSH   r0,`$FRAME-$SIZE_T*21`($sp)
+       $PUSH   $toc,`$FRAME-$SIZE_T*20`($sp)
+       $PUSH   r13,`$FRAME-$SIZE_T*19`($sp)
+       $PUSH   r14,`$FRAME-$SIZE_T*18`($sp)
+       $PUSH   r15,`$FRAME-$SIZE_T*17`($sp)
+       $PUSH   r16,`$FRAME-$SIZE_T*16`($sp)
+       $PUSH   r17,`$FRAME-$SIZE_T*15`($sp)
+       $PUSH   r18,`$FRAME-$SIZE_T*14`($sp)
+       $PUSH   r19,`$FRAME-$SIZE_T*13`($sp)
+       $PUSH   r20,`$FRAME-$SIZE_T*12`($sp)
+       $PUSH   r21,`$FRAME-$SIZE_T*11`($sp)
+       $PUSH   r22,`$FRAME-$SIZE_T*10`($sp)
+       $PUSH   r23,`$FRAME-$SIZE_T*9`($sp)
+       $PUSH   r24,`$FRAME-$SIZE_T*8`($sp)
+       $PUSH   r25,`$FRAME-$SIZE_T*7`($sp)
+       $PUSH   r26,`$FRAME-$SIZE_T*6`($sp)
+       $PUSH   r27,`$FRAME-$SIZE_T*5`($sp)
+       $PUSH   r28,`$FRAME-$SIZE_T*4`($sp)
+       $PUSH   r29,`$FRAME-$SIZE_T*3`($sp)
+       $PUSH   r30,`$FRAME-$SIZE_T*2`($sp)
+       $PUSH   r31,`$FRAME-$SIZE_T*1`($sp)
+
+       $LD     $A,`0*$SZ`($ctx)
+       mr      $inp,r4                         ; incarnate $inp
+       $LD     $B,`1*$SZ`($ctx)
+       $LD     $C,`2*$SZ`($ctx)
+       $LD     $D,`3*$SZ`($ctx)
+       $LD     $E,`4*$SZ`($ctx)
+       $LD     $F,`5*$SZ`($ctx)
+       $LD     $G,`6*$SZ`($ctx)
+       $LD     $H,`7*$SZ`($ctx)
+
+       b       LPICmeup
+LPICedup:
+       andi.   r0,$inp,3
+       bne     Lunaligned
+Laligned:
+       add     $num,$inp,$num
+       $PUSH   $num,`$FRAME-$SIZE_T*24`($sp)   ; end pointer
+       $PUSH   $inp,`$FRAME-$SIZE_T*23`($sp)   ; inp pointer
+       bl      Lsha2_block_private
+Ldone:
+       $POP    r0,`$FRAME-$SIZE_T*21`($sp)
+       $POP    $toc,`$FRAME-$SIZE_T*20`($sp)
+       $POP    r13,`$FRAME-$SIZE_T*19`($sp)
+       $POP    r14,`$FRAME-$SIZE_T*18`($sp)
+       $POP    r15,`$FRAME-$SIZE_T*17`($sp)
+       $POP    r16,`$FRAME-$SIZE_T*16`($sp)
+       $POP    r17,`$FRAME-$SIZE_T*15`($sp)
+       $POP    r18,`$FRAME-$SIZE_T*14`($sp)
+       $POP    r19,`$FRAME-$SIZE_T*13`($sp)
+       $POP    r20,`$FRAME-$SIZE_T*12`($sp)
+       $POP    r21,`$FRAME-$SIZE_T*11`($sp)
+       $POP    r22,`$FRAME-$SIZE_T*10`($sp)
+       $POP    r23,`$FRAME-$SIZE_T*9`($sp)
+       $POP    r24,`$FRAME-$SIZE_T*8`($sp)
+       $POP    r25,`$FRAME-$SIZE_T*7`($sp)
+       $POP    r26,`$FRAME-$SIZE_T*6`($sp)
+       $POP    r27,`$FRAME-$SIZE_T*5`($sp)
+       $POP    r28,`$FRAME-$SIZE_T*4`($sp)
+       $POP    r29,`$FRAME-$SIZE_T*3`($sp)
+       $POP    r30,`$FRAME-$SIZE_T*2`($sp)
+       $POP    r31,`$FRAME-$SIZE_T*1`($sp)
+       mtlr    r0
+       addi    $sp,$sp,`$FRAME+16*$SZ`
+       blr
+___
+
+# PowerPC specification allows an implementation to be ill-behaved
+# upon unaligned access which crosses page boundary. "Better safe
+# than sorry" principle makes me treat it specially. But I don't
+# look for particular offending word, but rather for the input
+# block which crosses the boundary. Once found that block is aligned
+# and hashed separately...
+$code.=<<___;
+.align 4
+Lunaligned:
+       subfic  $t1,$inp,4096
+       andi.   $t1,$t1,`4096-16*$SZ`   ; distance to closest page boundary
+       beq     Lcross_page
+       $UCMP   $num,$t1
+       ble-    Laligned                ; didn't cross the page boundary
+       subfc   $num,$t1,$num
+       add     $t1,$inp,$t1
+       $PUSH   $num,`$FRAME-$SIZE_T*25`($sp)   ; save real remaining num
+       $PUSH   $t1,`$FRAME-$SIZE_T*24`($sp)    ; intermediate end pointer
+       $PUSH   $inp,`$FRAME-$SIZE_T*23`($sp)   ; inp pointer
+       bl      Lsha2_block_private
+       ; $inp equals to the intermediate end pointer here
+       $POP    $num,`$FRAME-$SIZE_T*25`($sp)   ; restore real remaining num
+Lcross_page:
+       li      $t1,`16*$SZ/4`
+       mtctr   $t1
+       addi    r20,$sp,$FRAME                  ; aligned spot below the frame
+Lmemcpy:
+       lbz     r16,0($inp)
+       lbz     r17,1($inp)
+       lbz     r18,2($inp)
+       lbz     r19,3($inp)
+       addi    $inp,$inp,4
+       stb     r16,0(r20)
+       stb     r17,1(r20)
+       stb     r18,2(r20)
+       stb     r19,3(r20)
+       addi    r20,r20,4
+       bdnz    Lmemcpy
+
+       $PUSH   $inp,`$FRAME-$SIZE_T*26`($sp)   ; save real inp
+       addi    $t1,$sp,`$FRAME+16*$SZ`         ; fictitious end pointer
+       addi    $inp,$sp,$FRAME                 ; fictitious inp pointer
+       $PUSH   $num,`$FRAME-$SIZE_T*25`($sp)   ; save real num
+       $PUSH   $t1,`$FRAME-$SIZE_T*24`($sp)    ; end pointer
+       $PUSH   $inp,`$FRAME-$SIZE_T*23`($sp)   ; inp pointer
+       bl      Lsha2_block_private
+       $POP    $inp,`$FRAME-$SIZE_T*26`($sp)   ; restore real inp
+       $POP    $num,`$FRAME-$SIZE_T*25`($sp)   ; restore real num
+       addic.  $num,$num,`-16*$SZ`             ; num--
+       bne-    Lunaligned
+       b       Ldone
+___
+
+$code.=<<___;
+.align 4
+Lsha2_block_private:
+___
+for($i=0;$i<16;$i++) {
+$code.=<<___ if ($SZ==4);
+       lwz     @X[$i],`$i*$SZ`($inp)
+___
+# 64-bit loads are split to 2x32-bit ones, as CPU can't handle
+# unaligned 64-bit loads, only 32-bit ones...
+$code.=<<___ if ($SZ==8);
+       lwz     $t0,`$i*$SZ`($inp)
+       lwz     @X[$i],`$i*$SZ+4`($inp)
+       insrdi  @X[$i],$t0,32,0
+___
+       &ROUND_00_15($i,@V);
+       unshift(@V,pop(@V));
+}
+$code.=<<___;
+       li      $T,`$rounds/16-1`
+       mtctr   $T
+.align 4
+Lrounds:
+       addi    $Tbl,$Tbl,`16*$SZ`
+___
+for(;$i<32;$i++) {
+       &ROUND_16_xx($i,@V);
+       unshift(@V,pop(@V));
+}
+$code.=<<___;
+       bdnz-   Lrounds
+
+       $POP    $ctx,`$FRAME-$SIZE_T*22`($sp)
+       $POP    $inp,`$FRAME-$SIZE_T*23`($sp)   ; inp pointer
+       $POP    $num,`$FRAME-$SIZE_T*24`($sp)   ; end pointer
+       subi    $Tbl,$Tbl,`($rounds-16)*$SZ`    ; rewind Tbl
+
+       $LD     r16,`0*$SZ`($ctx)
+       $LD     r17,`1*$SZ`($ctx)
+       $LD     r18,`2*$SZ`($ctx)
+       $LD     r19,`3*$SZ`($ctx)
+       $LD     r20,`4*$SZ`($ctx)
+       $LD     r21,`5*$SZ`($ctx)
+       $LD     r22,`6*$SZ`($ctx)
+       addi    $inp,$inp,`16*$SZ`              ; advance inp
+       $LD     r23,`7*$SZ`($ctx)
+       add     $A,$A,r16
+       add     $B,$B,r17
+       $PUSH   $inp,`$FRAME-$SIZE_T*23`($sp)
+       add     $C,$C,r18
+       $ST     $A,`0*$SZ`($ctx)
+       add     $D,$D,r19
+       $ST     $B,`1*$SZ`($ctx)
+       add     $E,$E,r20
+       $ST     $C,`2*$SZ`($ctx)
+       add     $F,$F,r21
+       $ST     $D,`3*$SZ`($ctx)
+       add     $G,$G,r22
+       $ST     $E,`4*$SZ`($ctx)
+       add     $H,$H,r23
+       $ST     $F,`5*$SZ`($ctx)
+       $ST     $G,`6*$SZ`($ctx)
+       $UCMP   $inp,$num
+       $ST     $H,`7*$SZ`($ctx)
+       bne     Lsha2_block_private
+       blr
+___
+
+# Ugly hack here, because PPC assembler syntax seem to vary too
+# much from platforms to platform...
+$code.=<<___;
+.align 6
+LPICmeup:
+       bl      LPIC
+       addi    $Tbl,$Tbl,`64-4`        ; "distance" between . and last nop
+       b       LPICedup
+       nop
+       nop
+       nop
+       nop
+       nop
+LPIC:  mflr    $Tbl
+       blr
+       nop
+       nop
+       nop
+       nop
+       nop
+       nop
+___
+$code.=<<___ if ($SZ==8);
+       .long   0x428a2f98,0xd728ae22,0x71374491,0x23ef65cd
+       .long   0xb5c0fbcf,0xec4d3b2f,0xe9b5dba5,0x8189dbbc
+       .long   0x3956c25b,0xf348b538,0x59f111f1,0xb605d019
+       .long   0x923f82a4,0xaf194f9b,0xab1c5ed5,0xda6d8118
+       .long   0xd807aa98,0xa3030242,0x12835b01,0x45706fbe
+       .long   0x243185be,0x4ee4b28c,0x550c7dc3,0xd5ffb4e2
+       .long   0x72be5d74,0xf27b896f,0x80deb1fe,0x3b1696b1
+       .long   0x9bdc06a7,0x25c71235,0xc19bf174,0xcf692694
+       .long   0xe49b69c1,0x9ef14ad2,0xefbe4786,0x384f25e3
+       .long   0x0fc19dc6,0x8b8cd5b5,0x240ca1cc,0x77ac9c65
+       .long   0x2de92c6f,0x592b0275,0x4a7484aa,0x6ea6e483
+       .long   0x5cb0a9dc,0xbd41fbd4,0x76f988da,0x831153b5
+       .long   0x983e5152,0xee66dfab,0xa831c66d,0x2db43210
+       .long   0xb00327c8,0x98fb213f,0xbf597fc7,0xbeef0ee4
+       .long   0xc6e00bf3,0x3da88fc2,0xd5a79147,0x930aa725
+       .long   0x06ca6351,0xe003826f,0x14292967,0x0a0e6e70
+       .long   0x27b70a85,0x46d22ffc,0x2e1b2138,0x5c26c926
+       .long   0x4d2c6dfc,0x5ac42aed,0x53380d13,0x9d95b3df
+       .long   0x650a7354,0x8baf63de,0x766a0abb,0x3c77b2a8
+       .long   0x81c2c92e,0x47edaee6,0x92722c85,0x1482353b
+       .long   0xa2bfe8a1,0x4cf10364,0xa81a664b,0xbc423001
+       .long   0xc24b8b70,0xd0f89791,0xc76c51a3,0x0654be30
+       .long   0xd192e819,0xd6ef5218,0xd6990624,0x5565a910
+       .long   0xf40e3585,0x5771202a,0x106aa070,0x32bbd1b8
+       .long   0x19a4c116,0xb8d2d0c8,0x1e376c08,0x5141ab53
+       .long   0x2748774c,0xdf8eeb99,0x34b0bcb5,0xe19b48a8
+       .long   0x391c0cb3,0xc5c95a63,0x4ed8aa4a,0xe3418acb
+       .long   0x5b9cca4f,0x7763e373,0x682e6ff3,0xd6b2b8a3
+       .long   0x748f82ee,0x5defb2fc,0x78a5636f,0x43172f60
+       .long   0x84c87814,0xa1f0ab72,0x8cc70208,0x1a6439ec
+       .long   0x90befffa,0x23631e28,0xa4506ceb,0xde82bde9
+       .long   0xbef9a3f7,0xb2c67915,0xc67178f2,0xe372532b
+       .long   0xca273ece,0xea26619c,0xd186b8c7,0x21c0c207
+       .long   0xeada7dd6,0xcde0eb1e,0xf57d4f7f,0xee6ed178
+       .long   0x06f067aa,0x72176fba,0x0a637dc5,0xa2c898a6
+       .long   0x113f9804,0xbef90dae,0x1b710b35,0x131c471b
+       .long   0x28db77f5,0x23047d84,0x32caab7b,0x40c72493
+       .long   0x3c9ebe0a,0x15c9bebc,0x431d67c4,0x9c100d4c
+       .long   0x4cc5d4be,0xcb3e42b6,0x597f299c,0xfc657e2a
+       .long   0x5fcb6fab,0x3ad6faec,0x6c44198c,0x4a475817
+___
+$code.=<<___ if ($SZ==4);
+       .long   0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5
+       .long   0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5
+       .long   0xd807aa98,0x12835b01,0x243185be,0x550c7dc3
+       .long   0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174
+       .long   0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc
+       .long   0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da
+       .long   0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7
+       .long   0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967
+       .long   0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13
+       .long   0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85
+       .long   0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3
+       .long   0xd192e819,0xd6990624,0xf40e3585,0x106aa070
+       .long   0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5
+       .long   0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3
+       .long   0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208
+       .long   0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2
+___
+
+$code =~ s/\`([^\`]*)\`/eval $1/gem;
+print $code;
+close STDOUT;
diff --git a/deps/openssl/openssl/crypto/sha/asm/sha512-s390x.pl b/deps/openssl/openssl/crypto/sha/asm/sha512-s390x.pl
new file mode 100644 (file)
index 0000000..e7ef2d5
--- /dev/null
@@ -0,0 +1,301 @@
+#!/usr/bin/env perl
+
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+
+# SHA256/512 block procedures for s390x.
+
+# April 2007.
+#
+# sha256_block_data_order is reportedly >3 times faster than gcc 3.3
+# generated code (must be a bug in compiler, as improvement is
+# "pathologically" high, in particular in comparison to other SHA
+# modules). But the real twist is that it detects if hardware support
+# for SHA256 is available and in such case utilizes it. Then the
+# performance can reach >6.5x of assembler one for larger chunks.
+#
+# sha512_block_data_order is ~70% faster than gcc 3.3 generated code.
+
+# January 2009.
+#
+# Add support for hardware SHA512 and reschedule instructions to
+# favour dual-issue z10 pipeline. Hardware SHA256/512 is ~4.7x faster
+# than software.
+
+$t0="%r0";
+$t1="%r1";
+$ctx="%r2";    $t2="%r2";
+$inp="%r3";
+$len="%r4";    # used as index in inner loop
+
+$A="%r5";
+$B="%r6";
+$C="%r7";
+$D="%r8";
+$E="%r9";
+$F="%r10";
+$G="%r11";
+$H="%r12";     @V=($A,$B,$C,$D,$E,$F,$G,$H);
+$tbl="%r13";
+$T1="%r14";
+$sp="%r15";
+
+$output=shift;
+open STDOUT,">$output";
+
+if ($output =~ /512/) {
+       $label="512";
+       $SZ=8;
+       $LD="lg";       # load from memory
+       $ST="stg";      # store to memory
+       $ADD="alg";     # add with memory operand
+       $ROT="rllg";    # rotate left
+       $SHR="srlg";    # logical right shift [see even at the end]
+       @Sigma0=(25,30,36);
+       @Sigma1=(23,46,50);
+       @sigma0=(56,63, 7);
+       @sigma1=( 3,45, 6);
+       $rounds=80;
+       $kimdfunc=3;    # 0 means unknown/unsupported/unimplemented/disabled
+} else {
+       $label="256";
+       $SZ=4;
+       $LD="llgf";     # load from memory
+       $ST="st";       # store to memory
+       $ADD="al";      # add with memory operand
+       $ROT="rll";     # rotate left
+       $SHR="srl";     # logical right shift
+       @Sigma0=(10,19,30);
+       @Sigma1=( 7,21,26);
+       @sigma0=(14,25, 3);
+       @sigma1=(13,15,10);
+       $rounds=64;
+       $kimdfunc=2;    # magic function code for kimd instruction
+}
+$Func="sha${label}_block_data_order";
+$Table="K${label}";
+$frame=160+16*$SZ;
+
+sub BODY_00_15 {
+my ($i,$a,$b,$c,$d,$e,$f,$g,$h) = @_;
+
+$code.=<<___ if ($i<16);
+       $LD     $T1,`$i*$SZ`($inp)      ### $i
+___
+$code.=<<___;
+       $ROT    $t0,$e,$Sigma1[0]
+       $ROT    $t1,$e,$Sigma1[1]
+        lgr    $t2,$f
+       xgr     $t0,$t1
+       $ROT    $t1,$t1,`$Sigma1[2]-$Sigma1[1]`
+        xgr    $t2,$g
+       $ST     $T1,`160+$SZ*($i%16)`($sp)
+       xgr     $t0,$t1                 # Sigma1(e)
+       la      $T1,0($T1,$h)           # T1+=h
+        ngr    $t2,$e
+        lgr    $t1,$a
+       algr    $T1,$t0                 # T1+=Sigma1(e)
+       $ROT    $h,$a,$Sigma0[0]
+        xgr    $t2,$g                  # Ch(e,f,g)
+       $ADD    $T1,`$i*$SZ`($len,$tbl) # T1+=K[i]
+       $ROT    $t0,$a,$Sigma0[1]
+       algr    $T1,$t2                 # T1+=Ch(e,f,g)
+        ogr    $t1,$b
+       xgr     $h,$t0
+        lgr    $t2,$a
+        ngr    $t1,$c
+       $ROT    $t0,$t0,`$Sigma0[2]-$Sigma0[1]`
+       xgr     $h,$t0                  # h=Sigma0(a)
+        ngr    $t2,$b
+       algr    $h,$T1                  # h+=T1
+        ogr    $t2,$t1                 # Maj(a,b,c)
+       la      $d,0($d,$T1)            # d+=T1
+       algr    $h,$t2                  # h+=Maj(a,b,c)
+___
+}
+
+sub BODY_16_XX {
+my ($i,$a,$b,$c,$d,$e,$f,$g,$h) = @_;
+
+$code.=<<___;
+       $LD     $T1,`160+$SZ*(($i+1)%16)`($sp)  ### $i
+       $LD     $t1,`160+$SZ*(($i+14)%16)`($sp)
+       $ROT    $t0,$T1,$sigma0[0]
+       $SHR    $T1,$sigma0[2]
+       $ROT    $t2,$t0,`$sigma0[1]-$sigma0[0]`
+       xgr     $T1,$t0
+       $ROT    $t0,$t1,$sigma1[0]
+       xgr     $T1,$t2                         # sigma0(X[i+1])
+       $SHR    $t1,$sigma1[2]
+       $ADD    $T1,`160+$SZ*($i%16)`($sp)      # +=X[i]
+       xgr     $t1,$t0
+       $ROT    $t0,$t0,`$sigma1[1]-$sigma1[0]`
+       $ADD    $T1,`160+$SZ*(($i+9)%16)`($sp)  # +=X[i+9]
+       xgr     $t1,$t0                         # sigma1(X[i+14])
+       algr    $T1,$t1                         # +=sigma1(X[i+14])
+___
+       &BODY_00_15(@_);
+}
+
+$code.=<<___;
+.text
+.align 64
+.type  $Table,\@object
+$Table:
+___
+$code.=<<___ if ($SZ==4);
+       .long   0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5
+       .long   0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5
+       .long   0xd807aa98,0x12835b01,0x243185be,0x550c7dc3
+       .long   0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174
+       .long   0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc
+       .long   0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da
+       .long   0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7
+       .long   0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967
+       .long   0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13
+       .long   0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85
+       .long   0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3
+       .long   0xd192e819,0xd6990624,0xf40e3585,0x106aa070
+       .long   0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5
+       .long   0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3
+       .long   0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208
+       .long   0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2
+___
+$code.=<<___ if ($SZ==8);
+       .quad   0x428a2f98d728ae22,0x7137449123ef65cd
+       .quad   0xb5c0fbcfec4d3b2f,0xe9b5dba58189dbbc
+       .quad   0x3956c25bf348b538,0x59f111f1b605d019
+       .quad   0x923f82a4af194f9b,0xab1c5ed5da6d8118
+       .quad   0xd807aa98a3030242,0x12835b0145706fbe
+       .quad   0x243185be4ee4b28c,0x550c7dc3d5ffb4e2
+       .quad   0x72be5d74f27b896f,0x80deb1fe3b1696b1
+       .quad   0x9bdc06a725c71235,0xc19bf174cf692694
+       .quad   0xe49b69c19ef14ad2,0xefbe4786384f25e3
+       .quad   0x0fc19dc68b8cd5b5,0x240ca1cc77ac9c65
+       .quad   0x2de92c6f592b0275,0x4a7484aa6ea6e483
+       .quad   0x5cb0a9dcbd41fbd4,0x76f988da831153b5
+       .quad   0x983e5152ee66dfab,0xa831c66d2db43210
+       .quad   0xb00327c898fb213f,0xbf597fc7beef0ee4
+       .quad   0xc6e00bf33da88fc2,0xd5a79147930aa725
+       .quad   0x06ca6351e003826f,0x142929670a0e6e70
+       .quad   0x27b70a8546d22ffc,0x2e1b21385c26c926
+       .quad   0x4d2c6dfc5ac42aed,0x53380d139d95b3df
+       .quad   0x650a73548baf63de,0x766a0abb3c77b2a8
+       .quad   0x81c2c92e47edaee6,0x92722c851482353b
+       .quad   0xa2bfe8a14cf10364,0xa81a664bbc423001
+       .quad   0xc24b8b70d0f89791,0xc76c51a30654be30
+       .quad   0xd192e819d6ef5218,0xd69906245565a910
+       .quad   0xf40e35855771202a,0x106aa07032bbd1b8
+       .quad   0x19a4c116b8d2d0c8,0x1e376c085141ab53
+       .quad   0x2748774cdf8eeb99,0x34b0bcb5e19b48a8
+       .quad   0x391c0cb3c5c95a63,0x4ed8aa4ae3418acb
+       .quad   0x5b9cca4f7763e373,0x682e6ff3d6b2b8a3
+       .quad   0x748f82ee5defb2fc,0x78a5636f43172f60
+       .quad   0x84c87814a1f0ab72,0x8cc702081a6439ec
+       .quad   0x90befffa23631e28,0xa4506cebde82bde9
+       .quad   0xbef9a3f7b2c67915,0xc67178f2e372532b
+       .quad   0xca273eceea26619c,0xd186b8c721c0c207
+       .quad   0xeada7dd6cde0eb1e,0xf57d4f7fee6ed178
+       .quad   0x06f067aa72176fba,0x0a637dc5a2c898a6
+       .quad   0x113f9804bef90dae,0x1b710b35131c471b
+       .quad   0x28db77f523047d84,0x32caab7b40c72493
+       .quad   0x3c9ebe0a15c9bebc,0x431d67c49c100d4c
+       .quad   0x4cc5d4becb3e42b6,0x597f299cfc657e2a
+       .quad   0x5fcb6fab3ad6faec,0x6c44198c4a475817
+___
+$code.=<<___;
+.size  $Table,.-$Table
+.globl $Func
+.type  $Func,\@function
+$Func:
+___
+$code.=<<___ if ($kimdfunc);
+       larl    %r1,OPENSSL_s390xcap_P
+       lg      %r0,0(%r1)
+       tmhl    %r0,0x4000      # check for message-security assist
+       jz      .Lsoftware
+       lghi    %r0,0
+       la      %r1,16($sp)
+       .long   0xb93e0002      # kimd %r0,%r2
+       lg      %r0,16($sp)
+       tmhh    %r0,`0x8000>>$kimdfunc`
+       jz      .Lsoftware
+       lghi    %r0,$kimdfunc
+       lgr     %r1,$ctx
+       lgr     %r2,$inp
+       sllg    %r3,$len,`log(16*$SZ)/log(2)`
+       .long   0xb93e0002      # kimd %r0,%r2
+       brc     1,.-4           # pay attention to "partial completion"
+       br      %r14
+.align 16
+.Lsoftware:
+___
+$code.=<<___;
+       sllg    $len,$len,`log(16*$SZ)/log(2)`
+       lghi    %r1,-$frame
+       agr     $len,$inp
+       stmg    $ctx,%r15,16($sp)
+       lgr     %r0,$sp
+       la      $sp,0(%r1,$sp)
+       stg     %r0,0($sp)
+
+       larl    $tbl,$Table
+       $LD     $A,`0*$SZ`($ctx)
+       $LD     $B,`1*$SZ`($ctx)
+       $LD     $C,`2*$SZ`($ctx)
+       $LD     $D,`3*$SZ`($ctx)
+       $LD     $E,`4*$SZ`($ctx)
+       $LD     $F,`5*$SZ`($ctx)
+       $LD     $G,`6*$SZ`($ctx)
+       $LD     $H,`7*$SZ`($ctx)
+
+.Lloop:
+       lghi    $len,0
+___
+for ($i=0;$i<16;$i++)  { &BODY_00_15($i,@V); unshift(@V,pop(@V)); }
+$code.=".Lrounds_16_xx:\n";
+for (;$i<32;$i++)      { &BODY_16_XX($i,@V); unshift(@V,pop(@V)); }
+$code.=<<___;
+       aghi    $len,`16*$SZ`
+       lghi    $t0,`($rounds-16)*$SZ`
+       clgr    $len,$t0
+       jne     .Lrounds_16_xx
+
+       lg      $ctx,`$frame+16`($sp)
+       la      $inp,`16*$SZ`($inp)
+       $ADD    $A,`0*$SZ`($ctx)
+       $ADD    $B,`1*$SZ`($ctx)
+       $ADD    $C,`2*$SZ`($ctx)
+       $ADD    $D,`3*$SZ`($ctx)
+       $ADD    $E,`4*$SZ`($ctx)
+       $ADD    $F,`5*$SZ`($ctx)
+       $ADD    $G,`6*$SZ`($ctx)
+       $ADD    $H,`7*$SZ`($ctx)
+       $ST     $A,`0*$SZ`($ctx)
+       $ST     $B,`1*$SZ`($ctx)
+       $ST     $C,`2*$SZ`($ctx)
+       $ST     $D,`3*$SZ`($ctx)
+       $ST     $E,`4*$SZ`($ctx)
+       $ST     $F,`5*$SZ`($ctx)
+       $ST     $G,`6*$SZ`($ctx)
+       $ST     $H,`7*$SZ`($ctx)
+       clg     $inp,`$frame+32`($sp)
+       jne     .Lloop
+
+       lmg     %r6,%r15,`$frame+48`($sp)       
+       br      %r14
+.size  $Func,.-$Func
+.string        "SHA${label} block transform for s390x, CRYPTOGAMS by <appro\@openssl.org>"
+.comm  OPENSSL_s390xcap_P,8,8
+___
+
+$code =~ s/\`([^\`]*)\`/eval $1/gem;
+# unlike 32-bit shift 64-bit one takes three arguments
+$code =~ s/(srlg\s+)(%r[0-9]+),/$1$2,$2,/gm;
+
+print $code;
+close STDOUT;
diff --git a/deps/openssl/openssl/crypto/sha/asm/sha512-sparcv9.pl b/deps/openssl/openssl/crypto/sha/asm/sha512-sparcv9.pl
new file mode 100644 (file)
index 0000000..ec5d781
--- /dev/null
@@ -0,0 +1,594 @@
+#!/usr/bin/env perl
+
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+
+# SHA256 performance improvement over compiler generated code varies
+# from 40% for Sun C [32-bit build] to 70% for gcc [3.3, 64-bit
+# build]. Just like in SHA1 module I aim to ensure scalability on
+# UltraSPARC T1 by packing X[16] to 8 64-bit registers.
+
+# SHA512 on pre-T1 UltraSPARC.
+#
+# Performance is >75% better than 64-bit code generated by Sun C and
+# over 2x than 32-bit code. X[16] resides on stack, but access to it
+# is scheduled for L2 latency and staged through 32 least significant
+# bits of %l0-%l7. The latter is done to achieve 32-/64-bit ABI
+# duality. Nevetheless it's ~40% faster than SHA256, which is pretty
+# good [optimal coefficient is 50%].
+#
+# SHA512 on UltraSPARC T1.
+#
+# It's not any faster than 64-bit code generated by Sun C 5.8. This is
+# because 64-bit code generator has the advantage of using 64-bit
+# loads(*) to access X[16], which I consciously traded for 32-/64-bit
+# ABI duality [as per above]. But it surpasses 32-bit Sun C generated
+# code by 60%, not to mention that it doesn't suffer from severe decay
+# when running 4 times physical cores threads and that it leaves gcc
+# [3.4] behind by over 4x factor! If compared to SHA256, single thread
+# performance is only 10% better, but overall throughput for maximum
+# amount of threads for given CPU exceeds corresponding one of SHA256
+# by 30% [again, optimal coefficient is 50%].
+#
+# (*)  Unlike pre-T1 UltraSPARC loads on T1 are executed strictly
+#      in-order, i.e. load instruction has to complete prior next
+#      instruction in given thread is executed, even if the latter is
+#      not dependent on load result! This means that on T1 two 32-bit
+#      loads are always slower than one 64-bit load. Once again this
+#      is unlike pre-T1 UltraSPARC, where, if scheduled appropriately,
+#      2x32-bit loads can be as fast as 1x64-bit ones.
+
+$bits=32;
+for (@ARGV)    { $bits=64 if (/\-m64/ || /\-xarch\=v9/); }
+if ($bits==64) { $bias=2047; $frame=192; }
+else           { $bias=0;    $frame=112; }
+
+$output=shift;
+open STDOUT,">$output";
+
+if ($output =~ /512/) {
+       $label="512";
+       $SZ=8;
+       $LD="ldx";              # load from memory
+       $ST="stx";              # store to memory
+       $SLL="sllx";            # shift left logical
+       $SRL="srlx";            # shift right logical
+       @Sigma0=(28,34,39);
+       @Sigma1=(14,18,41);
+       @sigma0=( 7, 1, 8);     # right shift first
+       @sigma1=( 6,19,61);     # right shift first
+       $lastK=0x817;
+       $rounds=80;
+       $align=4;
+
+       $locals=16*$SZ;         # X[16]
+
+       $A="%o0";
+       $B="%o1";
+       $C="%o2";
+       $D="%o3";
+       $E="%o4";
+       $F="%o5";
+       $G="%g1";
+       $H="%o7";
+       @V=($A,$B,$C,$D,$E,$F,$G,$H);
+} else {
+       $label="256";
+       $SZ=4;
+       $LD="ld";               # load from memory
+       $ST="st";               # store to memory
+       $SLL="sll";             # shift left logical
+       $SRL="srl";             # shift right logical
+       @Sigma0=( 2,13,22);
+       @Sigma1=( 6,11,25);
+       @sigma0=( 3, 7,18);     # right shift first
+       @sigma1=(10,17,19);     # right shift first
+       $lastK=0x8f2;
+       $rounds=64;
+       $align=8;
+
+       $locals=0;              # X[16] is register resident
+       @X=("%o0","%o1","%o2","%o3","%o4","%o5","%g1","%o7");
+       
+       $A="%l0";
+       $B="%l1";
+       $C="%l2";
+       $D="%l3";
+       $E="%l4";
+       $F="%l5";
+       $G="%l6";
+       $H="%l7";
+       @V=($A,$B,$C,$D,$E,$F,$G,$H);
+}
+$T1="%g2";
+$tmp0="%g3";
+$tmp1="%g4";
+$tmp2="%g5";
+
+$ctx="%i0";
+$inp="%i1";
+$len="%i2";
+$Ktbl="%i3";
+$tmp31="%i4";
+$tmp32="%i5";
+
+########### SHA256
+$Xload = sub {
+my ($i,$a,$b,$c,$d,$e,$f,$g,$h)=@_;
+
+    if ($i==0) {
+$code.=<<___;
+       ldx     [$inp+0],@X[0]
+       ldx     [$inp+16],@X[2]
+       ldx     [$inp+32],@X[4]
+       ldx     [$inp+48],@X[6]
+       ldx     [$inp+8],@X[1]
+       ldx     [$inp+24],@X[3]
+       subcc   %g0,$tmp31,$tmp32 ! should be 64-$tmp31, but -$tmp31 works too
+       ldx     [$inp+40],@X[5]
+       bz,pt   %icc,.Laligned
+       ldx     [$inp+56],@X[7]
+
+       sllx    @X[0],$tmp31,@X[0]
+       ldx     [$inp+64],$T1
+___
+for($j=0;$j<7;$j++)
+{   $code.=<<___;
+       srlx    @X[$j+1],$tmp32,$tmp1
+       sllx    @X[$j+1],$tmp31,@X[$j+1]
+       or      $tmp1,@X[$j],@X[$j]
+___
+}
+$code.=<<___;
+       srlx    $T1,$tmp32,$T1
+       or      $T1,@X[7],@X[7]
+.Laligned:
+___
+    }
+
+    if ($i&1) {
+       $code.="\tadd   @X[$i/2],$h,$T1\n";
+    } else {
+       $code.="\tsrlx  @X[$i/2],32,$T1\n\tadd  $h,$T1,$T1\n";
+    }
+} if ($SZ==4);
+
+########### SHA512
+$Xload = sub {
+my ($i,$a,$b,$c,$d,$e,$f,$g,$h)=@_;
+my @pair=("%l".eval(($i*2)%8),"%l".eval(($i*2)%8+1),"%l".eval((($i+1)*2)%8));
+
+$code.=<<___ if ($i==0);
+       ld      [$inp+0],%l0
+       ld      [$inp+4],%l1
+       ld      [$inp+8],%l2
+       ld      [$inp+12],%l3
+       ld      [$inp+16],%l4
+       ld      [$inp+20],%l5
+       ld      [$inp+24],%l6
+       ld      [$inp+28],%l7
+___
+$code.=<<___ if ($i<15);
+       sllx    @pair[1],$tmp31,$tmp2   ! Xload($i)
+       add     $tmp31,32,$tmp0
+       sllx    @pair[0],$tmp0,$tmp1
+       `"ld    [$inp+".eval(32+0+$i*8)."],@pair[0]"    if ($i<12)`
+       srlx    @pair[2],$tmp32,@pair[1]
+       or      $tmp1,$tmp2,$tmp2
+       or      @pair[1],$tmp2,$tmp2
+       `"ld    [$inp+".eval(32+4+$i*8)."],@pair[1]"    if ($i<12)`
+       add     $h,$tmp2,$T1
+       $ST     $tmp2,[%sp+`$bias+$frame+$i*$SZ`]
+___
+$code.=<<___ if ($i==12);
+       brnz,a  $tmp31,.+8
+       ld      [$inp+128],%l0
+___
+$code.=<<___ if ($i==15);
+       ld      [%sp+`$bias+$frame+(($i+1+1)%16)*$SZ+0`],%l2
+       sllx    @pair[1],$tmp31,$tmp2   ! Xload($i)
+       add     $tmp31,32,$tmp0
+       ld      [%sp+`$bias+$frame+(($i+1+1)%16)*$SZ+4`],%l3
+       sllx    @pair[0],$tmp0,$tmp1
+       ld      [%sp+`$bias+$frame+(($i+1+9)%16)*$SZ+0`],%l4
+       srlx    @pair[2],$tmp32,@pair[1]
+       or      $tmp1,$tmp2,$tmp2
+       ld      [%sp+`$bias+$frame+(($i+1+9)%16)*$SZ+4`],%l5
+       or      @pair[1],$tmp2,$tmp2
+       ld      [%sp+`$bias+$frame+(($i+1+14)%16)*$SZ+0`],%l6
+       add     $h,$tmp2,$T1
+       $ST     $tmp2,[%sp+`$bias+$frame+$i*$SZ`]
+       ld      [%sp+`$bias+$frame+(($i+1+14)%16)*$SZ+4`],%l7
+       ld      [%sp+`$bias+$frame+(($i+1+0)%16)*$SZ+0`],%l0
+       ld      [%sp+`$bias+$frame+(($i+1+0)%16)*$SZ+4`],%l1
+___
+} if ($SZ==8);
+
+########### common
+sub BODY_00_15 {
+my ($i,$a,$b,$c,$d,$e,$f,$g,$h)=@_;
+
+    if ($i<16) {
+       &$Xload(@_);
+    } else {
+       $code.="\tadd   $h,$T1,$T1\n";
+    }
+
+$code.=<<___;
+       $SRL    $e,@Sigma1[0],$h        !! $i
+       xor     $f,$g,$tmp2
+       $SLL    $e,`$SZ*8-@Sigma1[2]`,$tmp1
+       and     $e,$tmp2,$tmp2
+       $SRL    $e,@Sigma1[1],$tmp0
+       xor     $tmp1,$h,$h
+       $SLL    $e,`$SZ*8-@Sigma1[1]`,$tmp1
+       xor     $tmp0,$h,$h
+       $SRL    $e,@Sigma1[2],$tmp0
+       xor     $tmp1,$h,$h
+       $SLL    $e,`$SZ*8-@Sigma1[0]`,$tmp1
+       xor     $tmp0,$h,$h
+       xor     $g,$tmp2,$tmp2          ! Ch(e,f,g)
+       xor     $tmp1,$h,$tmp0          ! Sigma1(e)
+
+       $SRL    $a,@Sigma0[0],$h
+       add     $tmp2,$T1,$T1
+       $LD     [$Ktbl+`$i*$SZ`],$tmp2  ! K[$i]
+       $SLL    $a,`$SZ*8-@Sigma0[2]`,$tmp1
+       add     $tmp0,$T1,$T1
+       $SRL    $a,@Sigma0[1],$tmp0
+       xor     $tmp1,$h,$h
+       $SLL    $a,`$SZ*8-@Sigma0[1]`,$tmp1
+       xor     $tmp0,$h,$h
+       $SRL    $a,@Sigma0[2],$tmp0
+       xor     $tmp1,$h,$h     
+       $SLL    $a,`$SZ*8-@Sigma0[0]`,$tmp1
+       xor     $tmp0,$h,$h
+       xor     $tmp1,$h,$h             ! Sigma0(a)
+
+       or      $a,$b,$tmp0
+       and     $a,$b,$tmp1
+       and     $c,$tmp0,$tmp0
+       or      $tmp0,$tmp1,$tmp1       ! Maj(a,b,c)
+       add     $tmp2,$T1,$T1           ! +=K[$i]
+       add     $tmp1,$h,$h
+
+       add     $T1,$d,$d
+       add     $T1,$h,$h
+___
+}
+
+########### SHA256
+$BODY_16_XX = sub {
+my $i=@_[0];
+my $xi;
+
+    if ($i&1) {
+       $xi=$tmp32;
+       $code.="\tsrlx  @X[(($i+1)/2)%8],32,$xi\n";
+    } else {
+       $xi=@X[(($i+1)/2)%8];
+    }
+$code.=<<___;
+       srl     $xi,@sigma0[0],$T1              !! Xupdate($i)
+       sll     $xi,`32-@sigma0[2]`,$tmp1
+       srl     $xi,@sigma0[1],$tmp0
+       xor     $tmp1,$T1,$T1
+       sll     $tmp1,`@sigma0[2]-@sigma0[1]`,$tmp1
+       xor     $tmp0,$T1,$T1
+       srl     $xi,@sigma0[2],$tmp0
+       xor     $tmp1,$T1,$T1
+___
+    if ($i&1) {
+       $xi=@X[(($i+14)/2)%8];
+    } else {
+       $xi=$tmp32;
+       $code.="\tsrlx  @X[(($i+14)/2)%8],32,$xi\n";
+    }
+$code.=<<___;
+       srl     $xi,@sigma1[0],$tmp2
+       xor     $tmp0,$T1,$T1                   ! T1=sigma0(X[i+1])
+       sll     $xi,`32-@sigma1[2]`,$tmp1
+       srl     $xi,@sigma1[1],$tmp0
+       xor     $tmp1,$tmp2,$tmp2
+       sll     $tmp1,`@sigma1[2]-@sigma1[1]`,$tmp1
+       xor     $tmp0,$tmp2,$tmp2
+       srl     $xi,@sigma1[2],$tmp0
+       xor     $tmp1,$tmp2,$tmp2
+___
+    if ($i&1) {
+       $xi=@X[($i/2)%8];
+$code.=<<___;
+       srlx    @X[(($i+9)/2)%8],32,$tmp1       ! X[i+9]
+       xor     $tmp0,$tmp2,$tmp2               ! sigma1(X[i+14])
+       srl     @X[($i/2)%8],0,$tmp0
+       add     $xi,$T1,$T1                     ! +=X[i]
+       xor     $tmp0,@X[($i/2)%8],@X[($i/2)%8]
+       add     $tmp2,$T1,$T1
+       add     $tmp1,$T1,$T1
+
+       srl     $T1,0,$T1
+       or      $T1,@X[($i/2)%8],@X[($i/2)%8]
+___
+    } else {
+       $xi=@X[(($i+9)/2)%8];
+$code.=<<___;
+       srlx    @X[($i/2)%8],32,$tmp1           ! X[i]
+       xor     $tmp0,$tmp2,$tmp2               ! sigma1(X[i+14])
+       srl     @X[($i/2)%8],0,@X[($i/2)%8]
+       add     $xi,$T1,$T1                     ! +=X[i+9]
+       add     $tmp2,$T1,$T1
+       add     $tmp1,$T1,$T1
+
+       sllx    $T1,32,$tmp0
+       or      $tmp0,@X[($i/2)%8],@X[($i/2)%8]
+___
+    }
+    &BODY_00_15(@_);
+} if ($SZ==4);
+
+########### SHA512
+$BODY_16_XX = sub {
+my $i=@_[0];
+my @pair=("%l".eval(($i*2)%8),"%l".eval(($i*2)%8+1));
+
+$code.=<<___;
+       sllx    %l2,32,$tmp0            !! Xupdate($i)
+       or      %l3,$tmp0,$tmp0
+
+       srlx    $tmp0,@sigma0[0],$T1
+       ld      [%sp+`$bias+$frame+(($i+1+1)%16)*$SZ+0`],%l2
+       sllx    $tmp0,`64-@sigma0[2]`,$tmp1
+       ld      [%sp+`$bias+$frame+(($i+1+1)%16)*$SZ+4`],%l3
+       srlx    $tmp0,@sigma0[1],$tmp0
+       xor     $tmp1,$T1,$T1
+       sllx    $tmp1,`@sigma0[2]-@sigma0[1]`,$tmp1
+       xor     $tmp0,$T1,$T1
+       srlx    $tmp0,`@sigma0[2]-@sigma0[1]`,$tmp0
+       xor     $tmp1,$T1,$T1
+       sllx    %l6,32,$tmp2
+       xor     $tmp0,$T1,$T1           ! sigma0(X[$i+1])
+       or      %l7,$tmp2,$tmp2
+
+       srlx    $tmp2,@sigma1[0],$tmp1
+       ld      [%sp+`$bias+$frame+(($i+1+14)%16)*$SZ+0`],%l6
+       sllx    $tmp2,`64-@sigma1[2]`,$tmp0
+       ld      [%sp+`$bias+$frame+(($i+1+14)%16)*$SZ+4`],%l7
+       srlx    $tmp2,@sigma1[1],$tmp2
+       xor     $tmp0,$tmp1,$tmp1
+       sllx    $tmp0,`@sigma1[2]-@sigma1[1]`,$tmp0
+       xor     $tmp2,$tmp1,$tmp1
+       srlx    $tmp2,`@sigma1[2]-@sigma1[1]`,$tmp2
+       xor     $tmp0,$tmp1,$tmp1
+       sllx    %l4,32,$tmp0
+       xor     $tmp2,$tmp1,$tmp1       ! sigma1(X[$i+14])
+       ld      [%sp+`$bias+$frame+(($i+1+9)%16)*$SZ+0`],%l4
+       or      %l5,$tmp0,$tmp0
+       ld      [%sp+`$bias+$frame+(($i+1+9)%16)*$SZ+4`],%l5
+
+       sllx    %l0,32,$tmp2
+       add     $tmp1,$T1,$T1
+       ld      [%sp+`$bias+$frame+(($i+1+0)%16)*$SZ+0`],%l0
+       or      %l1,$tmp2,$tmp2
+       add     $tmp0,$T1,$T1           ! +=X[$i+9]
+       ld      [%sp+`$bias+$frame+(($i+1+0)%16)*$SZ+4`],%l1
+       add     $tmp2,$T1,$T1           ! +=X[$i]
+       $ST     $T1,[%sp+`$bias+$frame+($i%16)*$SZ`]
+___
+    &BODY_00_15(@_);
+} if ($SZ==8);
+
+$code.=<<___ if ($bits==64);
+.register      %g2,#scratch
+.register      %g3,#scratch
+___
+$code.=<<___;
+.section       ".text",#alloc,#execinstr
+
+.align 64
+K${label}:
+.type  K${label},#object
+___
+if ($SZ==4) {
+$code.=<<___;
+       .long   0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5
+       .long   0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5
+       .long   0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3
+       .long   0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174
+       .long   0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc
+       .long   0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da
+       .long   0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7
+       .long   0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967
+       .long   0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13
+       .long   0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85
+       .long   0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3
+       .long   0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070
+       .long   0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5
+       .long   0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3
+       .long   0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208
+       .long   0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
+___
+} else {
+$code.=<<___;
+       .long   0x428a2f98,0xd728ae22, 0x71374491,0x23ef65cd
+       .long   0xb5c0fbcf,0xec4d3b2f, 0xe9b5dba5,0x8189dbbc
+       .long   0x3956c25b,0xf348b538, 0x59f111f1,0xb605d019
+       .long   0x923f82a4,0xaf194f9b, 0xab1c5ed5,0xda6d8118
+       .long   0xd807aa98,0xa3030242, 0x12835b01,0x45706fbe
+       .long   0x243185be,0x4ee4b28c, 0x550c7dc3,0xd5ffb4e2
+       .long   0x72be5d74,0xf27b896f, 0x80deb1fe,0x3b1696b1
+       .long   0x9bdc06a7,0x25c71235, 0xc19bf174,0xcf692694
+       .long   0xe49b69c1,0x9ef14ad2, 0xefbe4786,0x384f25e3
+       .long   0x0fc19dc6,0x8b8cd5b5, 0x240ca1cc,0x77ac9c65
+       .long   0x2de92c6f,0x592b0275, 0x4a7484aa,0x6ea6e483
+       .long   0x5cb0a9dc,0xbd41fbd4, 0x76f988da,0x831153b5
+       .long   0x983e5152,0xee66dfab, 0xa831c66d,0x2db43210
+       .long   0xb00327c8,0x98fb213f, 0xbf597fc7,0xbeef0ee4
+       .long   0xc6e00bf3,0x3da88fc2, 0xd5a79147,0x930aa725
+       .long   0x06ca6351,0xe003826f, 0x14292967,0x0a0e6e70
+       .long   0x27b70a85,0x46d22ffc, 0x2e1b2138,0x5c26c926
+       .long   0x4d2c6dfc,0x5ac42aed, 0x53380d13,0x9d95b3df
+       .long   0x650a7354,0x8baf63de, 0x766a0abb,0x3c77b2a8
+       .long   0x81c2c92e,0x47edaee6, 0x92722c85,0x1482353b
+       .long   0xa2bfe8a1,0x4cf10364, 0xa81a664b,0xbc423001
+       .long   0xc24b8b70,0xd0f89791, 0xc76c51a3,0x0654be30
+       .long   0xd192e819,0xd6ef5218, 0xd6990624,0x5565a910
+       .long   0xf40e3585,0x5771202a, 0x106aa070,0x32bbd1b8
+       .long   0x19a4c116,0xb8d2d0c8, 0x1e376c08,0x5141ab53
+       .long   0x2748774c,0xdf8eeb99, 0x34b0bcb5,0xe19b48a8
+       .long   0x391c0cb3,0xc5c95a63, 0x4ed8aa4a,0xe3418acb
+       .long   0x5b9cca4f,0x7763e373, 0x682e6ff3,0xd6b2b8a3
+       .long   0x748f82ee,0x5defb2fc, 0x78a5636f,0x43172f60
+       .long   0x84c87814,0xa1f0ab72, 0x8cc70208,0x1a6439ec
+       .long   0x90befffa,0x23631e28, 0xa4506ceb,0xde82bde9
+       .long   0xbef9a3f7,0xb2c67915, 0xc67178f2,0xe372532b
+       .long   0xca273ece,0xea26619c, 0xd186b8c7,0x21c0c207
+       .long   0xeada7dd6,0xcde0eb1e, 0xf57d4f7f,0xee6ed178
+       .long   0x06f067aa,0x72176fba, 0x0a637dc5,0xa2c898a6
+       .long   0x113f9804,0xbef90dae, 0x1b710b35,0x131c471b
+       .long   0x28db77f5,0x23047d84, 0x32caab7b,0x40c72493
+       .long   0x3c9ebe0a,0x15c9bebc, 0x431d67c4,0x9c100d4c
+       .long   0x4cc5d4be,0xcb3e42b6, 0x597f299c,0xfc657e2a
+       .long   0x5fcb6fab,0x3ad6faec, 0x6c44198c,0x4a475817
+___
+}
+$code.=<<___;
+.size  K${label},.-K${label}
+.globl sha${label}_block_data_order
+sha${label}_block_data_order:
+       save    %sp,`-$frame-$locals`,%sp
+       and     $inp,`$align-1`,$tmp31
+       sllx    $len,`log(16*$SZ)/log(2)`,$len
+       andn    $inp,`$align-1`,$inp
+       sll     $tmp31,3,$tmp31
+       add     $inp,$len,$len
+___
+$code.=<<___ if ($SZ==8); # SHA512
+       mov     32,$tmp32
+       sub     $tmp32,$tmp31,$tmp32
+___
+$code.=<<___;
+.Lpic: call    .+8
+       add     %o7,K${label}-.Lpic,$Ktbl
+
+       $LD     [$ctx+`0*$SZ`],$A
+       $LD     [$ctx+`1*$SZ`],$B
+       $LD     [$ctx+`2*$SZ`],$C
+       $LD     [$ctx+`3*$SZ`],$D
+       $LD     [$ctx+`4*$SZ`],$E
+       $LD     [$ctx+`5*$SZ`],$F
+       $LD     [$ctx+`6*$SZ`],$G
+       $LD     [$ctx+`7*$SZ`],$H
+
+.Lloop:
+___
+for ($i=0;$i<16;$i++)  { &BODY_00_15($i,@V); unshift(@V,pop(@V)); }
+$code.=".L16_xx:\n";
+for (;$i<32;$i++)      { &$BODY_16_XX($i,@V); unshift(@V,pop(@V)); }
+$code.=<<___;
+       and     $tmp2,0xfff,$tmp2
+       cmp     $tmp2,$lastK
+       bne     .L16_xx
+       add     $Ktbl,`16*$SZ`,$Ktbl    ! Ktbl+=16
+
+___
+$code.=<<___ if ($SZ==4); # SHA256
+       $LD     [$ctx+`0*$SZ`],@X[0]
+       $LD     [$ctx+`1*$SZ`],@X[1]
+       $LD     [$ctx+`2*$SZ`],@X[2]
+       $LD     [$ctx+`3*$SZ`],@X[3]
+       $LD     [$ctx+`4*$SZ`],@X[4]
+       $LD     [$ctx+`5*$SZ`],@X[5]
+       $LD     [$ctx+`6*$SZ`],@X[6]
+       $LD     [$ctx+`7*$SZ`],@X[7]
+
+       add     $A,@X[0],$A
+       $ST     $A,[$ctx+`0*$SZ`]
+       add     $B,@X[1],$B
+       $ST     $B,[$ctx+`1*$SZ`]
+       add     $C,@X[2],$C
+       $ST     $C,[$ctx+`2*$SZ`]
+       add     $D,@X[3],$D
+       $ST     $D,[$ctx+`3*$SZ`]
+       add     $E,@X[4],$E
+       $ST     $E,[$ctx+`4*$SZ`]
+       add     $F,@X[5],$F
+       $ST     $F,[$ctx+`5*$SZ`]
+       add     $G,@X[6],$G
+       $ST     $G,[$ctx+`6*$SZ`]
+       add     $H,@X[7],$H
+       $ST     $H,[$ctx+`7*$SZ`]
+___
+$code.=<<___ if ($SZ==8); # SHA512
+       ld      [$ctx+`0*$SZ+0`],%l0
+       ld      [$ctx+`0*$SZ+4`],%l1
+       ld      [$ctx+`1*$SZ+0`],%l2
+       ld      [$ctx+`1*$SZ+4`],%l3
+       ld      [$ctx+`2*$SZ+0`],%l4
+       ld      [$ctx+`2*$SZ+4`],%l5
+       ld      [$ctx+`3*$SZ+0`],%l6
+
+       sllx    %l0,32,$tmp0
+       ld      [$ctx+`3*$SZ+4`],%l7
+       sllx    %l2,32,$tmp1
+       or      %l1,$tmp0,$tmp0
+       or      %l3,$tmp1,$tmp1
+       add     $tmp0,$A,$A
+       add     $tmp1,$B,$B
+       $ST     $A,[$ctx+`0*$SZ`]
+       sllx    %l4,32,$tmp2
+       $ST     $B,[$ctx+`1*$SZ`]
+       sllx    %l6,32,$T1
+       or      %l5,$tmp2,$tmp2
+       or      %l7,$T1,$T1
+       add     $tmp2,$C,$C
+       $ST     $C,[$ctx+`2*$SZ`]
+       add     $T1,$D,$D
+       $ST     $D,[$ctx+`3*$SZ`]
+
+       ld      [$ctx+`4*$SZ+0`],%l0
+       ld      [$ctx+`4*$SZ+4`],%l1
+       ld      [$ctx+`5*$SZ+0`],%l2
+       ld      [$ctx+`5*$SZ+4`],%l3
+       ld      [$ctx+`6*$SZ+0`],%l4
+       ld      [$ctx+`6*$SZ+4`],%l5
+       ld      [$ctx+`7*$SZ+0`],%l6
+
+       sllx    %l0,32,$tmp0
+       ld      [$ctx+`7*$SZ+4`],%l7
+       sllx    %l2,32,$tmp1
+       or      %l1,$tmp0,$tmp0
+       or      %l3,$tmp1,$tmp1
+       add     $tmp0,$E,$E
+       add     $tmp1,$F,$F
+       $ST     $E,[$ctx+`4*$SZ`]
+       sllx    %l4,32,$tmp2
+       $ST     $F,[$ctx+`5*$SZ`]
+       sllx    %l6,32,$T1
+       or      %l5,$tmp2,$tmp2
+       or      %l7,$T1,$T1
+       add     $tmp2,$G,$G
+       $ST     $G,[$ctx+`6*$SZ`]
+       add     $T1,$H,$H
+       $ST     $H,[$ctx+`7*$SZ`]
+___
+$code.=<<___;
+       add     $inp,`16*$SZ`,$inp              ! advance inp
+       cmp     $inp,$len
+       bne     `$bits==64?"%xcc":"%icc"`,.Lloop
+       sub     $Ktbl,`($rounds-16)*$SZ`,$Ktbl  ! rewind Ktbl
+
+       ret
+       restore
+.type  sha${label}_block_data_order,#function
+.size  sha${label}_block_data_order,(.-sha${label}_block_data_order)
+.asciz "SHA${label} block transform for SPARCv9, CRYPTOGAMS by <appro\@openssl.org>"
+.align 4
+___
+
+$code =~ s/\`([^\`]*)\`/eval $1/gem;
+print $code;
+close STDOUT;
diff --git a/deps/openssl/openssl/crypto/sha/asm/sha512-sse2.pl b/deps/openssl/openssl/crypto/sha/asm/sha512-sse2.pl
deleted file mode 100644 (file)
index 10902bf..0000000
+++ /dev/null
@@ -1,404 +0,0 @@
-#!/usr/bin/env perl
-#
-# ====================================================================
-# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
-# project. Rights for redistribution and usage in source and binary
-# forms are granted according to the OpenSSL license.
-# ====================================================================
-#
-# SHA512_Transform_SSE2.
-#
-# As the name suggests, this is an IA-32 SSE2 implementation of
-# SHA512_Transform. Motivating factor for the undertaken effort was that
-# SHA512 was observed to *consistently* perform *significantly* poorer
-# than SHA256 [2x and slower is common] on 32-bit platforms. On 64-bit
-# platforms on the other hand SHA512 tend to outperform SHA256 [~50%
-# seem to be common improvement factor]. All this is perfectly natural,
-# as SHA512 is a 64-bit algorithm. But isn't IA-32 SSE2 essentially
-# a 64-bit instruction set? Is it rich enough to implement SHA512?
-# If answer was "no," then you wouldn't have been reading this...
-#
-# Throughput performance in MBps (larger is better):
-#
-#              2.4GHz P4       1.4GHz AMD32    1.4GHz AMD64(*)
-# SHA256/gcc(*)        54              43              59
-# SHA512/gcc   17              23              92
-# SHA512/sse2  61(**)          57(**)
-# SHA512/icc   26              28
-# SHA256/icc(*)        65              54
-#
-# (*)  AMD64 and SHA256 numbers are presented mostly for amusement or
-#      reference purposes.
-# (**) I.e. it gives ~2-3x speed-up if compared with compiler generated
-#      code. One can argue that hand-coded *non*-SSE2 implementation
-#      would perform better than compiler generated one as well, and
-#      that comparison is therefore not exactly fair. Well, as SHA512
-#      puts enormous pressure on IA-32 GP register bank, I reckon that
-#      hand-coded version wouldn't perform significantly better than
-#      one compiled with icc, ~20% perhaps... So that this code would
-#      still outperform it with distinguishing marginal. But feel free
-#      to prove me wrong:-)
-#                                              <appro@fy.chalmers.se>
-push(@INC,"perlasm","../../perlasm");
-require "x86asm.pl";
-
-&asm_init($ARGV[0],"sha512-sse2.pl",$ARGV[$#ARGV] eq "386");
-
-$K512="esi";   # K512[80] table, found at the end...
-#$W512="esp";  # $W512 is not just W512[16]: it comprises *two* copies
-               # of W512[16] and a copy of A-H variables...
-$W512_SZ=8*(16+16+8);  # see above...
-#$Kidx="ebx";  # index in K512 table, advances from 0 to 80...
-$Widx="edx";   # index in W512, wraps around at 16...
-$data="edi";   # 16 qwords of input data...
-$A="mm0";      # B-D and
-$E="mm1";      # F-H are allocated dynamically...
-$Aoff=256+0;   # A-H offsets relative to $W512...
-$Boff=256+8;
-$Coff=256+16;
-$Doff=256+24;
-$Eoff=256+32;
-$Foff=256+40;
-$Goff=256+48;
-$Hoff=256+56;
-
-sub SHA2_ROUND()
-{ local ($kidx,$widx)=@_;
-
-       # One can argue that one could reorder instructions for better
-       # performance. Well, I tried and it doesn't seem to make any
-       # noticeable difference. Modern out-of-order execution cores
-       # reorder instructions to their liking in either case and they
-       # apparently do decent job. So we can keep the code more
-       # readable/regular/comprehensible:-)
-
-       # I adhere to 64-bit %mmX registers in order to avoid/not care
-       # about #GP exceptions on misaligned 128-bit access, most
-       # notably in paddq with memory operand. Not to mention that
-       # SSE2 intructions operating on %mmX can be scheduled every
-       # cycle [and not every second one if operating on %xmmN].
-
-       &movq   ("mm4",&QWP($Foff,$W512));      # load f
-       &movq   ("mm5",&QWP($Goff,$W512));      # load g
-       &movq   ("mm6",&QWP($Hoff,$W512));      # load h
-
-       &movq   ("mm2",$E);                     # %mm2 is sliding right
-       &movq   ("mm3",$E);                     # %mm3 is sliding left
-       &psrlq  ("mm2",14);
-       &psllq  ("mm3",23);
-       &movq   ("mm7","mm2");                  # %mm7 is T1
-       &pxor   ("mm7","mm3");
-       &psrlq  ("mm2",4);
-       &psllq  ("mm3",23);
-       &pxor   ("mm7","mm2");
-       &pxor   ("mm7","mm3");
-       &psrlq  ("mm2",23);
-       &psllq  ("mm3",4);
-       &pxor   ("mm7","mm2");
-       &pxor   ("mm7","mm3");                  # T1=Sigma1_512(e)
-
-       &movq   (&QWP($Foff,$W512),$E);         # f = e
-       &movq   (&QWP($Goff,$W512),"mm4");      # g = f
-       &movq   (&QWP($Hoff,$W512),"mm5");      # h = g
-
-       &pxor   ("mm4","mm5");                  # f^=g
-       &pand   ("mm4",$E);                     # f&=e
-       &pxor   ("mm4","mm5");                  # f^=g
-       &paddq  ("mm7","mm4");                  # T1+=Ch(e,f,g)
-
-       &movq   ("mm2",&QWP($Boff,$W512));      # load b
-       &movq   ("mm3",&QWP($Coff,$W512));      # load c
-       &movq   ($E,&QWP($Doff,$W512));         # e = d
-
-       &paddq  ("mm7","mm6");                  # T1+=h
-       &paddq  ("mm7",&QWP(0,$K512,$kidx,8));  # T1+=K512[i]
-       &paddq  ("mm7",&QWP(0,$W512,$widx,8));  # T1+=W512[i]
-       &paddq  ($E,"mm7");                     # e += T1
-
-       &movq   ("mm4",$A);                     # %mm4 is sliding right
-       &movq   ("mm5",$A);                     # %mm5 is sliding left
-       &psrlq  ("mm4",28);
-       &psllq  ("mm5",25);
-       &movq   ("mm6","mm4");                  # %mm6 is T2
-       &pxor   ("mm6","mm5");
-       &psrlq  ("mm4",6);
-       &psllq  ("mm5",5);
-       &pxor   ("mm6","mm4");
-       &pxor   ("mm6","mm5");
-       &psrlq  ("mm4",5);
-       &psllq  ("mm5",6);
-       &pxor   ("mm6","mm4");
-       &pxor   ("mm6","mm5");                  # T2=Sigma0_512(a)
-
-       &movq   (&QWP($Boff,$W512),$A);         # b = a
-       &movq   (&QWP($Coff,$W512),"mm2");      # c = b
-       &movq   (&QWP($Doff,$W512),"mm3");      # d = c
-
-       &movq   ("mm4",$A);                     # %mm4=a
-       &por    ($A,"mm3");                     # a=a|c
-       &pand   ("mm4","mm3");                  # %mm4=a&c
-       &pand   ($A,"mm2");                     # a=(a|c)&b
-       &por    ("mm4",$A);                     # %mm4=(a&c)|((a|c)&b)
-       &paddq  ("mm6","mm4");                  # T2+=Maj(a,b,c)
-
-       &movq   ($A,"mm7");                     # a=T1
-       &paddq  ($A,"mm6");                     # a+=T2
-}
-
-$func="sha512_block_sse2";
-
-&function_begin_B($func);
-       if (0) {# Caller is expected to check if it's appropriate to
-               # call this routine. Below 3 lines are retained for
-               # debugging purposes...
-               &picmeup("eax","OPENSSL_ia32cap");
-               &bt     (&DWP(0,"eax"),26);
-               &jnc    ("SHA512_Transform");
-       }
-
-       &push   ("ebp");
-       &mov    ("ebp","esp");
-       &push   ("ebx");
-       &push   ("esi");
-       &push   ("edi");
-
-       &mov    ($Widx,&DWP(8,"ebp"));          # A-H state, 1st arg
-       &mov    ($data,&DWP(12,"ebp"));         # input data, 2nd arg
-       &call   (&label("pic_point"));          # make it PIC!
-&set_label("pic_point");
-       &blindpop($K512);
-       &lea    ($K512,&DWP(&label("K512")."-".&label("pic_point"),$K512));
-
-       $W512 = "esp";                  # start using %esp as W512
-       &sub    ($W512,$W512_SZ);
-       &and    ($W512,-16);            # ensure 128-bit alignment
-
-       # make private copy of A-H
-       #     v assume the worst and stick to unaligned load
-       &movdqu ("xmm0",&QWP(0,$Widx));
-       &movdqu ("xmm1",&QWP(16,$Widx));
-       &movdqu ("xmm2",&QWP(32,$Widx));
-       &movdqu ("xmm3",&QWP(48,$Widx));
-
-&align(8);
-&set_label("_chunk_loop");
-
-       &movdqa (&QWP($Aoff,$W512),"xmm0");     # a,b
-       &movdqa (&QWP($Coff,$W512),"xmm1");     # c,d
-       &movdqa (&QWP($Eoff,$W512),"xmm2");     # e,f
-       &movdqa (&QWP($Goff,$W512),"xmm3");     # g,h
-
-       &xor    ($Widx,$Widx);
-
-       &movdq2q($A,"xmm0");                    # load a
-       &movdq2q($E,"xmm2");                    # load e
-
-       # Why aren't loops unrolled? It makes sense to unroll if
-       # execution time for loop body is comparable with branch
-       # penalties and/or if whole data-set resides in register bank.
-       # Neither is case here... Well, it would be possible to
-       # eliminate few store operations, but it would hardly affect
-       # so to say stop-watch performance, as there is a lot of
-       # available memory slots to fill. It will only relieve some
-       # pressure off memory bus...
-
-       # flip input stream byte order...
-       &mov    ("eax",&DWP(0,$data,$Widx,8));
-       &mov    ("ebx",&DWP(4,$data,$Widx,8));
-       &bswap  ("eax");
-       &bswap  ("ebx");
-       &mov    (&DWP(0,$W512,$Widx,8),"ebx");          # W512[i]
-       &mov    (&DWP(4,$W512,$Widx,8),"eax");
-       &mov    (&DWP(128+0,$W512,$Widx,8),"ebx");      # copy of W512[i]
-       &mov    (&DWP(128+4,$W512,$Widx,8),"eax");
-
-&align(8);
-&set_label("_1st_loop");               # 0-15
-       # flip input stream byte order...
-       &mov    ("eax",&DWP(0+8,$data,$Widx,8));
-       &mov    ("ebx",&DWP(4+8,$data,$Widx,8));
-       &bswap  ("eax");
-       &bswap  ("ebx");
-       &mov    (&DWP(0+8,$W512,$Widx,8),"ebx");        # W512[i]
-       &mov    (&DWP(4+8,$W512,$Widx,8),"eax");
-       &mov    (&DWP(128+0+8,$W512,$Widx,8),"ebx");    # copy of W512[i]
-       &mov    (&DWP(128+4+8,$W512,$Widx,8),"eax");
-&set_label("_1st_looplet");
-       &SHA2_ROUND($Widx,$Widx); &inc($Widx);
-
-&cmp   ($Widx,15)
-&jl    (&label("_1st_loop"));
-&je    (&label("_1st_looplet"));       # playing similar trick on 2nd loop
-                                       # does not improve performance...
-
-       $Kidx = "ebx";                  # start using %ebx as Kidx
-       &mov    ($Kidx,$Widx);
-
-&align(8);
-&set_label("_2nd_loop");               # 16-79
-       &and($Widx,0xf);
-
-       # 128-bit fragment! I update W512[i] and W512[i+1] in
-       # parallel:-) Note that I refer to W512[(i&0xf)+N] and not to
-       # W512[(i+N)&0xf]! This is exactly what I maintain the second
-       # copy of W512[16] for...
-       &movdqu ("xmm0",&QWP(8*1,$W512,$Widx,8));       # s0=W512[i+1]
-       &movdqa ("xmm2","xmm0");                # %xmm2 is sliding right
-       &movdqa ("xmm3","xmm0");                # %xmm3 is sliding left
-       &psrlq  ("xmm2",1);
-       &psllq  ("xmm3",56);
-       &movdqa ("xmm0","xmm2");
-       &pxor   ("xmm0","xmm3");
-       &psrlq  ("xmm2",6);
-       &psllq  ("xmm3",7);
-       &pxor   ("xmm0","xmm2");
-       &pxor   ("xmm0","xmm3");
-       &psrlq  ("xmm2",1);
-       &pxor   ("xmm0","xmm2");                # s0 = sigma0_512(s0);
-
-       &movdqa ("xmm1",&QWP(8*14,$W512,$Widx,8));      # s1=W512[i+14]
-       &movdqa ("xmm4","xmm1");                # %xmm4 is sliding right
-       &movdqa ("xmm5","xmm1");                # %xmm5 is sliding left
-       &psrlq  ("xmm4",6);
-       &psllq  ("xmm5",3);
-       &movdqa ("xmm1","xmm4");
-       &pxor   ("xmm1","xmm5");
-       &psrlq  ("xmm4",13);
-       &psllq  ("xmm5",42);
-       &pxor   ("xmm1","xmm4");
-       &pxor   ("xmm1","xmm5");
-       &psrlq  ("xmm4",42);
-       &pxor   ("xmm1","xmm4");                # s1 = sigma1_512(s1);
-
-       #     + have to explictly load W512[i+9] as it's not 128-bit
-       #     v aligned and paddq would throw an exception...
-       &movdqu ("xmm6",&QWP(8*9,$W512,$Widx,8));
-       &paddq  ("xmm0","xmm1");                # s0 += s1
-       &paddq  ("xmm0","xmm6");                # s0 += W512[i+9]
-       &paddq  ("xmm0",&QWP(0,$W512,$Widx,8)); # s0 += W512[i]
-
-       &movdqa (&QWP(0,$W512,$Widx,8),"xmm0");         # W512[i] = s0
-       &movdqa (&QWP(16*8,$W512,$Widx,8),"xmm0");      # copy of W512[i]
-
-       # as the above fragment was 128-bit, we "owe" 2 rounds...
-       &SHA2_ROUND($Kidx,$Widx); &inc($Kidx); &inc($Widx);
-       &SHA2_ROUND($Kidx,$Widx); &inc($Kidx); &inc($Widx);
-
-&cmp   ($Kidx,80);
-&jl    (&label("_2nd_loop"));
-
-       # update A-H state
-       &mov    ($Widx,&DWP(8,"ebp"));          # A-H state, 1st arg
-       &movq   (&QWP($Aoff,$W512),$A);         # write out a
-       &movq   (&QWP($Eoff,$W512),$E);         # write out e
-       &movdqu ("xmm0",&QWP(0,$Widx));
-       &movdqu ("xmm1",&QWP(16,$Widx));
-       &movdqu ("xmm2",&QWP(32,$Widx));
-       &movdqu ("xmm3",&QWP(48,$Widx));
-       &paddq  ("xmm0",&QWP($Aoff,$W512));     # 128-bit additions...
-       &paddq  ("xmm1",&QWP($Coff,$W512));
-       &paddq  ("xmm2",&QWP($Eoff,$W512));
-       &paddq  ("xmm3",&QWP($Goff,$W512));
-       &movdqu (&QWP(0,$Widx),"xmm0");
-       &movdqu (&QWP(16,$Widx),"xmm1");
-       &movdqu (&QWP(32,$Widx),"xmm2");
-       &movdqu (&QWP(48,$Widx),"xmm3");
-
-&add   ($data,16*8);                           # advance input data pointer
-&dec   (&DWP(16,"ebp"));                       # decrement 3rd arg
-&jnz   (&label("_chunk_loop"));
-
-       # epilogue
-       &emms   ();     # required for at least ELF and Win32 ABIs
-       &mov    ("edi",&DWP(-12,"ebp"));
-       &mov    ("esi",&DWP(-8,"ebp"));
-       &mov    ("ebx",&DWP(-4,"ebp"));
-       &leave  ();
-&ret   ();
-
-&align(64);
-&set_label("K512");    # Yes! I keep it in the code segment!
-       &data_word(0xd728ae22,0x428a2f98);      # u64
-       &data_word(0x23ef65cd,0x71374491);      # u64
-       &data_word(0xec4d3b2f,0xb5c0fbcf);      # u64
-       &data_word(0x8189dbbc,0xe9b5dba5);      # u64
-       &data_word(0xf348b538,0x3956c25b);      # u64
-       &data_word(0xb605d019,0x59f111f1);      # u64
-       &data_word(0xaf194f9b,0x923f82a4);      # u64
-       &data_word(0xda6d8118,0xab1c5ed5);      # u64
-       &data_word(0xa3030242,0xd807aa98);      # u64
-       &data_word(0x45706fbe,0x12835b01);      # u64
-       &data_word(0x4ee4b28c,0x243185be);      # u64
-       &data_word(0xd5ffb4e2,0x550c7dc3);      # u64
-       &data_word(0xf27b896f,0x72be5d74);      # u64
-       &data_word(0x3b1696b1,0x80deb1fe);      # u64
-       &data_word(0x25c71235,0x9bdc06a7);      # u64
-       &data_word(0xcf692694,0xc19bf174);      # u64
-       &data_word(0x9ef14ad2,0xe49b69c1);      # u64
-       &data_word(0x384f25e3,0xefbe4786);      # u64
-       &data_word(0x8b8cd5b5,0x0fc19dc6);      # u64
-       &data_word(0x77ac9c65,0x240ca1cc);      # u64
-       &data_word(0x592b0275,0x2de92c6f);      # u64
-       &data_word(0x6ea6e483,0x4a7484aa);      # u64
-       &data_word(0xbd41fbd4,0x5cb0a9dc);      # u64
-       &data_word(0x831153b5,0x76f988da);      # u64
-       &data_word(0xee66dfab,0x983e5152);      # u64
-       &data_word(0x2db43210,0xa831c66d);      # u64
-       &data_word(0x98fb213f,0xb00327c8);      # u64
-       &data_word(0xbeef0ee4,0xbf597fc7);      # u64
-       &data_word(0x3da88fc2,0xc6e00bf3);      # u64
-       &data_word(0x930aa725,0xd5a79147);      # u64
-       &data_word(0xe003826f,0x06ca6351);      # u64
-       &data_word(0x0a0e6e70,0x14292967);      # u64
-       &data_word(0x46d22ffc,0x27b70a85);      # u64
-       &data_word(0x5c26c926,0x2e1b2138);      # u64
-       &data_word(0x5ac42aed,0x4d2c6dfc);      # u64
-       &data_word(0x9d95b3df,0x53380d13);      # u64
-       &data_word(0x8baf63de,0x650a7354);      # u64
-       &data_word(0x3c77b2a8,0x766a0abb);      # u64
-       &data_word(0x47edaee6,0x81c2c92e);      # u64
-       &data_word(0x1482353b,0x92722c85);      # u64
-       &data_word(0x4cf10364,0xa2bfe8a1);      # u64
-       &data_word(0xbc423001,0xa81a664b);      # u64
-       &data_word(0xd0f89791,0xc24b8b70);      # u64
-       &data_word(0x0654be30,0xc76c51a3);      # u64
-       &data_word(0xd6ef5218,0xd192e819);      # u64
-       &data_word(0x5565a910,0xd6990624);      # u64
-       &data_word(0x5771202a,0xf40e3585);      # u64
-       &data_word(0x32bbd1b8,0x106aa070);      # u64
-       &data_word(0xb8d2d0c8,0x19a4c116);      # u64
-       &data_word(0x5141ab53,0x1e376c08);      # u64
-       &data_word(0xdf8eeb99,0x2748774c);      # u64
-       &data_word(0xe19b48a8,0x34b0bcb5);      # u64
-       &data_word(0xc5c95a63,0x391c0cb3);      # u64
-       &data_word(0xe3418acb,0x4ed8aa4a);      # u64
-       &data_word(0x7763e373,0x5b9cca4f);      # u64
-       &data_word(0xd6b2b8a3,0x682e6ff3);      # u64
-       &data_word(0x5defb2fc,0x748f82ee);      # u64
-       &data_word(0x43172f60,0x78a5636f);      # u64
-       &data_word(0xa1f0ab72,0x84c87814);      # u64
-       &data_word(0x1a6439ec,0x8cc70208);      # u64
-       &data_word(0x23631e28,0x90befffa);      # u64
-       &data_word(0xde82bde9,0xa4506ceb);      # u64
-       &data_word(0xb2c67915,0xbef9a3f7);      # u64
-       &data_word(0xe372532b,0xc67178f2);      # u64
-       &data_word(0xea26619c,0xca273ece);      # u64
-       &data_word(0x21c0c207,0xd186b8c7);      # u64
-       &data_word(0xcde0eb1e,0xeada7dd6);      # u64
-       &data_word(0xee6ed178,0xf57d4f7f);      # u64
-       &data_word(0x72176fba,0x06f067aa);      # u64
-       &data_word(0xa2c898a6,0x0a637dc5);      # u64
-       &data_word(0xbef90dae,0x113f9804);      # u64
-       &data_word(0x131c471b,0x1b710b35);      # u64
-       &data_word(0x23047d84,0x28db77f5);      # u64
-       &data_word(0x40c72493,0x32caab7b);      # u64
-       &data_word(0x15c9bebc,0x3c9ebe0a);      # u64
-       &data_word(0x9c100d4c,0x431d67c4);      # u64
-       &data_word(0xcb3e42b6,0x4cc5d4be);      # u64
-       &data_word(0xfc657e2a,0x597f299c);      # u64
-       &data_word(0x3ad6faec,0x5fcb6fab);      # u64
-       &data_word(0x4a475817,0x6c44198c);      # u64
-
-&function_end_B($func);
-
-&asm_finish();
index b6252d3..e6643f8 100755 (executable)
 # sha256_block:-( This is presumably because 64-bit shifts/rotates
 # apparently are not atomic instructions, but implemented in microcode.
 
-$output=shift;
+$flavour = shift;
+$output  = shift;
+if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
+
+$win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
 
 $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
 ( $xlate="${dir}x86_64-xlate.pl" and -f $xlate ) or
 ( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
 die "can't locate x86_64-xlate.pl";
 
-open STDOUT,"| $^X $xlate $output";
+open STDOUT,"| $^X $xlate $flavour $output";
 
 if ($output =~ /512/) {
        $func="sha512_block_data_order";
@@ -186,7 +190,7 @@ $func:
        push    %r13
        push    %r14
        push    %r15
-       mov     %rsp,%rbp               # copy %rsp
+       mov     %rsp,%r11               # copy %rsp
        shl     \$4,%rdx                # num*16
        sub     \$$framesz,%rsp
        lea     ($inp,%rdx,$SZ),%rdx    # inp+num*16*$SZ
@@ -194,10 +198,10 @@ $func:
        mov     $ctx,$_ctx              # save ctx, 1st arg
        mov     $inp,$_inp              # save inp, 2nd arh
        mov     %rdx,$_end              # save end pointer, "3rd" arg
-       mov     %rbp,$_rsp              # save copy of %rsp
+       mov     %r11,$_rsp              # save copy of %rsp
+.Lprologue:
 
-       .picmeup $Tbl
-       lea     $TABLE-.($Tbl),$Tbl
+       lea     $TABLE(%rip),$Tbl
 
        mov     $SZ*0($ctx),$A
        mov     $SZ*1($ctx),$B
@@ -257,14 +261,15 @@ $code.=<<___;
        mov     $H,$SZ*7($ctx)
        jb      .Lloop
 
-       mov     $_rsp,%rsp
-       pop     %r15
-       pop     %r14
-       pop     %r13
-       pop     %r12
-       pop     %rbp
-       pop     %rbx
-
+       mov     $_rsp,%rsi
+       mov     (%rsi),%r15
+       mov     8(%rsi),%r14
+       mov     16(%rsi),%r13
+       mov     24(%rsi),%r12
+       mov     32(%rsi),%rbp
+       mov     40(%rsi),%rbx
+       lea     48(%rsi),%rsp
+.Lepilogue:
        ret
 .size  $func,.-$func
 ___
@@ -339,6 +344,113 @@ $TABLE:
 ___
 }
 
+# EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
+#              CONTEXT *context,DISPATCHER_CONTEXT *disp)
+if ($win64) {
+$rec="%rcx";
+$frame="%rdx";
+$context="%r8";
+$disp="%r9";
+
+$code.=<<___;
+.extern        __imp_RtlVirtualUnwind
+.type  se_handler,\@abi-omnipotent
+.align 16
+se_handler:
+       push    %rsi
+       push    %rdi
+       push    %rbx
+       push    %rbp
+       push    %r12
+       push    %r13
+       push    %r14
+       push    %r15
+       pushfq
+       sub     \$64,%rsp
+
+       mov     120($context),%rax      # pull context->Rax
+       mov     248($context),%rbx      # pull context->Rip
+
+       lea     .Lprologue(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip<.Lprologue
+       jb      .Lin_prologue
+
+       mov     152($context),%rax      # pull context->Rsp
+
+       lea     .Lepilogue(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip>=.Lepilogue
+       jae     .Lin_prologue
+
+       mov     16*$SZ+3*8(%rax),%rax   # pull $_rsp
+       lea     48(%rax),%rax
+
+       mov     -8(%rax),%rbx
+       mov     -16(%rax),%rbp
+       mov     -24(%rax),%r12
+       mov     -32(%rax),%r13
+       mov     -40(%rax),%r14
+       mov     -48(%rax),%r15
+       mov     %rbx,144($context)      # restore context->Rbx
+       mov     %rbp,160($context)      # restore context->Rbp
+       mov     %r12,216($context)      # restore context->R12
+       mov     %r13,224($context)      # restore context->R13
+       mov     %r14,232($context)      # restore context->R14
+       mov     %r15,240($context)      # restore context->R15
+
+.Lin_prologue:
+       mov     8(%rax),%rdi
+       mov     16(%rax),%rsi
+       mov     %rax,152($context)      # restore context->Rsp
+       mov     %rsi,168($context)      # restore context->Rsi
+       mov     %rdi,176($context)      # restore context->Rdi
+
+       mov     40($disp),%rdi          # disp->ContextRecord
+       mov     $context,%rsi           # context
+       mov     \$154,%ecx              # sizeof(CONTEXT)
+       .long   0xa548f3fc              # cld; rep movsq
+
+       mov     $disp,%rsi
+       xor     %rcx,%rcx               # arg1, UNW_FLAG_NHANDLER
+       mov     8(%rsi),%rdx            # arg2, disp->ImageBase
+       mov     0(%rsi),%r8             # arg3, disp->ControlPc
+       mov     16(%rsi),%r9            # arg4, disp->FunctionEntry
+       mov     40(%rsi),%r10           # disp->ContextRecord
+       lea     56(%rsi),%r11           # &disp->HandlerData
+       lea     24(%rsi),%r12           # &disp->EstablisherFrame
+       mov     %r10,32(%rsp)           # arg5
+       mov     %r11,40(%rsp)           # arg6
+       mov     %r12,48(%rsp)           # arg7
+       mov     %rcx,56(%rsp)           # arg8, (NULL)
+       call    *__imp_RtlVirtualUnwind(%rip)
+
+       mov     \$1,%eax                # ExceptionContinueSearch
+       add     \$64,%rsp
+       popfq
+       pop     %r15
+       pop     %r14
+       pop     %r13
+       pop     %r12
+       pop     %rbp
+       pop     %rbx
+       pop     %rdi
+       pop     %rsi
+       ret
+.size  se_handler,.-se_handler
+
+.section       .pdata
+.align 4
+       .rva    .LSEH_begin_$func
+       .rva    .LSEH_end_$func
+       .rva    .LSEH_info_$func
+
+.section       .xdata
+.align 8
+.LSEH_info_$func:
+       .byte   9,0,0,0
+       .rva    se_handler
+___
+}
+
 $code =~ s/\`([^\`]*)\`/eval $1/gem;
 print $code;
 close STDOUT;
index 47a2c29..16cacf9 100644 (file)
@@ -81,7 +81,7 @@ extern "C" {
  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  */
 
-#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)
+#if defined(__LP32__)
 #define SHA_LONG unsigned long
 #elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
 #define SHA_LONG unsigned long
@@ -106,9 +106,6 @@ typedef struct SHAstate_st
        } SHA_CTX;
 
 #ifndef OPENSSL_NO_SHA0
-#ifdef OPENSSL_FIPS
-int private_SHA_Init(SHA_CTX *c);
-#endif
 int SHA_Init(SHA_CTX *c);
 int SHA_Update(SHA_CTX *c, const void *data, size_t len);
 int SHA_Final(unsigned char *md, SHA_CTX *c);
index 4831174..7c65b60 100644 (file)
@@ -61,7 +61,7 @@
 #include <openssl/sha.h>
 #include <openssl/crypto.h>
 
-#if !defined(OPENSSL_NO_SHA1)
+#ifndef OPENSSL_NO_SHA1
 unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md)
        {
        SHA_CTX c;
index d31f078..50d1925 100644 (file)
 #define SHA_1
 
 #include <openssl/opensslv.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
 
 const char SHA1_version[]="SHA1" OPENSSL_VERSION_PTEXT;
 
index 3256a83..8952d87 100644 (file)
 
 #include <openssl/crypto.h>
 #include <openssl/sha.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
 #include <openssl/opensslv.h>
 
 const char SHA256_version[]="SHA-256" OPENSSL_VERSION_PTEXT;
 
 int SHA224_Init (SHA256_CTX *c)
        {
-#ifdef OPENSSL_FIPS
-       FIPS_selftest_check();
-#endif
+       memset (c,0,sizeof(*c));
        c->h[0]=0xc1059ed8UL;   c->h[1]=0x367cd507UL;
        c->h[2]=0x3070dd17UL;   c->h[3]=0xf70e5939UL;
        c->h[4]=0xffc00b31UL;   c->h[5]=0x68581511UL;
        c->h[6]=0x64f98fa7UL;   c->h[7]=0xbefa4fa4UL;
-       c->Nl=0;        c->Nh=0;
-       c->num=0;       c->md_len=SHA224_DIGEST_LENGTH;
+       c->md_len=SHA224_DIGEST_LENGTH;
        return 1;
        }
 
 int SHA256_Init (SHA256_CTX *c)
        {
-#ifdef OPENSSL_FIPS
-       FIPS_selftest_check();
-#endif
+       memset (c,0,sizeof(*c));
        c->h[0]=0x6a09e667UL;   c->h[1]=0xbb67ae85UL;
        c->h[2]=0x3c6ef372UL;   c->h[3]=0xa54ff53aUL;
        c->h[4]=0x510e527fUL;   c->h[5]=0x9b05688cUL;
        c->h[6]=0x1f83d9abUL;   c->h[7]=0x5be0cd19UL;
-       c->Nl=0;        c->Nh=0;
-       c->num=0;       c->md_len=SHA256_DIGEST_LENGTH;
+       c->md_len=SHA256_DIGEST_LENGTH;
        return 1;
        }
 
@@ -94,21 +84,21 @@ int SHA224_Final (unsigned char *md, SHA256_CTX *c)
  */
 #define        HASH_MAKE_STRING(c,s)   do {    \
        unsigned long ll;               \
-       unsigned int  xn;               \
+       unsigned int  nn;               \
        switch ((c)->md_len)            \
        {   case SHA224_DIGEST_LENGTH:  \
-               for (xn=0;xn<SHA224_DIGEST_LENGTH/4;xn++)       \
-               {   ll=(c)->h[xn]; HOST_l2c(ll,(s));   }        \
+               for (nn=0;nn<SHA224_DIGEST_LENGTH/4;nn++)       \
+               {   ll=(c)->h[nn]; HOST_l2c(ll,(s));   }        \
                break;                  \
            case SHA256_DIGEST_LENGTH:  \
-               for (xn=0;xn<SHA256_DIGEST_LENGTH/4;xn++)       \
-               {   ll=(c)->h[xn]; HOST_l2c(ll,(s));   }        \
+               for (nn=0;nn<SHA256_DIGEST_LENGTH/4;nn++)       \
+               {   ll=(c)->h[nn]; HOST_l2c(ll,(s));   }        \
                break;                  \
            default:                    \
                if ((c)->md_len > SHA256_DIGEST_LENGTH) \
                    return 0;                           \
-               for (xn=0;xn<(c)->md_len/4;xn++)                \
-               {   ll=(c)->h[xn]; HOST_l2c(ll,(s));   }        \
+               for (nn=0;nn<(c)->md_len/4;nn++)                \
+               {   ll=(c)->h[nn]; HOST_l2c(ll,(s));   }        \
                break;                  \
        }                               \
        } while (0)
index 9e91bca..cbc0e58 100644 (file)
@@ -5,10 +5,6 @@
  * ====================================================================
  */
 #include <openssl/opensslconf.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
 #if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA512)
 /*
  * IMPLEMENTATION NOTES.
@@ -65,9 +61,19 @@ const char SHA512_version[]="SHA-512" OPENSSL_VERSION_PTEXT;
 
 int SHA384_Init (SHA512_CTX *c)
        {
-#ifdef OPENSSL_FIPS
-       FIPS_selftest_check();
-#endif
+#if defined(SHA512_ASM) && (defined(__arm__) || defined(__arm))
+       /* maintain dword order required by assembler module */
+       unsigned int *h = (unsigned int *)c->h;
+
+       h[0]  = 0xcbbb9d5d; h[1]  = 0xc1059ed8;
+       h[2]  = 0x629a292a; h[3]  = 0x367cd507;
+       h[4]  = 0x9159015a; h[5]  = 0x3070dd17;
+       h[6]  = 0x152fecd8; h[7]  = 0xf70e5939;
+       h[8]  = 0x67332667; h[9]  = 0xffc00b31;
+       h[10] = 0x8eb44a87; h[11] = 0x68581511;
+       h[12] = 0xdb0c2e0d; h[13] = 0x64f98fa7;
+       h[14] = 0x47b5481d; h[15] = 0xbefa4fa4;
+#else
        c->h[0]=U64(0xcbbb9d5dc1059ed8);
        c->h[1]=U64(0x629a292a367cd507);
        c->h[2]=U64(0x9159015a3070dd17);
@@ -76,6 +82,7 @@ int SHA384_Init (SHA512_CTX *c)
        c->h[5]=U64(0x8eb44a8768581511);
        c->h[6]=U64(0xdb0c2e0d64f98fa7);
        c->h[7]=U64(0x47b5481dbefa4fa4);
+#endif
         c->Nl=0;        c->Nh=0;
         c->num=0;       c->md_len=SHA384_DIGEST_LENGTH;
         return 1;
@@ -83,9 +90,19 @@ int SHA384_Init (SHA512_CTX *c)
 
 int SHA512_Init (SHA512_CTX *c)
        {
-#ifdef OPENSSL_FIPS
-       FIPS_selftest_check();
-#endif
+#if defined(SHA512_ASM) && (defined(__arm__) || defined(__arm))
+       /* maintain dword order required by assembler module */
+       unsigned int *h = (unsigned int *)c->h;
+
+       h[0]  = 0x6a09e667; h[1]  = 0xf3bcc908;
+       h[2]  = 0xbb67ae85; h[3]  = 0x84caa73b;
+       h[4]  = 0x3c6ef372; h[5]  = 0xfe94f82b;
+       h[6]  = 0xa54ff53a; h[7]  = 0x5f1d36f1;
+       h[8]  = 0x510e527f; h[9]  = 0xade682d1;
+       h[10] = 0x9b05688c; h[11] = 0x2b3e6c1f;
+       h[12] = 0x1f83d9ab; h[13] = 0xfb41bd6b;
+       h[14] = 0x5be0cd19; h[15] = 0x137e2179;
+#else
        c->h[0]=U64(0x6a09e667f3bcc908);
        c->h[1]=U64(0xbb67ae8584caa73b);
        c->h[2]=U64(0x3c6ef372fe94f82b);
@@ -94,6 +111,7 @@ int SHA512_Init (SHA512_CTX *c)
        c->h[5]=U64(0x9b05688c2b3e6c1f);
        c->h[6]=U64(0x1f83d9abfb41bd6b);
        c->h[7]=U64(0x5be0cd19137e2179);
+#endif
         c->Nl=0;        c->Nh=0;
         c->num=0;       c->md_len=SHA512_DIGEST_LENGTH;
         return 1;
@@ -142,6 +160,24 @@ int SHA512_Final (unsigned char *md, SHA512_CTX *c)
 
        if (md==0) return 0;
 
+#if defined(SHA512_ASM) && (defined(__arm__) || defined(__arm))
+       /* recall assembler dword order... */
+       n = c->md_len;
+       if (n == SHA384_DIGEST_LENGTH || n == SHA512_DIGEST_LENGTH)
+               {
+               unsigned int *h = (unsigned int *)c->h, t;
+
+               for (n/=4;n;n--)
+                       {
+                       t = *(h++);
+                       *(md++) = (unsigned char)(t>>24);
+                       *(md++) = (unsigned char)(t>>16);
+                       *(md++) = (unsigned char)(t>>8);
+                       *(md++) = (unsigned char)(t);
+                       }
+               }
+       else    return 0;
+#else
        switch (c->md_len)
                {
                /* Let compiler decide if it's appropriate to unroll... */
@@ -178,7 +214,7 @@ int SHA512_Final (unsigned char *md, SHA512_CTX *c)
                /* ... as well as make sure md_len is not abused. */
                default:        return 0;
                }
-
+#endif
        return 1;
        }
 
@@ -204,7 +240,7 @@ int SHA512_Update (SHA512_CTX *c, const void *_data, size_t len)
 
                if (len < n)
                        {
-                       memcpy (p+c->num,data,len), c->num += len;
+                       memcpy (p+c->num,data,len), c->num += (unsigned int)len;
                        return 1;
                        }
                else    {
@@ -314,7 +350,7 @@ static const SHA_LONG64 K512[80] = {
 #ifndef PEDANTIC
 # if defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
 #  if defined(__x86_64) || defined(__x86_64__)
-#   define ROTR(a,n)   ({ unsigned long ret;           \
+#   define ROTR(a,n)   ({ SHA_LONG64 ret;              \
                                asm ("rorq %1,%0"       \
                                : "=r"(ret)             \
                                : "J"(n),"0"(a)         \
@@ -337,20 +373,21 @@ static const SHA_LONG64 K512[80] = {
                                ((SHA_LONG64)hi)<<32|lo;        })
 #   else
 #    define PULL64(x) ({ const unsigned int *p=(const unsigned int *)(&(x));\
-                        unsigned int hi=p[0],lo=p[1];                  \
+                        unsigned int hi=p[0],lo=p[1];          \
                                asm ("bswapl %0; bswapl %1;"    \
                                : "=r"(lo),"=r"(hi)             \
                                : "0"(lo),"1"(hi));             \
                                ((SHA_LONG64)hi)<<32|lo;        })
 #   endif
 #  elif (defined(_ARCH_PPC) && defined(__64BIT__)) || defined(_ARCH_PPC64)
-#   define ROTR(a,n)   ({ unsigned long ret;           \
+#   define ROTR(a,n)   ({ SHA_LONG64 ret;              \
                                asm ("rotrdi %0,%1,%2"  \
                                : "=r"(ret)             \
                                : "r"(a),"K"(n)); ret;  })
 #  endif
 # elif defined(_MSC_VER)
 #  if defined(_WIN64)  /* applies to both IA-64 and AMD64 */
+#   pragma intrinsic(_rotr64)
 #   define ROTR(a,n)   _rotr64((a),n)
 #  endif
 #  if defined(_M_IX86) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
@@ -398,15 +435,66 @@ static const SHA_LONG64 K512[80] = {
 #define Ch(x,y,z)      (((x) & (y)) ^ ((~(x)) & (z)))
 #define Maj(x,y,z)     (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
 
-#if defined(OPENSSL_IA32_SSE2) && !defined(OPENSSL_NO_ASM) && !defined(I386_ONLY)
-#define        GO_FOR_SSE2(ctx,in,num)         do {            \
-       void    sha512_block_sse2(void *,const void *,size_t);  \
-       if (!(OPENSSL_ia32cap_P & (1<<26))) break;      \
-       sha512_block_sse2(ctx->h,in,num); return;       \
-                                       } while (0)
+
+#if defined(__i386) || defined(__i386__) || defined(_M_IX86)
+/*
+ * This code should give better results on 32-bit CPU with less than
+ * ~24 registers, both size and performance wise...
+ */
+static void sha512_block_data_order (SHA512_CTX *ctx, const void *in, size_t num)
+       {
+       const SHA_LONG64 *W=in;
+       SHA_LONG64      A,E,T;
+       SHA_LONG64      X[9+80],*F;
+       int i;
+
+                       while (num--) {
+
+       F    = X+80;
+       A    = ctx->h[0];       F[1] = ctx->h[1];
+       F[2] = ctx->h[2];       F[3] = ctx->h[3];
+       E    = ctx->h[4];       F[5] = ctx->h[5];
+       F[6] = ctx->h[6];       F[7] = ctx->h[7];
+
+       for (i=0;i<16;i++,F--)
+               {
+#ifdef B_ENDIAN
+               T = W[i];
+#else
+               T = PULL64(W[i]);
 #endif
+               F[0] = A;
+               F[4] = E;
+               F[8] = T;
+               T   += F[7] + Sigma1(E) + Ch(E,F[5],F[6]) + K512[i];
+               E    = F[3] + T;
+               A    = T + Sigma0(A) + Maj(A,F[1],F[2]);
+               }
+
+       for (;i<80;i++,F--)
+               {
+               T    = sigma0(F[8+16-1]);
+               T   += sigma1(F[8+16-14]);
+               T   += F[8+16] + F[8+16-9];
+
+               F[0] = A;
+               F[4] = E;
+               F[8] = T;
+               T   += F[7] + Sigma1(E) + Ch(E,F[5],F[6]) + K512[i];
+               E    = F[3] + T;
+               A    = T + Sigma0(A) + Maj(A,F[1],F[2]);
+               }
 
-#ifdef OPENSSL_SMALL_FOOTPRINT
+       ctx->h[0] += A;         ctx->h[1] += F[1];
+       ctx->h[2] += F[2];      ctx->h[3] += F[3];
+       ctx->h[4] += E;         ctx->h[5] += F[5];
+       ctx->h[6] += F[6];      ctx->h[7] += F[7];
+
+                       W+=SHA_LBLOCK;
+                       }
+       }
+
+#elif defined(OPENSSL_SMALL_FOOTPRINT)
 
 static void sha512_block_data_order (SHA512_CTX *ctx, const void *in, size_t num)
        {
@@ -415,10 +503,6 @@ static void sha512_block_data_order (SHA512_CTX *ctx, const void *in, size_t num
        SHA_LONG64      X[16];
        int i;
 
-#ifdef GO_FOR_SSE2
-       GO_FOR_SSE2(ctx,in,num);
-#endif
-
                        while (num--) {
 
        a = ctx->h[0];  b = ctx->h[1];  c = ctx->h[2];  d = ctx->h[3];
@@ -463,11 +547,11 @@ static void sha512_block_data_order (SHA512_CTX *ctx, const void *in, size_t num
        h = Sigma0(a) + Maj(a,b,c);                     \
        d += T1;        h += T1;                } while (0)
 
-#define        ROUND_16_80(i,a,b,c,d,e,f,g,h,X)        do {    \
-       s0 = X[(i+1)&0x0f];     s0 = sigma0(s0);        \
-       s1 = X[(i+14)&0x0f];    s1 = sigma1(s1);        \
-       T1 = X[(i)&0x0f] += s0 + s1 + X[(i+9)&0x0f];    \
-       ROUND_00_15(i,a,b,c,d,e,f,g,h);         } while (0)
+#define        ROUND_16_80(i,j,a,b,c,d,e,f,g,h,X)      do {    \
+       s0 = X[(j+1)&0x0f];     s0 = sigma0(s0);        \
+       s1 = X[(j+14)&0x0f];    s1 = sigma1(s1);        \
+       T1 = X[(j)&0x0f] += s0 + s1 + X[(j+9)&0x0f];    \
+       ROUND_00_15(i+j,a,b,c,d,e,f,g,h);               } while (0)
 
 static void sha512_block_data_order (SHA512_CTX *ctx, const void *in, size_t num)
        {
@@ -476,10 +560,6 @@ static void sha512_block_data_order (SHA512_CTX *ctx, const void *in, size_t num
        SHA_LONG64      X[16];
        int i;
 
-#ifdef GO_FOR_SSE2
-       GO_FOR_SSE2(ctx,in,num);
-#endif
-
                        while (num--) {
 
        a = ctx->h[0];  b = ctx->h[1];  c = ctx->h[2];  d = ctx->h[3];
@@ -521,16 +601,24 @@ static void sha512_block_data_order (SHA512_CTX *ctx, const void *in, size_t num
        T1 = X[15] = PULL64(W[15]);     ROUND_00_15(15,b,c,d,e,f,g,h,a);
 #endif
 
-       for (i=16;i<80;i+=8)
+       for (i=16;i<80;i+=16)
                {
-               ROUND_16_80(i+0,a,b,c,d,e,f,g,h,X);
-               ROUND_16_80(i+1,h,a,b,c,d,e,f,g,X);
-               ROUND_16_80(i+2,g,h,a,b,c,d,e,f,X);
-               ROUND_16_80(i+3,f,g,h,a,b,c,d,e,X);
-               ROUND_16_80(i+4,e,f,g,h,a,b,c,d,X);
-               ROUND_16_80(i+5,d,e,f,g,h,a,b,c,X);
-               ROUND_16_80(i+6,c,d,e,f,g,h,a,b,X);
-               ROUND_16_80(i+7,b,c,d,e,f,g,h,a,X);
+               ROUND_16_80(i, 0,a,b,c,d,e,f,g,h,X);
+               ROUND_16_80(i, 1,h,a,b,c,d,e,f,g,X);
+               ROUND_16_80(i, 2,g,h,a,b,c,d,e,f,X);
+               ROUND_16_80(i, 3,f,g,h,a,b,c,d,e,X);
+               ROUND_16_80(i, 4,e,f,g,h,a,b,c,d,X);
+               ROUND_16_80(i, 5,d,e,f,g,h,a,b,c,X);
+               ROUND_16_80(i, 6,c,d,e,f,g,h,a,b,X);
+               ROUND_16_80(i, 7,b,c,d,e,f,g,h,a,X);
+               ROUND_16_80(i, 8,a,b,c,d,e,f,g,h,X);
+               ROUND_16_80(i, 9,h,a,b,c,d,e,f,g,X);
+               ROUND_16_80(i,10,g,h,a,b,c,d,e,f,X);
+               ROUND_16_80(i,11,f,g,h,a,b,c,d,e,X);
+               ROUND_16_80(i,12,e,f,g,h,a,b,c,d,X);
+               ROUND_16_80(i,13,d,e,f,g,h,a,b,c,X);
+               ROUND_16_80(i,14,c,d,e,f,g,h,a,b,X);
+               ROUND_16_80(i,15,b,c,d,e,f,g,h,a,X);
                }
 
        ctx->h[0] += a; ctx->h[1] += b; ctx->h[2] += c; ctx->h[3] += d;
@@ -544,13 +632,10 @@ static void sha512_block_data_order (SHA512_CTX *ctx, const void *in, size_t num
 
 #endif /* SHA512_ASM */
 
-#else /* OPENSSL_NO_SHA512 */
+#else /* !OPENSSL_NO_SHA512 */
 
-/* Sensitive compilers ("Compaq C V6.4-005 on OpenVMS VAX V7.3", for
- * example) dislike a statement-free file, complaining:
- * "%CC-W-EMPTYFILE, Source file does not contain any declarations."
- */
-
-int sha512_dummy();
+#if defined(PEDANTIC) || defined(__DECC) || defined(OPENSSL_SYS_MACOSX)
+static void *dummy=&dummy;
+#endif
 
-#endif /* OPENSSL_NO_SHA512 */
+#endif /* !OPENSSL_NO_SHA512 */
index 598f4d7..70eb560 100644 (file)
  */
 
 #include <openssl/opensslconf.h>
-#include <openssl/crypto.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
-#include <openssl/err.h>
 #if !defined(OPENSSL_NO_SHA0) && !defined(OPENSSL_NO_SHA)
 
 #undef  SHA_1
index da46ddf..672c26e 100644 (file)
@@ -122,23 +122,14 @@ void sha1_block_data_order (SHA_CTX *c, const void *p,size_t num);
 #define INIT_DATA_h3 0x10325476UL
 #define INIT_DATA_h4 0xc3d2e1f0UL
 
-#if defined(SHA_0) && defined(OPENSSL_FIPS)
-FIPS_NON_FIPS_MD_Init(SHA)
-#else
 int HASH_INIT (SHA_CTX *c)
-#endif
        {
-#if defined(SHA_1) && defined(OPENSSL_FIPS)
-       FIPS_selftest_check();
-#endif
+       memset (c,0,sizeof(*c));
        c->h0=INIT_DATA_h0;
        c->h1=INIT_DATA_h1;
        c->h2=INIT_DATA_h2;
        c->h3=INIT_DATA_h3;
        c->h4=INIT_DATA_h4;
-       c->Nl=0;
-       c->Nh=0;
-       c->num=0;
        return 1;
        }
 
index ed0fe06..2761464 100644 (file)
@@ -123,9 +123,9 @@ int main(int argc, char *argv[])
        i=1;
        while (*P != NULL)
                {
-               EVP_Digest(*P,strlen((char *)*P),md,NULL,EVP_sha(), NULL);
+               EVP_Digest(*P,strlen(*P),md,NULL,EVP_sha(), NULL);
                p=pt(md);
-               if (strcmp(p,(char *)*R) != 0)
+               if (strcmp(p,*R) != 0)
                        {
                        printf("error calculating SHA on '%s'\n",*P);
                        printf("got %s instead of %s\n",p,*R);
index c17350f..ae61f7f 100644 (file)
@@ -34,7 +34,8 @@ OPENSSL_wipe_cpu:
        nop
        call    .PIC.zero.up
        mov     .zero-(.-4),%o0
-       ldd     [%o0],%f0
+       ld      [%o0],%f0
+       ld      [%o0],%f1
 
        subcc   %g0,1,%o0
        ! Following is V9 "rd %ccr,%o0" instruction. However! V8
@@ -166,6 +167,7 @@ walk_reg_wins:
 
 .global        OPENSSL_atomic_add
 .type  OPENSSL_atomic_add,#function
+.align 32
 OPENSSL_atomic_add:
 #ifndef ABI64
        subcc   %g0,1,%o2
@@ -177,7 +179,7 @@ OPENSSL_atomic_add:
        ba      .enter
        nop
 #ifdef __sun
-! Note that you don't have to link with libthread to call thr_yield,
+! Note that you do not have to link with libthread to call thr_yield,
 ! as libc provides a stub, which is overloaded the moment you link
 ! with *either* libpthread or libthread...
 #define        YIELD_CPU       thr_yield
@@ -213,27 +215,188 @@ OPENSSL_atomic_add:
        sra     %o0,%g0,%o0     ! we return signed int, remember?
 .size  OPENSSL_atomic_add,.-OPENSSL_atomic_add
 
-.global        OPENSSL_rdtsc
+.global        _sparcv9_rdtick
+.align 32
+_sparcv9_rdtick:
        subcc   %g0,1,%o0
        .word   0x91408000      !rd     %ccr,%o0
        cmp     %o0,0x99
-       bne     .notsc
+       bne     .notick
        xor     %o0,%o0,%o0
-       save    %sp,FRAME-16,%sp
-       mov     513,%o0         !SI_PLATFORM
-       add     %sp,BIAS+16,%o1
-       call    sysinfo
-       mov     256,%o2
-
-       add     %sp,BIAS-16,%o1
-       ld      [%o1],%l0
-       ld      [%o1+4],%l1
-       ld      [%o1+8],%l2
-       mov     %lo('SUNW'),%l3
-       ret
-       restore
-.notsc:
+       .word   0x91410000      !rd     %tick,%o0
+       retl
+       .word   0x93323020      !srlx   %o0,32,%o1
+.notick:
+       retl
+       xor     %o1,%o1,%o1
+.type  _sparcv9_rdtick,#function
+.size  _sparcv9_rdtick,.-_sparcv9_rdtick
+
+.global        _sparcv9_vis1_probe
+.align 8
+_sparcv9_vis1_probe:
+       .word   0x81b00d80      !fxor   %f0,%f0,%f0
+       add     %sp,BIAS+2,%o1
+       retl
+       .word   0xc19a5a40      !ldda   [%o1]ASI_FP16_P,%f0
+.type  _sparcv9_vis1_probe,#function
+.size  _sparcv9_vis1_probe,.-_sparcv9_vis1_probe
+
+! Probe and instrument VIS1 instruction. Output is number of cycles it
+! takes to execute rdtick and pair of VIS1 instructions. US-Tx VIS unit
+! is slow (documented to be 6 cycles on T2) and the core is in-order
+! single-issue, it should be possible to distinguish Tx reliably...
+! Observed return values are:
+!
+!      UltraSPARC IIe          7
+!      UltraSPARC III          7
+!      UltraSPARC T1           24
+!
+! Numbers for T2 and SPARC64 V-VII are more than welcomed.
+!
+! It would be possible to detect specifically US-T1 by instrumenting
+! fmul8ulx16, which is emulated on T1 and as such accounts for quite
+! a lot of %tick-s, couple of thousand on Linux...
+.global        _sparcv9_vis1_instrument
+.align 8
+_sparcv9_vis1_instrument:
+       .word   0x91410000      !rd     %tick,%o0
+       .word   0x81b00d80      !fxor   %f0,%f0,%f0
+       .word   0x85b08d82      !fxor   %f2,%f2,%f2
+       .word   0x93410000      !rd     %tick,%o1
+       .word   0x81b00d80      !fxor   %f0,%f0,%f0
+       .word   0x85b08d82      !fxor   %f2,%f2,%f2
+       .word   0x95410000      !rd     %tick,%o2
+       .word   0x81b00d80      !fxor   %f0,%f0,%f0
+       .word   0x85b08d82      !fxor   %f2,%f2,%f2
+       .word   0x97410000      !rd     %tick,%o3
+       .word   0x81b00d80      !fxor   %f0,%f0,%f0
+       .word   0x85b08d82      !fxor   %f2,%f2,%f2
+       .word   0x99410000      !rd     %tick,%o4
+
+       ! calculate intervals
+       sub     %o1,%o0,%o0
+       sub     %o2,%o1,%o1
+       sub     %o3,%o2,%o2
+       sub     %o4,%o3,%o3
+
+       ! find minumum value
+       cmp     %o0,%o1
+       .word   0x38680002      !bgu,a  %xcc,.+8
+       mov     %o1,%o0
+       cmp     %o0,%o2
+       .word   0x38680002      !bgu,a  %xcc,.+8
+       mov     %o2,%o0
+       cmp     %o0,%o3
+       .word   0x38680002      !bgu,a  %xcc,.+8
+       mov     %o3,%o0
+
+       retl
+       nop
+.type  _sparcv9_vis1_instrument,#function
+.size  _sparcv9_vis1_instrument,.-_sparcv9_vis1_instrument
+
+.global        _sparcv9_vis2_probe
+.align 8
+_sparcv9_vis2_probe:
+       retl
+       .word   0x81b00980      !bshuffle       %f0,%f0,%f0
+.type  _sparcv9_vis2_probe,#function
+.size  _sparcv9_vis2_probe,.-_sparcv9_vis2_probe
+
+.global        _sparcv9_fmadd_probe
+.align 8
+_sparcv9_fmadd_probe:
+       .word   0x81b00d80      !fxor   %f0,%f0,%f0
+       .word   0x85b08d82      !fxor   %f2,%f2,%f2
        retl
+       .word   0x81b80440      !fmaddd %f0,%f0,%f2,%f0
+.type  _sparcv9_fmadd_probe,#function
+.size  _sparcv9_fmadd_probe,.-_sparcv9_fmadd_probe
+
+.global        OPENSSL_cleanse
+.align 32
+OPENSSL_cleanse:
+       cmp     %o1,14
+       nop
+#ifdef ABI64
+       bgu     %xcc,.Lot
+#else
+       bgu     .Lot
+#endif
+       cmp     %o1,0
+       bne     .Little
+       nop
+       retl
+       nop
+
+.Little:
+       stb     %g0,[%o0]
+       subcc   %o1,1,%o1
+       bnz     .Little
+       add     %o0,1,%o0
+       retl
+       nop
+.align 32
+.Lot:
+#ifndef ABI64
+       subcc   %g0,1,%g1
+       ! see above for explanation
+       .word   0x83408000      !rd     %ccr,%g1
+       cmp     %g1,0x99
+       bne     .v8lot
+       nop
+#endif
+
+.v9lot:        andcc   %o0,7,%g0
+       bz      .v9aligned
+       nop
+       stb     %g0,[%o0]
+       sub     %o1,1,%o1
+       ba      .v9lot
+       add     %o0,1,%o0
+.align 16,0x01000000
+.v9aligned:
+       .word   0xc0720000      !stx    %g0,[%o0]
+       sub     %o1,8,%o1
+       andcc   %o1,-8,%g0
+#ifdef ABI64
+       .word   0x126ffffd      !bnz    %xcc,.v9aligned
+#else
+       .word   0x124ffffd      !bnz    %icc,.v9aligned
+#endif
+       add     %o0,8,%o0
+
+       cmp     %o1,0
+       bne     .Little
+       nop
+       retl
+       nop
+#ifndef ABI64
+.v8lot:        andcc   %o0,3,%g0
+       bz      .v8aligned
+       nop
+       stb     %g0,[%o0]
+       sub     %o1,1,%o1
+       ba      .v8lot
+       add     %o0,1,%o0
+       nop
+.v8aligned:
+       st      %g0,[%o0]
+       sub     %o1,4,%o1
+       andcc   %o1,-4,%g0
+       bnz     .v8aligned
+       add     %o0,4,%o0
+
+       cmp     %o1,0
+       bne     .Little
+       nop
+       retl
+       nop
+#endif
+.type  OPENSSL_cleanse,#function
+.size  OPENSSL_cleanse,.-OPENSSL_cleanse
+
+.section       ".init",#alloc,#execinstr
+       call    OPENSSL_cpuid_setup
        nop
-.type  OPENSSL_rdtsc,#function
-.size  OPENSSL_rdtsc,.-OPENSSL_atomic_add
diff --git a/deps/openssl/openssl/crypto/sparcv9cap.c b/deps/openssl/openssl/crypto/sparcv9cap.c
new file mode 100644 (file)
index 0000000..ed195ab
--- /dev/null
@@ -0,0 +1,237 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <setjmp.h>
+#include <signal.h>
+#include <sys/time.h>
+#include <openssl/bn.h>
+
+#define SPARCV9_TICK_PRIVILEGED        (1<<0)
+#define SPARCV9_PREFER_FPU     (1<<1)
+#define SPARCV9_VIS1           (1<<2)
+#define SPARCV9_VIS2           (1<<3)  /* reserved */
+#define SPARCV9_FMADD          (1<<4)  /* reserved for SPARC64 V */
+
+static int OPENSSL_sparcv9cap_P=SPARCV9_TICK_PRIVILEGED;
+
+int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np,const BN_ULONG *n0, int num)
+       {
+       int bn_mul_mont_fpu(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np,const BN_ULONG *n0, int num);
+       int bn_mul_mont_int(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np,const BN_ULONG *n0, int num);
+
+       if ((OPENSSL_sparcv9cap_P&(SPARCV9_PREFER_FPU|SPARCV9_VIS1)) ==
+               (SPARCV9_PREFER_FPU|SPARCV9_VIS1))
+               return bn_mul_mont_fpu(rp,ap,bp,np,n0,num);
+       else
+               return bn_mul_mont_int(rp,ap,bp,np,n0,num);
+       }
+
+unsigned long  _sparcv9_rdtick(void);
+void           _sparcv9_vis1_probe(void);
+unsigned long  _sparcv9_vis1_instrument(void);
+void           _sparcv9_vis2_probe(void);
+void           _sparcv9_fmadd_probe(void);
+
+unsigned long OPENSSL_rdtsc(void)
+       {
+       if (OPENSSL_sparcv9cap_P&SPARCV9_TICK_PRIVILEGED)
+#if defined(__sun) && defined(__SVR4)
+               return gethrtime();
+#else
+               return 0;
+#endif
+       else
+               return _sparcv9_rdtick();
+       }
+
+#if 0 && defined(__sun) && defined(__SVR4)
+/* This code path is disabled, because of incompatibility of
+ * libdevinfo.so.1 and libmalloc.so.1 (see below for details)
+ */
+#include <malloc.h>
+#include <dlfcn.h>
+#include <libdevinfo.h>
+#include <sys/systeminfo.h>
+
+typedef di_node_t (*di_init_t)(const char *,uint_t);
+typedef void      (*di_fini_t)(di_node_t);
+typedef char *    (*di_node_name_t)(di_node_t);
+typedef int       (*di_walk_node_t)(di_node_t,uint_t,di_node_name_t,int (*)(di_node_t,di_node_name_t));
+
+#define DLLINK(h,name) (name=(name##_t)dlsym((h),#name))
+
+static int walk_nodename(di_node_t node, di_node_name_t di_node_name)
+       {
+       char *name = (*di_node_name)(node);
+
+       /* This is expected to catch all UltraSPARC flavors prior T1 */
+       if (!strcmp (name,"SUNW,UltraSPARC") ||
+           !strncmp(name,"SUNW,UltraSPARC-I",17))  /* covers II,III,IV */
+               {
+               OPENSSL_sparcv9cap_P |= SPARCV9_PREFER_FPU|SPARCV9_VIS1;
+
+               /* %tick is privileged only on UltraSPARC-I/II, but not IIe */
+               if (name[14]!='\0' && name[17]!='\0' && name[18]!='\0')
+                       OPENSSL_sparcv9cap_P &= ~SPARCV9_TICK_PRIVILEGED;
+
+               return DI_WALK_TERMINATE;
+               }
+       /* This is expected to catch remaining UltraSPARCs, such as T1 */
+       else if (!strncmp(name,"SUNW,UltraSPARC",15))
+               {
+               OPENSSL_sparcv9cap_P &= ~SPARCV9_TICK_PRIVILEGED;
+
+               return DI_WALK_TERMINATE;
+               }
+
+       return DI_WALK_CONTINUE;
+       }
+
+void OPENSSL_cpuid_setup(void)
+       {
+       void *h;
+       char *e,si[256];
+       static int trigger=0;
+
+       if (trigger) return;
+       trigger=1;
+
+       if ((e=getenv("OPENSSL_sparcv9cap")))
+               {
+               OPENSSL_sparcv9cap_P=strtoul(e,NULL,0);
+               return;
+               }
+
+       if (sysinfo(SI_MACHINE,si,sizeof(si))>0)
+               {
+               if (strcmp(si,"sun4v"))
+                       /* FPU is preferred for all CPUs, but US-T1/2 */
+                       OPENSSL_sparcv9cap_P |= SPARCV9_PREFER_FPU;
+               }
+
+       if (sysinfo(SI_ISALIST,si,sizeof(si))>0)
+               {
+               if (strstr(si,"+vis"))
+                       OPENSSL_sparcv9cap_P |= SPARCV9_VIS1;
+               if (strstr(si,"+vis2"))
+                       {
+                       OPENSSL_sparcv9cap_P |= SPARCV9_VIS2;
+                       OPENSSL_sparcv9cap_P &= ~SPARCV9_TICK_PRIVILEGED;
+                       return;
+                       }
+               }
+#ifdef M_KEEP
+       /*
+        * Solaris libdevinfo.so.1 is effectively incomatible with
+        * libmalloc.so.1. Specifically, if application is linked with
+        * -lmalloc, it crashes upon startup with SIGSEGV in
+        * free(3LIBMALLOC) called by di_fini. Prior call to
+        * mallopt(M_KEEP,0) somehow helps... But not always...
+        */
+       if ((h = dlopen(NULL,RTLD_LAZY)))
+               {
+               union { void *p; int (*f)(int,int); } sym;
+               if ((sym.p = dlsym(h,"mallopt"))) (*sym.f)(M_KEEP,0);
+               dlclose(h);
+               }
+#endif
+       if ((h = dlopen("libdevinfo.so.1",RTLD_LAZY))) do
+               {
+               di_init_t       di_init;
+               di_fini_t       di_fini;
+               di_walk_node_t  di_walk_node;
+               di_node_name_t  di_node_name;
+               di_node_t       root_node;
+
+               if (!DLLINK(h,di_init))         break;
+               if (!DLLINK(h,di_fini))         break;
+               if (!DLLINK(h,di_walk_node))    break;
+               if (!DLLINK(h,di_node_name))    break;
+
+               if ((root_node = (*di_init)("/",DINFOSUBTREE))!=DI_NODE_NIL)
+                       {
+                       (*di_walk_node)(root_node,DI_WALK_SIBFIRST,
+                                       di_node_name,walk_nodename);
+                       (*di_fini)(root_node);
+                       }
+               } while(0);
+
+       if (h) dlclose(h);
+       }
+
+#else
+
+static sigjmp_buf common_jmp;
+static void common_handler(int sig) { siglongjmp(common_jmp,sig); }
+
+void OPENSSL_cpuid_setup(void)
+       {
+       char *e;
+       struct sigaction        common_act,ill_oact,bus_oact;
+       sigset_t                all_masked,oset;
+       int                     sig;
+       static int trigger=0;
+
+       if (trigger) return;
+       trigger=1;
+       if ((e=getenv("OPENSSL_sparcv9cap")))
+               {
+               OPENSSL_sparcv9cap_P=strtoul(e,NULL,0);
+               return;
+               }
+
+       /* Initial value, fits UltraSPARC-I&II... */
+       OPENSSL_sparcv9cap_P = SPARCV9_PREFER_FPU|SPARCV9_TICK_PRIVILEGED;
+
+       sigfillset(&all_masked);
+       sigdelset(&all_masked,SIGILL);
+       sigdelset(&all_masked,SIGTRAP);
+#ifdef SIGEMT
+       sigdelset(&all_masked,SIGEMT);
+#endif
+       sigdelset(&all_masked,SIGFPE);
+       sigdelset(&all_masked,SIGBUS);
+       sigdelset(&all_masked,SIGSEGV);
+       sigprocmask(SIG_SETMASK,&all_masked,&oset);
+
+       memset(&common_act,0,sizeof(common_act));
+       common_act.sa_handler = common_handler;
+       common_act.sa_mask    = all_masked;
+
+       sigaction(SIGILL,&common_act,&ill_oact);
+       sigaction(SIGBUS,&common_act,&bus_oact);/* T1 fails 16-bit ldda [on Linux] */
+
+       if (sigsetjmp(common_jmp,1) == 0)
+               {
+               _sparcv9_rdtick();
+               OPENSSL_sparcv9cap_P &= ~SPARCV9_TICK_PRIVILEGED;
+               }
+
+       if (sigsetjmp(common_jmp,1) == 0)
+               {
+               _sparcv9_vis1_probe();
+               OPENSSL_sparcv9cap_P |= SPARCV9_VIS1;
+               /* detect UltraSPARC-Tx, see sparccpud.S for details... */
+               if (_sparcv9_vis1_instrument() >= 12)
+                       OPENSSL_sparcv9cap_P &= ~(SPARCV9_VIS1|SPARCV9_PREFER_FPU);
+               else
+                       {
+                       _sparcv9_vis2_probe();
+                       OPENSSL_sparcv9cap_P |= SPARCV9_VIS2;
+                       }
+               }
+
+       if (sigsetjmp(common_jmp,1) == 0)
+               {
+               _sparcv9_fmadd_probe();
+               OPENSSL_sparcv9cap_P |= SPARCV9_FMADD;
+               }
+
+       sigaction(SIGBUS,&bus_oact,NULL);
+       sigaction(SIGILL,&ill_oact,NULL);
+
+       sigprocmask(SIG_SETMASK,&oset,NULL);
+       }
+
+#endif
index 489a77b..5327692 100644 (file)
@@ -33,7 +33,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
index b59c640..3e76aa5 100644 (file)
 
 #include <openssl/stack.h>
 
-#ifdef DEBUG_SAFESTACK
-
 #ifndef CHECKED_PTR_OF
 #define CHECKED_PTR_OF(type, p) \
     ((void*) (1 ? p : (type*)0))
 #endif
 
+/* In C++ we get problems because an explicit cast is needed from (void *)
+ * we use CHECKED_STACK_OF to ensure the correct type is passed in the macros
+ * below. 
+ */
+
+#define CHECKED_STACK_OF(type, p) \
+    ((_STACK*) (1 ? p : (STACK_OF(type)*)0))
+
 #define CHECKED_SK_FREE_FUNC(type, p) \
     ((void (*)(void *)) ((1 ? p : (void (*)(type *))0)))
 
+#define CHECKED_SK_FREE_FUNC2(type, p) \
+    ((void (*)(void *)) ((1 ? p : (void (*)(type))0)))
+
 #define CHECKED_SK_CMP_FUNC(type, p) \
-    ((int (*)(const char * const *, const char * const *)) \
+    ((int (*)(const void *, const void *)) \
        ((1 ? p : (int (*)(const type * const *, const type * const *))0)))
 
 #define STACK_OF(type) struct stack_st_##type
 #define DECLARE_STACK_OF(type) \
 STACK_OF(type) \
     { \
-    STACK stack; \
+    _STACK stack; \
+    };
+#define DECLARE_SPECIAL_STACK_OF(type, type2) \
+STACK_OF(type) \
+    { \
+    _STACK stack; \
     };
 
 #define IMPLEMENT_STACK_OF(type) /* nada (obsolete in new safestack approach)*/
 
+
+/* Strings are special: normally an lhash entry will point to a single
+ * (somewhat) mutable object. In the case of strings:
+ *
+ * a) Instead of a single char, there is an array of chars, NUL-terminated.
+ * b) The string may have be immutable.
+ *
+ * So, they need their own declarations. Especially important for
+ * type-checking tools, such as Deputy.
+ *
+o * In practice, however, it appears to be hard to have a const
+ * string. For now, I'm settling for dealing with the fact it is a
+ * string at all.
+ */
+typedef char *OPENSSL_STRING;
+
+typedef const char *OPENSSL_CSTRING;
+
+/* Confusingly, LHASH_OF(STRING) deals with char ** throughout, but
+ * STACK_OF(STRING) is really more like STACK_OF(char), only, as
+ * mentioned above, instead of a single char each entry is a
+ * NUL-terminated array of chars. So, we have to implement STRING
+ * specially for STACK_OF. This is dealt with in the autogenerated
+ * macros below.
+ */
+
+DECLARE_SPECIAL_STACK_OF(OPENSSL_STRING, char)
+
+/* Similarly, we sometimes use a block of characters, NOT
+ * nul-terminated. These should also be distinguished from "normal"
+ * stacks. */
+
+typedef void *OPENSSL_BLOCK;
+DECLARE_SPECIAL_STACK_OF(OPENSSL_BLOCK, void)
+
 /* SKM_sk_... stack macros are internal to safestack.h:
  * never use them directly, use sk_<type>_... instead */
 #define SKM_sk_new(type, cmp) \
@@ -89,52 +138,56 @@ STACK_OF(type) \
 #define SKM_sk_new_null(type) \
        ((STACK_OF(type) *)sk_new_null())
 #define SKM_sk_free(type, st) \
-       sk_free(CHECKED_PTR_OF(STACK_OF(type), st))
+       sk_free(CHECKED_STACK_OF(type, st))
 #define SKM_sk_num(type, st) \
-       sk_num(CHECKED_PTR_OF(STACK_OF(type), st))
+       sk_num(CHECKED_STACK_OF(type, st))
 #define SKM_sk_value(type, st,i) \
-       ((type *)sk_value(CHECKED_PTR_OF(STACK_OF(type), st), i))
+       ((type *)sk_value(CHECKED_STACK_OF(type, st), i))
 #define SKM_sk_set(type, st,i,val) \
-       sk_set(CHECKED_PTR_OF(STACK_OF(type), st), i, CHECKED_PTR_OF(type, val))
+       sk_set(CHECKED_STACK_OF(type, st), i, CHECKED_PTR_OF(type, val))
 #define SKM_sk_zero(type, st) \
-       sk_zero(CHECKED_PTR_OF(STACK_OF(type), st))
-#define SKM_sk_push(type, st,val) \
-       sk_push(CHECKED_PTR_OF(STACK_OF(type), st), CHECKED_PTR_OF(type, val))
-#define SKM_sk_unshift(type, st,val) \
-       sk_unshift(CHECKED_PTR_OF(STACK_OF(type), st), CHECKED_PTR_OF(type, val))
-#define SKM_sk_find(type, st,val) \
-       sk_find(CHECKED_PTR_OF(STACK_OF(type), st), CHECKED_PTR_OF(type, val))
-#define SKM_sk_delete(type, st,i) \
-       (type *)sk_delete(CHECKED_PTR_OF(STACK_OF(type), st), i)
-#define SKM_sk_delete_ptr(type, st,ptr) \
-       (type *)sk_delete_ptr(CHECKED_PTR_OF(STACK_OF(type), st), CHECKED_PTR_OF(type, ptr))
-#define SKM_sk_insert(type, st,val,i) \
-       sk_insert(CHECKED_PTR_OF(STACK_OF(type), st), CHECKED_PTR_OF(type, val), i)
-#define SKM_sk_set_cmp_func(type, st,cmp) \
+       sk_zero(CHECKED_STACK_OF(type, st))
+#define SKM_sk_push(type, st, val) \
+       sk_push(CHECKED_STACK_OF(type, st), CHECKED_PTR_OF(type, val))
+#define SKM_sk_unshift(type, st, val) \
+       sk_unshift(CHECKED_STACK_OF(type, st), CHECKED_PTR_OF(type, val))
+#define SKM_sk_find(type, st, val) \
+       sk_find(CHECKED_STACK_OF(type, st), CHECKED_PTR_OF(type, val))
+#define SKM_sk_find_ex(type, st, val) \
+       sk_find_ex(CHECKED_STACK_OF(type, st), \
+                  CHECKED_PTR_OF(type, val))
+#define SKM_sk_delete(type, st, i) \
+       (type *)sk_delete(CHECKED_STACK_OF(type, st), i)
+#define SKM_sk_delete_ptr(type, st, ptr) \
+       (type *)sk_delete_ptr(CHECKED_STACK_OF(type, st), CHECKED_PTR_OF(type, ptr))
+#define SKM_sk_insert(type, st,val, i) \
+       sk_insert(CHECKED_STACK_OF(type, st), CHECKED_PTR_OF(type, val), i)
+#define SKM_sk_set_cmp_func(type, st, cmp) \
        ((int (*)(const type * const *,const type * const *)) \
-       sk_set_cmp_func(CHECKED_PTR_OF(STACK_OF(type), st), CHECKED_SK_CMP_FUNC(type, cmp)))
+       sk_set_cmp_func(CHECKED_STACK_OF(type, st), CHECKED_SK_CMP_FUNC(type, cmp)))
 #define SKM_sk_dup(type, st) \
-       (STACK_OF(type) *)sk_dup(CHECKED_PTR_OF(STACK_OF(type), st))
-#define SKM_sk_pop_free(type, st,free_func) \
-       sk_pop_free(CHECKED_PTR_OF(STACK_OF(type), st), CHECKED_SK_FREE_FUNC(type, free_func))
+       (STACK_OF(type) *)sk_dup(CHECKED_STACK_OF(type, st))
+#define SKM_sk_pop_free(type, st, free_func) \
+       sk_pop_free(CHECKED_STACK_OF(type, st), CHECKED_SK_FREE_FUNC(type, free_func))
 #define SKM_sk_shift(type, st) \
-       (type *)sk_shift(CHECKED_PTR_OF(STACK_OF(type), st))
+       (type *)sk_shift(CHECKED_STACK_OF(type, st))
 #define SKM_sk_pop(type, st) \
-       (type *)sk_pop(CHECKED_PTR_OF(STACK_OF(type), st))
+       (type *)sk_pop(CHECKED_STACK_OF(type, st))
 #define SKM_sk_sort(type, st) \
-       sk_sort(CHECKED_PTR_OF(STACK_OF(type), st))
+       sk_sort(CHECKED_STACK_OF(type, st))
 #define SKM_sk_is_sorted(type, st) \
-       sk_is_sorted(CHECKED_PTR_OF(STACK_OF(type), st))
+       sk_is_sorted(CHECKED_STACK_OF(type, st))
 
 #define        SKM_ASN1_SET_OF_d2i(type, st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
-       (STACK_OF(type) *)d2i_ASN1_SET(CHECKED_PTR_OF(STACK_OF(type)*, st), \
+  (STACK_OF(type) *)d2i_ASN1_SET( \
+                               (STACK_OF(OPENSSL_BLOCK) **)CHECKED_PTR_OF(STACK_OF(type)*, st), \
                                pp, length, \
                                CHECKED_D2I_OF(type, d2i_func), \
                                CHECKED_SK_FREE_FUNC(type, free_func), \
                                ex_tag, ex_class)
 
 #define        SKM_ASN1_SET_OF_i2d(type, st, pp, i2d_func, ex_tag, ex_class, is_set) \
-       i2d_ASN1_SET(CHECKED_PTR_OF(STACK_OF(type), st), pp, \
+  i2d_ASN1_SET((STACK_OF(OPENSSL_BLOCK) *)CHECKED_STACK_OF(type, st), pp, \
                                CHECKED_I2D_OF(type, i2d_func), \
                                ex_tag, ex_class, is_set)
 
@@ -151,72 +204,8 @@ STACK_OF(type) \
                                CHECKED_SK_FREE_FUNC(type, free_func), \
                                pass, passlen, oct, seq)
 
-#else
-
-#define STACK_OF(type) STACK
-#define PREDECLARE_STACK_OF(type) /* nada */
-#define DECLARE_STACK_OF(type)    /* nada */
-#define IMPLEMENT_STACK_OF(type)  /* nada */
-
-#define SKM_sk_new(type, cmp) \
-       sk_new((int (*)(const char * const *, const char * const *))(cmp))
-#define SKM_sk_new_null(type) \
-       sk_new_null()
-#define SKM_sk_free(type, st) \
-       sk_free(st)
-#define SKM_sk_num(type, st) \
-       sk_num(st)
-#define SKM_sk_value(type, st,i) \
-       ((type *)sk_value(st, i))
-#define SKM_sk_set(type, st,i,val) \
-       ((type *)sk_set(st, i,(char *)val))
-#define SKM_sk_zero(type, st) \
-       sk_zero(st)
-#define SKM_sk_push(type, st,val) \
-       sk_push(st, (char *)val)
-#define SKM_sk_unshift(type, st,val) \
-       sk_unshift(st, (char *)val)
-#define SKM_sk_find(type, st,val) \
-       sk_find(st, (char *)val)
-#define SKM_sk_delete(type, st,i) \
-       ((type *)sk_delete(st, i))
-#define SKM_sk_delete_ptr(type, st,ptr) \
-       ((type *)sk_delete_ptr(st,(char *)ptr))
-#define SKM_sk_insert(type, st,val,i) \
-       sk_insert(st, (char *)val, i)
-#define SKM_sk_set_cmp_func(type, st,cmp) \
-       ((int (*)(const type * const *,const type * const *)) \
-       sk_set_cmp_func(st, (int (*)(const char * const *, const char * const *))(cmp)))
-#define SKM_sk_dup(type, st) \
-       sk_dup(st)
-#define SKM_sk_pop_free(type, st,free_func) \
-       sk_pop_free(st, (void (*)(void *))free_func)
-#define SKM_sk_shift(type, st) \
-       ((type *)sk_shift(st))
-#define SKM_sk_pop(type, st) \
-       ((type *)sk_pop(st))
-#define SKM_sk_sort(type, st) \
-       sk_sort(st)
-#define SKM_sk_is_sorted(type, st) \
-       sk_is_sorted(st)
-
-#define        SKM_ASN1_SET_OF_d2i(type, st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
-       d2i_ASN1_SET(st,pp,length, (void *(*)(void ** ,const unsigned char ** ,long))d2i_func, (void (*)(void *))free_func, ex_tag,ex_class)
-#define        SKM_ASN1_SET_OF_i2d(type, st, pp, i2d_func, ex_tag, ex_class, is_set) \
-       i2d_ASN1_SET(st,pp,(int (*)(void *, unsigned char **))i2d_func,ex_tag,ex_class,is_set)
-
-#define        SKM_ASN1_seq_pack(type, st, i2d_func, buf, len) \
-       ASN1_seq_pack(st, (int (*)(void *, unsigned char **))i2d_func, buf, len)
-#define        SKM_ASN1_seq_unpack(type, buf, len, d2i_func, free_func) \
-       ASN1_seq_unpack(buf,len,(void *(*)(void **,const unsigned char **,long))d2i_func, (void(*)(void *))free_func)
-
-#define SKM_PKCS12_decrypt_d2i(type, algor, d2i_func, free_func, pass, passlen, oct, seq) \
-       ((STACK *)PKCS12_decrypt_d2i(algor,(char *(*)())d2i_func, (void(*)(void *))free_func,pass,passlen,oct,seq))
-
-#endif
-
 /* This block of defines is updated by util/mkstack.pl, please do not touch! */
-#define sk_ACCESS_DESCRIPTION_new(st) SKM_sk_new(ACCESS_DESCRIPTION, (st))
+#define sk_ACCESS_DESCRIPTION_new(cmp) SKM_sk_new(ACCESS_DESCRIPTION, (cmp))
 #define sk_ACCESS_DESCRIPTION_new_null() SKM_sk_new_null(ACCESS_DESCRIPTION)
 #define sk_ACCESS_DESCRIPTION_free(st) SKM_sk_free(ACCESS_DESCRIPTION, (st))
 #define sk_ACCESS_DESCRIPTION_num(st) SKM_sk_num(ACCESS_DESCRIPTION, (st))
@@ -238,7 +227,7 @@ STACK_OF(type) \
 #define sk_ACCESS_DESCRIPTION_sort(st) SKM_sk_sort(ACCESS_DESCRIPTION, (st))
 #define sk_ACCESS_DESCRIPTION_is_sorted(st) SKM_sk_is_sorted(ACCESS_DESCRIPTION, (st))
 
-#define sk_ASIdOrRange_new(st) SKM_sk_new(ASIdOrRange, (st))
+#define sk_ASIdOrRange_new(cmp) SKM_sk_new(ASIdOrRange, (cmp))
 #define sk_ASIdOrRange_new_null() SKM_sk_new_null(ASIdOrRange)
 #define sk_ASIdOrRange_free(st) SKM_sk_free(ASIdOrRange, (st))
 #define sk_ASIdOrRange_num(st) SKM_sk_num(ASIdOrRange, (st))
@@ -260,7 +249,7 @@ STACK_OF(type) \
 #define sk_ASIdOrRange_sort(st) SKM_sk_sort(ASIdOrRange, (st))
 #define sk_ASIdOrRange_is_sorted(st) SKM_sk_is_sorted(ASIdOrRange, (st))
 
-#define sk_ASN1_GENERALSTRING_new(st) SKM_sk_new(ASN1_GENERALSTRING, (st))
+#define sk_ASN1_GENERALSTRING_new(cmp) SKM_sk_new(ASN1_GENERALSTRING, (cmp))
 #define sk_ASN1_GENERALSTRING_new_null() SKM_sk_new_null(ASN1_GENERALSTRING)
 #define sk_ASN1_GENERALSTRING_free(st) SKM_sk_free(ASN1_GENERALSTRING, (st))
 #define sk_ASN1_GENERALSTRING_num(st) SKM_sk_num(ASN1_GENERALSTRING, (st))
@@ -282,7 +271,7 @@ STACK_OF(type) \
 #define sk_ASN1_GENERALSTRING_sort(st) SKM_sk_sort(ASN1_GENERALSTRING, (st))
 #define sk_ASN1_GENERALSTRING_is_sorted(st) SKM_sk_is_sorted(ASN1_GENERALSTRING, (st))
 
-#define sk_ASN1_INTEGER_new(st) SKM_sk_new(ASN1_INTEGER, (st))
+#define sk_ASN1_INTEGER_new(cmp) SKM_sk_new(ASN1_INTEGER, (cmp))
 #define sk_ASN1_INTEGER_new_null() SKM_sk_new_null(ASN1_INTEGER)
 #define sk_ASN1_INTEGER_free(st) SKM_sk_free(ASN1_INTEGER, (st))
 #define sk_ASN1_INTEGER_num(st) SKM_sk_num(ASN1_INTEGER, (st))
@@ -304,7 +293,7 @@ STACK_OF(type) \
 #define sk_ASN1_INTEGER_sort(st) SKM_sk_sort(ASN1_INTEGER, (st))
 #define sk_ASN1_INTEGER_is_sorted(st) SKM_sk_is_sorted(ASN1_INTEGER, (st))
 
-#define sk_ASN1_OBJECT_new(st) SKM_sk_new(ASN1_OBJECT, (st))
+#define sk_ASN1_OBJECT_new(cmp) SKM_sk_new(ASN1_OBJECT, (cmp))
 #define sk_ASN1_OBJECT_new_null() SKM_sk_new_null(ASN1_OBJECT)
 #define sk_ASN1_OBJECT_free(st) SKM_sk_free(ASN1_OBJECT, (st))
 #define sk_ASN1_OBJECT_num(st) SKM_sk_num(ASN1_OBJECT, (st))
@@ -326,7 +315,7 @@ STACK_OF(type) \
 #define sk_ASN1_OBJECT_sort(st) SKM_sk_sort(ASN1_OBJECT, (st))
 #define sk_ASN1_OBJECT_is_sorted(st) SKM_sk_is_sorted(ASN1_OBJECT, (st))
 
-#define sk_ASN1_STRING_TABLE_new(st) SKM_sk_new(ASN1_STRING_TABLE, (st))
+#define sk_ASN1_STRING_TABLE_new(cmp) SKM_sk_new(ASN1_STRING_TABLE, (cmp))
 #define sk_ASN1_STRING_TABLE_new_null() SKM_sk_new_null(ASN1_STRING_TABLE)
 #define sk_ASN1_STRING_TABLE_free(st) SKM_sk_free(ASN1_STRING_TABLE, (st))
 #define sk_ASN1_STRING_TABLE_num(st) SKM_sk_num(ASN1_STRING_TABLE, (st))
@@ -348,7 +337,7 @@ STACK_OF(type) \
 #define sk_ASN1_STRING_TABLE_sort(st) SKM_sk_sort(ASN1_STRING_TABLE, (st))
 #define sk_ASN1_STRING_TABLE_is_sorted(st) SKM_sk_is_sorted(ASN1_STRING_TABLE, (st))
 
-#define sk_ASN1_TYPE_new(st) SKM_sk_new(ASN1_TYPE, (st))
+#define sk_ASN1_TYPE_new(cmp) SKM_sk_new(ASN1_TYPE, (cmp))
 #define sk_ASN1_TYPE_new_null() SKM_sk_new_null(ASN1_TYPE)
 #define sk_ASN1_TYPE_free(st) SKM_sk_free(ASN1_TYPE, (st))
 #define sk_ASN1_TYPE_num(st) SKM_sk_num(ASN1_TYPE, (st))
@@ -370,7 +359,29 @@ STACK_OF(type) \
 #define sk_ASN1_TYPE_sort(st) SKM_sk_sort(ASN1_TYPE, (st))
 #define sk_ASN1_TYPE_is_sorted(st) SKM_sk_is_sorted(ASN1_TYPE, (st))
 
-#define sk_ASN1_VALUE_new(st) SKM_sk_new(ASN1_VALUE, (st))
+#define sk_ASN1_UTF8STRING_new(cmp) SKM_sk_new(ASN1_UTF8STRING, (cmp))
+#define sk_ASN1_UTF8STRING_new_null() SKM_sk_new_null(ASN1_UTF8STRING)
+#define sk_ASN1_UTF8STRING_free(st) SKM_sk_free(ASN1_UTF8STRING, (st))
+#define sk_ASN1_UTF8STRING_num(st) SKM_sk_num(ASN1_UTF8STRING, (st))
+#define sk_ASN1_UTF8STRING_value(st, i) SKM_sk_value(ASN1_UTF8STRING, (st), (i))
+#define sk_ASN1_UTF8STRING_set(st, i, val) SKM_sk_set(ASN1_UTF8STRING, (st), (i), (val))
+#define sk_ASN1_UTF8STRING_zero(st) SKM_sk_zero(ASN1_UTF8STRING, (st))
+#define sk_ASN1_UTF8STRING_push(st, val) SKM_sk_push(ASN1_UTF8STRING, (st), (val))
+#define sk_ASN1_UTF8STRING_unshift(st, val) SKM_sk_unshift(ASN1_UTF8STRING, (st), (val))
+#define sk_ASN1_UTF8STRING_find(st, val) SKM_sk_find(ASN1_UTF8STRING, (st), (val))
+#define sk_ASN1_UTF8STRING_find_ex(st, val) SKM_sk_find_ex(ASN1_UTF8STRING, (st), (val))
+#define sk_ASN1_UTF8STRING_delete(st, i) SKM_sk_delete(ASN1_UTF8STRING, (st), (i))
+#define sk_ASN1_UTF8STRING_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_UTF8STRING, (st), (ptr))
+#define sk_ASN1_UTF8STRING_insert(st, val, i) SKM_sk_insert(ASN1_UTF8STRING, (st), (val), (i))
+#define sk_ASN1_UTF8STRING_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_UTF8STRING, (st), (cmp))
+#define sk_ASN1_UTF8STRING_dup(st) SKM_sk_dup(ASN1_UTF8STRING, st)
+#define sk_ASN1_UTF8STRING_pop_free(st, free_func) SKM_sk_pop_free(ASN1_UTF8STRING, (st), (free_func))
+#define sk_ASN1_UTF8STRING_shift(st) SKM_sk_shift(ASN1_UTF8STRING, (st))
+#define sk_ASN1_UTF8STRING_pop(st) SKM_sk_pop(ASN1_UTF8STRING, (st))
+#define sk_ASN1_UTF8STRING_sort(st) SKM_sk_sort(ASN1_UTF8STRING, (st))
+#define sk_ASN1_UTF8STRING_is_sorted(st) SKM_sk_is_sorted(ASN1_UTF8STRING, (st))
+
+#define sk_ASN1_VALUE_new(cmp) SKM_sk_new(ASN1_VALUE, (cmp))
 #define sk_ASN1_VALUE_new_null() SKM_sk_new_null(ASN1_VALUE)
 #define sk_ASN1_VALUE_free(st) SKM_sk_free(ASN1_VALUE, (st))
 #define sk_ASN1_VALUE_num(st) SKM_sk_num(ASN1_VALUE, (st))
@@ -392,7 +403,7 @@ STACK_OF(type) \
 #define sk_ASN1_VALUE_sort(st) SKM_sk_sort(ASN1_VALUE, (st))
 #define sk_ASN1_VALUE_is_sorted(st) SKM_sk_is_sorted(ASN1_VALUE, (st))
 
-#define sk_BIO_new(st) SKM_sk_new(BIO, (st))
+#define sk_BIO_new(cmp) SKM_sk_new(BIO, (cmp))
 #define sk_BIO_new_null() SKM_sk_new_null(BIO)
 #define sk_BIO_free(st) SKM_sk_free(BIO, (st))
 #define sk_BIO_num(st) SKM_sk_num(BIO, (st))
@@ -414,7 +425,51 @@ STACK_OF(type) \
 #define sk_BIO_sort(st) SKM_sk_sort(BIO, (st))
 #define sk_BIO_is_sorted(st) SKM_sk_is_sorted(BIO, (st))
 
-#define sk_CMS_CertificateChoices_new(st) SKM_sk_new(CMS_CertificateChoices, (st))
+#define sk_BY_DIR_ENTRY_new(cmp) SKM_sk_new(BY_DIR_ENTRY, (cmp))
+#define sk_BY_DIR_ENTRY_new_null() SKM_sk_new_null(BY_DIR_ENTRY)
+#define sk_BY_DIR_ENTRY_free(st) SKM_sk_free(BY_DIR_ENTRY, (st))
+#define sk_BY_DIR_ENTRY_num(st) SKM_sk_num(BY_DIR_ENTRY, (st))
+#define sk_BY_DIR_ENTRY_value(st, i) SKM_sk_value(BY_DIR_ENTRY, (st), (i))
+#define sk_BY_DIR_ENTRY_set(st, i, val) SKM_sk_set(BY_DIR_ENTRY, (st), (i), (val))
+#define sk_BY_DIR_ENTRY_zero(st) SKM_sk_zero(BY_DIR_ENTRY, (st))
+#define sk_BY_DIR_ENTRY_push(st, val) SKM_sk_push(BY_DIR_ENTRY, (st), (val))
+#define sk_BY_DIR_ENTRY_unshift(st, val) SKM_sk_unshift(BY_DIR_ENTRY, (st), (val))
+#define sk_BY_DIR_ENTRY_find(st, val) SKM_sk_find(BY_DIR_ENTRY, (st), (val))
+#define sk_BY_DIR_ENTRY_find_ex(st, val) SKM_sk_find_ex(BY_DIR_ENTRY, (st), (val))
+#define sk_BY_DIR_ENTRY_delete(st, i) SKM_sk_delete(BY_DIR_ENTRY, (st), (i))
+#define sk_BY_DIR_ENTRY_delete_ptr(st, ptr) SKM_sk_delete_ptr(BY_DIR_ENTRY, (st), (ptr))
+#define sk_BY_DIR_ENTRY_insert(st, val, i) SKM_sk_insert(BY_DIR_ENTRY, (st), (val), (i))
+#define sk_BY_DIR_ENTRY_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(BY_DIR_ENTRY, (st), (cmp))
+#define sk_BY_DIR_ENTRY_dup(st) SKM_sk_dup(BY_DIR_ENTRY, st)
+#define sk_BY_DIR_ENTRY_pop_free(st, free_func) SKM_sk_pop_free(BY_DIR_ENTRY, (st), (free_func))
+#define sk_BY_DIR_ENTRY_shift(st) SKM_sk_shift(BY_DIR_ENTRY, (st))
+#define sk_BY_DIR_ENTRY_pop(st) SKM_sk_pop(BY_DIR_ENTRY, (st))
+#define sk_BY_DIR_ENTRY_sort(st) SKM_sk_sort(BY_DIR_ENTRY, (st))
+#define sk_BY_DIR_ENTRY_is_sorted(st) SKM_sk_is_sorted(BY_DIR_ENTRY, (st))
+
+#define sk_BY_DIR_HASH_new(cmp) SKM_sk_new(BY_DIR_HASH, (cmp))
+#define sk_BY_DIR_HASH_new_null() SKM_sk_new_null(BY_DIR_HASH)
+#define sk_BY_DIR_HASH_free(st) SKM_sk_free(BY_DIR_HASH, (st))
+#define sk_BY_DIR_HASH_num(st) SKM_sk_num(BY_DIR_HASH, (st))
+#define sk_BY_DIR_HASH_value(st, i) SKM_sk_value(BY_DIR_HASH, (st), (i))
+#define sk_BY_DIR_HASH_set(st, i, val) SKM_sk_set(BY_DIR_HASH, (st), (i), (val))
+#define sk_BY_DIR_HASH_zero(st) SKM_sk_zero(BY_DIR_HASH, (st))
+#define sk_BY_DIR_HASH_push(st, val) SKM_sk_push(BY_DIR_HASH, (st), (val))
+#define sk_BY_DIR_HASH_unshift(st, val) SKM_sk_unshift(BY_DIR_HASH, (st), (val))
+#define sk_BY_DIR_HASH_find(st, val) SKM_sk_find(BY_DIR_HASH, (st), (val))
+#define sk_BY_DIR_HASH_find_ex(st, val) SKM_sk_find_ex(BY_DIR_HASH, (st), (val))
+#define sk_BY_DIR_HASH_delete(st, i) SKM_sk_delete(BY_DIR_HASH, (st), (i))
+#define sk_BY_DIR_HASH_delete_ptr(st, ptr) SKM_sk_delete_ptr(BY_DIR_HASH, (st), (ptr))
+#define sk_BY_DIR_HASH_insert(st, val, i) SKM_sk_insert(BY_DIR_HASH, (st), (val), (i))
+#define sk_BY_DIR_HASH_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(BY_DIR_HASH, (st), (cmp))
+#define sk_BY_DIR_HASH_dup(st) SKM_sk_dup(BY_DIR_HASH, st)
+#define sk_BY_DIR_HASH_pop_free(st, free_func) SKM_sk_pop_free(BY_DIR_HASH, (st), (free_func))
+#define sk_BY_DIR_HASH_shift(st) SKM_sk_shift(BY_DIR_HASH, (st))
+#define sk_BY_DIR_HASH_pop(st) SKM_sk_pop(BY_DIR_HASH, (st))
+#define sk_BY_DIR_HASH_sort(st) SKM_sk_sort(BY_DIR_HASH, (st))
+#define sk_BY_DIR_HASH_is_sorted(st) SKM_sk_is_sorted(BY_DIR_HASH, (st))
+
+#define sk_CMS_CertificateChoices_new(cmp) SKM_sk_new(CMS_CertificateChoices, (cmp))
 #define sk_CMS_CertificateChoices_new_null() SKM_sk_new_null(CMS_CertificateChoices)
 #define sk_CMS_CertificateChoices_free(st) SKM_sk_free(CMS_CertificateChoices, (st))
 #define sk_CMS_CertificateChoices_num(st) SKM_sk_num(CMS_CertificateChoices, (st))
@@ -436,7 +491,7 @@ STACK_OF(type) \
 #define sk_CMS_CertificateChoices_sort(st) SKM_sk_sort(CMS_CertificateChoices, (st))
 #define sk_CMS_CertificateChoices_is_sorted(st) SKM_sk_is_sorted(CMS_CertificateChoices, (st))
 
-#define sk_CMS_RecipientInfo_new(st) SKM_sk_new(CMS_RecipientInfo, (st))
+#define sk_CMS_RecipientInfo_new(cmp) SKM_sk_new(CMS_RecipientInfo, (cmp))
 #define sk_CMS_RecipientInfo_new_null() SKM_sk_new_null(CMS_RecipientInfo)
 #define sk_CMS_RecipientInfo_free(st) SKM_sk_free(CMS_RecipientInfo, (st))
 #define sk_CMS_RecipientInfo_num(st) SKM_sk_num(CMS_RecipientInfo, (st))
@@ -458,7 +513,7 @@ STACK_OF(type) \
 #define sk_CMS_RecipientInfo_sort(st) SKM_sk_sort(CMS_RecipientInfo, (st))
 #define sk_CMS_RecipientInfo_is_sorted(st) SKM_sk_is_sorted(CMS_RecipientInfo, (st))
 
-#define sk_CMS_RevocationInfoChoice_new(st) SKM_sk_new(CMS_RevocationInfoChoice, (st))
+#define sk_CMS_RevocationInfoChoice_new(cmp) SKM_sk_new(CMS_RevocationInfoChoice, (cmp))
 #define sk_CMS_RevocationInfoChoice_new_null() SKM_sk_new_null(CMS_RevocationInfoChoice)
 #define sk_CMS_RevocationInfoChoice_free(st) SKM_sk_free(CMS_RevocationInfoChoice, (st))
 #define sk_CMS_RevocationInfoChoice_num(st) SKM_sk_num(CMS_RevocationInfoChoice, (st))
@@ -480,7 +535,7 @@ STACK_OF(type) \
 #define sk_CMS_RevocationInfoChoice_sort(st) SKM_sk_sort(CMS_RevocationInfoChoice, (st))
 #define sk_CMS_RevocationInfoChoice_is_sorted(st) SKM_sk_is_sorted(CMS_RevocationInfoChoice, (st))
 
-#define sk_CMS_SignerInfo_new(st) SKM_sk_new(CMS_SignerInfo, (st))
+#define sk_CMS_SignerInfo_new(cmp) SKM_sk_new(CMS_SignerInfo, (cmp))
 #define sk_CMS_SignerInfo_new_null() SKM_sk_new_null(CMS_SignerInfo)
 #define sk_CMS_SignerInfo_free(st) SKM_sk_free(CMS_SignerInfo, (st))
 #define sk_CMS_SignerInfo_num(st) SKM_sk_num(CMS_SignerInfo, (st))
@@ -502,7 +557,7 @@ STACK_OF(type) \
 #define sk_CMS_SignerInfo_sort(st) SKM_sk_sort(CMS_SignerInfo, (st))
 #define sk_CMS_SignerInfo_is_sorted(st) SKM_sk_is_sorted(CMS_SignerInfo, (st))
 
-#define sk_CONF_IMODULE_new(st) SKM_sk_new(CONF_IMODULE, (st))
+#define sk_CONF_IMODULE_new(cmp) SKM_sk_new(CONF_IMODULE, (cmp))
 #define sk_CONF_IMODULE_new_null() SKM_sk_new_null(CONF_IMODULE)
 #define sk_CONF_IMODULE_free(st) SKM_sk_free(CONF_IMODULE, (st))
 #define sk_CONF_IMODULE_num(st) SKM_sk_num(CONF_IMODULE, (st))
@@ -524,7 +579,7 @@ STACK_OF(type) \
 #define sk_CONF_IMODULE_sort(st) SKM_sk_sort(CONF_IMODULE, (st))
 #define sk_CONF_IMODULE_is_sorted(st) SKM_sk_is_sorted(CONF_IMODULE, (st))
 
-#define sk_CONF_MODULE_new(st) SKM_sk_new(CONF_MODULE, (st))
+#define sk_CONF_MODULE_new(cmp) SKM_sk_new(CONF_MODULE, (cmp))
 #define sk_CONF_MODULE_new_null() SKM_sk_new_null(CONF_MODULE)
 #define sk_CONF_MODULE_free(st) SKM_sk_free(CONF_MODULE, (st))
 #define sk_CONF_MODULE_num(st) SKM_sk_num(CONF_MODULE, (st))
@@ -546,7 +601,7 @@ STACK_OF(type) \
 #define sk_CONF_MODULE_sort(st) SKM_sk_sort(CONF_MODULE, (st))
 #define sk_CONF_MODULE_is_sorted(st) SKM_sk_is_sorted(CONF_MODULE, (st))
 
-#define sk_CONF_VALUE_new(st) SKM_sk_new(CONF_VALUE, (st))
+#define sk_CONF_VALUE_new(cmp) SKM_sk_new(CONF_VALUE, (cmp))
 #define sk_CONF_VALUE_new_null() SKM_sk_new_null(CONF_VALUE)
 #define sk_CONF_VALUE_free(st) SKM_sk_free(CONF_VALUE, (st))
 #define sk_CONF_VALUE_num(st) SKM_sk_num(CONF_VALUE, (st))
@@ -568,7 +623,7 @@ STACK_OF(type) \
 #define sk_CONF_VALUE_sort(st) SKM_sk_sort(CONF_VALUE, (st))
 #define sk_CONF_VALUE_is_sorted(st) SKM_sk_is_sorted(CONF_VALUE, (st))
 
-#define sk_CRYPTO_EX_DATA_FUNCS_new(st) SKM_sk_new(CRYPTO_EX_DATA_FUNCS, (st))
+#define sk_CRYPTO_EX_DATA_FUNCS_new(cmp) SKM_sk_new(CRYPTO_EX_DATA_FUNCS, (cmp))
 #define sk_CRYPTO_EX_DATA_FUNCS_new_null() SKM_sk_new_null(CRYPTO_EX_DATA_FUNCS)
 #define sk_CRYPTO_EX_DATA_FUNCS_free(st) SKM_sk_free(CRYPTO_EX_DATA_FUNCS, (st))
 #define sk_CRYPTO_EX_DATA_FUNCS_num(st) SKM_sk_num(CRYPTO_EX_DATA_FUNCS, (st))
@@ -590,7 +645,7 @@ STACK_OF(type) \
 #define sk_CRYPTO_EX_DATA_FUNCS_sort(st) SKM_sk_sort(CRYPTO_EX_DATA_FUNCS, (st))
 #define sk_CRYPTO_EX_DATA_FUNCS_is_sorted(st) SKM_sk_is_sorted(CRYPTO_EX_DATA_FUNCS, (st))
 
-#define sk_CRYPTO_dynlock_new(st) SKM_sk_new(CRYPTO_dynlock, (st))
+#define sk_CRYPTO_dynlock_new(cmp) SKM_sk_new(CRYPTO_dynlock, (cmp))
 #define sk_CRYPTO_dynlock_new_null() SKM_sk_new_null(CRYPTO_dynlock)
 #define sk_CRYPTO_dynlock_free(st) SKM_sk_free(CRYPTO_dynlock, (st))
 #define sk_CRYPTO_dynlock_num(st) SKM_sk_num(CRYPTO_dynlock, (st))
@@ -612,7 +667,7 @@ STACK_OF(type) \
 #define sk_CRYPTO_dynlock_sort(st) SKM_sk_sort(CRYPTO_dynlock, (st))
 #define sk_CRYPTO_dynlock_is_sorted(st) SKM_sk_is_sorted(CRYPTO_dynlock, (st))
 
-#define sk_DIST_POINT_new(st) SKM_sk_new(DIST_POINT, (st))
+#define sk_DIST_POINT_new(cmp) SKM_sk_new(DIST_POINT, (cmp))
 #define sk_DIST_POINT_new_null() SKM_sk_new_null(DIST_POINT)
 #define sk_DIST_POINT_free(st) SKM_sk_free(DIST_POINT, (st))
 #define sk_DIST_POINT_num(st) SKM_sk_num(DIST_POINT, (st))
@@ -634,7 +689,7 @@ STACK_OF(type) \
 #define sk_DIST_POINT_sort(st) SKM_sk_sort(DIST_POINT, (st))
 #define sk_DIST_POINT_is_sorted(st) SKM_sk_is_sorted(DIST_POINT, (st))
 
-#define sk_ENGINE_new(st) SKM_sk_new(ENGINE, (st))
+#define sk_ENGINE_new(cmp) SKM_sk_new(ENGINE, (cmp))
 #define sk_ENGINE_new_null() SKM_sk_new_null(ENGINE)
 #define sk_ENGINE_free(st) SKM_sk_free(ENGINE, (st))
 #define sk_ENGINE_num(st) SKM_sk_num(ENGINE, (st))
@@ -656,7 +711,7 @@ STACK_OF(type) \
 #define sk_ENGINE_sort(st) SKM_sk_sort(ENGINE, (st))
 #define sk_ENGINE_is_sorted(st) SKM_sk_is_sorted(ENGINE, (st))
 
-#define sk_ENGINE_CLEANUP_ITEM_new(st) SKM_sk_new(ENGINE_CLEANUP_ITEM, (st))
+#define sk_ENGINE_CLEANUP_ITEM_new(cmp) SKM_sk_new(ENGINE_CLEANUP_ITEM, (cmp))
 #define sk_ENGINE_CLEANUP_ITEM_new_null() SKM_sk_new_null(ENGINE_CLEANUP_ITEM)
 #define sk_ENGINE_CLEANUP_ITEM_free(st) SKM_sk_free(ENGINE_CLEANUP_ITEM, (st))
 #define sk_ENGINE_CLEANUP_ITEM_num(st) SKM_sk_num(ENGINE_CLEANUP_ITEM, (st))
@@ -678,7 +733,117 @@ STACK_OF(type) \
 #define sk_ENGINE_CLEANUP_ITEM_sort(st) SKM_sk_sort(ENGINE_CLEANUP_ITEM, (st))
 #define sk_ENGINE_CLEANUP_ITEM_is_sorted(st) SKM_sk_is_sorted(ENGINE_CLEANUP_ITEM, (st))
 
-#define sk_GENERAL_NAME_new(st) SKM_sk_new(GENERAL_NAME, (st))
+#define sk_ESS_CERT_ID_new(cmp) SKM_sk_new(ESS_CERT_ID, (cmp))
+#define sk_ESS_CERT_ID_new_null() SKM_sk_new_null(ESS_CERT_ID)
+#define sk_ESS_CERT_ID_free(st) SKM_sk_free(ESS_CERT_ID, (st))
+#define sk_ESS_CERT_ID_num(st) SKM_sk_num(ESS_CERT_ID, (st))
+#define sk_ESS_CERT_ID_value(st, i) SKM_sk_value(ESS_CERT_ID, (st), (i))
+#define sk_ESS_CERT_ID_set(st, i, val) SKM_sk_set(ESS_CERT_ID, (st), (i), (val))
+#define sk_ESS_CERT_ID_zero(st) SKM_sk_zero(ESS_CERT_ID, (st))
+#define sk_ESS_CERT_ID_push(st, val) SKM_sk_push(ESS_CERT_ID, (st), (val))
+#define sk_ESS_CERT_ID_unshift(st, val) SKM_sk_unshift(ESS_CERT_ID, (st), (val))
+#define sk_ESS_CERT_ID_find(st, val) SKM_sk_find(ESS_CERT_ID, (st), (val))
+#define sk_ESS_CERT_ID_find_ex(st, val) SKM_sk_find_ex(ESS_CERT_ID, (st), (val))
+#define sk_ESS_CERT_ID_delete(st, i) SKM_sk_delete(ESS_CERT_ID, (st), (i))
+#define sk_ESS_CERT_ID_delete_ptr(st, ptr) SKM_sk_delete_ptr(ESS_CERT_ID, (st), (ptr))
+#define sk_ESS_CERT_ID_insert(st, val, i) SKM_sk_insert(ESS_CERT_ID, (st), (val), (i))
+#define sk_ESS_CERT_ID_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ESS_CERT_ID, (st), (cmp))
+#define sk_ESS_CERT_ID_dup(st) SKM_sk_dup(ESS_CERT_ID, st)
+#define sk_ESS_CERT_ID_pop_free(st, free_func) SKM_sk_pop_free(ESS_CERT_ID, (st), (free_func))
+#define sk_ESS_CERT_ID_shift(st) SKM_sk_shift(ESS_CERT_ID, (st))
+#define sk_ESS_CERT_ID_pop(st) SKM_sk_pop(ESS_CERT_ID, (st))
+#define sk_ESS_CERT_ID_sort(st) SKM_sk_sort(ESS_CERT_ID, (st))
+#define sk_ESS_CERT_ID_is_sorted(st) SKM_sk_is_sorted(ESS_CERT_ID, (st))
+
+#define sk_EVP_MD_new(cmp) SKM_sk_new(EVP_MD, (cmp))
+#define sk_EVP_MD_new_null() SKM_sk_new_null(EVP_MD)
+#define sk_EVP_MD_free(st) SKM_sk_free(EVP_MD, (st))
+#define sk_EVP_MD_num(st) SKM_sk_num(EVP_MD, (st))
+#define sk_EVP_MD_value(st, i) SKM_sk_value(EVP_MD, (st), (i))
+#define sk_EVP_MD_set(st, i, val) SKM_sk_set(EVP_MD, (st), (i), (val))
+#define sk_EVP_MD_zero(st) SKM_sk_zero(EVP_MD, (st))
+#define sk_EVP_MD_push(st, val) SKM_sk_push(EVP_MD, (st), (val))
+#define sk_EVP_MD_unshift(st, val) SKM_sk_unshift(EVP_MD, (st), (val))
+#define sk_EVP_MD_find(st, val) SKM_sk_find(EVP_MD, (st), (val))
+#define sk_EVP_MD_find_ex(st, val) SKM_sk_find_ex(EVP_MD, (st), (val))
+#define sk_EVP_MD_delete(st, i) SKM_sk_delete(EVP_MD, (st), (i))
+#define sk_EVP_MD_delete_ptr(st, ptr) SKM_sk_delete_ptr(EVP_MD, (st), (ptr))
+#define sk_EVP_MD_insert(st, val, i) SKM_sk_insert(EVP_MD, (st), (val), (i))
+#define sk_EVP_MD_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(EVP_MD, (st), (cmp))
+#define sk_EVP_MD_dup(st) SKM_sk_dup(EVP_MD, st)
+#define sk_EVP_MD_pop_free(st, free_func) SKM_sk_pop_free(EVP_MD, (st), (free_func))
+#define sk_EVP_MD_shift(st) SKM_sk_shift(EVP_MD, (st))
+#define sk_EVP_MD_pop(st) SKM_sk_pop(EVP_MD, (st))
+#define sk_EVP_MD_sort(st) SKM_sk_sort(EVP_MD, (st))
+#define sk_EVP_MD_is_sorted(st) SKM_sk_is_sorted(EVP_MD, (st))
+
+#define sk_EVP_PBE_CTL_new(cmp) SKM_sk_new(EVP_PBE_CTL, (cmp))
+#define sk_EVP_PBE_CTL_new_null() SKM_sk_new_null(EVP_PBE_CTL)
+#define sk_EVP_PBE_CTL_free(st) SKM_sk_free(EVP_PBE_CTL, (st))
+#define sk_EVP_PBE_CTL_num(st) SKM_sk_num(EVP_PBE_CTL, (st))
+#define sk_EVP_PBE_CTL_value(st, i) SKM_sk_value(EVP_PBE_CTL, (st), (i))
+#define sk_EVP_PBE_CTL_set(st, i, val) SKM_sk_set(EVP_PBE_CTL, (st), (i), (val))
+#define sk_EVP_PBE_CTL_zero(st) SKM_sk_zero(EVP_PBE_CTL, (st))
+#define sk_EVP_PBE_CTL_push(st, val) SKM_sk_push(EVP_PBE_CTL, (st), (val))
+#define sk_EVP_PBE_CTL_unshift(st, val) SKM_sk_unshift(EVP_PBE_CTL, (st), (val))
+#define sk_EVP_PBE_CTL_find(st, val) SKM_sk_find(EVP_PBE_CTL, (st), (val))
+#define sk_EVP_PBE_CTL_find_ex(st, val) SKM_sk_find_ex(EVP_PBE_CTL, (st), (val))
+#define sk_EVP_PBE_CTL_delete(st, i) SKM_sk_delete(EVP_PBE_CTL, (st), (i))
+#define sk_EVP_PBE_CTL_delete_ptr(st, ptr) SKM_sk_delete_ptr(EVP_PBE_CTL, (st), (ptr))
+#define sk_EVP_PBE_CTL_insert(st, val, i) SKM_sk_insert(EVP_PBE_CTL, (st), (val), (i))
+#define sk_EVP_PBE_CTL_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(EVP_PBE_CTL, (st), (cmp))
+#define sk_EVP_PBE_CTL_dup(st) SKM_sk_dup(EVP_PBE_CTL, st)
+#define sk_EVP_PBE_CTL_pop_free(st, free_func) SKM_sk_pop_free(EVP_PBE_CTL, (st), (free_func))
+#define sk_EVP_PBE_CTL_shift(st) SKM_sk_shift(EVP_PBE_CTL, (st))
+#define sk_EVP_PBE_CTL_pop(st) SKM_sk_pop(EVP_PBE_CTL, (st))
+#define sk_EVP_PBE_CTL_sort(st) SKM_sk_sort(EVP_PBE_CTL, (st))
+#define sk_EVP_PBE_CTL_is_sorted(st) SKM_sk_is_sorted(EVP_PBE_CTL, (st))
+
+#define sk_EVP_PKEY_ASN1_METHOD_new(cmp) SKM_sk_new(EVP_PKEY_ASN1_METHOD, (cmp))
+#define sk_EVP_PKEY_ASN1_METHOD_new_null() SKM_sk_new_null(EVP_PKEY_ASN1_METHOD)
+#define sk_EVP_PKEY_ASN1_METHOD_free(st) SKM_sk_free(EVP_PKEY_ASN1_METHOD, (st))
+#define sk_EVP_PKEY_ASN1_METHOD_num(st) SKM_sk_num(EVP_PKEY_ASN1_METHOD, (st))
+#define sk_EVP_PKEY_ASN1_METHOD_value(st, i) SKM_sk_value(EVP_PKEY_ASN1_METHOD, (st), (i))
+#define sk_EVP_PKEY_ASN1_METHOD_set(st, i, val) SKM_sk_set(EVP_PKEY_ASN1_METHOD, (st), (i), (val))
+#define sk_EVP_PKEY_ASN1_METHOD_zero(st) SKM_sk_zero(EVP_PKEY_ASN1_METHOD, (st))
+#define sk_EVP_PKEY_ASN1_METHOD_push(st, val) SKM_sk_push(EVP_PKEY_ASN1_METHOD, (st), (val))
+#define sk_EVP_PKEY_ASN1_METHOD_unshift(st, val) SKM_sk_unshift(EVP_PKEY_ASN1_METHOD, (st), (val))
+#define sk_EVP_PKEY_ASN1_METHOD_find(st, val) SKM_sk_find(EVP_PKEY_ASN1_METHOD, (st), (val))
+#define sk_EVP_PKEY_ASN1_METHOD_find_ex(st, val) SKM_sk_find_ex(EVP_PKEY_ASN1_METHOD, (st), (val))
+#define sk_EVP_PKEY_ASN1_METHOD_delete(st, i) SKM_sk_delete(EVP_PKEY_ASN1_METHOD, (st), (i))
+#define sk_EVP_PKEY_ASN1_METHOD_delete_ptr(st, ptr) SKM_sk_delete_ptr(EVP_PKEY_ASN1_METHOD, (st), (ptr))
+#define sk_EVP_PKEY_ASN1_METHOD_insert(st, val, i) SKM_sk_insert(EVP_PKEY_ASN1_METHOD, (st), (val), (i))
+#define sk_EVP_PKEY_ASN1_METHOD_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(EVP_PKEY_ASN1_METHOD, (st), (cmp))
+#define sk_EVP_PKEY_ASN1_METHOD_dup(st) SKM_sk_dup(EVP_PKEY_ASN1_METHOD, st)
+#define sk_EVP_PKEY_ASN1_METHOD_pop_free(st, free_func) SKM_sk_pop_free(EVP_PKEY_ASN1_METHOD, (st), (free_func))
+#define sk_EVP_PKEY_ASN1_METHOD_shift(st) SKM_sk_shift(EVP_PKEY_ASN1_METHOD, (st))
+#define sk_EVP_PKEY_ASN1_METHOD_pop(st) SKM_sk_pop(EVP_PKEY_ASN1_METHOD, (st))
+#define sk_EVP_PKEY_ASN1_METHOD_sort(st) SKM_sk_sort(EVP_PKEY_ASN1_METHOD, (st))
+#define sk_EVP_PKEY_ASN1_METHOD_is_sorted(st) SKM_sk_is_sorted(EVP_PKEY_ASN1_METHOD, (st))
+
+#define sk_EVP_PKEY_METHOD_new(cmp) SKM_sk_new(EVP_PKEY_METHOD, (cmp))
+#define sk_EVP_PKEY_METHOD_new_null() SKM_sk_new_null(EVP_PKEY_METHOD)
+#define sk_EVP_PKEY_METHOD_free(st) SKM_sk_free(EVP_PKEY_METHOD, (st))
+#define sk_EVP_PKEY_METHOD_num(st) SKM_sk_num(EVP_PKEY_METHOD, (st))
+#define sk_EVP_PKEY_METHOD_value(st, i) SKM_sk_value(EVP_PKEY_METHOD, (st), (i))
+#define sk_EVP_PKEY_METHOD_set(st, i, val) SKM_sk_set(EVP_PKEY_METHOD, (st), (i), (val))
+#define sk_EVP_PKEY_METHOD_zero(st) SKM_sk_zero(EVP_PKEY_METHOD, (st))
+#define sk_EVP_PKEY_METHOD_push(st, val) SKM_sk_push(EVP_PKEY_METHOD, (st), (val))
+#define sk_EVP_PKEY_METHOD_unshift(st, val) SKM_sk_unshift(EVP_PKEY_METHOD, (st), (val))
+#define sk_EVP_PKEY_METHOD_find(st, val) SKM_sk_find(EVP_PKEY_METHOD, (st), (val))
+#define sk_EVP_PKEY_METHOD_find_ex(st, val) SKM_sk_find_ex(EVP_PKEY_METHOD, (st), (val))
+#define sk_EVP_PKEY_METHOD_delete(st, i) SKM_sk_delete(EVP_PKEY_METHOD, (st), (i))
+#define sk_EVP_PKEY_METHOD_delete_ptr(st, ptr) SKM_sk_delete_ptr(EVP_PKEY_METHOD, (st), (ptr))
+#define sk_EVP_PKEY_METHOD_insert(st, val, i) SKM_sk_insert(EVP_PKEY_METHOD, (st), (val), (i))
+#define sk_EVP_PKEY_METHOD_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(EVP_PKEY_METHOD, (st), (cmp))
+#define sk_EVP_PKEY_METHOD_dup(st) SKM_sk_dup(EVP_PKEY_METHOD, st)
+#define sk_EVP_PKEY_METHOD_pop_free(st, free_func) SKM_sk_pop_free(EVP_PKEY_METHOD, (st), (free_func))
+#define sk_EVP_PKEY_METHOD_shift(st) SKM_sk_shift(EVP_PKEY_METHOD, (st))
+#define sk_EVP_PKEY_METHOD_pop(st) SKM_sk_pop(EVP_PKEY_METHOD, (st))
+#define sk_EVP_PKEY_METHOD_sort(st) SKM_sk_sort(EVP_PKEY_METHOD, (st))
+#define sk_EVP_PKEY_METHOD_is_sorted(st) SKM_sk_is_sorted(EVP_PKEY_METHOD, (st))
+
+#define sk_GENERAL_NAME_new(cmp) SKM_sk_new(GENERAL_NAME, (cmp))
 #define sk_GENERAL_NAME_new_null() SKM_sk_new_null(GENERAL_NAME)
 #define sk_GENERAL_NAME_free(st) SKM_sk_free(GENERAL_NAME, (st))
 #define sk_GENERAL_NAME_num(st) SKM_sk_num(GENERAL_NAME, (st))
@@ -700,7 +865,7 @@ STACK_OF(type) \
 #define sk_GENERAL_NAME_sort(st) SKM_sk_sort(GENERAL_NAME, (st))
 #define sk_GENERAL_NAME_is_sorted(st) SKM_sk_is_sorted(GENERAL_NAME, (st))
 
-#define sk_GENERAL_NAMES_new(st) SKM_sk_new(GENERAL_NAMES, (st))
+#define sk_GENERAL_NAMES_new(cmp) SKM_sk_new(GENERAL_NAMES, (cmp))
 #define sk_GENERAL_NAMES_new_null() SKM_sk_new_null(GENERAL_NAMES)
 #define sk_GENERAL_NAMES_free(st) SKM_sk_free(GENERAL_NAMES, (st))
 #define sk_GENERAL_NAMES_num(st) SKM_sk_num(GENERAL_NAMES, (st))
@@ -722,7 +887,7 @@ STACK_OF(type) \
 #define sk_GENERAL_NAMES_sort(st) SKM_sk_sort(GENERAL_NAMES, (st))
 #define sk_GENERAL_NAMES_is_sorted(st) SKM_sk_is_sorted(GENERAL_NAMES, (st))
 
-#define sk_GENERAL_SUBTREE_new(st) SKM_sk_new(GENERAL_SUBTREE, (st))
+#define sk_GENERAL_SUBTREE_new(cmp) SKM_sk_new(GENERAL_SUBTREE, (cmp))
 #define sk_GENERAL_SUBTREE_new_null() SKM_sk_new_null(GENERAL_SUBTREE)
 #define sk_GENERAL_SUBTREE_free(st) SKM_sk_free(GENERAL_SUBTREE, (st))
 #define sk_GENERAL_SUBTREE_num(st) SKM_sk_num(GENERAL_SUBTREE, (st))
@@ -744,7 +909,7 @@ STACK_OF(type) \
 #define sk_GENERAL_SUBTREE_sort(st) SKM_sk_sort(GENERAL_SUBTREE, (st))
 #define sk_GENERAL_SUBTREE_is_sorted(st) SKM_sk_is_sorted(GENERAL_SUBTREE, (st))
 
-#define sk_IPAddressFamily_new(st) SKM_sk_new(IPAddressFamily, (st))
+#define sk_IPAddressFamily_new(cmp) SKM_sk_new(IPAddressFamily, (cmp))
 #define sk_IPAddressFamily_new_null() SKM_sk_new_null(IPAddressFamily)
 #define sk_IPAddressFamily_free(st) SKM_sk_free(IPAddressFamily, (st))
 #define sk_IPAddressFamily_num(st) SKM_sk_num(IPAddressFamily, (st))
@@ -766,7 +931,7 @@ STACK_OF(type) \
 #define sk_IPAddressFamily_sort(st) SKM_sk_sort(IPAddressFamily, (st))
 #define sk_IPAddressFamily_is_sorted(st) SKM_sk_is_sorted(IPAddressFamily, (st))
 
-#define sk_IPAddressOrRange_new(st) SKM_sk_new(IPAddressOrRange, (st))
+#define sk_IPAddressOrRange_new(cmp) SKM_sk_new(IPAddressOrRange, (cmp))
 #define sk_IPAddressOrRange_new_null() SKM_sk_new_null(IPAddressOrRange)
 #define sk_IPAddressOrRange_free(st) SKM_sk_free(IPAddressOrRange, (st))
 #define sk_IPAddressOrRange_num(st) SKM_sk_num(IPAddressOrRange, (st))
@@ -788,7 +953,7 @@ STACK_OF(type) \
 #define sk_IPAddressOrRange_sort(st) SKM_sk_sort(IPAddressOrRange, (st))
 #define sk_IPAddressOrRange_is_sorted(st) SKM_sk_is_sorted(IPAddressOrRange, (st))
 
-#define sk_KRB5_APREQBODY_new(st) SKM_sk_new(KRB5_APREQBODY, (st))
+#define sk_KRB5_APREQBODY_new(cmp) SKM_sk_new(KRB5_APREQBODY, (cmp))
 #define sk_KRB5_APREQBODY_new_null() SKM_sk_new_null(KRB5_APREQBODY)
 #define sk_KRB5_APREQBODY_free(st) SKM_sk_free(KRB5_APREQBODY, (st))
 #define sk_KRB5_APREQBODY_num(st) SKM_sk_num(KRB5_APREQBODY, (st))
@@ -810,7 +975,7 @@ STACK_OF(type) \
 #define sk_KRB5_APREQBODY_sort(st) SKM_sk_sort(KRB5_APREQBODY, (st))
 #define sk_KRB5_APREQBODY_is_sorted(st) SKM_sk_is_sorted(KRB5_APREQBODY, (st))
 
-#define sk_KRB5_AUTHDATA_new(st) SKM_sk_new(KRB5_AUTHDATA, (st))
+#define sk_KRB5_AUTHDATA_new(cmp) SKM_sk_new(KRB5_AUTHDATA, (cmp))
 #define sk_KRB5_AUTHDATA_new_null() SKM_sk_new_null(KRB5_AUTHDATA)
 #define sk_KRB5_AUTHDATA_free(st) SKM_sk_free(KRB5_AUTHDATA, (st))
 #define sk_KRB5_AUTHDATA_num(st) SKM_sk_num(KRB5_AUTHDATA, (st))
@@ -832,7 +997,7 @@ STACK_OF(type) \
 #define sk_KRB5_AUTHDATA_sort(st) SKM_sk_sort(KRB5_AUTHDATA, (st))
 #define sk_KRB5_AUTHDATA_is_sorted(st) SKM_sk_is_sorted(KRB5_AUTHDATA, (st))
 
-#define sk_KRB5_AUTHENTBODY_new(st) SKM_sk_new(KRB5_AUTHENTBODY, (st))
+#define sk_KRB5_AUTHENTBODY_new(cmp) SKM_sk_new(KRB5_AUTHENTBODY, (cmp))
 #define sk_KRB5_AUTHENTBODY_new_null() SKM_sk_new_null(KRB5_AUTHENTBODY)
 #define sk_KRB5_AUTHENTBODY_free(st) SKM_sk_free(KRB5_AUTHENTBODY, (st))
 #define sk_KRB5_AUTHENTBODY_num(st) SKM_sk_num(KRB5_AUTHENTBODY, (st))
@@ -854,7 +1019,7 @@ STACK_OF(type) \
 #define sk_KRB5_AUTHENTBODY_sort(st) SKM_sk_sort(KRB5_AUTHENTBODY, (st))
 #define sk_KRB5_AUTHENTBODY_is_sorted(st) SKM_sk_is_sorted(KRB5_AUTHENTBODY, (st))
 
-#define sk_KRB5_CHECKSUM_new(st) SKM_sk_new(KRB5_CHECKSUM, (st))
+#define sk_KRB5_CHECKSUM_new(cmp) SKM_sk_new(KRB5_CHECKSUM, (cmp))
 #define sk_KRB5_CHECKSUM_new_null() SKM_sk_new_null(KRB5_CHECKSUM)
 #define sk_KRB5_CHECKSUM_free(st) SKM_sk_free(KRB5_CHECKSUM, (st))
 #define sk_KRB5_CHECKSUM_num(st) SKM_sk_num(KRB5_CHECKSUM, (st))
@@ -876,7 +1041,7 @@ STACK_OF(type) \
 #define sk_KRB5_CHECKSUM_sort(st) SKM_sk_sort(KRB5_CHECKSUM, (st))
 #define sk_KRB5_CHECKSUM_is_sorted(st) SKM_sk_is_sorted(KRB5_CHECKSUM, (st))
 
-#define sk_KRB5_ENCDATA_new(st) SKM_sk_new(KRB5_ENCDATA, (st))
+#define sk_KRB5_ENCDATA_new(cmp) SKM_sk_new(KRB5_ENCDATA, (cmp))
 #define sk_KRB5_ENCDATA_new_null() SKM_sk_new_null(KRB5_ENCDATA)
 #define sk_KRB5_ENCDATA_free(st) SKM_sk_free(KRB5_ENCDATA, (st))
 #define sk_KRB5_ENCDATA_num(st) SKM_sk_num(KRB5_ENCDATA, (st))
@@ -898,7 +1063,7 @@ STACK_OF(type) \
 #define sk_KRB5_ENCDATA_sort(st) SKM_sk_sort(KRB5_ENCDATA, (st))
 #define sk_KRB5_ENCDATA_is_sorted(st) SKM_sk_is_sorted(KRB5_ENCDATA, (st))
 
-#define sk_KRB5_ENCKEY_new(st) SKM_sk_new(KRB5_ENCKEY, (st))
+#define sk_KRB5_ENCKEY_new(cmp) SKM_sk_new(KRB5_ENCKEY, (cmp))
 #define sk_KRB5_ENCKEY_new_null() SKM_sk_new_null(KRB5_ENCKEY)
 #define sk_KRB5_ENCKEY_free(st) SKM_sk_free(KRB5_ENCKEY, (st))
 #define sk_KRB5_ENCKEY_num(st) SKM_sk_num(KRB5_ENCKEY, (st))
@@ -920,7 +1085,7 @@ STACK_OF(type) \
 #define sk_KRB5_ENCKEY_sort(st) SKM_sk_sort(KRB5_ENCKEY, (st))
 #define sk_KRB5_ENCKEY_is_sorted(st) SKM_sk_is_sorted(KRB5_ENCKEY, (st))
 
-#define sk_KRB5_PRINCNAME_new(st) SKM_sk_new(KRB5_PRINCNAME, (st))
+#define sk_KRB5_PRINCNAME_new(cmp) SKM_sk_new(KRB5_PRINCNAME, (cmp))
 #define sk_KRB5_PRINCNAME_new_null() SKM_sk_new_null(KRB5_PRINCNAME)
 #define sk_KRB5_PRINCNAME_free(st) SKM_sk_free(KRB5_PRINCNAME, (st))
 #define sk_KRB5_PRINCNAME_num(st) SKM_sk_num(KRB5_PRINCNAME, (st))
@@ -942,7 +1107,7 @@ STACK_OF(type) \
 #define sk_KRB5_PRINCNAME_sort(st) SKM_sk_sort(KRB5_PRINCNAME, (st))
 #define sk_KRB5_PRINCNAME_is_sorted(st) SKM_sk_is_sorted(KRB5_PRINCNAME, (st))
 
-#define sk_KRB5_TKTBODY_new(st) SKM_sk_new(KRB5_TKTBODY, (st))
+#define sk_KRB5_TKTBODY_new(cmp) SKM_sk_new(KRB5_TKTBODY, (cmp))
 #define sk_KRB5_TKTBODY_new_null() SKM_sk_new_null(KRB5_TKTBODY)
 #define sk_KRB5_TKTBODY_free(st) SKM_sk_free(KRB5_TKTBODY, (st))
 #define sk_KRB5_TKTBODY_num(st) SKM_sk_num(KRB5_TKTBODY, (st))
@@ -964,7 +1129,29 @@ STACK_OF(type) \
 #define sk_KRB5_TKTBODY_sort(st) SKM_sk_sort(KRB5_TKTBODY, (st))
 #define sk_KRB5_TKTBODY_is_sorted(st) SKM_sk_is_sorted(KRB5_TKTBODY, (st))
 
-#define sk_MIME_HEADER_new(st) SKM_sk_new(MIME_HEADER, (st))
+#define sk_MEM_OBJECT_DATA_new(cmp) SKM_sk_new(MEM_OBJECT_DATA, (cmp))
+#define sk_MEM_OBJECT_DATA_new_null() SKM_sk_new_null(MEM_OBJECT_DATA)
+#define sk_MEM_OBJECT_DATA_free(st) SKM_sk_free(MEM_OBJECT_DATA, (st))
+#define sk_MEM_OBJECT_DATA_num(st) SKM_sk_num(MEM_OBJECT_DATA, (st))
+#define sk_MEM_OBJECT_DATA_value(st, i) SKM_sk_value(MEM_OBJECT_DATA, (st), (i))
+#define sk_MEM_OBJECT_DATA_set(st, i, val) SKM_sk_set(MEM_OBJECT_DATA, (st), (i), (val))
+#define sk_MEM_OBJECT_DATA_zero(st) SKM_sk_zero(MEM_OBJECT_DATA, (st))
+#define sk_MEM_OBJECT_DATA_push(st, val) SKM_sk_push(MEM_OBJECT_DATA, (st), (val))
+#define sk_MEM_OBJECT_DATA_unshift(st, val) SKM_sk_unshift(MEM_OBJECT_DATA, (st), (val))
+#define sk_MEM_OBJECT_DATA_find(st, val) SKM_sk_find(MEM_OBJECT_DATA, (st), (val))
+#define sk_MEM_OBJECT_DATA_find_ex(st, val) SKM_sk_find_ex(MEM_OBJECT_DATA, (st), (val))
+#define sk_MEM_OBJECT_DATA_delete(st, i) SKM_sk_delete(MEM_OBJECT_DATA, (st), (i))
+#define sk_MEM_OBJECT_DATA_delete_ptr(st, ptr) SKM_sk_delete_ptr(MEM_OBJECT_DATA, (st), (ptr))
+#define sk_MEM_OBJECT_DATA_insert(st, val, i) SKM_sk_insert(MEM_OBJECT_DATA, (st), (val), (i))
+#define sk_MEM_OBJECT_DATA_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(MEM_OBJECT_DATA, (st), (cmp))
+#define sk_MEM_OBJECT_DATA_dup(st) SKM_sk_dup(MEM_OBJECT_DATA, st)
+#define sk_MEM_OBJECT_DATA_pop_free(st, free_func) SKM_sk_pop_free(MEM_OBJECT_DATA, (st), (free_func))
+#define sk_MEM_OBJECT_DATA_shift(st) SKM_sk_shift(MEM_OBJECT_DATA, (st))
+#define sk_MEM_OBJECT_DATA_pop(st) SKM_sk_pop(MEM_OBJECT_DATA, (st))
+#define sk_MEM_OBJECT_DATA_sort(st) SKM_sk_sort(MEM_OBJECT_DATA, (st))
+#define sk_MEM_OBJECT_DATA_is_sorted(st) SKM_sk_is_sorted(MEM_OBJECT_DATA, (st))
+
+#define sk_MIME_HEADER_new(cmp) SKM_sk_new(MIME_HEADER, (cmp))
 #define sk_MIME_HEADER_new_null() SKM_sk_new_null(MIME_HEADER)
 #define sk_MIME_HEADER_free(st) SKM_sk_free(MIME_HEADER, (st))
 #define sk_MIME_HEADER_num(st) SKM_sk_num(MIME_HEADER, (st))
@@ -986,7 +1173,7 @@ STACK_OF(type) \
 #define sk_MIME_HEADER_sort(st) SKM_sk_sort(MIME_HEADER, (st))
 #define sk_MIME_HEADER_is_sorted(st) SKM_sk_is_sorted(MIME_HEADER, (st))
 
-#define sk_MIME_PARAM_new(st) SKM_sk_new(MIME_PARAM, (st))
+#define sk_MIME_PARAM_new(cmp) SKM_sk_new(MIME_PARAM, (cmp))
 #define sk_MIME_PARAM_new_null() SKM_sk_new_null(MIME_PARAM)
 #define sk_MIME_PARAM_free(st) SKM_sk_free(MIME_PARAM, (st))
 #define sk_MIME_PARAM_num(st) SKM_sk_num(MIME_PARAM, (st))
@@ -1008,7 +1195,7 @@ STACK_OF(type) \
 #define sk_MIME_PARAM_sort(st) SKM_sk_sort(MIME_PARAM, (st))
 #define sk_MIME_PARAM_is_sorted(st) SKM_sk_is_sorted(MIME_PARAM, (st))
 
-#define sk_NAME_FUNCS_new(st) SKM_sk_new(NAME_FUNCS, (st))
+#define sk_NAME_FUNCS_new(cmp) SKM_sk_new(NAME_FUNCS, (cmp))
 #define sk_NAME_FUNCS_new_null() SKM_sk_new_null(NAME_FUNCS)
 #define sk_NAME_FUNCS_free(st) SKM_sk_free(NAME_FUNCS, (st))
 #define sk_NAME_FUNCS_num(st) SKM_sk_num(NAME_FUNCS, (st))
@@ -1030,7 +1217,7 @@ STACK_OF(type) \
 #define sk_NAME_FUNCS_sort(st) SKM_sk_sort(NAME_FUNCS, (st))
 #define sk_NAME_FUNCS_is_sorted(st) SKM_sk_is_sorted(NAME_FUNCS, (st))
 
-#define sk_OCSP_CERTID_new(st) SKM_sk_new(OCSP_CERTID, (st))
+#define sk_OCSP_CERTID_new(cmp) SKM_sk_new(OCSP_CERTID, (cmp))
 #define sk_OCSP_CERTID_new_null() SKM_sk_new_null(OCSP_CERTID)
 #define sk_OCSP_CERTID_free(st) SKM_sk_free(OCSP_CERTID, (st))
 #define sk_OCSP_CERTID_num(st) SKM_sk_num(OCSP_CERTID, (st))
@@ -1052,7 +1239,7 @@ STACK_OF(type) \
 #define sk_OCSP_CERTID_sort(st) SKM_sk_sort(OCSP_CERTID, (st))
 #define sk_OCSP_CERTID_is_sorted(st) SKM_sk_is_sorted(OCSP_CERTID, (st))
 
-#define sk_OCSP_ONEREQ_new(st) SKM_sk_new(OCSP_ONEREQ, (st))
+#define sk_OCSP_ONEREQ_new(cmp) SKM_sk_new(OCSP_ONEREQ, (cmp))
 #define sk_OCSP_ONEREQ_new_null() SKM_sk_new_null(OCSP_ONEREQ)
 #define sk_OCSP_ONEREQ_free(st) SKM_sk_free(OCSP_ONEREQ, (st))
 #define sk_OCSP_ONEREQ_num(st) SKM_sk_num(OCSP_ONEREQ, (st))
@@ -1074,7 +1261,7 @@ STACK_OF(type) \
 #define sk_OCSP_ONEREQ_sort(st) SKM_sk_sort(OCSP_ONEREQ, (st))
 #define sk_OCSP_ONEREQ_is_sorted(st) SKM_sk_is_sorted(OCSP_ONEREQ, (st))
 
-#define sk_OCSP_RESPID_new(st) SKM_sk_new(OCSP_RESPID, (st))
+#define sk_OCSP_RESPID_new(cmp) SKM_sk_new(OCSP_RESPID, (cmp))
 #define sk_OCSP_RESPID_new_null() SKM_sk_new_null(OCSP_RESPID)
 #define sk_OCSP_RESPID_free(st) SKM_sk_free(OCSP_RESPID, (st))
 #define sk_OCSP_RESPID_num(st) SKM_sk_num(OCSP_RESPID, (st))
@@ -1096,7 +1283,7 @@ STACK_OF(type) \
 #define sk_OCSP_RESPID_sort(st) SKM_sk_sort(OCSP_RESPID, (st))
 #define sk_OCSP_RESPID_is_sorted(st) SKM_sk_is_sorted(OCSP_RESPID, (st))
 
-#define sk_OCSP_SINGLERESP_new(st) SKM_sk_new(OCSP_SINGLERESP, (st))
+#define sk_OCSP_SINGLERESP_new(cmp) SKM_sk_new(OCSP_SINGLERESP, (cmp))
 #define sk_OCSP_SINGLERESP_new_null() SKM_sk_new_null(OCSP_SINGLERESP)
 #define sk_OCSP_SINGLERESP_free(st) SKM_sk_free(OCSP_SINGLERESP, (st))
 #define sk_OCSP_SINGLERESP_num(st) SKM_sk_num(OCSP_SINGLERESP, (st))
@@ -1118,7 +1305,7 @@ STACK_OF(type) \
 #define sk_OCSP_SINGLERESP_sort(st) SKM_sk_sort(OCSP_SINGLERESP, (st))
 #define sk_OCSP_SINGLERESP_is_sorted(st) SKM_sk_is_sorted(OCSP_SINGLERESP, (st))
 
-#define sk_PKCS12_SAFEBAG_new(st) SKM_sk_new(PKCS12_SAFEBAG, (st))
+#define sk_PKCS12_SAFEBAG_new(cmp) SKM_sk_new(PKCS12_SAFEBAG, (cmp))
 #define sk_PKCS12_SAFEBAG_new_null() SKM_sk_new_null(PKCS12_SAFEBAG)
 #define sk_PKCS12_SAFEBAG_free(st) SKM_sk_free(PKCS12_SAFEBAG, (st))
 #define sk_PKCS12_SAFEBAG_num(st) SKM_sk_num(PKCS12_SAFEBAG, (st))
@@ -1140,7 +1327,7 @@ STACK_OF(type) \
 #define sk_PKCS12_SAFEBAG_sort(st) SKM_sk_sort(PKCS12_SAFEBAG, (st))
 #define sk_PKCS12_SAFEBAG_is_sorted(st) SKM_sk_is_sorted(PKCS12_SAFEBAG, (st))
 
-#define sk_PKCS7_new(st) SKM_sk_new(PKCS7, (st))
+#define sk_PKCS7_new(cmp) SKM_sk_new(PKCS7, (cmp))
 #define sk_PKCS7_new_null() SKM_sk_new_null(PKCS7)
 #define sk_PKCS7_free(st) SKM_sk_free(PKCS7, (st))
 #define sk_PKCS7_num(st) SKM_sk_num(PKCS7, (st))
@@ -1162,7 +1349,7 @@ STACK_OF(type) \
 #define sk_PKCS7_sort(st) SKM_sk_sort(PKCS7, (st))
 #define sk_PKCS7_is_sorted(st) SKM_sk_is_sorted(PKCS7, (st))
 
-#define sk_PKCS7_RECIP_INFO_new(st) SKM_sk_new(PKCS7_RECIP_INFO, (st))
+#define sk_PKCS7_RECIP_INFO_new(cmp) SKM_sk_new(PKCS7_RECIP_INFO, (cmp))
 #define sk_PKCS7_RECIP_INFO_new_null() SKM_sk_new_null(PKCS7_RECIP_INFO)
 #define sk_PKCS7_RECIP_INFO_free(st) SKM_sk_free(PKCS7_RECIP_INFO, (st))
 #define sk_PKCS7_RECIP_INFO_num(st) SKM_sk_num(PKCS7_RECIP_INFO, (st))
@@ -1184,7 +1371,7 @@ STACK_OF(type) \
 #define sk_PKCS7_RECIP_INFO_sort(st) SKM_sk_sort(PKCS7_RECIP_INFO, (st))
 #define sk_PKCS7_RECIP_INFO_is_sorted(st) SKM_sk_is_sorted(PKCS7_RECIP_INFO, (st))
 
-#define sk_PKCS7_SIGNER_INFO_new(st) SKM_sk_new(PKCS7_SIGNER_INFO, (st))
+#define sk_PKCS7_SIGNER_INFO_new(cmp) SKM_sk_new(PKCS7_SIGNER_INFO, (cmp))
 #define sk_PKCS7_SIGNER_INFO_new_null() SKM_sk_new_null(PKCS7_SIGNER_INFO)
 #define sk_PKCS7_SIGNER_INFO_free(st) SKM_sk_free(PKCS7_SIGNER_INFO, (st))
 #define sk_PKCS7_SIGNER_INFO_num(st) SKM_sk_num(PKCS7_SIGNER_INFO, (st))
@@ -1206,7 +1393,7 @@ STACK_OF(type) \
 #define sk_PKCS7_SIGNER_INFO_sort(st) SKM_sk_sort(PKCS7_SIGNER_INFO, (st))
 #define sk_PKCS7_SIGNER_INFO_is_sorted(st) SKM_sk_is_sorted(PKCS7_SIGNER_INFO, (st))
 
-#define sk_POLICYINFO_new(st) SKM_sk_new(POLICYINFO, (st))
+#define sk_POLICYINFO_new(cmp) SKM_sk_new(POLICYINFO, (cmp))
 #define sk_POLICYINFO_new_null() SKM_sk_new_null(POLICYINFO)
 #define sk_POLICYINFO_free(st) SKM_sk_free(POLICYINFO, (st))
 #define sk_POLICYINFO_num(st) SKM_sk_num(POLICYINFO, (st))
@@ -1228,7 +1415,7 @@ STACK_OF(type) \
 #define sk_POLICYINFO_sort(st) SKM_sk_sort(POLICYINFO, (st))
 #define sk_POLICYINFO_is_sorted(st) SKM_sk_is_sorted(POLICYINFO, (st))
 
-#define sk_POLICYQUALINFO_new(st) SKM_sk_new(POLICYQUALINFO, (st))
+#define sk_POLICYQUALINFO_new(cmp) SKM_sk_new(POLICYQUALINFO, (cmp))
 #define sk_POLICYQUALINFO_new_null() SKM_sk_new_null(POLICYQUALINFO)
 #define sk_POLICYQUALINFO_free(st) SKM_sk_free(POLICYQUALINFO, (st))
 #define sk_POLICYQUALINFO_num(st) SKM_sk_num(POLICYQUALINFO, (st))
@@ -1250,7 +1437,7 @@ STACK_OF(type) \
 #define sk_POLICYQUALINFO_sort(st) SKM_sk_sort(POLICYQUALINFO, (st))
 #define sk_POLICYQUALINFO_is_sorted(st) SKM_sk_is_sorted(POLICYQUALINFO, (st))
 
-#define sk_POLICY_MAPPING_new(st) SKM_sk_new(POLICY_MAPPING, (st))
+#define sk_POLICY_MAPPING_new(cmp) SKM_sk_new(POLICY_MAPPING, (cmp))
 #define sk_POLICY_MAPPING_new_null() SKM_sk_new_null(POLICY_MAPPING)
 #define sk_POLICY_MAPPING_free(st) SKM_sk_free(POLICY_MAPPING, (st))
 #define sk_POLICY_MAPPING_num(st) SKM_sk_num(POLICY_MAPPING, (st))
@@ -1272,7 +1459,7 @@ STACK_OF(type) \
 #define sk_POLICY_MAPPING_sort(st) SKM_sk_sort(POLICY_MAPPING, (st))
 #define sk_POLICY_MAPPING_is_sorted(st) SKM_sk_is_sorted(POLICY_MAPPING, (st))
 
-#define sk_SSL_CIPHER_new(st) SKM_sk_new(SSL_CIPHER, (st))
+#define sk_SSL_CIPHER_new(cmp) SKM_sk_new(SSL_CIPHER, (cmp))
 #define sk_SSL_CIPHER_new_null() SKM_sk_new_null(SSL_CIPHER)
 #define sk_SSL_CIPHER_free(st) SKM_sk_free(SSL_CIPHER, (st))
 #define sk_SSL_CIPHER_num(st) SKM_sk_num(SSL_CIPHER, (st))
@@ -1294,7 +1481,7 @@ STACK_OF(type) \
 #define sk_SSL_CIPHER_sort(st) SKM_sk_sort(SSL_CIPHER, (st))
 #define sk_SSL_CIPHER_is_sorted(st) SKM_sk_is_sorted(SSL_CIPHER, (st))
 
-#define sk_SSL_COMP_new(st) SKM_sk_new(SSL_COMP, (st))
+#define sk_SSL_COMP_new(cmp) SKM_sk_new(SSL_COMP, (cmp))
 #define sk_SSL_COMP_new_null() SKM_sk_new_null(SSL_COMP)
 #define sk_SSL_COMP_free(st) SKM_sk_free(SSL_COMP, (st))
 #define sk_SSL_COMP_num(st) SKM_sk_num(SSL_COMP, (st))
@@ -1316,7 +1503,51 @@ STACK_OF(type) \
 #define sk_SSL_COMP_sort(st) SKM_sk_sort(SSL_COMP, (st))
 #define sk_SSL_COMP_is_sorted(st) SKM_sk_is_sorted(SSL_COMP, (st))
 
-#define sk_STORE_OBJECT_new(st) SKM_sk_new(STORE_OBJECT, (st))
+#define sk_STACK_OF_X509_NAME_ENTRY_new(cmp) SKM_sk_new(STACK_OF_X509_NAME_ENTRY, (cmp))
+#define sk_STACK_OF_X509_NAME_ENTRY_new_null() SKM_sk_new_null(STACK_OF_X509_NAME_ENTRY)
+#define sk_STACK_OF_X509_NAME_ENTRY_free(st) SKM_sk_free(STACK_OF_X509_NAME_ENTRY, (st))
+#define sk_STACK_OF_X509_NAME_ENTRY_num(st) SKM_sk_num(STACK_OF_X509_NAME_ENTRY, (st))
+#define sk_STACK_OF_X509_NAME_ENTRY_value(st, i) SKM_sk_value(STACK_OF_X509_NAME_ENTRY, (st), (i))
+#define sk_STACK_OF_X509_NAME_ENTRY_set(st, i, val) SKM_sk_set(STACK_OF_X509_NAME_ENTRY, (st), (i), (val))
+#define sk_STACK_OF_X509_NAME_ENTRY_zero(st) SKM_sk_zero(STACK_OF_X509_NAME_ENTRY, (st))
+#define sk_STACK_OF_X509_NAME_ENTRY_push(st, val) SKM_sk_push(STACK_OF_X509_NAME_ENTRY, (st), (val))
+#define sk_STACK_OF_X509_NAME_ENTRY_unshift(st, val) SKM_sk_unshift(STACK_OF_X509_NAME_ENTRY, (st), (val))
+#define sk_STACK_OF_X509_NAME_ENTRY_find(st, val) SKM_sk_find(STACK_OF_X509_NAME_ENTRY, (st), (val))
+#define sk_STACK_OF_X509_NAME_ENTRY_find_ex(st, val) SKM_sk_find_ex(STACK_OF_X509_NAME_ENTRY, (st), (val))
+#define sk_STACK_OF_X509_NAME_ENTRY_delete(st, i) SKM_sk_delete(STACK_OF_X509_NAME_ENTRY, (st), (i))
+#define sk_STACK_OF_X509_NAME_ENTRY_delete_ptr(st, ptr) SKM_sk_delete_ptr(STACK_OF_X509_NAME_ENTRY, (st), (ptr))
+#define sk_STACK_OF_X509_NAME_ENTRY_insert(st, val, i) SKM_sk_insert(STACK_OF_X509_NAME_ENTRY, (st), (val), (i))
+#define sk_STACK_OF_X509_NAME_ENTRY_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(STACK_OF_X509_NAME_ENTRY, (st), (cmp))
+#define sk_STACK_OF_X509_NAME_ENTRY_dup(st) SKM_sk_dup(STACK_OF_X509_NAME_ENTRY, st)
+#define sk_STACK_OF_X509_NAME_ENTRY_pop_free(st, free_func) SKM_sk_pop_free(STACK_OF_X509_NAME_ENTRY, (st), (free_func))
+#define sk_STACK_OF_X509_NAME_ENTRY_shift(st) SKM_sk_shift(STACK_OF_X509_NAME_ENTRY, (st))
+#define sk_STACK_OF_X509_NAME_ENTRY_pop(st) SKM_sk_pop(STACK_OF_X509_NAME_ENTRY, (st))
+#define sk_STACK_OF_X509_NAME_ENTRY_sort(st) SKM_sk_sort(STACK_OF_X509_NAME_ENTRY, (st))
+#define sk_STACK_OF_X509_NAME_ENTRY_is_sorted(st) SKM_sk_is_sorted(STACK_OF_X509_NAME_ENTRY, (st))
+
+#define sk_STORE_ATTR_INFO_new(cmp) SKM_sk_new(STORE_ATTR_INFO, (cmp))
+#define sk_STORE_ATTR_INFO_new_null() SKM_sk_new_null(STORE_ATTR_INFO)
+#define sk_STORE_ATTR_INFO_free(st) SKM_sk_free(STORE_ATTR_INFO, (st))
+#define sk_STORE_ATTR_INFO_num(st) SKM_sk_num(STORE_ATTR_INFO, (st))
+#define sk_STORE_ATTR_INFO_value(st, i) SKM_sk_value(STORE_ATTR_INFO, (st), (i))
+#define sk_STORE_ATTR_INFO_set(st, i, val) SKM_sk_set(STORE_ATTR_INFO, (st), (i), (val))
+#define sk_STORE_ATTR_INFO_zero(st) SKM_sk_zero(STORE_ATTR_INFO, (st))
+#define sk_STORE_ATTR_INFO_push(st, val) SKM_sk_push(STORE_ATTR_INFO, (st), (val))
+#define sk_STORE_ATTR_INFO_unshift(st, val) SKM_sk_unshift(STORE_ATTR_INFO, (st), (val))
+#define sk_STORE_ATTR_INFO_find(st, val) SKM_sk_find(STORE_ATTR_INFO, (st), (val))
+#define sk_STORE_ATTR_INFO_find_ex(st, val) SKM_sk_find_ex(STORE_ATTR_INFO, (st), (val))
+#define sk_STORE_ATTR_INFO_delete(st, i) SKM_sk_delete(STORE_ATTR_INFO, (st), (i))
+#define sk_STORE_ATTR_INFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(STORE_ATTR_INFO, (st), (ptr))
+#define sk_STORE_ATTR_INFO_insert(st, val, i) SKM_sk_insert(STORE_ATTR_INFO, (st), (val), (i))
+#define sk_STORE_ATTR_INFO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(STORE_ATTR_INFO, (st), (cmp))
+#define sk_STORE_ATTR_INFO_dup(st) SKM_sk_dup(STORE_ATTR_INFO, st)
+#define sk_STORE_ATTR_INFO_pop_free(st, free_func) SKM_sk_pop_free(STORE_ATTR_INFO, (st), (free_func))
+#define sk_STORE_ATTR_INFO_shift(st) SKM_sk_shift(STORE_ATTR_INFO, (st))
+#define sk_STORE_ATTR_INFO_pop(st) SKM_sk_pop(STORE_ATTR_INFO, (st))
+#define sk_STORE_ATTR_INFO_sort(st) SKM_sk_sort(STORE_ATTR_INFO, (st))
+#define sk_STORE_ATTR_INFO_is_sorted(st) SKM_sk_is_sorted(STORE_ATTR_INFO, (st))
+
+#define sk_STORE_OBJECT_new(cmp) SKM_sk_new(STORE_OBJECT, (cmp))
 #define sk_STORE_OBJECT_new_null() SKM_sk_new_null(STORE_OBJECT)
 #define sk_STORE_OBJECT_free(st) SKM_sk_free(STORE_OBJECT, (st))
 #define sk_STORE_OBJECT_num(st) SKM_sk_num(STORE_OBJECT, (st))
@@ -1338,7 +1569,7 @@ STACK_OF(type) \
 #define sk_STORE_OBJECT_sort(st) SKM_sk_sort(STORE_OBJECT, (st))
 #define sk_STORE_OBJECT_is_sorted(st) SKM_sk_is_sorted(STORE_OBJECT, (st))
 
-#define sk_SXNETID_new(st) SKM_sk_new(SXNETID, (st))
+#define sk_SXNETID_new(cmp) SKM_sk_new(SXNETID, (cmp))
 #define sk_SXNETID_new_null() SKM_sk_new_null(SXNETID)
 #define sk_SXNETID_free(st) SKM_sk_free(SXNETID, (st))
 #define sk_SXNETID_num(st) SKM_sk_num(SXNETID, (st))
@@ -1360,7 +1591,7 @@ STACK_OF(type) \
 #define sk_SXNETID_sort(st) SKM_sk_sort(SXNETID, (st))
 #define sk_SXNETID_is_sorted(st) SKM_sk_is_sorted(SXNETID, (st))
 
-#define sk_UI_STRING_new(st) SKM_sk_new(UI_STRING, (st))
+#define sk_UI_STRING_new(cmp) SKM_sk_new(UI_STRING, (cmp))
 #define sk_UI_STRING_new_null() SKM_sk_new_null(UI_STRING)
 #define sk_UI_STRING_free(st) SKM_sk_free(UI_STRING, (st))
 #define sk_UI_STRING_num(st) SKM_sk_num(UI_STRING, (st))
@@ -1382,7 +1613,7 @@ STACK_OF(type) \
 #define sk_UI_STRING_sort(st) SKM_sk_sort(UI_STRING, (st))
 #define sk_UI_STRING_is_sorted(st) SKM_sk_is_sorted(UI_STRING, (st))
 
-#define sk_X509_new(st) SKM_sk_new(X509, (st))
+#define sk_X509_new(cmp) SKM_sk_new(X509, (cmp))
 #define sk_X509_new_null() SKM_sk_new_null(X509)
 #define sk_X509_free(st) SKM_sk_free(X509, (st))
 #define sk_X509_num(st) SKM_sk_num(X509, (st))
@@ -1404,7 +1635,7 @@ STACK_OF(type) \
 #define sk_X509_sort(st) SKM_sk_sort(X509, (st))
 #define sk_X509_is_sorted(st) SKM_sk_is_sorted(X509, (st))
 
-#define sk_X509V3_EXT_METHOD_new(st) SKM_sk_new(X509V3_EXT_METHOD, (st))
+#define sk_X509V3_EXT_METHOD_new(cmp) SKM_sk_new(X509V3_EXT_METHOD, (cmp))
 #define sk_X509V3_EXT_METHOD_new_null() SKM_sk_new_null(X509V3_EXT_METHOD)
 #define sk_X509V3_EXT_METHOD_free(st) SKM_sk_free(X509V3_EXT_METHOD, (st))
 #define sk_X509V3_EXT_METHOD_num(st) SKM_sk_num(X509V3_EXT_METHOD, (st))
@@ -1426,7 +1657,7 @@ STACK_OF(type) \
 #define sk_X509V3_EXT_METHOD_sort(st) SKM_sk_sort(X509V3_EXT_METHOD, (st))
 #define sk_X509V3_EXT_METHOD_is_sorted(st) SKM_sk_is_sorted(X509V3_EXT_METHOD, (st))
 
-#define sk_X509_ALGOR_new(st) SKM_sk_new(X509_ALGOR, (st))
+#define sk_X509_ALGOR_new(cmp) SKM_sk_new(X509_ALGOR, (cmp))
 #define sk_X509_ALGOR_new_null() SKM_sk_new_null(X509_ALGOR)
 #define sk_X509_ALGOR_free(st) SKM_sk_free(X509_ALGOR, (st))
 #define sk_X509_ALGOR_num(st) SKM_sk_num(X509_ALGOR, (st))
@@ -1448,7 +1679,7 @@ STACK_OF(type) \
 #define sk_X509_ALGOR_sort(st) SKM_sk_sort(X509_ALGOR, (st))
 #define sk_X509_ALGOR_is_sorted(st) SKM_sk_is_sorted(X509_ALGOR, (st))
 
-#define sk_X509_ATTRIBUTE_new(st) SKM_sk_new(X509_ATTRIBUTE, (st))
+#define sk_X509_ATTRIBUTE_new(cmp) SKM_sk_new(X509_ATTRIBUTE, (cmp))
 #define sk_X509_ATTRIBUTE_new_null() SKM_sk_new_null(X509_ATTRIBUTE)
 #define sk_X509_ATTRIBUTE_free(st) SKM_sk_free(X509_ATTRIBUTE, (st))
 #define sk_X509_ATTRIBUTE_num(st) SKM_sk_num(X509_ATTRIBUTE, (st))
@@ -1470,7 +1701,7 @@ STACK_OF(type) \
 #define sk_X509_ATTRIBUTE_sort(st) SKM_sk_sort(X509_ATTRIBUTE, (st))
 #define sk_X509_ATTRIBUTE_is_sorted(st) SKM_sk_is_sorted(X509_ATTRIBUTE, (st))
 
-#define sk_X509_CRL_new(st) SKM_sk_new(X509_CRL, (st))
+#define sk_X509_CRL_new(cmp) SKM_sk_new(X509_CRL, (cmp))
 #define sk_X509_CRL_new_null() SKM_sk_new_null(X509_CRL)
 #define sk_X509_CRL_free(st) SKM_sk_free(X509_CRL, (st))
 #define sk_X509_CRL_num(st) SKM_sk_num(X509_CRL, (st))
@@ -1492,7 +1723,7 @@ STACK_OF(type) \
 #define sk_X509_CRL_sort(st) SKM_sk_sort(X509_CRL, (st))
 #define sk_X509_CRL_is_sorted(st) SKM_sk_is_sorted(X509_CRL, (st))
 
-#define sk_X509_EXTENSION_new(st) SKM_sk_new(X509_EXTENSION, (st))
+#define sk_X509_EXTENSION_new(cmp) SKM_sk_new(X509_EXTENSION, (cmp))
 #define sk_X509_EXTENSION_new_null() SKM_sk_new_null(X509_EXTENSION)
 #define sk_X509_EXTENSION_free(st) SKM_sk_free(X509_EXTENSION, (st))
 #define sk_X509_EXTENSION_num(st) SKM_sk_num(X509_EXTENSION, (st))
@@ -1514,7 +1745,7 @@ STACK_OF(type) \
 #define sk_X509_EXTENSION_sort(st) SKM_sk_sort(X509_EXTENSION, (st))
 #define sk_X509_EXTENSION_is_sorted(st) SKM_sk_is_sorted(X509_EXTENSION, (st))
 
-#define sk_X509_INFO_new(st) SKM_sk_new(X509_INFO, (st))
+#define sk_X509_INFO_new(cmp) SKM_sk_new(X509_INFO, (cmp))
 #define sk_X509_INFO_new_null() SKM_sk_new_null(X509_INFO)
 #define sk_X509_INFO_free(st) SKM_sk_free(X509_INFO, (st))
 #define sk_X509_INFO_num(st) SKM_sk_num(X509_INFO, (st))
@@ -1536,7 +1767,7 @@ STACK_OF(type) \
 #define sk_X509_INFO_sort(st) SKM_sk_sort(X509_INFO, (st))
 #define sk_X509_INFO_is_sorted(st) SKM_sk_is_sorted(X509_INFO, (st))
 
-#define sk_X509_LOOKUP_new(st) SKM_sk_new(X509_LOOKUP, (st))
+#define sk_X509_LOOKUP_new(cmp) SKM_sk_new(X509_LOOKUP, (cmp))
 #define sk_X509_LOOKUP_new_null() SKM_sk_new_null(X509_LOOKUP)
 #define sk_X509_LOOKUP_free(st) SKM_sk_free(X509_LOOKUP, (st))
 #define sk_X509_LOOKUP_num(st) SKM_sk_num(X509_LOOKUP, (st))
@@ -1558,7 +1789,7 @@ STACK_OF(type) \
 #define sk_X509_LOOKUP_sort(st) SKM_sk_sort(X509_LOOKUP, (st))
 #define sk_X509_LOOKUP_is_sorted(st) SKM_sk_is_sorted(X509_LOOKUP, (st))
 
-#define sk_X509_NAME_new(st) SKM_sk_new(X509_NAME, (st))
+#define sk_X509_NAME_new(cmp) SKM_sk_new(X509_NAME, (cmp))
 #define sk_X509_NAME_new_null() SKM_sk_new_null(X509_NAME)
 #define sk_X509_NAME_free(st) SKM_sk_free(X509_NAME, (st))
 #define sk_X509_NAME_num(st) SKM_sk_num(X509_NAME, (st))
@@ -1580,7 +1811,7 @@ STACK_OF(type) \
 #define sk_X509_NAME_sort(st) SKM_sk_sort(X509_NAME, (st))
 #define sk_X509_NAME_is_sorted(st) SKM_sk_is_sorted(X509_NAME, (st))
 
-#define sk_X509_NAME_ENTRY_new(st) SKM_sk_new(X509_NAME_ENTRY, (st))
+#define sk_X509_NAME_ENTRY_new(cmp) SKM_sk_new(X509_NAME_ENTRY, (cmp))
 #define sk_X509_NAME_ENTRY_new_null() SKM_sk_new_null(X509_NAME_ENTRY)
 #define sk_X509_NAME_ENTRY_free(st) SKM_sk_free(X509_NAME_ENTRY, (st))
 #define sk_X509_NAME_ENTRY_num(st) SKM_sk_num(X509_NAME_ENTRY, (st))
@@ -1602,7 +1833,7 @@ STACK_OF(type) \
 #define sk_X509_NAME_ENTRY_sort(st) SKM_sk_sort(X509_NAME_ENTRY, (st))
 #define sk_X509_NAME_ENTRY_is_sorted(st) SKM_sk_is_sorted(X509_NAME_ENTRY, (st))
 
-#define sk_X509_OBJECT_new(st) SKM_sk_new(X509_OBJECT, (st))
+#define sk_X509_OBJECT_new(cmp) SKM_sk_new(X509_OBJECT, (cmp))
 #define sk_X509_OBJECT_new_null() SKM_sk_new_null(X509_OBJECT)
 #define sk_X509_OBJECT_free(st) SKM_sk_free(X509_OBJECT, (st))
 #define sk_X509_OBJECT_num(st) SKM_sk_num(X509_OBJECT, (st))
@@ -1624,7 +1855,7 @@ STACK_OF(type) \
 #define sk_X509_OBJECT_sort(st) SKM_sk_sort(X509_OBJECT, (st))
 #define sk_X509_OBJECT_is_sorted(st) SKM_sk_is_sorted(X509_OBJECT, (st))
 
-#define sk_X509_POLICY_DATA_new(st) SKM_sk_new(X509_POLICY_DATA, (st))
+#define sk_X509_POLICY_DATA_new(cmp) SKM_sk_new(X509_POLICY_DATA, (cmp))
 #define sk_X509_POLICY_DATA_new_null() SKM_sk_new_null(X509_POLICY_DATA)
 #define sk_X509_POLICY_DATA_free(st) SKM_sk_free(X509_POLICY_DATA, (st))
 #define sk_X509_POLICY_DATA_num(st) SKM_sk_num(X509_POLICY_DATA, (st))
@@ -1646,7 +1877,7 @@ STACK_OF(type) \
 #define sk_X509_POLICY_DATA_sort(st) SKM_sk_sort(X509_POLICY_DATA, (st))
 #define sk_X509_POLICY_DATA_is_sorted(st) SKM_sk_is_sorted(X509_POLICY_DATA, (st))
 
-#define sk_X509_POLICY_NODE_new(st) SKM_sk_new(X509_POLICY_NODE, (st))
+#define sk_X509_POLICY_NODE_new(cmp) SKM_sk_new(X509_POLICY_NODE, (cmp))
 #define sk_X509_POLICY_NODE_new_null() SKM_sk_new_null(X509_POLICY_NODE)
 #define sk_X509_POLICY_NODE_free(st) SKM_sk_free(X509_POLICY_NODE, (st))
 #define sk_X509_POLICY_NODE_num(st) SKM_sk_num(X509_POLICY_NODE, (st))
@@ -1668,29 +1899,7 @@ STACK_OF(type) \
 #define sk_X509_POLICY_NODE_sort(st) SKM_sk_sort(X509_POLICY_NODE, (st))
 #define sk_X509_POLICY_NODE_is_sorted(st) SKM_sk_is_sorted(X509_POLICY_NODE, (st))
 
-#define sk_X509_POLICY_REF_new(st) SKM_sk_new(X509_POLICY_REF, (st))
-#define sk_X509_POLICY_REF_new_null() SKM_sk_new_null(X509_POLICY_REF)
-#define sk_X509_POLICY_REF_free(st) SKM_sk_free(X509_POLICY_REF, (st))
-#define sk_X509_POLICY_REF_num(st) SKM_sk_num(X509_POLICY_REF, (st))
-#define sk_X509_POLICY_REF_value(st, i) SKM_sk_value(X509_POLICY_REF, (st), (i))
-#define sk_X509_POLICY_REF_set(st, i, val) SKM_sk_set(X509_POLICY_REF, (st), (i), (val))
-#define sk_X509_POLICY_REF_zero(st) SKM_sk_zero(X509_POLICY_REF, (st))
-#define sk_X509_POLICY_REF_push(st, val) SKM_sk_push(X509_POLICY_REF, (st), (val))
-#define sk_X509_POLICY_REF_unshift(st, val) SKM_sk_unshift(X509_POLICY_REF, (st), (val))
-#define sk_X509_POLICY_REF_find(st, val) SKM_sk_find(X509_POLICY_REF, (st), (val))
-#define sk_X509_POLICY_REF_find_ex(st, val) SKM_sk_find_ex(X509_POLICY_REF, (st), (val))
-#define sk_X509_POLICY_REF_delete(st, i) SKM_sk_delete(X509_POLICY_REF, (st), (i))
-#define sk_X509_POLICY_REF_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_POLICY_REF, (st), (ptr))
-#define sk_X509_POLICY_REF_insert(st, val, i) SKM_sk_insert(X509_POLICY_REF, (st), (val), (i))
-#define sk_X509_POLICY_REF_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_POLICY_REF, (st), (cmp))
-#define sk_X509_POLICY_REF_dup(st) SKM_sk_dup(X509_POLICY_REF, st)
-#define sk_X509_POLICY_REF_pop_free(st, free_func) SKM_sk_pop_free(X509_POLICY_REF, (st), (free_func))
-#define sk_X509_POLICY_REF_shift(st) SKM_sk_shift(X509_POLICY_REF, (st))
-#define sk_X509_POLICY_REF_pop(st) SKM_sk_pop(X509_POLICY_REF, (st))
-#define sk_X509_POLICY_REF_sort(st) SKM_sk_sort(X509_POLICY_REF, (st))
-#define sk_X509_POLICY_REF_is_sorted(st) SKM_sk_is_sorted(X509_POLICY_REF, (st))
-
-#define sk_X509_PURPOSE_new(st) SKM_sk_new(X509_PURPOSE, (st))
+#define sk_X509_PURPOSE_new(cmp) SKM_sk_new(X509_PURPOSE, (cmp))
 #define sk_X509_PURPOSE_new_null() SKM_sk_new_null(X509_PURPOSE)
 #define sk_X509_PURPOSE_free(st) SKM_sk_free(X509_PURPOSE, (st))
 #define sk_X509_PURPOSE_num(st) SKM_sk_num(X509_PURPOSE, (st))
@@ -1712,7 +1921,7 @@ STACK_OF(type) \
 #define sk_X509_PURPOSE_sort(st) SKM_sk_sort(X509_PURPOSE, (st))
 #define sk_X509_PURPOSE_is_sorted(st) SKM_sk_is_sorted(X509_PURPOSE, (st))
 
-#define sk_X509_REVOKED_new(st) SKM_sk_new(X509_REVOKED, (st))
+#define sk_X509_REVOKED_new(cmp) SKM_sk_new(X509_REVOKED, (cmp))
 #define sk_X509_REVOKED_new_null() SKM_sk_new_null(X509_REVOKED)
 #define sk_X509_REVOKED_free(st) SKM_sk_free(X509_REVOKED, (st))
 #define sk_X509_REVOKED_num(st) SKM_sk_num(X509_REVOKED, (st))
@@ -1734,7 +1943,7 @@ STACK_OF(type) \
 #define sk_X509_REVOKED_sort(st) SKM_sk_sort(X509_REVOKED, (st))
 #define sk_X509_REVOKED_is_sorted(st) SKM_sk_is_sorted(X509_REVOKED, (st))
 
-#define sk_X509_TRUST_new(st) SKM_sk_new(X509_TRUST, (st))
+#define sk_X509_TRUST_new(cmp) SKM_sk_new(X509_TRUST, (cmp))
 #define sk_X509_TRUST_new_null() SKM_sk_new_null(X509_TRUST)
 #define sk_X509_TRUST_free(st) SKM_sk_free(X509_TRUST, (st))
 #define sk_X509_TRUST_num(st) SKM_sk_num(X509_TRUST, (st))
@@ -1756,7 +1965,7 @@ STACK_OF(type) \
 #define sk_X509_TRUST_sort(st) SKM_sk_sort(X509_TRUST, (st))
 #define sk_X509_TRUST_is_sorted(st) SKM_sk_is_sorted(X509_TRUST, (st))
 
-#define sk_X509_VERIFY_PARAM_new(st) SKM_sk_new(X509_VERIFY_PARAM, (st))
+#define sk_X509_VERIFY_PARAM_new(cmp) SKM_sk_new(X509_VERIFY_PARAM, (cmp))
 #define sk_X509_VERIFY_PARAM_new_null() SKM_sk_new_null(X509_VERIFY_PARAM)
 #define sk_X509_VERIFY_PARAM_free(st) SKM_sk_free(X509_VERIFY_PARAM, (st))
 #define sk_X509_VERIFY_PARAM_num(st) SKM_sk_num(X509_VERIFY_PARAM, (st))
@@ -1778,6 +1987,125 @@ STACK_OF(type) \
 #define sk_X509_VERIFY_PARAM_sort(st) SKM_sk_sort(X509_VERIFY_PARAM, (st))
 #define sk_X509_VERIFY_PARAM_is_sorted(st) SKM_sk_is_sorted(X509_VERIFY_PARAM, (st))
 
+#define sk_nid_triple_new(cmp) SKM_sk_new(nid_triple, (cmp))
+#define sk_nid_triple_new_null() SKM_sk_new_null(nid_triple)
+#define sk_nid_triple_free(st) SKM_sk_free(nid_triple, (st))
+#define sk_nid_triple_num(st) SKM_sk_num(nid_triple, (st))
+#define sk_nid_triple_value(st, i) SKM_sk_value(nid_triple, (st), (i))
+#define sk_nid_triple_set(st, i, val) SKM_sk_set(nid_triple, (st), (i), (val))
+#define sk_nid_triple_zero(st) SKM_sk_zero(nid_triple, (st))
+#define sk_nid_triple_push(st, val) SKM_sk_push(nid_triple, (st), (val))
+#define sk_nid_triple_unshift(st, val) SKM_sk_unshift(nid_triple, (st), (val))
+#define sk_nid_triple_find(st, val) SKM_sk_find(nid_triple, (st), (val))
+#define sk_nid_triple_find_ex(st, val) SKM_sk_find_ex(nid_triple, (st), (val))
+#define sk_nid_triple_delete(st, i) SKM_sk_delete(nid_triple, (st), (i))
+#define sk_nid_triple_delete_ptr(st, ptr) SKM_sk_delete_ptr(nid_triple, (st), (ptr))
+#define sk_nid_triple_insert(st, val, i) SKM_sk_insert(nid_triple, (st), (val), (i))
+#define sk_nid_triple_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(nid_triple, (st), (cmp))
+#define sk_nid_triple_dup(st) SKM_sk_dup(nid_triple, st)
+#define sk_nid_triple_pop_free(st, free_func) SKM_sk_pop_free(nid_triple, (st), (free_func))
+#define sk_nid_triple_shift(st) SKM_sk_shift(nid_triple, (st))
+#define sk_nid_triple_pop(st) SKM_sk_pop(nid_triple, (st))
+#define sk_nid_triple_sort(st) SKM_sk_sort(nid_triple, (st))
+#define sk_nid_triple_is_sorted(st) SKM_sk_is_sorted(nid_triple, (st))
+
+#define sk_void_new(cmp) SKM_sk_new(void, (cmp))
+#define sk_void_new_null() SKM_sk_new_null(void)
+#define sk_void_free(st) SKM_sk_free(void, (st))
+#define sk_void_num(st) SKM_sk_num(void, (st))
+#define sk_void_value(st, i) SKM_sk_value(void, (st), (i))
+#define sk_void_set(st, i, val) SKM_sk_set(void, (st), (i), (val))
+#define sk_void_zero(st) SKM_sk_zero(void, (st))
+#define sk_void_push(st, val) SKM_sk_push(void, (st), (val))
+#define sk_void_unshift(st, val) SKM_sk_unshift(void, (st), (val))
+#define sk_void_find(st, val) SKM_sk_find(void, (st), (val))
+#define sk_void_find_ex(st, val) SKM_sk_find_ex(void, (st), (val))
+#define sk_void_delete(st, i) SKM_sk_delete(void, (st), (i))
+#define sk_void_delete_ptr(st, ptr) SKM_sk_delete_ptr(void, (st), (ptr))
+#define sk_void_insert(st, val, i) SKM_sk_insert(void, (st), (val), (i))
+#define sk_void_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(void, (st), (cmp))
+#define sk_void_dup(st) SKM_sk_dup(void, st)
+#define sk_void_pop_free(st, free_func) SKM_sk_pop_free(void, (st), (free_func))
+#define sk_void_shift(st) SKM_sk_shift(void, (st))
+#define sk_void_pop(st) SKM_sk_pop(void, (st))
+#define sk_void_sort(st) SKM_sk_sort(void, (st))
+#define sk_void_is_sorted(st) SKM_sk_is_sorted(void, (st))
+
+#define sk_OPENSSL_STRING_new(cmp) ((STACK_OF(OPENSSL_STRING) *)sk_new(CHECKED_SK_CMP_FUNC(char, cmp)))
+#define sk_OPENSSL_STRING_new_null() ((STACK_OF(OPENSSL_STRING) *)sk_new_null())
+#define sk_OPENSSL_STRING_push(st, val) sk_push(CHECKED_STACK_OF(OPENSSL_STRING, st), CHECKED_PTR_OF(char, val))
+#define sk_OPENSSL_STRING_find(st, val) sk_find(CHECKED_STACK_OF(OPENSSL_STRING, st), CHECKED_PTR_OF(char, val))
+#define sk_OPENSSL_STRING_value(st, i) ((OPENSSL_STRING)sk_value(CHECKED_STACK_OF(OPENSSL_STRING, st), i))
+#define sk_OPENSSL_STRING_num(st) SKM_sk_num(OPENSSL_STRING, st)
+#define sk_OPENSSL_STRING_pop_free(st, free_func) sk_pop_free(CHECKED_STACK_OF(OPENSSL_STRING, st), CHECKED_SK_FREE_FUNC2(OPENSSL_STRING, free_func))
+#define sk_OPENSSL_STRING_insert(st, val, i) sk_insert(CHECKED_STACK_OF(OPENSSL_STRING, st), CHECKED_PTR_OF(char, val), i)
+#define sk_OPENSSL_STRING_free(st) SKM_sk_free(OPENSSL_STRING, st)
+#define sk_OPENSSL_STRING_set(st, i, val) sk_set(CHECKED_STACK_OF(OPENSSL_STRING, st), i, CHECKED_PTR_OF(char, val))
+#define sk_OPENSSL_STRING_zero(st) SKM_sk_zero(OPENSSL_STRING, (st))
+#define sk_OPENSSL_STRING_unshift(st, val) sk_unshift(CHECKED_STACK_OF(OPENSSL_STRING, st), CHECKED_PTR_OF(char, val))
+#define sk_OPENSSL_STRING_find_ex(st, val) sk_find_ex((_STACK *)CHECKED_CONST_PTR_OF(STACK_OF(OPENSSL_STRING), st), CHECKED_CONST_PTR_OF(char, val))
+#define sk_OPENSSL_STRING_delete(st, i) SKM_sk_delete(OPENSSL_STRING, (st), (i))
+#define sk_OPENSSL_STRING_delete_ptr(st, ptr) (OPENSSL_STRING *)sk_delete_ptr(CHECKED_STACK_OF(OPENSSL_STRING, st), CHECKED_PTR_OF(char, ptr))
+#define sk_OPENSSL_STRING_set_cmp_func(st, cmp)  \
+       ((int (*)(const char * const *,const char * const *)) \
+       sk_set_cmp_func(CHECKED_STACK_OF(OPENSSL_STRING, st), CHECKED_SK_CMP_FUNC(char, cmp)))
+#define sk_OPENSSL_STRING_dup(st) SKM_sk_dup(OPENSSL_STRING, st)
+#define sk_OPENSSL_STRING_shift(st) SKM_sk_shift(OPENSSL_STRING, (st))
+#define sk_OPENSSL_STRING_pop(st) (char *)sk_pop(CHECKED_STACK_OF(OPENSSL_STRING, st))
+#define sk_OPENSSL_STRING_sort(st) SKM_sk_sort(OPENSSL_STRING, (st))
+#define sk_OPENSSL_STRING_is_sorted(st) SKM_sk_is_sorted(OPENSSL_STRING, (st))
+
+
+#define sk_OPENSSL_PSTRING_new(cmp) ((STACK_OF(OPENSSL_PSTRING) *)sk_new(CHECKED_SK_CMP_FUNC(OPENSSL_STRING, cmp)))
+#define sk_OPENSSL_PSTRING_new_null() ((STACK_OF(OPENSSL_PSTRING) *)sk_new_null())
+#define sk_OPENSSL_PSTRING_push(st, val) sk_push(CHECKED_STACK_OF(OPENSSL_PSTRING, st), CHECKED_PTR_OF(OPENSSL_STRING, val))
+#define sk_OPENSSL_PSTRING_find(st, val) sk_find(CHECKED_STACK_OF(OPENSSL_PSTRING, st), CHECKED_PTR_OF(OPENSSL_STRING, val))
+#define sk_OPENSSL_PSTRING_value(st, i) ((OPENSSL_PSTRING)sk_value(CHECKED_STACK_OF(OPENSSL_PSTRING, st), i))
+#define sk_OPENSSL_PSTRING_num(st) SKM_sk_num(OPENSSL_PSTRING, st)
+#define sk_OPENSSL_PSTRING_pop_free(st, free_func) sk_pop_free(CHECKED_STACK_OF(OPENSSL_PSTRING, st), CHECKED_SK_FREE_FUNC2(OPENSSL_PSTRING, free_func))
+#define sk_OPENSSL_PSTRING_insert(st, val, i) sk_insert(CHECKED_STACK_OF(OPENSSL_PSTRING, st), CHECKED_PTR_OF(OPENSSL_STRING, val), i)
+#define sk_OPENSSL_PSTRING_free(st) SKM_sk_free(OPENSSL_PSTRING, st)
+#define sk_OPENSSL_PSTRING_set(st, i, val) sk_set(CHECKED_STACK_OF(OPENSSL_PSTRING, st), i, CHECKED_PTR_OF(OPENSSL_STRING, val))
+#define sk_OPENSSL_PSTRING_zero(st) SKM_sk_zero(OPENSSL_PSTRING, (st))
+#define sk_OPENSSL_PSTRING_unshift(st, val) sk_unshift(CHECKED_STACK_OF(OPENSSL_PSTRING, st), CHECKED_PTR_OF(OPENSSL_STRING, val))
+#define sk_OPENSSL_PSTRING_find_ex(st, val) sk_find_ex((_STACK *)CHECKED_CONST_PTR_OF(STACK_OF(OPENSSL_PSTRING), st), CHECKED_CONST_PTR_OF(OPENSSL_STRING, val))
+#define sk_OPENSSL_PSTRING_delete(st, i) SKM_sk_delete(OPENSSL_PSTRING, (st), (i))
+#define sk_OPENSSL_PSTRING_delete_ptr(st, ptr) (OPENSSL_PSTRING *)sk_delete_ptr(CHECKED_STACK_OF(OPENSSL_PSTRING, st), CHECKED_PTR_OF(OPENSSL_STRING, ptr))
+#define sk_OPENSSL_PSTRING_set_cmp_func(st, cmp)  \
+       ((int (*)(const OPENSSL_STRING * const *,const OPENSSL_STRING * const *)) \
+       sk_set_cmp_func(CHECKED_STACK_OF(OPENSSL_PSTRING, st), CHECKED_SK_CMP_FUNC(OPENSSL_STRING, cmp)))
+#define sk_OPENSSL_PSTRING_dup(st) SKM_sk_dup(OPENSSL_PSTRING, st)
+#define sk_OPENSSL_PSTRING_shift(st) SKM_sk_shift(OPENSSL_PSTRING, (st))
+#define sk_OPENSSL_PSTRING_pop(st) (OPENSSL_STRING *)sk_pop(CHECKED_STACK_OF(OPENSSL_PSTRING, st))
+#define sk_OPENSSL_PSTRING_sort(st) SKM_sk_sort(OPENSSL_PSTRING, (st))
+#define sk_OPENSSL_PSTRING_is_sorted(st) SKM_sk_is_sorted(OPENSSL_PSTRING, (st))
+
+
+#define sk_OPENSSL_BLOCK_new(cmp) ((STACK_OF(OPENSSL_BLOCK) *)sk_new(CHECKED_SK_CMP_FUNC(void, cmp)))
+#define sk_OPENSSL_BLOCK_new_null() ((STACK_OF(OPENSSL_BLOCK) *)sk_new_null())
+#define sk_OPENSSL_BLOCK_push(st, val) sk_push(CHECKED_STACK_OF(OPENSSL_BLOCK, st), CHECKED_PTR_OF(void, val))
+#define sk_OPENSSL_BLOCK_find(st, val) sk_find(CHECKED_STACK_OF(OPENSSL_BLOCK, st), CHECKED_PTR_OF(void, val))
+#define sk_OPENSSL_BLOCK_value(st, i) ((OPENSSL_BLOCK)sk_value(CHECKED_STACK_OF(OPENSSL_BLOCK, st), i))
+#define sk_OPENSSL_BLOCK_num(st) SKM_sk_num(OPENSSL_BLOCK, st)
+#define sk_OPENSSL_BLOCK_pop_free(st, free_func) sk_pop_free(CHECKED_STACK_OF(OPENSSL_BLOCK, st), CHECKED_SK_FREE_FUNC2(OPENSSL_BLOCK, free_func))
+#define sk_OPENSSL_BLOCK_insert(st, val, i) sk_insert(CHECKED_STACK_OF(OPENSSL_BLOCK, st), CHECKED_PTR_OF(void, val), i)
+#define sk_OPENSSL_BLOCK_free(st) SKM_sk_free(OPENSSL_BLOCK, st)
+#define sk_OPENSSL_BLOCK_set(st, i, val) sk_set(CHECKED_STACK_OF(OPENSSL_BLOCK, st), i, CHECKED_PTR_OF(void, val))
+#define sk_OPENSSL_BLOCK_zero(st) SKM_sk_zero(OPENSSL_BLOCK, (st))
+#define sk_OPENSSL_BLOCK_unshift(st, val) sk_unshift(CHECKED_STACK_OF(OPENSSL_BLOCK, st), CHECKED_PTR_OF(void, val))
+#define sk_OPENSSL_BLOCK_find_ex(st, val) sk_find_ex((_STACK *)CHECKED_CONST_PTR_OF(STACK_OF(OPENSSL_BLOCK), st), CHECKED_CONST_PTR_OF(void, val))
+#define sk_OPENSSL_BLOCK_delete(st, i) SKM_sk_delete(OPENSSL_BLOCK, (st), (i))
+#define sk_OPENSSL_BLOCK_delete_ptr(st, ptr) (OPENSSL_BLOCK *)sk_delete_ptr(CHECKED_STACK_OF(OPENSSL_BLOCK, st), CHECKED_PTR_OF(void, ptr))
+#define sk_OPENSSL_BLOCK_set_cmp_func(st, cmp)  \
+       ((int (*)(const void * const *,const void * const *)) \
+       sk_set_cmp_func(CHECKED_STACK_OF(OPENSSL_BLOCK, st), CHECKED_SK_CMP_FUNC(void, cmp)))
+#define sk_OPENSSL_BLOCK_dup(st) SKM_sk_dup(OPENSSL_BLOCK, st)
+#define sk_OPENSSL_BLOCK_shift(st) SKM_sk_shift(OPENSSL_BLOCK, (st))
+#define sk_OPENSSL_BLOCK_pop(st) (void *)sk_pop(CHECKED_STACK_OF(OPENSSL_BLOCK, st))
+#define sk_OPENSSL_BLOCK_sort(st) SKM_sk_sort(OPENSSL_BLOCK, (st))
+#define sk_OPENSSL_BLOCK_is_sorted(st) SKM_sk_is_sorted(OPENSSL_BLOCK, (st))
+
+
 #define d2i_ASN1_SET_OF_ACCESS_DESCRIPTION(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
        SKM_ASN1_SET_OF_d2i(ACCESS_DESCRIPTION, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) 
 #define i2d_ASN1_SET_OF_ACCESS_DESCRIPTION(st, pp, i2d_func, ex_tag, ex_class, is_set) \
@@ -1814,6 +2142,15 @@ STACK_OF(type) \
 #define ASN1_seq_unpack_ASN1_TYPE(buf, len, d2i_func, free_func) \
        SKM_ASN1_seq_unpack(ASN1_TYPE, (buf), (len), (d2i_func), (free_func))
 
+#define d2i_ASN1_SET_OF_ASN1_UTF8STRING(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
+       SKM_ASN1_SET_OF_d2i(ASN1_UTF8STRING, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) 
+#define i2d_ASN1_SET_OF_ASN1_UTF8STRING(st, pp, i2d_func, ex_tag, ex_class, is_set) \
+       SKM_ASN1_SET_OF_i2d(ASN1_UTF8STRING, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
+#define ASN1_seq_pack_ASN1_UTF8STRING(st, i2d_func, buf, len) \
+       SKM_ASN1_seq_pack(ASN1_UTF8STRING, (st), (i2d_func), (buf), (len))
+#define ASN1_seq_unpack_ASN1_UTF8STRING(buf, len, d2i_func, free_func) \
+       SKM_ASN1_seq_unpack(ASN1_UTF8STRING, (buf), (len), (d2i_func), (free_func))
+
 #define d2i_ASN1_SET_OF_DIST_POINT(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
        SKM_ASN1_SET_OF_d2i(DIST_POINT, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) 
 #define i2d_ASN1_SET_OF_DIST_POINT(st, pp, i2d_func, ex_tag, ex_class, is_set) \
@@ -1823,6 +2160,24 @@ STACK_OF(type) \
 #define ASN1_seq_unpack_DIST_POINT(buf, len, d2i_func, free_func) \
        SKM_ASN1_seq_unpack(DIST_POINT, (buf), (len), (d2i_func), (free_func))
 
+#define d2i_ASN1_SET_OF_ESS_CERT_ID(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
+       SKM_ASN1_SET_OF_d2i(ESS_CERT_ID, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) 
+#define i2d_ASN1_SET_OF_ESS_CERT_ID(st, pp, i2d_func, ex_tag, ex_class, is_set) \
+       SKM_ASN1_SET_OF_i2d(ESS_CERT_ID, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
+#define ASN1_seq_pack_ESS_CERT_ID(st, i2d_func, buf, len) \
+       SKM_ASN1_seq_pack(ESS_CERT_ID, (st), (i2d_func), (buf), (len))
+#define ASN1_seq_unpack_ESS_CERT_ID(buf, len, d2i_func, free_func) \
+       SKM_ASN1_seq_unpack(ESS_CERT_ID, (buf), (len), (d2i_func), (free_func))
+
+#define d2i_ASN1_SET_OF_EVP_MD(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
+       SKM_ASN1_SET_OF_d2i(EVP_MD, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) 
+#define i2d_ASN1_SET_OF_EVP_MD(st, pp, i2d_func, ex_tag, ex_class, is_set) \
+       SKM_ASN1_SET_OF_i2d(EVP_MD, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
+#define ASN1_seq_pack_EVP_MD(st, i2d_func, buf, len) \
+       SKM_ASN1_seq_pack(EVP_MD, (st), (i2d_func), (buf), (len))
+#define ASN1_seq_unpack_EVP_MD(buf, len, d2i_func, free_func) \
+       SKM_ASN1_seq_unpack(EVP_MD, (buf), (len), (d2i_func), (free_func))
+
 #define d2i_ASN1_SET_OF_GENERAL_NAME(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
        SKM_ASN1_SET_OF_d2i(GENERAL_NAME, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) 
 #define i2d_ASN1_SET_OF_GENERAL_NAME(st, pp, i2d_func, ex_tag, ex_class, is_set) \
@@ -1981,6 +2336,240 @@ STACK_OF(type) \
 
 #define PKCS12_decrypt_d2i_PKCS7(algor, d2i_func, free_func, pass, passlen, oct, seq) \
        SKM_PKCS12_decrypt_d2i(PKCS7, (algor), (d2i_func), (free_func), (pass), (passlen), (oct), (seq))
+
+#define lh_ADDED_OBJ_new() LHM_lh_new(ADDED_OBJ,added_obj)
+#define lh_ADDED_OBJ_insert(lh,inst) LHM_lh_insert(ADDED_OBJ,lh,inst)
+#define lh_ADDED_OBJ_retrieve(lh,inst) LHM_lh_retrieve(ADDED_OBJ,lh,inst)
+#define lh_ADDED_OBJ_delete(lh,inst) LHM_lh_delete(ADDED_OBJ,lh,inst)
+#define lh_ADDED_OBJ_doall(lh,fn) LHM_lh_doall(ADDED_OBJ,lh,fn)
+#define lh_ADDED_OBJ_doall_arg(lh,fn,arg_type,arg) \
+  LHM_lh_doall_arg(ADDED_OBJ,lh,fn,arg_type,arg)
+#define lh_ADDED_OBJ_error(lh) LHM_lh_error(ADDED_OBJ,lh)
+#define lh_ADDED_OBJ_num_items(lh) LHM_lh_num_items(ADDED_OBJ,lh)
+#define lh_ADDED_OBJ_down_load(lh) LHM_lh_down_load(ADDED_OBJ,lh)
+#define lh_ADDED_OBJ_node_stats_bio(lh,out) \
+  LHM_lh_node_stats_bio(ADDED_OBJ,lh,out)
+#define lh_ADDED_OBJ_node_usage_stats_bio(lh,out) \
+  LHM_lh_node_usage_stats_bio(ADDED_OBJ,lh,out)
+#define lh_ADDED_OBJ_stats_bio(lh,out) \
+  LHM_lh_stats_bio(ADDED_OBJ,lh,out)
+#define lh_ADDED_OBJ_free(lh) LHM_lh_free(ADDED_OBJ,lh)
+
+#define lh_APP_INFO_new() LHM_lh_new(APP_INFO,app_info)
+#define lh_APP_INFO_insert(lh,inst) LHM_lh_insert(APP_INFO,lh,inst)
+#define lh_APP_INFO_retrieve(lh,inst) LHM_lh_retrieve(APP_INFO,lh,inst)
+#define lh_APP_INFO_delete(lh,inst) LHM_lh_delete(APP_INFO,lh,inst)
+#define lh_APP_INFO_doall(lh,fn) LHM_lh_doall(APP_INFO,lh,fn)
+#define lh_APP_INFO_doall_arg(lh,fn,arg_type,arg) \
+  LHM_lh_doall_arg(APP_INFO,lh,fn,arg_type,arg)
+#define lh_APP_INFO_error(lh) LHM_lh_error(APP_INFO,lh)
+#define lh_APP_INFO_num_items(lh) LHM_lh_num_items(APP_INFO,lh)
+#define lh_APP_INFO_down_load(lh) LHM_lh_down_load(APP_INFO,lh)
+#define lh_APP_INFO_node_stats_bio(lh,out) \
+  LHM_lh_node_stats_bio(APP_INFO,lh,out)
+#define lh_APP_INFO_node_usage_stats_bio(lh,out) \
+  LHM_lh_node_usage_stats_bio(APP_INFO,lh,out)
+#define lh_APP_INFO_stats_bio(lh,out) \
+  LHM_lh_stats_bio(APP_INFO,lh,out)
+#define lh_APP_INFO_free(lh) LHM_lh_free(APP_INFO,lh)
+
+#define lh_CONF_VALUE_new() LHM_lh_new(CONF_VALUE,conf_value)
+#define lh_CONF_VALUE_insert(lh,inst) LHM_lh_insert(CONF_VALUE,lh,inst)
+#define lh_CONF_VALUE_retrieve(lh,inst) LHM_lh_retrieve(CONF_VALUE,lh,inst)
+#define lh_CONF_VALUE_delete(lh,inst) LHM_lh_delete(CONF_VALUE,lh,inst)
+#define lh_CONF_VALUE_doall(lh,fn) LHM_lh_doall(CONF_VALUE,lh,fn)
+#define lh_CONF_VALUE_doall_arg(lh,fn,arg_type,arg) \
+  LHM_lh_doall_arg(CONF_VALUE,lh,fn,arg_type,arg)
+#define lh_CONF_VALUE_error(lh) LHM_lh_error(CONF_VALUE,lh)
+#define lh_CONF_VALUE_num_items(lh) LHM_lh_num_items(CONF_VALUE,lh)
+#define lh_CONF_VALUE_down_load(lh) LHM_lh_down_load(CONF_VALUE,lh)
+#define lh_CONF_VALUE_node_stats_bio(lh,out) \
+  LHM_lh_node_stats_bio(CONF_VALUE,lh,out)
+#define lh_CONF_VALUE_node_usage_stats_bio(lh,out) \
+  LHM_lh_node_usage_stats_bio(CONF_VALUE,lh,out)
+#define lh_CONF_VALUE_stats_bio(lh,out) \
+  LHM_lh_stats_bio(CONF_VALUE,lh,out)
+#define lh_CONF_VALUE_free(lh) LHM_lh_free(CONF_VALUE,lh)
+
+#define lh_ENGINE_PILE_new() LHM_lh_new(ENGINE_PILE,engine_pile)
+#define lh_ENGINE_PILE_insert(lh,inst) LHM_lh_insert(ENGINE_PILE,lh,inst)
+#define lh_ENGINE_PILE_retrieve(lh,inst) LHM_lh_retrieve(ENGINE_PILE,lh,inst)
+#define lh_ENGINE_PILE_delete(lh,inst) LHM_lh_delete(ENGINE_PILE,lh,inst)
+#define lh_ENGINE_PILE_doall(lh,fn) LHM_lh_doall(ENGINE_PILE,lh,fn)
+#define lh_ENGINE_PILE_doall_arg(lh,fn,arg_type,arg) \
+  LHM_lh_doall_arg(ENGINE_PILE,lh,fn,arg_type,arg)
+#define lh_ENGINE_PILE_error(lh) LHM_lh_error(ENGINE_PILE,lh)
+#define lh_ENGINE_PILE_num_items(lh) LHM_lh_num_items(ENGINE_PILE,lh)
+#define lh_ENGINE_PILE_down_load(lh) LHM_lh_down_load(ENGINE_PILE,lh)
+#define lh_ENGINE_PILE_node_stats_bio(lh,out) \
+  LHM_lh_node_stats_bio(ENGINE_PILE,lh,out)
+#define lh_ENGINE_PILE_node_usage_stats_bio(lh,out) \
+  LHM_lh_node_usage_stats_bio(ENGINE_PILE,lh,out)
+#define lh_ENGINE_PILE_stats_bio(lh,out) \
+  LHM_lh_stats_bio(ENGINE_PILE,lh,out)
+#define lh_ENGINE_PILE_free(lh) LHM_lh_free(ENGINE_PILE,lh)
+
+#define lh_ERR_STATE_new() LHM_lh_new(ERR_STATE,err_state)
+#define lh_ERR_STATE_insert(lh,inst) LHM_lh_insert(ERR_STATE,lh,inst)
+#define lh_ERR_STATE_retrieve(lh,inst) LHM_lh_retrieve(ERR_STATE,lh,inst)
+#define lh_ERR_STATE_delete(lh,inst) LHM_lh_delete(ERR_STATE,lh,inst)
+#define lh_ERR_STATE_doall(lh,fn) LHM_lh_doall(ERR_STATE,lh,fn)
+#define lh_ERR_STATE_doall_arg(lh,fn,arg_type,arg) \
+  LHM_lh_doall_arg(ERR_STATE,lh,fn,arg_type,arg)
+#define lh_ERR_STATE_error(lh) LHM_lh_error(ERR_STATE,lh)
+#define lh_ERR_STATE_num_items(lh) LHM_lh_num_items(ERR_STATE,lh)
+#define lh_ERR_STATE_down_load(lh) LHM_lh_down_load(ERR_STATE,lh)
+#define lh_ERR_STATE_node_stats_bio(lh,out) \
+  LHM_lh_node_stats_bio(ERR_STATE,lh,out)
+#define lh_ERR_STATE_node_usage_stats_bio(lh,out) \
+  LHM_lh_node_usage_stats_bio(ERR_STATE,lh,out)
+#define lh_ERR_STATE_stats_bio(lh,out) \
+  LHM_lh_stats_bio(ERR_STATE,lh,out)
+#define lh_ERR_STATE_free(lh) LHM_lh_free(ERR_STATE,lh)
+
+#define lh_ERR_STRING_DATA_new() LHM_lh_new(ERR_STRING_DATA,err_string_data)
+#define lh_ERR_STRING_DATA_insert(lh,inst) LHM_lh_insert(ERR_STRING_DATA,lh,inst)
+#define lh_ERR_STRING_DATA_retrieve(lh,inst) LHM_lh_retrieve(ERR_STRING_DATA,lh,inst)
+#define lh_ERR_STRING_DATA_delete(lh,inst) LHM_lh_delete(ERR_STRING_DATA,lh,inst)
+#define lh_ERR_STRING_DATA_doall(lh,fn) LHM_lh_doall(ERR_STRING_DATA,lh,fn)
+#define lh_ERR_STRING_DATA_doall_arg(lh,fn,arg_type,arg) \
+  LHM_lh_doall_arg(ERR_STRING_DATA,lh,fn,arg_type,arg)
+#define lh_ERR_STRING_DATA_error(lh) LHM_lh_error(ERR_STRING_DATA,lh)
+#define lh_ERR_STRING_DATA_num_items(lh) LHM_lh_num_items(ERR_STRING_DATA,lh)
+#define lh_ERR_STRING_DATA_down_load(lh) LHM_lh_down_load(ERR_STRING_DATA,lh)
+#define lh_ERR_STRING_DATA_node_stats_bio(lh,out) \
+  LHM_lh_node_stats_bio(ERR_STRING_DATA,lh,out)
+#define lh_ERR_STRING_DATA_node_usage_stats_bio(lh,out) \
+  LHM_lh_node_usage_stats_bio(ERR_STRING_DATA,lh,out)
+#define lh_ERR_STRING_DATA_stats_bio(lh,out) \
+  LHM_lh_stats_bio(ERR_STRING_DATA,lh,out)
+#define lh_ERR_STRING_DATA_free(lh) LHM_lh_free(ERR_STRING_DATA,lh)
+
+#define lh_EX_CLASS_ITEM_new() LHM_lh_new(EX_CLASS_ITEM,ex_class_item)
+#define lh_EX_CLASS_ITEM_insert(lh,inst) LHM_lh_insert(EX_CLASS_ITEM,lh,inst)
+#define lh_EX_CLASS_ITEM_retrieve(lh,inst) LHM_lh_retrieve(EX_CLASS_ITEM,lh,inst)
+#define lh_EX_CLASS_ITEM_delete(lh,inst) LHM_lh_delete(EX_CLASS_ITEM,lh,inst)
+#define lh_EX_CLASS_ITEM_doall(lh,fn) LHM_lh_doall(EX_CLASS_ITEM,lh,fn)
+#define lh_EX_CLASS_ITEM_doall_arg(lh,fn,arg_type,arg) \
+  LHM_lh_doall_arg(EX_CLASS_ITEM,lh,fn,arg_type,arg)
+#define lh_EX_CLASS_ITEM_error(lh) LHM_lh_error(EX_CLASS_ITEM,lh)
+#define lh_EX_CLASS_ITEM_num_items(lh) LHM_lh_num_items(EX_CLASS_ITEM,lh)
+#define lh_EX_CLASS_ITEM_down_load(lh) LHM_lh_down_load(EX_CLASS_ITEM,lh)
+#define lh_EX_CLASS_ITEM_node_stats_bio(lh,out) \
+  LHM_lh_node_stats_bio(EX_CLASS_ITEM,lh,out)
+#define lh_EX_CLASS_ITEM_node_usage_stats_bio(lh,out) \
+  LHM_lh_node_usage_stats_bio(EX_CLASS_ITEM,lh,out)
+#define lh_EX_CLASS_ITEM_stats_bio(lh,out) \
+  LHM_lh_stats_bio(EX_CLASS_ITEM,lh,out)
+#define lh_EX_CLASS_ITEM_free(lh) LHM_lh_free(EX_CLASS_ITEM,lh)
+
+#define lh_FUNCTION_new() LHM_lh_new(FUNCTION,function)
+#define lh_FUNCTION_insert(lh,inst) LHM_lh_insert(FUNCTION,lh,inst)
+#define lh_FUNCTION_retrieve(lh,inst) LHM_lh_retrieve(FUNCTION,lh,inst)
+#define lh_FUNCTION_delete(lh,inst) LHM_lh_delete(FUNCTION,lh,inst)
+#define lh_FUNCTION_doall(lh,fn) LHM_lh_doall(FUNCTION,lh,fn)
+#define lh_FUNCTION_doall_arg(lh,fn,arg_type,arg) \
+  LHM_lh_doall_arg(FUNCTION,lh,fn,arg_type,arg)
+#define lh_FUNCTION_error(lh) LHM_lh_error(FUNCTION,lh)
+#define lh_FUNCTION_num_items(lh) LHM_lh_num_items(FUNCTION,lh)
+#define lh_FUNCTION_down_load(lh) LHM_lh_down_load(FUNCTION,lh)
+#define lh_FUNCTION_node_stats_bio(lh,out) \
+  LHM_lh_node_stats_bio(FUNCTION,lh,out)
+#define lh_FUNCTION_node_usage_stats_bio(lh,out) \
+  LHM_lh_node_usage_stats_bio(FUNCTION,lh,out)
+#define lh_FUNCTION_stats_bio(lh,out) \
+  LHM_lh_stats_bio(FUNCTION,lh,out)
+#define lh_FUNCTION_free(lh) LHM_lh_free(FUNCTION,lh)
+
+#define lh_MEM_new() LHM_lh_new(MEM,mem)
+#define lh_MEM_insert(lh,inst) LHM_lh_insert(MEM,lh,inst)
+#define lh_MEM_retrieve(lh,inst) LHM_lh_retrieve(MEM,lh,inst)
+#define lh_MEM_delete(lh,inst) LHM_lh_delete(MEM,lh,inst)
+#define lh_MEM_doall(lh,fn) LHM_lh_doall(MEM,lh,fn)
+#define lh_MEM_doall_arg(lh,fn,arg_type,arg) \
+  LHM_lh_doall_arg(MEM,lh,fn,arg_type,arg)
+#define lh_MEM_error(lh) LHM_lh_error(MEM,lh)
+#define lh_MEM_num_items(lh) LHM_lh_num_items(MEM,lh)
+#define lh_MEM_down_load(lh) LHM_lh_down_load(MEM,lh)
+#define lh_MEM_node_stats_bio(lh,out) \
+  LHM_lh_node_stats_bio(MEM,lh,out)
+#define lh_MEM_node_usage_stats_bio(lh,out) \
+  LHM_lh_node_usage_stats_bio(MEM,lh,out)
+#define lh_MEM_stats_bio(lh,out) \
+  LHM_lh_stats_bio(MEM,lh,out)
+#define lh_MEM_free(lh) LHM_lh_free(MEM,lh)
+
+#define lh_OBJ_NAME_new() LHM_lh_new(OBJ_NAME,obj_name)
+#define lh_OBJ_NAME_insert(lh,inst) LHM_lh_insert(OBJ_NAME,lh,inst)
+#define lh_OBJ_NAME_retrieve(lh,inst) LHM_lh_retrieve(OBJ_NAME,lh,inst)
+#define lh_OBJ_NAME_delete(lh,inst) LHM_lh_delete(OBJ_NAME,lh,inst)
+#define lh_OBJ_NAME_doall(lh,fn) LHM_lh_doall(OBJ_NAME,lh,fn)
+#define lh_OBJ_NAME_doall_arg(lh,fn,arg_type,arg) \
+  LHM_lh_doall_arg(OBJ_NAME,lh,fn,arg_type,arg)
+#define lh_OBJ_NAME_error(lh) LHM_lh_error(OBJ_NAME,lh)
+#define lh_OBJ_NAME_num_items(lh) LHM_lh_num_items(OBJ_NAME,lh)
+#define lh_OBJ_NAME_down_load(lh) LHM_lh_down_load(OBJ_NAME,lh)
+#define lh_OBJ_NAME_node_stats_bio(lh,out) \
+  LHM_lh_node_stats_bio(OBJ_NAME,lh,out)
+#define lh_OBJ_NAME_node_usage_stats_bio(lh,out) \
+  LHM_lh_node_usage_stats_bio(OBJ_NAME,lh,out)
+#define lh_OBJ_NAME_stats_bio(lh,out) \
+  LHM_lh_stats_bio(OBJ_NAME,lh,out)
+#define lh_OBJ_NAME_free(lh) LHM_lh_free(OBJ_NAME,lh)
+
+#define lh_OPENSSL_CSTRING_new() LHM_lh_new(OPENSSL_CSTRING,openssl_cstring)
+#define lh_OPENSSL_CSTRING_insert(lh,inst) LHM_lh_insert(OPENSSL_CSTRING,lh,inst)
+#define lh_OPENSSL_CSTRING_retrieve(lh,inst) LHM_lh_retrieve(OPENSSL_CSTRING,lh,inst)
+#define lh_OPENSSL_CSTRING_delete(lh,inst) LHM_lh_delete(OPENSSL_CSTRING,lh,inst)
+#define lh_OPENSSL_CSTRING_doall(lh,fn) LHM_lh_doall(OPENSSL_CSTRING,lh,fn)
+#define lh_OPENSSL_CSTRING_doall_arg(lh,fn,arg_type,arg) \
+  LHM_lh_doall_arg(OPENSSL_CSTRING,lh,fn,arg_type,arg)
+#define lh_OPENSSL_CSTRING_error(lh) LHM_lh_error(OPENSSL_CSTRING,lh)
+#define lh_OPENSSL_CSTRING_num_items(lh) LHM_lh_num_items(OPENSSL_CSTRING,lh)
+#define lh_OPENSSL_CSTRING_down_load(lh) LHM_lh_down_load(OPENSSL_CSTRING,lh)
+#define lh_OPENSSL_CSTRING_node_stats_bio(lh,out) \
+  LHM_lh_node_stats_bio(OPENSSL_CSTRING,lh,out)
+#define lh_OPENSSL_CSTRING_node_usage_stats_bio(lh,out) \
+  LHM_lh_node_usage_stats_bio(OPENSSL_CSTRING,lh,out)
+#define lh_OPENSSL_CSTRING_stats_bio(lh,out) \
+  LHM_lh_stats_bio(OPENSSL_CSTRING,lh,out)
+#define lh_OPENSSL_CSTRING_free(lh) LHM_lh_free(OPENSSL_CSTRING,lh)
+
+#define lh_OPENSSL_STRING_new() LHM_lh_new(OPENSSL_STRING,openssl_string)
+#define lh_OPENSSL_STRING_insert(lh,inst) LHM_lh_insert(OPENSSL_STRING,lh,inst)
+#define lh_OPENSSL_STRING_retrieve(lh,inst) LHM_lh_retrieve(OPENSSL_STRING,lh,inst)
+#define lh_OPENSSL_STRING_delete(lh,inst) LHM_lh_delete(OPENSSL_STRING,lh,inst)
+#define lh_OPENSSL_STRING_doall(lh,fn) LHM_lh_doall(OPENSSL_STRING,lh,fn)
+#define lh_OPENSSL_STRING_doall_arg(lh,fn,arg_type,arg) \
+  LHM_lh_doall_arg(OPENSSL_STRING,lh,fn,arg_type,arg)
+#define lh_OPENSSL_STRING_error(lh) LHM_lh_error(OPENSSL_STRING,lh)
+#define lh_OPENSSL_STRING_num_items(lh) LHM_lh_num_items(OPENSSL_STRING,lh)
+#define lh_OPENSSL_STRING_down_load(lh) LHM_lh_down_load(OPENSSL_STRING,lh)
+#define lh_OPENSSL_STRING_node_stats_bio(lh,out) \
+  LHM_lh_node_stats_bio(OPENSSL_STRING,lh,out)
+#define lh_OPENSSL_STRING_node_usage_stats_bio(lh,out) \
+  LHM_lh_node_usage_stats_bio(OPENSSL_STRING,lh,out)
+#define lh_OPENSSL_STRING_stats_bio(lh,out) \
+  LHM_lh_stats_bio(OPENSSL_STRING,lh,out)
+#define lh_OPENSSL_STRING_free(lh) LHM_lh_free(OPENSSL_STRING,lh)
+
+#define lh_SSL_SESSION_new() LHM_lh_new(SSL_SESSION,ssl_session)
+#define lh_SSL_SESSION_insert(lh,inst) LHM_lh_insert(SSL_SESSION,lh,inst)
+#define lh_SSL_SESSION_retrieve(lh,inst) LHM_lh_retrieve(SSL_SESSION,lh,inst)
+#define lh_SSL_SESSION_delete(lh,inst) LHM_lh_delete(SSL_SESSION,lh,inst)
+#define lh_SSL_SESSION_doall(lh,fn) LHM_lh_doall(SSL_SESSION,lh,fn)
+#define lh_SSL_SESSION_doall_arg(lh,fn,arg_type,arg) \
+  LHM_lh_doall_arg(SSL_SESSION,lh,fn,arg_type,arg)
+#define lh_SSL_SESSION_error(lh) LHM_lh_error(SSL_SESSION,lh)
+#define lh_SSL_SESSION_num_items(lh) LHM_lh_num_items(SSL_SESSION,lh)
+#define lh_SSL_SESSION_down_load(lh) LHM_lh_down_load(SSL_SESSION,lh)
+#define lh_SSL_SESSION_node_stats_bio(lh,out) \
+  LHM_lh_node_stats_bio(SSL_SESSION,lh,out)
+#define lh_SSL_SESSION_node_usage_stats_bio(lh,out) \
+  LHM_lh_node_usage_stats_bio(SSL_SESSION,lh,out)
+#define lh_SSL_SESSION_stats_bio(lh,out) \
+  LHM_lh_stats_bio(SSL_SESSION,lh,out)
+#define lh_SSL_SESSION_free(lh) LHM_lh_free(SSL_SESSION,lh)
 /* End of util/mkstack.pl block, you may now edit :-) */
 
 #endif /* !defined HEADER_SAFESTACK_H */
index 378bd7c..76cf1a1 100644 (file)
@@ -77,10 +77,10 @@ const char STACK_version[]="Stack" OPENSSL_VERSION_PTEXT;
 
 #include <errno.h>
 
-int (*sk_set_cmp_func(STACK *sk, int (*c)(const char * const *,const char * const *)))
-               (const char * const *, const char * const *)
+int (*sk_set_cmp_func(_STACK *sk, int (*c)(const void *, const void *)))
+               (const void *, const void *)
        {
-       int (*old)(const char * const *,const char * const *)=sk->comp;
+       int (*old)(const void *,const void *)=sk->comp;
 
        if (sk->comp != c)
                sk->sorted=0;
@@ -89,9 +89,9 @@ int (*sk_set_cmp_func(STACK *sk, int (*c)(const char * const *,const char * cons
        return old;
        }
 
-STACK *sk_dup(STACK *sk)
+_STACK *sk_dup(_STACK *sk)
        {
-       STACK *ret;
+       _STACK *ret;
        char **s;
 
        if ((ret=sk_new(sk->comp)) == NULL) goto err;
@@ -112,19 +112,19 @@ err:
        return(NULL);
        }
 
-STACK *sk_new_null(void)
+_STACK *sk_new_null(void)
        {
-       return sk_new((int (*)(const char * const *, const char * const *))0);
+       return sk_new((int (*)(const void *, const void *))0);
        }
 
-STACK *sk_new(int (*c)(const char * const *, const char * const *))
+_STACK *sk_new(int (*c)(const void *, const void *))
        {
-       STACK *ret;
+       _STACK *ret;
        int i;
 
-       if ((ret=(STACK *)OPENSSL_malloc(sizeof(STACK))) == NULL)
+       if ((ret=OPENSSL_malloc(sizeof(_STACK))) == NULL)
                goto err;
-       if ((ret->data=(char **)OPENSSL_malloc(sizeof(char *)*MIN_NODES)) == NULL)
+       if ((ret->data=OPENSSL_malloc(sizeof(char *)*MIN_NODES)) == NULL)
                goto err;
        for (i=0; i<MIN_NODES; i++)
                ret->data[i]=NULL;
@@ -139,14 +139,14 @@ err:
        return(NULL);
        }
 
-int sk_insert(STACK *st, char *data, int loc)
+int sk_insert(_STACK *st, void *data, int loc)
        {
        char **s;
 
        if(st == NULL) return 0;
        if (st->num_alloc <= st->num+1)
                {
-               s=(char **)OPENSSL_realloc((char *)st->data,
+               s=OPENSSL_realloc((char *)st->data,
                        (unsigned int)sizeof(char *)*st->num_alloc*2);
                if (s == NULL)
                        return(0);
@@ -160,14 +160,14 @@ int sk_insert(STACK *st, char *data, int loc)
                int i;
                char **f,**t;
 
-               f=(char **)st->data;
-               t=(char **)&(st->data[1]);
+               f=st->data;
+               t=&(st->data[1]);
                for (i=st->num; i>=loc; i--)
                        t[i]=f[i];
                        
 #ifdef undef /* no memmove on sunos :-( */
-               memmove( (char *)&(st->data[loc+1]),
-                       (char *)&(st->data[loc]),
+               memmove(&(st->data[loc+1]),
+                       &(st->data[loc]),
                        sizeof(char *)*(st->num-loc));
 #endif
                st->data[loc]=data;
@@ -177,7 +177,7 @@ int sk_insert(STACK *st, char *data, int loc)
        return(st->num);
        }
 
-char *sk_delete_ptr(STACK *st, char *p)
+void *sk_delete_ptr(_STACK *st, void *p)
        {
        int i;
 
@@ -187,7 +187,7 @@ char *sk_delete_ptr(STACK *st, char *p)
        return(NULL);
        }
 
-char *sk_delete(STACK *st, int loc)
+void *sk_delete(_STACK *st, int loc)
        {
        char *ret;
        int i,j;
@@ -210,11 +210,11 @@ char *sk_delete(STACK *st, int loc)
        return(ret);
        }
 
-static int internal_find(STACK *st, char *data, int ret_val_options)
+static int internal_find(_STACK *st, void *data, int ret_val_options)
        {
-       char **r;
+       const void * const *r;
        int i;
-       int (*comp_func)(const void *,const void *);
+
        if(st == NULL) return -1;
 
        if (st->comp == NULL)
@@ -226,53 +226,46 @@ static int internal_find(STACK *st, char *data, int ret_val_options)
                }
        sk_sort(st);
        if (data == NULL) return(-1);
-       /* This (and the "qsort" below) are the two places in OpenSSL
-        * where we need to convert from our standard (type **,type **)
-        * compare callback type to the (void *,void *) type required by
-        * bsearch. However, the "data" it is being called(back) with are
-        * not (type *) pointers, but the *pointers* to (type *) pointers,
-        * so we get our extra level of pointer dereferencing that way. */
-       comp_func=(int (*)(const void *,const void *))(st->comp);
-       r=(char **)OBJ_bsearch_ex((char *)&data,(char *)st->data,
-               st->num,sizeof(char *),comp_func,ret_val_options);
+       r=OBJ_bsearch_ex_(&data,st->data,st->num,sizeof(void *),st->comp,
+                         ret_val_options);
        if (r == NULL) return(-1);
-       return((int)(r-st->data));
+       return (int)((char **)r-st->data);
        }
 
-int sk_find(STACK *st, char *data)
+int sk_find(_STACK *st, void *data)
        {
        return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);
        }
-int sk_find_ex(STACK *st, char *data)
+int sk_find_ex(_STACK *st, void *data)
        {
        return internal_find(st, data, OBJ_BSEARCH_VALUE_ON_NOMATCH);
        }
 
-int sk_push(STACK *st, char *data)
+int sk_push(_STACK *st, void *data)
        {
        return(sk_insert(st,data,st->num));
        }
 
-int sk_unshift(STACK *st, char *data)
+int sk_unshift(_STACK *st, void *data)
        {
        return(sk_insert(st,data,0));
        }
 
-char *sk_shift(STACK *st)
+void *sk_shift(_STACK *st)
        {
        if (st == NULL) return(NULL);
        if (st->num <= 0) return(NULL);
        return(sk_delete(st,0));
        }
 
-char *sk_pop(STACK *st)
+void *sk_pop(_STACK *st)
        {
        if (st == NULL) return(NULL);
        if (st->num <= 0) return(NULL);
        return(sk_delete(st,st->num-1));
        }
 
-void sk_zero(STACK *st)
+void sk_zero(_STACK *st)
        {
        if (st == NULL) return;
        if (st->num <= 0) return;
@@ -280,7 +273,7 @@ void sk_zero(STACK *st)
        st->num=0;
        }
 
-void sk_pop_free(STACK *st, void (*func)(void *))
+void sk_pop_free(_STACK *st, void (*func)(void *))
        {
        int i;
 
@@ -291,32 +284,32 @@ void sk_pop_free(STACK *st, void (*func)(void *))
        sk_free(st);
        }
 
-void sk_free(STACK *st)
+void sk_free(_STACK *st)
        {
        if (st == NULL) return;
        if (st->data != NULL) OPENSSL_free(st->data);
        OPENSSL_free(st);
        }
 
-int sk_num(const STACK *st)
+int sk_num(const _STACK *st)
 {
        if(st == NULL) return -1;
        return st->num;
 }
 
-char *sk_value(const STACK *st, int i)
+void *sk_value(const _STACK *st, int i)
 {
        if(!st || (i < 0) || (i >= st->num)) return NULL;
        return st->data[i];
 }
 
-char *sk_set(STACK *st, int i, char *value)
+void *sk_set(_STACK *st, int i, void *value)
 {
        if(!st || (i < 0) || (i >= st->num)) return NULL;
        return (st->data[i] = value);
 }
 
-void sk_sort(STACK *st)
+void sk_sort(_STACK *st)
        {
        if (st && !st->sorted)
                {
@@ -333,7 +326,7 @@ void sk_sort(STACK *st)
                }
        }
 
-int sk_is_sorted(const STACK *st)
+int sk_is_sorted(const _STACK *st)
        {
        if (!st)
                return 1;
index 5cbb116..ce35e55 100644 (file)
@@ -70,37 +70,36 @@ typedef struct stack_st
        int sorted;
 
        int num_alloc;
-       int (*comp)(const char * const *, const char * const *);
-       } STACK;
+       int (*comp)(const void *, const void *);
+       } _STACK;  /* Use STACK_OF(...) instead */
 
 #define M_sk_num(sk)           ((sk) ? (sk)->num:-1)
 #define M_sk_value(sk,n)       ((sk) ? (sk)->data[n] : NULL)
 
-int sk_num(const STACK *);
-char *sk_value(const STACK *, int);
+int sk_num(const _STACK *);
+void *sk_value(const _STACK *, int);
 
-char *sk_set(STACK *, int, char *);
+void *sk_set(_STACK *, int, void *);
 
-STACK *sk_new(int (*cmp)(const char * const *, const char * const *));
-STACK *sk_new_null(void);
-void sk_free(STACK *);
-void sk_pop_free(STACK *st, void (*func)(void *));
-int sk_insert(STACK *sk,char *data,int where);
-char *sk_delete(STACK *st,int loc);
-char *sk_delete_ptr(STACK *st, char *p);
-int sk_find(STACK *st,char *data);
-int sk_find_ex(STACK *st,char *data);
-int sk_push(STACK *st,char *data);
-int sk_unshift(STACK *st,char *data);
-char *sk_shift(STACK *st);
-char *sk_pop(STACK *st);
-void sk_zero(STACK *st);
-int (*sk_set_cmp_func(STACK *sk, int (*c)(const char * const *,
-                       const char * const *)))
-                       (const char * const *, const char * const *);
-STACK *sk_dup(STACK *st);
-void sk_sort(STACK *st);
-int sk_is_sorted(const STACK *st);
+_STACK *sk_new(int (*cmp)(const void *, const void *));
+_STACK *sk_new_null(void);
+void sk_free(_STACK *);
+void sk_pop_free(_STACK *st, void (*func)(void *));
+int sk_insert(_STACK *sk, void *data, int where);
+void *sk_delete(_STACK *st, int loc);
+void *sk_delete_ptr(_STACK *st, void *p);
+int sk_find(_STACK *st, void *data);
+int sk_find_ex(_STACK *st, void *data);
+int sk_push(_STACK *st, void *data);
+int sk_unshift(_STACK *st, void *data);
+void *sk_shift(_STACK *st);
+void *sk_pop(_STACK *st);
+void sk_zero(_STACK *st);
+int (*sk_set_cmp_func(_STACK *sk, int (*c)(const void *, const void *)))
+       (const void *, const void *);
+_STACK *sk_dup(_STACK *st);
+void sk_sort(_STACK *st);
+int sk_is_sorted(const _STACK *st);
 
 #ifdef  __cplusplus
 }
index c9f5d00..0dcfd78 100644 (file)
@@ -35,7 +35,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -89,14 +89,14 @@ str_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 str_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 str_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
 str_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-str_lib.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-str_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-str_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-str_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-str_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-str_lib.o: ../../include/openssl/stack.h ../../include/openssl/store.h
-str_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-str_lib.o: ../../include/openssl/x509_vfy.h str_lib.c str_locl.h
+str_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+str_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+str_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+str_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+str_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+str_lib.o: ../../include/openssl/store.h ../../include/openssl/symhacks.h
+str_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+str_lib.o: str_lib.c str_locl.h
 str_mem.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
 str_mem.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
 str_mem.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
index 6458337..0a28c7d 100644 (file)
 #ifndef HEADER_STORE_H
 #define HEADER_STORE_H
 
+#include <openssl/opensslconf.h>
+
+#ifdef OPENSSL_NO_STORE
+#error STORE is disabled.
+#endif
+
 #include <openssl/ossl_typ.h>
 #ifndef OPENSSL_NO_DEPRECATED
 #include <openssl/evp.h>
@@ -408,7 +414,8 @@ int STORE_ATTR_INFO_modify_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
 
 /* Compare on basis of a bit pattern formed by the STORE_ATTR_TYPES values
    in each contained attribute. */
-int STORE_ATTR_INFO_compare(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b);
+int STORE_ATTR_INFO_compare(const STORE_ATTR_INFO * const *a,
+                           const STORE_ATTR_INFO * const *b);
 /* Check if the set of attributes in a is within the range of attributes
    set in b. */
 int STORE_ATTR_INFO_in_range(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b);
index 6fee649..924edf0 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/store/str_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
index 32ae5bd..f1dbcbd 100644 (file)
@@ -1670,7 +1670,7 @@ int STORE_parse_attrs_endp(void *handle)
        }
 
 static int attr_info_compare_compute_range(
-       unsigned char *abits, unsigned char *bbits,
+       const unsigned char *abits, const unsigned char *bbits,
        unsigned int *alowp, unsigned int *ahighp,
        unsigned int *blowp, unsigned int *bhighp)
        {
@@ -1739,13 +1739,15 @@ static int attr_info_compare_compute_range(
        return res;
        }
 
-int STORE_ATTR_INFO_compare(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
+int STORE_ATTR_INFO_compare(const STORE_ATTR_INFO * const *a,
+                           const STORE_ATTR_INFO * const *b)
        {
        if (a == b) return 0;
        if (!a) return -1;
        if (!b) return 1;
-       return attr_info_compare_compute_range(a->set, b->set, 0, 0, 0, 0);
+       return attr_info_compare_compute_range((*a)->set, (*b)->set, 0, 0, 0, 0);
        }
+
 int STORE_ATTR_INFO_in_range(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
        {
        unsigned int alow, ahigh, blow, bhigh;
@@ -1759,6 +1761,7 @@ int STORE_ATTR_INFO_in_range(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
                return 1;
        return 0;
        }
+
 int STORE_ATTR_INFO_in(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
        {
        unsigned char *abits, *bbits;
@@ -1776,6 +1779,7 @@ int STORE_ATTR_INFO_in(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
                }
        return 1;
        }
+
 int STORE_ATTR_INFO_in_ex(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
        {
        STORE_ATTR_TYPES i;
index 527757a..8ac4f7e 100644 (file)
    attribute type code).
 */
 
-struct mem_object_data_st
+typedef struct mem_object_data_st
        {
        STORE_OBJECT *object;
        STORE_ATTR_INFO *attr_info;
        int references;
-       };
+       } MEM_OBJECT_DATA;
 
+DECLARE_STACK_OF(MEM_OBJECT_DATA)
 struct mem_data_st
        {
-       STACK *data;            /* A stack of mem_object_data_st,
-                                  sorted with STORE_ATTR_INFO_compare(). */
+       STACK_OF(MEM_OBJECT_DATA) *data; /* sorted with
+                                         * STORE_ATTR_INFO_compare(). */
        unsigned int compute_components : 1; /* Currently unused, but can
                                                be used to add attributes
                                                from parts of the data. */
        };
 
+DECLARE_STACK_OF(STORE_ATTR_INFO)
 struct mem_ctx_st
        {
        int type;               /* The type we're searching for */
-       STACK *search_attributes; /* Sets of attributes to search for.
-                                    Each element is a STORE_ATTR_INFO. */
-       int search_index;       /* which of the search attributes we found a match
-                                  for, -1 when we still haven't found any */
-       int index;              /* -1 as long as we're searching for the first */
+       STACK_OF(STORE_ATTR_INFO) *search_attributes; /* Sets of
+                                    attributes to search for.  Each
+                                    element is a STORE_ATTR_INFO. */
+       int search_index;       /* which of the search attributes we
+                                  found a match for, -1 when we still
+                                  haven't found any */
+       int index;              /* -1 as long as we're searching for
+                                    the first */
        };
 
 static int mem_init(STORE *s);
@@ -240,7 +245,7 @@ static void *mem_list_start(STORE *s, STORE_OBJECT_TYPES type,
                if (context->search_attributes == NULL)
                        {
                        context->search_attributes =
-                               sk_new((int (*)(const char * const *, const char * const *))STORE_ATTR_INFO_compare);
+                               sk_STORE_ATTR_INFO_new(STORE_ATTR_INFO_compare);
                        if (!context->search_attributes)
                                {
                                STOREerr(STORE_F_MEM_LIST_START,
@@ -248,7 +253,7 @@ static void *mem_list_start(STORE *s, STORE_OBJECT_TYPES type,
                                goto err;
                                }
                        }
-               sk_push(context->search_attributes,(char *)attrs);
+               sk_STORE_ATTR_INFO_push(context->search_attributes,attrs);
                }
        if (!STORE_parse_attrs_endp(attribute_context))
                goto err;
@@ -284,11 +289,14 @@ static STORE_OBJECT *mem_list_next(STORE *s, void *handle)
 
        if (context->search_index == -1)
                {
-               for (i = 0; i < sk_num(context->search_attributes); i++)
+               for (i = 0;
+                    i < sk_STORE_ATTR_INFO_num(context->search_attributes);
+                    i++)
                        {
-                       key.attr_info =
-                               (STORE_ATTR_INFO *)sk_value(context->search_attributes, i);
-                       srch = sk_find_ex(store->data, (char *)&key);
+                       key.attr_info
+                         = sk_STORE_ATTR_INFO_value(context->search_attributes,
+                                                    i);
+                       srch = sk_MEM_OBJECT_DATA_find_ex(store->data, &key);
 
                        if (srch >= 0)
                                {
@@ -301,21 +309,20 @@ static STORE_OBJECT *mem_list_next(STORE *s, void *handle)
                return NULL;
        
        key.attr_info =
-               (STORE_ATTR_INFO *)sk_value(context->search_attributes,
-                       context->search_index);
+               sk_STORE_ATTR_INFO_value(context->search_attributes,
+                                        context->search_index);
        for(srch = context->search_index;
-           srch < sk_num(store->data)
+           srch < sk_MEM_OBJECT_DATA_num(store->data)
                    && STORE_ATTR_INFO_in_range(key.attr_info,
-                           (STORE_ATTR_INFO *)sk_value(store->data, srch))
+                           sk_MEM_OBJECT_DATA_value(store->data, srch)->attr_info)
                    && !(cres = STORE_ATTR_INFO_in_ex(key.attr_info,
-                                (STORE_ATTR_INFO *)sk_value(store->data, srch)));
+                                sk_MEM_OBJECT_DATA_value(store->data, srch)->attr_info));
            srch++)
                ;
 
        context->search_index = srch;
        if (cres)
-               return ((struct mem_object_data_st *)sk_value(store->data,
-                               srch))->object;
+               return (sk_MEM_OBJECT_DATA_value(store->data, srch))->object;
        return NULL;
        }
 static int mem_list_end(STORE *s, void *handle)
@@ -328,7 +335,7 @@ static int mem_list_end(STORE *s, void *handle)
                return 0;
                }
        if (context && context->search_attributes)
-               sk_free(context->search_attributes);
+               sk_STORE_ATTR_INFO_free(context->search_attributes);
        if (context) OPENSSL_free(context);
        return 1;
        }
@@ -337,7 +344,8 @@ static int mem_list_endp(STORE *s, void *handle)
        struct mem_ctx_st *context = (struct mem_ctx_st *)handle;
 
        if (!context
-               || context->search_index == sk_num(context->search_attributes))
+           || context->search_index
+              == sk_STORE_ATTR_INFO_num(context->search_attributes))
                return 1;
        return 0;
        }
index 0114093..3fd4a81 100644 (file)
    incompatibilities. */
 #ifdef OPENSSL_SYS_VMS
 
-/* Hack a long name in crypto/cryptlib.c */
-#undef int_CRYPTO_set_do_dynlock_callback
-#define int_CRYPTO_set_do_dynlock_callback     int_CRYPTO_set_do_dynlock_cb
-
 /* Hack a long name in crypto/ex_data.c */
 #undef CRYPTO_get_ex_data_implementation
 #define CRYPTO_get_ex_data_implementation      CRYPTO_get_ex_data_impl
 #undef CRYPTO_set_dynlock_create_callback
 #define CRYPTO_set_dynlock_create_callback      CRYPTO_set_dynlock_create_cb
 #undef CRYPTO_set_dynlock_lock_callback
-#define CRYPTO_set_dynlock_lock_callback        CRYPTO_set_dynlock_lock_cb
+#define CRYPTO_set_dynlock_lock_callback       CRYPTO_set_dynlock_lock_cb
 #undef CRYPTO_get_dynlock_lock_callback
-#define CRYPTO_get_dynlock_lock_callback        CRYPTO_get_dynlock_lock_cb
+#define CRYPTO_get_dynlock_lock_callback       CRYPTO_get_dynlock_lock_cb
 #undef CRYPTO_get_dynlock_destroy_callback
 #define CRYPTO_get_dynlock_destroy_callback     CRYPTO_get_dynlock_destroy_cb
 #undef CRYPTO_get_dynlock_create_callback
 
 /* Hack some long SSL names */
 #undef SSL_CTX_set_default_verify_paths
-#define SSL_CTX_set_default_verify_paths        SSL_CTX_set_def_verify_paths
+#define SSL_CTX_set_default_verify_paths       SSL_CTX_set_def_verify_paths
 #undef SSL_get_ex_data_X509_STORE_CTX_idx
 #define SSL_get_ex_data_X509_STORE_CTX_idx      SSL_get_ex_d_X509_STORE_CTX_idx
 #undef SSL_add_file_cert_subjects_to_stack
 #undef SSL_CTX_use_certificate_chain_file
 #define SSL_CTX_use_certificate_chain_file      SSL_CTX_use_cert_chain_file
 #undef SSL_CTX_set_cert_verify_callback
-#define SSL_CTX_set_cert_verify_callback        SSL_CTX_set_cert_verify_cb
+#define SSL_CTX_set_cert_verify_callback       SSL_CTX_set_cert_verify_cb
 #undef SSL_CTX_set_default_passwd_cb_userdata
 #define SSL_CTX_set_default_passwd_cb_userdata  SSL_CTX_set_def_passwd_cb_ud
 #undef SSL_COMP_get_compression_methods
 #undef ENGINE_set_default_BN_mod_exp_crt
 #define ENGINE_set_default_BN_mod_exp_crt      ENGINE_set_def_BN_mod_exp_crt
 #undef ENGINE_set_load_privkey_function
-#define ENGINE_set_load_privkey_function        ENGINE_set_load_privkey_fn
+#define ENGINE_set_load_privkey_function       ENGINE_set_load_privkey_fn
 #undef ENGINE_get_load_privkey_function
-#define ENGINE_get_load_privkey_function        ENGINE_get_load_privkey_fn
+#define ENGINE_get_load_privkey_function       ENGINE_get_load_privkey_fn
+#undef ENGINE_unregister_pkey_asn1_meths
+#define ENGINE_unregister_pkey_asn1_meths      ENGINE_unreg_pkey_asn1_meths
+#undef ENGINE_register_all_pkey_asn1_meths
+#define ENGINE_register_all_pkey_asn1_meths    ENGINE_reg_all_pkey_asn1_meths
+#undef ENGINE_set_default_pkey_asn1_meths
+#define ENGINE_set_default_pkey_asn1_meths     ENGINE_set_def_pkey_asn1_meths
+#undef ENGINE_get_pkey_asn1_meth_engine
+#define ENGINE_get_pkey_asn1_meth_engine       ENGINE_get_pkey_asn1_meth_eng
 #undef ENGINE_set_load_ssl_client_cert_function
 #define ENGINE_set_load_ssl_client_cert_function \
                                                ENGINE_set_ld_ssl_clnt_cert_fn
 
 /* Hack some long OCSP names */
 #undef OCSP_REQUEST_get_ext_by_critical
-#define OCSP_REQUEST_get_ext_by_critical        OCSP_REQUEST_get_ext_by_crit
+#define OCSP_REQUEST_get_ext_by_critical       OCSP_REQUEST_get_ext_by_crit
 #undef OCSP_BASICRESP_get_ext_by_critical
 #define OCSP_BASICRESP_get_ext_by_critical      OCSP_BASICRESP_get_ext_by_crit
 #undef OCSP_SINGLERESP_get_ext_by_critical
 #define OPENSSL_add_all_algorithms_noconf      OPENSSL_add_all_algo_noconf
 #undef OPENSSL_add_all_algorithms_conf
 #define OPENSSL_add_all_algorithms_conf                OPENSSL_add_all_algo_conf
+#undef EVP_PKEY_meth_set_verify_recover
+#define EVP_PKEY_meth_set_verify_recover       EVP_PKEY_meth_set_vrfy_recover
 
 /* Hack some long EC names */
 #undef EC_GROUP_set_point_conversion_form
 #define EC_POINT_set_compressed_coordinates_GF2m \
                                                 EC_POINT_set_compr_coords_GF2m
 #undef ec_GF2m_simple_group_clear_finish
-#define ec_GF2m_simple_group_clear_finish        ec_GF2m_simple_grp_clr_finish
+#define ec_GF2m_simple_group_clear_finish      ec_GF2m_simple_grp_clr_finish
 #undef ec_GF2m_simple_group_check_discriminant
 #define ec_GF2m_simple_group_check_discriminant        ec_GF2m_simple_grp_chk_discrim
 #undef ec_GF2m_simple_point_clear_finish
-#define ec_GF2m_simple_point_clear_finish        ec_GF2m_simple_pt_clr_finish
+#define ec_GF2m_simple_point_clear_finish      ec_GF2m_simple_pt_clr_finish
 #undef ec_GF2m_simple_point_set_to_infinity
-#define ec_GF2m_simple_point_set_to_infinity     ec_GF2m_simple_pt_set_to_inf
+#define ec_GF2m_simple_point_set_to_infinity   ec_GF2m_simple_pt_set_to_inf
 #undef ec_GF2m_simple_points_make_affine
-#define ec_GF2m_simple_points_make_affine        ec_GF2m_simple_pts_make_affine
+#define ec_GF2m_simple_points_make_affine      ec_GF2m_simple_pts_make_affine
 #undef ec_GF2m_simple_point_set_affine_coordinates
 #define ec_GF2m_simple_point_set_affine_coordinates \
                                                 ec_GF2m_smp_pt_set_af_coords
 #undef ec_GFp_simple_group_get_curve_GFp
 #define ec_GFp_simple_group_get_curve_GFp       ec_GFp_simple_grp_get_curve_GFp
 #undef ec_GFp_simple_group_clear_finish
-#define ec_GFp_simple_group_clear_finish        ec_GFp_simple_grp_clear_finish
+#define ec_GFp_simple_group_clear_finish       ec_GFp_simple_grp_clear_finish
 #undef ec_GFp_simple_group_set_generator
 #define ec_GFp_simple_group_set_generator       ec_GFp_simple_grp_set_generator
 #undef ec_GFp_simple_group_get0_generator
 #define ec_GFp_simple_group_get0_generator      ec_GFp_simple_grp_gt0_generator
 #undef ec_GFp_simple_group_get_cofactor
-#define ec_GFp_simple_group_get_cofactor        ec_GFp_simple_grp_get_cofactor
+#define ec_GFp_simple_group_get_cofactor       ec_GFp_simple_grp_get_cofactor
 #undef ec_GFp_simple_point_clear_finish
-#define ec_GFp_simple_point_clear_finish        ec_GFp_simple_pt_clear_finish
+#define ec_GFp_simple_point_clear_finish       ec_GFp_simple_pt_clear_finish
 #undef ec_GFp_simple_point_set_to_infinity
 #define ec_GFp_simple_point_set_to_infinity     ec_GFp_simple_pt_set_to_inf
 #undef ec_GFp_simple_points_make_affine
-#define ec_GFp_simple_points_make_affine        ec_GFp_simple_pts_make_affine
+#define ec_GFp_simple_points_make_affine       ec_GFp_simple_pts_make_affine
 #undef ec_GFp_simple_group_get_curve_GFp
 #define ec_GFp_simple_group_get_curve_GFp       ec_GFp_simple_grp_get_curve_GFp
 #undef ec_GFp_simple_set_Jprojective_coordinates_GFp
 #undef STORE_method_get_unlock_store_function
 #define STORE_method_get_unlock_store_function STORE_meth_get_unlock_store_fn
 
+/* Hack some long TS names */
+#undef TS_RESP_CTX_set_status_info_cond
+#define TS_RESP_CTX_set_status_info_cond       TS_RESP_CTX_set_stat_info_cond
+#undef TS_RESP_CTX_set_clock_precision_digits
+#define TS_RESP_CTX_set_clock_precision_digits TS_RESP_CTX_set_clk_prec_digits
+#undef TS_CONF_set_clock_precision_digits
+#define TS_CONF_set_clock_precision_digits     TS_CONF_set_clk_prec_digits
+
 /* Hack some long CMS names */
 #undef CMS_RecipientInfo_ktri_get0_algs
 #define CMS_RecipientInfo_ktri_get0_algs       CMS_RecipInfo_ktri_get0_algs
 #undef dtls1_retransmit_buffered_messages
 #define dtls1_retransmit_buffered_messages     dtls1_retransmit_buffered_msgs
 
+/* Hack some long UI names */
+#undef UI_method_get_prompt_constructor
+#define UI_method_get_prompt_constructor       UI_method_get_prompt_constructr
+#undef UI_method_set_prompt_constructor
+#define UI_method_set_prompt_constructor       UI_method_set_prompt_constructr
+
 #endif /* defined OPENSSL_SYS_VMS */
 
 
-/* Case insensiteve linking causes problems.... */
-#if defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_OS2)
+/* Case insensitive linking causes problems.... */
+#if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_OS2)
 #undef ERR_load_CRYPTO_strings
 #define ERR_load_CRYPTO_strings                        ERR_load_CRYPTOlib_strings
 #undef OCSP_crlID_new
-#define OCSP_crlID_new                          OCSP_crlID2_new
+#define OCSP_crlID_new                         OCSP_crlID2_new
 
 #undef d2i_ECPARAMETERS
-#define d2i_ECPARAMETERS                        d2i_UC_ECPARAMETERS
+#define d2i_ECPARAMETERS                       d2i_UC_ECPARAMETERS
 #undef i2d_ECPARAMETERS
-#define i2d_ECPARAMETERS                        i2d_UC_ECPARAMETERS
+#define i2d_ECPARAMETERS                       i2d_UC_ECPARAMETERS
 #undef d2i_ECPKPARAMETERS
-#define d2i_ECPKPARAMETERS                      d2i_UC_ECPKPARAMETERS
+#define d2i_ECPKPARAMETERS                     d2i_UC_ECPKPARAMETERS
 #undef i2d_ECPKPARAMETERS
-#define i2d_ECPKPARAMETERS                      i2d_UC_ECPKPARAMETERS
+#define i2d_ECPKPARAMETERS                     i2d_UC_ECPKPARAMETERS
 
 /* These functions do not seem to exist!  However, I'm paranoid...
    Original command in x509v3.h:
    hide them a little, by giving them an extra 'o' at the
    beginning of the name... */
 #undef X509v3_cleanup_extensions
-#define X509v3_cleanup_extensions               oX509v3_cleanup_extensions
+#define X509v3_cleanup_extensions              oX509v3_cleanup_extensions
 #undef X509v3_add_extension
-#define X509v3_add_extension                    oX509v3_add_extension
+#define X509v3_add_extension                   oX509v3_add_extension
 #undef X509v3_add_netscape_extensions
-#define X509v3_add_netscape_extensions          oX509v3_add_netscape_extensions
+#define X509v3_add_netscape_extensions         oX509v3_add_netscape_extensions
 #undef X509v3_add_standard_extensions
-#define X509v3_add_standard_extensions          oX509v3_add_standard_extensions
+#define X509v3_add_standard_extensions         oX509v3_add_standard_extensions
 
+/* This one clashes with CMS_data_create */
+#undef cms_Data_create
+#define cms_Data_create                                priv_cms_Data_create
 
 #endif
 
 
 #endif /* ! defined HEADER_VMS_IDHACKS_H */
-/* This one clashes with CMS_data_create */
-#undef cms_Data_create
-#define cms_Data_create                                priv_cms_Data_create
index f6f3df4..eba7aa8 100644 (file)
@@ -117,11 +117,13 @@ void solaris_locking_callback(int mode,int type,char *file,int line);
 void win32_locking_callback(int mode,int type,char *file,int line);
 void pthreads_locking_callback(int mode,int type,char *file,int line);
 void netware_locking_callback(int mode,int type,char *file,int line);
+void beos_locking_callback(int mode,int type,const char *file,int line);
 
 unsigned long irix_thread_id(void );
 unsigned long solaris_thread_id(void );
 unsigned long pthreads_thread_id(void );
 unsigned long netware_thread_id(void );
+unsigned long beos_thread_id(void );
 
 #if defined(OPENSSL_SYS_NETWARE)
 static MPKMutex *lock_cs;
@@ -1209,3 +1211,100 @@ unsigned long netware_thread_id(void)
    return(ret);
 }
 #endif /* NETWARE */
+
+#ifdef BEOS_THREADS
+
+#include <Locker.h>
+
+static BLocker** lock_cs;
+static long* lock_count;
+
+void thread_setup(void)
+       {
+       int i;
+
+       lock_cs=(BLocker**)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(BLocker*));
+       lock_count=(long*)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(long));
+       for (i=0; i<CRYPTO_num_locks(); i++)
+               {
+               lock_count[i]=0;
+               lock_cs[i] = new BLocker(CRYPTO_get_lock_name(i));
+               }
+
+       CRYPTO_set_id_callback((unsigned long (*)())beos_thread_id);
+       CRYPTO_set_locking_callback(beos_locking_callback);
+       }
+
+void thread_cleanup(void)
+       {
+       int i;
+
+       CRYPTO_set_locking_callback(NULL);
+       fprintf(stderr,"cleanup\n");
+       for (i=0; i<CRYPTO_num_locks(); i++)
+               {
+               delete lock_cs[i];
+               fprintf(stderr,"%8ld:%s\n",lock_count[i],
+                       CRYPTO_get_lock_name(i));
+               }
+       OPENSSL_free(lock_cs);
+       OPENSSL_free(lock_count);
+
+       fprintf(stderr,"done cleanup\n");
+       }
+
+void beos_locking_callback(int mode, int type, const char *file, int line)
+    {
+#if 0
+       fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
+               CRYPTO_thread_id(),
+               (mode&CRYPTO_LOCK)?"l":"u",
+               (type&CRYPTO_READ)?"r":"w",file,line);
+#endif
+       if (mode & CRYPTO_LOCK)
+               {
+               lock_cs[type]->Lock();
+               lock_count[type]++;
+               }
+       else
+               {
+               lock_cs[type]->Unlock();
+               }
+       }
+
+void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx)
+       {
+       SSL_CTX *ssl_ctx[2];
+       thread_id thread_ctx[MAX_THREAD_NUMBER];
+       int i;
+
+       ssl_ctx[0]=s_ctx;
+       ssl_ctx[1]=c_ctx;
+
+       for (i=0; i<thread_number; i++)
+               {
+               thread_ctx[i] = spawn_thread((thread_func)ndoit,
+                       NULL, B_NORMAL_PRIORITY, (void *)ssl_ctx);
+               resume_thread(thread_ctx[i]);
+               }
+
+       printf("waiting...\n");
+       for (i=0; i<thread_number; i++)
+               {
+               status_t result;
+               wait_for_thread(thread_ctx[i], &result);
+               }
+
+       printf("beos threads done (%d,%d)\n",
+               s_ctx->references,c_ctx->references);
+       }
+
+unsigned long beos_thread_id(void)
+       {
+       unsigned long ret;
+
+       ret=(unsigned long)find_thread(NULL);
+       return(ret);
+       }
+
+#endif /* BEOS_THREADS */
diff --git a/deps/openssl/openssl/crypto/tmdiff.c b/deps/openssl/openssl/crypto/tmdiff.c
deleted file mode 100644 (file)
index 1c6e052..0000000
+++ /dev/null
@@ -1,260 +0,0 @@
-/* crypto/tmdiff.c */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include "cryptlib.h"
-#include <openssl/tmdiff.h>
-#if !defined(OPENSSL_SYS_MSDOS)
-#include OPENSSL_UNISTD
-#endif
-
-#ifdef TIMEB
-#undef OPENSSL_SYS_WIN32
-#undef TIMES
-#endif
-
-#if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN32) && !(defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX_RHAPSODY) && !defined(OPENSSL_SYS_VXWORKS)
-# define TIMES
-#endif
-
-#ifdef OPENSSL_SYS_NETWARE
-#undef TIMES
-#endif
-
-#if !defined(_IRIX) || defined (OPENSSL_SYS_NETWARE)
-#  include <time.h>
-#endif
-#ifdef TIMES
-#  include <sys/types.h>
-#  include <sys/times.h>
-#endif
-
-/* Depending on the VMS version, the tms structure is perhaps defined.
-   The __TMS macro will show if it was.  If it wasn't defined, we should
-   undefine TIMES, since that tells the rest of the program how things
-   should be handled.                          -- Richard Levitte */
-#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
-#undef TIMES
-#endif
-
-#if defined(sun) || defined(__ultrix)
-#define _POSIX_SOURCE
-#include <limits.h>
-#include <sys/param.h>
-#endif
-
-#if !defined(TIMES) && !defined(OPENSSL_SYS_VXWORKS) && !defined(OPENSSL_SYS_NETWARE)
-#include <sys/timeb.h>
-#endif
-
-#ifdef OPENSSL_SYS_WIN32
-#include <windows.h>
-#endif
-
-/* The following if from times(3) man page.  It may need to be changed */
-#ifndef HZ
-# if defined(_SC_CLK_TCK) \
-     && (!defined(OPENSSL_SYS_VMS) || __CTRL_VER >= 70000000)
-/* #  define HZ ((double)sysconf(_SC_CLK_TCK)) */
-#  define HZ sysconf(_SC_CLK_TCK)
-# else
-#  ifndef CLK_TCK
-#   ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
-#    define HZ  100.0
-#   else /* _BSD_CLK_TCK_ */
-#    define HZ ((double)_BSD_CLK_TCK_)
-#   endif
-#  else /* CLK_TCK */
-#   define HZ ((double)CLK_TCK)
-#  endif
-# endif
-#endif
-
-struct ms_tm
-       {
-#ifdef TIMES
-       struct tms ms_tms;
-#else
-#  ifdef OPENSSL_SYS_WIN32
-       HANDLE thread_id;
-       FILETIME ms_win32;
-#  elif defined (OPENSSL_SYS_NETWARE)
-   clock_t ms_clock;
-#  else
-#    ifdef OPENSSL_SYS_VXWORKS
-          unsigned long ticks;
-#    else
-       struct timeb ms_timeb;
-#    endif
-#  endif
-#endif
-       };
-
-MS_TM *ms_time_new(void)
-       {
-       MS_TM *ret;
-
-       ret=(MS_TM *)OPENSSL_malloc(sizeof(MS_TM));
-       if (ret == NULL)
-               return(NULL);
-       memset(ret,0,sizeof(MS_TM));
-#ifdef OPENSSL_SYS_WIN32
-       ret->thread_id=GetCurrentThread();
-#endif
-       return ret;
-       }
-
-void ms_time_free(MS_TM *a)
-       {
-       if (a != NULL)
-               OPENSSL_free(a);
-       }
-
-void ms_time_get(MS_TM *tm)
-       {
-#ifdef OPENSSL_SYS_WIN32
-       FILETIME tmpa,tmpb,tmpc;
-#endif
-
-#ifdef TIMES
-       times(&tm->ms_tms);
-#else
-#  ifdef OPENSSL_SYS_WIN32
-       GetThreadTimes(tm->thread_id,&tmpa,&tmpb,&tmpc,&(tm->ms_win32));
-#  elif defined (OPENSSL_SYS_NETWARE)
-   tm->ms_clock = clock();
-#  else
-#    ifdef OPENSSL_SYS_VXWORKS
-        tm->ticks = tickGet();
-#    else
-       ftime(&tm->ms_timeb);
-#    endif
-#  endif
-#endif
-       }
-
-double ms_time_diff(MS_TM *a, MS_TM *b)
-       {
-       double ret;
-
-#ifdef TIMES
-       ret = HZ;
-       ret = (b->ms_tms.tms_utime-a->ms_tms.tms_utime) / ret;
-#else
-# ifdef OPENSSL_SYS_WIN32
-       {
-#ifdef __GNUC__
-       signed long long la,lb;
-#else
-       signed _int64 la,lb;
-#endif
-       la=a->ms_win32.dwHighDateTime;
-       lb=b->ms_win32.dwHighDateTime;
-       la<<=32;
-       lb<<=32;
-       la+=a->ms_win32.dwLowDateTime;
-       lb+=b->ms_win32.dwLowDateTime;
-       ret=((double)(lb-la))/1e7;
-       }
-# elif defined (OPENSSL_SYS_NETWARE)
-    ret= (double)(b->ms_clock - a->ms_clock);
-# else
-#  ifdef OPENSSL_SYS_VXWORKS
-        ret = (double)(b->ticks - a->ticks) / (double)sysClkRateGet();
-#  else
-       ret=     (double)(b->ms_timeb.time-a->ms_timeb.time)+
-               (((double)b->ms_timeb.millitm)-
-               ((double)a->ms_timeb.millitm))/1000.0;
-#  endif
-# endif
-#endif
-       return((ret < 0.0000001)?0.0000001:ret);
-       }
-
-int ms_time_cmp(const MS_TM *a, const MS_TM *b)
-       {
-       double d;
-       int ret;
-
-#ifdef TIMES
-       d = HZ;
-       d = (b->ms_tms.tms_utime-a->ms_tms.tms_utime) / d;
-#else
-# ifdef OPENSSL_SYS_WIN32
-       d =(b->ms_win32.dwHighDateTime&0x000fffff)*10+b->ms_win32.dwLowDateTime/1e7;
-       d-=(a->ms_win32.dwHighDateTime&0x000fffff)*10+a->ms_win32.dwLowDateTime/1e7;
-# elif defined (OPENSSL_SYS_NETWARE)
-    d= (double)(b->ms_clock - a->ms_clock);
-# else
-#  ifdef OPENSSL_SYS_VXWORKS
-        d = (b->ticks - a->ticks);
-#  else
-       d=       (double)(b->ms_timeb.time-a->ms_timeb.time)+
-               (((double)b->ms_timeb.millitm)-(double)a->ms_timeb.millitm)/1000.0;
-#  endif
-# endif
-#endif
-       if (d == 0.0)
-               ret=0;
-       else if (d < 0)
-               ret= -1;
-       else
-               ret=1;
-       return(ret);
-       }
-
diff --git a/deps/openssl/openssl/crypto/tmdiff.h b/deps/openssl/openssl/crypto/tmdiff.h
deleted file mode 100644 (file)
index af5c41c..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/* crypto/tmdiff.h */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-/* Header for dynamic hash table routines
- * Author - Eric Young
- */
-/* ... erm yeah, "dynamic hash tables" you say?
- * 
- * And what would dynamic hash tables have to do with any of this code *now*?
- * AFAICS, this code is only referenced by crypto/bn/exp.c which is an unused
- * file that I doubt compiles any more. speed.c is the only thing that could
- * use this (and it has nothing to do with hash tables), yet it instead has its
- * own duplication of all this stuff and looks, if anything, more complete. See
- * the corresponding note in apps/speed.c.
- * The Bemused - Geoff
- */
-
-#ifndef HEADER_TMDIFF_H
-#define HEADER_TMDIFF_H
-
-#ifdef  __cplusplus
-extern "C" {
-#endif
-
-typedef struct ms_tm MS_TM;
-
-MS_TM *ms_time_new(void );
-void ms_time_free(MS_TM *a);
-void ms_time_get(MS_TM *a);
-double ms_time_diff(MS_TM *start, MS_TM *end);
-int ms_time_cmp(const MS_TM *ap, const MS_TM *bp);
-
-#ifdef  __cplusplus
-}
-#endif
-
-#endif
-
diff --git a/deps/openssl/openssl/crypto/ts/Makefile b/deps/openssl/openssl/crypto/ts/Makefile
new file mode 100644 (file)
index 0000000..c182345
--- /dev/null
@@ -0,0 +1,269 @@
+#
+# SSLeay/crypto/ts/Makefile
+#
+
+DIR=   ts
+TOP=   ../..
+CC=    cc
+INCLUDES= -I.. -I../../include
+CFLAG = -g
+INSTALL_PREFIX=
+OPENSSLDIR=     /usr/local/ssl
+INSTALLTOP=/usr/local/ssl
+MAKEDEPPROG=   makedepend
+MAKEDEPEND=    $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
+MAKEFILE=      Makefile
+AR=            ar r
+
+PEX_LIBS=
+EX_LIBS=
+CFLAGS= $(INCLUDES) $(CFLAG)
+
+GENERAL= Makefile
+TEST=
+APPS=
+
+LIB=$(TOP)/libcrypto.a
+LIBSRC=        ts_err.c ts_req_utils.c ts_req_print.c ts_rsp_utils.c ts_rsp_print.c \
+       ts_rsp_sign.c ts_rsp_verify.c ts_verify_ctx.c ts_lib.c ts_conf.c \
+       ts_asn1.c
+LIBOBJ= ts_err.o ts_req_utils.o ts_req_print.o ts_rsp_utils.o ts_rsp_print.o \
+       ts_rsp_sign.o ts_rsp_verify.o ts_verify_ctx.o ts_lib.o ts_conf.o \
+       ts_asn1.o
+
+SRC= $(LIBSRC)
+
+EXHEADER= ts.h
+HEADER=        $(EXHEADER)
+
+ALL=    $(GENERAL) $(SRC) $(HEADER)
+
+top:
+       (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
+
+test:
+
+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)
+
+lint:
+       lint -DLINT $(INCLUDES) $(SRC)>fluff
+
+depend:
+       $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(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 enc dec sign verify
+
+# DO NOT DELETE THIS LINE -- make depend depends on it.
+
+ts_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
+ts_asn1.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
+ts_asn1.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
+ts_asn1.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
+ts_asn1.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+ts_asn1.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
+ts_asn1.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+ts_asn1.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+ts_asn1.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+ts_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+ts_asn1.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
+ts_asn1.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+ts_asn1.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+ts_asn1.o: ../../include/openssl/ts.h ../../include/openssl/x509.h
+ts_asn1.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+ts_asn1.o: ts_asn1.c
+ts_conf.o: ../../e_os.h ../../include/openssl/asn1.h
+ts_conf.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
+ts_conf.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
+ts_conf.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
+ts_conf.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+ts_conf.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
+ts_conf.o: ../../include/openssl/engine.h ../../include/openssl/err.h
+ts_conf.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+ts_conf.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+ts_conf.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+ts_conf.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
+ts_conf.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
+ts_conf.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+ts_conf.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+ts_conf.o: ../../include/openssl/symhacks.h ../../include/openssl/ts.h
+ts_conf.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+ts_conf.o: ../../include/openssl/x509v3.h ../cryptlib.h ts_conf.c
+ts_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
+ts_err.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
+ts_err.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
+ts_err.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
+ts_err.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+ts_err.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
+ts_err.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+ts_err.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+ts_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+ts_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+ts_err.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+ts_err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+ts_err.o: ../../include/openssl/symhacks.h ../../include/openssl/ts.h
+ts_err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+ts_err.o: ../../include/openssl/x509v3.h ts_err.c
+ts_lib.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
+ts_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
+ts_lib.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
+ts_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
+ts_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+ts_lib.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
+ts_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+ts_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+ts_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+ts_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+ts_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
+ts_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+ts_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+ts_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+ts_lib.o: ../../include/openssl/x509v3.h ../cryptlib.h ts.h ts_lib.c
+ts_req_print.o: ../../e_os.h ../../include/openssl/asn1.h
+ts_req_print.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
+ts_req_print.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
+ts_req_print.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
+ts_req_print.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
+ts_req_print.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+ts_req_print.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
+ts_req_print.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+ts_req_print.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+ts_req_print.o: ../../include/openssl/opensslconf.h
+ts_req_print.o: ../../include/openssl/opensslv.h
+ts_req_print.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+ts_req_print.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+ts_req_print.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+ts_req_print.o: ../../include/openssl/symhacks.h ../../include/openssl/ts.h
+ts_req_print.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+ts_req_print.o: ../../include/openssl/x509v3.h ../cryptlib.h ts_req_print.c
+ts_req_utils.o: ../../e_os.h ../../include/openssl/asn1.h
+ts_req_utils.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
+ts_req_utils.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
+ts_req_utils.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
+ts_req_utils.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+ts_req_utils.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
+ts_req_utils.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+ts_req_utils.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+ts_req_utils.o: ../../include/openssl/objects.h
+ts_req_utils.o: ../../include/openssl/opensslconf.h
+ts_req_utils.o: ../../include/openssl/opensslv.h
+ts_req_utils.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+ts_req_utils.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+ts_req_utils.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+ts_req_utils.o: ../../include/openssl/symhacks.h ../../include/openssl/ts.h
+ts_req_utils.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+ts_req_utils.o: ../../include/openssl/x509v3.h ../cryptlib.h ts_req_utils.c
+ts_rsp_print.o: ../../e_os.h ../../include/openssl/asn1.h
+ts_rsp_print.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
+ts_rsp_print.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
+ts_rsp_print.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
+ts_rsp_print.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
+ts_rsp_print.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+ts_rsp_print.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
+ts_rsp_print.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+ts_rsp_print.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+ts_rsp_print.o: ../../include/openssl/opensslconf.h
+ts_rsp_print.o: ../../include/openssl/opensslv.h
+ts_rsp_print.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+ts_rsp_print.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+ts_rsp_print.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+ts_rsp_print.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+ts_rsp_print.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+ts_rsp_print.o: ../cryptlib.h ts.h ts_rsp_print.c
+ts_rsp_sign.o: ../../e_os.h ../../include/openssl/asn1.h
+ts_rsp_sign.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
+ts_rsp_sign.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
+ts_rsp_sign.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
+ts_rsp_sign.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+ts_rsp_sign.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
+ts_rsp_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+ts_rsp_sign.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+ts_rsp_sign.o: ../../include/openssl/objects.h
+ts_rsp_sign.o: ../../include/openssl/opensslconf.h
+ts_rsp_sign.o: ../../include/openssl/opensslv.h
+ts_rsp_sign.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+ts_rsp_sign.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+ts_rsp_sign.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+ts_rsp_sign.o: ../../include/openssl/symhacks.h ../../include/openssl/ts.h
+ts_rsp_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+ts_rsp_sign.o: ../../include/openssl/x509v3.h ../cryptlib.h ts_rsp_sign.c
+ts_rsp_utils.o: ../../e_os.h ../../include/openssl/asn1.h
+ts_rsp_utils.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
+ts_rsp_utils.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
+ts_rsp_utils.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
+ts_rsp_utils.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+ts_rsp_utils.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
+ts_rsp_utils.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+ts_rsp_utils.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+ts_rsp_utils.o: ../../include/openssl/objects.h
+ts_rsp_utils.o: ../../include/openssl/opensslconf.h
+ts_rsp_utils.o: ../../include/openssl/opensslv.h
+ts_rsp_utils.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+ts_rsp_utils.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+ts_rsp_utils.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+ts_rsp_utils.o: ../../include/openssl/symhacks.h ../../include/openssl/ts.h
+ts_rsp_utils.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+ts_rsp_utils.o: ../../include/openssl/x509v3.h ../cryptlib.h ts_rsp_utils.c
+ts_rsp_verify.o: ../../e_os.h ../../include/openssl/asn1.h
+ts_rsp_verify.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
+ts_rsp_verify.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
+ts_rsp_verify.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
+ts_rsp_verify.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+ts_rsp_verify.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
+ts_rsp_verify.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+ts_rsp_verify.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+ts_rsp_verify.o: ../../include/openssl/objects.h
+ts_rsp_verify.o: ../../include/openssl/opensslconf.h
+ts_rsp_verify.o: ../../include/openssl/opensslv.h
+ts_rsp_verify.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+ts_rsp_verify.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+ts_rsp_verify.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+ts_rsp_verify.o: ../../include/openssl/symhacks.h ../../include/openssl/ts.h
+ts_rsp_verify.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+ts_rsp_verify.o: ../../include/openssl/x509v3.h ../cryptlib.h ts_rsp_verify.c
+ts_verify_ctx.o: ../../e_os.h ../../include/openssl/asn1.h
+ts_verify_ctx.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
+ts_verify_ctx.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
+ts_verify_ctx.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
+ts_verify_ctx.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+ts_verify_ctx.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
+ts_verify_ctx.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+ts_verify_ctx.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+ts_verify_ctx.o: ../../include/openssl/objects.h
+ts_verify_ctx.o: ../../include/openssl/opensslconf.h
+ts_verify_ctx.o: ../../include/openssl/opensslv.h
+ts_verify_ctx.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+ts_verify_ctx.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+ts_verify_ctx.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+ts_verify_ctx.o: ../../include/openssl/symhacks.h ../../include/openssl/ts.h
+ts_verify_ctx.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+ts_verify_ctx.o: ../../include/openssl/x509v3.h ../cryptlib.h ts_verify_ctx.c
diff --git a/deps/openssl/openssl/crypto/ts/ts.h b/deps/openssl/openssl/crypto/ts/ts.h
new file mode 100644 (file)
index 0000000..190e8a1
--- /dev/null
@@ -0,0 +1,861 @@
+/* crypto/ts/ts.h */
+/* Written by Zoltan Glozik (zglozik@opentsa.org) for the OpenSSL
+ * project 2002, 2003, 2004.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#ifndef HEADER_TS_H
+#define HEADER_TS_H
+
+#include <openssl/opensslconf.h>
+#include <openssl/symhacks.h>
+#ifndef OPENSSL_NO_BUFFER
+#include <openssl/buffer.h>
+#endif
+#ifndef OPENSSL_NO_EVP
+#include <openssl/evp.h>
+#endif
+#ifndef OPENSSL_NO_BIO
+#include <openssl/bio.h>
+#endif
+#include <openssl/stack.h>
+#include <openssl/asn1.h>
+#include <openssl/safestack.h>
+
+#ifndef OPENSSL_NO_RSA
+#include <openssl/rsa.h>
+#endif
+
+#ifndef OPENSSL_NO_DSA
+#include <openssl/dsa.h>
+#endif
+
+#ifndef OPENSSL_NO_DH
+#include <openssl/dh.h>
+#endif
+
+#include <openssl/evp.h>
+
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+#ifdef WIN32
+/* Under Win32 this is defined in wincrypt.h */
+#undef X509_NAME
+#endif
+
+#include <openssl/x509.h>
+#include <openssl/x509v3.h>
+
+/*
+MessageImprint ::= SEQUENCE  {
+     hashAlgorithm                AlgorithmIdentifier,
+     hashedMessage                OCTET STRING  }
+*/
+
+typedef struct TS_msg_imprint_st
+       {
+       X509_ALGOR *hash_algo;
+       ASN1_OCTET_STRING *hashed_msg;
+       } TS_MSG_IMPRINT;
+
+/*
+TimeStampReq ::= SEQUENCE  {
+   version                  INTEGER  { v1(1) },
+   messageImprint           MessageImprint,
+     --a hash algorithm OID and the hash value of the data to be
+     --time-stamped
+   reqPolicy                TSAPolicyId                OPTIONAL,
+   nonce                    INTEGER                    OPTIONAL,
+   certReq                  BOOLEAN                    DEFAULT FALSE,
+   extensions               [0] IMPLICIT Extensions    OPTIONAL  }
+*/
+
+typedef struct TS_req_st
+       {
+       ASN1_INTEGER *version;
+       TS_MSG_IMPRINT *msg_imprint;
+       ASN1_OBJECT *policy_id;         /* OPTIONAL */
+       ASN1_INTEGER *nonce;            /* OPTIONAL */
+       ASN1_BOOLEAN cert_req;          /* DEFAULT FALSE */
+       STACK_OF(X509_EXTENSION) *extensions;   /* [0] OPTIONAL */
+       } TS_REQ;
+
+/*
+Accuracy ::= SEQUENCE {
+                seconds        INTEGER           OPTIONAL,
+                millis     [0] INTEGER  (1..999) OPTIONAL,
+                micros     [1] INTEGER  (1..999) OPTIONAL  }
+*/
+
+typedef struct TS_accuracy_st
+       {
+       ASN1_INTEGER *seconds;
+       ASN1_INTEGER *millis;
+       ASN1_INTEGER *micros;
+       } TS_ACCURACY;
+
+/*
+TSTInfo ::= SEQUENCE  {
+    version                      INTEGER  { v1(1) },
+    policy                       TSAPolicyId,
+    messageImprint               MessageImprint,
+      -- MUST have the same value as the similar field in
+      -- TimeStampReq
+    serialNumber                 INTEGER,
+     -- Time-Stamping users MUST be ready to accommodate integers
+     -- up to 160 bits.
+    genTime                      GeneralizedTime,
+    accuracy                     Accuracy                 OPTIONAL,
+    ordering                     BOOLEAN             DEFAULT FALSE,
+    nonce                        INTEGER                  OPTIONAL,
+      -- MUST be present if the similar field was present
+      -- in TimeStampReq.  In that case it MUST have the same value.
+    tsa                          [0] GeneralName          OPTIONAL,
+    extensions                   [1] IMPLICIT Extensions  OPTIONAL   }
+*/
+
+typedef struct TS_tst_info_st
+       {
+       ASN1_INTEGER *version;
+       ASN1_OBJECT *policy_id;
+       TS_MSG_IMPRINT *msg_imprint;
+       ASN1_INTEGER *serial;
+       ASN1_GENERALIZEDTIME *time;
+       TS_ACCURACY *accuracy;
+       ASN1_BOOLEAN ordering;
+       ASN1_INTEGER *nonce;
+       GENERAL_NAME *tsa;
+       STACK_OF(X509_EXTENSION) *extensions;
+       } TS_TST_INFO;  
+
+/*
+PKIStatusInfo ::= SEQUENCE {
+    status        PKIStatus,
+    statusString  PKIFreeText     OPTIONAL,
+    failInfo      PKIFailureInfo  OPTIONAL  }
+
+From RFC 1510 - section 3.1.1:
+PKIFreeText ::= SEQUENCE SIZE (1..MAX) OF UTF8String
+       -- text encoded as UTF-8 String (note:  each UTF8String SHOULD
+       -- include an RFC 1766 language tag to indicate the language
+       -- of the contained text)
+*/
+
+/* Possible values for status. See ts_resp_print.c && ts_resp_verify.c. */
+
+#define        TS_STATUS_GRANTED                       0
+#define        TS_STATUS_GRANTED_WITH_MODS             1
+#define        TS_STATUS_REJECTION                     2
+#define        TS_STATUS_WAITING                       3
+#define        TS_STATUS_REVOCATION_WARNING            4
+#define        TS_STATUS_REVOCATION_NOTIFICATION       5
+
+/* Possible values for failure_info. See ts_resp_print.c && ts_resp_verify.c */
+
+#define        TS_INFO_BAD_ALG                 0
+#define        TS_INFO_BAD_REQUEST             2
+#define        TS_INFO_BAD_DATA_FORMAT         5
+#define        TS_INFO_TIME_NOT_AVAILABLE      14
+#define        TS_INFO_UNACCEPTED_POLICY       15
+#define        TS_INFO_UNACCEPTED_EXTENSION    16
+#define        TS_INFO_ADD_INFO_NOT_AVAILABLE  17
+#define        TS_INFO_SYSTEM_FAILURE          25
+
+typedef struct TS_status_info_st
+       {
+       ASN1_INTEGER *status;
+       STACK_OF(ASN1_UTF8STRING) *text;
+       ASN1_BIT_STRING *failure_info;
+       } TS_STATUS_INFO;
+
+DECLARE_STACK_OF(ASN1_UTF8STRING)
+DECLARE_ASN1_SET_OF(ASN1_UTF8STRING)
+
+/*
+TimeStampResp ::= SEQUENCE  {
+     status                  PKIStatusInfo,
+     timeStampToken          TimeStampToken     OPTIONAL }
+*/
+
+typedef struct TS_resp_st
+       {
+       TS_STATUS_INFO *status_info;
+       PKCS7 *token;
+       TS_TST_INFO *tst_info;
+       } TS_RESP;
+
+/* The structure below would belong to the ESS component. */
+
+/*
+IssuerSerial ::= SEQUENCE {
+       issuer                   GeneralNames,
+       serialNumber             CertificateSerialNumber
+       }
+*/
+
+typedef struct ESS_issuer_serial
+       {
+       STACK_OF(GENERAL_NAME)  *issuer;
+       ASN1_INTEGER            *serial;
+       } ESS_ISSUER_SERIAL;
+
+/*
+ESSCertID ::=  SEQUENCE {
+        certHash                 Hash,
+        issuerSerial             IssuerSerial OPTIONAL
+}
+*/
+
+typedef struct ESS_cert_id
+       {
+       ASN1_OCTET_STRING *hash;        /* Always SHA-1 digest. */
+       ESS_ISSUER_SERIAL *issuer_serial;
+       } ESS_CERT_ID;
+
+DECLARE_STACK_OF(ESS_CERT_ID)
+DECLARE_ASN1_SET_OF(ESS_CERT_ID)
+
+/*
+SigningCertificate ::=  SEQUENCE {
+       certs        SEQUENCE OF ESSCertID,
+       policies     SEQUENCE OF PolicyInformation OPTIONAL
+}
+*/
+
+typedef struct ESS_signing_cert
+       {
+       STACK_OF(ESS_CERT_ID) *cert_ids;
+       STACK_OF(POLICYINFO) *policy_info;
+       } ESS_SIGNING_CERT;
+
+
+TS_REQ *TS_REQ_new(void);
+void   TS_REQ_free(TS_REQ *a);
+int    i2d_TS_REQ(const TS_REQ *a, unsigned char **pp);
+TS_REQ *d2i_TS_REQ(TS_REQ **a, const unsigned char **pp, long length);
+
+TS_REQ *TS_REQ_dup(TS_REQ *a);
+
+TS_REQ *d2i_TS_REQ_fp(FILE *fp, TS_REQ **a);
+int    i2d_TS_REQ_fp(FILE *fp, TS_REQ *a);
+TS_REQ *d2i_TS_REQ_bio(BIO *fp, TS_REQ **a);
+int    i2d_TS_REQ_bio(BIO *fp, TS_REQ *a);
+
+TS_MSG_IMPRINT *TS_MSG_IMPRINT_new(void);
+void           TS_MSG_IMPRINT_free(TS_MSG_IMPRINT *a);
+int            i2d_TS_MSG_IMPRINT(const TS_MSG_IMPRINT *a, unsigned char **pp);
+TS_MSG_IMPRINT *d2i_TS_MSG_IMPRINT(TS_MSG_IMPRINT **a,
+                                   const unsigned char **pp, long length);
+
+TS_MSG_IMPRINT *TS_MSG_IMPRINT_dup(TS_MSG_IMPRINT *a);
+
+TS_MSG_IMPRINT *d2i_TS_MSG_IMPRINT_fp(FILE *fp, TS_MSG_IMPRINT **a);
+int            i2d_TS_MSG_IMPRINT_fp(FILE *fp, TS_MSG_IMPRINT *a);
+TS_MSG_IMPRINT *d2i_TS_MSG_IMPRINT_bio(BIO *fp, TS_MSG_IMPRINT **a);
+int            i2d_TS_MSG_IMPRINT_bio(BIO *fp, TS_MSG_IMPRINT *a);
+
+TS_RESP        *TS_RESP_new(void);
+void   TS_RESP_free(TS_RESP *a);
+int    i2d_TS_RESP(const TS_RESP *a, unsigned char **pp);
+TS_RESP        *d2i_TS_RESP(TS_RESP **a, const unsigned char **pp, long length);
+TS_TST_INFO *PKCS7_to_TS_TST_INFO(PKCS7 *token);
+TS_RESP        *TS_RESP_dup(TS_RESP *a);
+
+TS_RESP        *d2i_TS_RESP_fp(FILE *fp, TS_RESP **a);
+int    i2d_TS_RESP_fp(FILE *fp, TS_RESP *a);
+TS_RESP        *d2i_TS_RESP_bio(BIO *fp, TS_RESP **a);
+int    i2d_TS_RESP_bio(BIO *fp, TS_RESP *a);
+
+TS_STATUS_INFO *TS_STATUS_INFO_new(void);
+void           TS_STATUS_INFO_free(TS_STATUS_INFO *a);
+int            i2d_TS_STATUS_INFO(const TS_STATUS_INFO *a, unsigned char **pp);
+TS_STATUS_INFO *d2i_TS_STATUS_INFO(TS_STATUS_INFO **a, 
+                                   const unsigned char **pp, long length);
+TS_STATUS_INFO *TS_STATUS_INFO_dup(TS_STATUS_INFO *a);
+
+TS_TST_INFO    *TS_TST_INFO_new(void);
+void           TS_TST_INFO_free(TS_TST_INFO *a);
+int            i2d_TS_TST_INFO(const TS_TST_INFO *a, unsigned char **pp);
+TS_TST_INFO    *d2i_TS_TST_INFO(TS_TST_INFO **a, const unsigned char **pp,
+                                   long length);
+TS_TST_INFO    *TS_TST_INFO_dup(TS_TST_INFO *a);
+
+TS_TST_INFO    *d2i_TS_TST_INFO_fp(FILE *fp, TS_TST_INFO **a);
+int            i2d_TS_TST_INFO_fp(FILE *fp, TS_TST_INFO *a);
+TS_TST_INFO    *d2i_TS_TST_INFO_bio(BIO *fp, TS_TST_INFO **a);
+int            i2d_TS_TST_INFO_bio(BIO *fp, TS_TST_INFO *a);
+
+TS_ACCURACY    *TS_ACCURACY_new(void);
+void           TS_ACCURACY_free(TS_ACCURACY *a);
+int            i2d_TS_ACCURACY(const TS_ACCURACY *a, unsigned char **pp);
+TS_ACCURACY    *d2i_TS_ACCURACY(TS_ACCURACY **a, const unsigned char **pp,
+                                   long length);
+TS_ACCURACY    *TS_ACCURACY_dup(TS_ACCURACY *a);
+
+ESS_ISSUER_SERIAL *ESS_ISSUER_SERIAL_new(void);
+void             ESS_ISSUER_SERIAL_free(ESS_ISSUER_SERIAL *a);
+int              i2d_ESS_ISSUER_SERIAL(const ESS_ISSUER_SERIAL *a,
+                                       unsigned char **pp);
+ESS_ISSUER_SERIAL *d2i_ESS_ISSUER_SERIAL(ESS_ISSUER_SERIAL **a,
+                                        const unsigned char **pp, long length);
+ESS_ISSUER_SERIAL *ESS_ISSUER_SERIAL_dup(ESS_ISSUER_SERIAL *a);
+
+ESS_CERT_ID    *ESS_CERT_ID_new(void);
+void           ESS_CERT_ID_free(ESS_CERT_ID *a);
+int            i2d_ESS_CERT_ID(const ESS_CERT_ID *a, unsigned char **pp);
+ESS_CERT_ID    *d2i_ESS_CERT_ID(ESS_CERT_ID **a, const unsigned char **pp,
+                                long length);
+ESS_CERT_ID    *ESS_CERT_ID_dup(ESS_CERT_ID *a);
+
+ESS_SIGNING_CERT *ESS_SIGNING_CERT_new(void);
+void            ESS_SIGNING_CERT_free(ESS_SIGNING_CERT *a);
+int             i2d_ESS_SIGNING_CERT(const ESS_SIGNING_CERT *a, 
+                                     unsigned char **pp);
+ESS_SIGNING_CERT *d2i_ESS_SIGNING_CERT(ESS_SIGNING_CERT **a,
+                                      const unsigned char **pp, long length);
+ESS_SIGNING_CERT *ESS_SIGNING_CERT_dup(ESS_SIGNING_CERT *a);
+
+void ERR_load_TS_strings(void);
+
+int TS_REQ_set_version(TS_REQ *a, long version);
+long TS_REQ_get_version(const TS_REQ *a);
+
+int TS_REQ_set_msg_imprint(TS_REQ *a, TS_MSG_IMPRINT *msg_imprint);
+TS_MSG_IMPRINT *TS_REQ_get_msg_imprint(TS_REQ *a);
+
+int TS_MSG_IMPRINT_set_algo(TS_MSG_IMPRINT *a, X509_ALGOR *alg);
+X509_ALGOR *TS_MSG_IMPRINT_get_algo(TS_MSG_IMPRINT *a);
+
+int TS_MSG_IMPRINT_set_msg(TS_MSG_IMPRINT *a, unsigned char *d, int len);
+ASN1_OCTET_STRING *TS_MSG_IMPRINT_get_msg(TS_MSG_IMPRINT *a);
+
+int TS_REQ_set_policy_id(TS_REQ *a, ASN1_OBJECT *policy);
+ASN1_OBJECT *TS_REQ_get_policy_id(TS_REQ *a);
+
+int TS_REQ_set_nonce(TS_REQ *a, const ASN1_INTEGER *nonce);
+const ASN1_INTEGER *TS_REQ_get_nonce(const TS_REQ *a);
+
+int TS_REQ_set_cert_req(TS_REQ *a, int cert_req);
+int TS_REQ_get_cert_req(const TS_REQ *a);
+
+STACK_OF(X509_EXTENSION) *TS_REQ_get_exts(TS_REQ *a);
+void TS_REQ_ext_free(TS_REQ *a);
+int TS_REQ_get_ext_count(TS_REQ *a);
+int TS_REQ_get_ext_by_NID(TS_REQ *a, int nid, int lastpos);
+int TS_REQ_get_ext_by_OBJ(TS_REQ *a, ASN1_OBJECT *obj, int lastpos);
+int TS_REQ_get_ext_by_critical(TS_REQ *a, int crit, int lastpos);
+X509_EXTENSION *TS_REQ_get_ext(TS_REQ *a, int loc);
+X509_EXTENSION *TS_REQ_delete_ext(TS_REQ *a, int loc);
+int TS_REQ_add_ext(TS_REQ *a, X509_EXTENSION *ex, int loc);
+void *TS_REQ_get_ext_d2i(TS_REQ *a, int nid, int *crit, int *idx);
+
+/* Function declarations for TS_REQ defined in ts/ts_req_print.c */
+
+int TS_REQ_print_bio(BIO *bio, TS_REQ *a);
+
+/* Function declarations for TS_RESP defined in ts/ts_resp_utils.c */
+
+int TS_RESP_set_status_info(TS_RESP *a, TS_STATUS_INFO *info);
+TS_STATUS_INFO *TS_RESP_get_status_info(TS_RESP *a);
+
+/* Caller loses ownership of PKCS7 and TS_TST_INFO objects. */
+void TS_RESP_set_tst_info(TS_RESP *a, PKCS7 *p7, TS_TST_INFO *tst_info);
+PKCS7 *TS_RESP_get_token(TS_RESP *a);
+TS_TST_INFO *TS_RESP_get_tst_info(TS_RESP *a);
+
+int TS_TST_INFO_set_version(TS_TST_INFO *a, long version);
+long TS_TST_INFO_get_version(const TS_TST_INFO *a);
+
+int TS_TST_INFO_set_policy_id(TS_TST_INFO *a, ASN1_OBJECT *policy_id);
+ASN1_OBJECT *TS_TST_INFO_get_policy_id(TS_TST_INFO *a);
+
+int TS_TST_INFO_set_msg_imprint(TS_TST_INFO *a, TS_MSG_IMPRINT *msg_imprint);
+TS_MSG_IMPRINT *TS_TST_INFO_get_msg_imprint(TS_TST_INFO *a);
+
+int TS_TST_INFO_set_serial(TS_TST_INFO *a, const ASN1_INTEGER *serial);
+const ASN1_INTEGER *TS_TST_INFO_get_serial(const TS_TST_INFO *a);
+
+int TS_TST_INFO_set_time(TS_TST_INFO *a, const ASN1_GENERALIZEDTIME *gtime);
+const ASN1_GENERALIZEDTIME *TS_TST_INFO_get_time(const TS_TST_INFO *a);
+
+int TS_TST_INFO_set_accuracy(TS_TST_INFO *a, TS_ACCURACY *accuracy);
+TS_ACCURACY *TS_TST_INFO_get_accuracy(TS_TST_INFO *a);
+
+int TS_ACCURACY_set_seconds(TS_ACCURACY *a, const ASN1_INTEGER *seconds);
+const ASN1_INTEGER *TS_ACCURACY_get_seconds(const TS_ACCURACY *a);
+
+int TS_ACCURACY_set_millis(TS_ACCURACY *a, const ASN1_INTEGER *millis);
+const ASN1_INTEGER *TS_ACCURACY_get_millis(const TS_ACCURACY *a);
+
+int TS_ACCURACY_set_micros(TS_ACCURACY *a, const ASN1_INTEGER *micros);
+const ASN1_INTEGER *TS_ACCURACY_get_micros(const TS_ACCURACY *a);
+
+int TS_TST_INFO_set_ordering(TS_TST_INFO *a, int ordering);
+int TS_TST_INFO_get_ordering(const TS_TST_INFO *a);
+
+int TS_TST_INFO_set_nonce(TS_TST_INFO *a, const ASN1_INTEGER *nonce);
+const ASN1_INTEGER *TS_TST_INFO_get_nonce(const TS_TST_INFO *a);
+
+int TS_TST_INFO_set_tsa(TS_TST_INFO *a, GENERAL_NAME *tsa);
+GENERAL_NAME *TS_TST_INFO_get_tsa(TS_TST_INFO *a);
+
+STACK_OF(X509_EXTENSION) *TS_TST_INFO_get_exts(TS_TST_INFO *a);
+void TS_TST_INFO_ext_free(TS_TST_INFO *a);
+int TS_TST_INFO_get_ext_count(TS_TST_INFO *a);
+int TS_TST_INFO_get_ext_by_NID(TS_TST_INFO *a, int nid, int lastpos);
+int TS_TST_INFO_get_ext_by_OBJ(TS_TST_INFO *a, ASN1_OBJECT *obj, int lastpos);
+int TS_TST_INFO_get_ext_by_critical(TS_TST_INFO *a, int crit, int lastpos);
+X509_EXTENSION *TS_TST_INFO_get_ext(TS_TST_INFO *a, int loc);
+X509_EXTENSION *TS_TST_INFO_delete_ext(TS_TST_INFO *a, int loc);
+int TS_TST_INFO_add_ext(TS_TST_INFO *a, X509_EXTENSION *ex, int loc);
+void *TS_TST_INFO_get_ext_d2i(TS_TST_INFO *a, int nid, int *crit, int *idx);
+
+/* Declarations related to response generation, defined in ts/ts_resp_sign.c. */
+
+/* Optional flags for response generation. */
+
+/* Don't include the TSA name in response. */
+#define        TS_TSA_NAME             0x01
+
+/* Set ordering to true in response. */
+#define        TS_ORDERING             0x02
+
+/*
+ * Include the signer certificate and the other specified certificates in
+ * the ESS signing certificate attribute beside the PKCS7 signed data.
+ * Only the signer certificates is included by default.
+ */
+#define        TS_ESS_CERT_ID_CHAIN    0x04
+
+/* Forward declaration. */
+struct TS_resp_ctx;
+
+/* This must return a unique number less than 160 bits long. */
+typedef ASN1_INTEGER *(*TS_serial_cb)(struct TS_resp_ctx *, void *);
+
+/* This must return the seconds and microseconds since Jan 1, 1970 in
+   the sec and usec variables allocated by the caller. 
+   Return non-zero for success and zero for failure. */
+typedef        int (*TS_time_cb)(struct TS_resp_ctx *, void *, long *sec, long *usec);
+
+/* This must process the given extension.
+ * It can modify the TS_TST_INFO object of the context.
+ * Return values: !0 (processed), 0 (error, it must set the 
+ * status info/failure info of the response).
+ */
+typedef        int (*TS_extension_cb)(struct TS_resp_ctx *, X509_EXTENSION *, void *);
+
+typedef struct TS_resp_ctx
+       {
+       X509            *signer_cert;
+       EVP_PKEY        *signer_key;
+       STACK_OF(X509)  *certs; /* Certs to include in signed data. */
+       STACK_OF(ASN1_OBJECT)   *policies;      /* Acceptable policies. */
+       ASN1_OBJECT     *default_policy; /* It may appear in policies, too. */
+       STACK_OF(EVP_MD)        *mds;   /* Acceptable message digests. */
+       ASN1_INTEGER    *seconds;       /* accuracy, 0 means not specified. */
+       ASN1_INTEGER    *millis;        /* accuracy, 0 means not specified. */
+       ASN1_INTEGER    *micros;        /* accuracy, 0 means not specified. */
+       unsigned        clock_precision_digits; /* fraction of seconds in
+                                                  time stamp token. */
+       unsigned        flags;          /* Optional info, see values above. */
+
+       /* Callback functions. */
+       TS_serial_cb serial_cb;
+       void *serial_cb_data;   /* User data for serial_cb. */
+       
+       TS_time_cb time_cb;
+       void *time_cb_data;     /* User data for time_cb. */
+       
+       TS_extension_cb extension_cb;
+       void *extension_cb_data;        /* User data for extension_cb. */
+
+       /* These members are used only while creating the response. */
+       TS_REQ          *request;
+       TS_RESP         *response;
+       TS_TST_INFO     *tst_info;
+       } TS_RESP_CTX;
+
+DECLARE_STACK_OF(EVP_MD)
+DECLARE_ASN1_SET_OF(EVP_MD)
+
+/* Creates a response context that can be used for generating responses. */
+TS_RESP_CTX *TS_RESP_CTX_new(void);
+void TS_RESP_CTX_free(TS_RESP_CTX *ctx);
+
+/* This parameter must be set. */
+int TS_RESP_CTX_set_signer_cert(TS_RESP_CTX *ctx, X509 *signer);
+
+/* This parameter must be set. */
+int TS_RESP_CTX_set_signer_key(TS_RESP_CTX *ctx, EVP_PKEY *key);
+
+/* This parameter must be set. */
+int TS_RESP_CTX_set_def_policy(TS_RESP_CTX *ctx, ASN1_OBJECT *def_policy);
+
+/* No additional certs are included in the response by default. */
+int TS_RESP_CTX_set_certs(TS_RESP_CTX *ctx, STACK_OF(X509) *certs);
+
+/* Adds a new acceptable policy, only the default policy 
+   is accepted by default. */
+int TS_RESP_CTX_add_policy(TS_RESP_CTX *ctx, ASN1_OBJECT *policy);
+
+/* Adds a new acceptable message digest. Note that no message digests 
+   are accepted by default. The md argument is shared with the caller. */
+int TS_RESP_CTX_add_md(TS_RESP_CTX *ctx, const EVP_MD *md);
+
+/* Accuracy is not included by default. */
+int TS_RESP_CTX_set_accuracy(TS_RESP_CTX *ctx,
+                            int secs, int millis, int micros);
+
+/* Clock precision digits, i.e. the number of decimal digits: 
+   '0' means sec, '3' msec, '6' usec, and so on. Default is 0. */ 
+int TS_RESP_CTX_set_clock_precision_digits(TS_RESP_CTX *ctx,
+                                          unsigned clock_precision_digits);
+/* At most we accept usec precision. */        
+#define TS_MAX_CLOCK_PRECISION_DIGITS  6
+
+/* No flags are set by default. */
+void TS_RESP_CTX_add_flags(TS_RESP_CTX *ctx, int flags);
+
+/* Default callback always returns a constant. */
+void TS_RESP_CTX_set_serial_cb(TS_RESP_CTX *ctx, TS_serial_cb cb, void *data);
+
+/* Default callback uses the gettimeofday() and gmtime() system calls. */
+void TS_RESP_CTX_set_time_cb(TS_RESP_CTX *ctx, TS_time_cb cb, void *data);
+
+/* Default callback rejects all extensions. The extension callback is called 
+ * when the TS_TST_INFO object is already set up and not signed yet. */
+/* FIXME: extension handling is not tested yet. */
+void TS_RESP_CTX_set_extension_cb(TS_RESP_CTX *ctx, 
+                                 TS_extension_cb cb, void *data);
+
+/* The following methods can be used in the callbacks. */
+int TS_RESP_CTX_set_status_info(TS_RESP_CTX *ctx, 
+                               int status, const char *text);
+
+/* Sets the status info only if it is still TS_STATUS_GRANTED. */
+int TS_RESP_CTX_set_status_info_cond(TS_RESP_CTX *ctx, 
+                                    int status, const char *text);
+
+int TS_RESP_CTX_add_failure_info(TS_RESP_CTX *ctx, int failure);
+
+/* The get methods below can be used in the extension callback. */
+TS_REQ *TS_RESP_CTX_get_request(TS_RESP_CTX *ctx);
+
+TS_TST_INFO *TS_RESP_CTX_get_tst_info(TS_RESP_CTX *ctx);
+
+/* 
+ * Creates the signed TS_TST_INFO and puts it in TS_RESP.
+ * In case of errors it sets the status info properly.
+ * Returns NULL only in case of memory allocation/fatal error.
+ */
+TS_RESP *TS_RESP_create_response(TS_RESP_CTX *ctx, BIO *req_bio);
+
+/*
+ * Declarations related to response verification,
+ * they are defined in ts/ts_resp_verify.c.
+ */
+
+int TS_RESP_verify_signature(PKCS7 *token, STACK_OF(X509) *certs,
+                            X509_STORE *store, X509 **signer_out);
+
+/* Context structure for the generic verify method. */
+
+/* Verify the signer's certificate and the signature of the response. */
+#define        TS_VFY_SIGNATURE        (1u << 0)
+/* Verify the version number of the response. */
+#define        TS_VFY_VERSION          (1u << 1)
+/* Verify if the policy supplied by the user matches the policy of the TSA. */
+#define        TS_VFY_POLICY           (1u << 2)
+/* Verify the message imprint provided by the user. This flag should not be
+   specified with TS_VFY_DATA. */
+#define        TS_VFY_IMPRINT          (1u << 3)
+/* Verify the message imprint computed by the verify method from the user
+   provided data and the MD algorithm of the response. This flag should not be
+   specified with TS_VFY_IMPRINT. */
+#define        TS_VFY_DATA             (1u << 4)
+/* Verify the nonce value. */
+#define        TS_VFY_NONCE            (1u << 5)
+/* Verify if the TSA name field matches the signer certificate. */
+#define        TS_VFY_SIGNER           (1u << 6)
+/* Verify if the TSA name field equals to the user provided name. */
+#define        TS_VFY_TSA_NAME         (1u << 7)
+
+/* You can use the following convenience constants. */
+#define        TS_VFY_ALL_IMPRINT      (TS_VFY_SIGNATURE       \
+                                | TS_VFY_VERSION       \
+                                | TS_VFY_POLICY        \
+                                | TS_VFY_IMPRINT       \
+                                | TS_VFY_NONCE         \
+                                | TS_VFY_SIGNER        \
+                                | TS_VFY_TSA_NAME)
+#define        TS_VFY_ALL_DATA         (TS_VFY_SIGNATURE       \
+                                | TS_VFY_VERSION       \
+                                | TS_VFY_POLICY        \
+                                | TS_VFY_DATA          \
+                                | TS_VFY_NONCE         \
+                                | TS_VFY_SIGNER        \
+                                | TS_VFY_TSA_NAME)
+
+typedef struct TS_verify_ctx
+       {
+       /* Set this to the union of TS_VFY_... flags you want to carry out. */
+       unsigned        flags;
+
+       /* Must be set only with TS_VFY_SIGNATURE. certs is optional. */
+       X509_STORE      *store;
+       STACK_OF(X509)  *certs;
+
+       /* Must be set only with TS_VFY_POLICY. */
+       ASN1_OBJECT     *policy;
+
+       /* Must be set only with TS_VFY_IMPRINT. If md_alg is NULL, 
+          the algorithm from the response is used. */
+       X509_ALGOR      *md_alg;
+       unsigned char   *imprint;
+       unsigned        imprint_len;
+
+       /* Must be set only with TS_VFY_DATA. */
+       BIO             *data;
+
+       /* Must be set only with TS_VFY_TSA_NAME. */
+       ASN1_INTEGER    *nonce;
+
+       /* Must be set only with TS_VFY_TSA_NAME. */
+       GENERAL_NAME    *tsa_name;
+       } TS_VERIFY_CTX;
+
+int TS_RESP_verify_response(TS_VERIFY_CTX *ctx, TS_RESP *response);
+int TS_RESP_verify_token(TS_VERIFY_CTX *ctx, PKCS7 *token);
+
+/*
+ * Declarations related to response verification context,
+ * they are defined in ts/ts_verify_ctx.c.
+ */
+
+/* Set all fields to zero. */
+TS_VERIFY_CTX *TS_VERIFY_CTX_new(void);
+void TS_VERIFY_CTX_init(TS_VERIFY_CTX *ctx);
+void TS_VERIFY_CTX_free(TS_VERIFY_CTX *ctx);
+void TS_VERIFY_CTX_cleanup(TS_VERIFY_CTX *ctx);
+
+/* 
+ * If ctx is NULL, it allocates and returns a new object, otherwise
+ * it returns ctx. It initialises all the members as follows:
+ * flags = TS_VFY_ALL_IMPRINT & ~(TS_VFY_TSA_NAME | TS_VFY_SIGNATURE)
+ * certs = NULL
+ * store = NULL
+ * policy = policy from the request or NULL if absent (in this case
+ *     TS_VFY_POLICY is cleared from flags as well)
+ * md_alg = MD algorithm from request
+ * imprint, imprint_len = imprint from request
+ * data = NULL
+ * nonce, nonce_len = nonce from the request or NULL if absent (in this case
+ *     TS_VFY_NONCE is cleared from flags as well)
+ * tsa_name = NULL
+ * Important: after calling this method TS_VFY_SIGNATURE should be added!
+ */
+TS_VERIFY_CTX *TS_REQ_to_TS_VERIFY_CTX(TS_REQ *req, TS_VERIFY_CTX *ctx);
+
+/* Function declarations for TS_RESP defined in ts/ts_resp_print.c */
+
+int TS_RESP_print_bio(BIO *bio, TS_RESP *a);
+int TS_STATUS_INFO_print_bio(BIO *bio, TS_STATUS_INFO *a);
+int TS_TST_INFO_print_bio(BIO *bio, TS_TST_INFO *a);
+
+/* Common utility functions defined in ts/ts_lib.c */
+
+int TS_ASN1_INTEGER_print_bio(BIO *bio, const ASN1_INTEGER *num);
+int TS_OBJ_print_bio(BIO *bio, const ASN1_OBJECT *obj);
+int TS_ext_print_bio(BIO *bio, const STACK_OF(X509_EXTENSION) *extensions);
+int TS_X509_ALGOR_print_bio(BIO *bio, const X509_ALGOR *alg);
+int TS_MSG_IMPRINT_print_bio(BIO *bio, TS_MSG_IMPRINT *msg);
+
+/* Function declarations for handling configuration options,
+   defined in ts/ts_conf.c */
+
+X509 *TS_CONF_load_cert(const char *file);
+STACK_OF(X509) *TS_CONF_load_certs(const char *file);
+EVP_PKEY *TS_CONF_load_key(const char *file, const char *pass);
+const char *TS_CONF_get_tsa_section(CONF *conf, const char *section);
+int TS_CONF_set_serial(CONF *conf, const char *section, TS_serial_cb cb,
+                      TS_RESP_CTX *ctx);
+int TS_CONF_set_crypto_device(CONF *conf, const char *section,
+                             const char *device);
+int TS_CONF_set_default_engine(const char *name);
+int TS_CONF_set_signer_cert(CONF *conf, const char *section,
+                           const char *cert, TS_RESP_CTX *ctx);
+int TS_CONF_set_certs(CONF *conf, const char *section, const char *certs,
+                     TS_RESP_CTX *ctx);
+int TS_CONF_set_signer_key(CONF *conf, const char *section,
+                          const char *key, const char *pass, TS_RESP_CTX *ctx);
+int TS_CONF_set_def_policy(CONF *conf, const char *section,
+                          const char *policy, TS_RESP_CTX *ctx);
+int TS_CONF_set_policies(CONF *conf, const char *section, TS_RESP_CTX *ctx);
+int TS_CONF_set_digests(CONF *conf, const char *section, TS_RESP_CTX *ctx);
+int TS_CONF_set_accuracy(CONF *conf, const char *section, TS_RESP_CTX *ctx);
+int TS_CONF_set_clock_precision_digits(CONF *conf, const char *section,
+                                      TS_RESP_CTX *ctx);
+int TS_CONF_set_ordering(CONF *conf, const char *section, TS_RESP_CTX *ctx);
+int TS_CONF_set_tsa_name(CONF *conf, const char *section, TS_RESP_CTX *ctx);
+int TS_CONF_set_ess_cert_id_chain(CONF *conf, const char *section,
+                                 TS_RESP_CTX *ctx);
+
+/* -------------------------------------------------- */
+/* BEGIN ERROR CODES */
+/* The following lines are auto generated by the script mkerr.pl. Any changes
+ * made after this point may be overwritten when the script is next run.
+ */
+void ERR_load_TS_strings(void);
+
+/* Error codes for the TS functions. */
+
+/* Function codes. */
+#define TS_F_D2I_TS_RESP                                147
+#define TS_F_DEF_SERIAL_CB                              110
+#define TS_F_DEF_TIME_CB                                111
+#define TS_F_ESS_ADD_SIGNING_CERT                       112
+#define TS_F_ESS_CERT_ID_NEW_INIT                       113
+#define TS_F_ESS_SIGNING_CERT_NEW_INIT                  114
+#define TS_F_INT_TS_RESP_VERIFY_TOKEN                   149
+#define TS_F_PKCS7_TO_TS_TST_INFO                       148
+#define TS_F_TS_ACCURACY_SET_MICROS                     115
+#define TS_F_TS_ACCURACY_SET_MILLIS                     116
+#define TS_F_TS_ACCURACY_SET_SECONDS                    117
+#define TS_F_TS_CHECK_IMPRINTS                          100
+#define TS_F_TS_CHECK_NONCES                            101
+#define TS_F_TS_CHECK_POLICY                            102
+#define TS_F_TS_CHECK_SIGNING_CERTS                     103
+#define TS_F_TS_CHECK_STATUS_INFO                       104
+#define TS_F_TS_COMPUTE_IMPRINT                                 145
+#define TS_F_TS_CONF_SET_DEFAULT_ENGINE                         146
+#define TS_F_TS_GET_STATUS_TEXT                                 105
+#define TS_F_TS_MSG_IMPRINT_SET_ALGO                    118
+#define TS_F_TS_REQ_SET_MSG_IMPRINT                     119
+#define TS_F_TS_REQ_SET_NONCE                           120
+#define TS_F_TS_REQ_SET_POLICY_ID                       121
+#define TS_F_TS_RESP_CREATE_RESPONSE                    122
+#define TS_F_TS_RESP_CREATE_TST_INFO                    123
+#define TS_F_TS_RESP_CTX_ADD_FAILURE_INFO               124
+#define TS_F_TS_RESP_CTX_ADD_MD                                 125
+#define TS_F_TS_RESP_CTX_ADD_POLICY                     126
+#define TS_F_TS_RESP_CTX_NEW                            127
+#define TS_F_TS_RESP_CTX_SET_ACCURACY                   128
+#define TS_F_TS_RESP_CTX_SET_CERTS                      129
+#define TS_F_TS_RESP_CTX_SET_DEF_POLICY                         130
+#define TS_F_TS_RESP_CTX_SET_SIGNER_CERT                131
+#define TS_F_TS_RESP_CTX_SET_STATUS_INFO                132
+#define TS_F_TS_RESP_GET_POLICY                                 133
+#define TS_F_TS_RESP_SET_GENTIME_WITH_PRECISION                 134
+#define TS_F_TS_RESP_SET_STATUS_INFO                    135
+#define TS_F_TS_RESP_SET_TST_INFO                       150
+#define TS_F_TS_RESP_SIGN                               136
+#define TS_F_TS_RESP_VERIFY_SIGNATURE                   106
+#define TS_F_TS_RESP_VERIFY_TOKEN                       107
+#define TS_F_TS_TST_INFO_SET_ACCURACY                   137
+#define TS_F_TS_TST_INFO_SET_MSG_IMPRINT                138
+#define TS_F_TS_TST_INFO_SET_NONCE                      139
+#define TS_F_TS_TST_INFO_SET_POLICY_ID                  140
+#define TS_F_TS_TST_INFO_SET_SERIAL                     141
+#define TS_F_TS_TST_INFO_SET_TIME                       142
+#define TS_F_TS_TST_INFO_SET_TSA                        143
+#define TS_F_TS_VERIFY                                  108
+#define TS_F_TS_VERIFY_CERT                             109
+#define TS_F_TS_VERIFY_CTX_NEW                          144
+
+/* Reason codes. */
+#define TS_R_BAD_PKCS7_TYPE                             132
+#define TS_R_BAD_TYPE                                   133
+#define TS_R_CERTIFICATE_VERIFY_ERROR                   100
+#define TS_R_COULD_NOT_SET_ENGINE                       127
+#define TS_R_COULD_NOT_SET_TIME                                 115
+#define TS_R_D2I_TS_RESP_INT_FAILED                     128
+#define TS_R_DETACHED_CONTENT                           134
+#define TS_R_ESS_ADD_SIGNING_CERT_ERROR                         116
+#define TS_R_ESS_SIGNING_CERTIFICATE_ERROR              101
+#define TS_R_INVALID_NULL_POINTER                       102
+#define TS_R_INVALID_SIGNER_CERTIFICATE_PURPOSE                 117
+#define TS_R_MESSAGE_IMPRINT_MISMATCH                   103
+#define TS_R_NONCE_MISMATCH                             104
+#define TS_R_NONCE_NOT_RETURNED                                 105
+#define TS_R_NO_CONTENT                                         106
+#define TS_R_NO_TIME_STAMP_TOKEN                        107
+#define TS_R_PKCS7_ADD_SIGNATURE_ERROR                  118
+#define TS_R_PKCS7_ADD_SIGNED_ATTR_ERROR                119
+#define TS_R_PKCS7_TO_TS_TST_INFO_FAILED                129
+#define TS_R_POLICY_MISMATCH                            108
+#define TS_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE     120
+#define TS_R_RESPONSE_SETUP_ERROR                       121
+#define TS_R_SIGNATURE_FAILURE                          109
+#define TS_R_THERE_MUST_BE_ONE_SIGNER                   110
+#define TS_R_TIME_SYSCALL_ERROR                                 122
+#define TS_R_TOKEN_NOT_PRESENT                          130
+#define TS_R_TOKEN_PRESENT                              131
+#define TS_R_TSA_NAME_MISMATCH                          111
+#define TS_R_TSA_UNTRUSTED                              112
+#define TS_R_TST_INFO_SETUP_ERROR                       123
+#define TS_R_TS_DATASIGN                                124
+#define TS_R_UNACCEPTABLE_POLICY                        125
+#define TS_R_UNSUPPORTED_MD_ALGORITHM                   126
+#define TS_R_UNSUPPORTED_VERSION                        113
+#define TS_R_WRONG_CONTENT_TYPE                                 114
+
+#ifdef  __cplusplus
+}
+#endif
+#endif
diff --git a/deps/openssl/openssl/crypto/ts/ts_asn1.c b/deps/openssl/openssl/crypto/ts/ts_asn1.c
new file mode 100644 (file)
index 0000000..40b730c
--- /dev/null
@@ -0,0 +1,322 @@
+/* crypto/ts/ts_asn1.c */
+/* Written by Nils Larsch for the OpenSSL project 2004.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <openssl/ts.h>
+#include <openssl/err.h>
+#include <openssl/asn1t.h>
+
+ASN1_SEQUENCE(TS_MSG_IMPRINT) = {
+       ASN1_SIMPLE(TS_MSG_IMPRINT, hash_algo, X509_ALGOR),
+       ASN1_SIMPLE(TS_MSG_IMPRINT, hashed_msg, ASN1_OCTET_STRING)
+} ASN1_SEQUENCE_END(TS_MSG_IMPRINT)
+
+IMPLEMENT_ASN1_FUNCTIONS_const(TS_MSG_IMPRINT)
+IMPLEMENT_ASN1_DUP_FUNCTION(TS_MSG_IMPRINT)
+#ifndef OPENSSL_NO_BIO
+TS_MSG_IMPRINT *d2i_TS_MSG_IMPRINT_bio(BIO *bp, TS_MSG_IMPRINT **a)
+       {
+       return ASN1_d2i_bio_of(TS_MSG_IMPRINT, TS_MSG_IMPRINT_new, d2i_TS_MSG_IMPRINT, bp, a);
+       }
+
+int i2d_TS_MSG_IMPRINT_bio(BIO *bp, TS_MSG_IMPRINT *a)
+{
+       return ASN1_i2d_bio_of_const(TS_MSG_IMPRINT, i2d_TS_MSG_IMPRINT, bp, a);
+}
+#endif
+#ifndef OPENSSL_NO_FP_API
+TS_MSG_IMPRINT *d2i_TS_MSG_IMPRINT_fp(FILE *fp, TS_MSG_IMPRINT **a)
+       {
+       return ASN1_d2i_fp_of(TS_MSG_IMPRINT, TS_MSG_IMPRINT_new, d2i_TS_MSG_IMPRINT, fp, a);
+       }
+
+int i2d_TS_MSG_IMPRINT_fp(FILE *fp, TS_MSG_IMPRINT *a)
+       {
+       return ASN1_i2d_fp_of_const(TS_MSG_IMPRINT, i2d_TS_MSG_IMPRINT, fp, a);
+       }
+#endif
+
+ASN1_SEQUENCE(TS_REQ) = {
+       ASN1_SIMPLE(TS_REQ, version, ASN1_INTEGER),
+       ASN1_SIMPLE(TS_REQ, msg_imprint, TS_MSG_IMPRINT),
+       ASN1_OPT(TS_REQ, policy_id, ASN1_OBJECT),
+       ASN1_OPT(TS_REQ, nonce, ASN1_INTEGER),
+       ASN1_OPT(TS_REQ, cert_req, ASN1_FBOOLEAN),
+       ASN1_IMP_SEQUENCE_OF_OPT(TS_REQ, extensions, X509_EXTENSION, 0)
+} ASN1_SEQUENCE_END(TS_REQ)
+
+IMPLEMENT_ASN1_FUNCTIONS_const(TS_REQ)
+IMPLEMENT_ASN1_DUP_FUNCTION(TS_REQ)
+#ifndef OPENSSL_NO_BIO
+TS_REQ *d2i_TS_REQ_bio(BIO *bp, TS_REQ **a)
+       {
+       return ASN1_d2i_bio_of(TS_REQ, TS_REQ_new, d2i_TS_REQ, bp, a);
+       }
+
+int i2d_TS_REQ_bio(BIO *bp, TS_REQ *a)
+       {
+       return ASN1_i2d_bio_of_const(TS_REQ, i2d_TS_REQ, bp, a);
+       }
+#endif
+#ifndef OPENSSL_NO_FP_API
+TS_REQ *d2i_TS_REQ_fp(FILE *fp, TS_REQ **a)
+       {
+       return ASN1_d2i_fp_of(TS_REQ, TS_REQ_new, d2i_TS_REQ, fp, a);
+       }
+
+int i2d_TS_REQ_fp(FILE *fp, TS_REQ *a)
+       {
+       return ASN1_i2d_fp_of_const(TS_REQ, i2d_TS_REQ, fp, a);
+       }
+#endif
+
+ASN1_SEQUENCE(TS_ACCURACY) = {
+       ASN1_OPT(TS_ACCURACY, seconds, ASN1_INTEGER),
+       ASN1_IMP_OPT(TS_ACCURACY, millis, ASN1_INTEGER, 0),
+       ASN1_IMP_OPT(TS_ACCURACY, micros, ASN1_INTEGER, 1)
+} ASN1_SEQUENCE_END(TS_ACCURACY)
+
+IMPLEMENT_ASN1_FUNCTIONS_const(TS_ACCURACY)
+IMPLEMENT_ASN1_DUP_FUNCTION(TS_ACCURACY)
+
+ASN1_SEQUENCE(TS_TST_INFO) = {
+       ASN1_SIMPLE(TS_TST_INFO, version, ASN1_INTEGER),
+       ASN1_SIMPLE(TS_TST_INFO, policy_id, ASN1_OBJECT),
+       ASN1_SIMPLE(TS_TST_INFO, msg_imprint, TS_MSG_IMPRINT),
+       ASN1_SIMPLE(TS_TST_INFO, serial, ASN1_INTEGER),
+       ASN1_SIMPLE(TS_TST_INFO, time, ASN1_GENERALIZEDTIME),
+       ASN1_OPT(TS_TST_INFO, accuracy, TS_ACCURACY),
+       ASN1_OPT(TS_TST_INFO, ordering, ASN1_FBOOLEAN),
+       ASN1_OPT(TS_TST_INFO, nonce, ASN1_INTEGER),
+       ASN1_EXP_OPT(TS_TST_INFO, tsa, GENERAL_NAME, 0),
+       ASN1_IMP_SEQUENCE_OF_OPT(TS_TST_INFO, extensions, X509_EXTENSION, 1)
+} ASN1_SEQUENCE_END(TS_TST_INFO)
+
+IMPLEMENT_ASN1_FUNCTIONS_const(TS_TST_INFO)
+IMPLEMENT_ASN1_DUP_FUNCTION(TS_TST_INFO)
+#ifndef OPENSSL_NO_BIO
+TS_TST_INFO *d2i_TS_TST_INFO_bio(BIO *bp, TS_TST_INFO **a)
+       {
+       return ASN1_d2i_bio_of(TS_TST_INFO, TS_TST_INFO_new, d2i_TS_TST_INFO, bp, a);
+       }
+
+int i2d_TS_TST_INFO_bio(BIO *bp, TS_TST_INFO *a)
+       {
+       return ASN1_i2d_bio_of_const(TS_TST_INFO, i2d_TS_TST_INFO, bp, a);
+       }
+#endif
+#ifndef OPENSSL_NO_FP_API
+TS_TST_INFO *d2i_TS_TST_INFO_fp(FILE *fp, TS_TST_INFO **a)
+       {
+       return ASN1_d2i_fp_of(TS_TST_INFO, TS_TST_INFO_new, d2i_TS_TST_INFO, fp, a);
+       }
+
+int i2d_TS_TST_INFO_fp(FILE *fp, TS_TST_INFO *a)
+       {
+       return ASN1_i2d_fp_of_const(TS_TST_INFO, i2d_TS_TST_INFO, fp, a);
+       }
+#endif
+
+ASN1_SEQUENCE(TS_STATUS_INFO) = {
+       ASN1_SIMPLE(TS_STATUS_INFO, status, ASN1_INTEGER),
+       ASN1_SEQUENCE_OF_OPT(TS_STATUS_INFO, text, ASN1_UTF8STRING),
+       ASN1_OPT(TS_STATUS_INFO, failure_info, ASN1_BIT_STRING)
+} ASN1_SEQUENCE_END(TS_STATUS_INFO)
+
+IMPLEMENT_ASN1_FUNCTIONS_const(TS_STATUS_INFO)
+IMPLEMENT_ASN1_DUP_FUNCTION(TS_STATUS_INFO)
+
+static int ts_resp_set_tst_info(TS_RESP *a)
+{
+       long    status;
+
+       status = ASN1_INTEGER_get(a->status_info->status);
+
+       if (a->token) {
+               if (status != 0 && status != 1) {
+                       TSerr(TS_F_TS_RESP_SET_TST_INFO, TS_R_TOKEN_PRESENT);
+                       return 0;
+               }
+               if (a->tst_info != NULL)
+                       TS_TST_INFO_free(a->tst_info);
+               a->tst_info = PKCS7_to_TS_TST_INFO(a->token);
+               if (!a->tst_info) {
+                       TSerr(TS_F_TS_RESP_SET_TST_INFO, TS_R_PKCS7_TO_TS_TST_INFO_FAILED);
+                       return 0;
+               }
+       } else if (status == 0 || status == 1) {
+               TSerr(TS_F_TS_RESP_SET_TST_INFO, TS_R_TOKEN_NOT_PRESENT);
+               return 0;
+       }
+
+       return 1;
+}
+
+static int ts_resp_cb(int op, ASN1_VALUE **pval, const ASN1_ITEM *it,
+       void *exarg)
+{
+       TS_RESP *ts_resp = (TS_RESP *)*pval;
+       if (op == ASN1_OP_NEW_POST) {
+               ts_resp->tst_info = NULL;
+       } else if (op == ASN1_OP_FREE_POST) {
+               if (ts_resp->tst_info != NULL)
+                       TS_TST_INFO_free(ts_resp->tst_info);
+       } else if (op == ASN1_OP_D2I_POST) {
+               if (ts_resp_set_tst_info(ts_resp) == 0)
+                       return 0;
+       }
+       return 1;
+}
+
+ASN1_SEQUENCE_cb(TS_RESP, ts_resp_cb) = {
+       ASN1_SIMPLE(TS_RESP, status_info, TS_STATUS_INFO),
+       ASN1_OPT(TS_RESP, token, PKCS7),
+} ASN1_SEQUENCE_END_cb(TS_RESP, TS_RESP)
+
+IMPLEMENT_ASN1_FUNCTIONS_const(TS_RESP)
+IMPLEMENT_ASN1_DUP_FUNCTION(TS_RESP)
+#ifndef OPENSSL_NO_BIO
+TS_RESP *d2i_TS_RESP_bio(BIO *bp, TS_RESP **a)
+       {
+       return ASN1_d2i_bio_of(TS_RESP, TS_RESP_new, d2i_TS_RESP, bp, a);
+       }
+
+int i2d_TS_RESP_bio(BIO *bp, TS_RESP *a)
+       {
+       return ASN1_i2d_bio_of_const(TS_RESP, i2d_TS_RESP, bp, a);
+       }
+#endif
+#ifndef OPENSSL_NO_FP_API
+TS_RESP *d2i_TS_RESP_fp(FILE *fp, TS_RESP **a)
+       {
+       return ASN1_d2i_fp_of(TS_RESP, TS_RESP_new, d2i_TS_RESP, fp, a);
+       }
+
+int i2d_TS_RESP_fp(FILE *fp, TS_RESP *a)
+       {
+       return ASN1_i2d_fp_of_const(TS_RESP, i2d_TS_RESP, fp, a);
+       }
+#endif
+
+ASN1_SEQUENCE(ESS_ISSUER_SERIAL) = {
+       ASN1_SEQUENCE_OF(ESS_ISSUER_SERIAL, issuer, GENERAL_NAME),
+       ASN1_SIMPLE(ESS_ISSUER_SERIAL, serial, ASN1_INTEGER)
+} ASN1_SEQUENCE_END(ESS_ISSUER_SERIAL)
+
+IMPLEMENT_ASN1_FUNCTIONS_const(ESS_ISSUER_SERIAL)
+IMPLEMENT_ASN1_DUP_FUNCTION(ESS_ISSUER_SERIAL)
+
+ASN1_SEQUENCE(ESS_CERT_ID) = {
+       ASN1_SIMPLE(ESS_CERT_ID, hash, ASN1_OCTET_STRING),
+       ASN1_OPT(ESS_CERT_ID, issuer_serial, ESS_ISSUER_SERIAL)
+} ASN1_SEQUENCE_END(ESS_CERT_ID)
+
+IMPLEMENT_ASN1_FUNCTIONS_const(ESS_CERT_ID)
+IMPLEMENT_ASN1_DUP_FUNCTION(ESS_CERT_ID)
+
+ASN1_SEQUENCE(ESS_SIGNING_CERT) = {
+       ASN1_SEQUENCE_OF(ESS_SIGNING_CERT, cert_ids, ESS_CERT_ID),
+       ASN1_SEQUENCE_OF_OPT(ESS_SIGNING_CERT, policy_info, POLICYINFO)
+} ASN1_SEQUENCE_END(ESS_SIGNING_CERT)
+
+IMPLEMENT_ASN1_FUNCTIONS_const(ESS_SIGNING_CERT)
+IMPLEMENT_ASN1_DUP_FUNCTION(ESS_SIGNING_CERT)
+
+/* Getting encapsulated TS_TST_INFO object from PKCS7. */
+TS_TST_INFO *PKCS7_to_TS_TST_INFO(PKCS7 *token)
+{
+       PKCS7_SIGNED *pkcs7_signed;
+       PKCS7 *enveloped;
+       ASN1_TYPE *tst_info_wrapper;
+       ASN1_OCTET_STRING *tst_info_der;
+       const unsigned char *p;
+
+       if (!PKCS7_type_is_signed(token))
+               {
+               TSerr(TS_F_PKCS7_TO_TS_TST_INFO, TS_R_BAD_PKCS7_TYPE);
+               return NULL;
+               }
+
+       /* Content must be present. */
+       if (PKCS7_get_detached(token))
+               {
+               TSerr(TS_F_PKCS7_TO_TS_TST_INFO, TS_R_DETACHED_CONTENT);
+               return NULL;
+               }
+
+       /* We have a signed data with content. */
+       pkcs7_signed = token->d.sign;
+       enveloped = pkcs7_signed->contents;
+       if (OBJ_obj2nid(enveloped->type) != NID_id_smime_ct_TSTInfo)
+               {
+               TSerr(TS_F_PKCS7_TO_TS_TST_INFO, TS_R_BAD_PKCS7_TYPE);
+               return NULL;
+               }
+
+       /* We have a DER encoded TST_INFO as the signed data. */
+       tst_info_wrapper = enveloped->d.other;
+       if (tst_info_wrapper->type != V_ASN1_OCTET_STRING)
+               {
+               TSerr(TS_F_PKCS7_TO_TS_TST_INFO, TS_R_BAD_TYPE);
+               return NULL;
+               }
+
+       /* We have the correct ASN1_OCTET_STRING type. */
+       tst_info_der = tst_info_wrapper->value.octet_string;
+       /* At last, decode the TST_INFO. */
+       p = tst_info_der->data;
+       return d2i_TS_TST_INFO(NULL, &p, tst_info_der->length);
+}
diff --git a/deps/openssl/openssl/crypto/ts/ts_conf.c b/deps/openssl/openssl/crypto/ts/ts_conf.c
new file mode 100644 (file)
index 0000000..c39be76
--- /dev/null
@@ -0,0 +1,507 @@
+/* crypto/ts/ts_conf.c */
+/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
+ * project 2002.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <string.h>
+
+#include <openssl/crypto.h>
+#include "cryptlib.h"
+#include <openssl/pem.h>
+#ifndef OPENSSL_NO_ENGINE
+#include <openssl/engine.h>
+#endif
+#include <openssl/ts.h>
+
+/* Macro definitions for the configuration file. */
+
+#define        BASE_SECTION                    "tsa"
+#define        ENV_DEFAULT_TSA                 "default_tsa"
+#define        ENV_SERIAL                      "serial"
+#define ENV_CRYPTO_DEVICE              "crypto_device"
+#define        ENV_SIGNER_CERT                 "signer_cert"
+#define        ENV_CERTS                       "certs"
+#define        ENV_SIGNER_KEY                  "signer_key"
+#define        ENV_DEFAULT_POLICY              "default_policy"
+#define        ENV_OTHER_POLICIES              "other_policies"
+#define        ENV_DIGESTS                     "digests"
+#define        ENV_ACCURACY                    "accuracy"
+#define        ENV_ORDERING                    "ordering"
+#define        ENV_TSA_NAME                    "tsa_name"
+#define        ENV_ESS_CERT_ID_CHAIN           "ess_cert_id_chain"
+#define        ENV_VALUE_SECS                  "secs"
+#define        ENV_VALUE_MILLISECS             "millisecs"
+#define        ENV_VALUE_MICROSECS             "microsecs"
+#define        ENV_CLOCK_PRECISION_DIGITS      "clock_precision_digits" 
+#define        ENV_VALUE_YES                   "yes"
+#define        ENV_VALUE_NO                    "no"
+
+/* Function definitions for certificate and key loading. */
+
+X509 *TS_CONF_load_cert(const char *file)
+       {
+       BIO *cert = NULL;
+       X509 *x = NULL;
+
+       if ((cert = BIO_new_file(file, "r")) == NULL) goto end;
+       x = PEM_read_bio_X509_AUX(cert, NULL, NULL, NULL);
+end:
+       if (x == NULL)
+               fprintf(stderr, "unable to load certificate: %s\n", file);
+       BIO_free(cert);
+       return x;
+       }
+
+STACK_OF(X509) *TS_CONF_load_certs(const char *file)
+       {
+       BIO *certs = NULL;
+       STACK_OF(X509) *othercerts = NULL;
+       STACK_OF(X509_INFO) *allcerts = NULL;
+       int i;
+
+       if (!(certs = BIO_new_file(file, "r"))) goto end;
+
+       if (!(othercerts = sk_X509_new_null())) goto end;
+       allcerts = PEM_X509_INFO_read_bio(certs, NULL, NULL, NULL);
+       for(i = 0; i < sk_X509_INFO_num(allcerts); i++)
+               {
+               X509_INFO *xi = sk_X509_INFO_value(allcerts, i);
+               if (xi->x509)
+                       {
+                       sk_X509_push(othercerts, xi->x509);
+                       xi->x509 = NULL;
+                       }
+               }
+end:
+       if (othercerts == NULL)
+               fprintf(stderr, "unable to load certificates: %s\n", file);
+       sk_X509_INFO_pop_free(allcerts, X509_INFO_free);
+       BIO_free(certs);
+       return othercerts;
+       }
+
+EVP_PKEY *TS_CONF_load_key(const char *file, const char *pass)
+       {
+       BIO *key = NULL;
+       EVP_PKEY *pkey = NULL;
+
+       if (!(key = BIO_new_file(file, "r"))) goto end;
+       pkey = PEM_read_bio_PrivateKey(key, NULL, NULL, (char *) pass);
+ end:
+       if (pkey == NULL)
+               fprintf(stderr, "unable to load private key: %s\n", file);
+       BIO_free(key);
+       return pkey;
+       }
+
+/* Function definitions for handling configuration options. */
+
+static void TS_CONF_lookup_fail(const char *name, const char *tag)
+       {
+       fprintf(stderr, "variable lookup failed for %s::%s\n", name, tag);
+       }
+
+static void TS_CONF_invalid(const char *name, const char *tag)
+       {
+       fprintf(stderr, "invalid variable value for %s::%s\n", name, tag);
+       }
+
+const char *TS_CONF_get_tsa_section(CONF *conf, const char *section)
+       {
+       if (!section)
+               {
+               section = NCONF_get_string(conf, BASE_SECTION, ENV_DEFAULT_TSA);
+               if (!section)
+                       TS_CONF_lookup_fail(BASE_SECTION, ENV_DEFAULT_TSA);
+               }
+       return section;
+       }
+
+int TS_CONF_set_serial(CONF *conf, const char *section, TS_serial_cb cb,
+                      TS_RESP_CTX *ctx)
+       {
+       int ret = 0;
+       char *serial = NCONF_get_string(conf, section, ENV_SERIAL);
+       if (!serial)
+               {
+               TS_CONF_lookup_fail(section, ENV_SERIAL);
+               goto err;
+               }
+       TS_RESP_CTX_set_serial_cb(ctx, cb, serial);
+
+       ret = 1;
+ err:
+       return ret;
+       }
+
+#ifndef OPENSSL_NO_ENGINE
+
+int TS_CONF_set_crypto_device(CONF *conf, const char *section,
+                             const char *device)
+       {
+       int ret = 0;
+       
+       if (!device)
+               device = NCONF_get_string(conf, section,
+                                         ENV_CRYPTO_DEVICE);
+
+       if (device && !TS_CONF_set_default_engine(device))
+               {
+               TS_CONF_invalid(section, ENV_CRYPTO_DEVICE);
+               goto err;
+               }
+       ret = 1;
+ err:
+       return ret;
+       }
+
+int TS_CONF_set_default_engine(const char *name)
+       {
+       ENGINE *e = NULL;
+       int ret = 0;
+
+       /* Leave the default if builtin specified. */
+       if (strcmp(name, "builtin") == 0) return 1;
+
+       if (!(e = ENGINE_by_id(name))) goto err;
+       /* Enable the use of the NCipher HSM for forked children. */
+       if (strcmp(name, "chil") == 0) 
+               ENGINE_ctrl(e, ENGINE_CTRL_CHIL_SET_FORKCHECK, 1, 0, 0);
+       /* All the operations are going to be carried out by the engine. */
+       if (!ENGINE_set_default(e, ENGINE_METHOD_ALL)) goto err;
+       ret = 1;
+ err:
+       if (!ret)
+               {
+               TSerr(TS_F_TS_CONF_SET_DEFAULT_ENGINE, 
+                     TS_R_COULD_NOT_SET_ENGINE);
+               ERR_add_error_data(2, "engine:", name);
+               }
+       if (e) ENGINE_free(e);
+       return ret;
+       }
+
+#endif
+
+int TS_CONF_set_signer_cert(CONF *conf, const char *section,
+                           const char *cert, TS_RESP_CTX *ctx)
+       {
+       int ret = 0;
+       X509 *cert_obj = NULL;
+       if (!cert) 
+               cert = NCONF_get_string(conf, section, ENV_SIGNER_CERT);
+       if (!cert)
+               {
+               TS_CONF_lookup_fail(section, ENV_SIGNER_CERT);
+               goto err;
+               }
+       if (!(cert_obj = TS_CONF_load_cert(cert)))
+               goto err;
+       if (!TS_RESP_CTX_set_signer_cert(ctx, cert_obj))
+               goto err;
+
+       ret = 1;
+ err:
+       X509_free(cert_obj);
+       return ret;
+       }
+
+int TS_CONF_set_certs(CONF *conf, const char *section, const char *certs,
+                     TS_RESP_CTX *ctx)
+       {
+       int ret = 0;
+       STACK_OF(X509) *certs_obj = NULL;
+       if (!certs) 
+               certs = NCONF_get_string(conf, section, ENV_CERTS);
+       /* Certificate chain is optional. */
+       if (!certs) goto end;
+       if (!(certs_obj = TS_CONF_load_certs(certs))) goto err;
+       if (!TS_RESP_CTX_set_certs(ctx, certs_obj)) goto err;
+ end:
+       ret = 1;
+ err:
+       sk_X509_pop_free(certs_obj, X509_free);
+       return ret;
+       }
+
+int TS_CONF_set_signer_key(CONF *conf, const char *section,
+                          const char *key, const char *pass,
+                          TS_RESP_CTX *ctx)
+       {
+       int ret = 0;
+       EVP_PKEY *key_obj = NULL;
+       if (!key) 
+               key = NCONF_get_string(conf, section, ENV_SIGNER_KEY);
+       if (!key)
+               {
+               TS_CONF_lookup_fail(section, ENV_SIGNER_KEY);
+               goto err;
+               }
+       if (!(key_obj = TS_CONF_load_key(key, pass))) goto err;
+       if (!TS_RESP_CTX_set_signer_key(ctx, key_obj)) goto err;
+
+       ret = 1;
+ err:
+       EVP_PKEY_free(key_obj);
+       return ret;
+       }
+
+int TS_CONF_set_def_policy(CONF *conf, const char *section,
+                          const char *policy, TS_RESP_CTX *ctx)
+       {
+       int ret = 0;
+       ASN1_OBJECT *policy_obj = NULL;
+       if (!policy) 
+               policy = NCONF_get_string(conf, section, 
+                                         ENV_DEFAULT_POLICY);
+       if (!policy)
+               {
+               TS_CONF_lookup_fail(section, ENV_DEFAULT_POLICY);
+               goto err;
+               }
+       if (!(policy_obj = OBJ_txt2obj(policy, 0)))
+               {
+               TS_CONF_invalid(section, ENV_DEFAULT_POLICY);
+               goto err;
+               }
+       if (!TS_RESP_CTX_set_def_policy(ctx, policy_obj))
+               goto err;
+
+       ret = 1;
+ err:
+       ASN1_OBJECT_free(policy_obj);
+       return ret;
+       }
+
+int TS_CONF_set_policies(CONF *conf, const char *section,
+                        TS_RESP_CTX *ctx)
+       {
+       int ret = 0;
+       int i;
+       STACK_OF(CONF_VALUE) *list = NULL;
+       char *policies = NCONF_get_string(conf, section, 
+                                         ENV_OTHER_POLICIES);
+       /* If no other policy is specified, that's fine. */
+       if (policies && !(list = X509V3_parse_list(policies)))
+               {
+               TS_CONF_invalid(section, ENV_OTHER_POLICIES);
+               goto err;
+               }
+       for (i = 0; i < sk_CONF_VALUE_num(list); ++i)
+               {
+               CONF_VALUE *val = sk_CONF_VALUE_value(list, i);
+               const char *extval = val->value ? val->value : val->name;
+               ASN1_OBJECT *objtmp;
+               if (!(objtmp = OBJ_txt2obj(extval, 0)))
+                       {
+                       TS_CONF_invalid(section, ENV_OTHER_POLICIES);
+                       goto err;
+                       }
+               if (!TS_RESP_CTX_add_policy(ctx, objtmp))
+                       goto err;
+               ASN1_OBJECT_free(objtmp);
+               }
+
+       ret = 1;
+ err:
+       sk_CONF_VALUE_pop_free(list, X509V3_conf_free);
+       return ret;
+       }
+
+int TS_CONF_set_digests(CONF *conf, const char *section,
+                       TS_RESP_CTX *ctx)
+       {
+       int ret = 0;
+       int i;
+       STACK_OF(CONF_VALUE) *list = NULL;
+       char *digests = NCONF_get_string(conf, section, ENV_DIGESTS);
+       if (!digests)
+               {
+               TS_CONF_lookup_fail(section, ENV_DIGESTS);
+               goto err;
+               }
+       if (!(list = X509V3_parse_list(digests)))
+               {
+               TS_CONF_invalid(section, ENV_DIGESTS);
+               goto err;
+               }
+       if (sk_CONF_VALUE_num(list) == 0)
+               {
+               TS_CONF_invalid(section, ENV_DIGESTS);
+               goto err;
+               }
+       for (i = 0; i < sk_CONF_VALUE_num(list); ++i)
+               {
+               CONF_VALUE *val = sk_CONF_VALUE_value(list, i);
+               const char *extval = val->value ? val->value : val->name;
+               const EVP_MD *md;
+               if (!(md = EVP_get_digestbyname(extval)))
+                       {
+                       TS_CONF_invalid(section, ENV_DIGESTS);
+                       goto err;
+                       }
+               if (!TS_RESP_CTX_add_md(ctx, md))
+                       goto err;
+               }
+
+       ret = 1;
+ err:
+       sk_CONF_VALUE_pop_free(list, X509V3_conf_free);
+       return ret;
+       }
+
+int TS_CONF_set_accuracy(CONF *conf, const char *section, TS_RESP_CTX *ctx)
+       {
+       int ret = 0;
+       int i;
+       int secs = 0, millis = 0, micros = 0;
+       STACK_OF(CONF_VALUE) *list = NULL;
+       char *accuracy = NCONF_get_string(conf, section, ENV_ACCURACY);
+
+       if (accuracy && !(list = X509V3_parse_list(accuracy)))
+               {
+               TS_CONF_invalid(section, ENV_ACCURACY);
+               goto err;
+               }
+       for (i = 0; i < sk_CONF_VALUE_num(list); ++i)
+               {
+               CONF_VALUE *val = sk_CONF_VALUE_value(list, i);
+               if (strcmp(val->name, ENV_VALUE_SECS) == 0) 
+                       {
+                       if (val->value) secs = atoi(val->value);
+                       }
+               else if (strcmp(val->name, ENV_VALUE_MILLISECS) == 0)
+                       {
+                       if (val->value) millis = atoi(val->value);
+                       }
+               else if (strcmp(val->name, ENV_VALUE_MICROSECS) == 0)
+                       {
+                       if (val->value) micros = atoi(val->value);
+                       }
+               else
+                       {
+                       TS_CONF_invalid(section, ENV_ACCURACY);
+                       goto err;
+                       }
+               }
+       if (!TS_RESP_CTX_set_accuracy(ctx, secs, millis, micros))
+               goto err;
+
+       ret = 1;
+ err:
+       sk_CONF_VALUE_pop_free(list, X509V3_conf_free);
+       return ret;
+       }
+
+int TS_CONF_set_clock_precision_digits(CONF *conf, const char *section,
+                                      TS_RESP_CTX *ctx)
+       {
+       int ret = 0;
+       long digits = 0;
+       
+       /* If not specified, set the default value to 0, i.e. sec  precision */
+       if (!NCONF_get_number_e(conf, section, ENV_CLOCK_PRECISION_DIGITS,
+                               &digits))
+               digits = 0;
+       if (digits < 0 || digits > TS_MAX_CLOCK_PRECISION_DIGITS)
+               {
+               TS_CONF_invalid(section, ENV_CLOCK_PRECISION_DIGITS);
+               goto err;
+               }
+
+       if (!TS_RESP_CTX_set_clock_precision_digits(ctx, digits))
+               goto err;
+
+       return 1;
+ err:
+       return ret;
+       }
+
+static int TS_CONF_add_flag(CONF *conf, const char *section, const char *field,
+                           int flag, TS_RESP_CTX *ctx)
+       {
+       /* Default is false. */
+       const char *value = NCONF_get_string(conf, section, field);
+       if (value)
+               {
+               if (strcmp(value, ENV_VALUE_YES) == 0)
+                       TS_RESP_CTX_add_flags(ctx, flag);
+               else if (strcmp(value, ENV_VALUE_NO) != 0)
+                       {
+                       TS_CONF_invalid(section, field);
+                       return 0;
+                       }
+               }
+
+       return 1;
+       }
+
+int TS_CONF_set_ordering(CONF *conf, const char *section, TS_RESP_CTX *ctx)
+       {
+       return TS_CONF_add_flag(conf, section, ENV_ORDERING, TS_ORDERING, ctx);
+       }
+
+int TS_CONF_set_tsa_name(CONF *conf, const char *section, TS_RESP_CTX *ctx)
+       {
+       return TS_CONF_add_flag(conf, section, ENV_TSA_NAME, TS_TSA_NAME, ctx);
+       }
+
+int TS_CONF_set_ess_cert_id_chain(CONF *conf, const char *section,
+                                 TS_RESP_CTX *ctx)
+       {
+       return TS_CONF_add_flag(conf, section, ENV_ESS_CERT_ID_CHAIN, 
+                               TS_ESS_CERT_ID_CHAIN, ctx);
+       }
diff --git a/deps/openssl/openssl/crypto/ts/ts_err.c b/deps/openssl/openssl/crypto/ts/ts_err.c
new file mode 100644 (file)
index 0000000..a08b0ff
--- /dev/null
@@ -0,0 +1,179 @@
+/* crypto/ts/ts_err.c */
+/* ====================================================================
+ * Copyright (c) 1999-2007 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    openssl-core@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+/* NOTE: this file was auto generated by the mkerr.pl script: any changes
+ * made to it will be overwritten when the script next updates this file,
+ * only reason strings will be preserved.
+ */
+
+#include <stdio.h>
+#include <openssl/err.h>
+#include <openssl/ts.h>
+
+/* BEGIN ERROR CODES */
+#ifndef OPENSSL_NO_ERR
+
+#define ERR_FUNC(func) ERR_PACK(ERR_LIB_TS,func,0)
+#define ERR_REASON(reason) ERR_PACK(ERR_LIB_TS,0,reason)
+
+static ERR_STRING_DATA TS_str_functs[]=
+       {
+{ERR_FUNC(TS_F_D2I_TS_RESP),   "d2i_TS_RESP"},
+{ERR_FUNC(TS_F_DEF_SERIAL_CB), "DEF_SERIAL_CB"},
+{ERR_FUNC(TS_F_DEF_TIME_CB),   "DEF_TIME_CB"},
+{ERR_FUNC(TS_F_ESS_ADD_SIGNING_CERT),  "ESS_ADD_SIGNING_CERT"},
+{ERR_FUNC(TS_F_ESS_CERT_ID_NEW_INIT),  "ESS_CERT_ID_NEW_INIT"},
+{ERR_FUNC(TS_F_ESS_SIGNING_CERT_NEW_INIT),     "ESS_SIGNING_CERT_NEW_INIT"},
+{ERR_FUNC(TS_F_INT_TS_RESP_VERIFY_TOKEN),      "INT_TS_RESP_VERIFY_TOKEN"},
+{ERR_FUNC(TS_F_PKCS7_TO_TS_TST_INFO),  "PKCS7_to_TS_TST_INFO"},
+{ERR_FUNC(TS_F_TS_ACCURACY_SET_MICROS),        "TS_ACCURACY_set_micros"},
+{ERR_FUNC(TS_F_TS_ACCURACY_SET_MILLIS),        "TS_ACCURACY_set_millis"},
+{ERR_FUNC(TS_F_TS_ACCURACY_SET_SECONDS),       "TS_ACCURACY_set_seconds"},
+{ERR_FUNC(TS_F_TS_CHECK_IMPRINTS),     "TS_CHECK_IMPRINTS"},
+{ERR_FUNC(TS_F_TS_CHECK_NONCES),       "TS_CHECK_NONCES"},
+{ERR_FUNC(TS_F_TS_CHECK_POLICY),       "TS_CHECK_POLICY"},
+{ERR_FUNC(TS_F_TS_CHECK_SIGNING_CERTS),        "TS_CHECK_SIGNING_CERTS"},
+{ERR_FUNC(TS_F_TS_CHECK_STATUS_INFO),  "TS_CHECK_STATUS_INFO"},
+{ERR_FUNC(TS_F_TS_COMPUTE_IMPRINT),    "TS_COMPUTE_IMPRINT"},
+{ERR_FUNC(TS_F_TS_CONF_SET_DEFAULT_ENGINE),    "TS_CONF_set_default_engine"},
+{ERR_FUNC(TS_F_TS_GET_STATUS_TEXT),    "TS_GET_STATUS_TEXT"},
+{ERR_FUNC(TS_F_TS_MSG_IMPRINT_SET_ALGO),       "TS_MSG_IMPRINT_set_algo"},
+{ERR_FUNC(TS_F_TS_REQ_SET_MSG_IMPRINT),        "TS_REQ_set_msg_imprint"},
+{ERR_FUNC(TS_F_TS_REQ_SET_NONCE),      "TS_REQ_set_nonce"},
+{ERR_FUNC(TS_F_TS_REQ_SET_POLICY_ID),  "TS_REQ_set_policy_id"},
+{ERR_FUNC(TS_F_TS_RESP_CREATE_RESPONSE),       "TS_RESP_create_response"},
+{ERR_FUNC(TS_F_TS_RESP_CREATE_TST_INFO),       "TS_RESP_CREATE_TST_INFO"},
+{ERR_FUNC(TS_F_TS_RESP_CTX_ADD_FAILURE_INFO),  "TS_RESP_CTX_add_failure_info"},
+{ERR_FUNC(TS_F_TS_RESP_CTX_ADD_MD),    "TS_RESP_CTX_add_md"},
+{ERR_FUNC(TS_F_TS_RESP_CTX_ADD_POLICY),        "TS_RESP_CTX_add_policy"},
+{ERR_FUNC(TS_F_TS_RESP_CTX_NEW),       "TS_RESP_CTX_new"},
+{ERR_FUNC(TS_F_TS_RESP_CTX_SET_ACCURACY),      "TS_RESP_CTX_set_accuracy"},
+{ERR_FUNC(TS_F_TS_RESP_CTX_SET_CERTS), "TS_RESP_CTX_set_certs"},
+{ERR_FUNC(TS_F_TS_RESP_CTX_SET_DEF_POLICY),    "TS_RESP_CTX_set_def_policy"},
+{ERR_FUNC(TS_F_TS_RESP_CTX_SET_SIGNER_CERT),   "TS_RESP_CTX_set_signer_cert"},
+{ERR_FUNC(TS_F_TS_RESP_CTX_SET_STATUS_INFO),   "TS_RESP_CTX_set_status_info"},
+{ERR_FUNC(TS_F_TS_RESP_GET_POLICY),    "TS_RESP_GET_POLICY"},
+{ERR_FUNC(TS_F_TS_RESP_SET_GENTIME_WITH_PRECISION),    "TS_RESP_SET_GENTIME_WITH_PRECISION"},
+{ERR_FUNC(TS_F_TS_RESP_SET_STATUS_INFO),       "TS_RESP_set_status_info"},
+{ERR_FUNC(TS_F_TS_RESP_SET_TST_INFO),  "TS_RESP_set_tst_info"},
+{ERR_FUNC(TS_F_TS_RESP_SIGN),  "TS_RESP_SIGN"},
+{ERR_FUNC(TS_F_TS_RESP_VERIFY_SIGNATURE),      "TS_RESP_verify_signature"},
+{ERR_FUNC(TS_F_TS_RESP_VERIFY_TOKEN),  "TS_RESP_verify_token"},
+{ERR_FUNC(TS_F_TS_TST_INFO_SET_ACCURACY),      "TS_TST_INFO_set_accuracy"},
+{ERR_FUNC(TS_F_TS_TST_INFO_SET_MSG_IMPRINT),   "TS_TST_INFO_set_msg_imprint"},
+{ERR_FUNC(TS_F_TS_TST_INFO_SET_NONCE), "TS_TST_INFO_set_nonce"},
+{ERR_FUNC(TS_F_TS_TST_INFO_SET_POLICY_ID),     "TS_TST_INFO_set_policy_id"},
+{ERR_FUNC(TS_F_TS_TST_INFO_SET_SERIAL),        "TS_TST_INFO_set_serial"},
+{ERR_FUNC(TS_F_TS_TST_INFO_SET_TIME),  "TS_TST_INFO_set_time"},
+{ERR_FUNC(TS_F_TS_TST_INFO_SET_TSA),   "TS_TST_INFO_set_tsa"},
+{ERR_FUNC(TS_F_TS_VERIFY),     "TS_VERIFY"},
+{ERR_FUNC(TS_F_TS_VERIFY_CERT),        "TS_VERIFY_CERT"},
+{ERR_FUNC(TS_F_TS_VERIFY_CTX_NEW),     "TS_VERIFY_CTX_new"},
+{0,NULL}
+       };
+
+static ERR_STRING_DATA TS_str_reasons[]=
+       {
+{ERR_REASON(TS_R_BAD_PKCS7_TYPE)         ,"bad pkcs7 type"},
+{ERR_REASON(TS_R_BAD_TYPE)               ,"bad type"},
+{ERR_REASON(TS_R_CERTIFICATE_VERIFY_ERROR),"certificate verify error"},
+{ERR_REASON(TS_R_COULD_NOT_SET_ENGINE)   ,"could not set engine"},
+{ERR_REASON(TS_R_COULD_NOT_SET_TIME)     ,"could not set time"},
+{ERR_REASON(TS_R_D2I_TS_RESP_INT_FAILED) ,"d2i ts resp int failed"},
+{ERR_REASON(TS_R_DETACHED_CONTENT)       ,"detached content"},
+{ERR_REASON(TS_R_ESS_ADD_SIGNING_CERT_ERROR),"ess add signing cert error"},
+{ERR_REASON(TS_R_ESS_SIGNING_CERTIFICATE_ERROR),"ess signing certificate error"},
+{ERR_REASON(TS_R_INVALID_NULL_POINTER)   ,"invalid null pointer"},
+{ERR_REASON(TS_R_INVALID_SIGNER_CERTIFICATE_PURPOSE),"invalid signer certificate purpose"},
+{ERR_REASON(TS_R_MESSAGE_IMPRINT_MISMATCH),"message imprint mismatch"},
+{ERR_REASON(TS_R_NONCE_MISMATCH)         ,"nonce mismatch"},
+{ERR_REASON(TS_R_NONCE_NOT_RETURNED)     ,"nonce not returned"},
+{ERR_REASON(TS_R_NO_CONTENT)             ,"no content"},
+{ERR_REASON(TS_R_NO_TIME_STAMP_TOKEN)    ,"no time stamp token"},
+{ERR_REASON(TS_R_PKCS7_ADD_SIGNATURE_ERROR),"pkcs7 add signature error"},
+{ERR_REASON(TS_R_PKCS7_ADD_SIGNED_ATTR_ERROR),"pkcs7 add signed attr error"},
+{ERR_REASON(TS_R_PKCS7_TO_TS_TST_INFO_FAILED),"pkcs7 to ts tst info failed"},
+{ERR_REASON(TS_R_POLICY_MISMATCH)        ,"policy mismatch"},
+{ERR_REASON(TS_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE),"private key does not match certificate"},
+{ERR_REASON(TS_R_RESPONSE_SETUP_ERROR)   ,"response setup error"},
+{ERR_REASON(TS_R_SIGNATURE_FAILURE)      ,"signature failure"},
+{ERR_REASON(TS_R_THERE_MUST_BE_ONE_SIGNER),"there must be one signer"},
+{ERR_REASON(TS_R_TIME_SYSCALL_ERROR)     ,"time syscall error"},
+{ERR_REASON(TS_R_TOKEN_NOT_PRESENT)      ,"token not present"},
+{ERR_REASON(TS_R_TOKEN_PRESENT)          ,"token present"},
+{ERR_REASON(TS_R_TSA_NAME_MISMATCH)      ,"tsa name mismatch"},
+{ERR_REASON(TS_R_TSA_UNTRUSTED)          ,"tsa untrusted"},
+{ERR_REASON(TS_R_TST_INFO_SETUP_ERROR)   ,"tst info setup error"},
+{ERR_REASON(TS_R_TS_DATASIGN)            ,"ts datasign"},
+{ERR_REASON(TS_R_UNACCEPTABLE_POLICY)    ,"unacceptable policy"},
+{ERR_REASON(TS_R_UNSUPPORTED_MD_ALGORITHM),"unsupported md algorithm"},
+{ERR_REASON(TS_R_UNSUPPORTED_VERSION)    ,"unsupported version"},
+{ERR_REASON(TS_R_WRONG_CONTENT_TYPE)     ,"wrong content type"},
+{0,NULL}
+       };
+
+#endif
+
+void ERR_load_TS_strings(void)
+       {
+#ifndef OPENSSL_NO_ERR
+
+       if (ERR_func_error_string(TS_str_functs[0].error) == NULL)
+               {
+               ERR_load_strings(0,TS_str_functs);
+               ERR_load_strings(0,TS_str_reasons);
+               }
+#endif
+       }
diff --git a/deps/openssl/openssl/crypto/ts/ts_lib.c b/deps/openssl/openssl/crypto/ts/ts_lib.c
new file mode 100644 (file)
index 0000000..e8608db
--- /dev/null
@@ -0,0 +1,145 @@
+/* crypto/ts/ts_lib.c */
+/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
+ * project 2002.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include "cryptlib.h"
+#include <openssl/objects.h>
+#include <openssl/bn.h>
+#include <openssl/x509v3.h>
+#include "ts.h"
+
+/* Local function declarations. */
+
+/* Function definitions. */
+
+int TS_ASN1_INTEGER_print_bio(BIO *bio, const ASN1_INTEGER *num)
+       {
+       BIGNUM num_bn;
+       int result = 0;
+       char *hex;
+
+       BN_init(&num_bn);
+       ASN1_INTEGER_to_BN(num, &num_bn);
+       if ((hex = BN_bn2hex(&num_bn))) 
+               {
+               result = BIO_write(bio, "0x", 2) > 0;
+               result = result && BIO_write(bio, hex, strlen(hex)) > 0;
+               OPENSSL_free(hex);
+               }
+       BN_free(&num_bn);
+
+       return result;
+       }
+
+int TS_OBJ_print_bio(BIO *bio, const ASN1_OBJECT *obj)
+       {
+       char obj_txt[128];
+
+       int len = OBJ_obj2txt(obj_txt, sizeof(obj_txt), obj, 0);
+       BIO_write(bio, obj_txt, len);
+       BIO_write(bio, "\n", 1);
+
+       return 1;
+       }
+
+int TS_ext_print_bio(BIO *bio, const STACK_OF(X509_EXTENSION) *extensions)
+       {
+       int i, critical, n;
+       X509_EXTENSION *ex;
+       ASN1_OBJECT *obj;
+
+       BIO_printf(bio, "Extensions:\n");
+       n = X509v3_get_ext_count(extensions);
+       for (i = 0; i < n; i++)
+               {
+               ex = X509v3_get_ext(extensions, i);
+               obj = X509_EXTENSION_get_object(ex);
+               i2a_ASN1_OBJECT(bio, obj);
+               critical = X509_EXTENSION_get_critical(ex);
+               BIO_printf(bio, ": %s\n", critical ? "critical" : "");
+               if (!X509V3_EXT_print(bio, ex, 0, 4))
+                       {
+                       BIO_printf(bio, "%4s", "");
+                       M_ASN1_OCTET_STRING_print(bio, ex->value);
+                       }
+               BIO_write(bio, "\n", 1);
+               }
+
+       return 1;
+       }
+
+int TS_X509_ALGOR_print_bio(BIO *bio, const X509_ALGOR *alg)
+       {
+       int i = OBJ_obj2nid(alg->algorithm);
+       return BIO_printf(bio, "Hash Algorithm: %s\n",
+               (i == NID_undef) ? "UNKNOWN" : OBJ_nid2ln(i));
+       }
+
+int TS_MSG_IMPRINT_print_bio(BIO *bio, TS_MSG_IMPRINT *a)
+       {
+       const ASN1_OCTET_STRING *msg;
+
+       TS_X509_ALGOR_print_bio(bio, TS_MSG_IMPRINT_get_algo(a));
+
+       BIO_printf(bio, "Message data:\n");
+       msg = TS_MSG_IMPRINT_get_msg(a);
+       BIO_dump_indent(bio, (const char *)M_ASN1_STRING_data(msg), 
+                       M_ASN1_STRING_length(msg), 4);
+
+       return 1;
+       }
similarity index 70%
rename from deps/openssl/openssl/crypto/buffer/buf_str.c
rename to deps/openssl/openssl/crypto/ts/ts_req_print.c
index 28dd1e4..eba12c3 100644 (file)
@@ -1,6 +1,9 @@
-/* crypto/buffer/buf_str.c */
+/* crypto/ts/ts_req_print.c */
+/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
+ * project 2002.
+ */
 /* ====================================================================
- * Copyright (c) 2007 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 #include <stdio.h>
 #include "cryptlib.h"
-#include <openssl/buffer.h>
+#include <openssl/objects.h>
+#include <openssl/bn.h>
+#include <openssl/x509v3.h>
+#include <openssl/ts.h>
 
-char *BUF_strdup(const char *str)
-       {
-       if (str == NULL) return(NULL);
-       return BUF_strndup(str, strlen(str));
-       }
+/* Function definitions. */
 
-char *BUF_strndup(const char *str, size_t siz)
+int TS_REQ_print_bio(BIO *bio, TS_REQ *a)
        {
-       char *ret;
+       int v;
+       ASN1_OBJECT *policy_id;
+       const ASN1_INTEGER *nonce;
 
-       if (str == NULL) return(NULL);
+       if (a == NULL) return 0;
 
-       ret=OPENSSL_malloc(siz+1);
-       if (ret == NULL) 
-               {
-               BUFerr(BUF_F_BUF_STRNDUP,ERR_R_MALLOC_FAILURE);
-               return(NULL);
-               }
-       BUF_strlcpy(ret,str,siz+1);
-       return(ret);
-       }
+       v = TS_REQ_get_version(a);
+       BIO_printf(bio, "Version: %d\n", v);
 
-void *BUF_memdup(const void *data, size_t siz)
-       {
-       void *ret;
+       TS_MSG_IMPRINT_print_bio(bio, TS_REQ_get_msg_imprint(a));
 
-       if (data == NULL) return(NULL);
+       BIO_printf(bio, "Policy OID: ");
+       policy_id = TS_REQ_get_policy_id(a);
+       if (policy_id == NULL)
+               BIO_printf(bio, "unspecified\n");
+       else    
+               TS_OBJ_print_bio(bio, policy_id);
 
-       ret=OPENSSL_malloc(siz);
-       if (ret == NULL) 
-               {
-               BUFerr(BUF_F_BUF_MEMDUP,ERR_R_MALLOC_FAILURE);
-               return(NULL);
-               }
-       return memcpy(ret, data, siz);
-       }       
+       BIO_printf(bio, "Nonce: ");
+       nonce = TS_REQ_get_nonce(a);
+       if (nonce == NULL)
+               BIO_printf(bio, "unspecified");
+       else
+               TS_ASN1_INTEGER_print_bio(bio, nonce);
+       BIO_write(bio, "\n", 1);
 
-size_t BUF_strlcpy(char *dst, const char *src, size_t size)
-       {
-       size_t l = 0;
-       for(; size > 1 && *src; size--)
-               {
-               *dst++ = *src++;
-               l++;
-               }
-       if (size)
-               *dst = '\0';
-       return l + strlen(src);
-       }
+       BIO_printf(bio, "Certificate required: %s\n", 
+                  TS_REQ_get_cert_req(a) ? "yes" : "no");
 
-size_t BUF_strlcat(char *dst, const char *src, size_t size)
-       {
-       size_t l = 0;
-       for(; size > 0 && *dst; size--, dst++)
-               l++;
-       return l + BUF_strlcpy(dst, src, size);
+       TS_ext_print_bio(bio, TS_REQ_get_exts(a));
+
+       return 1;
        }
diff --git a/deps/openssl/openssl/crypto/ts/ts_req_utils.c b/deps/openssl/openssl/crypto/ts/ts_req_utils.c
new file mode 100644 (file)
index 0000000..43280c1
--- /dev/null
@@ -0,0 +1,234 @@
+/* crypto/ts/ts_req_utils.c */
+/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
+ * project 2002.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include "cryptlib.h"
+#include <openssl/objects.h>
+#include <openssl/x509v3.h>
+#include <openssl/ts.h>
+
+int TS_REQ_set_version(TS_REQ *a, long version)
+       {
+       return ASN1_INTEGER_set(a->version, version);
+       }
+
+long TS_REQ_get_version(const TS_REQ *a)
+       {
+       return ASN1_INTEGER_get(a->version);
+       }
+
+int TS_REQ_set_msg_imprint(TS_REQ *a, TS_MSG_IMPRINT *msg_imprint)
+       {
+       TS_MSG_IMPRINT *new_msg_imprint;
+
+       if (a->msg_imprint == msg_imprint)
+               return 1;
+       new_msg_imprint = TS_MSG_IMPRINT_dup(msg_imprint);
+       if (new_msg_imprint == NULL)
+               {
+               TSerr(TS_F_TS_REQ_SET_MSG_IMPRINT, ERR_R_MALLOC_FAILURE);
+               return 0;
+               }
+       TS_MSG_IMPRINT_free(a->msg_imprint);
+       a->msg_imprint = new_msg_imprint;
+       return 1;
+       }
+
+TS_MSG_IMPRINT *TS_REQ_get_msg_imprint(TS_REQ *a)
+       {
+       return a->msg_imprint;
+       }
+
+int TS_MSG_IMPRINT_set_algo(TS_MSG_IMPRINT *a, X509_ALGOR *alg)
+       {
+       X509_ALGOR *new_alg;
+
+       if (a->hash_algo == alg)
+               return 1;
+       new_alg = X509_ALGOR_dup(alg);
+       if (new_alg == NULL)
+               {
+               TSerr(TS_F_TS_MSG_IMPRINT_SET_ALGO, ERR_R_MALLOC_FAILURE);
+               return 0;
+               }
+       X509_ALGOR_free(a->hash_algo);
+       a->hash_algo = new_alg;
+       return 1;
+       }
+
+X509_ALGOR *TS_MSG_IMPRINT_get_algo(TS_MSG_IMPRINT *a)
+       {
+       return a->hash_algo;
+       }
+
+int TS_MSG_IMPRINT_set_msg(TS_MSG_IMPRINT *a, unsigned char *d, int len)
+       {
+       return ASN1_OCTET_STRING_set(a->hashed_msg, d, len);
+       }
+
+ASN1_OCTET_STRING *TS_MSG_IMPRINT_get_msg(TS_MSG_IMPRINT *a)
+       {
+       return a->hashed_msg;
+       }
+
+int TS_REQ_set_policy_id(TS_REQ *a, ASN1_OBJECT *policy)
+       {
+       ASN1_OBJECT *new_policy;
+
+       if (a->policy_id == policy)
+               return 1;
+       new_policy = OBJ_dup(policy);
+       if (new_policy == NULL)
+               {
+               TSerr(TS_F_TS_REQ_SET_POLICY_ID, ERR_R_MALLOC_FAILURE);
+               return 0;
+               }
+       ASN1_OBJECT_free(a->policy_id);
+       a->policy_id = new_policy;
+       return 1;
+       }
+
+ASN1_OBJECT *TS_REQ_get_policy_id(TS_REQ *a)
+       {
+       return a->policy_id;
+       }
+
+int TS_REQ_set_nonce(TS_REQ *a, const ASN1_INTEGER *nonce)
+       {
+       ASN1_INTEGER *new_nonce;
+
+       if (a->nonce == nonce)
+               return 1;
+       new_nonce = ASN1_INTEGER_dup(nonce);
+       if (new_nonce == NULL)
+               {
+               TSerr(TS_F_TS_REQ_SET_NONCE, ERR_R_MALLOC_FAILURE);
+               return 0;
+               }
+       ASN1_INTEGER_free(a->nonce);
+       a->nonce = new_nonce;
+       return 1;
+       }
+
+const ASN1_INTEGER *TS_REQ_get_nonce(const TS_REQ *a)
+       {
+       return a->nonce;
+       }
+
+int TS_REQ_set_cert_req(TS_REQ *a, int cert_req)
+       {
+       a->cert_req = cert_req ? 0xFF : 0x00;
+       return 1;
+       }
+
+int TS_REQ_get_cert_req(const TS_REQ *a)
+       {
+       return a->cert_req ? 1 : 0;
+       }
+
+STACK_OF(X509_EXTENSION) *TS_REQ_get_exts(TS_REQ *a)
+       {
+       return a->extensions;
+       }
+
+void TS_REQ_ext_free(TS_REQ *a)
+       {
+       if (!a) return;
+       sk_X509_EXTENSION_pop_free(a->extensions, X509_EXTENSION_free);
+       a->extensions = NULL;
+       }
+
+int TS_REQ_get_ext_count(TS_REQ *a)
+       {
+       return X509v3_get_ext_count(a->extensions);
+       }
+
+int TS_REQ_get_ext_by_NID(TS_REQ *a, int nid, int lastpos)
+       {
+       return X509v3_get_ext_by_NID(a->extensions, nid, lastpos);
+       }
+
+int TS_REQ_get_ext_by_OBJ(TS_REQ *a, ASN1_OBJECT *obj, int lastpos)
+       {
+       return X509v3_get_ext_by_OBJ(a->extensions, obj, lastpos);
+       }
+
+int TS_REQ_get_ext_by_critical(TS_REQ *a, int crit, int lastpos)
+       {
+       return X509v3_get_ext_by_critical(a->extensions, crit, lastpos);
+       }
+
+X509_EXTENSION *TS_REQ_get_ext(TS_REQ *a, int loc)
+       {
+       return X509v3_get_ext(a->extensions,loc);
+       }
+
+X509_EXTENSION *TS_REQ_delete_ext(TS_REQ *a, int loc)
+       {
+       return X509v3_delete_ext(a->extensions,loc);
+       }
+
+int TS_REQ_add_ext(TS_REQ *a, X509_EXTENSION *ex, int loc)
+       {
+       return X509v3_add_ext(&a->extensions,ex,loc) != NULL;
+       }
+
+void *TS_REQ_get_ext_d2i(TS_REQ *a, int nid, int *crit, int *idx)
+       {
+       return X509V3_get_d2i(a->extensions, nid, crit, idx);
+       }
diff --git a/deps/openssl/openssl/crypto/ts/ts_rsp_print.c b/deps/openssl/openssl/crypto/ts/ts_rsp_print.c
new file mode 100644 (file)
index 0000000..2106251
--- /dev/null
@@ -0,0 +1,287 @@
+/* crypto/ts/ts_resp_print.c */
+/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
+ * project 2002.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include "cryptlib.h"
+#include <openssl/objects.h>
+#include <openssl/bn.h>
+#include <openssl/x509v3.h>
+#include "ts.h"
+
+struct status_map_st
+       {
+       int bit;
+       const char *text;
+       };
+
+/* Local function declarations. */
+
+static int TS_status_map_print(BIO *bio, struct status_map_st *a,
+                              ASN1_BIT_STRING *v);
+static int TS_ACCURACY_print_bio(BIO *bio, const TS_ACCURACY *accuracy);
+
+/* Function definitions. */
+
+int TS_RESP_print_bio(BIO *bio, TS_RESP *a)
+       {
+       TS_TST_INFO *tst_info;
+
+       BIO_printf(bio, "Status info:\n");
+       TS_STATUS_INFO_print_bio(bio, TS_RESP_get_status_info(a));
+
+       BIO_printf(bio, "\nTST info:\n");
+       tst_info = TS_RESP_get_tst_info(a);
+       if (tst_info != NULL)
+               TS_TST_INFO_print_bio(bio, TS_RESP_get_tst_info(a));
+       else
+               BIO_printf(bio, "Not included.\n");
+               
+       return 1;
+       }
+
+int TS_STATUS_INFO_print_bio(BIO *bio, TS_STATUS_INFO *a)
+       {
+       static const char *status_map[] =
+               {
+               "Granted.",
+               "Granted with modifications.",
+               "Rejected.",
+               "Waiting.",
+               "Revocation warning.",
+               "Revoked."
+               };
+       static struct status_map_st failure_map[] =
+               {
+               { TS_INFO_BAD_ALG,
+               "unrecognized or unsupported algorithm identifier" },
+               { TS_INFO_BAD_REQUEST,
+               "transaction not permitted or supported" },
+               { TS_INFO_BAD_DATA_FORMAT,
+               "the data submitted has the wrong format" },
+               { TS_INFO_TIME_NOT_AVAILABLE,
+               "the TSA's time source is not available" },
+               { TS_INFO_UNACCEPTED_POLICY,
+               "the requested TSA policy is not supported by the TSA" },
+               { TS_INFO_UNACCEPTED_EXTENSION,
+               "the requested extension is not supported by the TSA" },
+               { TS_INFO_ADD_INFO_NOT_AVAILABLE,
+               "the additional information requested could not be understood "
+               "or is not available" },
+               { TS_INFO_SYSTEM_FAILURE,
+               "the request cannot be handled due to system failure" },
+               { -1, NULL }
+               };
+       long status;
+       int i, lines = 0;
+
+       /* Printing status code. */
+       BIO_printf(bio, "Status: ");
+       status = ASN1_INTEGER_get(a->status);
+       if (0 <= status && status < (long)(sizeof(status_map)/sizeof(status_map[0])))
+               BIO_printf(bio, "%s\n", status_map[status]);
+       else
+               BIO_printf(bio, "out of bounds\n");
+       
+       /* Printing status description. */
+       BIO_printf(bio, "Status description: ");
+       for (i = 0; i < sk_ASN1_UTF8STRING_num(a->text); ++i)
+               {
+               if (i > 0)
+                       BIO_puts(bio, "\t");
+               ASN1_STRING_print_ex(bio, sk_ASN1_UTF8STRING_value(a->text, i),
+                                    0);
+               BIO_puts(bio, "\n");
+               }
+       if (i == 0)
+               BIO_printf(bio, "unspecified\n");
+
+       /* Printing failure information. */
+       BIO_printf(bio, "Failure info: ");
+       if (a->failure_info != NULL)
+               lines = TS_status_map_print(bio, failure_map,
+                                           a->failure_info);
+       if (lines == 0)
+               BIO_printf(bio, "unspecified");
+       BIO_printf(bio, "\n");
+
+       return 1;
+       }
+
+static int TS_status_map_print(BIO *bio, struct status_map_st *a,
+                              ASN1_BIT_STRING *v)
+       {
+       int lines = 0;
+
+       for (; a->bit >= 0; ++a)
+               {
+               if (ASN1_BIT_STRING_get_bit(v, a->bit))
+                       {
+                       if (++lines > 1)
+                               BIO_printf(bio, ", ");
+                       BIO_printf(bio, "%s", a->text);
+                       }
+               }
+
+       return lines;
+       }
+
+int TS_TST_INFO_print_bio(BIO *bio, TS_TST_INFO *a)
+       {
+       int v;
+       ASN1_OBJECT *policy_id;
+       const ASN1_INTEGER *serial;
+       const ASN1_GENERALIZEDTIME *gtime;
+       TS_ACCURACY *accuracy;
+       const ASN1_INTEGER *nonce;
+       GENERAL_NAME *tsa_name;
+
+       if (a == NULL) return 0;
+
+       /* Print version. */
+       v = TS_TST_INFO_get_version(a);
+       BIO_printf(bio, "Version: %d\n", v);
+
+       /* Print policy id. */
+       BIO_printf(bio, "Policy OID: ");
+       policy_id = TS_TST_INFO_get_policy_id(a);
+       TS_OBJ_print_bio(bio, policy_id);
+
+       /* Print message imprint. */
+       TS_MSG_IMPRINT_print_bio(bio, TS_TST_INFO_get_msg_imprint(a));
+
+       /* Print serial number. */
+       BIO_printf(bio, "Serial number: ");
+       serial = TS_TST_INFO_get_serial(a);
+       if (serial == NULL)
+               BIO_printf(bio, "unspecified");
+       else
+               TS_ASN1_INTEGER_print_bio(bio, serial);
+       BIO_write(bio, "\n", 1);
+
+       /* Print time stamp. */
+       BIO_printf(bio, "Time stamp: ");
+       gtime = TS_TST_INFO_get_time(a);
+       ASN1_GENERALIZEDTIME_print(bio, gtime);
+       BIO_write(bio, "\n", 1);
+
+       /* Print accuracy. */
+       BIO_printf(bio, "Accuracy: ");
+       accuracy = TS_TST_INFO_get_accuracy(a);
+       if (accuracy == NULL)
+               BIO_printf(bio, "unspecified");
+       else
+               TS_ACCURACY_print_bio(bio, accuracy);
+       BIO_write(bio, "\n", 1);
+
+       /* Print ordering. */
+       BIO_printf(bio, "Ordering: %s\n", 
+                  TS_TST_INFO_get_ordering(a) ? "yes" : "no");
+
+       /* Print nonce. */
+       BIO_printf(bio, "Nonce: ");
+       nonce = TS_TST_INFO_get_nonce(a);
+       if (nonce == NULL)
+               BIO_printf(bio, "unspecified");
+       else
+               TS_ASN1_INTEGER_print_bio(bio, nonce);
+       BIO_write(bio, "\n", 1);
+
+       /* Print TSA name. */
+       BIO_printf(bio, "TSA: ");
+       tsa_name = TS_TST_INFO_get_tsa(a);
+       if (tsa_name == NULL)
+               BIO_printf(bio, "unspecified");
+       else
+               {
+               STACK_OF(CONF_VALUE) *nval;
+               if ((nval = i2v_GENERAL_NAME(NULL, tsa_name, NULL)))
+                       X509V3_EXT_val_prn(bio, nval, 0, 0);
+               sk_CONF_VALUE_pop_free(nval, X509V3_conf_free);
+               }
+       BIO_write(bio, "\n", 1);
+
+       /* Print extensions. */
+       TS_ext_print_bio(bio, TS_TST_INFO_get_exts(a));
+
+       return 1;
+       }
+
+static int TS_ACCURACY_print_bio(BIO *bio, const TS_ACCURACY *accuracy)
+       {
+       const ASN1_INTEGER *seconds = TS_ACCURACY_get_seconds(accuracy);
+       const ASN1_INTEGER *millis = TS_ACCURACY_get_millis(accuracy);
+       const ASN1_INTEGER *micros = TS_ACCURACY_get_micros(accuracy);
+
+       if (seconds != NULL)
+               TS_ASN1_INTEGER_print_bio(bio, seconds);
+       else
+               BIO_printf(bio, "unspecified");
+       BIO_printf(bio, " seconds, ");
+       if (millis != NULL)
+               TS_ASN1_INTEGER_print_bio(bio, millis);
+       else
+               BIO_printf(bio, "unspecified");
+       BIO_printf(bio, " millis, ");
+       if (micros != NULL)
+               TS_ASN1_INTEGER_print_bio(bio, micros);
+       else
+               BIO_printf(bio, "unspecified");
+       BIO_printf(bio, " micros");
+
+       return 1;
+       }
diff --git a/deps/openssl/openssl/crypto/ts/ts_rsp_sign.c b/deps/openssl/openssl/crypto/ts/ts_rsp_sign.c
new file mode 100644 (file)
index 0000000..b0f023c
--- /dev/null
@@ -0,0 +1,1020 @@
+/* crypto/ts/ts_resp_sign.c */
+/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
+ * project 2002.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include "cryptlib.h"
+
+#if defined(OPENSSL_SYS_UNIX)
+#include <sys/time.h>
+#endif
+
+#include <openssl/objects.h>
+#include <openssl/ts.h>
+#include <openssl/pkcs7.h>
+
+/* Private function declarations. */
+
+static ASN1_INTEGER *def_serial_cb(struct TS_resp_ctx *, void *);
+static int def_time_cb(struct TS_resp_ctx *, void *, long *sec, long *usec);
+static int def_extension_cb(struct TS_resp_ctx *, X509_EXTENSION *, void *);
+
+static void TS_RESP_CTX_init(TS_RESP_CTX *ctx);
+static void TS_RESP_CTX_cleanup(TS_RESP_CTX *ctx);
+static int TS_RESP_check_request(TS_RESP_CTX *ctx);
+static ASN1_OBJECT *TS_RESP_get_policy(TS_RESP_CTX *ctx);
+static TS_TST_INFO *TS_RESP_create_tst_info(TS_RESP_CTX *ctx, 
+                                           ASN1_OBJECT *policy);
+static int TS_RESP_process_extensions(TS_RESP_CTX *ctx);
+static int TS_RESP_sign(TS_RESP_CTX *ctx);
+
+static ESS_SIGNING_CERT *ESS_SIGNING_CERT_new_init(X509 *signcert, 
+                                                  STACK_OF(X509) *certs);
+static ESS_CERT_ID *ESS_CERT_ID_new_init(X509 *cert, int issuer_needed);
+static int TS_TST_INFO_content_new(PKCS7 *p7);
+static int ESS_add_signing_cert(PKCS7_SIGNER_INFO *si, ESS_SIGNING_CERT *sc);
+
+static ASN1_GENERALIZEDTIME *TS_RESP_set_genTime_with_precision(
+       ASN1_GENERALIZEDTIME *, long, long, unsigned);
+
+/* Default callbacks for response generation. */
+
+static ASN1_INTEGER *def_serial_cb(struct TS_resp_ctx *ctx, void *data)
+       {
+       ASN1_INTEGER *serial = ASN1_INTEGER_new();
+       if (!serial) goto err;
+       if (!ASN1_INTEGER_set(serial, 1)) goto err;
+       return serial;
+ err:
+       TSerr(TS_F_DEF_SERIAL_CB, ERR_R_MALLOC_FAILURE);
+       TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION,
+                                   "Error during serial number generation.");
+       return NULL;
+       }
+
+#if defined(OPENSSL_SYS_UNIX)
+
+/* Use the gettimeofday function call. */
+static int def_time_cb(struct TS_resp_ctx *ctx, void *data, 
+                      long *sec, long *usec)
+       {
+       struct timeval tv;
+       if (gettimeofday(&tv, NULL) != 0) 
+               {
+               TSerr(TS_F_DEF_TIME_CB, TS_R_TIME_SYSCALL_ERROR);
+               TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION,
+                                           "Time is not available.");
+               TS_RESP_CTX_add_failure_info(ctx, TS_INFO_TIME_NOT_AVAILABLE);
+               return 0;
+               }
+       /* Return time to caller. */
+       *sec = tv.tv_sec;
+       *usec = tv.tv_usec;
+
+       return 1;
+       }
+
+#else
+
+/* Use the time function call that provides only seconds precision. */
+static int def_time_cb(struct TS_resp_ctx *ctx, void *data, 
+                      long *sec, long *usec)
+       {
+       time_t t;
+       if (time(&t) == (time_t) -1)
+               {
+               TSerr(TS_F_DEF_TIME_CB, TS_R_TIME_SYSCALL_ERROR);
+               TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION,
+                                           "Time is not available.");
+               TS_RESP_CTX_add_failure_info(ctx, TS_INFO_TIME_NOT_AVAILABLE);
+               return 0;
+               }
+       /* Return time to caller, only second precision. */
+       *sec = (long) t;
+       *usec = 0;
+
+       return 1;
+       }
+
+#endif
+
+static int def_extension_cb(struct TS_resp_ctx *ctx, X509_EXTENSION *ext,
+                           void *data)
+       {
+       /* No extensions are processed here. */
+       TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION,
+                                   "Unsupported extension.");
+       TS_RESP_CTX_add_failure_info(ctx, TS_INFO_UNACCEPTED_EXTENSION);
+       return 0;
+       }
+
+/* TS_RESP_CTX management functions. */
+
+TS_RESP_CTX *TS_RESP_CTX_new()
+       {
+       TS_RESP_CTX *ctx;
+
+       if (!(ctx = (TS_RESP_CTX *) OPENSSL_malloc(sizeof(TS_RESP_CTX))))
+               {
+               TSerr(TS_F_TS_RESP_CTX_NEW, ERR_R_MALLOC_FAILURE);
+               return NULL;
+               }
+       memset(ctx, 0, sizeof(TS_RESP_CTX));
+
+       /* Setting default callbacks. */
+       ctx->serial_cb = def_serial_cb;
+       ctx->time_cb = def_time_cb;
+       ctx->extension_cb = def_extension_cb;
+
+       return ctx;
+       }
+
+void TS_RESP_CTX_free(TS_RESP_CTX *ctx)
+       {
+       if (!ctx) return;
+
+       X509_free(ctx->signer_cert);
+       EVP_PKEY_free(ctx->signer_key);
+       sk_X509_pop_free(ctx->certs, X509_free);
+       sk_ASN1_OBJECT_pop_free(ctx->policies, ASN1_OBJECT_free);
+       ASN1_OBJECT_free(ctx->default_policy);
+       sk_EVP_MD_free(ctx->mds);       /* No EVP_MD_free method exists. */
+       ASN1_INTEGER_free(ctx->seconds);
+       ASN1_INTEGER_free(ctx->millis);
+       ASN1_INTEGER_free(ctx->micros);
+       OPENSSL_free(ctx);
+       }
+
+int TS_RESP_CTX_set_signer_cert(TS_RESP_CTX *ctx, X509 *signer)
+       {
+       if (X509_check_purpose(signer, X509_PURPOSE_TIMESTAMP_SIGN, 0) != 1)
+               {
+               TSerr(TS_F_TS_RESP_CTX_SET_SIGNER_CERT, 
+                     TS_R_INVALID_SIGNER_CERTIFICATE_PURPOSE);
+               return 0;
+               }
+       if (ctx->signer_cert) X509_free(ctx->signer_cert);
+       ctx->signer_cert = signer;
+       CRYPTO_add(&ctx->signer_cert->references, +1, CRYPTO_LOCK_X509);
+       return 1;
+       }
+
+int TS_RESP_CTX_set_signer_key(TS_RESP_CTX *ctx, EVP_PKEY *key)
+       {
+       if (ctx->signer_key) EVP_PKEY_free(ctx->signer_key);
+       ctx->signer_key = key;
+       CRYPTO_add(&ctx->signer_key->references, +1, CRYPTO_LOCK_EVP_PKEY);
+
+       return 1;
+       }
+
+int TS_RESP_CTX_set_def_policy(TS_RESP_CTX *ctx, ASN1_OBJECT *def_policy)
+       {
+       if (ctx->default_policy) ASN1_OBJECT_free(ctx->default_policy);
+       if (!(ctx->default_policy = OBJ_dup(def_policy))) goto err;
+       return 1;
+ err:
+       TSerr(TS_F_TS_RESP_CTX_SET_DEF_POLICY, ERR_R_MALLOC_FAILURE);
+       return 0;
+       }
+
+int TS_RESP_CTX_set_certs(TS_RESP_CTX *ctx, STACK_OF(X509) *certs)
+       {
+       int i;
+
+       if (ctx->certs)
+               {
+               sk_X509_pop_free(ctx->certs, X509_free);
+               ctx->certs = NULL;
+               }
+       if (!certs) return 1;
+       if (!(ctx->certs = sk_X509_dup(certs))) 
+               {
+               TSerr(TS_F_TS_RESP_CTX_SET_CERTS, ERR_R_MALLOC_FAILURE);
+               return 0;
+               }
+       for (i = 0; i < sk_X509_num(ctx->certs); ++i)
+               {
+               X509 *cert = sk_X509_value(ctx->certs, i);
+               CRYPTO_add(&cert->references, +1, CRYPTO_LOCK_X509);
+               }
+
+       return 1;
+       }
+
+int TS_RESP_CTX_add_policy(TS_RESP_CTX *ctx, ASN1_OBJECT *policy)
+       {
+       ASN1_OBJECT *copy = NULL;
+
+       /* Create new policy stack if necessary. */
+       if (!ctx->policies && !(ctx->policies = sk_ASN1_OBJECT_new_null())) 
+               goto err;
+       if (!(copy = OBJ_dup(policy))) goto err;
+       if (!sk_ASN1_OBJECT_push(ctx->policies, copy)) goto err;
+
+       return 1;
+ err:
+       TSerr(TS_F_TS_RESP_CTX_ADD_POLICY, ERR_R_MALLOC_FAILURE);
+       ASN1_OBJECT_free(copy);
+       return 0;
+       }
+
+int TS_RESP_CTX_add_md(TS_RESP_CTX *ctx, const EVP_MD *md)
+       {
+       /* Create new md stack if necessary. */
+       if (!ctx->mds && !(ctx->mds = sk_EVP_MD_new_null())) 
+               goto err;
+       /* Add the shared md, no copy needed. */
+       if (!sk_EVP_MD_push(ctx->mds, (EVP_MD *)md)) goto err;
+
+       return 1;
+ err:
+       TSerr(TS_F_TS_RESP_CTX_ADD_MD, ERR_R_MALLOC_FAILURE);
+       return 0;
+       }
+
+#define TS_RESP_CTX_accuracy_free(ctx)         \
+       ASN1_INTEGER_free(ctx->seconds);        \
+       ctx->seconds = NULL;                    \
+       ASN1_INTEGER_free(ctx->millis);         \
+       ctx->millis = NULL;                     \
+       ASN1_INTEGER_free(ctx->micros);         \
+       ctx->micros = NULL;
+
+int TS_RESP_CTX_set_accuracy(TS_RESP_CTX *ctx, 
+                            int secs, int millis, int micros)
+       {
+
+       TS_RESP_CTX_accuracy_free(ctx);
+       if (secs && (!(ctx->seconds = ASN1_INTEGER_new())
+                    || !ASN1_INTEGER_set(ctx->seconds, secs)))
+               goto err;
+       if (millis && (!(ctx->millis = ASN1_INTEGER_new())
+                      || !ASN1_INTEGER_set(ctx->millis, millis)))
+               goto err;
+       if (micros && (!(ctx->micros = ASN1_INTEGER_new())
+                      || !ASN1_INTEGER_set(ctx->micros, micros)))
+               goto err;
+
+       return 1;
+ err:
+       TS_RESP_CTX_accuracy_free(ctx);
+       TSerr(TS_F_TS_RESP_CTX_SET_ACCURACY, ERR_R_MALLOC_FAILURE);
+       return 0;
+       }
+
+void TS_RESP_CTX_add_flags(TS_RESP_CTX *ctx, int flags)
+       {
+       ctx->flags |= flags;
+       }
+
+void TS_RESP_CTX_set_serial_cb(TS_RESP_CTX *ctx, TS_serial_cb cb, void *data)
+       {
+       ctx->serial_cb = cb;
+       ctx->serial_cb_data = data;
+       }
+
+void TS_RESP_CTX_set_time_cb(TS_RESP_CTX *ctx, TS_time_cb cb, void *data)
+       {
+       ctx->time_cb = cb;
+       ctx->time_cb_data = data;
+       }
+
+void TS_RESP_CTX_set_extension_cb(TS_RESP_CTX *ctx, 
+                                 TS_extension_cb cb, void *data)
+       {
+       ctx->extension_cb = cb;
+       ctx->extension_cb_data = data;
+       }
+
+int TS_RESP_CTX_set_status_info(TS_RESP_CTX *ctx, 
+                               int status, const char *text)
+       {
+       TS_STATUS_INFO *si = NULL;
+       ASN1_UTF8STRING *utf8_text = NULL;
+       int ret = 0;
+
+       if (!(si = TS_STATUS_INFO_new())) goto err;
+       if (!ASN1_INTEGER_set(si->status, status)) goto err;
+       if (text)
+               {
+               if (!(utf8_text = ASN1_UTF8STRING_new())
+                   || !ASN1_STRING_set(utf8_text, text, strlen(text)))
+                       goto err;
+               if (!si->text && !(si->text = sk_ASN1_UTF8STRING_new_null()))
+                       goto err;
+               if (!sk_ASN1_UTF8STRING_push(si->text, utf8_text)) goto err;
+               utf8_text = NULL;       /* Ownership is lost. */
+               }
+       if (!TS_RESP_set_status_info(ctx->response, si)) goto err;
+       ret = 1;
+ err:
+       if (!ret)
+               TSerr(TS_F_TS_RESP_CTX_SET_STATUS_INFO, ERR_R_MALLOC_FAILURE);
+       TS_STATUS_INFO_free(si);
+       ASN1_UTF8STRING_free(utf8_text);
+       return ret;
+       }
+
+int TS_RESP_CTX_set_status_info_cond(TS_RESP_CTX *ctx, 
+                                    int status, const char *text)
+       {
+       int ret = 1;
+       TS_STATUS_INFO *si = TS_RESP_get_status_info(ctx->response);
+
+       if (ASN1_INTEGER_get(si->status) == TS_STATUS_GRANTED)
+               {
+               /* Status has not been set, set it now. */
+               ret = TS_RESP_CTX_set_status_info(ctx, status, text);
+               }
+       return ret;
+       }
+
+int TS_RESP_CTX_add_failure_info(TS_RESP_CTX *ctx, int failure)
+       {
+       TS_STATUS_INFO *si = TS_RESP_get_status_info(ctx->response);
+       if (!si->failure_info && !(si->failure_info = ASN1_BIT_STRING_new()))
+               goto err;
+       if (!ASN1_BIT_STRING_set_bit(si->failure_info, failure, 1))
+               goto err;
+       return 1;
+ err:
+       TSerr(TS_F_TS_RESP_CTX_ADD_FAILURE_INFO, ERR_R_MALLOC_FAILURE);
+       return 0;
+       }
+
+TS_REQ *TS_RESP_CTX_get_request(TS_RESP_CTX *ctx)
+       {
+       return ctx->request;
+       }
+
+TS_TST_INFO *TS_RESP_CTX_get_tst_info(TS_RESP_CTX *ctx)
+       {
+       return ctx->tst_info;
+       }
+
+int TS_RESP_CTX_set_clock_precision_digits(TS_RESP_CTX *ctx, unsigned precision)
+       {
+       if (precision > TS_MAX_CLOCK_PRECISION_DIGITS)
+              return 0;
+       ctx->clock_precision_digits = precision;
+       return 1;
+       }
+
+/* Main entry method of the response generation. */
+TS_RESP *TS_RESP_create_response(TS_RESP_CTX *ctx, BIO *req_bio)
+       {
+       ASN1_OBJECT *policy;
+       TS_RESP *response;
+       int result = 0;
+
+       TS_RESP_CTX_init(ctx);
+
+       /* Creating the response object. */
+       if (!(ctx->response = TS_RESP_new())) 
+               {
+               TSerr(TS_F_TS_RESP_CREATE_RESPONSE, ERR_R_MALLOC_FAILURE);
+               goto end;
+               }
+
+       /* Parsing DER request. */
+       if (!(ctx->request = d2i_TS_REQ_bio(req_bio, NULL)))
+               {
+               TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION,
+                                           "Bad request format or "
+                                           "system error.");
+               TS_RESP_CTX_add_failure_info(ctx, TS_INFO_BAD_DATA_FORMAT);
+               goto end;
+               }
+
+       /* Setting default status info. */
+       if (!TS_RESP_CTX_set_status_info(ctx, TS_STATUS_GRANTED, NULL))
+               goto end;
+
+       /* Checking the request format. */
+       if (!TS_RESP_check_request(ctx)) goto end;
+
+       /* Checking acceptable policies. */
+       if (!(policy = TS_RESP_get_policy(ctx))) goto end;
+
+       /* Creating the TS_TST_INFO object. */
+       if (!(ctx->tst_info = TS_RESP_create_tst_info(ctx, policy)))
+               goto end;
+
+       /* Processing extensions. */
+       if (!TS_RESP_process_extensions(ctx)) goto end;
+
+       /* Generating the signature. */
+       if (!TS_RESP_sign(ctx)) goto end;
+
+       /* Everything was successful. */
+       result = 1;
+ end:
+       if (!result)
+               {
+               TSerr(TS_F_TS_RESP_CREATE_RESPONSE, TS_R_RESPONSE_SETUP_ERROR);
+               if (ctx->response != NULL)
+                       {
+                       if (TS_RESP_CTX_set_status_info_cond(ctx,
+                               TS_STATUS_REJECTION, "Error during response "
+                               "generation.") == 0)
+                               {
+                               TS_RESP_free(ctx->response);
+                               ctx->response = NULL;
+                               }
+                       }
+               }
+       response = ctx->response;
+       ctx->response = NULL;   /* Ownership will be returned to caller. */
+       TS_RESP_CTX_cleanup(ctx);
+       return response;
+       }
+
+/* Initializes the variable part of the context. */
+static void TS_RESP_CTX_init(TS_RESP_CTX *ctx)
+       {
+       ctx->request = NULL;
+       ctx->response = NULL;
+       ctx->tst_info = NULL;
+       }
+
+/* Cleans up the variable part of the context. */
+static void TS_RESP_CTX_cleanup(TS_RESP_CTX *ctx)
+       {
+       TS_REQ_free(ctx->request);
+       ctx->request = NULL;
+       TS_RESP_free(ctx->response);
+       ctx->response = NULL;
+       TS_TST_INFO_free(ctx->tst_info);
+       ctx->tst_info = NULL;
+       }
+
+/* Checks the format and content of the request. */
+static int TS_RESP_check_request(TS_RESP_CTX *ctx)
+       {
+       TS_REQ *request = ctx->request;
+       TS_MSG_IMPRINT *msg_imprint;
+       X509_ALGOR *md_alg;
+       int md_alg_id;
+       const ASN1_OCTET_STRING *digest;
+       EVP_MD *md = NULL;
+       int i;
+
+       /* Checking request version. */
+       if (TS_REQ_get_version(request) != 1)
+               {
+               TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION,
+                                           "Bad request version.");
+               TS_RESP_CTX_add_failure_info(ctx, TS_INFO_BAD_REQUEST);
+               return 0;
+               }
+
+       /* Checking message digest algorithm. */
+       msg_imprint = TS_REQ_get_msg_imprint(request);
+       md_alg = TS_MSG_IMPRINT_get_algo(msg_imprint);
+       md_alg_id = OBJ_obj2nid(md_alg->algorithm);
+       for (i = 0; !md && i < sk_EVP_MD_num(ctx->mds); ++i)
+               {
+               EVP_MD *current_md = sk_EVP_MD_value(ctx->mds, i);
+               if (md_alg_id == EVP_MD_type(current_md))
+                       md = current_md;
+               }
+       if (!md)
+               {
+               TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION,
+                                           "Message digest algorithm is "
+                                           "not supported.");
+               TS_RESP_CTX_add_failure_info(ctx, TS_INFO_BAD_ALG);
+               return 0;
+               }
+
+       /* No message digest takes parameter. */
+       if (md_alg->parameter 
+           && ASN1_TYPE_get(md_alg->parameter) != V_ASN1_NULL)
+               {
+               TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION,
+                                           "Superfluous message digest "
+                                           "parameter.");
+               TS_RESP_CTX_add_failure_info(ctx, TS_INFO_BAD_ALG);
+               return 0;
+               }
+       /* Checking message digest size. */
+       digest = TS_MSG_IMPRINT_get_msg(msg_imprint);
+       if (digest->length != EVP_MD_size(md))
+               {
+               TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION,
+                                           "Bad message digest.");
+               TS_RESP_CTX_add_failure_info(ctx, TS_INFO_BAD_DATA_FORMAT);
+               return 0;
+               }
+
+       return 1;
+       }
+
+/* Returns the TSA policy based on the requested and acceptable policies. */
+static ASN1_OBJECT *TS_RESP_get_policy(TS_RESP_CTX *ctx)
+       {
+       ASN1_OBJECT *requested = TS_REQ_get_policy_id(ctx->request);
+       ASN1_OBJECT *policy = NULL;
+       int i;
+
+       if (ctx->default_policy == NULL)
+               {
+               TSerr(TS_F_TS_RESP_GET_POLICY, TS_R_INVALID_NULL_POINTER);
+               return NULL;
+               }
+       /* Return the default policy if none is requested or the default is
+          requested. */
+       if (!requested || !OBJ_cmp(requested, ctx->default_policy))
+               policy = ctx->default_policy;
+
+       /* Check if the policy is acceptable. */
+       for (i = 0; !policy && i < sk_ASN1_OBJECT_num(ctx->policies); ++i)
+               {
+               ASN1_OBJECT *current = sk_ASN1_OBJECT_value(ctx->policies, i);
+               if (!OBJ_cmp(requested, current))
+                       policy = current;
+               }
+       if (!policy)
+               {
+               TSerr(TS_F_TS_RESP_GET_POLICY, TS_R_UNACCEPTABLE_POLICY);
+               TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION,
+                                           "Requested policy is not "
+                                           "supported.");
+               TS_RESP_CTX_add_failure_info(ctx, TS_INFO_UNACCEPTED_POLICY);
+               }
+       return policy;
+       }
+
+/* Creates the TS_TST_INFO object based on the settings of the context. */
+static TS_TST_INFO *TS_RESP_create_tst_info(TS_RESP_CTX *ctx,
+                                           ASN1_OBJECT *policy)
+       {
+       int result = 0;
+       TS_TST_INFO *tst_info = NULL;
+       ASN1_INTEGER *serial = NULL;
+       ASN1_GENERALIZEDTIME *asn1_time = NULL;
+       long sec, usec;
+       TS_ACCURACY *accuracy = NULL;
+       const ASN1_INTEGER *nonce;
+       GENERAL_NAME *tsa_name = NULL;
+
+       if (!(tst_info = TS_TST_INFO_new())) goto end;
+       if (!TS_TST_INFO_set_version(tst_info, 1)) goto end;
+       if (!TS_TST_INFO_set_policy_id(tst_info, policy)) goto end;
+       if (!TS_TST_INFO_set_msg_imprint(tst_info, ctx->request->msg_imprint))
+               goto end;
+       if (!(serial = (*ctx->serial_cb)(ctx, ctx->serial_cb_data))
+           || !TS_TST_INFO_set_serial(tst_info, serial))
+               goto end;
+       if (!(*ctx->time_cb)(ctx, ctx->time_cb_data, &sec, &usec)
+            || !(asn1_time = TS_RESP_set_genTime_with_precision(NULL, 
+                                       sec, usec, 
+                                       ctx->clock_precision_digits))
+           || !TS_TST_INFO_set_time(tst_info, asn1_time))
+               goto end;
+
+       /* Setting accuracy if needed. */
+       if ((ctx->seconds || ctx->millis || ctx->micros) 
+           && !(accuracy = TS_ACCURACY_new()))
+               goto end;
+
+       if (ctx->seconds && !TS_ACCURACY_set_seconds(accuracy, ctx->seconds))
+               goto end;
+       if (ctx->millis && !TS_ACCURACY_set_millis(accuracy, ctx->millis))
+               goto end;
+       if (ctx->micros && !TS_ACCURACY_set_micros(accuracy, ctx->micros))
+               goto end;
+       if (accuracy && !TS_TST_INFO_set_accuracy(tst_info, accuracy)) 
+               goto end;
+
+       /* Setting ordering. */
+       if ((ctx->flags & TS_ORDERING) 
+           && !TS_TST_INFO_set_ordering(tst_info, 1))
+               goto end;
+       
+       /* Setting nonce if needed. */
+       if ((nonce = TS_REQ_get_nonce(ctx->request)) != NULL
+           && !TS_TST_INFO_set_nonce(tst_info, nonce))
+               goto end;
+
+       /* Setting TSA name to subject of signer certificate. */
+       if (ctx->flags & TS_TSA_NAME)
+               {
+               if (!(tsa_name = GENERAL_NAME_new())) goto end;
+               tsa_name->type = GEN_DIRNAME;
+               tsa_name->d.dirn = 
+                       X509_NAME_dup(ctx->signer_cert->cert_info->subject);
+               if (!tsa_name->d.dirn) goto end;
+               if (!TS_TST_INFO_set_tsa(tst_info, tsa_name)) goto end;
+               }
+
+       result = 1;
+ end:
+       if (!result)
+               {
+               TS_TST_INFO_free(tst_info);
+               tst_info = NULL;
+               TSerr(TS_F_TS_RESP_CREATE_TST_INFO, TS_R_TST_INFO_SETUP_ERROR);
+               TS_RESP_CTX_set_status_info_cond(ctx, TS_STATUS_REJECTION,
+                                                "Error during TSTInfo "
+                                                "generation.");
+               }
+       GENERAL_NAME_free(tsa_name);
+       TS_ACCURACY_free(accuracy);
+       ASN1_GENERALIZEDTIME_free(asn1_time);
+       ASN1_INTEGER_free(serial);
+       
+       return tst_info;
+       }
+
+/* Processing the extensions of the request. */
+static int TS_RESP_process_extensions(TS_RESP_CTX *ctx)
+       {
+       STACK_OF(X509_EXTENSION) *exts = TS_REQ_get_exts(ctx->request);
+       int i;
+       int ok = 1;
+
+       for (i = 0; ok && i < sk_X509_EXTENSION_num(exts); ++i)
+               {
+               X509_EXTENSION *ext = sk_X509_EXTENSION_value(exts, i);
+               /* XXXXX The last argument was previously
+                  (void *)ctx->extension_cb, but ISO C doesn't permit
+                  converting a function pointer to void *.  For lack of
+                  better information, I'm placing a NULL there instead.
+                  The callback can pick its own address out from the ctx
+                  anyway...
+               */
+               ok = (*ctx->extension_cb)(ctx, ext, NULL);
+               }
+
+       return ok;
+       }
+
+/* Functions for signing the TS_TST_INFO structure of the context. */
+static int TS_RESP_sign(TS_RESP_CTX *ctx)
+       {
+       int ret = 0;
+       PKCS7 *p7 = NULL;
+       PKCS7_SIGNER_INFO *si;
+       STACK_OF(X509) *certs;  /* Certificates to include in sc. */
+       ESS_SIGNING_CERT *sc = NULL;
+       ASN1_OBJECT *oid;
+       BIO *p7bio = NULL;
+       int i;
+
+       /* Check if signcert and pkey match. */
+       if (!X509_check_private_key(ctx->signer_cert, ctx->signer_key)) {
+               TSerr(TS_F_TS_RESP_SIGN, 
+                     TS_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
+                goto err;
+       }
+
+       /* Create a new PKCS7 signed object. */
+       if (!(p7 = PKCS7_new())) {
+               TSerr(TS_F_TS_RESP_SIGN, ERR_R_MALLOC_FAILURE);
+               goto err;
+       }
+       if (!PKCS7_set_type(p7, NID_pkcs7_signed)) goto err;
+
+       /* Force SignedData version to be 3 instead of the default 1. */
+       if (!ASN1_INTEGER_set(p7->d.sign->version, 3)) goto err;
+
+       /* Add signer certificate and optional certificate chain. */
+       if (TS_REQ_get_cert_req(ctx->request))
+               {
+               PKCS7_add_certificate(p7, ctx->signer_cert);
+               if (ctx->certs)
+                       {
+                       for(i = 0; i < sk_X509_num(ctx->certs); ++i) 
+                               {
+                               X509 *cert = sk_X509_value(ctx->certs, i);
+                               PKCS7_add_certificate(p7, cert);
+                               }
+                       }
+               }
+
+       /* Add a new signer info. */
+       if (!(si = PKCS7_add_signature(p7, ctx->signer_cert, 
+                                      ctx->signer_key, EVP_sha1())))
+               {
+               TSerr(TS_F_TS_RESP_SIGN, TS_R_PKCS7_ADD_SIGNATURE_ERROR);
+               goto err;
+               }
+
+       /* Add content type signed attribute to the signer info. */
+       oid = OBJ_nid2obj(NID_id_smime_ct_TSTInfo);
+       if (!PKCS7_add_signed_attribute(si, NID_pkcs9_contentType,
+                                       V_ASN1_OBJECT, oid))
+               {
+               TSerr(TS_F_TS_RESP_SIGN, TS_R_PKCS7_ADD_SIGNED_ATTR_ERROR);
+               goto err;
+               }
+
+       /* Create the ESS SigningCertificate attribute which contains 
+          the signer certificate id and optionally the certificate chain. */
+       certs = ctx->flags & TS_ESS_CERT_ID_CHAIN ? ctx->certs : NULL;
+       if (!(sc = ESS_SIGNING_CERT_new_init(ctx->signer_cert, certs)))
+               goto err;
+
+       /* Add SigningCertificate signed attribute to the signer info. */
+       if (!ESS_add_signing_cert(si, sc))
+               {
+               TSerr(TS_F_TS_RESP_SIGN, TS_R_ESS_ADD_SIGNING_CERT_ERROR);
+               goto err;
+               }       
+
+       /* Add a new empty NID_id_smime_ct_TSTInfo encapsulated content. */
+       if (!TS_TST_INFO_content_new(p7)) goto err;
+
+       /* Add the DER encoded tst_info to the PKCS7 structure. */
+       if (!(p7bio = PKCS7_dataInit(p7, NULL))) {
+               TSerr(TS_F_TS_RESP_SIGN, ERR_R_MALLOC_FAILURE);
+               goto err;
+       }
+
+       /* Convert tst_info to DER. */
+       if (!i2d_TS_TST_INFO_bio(p7bio, ctx->tst_info))
+               {
+               TSerr(TS_F_TS_RESP_SIGN, TS_R_TS_DATASIGN);
+               goto err;
+               }
+
+       /* Create the signature and add it to the signer info. */
+        if (!PKCS7_dataFinal(p7, p7bio))
+               {
+               TSerr(TS_F_TS_RESP_SIGN, TS_R_TS_DATASIGN);
+               goto err;
+               }
+
+       /* Set new PKCS7 and TST_INFO objects. */
+       TS_RESP_set_tst_info(ctx->response, p7, ctx->tst_info);
+       p7 = NULL;              /* Ownership is lost. */
+       ctx->tst_info = NULL;   /* Ownership is lost. */
+
+       ret = 1;
+ err:
+       if (!ret)
+               TS_RESP_CTX_set_status_info_cond(ctx, TS_STATUS_REJECTION,
+                                                "Error during signature "
+                                                "generation.");
+       BIO_free_all(p7bio);
+       ESS_SIGNING_CERT_free(sc);
+       PKCS7_free(p7);
+       return ret;
+       }
+
+static ESS_SIGNING_CERT *ESS_SIGNING_CERT_new_init(X509 *signcert, 
+                                                  STACK_OF(X509) *certs)
+       {
+       ESS_CERT_ID *cid;
+       ESS_SIGNING_CERT *sc = NULL;
+       int i;
+
+       /* Creating the ESS_CERT_ID stack. */
+       if (!(sc = ESS_SIGNING_CERT_new())) goto err;
+       if (!sc->cert_ids && !(sc->cert_ids = sk_ESS_CERT_ID_new_null()))
+               goto err;
+
+       /* Adding the signing certificate id. */
+       if (!(cid = ESS_CERT_ID_new_init(signcert, 0))
+           || !sk_ESS_CERT_ID_push(sc->cert_ids, cid))
+               goto err;
+       /* Adding the certificate chain ids. */
+       for (i = 0; i < sk_X509_num(certs); ++i)
+               {
+               X509 *cert = sk_X509_value(certs, i);
+               if (!(cid = ESS_CERT_ID_new_init(cert, 1))
+                   || !sk_ESS_CERT_ID_push(sc->cert_ids, cid))
+                       goto err;
+               }
+
+       return sc;
+err:
+       ESS_SIGNING_CERT_free(sc);
+       TSerr(TS_F_ESS_SIGNING_CERT_NEW_INIT, ERR_R_MALLOC_FAILURE);
+       return NULL;
+       }
+
+static ESS_CERT_ID *ESS_CERT_ID_new_init(X509 *cert, int issuer_needed)
+       {
+       ESS_CERT_ID *cid = NULL;
+       GENERAL_NAME *name = NULL;
+       
+       /* Recompute SHA1 hash of certificate if necessary (side effect). */
+       X509_check_purpose(cert, -1, 0);
+
+       if (!(cid = ESS_CERT_ID_new())) goto err;
+       if (!ASN1_OCTET_STRING_set(cid->hash, cert->sha1_hash,
+                                  sizeof(cert->sha1_hash)))
+               goto err;
+
+       /* Setting the issuer/serial if requested. */
+       if (issuer_needed)
+               {
+               /* Creating issuer/serial structure. */
+               if (!cid->issuer_serial
+                   && !(cid->issuer_serial = ESS_ISSUER_SERIAL_new()))
+                       goto err;
+               /* Creating general name from the certificate issuer. */
+               if (!(name = GENERAL_NAME_new())) goto err;
+               name->type = GEN_DIRNAME;
+               if (!(name->d.dirn = X509_NAME_dup(cert->cert_info->issuer))) 
+                       goto err;
+               if (!sk_GENERAL_NAME_push(cid->issuer_serial->issuer, name)) 
+                       goto err;
+               name = NULL;    /* Ownership is lost. */
+               /* Setting the serial number. */
+               ASN1_INTEGER_free(cid->issuer_serial->serial);
+               if (!(cid->issuer_serial->serial = 
+                     ASN1_INTEGER_dup(cert->cert_info->serialNumber)))
+                       goto err;
+               }
+
+       return cid;
+err:
+       GENERAL_NAME_free(name);
+       ESS_CERT_ID_free(cid);
+       TSerr(TS_F_ESS_CERT_ID_NEW_INIT, ERR_R_MALLOC_FAILURE);
+       return NULL;
+       }
+
+static int TS_TST_INFO_content_new(PKCS7 *p7)
+       {
+       PKCS7 *ret = NULL;
+       ASN1_OCTET_STRING *octet_string = NULL;
+
+       /* Create new encapsulated NID_id_smime_ct_TSTInfo content. */
+       if (!(ret = PKCS7_new())) goto err;
+       if (!(ret->d.other = ASN1_TYPE_new())) goto err;
+       ret->type = OBJ_nid2obj(NID_id_smime_ct_TSTInfo);
+       if (!(octet_string = ASN1_OCTET_STRING_new())) goto err;
+       ASN1_TYPE_set(ret->d.other, V_ASN1_OCTET_STRING, octet_string);
+       octet_string = NULL;
+
+       /* Add encapsulated content to signed PKCS7 structure. */
+       if (!PKCS7_set_content(p7, ret)) goto err;
+
+       return 1;
+ err:
+       ASN1_OCTET_STRING_free(octet_string);
+       PKCS7_free(ret);
+       return 0;
+       }
+
+static int ESS_add_signing_cert(PKCS7_SIGNER_INFO *si, ESS_SIGNING_CERT *sc)
+       {
+       ASN1_STRING *seq = NULL;
+       unsigned char *p, *pp = NULL;
+       int len;
+
+       len = i2d_ESS_SIGNING_CERT(sc, NULL);
+       if (!(pp = (unsigned char *) OPENSSL_malloc(len)))
+               {
+               TSerr(TS_F_ESS_ADD_SIGNING_CERT, ERR_R_MALLOC_FAILURE);
+               goto err;
+               }
+       p = pp;
+       i2d_ESS_SIGNING_CERT(sc, &p);
+       if (!(seq = ASN1_STRING_new()) || !ASN1_STRING_set(seq, pp, len))
+               {
+               TSerr(TS_F_ESS_ADD_SIGNING_CERT, ERR_R_MALLOC_FAILURE);
+               goto err;
+               }
+       OPENSSL_free(pp); pp = NULL;
+       return PKCS7_add_signed_attribute(si, 
+                                         NID_id_smime_aa_signingCertificate,
+                                         V_ASN1_SEQUENCE, seq);
+ err:
+       ASN1_STRING_free(seq);
+       OPENSSL_free(pp);
+
+       return 0;
+       }
+
+
+static ASN1_GENERALIZEDTIME *
+TS_RESP_set_genTime_with_precision(ASN1_GENERALIZEDTIME *asn1_time, 
+                                  long sec, long usec, unsigned precision)
+       {
+       time_t time_sec = (time_t) sec;
+       struct tm *tm = NULL;   
+       char genTime_str[17 + TS_MAX_CLOCK_PRECISION_DIGITS];
+       char *p = genTime_str;
+       char *p_end = genTime_str + sizeof(genTime_str);
+
+       if (precision > TS_MAX_CLOCK_PRECISION_DIGITS)
+               goto err;
+
+       
+       if (!(tm = gmtime(&time_sec)))
+               goto err;
+
+       /* 
+        * Put "genTime_str" in GeneralizedTime format.  We work around the 
+        * restrictions imposed by rfc3280 (i.e. "GeneralizedTime values MUST 
+        * NOT include fractional seconds") and OpenSSL related functions to 
+        * meet the rfc3161 requirement: "GeneralizedTime syntax can include 
+        * fraction-of-second details". 
+        */                   
+       p += BIO_snprintf(p, p_end - p,
+                         "%04d%02d%02d%02d%02d%02d",
+                         tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, 
+                         tm->tm_hour, tm->tm_min, tm->tm_sec);
+       if (precision > 0)
+       {
+               /* Add fraction of seconds (leave space for dot and null). */
+               BIO_snprintf(p, 2 + precision, ".%ld", usec);
+               /* We cannot use the snprintf return value, 
+                  because it might have been truncated. */
+               p += strlen(p);
+
+               /* To make things a bit harder, X.690 | ISO/IEC 8825-1 provides
+                  the following restrictions for a DER-encoding, which OpenSSL
+                  (specifically ASN1_GENERALIZEDTIME_check() function) doesn't 
+                  support:
+                  "The encoding MUST terminate with a "Z" (which means "Zulu" 
+                  time). The decimal point element, if present, MUST be the 
+                  point option ".". The fractional-seconds elements, 
+                  if present, MUST omit all trailing 0's; 
+                  if the elements correspond to 0, they MUST be wholly
+                  omitted, and the decimal point element also MUST be
+                  omitted." */
+               /* Remove trailing zeros. The dot guarantees the exit
+                  condition of this loop even if all the digits are zero. */
+               while (*--p == '0')
+                       /* empty */;
+               /* p points to either the dot or the last non-zero digit. */
+               if (*p != '.') ++p;
+               }
+       /* Add the trailing Z and the terminating null. */
+       *p++ = 'Z';
+       *p++ = '\0';
+
+       /* Now call OpenSSL to check and set our genTime value */
+       if (!asn1_time && !(asn1_time = M_ASN1_GENERALIZEDTIME_new()))
+               goto err;
+       if (!ASN1_GENERALIZEDTIME_set_string(asn1_time, genTime_str))
+               {
+               ASN1_GENERALIZEDTIME_free(asn1_time);
+               goto err;
+               }
+
+       return asn1_time;
+ err:
+       TSerr(TS_F_TS_RESP_SET_GENTIME_WITH_PRECISION, TS_R_COULD_NOT_SET_TIME);
+       return NULL;
+       }
diff --git a/deps/openssl/openssl/crypto/ts/ts_rsp_utils.c b/deps/openssl/openssl/crypto/ts/ts_rsp_utils.c
new file mode 100644 (file)
index 0000000..401c1fd
--- /dev/null
@@ -0,0 +1,409 @@
+/* crypto/ts/ts_resp_utils.c */
+/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
+ * project 2002.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include "cryptlib.h"
+#include <openssl/objects.h>
+#include <openssl/ts.h>
+#include <openssl/pkcs7.h>
+
+/* Function definitions. */
+
+int TS_RESP_set_status_info(TS_RESP *a, TS_STATUS_INFO *status_info)
+       {
+       TS_STATUS_INFO *new_status_info;
+
+       if (a->status_info == status_info)
+               return 1;
+       new_status_info = TS_STATUS_INFO_dup(status_info);
+       if (new_status_info == NULL)
+               {
+               TSerr(TS_F_TS_RESP_SET_STATUS_INFO, ERR_R_MALLOC_FAILURE);
+               return 0;
+               }
+       TS_STATUS_INFO_free(a->status_info);
+       a->status_info = new_status_info;
+
+       return 1;
+       }
+
+TS_STATUS_INFO *TS_RESP_get_status_info(TS_RESP *a)
+       {
+       return a->status_info;
+       }
+
+/* Caller loses ownership of PKCS7 and TS_TST_INFO objects. */
+void TS_RESP_set_tst_info(TS_RESP *a, PKCS7 *p7, TS_TST_INFO *tst_info)
+       {
+       /* Set new PKCS7 and TST_INFO objects. */
+       PKCS7_free(a->token);
+       a->token = p7;
+       TS_TST_INFO_free(a->tst_info);
+       a->tst_info = tst_info;
+       }
+
+PKCS7 *TS_RESP_get_token(TS_RESP *a)
+       {
+       return a->token;
+       }
+
+TS_TST_INFO *TS_RESP_get_tst_info(TS_RESP *a)
+       {
+       return a->tst_info;
+       }
+
+int TS_TST_INFO_set_version(TS_TST_INFO *a, long version)
+       {
+       return ASN1_INTEGER_set(a->version, version);
+       }
+
+long TS_TST_INFO_get_version(const TS_TST_INFO *a)
+       {
+       return ASN1_INTEGER_get(a->version);
+       }
+
+int TS_TST_INFO_set_policy_id(TS_TST_INFO *a, ASN1_OBJECT *policy)
+       {
+       ASN1_OBJECT *new_policy;
+
+       if (a->policy_id == policy)
+               return 1;
+       new_policy = OBJ_dup(policy);
+       if (new_policy == NULL)
+               {
+               TSerr(TS_F_TS_TST_INFO_SET_POLICY_ID, ERR_R_MALLOC_FAILURE);
+               return 0;
+               }
+       ASN1_OBJECT_free(a->policy_id);
+       a->policy_id = new_policy;
+       return 1;
+       }
+
+ASN1_OBJECT *TS_TST_INFO_get_policy_id(TS_TST_INFO *a)
+       {
+       return a->policy_id;
+       }
+
+int TS_TST_INFO_set_msg_imprint(TS_TST_INFO *a, TS_MSG_IMPRINT *msg_imprint)
+       {
+       TS_MSG_IMPRINT *new_msg_imprint;
+
+       if (a->msg_imprint == msg_imprint)
+               return 1;
+       new_msg_imprint = TS_MSG_IMPRINT_dup(msg_imprint);
+       if (new_msg_imprint == NULL)
+               {
+               TSerr(TS_F_TS_TST_INFO_SET_MSG_IMPRINT, ERR_R_MALLOC_FAILURE);
+               return 0;
+               }
+       TS_MSG_IMPRINT_free(a->msg_imprint);
+       a->msg_imprint = new_msg_imprint;
+       return 1;
+       }
+
+TS_MSG_IMPRINT *TS_TST_INFO_get_msg_imprint(TS_TST_INFO *a)
+       {
+       return a->msg_imprint;
+       }
+
+int TS_TST_INFO_set_serial(TS_TST_INFO *a, const ASN1_INTEGER *serial)
+       {
+       ASN1_INTEGER *new_serial;
+
+       if (a->serial == serial)
+               return 1;
+       new_serial = ASN1_INTEGER_dup(serial);
+       if (new_serial == NULL)
+               {
+               TSerr(TS_F_TS_TST_INFO_SET_SERIAL, ERR_R_MALLOC_FAILURE);
+               return 0;
+               }
+       ASN1_INTEGER_free(a->serial);
+       a->serial = new_serial;
+       return 1;
+       }
+
+const ASN1_INTEGER *TS_TST_INFO_get_serial(const TS_TST_INFO *a)
+       {
+       return a->serial;
+       }
+
+int TS_TST_INFO_set_time(TS_TST_INFO *a, const ASN1_GENERALIZEDTIME *gtime)
+       {
+       ASN1_GENERALIZEDTIME *new_time;
+
+       if (a->time == gtime)
+               return 1;
+       new_time = M_ASN1_GENERALIZEDTIME_dup(gtime);
+       if (new_time == NULL)
+               {
+               TSerr(TS_F_TS_TST_INFO_SET_TIME, ERR_R_MALLOC_FAILURE);
+               return 0;
+               }
+       ASN1_GENERALIZEDTIME_free(a->time);
+       a->time = new_time;
+       return 1;
+       }
+
+const ASN1_GENERALIZEDTIME *TS_TST_INFO_get_time(const TS_TST_INFO *a)
+       {
+       return a->time;
+       }
+
+int TS_TST_INFO_set_accuracy(TS_TST_INFO *a, TS_ACCURACY *accuracy)
+       {
+       TS_ACCURACY *new_accuracy;
+
+       if (a->accuracy == accuracy)
+               return 1;
+       new_accuracy = TS_ACCURACY_dup(accuracy);
+       if (new_accuracy == NULL)
+               {
+               TSerr(TS_F_TS_TST_INFO_SET_ACCURACY, ERR_R_MALLOC_FAILURE);
+               return 0;
+               }
+       TS_ACCURACY_free(a->accuracy);
+       a->accuracy = new_accuracy;
+       return 1;
+       }
+
+TS_ACCURACY *TS_TST_INFO_get_accuracy(TS_TST_INFO *a)
+       {
+       return a->accuracy;
+       }
+
+int TS_ACCURACY_set_seconds(TS_ACCURACY *a, const ASN1_INTEGER *seconds)
+       {
+       ASN1_INTEGER *new_seconds;
+
+       if (a->seconds == seconds)
+               return 1;
+       new_seconds = ASN1_INTEGER_dup(seconds);
+       if (new_seconds == NULL)
+               {
+               TSerr(TS_F_TS_ACCURACY_SET_SECONDS, ERR_R_MALLOC_FAILURE);
+               return 0;
+               }
+       ASN1_INTEGER_free(a->seconds);
+       a->seconds = new_seconds;
+       return 1;
+       }
+
+const ASN1_INTEGER *TS_ACCURACY_get_seconds(const TS_ACCURACY *a)
+       {
+       return a->seconds;
+       }
+
+int TS_ACCURACY_set_millis(TS_ACCURACY *a, const ASN1_INTEGER *millis)
+       {
+       ASN1_INTEGER *new_millis = NULL;
+
+       if (a->millis == millis)
+               return 1;
+       if (millis != NULL)
+               {
+               new_millis = ASN1_INTEGER_dup(millis);
+               if (new_millis == NULL)
+                       {
+                       TSerr(TS_F_TS_ACCURACY_SET_MILLIS, 
+                             ERR_R_MALLOC_FAILURE);
+                       return 0;
+                       }
+               }
+       ASN1_INTEGER_free(a->millis);
+       a->millis = new_millis;
+       return 1;
+       }
+
+const ASN1_INTEGER *TS_ACCURACY_get_millis(const TS_ACCURACY *a)
+       {
+       return a->millis;
+       }
+
+int TS_ACCURACY_set_micros(TS_ACCURACY *a, const ASN1_INTEGER *micros)
+       {
+       ASN1_INTEGER *new_micros = NULL;
+
+       if (a->micros == micros)
+               return 1;
+       if (micros != NULL)
+               {
+               new_micros = ASN1_INTEGER_dup(micros);
+               if (new_micros == NULL)
+                       {
+                       TSerr(TS_F_TS_ACCURACY_SET_MICROS, 
+                             ERR_R_MALLOC_FAILURE);
+                       return 0;
+                       }
+               }
+       ASN1_INTEGER_free(a->micros);
+       a->micros = new_micros;
+       return 1;
+       }
+
+const ASN1_INTEGER *TS_ACCURACY_get_micros(const TS_ACCURACY *a)
+       {
+       return a->micros;
+       }
+
+int TS_TST_INFO_set_ordering(TS_TST_INFO *a, int ordering)
+       {
+       a->ordering = ordering ? 0xFF : 0x00;
+       return 1;
+       }
+
+int TS_TST_INFO_get_ordering(const TS_TST_INFO *a)
+       {
+       return a->ordering ? 1 : 0;
+       }
+
+int TS_TST_INFO_set_nonce(TS_TST_INFO *a, const ASN1_INTEGER *nonce)
+       {
+       ASN1_INTEGER *new_nonce;
+
+       if (a->nonce == nonce)
+               return 1;
+       new_nonce = ASN1_INTEGER_dup(nonce);
+       if (new_nonce == NULL)
+               {
+               TSerr(TS_F_TS_TST_INFO_SET_NONCE, ERR_R_MALLOC_FAILURE);
+               return 0;
+               }
+       ASN1_INTEGER_free(a->nonce);
+       a->nonce = new_nonce;
+       return 1;
+       }
+
+const ASN1_INTEGER *TS_TST_INFO_get_nonce(const TS_TST_INFO *a)
+       {
+       return a->nonce;
+       }
+
+int TS_TST_INFO_set_tsa(TS_TST_INFO *a, GENERAL_NAME *tsa)
+       {
+       GENERAL_NAME *new_tsa;
+
+       if (a->tsa == tsa)
+               return 1;
+       new_tsa = GENERAL_NAME_dup(tsa);
+       if (new_tsa == NULL)
+               {
+               TSerr(TS_F_TS_TST_INFO_SET_TSA, ERR_R_MALLOC_FAILURE);
+               return 0;
+               }
+       GENERAL_NAME_free(a->tsa);
+       a->tsa = new_tsa;
+       return 1;
+       }
+
+GENERAL_NAME *TS_TST_INFO_get_tsa(TS_TST_INFO *a)
+       {
+       return a->tsa;
+       }
+
+STACK_OF(X509_EXTENSION) *TS_TST_INFO_get_exts(TS_TST_INFO *a)
+       {
+       return a->extensions;
+       }
+
+void TS_TST_INFO_ext_free(TS_TST_INFO *a)
+       {
+       if (!a) return;
+       sk_X509_EXTENSION_pop_free(a->extensions, X509_EXTENSION_free);
+       a->extensions = NULL;
+       }
+
+int TS_TST_INFO_get_ext_count(TS_TST_INFO *a)
+       {
+       return X509v3_get_ext_count(a->extensions);
+       }
+
+int TS_TST_INFO_get_ext_by_NID(TS_TST_INFO *a, int nid, int lastpos)
+       {
+       return X509v3_get_ext_by_NID(a->extensions, nid, lastpos);
+       }
+
+int TS_TST_INFO_get_ext_by_OBJ(TS_TST_INFO *a, ASN1_OBJECT *obj, int lastpos)
+       {
+       return X509v3_get_ext_by_OBJ(a->extensions, obj, lastpos);
+       }
+
+int TS_TST_INFO_get_ext_by_critical(TS_TST_INFO *a, int crit, int lastpos)
+       {
+       return X509v3_get_ext_by_critical(a->extensions, crit, lastpos);
+       }
+
+X509_EXTENSION *TS_TST_INFO_get_ext(TS_TST_INFO *a, int loc)
+       {
+       return X509v3_get_ext(a->extensions,loc);
+       }
+
+X509_EXTENSION *TS_TST_INFO_delete_ext(TS_TST_INFO *a, int loc)
+       {
+       return X509v3_delete_ext(a->extensions,loc);
+       }
+
+int TS_TST_INFO_add_ext(TS_TST_INFO *a, X509_EXTENSION *ex, int loc)
+       {
+       return X509v3_add_ext(&a->extensions,ex,loc) != NULL;
+       }
+
+void *TS_TST_INFO_get_ext_d2i(TS_TST_INFO *a, int nid, int *crit, int *idx)
+       {
+       return X509V3_get_d2i(a->extensions, nid, crit, idx);
+       }
diff --git a/deps/openssl/openssl/crypto/ts/ts_rsp_verify.c b/deps/openssl/openssl/crypto/ts/ts_rsp_verify.c
new file mode 100644 (file)
index 0000000..e1f3b53
--- /dev/null
@@ -0,0 +1,725 @@
+/* crypto/ts/ts_resp_verify.c */
+/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
+ * project 2002.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include "cryptlib.h"
+#include <openssl/objects.h>
+#include <openssl/ts.h>
+#include <openssl/pkcs7.h>
+
+/* Private function declarations. */
+
+static int TS_verify_cert(X509_STORE *store, STACK_OF(X509) *untrusted,
+                         X509 *signer, STACK_OF(X509) **chain);
+static int TS_check_signing_certs(PKCS7_SIGNER_INFO *si, STACK_OF(X509) *chain);
+static ESS_SIGNING_CERT *ESS_get_signing_cert(PKCS7_SIGNER_INFO *si);
+static int TS_find_cert(STACK_OF(ESS_CERT_ID) *cert_ids, X509 *cert);
+static int TS_issuer_serial_cmp(ESS_ISSUER_SERIAL *is, X509_CINF *cinfo);
+static int int_TS_RESP_verify_token(TS_VERIFY_CTX *ctx, 
+                                PKCS7 *token, TS_TST_INFO *tst_info);
+static int TS_check_status_info(TS_RESP *response);
+static char *TS_get_status_text(STACK_OF(ASN1_UTF8STRING) *text);
+static int TS_check_policy(ASN1_OBJECT *req_oid, TS_TST_INFO *tst_info);
+static int TS_compute_imprint(BIO *data, TS_TST_INFO *tst_info,
+                             X509_ALGOR **md_alg, 
+                             unsigned char **imprint, unsigned *imprint_len);
+static int TS_check_imprints(X509_ALGOR *algor_a, 
+                            unsigned char *imprint_a, unsigned len_a,
+                            TS_TST_INFO *tst_info);
+static int TS_check_nonces(const ASN1_INTEGER *a, TS_TST_INFO *tst_info);
+static int TS_check_signer_name(GENERAL_NAME *tsa_name, X509 *signer);
+static int TS_find_name(STACK_OF(GENERAL_NAME) *gen_names, GENERAL_NAME *name);
+
+/*
+ * Local mapping between response codes and descriptions.
+ * Don't forget to change TS_STATUS_BUF_SIZE when modifying 
+ * the elements of this array.
+ */
+static const char *TS_status_text[] =
+       { "granted",
+         "grantedWithMods",
+         "rejection",
+         "waiting",
+         "revocationWarning",
+         "revocationNotification" };
+
+#define TS_STATUS_TEXT_SIZE    (sizeof(TS_status_text)/sizeof(*TS_status_text))
+
+/*
+ * This must be greater or equal to the sum of the strings in TS_status_text
+ * plus the number of its elements.
+ */
+#define TS_STATUS_BUF_SIZE     256
+
+static struct
+       {
+       int code;
+       const char *text;
+       } TS_failure_info[] =
+               { { TS_INFO_BAD_ALG, "badAlg" },
+                 { TS_INFO_BAD_REQUEST, "badRequest" },
+                 { TS_INFO_BAD_DATA_FORMAT, "badDataFormat" },
+                 { TS_INFO_TIME_NOT_AVAILABLE, "timeNotAvailable" },
+                 { TS_INFO_UNACCEPTED_POLICY, "unacceptedPolicy" },
+                 { TS_INFO_UNACCEPTED_EXTENSION, "unacceptedExtension" },
+                 { TS_INFO_ADD_INFO_NOT_AVAILABLE, "addInfoNotAvailable" },
+                 { TS_INFO_SYSTEM_FAILURE, "systemFailure" } };
+
+#define TS_FAILURE_INFO_SIZE   (sizeof(TS_failure_info) / \
+                               sizeof(*TS_failure_info))
+
+/* Functions for verifying a signed TS_TST_INFO structure. */
+
+/*
+ * This function carries out the following tasks:
+ *     - Checks if there is one and only one signer.
+ *     - Search for the signing certificate in 'certs' and in the response.
+ *     - Check the extended key usage and key usage fields of the signer
+ *     certificate (done by the path validation).
+ *     - Build and validate the certificate path.
+ *     - Check if the certificate path meets the requirements of the
+ *     SigningCertificate ESS signed attribute.
+ *     - Verify the signature value.
+ *     - Returns the signer certificate in 'signer', if 'signer' is not NULL.
+ */
+int TS_RESP_verify_signature(PKCS7 *token, STACK_OF(X509) *certs,
+                            X509_STORE *store, X509 **signer_out)
+       {
+       STACK_OF(PKCS7_SIGNER_INFO) *sinfos = NULL;
+       PKCS7_SIGNER_INFO *si;
+       STACK_OF(X509) *signers = NULL;
+       X509    *signer;
+       STACK_OF(X509) *chain = NULL;
+       char    buf[4096];
+       int     i, j = 0, ret = 0;
+       BIO     *p7bio = NULL;
+
+       /* Some sanity checks first. */
+       if (!token)
+               {
+               TSerr(TS_F_TS_RESP_VERIFY_SIGNATURE, TS_R_INVALID_NULL_POINTER);
+               goto err;
+               }
+
+       /* Check for the correct content type */
+       if(!PKCS7_type_is_signed(token))
+               {
+               TSerr(TS_F_TS_RESP_VERIFY_SIGNATURE, TS_R_WRONG_CONTENT_TYPE);
+               goto err;
+               }
+
+       /* Check if there is one and only one signer. */
+       sinfos = PKCS7_get_signer_info(token);
+       if (!sinfos || sk_PKCS7_SIGNER_INFO_num(sinfos) != 1)
+               {
+               TSerr(TS_F_TS_RESP_VERIFY_SIGNATURE,
+                     TS_R_THERE_MUST_BE_ONE_SIGNER);
+               goto err;
+               }
+       si = sk_PKCS7_SIGNER_INFO_value(sinfos, 0);
+
+       /* Check for no content: no data to verify signature. */
+       if (PKCS7_get_detached(token))
+               {
+               TSerr(TS_F_TS_RESP_VERIFY_SIGNATURE, TS_R_NO_CONTENT);
+               goto err;
+               }
+       
+       /* Get hold of the signer certificate, search only internal
+          certificates if it was requested. */
+       signers = PKCS7_get0_signers(token, certs, 0);
+       if (!signers || sk_X509_num(signers) != 1) goto err;
+       signer = sk_X509_value(signers, 0);
+
+       /* Now verify the certificate. */
+       if (!TS_verify_cert(store, certs, signer, &chain)) goto err;
+
+       /* Check if the signer certificate is consistent with the
+          ESS extension. */
+       if (!TS_check_signing_certs(si, chain)) goto err;
+
+       /* Creating the message digest. */
+       p7bio = PKCS7_dataInit(token, NULL);
+
+       /* We now have to 'read' from p7bio to calculate digests etc. */
+       while ((i = BIO_read(p7bio,buf,sizeof(buf))) > 0);
+
+       /* Verifying the signature. */
+       j = PKCS7_signatureVerify(p7bio, token, si, signer);
+       if (j <= 0)
+               {
+               TSerr(TS_F_TS_RESP_VERIFY_SIGNATURE, TS_R_SIGNATURE_FAILURE);
+               goto err;
+               }
+
+       /* Return the signer certificate if needed. */
+       if (signer_out)
+               {
+               *signer_out = signer;
+               CRYPTO_add(&signer->references, 1, CRYPTO_LOCK_X509);
+               }
+
+       ret = 1;
+
+ err:
+       BIO_free_all(p7bio);
+       sk_X509_pop_free(chain, X509_free);
+       sk_X509_free(signers);
+
+       return ret;
+       }
+
+/*
+ * The certificate chain is returned in chain. Caller is responsible for
+ * freeing the vector.
+ */
+static int TS_verify_cert(X509_STORE *store, STACK_OF(X509) *untrusted,
+                         X509 *signer, STACK_OF(X509) **chain)
+       {
+       X509_STORE_CTX  cert_ctx;
+       int i;
+       int ret = 1;
+
+       /* chain is an out argument. */
+       *chain = NULL;
+       X509_STORE_CTX_init(&cert_ctx, store, signer, untrusted);
+       X509_STORE_CTX_set_purpose(&cert_ctx, X509_PURPOSE_TIMESTAMP_SIGN);
+       i = X509_verify_cert(&cert_ctx);
+       if (i <= 0)
+               {
+               int j = X509_STORE_CTX_get_error(&cert_ctx);
+               TSerr(TS_F_TS_VERIFY_CERT, TS_R_CERTIFICATE_VERIFY_ERROR);
+               ERR_add_error_data(2, "Verify error:",
+                                  X509_verify_cert_error_string(j));
+               ret = 0;
+               }
+       else
+               {
+               /* Get a copy of the certificate chain. */
+               *chain = X509_STORE_CTX_get1_chain(&cert_ctx);
+               }
+
+       X509_STORE_CTX_cleanup(&cert_ctx);
+
+       return ret;
+       }
+
+static int TS_check_signing_certs(PKCS7_SIGNER_INFO *si, STACK_OF(X509) *chain)
+       {
+       ESS_SIGNING_CERT *ss = ESS_get_signing_cert(si);
+       STACK_OF(ESS_CERT_ID) *cert_ids = NULL;
+       X509 *cert;
+       int i = 0;
+       int ret = 0;
+
+       if (!ss) goto err;
+       cert_ids = ss->cert_ids;
+       /* The signer certificate must be the first in cert_ids. */
+       cert = sk_X509_value(chain, 0);
+       if (TS_find_cert(cert_ids, cert) != 0) goto err;
+       
+       /* Check the other certificates of the chain if there are more
+          than one certificate ids in cert_ids. */
+       if (sk_ESS_CERT_ID_num(cert_ids) > 1)
+               {
+               /* All the certificates of the chain must be in cert_ids. */
+               for (i = 1; i < sk_X509_num(chain); ++i)
+                       {
+                       cert = sk_X509_value(chain, i);
+                       if (TS_find_cert(cert_ids, cert) < 0) goto err;
+                       }
+               }
+       ret = 1;
+ err:
+       if (!ret)
+               TSerr(TS_F_TS_CHECK_SIGNING_CERTS, 
+                     TS_R_ESS_SIGNING_CERTIFICATE_ERROR);
+       ESS_SIGNING_CERT_free(ss);
+       return ret;
+       }
+
+static ESS_SIGNING_CERT *ESS_get_signing_cert(PKCS7_SIGNER_INFO *si)
+       {
+       ASN1_TYPE *attr;
+       const unsigned char *p;
+       attr = PKCS7_get_signed_attribute(si, 
+                                         NID_id_smime_aa_signingCertificate);
+       if (!attr) return NULL;
+       p = attr->value.sequence->data;
+       return d2i_ESS_SIGNING_CERT(NULL, &p, attr->value.sequence->length);
+       }
+
+/* Returns < 0 if certificate is not found, certificate index otherwise. */
+static int TS_find_cert(STACK_OF(ESS_CERT_ID) *cert_ids, X509 *cert)
+       {
+       int i;
+
+       if (!cert_ids || !cert) return -1;
+
+       /* Recompute SHA1 hash of certificate if necessary (side effect). */
+       X509_check_purpose(cert, -1, 0);
+
+       /* Look for cert in the cert_ids vector. */
+       for (i = 0; i < sk_ESS_CERT_ID_num(cert_ids); ++i)
+               {
+               ESS_CERT_ID *cid = sk_ESS_CERT_ID_value(cert_ids, i);
+
+               /* Check the SHA-1 hash first. */
+               if (cid->hash->length == sizeof(cert->sha1_hash)
+                   && !memcmp(cid->hash->data, cert->sha1_hash,
+                              sizeof(cert->sha1_hash)))
+                       {
+                       /* Check the issuer/serial as well if specified. */
+                       ESS_ISSUER_SERIAL *is = cid->issuer_serial;
+                       if (!is || !TS_issuer_serial_cmp(is, cert->cert_info))
+                               return i;
+                       }
+               }
+       
+       return -1;
+       }
+
+static int TS_issuer_serial_cmp(ESS_ISSUER_SERIAL *is, X509_CINF *cinfo)
+       {
+       GENERAL_NAME *issuer;
+
+       if (!is || !cinfo || sk_GENERAL_NAME_num(is->issuer) != 1) return -1;
+
+       /* Check the issuer first. It must be a directory name. */
+       issuer = sk_GENERAL_NAME_value(is->issuer, 0);
+       if (issuer->type != GEN_DIRNAME 
+           || X509_NAME_cmp(issuer->d.dirn, cinfo->issuer))
+               return -1;
+
+       /* Check the serial number, too. */
+       if (ASN1_INTEGER_cmp(is->serial, cinfo->serialNumber))
+               return -1;
+
+       return 0;
+       }
+
+/*
+ * Verifies whether 'response' contains a valid response with regards 
+ * to the settings of the context:
+ *     - Gives an error message if the TS_TST_INFO is not present.
+ *     - Calls _TS_RESP_verify_token to verify the token content.
+ */
+int TS_RESP_verify_response(TS_VERIFY_CTX *ctx, TS_RESP *response)
+       {
+       PKCS7 *token = TS_RESP_get_token(response);
+       TS_TST_INFO *tst_info = TS_RESP_get_tst_info(response);
+       int ret = 0;
+
+       /* Check if we have a successful TS_TST_INFO object in place. */
+       if (!TS_check_status_info(response)) goto err;
+
+       /* Check the contents of the time stamp token. */
+       if (!int_TS_RESP_verify_token(ctx, token, tst_info))
+               goto err;
+
+       ret = 1;
+ err:
+       return ret;
+       }
+
+/*
+ * Tries to extract a TS_TST_INFO structure from the PKCS7 token and
+ * calls the internal int_TS_RESP_verify_token function for verifying it.
+ */
+int TS_RESP_verify_token(TS_VERIFY_CTX *ctx, PKCS7 *token)
+       {
+       TS_TST_INFO *tst_info = PKCS7_to_TS_TST_INFO(token);
+       int ret = 0;
+       if (tst_info)
+               {
+               ret = int_TS_RESP_verify_token(ctx, token, tst_info);
+               TS_TST_INFO_free(tst_info);
+               }
+       return ret;
+       }
+
+/*
+ * Verifies whether the 'token' contains a valid time stamp token 
+ * with regards to the settings of the context. Only those checks are
+ * carried out that are specified in the context:
+ *     - Verifies the signature of the TS_TST_INFO.
+ *     - Checks the version number of the response.
+ *     - Check if the requested and returned policies math.
+ *     - Check if the message imprints are the same.
+ *     - Check if the nonces are the same.
+ *     - Check if the TSA name matches the signer.
+ *     - Check if the TSA name is the expected TSA.
+ */
+static int int_TS_RESP_verify_token(TS_VERIFY_CTX *ctx, 
+                                PKCS7 *token, TS_TST_INFO *tst_info)
+       {
+       X509 *signer = NULL;
+       GENERAL_NAME *tsa_name = TS_TST_INFO_get_tsa(tst_info);
+       X509_ALGOR *md_alg = NULL;
+       unsigned char *imprint = NULL;
+       unsigned imprint_len = 0;
+       int ret = 0;
+
+       /* Verify the signature. */
+       if ((ctx->flags & TS_VFY_SIGNATURE)
+           && !TS_RESP_verify_signature(token, ctx->certs, ctx->store,
+                                        &signer))
+               goto err;
+       
+       /* Check version number of response. */
+       if ((ctx->flags & TS_VFY_VERSION)
+           && TS_TST_INFO_get_version(tst_info) != 1)
+               {
+               TSerr(TS_F_INT_TS_RESP_VERIFY_TOKEN, TS_R_UNSUPPORTED_VERSION);
+               goto err;
+               }
+
+       /* Check policies. */
+       if ((ctx->flags & TS_VFY_POLICY)
+           && !TS_check_policy(ctx->policy, tst_info))
+               goto err;
+       
+       /* Check message imprints. */
+       if ((ctx->flags & TS_VFY_IMPRINT)
+           && !TS_check_imprints(ctx->md_alg, ctx->imprint, ctx->imprint_len,
+                                 tst_info)) 
+               goto err;
+
+       /* Compute and check message imprints. */
+       if ((ctx->flags & TS_VFY_DATA)
+           && (!TS_compute_imprint(ctx->data, tst_info,
+                                   &md_alg, &imprint, &imprint_len)
+           || !TS_check_imprints(md_alg, imprint, imprint_len, tst_info)))
+               goto err;
+
+       /* Check nonces. */
+       if ((ctx->flags & TS_VFY_NONCE)
+           && !TS_check_nonces(ctx->nonce, tst_info))
+               goto err;
+
+       /* Check whether TSA name and signer certificate match. */
+       if ((ctx->flags & TS_VFY_SIGNER)
+           && tsa_name && !TS_check_signer_name(tsa_name, signer))
+               {
+               TSerr(TS_F_INT_TS_RESP_VERIFY_TOKEN, TS_R_TSA_NAME_MISMATCH);
+               goto err;
+               }
+
+       /* Check whether the TSA is the expected one. */
+       if ((ctx->flags & TS_VFY_TSA_NAME)
+           && !TS_check_signer_name(ctx->tsa_name, signer))
+               {
+               TSerr(TS_F_INT_TS_RESP_VERIFY_TOKEN, TS_R_TSA_UNTRUSTED);
+               goto err;
+               }
+
+       ret = 1;
+ err:
+       X509_free(signer);
+       X509_ALGOR_free(md_alg);
+       OPENSSL_free(imprint);
+       return ret;
+       }
+
+static int TS_check_status_info(TS_RESP *response)
+       {
+       TS_STATUS_INFO *info = TS_RESP_get_status_info(response);
+       long status = ASN1_INTEGER_get(info->status);
+       const char *status_text = NULL;
+       char *embedded_status_text = NULL;
+       char failure_text[TS_STATUS_BUF_SIZE] = "";
+
+       /* Check if everything went fine. */
+       if (status == 0 || status == 1) return 1;
+
+       /* There was an error, get the description in status_text. */
+       if (0 <= status && status < (long)TS_STATUS_TEXT_SIZE)
+               status_text = TS_status_text[status];
+       else
+               status_text = "unknown code";
+
+       /* Set the embedded_status_text to the returned description. */
+       if (sk_ASN1_UTF8STRING_num(info->text) > 0
+           && !(embedded_status_text = TS_get_status_text(info->text)))
+               return 0;
+       
+       /* Filling in failure_text with the failure information. */
+       if (info->failure_info)
+               {
+               int i;
+               int first = 1;
+               for (i = 0; i < (int)TS_FAILURE_INFO_SIZE; ++i)
+                       {
+                       if (ASN1_BIT_STRING_get_bit(info->failure_info,
+                                                   TS_failure_info[i].code))
+                               {
+                               if (!first)
+                                       strcpy(failure_text, ",");
+                               else
+                                       first = 0;
+                               strcat(failure_text, TS_failure_info[i].text);
+                               }
+                       }
+               }
+       if (failure_text[0] == '\0')
+               strcpy(failure_text, "unspecified");
+
+       /* Making up the error string. */
+       TSerr(TS_F_TS_CHECK_STATUS_INFO, TS_R_NO_TIME_STAMP_TOKEN);
+       ERR_add_error_data(6,
+                          "status code: ", status_text,
+                          ", status text: ", embedded_status_text ? 
+                          embedded_status_text : "unspecified",
+                          ", failure codes: ", failure_text);
+       OPENSSL_free(embedded_status_text);
+
+       return 0;
+       }
+
+static char *TS_get_status_text(STACK_OF(ASN1_UTF8STRING) *text)
+       {
+       int i;
+       unsigned int length = 0;
+       char *result = NULL;
+       char *p;
+
+       /* Determine length first. */
+       for (i = 0; i < sk_ASN1_UTF8STRING_num(text); ++i)
+               {
+               ASN1_UTF8STRING *current = sk_ASN1_UTF8STRING_value(text, i);
+               length += ASN1_STRING_length(current);
+               length += 1;    /* separator character */
+               }
+       /* Allocate memory (closing '\0' included). */
+       if (!(result = OPENSSL_malloc(length)))
+               {
+               TSerr(TS_F_TS_GET_STATUS_TEXT, ERR_R_MALLOC_FAILURE);
+               return NULL;
+               }
+       /* Concatenate the descriptions. */
+       for (i = 0, p = result; i < sk_ASN1_UTF8STRING_num(text); ++i)
+               {
+               ASN1_UTF8STRING *current = sk_ASN1_UTF8STRING_value(text, i);
+               length = ASN1_STRING_length(current);
+               if (i > 0) *p++ = '/';
+               strncpy(p, (const char *)ASN1_STRING_data(current), length);
+               p += length;
+               }
+       /* We do have space for this, too. */
+       *p = '\0';
+       
+       return result;
+       }
+
+static int TS_check_policy(ASN1_OBJECT *req_oid, TS_TST_INFO *tst_info)
+       {
+       ASN1_OBJECT *resp_oid = TS_TST_INFO_get_policy_id(tst_info);
+
+       if (OBJ_cmp(req_oid, resp_oid) != 0)
+               {
+               TSerr(TS_F_TS_CHECK_POLICY, TS_R_POLICY_MISMATCH);
+               return 0;
+               }
+
+       return 1;
+       }
+
+static int TS_compute_imprint(BIO *data, TS_TST_INFO *tst_info,
+                             X509_ALGOR **md_alg, 
+                             unsigned char **imprint, unsigned *imprint_len)
+       {
+       TS_MSG_IMPRINT *msg_imprint = TS_TST_INFO_get_msg_imprint(tst_info);
+       X509_ALGOR *md_alg_resp = TS_MSG_IMPRINT_get_algo(msg_imprint);
+       const EVP_MD *md;
+       EVP_MD_CTX md_ctx;
+       unsigned char buffer[4096];
+       int length;
+
+       *md_alg = NULL;
+       *imprint = NULL;
+
+       /* Return the MD algorithm of the response. */
+       if (!(*md_alg = X509_ALGOR_dup(md_alg_resp))) goto err;
+
+       /* Getting the MD object. */
+       if (!(md = EVP_get_digestbyobj((*md_alg)->algorithm)))
+               {
+               TSerr(TS_F_TS_COMPUTE_IMPRINT, TS_R_UNSUPPORTED_MD_ALGORITHM);
+               goto err;
+               }
+
+       /* Compute message digest. */
+       length = EVP_MD_size(md);
+       if (length < 0)
+           goto err;
+       *imprint_len = length;
+       if (!(*imprint = OPENSSL_malloc(*imprint_len))) 
+               {
+               TSerr(TS_F_TS_COMPUTE_IMPRINT, ERR_R_MALLOC_FAILURE);
+               goto err;
+               }
+
+       EVP_DigestInit(&md_ctx, md);
+       while ((length = BIO_read(data, buffer, sizeof(buffer))) > 0)
+               {
+               EVP_DigestUpdate(&md_ctx, buffer, length);
+               }
+       EVP_DigestFinal(&md_ctx, *imprint, NULL);
+
+       return 1;
+ err:
+       X509_ALGOR_free(*md_alg);
+       OPENSSL_free(*imprint);
+       *imprint_len = 0;
+       return 0;
+       }
+
+static int TS_check_imprints(X509_ALGOR *algor_a, 
+                            unsigned char *imprint_a, unsigned len_a,
+                            TS_TST_INFO *tst_info)
+       {
+       TS_MSG_IMPRINT *b = TS_TST_INFO_get_msg_imprint(tst_info);
+       X509_ALGOR *algor_b = TS_MSG_IMPRINT_get_algo(b);
+       int ret = 0;
+
+       /* algor_a is optional. */
+       if (algor_a)
+               {
+               /* Compare algorithm OIDs. */
+               if (OBJ_cmp(algor_a->algorithm, algor_b->algorithm)) goto err;
+
+               /* The parameter must be NULL in both. */
+               if ((algor_a->parameter 
+                    && ASN1_TYPE_get(algor_a->parameter) != V_ASN1_NULL)
+                   || (algor_b->parameter
+                       && ASN1_TYPE_get(algor_b->parameter) != V_ASN1_NULL))
+                       goto err;
+               }
+
+       /* Compare octet strings. */
+       ret = len_a == (unsigned) ASN1_STRING_length(b->hashed_msg) &&
+               memcmp(imprint_a, ASN1_STRING_data(b->hashed_msg), len_a) == 0;
+ err:
+       if (!ret)
+               TSerr(TS_F_TS_CHECK_IMPRINTS, TS_R_MESSAGE_IMPRINT_MISMATCH);
+       return ret;
+       }
+
+static int TS_check_nonces(const ASN1_INTEGER *a, TS_TST_INFO *tst_info)
+       {
+       const ASN1_INTEGER *b = TS_TST_INFO_get_nonce(tst_info);
+
+       /* Error if nonce is missing. */
+       if (!b)
+               {
+               TSerr(TS_F_TS_CHECK_NONCES, TS_R_NONCE_NOT_RETURNED);
+               return 0;
+               }
+
+       /* No error if a nonce is returned without being requested. */
+       if (ASN1_INTEGER_cmp(a, b) != 0)
+               {
+               TSerr(TS_F_TS_CHECK_NONCES, TS_R_NONCE_MISMATCH);
+               return 0;
+               }
+
+       return 1;
+       }
+
+/* Check if the specified TSA name matches either the subject
+   or one of the subject alternative names of the TSA certificate. */
+static int TS_check_signer_name(GENERAL_NAME *tsa_name, X509 *signer)
+       {
+       STACK_OF(GENERAL_NAME) *gen_names = NULL;
+       int idx = -1;
+       int found = 0;
+
+       /* Check the subject name first. */
+       if (tsa_name->type == GEN_DIRNAME 
+           && X509_name_cmp(tsa_name->d.dirn, signer->cert_info->subject) == 0)
+               return 1;
+
+       /* Check all the alternative names. */
+       gen_names = X509_get_ext_d2i(signer, NID_subject_alt_name,
+                                    NULL, &idx);
+       while (gen_names != NULL
+              && !(found = TS_find_name(gen_names, tsa_name) >= 0))
+               {
+               /* Get the next subject alternative name,
+                  although there should be no more than one. */
+               GENERAL_NAMES_free(gen_names);
+               gen_names = X509_get_ext_d2i(signer, NID_subject_alt_name,
+                                            NULL, &idx);
+               }
+       if (gen_names) GENERAL_NAMES_free(gen_names);
+       
+       return found;
+       }
+
+/* Returns 1 if name is in gen_names, 0 otherwise. */
+static int TS_find_name(STACK_OF(GENERAL_NAME) *gen_names, GENERAL_NAME *name)
+       {
+       int i, found;
+       for (i = 0, found = 0; !found && i < sk_GENERAL_NAME_num(gen_names);
+            ++i)
+               {
+               GENERAL_NAME *current = sk_GENERAL_NAME_value(gen_names, i);
+               found = GENERAL_NAME_cmp(current, name) == 0;
+               }
+       return found ? i - 1 : -1;
+       }
diff --git a/deps/openssl/openssl/crypto/ts/ts_verify_ctx.c b/deps/openssl/openssl/crypto/ts/ts_verify_ctx.c
new file mode 100644 (file)
index 0000000..609b773
--- /dev/null
@@ -0,0 +1,159 @@
+/* crypto/ts/ts_verify_ctx.c */
+/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
+ * project 2003.
+ */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include "cryptlib.h"
+#include <openssl/objects.h>
+#include <openssl/ts.h>
+
+TS_VERIFY_CTX *TS_VERIFY_CTX_new(void)
+       {
+       TS_VERIFY_CTX *ctx = 
+               (TS_VERIFY_CTX *) OPENSSL_malloc(sizeof(TS_VERIFY_CTX));
+       if (ctx)
+               memset(ctx, 0, sizeof(TS_VERIFY_CTX));
+       else
+               TSerr(TS_F_TS_VERIFY_CTX_NEW, ERR_R_MALLOC_FAILURE);
+       return ctx;
+       }
+
+void TS_VERIFY_CTX_init(TS_VERIFY_CTX *ctx)
+       {
+       OPENSSL_assert(ctx != NULL);
+       memset(ctx, 0, sizeof(TS_VERIFY_CTX));
+       }
+
+void TS_VERIFY_CTX_free(TS_VERIFY_CTX *ctx)
+       {
+       if (!ctx) return;
+
+       TS_VERIFY_CTX_cleanup(ctx);
+       OPENSSL_free(ctx);
+       }
+
+void TS_VERIFY_CTX_cleanup(TS_VERIFY_CTX *ctx)
+       {
+       if (!ctx) return;
+
+       X509_STORE_free(ctx->store);
+       sk_X509_pop_free(ctx->certs, X509_free);
+
+       ASN1_OBJECT_free(ctx->policy);
+
+       X509_ALGOR_free(ctx->md_alg);
+       OPENSSL_free(ctx->imprint);
+       
+       BIO_free_all(ctx->data);
+
+       ASN1_INTEGER_free(ctx->nonce);
+
+       GENERAL_NAME_free(ctx->tsa_name);
+
+       TS_VERIFY_CTX_init(ctx);
+       }
+
+TS_VERIFY_CTX *TS_REQ_to_TS_VERIFY_CTX(TS_REQ *req, TS_VERIFY_CTX *ctx)
+       {
+       TS_VERIFY_CTX *ret = ctx;
+       ASN1_OBJECT *policy;
+       TS_MSG_IMPRINT *imprint;
+       X509_ALGOR *md_alg;
+       ASN1_OCTET_STRING *msg;
+       const ASN1_INTEGER *nonce;
+
+       OPENSSL_assert(req != NULL);
+       if (ret)
+               TS_VERIFY_CTX_cleanup(ret);
+       else
+               if (!(ret = TS_VERIFY_CTX_new())) return NULL;
+
+       /* Setting flags. */
+       ret->flags = TS_VFY_ALL_IMPRINT & ~(TS_VFY_TSA_NAME | TS_VFY_SIGNATURE);
+
+       /* Setting policy. */
+       if ((policy = TS_REQ_get_policy_id(req)) != NULL)
+               {
+               if (!(ret->policy = OBJ_dup(policy))) goto err;
+               }
+       else
+               ret->flags &= ~TS_VFY_POLICY;
+
+       /* Setting md_alg, imprint and imprint_len. */
+       imprint = TS_REQ_get_msg_imprint(req);
+       md_alg = TS_MSG_IMPRINT_get_algo(imprint);
+       if (!(ret->md_alg = X509_ALGOR_dup(md_alg))) goto err;
+       msg = TS_MSG_IMPRINT_get_msg(imprint);
+       ret->imprint_len = ASN1_STRING_length(msg);
+       if (!(ret->imprint = OPENSSL_malloc(ret->imprint_len))) goto err;
+       memcpy(ret->imprint, ASN1_STRING_data(msg), ret->imprint_len);
+
+       /* Setting nonce. */
+       if ((nonce = TS_REQ_get_nonce(req)) != NULL)
+               {
+               if (!(ret->nonce = ASN1_INTEGER_dup(nonce))) goto err;
+               }
+       else
+               ret->flags &= ~TS_VFY_NONCE;
+
+       return ret;
+ err:
+       if (ctx)
+               TS_VERIFY_CTX_cleanup(ctx);
+       else
+               TS_VERIFY_CTX_free(ret);
+       return NULL;
+       }
index 87e57b4..e6f3033 100644 (file)
@@ -33,7 +33,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
index 3ed5f72..6f2ce3b 100644 (file)
@@ -77,22 +77,23 @@ TXT_DB *TXT_DB_read(BIO *in, int num)
        int i,add,n;
        int size=BUFSIZE;
        int offset=0;
-       char *p,**pp,*f;
+       char *p,*f;
+       OPENSSL_STRING *pp;
        BUF_MEM *buf=NULL;
 
        if ((buf=BUF_MEM_new()) == NULL) goto err;
        if (!BUF_MEM_grow(buf,size)) goto err;
 
-       if ((ret=(TXT_DB *)OPENSSL_malloc(sizeof(TXT_DB))) == NULL)
+       if ((ret=OPENSSL_malloc(sizeof(TXT_DB))) == NULL)
                goto err;
        ret->num_fields=num;
        ret->index=NULL;
        ret->qual=NULL;
-       if ((ret->data=sk_new_null()) == NULL)
+       if ((ret->data=sk_OPENSSL_PSTRING_new_null()) == NULL)
                goto err;
-       if ((ret->index=(LHASH **)OPENSSL_malloc(sizeof(LHASH *)*num)) == NULL)
+       if ((ret->index=OPENSSL_malloc(sizeof(*ret->index)*num)) == NULL)
                goto err;
-       if ((ret->qual=(int (**)(char **))OPENSSL_malloc(sizeof(int (**)(char **))*num)) == NULL)
+       if ((ret->qual=OPENSSL_malloc(sizeof(*(ret->qual))*num)) == NULL)
                goto err;
        for (i=0; i<num; i++)
                {
@@ -122,7 +123,7 @@ TXT_DB *TXT_DB_read(BIO *in, int num)
                else
                        {
                        buf->data[offset-1]='\0'; /* blat the '\n' */
-                       if (!(p=(char *)OPENSSL_malloc(add+offset))) goto err;
+                       if (!(p=OPENSSL_malloc(add+offset))) goto err;
                        offset=0;
                        }
                pp=(char **)p;
@@ -155,16 +156,16 @@ TXT_DB *TXT_DB_read(BIO *in, int num)
                *(p++)='\0';
                if ((n != num) || (*f != '\0'))
                        {
-#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)  /* temporaty fix :-( */
+#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)  /* temporary fix :-( */
                        fprintf(stderr,"wrong number of fields on line %ld (looking for field %d, got %d, '%s' left)\n",ln,num,n,f);
 #endif
                        er=2;
                        goto err;
                        }
                pp[n]=p;
-               if (!sk_push(ret->data,(char *)pp))
+               if (!sk_OPENSSL_PSTRING_push(ret->data,pp))
                        {
-#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)  /* temporaty fix :-( */
+#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)  /* temporary fix :-( */
                        fprintf(stderr,"failure in sk_push\n");
 #endif
                        er=2;
@@ -181,7 +182,7 @@ err:
 #endif
                if (ret != NULL)
                        {
-                       if (ret->data != NULL) sk_free(ret->data);
+                       if (ret->data != NULL) sk_OPENSSL_PSTRING_free(ret->data);
                        if (ret->index != NULL) OPENSSL_free(ret->index);
                        if (ret->qual != NULL) OPENSSL_free(ret->qual);
                        if (ret != NULL) OPENSSL_free(ret);
@@ -192,10 +193,10 @@ err:
                return(ret);
        }
 
-char **TXT_DB_get_by_index(TXT_DB *db, int idx, char **value)
+OPENSSL_STRING *TXT_DB_get_by_index(TXT_DB *db, int idx, OPENSSL_STRING *value)
        {
-       char **ret;
-       LHASH *lh;
+       OPENSSL_STRING *ret;
+       LHASH_OF(OPENSSL_STRING) *lh;
 
        if (idx >= db->num_fields)
                {
@@ -208,16 +209,16 @@ char **TXT_DB_get_by_index(TXT_DB *db, int idx, char **value)
                db->error=DB_ERROR_NO_INDEX;
                return(NULL);
                }
-       ret=(char **)lh_retrieve(lh,value);
+       ret=lh_OPENSSL_STRING_retrieve(lh,value);
        db->error=DB_ERROR_OK;
        return(ret);
        }
 
-int TXT_DB_create_index(TXT_DB *db, int field, int (*qual)(char **),
-               LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp)
+int TXT_DB_create_index(TXT_DB *db, int field, int (*qual)(OPENSSL_STRING *),
+                       LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp)
        {
-       LHASH *idx;
-       char **r;
+       LHASH_OF(OPENSSL_STRING) *idx;
+       OPENSSL_STRING *r;
        int i,n;
 
        if (field >= db->num_fields)
@@ -225,26 +226,27 @@ int TXT_DB_create_index(TXT_DB *db, int field, int (*qual)(char **),
                db->error=DB_ERROR_INDEX_OUT_OF_RANGE;
                return(0);
                }
-       if ((idx=lh_new(hash,cmp)) == NULL)
+       /* FIXME: we lose type checking at this point */
+       if ((idx=(LHASH_OF(OPENSSL_STRING) *)lh_new(hash,cmp)) == NULL)
                {
                db->error=DB_ERROR_MALLOC;
                return(0);
                }
-       n=sk_num(db->data);
+       n=sk_OPENSSL_PSTRING_num(db->data);
        for (i=0; i<n; i++)
                {
-               r=(char **)sk_value(db->data,i);
+               r=sk_OPENSSL_PSTRING_value(db->data,i);
                if ((qual != NULL) && (qual(r) == 0)) continue;
-               if ((r=lh_insert(idx,r)) != NULL)
+               if ((r=lh_OPENSSL_STRING_insert(idx,r)) != NULL)
                        {
                        db->error=DB_ERROR_INDEX_CLASH;
-                       db->arg1=sk_find(db->data,(char *)r);
+                       db->arg1=sk_OPENSSL_PSTRING_find(db->data,r);
                        db->arg2=i;
-                       lh_free(idx);
+                       lh_OPENSSL_STRING_free(idx);
                        return(0);
                        }
                }
-       if (db->index[field] != NULL) lh_free(db->index[field]);
+       if (db->index[field] != NULL) lh_OPENSSL_STRING_free(db->index[field]);
        db->index[field]=idx;
        db->qual[field]=qual;
        return(1);
@@ -259,11 +261,11 @@ long TXT_DB_write(BIO *out, TXT_DB *db)
 
        if ((buf=BUF_MEM_new()) == NULL)
                goto err;
-       n=sk_num(db->data);
+       n=sk_OPENSSL_PSTRING_num(db->data);
        nn=db->num_fields;
        for (i=0; i<n; i++)
                {
-               pp=(char **)sk_value(db->data,i);
+               pp=sk_OPENSSL_PSTRING_value(db->data,i);
 
                l=0;
                for (j=0; j<nn; j++)
@@ -298,10 +300,10 @@ err:
        return(ret);
        }
 
-int TXT_DB_insert(TXT_DB *db, char **row)
+int TXT_DB_insert(TXT_DB *db, OPENSSL_STRING *row)
        {
        int i;
-       char **r;
+       OPENSSL_STRING *r;
 
        for (i=0; i<db->num_fields; i++)
                {
@@ -309,7 +311,7 @@ int TXT_DB_insert(TXT_DB *db, char **row)
                        {
                        if ((db->qual[i] != NULL) &&
                                (db->qual[i](row) == 0)) continue;
-                       r=(char **)lh_retrieve(db->index[i],row);
+                       r=lh_OPENSSL_STRING_retrieve(db->index[i],row);
                        if (r != NULL)
                                {
                                db->error=DB_ERROR_INDEX_CLASH;
@@ -320,7 +322,7 @@ int TXT_DB_insert(TXT_DB *db, char **row)
                        }
                }
        /* We have passed the index checks, now just append and insert */
-       if (!sk_push(db->data,(char *)row))
+       if (!sk_OPENSSL_PSTRING_push(db->data,row))
                {
                db->error=DB_ERROR_MALLOC;
                goto err;
@@ -332,7 +334,7 @@ int TXT_DB_insert(TXT_DB *db, char **row)
                        {
                        if ((db->qual[i] != NULL) &&
                                (db->qual[i](row) == 0)) continue;
-                       lh_insert(db->index[i],row);
+                       (void)lh_OPENSSL_STRING_insert(db->index[i],row);
                        }
                }
        return(1);
@@ -351,18 +353,18 @@ void TXT_DB_free(TXT_DB *db)
        if (db->index != NULL)
                {
                for (i=db->num_fields-1; i>=0; i--)
-                       if (db->index[i] != NULL) lh_free(db->index[i]);
+                       if (db->index[i] != NULL) lh_OPENSSL_STRING_free(db->index[i]);
                OPENSSL_free(db->index);
                }
        if (db->qual != NULL)
                OPENSSL_free(db->qual);
        if (db->data != NULL)
                {
-               for (i=sk_num(db->data)-1; i>=0; i--)
+               for (i=sk_OPENSSL_PSTRING_num(db->data)-1; i>=0; i--)
                        {
                        /* check if any 'fields' have been allocated
                         * from outside of the initial block */
-                       p=(char **)sk_value(db->data,i);
+                       p=sk_OPENSSL_PSTRING_value(db->data,i);
                        max=p[db->num_fields]; /* last address */
                        if (max == NULL) /* new row */
                                {
@@ -378,9 +380,9 @@ void TXT_DB_free(TXT_DB *db)
                                                OPENSSL_free(p[n]);
                                        }
                                }
-                       OPENSSL_free(sk_value(db->data,i));
+                       OPENSSL_free(sk_OPENSSL_PSTRING_value(db->data,i));
                        }
-               sk_free(db->data);
+               sk_OPENSSL_PSTRING_free(db->data);
                }
        OPENSSL_free(db);
        }
index 307e1ba..6abe435 100644 (file)
 extern "C" {
 #endif
 
+typedef OPENSSL_STRING *OPENSSL_PSTRING;
+DECLARE_SPECIAL_STACK_OF(OPENSSL_PSTRING, OPENSSL_STRING)
+
 typedef struct txt_db_st
        {
        int num_fields;
-       STACK /* char ** */ *data;
-       LHASH **index;
-       int (**qual)(char **);
+       STACK_OF(OPENSSL_PSTRING) *data;
+       LHASH_OF(OPENSSL_STRING) **index;
+       int (**qual)(OPENSSL_STRING *);
        long error;
        long arg1;
        long arg2;
-       char **arg_row;
+       OPENSSL_STRING *arg_row;
        } TXT_DB;
 
 #ifndef OPENSSL_NO_BIO
@@ -96,11 +99,11 @@ long TXT_DB_write(BIO *out, TXT_DB *db);
 TXT_DB *TXT_DB_read(char *in, int num);
 long TXT_DB_write(char *out, TXT_DB *db);
 #endif
-int TXT_DB_create_index(TXT_DB *db,int field,int (*qual)(char **),
-               LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp);
+int TXT_DB_create_index(TXT_DB *db,int field,int (*qual)(OPENSSL_STRING *),
+                       LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp);
 void TXT_DB_free(TXT_DB *db);
-char **TXT_DB_get_by_index(TXT_DB *db, int idx, char **value);
-int TXT_DB_insert(TXT_DB *db,char **value);
+OPENSSL_STRING *TXT_DB_get_by_index(TXT_DB *db, int idx, OPENSSL_STRING *value);
+int TXT_DB_insert(TXT_DB *db, OPENSSL_STRING *value);
 
 #ifdef  __cplusplus
 }
index 4755e20..a685659 100644 (file)
@@ -37,7 +37,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
index 0182964..2b1cfa2 100644 (file)
@@ -287,8 +287,8 @@ UI_METHOD *UI_OpenSSL(void);
 /* The UI_STRING type is the data structure that contains all the needed info
    about a string or a prompt, including test data for a verification prompt.
 */
-DECLARE_STACK_OF(UI_STRING)
 typedef struct ui_string_st UI_STRING;
+DECLARE_STACK_OF(UI_STRING)
 
 /* The different types of strings that are currently supported.
    This is only needed by method authors. */
@@ -310,11 +310,13 @@ int UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis
 int UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui));
 int UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis));
 int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui));
+int UI_method_set_prompt_constructor(UI_METHOD *method, char *(*prompt_constructor)(UI* ui, const char* object_desc, const char* object_name));
 int (*UI_method_get_opener(UI_METHOD *method))(UI*);
 int (*UI_method_get_writer(UI_METHOD *method))(UI*,UI_STRING*);
 int (*UI_method_get_flusher(UI_METHOD *method))(UI*);
 int (*UI_method_get_reader(UI_METHOD *method))(UI*,UI_STRING*);
 int (*UI_method_get_closer(UI_METHOD *method))(UI*);
+char* (*UI_method_get_prompt_constructor(UI_METHOD *method))(UI*, const char*, const char*);
 
 /* The following functions are helpers for method writers to access relevant
    data from a UI_STRING. */
index 786bd0d..a6b9629 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/ui/ui_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
index ac01008..a8abc27 100644 (file)
@@ -693,6 +693,17 @@ int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui))
                return -1;
        }
 
+int UI_method_set_prompt_constructor(UI_METHOD *method, char *(*prompt_constructor)(UI* ui, const char* object_desc, const char* object_name))
+       {
+       if (method)
+               {
+               method->ui_construct_prompt = prompt_constructor;
+               return 0;
+               }
+       else
+               return -1;
+       }
+
 int (*UI_method_get_opener(UI_METHOD *method))(UI*)
        {
        if (method)
@@ -733,6 +744,14 @@ int (*UI_method_get_closer(UI_METHOD *method))(UI*)
                return NULL;
        }
 
+char* (*UI_method_get_prompt_constructor(UI_METHOD *method))(UI*, const char*, const char*)
+       {
+       if (method)
+               return method->ui_construct_prompt;
+       else
+               return NULL;
+       }
+
 enum UI_string_types UI_get_string_type(UI_STRING *uis)
        {
        if (!uis)
index 40d2031..b05cbf3 100644 (file)
  * sigaction and fileno included. -pedantic would be more appropriate for
  * the intended purposes, but we can't prevent users from adding -ansi.
  */
+#ifndef _POSIX_C_SOURCE
+#define _POSIX_C_SOURCE 2
+#endif
 #include <signal.h>
 #include <stdio.h>
 #include <string.h>
  * TERMIO, TERMIOS, VMS, MSDOS and SGTTY
  */
 
-#if defined(__sun) && !defined(TERMIOS)
-# define TERMIOS
-# undef  TERMIO
-# undef  SGTTY
-#endif
-
 #if defined(__sgi) && !defined(TERMIOS)
 # define TERMIOS
 # undef  TERMIO
 # undef  SGTTY
 #endif
 
-#if defined(linux) && !defined(TERMIO)
+#if defined(linux) && !defined(TERMIO) && !defined(__ANDROID__)
 # undef  TERMIOS
 # define TERMIO
 # undef  SGTTY
@@ -481,7 +478,7 @@ static int open_console(UI *ui)
        CRYPTO_w_lock(CRYPTO_LOCK_UI);
        is_a_tty = 1;
 
-#if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_NETWARE)
+#if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_NETWARE) || defined(OPENSSL_SYS_BEOS)
        tty_in=stdin;
        tty_out=stderr;
 #else
diff --git a/deps/openssl/openssl/crypto/vms_rms.h b/deps/openssl/openssl/crypto/vms_rms.h
new file mode 100644 (file)
index 0000000..00a00d9
--- /dev/null
@@ -0,0 +1,51 @@
+
+#ifdef NAML$C_MAXRSS
+
+# define CC_RMS_NAMX cc$rms_naml
+# define FAB_NAMX fab$l_naml
+# define FAB_OR_NAML( fab, naml) naml
+# define FAB_OR_NAML_DNA naml$l_long_defname
+# define FAB_OR_NAML_DNS naml$l_long_defname_size
+# define FAB_OR_NAML_FNA naml$l_long_filename
+# define FAB_OR_NAML_FNS naml$l_long_filename_size
+# define NAMX_ESA naml$l_long_expand
+# define NAMX_ESL naml$l_long_expand_size
+# define NAMX_ESS naml$l_long_expand_alloc
+# define NAMX_NOP naml$b_nop
+# define SET_NAMX_NO_SHORT_UPCASE( nam) nam.naml$v_no_short_upcase = 1
+
+# if __INITIAL_POINTER_SIZE == 64
+#  define NAMX_DNA_FNA_SET(fab) fab.fab$l_dna = (__char_ptr32) -1; \
+   fab.fab$l_fna = (__char_ptr32) -1;
+# else /* __INITIAL_POINTER_SIZE == 64 */
+#  define NAMX_DNA_FNA_SET(fab) fab.fab$l_dna = (char *) -1; \
+   fab.fab$l_fna = (char *) -1;
+# endif /* __INITIAL_POINTER_SIZE == 64 [else] */
+
+# define NAMX_MAXRSS NAML$C_MAXRSS
+# define NAMX_STRUCT NAML
+
+#else /* def NAML$C_MAXRSS */
+
+# define CC_RMS_NAMX cc$rms_nam
+# define FAB_NAMX fab$l_nam
+# define FAB_OR_NAML( fab, naml) fab
+# define FAB_OR_NAML_DNA fab$l_dna
+# define FAB_OR_NAML_DNS fab$b_dns
+# define FAB_OR_NAML_FNA fab$l_fna
+# define FAB_OR_NAML_FNS fab$b_fns
+# define NAMX_ESA nam$l_esa
+# define NAMX_ESL nam$b_esl
+# define NAMX_ESS nam$b_ess
+# define NAMX_NOP nam$b_nop
+# define NAMX_DNA_FNA_SET(fab)
+# define NAMX_MAXRSS NAM$C_MAXRSS
+# define NAMX_STRUCT NAM
+# ifdef NAM$M_NO_SHORT_UPCASE
+#  define SET_NAMX_NO_SHORT_UPCASE( nam) naml.naml$v_no_short_upcase = 1
+# else /* def NAM$M_NO_SHORT_UPCASE */
+#  define SET_NAMX_NO_SHORT_UPCASE( nam)
+# endif /* def NAM$M_NO_SHORT_UPCASE [else] */
+
+#endif /* def NAML$C_MAXRSS [else] */
+
diff --git a/deps/openssl/openssl/crypto/whrlpool/Makefile b/deps/openssl/openssl/crypto/whrlpool/Makefile
new file mode 100644 (file)
index 0000000..566b996
--- /dev/null
@@ -0,0 +1,93 @@
+#
+# crypto/whrlpool/Makefile
+#
+
+DIR=   whrlpool
+TOP=   ../..
+CC=    cc
+CPP=   $(CC) -E
+INCLUDES=
+CFLAG=-g
+MAKEFILE=      Makefile
+AR=            ar r
+
+WP_ASM_OBJ=wp_block.o
+
+CFLAGS= $(INCLUDES) $(CFLAG)
+ASFLAGS= $(INCLUDES) $(ASFLAG)
+AFLAGS= $(ASFLAGS)
+
+GENERAL=Makefile
+TEST=wp_test.c
+APPS=
+
+LIB=$(TOP)/libcrypto.a
+LIBSRC=wp_dgst.c wp_block.c
+LIBOBJ=wp_dgst.o $(WP_ASM_OBJ)
+
+SRC= $(LIBSRC)
+
+EXHEADER= whrlpool.h
+HEADER= wp_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
+
+wp-mmx.s:      asm/wp-mmx.pl ../perlasm/x86asm.pl
+       $(PERL) asm/wp-mmx.pl $(PERLASM_SCHEME) $(CFLAGS) $(PROCESSOR) > $@
+
+wp-x86_64.s: asm/wp-x86_64.pl
+       $(PERL) asm/wp-x86_64.pl $(PERLASM_SCHEME) > $@
+
+$(LIBOBJ): $(LIBSRC)
+
+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
+
+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 *.s *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
+
+# DO NOT DELETE THIS LINE -- make depend depends on it.
+
+wp_block.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
+wp_block.o: ../../include/openssl/whrlpool.h wp_block.c wp_locl.h
+wp_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
+wp_dgst.o: ../../include/openssl/whrlpool.h wp_dgst.c wp_locl.h
diff --git a/deps/openssl/openssl/crypto/whrlpool/asm/wp-mmx.pl b/deps/openssl/openssl/crypto/whrlpool/asm/wp-mmx.pl
new file mode 100644 (file)
index 0000000..32cf163
--- /dev/null
@@ -0,0 +1,493 @@
+#!/usr/bin/env perl
+#
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. Rights for redistribution and usage in source and binary
+# forms are granted according to the OpenSSL license.
+# ====================================================================
+#
+# whirlpool_block_mmx implementation.
+#
+*SCALE=\(2); # 2 or 8, that is the question:-) Value of 8 results
+# in 16KB large table, which is tough on L1 cache, but eliminates
+# unaligned references to it. Value of 2 results in 4KB table, but
+# 7/8 of references to it are unaligned. AMD cores seem to be
+# allergic to the latter, while Intel ones - to former [see the
+# table]. I stick to value of 2 for two reasons: 1. smaller table
+# minimizes cache trashing and thus mitigates the hazard of side-
+# channel leakage similar to AES cache-timing one; 2. performance
+# gap among different Âµ-archs is smaller.
+#
+# Performance table lists rounded amounts of CPU cycles spent by
+# whirlpool_block_mmx routine on single 64 byte input block, i.e.
+# smaller is better and asymptotic throughput can be estimated by
+# multiplying 64 by CPU clock frequency and dividing by relevant
+# value from the given table:
+#
+#              $SCALE=2/8      icc8    gcc3    
+# Intel P4     3200/4600       4600(*) 6400
+# Intel PIII   2900/3000       4900    5400
+# AMD K[78]    2500/1800       9900    8200(**)
+#
+# (*)  I've sketched even non-MMX assembler, but for the record
+#      I've failed to beat the Intel compiler on P4, without using
+#      MMX that is...
+# (**) ... on AMD on the other hand non-MMX assembler was observed
+#      to perform significantly better, but I figured this MMX
+#      implementation is even faster anyway, so why bother? As for
+#      pre-MMX AMD core[s], the improvement coefficient is more
+#      than likely to vary anyway and I don't know how. But the
+#      least I know is that gcc-generated code compiled with
+#      -DL_ENDIAN and -DOPENSSL_SMALL_FOOTPRINT [see C module for
+#      details] and optimized for Pentium was observed to perform
+#      *better* on Pentium 100 than unrolled non-MMX assembler
+#      loop... So we just say that I don't know if maintaining
+#      non-MMX implementation would actually pay off, but till
+#      opposite is proved "unlikely" is assumed.
+
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+push(@INC,"${dir}","${dir}../../perlasm");
+require "x86asm.pl";
+
+&asm_init($ARGV[0],"wp-mmx.pl");
+
+sub L()  { &data_byte(@_); }
+sub LL()
+{      if      ($SCALE==2)     { &data_byte(@_); &data_byte(@_); }
+       elsif   ($SCALE==8)     { for ($i=0;$i<8;$i++) {
+                                       &data_byte(@_);
+                                       unshift(@_,pop(@_));
+                                 }
+                               }
+       else                    { die "unvalid SCALE value"; }
+}
+
+sub scale()
+{      if      ($SCALE==2)     { &lea(@_[0],&DWP(0,@_[1],@_[1])); }
+       elsif   ($SCALE==8)     { &lea(@_[0],&DWP(0,"",@_[1],8));  }
+       else                    { die "unvalid SCALE value";       }
+}
+
+sub row()
+{      if      ($SCALE==2)     { ((8-shift)&7); }
+       elsif   ($SCALE==8)     { (8*shift);     }
+       else                    { die "unvalid SCALE value"; }
+}
+
+$tbl="ebp";
+@mm=("mm0","mm1","mm2","mm3","mm4","mm5","mm6","mm7");
+
+&function_begin_B("whirlpool_block_mmx");
+       &push   ("ebp");
+       &push   ("ebx");
+       &push   ("esi");
+       &push   ("edi");
+
+       &mov    ("esi",&wparam(0));             # hash value
+       &mov    ("edi",&wparam(1));             # input data stream
+       &mov    ("ebp",&wparam(2));             # number of chunks in input
+
+       &mov    ("eax","esp");                  # copy stack pointer
+       &sub    ("esp",128+20);                 # allocate frame
+       &and    ("esp",-64);                    # align for cache-line
+
+       &lea    ("ebx",&DWP(128,"esp"));
+       &mov    (&DWP(0,"ebx"),"esi");          # save parameter block
+       &mov    (&DWP(4,"ebx"),"edi");
+       &mov    (&DWP(8,"ebx"),"ebp");
+       &mov    (&DWP(16,"ebx"),"eax");         # saved stack pointer
+
+       &call   (&label("pic_point"));
+&set_label("pic_point");
+       &blindpop($tbl);
+       &lea    ($tbl,&DWP(&label("table")."-".&label("pic_point"),$tbl));
+
+       &xor    ("ecx","ecx");
+       &xor    ("edx","edx");
+
+       for($i=0;$i<8;$i++) { &movq(@mm[$i],&QWP($i*8,"esi")); }    # L=H
+&set_label("outerloop");
+       for($i=0;$i<8;$i++) { &movq(&QWP($i*8,"esp"),@mm[$i]); }    # K=L
+       for($i=0;$i<8;$i++) { &pxor(@mm[$i],&QWP($i*8,"edi")); }    # L^=inp
+       for($i=0;$i<8;$i++) { &movq(&QWP(64+$i*8,"esp"),@mm[$i]); } # S=L
+
+       &xor    ("esi","esi");
+       &mov    (&DWP(12,"ebx"),"esi");         # zero round counter
+
+&set_label("round",16);
+       &movq   (@mm[0],&QWP(2048*$SCALE,$tbl,"esi",8));        # rc[r]
+       &mov    ("eax",&DWP(0,"esp"));
+       &mov    ("ebx",&DWP(4,"esp"));
+for($i=0;$i<8;$i++) {
+    my $func = ($i==0)? movq : pxor;
+       &movb   (&LB("ecx"),&LB("eax"));
+       &movb   (&LB("edx"),&HB("eax"));
+       &scale  ("esi","ecx");
+       &scale  ("edi","edx");
+       &shr    ("eax",16);
+       &pxor   (@mm[0],&QWP(&row(0),$tbl,"esi",8));
+       &$func  (@mm[1],&QWP(&row(1),$tbl,"edi",8));
+       &movb   (&LB("ecx"),&LB("eax"));
+       &movb   (&LB("edx"),&HB("eax"));
+       &mov    ("eax",&DWP(($i+1)*8,"esp"));
+       &scale  ("esi","ecx");
+       &scale  ("edi","edx");
+       &$func  (@mm[2],&QWP(&row(2),$tbl,"esi",8));
+       &$func  (@mm[3],&QWP(&row(3),$tbl,"edi",8));
+       &movb   (&LB("ecx"),&LB("ebx"));
+       &movb   (&LB("edx"),&HB("ebx"));
+       &scale  ("esi","ecx");
+       &scale  ("edi","edx");
+       &shr    ("ebx",16);
+       &$func  (@mm[4],&QWP(&row(4),$tbl,"esi",8));
+       &$func  (@mm[5],&QWP(&row(5),$tbl,"edi",8));
+       &movb   (&LB("ecx"),&LB("ebx"));
+       &movb   (&LB("edx"),&HB("ebx"));
+       &mov    ("ebx",&DWP(($i+1)*8+4,"esp"));
+       &scale  ("esi","ecx");
+       &scale  ("edi","edx");
+       &$func  (@mm[6],&QWP(&row(6),$tbl,"esi",8));
+       &$func  (@mm[7],&QWP(&row(7),$tbl,"edi",8));
+    push(@mm,shift(@mm));
+}
+
+       for($i=0;$i<8;$i++) { &movq(&QWP($i*8,"esp"),@mm[$i]); }    # K=L
+
+for($i=0;$i<8;$i++) {
+       &movb   (&LB("ecx"),&LB("eax"));
+       &movb   (&LB("edx"),&HB("eax"));
+       &scale  ("esi","ecx");
+       &scale  ("edi","edx");
+       &shr    ("eax",16);
+       &pxor   (@mm[0],&QWP(&row(0),$tbl,"esi",8));
+       &pxor   (@mm[1],&QWP(&row(1),$tbl,"edi",8));
+       &movb   (&LB("ecx"),&LB("eax"));
+       &movb   (&LB("edx"),&HB("eax"));
+       &mov    ("eax",&DWP(64+($i+1)*8,"esp"))         if ($i<7);
+       &scale  ("esi","ecx");
+       &scale  ("edi","edx");
+       &pxor   (@mm[2],&QWP(&row(2),$tbl,"esi",8));
+       &pxor   (@mm[3],&QWP(&row(3),$tbl,"edi",8));
+       &movb   (&LB("ecx"),&LB("ebx"));
+       &movb   (&LB("edx"),&HB("ebx"));
+       &scale  ("esi","ecx");
+       &scale  ("edi","edx");
+       &shr    ("ebx",16);
+       &pxor   (@mm[4],&QWP(&row(4),$tbl,"esi",8));
+       &pxor   (@mm[5],&QWP(&row(5),$tbl,"edi",8));
+       &movb   (&LB("ecx"),&LB("ebx"));
+       &movb   (&LB("edx"),&HB("ebx"));
+       &mov    ("ebx",&DWP(64+($i+1)*8+4,"esp"))       if ($i<7);
+       &scale  ("esi","ecx");
+       &scale  ("edi","edx");
+       &pxor   (@mm[6],&QWP(&row(6),$tbl,"esi",8));
+       &pxor   (@mm[7],&QWP(&row(7),$tbl,"edi",8));
+    push(@mm,shift(@mm));
+}
+       &lea    ("ebx",&DWP(128,"esp"));
+       &mov    ("esi",&DWP(12,"ebx"));         # pull round counter
+       &add    ("esi",1);
+       &cmp    ("esi",10);
+       &je     (&label("roundsdone"));
+
+       &mov    (&DWP(12,"ebx"),"esi");         # update round counter
+       for($i=0;$i<8;$i++) { &movq(&QWP(64+$i*8,"esp"),@mm[$i]); } # S=L
+       &jmp    (&label("round"));
+
+&set_label("roundsdone",16);
+       &mov    ("esi",&DWP(0,"ebx"));          # reload argument block
+       &mov    ("edi",&DWP(4,"ebx"));
+       &mov    ("eax",&DWP(8,"ebx"));
+
+       for($i=0;$i<8;$i++) { &pxor(@mm[$i],&QWP($i*8,"edi")); }    # L^=inp
+       for($i=0;$i<8;$i++) { &pxor(@mm[$i],&QWP($i*8,"esi")); }    # L^=H
+       for($i=0;$i<8;$i++) { &movq(&QWP($i*8,"esi"),@mm[$i]); }    # H=L
+
+       &lea    ("edi",&DWP(64,"edi"));         # inp+=64
+       &sub    ("eax",1);                      # num--
+       &jz     (&label("alldone"));
+       &mov    (&DWP(4,"ebx"),"edi");          # update argument block
+       &mov    (&DWP(8,"ebx"),"eax");
+       &jmp    (&label("outerloop"));
+
+&set_label("alldone");
+       &emms   ();
+       &mov    ("esp",&DWP(16,"ebx"));         # restore saved stack pointer
+       &pop    ("edi");
+       &pop    ("esi");
+       &pop    ("ebx");
+       &pop    ("ebp");
+       &ret    ();
+
+&align(64);
+&set_label("table");
+       &LL(0x18,0x18,0x60,0x18,0xc0,0x78,0x30,0xd8);
+       &LL(0x23,0x23,0x8c,0x23,0x05,0xaf,0x46,0x26);
+       &LL(0xc6,0xc6,0x3f,0xc6,0x7e,0xf9,0x91,0xb8);
+       &LL(0xe8,0xe8,0x87,0xe8,0x13,0x6f,0xcd,0xfb);
+       &LL(0x87,0x87,0x26,0x87,0x4c,0xa1,0x13,0xcb);
+       &LL(0xb8,0xb8,0xda,0xb8,0xa9,0x62,0x6d,0x11);
+       &LL(0x01,0x01,0x04,0x01,0x08,0x05,0x02,0x09);
+       &LL(0x4f,0x4f,0x21,0x4f,0x42,0x6e,0x9e,0x0d);
+       &LL(0x36,0x36,0xd8,0x36,0xad,0xee,0x6c,0x9b);
+       &LL(0xa6,0xa6,0xa2,0xa6,0x59,0x04,0x51,0xff);
+       &LL(0xd2,0xd2,0x6f,0xd2,0xde,0xbd,0xb9,0x0c);
+       &LL(0xf5,0xf5,0xf3,0xf5,0xfb,0x06,0xf7,0x0e);
+       &LL(0x79,0x79,0xf9,0x79,0xef,0x80,0xf2,0x96);
+       &LL(0x6f,0x6f,0xa1,0x6f,0x5f,0xce,0xde,0x30);
+       &LL(0x91,0x91,0x7e,0x91,0xfc,0xef,0x3f,0x6d);
+       &LL(0x52,0x52,0x55,0x52,0xaa,0x07,0xa4,0xf8);
+       &LL(0x60,0x60,0x9d,0x60,0x27,0xfd,0xc0,0x47);
+       &LL(0xbc,0xbc,0xca,0xbc,0x89,0x76,0x65,0x35);
+       &LL(0x9b,0x9b,0x56,0x9b,0xac,0xcd,0x2b,0x37);
+       &LL(0x8e,0x8e,0x02,0x8e,0x04,0x8c,0x01,0x8a);
+       &LL(0xa3,0xa3,0xb6,0xa3,0x71,0x15,0x5b,0xd2);
+       &LL(0x0c,0x0c,0x30,0x0c,0x60,0x3c,0x18,0x6c);
+       &LL(0x7b,0x7b,0xf1,0x7b,0xff,0x8a,0xf6,0x84);
+       &LL(0x35,0x35,0xd4,0x35,0xb5,0xe1,0x6a,0x80);
+       &LL(0x1d,0x1d,0x74,0x1d,0xe8,0x69,0x3a,0xf5);
+       &LL(0xe0,0xe0,0xa7,0xe0,0x53,0x47,0xdd,0xb3);
+       &LL(0xd7,0xd7,0x7b,0xd7,0xf6,0xac,0xb3,0x21);
+       &LL(0xc2,0xc2,0x2f,0xc2,0x5e,0xed,0x99,0x9c);
+       &LL(0x2e,0x2e,0xb8,0x2e,0x6d,0x96,0x5c,0x43);
+       &LL(0x4b,0x4b,0x31,0x4b,0x62,0x7a,0x96,0x29);
+       &LL(0xfe,0xfe,0xdf,0xfe,0xa3,0x21,0xe1,0x5d);
+       &LL(0x57,0x57,0x41,0x57,0x82,0x16,0xae,0xd5);
+       &LL(0x15,0x15,0x54,0x15,0xa8,0x41,0x2a,0xbd);
+       &LL(0x77,0x77,0xc1,0x77,0x9f,0xb6,0xee,0xe8);
+       &LL(0x37,0x37,0xdc,0x37,0xa5,0xeb,0x6e,0x92);
+       &LL(0xe5,0xe5,0xb3,0xe5,0x7b,0x56,0xd7,0x9e);
+       &LL(0x9f,0x9f,0x46,0x9f,0x8c,0xd9,0x23,0x13);
+       &LL(0xf0,0xf0,0xe7,0xf0,0xd3,0x17,0xfd,0x23);
+       &LL(0x4a,0x4a,0x35,0x4a,0x6a,0x7f,0x94,0x20);
+       &LL(0xda,0xda,0x4f,0xda,0x9e,0x95,0xa9,0x44);
+       &LL(0x58,0x58,0x7d,0x58,0xfa,0x25,0xb0,0xa2);
+       &LL(0xc9,0xc9,0x03,0xc9,0x06,0xca,0x8f,0xcf);
+       &LL(0x29,0x29,0xa4,0x29,0x55,0x8d,0x52,0x7c);
+       &LL(0x0a,0x0a,0x28,0x0a,0x50,0x22,0x14,0x5a);
+       &LL(0xb1,0xb1,0xfe,0xb1,0xe1,0x4f,0x7f,0x50);
+       &LL(0xa0,0xa0,0xba,0xa0,0x69,0x1a,0x5d,0xc9);
+       &LL(0x6b,0x6b,0xb1,0x6b,0x7f,0xda,0xd6,0x14);
+       &LL(0x85,0x85,0x2e,0x85,0x5c,0xab,0x17,0xd9);
+       &LL(0xbd,0xbd,0xce,0xbd,0x81,0x73,0x67,0x3c);
+       &LL(0x5d,0x5d,0x69,0x5d,0xd2,0x34,0xba,0x8f);
+       &LL(0x10,0x10,0x40,0x10,0x80,0x50,0x20,0x90);
+       &LL(0xf4,0xf4,0xf7,0xf4,0xf3,0x03,0xf5,0x07);
+       &LL(0xcb,0xcb,0x0b,0xcb,0x16,0xc0,0x8b,0xdd);
+       &LL(0x3e,0x3e,0xf8,0x3e,0xed,0xc6,0x7c,0xd3);
+       &LL(0x05,0x05,0x14,0x05,0x28,0x11,0x0a,0x2d);
+       &LL(0x67,0x67,0x81,0x67,0x1f,0xe6,0xce,0x78);
+       &LL(0xe4,0xe4,0xb7,0xe4,0x73,0x53,0xd5,0x97);
+       &LL(0x27,0x27,0x9c,0x27,0x25,0xbb,0x4e,0x02);
+       &LL(0x41,0x41,0x19,0x41,0x32,0x58,0x82,0x73);
+       &LL(0x8b,0x8b,0x16,0x8b,0x2c,0x9d,0x0b,0xa7);
+       &LL(0xa7,0xa7,0xa6,0xa7,0x51,0x01,0x53,0xf6);
+       &LL(0x7d,0x7d,0xe9,0x7d,0xcf,0x94,0xfa,0xb2);
+       &LL(0x95,0x95,0x6e,0x95,0xdc,0xfb,0x37,0x49);
+       &LL(0xd8,0xd8,0x47,0xd8,0x8e,0x9f,0xad,0x56);
+       &LL(0xfb,0xfb,0xcb,0xfb,0x8b,0x30,0xeb,0x70);
+       &LL(0xee,0xee,0x9f,0xee,0x23,0x71,0xc1,0xcd);
+       &LL(0x7c,0x7c,0xed,0x7c,0xc7,0x91,0xf8,0xbb);
+       &LL(0x66,0x66,0x85,0x66,0x17,0xe3,0xcc,0x71);
+       &LL(0xdd,0xdd,0x53,0xdd,0xa6,0x8e,0xa7,0x7b);
+       &LL(0x17,0x17,0x5c,0x17,0xb8,0x4b,0x2e,0xaf);
+       &LL(0x47,0x47,0x01,0x47,0x02,0x46,0x8e,0x45);
+       &LL(0x9e,0x9e,0x42,0x9e,0x84,0xdc,0x21,0x1a);
+       &LL(0xca,0xca,0x0f,0xca,0x1e,0xc5,0x89,0xd4);
+       &LL(0x2d,0x2d,0xb4,0x2d,0x75,0x99,0x5a,0x58);
+       &LL(0xbf,0xbf,0xc6,0xbf,0x91,0x79,0x63,0x2e);
+       &LL(0x07,0x07,0x1c,0x07,0x38,0x1b,0x0e,0x3f);
+       &LL(0xad,0xad,0x8e,0xad,0x01,0x23,0x47,0xac);
+       &LL(0x5a,0x5a,0x75,0x5a,0xea,0x2f,0xb4,0xb0);
+       &LL(0x83,0x83,0x36,0x83,0x6c,0xb5,0x1b,0xef);
+       &LL(0x33,0x33,0xcc,0x33,0x85,0xff,0x66,0xb6);
+       &LL(0x63,0x63,0x91,0x63,0x3f,0xf2,0xc6,0x5c);
+       &LL(0x02,0x02,0x08,0x02,0x10,0x0a,0x04,0x12);
+       &LL(0xaa,0xaa,0x92,0xaa,0x39,0x38,0x49,0x93);
+       &LL(0x71,0x71,0xd9,0x71,0xaf,0xa8,0xe2,0xde);
+       &LL(0xc8,0xc8,0x07,0xc8,0x0e,0xcf,0x8d,0xc6);
+       &LL(0x19,0x19,0x64,0x19,0xc8,0x7d,0x32,0xd1);
+       &LL(0x49,0x49,0x39,0x49,0x72,0x70,0x92,0x3b);
+       &LL(0xd9,0xd9,0x43,0xd9,0x86,0x9a,0xaf,0x5f);
+       &LL(0xf2,0xf2,0xef,0xf2,0xc3,0x1d,0xf9,0x31);
+       &LL(0xe3,0xe3,0xab,0xe3,0x4b,0x48,0xdb,0xa8);
+       &LL(0x5b,0x5b,0x71,0x5b,0xe2,0x2a,0xb6,0xb9);
+       &LL(0x88,0x88,0x1a,0x88,0x34,0x92,0x0d,0xbc);
+       &LL(0x9a,0x9a,0x52,0x9a,0xa4,0xc8,0x29,0x3e);
+       &LL(0x26,0x26,0x98,0x26,0x2d,0xbe,0x4c,0x0b);
+       &LL(0x32,0x32,0xc8,0x32,0x8d,0xfa,0x64,0xbf);
+       &LL(0xb0,0xb0,0xfa,0xb0,0xe9,0x4a,0x7d,0x59);
+       &LL(0xe9,0xe9,0x83,0xe9,0x1b,0x6a,0xcf,0xf2);
+       &LL(0x0f,0x0f,0x3c,0x0f,0x78,0x33,0x1e,0x77);
+       &LL(0xd5,0xd5,0x73,0xd5,0xe6,0xa6,0xb7,0x33);
+       &LL(0x80,0x80,0x3a,0x80,0x74,0xba,0x1d,0xf4);
+       &LL(0xbe,0xbe,0xc2,0xbe,0x99,0x7c,0x61,0x27);
+       &LL(0xcd,0xcd,0x13,0xcd,0x26,0xde,0x87,0xeb);
+       &LL(0x34,0x34,0xd0,0x34,0xbd,0xe4,0x68,0x89);
+       &LL(0x48,0x48,0x3d,0x48,0x7a,0x75,0x90,0x32);
+       &LL(0xff,0xff,0xdb,0xff,0xab,0x24,0xe3,0x54);
+       &LL(0x7a,0x7a,0xf5,0x7a,0xf7,0x8f,0xf4,0x8d);
+       &LL(0x90,0x90,0x7a,0x90,0xf4,0xea,0x3d,0x64);
+       &LL(0x5f,0x5f,0x61,0x5f,0xc2,0x3e,0xbe,0x9d);
+       &LL(0x20,0x20,0x80,0x20,0x1d,0xa0,0x40,0x3d);
+       &LL(0x68,0x68,0xbd,0x68,0x67,0xd5,0xd0,0x0f);
+       &LL(0x1a,0x1a,0x68,0x1a,0xd0,0x72,0x34,0xca);
+       &LL(0xae,0xae,0x82,0xae,0x19,0x2c,0x41,0xb7);
+       &LL(0xb4,0xb4,0xea,0xb4,0xc9,0x5e,0x75,0x7d);
+       &LL(0x54,0x54,0x4d,0x54,0x9a,0x19,0xa8,0xce);
+       &LL(0x93,0x93,0x76,0x93,0xec,0xe5,0x3b,0x7f);
+       &LL(0x22,0x22,0x88,0x22,0x0d,0xaa,0x44,0x2f);
+       &LL(0x64,0x64,0x8d,0x64,0x07,0xe9,0xc8,0x63);
+       &LL(0xf1,0xf1,0xe3,0xf1,0xdb,0x12,0xff,0x2a);
+       &LL(0x73,0x73,0xd1,0x73,0xbf,0xa2,0xe6,0xcc);
+       &LL(0x12,0x12,0x48,0x12,0x90,0x5a,0x24,0x82);
+       &LL(0x40,0x40,0x1d,0x40,0x3a,0x5d,0x80,0x7a);
+       &LL(0x08,0x08,0x20,0x08,0x40,0x28,0x10,0x48);
+       &LL(0xc3,0xc3,0x2b,0xc3,0x56,0xe8,0x9b,0x95);
+       &LL(0xec,0xec,0x97,0xec,0x33,0x7b,0xc5,0xdf);
+       &LL(0xdb,0xdb,0x4b,0xdb,0x96,0x90,0xab,0x4d);
+       &LL(0xa1,0xa1,0xbe,0xa1,0x61,0x1f,0x5f,0xc0);
+       &LL(0x8d,0x8d,0x0e,0x8d,0x1c,0x83,0x07,0x91);
+       &LL(0x3d,0x3d,0xf4,0x3d,0xf5,0xc9,0x7a,0xc8);
+       &LL(0x97,0x97,0x66,0x97,0xcc,0xf1,0x33,0x5b);
+       &LL(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
+       &LL(0xcf,0xcf,0x1b,0xcf,0x36,0xd4,0x83,0xf9);
+       &LL(0x2b,0x2b,0xac,0x2b,0x45,0x87,0x56,0x6e);
+       &LL(0x76,0x76,0xc5,0x76,0x97,0xb3,0xec,0xe1);
+       &LL(0x82,0x82,0x32,0x82,0x64,0xb0,0x19,0xe6);
+       &LL(0xd6,0xd6,0x7f,0xd6,0xfe,0xa9,0xb1,0x28);
+       &LL(0x1b,0x1b,0x6c,0x1b,0xd8,0x77,0x36,0xc3);
+       &LL(0xb5,0xb5,0xee,0xb5,0xc1,0x5b,0x77,0x74);
+       &LL(0xaf,0xaf,0x86,0xaf,0x11,0x29,0x43,0xbe);
+       &LL(0x6a,0x6a,0xb5,0x6a,0x77,0xdf,0xd4,0x1d);
+       &LL(0x50,0x50,0x5d,0x50,0xba,0x0d,0xa0,0xea);
+       &LL(0x45,0x45,0x09,0x45,0x12,0x4c,0x8a,0x57);
+       &LL(0xf3,0xf3,0xeb,0xf3,0xcb,0x18,0xfb,0x38);
+       &LL(0x30,0x30,0xc0,0x30,0x9d,0xf0,0x60,0xad);
+       &LL(0xef,0xef,0x9b,0xef,0x2b,0x74,0xc3,0xc4);
+       &LL(0x3f,0x3f,0xfc,0x3f,0xe5,0xc3,0x7e,0xda);
+       &LL(0x55,0x55,0x49,0x55,0x92,0x1c,0xaa,0xc7);
+       &LL(0xa2,0xa2,0xb2,0xa2,0x79,0x10,0x59,0xdb);
+       &LL(0xea,0xea,0x8f,0xea,0x03,0x65,0xc9,0xe9);
+       &LL(0x65,0x65,0x89,0x65,0x0f,0xec,0xca,0x6a);
+       &LL(0xba,0xba,0xd2,0xba,0xb9,0x68,0x69,0x03);
+       &LL(0x2f,0x2f,0xbc,0x2f,0x65,0x93,0x5e,0x4a);
+       &LL(0xc0,0xc0,0x27,0xc0,0x4e,0xe7,0x9d,0x8e);
+       &LL(0xde,0xde,0x5f,0xde,0xbe,0x81,0xa1,0x60);
+       &LL(0x1c,0x1c,0x70,0x1c,0xe0,0x6c,0x38,0xfc);
+       &LL(0xfd,0xfd,0xd3,0xfd,0xbb,0x2e,0xe7,0x46);
+       &LL(0x4d,0x4d,0x29,0x4d,0x52,0x64,0x9a,0x1f);
+       &LL(0x92,0x92,0x72,0x92,0xe4,0xe0,0x39,0x76);
+       &LL(0x75,0x75,0xc9,0x75,0x8f,0xbc,0xea,0xfa);
+       &LL(0x06,0x06,0x18,0x06,0x30,0x1e,0x0c,0x36);
+       &LL(0x8a,0x8a,0x12,0x8a,0x24,0x98,0x09,0xae);
+       &LL(0xb2,0xb2,0xf2,0xb2,0xf9,0x40,0x79,0x4b);
+       &LL(0xe6,0xe6,0xbf,0xe6,0x63,0x59,0xd1,0x85);
+       &LL(0x0e,0x0e,0x38,0x0e,0x70,0x36,0x1c,0x7e);
+       &LL(0x1f,0x1f,0x7c,0x1f,0xf8,0x63,0x3e,0xe7);
+       &LL(0x62,0x62,0x95,0x62,0x37,0xf7,0xc4,0x55);
+       &LL(0xd4,0xd4,0x77,0xd4,0xee,0xa3,0xb5,0x3a);
+       &LL(0xa8,0xa8,0x9a,0xa8,0x29,0x32,0x4d,0x81);
+       &LL(0x96,0x96,0x62,0x96,0xc4,0xf4,0x31,0x52);
+       &LL(0xf9,0xf9,0xc3,0xf9,0x9b,0x3a,0xef,0x62);
+       &LL(0xc5,0xc5,0x33,0xc5,0x66,0xf6,0x97,0xa3);
+       &LL(0x25,0x25,0x94,0x25,0x35,0xb1,0x4a,0x10);
+       &LL(0x59,0x59,0x79,0x59,0xf2,0x20,0xb2,0xab);
+       &LL(0x84,0x84,0x2a,0x84,0x54,0xae,0x15,0xd0);
+       &LL(0x72,0x72,0xd5,0x72,0xb7,0xa7,0xe4,0xc5);
+       &LL(0x39,0x39,0xe4,0x39,0xd5,0xdd,0x72,0xec);
+       &LL(0x4c,0x4c,0x2d,0x4c,0x5a,0x61,0x98,0x16);
+       &LL(0x5e,0x5e,0x65,0x5e,0xca,0x3b,0xbc,0x94);
+       &LL(0x78,0x78,0xfd,0x78,0xe7,0x85,0xf0,0x9f);
+       &LL(0x38,0x38,0xe0,0x38,0xdd,0xd8,0x70,0xe5);
+       &LL(0x8c,0x8c,0x0a,0x8c,0x14,0x86,0x05,0x98);
+       &LL(0xd1,0xd1,0x63,0xd1,0xc6,0xb2,0xbf,0x17);
+       &LL(0xa5,0xa5,0xae,0xa5,0x41,0x0b,0x57,0xe4);
+       &LL(0xe2,0xe2,0xaf,0xe2,0x43,0x4d,0xd9,0xa1);
+       &LL(0x61,0x61,0x99,0x61,0x2f,0xf8,0xc2,0x4e);
+       &LL(0xb3,0xb3,0xf6,0xb3,0xf1,0x45,0x7b,0x42);
+       &LL(0x21,0x21,0x84,0x21,0x15,0xa5,0x42,0x34);
+       &LL(0x9c,0x9c,0x4a,0x9c,0x94,0xd6,0x25,0x08);
+       &LL(0x1e,0x1e,0x78,0x1e,0xf0,0x66,0x3c,0xee);
+       &LL(0x43,0x43,0x11,0x43,0x22,0x52,0x86,0x61);
+       &LL(0xc7,0xc7,0x3b,0xc7,0x76,0xfc,0x93,0xb1);
+       &LL(0xfc,0xfc,0xd7,0xfc,0xb3,0x2b,0xe5,0x4f);
+       &LL(0x04,0x04,0x10,0x04,0x20,0x14,0x08,0x24);
+       &LL(0x51,0x51,0x59,0x51,0xb2,0x08,0xa2,0xe3);
+       &LL(0x99,0x99,0x5e,0x99,0xbc,0xc7,0x2f,0x25);
+       &LL(0x6d,0x6d,0xa9,0x6d,0x4f,0xc4,0xda,0x22);
+       &LL(0x0d,0x0d,0x34,0x0d,0x68,0x39,0x1a,0x65);
+       &LL(0xfa,0xfa,0xcf,0xfa,0x83,0x35,0xe9,0x79);
+       &LL(0xdf,0xdf,0x5b,0xdf,0xb6,0x84,0xa3,0x69);
+       &LL(0x7e,0x7e,0xe5,0x7e,0xd7,0x9b,0xfc,0xa9);
+       &LL(0x24,0x24,0x90,0x24,0x3d,0xb4,0x48,0x19);
+       &LL(0x3b,0x3b,0xec,0x3b,0xc5,0xd7,0x76,0xfe);
+       &LL(0xab,0xab,0x96,0xab,0x31,0x3d,0x4b,0x9a);
+       &LL(0xce,0xce,0x1f,0xce,0x3e,0xd1,0x81,0xf0);
+       &LL(0x11,0x11,0x44,0x11,0x88,0x55,0x22,0x99);
+       &LL(0x8f,0x8f,0x06,0x8f,0x0c,0x89,0x03,0x83);
+       &LL(0x4e,0x4e,0x25,0x4e,0x4a,0x6b,0x9c,0x04);
+       &LL(0xb7,0xb7,0xe6,0xb7,0xd1,0x51,0x73,0x66);
+       &LL(0xeb,0xeb,0x8b,0xeb,0x0b,0x60,0xcb,0xe0);
+       &LL(0x3c,0x3c,0xf0,0x3c,0xfd,0xcc,0x78,0xc1);
+       &LL(0x81,0x81,0x3e,0x81,0x7c,0xbf,0x1f,0xfd);
+       &LL(0x94,0x94,0x6a,0x94,0xd4,0xfe,0x35,0x40);
+       &LL(0xf7,0xf7,0xfb,0xf7,0xeb,0x0c,0xf3,0x1c);
+       &LL(0xb9,0xb9,0xde,0xb9,0xa1,0x67,0x6f,0x18);
+       &LL(0x13,0x13,0x4c,0x13,0x98,0x5f,0x26,0x8b);
+       &LL(0x2c,0x2c,0xb0,0x2c,0x7d,0x9c,0x58,0x51);
+       &LL(0xd3,0xd3,0x6b,0xd3,0xd6,0xb8,0xbb,0x05);
+       &LL(0xe7,0xe7,0xbb,0xe7,0x6b,0x5c,0xd3,0x8c);
+       &LL(0x6e,0x6e,0xa5,0x6e,0x57,0xcb,0xdc,0x39);
+       &LL(0xc4,0xc4,0x37,0xc4,0x6e,0xf3,0x95,0xaa);
+       &LL(0x03,0x03,0x0c,0x03,0x18,0x0f,0x06,0x1b);
+       &LL(0x56,0x56,0x45,0x56,0x8a,0x13,0xac,0xdc);
+       &LL(0x44,0x44,0x0d,0x44,0x1a,0x49,0x88,0x5e);
+       &LL(0x7f,0x7f,0xe1,0x7f,0xdf,0x9e,0xfe,0xa0);
+       &LL(0xa9,0xa9,0x9e,0xa9,0x21,0x37,0x4f,0x88);
+       &LL(0x2a,0x2a,0xa8,0x2a,0x4d,0x82,0x54,0x67);
+       &LL(0xbb,0xbb,0xd6,0xbb,0xb1,0x6d,0x6b,0x0a);
+       &LL(0xc1,0xc1,0x23,0xc1,0x46,0xe2,0x9f,0x87);
+       &LL(0x53,0x53,0x51,0x53,0xa2,0x02,0xa6,0xf1);
+       &LL(0xdc,0xdc,0x57,0xdc,0xae,0x8b,0xa5,0x72);
+       &LL(0x0b,0x0b,0x2c,0x0b,0x58,0x27,0x16,0x53);
+       &LL(0x9d,0x9d,0x4e,0x9d,0x9c,0xd3,0x27,0x01);
+       &LL(0x6c,0x6c,0xad,0x6c,0x47,0xc1,0xd8,0x2b);
+       &LL(0x31,0x31,0xc4,0x31,0x95,0xf5,0x62,0xa4);
+       &LL(0x74,0x74,0xcd,0x74,0x87,0xb9,0xe8,0xf3);
+       &LL(0xf6,0xf6,0xff,0xf6,0xe3,0x09,0xf1,0x15);
+       &LL(0x46,0x46,0x05,0x46,0x0a,0x43,0x8c,0x4c);
+       &LL(0xac,0xac,0x8a,0xac,0x09,0x26,0x45,0xa5);
+       &LL(0x89,0x89,0x1e,0x89,0x3c,0x97,0x0f,0xb5);
+       &LL(0x14,0x14,0x50,0x14,0xa0,0x44,0x28,0xb4);
+       &LL(0xe1,0xe1,0xa3,0xe1,0x5b,0x42,0xdf,0xba);
+       &LL(0x16,0x16,0x58,0x16,0xb0,0x4e,0x2c,0xa6);
+       &LL(0x3a,0x3a,0xe8,0x3a,0xcd,0xd2,0x74,0xf7);
+       &LL(0x69,0x69,0xb9,0x69,0x6f,0xd0,0xd2,0x06);
+       &LL(0x09,0x09,0x24,0x09,0x48,0x2d,0x12,0x41);
+       &LL(0x70,0x70,0xdd,0x70,0xa7,0xad,0xe0,0xd7);
+       &LL(0xb6,0xb6,0xe2,0xb6,0xd9,0x54,0x71,0x6f);
+       &LL(0xd0,0xd0,0x67,0xd0,0xce,0xb7,0xbd,0x1e);
+       &LL(0xed,0xed,0x93,0xed,0x3b,0x7e,0xc7,0xd6);
+       &LL(0xcc,0xcc,0x17,0xcc,0x2e,0xdb,0x85,0xe2);
+       &LL(0x42,0x42,0x15,0x42,0x2a,0x57,0x84,0x68);
+       &LL(0x98,0x98,0x5a,0x98,0xb4,0xc2,0x2d,0x2c);
+       &LL(0xa4,0xa4,0xaa,0xa4,0x49,0x0e,0x55,0xed);
+       &LL(0x28,0x28,0xa0,0x28,0x5d,0x88,0x50,0x75);
+       &LL(0x5c,0x5c,0x6d,0x5c,0xda,0x31,0xb8,0x86);
+       &LL(0xf8,0xf8,0xc7,0xf8,0x93,0x3f,0xed,0x6b);
+       &LL(0x86,0x86,0x22,0x86,0x44,0xa4,0x11,0xc2);
+
+       &L(0x18,0x23,0xc6,0xe8,0x87,0xb8,0x01,0x4f);    # rc[ROUNDS]
+       &L(0x36,0xa6,0xd2,0xf5,0x79,0x6f,0x91,0x52);
+       &L(0x60,0xbc,0x9b,0x8e,0xa3,0x0c,0x7b,0x35);
+       &L(0x1d,0xe0,0xd7,0xc2,0x2e,0x4b,0xfe,0x57);
+       &L(0x15,0x77,0x37,0xe5,0x9f,0xf0,0x4a,0xda);
+       &L(0x58,0xc9,0x29,0x0a,0xb1,0xa0,0x6b,0x85);
+       &L(0xbd,0x5d,0x10,0xf4,0xcb,0x3e,0x05,0x67);
+       &L(0xe4,0x27,0x41,0x8b,0xa7,0x7d,0x95,0xd8);
+       &L(0xfb,0xee,0x7c,0x66,0xdd,0x17,0x47,0x9e);
+       &L(0xca,0x2d,0xbf,0x07,0xad,0x5a,0x83,0x33);
+
+&function_end_B("whirlpool_block_mmx");
+&asm_finish(); 
diff --git a/deps/openssl/openssl/crypto/whrlpool/asm/wp-x86_64.pl b/deps/openssl/openssl/crypto/whrlpool/asm/wp-x86_64.pl
new file mode 100644 (file)
index 0000000..87c0843
--- /dev/null
@@ -0,0 +1,589 @@
+#!/usr/bin/env perl
+#
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. Rights for redistribution and usage in source and binary
+# forms are granted according to the OpenSSL license.
+# ====================================================================
+#
+# whirlpool_block for x86_64.
+#
+# 2500 cycles per 64-byte input block on AMD64, which is *identical*
+# to 32-bit MMX version executed on same CPU. So why did I bother?
+# Well, it's faster than gcc 3.3.2 generated code by over 50%, and
+# over 80% faster than PathScale 1.4, an "ambitious" commercial
+# compiler. Furthermore it surpasses gcc 3.4.3 by 170% and Sun Studio
+# 10 - by 360%[!]... What is it with x86_64 compilers? It's not the
+# first example when they fail to generate more optimal code, when
+# I believe they had *all* chances to...
+#
+# Note that register and stack frame layout are virtually identical
+# to 32-bit MMX version, except that %r8-15 are used instead of
+# %mm0-8. You can even notice that K[i] and S[i] are loaded to
+# %eax:%ebx as pair of 32-bit values and not as single 64-bit one.
+# This is done in order to avoid 64-bit shift penalties on Intel
+# EM64T core. Speaking of which! I bet it's possible to improve
+# Opteron performance by compressing the table to 2KB and replacing
+# unaligned references with complementary rotations [which would
+# incidentally replace lea instructions], but it would definitely
+# just "kill" EM64T, because it has only 1 shifter/rotator [against
+# 3 on Opteron] and which is *unacceptably* slow with 64-bit
+# operand.
+
+$flavour = shift;
+$output  = shift;
+if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
+
+$win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
+
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; my $dir=$1; my $xlate;
+( $xlate="${dir}x86_64-xlate.pl" and -f $xlate ) or
+( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
+die "can't locate x86_64-xlate.pl";
+
+open STDOUT,"| $^X $xlate $flavour $output";
+
+sub L() { $code.=".byte        ".join(',',@_)."\n"; }
+sub LL(){ $code.=".byte        ".join(',',@_).",".join(',',@_)."\n"; }
+
+@mm=("%r8","%r9","%r10","%r11","%r12","%r13","%r14","%r15");
+
+$func="whirlpool_block";
+$table=".Ltable";
+
+$code=<<___;
+.text
+
+.globl $func
+.type  $func,\@function,3
+.align 16
+$func:
+       push    %rbx
+       push    %rbp
+       push    %r12
+       push    %r13
+       push    %r14
+       push    %r15
+
+       mov     %rsp,%r11
+       sub     \$128+40,%rsp
+       and     \$-64,%rsp
+
+       lea     128(%rsp),%r10
+       mov     %rdi,0(%r10)            # save parameter block
+       mov     %rsi,8(%r10)
+       mov     %rdx,16(%r10)
+       mov     %r11,32(%r10)           # saved stack pointer
+.Lprologue:
+
+       mov     %r10,%rbx
+       lea     $table(%rip),%rbp
+
+       xor     %rcx,%rcx
+       xor     %rdx,%rdx
+___
+for($i=0;$i<8;$i++) { $code.="mov $i*8(%rdi),@mm[$i]\n"; }     # L=H
+$code.=".Louterloop:\n";
+for($i=0;$i<8;$i++) { $code.="mov @mm[$i],$i*8(%rsp)\n"; }     # K=L
+for($i=0;$i<8;$i++) { $code.="xor $i*8(%rsi),@mm[$i]\n"; }     # L^=inp
+for($i=0;$i<8;$i++) { $code.="mov @mm[$i],64+$i*8(%rsp)\n"; }  # S=L
+$code.=<<___;
+       xor     %rsi,%rsi
+       mov     %rsi,24(%rbx)           # zero round counter
+.align 16
+.Lround:
+       mov     4096(%rbp,%rsi,8),@mm[0]        # rc[r]
+       mov     0(%rsp),%eax
+       mov     4(%rsp),%ebx
+___
+for($i=0;$i<8;$i++) {
+    my $func = ($i==0)? "mov" : "xor";
+    $code.=<<___;
+       mov     %al,%cl
+       mov     %ah,%dl
+       lea     (%rcx,%rcx),%rsi
+       lea     (%rdx,%rdx),%rdi
+       shr     \$16,%eax
+       xor     0(%rbp,%rsi,8),@mm[0]
+       $func   7(%rbp,%rdi,8),@mm[1]
+       mov     %al,%cl
+       mov     %ah,%dl
+       mov     $i*8+8(%rsp),%eax               # ($i+1)*8
+       lea     (%rcx,%rcx),%rsi
+       lea     (%rdx,%rdx),%rdi
+       $func   6(%rbp,%rsi,8),@mm[2]
+       $func   5(%rbp,%rdi,8),@mm[3]
+       mov     %bl,%cl
+       mov     %bh,%dl
+       lea     (%rcx,%rcx),%rsi
+       lea     (%rdx,%rdx),%rdi
+       shr     \$16,%ebx
+       $func   4(%rbp,%rsi,8),@mm[4]
+       $func   3(%rbp,%rdi,8),@mm[5]
+       mov     %bl,%cl
+       mov     %bh,%dl
+       mov     $i*8+8+4(%rsp),%ebx             # ($i+1)*8+4
+       lea     (%rcx,%rcx),%rsi
+       lea     (%rdx,%rdx),%rdi
+       $func   2(%rbp,%rsi,8),@mm[6]
+       $func   1(%rbp,%rdi,8),@mm[7]
+___
+    push(@mm,shift(@mm));
+}
+for($i=0;$i<8;$i++) { $code.="mov @mm[$i],$i*8(%rsp)\n"; }     # K=L
+for($i=0;$i<8;$i++) {
+    $code.=<<___;
+       mov     %al,%cl
+       mov     %ah,%dl
+       lea     (%rcx,%rcx),%rsi
+       lea     (%rdx,%rdx),%rdi
+       shr     \$16,%eax
+       xor     0(%rbp,%rsi,8),@mm[0]
+       xor     7(%rbp,%rdi,8),@mm[1]
+       mov     %al,%cl
+       mov     %ah,%dl
+       `"mov   64+$i*8+8(%rsp),%eax"   if($i<7);`      # 64+($i+1)*8
+       lea     (%rcx,%rcx),%rsi
+       lea     (%rdx,%rdx),%rdi
+       xor     6(%rbp,%rsi,8),@mm[2]
+       xor     5(%rbp,%rdi,8),@mm[3]
+       mov     %bl,%cl
+       mov     %bh,%dl
+       lea     (%rcx,%rcx),%rsi
+       lea     (%rdx,%rdx),%rdi
+       shr     \$16,%ebx
+       xor     4(%rbp,%rsi,8),@mm[4]
+       xor     3(%rbp,%rdi,8),@mm[5]
+       mov     %bl,%cl
+       mov     %bh,%dl
+       `"mov   64+$i*8+8+4(%rsp),%ebx" if($i<7);`      # 64+($i+1)*8+4
+       lea     (%rcx,%rcx),%rsi
+       lea     (%rdx,%rdx),%rdi
+       xor     2(%rbp,%rsi,8),@mm[6]
+       xor     1(%rbp,%rdi,8),@mm[7]
+___
+    push(@mm,shift(@mm));
+}
+$code.=<<___;
+       lea     128(%rsp),%rbx
+       mov     24(%rbx),%rsi           # pull round counter
+       add     \$1,%rsi
+       cmp     \$10,%rsi
+       je      .Lroundsdone
+
+       mov     %rsi,24(%rbx)           # update round counter
+___
+for($i=0;$i<8;$i++) { $code.="mov @mm[$i],64+$i*8(%rsp)\n"; }  # S=L
+$code.=<<___;
+       jmp     .Lround
+.align 16
+.Lroundsdone:
+       mov     0(%rbx),%rdi            # reload argument block
+       mov     8(%rbx),%rsi
+       mov     16(%rbx),%rax
+___
+for($i=0;$i<8;$i++) { $code.="xor $i*8(%rsi),@mm[$i]\n"; }     # L^=inp
+for($i=0;$i<8;$i++) { $code.="xor $i*8(%rdi),@mm[$i]\n"; }     # L^=H
+for($i=0;$i<8;$i++) { $code.="mov @mm[$i],$i*8(%rdi)\n"; }     # H=L
+$code.=<<___;
+       lea     64(%rsi),%rsi           # inp+=64
+       sub     \$1,%rax                # num--
+       jz      .Lalldone
+       mov     %rsi,8(%rbx)            # update parameter block
+       mov     %rax,16(%rbx)
+       jmp     .Louterloop
+.Lalldone:
+       mov     32(%rbx),%rsi           # restore saved pointer
+       mov     (%rsi),%r15
+       mov     8(%rsi),%r14
+       mov     16(%rsi),%r13
+       mov     24(%rsi),%r12
+       mov     32(%rsi),%rbp
+       mov     40(%rsi),%rbx
+       lea     48(%rsi),%rsp
+.Lepilogue:
+       ret
+.size  $func,.-$func
+
+.align 64
+.type  $table,\@object
+$table:
+___
+       &LL(0x18,0x18,0x60,0x18,0xc0,0x78,0x30,0xd8);
+       &LL(0x23,0x23,0x8c,0x23,0x05,0xaf,0x46,0x26);
+       &LL(0xc6,0xc6,0x3f,0xc6,0x7e,0xf9,0x91,0xb8);
+       &LL(0xe8,0xe8,0x87,0xe8,0x13,0x6f,0xcd,0xfb);
+       &LL(0x87,0x87,0x26,0x87,0x4c,0xa1,0x13,0xcb);
+       &LL(0xb8,0xb8,0xda,0xb8,0xa9,0x62,0x6d,0x11);
+       &LL(0x01,0x01,0x04,0x01,0x08,0x05,0x02,0x09);
+       &LL(0x4f,0x4f,0x21,0x4f,0x42,0x6e,0x9e,0x0d);
+       &LL(0x36,0x36,0xd8,0x36,0xad,0xee,0x6c,0x9b);
+       &LL(0xa6,0xa6,0xa2,0xa6,0x59,0x04,0x51,0xff);
+       &LL(0xd2,0xd2,0x6f,0xd2,0xde,0xbd,0xb9,0x0c);
+       &LL(0xf5,0xf5,0xf3,0xf5,0xfb,0x06,0xf7,0x0e);
+       &LL(0x79,0x79,0xf9,0x79,0xef,0x80,0xf2,0x96);
+       &LL(0x6f,0x6f,0xa1,0x6f,0x5f,0xce,0xde,0x30);
+       &LL(0x91,0x91,0x7e,0x91,0xfc,0xef,0x3f,0x6d);
+       &LL(0x52,0x52,0x55,0x52,0xaa,0x07,0xa4,0xf8);
+       &LL(0x60,0x60,0x9d,0x60,0x27,0xfd,0xc0,0x47);
+       &LL(0xbc,0xbc,0xca,0xbc,0x89,0x76,0x65,0x35);
+       &LL(0x9b,0x9b,0x56,0x9b,0xac,0xcd,0x2b,0x37);
+       &LL(0x8e,0x8e,0x02,0x8e,0x04,0x8c,0x01,0x8a);
+       &LL(0xa3,0xa3,0xb6,0xa3,0x71,0x15,0x5b,0xd2);
+       &LL(0x0c,0x0c,0x30,0x0c,0x60,0x3c,0x18,0x6c);
+       &LL(0x7b,0x7b,0xf1,0x7b,0xff,0x8a,0xf6,0x84);
+       &LL(0x35,0x35,0xd4,0x35,0xb5,0xe1,0x6a,0x80);
+       &LL(0x1d,0x1d,0x74,0x1d,0xe8,0x69,0x3a,0xf5);
+       &LL(0xe0,0xe0,0xa7,0xe0,0x53,0x47,0xdd,0xb3);
+       &LL(0xd7,0xd7,0x7b,0xd7,0xf6,0xac,0xb3,0x21);
+       &LL(0xc2,0xc2,0x2f,0xc2,0x5e,0xed,0x99,0x9c);
+       &LL(0x2e,0x2e,0xb8,0x2e,0x6d,0x96,0x5c,0x43);
+       &LL(0x4b,0x4b,0x31,0x4b,0x62,0x7a,0x96,0x29);
+       &LL(0xfe,0xfe,0xdf,0xfe,0xa3,0x21,0xe1,0x5d);
+       &LL(0x57,0x57,0x41,0x57,0x82,0x16,0xae,0xd5);
+       &LL(0x15,0x15,0x54,0x15,0xa8,0x41,0x2a,0xbd);
+       &LL(0x77,0x77,0xc1,0x77,0x9f,0xb6,0xee,0xe8);
+       &LL(0x37,0x37,0xdc,0x37,0xa5,0xeb,0x6e,0x92);
+       &LL(0xe5,0xe5,0xb3,0xe5,0x7b,0x56,0xd7,0x9e);
+       &LL(0x9f,0x9f,0x46,0x9f,0x8c,0xd9,0x23,0x13);
+       &LL(0xf0,0xf0,0xe7,0xf0,0xd3,0x17,0xfd,0x23);
+       &LL(0x4a,0x4a,0x35,0x4a,0x6a,0x7f,0x94,0x20);
+       &LL(0xda,0xda,0x4f,0xda,0x9e,0x95,0xa9,0x44);
+       &LL(0x58,0x58,0x7d,0x58,0xfa,0x25,0xb0,0xa2);
+       &LL(0xc9,0xc9,0x03,0xc9,0x06,0xca,0x8f,0xcf);
+       &LL(0x29,0x29,0xa4,0x29,0x55,0x8d,0x52,0x7c);
+       &LL(0x0a,0x0a,0x28,0x0a,0x50,0x22,0x14,0x5a);
+       &LL(0xb1,0xb1,0xfe,0xb1,0xe1,0x4f,0x7f,0x50);
+       &LL(0xa0,0xa0,0xba,0xa0,0x69,0x1a,0x5d,0xc9);
+       &LL(0x6b,0x6b,0xb1,0x6b,0x7f,0xda,0xd6,0x14);
+       &LL(0x85,0x85,0x2e,0x85,0x5c,0xab,0x17,0xd9);
+       &LL(0xbd,0xbd,0xce,0xbd,0x81,0x73,0x67,0x3c);
+       &LL(0x5d,0x5d,0x69,0x5d,0xd2,0x34,0xba,0x8f);
+       &LL(0x10,0x10,0x40,0x10,0x80,0x50,0x20,0x90);
+       &LL(0xf4,0xf4,0xf7,0xf4,0xf3,0x03,0xf5,0x07);
+       &LL(0xcb,0xcb,0x0b,0xcb,0x16,0xc0,0x8b,0xdd);
+       &LL(0x3e,0x3e,0xf8,0x3e,0xed,0xc6,0x7c,0xd3);
+       &LL(0x05,0x05,0x14,0x05,0x28,0x11,0x0a,0x2d);
+       &LL(0x67,0x67,0x81,0x67,0x1f,0xe6,0xce,0x78);
+       &LL(0xe4,0xe4,0xb7,0xe4,0x73,0x53,0xd5,0x97);
+       &LL(0x27,0x27,0x9c,0x27,0x25,0xbb,0x4e,0x02);
+       &LL(0x41,0x41,0x19,0x41,0x32,0x58,0x82,0x73);
+       &LL(0x8b,0x8b,0x16,0x8b,0x2c,0x9d,0x0b,0xa7);
+       &LL(0xa7,0xa7,0xa6,0xa7,0x51,0x01,0x53,0xf6);
+       &LL(0x7d,0x7d,0xe9,0x7d,0xcf,0x94,0xfa,0xb2);
+       &LL(0x95,0x95,0x6e,0x95,0xdc,0xfb,0x37,0x49);
+       &LL(0xd8,0xd8,0x47,0xd8,0x8e,0x9f,0xad,0x56);
+       &LL(0xfb,0xfb,0xcb,0xfb,0x8b,0x30,0xeb,0x70);
+       &LL(0xee,0xee,0x9f,0xee,0x23,0x71,0xc1,0xcd);
+       &LL(0x7c,0x7c,0xed,0x7c,0xc7,0x91,0xf8,0xbb);
+       &LL(0x66,0x66,0x85,0x66,0x17,0xe3,0xcc,0x71);
+       &LL(0xdd,0xdd,0x53,0xdd,0xa6,0x8e,0xa7,0x7b);
+       &LL(0x17,0x17,0x5c,0x17,0xb8,0x4b,0x2e,0xaf);
+       &LL(0x47,0x47,0x01,0x47,0x02,0x46,0x8e,0x45);
+       &LL(0x9e,0x9e,0x42,0x9e,0x84,0xdc,0x21,0x1a);
+       &LL(0xca,0xca,0x0f,0xca,0x1e,0xc5,0x89,0xd4);
+       &LL(0x2d,0x2d,0xb4,0x2d,0x75,0x99,0x5a,0x58);
+       &LL(0xbf,0xbf,0xc6,0xbf,0x91,0x79,0x63,0x2e);
+       &LL(0x07,0x07,0x1c,0x07,0x38,0x1b,0x0e,0x3f);
+       &LL(0xad,0xad,0x8e,0xad,0x01,0x23,0x47,0xac);
+       &LL(0x5a,0x5a,0x75,0x5a,0xea,0x2f,0xb4,0xb0);
+       &LL(0x83,0x83,0x36,0x83,0x6c,0xb5,0x1b,0xef);
+       &LL(0x33,0x33,0xcc,0x33,0x85,0xff,0x66,0xb6);
+       &LL(0x63,0x63,0x91,0x63,0x3f,0xf2,0xc6,0x5c);
+       &LL(0x02,0x02,0x08,0x02,0x10,0x0a,0x04,0x12);
+       &LL(0xaa,0xaa,0x92,0xaa,0x39,0x38,0x49,0x93);
+       &LL(0x71,0x71,0xd9,0x71,0xaf,0xa8,0xe2,0xde);
+       &LL(0xc8,0xc8,0x07,0xc8,0x0e,0xcf,0x8d,0xc6);
+       &LL(0x19,0x19,0x64,0x19,0xc8,0x7d,0x32,0xd1);
+       &LL(0x49,0x49,0x39,0x49,0x72,0x70,0x92,0x3b);
+       &LL(0xd9,0xd9,0x43,0xd9,0x86,0x9a,0xaf,0x5f);
+       &LL(0xf2,0xf2,0xef,0xf2,0xc3,0x1d,0xf9,0x31);
+       &LL(0xe3,0xe3,0xab,0xe3,0x4b,0x48,0xdb,0xa8);
+       &LL(0x5b,0x5b,0x71,0x5b,0xe2,0x2a,0xb6,0xb9);
+       &LL(0x88,0x88,0x1a,0x88,0x34,0x92,0x0d,0xbc);
+       &LL(0x9a,0x9a,0x52,0x9a,0xa4,0xc8,0x29,0x3e);
+       &LL(0x26,0x26,0x98,0x26,0x2d,0xbe,0x4c,0x0b);
+       &LL(0x32,0x32,0xc8,0x32,0x8d,0xfa,0x64,0xbf);
+       &LL(0xb0,0xb0,0xfa,0xb0,0xe9,0x4a,0x7d,0x59);
+       &LL(0xe9,0xe9,0x83,0xe9,0x1b,0x6a,0xcf,0xf2);
+       &LL(0x0f,0x0f,0x3c,0x0f,0x78,0x33,0x1e,0x77);
+       &LL(0xd5,0xd5,0x73,0xd5,0xe6,0xa6,0xb7,0x33);
+       &LL(0x80,0x80,0x3a,0x80,0x74,0xba,0x1d,0xf4);
+       &LL(0xbe,0xbe,0xc2,0xbe,0x99,0x7c,0x61,0x27);
+       &LL(0xcd,0xcd,0x13,0xcd,0x26,0xde,0x87,0xeb);
+       &LL(0x34,0x34,0xd0,0x34,0xbd,0xe4,0x68,0x89);
+       &LL(0x48,0x48,0x3d,0x48,0x7a,0x75,0x90,0x32);
+       &LL(0xff,0xff,0xdb,0xff,0xab,0x24,0xe3,0x54);
+       &LL(0x7a,0x7a,0xf5,0x7a,0xf7,0x8f,0xf4,0x8d);
+       &LL(0x90,0x90,0x7a,0x90,0xf4,0xea,0x3d,0x64);
+       &LL(0x5f,0x5f,0x61,0x5f,0xc2,0x3e,0xbe,0x9d);
+       &LL(0x20,0x20,0x80,0x20,0x1d,0xa0,0x40,0x3d);
+       &LL(0x68,0x68,0xbd,0x68,0x67,0xd5,0xd0,0x0f);
+       &LL(0x1a,0x1a,0x68,0x1a,0xd0,0x72,0x34,0xca);
+       &LL(0xae,0xae,0x82,0xae,0x19,0x2c,0x41,0xb7);
+       &LL(0xb4,0xb4,0xea,0xb4,0xc9,0x5e,0x75,0x7d);
+       &LL(0x54,0x54,0x4d,0x54,0x9a,0x19,0xa8,0xce);
+       &LL(0x93,0x93,0x76,0x93,0xec,0xe5,0x3b,0x7f);
+       &LL(0x22,0x22,0x88,0x22,0x0d,0xaa,0x44,0x2f);
+       &LL(0x64,0x64,0x8d,0x64,0x07,0xe9,0xc8,0x63);
+       &LL(0xf1,0xf1,0xe3,0xf1,0xdb,0x12,0xff,0x2a);
+       &LL(0x73,0x73,0xd1,0x73,0xbf,0xa2,0xe6,0xcc);
+       &LL(0x12,0x12,0x48,0x12,0x90,0x5a,0x24,0x82);
+       &LL(0x40,0x40,0x1d,0x40,0x3a,0x5d,0x80,0x7a);
+       &LL(0x08,0x08,0x20,0x08,0x40,0x28,0x10,0x48);
+       &LL(0xc3,0xc3,0x2b,0xc3,0x56,0xe8,0x9b,0x95);
+       &LL(0xec,0xec,0x97,0xec,0x33,0x7b,0xc5,0xdf);
+       &LL(0xdb,0xdb,0x4b,0xdb,0x96,0x90,0xab,0x4d);
+       &LL(0xa1,0xa1,0xbe,0xa1,0x61,0x1f,0x5f,0xc0);
+       &LL(0x8d,0x8d,0x0e,0x8d,0x1c,0x83,0x07,0x91);
+       &LL(0x3d,0x3d,0xf4,0x3d,0xf5,0xc9,0x7a,0xc8);
+       &LL(0x97,0x97,0x66,0x97,0xcc,0xf1,0x33,0x5b);
+       &LL(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
+       &LL(0xcf,0xcf,0x1b,0xcf,0x36,0xd4,0x83,0xf9);
+       &LL(0x2b,0x2b,0xac,0x2b,0x45,0x87,0x56,0x6e);
+       &LL(0x76,0x76,0xc5,0x76,0x97,0xb3,0xec,0xe1);
+       &LL(0x82,0x82,0x32,0x82,0x64,0xb0,0x19,0xe6);
+       &LL(0xd6,0xd6,0x7f,0xd6,0xfe,0xa9,0xb1,0x28);
+       &LL(0x1b,0x1b,0x6c,0x1b,0xd8,0x77,0x36,0xc3);
+       &LL(0xb5,0xb5,0xee,0xb5,0xc1,0x5b,0x77,0x74);
+       &LL(0xaf,0xaf,0x86,0xaf,0x11,0x29,0x43,0xbe);
+       &LL(0x6a,0x6a,0xb5,0x6a,0x77,0xdf,0xd4,0x1d);
+       &LL(0x50,0x50,0x5d,0x50,0xba,0x0d,0xa0,0xea);
+       &LL(0x45,0x45,0x09,0x45,0x12,0x4c,0x8a,0x57);
+       &LL(0xf3,0xf3,0xeb,0xf3,0xcb,0x18,0xfb,0x38);
+       &LL(0x30,0x30,0xc0,0x30,0x9d,0xf0,0x60,0xad);
+       &LL(0xef,0xef,0x9b,0xef,0x2b,0x74,0xc3,0xc4);
+       &LL(0x3f,0x3f,0xfc,0x3f,0xe5,0xc3,0x7e,0xda);
+       &LL(0x55,0x55,0x49,0x55,0x92,0x1c,0xaa,0xc7);
+       &LL(0xa2,0xa2,0xb2,0xa2,0x79,0x10,0x59,0xdb);
+       &LL(0xea,0xea,0x8f,0xea,0x03,0x65,0xc9,0xe9);
+       &LL(0x65,0x65,0x89,0x65,0x0f,0xec,0xca,0x6a);
+       &LL(0xba,0xba,0xd2,0xba,0xb9,0x68,0x69,0x03);
+       &LL(0x2f,0x2f,0xbc,0x2f,0x65,0x93,0x5e,0x4a);
+       &LL(0xc0,0xc0,0x27,0xc0,0x4e,0xe7,0x9d,0x8e);
+       &LL(0xde,0xde,0x5f,0xde,0xbe,0x81,0xa1,0x60);
+       &LL(0x1c,0x1c,0x70,0x1c,0xe0,0x6c,0x38,0xfc);
+       &LL(0xfd,0xfd,0xd3,0xfd,0xbb,0x2e,0xe7,0x46);
+       &LL(0x4d,0x4d,0x29,0x4d,0x52,0x64,0x9a,0x1f);
+       &LL(0x92,0x92,0x72,0x92,0xe4,0xe0,0x39,0x76);
+       &LL(0x75,0x75,0xc9,0x75,0x8f,0xbc,0xea,0xfa);
+       &LL(0x06,0x06,0x18,0x06,0x30,0x1e,0x0c,0x36);
+       &LL(0x8a,0x8a,0x12,0x8a,0x24,0x98,0x09,0xae);
+       &LL(0xb2,0xb2,0xf2,0xb2,0xf9,0x40,0x79,0x4b);
+       &LL(0xe6,0xe6,0xbf,0xe6,0x63,0x59,0xd1,0x85);
+       &LL(0x0e,0x0e,0x38,0x0e,0x70,0x36,0x1c,0x7e);
+       &LL(0x1f,0x1f,0x7c,0x1f,0xf8,0x63,0x3e,0xe7);
+       &LL(0x62,0x62,0x95,0x62,0x37,0xf7,0xc4,0x55);
+       &LL(0xd4,0xd4,0x77,0xd4,0xee,0xa3,0xb5,0x3a);
+       &LL(0xa8,0xa8,0x9a,0xa8,0x29,0x32,0x4d,0x81);
+       &LL(0x96,0x96,0x62,0x96,0xc4,0xf4,0x31,0x52);
+       &LL(0xf9,0xf9,0xc3,0xf9,0x9b,0x3a,0xef,0x62);
+       &LL(0xc5,0xc5,0x33,0xc5,0x66,0xf6,0x97,0xa3);
+       &LL(0x25,0x25,0x94,0x25,0x35,0xb1,0x4a,0x10);
+       &LL(0x59,0x59,0x79,0x59,0xf2,0x20,0xb2,0xab);
+       &LL(0x84,0x84,0x2a,0x84,0x54,0xae,0x15,0xd0);
+       &LL(0x72,0x72,0xd5,0x72,0xb7,0xa7,0xe4,0xc5);
+       &LL(0x39,0x39,0xe4,0x39,0xd5,0xdd,0x72,0xec);
+       &LL(0x4c,0x4c,0x2d,0x4c,0x5a,0x61,0x98,0x16);
+       &LL(0x5e,0x5e,0x65,0x5e,0xca,0x3b,0xbc,0x94);
+       &LL(0x78,0x78,0xfd,0x78,0xe7,0x85,0xf0,0x9f);
+       &LL(0x38,0x38,0xe0,0x38,0xdd,0xd8,0x70,0xe5);
+       &LL(0x8c,0x8c,0x0a,0x8c,0x14,0x86,0x05,0x98);
+       &LL(0xd1,0xd1,0x63,0xd1,0xc6,0xb2,0xbf,0x17);
+       &LL(0xa5,0xa5,0xae,0xa5,0x41,0x0b,0x57,0xe4);
+       &LL(0xe2,0xe2,0xaf,0xe2,0x43,0x4d,0xd9,0xa1);
+       &LL(0x61,0x61,0x99,0x61,0x2f,0xf8,0xc2,0x4e);
+       &LL(0xb3,0xb3,0xf6,0xb3,0xf1,0x45,0x7b,0x42);
+       &LL(0x21,0x21,0x84,0x21,0x15,0xa5,0x42,0x34);
+       &LL(0x9c,0x9c,0x4a,0x9c,0x94,0xd6,0x25,0x08);
+       &LL(0x1e,0x1e,0x78,0x1e,0xf0,0x66,0x3c,0xee);
+       &LL(0x43,0x43,0x11,0x43,0x22,0x52,0x86,0x61);
+       &LL(0xc7,0xc7,0x3b,0xc7,0x76,0xfc,0x93,0xb1);
+       &LL(0xfc,0xfc,0xd7,0xfc,0xb3,0x2b,0xe5,0x4f);
+       &LL(0x04,0x04,0x10,0x04,0x20,0x14,0x08,0x24);
+       &LL(0x51,0x51,0x59,0x51,0xb2,0x08,0xa2,0xe3);
+       &LL(0x99,0x99,0x5e,0x99,0xbc,0xc7,0x2f,0x25);
+       &LL(0x6d,0x6d,0xa9,0x6d,0x4f,0xc4,0xda,0x22);
+       &LL(0x0d,0x0d,0x34,0x0d,0x68,0x39,0x1a,0x65);
+       &LL(0xfa,0xfa,0xcf,0xfa,0x83,0x35,0xe9,0x79);
+       &LL(0xdf,0xdf,0x5b,0xdf,0xb6,0x84,0xa3,0x69);
+       &LL(0x7e,0x7e,0xe5,0x7e,0xd7,0x9b,0xfc,0xa9);
+       &LL(0x24,0x24,0x90,0x24,0x3d,0xb4,0x48,0x19);
+       &LL(0x3b,0x3b,0xec,0x3b,0xc5,0xd7,0x76,0xfe);
+       &LL(0xab,0xab,0x96,0xab,0x31,0x3d,0x4b,0x9a);
+       &LL(0xce,0xce,0x1f,0xce,0x3e,0xd1,0x81,0xf0);
+       &LL(0x11,0x11,0x44,0x11,0x88,0x55,0x22,0x99);
+       &LL(0x8f,0x8f,0x06,0x8f,0x0c,0x89,0x03,0x83);
+       &LL(0x4e,0x4e,0x25,0x4e,0x4a,0x6b,0x9c,0x04);
+       &LL(0xb7,0xb7,0xe6,0xb7,0xd1,0x51,0x73,0x66);
+       &LL(0xeb,0xeb,0x8b,0xeb,0x0b,0x60,0xcb,0xe0);
+       &LL(0x3c,0x3c,0xf0,0x3c,0xfd,0xcc,0x78,0xc1);
+       &LL(0x81,0x81,0x3e,0x81,0x7c,0xbf,0x1f,0xfd);
+       &LL(0x94,0x94,0x6a,0x94,0xd4,0xfe,0x35,0x40);
+       &LL(0xf7,0xf7,0xfb,0xf7,0xeb,0x0c,0xf3,0x1c);
+       &LL(0xb9,0xb9,0xde,0xb9,0xa1,0x67,0x6f,0x18);
+       &LL(0x13,0x13,0x4c,0x13,0x98,0x5f,0x26,0x8b);
+       &LL(0x2c,0x2c,0xb0,0x2c,0x7d,0x9c,0x58,0x51);
+       &LL(0xd3,0xd3,0x6b,0xd3,0xd6,0xb8,0xbb,0x05);
+       &LL(0xe7,0xe7,0xbb,0xe7,0x6b,0x5c,0xd3,0x8c);
+       &LL(0x6e,0x6e,0xa5,0x6e,0x57,0xcb,0xdc,0x39);
+       &LL(0xc4,0xc4,0x37,0xc4,0x6e,0xf3,0x95,0xaa);
+       &LL(0x03,0x03,0x0c,0x03,0x18,0x0f,0x06,0x1b);
+       &LL(0x56,0x56,0x45,0x56,0x8a,0x13,0xac,0xdc);
+       &LL(0x44,0x44,0x0d,0x44,0x1a,0x49,0x88,0x5e);
+       &LL(0x7f,0x7f,0xe1,0x7f,0xdf,0x9e,0xfe,0xa0);
+       &LL(0xa9,0xa9,0x9e,0xa9,0x21,0x37,0x4f,0x88);
+       &LL(0x2a,0x2a,0xa8,0x2a,0x4d,0x82,0x54,0x67);
+       &LL(0xbb,0xbb,0xd6,0xbb,0xb1,0x6d,0x6b,0x0a);
+       &LL(0xc1,0xc1,0x23,0xc1,0x46,0xe2,0x9f,0x87);
+       &LL(0x53,0x53,0x51,0x53,0xa2,0x02,0xa6,0xf1);
+       &LL(0xdc,0xdc,0x57,0xdc,0xae,0x8b,0xa5,0x72);
+       &LL(0x0b,0x0b,0x2c,0x0b,0x58,0x27,0x16,0x53);
+       &LL(0x9d,0x9d,0x4e,0x9d,0x9c,0xd3,0x27,0x01);
+       &LL(0x6c,0x6c,0xad,0x6c,0x47,0xc1,0xd8,0x2b);
+       &LL(0x31,0x31,0xc4,0x31,0x95,0xf5,0x62,0xa4);
+       &LL(0x74,0x74,0xcd,0x74,0x87,0xb9,0xe8,0xf3);
+       &LL(0xf6,0xf6,0xff,0xf6,0xe3,0x09,0xf1,0x15);
+       &LL(0x46,0x46,0x05,0x46,0x0a,0x43,0x8c,0x4c);
+       &LL(0xac,0xac,0x8a,0xac,0x09,0x26,0x45,0xa5);
+       &LL(0x89,0x89,0x1e,0x89,0x3c,0x97,0x0f,0xb5);
+       &LL(0x14,0x14,0x50,0x14,0xa0,0x44,0x28,0xb4);
+       &LL(0xe1,0xe1,0xa3,0xe1,0x5b,0x42,0xdf,0xba);
+       &LL(0x16,0x16,0x58,0x16,0xb0,0x4e,0x2c,0xa6);
+       &LL(0x3a,0x3a,0xe8,0x3a,0xcd,0xd2,0x74,0xf7);
+       &LL(0x69,0x69,0xb9,0x69,0x6f,0xd0,0xd2,0x06);
+       &LL(0x09,0x09,0x24,0x09,0x48,0x2d,0x12,0x41);
+       &LL(0x70,0x70,0xdd,0x70,0xa7,0xad,0xe0,0xd7);
+       &LL(0xb6,0xb6,0xe2,0xb6,0xd9,0x54,0x71,0x6f);
+       &LL(0xd0,0xd0,0x67,0xd0,0xce,0xb7,0xbd,0x1e);
+       &LL(0xed,0xed,0x93,0xed,0x3b,0x7e,0xc7,0xd6);
+       &LL(0xcc,0xcc,0x17,0xcc,0x2e,0xdb,0x85,0xe2);
+       &LL(0x42,0x42,0x15,0x42,0x2a,0x57,0x84,0x68);
+       &LL(0x98,0x98,0x5a,0x98,0xb4,0xc2,0x2d,0x2c);
+       &LL(0xa4,0xa4,0xaa,0xa4,0x49,0x0e,0x55,0xed);
+       &LL(0x28,0x28,0xa0,0x28,0x5d,0x88,0x50,0x75);
+       &LL(0x5c,0x5c,0x6d,0x5c,0xda,0x31,0xb8,0x86);
+       &LL(0xf8,0xf8,0xc7,0xf8,0x93,0x3f,0xed,0x6b);
+       &LL(0x86,0x86,0x22,0x86,0x44,0xa4,0x11,0xc2);
+
+       &L(0x18,0x23,0xc6,0xe8,0x87,0xb8,0x01,0x4f);    # rc[ROUNDS]
+       &L(0x36,0xa6,0xd2,0xf5,0x79,0x6f,0x91,0x52);
+       &L(0x60,0xbc,0x9b,0x8e,0xa3,0x0c,0x7b,0x35);
+       &L(0x1d,0xe0,0xd7,0xc2,0x2e,0x4b,0xfe,0x57);
+       &L(0x15,0x77,0x37,0xe5,0x9f,0xf0,0x4a,0xda);
+       &L(0x58,0xc9,0x29,0x0a,0xb1,0xa0,0x6b,0x85);
+       &L(0xbd,0x5d,0x10,0xf4,0xcb,0x3e,0x05,0x67);
+       &L(0xe4,0x27,0x41,0x8b,0xa7,0x7d,0x95,0xd8);
+       &L(0xfb,0xee,0x7c,0x66,0xdd,0x17,0x47,0x9e);
+       &L(0xca,0x2d,0xbf,0x07,0xad,0x5a,0x83,0x33);
+
+# EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
+#              CONTEXT *context,DISPATCHER_CONTEXT *disp)
+if ($win64) {
+$rec="%rcx";
+$frame="%rdx";
+$context="%r8";
+$disp="%r9";
+
+$code.=<<___;
+.extern        __imp_RtlVirtualUnwind
+.type  se_handler,\@abi-omnipotent
+.align 16
+se_handler:
+       push    %rsi
+       push    %rdi
+       push    %rbx
+       push    %rbp
+       push    %r12
+       push    %r13
+       push    %r14
+       push    %r15
+       pushfq
+       sub     \$64,%rsp
+
+       mov     120($context),%rax      # pull context->Rax
+       mov     248($context),%rbx      # pull context->Rip
+
+       lea     .Lprologue(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip<.Lprologue
+       jb      .Lin_prologue
+
+       mov     152($context),%rax      # pull context->Rsp
+
+       lea     .Lepilogue(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip>=.Lepilogue
+       jae     .Lin_prologue
+
+       mov     128+32(%rax),%rax       # pull saved stack pointer
+       lea     48(%rax),%rax
+
+       mov     -8(%rax),%rbx
+       mov     -16(%rax),%rbp
+       mov     -24(%rax),%r12
+       mov     -32(%rax),%r13
+       mov     -40(%rax),%r14
+       mov     -48(%rax),%r15
+       mov     %rbx,144($context)      # restore context->Rbx
+       mov     %rbp,160($context)      # restore context->Rbp
+       mov     %r12,216($context)      # restore context->R12
+       mov     %r13,224($context)      # restore context->R13
+       mov     %r14,232($context)      # restore context->R14
+       mov     %r15,240($context)      # restore context->R15
+
+.Lin_prologue:
+       mov     8(%rax),%rdi
+       mov     16(%rax),%rsi
+       mov     %rax,152($context)      # restore context->Rsp
+       mov     %rsi,168($context)      # restore context->Rsi
+       mov     %rdi,176($context)      # restore context->Rdi
+
+       mov     40($disp),%rdi          # disp->ContextRecord
+       mov     $context,%rsi           # context
+       mov     \$154,%ecx              # sizeof(CONTEXT)
+       .long   0xa548f3fc              # cld; rep movsq
+
+       mov     $disp,%rsi
+       xor     %rcx,%rcx               # arg1, UNW_FLAG_NHANDLER
+       mov     8(%rsi),%rdx            # arg2, disp->ImageBase
+       mov     0(%rsi),%r8             # arg3, disp->ControlPc
+       mov     16(%rsi),%r9            # arg4, disp->FunctionEntry
+       mov     40(%rsi),%r10           # disp->ContextRecord
+       lea     56(%rsi),%r11           # &disp->HandlerData
+       lea     24(%rsi),%r12           # &disp->EstablisherFrame
+       mov     %r10,32(%rsp)           # arg5
+       mov     %r11,40(%rsp)           # arg6
+       mov     %r12,48(%rsp)           # arg7
+       mov     %rcx,56(%rsp)           # arg8, (NULL)
+       call    *__imp_RtlVirtualUnwind(%rip)
+
+       mov     \$1,%eax                # ExceptionContinueSearch
+       add     \$64,%rsp
+       popfq
+       pop     %r15
+       pop     %r14
+       pop     %r13
+       pop     %r12
+       pop     %rbp
+       pop     %rbx
+       pop     %rdi
+       pop     %rsi
+       ret
+.size  se_handler,.-se_handler
+
+.section       .pdata
+.align 4
+       .rva    .LSEH_begin_$func
+       .rva    .LSEH_end_$func
+       .rva    .LSEH_info_$func
+
+.section       .xdata
+.align 8
+.LSEH_info_$func:
+       .byte   9,0,0,0
+       .rva    se_handler
+___
+}
+
+$code =~ s/\`([^\`]*)\`/eval $1/gem;
+print $code;
+close STDOUT;
diff --git a/deps/openssl/openssl/crypto/whrlpool/whrlpool.h b/deps/openssl/openssl/crypto/whrlpool/whrlpool.h
new file mode 100644 (file)
index 0000000..03c91da
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef HEADER_WHRLPOOL_H
+#define HEADER_WHRLPOOL_H
+
+#include <openssl/e_os2.h>
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define WHIRLPOOL_DIGEST_LENGTH        (512/8)
+#define WHIRLPOOL_BBLOCK       512
+#define WHIRLPOOL_COUNTER      (256/8)
+
+typedef struct {
+       union   {
+               unsigned char   c[WHIRLPOOL_DIGEST_LENGTH];
+               /* double q is here to ensure 64-bit alignment */
+               double          q[WHIRLPOOL_DIGEST_LENGTH/sizeof(double)];
+               }       H;
+       unsigned char   data[WHIRLPOOL_BBLOCK/8];
+       unsigned int    bitoff;
+       size_t          bitlen[WHIRLPOOL_COUNTER/sizeof(size_t)];
+       } WHIRLPOOL_CTX;
+
+#ifndef OPENSSL_NO_WHIRLPOOL
+int WHIRLPOOL_Init     (WHIRLPOOL_CTX *c);
+int WHIRLPOOL_Update   (WHIRLPOOL_CTX *c,const void *inp,size_t bytes);
+void WHIRLPOOL_BitUpdate(WHIRLPOOL_CTX *c,const void *inp,size_t bits);
+int WHIRLPOOL_Final    (unsigned char *md,WHIRLPOOL_CTX *c);
+unsigned char *WHIRLPOOL(const void *inp,size_t bytes,unsigned char *md);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/deps/openssl/openssl/crypto/whrlpool/wp_block.c b/deps/openssl/openssl/crypto/whrlpool/wp_block.c
new file mode 100644 (file)
index 0000000..221f6cc
--- /dev/null
@@ -0,0 +1,655 @@
+/**
+ * The Whirlpool hashing function.
+ *
+ * <P>
+ * <b>References</b>
+ *
+ * <P>
+ * The Whirlpool algorithm was developed by
+ * <a href="mailto:pbarreto@scopus.com.br">Paulo S. L. M. Barreto</a> and
+ * <a href="mailto:vincent.rijmen@cryptomathic.com">Vincent Rijmen</a>.
+ *
+ * See
+ *      P.S.L.M. Barreto, V. Rijmen,
+ *      ``The Whirlpool hashing function,''
+ *      NESSIE submission, 2000 (tweaked version, 2001),
+ *      <https://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/whirlpool.zip>
+ *
+ * Based on "@version 3.0 (2003.03.12)" by Paulo S.L.M. Barreto and
+ * Vincent Rijmen. Lookup "reference implementations" on
+ * <http://planeta.terra.com.br/informatica/paulobarreto/>
+ *
+ * =============================================================================
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
+ * 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 AUTHORS OR 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 "wp_locl.h"
+#include <string.h>
+
+typedef unsigned char          u8;
+#if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32)
+typedef unsigned __int64       u64;
+#elif defined(__arch64__)
+typedef unsigned long          u64;
+#else
+typedef unsigned long long     u64;
+#endif
+
+#define ROUNDS 10
+
+#define STRICT_ALIGNMENT
+#if defined(__i386) || defined(__i386__) || \
+    defined(__x86_64) || defined(__x86_64__) || \
+    defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64)
+/* Well, formally there're couple of other architectures, which permit
+ * unaligned loads, specifically those not crossing cache lines, IA-64
+ * and PowerPC... */
+#  undef STRICT_ALIGNMENT
+#endif
+
+#undef SMALL_REGISTER_BANK
+#if defined(__i386) || defined(__i386__) || defined(_M_IX86)
+#  define SMALL_REGISTER_BANK
+#  if defined(WHIRLPOOL_ASM)
+#    ifndef OPENSSL_SMALL_FOOTPRINT
+#      define OPENSSL_SMALL_FOOTPRINT  /* it appears that for elder non-MMX
+                                          CPUs this is actually faster! */
+#    endif
+#    define GO_FOR_MMX(ctx,inp,num)    do {                    \
+       extern unsigned long OPENSSL_ia32cap_P;                 \
+       void whirlpool_block_mmx(void *,const void *,size_t);   \
+       if (!(OPENSSL_ia32cap_P & (1<<23)))     break;          \
+        whirlpool_block_mmx(ctx->H.c,inp,num); return;         \
+                                       } while (0)
+#  endif
+#endif
+
+#undef ROTATE
+#if defined(_MSC_VER)
+#  if defined(_WIN64)  /* applies to both IA-64 and AMD64 */
+#    pragma intrinsic(_rotl64)
+#    define ROTATE(a,n)        _rotl64((a),n)
+#  endif
+#elif defined(__GNUC__) && __GNUC__>=2
+#  if defined(__x86_64) || defined(__x86_64__)
+#    if defined(L_ENDIAN)
+#      define ROTATE(a,n)      ({ u64 ret; asm ("rolq %1,%0"   \
+                                  : "=r"(ret) : "J"(n),"0"(a) : "cc"); ret; })
+#    elif defined(B_ENDIAN)
+       /* Most will argue that x86_64 is always little-endian. Well,
+        * yes, but then we have stratus.com who has modified gcc to
+       * "emulate" big-endian on x86. Is there evidence that they
+       * [or somebody else] won't do same for x86_64? Naturally no.
+       * And this line is waiting ready for that brave soul:-) */
+#      define ROTATE(a,n)      ({ u64 ret; asm ("rorq %1,%0"   \
+                                  : "=r"(ret) : "J"(n),"0"(a) : "cc"); ret; })
+#    endif
+#  elif defined(__ia64) || defined(__ia64__)
+#    if defined(L_ENDIAN)
+#      define ROTATE(a,n)      ({ u64 ret; asm ("shrp %0=%1,%1,%2"     \
+                                  : "=r"(ret) : "r"(a),"M"(64-(n))); ret; })
+#    elif defined(B_ENDIAN)
+#      define ROTATE(a,n)      ({ u64 ret; asm ("shrp %0=%1,%1,%2"     \
+                                  : "=r"(ret) : "r"(a),"M"(n)); ret; })
+#    endif
+#  endif
+#endif
+
+#if defined(OPENSSL_SMALL_FOOTPRINT)
+#  if !defined(ROTATE)
+#    if defined(L_ENDIAN)      /* little-endians have to rotate left */
+#      define ROTATE(i,n)      ((i)<<(n) ^ (i)>>(64-n))
+#    elif defined(B_ENDIAN)    /* big-endians have to rotate right */
+#      define ROTATE(i,n)      ((i)>>(n) ^ (i)<<(64-n))
+#    endif
+#  endif
+#  if defined(ROTATE) && !defined(STRICT_ALIGNMENT)
+#    define STRICT_ALIGNMENT   /* ensure smallest table size */
+#  endif
+#endif
+
+/*
+ * Table size depends on STRICT_ALIGNMENT and whether or not endian-
+ * specific ROTATE macro is defined. If STRICT_ALIGNMENT is not
+ * defined, which is normally the case on x86[_64] CPUs, the table is
+ * 4KB large unconditionally. Otherwise if ROTATE is defined, the
+ * table is 2KB large, and otherwise - 16KB. 2KB table requires a
+ * whole bunch of additional rotations, but I'm willing to "trade,"
+ * because 16KB table certainly trashes L1 cache. I wish all CPUs
+ * could handle unaligned load as 4KB table doesn't trash the cache,
+ * nor does it require additional rotations.
+ */
+/*
+ * Note that every Cn macro expands as two loads: one byte load and
+ * one quadword load. One can argue that that many single-byte loads
+ * is too excessive, as one could load a quadword and "milk" it for
+ * eight 8-bit values instead. Well, yes, but in order to do so *and*
+ * avoid excessive loads you have to accomodate a handful of 64-bit
+ * values in the register bank and issue a bunch of shifts and mask.
+ * It's a tradeoff: loads vs. shift and mask in big register bank[!].
+ * On most CPUs eight single-byte loads are faster and I let other
+ * ones to depend on smart compiler to fold byte loads if beneficial.
+ * Hand-coded assembler would be another alternative:-)
+ */
+#ifdef STRICT_ALIGNMENT
+#  if defined(ROTATE)
+#    define N  1
+#    define LL(c0,c1,c2,c3,c4,c5,c6,c7)        c0,c1,c2,c3,c4,c5,c6,c7
+#    define C0(K,i)    (Cx.q[K.c[(i)*8+0]])
+#    define C1(K,i)    ROTATE(Cx.q[K.c[(i)*8+1]],8)
+#    define C2(K,i)    ROTATE(Cx.q[K.c[(i)*8+2]],16)
+#    define C3(K,i)    ROTATE(Cx.q[K.c[(i)*8+3]],24)
+#    define C4(K,i)    ROTATE(Cx.q[K.c[(i)*8+4]],32)
+#    define C5(K,i)    ROTATE(Cx.q[K.c[(i)*8+5]],40)
+#    define C6(K,i)    ROTATE(Cx.q[K.c[(i)*8+6]],48)
+#    define C7(K,i)    ROTATE(Cx.q[K.c[(i)*8+7]],56)
+#  else
+#    define N  8
+#    define LL(c0,c1,c2,c3,c4,c5,c6,c7)        c0,c1,c2,c3,c4,c5,c6,c7, \
+                                       c7,c0,c1,c2,c3,c4,c5,c6, \
+                                       c6,c7,c0,c1,c2,c3,c4,c5, \
+                                       c5,c6,c7,c0,c1,c2,c3,c4, \
+                                       c4,c5,c6,c7,c0,c1,c2,c3, \
+                                       c3,c4,c5,c6,c7,c0,c1,c2, \
+                                       c2,c3,c4,c5,c6,c7,c0,c1, \
+                                       c1,c2,c3,c4,c5,c6,c7,c0
+#    define C0(K,i)    (Cx.q[0+8*K.c[(i)*8+0]])
+#    define C1(K,i)    (Cx.q[1+8*K.c[(i)*8+1]])
+#    define C2(K,i)    (Cx.q[2+8*K.c[(i)*8+2]])
+#    define C3(K,i)    (Cx.q[3+8*K.c[(i)*8+3]])
+#    define C4(K,i)    (Cx.q[4+8*K.c[(i)*8+4]])
+#    define C5(K,i)    (Cx.q[5+8*K.c[(i)*8+5]])
+#    define C6(K,i)    (Cx.q[6+8*K.c[(i)*8+6]])
+#    define C7(K,i)    (Cx.q[7+8*K.c[(i)*8+7]])
+#  endif
+#else
+#  define N    2
+#  define LL(c0,c1,c2,c3,c4,c5,c6,c7)  c0,c1,c2,c3,c4,c5,c6,c7, \
+                                       c0,c1,c2,c3,c4,c5,c6,c7
+#  define C0(K,i)      (((u64*)(Cx.c+0))[2*K.c[(i)*8+0]])
+#  define C1(K,i)      (((u64*)(Cx.c+7))[2*K.c[(i)*8+1]])
+#  define C2(K,i)      (((u64*)(Cx.c+6))[2*K.c[(i)*8+2]])
+#  define C3(K,i)      (((u64*)(Cx.c+5))[2*K.c[(i)*8+3]])
+#  define C4(K,i)      (((u64*)(Cx.c+4))[2*K.c[(i)*8+4]])
+#  define C5(K,i)      (((u64*)(Cx.c+3))[2*K.c[(i)*8+5]])
+#  define C6(K,i)      (((u64*)(Cx.c+2))[2*K.c[(i)*8+6]])
+#  define C7(K,i)      (((u64*)(Cx.c+1))[2*K.c[(i)*8+7]])
+#endif
+
+static const
+union  {
+       u8      c[(256*N+ROUNDS)*sizeof(u64)];
+       u64     q[(256*N+ROUNDS)];
+       } Cx = { {
+       /* Note endian-neutral representation:-) */
+       LL(0x18,0x18,0x60,0x18,0xc0,0x78,0x30,0xd8),
+       LL(0x23,0x23,0x8c,0x23,0x05,0xaf,0x46,0x26),
+       LL(0xc6,0xc6,0x3f,0xc6,0x7e,0xf9,0x91,0xb8),
+       LL(0xe8,0xe8,0x87,0xe8,0x13,0x6f,0xcd,0xfb),
+       LL(0x87,0x87,0x26,0x87,0x4c,0xa1,0x13,0xcb),
+       LL(0xb8,0xb8,0xda,0xb8,0xa9,0x62,0x6d,0x11),
+       LL(0x01,0x01,0x04,0x01,0x08,0x05,0x02,0x09),
+       LL(0x4f,0x4f,0x21,0x4f,0x42,0x6e,0x9e,0x0d),
+       LL(0x36,0x36,0xd8,0x36,0xad,0xee,0x6c,0x9b),
+       LL(0xa6,0xa6,0xa2,0xa6,0x59,0x04,0x51,0xff),
+       LL(0xd2,0xd2,0x6f,0xd2,0xde,0xbd,0xb9,0x0c),
+       LL(0xf5,0xf5,0xf3,0xf5,0xfb,0x06,0xf7,0x0e),
+       LL(0x79,0x79,0xf9,0x79,0xef,0x80,0xf2,0x96),
+       LL(0x6f,0x6f,0xa1,0x6f,0x5f,0xce,0xde,0x30),
+       LL(0x91,0x91,0x7e,0x91,0xfc,0xef,0x3f,0x6d),
+       LL(0x52,0x52,0x55,0x52,0xaa,0x07,0xa4,0xf8),
+       LL(0x60,0x60,0x9d,0x60,0x27,0xfd,0xc0,0x47),
+       LL(0xbc,0xbc,0xca,0xbc,0x89,0x76,0x65,0x35),
+       LL(0x9b,0x9b,0x56,0x9b,0xac,0xcd,0x2b,0x37),
+       LL(0x8e,0x8e,0x02,0x8e,0x04,0x8c,0x01,0x8a),
+       LL(0xa3,0xa3,0xb6,0xa3,0x71,0x15,0x5b,0xd2),
+       LL(0x0c,0x0c,0x30,0x0c,0x60,0x3c,0x18,0x6c),
+       LL(0x7b,0x7b,0xf1,0x7b,0xff,0x8a,0xf6,0x84),
+       LL(0x35,0x35,0xd4,0x35,0xb5,0xe1,0x6a,0x80),
+       LL(0x1d,0x1d,0x74,0x1d,0xe8,0x69,0x3a,0xf5),
+       LL(0xe0,0xe0,0xa7,0xe0,0x53,0x47,0xdd,0xb3),
+       LL(0xd7,0xd7,0x7b,0xd7,0xf6,0xac,0xb3,0x21),
+       LL(0xc2,0xc2,0x2f,0xc2,0x5e,0xed,0x99,0x9c),
+       LL(0x2e,0x2e,0xb8,0x2e,0x6d,0x96,0x5c,0x43),
+       LL(0x4b,0x4b,0x31,0x4b,0x62,0x7a,0x96,0x29),
+       LL(0xfe,0xfe,0xdf,0xfe,0xa3,0x21,0xe1,0x5d),
+       LL(0x57,0x57,0x41,0x57,0x82,0x16,0xae,0xd5),
+       LL(0x15,0x15,0x54,0x15,0xa8,0x41,0x2a,0xbd),
+       LL(0x77,0x77,0xc1,0x77,0x9f,0xb6,0xee,0xe8),
+       LL(0x37,0x37,0xdc,0x37,0xa5,0xeb,0x6e,0x92),
+       LL(0xe5,0xe5,0xb3,0xe5,0x7b,0x56,0xd7,0x9e),
+       LL(0x9f,0x9f,0x46,0x9f,0x8c,0xd9,0x23,0x13),
+       LL(0xf0,0xf0,0xe7,0xf0,0xd3,0x17,0xfd,0x23),
+       LL(0x4a,0x4a,0x35,0x4a,0x6a,0x7f,0x94,0x20),
+       LL(0xda,0xda,0x4f,0xda,0x9e,0x95,0xa9,0x44),
+       LL(0x58,0x58,0x7d,0x58,0xfa,0x25,0xb0,0xa2),
+       LL(0xc9,0xc9,0x03,0xc9,0x06,0xca,0x8f,0xcf),
+       LL(0x29,0x29,0xa4,0x29,0x55,0x8d,0x52,0x7c),
+       LL(0x0a,0x0a,0x28,0x0a,0x50,0x22,0x14,0x5a),
+       LL(0xb1,0xb1,0xfe,0xb1,0xe1,0x4f,0x7f,0x50),
+       LL(0xa0,0xa0,0xba,0xa0,0x69,0x1a,0x5d,0xc9),
+       LL(0x6b,0x6b,0xb1,0x6b,0x7f,0xda,0xd6,0x14),
+       LL(0x85,0x85,0x2e,0x85,0x5c,0xab,0x17,0xd9),
+       LL(0xbd,0xbd,0xce,0xbd,0x81,0x73,0x67,0x3c),
+       LL(0x5d,0x5d,0x69,0x5d,0xd2,0x34,0xba,0x8f),
+       LL(0x10,0x10,0x40,0x10,0x80,0x50,0x20,0x90),
+       LL(0xf4,0xf4,0xf7,0xf4,0xf3,0x03,0xf5,0x07),
+       LL(0xcb,0xcb,0x0b,0xcb,0x16,0xc0,0x8b,0xdd),
+       LL(0x3e,0x3e,0xf8,0x3e,0xed,0xc6,0x7c,0xd3),
+       LL(0x05,0x05,0x14,0x05,0x28,0x11,0x0a,0x2d),
+       LL(0x67,0x67,0x81,0x67,0x1f,0xe6,0xce,0x78),
+       LL(0xe4,0xe4,0xb7,0xe4,0x73,0x53,0xd5,0x97),
+       LL(0x27,0x27,0x9c,0x27,0x25,0xbb,0x4e,0x02),
+       LL(0x41,0x41,0x19,0x41,0x32,0x58,0x82,0x73),
+       LL(0x8b,0x8b,0x16,0x8b,0x2c,0x9d,0x0b,0xa7),
+       LL(0xa7,0xa7,0xa6,0xa7,0x51,0x01,0x53,0xf6),
+       LL(0x7d,0x7d,0xe9,0x7d,0xcf,0x94,0xfa,0xb2),
+       LL(0x95,0x95,0x6e,0x95,0xdc,0xfb,0x37,0x49),
+       LL(0xd8,0xd8,0x47,0xd8,0x8e,0x9f,0xad,0x56),
+       LL(0xfb,0xfb,0xcb,0xfb,0x8b,0x30,0xeb,0x70),
+       LL(0xee,0xee,0x9f,0xee,0x23,0x71,0xc1,0xcd),
+       LL(0x7c,0x7c,0xed,0x7c,0xc7,0x91,0xf8,0xbb),
+       LL(0x66,0x66,0x85,0x66,0x17,0xe3,0xcc,0x71),
+       LL(0xdd,0xdd,0x53,0xdd,0xa6,0x8e,0xa7,0x7b),
+       LL(0x17,0x17,0x5c,0x17,0xb8,0x4b,0x2e,0xaf),
+       LL(0x47,0x47,0x01,0x47,0x02,0x46,0x8e,0x45),
+       LL(0x9e,0x9e,0x42,0x9e,0x84,0xdc,0x21,0x1a),
+       LL(0xca,0xca,0x0f,0xca,0x1e,0xc5,0x89,0xd4),
+       LL(0x2d,0x2d,0xb4,0x2d,0x75,0x99,0x5a,0x58),
+       LL(0xbf,0xbf,0xc6,0xbf,0x91,0x79,0x63,0x2e),
+       LL(0x07,0x07,0x1c,0x07,0x38,0x1b,0x0e,0x3f),
+       LL(0xad,0xad,0x8e,0xad,0x01,0x23,0x47,0xac),
+       LL(0x5a,0x5a,0x75,0x5a,0xea,0x2f,0xb4,0xb0),
+       LL(0x83,0x83,0x36,0x83,0x6c,0xb5,0x1b,0xef),
+       LL(0x33,0x33,0xcc,0x33,0x85,0xff,0x66,0xb6),
+       LL(0x63,0x63,0x91,0x63,0x3f,0xf2,0xc6,0x5c),
+       LL(0x02,0x02,0x08,0x02,0x10,0x0a,0x04,0x12),
+       LL(0xaa,0xaa,0x92,0xaa,0x39,0x38,0x49,0x93),
+       LL(0x71,0x71,0xd9,0x71,0xaf,0xa8,0xe2,0xde),
+       LL(0xc8,0xc8,0x07,0xc8,0x0e,0xcf,0x8d,0xc6),
+       LL(0x19,0x19,0x64,0x19,0xc8,0x7d,0x32,0xd1),
+       LL(0x49,0x49,0x39,0x49,0x72,0x70,0x92,0x3b),
+       LL(0xd9,0xd9,0x43,0xd9,0x86,0x9a,0xaf,0x5f),
+       LL(0xf2,0xf2,0xef,0xf2,0xc3,0x1d,0xf9,0x31),
+       LL(0xe3,0xe3,0xab,0xe3,0x4b,0x48,0xdb,0xa8),
+       LL(0x5b,0x5b,0x71,0x5b,0xe2,0x2a,0xb6,0xb9),
+       LL(0x88,0x88,0x1a,0x88,0x34,0x92,0x0d,0xbc),
+       LL(0x9a,0x9a,0x52,0x9a,0xa4,0xc8,0x29,0x3e),
+       LL(0x26,0x26,0x98,0x26,0x2d,0xbe,0x4c,0x0b),
+       LL(0x32,0x32,0xc8,0x32,0x8d,0xfa,0x64,0xbf),
+       LL(0xb0,0xb0,0xfa,0xb0,0xe9,0x4a,0x7d,0x59),
+       LL(0xe9,0xe9,0x83,0xe9,0x1b,0x6a,0xcf,0xf2),
+       LL(0x0f,0x0f,0x3c,0x0f,0x78,0x33,0x1e,0x77),
+       LL(0xd5,0xd5,0x73,0xd5,0xe6,0xa6,0xb7,0x33),
+       LL(0x80,0x80,0x3a,0x80,0x74,0xba,0x1d,0xf4),
+       LL(0xbe,0xbe,0xc2,0xbe,0x99,0x7c,0x61,0x27),
+       LL(0xcd,0xcd,0x13,0xcd,0x26,0xde,0x87,0xeb),
+       LL(0x34,0x34,0xd0,0x34,0xbd,0xe4,0x68,0x89),
+       LL(0x48,0x48,0x3d,0x48,0x7a,0x75,0x90,0x32),
+       LL(0xff,0xff,0xdb,0xff,0xab,0x24,0xe3,0x54),
+       LL(0x7a,0x7a,0xf5,0x7a,0xf7,0x8f,0xf4,0x8d),
+       LL(0x90,0x90,0x7a,0x90,0xf4,0xea,0x3d,0x64),
+       LL(0x5f,0x5f,0x61,0x5f,0xc2,0x3e,0xbe,0x9d),
+       LL(0x20,0x20,0x80,0x20,0x1d,0xa0,0x40,0x3d),
+       LL(0x68,0x68,0xbd,0x68,0x67,0xd5,0xd0,0x0f),
+       LL(0x1a,0x1a,0x68,0x1a,0xd0,0x72,0x34,0xca),
+       LL(0xae,0xae,0x82,0xae,0x19,0x2c,0x41,0xb7),
+       LL(0xb4,0xb4,0xea,0xb4,0xc9,0x5e,0x75,0x7d),
+       LL(0x54,0x54,0x4d,0x54,0x9a,0x19,0xa8,0xce),
+       LL(0x93,0x93,0x76,0x93,0xec,0xe5,0x3b,0x7f),
+       LL(0x22,0x22,0x88,0x22,0x0d,0xaa,0x44,0x2f),
+       LL(0x64,0x64,0x8d,0x64,0x07,0xe9,0xc8,0x63),
+       LL(0xf1,0xf1,0xe3,0xf1,0xdb,0x12,0xff,0x2a),
+       LL(0x73,0x73,0xd1,0x73,0xbf,0xa2,0xe6,0xcc),
+       LL(0x12,0x12,0x48,0x12,0x90,0x5a,0x24,0x82),
+       LL(0x40,0x40,0x1d,0x40,0x3a,0x5d,0x80,0x7a),
+       LL(0x08,0x08,0x20,0x08,0x40,0x28,0x10,0x48),
+       LL(0xc3,0xc3,0x2b,0xc3,0x56,0xe8,0x9b,0x95),
+       LL(0xec,0xec,0x97,0xec,0x33,0x7b,0xc5,0xdf),
+       LL(0xdb,0xdb,0x4b,0xdb,0x96,0x90,0xab,0x4d),
+       LL(0xa1,0xa1,0xbe,0xa1,0x61,0x1f,0x5f,0xc0),
+       LL(0x8d,0x8d,0x0e,0x8d,0x1c,0x83,0x07,0x91),
+       LL(0x3d,0x3d,0xf4,0x3d,0xf5,0xc9,0x7a,0xc8),
+       LL(0x97,0x97,0x66,0x97,0xcc,0xf1,0x33,0x5b),
+       LL(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),
+       LL(0xcf,0xcf,0x1b,0xcf,0x36,0xd4,0x83,0xf9),
+       LL(0x2b,0x2b,0xac,0x2b,0x45,0x87,0x56,0x6e),
+       LL(0x76,0x76,0xc5,0x76,0x97,0xb3,0xec,0xe1),
+       LL(0x82,0x82,0x32,0x82,0x64,0xb0,0x19,0xe6),
+       LL(0xd6,0xd6,0x7f,0xd6,0xfe,0xa9,0xb1,0x28),
+       LL(0x1b,0x1b,0x6c,0x1b,0xd8,0x77,0x36,0xc3),
+       LL(0xb5,0xb5,0xee,0xb5,0xc1,0x5b,0x77,0x74),
+       LL(0xaf,0xaf,0x86,0xaf,0x11,0x29,0x43,0xbe),
+       LL(0x6a,0x6a,0xb5,0x6a,0x77,0xdf,0xd4,0x1d),
+       LL(0x50,0x50,0x5d,0x50,0xba,0x0d,0xa0,0xea),
+       LL(0x45,0x45,0x09,0x45,0x12,0x4c,0x8a,0x57),
+       LL(0xf3,0xf3,0xeb,0xf3,0xcb,0x18,0xfb,0x38),
+       LL(0x30,0x30,0xc0,0x30,0x9d,0xf0,0x60,0xad),
+       LL(0xef,0xef,0x9b,0xef,0x2b,0x74,0xc3,0xc4),
+       LL(0x3f,0x3f,0xfc,0x3f,0xe5,0xc3,0x7e,0xda),
+       LL(0x55,0x55,0x49,0x55,0x92,0x1c,0xaa,0xc7),
+       LL(0xa2,0xa2,0xb2,0xa2,0x79,0x10,0x59,0xdb),
+       LL(0xea,0xea,0x8f,0xea,0x03,0x65,0xc9,0xe9),
+       LL(0x65,0x65,0x89,0x65,0x0f,0xec,0xca,0x6a),
+       LL(0xba,0xba,0xd2,0xba,0xb9,0x68,0x69,0x03),
+       LL(0x2f,0x2f,0xbc,0x2f,0x65,0x93,0x5e,0x4a),
+       LL(0xc0,0xc0,0x27,0xc0,0x4e,0xe7,0x9d,0x8e),
+       LL(0xde,0xde,0x5f,0xde,0xbe,0x81,0xa1,0x60),
+       LL(0x1c,0x1c,0x70,0x1c,0xe0,0x6c,0x38,0xfc),
+       LL(0xfd,0xfd,0xd3,0xfd,0xbb,0x2e,0xe7,0x46),
+       LL(0x4d,0x4d,0x29,0x4d,0x52,0x64,0x9a,0x1f),
+       LL(0x92,0x92,0x72,0x92,0xe4,0xe0,0x39,0x76),
+       LL(0x75,0x75,0xc9,0x75,0x8f,0xbc,0xea,0xfa),
+       LL(0x06,0x06,0x18,0x06,0x30,0x1e,0x0c,0x36),
+       LL(0x8a,0x8a,0x12,0x8a,0x24,0x98,0x09,0xae),
+       LL(0xb2,0xb2,0xf2,0xb2,0xf9,0x40,0x79,0x4b),
+       LL(0xe6,0xe6,0xbf,0xe6,0x63,0x59,0xd1,0x85),
+       LL(0x0e,0x0e,0x38,0x0e,0x70,0x36,0x1c,0x7e),
+       LL(0x1f,0x1f,0x7c,0x1f,0xf8,0x63,0x3e,0xe7),
+       LL(0x62,0x62,0x95,0x62,0x37,0xf7,0xc4,0x55),
+       LL(0xd4,0xd4,0x77,0xd4,0xee,0xa3,0xb5,0x3a),
+       LL(0xa8,0xa8,0x9a,0xa8,0x29,0x32,0x4d,0x81),
+       LL(0x96,0x96,0x62,0x96,0xc4,0xf4,0x31,0x52),
+       LL(0xf9,0xf9,0xc3,0xf9,0x9b,0x3a,0xef,0x62),
+       LL(0xc5,0xc5,0x33,0xc5,0x66,0xf6,0x97,0xa3),
+       LL(0x25,0x25,0x94,0x25,0x35,0xb1,0x4a,0x10),
+       LL(0x59,0x59,0x79,0x59,0xf2,0x20,0xb2,0xab),
+       LL(0x84,0x84,0x2a,0x84,0x54,0xae,0x15,0xd0),
+       LL(0x72,0x72,0xd5,0x72,0xb7,0xa7,0xe4,0xc5),
+       LL(0x39,0x39,0xe4,0x39,0xd5,0xdd,0x72,0xec),
+       LL(0x4c,0x4c,0x2d,0x4c,0x5a,0x61,0x98,0x16),
+       LL(0x5e,0x5e,0x65,0x5e,0xca,0x3b,0xbc,0x94),
+       LL(0x78,0x78,0xfd,0x78,0xe7,0x85,0xf0,0x9f),
+       LL(0x38,0x38,0xe0,0x38,0xdd,0xd8,0x70,0xe5),
+       LL(0x8c,0x8c,0x0a,0x8c,0x14,0x86,0x05,0x98),
+       LL(0xd1,0xd1,0x63,0xd1,0xc6,0xb2,0xbf,0x17),
+       LL(0xa5,0xa5,0xae,0xa5,0x41,0x0b,0x57,0xe4),
+       LL(0xe2,0xe2,0xaf,0xe2,0x43,0x4d,0xd9,0xa1),
+       LL(0x61,0x61,0x99,0x61,0x2f,0xf8,0xc2,0x4e),
+       LL(0xb3,0xb3,0xf6,0xb3,0xf1,0x45,0x7b,0x42),
+       LL(0x21,0x21,0x84,0x21,0x15,0xa5,0x42,0x34),
+       LL(0x9c,0x9c,0x4a,0x9c,0x94,0xd6,0x25,0x08),
+       LL(0x1e,0x1e,0x78,0x1e,0xf0,0x66,0x3c,0xee),
+       LL(0x43,0x43,0x11,0x43,0x22,0x52,0x86,0x61),
+       LL(0xc7,0xc7,0x3b,0xc7,0x76,0xfc,0x93,0xb1),
+       LL(0xfc,0xfc,0xd7,0xfc,0xb3,0x2b,0xe5,0x4f),
+       LL(0x04,0x04,0x10,0x04,0x20,0x14,0x08,0x24),
+       LL(0x51,0x51,0x59,0x51,0xb2,0x08,0xa2,0xe3),
+       LL(0x99,0x99,0x5e,0x99,0xbc,0xc7,0x2f,0x25),
+       LL(0x6d,0x6d,0xa9,0x6d,0x4f,0xc4,0xda,0x22),
+       LL(0x0d,0x0d,0x34,0x0d,0x68,0x39,0x1a,0x65),
+       LL(0xfa,0xfa,0xcf,0xfa,0x83,0x35,0xe9,0x79),
+       LL(0xdf,0xdf,0x5b,0xdf,0xb6,0x84,0xa3,0x69),
+       LL(0x7e,0x7e,0xe5,0x7e,0xd7,0x9b,0xfc,0xa9),
+       LL(0x24,0x24,0x90,0x24,0x3d,0xb4,0x48,0x19),
+       LL(0x3b,0x3b,0xec,0x3b,0xc5,0xd7,0x76,0xfe),
+       LL(0xab,0xab,0x96,0xab,0x31,0x3d,0x4b,0x9a),
+       LL(0xce,0xce,0x1f,0xce,0x3e,0xd1,0x81,0xf0),
+       LL(0x11,0x11,0x44,0x11,0x88,0x55,0x22,0x99),
+       LL(0x8f,0x8f,0x06,0x8f,0x0c,0x89,0x03,0x83),
+       LL(0x4e,0x4e,0x25,0x4e,0x4a,0x6b,0x9c,0x04),
+       LL(0xb7,0xb7,0xe6,0xb7,0xd1,0x51,0x73,0x66),
+       LL(0xeb,0xeb,0x8b,0xeb,0x0b,0x60,0xcb,0xe0),
+       LL(0x3c,0x3c,0xf0,0x3c,0xfd,0xcc,0x78,0xc1),
+       LL(0x81,0x81,0x3e,0x81,0x7c,0xbf,0x1f,0xfd),
+       LL(0x94,0x94,0x6a,0x94,0xd4,0xfe,0x35,0x40),
+       LL(0xf7,0xf7,0xfb,0xf7,0xeb,0x0c,0xf3,0x1c),
+       LL(0xb9,0xb9,0xde,0xb9,0xa1,0x67,0x6f,0x18),
+       LL(0x13,0x13,0x4c,0x13,0x98,0x5f,0x26,0x8b),
+       LL(0x2c,0x2c,0xb0,0x2c,0x7d,0x9c,0x58,0x51),
+       LL(0xd3,0xd3,0x6b,0xd3,0xd6,0xb8,0xbb,0x05),
+       LL(0xe7,0xe7,0xbb,0xe7,0x6b,0x5c,0xd3,0x8c),
+       LL(0x6e,0x6e,0xa5,0x6e,0x57,0xcb,0xdc,0x39),
+       LL(0xc4,0xc4,0x37,0xc4,0x6e,0xf3,0x95,0xaa),
+       LL(0x03,0x03,0x0c,0x03,0x18,0x0f,0x06,0x1b),
+       LL(0x56,0x56,0x45,0x56,0x8a,0x13,0xac,0xdc),
+       LL(0x44,0x44,0x0d,0x44,0x1a,0x49,0x88,0x5e),
+       LL(0x7f,0x7f,0xe1,0x7f,0xdf,0x9e,0xfe,0xa0),
+       LL(0xa9,0xa9,0x9e,0xa9,0x21,0x37,0x4f,0x88),
+       LL(0x2a,0x2a,0xa8,0x2a,0x4d,0x82,0x54,0x67),
+       LL(0xbb,0xbb,0xd6,0xbb,0xb1,0x6d,0x6b,0x0a),
+       LL(0xc1,0xc1,0x23,0xc1,0x46,0xe2,0x9f,0x87),
+       LL(0x53,0x53,0x51,0x53,0xa2,0x02,0xa6,0xf1),
+       LL(0xdc,0xdc,0x57,0xdc,0xae,0x8b,0xa5,0x72),
+       LL(0x0b,0x0b,0x2c,0x0b,0x58,0x27,0x16,0x53),
+       LL(0x9d,0x9d,0x4e,0x9d,0x9c,0xd3,0x27,0x01),
+       LL(0x6c,0x6c,0xad,0x6c,0x47,0xc1,0xd8,0x2b),
+       LL(0x31,0x31,0xc4,0x31,0x95,0xf5,0x62,0xa4),
+       LL(0x74,0x74,0xcd,0x74,0x87,0xb9,0xe8,0xf3),
+       LL(0xf6,0xf6,0xff,0xf6,0xe3,0x09,0xf1,0x15),
+       LL(0x46,0x46,0x05,0x46,0x0a,0x43,0x8c,0x4c),
+       LL(0xac,0xac,0x8a,0xac,0x09,0x26,0x45,0xa5),
+       LL(0x89,0x89,0x1e,0x89,0x3c,0x97,0x0f,0xb5),
+       LL(0x14,0x14,0x50,0x14,0xa0,0x44,0x28,0xb4),
+       LL(0xe1,0xe1,0xa3,0xe1,0x5b,0x42,0xdf,0xba),
+       LL(0x16,0x16,0x58,0x16,0xb0,0x4e,0x2c,0xa6),
+       LL(0x3a,0x3a,0xe8,0x3a,0xcd,0xd2,0x74,0xf7),
+       LL(0x69,0x69,0xb9,0x69,0x6f,0xd0,0xd2,0x06),
+       LL(0x09,0x09,0x24,0x09,0x48,0x2d,0x12,0x41),
+       LL(0x70,0x70,0xdd,0x70,0xa7,0xad,0xe0,0xd7),
+       LL(0xb6,0xb6,0xe2,0xb6,0xd9,0x54,0x71,0x6f),
+       LL(0xd0,0xd0,0x67,0xd0,0xce,0xb7,0xbd,0x1e),
+       LL(0xed,0xed,0x93,0xed,0x3b,0x7e,0xc7,0xd6),
+       LL(0xcc,0xcc,0x17,0xcc,0x2e,0xdb,0x85,0xe2),
+       LL(0x42,0x42,0x15,0x42,0x2a,0x57,0x84,0x68),
+       LL(0x98,0x98,0x5a,0x98,0xb4,0xc2,0x2d,0x2c),
+       LL(0xa4,0xa4,0xaa,0xa4,0x49,0x0e,0x55,0xed),
+       LL(0x28,0x28,0xa0,0x28,0x5d,0x88,0x50,0x75),
+       LL(0x5c,0x5c,0x6d,0x5c,0xda,0x31,0xb8,0x86),
+       LL(0xf8,0xf8,0xc7,0xf8,0x93,0x3f,0xed,0x6b),
+       LL(0x86,0x86,0x22,0x86,0x44,0xa4,0x11,0xc2),
+#define RC     (&(Cx.q[256*N]))
+       0x18,0x23,0xc6,0xe8,0x87,0xb8,0x01,0x4f,        /* rc[ROUNDS] */
+       0x36,0xa6,0xd2,0xf5,0x79,0x6f,0x91,0x52,
+       0x60,0xbc,0x9b,0x8e,0xa3,0x0c,0x7b,0x35,
+       0x1d,0xe0,0xd7,0xc2,0x2e,0x4b,0xfe,0x57,
+       0x15,0x77,0x37,0xe5,0x9f,0xf0,0x4a,0xda,
+       0x58,0xc9,0x29,0x0a,0xb1,0xa0,0x6b,0x85,
+       0xbd,0x5d,0x10,0xf4,0xcb,0x3e,0x05,0x67,
+       0xe4,0x27,0x41,0x8b,0xa7,0x7d,0x95,0xd8,
+       0xfb,0xee,0x7c,0x66,0xdd,0x17,0x47,0x9e,
+       0xca,0x2d,0xbf,0x07,0xad,0x5a,0x83,0x33
+       }
+};
+
+void whirlpool_block(WHIRLPOOL_CTX *ctx,const void *inp,size_t n)
+       {
+       int     r;
+       const u8 *p=inp;
+       union   { u64 q[8]; u8 c[64]; } S,K,*H=(void *)ctx->H.q;
+
+#ifdef GO_FOR_MMX
+       GO_FOR_MMX(ctx,inp,n);
+#endif
+                                                       do {
+#ifdef OPENSSL_SMALL_FOOTPRINT
+       u64     L[8];
+       int     i;
+
+       for (i=0;i<64;i++)      S.c[i] = (K.c[i] = H->c[i]) ^ p[i];
+       for (r=0;r<ROUNDS;r++)
+               {
+               for (i=0;i<8;i++)
+                       {
+                       L[i]  = i ? 0 : RC[r];
+                       L[i] ^= C0(K,i)       ^ C1(K,(i-1)&7) ^
+                               C2(K,(i-2)&7) ^ C3(K,(i-3)&7) ^
+                               C4(K,(i-4)&7) ^ C5(K,(i-5)&7) ^
+                               C6(K,(i-6)&7) ^ C7(K,(i-7)&7);
+                       }
+               memcpy (K.q,L,64);
+               for (i=0;i<8;i++)
+                       {
+                       L[i] ^= C0(S,i)       ^ C1(S,(i-1)&7) ^
+                               C2(S,(i-2)&7) ^ C3(S,(i-3)&7) ^
+                               C4(S,(i-4)&7) ^ C5(S,(i-5)&7) ^
+                               C6(S,(i-6)&7) ^ C7(S,(i-7)&7);
+                       }
+               memcpy (S.q,L,64);
+               }
+       for (i=0;i<64;i++)      H->c[i] ^= S.c[i] ^ p[i];
+#else
+       u64     L0,L1,L2,L3,L4,L5,L6,L7;
+
+#ifdef STRICT_ALIGNMENT
+       if ((size_t)p & 7)
+               {
+               memcpy (S.c,p,64);
+               S.q[0] ^= (K.q[0] = H->q[0]);
+               S.q[1] ^= (K.q[1] = H->q[1]);
+               S.q[2] ^= (K.q[2] = H->q[2]);
+               S.q[3] ^= (K.q[3] = H->q[3]);
+               S.q[4] ^= (K.q[4] = H->q[4]);
+               S.q[5] ^= (K.q[5] = H->q[5]);
+               S.q[6] ^= (K.q[6] = H->q[6]);
+               S.q[7] ^= (K.q[7] = H->q[7]);
+               }
+       else
+#endif
+               {
+               const u64 *pa = (const u64*)p;
+               S.q[0] = (K.q[0] = H->q[0]) ^ pa[0];
+               S.q[1] = (K.q[1] = H->q[1]) ^ pa[1];
+               S.q[2] = (K.q[2] = H->q[2]) ^ pa[2];
+               S.q[3] = (K.q[3] = H->q[3]) ^ pa[3];
+               S.q[4] = (K.q[4] = H->q[4]) ^ pa[4];
+               S.q[5] = (K.q[5] = H->q[5]) ^ pa[5];
+               S.q[6] = (K.q[6] = H->q[6]) ^ pa[6];
+               S.q[7] = (K.q[7] = H->q[7]) ^ pa[7];
+               }
+
+       for(r=0;r<ROUNDS;r++)
+               {
+#ifdef SMALL_REGISTER_BANK
+               L0 =    C0(K,0) ^ C1(K,7) ^ C2(K,6) ^ C3(K,5) ^
+                       C4(K,4) ^ C5(K,3) ^ C6(K,2) ^ C7(K,1) ^ RC[r];
+               L1 =    C0(K,1) ^ C1(K,0) ^ C2(K,7) ^ C3(K,6) ^
+                       C4(K,5) ^ C5(K,4) ^ C6(K,3) ^ C7(K,2);
+               L2 =    C0(K,2) ^ C1(K,1) ^ C2(K,0) ^ C3(K,7) ^
+                       C4(K,6) ^ C5(K,5) ^ C6(K,4) ^ C7(K,3);
+               L3 =    C0(K,3) ^ C1(K,2) ^ C2(K,1) ^ C3(K,0) ^
+                       C4(K,7) ^ C5(K,6) ^ C6(K,5) ^ C7(K,4);
+               L4 =    C0(K,4) ^ C1(K,3) ^ C2(K,2) ^ C3(K,1) ^
+                       C4(K,0) ^ C5(K,7) ^ C6(K,6) ^ C7(K,5);
+               L5 =    C0(K,5) ^ C1(K,4) ^ C2(K,3) ^ C3(K,2) ^
+                       C4(K,1) ^ C5(K,0) ^ C6(K,7) ^ C7(K,6);
+               L6 =    C0(K,6) ^ C1(K,5) ^ C2(K,4) ^ C3(K,3) ^
+                       C4(K,2) ^ C5(K,1) ^ C6(K,0) ^ C7(K,7);
+               L7 =    C0(K,7) ^ C1(K,6) ^ C2(K,5) ^ C3(K,4) ^
+                       C4(K,3) ^ C5(K,2) ^ C6(K,1) ^ C7(K,0);
+
+               K.q[0] = L0; K.q[1] = L1; K.q[2] = L2; K.q[3] = L3;
+               K.q[4] = L4; K.q[5] = L5; K.q[6] = L6; K.q[7] = L7;
+
+               L0 ^=   C0(S,0) ^ C1(S,7) ^ C2(S,6) ^ C3(S,5) ^
+                       C4(S,4) ^ C5(S,3) ^ C6(S,2) ^ C7(S,1);
+               L1 ^=   C0(S,1) ^ C1(S,0) ^ C2(S,7) ^ C3(S,6) ^
+                       C4(S,5) ^ C5(S,4) ^ C6(S,3) ^ C7(S,2);
+               L2 ^=   C0(S,2) ^ C1(S,1) ^ C2(S,0) ^ C3(S,7) ^
+                       C4(S,6) ^ C5(S,5) ^ C6(S,4) ^ C7(S,3);
+               L3 ^=   C0(S,3) ^ C1(S,2) ^ C2(S,1) ^ C3(S,0) ^
+                       C4(S,7) ^ C5(S,6) ^ C6(S,5) ^ C7(S,4);
+               L4 ^=   C0(S,4) ^ C1(S,3) ^ C2(S,2) ^ C3(S,1) ^
+                       C4(S,0) ^ C5(S,7) ^ C6(S,6) ^ C7(S,5);
+               L5 ^=   C0(S,5) ^ C1(S,4) ^ C2(S,3) ^ C3(S,2) ^
+                       C4(S,1) ^ C5(S,0) ^ C6(S,7) ^ C7(S,6);
+               L6 ^=   C0(S,6) ^ C1(S,5) ^ C2(S,4) ^ C3(S,3) ^
+                       C4(S,2) ^ C5(S,1) ^ C6(S,0) ^ C7(S,7);
+               L7 ^=   C0(S,7) ^ C1(S,6) ^ C2(S,5) ^ C3(S,4) ^
+                       C4(S,3) ^ C5(S,2) ^ C6(S,1) ^ C7(S,0);
+
+               S.q[0] = L0; S.q[1] = L1; S.q[2] = L2; S.q[3] = L3;
+               S.q[4] = L4; S.q[5] = L5; S.q[6] = L6; S.q[7] = L7;
+#else
+               L0  = C0(K,0); L1  = C1(K,0); L2  = C2(K,0); L3  = C3(K,0);
+               L4  = C4(K,0); L5  = C5(K,0); L6  = C6(K,0); L7  = C7(K,0);
+               L0 ^= RC[r];
+
+               L1 ^= C0(K,1); L2 ^= C1(K,1); L3 ^= C2(K,1); L4 ^= C3(K,1);
+               L5 ^= C4(K,1); L6 ^= C5(K,1); L7 ^= C6(K,1); L0 ^= C7(K,1);
+
+               L2 ^= C0(K,2); L3 ^= C1(K,2); L4 ^= C2(K,2); L5 ^= C3(K,2);
+               L6 ^= C4(K,2); L7 ^= C5(K,2); L0 ^= C6(K,2); L1 ^= C7(K,2);
+
+               L3 ^= C0(K,3); L4 ^= C1(K,3); L5 ^= C2(K,3); L6 ^= C3(K,3);
+               L7 ^= C4(K,3); L0 ^= C5(K,3); L1 ^= C6(K,3); L2 ^= C7(K,3);
+
+               L4 ^= C0(K,4); L5 ^= C1(K,4); L6 ^= C2(K,4); L7 ^= C3(K,4);
+               L0 ^= C4(K,4); L1 ^= C5(K,4); L2 ^= C6(K,4); L3 ^= C7(K,4);
+
+               L5 ^= C0(K,5); L6 ^= C1(K,5); L7 ^= C2(K,5); L0 ^= C3(K,5);
+               L1 ^= C4(K,5); L2 ^= C5(K,5); L3 ^= C6(K,5); L4 ^= C7(K,5);
+
+               L6 ^= C0(K,6); L7 ^= C1(K,6); L0 ^= C2(K,6); L1 ^= C3(K,6);
+               L2 ^= C4(K,6); L3 ^= C5(K,6); L4 ^= C6(K,6); L5 ^= C7(K,6);
+
+               L7 ^= C0(K,7); L0 ^= C1(K,7); L1 ^= C2(K,7); L2 ^= C3(K,7);
+               L3 ^= C4(K,7); L4 ^= C5(K,7); L5 ^= C6(K,7); L6 ^= C7(K,7);
+
+               K.q[0] = L0; K.q[1] = L1; K.q[2] = L2; K.q[3] = L3;
+               K.q[4] = L4; K.q[5] = L5; K.q[6] = L6; K.q[7] = L7;
+
+               L0 ^= C0(S,0); L1 ^= C1(S,0); L2 ^= C2(S,0); L3 ^= C3(S,0);
+               L4 ^= C4(S,0); L5 ^= C5(S,0); L6 ^= C6(S,0); L7 ^= C7(S,0);
+
+               L1 ^= C0(S,1); L2 ^= C1(S,1); L3 ^= C2(S,1); L4 ^= C3(S,1);
+               L5 ^= C4(S,1); L6 ^= C5(S,1); L7 ^= C6(S,1); L0 ^= C7(S,1);
+
+               L2 ^= C0(S,2); L3 ^= C1(S,2); L4 ^= C2(S,2); L5 ^= C3(S,2);
+               L6 ^= C4(S,2); L7 ^= C5(S,2); L0 ^= C6(S,2); L1 ^= C7(S,2);
+
+               L3 ^= C0(S,3); L4 ^= C1(S,3); L5 ^= C2(S,3); L6 ^= C3(S,3);
+               L7 ^= C4(S,3); L0 ^= C5(S,3); L1 ^= C6(S,3); L2 ^= C7(S,3);
+
+               L4 ^= C0(S,4); L5 ^= C1(S,4); L6 ^= C2(S,4); L7 ^= C3(S,4);
+               L0 ^= C4(S,4); L1 ^= C5(S,4); L2 ^= C6(S,4); L3 ^= C7(S,4);
+
+               L5 ^= C0(S,5); L6 ^= C1(S,5); L7 ^= C2(S,5); L0 ^= C3(S,5);
+               L1 ^= C4(S,5); L2 ^= C5(S,5); L3 ^= C6(S,5); L4 ^= C7(S,5);
+
+               L6 ^= C0(S,6); L7 ^= C1(S,6); L0 ^= C2(S,6); L1 ^= C3(S,6);
+               L2 ^= C4(S,6); L3 ^= C5(S,6); L4 ^= C6(S,6); L5 ^= C7(S,6);
+
+               L7 ^= C0(S,7); L0 ^= C1(S,7); L1 ^= C2(S,7); L2 ^= C3(S,7);
+               L3 ^= C4(S,7); L4 ^= C5(S,7); L5 ^= C6(S,7); L6 ^= C7(S,7);
+
+               S.q[0] = L0; S.q[1] = L1; S.q[2] = L2; S.q[3] = L3;
+               S.q[4] = L4; S.q[5] = L5; S.q[6] = L6; S.q[7] = L7;
+#endif
+               }
+
+#ifdef STRICT_ALIGNMENT
+       if ((size_t)p & 7)
+               {
+               int i;
+               for(i=0;i<64;i++)       H->c[i] ^= S.c[i] ^ p[i];
+               }
+       else
+#endif
+               {
+               const u64 *pa=(const u64 *)p;
+               H->q[0] ^= S.q[0] ^ pa[0];
+               H->q[1] ^= S.q[1] ^ pa[1];
+               H->q[2] ^= S.q[2] ^ pa[2];
+               H->q[3] ^= S.q[3] ^ pa[3];
+               H->q[4] ^= S.q[4] ^ pa[4];
+               H->q[5] ^= S.q[5] ^ pa[5];
+               H->q[6] ^= S.q[6] ^ pa[6];
+               H->q[7] ^= S.q[7] ^ pa[7];
+               }
+#endif
+                                                       p += 64;
+                                                       } while(--n);
+       }
diff --git a/deps/openssl/openssl/crypto/whrlpool/wp_dgst.c b/deps/openssl/openssl/crypto/whrlpool/wp_dgst.c
new file mode 100644 (file)
index 0000000..ee5c5c1
--- /dev/null
@@ -0,0 +1,264 @@
+/**
+ * The Whirlpool hashing function.
+ *
+ * <P>
+ * <b>References</b>
+ *
+ * <P>
+ * The Whirlpool algorithm was developed by
+ * <a href="mailto:pbarreto@scopus.com.br">Paulo S. L. M. Barreto</a> and
+ * <a href="mailto:vincent.rijmen@cryptomathic.com">Vincent Rijmen</a>.
+ *
+ * See
+ *      P.S.L.M. Barreto, V. Rijmen,
+ *      ``The Whirlpool hashing function,''
+ *      NESSIE submission, 2000 (tweaked version, 2001),
+ *      <https://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/whirlpool.zip>
+ *
+ * Based on "@version 3.0 (2003.03.12)" by Paulo S.L.M. Barreto and
+ * Vincent Rijmen. Lookup "reference implementations" on
+ * <http://planeta.terra.com.br/informatica/paulobarreto/>
+ *
+ * =============================================================================
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
+ * 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 AUTHORS OR 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.
+ *
+ */
+
+/*
+ * OpenSSL-specific implementation notes.
+ *
+ * WHIRLPOOL_Update as well as one-stroke WHIRLPOOL both expect
+ * number of *bytes* as input length argument. Bit-oriented routine
+ * as specified by authors is called WHIRLPOOL_BitUpdate[!] and
+ * does not have one-stroke counterpart.
+ *
+ * WHIRLPOOL_BitUpdate implements byte-oriented loop, essentially
+ * to serve WHIRLPOOL_Update. This is done for performance.
+ *
+ * Unlike authors' reference implementation, block processing
+ * routine whirlpool_block is designed to operate on multi-block
+ * input. This is done for perfomance.
+ */
+
+#include "wp_locl.h"
+#include <string.h>
+
+int WHIRLPOOL_Init     (WHIRLPOOL_CTX *c)
+       {
+       memset (c,0,sizeof(*c));
+       return(1);
+       }
+
+int WHIRLPOOL_Update   (WHIRLPOOL_CTX *c,const void *_inp,size_t bytes)
+       {
+       /* Well, largest suitable chunk size actually is
+        * (1<<(sizeof(size_t)*8-3))-64, but below number
+        * is large enough for not to care about excessive
+        * calls to WHIRLPOOL_BitUpdate... */
+       size_t chunk = ((size_t)1)<<(sizeof(size_t)*8-4);
+       const unsigned char *inp = _inp;
+
+       while (bytes>=chunk)
+               {
+               WHIRLPOOL_BitUpdate(c,inp,chunk*8);
+               bytes -= chunk;
+               inp   += chunk;
+               }
+       if (bytes)
+               WHIRLPOOL_BitUpdate(c,inp,bytes*8);
+
+       return(1);
+       }
+
+void WHIRLPOOL_BitUpdate(WHIRLPOOL_CTX *c,const void *_inp,size_t bits)
+       {
+       size_t          n;
+       unsigned int    bitoff = c->bitoff,
+                       bitrem = bitoff%8,
+                       inpgap = (8-(unsigned int)bits%8)&7;
+       const unsigned char *inp=_inp;
+
+       /* This 256-bit increment procedure relies on the size_t
+        * being natural size of CPU register, so that we don't
+        * have to mask the value in order to detect overflows. */
+       c->bitlen[0] += bits;
+       if (c->bitlen[0] < bits)        /* overflow */
+               {
+               n = 1;
+               do  {   c->bitlen[n]++;
+                   } while(c->bitlen[n]==0
+                           && ++n<(WHIRLPOOL_COUNTER/sizeof(size_t)));
+               }
+
+#ifndef OPENSSL_SMALL_FOOTPRINT
+       reconsider:
+       if (inpgap==0 && bitrem==0)     /* byte-oriented loop */
+               {
+               while (bits)
+                       {
+                       if (bitoff==0 && (n=bits/WHIRLPOOL_BBLOCK))
+                               {
+                               whirlpool_block(c,inp,n);
+                               inp  += n*WHIRLPOOL_BBLOCK/8;
+                               bits %= WHIRLPOOL_BBLOCK;
+                               }
+                       else
+                               {
+                               unsigned int byteoff = bitoff/8;
+
+                               bitrem = WHIRLPOOL_BBLOCK - bitoff;/* re-use bitrem */
+                               if (bits >= bitrem)
+                                       {
+                                       bits -= bitrem;
+                                       bitrem /= 8;
+                                       memcpy(c->data+byteoff,inp,bitrem);
+                                       inp  += bitrem;
+                                       whirlpool_block(c,c->data,1);
+                                       bitoff = 0;
+                                       }
+                               else
+                                       {
+                                       memcpy(c->data+byteoff,inp,bits/8);
+                                       bitoff += (unsigned int)bits;
+                                       bits = 0;
+                                       }
+                               c->bitoff = bitoff;
+                               }
+                       }
+               }
+       else                            /* bit-oriented loop */
+#endif
+               {
+               /*
+                          inp
+                          |
+                          +-------+-------+-------
+                             |||||||||||||||||||||
+                          +-------+-------+-------
+               +-------+-------+-------+-------+-------
+               ||||||||||||||                          c->data
+               +-------+-------+-------+-------+-------
+                       |
+                       c->bitoff/8
+               */
+               while (bits)
+                       {
+                       unsigned int    byteoff = bitoff/8;
+                       unsigned char   b;
+
+#ifndef OPENSSL_SMALL_FOOTPRINT
+                       if (bitrem==inpgap)
+                               {
+                               c->data[byteoff++] |= inp[0] & (0xff>>inpgap);
+                               inpgap = 8-inpgap;
+                               bitoff += inpgap;  bitrem = 0;  /* bitoff%8 */
+                               bits   -= inpgap;  inpgap = 0;  /* bits%8   */
+                               inp++;
+                               if (bitoff==WHIRLPOOL_BBLOCK)
+                                       {
+                                       whirlpool_block(c,c->data,1);
+                                       bitoff = 0;
+                                       }
+                               c->bitoff = bitoff;
+                               goto reconsider;
+                               }
+                       else
+#endif
+                       if (bits>=8)
+                               {
+                               b  = ((inp[0]<<inpgap) | (inp[1]>>(8-inpgap)));
+                               b &= 0xff;
+                               if (bitrem)     c->data[byteoff++] |= b>>bitrem;
+                               else            c->data[byteoff++]  = b;
+                               bitoff += 8;
+                               bits   -= 8;
+                               inp++;
+                               if (bitoff>=WHIRLPOOL_BBLOCK)
+                                       {
+                                       whirlpool_block(c,c->data,1);
+                                       byteoff  = 0;
+                                       bitoff  %= WHIRLPOOL_BBLOCK;
+                                       }
+                               if (bitrem)     c->data[byteoff] = b<<(8-bitrem);
+                               }
+                       else    /* remaining less than 8 bits */
+                               {
+                               b = (inp[0]<<inpgap)&0xff;
+                               if (bitrem)     c->data[byteoff++] |= b>>bitrem;
+                               else            c->data[byteoff++]  = b;
+                               bitoff += (unsigned int)bits;
+                               if (bitoff==WHIRLPOOL_BBLOCK)
+                                       {
+                                       whirlpool_block(c,c->data,1);
+                                       byteoff  = 0;
+                                       bitoff  %= WHIRLPOOL_BBLOCK;
+                                       }
+                               if (bitrem)     c->data[byteoff] = b<<(8-bitrem);
+                               bits = 0;
+                               }
+                       c->bitoff = bitoff;
+                       }
+               }
+       }
+
+int WHIRLPOOL_Final    (unsigned char *md,WHIRLPOOL_CTX *c)
+       {
+       unsigned int    bitoff  = c->bitoff,
+                       byteoff = bitoff/8;
+       size_t          i,j,v;
+       unsigned char  *p;
+
+       bitoff %= 8;
+       if (bitoff)     c->data[byteoff] |= 0x80>>bitoff;
+       else            c->data[byteoff]  = 0x80;
+       byteoff++;
+
+       /* pad with zeros */
+       if (byteoff > (WHIRLPOOL_BBLOCK/8-WHIRLPOOL_COUNTER))
+               {
+               if (byteoff<WHIRLPOOL_BBLOCK/8)
+                       memset(&c->data[byteoff],0,WHIRLPOOL_BBLOCK/8-byteoff);
+               whirlpool_block(c,c->data,1);
+               byteoff = 0;
+               }
+       if (byteoff < (WHIRLPOOL_BBLOCK/8-WHIRLPOOL_COUNTER))
+               memset(&c->data[byteoff],0,
+                       (WHIRLPOOL_BBLOCK/8-WHIRLPOOL_COUNTER)-byteoff);
+       /* smash 256-bit c->bitlen in big-endian order */
+       p = &c->data[WHIRLPOOL_BBLOCK/8-1];     /* last byte in c->data */
+       for(i=0;i<WHIRLPOOL_COUNTER/sizeof(size_t);i++)
+               for(v=c->bitlen[i],j=0;j<sizeof(size_t);j++,v>>=8)
+                       *p-- = (unsigned char)(v&0xff);
+
+       whirlpool_block(c,c->data,1);
+
+       if (md) {
+               memcpy(md,c->H.c,WHIRLPOOL_DIGEST_LENGTH);
+               memset(c,0,sizeof(*c));
+               return(1);
+               }
+       return(0);
+       }
+
+unsigned char *WHIRLPOOL(const void *inp, size_t bytes,unsigned char *md)
+       {
+       WHIRLPOOL_CTX ctx;
+       static unsigned char m[WHIRLPOOL_DIGEST_LENGTH];
+
+       if (md == NULL) md=m;
+       WHIRLPOOL_Init(&ctx);
+       WHIRLPOOL_Update(&ctx,inp,bytes);
+       WHIRLPOOL_Final(md,&ctx);
+       return(md);
+       }
diff --git a/deps/openssl/openssl/crypto/whrlpool/wp_locl.h b/deps/openssl/openssl/crypto/whrlpool/wp_locl.h
new file mode 100644 (file)
index 0000000..94e56a3
--- /dev/null
@@ -0,0 +1,3 @@
+#include <openssl/whrlpool.h>
+
+void whirlpool_block(WHIRLPOOL_CTX *,const void *,size_t);
diff --git a/deps/openssl/openssl/crypto/whrlpool/wp_test.c b/deps/openssl/openssl/crypto/whrlpool/wp_test.c
new file mode 100644 (file)
index 0000000..c68c2c6
--- /dev/null
@@ -0,0 +1,228 @@
+/* ====================================================================
+ * Copyright (c) 2005 The OpenSSL Project.  All rights reserved.
+ * ====================================================================
+ */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <openssl/whrlpool.h>
+#include <openssl/crypto.h>
+
+#if defined(OPENSSL_NO_WHIRLPOOL)
+int main(int argc, char *argv[])
+{
+    printf("No Whirlpool support\n");
+    return(0);
+}
+#else
+
+/* ISO/IEC 10118-3 test vector set */
+unsigned char iso_test_1[WHIRLPOOL_DIGEST_LENGTH] = {
+       0x19,0xFA,0x61,0xD7,0x55,0x22,0xA4,0x66,
+       0x9B,0x44,0xE3,0x9C,0x1D,0x2E,0x17,0x26,
+       0xC5,0x30,0x23,0x21,0x30,0xD4,0x07,0xF8,
+       0x9A,0xFE,0xE0,0x96,0x49,0x97,0xF7,0xA7,
+       0x3E,0x83,0xBE,0x69,0x8B,0x28,0x8F,0xEB,
+       0xCF,0x88,0xE3,0xE0,0x3C,0x4F,0x07,0x57,
+       0xEA,0x89,0x64,0xE5,0x9B,0x63,0xD9,0x37,
+       0x08,0xB1,0x38,0xCC,0x42,0xA6,0x6E,0xB3 };
+
+unsigned char iso_test_2[WHIRLPOOL_DIGEST_LENGTH] = {
+       0x8A,0xCA,0x26,0x02,0x79,0x2A,0xEC,0x6F,
+       0x11,0xA6,0x72,0x06,0x53,0x1F,0xB7,0xD7,
+       0xF0,0xDF,0xF5,0x94,0x13,0x14,0x5E,0x69,
+       0x73,0xC4,0x50,0x01,0xD0,0x08,0x7B,0x42,
+       0xD1,0x1B,0xC6,0x45,0x41,0x3A,0xEF,0xF6,
+       0x3A,0x42,0x39,0x1A,0x39,0x14,0x5A,0x59,
+       0x1A,0x92,0x20,0x0D,0x56,0x01,0x95,0xE5,
+       0x3B,0x47,0x85,0x84,0xFD,0xAE,0x23,0x1A };
+
+unsigned char iso_test_3[WHIRLPOOL_DIGEST_LENGTH] = {
+       0x4E,0x24,0x48,0xA4,0xC6,0xF4,0x86,0xBB,
+       0x16,0xB6,0x56,0x2C,0x73,0xB4,0x02,0x0B,
+       0xF3,0x04,0x3E,0x3A,0x73,0x1B,0xCE,0x72,
+       0x1A,0xE1,0xB3,0x03,0xD9,0x7E,0x6D,0x4C,
+       0x71,0x81,0xEE,0xBD,0xB6,0xC5,0x7E,0x27,
+       0x7D,0x0E,0x34,0x95,0x71,0x14,0xCB,0xD6,
+       0xC7,0x97,0xFC,0x9D,0x95,0xD8,0xB5,0x82,
+       0xD2,0x25,0x29,0x20,0x76,0xD4,0xEE,0xF5 };
+
+unsigned char iso_test_4[WHIRLPOOL_DIGEST_LENGTH] = {
+       0x37,0x8C,0x84,0xA4,0x12,0x6E,0x2D,0xC6,
+       0xE5,0x6D,0xCC,0x74,0x58,0x37,0x7A,0xAC,
+       0x83,0x8D,0x00,0x03,0x22,0x30,0xF5,0x3C,
+       0xE1,0xF5,0x70,0x0C,0x0F,0xFB,0x4D,0x3B,
+       0x84,0x21,0x55,0x76,0x59,0xEF,0x55,0xC1,
+       0x06,0xB4,0xB5,0x2A,0xC5,0xA4,0xAA,0xA6,
+       0x92,0xED,0x92,0x00,0x52,0x83,0x8F,0x33,
+       0x62,0xE8,0x6D,0xBD,0x37,0xA8,0x90,0x3E };
+
+unsigned char iso_test_5[WHIRLPOOL_DIGEST_LENGTH] = {
+       0xF1,0xD7,0x54,0x66,0x26,0x36,0xFF,0xE9,
+       0x2C,0x82,0xEB,0xB9,0x21,0x2A,0x48,0x4A,
+       0x8D,0x38,0x63,0x1E,0xAD,0x42,0x38,0xF5,
+       0x44,0x2E,0xE1,0x3B,0x80,0x54,0xE4,0x1B,
+       0x08,0xBF,0x2A,0x92,0x51,0xC3,0x0B,0x6A,
+       0x0B,0x8A,0xAE,0x86,0x17,0x7A,0xB4,0xA6,
+       0xF6,0x8F,0x67,0x3E,0x72,0x07,0x86,0x5D,
+       0x5D,0x98,0x19,0xA3,0xDB,0xA4,0xEB,0x3B };
+
+unsigned char iso_test_6[WHIRLPOOL_DIGEST_LENGTH] = {
+       0xDC,0x37,0xE0,0x08,0xCF,0x9E,0xE6,0x9B,
+       0xF1,0x1F,0x00,0xED,0x9A,0xBA,0x26,0x90,
+       0x1D,0xD7,0xC2,0x8C,0xDE,0xC0,0x66,0xCC,
+       0x6A,0xF4,0x2E,0x40,0xF8,0x2F,0x3A,0x1E,
+       0x08,0xEB,0xA2,0x66,0x29,0x12,0x9D,0x8F,
+       0xB7,0xCB,0x57,0x21,0x1B,0x92,0x81,0xA6,
+       0x55,0x17,0xCC,0x87,0x9D,0x7B,0x96,0x21,
+       0x42,0xC6,0x5F,0x5A,0x7A,0xF0,0x14,0x67 };
+
+unsigned char iso_test_7[WHIRLPOOL_DIGEST_LENGTH] = {
+       0x46,0x6E,0xF1,0x8B,0xAB,0xB0,0x15,0x4D,
+       0x25,0xB9,0xD3,0x8A,0x64,0x14,0xF5,0xC0,
+       0x87,0x84,0x37,0x2B,0xCC,0xB2,0x04,0xD6,
+       0x54,0x9C,0x4A,0xFA,0xDB,0x60,0x14,0x29,
+       0x4D,0x5B,0xD8,0xDF,0x2A,0x6C,0x44,0xE5,
+       0x38,0xCD,0x04,0x7B,0x26,0x81,0xA5,0x1A,
+       0x2C,0x60,0x48,0x1E,0x88,0xC5,0xA2,0x0B,
+       0x2C,0x2A,0x80,0xCF,0x3A,0x9A,0x08,0x3B };
+
+unsigned char iso_test_8[WHIRLPOOL_DIGEST_LENGTH] = {
+       0x2A,0x98,0x7E,0xA4,0x0F,0x91,0x70,0x61,
+       0xF5,0xD6,0xF0,0xA0,0xE4,0x64,0x4F,0x48,
+       0x8A,0x7A,0x5A,0x52,0xDE,0xEE,0x65,0x62,
+       0x07,0xC5,0x62,0xF9,0x88,0xE9,0x5C,0x69,
+       0x16,0xBD,0xC8,0x03,0x1B,0xC5,0xBE,0x1B,
+       0x7B,0x94,0x76,0x39,0xFE,0x05,0x0B,0x56,
+       0x93,0x9B,0xAA,0xA0,0xAD,0xFF,0x9A,0xE6,
+       0x74,0x5B,0x7B,0x18,0x1C,0x3B,0xE3,0xFD };
+
+unsigned char iso_test_9[WHIRLPOOL_DIGEST_LENGTH] = {
+       0x0C,0x99,0x00,0x5B,0xEB,0x57,0xEF,0xF5,
+       0x0A,0x7C,0xF0,0x05,0x56,0x0D,0xDF,0x5D,
+       0x29,0x05,0x7F,0xD8,0x6B,0x20,0xBF,0xD6,
+       0x2D,0xEC,0xA0,0xF1,0xCC,0xEA,0x4A,0xF5,
+       0x1F,0xC1,0x54,0x90,0xED,0xDC,0x47,0xAF,
+       0x32,0xBB,0x2B,0x66,0xC3,0x4F,0xF9,0xAD,
+       0x8C,0x60,0x08,0xAD,0x67,0x7F,0x77,0x12,
+       0x69,0x53,0xB2,0x26,0xE4,0xED,0x8B,0x01 };
+
+int main (int argc,char *argv[])
+{ unsigned char md[WHIRLPOOL_DIGEST_LENGTH];
+  int          i;
+  WHIRLPOOL_CTX        ctx;
+
+#ifdef OPENSSL_IA32_SSE2
+    /* Alternative to this is to call OpenSSL_add_all_algorithms...
+     * The below code is retained exclusively for debugging purposes. */
+    { char      *env;
+
+       if ((env=getenv("OPENSSL_ia32cap")))
+           OPENSSL_ia32cap = strtoul (env,NULL,0);
+    }
+#endif
+
+    fprintf(stdout,"Testing Whirlpool ");
+
+    WHIRLPOOL("",0,md);
+    if (memcmp(md,iso_test_1,sizeof(iso_test_1)))
+    {   fflush(stdout);
+       fprintf(stderr,"\nTEST 1 of 9 failed.\n");
+       return 1;
+    }
+    else
+       fprintf(stdout,"."); fflush(stdout);
+
+    WHIRLPOOL("a",1,md);
+    if (memcmp(md,iso_test_2,sizeof(iso_test_2)))
+    {   fflush(stdout);
+       fprintf(stderr,"\nTEST 2 of 9 failed.\n");
+       return 1;
+    }
+    else
+       fprintf(stdout,"."); fflush(stdout);
+
+    WHIRLPOOL("abc",3,md);
+    if (memcmp(md,iso_test_3,sizeof(iso_test_3)))
+    {   fflush(stdout);
+       fprintf(stderr,"\nTEST 3 of 9 failed.\n");
+       return 1;
+    }
+    else
+       fprintf(stdout,"."); fflush(stdout);
+
+    WHIRLPOOL("message digest",14,md);
+    if (memcmp(md,iso_test_4,sizeof(iso_test_4)))
+    {   fflush(stdout);
+       fprintf(stderr,"\nTEST 4 of 9 failed.\n");
+       return 1;
+    }
+    else
+       fprintf(stdout,"."); fflush(stdout);
+
+    WHIRLPOOL("abcdefghijklmnopqrstuvwxyz",26,md);
+    if (memcmp(md,iso_test_5,sizeof(iso_test_5)))
+    {   fflush(stdout);
+       fprintf(stderr,"\nTEST 5 of 9 failed.\n");
+       return 1;
+    }
+    else
+       fprintf(stdout,"."); fflush(stdout);
+
+    WHIRLPOOL( "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+               "abcdefghijklmnopqrstuvwxyz"
+               "0123456789",62,md);
+    if (memcmp(md,iso_test_6,sizeof(iso_test_6)))
+    {   fflush(stdout);
+       fprintf(stderr,"\nTEST 6 of 9 failed.\n");
+       return 1;
+    }
+    else
+       fprintf(stdout,"."); fflush(stdout);
+
+    WHIRLPOOL( "1234567890""1234567890""1234567890""1234567890"
+               "1234567890""1234567890""1234567890""1234567890",80,md);
+    if (memcmp(md,iso_test_7,sizeof(iso_test_7)))
+    {   fflush(stdout);
+       fprintf(stderr,"\nTEST 7 of 9 failed.\n");
+       return 1;
+    }
+    else
+       fprintf(stdout,"."); fflush(stdout);
+
+    WHIRLPOOL("abcdbcdecdefdefgefghfghighijhijk",32,md);
+    if (memcmp(md,iso_test_8,sizeof(iso_test_8)))
+    {   fflush(stdout);
+       fprintf(stderr,"\nTEST 8 of 9 failed.\n");
+       return 1;
+    }
+    else
+       fprintf(stdout,"."); fflush(stdout);
+    WHIRLPOOL_Init (&ctx);
+    for (i=0;i<1000000;i+=288)
+       WHIRLPOOL_Update (&ctx, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
+                               "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
+                               "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
+                               "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
+                               "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
+                               "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
+                               "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
+                               "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
+                               "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa",
+                               (1000000-i)<288?1000000-i:288);
+    WHIRLPOOL_Final (md,&ctx);
+    if (memcmp(md,iso_test_9,sizeof(iso_test_9)))
+    {   fflush(stdout);
+       fprintf(stderr,"\nTEST 9 of 9 failed.\n");
+       return 1;
+    }
+    else
+       fprintf(stdout,"."); fflush(stdout);
+
+    fprintf(stdout," passed.\n"); fflush(stdout);
+
+  return 0;
+}
+#endif
index 464752b..72c8227 100644 (file)
@@ -43,12 +43,12 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
 files:
-       $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
+       $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
 
 links:
        @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
@@ -89,37 +89,35 @@ by_dir.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 by_dir.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 by_dir.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 by_dir.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-by_dir.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-by_dir.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-by_dir.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-by_dir.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-by_dir.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-by_dir.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-by_dir.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-by_dir.o: ../cryptlib.h by_dir.c
+by_dir.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+by_dir.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+by_dir.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+by_dir.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+by_dir.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+by_dir.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+by_dir.o: ../../include/openssl/x509_vfy.h ../cryptlib.h by_dir.c
 by_file.o: ../../e_os.h ../../include/openssl/asn1.h
 by_file.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 by_file.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 by_file.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 by_file.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-by_file.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-by_file.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-by_file.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-by_file.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-by_file.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
-by_file.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-by_file.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-by_file.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-by_file.o: ../../include/openssl/x509_vfy.h ../cryptlib.h by_file.c
+by_file.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+by_file.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+by_file.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+by_file.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
+by_file.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
+by_file.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+by_file.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+by_file.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+by_file.o: ../cryptlib.h by_file.c
 x509_att.o: ../../e_os.h ../../include/openssl/asn1.h
 x509_att.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 x509_att.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 x509_att.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 x509_att.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 x509_att.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-x509_att.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-x509_att.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-x509_att.o: ../../include/openssl/opensslconf.h
+x509_att.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+x509_att.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 x509_att.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 x509_att.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 x509_att.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -132,9 +130,8 @@ x509_cmp.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 x509_cmp.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 x509_cmp.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 x509_cmp.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-x509_cmp.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-x509_cmp.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-x509_cmp.o: ../../include/openssl/opensslconf.h
+x509_cmp.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+x509_cmp.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 x509_cmp.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 x509_cmp.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 x509_cmp.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -146,22 +143,22 @@ x509_d2.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 x509_d2.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 x509_d2.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 x509_d2.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-x509_d2.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-x509_d2.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-x509_d2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-x509_d2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-x509_d2.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-x509_d2.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-x509_d2.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-x509_d2.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x509_d2.c
+x509_d2.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+x509_d2.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+x509_d2.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+x509_d2.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+x509_d2.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+x509_d2.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+x509_d2.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+x509_d2.o: ../cryptlib.h x509_d2.c
 x509_def.o: ../../e_os.h ../../include/openssl/asn1.h
 x509_def.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 x509_def.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 x509_def.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 x509_def.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-x509_def.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-x509_def.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-x509_def.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+x509_def.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+x509_def.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+x509_def.o: ../../include/openssl/opensslconf.h
 x509_def.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 x509_def.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 x509_def.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -172,9 +169,8 @@ x509_err.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 x509_err.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 x509_err.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 x509_err.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-x509_err.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-x509_err.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-x509_err.o: ../../include/openssl/opensslconf.h
+x509_err.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+x509_err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 x509_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 x509_err.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 x509_err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -186,9 +182,8 @@ x509_ext.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 x509_ext.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 x509_ext.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 x509_ext.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-x509_ext.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-x509_ext.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-x509_ext.o: ../../include/openssl/opensslconf.h
+x509_ext.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+x509_ext.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 x509_ext.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 x509_ext.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 x509_ext.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -201,22 +196,22 @@ x509_lu.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 x509_lu.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 x509_lu.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 x509_lu.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-x509_lu.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-x509_lu.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-x509_lu.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-x509_lu.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-x509_lu.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-x509_lu.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-x509_lu.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-x509_lu.o: ../../include/openssl/x509v3.h ../cryptlib.h x509_lu.c
+x509_lu.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+x509_lu.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+x509_lu.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+x509_lu.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+x509_lu.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+x509_lu.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+x509_lu.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+x509_lu.o: ../cryptlib.h x509_lu.c
 x509_obj.o: ../../e_os.h ../../include/openssl/asn1.h
 x509_obj.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 x509_obj.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 x509_obj.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 x509_obj.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-x509_obj.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-x509_obj.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-x509_obj.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+x509_obj.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+x509_obj.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+x509_obj.o: ../../include/openssl/opensslconf.h
 x509_obj.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 x509_obj.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 x509_obj.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -228,21 +223,20 @@ x509_r2x.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 x509_r2x.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 x509_r2x.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 x509_r2x.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-x509_r2x.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-x509_r2x.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-x509_r2x.o: ../../include/openssl/opensslconf.h
+x509_r2x.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+x509_r2x.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 x509_r2x.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 x509_r2x.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 x509_r2x.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
 x509_r2x.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
 x509_r2x.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x509_r2x.c
 x509_req.o: ../../e_os.h ../../include/openssl/asn1.h
-x509_req.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
-x509_req.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
-x509_req.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-x509_req.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
-x509_req.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-x509_req.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
+x509_req.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
+x509_req.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
+x509_req.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+x509_req.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+x509_req.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
+x509_req.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
 x509_req.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
 x509_req.o: ../../include/openssl/opensslconf.h
 x509_req.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
@@ -256,9 +250,9 @@ x509_set.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 x509_set.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 x509_set.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 x509_set.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-x509_set.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-x509_set.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-x509_set.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+x509_set.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+x509_set.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+x509_set.o: ../../include/openssl/opensslconf.h
 x509_set.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 x509_set.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 x509_set.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -270,9 +264,8 @@ x509_trs.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 x509_trs.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 x509_trs.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 x509_trs.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-x509_trs.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-x509_trs.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-x509_trs.o: ../../include/openssl/opensslconf.h
+x509_trs.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+x509_trs.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 x509_trs.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 x509_trs.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 x509_trs.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -284,9 +277,9 @@ x509_txt.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 x509_txt.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 x509_txt.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 x509_txt.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-x509_txt.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-x509_txt.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-x509_txt.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+x509_txt.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+x509_txt.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+x509_txt.o: ../../include/openssl/opensslconf.h
 x509_txt.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 x509_txt.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 x509_txt.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -298,23 +291,22 @@ x509_v3.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 x509_v3.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 x509_v3.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 x509_v3.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-x509_v3.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-x509_v3.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-x509_v3.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-x509_v3.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-x509_v3.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-x509_v3.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-x509_v3.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-x509_v3.o: ../../include/openssl/x509v3.h ../cryptlib.h x509_v3.c
+x509_v3.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+x509_v3.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+x509_v3.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+x509_v3.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+x509_v3.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+x509_v3.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+x509_v3.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+x509_v3.o: ../cryptlib.h x509_v3.c
 x509_vfy.o: ../../e_os.h ../../include/openssl/asn1.h
 x509_vfy.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 x509_vfy.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 x509_vfy.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 x509_vfy.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 x509_vfy.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-x509_vfy.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-x509_vfy.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-x509_vfy.o: ../../include/openssl/opensslconf.h
+x509_vfy.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+x509_vfy.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 x509_vfy.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 x509_vfy.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 x509_vfy.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -327,9 +319,8 @@ x509_vpm.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 x509_vpm.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 x509_vpm.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 x509_vpm.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-x509_vpm.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-x509_vpm.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-x509_vpm.o: ../../include/openssl/opensslconf.h
+x509_vpm.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+x509_vpm.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 x509_vpm.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 x509_vpm.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 x509_vpm.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -341,9 +332,9 @@ x509cset.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 x509cset.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 x509cset.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 x509cset.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-x509cset.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-x509cset.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-x509cset.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+x509cset.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+x509cset.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+x509cset.o: ../../include/openssl/opensslconf.h
 x509cset.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 x509cset.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 x509cset.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -354,9 +345,9 @@ x509name.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 x509name.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 x509name.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 x509name.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-x509name.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-x509name.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-x509name.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+x509name.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+x509name.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+x509name.o: ../../include/openssl/opensslconf.h
 x509name.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 x509name.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 x509name.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -367,9 +358,9 @@ x509rset.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 x509rset.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 x509rset.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 x509rset.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-x509rset.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-x509rset.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-x509rset.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+x509rset.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+x509rset.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+x509rset.o: ../../include/openssl/opensslconf.h
 x509rset.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 x509rset.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 x509rset.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -380,9 +371,9 @@ x509spki.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 x509spki.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 x509spki.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 x509spki.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-x509spki.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-x509spki.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-x509spki.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+x509spki.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+x509spki.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+x509spki.o: ../../include/openssl/opensslconf.h
 x509spki.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 x509spki.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 x509spki.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -393,9 +384,9 @@ x509type.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 x509type.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 x509type.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 x509type.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-x509type.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-x509type.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-x509type.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+x509type.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+x509type.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+x509type.o: ../../include/openssl/opensslconf.h
 x509type.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 x509type.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 x509type.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -406,12 +397,11 @@ x_all.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 x_all.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
 x_all.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 x_all.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-x_all.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-x_all.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-x_all.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-x_all.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-x_all.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
-x_all.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-x_all.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-x_all.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-x_all.o: ../cryptlib.h x_all.c
+x_all.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+x_all.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+x_all.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+x_all.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+x_all.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+x_all.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+x_all.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+x_all.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_all.c
index b3acd80..03293ac 100644 (file)
 #ifndef NO_SYS_TYPES_H
 # include <sys/types.h>
 #endif
-#ifdef MAC_OS_pre_X
-# include <stat.h>
-#else
+#ifndef OPENSSL_NO_POSIX_IO
 # include <sys/stat.h>
 #endif
 
 #include <openssl/lhash.h>
 #include <openssl/x509.h>
 
-#ifdef _WIN32
-#define stat   _stat
-#endif
+
+typedef struct lookup_dir_hashes_st
+       {
+       unsigned long hash;
+       int suffix;
+       } BY_DIR_HASH;
+
+typedef struct lookup_dir_entry_st
+       {
+       char *dir;
+       int dir_type;
+       STACK_OF(BY_DIR_HASH) *hashes;
+       } BY_DIR_ENTRY;
 
 typedef struct lookup_dir_st
        {
        BUF_MEM *buffer;
-       int num_dirs;
-       char **dirs;
-       int *dirs_type;
-       int num_dirs_alloced;
+       STACK_OF(BY_DIR_ENTRY) *dirs;
        } BY_DIR;
 
+DECLARE_STACK_OF(BY_DIR_HASH)
+DECLARE_STACK_OF(BY_DIR_ENTRY)
+
 static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
        char **ret);
 static int new_dir(X509_LOOKUP *lu);
@@ -127,7 +135,7 @@ static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
        case X509_L_ADD_DIR:
                if (argl == X509_FILETYPE_DEFAULT)
                        {
-                       dir=(char *)Getenv(X509_get_default_cert_dir_env());
+                       dir=(char *)getenv(X509_get_default_cert_dir_env());
                        if (dir)
                                ret=add_cert_dir(ld,dir,X509_FILETYPE_PEM);
                        else
@@ -156,34 +164,51 @@ static int new_dir(X509_LOOKUP *lu)
                OPENSSL_free(a);
                return(0);
                }
-       a->num_dirs=0;
        a->dirs=NULL;
-       a->dirs_type=NULL;
-       a->num_dirs_alloced=0;
        lu->method_data=(char *)a;
        return(1);
        }
 
+static void by_dir_hash_free(BY_DIR_HASH *hash)
+       {
+       OPENSSL_free(hash);
+       }
+
+static int by_dir_hash_cmp(const BY_DIR_HASH * const *a,
+                       const BY_DIR_HASH * const *b)
+       {
+       if ((*a)->hash > (*b)->hash)
+               return 1;
+       if ((*a)->hash < (*b)->hash)
+               return -1;
+       return 0;
+       }
+
+static void by_dir_entry_free(BY_DIR_ENTRY *ent)
+       {
+       if (ent->dir)
+               OPENSSL_free(ent->dir);
+       if (ent->hashes)
+               sk_BY_DIR_HASH_pop_free(ent->hashes, by_dir_hash_free);
+       OPENSSL_free(ent);
+       }
+
 static void free_dir(X509_LOOKUP *lu)
        {
        BY_DIR *a;
-       int i;
 
        a=(BY_DIR *)lu->method_data;
-       for (i=0; i<a->num_dirs; i++)
-               if (a->dirs[i] != NULL) OPENSSL_free(a->dirs[i]);
-       if (a->dirs != NULL) OPENSSL_free(a->dirs);
-       if (a->dirs_type != NULL) OPENSSL_free(a->dirs_type);
-       if (a->buffer != NULL) BUF_MEM_free(a->buffer);
+       if (a->dirs != NULL)
+               sk_BY_DIR_ENTRY_pop_free(a->dirs, by_dir_entry_free);
+       if (a->buffer != NULL)
+               BUF_MEM_free(a->buffer);
        OPENSSL_free(a);
        }
 
 static int add_cert_dir(BY_DIR *ctx, const char *dir, int type)
        {
        int j,len;
-       int *ip;
        const char *s,*ss,*p;
-       char **pp;
 
        if (dir == NULL || !*dir)
            {
@@ -197,49 +222,52 @@ static int add_cert_dir(BY_DIR *ctx, const char *dir, int type)
                {
                if ((*p == LIST_SEPARATOR_CHAR) || (*p == '\0'))
                        {
+                       BY_DIR_ENTRY *ent;
                        ss=s;
                        s=p+1;
                        len=(int)(p-ss);
                        if (len == 0) continue;
-                       for (j=0; j<ctx->num_dirs; j++)
-                               if (strlen(ctx->dirs[j]) == (size_t)len &&
-                                   strncmp(ctx->dirs[j],ss,(unsigned int)len) == 0)
+                       for (j=0; j < sk_BY_DIR_ENTRY_num(ctx->dirs); j++)
+                               {
+                               ent = sk_BY_DIR_ENTRY_value(ctx->dirs, j);
+                               if (strlen(ent->dir) == (size_t)len &&
+                                   strncmp(ent->dir,ss,(unsigned int)len) == 0)
                                        break;
-                       if (j<ctx->num_dirs)
+                               }
+                       if (j < sk_BY_DIR_ENTRY_num(ctx->dirs))
                                continue;
-                       if (ctx->num_dirs_alloced < (ctx->num_dirs+1))
+                       if (ctx->dirs == NULL)
                                {
-                               ctx->num_dirs_alloced+=10;
-                               pp=(char **)OPENSSL_malloc(ctx->num_dirs_alloced*
-                                       sizeof(char *));
-                               ip=(int *)OPENSSL_malloc(ctx->num_dirs_alloced*
-                                       sizeof(int));
-                               if ((pp == NULL) || (ip == NULL))
+                               ctx->dirs = sk_BY_DIR_ENTRY_new_null();
+                               if (!ctx->dirs)
                                        {
                                        X509err(X509_F_ADD_CERT_DIR,ERR_R_MALLOC_FAILURE);
-                                       return(0);
+                                       return 0;
                                        }
-                               memcpy(pp,ctx->dirs,(ctx->num_dirs_alloced-10)*
-                                       sizeof(char *));
-                               memcpy(ip,ctx->dirs_type,(ctx->num_dirs_alloced-10)*
-                                       sizeof(int));
-                               if (ctx->dirs != NULL)
-                                       OPENSSL_free(ctx->dirs);
-                               if (ctx->dirs_type != NULL)
-                                       OPENSSL_free(ctx->dirs_type);
-                               ctx->dirs=pp;
-                               ctx->dirs_type=ip;
                                }
-                       ctx->dirs_type[ctx->num_dirs]=type;
-                       ctx->dirs[ctx->num_dirs]=(char *)OPENSSL_malloc((unsigned int)len+1);
-                       if (ctx->dirs[ctx->num_dirs] == NULL) return(0);
-                       strncpy(ctx->dirs[ctx->num_dirs],ss,(unsigned int)len);
-                       ctx->dirs[ctx->num_dirs][len]='\0';
-                       ctx->num_dirs++;
+                       ent = OPENSSL_malloc(sizeof(BY_DIR_ENTRY));
+                       if (!ent)
+                               return 0;
+                       ent->dir_type = type;
+                       ent->hashes = sk_BY_DIR_HASH_new(by_dir_hash_cmp);
+                       ent->dir = OPENSSL_malloc((unsigned int)len+1);
+                       if (!ent->dir || !ent->hashes)
+                               {
+                               by_dir_entry_free(ent);
+                               return 0;
+                               }
+                       strncpy(ent->dir,ss,(unsigned int)len);
+                       ent->dir[len] = '\0';
+                       if (!sk_BY_DIR_ENTRY_push(ctx->dirs, ent))
+                               {
+                               by_dir_entry_free(ent);
+                               return 0;
+                               }
                        }
-               if (*p == '\0') break;
+               if (*p == '\0')
+                       break;
                }
-       return(1);
+       return 1;
        }
 
 static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
@@ -259,8 +287,9 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
        int ok=0;
        int i,j,k;
        unsigned long h;
+       unsigned long hash_array[2];
+       int hash_index;
        BUF_MEM *b=NULL;
-       struct stat st;
        X509_OBJECT stmp,*tmp;
        const char *postfix="";
 
@@ -296,20 +325,50 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
        ctx=(BY_DIR *)xl->method_data;
 
        h=X509_NAME_hash(name);
-       for (i=0; i<ctx->num_dirs; i++)
+       hash_array[0]=h;
+       hash_array[1]=X509_NAME_hash_old(name);
+       for (hash_index=0; hash_index < 2; hash_index++)
                {
-               j=strlen(ctx->dirs[i])+1+8+6+1+1;
+               h=hash_array[hash_index];
+       for (i=0; i < sk_BY_DIR_ENTRY_num(ctx->dirs); i++)
+               {
+               BY_DIR_ENTRY *ent;
+               int idx;
+               BY_DIR_HASH htmp, *hent;
+               ent = sk_BY_DIR_ENTRY_value(ctx->dirs, i);
+               j=strlen(ent->dir)+1+8+6+1+1;
                if (!BUF_MEM_grow(b,j))
                        {
                        X509err(X509_F_GET_CERT_BY_SUBJECT,ERR_R_MALLOC_FAILURE);
                        goto finish;
                        }
-               k=0;
+               if (type == X509_LU_CRL && ent->hashes)
+                       {
+                       htmp.hash = h;
+                       CRYPTO_r_lock(CRYPTO_LOCK_X509_STORE);
+                       idx = sk_BY_DIR_HASH_find(ent->hashes, &htmp);
+                       if (idx >= 0)
+                               {
+                               hent = sk_BY_DIR_HASH_value(ent->hashes, idx);
+                               k = hent->suffix;
+                               }
+                       else
+                               {
+                               hent = NULL;
+                               k=0;
+                               }
+                       CRYPTO_r_unlock(CRYPTO_LOCK_X509_STORE);
+                       }
+               else
+                       {
+                       k = 0;
+                       hent = NULL;
+                       }
                for (;;)
                        {
                        char c = '/';
 #ifdef OPENSSL_SYS_VMS
-                       c = ctx->dirs[i][strlen(ctx->dirs[i])-1];
+                       c = ent->dir[strlen(ent->dir)-1];
                        if (c != ':' && c != '>' && c != ']')
                                {
                                /* If no separator is present, we assume the
@@ -330,32 +389,40 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
                                /* This is special.  When c == '\0', no
                                   directory separator should be added. */
                                BIO_snprintf(b->data,b->max,
-                                       "%s%08lx.%s%d",ctx->dirs[i],h,
+                                       "%s%08lx.%s%d",ent->dir,h,
                                        postfix,k);
                                }
                        else
                                {
                                BIO_snprintf(b->data,b->max,
-                                       "%s%c%08lx.%s%d",ctx->dirs[i],c,h,
+                                       "%s%c%08lx.%s%d",ent->dir,c,h,
                                        postfix,k);
                                }
-                       k++;
+#ifndef OPENSSL_NO_POSIX_IO
+#ifdef _WIN32
+#define stat _stat
+#endif
+                       {
+                       struct stat st;
                        if (stat(b->data,&st) < 0)
                                break;
+                       }
+#endif
                        /* found one. */
                        if (type == X509_LU_X509)
                                {
                                if ((X509_load_cert_file(xl,b->data,
-                                       ctx->dirs_type[i])) == 0)
+                                       ent->dir_type)) == 0)
                                        break;
                                }
                        else if (type == X509_LU_CRL)
                                {
                                if ((X509_load_crl_file(xl,b->data,
-                                       ctx->dirs_type[i])) == 0)
+                                       ent->dir_type)) == 0)
                                        break;
                                }
                        /* else case will caught higher up */
+                       k++;
                        }
 
                /* we have added it to the cache so now pull
@@ -366,6 +433,43 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
                else tmp = NULL;
                CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
 
+
+               /* If a CRL, update the last file suffix added for this */
+
+               if (type == X509_LU_CRL)
+                       {
+                       CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);
+                       /* Look for entry again in case another thread added
+                        * an entry first.
+                        */
+                       if (!hent)
+                               {
+                               htmp.hash = h;
+                               idx = sk_BY_DIR_HASH_find(ent->hashes, &htmp);
+                               if (idx >= 0)
+                                       hent =
+                                        sk_BY_DIR_HASH_value(ent->hashes, idx);
+                               }
+                       if (!hent)
+                               {
+                               hent = OPENSSL_malloc(sizeof(BY_DIR_HASH));
+                               hent->hash = h;
+                               hent->suffix = k;
+                               if (!sk_BY_DIR_HASH_push(ent->hashes, hent))
+                                       {
+                                       CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
+                                       OPENSSL_free(hent);
+                                       ok = 0;
+                                       goto finish;
+                                       }
+                               }
+                       else if (hent->suffix < k)
+                               hent->suffix = k;
+
+                       CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
+
+                       }
+
                if (tmp != NULL)
                        {
                        ok=1;
@@ -379,6 +483,7 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
                        goto finish;
                        }
                }
+               }
 finish:
        if (b != NULL) BUF_MEM_free(b);
        return(ok);
index a5e0d4a..57b08ee 100644 (file)
@@ -100,7 +100,7 @@ static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
        case X509_L_FILE_LOAD:
                if (argl == X509_FILETYPE_DEFAULT)
                        {
-                       file = (char *)Getenv(X509_get_default_cert_file_env());
+                       file = (char *)getenv(X509_get_default_cert_file_env());
                        if (file)
                                ok = (X509_load_cert_crl_file(ctx,file,
                                              X509_FILETYPE_PEM) != 0);
index c34689a..e6f8a40 100644 (file)
@@ -157,12 +157,12 @@ typedef struct X509_val_st
        ASN1_TIME *notAfter;
        } X509_VAL;
 
-typedef struct X509_pubkey_st
+struct X509_pubkey_st
        {
        X509_ALGOR *algor;
        ASN1_BIT_STRING *public_key;
        EVP_PKEY *pkey;
-       } X509_PUBKEY;
+       };
 
 typedef struct X509_sig_st
        {
@@ -191,7 +191,9 @@ struct X509_name_st
 #else
        char *bytes;
 #endif
-       unsigned long hash; /* Keep the hash around for lookups */
+/*     unsigned long hash; Keep the hash around for lookups */
+       unsigned char *canon_enc;
+       int canon_enclen;
        } /* X509_NAME */;
 
 DECLARE_STACK_OF(X509_NAME)
@@ -291,8 +293,11 @@ struct x509_st
        unsigned long ex_xkusage;
        unsigned long ex_nscert;
        ASN1_OCTET_STRING *skid;
-       struct AUTHORITY_KEYID_st *akid;
+       AUTHORITY_KEYID *akid;
        X509_POLICY_CACHE *policy_cache;
+       STACK_OF(DIST_POINT) *crldp;
+       STACK_OF(GENERAL_NAME) *altname;
+       NAME_CONSTRAINTS *nc;
 #ifndef OPENSSL_NO_RFC3779
        STACK_OF(IPAddressFamily) *rfc3779_addr;
        struct ASIdentifiers_st *rfc3779_asid;
@@ -335,10 +340,11 @@ typedef struct x509_cert_pair_st {
 #define X509_TRUST_OBJECT_SIGN 5
 #define X509_TRUST_OCSP_SIGN   6
 #define X509_TRUST_OCSP_REQUEST        7
+#define X509_TRUST_TSA         8
 
 /* Keep these up to date! */
 #define X509_TRUST_MIN         1
-#define X509_TRUST_MAX         7
+#define X509_TRUST_MAX         8
 
 
 /* trust_flags values */
@@ -425,13 +431,17 @@ typedef struct x509_cert_pair_st {
                        XN_FLAG_FN_LN | \
                        XN_FLAG_FN_ALIGN)
 
-typedef struct X509_revoked_st
+struct x509_revoked_st
        {
        ASN1_INTEGER *serialNumber;
        ASN1_TIME *revocationDate;
        STACK_OF(X509_EXTENSION) /* optional */ *extensions;
+       /* Set up if indirect CRL */
+       STACK_OF(GENERAL_NAME) *issuer;
+       /* Revocation reason */
+       int reason;
        int sequence; /* load sequence */
-       } X509_REVOKED;
+       };
 
 DECLARE_STACK_OF(X509_REVOKED)
 DECLARE_ASN1_SET_OF(X509_REVOKED)
@@ -455,6 +465,22 @@ struct X509_crl_st
        X509_ALGOR *sig_alg;
        ASN1_BIT_STRING *signature;
        int references;
+       int flags;
+       /* Copies of various extensions */
+       AUTHORITY_KEYID *akid;
+       ISSUING_DIST_POINT *idp;
+       /* Convenient breakdown of IDP */
+       int idp_flags;
+       int idp_reasons;
+       /* CRL and base CRL numbers for delta processing */
+       ASN1_INTEGER *crl_number;
+       ASN1_INTEGER *base_crl_number;
+#ifndef OPENSSL_NO_SHA
+       unsigned char sha1_hash[SHA_DIGEST_LENGTH];
+#endif
+       STACK_OF(GENERAL_NAMES) *issuers;
+       const X509_CRL_METHOD *meth;
+       void *meth_data;
        } /* X509_CRL */;
 
 DECLARE_STACK_OF(X509_CRL)
@@ -553,18 +579,19 @@ X509_ALGOR *prf;
 
 /* PKCS#8 private key info structure */
 
-typedef struct pkcs8_priv_key_info_st
+struct pkcs8_priv_key_info_st
         {
         int broken;     /* Flag for various broken formats */
 #define PKCS8_OK               0
 #define PKCS8_NO_OCTET         1
 #define PKCS8_EMBEDDED_PARAM   2
 #define PKCS8_NS_DB            3
+#define PKCS8_NEG_PRIVKEY      4
         ASN1_INTEGER *version;
         X509_ALGOR *pkeyalg;
         ASN1_TYPE *pkey; /* Should be OCTET STRING but some are broken */
         STACK_OF(X509_ATTRIBUTE) *attributes;
-        } PKCS8_PRIV_KEY_INFO;
+        };
 
 #ifdef  __cplusplus
 }
@@ -577,151 +604,6 @@ typedef struct pkcs8_priv_key_info_st
 extern "C" {
 #endif
 
-#ifdef SSLEAY_MACROS
-#define X509_verify(a,r) ASN1_verify((int (*)())i2d_X509_CINF,a->sig_alg,\
-       a->signature,(char *)a->cert_info,r)
-#define X509_REQ_verify(a,r) ASN1_verify((int (*)())i2d_X509_REQ_INFO, \
-       a->sig_alg,a->signature,(char *)a->req_info,r)
-#define X509_CRL_verify(a,r) ASN1_verify((int (*)())i2d_X509_CRL_INFO, \
-       a->sig_alg, a->signature,(char *)a->crl,r)
-
-#define X509_sign(x,pkey,md) \
-       ASN1_sign((int (*)())i2d_X509_CINF, x->cert_info->signature, \
-               x->sig_alg, x->signature, (char *)x->cert_info,pkey,md)
-#define X509_REQ_sign(x,pkey,md) \
-       ASN1_sign((int (*)())i2d_X509_REQ_INFO,x->sig_alg, NULL, \
-               x->signature, (char *)x->req_info,pkey,md)
-#define X509_CRL_sign(x,pkey,md) \
-       ASN1_sign((int (*)())i2d_X509_CRL_INFO,x->crl->sig_alg,x->sig_alg, \
-               x->signature, (char *)x->crl,pkey,md)
-#define NETSCAPE_SPKI_sign(x,pkey,md) \
-       ASN1_sign((int (*)())i2d_NETSCAPE_SPKAC, x->sig_algor,NULL, \
-               x->signature, (char *)x->spkac,pkey,md)
-
-#define X509_dup(x509) (X509 *)ASN1_dup((int (*)())i2d_X509, \
-               (char *(*)())d2i_X509,(char *)x509)
-#define X509_ATTRIBUTE_dup(xa) (X509_ATTRIBUTE *)ASN1_dup(\
-               (int (*)())i2d_X509_ATTRIBUTE, \
-               (char *(*)())d2i_X509_ATTRIBUTE,(char *)xa)
-#define X509_EXTENSION_dup(ex) (X509_EXTENSION *)ASN1_dup( \
-               (int (*)())i2d_X509_EXTENSION, \
-               (char *(*)())d2i_X509_EXTENSION,(char *)ex)
-#define d2i_X509_fp(fp,x509) (X509 *)ASN1_d2i_fp((char *(*)())X509_new, \
-               (char *(*)())d2i_X509, (fp),(unsigned char **)(x509))
-#define i2d_X509_fp(fp,x509) ASN1_i2d_fp(i2d_X509,fp,(unsigned char *)x509)
-#define d2i_X509_bio(bp,x509) (X509 *)ASN1_d2i_bio((char *(*)())X509_new, \
-               (char *(*)())d2i_X509, (bp),(unsigned char **)(x509))
-#define i2d_X509_bio(bp,x509) ASN1_i2d_bio(i2d_X509,bp,(unsigned char *)x509)
-
-#define X509_CRL_dup(crl) (X509_CRL *)ASN1_dup((int (*)())i2d_X509_CRL, \
-               (char *(*)())d2i_X509_CRL,(char *)crl)
-#define d2i_X509_CRL_fp(fp,crl) (X509_CRL *)ASN1_d2i_fp((char *(*)()) \
-               X509_CRL_new,(char *(*)())d2i_X509_CRL, (fp),\
-               (unsigned char **)(crl))
-#define i2d_X509_CRL_fp(fp,crl) ASN1_i2d_fp(i2d_X509_CRL,fp,\
-               (unsigned char *)crl)
-#define d2i_X509_CRL_bio(bp,crl) (X509_CRL *)ASN1_d2i_bio((char *(*)()) \
-               X509_CRL_new,(char *(*)())d2i_X509_CRL, (bp),\
-               (unsigned char **)(crl))
-#define i2d_X509_CRL_bio(bp,crl) ASN1_i2d_bio(i2d_X509_CRL,bp,\
-               (unsigned char *)crl)
-
-#define PKCS7_dup(p7) (PKCS7 *)ASN1_dup((int (*)())i2d_PKCS7, \
-               (char *(*)())d2i_PKCS7,(char *)p7)
-#define d2i_PKCS7_fp(fp,p7) (PKCS7 *)ASN1_d2i_fp((char *(*)()) \
-               PKCS7_new,(char *(*)())d2i_PKCS7, (fp),\
-               (unsigned char **)(p7))
-#define i2d_PKCS7_fp(fp,p7) ASN1_i2d_fp(i2d_PKCS7,fp,\
-               (unsigned char *)p7)
-#define d2i_PKCS7_bio(bp,p7) (PKCS7 *)ASN1_d2i_bio((char *(*)()) \
-               PKCS7_new,(char *(*)())d2i_PKCS7, (bp),\
-               (unsigned char **)(p7))
-#define i2d_PKCS7_bio(bp,p7) ASN1_i2d_bio(i2d_PKCS7,bp,\
-               (unsigned char *)p7)
-
-#define X509_REQ_dup(req) (X509_REQ *)ASN1_dup((int (*)())i2d_X509_REQ, \
-               (char *(*)())d2i_X509_REQ,(char *)req)
-#define d2i_X509_REQ_fp(fp,req) (X509_REQ *)ASN1_d2i_fp((char *(*)())\
-               X509_REQ_new, (char *(*)())d2i_X509_REQ, (fp),\
-               (unsigned char **)(req))
-#define i2d_X509_REQ_fp(fp,req) ASN1_i2d_fp(i2d_X509_REQ,fp,\
-               (unsigned char *)req)
-#define d2i_X509_REQ_bio(bp,req) (X509_REQ *)ASN1_d2i_bio((char *(*)())\
-               X509_REQ_new, (char *(*)())d2i_X509_REQ, (bp),\
-               (unsigned char **)(req))
-#define i2d_X509_REQ_bio(bp,req) ASN1_i2d_bio(i2d_X509_REQ,bp,\
-               (unsigned char *)req)
-
-#define RSAPublicKey_dup(rsa) (RSA *)ASN1_dup((int (*)())i2d_RSAPublicKey, \
-               (char *(*)())d2i_RSAPublicKey,(char *)rsa)
-#define RSAPrivateKey_dup(rsa) (RSA *)ASN1_dup((int (*)())i2d_RSAPrivateKey, \
-               (char *(*)())d2i_RSAPrivateKey,(char *)rsa)
-
-#define d2i_RSAPrivateKey_fp(fp,rsa) (RSA *)ASN1_d2i_fp((char *(*)())\
-               RSA_new,(char *(*)())d2i_RSAPrivateKey, (fp), \
-               (unsigned char **)(rsa))
-#define i2d_RSAPrivateKey_fp(fp,rsa) ASN1_i2d_fp(i2d_RSAPrivateKey,fp, \
-               (unsigned char *)rsa)
-#define d2i_RSAPrivateKey_bio(bp,rsa) (RSA *)ASN1_d2i_bio((char *(*)())\
-               RSA_new,(char *(*)())d2i_RSAPrivateKey, (bp), \
-               (unsigned char **)(rsa))
-#define i2d_RSAPrivateKey_bio(bp,rsa) ASN1_i2d_bio(i2d_RSAPrivateKey,bp, \
-               (unsigned char *)rsa)
-
-#define d2i_RSAPublicKey_fp(fp,rsa) (RSA *)ASN1_d2i_fp((char *(*)())\
-               RSA_new,(char *(*)())d2i_RSAPublicKey, (fp), \
-               (unsigned char **)(rsa))
-#define i2d_RSAPublicKey_fp(fp,rsa) ASN1_i2d_fp(i2d_RSAPublicKey,fp, \
-               (unsigned char *)rsa)
-#define d2i_RSAPublicKey_bio(bp,rsa) (RSA *)ASN1_d2i_bio((char *(*)())\
-               RSA_new,(char *(*)())d2i_RSAPublicKey, (bp), \
-               (unsigned char **)(rsa))
-#define i2d_RSAPublicKey_bio(bp,rsa) ASN1_i2d_bio(i2d_RSAPublicKey,bp, \
-               (unsigned char *)rsa)
-
-#define d2i_DSAPrivateKey_fp(fp,dsa) (DSA *)ASN1_d2i_fp((char *(*)())\
-               DSA_new,(char *(*)())d2i_DSAPrivateKey, (fp), \
-               (unsigned char **)(dsa))
-#define i2d_DSAPrivateKey_fp(fp,dsa) ASN1_i2d_fp(i2d_DSAPrivateKey,fp, \
-               (unsigned char *)dsa)
-#define d2i_DSAPrivateKey_bio(bp,dsa) (DSA *)ASN1_d2i_bio((char *(*)())\
-               DSA_new,(char *(*)())d2i_DSAPrivateKey, (bp), \
-               (unsigned char **)(dsa))
-#define i2d_DSAPrivateKey_bio(bp,dsa) ASN1_i2d_bio(i2d_DSAPrivateKey,bp, \
-               (unsigned char *)dsa)
-
-#define d2i_ECPrivateKey_fp(fp,ecdsa) (EC_KEY *)ASN1_d2i_fp((char *(*)())\
-               EC_KEY_new,(char *(*)())d2i_ECPrivateKey, (fp), \
-               (unsigned char **)(ecdsa))
-#define i2d_ECPrivateKey_fp(fp,ecdsa) ASN1_i2d_fp(i2d_ECPrivateKey,fp, \
-               (unsigned char *)ecdsa)
-#define d2i_ECPrivateKey_bio(bp,ecdsa) (EC_KEY *)ASN1_d2i_bio((char *(*)())\
-               EC_KEY_new,(char *(*)())d2i_ECPrivateKey, (bp), \
-               (unsigned char **)(ecdsa))
-#define i2d_ECPrivateKey_bio(bp,ecdsa) ASN1_i2d_bio(i2d_ECPrivateKey,bp, \
-               (unsigned char *)ecdsa)
-
-#define X509_ALGOR_dup(xn) (X509_ALGOR *)ASN1_dup((int (*)())i2d_X509_ALGOR,\
-               (char *(*)())d2i_X509_ALGOR,(char *)xn)
-
-#define X509_NAME_dup(xn) (X509_NAME *)ASN1_dup((int (*)())i2d_X509_NAME, \
-               (char *(*)())d2i_X509_NAME,(char *)xn)
-#define X509_NAME_ENTRY_dup(ne) (X509_NAME_ENTRY *)ASN1_dup( \
-               (int (*)())i2d_X509_NAME_ENTRY, \
-               (char *(*)())d2i_X509_NAME_ENTRY,\
-               (char *)ne)
-
-#define X509_digest(data,type,md,len) \
-       ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len)
-#define X509_NAME_digest(data,type,md,len) \
-       ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len)
-#ifndef PKCS7_ISSUER_AND_SERIAL_digest
-#define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \
-       ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\
-               (char *)data,md,len)
-#endif
-#endif
-
 #define X509_EXT_PACK_UNKNOWN  1
 #define X509_EXT_PACK_STRING   2
 
@@ -742,6 +624,18 @@ extern "C" {
 #define                X509_CRL_get_issuer(x) ((x)->crl->issuer)
 #define                X509_CRL_get_REVOKED(x) ((x)->crl->revoked)
 
+void X509_CRL_set_default_method(const X509_CRL_METHOD *meth);
+X509_CRL_METHOD *X509_CRL_METHOD_new(
+       int (*crl_init)(X509_CRL *crl),
+       int (*crl_free)(X509_CRL *crl),
+       int (*crl_lookup)(X509_CRL *crl, X509_REVOKED **ret,
+                               ASN1_INTEGER *ser, X509_NAME *issuer),
+       int (*crl_verify)(X509_CRL *crl, EVP_PKEY *pk));
+void X509_CRL_METHOD_free(X509_CRL_METHOD *m);
+
+void X509_CRL_set_meth_data(X509_CRL *crl, void *dat);
+void *X509_CRL_get_meth_data(X509_CRL *crl);
+
 /* This one is only used so that a binary form can output, as in
  * i2d_X509_NAME(X509_get_X509_PUBKEY(x),&buf) */
 #define        X509_get_X509_PUBKEY(x) ((x)->cert_info->key)
@@ -749,7 +643,6 @@ extern "C" {
 
 const char *X509_verify_cert_error_string(long n);
 
-#ifndef SSLEAY_MACROS
 #ifndef OPENSSL_NO_EVP
 int X509_verify(X509 *a, EVP_PKEY *r);
 
@@ -874,11 +767,11 @@ void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval,
 X509_NAME *X509_NAME_dup(X509_NAME *xn);
 X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne);
 
-#endif /* !SSLEAY_MACROS */
-
-int            X509_cmp_time(ASN1_TIME *s, time_t *t);
-int            X509_cmp_current_time(ASN1_TIME *s);
+int            X509_cmp_time(const ASN1_TIME *s, time_t *t);
+int            X509_cmp_current_time(const ASN1_TIME *s);
 ASN1_TIME *    X509_time_adj(ASN1_TIME *s, long adj, time_t *t);
+ASN1_TIME *    X509_time_adj_ex(ASN1_TIME *s,
+                               int offset_day, long offset_sec, time_t *t);
 ASN1_TIME *    X509_gmtime_adj(ASN1_TIME *s, long adj);
 
 const char *   X509_get_default_cert_area(void );
@@ -966,6 +859,9 @@ DECLARE_ASN1_FUNCTIONS(X509_CRL_INFO)
 DECLARE_ASN1_FUNCTIONS(X509_CRL)
 
 int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev);
+int X509_CRL_get0_by_serial(X509_CRL *crl,
+               X509_REVOKED **ret, ASN1_INTEGER *serial);
+int X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret, X509 *x);
 
 X509_PKEY *    X509_PKEY_new(void );
 void           X509_PKEY_free(X509_PKEY *a);
@@ -1009,8 +905,8 @@ int                X509_set_issuer_name(X509 *x, X509_NAME *name);
 X509_NAME *    X509_get_issuer_name(X509 *a);
 int            X509_set_subject_name(X509 *x, X509_NAME *name);
 X509_NAME *    X509_get_subject_name(X509 *a);
-int            X509_set_notBefore(X509 *x, ASN1_TIME *tm);
-int            X509_set_notAfter(X509 *x, ASN1_TIME *tm);
+int            X509_set_notBefore(X509 *x, const ASN1_TIME *tm);
+int            X509_set_notAfter(X509 *x, const ASN1_TIME *tm);
 int            X509_set_pubkey(X509 *x, EVP_PKEY *pkey);
 EVP_PKEY *     X509_get_pubkey(X509 *x);
 ASN1_BIT_STRING * X509_get0_pubkey_bitstr(const X509 *x);
@@ -1047,8 +943,8 @@ int X509_REQ_add1_attr_by_txt(X509_REQ *req,
 
 int X509_CRL_set_version(X509_CRL *x, long version);
 int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name);
-int X509_CRL_set_lastUpdate(X509_CRL *x, ASN1_TIME *tm);
-int X509_CRL_set_nextUpdate(X509_CRL *x, ASN1_TIME *tm);
+int X509_CRL_set_lastUpdate(X509_CRL *x, const ASN1_TIME *tm);
+int X509_CRL_set_nextUpdate(X509_CRL *x, const ASN1_TIME *tm);
 int X509_CRL_sort(X509_CRL *crl);
 
 int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial);
@@ -1067,11 +963,18 @@ unsigned long    X509_issuer_name_hash(X509 *a);
 int            X509_subject_name_cmp(const X509 *a, const X509 *b);
 unsigned long  X509_subject_name_hash(X509 *x);
 
+#ifndef OPENSSL_NO_MD5
+unsigned long  X509_issuer_name_hash_old(X509 *a);
+unsigned long  X509_subject_name_hash_old(X509 *x);
+#endif
+
 int            X509_cmp(const X509 *a, const X509 *b);
 int            X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b);
 unsigned long  X509_NAME_hash(X509_NAME *x);
+unsigned long  X509_NAME_hash_old(X509_NAME *x);
 
 int            X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b);
+int            X509_CRL_match(const X509_CRL *a, const X509_CRL *b);
 #ifndef OPENSSL_NO_FP_API
 int            X509_print_ex_fp(FILE *bp,X509 *x, unsigned long nmflag, unsigned long cflag);
 int            X509_print_fp(FILE *bp,X509 *x);
@@ -1247,9 +1150,16 @@ DECLARE_ASN1_FUNCTIONS(PBEPARAM)
 DECLARE_ASN1_FUNCTIONS(PBE2PARAM)
 DECLARE_ASN1_FUNCTIONS(PBKDF2PARAM)
 
-X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt, int saltlen);
+int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter,
+                               const unsigned char *salt, int saltlen);
+
+X509_ALGOR *PKCS5_pbe_set(int alg, int iter,
+                               const unsigned char *salt, int saltlen);
 X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
                                         unsigned char *salt, int saltlen);
+X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter,
+                                unsigned char *salt, int saltlen,
+                                unsigned char *aiv, int prf_nid);
 
 /* PKCS#8 utilities */
 
@@ -1260,6 +1170,22 @@ PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey);
 PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken);
 PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken);
 
+int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj,
+                       int version, int ptype, void *pval,
+                               unsigned char *penc, int penclen);
+int PKCS8_pkey_get0(ASN1_OBJECT **ppkalg,
+               const unsigned char **pk, int *ppklen,
+               X509_ALGOR **pa,
+               PKCS8_PRIV_KEY_INFO *p8);
+
+int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj,
+                                       int ptype, void *pval,
+                                       unsigned char *penc, int penclen);
+int X509_PUBKEY_get0_param(ASN1_OBJECT **ppkalg,
+               const unsigned char **pk, int *ppklen,
+               X509_ALGOR **pa,
+               X509_PUBKEY *pub);
+
 int X509_check_trust(X509 *x, int id, int flags);
 int X509_TRUST_get_count(void);
 X509_TRUST * X509_TRUST_get0(int idx);
@@ -1339,7 +1265,10 @@ void ERR_load_X509_strings(void);
 #define X509_R_KEY_VALUES_MISMATCH                      116
 #define X509_R_LOADING_CERT_DIR                                 103
 #define X509_R_LOADING_DEFAULTS                                 104
+#define X509_R_METHOD_NOT_SUPPORTED                     124
 #define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY             105
+#define X509_R_PUBLIC_KEY_DECODE_ERROR                  125
+#define X509_R_PUBLIC_KEY_ENCODE_ERROR                  126
 #define X509_R_SHOULD_RETRY                             106
 #define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN       107
 #define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY           108
index 2faf925..4bc9da0 100644 (file)
@@ -116,6 +116,13 @@ int X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b)
        return(X509_NAME_cmp(a->crl->issuer,b->crl->issuer));
        }
 
+#ifndef OPENSSL_NO_SHA
+int X509_CRL_match(const X509_CRL *a, const X509_CRL *b)
+       {
+       return memcmp(a->sha1_hash, b->sha1_hash, 20);
+       }
+#endif
+
 X509_NAME *X509_get_issuer_name(X509 *a)
        {
        return(a->cert_info->issuer);
@@ -126,6 +133,13 @@ unsigned long X509_issuer_name_hash(X509 *x)
        return(X509_NAME_hash(x->cert_info->issuer));
        }
 
+#ifndef OPENSSL_NO_MD5
+unsigned long X509_issuer_name_hash_old(X509 *x)
+       {
+       return(X509_NAME_hash_old(x->cert_info->issuer));
+       }
+#endif
+
 X509_NAME *X509_get_subject_name(X509 *a)
        {
        return(a->cert_info->subject);
@@ -141,6 +155,13 @@ unsigned long X509_subject_name_hash(X509 *x)
        return(X509_NAME_hash(x->cert_info->subject));
        }
 
+#ifndef OPENSSL_NO_MD5
+unsigned long X509_subject_name_hash_old(X509 *x)
+       {
+       return(X509_NAME_hash_old(x->cert_info->subject));
+       }
+#endif
+
 #ifndef OPENSSL_NO_SHA
 /* Compare two certificates: they must be identical for
  * this to work. NB: Although "cmp" operations are generally
@@ -162,177 +183,63 @@ int X509_cmp(const X509 *a, const X509 *b)
 #endif
 
 
-/* Case insensitive string comparision */
-static int nocase_cmp(const ASN1_STRING *a, const ASN1_STRING *b)
-{
-       int i;
-
-       if (a->length != b->length)
-               return (a->length - b->length);
-
-       for (i=0; i<a->length; i++)
-       {
-               int ca, cb;
-
-               ca = tolower(a->data[i]);
-               cb = tolower(b->data[i]);
-
-               if (ca != cb)
-                       return(ca-cb);
-       }
-       return 0;
-}
-
-/* Case insensitive string comparision with space normalization 
- * Space normalization - ignore leading, trailing spaces, 
- *       multiple spaces between characters are replaced by single space  
- */
-static int nocase_spacenorm_cmp(const ASN1_STRING *a, const ASN1_STRING *b)
-{
-       unsigned char *pa = NULL, *pb = NULL;
-       int la, lb;
-       
-       la = a->length;
-       lb = b->length;
-       pa = a->data;
-       pb = b->data;
-
-       /* skip leading spaces */
-       while (la > 0 && isspace(*pa))
-       {
-               la--;
-               pa++;
-       }
-       while (lb > 0 && isspace(*pb))
-       {
-               lb--;
-               pb++;
-       }
-
-       /* skip trailing spaces */
-       while (la > 0 && isspace(pa[la-1]))
-               la--;
-       while (lb > 0 && isspace(pb[lb-1]))
-               lb--;
-
-       /* compare strings with space normalization */
-       while (la > 0 && lb > 0)
+int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b)
        {
-               int ca, cb;
-
-               /* compare character */
-               ca = tolower(*pa);
-               cb = tolower(*pb);
-               if (ca != cb)
-                       return (ca - cb);
+       int ret;
 
-               pa++; pb++;
-               la--; lb--;
+       /* Ensure canonical encoding is present and up to date */
 
-               if (la <= 0 || lb <= 0)
-                       break;
+       if (!a->canon_enc || a->modified)
+               {
+               ret = i2d_X509_NAME((X509_NAME *)a, NULL);
+               if (ret < 0)
+                       return -2;
+               }
 
-               /* is white space next character ? */
-               if (isspace(*pa) && isspace(*pb))
+       if (!b->canon_enc || b->modified)
                {
-                       /* skip remaining white spaces */
-                       while (la > 0 && isspace(*pa))
-                       {
-                               la--;
-                               pa++;
-                       }
-                       while (lb > 0 && isspace(*pb))
-                       {
-                               lb--;
-                               pb++;
-                       }
+               ret = i2d_X509_NAME((X509_NAME *)b, NULL);
+               if (ret < 0)
+                       return -2;
                }
-       }
-       if (la > 0 || lb > 0)
-               return la - lb;
 
-       return 0;
-}
+       ret = a->canon_enclen - b->canon_enclen;
 
-static int asn1_string_memcmp(ASN1_STRING *a, ASN1_STRING *b)
-       {
-       int j;
-       j = a->length - b->length;
-       if (j)
-               return j;
-       return memcmp(a->data, b->data, a->length);
-       }
+       if (ret)
+               return ret;
 
-#define STR_TYPE_CMP (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_UTF8STRING)
+       return memcmp(a->canon_enc, b->canon_enc, a->canon_enclen);
 
-int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b)
-       {
-       int i,j;
-       X509_NAME_ENTRY *na,*nb;
+       }
 
-       unsigned long nabit, nbbit;
+unsigned long X509_NAME_hash(X509_NAME *x)
+       {
+       unsigned long ret=0;
+       unsigned char md[SHA_DIGEST_LENGTH];
 
-       j = sk_X509_NAME_ENTRY_num(a->entries)
-                 - sk_X509_NAME_ENTRY_num(b->entries);
-       if (j)
-               return j;
-       for (i=sk_X509_NAME_ENTRY_num(a->entries)-1; i>=0; i--)
-               {
-               na=sk_X509_NAME_ENTRY_value(a->entries,i);
-               nb=sk_X509_NAME_ENTRY_value(b->entries,i);
-               j=na->value->type-nb->value->type;
-               if (j)
-                       {
-                       nabit = ASN1_tag2bit(na->value->type);
-                       nbbit = ASN1_tag2bit(nb->value->type);
-                       if (!(nabit & STR_TYPE_CMP) ||
-                               !(nbbit & STR_TYPE_CMP))
-                               return j;
-                       if (!asn1_string_memcmp(na->value, nb->value))
-                               j = 0;
-                       }
-               else if (na->value->type == V_ASN1_PRINTABLESTRING)
-                       j=nocase_spacenorm_cmp(na->value, nb->value);
-               else if (na->value->type == V_ASN1_IA5STRING
-                       && OBJ_obj2nid(na->object) == NID_pkcs9_emailAddress)
-                       j=nocase_cmp(na->value, nb->value);
-               else
-                       j = asn1_string_memcmp(na->value, nb->value);
-               if (j) return(j);
-               j=na->set-nb->set;
-               if (j) return(j);
-               }
+       /* Make sure X509_NAME structure contains valid cached encoding */
+       i2d_X509_NAME(x,NULL);
+       EVP_Digest(x->canon_enc, x->canon_enclen, md, NULL, EVP_sha1(), NULL);
 
-       /* We will check the object types after checking the values
-        * since the values will more often be different than the object
-        * types. */
-       for (i=sk_X509_NAME_ENTRY_num(a->entries)-1; i>=0; i--)
-               {
-               na=sk_X509_NAME_ENTRY_value(a->entries,i);
-               nb=sk_X509_NAME_ENTRY_value(b->entries,i);
-               j=OBJ_cmp(na->object,nb->object);
-               if (j) return(j);
-               }
-       return(0);
+       ret=(   ((unsigned long)md[0]     )|((unsigned long)md[1]<<8L)|
+               ((unsigned long)md[2]<<16L)|((unsigned long)md[3]<<24L)
+               )&0xffffffffL;
+       return(ret);
        }
 
+
 #ifndef OPENSSL_NO_MD5
 /* I now DER encode the name and hash it.  Since I cache the DER encoding,
  * this is reasonably efficient. */
-unsigned long X509_NAME_hash(X509_NAME *x)
+
+unsigned long X509_NAME_hash_old(X509_NAME *x)
        {
        unsigned long ret=0;
        unsigned char md[16];
-       EVP_MD_CTX md_ctx;
 
        /* Make sure X509_NAME structure contains valid cached encoding */
        i2d_X509_NAME(x,NULL);
-       EVP_MD_CTX_init(&md_ctx);
-       EVP_MD_CTX_set_flags(&md_ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
-       EVP_DigestInit_ex(&md_ctx, EVP_md5(), NULL);
-       EVP_DigestUpdate(&md_ctx, x->bytes->data, x->bytes->length);
-       EVP_DigestFinal_ex(&md_ctx,md,NULL);
-       EVP_MD_CTX_cleanup(&md_ctx);
+       EVP_Digest(x->bytes->data, x->bytes->length, md, NULL, EVP_md5(), NULL);
 
        ret=(   ((unsigned long)md[0]     )|((unsigned long)md[1]<<8L)|
                ((unsigned long)md[2]<<16L)|((unsigned long)md[3]<<24L)
@@ -393,14 +300,19 @@ ASN1_BIT_STRING *X509_get0_pubkey_bitstr(const X509 *x)
 
 int X509_check_private_key(X509 *x, EVP_PKEY *k)
        {
-       EVP_PKEY *xk=NULL;
-       int ok=0;
+       EVP_PKEY *xk;
+       int ret;
 
        xk=X509_get_pubkey(x);
-       switch (EVP_PKEY_cmp(xk, k))
+
+       if (xk)
+               ret = EVP_PKEY_cmp(xk, k);
+       else
+               ret = -2;
+
+       switch (ret)
                {
        case 1:
-               ok=1;
                break;
        case 0:
                X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH);
@@ -409,24 +321,11 @@ int X509_check_private_key(X509 *x, EVP_PKEY *k)
                X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_TYPE_MISMATCH);
                break;
        case -2:
-#ifndef OPENSSL_NO_EC
-               if (k->type == EVP_PKEY_EC)
-                       {
-                       X509err(X509_F_X509_CHECK_PRIVATE_KEY, ERR_R_EC_LIB);
-                       break;
-                       }
-#endif
-#ifndef OPENSSL_NO_DH
-               if (k->type == EVP_PKEY_DH)
-                       {
-                       /* No idea */
-                       X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_CANT_CHECK_DH_KEY);
-                       break;
-                       }
-#endif
                X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_UNKNOWN_KEY_TYPE);
                }
-
-       EVP_PKEY_free(xk);
-       return(ok);
+       if (xk)
+               EVP_PKEY_free(xk);
+       if (ret > 0)
+               return 1;
+       return 0;
        }
index fb37729..a01402f 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/x509/x509_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -132,7 +132,10 @@ static ERR_STRING_DATA X509_str_reasons[]=
 {ERR_REASON(X509_R_KEY_VALUES_MISMATCH)  ,"key values mismatch"},
 {ERR_REASON(X509_R_LOADING_CERT_DIR)     ,"loading cert dir"},
 {ERR_REASON(X509_R_LOADING_DEFAULTS)     ,"loading defaults"},
+{ERR_REASON(X509_R_METHOD_NOT_SUPPORTED) ,"method not supported"},
 {ERR_REASON(X509_R_NO_CERT_SET_FOR_US_TO_VERIFY),"no cert set for us to verify"},
+{ERR_REASON(X509_R_PUBLIC_KEY_DECODE_ERROR),"public key decode error"},
+{ERR_REASON(X509_R_PUBLIC_KEY_ENCODE_ERROR),"public key encode error"},
 {ERR_REASON(X509_R_SHOULD_RETRY)         ,"should retry"},
 {ERR_REASON(X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN),"unable to find parameters in chain"},
 {ERR_REASON(X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY),"unable to get certs public key"},
index b486171..3a6e04a 100644 (file)
@@ -196,6 +196,8 @@ X509_STORE *X509_STORE_new(void)
        ret->get_crl = 0;
        ret->check_crl = 0;
        ret->cert_crl = 0;
+       ret->lookup_certs = 0;
+       ret->lookup_crls = 0;
        ret->cleanup = 0;
 
        if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE, ret, &ret->ex_data))
@@ -296,7 +298,7 @@ int X509_STORE_get_by_subject(X509_STORE_CTX *vs, int type, X509_NAME *name,
        tmp=X509_OBJECT_retrieve_by_subject(ctx->objs,type,name);
        CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
 
-       if (tmp == NULL)
+       if (tmp == NULL || type == X509_LU_CRL)
                {
                for (i=vs->current_method; i<sk_X509_LOOKUP_num(ctx->get_cert_methods); i++)
                        {
@@ -421,14 +423,15 @@ void X509_OBJECT_free_contents(X509_OBJECT *a)
                }
        }
 
-int X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, int type,
-            X509_NAME *name)
+static int x509_object_idx_cnt(STACK_OF(X509_OBJECT) *h, int type,
+            X509_NAME *name, int *pnmatch)
        {
        X509_OBJECT stmp;
        X509 x509_s;
        X509_CINF cinf_s;
        X509_CRL crl_s;
        X509_CRL_INFO crl_info_s;
+       int idx;
 
        stmp.type=type;
        switch (type)
@@ -448,7 +451,29 @@ int X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, int type,
                return -1;
                }
 
-       return sk_X509_OBJECT_find(h,&stmp);
+       idx = sk_X509_OBJECT_find(h,&stmp);
+       if (idx >= 0 && pnmatch)
+               {
+               int tidx;
+               const X509_OBJECT *tobj, *pstmp;
+               *pnmatch = 1;
+               pstmp = &stmp;
+               for (tidx = idx + 1; tidx < sk_X509_OBJECT_num(h); tidx++)
+                       {
+                       tobj = sk_X509_OBJECT_value(h, tidx);
+                       if (x509_object_cmp(&tobj, &pstmp))
+                               break;
+                       (*pnmatch)++;
+                       }
+               }
+       return idx;
+       }
+
+
+int X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, int type,
+            X509_NAME *name)
+       {
+       return x509_object_idx_cnt(h, type, name, NULL);
        }
 
 X509_OBJECT *X509_OBJECT_retrieve_by_subject(STACK_OF(X509_OBJECT) *h, int type,
@@ -460,19 +485,125 @@ X509_OBJECT *X509_OBJECT_retrieve_by_subject(STACK_OF(X509_OBJECT) *h, int type,
        return sk_X509_OBJECT_value(h, idx);
        }
 
+STACK_OF(X509)* X509_STORE_get1_certs(X509_STORE_CTX *ctx, X509_NAME *nm)
+       {
+       int i, idx, cnt;
+       STACK_OF(X509) *sk;
+       X509 *x;
+       X509_OBJECT *obj;
+       sk = sk_X509_new_null();
+       CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);
+       idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_X509, nm, &cnt);
+       if (idx < 0)
+               {
+               /* Nothing found in cache: do lookup to possibly add new
+                * objects to cache
+                */
+               X509_OBJECT xobj;
+               CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
+               if (!X509_STORE_get_by_subject(ctx, X509_LU_X509, nm, &xobj))
+                       {
+                       sk_X509_free(sk);
+                       return NULL;
+                       }
+               X509_OBJECT_free_contents(&xobj);
+               CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);
+               idx = x509_object_idx_cnt(ctx->ctx->objs,X509_LU_X509,nm, &cnt);
+               if (idx < 0)
+                       {
+                       CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
+                       sk_X509_free(sk);
+                       return NULL;
+                       }
+               }
+       for (i = 0; i < cnt; i++, idx++)
+               {
+               obj = sk_X509_OBJECT_value(ctx->ctx->objs, idx);
+               x = obj->data.x509;
+               CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509);
+               if (!sk_X509_push(sk, x))
+                       {
+                       CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
+                       X509_free(x);
+                       sk_X509_pop_free(sk, X509_free);
+                       return NULL;
+                       }
+               }
+       CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
+       return sk;
+
+       }
+
+STACK_OF(X509_CRL)* X509_STORE_get1_crls(X509_STORE_CTX *ctx, X509_NAME *nm)
+       {
+       int i, idx, cnt;
+       STACK_OF(X509_CRL) *sk;
+       X509_CRL *x;
+       X509_OBJECT *obj, xobj;
+       sk = sk_X509_CRL_new_null();
+       CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);
+       /* Check cache first */
+       idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_CRL, nm, &cnt);
+
+       /* Always do lookup to possibly add new CRLs to cache
+        */
+       CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
+       if (!X509_STORE_get_by_subject(ctx, X509_LU_CRL, nm, &xobj))
+               {
+               sk_X509_CRL_free(sk);
+               return NULL;
+               }
+       X509_OBJECT_free_contents(&xobj);
+       CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);
+       idx = x509_object_idx_cnt(ctx->ctx->objs,X509_LU_CRL, nm, &cnt);
+       if (idx < 0)
+               {
+               CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
+               sk_X509_CRL_free(sk);
+               return NULL;
+               }
+
+       for (i = 0; i < cnt; i++, idx++)
+               {
+               obj = sk_X509_OBJECT_value(ctx->ctx->objs, idx);
+               x = obj->data.crl;
+               CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509_CRL);
+               if (!sk_X509_CRL_push(sk, x))
+                       {
+                       CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
+                       X509_CRL_free(x);
+                       sk_X509_CRL_pop_free(sk, X509_CRL_free);
+                       return NULL;
+                       }
+               }
+       CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
+       return sk;
+       }
+
 X509_OBJECT *X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h, X509_OBJECT *x)
        {
        int idx, i;
        X509_OBJECT *obj;
        idx = sk_X509_OBJECT_find(h, x);
        if (idx == -1) return NULL;
-       if (x->type != X509_LU_X509) return sk_X509_OBJECT_value(h, idx);
+       if ((x->type != X509_LU_X509) && (x->type != X509_LU_CRL))
+               return sk_X509_OBJECT_value(h, idx);
        for (i = idx; i < sk_X509_OBJECT_num(h); i++)
                {
                obj = sk_X509_OBJECT_value(h, i);
                if (x509_object_cmp((const X509_OBJECT **)&obj, (const X509_OBJECT **)&x))
                        return NULL;
-               if ((x->type != X509_LU_X509) || !X509_cmp(obj->data.x509, x->data.x509))
+               if (x->type == X509_LU_X509)
+                       {
+                       if (!X509_cmp(obj->data.x509, x->data.x509))
+                               return obj;
+                       }
+               else if (x->type == X509_LU_CRL)
+                       {
+                       if (!X509_CRL_match(obj->data.crl, x->data.crl))
+                               return obj;
+                       }
+               else
                        return obj;
                }
        return NULL;
@@ -575,5 +706,11 @@ int X509_STORE_set1_param(X509_STORE *ctx, X509_VERIFY_PARAM *param)
        return X509_VERIFY_PARAM_set1(ctx->param, param);
        }
 
+void X509_STORE_set_verify_cb(X509_STORE *ctx,
+                                 int (*verify_cb)(int, X509_STORE_CTX *))
+       {
+       ctx->verify_cb = verify_cb;
+       }
+
 IMPLEMENT_STACK_OF(X509_LOOKUP)
 IMPLEMENT_STACK_OF(X509_OBJECT)
index 1e718f7..21fed9f 100644 (file)
@@ -72,7 +72,7 @@ int i;
        char *p;
        unsigned char *q;
        BUF_MEM *b=NULL;
-       static char hex[17]="0123456789ABCDEF";
+       static const char hex[17]="0123456789ABCDEF";
        int gs_doit[4];
        char tmp_buf[80];
 #ifdef CHARSET_EBCDIC
index 3872e1f..48183dc 100644 (file)
@@ -61,6 +61,7 @@
 #include <openssl/bn.h>
 #include <openssl/evp.h>
 #include <openssl/asn1.h>
+#include <openssl/asn1t.h>
 #include <openssl/x509.h>
 #include <openssl/objects.h>
 #include <openssl/buffer.h>
@@ -205,10 +206,9 @@ STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req)
        if(!ext || (ext->type != V_ASN1_SEQUENCE))
                return NULL;
        p = ext->value.sequence->data;
-       return d2i_ASN1_SET_OF_X509_EXTENSION(NULL, &p,
-                       ext->value.sequence->length,
-                       d2i_X509_EXTENSION, X509_EXTENSION_free,
-                       V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
+       return (STACK_OF(X509_EXTENSION) *)
+               ASN1_item_d2i(NULL, &p, ext->value.sequence->length,
+                               ASN1_ITEM_rptr(X509_EXTENSIONS));
 }
 
 /* Add a STACK_OF extensions to a certificate request: allow alternative OIDs
@@ -218,8 +218,6 @@ STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req)
 int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts,
                                int nid)
 {
-       unsigned char *p = NULL, *q;
-       long len;
        ASN1_TYPE *at = NULL;
        X509_ATTRIBUTE *attr = NULL;
        if(!(at = ASN1_TYPE_new()) ||
@@ -227,15 +225,10 @@ int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts,
 
        at->type = V_ASN1_SEQUENCE;
        /* Generate encoding of extensions */
-       len = i2d_ASN1_SET_OF_X509_EXTENSION(exts, NULL, i2d_X509_EXTENSION,
-                       V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, IS_SEQUENCE);
-       if(!(p = OPENSSL_malloc(len))) goto err;
-       q = p;
-       i2d_ASN1_SET_OF_X509_EXTENSION(exts, &q, i2d_X509_EXTENSION,
-                       V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, IS_SEQUENCE);
-       at->value.sequence->data = p;
-       p = NULL;
-       at->value.sequence->length = len;
+       at->value.sequence->length = 
+                       ASN1_item_i2d((ASN1_VALUE *)exts,
+                               &at->value.sequence->data,
+                               ASN1_ITEM_rptr(X509_EXTENSIONS));
        if(!(attr = X509_ATTRIBUTE_new())) goto err;
        if(!(attr->value.set = sk_ASN1_TYPE_new_null())) goto err;
        if(!sk_ASN1_TYPE_push(attr->value.set, at)) goto err;
@@ -250,7 +243,6 @@ int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts,
        if(!sk_X509_ATTRIBUTE_push(req->req_info->attributes, attr)) goto err;
        return 1;
        err:
-       if(p) OPENSSL_free(p);
        X509_ATTRIBUTE_free(attr);
        ASN1_TYPE_free(at);
        return 0;
index aaf61ca..4b94fc5 100644 (file)
@@ -104,7 +104,7 @@ int X509_set_subject_name(X509 *x, X509_NAME *name)
        return(X509_NAME_set(&x->cert_info->subject,name));
        }
 
-int X509_set_notBefore(X509 *x, ASN1_TIME *tm)
+int X509_set_notBefore(X509 *x, const ASN1_TIME *tm)
        {
        ASN1_TIME *in;
 
@@ -122,7 +122,7 @@ int X509_set_notBefore(X509 *x, ASN1_TIME *tm)
        return(in != NULL);
        }
 
-int X509_set_notAfter(X509 *x, ASN1_TIME *tm)
+int X509_set_notAfter(X509 *x, const ASN1_TIME *tm)
        {
        ASN1_TIME *in;
 
index ed18700..a6cb9c8 100644 (file)
@@ -84,7 +84,8 @@ static X509_TRUST trstandard[] = {
 {X509_TRUST_EMAIL, 0, trust_1oidany, "S/MIME email", NID_email_protect, NULL},
 {X509_TRUST_OBJECT_SIGN, 0, trust_1oidany, "Object Signer", NID_code_sign, NULL},
 {X509_TRUST_OCSP_SIGN, 0, trust_1oid, "OCSP responder", NID_OCSP_sign, NULL},
-{X509_TRUST_OCSP_REQUEST, 0, trust_1oid, "OCSP request", NID_ad_OCSP, NULL}
+{X509_TRUST_OCSP_REQUEST, 0, trust_1oid, "OCSP request", NID_ad_OCSP, NULL},
+{X509_TRUST_TSA, 0, trust_1oidany, "TSA server", NID_time_stamp, NULL}
 };
 
 #define X509_TRUST_COUNT       (sizeof(trstandard)/sizeof(X509_TRUST))
index 73a8ec7..c44f753 100644 (file)
@@ -162,8 +162,28 @@ const char *X509_verify_cert_error_string(long n)
                return("invalid or inconsistent certificate policy extension");
        case X509_V_ERR_NO_EXPLICIT_POLICY:
                return("no explicit policy");
-       case X509_V_ERR_UNNESTED_RESOURCE:
-               return("RFC 3779 resource not subset of parent's resources");
+       case X509_V_ERR_DIFFERENT_CRL_SCOPE:
+       return("Different CRL scope");
+       case X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE:
+       return("Unsupported extension feature");
+       case X509_V_ERR_UNNESTED_RESOURCE:
+               return("RFC 3779 resource not subset of parent's resources");
+
+       case X509_V_ERR_PERMITTED_VIOLATION:
+               return("permitted subtree violation");
+       case X509_V_ERR_EXCLUDED_VIOLATION:
+               return("excluded subtree violation");
+       case X509_V_ERR_SUBTREE_MINMAX:
+               return("name constraints minimum and maximum not supported");
+       case X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE:
+               return("unsupported name constraint type");
+       case X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX:
+               return("unsupported or invalid name constraint syntax");
+       case X509_V_ERR_UNSUPPORTED_NAME_SYNTAX:
+               return("unsupported or invalid name syntax");
+       case X509_V_ERR_CRL_PATH_VALIDATION_ERROR:
+               return("CRL path validation error");
+
        default:
                BIO_snprintf(buf,sizeof buf,"error number %ld",n);
                return(buf);
index aeb6337..701ec56 100644 (file)
 #include <openssl/x509v3.h>
 #include <openssl/objects.h>
 
+/* CRL score values */
+
+/* No unhandled critical extensions */
+
+#define CRL_SCORE_NOCRITICAL   0x100
+
+/* certificate is within CRL scope */
+
+#define CRL_SCORE_SCOPE                0x080
+
+/* CRL times valid */
+
+#define CRL_SCORE_TIME         0x040
+
+/* Issuer name matches certificate */
+
+#define CRL_SCORE_ISSUER_NAME  0x020
+
+/* If this score or above CRL is probably valid */
+
+#define CRL_SCORE_VALID (CRL_SCORE_NOCRITICAL|CRL_SCORE_TIME|CRL_SCORE_SCOPE)
+
+/* CRL issuer is certificate issuer */
+
+#define CRL_SCORE_ISSUER_CERT  0x018
+
+/* CRL issuer is on certificate path */
+
+#define CRL_SCORE_SAME_PATH    0x008
+
+/* CRL issuer matches CRL AKID */
+
+#define CRL_SCORE_AKID         0x004
+
+/* Have a delta CRL with valid times */
+
+#define CRL_SCORE_TIME_DELTA   0x002
+
 static int null_callback(int ok,X509_STORE_CTX *e);
 static int check_issued(X509_STORE_CTX *ctx, X509 *x, X509 *issuer);
 static X509 *find_issuer(X509_STORE_CTX *ctx, STACK_OF(X509) *sk, X509 *x);
 static int check_chain_extensions(X509_STORE_CTX *ctx);
+static int check_name_constraints(X509_STORE_CTX *ctx);
 static int check_trust(X509_STORE_CTX *ctx);
 static int check_revocation(X509_STORE_CTX *ctx);
 static int check_cert(X509_STORE_CTX *ctx);
 static int check_policy(X509_STORE_CTX *ctx);
+
+static int get_crl_score(X509_STORE_CTX *ctx, X509 **pissuer,
+                       unsigned int *preasons,
+                       X509_CRL *crl, X509 *x);
+static int get_crl_delta(X509_STORE_CTX *ctx,
+                               X509_CRL **pcrl, X509_CRL **pdcrl, X509 *x);
+static void get_delta_sk(X509_STORE_CTX *ctx, X509_CRL **dcrl, int *pcrl_score,
+                       X509_CRL *base, STACK_OF(X509_CRL) *crls);
+static void crl_akid_check(X509_STORE_CTX *ctx, X509_CRL *crl,
+                               X509 **pissuer, int *pcrl_score);
+static int crl_crldp_check(X509 *x, X509_CRL *crl, int crl_score,
+                               unsigned int *preasons);
+static int check_crl_path(X509_STORE_CTX *ctx, X509 *x);
+static int check_crl_chain(X509_STORE_CTX *ctx,
+                       STACK_OF(X509) *cert_path,
+                       STACK_OF(X509) *crl_path);
+
 static int internal_verify(X509_STORE_CTX *ctx);
 const char X509_version[]="X.509" OPENSSL_VERSION_PTEXT;
 
@@ -97,6 +153,7 @@ static int x509_subject_cmp(X509 **a, X509 **b)
 int X509_verify_cert(X509_STORE_CTX *ctx)
        {
        X509 *x,*xtmp,*chain_ss=NULL;
+       X509_NAME *xn;
        int bad_chain = 0;
        X509_VERIFY_PARAM *param = ctx->param;
        int depth,i,ok=0;
@@ -148,6 +205,7 @@ int X509_verify_cert(X509_STORE_CTX *ctx)
                                         */
 
                /* If we are self signed, we break */
+               xn=X509_get_issuer_name(x);
                if (ctx->check_issued(ctx, x,x)) break;
 
                /* If we were passed a cert chain, use it first */
@@ -184,6 +242,7 @@ int X509_verify_cert(X509_STORE_CTX *ctx)
 
        i=sk_X509_num(ctx->chain);
        x=sk_X509_value(ctx->chain,i-1);
+       xn = X509_get_subject_name(x);
        if (ctx->check_issued(ctx, x, x))
                {
                /* we have a self signed certificate */
@@ -232,6 +291,7 @@ int X509_verify_cert(X509_STORE_CTX *ctx)
                if (depth < num) break;
 
                /* If we are self signed, we break */
+               xn=X509_get_issuer_name(x);
                if (ctx->check_issued(ctx,x,x)) break;
 
                ok = ctx->get_issuer(&xtmp, ctx, x);
@@ -250,6 +310,7 @@ int X509_verify_cert(X509_STORE_CTX *ctx)
                }
 
        /* we now have our chain, lets check it... */
+       xn=X509_get_issuer_name(x);
 
        /* Is last certificate looked up self signed? */
        if (!ctx->check_issued(ctx,x,x))
@@ -284,6 +345,12 @@ int X509_verify_cert(X509_STORE_CTX *ctx)
 
        if (!ok) goto end;
 
+       /* Check name constraints */
+
+       ok = check_name_constraints(ctx);
+       
+       if (!ok) goto end;
+
        /* The chain extensions are OK: check trust */
 
        if (param->trust > 0) ok = check_trust(ctx);
@@ -393,8 +460,8 @@ static int check_chain_extensions(X509_STORE_CTX *ctx)
        X509 *x;
        int (*cb)(int xok,X509_STORE_CTX *xctx);
        int proxy_path_length = 0;
-       int allow_proxy_certs =
-               !!(ctx->param->flags & X509_V_FLAG_ALLOW_PROXY_CERTS);
+       int purpose;
+       int allow_proxy_certs;
        cb=ctx->verify_cb;
 
        /* must_be_ca can have 1 of 3 values:
@@ -407,10 +474,22 @@ static int check_chain_extensions(X509_STORE_CTX *ctx)
        */
        must_be_ca = -1;
 
-       /* A hack to keep people who don't want to modify their software
-          happy */
-       if (getenv("OPENSSL_ALLOW_PROXY_CERTS"))
-               allow_proxy_certs = 1;
+       /* CRL path validation */
+       if (ctx->parent)
+               {
+               allow_proxy_certs = 0;
+               purpose = X509_PURPOSE_CRL_SIGN;
+               }
+       else
+               {
+               allow_proxy_certs =
+                       !!(ctx->param->flags & X509_V_FLAG_ALLOW_PROXY_CERTS);
+               /* A hack to keep people who don't want to modify their
+                  software happy */
+               if (getenv("OPENSSL_ALLOW_PROXY_CERTS"))
+                       allow_proxy_certs = 1;
+               purpose = ctx->param->purpose;
+               }
 
        /* Check all untrusted certificates */
        for (i = 0; i < ctx->last_untrusted; i++)
@@ -477,8 +556,7 @@ static int check_chain_extensions(X509_STORE_CTX *ctx)
                        }
                if (ctx->param->purpose > 0)
                        {
-                       ret = X509_check_purpose(x, ctx->param->purpose,
-                               must_be_ca > 0);
+                       ret = X509_check_purpose(x, purpose, must_be_ca > 0);
                        if ((ret == 0)
                                || ((ctx->param->flags & X509_V_FLAG_X509_STRICT)
                                        && (ret != 1)))
@@ -531,6 +609,42 @@ static int check_chain_extensions(X509_STORE_CTX *ctx)
 #endif
 }
 
+static int check_name_constraints(X509_STORE_CTX *ctx)
+       {
+       X509 *x;
+       int i, j, rv;
+       /* Check name constraints for all certificates */
+       for (i = sk_X509_num(ctx->chain) - 1; i >= 0; i--)
+               {
+               x = sk_X509_value(ctx->chain, i);
+               /* Ignore self issued certs unless last in chain */
+               if (i && (x->ex_flags & EXFLAG_SI))
+                       continue;
+               /* Check against constraints for all certificates higher in
+                * chain including trust anchor. Trust anchor not strictly
+                * speaking needed but if it includes constraints it is to be
+                * assumed it expects them to be obeyed.
+                */
+               for (j = sk_X509_num(ctx->chain) - 1; j > i; j--)
+                       {
+                       NAME_CONSTRAINTS *nc = sk_X509_value(ctx->chain, j)->nc;
+                       if (nc)
+                               {
+                               rv = NAME_CONSTRAINTS_check(x, nc);
+                               if (rv != X509_V_OK)
+                                       {
+                                       ctx->error = rv;
+                                       ctx->error_depth = i;
+                                       ctx->current_cert = x;
+                                       if (!ctx->verify_cb(0,ctx))
+                                               return 0;
+                                       }
+                               }
+                       }
+               }
+       return 1;
+       }
+
 static int check_trust(X509_STORE_CTX *ctx)
 {
 #ifdef OPENSSL_NO_CHAIN_VERIFY
@@ -565,7 +679,12 @@ static int check_revocation(X509_STORE_CTX *ctx)
        if (ctx->param->flags & X509_V_FLAG_CRL_CHECK_ALL)
                last = sk_X509_num(ctx->chain) - 1;
        else
+               {
+               /* If checking CRL paths this isn't the EE certificate */
+               if (ctx->parent)
+                       return 1;
                last = 0;
+               }
        for(i = 0; i <= last; i++)
                {
                ctx->error_depth = i;
@@ -577,30 +696,66 @@ static int check_revocation(X509_STORE_CTX *ctx)
 
 static int check_cert(X509_STORE_CTX *ctx)
        {
-       X509_CRL *crl = NULL;
+       X509_CRL *crl = NULL, *dcrl = NULL;
        X509 *x;
        int ok, cnum;
        cnum = ctx->error_depth;
        x = sk_X509_value(ctx->chain, cnum);
        ctx->current_cert = x;
-       /* Try to retrieve relevant CRL */
-       ok = ctx->get_crl(ctx, &crl, x);
-       /* If error looking up CRL, nothing we can do except
-        * notify callback
-        */
-       if(!ok)
+       ctx->current_issuer = NULL;
+       ctx->current_crl_score = 0;
+       ctx->current_reasons = 0;
+       while (ctx->current_reasons != CRLDP_ALL_REASONS)
                {
-               ctx->error = X509_V_ERR_UNABLE_TO_GET_CRL;
-               ok = ctx->verify_cb(0, ctx);
-               goto err;
+               /* Try to retrieve relevant CRL */
+               if (ctx->get_crl)
+                       ok = ctx->get_crl(ctx, &crl, x);
+               else
+                       ok = get_crl_delta(ctx, &crl, &dcrl, x);
+               /* If error looking up CRL, nothing we can do except
+                * notify callback
+                */
+               if(!ok)
+                       {
+                       ctx->error = X509_V_ERR_UNABLE_TO_GET_CRL;
+                       ok = ctx->verify_cb(0, ctx);
+                       goto err;
+                       }
+               ctx->current_crl = crl;
+               ok = ctx->check_crl(ctx, crl);
+               if (!ok)
+                       goto err;
+
+               if (dcrl)
+                       {
+                       ok = ctx->check_crl(ctx, dcrl);
+                       if (!ok)
+                               goto err;
+                       ok = ctx->cert_crl(ctx, dcrl, x);
+                       if (!ok)
+                               goto err;
+                       }
+               else
+                       ok = 1;
+
+               /* Don't look in full CRL if delta reason is removefromCRL */
+               if (ok != 2)
+                       {
+                       ok = ctx->cert_crl(ctx, crl, x);
+                       if (!ok)
+                               goto err;
+                       }
+
+               X509_CRL_free(crl);
+               X509_CRL_free(dcrl);
+               crl = NULL;
+               dcrl = NULL;
                }
-       ctx->current_crl = crl;
-       ok = ctx->check_crl(ctx, crl);
-       if (!ok) goto err;
-       ok = ctx->cert_crl(ctx, crl, x);
        err:
-       ctx->current_crl = NULL;
        X509_CRL_free(crl);
+       X509_CRL_free(dcrl);
+
+       ctx->current_crl = NULL;
        return ok;
 
        }
@@ -611,7 +766,8 @@ static int check_crl_time(X509_STORE_CTX *ctx, X509_CRL *crl, int notify)
        {
        time_t *ptime;
        int i;
-       ctx->current_crl = crl;
+       if (notify)
+               ctx->current_crl = crl;
        if (ctx->param->flags & X509_V_FLAG_USE_CHECK_TIME)
                ptime = &ctx->param->check_time;
        else
@@ -620,15 +776,19 @@ static int check_crl_time(X509_STORE_CTX *ctx, X509_CRL *crl, int notify)
        i=X509_cmp_time(X509_CRL_get_lastUpdate(crl), ptime);
        if (i == 0)
                {
+               if (!notify)
+                       return 0;
                ctx->error=X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD;
-               if (!notify || !ctx->verify_cb(0, ctx))
+               if (!ctx->verify_cb(0, ctx))
                        return 0;
                }
 
        if (i > 0)
                {
+               if (!notify)
+                       return 0;
                ctx->error=X509_V_ERR_CRL_NOT_YET_VALID;
-               if (!notify || !ctx->verify_cb(0, ctx))
+               if (!ctx->verify_cb(0, ctx))
                        return 0;
                }
 
@@ -638,92 +798,545 @@ static int check_crl_time(X509_STORE_CTX *ctx, X509_CRL *crl, int notify)
 
                if (i == 0)
                        {
+                       if (!notify)
+                               return 0;
                        ctx->error=X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD;
-                       if (!notify || !ctx->verify_cb(0, ctx))
+                       if (!ctx->verify_cb(0, ctx))
                                return 0;
                        }
-
-               if (i < 0)
+               /* Ignore expiry of base CRL is delta is valid */
+               if ((i < 0) && !(ctx->current_crl_score & CRL_SCORE_TIME_DELTA))
                        {
+                       if (!notify)
+                               return 0;
                        ctx->error=X509_V_ERR_CRL_HAS_EXPIRED;
-                       if (!notify || !ctx->verify_cb(0, ctx))
+                       if (!ctx->verify_cb(0, ctx))
                                return 0;
                        }
                }
 
-       ctx->current_crl = NULL;
+       if (notify)
+               ctx->current_crl = NULL;
 
        return 1;
        }
 
-/* Lookup CRLs from the supplied list. Look for matching isser name
- * and validity. If we can't find a valid CRL return the last one
- * with matching name. This gives more meaningful error codes. Otherwise
- * we'd get a CRL not found error if a CRL existed with matching name but
- * was invalid.
- */
-
-static int get_crl_sk(X509_STORE_CTX *ctx, X509_CRL **pcrl,
-                       X509_NAME *nm, STACK_OF(X509_CRL) *crls)
+static int get_crl_sk(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509_CRL **pdcrl,
+                       X509 **pissuer, int *pscore, unsigned int *preasons,
+                       STACK_OF(X509_CRL) *crls)
        {
-       int i;
+       int i, crl_score, best_score = *pscore;
+       unsigned int reasons, best_reasons = 0;
+       X509 *x = ctx->current_cert;
        X509_CRL *crl, *best_crl = NULL;
+       X509 *crl_issuer = NULL, *best_crl_issuer = NULL;
+
        for (i = 0; i < sk_X509_CRL_num(crls); i++)
                {
                crl = sk_X509_CRL_value(crls, i);
-               if (X509_NAME_cmp(nm, X509_CRL_get_issuer(crl)))
-                       continue;
-               if (check_crl_time(ctx, crl, 0))
+               reasons = *preasons;
+               crl_score = get_crl_score(ctx, &crl_issuer, &reasons, crl, x);
+
+               if (crl_score > best_score)
                        {
-                       *pcrl = crl;
-                       CRYPTO_add(&crl->references, 1, CRYPTO_LOCK_X509);
-                       return 1;
+                       best_crl = crl;
+                       best_crl_issuer = crl_issuer;
+                       best_score = crl_score;
+                       best_reasons = reasons;
                        }
-               best_crl = crl;
                }
+
        if (best_crl)
                {
+               if (*pcrl)
+                       X509_CRL_free(*pcrl);
                *pcrl = best_crl;
-               CRYPTO_add(&best_crl->references, 1, CRYPTO_LOCK_X509);
+               *pissuer = best_crl_issuer;
+               *pscore = best_score;
+               *preasons = best_reasons;
+               CRYPTO_add(&best_crl->references, 1, CRYPTO_LOCK_X509_CRL);
+               if (*pdcrl)
+                       {
+                       X509_CRL_free(*pdcrl);
+                       *pdcrl = NULL;
+                       }
+               get_delta_sk(ctx, pdcrl, pscore, best_crl, crls);
                }
-               
+
+       if (best_score >= CRL_SCORE_VALID)
+               return 1;
+
        return 0;
        }
 
-/* Retrieve CRL corresponding to certificate: currently just a
- * subject lookup: maybe use AKID later...
+/* Compare two CRL extensions for delta checking purposes. They should be
+ * both present or both absent. If both present all fields must be identical.
  */
-static int get_crl(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509 *x)
+
+static int crl_extension_match(X509_CRL *a, X509_CRL *b, int nid)
        {
-       int ok;
-       X509_CRL *crl = NULL;
-       X509_OBJECT xobj;
-       X509_NAME *nm;
-       nm = X509_get_issuer_name(x);
-       ok = get_crl_sk(ctx, &crl, nm, ctx->crls);
-       if (ok)
+       ASN1_OCTET_STRING *exta, *extb;
+       int i;
+       i = X509_CRL_get_ext_by_NID(a, nid, 0);
+       if (i >= 0)
                {
-               *pcrl = crl;
+               /* Can't have multiple occurrences */
+               if (X509_CRL_get_ext_by_NID(a, nid, i) != -1)
+                       return 0;
+               exta = X509_EXTENSION_get_data(X509_CRL_get_ext(a, i));
+               }
+       else
+               exta = NULL;
+
+       i = X509_CRL_get_ext_by_NID(b, nid, 0);
+
+       if (i >= 0)
+               {
+
+               if (X509_CRL_get_ext_by_NID(b, nid, i) != -1)
+                       return 0;
+               extb = X509_EXTENSION_get_data(X509_CRL_get_ext(b, i));
+               }
+       else
+               extb = NULL;
+
+       if (!exta && !extb)
                return 1;
+
+       if (!exta || !extb)
+               return 0;
+
+
+       if (ASN1_OCTET_STRING_cmp(exta, extb))
+               return 0;
+
+       return 1;
+       }
+
+/* See if a base and delta are compatible */
+
+static int check_delta_base(X509_CRL *delta, X509_CRL *base)
+       {
+       /* Delta CRL must be a delta */
+       if (!delta->base_crl_number)
+                       return 0;
+       /* Base must have a CRL number */
+       if (!base->crl_number)
+                       return 0;
+       /* Issuer names must match */
+       if (X509_NAME_cmp(X509_CRL_get_issuer(base),
+                               X509_CRL_get_issuer(delta)))
+               return 0;
+       /* AKID and IDP must match */
+       if (!crl_extension_match(delta, base, NID_authority_key_identifier))
+                       return 0;
+       if (!crl_extension_match(delta, base, NID_issuing_distribution_point))
+                       return 0;
+       /* Delta CRL base number must not exceed Full CRL number. */
+       if (ASN1_INTEGER_cmp(delta->base_crl_number, base->crl_number) > 0)
+                       return 0;
+       /* Delta CRL number must exceed full CRL number */
+       if (ASN1_INTEGER_cmp(delta->crl_number, base->crl_number) > 0)
+                       return 1;
+       return 0;
+       }
+
+/* For a given base CRL find a delta... maybe extend to delta scoring
+ * or retrieve a chain of deltas...
+ */
+
+static void get_delta_sk(X509_STORE_CTX *ctx, X509_CRL **dcrl, int *pscore,
+                       X509_CRL *base, STACK_OF(X509_CRL) *crls)
+       {
+       X509_CRL *delta;
+       int i;
+       if (!(ctx->param->flags & X509_V_FLAG_USE_DELTAS))
+               return;
+       if (!((ctx->current_cert->ex_flags | base->flags) & EXFLAG_FRESHEST))
+               return;
+       for (i = 0; i < sk_X509_CRL_num(crls); i++)
+               {
+               delta = sk_X509_CRL_value(crls, i);
+               if (check_delta_base(delta, base))
+                       {
+                       if (check_crl_time(ctx, delta, 0))
+                               *pscore |= CRL_SCORE_TIME_DELTA;
+                       CRYPTO_add(&delta->references, 1, CRYPTO_LOCK_X509_CRL);
+                       *dcrl = delta;
+                       return;
+                       }
+               }
+       *dcrl = NULL;
+       }
+
+/* For a given CRL return how suitable it is for the supplied certificate 'x'.
+ * The return value is a mask of several criteria.
+ * If the issuer is not the certificate issuer this is returned in *pissuer.
+ * The reasons mask is also used to determine if the CRL is suitable: if
+ * no new reasons the CRL is rejected, otherwise reasons is updated.
+ */
+
+static int get_crl_score(X509_STORE_CTX *ctx, X509 **pissuer,
+                       unsigned int *preasons,
+                       X509_CRL *crl, X509 *x)
+       {
+
+       int crl_score = 0;
+       unsigned int tmp_reasons = *preasons, crl_reasons;
+
+       /* First see if we can reject CRL straight away */
+
+       /* Invalid IDP cannot be processed */
+       if (crl->idp_flags & IDP_INVALID)
+               return 0;
+       /* Reason codes or indirect CRLs need extended CRL support */
+       if (!(ctx->param->flags & X509_V_FLAG_EXTENDED_CRL_SUPPORT))
+               {
+               if (crl->idp_flags & (IDP_INDIRECT | IDP_REASONS))
+                       return 0;
+               }
+       else if (crl->idp_flags & IDP_REASONS)
+               {
+               /* If no new reasons reject */
+               if (!(crl->idp_reasons & ~tmp_reasons))
+                       return 0;
+               }
+       /* Don't process deltas at this stage */
+       else if (crl->base_crl_number)
+               return 0;
+       /* If issuer name doesn't match certificate need indirect CRL */
+       if (X509_NAME_cmp(X509_get_issuer_name(x), X509_CRL_get_issuer(crl)))
+               {
+               if (!(crl->idp_flags & IDP_INDIRECT))
+                       return 0;
+               }
+       else
+               crl_score |= CRL_SCORE_ISSUER_NAME;
+
+       if (!(crl->flags & EXFLAG_CRITICAL))
+               crl_score |= CRL_SCORE_NOCRITICAL;
+
+       /* Check expiry */
+       if (check_crl_time(ctx, crl, 0))
+               crl_score |= CRL_SCORE_TIME;
+
+       /* Check authority key ID and locate certificate issuer */
+       crl_akid_check(ctx, crl, pissuer, &crl_score);
+
+       /* If we can't locate certificate issuer at this point forget it */
+
+       if (!(crl_score & CRL_SCORE_AKID))
+               return 0;
+
+       /* Check cert for matching CRL distribution points */
+
+       if (crl_crldp_check(x, crl, crl_score, &crl_reasons))
+               {
+               /* If no new reasons reject */
+               if (!(crl_reasons & ~tmp_reasons))
+                       return 0;
+               tmp_reasons |= crl_reasons;
+               crl_score |= CRL_SCORE_SCOPE;
                }
 
-       ok = X509_STORE_get_by_subject(ctx, X509_LU_CRL, nm, &xobj);
+       *preasons = tmp_reasons;
+
+       return crl_score;
+
+       }
 
-       if (!ok)
+static void crl_akid_check(X509_STORE_CTX *ctx, X509_CRL *crl,
+                               X509 **pissuer, int *pcrl_score)
+       {
+       X509 *crl_issuer = NULL;
+       X509_NAME *cnm = X509_CRL_get_issuer(crl);
+       int cidx = ctx->error_depth;
+       int i;
+
+       if (cidx != sk_X509_num(ctx->chain) - 1)
+               cidx++;
+
+       crl_issuer = sk_X509_value(ctx->chain, cidx);
+
+       if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK)
                {
-               /* If we got a near match from get_crl_sk use that */
-               if (crl)
+               if (*pcrl_score & CRL_SCORE_ISSUER_NAME)
                        {
-                       *pcrl = crl;
-                       return 1;
+                       *pcrl_score |= CRL_SCORE_AKID|CRL_SCORE_ISSUER_CERT;
+                       *pissuer = crl_issuer;
+                       return;
+                       }
+               }
+
+       for (cidx++; cidx < sk_X509_num(ctx->chain); cidx++)
+               {
+               crl_issuer = sk_X509_value(ctx->chain, cidx);
+               if (X509_NAME_cmp(X509_get_subject_name(crl_issuer), cnm))
+                       continue;
+               if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK)
+                       {
+                       *pcrl_score |= CRL_SCORE_AKID|CRL_SCORE_SAME_PATH;
+                       *pissuer = crl_issuer;
+                       return;
+                       }
+               }
+
+       /* Anything else needs extended CRL support */
+
+       if (!(ctx->param->flags & X509_V_FLAG_EXTENDED_CRL_SUPPORT))
+               return;
+
+       /* Otherwise the CRL issuer is not on the path. Look for it in the
+        * set of untrusted certificates.
+        */
+       for (i = 0; i < sk_X509_num(ctx->untrusted); i++)
+               {
+               crl_issuer = sk_X509_value(ctx->untrusted, i);
+               if (X509_NAME_cmp(X509_get_subject_name(crl_issuer), cnm))
+                       continue;
+               if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK)
+                       {
+                       *pissuer = crl_issuer;
+                       *pcrl_score |= CRL_SCORE_AKID;
+                       return;
+                       }
+               }
+       }
+
+/* Check the path of a CRL issuer certificate. This creates a new
+ * X509_STORE_CTX and populates it with most of the parameters from the
+ * parent. This could be optimised somewhat since a lot of path checking
+ * will be duplicated by the parent, but this will rarely be used in 
+ * practice.
+ */
+
+static int check_crl_path(X509_STORE_CTX *ctx, X509 *x)
+       {
+       X509_STORE_CTX crl_ctx;
+       int ret;
+       /* Don't allow recursive CRL path validation */
+       if (ctx->parent)
+               return 0;
+       if (!X509_STORE_CTX_init(&crl_ctx, ctx->ctx, x, ctx->untrusted))
+               return -1;
+
+       crl_ctx.crls = ctx->crls;
+       /* Copy verify params across */
+       X509_STORE_CTX_set0_param(&crl_ctx, ctx->param);
+
+       crl_ctx.parent = ctx;
+       crl_ctx.verify_cb = ctx->verify_cb;
+
+       /* Verify CRL issuer */
+       ret = X509_verify_cert(&crl_ctx);
+
+       if (ret <= 0)
+               goto err;
+
+       /* Check chain is acceptable */
+
+       ret = check_crl_chain(ctx, ctx->chain, crl_ctx.chain);
+       err:
+       X509_STORE_CTX_cleanup(&crl_ctx);
+       return ret;
+       }
+
+/* RFC3280 says nothing about the relationship between CRL path
+ * and certificate path, which could lead to situations where a
+ * certificate could be revoked or validated by a CA not authorised
+ * to do so. RFC5280 is more strict and states that the two paths must
+ * end in the same trust anchor, though some discussions remain...
+ * until this is resolved we use the RFC5280 version
+ */
+
+static int check_crl_chain(X509_STORE_CTX *ctx,
+                       STACK_OF(X509) *cert_path,
+                       STACK_OF(X509) *crl_path)
+       {
+       X509 *cert_ta, *crl_ta;
+       cert_ta = sk_X509_value(cert_path, sk_X509_num(cert_path) - 1);
+       crl_ta = sk_X509_value(crl_path, sk_X509_num(crl_path) - 1);
+       if (!X509_cmp(cert_ta, crl_ta))
+               return 1;
+       return 0;
+       }
+
+/* Check for match between two dist point names: three separate cases.
+ * 1. Both are relative names and compare X509_NAME types.
+ * 2. One full, one relative. Compare X509_NAME to GENERAL_NAMES.
+ * 3. Both are full names and compare two GENERAL_NAMES.
+ * 4. One is NULL: automatic match.
+ */
+
+
+static int idp_check_dp(DIST_POINT_NAME *a, DIST_POINT_NAME *b)
+       {
+       X509_NAME *nm = NULL;
+       GENERAL_NAMES *gens = NULL;
+       GENERAL_NAME *gena, *genb;
+       int i, j;
+       if (!a || !b)
+               return 1;
+       if (a->type == 1)
+               {
+               if (!a->dpname)
+                       return 0;
+               /* Case 1: two X509_NAME */
+               if (b->type == 1)
+                       {
+                       if (!b->dpname)
+                               return 0;
+                       if (!X509_NAME_cmp(a->dpname, b->dpname))
+                               return 1;
+                       else
+                               return 0;
                        }
+               /* Case 2: set name and GENERAL_NAMES appropriately */
+               nm = a->dpname;
+               gens = b->name.fullname;
+               }
+       else if (b->type == 1)
+               {
+               if (!b->dpname)
+                       return 0;
+               /* Case 2: set name and GENERAL_NAMES appropriately */
+               gens = a->name.fullname;
+               nm = b->dpname;
+               }
+
+       /* Handle case 2 with one GENERAL_NAMES and one X509_NAME */
+       if (nm)
+               {
+               for (i = 0; i < sk_GENERAL_NAME_num(gens); i++)
+                       {
+                       gena = sk_GENERAL_NAME_value(gens, i);  
+                       if (gena->type != GEN_DIRNAME)
+                               continue;
+                       if (!X509_NAME_cmp(nm, gena->d.directoryName))
+                               return 1;
+                       }
+               return 0;
+               }
+
+       /* Else case 3: two GENERAL_NAMES */
+
+       for (i = 0; i < sk_GENERAL_NAME_num(a->name.fullname); i++)
+               {
+               gena = sk_GENERAL_NAME_value(a->name.fullname, i);
+               for (j = 0; j < sk_GENERAL_NAME_num(b->name.fullname); j++)
+                       {
+                       genb = sk_GENERAL_NAME_value(b->name.fullname, j);
+                       if (!GENERAL_NAME_cmp(gena, genb))
+                               return 1;
+                       }
+               }
+
+       return 0;
+
+       }
+
+static int crldp_check_crlissuer(DIST_POINT *dp, X509_CRL *crl, int crl_score)
+       {
+       int i;
+       X509_NAME *nm = X509_CRL_get_issuer(crl);
+       /* If no CRLissuer return is successful iff don't need a match */
+       if (!dp->CRLissuer)
+               return !!(crl_score & CRL_SCORE_ISSUER_NAME);
+       for (i = 0; i < sk_GENERAL_NAME_num(dp->CRLissuer); i++)
+               {
+               GENERAL_NAME *gen = sk_GENERAL_NAME_value(dp->CRLissuer, i);
+               if (gen->type != GEN_DIRNAME)
+                       continue;
+               if (!X509_NAME_cmp(gen->d.directoryName, nm))
+                       return 1;
+               }
+       return 0;
+       }
+
+/* Check CRLDP and IDP */
+
+static int crl_crldp_check(X509 *x, X509_CRL *crl, int crl_score,
+                               unsigned int *preasons)
+       {
+       int i;
+       if (crl->idp_flags & IDP_ONLYATTR)
                return 0;
+       if (x->ex_flags & EXFLAG_CA)
+               {
+               if (crl->idp_flags & IDP_ONLYUSER)
+                       return 0;
+               }
+       else
+               {
+               if (crl->idp_flags & IDP_ONLYCA)
+                       return 0;
+               }
+       *preasons = crl->idp_reasons;
+       for (i = 0; i < sk_DIST_POINT_num(x->crldp); i++)
+               {
+               DIST_POINT *dp = sk_DIST_POINT_value(x->crldp, i);
+               if (crldp_check_crlissuer(dp, crl, crl_score))
+                       {
+                       if (!crl->idp ||
+                            idp_check_dp(dp->distpoint, crl->idp->distpoint))
+                               {
+                               *preasons &= dp->dp_reasons;
+                               return 1;
+                               }
+                       }
                }
+       if ((!crl->idp || !crl->idp->distpoint) && (crl_score & CRL_SCORE_ISSUER_NAME))
+               return 1;
+       return 0;
+       }
+
+/* Retrieve CRL corresponding to current certificate.
+ * If deltas enabled try to find a delta CRL too
+ */
+       
+static int get_crl_delta(X509_STORE_CTX *ctx,
+                               X509_CRL **pcrl, X509_CRL **pdcrl, X509 *x)
+       {
+       int ok;
+       X509 *issuer = NULL;
+       int crl_score = 0;
+       unsigned int reasons;
+       X509_CRL *crl = NULL, *dcrl = NULL;
+       STACK_OF(X509_CRL) *skcrl;
+       X509_NAME *nm = X509_get_issuer_name(x);
+       reasons = ctx->current_reasons;
+       ok = get_crl_sk(ctx, &crl, &dcrl, 
+                               &issuer, &crl_score, &reasons, ctx->crls);
+
+       if (ok)
+               goto done;
+
+       /* Lookup CRLs from store */
 
-       *pcrl = xobj.data.crl;
+       skcrl = ctx->lookup_crls(ctx, nm);
+
+       /* If no CRLs found and a near match from get_crl_sk use that */
+       if (!skcrl && crl)
+               goto done;
+
+       get_crl_sk(ctx, &crl, &dcrl, &issuer, &crl_score, &reasons, skcrl);
+
+       sk_X509_CRL_pop_free(skcrl, X509_CRL_free);
+
+       done:
+
+       /* If we got any kind of CRL use it and return success */
        if (crl)
-               X509_CRL_free(crl);
-       return 1;
+               {
+               ctx->current_issuer = issuer;
+               ctx->current_crl_score = crl_score;
+               ctx->current_reasons = reasons;
+               *pcrl = crl;
+               *pdcrl = dcrl;
+               return 1;
+               }
+
+       return 0;
        }
 
 /* Check CRL validity */
@@ -734,10 +1347,14 @@ static int check_crl(X509_STORE_CTX *ctx, X509_CRL *crl)
        int ok = 0, chnum, cnum;
        cnum = ctx->error_depth;
        chnum = sk_X509_num(ctx->chain) - 1;
-       /* Find CRL issuer: if not last certificate then issuer
+       /* if we have an alternative CRL issuer cert use that */
+       if (ctx->current_issuer)
+               issuer = ctx->current_issuer;
+
+       /* Else find CRL issuer: if not last certificate then issuer
         * is next certificate in chain.
         */
-       if(cnum < chnum)
+       else if (cnum < chnum)
                issuer = sk_X509_value(ctx->chain, cnum + 1);
        else
                {
@@ -753,13 +1370,52 @@ static int check_crl(X509_STORE_CTX *ctx, X509_CRL *crl)
 
        if(issuer)
                {
-               /* Check for cRLSign bit if keyUsage present */
-               if ((issuer->ex_flags & EXFLAG_KUSAGE) &&
-                       !(issuer->ex_kusage & KU_CRL_SIGN))
+               /* Skip most tests for deltas because they have already
+                * been done
+                */
+               if (!crl->base_crl_number)
                        {
-                       ctx->error = X509_V_ERR_KEYUSAGE_NO_CRL_SIGN;
-                       ok = ctx->verify_cb(0, ctx);
-                       if(!ok) goto err;
+                       /* Check for cRLSign bit if keyUsage present */
+                       if ((issuer->ex_flags & EXFLAG_KUSAGE) &&
+                               !(issuer->ex_kusage & KU_CRL_SIGN))
+                               {
+                               ctx->error = X509_V_ERR_KEYUSAGE_NO_CRL_SIGN;
+                               ok = ctx->verify_cb(0, ctx);
+                               if(!ok) goto err;
+                               }
+
+                       if (!(ctx->current_crl_score & CRL_SCORE_SCOPE))
+                               {
+                               ctx->error = X509_V_ERR_DIFFERENT_CRL_SCOPE;
+                               ok = ctx->verify_cb(0, ctx);
+                               if(!ok) goto err;
+                               }
+
+                       if (!(ctx->current_crl_score & CRL_SCORE_SAME_PATH))
+                               {
+                               if (check_crl_path(ctx, ctx->current_issuer) <= 0)
+                                       {
+                                       ctx->error = X509_V_ERR_CRL_PATH_VALIDATION_ERROR;
+                                       ok = ctx->verify_cb(0, ctx);
+                                       if(!ok) goto err;
+                                       }
+                               }
+
+                       if (crl->idp_flags & IDP_INVALID)
+                               {
+                               ctx->error = X509_V_ERR_INVALID_EXTENSION;
+                               ok = ctx->verify_cb(0, ctx);
+                               if(!ok) goto err;
+                               }
+
+
+                       }
+
+               if (!(ctx->current_crl_score & CRL_SCORE_TIME))
+                       {
+                       ok = check_crl_time(ctx, crl, 1);
+                       if (!ok)
+                               goto err;
                        }
 
                /* Attempt to get issuer certificate public key */
@@ -783,10 +1439,6 @@ static int check_crl(X509_STORE_CTX *ctx, X509_CRL *crl)
                        }
                }
 
-       ok = check_crl_time(ctx, crl, 1);
-       if (!ok)
-               goto err;
-
        ok = 1;
 
        err:
@@ -797,62 +1449,43 @@ static int check_crl(X509_STORE_CTX *ctx, X509_CRL *crl)
 /* Check certificate against CRL */
 static int cert_crl(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x)
        {
-       int idx, ok;
-       X509_REVOKED rtmp;
-       STACK_OF(X509_EXTENSION) *exts;
-       X509_EXTENSION *ext;
-       /* Look for serial number of certificate in CRL */
-       rtmp.serialNumber = X509_get_serialNumber(x);
-       /* Sort revoked into serial number order if not already sorted.
-        * Do this under a lock to avoid race condition.
-        */
-       if (!sk_X509_REVOKED_is_sorted(crl->crl->revoked))
+       int ok;
+       X509_REVOKED *rev;
+       /* The rules changed for this... previously if a CRL contained
+        * unhandled critical extensions it could still be used to indicate
+        * a certificate was revoked. This has since been changed since 
+        * critical extension can change the meaning of CRL entries.
+        */
+       if (crl->flags & EXFLAG_CRITICAL)
                {
-               CRYPTO_w_lock(CRYPTO_LOCK_X509_CRL);
-               sk_X509_REVOKED_sort(crl->crl->revoked);
-               CRYPTO_w_unlock(CRYPTO_LOCK_X509_CRL);
+               if (ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL)
+                       return 1;
+               ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION;
+               ok = ctx->verify_cb(0, ctx);
+               if(!ok)
+                       return 0;
                }
-       idx = sk_X509_REVOKED_find(crl->crl->revoked, &rtmp);
-       /* If found assume revoked: want something cleverer than
-        * this to handle entry extensions in V2 CRLs.
+       /* Look for serial number of certificate in CRL
+        * If found make sure reason is not removeFromCRL.
         */
-       if(idx >= 0)
+       if (X509_CRL_get0_by_cert(crl, &rev, x))
                {
+               if (rev->reason == CRL_REASON_REMOVE_FROM_CRL)
+                       return 2;
                ctx->error = X509_V_ERR_CERT_REVOKED;
                ok = ctx->verify_cb(0, ctx);
-               if (!ok) return 0;
+               if (!ok)
+                       return 0;
                }
 
-       if (ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL)
-               return 1;
-
-       /* See if we have any critical CRL extensions: since we
-        * currently don't handle any CRL extensions the CRL must be
-        * rejected. 
-        * This code accesses the X509_CRL structure directly: applications
-        * shouldn't do this.
-        */
-
-       exts = crl->crl->extensions;
-
-       for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++)
-               {
-               ext = sk_X509_EXTENSION_value(exts, idx);
-               if (ext->critical > 0)
-                       {
-                       ctx->error =
-                               X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION;
-                       ok = ctx->verify_cb(0, ctx);
-                       if(!ok) return 0;
-                       break;
-                       }
-               }
        return 1;
        }
 
 static int check_policy(X509_STORE_CTX *ctx)
        {
        int ret;
+       if (ctx->parent)
+               return 1;
        ret = X509_policy_check(&ctx->tree, &ctx->explicit_policy, ctx->chain,
                                ctx->param->policies, ctx->param->flags);
        if (ret == 0)
@@ -875,7 +1508,8 @@ static int check_policy(X509_STORE_CTX *ctx)
                                continue;
                        ctx->current_cert = x;
                        ctx->error = X509_V_ERR_INVALID_POLICY_EXTENSION;
-                       ret = ctx->verify_cb(0, ctx);
+                       if(!ctx->verify_cb(0, ctx))
+                               return 0;
                        }
                return 1;
                }
@@ -1034,12 +1668,12 @@ end:
        return ok;
        }
 
-int X509_cmp_current_time(ASN1_TIME *ctm)
+int X509_cmp_current_time(const ASN1_TIME *ctm)
 {
        return X509_cmp_time(ctm, NULL);
 }
 
-int X509_cmp_time(ASN1_TIME *ctm, time_t *cmp_time)
+int X509_cmp_time(const ASN1_TIME *ctm, time_t *cmp_time)
        {
        char *str;
        ASN1_TIME atm;
@@ -1094,10 +1728,11 @@ int X509_cmp_time(ASN1_TIME *ctm, time_t *cmp_time)
                        offset= -offset;
                }
        atm.type=ctm->type;
+       atm.flags = 0;
        atm.length=sizeof(buff2);
        atm.data=(unsigned char *)buff2;
 
-       if (X509_time_adj(&atm,-offset*60, cmp_time) == NULL)
+       if (X509_time_adj(&atm, offset*60, cmp_time) == NULL)
                return 0;
 
        if (ctm->type == V_ASN1_UTCTIME)
@@ -1122,19 +1757,28 @@ ASN1_TIME *X509_gmtime_adj(ASN1_TIME *s, long adj)
        return X509_time_adj(s, adj, NULL);
 }
 
-ASN1_TIME *X509_time_adj(ASN1_TIME *s, long adj, time_t *in_tm)
+ASN1_TIME *X509_time_adj(ASN1_TIME *s, long offset_sec, time_t *in_tm)
+       {
+       return X509_time_adj_ex(s, 0, offset_sec, in_tm);
+       }
+
+ASN1_TIME *X509_time_adj_ex(ASN1_TIME *s,
+                               int offset_day, long offset_sec, time_t *in_tm)
        {
        time_t t;
-       int type = -1;
 
        if (in_tm) t = *in_tm;
        else time(&t);
 
-       t+=adj;
-       if (s) type = s->type;
-       if (type == V_ASN1_UTCTIME) return ASN1_UTCTIME_set(s,t);
-       if (type == V_ASN1_GENERALIZEDTIME) return ASN1_GENERALIZEDTIME_set(s, t);
-       return ASN1_TIME_set(s, t);
+       if (s && !(s->flags & ASN1_STRING_FLAG_MSTRING))
+               {
+               if (s->type == V_ASN1_UTCTIME)
+                       return ASN1_UTCTIME_adj(s,t, offset_day, offset_sec);
+               if (s->type == V_ASN1_GENERALIZEDTIME)
+                       return ASN1_GENERALIZEDTIME_adj(s, t, offset_day,
+                                                               offset_sec);
+               }
+       return ASN1_TIME_adj(s, t, offset_day, offset_sec);
        }
 
 int X509_get_pubkey_parameters(EVP_PKEY *pkey, STACK_OF(X509) *chain)
@@ -1237,6 +1881,21 @@ STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx)
        return chain;
        }
 
+X509 *X509_STORE_CTX_get0_current_issuer(X509_STORE_CTX *ctx)
+       {
+       return ctx->current_issuer;
+       }
+
+X509_CRL *X509_STORE_CTX_get0_current_crl(X509_STORE_CTX *ctx)
+       {
+       return ctx->current_crl;
+       }
+
+X509_STORE_CTX *X509_STORE_CTX_get0_parent_ctx(X509_STORE_CTX *ctx)
+       {
+       return ctx->parent;
+       }
+
 void X509_STORE_CTX_set_cert(X509_STORE_CTX *ctx, X509 *x)
        {
        ctx->cert=x;
@@ -1357,7 +2016,11 @@ int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
        ctx->error_depth=0;
        ctx->current_cert=NULL;
        ctx->current_issuer=NULL;
+       ctx->current_crl=NULL;
+       ctx->current_crl_score=0;
+       ctx->current_reasons=0;
        ctx->tree = NULL;
+       ctx->parent = NULL;
 
        ctx->param = X509_VERIFY_PARAM_new();
 
@@ -1423,7 +2086,7 @@ int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
        if (store && store->get_crl)
                ctx->get_crl = store->get_crl;
        else
-               ctx->get_crl = get_crl;
+               ctx->get_crl = NULL;
 
        if (store && store->check_crl)
                ctx->check_crl = store->check_crl;
@@ -1435,6 +2098,16 @@ int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
        else
                ctx->cert_crl = cert_crl;
 
+       if (store && store->lookup_certs)
+               ctx->lookup_certs = store->lookup_certs;
+       else
+               ctx->lookup_certs = X509_STORE_get1_certs;
+
+       if (store && store->lookup_crls)
+               ctx->lookup_crls = store->lookup_crls;
+       else
+               ctx->lookup_crls = X509_STORE_get1_crls;
+
        ctx->check_policy = check_policy;
 
 
@@ -1467,7 +2140,8 @@ void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx)
        if (ctx->cleanup) ctx->cleanup(ctx);
        if (ctx->param != NULL)
                {
-               X509_VERIFY_PARAM_free(ctx->param);
+               if (ctx->parent == NULL)
+                       X509_VERIFY_PARAM_free(ctx->param);
                ctx->param=NULL;
                }
        if (ctx->tree != NULL)
index 86ae35f..fe09b30 100644 (file)
@@ -77,6 +77,7 @@
 extern "C" {
 #endif
 
+#if 0
 /* Outer object */
 typedef struct x509_hash_dir_st
        {
@@ -85,6 +86,7 @@ typedef struct x509_hash_dir_st
        int *dirs_type;
        int num_dirs_alloced;
        } X509_HASH_DIR_CTX;
+#endif
 
 typedef struct x509_file_st
        {
@@ -198,6 +200,8 @@ struct x509_store_st
        int (*get_crl)(X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x); /* retrieve CRL */
        int (*check_crl)(X509_STORE_CTX *ctx, X509_CRL *crl); /* Check CRL validity */
        int (*cert_crl)(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x); /* Check certificate against CRL */
+       STACK_OF(X509) * (*lookup_certs)(X509_STORE_CTX *ctx, X509_NAME *nm);
+       STACK_OF(X509_CRL) * (*lookup_crls)(X509_STORE_CTX *ctx, X509_NAME *nm);
        int (*cleanup)(X509_STORE_CTX *ctx);
 
        CRYPTO_EX_DATA ex_data;
@@ -246,6 +250,8 @@ struct x509_store_ctx_st      /* X509_STORE_CTX */
        int (*check_crl)(X509_STORE_CTX *ctx, X509_CRL *crl); /* Check CRL validity */
        int (*cert_crl)(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x); /* Check certificate against CRL */
        int (*check_policy)(X509_STORE_CTX *ctx);
+       STACK_OF(X509) * (*lookup_certs)(X509_STORE_CTX *ctx, X509_NAME *nm);
+       STACK_OF(X509_CRL) * (*lookup_crls)(X509_STORE_CTX *ctx, X509_NAME *nm);
        int (*cleanup)(X509_STORE_CTX *ctx);
 
        /* The following is built up */
@@ -263,6 +269,11 @@ struct x509_store_ctx_st      /* X509_STORE_CTX */
        X509 *current_issuer;   /* cert currently being tested as valid issuer */
        X509_CRL *current_crl;  /* current CRL */
 
+       int current_crl_score;  /* score of current CRL */
+       unsigned int current_reasons;  /* Reason mask */
+
+       X509_STORE_CTX *parent; /* For CRL path validation: parent context */
+
        CRYPTO_EX_DATA ex_data;
        } /* X509_STORE_CTX */;
 
@@ -330,8 +341,18 @@ void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth);
 #define                X509_V_ERR_INVALID_EXTENSION                    41
 #define                X509_V_ERR_INVALID_POLICY_EXTENSION             42
 #define                X509_V_ERR_NO_EXPLICIT_POLICY                   43
+#define                X509_V_ERR_DIFFERENT_CRL_SCOPE                  44
+#define                X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE        45
+
+#define                X509_V_ERR_UNNESTED_RESOURCE                    46
 
-#define                X509_V_ERR_UNNESTED_RESOURCE                    44
+#define                X509_V_ERR_PERMITTED_VIOLATION                  47
+#define                X509_V_ERR_EXCLUDED_VIOLATION                   48
+#define                X509_V_ERR_SUBTREE_MINMAX                       49
+#define                X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE          51
+#define                X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX        52
+#define                X509_V_ERR_UNSUPPORTED_NAME_SYNTAX              53
+#define                X509_V_ERR_CRL_PATH_VALIDATION_ERROR            54
 
 /* The application is not happy */
 #define                X509_V_ERR_APPLICATION_VERIFICATION             50
@@ -362,10 +383,14 @@ void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth);
 #define X509_V_FLAG_INHIBIT_MAP                        0x400
 /* Notify callback that policy is OK */
 #define X509_V_FLAG_NOTIFY_POLICY              0x800
-
+/* Extended CRL features such as indirect CRLs, alternate CRL signing keys */
+#define X509_V_FLAG_EXTENDED_CRL_SUPPORT       0x1000
+/* Delta CRL support */
+#define X509_V_FLAG_USE_DELTAS                 0x2000
 /* Check selfsigned CA signature */
 #define X509_V_FLAG_CHECK_SS_SIGNATURE         0x4000
 
+
 #define X509_VP_FLAG_DEFAULT                   0x1
 #define X509_VP_FLAG_OVERWRITE                 0x2
 #define X509_VP_FLAG_RESET_FLAGS               0x4
@@ -387,11 +412,16 @@ void X509_OBJECT_free_contents(X509_OBJECT *a);
 X509_STORE *X509_STORE_new(void );
 void X509_STORE_free(X509_STORE *v);
 
+STACK_OF(X509)* X509_STORE_get1_certs(X509_STORE_CTX *st, X509_NAME *nm);
+STACK_OF(X509_CRL)* X509_STORE_get1_crls(X509_STORE_CTX *st, X509_NAME *nm);
 int X509_STORE_set_flags(X509_STORE *ctx, unsigned long flags);
 int X509_STORE_set_purpose(X509_STORE *ctx, int purpose);
 int X509_STORE_set_trust(X509_STORE *ctx, int trust);
 int X509_STORE_set1_param(X509_STORE *ctx, X509_VERIFY_PARAM *pm);
 
+void X509_STORE_set_verify_cb(X509_STORE *ctx,
+                                 int (*verify_cb)(int, X509_STORE_CTX *));
+
 X509_STORE_CTX *X509_STORE_CTX_new(void);
 
 int X509_STORE_CTX_get1_issuer(X509 **issuer, X509_STORE_CTX *ctx, X509 *x);
@@ -450,6 +480,9 @@ int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx);
 void   X509_STORE_CTX_set_error(X509_STORE_CTX *ctx,int s);
 int    X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx);
 X509 * X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx);
+X509 *X509_STORE_CTX_get0_current_issuer(X509_STORE_CTX *ctx);
+X509_CRL *X509_STORE_CTX_get0_current_crl(X509_STORE_CTX *ctx);
+X509_STORE_CTX *X509_STORE_CTX_get0_parent_ctx(X509_STORE_CTX *ctx);
 STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx);
 STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx);
 void   X509_STORE_CTX_set_cert(X509_STORE_CTX *c,X509 *x);
index 01c5541..dfd89d8 100644 (file)
@@ -74,6 +74,7 @@ static void x509_verify_param_zero(X509_VERIFY_PARAM *param)
        param->name = NULL;
        param->purpose = 0;
        param->trust = 0;
+       /*param->inh_flags = X509_VP_FLAG_DEFAULT;*/
        param->inh_flags = 0;
        param->flags = 0;
        param->depth = -1;
@@ -328,7 +329,7 @@ static const X509_VERIFY_PARAM default_table[] = {
        NULL            /* policies */
        },
        {
-       "pkcs7",                        /* S/MIME signing parameters */
+       "pkcs7",                        /* S/MIME sign parameters */
        0,                              /* Check time */
        0,                              /* internal flags */
        0,                              /* flags */
@@ -338,7 +339,7 @@ static const X509_VERIFY_PARAM default_table[] = {
        NULL                            /* policies */
        },
        {
-       "smime_sign",                   /* S/MIME signing parameters */
+       "smime_sign",                   /* S/MIME sign parameters */
        0,                              /* Check time */
        0,                              /* internal flags */
        0,                              /* flags */
@@ -370,12 +371,17 @@ static const X509_VERIFY_PARAM default_table[] = {
 
 static STACK_OF(X509_VERIFY_PARAM) *param_table = NULL;
 
-static int table_cmp(const void *pa, const void *pb)
+static int table_cmp(const X509_VERIFY_PARAM *a, const X509_VERIFY_PARAM *b)
+
        {
-       const X509_VERIFY_PARAM *a = pa, *b = pb;
        return strcmp(a->name, b->name);
        }
 
+DECLARE_OBJ_BSEARCH_CMP_FN(X509_VERIFY_PARAM, X509_VERIFY_PARAM,
+                          table);
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(X509_VERIFY_PARAM, X509_VERIFY_PARAM,
+                            table);
+
 static int param_cmp(const X509_VERIFY_PARAM * const *a,
                        const X509_VERIFY_PARAM * const *b)
        {
@@ -411,6 +417,7 @@ const X509_VERIFY_PARAM *X509_VERIFY_PARAM_lookup(const char *name)
        {
        int idx;
        X509_VERIFY_PARAM pm;
+
        pm.name = (char *)name;
        if (param_table)
                {
@@ -418,11 +425,8 @@ const X509_VERIFY_PARAM *X509_VERIFY_PARAM_lookup(const char *name)
                if (idx != -1)
                        return sk_X509_VERIFY_PARAM_value(param_table, idx);
                }
-       return (const X509_VERIFY_PARAM *) OBJ_bsearch((char *)&pm,
-                               (char *)&default_table,
-                               sizeof(default_table)/sizeof(X509_VERIFY_PARAM),
-                               sizeof(X509_VERIFY_PARAM),
-                               table_cmp);
+       return OBJ_bsearch_table(&pm, default_table,
+                          sizeof(default_table)/sizeof(X509_VERIFY_PARAM));
        }
 
 void X509_VERIFY_PARAM_table_cleanup(void)
index 7f4004b..3109def 100644 (file)
@@ -81,7 +81,7 @@ int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name)
        }
 
 
-int X509_CRL_set_lastUpdate(X509_CRL *x, ASN1_TIME *tm)
+int X509_CRL_set_lastUpdate(X509_CRL *x, const ASN1_TIME *tm)
        {
        ASN1_TIME *in;
 
@@ -99,7 +99,7 @@ int X509_CRL_set_lastUpdate(X509_CRL *x, ASN1_TIME *tm)
        return(in != NULL);
        }
 
-int X509_CRL_set_nextUpdate(X509_CRL *x, ASN1_TIME *tm)
+int X509_CRL_set_nextUpdate(X509_CRL *x, const ASN1_TIME *tm)
        {
        ASN1_TIME *in;
 
index 068abfe..27bc4dc 100644 (file)
@@ -356,7 +356,7 @@ int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type,
                return ASN1_STRING_set_by_NID(&ne->value, bytes,
                                                len, type,
                                        OBJ_obj2nid(ne->object)) ? 1 : 0;
-       if (len < 0) len=strlen((char *)bytes);
+       if (len < 0) len=strlen((const char *)bytes);
        i=ASN1_STRING_set(ne->value,bytes,len);
        if (!i) return(0);
        if (type != V_ASN1_UNDEF)
index 2cd994c..3385ad3 100644 (file)
@@ -91,6 +91,10 @@ int X509_certificate_type(X509 *x, EVP_PKEY *pkey)
                break;
        case EVP_PKEY_DH:
                ret=EVP_PK_DH|EVP_PKT_EXCH;
+               break;  
+       case NID_id_GostR3410_94:
+       case NID_id_GostR3410_2001:
+               ret=EVP_PKT_EXCH|EVP_PKT_SIGN;
                break;
        default:
                break;
index c7b07f7..8ec88c2 100644 (file)
@@ -57,7 +57,6 @@
  */
 
 #include <stdio.h>
-#undef SSLEAY_MACROS
 #include <openssl/stack.h>
 #include "cryptlib.h"
 #include <openssl/buffer.h>
@@ -83,12 +82,6 @@ int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r)
                a->sig_alg,a->signature,a->req_info,r));
        }
 
-int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r)
-       {
-       return(ASN1_item_verify(ASN1_ITEM_rptr(X509_CRL_INFO),
-               a->sig_alg, a->signature,a->crl,r));
-       }
-
 int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r)
        {
        return(ASN1_item_verify(ASN1_ITEM_rptr(NETSCAPE_SPKAC),
index e71dc42..556ef35 100644 (file)
@@ -43,7 +43,7 @@ top:
 all:   lib
 
 lib:   $(LIBOBJ)
-       $(ARX) $(LIB) $(LIBOBJ)
+       $(AR) $(LIB) $(LIBOBJ)
        $(RANLIB) $(LIB) || echo Never mind.
        @touch lib
 
@@ -90,8 +90,8 @@ pcy_cache.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 pcy_cache.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 pcy_cache.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 pcy_cache.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-pcy_cache.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-pcy_cache.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+pcy_cache.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+pcy_cache.o: ../../include/openssl/objects.h
 pcy_cache.o: ../../include/openssl/opensslconf.h
 pcy_cache.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 pcy_cache.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
@@ -105,9 +105,8 @@ pcy_data.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 pcy_data.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 pcy_data.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 pcy_data.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-pcy_data.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-pcy_data.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-pcy_data.o: ../../include/openssl/opensslconf.h
+pcy_data.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+pcy_data.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 pcy_data.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 pcy_data.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 pcy_data.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -120,36 +119,35 @@ pcy_lib.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 pcy_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 pcy_lib.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 pcy_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-pcy_lib.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-pcy_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-pcy_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-pcy_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-pcy_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-pcy_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-pcy_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-pcy_lib.o: ../../include/openssl/x509v3.h ../cryptlib.h pcy_int.h pcy_lib.c
+pcy_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+pcy_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+pcy_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+pcy_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+pcy_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+pcy_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+pcy_lib.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+pcy_lib.o: ../cryptlib.h pcy_int.h pcy_lib.c
 pcy_map.o: ../../e_os.h ../../include/openssl/asn1.h
 pcy_map.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 pcy_map.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 pcy_map.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 pcy_map.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 pcy_map.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-pcy_map.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-pcy_map.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-pcy_map.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-pcy_map.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-pcy_map.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-pcy_map.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-pcy_map.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-pcy_map.o: ../../include/openssl/x509v3.h ../cryptlib.h pcy_int.h pcy_map.c
+pcy_map.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+pcy_map.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+pcy_map.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+pcy_map.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+pcy_map.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+pcy_map.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+pcy_map.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+pcy_map.o: ../cryptlib.h pcy_int.h pcy_map.c
 pcy_node.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
 pcy_node.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 pcy_node.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 pcy_node.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 pcy_node.o: ../../include/openssl/ecdsa.h ../../include/openssl/evp.h
-pcy_node.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-pcy_node.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-pcy_node.o: ../../include/openssl/opensslconf.h
+pcy_node.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+pcy_node.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 pcy_node.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 pcy_node.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 pcy_node.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -162,9 +160,8 @@ pcy_tree.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 pcy_tree.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 pcy_tree.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 pcy_tree.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-pcy_tree.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-pcy_tree.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-pcy_tree.o: ../../include/openssl/opensslconf.h
+pcy_tree.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+pcy_tree.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 pcy_tree.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 pcy_tree.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 pcy_tree.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -177,39 +174,37 @@ v3_addr.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 v3_addr.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 v3_addr.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 v3_addr.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-v3_addr.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-v3_addr.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-v3_addr.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-v3_addr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-v3_addr.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-v3_addr.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-v3_addr.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-v3_addr.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
-v3_addr.o: ../cryptlib.h v3_addr.c
+v3_addr.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+v3_addr.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+v3_addr.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+v3_addr.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+v3_addr.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+v3_addr.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+v3_addr.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+v3_addr.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_addr.c
 v3_akey.o: ../../e_os.h ../../include/openssl/asn1.h
 v3_akey.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 v3_akey.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 v3_akey.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 v3_akey.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 v3_akey.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-v3_akey.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-v3_akey.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-v3_akey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-v3_akey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-v3_akey.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-v3_akey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-v3_akey.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-v3_akey.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
-v3_akey.o: ../cryptlib.h v3_akey.c
+v3_akey.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+v3_akey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+v3_akey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+v3_akey.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+v3_akey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+v3_akey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+v3_akey.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+v3_akey.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_akey.c
 v3_akeya.o: ../../e_os.h ../../include/openssl/asn1.h
 v3_akeya.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 v3_akeya.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 v3_akeya.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 v3_akeya.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 v3_akeya.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-v3_akeya.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-v3_akeya.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-v3_akeya.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+v3_akeya.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+v3_akeya.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+v3_akeya.o: ../../include/openssl/opensslconf.h
 v3_akeya.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 v3_akeya.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 v3_akeya.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -221,15 +216,14 @@ v3_alt.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 v3_alt.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 v3_alt.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 v3_alt.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-v3_alt.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-v3_alt.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-v3_alt.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-v3_alt.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-v3_alt.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-v3_alt.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-v3_alt.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-v3_alt.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
-v3_alt.o: ../cryptlib.h v3_alt.c
+v3_alt.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+v3_alt.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+v3_alt.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+v3_alt.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+v3_alt.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+v3_alt.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+v3_alt.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+v3_alt.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_alt.c
 v3_asid.o: ../../e_os.h ../../include/openssl/asn1.h
 v3_asid.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 v3_asid.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
@@ -237,23 +231,23 @@ v3_asid.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 v3_asid.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 v3_asid.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 v3_asid.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-v3_asid.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-v3_asid.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-v3_asid.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-v3_asid.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-v3_asid.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-v3_asid.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-v3_asid.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-v3_asid.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_asid.c
+v3_asid.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+v3_asid.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+v3_asid.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+v3_asid.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+v3_asid.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+v3_asid.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+v3_asid.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+v3_asid.o: ../cryptlib.h v3_asid.c
 v3_bcons.o: ../../e_os.h ../../include/openssl/asn1.h
 v3_bcons.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 v3_bcons.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 v3_bcons.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 v3_bcons.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 v3_bcons.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-v3_bcons.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-v3_bcons.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-v3_bcons.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+v3_bcons.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+v3_bcons.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+v3_bcons.o: ../../include/openssl/opensslconf.h
 v3_bcons.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 v3_bcons.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 v3_bcons.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -266,9 +260,8 @@ v3_bitst.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 v3_bitst.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 v3_bitst.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 v3_bitst.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-v3_bitst.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-v3_bitst.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-v3_bitst.o: ../../include/openssl/opensslconf.h
+v3_bitst.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+v3_bitst.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 v3_bitst.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 v3_bitst.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 v3_bitst.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -281,23 +274,23 @@ v3_conf.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 v3_conf.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 v3_conf.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 v3_conf.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-v3_conf.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-v3_conf.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-v3_conf.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-v3_conf.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-v3_conf.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-v3_conf.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-v3_conf.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-v3_conf.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_conf.c
+v3_conf.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+v3_conf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+v3_conf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+v3_conf.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+v3_conf.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+v3_conf.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+v3_conf.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+v3_conf.o: ../cryptlib.h v3_conf.c
 v3_cpols.o: ../../e_os.h ../../include/openssl/asn1.h
 v3_cpols.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 v3_cpols.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 v3_cpols.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 v3_cpols.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 v3_cpols.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-v3_cpols.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-v3_cpols.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-v3_cpols.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+v3_cpols.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+v3_cpols.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+v3_cpols.o: ../../include/openssl/opensslconf.h
 v3_cpols.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 v3_cpols.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 v3_cpols.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -310,38 +303,37 @@ v3_crld.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 v3_crld.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 v3_crld.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 v3_crld.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-v3_crld.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-v3_crld.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-v3_crld.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-v3_crld.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-v3_crld.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-v3_crld.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-v3_crld.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-v3_crld.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
-v3_crld.o: ../cryptlib.h v3_crld.c
+v3_crld.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+v3_crld.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+v3_crld.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+v3_crld.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+v3_crld.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+v3_crld.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+v3_crld.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+v3_crld.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_crld.c
 v3_enum.o: ../../e_os.h ../../include/openssl/asn1.h
 v3_enum.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 v3_enum.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 v3_enum.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 v3_enum.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 v3_enum.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-v3_enum.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-v3_enum.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-v3_enum.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-v3_enum.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-v3_enum.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-v3_enum.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-v3_enum.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-v3_enum.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_enum.c
+v3_enum.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+v3_enum.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+v3_enum.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+v3_enum.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+v3_enum.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+v3_enum.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+v3_enum.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+v3_enum.o: ../cryptlib.h v3_enum.c
 v3_extku.o: ../../e_os.h ../../include/openssl/asn1.h
 v3_extku.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 v3_extku.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 v3_extku.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 v3_extku.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 v3_extku.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-v3_extku.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-v3_extku.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-v3_extku.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+v3_extku.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+v3_extku.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+v3_extku.o: ../../include/openssl/opensslconf.h
 v3_extku.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 v3_extku.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 v3_extku.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -354,81 +346,76 @@ v3_genn.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 v3_genn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 v3_genn.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 v3_genn.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-v3_genn.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-v3_genn.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-v3_genn.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-v3_genn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-v3_genn.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-v3_genn.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-v3_genn.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-v3_genn.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
-v3_genn.o: ../cryptlib.h v3_genn.c
+v3_genn.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+v3_genn.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+v3_genn.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+v3_genn.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+v3_genn.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+v3_genn.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+v3_genn.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+v3_genn.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_genn.c
 v3_ia5.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 v3_ia5.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 v3_ia5.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 v3_ia5.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 v3_ia5.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-v3_ia5.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-v3_ia5.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-v3_ia5.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-v3_ia5.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-v3_ia5.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-v3_ia5.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-v3_ia5.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-v3_ia5.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
-v3_ia5.o: ../cryptlib.h v3_ia5.c
+v3_ia5.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+v3_ia5.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+v3_ia5.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+v3_ia5.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+v3_ia5.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+v3_ia5.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+v3_ia5.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+v3_ia5.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_ia5.c
 v3_info.o: ../../e_os.h ../../include/openssl/asn1.h
 v3_info.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 v3_info.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 v3_info.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 v3_info.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 v3_info.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-v3_info.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-v3_info.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-v3_info.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-v3_info.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-v3_info.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-v3_info.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-v3_info.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-v3_info.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
-v3_info.o: ../cryptlib.h v3_info.c
+v3_info.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+v3_info.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+v3_info.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+v3_info.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+v3_info.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+v3_info.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+v3_info.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+v3_info.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_info.c
 v3_int.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 v3_int.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 v3_int.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 v3_int.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 v3_int.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-v3_int.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-v3_int.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-v3_int.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-v3_int.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-v3_int.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-v3_int.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-v3_int.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-v3_int.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
-v3_int.o: ../cryptlib.h v3_int.c
+v3_int.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+v3_int.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+v3_int.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+v3_int.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+v3_int.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+v3_int.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+v3_int.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+v3_int.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_int.c
 v3_lib.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 v3_lib.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 v3_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 v3_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 v3_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-v3_lib.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-v3_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-v3_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-v3_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-v3_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-v3_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-v3_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-v3_lib.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
-v3_lib.o: ../cryptlib.h ext_dat.h v3_lib.c
+v3_lib.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+v3_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+v3_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+v3_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+v3_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+v3_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+v3_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+v3_lib.o: ../../include/openssl/x509v3.h ../cryptlib.h ext_dat.h v3_lib.c
 v3_ncons.o: ../../e_os.h ../../include/openssl/asn1.h
 v3_ncons.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 v3_ncons.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 v3_ncons.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 v3_ncons.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 v3_ncons.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-v3_ncons.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-v3_ncons.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-v3_ncons.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+v3_ncons.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+v3_ncons.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+v3_ncons.o: ../../include/openssl/opensslconf.h
 v3_ncons.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 v3_ncons.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 v3_ncons.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -441,52 +428,49 @@ v3_ocsp.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 v3_ocsp.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 v3_ocsp.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 v3_ocsp.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-v3_ocsp.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-v3_ocsp.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-v3_ocsp.o: ../../include/openssl/ocsp.h ../../include/openssl/opensslconf.h
-v3_ocsp.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-v3_ocsp.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-v3_ocsp.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-v3_ocsp.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-v3_ocsp.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
-v3_ocsp.o: ../cryptlib.h v3_ocsp.c
+v3_ocsp.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+v3_ocsp.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h
+v3_ocsp.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+v3_ocsp.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+v3_ocsp.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+v3_ocsp.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+v3_ocsp.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+v3_ocsp.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_ocsp.c
 v3_pci.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 v3_pci.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 v3_pci.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 v3_pci.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 v3_pci.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-v3_pci.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-v3_pci.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-v3_pci.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-v3_pci.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-v3_pci.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-v3_pci.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-v3_pci.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-v3_pci.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
-v3_pci.o: ../cryptlib.h v3_pci.c
+v3_pci.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+v3_pci.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+v3_pci.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+v3_pci.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+v3_pci.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+v3_pci.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+v3_pci.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+v3_pci.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_pci.c
 v3_pcia.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
 v3_pcia.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 v3_pcia.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 v3_pcia.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 v3_pcia.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
-v3_pcia.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-v3_pcia.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-v3_pcia.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-v3_pcia.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-v3_pcia.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-v3_pcia.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-v3_pcia.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-v3_pcia.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
-v3_pcia.o: v3_pcia.c
+v3_pcia.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+v3_pcia.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+v3_pcia.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+v3_pcia.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+v3_pcia.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+v3_pcia.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+v3_pcia.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+v3_pcia.o: ../../include/openssl/x509v3.h v3_pcia.c
 v3_pcons.o: ../../e_os.h ../../include/openssl/asn1.h
 v3_pcons.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 v3_pcons.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 v3_pcons.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 v3_pcons.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 v3_pcons.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-v3_pcons.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-v3_pcons.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-v3_pcons.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+v3_pcons.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+v3_pcons.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+v3_pcons.o: ../../include/openssl/opensslconf.h
 v3_pcons.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 v3_pcons.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 v3_pcons.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -499,24 +483,23 @@ v3_pku.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 v3_pku.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 v3_pku.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 v3_pku.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-v3_pku.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-v3_pku.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-v3_pku.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-v3_pku.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-v3_pku.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-v3_pku.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-v3_pku.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-v3_pku.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
-v3_pku.o: ../cryptlib.h v3_pku.c
+v3_pku.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+v3_pku.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+v3_pku.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+v3_pku.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+v3_pku.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+v3_pku.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+v3_pku.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+v3_pku.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_pku.c
 v3_pmaps.o: ../../e_os.h ../../include/openssl/asn1.h
 v3_pmaps.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 v3_pmaps.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 v3_pmaps.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 v3_pmaps.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 v3_pmaps.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-v3_pmaps.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-v3_pmaps.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-v3_pmaps.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+v3_pmaps.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+v3_pmaps.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+v3_pmaps.o: ../../include/openssl/opensslconf.h
 v3_pmaps.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 v3_pmaps.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 v3_pmaps.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -528,52 +511,51 @@ v3_prn.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 v3_prn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 v3_prn.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 v3_prn.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-v3_prn.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-v3_prn.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-v3_prn.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-v3_prn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-v3_prn.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-v3_prn.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-v3_prn.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-v3_prn.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
-v3_prn.o: ../cryptlib.h v3_prn.c
+v3_prn.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+v3_prn.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+v3_prn.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+v3_prn.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+v3_prn.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+v3_prn.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+v3_prn.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+v3_prn.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_prn.c
 v3_purp.o: ../../e_os.h ../../include/openssl/asn1.h
 v3_purp.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 v3_purp.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 v3_purp.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 v3_purp.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 v3_purp.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-v3_purp.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-v3_purp.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-v3_purp.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-v3_purp.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-v3_purp.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-v3_purp.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-v3_purp.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-v3_purp.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_purp.c
+v3_purp.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+v3_purp.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+v3_purp.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+v3_purp.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+v3_purp.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+v3_purp.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+v3_purp.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+v3_purp.o: ../cryptlib.h v3_purp.c
 v3_skey.o: ../../e_os.h ../../include/openssl/asn1.h
 v3_skey.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 v3_skey.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 v3_skey.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 v3_skey.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 v3_skey.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-v3_skey.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-v3_skey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-v3_skey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-v3_skey.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-v3_skey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-v3_skey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-v3_skey.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-v3_skey.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_skey.c
+v3_skey.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+v3_skey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+v3_skey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+v3_skey.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+v3_skey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+v3_skey.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+v3_skey.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+v3_skey.o: ../cryptlib.h v3_skey.c
 v3_sxnet.o: ../../e_os.h ../../include/openssl/asn1.h
 v3_sxnet.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 v3_sxnet.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 v3_sxnet.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 v3_sxnet.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 v3_sxnet.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-v3_sxnet.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-v3_sxnet.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-v3_sxnet.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+v3_sxnet.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+v3_sxnet.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+v3_sxnet.o: ../../include/openssl/opensslconf.h
 v3_sxnet.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 v3_sxnet.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 v3_sxnet.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -586,25 +568,24 @@ v3_utl.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
 v3_utl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
 v3_utl.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
 v3_utl.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-v3_utl.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-v3_utl.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-v3_utl.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-v3_utl.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-v3_utl.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-v3_utl.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-v3_utl.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-v3_utl.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_utl.c
+v3_utl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+v3_utl.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+v3_utl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+v3_utl.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+v3_utl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+v3_utl.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+v3_utl.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+v3_utl.o: ../cryptlib.h v3_utl.c
 v3err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
 v3err.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
 v3err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 v3err.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
 v3err.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-v3err.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-v3err.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-v3err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-v3err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-v3err.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-v3err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-v3err.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-v3err.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
-v3err.o: v3err.c
+v3err.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+v3err.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+v3err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+v3err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+v3err.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+v3err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+v3err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+v3err.o: ../../include/openssl/x509v3.h v3err.c
index 3eaec46..76daee6 100644 (file)
@@ -61,21 +61,19 @@ extern X509V3_EXT_METHOD v3_bcons, v3_nscert, v3_key_usage, v3_ext_ku;
 extern X509V3_EXT_METHOD v3_pkey_usage_period, v3_sxnet, v3_info, v3_sinfo;
 extern X509V3_EXT_METHOD v3_ns_ia5_list[], v3_alt[], v3_skey_id, v3_akey_id;
 extern X509V3_EXT_METHOD v3_crl_num, v3_crl_reason, v3_crl_invdate;
-extern X509V3_EXT_METHOD v3_delta_crl, v3_cpols, v3_crld;
+extern X509V3_EXT_METHOD v3_delta_crl, v3_cpols, v3_crld, v3_freshest_crl;
 extern X509V3_EXT_METHOD v3_ocsp_nonce, v3_ocsp_accresp, v3_ocsp_acutoff;
 extern X509V3_EXT_METHOD v3_ocsp_crlid, v3_ocsp_nocheck, v3_ocsp_serviceloc;
 extern X509V3_EXT_METHOD v3_crl_hold, v3_pci;
 extern X509V3_EXT_METHOD v3_policy_mappings, v3_policy_constraints;
-extern X509V3_EXT_METHOD v3_name_constraints, v3_inhibit_anyp;
-#ifndef OPENSSL_NO_RFC3779
+extern X509V3_EXT_METHOD v3_name_constraints, v3_inhibit_anyp, v3_idp;
 extern X509V3_EXT_METHOD v3_addr, v3_asid;
-#endif
 
 /* This table will be searched using OBJ_bsearch so it *must* kept in
  * order of the ext_nid values.
  */
 
-static X509V3_EXT_METHOD *standard_exts[] = {
+static const X509V3_EXT_METHOD *standard_exts[] = {
 &v3_nscert,
 &v3_ns_ia5_list[0],
 &v3_ns_ia5_list[1],
@@ -122,7 +120,10 @@ static X509V3_EXT_METHOD *standard_exts[] = {
 &v3_pci,
 &v3_name_constraints,
 &v3_policy_mappings,
-&v3_inhibit_anyp
+&v3_inhibit_anyp,
+&v3_idp,
+&v3_alt[2],
+&v3_freshest_crl,
 };
 
 /* Number of standard extensions */
index 1030931..172b7e7 100644 (file)
@@ -139,7 +139,6 @@ static int policy_cache_new(X509 *x)
                return 0;
        cache->anyPolicy = NULL;
        cache->data = NULL;
-       cache->maps = NULL;
        cache->any_skip = -1;
        cache->explicit_skip = -1;
        cache->map_skip = -1;
index fb392b9..3444b03 100644 (file)
@@ -82,17 +82,21 @@ void policy_data_free(X509_POLICY_DATA *data)
  * another source.
  */
 
-X509_POLICY_DATA *policy_data_new(POLICYINFO *policy, ASN1_OBJECT *id, int crit)
+X509_POLICY_DATA *policy_data_new(POLICYINFO *policy,
+                                       const ASN1_OBJECT *cid, int crit)
        {
        X509_POLICY_DATA *ret;
-       if (!policy && !id)
+       ASN1_OBJECT *id;
+       if (!policy && !cid)
                return NULL;
-       if (id)
+       if (cid)
                {
-               id = OBJ_dup(id);
+               id = OBJ_dup(cid);
                if (!id)
                        return NULL;
                }
+       else
+               id = NULL;
        ret = OPENSSL_malloc(sizeof(X509_POLICY_DATA));
        if (!ret)
                return NULL;
index 3780de4..ccff928 100644 (file)
  *
  */
 
-DECLARE_STACK_OF(X509_POLICY_DATA)
-DECLARE_STACK_OF(X509_POLICY_REF)
-DECLARE_STACK_OF(X509_POLICY_NODE)
 
 typedef struct X509_POLICY_DATA_st X509_POLICY_DATA;
-typedef struct X509_POLICY_REF_st X509_POLICY_REF;
+
+DECLARE_STACK_OF(X509_POLICY_DATA)
 
 /* Internal structures */
 
@@ -110,16 +108,6 @@ struct X509_POLICY_DATA_st
 
 #define POLICY_DATA_FLAG_CRITICAL              0x10
 
-/* This structure is an entry from a table of mapped policies which
- * cross reference the policy it refers to.
- */
-
-struct X509_POLICY_REF_st
-       {
-       ASN1_OBJECT *subjectDomainPolicy;
-       const X509_POLICY_DATA *data;
-       };
-
 /* This structure is cached with a certificate */
 
 struct X509_POLICY_CACHE_st {
@@ -127,8 +115,6 @@ struct X509_POLICY_CACHE_st {
        X509_POLICY_DATA *anyPolicy;
        /* other policy data */
        STACK_OF(X509_POLICY_DATA) *data;
-       /* If policyMappings extension present a table of mapped policies */
-       STACK_OF(X509_POLICY_REF) *maps;
        /* If InhibitAnyPolicy present this is its value or -1 if absent. */
        long any_skip;
        /* If policyConstraints and requireExplicitPolicy present this is its
@@ -193,7 +179,7 @@ struct X509_POLICY_TREE_st
 
 /* Internal functions */
 
-X509_POLICY_DATA *policy_data_new(POLICYINFO *policy, ASN1_OBJECT *id,
+X509_POLICY_DATA *policy_data_new(POLICYINFO *policy, const ASN1_OBJECT *id,
                                                                int crit);
 void policy_data_free(X509_POLICY_DATA *data);
 
@@ -209,15 +195,18 @@ void policy_cache_init(void);
 void policy_cache_free(X509_POLICY_CACHE *cache);
 
 X509_POLICY_NODE *level_find_node(const X509_POLICY_LEVEL *level,
+                                       const X509_POLICY_NODE *parent, 
                                        const ASN1_OBJECT *id);
 
 X509_POLICY_NODE *tree_find_sk(STACK_OF(X509_POLICY_NODE) *sk,
                                                const ASN1_OBJECT *id);
 
 X509_POLICY_NODE *level_add_node(X509_POLICY_LEVEL *level,
-                       X509_POLICY_DATA *data,
+                       const X509_POLICY_DATA *data,
                        X509_POLICY_NODE *parent,
                        X509_POLICY_TREE *tree);
 void policy_node_free(X509_POLICY_NODE *node);
+int policy_node_match(const X509_POLICY_LEVEL *lvl,
+                     const X509_POLICY_NODE *node, const ASN1_OBJECT *oid);
 
 const X509_POLICY_CACHE *policy_cache_set(X509 *x);
index f28796e..21163b5 100644 (file)
 
 #include "pcy_int.h"
 
-static int ref_cmp(const X509_POLICY_REF * const *a,
-                       const X509_POLICY_REF * const *b)
-       {
-       return OBJ_cmp((*a)->subjectDomainPolicy, (*b)->subjectDomainPolicy);
-       }
-
-static void policy_map_free(X509_POLICY_REF *map)
-       {
-       if (map->subjectDomainPolicy)
-               ASN1_OBJECT_free(map->subjectDomainPolicy);
-       OPENSSL_free(map);
-       }
-
-static X509_POLICY_REF *policy_map_find(X509_POLICY_CACHE *cache, ASN1_OBJECT *id)
-       {
-       X509_POLICY_REF tmp;
-       int idx;
-       tmp.subjectDomainPolicy = id;
-
-       idx = sk_X509_POLICY_REF_find(cache->maps, &tmp);
-       if (idx == -1)
-               return NULL;
-       return sk_X509_POLICY_REF_value(cache->maps, idx);
-       }
-
 /* Set policy mapping entries in cache.
  * Note: this modifies the passed POLICY_MAPPINGS structure
  */
@@ -94,7 +69,6 @@ static X509_POLICY_REF *policy_map_find(X509_POLICY_CACHE *cache, ASN1_OBJECT *i
 int policy_cache_set_mapping(X509 *x, POLICY_MAPPINGS *maps)
        {
        POLICY_MAPPING *map;
-       X509_POLICY_REF *ref = NULL;
        X509_POLICY_DATA *data;
        X509_POLICY_CACHE *cache = x->policy_cache;
        int i;
@@ -104,7 +78,6 @@ int policy_cache_set_mapping(X509 *x, POLICY_MAPPINGS *maps)
                ret = -1;
                goto bad_mapping;
                }
-       cache->maps = sk_X509_POLICY_REF_new(ref_cmp);
        for (i = 0; i < sk_POLICY_MAPPING_num(maps); i++)
                {
                map = sk_POLICY_MAPPING_value(maps, i);
@@ -116,13 +89,6 @@ int policy_cache_set_mapping(X509 *x, POLICY_MAPPINGS *maps)
                        goto bad_mapping;
                        }
 
-               /* If we've already mapped from this OID bad mapping */
-               if (policy_map_find(cache, map->subjectDomainPolicy) != NULL)
-                       {
-                       ret = -1;
-                       goto bad_mapping;
-                       }
-
                /* Attempt to find matching policy data */
                data = policy_cache_find_data(cache, map->issuerDomainPolicy);
                /* If we don't have anyPolicy can't map */
@@ -138,7 +104,7 @@ int policy_cache_set_mapping(X509 *x, POLICY_MAPPINGS *maps)
                        if (!data)
                                goto bad_mapping;
                        data->qualifier_set = cache->anyPolicy->qualifier_set;
-                       map->issuerDomainPolicy = NULL;
+                       /*map->issuerDomainPolicy = NULL;*/
                        data->flags |= POLICY_DATA_FLAG_MAPPED_ANY;
                        data->flags |= POLICY_DATA_FLAG_SHARED_QUALIFIERS;
                        if (!sk_X509_POLICY_DATA_push(cache->data, data))
@@ -149,23 +115,10 @@ int policy_cache_set_mapping(X509 *x, POLICY_MAPPINGS *maps)
                        }
                else
                        data->flags |= POLICY_DATA_FLAG_MAPPED;
-
                if (!sk_ASN1_OBJECT_push(data->expected_policy_set, 
                                                map->subjectDomainPolicy))
                        goto bad_mapping;
-               
-               ref = OPENSSL_malloc(sizeof(X509_POLICY_REF));
-               if (!ref)
-                       goto bad_mapping;
-
-               ref->subjectDomainPolicy = map->subjectDomainPolicy;
                map->subjectDomainPolicy = NULL;
-               ref->data = data;
-
-               if (!sk_X509_POLICY_REF_push(cache->maps, ref))
-                       goto bad_mapping;
-
-               ref = NULL;
 
                }
 
@@ -173,13 +126,6 @@ int policy_cache_set_mapping(X509 *x, POLICY_MAPPINGS *maps)
        bad_mapping:
        if (ret == -1)
                x->ex_flags |= EXFLAG_INVALID_POLICY;
-       if (ref)
-               policy_map_free(ref);
-       if (ret <= 0)
-               {
-               sk_X509_POLICY_REF_pop_free(cache->maps, policy_map_free);
-               cache->maps = NULL;
-               }
        sk_POLICY_MAPPING_pop_free(maps, POLICY_MAPPING_free);
        return ret;
 
index 6587cb0..bd1e7f1 100644 (file)
@@ -92,13 +92,25 @@ X509_POLICY_NODE *tree_find_sk(STACK_OF(X509_POLICY_NODE) *nodes,
        }
 
 X509_POLICY_NODE *level_find_node(const X509_POLICY_LEVEL *level,
+                                       const X509_POLICY_NODE *parent, 
                                        const ASN1_OBJECT *id)
        {
-       return tree_find_sk(level->nodes, id);
+       X509_POLICY_NODE *node;
+       int i;
+       for (i = 0; i < sk_X509_POLICY_NODE_num(level->nodes); i++)
+               {
+               node = sk_X509_POLICY_NODE_value(level->nodes, i);
+               if (node->parent == parent)
+                       {
+                       if (!OBJ_cmp(node->data->valid_policy, id))
+                               return node;
+                       }
+               }
+       return NULL;
        }
 
 X509_POLICY_NODE *level_add_node(X509_POLICY_LEVEL *level,
-                       X509_POLICY_DATA *data,
+                       const X509_POLICY_DATA *data,
                        X509_POLICY_NODE *parent,
                        X509_POLICY_TREE *tree)
        {
@@ -155,4 +167,31 @@ void policy_node_free(X509_POLICY_NODE *node)
        OPENSSL_free(node);
        }
 
+/* See if a policy node matches a policy OID. If mapping enabled look through
+ * expected policy set otherwise just valid policy.
+ */
+
+int policy_node_match(const X509_POLICY_LEVEL *lvl,
+                     const X509_POLICY_NODE *node, const ASN1_OBJECT *oid)
+       {
+       int i;
+       ASN1_OBJECT *policy_oid;
+       const X509_POLICY_DATA *x = node->data;
+
+       if (        (lvl->flags & X509_V_FLAG_INHIBIT_MAP)
+               || !(x->flags & POLICY_DATA_FLAG_MAP_MASK))
+               {
+               if (!OBJ_cmp(x->valid_policy, oid))
+                       return 1;
+               return 0;
+               }
+
+       for (i = 0; i < sk_ASN1_OBJECT_num(x->expected_policy_set); i++)
+               {
+               policy_oid = sk_ASN1_OBJECT_value(x->expected_policy_set, i);
+               if (!OBJ_cmp(policy_oid, oid))
+                       return 1;
+               }
+       return 0;
 
+       }
index 89f84bf..bb97773 100644 (file)
 
 #include "pcy_int.h"
 
+/* Enable this to print out the complete policy tree at various point during
+ * evaluation.
+ */
+
+/*#define OPENSSL_POLICY_DEBUG*/
+
+#ifdef OPENSSL_POLICY_DEBUG
+
+static void expected_print(BIO *err, X509_POLICY_LEVEL *lev,
+                               X509_POLICY_NODE *node, int indent)
+       {
+       if (        (lev->flags & X509_V_FLAG_INHIBIT_MAP)
+               || !(node->data->flags & POLICY_DATA_FLAG_MAP_MASK))
+               BIO_puts(err, "  Not Mapped\n");
+       else
+               {
+               int i;
+               STACK_OF(ASN1_OBJECT) *pset = node->data->expected_policy_set;
+               ASN1_OBJECT *oid;
+               BIO_puts(err, "  Expected: ");
+               for (i = 0; i < sk_ASN1_OBJECT_num(pset); i++)
+                       {
+                       oid = sk_ASN1_OBJECT_value(pset, i);
+                       if (i)
+                               BIO_puts(err, ", ");
+                       i2a_ASN1_OBJECT(err, oid);
+                       }
+               BIO_puts(err, "\n");
+               }
+       }
+
+static void tree_print(char *str, X509_POLICY_TREE *tree,
+                       X509_POLICY_LEVEL *curr)
+       {
+       X509_POLICY_LEVEL *plev;
+       X509_POLICY_NODE *node;
+       int i;
+       BIO *err;
+       err = BIO_new_fp(stderr, BIO_NOCLOSE);
+       if (!curr)
+               curr = tree->levels + tree->nlevel;
+       else
+               curr++;
+       BIO_printf(err, "Level print after %s\n", str);
+       BIO_printf(err, "Printing Up to Level %ld\n", curr - tree->levels);
+       for (plev = tree->levels; plev != curr; plev++)
+               {
+               BIO_printf(err, "Level %ld, flags = %x\n",
+                               plev - tree->levels, plev->flags);
+               for (i = 0; i < sk_X509_POLICY_NODE_num(plev->nodes); i++)
+                       {
+                       node = sk_X509_POLICY_NODE_value(plev->nodes, i);
+                       X509_POLICY_NODE_print(err, node, 2);
+                       expected_print(err, plev, node, 2);
+                       BIO_printf(err, "  Flags: %x\n", node->data->flags);
+                       }
+               if (plev->anyPolicy)
+                       X509_POLICY_NODE_print(err, plev->anyPolicy, 2);
+               }
+
+       BIO_free(err);
+
+       }
+#else
+
+#define tree_print(a,b,c) /* */
+
+#endif
+
 /* Initialize policy tree. Return values:
  *  0 Some internal error occured.
  * -1 Inconsistent or invalid extensions in certificates.
@@ -87,8 +156,10 @@ static int tree_init(X509_POLICY_TREE **ptree, STACK_OF(X509) *certs,
        *ptree = NULL;
        n = sk_X509_num(certs);
 
+#if 0
        /* Disable policy mapping for now... */
        flags |= X509_V_FLAG_INHIBIT_MAP;
+#endif
 
        if (flags & X509_V_FLAG_EXPLICIT_POLICY)
                explicit_policy = 0;
@@ -184,7 +255,6 @@ static int tree_init(X509_POLICY_TREE **ptree, STACK_OF(X509) *certs,
                level++;
                x = sk_X509_value(certs, i);
                cache = policy_cache_set(x);
-
                CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509);
                level->cert = x;
 
@@ -213,13 +283,13 @@ static int tree_init(X509_POLICY_TREE **ptree, STACK_OF(X509) *certs,
                        level->flags |= X509_V_FLAG_INHIBIT_MAP;
                else
                        {
-                       map_skip--;
+                       if (!(x->ex_flags & EXFLAG_SI))
+                               map_skip--;
                        if ((cache->map_skip >= 0)
                                && (cache->map_skip < map_skip))
                                map_skip = cache->map_skip;
                        }
 
-
                }
 
        *ptree = tree;
@@ -237,7 +307,32 @@ static int tree_init(X509_POLICY_TREE **ptree, STACK_OF(X509) *certs,
 
        }
 
-/* This corresponds to RFC3280 XXXX XXXXX:
+static int tree_link_matching_nodes(X509_POLICY_LEVEL *curr,
+                               const X509_POLICY_DATA *data)
+       {
+       X509_POLICY_LEVEL *last = curr - 1;
+       X509_POLICY_NODE *node;
+       int i, matched = 0;
+       /* Iterate through all in nodes linking matches */
+       for (i = 0; i < sk_X509_POLICY_NODE_num(last->nodes); i++)
+               {
+               node = sk_X509_POLICY_NODE_value(last->nodes, i);
+               if (policy_node_match(last, node, data->valid_policy))
+                       {
+                       if (!level_add_node(curr, data, node, NULL))
+                               return 0;
+                       matched = 1;
+                       }
+               }
+       if (!matched && last->anyPolicy)
+               {
+               if (!level_add_node(curr, data, last->anyPolicy, NULL))
+                       return 0;
+               }
+       return 1;
+       }
+
+/* This corresponds to RFC3280 6.1.3(d)(1):
  * link any data from CertificatePolicies onto matching parent
  * or anyPolicy if no match.
  */
@@ -246,10 +341,8 @@ static int tree_link_nodes(X509_POLICY_LEVEL *curr,
                                const X509_POLICY_CACHE *cache)
        {
        int i;
-       X509_POLICY_LEVEL *last;
        X509_POLICY_DATA *data;
-       X509_POLICY_NODE *parent;
-       last = curr - 1;
+
        for (i = 0; i < sk_X509_POLICY_DATA_num(cache->data); i++)
                {
                data = sk_X509_POLICY_DATA_value(cache->data, i);
@@ -261,40 +354,109 @@ static int tree_link_nodes(X509_POLICY_LEVEL *curr,
                 * link because then it will have the mapping flags
                 * right and we can prune it later.
                 */
+#if 0
                if ((data->flags & POLICY_DATA_FLAG_MAPPED_ANY)
                        && !(curr->flags & X509_V_FLAG_INHIBIT_ANY))
                        continue;
-               /* Look for matching node in parent */
-               parent = level_find_node(last, data->valid_policy);
-               /* If no match link to anyPolicy */
-               if (!parent)
-                       parent = last->anyPolicy;
-               if (parent && !level_add_node(curr, data, parent, NULL))
+#endif
+               /* Look for matching nodes in previous level */
+               if (!tree_link_matching_nodes(curr, data))
                                return 0;
                }
        return 1;
        }
 
-/* This corresponds to RFC3280 XXXX XXXXX:
+/* This corresponds to RFC3280 6.1.3(d)(2):
  * Create new data for any unmatched policies in the parent and link
  * to anyPolicy.
  */
 
+static int tree_add_unmatched(X509_POLICY_LEVEL *curr,
+                       const X509_POLICY_CACHE *cache,
+                       const ASN1_OBJECT *id,
+                       X509_POLICY_NODE *node,
+                       X509_POLICY_TREE *tree)
+       {
+       X509_POLICY_DATA *data;
+       if (id == NULL)
+               id = node->data->valid_policy;
+       /* Create a new node with qualifiers from anyPolicy and
+        * id from unmatched node.
+        */
+       data = policy_data_new(NULL, id, node_critical(node));
+
+       if (data == NULL)
+               return 0;
+       /* Curr may not have anyPolicy */
+       data->qualifier_set = cache->anyPolicy->qualifier_set;
+       data->flags |= POLICY_DATA_FLAG_SHARED_QUALIFIERS;
+       if (!level_add_node(curr, data, node, tree))
+               {
+               policy_data_free(data);
+               return 0;
+               }
+
+       return 1;
+       }
+
+static int tree_link_unmatched(X509_POLICY_LEVEL *curr,
+                       const X509_POLICY_CACHE *cache,
+                       X509_POLICY_NODE *node,
+                       X509_POLICY_TREE *tree)
+       {
+       const X509_POLICY_LEVEL *last = curr - 1;
+       int i;
+
+       if (        (last->flags & X509_V_FLAG_INHIBIT_MAP)
+               || !(node->data->flags & POLICY_DATA_FLAG_MAPPED))
+               {
+               /* If no policy mapping: matched if one child present */
+               if (node->nchild)
+                       return 1;
+               if (!tree_add_unmatched(curr, cache, NULL, node, tree))
+                       return 0;
+               /* Add it */
+               }
+       else
+               {
+               /* If mapping: matched if one child per expected policy set */
+               STACK_OF(ASN1_OBJECT) *expset = node->data->expected_policy_set;
+               if (node->nchild == sk_ASN1_OBJECT_num(expset))
+                       return 1;
+               /* Locate unmatched nodes */
+               for (i = 0; i < sk_ASN1_OBJECT_num(expset); i++)
+                       {
+                       ASN1_OBJECT *oid = sk_ASN1_OBJECT_value(expset, i);
+                       if (level_find_node(curr, node, oid))
+                               continue;
+                       if (!tree_add_unmatched(curr, cache, oid, node, tree))
+                               return 0;
+                       }
+
+               }
+
+       return 1;
+
+       }
+
 static int tree_link_any(X509_POLICY_LEVEL *curr,
                        const X509_POLICY_CACHE *cache,
                        X509_POLICY_TREE *tree)
        {
        int i;
-       X509_POLICY_DATA *data;
+       /*X509_POLICY_DATA *data;*/
        X509_POLICY_NODE *node;
-       X509_POLICY_LEVEL *last;
-
-       last = curr - 1;
+       X509_POLICY_LEVEL *last = curr - 1;
 
        for (i = 0; i < sk_X509_POLICY_NODE_num(last->nodes); i++)
                {
                node = sk_X509_POLICY_NODE_value(last->nodes, i);
 
+               if (!tree_link_unmatched(curr, cache, node, tree))
+                       return 0;
+
+#if 0
+
                /* Skip any node with any children: we only want unmathced
                 * nodes.
                 *
@@ -303,6 +465,7 @@ static int tree_link_any(X509_POLICY_LEVEL *curr,
                 */
                if (node->nchild)
                        continue;
+
                /* Create a new node with qualifiers from anyPolicy and
                 * id from unmatched node.
                 */
@@ -319,6 +482,9 @@ static int tree_link_any(X509_POLICY_LEVEL *curr,
                        policy_data_free(data);
                        return 0;
                        }
+
+#endif
+
                }
        /* Finally add link to anyPolicy */
        if (last->anyPolicy)
@@ -337,30 +503,36 @@ static int tree_link_any(X509_POLICY_LEVEL *curr,
 
 static int tree_prune(X509_POLICY_TREE *tree, X509_POLICY_LEVEL *curr)
        {
+       STACK_OF(X509_POLICY_NODE) *nodes;
        X509_POLICY_NODE *node;
        int i;
-       for (i = sk_X509_POLICY_NODE_num(curr->nodes) - 1; i >= 0; i--)
+       nodes = curr->nodes;
+       if (curr->flags & X509_V_FLAG_INHIBIT_MAP)
                {
-               node = sk_X509_POLICY_NODE_value(curr->nodes, i);
-               /* Delete any mapped data: see RFC3280 XXXX */
-               if (node->data->flags & POLICY_DATA_FLAG_MAP_MASK)
+               for (i = sk_X509_POLICY_NODE_num(nodes) - 1; i >= 0; i--)
                        {
-                       node->parent->nchild--;
-                       OPENSSL_free(node);
-                       (void)sk_X509_POLICY_NODE_delete(curr->nodes, i);
+                       node = sk_X509_POLICY_NODE_value(nodes, i);
+                       /* Delete any mapped data: see RFC3280 XXXX */
+                       if (node->data->flags & POLICY_DATA_FLAG_MAP_MASK)
+                               {
+                               node->parent->nchild--;
+                               OPENSSL_free(node);
+                               (void)sk_X509_POLICY_NODE_delete(nodes,i);
+                               }
                        }
                }
 
        for(;;) {
                --curr;
-               for (i = sk_X509_POLICY_NODE_num(curr->nodes) - 1; i >= 0; i--)
+               nodes = curr->nodes;
+               for (i = sk_X509_POLICY_NODE_num(nodes) - 1; i >= 0; i--)
                        {
-                       node = sk_X509_POLICY_NODE_value(curr->nodes, i);
+                       node = sk_X509_POLICY_NODE_value(nodes, i);
                        if (node->nchild == 0)
                                {
                                node->parent->nchild--;
                                OPENSSL_free(node);
-                               (void)sk_X509_POLICY_NODE_delete(curr->nodes, i);
+                               (void)sk_X509_POLICY_NODE_delete(nodes, i);
                                }
                        }
                if (curr->anyPolicy && !curr->anyPolicy->nchild)
@@ -536,6 +708,7 @@ static int tree_evaluate(X509_POLICY_TREE *tree)
                if (!(curr->flags & X509_V_FLAG_INHIBIT_ANY)
                        && !tree_link_any(curr, cache, tree))
                        return 0;
+       tree_print("before tree_prune()", tree, curr);
                ret = tree_prune(tree, curr);
                if (ret != 1)
                        return ret;
@@ -604,7 +777,6 @@ int X509_policy_check(X509_POLICY_TREE **ptree, int *pexplicit_policy,
        *pexplicit_policy = 0;
        ret = tree_init(&tree, certs, flags);
 
-
        switch (ret)
                {
 
@@ -613,6 +785,10 @@ int X509_policy_check(X509_POLICY_TREE **ptree, int *pexplicit_policy,
                return 1;
 
                /* Some internal error */
+               case -1:
+               return -1;
+
+               /* Some internal error */
                case 0:
                return 0;
 
@@ -646,6 +822,8 @@ int X509_policy_check(X509_POLICY_TREE **ptree, int *pexplicit_policy,
        if (!tree) goto error;
        ret = tree_evaluate(tree);
 
+       tree_print("tree_evaluate()", tree, NULL);
+
        if (ret <= 0)
                goto error;
 
index d97944f..df46a49 100644 (file)
@@ -142,12 +142,13 @@ unsigned int v3_addr_get_afi(const IPAddressFamily *f)
  * Expand the bitstring form of an address into a raw byte array.
  * At the moment this is coded for simplicity, not speed.
  */
-static void addr_expand(unsigned char *addr,
+static int addr_expand(unsigned char *addr,
                        const ASN1_BIT_STRING *bs,
                        const int length,
                        const unsigned char fill)
 {
-  OPENSSL_assert(bs->length >= 0 && bs->length <= length);
+  if (bs->length < 0 || bs->length > length)
+    return 0;
   if (bs->length > 0) {
     memcpy(addr, bs->data, bs->length);
     if ((bs->flags & 7) != 0) {
@@ -159,6 +160,7 @@ static void addr_expand(unsigned char *addr,
     }
   }
   memset(addr + bs->length, fill, length - bs->length);
+  return 1;
 }
 
 /*
@@ -181,15 +183,13 @@ static int i2r_address(BIO *out,
     return 0;
   switch (afi) {
   case IANA_AFI_IPV4:
-    if (bs->length > 4)
+    if (!addr_expand(addr, bs, 4, fill))
       return 0;
-    addr_expand(addr, bs, 4, fill);
     BIO_printf(out, "%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]);
     break;
   case IANA_AFI_IPV6:
-    if (bs->length > 16)
+    if (!addr_expand(addr, bs, 16, fill))
       return 0;
-    addr_expand(addr, bs, 16, fill);
     for (n = 16; n > 1 && addr[n-1] == 0x00 && addr[n-2] == 0x00; n -= 2)
       ;
     for (i = 0; i < n; i += 2)
@@ -242,7 +242,7 @@ static int i2r_IPAddressOrRanges(BIO *out,
 /*
  * i2r handler for an IPAddrBlocks extension.
  */
-static int i2r_IPAddrBlocks(X509V3_EXT_METHOD *method,
+static int i2r_IPAddrBlocks(const X509V3_EXT_METHOD *method,
                            void *ext,
                            BIO *out,
                            int indent)
@@ -315,34 +315,43 @@ static int i2r_IPAddrBlocks(X509V3_EXT_METHOD *method,
 /*
  * Sort comparison function for a sequence of IPAddressOrRange
  * elements.
+ *
+ * There's no sane answer we can give if addr_expand() fails, and an
+ * assertion failure on externally supplied data is seriously uncool,
+ * so we just arbitrarily declare that if given invalid inputs this
+ * function returns -1.  If this messes up your preferred sort order
+ * for garbage input, tough noogies.
  */
 static int IPAddressOrRange_cmp(const IPAddressOrRange *a,
                                const IPAddressOrRange *b,
                                const int length)
 {
   unsigned char addr_a[ADDR_RAW_BUF_LEN], addr_b[ADDR_RAW_BUF_LEN];
-  int prefixlen_a = 0;
-  int prefixlen_b = 0;
+  int prefixlen_a = 0, prefixlen_b = 0;
   int r;
 
   switch (a->type) {
   case IPAddressOrRange_addressPrefix:
-    addr_expand(addr_a, a->u.addressPrefix, length, 0x00);
+    if (!addr_expand(addr_a, a->u.addressPrefix, length, 0x00))
+      return -1;
     prefixlen_a = addr_prefixlen(a->u.addressPrefix);
     break;
   case IPAddressOrRange_addressRange:
-    addr_expand(addr_a, a->u.addressRange->min, length, 0x00);
+    if (!addr_expand(addr_a, a->u.addressRange->min, length, 0x00))
+      return -1;
     prefixlen_a = length * 8;
     break;
   }
 
   switch (b->type) {
   case IPAddressOrRange_addressPrefix:
-    addr_expand(addr_b, b->u.addressPrefix, length, 0x00);
+    if (!addr_expand(addr_b, b->u.addressPrefix, length, 0x00))
+      return -1;
     prefixlen_b = addr_prefixlen(b->u.addressPrefix);
     break;
   case IPAddressOrRange_addressRange:
-    addr_expand(addr_b, b->u.addressRange->min, length, 0x00);
+    if (!addr_expand(addr_b, b->u.addressRange->min, length, 0x00))
+      return -1;
     prefixlen_b = length * 8;
     break;
   }
@@ -384,6 +393,7 @@ static int range_should_be_prefix(const unsigned char *min,
   unsigned char mask;
   int i, j;
 
+  OPENSSL_assert(memcmp(min, max, length) <= 0);
   for (i = 0; i < length && min[i] == max[i]; i++)
     ;
   for (j = length - 1; j >= 0 && min[j] == 0x00 && max[j] == 0xFF; j--)
@@ -602,10 +612,10 @@ static IPAddressOrRanges *make_prefix_or_range(IPAddrBlocks *addr,
     return NULL;
   switch (afi) {
   case IANA_AFI_IPV4:
-    (void)sk_IPAddressOrRange_set_cmp_func(aors, v4IPAddressOrRange_cmp);
+    (void) sk_IPAddressOrRange_set_cmp_func(aors, v4IPAddressOrRange_cmp);
     break;
   case IANA_AFI_IPV6:
-    (void)sk_IPAddressOrRange_set_cmp_func(aors, v6IPAddressOrRange_cmp);
+    (void) sk_IPAddressOrRange_set_cmp_func(aors, v6IPAddressOrRange_cmp);
     break;
   }
   f->ipAddressChoice->type = IPAddressChoice_addressesOrRanges;
@@ -657,22 +667,22 @@ int v3_addr_add_range(IPAddrBlocks *addr,
 /*
  * Extract min and max values from an IPAddressOrRange.
  */
-static void extract_min_max(IPAddressOrRange *aor,
+static int extract_min_max(IPAddressOrRange *aor,
                            unsigned char *min,
                            unsigned char *max,
                            int length)
 {
-  OPENSSL_assert(aor != NULL && min != NULL && max != NULL);
+  if (aor == NULL || min == NULL || max == NULL)
+    return 0;
   switch (aor->type) {
   case IPAddressOrRange_addressPrefix:
-    addr_expand(min, aor->u.addressPrefix, length, 0x00);
-    addr_expand(max, aor->u.addressPrefix, length, 0xFF);
-    return;
+    return (addr_expand(min, aor->u.addressPrefix, length, 0x00) &&
+           addr_expand(max, aor->u.addressPrefix, length, 0xFF));
   case IPAddressOrRange_addressRange:
-    addr_expand(min, aor->u.addressRange->min, length, 0x00);
-    addr_expand(max, aor->u.addressRange->max, length, 0xFF);
-    return;
+    return (addr_expand(min, aor->u.addressRange->min, length, 0x00) &&
+           addr_expand(max, aor->u.addressRange->max, length, 0xFF));
   }
+  return 0;
 }
 
 /*
@@ -688,9 +698,10 @@ int v3_addr_get_range(IPAddressOrRange *aor,
   if (aor == NULL || min == NULL || max == NULL ||
       afi_length == 0 || length < afi_length ||
       (aor->type != IPAddressOrRange_addressPrefix &&
-       aor->type != IPAddressOrRange_addressRange))
+       aor->type != IPAddressOrRange_addressRange) ||
+      !extract_min_max(aor, min, max, afi_length))
     return 0;
-  extract_min_max(aor, min, max, afi_length);
+
   return afi_length;
 }
 
@@ -772,8 +783,9 @@ int v3_addr_is_canonical(IPAddrBlocks *addr)
       IPAddressOrRange *a = sk_IPAddressOrRange_value(aors, j);
       IPAddressOrRange *b = sk_IPAddressOrRange_value(aors, j + 1);
 
-      extract_min_max(a, a_min, a_max, length);
-      extract_min_max(b, b_min, b_max, length);
+      if (!extract_min_max(a, a_min, a_max, length) ||
+         !extract_min_max(b, b_min, b_max, length))
+       return 0;
 
       /*
        * Punt misordered list, overlapping start, or inverted range.
@@ -801,14 +813,17 @@ int v3_addr_is_canonical(IPAddrBlocks *addr)
     }
 
     /*
-     * Check final range to see if it should be a prefix.
+     * Check range to see if it's inverted or should be a
+     * prefix.
      */
     j = sk_IPAddressOrRange_num(aors) - 1;
     {
       IPAddressOrRange *a = sk_IPAddressOrRange_value(aors, j);
-      if (a->type == IPAddressOrRange_addressRange) {
-       extract_min_max(a, a_min, a_max, length);
-       if (range_should_be_prefix(a_min, a_max, length) >= 0)
+      if (a != NULL && a->type == IPAddressOrRange_addressRange) {
+       if (!extract_min_max(a, a_min, a_max, length))
+         return 0;
+       if (memcmp(a_min, a_max, length) > 0 ||
+           range_should_be_prefix(a_min, a_max, length) >= 0)
          return 0;
       }
     }
@@ -842,8 +857,16 @@ static int IPAddressOrRanges_canonize(IPAddressOrRanges *aors,
     unsigned char a_min[ADDR_RAW_BUF_LEN], a_max[ADDR_RAW_BUF_LEN];
     unsigned char b_min[ADDR_RAW_BUF_LEN], b_max[ADDR_RAW_BUF_LEN];
 
-    extract_min_max(a, a_min, a_max, length);
-    extract_min_max(b, b_min, b_max, length);
+    if (!extract_min_max(a, a_min, a_max, length) ||
+       !extract_min_max(b, b_min, b_max, length))
+      return 0;
+
+    /*
+     * Punt inverted ranges.
+     */
+    if (memcmp(a_min, a_max, length) > 0 ||
+       memcmp(b_min, b_max, length) > 0)
+      return 0;
 
     /*
      * Punt overlaps.
@@ -861,8 +884,8 @@ static int IPAddressOrRanges_canonize(IPAddressOrRanges *aors,
       IPAddressOrRange *merged;
       if (!make_addressRange(&merged, a_min, b_max, length))
        return 0;
-      sk_IPAddressOrRange_set(aors, i, merged);
-      (void)sk_IPAddressOrRange_delete(aors, i + 1);
+      (void) sk_IPAddressOrRange_set(aors, i, merged);
+      (void) sk_IPAddressOrRange_delete(aors, i + 1);
       IPAddressOrRange_free(a);
       IPAddressOrRange_free(b);
       --i;
@@ -870,6 +893,20 @@ static int IPAddressOrRanges_canonize(IPAddressOrRanges *aors,
     }
   }
 
+  /*
+   * Check for inverted final range.
+   */
+  j = sk_IPAddressOrRange_num(aors) - 1;
+  {
+    IPAddressOrRange *a = sk_IPAddressOrRange_value(aors, j);
+    if (a != NULL && a->type == IPAddressOrRange_addressRange) {
+      unsigned char a_min[ADDR_RAW_BUF_LEN], a_max[ADDR_RAW_BUF_LEN];
+      extract_min_max(a, a_min, a_max, length);
+      if (memcmp(a_min, a_max, length) > 0)
+       return 0;
+    }
+  }
+
   return 1;
 }
 
@@ -886,7 +923,7 @@ int v3_addr_canonize(IPAddrBlocks *addr)
                                    v3_addr_get_afi(f)))
       return 0;
   }
-  (void)sk_IPAddressFamily_set_cmp_func(addr, IPAddressFamily_cmp);
+  (void) sk_IPAddressFamily_set_cmp_func(addr, IPAddressFamily_cmp);
   sk_IPAddressFamily_sort(addr);
   OPENSSL_assert(v3_addr_is_canonical(addr));
   return 1;
@@ -895,7 +932,7 @@ int v3_addr_canonize(IPAddrBlocks *addr)
 /*
  * v2i handler for the IPAddrBlocks extension.
  */
-static void *v2i_IPAddrBlocks(struct v3_ext_method *method,
+static void *v2i_IPAddrBlocks(const struct v3_ext_method *method,
                              struct v3_ext_ctx *ctx,
                              STACK_OF(CONF_VALUE) *values)
 {
@@ -1018,6 +1055,11 @@ static void *v2i_IPAddrBlocks(struct v3_ext_method *method,
        X509V3_conf_err(val);
        goto err;
       }
+      if (memcmp(min, max, length_from_afi(afi)) > 0) {
+       X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_EXTENSION_VALUE_ERROR);
+       X509V3_conf_err(val);
+       goto err;
+      }
       if (!v3_addr_add_range(addr, afi, safi, min, max)) {
        X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE);
        goto err;
@@ -1103,13 +1145,15 @@ static int addr_contains(IPAddressOrRanges *parent,
 
   p = 0;
   for (c = 0; c < sk_IPAddressOrRange_num(child); c++) {
-    extract_min_max(sk_IPAddressOrRange_value(child, c),
-                   c_min, c_max, length);
+    if (!extract_min_max(sk_IPAddressOrRange_value(child, c),
+                        c_min, c_max, length))
+      return -1;
     for (;; p++) {
       if (p >= sk_IPAddressOrRange_num(parent))
        return 0;
-      extract_min_max(sk_IPAddressOrRange_value(parent, p),
-                     p_min, p_max, length);
+      if (!extract_min_max(sk_IPAddressOrRange_value(parent, p),
+                          p_min, p_max, length))
+       return 0;
       if (memcmp(p_max, c_max, length) < 0)
        continue;
       if (memcmp(p_min, c_min, length) > 0)
@@ -1131,7 +1175,7 @@ int v3_addr_subset(IPAddrBlocks *a, IPAddrBlocks *b)
     return 1;
   if (b == NULL || v3_addr_inherits(a) || v3_addr_inherits(b))
     return 0;
-  (void)sk_IPAddressFamily_set_cmp_func(b, IPAddressFamily_cmp);
+  (void) sk_IPAddressFamily_set_cmp_func(b, IPAddressFamily_cmp);
   for (i = 0; i < sk_IPAddressFamily_num(a); i++) {
     IPAddressFamily *fa = sk_IPAddressFamily_value(a, i);
     int j = sk_IPAddressFamily_find(b, fa);
@@ -1173,7 +1217,7 @@ static int v3_addr_validate_path_internal(X509_STORE_CTX *ctx,
 {
   IPAddrBlocks *child = NULL;
   int i, j, ret = 1;
-  X509 *x = NULL;
+  X509 *x;
 
   OPENSSL_assert(chain != NULL && sk_X509_num(chain) > 0);
   OPENSSL_assert(ctx != NULL || ext != NULL);
@@ -1186,6 +1230,7 @@ static int v3_addr_validate_path_internal(X509_STORE_CTX *ctx,
    */
   if (ext != NULL) {
     i = -1;
+    x = NULL;
   } else {
     i = 0;
     x = sk_X509_value(chain, i);
@@ -1195,7 +1240,7 @@ static int v3_addr_validate_path_internal(X509_STORE_CTX *ctx,
   }
   if (!v3_addr_is_canonical(ext))
     validation_err(X509_V_ERR_INVALID_EXTENSION);
-  (void)sk_IPAddressFamily_set_cmp_func(ext, IPAddressFamily_cmp);
+  (void) sk_IPAddressFamily_set_cmp_func(ext, IPAddressFamily_cmp);
   if ((child = sk_IPAddressFamily_dup(ext)) == NULL) {
     X509V3err(X509V3_F_V3_ADDR_VALIDATE_PATH_INTERNAL, ERR_R_MALLOC_FAILURE);
     ret = 0;
@@ -1221,7 +1266,7 @@ static int v3_addr_validate_path_internal(X509_STORE_CTX *ctx,
       }
       continue;
     }
-    (void)sk_IPAddressFamily_set_cmp_func(x->rfc3779_addr, IPAddressFamily_cmp);
+    (void) sk_IPAddressFamily_set_cmp_func(x->rfc3779_addr, IPAddressFamily_cmp);
     for (j = 0; j < sk_IPAddressFamily_num(child); j++) {
       IPAddressFamily *fc = sk_IPAddressFamily_value(child, j);
       int k = sk_IPAddressFamily_find(x->rfc3779_addr, fc);
@@ -1248,6 +1293,7 @@ static int v3_addr_validate_path_internal(X509_STORE_CTX *ctx,
   /*
    * Trust anchor can't inherit.
    */
+  OPENSSL_assert(x != NULL);
   if (x->rfc3779_addr != NULL) {
     for (j = 0; j < sk_IPAddressFamily_num(x->rfc3779_addr); j++) {
       IPAddressFamily *fp = sk_IPAddressFamily_value(x->rfc3779_addr, j);
index 69244e4..d29d943 100644 (file)
@@ -82,6 +82,12 @@ NULL, NULL, NULL},
 (X509V3_EXT_I2V)i2v_GENERAL_NAMES,
 (X509V3_EXT_V2I)v2i_issuer_alt,
 NULL, NULL, NULL},
+
+{ NID_certificate_issuer, 0, ASN1_ITEM_ref(GENERAL_NAMES),
+0,0,0,0,
+0,0,
+(X509V3_EXT_I2V)i2v_GENERAL_NAMES,
+NULL, NULL, NULL, NULL},
 };
 
 STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method,
@@ -387,8 +393,8 @@ static int copy_email(X509V3_CTX *ctx, GENERAL_NAMES *gens, int move_p)
        
 }
 
-GENERAL_NAMES *v2i_GENERAL_NAMES(X509V3_EXT_METHOD *method,
-                               X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
+GENERAL_NAMES *v2i_GENERAL_NAMES(const X509V3_EXT_METHOD *method,
+                                X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
 {
        GENERAL_NAME *gen;
        GENERAL_NAMES *gens = NULL;
@@ -409,28 +415,22 @@ GENERAL_NAMES *v2i_GENERAL_NAMES(X509V3_EXT_METHOD *method,
        return NULL;
 }
 
-GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
-                                                        CONF_VALUE *cnf)
+GENERAL_NAME *v2i_GENERAL_NAME(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
+                              CONF_VALUE *cnf)
        {
        return v2i_GENERAL_NAME_ex(NULL, method, ctx, cnf, 0);
        }
 
-GENERAL_NAME *v2i_GENERAL_NAME_ex(GENERAL_NAME *out,
-                               X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
-                                                CONF_VALUE *cnf, int is_nc)
+GENERAL_NAME *a2i_GENERAL_NAME(GENERAL_NAME *out,
+                              const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
+                              int gen_type, char *value, int is_nc)
        {
        char is_string = 0;
-       int type;
        GENERAL_NAME *gen = NULL;
 
-       char *name, *value;
-
-       name = cnf->name;
-       value = cnf->value;
-
        if(!value)
                {
-               X509V3err(X509V3_F_V2I_GENERAL_NAME_EX,X509V3_R_MISSING_VALUE);
+               X509V3err(X509V3_F_A2I_GENERAL_NAME,X509V3_R_MISSING_VALUE);
                return NULL;
                }
 
@@ -441,74 +441,62 @@ GENERAL_NAME *v2i_GENERAL_NAME_ex(GENERAL_NAME *out,
                gen = GENERAL_NAME_new();
                if(gen == NULL)
                        {
-                       X509V3err(X509V3_F_V2I_GENERAL_NAME_EX,ERR_R_MALLOC_FAILURE);
+                       X509V3err(X509V3_F_A2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
                        return NULL;
                        }
                }
 
-       if(!name_cmp(name, "email"))
-               {
-               is_string = 1;
-               type = GEN_EMAIL;
-               }
-       else if(!name_cmp(name, "URI"))
-               {
-               is_string = 1;
-               type = GEN_URI;
-               }
-       else if(!name_cmp(name, "DNS"))
+       switch (gen_type)
                {
+               case GEN_URI:
+               case GEN_EMAIL:
+               case GEN_DNS:
                is_string = 1;
-               type = GEN_DNS;
-               }
-       else if(!name_cmp(name, "RID"))
+               break;
+               
+               case GEN_RID:
                {
                ASN1_OBJECT *obj;
                if(!(obj = OBJ_txt2obj(value,0)))
                        {
-                       X509V3err(X509V3_F_V2I_GENERAL_NAME_EX,X509V3_R_BAD_OBJECT);
+                       X509V3err(X509V3_F_A2I_GENERAL_NAME,X509V3_R_BAD_OBJECT);
                        ERR_add_error_data(2, "value=", value);
                        goto err;
                        }
                gen->d.rid = obj;
-               type = GEN_RID;
                }
-       else if(!name_cmp(name, "IP"))
-               {
+               break;
+
+               case GEN_IPADD:
                if (is_nc)
                        gen->d.ip = a2i_IPADDRESS_NC(value);
                else
                        gen->d.ip = a2i_IPADDRESS(value);
                if(gen->d.ip == NULL)
                        {
-                       X509V3err(X509V3_F_V2I_GENERAL_NAME_EX,X509V3_R_BAD_IP_ADDRESS);
+                       X509V3err(X509V3_F_A2I_GENERAL_NAME,X509V3_R_BAD_IP_ADDRESS);
                        ERR_add_error_data(2, "value=", value);
                        goto err;
                        }
-               type = GEN_IPADD;
-               }
-       else if(!name_cmp(name, "dirName"))
-               {
-               type = GEN_DIRNAME;
+               break;
+
+               case GEN_DIRNAME:
                if (!do_dirname(gen, value, ctx))
                        {
-                       X509V3err(X509V3_F_V2I_GENERAL_NAME_EX,X509V3_R_DIRNAME_ERROR);
+                       X509V3err(X509V3_F_A2I_GENERAL_NAME,X509V3_R_DIRNAME_ERROR);
                        goto err;
                        }
-               }
-       else if(!name_cmp(name, "otherName"))
-               {
+               break;
+
+               case GEN_OTHERNAME:
                if (!do_othername(gen, value, ctx))
                        {
-                       X509V3err(X509V3_F_V2I_GENERAL_NAME_EX,X509V3_R_OTHERNAME_ERROR);
+                       X509V3err(X509V3_F_A2I_GENERAL_NAME,X509V3_R_OTHERNAME_ERROR);
                        goto err;
                        }
-               type = GEN_OTHERNAME;
-               }
-       else
-               {
-               X509V3err(X509V3_F_V2I_GENERAL_NAME_EX,X509V3_R_UNSUPPORTED_OPTION);
-               ERR_add_error_data(2, "name=", name);
+               break;
+               default:
+               X509V3err(X509V3_F_A2I_GENERAL_NAME,X509V3_R_UNSUPPORTED_TYPE);
                goto err;
                }
 
@@ -518,12 +506,12 @@ GENERAL_NAME *v2i_GENERAL_NAME_ex(GENERAL_NAME *out,
                              !ASN1_STRING_set(gen->d.ia5, (unsigned char*)value,
                                               strlen(value)))
                        {
-                       X509V3err(X509V3_F_V2I_GENERAL_NAME_EX,ERR_R_MALLOC_FAILURE);
+                       X509V3err(X509V3_F_A2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
                        goto err;
                        }
                }
 
-       gen->type = type;
+       gen->type = gen_type;
 
        return gen;
 
@@ -533,6 +521,48 @@ GENERAL_NAME *v2i_GENERAL_NAME_ex(GENERAL_NAME *out,
        return NULL;
        }
 
+GENERAL_NAME *v2i_GENERAL_NAME_ex(GENERAL_NAME *out,
+                                 const X509V3_EXT_METHOD *method,
+                                 X509V3_CTX *ctx, CONF_VALUE *cnf, int is_nc)
+       {
+       int type;
+
+       char *name, *value;
+
+       name = cnf->name;
+       value = cnf->value;
+
+       if(!value)
+               {
+               X509V3err(X509V3_F_V2I_GENERAL_NAME_EX,X509V3_R_MISSING_VALUE);
+               return NULL;
+               }
+
+       if(!name_cmp(name, "email"))
+               type = GEN_EMAIL;
+       else if(!name_cmp(name, "URI"))
+               type = GEN_URI;
+       else if(!name_cmp(name, "DNS"))
+               type = GEN_DNS;
+       else if(!name_cmp(name, "RID"))
+               type = GEN_RID;
+       else if(!name_cmp(name, "IP"))
+               type = GEN_IPADD;
+       else if(!name_cmp(name, "dirName"))
+               type = GEN_DIRNAME;
+       else if(!name_cmp(name, "otherName"))
+               type = GEN_OTHERNAME;
+       else
+               {
+               X509V3err(X509V3_F_V2I_GENERAL_NAME_EX,X509V3_R_UNSUPPORTED_OPTION);
+               ERR_add_error_data(2, "name=", name);
+               return NULL;
+               }
+
+       return a2i_GENERAL_NAME(out, method, ctx, type, value, is_nc);
+
+       }
+
 static int do_othername(GENERAL_NAME *gen, char *value, X509V3_CTX *ctx)
        {
        char *objtmp = NULL, *p;
@@ -578,7 +608,6 @@ static int do_dirname(GENERAL_NAME *gen, char *value, X509V3_CTX *ctx)
        if (!ret)
                X509_NAME_free(nm);
        gen->d.dirn = nm;
-
        X509V3_section_free(ctx, sk);
                
        return ret;
index cff04a3..3f434c0 100644 (file)
@@ -151,7 +151,7 @@ static int i2r_ASIdentifierChoice(BIO *out,
 /*
  * i2r method for an ASIdentifier extension.
  */
-static int i2r_ASIdentifiers(X509V3_EXT_METHOD *method,
+static int i2r_ASIdentifiers(const X509V3_EXT_METHOD *method,
                             void *ext,
                             BIO *out,
                             int indent)
@@ -465,7 +465,7 @@ static int ASIdentifierChoice_canonize(ASIdentifierChoice *choice)
        break;
       }
       ASIdOrRange_free(b);
-      (void)sk_ASIdOrRange_delete(choice->u.asIdsOrRanges, i + 1);
+      sk_ASIdOrRange_delete(choice->u.asIdsOrRanges, i + 1);
       i--;
       continue;
     }
@@ -494,7 +494,7 @@ int v3_asid_canonize(ASIdentifiers *asid)
 /*
  * v2i method for an ASIdentifier extension.
  */
-static void *v2i_ASIdentifiers(struct v3_ext_method *method,
+static void *v2i_ASIdentifiers(const struct v3_ext_method *method,
                               struct v3_ext_ctx *ctx,
                               STACK_OF(CONF_VALUE) *values)
 {
@@ -706,7 +706,7 @@ static int v3_asid_validate_path_internal(X509_STORE_CTX *ctx,
 {
   ASIdOrRanges *child_as = NULL, *child_rdi = NULL;
   int i, ret = 1, inherit_as = 0, inherit_rdi = 0;
-  X509 *x = NULL;
+  X509 *x;
 
   OPENSSL_assert(chain != NULL && sk_X509_num(chain) > 0);
   OPENSSL_assert(ctx != NULL || ext != NULL);
@@ -719,6 +719,7 @@ static int v3_asid_validate_path_internal(X509_STORE_CTX *ctx,
    */
   if (ext != NULL) {
     i = -1;
+    x = NULL;
   } else {
     i = 0;
     x = sk_X509_value(chain, i);
@@ -798,6 +799,7 @@ static int v3_asid_validate_path_internal(X509_STORE_CTX *ctx,
   /*
    * Trust anchor can't inherit.
    */
+  OPENSSL_assert(x != NULL);
   if (x->rfc3779_asid != NULL) {
     if (x->rfc3779_asid->asnum != NULL &&
        x->rfc3779_asid->asnum->type == ASIdentifierChoice_inherit)
index 11eb6b7..6730f9a 100644 (file)
@@ -72,14 +72,14 @@ static X509_EXTENSION *do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid, in
 static X509_EXTENSION *v3_generic_extension(const char *ext, char *value, int crit, int type, X509V3_CTX *ctx);
 static char *conf_lhash_get_string(void *db, char *section, char *value);
 static STACK_OF(CONF_VALUE) *conf_lhash_get_section(void *db, char *section);
-static X509_EXTENSION *do_ext_i2d(X509V3_EXT_METHOD *method, int ext_nid,
-                                                int crit, void *ext_struc);
+static X509_EXTENSION *do_ext_i2d(const X509V3_EXT_METHOD *method, int ext_nid,
+                                 int crit, void *ext_struc);
 static unsigned char *generic_asn1(char *value, X509V3_CTX *ctx, long *ext_len);
 /* CONF *conf:  Config file    */
 /* char *name:  Name    */
 /* char *value:  Value    */
 X509_EXTENSION *X509V3_EXT_nconf(CONF *conf, X509V3_CTX *ctx, char *name,
-            char *value)
+                                char *value)
        {
        int crit;
        int ext_type;
@@ -99,7 +99,7 @@ X509_EXTENSION *X509V3_EXT_nconf(CONF *conf, X509V3_CTX *ctx, char *name,
 /* CONF *conf:  Config file    */
 /* char *value:  Value    */
 X509_EXTENSION *X509V3_EXT_nconf_nid(CONF *conf, X509V3_CTX *ctx, int ext_nid,
-            char *value)
+                                    char *value)
        {
        int crit;
        int ext_type;
@@ -113,9 +113,9 @@ X509_EXTENSION *X509V3_EXT_nconf_nid(CONF *conf, X509V3_CTX *ctx, int ext_nid,
 /* CONF *conf:  Config file    */
 /* char *value:  Value    */
 static X509_EXTENSION *do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid,
-            int crit, char *value)
+                                   int crit, char *value)
        {
-       X509V3_EXT_METHOD *method;
+       const X509V3_EXT_METHOD *method;
        X509_EXTENSION *ext;
        STACK_OF(CONF_VALUE) *nval;
        void *ext_struc;
@@ -172,8 +172,8 @@ static X509_EXTENSION *do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid,
 
        }
 
-static X509_EXTENSION *do_ext_i2d(X509V3_EXT_METHOD *method, int ext_nid,
-                                                int crit, void *ext_struc)
+static X509_EXTENSION *do_ext_i2d(const X509V3_EXT_METHOD *method, int ext_nid,
+                                 int crit, void *ext_struc)
        {
        unsigned char *ext_der;
        int ext_len;
@@ -214,7 +214,7 @@ static X509_EXTENSION *do_ext_i2d(X509V3_EXT_METHOD *method, int ext_nid,
 
 X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc)
        {
-       X509V3_EXT_METHOD *method;
+       const X509V3_EXT_METHOD *method;
        if (!(method = X509V3_EXT_get_nid(ext_nid))) {
                X509V3err(X509V3_F_X509V3_EXT_I2D,X509V3_R_UNKNOWN_EXTENSION);
                return NULL;
@@ -258,7 +258,8 @@ static int v3_check_generic(char **value)
 
 /* Create a generic extension: for now just handle DER type */
 static X509_EXTENSION *v3_generic_extension(const char *ext, char *value,
-            int crit, int gen_type, X509V3_CTX *ctx)
+                                           int crit, int gen_type,
+                                           X509V3_CTX *ctx)
        {
        unsigned char *ext_der=NULL;
        long ext_len;
@@ -322,7 +323,7 @@ static unsigned char *generic_asn1(char *value, X509V3_CTX *ctx, long *ext_len)
 
 
 int X509V3_EXT_add_nconf_sk(CONF *conf, X509V3_CTX *ctx, char *section,
-            STACK_OF(X509_EXTENSION) **sk)
+                           STACK_OF(X509_EXTENSION) **sk)
        {
        X509_EXTENSION *ext;
        STACK_OF(CONF_VALUE) *nval;
@@ -343,7 +344,7 @@ int X509V3_EXT_add_nconf_sk(CONF *conf, X509V3_CTX *ctx, char *section,
 /* Convenience functions to add extensions to a certificate, CRL and request */
 
 int X509V3_EXT_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section,
-            X509 *cert)
+                        X509 *cert)
        {
        STACK_OF(X509_EXTENSION) **sk = NULL;
        if (cert)
@@ -354,7 +355,7 @@ int X509V3_EXT_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section,
 /* Same as above but for a CRL */
 
 int X509V3_EXT_CRL_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section,
-            X509_CRL *crl)
+                            X509_CRL *crl)
        {
        STACK_OF(X509_EXTENSION) **sk = NULL;
        if (crl)
@@ -443,7 +444,7 @@ void X509V3_set_nconf(X509V3_CTX *ctx, CONF *conf)
        }
 
 void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subj, X509_REQ *req,
-            X509_CRL *crl, int flags)
+                   X509_CRL *crl, int flags)
        {
        ctx->issuer_cert = issuer;
        ctx->subject_cert = subj;
@@ -454,8 +455,8 @@ void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subj, X509_REQ *req,
 
 /* Old conf compatibility functions */
 
-X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name,
-            char *value)
+X509_EXTENSION *X509V3_EXT_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx,
+                               char *name, char *value)
        {
        CONF ctmp;
        CONF_set_nconf(&ctmp, conf);
@@ -464,8 +465,8 @@ X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name,
 
 /* LHASH *conf:  Config file    */
 /* char *value:  Value    */
-X509_EXTENSION *X509V3_EXT_conf_nid(LHASH *conf, X509V3_CTX *ctx, int ext_nid,
-            char *value)
+X509_EXTENSION *X509V3_EXT_conf_nid(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx,
+                                   int ext_nid, char *value)
        {
        CONF ctmp;
        CONF_set_nconf(&ctmp, conf);
@@ -489,14 +490,14 @@ NULL,
 NULL
 };
 
-void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash)
+void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH_OF(CONF_VALUE) *lhash)
        {
        ctx->db_meth = &conf_lhash_method;
        ctx->db = lhash;
        }
 
-int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
-            X509 *cert)
+int X509V3_EXT_add_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx,
+                       char *section, X509 *cert)
        {
        CONF ctmp;
        CONF_set_nconf(&ctmp, conf);
@@ -505,8 +506,8 @@ int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
 
 /* Same as above but for a CRL */
 
-int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
-            X509_CRL *crl)
+int X509V3_EXT_CRL_add_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx,
+                           char *section, X509_CRL *crl)
        {
        CONF ctmp;
        CONF_set_nconf(&ctmp, conf);
@@ -515,8 +516,8 @@ int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
 
 /* Add extensions to certificate request */
 
-int X509V3_EXT_REQ_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
-            X509_REQ *req)
+int X509V3_EXT_REQ_add_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx,
+                           char *section, X509_REQ *req)
        {
        CONF ctmp;
        CONF_set_nconf(&ctmp, conf);
index ad0506d..1f0798b 100644 (file)
@@ -450,5 +450,8 @@ void X509_POLICY_NODE_print(BIO *out, X509_POLICY_NODE *node, int indent)
        else
                BIO_printf(out, "%*sNo Qualifiers\n", indent + 2, "");
        }
-       
+
+
 IMPLEMENT_STACK_OF(X509_POLICY_NODE)
+IMPLEMENT_STACK_OF(X509_POLICY_DATA)
+
index 181a897..790a6dd 100644 (file)
@@ -3,7 +3,7 @@
  * project 1999.
  */
 /* ====================================================================
- * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2008 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include <openssl/asn1t.h>
 #include <openssl/x509v3.h>
 
-static STACK_OF(CONF_VALUE) *i2v_crld(X509V3_EXT_METHOD *method,
-               STACK_OF(DIST_POINT) *crld, STACK_OF(CONF_VALUE) *extlist);
-static STACK_OF(DIST_POINT) *v2i_crld(X509V3_EXT_METHOD *method,
-                               X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
-
-const X509V3_EXT_METHOD v3_crld = {
-NID_crl_distribution_points, X509V3_EXT_MULTILINE, ASN1_ITEM_ref(CRL_DIST_POINTS),
-0,0,0,0,
-0,0,
-(X509V3_EXT_I2V)i2v_crld,
-(X509V3_EXT_V2I)v2i_crld,
-0,0,
-NULL
+static void *v2i_crld(const X509V3_EXT_METHOD *method,
+                     X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
+static int i2r_crldp(const X509V3_EXT_METHOD *method, void *pcrldp, BIO *out,
+                    int indent);
+
+const X509V3_EXT_METHOD v3_crld =
+       {
+       NID_crl_distribution_points, 0, ASN1_ITEM_ref(CRL_DIST_POINTS),
+       0,0,0,0,
+       0,0,
+       0,
+       v2i_crld,
+       i2r_crldp,0,
+       NULL
+       };
+
+const X509V3_EXT_METHOD v3_freshest_crl =
+       {
+       NID_freshest_crl, 0, ASN1_ITEM_ref(CRL_DIST_POINTS),
+       0,0,0,0,
+       0,0,
+       0,
+       v2i_crld,
+       i2r_crldp,0,
+       NULL
+       };
+
+static STACK_OF(GENERAL_NAME) *gnames_from_sectname(X509V3_CTX *ctx, char *sect)
+       {
+       STACK_OF(CONF_VALUE) *gnsect;
+       STACK_OF(GENERAL_NAME) *gens;
+       if (*sect == '@')
+               gnsect = X509V3_get_section(ctx, sect + 1);
+       else
+               gnsect = X509V3_parse_list(sect);
+       if (!gnsect)
+               {
+               X509V3err(X509V3_F_GNAMES_FROM_SECTNAME,
+                                               X509V3_R_SECTION_NOT_FOUND);
+               return NULL;
+               }
+       gens = v2i_GENERAL_NAMES(NULL, ctx, gnsect);
+       if (*sect == '@')
+               X509V3_section_free(ctx, gnsect);
+       else
+               sk_CONF_VALUE_pop_free(gnsect, X509V3_conf_free);
+       return gens;
+       }
+
+static int set_dist_point_name(DIST_POINT_NAME **pdp, X509V3_CTX *ctx,
+                                                       CONF_VALUE *cnf)
+       {
+       STACK_OF(GENERAL_NAME) *fnm = NULL;
+       STACK_OF(X509_NAME_ENTRY) *rnm = NULL;
+       if (!strncmp(cnf->name, "fullname", 9))
+               {
+               fnm = gnames_from_sectname(ctx, cnf->value);
+               if (!fnm)
+                       goto err;
+               }
+       else if (!strcmp(cnf->name, "relativename"))
+               {
+               int ret;
+               STACK_OF(CONF_VALUE) *dnsect;
+               X509_NAME *nm;
+               nm = X509_NAME_new();
+               if (!nm)
+                       return -1;
+               dnsect = X509V3_get_section(ctx, cnf->value);
+               if (!dnsect)
+                       {
+                       X509V3err(X509V3_F_SET_DIST_POINT_NAME,
+                                               X509V3_R_SECTION_NOT_FOUND);
+                       return -1;
+                       }
+               ret = X509V3_NAME_from_section(nm, dnsect, MBSTRING_ASC);
+               X509V3_section_free(ctx, dnsect);
+               rnm = nm->entries;
+               nm->entries = NULL;
+               X509_NAME_free(nm);
+               if (!ret || sk_X509_NAME_ENTRY_num(rnm) <= 0)
+                       goto err;
+               /* Since its a name fragment can't have more than one
+                * RDNSequence
+                */
+               if (sk_X509_NAME_ENTRY_value(rnm,
+                               sk_X509_NAME_ENTRY_num(rnm) - 1)->set)
+                       {
+                       X509V3err(X509V3_F_SET_DIST_POINT_NAME,
+                                               X509V3_R_INVALID_MULTIPLE_RDNS);
+                       goto err;
+                       }
+               }
+       else
+               return 0;
+
+       if (*pdp)
+               {
+               X509V3err(X509V3_F_SET_DIST_POINT_NAME,
+                                               X509V3_R_DISTPOINT_ALREADY_SET);
+               goto err;
+               }
+
+       *pdp = DIST_POINT_NAME_new();
+       if (!*pdp)
+               goto err;
+       if (fnm)
+               {
+               (*pdp)->type = 0;
+               (*pdp)->name.fullname = fnm;
+               }
+       else
+               {
+               (*pdp)->type = 1;
+               (*pdp)->name.relativename = rnm;
+               }
+
+       return 1;
+               
+       err:
+       if (fnm)
+               sk_GENERAL_NAME_pop_free(fnm, GENERAL_NAME_free);
+       if (rnm)
+               sk_X509_NAME_ENTRY_pop_free(rnm, X509_NAME_ENTRY_free);
+       return -1;
+       }
+
+static const BIT_STRING_BITNAME reason_flags[] = {
+{0, "Unused", "unused"},
+{1, "Key Compromise", "keyCompromise"},
+{2, "CA Compromise", "CACompromise"},
+{3, "Affiliation Changed", "affiliationChanged"},
+{4, "Superseded", "superseded"},
+{5, "Cessation Of Operation", "cessationOfOperation"},
+{6, "Certificate Hold", "certificateHold"},
+{7, "Privilege Withdrawn", "privilegeWithdrawn"},
+{8, "AA Compromise", "AACompromise"},
+{-1, NULL, NULL}
 };
 
-static STACK_OF(CONF_VALUE) *i2v_crld(X509V3_EXT_METHOD *method,
-                       STACK_OF(DIST_POINT) *crld, STACK_OF(CONF_VALUE) *exts)
-{
-       DIST_POINT *point;
+static int set_reasons(ASN1_BIT_STRING **preas, char *value)
+       {
+       STACK_OF(CONF_VALUE) *rsk = NULL;
+       const BIT_STRING_BITNAME *pbn;
+       const char *bnam;
+       int i, ret = 0;
+       rsk = X509V3_parse_list(value);
+       if (!rsk)
+               return 0;
+       if (*preas)
+               return 0;
+       for (i = 0; i < sk_CONF_VALUE_num(rsk); i++)
+               {
+               bnam = sk_CONF_VALUE_value(rsk, i)->name;
+               if (!*preas)
+                       {
+                       *preas = ASN1_BIT_STRING_new();
+                       if (!*preas)
+                               goto err;
+                       }
+               for (pbn = reason_flags; pbn->lname; pbn++)
+                       {
+                       if (!strcmp(pbn->sname, bnam))
+                               {
+                               if (!ASN1_BIT_STRING_set_bit(*preas,
+                                                       pbn->bitnum, 1))
+                                       goto err;
+                               break;
+                               }
+                       }
+               if (!pbn->lname)
+                       goto err;
+               }
+       ret = 1;
+
+       err:
+       sk_CONF_VALUE_pop_free(rsk, X509V3_conf_free);
+       return ret;
+       }
+
+static int print_reasons(BIO *out, const char *rname,
+                       ASN1_BIT_STRING *rflags, int indent)
+       {
+       int first = 1;
+       const BIT_STRING_BITNAME *pbn;
+       BIO_printf(out, "%*s%s:\n%*s", indent, "", rname, indent + 2, "");
+       for (pbn = reason_flags; pbn->lname; pbn++)
+               {
+               if (ASN1_BIT_STRING_get_bit(rflags, pbn->bitnum))
+                       {
+                       if (first)
+                               first = 0;
+                       else
+                               BIO_puts(out, ", ");
+                       BIO_puts(out, pbn->lname);
+                       }
+               }
+       if (first)
+               BIO_puts(out, "<EMPTY>\n");
+       else
+               BIO_puts(out, "\n");
+       return 1;
+       }
+
+static DIST_POINT *crldp_from_section(X509V3_CTX *ctx,
+                                               STACK_OF(CONF_VALUE) *nval)
+       {
        int i;
-       for(i = 0; i < sk_DIST_POINT_num(crld); i++) {
-               point = sk_DIST_POINT_value(crld, i);
-               if(point->distpoint) {
-                       if(point->distpoint->type == 0)
-                               exts = i2v_GENERAL_NAMES(NULL,
-                                        point->distpoint->name.fullname, exts);
-                       else X509V3_add_value("RelativeName","<UNSUPPORTED>", &exts);
+       CONF_VALUE *cnf;
+       DIST_POINT *point = NULL;
+       point = DIST_POINT_new();
+       if (!point)
+               goto err;
+       for(i = 0; i < sk_CONF_VALUE_num(nval); i++)
+               {
+               int ret;
+               cnf = sk_CONF_VALUE_value(nval, i);
+               ret = set_dist_point_name(&point->distpoint, ctx, cnf);
+               if (ret > 0)
+                       continue;
+               if (ret < 0)
+                       goto err;
+               if (!strcmp(cnf->name, "reasons"))
+                       {
+                       if (!set_reasons(&point->reasons, cnf->value))
+                               goto err;
+                       }
+               else if (!strcmp(cnf->name, "CRLissuer"))
+                       {
+                       point->CRLissuer =
+                               gnames_from_sectname(ctx, cnf->value);
+                       if (!point->CRLissuer)
+                               goto err;
+                       }
                }
-               if(point->reasons) 
-                       X509V3_add_value("reasons","<UNSUPPORTED>", &exts);
-               if(point->CRLissuer)
-                       X509V3_add_value("CRLissuer","<UNSUPPORTED>", &exts);
+
+       return point;
+                       
+
+       err:
+       if (point)
+               DIST_POINT_free(point);
+       return NULL;
        }
-       return exts;
-}
 
-static STACK_OF(DIST_POINT) *v2i_crld(X509V3_EXT_METHOD *method,
-                               X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
-{
+static void *v2i_crld(const X509V3_EXT_METHOD *method,
+                     X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
+       {
        STACK_OF(DIST_POINT) *crld = NULL;
        GENERAL_NAMES *gens = NULL;
        GENERAL_NAME *gen = NULL;
@@ -111,19 +320,44 @@ static STACK_OF(DIST_POINT) *v2i_crld(X509V3_EXT_METHOD *method,
        for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
                DIST_POINT *point;
                cnf = sk_CONF_VALUE_value(nval, i);
-               if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) goto err; 
-               if(!(gens = GENERAL_NAMES_new())) goto merr;
-               if(!sk_GENERAL_NAME_push(gens, gen)) goto merr;
-               gen = NULL;
-               if(!(point = DIST_POINT_new())) goto merr;
-               if(!sk_DIST_POINT_push(crld, point)) {
-                       DIST_POINT_free(point);
-                       goto merr;
-               }
-               if(!(point->distpoint = DIST_POINT_NAME_new())) goto merr;
-               point->distpoint->name.fullname = gens;
-               point->distpoint->type = 0;
-               gens = NULL;
+               if (!cnf->value)
+                       {
+                       STACK_OF(CONF_VALUE) *dpsect;
+                       dpsect = X509V3_get_section(ctx, cnf->name);
+                       if (!dpsect)
+                               goto err;
+                       point = crldp_from_section(ctx, dpsect);
+                       X509V3_section_free(ctx, dpsect);
+                       if (!point)
+                               goto err;
+                       if(!sk_DIST_POINT_push(crld, point))
+                               {
+                               DIST_POINT_free(point);
+                               goto merr;
+                               }
+                       }
+               else
+                       {
+                       if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf)))
+                               goto err; 
+                       if(!(gens = GENERAL_NAMES_new()))
+                               goto merr;
+                       if(!sk_GENERAL_NAME_push(gens, gen))
+                               goto merr;
+                       gen = NULL;
+                       if(!(point = DIST_POINT_new()))
+                               goto merr;
+                       if(!sk_DIST_POINT_push(crld, point))
+                               {
+                               DIST_POINT_free(point);
+                               goto merr;
+                               }
+                       if(!(point->distpoint = DIST_POINT_NAME_new()))
+                               goto merr;
+                       point->distpoint->name.fullname = gens;
+                       point->distpoint->type = 0;
+                       gens = NULL;
+                       }
        }
        return crld;
 
@@ -139,11 +373,31 @@ static STACK_OF(DIST_POINT) *v2i_crld(X509V3_EXT_METHOD *method,
 IMPLEMENT_STACK_OF(DIST_POINT)
 IMPLEMENT_ASN1_SET_OF(DIST_POINT)
 
+static int dpn_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
+                                                               void *exarg)
+       {
+       DIST_POINT_NAME *dpn = (DIST_POINT_NAME *)*pval;
+
+       switch(operation)
+               {
+               case ASN1_OP_NEW_POST:
+               dpn->dpname = NULL;
+               break;
+
+               case ASN1_OP_FREE_POST:
+               if (dpn->dpname)
+                       X509_NAME_free(dpn->dpname);
+               break;
+               }
+       return 1;
+       }
+
 
-ASN1_CHOICE(DIST_POINT_NAME) = {
+ASN1_CHOICE_cb(DIST_POINT_NAME, dpn_cb) = {
        ASN1_IMP_SEQUENCE_OF(DIST_POINT_NAME, name.fullname, GENERAL_NAME, 0),
        ASN1_IMP_SET_OF(DIST_POINT_NAME, name.relativename, X509_NAME_ENTRY, 1)
-} ASN1_CHOICE_END(DIST_POINT_NAME)
+} ASN1_CHOICE_END_cb(DIST_POINT_NAME, DIST_POINT_NAME, type)
+
 
 IMPLEMENT_ASN1_FUNCTIONS(DIST_POINT_NAME)
 
@@ -160,3 +414,203 @@ ASN1_ITEM_TEMPLATE(CRL_DIST_POINTS) =
 ASN1_ITEM_TEMPLATE_END(CRL_DIST_POINTS)
 
 IMPLEMENT_ASN1_FUNCTIONS(CRL_DIST_POINTS)
+
+ASN1_SEQUENCE(ISSUING_DIST_POINT) = {
+       ASN1_EXP_OPT(ISSUING_DIST_POINT, distpoint, DIST_POINT_NAME, 0),
+       ASN1_IMP_OPT(ISSUING_DIST_POINT, onlyuser, ASN1_FBOOLEAN, 1),
+       ASN1_IMP_OPT(ISSUING_DIST_POINT, onlyCA, ASN1_FBOOLEAN, 2),
+       ASN1_IMP_OPT(ISSUING_DIST_POINT, onlysomereasons, ASN1_BIT_STRING, 3),
+       ASN1_IMP_OPT(ISSUING_DIST_POINT, indirectCRL, ASN1_FBOOLEAN, 4),
+       ASN1_IMP_OPT(ISSUING_DIST_POINT, onlyattr, ASN1_FBOOLEAN, 5)
+} ASN1_SEQUENCE_END(ISSUING_DIST_POINT)
+
+IMPLEMENT_ASN1_FUNCTIONS(ISSUING_DIST_POINT)
+
+static int i2r_idp(const X509V3_EXT_METHOD *method, void *pidp, BIO *out,
+                  int indent);
+static void *v2i_idp(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
+                    STACK_OF(CONF_VALUE) *nval);
+
+const X509V3_EXT_METHOD v3_idp =
+       {
+       NID_issuing_distribution_point, X509V3_EXT_MULTILINE,
+       ASN1_ITEM_ref(ISSUING_DIST_POINT),
+       0,0,0,0,
+       0,0,
+       0,
+       v2i_idp,
+       i2r_idp,0,
+       NULL
+       };
+
+static void *v2i_idp(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
+                    STACK_OF(CONF_VALUE) *nval)
+       {
+       ISSUING_DIST_POINT *idp = NULL;
+       CONF_VALUE *cnf;
+       char *name, *val;
+       int i, ret;
+       idp = ISSUING_DIST_POINT_new();
+       if (!idp)
+               goto merr;
+       for(i = 0; i < sk_CONF_VALUE_num(nval); i++)
+               {
+               cnf = sk_CONF_VALUE_value(nval, i);
+               name = cnf->name;
+               val = cnf->value;
+               ret = set_dist_point_name(&idp->distpoint, ctx, cnf);
+               if (ret > 0)
+                       continue;
+               if (ret < 0)
+                       goto err;
+               if (!strcmp(name, "onlyuser"))
+                       {
+                       if (!X509V3_get_value_bool(cnf, &idp->onlyuser))
+                               goto err;
+                       }
+               else if (!strcmp(name, "onlyCA"))
+                       {
+                       if (!X509V3_get_value_bool(cnf, &idp->onlyCA))
+                               goto err;
+                       }
+               else if (!strcmp(name, "onlyAA"))
+                       {
+                       if (!X509V3_get_value_bool(cnf, &idp->onlyattr))
+                               goto err;
+                       }
+               else if (!strcmp(name, "indirectCRL"))
+                       {
+                       if (!X509V3_get_value_bool(cnf, &idp->indirectCRL))
+                               goto err;
+                       }
+               else if (!strcmp(name, "onlysomereasons"))
+                       {
+                       if (!set_reasons(&idp->onlysomereasons, val))
+                               goto err;
+                       }
+               else
+                       {
+                        X509V3err(X509V3_F_V2I_IDP, X509V3_R_INVALID_NAME);
+                        X509V3_conf_err(cnf);
+                        goto err;
+                       }
+               }
+       return idp;
+
+       merr:
+       X509V3err(X509V3_F_V2I_IDP,ERR_R_MALLOC_FAILURE);
+       err:
+       ISSUING_DIST_POINT_free(idp);
+       return NULL;
+       }
+
+static int print_gens(BIO *out, STACK_OF(GENERAL_NAME) *gens, int indent)
+       {
+       int i;
+       for (i = 0; i < sk_GENERAL_NAME_num(gens); i++)
+               {
+               BIO_printf(out, "%*s", indent + 2, "");
+               GENERAL_NAME_print(out, sk_GENERAL_NAME_value(gens, i));
+               BIO_puts(out, "\n");
+               }
+       return 1;
+       }
+
+static int print_distpoint(BIO *out, DIST_POINT_NAME *dpn, int indent)
+       {
+       if (dpn->type == 0)
+               {
+               BIO_printf(out, "%*sFull Name:\n", indent, "");
+               print_gens(out, dpn->name.fullname, indent);
+               }
+       else
+               {
+               X509_NAME ntmp;
+               ntmp.entries = dpn->name.relativename;
+               BIO_printf(out, "%*sRelative Name:\n%*s",
+                                               indent, "", indent + 2, "");
+               X509_NAME_print_ex(out, &ntmp, 0, XN_FLAG_ONELINE);
+               BIO_puts(out, "\n");
+               }
+       return 1;
+       }
+
+static int i2r_idp(const X509V3_EXT_METHOD *method, void *pidp, BIO *out,
+                  int indent)
+       {
+       ISSUING_DIST_POINT *idp = pidp;
+       if (idp->distpoint)
+               print_distpoint(out, idp->distpoint, indent);
+       if (idp->onlyuser > 0)
+               BIO_printf(out, "%*sOnly User Certificates\n", indent, "");
+       if (idp->onlyCA > 0)
+               BIO_printf(out, "%*sOnly CA Certificates\n", indent, "");
+       if (idp->indirectCRL > 0)
+               BIO_printf(out, "%*sIndirect CRL\n", indent, "");
+       if (idp->onlysomereasons)
+               print_reasons(out, "Only Some Reasons", 
+                               idp->onlysomereasons, indent);
+       if (idp->onlyattr > 0)
+               BIO_printf(out, "%*sOnly Attribute Certificates\n", indent, "");
+       if (!idp->distpoint && (idp->onlyuser <= 0) && (idp->onlyCA <= 0)
+               && (idp->indirectCRL <= 0) && !idp->onlysomereasons
+               && (idp->onlyattr <= 0))
+               BIO_printf(out, "%*s<EMPTY>\n", indent, "");
+               
+       return 1;
+       }
+
+static int i2r_crldp(const X509V3_EXT_METHOD *method, void *pcrldp, BIO *out,
+                    int indent)
+       {
+       STACK_OF(DIST_POINT) *crld = pcrldp;
+       DIST_POINT *point;
+       int i;
+       for(i = 0; i < sk_DIST_POINT_num(crld); i++)
+               {
+               BIO_puts(out, "\n");
+               point = sk_DIST_POINT_value(crld, i);
+               if(point->distpoint)
+                       print_distpoint(out, point->distpoint, indent);
+               if(point->reasons) 
+                       print_reasons(out, "Reasons", point->reasons,
+                                                               indent);
+               if(point->CRLissuer)
+                       {
+                       BIO_printf(out, "%*sCRL Issuer:\n", indent, "");
+                       print_gens(out, point->CRLissuer, indent);
+                       }
+               }
+       return 1;
+       }
+
+int DIST_POINT_set_dpname(DIST_POINT_NAME *dpn, X509_NAME *iname)
+       {
+       int i;
+       STACK_OF(X509_NAME_ENTRY) *frag;
+       X509_NAME_ENTRY *ne;
+       if (!dpn || (dpn->type != 1))
+               return 1;
+       frag = dpn->name.relativename;
+       dpn->dpname = X509_NAME_dup(iname);
+       if (!dpn->dpname)
+               return 0;
+       for (i = 0; i < sk_X509_NAME_ENTRY_num(frag); i++)
+               {
+               ne = sk_X509_NAME_ENTRY_value(frag, i);
+               if (!X509_NAME_add_entry(dpn->dpname, ne, -1, i ? 0 : 1))
+                       {
+                       X509_NAME_free(dpn->dpname);
+                       dpn->dpname = NULL;
+                       return 0;
+                       }
+               }
+       /* generate cached encoding of name */
+       if (i2d_X509_NAME(dpn->dpname, NULL) < 0)
+               {
+               X509_NAME_free(dpn->dpname);
+               dpn->dpname = NULL;
+               return 0;
+               }
+       return 1;
+       }
index 36576ea..c0575e3 100644 (file)
 #include <openssl/x509v3.h>
 
 static ENUMERATED_NAMES crl_reasons[] = {
-{0, "Unspecified", "unspecified"},
-{1, "Key Compromise", "keyCompromise"},
-{2, "CA Compromise", "CACompromise"},
-{3, "Affiliation Changed", "affiliationChanged"},
-{4, "Superseded", "superseded"},
-{5, "Cessation Of Operation", "cessationOfOperation"},
-{6, "Certificate Hold", "certificateHold"},
-{8, "Remove From CRL", "removeFromCRL"},
+{CRL_REASON_UNSPECIFIED,        "Unspecified", "unspecified"},
+{CRL_REASON_KEY_COMPROMISE,     "Key Compromise", "keyCompromise"},
+{CRL_REASON_CA_COMPROMISE,      "CA Compromise", "CACompromise"},
+{CRL_REASON_AFFILIATION_CHANGED, "Affiliation Changed", "affiliationChanged"},
+{CRL_REASON_SUPERSEDED,         "Superseded", "superseded"},
+{CRL_REASON_CESSATION_OF_OPERATION,
+                       "Cessation Of Operation", "cessationOfOperation"},
+{CRL_REASON_CERTIFICATE_HOLD,   "Certificate Hold", "certificateHold"},
+{CRL_REASON_REMOVE_FROM_CRL,    "Remove From CRL", "removeFromCRL"},
+{CRL_REASON_PRIVILEGE_WITHDRAWN, "Privilege Withdrawn", "privilegeWithdrawn"},
+{CRL_REASON_AA_COMPROMISE,      "AA Compromise", "AACompromise"},
 {-1, NULL, NULL}
 };
 
index c0d1450..1c66532 100644 (file)
 #include <openssl/conf.h>
 #include <openssl/x509v3.h>
 
-static void *v2i_EXTENDED_KEY_USAGE(X509V3_EXT_METHOD *method,
-                               X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
-static STACK_OF(CONF_VALUE) *i2v_EXTENDED_KEY_USAGE(X509V3_EXT_METHOD *method,
+static void *v2i_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method,
+                                   X509V3_CTX *ctx,
+                                   STACK_OF(CONF_VALUE) *nval);
+static STACK_OF(CONF_VALUE) *i2v_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method,
                void *eku, STACK_OF(CONF_VALUE) *extlist);
 
 const X509V3_EXT_METHOD v3_ext_ku = {
@@ -97,8 +98,9 @@ ASN1_ITEM_TEMPLATE_END(EXTENDED_KEY_USAGE)
 
 IMPLEMENT_ASN1_FUNCTIONS(EXTENDED_KEY_USAGE)
 
-static STACK_OF(CONF_VALUE) *i2v_EXTENDED_KEY_USAGE(X509V3_EXT_METHOD *method,
-               void *a, STACK_OF(CONF_VALUE) *ext_list)
+static STACK_OF(CONF_VALUE) *
+  i2v_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method, void *a,
+                        STACK_OF(CONF_VALUE) *ext_list)
 {
        EXTENDED_KEY_USAGE *eku = a;
        int i;
@@ -112,8 +114,8 @@ static STACK_OF(CONF_VALUE) *i2v_EXTENDED_KEY_USAGE(X509V3_EXT_METHOD *method,
        return ext_list;
 }
 
-static void *v2i_EXTENDED_KEY_USAGE(X509V3_EXT_METHOD *method,
-                               X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
+static void *v2i_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method,
+                                   X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
 {
        EXTENDED_KEY_USAGE *extku;
        char *extval;
index 84b4b1c..b628357 100644 (file)
@@ -3,7 +3,7 @@
  * project 1999.
  */
 /* ====================================================================
- * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2008 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -99,3 +99,154 @@ ASN1_ITEM_TEMPLATE(GENERAL_NAMES) =
 ASN1_ITEM_TEMPLATE_END(GENERAL_NAMES)
 
 IMPLEMENT_ASN1_FUNCTIONS(GENERAL_NAMES)
+
+GENERAL_NAME *GENERAL_NAME_dup(GENERAL_NAME *a)
+       {
+       return (GENERAL_NAME *) ASN1_dup((i2d_of_void *) i2d_GENERAL_NAME,
+                                        (d2i_of_void *) d2i_GENERAL_NAME,
+                                        (char *) a);
+       }
+
+/* Returns 0 if they are equal, != 0 otherwise. */
+int GENERAL_NAME_cmp(GENERAL_NAME *a, GENERAL_NAME *b)
+       {
+       int result = -1;
+
+       if (!a || !b || a->type != b->type) return -1;
+       switch(a->type)
+               {
+       case GEN_X400:
+       case GEN_EDIPARTY:
+               result = ASN1_TYPE_cmp(a->d.other, b->d.other);
+               break;
+
+       case GEN_OTHERNAME:
+               result = OTHERNAME_cmp(a->d.otherName, b->d.otherName);
+               break;
+
+       case GEN_EMAIL:
+       case GEN_DNS:
+       case GEN_URI:
+               result = ASN1_STRING_cmp(a->d.ia5, b->d.ia5);
+               break;
+
+       case GEN_DIRNAME:
+               result = X509_NAME_cmp(a->d.dirn, b->d.dirn);
+               break;
+
+       case GEN_IPADD:
+               result = ASN1_OCTET_STRING_cmp(a->d.ip, b->d.ip);
+               break;
+       
+       case GEN_RID:
+               result = OBJ_cmp(a->d.rid, b->d.rid);
+               break;
+               }
+       return result;
+       }
+
+/* Returns 0 if they are equal, != 0 otherwise. */
+int OTHERNAME_cmp(OTHERNAME *a, OTHERNAME *b)
+       {
+       int result = -1;
+
+       if (!a || !b) return -1;
+       /* Check their type first. */
+       if ((result = OBJ_cmp(a->type_id, b->type_id)) != 0)
+               return result;
+       /* Check the value. */
+       result = ASN1_TYPE_cmp(a->value, b->value);
+       return result;
+       }
+
+void GENERAL_NAME_set0_value(GENERAL_NAME *a, int type, void *value)
+       {
+       switch(type)
+               {
+       case GEN_X400:
+       case GEN_EDIPARTY:
+               a->d.other = value;
+               break;
+
+       case GEN_OTHERNAME:
+               a->d.otherName = value;
+               break;
+
+       case GEN_EMAIL:
+       case GEN_DNS:
+       case GEN_URI:
+               a->d.ia5 = value;
+               break;
+
+       case GEN_DIRNAME:
+               a->d.dirn = value;
+               break;
+
+       case GEN_IPADD:
+               a->d.ip = value;
+               break;
+       
+       case GEN_RID:
+               a->d.rid = value;
+               break;
+               }
+       a->type = type;
+       }
+
+void *GENERAL_NAME_get0_value(GENERAL_NAME *a, int *ptype)
+       {
+       if (ptype)
+               *ptype = a->type;
+       switch(a->type)
+               {
+       case GEN_X400:
+       case GEN_EDIPARTY:
+               return a->d.other;
+
+       case GEN_OTHERNAME:
+               return a->d.otherName;
+
+       case GEN_EMAIL:
+       case GEN_DNS:
+       case GEN_URI:
+               return a->d.ia5;
+
+       case GEN_DIRNAME:
+               return a->d.dirn;
+
+       case GEN_IPADD:
+               return a->d.ip;
+       
+       case GEN_RID:
+               return a->d.rid;
+
+       default:
+               return NULL;
+               }
+       }
+
+int GENERAL_NAME_set0_othername(GENERAL_NAME *gen,
+                               ASN1_OBJECT *oid, ASN1_TYPE *value)
+       {
+       OTHERNAME *oth;
+       oth = OTHERNAME_new();
+       if (!oth)
+               return 0;
+       oth->type_id = oid;
+       oth->value = value;
+       GENERAL_NAME_set0_value(gen, GEN_OTHERNAME, oth);
+       return 1;
+       }
+
+int GENERAL_NAME_get0_otherName(GENERAL_NAME *gen, 
+                               ASN1_OBJECT **poid, ASN1_TYPE **pvalue)
+       {
+       if (gen->type != GEN_OTHERNAME)
+               return 0;
+       if (poid)
+               *poid = gen->d.otherName->type_id;
+       if (pvalue)
+               *pvalue = gen->d.otherName->value;
+       return 1;
+       }
+
index df3a48f..0f1e1d4 100644 (file)
@@ -84,20 +84,24 @@ int X509V3_EXT_add(X509V3_EXT_METHOD *ext)
 }
 
 static int ext_cmp(const X509V3_EXT_METHOD * const *a,
-               const X509V3_EXT_METHOD * const *b)
+                  const X509V3_EXT_METHOD * const *b)
 {
        return ((*a)->ext_nid - (*b)->ext_nid);
 }
 
-X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid)
+DECLARE_OBJ_BSEARCH_CMP_FN(const X509V3_EXT_METHOD *, const X509V3_EXT_METHOD *,
+                          ext);
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(const X509V3_EXT_METHOD *,
+                            const X509V3_EXT_METHOD *, ext);
+
+const X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid)
 {
-       X509V3_EXT_METHOD tmp, *t = &tmp, **ret;
+       X509V3_EXT_METHOD tmp;
+       const X509V3_EXT_METHOD *t = &tmp, * const *ret;
        int idx;
        if(nid < 0) return NULL;
        tmp.ext_nid = nid;
-       ret = (X509V3_EXT_METHOD **) OBJ_bsearch((char *)&t,
-                       (char *)standard_exts, STANDARD_EXTENSION_COUNT,
-                       sizeof(X509V3_EXT_METHOD *), (int (*)(const void *, const void *))ext_cmp);
+       ret = OBJ_bsearch_ext(&t, standard_exts, STANDARD_EXTENSION_COUNT);
        if(ret) return *ret;
        if(!ext_list) return NULL;
        idx = sk_X509V3_EXT_METHOD_find(ext_list, &tmp);
@@ -105,7 +109,7 @@ X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid)
        return sk_X509V3_EXT_METHOD_value(ext_list, idx);
 }
 
-X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext)
+const X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext)
 {
        int nid;
        if((nid = OBJ_obj2nid(ext->object)) == NID_undef) return NULL;
@@ -122,7 +126,9 @@ int X509V3_EXT_add_list(X509V3_EXT_METHOD *extlist)
 
 int X509V3_EXT_add_alias(int nid_to, int nid_from)
 {
-       X509V3_EXT_METHOD *ext, *tmpext;
+       const X509V3_EXT_METHOD *ext;
+       X509V3_EXT_METHOD *tmpext;
+
        if(!(ext = X509V3_EXT_get_nid(nid_from))) {
                X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS,X509V3_R_EXTENSION_NOT_FOUND);
                return 0;
@@ -161,7 +167,7 @@ int X509V3_add_standard_extensions(void)
 
 void *X509V3_EXT_d2i(X509_EXTENSION *ext)
 {
-       X509V3_EXT_METHOD *method;
+       const X509V3_EXT_METHOD *method;
        const unsigned char *p;
 
        if(!(method = X509V3_EXT_get(ext))) return NULL;
index 624fe7e..a01dc64 100644 (file)
 #include <openssl/conf.h>
 #include <openssl/x509v3.h>
 
-static void *v2i_NAME_CONSTRAINTS(X509V3_EXT_METHOD *method,
-                               X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
-static int i2r_NAME_CONSTRAINTS(X509V3_EXT_METHOD *method, 
+static void *v2i_NAME_CONSTRAINTS(const X509V3_EXT_METHOD *method,
+                                 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
+static int i2r_NAME_CONSTRAINTS(const X509V3_EXT_METHOD *method, 
                                void *a, BIO *bp, int ind);
-static int do_i2r_name_constraints(X509V3_EXT_METHOD *method,
-                               STACK_OF(GENERAL_SUBTREE) *trees,
-                                       BIO *bp, int ind, char *name);
+static int do_i2r_name_constraints(const X509V3_EXT_METHOD *method,
+                                  STACK_OF(GENERAL_SUBTREE) *trees,
+                                  BIO *bp, int ind, char *name);
 static int print_nc_ipadd(BIO *bp, ASN1_OCTET_STRING *ip);
 
+static int nc_match(GENERAL_NAME *gen, NAME_CONSTRAINTS *nc);
+static int nc_match_single(GENERAL_NAME *sub, GENERAL_NAME *gen);
+static int nc_dn(X509_NAME *sub, X509_NAME *nm);
+static int nc_dns(ASN1_IA5STRING *sub, ASN1_IA5STRING *dns);
+static int nc_email(ASN1_IA5STRING *sub, ASN1_IA5STRING *eml);
+static int nc_uri(ASN1_IA5STRING *uri, ASN1_IA5STRING *base);
+
 const X509V3_EXT_METHOD v3_name_constraints = {
        NID_name_constraints, 0,
        ASN1_ITEM_ref(NAME_CONSTRAINTS),
@@ -99,8 +106,8 @@ ASN1_SEQUENCE(NAME_CONSTRAINTS) = {
 IMPLEMENT_ASN1_ALLOC_FUNCTIONS(GENERAL_SUBTREE)
 IMPLEMENT_ASN1_ALLOC_FUNCTIONS(NAME_CONSTRAINTS)
 
-static void *v2i_NAME_CONSTRAINTS(X509V3_EXT_METHOD *method,
-                               X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
+static void *v2i_NAME_CONSTRAINTS(const X509V3_EXT_METHOD *method,
+                                 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
        {
        int i;
        CONF_VALUE tval, *val;
@@ -155,8 +162,8 @@ static void *v2i_NAME_CONSTRAINTS(X509V3_EXT_METHOD *method,
 
        
 
-static int i2r_NAME_CONSTRAINTS(X509V3_EXT_METHOD *method,
-                               void *a, BIO *bp, int ind)
+static int i2r_NAME_CONSTRAINTS(const X509V3_EXT_METHOD *method, void *a,
+                               BIO *bp, int ind)
        {
        NAME_CONSTRAINTS *ncons = a;
        do_i2r_name_constraints(method, ncons->permittedSubtrees,
@@ -166,9 +173,9 @@ static int i2r_NAME_CONSTRAINTS(X509V3_EXT_METHOD *method,
        return 1;
        }
 
-static int do_i2r_name_constraints(X509V3_EXT_METHOD *method,
-                               STACK_OF(GENERAL_SUBTREE) *trees,
-                                       BIO *bp, int ind, char *name)
+static int do_i2r_name_constraints(const X509V3_EXT_METHOD *method,
+                                  STACK_OF(GENERAL_SUBTREE) *trees,
+                                  BIO *bp, int ind, char *name)
        {
        GENERAL_SUBTREE *tree;
        int i;
@@ -217,3 +224,282 @@ static int print_nc_ipadd(BIO *bp, ASN1_OCTET_STRING *ip)
        return 1;
        }
 
+/* Check a certificate conforms to a specified set of constraints.
+ * Return values:
+ *  X509_V_OK: All constraints obeyed.
+ *  X509_V_ERR_PERMITTED_VIOLATION: Permitted subtree violation.
+ *  X509_V_ERR_EXCLUDED_VIOLATION: Excluded subtree violation.
+ *  X509_V_ERR_SUBTREE_MINMAX: Min or max values present and matching type.
+ *  X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE:  Unsupported constraint type.
+ *  X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX: bad unsupported constraint syntax.
+ *  X509_V_ERR_UNSUPPORTED_NAME_SYNTAX: bad or unsupported syntax of name
+
+ */
+
+int NAME_CONSTRAINTS_check(X509 *x, NAME_CONSTRAINTS *nc)
+       {
+       int r, i;
+       X509_NAME *nm;
+
+       nm = X509_get_subject_name(x);
+
+       if (X509_NAME_entry_count(nm) > 0)
+               {
+               GENERAL_NAME gntmp;
+               gntmp.type = GEN_DIRNAME;
+               gntmp.d.directoryName = nm;
+
+               r = nc_match(&gntmp, nc);
+
+               if (r != X509_V_OK)
+                       return r;
+
+               gntmp.type = GEN_EMAIL;
+
+
+               /* Process any email address attributes in subject name */
+
+               for (i = -1;;)
+                       {
+                       X509_NAME_ENTRY *ne;
+                       i = X509_NAME_get_index_by_NID(nm,
+                                                      NID_pkcs9_emailAddress,
+                                                      i);
+                       if (i == -1)
+                               break;
+                       ne = X509_NAME_get_entry(nm, i);
+                       gntmp.d.rfc822Name = X509_NAME_ENTRY_get_data(ne);
+                       if (gntmp.d.rfc822Name->type != V_ASN1_IA5STRING)
+                               return X509_V_ERR_UNSUPPORTED_NAME_SYNTAX;
+
+                       r = nc_match(&gntmp, nc);
+
+                       if (r != X509_V_OK)
+                               return r;
+                       }
+               
+               }
+
+       for (i = 0; i < sk_GENERAL_NAME_num(x->altname); i++)
+               {
+               GENERAL_NAME *gen = sk_GENERAL_NAME_value(x->altname, i);
+               r = nc_match(gen, nc);
+               if (r != X509_V_OK)
+                       return r;
+               }
+
+       return X509_V_OK;
+
+       }
+
+static int nc_match(GENERAL_NAME *gen, NAME_CONSTRAINTS *nc)
+       {
+       GENERAL_SUBTREE *sub;
+       int i, r, match = 0;
+
+       /* Permitted subtrees: if any subtrees exist of matching the type
+        * at least one subtree must match.
+        */
+
+       for (i = 0; i < sk_GENERAL_SUBTREE_num(nc->permittedSubtrees); i++)
+               {
+               sub = sk_GENERAL_SUBTREE_value(nc->permittedSubtrees, i);
+               if (gen->type != sub->base->type)
+                       continue;
+               if (sub->minimum || sub->maximum)
+                       return X509_V_ERR_SUBTREE_MINMAX;
+               /* If we already have a match don't bother trying any more */
+               if (match == 2)
+                       continue;
+               if (match == 0)
+                       match = 1;
+               r = nc_match_single(gen, sub->base);
+               if (r == X509_V_OK)
+                       match = 2;
+               else if (r != X509_V_ERR_PERMITTED_VIOLATION)
+                       return r;
+               }
+
+       if (match == 1)
+               return X509_V_ERR_PERMITTED_VIOLATION;
+
+       /* Excluded subtrees: must not match any of these */
+
+       for (i = 0; i < sk_GENERAL_SUBTREE_num(nc->excludedSubtrees); i++)
+               {
+               sub = sk_GENERAL_SUBTREE_value(nc->excludedSubtrees, i);
+               if (gen->type != sub->base->type)
+                       continue;
+               if (sub->minimum || sub->maximum)
+                       return X509_V_ERR_SUBTREE_MINMAX;
+
+               r = nc_match_single(gen, sub->base);
+               if (r == X509_V_OK)
+                       return X509_V_ERR_EXCLUDED_VIOLATION;
+               else if (r != X509_V_ERR_PERMITTED_VIOLATION)
+                       return r;
+
+               }
+
+       return X509_V_OK;
+
+       }
+
+static int nc_match_single(GENERAL_NAME *gen, GENERAL_NAME *base)
+       {
+       switch(base->type)
+               {
+               case GEN_DIRNAME:
+               return nc_dn(gen->d.directoryName, base->d.directoryName);
+
+               case GEN_DNS:
+               return nc_dns(gen->d.dNSName, base->d.dNSName);
+
+               case GEN_EMAIL:
+               return nc_email(gen->d.rfc822Name, base->d.rfc822Name);
+
+               case GEN_URI:
+               return nc_uri(gen->d.uniformResourceIdentifier,
+                                       base->d.uniformResourceIdentifier);
+
+               default:
+               return X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE;
+               }
+
+       }
+
+/* directoryName name constraint matching.
+ * The canonical encoding of X509_NAME makes this comparison easy. It is
+ * matched if the subtree is a subset of the name.
+ */
+
+static int nc_dn(X509_NAME *nm, X509_NAME *base)
+       {
+       /* Ensure canonical encodings are up to date.  */
+       if (nm->modified && i2d_X509_NAME(nm, NULL) < 0)
+               return X509_V_ERR_OUT_OF_MEM;
+       if (base->modified && i2d_X509_NAME(base, NULL) < 0)
+               return X509_V_ERR_OUT_OF_MEM;
+       if (base->canon_enclen > nm->canon_enclen)
+               return X509_V_ERR_PERMITTED_VIOLATION;
+       if (memcmp(base->canon_enc, nm->canon_enc, base->canon_enclen))
+               return X509_V_ERR_PERMITTED_VIOLATION;
+       return X509_V_OK;
+       }
+
+static int nc_dns(ASN1_IA5STRING *dns, ASN1_IA5STRING *base)
+       {
+       char *baseptr = (char *)base->data;
+       char *dnsptr = (char *)dns->data;
+       /* Empty matches everything */
+       if (!*baseptr)
+               return X509_V_OK;
+       /* Otherwise can add zero or more components on the left so
+        * compare RHS and if dns is longer and expect '.' as preceding
+        * character.
+        */
+       if (dns->length > base->length)
+               {
+               dnsptr += dns->length - base->length;
+               if (dnsptr[-1] != '.')
+                       return X509_V_ERR_PERMITTED_VIOLATION;
+               }
+
+       if (strcasecmp(baseptr, dnsptr))
+                       return X509_V_ERR_PERMITTED_VIOLATION;
+
+       return X509_V_OK;
+
+       }
+
+static int nc_email(ASN1_IA5STRING *eml, ASN1_IA5STRING *base)
+       {
+       const char *baseptr = (char *)base->data;
+       const char *emlptr = (char *)eml->data;
+
+       const char *baseat = strchr(baseptr, '@');
+       const char *emlat = strchr(emlptr, '@');
+       if (!emlat)
+               return X509_V_ERR_UNSUPPORTED_NAME_SYNTAX;
+       /* Special case: inital '.' is RHS match */
+       if (!baseat && (*baseptr == '.'))
+               {
+               if (eml->length > base->length)
+                       {
+                       emlptr += eml->length - base->length;
+                       if (!strcasecmp(baseptr, emlptr))
+                               return X509_V_OK;
+                       }
+               return X509_V_ERR_PERMITTED_VIOLATION;
+               }
+
+       /* If we have anything before '@' match local part */
+
+       if (baseat)
+               {
+               if (baseat != baseptr)
+                       {
+                       if ((baseat - baseptr) != (emlat - emlptr))
+                               return X509_V_ERR_PERMITTED_VIOLATION;
+                       /* Case sensitive match of local part */
+                       if (strncmp(baseptr, emlptr, emlat - emlptr))
+                               return X509_V_ERR_PERMITTED_VIOLATION;
+                       }
+               /* Position base after '@' */
+               baseptr = baseat + 1;
+               }
+       emlptr = emlat + 1;
+       /* Just have hostname left to match: case insensitive */
+       if (strcasecmp(baseptr, emlptr))
+               return X509_V_ERR_PERMITTED_VIOLATION;
+
+       return X509_V_OK;
+
+       }
+
+static int nc_uri(ASN1_IA5STRING *uri, ASN1_IA5STRING *base)
+       {
+       const char *baseptr = (char *)base->data;
+       const char *hostptr = (char *)uri->data;
+       const char *p = strchr(hostptr, ':');
+       int hostlen;
+       /* Check for foo:// and skip past it */
+       if (!p || (p[1] != '/') || (p[2] != '/'))
+               return X509_V_ERR_UNSUPPORTED_NAME_SYNTAX;
+       hostptr = p + 3;
+
+       /* Determine length of hostname part of URI */
+
+       /* Look for a port indicator as end of hostname first */
+
+       p = strchr(hostptr, ':');
+       /* Otherwise look for trailing slash */
+       if (!p)
+               p = strchr(hostptr, '/');
+
+       if (!p)
+               hostlen = strlen(hostptr);
+       else
+               hostlen = p - hostptr;
+
+       if (hostlen == 0)
+               return X509_V_ERR_UNSUPPORTED_NAME_SYNTAX;
+
+       /* Special case: inital '.' is RHS match */
+       if (*baseptr == '.')
+               {
+               if (hostlen > base->length)
+                       {
+                       p = hostptr + hostlen - base->length;
+                       if (!strncasecmp(p, baseptr, base->length))
+                               return X509_V_OK;
+                       }
+               return X509_V_ERR_PERMITTED_VIOLATION;
+               }
+
+       if ((base->length != (int)hostlen) || strncasecmp(hostptr, baseptr, hostlen))
+               return X509_V_ERR_PERMITTED_VIOLATION;
+
+       return X509_V_OK;
+
+       }
index 5c19cf4..0c165af 100644 (file)
 /* OCSP extensions and a couple of CRL entry extensions
  */
 
-static int i2r_ocsp_crlid(X509V3_EXT_METHOD *method, void *nonce, BIO *out, int indent);
-static int i2r_ocsp_acutoff(X509V3_EXT_METHOD *method, void *nonce, BIO *out, int indent);
-static int i2r_object(X509V3_EXT_METHOD *method, void *obj, BIO *out, int indent);
+static int i2r_ocsp_crlid(const X509V3_EXT_METHOD *method, void *nonce,
+                         BIO *out, int indent);
+static int i2r_ocsp_acutoff(const X509V3_EXT_METHOD *method, void *nonce,
+                           BIO *out, int indent);
+static int i2r_object(const X509V3_EXT_METHOD *method, void *obj, BIO *out,
+                     int indent);
 
 static void *ocsp_nonce_new(void);
 static int i2d_ocsp_nonce(void *a, unsigned char **pp);
 static void *d2i_ocsp_nonce(void *a, const unsigned char **pp, long length);
 static void ocsp_nonce_free(void *a);
-static int i2r_ocsp_nonce(X509V3_EXT_METHOD *method, void *nonce, BIO *out, int indent);
+static int i2r_ocsp_nonce(const X509V3_EXT_METHOD *method, void *nonce,
+                         BIO *out, int indent);
 
-static int i2r_ocsp_nocheck(X509V3_EXT_METHOD *method, void *nocheck, BIO *out, int indent);
-static void *s2i_ocsp_nocheck(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, const char *str);
-static int i2r_ocsp_serviceloc(X509V3_EXT_METHOD *method, void *in, BIO *bp, int ind);
+static int i2r_ocsp_nocheck(const X509V3_EXT_METHOD *method,
+                           void *nocheck, BIO *out, int indent);
+static void *s2i_ocsp_nocheck(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
+                             const char *str);
+static int i2r_ocsp_serviceloc(const X509V3_EXT_METHOD *method, void *in,
+                              BIO *bp, int ind);
 
 const X509V3_EXT_METHOD v3_ocsp_crlid = {
        NID_id_pkix_OCSP_CrlID, 0, ASN1_ITEM_ref(OCSP_CRLID),
@@ -148,7 +155,8 @@ const X509V3_EXT_METHOD v3_ocsp_serviceloc = {
        NULL
 };
 
-static int i2r_ocsp_crlid(X509V3_EXT_METHOD *method, void *in, BIO *bp, int ind)
+static int i2r_ocsp_crlid(const X509V3_EXT_METHOD *method, void *in, BIO *bp,
+                         int ind)
 {
        OCSP_CRLID *a = in;
        if (a->crlUrl)
@@ -174,7 +182,8 @@ static int i2r_ocsp_crlid(X509V3_EXT_METHOD *method, void *in, BIO *bp, int ind)
        return 0;
 }
 
-static int i2r_ocsp_acutoff(X509V3_EXT_METHOD *method, void *cutoff, BIO *bp, int ind)
+static int i2r_ocsp_acutoff(const X509V3_EXT_METHOD *method, void *cutoff,
+                           BIO *bp, int ind)
 {
        if (BIO_printf(bp, "%*s", ind, "") <= 0) return 0;
        if(!ASN1_GENERALIZEDTIME_print(bp, cutoff)) return 0;
@@ -182,7 +191,8 @@ static int i2r_ocsp_acutoff(X509V3_EXT_METHOD *method, void *cutoff, BIO *bp, in
 }
 
 
-static int i2r_object(X509V3_EXT_METHOD *method, void *oid, BIO *bp, int ind)
+static int i2r_object(const X509V3_EXT_METHOD *method, void *oid, BIO *bp,
+                     int ind)
 {
        if (BIO_printf(bp, "%*s", ind, "") <= 0) return 0;
        if(i2a_ASN1_OBJECT(bp, oid) <= 0) return 0;
@@ -232,7 +242,8 @@ static void ocsp_nonce_free(void *a)
        M_ASN1_OCTET_STRING_free(a);
 }
 
-static int i2r_ocsp_nonce(X509V3_EXT_METHOD *method, void *nonce, BIO *out, int indent)
+static int i2r_ocsp_nonce(const X509V3_EXT_METHOD *method, void *nonce,
+                         BIO *out, int indent)
 {
        if(BIO_printf(out, "%*s", indent, "") <= 0) return 0;
        if(i2a_ASN1_STRING(out, nonce, V_ASN1_OCTET_STRING) <= 0) return 0;
@@ -241,17 +252,20 @@ static int i2r_ocsp_nonce(X509V3_EXT_METHOD *method, void *nonce, BIO *out, int
 
 /* Nocheck is just a single NULL. Don't print anything and always set it */
 
-static int i2r_ocsp_nocheck(X509V3_EXT_METHOD *method, void *nocheck, BIO *out, int indent)
+static int i2r_ocsp_nocheck(const X509V3_EXT_METHOD *method, void *nocheck,
+                           BIO *out, int indent)
 {
        return 1;
 }
 
-static void *s2i_ocsp_nocheck(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, const char *str)
+static void *s2i_ocsp_nocheck(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
+                             const char *str)
 {
        return ASN1_NULL_new();
 }
 
-static int i2r_ocsp_serviceloc(X509V3_EXT_METHOD *method, void *in, BIO *bp, int ind)
+static int i2r_ocsp_serviceloc(const X509V3_EXT_METHOD *method, void *in,
+                              BIO *bp, int ind)
         {
        int i;
        OCSP_SERVICELOC *a = in;
index 823e9af..0dcfa00 100644 (file)
@@ -82,7 +82,7 @@ static int process_pci_value(CONF_VALUE *val,
                {
                if (*language)
                        {
-                       X509V3err(X509V3_F_PROCESS_PCI_VALUE,X509V3_R_POLICY_LANGUAGE_ALREADTY_DEFINED);
+                       X509V3err(X509V3_F_PROCESS_PCI_VALUE,X509V3_R_POLICY_LANGUAGE_ALREADY_DEFINED);
                        X509V3_conf_err(val);
                        return 0;
                        }
@@ -97,7 +97,7 @@ static int process_pci_value(CONF_VALUE *val,
                {
                if (*pathlen)
                        {
-                       X509V3err(X509V3_F_PROCESS_PCI_VALUE,X509V3_R_POLICY_PATH_LENGTH_ALREADTY_DEFINED);
+                       X509V3err(X509V3_F_PROCESS_PCI_VALUE,X509V3_R_POLICY_PATH_LENGTH_ALREADY_DEFINED);
                        X509V3_conf_err(val);
                        return 0;
                        }
index 86c0ff7..30ca652 100644 (file)
 #include <openssl/conf.h>
 #include <openssl/x509v3.h>
 
-static STACK_OF(CONF_VALUE) *i2v_POLICY_CONSTRAINTS(X509V3_EXT_METHOD *method,
-                               void *bcons, STACK_OF(CONF_VALUE) *extlist);
-static void *v2i_POLICY_CONSTRAINTS(X509V3_EXT_METHOD *method,
-                               X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values);
+static STACK_OF(CONF_VALUE) *
+i2v_POLICY_CONSTRAINTS(const X509V3_EXT_METHOD *method, void *bcons,
+                      STACK_OF(CONF_VALUE) *extlist);
+static void *v2i_POLICY_CONSTRAINTS(const X509V3_EXT_METHOD *method,
+                                   X509V3_CTX *ctx,
+                                   STACK_OF(CONF_VALUE) *values);
 
 const X509V3_EXT_METHOD v3_policy_constraints = {
 NID_policy_constraints, 0,
@@ -88,8 +90,9 @@ ASN1_SEQUENCE(POLICY_CONSTRAINTS) = {
 IMPLEMENT_ASN1_ALLOC_FUNCTIONS(POLICY_CONSTRAINTS)
 
 
-static STACK_OF(CONF_VALUE) *i2v_POLICY_CONSTRAINTS(X509V3_EXT_METHOD *method,
-            void *a, STACK_OF(CONF_VALUE) *extlist)
+static STACK_OF(CONF_VALUE) *
+i2v_POLICY_CONSTRAINTS(const X509V3_EXT_METHOD *method, void *a,
+                      STACK_OF(CONF_VALUE) *extlist)
 {
        POLICY_CONSTRAINTS *pcons = a;
        X509V3_add_value_int("Require Explicit Policy",
@@ -99,8 +102,9 @@ static STACK_OF(CONF_VALUE) *i2v_POLICY_CONSTRAINTS(X509V3_EXT_METHOD *method,
        return extlist;
 }
 
-static void *v2i_POLICY_CONSTRAINTS(X509V3_EXT_METHOD *method,
-            X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values)
+static void *v2i_POLICY_CONSTRAINTS(const X509V3_EXT_METHOD *method,
+                                   X509V3_CTX *ctx,
+                                   STACK_OF(CONF_VALUE) *values)
 {
        POLICY_CONSTRAINTS *pcons=NULL;
        CONF_VALUE *val;
index da03bbc..865bcd3 100644 (file)
 #include <openssl/conf.h>
 #include <openssl/x509v3.h>
 
-static void *v2i_POLICY_MAPPINGS(X509V3_EXT_METHOD *method,
-                               X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
-static STACK_OF(CONF_VALUE) *i2v_POLICY_MAPPINGS(X509V3_EXT_METHOD *method,
-                               void *pmps, STACK_OF(CONF_VALUE) *extlist);
+static void *v2i_POLICY_MAPPINGS(const X509V3_EXT_METHOD *method,
+                                X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
+static STACK_OF(CONF_VALUE) *
+i2v_POLICY_MAPPINGS(const X509V3_EXT_METHOD *method, void *pmps,
+                   STACK_OF(CONF_VALUE) *extlist);
 
 const X509V3_EXT_METHOD v3_policy_mappings = {
        NID_policy_mappings, 0,
@@ -92,8 +93,9 @@ ASN1_ITEM_TEMPLATE_END(POLICY_MAPPINGS)
 IMPLEMENT_ASN1_ALLOC_FUNCTIONS(POLICY_MAPPING)
 
 
-static STACK_OF(CONF_VALUE) *i2v_POLICY_MAPPINGS(X509V3_EXT_METHOD *method,
-               void *a, STACK_OF(CONF_VALUE) *ext_list)
+static STACK_OF(CONF_VALUE) *
+i2v_POLICY_MAPPINGS(const X509V3_EXT_METHOD *method, void *a,
+                   STACK_OF(CONF_VALUE) *ext_list)
 {
        POLICY_MAPPINGS *pmaps = a;
        POLICY_MAPPING *pmap;
@@ -109,8 +111,8 @@ static STACK_OF(CONF_VALUE) *i2v_POLICY_MAPPINGS(X509V3_EXT_METHOD *method,
        return ext_list;
 }
 
-static void *v2i_POLICY_MAPPINGS(X509V3_EXT_METHOD *method,
-                               X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
+static void *v2i_POLICY_MAPPINGS(const X509V3_EXT_METHOD *method,
+                                X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
 {
        POLICY_MAPPINGS *pmaps;
        POLICY_MAPPING *pmap;
index c1bb17f..3146218 100644 (file)
@@ -110,7 +110,7 @@ int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, int inde
        void *ext_str = NULL;
        char *value = NULL;
        const unsigned char *p;
-       X509V3_EXT_METHOD *method;      
+       const X509V3_EXT_METHOD *method;        
        STACK_OF(CONF_VALUE) *nval = NULL;
        int ok = 1;
 
index e18751e..181bd34 100644 (file)
@@ -71,6 +71,7 @@ static int purpose_smime(const X509 *x, int ca);
 static int check_purpose_smime_sign(const X509_PURPOSE *xp, const X509 *x, int ca);
 static int check_purpose_smime_encrypt(const X509_PURPOSE *xp, const X509 *x, int ca);
 static int check_purpose_crl_sign(const X509_PURPOSE *xp, const X509 *x, int ca);
+static int check_purpose_timestamp_sign(const X509_PURPOSE *xp, const X509 *x, int ca);
 static int no_check(const X509_PURPOSE *xp, const X509 *x, int ca);
 static int ocsp_helper(const X509_PURPOSE *xp, const X509 *x, int ca);
 
@@ -87,6 +88,7 @@ static X509_PURPOSE xstandard[] = {
        {X509_PURPOSE_CRL_SIGN, X509_TRUST_COMPAT, 0, check_purpose_crl_sign, "CRL signing", "crlsign", NULL},
        {X509_PURPOSE_ANY, X509_TRUST_DEFAULT, 0, no_check, "Any Purpose", "any", NULL},
        {X509_PURPOSE_OCSP_HELPER, X509_TRUST_COMPAT, 0, ocsp_helper, "OCSP helper", "ocsphelper", NULL},
+       {X509_PURPOSE_TIMESTAMP_SIGN, X509_TRUST_TSA, 0, check_purpose_timestamp_sign, "Time Stamp signing", "timestampsign", NULL},
 };
 
 #define X509_PURPOSE_COUNT (sizeof(xstandard)/sizeof(X509_PURPOSE))
@@ -265,11 +267,14 @@ int X509_PURPOSE_get_trust(X509_PURPOSE *xp)
        return xp->trust;
 }
 
-static int nid_cmp(int *a, int *b)
+static int nid_cmp(const int *a, const int *b)
        {
        return *a - *b;
        }
 
+DECLARE_OBJ_BSEARCH_CMP_FN(int, int, nid);
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(int, int, nid);
+
 int X509_supported_extension(X509_EXTENSION *ex)
        {
        /* This table is a list of the NIDs of supported extensions:
@@ -280,7 +285,7 @@ int X509_supported_extension(X509_EXTENSION *ex)
         * searched using bsearch.
         */
 
-       static int supported_nids[] = {
+       static const int supported_nids[] = {
                NID_netscape_cert_type, /* 71 */
                NID_key_usage,          /* 83 */
                NID_subject_alt_name,   /* 85 */
@@ -292,24 +297,62 @@ int X509_supported_extension(X509_EXTENSION *ex)
                NID_sbgp_autonomousSysNum, /* 291 */
 #endif
                NID_policy_constraints, /* 401 */
-               NID_proxyCertInfo,      /* 661 */
+               NID_proxyCertInfo,      /* 663 */
+               NID_name_constraints,   /* 666 */
+               NID_policy_mappings,    /* 747 */
                NID_inhibit_any_policy  /* 748 */
        };
 
-       int ex_nid;
-
-       ex_nid = OBJ_obj2nid(X509_EXTENSION_get_object(ex));
+       int ex_nid = OBJ_obj2nid(X509_EXTENSION_get_object(ex));
 
        if (ex_nid == NID_undef) 
                return 0;
 
-       if (OBJ_bsearch((char *)&ex_nid, (char *)supported_nids,
-               sizeof(supported_nids)/sizeof(int), sizeof(int),
-               (int (*)(const void *, const void *))nid_cmp))
+       if (OBJ_bsearch_nid(&ex_nid, supported_nids,
+                       sizeof(supported_nids)/sizeof(int)))
                return 1;
        return 0;
        }
+
+static void setup_dp(X509 *x, DIST_POINT *dp)
+       {
+       X509_NAME *iname = NULL;
+       int i;
+       if (dp->reasons)
+               {
+               if (dp->reasons->length > 0)
+                       dp->dp_reasons = dp->reasons->data[0];
+               if (dp->reasons->length > 1)
+                       dp->dp_reasons |= (dp->reasons->data[1] << 8);
+               dp->dp_reasons &= CRLDP_ALL_REASONS;
+               }
+       else
+               dp->dp_reasons = CRLDP_ALL_REASONS;
+       if (!dp->distpoint || (dp->distpoint->type != 1))
+               return;
+       for (i = 0; i < sk_GENERAL_NAME_num(dp->CRLissuer); i++)
+               {
+               GENERAL_NAME *gen = sk_GENERAL_NAME_value(dp->CRLissuer, i);
+               if (gen->type == GEN_DIRNAME)
+                       {
+                       iname = gen->d.directoryName;
+                       break;
+                       }
+               }
+       if (!iname)
+               iname = X509_get_issuer_name(x);
+
+       DIST_POINT_set_dpname(dp->distpoint, iname);
+
+       }
+
+static void setup_crldp(X509 *x)
+       {
+       int i;
+       x->crldp = X509_get_ext_d2i(x, NID_crl_distribution_points, NULL, NULL);
+       for (i = 0; i < sk_DIST_POINT_num(x->crldp); i++)
+               setup_dp(x, sk_DIST_POINT_value(x->crldp, i));
+       }
 
 static void x509v3_cache_extensions(X509 *x)
 {
@@ -417,16 +460,25 @@ static void x509v3_cache_extensions(X509 *x)
        }
        x->skid =X509_get_ext_d2i(x, NID_subject_key_identifier, NULL, NULL);
        x->akid =X509_get_ext_d2i(x, NID_authority_key_identifier, NULL, NULL);
+       x->altname = X509_get_ext_d2i(x, NID_subject_alt_name, NULL, NULL);
+       x->nc = X509_get_ext_d2i(x, NID_name_constraints, &i, NULL);
+       if (!x->nc && (i != -1))
+               x->ex_flags |= EXFLAG_INVALID;
+       setup_crldp(x);
+
 #ifndef OPENSSL_NO_RFC3779
-       x->rfc3779_addr =X509_get_ext_d2i(x, NID_sbgp_ipAddrBlock, NULL, NULL);
-       x->rfc3779_asid =X509_get_ext_d2i(x, NID_sbgp_autonomousSysNum,
-                                         NULL, NULL);
+       x->rfc3779_addr =X509_get_ext_d2i(x, NID_sbgp_ipAddrBlock, NULL, NULL);
+       x->rfc3779_asid =X509_get_ext_d2i(x, NID_sbgp_autonomousSysNum,
+                                         NULL, NULL);
 #endif
        for (i = 0; i < X509_get_ext_count(x); i++)
                {
                ex = X509_get_ext(x, i);
                if (!X509_EXTENSION_get_critical(ex))
                        continue;
+               if (OBJ_obj2nid(X509_EXTENSION_get_object(ex))
+                                       == NID_freshest_crl)
+                       x->ex_flags |= EXFLAG_FRESHEST;
                if (!X509_supported_extension(ex))
                        {
                        x->ex_flags |= EXFLAG_CRITICAL;
@@ -594,6 +646,41 @@ static int ocsp_helper(const X509_PURPOSE *xp, const X509 *x, int ca)
        return 1;
 }
 
+static int check_purpose_timestamp_sign(const X509_PURPOSE *xp, const X509 *x,
+                                       int ca)
+{
+       int i_ext;
+
+       /* If ca is true we must return if this is a valid CA certificate. */
+       if (ca) return check_ca(x);
+
+       /* 
+        * Check the optional key usage field:
+        * if Key Usage is present, it must be one of digitalSignature 
+        * and/or nonRepudiation (other values are not consistent and shall
+        * be rejected).
+        */
+       if ((x->ex_flags & EXFLAG_KUSAGE)
+           && ((x->ex_kusage & ~(KU_NON_REPUDIATION | KU_DIGITAL_SIGNATURE)) ||
+               !(x->ex_kusage & (KU_NON_REPUDIATION | KU_DIGITAL_SIGNATURE))))
+               return 0;
+
+       /* Only time stamp key usage is permitted and it's required. */
+       if (!(x->ex_flags & EXFLAG_XKUSAGE) || x->ex_xkusage != XKU_TIMESTAMP)
+               return 0;
+
+       /* Extended Key Usage MUST be critical */
+       i_ext = X509_get_ext_by_NID((X509 *) x, NID_ext_key_usage, 0);
+       if (i_ext >= 0)
+               {
+               X509_EXTENSION *ext = X509_get_ext((X509 *) x, i_ext);
+               if (!X509_EXTENSION_get_critical(ext))
+                       return 0;
+               }
+
+       return 1;
+}
+
 static int no_check(const X509_PURPOSE *xp, const X509 *x, int ca)
 {
        return 1;
@@ -618,39 +705,14 @@ int X509_check_issued(X509 *issuer, X509 *subject)
                                return X509_V_ERR_SUBJECT_ISSUER_MISMATCH;
        x509v3_cache_extensions(issuer);
        x509v3_cache_extensions(subject);
-       if(subject->akid) {
-               /* Check key ids (if present) */
-               if(subject->akid->keyid && issuer->skid &&
-                ASN1_OCTET_STRING_cmp(subject->akid->keyid, issuer->skid) )
-                               return X509_V_ERR_AKID_SKID_MISMATCH;
-               /* Check serial number */
-               if(subject->akid->serial &&
-                       ASN1_INTEGER_cmp(X509_get_serialNumber(issuer),
-                                               subject->akid->serial))
-                               return X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH;
-               /* Check issuer name */
-               if(subject->akid->issuer) {
-                       /* Ugh, for some peculiar reason AKID includes
-                        * SEQUENCE OF GeneralName. So look for a DirName.
-                        * There may be more than one but we only take any
-                        * notice of the first.
-                        */
-                       GENERAL_NAMES *gens;
-                       GENERAL_NAME *gen;
-                       X509_NAME *nm = NULL;
-                       int i;
-                       gens = subject->akid->issuer;
-                       for(i = 0; i < sk_GENERAL_NAME_num(gens); i++) {
-                               gen = sk_GENERAL_NAME_value(gens, i);
-                               if(gen->type == GEN_DIRNAME) {
-                                       nm = gen->d.dirn;
-                                       break;
-                               }
-                       }
-                       if(nm && X509_NAME_cmp(nm, X509_get_issuer_name(issuer)))
-                               return X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH;
+
+       if(subject->akid)
+               {
+               int ret = X509_check_akid(issuer, subject->akid);
+               if (ret != X509_V_OK)
+                       return ret;
                }
-       }
+
        if(subject->ex_flags & EXFLAG_PROXY)
                {
                if(ku_reject(issuer, KU_DIGITAL_SIGNATURE))
@@ -661,3 +723,45 @@ int X509_check_issued(X509 *issuer, X509 *subject)
        return X509_V_OK;
 }
 
+int X509_check_akid(X509 *issuer, AUTHORITY_KEYID *akid)
+       {
+
+       if(!akid)
+               return X509_V_OK;
+
+       /* Check key ids (if present) */
+       if(akid->keyid && issuer->skid &&
+                ASN1_OCTET_STRING_cmp(akid->keyid, issuer->skid) )
+                               return X509_V_ERR_AKID_SKID_MISMATCH;
+       /* Check serial number */
+       if(akid->serial &&
+               ASN1_INTEGER_cmp(X509_get_serialNumber(issuer), akid->serial))
+                               return X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH;
+       /* Check issuer name */
+       if(akid->issuer)
+               {
+               /* Ugh, for some peculiar reason AKID includes
+                * SEQUENCE OF GeneralName. So look for a DirName.
+                * There may be more than one but we only take any
+                * notice of the first.
+                */
+               GENERAL_NAMES *gens;
+               GENERAL_NAME *gen;
+               X509_NAME *nm = NULL;
+               int i;
+               gens = akid->issuer;
+               for(i = 0; i < sk_GENERAL_NAME_num(gens); i++)
+                       {
+                       gen = sk_GENERAL_NAME_value(gens, i);
+                       if(gen->type == GEN_DIRNAME)
+                               {
+                               nm = gen->d.dirn;
+                               break;
+                               }
+                       }
+               if(nm && X509_NAME_cmp(nm, X509_get_issuer_name(issuer)))
+                       return X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH;
+               }
+       return X509_V_OK;
+       }
+
index 7a45216..e030234 100644 (file)
@@ -67,9 +67,9 @@
 
 static char *strip_spaces(char *name);
 static int sk_strcmp(const char * const *a, const char * const *b);
-static STACK *get_email(X509_NAME *name, GENERAL_NAMES *gens);
-static void str_free(void *str);
-static int append_ia5(STACK **sk, ASN1_IA5STRING *email);
+static STACK_OF(OPENSSL_STRING) *get_email(X509_NAME *name, GENERAL_NAMES *gens);
+static void str_free(OPENSSL_STRING str);
+static int append_ia5(STACK_OF(OPENSSL_STRING) **sk, ASN1_IA5STRING *email);
 
 static int ipv4_from_asc(unsigned char *v4, const char *in);
 static int ipv6_from_asc(unsigned char *v6, const char *in);
@@ -360,10 +360,10 @@ static char *strip_spaces(char *name)
  * @@@ (Contents of buffer are always kept in ASCII, also on EBCDIC machines)
  */
 
-char *hex_to_string(unsigned char *buffer, long len)
+char *hex_to_string(const unsigned char *buffer, long len)
 {
        char *tmp, *q;
-       unsigned char *p;
+       const unsigned char *p;
        int i;
        const static char hexdig[] = "0123456789ABCDEF";
        if(!buffer || !len) return NULL;
@@ -389,7 +389,7 @@ char *hex_to_string(unsigned char *buffer, long len)
  * a buffer
  */
 
-unsigned char *string_to_hex(char *str, long *len)
+unsigned char *string_to_hex(const char *str, long *len)
 {
        unsigned char *hexbuf, *q;
        unsigned char ch, cl, *p;
@@ -463,21 +463,23 @@ static int sk_strcmp(const char * const *a, const char * const *b)
        return strcmp(*a, *b);
 }
 
-STACK *X509_get1_email(X509 *x)
+STACK_OF(OPENSSL_STRING) *X509_get1_email(X509 *x)
 {
        GENERAL_NAMES *gens;
-       STACK *ret;
+       STACK_OF(OPENSSL_STRING) *ret;
+
        gens = X509_get_ext_d2i(x, NID_subject_alt_name, NULL, NULL);
        ret = get_email(X509_get_subject_name(x), gens);
        sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
        return ret;
 }
 
-STACK *X509_get1_ocsp(X509 *x)
+STACK_OF(OPENSSL_STRING) *X509_get1_ocsp(X509 *x)
 {
        AUTHORITY_INFO_ACCESS *info;
-       STACK *ret = NULL;
+       STACK_OF(OPENSSL_STRING) *ret = NULL;
        int i;
+
        info = X509_get_ext_d2i(x, NID_info_access, NULL, NULL);
        if (!info)
                return NULL;
@@ -497,11 +499,12 @@ STACK *X509_get1_ocsp(X509 *x)
        return ret;
 }
 
-STACK *X509_REQ_get1_email(X509_REQ *x)
+STACK_OF(OPENSSL_STRING) *X509_REQ_get1_email(X509_REQ *x)
 {
        GENERAL_NAMES *gens;
        STACK_OF(X509_EXTENSION) *exts;
-       STACK *ret;
+       STACK_OF(OPENSSL_STRING) *ret;
+
        exts = X509_REQ_get_extensions(x);
        gens = X509V3_get_d2i(exts, NID_subject_alt_name, NULL, NULL);
        ret = get_email(X509_REQ_get_subject_name(x), gens);
@@ -511,9 +514,9 @@ STACK *X509_REQ_get1_email(X509_REQ *x)
 }
 
 
-static STACK *get_email(X509_NAME *name, GENERAL_NAMES *gens)
+static STACK_OF(OPENSSL_STRING) *get_email(X509_NAME *name, GENERAL_NAMES *gens)
 {
-       STACK *ret = NULL;
+       STACK_OF(OPENSSL_STRING) *ret = NULL;
        X509_NAME_ENTRY *ne;
        ASN1_IA5STRING *email;
        GENERAL_NAME *gen;
@@ -536,23 +539,23 @@ static STACK *get_email(X509_NAME *name, GENERAL_NAMES *gens)
        return ret;
 }
 
-static void str_free(void *str)
+static void str_free(OPENSSL_STRING str)
 {
        OPENSSL_free(str);
 }
 
-static int append_ia5(STACK **sk, ASN1_IA5STRING *email)
+static int append_ia5(STACK_OF(OPENSSL_STRING) **sk, ASN1_IA5STRING *email)
 {
        char *emtmp;
        /* First some sanity checks */
        if(email->type != V_ASN1_IA5STRING) return 1;
        if(!email->data || !email->length) return 1;
-       if(!*sk) *sk = sk_new(sk_strcmp);
+       if(!*sk) *sk = sk_OPENSSL_STRING_new(sk_strcmp);
        if(!*sk) return 0;
        /* Don't add duplicates */
-       if(sk_find(*sk, (char *)email->data) != -1) return 1;
+       if(sk_OPENSSL_STRING_find(*sk, (char *)email->data) != -1) return 1;
        emtmp = BUF_strdup((char *)email->data);
-       if(!emtmp || !sk_push(*sk, emtmp)) {
+       if(!emtmp || !sk_OPENSSL_STRING_push(*sk, emtmp)) {
                X509_email_free(*sk);
                *sk = NULL;
                return 0;
@@ -560,9 +563,9 @@ static int append_ia5(STACK **sk, ASN1_IA5STRING *email)
        return 1;
 }
 
-void X509_email_free(STACK *sk)
+void X509_email_free(STACK_OF(OPENSSL_STRING) *sk)
 {
-       sk_pop_free(sk, str_free);
+       sk_OPENSSL_STRING_pop_free(sk, str_free);
 }
 
 /* Convert IP addresses both IPv4 and IPv6 into an 
index d538ad8..f9f6f1f 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/x509v3/v3err.c */
 /* ====================================================================
- * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2007 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -70,6 +70,7 @@
 
 static ERR_STRING_DATA X509V3_str_functs[]=
        {
+{ERR_FUNC(X509V3_F_A2I_GENERAL_NAME),  "A2I_GENERAL_NAME"},
 {ERR_FUNC(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE),       "ASIDENTIFIERCHOICE_CANONIZE"},
 {ERR_FUNC(X509V3_F_ASIDENTIFIERCHOICE_IS_CANONICAL),   "ASIDENTIFIERCHOICE_IS_CANONICAL"},
 {ERR_FUNC(X509V3_F_COPY_EMAIL),        "COPY_EMAIL"},
@@ -79,6 +80,7 @@ static ERR_STRING_DATA X509V3_str_functs[]=
 {ERR_FUNC(X509V3_F_DO_EXT_I2D),        "DO_EXT_I2D"},
 {ERR_FUNC(X509V3_F_DO_EXT_NCONF),      "DO_EXT_NCONF"},
 {ERR_FUNC(X509V3_F_DO_I2V_NAME_CONSTRAINTS),   "DO_I2V_NAME_CONSTRAINTS"},
+{ERR_FUNC(X509V3_F_GNAMES_FROM_SECTNAME),      "GNAMES_FROM_SECTNAME"},
 {ERR_FUNC(X509V3_F_HEX_TO_STRING),     "hex_to_string"},
 {ERR_FUNC(X509V3_F_I2S_ASN1_ENUMERATED),       "i2s_ASN1_ENUMERATED"},
 {ERR_FUNC(X509V3_F_I2S_ASN1_IA5STRING),        "I2S_ASN1_IA5STRING"},
@@ -95,6 +97,7 @@ static ERR_STRING_DATA X509V3_str_functs[]=
 {ERR_FUNC(X509V3_F_S2I_ASN1_OCTET_STRING),     "s2i_ASN1_OCTET_STRING"},
 {ERR_FUNC(X509V3_F_S2I_ASN1_SKEY_ID),  "S2I_ASN1_SKEY_ID"},
 {ERR_FUNC(X509V3_F_S2I_SKEY_ID),       "S2I_SKEY_ID"},
+{ERR_FUNC(X509V3_F_SET_DIST_POINT_NAME),       "SET_DIST_POINT_NAME"},
 {ERR_FUNC(X509V3_F_STRING_TO_HEX),     "string_to_hex"},
 {ERR_FUNC(X509V3_F_SXNET_ADD_ID_ASC),  "SXNET_add_id_asc"},
 {ERR_FUNC(X509V3_F_SXNET_ADD_ID_INTEGER),      "SXNET_add_id_INTEGER"},
@@ -110,6 +113,7 @@ static ERR_STRING_DATA X509V3_str_functs[]=
 {ERR_FUNC(X509V3_F_V2I_EXTENDED_KEY_USAGE),    "V2I_EXTENDED_KEY_USAGE"},
 {ERR_FUNC(X509V3_F_V2I_GENERAL_NAMES), "v2i_GENERAL_NAMES"},
 {ERR_FUNC(X509V3_F_V2I_GENERAL_NAME_EX),       "v2i_GENERAL_NAME_ex"},
+{ERR_FUNC(X509V3_F_V2I_IDP),   "V2I_IDP"},
 {ERR_FUNC(X509V3_F_V2I_IPADDRBLOCKS),  "V2I_IPADDRBLOCKS"},
 {ERR_FUNC(X509V3_F_V2I_ISSUER_ALT),    "V2I_ISSUER_ALT"},
 {ERR_FUNC(X509V3_F_V2I_NAME_CONSTRAINTS),      "V2I_NAME_CONSTRAINTS"},
@@ -141,6 +145,7 @@ static ERR_STRING_DATA X509V3_str_reasons[]=
 {ERR_REASON(X509V3_R_BN_DEC2BN_ERROR)    ,"bn dec2bn error"},
 {ERR_REASON(X509V3_R_BN_TO_ASN1_INTEGER_ERROR),"bn to asn1 integer error"},
 {ERR_REASON(X509V3_R_DIRNAME_ERROR)      ,"dirname error"},
+{ERR_REASON(X509V3_R_DISTPOINT_ALREADY_SET),"distpoint already set"},
 {ERR_REASON(X509V3_R_DUPLICATE_ZONE_ID)  ,"duplicate zone id"},
 {ERR_REASON(X509V3_R_ERROR_CONVERTING_ZONE),"error converting zone"},
 {ERR_REASON(X509V3_R_ERROR_CREATING_EXTENSION),"error creating extension"},
@@ -154,6 +159,7 @@ static ERR_STRING_DATA X509V3_str_reasons[]=
 {ERR_REASON(X509V3_R_ILLEGAL_EMPTY_EXTENSION),"illegal empty extension"},
 {ERR_REASON(X509V3_R_ILLEGAL_HEX_DIGIT)  ,"illegal hex digit"},
 {ERR_REASON(X509V3_R_INCORRECT_POLICY_SYNTAX_TAG),"incorrect policy syntax tag"},
+{ERR_REASON(X509V3_R_INVALID_MULTIPLE_RDNS),"invalid multiple rdns"},
 {ERR_REASON(X509V3_R_INVALID_ASNUMBER)   ,"invalid asnumber"},
 {ERR_REASON(X509V3_R_INVALID_ASRANGE)    ,"invalid asrange"},
 {ERR_REASON(X509V3_R_INVALID_BOOLEAN_STRING),"invalid boolean string"},
@@ -187,9 +193,9 @@ static ERR_STRING_DATA X509V3_str_reasons[]=
 {ERR_REASON(X509V3_R_ODD_NUMBER_OF_DIGITS),"odd number of digits"},
 {ERR_REASON(X509V3_R_OPERATION_NOT_DEFINED),"operation not defined"},
 {ERR_REASON(X509V3_R_OTHERNAME_ERROR)    ,"othername error"},
-{ERR_REASON(X509V3_R_POLICY_LANGUAGE_ALREADTY_DEFINED),"policy language alreadty defined"},
+{ERR_REASON(X509V3_R_POLICY_LANGUAGE_ALREADY_DEFINED),"policy language already defined"},
 {ERR_REASON(X509V3_R_POLICY_PATH_LENGTH) ,"policy path length"},
-{ERR_REASON(X509V3_R_POLICY_PATH_LENGTH_ALREADTY_DEFINED),"policy path length alreadty defined"},
+{ERR_REASON(X509V3_R_POLICY_PATH_LENGTH_ALREADY_DEFINED),"policy path length already defined"},
 {ERR_REASON(X509V3_R_POLICY_SYNTAX_NOT_CURRENTLY_SUPPORTED),"policy syntax not currently supported"},
 {ERR_REASON(X509V3_R_POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY),"policy when proxy language requires no policy"},
 {ERR_REASON(X509V3_R_SECTION_NOT_FOUND)  ,"section not found"},
@@ -200,6 +206,7 @@ static ERR_STRING_DATA X509V3_str_reasons[]=
 {ERR_REASON(X509V3_R_UNKNOWN_EXTENSION_NAME),"unknown extension name"},
 {ERR_REASON(X509V3_R_UNKNOWN_OPTION)     ,"unknown option"},
 {ERR_REASON(X509V3_R_UNSUPPORTED_OPTION) ,"unsupported option"},
+{ERR_REASON(X509V3_R_UNSUPPORTED_TYPE)   ,"unsupported type"},
 {ERR_REASON(X509V3_R_USER_TOO_LONG)      ,"user too long"},
 {0,NULL}
        };
index 9ef83da..b308abe 100644 (file)
@@ -76,12 +76,19 @@ typedef void * (*X509V3_EXT_NEW)(void);
 typedef void (*X509V3_EXT_FREE)(void *);
 typedef void * (*X509V3_EXT_D2I)(void *, const unsigned char ** , long);
 typedef int (*X509V3_EXT_I2D)(void *, unsigned char **);
-typedef STACK_OF(CONF_VALUE) * (*X509V3_EXT_I2V)(struct v3_ext_method *method, void *ext, STACK_OF(CONF_VALUE) *extlist);
-typedef void * (*X509V3_EXT_V2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, STACK_OF(CONF_VALUE) *values);
-typedef char * (*X509V3_EXT_I2S)(struct v3_ext_method *method, void *ext);
-typedef void * (*X509V3_EXT_S2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, const char *str);
-typedef int (*X509V3_EXT_I2R)(struct v3_ext_method *method, void *ext, BIO *out, int indent);
-typedef void * (*X509V3_EXT_R2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, const char *str);
+typedef STACK_OF(CONF_VALUE) *
+  (*X509V3_EXT_I2V)(const struct v3_ext_method *method, void *ext,
+                   STACK_OF(CONF_VALUE) *extlist);
+typedef void * (*X509V3_EXT_V2I)(const struct v3_ext_method *method,
+                                struct v3_ext_ctx *ctx,
+                                STACK_OF(CONF_VALUE) *values);
+typedef char * (*X509V3_EXT_I2S)(const struct v3_ext_method *method, void *ext);
+typedef void * (*X509V3_EXT_S2I)(const struct v3_ext_method *method,
+                                struct v3_ext_ctx *ctx, const char *str);
+typedef int (*X509V3_EXT_I2R)(const struct v3_ext_method *method, void *ext,
+                             BIO *out, int indent);
+typedef void * (*X509V3_EXT_R2I)(const struct v3_ext_method *method,
+                                struct v3_ext_ctx *ctx, const char *str);
 
 /* V3 extension structure */
 
@@ -220,24 +227,41 @@ union {
        GENERAL_NAMES *fullname;
        STACK_OF(X509_NAME_ENTRY) *relativename;
 } name;
+/* If relativename then this contains the full distribution point name */
+X509_NAME *dpname;
 } DIST_POINT_NAME;
-
-typedef struct DIST_POINT_st {
+/* All existing reasons */
+#define CRLDP_ALL_REASONS      0x807f
+
+#define CRL_REASON_NONE                                -1
+#define CRL_REASON_UNSPECIFIED                 0
+#define CRL_REASON_KEY_COMPROMISE              1
+#define CRL_REASON_CA_COMPROMISE               2
+#define CRL_REASON_AFFILIATION_CHANGED         3
+#define CRL_REASON_SUPERSEDED                  4
+#define CRL_REASON_CESSATION_OF_OPERATION      5
+#define CRL_REASON_CERTIFICATE_HOLD            6
+#define CRL_REASON_REMOVE_FROM_CRL             8
+#define CRL_REASON_PRIVILEGE_WITHDRAWN         9
+#define CRL_REASON_AA_COMPROMISE               10
+
+struct DIST_POINT_st {
 DIST_POINT_NAME        *distpoint;
 ASN1_BIT_STRING *reasons;
 GENERAL_NAMES *CRLissuer;
-} DIST_POINT;
+int dp_reasons;
+};
 
 typedef STACK_OF(DIST_POINT) CRL_DIST_POINTS;
 
 DECLARE_STACK_OF(DIST_POINT)
 DECLARE_ASN1_SET_OF(DIST_POINT)
 
-typedef struct AUTHORITY_KEYID_st {
+struct AUTHORITY_KEYID_st {
 ASN1_OCTET_STRING *keyid;
 GENERAL_NAMES *issuer;
 ASN1_INTEGER *serial;
-} AUTHORITY_KEYID;
+};
 
 /* Strong extranet structures */
 
@@ -303,10 +327,10 @@ typedef struct GENERAL_SUBTREE_st {
 
 DECLARE_STACK_OF(GENERAL_SUBTREE)
 
-typedef struct NAME_CONSTRAINTS_st {
+struct NAME_CONSTRAINTS_st {
        STACK_OF(GENERAL_SUBTREE) *permittedSubtrees;
        STACK_OF(GENERAL_SUBTREE) *excludedSubtrees;
-} NAME_CONSTRAINTS;
+};
 
 typedef struct POLICY_CONSTRAINTS_st {
        ASN1_INTEGER *requireExplicitPolicy;
@@ -329,6 +353,31 @@ typedef struct PROXY_CERT_INFO_EXTENSION_st
 DECLARE_ASN1_FUNCTIONS(PROXY_POLICY)
 DECLARE_ASN1_FUNCTIONS(PROXY_CERT_INFO_EXTENSION)
 
+struct ISSUING_DIST_POINT_st
+       {
+       DIST_POINT_NAME *distpoint;
+       int onlyuser;
+       int onlyCA;
+       ASN1_BIT_STRING *onlysomereasons;
+       int indirectCRL;
+       int onlyattr;
+       };
+
+/* Values in idp_flags field */
+/* IDP present */
+#define        IDP_PRESENT     0x1
+/* IDP values inconsistent */
+#define IDP_INVALID    0x2
+/* onlyuser true */
+#define        IDP_ONLYUSER    0x4
+/* onlyCA true */
+#define        IDP_ONLYCA      0x8
+/* onlyattr true */
+#define IDP_ONLYATTR   0x10
+/* indirectCRL true */
+#define IDP_INDIRECT   0x20
+/* onlysomereasons present */
+#define IDP_REASONS    0x40
 
 #define X509V3_conf_err(val) ERR_add_error_data(6, "section:", val->section, \
 ",name:", val->name, ",value:", val->value);
@@ -373,6 +422,7 @@ DECLARE_ASN1_FUNCTIONS(PROXY_CERT_INFO_EXTENSION)
 #define EXFLAG_PROXY           0x400
 
 #define EXFLAG_INVALID_POLICY  0x800
+#define EXFLAG_FRESHEST                0x1000
 
 #define KU_DIGITAL_SIGNATURE   0x0080
 #define KU_NON_REPUDIATION     0x0040
@@ -424,9 +474,10 @@ typedef struct x509_purpose_st {
 #define X509_PURPOSE_CRL_SIGN          6
 #define X509_PURPOSE_ANY               7
 #define X509_PURPOSE_OCSP_HELPER       8
+#define X509_PURPOSE_TIMESTAMP_SIGN    9
 
 #define X509_PURPOSE_MIN               1
-#define X509_PURPOSE_MAX               8
+#define X509_PURPOSE_MAX               9
 
 /* Flags for X509V3_EXT_print() */
 
@@ -471,6 +522,9 @@ DECLARE_ASN1_FUNCTIONS(AUTHORITY_KEYID)
 DECLARE_ASN1_FUNCTIONS(PKEY_USAGE_PERIOD)
 
 DECLARE_ASN1_FUNCTIONS(GENERAL_NAME)
+GENERAL_NAME *GENERAL_NAME_dup(GENERAL_NAME *a);
+int GENERAL_NAME_cmp(GENERAL_NAME *a, GENERAL_NAME *b);
+
 
 
 ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
@@ -486,11 +540,18 @@ DECLARE_ASN1_FUNCTIONS(GENERAL_NAMES)
 
 STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method,
                GENERAL_NAMES *gen, STACK_OF(CONF_VALUE) *extlist);
-GENERAL_NAMES *v2i_GENERAL_NAMES(X509V3_EXT_METHOD *method,
-                               X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
+GENERAL_NAMES *v2i_GENERAL_NAMES(const X509V3_EXT_METHOD *method,
+                                X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
 
 DECLARE_ASN1_FUNCTIONS(OTHERNAME)
 DECLARE_ASN1_FUNCTIONS(EDIPARTYNAME)
+int OTHERNAME_cmp(OTHERNAME *a, OTHERNAME *b);
+void GENERAL_NAME_set0_value(GENERAL_NAME *a, int type, void *value);
+void *GENERAL_NAME_get0_value(GENERAL_NAME *a, int *ptype);
+int GENERAL_NAME_set0_othername(GENERAL_NAME *gen,
+                               ASN1_OBJECT *oid, ASN1_TYPE *value);
+int GENERAL_NAME_get0_otherName(GENERAL_NAME *gen, 
+                               ASN1_OBJECT **poid, ASN1_TYPE **pvalue);
 
 char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *ia5);
 ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
@@ -507,6 +568,11 @@ DECLARE_ASN1_FUNCTIONS(NOTICEREF)
 DECLARE_ASN1_FUNCTIONS(CRL_DIST_POINTS)
 DECLARE_ASN1_FUNCTIONS(DIST_POINT)
 DECLARE_ASN1_FUNCTIONS(DIST_POINT_NAME)
+DECLARE_ASN1_FUNCTIONS(ISSUING_DIST_POINT)
+
+int DIST_POINT_set_dpname(DIST_POINT_NAME *dpn, X509_NAME *iname);
+
+int NAME_CONSTRAINTS_check(X509 *x, NAME_CONSTRAINTS *nc);
 
 DECLARE_ASN1_FUNCTIONS(ACCESS_DESCRIPTION)
 DECLARE_ASN1_FUNCTIONS(AUTHORITY_INFO_ACCESS)
@@ -524,11 +590,16 @@ DECLARE_ASN1_ALLOC_FUNCTIONS(NAME_CONSTRAINTS)
 DECLARE_ASN1_ALLOC_FUNCTIONS(POLICY_CONSTRAINTS)
 DECLARE_ASN1_ITEM(POLICY_CONSTRAINTS)
 
+GENERAL_NAME *a2i_GENERAL_NAME(GENERAL_NAME *out,
+                              const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
+                              int gen_type, char *value, int is_nc);
+
 #ifdef HEADER_CONF_H
-GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
-                                                       CONF_VALUE *cnf);
-GENERAL_NAME *v2i_GENERAL_NAME_ex(GENERAL_NAME *out, X509V3_EXT_METHOD *method,
-                               X509V3_CTX *ctx, CONF_VALUE *cnf, int is_nc);
+GENERAL_NAME *v2i_GENERAL_NAME(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
+                              CONF_VALUE *cnf);
+GENERAL_NAME *v2i_GENERAL_NAME_ex(GENERAL_NAME *out,
+                                 const X509V3_EXT_METHOD *method,
+                                 X509V3_CTX *ctx, CONF_VALUE *cnf, int is_nc);
 void X509V3_conf_free(CONF_VALUE *val);
 
 X509_EXTENSION *X509V3_EXT_nconf_nid(CONF *conf, X509V3_CTX *ctx, int ext_nid, char *value);
@@ -538,18 +609,23 @@ int X509V3_EXT_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section, X509 *cert)
 int X509V3_EXT_REQ_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section, X509_REQ *req);
 int X509V3_EXT_CRL_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section, X509_CRL *crl);
 
-X509_EXTENSION *X509V3_EXT_conf_nid(LHASH *conf, X509V3_CTX *ctx, int ext_nid, char *value);
-X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name, char *value);
-int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509 *cert);
-int X509V3_EXT_REQ_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509_REQ *req);
-int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509_CRL *crl);
+X509_EXTENSION *X509V3_EXT_conf_nid(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx,
+                                   int ext_nid, char *value);
+X509_EXTENSION *X509V3_EXT_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx,
+                               char *name, char *value);
+int X509V3_EXT_add_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx,
+                       char *section, X509 *cert);
+int X509V3_EXT_REQ_add_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx,
+                           char *section, X509_REQ *req);
+int X509V3_EXT_CRL_add_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx,
+                           char *section, X509_CRL *crl);
 
 int X509V3_add_value_bool_nf(char *name, int asn1_bool,
-                                               STACK_OF(CONF_VALUE) **extlist);
+                            STACK_OF(CONF_VALUE) **extlist);
 int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool);
 int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint);
 void X509V3_set_nconf(X509V3_CTX *ctx, CONF *conf);
-void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash);
+void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH_OF(CONF_VALUE) *lhash);
 #endif
 
 char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section);
@@ -576,8 +652,8 @@ int X509V3_EXT_add_list(X509V3_EXT_METHOD *extlist);
 int X509V3_EXT_add_alias(int nid_to, int nid_from);
 void X509V3_EXT_cleanup(void);
 
-X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext);
-X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid);
+const X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext);
+const X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid);
 int X509V3_add_standard_extensions(void);
 STACK_OF(CONF_VALUE) *X509V3_parse_list(const char *line);
 void *X509V3_EXT_d2i(X509_EXTENSION *ext);
@@ -587,8 +663,8 @@ void *X509V3_get_d2i(STACK_OF(X509_EXTENSION) *x, int nid, int *crit, int *idx);
 X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc);
 int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, void *value, int crit, unsigned long flags);
 
-char *hex_to_string(unsigned char *buffer, long len);
-unsigned char *string_to_hex(char *str, long *len);
+char *hex_to_string(const unsigned char *buffer, long len);
+unsigned char *string_to_hex(const char *str, long *len);
 int name_cmp(const char *name, const char *cmp);
 
 void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent,
@@ -603,6 +679,7 @@ int X509_check_purpose(X509 *x, int id, int ca);
 int X509_supported_extension(X509_EXTENSION *ex);
 int X509_PURPOSE_set(int *p, int purpose);
 int X509_check_issued(X509 *issuer, X509 *subject);
+int X509_check_akid(X509 *issuer, AUTHORITY_KEYID *akid);
 int X509_PURPOSE_get_count(void);
 X509_PURPOSE * X509_PURPOSE_get0(int idx);
 int X509_PURPOSE_get_by_sname(char *sname);
@@ -616,10 +693,10 @@ int X509_PURPOSE_get_trust(X509_PURPOSE *xp);
 void X509_PURPOSE_cleanup(void);
 int X509_PURPOSE_get_id(X509_PURPOSE *);
 
-STACK *X509_get1_email(X509 *x);
-STACK *X509_REQ_get1_email(X509_REQ *x);
-void X509_email_free(STACK *sk);
-STACK *X509_get1_ocsp(X509 *x);
+STACK_OF(OPENSSL_STRING) *X509_get1_email(X509 *x);
+STACK_OF(OPENSSL_STRING) *X509_REQ_get1_email(X509_REQ *x);
+void X509_email_free(STACK_OF(OPENSSL_STRING) *sk);
+STACK_OF(OPENSSL_STRING) *X509_get1_ocsp(X509 *x);
 
 ASN1_OCTET_STRING *a2i_IPADDRESS(const char *ipasc);
 ASN1_OCTET_STRING *a2i_IPADDRESS_NC(const char *ipasc);
@@ -628,6 +705,7 @@ int X509V3_NAME_from_section(X509_NAME *nm, STACK_OF(CONF_VALUE)*dn_sk,
                                                unsigned long chtype);
 
 void X509_POLICY_NODE_print(BIO *out, X509_POLICY_NODE *node, int indent);
+DECLARE_STACK_OF(X509_POLICY_NODE)
 
 #ifndef OPENSSL_NO_RFC3779
 
@@ -787,8 +865,9 @@ void ERR_load_X509V3_strings(void);
 /* Error codes for the X509V3 functions. */
 
 /* Function codes. */
-#define X509V3_F_ASIDENTIFIERCHOICE_CANONIZE            156
-#define X509V3_F_ASIDENTIFIERCHOICE_IS_CANONICAL        157
+#define X509V3_F_A2I_GENERAL_NAME                       164
+#define X509V3_F_ASIDENTIFIERCHOICE_CANONIZE            161
+#define X509V3_F_ASIDENTIFIERCHOICE_IS_CANONICAL        162
 #define X509V3_F_COPY_EMAIL                             122
 #define X509V3_F_COPY_ISSUER                            123
 #define X509V3_F_DO_DIRNAME                             144
@@ -796,6 +875,7 @@ void ERR_load_X509V3_strings(void);
 #define X509V3_F_DO_EXT_I2D                             135
 #define X509V3_F_DO_EXT_NCONF                           151
 #define X509V3_F_DO_I2V_NAME_CONSTRAINTS                148
+#define X509V3_F_GNAMES_FROM_SECTNAME                   156
 #define X509V3_F_HEX_TO_STRING                          111
 #define X509V3_F_I2S_ASN1_ENUMERATED                    121
 #define X509V3_F_I2S_ASN1_IA5STRING                     149
@@ -812,13 +892,14 @@ void ERR_load_X509V3_strings(void);
 #define X509V3_F_S2I_ASN1_OCTET_STRING                  112
 #define X509V3_F_S2I_ASN1_SKEY_ID                       114
 #define X509V3_F_S2I_SKEY_ID                            115
+#define X509V3_F_SET_DIST_POINT_NAME                    158
 #define X509V3_F_STRING_TO_HEX                          113
 #define X509V3_F_SXNET_ADD_ID_ASC                       125
 #define X509V3_F_SXNET_ADD_ID_INTEGER                   126
 #define X509V3_F_SXNET_ADD_ID_ULONG                     127
 #define X509V3_F_SXNET_GET_ID_ASC                       128
 #define X509V3_F_SXNET_GET_ID_ULONG                     129
-#define X509V3_F_V2I_ASIDENTIFIERS                      158
+#define X509V3_F_V2I_ASIDENTIFIERS                      163
 #define X509V3_F_V2I_ASN1_BIT_STRING                    101
 #define X509V3_F_V2I_AUTHORITY_INFO_ACCESS              139
 #define X509V3_F_V2I_AUTHORITY_KEYID                    119
@@ -827,6 +908,7 @@ void ERR_load_X509V3_strings(void);
 #define X509V3_F_V2I_EXTENDED_KEY_USAGE                         103
 #define X509V3_F_V2I_GENERAL_NAMES                      118
 #define X509V3_F_V2I_GENERAL_NAME_EX                    117
+#define X509V3_F_V2I_IDP                                157
 #define X509V3_F_V2I_IPADDRBLOCKS                       159
 #define X509V3_F_V2I_ISSUER_ALT                                 153
 #define X509V3_F_V2I_NAME_CONSTRAINTS                   147
@@ -855,6 +937,7 @@ void ERR_load_X509V3_strings(void);
 #define X509V3_R_BN_DEC2BN_ERROR                        100
 #define X509V3_R_BN_TO_ASN1_INTEGER_ERROR               101
 #define X509V3_R_DIRNAME_ERROR                          149
+#define X509V3_R_DISTPOINT_ALREADY_SET                  160
 #define X509V3_R_DUPLICATE_ZONE_ID                      133
 #define X509V3_R_ERROR_CONVERTING_ZONE                  131
 #define X509V3_R_ERROR_CREATING_EXTENSION               144
@@ -868,12 +951,13 @@ void ERR_load_X509V3_strings(void);
 #define X509V3_R_ILLEGAL_EMPTY_EXTENSION                151
 #define X509V3_R_ILLEGAL_HEX_DIGIT                      113
 #define X509V3_R_INCORRECT_POLICY_SYNTAX_TAG            152
-#define X509V3_R_INVALID_ASNUMBER                       160
-#define X509V3_R_INVALID_ASRANGE                        161
+#define X509V3_R_INVALID_MULTIPLE_RDNS                  161
+#define X509V3_R_INVALID_ASNUMBER                       162
+#define X509V3_R_INVALID_ASRANGE                        163
 #define X509V3_R_INVALID_BOOLEAN_STRING                         104
 #define X509V3_R_INVALID_EXTENSION_STRING               105
-#define X509V3_R_INVALID_INHERITANCE                    162
-#define X509V3_R_INVALID_IPADDRESS                      163
+#define X509V3_R_INVALID_INHERITANCE                    165
+#define X509V3_R_INVALID_IPADDRESS                      166
 #define X509V3_R_INVALID_NAME                           106
 #define X509V3_R_INVALID_NULL_ARGUMENT                  107
 #define X509V3_R_INVALID_NULL_NAME                      108
@@ -901,9 +985,9 @@ void ERR_load_X509V3_strings(void);
 #define X509V3_R_ODD_NUMBER_OF_DIGITS                   112
 #define X509V3_R_OPERATION_NOT_DEFINED                  148
 #define X509V3_R_OTHERNAME_ERROR                        147
-#define X509V3_R_POLICY_LANGUAGE_ALREADTY_DEFINED       155
+#define X509V3_R_POLICY_LANGUAGE_ALREADY_DEFINED        155
 #define X509V3_R_POLICY_PATH_LENGTH                     156
-#define X509V3_R_POLICY_PATH_LENGTH_ALREADTY_DEFINED    157
+#define X509V3_R_POLICY_PATH_LENGTH_ALREADY_DEFINED     157
 #define X509V3_R_POLICY_SYNTAX_NOT_CURRENTLY_SUPPORTED  158
 #define X509V3_R_POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY 159
 #define X509V3_R_SECTION_NOT_FOUND                      150
@@ -914,6 +998,7 @@ void ERR_load_X509V3_strings(void);
 #define X509V3_R_UNKNOWN_EXTENSION_NAME                         130
 #define X509V3_R_UNKNOWN_OPTION                                 120
 #define X509V3_R_UNSUPPORTED_OPTION                     117
+#define X509V3_R_UNSUPPORTED_TYPE                       167
 #define X509V3_R_USER_TOO_LONG                          132
 
 #ifdef  __cplusplus
index 2616a03..c96821a 100644 (file)
 #!/usr/bin/env perl
 
-$output=shift;
-$masm=1 if ($output =~ /\.asm/);
-open STDOUT,">$output" || die "can't open $output: $!";
-
-print<<___ if(defined($masm));
-_TEXT  SEGMENT
-PUBLIC OPENSSL_rdtsc
-
-PUBLIC OPENSSL_atomic_add
-ALIGN  16
-OPENSSL_atomic_add     PROC
-       mov     eax,DWORD PTR[rcx]
-\$Lspin:       lea     r8,DWORD PTR[rdx+rax]
-lock   cmpxchg DWORD PTR[rcx],r8d
-       jne     \$Lspin
-       mov     eax,r8d
-       cdqe    
-       ret
-OPENSSL_atomic_add     ENDP
-
-PUBLIC OPENSSL_wipe_cpu
-ALIGN  16
-OPENSSL_wipe_cpu       PROC
-       pxor    xmm0,xmm0
-       pxor    xmm1,xmm1
-       pxor    xmm2,xmm2
-       pxor    xmm3,xmm3
-       pxor    xmm4,xmm4
-       pxor    xmm5,xmm5
-       xor     rcx,rcx
-       xor     rdx,rdx
-       xor     r8,r8
-       xor     r9,r9
-       xor     r10,r10
-       xor     r11,r11
-       lea     rax,QWORD PTR[rsp+8]
-       ret
-OPENSSL_wipe_cpu       ENDP
-_TEXT  ENDS
+$flavour = shift;
+$output  = shift;
+if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
 
-CRT\$XIU       SEGMENT
-EXTRN  OPENSSL_cpuid_setup:PROC
-DQ     OPENSSL_cpuid_setup
-CRT\$XIU       ENDS
+$win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
+
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+open STDOUT,"| $^X ${dir}perlasm/x86_64-xlate.pl $flavour $output";
+
+if ($win64)    { $arg1="%rcx"; $arg2="%rdx"; }
+else           { $arg1="%rdi"; $arg2="%rsi"; }
+print<<___;
+.extern                OPENSSL_cpuid_setup
+.section       .init
+       call    OPENSSL_cpuid_setup
 
-___
-print<<___ if(!defined($masm));
 .text
 
 .globl OPENSSL_atomic_add
-.type  OPENSSL_atomic_add,\@function
+.type  OPENSSL_atomic_add,\@abi-omnipotent
 .align 16
 OPENSSL_atomic_add:
-       movl    (%rdi),%eax
-.Lspin:        leaq    (%rsi,%rax),%r8
-lock;  cmpxchgl        %r8d,(%rdi)
+       movl    ($arg1),%eax
+.Lspin:        leaq    ($arg2,%rax),%r8
+       .byte   0xf0            # lock
+       cmpxchgl        %r8d,($arg1)
        jne     .Lspin
        movl    %r8d,%eax
-       .byte   0x48,0x98
+       .byte   0x48,0x98       # cltq/cdqe
        ret
 .size  OPENSSL_atomic_add,.-OPENSSL_atomic_add
 
-.globl OPENSSL_wipe_cpu
-.type  OPENSSL_wipe_cpu,\@function
-.align 16
-OPENSSL_wipe_cpu:
-       pxor    %xmm0,%xmm0
-       pxor    %xmm1,%xmm1
-       pxor    %xmm2,%xmm2
-       pxor    %xmm3,%xmm3
-       pxor    %xmm4,%xmm4
-       pxor    %xmm5,%xmm5
-       pxor    %xmm6,%xmm6
-       pxor    %xmm7,%xmm7
-       pxor    %xmm8,%xmm8
-       pxor    %xmm9,%xmm9
-       pxor    %xmm10,%xmm10
-       pxor    %xmm11,%xmm11
-       pxor    %xmm12,%xmm12
-       pxor    %xmm13,%xmm13
-       pxor    %xmm14,%xmm14
-       pxor    %xmm15,%xmm15
-       xorq    %rcx,%rcx
-       xorq    %rdx,%rdx
-       xorq    %rsi,%rsi
-       xorq    %rdi,%rdi
-       xorq    %r8,%r8
-       xorq    %r9,%r9
-       xorq    %r10,%r10
-       xorq    %r11,%r11
-       leaq    8(%rsp),%rax
-       ret
-.size  OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
-
-.section       .init
-       call    OPENSSL_cpuid_setup
-
-___
-
-open STDOUT,"| $^X perlasm/x86_64-xlate.pl $output";
-print<<___;
-.text
-
 .globl OPENSSL_rdtsc
 .type  OPENSSL_rdtsc,\@abi-omnipotent
 .align 16
@@ -121,6 +50,8 @@ OPENSSL_ia32_cpuid:
 
        xor     %eax,%eax
        cpuid
+       mov     %eax,%r11d              # max value for standard query level
+
        xor     %eax,%eax
        cmp     \$0x756e6547,%ebx       # "Genu"
        setne   %al
@@ -130,10 +61,56 @@ OPENSSL_ia32_cpuid:
        or      %eax,%r9d
        cmp     \$0x6c65746e,%ecx       # "ntel"
        setne   %al
-       or      %eax,%r9d
+       or      %eax,%r9d               # 0 indicates Intel CPU
+       jz      .Lintel
+
+       cmp     \$0x68747541,%ebx       # "Auth"
+       setne   %al
+       mov     %eax,%r10d
+       cmp     \$0x69746E65,%edx       # "enti"
+       setne   %al
+       or      %eax,%r10d
+       cmp     \$0x444D4163,%ecx       # "cAMD"
+       setne   %al
+       or      %eax,%r10d              # 0 indicates AMD CPU
+       jnz     .Lintel
+
+       # AMD specific
+       mov     \$0x80000000,%eax
+       cpuid
+       cmp     \$0x80000008,%eax
+       jb      .Lintel
+
+       mov     \$0x80000008,%eax
+       cpuid
+       movzb   %cl,%r10                # number of cores - 1
+       inc     %r10                    # number of cores
 
        mov     \$1,%eax
        cpuid
+       bt      \$28,%edx               # test hyper-threading bit
+       jnc     .Ldone
+       shr     \$16,%ebx               # number of logical processors
+       cmp     %r10b,%bl
+       ja      .Ldone
+       and     \$0xefffffff,%edx       # ~(1<<28)
+       jmp     .Ldone
+
+.Lintel:
+       cmp     \$4,%r11d
+       mov     \$-1,%r10d
+       jb      .Lnocacheinfo
+
+       mov     \$4,%eax
+       mov     \$0,%ecx                # query L1D
+       cpuid
+       mov     %eax,%r10d
+       shr     \$14,%r10d
+       and     \$0xfff,%r10d           # number of cores -1 per L1D
+
+.Lnocacheinfo:
+       mov     \$1,%eax
+       cpuid
        cmp     \$0,%r9d
        jne     .Lnotintel
        or      \$0x00100000,%edx       # use reserved 20th bit to engage RC4_CHAR
@@ -144,6 +121,11 @@ OPENSSL_ia32_cpuid:
 .Lnotintel:
        bt      \$28,%edx               # test hyper-threading bit
        jnc     .Ldone
+       and     \$0xefffffff,%edx       # ~(1<<28)
+       cmp     \$0,%r10d
+       je      .Ldone
+
+       or      \$0x10000000,%edx       # 1<<28
        shr     \$16,%ebx
        cmp     \$1,%bl                 # see if cache is shared
        ja      .Ldone
@@ -155,5 +137,96 @@ OPENSSL_ia32_cpuid:
        or      %rcx,%rax
        ret
 .size  OPENSSL_ia32_cpuid,.-OPENSSL_ia32_cpuid
+
+.globl  OPENSSL_cleanse
+.type   OPENSSL_cleanse,\@abi-omnipotent
+.align  16
+OPENSSL_cleanse:
+       xor     %rax,%rax
+       cmp     \$15,$arg2
+       jae     .Lot
+       cmp     \$0,$arg2
+       je      .Lret
+.Little:
+       mov     %al,($arg1)
+       sub     \$1,$arg2
+       lea     1($arg1),$arg1
+       jnz     .Little
+.Lret:
+       ret
+.align 16
+.Lot:
+       test    \$7,$arg1
+       jz      .Laligned
+       mov     %al,($arg1)
+       lea     -1($arg2),$arg2
+       lea     1($arg1),$arg1
+       jmp     .Lot
+.Laligned:
+       mov     %rax,($arg1)
+       lea     -8($arg2),$arg2
+       test    \$-8,$arg2
+       lea     8($arg1),$arg1
+       jnz     .Laligned
+       cmp     \$0,$arg2
+       jne     .Little
+       ret
+.size  OPENSSL_cleanse,.-OPENSSL_cleanse
+___
+
+print<<___ if (!$win64);
+.globl OPENSSL_wipe_cpu
+.type  OPENSSL_wipe_cpu,\@abi-omnipotent
+.align 16
+OPENSSL_wipe_cpu:
+       pxor    %xmm0,%xmm0
+       pxor    %xmm1,%xmm1
+       pxor    %xmm2,%xmm2
+       pxor    %xmm3,%xmm3
+       pxor    %xmm4,%xmm4
+       pxor    %xmm5,%xmm5
+       pxor    %xmm6,%xmm6
+       pxor    %xmm7,%xmm7
+       pxor    %xmm8,%xmm8
+       pxor    %xmm9,%xmm9
+       pxor    %xmm10,%xmm10
+       pxor    %xmm11,%xmm11
+       pxor    %xmm12,%xmm12
+       pxor    %xmm13,%xmm13
+       pxor    %xmm14,%xmm14
+       pxor    %xmm15,%xmm15
+       xorq    %rcx,%rcx
+       xorq    %rdx,%rdx
+       xorq    %rsi,%rsi
+       xorq    %rdi,%rdi
+       xorq    %r8,%r8
+       xorq    %r9,%r9
+       xorq    %r10,%r10
+       xorq    %r11,%r11
+       leaq    8(%rsp),%rax
+       ret
+.size  OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
 ___
+print<<___ if ($win64);
+.globl OPENSSL_wipe_cpu
+.type  OPENSSL_wipe_cpu,\@abi-omnipotent
+.align 16
+OPENSSL_wipe_cpu:
+       pxor    %xmm0,%xmm0
+       pxor    %xmm1,%xmm1
+       pxor    %xmm2,%xmm2
+       pxor    %xmm3,%xmm3
+       pxor    %xmm4,%xmm4
+       pxor    %xmm5,%xmm5
+       xorq    %rcx,%rcx
+       xorq    %rdx,%rdx
+       xorq    %r8,%r8
+       xorq    %r9,%r9
+       xorq    %r10,%r10
+       xorq    %r11,%r11
+       leaq    8(%rsp),%rax
+       ret
+.size  OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
+___
+
 close STDOUT;  # flush
index 4408ef2..a7464af 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/bin/env perl
 
-push(@INC,"perlasm");
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+push(@INC, "${dir}perlasm", "perlasm");
 require "x86asm.pl";
 
 &asm_init($ARGV[0],"x86cpuid");
@@ -22,38 +23,90 @@ for (@ARGV) { $sse2=1 if (/-DOPENSSL_IA32_SSE2/); }
        &jnc    (&label("done"));
        &xor    ("eax","eax");
        &cpuid  ();
+       &mov    ("edi","eax");          # max value for standard query level
+
        &xor    ("eax","eax");
        &cmp    ("ebx",0x756e6547);     # "Genu"
-       &data_byte(0x0f,0x95,0xc0);     #&setne (&LB("eax"));
+       &setne  (&LB("eax"));
        &mov    ("ebp","eax");
        &cmp    ("edx",0x49656e69);     # "ineI"
-       &data_byte(0x0f,0x95,0xc0);     #&setne (&LB("eax"));
+       &setne  (&LB("eax"));
        &or     ("ebp","eax");
        &cmp    ("ecx",0x6c65746e);     # "ntel"
-       &data_byte(0x0f,0x95,0xc0);     #&setne (&LB("eax"));
-       &or     ("ebp","eax");
+       &setne  (&LB("eax"));
+       &or     ("ebp","eax");          # 0 indicates Intel CPU
+       &jz     (&label("intel"));
+
+       &cmp    ("ebx",0x68747541);     # "Auth"
+       &setne  (&LB("eax"));
+       &mov    ("esi","eax");
+       &cmp    ("edx",0x69746E65);     # "enti"
+       &setne  (&LB("eax"));
+       &or     ("esi","eax");
+       &cmp    ("ecx",0x444D4163);     # "cAMD"
+       &setne  (&LB("eax"));
+       &or     ("esi","eax");          # 0 indicates AMD CPU
+       &jnz    (&label("intel"));
+
+       # AMD specific
+       &mov    ("eax",0x80000000);
+       &cpuid  ();
+       &cmp    ("eax",0x80000008);
+       &jb     (&label("intel"));
+
+       &mov    ("eax",0x80000008);
+       &cpuid  ();
+       &movz   ("esi",&LB("ecx"));     # number of cores - 1
+       &inc    ("esi");                # number of cores
+
+       &mov    ("eax",1);
+       &cpuid  ();
+       &bt     ("edx",28);
+       &jnc    (&label("done"));
+       &shr    ("ebx",16);
+       &and    ("ebx",0xff);
+       &cmp    ("ebx","esi");
+       &ja     (&label("done"));
+       &and    ("edx",0xefffffff);     # clear hyper-threading bit
+       &jmp    (&label("done"));
+       
+&set_label("intel");
+       &cmp    ("edi",4);
+       &mov    ("edi",-1);
+       &jb     (&label("nocacheinfo"));
+
+       &mov    ("eax",4);
+       &mov    ("ecx",0);              # query L1D
+       &cpuid  ();
+       &mov    ("edi","eax");
+       &shr    ("edi",14);
+       &and    ("edi",0xfff);          # number of cores -1 per L1D
+
+&set_label("nocacheinfo");
        &mov    ("eax",1);
        &cpuid  ();
        &cmp    ("ebp",0);
        &jne    (&label("notP4"));
-       &and    ("eax",15<<8);          # familiy ID
-       &cmp    ("eax",15<<8);          # P4?
+       &and    (&HB("eax"),15);        # familiy ID
+       &cmp    (&HB("eax"),15);        # P4?
        &jne    (&label("notP4"));
        &or     ("edx",1<<20);          # use reserved bit to engage RC4_CHAR
 &set_label("notP4");
        &bt     ("edx",28);             # test hyper-threading bit
        &jnc    (&label("done"));
+       &and    ("edx",0xefffffff);
+       &cmp    ("edi",0);
+       &je     (&label("done"));
+
+       &or     ("edx",0x10000000);
        &shr    ("ebx",16);
-       &and    ("ebx",0xff);
-       &cmp    ("ebx",1);              # see if cache is shared(*)
+       &cmp    (&LB("ebx"),1);
        &ja     (&label("done"));
        &and    ("edx",0xefffffff);     # clear hyper-threading bit if not
 &set_label("done");
        &mov    ("eax","edx");
        &mov    ("edx","ecx");
 &function_end("OPENSSL_ia32_cpuid");
-# (*)  on Core2 this value is set to 2 denoting the fact that L2
-#      cache is shared between cores.
 
 &external_label("OPENSSL_ia32cap_P");
 
@@ -220,6 +273,40 @@ for (@ARGV) { $sse2=1 if (/-DOPENSSL_IA32_SSE2/); }
        }
 &function_end_B("OPENSSL_indirect_call");
 
+&function_begin_B("OPENSSL_cleanse");
+       &mov    ("edx",&wparam(0));
+       &mov    ("ecx",&wparam(1));
+       &xor    ("eax","eax");
+       &cmp    ("ecx",7);
+       &jae    (&label("lot"));
+       &cmp    ("ecx",0);
+       &je     (&label("ret"));
+&set_label("little");
+       &mov    (&BP(0,"edx"),"al");
+       &sub    ("ecx",1);
+       &lea    ("edx",&DWP(1,"edx"));
+       &jnz    (&label("little"));
+&set_label("ret");
+       &ret    ();
+
+&set_label("lot",16);
+       &test   ("edx",3);
+       &jz     (&label("aligned"));
+       &mov    (&BP(0,"edx"),"al");
+       &lea    ("ecx",&DWP(-1,"ecx"));
+       &lea    ("edx",&DWP(1,"edx"));
+       &jmp    (&label("lot"));
+&set_label("aligned");
+       &mov    (&DWP(0,"edx"),"eax");
+       &lea    ("ecx",&DWP(-4,"ecx"));
+       &test   ("ecx",-4);
+       &lea    ("edx",&DWP(4,"edx"));
+       &jnz    (&label("aligned"));
+       &cmp    ("ecx",0);
+       &jne    (&label("little"));
+       &ret    ();
+&function_end_B("OPENSSL_cleanse");
+
 &initseg("OPENSSL_cpuid_setup");
 
 &asm_finish();
diff --git a/deps/openssl/openssl/demos/cms/cacert.pem b/deps/openssl/openssl/demos/cms/cacert.pem
new file mode 100644 (file)
index 0000000..75cbb34
--- /dev/null
@@ -0,0 +1,18 @@
+-----BEGIN CERTIFICATE-----
+MIIC6DCCAlGgAwIBAgIJAMfGO3rdo2uUMA0GCSqGSIb3DQEBBAUAMFcxCzAJBgNV
+BAYTAlVLMRIwEAYDVQQHEwlUZXN0IENpdHkxFjAUBgNVBAoTDU9wZW5TU0wgR3Jv
+dXAxHDAaBgNVBAMTE1Rlc3QgUy9NSU1FIFJvb3QgQ0EwHhcNMDcwNDEzMTc0MzE3
+WhcNMTcwNDEwMTc0MzE3WjBXMQswCQYDVQQGEwJVSzESMBAGA1UEBxMJVGVzdCBD
+aXR5MRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMRwwGgYDVQQDExNUZXN0IFMvTUlN
+RSBSb290IENBMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqJMal1uC1/1wz
+i5+dE4EZF2im3BgROm5PVMbwPY9V1t+KYvtdc3rMcRgJaMbP+qaEcDXoIsZfYXGR
+ielgfDNZmZcj1y/FOum+Jc2OZMs3ggPmjIQ3dbBECq0hZKcbz7wfr+2OeNWm46iT
+jcSIXpGIRhUYEzOgv7zb8oOU70IbbwIDAQABo4G7MIG4MB0GA1UdDgQWBBRHUypx
+CXFQYqewhGo72lWPQUsjoDCBiAYDVR0jBIGAMH6AFEdTKnEJcVBip7CEajvaVY9B
+SyOgoVukWTBXMQswCQYDVQQGEwJVSzESMBAGA1UEBxMJVGVzdCBDaXR5MRYwFAYD
+VQQKEw1PcGVuU1NMIEdyb3VwMRwwGgYDVQQDExNUZXN0IFMvTUlNRSBSb290IENB
+ggkAx8Y7et2ja5QwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQQFAAOBgQANI+Yc
+G/YDM1WMUGEzEkU9UhsIUqdyBebnK3+OyxZSouDcE/M10jFJzBf/F5b0uUGAKWwo
+u0dzmILfKjdfWe8EyCRafZcm00rVcO09i/63FBYzlHbmfUATIqZdhKzxxQMPs5mF
+1je+pHUpzIY8TSXyh/uD9IkAy04IHwGZQf9akw==
+-----END CERTIFICATE-----
diff --git a/deps/openssl/openssl/demos/cms/cakey.pem b/deps/openssl/openssl/demos/cms/cakey.pem
new file mode 100644 (file)
index 0000000..3b53c5e
--- /dev/null
@@ -0,0 +1,15 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICXgIBAAKBgQCqJMal1uC1/1wzi5+dE4EZF2im3BgROm5PVMbwPY9V1t+KYvtd
+c3rMcRgJaMbP+qaEcDXoIsZfYXGRielgfDNZmZcj1y/FOum+Jc2OZMs3ggPmjIQ3
+dbBECq0hZKcbz7wfr+2OeNWm46iTjcSIXpGIRhUYEzOgv7zb8oOU70IbbwIDAQAB
+AoGBAKWOZ2UTc1BkjDjz0XoscmAR8Rj77MdGzfOPkIxPultSW+3yZpkGNyUbnsH5
+HAtf4Avai/m3bMN+s91kDpx9/g/I9ZEHPQLcDICETvwt/EHT7+hwvaQgsM+TgpMs
+tjlGZOWent6wVIuvwwzqOMXZLgK9FvY7upwgtrys4G3Kab5hAkEA2QzFflWyEvKS
+rMSaVtn/IjFilwa7H0IdakkjM34z4peerFTPBr4J47YD4RCR/dAvxyNy3zUxtH18
+9R6dUixI6QJBAMitJD0xOkbGWBX8KVJvRiKOIdf/95ZUAgN/h3bWKy57EB9NYj3u
+jbxXcvdjfSqiITykkjAg7SG7nrlzJsu6CpcCQG6gVsy0auXDY0TRlASuaZ6I40Is
+uRUOgqWYj2uAaHuWYdZeB4LdO3cnX0TISFDAWom6JKNlnmbrCtR4fSDT13kCQQCU
++VQJyV3F5MDHsWbLt6eNR46AV5lpk/vatPXPlrZ/zwPs+PmRmGLICvNiDA2DdNDP
+wCx2Zjsj67CtY3rNitMJAkEAm09BQnjnbBXUb1rd2SjNDWTsu80Z+zLu8pAwXNhW
+8nsvMYqlYMIxuMPwu/QuTnMRhMZ08uhqoD3ukZnBeoMEVg==
+-----END RSA PRIVATE KEY-----
diff --git a/deps/openssl/openssl/demos/cms/cms_comp.c b/deps/openssl/openssl/demos/cms/cms_comp.c
new file mode 100644 (file)
index 0000000..b7943e8
--- /dev/null
@@ -0,0 +1,61 @@
+/* Simple S/MIME compress example */
+#include <openssl/pem.h>
+#include <openssl/cms.h>
+#include <openssl/err.h>
+
+int main(int argc, char **argv)
+       {
+       BIO *in = NULL, *out = NULL;
+       CMS_ContentInfo *cms = NULL;
+       int ret = 1;
+
+       /*
+        * On OpenSSL 0.9.9 only:
+        * for streaming set CMS_STREAM
+        */
+       int flags = CMS_STREAM;
+
+       OpenSSL_add_all_algorithms();
+       ERR_load_crypto_strings();
+
+       /* Open content being compressed */
+
+       in = BIO_new_file("comp.txt", "r");
+
+       if (!in)
+               goto err;
+
+       /* compress content */
+       cms = CMS_compress(in, NID_zlib_compression, flags);
+
+       if (!cms)
+               goto err;
+
+       out = BIO_new_file("smcomp.txt", "w");
+       if (!out)
+               goto err;
+
+       /* Write out S/MIME message */
+       if (!SMIME_write_CMS(out, cms, in, flags))
+               goto err;
+
+       ret = 0;
+
+       err:
+
+       if (ret)
+               {
+               fprintf(stderr, "Error Compressing Data\n");
+               ERR_print_errors_fp(stderr);
+               }
+
+       if (cms)
+               CMS_ContentInfo_free(cms);
+       if (in)
+               BIO_free(in);
+       if (out)
+               BIO_free(out);
+
+       return ret;
+
+       }
diff --git a/deps/openssl/openssl/demos/cms/cms_ddec.c b/deps/openssl/openssl/demos/cms/cms_ddec.c
new file mode 100644 (file)
index 0000000..ba68cfd
--- /dev/null
@@ -0,0 +1,89 @@
+/* S/MIME detached data decrypt example: rarely done but
+ * should the need arise this is an example....
+ */
+#include <openssl/pem.h>
+#include <openssl/cms.h>
+#include <openssl/err.h>
+
+int main(int argc, char **argv)
+       {
+       BIO *in = NULL, *out = NULL, *tbio = NULL, *dcont = NULL;
+       X509 *rcert = NULL;
+       EVP_PKEY *rkey = NULL;
+       CMS_ContentInfo *cms = NULL;
+       int ret = 1;
+
+       OpenSSL_add_all_algorithms();
+       ERR_load_crypto_strings();
+
+       /* Read in recipient certificate and private key */
+       tbio = BIO_new_file("signer.pem", "r");
+
+       if (!tbio)
+               goto err;
+
+       rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+
+       BIO_reset(tbio);
+
+       rkey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
+
+       if (!rcert || !rkey)
+               goto err;
+
+       /* Open PEM file containing enveloped data */
+
+       in = BIO_new_file("smencr.pem", "r");
+
+       if (!in)
+               goto err;
+
+       /* Parse PEM content */
+       cms = PEM_read_bio_CMS(in, NULL, 0, NULL);
+
+       if (!cms)
+               goto err;
+
+       /* Open file containing detached content */
+       dcont = BIO_new_file("smencr.out", "rb");
+
+       if (!in)
+               goto err;
+
+       out = BIO_new_file("encrout.txt", "w");
+       if (!out)
+               goto err;
+
+       /* Decrypt S/MIME message */
+       if (!CMS_decrypt(cms, rkey, rcert, dcont, out, 0))
+               goto err;
+
+       ret = 0;
+
+       err:
+
+       if (ret)
+               {
+               fprintf(stderr, "Error Decrypting Data\n");
+               ERR_print_errors_fp(stderr);
+               }
+
+       if (cms)
+               CMS_ContentInfo_free(cms);
+       if (rcert)
+               X509_free(rcert);
+       if (rkey)
+               EVP_PKEY_free(rkey);
+
+       if (in)
+               BIO_free(in);
+       if (out)
+               BIO_free(out);
+       if (tbio)
+               BIO_free(tbio);
+       if (dcont)
+               BIO_free(dcont);
+
+       return ret;
+
+       }
diff --git a/deps/openssl/openssl/demos/cms/cms_dec.c b/deps/openssl/openssl/demos/cms/cms_dec.c
new file mode 100644 (file)
index 0000000..7ddf653
--- /dev/null
@@ -0,0 +1,79 @@
+/* Simple S/MIME decryption example */
+#include <openssl/pem.h>
+#include <openssl/cms.h>
+#include <openssl/err.h>
+
+int main(int argc, char **argv)
+       {
+       BIO *in = NULL, *out = NULL, *tbio = NULL;
+       X509 *rcert = NULL;
+       EVP_PKEY *rkey = NULL;
+       CMS_ContentInfo *cms = NULL;
+       int ret = 1;
+
+       OpenSSL_add_all_algorithms();
+       ERR_load_crypto_strings();
+
+       /* Read in recipient certificate and private key */
+       tbio = BIO_new_file("signer.pem", "r");
+
+       if (!tbio)
+               goto err;
+
+       rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+
+       BIO_reset(tbio);
+
+       rkey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
+
+       if (!rcert || !rkey)
+               goto err;
+
+       /* Open S/MIME message to decrypt */
+
+       in = BIO_new_file("smencr.txt", "r");
+
+       if (!in)
+               goto err;
+
+       /* Parse message */
+       cms = SMIME_read_CMS(in, NULL);
+
+       if (!cms)
+               goto err;
+
+       out = BIO_new_file("decout.txt", "w");
+       if (!out)
+               goto err;
+
+       /* Decrypt S/MIME message */
+       if (!CMS_decrypt(cms, rkey, rcert, out, NULL, 0))
+               goto err;
+
+       ret = 0;
+
+       err:
+
+       if (ret)
+               {
+               fprintf(stderr, "Error Decrypting Data\n");
+               ERR_print_errors_fp(stderr);
+               }
+
+       if (cms)
+               CMS_ContentInfo_free(cms);
+       if (rcert)
+               X509_free(rcert);
+       if (rkey)
+               EVP_PKEY_free(rkey);
+
+       if (in)
+               BIO_free(in);
+       if (out)
+               BIO_free(out);
+       if (tbio)
+               BIO_free(tbio);
+
+       return ret;
+
+       }
diff --git a/deps/openssl/openssl/demos/cms/cms_denc.c b/deps/openssl/openssl/demos/cms/cms_denc.c
new file mode 100644 (file)
index 0000000..9265e47
--- /dev/null
@@ -0,0 +1,97 @@
+/* S/MIME detached data encrypt example: rarely done but
+ * should the need arise this is an example....
+ */
+#include <openssl/pem.h>
+#include <openssl/cms.h>
+#include <openssl/err.h>
+
+int main(int argc, char **argv)
+       {
+       BIO *in = NULL, *out = NULL, *tbio = NULL, *dout = NULL;
+       X509 *rcert = NULL;
+       STACK_OF(X509) *recips = NULL;
+       CMS_ContentInfo *cms = NULL;
+       int ret = 1;
+
+       int flags = CMS_STREAM|CMS_DETACHED;
+
+       OpenSSL_add_all_algorithms();
+       ERR_load_crypto_strings();
+
+       /* Read in recipient certificate */
+       tbio = BIO_new_file("signer.pem", "r");
+
+       if (!tbio)
+               goto err;
+
+       rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+
+       if (!rcert)
+               goto err;
+
+       /* Create recipient STACK and add recipient cert to it */
+       recips = sk_X509_new_null();
+
+       if (!recips || !sk_X509_push(recips, rcert))
+               goto err;
+
+       /* sk_X509_pop_free will free up recipient STACK and its contents
+        * so set rcert to NULL so it isn't freed up twice.
+        */
+       rcert = NULL;
+
+       /* Open content being encrypted */
+
+       in = BIO_new_file("encr.txt", "r");
+
+       dout = BIO_new_file("smencr.out", "wb");
+
+       if (!in)
+               goto err;
+
+       /* encrypt content */
+       cms = CMS_encrypt(recips, in, EVP_des_ede3_cbc(), flags);
+
+       if (!cms)
+               goto err;
+
+       out = BIO_new_file("smencr.pem", "w");
+       if (!out)
+               goto err;
+
+       if (!CMS_final(cms, in, dout, flags))
+               goto err;
+
+       /* Write out CMS structure without content */
+       if (!PEM_write_bio_CMS(out, cms))
+               goto err;
+
+       ret = 0;
+
+       err:
+
+       if (ret)
+               {
+               fprintf(stderr, "Error Encrypting Data\n");
+               ERR_print_errors_fp(stderr);
+               }
+
+       if (cms)
+               CMS_ContentInfo_free(cms);
+       if (rcert)
+               X509_free(rcert);
+       if (recips)
+               sk_X509_pop_free(recips, X509_free);
+
+       if (in)
+               BIO_free(in);
+       if (out)
+               BIO_free(out);
+       if (dout)
+               BIO_free(dout);
+       if (tbio)
+               BIO_free(tbio);
+
+       return ret;
+
+       }
diff --git a/deps/openssl/openssl/demos/cms/cms_enc.c b/deps/openssl/openssl/demos/cms/cms_enc.c
new file mode 100644 (file)
index 0000000..916b479
--- /dev/null
@@ -0,0 +1,92 @@
+/* Simple S/MIME encrypt example */
+#include <openssl/pem.h>
+#include <openssl/cms.h>
+#include <openssl/err.h>
+
+int main(int argc, char **argv)
+       {
+       BIO *in = NULL, *out = NULL, *tbio = NULL;
+       X509 *rcert = NULL;
+       STACK_OF(X509) *recips = NULL;
+       CMS_ContentInfo *cms = NULL;
+       int ret = 1;
+
+       /*
+        * On OpenSSL 1.0.0 and later only:
+        * for streaming set CMS_STREAM
+        */
+       int flags = CMS_STREAM;
+
+       OpenSSL_add_all_algorithms();
+       ERR_load_crypto_strings();
+
+       /* Read in recipient certificate */
+       tbio = BIO_new_file("signer.pem", "r");
+
+       if (!tbio)
+               goto err;
+
+       rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+
+       if (!rcert)
+               goto err;
+
+       /* Create recipient STACK and add recipient cert to it */
+       recips = sk_X509_new_null();
+
+       if (!recips || !sk_X509_push(recips, rcert))
+               goto err;
+
+       /* sk_X509_pop_free will free up recipient STACK and its contents
+        * so set rcert to NULL so it isn't freed up twice.
+        */
+       rcert = NULL;
+
+       /* Open content being encrypted */
+
+       in = BIO_new_file("encr.txt", "r");
+
+       if (!in)
+               goto err;
+
+       /* encrypt content */
+       cms = CMS_encrypt(recips, in, EVP_des_ede3_cbc(), flags);
+
+       if (!cms)
+               goto err;
+
+       out = BIO_new_file("smencr.txt", "w");
+       if (!out)
+               goto err;
+
+       /* Write out S/MIME message */
+       if (!SMIME_write_CMS(out, cms, in, flags))
+               goto err;
+
+       ret = 0;
+
+       err:
+
+       if (ret)
+               {
+               fprintf(stderr, "Error Encrypting Data\n");
+               ERR_print_errors_fp(stderr);
+               }
+
+       if (cms)
+               CMS_ContentInfo_free(cms);
+       if (rcert)
+               X509_free(rcert);
+       if (recips)
+               sk_X509_pop_free(recips, X509_free);
+
+       if (in)
+               BIO_free(in);
+       if (out)
+               BIO_free(out);
+       if (tbio)
+               BIO_free(tbio);
+
+       return ret;
+
+       }
diff --git a/deps/openssl/openssl/demos/cms/cms_sign.c b/deps/openssl/openssl/demos/cms/cms_sign.c
new file mode 100644 (file)
index 0000000..42f7620
--- /dev/null
@@ -0,0 +1,89 @@
+/* Simple S/MIME signing example */
+#include <openssl/pem.h>
+#include <openssl/cms.h>
+#include <openssl/err.h>
+
+int main(int argc, char **argv)
+       {
+       BIO *in = NULL, *out = NULL, *tbio = NULL;
+       X509 *scert = NULL;
+       EVP_PKEY *skey = NULL;
+       CMS_ContentInfo *cms = NULL;
+       int ret = 1;
+
+       /* For simple S/MIME signing use CMS_DETACHED.
+        * On OpenSSL 0.9.9 only:
+        * for streaming detached set CMS_DETACHED|CMS_STREAM
+        * for streaming non-detached set CMS_STREAM
+        */
+       int flags = CMS_DETACHED|CMS_STREAM;
+
+       OpenSSL_add_all_algorithms();
+       ERR_load_crypto_strings();
+
+       /* Read in signer certificate and private key */
+       tbio = BIO_new_file("signer.pem", "r");
+
+       if (!tbio)
+               goto err;
+
+       scert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+
+       BIO_reset(tbio);
+
+       skey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
+
+       if (!scert || !skey)
+               goto err;
+
+       /* Open content being signed */
+
+       in = BIO_new_file("sign.txt", "r");
+
+       if (!in)
+               goto err;
+
+       /* Sign content */
+       cms = CMS_sign(scert, skey, NULL, in, flags);
+
+       if (!cms)
+               goto err;
+
+       out = BIO_new_file("smout.txt", "w");
+       if (!out)
+               goto err;
+
+       if (!(flags & CMS_STREAM))
+               BIO_reset(in);
+
+       /* Write out S/MIME message */
+       if (!SMIME_write_CMS(out, cms, in, flags))
+               goto err;
+
+       ret = 0;
+
+       err:
+
+       if (ret)
+               {
+               fprintf(stderr, "Error Signing Data\n");
+               ERR_print_errors_fp(stderr);
+               }
+
+       if (cms)
+               CMS_ContentInfo_free(cms);
+       if (scert)
+               X509_free(scert);
+       if (skey)
+               EVP_PKEY_free(skey);
+
+       if (in)
+               BIO_free(in);
+       if (out)
+               BIO_free(out);
+       if (tbio)
+               BIO_free(tbio);
+
+       return ret;
+
+       }
diff --git a/deps/openssl/openssl/demos/cms/cms_sign2.c b/deps/openssl/openssl/demos/cms/cms_sign2.c
new file mode 100644 (file)
index 0000000..36adee7
--- /dev/null
@@ -0,0 +1,103 @@
+/* S/MIME signing example: 2 signers */
+#include <openssl/pem.h>
+#include <openssl/cms.h>
+#include <openssl/err.h>
+
+int main(int argc, char **argv)
+       {
+       BIO *in = NULL, *out = NULL, *tbio = NULL;
+       X509 *scert = NULL, *scert2 = NULL;
+       EVP_PKEY *skey = NULL, *skey2 = NULL;
+       CMS_ContentInfo *cms = NULL;
+       int ret = 1;
+
+       OpenSSL_add_all_algorithms();
+       ERR_load_crypto_strings();
+
+       tbio = BIO_new_file("signer.pem", "r");
+
+       if (!tbio)
+               goto err;
+
+       scert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+
+       BIO_reset(tbio);
+
+       skey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
+
+       BIO_free(tbio);
+
+       tbio = BIO_new_file("signer2.pem", "r");
+
+       if (!tbio)
+               goto err;
+
+       scert2 = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+
+       BIO_reset(tbio);
+
+       skey2 = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
+
+       if (!scert2 || !skey2)
+               goto err;
+
+       in = BIO_new_file("sign.txt", "r");
+
+       if (!in)
+               goto err;
+
+       cms = CMS_sign(NULL, NULL, NULL, in, CMS_STREAM|CMS_PARTIAL);
+
+       if (!cms)
+               goto err;
+
+       /* Add each signer in turn */
+
+       if (!CMS_add1_signer(cms, scert, skey, NULL, 0))
+               goto err;
+
+       if (!CMS_add1_signer(cms, scert2, skey2, NULL, 0))
+               goto err;
+
+       out = BIO_new_file("smout.txt", "w");
+       if (!out)
+               goto err;
+
+       /* NB: content included and finalized by SMIME_write_CMS */
+
+       if (!SMIME_write_CMS(out, cms, in, CMS_STREAM))
+               goto err;
+
+       ret = 0;
+
+       err:
+
+       if (ret)
+               {
+               fprintf(stderr, "Error Signing Data\n");
+               ERR_print_errors_fp(stderr);
+               }
+
+       if (cms)
+               CMS_ContentInfo_free(cms);
+
+       if (scert)
+               X509_free(scert);
+       if (skey)
+               EVP_PKEY_free(skey);
+
+       if (scert2)
+               X509_free(scert2);
+       if (skey)
+               EVP_PKEY_free(skey2);
+
+       if (in)
+               BIO_free(in);
+       if (out)
+               BIO_free(out);
+       if (tbio)
+               BIO_free(tbio);
+
+       return ret;
+
+       }
diff --git a/deps/openssl/openssl/demos/cms/cms_uncomp.c b/deps/openssl/openssl/demos/cms/cms_uncomp.c
new file mode 100644 (file)
index 0000000..f15ae2f
--- /dev/null
@@ -0,0 +1,56 @@
+/* Simple S/MIME uncompression example */
+#include <openssl/pem.h>
+#include <openssl/cms.h>
+#include <openssl/err.h>
+
+int main(int argc, char **argv)
+       {
+       BIO *in = NULL, *out = NULL;
+       CMS_ContentInfo *cms = NULL;
+       int ret = 1;
+
+       OpenSSL_add_all_algorithms();
+       ERR_load_crypto_strings();
+
+       /* Open compressed content */
+
+       in = BIO_new_file("smcomp.txt", "r");
+
+       if (!in)
+               goto err;
+
+       /* Sign content */
+       cms = SMIME_read_CMS(in, NULL);
+
+       if (!cms)
+               goto err;
+
+       out = BIO_new_file("smuncomp.txt", "w");
+       if (!out)
+               goto err;
+
+       /* Uncompress S/MIME message */
+       if (!CMS_uncompress(cms, out, NULL, 0))
+               goto err;
+
+       ret = 0;
+
+       err:
+
+       if (ret)
+               {
+               fprintf(stderr, "Error Uncompressing Data\n");
+               ERR_print_errors_fp(stderr);
+               }
+
+       if (cms)
+               CMS_ContentInfo_free(cms);
+
+       if (in)
+               BIO_free(in);
+       if (out)
+               BIO_free(out);
+
+       return ret;
+
+       }
diff --git a/deps/openssl/openssl/demos/cms/cms_ver.c b/deps/openssl/openssl/demos/cms/cms_ver.c
new file mode 100644 (file)
index 0000000..bf1145e
--- /dev/null
@@ -0,0 +1,87 @@
+/* Simple S/MIME verification example */
+#include <openssl/pem.h>
+#include <openssl/cms.h>
+#include <openssl/err.h>
+
+int main(int argc, char **argv)
+       {
+       BIO *in = NULL, *out = NULL, *tbio = NULL, *cont = NULL;
+       X509_STORE *st = NULL;
+       X509 *cacert = NULL;
+       CMS_ContentInfo *cms = NULL;
+
+       int ret = 1;
+
+       OpenSSL_add_all_algorithms();
+       ERR_load_crypto_strings();
+
+       /* Set up trusted CA certificate store */
+
+       st = X509_STORE_new();
+
+       /* Read in CA certificate */
+       tbio = BIO_new_file("cacert.pem", "r");
+
+       if (!tbio)
+               goto err;
+
+       cacert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+
+       if (!cacert)
+               goto err;
+
+       if (!X509_STORE_add_cert(st, cacert))
+               goto err;
+
+       /* Open message being verified */
+
+       in = BIO_new_file("smout.txt", "r");
+
+       if (!in)
+               goto err;
+
+       /* parse message */
+       cms = SMIME_read_CMS(in, &cont);
+
+       if (!cms)
+               goto err;
+
+       /* File to output verified content to */
+       out = BIO_new_file("smver.txt", "w");
+       if (!out)
+               goto err;
+
+       if (!CMS_verify(cms, NULL, st, cont, out, 0))
+               {
+               fprintf(stderr, "Verification Failure\n");
+               goto err;
+               }
+
+       fprintf(stderr, "Verification Successful\n");
+
+       ret = 0;
+
+       err:
+
+       if (ret)
+               {
+               fprintf(stderr, "Error Verifying Data\n");
+               ERR_print_errors_fp(stderr);
+               }
+
+       if (cms)
+               CMS_ContentInfo_free(cms);
+
+       if (cacert)
+               X509_free(cacert);
+
+       if (in)
+               BIO_free(in);
+       if (out)
+               BIO_free(out);
+       if (tbio)
+               BIO_free(tbio);
+
+       return ret;
+
+       }
diff --git a/deps/openssl/openssl/demos/cms/comp.txt b/deps/openssl/openssl/demos/cms/comp.txt
new file mode 100644 (file)
index 0000000..1672328
--- /dev/null
@@ -0,0 +1,22 @@
+Content-type: text/plain
+
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
diff --git a/deps/openssl/openssl/demos/cms/encr.txt b/deps/openssl/openssl/demos/cms/encr.txt
new file mode 100644 (file)
index 0000000..0eceb40
--- /dev/null
@@ -0,0 +1,3 @@
+Content-type: text/plain
+
+Sample OpenSSL Data for CMS encryption
diff --git a/deps/openssl/openssl/demos/cms/sign.txt b/deps/openssl/openssl/demos/cms/sign.txt
new file mode 100644 (file)
index 0000000..c3f9d73
--- /dev/null
@@ -0,0 +1,3 @@
+Content-type: text/plain
+
+Test OpenSSL CMS Signed Content
diff --git a/deps/openssl/openssl/demos/cms/signer.pem b/deps/openssl/openssl/demos/cms/signer.pem
new file mode 100644 (file)
index 0000000..bac16ba
--- /dev/null
@@ -0,0 +1,32 @@
+-----BEGIN CERTIFICATE-----
+MIICpjCCAg+gAwIBAgIJAJ+rfmEoLQRhMA0GCSqGSIb3DQEBBAUAMFcxCzAJBgNV
+BAYTAlVLMRIwEAYDVQQHEwlUZXN0IENpdHkxFjAUBgNVBAoTDU9wZW5TU0wgR3Jv
+dXAxHDAaBgNVBAMTE1Rlc3QgUy9NSU1FIFJvb3QgQ0EwHhcNMDcwNDEzMTgyOTI3
+WhcNMTcwNDA5MTgyOTI3WjBWMQswCQYDVQQGEwJVSzElMCMGA1UEAxMcT3BlblNT
+TCB0ZXN0IFMvTUlNRSBzaWduZXIgMTEgMB4GCSqGSIb3DQEJARYRdGVzdDFAb3Bl
+bnNzbC5vcmcwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAL1ocAQ7ON2pIUXz
+jwKPzpPB9ozB6PFG6F6kARO+i0DiT6Qn8abUjwpHPU+lGys83QlpbkQVUD6Fv/4L
+ytihk6N9Pr/feECVcSZ20dI43WXjfYak14dSVrZkGNMMXqKmnnqtkAdD0oJN7A7y
+gcf8RuViV0kvk9/36eCMwMHrImfhAgMBAAGjezB5MAkGA1UdEwQCMAAwLAYJYIZI
+AYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENlcnRpZmljYXRlMB0GA1UdDgQW
+BBSyKqjvctIsFNBHULBTqr8SHtSxpDAfBgNVHSMEGDAWgBRHUypxCXFQYqewhGo7
+2lWPQUsjoDANBgkqhkiG9w0BAQQFAAOBgQBvdYVoBfd4RV/xWSMXIcgw/i5OiwyX
+MsenQePll51MpglfArd7pUipUalCqlJt/Gs8kD16Ih1z1yuWYVTMlnDZ0PwbIOYn
++Jr8XLF9b1SMJt6PwckZZ0LZdIi2KwGAxVsIW1kjJAqu9o4YH37XW37yYdQRxfvv
+lDiQlgX0JtmLgA==
+-----END CERTIFICATE-----
+-----BEGIN RSA PRIVATE KEY-----
+MIICXAIBAAKBgQC9aHAEOzjdqSFF848Cj86TwfaMwejxRuhepAETvotA4k+kJ/Gm
+1I8KRz1PpRsrPN0JaW5EFVA+hb/+C8rYoZOjfT6/33hAlXEmdtHSON1l432GpNeH
+Ula2ZBjTDF6ipp56rZAHQ9KCTewO8oHH/EblYldJL5Pf9+ngjMDB6yJn4QIDAQAB
+AoGACCuYIWaYll80UzslYRvo8lC8nOfEb5v6bBKxBTQD98GLY+5hKywiG3RlPalG
+mb/fXQeSPReaRYgpdwD1OBEIOEMW9kLyqpzokC0xjpZ+MwsuJTlxCesk5GEsMa3o
+wC3QMmiRA7qrZ/SzTtwrs++9mZ/pxp8JZ6pKYUj8SE7/vV0CQQDz8Ix2t40E16hx
+04+XhClnGqydZJyLLSxcTU3ZVhYxL+efo/5hZ8tKpkcDi8wq6T03BOKrKxrlIW55
+qDRNM24rAkEAxsWzu/rJhIouQyNoYygEIEYzFRlTQyZSg59u6dNiewMn27dOAbyc
+YT7B6da7e74QttTXo0lIllsX2S38+XsIIwJBANSRuIU3G66tkr5l4gnhhAaxqtuY
+sgVhvvdL8dvC9aG1Ifzt9hzBSthpHxbK+oYmK07HdhI8hLpIMLHYzoK7n3MCQEy4
+4rccBcxyyYiAkjozp+QNNIpgTBMPJ6pGT7lRLiHtBeV4y1NASdv/LTnk+Fi69Bid
+7t3H24ytfHcHmS1yn6ECQF6Jmh4C7dlvp59zXp+t+VsXxa/8sq41vKNIj0Rx9vh5
+xp9XL0C5ZpgmBnsTydP9pmkiL4ltLbMX0wJU6N2cmFw=
+-----END RSA PRIVATE KEY-----
diff --git a/deps/openssl/openssl/demos/cms/signer2.pem b/deps/openssl/openssl/demos/cms/signer2.pem
new file mode 100644 (file)
index 0000000..25e23d1
--- /dev/null
@@ -0,0 +1,32 @@
+-----BEGIN CERTIFICATE-----
+MIICpjCCAg+gAwIBAgIJAJ+rfmEoLQRiMA0GCSqGSIb3DQEBBAUAMFcxCzAJBgNV
+BAYTAlVLMRIwEAYDVQQHEwlUZXN0IENpdHkxFjAUBgNVBAoTDU9wZW5TU0wgR3Jv
+dXAxHDAaBgNVBAMTE1Rlc3QgUy9NSU1FIFJvb3QgQ0EwHhcNMDcwNDEzMTgyOTQ0
+WhcNMTcwNDA5MTgyOTQ0WjBWMQswCQYDVQQGEwJVSzElMCMGA1UEAxMcT3BlblNT
+TCB0ZXN0IFMvTUlNRSBzaWduZXIgMjEgMB4GCSqGSIb3DQEJARYRdGVzdDJAb3Bl
+bnNzbC5vcmcwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANco7VPgX9vcGwmZ
+jYqjq1JiR7M38dsMNhuJyLRVjJ5/cpFluQydQuG1PhzOJ8zfYVFicOXKvbYuKuXW
+ozZIwzqEqWsNf36KHTLS6yOMG8I13cRInh+fAIKq9Z8Eh65I7FJzVsNsfEQrGfEW
+GMA8us24IaSvP3QkbfHJn/4RaKznAgMBAAGjezB5MAkGA1UdEwQCMAAwLAYJYIZI
+AYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENlcnRpZmljYXRlMB0GA1UdDgQW
+BBRlrLQJUB8uAa4q8B2OqvvTXonF5zAfBgNVHSMEGDAWgBRHUypxCXFQYqewhGo7
+2lWPQUsjoDANBgkqhkiG9w0BAQQFAAOBgQBQbi2juGALg2k9m1hKpzR2lCGmGO3X
+h3Jh/l0vIxDr0RTgP2vBrtITlx655P/o1snoeTIpYG8uUnFnTE/6YakdayAIlxV4
+aZl63AivZMpQB5SPaPH/jEsGJ8UQMfdiy4ORWIULupuPKlKwODNw7tVhQIACS/DR
+2aX6rl2JEuJ5Yg==
+-----END CERTIFICATE-----
+-----BEGIN RSA PRIVATE KEY-----
+MIICXAIBAAKBgQDXKO1T4F/b3BsJmY2Ko6tSYkezN/HbDDYbici0VYyef3KRZbkM
+nULhtT4czifM32FRYnDlyr22Lirl1qM2SMM6hKlrDX9+ih0y0usjjBvCNd3ESJ4f
+nwCCqvWfBIeuSOxSc1bDbHxEKxnxFhjAPLrNuCGkrz90JG3xyZ/+EWis5wIDAQAB
+AoGAUTB2bcIrKfGimjrBOGGOUmYXnD8uGnQ/LqENhU8K4vxApTD3ZRUqmbUknQYF
+6r8YH/e/llasw8QkF9qod+F5GTgsnyh/aMidFHKrXXbf1662scz9+S6crSXq9Eb2
+CL57f6Kw61k6edrz8zHdA+rnTK00hzgzKCP4ZL5k8/55ueECQQD+BK+nsKi6CcKf
+m3Mh61Sf2Icm5JlMCKaihlbnh78lBN1imYUAfHJEnQ1ujxXB94R+6o9S+XrWTnTX
+2m/JNIfpAkEA2NaidX7Sv5jnRPkwJ02Srl0urxINLmg4bU0zmM3VoMklYBHWnMyr
+upPZGPh5TzCa+g6FTBmU8XK61wvnEKNcTwJBAM24VdnlBIDGbsx8RJ3vzLU30xz4
+ff5J80okqjUQhwkgC3tTAZgHMTPITZyAXQqdvrxakoCMc6MkHxTBX08AMCECQHHL
+SdyxXrYv7waSY0PtANJCkpJLveEhzqMFxdMmCjtj9BpTojYNbv3uQxtIopj9YAdk
+gW2ray++zvC2DV/86x8CQH4UJwgO6JqU4bSgi6HiRNjDg26tJ0Beu8jjl1vrkIVX
+pHFwSUeLZUsT2/iTUSgYH4uYiZPgYNcKTCT9W6se30A=
+-----END RSA PRIVATE KEY-----
diff --git a/deps/openssl/openssl/demos/jpake/Makefile b/deps/openssl/openssl/demos/jpake/Makefile
deleted file mode 100644 (file)
index 09b8f03..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-LDFLAGS=-L../.. -lcrypto
-CFLAGS=-I../../include -Wall -Werror -g
-
-all: jpakedemo
-
-jpakedemo: jpakedemo.o
-       $(CC) -g -o jpakedemo jpakedemo.o $(LDFLAGS)
diff --git a/deps/openssl/openssl/demos/jpake/jpakedemo.c b/deps/openssl/openssl/demos/jpake/jpakedemo.c
deleted file mode 100644 (file)
index 338a881..0000000
+++ /dev/null
@@ -1,469 +0,0 @@
-#include "openssl/bn.h"
-#include "openssl/sha.h"
-#include <assert.h>
-#include <string.h>
-#include <stdlib.h>
-
-/* Copyright (C) 2008 Ben Laurie (ben@links.org) */
-
-/*
- * Implement J-PAKE, as described in
- * http://grouper.ieee.org/groups/1363/Research/contributions/hao-ryan-2008.pdf
- * 
- * With hints from http://www.cl.cam.ac.uk/~fh240/software/JPAKE2.java.
- */
-
-static void showbn(const char *name, const BIGNUM *bn)
-    {
-    fputs(name, stdout);
-    fputs(" = ", stdout);
-    BN_print_fp(stdout, bn);
-    putc('\n', stdout);
-    }
-
-typedef struct
-    {
-    BN_CTX *ctx;  // Perhaps not the best place for this?
-    BIGNUM *p;
-    BIGNUM *q;
-    BIGNUM *g;
-    } JPakeParameters;
-
-static void JPakeParametersInit(JPakeParameters *params)
-    {
-    params->ctx = BN_CTX_new();
-
-    // For now use p, q, g from Java sample code. Later, generate them.
-    params->p = NULL;
-    BN_hex2bn(&params->p, "fd7f53811d75122952df4a9c2eece4e7f611b7523cef4400c31e3f80b6512669455d402251fb593d8d58fabfc5f5ba30f6cb9b556cd7813b801d346ff26660b76b9950a5a49f9fe8047b1022c24fbba9d7feb7c61bf83b57e7c6a8a6150f04fb83f6d3c51ec3023554135a169132f675f3ae2b61d72aeff22203199dd14801c7");
-    params->q = NULL;
-    BN_hex2bn(&params->q, "9760508f15230bccb292b982a2eb840bf0581cf5");
-    params->g = NULL;
-    BN_hex2bn(&params->g, "f7e1a085d69b3ddecbbcab5c36b857b97994afbbfa3aea82f9574c0b3d0782675159578ebad4594fe67107108180b449167123e84c281613b7cf09328cc8a6e13c167a8b547c8d28e0a3ae1e2bb3a675916ea37f0bfa213562f1fb627a01243bcca4f1bea8519089a883dfe15ae59f06928b665e807b552564014c3bfecf492a");
-
-    showbn("p", params->p);
-    showbn("q", params->q);
-    showbn("g", params->g);
-    }
-
-typedef struct
-    {
-    BIGNUM *gr;  // g^r (r random)
-    BIGNUM *b;   // b = r - x*h, h=hash(g, g^r, g^x, name)
-    } JPakeZKP;
-
-typedef struct
-    {
-    BIGNUM *gx;       // g^x
-    JPakeZKP zkpx;    // ZKP(x)
-    } JPakeStep1;
-
-typedef struct
-    {
-    BIGNUM *X;        // g^(xa + xc + xd) * xb * s
-    JPakeZKP zkpxbs;  // ZKP(xb * s)
-    } JPakeStep2;
-
-typedef struct
-    {
-    const char *name;  // Must be unique
-    int base;          // 1 for Alice, 3 for Bob. Only used for printing stuff.
-    JPakeStep1 s1c;    // Alice's g^x3, ZKP(x3) or Bob's g^x1, ZKP(x1)
-    JPakeStep1 s1d;    // Alice's g^x4, ZKP(x4) or Bob's g^x2, ZKP(x2)
-    JPakeStep2 s2;     // Alice's A, ZKP(x2 * s) or Bob's B, ZKP(x4 * s)
-    } JPakeUserPublic;
-
-/*
- * The user structure. In the definition, (xa, xb, xc, xd) are Alice's
- * (x1, x2, x3, x4) or Bob's (x3, x4, x1, x2). If you see what I mean.
- */
-typedef struct
-    {
-    JPakeUserPublic p;
-    BIGNUM *secret;    // The shared secret
-    BIGNUM *key;       // The calculated (shared) key
-    BIGNUM *xa;        // Alice's x1 or Bob's x3
-    BIGNUM *xb;        // Alice's x2 or Bob's x4
-    } JPakeUser;
-
-// Generate each party's random numbers. xa is in [0, q), xb is in [1, q).
-static void genrand(JPakeUser *user, const JPakeParameters *params)
-    {
-    BIGNUM *qm1;
-
-    // xa in [0, q)
-    user->xa = BN_new();
-    BN_rand_range(user->xa, params->q);
-
-    // q-1
-    qm1 = BN_new();
-    BN_copy(qm1, params->q);
-    BN_sub_word(qm1, 1);
-
-    // ... and xb in [0, q-1)
-    user->xb = BN_new();
-    BN_rand_range(user->xb, qm1);
-    // [1, q)
-    BN_add_word(user->xb, 1);
-
-    // cleanup
-    BN_free(qm1);
-
-    // Show
-    printf("x%d", user->p.base);
-    showbn("", user->xa);
-    printf("x%d", user->p.base+1);
-    showbn("", user->xb);
-    }
-
-static void hashlength(SHA_CTX *sha, size_t l)
-    {
-    unsigned char b[2];
-
-    assert(l <= 0xffff);
-    b[0] = l >> 8;
-    b[1] = l&0xff;
-    SHA1_Update(sha, b, 2);
-    }
-
-static void hashstring(SHA_CTX *sha, const char *string)
-    {
-    size_t l = strlen(string);
-
-    hashlength(sha, l);
-    SHA1_Update(sha, string, l);
-    }
-
-static void hashbn(SHA_CTX *sha, const BIGNUM *bn)
-    {
-    size_t l = BN_num_bytes(bn);
-    unsigned char *bin = alloca(l);
-
-    hashlength(sha, l);
-    BN_bn2bin(bn, bin);
-    SHA1_Update(sha, bin, l);
-    }
-
-// h=hash(g, g^r, g^x, name)
-static void zkpHash(BIGNUM *h, const JPakeZKP *zkp, const BIGNUM *gx,
-                   const JPakeUserPublic *from, const JPakeParameters *params)
-    {
-    unsigned char md[SHA_DIGEST_LENGTH];
-    SHA_CTX sha;
-
-    // XXX: hash should not allow moving of the boundaries - Java code
-    // is flawed in this respect. Length encoding seems simplest.
-    SHA1_Init(&sha);
-    hashbn(&sha, params->g);
-    hashbn(&sha, zkp->gr);
-    hashbn(&sha, gx);
-    hashstring(&sha, from->name);
-    SHA1_Final(md, &sha);
-    BN_bin2bn(md, SHA_DIGEST_LENGTH, h);
-    }
-
-// Prove knowledge of x
-// Note that we don't send g^x because, as it happens, we've always
-// sent it elsewhere. Also note that because of that, we could avoid
-// calculating it here, but we don't, for clarity...
-static void CreateZKP(JPakeZKP *zkp, const BIGNUM *x, const JPakeUser *us,
-                     const BIGNUM *zkpg, const JPakeParameters *params,
-                     int n, const char *suffix)
-    {
-    BIGNUM *r = BN_new();
-    BIGNUM *gx = BN_new();
-    BIGNUM *h = BN_new();
-    BIGNUM *t = BN_new();
-
-    // r in [0,q)
-    // XXX: Java chooses r in [0, 2^160) - i.e. distribution not uniform
-    BN_rand_range(r, params->q);
-    // g^r
-    zkp->gr = BN_new();
-    BN_mod_exp(zkp->gr, zkpg, r, params->p, params->ctx);
-    // g^x
-    BN_mod_exp(gx, zkpg, x, params->p, params->ctx);
-
-    // h=hash...
-    zkpHash(h, zkp, gx, &us->p, params);
-    
-    // b = r - x*h
-    BN_mod_mul(t, x, h, params->q, params->ctx);
-    zkp->b = BN_new();
-    BN_mod_sub(zkp->b, r, t, params->q, params->ctx);
-
-    // show
-    printf("  ZKP(x%d%s)\n", n, suffix);
-    showbn("   zkpg", zkpg);
-    showbn("    g^x", gx);
-    showbn("    g^r", zkp->gr);
-    showbn("      b", zkp->b);
-
-    // cleanup
-    BN_free(t);
-    BN_free(h);
-    BN_free(gx);
-    BN_free(r);
-    }
-
-static int VerifyZKP(const JPakeZKP *zkp, BIGNUM *gx,
-                    const JPakeUserPublic *them, const BIGNUM *zkpg,
-                    const JPakeParameters *params, int n, const char *suffix)
-    {
-    BIGNUM *h = BN_new();
-    BIGNUM *t1 = BN_new();
-    BIGNUM *t2 = BN_new();
-    BIGNUM *t3 = BN_new();
-    int ret = 0;
-
-    zkpHash(h, zkp, gx, them, params);
-
-    // t1 = g^b
-    BN_mod_exp(t1, zkpg, zkp->b, params->p, params->ctx);
-    // t2 = (g^x)^h = g^{hx}
-    BN_mod_exp(t2, gx, h, params->p, params->ctx);
-    // t3 = t1 * t2 = g^{hx} * g^b = g^{hx+b} = g^r (allegedly)
-    BN_mod_mul(t3, t1, t2, params->p, params->ctx);
-
-    printf("  ZKP(x%d%s)\n", n, suffix);
-    showbn("    zkpg", zkpg);
-    showbn("    g^r'", t3);
-
-    // verify t3 == g^r
-    if(BN_cmp(t3, zkp->gr) == 0)
-       ret = 1;
-
-    // cleanup
-    BN_free(t3);
-    BN_free(t2);
-    BN_free(t1);
-    BN_free(h);
-
-    if(ret)
-       puts("    OK");
-    else
-       puts("    FAIL");
-
-    return ret;
-    }    
-
-static void sendstep1_substep(JPakeStep1 *s1, const BIGNUM *x,
-                             const JPakeUser *us,
-                             const JPakeParameters *params, int n)
-    {
-    s1->gx = BN_new();
-    BN_mod_exp(s1->gx, params->g, x, params->p, params->ctx);
-    printf("  g^{x%d}", n);
-    showbn("", s1->gx);
-
-    CreateZKP(&s1->zkpx, x, us, params->g, params, n, "");
-    }
-
-static void sendstep1(const JPakeUser *us, JPakeUserPublic *them,
-                     const JPakeParameters *params)
-    {
-    printf("\n%s sends %s:\n\n", us->p.name, them->name);
-
-    // from's g^xa (which becomes to's g^xc) and ZKP(xa)
-    sendstep1_substep(&them->s1c, us->xa, us, params, us->p.base);
-    // from's g^xb (which becomes to's g^xd) and ZKP(xb)
-    sendstep1_substep(&them->s1d, us->xb, us, params, us->p.base+1);
-    }
-
-static int verifystep1(const JPakeUser *us, const JPakeUserPublic *them,
-                      const JPakeParameters *params)
-    {
-    printf("\n%s verifies %s:\n\n", us->p.name, them->name);
-
-    // verify their ZKP(xc)
-    if(!VerifyZKP(&us->p.s1c.zkpx, us->p.s1c.gx, them, params->g, params,
-                 them->base, ""))
-       return 0;
-
-    // verify their ZKP(xd)
-    if(!VerifyZKP(&us->p.s1d.zkpx, us->p.s1d.gx, them, params->g, params,
-                 them->base+1, ""))
-       return 0;
-
-    // g^xd != 1
-    printf("  g^{x%d} != 1: ", them->base+1);
-    if(BN_is_one(us->p.s1d.gx))
-       {
-       puts("FAIL");
-       return 0;
-       }
-    puts("OK");
-
-    return 1;
-    }
-
-static void sendstep2(const JPakeUser *us, JPakeUserPublic *them,
-                     const JPakeParameters *params)
-    {
-    BIGNUM *t1 = BN_new();
-    BIGNUM *t2 = BN_new();
-
-    printf("\n%s sends %s:\n\n", us->p.name, them->name);
-
-    // X = g^{(xa + xc + xd) * xb * s}
-    // t1 = g^xa
-    BN_mod_exp(t1, params->g, us->xa, params->p, params->ctx);
-    // t2 = t1 * g^{xc} = g^{xa} * g^{xc} = g^{xa + xc}
-    BN_mod_mul(t2, t1, us->p.s1c.gx, params->p, params->ctx);
-    // t1 = t2 * g^{xd} = g^{xa + xc + xd}
-    BN_mod_mul(t1, t2, us->p.s1d.gx, params->p, params->ctx);
-    // t2 = xb * s
-    BN_mod_mul(t2, us->xb, us->secret, params->q, params->ctx);
-    // X = t1^{t2} = t1^{xb * s} = g^{(xa + xc + xd) * xb * s}
-    them->s2.X = BN_new();
-    BN_mod_exp(them->s2.X, t1, t2, params->p, params->ctx);
-
-    // Show
-    printf("  g^{(x%d + x%d + x%d) * x%d * s)", us->p.base, them->base,
-          them->base+1, us->p.base+1);
-    showbn("", them->s2.X);
-
-    // ZKP(xb * s)
-    // XXX: this is kinda funky, because we're using
-    //
-    // g' = g^{xa + xc + xd}
-    //
-    // as the generator, which means X is g'^{xb * s}
-    CreateZKP(&them->s2.zkpxbs, t2, us, t1, params, us->p.base+1, " * s");
-
-    // cleanup
-    BN_free(t1);
-    BN_free(t2);
-    }
-
-static int verifystep2(const JPakeUser *us, const JPakeUserPublic *them,
-                      const JPakeParameters *params)
-    {
-    BIGNUM *t1 = BN_new();
-    BIGNUM *t2 = BN_new();
-    int ret = 0;
-
-    printf("\n%s verifies %s:\n\n", us->p.name, them->name);
-
-    // g' = g^{xc + xa + xb} [from our POV]
-    // t1 = xa + xb
-    BN_mod_add(t1, us->xa, us->xb, params->q, params->ctx);
-    // t2 = g^{t1} = g^{xa+xb}
-    BN_mod_exp(t2, params->g, t1, params->p, params->ctx);
-    // t1 = g^{xc} * t2 = g^{xc + xa + xb}
-    BN_mod_mul(t1, us->p.s1c.gx, t2, params->p, params->ctx);
-
-    if(VerifyZKP(&us->p.s2.zkpxbs, us->p.s2.X, them, t1, params, them->base+1,
-                 " * s"))
-       ret = 1;
-
-    // cleanup
-    BN_free(t2);
-    BN_free(t1);
-
-    return ret;
-    }
-
-static void computekey(JPakeUser *us, const JPakeParameters *params)
-    {
-    BIGNUM *t1 = BN_new();
-    BIGNUM *t2 = BN_new();
-    BIGNUM *t3 = BN_new();
-
-    printf("\n%s calculates the shared key:\n\n", us->p.name);
-
-    // K = (X/g^{xb * xd * s})^{xb}
-    //   = (g^{(xc + xa + xb) * xd * s - xb * xd *s})^{xb}
-    //   = (g^{(xa + xc) * xd * s})^{xb}
-    //   = g^{(xa + xc) * xb * xd * s}
-    // [which is the same regardless of who calculates it]
-
-    // t1 = (g^{xd})^{xb} = g^{xb * xd}
-    BN_mod_exp(t1, us->p.s1d.gx, us->xb, params->p, params->ctx);
-    // t2 = -s = q-s
-    BN_sub(t2, params->q, us->secret);
-    // t3 = t1^t2 = g^{-xb * xd * s}
-    BN_mod_exp(t3, t1, t2, params->p, params->ctx);
-    // t1 = X * t3 = X/g^{xb * xd * s}
-    BN_mod_mul(t1, us->p.s2.X, t3, params->p, params->ctx);
-    // K = t1^{xb}
-    us->key = BN_new();
-    BN_mod_exp(us->key, t1, us->xb, params->p, params->ctx);
-
-    // show
-    showbn("  K", us->key);
-
-    // cleanup
-    BN_free(t3);
-    BN_free(t2);
-    BN_free(t1);
-    }
-
-int main(int argc, char **argv)
-    {
-    JPakeParameters params;
-    JPakeUser alice, bob;
-
-    alice.p.name = "Alice";
-    alice.p.base = 1;
-    bob.p.name = "Bob";
-    bob.p.base = 3;
-
-    JPakeParametersInit(&params);
-
-    // Shared secret
-    alice.secret = BN_new();
-    BN_rand(alice.secret, 32, -1, 0);
-    bob.secret = alice.secret;
-    showbn("secret", alice.secret);
-
-    assert(BN_cmp(alice.secret, params.q) < 0);
-
-    // Alice's x1, x2
-    genrand(&alice, &params);
-
-    // Bob's x3, x4
-    genrand(&bob, &params);
-
-    // Now send stuff to each other...
-    sendstep1(&alice, &bob.p, &params);
-    sendstep1(&bob, &alice.p, &params);
-
-    // And verify what each other sent
-    if(!verifystep1(&alice, &bob.p, &params))
-       return 1;
-    if(!verifystep1(&bob, &alice.p, &params))
-       return 2;
-
-    // Second send
-    sendstep2(&alice, &bob.p, &params);
-    sendstep2(&bob, &alice.p, &params);
-
-    // And second verify
-    if(!verifystep2(&alice, &bob.p, &params))
-       return 3;
-    if(!verifystep2(&bob, &alice.p, &params))
-       return 4;
-
-    // Compute common key
-    computekey(&alice, &params);
-    computekey(&bob, &params);
-
-    // Confirm the common key is identical
-    // XXX: if the two secrets are not the same, everything works up
-    // to this point, so the only way to detect a failure is by the
-    // difference in the calculated keys.
-    // Since we're all the same code, just compare them directly. In a
-    // real system, Alice sends Bob H(H(K)), Bob checks it, then sends
-    // back H(K), which Alice checks, or something equivalent.
-    puts("\nAlice and Bob check keys are the same:");
-    if(BN_cmp(alice.key, bob.key) == 0)
-       puts("  OK");
-    else
-       {
-       puts("  FAIL");
-       return 5;
-       }
-
-    return 0;
-    }
index 8e1b686..fa8f509 100644 (file)
@@ -20,7 +20,7 @@ int main(int argc, char **argv)
                fprintf(stderr, "Usage: pkread p12file password opfile\n");
                exit (1);
        }
-       SSLeay_add_all_algorithms();
+       OpenSSL_add_all_algorithms();
        ERR_load_crypto_strings();
        if (!(fp = fopen(argv[1], "rb"))) {
                fprintf(stderr, "Error opening file %s\n", argv[1]);
@@ -51,7 +51,7 @@ int main(int argc, char **argv)
                fprintf(fp, "***User Certificate***\n");
                PEM_write_X509_AUX(fp, cert);
        }
-       if (ca && sk_num(ca)) {
+       if (ca && sk_X509_num(ca)) {
                fprintf(fp, "***Other Certificates***\n");
                for (i = 0; i < sk_X509_num(ca); i++) 
                    PEM_write_X509_AUX(fp, sk_X509_value(ca, i));
diff --git a/deps/openssl/openssl/demos/smime/cacert.pem b/deps/openssl/openssl/demos/smime/cacert.pem
new file mode 100644 (file)
index 0000000..75cbb34
--- /dev/null
@@ -0,0 +1,18 @@
+-----BEGIN CERTIFICATE-----
+MIIC6DCCAlGgAwIBAgIJAMfGO3rdo2uUMA0GCSqGSIb3DQEBBAUAMFcxCzAJBgNV
+BAYTAlVLMRIwEAYDVQQHEwlUZXN0IENpdHkxFjAUBgNVBAoTDU9wZW5TU0wgR3Jv
+dXAxHDAaBgNVBAMTE1Rlc3QgUy9NSU1FIFJvb3QgQ0EwHhcNMDcwNDEzMTc0MzE3
+WhcNMTcwNDEwMTc0MzE3WjBXMQswCQYDVQQGEwJVSzESMBAGA1UEBxMJVGVzdCBD
+aXR5MRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMRwwGgYDVQQDExNUZXN0IFMvTUlN
+RSBSb290IENBMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqJMal1uC1/1wz
+i5+dE4EZF2im3BgROm5PVMbwPY9V1t+KYvtdc3rMcRgJaMbP+qaEcDXoIsZfYXGR
+ielgfDNZmZcj1y/FOum+Jc2OZMs3ggPmjIQ3dbBECq0hZKcbz7wfr+2OeNWm46iT
+jcSIXpGIRhUYEzOgv7zb8oOU70IbbwIDAQABo4G7MIG4MB0GA1UdDgQWBBRHUypx
+CXFQYqewhGo72lWPQUsjoDCBiAYDVR0jBIGAMH6AFEdTKnEJcVBip7CEajvaVY9B
+SyOgoVukWTBXMQswCQYDVQQGEwJVSzESMBAGA1UEBxMJVGVzdCBDaXR5MRYwFAYD
+VQQKEw1PcGVuU1NMIEdyb3VwMRwwGgYDVQQDExNUZXN0IFMvTUlNRSBSb290IENB
+ggkAx8Y7et2ja5QwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQQFAAOBgQANI+Yc
+G/YDM1WMUGEzEkU9UhsIUqdyBebnK3+OyxZSouDcE/M10jFJzBf/F5b0uUGAKWwo
+u0dzmILfKjdfWe8EyCRafZcm00rVcO09i/63FBYzlHbmfUATIqZdhKzxxQMPs5mF
+1je+pHUpzIY8TSXyh/uD9IkAy04IHwGZQf9akw==
+-----END CERTIFICATE-----
diff --git a/deps/openssl/openssl/demos/smime/cakey.pem b/deps/openssl/openssl/demos/smime/cakey.pem
new file mode 100644 (file)
index 0000000..3b53c5e
--- /dev/null
@@ -0,0 +1,15 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICXgIBAAKBgQCqJMal1uC1/1wzi5+dE4EZF2im3BgROm5PVMbwPY9V1t+KYvtd
+c3rMcRgJaMbP+qaEcDXoIsZfYXGRielgfDNZmZcj1y/FOum+Jc2OZMs3ggPmjIQ3
+dbBECq0hZKcbz7wfr+2OeNWm46iTjcSIXpGIRhUYEzOgv7zb8oOU70IbbwIDAQAB
+AoGBAKWOZ2UTc1BkjDjz0XoscmAR8Rj77MdGzfOPkIxPultSW+3yZpkGNyUbnsH5
+HAtf4Avai/m3bMN+s91kDpx9/g/I9ZEHPQLcDICETvwt/EHT7+hwvaQgsM+TgpMs
+tjlGZOWent6wVIuvwwzqOMXZLgK9FvY7upwgtrys4G3Kab5hAkEA2QzFflWyEvKS
+rMSaVtn/IjFilwa7H0IdakkjM34z4peerFTPBr4J47YD4RCR/dAvxyNy3zUxtH18
+9R6dUixI6QJBAMitJD0xOkbGWBX8KVJvRiKOIdf/95ZUAgN/h3bWKy57EB9NYj3u
+jbxXcvdjfSqiITykkjAg7SG7nrlzJsu6CpcCQG6gVsy0auXDY0TRlASuaZ6I40Is
+uRUOgqWYj2uAaHuWYdZeB4LdO3cnX0TISFDAWom6JKNlnmbrCtR4fSDT13kCQQCU
++VQJyV3F5MDHsWbLt6eNR46AV5lpk/vatPXPlrZ/zwPs+PmRmGLICvNiDA2DdNDP
+wCx2Zjsj67CtY3rNitMJAkEAm09BQnjnbBXUb1rd2SjNDWTsu80Z+zLu8pAwXNhW
+8nsvMYqlYMIxuMPwu/QuTnMRhMZ08uhqoD3ukZnBeoMEVg==
+-----END RSA PRIVATE KEY-----
diff --git a/deps/openssl/openssl/demos/smime/encr.txt b/deps/openssl/openssl/demos/smime/encr.txt
new file mode 100644 (file)
index 0000000..f163a32
--- /dev/null
@@ -0,0 +1,3 @@
+Content-type: text/plain
+
+Sample OpenSSL Data for PKCS#7 encryption
diff --git a/deps/openssl/openssl/demos/smime/sign.txt b/deps/openssl/openssl/demos/smime/sign.txt
new file mode 100644 (file)
index 0000000..af1341d
--- /dev/null
@@ -0,0 +1,3 @@
+Content-type: text/plain
+
+Test OpenSSL Signed Content
diff --git a/deps/openssl/openssl/demos/smime/signer.pem b/deps/openssl/openssl/demos/smime/signer.pem
new file mode 100644 (file)
index 0000000..bac16ba
--- /dev/null
@@ -0,0 +1,32 @@
+-----BEGIN CERTIFICATE-----
+MIICpjCCAg+gAwIBAgIJAJ+rfmEoLQRhMA0GCSqGSIb3DQEBBAUAMFcxCzAJBgNV
+BAYTAlVLMRIwEAYDVQQHEwlUZXN0IENpdHkxFjAUBgNVBAoTDU9wZW5TU0wgR3Jv
+dXAxHDAaBgNVBAMTE1Rlc3QgUy9NSU1FIFJvb3QgQ0EwHhcNMDcwNDEzMTgyOTI3
+WhcNMTcwNDA5MTgyOTI3WjBWMQswCQYDVQQGEwJVSzElMCMGA1UEAxMcT3BlblNT
+TCB0ZXN0IFMvTUlNRSBzaWduZXIgMTEgMB4GCSqGSIb3DQEJARYRdGVzdDFAb3Bl
+bnNzbC5vcmcwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAL1ocAQ7ON2pIUXz
+jwKPzpPB9ozB6PFG6F6kARO+i0DiT6Qn8abUjwpHPU+lGys83QlpbkQVUD6Fv/4L
+ytihk6N9Pr/feECVcSZ20dI43WXjfYak14dSVrZkGNMMXqKmnnqtkAdD0oJN7A7y
+gcf8RuViV0kvk9/36eCMwMHrImfhAgMBAAGjezB5MAkGA1UdEwQCMAAwLAYJYIZI
+AYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENlcnRpZmljYXRlMB0GA1UdDgQW
+BBSyKqjvctIsFNBHULBTqr8SHtSxpDAfBgNVHSMEGDAWgBRHUypxCXFQYqewhGo7
+2lWPQUsjoDANBgkqhkiG9w0BAQQFAAOBgQBvdYVoBfd4RV/xWSMXIcgw/i5OiwyX
+MsenQePll51MpglfArd7pUipUalCqlJt/Gs8kD16Ih1z1yuWYVTMlnDZ0PwbIOYn
++Jr8XLF9b1SMJt6PwckZZ0LZdIi2KwGAxVsIW1kjJAqu9o4YH37XW37yYdQRxfvv
+lDiQlgX0JtmLgA==
+-----END CERTIFICATE-----
+-----BEGIN RSA PRIVATE KEY-----
+MIICXAIBAAKBgQC9aHAEOzjdqSFF848Cj86TwfaMwejxRuhepAETvotA4k+kJ/Gm
+1I8KRz1PpRsrPN0JaW5EFVA+hb/+C8rYoZOjfT6/33hAlXEmdtHSON1l432GpNeH
+Ula2ZBjTDF6ipp56rZAHQ9KCTewO8oHH/EblYldJL5Pf9+ngjMDB6yJn4QIDAQAB
+AoGACCuYIWaYll80UzslYRvo8lC8nOfEb5v6bBKxBTQD98GLY+5hKywiG3RlPalG
+mb/fXQeSPReaRYgpdwD1OBEIOEMW9kLyqpzokC0xjpZ+MwsuJTlxCesk5GEsMa3o
+wC3QMmiRA7qrZ/SzTtwrs++9mZ/pxp8JZ6pKYUj8SE7/vV0CQQDz8Ix2t40E16hx
+04+XhClnGqydZJyLLSxcTU3ZVhYxL+efo/5hZ8tKpkcDi8wq6T03BOKrKxrlIW55
+qDRNM24rAkEAxsWzu/rJhIouQyNoYygEIEYzFRlTQyZSg59u6dNiewMn27dOAbyc
+YT7B6da7e74QttTXo0lIllsX2S38+XsIIwJBANSRuIU3G66tkr5l4gnhhAaxqtuY
+sgVhvvdL8dvC9aG1Ifzt9hzBSthpHxbK+oYmK07HdhI8hLpIMLHYzoK7n3MCQEy4
+4rccBcxyyYiAkjozp+QNNIpgTBMPJ6pGT7lRLiHtBeV4y1NASdv/LTnk+Fi69Bid
+7t3H24ytfHcHmS1yn6ECQF6Jmh4C7dlvp59zXp+t+VsXxa/8sq41vKNIj0Rx9vh5
+xp9XL0C5ZpgmBnsTydP9pmkiL4ltLbMX0wJU6N2cmFw=
+-----END RSA PRIVATE KEY-----
diff --git a/deps/openssl/openssl/demos/smime/signer2.pem b/deps/openssl/openssl/demos/smime/signer2.pem
new file mode 100644 (file)
index 0000000..25e23d1
--- /dev/null
@@ -0,0 +1,32 @@
+-----BEGIN CERTIFICATE-----
+MIICpjCCAg+gAwIBAgIJAJ+rfmEoLQRiMA0GCSqGSIb3DQEBBAUAMFcxCzAJBgNV
+BAYTAlVLMRIwEAYDVQQHEwlUZXN0IENpdHkxFjAUBgNVBAoTDU9wZW5TU0wgR3Jv
+dXAxHDAaBgNVBAMTE1Rlc3QgUy9NSU1FIFJvb3QgQ0EwHhcNMDcwNDEzMTgyOTQ0
+WhcNMTcwNDA5MTgyOTQ0WjBWMQswCQYDVQQGEwJVSzElMCMGA1UEAxMcT3BlblNT
+TCB0ZXN0IFMvTUlNRSBzaWduZXIgMjEgMB4GCSqGSIb3DQEJARYRdGVzdDJAb3Bl
+bnNzbC5vcmcwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANco7VPgX9vcGwmZ
+jYqjq1JiR7M38dsMNhuJyLRVjJ5/cpFluQydQuG1PhzOJ8zfYVFicOXKvbYuKuXW
+ozZIwzqEqWsNf36KHTLS6yOMG8I13cRInh+fAIKq9Z8Eh65I7FJzVsNsfEQrGfEW
+GMA8us24IaSvP3QkbfHJn/4RaKznAgMBAAGjezB5MAkGA1UdEwQCMAAwLAYJYIZI
+AYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENlcnRpZmljYXRlMB0GA1UdDgQW
+BBRlrLQJUB8uAa4q8B2OqvvTXonF5zAfBgNVHSMEGDAWgBRHUypxCXFQYqewhGo7
+2lWPQUsjoDANBgkqhkiG9w0BAQQFAAOBgQBQbi2juGALg2k9m1hKpzR2lCGmGO3X
+h3Jh/l0vIxDr0RTgP2vBrtITlx655P/o1snoeTIpYG8uUnFnTE/6YakdayAIlxV4
+aZl63AivZMpQB5SPaPH/jEsGJ8UQMfdiy4ORWIULupuPKlKwODNw7tVhQIACS/DR
+2aX6rl2JEuJ5Yg==
+-----END CERTIFICATE-----
+-----BEGIN RSA PRIVATE KEY-----
+MIICXAIBAAKBgQDXKO1T4F/b3BsJmY2Ko6tSYkezN/HbDDYbici0VYyef3KRZbkM
+nULhtT4czifM32FRYnDlyr22Lirl1qM2SMM6hKlrDX9+ih0y0usjjBvCNd3ESJ4f
+nwCCqvWfBIeuSOxSc1bDbHxEKxnxFhjAPLrNuCGkrz90JG3xyZ/+EWis5wIDAQAB
+AoGAUTB2bcIrKfGimjrBOGGOUmYXnD8uGnQ/LqENhU8K4vxApTD3ZRUqmbUknQYF
+6r8YH/e/llasw8QkF9qod+F5GTgsnyh/aMidFHKrXXbf1662scz9+S6crSXq9Eb2
+CL57f6Kw61k6edrz8zHdA+rnTK00hzgzKCP4ZL5k8/55ueECQQD+BK+nsKi6CcKf
+m3Mh61Sf2Icm5JlMCKaihlbnh78lBN1imYUAfHJEnQ1ujxXB94R+6o9S+XrWTnTX
+2m/JNIfpAkEA2NaidX7Sv5jnRPkwJ02Srl0urxINLmg4bU0zmM3VoMklYBHWnMyr
+upPZGPh5TzCa+g6FTBmU8XK61wvnEKNcTwJBAM24VdnlBIDGbsx8RJ3vzLU30xz4
+ff5J80okqjUQhwkgC3tTAZgHMTPITZyAXQqdvrxakoCMc6MkHxTBX08AMCECQHHL
+SdyxXrYv7waSY0PtANJCkpJLveEhzqMFxdMmCjtj9BpTojYNbv3uQxtIopj9YAdk
+gW2ray++zvC2DV/86x8CQH4UJwgO6JqU4bSgi6HiRNjDg26tJ0Beu8jjl1vrkIVX
+pHFwSUeLZUsT2/iTUSgYH4uYiZPgYNcKTCT9W6se30A=
+-----END RSA PRIVATE KEY-----
diff --git a/deps/openssl/openssl/demos/smime/smdec.c b/deps/openssl/openssl/demos/smime/smdec.c
new file mode 100644 (file)
index 0000000..8b1a854
--- /dev/null
@@ -0,0 +1,83 @@
+/* Simple S/MIME signing example */
+#include <openssl/pem.h>
+#include <openssl/pkcs7.h>
+#include <openssl/err.h>
+
+int main(int argc, char **argv)
+       {
+       BIO *in = NULL, *out = NULL, *tbio = NULL;
+       X509 *rcert = NULL;
+       EVP_PKEY *rkey = NULL;
+       PKCS7 *p7 = NULL;
+       int ret = 1;
+
+       OpenSSL_add_all_algorithms();
+       ERR_load_crypto_strings();
+
+       /* Read in recipient certificate and private key */
+       tbio = BIO_new_file("signer.pem", "r");
+
+       if (!tbio)
+               goto err;
+
+       rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+
+       BIO_reset(tbio);
+
+       rkey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
+
+       if (!rcert || !rkey)
+               goto err;
+
+       /* Open content being signed */
+
+       in = BIO_new_file("smencr.txt", "r");
+
+       if (!in)
+               goto err;
+
+       /* Sign content */
+       p7 = SMIME_read_PKCS7(in, NULL);
+
+       if (!p7)
+               goto err;
+
+       out = BIO_new_file("encrout.txt", "w");
+       if (!out)
+               goto err;
+
+       /* Decrypt S/MIME message */
+       if (!PKCS7_decrypt(p7, rkey, rcert, out, 0))
+               goto err;
+
+       ret = 0;
+
+       err:
+
+       if (ret)
+               {
+               fprintf(stderr, "Error Signing Data\n");
+               ERR_print_errors_fp(stderr);
+               }
+
+       if (p7)
+               PKCS7_free(p7);
+       if (rcert)
+               X509_free(rcert);
+       if (rkey)
+               EVP_PKEY_free(rkey);
+
+       if (in)
+               BIO_free(in);
+       if (out)
+               BIO_free(out);
+       if (tbio)
+               BIO_free(tbio);
+
+       return ret;
+
+       }
+
+
+
+
diff --git a/deps/openssl/openssl/demos/smime/smenc.c b/deps/openssl/openssl/demos/smime/smenc.c
new file mode 100644 (file)
index 0000000..77dd732
--- /dev/null
@@ -0,0 +1,92 @@
+/* Simple S/MIME encrypt example */
+#include <openssl/pem.h>
+#include <openssl/pkcs7.h>
+#include <openssl/err.h>
+
+int main(int argc, char **argv)
+       {
+       BIO *in = NULL, *out = NULL, *tbio = NULL;
+       X509 *rcert = NULL;
+       STACK_OF(X509) *recips = NULL;
+       PKCS7 *p7 = NULL;
+       int ret = 1;
+
+       /*
+        * On OpenSSL 0.9.9 only:
+        * for streaming set PKCS7_STREAM
+        */
+       int flags = PKCS7_STREAM;
+
+       OpenSSL_add_all_algorithms();
+       ERR_load_crypto_strings();
+
+       /* Read in recipient certificate */
+       tbio = BIO_new_file("signer.pem", "r");
+
+       if (!tbio)
+               goto err;
+
+       rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+
+       if (!rcert)
+               goto err;
+
+       /* Create recipient STACK and add recipient cert to it */
+       recips = sk_X509_new_null();
+
+       if (!recips || !sk_X509_push(recips, rcert))
+               goto err;
+
+       /* sk_X509_pop_free will free up recipient STACK and its contents
+        * so set rcert to NULL so it isn't freed up twice.
+        */
+       rcert = NULL;
+
+       /* Open content being encrypted */
+
+       in = BIO_new_file("encr.txt", "r");
+
+       if (!in)
+               goto err;
+
+       /* encrypt content */
+       p7 = PKCS7_encrypt(recips, in, EVP_des_ede3_cbc(), flags);
+
+       if (!p7)
+               goto err;
+
+       out = BIO_new_file("smencr.txt", "w");
+       if (!out)
+               goto err;
+
+       /* Write out S/MIME message */
+       if (!SMIME_write_PKCS7(out, p7, in, flags))
+               goto err;
+
+       ret = 0;
+
+       err:
+
+       if (ret)
+               {
+               fprintf(stderr, "Error Encrypting Data\n");
+               ERR_print_errors_fp(stderr);
+               }
+
+       if (p7)
+               PKCS7_free(p7);
+       if (rcert)
+               X509_free(rcert);
+       if (recips)
+               sk_X509_pop_free(recips, X509_free);
+
+       if (in)
+               BIO_free(in);
+       if (out)
+               BIO_free(out);
+       if (tbio)
+               BIO_free(tbio);
+
+       return ret;
+
+       }
diff --git a/deps/openssl/openssl/demos/smime/smsign.c b/deps/openssl/openssl/demos/smime/smsign.c
new file mode 100644 (file)
index 0000000..ba78830
--- /dev/null
@@ -0,0 +1,89 @@
+/* Simple S/MIME signing example */
+#include <openssl/pem.h>
+#include <openssl/pkcs7.h>
+#include <openssl/err.h>
+
+int main(int argc, char **argv)
+       {
+       BIO *in = NULL, *out = NULL, *tbio = NULL;
+       X509 *scert = NULL;
+       EVP_PKEY *skey = NULL;
+       PKCS7 *p7 = NULL;
+       int ret = 1;
+
+       /* For simple S/MIME signing use PKCS7_DETACHED.
+        * On OpenSSL 0.9.9 only:
+        * for streaming detached set PKCS7_DETACHED|PKCS7_STREAM
+        * for streaming non-detached set PKCS7_STREAM
+        */
+       int flags = PKCS7_DETACHED|PKCS7_STREAM;
+
+       OpenSSL_add_all_algorithms();
+       ERR_load_crypto_strings();
+
+       /* Read in signer certificate and private key */
+       tbio = BIO_new_file("signer.pem", "r");
+
+       if (!tbio)
+               goto err;
+
+       scert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+
+       BIO_reset(tbio);
+
+       skey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
+
+       if (!scert || !skey)
+               goto err;
+
+       /* Open content being signed */
+
+       in = BIO_new_file("sign.txt", "r");
+
+       if (!in)
+               goto err;
+
+       /* Sign content */
+       p7 = PKCS7_sign(scert, skey, NULL, in, flags);
+
+       if (!p7)
+               goto err;
+
+       out = BIO_new_file("smout.txt", "w");
+       if (!out)
+               goto err;
+
+       if (!(flags & PKCS7_STREAM))
+               BIO_reset(in);
+
+       /* Write out S/MIME message */
+       if (!SMIME_write_PKCS7(out, p7, in, flags))
+               goto err;
+
+       ret = 0;
+
+       err:
+
+       if (ret)
+               {
+               fprintf(stderr, "Error Signing Data\n");
+               ERR_print_errors_fp(stderr);
+               }
+
+       if (p7)
+               PKCS7_free(p7);
+       if (scert)
+               X509_free(scert);
+       if (skey)
+               EVP_PKEY_free(skey);
+
+       if (in)
+               BIO_free(in);
+       if (out)
+               BIO_free(out);
+       if (tbio)
+               BIO_free(tbio);
+
+       return ret;
+
+       }
diff --git a/deps/openssl/openssl/demos/smime/smsign2.c b/deps/openssl/openssl/demos/smime/smsign2.c
new file mode 100644 (file)
index 0000000..ff835c5
--- /dev/null
@@ -0,0 +1,107 @@
+/* S/MIME signing example: 2 signers. OpenSSL 0.9.9 only */
+#include <openssl/pem.h>
+#include <openssl/pkcs7.h>
+#include <openssl/err.h>
+
+int main(int argc, char **argv)
+       {
+       BIO *in = NULL, *out = NULL, *tbio = NULL;
+       X509 *scert = NULL, *scert2 = NULL;
+       EVP_PKEY *skey = NULL, *skey2 = NULL;
+       PKCS7 *p7 = NULL;
+       int ret = 1;
+
+       OpenSSL_add_all_algorithms();
+       ERR_load_crypto_strings();
+
+       tbio = BIO_new_file("signer.pem", "r");
+
+       if (!tbio)
+               goto err;
+
+       scert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+
+       BIO_reset(tbio);
+
+       skey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
+
+       BIO_free(tbio);
+
+       tbio = BIO_new_file("signer2.pem", "r");
+
+       if (!tbio)
+               goto err;
+
+       scert2 = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+
+       BIO_reset(tbio);
+
+       skey2 = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
+
+       if (!scert2 || !skey2)
+               goto err;
+
+       in = BIO_new_file("sign.txt", "r");
+
+       if (!in)
+               goto err;
+
+       p7 = PKCS7_sign(NULL, NULL, NULL, in, PKCS7_STREAM|PKCS7_PARTIAL);
+
+       if (!p7)
+               goto err;
+
+       /* Add each signer in turn */
+
+       if (!PKCS7_sign_add_signer(p7, scert, skey, NULL, 0))
+               goto err;
+
+       if (!PKCS7_sign_add_signer(p7, scert2, skey2, NULL, 0))
+               goto err;
+
+       out = BIO_new_file("smout.txt", "w");
+       if (!out)
+               goto err;
+
+       /* NB: content included and finalized by SMIME_write_PKCS7 */
+
+       if (!SMIME_write_PKCS7(out, p7, in, PKCS7_STREAM))
+               goto err;
+
+       ret = 0;
+
+       err:
+
+       if (ret)
+               {
+               fprintf(stderr, "Error Signing Data\n");
+               ERR_print_errors_fp(stderr);
+               }
+
+       if (p7)
+               PKCS7_free(p7);
+
+       if (scert)
+               X509_free(scert);
+       if (skey)
+               EVP_PKEY_free(skey);
+
+       if (scert2)
+               X509_free(scert2);
+       if (skey)
+               EVP_PKEY_free(skey2);
+
+       if (in)
+               BIO_free(in);
+       if (out)
+               BIO_free(out);
+       if (tbio)
+               BIO_free(tbio);
+
+       return ret;
+
+       }
+
+
+
+
diff --git a/deps/openssl/openssl/demos/smime/smver.c b/deps/openssl/openssl/demos/smime/smver.c
new file mode 100644 (file)
index 0000000..9d360c2
--- /dev/null
@@ -0,0 +1,87 @@
+/* Simple S/MIME verification example */
+#include <openssl/pem.h>
+#include <openssl/pkcs7.h>
+#include <openssl/err.h>
+
+int main(int argc, char **argv)
+       {
+       BIO *in = NULL, *out = NULL, *tbio = NULL, *cont = NULL;
+       X509_STORE *st = NULL;
+       X509 *cacert = NULL;
+       PKCS7 *p7 = NULL;
+
+       int ret = 1;
+
+       OpenSSL_add_all_algorithms();
+       ERR_load_crypto_strings();
+
+       /* Set up trusted CA certificate store */
+
+       st = X509_STORE_new();
+
+       /* Read in signer certificate and private key */
+       tbio = BIO_new_file("cacert.pem", "r");
+
+       if (!tbio)
+               goto err;
+
+       cacert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+
+       if (!cacert)
+               goto err;
+
+       if (!X509_STORE_add_cert(st, cacert))
+               goto err;
+
+       /* Open content being signed */
+
+       in = BIO_new_file("smout.txt", "r");
+
+       if (!in)
+               goto err;
+
+       /* Sign content */
+       p7 = SMIME_read_PKCS7(in, &cont);
+
+       if (!p7)
+               goto err;
+
+       /* File to output verified content to */
+       out = BIO_new_file("smver.txt", "w");
+       if (!out)
+               goto err;
+
+       if (!PKCS7_verify(p7, NULL, st, cont, out, 0))
+               {
+               fprintf(stderr, "Verification Failure\n");
+               goto err;
+               }
+
+       fprintf(stderr, "Verification Successful\n");
+
+       ret = 0;
+
+       err:
+
+       if (ret)
+               {
+               fprintf(stderr, "Error Verifying Data\n");
+               ERR_print_errors_fp(stderr);
+               }
+
+       if (p7)
+               PKCS7_free(p7);
+
+       if (cacert)
+               X509_free(cacert);
+
+       if (in)
+               BIO_free(in);
+       if (out)
+               BIO_free(out);
+       if (tbio)
+               BIO_free(tbio);
+
+       return ret;
+
+       }
index 0c9123b..2179088 100755 (executable)
@@ -15,4 +15,5 @@ fi
 
 rm -f aclocal.m4 config.* configure install-sh \
        missing mkinstalldirs stamp-h.* Makefile.in \
-       ltconfig ltmain.sh
+       ltconfig ltmain.sh depcomp
+rm -rf autom4te.cache
index e649838..f6e452a 100644 (file)
@@ -134,8 +134,27 @@ RSA *cb_generate_tmp_rsa(SSL *s, int is_export, int keylength)
        /* TODO: Perhaps make it so our global key can be generated on-the-fly
         * after certain intervals? */
        static RSA *rsa_tmp = NULL;
-       if(!rsa_tmp)
-               rsa_tmp = RSA_generate_key(keylength, RSA_F4, NULL, NULL);
+       BIGNUM *bn = NULL;
+       int ok = 1;
+       if(!rsa_tmp) {
+               ok = 0;
+               if(!(bn = BN_new()))
+                       goto end;
+               if(!BN_set_word(bn, RSA_F4))
+                       goto end;
+               if(!(rsa_tmp = RSA_new()))
+                       goto end;
+               if(!RSA_generate_key_ex(rsa_tmp, keylength, bn, NULL))
+                       goto end;
+               ok = 1;
+       }
+end:
+       if(bn)
+               BN_free(bn);
+       if(!ok) {
+               RSA_free(rsa_tmp);
+               rsa_tmp = NULL;
+       }
        return rsa_tmp;
 }
 
index e918cba..ec49d3e 100644 (file)
@@ -697,9 +697,11 @@ static int ctx_set_dh(SSL_CTX *ctx, const char *dh_file, const char *dh_special)
                        abort();
                fprintf(stderr, "Info, generating DH parameters ... ");
                fflush(stderr);
-               if((dh = DH_generate_parameters(512, DH_GENERATOR_5,
-                                       NULL, NULL)) == NULL) {
+               if(!(dh = DH_new()) || !DH_generate_parameters_ex(dh, 512,
+                                       DH_GENERATOR_5, NULL)) {
                        fprintf(stderr, "error!\n");
+                       if(dh)
+                               DH_free(dh);
                        return 0;
                }
                fprintf(stderr, "complete\n");
@@ -733,7 +735,7 @@ static SSL_CTX *initialise_ssl_ctx(int server_mode, const char *engine_id,
                unsigned int verify_depth)
 {
        SSL_CTX *ctx = NULL, *ret = NULL;
-       SSL_METHOD *meth;
+       const SSL_METHOD *meth;
        ENGINE *e = NULL;
 
         OpenSSL_add_ssl_algorithms();
diff --git a/deps/openssl/openssl/doc/HOWTO/certificates.txt b/deps/openssl/openssl/doc/HOWTO/certificates.txt
new file mode 100644 (file)
index 0000000..a8a34c7
--- /dev/null
@@ -0,0 +1,105 @@
+<DRAFT!>
+                       HOWTO certificates
+
+1. Introduction
+
+How you handle certificates depend a great deal on what your role is.
+Your role can be one or several of:
+
+  - User of some client software
+  - User of some server software
+  - Certificate authority
+
+This file is for users who wish to get a certificate of their own.
+Certificate authorities should read ca.txt.
+
+In all the cases shown below, the standard configuration file, as
+compiled into openssl, will be used.  You may find it in /etc/,
+/usr/local/ssl/ or somewhere else.  The name is openssl.cnf, and
+is better described in another HOWTO <config.txt?>.  If you want to
+use a different configuration file, use the argument '-config {file}'
+with the command shown below.
+
+
+2. Relationship with keys
+
+Certificates are related to public key cryptography by containing a
+public key.  To be useful, there must be a corresponding private key
+somewhere.  With OpenSSL, public keys are easily derived from private
+keys, so before you create a certificate or a certificate request, you
+need to create a private key.
+
+Private keys are generated with 'openssl genrsa' if you want a RSA
+private key, or 'openssl gendsa' if you want a DSA private key.
+Further information on how to create private keys can be found in
+another HOWTO <keys.txt?>.  The rest of this text assumes you have
+a private key in the file privkey.pem.
+
+
+3. Creating a certificate request
+
+To create a certificate, you need to start with a certificate
+request (or, as some certificate authorities like to put
+it, "certificate signing request", since that's exactly what they do,
+they sign it and give you the result back, thus making it authentic
+according to their policies).  A certificate request can then be sent
+to a certificate authority to get it signed into a certificate, or if
+you have your own certificate authority, you may sign it yourself, or
+if you need a self-signed certificate (because you just want a test
+certificate or because you are setting up your own CA).
+
+The certificate request is created like this:
+
+  openssl req -new -key privkey.pem -out cert.csr
+
+Now, cert.csr can be sent to the certificate authority, if they can
+handle files in PEM format.  If not, use the extra argument '-outform'
+followed by the keyword for the format to use (see another HOWTO
+<formats.txt?>).  In some cases, that isn't sufficient and you will
+have to be more creative.
+
+When the certificate authority has then done the checks the need to
+do (and probably gotten payment from you), they will hand over your
+new certificate to you.
+
+Section 5 will tell you more on how to handle the certificate you
+received.
+
+
+4. Creating a self-signed test certificate
+
+If you don't want to deal with another certificate authority, or just
+want to create a test certificate for yourself.  This is similar to
+creating a certificate request, but creates a certificate instead of
+a certificate request.  This is NOT the recommended way to create a
+CA certificate, see ca.txt.
+
+  openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095
+
+
+5. What to do with the certificate
+
+If you created everything yourself, or if the certificate authority
+was kind enough, your certificate is a raw DER thing in PEM format.
+Your key most definitely is if you have followed the examples above.
+However, some (most?) certificate authorities will encode them with
+things like PKCS7 or PKCS12, or something else.  Depending on your
+applications, this may be perfectly OK, it all depends on what they
+know how to decode.  If not, There are a number of OpenSSL tools to
+convert between some (most?) formats.
+
+So, depending on your application, you may have to convert your
+certificate and your key to various formats, most often also putting
+them together into one file.  The ways to do this is described in
+another HOWTO <formats.txt?>, I will just mention the simplest case.
+In the case of a raw DER thing in PEM format, and assuming that's all
+right for yor applications, simply concatenating the certificate and
+the key into a new file and using that one should be enough.  With
+some applications, you don't even have to do that.
+
+
+By now, you have your cetificate and your private key and can start
+using the software that depend on it.
+
+-- 
+Richard Levitte
diff --git a/deps/openssl/openssl/doc/HOWTO/keys.txt b/deps/openssl/openssl/doc/HOWTO/keys.txt
new file mode 100644 (file)
index 0000000..7ae2a3a
--- /dev/null
@@ -0,0 +1,73 @@
+<DRAFT!>
+                       HOWTO keys
+
+1. Introduction
+
+Keys are the basis of public key algorithms and PKI.  Keys usually
+come in pairs, with one half being the public key and the other half
+being the private key.  With OpenSSL, the private key contains the
+public key information as well, so a public key doesn't need to be
+generated separately.
+
+Public keys come in several flavors, using different cryptographic
+algorithms.  The most popular ones associated with certificates are
+RSA and DSA, and this HOWTO will show how to generate each of them.
+
+
+2. To generate a RSA key
+
+A RSA key can be used both for encryption and for signing.
+
+Generating a key for the RSA algorithm is quite easy, all you have to
+do is the following:
+
+  openssl genrsa -des3 -out privkey.pem 2048
+
+With this variant, you will be prompted for a protecting password.  If
+you don't want your key to be protected by a password, remove the flag
+'-des3' from the command line above.
+
+    NOTE: if you intend to use the key together with a server
+    certificate, it may be a good thing to avoid protecting it
+    with a password, since that would mean someone would have to
+    type in the password every time the server needs to access
+    the key.
+
+The number 2048 is the size of the key, in bits.  Today, 2048 or
+higher is recommended for RSA keys, as fewer amount of bits is
+consider insecure or to be insecure pretty soon.
+
+
+3. To generate a DSA key
+
+A DSA key can be used for signing only.  This is important to keep
+in mind to know what kind of purposes a certificate request with a
+DSA key can really be used for.
+
+Generating a key for the DSA algorithm is a two-step process.  First,
+you have to generate parameters from which to generate the key:
+
+  openssl dsaparam -out dsaparam.pem 2048
+
+The number 2048 is the size of the key, in bits.  Today, 2048 or
+higher is recommended for DSA keys, as fewer amount of bits is
+consider insecure or to be insecure pretty soon.
+
+When that is done, you can generate a key using the parameters in
+question (actually, several keys can be generated from the same
+parameters):
+
+  openssl gendsa -des3 -out privkey.pem dsaparam.pem
+
+With this variant, you will be prompted for a protecting password.  If
+you don't want your key to be protected by a password, remove the flag
+'-des3' from the command line above.
+
+    NOTE: if you intend to use the key together with a server
+    certificate, it may be a good thing to avoid protecting it
+    with a password, since that would mean someone would have to
+    type in the password every time the server needs to access
+    the key.
+
+-- 
+Richard Levitte
diff --git a/deps/openssl/openssl/doc/HOWTO/proxy_certificates.txt b/deps/openssl/openssl/doc/HOWTO/proxy_certificates.txt
new file mode 100644 (file)
index 0000000..3d36b02
--- /dev/null
@@ -0,0 +1,322 @@
+<DRAFT!>
+                       HOWTO proxy certificates
+
+0. WARNING
+
+NONE OF THE CODE PRESENTED HERE HAVE BEEN CHECKED!  They are just an
+example to show you how things can be done.  There may be typos or
+type conflicts, and you will have to resolve them.
+
+1. Introduction
+
+Proxy certificates are defined in RFC 3820.  They are really usual
+certificates with the mandatory extension proxyCertInfo.
+
+Proxy certificates are issued by an End Entity (typically a user),
+either directly with the EE certificate as issuing certificate, or by
+extension through an already issued proxy certificate..  They are used
+to extend rights to some other entity (a computer process, typically,
+or sometimes to the user itself), so it can perform operations in the
+name of the owner of the EE certificate.
+
+See http://www.ietf.org/rfc/rfc3820.txt for more information.
+
+
+2. A warning about proxy certificates
+
+Noone seems to have tested proxy certificates with security in mind.
+Basically, to this date, it seems that proxy certificates have only
+been used in a world that's highly aware of them.  What would happen
+if an unsuspecting application is to validate a chain of certificates
+that contains proxy certificates?  It would usually consider the leaf
+to be the certificate to check for authorisation data, and since proxy
+certificates are controlled by the EE certificate owner alone, it's
+would be normal to consider what the EE certificate owner could do
+with them.
+
+subjectAltName and issuerAltName are forbidden in proxy certificates,
+and this is enforced in OpenSSL.  The subject must be the same as the
+issuer, with one commonName added on.
+
+Possible threats are, as far as has been imagined so far:
+
+ - impersonation through commonName (think server certificates).
+ - use of additional extensions, possibly non-standard ones used in
+   certain environments, that would grant extra or different
+   authorisation rights.
+
+For this reason, OpenSSL requires that the use of proxy certificates
+be explicitely allowed.  Currently, this can be done using the
+following methods:
+
+ - if the application calls X509_verify_cert() itself, it can do the
+   following prior to that call (ctx is the pointer passed in the call
+   to X509_verify_cert()):
+
+       X509_STORE_CTX_set_flags(ctx, X509_V_FLAG_ALLOW_PROXY_CERTS);
+
+ - in all other cases, proxy certificate validation can be enabled
+   before starting the application by setting the envirnoment variable
+   OPENSSL_ALLOW_PROXY with some non-empty value.
+
+There are thoughts to allow proxy certificates with a line in the
+default openssl.cnf, but that's still in the future.
+
+
+3. How to create proxy cerificates
+
+It's quite easy to create proxy certificates, by taking advantage of
+the lack of checks of the 'openssl x509' application (*ahem*).  But
+first, you need to create a configuration section that contains a
+definition of the proxyCertInfo extension, a little like this:
+
+  [ v3_proxy ]
+  # A proxy certificate MUST NEVER be a CA certificate.
+  basicConstraints=CA:FALSE
+
+  # Usual authority key ID
+  authorityKeyIdentifier=keyid,issuer:always
+
+  # Now, for the extension that marks this certificate as a proxy one
+  proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:1,policy:text:AB
+
+It's also possible to give the proxy extension in a separate section:
+
+  proxyCertInfo=critical,@proxy_ext
+
+  [ proxy_ext ]
+  language=id-ppl-anyLanguage
+  pathlen=0
+  policy=text:BC
+
+The policy value has a specific syntax, {syntag}:{string}, where the
+syntag determines what will be done with the string.  The recognised
+syntags are as follows:
+
+  text indicates that the string is simply the bytes, not
+       encoded in any kind of way:
+
+               policy=text:räksmörgÃ¥s
+
+       Previous versions of this design had a specific tag
+       for UTF-8 text.  However, since the bytes are copied
+       as-is anyway, there's no need for it.  Instead, use
+       the text: tag, like this:
+
+               policy=text:räksmörgÃ¥s
+
+  hex  indicates the string is encoded in hex, with colons
+       between each byte (every second hex digit):
+
+               policy=hex:72:E4:6B:73:6D:F6:72:67:E5:73
+
+       Previous versions of this design had a tag to insert a
+       complete DER blob.  However, the only legal use for
+       this would be to surround the bytes that would go with
+       the hex: tag with what's needed to construct a correct
+       OCTET STRING.  Since hex: does that, the DER tag felt
+       superfluous, and was therefore removed.
+
+  file indicates that the text of the policy should really be
+       taken from a file.  The string is then really a file
+       name.  This is useful for policies that are large
+       (more than a few of lines) XML documents, for example.
+
+The 'policy' setting can be split up in multiple lines like this:
+
+  0.policy=This is
+  1.polisy= a multi-
+  2.policy=line policy.
+
+NOTE: the proxy policy value is the part that determines the rights
+granted to the process using the proxy certificate.  The value is
+completely dependent on the application reading and interpretting it!
+
+Now that you have created an extension section for your proxy
+certificate, you can now easily create a proxy certificate like this:
+
+  openssl req -new -config openssl.cnf \
+         -out proxy.req -keyout proxy.key
+  openssl x509 -req -CAcreateserial -in proxy.req -days 7 \
+         -out proxy.crt -CA user.crt -CAkey user.key \
+         -extfile openssl.cnf -extensions v3_proxy
+
+It's just as easy to create a proxy certificate using another proxy
+certificate as issuer (note that I'm using a different configuration
+section for it):
+
+  openssl req -new -config openssl.cnf \
+         -out proxy2.req -keyout proxy2.key
+  openssl x509 -req -CAcreateserial -in proxy2.req -days 7 \
+         -out proxy2.crt -CA proxy.crt -CAkey proxy.key \
+         -extfile openssl.cnf -extensions v3_proxy2
+
+
+4. How to have your application interpret the policy?
+
+The basic way to interpret proxy policies is to prepare some default
+rights, then do a check of the proxy certificate against the a chain
+of proxy certificates, user certificate and CA certificates, and see
+what rights came out by the end.  Sounds easy, huh?  It almost is.
+
+The slightly complicated part is how to pass data between your
+application and the certificate validation procedure.
+
+You need the following ingredients:
+
+ - a callback routing that will be called for every certificate that's
+   validated.  It will be called several times for each certificates,
+   so you must be attentive to when it's a good time to do the proxy
+   policy interpretation and check, as well as to fill in the defaults
+   when the EE certificate is checked.
+
+ - a structure of data that's shared between your application code and
+   the callback.
+
+ - a wrapper function that sets it all up.
+
+ - an ex_data index function that creates an index into the generic
+   ex_data store that's attached to an X509 validation context.
+
+This is some cookbook code for you to fill in:
+
+  /* In this example, I will use a view of granted rights as a bit
+     array, one bit for each possible right.  */
+  typedef struct your_rights {
+    unsigned char rights[total_rights / 8];
+  } YOUR_RIGHTS;
+
+  /* The following procedure will create an index for the ex_data
+     store in the X509 validation context the first time it's called.
+     Subsequent calls will return the same index.  */
+  static int get_proxy_auth_ex_data_idx(void)
+  {
+    static volatile int idx = -1;
+    if (idx < 0)
+      {
+        CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);
+        if (idx < 0)
+          {
+            idx = X509_STORE_CTX_get_ex_new_index(0,
+                                                  "for verify callback",
+                                                  NULL,NULL,NULL);
+          }
+        CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
+      }
+    return idx;
+  }
+
+  /* Callback to be given to the X509 validation procedure.  */
+  static int verify_callback(int ok, X509_STORE_CTX *ctx)
+  {
+    if (ok == 1) /* It's REALLY important you keep the proxy policy
+                    check within this secion.  It's important to know
+                    that when ok is 1, the certificates are checked
+                    from top to bottom.  You get the CA root first,
+                    followed by the possible chain of intermediate
+                    CAs, followed by the EE certificate, followed by
+                    the possible proxy certificates.  */
+      {
+        X509 *xs = ctx->current_cert;
+
+        if (xs->ex_flags & EXFLAG_PROXY)
+          {
+           YOUR_RIGHTS *rights =
+              (YOUR_RIGHTS *)X509_STORE_CTX_get_ex_data(ctx,
+                get_proxy_auth_ex_data_idx());
+            PROXY_CERT_INFO_EXTENSION *pci =
+              X509_get_ext_d2i(xs, NID_proxyCertInfo, NULL, NULL);
+
+            switch (OBJ_obj2nid(pci->proxyPolicy->policyLanguage))
+              {
+              case NID_Independent:
+                /* Do whatever you need to grant explicit rights to
+                   this particular proxy certificate, usually by
+                   pulling them from some database.  If there are none
+                   to be found, clear all rights (making this and any
+                   subsequent proxy certificate void of any rights).
+                */
+                memset(rights->rights, 0, sizeof(rights->rights));
+                break;
+              case NID_id_ppl_inheritAll:
+                /* This is basically a NOP, we simply let the current
+                   rights stand as they are. */
+                break;
+              default:
+                /* This is usually the most complex section of code.
+                   You really do whatever you want as long as you
+                   follow RFC 3820.  In the example we use here, the
+                   simplest thing to do is to build another, temporary
+                   bit array and fill it with the rights granted by
+                   the current proxy certificate, then use it as a
+                   mask on the accumulated rights bit array, and
+                   voilà, you now have a new accumulated rights bit
+                   array.  */
+                {
+                  int i;
+                  YOUR_RIGHTS tmp_rights;
+                 memset(tmp_rights.rights, 0, sizeof(tmp_rights.rights));
+
+                  /* process_rights() is supposed to be a procedure
+                     that takes a string and it's length, interprets
+                     it and sets the bits in the YOUR_RIGHTS pointed
+                     at by the third argument.  */
+                  process_rights((char *) pci->proxyPolicy->policy->data,
+                                 pci->proxyPolicy->policy->length,
+                                 &tmp_rights);
+
+                  for(i = 0; i < total_rights / 8; i++)
+                    rights->rights[i] &= tmp_rights.rights[i];
+                }
+                break;
+              }
+            PROXY_CERT_INFO_EXTENSION_free(pci);
+          }
+        else if (!(xs->ex_flags & EXFLAG_CA))
+          {
+            /* We have a EE certificate, let's use it to set default!
+            */
+           YOUR_RIGHTS *rights =
+              (YOUR_RIGHTS *)X509_STORE_CTX_get_ex_data(ctx,
+                get_proxy_auth_ex_data_idx());
+
+            /* The following procedure finds out what rights the owner
+               of the current certificate has, and sets them in the
+               YOUR_RIGHTS structure pointed at by the second
+               argument.  */
+            set_default_rights(xs, rights);
+          }
+      }
+    return ok;
+  }
+
+  static int my_X509_verify_cert(X509_STORE_CTX *ctx,
+                                 YOUR_RIGHTS *needed_rights)
+  {
+    int i;
+    int (*save_verify_cb)(int ok,X509_STORE_CTX *ctx) = ctx->verify_cb;
+    YOUR_RIGHTS rights;
+
+    X509_STORE_CTX_set_verify_cb(ctx, verify_callback);
+    X509_STORE_CTX_set_ex_data(ctx, get_proxy_auth_ex_data_idx(), &rights);
+    X509_STORE_CTX_set_flags(ctx, X509_V_FLAG_ALLOW_PROXY_CERTS);
+    ok = X509_verify_cert(ctx);
+
+    if (ok == 1)
+      {
+        ok = check_needed_rights(rights, needed_rights);
+      }
+
+    X509_STORE_CTX_set_verify_cb(ctx, save_verify_cb);
+
+    return ok;
+  }
+
+If you use SSL or TLS, you can easily set up a callback to have the
+certificates checked properly, using the code above:
+
+  SSL_CTX_set_cert_verify_callback(s_ctx, my_X509_verify_cert, &needed_rights);
+
+
+-- 
+Richard Levitte
diff --git a/deps/openssl/openssl/doc/README b/deps/openssl/openssl/doc/README
new file mode 100644 (file)
index 0000000..6ecc14d
--- /dev/null
@@ -0,0 +1,12 @@
+
+ apps/openssl.pod .... Documentation of OpenSSL `openssl' command
+ crypto/crypto.pod ... Documentation of OpenSSL crypto.h+libcrypto.a
+ ssl/ssl.pod ......... Documentation of OpenSSL ssl.h+libssl.a
+ openssl.txt ......... Assembled documentation files for OpenSSL [not final]
+ ssleay.txt .......... Assembled documentation of ancestor SSLeay [obsolete]
+ standards.txt ....... Assembled pointers to standards, RFCs or internet drafts
+                       that are related to OpenSSL.
+
+ An archive of HTML documents for the SSLeay library is available from
+ http://www.columbia.edu/~ariel/ssleay/
+
diff --git a/deps/openssl/openssl/doc/apps/CA.pl.pod b/deps/openssl/openssl/doc/apps/CA.pl.pod
new file mode 100644 (file)
index 0000000..ed69952
--- /dev/null
@@ -0,0 +1,179 @@
+
+=pod
+
+=head1 NAME
+
+CA.pl - friendlier interface for OpenSSL certificate programs
+
+=head1 SYNOPSIS
+
+B<CA.pl>
+[B<-?>]
+[B<-h>]
+[B<-help>]
+[B<-newcert>]
+[B<-newreq>]
+[B<-newreq-nodes>]
+[B<-newca>]
+[B<-xsign>]
+[B<-sign>]
+[B<-signreq>]
+[B<-signcert>]
+[B<-verify>]
+[B<files>]
+
+=head1 DESCRIPTION
+
+The B<CA.pl> script is a perl script that supplies the relevant command line
+arguments to the B<openssl> command for some common certificate operations.
+It is intended to simplify the process of certificate creation and management
+by the use of some simple options.
+
+=head1 COMMAND OPTIONS
+
+=over 4
+
+=item B<?>, B<-h>, B<-help>
+
+prints a usage message.
+
+=item B<-newcert>
+
+creates a new self signed certificate. The private key and certificate are
+written to the file "newreq.pem".
+
+=item B<-newreq>
+
+creates a new certificate request. The private key and request are
+written to the file "newreq.pem".
+
+=item B<-newreq-nodes>
+
+is like B<-newreq> except that the private key will not be encrypted.
+
+=item B<-newca>
+
+creates a new CA hierarchy for use with the B<ca> program (or the B<-signcert>
+and B<-xsign> options). The user is prompted to enter the filename of the CA
+certificates (which should also contain the private key) or by hitting ENTER
+details of the CA will be prompted for. The relevant files and directories
+are created in a directory called "demoCA" in the current directory.
+
+=item B<-pkcs12>
+
+create a PKCS#12 file containing the user certificate, private key and CA
+certificate. It expects the user certificate and private key to be in the
+file "newcert.pem" and the CA certificate to be in the file demoCA/cacert.pem,
+it creates a file "newcert.p12". This command can thus be called after the
+B<-sign> option. The PKCS#12 file can be imported directly into a browser.
+If there is an additional argument on the command line it will be used as the
+"friendly name" for the certificate (which is typically displayed in the browser
+list box), otherwise the name "My Certificate" is used.
+
+=item B<-sign>, B<-signreq>, B<-xsign>
+
+calls the B<ca> program to sign a certificate request. It expects the request
+to be in the file "newreq.pem". The new certificate is written to the file
+"newcert.pem" except in the case of the B<-xsign> option when it is written
+to standard output.
+
+
+=item B<-signCA>
+
+this option is the same as the B<-signreq> option except it uses the configuration
+file section B<v3_ca> and so makes the signed request a valid CA certificate. This
+is useful when creating intermediate CA from a root CA.
+
+=item B<-signcert>
+
+this option is the same as B<-sign> except it expects a self signed certificate
+to be present in the file "newreq.pem".
+
+=item B<-verify>
+
+verifies certificates against the CA certificate for "demoCA". If no certificates
+are specified on the command line it tries to verify the file "newcert.pem". 
+
+=item B<files>
+
+one or more optional certificate file names for use with the B<-verify> command.
+
+=back
+
+=head1 EXAMPLES
+
+Create a CA hierarchy:
+
+ CA.pl -newca
+
+Complete certificate creation example: create a CA, create a request, sign
+the request and finally create a PKCS#12 file containing it.
+
+ CA.pl -newca
+ CA.pl -newreq
+ CA.pl -signreq
+ CA.pl -pkcs12 "My Test Certificate"
+
+=head1 DSA CERTIFICATES
+
+Although the B<CA.pl> creates RSA CAs and requests it is still possible to
+use it with DSA certificates and requests using the L<req(1)|req(1)> command
+directly. The following example shows the steps that would typically be taken.
+
+Create some DSA parameters:
+
+ openssl dsaparam -out dsap.pem 1024
+
+Create a DSA CA certificate and private key:
+
+ openssl req -x509 -newkey dsa:dsap.pem -keyout cacert.pem -out cacert.pem
+
+Create the CA directories and files:
+
+ CA.pl -newca
+
+enter cacert.pem when prompted for the CA file name.
+
+Create a DSA certificate request and private key (a different set of parameters
+can optionally be created first):
+
+ openssl req -out newreq.pem -newkey dsa:dsap.pem 
+
+Sign the request:
+
+ CA.pl -signreq
+
+=head1 NOTES
+
+Most of the filenames mentioned can be modified by editing the B<CA.pl> script.
+
+If the demoCA directory already exists then the B<-newca> command will not
+overwrite it and will do nothing. This can happen if a previous call using
+the B<-newca> option terminated abnormally. To get the correct behaviour
+delete the demoCA directory if it already exists.
+
+Under some environments it may not be possible to run the B<CA.pl> script
+directly (for example Win32) and the default configuration file location may
+be wrong. In this case the command:
+
+ perl -S CA.pl
+
+can be used and the B<OPENSSL_CONF> environment variable changed to point to 
+the correct path of the configuration file "openssl.cnf".
+
+The script is intended as a simple front end for the B<openssl> program for use
+by a beginner. Its behaviour isn't always what is wanted. For more control over the
+behaviour of the certificate commands call the B<openssl> command directly.
+
+=head1 ENVIRONMENT VARIABLES
+
+The variable B<OPENSSL_CONF> if defined allows an alternative configuration
+file location to be specified, it should contain the full path to the
+configuration file, not just its directory.
+
+=head1 SEE ALSO
+
+L<x509(1)|x509(1)>, L<ca(1)|ca(1)>, L<req(1)|req(1)>, L<pkcs12(1)|pkcs12(1)>,
+L<config(5)|config(5)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/asn1parse.pod b/deps/openssl/openssl/doc/apps/asn1parse.pod
new file mode 100644 (file)
index 0000000..f7bb926
--- /dev/null
@@ -0,0 +1,175 @@
+=pod
+
+=head1 NAME
+
+asn1parse - ASN.1 parsing tool
+
+=head1 SYNOPSIS
+
+B<openssl> B<asn1parse>
+[B<-inform PEM|DER>]
+[B<-in filename>]
+[B<-out filename>]
+[B<-noout>]
+[B<-offset number>]
+[B<-length number>]
+[B<-i>]
+[B<-oid filename>]
+[B<-strparse offset>]
+[B<-genstr string>]
+[B<-genconf file>]
+
+=head1 DESCRIPTION
+
+The B<asn1parse> command is a diagnostic utility that can parse ASN.1
+structures. It can also be used to extract data from ASN.1 formatted data.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-inform> B<DER|PEM>
+
+the input format. B<DER> is binary format and B<PEM> (the default) is base64
+encoded.
+
+=item B<-in filename>
+
+the input file, default is standard input
+
+=item B<-out filename>
+
+output file to place the DER encoded data into. If this
+option is not present then no data will be output. This is most useful when
+combined with the B<-strparse> option.
+
+=item B<-noout>
+
+don't output the parsed version of the input file.
+
+=item B<-offset number>
+
+starting offset to begin parsing, default is start of file.
+
+=item B<-length number>
+
+number of bytes to parse, default is until end of file.
+
+=item B<-i>
+
+indents the output according to the "depth" of the structures.
+
+=item B<-oid filename>
+
+a file containing additional OBJECT IDENTIFIERs (OIDs). The format of this
+file is described in the NOTES section below.
+
+=item B<-strparse offset>
+
+parse the contents octets of the ASN.1 object starting at B<offset>. This
+option can be used multiple times to "drill down" into a nested structure.
+
+=item B<-genstr string>, B<-genconf file>
+
+generate encoded data based on B<string>, B<file> or both using
+L<ASN1_generate_nconf(3)|ASN1_generate_nconf(3)> format. If B<file> only is
+present then the string is obtained from the default section using the name
+B<asn1>. The encoded data is passed through the ASN1 parser and printed out as
+though it came from a file, the contents can thus be examined and written to a
+file using the B<out> option. 
+
+=back
+
+=head2 OUTPUT
+
+The output will typically contain lines like this:
+
+  0:d=0  hl=4 l= 681 cons: SEQUENCE          
+
+.....
+
+  229:d=3  hl=3 l= 141 prim: BIT STRING        
+  373:d=2  hl=3 l= 162 cons: cont [ 3 ]        
+  376:d=3  hl=3 l= 159 cons: SEQUENCE          
+  379:d=4  hl=2 l=  29 cons: SEQUENCE          
+  381:d=5  hl=2 l=   3 prim: OBJECT            :X509v3 Subject Key Identifier
+  386:d=5  hl=2 l=  22 prim: OCTET STRING      
+  410:d=4  hl=2 l= 112 cons: SEQUENCE          
+  412:d=5  hl=2 l=   3 prim: OBJECT            :X509v3 Authority Key Identifier
+  417:d=5  hl=2 l= 105 prim: OCTET STRING      
+  524:d=4  hl=2 l=  12 cons: SEQUENCE          
+
+.....
+
+This example is part of a self signed certificate. Each line starts with the
+offset in decimal. B<d=XX> specifies the current depth. The depth is increased
+within the scope of any SET or SEQUENCE. B<hl=XX> gives the header length
+(tag and length octets) of the current type. B<l=XX> gives the length of
+the contents octets.
+
+The B<-i> option can be used to make the output more readable.
+
+Some knowledge of the ASN.1 structure is needed to interpret the output. 
+
+In this example the BIT STRING at offset 229 is the certificate public key.
+The contents octets of this will contain the public key information. This can
+be examined using the option B<-strparse 229> to yield:
+
+    0:d=0  hl=3 l= 137 cons: SEQUENCE          
+    3:d=1  hl=3 l= 129 prim: INTEGER           :E5D21E1F5C8D208EA7A2166C7FAF9F6BDF2059669C60876DDB70840F1A5AAFA59699FE471F379F1DD6A487E7D5409AB6A88D4A9746E24B91D8CF55DB3521015460C8EDE44EE8A4189F7A7BE77D6CD3A9AF2696F486855CF58BF0EDF2B4068058C7A947F52548DDF7E15E96B385F86422BEA9064A3EE9E1158A56E4A6F47E5897
+  135:d=1  hl=2 l=   3 prim: INTEGER           :010001
+
+=head1 NOTES
+
+If an OID is not part of OpenSSL's internal table it will be represented in
+numerical form (for example 1.2.3.4). The file passed to the B<-oid> option 
+allows additional OIDs to be included. Each line consists of three columns,
+the first column is the OID in numerical format and should be followed by white
+space. The second column is the "short name" which is a single word followed
+by white space. The final column is the rest of the line and is the
+"long name". B<asn1parse> displays the long name. Example:
+
+C<1.2.3.4      shortName       A long name>
+
+=head1 EXAMPLES
+
+Parse a file:
+
+ openssl asn1parse -in file.pem
+
+Parse a DER file:
+
+ openssl asn1parse -inform DER -in file.der
+
+Generate a simple UTF8String:
+
+ openssl asn1parse -genstr 'UTF8:Hello World'
+
+Generate and write out a UTF8String, don't print parsed output:
+
+ openssl asn1parse -genstr 'UTF8:Hello World' -noout -out utf8.der
+
+Generate using a config file:
+
+ openssl asn1parse -genconf asn1.cnf -noout -out asn1.der
+
+Example config file:
+
+ asn1=SEQUENCE:seq_sect
+
+ [seq_sect]
+
+ field1=BOOL:TRUE
+ field2=EXP:0, UTF8:some random string
+
+
+=head1 BUGS
+
+There should be options to change the format of output lines. The output of some
+ASN.1 types is not well handled (if at all).
+
+=head1 SEE ALSO
+
+L<ASN1_generate_nconf(3)|ASN1_generate_nconf(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/ca.pod b/deps/openssl/openssl/doc/apps/ca.pod
new file mode 100644 (file)
index 0000000..9ff0cc3
--- /dev/null
@@ -0,0 +1,675 @@
+
+=pod
+
+=head1 NAME
+
+ca - sample minimal CA application
+
+=head1 SYNOPSIS
+
+B<openssl> B<ca>
+[B<-verbose>]
+[B<-config filename>]
+[B<-name section>]
+[B<-gencrl>]
+[B<-revoke file>]
+[B<-crl_reason reason>]
+[B<-crl_hold instruction>]
+[B<-crl_compromise time>]
+[B<-crl_CA_compromise time>]
+[B<-crldays days>]
+[B<-crlhours hours>]
+[B<-crlexts section>]
+[B<-startdate date>]
+[B<-enddate date>]
+[B<-days arg>]
+[B<-md arg>]
+[B<-policy arg>]
+[B<-keyfile arg>]
+[B<-key arg>]
+[B<-passin arg>]
+[B<-cert file>]
+[B<-selfsign>]
+[B<-in file>]
+[B<-out file>]
+[B<-notext>]
+[B<-outdir dir>]
+[B<-infiles>]
+[B<-spkac file>]
+[B<-ss_cert file>]
+[B<-preserveDN>]
+[B<-noemailDN>]
+[B<-batch>]
+[B<-msie_hack>]
+[B<-extensions section>]
+[B<-extfile section>]
+[B<-engine id>]
+[B<-subj arg>]
+[B<-utf8>]
+[B<-multivalue-rdn>]
+
+=head1 DESCRIPTION
+
+The B<ca> command is a minimal CA application. It can be used
+to sign certificate requests in a variety of forms and generate
+CRLs it also maintains a text database of issued certificates
+and their status.
+
+The options descriptions will be divided into each purpose.
+
+=head1 CA OPTIONS
+
+=over 4
+
+=item B<-config filename>
+
+specifies the configuration file to use.
+
+=item B<-name section>
+
+specifies the configuration file section to use (overrides
+B<default_ca> in the B<ca> section).
+
+=item B<-in filename>
+
+an input filename containing a single certificate request to be
+signed by the CA.
+
+=item B<-ss_cert filename>
+
+a single self signed certificate to be signed by the CA.
+
+=item B<-spkac filename>
+
+a file containing a single Netscape signed public key and challenge
+and additional field values to be signed by the CA. See the B<SPKAC FORMAT>
+section for information on the required format.
+
+=item B<-infiles>
+
+if present this should be the last option, all subsequent arguments
+are assumed to the the names of files containing certificate requests. 
+
+=item B<-out filename>
+
+the output file to output certificates to. The default is standard
+output. The certificate details will also be printed out to this
+file.
+
+=item B<-outdir directory>
+
+the directory to output certificates to. The certificate will be
+written to a filename consisting of the serial number in hex with
+".pem" appended.
+
+=item B<-cert>
+
+the CA certificate file.
+
+=item B<-keyfile filename>
+
+the private key to sign requests with.
+
+=item B<-key password>
+
+the password used to encrypt the private key. Since on some
+systems the command line arguments are visible (e.g. Unix with
+the 'ps' utility) this option should be used with caution.
+
+=item B<-selfsign>
+
+indicates the issued certificates are to be signed with the key
+the certificate requests were signed with (given with B<-keyfile>).
+Cerificate requests signed with a different key are ignored.  If
+B<-spkac>, B<-ss_cert> or B<-gencrl> are given, B<-selfsign> is
+ignored.
+
+A consequence of using B<-selfsign> is that the self-signed
+certificate appears among the entries in the certificate database
+(see the configuration option B<database>), and uses the same
+serial number counter as all other certificates sign with the
+self-signed certificate.
+
+=item B<-passin arg>
+
+the key password source. For more information about the format of B<arg>
+see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
+
+=item B<-verbose>
+
+this prints extra details about the operations being performed.
+
+=item B<-notext>
+
+don't output the text form of a certificate to the output file.
+
+=item B<-startdate date>
+
+this allows the start date to be explicitly set. The format of the
+date is YYMMDDHHMMSSZ (the same as an ASN1 UTCTime structure).
+
+=item B<-enddate date>
+
+this allows the expiry date to be explicitly set. The format of the
+date is YYMMDDHHMMSSZ (the same as an ASN1 UTCTime structure).
+
+=item B<-days arg>
+
+the number of days to certify the certificate for.
+
+=item B<-md alg>
+
+the message digest to use. Possible values include md5, sha1 and mdc2.
+This option also applies to CRLs.
+
+=item B<-policy arg>
+
+this option defines the CA "policy" to use. This is a section in
+the configuration file which decides which fields should be mandatory
+or match the CA certificate. Check out the B<POLICY FORMAT> section
+for more information.
+
+=item B<-msie_hack>
+
+this is a legacy option to make B<ca> work with very old versions of
+the IE certificate enrollment control "certenr3". It used UniversalStrings
+for almost everything. Since the old control has various security bugs
+its use is strongly discouraged. The newer control "Xenroll" does not
+need this option.
+
+=item B<-preserveDN>
+
+Normally the DN order of a certificate is the same as the order of the
+fields in the relevant policy section. When this option is set the order 
+is the same as the request. This is largely for compatibility with the
+older IE enrollment control which would only accept certificates if their
+DNs match the order of the request. This is not needed for Xenroll.
+
+=item B<-noemailDN>
+
+The DN of a certificate can contain the EMAIL field if present in the
+request DN, however it is good policy just having the e-mail set into
+the altName extension of the certificate. When this option is set the
+EMAIL field is removed from the certificate' subject and set only in
+the, eventually present, extensions. The B<email_in_dn> keyword can be
+used in the configuration file to enable this behaviour.
+
+=item B<-batch>
+
+this sets the batch mode. In this mode no questions will be asked
+and all certificates will be certified automatically.
+
+=item B<-extensions section>
+
+the section of the configuration file containing certificate extensions
+to be added when a certificate is issued (defaults to B<x509_extensions>
+unless the B<-extfile> option is used). If no extension section is
+present then, a V1 certificate is created. If the extension section
+is present (even if it is empty), then a V3 certificate is created. See the:w
+L<x509v3_config(5)|x509v3_config(5)> manual page for details of the
+extension section format.
+
+=item B<-extfile file>
+
+an additional configuration file to read certificate extensions from
+(using the default section unless the B<-extensions> option is also
+used).
+
+=item B<-engine id>
+
+specifying an engine (by its unique B<id> string) will cause B<ca>
+to attempt to obtain a functional reference to the specified engine,
+thus initialising it if needed. The engine will then be set as the default
+for all available algorithms.
+
+=item B<-subj arg>
+
+supersedes subject name given in the request.
+The arg must be formatted as I</type0=value0/type1=value1/type2=...>,
+characters may be escaped by \ (backslash), no spaces are skipped.
+
+=item B<-utf8>
+
+this option causes field values to be interpreted as UTF8 strings, by 
+default they are interpreted as ASCII. This means that the field
+values, whether prompted from a terminal or obtained from a
+configuration file, must be valid UTF8 strings.
+
+=item B<-multivalue-rdn>
+
+this option causes the -subj argument to be interpretedt with full
+support for multivalued RDNs. Example:
+
+I</DC=org/DC=OpenSSL/DC=users/UID=123456+CN=John Doe>
+
+If -multi-rdn is not used then the UID value is I<123456+CN=John Doe>.
+
+=back
+
+=head1 CRL OPTIONS
+
+=over 4
+
+=item B<-gencrl>
+
+this option generates a CRL based on information in the index file.
+
+=item B<-crldays num>
+
+the number of days before the next CRL is due. That is the days from
+now to place in the CRL nextUpdate field.
+
+=item B<-crlhours num>
+
+the number of hours before the next CRL is due.
+
+=item B<-revoke filename>
+
+a filename containing a certificate to revoke.
+
+=item B<-crl_reason reason>
+
+revocation reason, where B<reason> is one of: B<unspecified>, B<keyCompromise>,
+B<CACompromise>, B<affiliationChanged>, B<superseded>, B<cessationOfOperation>,
+B<certificateHold> or B<removeFromCRL>. The matching of B<reason> is case
+insensitive. Setting any revocation reason will make the CRL v2.
+
+In practive B<removeFromCRL> is not particularly useful because it is only used
+in delta CRLs which are not currently implemented.
+
+=item B<-crl_hold instruction>
+
+This sets the CRL revocation reason code to B<certificateHold> and the hold
+instruction to B<instruction> which must be an OID. Although any OID can be
+used only B<holdInstructionNone> (the use of which is discouraged by RFC2459)
+B<holdInstructionCallIssuer> or B<holdInstructionReject> will normally be used.
+
+=item B<-crl_compromise time>
+
+This sets the revocation reason to B<keyCompromise> and the compromise time to
+B<time>. B<time> should be in GeneralizedTime format that is B<YYYYMMDDHHMMSSZ>.
+
+=item B<-crl_CA_compromise time>
+
+This is the same as B<crl_compromise> except the revocation reason is set to
+B<CACompromise>.
+
+=item B<-crlexts section>
+
+the section of the configuration file containing CRL extensions to
+include. If no CRL extension section is present then a V1 CRL is
+created, if the CRL extension section is present (even if it is
+empty) then a V2 CRL is created. The CRL extensions specified are
+CRL extensions and B<not> CRL entry extensions.  It should be noted
+that some software (for example Netscape) can't handle V2 CRLs. See
+L<x509v3_config(5)|x509v3_config(5)> manual page for details of the
+extension section format.
+
+=back
+
+=head1 CONFIGURATION FILE OPTIONS
+
+The section of the configuration file containing options for B<ca>
+is found as follows: If the B<-name> command line option is used,
+then it names the section to be used. Otherwise the section to
+be used must be named in the B<default_ca> option of the B<ca> section
+of the configuration file (or in the default section of the
+configuration file). Besides B<default_ca>, the following options are
+read directly from the B<ca> section:
+ RANDFILE
+ preserve
+ msie_hack
+With the exception of B<RANDFILE>, this is probably a bug and may
+change in future releases.
+
+Many of the configuration file options are identical to command line
+options. Where the option is present in the configuration file
+and the command line the command line value is used. Where an
+option is described as mandatory then it must be present in
+the configuration file or the command line equivalent (if
+any) used.
+
+=over 4
+
+=item B<oid_file>
+
+This specifies a file containing additional B<OBJECT IDENTIFIERS>.
+Each line of the file should consist of the numerical form of the
+object identifier followed by white space then the short name followed
+by white space and finally the long name. 
+
+=item B<oid_section>
+
+This specifies a section in the configuration file containing extra
+object identifiers. Each line should consist of the short name of the
+object identifier followed by B<=> and the numerical form. The short
+and long names are the same when this option is used.
+
+=item B<new_certs_dir>
+
+the same as the B<-outdir> command line option. It specifies
+the directory where new certificates will be placed. Mandatory.
+
+=item B<certificate>
+
+the same as B<-cert>. It gives the file containing the CA
+certificate. Mandatory.
+
+=item B<private_key>
+
+same as the B<-keyfile> option. The file containing the
+CA private key. Mandatory.
+
+=item B<RANDFILE>
+
+a file used to read and write random number seed information, or
+an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
+
+=item B<default_days>
+
+the same as the B<-days> option. The number of days to certify
+a certificate for. 
+
+=item B<default_startdate>
+
+the same as the B<-startdate> option. The start date to certify
+a certificate for. If not set the current time is used.
+
+=item B<default_enddate>
+
+the same as the B<-enddate> option. Either this option or
+B<default_days> (or the command line equivalents) must be
+present.
+
+=item B<default_crl_hours default_crl_days>
+
+the same as the B<-crlhours> and the B<-crldays> options. These
+will only be used if neither command line option is present. At
+least one of these must be present to generate a CRL.
+
+=item B<default_md>
+
+the same as the B<-md> option. The message digest to use. Mandatory.
+
+=item B<database>
+
+the text database file to use. Mandatory. This file must be present
+though initially it will be empty.
+
+=item B<unique_subject>
+
+if the value B<yes> is given, the valid certificate entries in the
+database must have unique subjects.  if the value B<no> is given,
+several valid certificate entries may have the exact same subject.
+The default value is B<yes>, to be compatible with older (pre 0.9.8)
+versions of OpenSSL.  However, to make CA certificate roll-over easier,
+it's recommended to use the value B<no>, especially if combined with
+the B<-selfsign> command line option.
+
+=item B<serial>
+
+a text file containing the next serial number to use in hex. Mandatory.
+This file must be present and contain a valid serial number.
+
+=item B<crlnumber>
+
+a text file containing the next CRL number to use in hex. The crl number
+will be inserted in the CRLs only if this file exists. If this file is
+present, it must contain a valid CRL number.
+
+=item B<x509_extensions>
+
+the same as B<-extensions>.
+
+=item B<crl_extensions>
+
+the same as B<-crlexts>.
+
+=item B<preserve>
+
+the same as B<-preserveDN>
+
+=item B<email_in_dn>
+
+the same as B<-noemailDN>. If you want the EMAIL field to be removed
+from the DN of the certificate simply set this to 'no'. If not present
+the default is to allow for the EMAIL filed in the certificate's DN.
+
+=item B<msie_hack>
+
+the same as B<-msie_hack>
+
+=item B<policy>
+
+the same as B<-policy>. Mandatory. See the B<POLICY FORMAT> section
+for more information.
+
+=item B<name_opt>, B<cert_opt>
+
+these options allow the format used to display the certificate details
+when asking the user to confirm signing. All the options supported by
+the B<x509> utilities B<-nameopt> and B<-certopt> switches can be used
+here, except the B<no_signame> and B<no_sigdump> are permanently set
+and cannot be disabled (this is because the certificate signature cannot
+be displayed because the certificate has not been signed at this point).
+
+For convenience the values B<ca_default> are accepted by both to produce
+a reasonable output.
+
+If neither option is present the format used in earlier versions of
+OpenSSL is used. Use of the old format is B<strongly> discouraged because
+it only displays fields mentioned in the B<policy> section, mishandles
+multicharacter string types and does not display extensions.
+
+=item B<copy_extensions>
+
+determines how extensions in certificate requests should be handled.
+If set to B<none> or this option is not present then extensions are
+ignored and not copied to the certificate. If set to B<copy> then any
+extensions present in the request that are not already present are copied
+to the certificate. If set to B<copyall> then all extensions in the
+request are copied to the certificate: if the extension is already present
+in the certificate it is deleted first. See the B<WARNINGS> section before
+using this option.
+
+The main use of this option is to allow a certificate request to supply
+values for certain extensions such as subjectAltName.
+
+=back
+
+=head1 POLICY FORMAT
+
+The policy section consists of a set of variables corresponding to
+certificate DN fields. If the value is "match" then the field value
+must match the same field in the CA certificate. If the value is
+"supplied" then it must be present. If the value is "optional" then
+it may be present. Any fields not mentioned in the policy section
+are silently deleted, unless the B<-preserveDN> option is set but
+this can be regarded more of a quirk than intended behaviour.
+
+=head1 SPKAC FORMAT
+
+The input to the B<-spkac> command line option is a Netscape
+signed public key and challenge. This will usually come from
+the B<KEYGEN> tag in an HTML form to create a new private key. 
+It is however possible to create SPKACs using the B<spkac> utility.
+
+The file should contain the variable SPKAC set to the value of
+the SPKAC and also the required DN components as name value pairs.
+If you need to include the same component twice then it can be
+preceded by a number and a '.'.
+
+=head1 EXAMPLES
+
+Note: these examples assume that the B<ca> directory structure is
+already set up and the relevant files already exist. This usually
+involves creating a CA certificate and private key with B<req>, a
+serial number file and an empty index file and placing them in
+the relevant directories.
+
+To use the sample configuration file below the directories demoCA,
+demoCA/private and demoCA/newcerts would be created. The CA
+certificate would be copied to demoCA/cacert.pem and its private
+key to demoCA/private/cakey.pem. A file demoCA/serial would be
+created containing for example "01" and the empty index file
+demoCA/index.txt.
+
+
+Sign a certificate request:
+
+ openssl ca -in req.pem -out newcert.pem
+
+Sign a certificate request, using CA extensions:
+
+ openssl ca -in req.pem -extensions v3_ca -out newcert.pem
+
+Generate a CRL
+
+ openssl ca -gencrl -out crl.pem
+
+Sign several requests:
+
+ openssl ca -infiles req1.pem req2.pem req3.pem
+
+Certify a Netscape SPKAC:
+
+ openssl ca -spkac spkac.txt
+
+A sample SPKAC file (the SPKAC line has been truncated for clarity):
+
+ SPKAC=MIG0MGAwXDANBgkqhkiG9w0BAQEFAANLADBIAkEAn7PDhCeV/xIxUg8V70YRxK2A5
+ CN=Steve Test
+ emailAddress=steve@openssl.org
+ 0.OU=OpenSSL Group
+ 1.OU=Another Group
+
+A sample configuration file with the relevant sections for B<ca>:
+
+ [ ca ]
+ default_ca      = CA_default            # The default ca section
+ [ CA_default ]
+
+ dir            = ./demoCA              # top dir
+ database       = $dir/index.txt        # index file.
+ new_certs_dir = $dir/newcerts         # new certs dir
+ certificate    = $dir/cacert.pem       # The CA cert
+ serial         = $dir/serial           # serial no file
+ private_key    = $dir/private/cakey.pem# CA private key
+ RANDFILE       = $dir/private/.rand    # random number file
+ default_days   = 365                   # how long to certify for
+ default_crl_days= 30                   # how long before next CRL
+ default_md     = md5                   # md to use
+
+ policy         = policy_any            # default policy
+ email_in_dn    = no                    # Don't add the email into cert DN
+
+ name_opt      = ca_default            # Subject name display option
+ cert_opt      = ca_default            # Certificate display option
+ copy_extensions = none                        # Don't copy extensions from request
+
+ [ policy_any ]
+ countryName            = supplied
+ stateOrProvinceName    = optional
+ organizationName       = optional
+ organizationalUnitName = optional
+ commonName             = supplied
+ emailAddress           = optional
+
+=head1 FILES
+
+Note: the location of all files can change either by compile time options,
+configuration file entries, environment variables or command line options.
+The values below reflect the default values.
+
+ /usr/local/ssl/lib/openssl.cnf - master configuration file
+ ./demoCA                       - main CA directory
+ ./demoCA/cacert.pem            - CA certificate
+ ./demoCA/private/cakey.pem     - CA private key
+ ./demoCA/serial                - CA serial number file
+ ./demoCA/serial.old            - CA serial number backup file
+ ./demoCA/index.txt             - CA text database file
+ ./demoCA/index.txt.old         - CA text database backup file
+ ./demoCA/certs                 - certificate output file
+ ./demoCA/.rnd                  - CA random seed information
+
+=head1 ENVIRONMENT VARIABLES
+
+B<OPENSSL_CONF> reflects the location of master configuration file it can
+be overridden by the B<-config> command line option.
+
+=head1 RESTRICTIONS
+
+The text database index file is a critical part of the process and 
+if corrupted it can be difficult to fix. It is theoretically possible
+to rebuild the index file from all the issued certificates and a current
+CRL: however there is no option to do this.
+
+V2 CRL features like delta CRLs are not currently supported.
+
+Although several requests can be input and handled at once it is only
+possible to include one SPKAC or self signed certificate.
+
+=head1 BUGS
+
+The use of an in memory text database can cause problems when large
+numbers of certificates are present because, as the name implies
+the database has to be kept in memory.
+
+The B<ca> command really needs rewriting or the required functionality
+exposed at either a command or interface level so a more friendly utility
+(perl script or GUI) can handle things properly. The scripts B<CA.sh> and
+B<CA.pl> help a little but not very much.
+
+Any fields in a request that are not present in a policy are silently
+deleted. This does not happen if the B<-preserveDN> option is used. To
+enforce the absence of the EMAIL field within the DN, as suggested by
+RFCs, regardless the contents of the request' subject the B<-noemailDN>
+option can be used. The behaviour should be more friendly and
+configurable.
+
+Cancelling some commands by refusing to certify a certificate can
+create an empty file.
+
+=head1 WARNINGS
+
+The B<ca> command is quirky and at times downright unfriendly.
+
+The B<ca> utility was originally meant as an example of how to do things
+in a CA. It was not supposed to be used as a full blown CA itself:
+nevertheless some people are using it for this purpose.
+
+The B<ca> command is effectively a single user command: no locking is
+done on the various files and attempts to run more than one B<ca> command
+on the same database can have unpredictable results.
+
+The B<copy_extensions> option should be used with caution. If care is
+not taken then it can be a security risk. For example if a certificate
+request contains a basicConstraints extension with CA:TRUE and the
+B<copy_extensions> value is set to B<copyall> and the user does not spot
+this when the certificate is displayed then this will hand the requestor
+a valid CA certificate.
+
+This situation can be avoided by setting B<copy_extensions> to B<copy>
+and including basicConstraints with CA:FALSE in the configuration file.
+Then if the request contains a basicConstraints extension it will be
+ignored.
+
+It is advisable to also include values for other extensions such
+as B<keyUsage> to prevent a request supplying its own values.
+
+Additional restrictions can be placed on the CA certificate itself.
+For example if the CA certificate has:
+
+ basicConstraints = CA:TRUE, pathlen:0
+
+then even if a certificate is issued with CA:TRUE it will not be valid.
+
+=head1 SEE ALSO
+
+L<req(1)|req(1)>, L<spkac(1)|spkac(1)>, L<x509(1)|x509(1)>, L<CA.pl(1)|CA.pl(1)>,
+L<config(5)|config(5)>, L<x509v3_config(5)|x509v3_config(5)> 
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/ciphers.pod b/deps/openssl/openssl/doc/apps/ciphers.pod
new file mode 100644 (file)
index 0000000..f44aa00
--- /dev/null
@@ -0,0 +1,478 @@
+=pod
+
+=head1 NAME
+
+ciphers - SSL cipher display and cipher list tool.
+
+=head1 SYNOPSIS
+
+B<openssl> B<ciphers>
+[B<-v>]
+[B<-V>]
+[B<-ssl2>]
+[B<-ssl3>]
+[B<-tls1>]
+[B<cipherlist>]
+
+=head1 DESCRIPTION
+
+The B<ciphers> command converts textual OpenSSL cipher lists into ordered
+SSL cipher preference lists. It can be used as a test tool to determine
+the appropriate cipherlist.
+
+=head1 COMMAND OPTIONS
+
+=over 4
+
+=item B<-v>
+
+Verbose option. List ciphers with a complete description of
+protocol version (SSLv2 or SSLv3; the latter includes TLS), key exchange,
+authentication, encryption and mac algorithms used along with any key size
+restrictions and whether the algorithm is classed as an "export" cipher.
+Note that without the B<-v> option, ciphers may seem to appear twice
+in a cipher list; this is when similar ciphers are available for
+SSL v2 and for SSL v3/TLS v1.
+
+=item B<-V>
+
+Like B<-V>, but include cipher suite codes in output (hex format).
+
+=item B<-ssl3>
+
+only include SSL v3 ciphers.
+
+=item B<-ssl2>
+
+only include SSL v2 ciphers.
+
+=item B<-tls1>
+
+only include TLS v1 ciphers.
+
+=item B<-h>, B<-?>
+
+print a brief usage message.
+
+=item B<cipherlist>
+
+a cipher list to convert to a cipher preference list. If it is not included
+then the default cipher list will be used. The format is described below.
+
+=back
+
+=head1 CIPHER LIST FORMAT
+
+The cipher list consists of one or more I<cipher strings> separated by colons.
+Commas or spaces are also acceptable separators but colons are normally used.
+
+The actual cipher string can take several different forms.
+
+It can consist of a single cipher suite such as B<RC4-SHA>.
+
+It can represent a list of cipher suites containing a certain algorithm, or
+cipher suites of a certain type. For example B<SHA1> represents all ciphers
+suites using the digest algorithm SHA1 and B<SSLv3> represents all SSL v3
+algorithms.
+
+Lists of cipher suites can be combined in a single cipher string using the
+B<+> character. This is used as a logical B<and> operation. For example
+B<SHA1+DES> represents all cipher suites containing the SHA1 B<and> the DES
+algorithms.
+
+Each cipher string can be optionally preceded by the characters B<!>,
+B<-> or B<+>.
+
+If B<!> is used then the ciphers are permanently deleted from the list.
+The ciphers deleted can never reappear in the list even if they are
+explicitly stated.
+
+If B<-> is used then the ciphers are deleted from the list, but some or
+all of the ciphers can be added again by later options.
+
+If B<+> is used then the ciphers are moved to the end of the list. This
+option doesn't add any new ciphers it just moves matching existing ones.
+
+If none of these characters is present then the string is just interpreted
+as a list of ciphers to be appended to the current preference list. If the
+list includes any ciphers already present they will be ignored: that is they
+will not moved to the end of the list.
+
+Additionally the cipher string B<@STRENGTH> can be used at any point to sort
+the current cipher list in order of encryption algorithm key length.
+
+=head1 CIPHER STRINGS
+
+The following is a list of all permitted cipher strings and their meanings.
+
+=over 4
+
+=item B<DEFAULT>
+
+the default cipher list. This is determined at compile time and, as of OpenSSL
+1.0.0, is normally B<ALL:!aNULL:!eNULL>. This must be the first cipher string
+specified.
+
+=item B<COMPLEMENTOFDEFAULT>
+
+the ciphers included in B<ALL>, but not enabled by default. Currently
+this is B<ADH>. Note that this rule does not cover B<eNULL>, which is
+not included by B<ALL> (use B<COMPLEMENTOFALL> if necessary).
+
+=item B<ALL>
+
+all cipher suites except the B<eNULL> ciphers which must be explicitly enabled;
+as of OpenSSL, the B<ALL> cipher suites are reasonably ordered by default
+
+=item B<COMPLEMENTOFALL>
+
+the cipher suites not enabled by B<ALL>, currently being B<eNULL>.
+
+=item B<HIGH>
+
+"high" encryption cipher suites. This currently means those with key lengths larger
+than 128 bits, and some cipher suites with 128-bit keys.
+
+=item B<MEDIUM>
+
+"medium" encryption cipher suites, currently some of those using 128 bit encryption.
+
+=item B<LOW>
+
+"low" encryption cipher suites, currently those using 64 or 56 bit encryption algorithms
+but excluding export cipher suites.
+
+=item B<EXP>, B<EXPORT>
+
+export encryption algorithms. Including 40 and 56 bits algorithms.
+
+=item B<EXPORT40>
+
+40 bit export encryption algorithms
+
+=item B<EXPORT56>
+
+56 bit export encryption algorithms. In OpenSSL 0.9.8c and later the set of
+56 bit export ciphers is empty unless OpenSSL has been explicitly configured
+with support for experimental ciphers.
+
+=item B<eNULL>, B<NULL>
+
+the "NULL" ciphers that is those offering no encryption. Because these offer no
+encryption at all and are a security risk they are disabled unless explicitly
+included.
+
+=item B<aNULL>
+
+the cipher suites offering no authentication. This is currently the anonymous
+DH algorithms. These cipher suites are vulnerable to a "man in the middle"
+attack and so their use is normally discouraged.
+
+=item B<kRSA>, B<RSA>
+
+cipher suites using RSA key exchange.
+
+=item B<kEDH>
+
+cipher suites using ephemeral DH key agreement.
+
+=item B<kDHr>, B<kDHd>
+
+cipher suites using DH key agreement and DH certificates signed by CAs with RSA
+and DSS keys respectively. Not implemented.
+
+=item B<aRSA>
+
+cipher suites using RSA authentication, i.e. the certificates carry RSA keys.
+
+=item B<aDSS>, B<DSS>
+
+cipher suites using DSS authentication, i.e. the certificates carry DSS keys.
+
+=item B<aDH>
+
+cipher suites effectively using DH authentication, i.e. the certificates carry
+DH keys.  Not implemented.
+
+=item B<kFZA>, B<aFZA>, B<eFZA>, B<FZA>
+
+ciphers suites using FORTEZZA key exchange, authentication, encryption or all
+FORTEZZA algorithms. Not implemented.
+
+=item B<TLSv1>, B<SSLv3>, B<SSLv2>
+
+TLS v1.0, SSL v3.0 or SSL v2.0 cipher suites respectively.
+
+=item B<DH>
+
+cipher suites using DH, including anonymous DH.
+
+=item B<ADH>
+
+anonymous DH cipher suites.
+
+=item B<AES>
+
+cipher suites using AES.
+
+=item B<CAMELLIA>
+
+cipher suites using Camellia.
+
+=item B<3DES>
+
+cipher suites using triple DES.
+
+=item B<DES>
+
+cipher suites using DES (not triple DES).
+
+=item B<RC4>
+
+cipher suites using RC4.
+
+=item B<RC2>
+
+cipher suites using RC2.
+
+=item B<IDEA>
+
+cipher suites using IDEA.
+
+=item B<SEED>
+
+cipher suites using SEED.
+
+=item B<MD5>
+
+cipher suites using MD5.
+
+=item B<SHA1>, B<SHA>
+
+cipher suites using SHA1.
+
+=item B<aGOST> 
+
+cipher suites using GOST R 34.10 (either 2001 or 94) for authenticaction
+(needs an engine supporting GOST algorithms). 
+
+=item B<aGOST01>
+
+cipher suites using GOST R 34.10-2001 authentication.
+
+=item B<aGOST94>
+
+cipher suites using GOST R 34.10-94 authentication (note that R 34.10-94
+standard has been expired so use GOST R 34.10-2001)
+
+=item B<kGOST>
+
+cipher suites, using VKO 34.10 key exchange, specified in the RFC 4357.
+
+=item B<GOST94>
+
+cipher suites, using HMAC based on GOST R 34.11-94.
+
+=item B<GOST89MAC>
+
+cipher suites using GOST 28147-89 MAC B<instead of> HMAC.
+
+
+=back
+
+=head1 CIPHER SUITE NAMES
+
+The following lists give the SSL or TLS cipher suites names from the
+relevant specification and their OpenSSL equivalents. It should be noted,
+that several cipher suite names do not include the authentication used,
+e.g. DES-CBC3-SHA. In these cases, RSA authentication is used.
+
+=head2 SSL v3.0 cipher suites.
+
+ SSL_RSA_WITH_NULL_MD5                   NULL-MD5
+ SSL_RSA_WITH_NULL_SHA                   NULL-SHA
+ SSL_RSA_EXPORT_WITH_RC4_40_MD5          EXP-RC4-MD5
+ SSL_RSA_WITH_RC4_128_MD5                RC4-MD5
+ SSL_RSA_WITH_RC4_128_SHA                RC4-SHA
+ SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5      EXP-RC2-CBC-MD5
+ SSL_RSA_WITH_IDEA_CBC_SHA               IDEA-CBC-SHA
+ SSL_RSA_EXPORT_WITH_DES40_CBC_SHA       EXP-DES-CBC-SHA
+ SSL_RSA_WITH_DES_CBC_SHA                DES-CBC-SHA
+ SSL_RSA_WITH_3DES_EDE_CBC_SHA           DES-CBC3-SHA
+
+ SSL_DH_DSS_EXPORT_WITH_DES40_CBC_SHA    Not implemented.
+ SSL_DH_DSS_WITH_DES_CBC_SHA             Not implemented.
+ SSL_DH_DSS_WITH_3DES_EDE_CBC_SHA        Not implemented.
+ SSL_DH_RSA_EXPORT_WITH_DES40_CBC_SHA    Not implemented.
+ SSL_DH_RSA_WITH_DES_CBC_SHA             Not implemented.
+ SSL_DH_RSA_WITH_3DES_EDE_CBC_SHA        Not implemented.
+ SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA   EXP-EDH-DSS-DES-CBC-SHA
+ SSL_DHE_DSS_WITH_DES_CBC_SHA            EDH-DSS-CBC-SHA
+ SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA       EDH-DSS-DES-CBC3-SHA
+ SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA   EXP-EDH-RSA-DES-CBC-SHA
+ SSL_DHE_RSA_WITH_DES_CBC_SHA            EDH-RSA-DES-CBC-SHA
+ SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA       EDH-RSA-DES-CBC3-SHA
+
+ SSL_DH_anon_EXPORT_WITH_RC4_40_MD5      EXP-ADH-RC4-MD5
+ SSL_DH_anon_WITH_RC4_128_MD5            ADH-RC4-MD5
+ SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA   EXP-ADH-DES-CBC-SHA
+ SSL_DH_anon_WITH_DES_CBC_SHA            ADH-DES-CBC-SHA
+ SSL_DH_anon_WITH_3DES_EDE_CBC_SHA       ADH-DES-CBC3-SHA
+
+ SSL_FORTEZZA_KEA_WITH_NULL_SHA          Not implemented.
+ SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA  Not implemented.
+ SSL_FORTEZZA_KEA_WITH_RC4_128_SHA       Not implemented.
+
+=head2 TLS v1.0 cipher suites.
+
+ TLS_RSA_WITH_NULL_MD5                   NULL-MD5
+ TLS_RSA_WITH_NULL_SHA                   NULL-SHA
+ TLS_RSA_EXPORT_WITH_RC4_40_MD5          EXP-RC4-MD5
+ TLS_RSA_WITH_RC4_128_MD5                RC4-MD5
+ TLS_RSA_WITH_RC4_128_SHA                RC4-SHA
+ TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5      EXP-RC2-CBC-MD5
+ TLS_RSA_WITH_IDEA_CBC_SHA               IDEA-CBC-SHA
+ TLS_RSA_EXPORT_WITH_DES40_CBC_SHA       EXP-DES-CBC-SHA
+ TLS_RSA_WITH_DES_CBC_SHA                DES-CBC-SHA
+ TLS_RSA_WITH_3DES_EDE_CBC_SHA           DES-CBC3-SHA
+
+ TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA    Not implemented.
+ TLS_DH_DSS_WITH_DES_CBC_SHA             Not implemented.
+ TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA        Not implemented.
+ TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA    Not implemented.
+ TLS_DH_RSA_WITH_DES_CBC_SHA             Not implemented.
+ TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA        Not implemented.
+ TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA   EXP-EDH-DSS-DES-CBC-SHA
+ TLS_DHE_DSS_WITH_DES_CBC_SHA            EDH-DSS-CBC-SHA
+ TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA       EDH-DSS-DES-CBC3-SHA
+ TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA   EXP-EDH-RSA-DES-CBC-SHA
+ TLS_DHE_RSA_WITH_DES_CBC_SHA            EDH-RSA-DES-CBC-SHA
+ TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA       EDH-RSA-DES-CBC3-SHA
+
+ TLS_DH_anon_EXPORT_WITH_RC4_40_MD5      EXP-ADH-RC4-MD5
+ TLS_DH_anon_WITH_RC4_128_MD5            ADH-RC4-MD5
+ TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA   EXP-ADH-DES-CBC-SHA
+ TLS_DH_anon_WITH_DES_CBC_SHA            ADH-DES-CBC-SHA
+ TLS_DH_anon_WITH_3DES_EDE_CBC_SHA       ADH-DES-CBC3-SHA
+
+=head2 AES ciphersuites from RFC3268, extending TLS v1.0
+
+ TLS_RSA_WITH_AES_128_CBC_SHA            AES128-SHA
+ TLS_RSA_WITH_AES_256_CBC_SHA            AES256-SHA
+
+ TLS_DH_DSS_WITH_AES_128_CBC_SHA         Not implemented.
+ TLS_DH_DSS_WITH_AES_256_CBC_SHA         Not implemented.
+ TLS_DH_RSA_WITH_AES_128_CBC_SHA         Not implemented.
+ TLS_DH_RSA_WITH_AES_256_CBC_SHA         Not implemented.
+
+ TLS_DHE_DSS_WITH_AES_128_CBC_SHA        DHE-DSS-AES128-SHA
+ TLS_DHE_DSS_WITH_AES_256_CBC_SHA        DHE-DSS-AES256-SHA
+ TLS_DHE_RSA_WITH_AES_128_CBC_SHA        DHE-RSA-AES128-SHA
+ TLS_DHE_RSA_WITH_AES_256_CBC_SHA        DHE-RSA-AES256-SHA
+
+ TLS_DH_anon_WITH_AES_128_CBC_SHA        ADH-AES128-SHA
+ TLS_DH_anon_WITH_AES_256_CBC_SHA        ADH-AES256-SHA
+
+=head2 Camellia ciphersuites from RFC4132, extending TLS v1.0
+
+ TLS_RSA_WITH_CAMELLIA_128_CBC_SHA      CAMELLIA128-SHA
+ TLS_RSA_WITH_CAMELLIA_256_CBC_SHA      CAMELLIA256-SHA
+
+ TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA   Not implemented.
+ TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA   Not implemented.
+ TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA   Not implemented.
+ TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA   Not implemented.
+
+ TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA  DHE-DSS-CAMELLIA128-SHA
+ TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA  DHE-DSS-CAMELLIA256-SHA
+ TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA  DHE-RSA-CAMELLIA128-SHA
+ TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA  DHE-RSA-CAMELLIA256-SHA
+
+ TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA  ADH-CAMELLIA128-SHA
+ TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA  ADH-CAMELLIA256-SHA
+
+=head2 SEED ciphersuites from RFC4162, extending TLS v1.0
+
+ TLS_RSA_WITH_SEED_CBC_SHA              SEED-SHA
+
+ TLS_DH_DSS_WITH_SEED_CBC_SHA           Not implemented.
+ TLS_DH_RSA_WITH_SEED_CBC_SHA           Not implemented.
+
+ TLS_DHE_DSS_WITH_SEED_CBC_SHA          DHE-DSS-SEED-SHA
+ TLS_DHE_RSA_WITH_SEED_CBC_SHA          DHE-RSA-SEED-SHA
+
+ TLS_DH_anon_WITH_SEED_CBC_SHA          ADH-SEED-SHA
+
+=head2 GOST ciphersuites from draft-chudov-cryptopro-cptls, extending TLS v1.0
+
+Note: these ciphers require an engine which including GOST cryptographic
+algorithms, such as the B<ccgost> engine, included in the OpenSSL distribution.
+
+ TLS_GOSTR341094_WITH_28147_CNT_IMIT GOST94-GOST89-GOST89
+ TLS_GOSTR341001_WITH_28147_CNT_IMIT GOST2001-GOST89-GOST89
+ TLS_GOSTR341094_WITH_NULL_GOSTR3411 GOST94-NULL-GOST94
+ TLS_GOSTR341001_WITH_NULL_GOSTR3411 GOST2001-NULL-GOST94
+
+=head2 Additional Export 1024 and other cipher suites
+
+Note: these ciphers can also be used in SSL v3.
+
+ TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA     EXP1024-DES-CBC-SHA
+ TLS_RSA_EXPORT1024_WITH_RC4_56_SHA      EXP1024-RC4-SHA
+ TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA EXP1024-DHE-DSS-DES-CBC-SHA
+ TLS_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA  EXP1024-DHE-DSS-RC4-SHA
+ TLS_DHE_DSS_WITH_RC4_128_SHA            DHE-DSS-RC4-SHA
+
+=head2 SSL v2.0 cipher suites.
+
+ SSL_CK_RC4_128_WITH_MD5                 RC4-MD5
+ SSL_CK_RC4_128_EXPORT40_WITH_MD5        EXP-RC4-MD5
+ SSL_CK_RC2_128_CBC_WITH_MD5             RC2-MD5
+ SSL_CK_RC2_128_CBC_EXPORT40_WITH_MD5    EXP-RC2-MD5
+ SSL_CK_IDEA_128_CBC_WITH_MD5            IDEA-CBC-MD5
+ SSL_CK_DES_64_CBC_WITH_MD5              DES-CBC-MD5
+ SSL_CK_DES_192_EDE3_CBC_WITH_MD5        DES-CBC3-MD5
+
+=head1 NOTES
+
+The non-ephemeral DH modes are currently unimplemented in OpenSSL
+because there is no support for DH certificates.
+
+Some compiled versions of OpenSSL may not include all the ciphers
+listed here because some ciphers were excluded at compile time.
+
+=head1 EXAMPLES
+
+Verbose listing of all OpenSSL ciphers including NULL ciphers:
+
+ openssl ciphers -v 'ALL:eNULL'
+
+Include all ciphers except NULL and anonymous DH then sort by
+strength:
+
+ openssl ciphers -v 'ALL:!ADH:@STRENGTH'
+
+Include only 3DES ciphers and then place RSA ciphers last:
+
+ openssl ciphers -v '3DES:+RSA'
+
+Include all RC4 ciphers but leave out those without authentication:
+
+ openssl ciphers -v 'RC4:!COMPLEMENTOFDEFAULT'
+
+Include all chiphers with RSA authentication but leave out ciphers without
+encryption.
+
+ openssl ciphers -v 'RSA:!COMPLEMENTOFALL'
+
+=head1 SEE ALSO
+
+L<s_client(1)|s_client(1)>, L<s_server(1)|s_server(1)>, L<ssl(3)|ssl(3)>
+
+=head1 HISTORY
+
+The B<COMPLENTOFALL> and B<COMPLEMENTOFDEFAULT> selection options
+for cipherlist strings were added in OpenSSL 0.9.7.
+The B<-V> option for the B<ciphers> command was added in OpenSSL 1.0.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/cms.pod b/deps/openssl/openssl/doc/apps/cms.pod
new file mode 100644 (file)
index 0000000..a09588a
--- /dev/null
@@ -0,0 +1,602 @@
+=pod
+
+=head1 NAME
+
+cms - CMS utility
+
+=head1 SYNOPSIS
+
+B<openssl> B<cms>
+[B<-encrypt>]
+[B<-decrypt>]
+[B<-sign>]
+[B<-verify>]
+[B<-cmsout>]
+[B<-resign>]
+[B<-data_create>]
+[B<-data_out>]
+[B<-digest_create>]
+[B<-digest_verify>]
+[B<-compress>]
+[B<-uncompress>]
+[B<-EncryptedData_encrypt>]
+[B<-sign_receipt>]
+[B<-verify_receipt receipt>]
+[B<-in filename>]
+[B<-inform SMIME|PEM|DER>]
+[B<-rctform SMIME|PEM|DER>]
+[B<-out filename>]
+[B<-outform SMIME|PEM|DER>]
+[B<-stream -indef -noindef>]
+[B<-noindef>]
+[B<-content filename>]
+[B<-text>]
+[B<-noout>]
+[B<-print>]
+[B<-CAfile file>]
+[B<-CApath dir>]
+[B<-md digest>]
+[B<-[cipher]>]
+[B<-nointern>]
+[B<-no_signer_cert_verify>]
+[B<-nocerts>]
+[B<-noattr>]
+[B<-nosmimecap>]
+[B<-binary>]
+[B<-nodetach>]
+[B<-certfile file>]
+[B<-certsout file>]
+[B<-signer file>]
+[B<-recip file>]
+[B<-keyid>]
+[B<-receipt_request_all -receipt_request_first>]
+[B<-receipt_request_from emailaddress>]
+[B<-receipt_request_to emailaddress>]
+[B<-receipt_request_print>]
+[B<-secretkey key>]
+[B<-secretkeyid id>]
+[B<-econtent_type type>]
+[B<-inkey file>]
+[B<-passin arg>]
+[B<-rand file(s)>]
+[B<cert.pem...>]
+[B<-to addr>]
+[B<-from addr>]
+[B<-subject subj>]
+[cert.pem]...
+
+=head1 DESCRIPTION
+
+The B<cms> command handles S/MIME v3.1 mail. It can encrypt, decrypt, sign and
+verify, compress and uncompress S/MIME messages.
+
+=head1 COMMAND OPTIONS
+
+There are fourteen operation options that set the type of operation to be
+performed. The meaning of the other options varies according to the operation
+type.
+
+=over 4
+
+=item B<-encrypt>
+
+encrypt mail for the given recipient certificates. Input file is the message
+to be encrypted. The output file is the encrypted mail in MIME format. The
+actual CMS type is <B>EnvelopedData<B>.
+
+=item B<-decrypt>
+
+decrypt mail using the supplied certificate and private key. Expects an
+encrypted mail message in MIME format for the input file. The decrypted mail
+is written to the output file.
+
+=item B<-sign>
+
+sign mail using the supplied certificate and private key. Input file is
+the message to be signed. The signed message in MIME format is written
+to the output file.
+
+=item B<-verify>
+
+verify signed mail. Expects a signed mail message on input and outputs
+the signed data. Both clear text and opaque signing is supported.
+
+=item B<-cmsout>
+
+takes an input message and writes out a PEM encoded CMS structure.
+
+=item B<-resign>
+
+resign a message: take an existing message and one or more new signers.
+
+=item B<-data_create>
+
+Create a CMS B<Data> type.
+
+=item B<-data_out>
+
+B<Data> type and output the content.
+
+=item B<-digest_create>
+
+Create a CMS B<DigestedData> type.
+
+=item B<-digest_verify>
+
+Verify a CMS B<DigestedData> type and output the content.
+
+=item B<-compress>
+
+Create a CMS B<CompressedData> type. OpenSSL must be compiled with B<zlib>
+support for this option to work, otherwise it will output an error.
+
+=item B<-uncompress>
+
+Uncompress a CMS B<CompressedData> type and output the content. OpenSSL must be
+compiled with B<zlib> support for this option to work, otherwise it will
+output an error.
+
+=item B<-EncryptedData_encrypt>
+
+Encrypt suppled content using supplied symmetric key and algorithm using a CMS
+B<EncrytedData> type and output the content.
+
+=item B<-sign_receipt>
+
+Generate and output a signed receipt for the supplied message. The input 
+message B<must> contain a signed receipt request. Functionality is otherwise
+similar to the B<-sign> operation.
+
+=item B<-verify_receipt receipt>
+
+Verify a signed receipt in filename B<receipt>. The input message B<must> 
+contain the original receipt request. Functionality is otherwise similar
+to the B<-verify> operation.
+
+=item B<-in filename>
+
+the input message to be encrypted or signed or the message to be decrypted
+or verified.
+
+=item B<-inform SMIME|PEM|DER>
+
+this specifies the input format for the CMS structure. The default
+is B<SMIME> which reads an S/MIME format message. B<PEM> and B<DER>
+format change this to expect PEM and DER format CMS structures
+instead. This currently only affects the input format of the CMS
+structure, if no CMS structure is being input (for example with
+B<-encrypt> or B<-sign>) this option has no effect.
+
+=item B<-rctform SMIME|PEM|DER>
+
+specify the format for a signed receipt for use with the B<-receipt_verify>
+operation.
+
+=item B<-out filename>
+
+the message text that has been decrypted or verified or the output MIME
+format message that has been signed or verified.
+
+=item B<-outform SMIME|PEM|DER>
+
+this specifies the output format for the CMS structure. The default
+is B<SMIME> which writes an S/MIME format message. B<PEM> and B<DER>
+format change this to write PEM and DER format CMS structures
+instead. This currently only affects the output format of the CMS
+structure, if no CMS structure is being output (for example with
+B<-verify> or B<-decrypt>) this option has no effect.
+
+=item B<-stream -indef -noindef>
+
+the B<-stream> and B<-indef> options are equivalent and enable streaming I/O
+for encoding operations. This permits single pass processing of data without
+the need to hold the entire contents in memory, potentially supporting very
+large files. Streaming is automatically set for S/MIME signing with detached
+data if the output format is B<SMIME> it is currently off by default for all
+other operations.
+
+=item B<-noindef>
+
+disable streaming I/O where it would produce and indefinite length constructed
+encoding. This option currently has no effect. In future streaming will be
+enabled by default on all relevant operations and this option will disable it.
+
+=item B<-content filename>
+
+This specifies a file containing the detached content, this is only
+useful with the B<-verify> command. This is only usable if the CMS
+structure is using the detached signature form where the content is
+not included. This option will override any content if the input format
+is S/MIME and it uses the multipart/signed MIME content type.
+
+=item B<-text>
+
+this option adds plain text (text/plain) MIME headers to the supplied
+message if encrypting or signing. If decrypting or verifying it strips
+off text headers: if the decrypted or verified message is not of MIME 
+type text/plain then an error occurs.
+
+=item B<-noout>
+
+for the B<-cmsout> operation do not output the parsed CMS structure. This
+is useful when combined with the B<-print> option or if the syntax of the CMS
+structure is being checked.
+
+=item B<-print>
+
+for the B<-cmsout> operation print out all fields of the CMS structure. This
+is mainly useful for testing purposes.
+
+=item B<-CAfile file>
+
+a file containing trusted CA certificates, only used with B<-verify>.
+
+=item B<-CApath dir>
+
+a directory containing trusted CA certificates, only used with
+B<-verify>. This directory must be a standard certificate directory: that
+is a hash of each subject name (using B<x509 -hash>) should be linked
+to each certificate.
+
+=item B<-md digest>
+
+digest algorithm to use when signing or resigning. If not present then the
+default digest algorithm for the signing key will be used (usually SHA1).
+
+=item B<-[cipher]>
+
+the encryption algorithm to use. For example triple DES (168 bits) - B<-des3>
+or 256 bit AES - B<-aes256>. Any standard algorithm name (as used by the
+EVP_get_cipherbyname() function) can also be used preceded by a dash, for 
+example B<-aes_128_cbc>. See L<B<enc>|enc(1)> for a list of ciphers
+supported by your version of OpenSSL.
+
+If not specified triple DES is used. Only used with B<-encrypt> and 
+B<-EncryptedData_create> commands.
+
+=item B<-nointern>
+
+when verifying a message normally certificates (if any) included in
+the message are searched for the signing certificate. With this option
+only the certificates specified in the B<-certfile> option are used.
+The supplied certificates can still be used as untrusted CAs however.
+
+=item B<-no_signer_cert_verify>
+
+do not verify the signers certificate of a signed message.
+
+=item B<-nocerts>
+
+when signing a message the signer's certificate is normally included
+with this option it is excluded. This will reduce the size of the
+signed message but the verifier must have a copy of the signers certificate
+available locally (passed using the B<-certfile> option for example).
+
+=item B<-noattr>
+
+normally when a message is signed a set of attributes are included which
+include the signing time and supported symmetric algorithms. With this
+option they are not included.
+
+=item B<-nosmimecap>
+
+exclude the list of supported algorithms from signed attributes, other options
+such as signing time and content type are still included.
+
+=item B<-binary>
+
+normally the input message is converted to "canonical" format which is
+effectively using CR and LF as end of line: as required by the S/MIME
+specification. When this option is present no translation occurs. This
+is useful when handling binary data which may not be in MIME format.
+
+=item B<-nodetach>
+
+when signing a message use opaque signing: this form is more resistant
+to translation by mail relays but it cannot be read by mail agents that
+do not support S/MIME.  Without this option cleartext signing with
+the MIME type multipart/signed is used.
+
+=item B<-certfile file>
+
+allows additional certificates to be specified. When signing these will
+be included with the message. When verifying these will be searched for
+the signers certificates. The certificates should be in PEM format.
+
+=item B<-certsout file>
+
+any certificates contained in the message are written to B<file>.
+
+=item B<-signer file>
+
+a signing certificate when signing or resigning a message, this option can be
+used multiple times if more than one signer is required. If a message is being
+verified then the signers certificates will be written to this file if the
+verification was successful.
+
+=item B<-recip file>
+
+the recipients certificate when decrypting a message. This certificate
+must match one of the recipients of the message or an error occurs.
+
+=item B<-keyid>
+
+use subject key identifier to identify certificates instead of issuer name and
+serial number. The supplied certificate B<must> include a subject key
+identifier extension. Supported by B<-sign> and B<-encrypt> options.
+
+=item B<-receipt_request_all -receipt_request_first>
+
+for B<-sign> option include a signed receipt request. Indicate requests should
+be provided by all receipient or first tier recipients (those mailed directly
+and not from a mailing list). Ignored it B<-receipt_request_from> is included.
+
+=item B<-receipt_request_from emailaddress>
+
+for B<-sign> option include a signed receipt request. Add an explicit email
+address where receipts should be supplied.
+
+=item B<-receipt_request_to emailaddress>
+
+Add an explicit email address where signed receipts should be sent to. This 
+option B<must> but supplied if a signed receipt it requested.
+
+=item B<-receipt_request_print>
+
+For the B<-verify> operation print out the contents of any signed receipt
+requests.
+
+=item B<-secretkey key>
+
+specify symmetric key to use. The key must be supplied in hex format and be
+consistent with the algorithm used. Supported by the B<-EncryptedData_encrypt>
+B<-EncrryptedData_decrypt>, B<-encrypt> and B<-decrypt> options. When used
+with B<-encrypt> or B<-decrypt> the supplied key is used to wrap or unwrap the
+content encryption key using an AES key in the B<KEKRecipientInfo> type.
+
+=item B<-secretkeyid id>
+
+the key identifier for the supplied symmetric key for B<KEKRecipientInfo> type.
+This option B<must> be present if the B<-secretkey> option is used with
+B<-encrypt>. With B<-decrypt> operations the B<id> is used to locate the
+relevant key if it is not supplied then an attempt is used to decrypt any
+B<KEKRecipientInfo> structures.
+
+=item B<-econtent_type type>
+
+set the encapsulated content type to B<type> if not supplied the B<Data> type
+is used. The B<type> argument can be any valid OID name in either text or
+numerical format. 
+
+=item B<-inkey file>
+
+the private key to use when signing or decrypting. This must match the
+corresponding certificate. If this option is not specified then the
+private key must be included in the certificate file specified with
+the B<-recip> or B<-signer> file. When signing this option can be used
+multiple times to specify successive keys.
+
+=item B<-passin arg>
+
+the private key password source. For more information about the format of B<arg>
+see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
+
+=item B<-rand file(s)>
+
+a file or files containing random data used to seed the random number
+generator, or an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
+Multiple files can be specified separated by a OS-dependent character.
+The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
+all others.
+
+=item B<cert.pem...>
+
+one or more certificates of message recipients: used when encrypting
+a message. 
+
+=item B<-to, -from, -subject>
+
+the relevant mail headers. These are included outside the signed
+portion of a message so they may be included manually. If signing
+then many S/MIME mail clients check the signers certificate's email
+address matches that specified in the From: address.
+
+=item B<-purpose, -ignore_critical, -issuer_checks, -crl_check, -crl_check_all, -policy_check, -extended_crl, -x509_strict, -policy -check_ss_sig>
+
+Set various certificate chain valiadition option. See the
+L<B<verify>|verify(1)> manual page for details.
+
+=back
+
+=head1 NOTES
+
+The MIME message must be sent without any blank lines between the
+headers and the output. Some mail programs will automatically add
+a blank line. Piping the mail directly to sendmail is one way to
+achieve the correct format.
+
+The supplied message to be signed or encrypted must include the
+necessary MIME headers or many S/MIME clients wont display it
+properly (if at all). You can use the B<-text> option to automatically
+add plain text headers.
+
+A "signed and encrypted" message is one where a signed message is
+then encrypted. This can be produced by encrypting an already signed
+message: see the examples section.
+
+This version of the program only allows one signer per message but it
+will verify multiple signers on received messages. Some S/MIME clients
+choke if a message contains multiple signers. It is possible to sign
+messages "in parallel" by signing an already signed message.
+
+The options B<-encrypt> and B<-decrypt> reflect common usage in S/MIME
+clients. Strictly speaking these process CMS enveloped data: CMS
+encrypted data is used for other purposes.
+
+The B<-resign> option uses an existing message digest when adding a new
+signer. This means that attributes must be present in at least one existing
+signer using the same message digest or this operation will fail.
+
+The B<-stream> and B<-indef> options enable experimental streaming I/O support.
+As a result the encoding is BER using indefinite length constructed encoding
+and no longer DER. Streaming is supported for the B<-encrypt> operation and the
+B<-sign> operation if the content is not detached.
+
+Streaming is always used for the B<-sign> operation with detached data but
+since the content is no longer part of the CMS structure the encoding
+remains DER.
+
+=head1 EXIT CODES
+
+=over 4
+
+=item 0
+
+the operation was completely successfully.
+
+=item 1 
+
+an error occurred parsing the command options.
+
+=item 2
+
+one of the input files could not be read.
+
+=item 3
+
+an error occurred creating the CMS file or when reading the MIME
+message.
+
+=item 4
+
+an error occurred decrypting or verifying the message.
+
+=item 5
+
+the message was verified correctly but an error occurred writing out
+the signers certificates.
+
+=back
+
+=head1 COMPATIBILITY WITH PKCS#7 format.
+
+The B<smime> utility can only process the older B<PKCS#7> format. The B<cms>
+utility supports Cryptographic Message Syntax format. Use of some features
+will result in messages which cannot be processed by applications which only
+support the older format. These are detailed below.
+
+The use of the B<-keyid> option with B<-sign> or B<-encrypt>.
+
+The B<-outform PEM> option uses different headers.
+
+The B<-compress> option.
+
+The B<-secretkey> option when used with B<-encrypt>.
+
+Additionally the B<-EncryptedData_create> and B<-data_create> type cannot
+be processed by the older B<smime> command.
+
+=head1 EXAMPLES
+
+Create a cleartext signed message:
+
+ openssl cms -sign -in message.txt -text -out mail.msg \
+       -signer mycert.pem
+
+Create an opaque signed message
+
+ openssl cms -sign -in message.txt -text -out mail.msg -nodetach \
+       -signer mycert.pem
+
+Create a signed message, include some additional certificates and
+read the private key from another file:
+
+ openssl cms -sign -in in.txt -text -out mail.msg \
+       -signer mycert.pem -inkey mykey.pem -certfile mycerts.pem
+
+Create a signed message with two signers, use key identifier:
+
+ openssl cms -sign -in message.txt -text -out mail.msg \
+       -signer mycert.pem -signer othercert.pem -keyid
+
+Send a signed message under Unix directly to sendmail, including headers:
+
+ openssl cms -sign -in in.txt -text -signer mycert.pem \
+       -from steve@openssl.org -to someone@somewhere \
+       -subject "Signed message" | sendmail someone@somewhere
+
+Verify a message and extract the signer's certificate if successful:
+
+ openssl cms -verify -in mail.msg -signer user.pem -out signedtext.txt
+
+Send encrypted mail using triple DES:
+
+ openssl cms -encrypt -in in.txt -from steve@openssl.org \
+       -to someone@somewhere -subject "Encrypted message" \
+       -des3 user.pem -out mail.msg
+
+Sign and encrypt mail:
+
+ openssl cms -sign -in ml.txt -signer my.pem -text \
+       | openssl cms -encrypt -out mail.msg \
+       -from steve@openssl.org -to someone@somewhere \
+       -subject "Signed and Encrypted message" -des3 user.pem
+
+Note: the encryption command does not include the B<-text> option because the
+message being encrypted already has MIME headers.
+
+Decrypt mail:
+
+ openssl cms -decrypt -in mail.msg -recip mycert.pem -inkey key.pem
+
+The output from Netscape form signing is a PKCS#7 structure with the
+detached signature format. You can use this program to verify the
+signature by line wrapping the base64 encoded structure and surrounding
+it with:
+
+ -----BEGIN PKCS7-----
+ -----END PKCS7-----
+
+and using the command, 
+
+ openssl cms -verify -inform PEM -in signature.pem -content content.txt
+
+alternatively you can base64 decode the signature and use
+
+ openssl cms -verify -inform DER -in signature.der -content content.txt
+
+Create an encrypted message using 128 bit Camellia:
+
+ openssl cms -encrypt -in plain.txt -camellia128 -out mail.msg cert.pem
+
+Add a signer to an existing message:
+
+ openssl cms -resign -in mail.msg -signer newsign.pem -out mail2.msg
+
+=head1 BUGS
+
+The MIME parser isn't very clever: it seems to handle most messages that I've
+thrown at it but it may choke on others.
+
+The code currently will only write out the signer's certificate to a file: if
+the signer has a separate encryption certificate this must be manually
+extracted. There should be some heuristic that determines the correct
+encryption certificate.
+
+Ideally a database should be maintained of a certificates for each email
+address.
+
+The code doesn't currently take note of the permitted symmetric encryption
+algorithms as supplied in the SMIMECapabilities signed attribute. this means the
+user has to manually include the correct encryption algorithm. It should store
+the list of permitted ciphers in a database and only use those.
+
+No revocation checking is done on the signer's certificate.
+
+=head1 HISTORY
+
+The use of multiple B<-signer> options and the B<-resign> command were first
+added in OpenSSL 1.0.0
+
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/config.pod b/deps/openssl/openssl/doc/apps/config.pod
new file mode 100644 (file)
index 0000000..ace34b6
--- /dev/null
@@ -0,0 +1,279 @@
+
+=pod
+
+=for comment openssl_manual_section:5
+
+=head1 NAME
+
+config - OpenSSL CONF library configuration files
+
+=head1 DESCRIPTION
+
+The OpenSSL CONF library can be used to read configuration files.
+It is used for the OpenSSL master configuration file B<openssl.cnf>
+and in a few other places like B<SPKAC> files and certificate extension
+files for the B<x509> utility. OpenSSL applications can also use the
+CONF library for their own purposes.
+
+A configuration file is divided into a number of sections. Each section
+starts with a line B<[ section_name ]> and ends when a new section is
+started or end of file is reached. A section name can consist of
+alphanumeric characters and underscores.
+
+The first section of a configuration file is special and is referred
+to as the B<default> section this is usually unnamed and is from the
+start of file until the first named section. When a name is being looked up
+it is first looked up in a named section (if any) and then the
+default section.
+
+The environment is mapped onto a section called B<ENV>.
+
+Comments can be included by preceding them with the B<#> character
+
+Each section in a configuration file consists of a number of name and
+value pairs of the form B<name=value>
+
+The B<name> string can contain any alphanumeric characters as well as
+a few punctuation symbols such as B<.> B<,> B<;> and B<_>.
+
+The B<value> string consists of the string following the B<=> character
+until end of line with any leading and trailing white space removed.
+
+The value string undergoes variable expansion. This can be done by
+including the form B<$var> or B<${var}>: this will substitute the value
+of the named variable in the current section. It is also possible to
+substitute a value from another section using the syntax B<$section::name>
+or B<${section::name}>. By using the form B<$ENV::name> environment
+variables can be substituted. It is also possible to assign values to
+environment variables by using the name B<ENV::name>, this will work
+if the program looks up environment variables using the B<CONF> library
+instead of calling B<getenv()> directly.
+
+It is possible to escape certain characters by using any kind of quote
+or the B<\> character. By making the last character of a line a B<\>
+a B<value> string can be spread across multiple lines. In addition
+the sequences B<\n>, B<\r>, B<\b> and B<\t> are recognized.
+
+=head1 OPENSSL LIBRARY CONFIGURATION
+
+In OpenSSL 0.9.7 and later applications can automatically configure certain
+aspects of OpenSSL using the master OpenSSL configuration file, or optionally
+an alternative configuration file. The B<openssl> utility includes this
+functionality: any sub command uses the master OpenSSL configuration file
+unless an option is used in the sub command to use an alternative configuration
+file.
+
+To enable library configuration the default section needs to contain an 
+appropriate line which points to the main configuration section. The default
+name is B<openssl_conf> which is used by the B<openssl> utility. Other
+applications may use an alternative name such as B<myapplicaton_conf>.
+
+The configuration section should consist of a set of name value pairs which
+contain specific module configuration information. The B<name> represents
+the name of the I<configuration module> the meaning of the B<value> is 
+module specific: it may, for example, represent a further configuration
+section containing configuration module specific information. E.g.
+
+ openssl_conf = openssl_init
+
+ [openssl_init]
+
+ oid_section = new_oids
+ engines = engine_section
+
+ [new_oids]
+
+ ... new oids here ...
+
+ [engine_section]
+
+ ... engine stuff here ...
+
+Currently there are two configuration modules. One for ASN1 objects another
+for ENGINE configuration.
+
+=head2 ASN1 OBJECT CONFIGURATION MODULE
+
+This module has the name B<oid_section>. The value of this variable points
+to a section containing name value pairs of OIDs: the name is the OID short
+and long name, the value is the numerical form of the OID. Although some of
+the B<openssl> utility sub commands already have their own ASN1 OBJECT section
+functionality not all do. By using the ASN1 OBJECT configuration module
+B<all> the B<openssl> utility sub commands can see the new objects as well
+as any compliant applications. For example:
+
+ [new_oids]
+ some_new_oid = 1.2.3.4
+ some_other_oid = 1.2.3.5
+
+In OpenSSL 0.9.8 it is also possible to set the value to the long name followed
+by a comma and the numerical OID form. For example:
+
+ shortName = some object long name, 1.2.3.4
+
+=head2 ENGINE CONFIGURATION MODULE
+
+This ENGINE configuration module has the name B<engines>. The value of this
+variable points to a section containing further ENGINE configuration
+information.
+
+The section pointed to by B<engines> is a table of engine names (though see
+B<engine_id> below) and further sections containing configuration informations
+specific to each ENGINE.
+
+Each ENGINE specific section is used to set default algorithms, load
+dynamic, perform initialization and send ctrls. The actual operation performed
+depends on the I<command> name which is the name of the name value pair. The
+currently supported commands are listed below.
+
+For example:
+
+ [engine_section]
+
+ # Configure ENGINE named "foo"
+ foo = foo_section
+ # Configure ENGINE named "bar"
+ bar = bar_section
+
+ [foo_section]
+ ... foo ENGINE specific commands ...
+
+ [bar_section]
+ ... "bar" ENGINE specific commands ...
+
+The command B<engine_id> is used to give the ENGINE name. If used this 
+command must be first. For example:
+
+ [engine_section]
+ # This would normally handle an ENGINE named "foo"
+ foo = foo_section
+
+ [foo_section]
+ # Override default name and use "myfoo" instead.
+ engine_id = myfoo
+
+The command B<dynamic_path> loads and adds an ENGINE from the given path. It
+is equivalent to sending the ctrls B<SO_PATH> with the path argument followed
+by B<LIST_ADD> with value 2 and B<LOAD> to the dynamic ENGINE. If this is
+not the required behaviour then alternative ctrls can be sent directly
+to the dynamic ENGINE using ctrl commands.
+
+The command B<init> determines whether to initialize the ENGINE. If the value
+is B<0> the ENGINE will not be initialized, if B<1> and attempt it made to
+initialized the ENGINE immediately. If the B<init> command is not present
+then an attempt will be made to initialize the ENGINE after all commands in
+its section have been processed.
+
+The command B<default_algorithms> sets the default algorithms an ENGINE will
+supply using the functions B<ENGINE_set_default_string()>
+
+If the name matches none of the above command names it is assumed to be a
+ctrl command which is sent to the ENGINE. The value of the command is the 
+argument to the ctrl command. If the value is the string B<EMPTY> then no
+value is sent to the command.
+
+For example:
+
+
+ [engine_section]
+
+ # Configure ENGINE named "foo"
+ foo = foo_section
+
+ [foo_section]
+ # Load engine from DSO
+ dynamic_path = /some/path/fooengine.so
+ # A foo specific ctrl.
+ some_ctrl = some_value
+ # Another ctrl that doesn't take a value.
+ other_ctrl = EMPTY
+ # Supply all default algorithms
+ default_algorithms = ALL
+
+=head1 NOTES
+
+If a configuration file attempts to expand a variable that doesn't exist
+then an error is flagged and the file will not load. This can happen
+if an attempt is made to expand an environment variable that doesn't
+exist. For example in a previous version of OpenSSL the default OpenSSL
+master configuration file used the value of B<HOME> which may not be
+defined on non Unix systems and would cause an error.
+
+This can be worked around by including a B<default> section to provide
+a default value: then if the environment lookup fails the default value
+will be used instead. For this to work properly the default value must
+be defined earlier in the configuration file than the expansion. See
+the B<EXAMPLES> section for an example of how to do this.
+
+If the same variable exists in the same section then all but the last
+value will be silently ignored. In certain circumstances such as with
+DNs the same field may occur multiple times. This is usually worked
+around by ignoring any characters before an initial B<.> e.g.
+
+ 1.OU="My first OU"
+ 2.OU="My Second OU"
+
+=head1 EXAMPLES
+
+Here is a sample configuration file using some of the features
+mentioned above.
+
+ # This is the default section.
+ HOME=/temp
+ RANDFILE= ${ENV::HOME}/.rnd
+ configdir=$ENV::HOME/config
+
+ [ section_one ]
+
+ # We are now in section one.
+
+ # Quotes permit leading and trailing whitespace
+ any = " any variable name "
+
+ other = A string that can \
+ cover several lines \
+ by including \\ characters
+
+ message = Hello World\n
+
+ [ section_two ]
+
+ greeting = $section_one::message
+
+This next example shows how to expand environment variables safely.
+
+Suppose you want a variable called B<tmpfile> to refer to a
+temporary filename. The directory it is placed in can determined by
+the the B<TEMP> or B<TMP> environment variables but they may not be
+set to any value at all. If you just include the environment variable
+names and the variable doesn't exist then this will cause an error when
+an attempt is made to load the configuration file. By making use of the
+default section both values can be looked up with B<TEMP> taking 
+priority and B</tmp> used if neither is defined:
+
+ TMP=/tmp
+ # The above value is used if TMP isn't in the environment
+ TEMP=$ENV::TMP
+ # The above value is used if TEMP isn't in the environment
+ tmpfile=${ENV::TEMP}/tmp.filename
+
+=head1 BUGS
+
+Currently there is no way to include characters using the octal B<\nnn>
+form. Strings are all null terminated so nulls cannot form part of
+the value.
+
+The escaping isn't quite right: if you want to use sequences like B<\n>
+you can't use any quote escaping on the same line.
+
+Files are loaded in a single pass. This means that an variable expansion
+will only work if the variables referenced are defined earlier in the
+file.
+
+=head1 SEE ALSO
+
+L<x509(1)|x509(1)>, L<req(1)|req(1)>, L<ca(1)|ca(1)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/crl.pod b/deps/openssl/openssl/doc/apps/crl.pod
new file mode 100644 (file)
index 0000000..a40c873
--- /dev/null
@@ -0,0 +1,117 @@
+=pod
+
+=head1 NAME
+
+crl - CRL utility
+
+=head1 SYNOPSIS
+
+B<openssl> B<crl>
+[B<-inform PEM|DER>]
+[B<-outform PEM|DER>]
+[B<-text>]
+[B<-in filename>]
+[B<-out filename>]
+[B<-noout>]
+[B<-hash>]
+[B<-issuer>]
+[B<-lastupdate>]
+[B<-nextupdate>]
+[B<-CAfile file>]
+[B<-CApath dir>]
+
+=head1 DESCRIPTION
+
+The B<crl> command processes CRL files in DER or PEM format.
+
+=head1 COMMAND OPTIONS
+
+=over 4
+
+=item B<-inform DER|PEM>
+
+This specifies the input format. B<DER> format is DER encoded CRL
+structure. B<PEM> (the default) is a base64 encoded version of
+the DER form with header and footer lines.
+
+=item B<-outform DER|PEM>
+
+This specifies the output format, the options have the same meaning as the 
+B<-inform> option.
+
+=item B<-in filename>
+
+This specifies the input filename to read from or standard input if this
+option is not specified.
+
+=item B<-out filename>
+
+specifies the output filename to write to or standard output by
+default.
+
+=item B<-text>
+
+print out the CRL in text form.
+
+=item B<-noout>
+
+don't output the encoded version of the CRL.
+
+=item B<-hash>
+
+output a hash of the issuer name. This can be use to lookup CRLs in
+a directory by issuer name.
+
+=item B<-issuer>
+
+output the issuer name.
+
+=item B<-lastupdate>
+
+output the lastUpdate field.
+
+=item B<-nextupdate>
+
+output the nextUpdate field.
+
+=item B<-CAfile file>
+
+verify the signature on a CRL by looking up the issuing certificate in
+B<file>
+
+=item B<-CApath dir>
+
+verify the signature on a CRL by looking up the issuing certificate in
+B<dir>. This directory must be a standard certificate directory: that
+is a hash of each subject name (using B<x509 -hash>) should be linked
+to each certificate.
+
+=back
+
+=head1 NOTES
+
+The PEM CRL format uses the header and footer lines:
+
+ -----BEGIN X509 CRL-----
+ -----END X509 CRL-----
+
+=head1 EXAMPLES
+
+Convert a CRL file from PEM to DER:
+
+ openssl crl -in crl.pem -outform DER -out crl.der
+
+Output the text form of a DER encoded certificate:
+
+ openssl crl -in crl.der -text -noout
+
+=head1 BUGS
+
+Ideally it should be possible to create a CRL using appropriate options
+and files too.
+
+=head1 SEE ALSO
+
+L<crl2pkcs7(1)|crl2pkcs7(1)>, L<ca(1)|ca(1)>, L<x509(1)|x509(1)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/crl2pkcs7.pod b/deps/openssl/openssl/doc/apps/crl2pkcs7.pod
new file mode 100644 (file)
index 0000000..3797bc0
--- /dev/null
@@ -0,0 +1,91 @@
+=pod
+
+=head1 NAME
+
+crl2pkcs7 - Create a PKCS#7 structure from a CRL and certificates.
+
+=head1 SYNOPSIS
+
+B<openssl> B<crl2pkcs7>
+[B<-inform PEM|DER>]
+[B<-outform PEM|DER>]
+[B<-in filename>]
+[B<-out filename>]
+[B<-certfile filename>]
+[B<-nocrl>]
+
+=head1 DESCRIPTION
+
+The B<crl2pkcs7> command takes an optional CRL and one or more
+certificates and converts them into a PKCS#7 degenerate "certificates
+only" structure.
+
+=head1 COMMAND OPTIONS
+
+=over 4
+
+=item B<-inform DER|PEM>
+
+This specifies the CRL input format. B<DER> format is DER encoded CRL
+structure.B<PEM> (the default) is a base64 encoded version of
+the DER form with header and footer lines.
+
+=item B<-outform DER|PEM>
+
+This specifies the PKCS#7 structure output format. B<DER> format is DER
+encoded PKCS#7 structure.B<PEM> (the default) is a base64 encoded version of
+the DER form with header and footer lines.
+
+=item B<-in filename>
+
+This specifies the input filename to read a CRL from or standard input if this
+option is not specified.
+
+=item B<-out filename>
+
+specifies the output filename to write the PKCS#7 structure to or standard
+output by default.
+
+=item B<-certfile filename>
+
+specifies a filename containing one or more certificates in B<PEM> format.
+All certificates in the file will be added to the PKCS#7 structure. This
+option can be used more than once to read certificates form multiple
+files.
+
+=item B<-nocrl>
+
+normally a CRL is included in the output file. With this option no CRL is
+included in the output file and a CRL is not read from the input file.
+
+=back
+
+=head1 EXAMPLES
+
+Create a PKCS#7 structure from a certificate and CRL:
+
+ openssl crl2pkcs7 -in crl.pem -certfile cert.pem -out p7.pem
+
+Creates a PKCS#7 structure in DER format with no CRL from several
+different certificates:
+
+ openssl crl2pkcs7 -nocrl -certfile newcert.pem 
+       -certfile demoCA/cacert.pem -outform DER -out p7.der
+
+=head1 NOTES
+
+The output file is a PKCS#7 signed data structure containing no signers and
+just certificates and an optional CRL.
+
+This utility can be used to send certificates and CAs to Netscape as part of
+the certificate enrollment process. This involves sending the DER encoded output
+as MIME type application/x-x509-user-cert.
+
+The B<PEM> encoded form with the header and footer lines removed can be used to
+install user certificates and CAs in MSIE using the Xenroll control.
+
+=head1 SEE ALSO
+
+L<pkcs7(1)|pkcs7(1)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/dgst.pod b/deps/openssl/openssl/doc/apps/dgst.pod
new file mode 100644 (file)
index 0000000..b035edf
--- /dev/null
@@ -0,0 +1,162 @@
+=pod
+
+=head1 NAME
+
+dgst, md5, md4, md2, sha1, sha, mdc2, ripemd160 - message digests
+
+=head1 SYNOPSIS
+
+B<openssl> B<dgst> 
+[B<-md5|-md4|-md2|-sha1|-sha|-mdc2|-ripemd160|-dss1>]
+[B<-c>]
+[B<-d>]
+[B<-hex>]
+[B<-binary>]
+[B<-out filename>]
+[B<-sign filename>]
+[B<-keyform arg>]
+[B<-passin arg>]
+[B<-verify filename>]
+[B<-prverify filename>]
+[B<-signature filename>]
+[B<-hmac key>]
+[B<file...>]
+
+[B<md5|md4|md2|sha1|sha|mdc2|ripemd160>]
+[B<-c>]
+[B<-d>]
+[B<file...>]
+
+=head1 DESCRIPTION
+
+The digest functions output the message digest of a supplied file or files
+in hexadecimal form. They can also be used for digital signing and verification.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-c>
+
+print out the digest in two digit groups separated by colons, only relevant if
+B<hex> format output is used.
+
+=item B<-d>
+
+print out BIO debugging information.
+
+=item B<-hex>
+
+digest is to be output as a hex dump. This is the default case for a "normal"
+digest as opposed to a digital signature.
+
+=item B<-binary>
+
+output the digest or signature in binary form.
+
+=item B<-out filename>
+
+filename to output to, or standard output by default.
+
+=item B<-sign filename>
+
+digitally sign the digest using the private key in "filename".
+
+=item B<-keyform arg>
+
+Specifies the key format to sign digest with. Only PEM and ENGINE
+formats are supported by the B<dgst> command.
+
+=item B<-engine id>
+
+Use engine B<id> for operations (including private key storage).
+This engine is not used as source for digest algorithms, unless it is
+also specified in the configuration file.
+
+=item B<-sigopt nm:v>
+
+Pass options to the signature algorithm during sign or verify operations.
+Names and values of these options are algorithm-specific.
+
+
+=item B<-passin arg>
+
+the private key password source. For more information about the format of B<arg>
+see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
+
+=item B<-verify filename>
+
+verify the signature using the the public key in "filename".
+The output is either "Verification OK" or "Verification Failure".
+
+=item B<-prverify filename>
+
+verify the signature using the  the private key in "filename".
+
+=item B<-signature filename>
+
+the actual signature to verify.
+
+=item B<-hmac key>
+
+create a hashed MAC using "key".
+
+=item B<-mac alg>
+
+create MAC (keyed Message Authentication Code). The most popular MAC
+algorithm is HMAC (hash-based MAC), but there are other MAC algorithms
+which are not based on hash, for instance B<gost-mac> algorithm,
+supported by B<ccgost> engine. MAC keys and other options should be set
+via B<-macopt> parameter.
+
+=item B<-macopt nm:v>
+
+Passes options to MAC algorithm, specified by B<-mac> key.
+Following options are supported by both by B<HMAC> and B<gost-mac>:
+
+=over 8
+
+=item B<key:string>
+       
+Specifies MAC key as alphnumeric string (use if key contain printable
+characters only). String length must conform to any restrictions of
+the MAC algorithm for example exactly 32 chars for gost-mac.
+
+=item B<hexkey:string>
+
+Specifies MAC key in hexadecimal form (two hex digits per byte).
+Key length must conform to any restrictions of the MAC algorithm
+for example exactly 32 chars for gost-mac.
+
+=back
+
+=item B<-rand file(s)>
+
+a file or files containing random data used to seed the random number
+generator, or an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
+Multiple files can be specified separated by a OS-dependent character.
+The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
+all others. 
+
+=item B<file...>
+
+file or files to digest. If no files are specified then standard input is
+used.
+
+=back
+
+=head1 NOTES
+
+The digest of choice for all new applications is SHA1. Other digests are
+however still widely used.
+
+If you wish to sign or verify data using the DSA algorithm then the dss1
+digest must be used.
+
+A source of random numbers is required for certain signing algorithms, in
+particular DSA.
+
+The signing and verify options should only be used if a single file is
+being signed or verified.
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/dhparam.pod b/deps/openssl/openssl/doc/apps/dhparam.pod
new file mode 100644 (file)
index 0000000..9edb4ff
--- /dev/null
@@ -0,0 +1,141 @@
+=pod
+
+=head1 NAME
+
+dhparam - DH parameter manipulation and generation
+
+=head1 SYNOPSIS
+
+B<openssl dhparam>
+[B<-inform DER|PEM>]
+[B<-outform DER|PEM>]
+[B<-in> I<filename>]
+[B<-out> I<filename>]
+[B<-dsaparam>]
+[B<-noout>]
+[B<-text>]
+[B<-C>]
+[B<-2>]
+[B<-5>]
+[B<-rand> I<file(s)>]
+[B<-engine id>]
+[I<numbits>]
+
+=head1 DESCRIPTION
+
+This command is used to manipulate DH parameter files.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-inform DER|PEM>
+
+This specifies the input format. The B<DER> option uses an ASN1 DER encoded
+form compatible with the PKCS#3 DHparameter structure. The PEM form is the
+default format: it consists of the B<DER> format base64 encoded with
+additional header and footer lines.
+
+=item B<-outform DER|PEM>
+
+This specifies the output format, the options have the same meaning as the 
+B<-inform> option.
+
+=item B<-in> I<filename>
+
+This specifies the input filename to read parameters from or standard input if
+this option is not specified.
+
+=item B<-out> I<filename>
+
+This specifies the output filename parameters to. Standard output is used
+if this option is not present. The output filename should B<not> be the same
+as the input filename.
+
+=item B<-dsaparam>
+
+If this option is used, DSA rather than DH parameters are read or created;
+they are converted to DH format.  Otherwise, "strong" primes (such
+that (p-1)/2 is also prime) will be used for DH parameter generation.
+
+DH parameter generation with the B<-dsaparam> option is much faster,
+and the recommended exponent length is shorter, which makes DH key
+exchange more efficient.  Beware that with such DSA-style DH
+parameters, a fresh DH key should be created for each use to
+avoid small-subgroup attacks that may be possible otherwise.
+
+=item B<-2>, B<-5>
+
+The generator to use, either 2 or 5. 2 is the default. If present then the
+input file is ignored and parameters are generated instead.
+
+=item B<-rand> I<file(s)>
+
+a file or files containing random data used to seed the random number
+generator, or an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
+Multiple files can be specified separated by a OS-dependent character.
+The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
+all others.
+
+=item I<numbits>
+
+this option specifies that a parameter set should be generated of size
+I<numbits>. It must be the last option. If not present then a value of 512
+is used. If this option is present then the input file is ignored and 
+parameters are generated instead.
+
+=item B<-noout>
+
+this option inhibits the output of the encoded version of the parameters.
+
+=item B<-text>
+
+this option prints out the DH parameters in human readable form.
+
+=item B<-C>
+
+this option converts the parameters into C code. The parameters can then
+be loaded by calling the B<get_dh>I<numbits>B<()> function.
+
+=item B<-engine id>
+
+specifying an engine (by its unique B<id> string) will cause B<dhparam>
+to attempt to obtain a functional reference to the specified engine,
+thus initialising it if needed. The engine will then be set as the default
+for all available algorithms.
+
+=back
+
+=head1 WARNINGS
+
+The program B<dhparam> combines the functionality of the programs B<dh> and
+B<gendh> in previous versions of OpenSSL and SSLeay. The B<dh> and B<gendh>
+programs are retained for now but may have different purposes in future 
+versions of OpenSSL.
+
+=head1 NOTES
+
+PEM format DH parameters use the header and footer lines:
+
+ -----BEGIN DH PARAMETERS-----
+ -----END DH PARAMETERS-----
+
+OpenSSL currently only supports the older PKCS#3 DH, not the newer X9.42
+DH.
+
+This program manipulates DH parameters not keys.
+
+=head1 BUGS
+
+There should be a way to generate and manipulate DH keys.
+
+=head1 SEE ALSO
+
+L<dsaparam(1)|dsaparam(1)>
+
+=head1 HISTORY
+
+The B<dhparam> command was added in OpenSSL 0.9.5.
+The B<-dsaparam> option was added in OpenSSL 0.9.6.
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/dsa.pod b/deps/openssl/openssl/doc/apps/dsa.pod
new file mode 100644 (file)
index 0000000..ddbc932
--- /dev/null
@@ -0,0 +1,158 @@
+=pod
+
+=head1 NAME
+
+dsa - DSA key processing
+
+=head1 SYNOPSIS
+
+B<openssl> B<dsa>
+[B<-inform PEM|DER>]
+[B<-outform PEM|DER>]
+[B<-in filename>]
+[B<-passin arg>]
+[B<-out filename>]
+[B<-passout arg>]
+[B<-des>]
+[B<-des3>]
+[B<-idea>]
+[B<-text>]
+[B<-noout>]
+[B<-modulus>]
+[B<-pubin>]
+[B<-pubout>]
+[B<-engine id>]
+
+=head1 DESCRIPTION
+
+The B<dsa> command processes DSA keys. They can be converted between various
+forms and their components printed out. B<Note> This command uses the
+traditional SSLeay compatible format for private key encryption: newer
+applications should use the more secure PKCS#8 format using the B<pkcs8>
+
+=head1 COMMAND OPTIONS
+
+=over 4
+
+=item B<-inform DER|PEM>
+
+This specifies the input format. The B<DER> option with a private key uses
+an ASN1 DER encoded form of an ASN.1 SEQUENCE consisting of the values of
+version (currently zero), p, q, g, the public and private key components
+respectively as ASN.1 INTEGERs. When used with a public key it uses a
+SubjectPublicKeyInfo structure: it is an error if the key is not DSA.
+
+The B<PEM> form is the default format: it consists of the B<DER> format base64
+encoded with additional header and footer lines. In the case of a private key
+PKCS#8 format is also accepted.
+
+=item B<-outform DER|PEM>
+
+This specifies the output format, the options have the same meaning as the 
+B<-inform> option.
+
+=item B<-in filename>
+
+This specifies the input filename to read a key from or standard input if this
+option is not specified. If the key is encrypted a pass phrase will be
+prompted for.
+
+=item B<-passin arg>
+
+the input file password source. For more information about the format of B<arg>
+see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
+
+=item B<-out filename>
+
+This specifies the output filename to write a key to or standard output by
+is not specified. If any encryption options are set then a pass phrase will be
+prompted for. The output filename should B<not> be the same as the input
+filename.
+
+=item B<-passout arg>
+
+the output file password source. For more information about the format of B<arg>
+see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
+
+=item B<-des|-des3|-idea>
+
+These options encrypt the private key with the DES, triple DES, or the 
+IDEA ciphers respectively before outputting it. A pass phrase is prompted for.
+If none of these options is specified the key is written in plain text. This
+means that using the B<dsa> utility to read in an encrypted key with no
+encryption option can be used to remove the pass phrase from a key, or by
+setting the encryption options it can be use to add or change the pass phrase.
+These options can only be used with PEM format output files.
+
+=item B<-text>
+
+prints out the public, private key components and parameters.
+
+=item B<-noout>
+
+this option prevents output of the encoded version of the key.
+
+=item B<-modulus>
+
+this option prints out the value of the public key component of the key.
+
+=item B<-pubin>
+
+by default a private key is read from the input file: with this option a
+public key is read instead.
+
+=item B<-pubout>
+
+by default a private key is output. With this option a public
+key will be output instead. This option is automatically set if the input is
+a public key.
+
+=item B<-engine id>
+
+specifying an engine (by its unique B<id> string) will cause B<dsa>
+to attempt to obtain a functional reference to the specified engine,
+thus initialising it if needed. The engine will then be set as the default
+for all available algorithms.
+
+=back
+
+=head1 NOTES
+
+The PEM private key format uses the header and footer lines:
+
+ -----BEGIN DSA PRIVATE KEY-----
+ -----END DSA PRIVATE KEY-----
+
+The PEM public key format uses the header and footer lines:
+
+ -----BEGIN PUBLIC KEY-----
+ -----END PUBLIC KEY-----
+
+=head1 EXAMPLES
+
+To remove the pass phrase on a DSA private key:
+
+ openssl dsa -in key.pem -out keyout.pem
+
+To encrypt a private key using triple DES:
+
+ openssl dsa -in key.pem -des3 -out keyout.pem
+
+To convert a private key from PEM to DER format: 
+
+ openssl dsa -in key.pem -outform DER -out keyout.der
+
+To print out the components of a private key to standard output:
+
+ openssl dsa -in key.pem -text -noout
+
+To just output the public part of a private key:
+
+ openssl dsa -in key.pem -pubout -out pubkey.pem
+
+=head1 SEE ALSO
+
+L<dsaparam(1)|dsaparam(1)>, L<gendsa(1)|gendsa(1)>, L<rsa(1)|rsa(1)>,
+L<genrsa(1)|genrsa(1)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/dsaparam.pod b/deps/openssl/openssl/doc/apps/dsaparam.pod
new file mode 100644 (file)
index 0000000..ba5ec4d
--- /dev/null
@@ -0,0 +1,110 @@
+=pod
+
+=head1 NAME
+
+dsaparam - DSA parameter manipulation and generation
+
+=head1 SYNOPSIS
+
+B<openssl dsaparam>
+[B<-inform DER|PEM>]
+[B<-outform DER|PEM>]
+[B<-in filename>]
+[B<-out filename>]
+[B<-noout>]
+[B<-text>]
+[B<-C>]
+[B<-rand file(s)>]
+[B<-genkey>]
+[B<-engine id>]
+[B<numbits>]
+
+=head1 DESCRIPTION
+
+This command is used to manipulate or generate DSA parameter files.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-inform DER|PEM>
+
+This specifies the input format. The B<DER> option uses an ASN1 DER encoded
+form compatible with RFC2459 (PKIX) DSS-Parms that is a SEQUENCE consisting
+of p, q and g respectively. The PEM form is the default format: it consists
+of the B<DER> format base64 encoded with additional header and footer lines.
+
+=item B<-outform DER|PEM>
+
+This specifies the output format, the options have the same meaning as the 
+B<-inform> option.
+
+=item B<-in filename>
+
+This specifies the input filename to read parameters from or standard input if
+this option is not specified. If the B<numbits> parameter is included then
+this option will be ignored.
+
+=item B<-out filename>
+
+This specifies the output filename parameters to. Standard output is used
+if this option is not present. The output filename should B<not> be the same
+as the input filename.
+
+=item B<-noout>
+
+this option inhibits the output of the encoded version of the parameters.
+
+=item B<-text>
+
+this option prints out the DSA parameters in human readable form.
+
+=item B<-C>
+
+this option converts the parameters into C code. The parameters can then
+be loaded by calling the B<get_dsaXXX()> function.
+
+=item B<-genkey>
+
+this option will generate a DSA either using the specified or generated
+parameters.
+
+=item B<-rand file(s)>
+
+a file or files containing random data used to seed the random number
+generator, or an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
+Multiple files can be specified separated by a OS-dependent character.
+The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
+all others.
+
+=item B<numbits>
+
+this option specifies that a parameter set should be generated of size
+B<numbits>. It must be the last option. If this option is included then
+the input file (if any) is ignored.
+
+=item B<-engine id>
+
+specifying an engine (by its unique B<id> string) will cause B<dsaparam>
+to attempt to obtain a functional reference to the specified engine,
+thus initialising it if needed. The engine will then be set as the default
+for all available algorithms.
+
+=back
+
+=head1 NOTES
+
+PEM format DSA parameters use the header and footer lines:
+
+ -----BEGIN DSA PARAMETERS-----
+ -----END DSA PARAMETERS-----
+
+DSA parameter generation is a slow process and as a result the same set of
+DSA parameters is often used to generate several distinct keys.
+
+=head1 SEE ALSO
+
+L<gendsa(1)|gendsa(1)>, L<dsa(1)|dsa(1)>, L<genrsa(1)|genrsa(1)>,
+L<rsa(1)|rsa(1)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/ec.pod b/deps/openssl/openssl/doc/apps/ec.pod
new file mode 100644 (file)
index 0000000..ba6dc46
--- /dev/null
@@ -0,0 +1,190 @@
+=pod
+
+=head1 NAME
+
+ec - EC key processing
+
+=head1 SYNOPSIS
+
+B<openssl> B<ec>
+[B<-inform PEM|DER>]
+[B<-outform PEM|DER>]
+[B<-in filename>]
+[B<-passin arg>]
+[B<-out filename>]
+[B<-passout arg>]
+[B<-des>]
+[B<-des3>]
+[B<-idea>]
+[B<-text>]
+[B<-noout>]
+[B<-param_out>]
+[B<-pubin>]
+[B<-pubout>]
+[B<-conv_form arg>]
+[B<-param_enc arg>]
+[B<-engine id>]
+
+=head1 DESCRIPTION
+
+The B<ec> command processes EC keys. They can be converted between various
+forms and their components printed out. B<Note> OpenSSL uses the 
+private key format specified in 'SEC 1: Elliptic Curve Cryptography'
+(http://www.secg.org/). To convert a OpenSSL EC private key into the
+PKCS#8 private key format use the B<pkcs8> command.
+
+=head1 COMMAND OPTIONS
+
+=over 4
+
+=item B<-inform DER|PEM>
+
+This specifies the input format. The B<DER> option with a private key uses
+an ASN.1 DER encoded SEC1 private key. When used with a public key it
+uses the SubjectPublicKeyInfo structur as specified in RFC 3280.
+The B<PEM> form is the default format: it consists of the B<DER> format base64
+encoded with additional header and footer lines. In the case of a private key
+PKCS#8 format is also accepted.
+
+=item B<-outform DER|PEM>
+
+This specifies the output format, the options have the same meaning as the 
+B<-inform> option.
+
+=item B<-in filename>
+
+This specifies the input filename to read a key from or standard input if this
+option is not specified. If the key is encrypted a pass phrase will be
+prompted for.
+
+=item B<-passin arg>
+
+the input file password source. For more information about the format of B<arg>
+see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
+
+=item B<-out filename>
+
+This specifies the output filename to write a key to or standard output by
+is not specified. If any encryption options are set then a pass phrase will be
+prompted for. The output filename should B<not> be the same as the input
+filename.
+
+=item B<-passout arg>
+
+the output file password source. For more information about the format of B<arg>
+see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
+
+=item B<-des|-des3|-idea>
+
+These options encrypt the private key with the DES, triple DES, IDEA or 
+any other cipher supported by OpenSSL before outputting it. A pass phrase is
+prompted for.
+If none of these options is specified the key is written in plain text. This
+means that using the B<ec> utility to read in an encrypted key with no
+encryption option can be used to remove the pass phrase from a key, or by
+setting the encryption options it can be use to add or change the pass phrase.
+These options can only be used with PEM format output files.
+
+=item B<-text>
+
+prints out the public, private key components and parameters.
+
+=item B<-noout>
+
+this option prevents output of the encoded version of the key.
+
+=item B<-modulus>
+
+this option prints out the value of the public key component of the key.
+
+=item B<-pubin>
+
+by default a private key is read from the input file: with this option a
+public key is read instead.
+
+=item B<-pubout>
+
+by default a private key is output. With this option a public
+key will be output instead. This option is automatically set if the input is
+a public key.
+
+=item B<-conv_form>
+
+This specifies how the points on the elliptic curve are converted
+into octet strings. Possible values are: B<compressed> (the default
+value), B<uncompressed> and B<hybrid>. For more information regarding
+the point conversion forms please read the X9.62 standard.
+B<Note> Due to patent issues the B<compressed> option is disabled
+by default for binary curves and can be enabled by defining
+the preprocessor macro B<OPENSSL_EC_BIN_PT_COMP> at compile time.
+
+=item B<-param_enc arg>
+
+This specifies how the elliptic curve parameters are encoded.
+Possible value are: B<named_curve>, i.e. the ec parameters are
+specified by a OID, or B<explicit> where the ec parameters are
+explicitly given (see RFC 3279 for the definition of the 
+EC parameters structures). The default value is B<named_curve>.
+B<Note> the B<implicitlyCA> alternative ,as specified in RFC 3279,
+is currently not implemented in OpenSSL.
+
+=item B<-engine id>
+
+specifying an engine (by its unique B<id> string) will cause B<ec>
+to attempt to obtain a functional reference to the specified engine,
+thus initialising it if needed. The engine will then be set as the default
+for all available algorithms.
+
+=back
+
+=head1 NOTES
+
+The PEM private key format uses the header and footer lines:
+
+ -----BEGIN EC PRIVATE KEY-----
+ -----END EC PRIVATE KEY-----
+
+The PEM public key format uses the header and footer lines:
+
+ -----BEGIN PUBLIC KEY-----
+ -----END PUBLIC KEY-----
+
+=head1 EXAMPLES
+
+To encrypt a private key using triple DES:
+
+ openssl ec -in key.pem -des3 -out keyout.pem
+
+To convert a private key from PEM to DER format: 
+
+ openssl ec -in key.pem -outform DER -out keyout.der
+
+To print out the components of a private key to standard output:
+
+ openssl ec -in key.pem -text -noout
+
+To just output the public part of a private key:
+
+ openssl ec -in key.pem -pubout -out pubkey.pem
+
+To change the parameters encoding to B<explicit>:
+
+ openssl ec -in key.pem -param_enc explicit -out keyout.pem
+
+To change the point conversion form to B<compressed>:
+
+ openssl ec -in key.pem -conv_form compressed -out keyout.pem
+
+=head1 SEE ALSO
+
+L<ecparam(1)|ecparam(1)>, L<dsa(1)|dsa(1)>, L<rsa(1)|rsa(1)>
+
+=head1 HISTORY
+
+The ec command was first introduced in OpenSSL 0.9.8.
+
+=head1 AUTHOR
+
+Nils Larsch for the OpenSSL project (http://www.openssl.org).
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/ecparam.pod b/deps/openssl/openssl/doc/apps/ecparam.pod
new file mode 100644 (file)
index 0000000..788c074
--- /dev/null
@@ -0,0 +1,179 @@
+=pod
+
+=head1 NAME
+
+ecparam - EC parameter manipulation and generation
+
+=head1 SYNOPSIS
+
+B<openssl ecparam>
+[B<-inform DER|PEM>]
+[B<-outform DER|PEM>]
+[B<-in filename>]
+[B<-out filename>]
+[B<-noout>]
+[B<-text>]
+[B<-C>]
+[B<-check>]
+[B<-name arg>]
+[B<-list_curve>]
+[B<-conv_form arg>]
+[B<-param_enc arg>]
+[B<-no_seed>]
+[B<-rand file(s)>]
+[B<-genkey>]
+[B<-engine id>]
+
+=head1 DESCRIPTION
+
+This command is used to manipulate or generate EC parameter files.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-inform DER|PEM>
+
+This specifies the input format. The B<DER> option uses an ASN.1 DER encoded
+form compatible with RFC 3279 EcpkParameters. The PEM form is the default
+format: it consists of the B<DER> format base64 encoded with additional 
+header and footer lines.
+
+=item B<-outform DER|PEM>
+
+This specifies the output format, the options have the same meaning as the 
+B<-inform> option.
+
+=item B<-in filename>
+
+This specifies the input filename to read parameters from or standard input if
+this option is not specified.
+
+=item B<-out filename>
+
+This specifies the output filename parameters to. Standard output is used
+if this option is not present. The output filename should B<not> be the same
+as the input filename.
+
+=item B<-noout>
+
+This option inhibits the output of the encoded version of the parameters.
+
+=item B<-text>
+
+This option prints out the EC parameters in human readable form.
+
+=item B<-C>
+
+This option converts the EC parameters into C code. The parameters can then
+be loaded by calling the B<get_ec_group_XXX()> function.
+
+=item B<-check>
+
+Validate the elliptic curve parameters.
+
+=item B<-name arg>
+
+Use the EC parameters with the specified 'short' name. Use B<-list_curves>
+to get a list of all currently implemented EC parameters.
+
+=item B<-list_curves>
+
+If this options is specified B<ecparam> will print out a list of all
+currently implemented EC parameters names and exit.
+
+=item B<-conv_form>
+
+This specifies how the points on the elliptic curve are converted
+into octet strings. Possible values are: B<compressed> (the default
+value), B<uncompressed> and B<hybrid>. For more information regarding
+the point conversion forms please read the X9.62 standard.
+B<Note> Due to patent issues the B<compressed> option is disabled
+by default for binary curves and can be enabled by defining
+the preprocessor macro B<OPENSSL_EC_BIN_PT_COMP> at compile time.
+
+=item B<-param_enc arg>
+
+This specifies how the elliptic curve parameters are encoded.
+Possible value are: B<named_curve>, i.e. the ec parameters are
+specified by a OID, or B<explicit> where the ec parameters are
+explicitly given (see RFC 3279 for the definition of the 
+EC parameters structures). The default value is B<named_curve>.
+B<Note> the B<implicitlyCA> alternative ,as specified in RFC 3279,
+is currently not implemented in OpenSSL.
+
+=item B<-no_seed>
+
+This option inhibits that the 'seed' for the parameter generation
+is included in the ECParameters structure (see RFC 3279).
+
+=item B<-genkey>
+
+This option will generate a EC private key using the specified parameters.
+
+=item B<-rand file(s)>
+
+a file or files containing random data used to seed the random number
+generator, or an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
+Multiple files can be specified separated by a OS-dependent character.
+The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
+all others.
+
+=item B<-engine id>
+
+specifying an engine (by its unique B<id> string) will cause B<ecparam>
+to attempt to obtain a functional reference to the specified engine,
+thus initialising it if needed. The engine will then be set as the default
+for all available algorithms.
+
+=back
+
+=head1 NOTES
+
+PEM format EC parameters use the header and footer lines:
+
+ -----BEGIN EC PARAMETERS-----
+ -----END EC PARAMETERS-----
+
+OpenSSL is currently not able to generate new groups and therefore
+B<ecparam> can only create EC parameters from known (named) curves. 
+
+=head1 EXAMPLES
+
+To create EC parameters with the group 'prime192v1':
+
+  openssl ecparam -out ec_param.pem -name prime192v1
+
+To create EC parameters with explicit parameters:
+
+  openssl ecparam -out ec_param.pem -name prime192v1 -param_enc explicit
+
+To validate given EC parameters:
+
+  openssl ecparam -in ec_param.pem -check
+
+To create EC parameters and a private key:
+
+  openssl ecparam -out ec_key.pem -name prime192v1 -genkey
+
+To change the point encoding to 'compressed':
+
+  openssl ecparam -in ec_in.pem -out ec_out.pem -conv_form compressed
+
+To print out the EC parameters to standard output:
+
+  openssl ecparam -in ec_param.pem -noout -text
+
+=head1 SEE ALSO
+
+L<ec(1)|ec(1)>, L<dsaparam(1)|dsaparam(1)>
+
+=head1 HISTORY
+
+The ecparam command was first introduced in OpenSSL 0.9.8.
+
+=head1 AUTHOR
+
+Nils Larsch for the OpenSSL project (http://www.openssl.org)
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/enc.pod b/deps/openssl/openssl/doc/apps/enc.pod
new file mode 100644 (file)
index 0000000..3dee4ed
--- /dev/null
@@ -0,0 +1,329 @@
+=pod
+
+=head1 NAME
+
+enc - symmetric cipher routines
+
+=head1 SYNOPSIS
+
+B<openssl enc -ciphername>
+[B<-in filename>]
+[B<-out filename>]
+[B<-pass arg>]
+[B<-e>]
+[B<-d>]
+[B<-a/-base64>]
+[B<-A>]
+[B<-k password>]
+[B<-kfile filename>]
+[B<-K key>]
+[B<-iv IV>]
+[B<-S salt>]
+[B<-salt>]
+[B<-nosalt>]
+[B<-z>]
+[B<-md>]
+[B<-p>]
+[B<-P>]
+[B<-bufsize number>]
+[B<-nopad>]
+[B<-debug>]
+[B<-none>]
+[B<-engine id>]
+
+=head1 DESCRIPTION
+
+The symmetric cipher commands allow data to be encrypted or decrypted
+using various block and stream ciphers using keys based on passwords
+or explicitly provided. Base64 encoding or decoding can also be performed
+either by itself or in addition to the encryption or decryption.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-in filename>
+
+the input filename, standard input by default.
+
+=item B<-out filename>
+
+the output filename, standard output by default.
+
+=item B<-pass arg>
+
+the password source. For more information about the format of B<arg>
+see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
+
+=item B<-salt>
+
+use a salt in the key derivation routines. This is the default.
+
+=item B<-nosalt>
+
+don't use a salt in the key derivation routines. This option B<SHOULD NOT> be
+used except for test purposes or compatibility with ancient versions of OpenSSL
+and SSLeay.
+
+=item B<-e>
+
+encrypt the input data: this is the default.
+
+=item B<-d>
+
+decrypt the input data.
+
+=item B<-a>
+
+base64 process the data. This means that if encryption is taking place
+the data is base64 encoded after encryption. If decryption is set then
+the input data is base64 decoded before being decrypted.
+
+=item B<-base64>
+
+same as B<-a>
+
+=item B<-A>
+
+if the B<-a> option is set then base64 process the data on one line.
+
+=item B<-k password>
+
+the password to derive the key from. This is for compatibility with previous
+versions of OpenSSL. Superseded by the B<-pass> argument.
+
+=item B<-kfile filename>
+
+read the password to derive the key from the first line of B<filename>.
+This is for compatibility with previous versions of OpenSSL. Superseded by
+the B<-pass> argument.
+
+=item B<-nosalt>
+
+do not use a salt 
+
+=item B<-salt>
+
+use salt (randomly generated or provide with B<-S> option) when
+encrypting (this is the default).
+
+=item B<-S salt>
+
+the actual salt to use: this must be represented as a string of hex digits.
+
+=item B<-K key>
+
+the actual key to use: this must be represented as a string comprised only
+of hex digits. If only the key is specified, the IV must additionally specified
+using the B<-iv> option. When both a key and a password are specified, the
+key given with the B<-K> option will be used and the IV generated from the
+password will be taken. It probably does not make much sense to specify
+both key and password.
+
+=item B<-iv IV>
+
+the actual IV to use: this must be represented as a string comprised only
+of hex digits. When only the key is specified using the B<-K> option, the
+IV must explicitly be defined. When a password is being specified using
+one of the other options, the IV is generated from this password.
+
+=item B<-p>
+
+print out the key and IV used.
+
+=item B<-P>
+
+print out the key and IV used then immediately exit: don't do any encryption
+or decryption.
+
+=item B<-bufsize number>
+
+set the buffer size for I/O
+
+=item B<-nopad>
+
+disable standard block padding
+
+=item B<-debug>
+
+debug the BIOs used for I/O.
+
+=item B<-z>
+
+Compress or decompress clear text using zlib before encryption or after
+decryption. This option exists only if OpenSSL with compiled with zlib
+or zlib-dynamic option.
+
+=item B<-none>
+
+Use NULL cipher (no encryption or decryption of input).
+
+=back
+
+=head1 NOTES
+
+The program can be called either as B<openssl ciphername> or
+B<openssl enc -ciphername>. But the first form doesn't work with
+engine-provided ciphers, because this form is processed before the
+configuration file is read and any ENGINEs loaded.
+
+Engines which provide entirely new encryption algorithms (such as ccgost
+engine which provides gost89 algorithm) should be configured in the
+configuration file. Engines, specified in the command line using -engine
+options can only be used for hadrware-assisted implementations of
+ciphers, which are supported by OpenSSL core or other engine, specified
+in the configuration file.
+
+When enc command lists supported ciphers, ciphers provided by engines,
+specified in the configuration files are listed too.
+
+A password will be prompted for to derive the key and IV if necessary.
+
+The B<-salt> option should B<ALWAYS> be used if the key is being derived
+from a password unless you want compatibility with previous versions of
+OpenSSL and SSLeay.
+
+Without the B<-salt> option it is possible to perform efficient dictionary
+attacks on the password and to attack stream cipher encrypted data. The reason
+for this is that without the salt the same password always generates the same
+encryption key. When the salt is being used the first eight bytes of the
+encrypted data are reserved for the salt: it is generated at random when
+encrypting a file and read from the encrypted file when it is decrypted.
+
+Some of the ciphers do not have large keys and others have security
+implications if not used correctly. A beginner is advised to just use
+a strong block cipher in CBC mode such as bf or des3.
+
+All the block ciphers normally use PKCS#5 padding also known as standard block
+padding: this allows a rudimentary integrity or password check to be
+performed. However since the chance of random data passing the test is
+better than 1 in 256 it isn't a very good test.
+
+If padding is disabled then the input data must be a multiple of the cipher
+block length.
+
+All RC2 ciphers have the same key and effective key length.
+
+Blowfish and RC5 algorithms use a 128 bit key.
+
+=head1 SUPPORTED CIPHERS
+
+Note that some of these ciphers can be disabled at compile time
+and some are available only if an appropriate engine is configured
+in the configuration file. The output of the B<enc> command run with
+unsupported options (for example B<openssl enc -help>) includes a
+list of ciphers, supported by your versesion of OpenSSL, including
+ones provided by configured engines.
+
+
+ base64             Base 64
+
+ bf-cbc             Blowfish in CBC mode
+ bf                 Alias for bf-cbc
+ bf-cfb             Blowfish in CFB mode
+ bf-ecb             Blowfish in ECB mode
+ bf-ofb             Blowfish in OFB mode
+
+ cast-cbc           CAST in CBC mode
+ cast               Alias for cast-cbc
+ cast5-cbc          CAST5 in CBC mode
+ cast5-cfb          CAST5 in CFB mode
+ cast5-ecb          CAST5 in ECB mode
+ cast5-ofb          CAST5 in OFB mode
+
+ des-cbc            DES in CBC mode
+ des                Alias for des-cbc
+ des-cfb            DES in CBC mode
+ des-ofb            DES in OFB mode
+ des-ecb            DES in ECB mode
+
+ des-ede-cbc        Two key triple DES EDE in CBC mode
+ des-ede            Two key triple DES EDE in ECB mode
+ des-ede-cfb        Two key triple DES EDE in CFB mode
+ des-ede-ofb        Two key triple DES EDE in OFB mode
+
+ des-ede3-cbc       Three key triple DES EDE in CBC mode
+ des-ede3           Three key triple DES EDE in ECB mode
+ des3               Alias for des-ede3-cbc
+ des-ede3-cfb       Three key triple DES EDE CFB mode
+ des-ede3-ofb       Three key triple DES EDE in OFB mode
+
+ desx               DESX algorithm.
+
+ gost89             GOST 28147-89 in CFB mode (provided by ccgost engine)
+ gost89-cnt        `GOST 28147-89 in CNT mode (provided by ccgost engine) 
+
+ idea-cbc           IDEA algorithm in CBC mode
+ idea               same as idea-cbc
+ idea-cfb           IDEA in CFB mode
+ idea-ecb           IDEA in ECB mode
+ idea-ofb           IDEA in OFB mode
+
+ rc2-cbc            128 bit RC2 in CBC mode
+ rc2                Alias for rc2-cbc
+ rc2-cfb            128 bit RC2 in CFB mode
+ rc2-ecb            128 bit RC2 in ECB mode
+ rc2-ofb            128 bit RC2 in OFB mode
+ rc2-64-cbc         64 bit RC2 in CBC mode
+ rc2-40-cbc         40 bit RC2 in CBC mode
+
+ rc4                128 bit RC4
+ rc4-64             64 bit RC4
+ rc4-40             40 bit RC4
+
+ rc5-cbc            RC5 cipher in CBC mode
+ rc5                Alias for rc5-cbc
+ rc5-cfb            RC5 cipher in CFB mode
+ rc5-ecb            RC5 cipher in ECB mode
+ rc5-ofb            RC5 cipher in OFB mode
+
+ aes-[128|192|256]-cbc 128/192/256 bit AES in CBC mode
+ aes-[128|192|256]     Alias for aes-[128|192|256]-cbc
+ aes-[128|192|256]-cfb 128/192/256 bit AES in 128 bit CFB mode
+ aes-[128|192|256]-cfb1        128/192/256 bit AES in 1 bit CFB mode
+ aes-[128|192|256]-cfb8        128/192/256 bit AES in 8 bit CFB mode
+ aes-[128|192|256]-ecb 128/192/256 bit AES in ECB mode
+ aes-[128|192|256]-ofb 128/192/256 bit AES in OFB mode
+
+=head1 EXAMPLES
+
+Just base64 encode a binary file:
+
+ openssl base64 -in file.bin -out file.b64
+
+Decode the same file
+
+ openssl base64 -d -in file.b64 -out file.bin 
+
+Encrypt a file using triple DES in CBC mode using a prompted password:
+
+ openssl des3 -salt -in file.txt -out file.des3 
+
+Decrypt a file using a supplied password:
+
+ openssl des3 -d -salt -in file.des3 -out file.txt -k mypassword
+
+Encrypt a file then base64 encode it (so it can be sent via mail for example)
+using Blowfish in CBC mode:
+
+ openssl bf -a -salt -in file.txt -out file.bf
+
+Base64 decode a file then decrypt it:
+
+ openssl bf -d -salt -a -in file.bf -out file.txt
+
+Decrypt some data using a supplied 40 bit RC4 key:
+
+ openssl rc4-40 -in file.rc4 -out file.txt -K 0102030405
+
+=head1 BUGS
+
+The B<-A> option when used with large files doesn't work properly.
+
+There should be an option to allow an iteration count to be included.
+
+The B<enc> program only supports a fixed number of algorithms with
+certain parameters. So if, for example, you want to use RC2 with a
+76 bit key or RC4 with an 84 bit key you can't use this program.
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/errstr.pod b/deps/openssl/openssl/doc/apps/errstr.pod
new file mode 100644 (file)
index 0000000..b3c6ccf
--- /dev/null
@@ -0,0 +1,39 @@
+=pod
+
+=head1 NAME
+
+errstr - lookup error codes
+
+=head1 SYNOPSIS
+
+B<openssl errstr error_code>
+
+=head1 DESCRIPTION
+
+Sometimes an application will not load error message and only
+numerical forms will be available. The B<errstr> utility can be used to 
+display the meaning of the hex code. The hex code is the hex digits after the
+second colon.
+
+=head1 EXAMPLE
+
+The error code:
+
+ 27594:error:2006D080:lib(32):func(109):reason(128):bss_file.c:107:
+
+can be displayed with:
+ openssl errstr 2006D080
+
+to produce the error message:
+
+ error:2006D080:BIO routines:BIO_new_file:no such file
+
+=head1 SEE ALSO
+
+L<err(3)|err(3)>,
+L<ERR_load_crypto_strings(3)|ERR_load_crypto_strings(3)>,
+L<SSL_load_error_strings(3)|SSL_load_error_strings(3)>
+
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/gendsa.pod b/deps/openssl/openssl/doc/apps/gendsa.pod
new file mode 100644 (file)
index 0000000..8c7f114
--- /dev/null
@@ -0,0 +1,66 @@
+=pod
+
+=head1 NAME
+
+gendsa - generate a DSA private key from a set of parameters
+
+=head1 SYNOPSIS
+
+B<openssl> B<gendsa>
+[B<-out filename>]
+[B<-des>]
+[B<-des3>]
+[B<-idea>]
+[B<-rand file(s)>]
+[B<-engine id>]
+[B<paramfile>]
+
+=head1 DESCRIPTION
+
+The B<gendsa> command generates a DSA private key from a DSA parameter file
+(which will be typically generated by the B<openssl dsaparam> command).
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-des|-des3|-idea>
+
+These options encrypt the private key with the DES, triple DES, or the 
+IDEA ciphers respectively before outputting it. A pass phrase is prompted for.
+If none of these options is specified no encryption is used.
+
+=item B<-rand file(s)>
+
+a file or files containing random data used to seed the random number
+generator, or an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
+Multiple files can be specified separated by a OS-dependent character.
+The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
+all others.
+
+=item B<-engine id>
+
+specifying an engine (by its unique B<id> string) will cause B<gendsa>
+to attempt to obtain a functional reference to the specified engine,
+thus initialising it if needed. The engine will then be set as the default
+for all available algorithms.
+
+=item B<paramfile>
+
+This option specifies the DSA parameter file to use. The parameters in this
+file determine the size of the private key. DSA parameters can be generated
+and examined using the B<openssl dsaparam> command.
+
+=back
+
+=head1 NOTES
+
+DSA key generation is little more than random number generation so it is
+much quicker that RSA key generation for example.
+
+=head1 SEE ALSO
+
+L<dsaparam(1)|dsaparam(1)>, L<dsa(1)|dsa(1)>, L<genrsa(1)|genrsa(1)>,
+L<rsa(1)|rsa(1)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/genpkey.pod b/deps/openssl/openssl/doc/apps/genpkey.pod
new file mode 100644 (file)
index 0000000..1611b5c
--- /dev/null
@@ -0,0 +1,213 @@
+=pod
+
+=head1 NAME
+
+genpkey - generate a private key
+
+=head1 SYNOPSIS
+
+B<openssl> B<genpkey>
+[B<-out filename>]
+[B<-outform PEM|DER>]
+[B<-pass arg>]
+[B<-cipher>]
+[B<-engine id>]
+[B<-paramfile file>]
+[B<-algorithm alg>]
+[B<-pkeyopt opt:value>]
+[B<-genparam>]
+[B<-text>]
+
+=head1 DESCRIPTION
+
+The B<genpkey> command generates a private key.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-out filename>
+
+the output filename. If this argument is not specified then standard output is
+used.  
+
+=item B<-outform DER|PEM>
+
+This specifies the output format DER or PEM.
+
+=item B<-pass arg>
+
+the output file password source. For more information about the format of B<arg>
+see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
+
+=item B<-cipher>
+
+This option encrypts the private key with the supplied cipher. Any algorithm
+name accepted by EVP_get_cipherbyname() is acceptable such as B<des3>.
+
+=item B<-engine id>
+
+specifying an engine (by its unique B<id> string) will cause B<genpkey>
+to attempt to obtain a functional reference to the specified engine,
+thus initialising it if needed. The engine will then be set as the default
+for all available algorithms. If used this option should precede all other
+options.
+
+=item B<-algorithm alg>
+
+public key algorithm to use such as RSA, DSA or DH. If used this option must
+precede any B<-pkeyopt> options. The options B<-paramfile> and B<-algorithm>
+are mutually exclusive.
+
+=item B<-pkeyopt opt:value>
+
+set the public key algorithm option B<opt> to B<value>. The precise set of
+options supported depends on the public key algorithm used and its
+implementation. See B<KEY GENERATION OPTIONS> below for more details.
+
+=item B<-genparam>
+
+generate a set of parameters instead of a private key. If used this option must
+precede and B<-algorithm>, B<-paramfile> or B<-pkeyopt> options.
+
+=item B<-paramfile filename>
+
+Some public key algorithms generate a private key based on a set of parameters.
+They can be supplied using this option. If this option is used the public key
+algorithm used is determined by the parameters. If used this option must
+precede and B<-pkeyopt> options. The options B<-paramfile> and B<-algorithm>
+are mutually exclusive.
+
+=item B<-text>
+
+Print an (unencrypted) text representation of private and public keys and
+parameters along with the PEM or DER structure.
+
+=back
+
+=head1 KEY GENERATION OPTIONS
+
+The options supported by each algorith and indeed each implementation of an
+algorithm can vary. The options for the OpenSSL implementations are detailed
+below.
+
+=head1 RSA KEY GENERATION OPTIONS
+
+=over 4
+
+=item B<rsa_keygen_bits:numbits>
+
+The number of bits in the generated key. If not specified 1024 is used.
+
+=item B<rsa_keygen_pubexp:value>
+
+The RSA public exponent value. This can be a large decimal or
+hexadecimal value if preceded by B<0x>. Default value is 65537.
+
+=back
+
+=head1 DSA PARAMETER GENERATION OPTIONS
+
+=over 4
+
+=item B<dsa_paramgen_bits:numbits>
+
+The number of bits in the generated parameters. If not specified 1024 is used.
+
+=head1 DH PARAMETER GENERATION OPTIONS
+
+=over 4
+
+=item B<dh_paramgen_prime_len:numbits>
+
+The number of bits in the prime parameter B<p>.
+
+=item B<dh_paramgen_generator:value>
+
+The value to use for the generator B<g>.
+
+=back
+
+=head1 EC PARAMETER GENERATION OPTIONS
+
+=over 4
+
+=item B<ec_paramgen_curve:curve>
+
+the EC curve to use.
+
+=back
+
+=head1 GOST2001 KEY GENERATION AND PARAMETER OPTIONS
+
+Gost 2001 support is not enabled by default. To enable this algorithm,
+one should load the ccgost engine in the OpenSSL configuration file.
+See README.gost file in the engines/ccgost directiry of the source
+distribution for more details.
+
+Use of a parameter file for the GOST R 34.10 algorithm is optional.
+Parameters can be specified during key generation directly as well as
+during generation of parameter file.
+
+=over 4
+
+=item B<paramset:name>
+
+Specifies GOST R 34.10-2001 parameter set according to RFC 4357.
+Parameter set can be specified using abbreviated name, object short name or
+numeric OID. Following parameter sets are supported:
+
+  paramset   OID               Usage
+  A          1.2.643.2.2.35.1  Signature
+  B          1.2.643.2.2.35.2  Signature
+  C          1.2.643.2.2.35.3  Signature
+  XA         1.2.643.2.2.36.0  Key exchange
+  XB         1.2.643.2.2.36.1  Key exchange
+  test       1.2.643.2.2.35.0  Test purposes
+
+=back
+
+
+
+=head1 NOTES
+
+The use of the genpkey program is encouraged over the algorithm specific
+utilities because additional algorithm options and ENGINE provided algorithms
+can be used.
+
+=head1 EXAMPLES
+
+Generate an RSA private key using default parameters:
+
+ openssl genpkey -algorithm RSA -out key.pem 
+
+Encrypt output private key using 128 bit AES and the passphrase "hello":
+
+ openssl genpkey -algorithm RSA -out key.pem -aes-128-cbc -pass pass:hello
+
+Generate a 2048 bit RSA key using 3 as the public exponent:
+
+ openssl genpkey -algorithm RSA -out key.pem -pkeyopt rsa_keygen_bits:2048 \
+                                               -pkeyopt rsa_keygen_pubexp:3
+
+Generate 1024 bit DSA parameters:
+
+ openssl genpkey -genparam -algorithm DSA -out dsap.pem \
+                                               -pkeyopt dsa_paramgen_bits:1024
+
+Generate DSA key from parameters:
+
+ openssl genpkey -paramfile dsap.pem -out dsakey.pem 
+
+Generate 1024 bit DH parameters:
+
+ openssl genpkey -genparam -algorithm DH -out dhp.pem \
+                                       -pkeyopt dh_paramgen_prime_len:1024
+
+Generate DH key from parameters:
+
+ openssl genpkey -paramfile dhp.pem -out dhkey.pem 
+
+
+=cut
+
diff --git a/deps/openssl/openssl/doc/apps/genrsa.pod b/deps/openssl/openssl/doc/apps/genrsa.pod
new file mode 100644 (file)
index 0000000..7dcac2a
--- /dev/null
@@ -0,0 +1,96 @@
+=pod
+
+=head1 NAME
+
+genrsa - generate an RSA private key
+
+=head1 SYNOPSIS
+
+B<openssl> B<genrsa>
+[B<-out filename>]
+[B<-passout arg>]
+[B<-des>]
+[B<-des3>]
+[B<-idea>]
+[B<-f4>]
+[B<-3>]
+[B<-rand file(s)>]
+[B<-engine id>]
+[B<numbits>]
+
+=head1 DESCRIPTION
+
+The B<genrsa> command generates an RSA private key.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-out filename>
+
+the output filename. If this argument is not specified then standard output is
+used.  
+
+=item B<-passout arg>
+
+the output file password source. For more information about the format of B<arg>
+see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
+
+=item B<-des|-des3|-idea>
+
+These options encrypt the private key with the DES, triple DES, or the 
+IDEA ciphers respectively before outputting it. If none of these options is
+specified no encryption is used. If encryption is used a pass phrase is prompted
+for if it is not supplied via the B<-passout> argument.
+
+=item B<-F4|-3>
+
+the public exponent to use, either 65537 or 3. The default is 65537.
+
+=item B<-rand file(s)>
+
+a file or files containing random data used to seed the random number
+generator, or an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
+Multiple files can be specified separated by a OS-dependent character.
+The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
+all others.
+
+=item B<-engine id>
+
+specifying an engine (by its unique B<id> string) will cause B<genrsa>
+to attempt to obtain a functional reference to the specified engine,
+thus initialising it if needed. The engine will then be set as the default
+for all available algorithms.
+
+=item B<numbits>
+
+the size of the private key to generate in bits. This must be the last option
+specified. The default is 512.
+
+=back
+
+=head1 NOTES
+
+RSA private key generation essentially involves the generation of two prime
+numbers. When generating a private key various symbols will be output to
+indicate the progress of the generation. A B<.> represents each number which
+has passed an initial sieve test, B<+> means a number has passed a single
+round of the Miller-Rabin primality test. A newline means that the number has
+passed all the prime tests (the actual number depends on the key size).
+
+Because key generation is a random process the time taken to generate a key
+may vary somewhat.
+
+=head1 BUGS
+
+A quirk of the prime generation algorithm is that it cannot generate small
+primes. Therefore the number of bits should not be less that 64. For typical
+private keys this will not matter because for security reasons they will
+be much larger (typically 1024 bits).
+
+=head1 SEE ALSO
+
+L<gendsa(1)|gendsa(1)>
+
+=cut
+
diff --git a/deps/openssl/openssl/doc/apps/nseq.pod b/deps/openssl/openssl/doc/apps/nseq.pod
new file mode 100644 (file)
index 0000000..989c310
--- /dev/null
@@ -0,0 +1,70 @@
+=pod
+
+=head1 NAME
+
+nseq - create or examine a netscape certificate sequence
+
+=head1 SYNOPSIS
+
+B<openssl> B<nseq>
+[B<-in filename>]
+[B<-out filename>]
+[B<-toseq>]
+
+=head1 DESCRIPTION
+
+The B<nseq> command takes a file containing a Netscape certificate
+sequence and prints out the certificates contained in it or takes a
+file of certificates and converts it into a Netscape certificate
+sequence.
+
+=head1 COMMAND OPTIONS
+
+=over 4
+
+=item B<-in filename>
+
+This specifies the input filename to read or standard input if this
+option is not specified.
+
+=item B<-out filename>
+
+specifies the output filename or standard output by default.
+
+=item B<-toseq>
+
+normally a Netscape certificate sequence will be input and the output
+is the certificates contained in it. With the B<-toseq> option the
+situation is reversed: a Netscape certificate sequence is created from
+a file of certificates.
+
+=back
+
+=head1 EXAMPLES
+
+Output the certificates in a Netscape certificate sequence
+
+ openssl nseq -in nseq.pem -out certs.pem
+
+Create a Netscape certificate sequence
+
+ openssl nseq -in certs.pem -toseq -out nseq.pem
+
+=head1 NOTES
+
+The B<PEM> encoded form uses the same headers and footers as a certificate:
+
+ -----BEGIN CERTIFICATE-----
+ -----END CERTIFICATE-----
+
+A Netscape certificate sequence is a Netscape specific form that can be sent
+to browsers as an alternative to the standard PKCS#7 format when several
+certificates are sent to the browser: for example during certificate enrollment.
+It is used by Netscape certificate server for example.
+
+=head1 BUGS
+
+This program needs a few more options: like allowing DER or PEM input and
+output files and allowing multiple certificate files to be used.
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/ocsp.pod b/deps/openssl/openssl/doc/apps/ocsp.pod
new file mode 100644 (file)
index 0000000..af2e12e
--- /dev/null
@@ -0,0 +1,371 @@
+=pod
+
+=head1 NAME
+
+ocsp - Online Certificate Status Protocol utility
+
+=head1 SYNOPSIS
+
+B<openssl> B<ocsp>
+[B<-out file>]
+[B<-issuer file>]
+[B<-cert file>]
+[B<-serial n>]
+[B<-signer file>]
+[B<-signkey file>]
+[B<-sign_other file>]
+[B<-no_certs>]
+[B<-req_text>]
+[B<-resp_text>]
+[B<-text>]
+[B<-reqout file>]
+[B<-respout file>]
+[B<-reqin file>]
+[B<-respin file>]
+[B<-nonce>]
+[B<-no_nonce>]
+[B<-url URL>]
+[B<-host host:n>]
+[B<-path>]
+[B<-CApath dir>]
+[B<-CAfile file>]
+[B<-VAfile file>]
+[B<-validity_period n>]
+[B<-status_age n>]
+[B<-noverify>]
+[B<-verify_other file>]
+[B<-trust_other>]
+[B<-no_intern>]
+[B<-no_signature_verify>]
+[B<-no_cert_verify>]
+[B<-no_chain>]
+[B<-no_cert_checks>]
+[B<-port num>]
+[B<-index file>]
+[B<-CA file>]
+[B<-rsigner file>]
+[B<-rkey file>]
+[B<-rother file>]
+[B<-resp_no_certs>]
+[B<-nmin n>]
+[B<-ndays n>]
+[B<-resp_key_id>]
+[B<-nrequest n>]
+[B<-md5|-sha1|...>]
+
+=head1 DESCRIPTION
+
+The Online Certificate Status Protocol (OCSP) enables applications to
+determine the (revocation) state of an identified certificate (RFC 2560).
+
+The B<ocsp> command performs many common OCSP tasks. It can be used
+to print out requests and responses, create requests and send queries
+to an OCSP responder and behave like a mini OCSP server itself.
+
+=head1 OCSP CLIENT OPTIONS
+
+=over 4
+
+=item B<-out filename>
+
+specify output filename, default is standard output.
+
+=item B<-issuer filename>
+
+This specifies the current issuer certificate. This option can be used
+multiple times. The certificate specified in B<filename> must be in
+PEM format. This option B<MUST> come before any B<-cert> options.
+
+=item B<-cert filename>
+
+Add the certificate B<filename> to the request. The issuer certificate
+is taken from the previous B<issuer> option, or an error occurs if no
+issuer certificate is specified.
+
+=item B<-serial num>
+
+Same as the B<cert> option except the certificate with serial number
+B<num> is added to the request. The serial number is interpreted as a
+decimal integer unless preceded by B<0x>. Negative integers can also
+be specified by preceding the value by a B<-> sign.
+
+=item B<-signer filename>, B<-signkey filename>
+
+Sign the OCSP request using the certificate specified in the B<signer>
+option and the private key specified by the B<signkey> option. If
+the B<signkey> option is not present then the private key is read
+from the same file as the certificate. If neither option is specified then
+the OCSP request is not signed.
+
+=item B<-sign_other filename>
+
+Additional certificates to include in the signed request.
+
+=item B<-nonce>, B<-no_nonce>
+
+Add an OCSP nonce extension to a request or disable OCSP nonce addition.
+Normally if an OCSP request is input using the B<respin> option no
+nonce is added: using the B<nonce> option will force addition of a nonce.
+If an OCSP request is being created (using B<cert> and B<serial> options)
+a nonce is automatically added specifying B<no_nonce> overrides this.
+
+=item B<-req_text>, B<-resp_text>, B<-text>
+
+print out the text form of the OCSP request, response or both respectively.
+
+=item B<-reqout file>, B<-respout file>
+
+write out the DER encoded certificate request or response to B<file>.
+
+=item B<-reqin file>, B<-respin file>
+
+read OCSP request or response file from B<file>. These option are ignored
+if OCSP request or response creation is implied by other options (for example
+with B<serial>, B<cert> and B<host> options).
+
+=item B<-url responder_url>
+
+specify the responder URL. Both HTTP and HTTPS (SSL/TLS) URLs can be specified.
+
+=item B<-host hostname:port>, B<-path pathname>
+
+if the B<host> option is present then the OCSP request is sent to the host
+B<hostname> on port B<port>. B<path> specifies the HTTP path name to use
+or "/" by default.
+
+=item B<-CAfile file>, B<-CApath pathname>
+
+file or pathname containing trusted CA certificates. These are used to verify
+the signature on the OCSP response.
+
+=item B<-verify_other file>
+
+file containing additional certificates to search when attempting to locate
+the OCSP response signing certificate. Some responders omit the actual signer's
+certificate from the response: this option can be used to supply the necessary
+certificate in such cases.
+
+=item B<-trust_other>
+
+the certificates specified by the B<-verify_other> option should be explicitly
+trusted and no additional checks will be performed on them. This is useful
+when the complete responder certificate chain is not available or trusting a
+root CA is not appropriate.
+
+=item B<-VAfile file>
+
+file containing explicitly trusted responder certificates. Equivalent to the
+B<-verify_other> and B<-trust_other> options.
+
+=item B<-noverify>
+
+don't attempt to verify the OCSP response signature or the nonce values. This
+option will normally only be used for debugging since it disables all verification
+of the responders certificate.
+
+=item B<-no_intern>
+
+ignore certificates contained in the OCSP response when searching for the
+signers certificate. With this option the signers certificate must be specified
+with either the B<-verify_other> or B<-VAfile> options.
+
+=item B<-no_signature_verify>
+
+don't check the signature on the OCSP response. Since this option tolerates invalid
+signatures on OCSP responses it will normally only be used for testing purposes.
+
+=item B<-no_cert_verify>
+
+don't verify the OCSP response signers certificate at all. Since this option allows
+the OCSP response to be signed by any certificate it should only be used for
+testing purposes.
+
+=item B<-no_chain>
+
+do not use certificates in the response as additional untrusted CA
+certificates.
+
+=item B<-no_cert_checks>
+
+don't perform any additional checks on the OCSP response signers certificate.
+That is do not make any checks to see if the signers certificate is authorised
+to provide the necessary status information: as a result this option should
+only be used for testing purposes.
+
+=item B<-validity_period nsec>, B<-status_age age>
+
+these options specify the range of times, in seconds, which will be tolerated
+in an OCSP response. Each certificate status response includes a B<notBefore> time and
+an optional B<notAfter> time. The current time should fall between these two values, but
+the interval between the two times may be only a few seconds. In practice the OCSP
+responder and clients clocks may not be precisely synchronised and so such a check
+may fail. To avoid this the B<-validity_period> option can be used to specify an
+acceptable error range in seconds, the default value is 5 minutes.
+
+If the B<notAfter> time is omitted from a response then this means that new status
+information is immediately available. In this case the age of the B<notBefore> field
+is checked to see it is not older than B<age> seconds old. By default this additional
+check is not performed.
+
+=item B<-md5|-sha1|-sha256|-ripemod160|...>
+
+this option sets digest algorithm to use for certificate identification
+in the OCSP request. By default SHA-1 is used. 
+
+=back
+
+=head1 OCSP SERVER OPTIONS
+
+=over 4
+
+=item B<-index indexfile>
+
+B<indexfile> is a text index file in B<ca> format containing certificate revocation
+information.
+
+If the B<index> option is specified the B<ocsp> utility is in responder mode, otherwise
+it is in client mode. The request(s) the responder processes can be either specified on
+the command line (using B<issuer> and B<serial> options), supplied in a file (using the
+B<respin> option) or via external OCSP clients (if B<port> or B<url> is specified).
+
+If the B<index> option is present then the B<CA> and B<rsigner> options must also be
+present.
+
+=item B<-CA file>
+
+CA certificate corresponding to the revocation information in B<indexfile>.
+
+=item B<-rsigner file>
+
+The certificate to sign OCSP responses with.
+
+=item B<-rother file>
+
+Additional certificates to include in the OCSP response.
+
+=item B<-resp_no_certs>
+
+Don't include any certificates in the OCSP response.
+
+=item B<-resp_key_id>
+
+Identify the signer certificate using the key ID, default is to use the subject name.
+
+=item B<-rkey file>
+
+The private key to sign OCSP responses with: if not present the file specified in the
+B<rsigner> option is used.
+
+=item B<-port portnum>
+
+Port to listen for OCSP requests on. The port may also be specified using the B<url>
+option.
+
+=item B<-nrequest number>
+
+The OCSP server will exit after receiving B<number> requests, default unlimited. 
+
+=item B<-nmin minutes>, B<-ndays days>
+
+Number of minutes or days when fresh revocation information is available: used in the
+B<nextUpdate> field. If neither option is present then the B<nextUpdate> field is 
+omitted meaning fresh revocation information is immediately available.
+
+=back
+
+=head1 OCSP Response verification.
+
+OCSP Response follows the rules specified in RFC2560.
+
+Initially the OCSP responder certificate is located and the signature on
+the OCSP request checked using the responder certificate's public key.
+
+Then a normal certificate verify is performed on the OCSP responder certificate
+building up a certificate chain in the process. The locations of the trusted
+certificates used to build the chain can be specified by the B<CAfile>
+and B<CApath> options or they will be looked for in the standard OpenSSL
+certificates directory.
+
+If the initial verify fails then the OCSP verify process halts with an
+error.
+
+Otherwise the issuing CA certificate in the request is compared to the OCSP
+responder certificate: if there is a match then the OCSP verify succeeds.
+
+Otherwise the OCSP responder certificate's CA is checked against the issuing
+CA certificate in the request. If there is a match and the OCSPSigning
+extended key usage is present in the OCSP responder certificate then the
+OCSP verify succeeds.
+
+Otherwise the root CA of the OCSP responders CA is checked to see if it
+is trusted for OCSP signing. If it is the OCSP verify succeeds.
+
+If none of these checks is successful then the OCSP verify fails.
+
+What this effectively means if that if the OCSP responder certificate is
+authorised directly by the CA it is issuing revocation information about
+(and it is correctly configured) then verification will succeed.
+
+If the OCSP responder is a "global responder" which can give details about
+multiple CAs and has its own separate certificate chain then its root
+CA can be trusted for OCSP signing. For example:
+
+ openssl x509 -in ocspCA.pem -addtrust OCSPSigning -out trustedCA.pem
+
+Alternatively the responder certificate itself can be explicitly trusted
+with the B<-VAfile> option.
+
+=head1 NOTES
+
+As noted, most of the verify options are for testing or debugging purposes.
+Normally only the B<-CApath>, B<-CAfile> and (if the responder is a 'global
+VA') B<-VAfile> options need to be used.
+
+The OCSP server is only useful for test and demonstration purposes: it is
+not really usable as a full OCSP responder. It contains only a very
+simple HTTP request handling and can only handle the POST form of OCSP
+queries. It also handles requests serially meaning it cannot respond to
+new requests until it has processed the current one. The text index file
+format of revocation is also inefficient for large quantities of revocation
+data.
+
+It is possible to run the B<ocsp> application in responder mode via a CGI
+script using the B<respin> and B<respout> options.
+
+=head1 EXAMPLES
+
+Create an OCSP request and write it to a file:
+
+ openssl ocsp -issuer issuer.pem -cert c1.pem -cert c2.pem -reqout req.der
+
+Send a query to an OCSP responder with URL http://ocsp.myhost.com/ save the 
+response to a file and print it out in text form
+
+ openssl ocsp -issuer issuer.pem -cert c1.pem -cert c2.pem \
+     -url http://ocsp.myhost.com/ -resp_text -respout resp.der
+
+Read in an OCSP response and print out text form:
+
+ openssl ocsp -respin resp.der -text
+
+OCSP server on port 8888 using a standard B<ca> configuration, and a separate
+responder certificate. All requests and responses are printed to a file.
+
+ openssl ocsp -index demoCA/index.txt -port 8888 -rsigner rcert.pem -CA demoCA/cacert.pem
+       -text -out log.txt
+
+As above but exit after processing one request:
+
+ openssl ocsp -index demoCA/index.txt -port 8888 -rsigner rcert.pem -CA demoCA/cacert.pem
+     -nrequest 1
+
+Query status information using internally generated request:
+
+ openssl ocsp -index demoCA/index.txt -rsigner rcert.pem -CA demoCA/cacert.pem
+     -issuer demoCA/cacert.pem -serial 1
+
+Query status information using request read from a file, write response to a
+second file.
+
+ openssl ocsp -index demoCA/index.txt -rsigner rcert.pem -CA demoCA/cacert.pem
+     -reqin req.der -respout resp.der
diff --git a/deps/openssl/openssl/doc/apps/openssl.pod b/deps/openssl/openssl/doc/apps/openssl.pod
new file mode 100644 (file)
index 0000000..738142e
--- /dev/null
@@ -0,0 +1,422 @@
+
+=pod
+
+=head1 NAME
+
+openssl - OpenSSL command line tool
+
+=head1 SYNOPSIS
+
+B<openssl>
+I<command>
+[ I<command_opts> ]
+[ I<command_args> ]
+
+B<openssl> [ B<list-standard-commands> | B<list-message-digest-commands> | B<list-cipher-commands> | B<list-cipher-algorithms> | B<list-message-digest-algorithms> | B<list-public-key-algorithms>]
+
+B<openssl> B<no->I<XXX> [ I<arbitrary options> ]
+
+=head1 DESCRIPTION
+
+OpenSSL is a cryptography toolkit implementing the Secure Sockets Layer (SSL
+v2/v3) and Transport Layer Security (TLS v1) network protocols and related
+cryptography standards required by them.
+
+The B<openssl> program is a command line tool for using the various
+cryptography functions of OpenSSL's B<crypto> library from the shell. 
+It can be used for 
+
+ o  Creation and management of private keys, public keys and parameters
+ o  Public key cryptographic operations
+ o  Creation of X.509 certificates, CSRs and CRLs 
+ o  Calculation of Message Digests
+ o  Encryption and Decryption with Ciphers
+ o  SSL/TLS Client and Server Tests
+ o  Handling of S/MIME signed or encrypted mail
+ o  Time Stamp requests, generation and verification
+
+=head1 COMMAND SUMMARY
+
+The B<openssl> program provides a rich variety of commands (I<command> in the
+SYNOPSIS above), each of which often has a wealth of options and arguments
+(I<command_opts> and I<command_args> in the SYNOPSIS).
+
+The pseudo-commands B<list-standard-commands>, B<list-message-digest-commands>,
+and B<list-cipher-commands> output a list (one entry per line) of the names
+of all standard commands, message digest commands, or cipher commands,
+respectively, that are available in the present B<openssl> utility.
+
+The pseudo-commands B<list-cipher-algorithms> and
+B<list-message-digest-algorithms> list all cipher and message digest names, one entry per line. Aliases are listed as:
+
+ from => to
+
+The pseudo-command B<list-public-key-algorithms> lists all supported public
+key algorithms.
+
+The pseudo-command B<no->I<XXX> tests whether a command of the
+specified name is available.  If no command named I<XXX> exists, it
+returns 0 (success) and prints B<no->I<XXX>; otherwise it returns 1
+and prints I<XXX>.  In both cases, the output goes to B<stdout> and
+nothing is printed to B<stderr>.  Additional command line arguments
+are always ignored.  Since for each cipher there is a command of the
+same name, this provides an easy way for shell scripts to test for the
+availability of ciphers in the B<openssl> program.  (B<no->I<XXX> is
+not able to detect pseudo-commands such as B<quit>,
+B<list->I<...>B<-commands>, or B<no->I<XXX> itself.)
+
+=head2 STANDARD COMMANDS
+
+=over 10
+
+=item L<B<asn1parse>|asn1parse(1)>
+
+Parse an ASN.1 sequence.
+
+=item L<B<ca>|ca(1)>
+
+Certificate Authority (CA) Management.  
+
+=item L<B<ciphers>|ciphers(1)>
+
+Cipher Suite Description Determination.
+
+=item L<B<cms>|cms(1)>
+
+CMS (Cryptographic Message Syntax) utility
+
+=item L<B<crl>|crl(1)>
+
+Certificate Revocation List (CRL) Management.
+
+=item L<B<crl2pkcs7>|crl2pkcs7(1)>
+
+CRL to PKCS#7 Conversion.
+
+=item L<B<dgst>|dgst(1)>
+
+Message Digest Calculation.
+
+=item B<dh>
+
+Diffie-Hellman Parameter Management.
+Obsoleted by L<B<dhparam>|dhparam(1)>.
+
+=item L<B<dhparam>|dhparam(1)>
+
+Generation and Management of Diffie-Hellman Parameters. Superseded by 
+L<B<genpkey>|genpkey(1)> and L<B<pkeyparam>|pkeyparam(1)>
+
+
+=item L<B<dsa>|dsa(1)>
+
+DSA Data Management.
+
+=item L<B<dsaparam>|dsaparam(1)>
+
+DSA Parameter Generation and Management. Superseded by 
+L<B<genpkey>|genpkey(1)> and L<B<pkeyparam>|pkeyparam(1)>
+
+=item L<B<ec>|ec(1)>
+
+EC (Elliptic curve) key processing
+
+=item L<B<ecparam>|ecparam(1)>
+
+EC parameter manipulation and generation
+
+=item L<B<enc>|enc(1)>
+
+Encoding with Ciphers.
+
+=item L<B<engine>|engine(1)>
+
+Engine (loadble module) information and manipulation.
+
+=item L<B<errstr>|errstr(1)>
+
+Error Number to Error String Conversion.
+
+=item B<gendh>
+
+Generation of Diffie-Hellman Parameters.
+Obsoleted by L<B<dhparam>|dhparam(1)>.
+
+=item L<B<gendsa>|gendsa(1)>
+
+Generation of DSA Private Key from Parameters. Superseded by 
+L<B<genpkey>|genpkey(1)> and L<B<pkey>|pkey(1)>
+
+=item L<B<genpkey>|genpkey(1)>
+
+Generation of Private Key or Parameters.
+
+=item L<B<genrsa>|genrsa(1)>
+
+Generation of RSA Private Key. Superceded by L<B<genpkey>|genpkey(1)>.
+
+=item L<B<nseq>|nseq(1)>
+
+Create or examine a netscape certificate sequence
+
+=item L<B<ocsp>|ocsp(1)>
+
+Online Certificate Status Protocol utility.
+
+=item L<B<passwd>|passwd(1)>
+
+Generation of hashed passwords.
+
+=item L<B<pkcs12>|pkcs12(1)>
+
+PKCS#12 Data Management.
+
+=item L<B<pkcs7>|pkcs7(1)>
+
+PKCS#7 Data Management.
+
+=item L<B<pkey>|pkey(1)>
+
+Public and private key management.
+
+=item L<B<pkeyparam>|pkeyparam(1)>
+
+Public key algorithm parameter management.
+
+=item L<B<pkeyutl>|pkeyutl(1)>
+
+Public key algorithm cryptographic operation utility.
+
+=item L<B<rand>|rand(1)>
+
+Generate pseudo-random bytes.
+
+=item L<B<req>|req(1)>
+
+PKCS#10 X.509 Certificate Signing Request (CSR) Management.
+
+=item L<B<rsa>|rsa(1)>
+
+RSA key management.
+
+
+=item L<B<rsautl>|rsautl(1)>
+
+RSA utility for signing, verification, encryption, and decryption. Superseded
+by  L<B<pkeyutl>|pkeyutl(1)>
+
+=item L<B<s_client>|s_client(1)>
+
+This implements a generic SSL/TLS client which can establish a transparent
+connection to a remote server speaking SSL/TLS. It's intended for testing
+purposes only and provides only rudimentary interface functionality but
+internally uses mostly all functionality of the OpenSSL B<ssl> library.
+
+=item L<B<s_server>|s_server(1)>
+
+This implements a generic SSL/TLS server which accepts connections from remote
+clients speaking SSL/TLS. It's intended for testing purposes only and provides
+only rudimentary interface functionality but internally uses mostly all
+functionality of the OpenSSL B<ssl> library.  It provides both an own command
+line oriented protocol for testing SSL functions and a simple HTTP response
+facility to emulate an SSL/TLS-aware webserver.
+
+=item L<B<s_time>|s_time(1)>
+
+SSL Connection Timer.
+
+=item L<B<sess_id>|sess_id(1)>
+
+SSL Session Data Management.
+
+=item L<B<smime>|smime(1)>
+
+S/MIME mail processing.
+
+=item L<B<speed>|speed(1)>
+
+Algorithm Speed Measurement.
+
+=item L<B<spkac>|spkac(1)>
+
+SPKAC printing and generating utility
+
+=item L<B<ts>|ts(1)>
+
+Time Stamping Authority tool (client/server)
+
+=item L<B<verify>|verify(1)>
+
+X.509 Certificate Verification.
+
+=item L<B<version>|version(1)>
+
+OpenSSL Version Information.
+
+=item L<B<x509>|x509(1)>
+
+X.509 Certificate Data Management.
+
+=back
+
+=head2 MESSAGE DIGEST COMMANDS
+
+=over 10
+
+=item B<md2>
+
+MD2 Digest
+
+=item B<md5>
+
+MD5 Digest
+
+=item B<mdc2>
+
+MDC2 Digest
+
+=item B<rmd160>
+
+RMD-160 Digest
+
+=item B<sha>            
+
+SHA Digest
+
+=item B<sha1>           
+
+SHA-1 Digest
+
+=back
+
+=item B<sha224>
+
+SHA-224 Digest
+
+=item B<sha256>
+
+SHA-256 Digest
+
+=item B<sha384>
+
+SHA-384 Digest
+
+=item B<sha512>
+
+SHA-512 Digest
+
+=head2 ENCODING AND CIPHER COMMANDS
+
+=over 10
+
+=item B<base64>
+
+Base64 Encoding
+
+=item B<bf bf-cbc bf-cfb bf-ecb bf-ofb>
+
+Blowfish Cipher
+
+=item B<cast cast-cbc>
+
+CAST Cipher
+
+=item B<cast5-cbc cast5-cfb cast5-ecb cast5-ofb>
+
+CAST5 Cipher
+
+=item B<des des-cbc des-cfb des-ecb des-ede des-ede-cbc des-ede-cfb des-ede-ofb des-ofb>
+
+DES Cipher
+
+=item B<des3 desx des-ede3 des-ede3-cbc des-ede3-cfb des-ede3-ofb>
+
+Triple-DES Cipher
+
+=item B<idea idea-cbc idea-cfb idea-ecb idea-ofb>
+
+IDEA Cipher
+
+=item B<rc2 rc2-cbc rc2-cfb rc2-ecb rc2-ofb>
+
+RC2 Cipher
+
+=item B<rc4>
+
+RC4 Cipher
+
+=item B<rc5 rc5-cbc rc5-cfb rc5-ecb rc5-ofb>
+
+RC5 Cipher
+
+=back
+
+=head1 PASS PHRASE ARGUMENTS
+
+Several commands accept password arguments, typically using B<-passin>
+and B<-passout> for input and output passwords respectively. These allow
+the password to be obtained from a variety of sources. Both of these
+options take a single argument whose format is described below. If no
+password argument is given and a password is required then the user is
+prompted to enter one: this will typically be read from the current
+terminal with echoing turned off.
+
+=over 10
+
+=item B<pass:password>
+
+the actual password is B<password>. Since the password is visible
+to utilities (like 'ps' under Unix) this form should only be used
+where security is not important.
+
+=item B<env:var>
+
+obtain the password from the environment variable B<var>. Since
+the environment of other processes is visible on certain platforms
+(e.g. ps under certain Unix OSes) this option should be used with caution.
+
+=item B<file:pathname>
+
+the first line of B<pathname> is the password. If the same B<pathname>
+argument is supplied to B<-passin> and B<-passout> arguments then the first
+line will be used for the input password and the next line for the output
+password. B<pathname> need not refer to a regular file: it could for example
+refer to a device or named pipe.
+
+=item B<fd:number>
+
+read the password from the file descriptor B<number>. This can be used to
+send the data via a pipe for example.
+
+=item B<stdin>
+
+read the password from standard input.
+
+=back
+
+=head1 SEE ALSO
+
+L<asn1parse(1)|asn1parse(1)>, L<ca(1)|ca(1)>, L<config(5)|config(5)>,
+L<crl(1)|crl(1)>, L<crl2pkcs7(1)|crl2pkcs7(1)>, L<dgst(1)|dgst(1)>,
+L<dhparam(1)|dhparam(1)>, L<dsa(1)|dsa(1)>, L<dsaparam(1)|dsaparam(1)>,
+L<enc(1)|enc(1)>, L<gendsa(1)|gendsa(1)>, L<genpkey(1)|genpkey(1)>,
+L<genrsa(1)|genrsa(1)>, L<nseq(1)|nseq(1)>, L<openssl(1)|openssl(1)>,
+L<passwd(1)|passwd(1)>,
+L<pkcs12(1)|pkcs12(1)>, L<pkcs7(1)|pkcs7(1)>, L<pkcs8(1)|pkcs8(1)>,
+L<rand(1)|rand(1)>, L<req(1)|req(1)>, L<rsa(1)|rsa(1)>,
+L<rsautl(1)|rsautl(1)>, L<s_client(1)|s_client(1)>,
+L<s_server(1)|s_server(1)>, L<s_time(1)|s_time(1)>,
+L<smime(1)|smime(1)>, L<spkac(1)|spkac(1)>,
+L<verify(1)|verify(1)>, L<version(1)|version(1)>, L<x509(1)|x509(1)>,
+L<crypto(3)|crypto(3)>, L<ssl(3)|ssl(3)>, L<x509v3_config(5)|x509v3_config(5)> 
+
+=head1 HISTORY
+
+The openssl(1) document appeared in OpenSSL 0.9.2.
+The B<list->I<XXX>B<-commands> pseudo-commands were added in OpenSSL 0.9.3;
+The B<list->I<XXX>B<-algorithms> pseudo-commands were added in OpenSSL 1.0.0;
+the B<no->I<XXX> pseudo-commands were added in OpenSSL 0.9.5a.
+For notes on the availability of other commands, see their individual
+manual pages.
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/passwd.pod b/deps/openssl/openssl/doc/apps/passwd.pod
new file mode 100644 (file)
index 0000000..f449825
--- /dev/null
@@ -0,0 +1,82 @@
+=pod
+
+=head1 NAME
+
+passwd - compute password hashes
+
+=head1 SYNOPSIS
+
+B<openssl passwd>
+[B<-crypt>]
+[B<-1>]
+[B<-apr1>]
+[B<-salt> I<string>]
+[B<-in> I<file>]
+[B<-stdin>]
+[B<-noverify>]
+[B<-quiet>]
+[B<-table>]
+{I<password>}
+
+=head1 DESCRIPTION
+
+The B<passwd> command computes the hash of a password typed at
+run-time or the hash of each password in a list.  The password list is
+taken from the named file for option B<-in file>, from stdin for
+option B<-stdin>, or from the command line, or from the terminal otherwise.
+The Unix standard algorithm B<crypt> and the MD5-based BSD password
+algorithm B<1> and its Apache variant B<apr1> are available.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-crypt>
+
+Use the B<crypt> algorithm (default).
+
+=item B<-1>
+
+Use the MD5 based BSD password algorithm B<1>.
+
+=item B<-apr1>
+
+Use the B<apr1> algorithm (Apache variant of the BSD algorithm).
+
+=item B<-salt> I<string>
+
+Use the specified salt.
+When reading a password from the terminal, this implies B<-noverify>.
+
+=item B<-in> I<file>
+
+Read passwords from I<file>.
+
+=item B<-stdin>
+
+Read passwords from B<stdin>.
+
+=item B<-noverify>
+
+Don't verify when reading a password from the terminal.
+
+=item B<-quiet>
+
+Don't output warnings when passwords given at the command line are truncated.
+
+=item B<-table>
+
+In the output list, prepend the cleartext password and a TAB character
+to each password hash.
+
+=back
+
+=head1 EXAMPLES
+
+B<openssl passwd -crypt -salt xx password> prints B<xxj31ZMTZzkVA>.
+
+B<openssl passwd -1 -salt xxxxxxxx password> prints B<$1$xxxxxxxx$UYCIxa628.9qXjpQCjM4a.>.
+
+B<openssl passwd -apr1 -salt xxxxxxxx password> prints B<$apr1$xxxxxxxx$dxHfLAsjHkDRmG83UXe8K0>.
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/pkcs12.pod b/deps/openssl/openssl/doc/apps/pkcs12.pod
new file mode 100644 (file)
index 0000000..f69a5c5
--- /dev/null
@@ -0,0 +1,363 @@
+
+=pod
+
+=head1 NAME
+
+pkcs12 - PKCS#12 file utility
+
+=head1 SYNOPSIS
+
+B<openssl> B<pkcs12>
+[B<-export>]
+[B<-chain>]
+[B<-inkey filename>]
+[B<-certfile filename>]
+[B<-name name>]
+[B<-caname name>]
+[B<-in filename>]
+[B<-out filename>]
+[B<-noout>]
+[B<-nomacver>]
+[B<-nocerts>]
+[B<-clcerts>]
+[B<-cacerts>]
+[B<-nokeys>]
+[B<-info>]
+[B<-des | -des3 | -idea | -aes128 | -aes192 | -aes256 | -camellia128 | -camellia192 | -camellia256 | -nodes>]
+[B<-noiter>]
+[B<-maciter | -nomaciter | -nomac>]
+[B<-twopass>]
+[B<-descert>]
+[B<-certpbe cipher>]
+[B<-keypbe cipher>]
+[B<-macalg digest>]
+[B<-keyex>]
+[B<-keysig>]
+[B<-password arg>]
+[B<-passin arg>]
+[B<-passout arg>]
+[B<-rand file(s)>]
+[B<-CAfile file>]
+[B<-CApath dir>]
+[B<-CSP name>]
+
+=head1 DESCRIPTION
+
+The B<pkcs12> command allows PKCS#12 files (sometimes referred to as
+PFX files) to be created and parsed. PKCS#12 files are used by several
+programs including Netscape, MSIE and MS Outlook.
+
+=head1 COMMAND OPTIONS
+
+There are a lot of options the meaning of some depends of whether a PKCS#12 file
+is being created or parsed. By default a PKCS#12 file is parsed. A PKCS#12
+file can be created by using the B<-export> option (see below).
+
+=head1 PARSING OPTIONS
+
+=over 4
+
+=item B<-in filename>
+
+This specifies filename of the PKCS#12 file to be parsed. Standard input is used
+by default.
+
+=item B<-out filename>
+
+The filename to write certificates and private keys to, standard output by
+default.  They are all written in PEM format.
+
+=item B<-pass arg>, B<-passin arg>
+
+the PKCS#12 file (i.e. input file) password source. For more information about
+the format of B<arg> see the B<PASS PHRASE ARGUMENTS> section in
+L<openssl(1)|openssl(1)>.
+
+=item B<-passout arg>
+
+pass phrase source to encrypt any outputed private keys with. For more
+information about the format of B<arg> see the B<PASS PHRASE ARGUMENTS> section
+in L<openssl(1)|openssl(1)>.
+
+=item B<-noout>
+
+this option inhibits output of the keys and certificates to the output file
+version of the PKCS#12 file.
+
+=item B<-clcerts>
+
+only output client certificates (not CA certificates).
+
+=item B<-cacerts>
+
+only output CA certificates (not client certificates).
+
+=item B<-nocerts>
+
+no certificates at all will be output.
+
+=item B<-nokeys>
+
+no private keys will be output.
+
+=item B<-info>
+
+output additional information about the PKCS#12 file structure, algorithms used and
+iteration counts.
+
+=item B<-des>
+
+use DES to encrypt private keys before outputting.
+
+=item B<-des3>
+
+use triple DES to encrypt private keys before outputting, this is the default.
+
+=item B<-idea>
+
+use IDEA to encrypt private keys before outputting.
+
+=item B<-aes128>, B<-aes192>, B<-aes256>
+
+use AES to encrypt private keys before outputting.
+
+=item B<-camellia128>, B<-camellia192>, B<-camellia256>
+
+use Camellia to encrypt private keys before outputting.
+
+=item B<-nodes>
+
+don't encrypt the private keys at all.
+
+=item B<-nomacver>
+
+don't attempt to verify the integrity MAC before reading the file.
+
+=item B<-twopass>
+
+prompt for separate integrity and encryption passwords: most software
+always assumes these are the same so this option will render such
+PKCS#12 files unreadable.
+
+=back
+
+=head1 FILE CREATION OPTIONS
+
+=over 4
+
+=item B<-export>
+
+This option specifies that a PKCS#12 file will be created rather than
+parsed.
+
+=item B<-out filename>
+
+This specifies filename to write the PKCS#12 file to. Standard output is used
+by default.
+
+=item B<-in filename>
+
+The filename to read certificates and private keys from, standard input by
+default.  They must all be in PEM format. The order doesn't matter but one
+private key and its corresponding certificate should be present. If additional
+certificates are present they will also be included in the PKCS#12 file.
+
+=item B<-inkey filename>
+
+file to read private key from. If not present then a private key must be present
+in the input file.
+
+=item B<-name friendlyname>
+
+This specifies the "friendly name" for the certificate and private key. This
+name is typically displayed in list boxes by software importing the file.
+
+=item B<-certfile filename>
+
+A filename to read additional certificates from.
+
+=item B<-caname friendlyname>
+
+This specifies the "friendly name" for other certificates. This option may be
+used multiple times to specify names for all certificates in the order they
+appear. Netscape ignores friendly names on other certificates whereas MSIE
+displays them.
+
+=item B<-pass arg>, B<-passout arg>
+
+the PKCS#12 file (i.e. output file) password source. For more information about
+the format of B<arg> see the B<PASS PHRASE ARGUMENTS> section in
+L<openssl(1)|openssl(1)>.
+
+=item B<-passin password>
+
+pass phrase source to decrypt any input private keys with. For more information
+about the format of B<arg> see the B<PASS PHRASE ARGUMENTS> section in
+L<openssl(1)|openssl(1)>.
+
+=item B<-chain>
+
+if this option is present then an attempt is made to include the entire
+certificate chain of the user certificate. The standard CA store is used
+for this search. If the search fails it is considered a fatal error.
+
+=item B<-descert>
+
+encrypt the certificate using triple DES, this may render the PKCS#12
+file unreadable by some "export grade" software. By default the private
+key is encrypted using triple DES and the certificate using 40 bit RC2.
+
+=item B<-keypbe alg>, B<-certpbe alg>
+
+these options allow the algorithm used to encrypt the private key and
+certificates to be selected. Any PKCS#5 v1.5 or PKCS#12 PBE algorithm name
+can be used (see B<NOTES> section for more information). If a a cipher name
+(as output by the B<list-cipher-algorithms> command is specified then it
+is used with PKCS#5 v2.0. For interoperability reasons it is advisable to only
+use PKCS#12 algorithms.
+
+=item B<-keyex|-keysig>
+
+specifies that the private key is to be used for key exchange or just signing.
+This option is only interpreted by MSIE and similar MS software. Normally
+"export grade" software will only allow 512 bit RSA keys to be used for
+encryption purposes but arbitrary length keys for signing. The B<-keysig>
+option marks the key for signing only. Signing only keys can be used for
+S/MIME signing, authenticode (ActiveX control signing)  and SSL client
+authentication, however due to a bug only MSIE 5.0 and later support
+the use of signing only keys for SSL client authentication.
+
+=item B<-macalg digest>
+
+specify the MAC digest algorithm. If not included them SHA1 will be used.
+
+=item B<-nomaciter>, B<-noiter>
+
+these options affect the iteration counts on the MAC and key algorithms.
+Unless you wish to produce files compatible with MSIE 4.0 you should leave
+these options alone.
+
+To discourage attacks by using large dictionaries of common passwords the
+algorithm that derives keys from passwords can have an iteration count applied
+to it: this causes a certain part of the algorithm to be repeated and slows it
+down. The MAC is used to check the file integrity but since it will normally
+have the same password as the keys and certificates it could also be attacked.
+By default both MAC and encryption iteration counts are set to 2048, using
+these options the MAC and encryption iteration counts can be set to 1, since
+this reduces the file security you should not use these options unless you
+really have to. Most software supports both MAC and key iteration counts.
+MSIE 4.0 doesn't support MAC iteration counts so it needs the B<-nomaciter>
+option.
+
+=item B<-maciter>
+
+This option is included for compatibility with previous versions, it used
+to be needed to use MAC iterations counts but they are now used by default.
+
+=item B<-nomac>
+
+don't attempt to provide the MAC integrity.
+
+=item B<-rand file(s)>
+
+a file or files containing random data used to seed the random number
+generator, or an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
+Multiple files can be specified separated by a OS-dependent character.
+The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
+all others.
+
+=item B<-CAfile file>
+
+CA storage as a file.
+
+=item B<-CApath dir>
+
+CA storage as a directory. This directory must be a standard certificate
+directory: that is a hash of each subject name (using B<x509 -hash>) should be
+linked to each certificate.
+
+=item B<-CSP name>
+
+write B<name> as a Microsoft CSP name.
+
+=back
+
+=head1 NOTES
+
+Although there are a large number of options most of them are very rarely
+used. For PKCS#12 file parsing only B<-in> and B<-out> need to be used
+for PKCS#12 file creation B<-export> and B<-name> are also used.
+
+If none of the B<-clcerts>, B<-cacerts> or B<-nocerts> options are present
+then all certificates will be output in the order they appear in the input
+PKCS#12 files. There is no guarantee that the first certificate present is
+the one corresponding to the private key. Certain software which requires
+a private key and certificate and assumes the first certificate in the
+file is the one corresponding to the private key: this may not always
+be the case. Using the B<-clcerts> option will solve this problem by only
+outputting the certificate corresponding to the private key. If the CA
+certificates are required then they can be output to a separate file using
+the B<-nokeys -cacerts> options to just output CA certificates.
+
+The B<-keypbe> and B<-certpbe> algorithms allow the precise encryption
+algorithms for private keys and certificates to be specified. Normally
+the defaults are fine but occasionally software can't handle triple DES
+encrypted private keys, then the option B<-keypbe PBE-SHA1-RC2-40> can
+be used to reduce the private key encryption to 40 bit RC2. A complete
+description of all algorithms is contained in the B<pkcs8> manual page.
+
+=head1 EXAMPLES
+
+Parse a PKCS#12 file and output it to a file:
+
+ openssl pkcs12 -in file.p12 -out file.pem
+
+Output only client certificates to a file:
+
+ openssl pkcs12 -in file.p12 -clcerts -out file.pem
+
+Don't encrypt the private key:
+ openssl pkcs12 -in file.p12 -out file.pem -nodes
+
+Print some info about a PKCS#12 file:
+
+ openssl pkcs12 -in file.p12 -info -noout
+
+Create a PKCS#12 file:
+
+ openssl pkcs12 -export -in file.pem -out file.p12 -name "My Certificate"
+
+Include some extra certificates:
+
+ openssl pkcs12 -export -in file.pem -out file.p12 -name "My Certificate" \
+  -certfile othercerts.pem
+
+=head1 BUGS
+
+Some would argue that the PKCS#12 standard is one big bug :-)
+
+Versions of OpenSSL before 0.9.6a had a bug in the PKCS#12 key generation
+routines. Under rare circumstances this could produce a PKCS#12 file encrypted
+with an invalid key. As a result some PKCS#12 files which triggered this bug
+from other implementations (MSIE or Netscape) could not be decrypted
+by OpenSSL and similarly OpenSSL could produce PKCS#12 files which could
+not be decrypted by other implementations. The chances of producing such
+a file are relatively small: less than 1 in 256.
+
+A side effect of fixing this bug is that any old invalidly encrypted PKCS#12
+files cannot no longer be parsed by the fixed version. Under such circumstances
+the B<pkcs12> utility will report that the MAC is OK but fail with a decryption
+error when extracting private keys.
+
+This problem can be resolved by extracting the private keys and certificates
+from the PKCS#12 file using an older version of OpenSSL and recreating the PKCS#12
+file from the keys and certificates using a newer version of OpenSSL. For example:
+
+ old-openssl -in bad.p12 -out keycerts.pem
+ openssl -in keycerts.pem -export -name "My PKCS#12 file" -out fixed.p12
+
+=head1 SEE ALSO
+
+L<pkcs8(1)|pkcs8(1)>
+
diff --git a/deps/openssl/openssl/doc/apps/pkcs7.pod b/deps/openssl/openssl/doc/apps/pkcs7.pod
new file mode 100644 (file)
index 0000000..acfb810
--- /dev/null
@@ -0,0 +1,105 @@
+=pod
+
+=head1 NAME
+
+pkcs7 - PKCS#7 utility
+
+=head1 SYNOPSIS
+
+B<openssl> B<pkcs7>
+[B<-inform PEM|DER>]
+[B<-outform PEM|DER>]
+[B<-in filename>]
+[B<-out filename>]
+[B<-print_certs>]
+[B<-text>]
+[B<-noout>]
+[B<-engine id>]
+
+=head1 DESCRIPTION
+
+The B<pkcs7> command processes PKCS#7 files in DER or PEM format.
+
+=head1 COMMAND OPTIONS
+
+=over 4
+
+=item B<-inform DER|PEM>
+
+This specifies the input format. B<DER> format is DER encoded PKCS#7
+v1.5 structure.B<PEM> (the default) is a base64 encoded version of
+the DER form with header and footer lines.
+
+=item B<-outform DER|PEM>
+
+This specifies the output format, the options have the same meaning as the 
+B<-inform> option.
+
+=item B<-in filename>
+
+This specifies the input filename to read from or standard input if this
+option is not specified.
+
+=item B<-out filename>
+
+specifies the output filename to write to or standard output by
+default.
+
+=item B<-print_certs>
+
+prints out any certificates or CRLs contained in the file. They are
+preceded by their subject and issuer names in one line format.
+
+=item B<-text>
+
+prints out certificates details in full rather than just subject and
+issuer names.
+
+=item B<-noout>
+
+don't output the encoded version of the PKCS#7 structure (or certificates
+is B<-print_certs> is set).
+
+=item B<-engine id>
+
+specifying an engine (by its unique B<id> string) will cause B<pkcs7>
+to attempt to obtain a functional reference to the specified engine,
+thus initialising it if needed. The engine will then be set as the default
+for all available algorithms.
+
+=back
+
+=head1 EXAMPLES
+
+Convert a PKCS#7 file from PEM to DER:
+
+ openssl pkcs7 -in file.pem -outform DER -out file.der
+
+Output all certificates in a file:
+
+ openssl pkcs7 -in file.pem -print_certs -out certs.pem
+
+=head1 NOTES
+
+The PEM PKCS#7 format uses the header and footer lines:
+
+ -----BEGIN PKCS7-----
+ -----END PKCS7-----
+
+For compatibility with some CAs it will also accept:
+
+ -----BEGIN CERTIFICATE-----
+ -----END CERTIFICATE-----
+
+=head1 RESTRICTIONS
+
+There is no option to print out all the fields of a PKCS#7 file.
+
+This PKCS#7 routines only understand PKCS#7 v 1.5 as specified in RFC2315 they 
+cannot currently parse, for example, the new CMS as described in RFC2630.
+
+=head1 SEE ALSO
+
+L<crl2pkcs7(1)|crl2pkcs7(1)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/pkcs8.pod b/deps/openssl/openssl/doc/apps/pkcs8.pod
new file mode 100644 (file)
index 0000000..84abee7
--- /dev/null
@@ -0,0 +1,243 @@
+=pod
+
+=head1 NAME
+
+pkcs8 - PKCS#8 format private key conversion tool
+
+=head1 SYNOPSIS
+
+B<openssl> B<pkcs8>
+[B<-topk8>]
+[B<-inform PEM|DER>]
+[B<-outform PEM|DER>]
+[B<-in filename>]
+[B<-passin arg>]
+[B<-out filename>]
+[B<-passout arg>]
+[B<-noiter>]
+[B<-nocrypt>]
+[B<-nooct>]
+[B<-embed>]
+[B<-nsdb>]
+[B<-v2 alg>]
+[B<-v1 alg>]
+[B<-engine id>]
+
+=head1 DESCRIPTION
+
+The B<pkcs8> command processes private keys in PKCS#8 format. It can handle
+both unencrypted PKCS#8 PrivateKeyInfo format and EncryptedPrivateKeyInfo
+format with a variety of PKCS#5 (v1.5 and v2.0) and PKCS#12 algorithms.
+
+=head1 COMMAND OPTIONS
+
+=over 4
+
+=item B<-topk8>
+
+Normally a PKCS#8 private key is expected on input and a traditional format
+private key will be written. With the B<-topk8> option the situation is
+reversed: it reads a traditional format private key and writes a PKCS#8
+format key.
+
+=item B<-inform DER|PEM>
+
+This specifies the input format. If a PKCS#8 format key is expected on input
+then either a B<DER> or B<PEM> encoded version of a PKCS#8 key will be
+expected. Otherwise the B<DER> or B<PEM> format of the traditional format
+private key is used.
+
+=item B<-outform DER|PEM>
+
+This specifies the output format, the options have the same meaning as the 
+B<-inform> option.
+
+=item B<-in filename>
+
+This specifies the input filename to read a key from or standard input if this
+option is not specified. If the key is encrypted a pass phrase will be
+prompted for.
+
+=item B<-passin arg>
+
+the input file password source. For more information about the format of B<arg>
+see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
+
+=item B<-out filename>
+
+This specifies the output filename to write a key to or standard output by
+default. If any encryption options are set then a pass phrase will be
+prompted for. The output filename should B<not> be the same as the input
+filename.
+
+=item B<-passout arg>
+
+the output file password source. For more information about the format of B<arg>
+see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
+
+=item B<-nocrypt>
+
+PKCS#8 keys generated or input are normally PKCS#8 EncryptedPrivateKeyInfo
+structures using an appropriate password based encryption algorithm. With
+this option an unencrypted PrivateKeyInfo structure is expected or output.
+This option does not encrypt private keys at all and should only be used
+when absolutely necessary. Certain software such as some versions of Java
+code signing software used unencrypted private keys.
+
+=item B<-nooct>
+
+This option generates RSA private keys in a broken format that some software
+uses. Specifically the private key should be enclosed in a OCTET STRING
+but some software just includes the structure itself without the
+surrounding OCTET STRING.
+
+=item B<-embed>
+
+This option generates DSA keys in a broken format. The DSA parameters are
+embedded inside the PrivateKey structure. In this form the OCTET STRING
+contains an ASN1 SEQUENCE consisting of two structures: a SEQUENCE containing
+the parameters and an ASN1 INTEGER containing the private key.
+
+=item B<-nsdb>
+
+This option generates DSA keys in a broken format compatible with Netscape
+private key databases. The PrivateKey contains a SEQUENCE consisting of
+the public and private keys respectively.
+
+=item B<-v2 alg>
+
+This option enables the use of PKCS#5 v2.0 algorithms. Normally PKCS#8
+private keys are encrypted with the password based encryption algorithm
+called B<pbeWithMD5AndDES-CBC> this uses 56 bit DES encryption but it
+was the strongest encryption algorithm supported in PKCS#5 v1.5. Using 
+the B<-v2> option PKCS#5 v2.0 algorithms are used which can use any
+encryption algorithm such as 168 bit triple DES or 128 bit RC2 however
+not many implementations support PKCS#5 v2.0 yet. If you are just using
+private keys with OpenSSL then this doesn't matter.
+
+The B<alg> argument is the encryption algorithm to use, valid values include
+B<des>, B<des3> and B<rc2>. It is recommended that B<des3> is used.
+
+=item B<-v1 alg>
+
+This option specifies a PKCS#5 v1.5 or PKCS#12 algorithm to use. A complete
+list of possible algorithms is included below.
+
+=item B<-engine id>
+
+specifying an engine (by its unique B<id> string) will cause B<pkcs8>
+to attempt to obtain a functional reference to the specified engine,
+thus initialising it if needed. The engine will then be set as the default
+for all available algorithms.
+
+=back
+
+=head1 NOTES
+
+The encrypted form of a PEM encode PKCS#8 files uses the following
+headers and footers:
+
+ -----BEGIN ENCRYPTED PRIVATE KEY-----
+ -----END ENCRYPTED PRIVATE KEY-----
+
+The unencrypted form uses:
+
+ -----BEGIN PRIVATE KEY-----
+ -----END PRIVATE KEY-----
+
+Private keys encrypted using PKCS#5 v2.0 algorithms and high iteration
+counts are more secure that those encrypted using the traditional
+SSLeay compatible formats. So if additional security is considered
+important the keys should be converted.
+
+The default encryption is only 56 bits because this is the encryption
+that most current implementations of PKCS#8 will support.
+
+Some software may use PKCS#12 password based encryption algorithms
+with PKCS#8 format private keys: these are handled automatically
+but there is no option to produce them.
+
+It is possible to write out DER encoded encrypted private keys in
+PKCS#8 format because the encryption details are included at an ASN1
+level whereas the traditional format includes them at a PEM level.
+
+=head1 PKCS#5 v1.5 and PKCS#12 algorithms.
+
+Various algorithms can be used with the B<-v1> command line option,
+including PKCS#5 v1.5 and PKCS#12. These are described in more detail
+below.
+
+=over 4
+
+=item B<PBE-MD2-DES PBE-MD5-DES>
+
+These algorithms were included in the original PKCS#5 v1.5 specification.
+They only offer 56 bits of protection since they both use DES.
+
+=item B<PBE-SHA1-RC2-64 PBE-MD2-RC2-64 PBE-MD5-RC2-64 PBE-SHA1-DES>
+
+These algorithms are not mentioned in the original PKCS#5 v1.5 specification
+but they use the same key derivation algorithm and are supported by some
+software. They are mentioned in PKCS#5 v2.0. They use either 64 bit RC2 or
+56 bit DES.
+
+=item B<PBE-SHA1-RC4-128 PBE-SHA1-RC4-40 PBE-SHA1-3DES PBE-SHA1-2DES PBE-SHA1-RC2-128 PBE-SHA1-RC2-40>
+
+These algorithms use the PKCS#12 password based encryption algorithm and
+allow strong encryption algorithms like triple DES or 128 bit RC2 to be used.
+
+=back
+
+=head1 EXAMPLES
+
+Convert a private from traditional to PKCS#5 v2.0 format using triple
+DES:
+
+ openssl pkcs8 -in key.pem -topk8 -v2 des3 -out enckey.pem
+
+Convert a private key to PKCS#8 using a PKCS#5 1.5 compatible algorithm
+(DES):
+
+ openssl pkcs8 -in key.pem -topk8 -out enckey.pem
+
+Convert a private key to PKCS#8 using a PKCS#12 compatible algorithm
+(3DES):
+
+ openssl pkcs8 -in key.pem -topk8 -out enckey.pem -v1 PBE-SHA1-3DES
+
+Read a DER unencrypted PKCS#8 format private key:
+
+ openssl pkcs8 -inform DER -nocrypt -in key.der -out key.pem
+
+Convert a private key from any PKCS#8 format to traditional format:
+
+ openssl pkcs8 -in pk8.pem -out key.pem
+
+=head1 STANDARDS
+
+Test vectors from this PKCS#5 v2.0 implementation were posted to the
+pkcs-tng mailing list using triple DES, DES and RC2 with high iteration
+counts, several people confirmed that they could decrypt the private
+keys produced and Therefore it can be assumed that the PKCS#5 v2.0
+implementation is reasonably accurate at least as far as these
+algorithms are concerned.
+
+The format of PKCS#8 DSA (and other) private keys is not well documented:
+it is hidden away in PKCS#11 v2.01, section 11.9. OpenSSL's default DSA
+PKCS#8 private key format complies with this standard.
+
+=head1 BUGS
+
+There should be an option that prints out the encryption algorithm
+in use and other details such as the iteration count.
+
+PKCS#8 using triple DES and PKCS#5 v2.0 should be the default private
+key format for OpenSSL: for compatibility several of the utilities use
+the old format at present.
+
+=head1 SEE ALSO
+
+L<dsa(1)|dsa(1)>, L<rsa(1)|rsa(1)>, L<genrsa(1)|genrsa(1)>,
+L<gendsa(1)|gendsa(1)> 
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/pkey.pod b/deps/openssl/openssl/doc/apps/pkey.pod
new file mode 100644 (file)
index 0000000..4851223
--- /dev/null
@@ -0,0 +1,135 @@
+
+=pod
+
+=head1 NAME
+
+pkey - public or private key processing tool
+
+=head1 SYNOPSIS
+
+B<openssl> B<pkey>
+[B<-inform PEM|DER>]
+[B<-outform PEM|DER>]
+[B<-in filename>]
+[B<-passin arg>]
+[B<-out filename>]
+[B<-passout arg>]
+[B<-cipher>]
+[B<-text>]
+[B<-text_pub>]
+[B<-noout>]
+[B<-pubin>]
+[B<-pubout>]
+[B<-engine id>]
+
+=head1 DESCRIPTION
+
+The B<pkey> command processes public or private keys. They can be converted
+between various forms and their components printed out.
+
+=head1 COMMAND OPTIONS
+
+=over 4
+
+=item B<-inform DER|PEM>
+
+This specifies the input format DER or PEM.
+
+=item B<-outform DER|PEM>
+
+This specifies the output format, the options have the same meaning as the 
+B<-inform> option.
+
+=item B<-in filename>
+
+This specifies the input filename to read a key from or standard input if this
+option is not specified. If the key is encrypted a pass phrase will be
+prompted for.
+
+=item B<-passin arg>
+
+the input file password source. For more information about the format of B<arg>
+see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
+
+=item B<-out filename>
+
+This specifies the output filename to write a key to or standard output if this
+option is not specified. If any encryption options are set then a pass phrase
+will be prompted for. The output filename should B<not> be the same as the input
+filename.
+
+=item B<-passout password>
+
+the output file password source. For more information about the format of B<arg>
+see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
+
+=item B<-cipher>
+
+These options encrypt the private key with the supplied cipher. Any algorithm
+name accepted by EVP_get_cipherbyname() is acceptable such as B<des3>.
+
+=item B<-text>
+
+prints out the various public or private key components in
+plain text in addition to the encoded version. 
+
+=item B<-text_pub>
+
+print out only public key components even if a private key is being processed.
+
+=item B<-noout>
+
+do not output the encoded version of the key.
+
+=item B<-pubin>
+
+by default a private key is read from the input file: with this
+option a public key is read instead.
+
+=item B<-pubout>
+
+by default a private key is output: with this option a public
+key will be output instead. This option is automatically set if
+the input is a public key.
+
+=item B<-engine id>
+
+specifying an engine (by its unique B<id> string) will cause B<pkey>
+to attempt to obtain a functional reference to the specified engine,
+thus initialising it if needed. The engine will then be set as the default
+for all available algorithms.
+
+=back
+
+=head1 EXAMPLES
+
+To remove the pass phrase on an RSA private key:
+
+ openssl pkey -in key.pem -out keyout.pem
+
+To encrypt a private key using triple DES:
+
+ openssl pkey -in key.pem -des3 -out keyout.pem
+
+To convert a private key from PEM to DER format: 
+
+ openssl pkey -in key.pem -outform DER -out keyout.der
+
+To print out the components of a private key to standard output:
+
+ openssl pkey -in key.pem -text -noout
+
+To print out the public components of a private key to standard output:
+
+ openssl pkey -in key.pem -text_pub -noout
+
+To just output the public part of a private key:
+
+ openssl pkey -in key.pem -pubout -out pubkey.pem
+
+=head1 SEE ALSO
+
+L<genpkey(1)|genpkey(1)>, L<rsa(1)|rsa(1)>, L<pkcs8(1)|pkcs8(1)>,
+L<dsa(1)|dsa(1)>, L<genrsa(1)|genrsa(1)>, L<gendsa(1)|gendsa(1)> 
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/pkeyparam.pod b/deps/openssl/openssl/doc/apps/pkeyparam.pod
new file mode 100644 (file)
index 0000000..154f672
--- /dev/null
@@ -0,0 +1,69 @@
+
+=pod
+
+=head1 NAME
+
+pkeyparam - public key algorithm parameter processing tool
+
+=head1 SYNOPSIS
+
+B<openssl> B<pkeyparam>
+[B<-in filename>]
+[B<-out filename>]
+[B<-text>]
+[B<-noout>]
+[B<-engine id>]
+
+=head1 DESCRIPTION
+
+The B<pkey> command processes public or private keys. They can be converted
+between various forms and their components printed out.
+
+=head1 COMMAND OPTIONS
+
+=over 4
+
+=item B<-in filename>
+
+This specifies the input filename to read parameters from or standard input if
+this option is not specified.
+
+=item B<-out filename>
+
+This specifies the output filename to write parameters to or standard output if
+this option is not specified.
+
+=item B<-text>
+
+prints out the parameters in plain text in addition to the encoded version. 
+
+=item B<-noout>
+
+do not output the encoded version of the parameters.
+
+=item B<-engine id>
+
+specifying an engine (by its unique B<id> string) will cause B<pkeyparam>
+to attempt to obtain a functional reference to the specified engine,
+thus initialising it if needed. The engine will then be set as the default
+for all available algorithms.
+
+=back
+
+=head1 EXAMPLE
+
+Print out text version of parameters:
+
+ openssl pkeyparam -in param.pem -text
+
+=head1 NOTES
+
+There are no B<-inform> or B<-outform> options for this command because only
+PEM format is supported because the key type is determined by the PEM headers.
+
+=head1 SEE ALSO
+
+L<genpkey(1)|genpkey(1)>, L<rsa(1)|rsa(1)>, L<pkcs8(1)|pkcs8(1)>,
+L<dsa(1)|dsa(1)>, L<genrsa(1)|genrsa(1)>, L<gendsa(1)|gendsa(1)> 
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/pkeyutl.pod b/deps/openssl/openssl/doc/apps/pkeyutl.pod
new file mode 100644 (file)
index 0000000..27be9a9
--- /dev/null
@@ -0,0 +1,222 @@
+=pod
+
+=head1 NAME
+
+pkeyutl - public key algorithm utility
+
+=head1 SYNOPSIS
+
+B<openssl> B<pkeyutl>
+[B<-in file>]
+[B<-out file>]
+[B<-sigfile file>]
+[B<-inkey file>]
+[B<-keyform PEM|DER>]
+[B<-passin arg>]
+[B<-peerkey file>]
+[B<-peerform PEM|DER>]
+[B<-pubin>]
+[B<-certin>]
+[B<-rev>]
+[B<-sign>]
+[B<-verify>]
+[B<-verifyrecover>]
+[B<-encrypt>]
+[B<-decrypt>]
+[B<-derive>]
+[B<-pkeyopt opt:value>]
+[B<-hexdump>]
+[B<-asn1parse>]
+[B<-engine id>]
+
+=head1 DESCRIPTION
+
+The B<pkeyutl> command can be used to perform public key operations using
+any supported algorithm.
+
+=head1 COMMAND OPTIONS
+
+=over 4
+
+=item B<-in filename>
+
+This specifies the input filename to read data from or standard input
+if this option is not specified.
+
+=item B<-out filename>
+
+specifies the output filename to write to or standard output by
+default.
+
+=item B<-inkey file>
+
+the input key file, by default it should be a private key.
+
+=item B<-keyform PEM|DER>
+
+the key format PEM, DER or ENGINE.
+
+=item B<-passin arg>
+
+the input key password source. For more information about the format of B<arg>
+see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
+
+
+=item B<-peerkey file>
+
+the peer key file, used by key derivation (agreement) operations.
+
+=item B<-peerform PEM|DER>
+
+the peer key format PEM, DER or ENGINE.
+
+=item B<-engine id>
+
+specifying an engine (by its unique B<id> string) will cause B<pkeyutl>
+to attempt to obtain a functional reference to the specified engine,
+thus initialising it if needed. The engine will then be set as the default
+for all available algorithms.
+
+
+=item B<-pubin>
+
+the input file is a public key. 
+
+=item B<-certin>
+
+the input is a certificate containing a public key. 
+
+=item B<-rev>
+
+reverse the order of the input buffer. This is useful for some libraries
+(such as CryptoAPI) which represent the buffer in little endian format.
+
+=item B<-sign>
+
+sign the input data and output the signed result. This requires
+a private key.
+
+=item B<-verify>
+
+verify the input data against the signature file and indicate if the
+verification succeeded or failed.
+
+=item B<-verifyrecover>
+
+verify the input data and output the recovered data.
+
+=item B<-encrypt>
+
+encrypt the input data using a public key.
+
+=item B<-decrypt>
+
+decrypt the input data using a private key.
+
+=item B<-derive>
+
+derive a shared secret using the peer key.
+
+=item B<-hexdump>
+
+hex dump the output data.
+
+=item B<-asn1parse>
+
+asn1parse the output data, this is useful when combined with the
+B<-verifyrecover> option when an ASN1 structure is signed.
+
+=back
+
+=head1 NOTES
+
+The operations and options supported vary according to the key algorithm
+and its implementation. The OpenSSL operations and options are indicated below.
+
+Unless otherwise mentioned all algorithms support the B<digest:alg> option
+which specifies the digest in use for sign, verify and verifyrecover operations.
+The value B<alg> should represent a digest name as used in the
+EVP_get_digestbyname() function for example B<sha1>.
+
+=head1 RSA ALGORITHM
+
+The RSA algorithm supports encrypt, decrypt, sign, verify and verifyrecover
+operations in general. Some padding modes only support some of these 
+operations however.
+
+=over 4
+
+=item -B<rsa_padding_mode:mode>
+
+This sets the RSA padding mode. Acceptable values for B<mode> are B<pkcs1> for
+PKCS#1 padding, B<sslv23> for SSLv23 padding, B<none> for no padding, B<oaep>
+for B<OAEP> mode, B<x931> for X9.31 mode and B<pss> for PSS.
+
+In PKCS#1 padding if the message digest is not set then the supplied data is 
+signed or verified directly instead of using a B<DigestInfo> structure. If a
+digest is set then the a B<DigestInfo> structure is used and its the length
+must correspond to the digest type.
+
+For B<oeap> mode only encryption and decryption is supported.
+
+For B<x931> if the digest type is set it is used to format the block data
+otherwise the first byte is used to specify the X9.31 digest ID. Sign,
+verify and verifyrecover are can be performed in this mode.
+
+For B<pss> mode only sign and verify are supported and the digest type must be
+specified.
+
+=item B<rsa_pss_saltlen:len>
+
+For B<pss> mode only this option specifies the salt length. Two special values
+are supported: -1 sets the salt length to the digest length. When signing -2
+sets the salt length to the maximum permissible value. When verifying -2 causes
+the salt length to be automatically determined based on the B<PSS> block
+structure.
+
+=back
+
+=head1 DSA ALGORITHM
+
+The DSA algorithm supports signing and verification operations only. Currently
+there are no additional options other than B<digest>. Only the SHA1
+digest can be used and this digest is assumed by default.
+
+=head1 DH ALGORITHM
+
+The DH algorithm only supports the derivation operation and no additional
+options.
+
+=head1 EC ALGORITHM
+
+The EC algorithm supports sign, verify and derive operations. The sign and
+verify operations use ECDSA and derive uses ECDH. Currently there are no
+additional options other than B<digest>. Only the SHA1 digest can be used and
+this digest is assumed by default.
+
+=head1 EXAMPLES
+
+Sign some data using a private key:
+
+ openssl pkeyutl -sign -in file -inkey key.pem -out sig
+
+Recover the signed data (e.g. if an RSA key is used):
+
+ openssl pkeyutl -verifyrecover -in sig -inkey key.pem
+
+Verify the signature (e.g. a DSA key):
+
+ openssl pkeyutl -verify -in file -sigfile sig -inkey key.pem
+
+Sign data using a message digest value (this is currently only valid for RSA):
+
+ openssl pkeyutl -sign -in file -inkey key.pem -out sig -pkeyopt digest:sha256
+
+Derive a shared secret value:
+
+ openssl pkeyutl -derive -inkey key.pem -peerkey pubkey.pem -out secret
+
+=head1 SEE ALSO
+
+L<genpkey(1)|genpkey(1)>, L<pkey(1)|pkey(1)>, L<rsautl(1)|rsautl(1)>
+L<dgst(1)|dgst(1)>, L<rsa(1)|rsa(1)>, L<genrsa(1)|genrsa(1)>
diff --git a/deps/openssl/openssl/doc/apps/rand.pod b/deps/openssl/openssl/doc/apps/rand.pod
new file mode 100644 (file)
index 0000000..d1d213e
--- /dev/null
@@ -0,0 +1,55 @@
+=pod
+
+=head1 NAME
+
+rand - generate pseudo-random bytes
+
+=head1 SYNOPSIS
+
+B<openssl rand>
+[B<-out> I<file>]
+[B<-rand> I<file(s)>]
+[B<-base64>]
+[B<-hex>]
+I<num>
+
+=head1 DESCRIPTION
+
+The B<rand> command outputs I<num> pseudo-random bytes after seeding
+the random number generator once.  As in other B<openssl> command
+line tools, PRNG seeding uses the file I<$HOME/>B<.rnd> or B<.rnd>
+in addition to the files given in the B<-rand> option.  A new
+I<$HOME>/B<.rnd> or B<.rnd> file will be written back if enough
+seeding was obtained from these sources.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-out> I<file>
+
+Write to I<file> instead of standard output.
+
+=item B<-rand> I<file(s)>
+
+Use specified file or files or EGD socket (see L<RAND_egd(3)|RAND_egd(3)>)
+for seeding the random number generator.
+Multiple files can be specified separated by a OS-dependent character.
+The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
+all others.
+
+=item B<-base64>
+
+Perform base64 encoding on the output.
+
+=item B<-hex>
+
+Show the output as a hex string.
+
+=back
+
+=head1 SEE ALSO
+
+L<RAND_bytes(3)|RAND_bytes(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/req.pod b/deps/openssl/openssl/doc/apps/req.pod
new file mode 100644 (file)
index 0000000..ff48bbd
--- /dev/null
@@ -0,0 +1,678 @@
+
+=pod
+
+=head1 NAME
+
+req - PKCS#10 certificate request and certificate generating utility.
+
+=head1 SYNOPSIS
+
+B<openssl> B<req>
+[B<-inform PEM|DER>]
+[B<-outform PEM|DER>]
+[B<-in filename>]
+[B<-passin arg>]
+[B<-out filename>]
+[B<-passout arg>]
+[B<-text>]
+[B<-pubkey>]
+[B<-noout>]
+[B<-verify>]
+[B<-modulus>]
+[B<-new>]
+[B<-rand file(s)>]
+[B<-newkey rsa:bits>]
+[B<-newkey alg:file>]
+[B<-nodes>]
+[B<-key filename>]
+[B<-keyform PEM|DER>]
+[B<-keyout filename>]
+[B<-keygen_engine id>]
+[B<-[digest]>]
+[B<-config filename>]
+[B<-subj arg>]
+[B<-multivalue-rdn>]
+[B<-x509>]
+[B<-days n>]
+[B<-set_serial n>]
+[B<-asn1-kludge>]
+[B<-no-asn1-kludge>]
+[B<-newhdr>]
+[B<-extensions section>]
+[B<-reqexts section>]
+[B<-utf8>]
+[B<-nameopt>]
+[B<-reqopt>]
+[B<-subject>]
+[B<-subj arg>]
+[B<-batch>]
+[B<-verbose>]
+[B<-engine id>]
+
+=head1 DESCRIPTION
+
+The B<req> command primarily creates and processes certificate requests
+in PKCS#10 format. It can additionally create self signed certificates
+for use as root CAs for example.
+
+=head1 COMMAND OPTIONS
+
+=over 4
+
+=item B<-inform DER|PEM>
+
+This specifies the input format. The B<DER> option uses an ASN1 DER encoded
+form compatible with the PKCS#10. The B<PEM> form is the default format: it
+consists of the B<DER> format base64 encoded with additional header and
+footer lines.
+
+=item B<-outform DER|PEM>
+
+This specifies the output format, the options have the same meaning as the 
+B<-inform> option.
+
+=item B<-in filename>
+
+This specifies the input filename to read a request from or standard input
+if this option is not specified. A request is only read if the creation
+options (B<-new> and B<-newkey>) are not specified.
+
+=item B<-passin arg>
+
+the input file password source. For more information about the format of B<arg>
+see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
+
+=item B<-out filename>
+
+This specifies the output filename to write to or standard output by
+default.
+
+=item B<-passout arg>
+
+the output file password source. For more information about the format of B<arg>
+see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
+
+=item B<-text>
+
+prints out the certificate request in text form.
+
+=item B<-subject>
+
+prints out the request subject (or certificate subject if B<-x509> is
+specified)
+
+=item B<-pubkey>
+
+outputs the public key.
+
+=item B<-noout>
+
+this option prevents output of the encoded version of the request.
+
+=item B<-modulus>
+
+this option prints out the value of the modulus of the public key
+contained in the request.
+
+=item B<-verify>
+
+verifies the signature on the request.
+
+=item B<-new>
+
+this option generates a new certificate request. It will prompt
+the user for the relevant field values. The actual fields
+prompted for and their maximum and minimum sizes are specified
+in the configuration file and any requested extensions.
+
+If the B<-key> option is not used it will generate a new RSA private
+key using information specified in the configuration file.
+
+=item B<-subj arg>
+
+Replaces subject field of input request with specified data and outputs
+modified request. The arg must be formatted as
+I</type0=value0/type1=value1/type2=...>,
+characters may be escaped by \ (backslash), no spaces are skipped.
+
+=item B<-rand file(s)>
+
+a file or files containing random data used to seed the random number
+generator, or an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
+Multiple files can be specified separated by a OS-dependent character.
+The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
+all others.
+
+=item B<-newkey arg>
+
+this option creates a new certificate request and a new private
+key. The argument takes one of several forms. B<rsa:nbits>, where
+B<nbits> is the number of bits, generates an RSA key B<nbits>
+in size. If B<nbits> is omitted, i.e. B<-newkey rsa> specified,
+the default key size, specified in the configuration file is used.
+
+All other algorithms support the B<-newkey alg:file> form, where file may be
+an algorithm parameter file, created by the B<genpkey -genparam> command
+or and X.509 certificate for a key with approriate algorithm.
+
+B<param:file> generates a key using the parameter file or certificate B<file>,
+the algorithm is determined by the parameters. B<algname:file> use algorithm
+B<algname> and parameter file B<file>: the two algorithms must match or an
+error occurs. B<algname> just uses algorithm B<algname>, and parameters,
+if neccessary should be specified via B<-pkeyopt> parameter.
+
+B<dsa:filename> generates a DSA key using the parameters
+in the file B<filename>. B<ec:filename> generates EC key (usable both with
+ECDSA or ECDH algorithms), B<gost2001:filename> generates GOST R
+34.10-2001 key (requires B<ccgost> engine configured in the configuration
+file). If just B<gost2001> is specified a parameter set should be
+specified by B<-pkeyopt paramset:X>
+
+
+=item B<-pkeyopt opt:value>
+
+set the public key algorithm option B<opt> to B<value>. The precise set of
+options supported depends on the public key algorithm used and its
+implementation. See B<KEY GENERATION OPTIONS> in the B<genpkey> manual page
+for more details.
+
+=item B<-key filename>
+
+This specifies the file to read the private key from. It also
+accepts PKCS#8 format private keys for PEM format files.
+
+=item B<-keyform PEM|DER>
+
+the format of the private key file specified in the B<-key>
+argument. PEM is the default.
+
+=item B<-keyout filename>
+
+this gives the filename to write the newly created private key to.
+If this option is not specified then the filename present in the
+configuration file is used.
+
+=item B<-nodes>
+
+if this option is specified then if a private key is created it
+will not be encrypted.
+
+=item B<-[digest]>
+
+this specifies the message digest to sign the request with (such as
+B<-md5>, B<-sha1>). This overrides the digest algorithm specified in
+the configuration file.
+
+Some public key algorithms may override this choice. For instance, DSA
+signatures always use SHA1, GOST R 34.10 signatures always use
+GOST R 34.11-94 (B<-md_gost94>).
+
+=item B<-config filename>
+
+this allows an alternative configuration file to be specified,
+this overrides the compile time filename or any specified in
+the B<OPENSSL_CONF> environment variable.
+
+=item B<-subj arg>
+
+sets subject name for new request or supersedes the subject name
+when processing a request.
+The arg must be formatted as I</type0=value0/type1=value1/type2=...>,
+characters may be escaped by \ (backslash), no spaces are skipped.
+
+=item B<-multivalue-rdn>
+
+this option causes the -subj argument to be interpreted with full
+support for multivalued RDNs. Example:
+
+I</DC=org/DC=OpenSSL/DC=users/UID=123456+CN=John Doe>
+
+If -multi-rdn is not used then the UID value is I<123456+CN=John Doe>.
+
+=item B<-x509>
+
+this option outputs a self signed certificate instead of a certificate
+request. This is typically used to generate a test certificate or
+a self signed root CA. The extensions added to the certificate
+(if any) are specified in the configuration file. Unless specified
+using the B<set_serial> option B<0> will be used for the serial
+number.
+
+=item B<-days n>
+
+when the B<-x509> option is being used this specifies the number of
+days to certify the certificate for. The default is 30 days.
+
+=item B<-set_serial n>
+
+serial number to use when outputting a self signed certificate. This
+may be specified as a decimal value or a hex value if preceded by B<0x>.
+It is possible to use negative serial numbers but this is not recommended.
+
+=item B<-extensions section>
+
+=item B<-reqexts section>
+
+these options specify alternative sections to include certificate
+extensions (if the B<-x509> option is present) or certificate
+request extensions. This allows several different sections to
+be used in the same configuration file to specify requests for
+a variety of purposes.
+
+=item B<-utf8>
+
+this option causes field values to be interpreted as UTF8 strings, by 
+default they are interpreted as ASCII. This means that the field
+values, whether prompted from a terminal or obtained from a
+configuration file, must be valid UTF8 strings.
+
+=item B<-nameopt option>
+
+option which determines how the subject or issuer names are displayed. The
+B<option> argument can be a single option or multiple options separated by
+commas.  Alternatively the B<-nameopt> switch may be used more than once to
+set multiple options. See the L<x509(1)|x509(1)> manual page for details.
+
+=item B<-reqopt>
+
+customise the output format used with B<-text>. The B<option> argument can be
+a single option or multiple options separated by commas. 
+
+See discission of the  B<-certopt> parameter in the L<B<x509>|x509(1)>
+command.
+
+
+=item B<-asn1-kludge>
+
+by default the B<req> command outputs certificate requests containing
+no attributes in the correct PKCS#10 format. However certain CAs will only
+accept requests containing no attributes in an invalid form: this
+option produces this invalid format.
+
+More precisely the B<Attributes> in a PKCS#10 certificate request
+are defined as a B<SET OF Attribute>. They are B<not OPTIONAL> so
+if no attributes are present then they should be encoded as an
+empty B<SET OF>. The invalid form does not include the empty
+B<SET OF> whereas the correct form does.
+
+It should be noted that very few CAs still require the use of this option.
+
+=item B<-no-asn1-kludge>
+
+Reverses effect of B<-asn1-kludge>
+
+=item B<-newhdr>
+
+Adds the word B<NEW> to the PEM file header and footer lines on the outputed
+request. Some software (Netscape certificate server) and some CAs need this.
+
+=item B<-batch>
+
+non-interactive mode.
+
+=item B<-verbose>
+
+print extra details about the operations being performed.
+
+=item B<-engine id>
+
+specifying an engine (by its unique B<id> string) will cause B<req>
+to attempt to obtain a functional reference to the specified engine,
+thus initialising it if needed. The engine will then be set as the default
+for all available algorithms.
+
+=item B<-keygen_engine id>
+
+specifies an engine (by its unique B<id> string) which would be used
+for key generation operations.
+
+=back
+
+=head1 CONFIGURATION FILE FORMAT
+
+The configuration options are specified in the B<req> section of
+the configuration file. As with all configuration files if no
+value is specified in the specific section (i.e. B<req>) then
+the initial unnamed or B<default> section is searched too.
+
+The options available are described in detail below.
+
+=over 4
+
+=item B<input_password output_password>
+
+The passwords for the input private key file (if present) and
+the output private key file (if one will be created). The
+command line options B<passin> and B<passout> override the
+configuration file values.
+
+=item B<default_bits>
+
+This specifies the default key size in bits. If not specified then
+512 is used. It is used if the B<-new> option is used. It can be
+overridden by using the B<-newkey> option.
+
+=item B<default_keyfile>
+
+This is the default filename to write a private key to. If not
+specified the key is written to standard output. This can be
+overridden by the B<-keyout> option.
+
+=item B<oid_file>
+
+This specifies a file containing additional B<OBJECT IDENTIFIERS>.
+Each line of the file should consist of the numerical form of the
+object identifier followed by white space then the short name followed
+by white space and finally the long name. 
+
+=item B<oid_section>
+
+This specifies a section in the configuration file containing extra
+object identifiers. Each line should consist of the short name of the
+object identifier followed by B<=> and the numerical form. The short
+and long names are the same when this option is used.
+
+=item B<RANDFILE>
+
+This specifies a filename in which random number seed information is
+placed and read from, or an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
+It is used for private key generation.
+
+=item B<encrypt_key>
+
+If this is set to B<no> then if a private key is generated it is
+B<not> encrypted. This is equivalent to the B<-nodes> command line
+option. For compatibility B<encrypt_rsa_key> is an equivalent option.
+
+=item B<default_md>
+
+This option specifies the digest algorithm to use. Possible values
+include B<md5 sha1 mdc2>. If not present then MD5 is used. This
+option can be overridden on the command line.
+
+=item B<string_mask>
+
+This option masks out the use of certain string types in certain
+fields. Most users will not need to change this option.
+
+It can be set to several values B<default> which is also the default
+option uses PrintableStrings, T61Strings and BMPStrings if the 
+B<pkix> value is used then only PrintableStrings and BMPStrings will
+be used. This follows the PKIX recommendation in RFC2459. If the
+B<utf8only> option is used then only UTF8Strings will be used: this
+is the PKIX recommendation in RFC2459 after 2003. Finally the B<nombstr>
+option just uses PrintableStrings and T61Strings: certain software has
+problems with BMPStrings and UTF8Strings: in particular Netscape.
+
+=item B<req_extensions>
+
+this specifies the configuration file section containing a list of
+extensions to add to the certificate request. It can be overridden
+by the B<-reqexts> command line switch. See the 
+L<x509v3_config(5)|x509v3_config(5)> manual page for details of the
+extension section format.
+
+=item B<x509_extensions>
+
+this specifies the configuration file section containing a list of
+extensions to add to certificate generated when the B<-x509> switch
+is used. It can be overridden by the B<-extensions> command line switch.
+
+=item B<prompt>
+
+if set to the value B<no> this disables prompting of certificate fields
+and just takes values from the config file directly. It also changes the
+expected format of the B<distinguished_name> and B<attributes> sections.
+
+=item B<utf8>
+
+if set to the value B<yes> then field values to be interpreted as UTF8
+strings, by default they are interpreted as ASCII. This means that
+the field values, whether prompted from a terminal or obtained from a
+configuration file, must be valid UTF8 strings.
+
+=item B<attributes>
+
+this specifies the section containing any request attributes: its format
+is the same as B<distinguished_name>. Typically these may contain the
+challengePassword or unstructuredName types. They are currently ignored
+by OpenSSL's request signing utilities but some CAs might want them.
+
+=item B<distinguished_name>
+
+This specifies the section containing the distinguished name fields to
+prompt for when generating a certificate or certificate request. The format
+is described in the next section.
+
+=back
+
+=head1 DISTINGUISHED NAME AND ATTRIBUTE SECTION FORMAT
+
+There are two separate formats for the distinguished name and attribute
+sections. If the B<prompt> option is set to B<no> then these sections
+just consist of field names and values: for example,
+
+ CN=My Name
+ OU=My Organization
+ emailAddress=someone@somewhere.org
+
+This allows external programs (e.g. GUI based) to generate a template file
+with all the field names and values and just pass it to B<req>. An example
+of this kind of configuration file is contained in the B<EXAMPLES> section.
+
+Alternatively if the B<prompt> option is absent or not set to B<no> then the
+file contains field prompting information. It consists of lines of the form:
+
+ fieldName="prompt"
+ fieldName_default="default field value"
+ fieldName_min= 2
+ fieldName_max= 4
+
+"fieldName" is the field name being used, for example commonName (or CN).
+The "prompt" string is used to ask the user to enter the relevant
+details. If the user enters nothing then the default value is used if no
+default value is present then the field is omitted. A field can
+still be omitted if a default value is present if the user just
+enters the '.' character.
+
+The number of characters entered must be between the fieldName_min and
+fieldName_max limits: there may be additional restrictions based
+on the field being used (for example countryName can only ever be
+two characters long and must fit in a PrintableString).
+
+Some fields (such as organizationName) can be used more than once
+in a DN. This presents a problem because configuration files will
+not recognize the same name occurring twice. To avoid this problem
+if the fieldName contains some characters followed by a full stop
+they will be ignored. So for example a second organizationName can
+be input by calling it "1.organizationName".
+
+The actual permitted field names are any object identifier short or
+long names. These are compiled into OpenSSL and include the usual
+values such as commonName, countryName, localityName, organizationName,
+organizationUnitName, stateOrProvinceName. Additionally emailAddress
+is include as well as name, surname, givenName initials and dnQualifier.
+
+Additional object identifiers can be defined with the B<oid_file> or
+B<oid_section> options in the configuration file. Any additional fields
+will be treated as though they were a DirectoryString.
+
+
+=head1 EXAMPLES
+
+Examine and verify certificate request:
+
+ openssl req -in req.pem -text -verify -noout
+
+Create a private key and then generate a certificate request from it:
+
+ openssl genrsa -out key.pem 1024
+ openssl req -new -key key.pem -out req.pem
+
+The same but just using req:
+
+ openssl req -newkey rsa:1024 -keyout key.pem -out req.pem
+
+Generate a self signed root certificate:
+
+ openssl req -x509 -newkey rsa:1024 -keyout key.pem -out req.pem
+
+Example of a file pointed to by the B<oid_file> option:
+
+ 1.2.3.4       shortName       A longer Name
+ 1.2.3.6       otherName       Other longer Name
+
+Example of a section pointed to by B<oid_section> making use of variable
+expansion:
+
+ testoid1=1.2.3.5
+ testoid2=${testoid1}.6
+
+Sample configuration file prompting for field values:
+
+ [ req ]
+ default_bits          = 1024
+ default_keyfile       = privkey.pem
+ distinguished_name    = req_distinguished_name
+ attributes            = req_attributes
+ x509_extensions       = v3_ca
+
+ dirstring_type = nobmp
+
+ [ req_distinguished_name ]
+ countryName                   = Country Name (2 letter code)
+ countryName_default           = AU
+ countryName_min               = 2
+ countryName_max               = 2
+
+ localityName                  = Locality Name (eg, city)
+
+ organizationalUnitName                = Organizational Unit Name (eg, section)
+
+ commonName                    = Common Name (eg, YOUR name)
+ commonName_max                        = 64
+
+ emailAddress                  = Email Address
+ emailAddress_max              = 40
+
+ [ req_attributes ]
+ challengePassword             = A challenge password
+ challengePassword_min         = 4
+ challengePassword_max         = 20
+
+ [ v3_ca ]
+
+ subjectKeyIdentifier=hash
+ authorityKeyIdentifier=keyid:always,issuer:always
+ basicConstraints = CA:true
+
+Sample configuration containing all field values:
+
+
+ RANDFILE              = $ENV::HOME/.rnd
+
+ [ req ]
+ default_bits          = 1024
+ default_keyfile       = keyfile.pem
+ distinguished_name    = req_distinguished_name
+ attributes            = req_attributes
+ prompt                        = no
+ output_password       = mypass
+
+ [ req_distinguished_name ]
+ C                     = GB
+ ST                    = Test State or Province
+ L                     = Test Locality
+ O                     = Organization Name
+ OU                    = Organizational Unit Name
+ CN                    = Common Name
+ emailAddress          = test@email.address
+
+ [ req_attributes ]
+ challengePassword             = A challenge password
+
+
+=head1 NOTES
+
+The header and footer lines in the B<PEM> format are normally:
+
+ -----BEGIN CERTIFICATE REQUEST-----
+ -----END CERTIFICATE REQUEST-----
+
+some software (some versions of Netscape certificate server) instead needs:
+
+ -----BEGIN NEW CERTIFICATE REQUEST-----
+ -----END NEW CERTIFICATE REQUEST-----
+
+which is produced with the B<-newhdr> option but is otherwise compatible.
+Either form is accepted transparently on input.
+
+The certificate requests generated by B<Xenroll> with MSIE have extensions
+added. It includes the B<keyUsage> extension which determines the type of
+key (signature only or general purpose) and any additional OIDs entered
+by the script in an extendedKeyUsage extension.
+
+=head1 DIAGNOSTICS
+
+The following messages are frequently asked about:
+
+       Using configuration from /some/path/openssl.cnf
+       Unable to load config info
+
+This is followed some time later by...
+
+       unable to find 'distinguished_name' in config
+       problems making Certificate Request
+
+The first error message is the clue: it can't find the configuration
+file! Certain operations (like examining a certificate request) don't
+need a configuration file so its use isn't enforced. Generation of
+certificates or requests however does need a configuration file. This
+could be regarded as a bug.
+
+Another puzzling message is this:
+
+        Attributes:
+            a0:00
+
+this is displayed when no attributes are present and the request includes
+the correct empty B<SET OF> structure (the DER encoding of which is 0xa0
+0x00). If you just see:
+
+        Attributes:
+
+then the B<SET OF> is missing and the encoding is technically invalid (but
+it is tolerated). See the description of the command line option B<-asn1-kludge>
+for more information.
+
+=head1 ENVIRONMENT VARIABLES
+
+The variable B<OPENSSL_CONF> if defined allows an alternative configuration
+file location to be specified, it will be overridden by the B<-config> command
+line switch if it is present. For compatibility reasons the B<SSLEAY_CONF>
+environment variable serves the same purpose but its use is discouraged.
+
+=head1 BUGS
+
+OpenSSL's handling of T61Strings (aka TeletexStrings) is broken: it effectively
+treats them as ISO-8859-1 (Latin 1), Netscape and MSIE have similar behaviour.
+This can cause problems if you need characters that aren't available in
+PrintableStrings and you don't want to or can't use BMPStrings.
+
+As a consequence of the T61String handling the only correct way to represent
+accented characters in OpenSSL is to use a BMPString: unfortunately Netscape
+currently chokes on these. If you have to use accented characters with Netscape
+and MSIE then you currently need to use the invalid T61String form.
+
+The current prompting is not very friendly. It doesn't allow you to confirm what
+you've just entered. Other things like extensions in certificate requests are
+statically defined in the configuration file. Some of these: like an email
+address in subjectAltName should be input by the user.
+
+=head1 SEE ALSO
+
+L<x509(1)|x509(1)>, L<ca(1)|ca(1)>, L<genrsa(1)|genrsa(1)>,
+L<gendsa(1)|gendsa(1)>, L<config(5)|config(5)>,
+L<x509v3_config(5)|x509v3_config(5)> 
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/rsa.pod b/deps/openssl/openssl/doc/apps/rsa.pod
new file mode 100644 (file)
index 0000000..69b2bef
--- /dev/null
@@ -0,0 +1,189 @@
+
+=pod
+
+=head1 NAME
+
+rsa - RSA key processing tool
+
+=head1 SYNOPSIS
+
+B<openssl> B<rsa>
+[B<-inform PEM|NET|DER>]
+[B<-outform PEM|NET|DER>]
+[B<-in filename>]
+[B<-passin arg>]
+[B<-out filename>]
+[B<-passout arg>]
+[B<-sgckey>]
+[B<-des>]
+[B<-des3>]
+[B<-idea>]
+[B<-text>]
+[B<-noout>]
+[B<-modulus>]
+[B<-check>]
+[B<-pubin>]
+[B<-pubout>]
+[B<-engine id>]
+
+=head1 DESCRIPTION
+
+The B<rsa> command processes RSA keys. They can be converted between various
+forms and their components printed out. B<Note> this command uses the
+traditional SSLeay compatible format for private key encryption: newer
+applications should use the more secure PKCS#8 format using the B<pkcs8>
+utility.
+
+=head1 COMMAND OPTIONS
+
+=over 4
+
+=item B<-inform DER|NET|PEM>
+
+This specifies the input format. The B<DER> option uses an ASN1 DER encoded
+form compatible with the PKCS#1 RSAPrivateKey or SubjectPublicKeyInfo format.
+The B<PEM> form is the default format: it consists of the B<DER> format base64
+encoded with additional header and footer lines. On input PKCS#8 format private
+keys are also accepted. The B<NET> form is a format is described in the B<NOTES>
+section.
+
+=item B<-outform DER|NET|PEM>
+
+This specifies the output format, the options have the same meaning as the 
+B<-inform> option.
+
+=item B<-in filename>
+
+This specifies the input filename to read a key from or standard input if this
+option is not specified. If the key is encrypted a pass phrase will be
+prompted for.
+
+=item B<-passin arg>
+
+the input file password source. For more information about the format of B<arg>
+see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
+
+=item B<-out filename>
+
+This specifies the output filename to write a key to or standard output if this
+option is not specified. If any encryption options are set then a pass phrase
+will be prompted for. The output filename should B<not> be the same as the input
+filename.
+
+=item B<-passout password>
+
+the output file password source. For more information about the format of B<arg>
+see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
+
+=item B<-sgckey>
+
+use the modified NET algorithm used with some versions of Microsoft IIS and SGC
+keys.
+
+=item B<-des|-des3|-idea>
+
+These options encrypt the private key with the DES, triple DES, or the 
+IDEA ciphers respectively before outputting it. A pass phrase is prompted for.
+If none of these options is specified the key is written in plain text. This
+means that using the B<rsa> utility to read in an encrypted key with no
+encryption option can be used to remove the pass phrase from a key, or by
+setting the encryption options it can be use to add or change the pass phrase.
+These options can only be used with PEM format output files.
+
+=item B<-text>
+
+prints out the various public or private key components in
+plain text in addition to the encoded version. 
+
+=item B<-noout>
+
+this option prevents output of the encoded version of the key.
+
+=item B<-modulus>
+
+this option prints out the value of the modulus of the key.
+
+=item B<-check>
+
+this option checks the consistency of an RSA private key.
+
+=item B<-pubin>
+
+by default a private key is read from the input file: with this
+option a public key is read instead.
+
+=item B<-pubout>
+
+by default a private key is output: with this option a public
+key will be output instead. This option is automatically set if
+the input is a public key.
+
+=item B<-engine id>
+
+specifying an engine (by its unique B<id> string) will cause B<rsa>
+to attempt to obtain a functional reference to the specified engine,
+thus initialising it if needed. The engine will then be set as the default
+for all available algorithms.
+
+=back
+
+=head1 NOTES
+
+The PEM private key format uses the header and footer lines:
+
+ -----BEGIN RSA PRIVATE KEY-----
+ -----END RSA PRIVATE KEY-----
+
+The PEM public key format uses the header and footer lines:
+
+ -----BEGIN PUBLIC KEY-----
+ -----END PUBLIC KEY-----
+
+The B<NET> form is a format compatible with older Netscape servers
+and Microsoft IIS .key files, this uses unsalted RC4 for its encryption.
+It is not very secure and so should only be used when necessary.
+
+Some newer version of IIS have additional data in the exported .key
+files. To use these with the utility, view the file with a binary editor
+and look for the string "private-key", then trace back to the byte
+sequence 0x30, 0x82 (this is an ASN1 SEQUENCE). Copy all the data
+from this point onwards to another file and use that as the input
+to the B<rsa> utility with the B<-inform NET> option. If you get
+an error after entering the password try the B<-sgckey> option.
+
+=head1 EXAMPLES
+
+To remove the pass phrase on an RSA private key:
+
+ openssl rsa -in key.pem -out keyout.pem
+
+To encrypt a private key using triple DES:
+
+ openssl rsa -in key.pem -des3 -out keyout.pem
+
+To convert a private key from PEM to DER format: 
+
+ openssl rsa -in key.pem -outform DER -out keyout.der
+
+To print out the components of a private key to standard output:
+
+ openssl rsa -in key.pem -text -noout
+
+To just output the public part of a private key:
+
+ openssl rsa -in key.pem -pubout -out pubkey.pem
+
+=head1 BUGS
+
+The command line password arguments don't currently work with
+B<NET> format.
+
+There should be an option that automatically handles .key files,
+without having to manually edit them.
+
+=head1 SEE ALSO
+
+L<pkcs8(1)|pkcs8(1)>, L<dsa(1)|dsa(1)>, L<genrsa(1)|genrsa(1)>,
+L<gendsa(1)|gendsa(1)> 
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/rsautl.pod b/deps/openssl/openssl/doc/apps/rsautl.pod
new file mode 100644 (file)
index 0000000..1a498c2
--- /dev/null
@@ -0,0 +1,183 @@
+=pod
+
+=head1 NAME
+
+rsautl - RSA utility
+
+=head1 SYNOPSIS
+
+B<openssl> B<rsautl>
+[B<-in file>]
+[B<-out file>]
+[B<-inkey file>]
+[B<-pubin>]
+[B<-certin>]
+[B<-sign>]
+[B<-verify>]
+[B<-encrypt>]
+[B<-decrypt>]
+[B<-pkcs>]
+[B<-ssl>]
+[B<-raw>]
+[B<-hexdump>]
+[B<-asn1parse>]
+
+=head1 DESCRIPTION
+
+The B<rsautl> command can be used to sign, verify, encrypt and decrypt
+data using the RSA algorithm.
+
+=head1 COMMAND OPTIONS
+
+=over 4
+
+=item B<-in filename>
+
+This specifies the input filename to read data from or standard input
+if this option is not specified.
+
+=item B<-out filename>
+
+specifies the output filename to write to or standard output by
+default.
+
+=item B<-inkey file>
+
+the input key file, by default it should be an RSA private key.
+
+=item B<-pubin>
+
+the input file is an RSA public key. 
+
+=item B<-certin>
+
+the input is a certificate containing an RSA public key. 
+
+=item B<-sign>
+
+sign the input data and output the signed result. This requires
+and RSA private key.
+
+=item B<-verify>
+
+verify the input data and output the recovered data.
+
+=item B<-encrypt>
+
+encrypt the input data using an RSA public key.
+
+=item B<-decrypt>
+
+decrypt the input data using an RSA private key.
+
+=item B<-pkcs, -oaep, -ssl, -raw>
+
+the padding to use: PKCS#1 v1.5 (the default), PKCS#1 OAEP,
+special padding used in SSL v2 backwards compatible handshakes,
+or no padding, respectively.
+For signatures, only B<-pkcs> and B<-raw> can be used.
+
+=item B<-hexdump>
+
+hex dump the output data.
+
+=item B<-asn1parse>
+
+asn1parse the output data, this is useful when combined with the
+B<-verify> option.
+
+=back
+
+=head1 NOTES
+
+B<rsautl> because it uses the RSA algorithm directly can only be
+used to sign or verify small pieces of data.
+
+=head1 EXAMPLES
+
+Sign some data using a private key:
+
+ openssl rsautl -sign -in file -inkey key.pem -out sig
+
+Recover the signed data
+
+ openssl rsautl -verify -in sig -inkey key.pem
+
+Examine the raw signed data:
+
+ openssl rsautl -verify -in file -inkey key.pem -raw -hexdump
+
+ 0000 - 00 01 ff ff ff ff ff ff-ff ff ff ff ff ff ff ff   ................
+ 0010 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff   ................
+ 0020 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff   ................
+ 0030 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff   ................
+ 0040 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff   ................
+ 0050 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff   ................
+ 0060 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff   ................
+ 0070 - ff ff ff ff 00 68 65 6c-6c 6f 20 77 6f 72 6c 64   .....hello world
+
+The PKCS#1 block formatting is evident from this. If this was done using
+encrypt and decrypt the block would have been of type 2 (the second byte)
+and random padding data visible instead of the 0xff bytes.
+
+It is possible to analyse the signature of certificates using this
+utility in conjunction with B<asn1parse>. Consider the self signed
+example in certs/pca-cert.pem . Running B<asn1parse> as follows yields:
+
+ openssl asn1parse -in pca-cert.pem
+
+    0:d=0  hl=4 l= 742 cons: SEQUENCE          
+    4:d=1  hl=4 l= 591 cons:  SEQUENCE          
+    8:d=2  hl=2 l=   3 cons:   cont [ 0 ]        
+   10:d=3  hl=2 l=   1 prim:    INTEGER           :02
+   13:d=2  hl=2 l=   1 prim:   INTEGER           :00
+   16:d=2  hl=2 l=  13 cons:   SEQUENCE          
+   18:d=3  hl=2 l=   9 prim:    OBJECT            :md5WithRSAEncryption
+   29:d=3  hl=2 l=   0 prim:    NULL              
+   31:d=2  hl=2 l=  92 cons:   SEQUENCE          
+   33:d=3  hl=2 l=  11 cons:    SET               
+   35:d=4  hl=2 l=   9 cons:     SEQUENCE          
+   37:d=5  hl=2 l=   3 prim:      OBJECT            :countryName
+   42:d=5  hl=2 l=   2 prim:      PRINTABLESTRING   :AU
+  ....
+  599:d=1  hl=2 l=  13 cons:  SEQUENCE          
+  601:d=2  hl=2 l=   9 prim:   OBJECT            :md5WithRSAEncryption
+  612:d=2  hl=2 l=   0 prim:   NULL              
+  614:d=1  hl=3 l= 129 prim:  BIT STRING        
+
+
+The final BIT STRING contains the actual signature. It can be extracted with:
+
+ openssl asn1parse -in pca-cert.pem -out sig -noout -strparse 614
+
+The certificate public key can be extracted with:
+ openssl x509 -in test/testx509.pem -pubkey -noout >pubkey.pem
+
+The signature can be analysed with:
+
+ openssl rsautl -in sig -verify -asn1parse -inkey pubkey.pem -pubin
+
+    0:d=0  hl=2 l=  32 cons: SEQUENCE          
+    2:d=1  hl=2 l=  12 cons:  SEQUENCE          
+    4:d=2  hl=2 l=   8 prim:   OBJECT            :md5
+   14:d=2  hl=2 l=   0 prim:   NULL              
+   16:d=1  hl=2 l=  16 prim:  OCTET STRING      
+      0000 - f3 46 9e aa 1a 4a 73 c9-37 ea 93 00 48 25 08 b5   .F...Js.7...H%..
+
+This is the parsed version of an ASN1 DigestInfo structure. It can be seen that
+the digest used was md5. The actual part of the certificate that was signed can
+be extracted with:
+
+ openssl asn1parse -in pca-cert.pem -out tbs -noout -strparse 4
+
+and its digest computed with:
+
+ openssl md5 -c tbs
+ MD5(tbs)= f3:46:9e:aa:1a:4a:73:c9:37:ea:93:00:48:25:08:b5
+
+which it can be seen agrees with the recovered value above.
+
+=head1 SEE ALSO
+
+L<dgst(1)|dgst(1)>, L<rsa(1)|rsa(1)>, L<genrsa(1)|genrsa(1)>
diff --git a/deps/openssl/openssl/doc/apps/s_client.pod b/deps/openssl/openssl/doc/apps/s_client.pod
new file mode 100644 (file)
index 0000000..4ebf7b5
--- /dev/null
@@ -0,0 +1,306 @@
+
+=pod
+
+=head1 NAME
+
+s_client - SSL/TLS client program
+
+=head1 SYNOPSIS
+
+B<openssl> B<s_client>
+[B<-connect host:port>]
+[B<-verify depth>]
+[B<-cert filename>]
+[B<-certform DER|PEM>]
+[B<-key filename>]
+[B<-keyform DER|PEM>]
+[B<-pass arg>]
+[B<-CApath directory>]
+[B<-CAfile filename>]
+[B<-reconnect>]
+[B<-pause>]
+[B<-showcerts>]
+[B<-debug>]
+[B<-msg>]
+[B<-nbio_test>]
+[B<-state>]
+[B<-nbio>]
+[B<-crlf>]
+[B<-ign_eof>]
+[B<-quiet>]
+[B<-ssl2>]
+[B<-ssl3>]
+[B<-tls1>]
+[B<-no_ssl2>]
+[B<-no_ssl3>]
+[B<-no_tls1>]
+[B<-bugs>]
+[B<-cipher cipherlist>]
+[B<-starttls protocol>]
+[B<-engine id>]
+[B<-tlsextdebug>]
+[B<-no_ticket>]
+[B<-sess_out filename>]
+[B<-sess_in filename>]
+[B<-rand file(s)>]
+
+=head1 DESCRIPTION
+
+The B<s_client> command implements a generic SSL/TLS client which connects
+to a remote host using SSL/TLS. It is a I<very> useful diagnostic tool for
+SSL servers.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-connect host:port>
+
+This specifies the host and optional port to connect to. If not specified
+then an attempt is made to connect to the local host on port 4433.
+
+=item B<-cert certname>
+
+The certificate to use, if one is requested by the server. The default is
+not to use a certificate.
+
+=item B<-certform format>
+
+The certificate format to use: DER or PEM. PEM is the default.
+
+=item B<-key keyfile>
+
+The private key to use. If not specified then the certificate file will
+be used.
+
+=item B<-keyform format>
+
+The private format to use: DER or PEM. PEM is the default.
+
+=item B<-pass arg>
+
+the private key password source. For more information about the format of B<arg>
+see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
+
+=item B<-verify depth>
+
+The verify depth to use. This specifies the maximum length of the
+server certificate chain and turns on server certificate verification.
+Currently the verify operation continues after errors so all the problems
+with a certificate chain can be seen. As a side effect the connection
+will never fail due to a server certificate verify failure.
+
+=item B<-CApath directory>
+
+The directory to use for server certificate verification. This directory
+must be in "hash format", see B<verify> for more information. These are
+also used when building the client certificate chain.
+
+=item B<-CAfile file>
+
+A file containing trusted certificates to use during server authentication
+and to use when attempting to build the client certificate chain.
+
+=item B<-purpose, -ignore_critical, -issuer_checks, -crl_check, -crl_check_all, -policy_check, -extended_crl, -x509_strict, -policy -check_ss_sig>
+
+Set various certificate chain valiadition option. See the
+L<B<verify>|verify(1)> manual page for details.
+
+=item B<-reconnect>
+
+reconnects to the same server 5 times using the same session ID, this can
+be used as a test that session caching is working.
+
+=item B<-pause>
+
+pauses 1 second between each read and write call.
+
+=item B<-showcerts>
+
+display the whole server certificate chain: normally only the server
+certificate itself is displayed.
+
+=item B<-prexit>
+
+print session information when the program exits. This will always attempt
+to print out information even if the connection fails. Normally information
+will only be printed out once if the connection succeeds. This option is useful
+because the cipher in use may be renegotiated or the connection may fail
+because a client certificate is required or is requested only after an
+attempt is made to access a certain URL. Note: the output produced by this
+option is not always accurate because a connection might never have been
+established.
+
+=item B<-state>
+
+prints out the SSL session states.
+
+=item B<-debug>
+
+print extensive debugging information including a hex dump of all traffic.
+
+=item B<-msg>
+
+show all protocol messages with hex dump.
+
+=item B<-nbio_test>
+
+tests non-blocking I/O
+
+=item B<-nbio>
+
+turns on non-blocking I/O
+
+=item B<-crlf>
+
+this option translated a line feed from the terminal into CR+LF as required
+by some servers.
+
+=item B<-ign_eof>
+
+inhibit shutting down the connection when end of file is reached in the
+input.
+
+=item B<-quiet>
+
+inhibit printing of session and certificate information.  This implicitly
+turns on B<-ign_eof> as well.
+
+=item B<-psk_identity identity>
+
+Use the PSK identity B<identity> when using a PSK cipher suite.
+
+=item B<-psk key>
+
+Use the PSK key B<key> when using a PSK cipher suite. The key is
+given as a hexadecimal number without leading 0x, for example -psk
+1a2b3c4d.
+
+=item B<-ssl2>, B<-ssl3>, B<-tls1>, B<-no_ssl2>, B<-no_ssl3>, B<-no_tls1>
+
+these options disable the use of certain SSL or TLS protocols. By default
+the initial handshake uses a method which should be compatible with all
+servers and permit them to use SSL v3, SSL v2 or TLS as appropriate.
+
+Unfortunately there are a lot of ancient and broken servers in use which
+cannot handle this technique and will fail to connect. Some servers only
+work if TLS is turned off with the B<-no_tls> option others will only
+support SSL v2 and may need the B<-ssl2> option.
+
+=item B<-bugs>
+
+there are several known bug in SSL and TLS implementations. Adding this
+option enables various workarounds.
+
+=item B<-cipher cipherlist>
+
+this allows the cipher list sent by the client to be modified. Although
+the server determines which cipher suite is used it should take the first
+supported cipher in the list sent by the client. See the B<ciphers>
+command for more information.
+
+=item B<-starttls protocol>
+
+send the protocol-specific message(s) to switch to TLS for communication.
+B<protocol> is a keyword for the intended protocol.  Currently, the only
+supported keywords are "smtp", "pop3", "imap", and "ftp".
+
+=item B<-tlsextdebug>
+
+print out a hex dump of any TLS extensions received from the server.
+
+=item B<-no_ticket>
+
+disable RFC4507bis session ticket support. 
+
+=item B<-sess_out filename>
+
+output SSL session to B<filename>
+
+=item B<-sess_in sess.pem>
+
+load SSL session from B<filename>. The client will attempt to resume a
+connection from this session.
+
+=item B<-engine id>
+
+specifying an engine (by its unique B<id> string) will cause B<s_client>
+to attempt to obtain a functional reference to the specified engine,
+thus initialising it if needed. The engine will then be set as the default
+for all available algorithms.
+
+=item B<-rand file(s)>
+
+a file or files containing random data used to seed the random number
+generator, or an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
+Multiple files can be specified separated by a OS-dependent character.
+The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
+all others.
+
+=back
+
+=head1 CONNECTED COMMANDS
+
+If a connection is established with an SSL server then any data received
+from the server is displayed and any key presses will be sent to the
+server. When used interactively (which means neither B<-quiet> nor B<-ign_eof>
+have been given), the session will be renegotiated if the line begins with an
+B<R>, and if the line begins with a B<Q> or if end of file is reached, the
+connection will be closed down.
+
+=head1 NOTES
+
+B<s_client> can be used to debug SSL servers. To connect to an SSL HTTP
+server the command:
+
+ openssl s_client -connect servername:443
+
+would typically be used (https uses port 443). If the connection succeeds
+then an HTTP command can be given such as "GET /" to retrieve a web page.
+
+If the handshake fails then there are several possible causes, if it is
+nothing obvious like no client certificate then the B<-bugs>, B<-ssl2>,
+B<-ssl3>, B<-tls1>, B<-no_ssl2>, B<-no_ssl3>, B<-no_tls1> options can be tried
+in case it is a buggy server. In particular you should play with these
+options B<before> submitting a bug report to an OpenSSL mailing list.
+
+A frequent problem when attempting to get client certificates working
+is that a web client complains it has no certificates or gives an empty
+list to choose from. This is normally because the server is not sending
+the clients certificate authority in its "acceptable CA list" when it
+requests a certificate. By using B<s_client> the CA list can be viewed
+and checked. However some servers only request client authentication
+after a specific URL is requested. To obtain the list in this case it
+is necessary to use the B<-prexit> option and send an HTTP request
+for an appropriate page.
+
+If a certificate is specified on the command line using the B<-cert>
+option it will not be used unless the server specifically requests
+a client certificate. Therefor merely including a client certificate
+on the command line is no guarantee that the certificate works.
+
+If there are problems verifying a server certificate then the
+B<-showcerts> option can be used to show the whole chain.
+
+Since the SSLv23 client hello cannot include compression methods or extensions
+these will only be supported if its use is disabled, for example by using the
+B<-no_sslv2> option.
+
+=head1 BUGS
+
+Because this program has a lot of options and also because some of
+the techniques used are rather old, the C source of s_client is rather
+hard to read and not a model of how things should be done. A typical
+SSL client program would be much simpler.
+
+The B<-verify> option should really exit if the server verification
+fails.
+
+The B<-prexit> option is a bit of a hack. We should really report
+information whenever a session is renegotiated.
+
+=head1 SEE ALSO
+
+L<sess_id(1)|sess_id(1)>, L<s_server(1)|s_server(1)>, L<ciphers(1)|ciphers(1)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/s_server.pod b/deps/openssl/openssl/doc/apps/s_server.pod
new file mode 100644 (file)
index 0000000..3e503e1
--- /dev/null
@@ -0,0 +1,355 @@
+
+=pod
+
+=head1 NAME
+
+s_server - SSL/TLS server program
+
+=head1 SYNOPSIS
+
+B<openssl> B<s_server>
+[B<-accept port>]
+[B<-context id>]
+[B<-verify depth>]
+[B<-Verify depth>]
+[B<-crl_check>]
+[B<-crl_check_all>]
+[B<-cert filename>]
+[B<-certform DER|PEM>]
+[B<-key keyfile>]
+[B<-keyform DER|PEM>]
+[B<-pass arg>]
+[B<-dcert filename>]
+[B<-dcertform DER|PEM>]
+[B<-dkey keyfile>]
+[B<-dkeyform DER|PEM>]
+[B<-dpass arg>]
+[B<-dhparam filename>]
+[B<-nbio>]
+[B<-nbio_test>]
+[B<-crlf>]
+[B<-debug>]
+[B<-msg>]
+[B<-state>]
+[B<-CApath directory>]
+[B<-CAfile filename>]
+[B<-nocert>]
+[B<-cipher cipherlist>]
+[B<-quiet>]
+[B<-no_tmp_rsa>]
+[B<-ssl2>]
+[B<-ssl3>]
+[B<-tls1>]
+[B<-no_ssl2>]
+[B<-no_ssl3>]
+[B<-no_tls1>]
+[B<-no_dhe>]
+[B<-bugs>]
+[B<-hack>]
+[B<-www>]
+[B<-WWW>]
+[B<-HTTP>]
+[B<-engine id>]
+[B<-tlsextdebug>]
+[B<-no_ticket>]
+[B<-id_prefix arg>]
+[B<-rand file(s)>]
+
+=head1 DESCRIPTION
+
+The B<s_server> command implements a generic SSL/TLS server which listens
+for connections on a given port using SSL/TLS.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-accept port>
+
+the TCP port to listen on for connections. If not specified 4433 is used.
+
+=item B<-context id>
+
+sets the SSL context id. It can be given any string value. If this option
+is not present a default value will be used.
+
+=item B<-cert certname>
+
+The certificate to use, most servers cipher suites require the use of a
+certificate and some require a certificate with a certain public key type:
+for example the DSS cipher suites require a certificate containing a DSS
+(DSA) key. If not specified then the filename "server.pem" will be used.
+
+=item B<-certform format>
+
+The certificate format to use: DER or PEM. PEM is the default.
+
+=item B<-key keyfile>
+
+The private key to use. If not specified then the certificate file will
+be used.
+
+=item B<-keyform format>
+
+The private format to use: DER or PEM. PEM is the default.
+
+=item B<-pass arg>
+
+the private key password source. For more information about the format of B<arg>
+see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
+
+=item B<-dcert filename>, B<-dkey keyname>
+
+specify an additional certificate and private key, these behave in the
+same manner as the B<-cert> and B<-key> options except there is no default
+if they are not specified (no additional certificate and key is used). As
+noted above some cipher suites require a certificate containing a key of
+a certain type. Some cipher suites need a certificate carrying an RSA key
+and some a DSS (DSA) key. By using RSA and DSS certificates and keys
+a server can support clients which only support RSA or DSS cipher suites
+by using an appropriate certificate.
+
+=item B<-dcertform format>, B<-dkeyform format>, B<-dpass arg>
+
+addtional certificate and private key format and passphrase respectively.
+
+=item B<-nocert>
+
+if this option is set then no certificate is used. This restricts the
+cipher suites available to the anonymous ones (currently just anonymous
+DH).
+
+=item B<-dhparam filename>
+
+the DH parameter file to use. The ephemeral DH cipher suites generate keys
+using a set of DH parameters. If not specified then an attempt is made to
+load the parameters from the server certificate file. If this fails then
+a static set of parameters hard coded into the s_server program will be used.
+
+=item B<-no_dhe>
+
+if this option is set then no DH parameters will be loaded effectively
+disabling the ephemeral DH cipher suites.
+
+=item B<-no_tmp_rsa>
+
+certain export cipher suites sometimes use a temporary RSA key, this option
+disables temporary RSA key generation.
+
+=item B<-verify depth>, B<-Verify depth>
+
+The verify depth to use. This specifies the maximum length of the
+client certificate chain and makes the server request a certificate from
+the client. With the B<-verify> option a certificate is requested but the
+client does not have to send one, with the B<-Verify> option the client
+must supply a certificate or an error occurs.
+
+=item B<-crl_check>, B<-crl_check_all>
+
+Check the peer certificate has not been revoked by its CA.
+The CRL(s) are appended to the certificate file. With the B<-crl_check_all>
+option all CRLs of all CAs in the chain are checked.
+
+=item B<-CApath directory>
+
+The directory to use for client certificate verification. This directory
+must be in "hash format", see B<verify> for more information. These are
+also used when building the server certificate chain.
+
+=item B<-CAfile file>
+
+A file containing trusted certificates to use during client authentication
+and to use when attempting to build the server certificate chain. The list
+is also used in the list of acceptable client CAs passed to the client when
+a certificate is requested.
+
+=item B<-state>
+
+prints out the SSL session states.
+
+=item B<-debug>
+
+print extensive debugging information including a hex dump of all traffic.
+
+=item B<-msg>
+
+show all protocol messages with hex dump.
+
+=item B<-nbio_test>
+
+tests non blocking I/O
+
+=item B<-nbio>
+
+turns on non blocking I/O
+
+=item B<-crlf>
+
+this option translated a line feed from the terminal into CR+LF.
+
+=item B<-quiet>
+
+inhibit printing of session and certificate information.
+
+=item B<-psk_hint hint>
+
+Use the PSK identity hint B<hint> when using a PSK cipher suite.
+
+=item B<-psk key>
+
+Use the PSK key B<key> when using a PSK cipher suite. The key is
+given as a hexadecimal number without leading 0x, for example -psk
+1a2b3c4d.
+
+=item B<-ssl2>, B<-ssl3>, B<-tls1>, B<-no_ssl2>, B<-no_ssl3>, B<-no_tls1>
+
+these options disable the use of certain SSL or TLS protocols. By default
+the initial handshake uses a method which should be compatible with all
+servers and permit them to use SSL v3, SSL v2 or TLS as appropriate.
+
+=item B<-bugs>
+
+there are several known bug in SSL and TLS implementations. Adding this
+option enables various workarounds.
+
+=item B<-hack>
+
+this option enables a further workaround for some some early Netscape
+SSL code (?).
+
+=item B<-cipher cipherlist>
+
+this allows the cipher list used by the server to be modified.  When
+the client sends a list of supported ciphers the first client cipher
+also included in the server list is used. Because the client specifies
+the preference order, the order of the server cipherlist irrelevant. See
+the B<ciphers> command for more information.
+
+=item B<-tlsextdebug>
+
+print out a hex dump of any TLS extensions received from the server.
+
+=item B<-no_ticket>
+
+disable RFC4507bis session ticket support. 
+
+=item B<-www>
+
+sends a status message back to the client when it connects. This includes
+lots of information about the ciphers used and various session parameters.
+The output is in HTML format so this option will normally be used with a
+web browser.
+
+=item B<-WWW>
+
+emulates a simple web server. Pages will be resolved relative to the
+current directory, for example if the URL https://myhost/page.html is
+requested the file ./page.html will be loaded.
+
+=item B<-HTTP>
+
+emulates a simple web server. Pages will be resolved relative to the
+current directory, for example if the URL https://myhost/page.html is
+requested the file ./page.html will be loaded. The files loaded are
+assumed to contain a complete and correct HTTP response (lines that
+are part of the HTTP response line and headers must end with CRLF).
+
+=item B<-engine id>
+
+specifying an engine (by its unique B<id> string) will cause B<s_server>
+to attempt to obtain a functional reference to the specified engine,
+thus initialising it if needed. The engine will then be set as the default
+for all available algorithms.
+
+=item B<-id_prefix arg>
+
+generate SSL/TLS session IDs prefixed by B<arg>. This is mostly useful
+for testing any SSL/TLS code (eg. proxies) that wish to deal with multiple
+servers, when each of which might be generating a unique range of session
+IDs (eg. with a certain prefix).
+
+=item B<-rand file(s)>
+
+a file or files containing random data used to seed the random number
+generator, or an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
+Multiple files can be specified separated by a OS-dependent character.
+The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
+all others.
+
+=back
+
+=head1 CONNECTED COMMANDS
+
+If a connection request is established with an SSL client and neither the
+B<-www> nor the B<-WWW> option has been used then normally any data received
+from the client is displayed and any key presses will be sent to the client. 
+
+Certain single letter commands are also recognized which perform special
+operations: these are listed below.
+
+=over 4
+
+=item B<q>
+
+end the current SSL connection but still accept new connections.
+
+=item B<Q>
+
+end the current SSL connection and exit.
+
+=item B<r>
+
+renegotiate the SSL session.
+
+=item B<R>
+
+renegotiate the SSL session and request a client certificate.
+
+=item B<P>
+
+send some plain text down the underlying TCP connection: this should
+cause the client to disconnect due to a protocol violation.
+
+=item B<S>
+
+print out some session cache status information.
+
+=back
+
+=head1 NOTES
+
+B<s_server> can be used to debug SSL clients. To accept connections from
+a web browser the command:
+
+ openssl s_server -accept 443 -www
+
+can be used for example.
+
+Most web browsers (in particular Netscape and MSIE) only support RSA cipher
+suites, so they cannot connect to servers which don't use a certificate
+carrying an RSA key or a version of OpenSSL with RSA disabled.
+
+Although specifying an empty list of CAs when requesting a client certificate
+is strictly speaking a protocol violation, some SSL clients interpret this to
+mean any CA is acceptable. This is useful for debugging purposes.
+
+The session parameters can printed out using the B<sess_id> program.
+
+=head1 BUGS
+
+Because this program has a lot of options and also because some of
+the techniques used are rather old, the C source of s_server is rather
+hard to read and not a model of how things should be done. A typical
+SSL server program would be much simpler.
+
+The output of common ciphers is wrong: it just gives the list of ciphers that
+OpenSSL recognizes and the client supports.
+
+There should be a way for the B<s_server> program to print out details of any
+unknown cipher suites a client says it supports.
+
+=head1 SEE ALSO
+
+L<sess_id(1)|sess_id(1)>, L<s_client(1)|s_client(1)>, L<ciphers(1)|ciphers(1)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/s_time.pod b/deps/openssl/openssl/doc/apps/s_time.pod
new file mode 100644 (file)
index 0000000..5a38aa2
--- /dev/null
@@ -0,0 +1,173 @@
+
+=pod
+
+=head1 NAME
+
+s_time - SSL/TLS performance timing program
+
+=head1 SYNOPSIS
+
+B<openssl> B<s_time>
+[B<-connect host:port>]
+[B<-www page>]
+[B<-cert filename>]
+[B<-key filename>]
+[B<-CApath directory>]
+[B<-CAfile filename>]
+[B<-reuse>]
+[B<-new>]
+[B<-verify depth>]
+[B<-nbio>]
+[B<-time seconds>]
+[B<-ssl2>]
+[B<-ssl3>]
+[B<-bugs>]
+[B<-cipher cipherlist>]
+
+=head1 DESCRIPTION
+
+The B<s_client> command implements a generic SSL/TLS client which connects to a
+remote host using SSL/TLS. It can request a page from the server and includes
+the time to transfer the payload data in its timing measurements. It measures
+the number of connections within a given timeframe, the amount of data
+transferred (if any), and calculates the average time spent for one connection.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-connect host:port>
+
+This specifies the host and optional port to connect to.
+
+=item B<-www page>
+
+This specifies the page to GET from the server. A value of '/' gets the
+index.htm[l] page. If this parameter is not specified, then B<s_time> will only
+perform the handshake to establish SSL connections but not transfer any
+payload data.
+
+=item B<-cert certname>
+
+The certificate to use, if one is requested by the server. The default is
+not to use a certificate. The file is in PEM format.
+
+=item B<-key keyfile>
+
+The private key to use. If not specified then the certificate file will
+be used. The file is in PEM format.
+
+=item B<-verify depth>
+
+The verify depth to use. This specifies the maximum length of the
+server certificate chain and turns on server certificate verification.
+Currently the verify operation continues after errors so all the problems
+with a certificate chain can be seen. As a side effect the connection
+will never fail due to a server certificate verify failure.
+
+=item B<-CApath directory>
+
+The directory to use for server certificate verification. This directory
+must be in "hash format", see B<verify> for more information. These are
+also used when building the client certificate chain.
+
+=item B<-CAfile file>
+
+A file containing trusted certificates to use during server authentication
+and to use when attempting to build the client certificate chain.
+
+=item B<-new>
+
+performs the timing test using a new session ID for each connection.
+If neither B<-new> nor B<-reuse> are specified, they are both on by default
+and executed in sequence.
+
+=item B<-reuse>
+
+performs the timing test using the same session ID; this can be used as a test
+that session caching is working. If neither B<-new> nor B<-reuse> are
+specified, they are both on by default and executed in sequence.
+
+=item B<-nbio>
+
+turns on non-blocking I/O.
+
+=item B<-ssl2>, B<-ssl3>
+
+these options disable the use of certain SSL or TLS protocols. By default
+the initial handshake uses a method which should be compatible with all
+servers and permit them to use SSL v3, SSL v2 or TLS as appropriate.
+The timing program is not as rich in options to turn protocols on and off as
+the L<s_client(1)|s_client(1)> program and may not connect to all servers.
+
+Unfortunately there are a lot of ancient and broken servers in use which
+cannot handle this technique and will fail to connect. Some servers only
+work if TLS is turned off with the B<-ssl3> option; others
+will only support SSL v2 and may need the B<-ssl2> option.
+
+=item B<-bugs>
+
+there are several known bug in SSL and TLS implementations. Adding this
+option enables various workarounds.
+
+=item B<-cipher cipherlist>
+
+this allows the cipher list sent by the client to be modified. Although
+the server determines which cipher suite is used it should take the first
+supported cipher in the list sent by the client.
+See the L<ciphers(1)|ciphers(1)> command for more information.
+
+=item B<-time length>
+
+specifies how long (in seconds) B<s_time> should establish connections and
+optionally transfer payload data from a server. Server and client performance
+and the link speed determine how many connections B<s_time> can establish.
+
+=back
+
+=head1 NOTES
+
+B<s_client> can be used to measure the performance of an SSL connection.
+To connect to an SSL HTTP server and get the default page the command
+
+ openssl s_time -connect servername:443 -www / -CApath yourdir -CAfile yourfile.pem -cipher commoncipher [-ssl3]
+
+would typically be used (https uses port 443). 'commoncipher' is a cipher to
+which both client and server can agree, see the L<ciphers(1)|ciphers(1)> command
+for details.
+
+If the handshake fails then there are several possible causes, if it is
+nothing obvious like no client certificate then the B<-bugs>, B<-ssl2>,
+B<-ssl3> options can be tried
+in case it is a buggy server. In particular you should play with these
+options B<before> submitting a bug report to an OpenSSL mailing list.
+
+A frequent problem when attempting to get client certificates working
+is that a web client complains it has no certificates or gives an empty
+list to choose from. This is normally because the server is not sending
+the clients certificate authority in its "acceptable CA list" when it
+requests a certificate. By using L<s_client(1)|s_client(1)> the CA list can be
+viewed and checked. However some servers only request client authentication
+after a specific URL is requested. To obtain the list in this case it
+is necessary to use the B<-prexit> option of L<s_client(1)|s_client(1)> and
+send an HTTP request for an appropriate page.
+
+If a certificate is specified on the command line using the B<-cert>
+option it will not be used unless the server specifically requests
+a client certificate. Therefor merely including a client certificate
+on the command line is no guarantee that the certificate works.
+
+=head1 BUGS
+
+Because this program does not have all the options of the
+L<s_client(1)|s_client(1)> program to turn protocols on and off, you may not be
+able to measure the performance of all protocols with all servers.
+
+The B<-verify> option should really exit if the server verification
+fails.
+
+=head1 SEE ALSO
+
+L<s_client(1)|s_client(1)>, L<s_server(1)|s_server(1)>, L<ciphers(1)|ciphers(1)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/sess_id.pod b/deps/openssl/openssl/doc/apps/sess_id.pod
new file mode 100644 (file)
index 0000000..9988d2c
--- /dev/null
@@ -0,0 +1,151 @@
+
+=pod
+
+=head1 NAME
+
+sess_id - SSL/TLS session handling utility
+
+=head1 SYNOPSIS
+
+B<openssl> B<sess_id>
+[B<-inform PEM|DER>]
+[B<-outform PEM|DER>]
+[B<-in filename>]
+[B<-out filename>]
+[B<-text>]
+[B<-noout>]
+[B<-context ID>]
+
+=head1 DESCRIPTION
+
+The B<sess_id> process the encoded version of the SSL session structure
+and optionally prints out SSL session details (for example the SSL session
+master key) in human readable format. Since this is a diagnostic tool that
+needs some knowledge of the SSL protocol to use properly, most users will
+not need to use it.
+
+=over 4
+
+=item B<-inform DER|PEM>
+
+This specifies the input format. The B<DER> option uses an ASN1 DER encoded
+format containing session details. The precise format can vary from one version
+to the next.  The B<PEM> form is the default format: it consists of the B<DER>
+format base64 encoded with additional header and footer lines.
+
+=item B<-outform DER|PEM>
+
+This specifies the output format, the options have the same meaning as the 
+B<-inform> option.
+
+=item B<-in filename>
+
+This specifies the input filename to read session information from or standard
+input by default.
+
+=item B<-out filename>
+
+This specifies the output filename to write session information to or standard
+output if this option is not specified.
+
+=item B<-text>
+
+prints out the various public or private key components in
+plain text in addition to the encoded version. 
+
+=item B<-cert>
+
+if a certificate is present in the session it will be output using this option,
+if the B<-text> option is also present then it will be printed out in text form.
+
+=item B<-noout>
+
+this option prevents output of the encoded version of the session.
+
+=item B<-context ID>
+
+this option can set the session id so the output session information uses the
+supplied ID. The ID can be any string of characters. This option wont normally
+be used.
+
+=back
+
+=head1 OUTPUT
+
+Typical output:
+
+ SSL-Session:
+     Protocol  : TLSv1
+     Cipher    : 0016
+     Session-ID: 871E62626C554CE95488823752CBD5F3673A3EF3DCE9C67BD916C809914B40ED
+     Session-ID-ctx: 01000000
+     Master-Key: A7CEFC571974BE02CAC305269DC59F76EA9F0B180CB6642697A68251F2D2BB57E51DBBB4C7885573192AE9AEE220FACD
+     Key-Arg   : None
+     Start Time: 948459261
+     Timeout   : 300 (sec)
+     Verify return code 0 (ok)
+
+Theses are described below in more detail.
+
+=over 4
+
+=item B<Protocol>
+
+this is the protocol in use TLSv1, SSLv3 or SSLv2.
+
+=item B<Cipher>
+
+the cipher used this is the actual raw SSL or TLS cipher code, see the SSL
+or TLS specifications for more information.
+
+=item B<Session-ID>
+
+the SSL session ID in hex format.
+
+=item B<Session-ID-ctx>
+
+the session ID context in hex format.
+
+=item B<Master-Key>
+
+this is the SSL session master key.
+
+=item B<Key-Arg>
+
+the key argument, this is only used in SSL v2.
+
+=item B<Start Time>
+
+this is the session start time represented as an integer in standard Unix format.
+
+=item B<Timeout>
+
+the timeout in seconds.
+
+=item B<Verify return code>
+
+this is the return code when an SSL client certificate is verified.
+
+=back
+
+=head1 NOTES
+
+The PEM encoded session format uses the header and footer lines:
+
+ -----BEGIN SSL SESSION PARAMETERS-----
+ -----END SSL SESSION PARAMETERS-----
+
+Since the SSL session output contains the master key it is possible to read the contents
+of an encrypted session using this information. Therefore appropriate security precautions
+should be taken if the information is being output by a "real" application. This is
+however strongly discouraged and should only be used for debugging purposes.
+
+=head1 BUGS
+
+The cipher and start time should be printed out in human readable form.
+
+=head1 SEE ALSO
+
+L<ciphers(1)|ciphers(1)>, L<s_server(1)|s_server(1)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/smime.pod b/deps/openssl/openssl/doc/apps/smime.pod
new file mode 100644 (file)
index 0000000..e4e89af
--- /dev/null
@@ -0,0 +1,445 @@
+=pod
+
+=head1 NAME
+
+smime - S/MIME utility
+
+=head1 SYNOPSIS
+
+B<openssl> B<smime>
+[B<-encrypt>]
+[B<-decrypt>]
+[B<-sign>]
+[B<-resign>]
+[B<-verify>]
+[B<-pk7out>]
+[B<-[cipher]>]
+[B<-in file>]
+[B<-certfile file>]
+[B<-signer file>]
+[B<-recip  file>]
+[B<-inform SMIME|PEM|DER>]
+[B<-passin arg>]
+[B<-inkey file>]
+[B<-out file>]
+[B<-outform SMIME|PEM|DER>]
+[B<-content file>]
+[B<-to addr>]
+[B<-from ad>]
+[B<-subject s>]
+[B<-text>]
+[B<-indef>]
+[B<-noindef>]
+[B<-stream>]
+[B<-rand file(s)>]
+[B<-md digest>]
+[cert.pem]...
+
+=head1 DESCRIPTION
+
+The B<smime> command handles S/MIME mail. It can encrypt, decrypt, sign and
+verify S/MIME messages.
+
+=head1 COMMAND OPTIONS
+
+There are six operation options that set the type of operation to be performed.
+The meaning of the other options varies according to the operation type.
+
+=over 4
+
+=item B<-encrypt>
+
+encrypt mail for the given recipient certificates. Input file is the message
+to be encrypted. The output file is the encrypted mail in MIME format.
+
+=item B<-decrypt>
+
+decrypt mail using the supplied certificate and private key. Expects an
+encrypted mail message in MIME format for the input file. The decrypted mail
+is written to the output file.
+
+=item B<-sign>
+
+sign mail using the supplied certificate and private key. Input file is
+the message to be signed. The signed message in MIME format is written
+to the output file.
+
+=item B<-verify>
+
+verify signed mail. Expects a signed mail message on input and outputs
+the signed data. Both clear text and opaque signing is supported.
+
+=item B<-pk7out>
+
+takes an input message and writes out a PEM encoded PKCS#7 structure.
+
+=item B<-resign>
+
+resign a message: take an existing message and one or more new signers.
+
+=item B<-in filename>
+
+the input message to be encrypted or signed or the MIME message to
+be decrypted or verified.
+
+=item B<-inform SMIME|PEM|DER>
+
+this specifies the input format for the PKCS#7 structure. The default
+is B<SMIME> which reads an S/MIME format message. B<PEM> and B<DER>
+format change this to expect PEM and DER format PKCS#7 structures
+instead. This currently only affects the input format of the PKCS#7
+structure, if no PKCS#7 structure is being input (for example with
+B<-encrypt> or B<-sign>) this option has no effect.
+
+=item B<-out filename>
+
+the message text that has been decrypted or verified or the output MIME
+format message that has been signed or verified.
+
+=item B<-outform SMIME|PEM|DER>
+
+this specifies the output format for the PKCS#7 structure. The default
+is B<SMIME> which write an S/MIME format message. B<PEM> and B<DER>
+format change this to write PEM and DER format PKCS#7 structures
+instead. This currently only affects the output format of the PKCS#7
+structure, if no PKCS#7 structure is being output (for example with
+B<-verify> or B<-decrypt>) this option has no effect.
+
+=item B<-stream -indef -noindef>
+
+the B<-stream> and B<-indef> options are equivalent and enable streaming I/O
+for encoding operations. This permits single pass processing of data without
+the need to hold the entire contents in memory, potentially supporting very
+large files. Streaming is automatically set for S/MIME signing with detached
+data if the output format is B<SMIME> it is currently off by default for all
+other operations.
+
+=item B<-noindef>
+
+disable streaming I/O where it would produce and indefinite length constructed
+encoding. This option currently has no effect. In future streaming will be
+enabled by default on all relevant operations and this option will disable it.
+
+=item B<-content filename>
+
+This specifies a file containing the detached content, this is only
+useful with the B<-verify> command. This is only usable if the PKCS#7
+structure is using the detached signature form where the content is
+not included. This option will override any content if the input format
+is S/MIME and it uses the multipart/signed MIME content type.
+
+=item B<-text>
+
+this option adds plain text (text/plain) MIME headers to the supplied
+message if encrypting or signing. If decrypting or verifying it strips
+off text headers: if the decrypted or verified message is not of MIME 
+type text/plain then an error occurs.
+
+=item B<-CAfile file>
+
+a file containing trusted CA certificates, only used with B<-verify>.
+
+=item B<-CApath dir>
+
+a directory containing trusted CA certificates, only used with
+B<-verify>. This directory must be a standard certificate directory: that
+is a hash of each subject name (using B<x509 -hash>) should be linked
+to each certificate.
+
+=item B<-md digest>
+
+digest algorithm to use when signing or resigning. If not present then the
+default digest algorithm for the signing key will be used (usually SHA1).
+
+=item B<-[cipher]>
+
+the encryption algorithm to use. For example DES  (56 bits) - B<-des>,
+triple DES (168 bits) - B<-des3>,
+EVP_get_cipherbyname() function) can also be used preceded by a dash, for 
+example B<-aes_128_cbc>. See L<B<enc>|enc(1)> for list of ciphers
+supported by your version of OpenSSL.
+
+If not specified 40 bit RC2 is used. Only used with B<-encrypt>.
+
+=item B<-nointern>
+
+when verifying a message normally certificates (if any) included in
+the message are searched for the signing certificate. With this option
+only the certificates specified in the B<-certfile> option are used.
+The supplied certificates can still be used as untrusted CAs however.
+
+=item B<-noverify>
+
+do not verify the signers certificate of a signed message.
+
+=item B<-nochain>
+
+do not do chain verification of signers certificates: that is don't
+use the certificates in the signed message as untrusted CAs.
+
+=item B<-nosigs>
+
+don't try to verify the signatures on the message.
+
+=item B<-nocerts>
+
+when signing a message the signer's certificate is normally included
+with this option it is excluded. This will reduce the size of the
+signed message but the verifier must have a copy of the signers certificate
+available locally (passed using the B<-certfile> option for example).
+
+=item B<-noattr>
+
+normally when a message is signed a set of attributes are included which
+include the signing time and supported symmetric algorithms. With this
+option they are not included.
+
+=item B<-binary>
+
+normally the input message is converted to "canonical" format which is
+effectively using CR and LF as end of line: as required by the S/MIME
+specification. When this option is present no translation occurs. This
+is useful when handling binary data which may not be in MIME format.
+
+=item B<-nodetach>
+
+when signing a message use opaque signing: this form is more resistant
+to translation by mail relays but it cannot be read by mail agents that
+do not support S/MIME.  Without this option cleartext signing with
+the MIME type multipart/signed is used.
+
+=item B<-certfile file>
+
+allows additional certificates to be specified. When signing these will
+be included with the message. When verifying these will be searched for
+the signers certificates. The certificates should be in PEM format.
+
+=item B<-signer file>
+
+a signing certificate when signing or resigning a message, this option can be
+used multiple times if more than one signer is required. If a message is being
+verified then the signers certificates will be written to this file if the
+verification was successful.
+
+=item B<-recip file>
+
+the recipients certificate when decrypting a message. This certificate
+must match one of the recipients of the message or an error occurs.
+
+=item B<-inkey file>
+
+the private key to use when signing or decrypting. This must match the
+corresponding certificate. If this option is not specified then the
+private key must be included in the certificate file specified with
+the B<-recip> or B<-signer> file. When signing this option can be used
+multiple times to specify successive keys.
+
+=item B<-passin arg>
+
+the private key password source. For more information about the format of B<arg>
+see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
+
+=item B<-rand file(s)>
+
+a file or files containing random data used to seed the random number
+generator, or an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
+Multiple files can be specified separated by a OS-dependent character.
+The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
+all others.
+
+=item B<cert.pem...>
+
+one or more certificates of message recipients: used when encrypting
+a message. 
+
+=item B<-to, -from, -subject>
+
+the relevant mail headers. These are included outside the signed
+portion of a message so they may be included manually. If signing
+then many S/MIME mail clients check the signers certificate's email
+address matches that specified in the From: address.
+
+=item B<-purpose, -ignore_critical, -issuer_checks, -crl_check, -crl_check_all, -policy_check, -extended_crl, -x509_strict, -policy -check_ss_sig>
+
+Set various options of certificate chain verification. See
+L<B<verify>|verify(1)> manual page for details.
+
+=back
+
+=head1 NOTES
+
+The MIME message must be sent without any blank lines between the
+headers and the output. Some mail programs will automatically add
+a blank line. Piping the mail directly to sendmail is one way to
+achieve the correct format.
+
+The supplied message to be signed or encrypted must include the
+necessary MIME headers or many S/MIME clients wont display it
+properly (if at all). You can use the B<-text> option to automatically
+add plain text headers.
+
+A "signed and encrypted" message is one where a signed message is
+then encrypted. This can be produced by encrypting an already signed
+message: see the examples section.
+
+This version of the program only allows one signer per message but it
+will verify multiple signers on received messages. Some S/MIME clients
+choke if a message contains multiple signers. It is possible to sign
+messages "in parallel" by signing an already signed message.
+
+The options B<-encrypt> and B<-decrypt> reflect common usage in S/MIME
+clients. Strictly speaking these process PKCS#7 enveloped data: PKCS#7
+encrypted data is used for other purposes.
+
+The B<-resign> option uses an existing message digest when adding a new
+signer. This means that attributes must be present in at least one existing
+signer using the same message digest or this operation will fail.
+
+The B<-stream> and B<-indef> options enable experimental streaming I/O support.
+As a result the encoding is BER using indefinite length constructed encoding
+and no longer DER. Streaming is supported for the B<-encrypt> operation and the
+B<-sign> operation if the content is not detached.
+
+Streaming is always used for the B<-sign> operation with detached data but
+since the content is no longer part of the PKCS#7 structure the encoding
+remains DER.
+
+=head1 EXIT CODES
+
+=over 4
+
+=item 0
+
+the operation was completely successfully.
+
+=item 1 
+
+an error occurred parsing the command options.
+
+=item 2
+
+one of the input files could not be read.
+
+=item 3
+
+an error occurred creating the PKCS#7 file or when reading the MIME
+message.
+
+=item 4
+
+an error occurred decrypting or verifying the message.
+
+=item 5
+
+the message was verified correctly but an error occurred writing out
+the signers certificates.
+
+=back
+
+=head1 EXAMPLES
+
+Create a cleartext signed message:
+
+ openssl smime -sign -in message.txt -text -out mail.msg \
+       -signer mycert.pem
+
+Create an opaque signed message:
+
+ openssl smime -sign -in message.txt -text -out mail.msg -nodetach \
+       -signer mycert.pem
+
+Create a signed message, include some additional certificates and
+read the private key from another file:
+
+ openssl smime -sign -in in.txt -text -out mail.msg \
+       -signer mycert.pem -inkey mykey.pem -certfile mycerts.pem
+
+Create a signed message with two signers:
+
+ openssl smime -sign -in message.txt -text -out mail.msg \
+       -signer mycert.pem -signer othercert.pem
+
+Send a signed message under Unix directly to sendmail, including headers:
+
+ openssl smime -sign -in in.txt -text -signer mycert.pem \
+       -from steve@openssl.org -to someone@somewhere \
+       -subject "Signed message" | sendmail someone@somewhere
+
+Verify a message and extract the signer's certificate if successful:
+
+ openssl smime -verify -in mail.msg -signer user.pem -out signedtext.txt
+
+Send encrypted mail using triple DES:
+
+ openssl smime -encrypt -in in.txt -from steve@openssl.org \
+       -to someone@somewhere -subject "Encrypted message" \
+       -des3 user.pem -out mail.msg
+
+Sign and encrypt mail:
+
+ openssl smime -sign -in ml.txt -signer my.pem -text \
+       | openssl smime -encrypt -out mail.msg \
+       -from steve@openssl.org -to someone@somewhere \
+       -subject "Signed and Encrypted message" -des3 user.pem
+
+Note: the encryption command does not include the B<-text> option because the
+message being encrypted already has MIME headers.
+
+Decrypt mail:
+
+ openssl smime -decrypt -in mail.msg -recip mycert.pem -inkey key.pem
+
+The output from Netscape form signing is a PKCS#7 structure with the
+detached signature format. You can use this program to verify the
+signature by line wrapping the base64 encoded structure and surrounding
+it with:
+
+ -----BEGIN PKCS7-----
+ -----END PKCS7-----
+
+and using the command: 
+
+ openssl smime -verify -inform PEM -in signature.pem -content content.txt
+
+Alternatively you can base64 decode the signature and use:
+
+ openssl smime -verify -inform DER -in signature.der -content content.txt
+
+Create an encrypted message using 128 bit Camellia:
+
+ openssl smime -encrypt -in plain.txt -camellia128 -out mail.msg cert.pem
+
+Add a signer to an existing message:
+
+ openssl smime -resign -in mail.msg -signer newsign.pem -out mail2.msg
+
+=head1 BUGS
+
+The MIME parser isn't very clever: it seems to handle most messages that I've
+thrown at it but it may choke on others.
+
+The code currently will only write out the signer's certificate to a file: if
+the signer has a separate encryption certificate this must be manually
+extracted. There should be some heuristic that determines the correct
+encryption certificate.
+
+Ideally a database should be maintained of a certificates for each email
+address.
+
+The code doesn't currently take note of the permitted symmetric encryption
+algorithms as supplied in the SMIMECapabilities signed attribute. This means the
+user has to manually include the correct encryption algorithm. It should store
+the list of permitted ciphers in a database and only use those.
+
+No revocation checking is done on the signer's certificate.
+
+The current code can only handle S/MIME v2 messages, the more complex S/MIME v3
+structures may cause parsing errors.
+
+=head1 HISTORY
+
+The use of multiple B<-signer> options and the B<-resign> command were first
+added in OpenSSL 1.0.0
+
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/speed.pod b/deps/openssl/openssl/doc/apps/speed.pod
new file mode 100644 (file)
index 0000000..1cd1998
--- /dev/null
@@ -0,0 +1,59 @@
+=pod
+
+=head1 NAME
+
+speed - test library performance
+
+=head1 SYNOPSIS
+
+B<openssl speed>
+[B<-engine id>]
+[B<md2>]
+[B<mdc2>]
+[B<md5>]
+[B<hmac>]
+[B<sha1>]
+[B<rmd160>]
+[B<idea-cbc>]
+[B<rc2-cbc>]
+[B<rc5-cbc>]
+[B<bf-cbc>]
+[B<des-cbc>]
+[B<des-ede3>]
+[B<rc4>]
+[B<rsa512>]
+[B<rsa1024>]
+[B<rsa2048>]
+[B<rsa4096>]
+[B<dsa512>]
+[B<dsa1024>]
+[B<dsa2048>]
+[B<idea>]
+[B<rc2>]
+[B<des>]
+[B<rsa>]
+[B<blowfish>]
+
+=head1 DESCRIPTION
+
+This command is used to test the performance of cryptographic algorithms.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-engine id>
+
+specifying an engine (by its unique B<id> string) will cause B<speed>
+to attempt to obtain a functional reference to the specified engine,
+thus initialising it if needed. The engine will then be set as the default
+for all available algorithms.
+
+=item B<[zero or more test algorithms]>
+
+If any options are given, B<speed> tests those algorithms, otherwise all of
+the above are tested.
+
+=back
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/spkac.pod b/deps/openssl/openssl/doc/apps/spkac.pod
new file mode 100644 (file)
index 0000000..97fb80e
--- /dev/null
@@ -0,0 +1,133 @@
+=pod
+
+=head1 NAME
+
+spkac - SPKAC printing and generating utility
+
+=head1 SYNOPSIS
+
+B<openssl> B<spkac>
+[B<-in filename>]
+[B<-out filename>]
+[B<-key keyfile>]
+[B<-passin arg>]
+[B<-challenge string>]
+[B<-pubkey>]
+[B<-spkac spkacname>]
+[B<-spksect section>]
+[B<-noout>]
+[B<-verify>]
+[B<-engine id>]
+
+=head1 DESCRIPTION
+
+The B<spkac> command processes Netscape signed public key and challenge
+(SPKAC) files. It can print out their contents, verify the signature and
+produce its own SPKACs from a supplied private key.
+
+=head1 COMMAND OPTIONS
+
+=over 4
+
+=item B<-in filename>
+
+This specifies the input filename to read from or standard input if this
+option is not specified. Ignored if the B<-key> option is used.
+
+=item B<-out filename>
+
+specifies the output filename to write to or standard output by
+default.
+
+=item B<-key keyfile>
+
+create an SPKAC file using the private key in B<keyfile>. The
+B<-in>, B<-noout>, B<-spksect> and B<-verify> options are ignored if
+present.
+
+=item B<-passin password>
+
+the input file password source. For more information about the format of B<arg>
+see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
+
+=item B<-challenge string>
+
+specifies the challenge string if an SPKAC is being created.
+
+=item B<-spkac spkacname>
+
+allows an alternative name form the variable containing the
+SPKAC. The default is "SPKAC". This option affects both
+generated and input SPKAC files.
+
+=item B<-spksect section>
+
+allows an alternative name form the section containing the
+SPKAC. The default is the default section.
+
+=item B<-noout>
+
+don't output the text version of the SPKAC (not used if an
+SPKAC is being created).
+
+=item B<-pubkey>
+
+output the public key of an SPKAC (not used if an SPKAC is
+being created).
+
+=item B<-verify>
+
+verifies the digital signature on the supplied SPKAC.
+
+=item B<-engine id>
+
+specifying an engine (by its unique B<id> string) will cause B<spkac>
+to attempt to obtain a functional reference to the specified engine,
+thus initialising it if needed. The engine will then be set as the default
+for all available algorithms.
+
+=back
+
+=head1 EXAMPLES
+
+Print out the contents of an SPKAC:
+
+ openssl spkac -in spkac.cnf
+
+Verify the signature of an SPKAC:
+
+ openssl spkac -in spkac.cnf -noout -verify
+
+Create an SPKAC using the challenge string "hello":
+
+ openssl spkac -key key.pem -challenge hello -out spkac.cnf
+
+Example of an SPKAC, (long lines split up for clarity):
+
+ SPKAC=MIG5MGUwXDANBgkqhkiG9w0BAQEFAANLADBIAkEA1cCoq2Wa3Ixs47uI7F\
+ PVwHVIPDx5yso105Y6zpozam135a8R0CpoRvkkigIyXfcCjiVi5oWk+6FfPaD03u\
+ PFoQIDAQABFgVoZWxsbzANBgkqhkiG9w0BAQQFAANBAFpQtY/FojdwkJh1bEIYuc\
+ 2EeM2KHTWPEepWYeawvHD0gQ3DngSC75YCWnnDdq+NQ3F+X4deMx9AaEglZtULwV\
+ 4=
+
+=head1 NOTES
+
+A created SPKAC with suitable DN components appended can be fed into
+the B<ca> utility.
+
+SPKACs are typically generated by Netscape when a form is submitted
+containing the B<KEYGEN> tag as part of the certificate enrollment
+process.
+
+The challenge string permits a primitive form of proof of possession
+of private key. By checking the SPKAC signature and a random challenge
+string some guarantee is given that the user knows the private key
+corresponding to the public key being certified. This is important in
+some applications. Without this it is possible for a previous SPKAC
+to be used in a "replay attack".
+
+=head1 SEE ALSO
+
+L<ca(1)|ca(1)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/ts.pod b/deps/openssl/openssl/doc/apps/ts.pod
new file mode 100644 (file)
index 0000000..7fb6caa
--- /dev/null
@@ -0,0 +1,594 @@
+=pod
+
+=head1 NAME
+
+ts - Time Stamping Authority tool (client/server)
+
+=head1 SYNOPSIS
+
+B<openssl> B<ts>
+B<-query>
+[B<-rand> file:file...]
+[B<-config> configfile]
+[B<-data> file_to_hash]
+[B<-digest> digest_bytes]
+[B<-md2>|B<-md4>|B<-md5>|B<-sha>|B<-sha1>|B<-mdc2>|B<-ripemd160>|B<...>]
+[B<-policy> object_id]
+[B<-no_nonce>]
+[B<-cert>]
+[B<-in> request.tsq]
+[B<-out> request.tsq]
+[B<-text>]
+
+B<openssl> B<ts>
+B<-reply>
+[B<-config> configfile]
+[B<-section> tsa_section]
+[B<-queryfile> request.tsq]
+[B<-passin> password_src]
+[B<-signer> tsa_cert.pem]
+[B<-inkey> private.pem]
+[B<-chain> certs_file.pem]
+[B<-policy> object_id]
+[B<-in> response.tsr]
+[B<-token_in>]
+[B<-out> response.tsr]
+[B<-token_out>]
+[B<-text>]
+[B<-engine> id]
+
+B<openssl> B<ts>
+B<-verify>
+[B<-data> file_to_hash]
+[B<-digest> digest_bytes]
+[B<-queryfile> request.tsq]
+[B<-in> response.tsr]
+[B<-token_in>]
+[B<-CApath> trusted_cert_path]
+[B<-CAfile> trusted_certs.pem]
+[B<-untrusted> cert_file.pem]
+
+=head1 DESCRIPTION
+
+The B<ts> command is a basic Time Stamping Authority (TSA) client and server
+application as specified in RFC 3161 (Time-Stamp Protocol, TSP). A
+TSA can be part of a PKI deployment and its role is to provide long
+term proof of the existence of a certain datum before a particular
+time. Here is a brief description of the protocol:
+
+=over 4
+
+=item 1.
+
+The TSA client computes a one-way hash value for a data file and sends
+the hash to the TSA.
+
+=item 2.
+
+The TSA attaches the current date and time to the received hash value,
+signs them and sends the time stamp token back to the client. By
+creating this token the TSA certifies the existence of the original
+data file at the time of response generation.
+
+=item 3.
+
+The TSA client receives the time stamp token and verifies the
+signature on it. It also checks if the token contains the same hash
+value that it had sent to the TSA.
+
+=back
+
+There is one DER encoded protocol data unit defined for transporting a time
+stamp request to the TSA and one for sending the time stamp response
+back to the client. The B<ts> command has three main functions:
+creating a time stamp request based on a data file,
+creating a time stamp response based on a request, verifying if a
+response corresponds to a particular request or a data file.
+
+There is no support for sending the requests/responses automatically
+over HTTP or TCP yet as suggested in RFC 3161. The users must send the
+requests either by ftp or e-mail.
+
+=head1 OPTIONS
+
+=head2 Time Stamp Request generation
+
+The B<-query> switch can be used for creating and printing a time stamp
+request with the following options:
+
+=over 4
+
+=item B<-rand> file:file...
+
+The files containing random data for seeding the random number
+generator. Multiple files can be specified, the separator is B<;> for
+MS-Windows, B<,> for VMS and B<:> for all other platforms. (Optional)
+
+=item B<-config> configfile
+
+The configuration file to use, this option overrides the
+B<OPENSSL_CONF> environment variable. Only the OID section
+of the config file is used with the B<-query> command. (Optional)
+
+=item B<-data> file_to_hash
+
+The data file for which the time stamp request needs to be
+created. stdin is the default if neither the B<-data> nor the B<-digest>
+parameter is specified. (Optional)
+
+=item B<-digest> digest_bytes
+
+It is possible to specify the message imprint explicitly without the data
+file. The imprint must be specified in a hexadecimal format, two characters
+per byte, the bytes optionally separated by colons (e.g. 1A:F6:01:... or
+1AF601...). The number of bytes must match the message digest algorithm 
+in use. (Optional)
+
+=item B<-md2>|B<-md4>|B<-md5>|B<-sha>|B<-sha1>|B<-mdc2>|B<-ripemd160>|B<...>
+
+The message digest to apply to the data file, it supports all the message
+digest algorithms that are supported by the openssl B<dgst> command.
+The default is SHA-1. (Optional)
+
+=item B<-policy> object_id
+
+The policy that the client expects the TSA to use for creating the
+time stamp token. Either the dotted OID notation or OID names defined
+in the config file can be used. If no policy is requested the TSA will
+use its own default policy. (Optional)
+
+=item B<-no_nonce>
+
+No nonce is specified in the request if this option is
+given. Otherwise a 64 bit long pseudo-random none is
+included in the request. It is recommended to use nonce to
+protect against replay-attacks. (Optional)
+
+=item B<-cert>
+
+The TSA is expected to include its signing certificate in the
+response. (Optional)
+
+=item B<-in> request.tsq
+
+This option specifies a previously created time stamp request in DER
+format that will be printed into the output file. Useful when you need
+to examine the content of a request in human-readable
+
+format. (Optional)
+
+=item B<-out> request.tsq
+
+Name of the output file to which the request will be written. Default
+is stdout. (Optional)
+
+=item B<-text>
+
+If this option is specified the output is human-readable text format
+instead of DER. (Optional)
+
+=back
+
+=head2 Time Stamp Response generation
+
+A time stamp response (TimeStampResp) consists of a response status
+and the time stamp token itself (ContentInfo), if the token generation was
+successful. The B<-reply> command is for creating a time stamp
+response or time stamp token based on a request and printing the
+response/token in human-readable format. If B<-token_out> is not
+specified the output is always a time stamp response (TimeStampResp),
+otherwise it is a time stamp token (ContentInfo).
+
+=over 4
+
+=item B<-config> configfile
+
+The configuration file to use, this option overrides the
+B<OPENSSL_CONF> environment variable. See B<CONFIGURATION FILE
+OPTIONS> for configurable variables. (Optional)
+
+=item B<-section> tsa_section
+
+The name of the config file section conatining the settings for the
+response generation. If not specified the default TSA section is
+used, see B<CONFIGURATION FILE OPTIONS> for details. (Optional)
+
+=item B<-queryfile> request.tsq
+
+The name of the file containing a DER encoded time stamp request. (Optional)
+
+=item B<-passin> password_src
+
+Specifies the password source for the private key of the TSA. See
+B<PASS PHRASE ARGUMENTS> in L<openssl(1)|openssl(1)>. (Optional)
+
+=item B<-signer> tsa_cert.pem
+
+The signer certificate of the TSA in PEM format. The TSA signing
+certificate must have exactly one extended key usage assigned to it:
+timeStamping. The extended key usage must also be critical, otherwise
+the certificate is going to be refused. Overrides the B<signer_cert>
+variable of the config file. (Optional)
+
+=item B<-inkey> private.pem
+
+The signer private key of the TSA in PEM format. Overrides the
+B<signer_key> config file option. (Optional)
+
+=item B<-chain> certs_file.pem
+
+The collection of certificates in PEM format that will all
+be included in the response in addition to the signer certificate if
+the B<-cert> option was used for the request. This file is supposed to
+contain the certificate chain for the signer certificate from its
+issuer upwards. The B<-reply> command does not build a certificate
+chain automatically. (Optional)
+
+=item B<-policy> object_id
+
+The default policy to use for the response unless the client
+explicitly requires a particular TSA policy. The OID can be specified
+either in dotted notation or with its name. Overrides the
+B<default_policy> config file option. (Optional)
+
+=item B<-in> response.tsr
+
+Specifies a previously created time stamp response or time stamp token
+(if B<-token_in> is also specified) in DER format that will be written
+to the output file. This option does not require a request, it is
+useful e.g. when you need to examine the content of a response or
+token or you want to extract the time stamp token from a response. If
+the input is a token and the output is a time stamp response a default
+'granted' status info is added to the token. (Optional)
+
+=item B<-token_in>
+
+This flag can be used together with the B<-in> option and indicates
+that the input is a DER encoded time stamp token (ContentInfo) instead
+of a time stamp response (TimeStampResp). (Optional)
+
+=item B<-out> response.tsr
+
+The response is written to this file. The format and content of the
+file depends on other options (see B<-text>, B<-token_out>). The default is
+stdout. (Optional)
+
+=item B<-token_out>
+
+The output is a time stamp token (ContentInfo) instead of time stamp
+response (TimeStampResp). (Optional)
+
+=item B<-text>
+
+If this option is specified the output is human-readable text format
+instead of DER. (Optional)
+
+=item B<-engine> id
+
+Specifying an engine (by its unique B<id> string) will cause B<ts>
+to attempt to obtain a functional reference to the specified engine,
+thus initialising it if needed. The engine will then be set as the default
+for all available algorithms. Default is builtin. (Optional)
+
+=back
+
+=head2 Time Stamp Response verification
+
+The B<-verify> command is for verifying if a time stamp response or time
+stamp token is valid and matches a particular time stamp request or
+data file. The B<-verify> command does not use the configuration file.
+
+=over 4
+
+=item B<-data> file_to_hash
+
+The response or token must be verified against file_to_hash. The file
+is hashed with the message digest algorithm specified in the token. 
+The B<-digest> and B<-queryfile> options must not be specified with this one.
+(Optional)
+
+=item B<-digest> digest_bytes
+
+The response or token must be verified against the message digest specified
+with this option. The number of bytes must match the message digest algorithm
+specified in the token. The B<-data> and B<-queryfile> options must not be
+specified with this one. (Optional)
+
+=item B<-queryfile> request.tsq
+
+The original time stamp request in DER format. The B<-data> and B<-digest>
+options must not be specified with this one. (Optional)
+
+=item B<-in> response.tsr
+
+The time stamp response that needs to be verified in DER format. (Mandatory)
+
+=item B<-token_in>
+
+This flag can be used together with the B<-in> option and indicates
+that the input is a DER encoded time stamp token (ContentInfo) instead
+of a time stamp response (TimeStampResp). (Optional)
+
+=item B<-CApath> trusted_cert_path
+
+The name of the directory containing the trused CA certificates of the
+client. See the similar option of L<verify(1)|verify(1)> for additional
+details. Either this option or B<-CAfile> must be specified. (Optional)
+
+
+=item B<-CAfile> trusted_certs.pem
+
+The name of the file containing a set of trusted self-signed CA 
+certificates in PEM format. See the similar option of 
+L<verify(1)|verify(1)> for additional details. Either this option 
+or B<-CApath> must be specified.
+(Optional)
+
+=item B<-untrusted> cert_file.pem
+
+Set of additional untrusted certificates in PEM format which may be
+needed when building the certificate chain for the TSA's signing
+certificate. This file must contain the TSA signing certificate and
+all intermediate CA certificates unless the response includes them.
+(Optional)
+
+=back
+
+=head1 CONFIGURATION FILE OPTIONS
+
+The B<-query> and B<-reply> commands make use of a configuration file
+defined by the B<OPENSSL_CONF> environment variable. See L<config(5)|config(5)>
+for a general description of the syntax of the config file. The
+B<-query> command uses only the symbolic OID names section
+and it can work without it. However, the B<-reply> command needs the
+config file for its operation.
+
+When there is a command line switch equivalent of a variable the
+switch always overrides the settings in the config file.
+
+=over 4
+
+=item B<tsa> section, B<default_tsa>   
+
+This is the main section and it specifies the name of another section
+that contains all the options for the B<-reply> command. This default
+section can be overriden with the B<-section> command line switch. (Optional)
+
+=item B<oid_file>
+
+See L<ca(1)|ca(1)> for description. (Optional)
+
+=item B<oid_section>
+
+See L<ca(1)|ca(1)> for description. (Optional)
+
+=item B<RANDFILE>
+
+See L<ca(1)|ca(1)> for description. (Optional)
+
+=item B<serial>
+
+The name of the file containing the hexadecimal serial number of the
+last time stamp response created. This number is incremented by 1 for
+each response. If the file does not exist at the time of response
+generation a new file is created with serial number 1. (Mandatory)
+
+=item B<crypto_device>
+
+Specifies the OpenSSL engine that will be set as the default for 
+all available algorithms. The default value is builtin, you can specify 
+any other engines supported by OpenSSL (e.g. use chil for the NCipher HSM).
+(Optional)
+
+=item B<signer_cert>
+
+TSA signing certificate in PEM format. The same as the B<-signer>
+command line option. (Optional)
+
+=item B<certs>
+
+A file containing a set of PEM encoded certificates that need to be
+included in the response. The same as the B<-chain> command line
+option. (Optional)
+
+=item B<signer_key>
+
+The private key of the TSA in PEM format. The same as the B<-inkey>
+command line option. (Optional)
+
+=item B<default_policy>
+
+The default policy to use when the request does not mandate any
+policy. The same as the B<-policy> command line option. (Optional)
+
+=item B<other_policies>
+
+Comma separated list of policies that are also acceptable by the TSA
+and used only if the request explicitly specifies one of them. (Optional)
+
+=item B<digests>
+
+The list of message digest algorithms that the TSA accepts. At least
+one algorithm must be specified. (Mandatory)
+
+=item B<accuracy>
+
+The accuracy of the time source of the TSA in seconds, milliseconds
+and microseconds. E.g. secs:1, millisecs:500, microsecs:100. If any of
+the components is missing zero is assumed for that field. (Optional)
+
+=item B<clock_precision_digits>
+
+Specifies the maximum number of digits, which represent the fraction of 
+seconds, that  need to be included in the time field. The trailing zeroes
+must be removed from the time, so there might actually be fewer digits,
+or no fraction of seconds at all. Supported only on UNIX platforms.
+The maximum value is 6, default is 0.
+(Optional)
+
+=item B<ordering>
+
+If this option is yes the responses generated by this TSA can always
+be ordered, even if the time difference between two responses is less
+than the sum of their accuracies. Default is no. (Optional)
+
+=item B<tsa_name>
+
+Set this option to yes if the subject name of the TSA must be included in
+the TSA name field of the response. Default is no. (Optional)
+
+=item B<ess_cert_id_chain>
+
+The SignedData objects created by the TSA always contain the
+certificate identifier of the signing certificate in a signed
+attribute (see RFC 2634, Enhanced Security Services). If this option
+is set to yes and either the B<certs> variable or the B<-chain> option
+is specified then the certificate identifiers of the chain will also
+be included in the SigningCertificate signed attribute. If this
+variable is set to no, only the signing certificate identifier is
+included. Default is no. (Optional)
+
+=back
+
+=head1 ENVIRONMENT VARIABLES
+
+B<OPENSSL_CONF> contains the path of the configuration file and can be
+overriden by the B<-config> command line option.
+
+=head1 EXAMPLES
+
+All the examples below presume that B<OPENSSL_CONF> is set to a proper
+configuration file, e.g. the example configuration file 
+openssl/apps/openssl.cnf will do.
+
+=head2 Time Stamp Request
+
+To create a time stamp request for design1.txt with SHA-1 
+without nonce and policy and no certificate is required in the response:
+
+  openssl ts -query -data design1.txt -no_nonce \
+       -out design1.tsq
+
+To create a similar time stamp request with specifying the message imprint
+explicitly:
+
+  openssl ts -query -digest b7e5d3f93198b38379852f2c04e78d73abdd0f4b \
+        -no_nonce -out design1.tsq
+
+To print the content of the previous request in human readable format:
+
+  openssl ts -query -in design1.tsq -text
+
+To create a time stamp request which includes the MD-5 digest 
+of design2.txt, requests the signer certificate and nonce,
+specifies a policy id (assuming the tsa_policy1 name is defined in the
+OID section of the config file):
+
+  openssl ts -query -data design2.txt -md5 \
+       -policy tsa_policy1 -cert -out design2.tsq
+
+=head2 Time Stamp Response
+
+Before generating a response a signing certificate must be created for
+the TSA that contains the B<timeStamping> critical extended key usage extension
+without any other key usage extensions. You can add the
+'extendedKeyUsage = critical,timeStamping' line to the user certificate section
+of the config file to generate a proper certificate. See L<req(1)|req(1)>,
+L<ca(1)|ca(1)>, L<x509(1)|x509(1)> for instructions. The examples
+below assume that cacert.pem contains the certificate of the CA,
+tsacert.pem is the signing certificate issued by cacert.pem and
+tsakey.pem is the private key of the TSA.
+
+To create a time stamp response for a request:
+
+  openssl ts -reply -queryfile design1.tsq -inkey tsakey.pem \
+       -signer tsacert.pem -out design1.tsr
+
+If you want to use the settings in the config file you could just write:
+
+  openssl ts -reply -queryfile design1.tsq -out design1.tsr
+
+To print a time stamp reply to stdout in human readable format:
+
+  openssl ts -reply -in design1.tsr -text
+
+To create a time stamp token instead of time stamp response:
+
+  openssl ts -reply -queryfile design1.tsq -out design1_token.der -token_out
+
+To print a time stamp token to stdout in human readable format:
+
+  openssl ts -reply -in design1_token.der -token_in -text -token_out
+
+To extract the time stamp token from a response:
+
+  openssl ts -reply -in design1.tsr -out design1_token.der -token_out
+
+To add 'granted' status info to a time stamp token thereby creating a
+valid response:
+
+  openssl ts -reply -in design1_token.der -token_in -out design1.tsr
+
+=head2 Time Stamp Verification
+
+To verify a time stamp reply against a request:
+
+  openssl ts -verify -queryfile design1.tsq -in design1.tsr \
+       -CAfile cacert.pem -untrusted tsacert.pem
+
+To verify a time stamp reply that includes the certificate chain:
+
+  openssl ts -verify -queryfile design2.tsq -in design2.tsr \
+       -CAfile cacert.pem
+
+To verify a time stamp token against the original data file:
+  openssl ts -verify -data design2.txt -in design2.tsr \
+       -CAfile cacert.pem
+
+To verify a time stamp token against a message imprint:
+  openssl ts -verify -digest b7e5d3f93198b38379852f2c04e78d73abdd0f4b \
+        -in design2.tsr -CAfile cacert.pem
+
+You could also look at the 'test' directory for more examples.
+
+=head1 BUGS
+
+If you find any bugs or you have suggestions please write to
+Zoltan Glozik <zglozik@opentsa.org>. Known issues:
+
+=over 4
+
+=item * No support for time stamps over SMTP, though it is quite easy
+to implement an automatic e-mail based TSA with L<procmail(1)|procmail(1)> 
+and L<perl(1)|perl(1)>. HTTP server support is provided in the form of 
+a separate apache module. HTTP client support is provided by
+L<tsget(1)|tsget(1)>. Pure TCP/IP protocol is not supported.
+
+=item * The file containing the last serial number of the TSA is not
+locked when being read or written. This is a problem if more than one
+instance of L<openssl(1)|openssl(1)> is trying to create a time stamp
+response at the same time. This is not an issue when using the apache
+server module, it does proper locking.
+
+=item * Look for the FIXME word in the source files.
+
+=item * The source code should really be reviewed by somebody else, too.
+
+=item * More testing is needed, I have done only some basic tests (see
+test/testtsa).
+
+=back
+
+=cut
+
+=head1 AUTHOR
+
+Zoltan Glozik <zglozik@opentsa.org>, OpenTSA project (http://www.opentsa.org)
+
+=head1 SEE ALSO
+
+L<tsget(1)|tsget(1)>, L<openssl(1)|openssl(1)>, L<req(1)|req(1)>, 
+L<x509(1)|x509(1)>, L<ca(1)|ca(1)>, L<genrsa(1)|genrsa(1)>, 
+L<config(5)|config(5)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/tsget.pod b/deps/openssl/openssl/doc/apps/tsget.pod
new file mode 100644 (file)
index 0000000..b05957b
--- /dev/null
@@ -0,0 +1,194 @@
+=pod
+
+=head1 NAME
+
+tsget - Time Stamping HTTP/HTTPS client
+
+=head1 SYNOPSIS
+
+B<tsget>
+B<-h> server_url
+[B<-e> extension]
+[B<-o> output]
+[B<-v>]
+[B<-d>]
+[B<-k> private_key.pem]
+[B<-p> key_password]
+[B<-c> client_cert.pem]
+[B<-C> CA_certs.pem]
+[B<-P> CA_path]
+[B<-r> file:file...]
+[B<-g> EGD_socket]
+[request]...
+
+=head1 DESCRIPTION
+
+The B<tsget> command can be used for sending a time stamp request, as
+specified in B<RFC 3161>, to a time stamp server over HTTP or HTTPS and storing
+the time stamp response in a file. This tool cannot be used for creating the
+requests and verifying responses, you can use the OpenSSL B<ts(1)> command to
+do that. B<tsget> can send several requests to the server without closing
+the TCP connection if more than one requests are specified on the command
+line.
+
+The tool sends the following HTTP request for each time stamp request:
+
+       POST url HTTP/1.1
+       User-Agent: OpenTSA tsget.pl/<version>
+       Host: <host>:<port>
+       Pragma: no-cache
+       Content-Type: application/timestamp-query
+       Accept: application/timestamp-reply
+       Content-Length: length of body
+
+       ...binary request specified by the user...
+
+B<tsget> expects a response of type application/timestamp-reply, which is
+written to a file without any interpretation.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-h> server_url
+
+The URL of the HTTP/HTTPS server listening for time stamp requests.
+
+=item B<-e> extension
+
+If the B<-o> option is not given this argument specifies the extension of the
+output files. The base name of the output file will be the same as those of
+the input files. Default extension is '.tsr'. (Optional)
+
+=item B<-o> output
+
+This option can be specified only when just one request is sent to the
+server. The time stamp response will be written to the given output file. '-'
+means standard output. In case of multiple time stamp requests or the absence
+of this argument the names of the output files will be derived from the names
+of the input files and the default or specified extension argument. (Optional)
+
+=item B<-v>
+
+The name of the currently processed request is printed on standard
+error. (Optional)
+
+=item B<-d>
+
+Switches on verbose mode for the underlying B<curl> library. You can see
+detailed debug messages for the connection. (Optional)
+
+=item B<-k> private_key.pem
+
+(HTTPS) In case of certificate-based client authentication over HTTPS
+<private_key.pem> must contain the private key of the user. The private key
+file can optionally be protected by a passphrase. The B<-c> option must also
+be specified. (Optional)
+
+=item B<-p> key_password
+
+(HTTPS) Specifies the passphrase for the private key specified by the B<-k>
+argument. If this option is omitted and the key is passphrase protected B<tsget>
+will ask for it. (Optional)
+
+=item B<-c> client_cert.pem
+
+(HTTPS) In case of certificate-based client authentication over HTTPS
+<client_cert.pem> must contain the X.509 certificate of the user.  The B<-k>
+option must also be specified. If this option is not specified no
+certificate-based client authentication will take place. (Optional)
+
+=item B<-C> CA_certs.pem
+
+(HTTPS) The trusted CA certificate store. The certificate chain of the peer's
+certificate must include one of the CA certificates specified in this file.
+Either option B<-C> or option B<-P> must be given in case of HTTPS. (Optional)
+
+=item B<-P> CA_path
+
+(HTTPS) The path containing the trusted CA certificates to verify the peer's
+certificate. The directory must be prepared with the B<c_rehash>
+OpenSSL utility. Either option B<-C> or option B<-P> must be given in case of
+HTTPS. (Optional)
+
+=item B<-rand> file:file...
+
+The files containing random data for seeding the random number
+generator. Multiple files can be specified, the separator is B<;> for
+MS-Windows, B<,> for VMS and B<:> for all other platforms. (Optional)
+
+=item B<-g> EGD_socket
+
+The name of an EGD socket to get random data from. (Optional)
+
+=item [request]...
+
+List of files containing B<RFC 3161> DER-encoded time stamp requests. If no
+requests are specifed only one request will be sent to the server and it will be
+read from the standard input. (Optional)
+
+=back
+
+=head1 ENVIRONMENT VARIABLES
+
+The B<TSGET> environment variable can optionally contain default
+arguments. The content of this variable is added to the list of command line
+arguments.
+
+=head1 EXAMPLES
+
+The examples below presume that B<file1.tsq> and B<file2.tsq> contain valid
+time stamp requests, tsa.opentsa.org listens at port 8080 for HTTP requests
+and at port 8443 for HTTPS requests, the TSA service is available at the /tsa
+absolute path.
+
+Get a time stamp response for file1.tsq over HTTP, output is written to 
+file1.tsr:
+
+  tsget -h http://tsa.opentsa.org:8080/tsa file1.tsq
+
+Get a time stamp response for file1.tsq and file2.tsq over HTTP showing
+progress, output is written to file1.reply and file2.reply respectively:
+
+  tsget -h http://tsa.opentsa.org:8080/tsa -v -e .reply \
+       file1.tsq file2.tsq
+
+Create a time stamp request, write it to file3.tsq, send it to the server and
+write the response to file3.tsr:
+
+  openssl ts -query -data file3.txt -cert | tee file3.tsq \
+       | tsget -h http://tsa.opentsa.org:8080/tsa \
+       -o file3.tsr
+
+Get a time stamp response for file1.tsq over HTTPS without client
+authentication:
+
+  tsget -h https://tsa.opentsa.org:8443/tsa \
+       -C cacerts.pem file1.tsq
+
+Get a time stamp response for file1.tsq over HTTPS with certificate-based
+client authentication (it will ask for the passphrase if client_key.pem is
+protected):
+
+  tsget -h https://tsa.opentsa.org:8443/tsa -C cacerts.pem \
+       -k client_key.pem -c client_cert.pem file1.tsq
+
+You can shorten the previous command line if you make use of the B<TSGET>
+environment variable. The following commands do the same as the previous
+example:
+
+  TSGET='-h https://tsa.opentsa.org:8443/tsa -C cacerts.pem \
+       -k client_key.pem -c client_cert.pem'
+  export TSGET
+  tsget file1.tsq
+
+=head1 AUTHOR
+
+Zoltan Glozik <zglozik@opentsa.org>, OpenTSA project (http://www.opentsa.org)
+
+=head1 SEE ALSO
+
+L<openssl(1)|openssl(1)>, L<ts(1)|ts(1)>, L<curl(1)|curl(1)>, 
+B<RFC 3161>
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/verify.pod b/deps/openssl/openssl/doc/apps/verify.pod
new file mode 100644 (file)
index 0000000..336098f
--- /dev/null
@@ -0,0 +1,406 @@
+=pod
+
+=head1 NAME
+
+verify - Utility to verify certificates.
+
+=head1 SYNOPSIS
+
+B<openssl> B<verify>
+[B<-CApath directory>]
+[B<-CAfile file>]
+[B<-purpose purpose>]
+[B<-policy arg>]
+[B<-ignore_critical>]
+[B<-crl_check>]
+[B<-crl_check_all>]
+[B<-policy_check>]
+[B<-explicit_policy>]
+[B<-inhibit_any>]
+[B<-inhibit_map>]
+[B<-x509_strict>]
+[B<-extended_crl>]
+[B<-use_deltas>]
+[B<-policy_print>]
+[B<-untrusted file>]
+[B<-help>]
+[B<-issuer_checks>]
+[B<-verbose>]
+[B<->]
+[certificates]
+
+
+=head1 DESCRIPTION
+
+The B<verify> command verifies certificate chains.
+
+=head1 COMMAND OPTIONS
+
+=over 4
+
+=item B<-CApath directory>
+
+A directory of trusted certificates. The certificates should have names
+of the form: hash.0 or have symbolic links to them of this
+form ("hash" is the hashed certificate subject name: see the B<-hash> option
+of the B<x509> utility). Under Unix the B<c_rehash> script will automatically
+create symbolic links to a directory of certificates.
+
+=item B<-CAfile file>
+
+A file of trusted certificates. The file should contain multiple certificates
+in PEM format concatenated together.
+
+=item B<-untrusted file>
+
+A file of untrusted certificates. The file should contain multiple certificates
+
+=item B<-purpose purpose>
+
+the intended use for the certificate. Without this option no chain verification
+will be done. Currently accepted uses are B<sslclient>, B<sslserver>,
+B<nssslserver>, B<smimesign>, B<smimeencrypt>. See the B<VERIFY OPERATION>
+section for more information.
+
+=item B<-help>
+
+prints out a usage message.
+
+=item B<-verbose>
+
+print extra information about the operations being performed.
+
+=item B<-issuer_checks>
+
+print out diagnostics relating to searches for the issuer certificate
+of the current certificate. This shows why each candidate issuer
+certificate was rejected. However the presence of rejection messages
+does not itself imply that anything is wrong: during the normal
+verify process several rejections may take place.
+
+=item B<-policy arg>
+
+Enable policy processing and add B<arg> to the user-initial-policy-set
+(see RFC3280 et al). The policy B<arg> can be an object name an OID in numeric
+form. This argument can appear more than once.
+
+=item B<-policy_check>
+
+Enables certificate policy processing.
+
+=item B<-explicit_policy>
+
+Set policy variable require-explicit-policy (see RFC3280 et al).
+
+=item B<-inhibit_any>
+
+Set policy variable inhibit-any-policy (see RFC3280 et al).
+
+=item B<-inhibit_map>
+
+Set policy variable inhibit-policy-mapping (see RFC3280 et al).
+
+=item B<-policy_print>
+
+Print out diagnostics, related to policy checking
+
+=item B<-crl_check>
+
+Checks end entity certificate validity by attempting to lookup a valid CRL.
+If a valid CRL cannot be found an error occurs. 
+
+=item B<-crl_check_all>
+
+Checks the validity of B<all> certificates in the chain by attempting
+to lookup valid CRLs.
+
+=item B<-ignore_critical>
+
+Normally if an unhandled critical extension is present which is not
+supported by OpenSSL the certificate is rejected (as required by
+RFC3280 et al). If this option is set critical extensions are
+ignored.
+
+=item B<-x509_strict>
+
+Disable workarounds for broken certificates which have to be disabled
+for strict X.509 compliance.
+
+=item B<-extended_crl>
+
+Enable extended CRL features such as indirect CRLs and alternate CRL
+signing keys.
+
+=item B<-use_deltas>
+
+Enable support for delta CRLs.
+
+=item B<-check_ss_sig>
+
+Verify the signature on the self-signed root CA. This is disabled by default
+because it doesn't add any security.
+
+=item B<->
+
+marks the last option. All arguments following this are assumed to be
+certificate files. This is useful if the first certificate filename begins
+with a B<->.
+
+=item B<certificates>
+
+one or more certificates to verify. If no certificate filenames are included
+then an attempt is made to read a certificate from standard input. They should
+all be in PEM format.
+
+
+=back
+
+=head1 VERIFY OPERATION
+
+The B<verify> program uses the same functions as the internal SSL and S/MIME
+verification, therefore this description applies to these verify operations
+too.
+
+There is one crucial difference between the verify operations performed
+by the B<verify> program: wherever possible an attempt is made to continue
+after an error whereas normally the verify operation would halt on the
+first error. This allows all the problems with a certificate chain to be
+determined.
+
+The verify operation consists of a number of separate steps.
+
+Firstly a certificate chain is built up starting from the supplied certificate
+and ending in the root CA. It is an error if the whole chain cannot be built
+up. The chain is built up by looking up the issuers certificate of the current
+certificate. If a certificate is found which is its own issuer it is assumed 
+to be the root CA.
+
+The process of 'looking up the issuers certificate' itself involves a number
+of steps. In versions of OpenSSL before 0.9.5a the first certificate whose
+subject name matched the issuer of the current certificate was assumed to be
+the issuers certificate. In OpenSSL 0.9.6 and later all certificates
+whose subject name matches the issuer name of the current certificate are 
+subject to further tests. The relevant authority key identifier components
+of the current certificate (if present) must match the subject key identifier
+(if present) and issuer and serial number of the candidate issuer, in addition
+the keyUsage extension of the candidate issuer (if present) must permit
+certificate signing.
+
+The lookup first looks in the list of untrusted certificates and if no match
+is found the remaining lookups are from the trusted certificates. The root CA
+is always looked up in the trusted certificate list: if the certificate to
+verify is a root certificate then an exact match must be found in the trusted
+list.
+
+The second operation is to check every untrusted certificate's extensions for
+consistency with the supplied purpose. If the B<-purpose> option is not included
+then no checks are done. The supplied or "leaf" certificate must have extensions
+compatible with the supplied purpose and all other certificates must also be valid
+CA certificates. The precise extensions required are described in more detail in
+the B<CERTIFICATE EXTENSIONS> section of the B<x509> utility.
+
+The third operation is to check the trust settings on the root CA. The root
+CA should be trusted for the supplied purpose. For compatibility with previous
+versions of SSLeay and OpenSSL a certificate with no trust settings is considered
+to be valid for all purposes. 
+
+The final operation is to check the validity of the certificate chain. The validity
+period is checked against the current system time and the notBefore and notAfter
+dates in the certificate. The certificate signatures are also checked at this
+point.
+
+If all operations complete successfully then certificate is considered valid. If
+any operation fails then the certificate is not valid.
+
+=head1 DIAGNOSTICS
+
+When a verify operation fails the output messages can be somewhat cryptic. The
+general form of the error message is:
+
+ server.pem: /C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test CA (1024 bit)
+ error 24 at 1 depth lookup:invalid CA certificate
+
+The first line contains the name of the certificate being verified followed by
+the subject name of the certificate. The second line contains the error number
+and the depth. The depth is number of the certificate being verified when a
+problem was detected starting with zero for the certificate being verified itself
+then 1 for the CA that signed the certificate and so on. Finally a text version
+of the error number is presented.
+
+An exhaustive list of the error codes and messages is shown below, this also
+includes the name of the error code as defined in the header file x509_vfy.h
+Some of the error codes are defined but never returned: these are described
+as "unused".
+
+=over 4
+
+=item B<0 X509_V_OK: ok>
+
+the operation was successful.
+
+=item B<2 X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: unable to get issuer certificate>
+
+the issuer certificate of a looked up certificate could not be found. This
+normally means the list of trusted certificates is not complete.
+
+=item B<3 X509_V_ERR_UNABLE_TO_GET_CRL: unable to get certificate CRL>
+
+the CRL of a certificate could not be found.
+
+=item B<4 X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE: unable to decrypt certificate's signature>
+
+the certificate signature could not be decrypted. This means that the actual signature value
+could not be determined rather than it not matching the expected value, this is only
+meaningful for RSA keys.
+
+=item B<5 X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE: unable to decrypt CRL's signature>
+
+the CRL signature could not be decrypted: this means that the actual signature value
+could not be determined rather than it not matching the expected value. Unused.
+
+=item B<6 X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY: unable to decode issuer public key>
+
+the public key in the certificate SubjectPublicKeyInfo could not be read.
+
+=item B<7 X509_V_ERR_CERT_SIGNATURE_FAILURE: certificate signature failure>
+
+the signature of the certificate is invalid.
+
+=item B<8 X509_V_ERR_CRL_SIGNATURE_FAILURE: CRL signature failure>
+
+the signature of the certificate is invalid.
+
+=item B<9 X509_V_ERR_CERT_NOT_YET_VALID: certificate is not yet valid>
+
+the certificate is not yet valid: the notBefore date is after the current time.
+
+=item B<10 X509_V_ERR_CERT_HAS_EXPIRED: certificate has expired>
+
+the certificate has expired: that is the notAfter date is before the current time.
+
+=item B<11 X509_V_ERR_CRL_NOT_YET_VALID: CRL is not yet valid>
+
+the CRL is not yet valid.
+
+=item B<12 X509_V_ERR_CRL_HAS_EXPIRED: CRL has expired>
+
+the CRL has expired.
+
+=item B<13 X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD: format error in certificate's notBefore field>
+
+the certificate notBefore field contains an invalid time.
+
+=item B<14 X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD: format error in certificate's notAfter field>
+
+the certificate notAfter field contains an invalid time.
+
+=item B<15 X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD: format error in CRL's lastUpdate field>
+
+the CRL lastUpdate field contains an invalid time.
+
+=item B<16 X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD: format error in CRL's nextUpdate field>
+
+the CRL nextUpdate field contains an invalid time.
+
+=item B<17 X509_V_ERR_OUT_OF_MEM: out of memory>
+
+an error occurred trying to allocate memory. This should never happen.
+
+=item B<18 X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: self signed certificate>
+
+the passed certificate is self signed and the same certificate cannot be found in the list of
+trusted certificates.
+
+=item B<19 X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN: self signed certificate in certificate chain>
+
+the certificate chain could be built up using the untrusted certificates but the root could not
+be found locally.
+
+=item B<20 X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY: unable to get local issuer certificate>
+
+the issuer certificate could not be found: this occurs if the issuer
+certificate of an untrusted certificate cannot be found.
+
+=item B<21 X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE: unable to verify the first certificate>
+
+no signatures could be verified because the chain contains only one certificate and it is not
+self signed.
+
+=item B<22 X509_V_ERR_CERT_CHAIN_TOO_LONG: certificate chain too long>
+
+the certificate chain length is greater than the supplied maximum depth. Unused.
+
+=item B<23 X509_V_ERR_CERT_REVOKED: certificate revoked>
+
+the certificate has been revoked.
+
+=item B<24 X509_V_ERR_INVALID_CA: invalid CA certificate>
+
+a CA certificate is invalid. Either it is not a CA or its extensions are not consistent
+with the supplied purpose.
+
+=item B<25 X509_V_ERR_PATH_LENGTH_EXCEEDED: path length constraint exceeded>
+
+the basicConstraints pathlength parameter has been exceeded.
+
+=item B<26 X509_V_ERR_INVALID_PURPOSE: unsupported certificate purpose>
+
+the supplied certificate cannot be used for the specified purpose.
+
+=item B<27 X509_V_ERR_CERT_UNTRUSTED: certificate not trusted>
+
+the root CA is not marked as trusted for the specified purpose.
+
+=item B<28 X509_V_ERR_CERT_REJECTED: certificate rejected>
+
+the root CA is marked to reject the specified purpose.
+
+=item B<29 X509_V_ERR_SUBJECT_ISSUER_MISMATCH: subject issuer mismatch>
+
+the current candidate issuer certificate was rejected because its subject name
+did not match the issuer name of the current certificate. Only displayed when
+the B<-issuer_checks> option is set.
+
+=item B<30 X509_V_ERR_AKID_SKID_MISMATCH: authority and subject key identifier mismatch>
+
+the current candidate issuer certificate was rejected because its subject key
+identifier was present and did not match the authority key identifier current
+certificate. Only displayed when the B<-issuer_checks> option is set.
+
+=item B<31 X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH: authority and issuer serial number mismatch>
+
+the current candidate issuer certificate was rejected because its issuer name
+and serial number was present and did not match the authority key identifier
+of the current certificate. Only displayed when the B<-issuer_checks> option is set.
+
+=item B<32 X509_V_ERR_KEYUSAGE_NO_CERTSIGN:key usage does not include certificate signing>
+
+the current candidate issuer certificate was rejected because its keyUsage extension
+does not permit certificate signing.
+
+=item B<50 X509_V_ERR_APPLICATION_VERIFICATION: application verification failure>
+
+an application specific error. Unused.
+
+=back
+
+=head1 BUGS
+
+Although the issuer checks are a considerably improvement over the old technique they still
+suffer from limitations in the underlying X509_LOOKUP API. One consequence of this is that
+trusted certificates with matching subject name must either appear in a file (as specified by the
+B<-CAfile> option) or a directory (as specified by B<-CApath>. If they occur in both then only
+the certificates in the file will be recognised.
+
+Previous versions of OpenSSL assume certificates with matching subject name are identical and
+mishandled them.
+
+Previous versions of this documentation swapped the meaning of the
+B<X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT> and
+B<20 X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY> error codes.
+
+=head1 SEE ALSO
+
+L<x509(1)|x509(1)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/version.pod b/deps/openssl/openssl/doc/apps/version.pod
new file mode 100644 (file)
index 0000000..e00324c
--- /dev/null
@@ -0,0 +1,64 @@
+=pod
+
+=head1 NAME
+
+version - print OpenSSL version information
+
+=head1 SYNOPSIS
+
+B<openssl version>
+[B<-a>]
+[B<-v>]
+[B<-b>]
+[B<-o>]
+[B<-f>]
+[B<-p>]
+
+=head1 DESCRIPTION
+
+This command is used to print out version information about OpenSSL.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-a>
+
+all information, this is the same as setting all the other flags.
+
+=item B<-v>
+
+the current OpenSSL version.
+
+=item B<-b>
+
+the date the current version of OpenSSL was built.
+
+=item B<-o>
+
+option information: various options set when the library was built.
+
+=item B<-c>
+
+compilation flags.
+
+=item B<-p>
+
+platform setting.
+
+=item B<-d>
+
+OPENSSLDIR setting.
+
+=back
+
+=head1 NOTES
+
+The output of B<openssl version -a> would typically be used when sending
+in a bug report.
+
+=head1 HISTORY
+
+The B<-d> option was added in OpenSSL 0.9.7.
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/x509.pod b/deps/openssl/openssl/doc/apps/x509.pod
new file mode 100644 (file)
index 0000000..3002b08
--- /dev/null
@@ -0,0 +1,856 @@
+
+=pod
+
+=head1 NAME
+
+x509 - Certificate display and signing utility
+
+=head1 SYNOPSIS
+
+B<openssl> B<x509>
+[B<-inform DER|PEM|NET>]
+[B<-outform DER|PEM|NET>]
+[B<-keyform DER|PEM>]
+[B<-CAform DER|PEM>]
+[B<-CAkeyform DER|PEM>]
+[B<-in filename>]
+[B<-out filename>]
+[B<-serial>]
+[B<-hash>]
+[B<-subject_hash>]
+[B<-issuer_hash>]
+[B<-subject>]
+[B<-issuer>]
+[B<-nameopt option>]
+[B<-email>]
+[B<-ocsp_uri>]
+[B<-startdate>]
+[B<-enddate>]
+[B<-purpose>]
+[B<-dates>]
+[B<-modulus>]
+[B<-fingerprint>]
+[B<-alias>]
+[B<-noout>]
+[B<-trustout>]
+[B<-clrtrust>]
+[B<-clrreject>]
+[B<-addtrust arg>]
+[B<-addreject arg>]
+[B<-setalias arg>]
+[B<-days arg>]
+[B<-set_serial n>]
+[B<-signkey filename>]
+[B<-x509toreq>]
+[B<-req>]
+[B<-CA filename>]
+[B<-CAkey filename>]
+[B<-CAcreateserial>]
+[B<-CAserial filename>]
+[B<-text>]
+[B<-C>]
+[B<-md2|-md5|-sha1|-mdc2>]
+[B<-clrext>]
+[B<-extfile filename>]
+[B<-extensions section>]
+[B<-engine id>]
+
+=head1 DESCRIPTION
+
+The B<x509> command is a multi purpose certificate utility. It can be
+used to display certificate information, convert certificates to
+various forms, sign certificate requests like a "mini CA" or edit
+certificate trust settings.
+
+Since there are a large number of options they will split up into
+various sections.
+
+=head1 OPTIONS
+
+=head2 INPUT, OUTPUT AND GENERAL PURPOSE OPTIONS
+
+=over 4
+
+=item B<-inform DER|PEM|NET>
+
+This specifies the input format normally the command will expect an X509
+certificate but this can change if other options such as B<-req> are
+present. The DER format is the DER encoding of the certificate and PEM
+is the base64 encoding of the DER encoding with header and footer lines
+added. The NET option is an obscure Netscape server format that is now
+obsolete.
+
+=item B<-outform DER|PEM|NET>
+
+This specifies the output format, the options have the same meaning as the 
+B<-inform> option.
+
+=item B<-in filename>
+
+This specifies the input filename to read a certificate from or standard input
+if this option is not specified.
+
+=item B<-out filename>
+
+This specifies the output filename to write to or standard output by
+default.
+
+=item B<-md2|-md5|-sha1|-mdc2>
+
+the digest to use. This affects any signing or display option that uses a message
+digest, such as the B<-fingerprint>, B<-signkey> and B<-CA> options. If not
+specified then SHA1 is used. If the key being used to sign with is a DSA key
+then this option has no effect: SHA1 is always used with DSA keys.
+
+=item B<-engine id>
+
+specifying an engine (by its unique B<id> string) will cause B<x509>
+to attempt to obtain a functional reference to the specified engine,
+thus initialising it if needed. The engine will then be set as the default
+for all available algorithms.
+
+=back
+
+=head2 DISPLAY OPTIONS
+
+Note: the B<-alias> and B<-purpose> options are also display options
+but are described in the B<TRUST SETTINGS> section.
+
+=over 4
+
+=item B<-text>
+
+prints out the certificate in text form. Full details are output including the
+public key, signature algorithms, issuer and subject names, serial number
+any extensions present and any trust settings.
+
+=item B<-certopt option>
+
+customise the output format used with B<-text>. The B<option> argument can be
+a single option or multiple options separated by commas. The B<-certopt> switch
+may be also be used more than once to set multiple options. See the B<TEXT OPTIONS>
+section for more information.
+
+=item B<-noout>
+
+this option prevents output of the encoded version of the request.
+
+=item B<-modulus>
+
+this option prints out the value of the modulus of the public key
+contained in the certificate.
+
+=item B<-serial>
+
+outputs the certificate serial number.
+
+=item B<-subject_hash>
+
+outputs the "hash" of the certificate subject name. This is used in OpenSSL to
+form an index to allow certificates in a directory to be looked up by subject
+name.
+
+=item B<-issuer_hash>
+
+outputs the "hash" of the certificate issuer name.
+
+=item B<-hash>
+
+synonym for "-subject_hash" for backward compatibility reasons.
+
+=item B<-subject_hash_old>
+
+outputs the "hash" of the certificate subject name using the older algorithm
+as used by OpenSSL versions before 1.0.0.
+
+=item B<-issuer_hash_old>
+
+outputs the "hash" of the certificate issuer name using the older algorithm
+as used by OpenSSL versions before 1.0.0.
+
+=item B<-subject>
+
+outputs the subject name.
+
+=item B<-issuer>
+
+outputs the issuer name.
+
+=item B<-nameopt option>
+
+option which determines how the subject or issuer names are displayed. The
+B<option> argument can be a single option or multiple options separated by
+commas.  Alternatively the B<-nameopt> switch may be used more than once to
+set multiple options. See the B<NAME OPTIONS> section for more information.
+
+=item B<-email>
+
+outputs the email address(es) if any.
+
+=item B<-ocsp_uri>
+
+outputs the OCSP responder address(es) if any.
+
+=item B<-startdate>
+
+prints out the start date of the certificate, that is the notBefore date.
+
+=item B<-enddate>
+
+prints out the expiry date of the certificate, that is the notAfter date.
+
+=item B<-dates>
+
+prints out the start and expiry dates of a certificate.
+
+=item B<-fingerprint>
+
+prints out the digest of the DER encoded version of the whole certificate
+(see digest options).
+
+=item B<-C>
+
+this outputs the certificate in the form of a C source file.
+
+=back
+
+=head2 TRUST SETTINGS
+
+Please note these options are currently experimental and may well change.
+
+A B<trusted certificate> is an ordinary certificate which has several
+additional pieces of information attached to it such as the permitted
+and prohibited uses of the certificate and an "alias".
+
+Normally when a certificate is being verified at least one certificate
+must be "trusted". By default a trusted certificate must be stored
+locally and must be a root CA: any certificate chain ending in this CA
+is then usable for any purpose.
+
+Trust settings currently are only used with a root CA. They allow a finer
+control over the purposes the root CA can be used for. For example a CA
+may be trusted for SSL client but not SSL server use.
+
+See the description of the B<verify> utility for more information on the
+meaning of trust settings.
+
+Future versions of OpenSSL will recognize trust settings on any
+certificate: not just root CAs.
+
+
+=over 4
+
+=item B<-trustout>
+
+this causes B<x509> to output a B<trusted> certificate. An ordinary
+or trusted certificate can be input but by default an ordinary
+certificate is output and any trust settings are discarded. With the
+B<-trustout> option a trusted certificate is output. A trusted
+certificate is automatically output if any trust settings are modified.
+
+=item B<-setalias arg>
+
+sets the alias of the certificate. This will allow the certificate
+to be referred to using a nickname for example "Steve's Certificate".
+
+=item B<-alias>
+
+outputs the certificate alias, if any.
+
+=item B<-clrtrust>
+
+clears all the permitted or trusted uses of the certificate.
+
+=item B<-clrreject>
+
+clears all the prohibited or rejected uses of the certificate.
+
+=item B<-addtrust arg>
+
+adds a trusted certificate use. Any object name can be used here
+but currently only B<clientAuth> (SSL client use), B<serverAuth>
+(SSL server use) and B<emailProtection> (S/MIME email) are used.
+Other OpenSSL applications may define additional uses.
+
+=item B<-addreject arg>
+
+adds a prohibited use. It accepts the same values as the B<-addtrust>
+option.
+
+=item B<-purpose>
+
+this option performs tests on the certificate extensions and outputs
+the results. For a more complete description see the B<CERTIFICATE
+EXTENSIONS> section.
+
+=back
+
+=head2 SIGNING OPTIONS
+
+The B<x509> utility can be used to sign certificates and requests: it
+can thus behave like a "mini CA".
+
+=over 4
+
+=item B<-signkey filename>
+
+this option causes the input file to be self signed using the supplied
+private key. 
+
+If the input file is a certificate it sets the issuer name to the
+subject name (i.e.  makes it self signed) changes the public key to the
+supplied value and changes the start and end dates. The start date is
+set to the current time and the end date is set to a value determined
+by the B<-days> option. Any certificate extensions are retained unless
+the B<-clrext> option is supplied.
+
+If the input is a certificate request then a self signed certificate
+is created using the supplied private key using the subject name in
+the request.
+
+=item B<-clrext>
+
+delete any extensions from a certificate. This option is used when a
+certificate is being created from another certificate (for example with
+the B<-signkey> or the B<-CA> options). Normally all extensions are
+retained.
+
+=item B<-keyform PEM|DER>
+
+specifies the format (DER or PEM) of the private key file used in the
+B<-signkey> option.
+
+=item B<-days arg>
+
+specifies the number of days to make a certificate valid for. The default
+is 30 days.
+
+=item B<-x509toreq>
+
+converts a certificate into a certificate request. The B<-signkey> option
+is used to pass the required private key.
+
+=item B<-req>
+
+by default a certificate is expected on input. With this option a
+certificate request is expected instead.
+
+=item B<-set_serial n>
+
+specifies the serial number to use. This option can be used with either
+the B<-signkey> or B<-CA> options. If used in conjunction with the B<-CA>
+option the serial number file (as specified by the B<-CAserial> or
+B<-CAcreateserial> options) is not used.
+
+The serial number can be decimal or hex (if preceded by B<0x>). Negative
+serial numbers can also be specified but their use is not recommended.
+
+=item B<-CA filename>
+
+specifies the CA certificate to be used for signing. When this option is
+present B<x509> behaves like a "mini CA". The input file is signed by this
+CA using this option: that is its issuer name is set to the subject name
+of the CA and it is digitally signed using the CAs private key.
+
+This option is normally combined with the B<-req> option. Without the
+B<-req> option the input is a certificate which must be self signed.
+
+=item B<-CAkey filename>
+
+sets the CA private key to sign a certificate with. If this option is
+not specified then it is assumed that the CA private key is present in
+the CA certificate file.
+
+=item B<-CAserial filename>
+
+sets the CA serial number file to use.
+
+When the B<-CA> option is used to sign a certificate it uses a serial
+number specified in a file. This file consist of one line containing
+an even number of hex digits with the serial number to use. After each
+use the serial number is incremented and written out to the file again.
+
+The default filename consists of the CA certificate file base name with
+".srl" appended. For example if the CA certificate file is called 
+"mycacert.pem" it expects to find a serial number file called "mycacert.srl".
+
+=item B<-CAcreateserial>
+
+with this option the CA serial number file is created if it does not exist:
+it will contain the serial number "02" and the certificate being signed will
+have the 1 as its serial number. Normally if the B<-CA> option is specified
+and the serial number file does not exist it is an error.
+
+=item B<-extfile filename>
+
+file containing certificate extensions to use. If not specified then
+no extensions are added to the certificate.
+
+=item B<-extensions section>
+
+the section to add certificate extensions from. If this option is not
+specified then the extensions should either be contained in the unnamed
+(default) section or the default section should contain a variable called
+"extensions" which contains the section to use. See the
+L<x509v3_config(5)|x509v3_config(5)> manual page for details of the
+extension section format.
+
+=back
+
+=head2 NAME OPTIONS
+
+The B<nameopt> command line switch determines how the subject and issuer
+names are displayed. If no B<nameopt> switch is present the default "oneline"
+format is used which is compatible with previous versions of OpenSSL.
+Each option is described in detail below, all options can be preceded by
+a B<-> to turn the option off. Only the first four will normally be used.
+
+=over 4
+
+=item B<compat>
+
+use the old format. This is equivalent to specifying no name options at all.
+
+=item B<RFC2253>
+
+displays names compatible with RFC2253 equivalent to B<esc_2253>, B<esc_ctrl>,
+B<esc_msb>, B<utf8>, B<dump_nostr>, B<dump_unknown>, B<dump_der>,
+B<sep_comma_plus>, B<dn_rev> and B<sname>.
+
+=item B<oneline>
+
+a oneline format which is more readable than RFC2253. It is equivalent to
+specifying the  B<esc_2253>, B<esc_ctrl>, B<esc_msb>, B<utf8>, B<dump_nostr>,
+B<dump_der>, B<use_quote>, B<sep_comma_plus_space>, B<space_eq> and B<sname>
+options.
+
+=item B<multiline>
+
+a multiline format. It is equivalent B<esc_ctrl>, B<esc_msb>, B<sep_multiline>,
+B<space_eq>, B<lname> and B<align>.
+
+=item B<esc_2253>
+
+escape the "special" characters required by RFC2253 in a field That is
+B<,+"E<lt>E<gt>;>. Additionally B<#> is escaped at the beginning of a string
+and a space character at the beginning or end of a string.
+
+=item B<esc_ctrl>
+
+escape control characters. That is those with ASCII values less than
+0x20 (space) and the delete (0x7f) character. They are escaped using the
+RFC2253 \XX notation (where XX are two hex digits representing the
+character value).
+
+=item B<esc_msb>
+
+escape characters with the MSB set, that is with ASCII values larger than
+127.
+
+=item B<use_quote>
+
+escapes some characters by surrounding the whole string with B<"> characters,
+without the option all escaping is done with the B<\> character.
+
+=item B<utf8>
+
+convert all strings to UTF8 format first. This is required by RFC2253. If
+you are lucky enough to have a UTF8 compatible terminal then the use
+of this option (and B<not> setting B<esc_msb>) may result in the correct
+display of multibyte (international) characters. Is this option is not
+present then multibyte characters larger than 0xff will be represented
+using the format \UXXXX for 16 bits and \WXXXXXXXX for 32 bits.
+Also if this option is off any UTF8Strings will be converted to their
+character form first.
+
+=item B<no_type>
+
+this option does not attempt to interpret multibyte characters in any
+way. That is their content octets are merely dumped as though one octet
+represents each character. This is useful for diagnostic purposes but
+will result in rather odd looking output.
+
+=item B<show_type>
+
+show the type of the ASN1 character string. The type precedes the
+field contents. For example "BMPSTRING: Hello World".
+
+=item B<dump_der>
+
+when this option is set any fields that need to be hexdumped will
+be dumped using the DER encoding of the field. Otherwise just the
+content octets will be displayed. Both options use the RFC2253
+B<#XXXX...> format.
+
+=item B<dump_nostr>
+
+dump non character string types (for example OCTET STRING) if this
+option is not set then non character string types will be displayed
+as though each content octet represents a single character.
+
+=item B<dump_all>
+
+dump all fields. This option when used with B<dump_der> allows the
+DER encoding of the structure to be unambiguously determined.
+
+=item B<dump_unknown>
+
+dump any field whose OID is not recognised by OpenSSL.
+
+=item B<sep_comma_plus>, B<sep_comma_plus_space>, B<sep_semi_plus_space>,
+B<sep_multiline>
+
+these options determine the field separators. The first character is
+between RDNs and the second between multiple AVAs (multiple AVAs are
+very rare and their use is discouraged). The options ending in
+"space" additionally place a space after the separator to make it
+more readable. The B<sep_multiline> uses a linefeed character for
+the RDN separator and a spaced B<+> for the AVA separator. It also
+indents the fields by four characters.
+
+=item B<dn_rev>
+
+reverse the fields of the DN. This is required by RFC2253. As a side
+effect this also reverses the order of multiple AVAs but this is
+permissible.
+
+=item B<nofname>, B<sname>, B<lname>, B<oid>
+
+these options alter how the field name is displayed. B<nofname> does
+not display the field at all. B<sname> uses the "short name" form
+(CN for commonName for example). B<lname> uses the long form.
+B<oid> represents the OID in numerical form and is useful for
+diagnostic purpose.
+
+=item B<align>
+
+align field values for a more readable output. Only usable with
+B<sep_multiline>.
+
+=item B<space_eq>
+
+places spaces round the B<=> character which follows the field
+name.
+
+=back
+
+=head2 TEXT OPTIONS
+
+As well as customising the name output format, it is also possible to
+customise the actual fields printed using the B<certopt> options when
+the B<text> option is present. The default behaviour is to print all fields.
+
+=over 4
+
+=item B<compatible>
+
+use the old format. This is equivalent to specifying no output options at all.
+
+=item B<no_header>
+
+don't print header information: that is the lines saying "Certificate" and "Data".
+
+=item B<no_version>
+
+don't print out the version number.
+
+=item B<no_serial>
+
+don't print out the serial number.
+
+=item B<no_signame>
+
+don't print out the signature algorithm used.
+
+=item B<no_validity>
+
+don't print the validity, that is the B<notBefore> and B<notAfter> fields.
+
+=item B<no_subject>
+
+don't print out the subject name.
+
+=item B<no_issuer>
+
+don't print out the issuer name.
+
+=item B<no_pubkey>
+
+don't print out the public key.
+
+=item B<no_sigdump>
+
+don't give a hexadecimal dump of the certificate signature.
+
+=item B<no_aux>
+
+don't print out certificate trust information.
+
+=item B<no_extensions>
+
+don't print out any X509V3 extensions.
+
+=item B<ext_default>
+
+retain default extension behaviour: attempt to print out unsupported certificate extensions.
+
+=item B<ext_error>
+
+print an error message for unsupported certificate extensions.
+
+=item B<ext_parse>
+
+ASN1 parse unsupported extensions.
+
+=item B<ext_dump>
+
+hex dump unsupported extensions.
+
+=item B<ca_default>
+
+the value used by the B<ca> utility, equivalent to B<no_issuer>, B<no_pubkey>, B<no_header>,
+B<no_version>, B<no_sigdump> and B<no_signame>.
+
+=back
+
+=head1 EXAMPLES
+
+Note: in these examples the '\' means the example should be all on one
+line.
+
+Display the contents of a certificate:
+
+ openssl x509 -in cert.pem -noout -text
+
+Display the certificate serial number:
+
+ openssl x509 -in cert.pem -noout -serial
+
+Display the certificate subject name:
+
+ openssl x509 -in cert.pem -noout -subject
+
+Display the certificate subject name in RFC2253 form:
+
+ openssl x509 -in cert.pem -noout -subject -nameopt RFC2253
+
+Display the certificate subject name in oneline form on a terminal
+supporting UTF8:
+
+ openssl x509 -in cert.pem -noout -subject -nameopt oneline,-esc_msb
+
+Display the certificate MD5 fingerprint:
+
+ openssl x509 -in cert.pem -noout -fingerprint
+
+Display the certificate SHA1 fingerprint:
+
+ openssl x509 -sha1 -in cert.pem -noout -fingerprint
+
+Convert a certificate from PEM to DER format:
+
+ openssl x509 -in cert.pem -inform PEM -out cert.der -outform DER
+
+Convert a certificate to a certificate request:
+
+ openssl x509 -x509toreq -in cert.pem -out req.pem -signkey key.pem
+
+Convert a certificate request into a self signed certificate using
+extensions for a CA:
+
+ openssl x509 -req -in careq.pem -extfile openssl.cnf -extensions v3_ca \
+       -signkey key.pem -out cacert.pem
+
+Sign a certificate request using the CA certificate above and add user
+certificate extensions:
+
+ openssl x509 -req -in req.pem -extfile openssl.cnf -extensions v3_usr \
+       -CA cacert.pem -CAkey key.pem -CAcreateserial
+
+
+Set a certificate to be trusted for SSL client use and change set its alias to
+"Steve's Class 1 CA"
+
+ openssl x509 -in cert.pem -addtrust clientAuth \
+       -setalias "Steve's Class 1 CA" -out trust.pem
+
+=head1 NOTES
+
+The PEM format uses the header and footer lines:
+
+ -----BEGIN CERTIFICATE-----
+ -----END CERTIFICATE-----
+
+it will also handle files containing:
+
+ -----BEGIN X509 CERTIFICATE-----
+ -----END X509 CERTIFICATE-----
+
+Trusted certificates have the lines
+
+ -----BEGIN TRUSTED CERTIFICATE-----
+ -----END TRUSTED CERTIFICATE-----
+
+The conversion to UTF8 format used with the name options assumes that
+T61Strings use the ISO8859-1 character set. This is wrong but Netscape
+and MSIE do this as do many certificates. So although this is incorrect
+it is more likely to display the majority of certificates correctly.
+
+The B<-fingerprint> option takes the digest of the DER encoded certificate.
+This is commonly called a "fingerprint". Because of the nature of message
+digests the fingerprint of a certificate is unique to that certificate and
+two certificates with the same fingerprint can be considered to be the same.
+
+The Netscape fingerprint uses MD5 whereas MSIE uses SHA1.
+
+The B<-email> option searches the subject name and the subject alternative
+name extension. Only unique email addresses will be printed out: it will
+not print the same address more than once.
+
+=head1 CERTIFICATE EXTENSIONS
+
+The B<-purpose> option checks the certificate extensions and determines
+what the certificate can be used for. The actual checks done are rather
+complex and include various hacks and workarounds to handle broken
+certificates and software.
+
+The same code is used when verifying untrusted certificates in chains
+so this section is useful if a chain is rejected by the verify code.
+
+The basicConstraints extension CA flag is used to determine whether the
+certificate can be used as a CA. If the CA flag is true then it is a CA,
+if the CA flag is false then it is not a CA. B<All> CAs should have the
+CA flag set to true.
+
+If the basicConstraints extension is absent then the certificate is
+considered to be a "possible CA" other extensions are checked according
+to the intended use of the certificate. A warning is given in this case
+because the certificate should really not be regarded as a CA: however
+it is allowed to be a CA to work around some broken software.
+
+If the certificate is a V1 certificate (and thus has no extensions) and
+it is self signed it is also assumed to be a CA but a warning is again
+given: this is to work around the problem of Verisign roots which are V1
+self signed certificates.
+
+If the keyUsage extension is present then additional restraints are
+made on the uses of the certificate. A CA certificate B<must> have the
+keyCertSign bit set if the keyUsage extension is present.
+
+The extended key usage extension places additional restrictions on the
+certificate uses. If this extension is present (whether critical or not)
+the key can only be used for the purposes specified.
+
+A complete description of each test is given below. The comments about
+basicConstraints and keyUsage and V1 certificates above apply to B<all>
+CA certificates.
+
+
+=over 4
+
+=item B<SSL Client>
+
+The extended key usage extension must be absent or include the "web client
+authentication" OID.  keyUsage must be absent or it must have the
+digitalSignature bit set. Netscape certificate type must be absent or it must
+have the SSL client bit set.
+
+=item B<SSL Client CA>
+
+The extended key usage extension must be absent or include the "web client
+authentication" OID. Netscape certificate type must be absent or it must have
+the SSL CA bit set: this is used as a work around if the basicConstraints
+extension is absent.
+
+=item B<SSL Server>
+
+The extended key usage extension must be absent or include the "web server
+authentication" and/or one of the SGC OIDs.  keyUsage must be absent or it
+must have the digitalSignature, the keyEncipherment set or both bits set.
+Netscape certificate type must be absent or have the SSL server bit set.
+
+=item B<SSL Server CA>
+
+The extended key usage extension must be absent or include the "web server
+authentication" and/or one of the SGC OIDs.  Netscape certificate type must
+be absent or the SSL CA bit must be set: this is used as a work around if the
+basicConstraints extension is absent.
+
+=item B<Netscape SSL Server>
+
+For Netscape SSL clients to connect to an SSL server it must have the
+keyEncipherment bit set if the keyUsage extension is present. This isn't
+always valid because some cipher suites use the key for digital signing.
+Otherwise it is the same as a normal SSL server.
+
+=item B<Common S/MIME Client Tests>
+
+The extended key usage extension must be absent or include the "email
+protection" OID. Netscape certificate type must be absent or should have the
+S/MIME bit set. If the S/MIME bit is not set in netscape certificate type
+then the SSL client bit is tolerated as an alternative but a warning is shown:
+this is because some Verisign certificates don't set the S/MIME bit.
+
+=item B<S/MIME Signing>
+
+In addition to the common S/MIME client tests the digitalSignature bit must
+be set if the keyUsage extension is present.
+
+=item B<S/MIME Encryption>
+
+In addition to the common S/MIME tests the keyEncipherment bit must be set
+if the keyUsage extension is present.
+
+=item B<S/MIME CA>
+
+The extended key usage extension must be absent or include the "email
+protection" OID. Netscape certificate type must be absent or must have the
+S/MIME CA bit set: this is used as a work around if the basicConstraints
+extension is absent. 
+
+=item B<CRL Signing>
+
+The keyUsage extension must be absent or it must have the CRL signing bit
+set.
+
+=item B<CRL Signing CA>
+
+The normal CA tests apply. Except in this case the basicConstraints extension
+must be present.
+
+=back
+
+=head1 BUGS
+
+Extensions in certificates are not transferred to certificate requests and
+vice versa.
+
+It is possible to produce invalid certificates or requests by specifying the
+wrong private key or using inconsistent options in some cases: these should
+be checked.
+
+There should be options to explicitly set such things as start and end
+dates rather than an offset from the current time.
+
+The code to implement the verify behaviour described in the B<TRUST SETTINGS>
+is currently being developed. It thus describes the intended behaviour rather
+than the current behaviour. It is hoped that it will represent reality in
+OpenSSL 0.9.5 and later.
+
+=head1 SEE ALSO
+
+L<req(1)|req(1)>, L<ca(1)|ca(1)>, L<genrsa(1)|genrsa(1)>,
+L<gendsa(1)|gendsa(1)>, L<verify(1)|verify(1)>,
+L<x509v3_config(5)|x509v3_config(5)> 
+
+=head1 HISTORY
+
+Before OpenSSL 0.9.8, the default digest for RSA keys was MD5.
+
+The hash algorithm used in the B<-subject_hash> and B<-issuer_hash> options
+before OpenSSL 1.0.0 was based on the deprecated MD5 algorithm and the encoding
+of the distinguished name. In OpenSSL 1.0.0 and later it is based on a
+canonical version of the DN using SHA1. This means that any directories using
+the old form must have their links rebuilt using B<c_rehash> or similar. 
+
+=cut
diff --git a/deps/openssl/openssl/doc/apps/x509v3_config.pod b/deps/openssl/openssl/doc/apps/x509v3_config.pod
new file mode 100644 (file)
index 0000000..0450067
--- /dev/null
@@ -0,0 +1,529 @@
+=pod
+
+=for comment openssl_manual_section:5
+
+=head1 NAME
+
+x509v3_config - X509 V3 certificate extension configuration format
+
+=head1 DESCRIPTION
+
+Several of the OpenSSL utilities can add extensions to a certificate or
+certificate request based on the contents of a configuration file.
+
+Typically the application will contain an option to point to an extension
+section. Each line of the extension section takes the form:
+
+ extension_name=[critical,] extension_options
+
+If B<critical> is present then the extension will be critical.
+
+The format of B<extension_options> depends on the value of B<extension_name>.
+
+There are four main types of extension: I<string> extensions, I<multi-valued>
+extensions, I<raw> and I<arbitrary> extensions.
+
+String extensions simply have a string which contains either the value itself
+or how it is obtained.
+
+For example:
+
+ nsComment="This is a Comment"
+
+Multi-valued extensions have a short form and a long form. The short form
+is a list of names and values:
+
+ basicConstraints=critical,CA:true,pathlen:1
+
+The long form allows the values to be placed in a separate section:
+
+ basicConstraints=critical,@bs_section
+
+ [bs_section]
+
+ CA=true
+ pathlen=1
+
+Both forms are equivalent.
+
+The syntax of raw extensions is governed by the extension code: it can
+for example contain data in multiple sections. The correct syntax to
+use is defined by the extension code itself: check out the certificate
+policies extension for an example.
+
+If an extension type is unsupported then the I<arbitrary> extension syntax
+must be used, see the L<ARBITRARY EXTENSIONS|/"ARBITRARY EXTENSIONS"> section for more details.
+
+=head1 STANDARD EXTENSIONS
+
+The following sections describe each supported extension in detail.
+
+=head2 Basic Constraints.
+
+This is a multi valued extension which indicates whether a certificate is
+a CA certificate. The first (mandatory) name is B<CA> followed by B<TRUE> or
+B<FALSE>. If B<CA> is B<TRUE> then an optional B<pathlen> name followed by an
+non-negative value can be included.
+
+For example:
+
+ basicConstraints=CA:TRUE
+
+ basicConstraints=CA:FALSE
+
+ basicConstraints=critical,CA:TRUE, pathlen:0
+
+A CA certificate B<must> include the basicConstraints value with the CA field
+set to TRUE. An end user certificate must either set CA to FALSE or exclude the
+extension entirely. Some software may require the inclusion of basicConstraints
+with CA set to FALSE for end entity certificates.
+
+The pathlen parameter indicates the maximum number of CAs that can appear
+below this one in a chain. So if you have a CA with a pathlen of zero it can
+only be used to sign end user certificates and not further CAs.
+
+
+=head2 Key Usage.
+
+Key usage is a multi valued extension consisting of a list of names of the
+permitted key usages.
+
+The supporte names are: digitalSignature, nonRepudiation, keyEncipherment,
+dataEncipherment, keyAgreement, keyCertSign, cRLSign, encipherOnly
+and decipherOnly.
+
+Examples:
+
+ keyUsage=digitalSignature, nonRepudiation
+
+ keyUsage=critical, keyCertSign
+
+
+=head2 Extended Key Usage.
+
+This extensions consists of a list of usages indicating purposes for which
+the certificate public key can be used for,
+
+These can either be object short names of the dotted numerical form of OIDs.
+While any OID can be used only certain values make sense. In particular the
+following PKIX, NS and MS values are meaningful:
+
+ Value                 Meaning
+ -----                 -------
+ serverAuth            SSL/TLS Web Server Authentication.
+ clientAuth            SSL/TLS Web Client Authentication.
+ codeSigning           Code signing.
+ emailProtection       E-mail Protection (S/MIME).
+ timeStamping          Trusted Timestamping
+ msCodeInd             Microsoft Individual Code Signing (authenticode)
+ msCodeCom             Microsoft Commercial Code Signing (authenticode)
+ msCTLSign             Microsoft Trust List Signing
+ msSGC                 Microsoft Server Gated Crypto
+ msEFS                 Microsoft Encrypted File System
+ nsSGC                 Netscape Server Gated Crypto
+
+Examples:
+
+ extendedKeyUsage=critical,codeSigning,1.2.3.4
+ extendedKeyUsage=nsSGC,msSGC
+
+
+=head2 Subject Key Identifier.
+
+This is really a string extension and can take two possible values. Either
+the word B<hash> which will automatically follow the guidelines in RFC3280
+or a hex string giving the extension value to include. The use of the hex
+string is strongly discouraged.
+
+Example:
+
+ subjectKeyIdentifier=hash
+
+
+=head2 Authority Key Identifier.
+
+The authority key identifier extension permits two options. keyid and issuer:
+both can take the optional value "always".
+
+If the keyid option is present an attempt is made to copy the subject key
+identifier from the parent certificate. If the value "always" is present
+then an error is returned if the option fails.
+
+The issuer option copies the issuer and serial number from the issuer
+certificate. This will only be done if the keyid option fails or
+is not included unless the "always" flag will always include the value.
+
+Example:
+
+ authorityKeyIdentifier=keyid,issuer
+
+
+=head2 Subject Alternative Name.
+
+The subject alternative name extension allows various literal values to be
+included in the configuration file. These include B<email> (an email address)
+B<URI> a uniform resource indicator, B<DNS> (a DNS domain name), B<RID> (a
+registered ID: OBJECT IDENTIFIER), B<IP> (an IP address), B<dirName>
+(a distinguished name) and otherName.
+
+The email option include a special 'copy' value. This will automatically
+include and email addresses contained in the certificate subject name in
+the extension.
+
+The IP address used in the B<IP> options can be in either IPv4 or IPv6 format.
+
+The value of B<dirName> should point to a section containing the distinguished
+name to use as a set of name value pairs. Multi values AVAs can be formed by
+preceeding the name with a B<+> character.
+
+otherName can include arbitrary data associated with an OID: the value
+should be the OID followed by a semicolon and the content in standard
+L<ASN1_generate_nconf(3)|ASN1_generate_nconf(3)> format.
+
+Examples:
+
+ subjectAltName=email:copy,email:my@other.address,URI:http://my.url.here/
+ subjectAltName=IP:192.168.7.1
+ subjectAltName=IP:13::17
+ subjectAltName=email:my@other.address,RID:1.2.3.4
+ subjectAltName=otherName:1.2.3.4;UTF8:some other identifier
+
+ subjectAltName=dirName:dir_sect
+
+ [dir_sect]
+ C=UK
+ O=My Organization
+ OU=My Unit
+ CN=My Name
+
+
+=head2 Issuer Alternative Name.
+
+The issuer alternative name option supports all the literal options of
+subject alternative name. It does B<not> support the email:copy option because
+that would not make sense. It does support an additional issuer:copy option
+that will copy all the subject alternative name values from the issuer 
+certificate (if possible).
+
+Example:
+
+ issuserAltName = issuer:copy
+
+
+=head2 Authority Info Access.
+
+The authority information access extension gives details about how to access
+certain information relating to the CA. Its syntax is accessOID;location
+where I<location> has the same syntax as subject alternative name (except
+that email:copy is not supported). accessOID can be any valid OID but only
+certain values are meaningful, for example OCSP and caIssuers.
+
+Example:
+
+ authorityInfoAccess = OCSP;URI:http://ocsp.my.host/
+ authorityInfoAccess = caIssuers;URI:http://my.ca/ca.html
+
+
+=head2 CRL distribution points.
+
+This is a multi-valued extension whose options can be either in name:value pair
+using the same form as subject alternative name or a single value representing
+a section name containing all the distribution point fields.
+
+For a name:value pair a new DistributionPoint with the fullName field set to
+the given value both the cRLissuer and reasons fields are omitted in this case.
+
+In the single option case the section indicated contains values for each
+field. In this section:
+
+If the name is "fullname" the value field should contain the full name
+of the distribution point in the same format as subject alternative name.
+
+If the name is "relativename" then the value field should contain a section
+name whose contents represent a DN fragment to be placed in this field.
+
+The name "CRLIssuer" if present should contain a value for this field in
+subject alternative name format.
+
+If the name is "reasons" the value field should consist of a comma
+separated field containing the reasons. Valid reasons are: "keyCompromise",
+"CACompromise", "affiliationChanged", "superseded", "cessationOfOperation",
+"certificateHold", "privilegeWithdrawn" and "AACompromise".
+
+
+Simple examples:
+
+ crlDistributionPoints=URI:http://myhost.com/myca.crl
+ crlDistributionPoints=URI:http://my.com/my.crl,URI:http://oth.com/my.crl
+
+Full distribution point example:
+
+ crlDistributionPoints=crldp1_section
+
+ [crldp1_section]
+
+ fullname=URI:http://myhost.com/myca.crl
+ CRLissuer=dirName:issuer_sect
+ reasons=keyCompromise, CACompromise
+
+ [issuer_sect]
+ C=UK
+ O=Organisation
+ CN=Some Name
+
+=head2 Issuing Distribution Point
+
+This extension should only appear in CRLs. It is a multi valued extension
+whose syntax is similar to the "section" pointed to by the CRL distribution
+points extension with a few differences.
+
+The names "reasons" and "CRLissuer" are not recognized.
+
+The name "onlysomereasons" is accepted which sets this field. The value is
+in the same format as the CRL distribution point "reasons" field.
+
+The names "onlyuser", "onlyCA", "onlyAA" and "indirectCRL" are also accepted
+the values should be a boolean value (TRUE or FALSE) to indicate the value of
+the corresponding field.
+
+Example:
+
+ issuingDistributionPoint=critical, @idp_section
+
+ [idp_section]
+
+ fullname=URI:http://myhost.com/myca.crl
+ indirectCRL=TRUE
+ onlysomereasons=keyCompromise, CACompromise
+
+ [issuer_sect]
+ C=UK
+ O=Organisation
+ CN=Some Name
+
+=head2 Certificate Policies.
+
+This is a I<raw> extension. All the fields of this extension can be set by
+using the appropriate syntax.
+
+If you follow the PKIX recommendations and just using one OID then you just
+include the value of that OID. Multiple OIDs can be set separated by commas,
+for example:
+
+ certificatePolicies= 1.2.4.5, 1.1.3.4
+
+If you wish to include qualifiers then the policy OID and qualifiers need to
+be specified in a separate section: this is done by using the @section syntax
+instead of a literal OID value.
+
+The section referred to must include the policy OID using the name
+policyIdentifier, cPSuri qualifiers can be included using the syntax:
+
+ CPS.nnn=value
+
+userNotice qualifiers can be set using the syntax:
+
+ userNotice.nnn=@notice
+
+The value of the userNotice qualifier is specified in the relevant section.
+This section can include explicitText, organization and noticeNumbers
+options. explicitText and organization are text strings, noticeNumbers is a
+comma separated list of numbers. The organization and noticeNumbers options
+(if included) must BOTH be present. If you use the userNotice option with IE5
+then you need the 'ia5org' option at the top level to modify the encoding:
+otherwise it will not be interpreted properly.
+
+Example:
+
+ certificatePolicies=ia5org,1.2.3.4,1.5.6.7.8,@polsect
+
+ [polsect]
+
+ policyIdentifier = 1.3.5.8
+ CPS.1="http://my.host.name/"
+ CPS.2="http://my.your.name/"
+ userNotice.1=@notice
+
+ [notice]
+
+ explicitText="Explicit Text Here"
+ organization="Organisation Name"
+ noticeNumbers=1,2,3,4
+
+The B<ia5org> option changes the type of the I<organization> field. In RFC2459
+it can only be of type DisplayText. In RFC3280 IA5Strring is also permissible.
+Some software (for example some versions of MSIE) may require ia5org.
+
+=head2 Policy Constraints
+
+This is a multi-valued extension which consisting of the names
+B<requireExplicitPolicy> or B<inhibitPolicyMapping> and a non negative intger
+value. At least one component must be present.
+
+Example:
+
+ policyConstraints = requireExplicitPolicy:3
+
+
+=head2 Inhibit Any Policy
+
+This is a string extension whose value must be a non negative integer.
+
+Example:
+
+ inhibitAnyPolicy = 2
+
+
+=head2 Name Constraints
+
+The name constraints extension is a multi-valued extension. The name should
+begin with the word B<permitted> or B<excluded> followed by a B<;>. The rest of
+the name and the value follows the syntax of subjectAltName except email:copy
+is not supported and the B<IP> form should consist of an IP addresses and 
+subnet mask separated by a B</>.
+
+Examples:
+
+ nameConstraints=permitted;IP:192.168.0.0/255.255.0.0
+
+ nameConstraints=permitted;email:.somedomain.com
+
+ nameConstraints=excluded;email:.com
+issuingDistributionPoint = idp_section
+
+=head2 OCSP No Check
+
+The OCSP No Check extension is a string extension but its value is ignored.
+
+Example:
+
+ noCheck = ignored
+
+
+=head1 DEPRECATED EXTENSIONS
+
+The following extensions are non standard, Netscape specific and largely
+obsolete. Their use in new applications is discouraged.
+
+=head2 Netscape String extensions.
+
+Netscape Comment (B<nsComment>) is a string extension containing a comment
+which will be displayed when the certificate is viewed in some browsers.
+
+Example:
+
+ nsComment = "Some Random Comment"
+
+Other supported extensions in this category are: B<nsBaseUrl>,
+B<nsRevocationUrl>, B<nsCaRevocationUrl>, B<nsRenewalUrl>, B<nsCaPolicyUrl>
+and B<nsSslServerName>.
+
+
+=head2 Netscape Certificate Type
+
+This is a multi-valued extensions which consists of a list of flags to be
+included. It was used to indicate the purposes for which a certificate could
+be used. The basicConstraints, keyUsage and extended key usage extensions are
+now used instead.
+
+Acceptable values for nsCertType are: B<client>, B<server>, B<email>,
+B<objsign>, B<reserved>, B<sslCA>, B<emailCA>, B<objCA>.
+
+
+=head1 ARBITRARY EXTENSIONS
+
+If an extension is not supported by the OpenSSL code then it must be encoded
+using the arbitrary extension format. It is also possible to use the arbitrary
+format for supported extensions. Extreme care should be taken to ensure that
+the data is formatted correctly for the given extension type.
+
+There are two ways to encode arbitrary extensions.
+
+The first way is to use the word ASN1 followed by the extension content
+using the same syntax as L<ASN1_generate_nconf(3)|ASN1_generate_nconf(3)>.
+For example:
+
+ 1.2.3.4=critical,ASN1:UTF8String:Some random data
+
+ 1.2.3.4=ASN1:SEQUENCE:seq_sect
+
+ [seq_sect]
+
+ field1 = UTF8:field1
+ field2 = UTF8:field2
+
+It is also possible to use the word DER to include the raw encoded data in any
+extension.
+
+ 1.2.3.4=critical,DER:01:02:03:04
+ 1.2.3.4=DER:01020304
+
+The value following DER is a hex dump of the DER encoding of the extension
+Any extension can be placed in this form to override the default behaviour.
+For example:
+
+ basicConstraints=critical,DER:00:01:02:03
+
+=head1 WARNING
+
+There is no guarantee that a specific implementation will process a given
+extension. It may therefore be sometimes possible to use certificates for
+purposes prohibited by their extensions because a specific application does
+not recognize or honour the values of the relevant extensions.
+
+The DER and ASN1 options should be used with caution. It is possible to create
+totally invalid extensions if they are not used carefully.
+
+
+=head1 NOTES
+
+If an extension is multi-value and a field value must contain a comma the long
+form must be used otherwise the comma would be misinterpreted as a field
+separator. For example:
+
+ subjectAltName=URI:ldap://somehost.com/CN=foo,OU=bar
+
+will produce an error but the equivalent form:
+
+ subjectAltName=@subject_alt_section
+
+ [subject_alt_section]
+ subjectAltName=URI:ldap://somehost.com/CN=foo,OU=bar
+
+is valid. 
+
+Due to the behaviour of the OpenSSL B<conf> library the same field name
+can only occur once in a section. This means that:
+
+ subjectAltName=@alt_section
+
+ [alt_section]
+
+ email=steve@here
+ email=steve@there
+
+will only recognize the last value. This can be worked around by using the form:
+
+ [alt_section]
+
+ email.1=steve@here
+ email.2=steve@there
+
+=head1 HISTORY
+
+The X509v3 extension code was first added to OpenSSL 0.9.2.
+
+Policy mappings, inhibit any policy and name constraints support was added in
+OpenSSL 0.9.8
+
+The B<directoryName> and B<otherName> option as well as the B<ASN1> option
+for arbitrary extensions was added in OpenSSL 0.9.8
+
+=head1 SEE ALSO
+
+L<req(1)|req(1)>, L<ca(1)|ca(1)>, L<x509(1)|x509(1)>,
+L<ASN1_generate_nconf(3)|ASN1_generate_nconf(3)>
+
+
+=cut
diff --git a/deps/openssl/openssl/doc/c-indentation.el b/deps/openssl/openssl/doc/c-indentation.el
new file mode 100644 (file)
index 0000000..90861d3
--- /dev/null
@@ -0,0 +1,45 @@
+; This Emacs Lisp file defines a C indentation style that closely
+; follows most aspects of the one that is used throughout SSLeay,
+; and hence in OpenSSL.
+; 
+; This definition is for the "CC mode" package, which is the default
+; mode for editing C source files in Emacs 20, not for the older
+; c-mode.el (which was the default in less recent releaes of Emacs 19).
+;
+; Copy the definition in your .emacs file or use M-x eval-buffer.
+; To activate this indentation style, visit a C file, type
+; M-x c-set-style <RET> (or C-c . for short), and enter "eay".
+; To toggle the auto-newline feature of CC mode, type C-c C-a.
+;
+; Apparently statement blocks that are not introduced by a statement
+; such as "if" and that are not the body of a function cannot
+; be handled too well by CC mode with this indentation style,
+; so you have to indent them manually (you can use C-q tab).
+; 
+; For suggesting improvements, please send e-mail to bodo@openssl.org.
+
+(c-add-style "eay"
+            '((c-basic-offset . 8)
+              (indent-tabs-mode . t)
+              (c-comment-only-line-offset . 0)
+              (c-hanging-braces-alist)
+              (c-offsets-alist . ((defun-open . +)
+                                  (defun-block-intro . 0)
+                                  (class-open . +)
+                                  (class-close . +)
+                                  (block-open . 0)
+                                  (block-close . 0)
+                                  (substatement-open . +)
+                                  (statement . 0)
+                                  (statement-block-intro . 0)
+                                  (statement-case-open . +)
+                                  (statement-case-intro . +)
+                                  (case-label . -)
+                                  (label . -)
+                                  (arglist-cont-nonempty . +)
+                                  (topmost-intro . -)
+                                  (brace-list-close . 0)
+                                  (brace-list-intro . 0)
+                                  (brace-list-open . +)
+                                  ))))
+
diff --git a/deps/openssl/openssl/doc/crypto/ASN1_OBJECT_new.pod b/deps/openssl/openssl/doc/crypto/ASN1_OBJECT_new.pod
new file mode 100644 (file)
index 0000000..9bae40f
--- /dev/null
@@ -0,0 +1,45 @@
+=pod
+
+=head1 NAME
+
+ASN1_OBJECT_new, ASN1_OBJECT_free, - object allocation functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/asn1.h>
+
+ ASN1_OBJECT *ASN1_OBJECT_new(void);
+ void ASN1_OBJECT_free(ASN1_OBJECT *a);
+
+=head1 DESCRIPTION
+
+The ASN1_OBJECT allocation routines, allocate and free an
+ASN1_OBJECT structure, which represents an ASN1 OBJECT IDENTIFIER.
+
+ASN1_OBJECT_new() allocates and initializes a ASN1_OBJECT structure.
+
+ASN1_OBJECT_free() frees up the B<ASN1_OBJECT> structure B<a>.
+
+=head1 NOTES
+
+Although ASN1_OBJECT_new() allocates a new ASN1_OBJECT structure it
+is almost never used in applications. The ASN1 object utility functions
+such as OBJ_nid2obj() are used instead.
+
+=head1 RETURN VALUES
+
+If the allocation fails, ASN1_OBJECT_new() returns B<NULL> and sets an error
+code that can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+Otherwise it returns a pointer to the newly allocated structure.
+
+ASN1_OBJECT_free() returns no value.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<d2i_ASN1_OBJECT(3)|d2i_ASN1_OBJECT(3)>
+
+=head1 HISTORY
+
+ASN1_OBJECT_new() and ASN1_OBJECT_free() are available in all versions of SSLeay and OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/ASN1_STRING_length.pod b/deps/openssl/openssl/doc/crypto/ASN1_STRING_length.pod
new file mode 100644 (file)
index 0000000..a08e9a0
--- /dev/null
@@ -0,0 +1,83 @@
+=pod
+
+=head1 NAME
+
+ASN1_STRING_dup, ASN1_STRING_cmp, ASN1_STRING_set, ASN1_STRING_length,
+ASN1_STRING_length_set, ASN1_STRING_type, ASN1_STRING_data -
+ASN1_STRING utility functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/asn1.h>
+
+ int ASN1_STRING_length(ASN1_STRING *x);
+ unsigned char * ASN1_STRING_data(ASN1_STRING *x);
+
+ ASN1_STRING * ASN1_STRING_dup(ASN1_STRING *a);
+
+ int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b);
+
+ int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len);
+
+ int ASN1_STRING_type(ASN1_STRING *x);
+
+ int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in);
+
+=head1 DESCRIPTION
+
+These functions allow an B<ASN1_STRING> structure to be manipulated.
+
+ASN1_STRING_length() returns the length of the content of B<x>.
+
+ASN1_STRING_data() returns an internal pointer to the data of B<x>.
+Since this is an internal pointer it should B<not> be freed or
+modified in any way.
+
+ASN1_STRING_dup() returns a copy of the structure B<a>.
+
+ASN1_STRING_cmp() compares B<a> and B<b> returning 0 if the two
+are identical. The string types and content are compared.
+
+ASN1_STRING_set() sets the data of string B<str> to the buffer
+B<data> or length B<len>. The supplied data is copied. If B<len>
+is -1 then the length is determined by strlen(data).
+
+ASN1_STRING_type() returns the type of B<x>, using standard constants
+such as B<V_ASN1_OCTET_STRING>.
+
+ASN1_STRING_to_UTF8() converts the string B<in> to UTF8 format, the
+converted data is allocated in a buffer in B<*out>. The length of
+B<out> is returned or a negative error code. The buffer B<*out>
+should be free using OPENSSL_free().
+
+=head1 NOTES
+
+Almost all ASN1 types in OpenSSL are represented as an B<ASN1_STRING>
+structure. Other types such as B<ASN1_OCTET_STRING> are simply typedefed
+to B<ASN1_STRING> and the functions call the B<ASN1_STRING> equivalents.
+B<ASN1_STRING> is also used for some B<CHOICE> types which consist
+entirely of primitive string types such as B<DirectoryString> and
+B<Time>.
+
+These functions should B<not> be used to examine or modify B<ASN1_INTEGER>
+or B<ASN1_ENUMERATED> types: the relevant B<INTEGER> or B<ENUMERATED>
+utility functions should be used instead.
+
+In general it cannot be assumed that the data returned by ASN1_STRING_data()
+is null terminated or does not contain embedded nulls. The actual format
+of the data will depend on the actual string type itself: for example
+for and IA5String the data will be ASCII, for a BMPString two bytes per
+character in big endian format, UTF8String will be in UTF8 format.
+
+Similar care should be take to ensure the data is in the correct format
+when calling ASN1_STRING_set().
+
+=head1 RETURN VALUES
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>
+
+=head1 HISTORY
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/ASN1_STRING_new.pod b/deps/openssl/openssl/doc/crypto/ASN1_STRING_new.pod
new file mode 100644 (file)
index 0000000..8ac2a03
--- /dev/null
@@ -0,0 +1,46 @@
+=pod
+
+=head1 NAME
+
+ASN1_STRING_new, ASN1_STRING_type_new, ASN1_STRING_free -
+ASN1_STRING allocation functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/asn1.h>
+
+ ASN1_STRING * ASN1_STRING_new(void);
+ ASN1_STRING * ASN1_STRING_type_new(int type);
+ void ASN1_STRING_free(ASN1_STRING *a);
+
+=head1 DESCRIPTION
+
+ASN1_STRING_new() returns an allocated B<ASN1_STRING> structure. Its type
+is undefined.
+
+ASN1_STRING_type_new() returns an allocated B<ASN1_STRING> structure of
+type B<type>.
+
+ASN1_STRING_free() frees up B<a>.
+
+=head1 NOTES
+
+Other string types call the B<ASN1_STRING> functions. For example
+ASN1_OCTET_STRING_new() calls ASN1_STRING_type(V_ASN1_OCTET_STRING).
+
+=head1 RETURN VALUES
+
+ASN1_STRING_new() and ASN1_STRING_type_new() return a valid
+ASN1_STRING structure or B<NULL> if an error occurred.
+
+ASN1_STRING_free() does not return a value.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>
+
+=head1 HISTORY
+
+TBA
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/ASN1_STRING_print_ex.pod b/deps/openssl/openssl/doc/crypto/ASN1_STRING_print_ex.pod
new file mode 100644 (file)
index 0000000..3891b88
--- /dev/null
@@ -0,0 +1,96 @@
+=pod
+
+=head1 NAME
+
+ASN1_STRING_print_ex, ASN1_STRING_print_ex_fp - ASN1_STRING output routines.
+
+=head1 SYNOPSIS
+
+ #include <openssl/asn1.h>
+
+ int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags);
+ int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags);
+ int ASN1_STRING_print(BIO *out, ASN1_STRING *str);
+
+
+=head1 DESCRIPTION
+
+These functions output an B<ASN1_STRING> structure. B<ASN1_STRING> is used to
+represent all the ASN1 string types.
+
+ASN1_STRING_print_ex() outputs B<str> to B<out>, the format is determined by
+the options B<flags>. ASN1_STRING_print_ex_fp() is identical except it outputs
+to B<fp> instead.
+
+ASN1_STRING_print() prints B<str> to B<out> but using a different format to
+ASN1_STRING_print_ex(). It replaces unprintable characters (other than CR, LF)
+with '.'.
+
+=head1 NOTES
+
+ASN1_STRING_print() is a legacy function which should be avoided in new applications.
+
+Although there are a large number of options frequently B<ASN1_STRFLGS_RFC2253> is 
+suitable, or on UTF8 terminals B<ASN1_STRFLGS_RFC2253 & ~ASN1_STRFLGS_ESC_MSB>.
+
+The complete set of supported options for B<flags> is listed below.
+
+Various characters can be escaped. If B<ASN1_STRFLGS_ESC_2253> is set the characters
+determined by RFC2253 are escaped. If B<ASN1_STRFLGS_ESC_CTRL> is set control
+characters are escaped. If B<ASN1_STRFLGS_ESC_MSB> is set characters with the
+MSB set are escaped: this option should B<not> be used if the terminal correctly
+interprets UTF8 sequences.
+
+Escaping takes several forms.
+
+If the character being escaped is a 16 bit character then the form "\UXXXX" is used
+using exactly four characters for the hex representation. If it is 32 bits then
+"\WXXXXXXXX" is used using eight characters of its hex representation. These forms
+will only be used if UTF8 conversion is not set (see below).
+
+Printable characters are normally escaped using the backslash '\' character. If
+B<ASN1_STRFLGS_ESC_QUOTE> is set then the whole string is instead surrounded by
+double quote characters: this is arguably more readable than the backslash
+notation. Other characters use the "\XX" using exactly two characters of the hex
+representation.
+
+If B<ASN1_STRFLGS_UTF8_CONVERT> is set then characters are converted to UTF8
+format first. If the terminal supports the display of UTF8 sequences then this
+option will correctly display multi byte characters.
+
+If B<ASN1_STRFLGS_IGNORE_TYPE> is set then the string type is not interpreted at
+all: everything is assumed to be one byte per character. This is primarily for
+debugging purposes and can result in confusing output in multi character strings.
+
+If B<ASN1_STRFLGS_SHOW_TYPE> is set then the string type itself is printed out
+before its value (for example "BMPSTRING"), this actually uses ASN1_tag2str().
+
+The content of a string instead of being interpreted can be "dumped": this just
+outputs the value of the string using the form #XXXX using hex format for each
+octet.
+
+If B<ASN1_STRFLGS_DUMP_ALL> is set then any type is dumped.
+
+Normally non character string types (such as OCTET STRING) are assumed to be
+one byte per character, if B<ASN1_STRFLGS_DUMP_UNKNOWN> is set then they will
+be dumped instead.
+
+When a type is dumped normally just the content octets are printed, if 
+B<ASN1_STRFLGS_DUMP_DER> is set then the complete encoding is dumped
+instead (including tag and length octets).
+
+B<ASN1_STRFLGS_RFC2253> includes all the flags required by RFC2253. It is
+equivalent to:
+ ASN1_STRFLGS_ESC_2253 | ASN1_STRFLGS_ESC_CTRL | ASN1_STRFLGS_ESC_MSB |
+ ASN1_STRFLGS_UTF8_CONVERT | ASN1_STRFLGS_DUMP_UNKNOWN ASN1_STRFLGS_DUMP_DER
+
+=head1 SEE ALSO
+
+L<X509_NAME_print_ex(3)|X509_NAME_print_ex(3)>,
+L<ASN1_tag2str(3)|ASN1_tag2str(3)>
+
+=head1 HISTORY
+
+TBA
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/ASN1_generate_nconf.pod b/deps/openssl/openssl/doc/crypto/ASN1_generate_nconf.pod
new file mode 100644 (file)
index 0000000..542fd15
--- /dev/null
@@ -0,0 +1,265 @@
+=pod
+
+=head1 NAME
+
+ASN1_generate_nconf, ASN1_generate_v3 - ASN1 generation functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/asn1.h>
+
+ ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf);
+ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf);
+
+=head1 DESCRIPTION
+
+These functions generate the ASN1 encoding of a string
+in an B<ASN1_TYPE> structure.
+
+B<str> contains the string to encode B<nconf> or B<cnf> contains
+the optional configuration information where additional strings
+will be read from. B<nconf> will typically come from a config
+file wherease B<cnf> is obtained from an B<X509V3_CTX> structure
+which will typically be used by X509 v3 certificate extension
+functions. B<cnf> or B<nconf> can be set to B<NULL> if no additional
+configuration will be used.
+
+=head1 GENERATION STRING FORMAT
+
+The actual data encoded is determined by the string B<str> and
+the configuration information. The general format of the string
+is:
+
+=over 2
+
+=item B<[modifier,]type[:value]>
+
+=back
+
+That is zero or more comma separated modifiers followed by a type
+followed by an optional colon and a value. The formats of B<type>,
+B<value> and B<modifier> are explained below.
+
+=head2 SUPPORTED TYPES
+
+The supported types are listed below. Unless otherwise specified
+only the B<ASCII> format is permissible.
+
+=over 2
+
+=item B<BOOLEAN>, B<BOOL>
+
+This encodes a boolean type. The B<value> string is mandatory and
+should be B<TRUE> or B<FALSE>. Additionally B<TRUE>, B<true>, B<Y>,
+B<y>, B<YES>, B<yes>, B<FALSE>, B<false>, B<N>, B<n>, B<NO> and B<no>
+are acceptable. 
+
+=item B<NULL>
+
+Encode the B<NULL> type, the B<value> string must not be present.
+
+=item B<INTEGER>, B<INT>
+
+Encodes an ASN1 B<INTEGER> type. The B<value> string represents
+the value of the integer, it can be preceeded by a minus sign and
+is normally interpreted as a decimal value unless the prefix B<0x>
+is included.
+
+=item B<ENUMERATED>, B<ENUM>
+
+Encodes the ASN1 B<ENUMERATED> type, it is otherwise identical to
+B<INTEGER>.
+
+=item B<OBJECT>, B<OID>
+
+Encodes an ASN1 B<OBJECT IDENTIFIER>, the B<value> string can be
+a short name, a long name or numerical format.
+
+=item B<UTCTIME>, B<UTC>
+
+Encodes an ASN1 B<UTCTime> structure, the value should be in
+the format B<YYMMDDHHMMSSZ>. 
+
+=item B<GENERALIZEDTIME>, B<GENTIME>
+
+Encodes an ASN1 B<GeneralizedTime> structure, the value should be in
+the format B<YYYYMMDDHHMMSSZ>. 
+
+=item B<OCTETSTRING>, B<OCT>
+
+Encodes an ASN1 B<OCTET STRING>. B<value> represents the contents
+of this structure, the format strings B<ASCII> and B<HEX> can be
+used to specify the format of B<value>.
+
+=item B<BITSTRING>, B<BITSTR>
+
+Encodes an ASN1 B<BIT STRING>. B<value> represents the contents
+of this structure, the format strings B<ASCII>, B<HEX> and B<BITLIST>
+can be used to specify the format of B<value>.
+
+If the format is anything other than B<BITLIST> the number of unused
+bits is set to zero.
+
+=item B<UNIVERSALSTRING>, B<UNIV>, B<IA5>, B<IA5STRING>, B<UTF8>,
+B<UTF8String>, B<BMP>, B<BMPSTRING>, B<VISIBLESTRING>,
+B<VISIBLE>, B<PRINTABLESTRING>, B<PRINTABLE>, B<T61>,
+B<T61STRING>, B<TELETEXSTRING>, B<GeneralString>, B<NUMERICSTRING>,
+B<NUMERIC>
+
+These encode the corresponding string types. B<value> represents the
+contents of this structure. The format can be B<ASCII> or B<UTF8>.
+
+=item B<SEQUENCE>, B<SEQ>, B<SET>
+
+Formats the result as an ASN1 B<SEQUENCE> or B<SET> type. B<value>
+should be a section name which will contain the contents. The
+field names in the section are ignored and the values are in the
+generated string format. If B<value> is absent then an empty SEQUENCE
+will be encoded.
+
+=back
+
+=head2 MODIFIERS
+
+Modifiers affect the following structure, they can be used to
+add EXPLICIT or IMPLICIT tagging, add wrappers or to change
+the string format of the final type and value. The supported
+formats are documented below.
+
+=over 2
+
+=item B<EXPLICIT>, B<EXP>
+
+Add an explicit tag to the following structure. This string
+should be followed by a colon and the tag value to use as a
+decimal value.
+
+By following the number with B<U>, B<A>, B<P> or B<C> UNIVERSAL,
+APPLICATION, PRIVATE or CONTEXT SPECIFIC tagging can be used,
+the default is CONTEXT SPECIFIC.
+
+=item B<IMPLICIT>, B<IMP>
+
+This is the same as B<EXPLICIT> except IMPLICIT tagging is used
+instead.
+
+=item B<OCTWRAP>, B<SEQWRAP>, B<SETWRAP>, B<BITWRAP>
+
+The following structure is surrounded by an OCTET STRING, a SEQUENCE,
+a SET or a BIT STRING respectively. For a BIT STRING the number of unused
+bits is set to zero.
+
+=item B<FORMAT>
+
+This specifies the format of the ultimate value. It should be followed
+by a colon and one of the strings B<ASCII>, B<UTF8>, B<HEX> or B<BITLIST>.
+
+If no format specifier is included then B<ASCII> is used. If B<UTF8> is
+specified then the value string must be a valid B<UTF8> string. For B<HEX> the
+output must be a set of hex digits. B<BITLIST> (which is only valid for a BIT
+STRING) is a comma separated list of the indices of the set bits, all other
+bits are zero.
+
+=back
+
+=head1 EXAMPLES
+
+A simple IA5String:
+
+ IA5STRING:Hello World
+
+An IA5String explicitly tagged:
+
+ EXPLICIT:0,IA5STRING:Hello World
+
+An IA5String explicitly tagged using APPLICATION tagging:
+
+ EXPLICIT:0A,IA5STRING:Hello World
+
+A BITSTRING with bits 1 and 5 set and all others zero:
+
+ FORMAT:BITLIST,BITSTRING:1,5
+
+A more complex example using a config file to produce a
+SEQUENCE consiting of a BOOL an OID and a UTF8String:
+
+ asn1 = SEQUENCE:seq_section
+
+ [seq_section]
+
+ field1 = BOOLEAN:TRUE
+ field2 = OID:commonName
+ field3 = UTF8:Third field
+
+This example produces an RSAPrivateKey structure, this is the
+key contained in the file client.pem in all OpenSSL distributions
+(note: the field names such as 'coeff' are ignored and are present just
+for clarity):
+
+ asn1=SEQUENCE:private_key
+ [private_key]
+ version=INTEGER:0
+
+ n=INTEGER:0xBB6FE79432CC6EA2D8F970675A5A87BFBE1AFF0BE63E879F2AFFB93644\
+ D4D2C6D000430DEC66ABF47829E74B8C5108623A1C0EE8BE217B3AD8D36D5EB4FCA1D9
+
+ e=INTEGER:0x010001
+
+ d=INTEGER:0x6F05EAD2F27FFAEC84BEC360C4B928FD5F3A9865D0FCAAD291E2A52F4A\
+ F810DC6373278C006A0ABBA27DC8C63BF97F7E666E27C5284D7D3B1FFFE16B7A87B51D
+
+ p=INTEGER:0xF3929B9435608F8A22C208D86795271D54EBDFB09DDEF539AB083DA912\
+ D4BD57
+
+ q=INTEGER:0xC50016F89DFF2561347ED1186A46E150E28BF2D0F539A1594BBD7FE467\
+ 46EC4F
+
+ exp1=INTEGER:0x9E7D4326C924AFC1DEA40B45650134966D6F9DFA3A7F9D698CD4ABEA\
+ 9C0A39B9
+
+ exp2=INTEGER:0xBA84003BB95355AFB7C50DF140C60513D0BA51D637272E355E397779\
+ E7B2458F
+
+ coeff=INTEGER:0x30B9E4F2AFA5AC679F920FC83F1F2DF1BAF1779CF989447FABC2F5\
+ 628657053A
+
+This example is the corresponding public key in a SubjectPublicKeyInfo
+structure:
+
+ # Start with a SEQUENCE
+ asn1=SEQUENCE:pubkeyinfo
+
+ # pubkeyinfo contains an algorithm identifier and the public key wrapped
+ # in a BIT STRING
+ [pubkeyinfo]
+ algorithm=SEQUENCE:rsa_alg
+ pubkey=BITWRAP,SEQUENCE:rsapubkey
+
+ # algorithm ID for RSA is just an OID and a NULL
+ [rsa_alg]
+ algorithm=OID:rsaEncryption
+ parameter=NULL
+
+ # Actual public key: modulus and exponent
+ [rsapubkey]
+ n=INTEGER:0xBB6FE79432CC6EA2D8F970675A5A87BFBE1AFF0BE63E879F2AFFB93644\
+ D4D2C6D000430DEC66ABF47829E74B8C5108623A1C0EE8BE217B3AD8D36D5EB4FCA1D9
+
+ e=INTEGER:0x010001
+
+=head1 RETURN VALUES
+
+ASN1_generate_nconf() and ASN1_generate_v3() return the encoded
+data as an B<ASN1_TYPE> structure or B<NULL> if an error occurred.
+
+The error codes that can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>
+
+=head1 HISTORY
+
+ASN1_generate_nconf() and ASN1_generate_v3() were added to OpenSSL 0.9.8
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/BIO_ctrl.pod b/deps/openssl/openssl/doc/crypto/BIO_ctrl.pod
new file mode 100644 (file)
index 0000000..722e8b8
--- /dev/null
@@ -0,0 +1,128 @@
+=pod
+
+=head1 NAME
+
+BIO_ctrl, BIO_callback_ctrl, BIO_ptr_ctrl, BIO_int_ctrl, BIO_reset,
+BIO_seek, BIO_tell, BIO_flush, BIO_eof, BIO_set_close, BIO_get_close,
+BIO_pending, BIO_wpending, BIO_ctrl_pending, BIO_ctrl_wpending,
+BIO_get_info_callback, BIO_set_info_callback - BIO control operations
+
+=head1 SYNOPSIS
+
+ #include <openssl/bio.h>
+
+ long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg);
+ long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long));
+ char *        BIO_ptr_ctrl(BIO *bp,int cmd,long larg);
+ long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg);
+
+ int BIO_reset(BIO *b);
+ int BIO_seek(BIO *b, int ofs);
+ int BIO_tell(BIO *b);
+ int BIO_flush(BIO *b);
+ int BIO_eof(BIO *b);
+ int BIO_set_close(BIO *b,long flag);
+ int BIO_get_close(BIO *b);
+ int BIO_pending(BIO *b);
+ int BIO_wpending(BIO *b);
+ size_t BIO_ctrl_pending(BIO *b);
+ size_t BIO_ctrl_wpending(BIO *b);
+
+ int BIO_get_info_callback(BIO *b,bio_info_cb **cbp);
+ int BIO_set_info_callback(BIO *b,bio_info_cb *cb);
+
+ typedef void bio_info_cb(BIO *b, int oper, const char *ptr, int arg1, long arg2, long arg3);
+
+=head1 DESCRIPTION
+
+BIO_ctrl(), BIO_callback_ctrl(), BIO_ptr_ctrl() and BIO_int_ctrl()
+are BIO "control" operations taking arguments of various types.
+These functions are not normally called directly, various macros
+are used instead. The standard macros are described below, macros
+specific to a particular type of BIO are described in the specific
+BIOs manual page as well as any special features of the standard
+calls.
+
+BIO_reset() typically resets a BIO to some initial state, in the case
+of file related BIOs for example it rewinds the file pointer to the
+start of the file.
+
+BIO_seek() resets a file related BIO's (that is file descriptor and
+FILE BIOs) file position pointer to B<ofs> bytes from start of file.
+
+BIO_tell() returns the current file position of a file related BIO.
+
+BIO_flush() normally writes out any internally buffered data, in some
+cases it is used to signal EOF and that no more data will be written.
+
+BIO_eof() returns 1 if the BIO has read EOF, the precise meaning of
+"EOF" varies according to the BIO type.
+
+BIO_set_close() sets the BIO B<b> close flag to B<flag>. B<flag> can
+take the value BIO_CLOSE or BIO_NOCLOSE. Typically BIO_CLOSE is used
+in a source/sink BIO to indicate that the underlying I/O stream should
+be closed when the BIO is freed.
+
+BIO_get_close() returns the BIOs close flag.
+
+BIO_pending(), BIO_ctrl_pending(), BIO_wpending() and BIO_ctrl_wpending()
+return the number of pending characters in the BIOs read and write buffers.
+Not all BIOs support these calls. BIO_ctrl_pending() and BIO_ctrl_wpending()
+return a size_t type and are functions, BIO_pending() and BIO_wpending() are
+macros which call BIO_ctrl().
+
+=head1 RETURN VALUES
+
+BIO_reset() normally returns 1 for success and 0 or -1 for failure. File
+BIOs are an exception, they return 0 for success and -1 for failure.
+
+BIO_seek() and BIO_tell() both return the current file position on success
+and -1 for failure, except file BIOs which for BIO_seek() always return 0
+for success and -1 for failure.
+
+BIO_flush() returns 1 for success and 0 or -1 for failure.
+
+BIO_eof() returns 1 if EOF has been reached 0 otherwise.
+
+BIO_set_close() always returns 1.
+
+BIO_get_close() returns the close flag value: BIO_CLOSE or BIO_NOCLOSE.
+
+BIO_pending(), BIO_ctrl_pending(), BIO_wpending() and BIO_ctrl_wpending()
+return the amount of pending data.
+
+=head1 NOTES
+
+BIO_flush(), because it can write data may return 0 or -1 indicating
+that the call should be retried later in a similar manner to BIO_write(). 
+The BIO_should_retry() call should be used and appropriate action taken
+is the call fails.
+
+The return values of BIO_pending() and BIO_wpending() may not reliably
+determine the amount of pending data in all cases. For example in the
+case of a file BIO some data may be available in the FILE structures
+internal buffers but it is not possible to determine this in a
+portably way. For other types of BIO they may not be supported.
+
+Filter BIOs if they do not internally handle a particular BIO_ctrl()
+operation usually pass the operation to the next BIO in the chain.
+This often means there is no need to locate the required BIO for
+a particular operation, it can be called on a chain and it will
+be automatically passed to the relevant BIO. However this can cause
+unexpected results: for example no current filter BIOs implement
+BIO_seek(), but this may still succeed if the chain ends in a FILE
+or file descriptor BIO.
+
+Source/sink BIOs return an 0 if they do not recognize the BIO_ctrl()
+operation.
+
+=head1 BUGS
+
+Some of the return values are ambiguous and care should be taken. In
+particular a return value of 0 can be returned if an operation is not
+supported, if an error occurred, if EOF has not been reached and in
+the case of BIO_seek() on a file BIO for a successful operation. 
+
+=head1 SEE ALSO
+
+TBA
diff --git a/deps/openssl/openssl/doc/crypto/BIO_f_base64.pod b/deps/openssl/openssl/doc/crypto/BIO_f_base64.pod
new file mode 100644 (file)
index 0000000..438af3b
--- /dev/null
@@ -0,0 +1,81 @@
+=pod
+
+=head1 NAME
+
+BIO_f_base64 - base64 BIO filter
+
+=head1 SYNOPSIS
+
+ #include <openssl/bio.h>
+ #include <openssl/evp.h>
+
+ BIO_METHOD *  BIO_f_base64(void);
+
+=head1 DESCRIPTION
+
+BIO_f_base64() returns the base64 BIO method. This is a filter
+BIO that base64 encodes any data written through it and decodes
+any data read through it.
+
+Base64 BIOs do not support BIO_gets() or BIO_puts(). 
+
+BIO_flush() on a base64 BIO that is being written through is
+used to signal that no more data is to be encoded: this is used
+to flush the final block through the BIO.
+
+The flag BIO_FLAGS_BASE64_NO_NL can be set with BIO_set_flags()
+to encode the data all on one line or expect the data to be all
+on one line.
+
+=head1 NOTES
+
+Because of the format of base64 encoding the end of the encoded
+block cannot always be reliably determined.
+
+=head1 RETURN VALUES
+
+BIO_f_base64() returns the base64 BIO method.
+
+=head1 EXAMPLES
+
+Base64 encode the string "Hello World\n" and write the result
+to standard output:
+
+ BIO *bio, *b64;
+ char message[] = "Hello World \n";
+
+ b64 = BIO_new(BIO_f_base64());
+ bio = BIO_new_fp(stdout, BIO_NOCLOSE);
+ bio = BIO_push(b64, bio);
+ BIO_write(bio, message, strlen(message));
+ BIO_flush(bio);
+
+ BIO_free_all(bio);
+
+Read Base64 encoded data from standard input and write the decoded
+data to standard output:
+
+ BIO *bio, *b64, *bio_out;
+ char inbuf[512];
+ int inlen;
+
+ b64 = BIO_new(BIO_f_base64());
+ bio = BIO_new_fp(stdin, BIO_NOCLOSE);
+ bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
+ bio = BIO_push(b64, bio);
+ while((inlen = BIO_read(bio, inbuf, 512)) > 0) 
+       BIO_write(bio_out, inbuf, inlen);
+
+ BIO_free_all(bio);
+
+=head1 BUGS
+
+The ambiguity of EOF in base64 encoded data can cause additional
+data following the base64 encoded block to be misinterpreted.
+
+There should be some way of specifying a test that the BIO can perform
+to reliably determine EOF (for example a MIME boundary).
+
+=head1 SEE ALSO
+
+TBA
diff --git a/deps/openssl/openssl/doc/crypto/BIO_f_buffer.pod b/deps/openssl/openssl/doc/crypto/BIO_f_buffer.pod
new file mode 100644 (file)
index 0000000..c0dccf1
--- /dev/null
@@ -0,0 +1,74 @@
+=pod
+
+=head1 NAME
+
+BIO_f_buffer - buffering BIO
+
+=head1 SYNOPSIS
+
+ #include <openssl/bio.h>
+
+ BIO_METHOD * BIO_f_buffer(void);
+
+ #define BIO_get_buffer_num_lines(b)   BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL)
+ #define BIO_set_read_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,0)
+ #define BIO_set_write_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,1)
+ #define BIO_set_buffer_size(b,size)   BIO_ctrl(b,BIO_C_SET_BUFF_SIZE,size,NULL)
+ #define BIO_set_buffer_read_data(b,buf,num) BIO_ctrl(b,BIO_C_SET_BUFF_READ_DATA,num,buf)
+
+=head1 DESCRIPTION
+
+BIO_f_buffer() returns the buffering BIO method.
+
+Data written to a buffering BIO is buffered and periodically written
+to the next BIO in the chain. Data read from a buffering BIO comes from
+an internal buffer which is filled from the next BIO in the chain.
+Both BIO_gets() and BIO_puts() are supported.
+
+Calling BIO_reset() on a buffering BIO clears any buffered data.
+
+BIO_get_buffer_num_lines() returns the number of lines currently buffered.
+
+BIO_set_read_buffer_size(), BIO_set_write_buffer_size() and BIO_set_buffer_size()
+set the read, write or both read and write buffer sizes to B<size>. The initial
+buffer size is DEFAULT_BUFFER_SIZE, currently 4096. Any attempt to reduce the
+buffer size below DEFAULT_BUFFER_SIZE is ignored. Any buffered data is cleared
+when the buffer is resized.
+
+BIO_set_buffer_read_data() clears the read buffer and fills it with B<num>
+bytes of B<buf>. If B<num> is larger than the current buffer size the buffer
+is expanded.
+
+=head1 NOTES
+
+Buffering BIOs implement BIO_gets() by using BIO_read() operations on the
+next BIO in the chain. By prepending a buffering BIO to a chain it is therefore
+possible to provide BIO_gets() functionality if the following BIOs do not
+support it (for example SSL BIOs).
+
+Data is only written to the next BIO in the chain when the write buffer fills
+or when BIO_flush() is called. It is therefore important to call BIO_flush()
+whenever any pending data should be written such as when removing a buffering
+BIO using BIO_pop(). BIO_flush() may need to be retried if the ultimate
+source/sink BIO is non blocking.
+
+=head1 RETURN VALUES
+
+BIO_f_buffer() returns the buffering BIO method.
+
+BIO_get_buffer_num_lines() returns the number of lines buffered (may be 0).
+
+BIO_set_read_buffer_size(), BIO_set_write_buffer_size() and BIO_set_buffer_size()
+return 1 if the buffer was successfully resized or 0 for failure.
+
+BIO_set_buffer_read_data() returns 1 if the data was set correctly or 0 if
+there was an error.
+
+=head1 SEE ALSO
+
+L<BIO(3)|BIO(3)>,
+L<BIO_reset(3)|BIO_reset(3)>,
+L<BIO_flush(3)|BIO_flush(3)>,
+L<BIO_pop(3)|BIO_pop(3)>,
+L<BIO_ctrl(3)|BIO_ctrl(3)>,
+L<BIO_int_ctrl(3)|BIO_ctrl(3)>
diff --git a/deps/openssl/openssl/doc/crypto/BIO_f_cipher.pod b/deps/openssl/openssl/doc/crypto/BIO_f_cipher.pod
new file mode 100644 (file)
index 0000000..02439ce
--- /dev/null
@@ -0,0 +1,76 @@
+=pod
+
+=head1 NAME
+
+BIO_f_cipher, BIO_set_cipher, BIO_get_cipher_status, BIO_get_cipher_ctx - cipher BIO filter
+
+=head1 SYNOPSIS
+
+ #include <openssl/bio.h>
+ #include <openssl/evp.h>
+
+ BIO_METHOD *  BIO_f_cipher(void);
+ void BIO_set_cipher(BIO *b,const EVP_CIPHER *cipher,
+               unsigned char *key, unsigned char *iv, int enc);
+ int BIO_get_cipher_status(BIO *b)
+ int BIO_get_cipher_ctx(BIO *b, EVP_CIPHER_CTX **pctx)
+
+=head1 DESCRIPTION
+
+BIO_f_cipher() returns the cipher BIO method. This is a filter
+BIO that encrypts any data written through it, and decrypts any data
+read from it. It is a BIO wrapper for the cipher routines
+EVP_CipherInit(), EVP_CipherUpdate() and EVP_CipherFinal().
+
+Cipher BIOs do not support BIO_gets() or BIO_puts(). 
+
+BIO_flush() on an encryption BIO that is being written through is
+used to signal that no more data is to be encrypted: this is used
+to flush and possibly pad the final block through the BIO.
+
+BIO_set_cipher() sets the cipher of BIO B<b> to B<cipher> using key B<key>
+and IV B<iv>. B<enc> should be set to 1 for encryption and zero for
+decryption.
+
+When reading from an encryption BIO the final block is automatically
+decrypted and checked when EOF is detected. BIO_get_cipher_status()
+is a BIO_ctrl() macro which can be called to determine whether the
+decryption operation was successful.
+
+BIO_get_cipher_ctx() is a BIO_ctrl() macro which retrieves the internal
+BIO cipher context. The retrieved context can be used in conjunction
+with the standard cipher routines to set it up. This is useful when
+BIO_set_cipher() is not flexible enough for the applications needs.
+
+=head1 NOTES
+
+When encrypting BIO_flush() B<must> be called to flush the final block
+through the BIO. If it is not then the final block will fail a subsequent
+decrypt.
+
+When decrypting an error on the final block is signalled by a zero
+return value from the read operation. A successful decrypt followed
+by EOF will also return zero for the final read. BIO_get_cipher_status()
+should be called to determine if the decrypt was successful.
+
+As always, if BIO_gets() or BIO_puts() support is needed then it can
+be achieved by preceding the cipher BIO with a buffering BIO.
+
+=head1 RETURN VALUES
+
+BIO_f_cipher() returns the cipher BIO method.
+
+BIO_set_cipher() does not return a value.
+
+BIO_get_cipher_status() returns 1 for a successful decrypt and 0
+for failure.
+
+BIO_get_cipher_ctx() currently always returns 1.
+
+=head1 EXAMPLES
+
+TBA
+
+=head1 SEE ALSO
+
+TBA
diff --git a/deps/openssl/openssl/doc/crypto/BIO_f_md.pod b/deps/openssl/openssl/doc/crypto/BIO_f_md.pod
new file mode 100644 (file)
index 0000000..2cc41f8
--- /dev/null
@@ -0,0 +1,144 @@
+=pod
+
+=head1 NAME
+
+BIO_f_md, BIO_set_md, BIO_get_md, BIO_get_md_ctx - message digest BIO filter
+
+=head1 SYNOPSIS
+
+ #include <openssl/bio.h>
+ #include <openssl/evp.h>
+
+ BIO_METHOD *  BIO_f_md(void);
+ int BIO_set_md(BIO *b,EVP_MD *md);
+ int BIO_get_md(BIO *b,EVP_MD **mdp);
+ int BIO_get_md_ctx(BIO *b,EVP_MD_CTX **mdcp);
+
+=head1 DESCRIPTION
+
+BIO_f_md() returns the message digest BIO method. This is a filter
+BIO that digests any data passed through it, it is a BIO wrapper
+for the digest routines EVP_DigestInit(), EVP_DigestUpdate()
+and EVP_DigestFinal().
+
+Any data written or read through a digest BIO using BIO_read() and
+BIO_write() is digested.
+
+BIO_gets(), if its B<size> parameter is large enough finishes the
+digest calculation and returns the digest value. BIO_puts() is
+not supported.
+
+BIO_reset() reinitialises a digest BIO.
+
+BIO_set_md() sets the message digest of BIO B<b> to B<md>: this
+must be called to initialize a digest BIO before any data is
+passed through it. It is a BIO_ctrl() macro.
+
+BIO_get_md() places the a pointer to the digest BIOs digest method
+in B<mdp>, it is a BIO_ctrl() macro.
+
+BIO_get_md_ctx() returns the digest BIOs context into B<mdcp>.
+
+=head1 NOTES
+
+The context returned by BIO_get_md_ctx() can be used in calls
+to EVP_DigestFinal() and also the signature routines EVP_SignFinal()
+and EVP_VerifyFinal().
+
+The context returned by BIO_get_md_ctx() is an internal context
+structure. Changes made to this context will affect the digest
+BIO itself and the context pointer will become invalid when the digest
+BIO is freed.
+
+After the digest has been retrieved from a digest BIO it must be
+reinitialized by calling BIO_reset(), or BIO_set_md() before any more
+data is passed through it.
+
+If an application needs to call BIO_gets() or BIO_puts() through
+a chain containing digest BIOs then this can be done by prepending
+a buffering BIO.
+
+Before OpenSSL 1.0.0 the call to BIO_get_md_ctx() would only work if the BIO
+had been initialized for example by calling BIO_set_md() ). In OpenSSL
+1.0.0 and later the context is always returned and the BIO is state is set
+to initialized. This allows applications to initialize the context externally
+if the standard calls such as BIO_set_md() are not sufficiently flexible.
+
+=head1 RETURN VALUES
+
+BIO_f_md() returns the digest BIO method.
+
+BIO_set_md(), BIO_get_md() and BIO_md_ctx() return 1 for success and
+0 for failure.
+
+=head1 EXAMPLES
+
+The following example creates a BIO chain containing an SHA1 and MD5
+digest BIO and passes the string "Hello World" through it. Error
+checking has been omitted for clarity.
+
+ BIO *bio, *mdtmp;
+ char message[] = "Hello World";
+ bio = BIO_new(BIO_s_null());
+ mdtmp = BIO_new(BIO_f_md());
+ BIO_set_md(mdtmp, EVP_sha1());
+ /* For BIO_push() we want to append the sink BIO and keep a note of
+  * the start of the chain.
+  */
+ bio = BIO_push(mdtmp, bio);
+ mdtmp = BIO_new(BIO_f_md());
+ BIO_set_md(mdtmp, EVP_md5());
+ bio = BIO_push(mdtmp, bio);
+ /* Note: mdtmp can now be discarded */
+ BIO_write(bio, message, strlen(message));
+
+The next example digests data by reading through a chain instead:
+
+ BIO *bio, *mdtmp;
+ char buf[1024];
+ int rdlen;
+ bio = BIO_new_file(file, "rb");
+ mdtmp = BIO_new(BIO_f_md());
+ BIO_set_md(mdtmp, EVP_sha1());
+ bio = BIO_push(mdtmp, bio);
+ mdtmp = BIO_new(BIO_f_md());
+ BIO_set_md(mdtmp, EVP_md5());
+ bio = BIO_push(mdtmp, bio);
+ do {
+       rdlen = BIO_read(bio, buf, sizeof(buf));
+        /* Might want to do something with the data here */
+ } while(rdlen > 0);
+
+This next example retrieves the message digests from a BIO chain and
+outputs them. This could be used with the examples above.
+
+ BIO *mdtmp;
+ unsigned char mdbuf[EVP_MAX_MD_SIZE];
+ int mdlen;
+ int i;
+ mdtmp = bio;  /* Assume bio has previously been set up */
+ do {
+       EVP_MD *md;
+       mdtmp = BIO_find_type(mdtmp, BIO_TYPE_MD);
+        if(!mdtmp) break;
+       BIO_get_md(mdtmp, &md);
+        printf("%s digest", OBJ_nid2sn(EVP_MD_type(md)));
+       mdlen = BIO_gets(mdtmp, mdbuf, EVP_MAX_MD_SIZE);
+       for(i = 0; i < mdlen; i++) printf(":%02X", mdbuf[i]);
+       printf("\n");
+       mdtmp = BIO_next(mdtmp);
+ } while(mdtmp);
+
+ BIO_free_all(bio);
+
+=head1 BUGS
+
+The lack of support for BIO_puts() and the non standard behaviour of
+BIO_gets() could be regarded as anomalous. It could be argued that BIO_gets()
+and BIO_puts() should be passed to the next BIO in the chain and digest
+the data passed through and that digests should be retrieved using a
+separate BIO_ctrl() call.
+
+=head1 SEE ALSO
+
+TBA
diff --git a/deps/openssl/openssl/doc/crypto/BIO_f_null.pod b/deps/openssl/openssl/doc/crypto/BIO_f_null.pod
new file mode 100644 (file)
index 0000000..b057c18
--- /dev/null
@@ -0,0 +1,32 @@
+=pod
+
+=head1 NAME
+
+BIO_f_null - null filter
+
+=head1 SYNOPSIS
+
+ #include <openssl/bio.h>
+
+ BIO_METHOD *  BIO_f_null(void);
+
+=head1 DESCRIPTION
+
+BIO_f_null() returns the null filter BIO method. This is a filter BIO
+that does nothing.
+
+All requests to a null filter BIO are passed through to the next BIO in
+the chain: this means that a BIO chain containing a null filter BIO
+behaves just as though the BIO was not there.
+
+=head1 NOTES
+
+As may be apparent a null filter BIO is not particularly useful.
+
+=head1 RETURN VALUES
+
+BIO_f_null() returns the null filter BIO method.
+
+=head1 SEE ALSO
+
+TBA
diff --git a/deps/openssl/openssl/doc/crypto/BIO_f_ssl.pod b/deps/openssl/openssl/doc/crypto/BIO_f_ssl.pod
new file mode 100644 (file)
index 0000000..bc5861a
--- /dev/null
@@ -0,0 +1,322 @@
+=pod
+
+=head1 NAME
+
+BIO_f_ssl, BIO_set_ssl, BIO_get_ssl, BIO_set_ssl_mode, BIO_set_ssl_renegotiate_bytes,
+BIO_get_num_renegotiates, BIO_set_ssl_renegotiate_timeout, BIO_new_ssl,
+BIO_new_ssl_connect, BIO_new_buffer_ssl_connect, BIO_ssl_copy_session_id,
+BIO_ssl_shutdown - SSL BIO
+
+=head1 SYNOPSIS
+
+ #include <openssl/bio.h>
+ #include <openssl/ssl.h>
+
+ BIO_METHOD *BIO_f_ssl(void);
+
+ #define BIO_set_ssl(b,ssl,c)  BIO_ctrl(b,BIO_C_SET_SSL,c,(char *)ssl)
+ #define BIO_get_ssl(b,sslp)   BIO_ctrl(b,BIO_C_GET_SSL,0,(char *)sslp)
+ #define BIO_set_ssl_mode(b,client)    BIO_ctrl(b,BIO_C_SSL_MODE,client,NULL)
+ #define BIO_set_ssl_renegotiate_bytes(b,num) \
+       BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_BYTES,num,NULL);
+ #define BIO_set_ssl_renegotiate_timeout(b,seconds) \
+       BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT,seconds,NULL);
+ #define BIO_get_num_renegotiates(b) \
+       BIO_ctrl(b,BIO_C_SET_SSL_NUM_RENEGOTIATES,0,NULL);
+
+ BIO *BIO_new_ssl(SSL_CTX *ctx,int client);
+ BIO *BIO_new_ssl_connect(SSL_CTX *ctx);
+ BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx);
+ int BIO_ssl_copy_session_id(BIO *to,BIO *from);
+ void BIO_ssl_shutdown(BIO *bio);
+
+ #define BIO_do_handshake(b)   BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL)
+
+=head1 DESCRIPTION
+
+BIO_f_ssl() returns the SSL BIO method. This is a filter BIO which
+is a wrapper round the OpenSSL SSL routines adding a BIO "flavour" to
+SSL I/O. 
+
+I/O performed on an SSL BIO communicates using the SSL protocol with
+the SSLs read and write BIOs. If an SSL connection is not established
+then an attempt is made to establish one on the first I/O call.
+
+If a BIO is appended to an SSL BIO using BIO_push() it is automatically
+used as the SSL BIOs read and write BIOs.
+
+Calling BIO_reset() on an SSL BIO closes down any current SSL connection
+by calling SSL_shutdown(). BIO_reset() is then sent to the next BIO in
+the chain: this will typically disconnect the underlying transport.
+The SSL BIO is then reset to the initial accept or connect state.
+
+If the close flag is set when an SSL BIO is freed then the internal
+SSL structure is also freed using SSL_free().
+
+BIO_set_ssl() sets the internal SSL pointer of BIO B<b> to B<ssl> using
+the close flag B<c>.
+
+BIO_get_ssl() retrieves the SSL pointer of BIO B<b>, it can then be
+manipulated using the standard SSL library functions.
+
+BIO_set_ssl_mode() sets the SSL BIO mode to B<client>. If B<client>
+is 1 client mode is set. If B<client> is 0 server mode is set.
+
+BIO_set_ssl_renegotiate_bytes() sets the renegotiate byte count
+to B<num>. When set after every B<num> bytes of I/O (read and write) 
+the SSL session is automatically renegotiated. B<num> must be at
+least 512 bytes.
+
+BIO_set_ssl_renegotiate_timeout() sets the renegotiate timeout to
+B<seconds>. When the renegotiate timeout elapses the session is
+automatically renegotiated.
+
+BIO_get_num_renegotiates() returns the total number of session
+renegotiations due to I/O or timeout.
+
+BIO_new_ssl() allocates an SSL BIO using SSL_CTX B<ctx> and using
+client mode if B<client> is non zero.
+
+BIO_new_ssl_connect() creates a new BIO chain consisting of an
+SSL BIO (using B<ctx>) followed by a connect BIO.
+
+BIO_new_buffer_ssl_connect() creates a new BIO chain consisting
+of a buffering BIO, an SSL BIO (using B<ctx>) and a connect
+BIO.
+
+BIO_ssl_copy_session_id() copies an SSL session id between 
+BIO chains B<from> and B<to>. It does this by locating the
+SSL BIOs in each chain and calling SSL_copy_session_id() on
+the internal SSL pointer.
+
+BIO_ssl_shutdown() closes down an SSL connection on BIO
+chain B<bio>. It does this by locating the SSL BIO in the
+chain and calling SSL_shutdown() on its internal SSL
+pointer.
+
+BIO_do_handshake() attempts to complete an SSL handshake on the
+supplied BIO and establish the SSL connection. It returns 1
+if the connection was established successfully. A zero or negative
+value is returned if the connection could not be established, the
+call BIO_should_retry() should be used for non blocking connect BIOs
+to determine if the call should be retried. If an SSL connection has
+already been established this call has no effect.
+
+=head1 NOTES
+
+SSL BIOs are exceptional in that if the underlying transport
+is non blocking they can still request a retry in exceptional
+circumstances. Specifically this will happen if a session
+renegotiation takes place during a BIO_read() operation, one
+case where this happens is when SGC or step up occurs.
+
+In OpenSSL 0.9.6 and later the SSL flag SSL_AUTO_RETRY can be
+set to disable this behaviour. That is when this flag is set
+an SSL BIO using a blocking transport will never request a
+retry.
+
+Since unknown BIO_ctrl() operations are sent through filter
+BIOs the servers name and port can be set using BIO_set_host()
+on the BIO returned by BIO_new_ssl_connect() without having
+to locate the connect BIO first.
+
+Applications do not have to call BIO_do_handshake() but may wish
+to do so to separate the handshake process from other I/O
+processing.
+
+=head1 RETURN VALUES
+
+TBA
+
+=head1 EXAMPLE
+
+This SSL/TLS client example, attempts to retrieve a page from an
+SSL/TLS web server. The I/O routines are identical to those of the
+unencrypted example in L<BIO_s_connect(3)|BIO_s_connect(3)>.
+
+ BIO *sbio, *out;
+ int len;
+ char tmpbuf[1024];
+ SSL_CTX *ctx;
+ SSL *ssl;
+
+ ERR_load_crypto_strings();
+ ERR_load_SSL_strings();
+ OpenSSL_add_all_algorithms();
+
+ /* We would seed the PRNG here if the platform didn't
+  * do it automatically
+  */
+
+ ctx = SSL_CTX_new(SSLv23_client_method());
+
+ /* We'd normally set some stuff like the verify paths and
+  * mode here because as things stand this will connect to
+  * any server whose certificate is signed by any CA.
+  */
+
+ sbio = BIO_new_ssl_connect(ctx);
+
+ BIO_get_ssl(sbio, &ssl);
+
+ if(!ssl) {
+   fprintf(stderr, "Can't locate SSL pointer\n");
+   /* whatever ... */
+ }
+
+ /* Don't want any retries */
+ SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
+
+ /* We might want to do other things with ssl here */
+
+ BIO_set_conn_hostname(sbio, "localhost:https");
+
+ out = BIO_new_fp(stdout, BIO_NOCLOSE);
+ if(BIO_do_connect(sbio) <= 0) {
+       fprintf(stderr, "Error connecting to server\n");
+       ERR_print_errors_fp(stderr);
+       /* whatever ... */
+ }
+
+ if(BIO_do_handshake(sbio) <= 0) {
+       fprintf(stderr, "Error establishing SSL connection\n");
+       ERR_print_errors_fp(stderr);
+       /* whatever ... */
+ }
+
+ /* Could examine ssl here to get connection info */
+
+ BIO_puts(sbio, "GET / HTTP/1.0\n\n");
+ for(;;) {     
+       len = BIO_read(sbio, tmpbuf, 1024);
+       if(len <= 0) break;
+       BIO_write(out, tmpbuf, len);
+ }
+ BIO_free_all(sbio);
+ BIO_free(out);
+
+Here is a simple server example. It makes use of a buffering
+BIO to allow lines to be read from the SSL BIO using BIO_gets.
+It creates a pseudo web page containing the actual request from
+a client and also echoes the request to standard output.
+
+ BIO *sbio, *bbio, *acpt, *out;
+ int len;
+ char tmpbuf[1024];
+ SSL_CTX *ctx;
+ SSL *ssl;
+
+ ERR_load_crypto_strings();
+ ERR_load_SSL_strings();
+ OpenSSL_add_all_algorithms();
+
+ /* Might seed PRNG here */
+
+ ctx = SSL_CTX_new(SSLv23_server_method());
+
+ if (!SSL_CTX_use_certificate_file(ctx,"server.pem",SSL_FILETYPE_PEM)
+       || !SSL_CTX_use_PrivateKey_file(ctx,"server.pem",SSL_FILETYPE_PEM)
+       || !SSL_CTX_check_private_key(ctx)) {
+
+       fprintf(stderr, "Error setting up SSL_CTX\n");
+       ERR_print_errors_fp(stderr);
+       return 0;
+ }
+
+ /* Might do other things here like setting verify locations and
+  * DH and/or RSA temporary key callbacks
+  */
+
+ /* New SSL BIO setup as server */
+ sbio=BIO_new_ssl(ctx,0);
+
+ BIO_get_ssl(sbio, &ssl);
+
+ if(!ssl) {
+   fprintf(stderr, "Can't locate SSL pointer\n");
+   /* whatever ... */
+ }
+
+ /* Don't want any retries */
+ SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
+
+ /* Create the buffering BIO */
+
+ bbio = BIO_new(BIO_f_buffer());
+
+ /* Add to chain */
+ sbio = BIO_push(bbio, sbio);
+
+ acpt=BIO_new_accept("4433");
+
+ /* By doing this when a new connection is established
+  * we automatically have sbio inserted into it. The
+  * BIO chain is now 'swallowed' by the accept BIO and
+  * will be freed when the accept BIO is freed. 
+  */
+ BIO_set_accept_bios(acpt,sbio);
+
+ out = BIO_new_fp(stdout, BIO_NOCLOSE);
+
+ /* Setup accept BIO */
+ if(BIO_do_accept(acpt) <= 0) {
+       fprintf(stderr, "Error setting up accept BIO\n");
+       ERR_print_errors_fp(stderr);
+       return 0;
+ }
+
+ /* Now wait for incoming connection */
+ if(BIO_do_accept(acpt) <= 0) {
+       fprintf(stderr, "Error in connection\n");
+       ERR_print_errors_fp(stderr);
+       return 0;
+ }
+
+ /* We only want one connection so remove and free
+  * accept BIO
+  */
+
+ sbio = BIO_pop(acpt);
+
+ BIO_free_all(acpt);
+
+ if(BIO_do_handshake(sbio) <= 0) {
+       fprintf(stderr, "Error in SSL handshake\n");
+       ERR_print_errors_fp(stderr);
+       return 0;
+ }
+
+ BIO_puts(sbio, "HTTP/1.0 200 OK\r\nContent-type: text/plain\r\n\r\n");
+ BIO_puts(sbio, "\r\nConnection Established\r\nRequest headers:\r\n");
+ BIO_puts(sbio, "--------------------------------------------------\r\n");
+
+ for(;;) {
+       len = BIO_gets(sbio, tmpbuf, 1024);
+        if(len <= 0) break;
+       BIO_write(sbio, tmpbuf, len);
+       BIO_write(out, tmpbuf, len);
+       /* Look for blank line signifying end of headers*/
+       if((tmpbuf[0] == '\r') || (tmpbuf[0] == '\n')) break;
+ }
+
+ BIO_puts(sbio, "--------------------------------------------------\r\n");
+ BIO_puts(sbio, "\r\n");
+
+ /* Since there is a buffering BIO present we had better flush it */
+ BIO_flush(sbio);
+
+ BIO_free_all(sbio);
+
+=head1 BUGS
+
+In OpenSSL versions before 1.0.0 the BIO_pop() call was handled incorrectly,
+the I/O BIO reference count was incorrectly incremented (instead of
+decremented) and dissociated with the SSL BIO even if the SSL BIO was not
+explicitly being popped (e.g. a pop higher up the chain). Applications which
+included workarounds for this bug (e.g. freeing BIOs more than once) should
+be modified to handle this fix or they may free up an already freed BIO.
+
+=head1 SEE ALSO
+
+TBA
diff --git a/deps/openssl/openssl/doc/crypto/BIO_find_type.pod b/deps/openssl/openssl/doc/crypto/BIO_find_type.pod
new file mode 100644 (file)
index 0000000..bd3b256
--- /dev/null
@@ -0,0 +1,98 @@
+=pod
+
+=head1 NAME
+
+BIO_find_type, BIO_next - BIO chain traversal
+
+=head1 SYNOPSIS
+
+ #include <openssl/bio.h>
+
+ BIO * BIO_find_type(BIO *b,int bio_type);
+ BIO * BIO_next(BIO *b);
+
+ #define BIO_method_type(b)            ((b)->method->type)
+
+ #define BIO_TYPE_NONE         0
+ #define BIO_TYPE_MEM          (1|0x0400)
+ #define BIO_TYPE_FILE         (2|0x0400)
+
+ #define BIO_TYPE_FD           (4|0x0400|0x0100)
+ #define BIO_TYPE_SOCKET               (5|0x0400|0x0100)
+ #define BIO_TYPE_NULL         (6|0x0400)
+ #define BIO_TYPE_SSL          (7|0x0200)
+ #define BIO_TYPE_MD           (8|0x0200)
+ #define BIO_TYPE_BUFFER               (9|0x0200)
+ #define BIO_TYPE_CIPHER               (10|0x0200)
+ #define BIO_TYPE_BASE64               (11|0x0200)
+ #define BIO_TYPE_CONNECT      (12|0x0400|0x0100)
+ #define BIO_TYPE_ACCEPT               (13|0x0400|0x0100)
+ #define BIO_TYPE_PROXY_CLIENT (14|0x0200)
+ #define BIO_TYPE_PROXY_SERVER (15|0x0200)
+ #define BIO_TYPE_NBIO_TEST    (16|0x0200)
+ #define BIO_TYPE_NULL_FILTER  (17|0x0200)
+ #define BIO_TYPE_BER          (18|0x0200)
+ #define BIO_TYPE_BIO          (19|0x0400)
+
+ #define BIO_TYPE_DESCRIPTOR   0x0100
+ #define BIO_TYPE_FILTER               0x0200
+ #define BIO_TYPE_SOURCE_SINK  0x0400
+
+=head1 DESCRIPTION
+
+The BIO_find_type() searches for a BIO of a given type in a chain, starting
+at BIO B<b>. If B<type> is a specific type (such as BIO_TYPE_MEM) then a search
+is made for a BIO of that type. If B<type> is a general type (such as
+B<BIO_TYPE_SOURCE_SINK>) then the next matching BIO of the given general type is
+searched for. BIO_find_type() returns the next matching BIO or NULL if none is
+found.
+
+Note: not all the B<BIO_TYPE_*> types above have corresponding BIO implementations.
+
+BIO_next() returns the next BIO in a chain. It can be used to traverse all BIOs
+in a chain or used in conjunction with BIO_find_type() to find all BIOs of a
+certain type.
+
+BIO_method_type() returns the type of a BIO.
+
+=head1 RETURN VALUES
+
+BIO_find_type() returns a matching BIO or NULL for no match.
+
+BIO_next() returns the next BIO in a chain.
+
+BIO_method_type() returns the type of the BIO B<b>.
+
+=head1 NOTES
+
+BIO_next() was added to OpenSSL 0.9.6 to provide a 'clean' way to traverse a BIO
+chain or find multiple matches using BIO_find_type(). Previous versions had to
+use:
+
+ next = bio->next_bio;
+
+=head1 BUGS
+
+BIO_find_type() in OpenSSL 0.9.5a and earlier could not be safely passed a
+NULL pointer for the B<b> argument.
+
+=head1 EXAMPLE
+
+Traverse a chain looking for digest BIOs:
+
+ BIO *btmp;
+ btmp = in_bio;        /* in_bio is chain to search through */
+
+ do {
+       btmp = BIO_find_type(btmp, BIO_TYPE_MD);
+       if(btmp == NULL) break; /* Not found */
+       /* btmp is a digest BIO, do something with it ...*/
+       ...
+
+       btmp = BIO_next(btmp);
+ } while(btmp);
+
+
+=head1 SEE ALSO
+
+TBA
diff --git a/deps/openssl/openssl/doc/crypto/BIO_new.pod b/deps/openssl/openssl/doc/crypto/BIO_new.pod
new file mode 100644 (file)
index 0000000..2a245fc
--- /dev/null
@@ -0,0 +1,65 @@
+=pod
+
+=head1 NAME
+
+BIO_new, BIO_set, BIO_free, BIO_vfree, BIO_free_all - BIO allocation and freeing functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/bio.h>
+
+ BIO * BIO_new(BIO_METHOD *type);
+ int   BIO_set(BIO *a,BIO_METHOD *type);
+ int   BIO_free(BIO *a);
+ void  BIO_vfree(BIO *a);
+ void  BIO_free_all(BIO *a);
+
+=head1 DESCRIPTION
+
+The BIO_new() function returns a new BIO using method B<type>.
+
+BIO_set() sets the method of an already existing BIO.
+
+BIO_free() frees up a single BIO, BIO_vfree() also frees up a single BIO
+but it does not return a value. Calling BIO_free() may also have some effect
+on the underlying I/O structure, for example it may close the file being
+referred to under certain circumstances. For more details see the individual
+BIO_METHOD descriptions.
+
+BIO_free_all() frees up an entire BIO chain, it does not halt if an error
+occurs freeing up an individual BIO in the chain.
+
+=head1 RETURN VALUES
+
+BIO_new() returns a newly created BIO or NULL if the call fails.
+
+BIO_set(), BIO_free() return 1 for success and 0 for failure.
+
+BIO_free_all() and BIO_vfree() do not return values.
+
+=head1 NOTES
+
+Some BIOs (such as memory BIOs) can be used immediately after calling
+BIO_new(). Others (such as file BIOs) need some additional initialization,
+and frequently a utility function exists to create and initialize such BIOs.
+
+If BIO_free() is called on a BIO chain it will only free one BIO resulting
+in a memory leak.
+
+Calling BIO_free_all() a single BIO has the same effect as calling BIO_free()
+on it other than the discarded return value.
+
+Normally the B<type> argument is supplied by a function which returns a
+pointer to a BIO_METHOD. There is a naming convention for such functions:
+a source/sink BIO is normally called BIO_s_*() and a filter BIO
+BIO_f_*();
+
+=head1 EXAMPLE
+
+Create a memory BIO:
+
+ BIO *mem = BIO_new(BIO_s_mem());
+
+=head1 SEE ALSO
+
+TBA
diff --git a/deps/openssl/openssl/doc/crypto/BIO_new_CMS.pod b/deps/openssl/openssl/doc/crypto/BIO_new_CMS.pod
new file mode 100644 (file)
index 0000000..9e3a4b7
--- /dev/null
@@ -0,0 +1,66 @@
+=pod
+
+=head1 NAME
+
+ BIO_new_CMS - CMS streaming filter BIO
+
+=head1 SYNOPSIS
+
+ #include <openssl/cms.h>
+
+ BIO *BIO_new_CMS(BIO *out, CMS_ContentInfo *cms);
+
+=head1 DESCRIPTION
+
+BIO_new_CMS() returns a streaming filter BIO chain based on B<cms>. The output
+of the filter is written to B<out>. Any data written to the chain is
+automatically translated to a BER format CMS structure of the appropriate type.
+
+=head1 NOTES
+
+The chain returned by this function behaves like a standard filter BIO. It
+supports non blocking I/O. Content is processed and streamed on the fly and not
+all held in memory at once: so it is possible to encode very large structures.
+After all content has been written through the chain BIO_flush() must be called
+to finalise the structure.
+
+The B<CMS_STREAM> flag must be included in the corresponding B<flags>
+parameter of the B<cms> creation function.
+
+If an application wishes to write additional data to B<out> BIOs should be
+removed from the chain using BIO_pop() and freed with BIO_free() until B<out>
+is reached. If no additional data needs to be written BIO_free_all() can be
+called to free up the whole chain.
+
+Any content written through the filter is used verbatim: no canonical
+translation is performed.
+
+It is possible to chain multiple BIOs to, for example, create a triple wrapped
+signed, enveloped, signed structure. In this case it is the applications
+responsibility to set the inner content type of any outer CMS_ContentInfo
+structures.
+
+Large numbers of small writes through the chain should be avoided as this will
+produce an output consisting of lots of OCTET STRING structures. Prepending
+a BIO_f_buffer() buffering BIO will prevent this.
+
+=head1 BUGS
+
+There is currently no corresponding inverse BIO: i.e. one which can decode
+a CMS structure on the fly.
+
+=head1 RETURN VALUES
+
+BIO_new_CMS() returns a BIO chain when successful or NULL if an error
+occurred. The error can be obtained from ERR_get_error(3).
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<CMS_sign(3)|CMS_sign(3)>,
+L<CMS_encrypt(3)|CMS_encrypt(3)>
+
+=head1 HISTORY
+
+BIO_new_CMS() was added to OpenSSL 1.0.0
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/BIO_push.pod b/deps/openssl/openssl/doc/crypto/BIO_push.pod
new file mode 100644 (file)
index 0000000..8af1d3c
--- /dev/null
@@ -0,0 +1,69 @@
+=pod
+
+=head1 NAME
+
+BIO_push, BIO_pop - add and remove BIOs from a chain.
+
+=head1 SYNOPSIS
+
+ #include <openssl/bio.h>
+
+ BIO * BIO_push(BIO *b,BIO *append);
+ BIO * BIO_pop(BIO *b);
+
+=head1 DESCRIPTION
+
+The BIO_push() function appends the BIO B<append> to B<b>, it returns
+B<b>.
+
+BIO_pop() removes the BIO B<b> from a chain and returns the next BIO
+in the chain, or NULL if there is no next BIO. The removed BIO then
+becomes a single BIO with no association with the original chain,
+it can thus be freed or attached to a different chain.
+
+=head1 NOTES
+
+The names of these functions are perhaps a little misleading. BIO_push()
+joins two BIO chains whereas BIO_pop() deletes a single BIO from a chain,
+the deleted BIO does not need to be at the end of a chain.
+
+The process of calling BIO_push() and BIO_pop() on a BIO may have additional
+consequences (a control call is made to the affected BIOs) any effects will
+be noted in the descriptions of individual BIOs.
+
+=head1 EXAMPLES
+
+For these examples suppose B<md1> and B<md2> are digest BIOs, B<b64> is
+a base64 BIO and B<f> is a file BIO.
+
+If the call:
+
+ BIO_push(b64, f);
+
+is made then the new chain will be B<b64-chain>. After making the calls
+
+ BIO_push(md2, b64);
+ BIO_push(md1, md2);
+
+the new chain is B<md1-md2-b64-f>. Data written to B<md1> will be digested
+by B<md1> and B<md2>, B<base64> encoded and written to B<f>.
+
+It should be noted that reading causes data to pass in the reverse
+direction, that is data is read from B<f>, base64 B<decoded> and digested
+by B<md1> and B<md2>. If the call:
+
+ BIO_pop(md2);
+
+The call will return B<b64> and the new chain will be B<md1-b64-f> data can
+be written to B<md1> as before.
+
+=head1 RETURN VALUES
+
+BIO_push() returns the end of the chain, B<b>.
+
+BIO_pop() returns the next BIO in the chain, or NULL if there is no next
+BIO.
+
+=head1 SEE ALSO
+
+TBA
diff --git a/deps/openssl/openssl/doc/crypto/BIO_read.pod b/deps/openssl/openssl/doc/crypto/BIO_read.pod
new file mode 100644 (file)
index 0000000..b345281
--- /dev/null
@@ -0,0 +1,66 @@
+=pod
+
+=head1 NAME
+
+BIO_read, BIO_write, BIO_gets, BIO_puts - BIO I/O functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/bio.h>
+
+ int   BIO_read(BIO *b, void *buf, int len);
+ int   BIO_gets(BIO *b,char *buf, int size);
+ int   BIO_write(BIO *b, const void *buf, int len);
+ int   BIO_puts(BIO *b,const char *buf);
+
+=head1 DESCRIPTION
+
+BIO_read() attempts to read B<len> bytes from BIO B<b> and places
+the data in B<buf>.
+
+BIO_gets() performs the BIOs "gets" operation and places the data
+in B<buf>. Usually this operation will attempt to read a line of data
+from the BIO of maximum length B<len>. There are exceptions to this
+however, for example BIO_gets() on a digest BIO will calculate and
+return the digest and other BIOs may not support BIO_gets() at all.
+
+BIO_write() attempts to write B<len> bytes from B<buf> to BIO B<b>.
+
+BIO_puts() attempts to write a null terminated string B<buf> to BIO B<b>
+
+=head1 RETURN VALUES
+
+All these functions return either the amount of data successfully read or
+written (if the return value is positive) or that no data was successfully
+read or written if the result is 0 or -1. If the return value is -2 then
+the operation is not implemented in the specific BIO type.
+
+=head1 NOTES
+
+A 0 or -1 return is not necessarily an indication of an error. In
+particular when the source/sink is non-blocking or of a certain type
+it may merely be an indication that no data is currently available and that
+the application should retry the operation later.
+
+One technique sometimes used with blocking sockets is to use a system call
+(such as select(), poll() or equivalent) to determine when data is available
+and then call read() to read the data. The equivalent with BIOs (that is call
+select() on the underlying I/O structure and then call BIO_read() to
+read the data) should B<not> be used because a single call to BIO_read()
+can cause several reads (and writes in the case of SSL BIOs) on the underlying
+I/O structure and may block as a result. Instead select() (or equivalent)
+should be combined with non blocking I/O so successive reads will request
+a retry instead of blocking.
+
+See L<BIO_should_retry(3)|BIO_should_retry(3)> for details of how to
+determine the cause of a retry and other I/O issues.
+
+If the BIO_gets() function is not supported by a BIO then it possible to
+work around this by adding a buffering BIO L<BIO_f_buffer(3)|BIO_f_buffer(3)>
+to the chain.
+
+=head1 SEE ALSO
+
+L<BIO_should_retry(3)|BIO_should_retry(3)>
+
+TBA
diff --git a/deps/openssl/openssl/doc/crypto/BIO_s_accept.pod b/deps/openssl/openssl/doc/crypto/BIO_s_accept.pod
new file mode 100644 (file)
index 0000000..7b63e46
--- /dev/null
@@ -0,0 +1,195 @@
+=pod
+
+=head1 NAME
+
+BIO_s_accept, BIO_set_accept_port, BIO_get_accept_port,
+BIO_set_nbio_accept, BIO_set_accept_bios, BIO_set_bind_mode,
+BIO_get_bind_mode, BIO_do_accept - accept BIO
+
+=head1 SYNOPSIS
+
+ #include <openssl/bio.h>
+
+ BIO_METHOD *BIO_s_accept(void);
+
+ long BIO_set_accept_port(BIO *b, char *name);
+ char *BIO_get_accept_port(BIO *b);
+
+ BIO *BIO_new_accept(char *host_port);
+
+ long BIO_set_nbio_accept(BIO *b, int n);
+ long BIO_set_accept_bios(BIO *b, char *bio);
+
+ long BIO_set_bind_mode(BIO *b, long mode);
+ long BIO_get_bind_mode(BIO *b, long dummy);
+
+ #define BIO_BIND_NORMAL               0
+ #define BIO_BIND_REUSEADDR_IF_UNUSED  1
+ #define BIO_BIND_REUSEADDR            2
+
+ int BIO_do_accept(BIO *b);
+
+=head1 DESCRIPTION
+
+BIO_s_accept() returns the accept BIO method. This is a wrapper
+round the platform's TCP/IP socket accept routines.
+
+Using accept BIOs, TCP/IP connections can be accepted and data
+transferred using only BIO routines. In this way any platform
+specific operations are hidden by the BIO abstraction.
+
+Read and write operations on an accept BIO will perform I/O
+on the underlying connection. If no connection is established
+and the port (see below) is set up properly then the BIO
+waits for an incoming connection.
+
+Accept BIOs support BIO_puts() but not BIO_gets().
+
+If the close flag is set on an accept BIO then any active
+connection on that chain is shutdown and the socket closed when
+the BIO is freed.
+
+Calling BIO_reset() on a accept BIO will close any active
+connection and reset the BIO into a state where it awaits another
+incoming connection.
+
+BIO_get_fd() and BIO_set_fd() can be called to retrieve or set
+the accept socket. See L<BIO_s_fd(3)|BIO_s_fd(3)>
+
+BIO_set_accept_port() uses the string B<name> to set the accept
+port. The port is represented as a string of the form "host:port",
+where "host" is the interface to use and "port" is the port.
+Either or both values can be "*" which is interpreted as meaning
+any interface or port respectively. "port" has the same syntax
+as the port specified in BIO_set_conn_port() for connect BIOs,
+that is it can be a numerical port string or a string to lookup
+using getservbyname() and a string table.
+
+BIO_new_accept() combines BIO_new() and BIO_set_accept_port() into
+a single call: that is it creates a new accept BIO with port
+B<host_port>.
+
+BIO_set_nbio_accept() sets the accept socket to blocking mode
+(the default) if B<n> is 0 or non blocking mode if B<n> is 1.
+
+BIO_set_accept_bios() can be used to set a chain of BIOs which
+will be duplicated and prepended to the chain when an incoming
+connection is received. This is useful if, for example, a 
+buffering or SSL BIO is required for each connection. The
+chain of BIOs must not be freed after this call, they will
+be automatically freed when the accept BIO is freed.
+
+BIO_set_bind_mode() and BIO_get_bind_mode() set and retrieve
+the current bind mode. If BIO_BIND_NORMAL (the default) is set
+then another socket cannot be bound to the same port. If
+BIO_BIND_REUSEADDR is set then other sockets can bind to the
+same port. If BIO_BIND_REUSEADDR_IF_UNUSED is set then and
+attempt is first made to use BIO_BIN_NORMAL, if this fails
+and the port is not in use then a second attempt is made
+using BIO_BIND_REUSEADDR.
+
+BIO_do_accept() serves two functions. When it is first
+called, after the accept BIO has been setup, it will attempt
+to create the accept socket and bind an address to it. Second
+and subsequent calls to BIO_do_accept() will await an incoming
+connection, or request a retry in non blocking mode.
+
+=head1 NOTES
+
+When an accept BIO is at the end of a chain it will await an
+incoming connection before processing I/O calls. When an accept
+BIO is not at then end of a chain it passes I/O calls to the next
+BIO in the chain.
+
+When a connection is established a new socket BIO is created for
+the connection and appended to the chain. That is the chain is now
+accept->socket. This effectively means that attempting I/O on
+an initial accept socket will await an incoming connection then
+perform I/O on it.
+
+If any additional BIOs have been set using BIO_set_accept_bios()
+then they are placed between the socket and the accept BIO,
+that is the chain will be accept->otherbios->socket.
+
+If a server wishes to process multiple connections (as is normally
+the case) then the accept BIO must be made available for further
+incoming connections. This can be done by waiting for a connection and
+then calling:
+
+ connection = BIO_pop(accept);
+
+After this call B<connection> will contain a BIO for the recently
+established connection and B<accept> will now be a single BIO
+again which can be used to await further incoming connections.
+If no further connections will be accepted the B<accept> can
+be freed using BIO_free().
+
+If only a single connection will be processed it is possible to
+perform I/O using the accept BIO itself. This is often undesirable
+however because the accept BIO will still accept additional incoming
+connections. This can be resolved by using BIO_pop() (see above)
+and freeing up the accept BIO after the initial connection.
+
+If the underlying accept socket is non-blocking and BIO_do_accept() is
+called to await an incoming connection it is possible for
+BIO_should_io_special() with the reason BIO_RR_ACCEPT. If this happens
+then it is an indication that an accept attempt would block: the application
+should take appropriate action to wait until the underlying socket has
+accepted a connection and retry the call.
+
+BIO_set_accept_port(), BIO_get_accept_port(), BIO_set_nbio_accept(),
+BIO_set_accept_bios(), BIO_set_bind_mode(), BIO_get_bind_mode() and
+BIO_do_accept() are macros.
+
+=head1 RETURN VALUES
+
+TBA
+
+=head1 EXAMPLE
+
+This example accepts two connections on port 4444, sends messages
+down each and finally closes both down.
+
+ BIO *abio, *cbio, *cbio2;
+ ERR_load_crypto_strings();
+ abio = BIO_new_accept("4444");
+
+ /* First call to BIO_accept() sets up accept BIO */
+ if(BIO_do_accept(abio) <= 0) {
+       fprintf(stderr, "Error setting up accept\n");
+       ERR_print_errors_fp(stderr);
+       exit(0);                
+ }
+
+ /* Wait for incoming connection */
+ if(BIO_do_accept(abio) <= 0) {
+       fprintf(stderr, "Error accepting connection\n");
+       ERR_print_errors_fp(stderr);
+       exit(0);                
+ }
+ fprintf(stderr, "Connection 1 established\n");
+ /* Retrieve BIO for connection */
+ cbio = BIO_pop(abio);
+ BIO_puts(cbio, "Connection 1: Sending out Data on initial connection\n");
+ fprintf(stderr, "Sent out data on connection 1\n");
+ /* Wait for another connection */
+ if(BIO_do_accept(abio) <= 0) {
+       fprintf(stderr, "Error accepting connection\n");
+       ERR_print_errors_fp(stderr);
+       exit(0);                
+ }
+ fprintf(stderr, "Connection 2 established\n");
+ /* Close accept BIO to refuse further connections */
+ cbio2 = BIO_pop(abio);
+ BIO_free(abio);
+ BIO_puts(cbio2, "Connection 2: Sending out Data on second\n");
+ fprintf(stderr, "Sent out data on connection 2\n");
+
+ BIO_puts(cbio, "Connection 1: Second connection established\n");
+ /* Close the two established connections */
+ BIO_free(cbio);
+ BIO_free(cbio2);
+
+=head1 SEE ALSO
+
+TBA
diff --git a/deps/openssl/openssl/doc/crypto/BIO_s_bio.pod b/deps/openssl/openssl/doc/crypto/BIO_s_bio.pod
new file mode 100644 (file)
index 0000000..8d0a55a
--- /dev/null
@@ -0,0 +1,182 @@
+=pod
+
+=head1 NAME
+
+BIO_s_bio, BIO_make_bio_pair, BIO_destroy_bio_pair, BIO_shutdown_wr, 
+BIO_set_write_buf_size, BIO_get_write_buf_size, BIO_new_bio_pair,
+BIO_get_write_guarantee, BIO_ctrl_get_write_guarantee, BIO_get_read_request,
+BIO_ctrl_get_read_request, BIO_ctrl_reset_read_request - BIO pair BIO
+
+=head1 SYNOPSIS
+
+ #include <openssl/bio.h>
+
+ BIO_METHOD *BIO_s_bio(void);
+
+ #define BIO_make_bio_pair(b1,b2)   (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2)
+ #define BIO_destroy_bio_pair(b)    (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL)
+
+ #define BIO_shutdown_wr(b) (int)BIO_ctrl(b, BIO_C_SHUTDOWN_WR, 0, NULL)
+
+ #define BIO_set_write_buf_size(b,size) (int)BIO_ctrl(b,BIO_C_SET_WRITE_BUF_SIZE,size,NULL)
+ #define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL)
+
+ int BIO_new_bio_pair(BIO **bio1, size_t writebuf1, BIO **bio2, size_t writebuf2);
+
+ #define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL)
+ size_t BIO_ctrl_get_write_guarantee(BIO *b);
+
+ #define BIO_get_read_request(b)    (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL)
+ size_t BIO_ctrl_get_read_request(BIO *b);
+
+ int BIO_ctrl_reset_read_request(BIO *b);
+
+=head1 DESCRIPTION
+
+BIO_s_bio() returns the method for a BIO pair. A BIO pair is a pair of source/sink
+BIOs where data written to either half of the pair is buffered and can be read from
+the other half. Both halves must usually by handled by the same application thread
+since no locking is done on the internal data structures.
+
+Since BIO chains typically end in a source/sink BIO it is possible to make this
+one half of a BIO pair and have all the data processed by the chain under application
+control.
+
+One typical use of BIO pairs is to place TLS/SSL I/O under application control, this
+can be used when the application wishes to use a non standard transport for
+TLS/SSL or the normal socket routines are inappropriate.
+
+Calls to BIO_read() will read data from the buffer or request a retry if no
+data is available.
+
+Calls to BIO_write() will place data in the buffer or request a retry if the
+buffer is full.
+
+The standard calls BIO_ctrl_pending() and BIO_ctrl_wpending() can be used to
+determine the amount of pending data in the read or write buffer.
+
+BIO_reset() clears any data in the write buffer.
+
+BIO_make_bio_pair() joins two separate BIOs into a connected pair.
+
+BIO_destroy_pair() destroys the association between two connected BIOs. Freeing
+up any half of the pair will automatically destroy the association.
+
+BIO_shutdown_wr() is used to close down a BIO B<b>. After this call no further
+writes on BIO B<b> are allowed (they will return an error). Reads on the other
+half of the pair will return any pending data or EOF when all pending data has
+been read. 
+
+BIO_set_write_buf_size() sets the write buffer size of BIO B<b> to B<size>.
+If the size is not initialized a default value is used. This is currently
+17K, sufficient for a maximum size TLS record.
+
+BIO_get_write_buf_size() returns the size of the write buffer.
+
+BIO_new_bio_pair() combines the calls to BIO_new(), BIO_make_bio_pair() and
+BIO_set_write_buf_size() to create a connected pair of BIOs B<bio1>, B<bio2>
+with write buffer sizes B<writebuf1> and B<writebuf2>. If either size is
+zero then the default size is used.  BIO_new_bio_pair() does not check whether
+B<bio1> or B<bio2> do point to some other BIO, the values are overwritten,
+BIO_free() is not called.
+
+BIO_get_write_guarantee() and BIO_ctrl_get_write_guarantee() return the maximum
+length of data that can be currently written to the BIO. Writes larger than this
+value will return a value from BIO_write() less than the amount requested or if the
+buffer is full request a retry. BIO_ctrl_get_write_guarantee() is a function
+whereas BIO_get_write_guarantee() is a macro.
+
+BIO_get_read_request() and BIO_ctrl_get_read_request() return the
+amount of data requested, or the buffer size if it is less, if the
+last read attempt at the other half of the BIO pair failed due to an
+empty buffer.  This can be used to determine how much data should be
+written to the BIO so the next read will succeed: this is most useful
+in TLS/SSL applications where the amount of data read is usually
+meaningful rather than just a buffer size. After a successful read
+this call will return zero.  It also will return zero once new data
+has been written satisfying the read request or part of it.
+Note that BIO_get_read_request() never returns an amount larger
+than that returned by BIO_get_write_guarantee().
+
+BIO_ctrl_reset_read_request() can also be used to reset the value returned by
+BIO_get_read_request() to zero.
+
+=head1 NOTES
+
+Both halves of a BIO pair should be freed. That is even if one half is implicit
+freed due to a BIO_free_all() or SSL_free() call the other half needs to be freed.
+
+When used in bidirectional applications (such as TLS/SSL) care should be taken to
+flush any data in the write buffer. This can be done by calling BIO_pending()
+on the other half of the pair and, if any data is pending, reading it and sending
+it to the underlying transport. This must be done before any normal processing
+(such as calling select() ) due to a request and BIO_should_read() being true.
+
+To see why this is important consider a case where a request is sent using
+BIO_write() and a response read with BIO_read(), this can occur during an
+TLS/SSL handshake for example. BIO_write() will succeed and place data in the write
+buffer. BIO_read() will initially fail and BIO_should_read() will be true. If
+the application then waits for data to be available on the underlying transport
+before flushing the write buffer it will never succeed because the request was
+never sent!
+
+=head1 RETURN VALUES
+
+BIO_new_bio_pair() returns 1 on success, with the new BIOs available in
+B<bio1> and B<bio2>, or 0 on failure, with NULL pointers stored into the
+locations for B<bio1> and B<bio2>. Check the error stack for more information.
+
+[XXXXX: More return values need to be added here]
+
+=head1 EXAMPLE
+
+The BIO pair can be used to have full control over the network access of an
+application. The application can call select() on the socket as required
+without having to go through the SSL-interface.
+
+ BIO *internal_bio, *network_bio;
+ ...
+ BIO_new_bio_pair(internal_bio, 0, network_bio, 0);
+ SSL_set_bio(ssl, internal_bio, internal_bio);
+ SSL_operations();
+ ...
+
+ application |   TLS-engine
+    |        |
+    +----------> SSL_operations()
+             |     /\    ||
+             |     ||    \/
+             |   BIO-pair (internal_bio)
+    +----------< BIO-pair (network_bio)
+    |        |
+  socket     |
+
+  ...
+  SSL_free(ssl);               /* implicitly frees internal_bio */
+  BIO_free(network_bio);
+  ...
+
+As the BIO pair will only buffer the data and never directly access the
+connection, it behaves non-blocking and will return as soon as the write
+buffer is full or the read buffer is drained. Then the application has to
+flush the write buffer and/or fill the read buffer.
+
+Use the BIO_ctrl_pending(), to find out whether data is buffered in the BIO
+and must be transfered to the network. Use BIO_ctrl_get_read_request() to
+find out, how many bytes must be written into the buffer before the
+SSL_operation() can successfully be continued.
+
+=head1 WARNING
+
+As the data is buffered, SSL_operation() may return with a ERROR_SSL_WANT_READ
+condition, but there is still data in the write buffer. An application must
+not rely on the error value of SSL_operation() but must assure that the
+write buffer is always flushed first. Otherwise a deadlock may occur as
+the peer might be waiting for the data before being able to continue.
+
+=head1 SEE ALSO
+
+L<SSL_set_bio(3)|SSL_set_bio(3)>, L<ssl(3)|ssl(3)>, L<bio(3)|bio(3)>,
+L<BIO_should_retry(3)|BIO_should_retry(3)>, L<BIO_read(3)|BIO_read(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/BIO_s_connect.pod b/deps/openssl/openssl/doc/crypto/BIO_s_connect.pod
new file mode 100644 (file)
index 0000000..bcf7d8d
--- /dev/null
@@ -0,0 +1,192 @@
+=pod
+
+=head1 NAME
+
+BIO_s_connect, BIO_set_conn_hostname, BIO_set_conn_port,
+BIO_set_conn_ip, BIO_set_conn_int_port, BIO_get_conn_hostname,
+BIO_get_conn_port, BIO_get_conn_ip, BIO_get_conn_int_port,
+BIO_set_nbio, BIO_do_connect - connect BIO
+
+=head1 SYNOPSIS
+
+ #include <openssl/bio.h>
+
+ BIO_METHOD * BIO_s_connect(void);
+
+ BIO *BIO_new_connect(char *name);
+
+ long BIO_set_conn_hostname(BIO *b, char *name);
+ long BIO_set_conn_port(BIO *b, char *port);
+ long BIO_set_conn_ip(BIO *b, char *ip);
+ long BIO_set_conn_int_port(BIO *b, char *port);
+ char *BIO_get_conn_hostname(BIO *b);
+ char *BIO_get_conn_port(BIO *b);
+ char *BIO_get_conn_ip(BIO *b, dummy);
+ long BIO_get_conn_int_port(BIO *b, int port);
+
+ long BIO_set_nbio(BIO *b, long n);
+
+ int BIO_do_connect(BIO *b);
+
+=head1 DESCRIPTION
+
+BIO_s_connect() returns the connect BIO method. This is a wrapper
+round the platform's TCP/IP socket connection routines.
+
+Using connect BIOs, TCP/IP connections can be made and data
+transferred using only BIO routines. In this way any platform
+specific operations are hidden by the BIO abstraction.
+
+Read and write operations on a connect BIO will perform I/O
+on the underlying connection. If no connection is established
+and the port and hostname (see below) is set up properly then
+a connection is established first.
+
+Connect BIOs support BIO_puts() but not BIO_gets().
+
+If the close flag is set on a connect BIO then any active
+connection is shutdown and the socket closed when the BIO
+is freed.
+
+Calling BIO_reset() on a connect BIO will close any active
+connection and reset the BIO into a state where it can connect
+to the same host again.
+
+BIO_get_fd() places the underlying socket in B<c> if it is not NULL,
+it also returns the socket . If B<c> is not NULL it should be of
+type (int *).
+
+BIO_set_conn_hostname() uses the string B<name> to set the hostname.
+The hostname can be an IP address. The hostname can also include the
+port in the form hostname:port . It is also acceptable to use the
+form "hostname/any/other/path" or "hostname:port/any/other/path".
+
+BIO_set_conn_port() sets the port to B<port>. B<port> can be the
+numerical form or a string such as "http". A string will be looked
+up first using getservbyname() on the host platform but if that
+fails a standard table of port names will be used. Currently the
+list is http, telnet, socks, https, ssl, ftp, gopher and wais.
+
+BIO_set_conn_ip() sets the IP address to B<ip> using binary form,
+that is four bytes specifying the IP address in big-endian form.
+
+BIO_set_conn_int_port() sets the port using B<port>. B<port> should
+be of type (int *).
+
+BIO_get_conn_hostname() returns the hostname of the connect BIO or
+NULL if the BIO is initialized but no hostname is set.
+This return value is an internal pointer which should not be modified.
+
+BIO_get_conn_port() returns the port as a string.
+
+BIO_get_conn_ip() returns the IP address in binary form.
+
+BIO_get_conn_int_port() returns the port as an int.
+
+BIO_set_nbio() sets the non blocking I/O flag to B<n>. If B<n> is
+zero then blocking I/O is set. If B<n> is 1 then non blocking I/O
+is set. Blocking I/O is the default. The call to BIO_set_nbio()
+should be made before the connection is established because 
+non blocking I/O is set during the connect process.
+
+BIO_new_connect() combines BIO_new() and BIO_set_conn_hostname() into
+a single call: that is it creates a new connect BIO with B<name>.
+
+BIO_do_connect() attempts to connect the supplied BIO. It returns 1
+if the connection was established successfully. A zero or negative
+value is returned if the connection could not be established, the
+call BIO_should_retry() should be used for non blocking connect BIOs
+to determine if the call should be retried.
+
+=head1 NOTES
+
+If blocking I/O is set then a non positive return value from any
+I/O call is caused by an error condition, although a zero return
+will normally mean that the connection was closed.
+
+If the port name is supplied as part of the host name then this will
+override any value set with BIO_set_conn_port(). This may be undesirable
+if the application does not wish to allow connection to arbitrary
+ports. This can be avoided by checking for the presence of the ':'
+character in the passed hostname and either indicating an error or
+truncating the string at that point.
+
+The values returned by BIO_get_conn_hostname(), BIO_get_conn_port(),
+BIO_get_conn_ip() and BIO_get_conn_int_port() are updated when a
+connection attempt is made. Before any connection attempt the values
+returned are those set by the application itself.
+
+Applications do not have to call BIO_do_connect() but may wish to do
+so to separate the connection process from other I/O processing.
+
+If non blocking I/O is set then retries will be requested as appropriate.
+
+It addition to BIO_should_read() and BIO_should_write() it is also
+possible for BIO_should_io_special() to be true during the initial
+connection process with the reason BIO_RR_CONNECT. If this is returned
+then this is an indication that a connection attempt would block,
+the application should then take appropriate action to wait until
+the underlying socket has connected and retry the call.
+
+BIO_set_conn_hostname(), BIO_set_conn_port(), BIO_set_conn_ip(),
+BIO_set_conn_int_port(), BIO_get_conn_hostname(), BIO_get_conn_port(),
+BIO_get_conn_ip(), BIO_get_conn_int_port(), BIO_set_nbio() and
+BIO_do_connect() are macros.
+
+=head1 RETURN VALUES
+
+BIO_s_connect() returns the connect BIO method.
+
+BIO_get_fd() returns the socket or -1 if the BIO has not
+been initialized.
+
+BIO_set_conn_hostname(), BIO_set_conn_port(), BIO_set_conn_ip() and
+BIO_set_conn_int_port() always return 1.
+
+BIO_get_conn_hostname() returns the connected hostname or NULL is
+none was set.
+
+BIO_get_conn_port() returns a string representing the connected
+port or NULL if not set.
+
+BIO_get_conn_ip() returns a pointer to the connected IP address in
+binary form or all zeros if not set.
+
+BIO_get_conn_int_port() returns the connected port or 0 if none was
+set.
+
+BIO_set_nbio() always returns 1.
+
+BIO_do_connect() returns 1 if the connection was successfully
+established and 0 or -1 if the connection failed.
+
+=head1 EXAMPLE
+
+This is example connects to a webserver on the local host and attempts
+to retrieve a page and copy the result to standard output.
+
+
+ BIO *cbio, *out;
+ int len;
+ char tmpbuf[1024];
+ ERR_load_crypto_strings();
+ cbio = BIO_new_connect("localhost:http");
+ out = BIO_new_fp(stdout, BIO_NOCLOSE);
+ if(BIO_do_connect(cbio) <= 0) {
+       fprintf(stderr, "Error connecting to server\n");
+       ERR_print_errors_fp(stderr);
+       /* whatever ... */
+       }
+ BIO_puts(cbio, "GET / HTTP/1.0\n\n");
+ for(;;) {     
+       len = BIO_read(cbio, tmpbuf, 1024);
+       if(len <= 0) break;
+       BIO_write(out, tmpbuf, len);
+ }
+ BIO_free(cbio);
+ BIO_free(out);
+
+
+=head1 SEE ALSO
+
+TBA
diff --git a/deps/openssl/openssl/doc/crypto/BIO_s_fd.pod b/deps/openssl/openssl/doc/crypto/BIO_s_fd.pod
new file mode 100644 (file)
index 0000000..b1de1d1
--- /dev/null
@@ -0,0 +1,89 @@
+=pod
+
+=head1 NAME
+
+BIO_s_fd, BIO_set_fd, BIO_get_fd, BIO_new_fd - file descriptor BIO
+
+=head1 SYNOPSIS
+
+ #include <openssl/bio.h>
+
+ BIO_METHOD *  BIO_s_fd(void);
+
+ #define BIO_set_fd(b,fd,c)    BIO_int_ctrl(b,BIO_C_SET_FD,c,fd)
+ #define BIO_get_fd(b,c)       BIO_ctrl(b,BIO_C_GET_FD,0,(char *)c)
+
+ BIO *BIO_new_fd(int fd, int close_flag);
+
+=head1 DESCRIPTION
+
+BIO_s_fd() returns the file descriptor BIO method. This is a wrapper
+round the platforms file descriptor routines such as read() and write().
+
+BIO_read() and BIO_write() read or write the underlying descriptor.
+BIO_puts() is supported but BIO_gets() is not.
+
+If the close flag is set then then close() is called on the underlying
+file descriptor when the BIO is freed.
+
+BIO_reset() attempts to change the file pointer to the start of file
+using lseek(fd, 0, 0).
+
+BIO_seek() sets the file pointer to position B<ofs> from start of file
+using lseek(fd, ofs, 0).
+
+BIO_tell() returns the current file position by calling lseek(fd, 0, 1).
+
+BIO_set_fd() sets the file descriptor of BIO B<b> to B<fd> and the close
+flag to B<c>.
+
+BIO_get_fd() places the file descriptor in B<c> if it is not NULL, it also
+returns the file descriptor. If B<c> is not NULL it should be of type
+(int *).
+
+BIO_new_fd() returns a file descriptor BIO using B<fd> and B<close_flag>.
+
+=head1 NOTES
+
+The behaviour of BIO_read() and BIO_write() depends on the behavior of the
+platforms read() and write() calls on the descriptor. If the underlying 
+file descriptor is in a non blocking mode then the BIO will behave in the
+manner described in the L<BIO_read(3)|BIO_read(3)> and L<BIO_should_retry(3)|BIO_should_retry(3)>
+manual pages.
+
+File descriptor BIOs should not be used for socket I/O. Use socket BIOs
+instead.
+
+=head1 RETURN VALUES
+
+BIO_s_fd() returns the file descriptor BIO method.
+
+BIO_reset() returns zero for success and -1 if an error occurred.
+BIO_seek() and BIO_tell() return the current file position or -1
+is an error occurred. These values reflect the underlying lseek()
+behaviour.
+
+BIO_set_fd() always returns 1.
+
+BIO_get_fd() returns the file descriptor or -1 if the BIO has not
+been initialized.
+
+BIO_new_fd() returns the newly allocated BIO or NULL is an error
+occurred.
+
+=head1 EXAMPLE
+
+This is a file descriptor BIO version of "Hello World":
+
+ BIO *out;
+ out = BIO_new_fd(fileno(stdout), BIO_NOCLOSE);
+ BIO_printf(out, "Hello World\n");
+ BIO_free(out);
+
+=head1 SEE ALSO
+
+L<BIO_seek(3)|BIO_seek(3)>, L<BIO_tell(3)|BIO_tell(3)>,
+L<BIO_reset(3)|BIO_reset(3)>, L<BIO_read(3)|BIO_read(3)>,
+L<BIO_write(3)|BIO_write(3)>, L<BIO_puts(3)|BIO_puts(3)>,
+L<BIO_gets(3)|BIO_gets(3)>, L<BIO_printf(3)|BIO_printf(3)>,
+L<BIO_set_close(3)|BIO_set_close(3)>, L<BIO_get_close(3)|BIO_get_close(3)>
diff --git a/deps/openssl/openssl/doc/crypto/BIO_s_file.pod b/deps/openssl/openssl/doc/crypto/BIO_s_file.pod
new file mode 100644 (file)
index 0000000..188aea3
--- /dev/null
@@ -0,0 +1,148 @@
+=pod
+
+=head1 NAME
+
+BIO_s_file, BIO_new_file, BIO_new_fp, BIO_set_fp, BIO_get_fp,
+BIO_read_filename, BIO_write_filename, BIO_append_filename,
+BIO_rw_filename - FILE bio
+
+=head1 SYNOPSIS
+
+ #include <openssl/bio.h>
+
+ BIO_METHOD *  BIO_s_file(void);
+ BIO *BIO_new_file(const char *filename, const char *mode);
+ BIO *BIO_new_fp(FILE *stream, int flags);
+
+ BIO_set_fp(BIO *b,FILE *fp, int flags);
+ BIO_get_fp(BIO *b,FILE **fpp);
+
+ int BIO_read_filename(BIO *b, char *name)
+ int BIO_write_filename(BIO *b, char *name)
+ int BIO_append_filename(BIO *b, char *name)
+ int BIO_rw_filename(BIO *b, char *name)
+
+=head1 DESCRIPTION
+
+BIO_s_file() returns the BIO file method. As its name implies it
+is a wrapper round the stdio FILE structure and it is a
+source/sink BIO.
+
+Calls to BIO_read() and BIO_write() read and write data to the
+underlying stream. BIO_gets() and BIO_puts() are supported on file BIOs.
+
+BIO_flush() on a file BIO calls the fflush() function on the wrapped
+stream.
+
+BIO_reset() attempts to change the file pointer to the start of file
+using fseek(stream, 0, 0).
+
+BIO_seek() sets the file pointer to position B<ofs> from start of file
+using fseek(stream, ofs, 0).
+
+BIO_eof() calls feof().
+
+Setting the BIO_CLOSE flag calls fclose() on the stream when the BIO
+is freed.
+
+BIO_new_file() creates a new file BIO with mode B<mode> the meaning
+of B<mode> is the same as the stdio function fopen(). The BIO_CLOSE
+flag is set on the returned BIO.
+
+BIO_new_fp() creates a file BIO wrapping B<stream>. Flags can be:
+BIO_CLOSE, BIO_NOCLOSE (the close flag) BIO_FP_TEXT (sets the underlying
+stream to text mode, default is binary: this only has any effect under
+Win32).
+
+BIO_set_fp() set the fp of a file BIO to B<fp>. B<flags> has the same
+meaning as in BIO_new_fp(), it is a macro.
+
+BIO_get_fp() retrieves the fp of a file BIO, it is a macro.
+
+BIO_seek() is a macro that sets the position pointer to B<offset> bytes
+from the start of file.
+
+BIO_tell() returns the value of the position pointer.
+
+BIO_read_filename(), BIO_write_filename(), BIO_append_filename() and
+BIO_rw_filename() set the file BIO B<b> to use file B<name> for
+reading, writing, append or read write respectively.
+
+=head1 NOTES
+
+When wrapping stdout, stdin or stderr the underlying stream should not
+normally be closed so the BIO_NOCLOSE flag should be set.
+
+Because the file BIO calls the underlying stdio functions any quirks
+in stdio behaviour will be mirrored by the corresponding BIO.
+
+On Windows BIO_new_files reserves for the filename argument to be
+UTF-8 encoded. In other words if you have to make it work in multi-
+lingual environment, encode file names in UTF-8.
+
+=head1 EXAMPLES
+
+File BIO "hello world":
+
+ BIO *bio_out;
+ bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
+ BIO_printf(bio_out, "Hello World\n");
+
+Alternative technique:
+
+ BIO *bio_out;
+ bio_out = BIO_new(BIO_s_file());
+ if(bio_out == NULL) /* Error ... */
+ if(!BIO_set_fp(bio_out, stdout, BIO_NOCLOSE)) /* Error ... */
+ BIO_printf(bio_out, "Hello World\n");
+
+Write to a file:
+
+ BIO *out;
+ out = BIO_new_file("filename.txt", "w");
+ if(!out) /* Error occurred */
+ BIO_printf(out, "Hello World\n");
+ BIO_free(out);
+
+Alternative technique:
+
+ BIO *out;
+ out = BIO_new(BIO_s_file());
+ if(out == NULL) /* Error ... */
+ if(!BIO_write_filename(out, "filename.txt")) /* Error ... */
+ BIO_printf(out, "Hello World\n");
+ BIO_free(out);
+
+=head1 RETURN VALUES
+
+BIO_s_file() returns the file BIO method.
+
+BIO_new_file() and BIO_new_fp() return a file BIO or NULL if an error
+occurred.
+
+BIO_set_fp() and BIO_get_fp() return 1 for success or 0 for failure
+(although the current implementation never return 0).
+
+BIO_seek() returns the same value as the underlying fseek() function:
+0 for success or -1 for failure.
+
+BIO_tell() returns the current file position.
+
+BIO_read_filename(), BIO_write_filename(),  BIO_append_filename() and
+BIO_rw_filename() return 1 for success or 0 for failure.
+
+=head1 BUGS
+
+BIO_reset() and BIO_seek() are implemented using fseek() on the underlying
+stream. The return value for fseek() is 0 for success or -1 if an error
+occurred this differs from other types of BIO which will typically return
+1 for success and a non positive value if an error occurred.
+
+=head1 SEE ALSO
+
+L<BIO_seek(3)|BIO_seek(3)>, L<BIO_tell(3)|BIO_tell(3)>,
+L<BIO_reset(3)|BIO_reset(3)>, L<BIO_flush(3)|BIO_flush(3)>,
+L<BIO_read(3)|BIO_read(3)>,
+L<BIO_write(3)|BIO_write(3)>, L<BIO_puts(3)|BIO_puts(3)>,
+L<BIO_gets(3)|BIO_gets(3)>, L<BIO_printf(3)|BIO_printf(3)>,
+L<BIO_set_close(3)|BIO_set_close(3)>, L<BIO_get_close(3)|BIO_get_close(3)>
diff --git a/deps/openssl/openssl/doc/crypto/BIO_s_mem.pod b/deps/openssl/openssl/doc/crypto/BIO_s_mem.pod
new file mode 100644 (file)
index 0000000..8f85e0d
--- /dev/null
@@ -0,0 +1,115 @@
+=pod
+
+=head1 NAME
+
+BIO_s_mem, BIO_set_mem_eof_return, BIO_get_mem_data, BIO_set_mem_buf,
+BIO_get_mem_ptr, BIO_new_mem_buf - memory BIO
+
+=head1 SYNOPSIS
+
+ #include <openssl/bio.h>
+
+ BIO_METHOD *  BIO_s_mem(void);
+
+ BIO_set_mem_eof_return(BIO *b,int v)
+ long BIO_get_mem_data(BIO *b, char **pp)
+ BIO_set_mem_buf(BIO *b,BUF_MEM *bm,int c)
+ BIO_get_mem_ptr(BIO *b,BUF_MEM **pp)
+
+ BIO *BIO_new_mem_buf(void *buf, int len);
+
+=head1 DESCRIPTION
+
+BIO_s_mem() return the memory BIO method function. 
+
+A memory BIO is a source/sink BIO which uses memory for its I/O. Data
+written to a memory BIO is stored in a BUF_MEM structure which is extended
+as appropriate to accommodate the stored data.
+
+Any data written to a memory BIO can be recalled by reading from it.
+Unless the memory BIO is read only any data read from it is deleted from
+the BIO.
+
+Memory BIOs support BIO_gets() and BIO_puts().
+
+If the BIO_CLOSE flag is set when a memory BIO is freed then the underlying
+BUF_MEM structure is also freed.
+
+Calling BIO_reset() on a read write memory BIO clears any data in it. On a
+read only BIO it restores the BIO to its original state and the read only
+data can be read again.
+
+BIO_eof() is true if no data is in the BIO.
+
+BIO_ctrl_pending() returns the number of bytes currently stored.
+
+BIO_set_mem_eof_return() sets the behaviour of memory BIO B<b> when it is
+empty. If the B<v> is zero then an empty memory BIO will return EOF (that is
+it will return zero and BIO_should_retry(b) will be false. If B<v> is non
+zero then it will return B<v> when it is empty and it will set the read retry
+flag (that is BIO_read_retry(b) is true). To avoid ambiguity with a normal
+positive return value B<v> should be set to a negative value, typically -1.
+
+BIO_get_mem_data() sets B<pp> to a pointer to the start of the memory BIOs data
+and returns the total amount of data available. It is implemented as a macro.
+
+BIO_set_mem_buf() sets the internal BUF_MEM structure to B<bm> and sets the
+close flag to B<c>, that is B<c> should be either BIO_CLOSE or BIO_NOCLOSE.
+It is a macro.
+
+BIO_get_mem_ptr() places the underlying BUF_MEM structure in B<pp>. It is
+a macro.
+
+BIO_new_mem_buf() creates a memory BIO using B<len> bytes of data at B<buf>,
+if B<len> is -1 then the B<buf> is assumed to be null terminated and its
+length is determined by B<strlen>. The BIO is set to a read only state and
+as a result cannot be written to. This is useful when some data needs to be
+made available from a static area of memory in the form of a BIO. The
+supplied data is read directly from the supplied buffer: it is B<not> copied
+first, so the supplied area of memory must be unchanged until the BIO is freed.
+
+=head1 NOTES
+
+Writes to memory BIOs will always succeed if memory is available: that is
+their size can grow indefinitely.
+
+Every read from a read write memory BIO will remove the data just read with
+an internal copy operation, if a BIO contains a lot of data and it is
+read in small chunks the operation can be very slow. The use of a read only
+memory BIO avoids this problem. If the BIO must be read write then adding
+a buffering BIO to the chain will speed up the process.
+
+=head1 BUGS
+
+There should be an option to set the maximum size of a memory BIO.
+
+There should be a way to "rewind" a read write BIO without destroying
+its contents.
+
+The copying operation should not occur after every small read of a large BIO
+to improve efficiency.
+
+=head1 EXAMPLE
+
+Create a memory BIO and write some data to it:
+
+ BIO *mem = BIO_new(BIO_s_mem());
+ BIO_puts(mem, "Hello World\n"); 
+
+Create a read only memory BIO:
+
+ char data[] = "Hello World";
+ BIO *mem;
+ mem = BIO_new_mem_buf(data, -1);
+
+Extract the BUF_MEM structure from a memory BIO and then free up the BIO:
+
+ BUF_MEM *bptr;
+ BIO_get_mem_ptr(mem, &bptr);
+ BIO_set_close(mem, BIO_NOCLOSE); /* So BIO_free() leaves BUF_MEM alone */
+ BIO_free(mem);
+
+=head1 SEE ALSO
+
+TBA
diff --git a/deps/openssl/openssl/doc/crypto/BIO_s_null.pod b/deps/openssl/openssl/doc/crypto/BIO_s_null.pod
new file mode 100644 (file)
index 0000000..e5514f7
--- /dev/null
@@ -0,0 +1,37 @@
+=pod
+
+=head1 NAME
+
+BIO_s_null - null data sink
+
+=head1 SYNOPSIS
+
+ #include <openssl/bio.h>
+
+ BIO_METHOD *  BIO_s_null(void);
+
+=head1 DESCRIPTION
+
+BIO_s_null() returns the null sink BIO method. Data written to
+the null sink is discarded, reads return EOF.
+
+=head1 NOTES
+
+A null sink BIO behaves in a similar manner to the Unix /dev/null
+device.
+
+A null bio can be placed on the end of a chain to discard any data
+passed through it.
+
+A null sink is useful if, for example, an application wishes to digest some
+data by writing through a digest bio but not send the digested data anywhere.
+Since a BIO chain must normally include a source/sink BIO this can be achieved
+by adding a null sink BIO to the end of the chain
+
+=head1 RETURN VALUES
+
+BIO_s_null() returns the null sink BIO method.
+
+=head1 SEE ALSO
+
+TBA
diff --git a/deps/openssl/openssl/doc/crypto/BIO_s_socket.pod b/deps/openssl/openssl/doc/crypto/BIO_s_socket.pod
new file mode 100644 (file)
index 0000000..1c8d3a9
--- /dev/null
@@ -0,0 +1,63 @@
+=pod
+
+=head1 NAME
+
+BIO_s_socket, BIO_new_socket - socket BIO
+
+=head1 SYNOPSIS
+
+ #include <openssl/bio.h>
+
+ BIO_METHOD *BIO_s_socket(void);
+
+ long BIO_set_fd(BIO *b, int fd, long close_flag);
+ long BIO_get_fd(BIO *b, int *c);
+
+ BIO *BIO_new_socket(int sock, int close_flag);
+
+=head1 DESCRIPTION
+
+BIO_s_socket() returns the socket BIO method. This is a wrapper
+round the platform's socket routines.
+
+BIO_read() and BIO_write() read or write the underlying socket.
+BIO_puts() is supported but BIO_gets() is not.
+
+If the close flag is set then the socket is shut down and closed
+when the BIO is freed.
+
+BIO_set_fd() sets the socket of BIO B<b> to B<fd> and the close
+flag to B<close_flag>.
+
+BIO_get_fd() places the socket in B<c> if it is not NULL, it also
+returns the socket. If B<c> is not NULL it should be of type (int *).
+
+BIO_new_socket() returns a socket BIO using B<sock> and B<close_flag>.
+
+=head1 NOTES
+
+Socket BIOs also support any relevant functionality of file descriptor
+BIOs.
+
+The reason for having separate file descriptor and socket BIOs is that on some
+platforms sockets are not file descriptors and use distinct I/O routines,
+Windows is one such platform. Any code mixing the two will not work on
+all platforms.
+
+BIO_set_fd() and BIO_get_fd() are macros.
+
+=head1 RETURN VALUES
+
+BIO_s_socket() returns the socket BIO method.
+
+BIO_set_fd() always returns 1.
+
+BIO_get_fd() returns the socket or -1 if the BIO has not been
+initialized.
+
+BIO_new_socket() returns the newly allocated BIO or NULL is an error
+occurred.
+
+=head1 SEE ALSO
+
+TBA
diff --git a/deps/openssl/openssl/doc/crypto/BIO_set_callback.pod b/deps/openssl/openssl/doc/crypto/BIO_set_callback.pod
new file mode 100644 (file)
index 0000000..4759556
--- /dev/null
@@ -0,0 +1,108 @@
+=pod
+
+=head1 NAME
+
+BIO_set_callback, BIO_get_callback, BIO_set_callback_arg, BIO_get_callback_arg,
+BIO_debug_callback - BIO callback functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/bio.h>
+
+ #define BIO_set_callback(b,cb)                ((b)->callback=(cb))
+ #define BIO_get_callback(b)           ((b)->callback)
+ #define BIO_set_callback_arg(b,arg)   ((b)->cb_arg=(char *)(arg))
+ #define BIO_get_callback_arg(b)               ((b)->cb_arg)
+
+ long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi,
+       long argl,long ret);
+
+ typedef long (*callback)(BIO *b, int oper, const char *argp,
+                       int argi, long argl, long retvalue);
+
+=head1 DESCRIPTION
+
+BIO_set_callback() and BIO_get_callback() set and retrieve the BIO callback,
+they are both macros. The callback is called during most high level BIO
+operations. It can be used for debugging purposes to trace operations on
+a BIO or to modify its operation.
+
+BIO_set_callback_arg() and BIO_get_callback_arg() are macros which can be
+used to set and retrieve an argument for use in the callback.
+
+BIO_debug_callback() is a standard debugging callback which prints
+out information relating to each BIO operation. If the callback
+argument is set if is interpreted as a BIO to send the information
+to, otherwise stderr is used.
+
+callback() is the callback function itself. The meaning of each
+argument is described below.
+
+The BIO the callback is attached to is passed in B<b>.
+
+B<oper> is set to the operation being performed. For some operations
+the callback is called twice, once before and once after the actual
+operation, the latter case has B<oper> or'ed with BIO_CB_RETURN.
+
+The meaning of the arguments B<argp>, B<argi> and B<argl> depends on
+the value of B<oper>, that is the operation being performed.
+
+B<retvalue> is the return value that would be returned to the
+application if no callback were present. The actual value returned
+is the return value of the callback itself. In the case of callbacks
+called before the actual BIO operation 1 is placed in retvalue, if
+the return value is not positive it will be immediately returned to
+the application and the BIO operation will not be performed.
+
+The callback should normally simply return B<retvalue> when it has
+finished processing, unless if specifically wishes to modify the
+value returned to the application.
+
+=head1 CALLBACK OPERATIONS
+
+=over 4
+
+=item B<BIO_free(b)>
+
+callback(b, BIO_CB_FREE, NULL, 0L, 0L, 1L) is called before the
+free operation.
+
+=item B<BIO_read(b, out, outl)>
+
+callback(b, BIO_CB_READ, out, outl, 0L, 1L) is called before
+the read and callback(b, BIO_CB_READ|BIO_CB_RETURN, out, outl, 0L, retvalue)
+after.
+
+=item B<BIO_write(b, in, inl)>
+
+callback(b, BIO_CB_WRITE, in, inl, 0L, 1L) is called before
+the write and callback(b, BIO_CB_WRITE|BIO_CB_RETURN, in, inl, 0L, retvalue)
+after.
+
+=item B<BIO_gets(b, out, outl)>
+
+callback(b, BIO_CB_GETS, out, outl, 0L, 1L) is called before
+the operation and callback(b, BIO_CB_GETS|BIO_CB_RETURN, out, outl, 0L, retvalue)
+after.
+
+=item B<BIO_puts(b, in)>
+
+callback(b, BIO_CB_WRITE, in, 0, 0L, 1L) is called before
+the operation and callback(b, BIO_CB_WRITE|BIO_CB_RETURN, in, 0, 0L, retvalue)
+after.
+
+=item B<BIO_ctrl(BIO *b, int cmd, long larg, void *parg)>
+
+callback(b,BIO_CB_CTRL,parg,cmd,larg,1L) is called before the call and
+callback(b,BIO_CB_CTRL|BIO_CB_RETURN,parg,cmd, larg,ret) after.
+
+=back
+
+=head1 EXAMPLE
+
+The BIO_debug_callback() function is a good example, its source is
+in crypto/bio/bio_cb.c
+
+=head1 SEE ALSO
+
+TBA
diff --git a/deps/openssl/openssl/doc/crypto/BIO_should_retry.pod b/deps/openssl/openssl/doc/crypto/BIO_should_retry.pod
new file mode 100644 (file)
index 0000000..b6d51f7
--- /dev/null
@@ -0,0 +1,114 @@
+=pod
+
+=head1 NAME
+
+BIO_should_retry, BIO_should_read, BIO_should_write,
+BIO_should_io_special, BIO_retry_type, BIO_should_retry,
+BIO_get_retry_BIO, BIO_get_retry_reason - BIO retry functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/bio.h>
+
+ #define BIO_should_read(a)            ((a)->flags & BIO_FLAGS_READ)
+ #define BIO_should_write(a)           ((a)->flags & BIO_FLAGS_WRITE)
+ #define BIO_should_io_special(a)      ((a)->flags & BIO_FLAGS_IO_SPECIAL)
+ #define BIO_retry_type(a)             ((a)->flags & BIO_FLAGS_RWS)
+ #define BIO_should_retry(a)           ((a)->flags & BIO_FLAGS_SHOULD_RETRY)
+
+ #define BIO_FLAGS_READ                0x01
+ #define BIO_FLAGS_WRITE       0x02
+ #define BIO_FLAGS_IO_SPECIAL  0x04
+ #define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL)
+ #define BIO_FLAGS_SHOULD_RETRY        0x08
+
+ BIO * BIO_get_retry_BIO(BIO *bio, int *reason);
+ int   BIO_get_retry_reason(BIO *bio);
+
+=head1 DESCRIPTION
+
+These functions determine why a BIO is not able to read or write data.
+They will typically be called after a failed BIO_read() or BIO_write()
+call.
+
+BIO_should_retry() is true if the call that produced this condition
+should then be retried at a later time.
+
+If BIO_should_retry() is false then the cause is an error condition.
+
+BIO_should_read() is true if the cause of the condition is that a BIO
+needs to read data.
+
+BIO_should_write() is true if the cause of the condition is that a BIO
+needs to read data.
+
+BIO_should_io_special() is true if some "special" condition, that is a
+reason other than reading or writing is the cause of the condition.
+
+BIO_retry_type() returns a mask of the cause of a retry condition
+consisting of the values B<BIO_FLAGS_READ>, B<BIO_FLAGS_WRITE>,
+B<BIO_FLAGS_IO_SPECIAL> though current BIO types will only set one of
+these.
+
+BIO_get_retry_BIO() determines the precise reason for the special
+condition, it returns the BIO that caused this condition and if 
+B<reason> is not NULL it contains the reason code. The meaning of
+the reason code and the action that should be taken depends on
+the type of BIO that resulted in this condition.
+
+BIO_get_retry_reason() returns the reason for a special condition if
+passed the relevant BIO, for example as returned by BIO_get_retry_BIO().
+
+=head1 NOTES
+
+If BIO_should_retry() returns false then the precise "error condition"
+depends on the BIO type that caused it and the return code of the BIO
+operation. For example if a call to BIO_read() on a socket BIO returns
+0 and BIO_should_retry() is false then the cause will be that the
+connection closed. A similar condition on a file BIO will mean that it
+has reached EOF. Some BIO types may place additional information on
+the error queue. For more details see the individual BIO type manual
+pages.
+
+If the underlying I/O structure is in a blocking mode almost all current
+BIO types will not request a retry, because the underlying I/O
+calls will not. If the application knows that the BIO type will never
+signal a retry then it need not call BIO_should_retry() after a failed
+BIO I/O call. This is typically done with file BIOs.
+
+SSL BIOs are the only current exception to this rule: they can request a
+retry even if the underlying I/O structure is blocking, if a handshake
+occurs during a call to BIO_read(). An application can retry the failed
+call immediately or avoid this situation by setting SSL_MODE_AUTO_RETRY
+on the underlying SSL structure.
+
+While an application may retry a failed non blocking call immediately
+this is likely to be very inefficient because the call will fail
+repeatedly until data can be processed or is available. An application
+will normally wait until the necessary condition is satisfied. How
+this is done depends on the underlying I/O structure.
+
+For example if the cause is ultimately a socket and BIO_should_read()
+is true then a call to select() may be made to wait until data is
+available and then retry the BIO operation. By combining the retry
+conditions of several non blocking BIOs in a single select() call
+it is possible to service several BIOs in a single thread, though
+the performance may be poor if SSL BIOs are present because long delays
+can occur during the initial handshake process. 
+
+It is possible for a BIO to block indefinitely if the underlying I/O
+structure cannot process or return any data. This depends on the behaviour of
+the platforms I/O functions. This is often not desirable: one solution
+is to use non blocking I/O and use a timeout on the select() (or
+equivalent) call.
+
+=head1 BUGS
+
+The OpenSSL ASN1 functions cannot gracefully deal with non blocking I/O:
+that is they cannot retry after a partial read or write. This is usually
+worked around by only passing the relevant data to ASN1 functions when
+the entire structure can be read or written.
+
+=head1 SEE ALSO
+
+TBA
diff --git a/deps/openssl/openssl/doc/crypto/BN_BLINDING_new.pod b/deps/openssl/openssl/doc/crypto/BN_BLINDING_new.pod
new file mode 100644 (file)
index 0000000..5f51fdb
--- /dev/null
@@ -0,0 +1,115 @@
+=pod
+
+=head1 NAME
+
+BN_BLINDING_new, BN_BLINDING_free, BN_BLINDING_update, BN_BLINDING_convert, 
+BN_BLINDING_invert, BN_BLINDING_convert_ex, BN_BLINDING_invert_ex, 
+BN_BLINDING_get_thread_id, BN_BLINDING_set_thread_id, BN_BLINDING_get_flags,
+BN_BLINDING_set_flags, BN_BLINDING_create_param - blinding related BIGNUM
+functions.
+
+=head1 SYNOPSIS
+
+ #include <openssl/bn.h>
+
+ BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai,
+       BIGNUM *mod);
+ void BN_BLINDING_free(BN_BLINDING *b);
+ int BN_BLINDING_update(BN_BLINDING *b,BN_CTX *ctx);
+ int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
+ int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
+ int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b,
+       BN_CTX *ctx);
+ int BN_BLINDING_invert_ex(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b,
+       BN_CTX *ctx);
+ #ifndef OPENSSL_NO_DEPRECATED
+ unsigned long BN_BLINDING_get_thread_id(const BN_BLINDING *);
+ void BN_BLINDING_set_thread_id(BN_BLINDING *, unsigned long);
+ #endif
+ CRYPTO_THREADID *BN_BLINDING_thread_id(BN_BLINDING *);
+ unsigned long BN_BLINDING_get_flags(const BN_BLINDING *);
+ void BN_BLINDING_set_flags(BN_BLINDING *, unsigned long);
+ BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b,
+       const BIGNUM *e, BIGNUM *m, BN_CTX *ctx,
+       int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
+                         const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx),
+       BN_MONT_CTX *m_ctx);
+
+=head1 DESCRIPTION
+
+BN_BLINDING_new() allocates a new B<BN_BLINDING> structure and copies
+the B<A> and B<Ai> values into the newly created B<BN_BLINDING> object.
+
+BN_BLINDING_free() frees the B<BN_BLINDING> structure.
+
+BN_BLINDING_update() updates the B<BN_BLINDING> parameters by squaring
+the B<A> and B<Ai> or, after specific number of uses and if the
+necessary parameters are set, by re-creating the blinding parameters.
+
+BN_BLINDING_convert_ex() multiplies B<n> with the blinding factor B<A>.
+If B<r> is not NULL a copy the inverse blinding factor B<Ai> will be
+returned in B<r> (this is useful if a B<RSA> object is shared amoung
+several threads). BN_BLINDING_invert_ex() multiplies B<n> with the
+inverse blinding factor B<Ai>. If B<r> is not NULL it will be used as
+the inverse blinding.
+
+BN_BLINDING_convert() and BN_BLINDING_invert() are wrapper
+functions for BN_BLINDING_convert_ex() and BN_BLINDING_invert_ex()
+with B<r> set to NULL.
+
+BN_BLINDING_thread_id() provides access to the B<CRYPTO_THREADID>
+object within the B<BN_BLINDING> structure. This is to help users
+provide proper locking if needed for multi-threaded use. The "thread
+id" object of a newly allocated B<BN_BLINDING> structure is
+initialised to the thread id in which BN_BLINDING_new() was called.
+
+BN_BLINDING_get_flags() returns the BN_BLINDING flags. Currently
+there are two supported flags: B<BN_BLINDING_NO_UPDATE> and
+B<BN_BLINDING_NO_RECREATE>. B<BN_BLINDING_NO_UPDATE> inhibits the
+automatic update of the B<BN_BLINDING> parameters after each use
+and B<BN_BLINDING_NO_RECREATE> inhibits the automatic re-creation
+of the B<BN_BLINDING> parameters after a fixed number of uses (currently
+32). In newly allocated B<BN_BLINDING> objects no flags are set.
+BN_BLINDING_set_flags() sets the B<BN_BLINDING> parameters flags.
+
+BN_BLINDING_create_param() creates new B<BN_BLINDING> parameters
+using the exponent B<e> and the modulus B<m>. B<bn_mod_exp> and
+B<m_ctx> can be used to pass special functions for exponentiation
+(normally BN_mod_exp_mont() and B<BN_MONT_CTX>).
+
+=head1 RETURN VALUES
+
+BN_BLINDING_new() returns the newly allocated B<BN_BLINDING> structure
+or NULL in case of an error.
+
+BN_BLINDING_update(), BN_BLINDING_convert(), BN_BLINDING_invert(),
+BN_BLINDING_convert_ex() and BN_BLINDING_invert_ex() return 1 on
+success and 0 if an error occured.
+
+BN_BLINDING_thread_id() returns a pointer to the thread id object
+within a B<BN_BLINDING> object.
+
+BN_BLINDING_get_flags() returns the currently set B<BN_BLINDING> flags
+(a B<unsigned long> value).
+
+BN_BLINDING_create_param() returns the newly created B<BN_BLINDING> 
+parameters or NULL on error.
+
+=head1 SEE ALSO
+
+L<bn(3)|bn(3)>
+
+=head1 HISTORY
+
+BN_BLINDING_thread_id was first introduced in OpenSSL 1.0.0, and it
+deprecates BN_BLINDING_set_thread_id and BN_BLINDING_get_thread_id.
+
+BN_BLINDING_convert_ex, BN_BLINDIND_invert_ex, BN_BLINDING_get_thread_id,
+BN_BLINDING_set_thread_id, BN_BLINDING_set_flags, BN_BLINDING_get_flags
+and BN_BLINDING_create_param were first introduced in OpenSSL 0.9.8
+
+=head1 AUTHOR
+
+Nils Larsch for the OpenSSL project (http://www.openssl.org).
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/BN_CTX_new.pod b/deps/openssl/openssl/doc/crypto/BN_CTX_new.pod
new file mode 100644 (file)
index 0000000..ad8d07d
--- /dev/null
@@ -0,0 +1,53 @@
+=pod
+
+=head1 NAME
+
+BN_CTX_new, BN_CTX_init, BN_CTX_free - allocate and free BN_CTX structures
+
+=head1 SYNOPSIS
+
+ #include <openssl/bn.h>
+
+ BN_CTX *BN_CTX_new(void);
+
+ void BN_CTX_init(BN_CTX *c);
+
+ void BN_CTX_free(BN_CTX *c);
+
+=head1 DESCRIPTION
+
+A B<BN_CTX> is a structure that holds B<BIGNUM> temporary variables used by
+library functions. Since dynamic memory allocation to create B<BIGNUM>s
+is rather expensive when used in conjunction with repeated subroutine
+calls, the B<BN_CTX> structure is used.
+
+BN_CTX_new() allocates and initializes a B<BN_CTX>
+structure. BN_CTX_init() initializes an existing uninitialized
+B<BN_CTX>.
+
+BN_CTX_free() frees the components of the B<BN_CTX>, and if it was
+created by BN_CTX_new(), also the structure itself.
+If L<BN_CTX_start(3)|BN_CTX_start(3)> has been used on the B<BN_CTX>,
+L<BN_CTX_end(3)|BN_CTX_end(3)> must be called before the B<BN_CTX>
+may be freed by BN_CTX_free().
+
+
+=head1 RETURN VALUES
+
+BN_CTX_new() returns a pointer to the B<BN_CTX>. If the allocation fails,
+it returns B<NULL> and sets an error code that can be obtained by
+L<ERR_get_error(3)|ERR_get_error(3)>.
+
+BN_CTX_init() and BN_CTX_free() have no return values.
+
+=head1 SEE ALSO
+
+L<bn(3)|bn(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<BN_add(3)|BN_add(3)>,
+L<BN_CTX_start(3)|BN_CTX_start(3)>
+
+=head1 HISTORY
+
+BN_CTX_new() and BN_CTX_free() are available in all versions on SSLeay
+and OpenSSL. BN_CTX_init() was added in SSLeay 0.9.1b.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/BN_CTX_start.pod b/deps/openssl/openssl/doc/crypto/BN_CTX_start.pod
new file mode 100644 (file)
index 0000000..dfcefe1
--- /dev/null
@@ -0,0 +1,52 @@
+=pod
+
+=head1 NAME
+
+BN_CTX_start, BN_CTX_get, BN_CTX_end - use temporary BIGNUM variables
+
+=head1 SYNOPSIS
+
+ #include <openssl/bn.h>
+
+ void BN_CTX_start(BN_CTX *ctx);
+
+ BIGNUM *BN_CTX_get(BN_CTX *ctx);
+
+ void BN_CTX_end(BN_CTX *ctx);
+
+=head1 DESCRIPTION
+
+These functions are used to obtain temporary B<BIGNUM> variables from
+a B<BN_CTX> (which can been created by using L<BN_CTX_new(3)|BN_CTX_new(3)>)
+in order to save the overhead of repeatedly creating and
+freeing B<BIGNUM>s in functions that are called from inside a loop.
+
+A function must call BN_CTX_start() first. Then, BN_CTX_get() may be
+called repeatedly to obtain temporary B<BIGNUM>s. All BN_CTX_get()
+calls must be made before calling any other functions that use the
+B<ctx> as an argument.
+
+Finally, BN_CTX_end() must be called before returning from the function.
+When BN_CTX_end() is called, the B<BIGNUM> pointers obtained from
+BN_CTX_get() become invalid.
+
+=head1 RETURN VALUES
+
+BN_CTX_start() and BN_CTX_end() return no values.
+
+BN_CTX_get() returns a pointer to the B<BIGNUM>, or B<NULL> on error.
+Once BN_CTX_get() has failed, the subsequent calls will return B<NULL>
+as well, so it is sufficient to check the return value of the last
+BN_CTX_get() call. In case of an error, an error code is set, which
+can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+
+=head1 SEE ALSO
+
+L<BN_CTX_new(3)|BN_CTX_new(3)>
+
+=head1 HISTORY
+
+BN_CTX_start(), BN_CTX_get() and BN_CTX_end() were added in OpenSSL 0.9.5.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/BN_add.pod b/deps/openssl/openssl/doc/crypto/BN_add.pod
new file mode 100644 (file)
index 0000000..88c7a79
--- /dev/null
@@ -0,0 +1,126 @@
+=pod
+
+=head1 NAME
+
+BN_add, BN_sub, BN_mul, BN_sqr, BN_div, BN_mod, BN_nnmod, BN_mod_add,
+BN_mod_sub, BN_mod_mul, BN_mod_sqr, BN_exp, BN_mod_exp, BN_gcd -
+arithmetic operations on BIGNUMs
+
+=head1 SYNOPSIS
+
+ #include <openssl/bn.h>
+
+ int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
+
+ int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
+
+ int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
+
+ int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx);
+
+ int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *a, const BIGNUM *d,
+         BN_CTX *ctx);
+
+ int BN_mod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
+
+ int BN_nnmod(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
+
+ int BN_mod_add(BIGNUM *r, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
+         BN_CTX *ctx);
+
+ int BN_mod_sub(BIGNUM *r, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
+         BN_CTX *ctx);
+
+ int BN_mod_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
+         BN_CTX *ctx);
+
+ int BN_mod_sqr(BIGNUM *r, BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
+
+ int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx);
+
+ int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
+         const BIGNUM *m, BN_CTX *ctx);
+
+ int BN_gcd(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
+
+=head1 DESCRIPTION
+
+BN_add() adds I<a> and I<b> and places the result in I<r> (C<r=a+b>).
+I<r> may be the same B<BIGNUM> as I<a> or I<b>.
+
+BN_sub() subtracts I<b> from I<a> and places the result in I<r> (C<r=a-b>).
+
+BN_mul() multiplies I<a> and I<b> and places the result in I<r> (C<r=a*b>).
+I<r> may be the same B<BIGNUM> as I<a> or I<b>.
+For multiplication by powers of 2, use L<BN_lshift(3)|BN_lshift(3)>.
+
+BN_sqr() takes the square of I<a> and places the result in I<r>
+(C<r=a^2>). I<r> and I<a> may be the same B<BIGNUM>.
+This function is faster than BN_mul(r,a,a).
+
+BN_div() divides I<a> by I<d> and places the result in I<dv> and the
+remainder in I<rem> (C<dv=a/d, rem=a%d>). Either of I<dv> and I<rem> may
+be B<NULL>, in which case the respective value is not returned.
+The result is rounded towards zero; thus if I<a> is negative, the
+remainder will be zero or negative.
+For division by powers of 2, use BN_rshift(3).
+
+BN_mod() corresponds to BN_div() with I<dv> set to B<NULL>.
+
+BN_nnmod() reduces I<a> modulo I<m> and places the non-negative
+remainder in I<r>.
+
+BN_mod_add() adds I<a> to I<b> modulo I<m> and places the non-negative
+result in I<r>.
+
+BN_mod_sub() subtracts I<b> from I<a> modulo I<m> and places the
+non-negative result in I<r>.
+
+BN_mod_mul() multiplies I<a> by I<b> and finds the non-negative
+remainder respective to modulus I<m> (C<r=(a*b) mod m>). I<r> may be
+the same B<BIGNUM> as I<a> or I<b>. For more efficient algorithms for
+repeated computations using the same modulus, see
+L<BN_mod_mul_montgomery(3)|BN_mod_mul_montgomery(3)> and
+L<BN_mod_mul_reciprocal(3)|BN_mod_mul_reciprocal(3)>.
+
+BN_mod_sqr() takes the square of I<a> modulo B<m> and places the
+result in I<r>.
+
+BN_exp() raises I<a> to the I<p>-th power and places the result in I<r>
+(C<r=a^p>). This function is faster than repeated applications of
+BN_mul().
+
+BN_mod_exp() computes I<a> to the I<p>-th power modulo I<m> (C<r=a^p %
+m>). This function uses less time and space than BN_exp().
+
+BN_gcd() computes the greatest common divisor of I<a> and I<b> and
+places the result in I<r>. I<r> may be the same B<BIGNUM> as I<a> or
+I<b>.
+
+For all functions, I<ctx> is a previously allocated B<BN_CTX> used for
+temporary variables; see L<BN_CTX_new(3)|BN_CTX_new(3)>.
+
+Unless noted otherwise, the result B<BIGNUM> must be different from
+the arguments.
+
+=head1 RETURN VALUES
+
+For all functions, 1 is returned for success, 0 on error. The return
+value should always be checked (e.g., C<if (!BN_add(r,a,b)) goto err;>).
+The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 SEE ALSO
+
+L<bn(3)|bn(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<BN_CTX_new(3)|BN_CTX_new(3)>,
+L<BN_add_word(3)|BN_add_word(3)>, L<BN_set_bit(3)|BN_set_bit(3)>
+
+=head1 HISTORY
+
+BN_add(), BN_sub(), BN_sqr(), BN_div(), BN_mod(), BN_mod_mul(),
+BN_mod_exp() and BN_gcd() are available in all versions of SSLeay and
+OpenSSL. The I<ctx> argument to BN_mul() was added in SSLeay
+0.9.1b. BN_exp() appeared in SSLeay 0.9.0.
+BN_nnmod(), BN_mod_add(), BN_mod_sub(), and BN_mod_sqr() were added in
+OpenSSL 0.9.7.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/BN_add_word.pod b/deps/openssl/openssl/doc/crypto/BN_add_word.pod
new file mode 100644 (file)
index 0000000..70667d2
--- /dev/null
@@ -0,0 +1,61 @@
+=pod
+
+=head1 NAME
+
+BN_add_word, BN_sub_word, BN_mul_word, BN_div_word, BN_mod_word - arithmetic
+functions on BIGNUMs with integers
+
+=head1 SYNOPSIS
+
+ #include <openssl/bn.h>
+
+ int BN_add_word(BIGNUM *a, BN_ULONG w);
+
+ int BN_sub_word(BIGNUM *a, BN_ULONG w);
+
+ int BN_mul_word(BIGNUM *a, BN_ULONG w);
+
+ BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);
+
+ BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w);
+
+=head1 DESCRIPTION
+
+These functions perform arithmetic operations on BIGNUMs with unsigned
+integers. They are much more efficient than the normal BIGNUM
+arithmetic operations.
+
+BN_add_word() adds B<w> to B<a> (C<a+=w>).
+
+BN_sub_word() subtracts B<w> from B<a> (C<a-=w>).
+
+BN_mul_word() multiplies B<a> and B<w> (C<a*=w>).
+
+BN_div_word() divides B<a> by B<w> (C<a/=w>) and returns the remainder.
+
+BN_mod_word() returns the remainder of B<a> divided by B<w> (C<a%w>).
+
+For BN_div_word() and BN_mod_word(), B<w> must not be 0.
+
+=head1 RETURN VALUES
+
+BN_add_word(), BN_sub_word() and BN_mul_word() return 1 for success, 0
+on error. The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+BN_mod_word() and BN_div_word() return B<a>%B<w> on success and
+B<(BN_ULONG)-1> if an error occurred.
+
+=head1 SEE ALSO
+
+L<bn(3)|bn(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<BN_add(3)|BN_add(3)>
+
+=head1 HISTORY
+
+BN_add_word() and BN_mod_word() are available in all versions of
+SSLeay and OpenSSL. BN_div_word() was added in SSLeay 0.8, and
+BN_sub_word() and BN_mul_word() in SSLeay 0.9.0.
+
+Before 0.9.8a the return value for BN_div_word() and BN_mod_word()
+in case of an error was 0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/BN_bn2bin.pod b/deps/openssl/openssl/doc/crypto/BN_bn2bin.pod
new file mode 100644 (file)
index 0000000..a4b17ca
--- /dev/null
@@ -0,0 +1,95 @@
+=pod
+
+=head1 NAME
+
+BN_bn2bin, BN_bin2bn, BN_bn2hex, BN_bn2dec, BN_hex2bn, BN_dec2bn,
+BN_print, BN_print_fp, BN_bn2mpi, BN_mpi2bn - format conversions
+
+=head1 SYNOPSIS
+
+ #include <openssl/bn.h>
+
+ int BN_bn2bin(const BIGNUM *a, unsigned char *to);
+ BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret);
+
+ char *BN_bn2hex(const BIGNUM *a);
+ char *BN_bn2dec(const BIGNUM *a);
+ int BN_hex2bn(BIGNUM **a, const char *str);
+ int BN_dec2bn(BIGNUM **a, const char *str);
+
+ int BN_print(BIO *fp, const BIGNUM *a);
+ int BN_print_fp(FILE *fp, const BIGNUM *a);
+
+ int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
+ BIGNUM *BN_mpi2bn(unsigned char *s, int len, BIGNUM *ret);
+
+=head1 DESCRIPTION
+
+BN_bn2bin() converts the absolute value of B<a> into big-endian form
+and stores it at B<to>. B<to> must point to BN_num_bytes(B<a>) bytes of
+memory.
+
+BN_bin2bn() converts the positive integer in big-endian form of length
+B<len> at B<s> into a B<BIGNUM> and places it in B<ret>. If B<ret> is
+NULL, a new B<BIGNUM> is created.
+
+BN_bn2hex() and BN_bn2dec() return printable strings containing the
+hexadecimal and decimal encoding of B<a> respectively. For negative
+numbers, the string is prefaced with a leading '-'. The string must be
+freed later using OPENSSL_free().
+
+BN_hex2bn() converts the string B<str> containing a hexadecimal number
+to a B<BIGNUM> and stores it in **B<bn>. If *B<bn> is NULL, a new
+B<BIGNUM> is created. If B<bn> is NULL, it only computes the number's
+length in hexadecimal digits. If the string starts with '-', the
+number is negative. BN_dec2bn() is the same using the decimal system.
+
+BN_print() and BN_print_fp() write the hexadecimal encoding of B<a>,
+with a leading '-' for negative numbers, to the B<BIO> or B<FILE>
+B<fp>.
+
+BN_bn2mpi() and BN_mpi2bn() convert B<BIGNUM>s from and to a format
+that consists of the number's length in bytes represented as a 4-byte
+big-endian number, and the number itself in big-endian format, where
+the most significant bit signals a negative number (the representation
+of numbers with the MSB set is prefixed with null byte).
+
+BN_bn2mpi() stores the representation of B<a> at B<to>, where B<to>
+must be large enough to hold the result. The size can be determined by
+calling BN_bn2mpi(B<a>, NULL).
+
+BN_mpi2bn() converts the B<len> bytes long representation at B<s> to
+a B<BIGNUM> and stores it at B<ret>, or in a newly allocated B<BIGNUM>
+if B<ret> is NULL.
+
+=head1 RETURN VALUES
+
+BN_bn2bin() returns the length of the big-endian number placed at B<to>.
+BN_bin2bn() returns the B<BIGNUM>, NULL on error.
+
+BN_bn2hex() and BN_bn2dec() return a null-terminated string, or NULL
+on error. BN_hex2bn() and BN_dec2bn() return the number's length in
+hexadecimal or decimal digits, and 0 on error.
+
+BN_print_fp() and BN_print() return 1 on success, 0 on write errors.
+
+BN_bn2mpi() returns the length of the representation. BN_mpi2bn()
+returns the B<BIGNUM>, and NULL on error.
+
+The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 SEE ALSO
+
+L<bn(3)|bn(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<BN_zero(3)|BN_zero(3)>,
+L<ASN1_INTEGER_to_BN(3)|ASN1_INTEGER_to_BN(3)>,
+L<BN_num_bytes(3)|BN_num_bytes(3)>
+
+=head1 HISTORY
+
+BN_bn2bin(), BN_bin2bn(), BN_print_fp() and BN_print() are available
+in all versions of SSLeay and OpenSSL.
+
+BN_bn2hex(), BN_bn2dec(), BN_hex2bn(), BN_dec2bn(), BN_bn2mpi() and
+BN_mpi2bn() were added in SSLeay 0.9.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/BN_cmp.pod b/deps/openssl/openssl/doc/crypto/BN_cmp.pod
new file mode 100644 (file)
index 0000000..23e9ed0
--- /dev/null
@@ -0,0 +1,48 @@
+=pod
+
+=head1 NAME
+
+BN_cmp, BN_ucmp, BN_is_zero, BN_is_one, BN_is_word, BN_is_odd - BIGNUM comparison and test functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/bn.h>
+
+ int BN_cmp(BIGNUM *a, BIGNUM *b);
+ int BN_ucmp(BIGNUM *a, BIGNUM *b);
+
+ int BN_is_zero(BIGNUM *a);
+ int BN_is_one(BIGNUM *a);
+ int BN_is_word(BIGNUM *a, BN_ULONG w);
+ int BN_is_odd(BIGNUM *a);
+
+=head1 DESCRIPTION
+
+BN_cmp() compares the numbers B<a> and B<b>. BN_ucmp() compares their
+absolute values.
+
+BN_is_zero(), BN_is_one() and BN_is_word() test if B<a> equals 0, 1,
+or B<w> respectively. BN_is_odd() tests if a is odd.
+
+BN_is_zero(), BN_is_one(), BN_is_word() and BN_is_odd() are macros.
+
+=head1 RETURN VALUES
+
+BN_cmp() returns -1 if B<a> E<lt> B<b>, 0 if B<a> == B<b> and 1 if
+B<a> E<gt> B<b>. BN_ucmp() is the same using the absolute values
+of B<a> and B<b>.
+
+BN_is_zero(), BN_is_one() BN_is_word() and BN_is_odd() return 1 if
+the condition is true, 0 otherwise.
+
+=head1 SEE ALSO
+
+L<bn(3)|bn(3)>
+
+=head1 HISTORY
+
+BN_cmp(), BN_ucmp(), BN_is_zero(), BN_is_one() and BN_is_word() are
+available in all versions of SSLeay and OpenSSL.
+BN_is_odd() was added in SSLeay 0.8.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/BN_copy.pod b/deps/openssl/openssl/doc/crypto/BN_copy.pod
new file mode 100644 (file)
index 0000000..388dd7d
--- /dev/null
@@ -0,0 +1,34 @@
+=pod
+
+=head1 NAME
+
+BN_copy, BN_dup - copy BIGNUMs
+
+=head1 SYNOPSIS
+
+ #include <openssl/bn.h>
+
+ BIGNUM *BN_copy(BIGNUM *to, const BIGNUM *from);
+
+ BIGNUM *BN_dup(const BIGNUM *from);
+
+=head1 DESCRIPTION
+
+BN_copy() copies B<from> to B<to>. BN_dup() creates a new B<BIGNUM>
+containing the value B<from>.
+
+=head1 RETURN VALUES
+
+BN_copy() returns B<to> on success, NULL on error. BN_dup() returns
+the new B<BIGNUM>, and NULL on error. The error codes can be obtained
+by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 SEE ALSO
+
+L<bn(3)|bn(3)>, L<ERR_get_error(3)|ERR_get_error(3)>
+
+=head1 HISTORY
+
+BN_copy() and BN_dup() are available in all versions of SSLeay and OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/BN_generate_prime.pod b/deps/openssl/openssl/doc/crypto/BN_generate_prime.pod
new file mode 100644 (file)
index 0000000..7dccacb
--- /dev/null
@@ -0,0 +1,102 @@
+=pod
+
+=head1 NAME
+
+BN_generate_prime, BN_is_prime, BN_is_prime_fasttest - generate primes and test for primality
+
+=head1 SYNOPSIS
+
+ #include <openssl/bn.h>
+
+ BIGNUM *BN_generate_prime(BIGNUM *ret, int num, int safe, BIGNUM *add,
+     BIGNUM *rem, void (*callback)(int, int, void *), void *cb_arg);
+
+ int BN_is_prime(const BIGNUM *a, int checks, void (*callback)(int, int, 
+     void *), BN_CTX *ctx, void *cb_arg);
+
+ int BN_is_prime_fasttest(const BIGNUM *a, int checks,
+     void (*callback)(int, int, void *), BN_CTX *ctx, void *cb_arg,
+     int do_trial_division);
+
+=head1 DESCRIPTION
+
+BN_generate_prime() generates a pseudo-random prime number of B<num>
+bits.
+If B<ret> is not B<NULL>, it will be used to store the number.
+
+If B<callback> is not B<NULL>, it is called as follows:
+
+=over 4
+
+=item *
+
+B<callback(0, i, cb_arg)> is called after generating the i-th
+potential prime number.
+
+=item *
+
+While the number is being tested for primality, B<callback(1, j,
+cb_arg)> is called as described below.
+
+=item *
+
+When a prime has been found, B<callback(2, i, cb_arg)> is called.
+
+=back
+
+The prime may have to fulfill additional requirements for use in
+Diffie-Hellman key exchange:
+
+If B<add> is not B<NULL>, the prime will fulfill the condition p % B<add>
+== B<rem> (p % B<add> == 1 if B<rem> == B<NULL>) in order to suit a given
+generator.
+
+If B<safe> is true, it will be a safe prime (i.e. a prime p so
+that (p-1)/2 is also prime).
+
+The PRNG must be seeded prior to calling BN_generate_prime().
+The prime number generation has a negligible error probability.
+
+BN_is_prime() and BN_is_prime_fasttest() test if the number B<a> is
+prime.  The following tests are performed until one of them shows that
+B<a> is composite; if B<a> passes all these tests, it is considered
+prime.
+
+BN_is_prime_fasttest(), when called with B<do_trial_division == 1>,
+first attempts trial division by a number of small primes;
+if no divisors are found by this test and B<callback> is not B<NULL>,
+B<callback(1, -1, cb_arg)> is called.
+If B<do_trial_division == 0>, this test is skipped.
+
+Both BN_is_prime() and BN_is_prime_fasttest() perform a Miller-Rabin
+probabilistic primality test with B<checks> iterations. If
+B<checks == BN_prime_checks>, a number of iterations is used that
+yields a false positive rate of at most 2^-80 for random input.
+
+If B<callback> is not B<NULL>, B<callback(1, j, cb_arg)> is called
+after the j-th iteration (j = 0, 1, ...). B<ctx> is a
+pre-allocated B<BN_CTX> (to save the overhead of allocating and
+freeing the structure in a loop), or B<NULL>.
+
+=head1 RETURN VALUES
+
+BN_generate_prime() returns the prime number on success, B<NULL> otherwise.
+
+BN_is_prime() returns 0 if the number is composite, 1 if it is
+prime with an error probability of less than 0.25^B<checks>, and
+-1 on error.
+
+The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 SEE ALSO
+
+L<bn(3)|bn(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>
+
+=head1 HISTORY
+
+The B<cb_arg> arguments to BN_generate_prime() and to BN_is_prime()
+were added in SSLeay 0.9.0. The B<ret> argument to BN_generate_prime()
+was added in SSLeay 0.9.1.
+BN_is_prime_fasttest() was added in OpenSSL 0.9.5.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/BN_mod_inverse.pod b/deps/openssl/openssl/doc/crypto/BN_mod_inverse.pod
new file mode 100644 (file)
index 0000000..3ea3975
--- /dev/null
@@ -0,0 +1,36 @@
+=pod
+
+=head1 NAME
+
+BN_mod_inverse - compute inverse modulo n
+
+=head1 SYNOPSIS
+
+ #include <openssl/bn.h>
+
+ BIGNUM *BN_mod_inverse(BIGNUM *r, BIGNUM *a, const BIGNUM *n,
+           BN_CTX *ctx);
+
+=head1 DESCRIPTION
+
+BN_mod_inverse() computes the inverse of B<a> modulo B<n>
+places the result in B<r> (C<(a*r)%n==1>). If B<r> is NULL,
+a new B<BIGNUM> is created.
+
+B<ctx> is a previously allocated B<BN_CTX> used for temporary
+variables. B<r> may be the same B<BIGNUM> as B<a> or B<n>.
+
+=head1 RETURN VALUES
+
+BN_mod_inverse() returns the B<BIGNUM> containing the inverse, and
+NULL on error. The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 SEE ALSO
+
+L<bn(3)|bn(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<BN_add(3)|BN_add(3)>
+
+=head1 HISTORY
+
+BN_mod_inverse() is available in all versions of SSLeay and OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/BN_mod_mul_montgomery.pod b/deps/openssl/openssl/doc/crypto/BN_mod_mul_montgomery.pod
new file mode 100644 (file)
index 0000000..6b16351
--- /dev/null
@@ -0,0 +1,101 @@
+=pod
+
+=head1 NAME
+
+BN_mod_mul_montgomery, BN_MONT_CTX_new, BN_MONT_CTX_init,
+BN_MONT_CTX_free, BN_MONT_CTX_set, BN_MONT_CTX_copy,
+BN_from_montgomery, BN_to_montgomery - Montgomery multiplication
+
+=head1 SYNOPSIS
+
+ #include <openssl/bn.h>
+
+ BN_MONT_CTX *BN_MONT_CTX_new(void);
+ void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
+ void BN_MONT_CTX_free(BN_MONT_CTX *mont);
+
+ int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *m, BN_CTX *ctx);
+ BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from);
+
+ int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
+         BN_MONT_CTX *mont, BN_CTX *ctx);
+
+ int BN_from_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
+         BN_CTX *ctx);
+
+ int BN_to_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
+         BN_CTX *ctx);
+
+=head1 DESCRIPTION
+
+These functions implement Montgomery multiplication. They are used
+automatically when L<BN_mod_exp(3)|BN_mod_exp(3)> is called with suitable input,
+but they may be useful when several operations are to be performed
+using the same modulus.
+
+BN_MONT_CTX_new() allocates and initializes a B<BN_MONT_CTX> structure.
+BN_MONT_CTX_init() initializes an existing uninitialized B<BN_MONT_CTX>.
+
+BN_MONT_CTX_set() sets up the I<mont> structure from the modulus I<m>
+by precomputing its inverse and a value R.
+
+BN_MONT_CTX_copy() copies the B<BN_MONT_CTX> I<from> to I<to>.
+
+BN_MONT_CTX_free() frees the components of the B<BN_MONT_CTX>, and, if
+it was created by BN_MONT_CTX_new(), also the structure itself.
+
+BN_mod_mul_montgomery() computes Mont(I<a>,I<b>):=I<a>*I<b>*R^-1 and places
+the result in I<r>.
+
+BN_from_montgomery() performs the Montgomery reduction I<r> = I<a>*R^-1.
+
+BN_to_montgomery() computes Mont(I<a>,R^2), i.e. I<a>*R.
+Note that I<a> must be non-negative and smaller than the modulus.
+
+For all functions, I<ctx> is a previously allocated B<BN_CTX> used for
+temporary variables.
+
+The B<BN_MONT_CTX> structure is defined as follows:
+
+ typedef struct bn_mont_ctx_st
+        {
+        int ri;         /* number of bits in R */
+        BIGNUM RR;      /* R^2 (used to convert to Montgomery form) */
+        BIGNUM N;       /* The modulus */
+        BIGNUM Ni;      /* R*(1/R mod N) - N*Ni = 1
+                         * (Ni is only stored for bignum algorithm) */
+        BN_ULONG n0;    /* least significant word of Ni */
+        int flags;
+        } BN_MONT_CTX;
+
+BN_to_montgomery() is a macro.
+
+=head1 RETURN VALUES
+
+BN_MONT_CTX_new() returns the newly allocated B<BN_MONT_CTX>, and NULL
+on error.
+
+BN_MONT_CTX_init() and BN_MONT_CTX_free() have no return values.
+
+For the other functions, 1 is returned for success, 0 on error.
+The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 WARNING
+
+The inputs must be reduced modulo B<m>, otherwise the result will be
+outside the expected range.
+
+=head1 SEE ALSO
+
+L<bn(3)|bn(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<BN_add(3)|BN_add(3)>,
+L<BN_CTX_new(3)|BN_CTX_new(3)>
+
+=head1 HISTORY
+
+BN_MONT_CTX_new(), BN_MONT_CTX_free(), BN_MONT_CTX_set(),
+BN_mod_mul_montgomery(), BN_from_montgomery() and BN_to_montgomery()
+are available in all versions of SSLeay and OpenSSL.
+
+BN_MONT_CTX_init() and BN_MONT_CTX_copy() were added in SSLeay 0.9.1b.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/BN_mod_mul_reciprocal.pod b/deps/openssl/openssl/doc/crypto/BN_mod_mul_reciprocal.pod
new file mode 100644 (file)
index 0000000..74a216d
--- /dev/null
@@ -0,0 +1,81 @@
+=pod
+
+=head1 NAME
+
+BN_mod_mul_reciprocal,  BN_div_recp, BN_RECP_CTX_new, BN_RECP_CTX_init,
+BN_RECP_CTX_free, BN_RECP_CTX_set - modular multiplication using
+reciprocal
+
+=head1 SYNOPSIS
+
+ #include <openssl/bn.h>
+
+ BN_RECP_CTX *BN_RECP_CTX_new(void);
+ void BN_RECP_CTX_init(BN_RECP_CTX *recp);
+ void BN_RECP_CTX_free(BN_RECP_CTX *recp);
+
+ int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *m, BN_CTX *ctx);
+
+ int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *a, BN_RECP_CTX *recp,
+        BN_CTX *ctx);
+
+ int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *a, BIGNUM *b,
+        BN_RECP_CTX *recp, BN_CTX *ctx);
+
+=head1 DESCRIPTION
+
+BN_mod_mul_reciprocal() can be used to perform an efficient
+L<BN_mod_mul(3)|BN_mod_mul(3)> operation when the operation will be performed
+repeatedly with the same modulus. It computes B<r>=(B<a>*B<b>)%B<m>
+using B<recp>=1/B<m>, which is set as described below.  B<ctx> is a
+previously allocated B<BN_CTX> used for temporary variables.
+
+BN_RECP_CTX_new() allocates and initializes a B<BN_RECP> structure.
+BN_RECP_CTX_init() initializes an existing uninitialized B<BN_RECP>.
+
+BN_RECP_CTX_free() frees the components of the B<BN_RECP>, and, if it
+was created by BN_RECP_CTX_new(), also the structure itself.
+
+BN_RECP_CTX_set() stores B<m> in B<recp> and sets it up for computing
+1/B<m> and shifting it left by BN_num_bits(B<m>)+1 to make it an
+integer. The result and the number of bits it was shifted left will
+later be stored in B<recp>.
+
+BN_div_recp() divides B<a> by B<m> using B<recp>. It places the quotient
+in B<dv> and the remainder in B<rem>.
+
+The B<BN_RECP_CTX> structure is defined as follows:
+
+ typedef struct bn_recp_ctx_st
+       {
+       BIGNUM N;       /* the divisor */
+       BIGNUM Nr;      /* the reciprocal */
+       int num_bits;
+       int shift;
+       int flags;
+       } BN_RECP_CTX;
+
+It cannot be shared between threads.
+
+=head1 RETURN VALUES
+
+BN_RECP_CTX_new() returns the newly allocated B<BN_RECP_CTX>, and NULL
+on error.
+
+BN_RECP_CTX_init() and BN_RECP_CTX_free() have no return values.
+
+For the other functions, 1 is returned for success, 0 on error.
+The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 SEE ALSO
+
+L<bn(3)|bn(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<BN_add(3)|BN_add(3)>,
+L<BN_CTX_new(3)|BN_CTX_new(3)>
+
+=head1 HISTORY
+
+B<BN_RECP_CTX> was added in SSLeay 0.9.0. Before that, the function
+BN_reciprocal() was used instead, and the BN_mod_mul_reciprocal()
+arguments were different.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/BN_new.pod b/deps/openssl/openssl/doc/crypto/BN_new.pod
new file mode 100644 (file)
index 0000000..ab7a105
--- /dev/null
@@ -0,0 +1,53 @@
+=pod
+
+=head1 NAME
+
+BN_new, BN_init, BN_clear, BN_free, BN_clear_free - allocate and free BIGNUMs
+
+=head1 SYNOPSIS
+
+ #include <openssl/bn.h>
+
+ BIGNUM *BN_new(void);
+
+ void BN_init(BIGNUM *);
+
+ void BN_clear(BIGNUM *a);
+
+ void BN_free(BIGNUM *a);
+
+ void BN_clear_free(BIGNUM *a);
+
+=head1 DESCRIPTION
+
+BN_new() allocates and initializes a B<BIGNUM> structure. BN_init()
+initializes an existing uninitialized B<BIGNUM>.
+
+BN_clear() is used to destroy sensitive data such as keys when they
+are no longer needed. It erases the memory used by B<a> and sets it
+to the value 0.
+
+BN_free() frees the components of the B<BIGNUM>, and if it was created
+by BN_new(), also the structure itself. BN_clear_free() additionally
+overwrites the data before the memory is returned to the system.
+
+=head1 RETURN VALUES
+
+BN_new() returns a pointer to the B<BIGNUM>. If the allocation fails,
+it returns B<NULL> and sets an error code that can be obtained
+by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+BN_init(), BN_clear(), BN_free() and BN_clear_free() have no return
+values.
+
+=head1 SEE ALSO
+
+L<bn(3)|bn(3)>, L<ERR_get_error(3)|ERR_get_error(3)>
+
+=head1 HISTORY
+
+BN_new(), BN_clear(), BN_free() and BN_clear_free() are available in
+all versions on SSLeay and OpenSSL.  BN_init() was added in SSLeay
+0.9.1b.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/BN_num_bytes.pod b/deps/openssl/openssl/doc/crypto/BN_num_bytes.pod
new file mode 100644 (file)
index 0000000..a6a2e3f
--- /dev/null
@@ -0,0 +1,57 @@
+=pod
+
+=head1 NAME
+
+BN_num_bits, BN_num_bytes, BN_num_bits_word - get BIGNUM size
+
+=head1 SYNOPSIS
+
+ #include <openssl/bn.h>
+
+ int BN_num_bytes(const BIGNUM *a);
+
+ int BN_num_bits(const BIGNUM *a);
+
+ int BN_num_bits_word(BN_ULONG w);
+
+=head1 DESCRIPTION
+
+BN_num_bytes() returns the size of a B<BIGNUM> in bytes.
+
+BN_num_bits_word() returns the number of significant bits in a word.
+If we take 0x00000432 as an example, it returns 11, not 16, not 32.
+Basically, except for a zero, it returns I<floor(log2(w))+1>.
+
+BN_num_bits() returns the number of significant bits in a B<BIGNUM>,
+following the same principle as BN_num_bits_word().
+
+BN_num_bytes() is a macro.
+
+=head1 RETURN VALUES
+
+The size.
+
+=head1 NOTES
+
+Some have tried using BN_num_bits() on individual numbers in RSA keys,
+DH keys and DSA keys, and found that they don't always come up with
+the number of bits they expected (something like 512, 1024, 2048,
+...).  This is because generating a number with some specific number
+of bits doesn't always set the highest bits, thereby making the number
+of I<significant> bits a little lower.  If you want to know the "key
+size" of such a key, either use functions like RSA_size(), DH_size()
+and DSA_size(), or use BN_num_bytes() and multiply with 8 (although
+there's no real guarantee that will match the "key size", just a lot
+more probability).
+
+=head1 SEE ALSO
+
+L<bn(3)|bn(3)>, L<DH_size(3)|DH_size(3)>, L<DSA_size(3)|DSA_size(3)>,
+L<RSA_size(3)|RSA_size(3)>
+
+=head1 HISTORY
+
+BN_num_bytes(), BN_num_bits() and BN_num_bits_word() are available in
+all versions of SSLeay and OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/BN_rand.pod b/deps/openssl/openssl/doc/crypto/BN_rand.pod
new file mode 100644 (file)
index 0000000..81f93c2
--- /dev/null
@@ -0,0 +1,58 @@
+=pod
+
+=head1 NAME
+
+BN_rand, BN_pseudo_rand - generate pseudo-random number
+
+=head1 SYNOPSIS
+
+ #include <openssl/bn.h>
+
+ int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
+
+ int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom);
+
+ int BN_rand_range(BIGNUM *rnd, BIGNUM *range);
+
+ int BN_pseudo_rand_range(BIGNUM *rnd, BIGNUM *range);
+
+=head1 DESCRIPTION
+
+BN_rand() generates a cryptographically strong pseudo-random number of
+B<bits> bits in length and stores it in B<rnd>. If B<top> is -1, the
+most significant bit of the random number can be zero. If B<top> is 0,
+it is set to 1, and if B<top> is 1, the two most significant bits of
+the number will be set to 1, so that the product of two such random
+numbers will always have 2*B<bits> length.  If B<bottom> is true, the
+number will be odd.
+
+BN_pseudo_rand() does the same, but pseudo-random numbers generated by
+this function are not necessarily unpredictable. They can be used for
+non-cryptographic purposes and for certain purposes in cryptographic
+protocols, but usually not for key generation etc.
+
+BN_rand_range() generates a cryptographically strong pseudo-random
+number B<rnd> in the range 0 <lt>= B<rnd> E<lt> B<range>.
+BN_pseudo_rand_range() does the same, but is based on BN_pseudo_rand(),
+and hence numbers generated by it are not necessarily unpredictable.
+
+The PRNG must be seeded prior to calling BN_rand() or BN_rand_range().
+
+=head1 RETURN VALUES
+
+The functions return 1 on success, 0 on error.
+The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 SEE ALSO
+
+L<bn(3)|bn(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>,
+L<RAND_add(3)|RAND_add(3)>, L<RAND_bytes(3)|RAND_bytes(3)>
+
+=head1 HISTORY
+
+BN_rand() is available in all versions of SSLeay and OpenSSL.
+BN_pseudo_rand() was added in OpenSSL 0.9.5. The B<top> == -1 case
+and the function BN_rand_range() were added in OpenSSL 0.9.6a.
+BN_pseudo_rand_range() was added in OpenSSL 0.9.6c.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/BN_set_bit.pod b/deps/openssl/openssl/doc/crypto/BN_set_bit.pod
new file mode 100644 (file)
index 0000000..b7c47b9
--- /dev/null
@@ -0,0 +1,66 @@
+=pod
+
+=head1 NAME
+
+BN_set_bit, BN_clear_bit, BN_is_bit_set, BN_mask_bits, BN_lshift,
+BN_lshift1, BN_rshift, BN_rshift1 - bit operations on BIGNUMs
+
+=head1 SYNOPSIS
+
+ #include <openssl/bn.h>
+
+ int BN_set_bit(BIGNUM *a, int n);
+ int BN_clear_bit(BIGNUM *a, int n);
+
+ int BN_is_bit_set(const BIGNUM *a, int n);
+
+ int BN_mask_bits(BIGNUM *a, int n);
+
+ int BN_lshift(BIGNUM *r, const BIGNUM *a, int n);
+ int BN_lshift1(BIGNUM *r, BIGNUM *a);
+
+ int BN_rshift(BIGNUM *r, BIGNUM *a, int n);
+ int BN_rshift1(BIGNUM *r, BIGNUM *a);
+
+=head1 DESCRIPTION
+
+BN_set_bit() sets bit B<n> in B<a> to 1 (C<a|=(1E<lt>E<lt>n)>). The
+number is expanded if necessary.
+
+BN_clear_bit() sets bit B<n> in B<a> to 0 (C<a&=~(1E<lt>E<lt>n)>). An
+error occurs if B<a> is shorter than B<n> bits.
+
+BN_is_bit_set() tests if bit B<n> in B<a> is set.
+
+BN_mask_bits() truncates B<a> to an B<n> bit number
+(C<a&=~((~0)E<gt>E<gt>n)>).  An error occurs if B<a> already is
+shorter than B<n> bits.
+
+BN_lshift() shifts B<a> left by B<n> bits and places the result in
+B<r> (C<r=a*2^n>). BN_lshift1() shifts B<a> left by one and places
+the result in B<r> (C<r=2*a>).
+
+BN_rshift() shifts B<a> right by B<n> bits and places the result in
+B<r> (C<r=a/2^n>). BN_rshift1() shifts B<a> right by one and places
+the result in B<r> (C<r=a/2>).
+
+For the shift functions, B<r> and B<a> may be the same variable.
+
+=head1 RETURN VALUES
+
+BN_is_bit_set() returns 1 if the bit is set, 0 otherwise.
+
+All other functions return 1 for success, 0 on error. The error codes
+can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 SEE ALSO
+
+L<bn(3)|bn(3)>, L<BN_num_bytes(3)|BN_num_bytes(3)>, L<BN_add(3)|BN_add(3)>
+
+=head1 HISTORY
+
+BN_set_bit(), BN_clear_bit(), BN_is_bit_set(), BN_mask_bits(),
+BN_lshift(), BN_lshift1(), BN_rshift(), and BN_rshift1() are available
+in all versions of SSLeay and OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/BN_swap.pod b/deps/openssl/openssl/doc/crypto/BN_swap.pod
new file mode 100644 (file)
index 0000000..79efaa1
--- /dev/null
@@ -0,0 +1,23 @@
+=pod
+
+=head1 NAME
+
+BN_swap - exchange BIGNUMs
+
+=head1 SYNOPSIS
+
+ #include <openssl/bn.h>
+
+ void BN_swap(BIGNUM *a, BIGNUM *b);
+
+=head1 DESCRIPTION
+
+BN_swap() exchanges the values of I<a> and I<b>.
+
+L<bn(3)|bn(3)>
+
+=head1 HISTORY
+
+BN_swap was added in OpenSSL 0.9.7.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/BN_zero.pod b/deps/openssl/openssl/doc/crypto/BN_zero.pod
new file mode 100644 (file)
index 0000000..b555ec3
--- /dev/null
@@ -0,0 +1,59 @@
+=pod
+
+=head1 NAME
+
+BN_zero, BN_one, BN_value_one, BN_set_word, BN_get_word - BIGNUM assignment
+operations
+
+=head1 SYNOPSIS
+
+ #include <openssl/bn.h>
+
+ int BN_zero(BIGNUM *a);
+ int BN_one(BIGNUM *a);
+
+ const BIGNUM *BN_value_one(void);
+
+ int BN_set_word(BIGNUM *a, unsigned long w);
+ unsigned long BN_get_word(BIGNUM *a);
+
+=head1 DESCRIPTION
+
+BN_zero(), BN_one() and BN_set_word() set B<a> to the values 0, 1 and
+B<w> respectively.  BN_zero() and BN_one() are macros.
+
+BN_value_one() returns a B<BIGNUM> constant of value 1. This constant
+is useful for use in comparisons and assignment.
+
+BN_get_word() returns B<a>, if it can be represented as an unsigned
+long.
+
+=head1 RETURN VALUES
+
+BN_get_word() returns the value B<a>, and 0xffffffffL if B<a> cannot
+be represented as an unsigned long.
+
+BN_zero(), BN_one() and BN_set_word() return 1 on success, 0 otherwise.
+BN_value_one() returns the constant.
+
+=head1 BUGS
+
+Someone might change the constant.
+
+If a B<BIGNUM> is equal to 0xffffffffL it can be represented as an
+unsigned long but this value is also returned on error.
+
+=head1 SEE ALSO
+
+L<bn(3)|bn(3)>, L<BN_bn2bin(3)|BN_bn2bin(3)>
+
+=head1 HISTORY
+
+BN_zero(), BN_one() and BN_set_word() are available in all versions of
+SSLeay and OpenSSL. BN_value_one() and BN_get_word() were added in
+SSLeay 0.8.
+
+BN_value_one() was changed to return a true const BIGNUM * in OpenSSL
+0.9.7.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/CMS_add0_cert.pod b/deps/openssl/openssl/doc/crypto/CMS_add0_cert.pod
new file mode 100644 (file)
index 0000000..9c13f48
--- /dev/null
@@ -0,0 +1,66 @@
+=pod
+
+=head1 NAME
+
+ CMS_add0_cert, CMS_add1_cert, CMS_get1_certs, CMS_add0_crl, CMS_get1_crls, - CMS certificate and CRL utility functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/cms.h>
+
+ int CMS_add0_cert(CMS_ContentInfo *cms, X509 *cert);
+ int CMS_add1_cert(CMS_ContentInfo *cms, X509 *cert);
+ STACK_OF(X509) *CMS_get1_certs(CMS_ContentInfo *cms);
+
+ int CMS_add0_crl(CMS_ContentInfo *cms, X509_CRL *crl);
+ int CMS_add1_crl(CMS_ContentInfo *cms, X509_CRL *crl);
+ STACK_OF(X509_CRL) *CMS_get1_crls(CMS_ContentInfo *cms);
+
+
+=head1 DESCRIPTION
+
+CMS_add0_cert() and CMS_add1_cert() add certificate B<cert> to B<cms>.
+must be of type signed data or enveloped data. 
+
+CMS_get1_certs() returns all certificates in B<cms>.
+
+CMS_add0_crl() and CMS_add1_crl() add CRL B<crl> to B<cms>. CMS_get1_crls()
+returns any CRLs in B<cms>.
+
+=head1 NOTES
+
+The CMS_ContentInfo structure B<cms> must be of type signed data or enveloped
+data or an error will be returned.
+
+For signed data certificates and CRLs are added to the B<certificates> and
+B<crls> fields of SignedData structure. For enveloped data they are added to
+B<OriginatorInfo>.
+
+As the B<0> implies CMS_add0_cert() adds B<cert> internally to B<cms> and it
+must not be freed up after the call as opposed to CMS_add1_cert() where B<cert>
+must be freed up.
+
+The same certificate or CRL must not be added to the same cms structure more
+than once.
+
+=head1 RETURN VALUES
+
+CMS_add0_cert(), CMS_add1_cert() and CMS_add0_crl() and CMS_add1_crl() return
+1 for success and 0 for failure. 
+
+CMS_get1_certs() and CMS_get1_crls() return the STACK of certificates or CRLs
+or NULL if there are none or an error occurs. The only error which will occur
+in practice is if the B<cms> type is invalid.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>,
+L<CMS_sign(3)|CMS_sign(3)>,
+L<CMS_encrypt(3)|CMS_encrypt(3)>
+
+=head1 HISTORY
+
+CMS_add0_cert(), CMS_add1_cert(), CMS_get1_certs(), CMS_add0_crl()
+and CMS_get1_crls() were all first added to OpenSSL 0.9.8
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/CMS_add1_recipient_cert.pod b/deps/openssl/openssl/doc/crypto/CMS_add1_recipient_cert.pod
new file mode 100644 (file)
index 0000000..d7d8e25
--- /dev/null
@@ -0,0 +1,62 @@
+=pod
+
+=head1 NAME
+
+ CMS_add1_recipient_cert, CMS_add0_recipient_key - add recipients to a CMS enveloped data structure
+
+=head1 SYNOPSIS
+
+ #include <openssl/cms.h>
+
+ CMS_RecipientInfo *CMS_add1_recipient_cert(CMS_ContentInfo *cms, X509 *recip, unsigned int flags);
+
+ CMS_RecipientInfo *CMS_add0_recipient_key(CMS_ContentInfo *cms, int nid, unsigned char *key, size_t keylen, unsigned char *id, size_t idlen, ASN1_GENERALIZEDTIME *date, ASN1_OBJECT *otherTypeId, ASN1_TYPE *otherType);
+
+=head1 DESCRIPTION
+
+CMS_add1_recipient_cert() adds recipient B<recip> to CMS_ContentInfo enveloped
+data structure B<cms> as a KeyTransRecipientInfo structure.
+
+CMS_add0_recipient_key() adds symmetric key B<key> of length B<keylen> using
+wrapping algorithm B<nid>, identifier B<id> of length B<idlen> and optional
+values B<date>, B<otherTypeId> and B<otherType> to CMS_ContentInfo enveloped
+data structure B<cms> as a KEKRecipientInfo structure.
+
+The CMS_ContentInfo structure should be obtained from an initial call to
+CMS_encrypt() with the flag B<CMS_PARTIAL> set.
+
+=head1 NOTES
+
+The main purpose of this function is to provide finer control over a CMS
+enveloped data structure where the simpler CMS_encrypt() function defaults are
+not appropriate. For example if one or more KEKRecipientInfo structures
+need to be added. New attributes can also be added using the returned
+CMS_RecipientInfo structure and the CMS attribute utility functions.
+
+OpenSSL will by default identify recipient certificates using issuer name
+and serial number. If B<CMS_USE_KEYID> is set it will use the subject key
+identifier value instead. An error occurs if all recipient certificates do not
+have a subject key identifier extension.
+
+Currently only AES based key wrapping algorithms are supported for B<nid>,
+specifically: NID_id_aes128_wrap, NID_id_aes192_wrap and NID_id_aes256_wrap.
+If B<nid> is set to B<NID_undef> then an AES wrap algorithm will be used
+consistent with B<keylen>.
+
+=head1 RETURN VALUES
+
+CMS_add1_recipient_cert() and CMS_add0_recipient_key() return an internal
+pointer to the CMS_RecipientInfo structure just added or NULL if an error
+occurs.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<CMS_decrypt(3)|CMS_decrypt(3)>,
+L<CMS_final(3)|CMS_final(3)>,
+
+=head1 HISTORY
+
+CMS_add1_recipient_cert() and CMS_add0_recipient_key() were added to OpenSSL
+0.9.8
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/CMS_compress.pod b/deps/openssl/openssl/doc/crypto/CMS_compress.pod
new file mode 100644 (file)
index 0000000..0a07152
--- /dev/null
@@ -0,0 +1,73 @@
+=pod
+
+=head1 NAME
+
+CMS_compress - create a CMS CompressedData structure
+
+=head1 SYNOPSIS
+
+ #include <openssl/cms.h>
+
+ CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags);
+
+=head1 DESCRIPTION
+
+CMS_compress() creates and returns a CMS CompressedData structure. B<comp_nid>
+is the compression algorithm to use or B<NID_undef> to use the default
+algorithm (zlib compression). B<in> is the content to be compressed.
+B<flags> is an optional set of flags.
+
+=head1 NOTES
+
+The only currently supported compression algorithm is zlib using the NID
+NID_zlib_compression.
+
+If zlib support is not compiled into OpenSSL then CMS_compress() will return
+an error.
+
+If the B<CMS_TEXT> flag is set MIME headers for type B<text/plain> are
+prepended to the data.
+
+Normally the supplied content is translated into MIME canonical format (as
+required by the S/MIME specifications) if B<CMS_BINARY> is set no translation
+occurs. This option should be used if the supplied data is in binary format
+otherwise the translation will corrupt it. If B<CMS_BINARY> is set then
+B<CMS_TEXT> is ignored.
+
+If the B<CMS_STREAM> flag is set a partial B<CMS_ContentInfo> structure is
+returned suitable for streaming I/O: no data is read from the BIO B<in>.
+
+The compressed data is included in the CMS_ContentInfo structure, unless
+B<CMS_DETACHED> is set in which case it is omitted. This is rarely used in
+practice and is not supported by SMIME_write_CMS().
+
+=head1 NOTES
+
+If the flag B<CMS_STREAM> is set the returned B<CMS_ContentInfo> structure is
+B<not> complete and outputting its contents via a function that does not
+properly finalize the B<CMS_ContentInfo> structure will give unpredictable
+results.
+
+Several functions including SMIME_write_CMS(), i2d_CMS_bio_stream(),
+PEM_write_bio_CMS_stream() finalize the structure. Alternatively finalization
+can be performed by obtaining the streaming ASN1 B<BIO> directly using
+BIO_new_CMS().
+
+Additional compression parameters such as the zlib compression level cannot
+currently be set.
+
+=head1 RETURN VALUES
+
+CMS_compress() returns either a CMS_ContentInfo structure or NULL if an error
+occurred. The error can be obtained from ERR_get_error(3).
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<CMS_uncompress(3)|CMS_uncompress(3)>
+
+=head1 HISTORY
+
+CMS_compress() was added to OpenSSL 0.9.8
+The B<CMS_STREAM> flag was first supported in OpenSSL 1.0.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/CMS_decrypt.pod b/deps/openssl/openssl/doc/crypto/CMS_decrypt.pod
new file mode 100644 (file)
index 0000000..d857e4f
--- /dev/null
@@ -0,0 +1,65 @@
+=pod
+
+=head1 NAME
+
+ CMS_decrypt - decrypt content from a CMS envelopedData structure
+
+=head1 SYNOPSIS
+
+ #include <openssl/cms.h>
+
+ int CMS_decrypt(CMS_ContentInfo *cms, EVP_PKEY *pkey, X509 *cert, BIO *dcont, BIO *out, unsigned int flags);
+
+=head1 DESCRIPTION
+
+CMS_decrypt() extracts and decrypts the content from a CMS EnvelopedData
+structure. B<pkey> is the private key of the recipient, B<cert> is the
+recipient's certificate, B<out> is a BIO to write the content to and
+B<flags> is an optional set of flags.
+
+The B<dcont> parameter is used in the rare case where the encrypted content
+is detached. It will normally be set to NULL.
+
+=head1 NOTES
+
+OpenSSL_add_all_algorithms() (or equivalent) should be called before using this
+function or errors about unknown algorithms will occur.
+
+Although the recipients certificate is not needed to decrypt the data it is
+needed to locate the appropriate (of possible several) recipients in the CMS
+structure. If B<cert> is set to NULL all possible recipients are tried.
+
+It is possible to determine the correct recipient key by other means (for
+example looking them up in a database) and setting them in the CMS structure
+in advance using the CMS utility functions such as CMS_set1_pkey(). In this
+case both B<cert> and B<pkey> should be set to NULL.
+
+To process KEKRecipientInfo types CMS_set1_key() or CMS_RecipientInfo_set0_key()
+and CMS_ReceipientInfo_decrypt() should be called before CMS_decrypt() and
+B<cert> and B<pkey> set to NULL.
+
+The following flags can be passed in the B<flags> parameter.
+
+If the B<CMS_TEXT> flag is set MIME headers for type B<text/plain> are deleted
+from the content. If the content is not of type B<text/plain> then an error is
+returned.
+
+=head1 RETURN VALUES
+
+CMS_decrypt() returns either 1 for success or 0 for failure.
+The error can be obtained from ERR_get_error(3)
+
+=head1 BUGS
+
+The lack of single pass processing and the need to hold all data in memory as
+mentioned in CMS_verify() also applies to CMS_decrypt().
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<CMS_encrypt(3)|CMS_encrypt(3)>
+
+=head1 HISTORY
+
+CMS_decrypt() was added to OpenSSL 0.9.8
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/CMS_encrypt.pod b/deps/openssl/openssl/doc/crypto/CMS_encrypt.pod
new file mode 100644 (file)
index 0000000..1ee5b27
--- /dev/null
@@ -0,0 +1,96 @@
+=pod
+
+=head1 NAME
+
+ CMS_encrypt - create a CMS envelopedData structure
+
+=head1 SYNOPSIS
+
+ #include <openssl/cms.h>
+
+ CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher, unsigned int flags);
+
+=head1 DESCRIPTION
+
+CMS_encrypt() creates and returns a CMS EnvelopedData structure. B<certs>
+is a list of recipient certificates. B<in> is the content to be encrypted.
+B<cipher> is the symmetric cipher to use. B<flags> is an optional set of flags.
+
+=head1 NOTES
+
+Only certificates carrying RSA keys are supported so the recipient certificates
+supplied to this function must all contain RSA public keys, though they do not
+have to be signed using the RSA algorithm.
+
+EVP_des_ede3_cbc() (triple DES) is the algorithm of choice for S/MIME use
+because most clients will support it.
+
+The algorithm passed in the B<cipher> parameter must support ASN1 encoding of
+its parameters. 
+
+Many browsers implement a "sign and encrypt" option which is simply an S/MIME
+envelopedData containing an S/MIME signed message. This can be readily produced
+by storing the S/MIME signed message in a memory BIO and passing it to
+CMS_encrypt().
+
+The following flags can be passed in the B<flags> parameter.
+
+If the B<CMS_TEXT> flag is set MIME headers for type B<text/plain> are
+prepended to the data.
+
+Normally the supplied content is translated into MIME canonical format (as
+required by the S/MIME specifications) if B<CMS_BINARY> is set no translation
+occurs. This option should be used if the supplied data is in binary format
+otherwise the translation will corrupt it. If B<CMS_BINARY> is set then
+B<CMS_TEXT> is ignored.
+
+OpenSSL will by default identify recipient certificates using issuer name
+and serial number. If B<CMS_USE_KEYID> is set it will use the subject key
+identifier value instead. An error occurs if all recipient certificates do not
+have a subject key identifier extension.
+
+If the B<CMS_STREAM> flag is set a partial B<CMS_ContentInfo> structure is
+returned suitable for streaming I/O: no data is read from the BIO B<in>.
+
+If the B<CMS_PARTIAL> flag is set a partial B<CMS_ContentInfo> structure is
+returned to which additional recipients and attributes can be added before
+finalization.
+
+The data being encrypted is included in the CMS_ContentInfo structure, unless
+B<CMS_DETACHED> is set in which case it is omitted. This is rarely used in
+practice and is not supported by SMIME_write_CMS().
+
+=head1 NOTES
+
+If the flag B<CMS_STREAM> is set the returned B<CMS_ContentInfo> structure is
+B<not> complete and outputting its contents via a function that does not
+properly finalize the B<CMS_ContentInfo> structure will give unpredictable
+results.
+
+Several functions including SMIME_write_CMS(), i2d_CMS_bio_stream(),
+PEM_write_bio_CMS_stream() finalize the structure. Alternatively finalization
+can be performed by obtaining the streaming ASN1 B<BIO> directly using
+BIO_new_CMS().
+
+The recipients specified in B<certs> use a CMS KeyTransRecipientInfo info
+structure. KEKRecipientInfo is also supported using the flag B<CMS_PARTIAL>
+and CMS_add0_recipient_key().
+
+The parameter B<certs> may be NULL if B<CMS_PARTIAL> is set and recipients
+added later using CMS_add1_recipient_cert() or CMS_add0_recipient_key().
+
+=head1 RETURN VALUES
+
+CMS_encrypt() returns either a CMS_ContentInfo structure or NULL if an error
+occurred. The error can be obtained from ERR_get_error(3).
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<CMS_decrypt(3)|CMS_decrypt(3)>
+
+=head1 HISTORY
+
+CMS_decrypt() was added to OpenSSL 0.9.8
+The B<CMS_STREAM> flag was first supported in OpenSSL 1.0.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/CMS_final.pod b/deps/openssl/openssl/doc/crypto/CMS_final.pod
new file mode 100644 (file)
index 0000000..36cf96b
--- /dev/null
@@ -0,0 +1,41 @@
+=pod
+
+=head1 NAME
+
+ CMS_final - finalise a CMS_ContentInfo structure
+
+=head1 SYNOPSIS
+
+ #include <openssl/cms.h>
+
+ int CMS_final(CMS_ContentInfo *cms, BIO *data, BIO *dcont, unsigned int flags);
+
+=head1 DESCRIPTION
+
+CMS_final() finalises the structure B<cms>. It's purpose is to perform any
+operations necessary on B<cms> (digest computation for example) and set the
+appropriate fields. The parameter B<data> contains the content to be 
+processed. The B<dcont> parameter contains a BIO to write content to after
+processing: this is only used with detached data and will usually be set to
+NULL.
+
+=head1 NOTES
+
+This function will normally be called when the B<CMS_PARTIAL> flag is used. It
+should only be used when streaming is not performed because the streaming
+I/O functions perform finalisation operations internally.
+
+=head1 RETURN VALUES
+
+CMS_final() returns 1 for success or 0 for failure.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<CMS_sign(3)|CMS_sign(3)>,
+L<CMS_encrypt(3)|CMS_encrypt(3)>
+
+=head1 HISTORY
+
+CMS_final() was added to OpenSSL 0.9.8
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/CMS_get0_RecipientInfos.pod b/deps/openssl/openssl/doc/crypto/CMS_get0_RecipientInfos.pod
new file mode 100644 (file)
index 0000000..e035542
--- /dev/null
@@ -0,0 +1,106 @@
+=pod
+
+=head1 NAME
+
+ CMS_get0_RecipientInfos, CMS_RecipientInfo_type, CMS_RecipientInfo_ktri_get0_signer_id,CMS_RecipientInfo_ktri_cert_cmp, CMS_RecipientInfo_set0_pkey, CMS_RecipientInfo_kekri_get0_id, CMS_RecipientInfo_kekri_id_cmp, CMS_RecipientInfo_set0_key, CMS_RecipientInfo_decrypt - CMS envelopedData RecipientInfo routines
+
+=head1 SYNOPSIS
+
+ #include <openssl/cms.h>
+
+ STACK_OF(CMS_RecipientInfo) *CMS_get0_RecipientInfos(CMS_ContentInfo *cms);
+ int CMS_RecipientInfo_type(CMS_RecipientInfo *ri);
+
+ int CMS_RecipientInfo_ktri_get0_signer_id(CMS_RecipientInfo *ri, ASN1_OCTET_STRING **keyid, X509_NAME **issuer, ASN1_INTEGER **sno);
+ int CMS_RecipientInfo_ktri_cert_cmp(CMS_RecipientInfo *ri, X509 *cert);
+ int CMS_RecipientInfo_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pkey);
+
+ int CMS_RecipientInfo_kekri_get0_id(CMS_RecipientInfo *ri, X509_ALGOR **palg, ASN1_OCTET_STRING **pid, ASN1_GENERALIZEDTIME **pdate, ASN1_OBJECT **potherid, ASN1_TYPE **pothertype);
+ int CMS_RecipientInfo_kekri_id_cmp(CMS_RecipientInfo *ri, const unsigned char *id, size_t idlen);
+ int CMS_RecipientInfo_set0_key(CMS_RecipientInfo *ri, unsigned char *key, size_t keylen);
+
+ int CMS_RecipientInfo_decrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri);
+
+=head1 DESCRIPTION
+
+The function CMS_get0_RecipientInfos() returns all the CMS_RecipientInfo
+structures associated with a CMS EnvelopedData structure.
+
+CMS_RecipientInfo_type() returns the type of CMS_RecipientInfo structure B<ri>.
+It will currently return CMS_RECIPINFO_TRANS, CMS_RECIPINFO_AGREE,
+CMS_RECIPINFO_KEK, CMS_RECIPINFO_PASS, or CMS_RECIPINFO_OTHER.
+
+CMS_RecipientInfo_ktri_get0_signer_id() retrieves the certificate recipient
+identifier associated with a specific CMS_RecipientInfo structure B<ri>, which
+must be of type CMS_RECIPINFO_TRANS. Either the keyidentifier will be set in
+B<keyid> or B<both> issuer name and serial number in B<issuer> and B<sno>. 
+
+CMS_RecipientInfo_ktri_cert_cmp() compares the certificate B<cert> against the
+CMS_RecipientInfo structure B<ri>, which must be of type CMS_RECIPINFO_TRANS.
+It returns zero if the comparison is successful and non zero if not.
+
+CMS_RecipientInfo_set0_pkey() associates the private key B<pkey> with
+the CMS_RecipientInfo structure B<ri>, which must be of type
+CMS_RECIPINFO_TRANS.
+
+CMS_RecipientInfo_kekri_get0_id() retrieves the key information from the
+CMS_RecipientInfo structure B<ri> which must be of type CMS_RECIPINFO_KEK.  Any
+of the remaining parameters can be NULL if the application is not interested in
+the value of a field. Where a field is optional and absent NULL will be written
+to the corresponding parameter. The keyEncryptionAlgorithm field is written to
+B<palg>, the B<keyIdentifier> field is written to B<pid>, the B<date> field if
+present is written to B<pdate>, if the B<other> field is present the components
+B<keyAttrId> and B<keyAttr> are written to parameters B<potherid> and
+B<pothertype>.
+
+CMS_RecipientInfo_kekri_id_cmp() compares the ID in the B<id> and B<idlen>
+parameters against the B<keyIdentifier> CMS_RecipientInfo structure B<ri>,
+which must be of type CMS_RECIPINFO_KEK.  It returns zero if the comparison is
+successful and non zero if not.
+
+CMS_RecipientInfo_set0_key() associates the symmetric key B<key> of length
+B<keylen> with the CMS_RecipientInfo structure B<ri>, which must be of type
+CMS_RECIPINFO_KEK.
+
+CMS_RecipientInfo_decrypt() attempts to decrypt CMS_RecipientInfo structure
+B<ri> in structure B<cms>. A key must have been associated with the structure
+first.
+
+=head1 NOTES
+
+The main purpose of these functions is to enable an application to lookup
+recipient keys using any appropriate technique when the simpler method
+of CMS_decrypt() is not appropriate.
+
+In typical usage and application will retrieve all CMS_RecipientInfo structures
+using CMS_get0_RecipientInfos() and check the type of each using
+CMS_RecpientInfo_type(). Depending on the type the CMS_RecipientInfo structure
+can be ignored or its key identifier data retrieved using an appropriate
+function. Then if the corresponding secret or private key can be obtained by
+any appropriate means it can then associated with the structure and
+CMS_RecpientInfo_decrypt() called. If successful CMS_decrypt() can be called
+with a NULL key to decrypt the enveloped content.
+
+=head1 RETURN VALUES
+
+CMS_get0_RecipientInfos() returns all CMS_RecipientInfo structures, or NULL if
+an error occurs.
+
+CMS_RecipientInfo_ktri_get0_signer_id(), CMS_RecipientInfo_set0_pkey(),
+CMS_RecipientInfo_kekri_get0_id(), CMS_RecipientInfo_set0_key() and
+CMS_RecipientInfo_decrypt() return 1 for success or 0 if an error occurs.
+
+CMS_RecipientInfo_ktri_cert_cmp() and CMS_RecipientInfo_kekri_cmp() return 0
+for a successful comparison and non zero otherwise.
+
+Any error can be obtained from L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<CMS_decrypt(3)|CMS_decrypt(3)>
+
+=head1 HISTORY
+
+These functions were first was added to OpenSSL 0.9.8
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/CMS_get0_SignerInfos.pod b/deps/openssl/openssl/doc/crypto/CMS_get0_SignerInfos.pod
new file mode 100644 (file)
index 0000000..47f6d2a
--- /dev/null
@@ -0,0 +1,75 @@
+=pod
+
+=head1 NAME
+
+ CMS_get0_SignerInfos, CMS_SignerInfo_get0_signer_id, CMS_SignerInfo_cert_cmp, CMS_set1_signer_certs - CMS signedData signer functions.
+
+=head1 SYNOPSIS
+
+ #include <openssl/cms.h>
+
+ STACK_OF(CMS_SignerInfo) *CMS_get0_SignerInfos(CMS_ContentInfo *cms);
+
+ int CMS_SignerInfo_get0_signer_id(CMS_SignerInfo *si, ASN1_OCTET_STRING **keyid, X509_NAME **issuer, ASN1_INTEGER **sno);
+ int CMS_SignerInfo_cert_cmp(CMS_SignerInfo *si, X509 *cert);
+ void CMS_SignerInfo_set1_signer_cert(CMS_SignerInfo *si, X509 *signer);
+
+=head1 DESCRIPTION
+
+The function CMS_get0_SignerInfos() returns all the CMS_SignerInfo structures
+associated with a CMS signedData structure.
+
+CMS_SignerInfo_get0_signer_id() retrieves the certificate signer identifier
+associated with a specific CMS_SignerInfo structure B<si>. Either the
+keyidentifier will be set in B<keyid> or B<both> issuer name and serial number
+in B<issuer> and B<sno>.
+
+CMS_SignerInfo_cert_cmp() compares the certificate B<cert> against the signer
+identifier B<si>. It returns zero if the comparison is successful and non zero
+if not.
+
+CMS_SignerInfo_set1_signer_cert() sets the signers certificate of B<si> to
+B<signer>.
+
+=head1 NOTES
+
+The main purpose of these functions is to enable an application to lookup
+signers certificates using any appropriate technique when the simpler method
+of CMS_verify() is not appropriate.
+
+In typical usage and application will retrieve all CMS_SignerInfo structures
+using CMS_get0_SignerInfo() and retrieve the identifier information using
+CMS. It will then obtain the signer certificate by some unspecified means
+(or return and error if it cannot be found) and set it using
+CMS_SignerInfo_set1_signer_cert().
+
+Once all signer certificates have been set CMS_verify() can be used.
+
+Although CMS_get0_SignerInfos() can return NULL is an error occur B<or> if
+there are no signers this is not a problem in practice because the only
+error which can occur is if the B<cms> structure is not of type signedData
+due to application error.
+
+=head1 RETURN VALUES
+
+CMS_get0_SignerInfos() returns all CMS_SignerInfo structures, or NULL there
+are no signers or an error occurs.
+
+CMS_SignerInfo_get0_signer_id() returns 1 for success and 0 for failure.
+
+CMS_SignerInfo_cert_cmp() returns 0 for a successful comparison and non
+zero otherwise.
+
+CMS_SignerInfo_set1_signer_cert() does not return a value.
+
+Any error can be obtained from L<ERR_get_error(3)|ERR_get_error(3)>
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<CMS_verify(3)|CMS_verify(3)>
+
+=head1 HISTORY
+
+These functions were first was added to OpenSSL 0.9.8
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/CMS_get0_type.pod b/deps/openssl/openssl/doc/crypto/CMS_get0_type.pod
new file mode 100644 (file)
index 0000000..8ff1c31
--- /dev/null
@@ -0,0 +1,63 @@
+=pod
+
+=head1 NAME
+
+ CMS_get0_type, CMS_set1_eContentType, CMS_get0_eContentType - get and set CMS content types
+
+=head1 SYNOPSIS
+
+ #include <openssl/cms.h>
+
+ const ASN1_OBJECT *CMS_get0_type(CMS_ContentInfo *cms);
+ int CMS_set1_eContentType(CMS_ContentInfo *cms, const ASN1_OBJECT *oid);
+ const ASN1_OBJECT *CMS_get0_eContentType(CMS_ContentInfo *cms);
+
+=head1 DESCRIPTION
+
+CMS_get0_type() returns the content type of a CMS_ContentInfo structure as
+and ASN1_OBJECT pointer. An application can then decide how to process the
+CMS_ContentInfo structure based on this value.
+
+CMS_set1_eContentType() sets the embedded content type of a CMS_ContentInfo
+structure. It should be called with CMS functions with the B<CMS_PARTIAL>
+flag and B<before> the structure is finalised, otherwise the results are
+undefined.
+
+ASN1_OBJECT *CMS_get0_eContentType() returns a pointer to the embedded
+content type.
+
+=head1 NOTES
+
+As the B<0> implies CMS_get0_type() and CMS_get0_eContentType() return internal
+pointers which should B<not> be freed up. CMS_set1_eContentType() copies the
+supplied OID and it B<should> be freed up after use.
+
+The B<ASN1_OBJECT> values returned can be converted to an integer B<NID> value
+using OBJ_obj2nid(). For the currently supported content types the following
+values are returned:
+
+ NID_pkcs7_data
+ NID_pkcs7_signed
+ NID_pkcs7_digest
+ NID_id_smime_ct_compressedData:
+ NID_pkcs7_encrypted
+ NID_pkcs7_enveloped
+
+
+=head1 RETURN VALUES
+
+CMS_get0_type() and CMS_get0_eContentType() return and ASN1_OBJECT structure.
+
+CMS_set1_eContentType() returns 1 for success or 0 if an error occurred.  The
+error can be obtained from ERR_get_error(3).
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>
+
+=head1 HISTORY
+
+CMS_get0_type(), CMS_set1_eContentType() and CMS_get0_eContentType() were all
+first added to OpenSSL 0.9.8
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/CMS_get1_ReceiptRequest.pod b/deps/openssl/openssl/doc/crypto/CMS_get1_ReceiptRequest.pod
new file mode 100644 (file)
index 0000000..f546376
--- /dev/null
@@ -0,0 +1,69 @@
+=pod
+
+=head1 NAME
+
+ CMS_ReceiptRequest_create0, CMS_add1_ReceiptRequest, CMS_get1_ReceiptRequest, CMS_ReceiptRequest_get0_values - CMS signed receipt request functions.
+
+=head1 SYNOPSIS
+
+ #include <openssl/cms.h>
+
+ CMS_ReceiptRequest *CMS_ReceiptRequest_create0(unsigned char *id, int idlen, int allorfirst, STACK_OF(GENERAL_NAMES) *receiptList, STACK_OF(GENERAL_NAMES) *receiptsTo);
+ int CMS_add1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest *rr);
+ int CMS_get1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest **prr);
+ void CMS_ReceiptRequest_get0_values(CMS_ReceiptRequest *rr, ASN1_STRING **pcid, int *pallorfirst, STACK_OF(GENERAL_NAMES) **plist, STACK_OF(GENERAL_NAMES) **prto);
+
+=head1 DESCRIPTION
+
+CMS_ReceiptRequest_create0() creates a signed receipt request structure. The
+B<signedContentIdentifier> field is set using B<id> and B<idlen>, or it is set
+to 32 bytes of pseudo random data if B<id> is NULL. If B<receiptList> is NULL
+the allOrFirstTier option in B<receiptsFrom> is used and set to the value of
+the B<allorfirst> parameter. If B<receiptList> is not NULL the B<receiptList>
+option in B<receiptsFrom> is used. The B<receiptsTo> parameter specifies the
+B<receiptsTo> field value.
+
+The CMS_add1_ReceiptRequest() function adds a signed receipt request B<rr>
+to SignerInfo structure B<si>.
+
+int CMS_get1_ReceiptRequest() looks for a signed receipt request in B<si>, if
+any is found it is decoded and written to B<prr>.
+
+CMS_ReceiptRequest_get0_values() retrieves the values of a receipt request.
+The signedContentIdentifier is copied to B<pcid>. If the B<allOrFirstTier>
+option of B<receiptsFrom> is used its value is copied to B<pallorfirst>
+otherwise the B<receiptList> field is copied to B<plist>. The B<receiptsTo>
+parameter is copied to B<prto>.
+
+=head1 NOTES
+
+For more details of the meaning of the fields see RFC2634.
+
+The contents of a signed receipt should only be considered meaningful if the
+corresponding CMS_ContentInfo structure can be successfully verified using
+CMS_verify().
+
+=head1 RETURN VALUES
+
+CMS_ReceiptRequest_create0() returns a signed receipt request structure or 
+NULL if an error occurred.
+
+CMS_add1_ReceiptRequest() returns 1 for success or 0 is an error occurred.
+
+CMS_get1_ReceiptRequest() returns 1 is a signed receipt request is found and
+decoded. It returns 0 if a signed receipt request is not present and -1 if
+it is present but malformed.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<CMS_sign(3)|CMS_sign(3)>,
+L<CMS_sign_receipt(3)|CMS_sign_receipt(3)>, L<CMS_verify(3)|CMS_verify(3)>
+L<CMS_verify_receipt(3)|CMS_verify_receipt(3)>
+
+=head1 HISTORY
+
+CMS_ReceiptRequest_create0(), CMS_add1_ReceiptRequest(),
+CMS_get1_ReceiptRequest() and CMS_ReceiptRequest_get0_values() were added to
+OpenSSL 0.9.8
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/CMS_sign.pod b/deps/openssl/openssl/doc/crypto/CMS_sign.pod
new file mode 100644 (file)
index 0000000..2cc72de
--- /dev/null
@@ -0,0 +1,121 @@
+=pod
+
+=head1 NAME
+
+ CMS_sign - create a CMS SignedData structure
+
+=head1 SYNOPSIS
+
+ #include <openssl/cms.h>
+
+ CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, BIO *data, unsigned int flags);
+
+=head1 DESCRIPTION
+
+CMS_sign() creates and returns a CMS SignedData structure. B<signcert> is
+the certificate to sign with, B<pkey> is the corresponding private key.
+B<certs> is an optional additional set of certificates to include in the CMS
+structure (for example any intermediate CAs in the chain). Any or all of
+these parameters can be B<NULL>, see B<NOTES> below.
+
+The data to be signed is read from BIO B<data>.
+
+B<flags> is an optional set of flags.
+
+=head1 NOTES
+
+Any of the following flags (ored together) can be passed in the B<flags>
+parameter.
+
+Many S/MIME clients expect the signed content to include valid MIME headers. If
+the B<CMS_TEXT> flag is set MIME headers for type B<text/plain> are prepended
+to the data.
+
+If B<CMS_NOCERTS> is set the signer's certificate will not be included in the
+CMS_ContentInfo structure, the signer's certificate must still be supplied in
+the B<signcert> parameter though. This can reduce the size of the signature if
+the signers certificate can be obtained by other means: for example a
+previously signed message.
+
+The data being signed is included in the CMS_ContentInfo structure, unless
+B<CMS_DETACHED> is set in which case it is omitted. This is used for
+CMS_ContentInfo detached signatures which are used in S/MIME plaintext signed
+messages for example.
+
+Normally the supplied content is translated into MIME canonical format (as
+required by the S/MIME specifications) if B<CMS_BINARY> is set no translation
+occurs. This option should be used if the supplied data is in binary format
+otherwise the translation will corrupt it.
+
+The SignedData structure includes several CMS signedAttributes including the
+signing time, the CMS content type and the supported list of ciphers in an
+SMIMECapabilities attribute. If B<CMS_NOATTR> is set then no signedAttributes
+will be used. If B<CMS_NOSMIMECAP> is set then just the SMIMECapabilities are
+omitted.
+
+If present the SMIMECapabilities attribute indicates support for the following
+algorithms in preference order: 256 bit AES, Gost R3411-94, Gost 28147-89, 192
+bit AES, 128 bit AES, triple DES, 128 bit RC2, 64 bit RC2, DES and 40 bit RC2.
+If any of these algorithms is not available then it will not be included: for example the GOST algorithms will not be included if the GOST ENGINE is
+not loaded.
+
+OpenSSL will by default identify signing certificates using issuer name
+and serial number. If B<CMS_USE_KEYID> is set it will use the subject key
+identifier value instead. An error occurs if the signing certificate does not
+have a subject key identifier extension.
+
+If the flags B<CMS_STREAM> is set then the returned B<CMS_ContentInfo>
+structure is just initialized ready to perform the signing operation. The
+signing is however B<not> performed and the data to be signed is not read from
+the B<data> parameter. Signing is deferred until after the data has been
+written. In this way data can be signed in a single pass.
+
+If the B<CMS_PARTIAL> flag is set a partial B<CMS_ContentInfo> structure is
+output to which additional signers and capabilities can be added before
+finalization.
+
+If the flag B<CMS_STREAM> is set the returned B<CMS_ContentInfo> structure is
+B<not> complete and outputting its contents via a function that does not
+properly finalize the B<CMS_ContentInfo> structure will give unpredictable
+results.
+
+Several functions including SMIME_write_CMS(), i2d_CMS_bio_stream(),
+PEM_write_bio_CMS_stream() finalize the structure. Alternatively finalization
+can be performed by obtaining the streaming ASN1 B<BIO> directly using
+BIO_new_CMS().
+
+If a signer is specified it will use the default digest for the signing
+algorithm. This is B<SHA1> for both RSA and DSA keys.
+
+If B<signcert> and B<pkey> are NULL then a certificates only CMS structure is
+output.
+
+The function CMS_sign() is a basic CMS signing function whose output will be
+suitable for many purposes. For finer control of the output format the
+B<certs>, B<signcert> and B<pkey> parameters can all be B<NULL> and the
+B<CMS_PARTIAL> flag set. Then one or more signers can be added using the
+function CMS_sign_add1_signer(), non default digests can be used and custom
+attributes added. B<CMS_final()> must then be called to finalize the
+structure if streaming is not enabled. 
+
+=head1 BUGS
+
+Some attributes such as counter signatures are not supported.
+
+=head1 RETURN VALUES
+
+CMS_sign() returns either a valid CMS_ContentInfo structure or NULL if an error
+occurred. The error can be obtained from ERR_get_error(3).
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<CMS_verify(3)|CMS_verify(3)>
+
+=head1 HISTORY
+
+CMS_sign() was added to OpenSSL 0.9.8
+
+The B<CMS_STREAM> flag is only supported for detached data in OpenSSL 0.9.8,
+it is supported for embedded data in OpenSSL 1.0.0 and later.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/CMS_sign_add1_signer.pod b/deps/openssl/openssl/doc/crypto/CMS_sign_add1_signer.pod
new file mode 100644 (file)
index 0000000..bda3ca2
--- /dev/null
@@ -0,0 +1,101 @@
+=pod
+
+=head1 NAME
+
+ CMS_sign_add1_signer, CMS_SignerInfo_sign - add a signer to a CMS_ContentInfo signed data structure.
+
+=head1 SYNOPSIS
+
+ #include <openssl/cms.h>
+
+ CMS_SignerInfo *CMS_sign_add1_signer(CMS_ContentInfo *cms, X509 *signcert, EVP_PKEY *pkey, const EVP_MD *md, unsigned int flags);
+
+ int CMS_SignerInfo_sign(CMS_SignerInfo *si);
+
+
+=head1 DESCRIPTION
+
+CMS_sign_add1_signer() adds a signer with certificate B<signcert> and private
+key B<pkey> using message digest B<md> to CMS_ContentInfo SignedData
+structure B<cms>.
+
+The CMS_ContentInfo structure should be obtained from an initial call to
+CMS_sign() with the flag B<CMS_PARTIAL> set or in the case or re-signing a
+valid CMS_ContentInfo SignedData structure.
+
+If the B<md> parameter is B<NULL> then the default digest for the public
+key algorithm will be used.
+
+Unless the B<CMS_REUSE_DIGEST> flag is set the returned CMS_ContentInfo
+structure is not complete and must be finalized either by streaming (if
+applicable) or a call to CMS_final().
+
+The CMS_SignerInfo_sign() function will explicitly sign a CMS_SignerInfo
+structure, its main use is when B<CMS_REUSE_DIGEST> and B<CMS_PARTIAL> flags
+are both set.
+
+=head1 NOTES
+
+The main purpose of CMS_sign_add1_signer() is to provide finer control
+over a CMS signed data structure where the simpler CMS_sign() function defaults
+are not appropriate. For example if multiple signers or non default digest
+algorithms are needed. New attributes can also be added using the returned
+CMS_SignerInfo structure and the CMS attribute utility functions or the
+CMS signed receipt request functions.
+
+Any of the following flags (ored together) can be passed in the B<flags>
+parameter.
+
+If B<CMS_REUSE_DIGEST> is set then an attempt is made to copy the content
+digest value from the CMS_ContentInfo structure: to add a signer to an existing
+structure.  An error occurs if a matching digest value cannot be found to copy.
+The returned CMS_ContentInfo structure will be valid and finalized when this
+flag is set.
+
+If B<CMS_PARTIAL> is set in addition to B<CMS_REUSE_DIGEST> then the 
+CMS_SignerInfo structure will not be finalized so additional attributes
+can be added. In this case an explicit call to CMS_SignerInfo_sign() is
+needed to finalize it.
+
+If B<CMS_NOCERTS> is set the signer's certificate will not be included in the
+CMS_ContentInfo structure, the signer's certificate must still be supplied in
+the B<signcert> parameter though. This can reduce the size of the signature if
+the signers certificate can be obtained by other means: for example a
+previously signed message.
+
+The SignedData structure includes several CMS signedAttributes including the
+signing time, the CMS content type and the supported list of ciphers in an
+SMIMECapabilities attribute. If B<CMS_NOATTR> is set then no signedAttributes
+will be used. If B<CMS_NOSMIMECAP> is set then just the SMIMECapabilities are
+omitted.
+
+OpenSSL will by default identify signing certificates using issuer name
+and serial number. If B<CMS_USE_KEYID> is set it will use the subject key
+identifier value instead. An error occurs if the signing certificate does not
+have a subject key identifier extension.
+
+If present the SMIMECapabilities attribute indicates support for the following
+algorithms in preference order: 256 bit AES, Gost R3411-94, Gost 28147-89, 192
+bit AES, 128 bit AES, triple DES, 128 bit RC2, 64 bit RC2, DES and 40 bit RC2.
+If any of these algorithms is not available then it will not be included: for example the GOST algorithms will not be included if the GOST ENGINE is
+not loaded.
+
+CMS_sign_add1_signer() returns an internal pointer to the CMS_SignerInfo
+structure just added, this can be used to set additional attributes 
+before it is finalized.
+
+=head1 RETURN VALUES
+
+CMS_sign1_add_signers() returns an internal pointer to the CMS_SignerInfo
+structure just added or NULL if an error occurs.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<CMS_sign(3)|CMS_sign(3)>,
+L<CMS_final(3)|CMS_final(3)>,
+
+=head1 HISTORY
+
+CMS_sign_add1_signer() was added to OpenSSL 0.9.8
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/CMS_sign_receipt.pod b/deps/openssl/openssl/doc/crypto/CMS_sign_receipt.pod
new file mode 100644 (file)
index 0000000..cae1f83
--- /dev/null
@@ -0,0 +1,45 @@
+=pod
+
+=head1 NAME
+
+ CMS_sign_receipt - create a CMS signed receipt
+
+=head1 SYNOPSIS
+
+ #include <openssl/cms.h>
+
+ CMS_ContentInfo *CMS_sign_receipt(CMS_SignerInfo *si, X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, unsigned int flags);
+
+=head1 DESCRIPTION
+
+CMS_sign_receipt() creates and returns a CMS signed receipt structure. B<si> is
+the B<CMS_SignerInfo> structure containing the signed receipt request.
+B<signcert> is the certificate to sign with, B<pkey> is the corresponding
+private key.  B<certs> is an optional additional set of certificates to include
+in the CMS structure (for example any intermediate CAs in the chain).
+
+B<flags> is an optional set of flags.
+
+=head1 NOTES
+
+This functions behaves in a similar way to CMS_sign() except the flag values
+B<CMS_DETACHED>, B<CMS_BINARY>, B<CMS_NOATTR>, B<CMS_TEXT> and B<CMS_STREAM>
+are not supported since they do not make sense in the context of signed
+receipts.
+
+=head1 RETURN VALUES
+
+CMS_sign_receipt() returns either a valid CMS_ContentInfo structure or NULL if
+an error occurred.  The error can be obtained from ERR_get_error(3).
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>,
+L<CMS_verify_receipt(3)|CMS_verify_receipt(3)>,
+L<CMS_sign(3)|CMS_sign(3)>
+
+=head1 HISTORY
+
+CMS_sign_receipt() was added to OpenSSL 0.9.8
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/CMS_uncompress.pod b/deps/openssl/openssl/doc/crypto/CMS_uncompress.pod
new file mode 100644 (file)
index 0000000..c6056b0
--- /dev/null
@@ -0,0 +1,54 @@
+=pod
+
+=head1 NAME
+
+ CMS_uncompress - uncompress a CMS CompressedData structure
+
+=head1 SYNOPSIS
+
+ #include <openssl/cms.h>
+
+ int CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out, unsigned int flags);
+
+=head1 DESCRIPTION
+
+CMS_uncompress() extracts and uncompresses the content from a CMS
+CompressedData structure B<cms>. B<data> is a BIO to write the content to and
+B<flags> is an optional set of flags.
+
+The B<dcont> parameter is used in the rare case where the compressed content
+is detached. It will normally be set to NULL.
+
+=head1 NOTES
+
+The only currently supported compression algorithm is zlib: if the structure
+indicates the use of any other algorithm an error is returned.
+
+If zlib support is not compiled into OpenSSL then CMS_uncompress() will always
+return an error.
+
+The following flags can be passed in the B<flags> parameter.
+
+If the B<CMS_TEXT> flag is set MIME headers for type B<text/plain> are deleted
+from the content. If the content is not of type B<text/plain> then an error is
+returned.
+
+=head1 RETURN VALUES
+
+CMS_uncompress() returns either 1 for success or 0 for failure. The error can
+be obtained from ERR_get_error(3)
+
+=head1 BUGS
+
+The lack of single pass processing and the need to hold all data in memory as
+mentioned in CMS_verify() also applies to CMS_decompress().
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<CMS_compress(3)|CMS_compress(3)>
+
+=head1 HISTORY
+
+CMS_uncompress() was added to OpenSSL 0.9.8
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/CMS_verify.pod b/deps/openssl/openssl/doc/crypto/CMS_verify.pod
new file mode 100644 (file)
index 0000000..8f26fda
--- /dev/null
@@ -0,0 +1,126 @@
+=pod
+
+=head1 NAME
+
+ CMS_verify - verify a CMS SignedData structure
+
+=head1 SYNOPSIS
+
+ #include <openssl/cms.h>
+
+ int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs, X509_STORE *store, BIO *indata, BIO *out, unsigned int flags);
+
+ STACK_OF(X509) *CMS_get0_signers(CMS_ContentInfo *cms);
+
+=head1 DESCRIPTION
+
+CMS_verify() verifies a CMS SignedData structure. B<cms> is the CMS_ContentInfo
+structure to verify. B<certs> is a set of certificates in which to search for
+the signing certificate(s). B<store> is a trusted certificate store used for
+chain verification. B<indata> is the detached content if the content is not
+present in B<cms>. The content is written to B<out> if it is not NULL.
+
+B<flags> is an optional set of flags, which can be used to modify the verify
+operation.
+
+CMS_get0_signers() retrieves the signing certificate(s) from B<cms>, it must
+be called after a successful CMS_verify() operation.
+
+=head1 VERIFY PROCESS
+
+Normally the verify process proceeds as follows.
+
+Initially some sanity checks are performed on B<cms>. The type of B<cms> must
+be SignedData. There must be at least one signature on the data and if
+the content is detached B<indata> cannot be B<NULL>.
+
+An attempt is made to locate all the signing certificate(s), first looking in
+the B<certs> parameter (if it is not NULL) and then looking in any
+certificates contained in the B<cms> structure itself. If any signing
+certificate cannot be located the operation fails.
+
+Each signing certificate is chain verified using the B<smimesign> purpose and
+the supplied trusted certificate store. Any internal certificates in the message
+are used as untrusted CAs. If CRL checking is enabled in B<store> any internal
+CRLs are used in addition to attempting to look them up in B<store>. If any
+chain verify fails an error code is returned.
+
+Finally the signed content is read (and written to B<out> is it is not NULL)
+and the signature's checked.
+
+If all signature's verify correctly then the function is successful.
+
+Any of the following flags (ored together) can be passed in the B<flags>
+parameter to change the default verify behaviour.
+
+If B<CMS_NOINTERN> is set the certificates in the message itself are not
+searched when locating the signing certificate(s). This means that all the
+signing certificates must be in the B<certs> parameter.
+
+If B<CMS_NOCRL> is set and CRL checking is enabled in B<store> then any
+CRLs in the message itself are ignored.
+
+If the B<CMS_TEXT> flag is set MIME headers for type B<text/plain> are deleted
+from the content. If the content is not of type B<text/plain> then an error is
+returned.
+
+If B<CMS_NO_SIGNER_CERT_VERIFY> is set the signing certificates are not
+verified.
+
+If B<CMS_NO_ATTR_VERIFY> is set the signed attributes signature is not 
+verified.
+
+If B<CMS_NO_CONTENT_VERIFY> is set then the content digest is not checked.
+
+=head1 NOTES
+
+One application of B<CMS_NOINTERN> is to only accept messages signed by
+a small number of certificates. The acceptable certificates would be passed
+in the B<certs> parameter. In this case if the signer is not one of the
+certificates supplied in B<certs> then the verify will fail because the
+signer cannot be found.
+
+In some cases the standard techniques for looking up and validating
+certificates are not appropriate: for example an application may wish to 
+lookup certificates in a database or perform customised verification. This
+can be achieved by setting and verifying the signers certificates manually 
+using the signed data utility functions.
+
+Care should be taken when modifying the default verify behaviour, for example
+setting B<CMS_NO_CONTENT_VERIFY> will totally disable all content verification 
+and any modified content will be considered valid. This combination is however
+useful if one merely wishes to write the content to B<out> and its validity
+is not considered important.
+
+Chain verification should arguably be performed using the signing time rather
+than the current time. However since the signing time is supplied by the
+signer it cannot be trusted without additional evidence (such as a trusted
+timestamp).
+
+=head1 RETURN VALUES
+
+CMS_verify() returns 1 for a successful verification and zero if an error
+occurred.
+
+CMS_get0_signers() returns all signers or NULL if an error occurred.
+
+The error can be obtained from L<ERR_get_error(3)|ERR_get_error(3)>
+
+=head1 BUGS
+
+The trusted certificate store is not searched for the signing certificate,
+this is primarily due to the inadequacies of the current B<X509_STORE>
+functionality.
+
+The lack of single pass processing means that the signed content must all
+be held in memory if it is not detached.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<CMS_sign(3)|CMS_sign(3)>
+
+=head1 HISTORY
+
+CMS_verify() was added to OpenSSL 0.9.8
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/CMS_verify_receipt.pod b/deps/openssl/openssl/doc/crypto/CMS_verify_receipt.pod
new file mode 100644 (file)
index 0000000..9283e0e
--- /dev/null
@@ -0,0 +1,47 @@
+=pod
+
+=head1 NAME
+
+ CMS_verify_receipt - verify a CMS signed receipt
+
+=head1 SYNOPSIS
+
+ #include <openssl/cms.h>
+
+ int CMS_verify_receipt(CMS_ContentInfo *rcms, CMS_ContentInfo *ocms, STACK_OF(X509) *certs, X509_STORE *store, unsigned int flags);
+
+=head1 DESCRIPTION
+
+CMS_verify_receipt() verifies a CMS signed receipt. B<rcms> is the signed
+receipt to verify. B<ocms> is the original SignedData structure containing the
+receipt request. B<certs> is a set of certificates in which to search for the
+signing certificate. B<store> is a trusted certificate store (used for chain
+verification). 
+
+B<flags> is an optional set of flags, which can be used to modify the verify
+operation.
+
+=head1 NOTES
+
+This functions behaves in a similar way to CMS_verify() except the flag values
+B<CMS_DETACHED>, B<CMS_BINARY>, B<CMS_TEXT> and B<CMS_STREAM> are not
+supported since they do not make sense in the context of signed receipts.
+
+=head1 RETURN VALUES
+
+CMS_verify_receipt() returns 1 for a successful verification and zero if an
+error occurred.
+
+The error can be obtained from L<ERR_get_error(3)|ERR_get_error(3)>
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>,
+L<CMS_sign_receipt(3)|CMS_sign_receipt(3)>,
+L<CMS_verify(3)|CMS_verify(3)>,
+
+=head1 HISTORY
+
+CMS_verify_receipt() was added to OpenSSL 0.9.8
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/CONF_modules_free.pod b/deps/openssl/openssl/doc/crypto/CONF_modules_free.pod
new file mode 100644 (file)
index 0000000..87bc7b7
--- /dev/null
@@ -0,0 +1,47 @@
+=pod
+
+=head1 NAME
+
+ CONF_modules_free, CONF_modules_finish, CONF_modules_unload -
+ OpenSSL configuration cleanup functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/conf.h>
+
+ void CONF_modules_free(void);
+ void CONF_modules_finish(void);
+ void CONF_modules_unload(int all);
+
+=head1 DESCRIPTION
+
+CONF_modules_free() closes down and frees up all memory allocated by all
+configuration modules.
+
+CONF_modules_finish() calls each configuration modules B<finish> handler
+to free up any configuration that module may have performed.
+
+CONF_modules_unload() finishes and unloads configuration modules. If
+B<all> is set to B<0> only modules loaded from DSOs will be unloads. If
+B<all> is B<1> all modules, including builtin modules will be unloaded.
+
+=head1 NOTES
+
+Normally applications will only call CONF_modules_free() at application to
+tidy up any configuration performed.
+
+=head1 RETURN VALUE
+
+None of the functions return a value.
+
+=head1 SEE ALSO
+
+L<conf(5)|conf(5)>, L<OPENSSL_config(3)|OPENSSL_config(3)>,
+L<CONF_modules_load_file(3), CONF_modules_load_file(3)>
+
+=head1 HISTORY
+
+CONF_modules_free(), CONF_modules_unload(), and CONF_modules_finish()
+first appeared in OpenSSL 0.9.7.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/CONF_modules_load_file.pod b/deps/openssl/openssl/doc/crypto/CONF_modules_load_file.pod
new file mode 100644 (file)
index 0000000..9965d69
--- /dev/null
@@ -0,0 +1,60 @@
+=pod
+
+=head1 NAME
+
+ CONF_modules_load_file, CONF_modules_load - OpenSSL configuration functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/conf.h>
+
+ int CONF_modules_load_file(const char *filename, const char *appname,
+                          unsigned long flags);
+ int CONF_modules_load(const CONF *cnf, const char *appname,
+                     unsigned long flags);
+
+=head1 DESCRIPTION
+
+The function CONF_modules_load_file() configures OpenSSL using file
+B<filename> and application name B<appname>. If B<filename> is NULL
+the standard OpenSSL configuration file is used. If B<appname> is
+NULL the standard OpenSSL application name B<openssl_conf> is used.
+The behaviour can be cutomized using B<flags>.
+
+CONF_modules_load() is idential to CONF_modules_load_file() except it
+read configuration information from B<cnf>. 
+
+=head1 NOTES
+
+The following B<flags> are currently recognized:
+
+B<CONF_MFLAGS_IGNORE_ERRORS> if set errors returned by individual
+configuration modules are ignored. If not set the first module error is
+considered fatal and no further modules are loads.
+
+Normally any modules errors will add error information to the error queue. If
+B<CONF_MFLAGS_SILENT> is set no error information is added.
+
+If B<CONF_MFLAGS_NO_DSO> is set configuration module loading from DSOs is
+disabled.
+
+B<CONF_MFLAGS_IGNORE_MISSING_FILE> if set will make CONF_load_modules_file()
+ignore missing configuration files. Normally a missing configuration file
+return an error.
+
+=head1 RETURN VALUE
+
+These functions return 1 for success and a zero or negative value for
+failure. If module errors are not ignored the return code will reflect the
+return value of the failing module (this will always be zero or negative).
+
+=head1 SEE ALSO
+
+L<conf(5)|conf(5)>, L<OPENSSL_config(3)|OPENSSL_config(3)>,
+L<CONF_free(3), CONF_free(3)>, L<err(3),err(3)>
+
+=head1 HISTORY
+
+CONF_modules_load_file and CONF_modules_load first appeared in OpenSSL 0.9.7.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/CRYPTO_set_ex_data.pod b/deps/openssl/openssl/doc/crypto/CRYPTO_set_ex_data.pod
new file mode 100644 (file)
index 0000000..7409c02
--- /dev/null
@@ -0,0 +1,53 @@
+=pod
+
+=head1 NAME
+
+CRYPTO_set_ex_data, CRYPTO_get_ex_data - internal application specific data functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/crypto.h>
+
+ int CRYPTO_set_ex_data(CRYPTO_EX_DATA *r, int idx, void *arg);
+
+ void *CRYPTO_get_ex_data(CRYPTO_EX_DATA *r, int idx);
+
+=head1 DESCRIPTION
+
+Several OpenSSL structures can have application specific data attached to them.
+These functions are used internally by OpenSSL to manipulate application
+specific data attached to a specific structure.
+
+These functions should only be used by applications to manipulate
+B<CRYPTO_EX_DATA> structures passed to the B<new_func()>, B<free_func()> and
+B<dup_func()> callbacks: as passed to B<RSA_get_ex_new_index()> for example.
+
+B<CRYPTO_set_ex_data()> is used to set application specific data, the data is
+supplied in the B<arg> parameter and its precise meaning is up to the
+application.
+
+B<CRYPTO_get_ex_data()> is used to retrieve application specific data. The data
+is returned to the application, this will be the same value as supplied to
+a previous B<CRYPTO_set_ex_data()> call.
+
+=head1 RETURN VALUES
+
+B<CRYPTO_set_ex_data()> returns 1 on success or 0 on failure.
+
+B<CRYPTO_get_ex_data()> returns the application data or 0 on failure. 0 may also
+be valid application data but currently it can only fail if given an invalid B<idx>
+parameter.
+
+On failure an error code can be obtained from L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 SEE ALSO
+
+L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>,
+L<DSA_get_ex_new_index(3)|DSA_get_ex_new_index(3)>,
+L<DH_get_ex_new_index(3)|DH_get_ex_new_index(3)>
+
+=head1 HISTORY
+
+CRYPTO_set_ex_data() and CRYPTO_get_ex_data() have been available since SSLeay 0.9.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/DH_generate_key.pod b/deps/openssl/openssl/doc/crypto/DH_generate_key.pod
new file mode 100644 (file)
index 0000000..81f09fd
--- /dev/null
@@ -0,0 +1,50 @@
+=pod
+
+=head1 NAME
+
+DH_generate_key, DH_compute_key - perform Diffie-Hellman key exchange
+
+=head1 SYNOPSIS
+
+ #include <openssl/dh.h>
+
+ int DH_generate_key(DH *dh);
+
+ int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh);
+
+=head1 DESCRIPTION
+
+DH_generate_key() performs the first step of a Diffie-Hellman key
+exchange by generating private and public DH values. By calling
+DH_compute_key(), these are combined with the other party's public
+value to compute the shared key.
+
+DH_generate_key() expects B<dh> to contain the shared parameters
+B<dh-E<gt>p> and B<dh-E<gt>g>. It generates a random private DH value
+unless B<dh-E<gt>priv_key> is already set, and computes the
+corresponding public value B<dh-E<gt>pub_key>, which can then be
+published.
+
+DH_compute_key() computes the shared secret from the private DH value
+in B<dh> and the other party's public value in B<pub_key> and stores
+it in B<key>. B<key> must point to B<DH_size(dh)> bytes of memory.
+
+=head1 RETURN VALUES
+
+DH_generate_key() returns 1 on success, 0 otherwise.
+
+DH_compute_key() returns the size of the shared secret on success, -1
+on error.
+
+The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 SEE ALSO
+
+L<dh(3)|dh(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>, L<DH_size(3)|DH_size(3)>
+
+=head1 HISTORY
+
+DH_generate_key() and DH_compute_key() are available in all versions
+of SSLeay and OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/DH_generate_parameters.pod b/deps/openssl/openssl/doc/crypto/DH_generate_parameters.pod
new file mode 100644 (file)
index 0000000..9081e9e
--- /dev/null
@@ -0,0 +1,73 @@
+=pod
+
+=head1 NAME
+
+DH_generate_parameters, DH_check - generate and check Diffie-Hellman parameters
+
+=head1 SYNOPSIS
+
+ #include <openssl/dh.h>
+
+ DH *DH_generate_parameters(int prime_len, int generator,
+     void (*callback)(int, int, void *), void *cb_arg);
+
+ int DH_check(DH *dh, int *codes);
+
+=head1 DESCRIPTION
+
+DH_generate_parameters() generates Diffie-Hellman parameters that can
+be shared among a group of users, and returns them in a newly
+allocated B<DH> structure. The pseudo-random number generator must be
+seeded prior to calling DH_generate_parameters().
+
+B<prime_len> is the length in bits of the safe prime to be generated.
+B<generator> is a small number E<gt> 1, typically 2 or 5. 
+
+A callback function may be used to provide feedback about the progress
+of the key generation. If B<callback> is not B<NULL>, it will be
+called as described in L<BN_generate_prime(3)|BN_generate_prime(3)> while a random prime
+number is generated, and when a prime has been found, B<callback(3,
+0, cb_arg)> is called.
+
+DH_check() validates Diffie-Hellman parameters. It checks that B<p> is
+a safe prime, and that B<g> is a suitable generator. In the case of an
+error, the bit flags DH_CHECK_P_NOT_SAFE_PRIME or
+DH_NOT_SUITABLE_GENERATOR are set in B<*codes>.
+DH_UNABLE_TO_CHECK_GENERATOR is set if the generator cannot be
+checked, i.e. it does not equal 2 or 5.
+
+=head1 RETURN VALUES
+
+DH_generate_parameters() returns a pointer to the DH structure, or
+NULL if the parameter generation fails. The error codes can be
+obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+DH_check() returns 1 if the check could be performed, 0 otherwise.
+
+=head1 NOTES
+
+DH_generate_parameters() may run for several hours before finding a
+suitable prime.
+
+The parameters generated by DH_generate_parameters() are not to be
+used in signature schemes.
+
+=head1 BUGS
+
+If B<generator> is not 2 or 5, B<dh-E<gt>g>=B<generator> is not
+a usable generator.
+
+=head1 SEE ALSO
+
+L<dh(3)|dh(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>,
+L<DH_free(3)|DH_free(3)>
+
+=head1 HISTORY
+
+DH_check() is available in all versions of SSLeay and OpenSSL.
+The B<cb_arg> argument to DH_generate_parameters() was added in SSLeay 0.9.0.
+
+In versions before OpenSSL 0.9.5, DH_CHECK_P_NOT_STRONG_PRIME is used
+instead of DH_CHECK_P_NOT_SAFE_PRIME.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/DH_get_ex_new_index.pod b/deps/openssl/openssl/doc/crypto/DH_get_ex_new_index.pod
new file mode 100644 (file)
index 0000000..fa5eab2
--- /dev/null
@@ -0,0 +1,36 @@
+=pod
+
+=head1 NAME
+
+DH_get_ex_new_index, DH_set_ex_data, DH_get_ex_data - add application specific data to DH structures
+
+=head1 SYNOPSIS
+
+ #include <openssl/dh.h>
+
+ int DH_get_ex_new_index(long argl, void *argp,
+               CRYPTO_EX_new *new_func,
+               CRYPTO_EX_dup *dup_func,
+               CRYPTO_EX_free *free_func);
+
+ int DH_set_ex_data(DH *d, int idx, void *arg);
+
+ char *DH_get_ex_data(DH *d, int idx);
+
+=head1 DESCRIPTION
+
+These functions handle application specific data in DH
+structures. Their usage is identical to that of
+RSA_get_ex_new_index(), RSA_set_ex_data() and RSA_get_ex_data()
+as described in L<RSA_get_ex_new_index(3)>.
+
+=head1 SEE ALSO
+
+L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>, L<dh(3)|dh(3)>
+
+=head1 HISTORY
+
+DH_get_ex_new_index(), DH_set_ex_data() and DH_get_ex_data() are
+available since OpenSSL 0.9.5.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/DH_new.pod b/deps/openssl/openssl/doc/crypto/DH_new.pod
new file mode 100644 (file)
index 0000000..60c9300
--- /dev/null
@@ -0,0 +1,40 @@
+=pod
+
+=head1 NAME
+
+DH_new, DH_free - allocate and free DH objects
+
+=head1 SYNOPSIS
+
+ #include <openssl/dh.h>
+
+ DH* DH_new(void);
+
+ void DH_free(DH *dh);
+
+=head1 DESCRIPTION
+
+DH_new() allocates and initializes a B<DH> structure.
+
+DH_free() frees the B<DH> structure and its components. The values are
+erased before the memory is returned to the system.
+
+=head1 RETURN VALUES
+
+If the allocation fails, DH_new() returns B<NULL> and sets an error
+code that can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>. Otherwise it returns
+a pointer to the newly allocated structure.
+
+DH_free() returns no value.
+
+=head1 SEE ALSO
+
+L<dh(3)|dh(3)>, L<ERR_get_error(3)|ERR_get_error(3)>,
+L<DH_generate_parameters(3)|DH_generate_parameters(3)>,
+L<DH_generate_key(3)|DH_generate_key(3)>
+
+=head1 HISTORY
+
+DH_new() and DH_free() are available in all versions of SSLeay and OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/DH_set_method.pod b/deps/openssl/openssl/doc/crypto/DH_set_method.pod
new file mode 100644 (file)
index 0000000..d5cdc3b
--- /dev/null
@@ -0,0 +1,129 @@
+=pod
+
+=head1 NAME
+
+DH_set_default_method, DH_get_default_method,
+DH_set_method, DH_new_method, DH_OpenSSL - select DH method
+
+=head1 SYNOPSIS
+
+ #include <openssl/dh.h>
+ #include <openssl/engine.h>
+
+ void DH_set_default_method(const DH_METHOD *meth);
+
+ const DH_METHOD *DH_get_default_method(void);
+
+ int DH_set_method(DH *dh, const DH_METHOD *meth);
+
+ DH *DH_new_method(ENGINE *engine);
+
+ const DH_METHOD *DH_OpenSSL(void);
+
+=head1 DESCRIPTION
+
+A B<DH_METHOD> specifies the functions that OpenSSL uses for Diffie-Hellman
+operations. By modifying the method, alternative implementations
+such as hardware accelerators may be used. IMPORTANT: See the NOTES section for
+important information about how these DH API functions are affected by the use
+of B<ENGINE> API calls.
+
+Initially, the default DH_METHOD is the OpenSSL internal implementation, as
+returned by DH_OpenSSL().
+
+DH_set_default_method() makes B<meth> the default method for all DH
+structures created later. B<NB>: This is true only whilst no ENGINE has been set
+as a default for DH, so this function is no longer recommended.
+
+DH_get_default_method() returns a pointer to the current default DH_METHOD.
+However, the meaningfulness of this result is dependent on whether the ENGINE
+API is being used, so this function is no longer recommended.
+
+DH_set_method() selects B<meth> to perform all operations using the key B<dh>.
+This will replace the DH_METHOD used by the DH key and if the previous method
+was supplied by an ENGINE, the handle to that ENGINE will be released during the
+change. It is possible to have DH keys that only work with certain DH_METHOD
+implementations (eg. from an ENGINE module that supports embedded
+hardware-protected keys), and in such cases attempting to change the DH_METHOD
+for the key can have unexpected results.
+
+DH_new_method() allocates and initializes a DH structure so that B<engine> will
+be used for the DH operations. If B<engine> is NULL, the default ENGINE for DH
+operations is used, and if no default ENGINE is set, the DH_METHOD controlled by
+DH_set_default_method() is used.
+
+=head1 THE DH_METHOD STRUCTURE
+
+ typedef struct dh_meth_st
+ {
+     /* name of the implementation */
+       const char *name;
+
+     /* generate private and public DH values for key agreement */
+        int (*generate_key)(DH *dh);
+
+     /* compute shared secret */
+        int (*compute_key)(unsigned char *key, BIGNUM *pub_key, DH *dh);
+
+     /* compute r = a ^ p mod m (May be NULL for some implementations) */
+        int (*bn_mod_exp)(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
+                                const BIGNUM *m, BN_CTX *ctx,
+                                BN_MONT_CTX *m_ctx);
+
+     /* called at DH_new */
+        int (*init)(DH *dh);
+
+     /* called at DH_free */
+        int (*finish)(DH *dh);
+
+        int flags;
+
+        char *app_data; /* ?? */
+
+ } DH_METHOD;
+
+=head1 RETURN VALUES
+
+DH_OpenSSL() and DH_get_default_method() return pointers to the respective
+B<DH_METHOD>s.
+
+DH_set_default_method() returns no value.
+
+DH_set_method() returns non-zero if the provided B<meth> was successfully set as
+the method for B<dh> (including unloading the ENGINE handle if the previous
+method was supplied by an ENGINE).
+
+DH_new_method() returns NULL and sets an error code that can be obtained by
+L<ERR_get_error(3)|ERR_get_error(3)> if the allocation fails. Otherwise it
+returns a pointer to the newly allocated structure.
+
+=head1 NOTES
+
+As of version 0.9.7, DH_METHOD implementations are grouped together with other
+algorithmic APIs (eg. RSA_METHOD, EVP_CIPHER, etc) in B<ENGINE> modules. If a
+default ENGINE is specified for DH functionality using an ENGINE API function,
+that will override any DH defaults set using the DH API (ie.
+DH_set_default_method()). For this reason, the ENGINE API is the recommended way
+to control default implementations for use in DH and other cryptographic
+algorithms.
+
+=head1 SEE ALSO
+
+L<dh(3)|dh(3)>, L<DH_new(3)|DH_new(3)>
+
+=head1 HISTORY
+
+DH_set_default_method(), DH_get_default_method(), DH_set_method(),
+DH_new_method() and DH_OpenSSL() were added in OpenSSL 0.9.4.
+
+DH_set_default_openssl_method() and DH_get_default_openssl_method() replaced
+DH_set_default_method() and DH_get_default_method() respectively, and
+DH_set_method() and DH_new_method() were altered to use B<ENGINE>s rather than
+B<DH_METHOD>s during development of the engine version of OpenSSL 0.9.6. For
+0.9.7, the handling of defaults in the ENGINE API was restructured so that this
+change was reversed, and behaviour of the other functions resembled more closely
+the previous behaviour. The behaviour of defaults in the ENGINE API now
+transparently overrides the behaviour of defaults in the DH API without
+requiring changing these function prototypes.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/DH_size.pod b/deps/openssl/openssl/doc/crypto/DH_size.pod
new file mode 100644 (file)
index 0000000..97f26fd
--- /dev/null
@@ -0,0 +1,33 @@
+=pod
+
+=head1 NAME
+
+DH_size - get Diffie-Hellman prime size
+
+=head1 SYNOPSIS
+
+ #include <openssl/dh.h>
+
+ int DH_size(DH *dh);
+
+=head1 DESCRIPTION
+
+This function returns the Diffie-Hellman size in bytes. It can be used
+to determine how much memory must be allocated for the shared secret
+computed by DH_compute_key().
+
+B<dh-E<gt>p> must not be B<NULL>.
+
+=head1 RETURN VALUE
+
+The size in bytes.
+
+=head1 SEE ALSO
+
+L<dh(3)|dh(3)>, L<DH_generate_key(3)|DH_generate_key(3)>
+
+=head1 HISTORY
+
+DH_size() is available in all versions of SSLeay and OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/DSA_SIG_new.pod b/deps/openssl/openssl/doc/crypto/DSA_SIG_new.pod
new file mode 100644 (file)
index 0000000..3ac6140
--- /dev/null
@@ -0,0 +1,40 @@
+=pod
+
+=head1 NAME
+
+DSA_SIG_new, DSA_SIG_free - allocate and free DSA signature objects
+
+=head1 SYNOPSIS
+
+ #include <openssl/dsa.h>
+
+ DSA_SIG *DSA_SIG_new(void);
+
+ void  DSA_SIG_free(DSA_SIG *a);
+
+=head1 DESCRIPTION
+
+DSA_SIG_new() allocates and initializes a B<DSA_SIG> structure.
+
+DSA_SIG_free() frees the B<DSA_SIG> structure and its components. The
+values are erased before the memory is returned to the system.
+
+=head1 RETURN VALUES
+
+If the allocation fails, DSA_SIG_new() returns B<NULL> and sets an
+error code that can be obtained by
+L<ERR_get_error(3)|ERR_get_error(3)>. Otherwise it returns a pointer
+to the newly allocated structure.
+
+DSA_SIG_free() returns no value.
+
+=head1 SEE ALSO
+
+L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>,
+L<DSA_do_sign(3)|DSA_do_sign(3)>
+
+=head1 HISTORY
+
+DSA_SIG_new() and DSA_SIG_free() were added in OpenSSL 0.9.3.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/DSA_do_sign.pod b/deps/openssl/openssl/doc/crypto/DSA_do_sign.pod
new file mode 100644 (file)
index 0000000..5dfc733
--- /dev/null
@@ -0,0 +1,47 @@
+=pod
+
+=head1 NAME
+
+DSA_do_sign, DSA_do_verify - raw DSA signature operations
+
+=head1 SYNOPSIS
+
+ #include <openssl/dsa.h>
+
+ DSA_SIG *DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
+
+ int DSA_do_verify(const unsigned char *dgst, int dgst_len,
+            DSA_SIG *sig, DSA *dsa);
+
+=head1 DESCRIPTION
+
+DSA_do_sign() computes a digital signature on the B<len> byte message
+digest B<dgst> using the private key B<dsa> and returns it in a
+newly allocated B<DSA_SIG> structure.
+
+L<DSA_sign_setup(3)|DSA_sign_setup(3)> may be used to precompute part
+of the signing operation in case signature generation is
+time-critical.
+
+DSA_do_verify() verifies that the signature B<sig> matches a given
+message digest B<dgst> of size B<len>.  B<dsa> is the signer's public
+key.
+
+=head1 RETURN VALUES
+
+DSA_do_sign() returns the signature, NULL on error.  DSA_do_verify()
+returns 1 for a valid signature, 0 for an incorrect signature and -1
+on error. The error codes can be obtained by
+L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 SEE ALSO
+
+L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>,
+L<DSA_SIG_new(3)|DSA_SIG_new(3)>,
+L<DSA_sign(3)|DSA_sign(3)>
+
+=head1 HISTORY
+
+DSA_do_sign() and DSA_do_verify() were added in OpenSSL 0.9.3.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/DSA_dup_DH.pod b/deps/openssl/openssl/doc/crypto/DSA_dup_DH.pod
new file mode 100644 (file)
index 0000000..7f6f0d1
--- /dev/null
@@ -0,0 +1,36 @@
+=pod
+
+=head1 NAME
+
+DSA_dup_DH - create a DH structure out of DSA structure
+
+=head1 SYNOPSIS
+
+ #include <openssl/dsa.h>
+
+ DH * DSA_dup_DH(const DSA *r);
+
+=head1 DESCRIPTION
+
+DSA_dup_DH() duplicates DSA parameters/keys as DH parameters/keys. q
+is lost during that conversion, but the resulting DH parameters
+contain its length.
+
+=head1 RETURN VALUE
+
+DSA_dup_DH() returns the new B<DH> structure, and NULL on error. The
+error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 NOTE
+
+Be careful to avoid small subgroup attacks when using this.
+
+=head1 SEE ALSO
+
+L<dh(3)|dh(3)>, L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>
+
+=head1 HISTORY
+
+DSA_dup_DH() was added in OpenSSL 0.9.4.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/DSA_generate_key.pod b/deps/openssl/openssl/doc/crypto/DSA_generate_key.pod
new file mode 100644 (file)
index 0000000..af83ccf
--- /dev/null
@@ -0,0 +1,34 @@
+=pod
+
+=head1 NAME
+
+DSA_generate_key - generate DSA key pair
+
+=head1 SYNOPSIS
+
+ #include <openssl/dsa.h>
+
+ int DSA_generate_key(DSA *a);
+
+=head1 DESCRIPTION
+
+DSA_generate_key() expects B<a> to contain DSA parameters. It generates
+a new key pair and stores it in B<a-E<gt>pub_key> and B<a-E<gt>priv_key>.
+
+The PRNG must be seeded prior to calling DSA_generate_key().
+
+=head1 RETURN VALUE
+
+DSA_generate_key() returns 1 on success, 0 otherwise.
+The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 SEE ALSO
+
+L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>,
+L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>
+
+=head1 HISTORY
+
+DSA_generate_key() is available since SSLeay 0.8.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/DSA_generate_parameters.pod b/deps/openssl/openssl/doc/crypto/DSA_generate_parameters.pod
new file mode 100644 (file)
index 0000000..be7c924
--- /dev/null
@@ -0,0 +1,105 @@
+=pod
+
+=head1 NAME
+
+DSA_generate_parameters - generate DSA parameters
+
+=head1 SYNOPSIS
+
+ #include <openssl/dsa.h>
+
+ DSA *DSA_generate_parameters(int bits, unsigned char *seed,
+                int seed_len, int *counter_ret, unsigned long *h_ret,
+               void (*callback)(int, int, void *), void *cb_arg);
+
+=head1 DESCRIPTION
+
+DSA_generate_parameters() generates primes p and q and a generator g
+for use in the DSA.
+
+B<bits> is the length of the prime to be generated; the DSS allows a
+maximum of 1024 bits.
+
+If B<seed> is B<NULL> or B<seed_len> E<lt> 20, the primes will be
+generated at random. Otherwise, the seed is used to generate
+them. If the given seed does not yield a prime q, a new random
+seed is chosen and placed at B<seed>.
+
+DSA_generate_parameters() places the iteration count in
+*B<counter_ret> and a counter used for finding a generator in
+*B<h_ret>, unless these are B<NULL>.
+
+A callback function may be used to provide feedback about the progress
+of the key generation. If B<callback> is not B<NULL>, it will be
+called as follows:
+
+=over 4
+
+=item *
+
+When a candidate for q is generated, B<callback(0, m++, cb_arg)> is called
+(m is 0 for the first candidate).
+
+=item *
+
+When a candidate for q has passed a test by trial division,
+B<callback(1, -1, cb_arg)> is called.
+While a candidate for q is tested by Miller-Rabin primality tests,
+B<callback(1, i, cb_arg)> is called in the outer loop
+(once for each witness that confirms that the candidate may be prime);
+i is the loop counter (starting at 0).
+
+=item *
+
+When a prime q has been found, B<callback(2, 0, cb_arg)> and
+B<callback(3, 0, cb_arg)> are called.
+
+=item *
+
+Before a candidate for p (other than the first) is generated and tested,
+B<callback(0, counter, cb_arg)> is called.
+
+=item *
+
+When a candidate for p has passed the test by trial division,
+B<callback(1, -1, cb_arg)> is called.
+While it is tested by the Miller-Rabin primality test,
+B<callback(1, i, cb_arg)> is called in the outer loop
+(once for each witness that confirms that the candidate may be prime).
+i is the loop counter (starting at 0).
+
+=item *
+
+When p has been found, B<callback(2, 1, cb_arg)> is called.
+
+=item *
+
+When the generator has been found, B<callback(3, 1, cb_arg)> is called.
+
+=back
+
+=head1 RETURN VALUE
+
+DSA_generate_parameters() returns a pointer to the DSA structure, or
+B<NULL> if the parameter generation fails. The error codes can be
+obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 BUGS
+
+Seed lengths E<gt> 20 are not supported.
+
+=head1 SEE ALSO
+
+L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>,
+L<DSA_free(3)|DSA_free(3)>
+
+=head1 HISTORY
+
+DSA_generate_parameters() appeared in SSLeay 0.8. The B<cb_arg>
+argument was added in SSLeay 0.9.0.
+In versions up to OpenSSL 0.9.4, B<callback(1, ...)> was called
+in the inner loop of the Miller-Rabin test whenever it reached the
+squaring step (the parameters to B<callback> did not reveal how many
+witnesses had been tested); since OpenSSL 0.9.5, B<callback(1, ...)>
+is called as in BN_is_prime(3), i.e. once for each witness.
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/DSA_get_ex_new_index.pod b/deps/openssl/openssl/doc/crypto/DSA_get_ex_new_index.pod
new file mode 100644 (file)
index 0000000..fb6efc1
--- /dev/null
@@ -0,0 +1,36 @@
+=pod
+
+=head1 NAME
+
+DSA_get_ex_new_index, DSA_set_ex_data, DSA_get_ex_data - add application specific data to DSA structures
+
+=head1 SYNOPSIS
+
+ #include <openssl/dsa.h>
+
+ int DSA_get_ex_new_index(long argl, void *argp,
+               CRYPTO_EX_new *new_func,
+               CRYPTO_EX_dup *dup_func,
+               CRYPTO_EX_free *free_func);
+
+ int DSA_set_ex_data(DSA *d, int idx, void *arg);
+
+ char *DSA_get_ex_data(DSA *d, int idx);
+
+=head1 DESCRIPTION
+
+These functions handle application specific data in DSA
+structures. Their usage is identical to that of
+RSA_get_ex_new_index(), RSA_set_ex_data() and RSA_get_ex_data()
+as described in L<RSA_get_ex_new_index(3)>.
+
+=head1 SEE ALSO
+
+L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>, L<dsa(3)|dsa(3)>
+
+=head1 HISTORY
+
+DSA_get_ex_new_index(), DSA_set_ex_data() and DSA_get_ex_data() are
+available since OpenSSL 0.9.5.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/DSA_new.pod b/deps/openssl/openssl/doc/crypto/DSA_new.pod
new file mode 100644 (file)
index 0000000..48e9b82
--- /dev/null
@@ -0,0 +1,42 @@
+=pod
+
+=head1 NAME
+
+DSA_new, DSA_free - allocate and free DSA objects
+
+=head1 SYNOPSIS
+
+ #include <openssl/dsa.h>
+
+ DSA* DSA_new(void);
+
+ void DSA_free(DSA *dsa);
+
+=head1 DESCRIPTION
+
+DSA_new() allocates and initializes a B<DSA> structure. It is equivalent to
+calling DSA_new_method(NULL).
+
+DSA_free() frees the B<DSA> structure and its components. The values are
+erased before the memory is returned to the system.
+
+=head1 RETURN VALUES
+
+If the allocation fails, DSA_new() returns B<NULL> and sets an error
+code that can be obtained by
+L<ERR_get_error(3)|ERR_get_error(3)>. Otherwise it returns a pointer
+to the newly allocated structure.
+
+DSA_free() returns no value.
+
+=head1 SEE ALSO
+
+L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>,
+L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>,
+L<DSA_generate_key(3)|DSA_generate_key(3)>
+
+=head1 HISTORY
+
+DSA_new() and DSA_free() are available in all versions of SSLeay and OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/DSA_set_method.pod b/deps/openssl/openssl/doc/crypto/DSA_set_method.pod
new file mode 100644 (file)
index 0000000..9c1434b
--- /dev/null
@@ -0,0 +1,143 @@
+=pod
+
+=head1 NAME
+
+DSA_set_default_method, DSA_get_default_method,
+DSA_set_method, DSA_new_method, DSA_OpenSSL - select DSA method
+
+=head1 SYNOPSIS
+
+ #include <openssl/dsa.h>
+ #include <openssl/engine.h>
+
+ void DSA_set_default_method(const DSA_METHOD *meth);
+
+ const DSA_METHOD *DSA_get_default_method(void);
+
+ int DSA_set_method(DSA *dsa, const DSA_METHOD *meth);
+
+ DSA *DSA_new_method(ENGINE *engine);
+
+ DSA_METHOD *DSA_OpenSSL(void);
+
+=head1 DESCRIPTION
+
+A B<DSA_METHOD> specifies the functions that OpenSSL uses for DSA
+operations. By modifying the method, alternative implementations
+such as hardware accelerators may be used. IMPORTANT: See the NOTES section for
+important information about how these DSA API functions are affected by the use
+of B<ENGINE> API calls.
+
+Initially, the default DSA_METHOD is the OpenSSL internal implementation,
+as returned by DSA_OpenSSL().
+
+DSA_set_default_method() makes B<meth> the default method for all DSA
+structures created later. B<NB>: This is true only whilst no ENGINE has
+been set as a default for DSA, so this function is no longer recommended.
+
+DSA_get_default_method() returns a pointer to the current default
+DSA_METHOD. However, the meaningfulness of this result is dependent on
+whether the ENGINE API is being used, so this function is no longer 
+recommended.
+
+DSA_set_method() selects B<meth> to perform all operations using the key
+B<rsa>. This will replace the DSA_METHOD used by the DSA key and if the
+previous method was supplied by an ENGINE, the handle to that ENGINE will
+be released during the change. It is possible to have DSA keys that only
+work with certain DSA_METHOD implementations (eg. from an ENGINE module
+that supports embedded hardware-protected keys), and in such cases
+attempting to change the DSA_METHOD for the key can have unexpected
+results.
+
+DSA_new_method() allocates and initializes a DSA structure so that B<engine>
+will be used for the DSA operations. If B<engine> is NULL, the default engine
+for DSA operations is used, and if no default ENGINE is set, the DSA_METHOD
+controlled by DSA_set_default_method() is used.
+
+=head1 THE DSA_METHOD STRUCTURE
+
+struct
+ {
+     /* name of the implementation */
+        const char *name;
+
+     /* sign */
+       DSA_SIG *(*dsa_do_sign)(const unsigned char *dgst, int dlen,
+                                 DSA *dsa);
+
+     /* pre-compute k^-1 and r */
+       int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp,
+                                 BIGNUM **rp);
+
+     /* verify */
+       int (*dsa_do_verify)(const unsigned char *dgst, int dgst_len,
+                                 DSA_SIG *sig, DSA *dsa);
+
+     /* compute rr = a1^p1 * a2^p2 mod m (May be NULL for some
+                                          implementations) */
+       int (*dsa_mod_exp)(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
+                                 BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
+                                 BN_CTX *ctx, BN_MONT_CTX *in_mont);
+
+     /* compute r = a ^ p mod m (May be NULL for some implementations) */
+        int (*bn_mod_exp)(DSA *dsa, BIGNUM *r, BIGNUM *a,
+                                 const BIGNUM *p, const BIGNUM *m,
+                                 BN_CTX *ctx, BN_MONT_CTX *m_ctx);
+
+     /* called at DSA_new */
+        int (*init)(DSA *DSA);
+
+     /* called at DSA_free */
+        int (*finish)(DSA *DSA);
+
+        int flags;
+
+        char *app_data; /* ?? */
+
+ } DSA_METHOD;
+
+=head1 RETURN VALUES
+
+DSA_OpenSSL() and DSA_get_default_method() return pointers to the respective
+B<DSA_METHOD>s.
+
+DSA_set_default_method() returns no value.
+
+DSA_set_method() returns non-zero if the provided B<meth> was successfully set as
+the method for B<dsa> (including unloading the ENGINE handle if the previous
+method was supplied by an ENGINE).
+
+DSA_new_method() returns NULL and sets an error code that can be
+obtained by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation
+fails. Otherwise it returns a pointer to the newly allocated structure.
+
+=head1 NOTES
+
+As of version 0.9.7, DSA_METHOD implementations are grouped together with other
+algorithmic APIs (eg. RSA_METHOD, EVP_CIPHER, etc) in B<ENGINE> modules. If a
+default ENGINE is specified for DSA functionality using an ENGINE API function,
+that will override any DSA defaults set using the DSA API (ie.
+DSA_set_default_method()). For this reason, the ENGINE API is the recommended way
+to control default implementations for use in DSA and other cryptographic
+algorithms.
+
+=head1 SEE ALSO
+
+L<dsa(3)|dsa(3)>, L<DSA_new(3)|DSA_new(3)>
+
+=head1 HISTORY
+
+DSA_set_default_method(), DSA_get_default_method(), DSA_set_method(),
+DSA_new_method() and DSA_OpenSSL() were added in OpenSSL 0.9.4.
+
+DSA_set_default_openssl_method() and DSA_get_default_openssl_method() replaced
+DSA_set_default_method() and DSA_get_default_method() respectively, and
+DSA_set_method() and DSA_new_method() were altered to use B<ENGINE>s rather than
+B<DSA_METHOD>s during development of the engine version of OpenSSL 0.9.6. For
+0.9.7, the handling of defaults in the ENGINE API was restructured so that this
+change was reversed, and behaviour of the other functions resembled more closely
+the previous behaviour. The behaviour of defaults in the ENGINE API now
+transparently overrides the behaviour of defaults in the DSA API without
+requiring changing these function prototypes.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/DSA_sign.pod b/deps/openssl/openssl/doc/crypto/DSA_sign.pod
new file mode 100644 (file)
index 0000000..97389e8
--- /dev/null
@@ -0,0 +1,66 @@
+=pod
+
+=head1 NAME
+
+DSA_sign, DSA_sign_setup, DSA_verify - DSA signatures
+
+=head1 SYNOPSIS
+
+ #include <openssl/dsa.h>
+
+ int   DSA_sign(int type, const unsigned char *dgst, int len,
+               unsigned char *sigret, unsigned int *siglen, DSA *dsa);
+
+ int   DSA_sign_setup(DSA *dsa, BN_CTX *ctx, BIGNUM **kinvp,
+                BIGNUM **rp);
+
+ int   DSA_verify(int type, const unsigned char *dgst, int len,
+               unsigned char *sigbuf, int siglen, DSA *dsa);
+
+=head1 DESCRIPTION
+
+DSA_sign() computes a digital signature on the B<len> byte message
+digest B<dgst> using the private key B<dsa> and places its ASN.1 DER
+encoding at B<sigret>. The length of the signature is places in
+*B<siglen>. B<sigret> must point to DSA_size(B<dsa>) bytes of memory.
+
+DSA_sign_setup() may be used to precompute part of the signing
+operation in case signature generation is time-critical. It expects
+B<dsa> to contain DSA parameters. It places the precomputed values
+in newly allocated B<BIGNUM>s at *B<kinvp> and *B<rp>, after freeing
+the old ones unless *B<kinvp> and *B<rp> are NULL. These values may
+be passed to DSA_sign() in B<dsa-E<gt>kinv> and B<dsa-E<gt>r>.
+B<ctx> is a pre-allocated B<BN_CTX> or NULL.
+
+DSA_verify() verifies that the signature B<sigbuf> of size B<siglen>
+matches a given message digest B<dgst> of size B<len>.
+B<dsa> is the signer's public key.
+
+The B<type> parameter is ignored.
+
+The PRNG must be seeded before DSA_sign() (or DSA_sign_setup())
+is called.
+
+=head1 RETURN VALUES
+
+DSA_sign() and DSA_sign_setup() return 1 on success, 0 on error.
+DSA_verify() returns 1 for a valid signature, 0 for an incorrect
+signature and -1 on error. The error codes can be obtained by
+L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 CONFORMING TO
+
+US Federal Information Processing Standard FIPS 186 (Digital Signature
+Standard, DSS), ANSI X9.30
+
+=head1 SEE ALSO
+
+L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>,
+L<DSA_do_sign(3)|DSA_do_sign(3)>
+
+=head1 HISTORY
+
+DSA_sign() and DSA_verify() are available in all versions of SSLeay.
+DSA_sign_setup() was added in SSLeay 0.8.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/DSA_size.pod b/deps/openssl/openssl/doc/crypto/DSA_size.pod
new file mode 100644 (file)
index 0000000..ba4f650
--- /dev/null
@@ -0,0 +1,33 @@
+=pod
+
+=head1 NAME
+
+DSA_size - get DSA signature size
+
+=head1 SYNOPSIS
+
+ #include <openssl/dsa.h>
+
+ int DSA_size(const DSA *dsa);
+
+=head1 DESCRIPTION
+
+This function returns the size of an ASN.1 encoded DSA signature in
+bytes. It can be used to determine how much memory must be allocated
+for a DSA signature.
+
+B<dsa-E<gt>q> must not be B<NULL>.
+
+=head1 RETURN VALUE
+
+The size in bytes.
+
+=head1 SEE ALSO
+
+L<dsa(3)|dsa(3)>, L<DSA_sign(3)|DSA_sign(3)>
+
+=head1 HISTORY
+
+DSA_size() is available in all versions of SSLeay and OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/ERR_GET_LIB.pod b/deps/openssl/openssl/doc/crypto/ERR_GET_LIB.pod
new file mode 100644 (file)
index 0000000..2a129da
--- /dev/null
@@ -0,0 +1,51 @@
+=pod
+
+=head1 NAME
+
+ERR_GET_LIB, ERR_GET_FUNC, ERR_GET_REASON - get library, function and
+reason code
+
+=head1 SYNOPSIS
+
+ #include <openssl/err.h>
+
+ int ERR_GET_LIB(unsigned long e);
+
+ int ERR_GET_FUNC(unsigned long e);
+
+ int ERR_GET_REASON(unsigned long e);
+
+=head1 DESCRIPTION
+
+The error code returned by ERR_get_error() consists of a library
+number, function code and reason code. ERR_GET_LIB(), ERR_GET_FUNC()
+and ERR_GET_REASON() can be used to extract these.
+
+The library number and function code describe where the error
+occurred, the reason code is the information about what went wrong.
+
+Each sub-library of OpenSSL has a unique library number; function and
+reason codes are unique within each sub-library.  Note that different
+libraries may use the same value to signal different functions and
+reasons.
+
+B<ERR_R_...> reason codes such as B<ERR_R_MALLOC_FAILURE> are globally
+unique. However, when checking for sub-library specific reason codes,
+be sure to also compare the library number.
+
+ERR_GET_LIB(), ERR_GET_FUNC() and ERR_GET_REASON() are macros.
+
+=head1 RETURN VALUES
+
+The library number, function code and reason code respectively.
+
+=head1 SEE ALSO
+
+L<err(3)|err(3)>, L<ERR_get_error(3)|ERR_get_error(3)>
+
+=head1 HISTORY
+
+ERR_GET_LIB(), ERR_GET_FUNC() and ERR_GET_REASON() are available in
+all versions of SSLeay and OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/ERR_clear_error.pod b/deps/openssl/openssl/doc/crypto/ERR_clear_error.pod
new file mode 100644 (file)
index 0000000..566e1f4
--- /dev/null
@@ -0,0 +1,29 @@
+=pod
+
+=head1 NAME
+
+ERR_clear_error - clear the error queue
+
+=head1 SYNOPSIS
+
+ #include <openssl/err.h>
+
+ void ERR_clear_error(void);
+
+=head1 DESCRIPTION
+
+ERR_clear_error() empties the current thread's error queue.
+
+=head1 RETURN VALUES
+
+ERR_clear_error() has no return value.
+
+=head1 SEE ALSO
+
+L<err(3)|err(3)>, L<ERR_get_error(3)|ERR_get_error(3)>
+
+=head1 HISTORY
+
+ERR_clear_error() is available in all versions of SSLeay and OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/ERR_error_string.pod b/deps/openssl/openssl/doc/crypto/ERR_error_string.pod
new file mode 100644 (file)
index 0000000..cdfa7fe
--- /dev/null
@@ -0,0 +1,73 @@
+=pod
+
+=head1 NAME
+
+ERR_error_string, ERR_error_string_n, ERR_lib_error_string,
+ERR_func_error_string, ERR_reason_error_string - obtain human-readable
+error message
+
+=head1 SYNOPSIS
+
+ #include <openssl/err.h>
+
+ char *ERR_error_string(unsigned long e, char *buf);
+ void ERR_error_string_n(unsigned long e, char *buf, size_t len);
+
+ const char *ERR_lib_error_string(unsigned long e);
+ const char *ERR_func_error_string(unsigned long e);
+ const char *ERR_reason_error_string(unsigned long e);
+
+=head1 DESCRIPTION
+
+ERR_error_string() generates a human-readable string representing the
+error code I<e>, and places it at I<buf>. I<buf> must be at least 120
+bytes long. If I<buf> is B<NULL>, the error string is placed in a
+static buffer.
+ERR_error_string_n() is a variant of ERR_error_string() that writes
+at most I<len> characters (including the terminating 0)
+and truncates the string if necessary.
+For ERR_error_string_n(), I<buf> may not be B<NULL>.
+
+The string will have the following format:
+
+ error:[error code]:[library name]:[function name]:[reason string]
+
+I<error code> is an 8 digit hexadecimal number, I<library name>,
+I<function name> and I<reason string> are ASCII text.
+
+ERR_lib_error_string(), ERR_func_error_string() and
+ERR_reason_error_string() return the library name, function
+name and reason string respectively.
+
+The OpenSSL error strings should be loaded by calling
+L<ERR_load_crypto_strings(3)|ERR_load_crypto_strings(3)> or, for SSL
+applications, L<SSL_load_error_strings(3)|SSL_load_error_strings(3)>
+first.
+If there is no text string registered for the given error code,
+the error string will contain the numeric code.
+
+L<ERR_print_errors(3)|ERR_print_errors(3)> can be used to print
+all error codes currently in the queue.
+
+=head1 RETURN VALUES
+
+ERR_error_string() returns a pointer to a static buffer containing the
+string if I<buf> B<== NULL>, I<buf> otherwise.
+
+ERR_lib_error_string(), ERR_func_error_string() and
+ERR_reason_error_string() return the strings, and B<NULL> if
+none is registered for the error code.
+
+=head1 SEE ALSO
+
+L<err(3)|err(3)>, L<ERR_get_error(3)|ERR_get_error(3)>,
+L<ERR_load_crypto_strings(3)|ERR_load_crypto_strings(3)>,
+L<SSL_load_error_strings(3)|SSL_load_error_strings(3)>
+L<ERR_print_errors(3)|ERR_print_errors(3)>
+
+=head1 HISTORY
+
+ERR_error_string() is available in all versions of SSLeay and OpenSSL.
+ERR_error_string_n() was added in OpenSSL 0.9.6.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/ERR_get_error.pod b/deps/openssl/openssl/doc/crypto/ERR_get_error.pod
new file mode 100644 (file)
index 0000000..3444304
--- /dev/null
@@ -0,0 +1,76 @@
+=pod
+
+=head1 NAME
+
+ERR_get_error, ERR_peek_error, ERR_peek_last_error,
+ERR_get_error_line, ERR_peek_error_line, ERR_peek_last_error_line,
+ERR_get_error_line_data, ERR_peek_error_line_data,
+ERR_peek_last_error_line_data - obtain error code and data
+
+=head1 SYNOPSIS
+
+ #include <openssl/err.h>
+
+ unsigned long ERR_get_error(void);
+ unsigned long ERR_peek_error(void);
+ unsigned long ERR_peek_last_error(void);
+
+ unsigned long ERR_get_error_line(const char **file, int *line);
+ unsigned long ERR_peek_error_line(const char **file, int *line);
+ unsigned long ERR_peek_last_error_line(const char **file, int *line);
+
+ unsigned long ERR_get_error_line_data(const char **file, int *line,
+         const char **data, int *flags);
+ unsigned long ERR_peek_error_line_data(const char **file, int *line,
+         const char **data, int *flags);
+ unsigned long ERR_peek_last_error_line_data(const char **file, int *line,
+         const char **data, int *flags);
+
+=head1 DESCRIPTION
+
+ERR_get_error() returns the earliest error code from the thread's error
+queue and removes the entry. This function can be called repeatedly
+until there are no more error codes to return.
+
+ERR_peek_error() returns the earliest error code from the thread's
+error queue without modifying it.
+
+ERR_peek_last_error() returns the latest error code from the thread's
+error queue without modifying it.
+
+See L<ERR_GET_LIB(3)|ERR_GET_LIB(3)> for obtaining information about
+location and reason of the error, and
+L<ERR_error_string(3)|ERR_error_string(3)> for human-readable error
+messages.
+
+ERR_get_error_line(), ERR_peek_error_line() and
+ERR_peek_last_error_line() are the same as the above, but they
+additionally store the file name and line number where
+the error occurred in *B<file> and *B<line>, unless these are B<NULL>.
+
+ERR_get_error_line_data(), ERR_peek_error_line_data() and
+ERR_get_last_error_line_data() store additional data and flags
+associated with the error code in *B<data>
+and *B<flags>, unless these are B<NULL>. *B<data> contains a string
+if *B<flags>&B<ERR_TXT_STRING>. If it has been allocated by OPENSSL_malloc(),
+*B<flags>&B<ERR_TXT_MALLOCED> is true.
+
+=head1 RETURN VALUES
+
+The error code, or 0 if there is no error in the queue.
+
+=head1 SEE ALSO
+
+L<err(3)|err(3)>, L<ERR_error_string(3)|ERR_error_string(3)>,
+L<ERR_GET_LIB(3)|ERR_GET_LIB(3)>
+
+=head1 HISTORY
+
+ERR_get_error(), ERR_peek_error(), ERR_get_error_line() and
+ERR_peek_error_line() are available in all versions of SSLeay and
+OpenSSL. ERR_get_error_line_data() and ERR_peek_error_line_data()
+were added in SSLeay 0.9.0.
+ERR_peek_last_error(), ERR_peek_last_error_line() and
+ERR_peek_last_error_line_data() were added in OpenSSL 0.9.7.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/ERR_load_crypto_strings.pod b/deps/openssl/openssl/doc/crypto/ERR_load_crypto_strings.pod
new file mode 100644 (file)
index 0000000..9bdec75
--- /dev/null
@@ -0,0 +1,46 @@
+=pod
+
+=head1 NAME
+
+ERR_load_crypto_strings, SSL_load_error_strings, ERR_free_strings -
+load and free error strings
+
+=head1 SYNOPSIS
+
+ #include <openssl/err.h>
+
+ void ERR_load_crypto_strings(void);
+ void ERR_free_strings(void);
+
+ #include <openssl/ssl.h>
+
+ void SSL_load_error_strings(void);
+
+=head1 DESCRIPTION
+
+ERR_load_crypto_strings() registers the error strings for all
+B<libcrypto> functions. SSL_load_error_strings() does the same,
+but also registers the B<libssl> error strings.
+
+One of these functions should be called before generating
+textual error messages. However, this is not required when memory
+usage is an issue.
+
+ERR_free_strings() frees all previously loaded error strings.
+
+=head1 RETURN VALUES
+
+ERR_load_crypto_strings(), SSL_load_error_strings() and
+ERR_free_strings() return no values.
+
+=head1 SEE ALSO
+
+L<err(3)|err(3)>, L<ERR_error_string(3)|ERR_error_string(3)>
+
+=head1 HISTORY
+
+ERR_load_error_strings(), SSL_load_error_strings() and
+ERR_free_strings() are available in all versions of SSLeay and
+OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/ERR_load_strings.pod b/deps/openssl/openssl/doc/crypto/ERR_load_strings.pod
new file mode 100644 (file)
index 0000000..5acdd0e
--- /dev/null
@@ -0,0 +1,54 @@
+=pod
+
+=head1 NAME
+
+ERR_load_strings, ERR_PACK, ERR_get_next_error_library - load
+arbitrary error strings
+
+=head1 SYNOPSIS
+
+ #include <openssl/err.h>
+
+ void ERR_load_strings(int lib, ERR_STRING_DATA str[]);
+
+ int ERR_get_next_error_library(void);
+
+ unsigned long ERR_PACK(int lib, int func, int reason);
+
+=head1 DESCRIPTION
+
+ERR_load_strings() registers error strings for library number B<lib>.
+
+B<str> is an array of error string data:
+
+ typedef struct ERR_string_data_st
+ {
+        unsigned long error;
+        char *string;
+ } ERR_STRING_DATA;
+
+The error code is generated from the library number and a function and
+reason code: B<error> = ERR_PACK(B<lib>, B<func>, B<reason>).
+ERR_PACK() is a macro.
+
+The last entry in the array is {0,0}.
+
+ERR_get_next_error_library() can be used to assign library numbers
+to user libraries at runtime.
+
+=head1 RETURN VALUE
+
+ERR_load_strings() returns no value. ERR_PACK() return the error code.
+ERR_get_next_error_library() returns a new library number.
+
+=head1 SEE ALSO
+
+L<err(3)|err(3)>, L<ERR_load_strings(3)|ERR_load_strings(3)>
+
+=head1 HISTORY
+
+ERR_load_error_strings() and ERR_PACK() are available in all versions
+of SSLeay and OpenSSL. ERR_get_next_error_library() was added in
+SSLeay 0.9.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/ERR_print_errors.pod b/deps/openssl/openssl/doc/crypto/ERR_print_errors.pod
new file mode 100644 (file)
index 0000000..b100a5f
--- /dev/null
@@ -0,0 +1,51 @@
+=pod
+
+=head1 NAME
+
+ERR_print_errors, ERR_print_errors_fp - print error messages
+
+=head1 SYNOPSIS
+
+ #include <openssl/err.h>
+
+ void ERR_print_errors(BIO *bp);
+ void ERR_print_errors_fp(FILE *fp);
+
+=head1 DESCRIPTION
+
+ERR_print_errors() is a convenience function that prints the error
+strings for all errors that OpenSSL has recorded to B<bp>, thus
+emptying the error queue.
+
+ERR_print_errors_fp() is the same, except that the output goes to a
+B<FILE>.
+
+
+The error strings will have the following format:
+
+ [pid]:error:[error code]:[library name]:[function name]:[reason string]:[file name]:[line]:[optional text message]
+
+I<error code> is an 8 digit hexadecimal number. I<library name>,
+I<function name> and I<reason string> are ASCII text, as is I<optional
+text message> if one was set for the respective error code.
+
+If there is no text string registered for the given error code,
+the error string will contain the numeric code.
+
+=head1 RETURN VALUES
+
+ERR_print_errors() and ERR_print_errors_fp() return no values.
+
+=head1 SEE ALSO
+
+L<err(3)|err(3)>, L<ERR_error_string(3)|ERR_error_string(3)>,
+L<ERR_get_error(3)|ERR_get_error(3)>,
+L<ERR_load_crypto_strings(3)|ERR_load_crypto_strings(3)>,
+L<SSL_load_error_strings(3)|SSL_load_error_strings(3)>
+
+=head1 HISTORY
+
+ERR_print_errors() and ERR_print_errors_fp()
+are available in all versions of SSLeay and OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/ERR_put_error.pod b/deps/openssl/openssl/doc/crypto/ERR_put_error.pod
new file mode 100644 (file)
index 0000000..acd241f
--- /dev/null
@@ -0,0 +1,44 @@
+=pod
+
+=head1 NAME
+
+ERR_put_error, ERR_add_error_data - record an error
+
+=head1 SYNOPSIS
+
+ #include <openssl/err.h>
+
+ void ERR_put_error(int lib, int func, int reason, const char *file,
+         int line);
+
+ void ERR_add_error_data(int num, ...);
+
+=head1 DESCRIPTION
+
+ERR_put_error() adds an error code to the thread's error queue. It
+signals that the error of reason code B<reason> occurred in function
+B<func> of library B<lib>, in line number B<line> of B<file>.
+This function is usually called by a macro.
+
+ERR_add_error_data() associates the concatenation of its B<num> string
+arguments with the error code added last.
+
+L<ERR_load_strings(3)|ERR_load_strings(3)> can be used to register
+error strings so that the application can a generate human-readable
+error messages for the error code.
+
+=head1 RETURN VALUES
+
+ERR_put_error() and ERR_add_error_data() return
+no values.
+
+=head1 SEE ALSO
+
+L<err(3)|err(3)>, L<ERR_load_strings(3)|ERR_load_strings(3)>
+
+=head1 HISTORY
+
+ERR_put_error() is available in all versions of SSLeay and OpenSSL.
+ERR_add_error_data() was added in SSLeay 0.9.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/ERR_remove_state.pod b/deps/openssl/openssl/doc/crypto/ERR_remove_state.pod
new file mode 100644 (file)
index 0000000..72925fb
--- /dev/null
@@ -0,0 +1,34 @@
+=pod
+
+=head1 NAME
+
+ERR_remove_state - free a thread's error queue
+
+=head1 SYNOPSIS
+
+ #include <openssl/err.h>
+
+ void ERR_remove_state(unsigned long pid);
+
+=head1 DESCRIPTION
+
+ERR_remove_state() frees the error queue associated with thread B<pid>.
+If B<pid> == 0, the current thread will have its error queue removed.
+
+Since error queue data structures are allocated automatically for new
+threads, they must be freed when threads are terminated in order to
+avoid memory leaks.
+
+=head1 RETURN VALUE
+
+ERR_remove_state() returns no value.
+
+=head1 SEE ALSO
+
+L<err(3)|err(3)>
+
+=head1 HISTORY
+
+ERR_remove_state() is available in all versions of SSLeay and OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/ERR_set_mark.pod b/deps/openssl/openssl/doc/crypto/ERR_set_mark.pod
new file mode 100644 (file)
index 0000000..d3ca4f2
--- /dev/null
@@ -0,0 +1,38 @@
+=pod
+
+=head1 NAME
+
+ERR_set_mark, ERR_pop_to_mark - set marks and pop errors until mark
+
+=head1 SYNOPSIS
+
+ #include <openssl/err.h>
+
+ int ERR_set_mark(void);
+
+ int ERR_pop_to_mark(void);
+
+=head1 DESCRIPTION
+
+ERR_set_mark() sets a mark on the current topmost error record if there
+is one.
+
+ERR_pop_to_mark() will pop the top of the error stack until a mark is found.
+The mark is then removed.  If there is no mark, the whole stack is removed.
+
+=head1 RETURN VALUES
+
+ERR_set_mark() returns 0 if the error stack is empty, otherwise 1.
+
+ERR_pop_to_mark() returns 0 if there was no mark in the error stack, which
+implies that the stack became empty, otherwise 1.
+
+=head1 SEE ALSO
+
+L<err(3)|err(3)>
+
+=head1 HISTORY
+
+ERR_set_mark() and ERR_pop_to_mark() were added in OpenSSL 0.9.8.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/EVP_BytesToKey.pod b/deps/openssl/openssl/doc/crypto/EVP_BytesToKey.pod
new file mode 100644 (file)
index 0000000..d375c46
--- /dev/null
@@ -0,0 +1,67 @@
+=pod
+
+=head1 NAME
+
+EVP_BytesToKey - password based encryption routine
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ int EVP_BytesToKey(const EVP_CIPHER *type,const EVP_MD *md,
+                       const unsigned char *salt,
+                       const unsigned char *data, int datal, int count,
+                       unsigned char *key,unsigned char *iv);
+
+=head1 DESCRIPTION
+
+EVP_BytesToKey() derives a key and IV from various parameters. B<type> is
+the cipher to derive the key and IV for. B<md> is the message digest to use.
+The B<salt> paramter is used as a salt in the derivation: it should point to
+an 8 byte buffer or NULL if no salt is used. B<data> is a buffer containing
+B<datal> bytes which is used to derive the keying data. B<count> is the
+iteration count to use. The derived key and IV will be written to B<key>
+and B<iv> respectively.
+
+=head1 NOTES
+
+A typical application of this function is to derive keying material for an
+encryption algorithm from a password in the B<data> parameter.
+
+Increasing the B<count> parameter slows down the algorithm which makes it
+harder for an attacker to peform a brute force attack using a large number
+of candidate passwords.
+
+If the total key and IV length is less than the digest length and
+B<MD5> is used then the derivation algorithm is compatible with PKCS#5 v1.5
+otherwise a non standard extension is used to derive the extra data.
+
+Newer applications should use more standard algorithms such as PKCS#5
+v2.0 for key derivation.
+
+=head1 KEY DERIVATION ALGORITHM
+
+The key and IV is derived by concatenating D_1, D_2, etc until
+enough data is available for the key and IV. D_i is defined as:
+
+       D_i = HASH^count(D_(i-1) || data || salt)
+
+where || denotes concatentaion, D_0 is empty, HASH is the digest
+algorithm in use, HASH^1(data) is simply HASH(data), HASH^2(data)
+is HASH(HASH(data)) and so on.
+
+The initial bytes are used for the key and the subsequent bytes for
+the IV.
+
+=head1 RETURN VALUES
+
+EVP_BytesToKey() returns the size of the derived key in bytes.
+
+=head1 SEE ALSO
+
+L<evp(3)|evp(3)>, L<rand(3)|rand(3)>,
+L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>
+
+=head1 HISTORY
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/EVP_DigestInit.pod b/deps/openssl/openssl/doc/crypto/EVP_DigestInit.pod
new file mode 100644 (file)
index 0000000..5b477ac
--- /dev/null
@@ -0,0 +1,259 @@
+=pod
+
+=head1 NAME
+
+EVP_MD_CTX_init, EVP_MD_CTX_create, EVP_DigestInit_ex, EVP_DigestUpdate,
+EVP_DigestFinal_ex, EVP_MD_CTX_cleanup, EVP_MD_CTX_destroy, EVP_MAX_MD_SIZE,
+EVP_MD_CTX_copy_ex, EVP_MD_CTX_copy, EVP_MD_type, EVP_MD_pkey_type, EVP_MD_size,
+EVP_MD_block_size, EVP_MD_CTX_md, EVP_MD_CTX_size, EVP_MD_CTX_block_size, EVP_MD_CTX_type,
+EVP_md_null, EVP_md2, EVP_md5, EVP_sha, EVP_sha1, EVP_dss, EVP_dss1, EVP_mdc2,
+EVP_ripemd160, EVP_get_digestbyname, EVP_get_digestbynid, EVP_get_digestbyobj -
+EVP digest routines
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ void EVP_MD_CTX_init(EVP_MD_CTX *ctx);
+ EVP_MD_CTX *EVP_MD_CTX_create(void);
+
+ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
+ int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt);
+ int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md,
+        unsigned int *s);
+
+ int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx);
+ void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx);
+
+ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out,const EVP_MD_CTX *in);  
+
+ int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
+ int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md,
+        unsigned int *s);
+
+ int EVP_MD_CTX_copy(EVP_MD_CTX *out,EVP_MD_CTX *in);  
+
+ #define EVP_MAX_MD_SIZE (16+20) /* The SSLv3 md5+sha1 type */
+
+
+ #define EVP_MD_type(e)                        ((e)->type)
+ #define EVP_MD_pkey_type(e)           ((e)->pkey_type)
+ #define EVP_MD_size(e)                        ((e)->md_size)
+ #define EVP_MD_block_size(e)          ((e)->block_size)
+
+ #define EVP_MD_CTX_md(e)              (e)->digest)
+ #define EVP_MD_CTX_size(e)            EVP_MD_size((e)->digest)
+ #define EVP_MD_CTX_block_size(e)      EVP_MD_block_size((e)->digest)
+ #define EVP_MD_CTX_type(e)            EVP_MD_type((e)->digest)
+
+ const EVP_MD *EVP_md_null(void);
+ const EVP_MD *EVP_md2(void);
+ const EVP_MD *EVP_md5(void);
+ const EVP_MD *EVP_sha(void);
+ const EVP_MD *EVP_sha1(void);
+ const EVP_MD *EVP_dss(void);
+ const EVP_MD *EVP_dss1(void);
+ const EVP_MD *EVP_mdc2(void);
+ const EVP_MD *EVP_ripemd160(void);
+
+ const EVP_MD *EVP_get_digestbyname(const char *name);
+ #define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a))
+ #define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a))
+
+=head1 DESCRIPTION
+
+The EVP digest routines are a high level interface to message digests.
+
+EVP_MD_CTX_init() initializes digest context B<ctx>.
+
+EVP_MD_CTX_create() allocates, initializes and returns a digest context.
+
+EVP_DigestInit_ex() sets up digest context B<ctx> to use a digest
+B<type> from ENGINE B<impl>. B<ctx> must be initialized before calling this
+function. B<type> will typically be supplied by a functionsuch as EVP_sha1().
+If B<impl> is NULL then the default implementation of digest B<type> is used.
+
+EVP_DigestUpdate() hashes B<cnt> bytes of data at B<d> into the
+digest context B<ctx>. This function can be called several times on the
+same B<ctx> to hash additional data.
+
+EVP_DigestFinal_ex() retrieves the digest value from B<ctx> and places
+it in B<md>. If the B<s> parameter is not NULL then the number of
+bytes of data written (i.e. the length of the digest) will be written
+to the integer at B<s>, at most B<EVP_MAX_MD_SIZE> bytes will be written.
+After calling EVP_DigestFinal_ex() no additional calls to EVP_DigestUpdate()
+can be made, but EVP_DigestInit_ex() can be called to initialize a new
+digest operation.
+
+EVP_MD_CTX_cleanup() cleans up digest context B<ctx>, it should be called
+after a digest context is no longer needed.
+
+EVP_MD_CTX_destroy() cleans up digest context B<ctx> and frees up the
+space allocated to it, it should be called only on a context created
+using EVP_MD_CTX_create().
+
+EVP_MD_CTX_copy_ex() can be used to copy the message digest state from
+B<in> to B<out>. This is useful if large amounts of data are to be
+hashed which only differ in the last few bytes. B<out> must be initialized
+before calling this function.
+
+EVP_DigestInit() behaves in the same way as EVP_DigestInit_ex() except
+the passed context B<ctx> does not have to be initialized, and it always
+uses the default digest implementation.
+
+EVP_DigestFinal() is similar to EVP_DigestFinal_ex() except the digest
+context B<ctx> is automatically cleaned up.
+
+EVP_MD_CTX_copy() is similar to EVP_MD_CTX_copy_ex() except the destination
+B<out> does not have to be initialized.
+
+EVP_MD_size() and EVP_MD_CTX_size() return the size of the message digest
+when passed an B<EVP_MD> or an B<EVP_MD_CTX> structure, i.e. the size of the
+hash.
+
+EVP_MD_block_size() and EVP_MD_CTX_block_size() return the block size of the
+message digest when passed an B<EVP_MD> or an B<EVP_MD_CTX> structure.
+
+EVP_MD_type() and EVP_MD_CTX_type() return the NID of the OBJECT IDENTIFIER
+representing the given message digest when passed an B<EVP_MD> structure.
+For example EVP_MD_type(EVP_sha1()) returns B<NID_sha1>. This function is
+normally used when setting ASN1 OIDs.
+
+EVP_MD_CTX_md() returns the B<EVP_MD> structure corresponding to the passed
+B<EVP_MD_CTX>.
+
+EVP_MD_pkey_type() returns the NID of the public key signing algorithm associated
+with this digest. For example EVP_sha1() is associated with RSA so this will
+return B<NID_sha1WithRSAEncryption>. This "link" between digests and signature
+algorithms may not be retained in future versions of OpenSSL.
+
+EVP_md2(), EVP_md5(), EVP_sha(), EVP_sha1(), EVP_mdc2() and EVP_ripemd160()
+return B<EVP_MD> structures for the MD2, MD5, SHA, SHA1, MDC2 and RIPEMD160 digest
+algorithms respectively. The associated signature algorithm is RSA in each case.
+
+EVP_dss() and EVP_dss1() return B<EVP_MD> structures for SHA and SHA1 digest
+algorithms but using DSS (DSA) for the signature algorithm. Note: there is 
+no need to use these pseudo-digests in OpenSSL 1.0.0 and later, they are
+however retained for compatibility.
+
+EVP_md_null() is a "null" message digest that does nothing: i.e. the hash it
+returns is of zero length.
+
+EVP_get_digestbyname(), EVP_get_digestbynid() and EVP_get_digestbyobj()
+return an B<EVP_MD> structure when passed a digest name, a digest NID or
+an ASN1_OBJECT structure respectively. The digest table must be initialized
+using, for example, OpenSSL_add_all_digests() for these functions to work.
+
+=head1 RETURN VALUES
+
+EVP_DigestInit_ex(), EVP_DigestUpdate() and EVP_DigestFinal_ex() return 1 for
+success and 0 for failure.
+
+EVP_MD_CTX_copy_ex() returns 1 if successful or 0 for failure.
+
+EVP_MD_type(), EVP_MD_pkey_type() and EVP_MD_type() return the NID of the
+corresponding OBJECT IDENTIFIER or NID_undef if none exists.
+
+EVP_MD_size(), EVP_MD_block_size(), EVP_MD_CTX_size(e), EVP_MD_size(),
+EVP_MD_CTX_block_size()        and EVP_MD_block_size() return the digest or block
+size in bytes.
+
+EVP_md_null(), EVP_md2(), EVP_md5(), EVP_sha(), EVP_sha1(), EVP_dss(),
+EVP_dss1(), EVP_mdc2() and EVP_ripemd160() return pointers to the
+corresponding EVP_MD structures.
+
+EVP_get_digestbyname(), EVP_get_digestbynid() and EVP_get_digestbyobj()
+return either an B<EVP_MD> structure or NULL if an error occurs.
+
+=head1 NOTES
+
+The B<EVP> interface to message digests should almost always be used in
+preference to the low level interfaces. This is because the code then becomes
+transparent to the digest used and much more flexible.
+
+SHA1 is the digest of choice for new applications. The other digest algorithms
+are still in common use.
+
+For most applications the B<impl> parameter to EVP_DigestInit_ex() will be
+set to NULL to use the default digest implementation.
+
+The functions EVP_DigestInit(), EVP_DigestFinal() and EVP_MD_CTX_copy() are 
+obsolete but are retained to maintain compatibility with existing code. New
+applications should use EVP_DigestInit_ex(), EVP_DigestFinal_ex() and 
+EVP_MD_CTX_copy_ex() because they can efficiently reuse a digest context
+instead of initializing and cleaning it up on each call and allow non default
+implementations of digests to be specified.
+
+In OpenSSL 0.9.7 and later if digest contexts are not cleaned up after use
+memory leaks will occur. 
+
+=head1 EXAMPLE
+
+This example digests the data "Test Message\n" and "Hello World\n", using the
+digest name passed on the command line.
+
+ #include <stdio.h>
+ #include <openssl/evp.h>
+
+ main(int argc, char *argv[])
+ {
+ EVP_MD_CTX mdctx;
+ const EVP_MD *md;
+ char mess1[] = "Test Message\n";
+ char mess2[] = "Hello World\n";
+ unsigned char md_value[EVP_MAX_MD_SIZE];
+ int md_len, i;
+
+ OpenSSL_add_all_digests();
+
+ if(!argv[1]) {
+       printf("Usage: mdtest digestname\n");
+       exit(1);
+ }
+
+ md = EVP_get_digestbyname(argv[1]);
+
+ if(!md) {
+       printf("Unknown message digest %s\n", argv[1]);
+       exit(1);
+ }
+
+ EVP_MD_CTX_init(&mdctx);
+ EVP_DigestInit_ex(&mdctx, md, NULL);
+ EVP_DigestUpdate(&mdctx, mess1, strlen(mess1));
+ EVP_DigestUpdate(&mdctx, mess2, strlen(mess2));
+ EVP_DigestFinal_ex(&mdctx, md_value, &md_len);
+ EVP_MD_CTX_cleanup(&mdctx);
+
+ printf("Digest is: ");
+ for(i = 0; i < md_len; i++) printf("%02x", md_value[i]);
+ printf("\n");
+ }
+
+=head1 SEE ALSO
+
+L<evp(3)|evp(3)>, L<hmac(3)|hmac(3)>, L<md2(3)|md2(3)>,
+L<md5(3)|md5(3)>, L<mdc2(3)|mdc2(3)>, L<ripemd(3)|ripemd(3)>,
+L<sha(3)|sha(3)>, L<dgst(1)|dgst(1)>
+
+=head1 HISTORY
+
+EVP_DigestInit(), EVP_DigestUpdate() and EVP_DigestFinal() are
+available in all versions of SSLeay and OpenSSL.
+
+EVP_MD_CTX_init(), EVP_MD_CTX_create(), EVP_MD_CTX_copy_ex(),
+EVP_MD_CTX_cleanup(), EVP_MD_CTX_destroy(), EVP_DigestInit_ex()
+and EVP_DigestFinal_ex() were added in OpenSSL 0.9.7.
+
+EVP_md_null(), EVP_md2(), EVP_md5(), EVP_sha(), EVP_sha1(),
+EVP_dss(), EVP_dss1(), EVP_mdc2() and EVP_ripemd160() were
+changed to return truely const EVP_MD * in OpenSSL 0.9.7.
+
+The link between digests and signing algorithms was fixed in OpenSSL 1.0 and
+later, so now EVP_sha1() can be used with RSA and DSA, there is no need to
+use EVP_dss1() any more.
+
+OpenSSL 1.0 and later does not include the MD2 digest algorithm in the
+default configuration due to its security weaknesses.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/EVP_DigestSignInit.pod b/deps/openssl/openssl/doc/crypto/EVP_DigestSignInit.pod
new file mode 100644 (file)
index 0000000..37d960e
--- /dev/null
@@ -0,0 +1,87 @@
+=pod
+
+=head1 NAME
+
+EVP_DigestSignInit, EVP_DigestSignUpdate, EVP_DigestSignFinal - EVP signing functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ int EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
+                       const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey);
+ int EVP_DigestSignUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
+ int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen);
+
+=head1 DESCRIPTION
+
+The EVP signature routines are a high level interface to digital signatures.
+
+EVP_DigestSignInit() sets up signing context B<ctx> to use digest B<type> from
+ENGINE B<impl> and private key B<pkey>. B<ctx> must be initialized with
+EVP_MD_CTX_init() before calling this function. If B<pctx> is not NULL the
+EVP_PKEY_CTX of the signing operation will be written to B<*pctx>: this can
+be used to set alternative signing options.
+
+EVP_DigestSignUpdate() hashes B<cnt> bytes of data at B<d> into the
+signature context B<ctx>. This function can be called several times on the
+same B<ctx> to include additional data. This function is currently implemented
+usig a macro.
+
+EVP_DigestSignFinal() signs the data in B<ctx> places the signature in B<sig>.
+If B<sig> is B<NULL> then the maximum size of the output buffer is written to
+the B<siglen> parameter. If B<sig> is not B<NULL> then before the call the
+B<siglen> parameter should contain the length of the B<sig> buffer, if the
+call is successful the signature is written to B<sig> and the amount of data
+written to B<siglen>.
+
+=head1 RETURN VALUES
+
+EVP_DigestSignInit() EVP_DigestSignUpdate() and EVP_DigestSignaFinal() return
+1 for success and 0 or a negative value for failure. In particular a return
+value of -2 indicates the operation is not supported by the public key
+algorithm.
+
+The error codes can be obtained from L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 NOTES
+
+The B<EVP> interface to digital signatures should almost always be used in
+preference to the low level interfaces. This is because the code then becomes
+transparent to the algorithm used and much more flexible.
+
+In previous versions of OpenSSL there was a link between message digest types
+and public key algorithms. This meant that "clone" digests such as EVP_dss1()
+needed to be used to sign using SHA1 and DSA. This is no longer necessary and
+the use of clone digest is now discouraged.
+
+For some key types and parameters the random number generator must be seeded
+or the operation will fail. 
+
+The call to EVP_DigestSignFinal() internally finalizes a copy of the digest
+context. This means that calls to EVP_DigestSignUpdate() and
+EVP_DigestSignFinal() can be called later to digest and sign additional data.
+
+Since only a copy of the digest context is ever finalized the context must
+be cleaned up after use by calling EVP_MD_CTX_cleanup() or a memory leak
+will occur.
+
+The use of EVP_PKEY_size() with these functions is discouraged because some
+signature operations may have a signature length which depends on the
+parameters set. As a result EVP_PKEY_size() would have to return a value
+which indicates the maximum possible signature for any set of parameters.
+
+=head1 SEE ALSO
+
+L<EVP_DigestVerifyInit(3)|EVP_DigestVerifyInit(3)>,
+L<EVP_DigestInit(3)|EVP_DigestInit(3)>, L<err(3)|err(3)>,
+L<evp(3)|evp(3)>, L<hmac(3)|hmac(3)>, L<md2(3)|md2(3)>,
+L<md5(3)|md5(3)>, L<mdc2(3)|mdc2(3)>, L<ripemd(3)|ripemd(3)>,
+L<sha(3)|sha(3)>, L<dgst(1)|dgst(1)>
+
+=head1 HISTORY
+
+EVP_DigestSignInit(), EVP_DigestSignUpdate() and EVP_DigestSignFinal() 
+were first added to OpenSSL 1.0.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/EVP_DigestVerifyInit.pod b/deps/openssl/openssl/doc/crypto/EVP_DigestVerifyInit.pod
new file mode 100644 (file)
index 0000000..f224488
--- /dev/null
@@ -0,0 +1,82 @@
+=pod
+
+=head1 NAME
+
+EVP_DigestVerifyInit, EVP_DigestVerifyUpdate, EVP_DigestVerifyFinal - EVP signature verification functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
+                       const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey);
+ int EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
+ int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, unsigned char *sig, size_t siglen);
+
+=head1 DESCRIPTION
+
+The EVP signature routines are a high level interface to digital signatures.
+
+EVP_DigestVerifyInit() sets up verification context B<ctx> to use digest
+B<type> from ENGINE B<impl> and public key B<pkey>. B<ctx> must be initialized
+with EVP_MD_CTX_init() before calling this function. If B<pctx> is not NULL the
+EVP_PKEY_CTX of the verification operation will be written to B<*pctx>: this
+can be used to set alternative verification options.
+
+EVP_DigestVerifyUpdate() hashes B<cnt> bytes of data at B<d> into the
+verification context B<ctx>. This function can be called several times on the
+same B<ctx> to include additional data. This function is currently implemented
+using a macro.
+
+EVP_DigestVerifyFinal() verifies the data in B<ctx> against the signature in
+B<sig> of length B<siglen>.
+
+=head1 RETURN VALUES
+
+EVP_DigestVerifyInit() and EVP_DigestVerifyUpdate() return 1 for success and 0
+or a negative value for failure. In particular a return value of -2 indicates
+the operation is not supported by the public key algorithm.
+
+Unlike other functions the return value 0 from EVP_DigestVerifyFinal() only
+indicates that the signature did not not verify successfully (that is tbs did
+not match the original data or the signature was of invalid form) it is not an
+indication of a more serious error.
+
+The error codes can be obtained from L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 NOTES
+
+The B<EVP> interface to digital signatures should almost always be used in
+preference to the low level interfaces. This is because the code then becomes
+transparent to the algorithm used and much more flexible.
+
+In previous versions of OpenSSL there was a link between message digest types
+and public key algorithms. This meant that "clone" digests such as EVP_dss1()
+needed to be used to sign using SHA1 and DSA. This is no longer necessary and
+the use of clone digest is now discouraged.
+
+For some key types and parameters the random number generator must be seeded
+or the operation will fail. 
+
+The call to EVP_DigestVerifyFinal() internally finalizes a copy of the digest
+context. This means that calls to EVP_VerifyUpdate() and EVP_VerifyFinal() can
+be called later to digest and verify additional data.
+
+Since only a copy of the digest context is ever finalized the context must
+be cleaned up after use by calling EVP_MD_CTX_cleanup() or a memory leak
+will occur.
+
+=head1 SEE ALSO
+
+L<EVP_DigestSignInit(3)|EVP_DigestSignInit(3)>,
+L<EVP_DigestInit(3)|EVP_DigestInit(3)>, L<err(3)|err(3)>,
+L<evp(3)|evp(3)>, L<hmac(3)|hmac(3)>, L<md2(3)|md2(3)>,
+L<md5(3)|md5(3)>, L<mdc2(3)|mdc2(3)>, L<ripemd(3)|ripemd(3)>,
+L<sha(3)|sha(3)>, L<dgst(1)|dgst(1)>
+
+=head1 HISTORY
+
+EVP_DigestVerifyInit(), EVP_DigestVerifyUpdate() and EVP_DigestVerifyFinal() 
+were first added to OpenSSL 1.0.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/EVP_EncryptInit.pod b/deps/openssl/openssl/doc/crypto/EVP_EncryptInit.pod
new file mode 100644 (file)
index 0000000..8271d3d
--- /dev/null
@@ -0,0 +1,511 @@
+=pod
+
+=head1 NAME
+
+EVP_CIPHER_CTX_init, EVP_EncryptInit_ex, EVP_EncryptUpdate,
+EVP_EncryptFinal_ex, EVP_DecryptInit_ex, EVP_DecryptUpdate,
+EVP_DecryptFinal_ex, EVP_CipherInit_ex, EVP_CipherUpdate,
+EVP_CipherFinal_ex, EVP_CIPHER_CTX_set_key_length,
+EVP_CIPHER_CTX_ctrl, EVP_CIPHER_CTX_cleanup, EVP_EncryptInit,
+EVP_EncryptFinal, EVP_DecryptInit, EVP_DecryptFinal,
+EVP_CipherInit, EVP_CipherFinal, EVP_get_cipherbyname,
+EVP_get_cipherbynid, EVP_get_cipherbyobj, EVP_CIPHER_nid,
+EVP_CIPHER_block_size, EVP_CIPHER_key_length, EVP_CIPHER_iv_length,
+EVP_CIPHER_flags, EVP_CIPHER_mode, EVP_CIPHER_type, EVP_CIPHER_CTX_cipher,
+EVP_CIPHER_CTX_nid, EVP_CIPHER_CTX_block_size, EVP_CIPHER_CTX_key_length,
+EVP_CIPHER_CTX_iv_length, EVP_CIPHER_CTX_get_app_data,
+EVP_CIPHER_CTX_set_app_data, EVP_CIPHER_CTX_type, EVP_CIPHER_CTX_flags,
+EVP_CIPHER_CTX_mode, EVP_CIPHER_param_to_asn1, EVP_CIPHER_asn1_to_param,
+EVP_CIPHER_CTX_set_padding - EVP cipher routines
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a);
+
+ int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
+        ENGINE *impl, unsigned char *key, unsigned char *iv);
+ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
+         int *outl, unsigned char *in, int inl);
+ int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out,
+         int *outl);
+
+ int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
+        ENGINE *impl, unsigned char *key, unsigned char *iv);
+ int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
+         int *outl, unsigned char *in, int inl);
+ int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm,
+         int *outl);
+
+ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
+         ENGINE *impl, unsigned char *key, unsigned char *iv, int enc);
+ int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
+         int *outl, unsigned char *in, int inl);
+ int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm,
+         int *outl);
+
+ int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
+         unsigned char *key, unsigned char *iv);
+ int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out,
+         int *outl);
+
+ int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
+         unsigned char *key, unsigned char *iv);
+ int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm,
+         int *outl);
+
+ int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
+         unsigned char *key, unsigned char *iv, int enc);
+ int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm,
+         int *outl);
+
+ int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *x, int padding);
+ int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen);
+ int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);
+ int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a);
+
+ const EVP_CIPHER *EVP_get_cipherbyname(const char *name);
+ #define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a))
+ #define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a))
+
+ #define EVP_CIPHER_nid(e)             ((e)->nid)
+ #define EVP_CIPHER_block_size(e)      ((e)->block_size)
+ #define EVP_CIPHER_key_length(e)      ((e)->key_len)
+ #define EVP_CIPHER_iv_length(e)               ((e)->iv_len)
+ #define EVP_CIPHER_flags(e)           ((e)->flags)
+ #define EVP_CIPHER_mode(e)            ((e)->flags) & EVP_CIPH_MODE)
+ int EVP_CIPHER_type(const EVP_CIPHER *ctx);
+
+ #define EVP_CIPHER_CTX_cipher(e)      ((e)->cipher)
+ #define EVP_CIPHER_CTX_nid(e)         ((e)->cipher->nid)
+ #define EVP_CIPHER_CTX_block_size(e)  ((e)->cipher->block_size)
+ #define EVP_CIPHER_CTX_key_length(e)  ((e)->key_len)
+ #define EVP_CIPHER_CTX_iv_length(e)   ((e)->cipher->iv_len)
+ #define EVP_CIPHER_CTX_get_app_data(e)        ((e)->app_data)
+ #define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d))
+ #define EVP_CIPHER_CTX_type(c)         EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c))
+ #define EVP_CIPHER_CTX_flags(e)               ((e)->cipher->flags)
+ #define EVP_CIPHER_CTX_mode(e)                ((e)->cipher->flags & EVP_CIPH_MODE)
+
+ int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
+ int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
+
+=head1 DESCRIPTION
+
+The EVP cipher routines are a high level interface to certain
+symmetric ciphers.
+
+EVP_CIPHER_CTX_init() initializes cipher contex B<ctx>.
+
+EVP_EncryptInit_ex() sets up cipher context B<ctx> for encryption
+with cipher B<type> from ENGINE B<impl>. B<ctx> must be initialized
+before calling this function. B<type> is normally supplied
+by a function such as EVP_des_cbc(). If B<impl> is NULL then the
+default implementation is used. B<key> is the symmetric key to use
+and B<iv> is the IV to use (if necessary), the actual number of bytes
+used for the key and IV depends on the cipher. It is possible to set
+all parameters to NULL except B<type> in an initial call and supply
+the remaining parameters in subsequent calls, all of which have B<type>
+set to NULL. This is done when the default cipher parameters are not
+appropriate.
+
+EVP_EncryptUpdate() encrypts B<inl> bytes from the buffer B<in> and
+writes the encrypted version to B<out>. This function can be called
+multiple times to encrypt successive blocks of data. The amount
+of data written depends on the block alignment of the encrypted data:
+as a result the amount of data written may be anything from zero bytes
+to (inl + cipher_block_size - 1) so B<outl> should contain sufficient
+room. The actual number of bytes written is placed in B<outl>.
+
+If padding is enabled (the default) then EVP_EncryptFinal_ex() encrypts
+the "final" data, that is any data that remains in a partial block.
+It uses L<standard block padding|/NOTES> (aka PKCS padding). The encrypted
+final data is written to B<out> which should have sufficient space for
+one cipher block. The number of bytes written is placed in B<outl>. After
+this function is called the encryption operation is finished and no further
+calls to EVP_EncryptUpdate() should be made.
+
+If padding is disabled then EVP_EncryptFinal_ex() will not encrypt any more
+data and it will return an error if any data remains in a partial block:
+that is if the total data length is not a multiple of the block size. 
+
+EVP_DecryptInit_ex(), EVP_DecryptUpdate() and EVP_DecryptFinal_ex() are the
+corresponding decryption operations. EVP_DecryptFinal() will return an
+error code if padding is enabled and the final block is not correctly
+formatted. The parameters and restrictions are identical to the encryption
+operations except that if padding is enabled the decrypted data buffer B<out>
+passed to EVP_DecryptUpdate() should have sufficient room for
+(B<inl> + cipher_block_size) bytes unless the cipher block size is 1 in
+which case B<inl> bytes is sufficient.
+
+EVP_CipherInit_ex(), EVP_CipherUpdate() and EVP_CipherFinal_ex() are
+functions that can be used for decryption or encryption. The operation
+performed depends on the value of the B<enc> parameter. It should be set
+to 1 for encryption, 0 for decryption and -1 to leave the value unchanged
+(the actual value of 'enc' being supplied in a previous call).
+
+EVP_CIPHER_CTX_cleanup() clears all information from a cipher context
+and free up any allocated memory associate with it. It should be called
+after all operations using a cipher are complete so sensitive information
+does not remain in memory.
+
+EVP_EncryptInit(), EVP_DecryptInit() and EVP_CipherInit() behave in a
+similar way to EVP_EncryptInit_ex(), EVP_DecryptInit_ex and
+EVP_CipherInit_ex() except the B<ctx> paramter does not need to be
+initialized and they always use the default cipher implementation.
+
+EVP_EncryptFinal(), EVP_DecryptFinal() and EVP_CipherFinal() behave in a
+similar way to EVP_EncryptFinal_ex(), EVP_DecryptFinal_ex() and
+EVP_CipherFinal_ex() except B<ctx> is automatically cleaned up 
+after the call.
+
+EVP_get_cipherbyname(), EVP_get_cipherbynid() and EVP_get_cipherbyobj()
+return an EVP_CIPHER structure when passed a cipher name, a NID or an
+ASN1_OBJECT structure.
+
+EVP_CIPHER_nid() and EVP_CIPHER_CTX_nid() return the NID of a cipher when
+passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX> structure.  The actual NID
+value is an internal value which may not have a corresponding OBJECT
+IDENTIFIER.
+
+EVP_CIPHER_CTX_set_padding() enables or disables padding. By default
+encryption operations are padded using standard block padding and the
+padding is checked and removed when decrypting. If the B<pad> parameter
+is zero then no padding is performed, the total amount of data encrypted
+or decrypted must then be a multiple of the block size or an error will
+occur.
+
+EVP_CIPHER_key_length() and EVP_CIPHER_CTX_key_length() return the key
+length of a cipher when passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX>
+structure. The constant B<EVP_MAX_KEY_LENGTH> is the maximum key length
+for all ciphers. Note: although EVP_CIPHER_key_length() is fixed for a
+given cipher, the value of EVP_CIPHER_CTX_key_length() may be different
+for variable key length ciphers.
+
+EVP_CIPHER_CTX_set_key_length() sets the key length of the cipher ctx.
+If the cipher is a fixed length cipher then attempting to set the key
+length to any value other than the fixed value is an error.
+
+EVP_CIPHER_iv_length() and EVP_CIPHER_CTX_iv_length() return the IV
+length of a cipher when passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX>.
+It will return zero if the cipher does not use an IV.  The constant
+B<EVP_MAX_IV_LENGTH> is the maximum IV length for all ciphers.
+
+EVP_CIPHER_block_size() and EVP_CIPHER_CTX_block_size() return the block
+size of a cipher when passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX>
+structure. The constant B<EVP_MAX_IV_LENGTH> is also the maximum block
+length for all ciphers.
+
+EVP_CIPHER_type() and EVP_CIPHER_CTX_type() return the type of the passed
+cipher or context. This "type" is the actual NID of the cipher OBJECT
+IDENTIFIER as such it ignores the cipher parameters and 40 bit RC2 and
+128 bit RC2 have the same NID. If the cipher does not have an object
+identifier or does not have ASN1 support this function will return
+B<NID_undef>.
+
+EVP_CIPHER_CTX_cipher() returns the B<EVP_CIPHER> structure when passed
+an B<EVP_CIPHER_CTX> structure.
+
+EVP_CIPHER_mode() and EVP_CIPHER_CTX_mode() return the block cipher mode:
+EVP_CIPH_ECB_MODE, EVP_CIPH_CBC_MODE, EVP_CIPH_CFB_MODE or
+EVP_CIPH_OFB_MODE. If the cipher is a stream cipher then
+EVP_CIPH_STREAM_CIPHER is returned.
+
+EVP_CIPHER_param_to_asn1() sets the AlgorithmIdentifier "parameter" based
+on the passed cipher. This will typically include any parameters and an
+IV. The cipher IV (if any) must be set when this call is made. This call
+should be made before the cipher is actually "used" (before any
+EVP_EncryptUpdate(), EVP_DecryptUpdate() calls for example). This function
+may fail if the cipher does not have any ASN1 support.
+
+EVP_CIPHER_asn1_to_param() sets the cipher parameters based on an ASN1
+AlgorithmIdentifier "parameter". The precise effect depends on the cipher
+In the case of RC2, for example, it will set the IV and effective key length.
+This function should be called after the base cipher type is set but before
+the key is set. For example EVP_CipherInit() will be called with the IV and
+key set to NULL, EVP_CIPHER_asn1_to_param() will be called and finally
+EVP_CipherInit() again with all parameters except the key set to NULL. It is
+possible for this function to fail if the cipher does not have any ASN1 support
+or the parameters cannot be set (for example the RC2 effective key length
+is not supported.
+
+EVP_CIPHER_CTX_ctrl() allows various cipher specific parameters to be determined
+and set. Currently only the RC2 effective key length and the number of rounds of
+RC5 can be set.
+
+=head1 RETURN VALUES
+
+EVP_EncryptInit_ex(), EVP_EncryptUpdate() and EVP_EncryptFinal_ex()
+return 1 for success and 0 for failure.
+
+EVP_DecryptInit_ex() and EVP_DecryptUpdate() return 1 for success and 0 for failure.
+EVP_DecryptFinal_ex() returns 0 if the decrypt failed or 1 for success.
+
+EVP_CipherInit_ex() and EVP_CipherUpdate() return 1 for success and 0 for failure.
+EVP_CipherFinal_ex() returns 0 for a decryption failure or 1 for success.
+
+EVP_CIPHER_CTX_cleanup() returns 1 for success and 0 for failure.
+
+EVP_get_cipherbyname(), EVP_get_cipherbynid() and EVP_get_cipherbyobj()
+return an B<EVP_CIPHER> structure or NULL on error.
+
+EVP_CIPHER_nid() and EVP_CIPHER_CTX_nid() return a NID.
+
+EVP_CIPHER_block_size() and EVP_CIPHER_CTX_block_size() return the block
+size.
+
+EVP_CIPHER_key_length() and EVP_CIPHER_CTX_key_length() return the key
+length.
+
+EVP_CIPHER_CTX_set_padding() always returns 1.
+
+EVP_CIPHER_iv_length() and EVP_CIPHER_CTX_iv_length() return the IV
+length or zero if the cipher does not use an IV.
+
+EVP_CIPHER_type() and EVP_CIPHER_CTX_type() return the NID of the cipher's
+OBJECT IDENTIFIER or NID_undef if it has no defined OBJECT IDENTIFIER.
+
+EVP_CIPHER_CTX_cipher() returns an B<EVP_CIPHER> structure.
+
+EVP_CIPHER_param_to_asn1() and EVP_CIPHER_asn1_to_param() return 1 for 
+success or zero for failure.
+
+=head1 CIPHER LISTING
+
+All algorithms have a fixed key length unless otherwise stated.
+
+=over 4
+
+=item EVP_enc_null()
+
+Null cipher: does nothing.
+
+=item EVP_des_cbc(void), EVP_des_ecb(void), EVP_des_cfb(void), EVP_des_ofb(void)
+
+DES in CBC, ECB, CFB and OFB modes respectively. 
+
+=item EVP_des_ede_cbc(void), EVP_des_ede(), EVP_des_ede_ofb(void),  EVP_des_ede_cfb(void)
+
+Two key triple DES in CBC, ECB, CFB and OFB modes respectively.
+
+=item EVP_des_ede3_cbc(void), EVP_des_ede3(), EVP_des_ede3_ofb(void),  EVP_des_ede3_cfb(void)
+
+Three key triple DES in CBC, ECB, CFB and OFB modes respectively.
+
+=item EVP_desx_cbc(void)
+
+DESX algorithm in CBC mode.
+
+=item EVP_rc4(void)
+
+RC4 stream cipher. This is a variable key length cipher with default key length 128 bits.
+
+=item EVP_rc4_40(void)
+
+RC4 stream cipher with 40 bit key length. This is obsolete and new code should use EVP_rc4()
+and the EVP_CIPHER_CTX_set_key_length() function.
+
+=item EVP_idea_cbc() EVP_idea_ecb(void), EVP_idea_cfb(void), EVP_idea_ofb(void), EVP_idea_cbc(void)
+
+IDEA encryption algorithm in CBC, ECB, CFB and OFB modes respectively.
+
+=item EVP_rc2_cbc(void), EVP_rc2_ecb(void), EVP_rc2_cfb(void), EVP_rc2_ofb(void)
+
+RC2 encryption algorithm in CBC, ECB, CFB and OFB modes respectively. This is a variable key
+length cipher with an additional parameter called "effective key bits" or "effective key length".
+By default both are set to 128 bits.
+
+=item EVP_rc2_40_cbc(void), EVP_rc2_64_cbc(void)
+
+RC2 algorithm in CBC mode with a default key length and effective key length of 40 and 64 bits.
+These are obsolete and new code should use EVP_rc2_cbc(), EVP_CIPHER_CTX_set_key_length() and
+EVP_CIPHER_CTX_ctrl() to set the key length and effective key length.
+
+=item EVP_bf_cbc(void), EVP_bf_ecb(void), EVP_bf_cfb(void), EVP_bf_ofb(void);
+
+Blowfish encryption algorithm in CBC, ECB, CFB and OFB modes respectively. This is a variable key
+length cipher.
+
+=item EVP_cast5_cbc(void), EVP_cast5_ecb(void), EVP_cast5_cfb(void), EVP_cast5_ofb(void)
+
+CAST encryption algorithm in CBC, ECB, CFB and OFB modes respectively. This is a variable key
+length cipher.
+
+=item EVP_rc5_32_12_16_cbc(void), EVP_rc5_32_12_16_ecb(void), EVP_rc5_32_12_16_cfb(void), EVP_rc5_32_12_16_ofb(void)
+
+RC5 encryption algorithm in CBC, ECB, CFB and OFB modes respectively. This is a variable key length
+cipher with an additional "number of rounds" parameter. By default the key length is set to 128
+bits and 12 rounds.
+
+=back
+
+=head1 NOTES
+
+Where possible the B<EVP> interface to symmetric ciphers should be used in
+preference to the low level interfaces. This is because the code then becomes
+transparent to the cipher used and much more flexible.
+
+PKCS padding works by adding B<n> padding bytes of value B<n> to make the total 
+length of the encrypted data a multiple of the block size. Padding is always
+added so if the data is already a multiple of the block size B<n> will equal
+the block size. For example if the block size is 8 and 11 bytes are to be
+encrypted then 5 padding bytes of value 5 will be added.
+
+When decrypting the final block is checked to see if it has the correct form.
+
+Although the decryption operation can produce an error if padding is enabled,
+it is not a strong test that the input data or key is correct. A random block
+has better than 1 in 256 chance of being of the correct format and problems with
+the input data earlier on will not produce a final decrypt error.
+
+If padding is disabled then the decryption operation will always succeed if
+the total amount of data decrypted is a multiple of the block size.
+
+The functions EVP_EncryptInit(), EVP_EncryptFinal(), EVP_DecryptInit(),
+EVP_CipherInit() and EVP_CipherFinal() are obsolete but are retained for
+compatibility with existing code. New code should use EVP_EncryptInit_ex(),
+EVP_EncryptFinal_ex(), EVP_DecryptInit_ex(), EVP_DecryptFinal_ex(),
+EVP_CipherInit_ex() and EVP_CipherFinal_ex() because they can reuse an
+existing context without allocating and freeing it up on each call.
+
+=head1 BUGS
+
+For RC5 the number of rounds can currently only be set to 8, 12 or 16. This is
+a limitation of the current RC5 code rather than the EVP interface.
+
+EVP_MAX_KEY_LENGTH and EVP_MAX_IV_LENGTH only refer to the internal ciphers with
+default key lengths. If custom ciphers exceed these values the results are
+unpredictable. This is because it has become standard practice to define a 
+generic key as a fixed unsigned char array containing EVP_MAX_KEY_LENGTH bytes.
+
+The ASN1 code is incomplete (and sometimes inaccurate) it has only been tested
+for certain common S/MIME ciphers (RC2, DES, triple DES) in CBC mode.
+
+=head1 EXAMPLES
+
+Get the number of rounds used in RC5:
+
+ int nrounds;
+ EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GET_RC5_ROUNDS, 0, &nrounds);
+
+Get the RC2 effective key length:
+
+ int key_bits;
+ EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GET_RC2_KEY_BITS, 0, &key_bits);
+
+Set the number of rounds used in RC5:
+
+ int nrounds;
+ EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_RC5_ROUNDS, nrounds, NULL);
+
+Set the effective key length used in RC2:
+
+ int key_bits;
+ EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_RC2_KEY_BITS, key_bits, NULL);
+
+Encrypt a string using blowfish:
+
+ int do_crypt(char *outfile)
+       {
+       unsigned char outbuf[1024];
+       int outlen, tmplen;
+       /* Bogus key and IV: we'd normally set these from
+        * another source.
+        */
+       unsigned char key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
+       unsigned char iv[] = {1,2,3,4,5,6,7,8};
+       char intext[] = "Some Crypto Text";
+       EVP_CIPHER_CTX ctx;
+       FILE *out;
+       EVP_CIPHER_CTX_init(&ctx);
+       EVP_EncryptInit_ex(&ctx, EVP_bf_cbc(), NULL, key, iv);
+
+       if(!EVP_EncryptUpdate(&ctx, outbuf, &outlen, intext, strlen(intext)))
+               {
+               /* Error */
+               return 0;
+               }
+       /* Buffer passed to EVP_EncryptFinal() must be after data just
+        * encrypted to avoid overwriting it.
+        */
+       if(!EVP_EncryptFinal_ex(&ctx, outbuf + outlen, &tmplen))
+               {
+               /* Error */
+               return 0;
+               }
+       outlen += tmplen;
+       EVP_CIPHER_CTX_cleanup(&ctx);
+       /* Need binary mode for fopen because encrypted data is
+        * binary data. Also cannot use strlen() on it because
+         * it wont be null terminated and may contain embedded
+        * nulls.
+        */
+       out = fopen(outfile, "wb");
+       fwrite(outbuf, 1, outlen, out);
+       fclose(out);
+       return 1;
+       }
+
+The ciphertext from the above example can be decrypted using the B<openssl>
+utility with the command line:
+ S<openssl bf -in cipher.bin -K 000102030405060708090A0B0C0D0E0F -iv 0102030405060708 -d>
+
+General encryption, decryption function example using FILE I/O and RC2 with an
+80 bit key:
+
+ int do_crypt(FILE *in, FILE *out, int do_encrypt)
+       {
+       /* Allow enough space in output buffer for additional block */
+       inbuf[1024], outbuf[1024 + EVP_MAX_BLOCK_LENGTH];
+       int inlen, outlen;
+       /* Bogus key and IV: we'd normally set these from
+        * another source.
+        */
+       unsigned char key[] = "0123456789";
+       unsigned char iv[] = "12345678";
+       /* Don't set key or IV because we will modify the parameters */
+       EVP_CIPHER_CTX_init(&ctx);
+       EVP_CipherInit_ex(&ctx, EVP_rc2(), NULL, NULL, NULL, do_encrypt);
+       EVP_CIPHER_CTX_set_key_length(&ctx, 10);
+       /* We finished modifying parameters so now we can set key and IV */
+       EVP_CipherInit_ex(&ctx, NULL, NULL, key, iv, do_encrypt);
+
+       for(;;) 
+               {
+               inlen = fread(inbuf, 1, 1024, in);
+               if(inlen <= 0) break;
+               if(!EVP_CipherUpdate(&ctx, outbuf, &outlen, inbuf, inlen))
+                       {
+                       /* Error */
+                       EVP_CIPHER_CTX_cleanup(&ctx);
+                       return 0;
+                       }
+               fwrite(outbuf, 1, outlen, out);
+               }
+       if(!EVP_CipherFinal_ex(&ctx, outbuf, &outlen))
+               {
+               /* Error */
+               EVP_CIPHER_CTX_cleanup(&ctx);
+               return 0;
+               }
+       fwrite(outbuf, 1, outlen, out);
+
+       EVP_CIPHER_CTX_cleanup(&ctx);
+       return 1;
+       }
+
+
+=head1 SEE ALSO
+
+L<evp(3)|evp(3)>
+
+=head1 HISTORY
+
+EVP_CIPHER_CTX_init(), EVP_EncryptInit_ex(), EVP_EncryptFinal_ex(),
+EVP_DecryptInit_ex(), EVP_DecryptFinal_ex(), EVP_CipherInit_ex(),
+EVP_CipherFinal_ex() and EVP_CIPHER_CTX_set_padding() appeared in
+OpenSSL 0.9.7.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/EVP_OpenInit.pod b/deps/openssl/openssl/doc/crypto/EVP_OpenInit.pod
new file mode 100644 (file)
index 0000000..2e710da
--- /dev/null
@@ -0,0 +1,63 @@
+=pod
+
+=head1 NAME
+
+EVP_OpenInit, EVP_OpenUpdate, EVP_OpenFinal - EVP envelope decryption
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ int EVP_OpenInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type,unsigned char *ek,
+               int ekl,unsigned char *iv,EVP_PKEY *priv);
+ int EVP_OpenUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
+         int *outl, unsigned char *in, int inl);
+ int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out,
+         int *outl);
+
+=head1 DESCRIPTION
+
+The EVP envelope routines are a high level interface to envelope
+decryption. They decrypt a public key encrypted symmetric key and
+then decrypt data using it.
+
+EVP_OpenInit() initializes a cipher context B<ctx> for decryption
+with cipher B<type>. It decrypts the encrypted symmetric key of length
+B<ekl> bytes passed in the B<ek> parameter using the private key B<priv>.
+The IV is supplied in the B<iv> parameter.
+
+EVP_OpenUpdate() and EVP_OpenFinal() have exactly the same properties
+as the EVP_DecryptUpdate() and EVP_DecryptFinal() routines, as 
+documented on the L<EVP_EncryptInit(3)|EVP_EncryptInit(3)> manual
+page.
+
+=head1 NOTES
+
+It is possible to call EVP_OpenInit() twice in the same way as
+EVP_DecryptInit(). The first call should have B<priv> set to NULL
+and (after setting any cipher parameters) it should be called again
+with B<type> set to NULL.
+
+If the cipher passed in the B<type> parameter is a variable length
+cipher then the key length will be set to the value of the recovered
+key length. If the cipher is a fixed length cipher then the recovered
+key length must match the fixed cipher length.
+
+=head1 RETURN VALUES
+
+EVP_OpenInit() returns 0 on error or a non zero integer (actually the
+recovered secret key size) if successful.
+
+EVP_OpenUpdate() returns 1 for success or 0 for failure.
+
+EVP_OpenFinal() returns 0 if the decrypt failed or 1 for success.
+
+=head1 SEE ALSO
+
+L<evp(3)|evp(3)>, L<rand(3)|rand(3)>,
+L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>,
+L<EVP_SealInit(3)|EVP_SealInit(3)>
+
+=head1 HISTORY
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/EVP_PKEY_CTX_ctrl.pod b/deps/openssl/openssl/doc/crypto/EVP_PKEY_CTX_ctrl.pod
new file mode 100644 (file)
index 0000000..f2f4559
--- /dev/null
@@ -0,0 +1,128 @@
+=pod
+
+=head1 NAME
+
+EVP_PKEY_ctrl, EVP_PKEY_ctrl_str - algorithm specific control operations
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,
+                               int cmd, int p1, void *p2);
+ int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *type,
+                                               const char *value);
+
+ int EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid);
+
+ #include <openssl/rsa.h>
+
+ int EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
+
+ int EVP_PKEY_CTX_set_rsa_padding(EVP_PKEY_CTX *ctx, int pad);
+ int EVP_PKEY_CTX_set_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int len);
+ int EVP_PKEY_CTX_set_rsa_rsa_keygen_bits(EVP_PKEY_CTX *ctx, int mbits);
+ int EVP_PKEY_CTX_set_rsa_keygen_pubexp(EVP_PKEY_CTX *ctx, BIGNUM *pubexp);
+
+ #include <openssl/dsa.h>
+ int EVP_PKEY_CTX_set_dsa_paramgen_bits(EVP_PKEY_CTX *ctx, int nbits);
+
+ #include <openssl/dh.h>
+ int EVP_PKEY_CTX_set_dh_paramgen_prime_len(EVP_PKEY_CTX *ctx, int len);
+ int EVP_PKEY_CTX_set_dh_paramgen_generator(EVP_PKEY_CTX *ctx, int gen);
+
+ #include <openssl/ec.h>
+ int EVP_PKEY_CTX_set_ec_paramgen_curve_nid(EVP_PKEY_CTX *ctx, int nid);
+
+=head1 DESCRIPTION
+
+The function EVP_PKEY_CTX_ctrl() sends a control operation to the context
+B<ctx>. The key type used must match B<keytype> if it is not -1. The parameter
+B<optype> is a mask indicating which operations the control can be applied to.
+The control command is indicated in B<cmd> and any additional arguments in
+B<p1> and B<p2>.
+
+Applications will not normally call EVP_PKEY_CTX_ctrl() directly but will
+instead call one of the algorithm specific macros below.
+
+The function EVP_PKEY_ctrl_str() allows an application to send an algorithm
+specific control operation to a context B<ctx> in string form. This is
+intended to be used for options specified on the command line or in text
+files. The commands supported are documented in the openssl utility
+command line pages for the option B<-pkeyopt> which is supported by the
+B<pkeyutl>, B<genpkey> and B<req> commands.
+
+All the remaining "functions" are implemented as macros.
+
+The EVP_PKEY_CTX_set_signature_md() macro sets the message digest type used
+in a signature. It can be used with any public key algorithm supporting
+signature operations.
+
+The macro EVP_PKEY_CTX_set_rsa_padding() sets the RSA padding mode for B<ctx>.
+The B<pad> parameter can take the value RSA_PKCS1_PADDING for PKCS#1 padding,
+RSA_SSLV23_PADDING for SSLv23 padding, RSA_NO_PADDING for no padding,
+RSA_PKCS1_OAEP_PADDING for OAEP padding (encrypt and decrypt only),
+RSA_X931_PADDING for X9.31 padding (signature operations only) and 
+RSA_PKCS1_PSS_PADDING (sign and verify only).
+
+Two RSA padding modes behave differently if EVP_PKEY_CTX_set_signature_md()
+is used. If this macro is called for PKCS#1 padding the plaintext buffer is
+an actual digest value and is encapsulated in a DigestInfo structure according
+to PKCS#1 when signing and this structure is expected (and stripped off) when
+verifying. If this control is not used with RSA and PKCS#1 padding then the
+supplied data is used directly and not encapsulated. In the case of X9.31
+padding for RSA the algorithm identifier byte is added or checked and removed
+if this control is called. If it is not called then the first byte of the plaintext buffer is expected to be the algorithm identifier byte.
+
+The EVP_PKEY_CTX_set_rsa_pss_saltlen() macro sets the RSA PSS salt length to
+B<len> as its name implies it is only supported for PSS padding.  Two special
+values are supported: -1 sets the salt length to the digest length. When
+signing -2 sets the salt length to the maximum permissible value. When
+verifying -2 causes the salt length to be automatically determined based on the
+B<PSS> block structure. If this macro is not called a salt length value of -2
+is used by default.
+
+The EVP_PKEY_CTX_set_rsa_rsa_keygen_bits() macro sets the RSA key length for
+RSA key genration to B<bits>. If not specified 1024 bits is used.
+
+The EVP_PKEY_CTX_set_rsa_keygen_pubexp() macro sets the public exponent value
+for RSA key generation to B<pubexp> currently it should be an odd integer. The
+B<pubexp> pointer is used internally by this function so it should not be 
+modified or free after the call. If this macro is not called then 65537 is used.
+
+The macro EVP_PKEY_CTX_set_dsa_paramgen_bits() sets the number of bits used
+for DSA parameter generation to B<bits>. If not specified 1024 is used.
+
+The macro EVP_PKEY_CTX_set_dh_paramgen_prime_len() sets the length of the DH
+prime parameter B<p> for DH parameter generation. If this macro is not called
+then 1024 is used.
+
+The EVP_PKEY_CTX_set_dh_paramgen_generator() macro sets DH generator to B<gen>
+for DH parameter generation. If not specified 2 is used.
+
+The EVP_PKEY_CTX_set_ec_paramgen_curve_nid() sets the EC curve for EC parameter
+generation to B<nid>. For EC parameter generation this macro must be called
+or an error occurs because there is no default curve.
+
+=head1 RETURN VALUES
+
+EVP_PKEY_CTX_ctrl() and its macros return a positive value for success and 0
+or a negative value for failure. In particular a return value of -2
+indicates the operation is not supported by the public key algorithm.
+
+=head1 SEE ALSO
+
+L<EVP_PKEY_CTX_new(3)|EVP_PKEY_CTX_new(3)>,
+L<EVP_PKEY_encrypt(3)|EVP_PKEY_encrypt(3)>,
+L<EVP_PKEY_decrypt(3)|EVP_PKEY_decrypt(3)>,
+L<EVP_PKEY_sign(3)|EVP_PKEY_sign(3)>,
+L<EVP_PKEY_verify(3)|EVP_PKEY_verify(3)>,
+L<EVP_PKEY_verifyrecover(3)|EVP_PKEY_verifyrecover(3)>,
+L<EVP_PKEY_derive(3)|EVP_PKEY_derive(3)> 
+L<EVP_PKEY_keygen(3)|EVP_PKEY_keygen(3)> 
+
+=head1 HISTORY
+
+These functions were first added to OpenSSL 1.0.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/EVP_PKEY_CTX_new.pod b/deps/openssl/openssl/doc/crypto/EVP_PKEY_CTX_new.pod
new file mode 100644 (file)
index 0000000..a9af867
--- /dev/null
@@ -0,0 +1,52 @@
+=pod
+
+=head1 NAME
+
+EVP_PKEY_CTX_new, EVP_PKEY_CTX_new_id, EVP_PKEY_CTX_dup, EVP_PKEY_CTX_free - public key algorithm context functions.
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e);
+ EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e);
+ EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *ctx);
+ void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx);
+
+=head1 DESCRIPTION
+
+The EVP_PKEY_CTX_new() function allocates public key algorithm context using
+the algorithm specified in B<pkey> and ENGINE B<e>.
+
+The EVP_PKEY_CTX_new_id() function allocates public key algorithm context
+using the algorithm specified by B<id> and ENGINE B<e>. It is normally used
+when no B<EVP_PKEY> structure is associated with the operations, for example
+during parameter generation of key genration for some algorithms.
+
+EVP_PKEY_CTX_dup() duplicates the context B<ctx>.
+
+EVP_PKEY_CTX_free() frees up the context B<ctx>.
+
+=head1 NOTES
+
+The B<EVP_PKEY_CTX> structure is an opaque public key algorithm context used
+by the OpenSSL high level public key API. Contexts B<MUST NOT> be shared between
+threads: that is it is not permissible to use the same context simultaneously
+in two threads.
+
+=head1 RETURN VALUES
+
+EVP_PKEY_CTX_new(), EVP_PKEY_CTX_new_id(), EVP_PKEY_CTX_dup() returns either
+the newly allocated B<EVP_PKEY_CTX> structure of B<NULL> if an error occurred.
+
+EVP_PKEY_CTX_free() does not return a value.
+
+=head1 SEE ALSO
+
+L<EVP_PKEY_new(3)|EVP_PKEY_new(3)>
+
+=head1 HISTORY
+
+These functions were first added to OpenSSL 1.0.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/EVP_PKEY_cmp.pod b/deps/openssl/openssl/doc/crypto/EVP_PKEY_cmp.pod
new file mode 100644 (file)
index 0000000..4f8185e
--- /dev/null
@@ -0,0 +1,61 @@
+=pod
+
+=head1 NAME
+
+EVP_PKEY_copy_parameters, EVP_PKEY_missing_parameters, EVP_PKEY_cmp_parameters, EVP_PKEY_cmp - public key parameter and comparison functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey);
+ int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from);
+
+ int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b);
+ int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b);
+
+=head1 DESCRIPTION
+
+The function EVP_PKEY_missing_parameters() returns 1 if the public key
+parameters of B<pkey> are missing and 0 if they are present or the algorithm
+doesn't use parameters.
+
+The function EVP_PKEY_copy_parameters() copies the parameters from key
+B<from> to key B<to>.
+
+The funcion EVP_PKEY_cmp_parameters() compares the parameters of keys
+B<a> and B<b>.
+
+The funcion EVP_PKEY_cmp() compares the public key components and paramters
+(if present) of keys B<a> and B<b>.
+
+=head1 NOTES
+
+The main purpose of the functions EVP_PKEY_missing_parameters() and
+EVP_PKEY_copy_parameters() is to handle public keys in certificates where the
+parameters are sometimes omitted from a public key if they are inherited from
+the CA that signed it.
+
+Since OpenSSL private keys contain public key components too the function
+EVP_PKEY_cmp() can also be used to determine if a private key matches
+a public key.
+
+=head1 RETURN VALUES
+
+The function EVP_PKEY_missing_parameters() returns 1 if the public key
+parameters of B<pkey> are missing and 0 if they are present or the algorithm
+doesn't use parameters.
+
+These functions EVP_PKEY_copy_parameters() returns 1 for success and 0 for
+failure.
+
+The function EVP_PKEY_cmp_parameters() and EVP_PKEY_cmp() return 1 if the
+keys match, 0 if they don't match, -1 if the key types are different and
+-2 if the operation is not supported.
+
+=head1 SEE ALSO
+
+L<EVP_PKEY_CTX_new(3)|EVP_PKEY_CTX_new(3)>,
+L<EVP_PKEY_keygen(3)|EVP_PKEY_keygen(3)> 
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/EVP_PKEY_decrypt.pod b/deps/openssl/openssl/doc/crypto/EVP_PKEY_decrypt.pod
new file mode 100644 (file)
index 0000000..42b2a8c
--- /dev/null
@@ -0,0 +1,93 @@
+=pod
+
+=head1 NAME
+
+EVP_PKEY_decrypt_init, EVP_PKEY_decrypt - decrypt using a public key algorithm
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx);
+ int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx,
+                       unsigned char *out, size_t *outlen,
+                       const unsigned char *in, size_t inlen);
+
+=head1 DESCRIPTION
+
+The EVP_PKEY_decrypt_init() function initializes a public key algorithm
+context using key B<pkey> for a decryption operation.
+
+The EVP_PKEY_decrypt() function performs a public key decryption operation
+using B<ctx>. The data to be decrypted is specified using the B<in> and
+B<inlen> parameters. If B<out> is B<NULL> then the maximum size of the output
+buffer is written to the B<outlen> parameter. If B<out> is not B<NULL> then
+before the call the B<outlen> parameter should contain the length of the
+B<out> buffer, if the call is successful the decrypted data is written to
+B<out> and the amount of data written to B<outlen>.
+
+=head1 NOTES
+
+After the call to EVP_PKEY_decrypt_init() algorithm specific control
+operations can be performed to set any appropriate parameters for the
+operation.
+
+The function EVP_PKEY_decrypt() can be called more than once on the same
+context if several operations are performed using the same parameters.
+
+=head1 RETURN VALUES
+
+EVP_PKEY_decrypt_init() and EVP_PKEY_decrypt() return 1 for success and 0
+or a negative value for failure. In particular a return value of -2
+indicates the operation is not supported by the public key algorithm.
+
+=head1 EXAMPLE
+
+Decrypt data using OAEP (for RSA keys):
+
+ #include <openssl/evp.h>
+ #include <openssl/rsa.h>
+
+ EVP_PKEY_CTX *ctx;
+ unsigned char *out, *in;
+ size_t outlen, inlen; 
+ EVP_PKEY *key;
+ /* NB: assumes key in, inlen are already set up
+  * and that key is an RSA private key
+  */
+ ctx = EVP_PKEY_CTX_new(key);
+ if (!ctx)
+       /* Error occurred */
+ if (EVP_PKEY_decrypt_init(ctx) <= 0)
+       /* Error */
+ if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_OAEP_PADDING) <= 0)
+       /* Error */
+
+ /* Determine buffer length */
+ if (EVP_PKEY_decrypt(ctx, NULL, &outlen, in, inlen) <= 0)
+       /* Error */
+
+ out = OPENSSL_malloc(outlen);
+
+ if (!out)
+       /* malloc failure */
+ if (EVP_PKEY_decrypt(ctx, out, &outlen, in, inlen) <= 0)
+       /* Error */
+
+ /* Decrypted data is outlen bytes written to buffer out */
+
+=head1 SEE ALSO
+
+L<EVP_PKEY_CTX_new(3)|EVP_PKEY_CTX_new(3)>,
+L<EVP_PKEY_encrypt(3)|EVP_PKEY_encrypt(3)>,
+L<EVP_PKEY_sign(3)|EVP_PKEY_sign(3)>,
+L<EVP_PKEY_verify(3)|EVP_PKEY_verify(3)>,
+L<EVP_PKEY_verifyrecover(3)|EVP_PKEY_verifyrecover(3)>,
+L<EVP_PKEY_derive(3)|EVP_PKEY_derive(3)> 
+
+=head1 HISTORY
+
+These functions were first added to OpenSSL 1.0.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/EVP_PKEY_derive.pod b/deps/openssl/openssl/doc/crypto/EVP_PKEY_derive.pod
new file mode 100644 (file)
index 0000000..d9d6d76
--- /dev/null
@@ -0,0 +1,93 @@
+=pod
+
+=head1 NAME
+
+EVP_PKEY_derive_init, EVP_PKEY_derive_set_peer, EVP_PKEY_derive - derive public key algorithm shared secret.
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx);
+ int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer);
+ int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen);
+
+=head1 DESCRIPTION
+
+The EVP_PKEY_derive_init() function initializes a public key algorithm
+context using key B<pkey> for shared secret derivation.
+
+The EVP_PKEY_derive_set_peer() function sets the peer key: this will normally
+be a public key.
+
+The EVP_PKEY_derive() derives a shared secret using B<ctx>.
+If B<key> is B<NULL> then the maximum size of the output buffer is written to
+the B<keylen> parameter. If B<key> is not B<NULL> then before the call the
+B<keylen> parameter should contain the length of the B<key> buffer, if the call
+is successful the shared secret is written to B<key> and the amount of data
+written to B<keylen>.
+
+=head1 NOTES
+
+After the call to EVP_PKEY_derive_init() algorithm specific control
+operations can be performed to set any appropriate parameters for the
+operation.
+
+The function EVP_PKEY_derive() can be called more than once on the same
+context if several operations are performed using the same parameters.
+
+=head1 RETURN VALUES
+
+EVP_PKEY_derive_init() and EVP_PKEY_derive() return 1 for success and 0
+or a negative value for failure. In particular a return value of -2
+indicates the operation is not supported by the public key algorithm.
+
+=head1 EXAMPLE
+
+Derive shared secret (for example DH or EC keys):
+
+ #include <openssl/evp.h>
+ #include <openssl/rsa.h>
+
+ EVP_PKEY_CTX *ctx;
+ unsigned char *skey;
+ size_t skeylen;
+ EVP_PKEY *pkey, *peerkey;
+ /* NB: assumes pkey, peerkey have been already set up */
+
+ ctx = EVP_PKEY_CTX_new(pkey);
+ if (!ctx)
+       /* Error occurred */
+ if (EVP_PKEY_derive_init(ctx) <= 0)
+       /* Error */
+ if (EVP_PKEY_derive_set_peer(ctx, peerkey) <= 0)
+       /* Error */
+
+ /* Determine buffer length */
+ if (EVP_PKEY_derive(ctx, NULL, &skeylen) <= 0)
+       /* Error */
+
+ skey = OPENSSL_malloc(skeylen);
+
+ if (!skey)
+       /* malloc failure */
+ if (EVP_PKEY_derive(ctx, skey, &skeylen) <= 0)
+       /* Error */
+
+ /* Shared secret is skey bytes written to buffer skey */
+
+=head1 SEE ALSO
+
+L<EVP_PKEY_CTX_new(3)|EVP_PKEY_CTX_new(3)>,
+L<EVP_PKEY_encrypt(3)|EVP_PKEY_encrypt(3)>,
+L<EVP_PKEY_decrypt(3)|EVP_PKEY_decrypt(3)>,
+L<EVP_PKEY_sign(3)|EVP_PKEY_sign(3)>,
+L<EVP_PKEY_verify(3)|EVP_PKEY_verify(3)>,
+L<EVP_PKEY_verifyrecover(3)|EVP_PKEY_verifyrecover(3)>,
+
+=head1 HISTORY
+
+These functions were first added to OpenSSL 1.0.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/EVP_PKEY_encrypt.pod b/deps/openssl/openssl/doc/crypto/EVP_PKEY_encrypt.pod
new file mode 100644 (file)
index 0000000..91c9c5d
--- /dev/null
@@ -0,0 +1,93 @@
+=pod
+
+=head1 NAME
+
+EVP_PKEY_encrypt_init, EVP_PKEY_encrypt - encrypt using a public key algorithm
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx);
+ int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx,
+                       unsigned char *out, size_t *outlen,
+                       const unsigned char *in, size_t inlen);
+
+=head1 DESCRIPTION
+
+The EVP_PKEY_encrypt_init() function initializes a public key algorithm
+context using key B<pkey> for an encryption operation.
+
+The EVP_PKEY_encrypt() function performs a public key encryption operation
+using B<ctx>. The data to be encrypted is specified using the B<in> and
+B<inlen> parameters. If B<out> is B<NULL> then the maximum size of the output
+buffer is written to the B<outlen> parameter. If B<out> is not B<NULL> then
+before the call the B<outlen> parameter should contain the length of the
+B<out> buffer, if the call is successful the encrypted data is written to
+B<out> and the amount of data written to B<outlen>.
+
+=head1 NOTES
+
+After the call to EVP_PKEY_encrypt_init() algorithm specific control
+operations can be performed to set any appropriate parameters for the
+operation.
+
+The function EVP_PKEY_encrypt() can be called more than once on the same
+context if several operations are performed using the same parameters.
+
+=head1 RETURN VALUES
+
+EVP_PKEY_encrypt_init() and EVP_PKEY_encrypt() return 1 for success and 0
+or a negative value for failure. In particular a return value of -2
+indicates the operation is not supported by the public key algorithm.
+
+=head1 EXAMPLE
+
+Encrypt data using OAEP (for RSA keys):
+
+ #include <openssl/evp.h>
+ #include <openssl/rsa.h>
+
+ EVP_PKEY_CTX *ctx;
+ unsigned char *out, *in;
+ size_t outlen, inlen; 
+ EVP_PKEY *key;
+ /* NB: assumes key in, inlen are already set up
+  * and that key is an RSA public key
+  */
+ ctx = EVP_PKEY_CTX_new(key);
+ if (!ctx)
+       /* Error occurred */
+ if (EVP_PKEY_encrypt_init(ctx) <= 0)
+       /* Error */
+ if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_OAEP_PADDING) <= 0)
+       /* Error */
+
+ /* Determine buffer length */
+ if (EVP_PKEY_encrypt(ctx, NULL, &outlen, in, inlen) <= 0)
+       /* Error */
+
+ out = OPENSSL_malloc(outlen);
+
+ if (!out)
+       /* malloc failure */
+ if (EVP_PKEY_encrypt(ctx, out, &outlen, in, inlen) <= 0)
+       /* Error */
+
+ /* Encrypted data is outlen bytes written to buffer out */
+
+=head1 SEE ALSO
+
+L<EVP_PKEY_CTX_new(3)|EVP_PKEY_CTX_new(3)>,
+L<EVP_PKEY_decrypt(3)|EVP_PKEY_decrypt(3)>,
+L<EVP_PKEY_sign(3)|EVP_PKEY_sign(3)>,
+L<EVP_PKEY_verify(3)|EVP_PKEY_verify(3)>,
+L<EVP_PKEY_verifyrecover(3)|EVP_PKEY_verifyrecover(3)>,
+L<EVP_PKEY_derive(3)|EVP_PKEY_derive(3)> 
+
+=head1 HISTORY
+
+These functions were first added to OpenSSL 1.0.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/EVP_PKEY_get_default_digest.pod b/deps/openssl/openssl/doc/crypto/EVP_PKEY_get_default_digest.pod
new file mode 100644 (file)
index 0000000..1a9c795
--- /dev/null
@@ -0,0 +1,41 @@
+=pod
+
+=head1 NAME
+
+EVP_PKEY_get_default_digest_nid - get default signature digest
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+ int EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid);
+
+=head1 DESCRIPTION
+
+The EVP_PKEY_get_default_digest_nid() function sets B<pnid> to the default
+message digest NID for the public key signature operations associated with key
+B<pkey>.
+
+=head1 NOTES
+
+For all current standard OpenSSL public key algorithms SHA1 is returned.
+
+=head1 RETURN VALUES
+
+The EVP_PKEY_get_default_digest_nid() function returns 1 if the message digest
+is advisory (that is other digests can be used) and 2 if it is mandatory (other
+digests can not be used).  It returns 0 or a negative value for failure. In
+particular a return value of -2 indicates the operation is not supported by the
+public key algorithm.
+
+=head1 SEE ALSO
+
+L<EVP_PKEY_CTX_new(3)|EVP_PKEY_CTX_new(3)>,
+L<EVP_PKEY_sign(3)|EVP_PKEY_sign(3)>,
+L<EVP_PKEY_verify(3)|EVP_PKEY_verify(3)>,
+L<EVP_PKEY_verifyrecover(3)|EVP_PKEY_verifyrecover(3)>,
+
+=head1 HISTORY
+
+This function was first added to OpenSSL 1.0.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/EVP_PKEY_keygen.pod b/deps/openssl/openssl/doc/crypto/EVP_PKEY_keygen.pod
new file mode 100644 (file)
index 0000000..37c6fe9
--- /dev/null
@@ -0,0 +1,161 @@
+=pod
+
+=head1 NAME
+
+EVP_PKEY_keygen_init, EVP_PKEY_keygen, EVP_PKEY_paramgen_init, EVP_PKEY_paramgen, EVP_PKEY_CTX_set_cb, EVP_PKEY_CTX_get_cb, EVP_PKEY_CTX_get_keygen_info, EVP_PKEVP_PKEY_CTX_set_app_data, EVP_PKEY_CTX_get_app_data - key and parameter generation functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ int EVP_PKEY_keygen_init(EVP_PKEY_CTX *ctx);
+ int EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey);
+ int EVP_PKEY_paramgen_init(EVP_PKEY_CTX *ctx);
+ int EVP_PKEY_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey);
+
+ typedef int EVP_PKEY_gen_cb(EVP_PKEY_CTX *ctx);
+
+ void EVP_PKEY_CTX_set_cb(EVP_PKEY_CTX *ctx, EVP_PKEY_gen_cb *cb);
+ EVP_PKEY_gen_cb *EVP_PKEY_CTX_get_cb(EVP_PKEY_CTX *ctx);
+
+ int EVP_PKEY_CTX_get_keygen_info(EVP_PKEY_CTX *ctx, int idx);
+
+ void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data);
+ void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx);
+
+=head1 DESCRIPTION
+
+The EVP_PKEY_keygen_init() function initializes a public key algorithm
+context using key B<pkey> for a key genration operation.
+
+The EVP_PKEY_keygen() function performs a key generation operation, the 
+generated key is written to B<ppkey>.
+
+The functions EVP_PKEY_paramgen_init() and EVP_PKEY_paramgen() are similar
+except parameters are generated.
+
+The function EVP_PKEY_set_cb() sets the key or parameter generation callback
+to B<cb>. The function EVP_PKEY_CTX_get_cb() returns the key or parameter
+generation callback.
+
+The function EVP_PKEY_CTX_get_keygen_info() returns parameters associated
+with the generation operation. If B<idx> is -1 the total number of
+parameters available is returned. Any non negative value returns the value of
+that parameter. EVP_PKEY_CTX_gen_keygen_info() with a non-negative value for
+B<idx> should only be called within the generation callback.
+
+If the callback returns 0 then the key genration operation is aborted and an
+error occurs. This might occur during a time consuming operation where
+a user clicks on a "cancel" button.
+
+The functions EVP_PKEY_CTX_set_app_data() and EVP_PKEY_CTX_get_app_data() set
+and retrieve an opaque pointer. This can be used to set some application
+defined value which can be retrieved in the callback: for example a handle
+which is used to update a "progress dialog".
+
+=head1 NOTES
+
+After the call to EVP_PKEY_keygen_init() or EVP_PKEY_paramgen_init() algorithm
+specific control operations can be performed to set any appropriate parameters
+for the operation.
+
+The functions EVP_PKEY_keygen() and EVP_PKEY_paramgen() can be called more than
+once on the same context if several operations are performed using the same
+parameters.
+
+The meaning of the parameters passed to the callback will depend on the
+algorithm and the specifiic implementation of the algorithm. Some might not
+give any useful information at all during key or parameter generation. Others
+might not even call the callback.
+
+The operation performed by key or parameter generation depends on the algorithm
+used. In some cases (e.g. EC with a supplied named curve) the "generation"
+option merely sets the appropriate fields in an EVP_PKEY structure.
+
+In OpenSSL an EVP_PKEY structure containing a private key also contains the
+public key components and parameters (if any). An OpenSSL private key is
+equivalent to what some libraries call a "key pair". A private key can be used
+in functions which require the use of a public key or parameters.
+
+=head1 RETURN VALUES
+
+EVP_PKEY_keygen_init(), EVP_PKEY_paramgen_init(), EVP_PKEY_keygen() and
+EVP_PKEY_paramgen() return 1 for success and 0 or a negative value for failure.
+In particular a return value of -2 indicates the operation is not supported by
+the public key algorithm.
+
+=head1 EXAMPLES
+
+Generate a 2048 bit RSA key:
+
+ #include <openssl/evp.h>
+ #include <openssl/rsa.h>
+
+ EVP_PKEY_CTX *ctx;
+ EVP_PKEY *pkey = NULL;
+ ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL);
+ if (!ctx)
+       /* Error occurred */
+ if (EVP_PKEY_keygen_init(ctx) <= 0)
+       /* Error */
+ if (EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, 2048) <= 0)
+       /* Error */
+
+ /* Generate key */
+ if (EVP_PKEY_keygen(ctx, &pkey) <= 0)
+       /* Error */
+
+Generate a key from a set of parameters:
+
+ #include <openssl/evp.h>
+ #include <openssl/rsa.h>
+
+ EVP_PKEY_CTX *ctx;
+ EVP_PKEY *pkey = NULL, *param;
+ /* Assumed param is set up already */
+ ctx = EVP_PKEY_CTX_new(param);
+ if (!ctx)
+       /* Error occurred */
+ if (EVP_PKEY_keygen_init(ctx) <= 0)
+       /* Error */
+
+ /* Generate key */
+ if (EVP_PKEY_keygen(ctx, &pkey) <= 0)
+       /* Error */
+
+Example of generation callback for OpenSSL public key implementations:
+
+ /* Application data is a BIO to output status to */
+
+ EVP_PKEY_CTX_set_app_data(ctx, status_bio);
+
+ static int genpkey_cb(EVP_PKEY_CTX *ctx)
+       {
+       char c='*';
+       BIO *b = EVP_PKEY_CTX_get_app_data(ctx);
+       int p;
+       p = EVP_PKEY_CTX_get_keygen_info(ctx, 0);
+       if (p == 0) c='.';
+       if (p == 1) c='+';
+       if (p == 2) c='*';
+       if (p == 3) c='\n';
+       BIO_write(b,&c,1);
+       (void)BIO_flush(b);
+       return 1;
+       }
+
+=head1 SEE ALSO
+
+L<EVP_PKEY_CTX_new(3)|EVP_PKEY_CTX_new(3)>,
+L<EVP_PKEY_encrypt(3)|EVP_PKEY_encrypt(3)>,
+L<EVP_PKEY_decrypt(3)|EVP_PKEY_decrypt(3)>,
+L<EVP_PKEY_sign(3)|EVP_PKEY_sign(3)>,
+L<EVP_PKEY_verify(3)|EVP_PKEY_verify(3)>,
+L<EVP_PKEY_verifyrecover(3)|EVP_PKEY_verifyrecover(3)>,
+L<EVP_PKEY_derive(3)|EVP_PKEY_derive(3)> 
+
+=head1 HISTORY
+
+These functions were first added to OpenSSL 1.0.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/EVP_PKEY_new.pod b/deps/openssl/openssl/doc/crypto/EVP_PKEY_new.pod
new file mode 100644 (file)
index 0000000..10687e4
--- /dev/null
@@ -0,0 +1,47 @@
+=pod
+
+=head1 NAME
+
+EVP_PKEY_new, EVP_PKEY_free - private key allocation functions.
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ EVP_PKEY *EVP_PKEY_new(void);
+ void EVP_PKEY_free(EVP_PKEY *key);
+
+
+=head1 DESCRIPTION
+
+The EVP_PKEY_new() function allocates an empty B<EVP_PKEY> 
+structure which is used by OpenSSL to store private keys.
+
+EVP_PKEY_free() frees up the private key B<key>.
+
+=head1 NOTES
+
+The B<EVP_PKEY> structure is used by various OpenSSL functions
+which require a general private key without reference to any
+particular algorithm.
+
+The structure returned by EVP_PKEY_new() is empty. To add a
+private key to this empty structure the functions described in
+L<EVP_PKEY_set1_RSA(3)|EVP_PKEY_set1_RSA(3)> should be used.
+
+=head1 RETURN VALUES
+
+EVP_PKEY_new() returns either the newly allocated B<EVP_PKEY>
+structure of B<NULL> if an error occurred.
+
+EVP_PKEY_free() does not return a value.
+
+=head1 SEE ALSO
+
+L<EVP_PKEY_set1_RSA(3)|EVP_PKEY_set1_RSA(3)>
+
+=head1 HISTORY
+
+TBA
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/EVP_PKEY_print_private.pod b/deps/openssl/openssl/doc/crypto/EVP_PKEY_print_private.pod
new file mode 100644 (file)
index 0000000..ce9d70d
--- /dev/null
@@ -0,0 +1,53 @@
+=pod
+
+=head1 NAME
+
+EVP_PKEY_print_public, EVP_PKEY_print_private, EVP_PKEY_print_params - public key algorithm printing routines.
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ int EVP_PKEY_print_public(BIO *out, const EVP_PKEY *pkey,
+                               int indent, ASN1_PCTX *pctx);
+ int EVP_PKEY_print_private(BIO *out, const EVP_PKEY *pkey,
+                               int indent, ASN1_PCTX *pctx);
+ int EVP_PKEY_print_params(BIO *out, const EVP_PKEY *pkey,
+                               int indent, ASN1_PCTX *pctx);
+
+=head1 DESCRIPTION
+
+The functions EVP_PKEY_print_public(), EVP_PKEY_print_private() and
+EVP_PKEY_print_params() print out the public, private or parameter components
+of key B<pkey> respectively. The key is sent to BIO B<out> in human readable
+form. The parameter B<indent> indicated how far the printout should be indented.
+
+The B<pctx> parameter allows the print output to be finely tuned by using
+ASN1 printing options. If B<pctx> is set to NULL then default values will
+be used.
+
+=head1 NOTES
+
+Currently no public key algorithms include any options in the B<pctx> parameter 
+parameter.
+
+If the key does not include all the components indicated by the function then
+only those contained in the key will be printed. For example passing a public
+key to EVP_PKEY_print_private() will only print the public components.
+
+=head1 RETURN VALUES
+
+These functions all return 1 for success and 0 or a negative value for failure.
+In particular a return value of -2 indicates the operation is not supported by
+the public key algorithm.
+
+=head1 SEE ALSO
+
+L<EVP_PKEY_CTX_new(3)|EVP_PKEY_CTX_new(3)>,
+L<EVP_PKEY_keygen(3)|EVP_PKEY_keygen(3)> 
+
+=head1 HISTORY
+
+These functions were first added to OpenSSL 1.0.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/EVP_PKEY_set1_RSA.pod b/deps/openssl/openssl/doc/crypto/EVP_PKEY_set1_RSA.pod
new file mode 100644 (file)
index 0000000..2db692e
--- /dev/null
@@ -0,0 +1,80 @@
+=pod
+
+=head1 NAME
+
+EVP_PKEY_set1_RSA, EVP_PKEY_set1_DSA, EVP_PKEY_set1_DH, EVP_PKEY_set1_EC_KEY,
+EVP_PKEY_get1_RSA, EVP_PKEY_get1_DSA, EVP_PKEY_get1_DH, EVP_PKEY_get1_EC_KEY,
+EVP_PKEY_assign_RSA, EVP_PKEY_assign_DSA, EVP_PKEY_assign_DH, EVP_PKEY_assign_EC_KEY,
+EVP_PKEY_type - EVP_PKEY assignment functions.
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ int EVP_PKEY_set1_RSA(EVP_PKEY *pkey,RSA *key);
+ int EVP_PKEY_set1_DSA(EVP_PKEY *pkey,DSA *key);
+ int EVP_PKEY_set1_DH(EVP_PKEY *pkey,DH *key);
+ int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey,EC_KEY *key);
+
+ RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey);
+ DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey);
+ DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey);
+ EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey);
+
+ int EVP_PKEY_assign_RSA(EVP_PKEY *pkey,RSA *key);
+ int EVP_PKEY_assign_DSA(EVP_PKEY *pkey,DSA *key);
+ int EVP_PKEY_assign_DH(EVP_PKEY *pkey,DH *key);
+ int EVP_PKEY_assign_EC_KEY(EVP_PKEY *pkey,EC_KEY *key);
+
+ int EVP_PKEY_type(int type);
+
+=head1 DESCRIPTION
+
+EVP_PKEY_set1_RSA(), EVP_PKEY_set1_DSA(), EVP_PKEY_set1_DH() and
+EVP_PKEY_set1_EC_KEY() set the key referenced by B<pkey> to B<key>.
+
+EVP_PKEY_get1_RSA(), EVP_PKEY_get1_DSA(), EVP_PKEY_get1_DH() and
+EVP_PKEY_get1_EC_KEY() return the referenced key in B<pkey> or
+B<NULL> if the key is not of the correct type.
+
+EVP_PKEY_assign_RSA() EVP_PKEY_assign_DSA(), EVP_PKEY_assign_DH()
+and EVP_PKEY_assign_EC_KEY() also set the referenced key to B<key>
+however these use the supplied B<key> internally and so B<key>
+will be freed when the parent B<pkey> is freed.
+
+EVP_PKEY_type() returns the type of key corresponding to the value
+B<type>. The type of a key can be obtained with
+EVP_PKEY_type(pkey->type). The return value will be EVP_PKEY_RSA,
+EVP_PKEY_DSA, EVP_PKEY_DH or EVP_PKEY_EC for the corresponding
+key types or NID_undef if the key type is unassigned.
+
+=head1 NOTES
+
+In accordance with the OpenSSL naming convention the key obtained
+from or assigned to the B<pkey> using the B<1> functions must be
+freed as well as B<pkey>.
+
+EVP_PKEY_assign_RSA() EVP_PKEY_assign_DSA(), EVP_PKEY_assign_DH()
+EVP_PKEY_assign_EC_KEY() are implemented as macros.
+
+=head1 RETURN VALUES
+
+EVP_PKEY_set1_RSA(), EVP_PKEY_set1_DSA(), EVP_PKEY_set1_DH() and
+EVP_PKEY_set1_EC_KEY() return 1 for success or 0 for failure.
+
+EVP_PKEY_get1_RSA(), EVP_PKEY_get1_DSA(), EVP_PKEY_get1_DH() and
+EVP_PKEY_get1_EC_KEY() return the referenced key or B<NULL> if 
+an error occurred.
+
+EVP_PKEY_assign_RSA() EVP_PKEY_assign_DSA(), EVP_PKEY_assign_DH()
+and EVP_PKEY_assign_EC_KEY() return 1 for success and 0 for failure.
+
+=head1 SEE ALSO
+
+L<EVP_PKEY_new(3)|EVP_PKEY_new(3)>
+
+=head1 HISTORY
+
+TBA
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/EVP_PKEY_sign.pod b/deps/openssl/openssl/doc/crypto/EVP_PKEY_sign.pod
new file mode 100644 (file)
index 0000000..2fb52c3
--- /dev/null
@@ -0,0 +1,96 @@
+=pod
+
+=head1 NAME
+
+EVP_PKEY_sign_init, EVP_PKEY_sign - sign using a public key algorithm
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx);
+ int EVP_PKEY_sign(EVP_PKEY_CTX *ctx,
+                       unsigned char *sig, size_t *siglen,
+                       const unsigned char *tbs, size_t tbslen);
+
+=head1 DESCRIPTION
+
+The EVP_PKEY_sign_init() function initializes a public key algorithm
+context using key B<pkey> for a signing operation.
+
+The EVP_PKEY_sign() function performs a public key signing operation
+using B<ctx>. The data to be signed is specified using the B<tbs> and
+B<tbslen> parameters. If B<sig> is B<NULL> then the maximum size of the output
+buffer is written to the B<siglen> parameter. If B<sig> is not B<NULL> then
+before the call the B<siglen> parameter should contain the length of the
+B<sig> buffer, if the call is successful the signature is written to
+B<sig> and the amount of data written to B<siglen>.
+
+=head1 NOTES
+
+After the call to EVP_PKEY_sign_init() algorithm specific control
+operations can be performed to set any appropriate parameters for the
+operation.
+
+The function EVP_PKEY_sign() can be called more than once on the same
+context if several operations are performed using the same parameters.
+
+=head1 RETURN VALUES
+
+EVP_PKEY_sign_init() and EVP_PKEY_sign() return 1 for success and 0
+or a negative value for failure. In particular a return value of -2
+indicates the operation is not supported by the public key algorithm.
+
+=head1 EXAMPLE
+
+Sign data using RSA with PKCS#1 padding and SHA256 digest:
+
+ #include <openssl/evp.h>
+ #include <openssl/rsa.h>
+
+ EVP_PKEY_CTX *ctx;
+ unsigned char *md, *sig;
+ size_t mdlen, siglen; 
+ EVP_PKEY *signing_key;
+ /* NB: assumes signing_key, md and mdlen are already set up
+  * and that signing_key is an RSA private key
+  */
+ ctx = EVP_PKEY_CTX_new(signing_key);
+ if (!ctx)
+       /* Error occurred */
+ if (EVP_PKEY_sign_init(ctx) <= 0)
+       /* Error */
+ if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0)
+       /* Error */
+ if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0)
+       /* Error */
+
+ /* Determine buffer length */
+ if (EVP_PKEY_sign(ctx, NULL, &siglen, md, mdlen) <= 0)
+       /* Error */
+
+ sig = OPENSSL_malloc(siglen);
+
+ if (!sig)
+       /* malloc failure */
+ if (EVP_PKEY_sign(ctx, sig, &siglen, md, mdlen) <= 0)
+       /* Error */
+
+ /* Signature is siglen bytes written to buffer sig */
+
+
+=head1 SEE ALSO
+
+L<EVP_PKEY_CTX_new(3)|EVP_PKEY_CTX_new(3)>,
+L<EVP_PKEY_encrypt(3)|EVP_PKEY_encrypt(3)>,
+L<EVP_PKEY_decrypt(3)|EVP_PKEY_decrypt(3)>,
+L<EVP_PKEY_verify(3)|EVP_PKEY_verify(3)>,
+L<EVP_PKEY_verifyrecover(3)|EVP_PKEY_verifyrecover(3)>,
+L<EVP_PKEY_derive(3)|EVP_PKEY_derive(3)> 
+
+=head1 HISTORY
+
+These functions were first added to OpenSSL 1.0.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/EVP_PKEY_verify.pod b/deps/openssl/openssl/doc/crypto/EVP_PKEY_verify.pod
new file mode 100644 (file)
index 0000000..f93e5fc
--- /dev/null
@@ -0,0 +1,91 @@
+=pod
+
+=head1 NAME
+
+EVP_PKEY_verify_init, EVP_PKEY_verify - signature verification using a public key algorithm
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ int EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx);
+ int EVP_PKEY_verify(EVP_PKEY_CTX *ctx,
+                       const unsigned char *sig, size_t siglen,
+                       const unsigned char *tbs, size_t tbslen);
+
+=head1 DESCRIPTION
+
+The EVP_PKEY_verify_init() function initializes a public key algorithm
+context using key B<pkey> for a signature verification operation.
+
+The EVP_PKEY_verify() function performs a public key verification operation
+using B<ctx>. The signature is specified using the B<sig> and
+B<siglen> parameters. The verified data (i.e. the data believed originally
+signed) is specified using the B<tbs> and B<tbslen> parameters.
+
+=head1 NOTES
+
+After the call to EVP_PKEY_verify_init() algorithm specific control
+operations can be performed to set any appropriate parameters for the
+operation.
+
+The function EVP_PKEY_verify() can be called more than once on the same
+context if several operations are performed using the same parameters.
+
+=head1 RETURN VALUES
+
+EVP_PKEY_verify_init() and EVP_PKEY_verify() return 1 if the verification was
+successful and 0 if it failed. Unlike other functions the return value 0 from
+EVP_PKEY_verify() only indicates that the signature did not not verify
+successfully (that is tbs did not match the original data or the signature was
+of invalid form) it is not an indication of a more serious error.
+
+A negative value indicates an error other that signature verification failure.
+In particular a return value of -2 indicates the operation is not supported by
+the public key algorithm.
+
+=head1 EXAMPLE
+
+Verify signature using PKCS#1 and SHA256 digest:
+
+ #include <openssl/evp.h>
+ #include <openssl/rsa.h>
+
+ EVP_PKEY_CTX *ctx;
+ unsigned char *md, *sig;
+ size_t mdlen, siglen; 
+ EVP_PKEY *verify_key;
+ /* NB: assumes verify_key, sig, siglen md and mdlen are already set up
+  * and that verify_key is an RSA public key
+  */
+ ctx = EVP_PKEY_CTX_new(verify_key);
+ if (!ctx)
+       /* Error occurred */
+ if (EVP_PKEY_verify_init(ctx) <= 0)
+       /* Error */
+ if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0)
+       /* Error */
+ if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0)
+       /* Error */
+
+ /* Perform operation */
+ ret = EVP_PKEY_verify(ctx, sig, siglen, md, mdlen);
+
+ /* ret == 1 indicates success, 0 verify failure and < 0 for some
+  * other error.
+  */
+
+=head1 SEE ALSO
+
+L<EVP_PKEY_CTX_new(3)|EVP_PKEY_CTX_new(3)>,
+L<EVP_PKEY_encrypt(3)|EVP_PKEY_encrypt(3)>,
+L<EVP_PKEY_decrypt(3)|EVP_PKEY_decrypt(3)>,
+L<EVP_PKEY_sign(3)|EVP_PKEY_sign(3)>,
+L<EVP_PKEY_verifyrecover(3)|EVP_PKEY_verifyrecover(3)>,
+L<EVP_PKEY_derive(3)|EVP_PKEY_derive(3)> 
+
+=head1 HISTORY
+
+These functions were first added to OpenSSL 1.0.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/EVP_PKEY_verifyrecover.pod b/deps/openssl/openssl/doc/crypto/EVP_PKEY_verifyrecover.pod
new file mode 100644 (file)
index 0000000..f3605eb
--- /dev/null
@@ -0,0 +1,103 @@
+=pod
+
+=head1 NAME
+
+EVP_PKEY_verifyrecover_init, EVP_PKEY_verifyrecover - recover signature using a public key algorithm
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ int EVP_PKEY_verifyrecover_init(EVP_PKEY_CTX *ctx);
+ int EVP_PKEY_verifyrecover(EVP_PKEY_CTX *ctx,
+                       unsigned char *rout, size_t *routlen,
+                       const unsigned char *sig, size_t siglen);
+
+=head1 DESCRIPTION
+
+The EVP_PKEY_verifyrecover_init() function initializes a public key algorithm
+context using key B<pkey> for a verify recover operation.
+
+The EVP_PKEY_verifyrecover() function recovers signed data
+using B<ctx>. The signature is specified using the B<sig> and
+B<siglen> parameters. If B<rout> is B<NULL> then the maximum size of the output
+buffer is written to the B<routlen> parameter. If B<rout> is not B<NULL> then
+before the call the B<routlen> parameter should contain the length of the
+B<rout> buffer, if the call is successful recovered data is written to
+B<rout> and the amount of data written to B<routlen>.
+
+=head1 NOTES
+
+Normally an application is only interested in whether a signature verification
+operation is successful in those cases the EVP_verify() function should be 
+used.
+
+Sometimes however it is useful to obtain the data originally signed using a
+signing operation. Only certain public key algorithms can recover a signature
+in this way (for example RSA in PKCS padding mode).
+
+After the call to EVP_PKEY_verifyrecover_init() algorithm specific control
+operations can be performed to set any appropriate parameters for the
+operation.
+
+The function EVP_PKEY_verifyrecover() can be called more than once on the same
+context if several operations are performed using the same parameters.
+
+=head1 RETURN VALUES
+
+EVP_PKEY_verifyrecover_init() and EVP_PKEY_verifyrecover() return 1 for success
+and 0 or a negative value for failure. In particular a return value of -2
+indicates the operation is not supported by the public key algorithm.
+
+=head1 EXAMPLE
+
+Recover digest originally signed using PKCS#1 and SHA256 digest:
+
+ #include <openssl/evp.h>
+ #include <openssl/rsa.h>
+
+ EVP_PKEY_CTX *ctx;
+ unsigned char *rout, *sig;
+ size_t routlen, siglen; 
+ EVP_PKEY *verify_key;
+ /* NB: assumes verify_key, sig and siglen are already set up
+  * and that verify_key is an RSA public key
+  */
+ ctx = EVP_PKEY_CTX_new(verify_key);
+ if (!ctx)
+       /* Error occurred */
+ if (EVP_PKEY_verifyrecover_init(ctx) <= 0)
+       /* Error */
+ if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0)
+       /* Error */
+ if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0)
+       /* Error */
+
+ /* Determine buffer length */
+ if (EVP_PKEY_verifyrecover(ctx, NULL, &routlen, sig, siglen) <= 0)
+       /* Error */
+
+ rout = OPENSSL_malloc(routlen);
+
+ if (!rout)
+       /* malloc failure */
+ if (EVP_PKEY_verifyrecover(ctx, rout, &routlen, sig, siglen) <= 0)
+       /* Error */
+
+ /* Recovered data is routlen bytes written to buffer rout */
+
+=head1 SEE ALSO
+
+L<EVP_PKEY_CTX_new(3)|EVP_PKEY_CTX_new(3)>,
+L<EVP_PKEY_encrypt(3)|EVP_PKEY_encrypt(3)>,
+L<EVP_PKEY_decrypt(3)|EVP_PKEY_decrypt(3)>,
+L<EVP_PKEY_sign(3)|EVP_PKEY_sign(3)>,
+L<EVP_PKEY_verify(3)|EVP_PKEY_verify(3)>,
+L<EVP_PKEY_derive(3)|EVP_PKEY_derive(3)> 
+
+=head1 HISTORY
+
+These functions were first added to OpenSSL 1.0.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/EVP_SealInit.pod b/deps/openssl/openssl/doc/crypto/EVP_SealInit.pod
new file mode 100644 (file)
index 0000000..7d793e1
--- /dev/null
@@ -0,0 +1,85 @@
+=pod
+
+=head1 NAME
+
+EVP_SealInit, EVP_SealUpdate, EVP_SealFinal - EVP envelope encryption
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
+                  unsigned char **ek, int *ekl, unsigned char *iv,
+                  EVP_PKEY **pubk, int npubk);
+ int EVP_SealUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
+         int *outl, unsigned char *in, int inl);
+ int EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out,
+         int *outl);
+
+=head1 DESCRIPTION
+
+The EVP envelope routines are a high level interface to envelope
+encryption. They generate a random key and IV (if required) then
+"envelope" it by using public key encryption. Data can then be
+encrypted using this key.
+
+EVP_SealInit() initializes a cipher context B<ctx> for encryption
+with cipher B<type> using a random secret key and IV. B<type> is normally
+supplied by a function such as EVP_des_cbc(). The secret key is encrypted
+using one or more public keys, this allows the same encrypted data to be
+decrypted using any of the corresponding private keys. B<ek> is an array of
+buffers where the public key encrypted secret key will be written, each buffer
+must contain enough room for the corresponding encrypted key: that is
+B<ek[i]> must have room for B<EVP_PKEY_size(pubk[i])> bytes. The actual
+size of each encrypted secret key is written to the array B<ekl>. B<pubk> is
+an array of B<npubk> public keys.
+
+The B<iv> parameter is a buffer where the generated IV is written to. It must
+contain enough room for the corresponding cipher's IV, as determined by (for
+example) EVP_CIPHER_iv_length(type).
+
+If the cipher does not require an IV then the B<iv> parameter is ignored
+and can be B<NULL>.
+
+EVP_SealUpdate() and EVP_SealFinal() have exactly the same properties
+as the EVP_EncryptUpdate() and EVP_EncryptFinal() routines, as 
+documented on the L<EVP_EncryptInit(3)|EVP_EncryptInit(3)> manual
+page. 
+
+=head1 RETURN VALUES
+
+EVP_SealInit() returns 0 on error or B<npubk> if successful.
+
+EVP_SealUpdate() and EVP_SealFinal() return 1 for success and 0 for
+failure.
+
+=head1 NOTES
+
+Because a random secret key is generated the random number generator
+must be seeded before calling EVP_SealInit().
+
+The public key must be RSA because it is the only OpenSSL public key
+algorithm that supports key transport.
+
+Envelope encryption is the usual method of using public key encryption
+on large amounts of data, this is because public key encryption is slow
+but symmetric encryption is fast. So symmetric encryption is used for
+bulk encryption and the small random symmetric key used is transferred
+using public key encryption.
+
+It is possible to call EVP_SealInit() twice in the same way as
+EVP_EncryptInit(). The first call should have B<npubk> set to 0
+and (after setting any cipher parameters) it should be called again
+with B<type> set to NULL.
+
+=head1 SEE ALSO
+
+L<evp(3)|evp(3)>, L<rand(3)|rand(3)>,
+L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>,
+L<EVP_OpenInit(3)|EVP_OpenInit(3)>
+
+=head1 HISTORY
+
+EVP_SealFinal() did not return a value before OpenSSL 0.9.7.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/EVP_SignInit.pod b/deps/openssl/openssl/doc/crypto/EVP_SignInit.pod
new file mode 100644 (file)
index 0000000..620a623
--- /dev/null
@@ -0,0 +1,104 @@
+=pod
+
+=head1 NAME
+
+EVP_SignInit, EVP_SignUpdate, EVP_SignFinal - EVP signing functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ int EVP_SignInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
+ int EVP_SignUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
+ int EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *sig,unsigned int *s, EVP_PKEY *pkey);
+
+ void EVP_SignInit(EVP_MD_CTX *ctx, const EVP_MD *type);
+
+ int EVP_PKEY_size(EVP_PKEY *pkey);
+
+=head1 DESCRIPTION
+
+The EVP signature routines are a high level interface to digital
+signatures.
+
+EVP_SignInit_ex() sets up signing context B<ctx> to use digest
+B<type> from ENGINE B<impl>. B<ctx> must be initialized with
+EVP_MD_CTX_init() before calling this function.
+
+EVP_SignUpdate() hashes B<cnt> bytes of data at B<d> into the
+signature context B<ctx>. This function can be called several times on the
+same B<ctx> to include additional data.
+
+EVP_SignFinal() signs the data in B<ctx> using the private key B<pkey> and
+places the signature in B<sig>. The number of bytes of data written (i.e. the
+length of the signature) will be written to the integer at B<s>, at most
+EVP_PKEY_size(pkey) bytes will be written. 
+
+EVP_SignInit() initializes a signing context B<ctx> to use the default
+implementation of digest B<type>.
+
+EVP_PKEY_size() returns the maximum size of a signature in bytes. The actual
+signature returned by EVP_SignFinal() may be smaller.
+
+=head1 RETURN VALUES
+
+EVP_SignInit_ex(), EVP_SignUpdate() and EVP_SignFinal() return 1
+for success and 0 for failure.
+
+EVP_PKEY_size() returns the maximum size of a signature in bytes.
+
+The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 NOTES
+
+The B<EVP> interface to digital signatures should almost always be used in
+preference to the low level interfaces. This is because the code then becomes
+transparent to the algorithm used and much more flexible.
+
+Due to the link between message digests and public key algorithms the correct
+digest algorithm must be used with the correct public key type. A list of
+algorithms and associated public key algorithms appears in 
+L<EVP_DigestInit(3)|EVP_DigestInit(3)>.
+
+When signing with DSA private keys the random number generator must be seeded
+or the operation will fail. The random number generator does not need to be
+seeded for RSA signatures.
+
+The call to EVP_SignFinal() internally finalizes a copy of the digest context.
+This means that calls to EVP_SignUpdate() and EVP_SignFinal() can be called
+later to digest and sign additional data.
+
+Since only a copy of the digest context is ever finalized the context must
+be cleaned up after use by calling EVP_MD_CTX_cleanup() or a memory leak
+will occur.
+
+=head1 BUGS
+
+Older versions of this documentation wrongly stated that calls to 
+EVP_SignUpdate() could not be made after calling EVP_SignFinal().
+
+Since the private key is passed in the call to EVP_SignFinal() any error
+relating to the private key (for example an unsuitable key and digest
+combination) will not be indicated until after potentially large amounts of
+data have been passed through EVP_SignUpdate().
+
+It is not possible to change the signing parameters using these function.
+
+The previous two bugs are fixed in the newer EVP_SignDigest*() function.
+
+=head1 SEE ALSO
+
+L<EVP_VerifyInit(3)|EVP_VerifyInit(3)>,
+L<EVP_DigestInit(3)|EVP_DigestInit(3)>, L<err(3)|err(3)>,
+L<evp(3)|evp(3)>, L<hmac(3)|hmac(3)>, L<md2(3)|md2(3)>,
+L<md5(3)|md5(3)>, L<mdc2(3)|mdc2(3)>, L<ripemd(3)|ripemd(3)>,
+L<sha(3)|sha(3)>, L<dgst(1)|dgst(1)>
+
+=head1 HISTORY
+
+EVP_SignInit(), EVP_SignUpdate() and EVP_SignFinal() are
+available in all versions of SSLeay and OpenSSL.
+
+EVP_SignInit_ex() was added in OpenSSL 0.9.7.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/EVP_VerifyInit.pod b/deps/openssl/openssl/doc/crypto/EVP_VerifyInit.pod
new file mode 100644 (file)
index 0000000..9097f09
--- /dev/null
@@ -0,0 +1,95 @@
+=pod
+
+=head1 NAME
+
+EVP_VerifyInit, EVP_VerifyUpdate, EVP_VerifyFinal - EVP signature verification functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ int EVP_VerifyInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
+ int EVP_VerifyUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
+ int EVP_VerifyFinal(EVP_MD_CTX *ctx,unsigned char *sigbuf, unsigned int siglen,EVP_PKEY *pkey);
+
+ int EVP_VerifyInit(EVP_MD_CTX *ctx, const EVP_MD *type);
+
+=head1 DESCRIPTION
+
+The EVP signature verification routines are a high level interface to digital
+signatures.
+
+EVP_VerifyInit_ex() sets up verification context B<ctx> to use digest
+B<type> from ENGINE B<impl>. B<ctx> must be initialized by calling
+EVP_MD_CTX_init() before calling this function.
+
+EVP_VerifyUpdate() hashes B<cnt> bytes of data at B<d> into the
+verification context B<ctx>. This function can be called several times on the
+same B<ctx> to include additional data.
+
+EVP_VerifyFinal() verifies the data in B<ctx> using the public key B<pkey>
+and against the B<siglen> bytes at B<sigbuf>.
+
+EVP_VerifyInit() initializes verification context B<ctx> to use the default
+implementation of digest B<type>.
+
+=head1 RETURN VALUES
+
+EVP_VerifyInit_ex() and EVP_VerifyUpdate() return 1 for success and 0 for
+failure.
+
+EVP_VerifyFinal() returns 1 for a correct signature, 0 for failure and -1 if some
+other error occurred.
+
+The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 NOTES
+
+The B<EVP> interface to digital signatures should almost always be used in
+preference to the low level interfaces. This is because the code then becomes
+transparent to the algorithm used and much more flexible.
+
+Due to the link between message digests and public key algorithms the correct
+digest algorithm must be used with the correct public key type. A list of
+algorithms and associated public key algorithms appears in 
+L<EVP_DigestInit(3)|EVP_DigestInit(3)>.
+
+The call to EVP_VerifyFinal() internally finalizes a copy of the digest context.
+This means that calls to EVP_VerifyUpdate() and EVP_VerifyFinal() can be called
+later to digest and verify additional data.
+
+Since only a copy of the digest context is ever finalized the context must
+be cleaned up after use by calling EVP_MD_CTX_cleanup() or a memory leak
+will occur.
+
+=head1 BUGS
+
+Older versions of this documentation wrongly stated that calls to 
+EVP_VerifyUpdate() could not be made after calling EVP_VerifyFinal().
+
+Since the public key is passed in the call to EVP_SignFinal() any error
+relating to the private key (for example an unsuitable key and digest
+combination) will not be indicated until after potentially large amounts of
+data have been passed through EVP_SignUpdate().
+
+It is not possible to change the signing parameters using these function.
+
+The previous two bugs are fixed in the newer EVP_VerifyDigest*() function.
+
+=head1 SEE ALSO
+
+L<evp(3)|evp(3)>,
+L<EVP_SignInit(3)|EVP_SignInit(3)>,
+L<EVP_DigestInit(3)|EVP_DigestInit(3)>, L<err(3)|err(3)>,
+L<evp(3)|evp(3)>, L<hmac(3)|hmac(3)>, L<md2(3)|md2(3)>,
+L<md5(3)|md5(3)>, L<mdc2(3)|mdc2(3)>, L<ripemd(3)|ripemd(3)>,
+L<sha(3)|sha(3)>, L<dgst(1)|dgst(1)>
+
+=head1 HISTORY
+
+EVP_VerifyInit(), EVP_VerifyUpdate() and EVP_VerifyFinal() are
+available in all versions of SSLeay and OpenSSL.
+
+EVP_VerifyInit_ex() was added in OpenSSL 0.9.7
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/OBJ_nid2obj.pod b/deps/openssl/openssl/doc/crypto/OBJ_nid2obj.pod
new file mode 100644 (file)
index 0000000..1e45dd4
--- /dev/null
@@ -0,0 +1,151 @@
+=pod
+
+=head1 NAME
+
+OBJ_nid2obj, OBJ_nid2ln, OBJ_nid2sn, OBJ_obj2nid, OBJ_txt2nid, OBJ_ln2nid, OBJ_sn2nid,
+OBJ_cmp, OBJ_dup, OBJ_txt2obj, OBJ_obj2txt, OBJ_create, OBJ_cleanup - ASN1 object utility
+functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/objects.h>
+
+ ASN1_OBJECT * OBJ_nid2obj(int n);
+ const char *  OBJ_nid2ln(int n);
+ const char *  OBJ_nid2sn(int n);
+
+ int OBJ_obj2nid(const ASN1_OBJECT *o);
+ int OBJ_ln2nid(const char *ln);
+ int OBJ_sn2nid(const char *sn);
+
+ int OBJ_txt2nid(const char *s);
+
+ ASN1_OBJECT * OBJ_txt2obj(const char *s, int no_name);
+ int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name);
+
+ int OBJ_cmp(const ASN1_OBJECT *a,const ASN1_OBJECT *b);
+ ASN1_OBJECT * OBJ_dup(const ASN1_OBJECT *o);
+
+ int OBJ_create(const char *oid,const char *sn,const char *ln);
+ void OBJ_cleanup(void);
+
+=head1 DESCRIPTION
+
+The ASN1 object utility functions process ASN1_OBJECT structures which are
+a representation of the ASN1 OBJECT IDENTIFIER (OID) type.
+
+OBJ_nid2obj(), OBJ_nid2ln() and OBJ_nid2sn() convert the NID B<n> to 
+an ASN1_OBJECT structure, its long name and its short name respectively,
+or B<NULL> is an error occurred.
+
+OBJ_obj2nid(), OBJ_ln2nid(), OBJ_sn2nid() return the corresponding NID
+for the object B<o>, the long name <ln> or the short name <sn> respectively
+or NID_undef if an error occurred.
+
+OBJ_txt2nid() returns NID corresponding to text string <s>. B<s> can be
+a long name, a short name or the numerical respresentation of an object.
+
+OBJ_txt2obj() converts the text string B<s> into an ASN1_OBJECT structure.
+If B<no_name> is 0 then long names and short names will be interpreted
+as well as numerical forms. If B<no_name> is 1 only the numerical form
+is acceptable.
+
+OBJ_obj2txt() converts the B<ASN1_OBJECT> B<a> into a textual representation.
+The representation is written as a null terminated string to B<buf>
+at most B<buf_len> bytes are written, truncating the result if necessary.
+The total amount of space required is returned. If B<no_name> is 0 then
+if the object has a long or short name then that will be used, otherwise
+the numerical form will be used. If B<no_name> is 1 then the numerical
+form will always be used.
+
+OBJ_cmp() compares B<a> to B<b>. If the two are identical 0 is returned.
+
+OBJ_dup() returns a copy of B<o>.
+
+OBJ_create() adds a new object to the internal table. B<oid> is the 
+numerical form of the object, B<sn> the short name and B<ln> the
+long name. A new NID is returned for the created object.
+
+OBJ_cleanup() cleans up OpenSSLs internal object table: this should
+be called before an application exits if any new objects were added
+using OBJ_create().
+
+=head1 NOTES
+
+Objects in OpenSSL can have a short name, a long name and a numerical
+identifier (NID) associated with them. A standard set of objects is
+represented in an internal table. The appropriate values are defined
+in the header file B<objects.h>.
+
+For example the OID for commonName has the following definitions:
+
+ #define SN_commonName                   "CN"
+ #define LN_commonName                   "commonName"
+ #define NID_commonName                  13
+
+New objects can be added by calling OBJ_create().
+
+Table objects have certain advantages over other objects: for example
+their NIDs can be used in a C language switch statement. They are
+also static constant structures which are shared: that is there
+is only a single constant structure for each table object.
+
+Objects which are not in the table have the NID value NID_undef.
+
+Objects do not need to be in the internal tables to be processed,
+the functions OBJ_txt2obj() and OBJ_obj2txt() can process the numerical
+form of an OID.
+
+=head1 EXAMPLES
+
+Create an object for B<commonName>:
+
+ ASN1_OBJECT *o;
+ o = OBJ_nid2obj(NID_commonName);
+
+Check if an object is B<commonName>
+
+ if (OBJ_obj2nid(obj) == NID_commonName)
+       /* Do something */
+
+Create a new NID and initialize an object from it:
+
+ int new_nid;
+ ASN1_OBJECT *obj;
+ new_nid = OBJ_create("1.2.3.4", "NewOID", "New Object Identifier");
+
+ obj = OBJ_nid2obj(new_nid);
+Create a new object directly:
+
+ obj = OBJ_txt2obj("1.2.3.4", 1);
+
+=head1 BUGS
+
+OBJ_obj2txt() is awkward and messy to use: it doesn't follow the 
+convention of other OpenSSL functions where the buffer can be set
+to B<NULL> to determine the amount of data that should be written.
+Instead B<buf> must point to a valid buffer and B<buf_len> should
+be set to a positive value. A buffer length of 80 should be more
+than enough to handle any OID encountered in practice.
+
+=head1 RETURN VALUES
+
+OBJ_nid2obj() returns an B<ASN1_OBJECT> structure or B<NULL> is an
+error occurred.
+
+OBJ_nid2ln() and OBJ_nid2sn() returns a valid string or B<NULL>
+on error.
+
+OBJ_obj2nid(), OBJ_ln2nid(), OBJ_sn2nid() and OBJ_txt2nid() return
+a NID or B<NID_undef> on error.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>
+
+=head1 HISTORY
+
+TBA
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/OPENSSL_Applink.pod b/deps/openssl/openssl/doc/crypto/OPENSSL_Applink.pod
new file mode 100644 (file)
index 0000000..e54de12
--- /dev/null
@@ -0,0 +1,21 @@
+=pod
+
+=head1 NAME
+
+OPENSSL_Applink - glue between OpenSSL BIO and Win32 compiler run-time
+
+=head1 SYNOPSIS
+
+ __declspec(dllexport) void **OPENSSL_Applink();
+
+=head1 DESCRIPTION
+
+OPENSSL_Applink is application-side interface which provides a glue
+between OpenSSL BIO layer and Win32 compiler run-time environment.
+Even though it appears at application side, it's essentially OpenSSL
+private interface. For this reason application developers are not
+expected to implement it, but to compile provided module with
+compiler of their choice and link it into the target application.
+The referred module is available as <openssl>/ms/applink.c.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/OPENSSL_VERSION_NUMBER.pod b/deps/openssl/openssl/doc/crypto/OPENSSL_VERSION_NUMBER.pod
new file mode 100644 (file)
index 0000000..c39ac35
--- /dev/null
@@ -0,0 +1,101 @@
+=pod
+
+=head1 NAME
+
+OPENSSL_VERSION_NUMBER, SSLeay, SSLeay_version - get OpenSSL version number
+
+=head1 SYNOPSIS
+
+ #include <openssl/opensslv.h>
+ #define OPENSSL_VERSION_NUMBER 0xnnnnnnnnnL
+
+ #include <openssl/crypto.h>
+ long SSLeay(void);
+ const char *SSLeay_version(int t);
+
+=head1 DESCRIPTION
+
+OPENSSL_VERSION_NUMBER is a numeric release version identifier:
+
+ MMNNFFPPS: major minor fix patch status
+
+The status nibble has one of the values 0 for development, 1 to e for betas
+1 to 14, and f for release.
+
+for example
+
+ 0x000906000 == 0.9.6 dev
+ 0x000906023 == 0.9.6b beta 3
+ 0x00090605f == 0.9.6e release
+
+Versions prior to 0.9.3 have identifiers E<lt> 0x0930.
+Versions between 0.9.3 and 0.9.5 had a version identifier with this
+interpretation:
+
+ MMNNFFRBB major minor fix final beta/patch
+
+for example
+
+ 0x000904100 == 0.9.4 release
+ 0x000905000 == 0.9.5 dev
+
+Version 0.9.5a had an interim interpretation that is like the current one,
+except the patch level got the highest bit set, to keep continuity.  The
+number was therefore 0x0090581f.
+
+
+For backward compatibility, SSLEAY_VERSION_NUMBER is also defined.
+
+SSLeay() returns this number. The return value can be compared to the
+macro to make sure that the correct version of the library has been
+loaded, especially when using DLLs on Windows systems.
+
+SSLeay_version() returns different strings depending on B<t>:
+
+=over 4
+
+=item SSLEAY_VERSION
+
+The text variant of the version number and the release date.  For example,
+"OpenSSL 0.9.5a 1 Apr 2000".
+
+=item SSLEAY_CFLAGS
+
+The compiler flags set for the compilation process in the form
+"compiler: ..."  if available or "compiler: information not available"
+otherwise.
+
+=item SSLEAY_BUILT_ON
+
+The date of the build process in the form "built on: ..." if available
+or "built on: date not available" otherwise.
+
+=item SSLEAY_PLATFORM
+
+The "Configure" target of the library build in the form "platform: ..."
+if available or "platform: information not available" otherwise.
+
+=item SSLEAY_DIR
+
+The "OPENSSLDIR" setting of the library build in the form "OPENSSLDIR: "...""
+if available or "OPENSSLDIR: N/A" otherwise.
+
+=back
+
+For an unknown B<t>, the text "not available" is returned.
+
+=head1 RETURN VALUE
+
+The version number.
+
+=head1 SEE ALSO
+
+L<crypto(3)|crypto(3)>
+
+=head1 HISTORY
+
+SSLeay() and SSLEAY_VERSION_NUMBER are available in all versions of SSLeay and OpenSSL.
+OPENSSL_VERSION_NUMBER is available in all versions of OpenSSL.
+B<SSLEAY_DIR> was added in OpenSSL 0.9.7.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/OPENSSL_config.pod b/deps/openssl/openssl/doc/crypto/OPENSSL_config.pod
new file mode 100644 (file)
index 0000000..e7bba2a
--- /dev/null
@@ -0,0 +1,82 @@
+=pod
+
+=head1 NAME
+
+OPENSSL_config, OPENSSL_no_config - simple OpenSSL configuration functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/conf.h>
+
+ void OPENSSL_config(const char *config_name);
+ void OPENSSL_no_config(void);
+
+=head1 DESCRIPTION
+
+OPENSSL_config() configures OpenSSL using the standard B<openssl.cnf>
+configuration file name using B<config_name>. If B<config_name> is NULL then
+the default name B<openssl_conf> will be used. Any errors are ignored. Further
+calls to OPENSSL_config() will have no effect. The configuration file format
+is documented in the L<conf(5)|conf(5)> manual page.
+
+OPENSSL_no_config() disables configuration. If called before OPENSSL_config()
+no configuration takes place.
+
+=head1 NOTES
+
+It is B<strongly> recommended that B<all> new applications call OPENSSL_config()
+or the more sophisticated functions such as CONF_modules_load() during
+initialization (that is before starting any threads). By doing this
+an application does not need to keep track of all configuration options
+and some new functionality can be supported automatically.
+
+It is also possible to automatically call OPENSSL_config() when an application
+calls OPENSSL_add_all_algorithms() by compiling an application with the
+preprocessor symbol B<OPENSSL_LOAD_CONF> #define'd. In this way configuration
+can be added without source changes.
+
+The environment variable B<OPENSSL_CONF> can be set to specify the location
+of the configuration file.
+Currently ASN1 OBJECTs and ENGINE configuration can be performed future
+versions of OpenSSL will add new configuration options.
+
+There are several reasons why calling the OpenSSL configuration routines is
+advisable. For example new ENGINE functionality was added to OpenSSL 0.9.7.
+In OpenSSL 0.9.7 control functions can be supported by ENGINEs, this can be
+used (among other things) to load dynamic ENGINEs from shared libraries (DSOs).
+However very few applications currently support the control interface and so
+very few can load and use dynamic ENGINEs. Equally in future more sophisticated
+ENGINEs will require certain control operations to customize them. If an
+application calls OPENSSL_config() it doesn't need to know or care about
+ENGINE control operations because they can be performed by editing a
+configuration file.
+
+Applications should free up configuration at application closedown by calling
+CONF_modules_free().
+
+=head1 RESTRICTIONS
+
+The OPENSSL_config() function is designed to be a very simple "call it and
+forget it" function. As a result its behaviour is somewhat limited. It ignores
+all errors silently and it can only load from the standard configuration file
+location for example.
+
+It is however B<much> better than nothing. Applications which need finer
+control over their configuration functionality should use the configuration
+functions such as CONF_load_modules() directly.
+
+=head1 RETURN VALUES
+
+Neither OPENSSL_config() nor OPENSSL_no_config() return a value.
+
+=head1 SEE ALSO
+
+L<conf(5)|conf(5)>, L<CONF_load_modules_file(3)|CONF_load_modules_file(3)>,
+L<CONF_modules_free(3),CONF_modules_free(3)>
+
+=head1 HISTORY
+
+OPENSSL_config() and OPENSSL_no_config() first appeared in OpenSSL 0.9.7
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/OPENSSL_ia32cap.pod b/deps/openssl/openssl/doc/crypto/OPENSSL_ia32cap.pod
new file mode 100644 (file)
index 0000000..2e659d3
--- /dev/null
@@ -0,0 +1,43 @@
+=pod
+
+=head1 NAME
+
+OPENSSL_ia32cap - finding the IA-32 processor capabilities
+
+=head1 SYNOPSIS
+
+ unsigned long *OPENSSL_ia32cap_loc(void);
+ #define OPENSSL_ia32cap (*(OPENSSL_ia32cap_loc()))
+
+=head1 DESCRIPTION
+
+Value returned by OPENSSL_ia32cap_loc() is address of a variable
+containing IA-32 processor capabilities bit vector as it appears in EDX
+register after executing CPUID instruction with EAX=1 input value (see
+Intel Application Note #241618). Naturally it's meaningful on IA-32[E]
+platforms only. The variable is normally set up automatically upon
+toolkit initialization, but can be manipulated afterwards to modify
+crypto library behaviour. For the moment of this writing six bits are
+significant, namely:
+
+1. bit #28 denoting Hyperthreading, which is used to distiguish
+   cores with shared cache;
+2. bit #26 denoting SSE2 support;
+3. bit #25 denoting SSE support;
+4. bit #23 denoting MMX support;
+5. bit #20, reserved by Intel, is used to choose between RC4 code
+   pathes;
+6. bit #4 denoting presence of Time-Stamp Counter.
+
+For example, clearing bit #26 at run-time disables high-performance
+SSE2 code present in the crypto library. You might have to do this if
+target OpenSSL application is executed on SSE2 capable CPU, but under
+control of OS which does not support SSE2 extentions. Even though you
+can manipulate the value programmatically, you most likely will find it
+more appropriate to set up an environment variable with the same name
+prior starting target application, e.g. on Intel P4 processor 'env
+OPENSSL_ia32cap=0x12900010 apps/openssl', to achieve same effect
+without modifying the application source code. Alternatively you can
+reconfigure the toolkit with no-sse2 option and recompile.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/OPENSSL_load_builtin_modules.pod b/deps/openssl/openssl/doc/crypto/OPENSSL_load_builtin_modules.pod
new file mode 100644 (file)
index 0000000..f14dfaf
--- /dev/null
@@ -0,0 +1,51 @@
+=pod
+
+=head1 NAME
+
+OPENSSL_load_builtin_modules - add standard configuration modules
+
+=head1 SYNOPSIS
+
+ #include <openssl/conf.h>
+
+ void OPENSSL_load_builtin_modules(void);
+ void ASN1_add_oid_module(void);
+ ENGINE_add_conf_module();
+
+=head1 DESCRIPTION
+
+The function OPENSSL_load_builtin_modules() adds all the standard OpenSSL
+configuration modules to the internal list. They can then be used by the
+OpenSSL configuration code.
+
+ASN1_add_oid_module() adds just the ASN1 OBJECT module.
+
+ENGINE_add_conf_module() adds just the ENGINE configuration module.
+
+=head1 NOTES
+
+If the simple configuration function OPENSSL_config() is called then 
+OPENSSL_load_builtin_modules() is called automatically.
+
+Applications which use the configuration functions directly will need to
+call OPENSSL_load_builtin_modules() themselves I<before> any other 
+configuration code.
+
+Applications should call OPENSSL_load_builtin_modules() to load all
+configuration modules instead of adding modules selectively: otherwise 
+functionality may be missing from the application if an when new
+modules are added.
+
+=head1 RETURN VALUE
+
+None of the functions return a value.
+
+=head1 SEE ALSO
+
+L<conf(3)|conf(3)>, L<OPENSSL_config(3)|OPENSSL_config(3)>
+
+=head1 HISTORY
+
+These functions first appeared in OpenSSL 0.9.7.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/OpenSSL_add_all_algorithms.pod b/deps/openssl/openssl/doc/crypto/OpenSSL_add_all_algorithms.pod
new file mode 100644 (file)
index 0000000..e63411b
--- /dev/null
@@ -0,0 +1,66 @@
+=pod
+
+=head1 NAME
+
+OpenSSL_add_all_algorithms, OpenSSL_add_all_ciphers, OpenSSL_add_all_digests -
+add algorithms to internal table
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ void OpenSSL_add_all_algorithms(void);
+ void OpenSSL_add_all_ciphers(void);
+ void OpenSSL_add_all_digests(void);
+
+ void EVP_cleanup(void);
+
+=head1 DESCRIPTION
+
+OpenSSL keeps an internal table of digest algorithms and ciphers. It uses
+this table to lookup ciphers via functions such as EVP_get_cipher_byname().
+
+OpenSSL_add_all_digests() adds all digest algorithms to the table.
+
+OpenSSL_add_all_algorithms() adds all algorithms to the table (digests and
+ciphers).
+
+OpenSSL_add_all_ciphers() adds all encryption algorithms to the table including
+password based encryption algorithms.
+
+EVP_cleanup() removes all ciphers and digests from the table.
+
+=head1 RETURN VALUES
+
+None of the functions return a value.
+
+=head1 NOTES
+
+A typical application will call OpenSSL_add_all_algorithms() initially and
+EVP_cleanup() before exiting.
+
+An application does not need to add algorithms to use them explicitly, for example
+by EVP_sha1(). It just needs to add them if it (or any of the functions it calls)
+needs to lookup algorithms.
+
+The cipher and digest lookup functions are used in many parts of the library. If
+the table is not initialized several functions will misbehave and complain they
+cannot find algorithms. This includes the PEM, PKCS#12, SSL and S/MIME libraries.
+This is a common query in the OpenSSL mailing lists.
+
+Calling OpenSSL_add_all_algorithms() links in all algorithms: as a result a
+statically linked executable can be quite large. If this is important it is possible
+to just add the required ciphers and digests.
+
+=head1 BUGS
+
+Although the functions do not return error codes it is possible for them to fail.
+This will only happen as a result of a memory allocation failure so this is not
+too much of a problem in practice.
+
+=head1 SEE ALSO
+
+L<evp(3)|evp(3)>, L<EVP_DigestInit(3)|EVP_DigestInit(3)>,
+L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/PEM_write_bio_CMS_stream.pod b/deps/openssl/openssl/doc/crypto/PEM_write_bio_CMS_stream.pod
new file mode 100644 (file)
index 0000000..e070c45
--- /dev/null
@@ -0,0 +1,41 @@
+=pod
+
+=head1 NAME
+
+ PEM_write_bio_CMS_stream - output CMS_ContentInfo structure in PEM format.
+
+=head1 SYNOPSIS
+
+ #include <openssl/cms.h>
+ #include <openssl/pem.h>
+
+ int PEM_write_bio_CMS_stream(BIO *out, CMS_ContentInfo *cms, BIO *data, int flags);
+
+=head1 DESCRIPTION
+
+PEM_write_bio_CMS_stream() outputs a CMS_ContentInfo structure in PEM format.
+
+It is otherwise identical to the function SMIME_write_CMS().
+
+=head1 NOTES
+
+This function is effectively a version of the PEM_write_bio_CMS() supporting
+streaming.
+
+=head1 RETURN VALUES
+
+PEM_write_bio_CMS_stream() returns 1 for success or 0 for failure.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<CMS_sign(3)|CMS_sign(3)>,
+L<CMS_verify(3)|CMS_verify(3)>, L<CMS_encrypt(3)|CMS_encrypt(3)>
+L<CMS_decrypt(3)|CMS_decrypt(3)>,
+L<SMIME_write_CMS(3)|SMIME_write_CMS(3)>,
+L<i2d_CMS_bio_stream(3)|i2d_CMS_bio_stream(3)>
+
+=head1 HISTORY
+
+PEM_write_bio_CMS_stream() was added to OpenSSL 1.0.0
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/PEM_write_bio_PKCS7_stream.pod b/deps/openssl/openssl/doc/crypto/PEM_write_bio_PKCS7_stream.pod
new file mode 100644 (file)
index 0000000..16fc9b6
--- /dev/null
@@ -0,0 +1,41 @@
+=pod
+
+=head1 NAME
+
+PEM_write_bio_PKCS7_stream - output PKCS7 structure in PEM format.
+
+=head1 SYNOPSIS
+
+ #include <openssl/pkcs7.h>
+ #include <openssl/pem.h>
+
+ int PEM_write_bio_PKCS7_stream(BIO *out, PKCS7 *p7, BIO *data, int flags);
+
+=head1 DESCRIPTION
+
+PEM_write_bio_PKCS7_stream() outputs a PKCS7 structure in PEM format.
+
+It is otherwise identical to the function SMIME_write_PKCS7().
+
+=head1 NOTES
+
+This function is effectively a version of the PEM_write_bio_PKCS7() supporting
+streaming.
+
+=head1 RETURN VALUES
+
+PEM_write_bio_PKCS7_stream() returns 1 for success or 0 for failure.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_sign(3)|PKCS7_sign(3)>,
+L<PKCS7_verify(3)|PKCS7_verify(3)>, L<PKCS7_encrypt(3)|PKCS7_encrypt(3)>
+L<PKCS7_decrypt(3)|PKCS7_decrypt(3)>,
+L<SMIME_write_PKCS7(3)|SMIME_write_PKCS7(3)>,
+L<i2d_PKCS7_bio_stream(3)|i2d_PKCS7_bio_stream(3)>
+
+=head1 HISTORY
+
+PEM_write_bio_PKCS7_stream() was added to OpenSSL 1.0.0
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/PKCS12_create.pod b/deps/openssl/openssl/doc/crypto/PKCS12_create.pod
new file mode 100644 (file)
index 0000000..de7cab2
--- /dev/null
@@ -0,0 +1,75 @@
+=pod
+
+=head1 NAME
+
+PKCS12_create - create a PKCS#12 structure
+
+=head1 SYNOPSIS
+
+ #include <openssl/pkcs12.h>
+
+ PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert, STACK_OF(X509) *ca,
+                               int nid_key, int nid_cert, int iter, int mac_iter, int keytype);
+
+=head1 DESCRIPTION
+
+PKCS12_create() creates a PKCS#12 structure.
+
+B<pass> is the passphrase to use. B<name> is the B<friendlyName> to use for
+the supplied certifictate and key. B<pkey> is the private key to include in
+the structure and B<cert> its corresponding certificates. B<ca>, if not B<NULL>
+is an optional set of certificates to also include in the structure.
+
+B<nid_key> and B<nid_cert> are the encryption algorithms that should be used
+for the key and certificate respectively. B<iter> is the encryption algorithm
+iteration count to use and B<mac_iter> is the MAC iteration count to use.
+B<keytype> is the type of key.
+
+=head1 NOTES
+
+The parameters B<nid_key>, B<nid_cert>, B<iter>, B<mac_iter> and B<keytype>
+can all be set to zero and sensible defaults will be used.
+
+These defaults are: 40 bit RC2 encryption for certificates, triple DES
+encryption for private keys, a key iteration count of PKCS12_DEFAULT_ITER
+(currently 2048) and a MAC iteration count of 1.
+
+The default MAC iteration count is 1 in order to retain compatibility with
+old software which did not interpret MAC iteration counts. If such compatibility
+is not required then B<mac_iter> should be set to PKCS12_DEFAULT_ITER.
+
+B<keytype> adds a flag to the store private key. This is a non standard extension
+that is only currently interpreted by MSIE. If set to zero the flag is omitted,
+if set to B<KEY_SIG> the key can be used for signing only, if set to B<KEY_EX>
+it can be used for signing and encryption. This option was useful for old
+export grade software which could use signing only keys of arbitrary size but
+had restrictions on the permissible sizes of keys which could be used for
+encryption.
+
+=head1 NEW FUNCTIONALITY IN OPENSSL 0.9.8
+
+Some additional functionality was added to PKCS12_create() in OpenSSL
+0.9.8. These extensions are detailed below.
+
+If a certificate contains an B<alias> or B<keyid> then this will be
+used for the corresponding B<friendlyName> or B<localKeyID> in the
+PKCS12 structure.
+
+Either B<pkey>, B<cert> or both can be B<NULL> to indicate that no key or
+certficate is required. In previous versions both had to be present or
+a fatal error is returned.
+
+B<nid_key> or B<nid_cert> can be set to -1 indicating that no encryption
+should be used. 
+
+B<mac_iter> can be set to -1 and the MAC will then be omitted entirely.
+
+=head1 SEE ALSO
+
+L<d2i_PKCS12(3)|d2i_PKCS12(3)>
+
+=head1 HISTORY
+
+PKCS12_create was added in OpenSSL 0.9.3
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/PKCS12_parse.pod b/deps/openssl/openssl/doc/crypto/PKCS12_parse.pod
new file mode 100644 (file)
index 0000000..c54cf2a
--- /dev/null
@@ -0,0 +1,57 @@
+=pod
+
+=head1 NAME
+
+PKCS12_parse - parse a PKCS#12 structure
+
+=head1 SYNOPSIS
+
+ #include <openssl/pkcs12.h>
+
+int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca);
+
+=head1 DESCRIPTION
+
+PKCS12_parse() parses a PKCS12 structure.
+
+B<p12> is the B<PKCS12> structure to parse. B<pass> is the passphrase to use.
+If successful the private key will be written to B<*pkey>, the corresponding
+certificate to B<*cert> and any additional certificates to B<*ca>.
+
+=head1 NOTES
+
+The parameters B<pkey> and B<cert> cannot be B<NULL>. B<ca> can be <NULL> in
+which case additional certificates will be discarded. B<*ca> can also be a
+valid STACK in which case additional certificates are appended to B<*ca>. If
+B<*ca> is B<NULL> a new STACK will be allocated.
+
+The B<friendlyName> and B<localKeyID> attributes (if present) on each
+certificate will be stored in the B<alias> and B<keyid> attributes of the
+B<X509> structure.
+
+=head1 RETURN VALUES
+
+PKCS12_parse() returns 1 for success and zero if an error occurred.
+
+The error can be obtained from L<ERR_get_error(3)|ERR_get_error(3)>
+
+=head1 BUGS
+
+Only a single private key and corresponding certificate is returned by this
+function. More complex PKCS#12 files with multiple private keys will only
+return the first match.
+
+Only B<friendlyName> and B<localKeyID> attributes are currently stored in
+certificates. Other attributes are discarded.
+
+Attributes currently cannot be stored in the private key B<EVP_PKEY> structure.
+
+=head1 SEE ALSO
+
+L<d2i_PKCS12(3)|d2i_PKCS12(3)>
+
+=head1 HISTORY
+
+PKCS12_parse was added in OpenSSL 0.9.3
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/PKCS7_decrypt.pod b/deps/openssl/openssl/doc/crypto/PKCS7_decrypt.pod
new file mode 100644 (file)
index 0000000..325699d
--- /dev/null
@@ -0,0 +1,55 @@
+=pod
+
+=head1 NAME
+
+PKCS7_decrypt - decrypt content from a PKCS#7 envelopedData structure
+
+=head1 SYNOPSIS
+
+ #include <openssl/pkcs7.h>
+
+ int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags);
+
+=head1 DESCRIPTION
+
+PKCS7_decrypt() extracts and decrypts the content from a PKCS#7 envelopedData
+structure. B<pkey> is the private key of the recipient, B<cert> is the
+recipients certificate, B<data> is a BIO to write the content to and
+B<flags> is an optional set of flags.
+
+=head1 NOTES
+
+OpenSSL_add_all_algorithms() (or equivalent) should be called before using this
+function or errors about unknown algorithms will occur.
+
+Although the recipients certificate is not needed to decrypt the data it is needed
+to locate the appropriate (of possible several) recipients in the PKCS#7 structure.
+
+The following flags can be passed in the B<flags> parameter.
+
+If the B<PKCS7_TEXT> flag is set MIME headers for type B<text/plain> are deleted
+from the content. If the content is not of type B<text/plain> then an error is
+returned.
+
+=head1 RETURN VALUES
+
+PKCS7_decrypt() returns either 1 for success or 0 for failure.
+The error can be obtained from ERR_get_error(3)
+
+=head1 BUGS
+
+PKCS7_decrypt() must be passed the correct recipient key and certificate. It would
+be better if it could look up the correct key and certificate from a database.
+
+The lack of single pass processing and need to hold all data in memory as
+mentioned in PKCS7_sign() also applies to PKCS7_verify().
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_encrypt(3)|PKCS7_encrypt(3)>
+
+=head1 HISTORY
+
+PKCS7_decrypt() was added to OpenSSL 0.9.5
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/PKCS7_encrypt.pod b/deps/openssl/openssl/doc/crypto/PKCS7_encrypt.pod
new file mode 100644 (file)
index 0000000..2cd925a
--- /dev/null
@@ -0,0 +1,80 @@
+=pod
+
+=head1 NAME
+
+PKCS7_encrypt - create a PKCS#7 envelopedData structure
+
+=head1 SYNOPSIS
+
+ #include <openssl/pkcs7.h>
+
+ PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher, int flags);
+
+=head1 DESCRIPTION
+
+PKCS7_encrypt() creates and returns a PKCS#7 envelopedData structure. B<certs>
+is a list of recipient certificates. B<in> is the content to be encrypted.
+B<cipher> is the symmetric cipher to use. B<flags> is an optional set of flags.
+
+=head1 NOTES
+
+Only RSA keys are supported in PKCS#7 and envelopedData so the recipient
+certificates supplied to this function must all contain RSA public keys, though
+they do not have to be signed using the RSA algorithm.
+
+EVP_des_ede3_cbc() (triple DES) is the algorithm of choice for S/MIME use
+because most clients will support it.
+
+Some old "export grade" clients may only support weak encryption using 40 or 64
+bit RC2. These can be used by passing EVP_rc2_40_cbc() and EVP_rc2_64_cbc()
+respectively.
+
+The algorithm passed in the B<cipher> parameter must support ASN1 encoding of
+its parameters. 
+
+Many browsers implement a "sign and encrypt" option which is simply an S/MIME
+envelopedData containing an S/MIME signed message. This can be readily produced
+by storing the S/MIME signed message in a memory BIO and passing it to
+PKCS7_encrypt().
+
+The following flags can be passed in the B<flags> parameter.
+
+If the B<PKCS7_TEXT> flag is set MIME headers for type B<text/plain> are
+prepended to the data.
+
+Normally the supplied content is translated into MIME canonical format (as
+required by the S/MIME specifications) if B<PKCS7_BINARY> is set no translation
+occurs. This option should be used if the supplied data is in binary format
+otherwise the translation will corrupt it. If B<PKCS7_BINARY> is set then
+B<PKCS7_TEXT> is ignored.
+
+If the B<PKCS7_STREAM> flag is set a partial B<PKCS7> structure is output
+suitable for streaming I/O: no data is read from the BIO B<in>.
+
+=head1 NOTES
+
+If the flag B<PKCS7_STREAM> is set the returned B<PKCS7> structure is B<not>
+complete and outputting its contents via a function that does not
+properly finalize the B<PKCS7> structure will give unpredictable 
+results.
+
+Several functions including SMIME_write_PKCS7(), i2d_PKCS7_bio_stream(),
+PEM_write_bio_PKCS7_stream() finalize the structure. Alternatively finalization
+can be performed by obtaining the streaming ASN1 B<BIO> directly using
+BIO_new_PKCS7().
+
+=head1 RETURN VALUES
+
+PKCS7_encrypt() returns either a PKCS7 structure or NULL if an error occurred.
+The error can be obtained from ERR_get_error(3).
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_decrypt(3)|PKCS7_decrypt(3)>
+
+=head1 HISTORY
+
+PKCS7_decrypt() was added to OpenSSL 0.9.5
+The B<PKCS7_STREAM> flag was first supported in OpenSSL 1.0.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/PKCS7_sign.pod b/deps/openssl/openssl/doc/crypto/PKCS7_sign.pod
new file mode 100644 (file)
index 0000000..64a3514
--- /dev/null
@@ -0,0 +1,116 @@
+=pod
+
+=head1 NAME
+
+PKCS7_sign - create a PKCS#7 signedData structure
+
+=head1 SYNOPSIS
+
+ #include <openssl/pkcs7.h>
+
+ PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, BIO *data, int flags);
+
+=head1 DESCRIPTION
+
+PKCS7_sign() creates and returns a PKCS#7 signedData structure. B<signcert> is
+the certificate to sign with, B<pkey> is the corresponsding private key.
+B<certs> is an optional additional set of certificates to include in the PKCS#7
+structure (for example any intermediate CAs in the chain). 
+
+The data to be signed is read from BIO B<data>.
+
+B<flags> is an optional set of flags.
+
+=head1 NOTES
+
+Any of the following flags (ored together) can be passed in the B<flags>
+parameter.
+
+Many S/MIME clients expect the signed content to include valid MIME headers. If
+the B<PKCS7_TEXT> flag is set MIME headers for type B<text/plain> are prepended
+to the data.
+
+If B<PKCS7_NOCERTS> is set the signer's certificate will not be included in the
+PKCS7 structure, the signer's certificate must still be supplied in the
+B<signcert> parameter though. This can reduce the size of the signature if the
+signers certificate can be obtained by other means: for example a previously
+signed message.
+
+The data being signed is included in the PKCS7 structure, unless
+B<PKCS7_DETACHED> is set in which case it is omitted. This is used for PKCS7
+detached signatures which are used in S/MIME plaintext signed messages for
+example.
+
+Normally the supplied content is translated into MIME canonical format (as
+required by the S/MIME specifications) if B<PKCS7_BINARY> is set no translation
+occurs. This option should be used if the supplied data is in binary format
+otherwise the translation will corrupt it.
+
+The signedData structure includes several PKCS#7 autenticatedAttributes
+including the signing time, the PKCS#7 content type and the supported list of
+ciphers in an SMIMECapabilities attribute. If B<PKCS7_NOATTR> is set then no
+authenticatedAttributes will be used. If B<PKCS7_NOSMIMECAP> is set then just
+the SMIMECapabilities are omitted.
+
+If present the SMIMECapabilities attribute indicates support for the following
+algorithms: triple DES, 128 bit RC2, 64 bit RC2, DES and 40 bit RC2. If any of
+these algorithms is disabled then it will not be included.
+
+If the flags B<PKCS7_STREAM> is set then the returned B<PKCS7> structure is
+just initialized ready to perform the signing operation. The signing is however
+B<not> performed and the data to be signed is not read from the B<data>
+parameter. Signing is deferred until after the data has been written. In this
+way data can be signed in a single pass.
+
+If the B<PKCS7_PARTIAL> flag is set a partial B<PKCS7> structure is output to
+which additional signers and capabilities can be added before finalization.
+
+
+=head1 NOTES
+
+If the flag B<PKCS7_STREAM> is set the returned B<PKCS7> structure is B<not>
+complete and outputting its contents via a function that does not properly
+finalize the B<PKCS7> structure will give unpredictable results.
+
+Several functions including SMIME_write_PKCS7(), i2d_PKCS7_bio_stream(),
+PEM_write_bio_PKCS7_stream() finalize the structure. Alternatively finalization
+can be performed by obtaining the streaming ASN1 B<BIO> directly using
+BIO_new_PKCS7().
+
+If a signer is specified it will use the default digest for the signing
+algorithm. This is B<SHA1> for both RSA and DSA keys.
+
+In OpenSSL 1.0.0 the B<certs>, B<signcert> and B<pkey> parameters can all be
+B<NULL> if the B<PKCS7_PARTIAL> flag is set. One or more signers can be added
+using the function B<PKCS7_sign_add_signer()>. B<PKCS7_final()> must also be
+called to finalize the structure if streaming is not enabled. Alternative
+signing digests can also be specified using this method.
+
+In OpenSSL 1.0.0 if B<signcert> and B<pkey> are NULL then a certificates only
+PKCS#7 structure is output.
+
+In versions of OpenSSL before 1.0.0 the B<signcert> and B<pkey> parameters must
+B<NOT> be NULL.
+
+=head1 BUGS
+
+Some advanced attributes such as counter signatures are not supported.
+
+=head1 RETURN VALUES
+
+PKCS7_sign() returns either a valid PKCS7 structure or NULL if an error
+occurred.  The error can be obtained from ERR_get_error(3).
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_verify(3)|PKCS7_verify(3)>
+
+=head1 HISTORY
+
+PKCS7_sign() was added to OpenSSL 0.9.5
+
+The B<PKCS7_PARTIAL> flag was added in OpenSSL 1.0.0
+
+The B<PKCS7_STREAM> flag was added in OpenSSL 1.0.0
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/PKCS7_sign_add_signer.pod b/deps/openssl/openssl/doc/crypto/PKCS7_sign_add_signer.pod
new file mode 100644 (file)
index 0000000..ebec4d5
--- /dev/null
@@ -0,0 +1,87 @@
+=pod
+
+=head1 NAME
+
+PKCS7_sign_add_signer - add a signer PKCS7 signed data structure.
+
+=head1 SYNOPSIS
+
+ #include <openssl/pkcs7.h>
+
+ PKCS7_SIGNER_INFO *PKCS7_sign_add_signer(PKCS7 *p7, X509 *signcert, EVP_PKEY *pkey, const EVP_MD *md, int flags);
+
+
+=head1 DESCRIPTION
+
+PKCS7_sign_add_signer() adds a signer with certificate B<signcert> and private
+key B<pkey> using message digest B<md> to a PKCS7 signed data structure
+B<p7>.
+
+The PKCS7 structure should be obtained from an initial call to PKCS7_sign()
+with the flag B<PKCS7_PARTIAL> set or in the case or re-signing a valid PKCS7
+signed data structure.
+
+If the B<md> parameter is B<NULL> then the default digest for the public
+key algorithm will be used.
+
+Unless the B<PKCS7_REUSE_DIGEST> flag is set the returned PKCS7 structure
+is not complete and must be finalized either by streaming (if applicable) or
+a call to PKCS7_final().
+
+
+=head1 NOTES
+
+The main purpose of this function is to provide finer control over a PKCS#7
+signed data structure where the simpler PKCS7_sign() function defaults are
+not appropriate. For example if multiple signers or non default digest
+algorithms are needed.
+
+Any of the following flags (ored together) can be passed in the B<flags>
+parameter.
+
+If B<PKCS7_REUSE_DIGEST> is set then an attempt is made to copy the content
+digest value from the PKCS7 struture: to add a signer to an existing structure.
+An error occurs if a matching digest value cannot be found to copy. The
+returned PKCS7 structure will be valid and finalized when this flag is set.
+
+If B<PKCS7_PARTIAL> is set in addition to B<PKCS7_REUSE_DIGEST> then the 
+B<PKCS7_SIGNER_INO> structure will not be finalized so additional attributes
+can be added. In this case an explicit call to PKCS7_SIGNER_INFO_sign() is
+needed to finalize it.
+
+If B<PKCS7_NOCERTS> is set the signer's certificate will not be included in the
+PKCS7 structure, the signer's certificate must still be supplied in the
+B<signcert> parameter though. This can reduce the size of the signature if the
+signers certificate can be obtained by other means: for example a previously
+signed message.
+
+The signedData structure includes several PKCS#7 autenticatedAttributes
+including the signing time, the PKCS#7 content type and the supported list of
+ciphers in an SMIMECapabilities attribute. If B<PKCS7_NOATTR> is set then no
+authenticatedAttributes will be used. If B<PKCS7_NOSMIMECAP> is set then just
+the SMIMECapabilities are omitted.
+
+If present the SMIMECapabilities attribute indicates support for the following
+algorithms: triple DES, 128 bit RC2, 64 bit RC2, DES and 40 bit RC2. If any of
+these algorithms is disabled then it will not be included.
+
+
+PKCS7_sign_add_signers() returns an internal pointer to the PKCS7_SIGNER_INFO
+structure just added, this can be used to set additional attributes 
+before it is finalized.
+
+=head1 RETURN VALUES
+
+PKCS7_sign_add_signers() returns an internal pointer to the PKCS7_SIGNER_INFO
+structure just added or NULL if an error occurs.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_sign(3)|PKCS7_sign(3)>,
+L<PKCS7_final(3)|PKCS7_final(3)>,
+
+=head1 HISTORY
+
+PPKCS7_sign_add_signer() was added to OpenSSL 1.0.0
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/PKCS7_verify.pod b/deps/openssl/openssl/doc/crypto/PKCS7_verify.pod
new file mode 100644 (file)
index 0000000..7c10a4c
--- /dev/null
@@ -0,0 +1,118 @@
+=pod
+
+=head1 NAME
+
+PKCS7_verify - verify a PKCS#7 signedData structure
+
+=head1 SYNOPSIS
+
+ #include <openssl/pkcs7.h>
+
+ int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, BIO *indata, BIO *out, int flags);
+
+ STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags);
+
+=head1 DESCRIPTION
+
+PKCS7_verify() verifies a PKCS#7 signedData structure. B<p7> is the PKCS7
+structure to verify. B<certs> is a set of certificates in which to search for
+the signer's certificate. B<store> is a trusted certficate store (used for
+chain verification). B<indata> is the signed data if the content is not
+present in B<p7> (that is it is detached). The content is written to B<out>
+if it is not NULL.
+
+B<flags> is an optional set of flags, which can be used to modify the verify
+operation.
+
+PKCS7_get0_signers() retrieves the signer's certificates from B<p7>, it does
+B<not> check their validity or whether any signatures are valid. The B<certs>
+and B<flags> parameters have the same meanings as in PKCS7_verify().
+
+=head1 VERIFY PROCESS
+
+Normally the verify process proceeds as follows.
+
+Initially some sanity checks are performed on B<p7>. The type of B<p7> must
+be signedData. There must be at least one signature on the data and if
+the content is detached B<indata> cannot be B<NULL>.
+
+An attempt is made to locate all the signer's certificates, first looking in
+the B<certs> parameter (if it is not B<NULL>) and then looking in any certificates
+contained in the B<p7> structure itself. If any signer's certificates cannot be
+located the operation fails.
+
+Each signer's certificate is chain verified using the B<smimesign> purpose and
+the supplied trusted certificate store. Any internal certificates in the message
+are used as untrusted CAs. If any chain verify fails an error code is returned.
+
+Finally the signed content is read (and written to B<out> is it is not NULL) and
+the signature's checked.
+
+If all signature's verify correctly then the function is successful.
+
+Any of the following flags (ored together) can be passed in the B<flags> parameter
+to change the default verify behaviour. Only the flag B<PKCS7_NOINTERN> is
+meaningful to PKCS7_get0_signers().
+
+If B<PKCS7_NOINTERN> is set the certificates in the message itself are not 
+searched when locating the signer's certificate. This means that all the signers
+certificates must be in the B<certs> parameter.
+
+If the B<PKCS7_TEXT> flag is set MIME headers for type B<text/plain> are deleted
+from the content. If the content is not of type B<text/plain> then an error is
+returned.
+
+If B<PKCS7_NOVERIFY> is set the signer's certificates are not chain verified.
+
+If B<PKCS7_NOCHAIN> is set then the certificates contained in the message are
+not used as untrusted CAs. This means that the whole verify chain (apart from
+the signer's certificate) must be contained in the trusted store.
+
+If B<PKCS7_NOSIGS> is set then the signatures on the data are not checked.
+
+=head1 NOTES
+
+One application of B<PKCS7_NOINTERN> is to only accept messages signed by
+a small number of certificates. The acceptable certificates would be passed
+in the B<certs> parameter. In this case if the signer is not one of the
+certificates supplied in B<certs> then the verify will fail because the
+signer cannot be found.
+
+Care should be taken when modifying the default verify behaviour, for example
+setting B<PKCS7_NOVERIFY|PKCS7_NOSIGS> will totally disable all verification 
+and any signed message will be considered valid. This combination is however
+useful if one merely wishes to write the content to B<out> and its validity
+is not considered important.
+
+Chain verification should arguably be performed  using the signing time rather
+than the current time. However since the signing time is supplied by the
+signer it cannot be trusted without additional evidence (such as a trusted
+timestamp).
+
+=head1 RETURN VALUES
+
+PKCS7_verify() returns 1 for a successful verification and zero or a negative
+value if an error occurs.
+
+PKCS7_get0_signers() returns all signers or B<NULL> if an error occurred.
+
+The error can be obtained from L<ERR_get_error(3)|ERR_get_error(3)>
+
+=head1 BUGS
+
+The trusted certificate store is not searched for the signers certificate,
+this is primarily due to the inadequacies of the current B<X509_STORE>
+functionality.
+
+The lack of single pass processing and need to hold all data in memory as
+mentioned in PKCS7_sign() also applies to PKCS7_verify().
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_sign(3)|PKCS7_sign(3)>
+
+=head1 HISTORY
+
+PKCS7_verify() was added to OpenSSL 0.9.5
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/RAND_add.pod b/deps/openssl/openssl/doc/crypto/RAND_add.pod
new file mode 100644 (file)
index 0000000..67c66f3
--- /dev/null
@@ -0,0 +1,77 @@
+=pod
+
+=head1 NAME
+
+RAND_add, RAND_seed, RAND_status, RAND_event, RAND_screen - add
+entropy to the PRNG
+
+=head1 SYNOPSIS
+
+ #include <openssl/rand.h>
+
+ void RAND_seed(const void *buf, int num);
+
+ void RAND_add(const void *buf, int num, double entropy);
+
+ int  RAND_status(void);
+
+ int  RAND_event(UINT iMsg, WPARAM wParam, LPARAM lParam);
+ void RAND_screen(void);
+
+=head1 DESCRIPTION
+
+RAND_add() mixes the B<num> bytes at B<buf> into the PRNG state. Thus,
+if the data at B<buf> are unpredictable to an adversary, this
+increases the uncertainty about the state and makes the PRNG output
+less predictable. Suitable input comes from user interaction (random
+key presses, mouse movements) and certain hardware events. The
+B<entropy> argument is (the lower bound of) an estimate of how much
+randomness is contained in B<buf>, measured in bytes. Details about
+sources of randomness and how to estimate their entropy can be found
+in the literature, e.g. RFC 1750.
+
+RAND_add() may be called with sensitive data such as user entered
+passwords. The seed values cannot be recovered from the PRNG output.
+
+OpenSSL makes sure that the PRNG state is unique for each thread. On
+systems that provide C</dev/urandom>, the randomness device is used
+to seed the PRNG transparently. However, on all other systems, the
+application is responsible for seeding the PRNG by calling RAND_add(),
+L<RAND_egd(3)|RAND_egd(3)>
+or L<RAND_load_file(3)|RAND_load_file(3)>.
+
+RAND_seed() is equivalent to RAND_add() when B<num == entropy>.
+
+RAND_event() collects the entropy from Windows events such as mouse
+movements and other user interaction. It should be called with the
+B<iMsg>, B<wParam> and B<lParam> arguments of I<all> messages sent to
+the window procedure. It will estimate the entropy contained in the
+event message (if any), and add it to the PRNG. The program can then
+process the messages as usual.
+
+The RAND_screen() function is available for the convenience of Windows
+programmers. It adds the current contents of the screen to the PRNG.
+For applications that can catch Windows events, seeding the PRNG by
+calling RAND_event() is a significantly better source of
+randomness. It should be noted that both methods cannot be used on
+servers that run without user interaction.
+
+=head1 RETURN VALUES
+
+RAND_status() and RAND_event() return 1 if the PRNG has been seeded
+with enough data, 0 otherwise.
+
+The other functions do not return values.
+
+=head1 SEE ALSO
+
+L<rand(3)|rand(3)>, L<RAND_egd(3)|RAND_egd(3)>,
+L<RAND_load_file(3)|RAND_load_file(3)>, L<RAND_cleanup(3)|RAND_cleanup(3)>
+
+=head1 HISTORY
+
+RAND_seed() and RAND_screen() are available in all versions of SSLeay
+and OpenSSL. RAND_add() and RAND_status() have been added in OpenSSL
+0.9.5, RAND_event() in OpenSSL 0.9.5a.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/RAND_bytes.pod b/deps/openssl/openssl/doc/crypto/RAND_bytes.pod
new file mode 100644 (file)
index 0000000..1a9b91e
--- /dev/null
@@ -0,0 +1,50 @@
+=pod
+
+=head1 NAME
+
+RAND_bytes, RAND_pseudo_bytes - generate random data
+
+=head1 SYNOPSIS
+
+ #include <openssl/rand.h>
+
+ int RAND_bytes(unsigned char *buf, int num);
+
+ int RAND_pseudo_bytes(unsigned char *buf, int num);
+
+=head1 DESCRIPTION
+
+RAND_bytes() puts B<num> cryptographically strong pseudo-random bytes
+into B<buf>. An error occurs if the PRNG has not been seeded with
+enough randomness to ensure an unpredictable byte sequence.
+
+RAND_pseudo_bytes() puts B<num> pseudo-random bytes into B<buf>.
+Pseudo-random byte sequences generated by RAND_pseudo_bytes() will be
+unique if they are of sufficient length, but are not necessarily
+unpredictable. They can be used for non-cryptographic purposes and for
+certain purposes in cryptographic protocols, but usually not for key
+generation etc.
+
+The contents of B<buf> is mixed into the entropy pool before retrieving
+the new pseudo-random bytes unless disabled at compile time (see FAQ).
+
+=head1 RETURN VALUES
+
+RAND_bytes() returns 1 on success, 0 otherwise. The error code can be
+obtained by L<ERR_get_error(3)|ERR_get_error(3)>. RAND_pseudo_bytes() returns 1 if the
+bytes generated are cryptographically strong, 0 otherwise. Both
+functions return -1 if they are not supported by the current RAND
+method.
+
+=head1 SEE ALSO
+
+L<rand(3)|rand(3)>, L<ERR_get_error(3)|ERR_get_error(3)>,
+L<RAND_add(3)|RAND_add(3)>
+
+=head1 HISTORY
+
+RAND_bytes() is available in all versions of SSLeay and OpenSSL.  It
+has a return value since OpenSSL 0.9.5. RAND_pseudo_bytes() was added
+in OpenSSL 0.9.5.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/RAND_cleanup.pod b/deps/openssl/openssl/doc/crypto/RAND_cleanup.pod
new file mode 100644 (file)
index 0000000..3a8f074
--- /dev/null
@@ -0,0 +1,29 @@
+=pod
+
+=head1 NAME
+
+RAND_cleanup - erase the PRNG state
+
+=head1 SYNOPSIS
+
+ #include <openssl/rand.h>
+
+ void RAND_cleanup(void);
+
+=head1 DESCRIPTION
+
+RAND_cleanup() erases the memory used by the PRNG.
+
+=head1 RETURN VALUE
+
+RAND_cleanup() returns no value.
+
+=head1 SEE ALSO
+
+L<rand(3)|rand(3)>
+
+=head1 HISTORY
+
+RAND_cleanup() is available in all versions of SSLeay and OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/RAND_egd.pod b/deps/openssl/openssl/doc/crypto/RAND_egd.pod
new file mode 100644 (file)
index 0000000..8b8c61d
--- /dev/null
@@ -0,0 +1,88 @@
+=pod
+
+=head1 NAME
+
+RAND_egd - query entropy gathering daemon
+
+=head1 SYNOPSIS
+
+ #include <openssl/rand.h>
+
+ int RAND_egd(const char *path);
+ int RAND_egd_bytes(const char *path, int bytes);
+
+ int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes);
+
+=head1 DESCRIPTION
+
+RAND_egd() queries the entropy gathering daemon EGD on socket B<path>.
+It queries 255 bytes and uses L<RAND_add(3)|RAND_add(3)> to seed the
+OpenSSL built-in PRNG. RAND_egd(path) is a wrapper for
+RAND_egd_bytes(path, 255);
+
+RAND_egd_bytes() queries the entropy gathering daemon EGD on socket B<path>.
+It queries B<bytes> bytes and uses L<RAND_add(3)|RAND_add(3)> to seed the
+OpenSSL built-in PRNG.
+This function is more flexible than RAND_egd().
+When only one secret key must
+be generated, it is not necessary to request the full amount 255 bytes from
+the EGD socket. This can be advantageous, since the amount of entropy
+that can be retrieved from EGD over time is limited.
+
+RAND_query_egd_bytes() performs the actual query of the EGD daemon on socket
+B<path>. If B<buf> is given, B<bytes> bytes are queried and written into
+B<buf>. If B<buf> is NULL, B<bytes> bytes are queried and used to seed the
+OpenSSL built-in PRNG using L<RAND_add(3)|RAND_add(3)>.
+
+=head1 NOTES
+
+On systems without /dev/*random devices providing entropy from the kernel,
+the EGD entropy gathering daemon can be used to collect entropy. It provides
+a socket interface through which entropy can be gathered in chunks up to
+255 bytes. Several chunks can be queried during one connection.
+
+EGD is available from http://www.lothar.com/tech/crypto/ (C<perl
+Makefile.PL; make; make install> to install). It is run as B<egd>
+I<path>, where I<path> is an absolute path designating a socket. When
+RAND_egd() is called with that path as an argument, it tries to read
+random bytes that EGD has collected. RAND_egd() retrieves entropy from the
+daemon using the daemon's "non-blocking read" command which shall
+be answered immediately by the daemon without waiting for additional
+entropy to be collected. The write and read socket operations in the
+communication are blocking.
+
+Alternatively, the EGD-interface compatible daemon PRNGD can be used. It is
+available from
+http://prngd.sourceforge.net/ .
+PRNGD does employ an internal PRNG itself and can therefore never run
+out of entropy.
+
+OpenSSL automatically queries EGD when entropy is requested via RAND_bytes()
+or the status is checked via RAND_status() for the first time, if the socket
+is located at /var/run/egd-pool, /dev/egd-pool or /etc/egd-pool.
+
+=head1 RETURN VALUE
+
+RAND_egd() and RAND_egd_bytes() return the number of bytes read from the
+daemon on success, and -1 if the connection failed or the daemon did not
+return enough data to fully seed the PRNG.
+
+RAND_query_egd_bytes() returns the number of bytes read from the daemon on
+success, and -1 if the connection failed. The PRNG state is not considered.
+
+=head1 SEE ALSO
+
+L<rand(3)|rand(3)>, L<RAND_add(3)|RAND_add(3)>,
+L<RAND_cleanup(3)|RAND_cleanup(3)>
+
+=head1 HISTORY
+
+RAND_egd() is available since OpenSSL 0.9.5.
+
+RAND_egd_bytes() is available since OpenSSL 0.9.6.
+
+RAND_query_egd_bytes() is available since OpenSSL 0.9.7.
+
+The automatic query of /var/run/egd-pool et al was added in OpenSSL 0.9.7.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/RAND_load_file.pod b/deps/openssl/openssl/doc/crypto/RAND_load_file.pod
new file mode 100644 (file)
index 0000000..d8c134e
--- /dev/null
@@ -0,0 +1,53 @@
+=pod
+
+=head1 NAME
+
+RAND_load_file, RAND_write_file, RAND_file_name - PRNG seed file
+
+=head1 SYNOPSIS
+
+ #include <openssl/rand.h>
+
+ const char *RAND_file_name(char *buf, size_t num);
+
+ int RAND_load_file(const char *filename, long max_bytes);
+
+ int RAND_write_file(const char *filename);
+
+=head1 DESCRIPTION
+
+RAND_file_name() generates a default path for the random seed
+file. B<buf> points to a buffer of size B<num> in which to store the
+filename. The seed file is $RANDFILE if that environment variable is
+set, $HOME/.rnd otherwise. If $HOME is not set either, or B<num> is
+too small for the path name, an error occurs.
+
+RAND_load_file() reads a number of bytes from file B<filename> and
+adds them to the PRNG. If B<max_bytes> is non-negative,
+up to to B<max_bytes> are read; starting with OpenSSL 0.9.5,
+if B<max_bytes> is -1, the complete file is read.
+
+RAND_write_file() writes a number of random bytes (currently 1024) to
+file B<filename> which can be used to initialize the PRNG by calling
+RAND_load_file() in a later session.
+
+=head1 RETURN VALUES
+
+RAND_load_file() returns the number of bytes read.
+
+RAND_write_file() returns the number of bytes written, and -1 if the
+bytes written were generated without appropriate seed.
+
+RAND_file_name() returns a pointer to B<buf> on success, and NULL on
+error.
+
+=head1 SEE ALSO
+
+L<rand(3)|rand(3)>, L<RAND_add(3)|RAND_add(3)>, L<RAND_cleanup(3)|RAND_cleanup(3)>
+
+=head1 HISTORY
+
+RAND_load_file(), RAND_write_file() and RAND_file_name() are available in
+all versions of SSLeay and OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/RAND_set_rand_method.pod b/deps/openssl/openssl/doc/crypto/RAND_set_rand_method.pod
new file mode 100644 (file)
index 0000000..e5b780f
--- /dev/null
@@ -0,0 +1,83 @@
+=pod
+
+=head1 NAME
+
+RAND_set_rand_method, RAND_get_rand_method, RAND_SSLeay - select RAND method
+
+=head1 SYNOPSIS
+
+ #include <openssl/rand.h>
+
+ void RAND_set_rand_method(const RAND_METHOD *meth);
+
+ const RAND_METHOD *RAND_get_rand_method(void);
+
+ RAND_METHOD *RAND_SSLeay(void);
+
+=head1 DESCRIPTION
+
+A B<RAND_METHOD> specifies the functions that OpenSSL uses for random number
+generation. By modifying the method, alternative implementations such as
+hardware RNGs may be used. IMPORTANT: See the NOTES section for important
+information about how these RAND API functions are affected by the use of
+B<ENGINE> API calls.
+
+Initially, the default RAND_METHOD is the OpenSSL internal implementation, as
+returned by RAND_SSLeay().
+
+RAND_set_default_method() makes B<meth> the method for PRNG use. B<NB>: This is
+true only whilst no ENGINE has been set as a default for RAND, so this function
+is no longer recommended.
+
+RAND_get_default_method() returns a pointer to the current RAND_METHOD.
+However, the meaningfulness of this result is dependent on whether the ENGINE
+API is being used, so this function is no longer recommended.
+
+=head1 THE RAND_METHOD STRUCTURE
+
+ typedef struct rand_meth_st
+ {
+        void (*seed)(const void *buf, int num);
+        int (*bytes)(unsigned char *buf, int num);
+        void (*cleanup)(void);
+        void (*add)(const void *buf, int num, int entropy);
+        int (*pseudorand)(unsigned char *buf, int num);
+       int (*status)(void);
+ } RAND_METHOD;
+
+The components point to the implementation of RAND_seed(),
+RAND_bytes(), RAND_cleanup(), RAND_add(), RAND_pseudo_rand()
+and RAND_status().
+Each component may be NULL if the function is not implemented.
+
+=head1 RETURN VALUES
+
+RAND_set_rand_method() returns no value. RAND_get_rand_method() and
+RAND_SSLeay() return pointers to the respective methods.
+
+=head1 NOTES
+
+As of version 0.9.7, RAND_METHOD implementations are grouped together with other
+algorithmic APIs (eg. RSA_METHOD, EVP_CIPHER, etc) in B<ENGINE> modules. If a
+default ENGINE is specified for RAND functionality using an ENGINE API function,
+that will override any RAND defaults set using the RAND API (ie.
+RAND_set_rand_method()). For this reason, the ENGINE API is the recommended way
+to control default implementations for use in RAND and other cryptographic
+algorithms.
+
+=head1 SEE ALSO
+
+L<rand(3)|rand(3)>, L<engine(3)|engine(3)>
+
+=head1 HISTORY
+
+RAND_set_rand_method(), RAND_get_rand_method() and RAND_SSLeay() are
+available in all versions of OpenSSL.
+
+In the engine version of version 0.9.6, RAND_set_rand_method() was altered to
+take an ENGINE pointer as its argument. As of version 0.9.7, that has been
+reverted as the ENGINE API transparently overrides RAND defaults if used,
+otherwise RAND API functions work as before. RAND_set_rand_engine() was also
+introduced in version 0.9.7.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/RSA_blinding_on.pod b/deps/openssl/openssl/doc/crypto/RSA_blinding_on.pod
new file mode 100644 (file)
index 0000000..fd2c69a
--- /dev/null
@@ -0,0 +1,43 @@
+=pod
+
+=head1 NAME
+
+RSA_blinding_on, RSA_blinding_off - protect the RSA operation from timing attacks
+
+=head1 SYNOPSIS
+
+ #include <openssl/rsa.h>
+
+ int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
+
+ void RSA_blinding_off(RSA *rsa);
+
+=head1 DESCRIPTION
+
+RSA is vulnerable to timing attacks. In a setup where attackers can
+measure the time of RSA decryption or signature operations, blinding
+must be used to protect the RSA operation from that attack.
+
+RSA_blinding_on() turns blinding on for key B<rsa> and generates a
+random blinding factor. B<ctx> is B<NULL> or a pre-allocated and
+initialized B<BN_CTX>. The random number generator must be seeded
+prior to calling RSA_blinding_on().
+
+RSA_blinding_off() turns blinding off and frees the memory used for
+the blinding factor.
+
+=head1 RETURN VALUES
+
+RSA_blinding_on() returns 1 on success, and 0 if an error occurred.
+
+RSA_blinding_off() returns no value.
+
+=head1 SEE ALSO
+
+L<rsa(3)|rsa(3)>, L<rand(3)|rand(3)>
+
+=head1 HISTORY
+
+RSA_blinding_on() and RSA_blinding_off() appeared in SSLeay 0.9.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/RSA_check_key.pod b/deps/openssl/openssl/doc/crypto/RSA_check_key.pod
new file mode 100644 (file)
index 0000000..a5198f3
--- /dev/null
@@ -0,0 +1,67 @@
+=pod
+
+=head1 NAME
+
+RSA_check_key - validate private RSA keys
+
+=head1 SYNOPSIS
+
+ #include <openssl/rsa.h>
+
+ int RSA_check_key(RSA *rsa);
+
+=head1 DESCRIPTION
+
+This function validates RSA keys. It checks that B<p> and B<q> are
+in fact prime, and that B<n = p*q>.
+
+It also checks that B<d*e = 1 mod (p-1*q-1)>,
+and that B<dmp1>, B<dmq1> and B<iqmp> are set correctly or are B<NULL>.
+
+As such, this function can not be used with any arbitrary RSA key object,
+even if it is otherwise fit for regular RSA operation. See B<NOTES> for more
+information.
+
+=head1 RETURN VALUE
+
+RSA_check_key() returns 1 if B<rsa> is a valid RSA key, and 0 otherwise.
+-1 is returned if an error occurs while checking the key.
+
+If the key is invalid or an error occurred, the reason code can be
+obtained using L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 NOTES
+
+This function does not work on RSA public keys that have only the modulus
+and public exponent elements populated. It performs integrity checks on all
+the RSA key material, so the RSA key structure must contain all the private
+key data too.
+
+Unlike most other RSA functions, this function does B<not> work
+transparently with any underlying ENGINE implementation because it uses the
+key data in the RSA structure directly. An ENGINE implementation can
+override the way key data is stored and handled, and can even provide
+support for HSM keys - in which case the RSA structure may contain B<no>
+key data at all! If the ENGINE in question is only being used for
+acceleration or analysis purposes, then in all likelihood the RSA key data
+is complete and untouched, but this can't be assumed in the general case.
+
+=head1 BUGS
+
+A method of verifying the RSA key using opaque RSA API functions might need
+to be considered. Right now RSA_check_key() simply uses the RSA structure
+elements directly, bypassing the RSA_METHOD table altogether (and
+completely violating encapsulation and object-orientation in the process).
+The best fix will probably be to introduce a "check_key()" handler to the
+RSA_METHOD function table so that alternative implementations can also
+provide their own verifiers.
+
+=head1 SEE ALSO
+
+L<rsa(3)|rsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>
+
+=head1 HISTORY
+
+RSA_check_key() appeared in OpenSSL 0.9.4.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/RSA_generate_key.pod b/deps/openssl/openssl/doc/crypto/RSA_generate_key.pod
new file mode 100644 (file)
index 0000000..52dbb14
--- /dev/null
@@ -0,0 +1,69 @@
+=pod
+
+=head1 NAME
+
+RSA_generate_key - generate RSA key pair
+
+=head1 SYNOPSIS
+
+ #include <openssl/rsa.h>
+
+ RSA *RSA_generate_key(int num, unsigned long e,
+    void (*callback)(int,int,void *), void *cb_arg);
+
+=head1 DESCRIPTION
+
+RSA_generate_key() generates a key pair and returns it in a newly
+allocated B<RSA> structure. The pseudo-random number generator must
+be seeded prior to calling RSA_generate_key().
+
+The modulus size will be B<num> bits, and the public exponent will be
+B<e>. Key sizes with B<num> E<lt> 1024 should be considered insecure.
+The exponent is an odd number, typically 3, 17 or 65537.
+
+A callback function may be used to provide feedback about the
+progress of the key generation. If B<callback> is not B<NULL>, it
+will be called as follows:
+
+=over 4
+
+=item *
+
+While a random prime number is generated, it is called as
+described in L<BN_generate_prime(3)|BN_generate_prime(3)>.
+
+=item *
+
+When the n-th randomly generated prime is rejected as not
+suitable for the key, B<callback(2, n, cb_arg)> is called.
+
+=item *
+
+When a random p has been found with p-1 relatively prime to B<e>,
+it is called as B<callback(3, 0, cb_arg)>.
+
+=back
+
+The process is then repeated for prime q with B<callback(3, 1, cb_arg)>.
+
+=head1 RETURN VALUE
+
+If key generation fails, RSA_generate_key() returns B<NULL>; the
+error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 BUGS
+
+B<callback(2, x, cb_arg)> is used with two different meanings.
+
+RSA_generate_key() goes into an infinite loop for illegal input values.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>,
+L<RSA_free(3)|RSA_free(3)>
+
+=head1 HISTORY
+
+The B<cb_arg> argument was added in SSLeay 0.9.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/RSA_get_ex_new_index.pod b/deps/openssl/openssl/doc/crypto/RSA_get_ex_new_index.pod
new file mode 100644 (file)
index 0000000..7d0fd1f
--- /dev/null
@@ -0,0 +1,120 @@
+=pod
+
+=head1 NAME
+
+RSA_get_ex_new_index, RSA_set_ex_data, RSA_get_ex_data - add application specific data to RSA structures
+
+=head1 SYNOPSIS
+
+ #include <openssl/rsa.h>
+
+ int RSA_get_ex_new_index(long argl, void *argp,
+               CRYPTO_EX_new *new_func,
+               CRYPTO_EX_dup *dup_func,
+               CRYPTO_EX_free *free_func);
+
+ int RSA_set_ex_data(RSA *r, int idx, void *arg);
+
+ void *RSA_get_ex_data(RSA *r, int idx);
+
+ typedef int CRYPTO_EX_new(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
+                           int idx, long argl, void *argp);
+ typedef void CRYPTO_EX_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
+                             int idx, long argl, void *argp);
+ typedef int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d,
+                           int idx, long argl, void *argp);
+
+=head1 DESCRIPTION
+
+Several OpenSSL structures can have application specific data attached to them.
+This has several potential uses, it can be used to cache data associated with
+a structure (for example the hash of some part of the structure) or some
+additional data (for example a handle to the data in an external library).
+
+Since the application data can be anything at all it is passed and retrieved
+as a B<void *> type.
+
+The B<RSA_get_ex_new_index()> function is initially called to "register" some
+new application specific data. It takes three optional function pointers which
+are called when the parent structure (in this case an RSA structure) is
+initially created, when it is copied and when it is freed up. If any or all of
+these function pointer arguments are not used they should be set to NULL. The
+precise manner in which these function pointers are called is described in more
+detail below. B<RSA_get_ex_new_index()> also takes additional long and pointer
+parameters which will be passed to the supplied functions but which otherwise
+have no special meaning. It returns an B<index> which should be stored
+(typically in a static variable) and passed used in the B<idx> parameter in
+the remaining functions. Each successful call to B<RSA_get_ex_new_index()>
+will return an index greater than any previously returned, this is important
+because the optional functions are called in order of increasing index value.
+
+B<RSA_set_ex_data()> is used to set application specific data, the data is
+supplied in the B<arg> parameter and its precise meaning is up to the
+application.
+
+B<RSA_get_ex_data()> is used to retrieve application specific data. The data
+is returned to the application, this will be the same value as supplied to
+a previous B<RSA_set_ex_data()> call.
+
+B<new_func()> is called when a structure is initially allocated (for example
+with B<RSA_new()>. The parent structure members will not have any meaningful
+values at this point. This function will typically be used to allocate any
+application specific structure.
+
+B<free_func()> is called when a structure is being freed up. The dynamic parent
+structure members should not be accessed because they will be freed up when
+this function is called.
+
+B<new_func()> and B<free_func()> take the same parameters. B<parent> is a
+pointer to the parent RSA structure. B<ptr> is a the application specific data
+(this wont be of much use in B<new_func()>. B<ad> is a pointer to the
+B<CRYPTO_EX_DATA> structure from the parent RSA structure: the functions
+B<CRYPTO_get_ex_data()> and B<CRYPTO_set_ex_data()> can be called to manipulate
+it. The B<idx> parameter is the index: this will be the same value returned by
+B<RSA_get_ex_new_index()> when the functions were initially registered. Finally
+the B<argl> and B<argp> parameters are the values originally passed to the same
+corresponding parameters when B<RSA_get_ex_new_index()> was called.
+
+B<dup_func()> is called when a structure is being copied. Pointers to the
+destination and source B<CRYPTO_EX_DATA> structures are passed in the B<to> and
+B<from> parameters respectively. The B<from_d> parameter is passed a pointer to
+the source application data when the function is called, when the function returns
+the value is copied to the destination: the application can thus modify the data
+pointed to by B<from_d> and have different values in the source and destination.
+The B<idx>, B<argl> and B<argp> parameters are the same as those in B<new_func()>
+and B<free_func()>.
+
+=head1 RETURN VALUES
+
+B<RSA_get_ex_new_index()> returns a new index or -1 on failure (note 0 is a valid
+index value).
+
+B<RSA_set_ex_data()> returns 1 on success or 0 on failure.
+
+B<RSA_get_ex_data()> returns the application data or 0 on failure. 0 may also
+be valid application data but currently it can only fail if given an invalid B<idx>
+parameter.
+
+B<new_func()> and B<dup_func()> should return 0 for failure and 1 for success.
+
+On failure an error code can be obtained from L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 BUGS
+
+B<dup_func()> is currently never called.
+
+The return value of B<new_func()> is ignored.
+
+The B<new_func()> function isn't very useful because no meaningful values are
+present in the parent RSA structure when it is called.
+
+=head1 SEE ALSO
+
+L<rsa(3)|rsa(3)>, L<CRYPTO_set_ex_data(3)|CRYPTO_set_ex_data(3)>
+
+=head1 HISTORY
+
+RSA_get_ex_new_index(), RSA_set_ex_data() and RSA_get_ex_data() are
+available since SSLeay 0.9.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/RSA_new.pod b/deps/openssl/openssl/doc/crypto/RSA_new.pod
new file mode 100644 (file)
index 0000000..3d15b92
--- /dev/null
@@ -0,0 +1,41 @@
+=pod
+
+=head1 NAME
+
+RSA_new, RSA_free - allocate and free RSA objects
+
+=head1 SYNOPSIS
+
+ #include <openssl/rsa.h>
+
+ RSA * RSA_new(void);
+
+ void RSA_free(RSA *rsa);
+
+=head1 DESCRIPTION
+
+RSA_new() allocates and initializes an B<RSA> structure. It is equivalent to
+calling RSA_new_method(NULL).
+
+RSA_free() frees the B<RSA> structure and its components. The key is
+erased before the memory is returned to the system.
+
+=head1 RETURN VALUES
+
+If the allocation fails, RSA_new() returns B<NULL> and sets an error
+code that can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>. Otherwise it returns
+a pointer to the newly allocated structure.
+
+RSA_free() returns no value.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<rsa(3)|rsa(3)>,
+L<RSA_generate_key(3)|RSA_generate_key(3)>,
+L<RSA_new_method(3)|RSA_new_method(3)>
+
+=head1 HISTORY
+
+RSA_new() and RSA_free() are available in all versions of SSLeay and OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/RSA_padding_add_PKCS1_type_1.pod b/deps/openssl/openssl/doc/crypto/RSA_padding_add_PKCS1_type_1.pod
new file mode 100644 (file)
index 0000000..b8f678f
--- /dev/null
@@ -0,0 +1,124 @@
+=pod
+
+=head1 NAME
+
+RSA_padding_add_PKCS1_type_1, RSA_padding_check_PKCS1_type_1,
+RSA_padding_add_PKCS1_type_2, RSA_padding_check_PKCS1_type_2,
+RSA_padding_add_PKCS1_OAEP, RSA_padding_check_PKCS1_OAEP,
+RSA_padding_add_SSLv23, RSA_padding_check_SSLv23,
+RSA_padding_add_none, RSA_padding_check_none - asymmetric encryption
+padding
+
+=head1 SYNOPSIS
+
+ #include <openssl/rsa.h>
+
+ int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
+    unsigned char *f, int fl);
+
+ int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
+    unsigned char *f, int fl, int rsa_len);
+
+ int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
+    unsigned char *f, int fl);
+
+ int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
+    unsigned char *f, int fl, int rsa_len);
+
+ int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
+    unsigned char *f, int fl, unsigned char *p, int pl);
+
+ int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
+    unsigned char *f, int fl, int rsa_len, unsigned char *p, int pl);
+
+ int RSA_padding_add_SSLv23(unsigned char *to, int tlen,
+    unsigned char *f, int fl);
+
+ int RSA_padding_check_SSLv23(unsigned char *to, int tlen,
+    unsigned char *f, int fl, int rsa_len);
+
+ int RSA_padding_add_none(unsigned char *to, int tlen,
+    unsigned char *f, int fl);
+
+ int RSA_padding_check_none(unsigned char *to, int tlen,
+    unsigned char *f, int fl, int rsa_len);
+
+=head1 DESCRIPTION
+
+The RSA_padding_xxx_xxx() functions are called from the RSA encrypt,
+decrypt, sign and verify functions. Normally they should not be called
+from application programs.
+
+However, they can also be called directly to implement padding for other
+asymmetric ciphers. RSA_padding_add_PKCS1_OAEP() and
+RSA_padding_check_PKCS1_OAEP() may be used in an application combined
+with B<RSA_NO_PADDING> in order to implement OAEP with an encoding
+parameter.
+
+RSA_padding_add_xxx() encodes B<fl> bytes from B<f> so as to fit into
+B<tlen> bytes and stores the result at B<to>. An error occurs if B<fl>
+does not meet the size requirements of the encoding method.
+
+The following encoding methods are implemented:
+
+=over 4
+
+=item PKCS1_type_1
+
+PKCS #1 v2.0 EMSA-PKCS1-v1_5 (PKCS #1 v1.5 block type 1); used for signatures
+
+=item PKCS1_type_2
+
+PKCS #1 v2.0 EME-PKCS1-v1_5 (PKCS #1 v1.5 block type 2)
+
+=item PKCS1_OAEP
+
+PKCS #1 v2.0 EME-OAEP
+
+=item SSLv23
+
+PKCS #1 EME-PKCS1-v1_5 with SSL-specific modification
+
+=item none
+
+simply copy the data
+
+=back
+
+The random number generator must be seeded prior to calling
+RSA_padding_add_xxx().
+
+RSA_padding_check_xxx() verifies that the B<fl> bytes at B<f> contain
+a valid encoding for a B<rsa_len> byte RSA key in the respective
+encoding method and stores the recovered data of at most B<tlen> bytes
+(for B<RSA_NO_PADDING>: of size B<tlen>)
+at B<to>.
+
+For RSA_padding_xxx_OAEP(), B<p> points to the encoding parameter
+of length B<pl>. B<p> may be B<NULL> if B<pl> is 0.
+
+=head1 RETURN VALUES
+
+The RSA_padding_add_xxx() functions return 1 on success, 0 on error.
+The RSA_padding_check_xxx() functions return the length of the
+recovered data, -1 on error. Error codes can be obtained by calling
+L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 SEE ALSO
+
+L<RSA_public_encrypt(3)|RSA_public_encrypt(3)>,
+L<RSA_private_decrypt(3)|RSA_private_decrypt(3)>,
+L<RSA_sign(3)|RSA_sign(3)>, L<RSA_verify(3)|RSA_verify(3)>
+
+=head1 HISTORY
+
+RSA_padding_add_PKCS1_type_1(), RSA_padding_check_PKCS1_type_1(),
+RSA_padding_add_PKCS1_type_2(), RSA_padding_check_PKCS1_type_2(),
+RSA_padding_add_SSLv23(), RSA_padding_check_SSLv23(),
+RSA_padding_add_none() and RSA_padding_check_none() appeared in
+SSLeay 0.9.0.
+
+RSA_padding_add_PKCS1_OAEP() and RSA_padding_check_PKCS1_OAEP() were
+added in OpenSSL 0.9.2b.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/RSA_print.pod b/deps/openssl/openssl/doc/crypto/RSA_print.pod
new file mode 100644 (file)
index 0000000..c971e91
--- /dev/null
@@ -0,0 +1,49 @@
+=pod
+
+=head1 NAME
+
+RSA_print, RSA_print_fp,
+DSAparams_print, DSAparams_print_fp, DSA_print, DSA_print_fp,
+DHparams_print, DHparams_print_fp - print cryptographic parameters
+
+=head1 SYNOPSIS
+
+ #include <openssl/rsa.h>
+
+ int RSA_print(BIO *bp, RSA *x, int offset);
+ int RSA_print_fp(FILE *fp, RSA *x, int offset);
+
+ #include <openssl/dsa.h>
+
+ int DSAparams_print(BIO *bp, DSA *x);
+ int DSAparams_print_fp(FILE *fp, DSA *x);
+ int DSA_print(BIO *bp, DSA *x, int offset);
+ int DSA_print_fp(FILE *fp, DSA *x, int offset);
+
+ #include <openssl/dh.h>
+
+ int DHparams_print(BIO *bp, DH *x);
+ int DHparams_print_fp(FILE *fp, DH *x);
+
+=head1 DESCRIPTION
+
+A human-readable hexadecimal output of the components of the RSA
+key, DSA parameters or key or DH parameters is printed to B<bp> or B<fp>.
+
+The output lines are indented by B<offset> spaces.
+
+=head1 RETURN VALUES
+
+These functions return 1 on success, 0 on error.
+
+=head1 SEE ALSO
+
+L<dh(3)|dh(3)>, L<dsa(3)|dsa(3)>, L<rsa(3)|rsa(3)>, L<BN_bn2bin(3)|BN_bn2bin(3)>
+
+=head1 HISTORY
+
+RSA_print(), RSA_print_fp(), DSA_print(), DSA_print_fp(), DH_print(),
+DH_print_fp() are available in all versions of SSLeay and OpenSSL.
+DSAparams_print() and DSAparams_print_fp() were added in SSLeay 0.8.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/RSA_private_encrypt.pod b/deps/openssl/openssl/doc/crypto/RSA_private_encrypt.pod
new file mode 100644 (file)
index 0000000..746a80c
--- /dev/null
@@ -0,0 +1,70 @@
+=pod
+
+=head1 NAME
+
+RSA_private_encrypt, RSA_public_decrypt - low level signature operations
+
+=head1 SYNOPSIS
+
+ #include <openssl/rsa.h>
+
+ int RSA_private_encrypt(int flen, unsigned char *from,
+    unsigned char *to, RSA *rsa, int padding);
+
+ int RSA_public_decrypt(int flen, unsigned char *from, 
+    unsigned char *to, RSA *rsa, int padding);
+
+=head1 DESCRIPTION
+
+These functions handle RSA signatures at a low level.
+
+RSA_private_encrypt() signs the B<flen> bytes at B<from> (usually a
+message digest with an algorithm identifier) using the private key
+B<rsa> and stores the signature in B<to>. B<to> must point to
+B<RSA_size(rsa)> bytes of memory.
+
+B<padding> denotes one of the following modes:
+
+=over 4
+
+=item RSA_PKCS1_PADDING
+
+PKCS #1 v1.5 padding. This function does not handle the
+B<algorithmIdentifier> specified in PKCS #1. When generating or
+verifying PKCS #1 signatures, L<RSA_sign(3)|RSA_sign(3)> and L<RSA_verify(3)|RSA_verify(3)> should be
+used.
+
+=item RSA_NO_PADDING
+
+Raw RSA signature. This mode should I<only> be used to implement
+cryptographically sound padding modes in the application code.
+Signing user data directly with RSA is insecure.
+
+=back
+
+RSA_public_decrypt() recovers the message digest from the B<flen>
+bytes long signature at B<from> using the signer's public key
+B<rsa>. B<to> must point to a memory section large enough to hold the
+message digest (which is smaller than B<RSA_size(rsa) -
+11>). B<padding> is the padding mode that was used to sign the data.
+
+=head1 RETURN VALUES
+
+RSA_private_encrypt() returns the size of the signature (i.e.,
+RSA_size(rsa)). RSA_public_decrypt() returns the size of the
+recovered message digest.
+
+On error, -1 is returned; the error codes can be
+obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<rsa(3)|rsa(3)>,
+L<RSA_sign(3)|RSA_sign(3)>, L<RSA_verify(3)|RSA_verify(3)>
+
+=head1 HISTORY
+
+The B<padding> argument was added in SSLeay 0.8. RSA_NO_PADDING is
+available since SSLeay 0.9.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/RSA_public_encrypt.pod b/deps/openssl/openssl/doc/crypto/RSA_public_encrypt.pod
new file mode 100644 (file)
index 0000000..ab0fe3b
--- /dev/null
@@ -0,0 +1,84 @@
+=pod
+
+=head1 NAME
+
+RSA_public_encrypt, RSA_private_decrypt - RSA public key cryptography
+
+=head1 SYNOPSIS
+
+ #include <openssl/rsa.h>
+
+ int RSA_public_encrypt(int flen, unsigned char *from,
+    unsigned char *to, RSA *rsa, int padding);
+
+ int RSA_private_decrypt(int flen, unsigned char *from,
+     unsigned char *to, RSA *rsa, int padding);
+
+=head1 DESCRIPTION
+
+RSA_public_encrypt() encrypts the B<flen> bytes at B<from> (usually a
+session key) using the public key B<rsa> and stores the ciphertext in
+B<to>. B<to> must point to RSA_size(B<rsa>) bytes of memory.
+
+B<padding> denotes one of the following modes:
+
+=over 4
+
+=item RSA_PKCS1_PADDING
+
+PKCS #1 v1.5 padding. This currently is the most widely used mode.
+
+=item RSA_PKCS1_OAEP_PADDING
+
+EME-OAEP as defined in PKCS #1 v2.0 with SHA-1, MGF1 and an empty
+encoding parameter. This mode is recommended for all new applications.
+
+=item RSA_SSLV23_PADDING
+
+PKCS #1 v1.5 padding with an SSL-specific modification that denotes
+that the server is SSL3 capable.
+
+=item RSA_NO_PADDING
+
+Raw RSA encryption. This mode should I<only> be used to implement
+cryptographically sound padding modes in the application code.
+Encrypting user data directly with RSA is insecure.
+
+=back
+
+B<flen> must be less than RSA_size(B<rsa>) - 11 for the PKCS #1 v1.5
+based padding modes, less than RSA_size(B<rsa>) - 41 for
+RSA_PKCS1_OAEP_PADDING and exactly RSA_size(B<rsa>) for RSA_NO_PADDING.
+The random number generator must be seeded prior to calling
+RSA_public_encrypt().
+
+RSA_private_decrypt() decrypts the B<flen> bytes at B<from> using the
+private key B<rsa> and stores the plaintext in B<to>. B<to> must point
+to a memory section large enough to hold the decrypted data (which is
+smaller than RSA_size(B<rsa>)). B<padding> is the padding mode that
+was used to encrypt the data.
+
+=head1 RETURN VALUES
+
+RSA_public_encrypt() returns the size of the encrypted data (i.e.,
+RSA_size(B<rsa>)). RSA_private_decrypt() returns the size of the
+recovered plaintext.
+
+On error, -1 is returned; the error codes can be
+obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 CONFORMING TO
+
+SSL, PKCS #1 v2.0
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>,
+L<RSA_size(3)|RSA_size(3)>
+
+=head1 HISTORY
+
+The B<padding> argument was added in SSLeay 0.8. RSA_NO_PADDING is
+available since SSLeay 0.9.0, OAEP was added in OpenSSL 0.9.2b.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/RSA_set_method.pod b/deps/openssl/openssl/doc/crypto/RSA_set_method.pod
new file mode 100644 (file)
index 0000000..2c963d7
--- /dev/null
@@ -0,0 +1,202 @@
+=pod
+
+=head1 NAME
+
+RSA_set_default_method, RSA_get_default_method, RSA_set_method,
+RSA_get_method, RSA_PKCS1_SSLeay, RSA_null_method, RSA_flags,
+RSA_new_method - select RSA method
+
+=head1 SYNOPSIS
+
+ #include <openssl/rsa.h>
+
+ void RSA_set_default_method(const RSA_METHOD *meth);
+
+ RSA_METHOD *RSA_get_default_method(void);
+
+ int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
+
+ RSA_METHOD *RSA_get_method(const RSA *rsa);
+
+ RSA_METHOD *RSA_PKCS1_SSLeay(void);
+
+ RSA_METHOD *RSA_null_method(void);
+
+ int RSA_flags(const RSA *rsa);
+
+ RSA *RSA_new_method(RSA_METHOD *method);
+
+=head1 DESCRIPTION
+
+An B<RSA_METHOD> specifies the functions that OpenSSL uses for RSA
+operations. By modifying the method, alternative implementations such as
+hardware accelerators may be used. IMPORTANT: See the NOTES section for
+important information about how these RSA API functions are affected by the
+use of B<ENGINE> API calls.
+
+Initially, the default RSA_METHOD is the OpenSSL internal implementation,
+as returned by RSA_PKCS1_SSLeay().
+
+RSA_set_default_method() makes B<meth> the default method for all RSA
+structures created later. B<NB>: This is true only whilst no ENGINE has
+been set as a default for RSA, so this function is no longer recommended.
+
+RSA_get_default_method() returns a pointer to the current default
+RSA_METHOD. However, the meaningfulness of this result is dependent on
+whether the ENGINE API is being used, so this function is no longer 
+recommended.
+
+RSA_set_method() selects B<meth> to perform all operations using the key
+B<rsa>. This will replace the RSA_METHOD used by the RSA key and if the
+previous method was supplied by an ENGINE, the handle to that ENGINE will
+be released during the change. It is possible to have RSA keys that only
+work with certain RSA_METHOD implementations (eg. from an ENGINE module
+that supports embedded hardware-protected keys), and in such cases
+attempting to change the RSA_METHOD for the key can have unexpected
+results.
+
+RSA_get_method() returns a pointer to the RSA_METHOD being used by B<rsa>.
+This method may or may not be supplied by an ENGINE implementation, but if
+it is, the return value can only be guaranteed to be valid as long as the
+RSA key itself is valid and does not have its implementation changed by
+RSA_set_method().
+
+RSA_flags() returns the B<flags> that are set for B<rsa>'s current
+RSA_METHOD. See the BUGS section.
+
+RSA_new_method() allocates and initializes an RSA structure so that
+B<engine> will be used for the RSA operations. If B<engine> is NULL, the
+default ENGINE for RSA operations is used, and if no default ENGINE is set,
+the RSA_METHOD controlled by RSA_set_default_method() is used.
+
+RSA_flags() returns the B<flags> that are set for B<rsa>'s current method.
+
+RSA_new_method() allocates and initializes an B<RSA> structure so that
+B<method> will be used for the RSA operations. If B<method> is B<NULL>,
+the default method is used.
+
+=head1 THE RSA_METHOD STRUCTURE
+
+ typedef struct rsa_meth_st
+ {
+     /* name of the implementation */
+       const char *name;
+
+     /* encrypt */
+       int (*rsa_pub_enc)(int flen, unsigned char *from,
+          unsigned char *to, RSA *rsa, int padding);
+
+     /* verify arbitrary data */
+       int (*rsa_pub_dec)(int flen, unsigned char *from,
+          unsigned char *to, RSA *rsa, int padding);
+
+     /* sign arbitrary data */
+       int (*rsa_priv_enc)(int flen, unsigned char *from,
+          unsigned char *to, RSA *rsa, int padding);
+
+     /* decrypt */
+       int (*rsa_priv_dec)(int flen, unsigned char *from,
+          unsigned char *to, RSA *rsa, int padding);
+
+     /* compute r0 = r0 ^ I mod rsa->n (May be NULL for some
+                                        implementations) */
+       int (*rsa_mod_exp)(BIGNUM *r0, BIGNUM *I, RSA *rsa);
+
+     /* compute r = a ^ p mod m (May be NULL for some implementations) */
+       int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
+          const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
+
+     /* called at RSA_new */
+       int (*init)(RSA *rsa);
+
+     /* called at RSA_free */
+       int (*finish)(RSA *rsa);
+
+     /* RSA_FLAG_EXT_PKEY        - rsa_mod_exp is called for private key
+      *                            operations, even if p,q,dmp1,dmq1,iqmp
+      *                            are NULL
+      * RSA_FLAG_SIGN_VER        - enable rsa_sign and rsa_verify
+      * RSA_METHOD_FLAG_NO_CHECK - don't check pub/private match
+      */
+       int flags;
+
+       char *app_data; /* ?? */
+
+     /* sign. For backward compatibility, this is used only
+      * if (flags & RSA_FLAG_SIGN_VER)
+      */
+       int (*rsa_sign)(int type, unsigned char *m, unsigned int m_len,
+           unsigned char *sigret, unsigned int *siglen, RSA *rsa);
+
+     /* verify. For backward compatibility, this is used only
+      * if (flags & RSA_FLAG_SIGN_VER)
+      */
+       int (*rsa_verify)(int type, unsigned char *m, unsigned int m_len,
+           unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
+
+ } RSA_METHOD;
+
+=head1 RETURN VALUES
+
+RSA_PKCS1_SSLeay(), RSA_PKCS1_null_method(), RSA_get_default_method()
+and RSA_get_method() return pointers to the respective RSA_METHODs.
+
+RSA_set_default_method() returns no value.
+
+RSA_set_method() returns a pointer to the old RSA_METHOD implementation
+that was replaced. However, this return value should probably be ignored
+because if it was supplied by an ENGINE, the pointer could be invalidated
+at any time if the ENGINE is unloaded (in fact it could be unloaded as a
+result of the RSA_set_method() function releasing its handle to the
+ENGINE). For this reason, the return type may be replaced with a B<void>
+declaration in a future release.
+
+RSA_new_method() returns NULL and sets an error code that can be obtained
+by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation fails. Otherwise
+it returns a pointer to the newly allocated structure.
+
+=head1 NOTES
+
+As of version 0.9.7, RSA_METHOD implementations are grouped together with
+other algorithmic APIs (eg. DSA_METHOD, EVP_CIPHER, etc) into B<ENGINE>
+modules. If a default ENGINE is specified for RSA functionality using an
+ENGINE API function, that will override any RSA defaults set using the RSA
+API (ie.  RSA_set_default_method()). For this reason, the ENGINE API is the
+recommended way to control default implementations for use in RSA and other
+cryptographic algorithms.
+
+=head1 BUGS
+
+The behaviour of RSA_flags() is a mis-feature that is left as-is for now
+to avoid creating compatibility problems. RSA functionality, such as the
+encryption functions, are controlled by the B<flags> value in the RSA key
+itself, not by the B<flags> value in the RSA_METHOD attached to the RSA key
+(which is what this function returns). If the flags element of an RSA key
+is changed, the changes will be honoured by RSA functionality but will not
+be reflected in the return value of the RSA_flags() function - in effect
+RSA_flags() behaves more like an RSA_default_flags() function (which does
+not currently exist).
+
+=head1 SEE ALSO
+
+L<rsa(3)|rsa(3)>, L<RSA_new(3)|RSA_new(3)>
+
+=head1 HISTORY
+
+RSA_new_method() and RSA_set_default_method() appeared in SSLeay 0.8.
+RSA_get_default_method(), RSA_set_method() and RSA_get_method() as
+well as the rsa_sign and rsa_verify components of RSA_METHOD were
+added in OpenSSL 0.9.4.
+
+RSA_set_default_openssl_method() and RSA_get_default_openssl_method()
+replaced RSA_set_default_method() and RSA_get_default_method()
+respectively, and RSA_set_method() and RSA_new_method() were altered to use
+B<ENGINE>s rather than B<RSA_METHOD>s during development of the engine
+version of OpenSSL 0.9.6. For 0.9.7, the handling of defaults in the ENGINE
+API was restructured so that this change was reversed, and behaviour of the
+other functions resembled more closely the previous behaviour. The
+behaviour of defaults in the ENGINE API now transparently overrides the
+behaviour of defaults in the RSA API without requiring changing these
+function prototypes.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/RSA_sign.pod b/deps/openssl/openssl/doc/crypto/RSA_sign.pod
new file mode 100644 (file)
index 0000000..8553be8
--- /dev/null
@@ -0,0 +1,62 @@
+=pod
+
+=head1 NAME
+
+RSA_sign, RSA_verify - RSA signatures
+
+=head1 SYNOPSIS
+
+ #include <openssl/rsa.h>
+
+ int RSA_sign(int type, const unsigned char *m, unsigned int m_len,
+    unsigned char *sigret, unsigned int *siglen, RSA *rsa);
+
+ int RSA_verify(int type, const unsigned char *m, unsigned int m_len,
+    unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
+
+=head1 DESCRIPTION
+
+RSA_sign() signs the message digest B<m> of size B<m_len> using the
+private key B<rsa> as specified in PKCS #1 v2.0. It stores the
+signature in B<sigret> and the signature size in B<siglen>. B<sigret>
+must point to RSA_size(B<rsa>) bytes of memory.
+
+B<type> denotes the message digest algorithm that was used to generate
+B<m>. It usually is one of B<NID_sha1>, B<NID_ripemd160> and B<NID_md5>;
+see L<objects(3)|objects(3)> for details. If B<type> is B<NID_md5_sha1>,
+an SSL signature (MD5 and SHA1 message digests with PKCS #1 padding
+and no algorithm identifier) is created.
+
+RSA_verify() verifies that the signature B<sigbuf> of size B<siglen>
+matches a given message digest B<m> of size B<m_len>. B<type> denotes
+the message digest algorithm that was used to generate the signature.
+B<rsa> is the signer's public key.
+
+=head1 RETURN VALUES
+
+RSA_sign() returns 1 on success, 0 otherwise.  RSA_verify() returns 1
+on successful verification, 0 otherwise.
+
+The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 BUGS
+
+Certain signatures with an improper algorithm identifier are accepted
+for compatibility with SSLeay 0.4.5 :-)
+
+=head1 CONFORMING TO
+
+SSL, PKCS #1 v2.0
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<objects(3)|objects(3)>,
+L<rsa(3)|rsa(3)>, L<RSA_private_encrypt(3)|RSA_private_encrypt(3)>,
+L<RSA_public_decrypt(3)|RSA_public_decrypt(3)> 
+
+=head1 HISTORY
+
+RSA_sign() and RSA_verify() are available in all versions of SSLeay
+and OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/RSA_sign_ASN1_OCTET_STRING.pod b/deps/openssl/openssl/doc/crypto/RSA_sign_ASN1_OCTET_STRING.pod
new file mode 100644 (file)
index 0000000..e70380b
--- /dev/null
@@ -0,0 +1,59 @@
+=pod
+
+=head1 NAME
+
+RSA_sign_ASN1_OCTET_STRING, RSA_verify_ASN1_OCTET_STRING - RSA signatures
+
+=head1 SYNOPSIS
+
+ #include <openssl/rsa.h>
+
+ int RSA_sign_ASN1_OCTET_STRING(int dummy, unsigned char *m,
+    unsigned int m_len, unsigned char *sigret, unsigned int *siglen,
+    RSA *rsa);
+
+ int RSA_verify_ASN1_OCTET_STRING(int dummy, unsigned char *m,
+    unsigned int m_len, unsigned char *sigbuf, unsigned int siglen,
+    RSA *rsa);
+
+=head1 DESCRIPTION
+
+RSA_sign_ASN1_OCTET_STRING() signs the octet string B<m> of size
+B<m_len> using the private key B<rsa> represented in DER using PKCS #1
+padding. It stores the signature in B<sigret> and the signature size
+in B<siglen>. B<sigret> must point to B<RSA_size(rsa)> bytes of
+memory.
+
+B<dummy> is ignored.
+
+The random number generator must be seeded prior to calling RSA_sign_ASN1_OCTET_STRING().
+
+RSA_verify_ASN1_OCTET_STRING() verifies that the signature B<sigbuf>
+of size B<siglen> is the DER representation of a given octet string
+B<m> of size B<m_len>. B<dummy> is ignored. B<rsa> is the signer's
+public key.
+
+=head1 RETURN VALUES
+
+RSA_sign_ASN1_OCTET_STRING() returns 1 on success, 0 otherwise.
+RSA_verify_ASN1_OCTET_STRING() returns 1 on successful verification, 0
+otherwise.
+
+The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 BUGS
+
+These functions serve no recognizable purpose.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<objects(3)|objects(3)>,
+L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>, L<RSA_sign(3)|RSA_sign(3)>,
+L<RSA_verify(3)|RSA_verify(3)>
+
+=head1 HISTORY
+
+RSA_sign_ASN1_OCTET_STRING() and RSA_verify_ASN1_OCTET_STRING() were
+added in SSLeay 0.8.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/RSA_size.pod b/deps/openssl/openssl/doc/crypto/RSA_size.pod
new file mode 100644 (file)
index 0000000..5b7f835
--- /dev/null
@@ -0,0 +1,33 @@
+=pod
+
+=head1 NAME
+
+RSA_size - get RSA modulus size
+
+=head1 SYNOPSIS
+
+ #include <openssl/rsa.h>
+
+ int RSA_size(const RSA *rsa);
+
+=head1 DESCRIPTION
+
+This function returns the RSA modulus size in bytes. It can be used to
+determine how much memory must be allocated for an RSA encrypted
+value.
+
+B<rsa-E<gt>n> must not be B<NULL>.
+
+=head1 RETURN VALUE
+
+The size in bytes.
+
+=head1 SEE ALSO
+
+L<rsa(3)|rsa(3)>
+
+=head1 HISTORY
+
+RSA_size() is available in all versions of SSLeay and OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/SMIME_read_CMS.pod b/deps/openssl/openssl/doc/crypto/SMIME_read_CMS.pod
new file mode 100644 (file)
index 0000000..acc5524
--- /dev/null
@@ -0,0 +1,70 @@
+=pod
+
+=head1 NAME
+
+ SMIME_read_CMS - parse S/MIME message.
+
+=head1 SYNOPSIS
+
+ #include <openssl/cms.h>
+
+ CMS_ContentInfo *SMIME_read_CMS(BIO *in, BIO **bcont);
+
+=head1 DESCRIPTION
+
+SMIME_read_CMS() parses a message in S/MIME format.
+
+B<in> is a BIO to read the message from.
+
+If cleartext signing is used then the content is saved in a memory bio which is
+written to B<*bcont>, otherwise B<*bcont> is set to NULL.
+
+The parsed CMS_ContentInfo structure is returned or NULL if an
+error occurred.
+
+=head1 NOTES
+
+If B<*bcont> is not NULL then the message is clear text signed. B<*bcont> can
+then be passed to CMS_verify() with the B<CMS_DETACHED> flag set.
+
+Otherwise the type of the returned structure can be determined
+using CMS_get0_type().
+
+To support future functionality if B<bcont> is not NULL B<*bcont> should be
+initialized to NULL. For example:
+
+ BIO *cont = NULL;
+ CMS_ContentInfo *cms;
+
+ cms = SMIME_read_CMS(in, &cont);
+
+=head1 BUGS
+
+The MIME parser used by SMIME_read_CMS() is somewhat primitive.  While it will
+handle most S/MIME messages more complex compound formats may not work.
+
+The parser assumes that the CMS_ContentInfo structure is always base64 encoded
+and will not handle the case where it is in binary format or uses quoted
+printable format.
+
+The use of a memory BIO to hold the signed content limits the size of message
+which can be processed due to memory restraints: a streaming single pass option
+should be available.
+
+=head1 RETURN VALUES
+
+SMIME_read_CMS() returns a valid B<CMS_ContentInfo> structure or B<NULL>
+if an error occurred. The error can be obtained from ERR_get_error(3).
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<CMS_type(3)|CMS_type(3)>
+L<SMIME_read_CMS(3)|SMIME_read_CMS(3)>, L<CMS_sign(3)|CMS_sign(3)>,
+L<CMS_verify(3)|CMS_verify(3)>, L<CMS_encrypt(3)|CMS_encrypt(3)>
+L<CMS_decrypt(3)|CMS_decrypt(3)>
+
+=head1 HISTORY
+
+SMIME_read_CMS() was added to OpenSSL 0.9.8
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/SMIME_read_PKCS7.pod b/deps/openssl/openssl/doc/crypto/SMIME_read_PKCS7.pod
new file mode 100644 (file)
index 0000000..9d46715
--- /dev/null
@@ -0,0 +1,73 @@
+=pod
+
+=head1 NAME
+
+SMIME_read_PKCS7 - parse S/MIME message.
+
+=head1 SYNOPSIS
+
+ #include <openssl/pkcs7.h>
+
+ PKCS7 *SMIME_read_PKCS7(BIO *in, BIO **bcont);
+
+=head1 DESCRIPTION
+
+SMIME_read_PKCS7() parses a message in S/MIME format.
+
+B<in> is a BIO to read the message from.
+
+If cleartext signing is used then the content is saved in
+a memory bio which is written to B<*bcont>, otherwise
+B<*bcont> is set to B<NULL>.
+
+The parsed PKCS#7 structure is returned or B<NULL> if an
+error occurred.
+
+=head1 NOTES
+
+If B<*bcont> is not B<NULL> then the message is clear text
+signed. B<*bcont> can then be passed to PKCS7_verify() with
+the B<PKCS7_DETACHED> flag set.
+
+Otherwise the type of the returned structure can be determined
+using PKCS7_type().
+
+To support future functionality if B<bcont> is not B<NULL>
+B<*bcont> should be initialized to B<NULL>. For example:
+
+ BIO *cont = NULL;
+ PKCS7 *p7;
+
+ p7 = SMIME_read_PKCS7(in, &cont);
+
+=head1 BUGS
+
+The MIME parser used by SMIME_read_PKCS7() is somewhat primitive.
+While it will handle most S/MIME messages more complex compound
+formats may not work.
+
+The parser assumes that the PKCS7 structure is always base64
+encoded and will not handle the case where it is in binary format
+or uses quoted printable format.
+
+The use of a memory BIO to hold the signed content limits the size
+of message which can be processed due to memory restraints: a
+streaming single pass option should be available.
+
+=head1 RETURN VALUES
+
+SMIME_read_PKCS7() returns a valid B<PKCS7> structure or B<NULL>
+is an error occurred. The error can be obtained from ERR_get_error(3).
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_type(3)|PKCS7_type(3)>
+L<SMIME_read_PKCS7(3)|SMIME_read_PKCS7(3)>, L<PKCS7_sign(3)|PKCS7_sign(3)>,
+L<PKCS7_verify(3)|PKCS7_verify(3)>, L<PKCS7_encrypt(3)|PKCS7_encrypt(3)>
+L<PKCS7_decrypt(3)|PKCS7_decrypt(3)>
+
+=head1 HISTORY
+
+SMIME_read_PKCS7() was added to OpenSSL 0.9.5
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/SMIME_write_CMS.pod b/deps/openssl/openssl/doc/crypto/SMIME_write_CMS.pod
new file mode 100644 (file)
index 0000000..04bedfb
--- /dev/null
@@ -0,0 +1,64 @@
+=pod
+
+=head1 NAME
+
+ SMIME_write_CMS - convert CMS structure to S/MIME format.
+
+=head1 SYNOPSIS
+
+ #include <openssl/cms.h>
+
+ int SMIME_write_CMS(BIO *out, CMS_ContentInfo *cms, BIO *data, int flags);
+
+=head1 DESCRIPTION
+
+SMIME_write_CMS() adds the appropriate MIME headers to a CMS
+structure to produce an S/MIME message.
+
+B<out> is the BIO to write the data to. B<cms> is the appropriate
+B<CMS_ContentInfo> structure. If streaming is enabled then the content must be
+supplied in the B<data> argument. B<flags> is an optional set of flags.
+
+=head1 NOTES
+
+The following flags can be passed in the B<flags> parameter.
+
+If B<CMS_DETACHED> is set then cleartext signing will be used, this option only
+makes sense for SignedData where B<CMS_DETACHED> is also set when CMS_sign() is
+called.
+
+If the B<CMS_TEXT> flag is set MIME headers for type B<text/plain> are added to
+the content, this only makes sense if B<CMS_DETACHED> is also set.
+
+If the B<CMS_STREAM> flag is set streaming is performed. This flag should only
+be set if B<CMS_STREAM> was also set in the previous call to a CMS_ContentInfo
+creation function.
+
+If cleartext signing is being used and B<CMS_STREAM> not set then the data must
+be read twice: once to compute the signature in CMS_sign() and once to output
+the S/MIME message.
+
+If streaming is performed the content is output in BER format using indefinite
+length constructed encoding except in the case of signed data with detached
+content where the content is absent and DER format is used.
+
+=head1 BUGS
+
+SMIME_write_CMS() always base64 encodes CMS structures, there should be an
+option to disable this.
+
+=head1 RETURN VALUES
+
+SMIME_write_CMS() returns 1 for success or 0 for failure.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<CMS_sign(3)|CMS_sign(3)>,
+L<CMS_verify(3)|CMS_verify(3)>, L<CMS_encrypt(3)|CMS_encrypt(3)>
+L<CMS_decrypt(3)|CMS_decrypt(3)>
+
+=head1 HISTORY
+
+SMIME_write_CMS() was added to OpenSSL 0.9.8
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/SMIME_write_PKCS7.pod b/deps/openssl/openssl/doc/crypto/SMIME_write_PKCS7.pod
new file mode 100644 (file)
index 0000000..ca6bd02
--- /dev/null
@@ -0,0 +1,65 @@
+=pod
+
+=head1 NAME
+
+SMIME_write_PKCS7 - convert PKCS#7 structure to S/MIME format.
+
+=head1 SYNOPSIS
+
+ #include <openssl/pkcs7.h>
+
+ int SMIME_write_PKCS7(BIO *out, PKCS7 *p7, BIO *data, int flags);
+
+=head1 DESCRIPTION
+
+SMIME_write_PKCS7() adds the appropriate MIME headers to a PKCS#7
+structure to produce an S/MIME message.
+
+B<out> is the BIO to write the data to. B<p7> is the appropriate B<PKCS7>
+structure. If streaming is enabled then the content must be supplied in the
+B<data> argument. B<flags> is an optional set of flags.
+
+=head1 NOTES
+
+The following flags can be passed in the B<flags> parameter.
+
+If B<PKCS7_DETACHED> is set then cleartext signing will be used,
+this option only makes sense for signedData where B<PKCS7_DETACHED>
+is also set when PKCS7_sign() is also called.
+
+If the B<PKCS7_TEXT> flag is set MIME headers for type B<text/plain>
+are added to the content, this only makes sense if B<PKCS7_DETACHED>
+is also set.
+
+If the B<PKCS7_STREAM> flag is set streaming is performed. This flag should
+only be set if B<PKCS7_STREAM> was also set in the previous call to
+PKCS7_sign() or B<PKCS7_encrypt()>.
+
+If cleartext signing is being used and B<PKCS7_STREAM> not set then
+the data must be read twice: once to compute the signature in PKCS7_sign()
+and once to output the S/MIME message.
+
+If streaming is performed the content is output in BER format using indefinite
+length constructuted encoding except in the case of signed data with detached
+content where the content is absent and DER format is used.
+
+=head1 BUGS
+
+SMIME_write_PKCS7() always base64 encodes PKCS#7 structures, there
+should be an option to disable this.
+
+=head1 RETURN VALUES
+
+SMIME_write_PKCS7() returns 1 for success or 0 for failure.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_sign(3)|PKCS7_sign(3)>,
+L<PKCS7_verify(3)|PKCS7_verify(3)>, L<PKCS7_encrypt(3)|PKCS7_encrypt(3)>
+L<PKCS7_decrypt(3)|PKCS7_decrypt(3)>
+
+=head1 HISTORY
+
+SMIME_write_PKCS7() was added to OpenSSL 0.9.5
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/X509_NAME_ENTRY_get_object.pod b/deps/openssl/openssl/doc/crypto/X509_NAME_ENTRY_get_object.pod
new file mode 100644 (file)
index 0000000..41902c0
--- /dev/null
@@ -0,0 +1,74 @@
+=pod
+
+=head1 NAME
+
+X509_NAME_ENTRY_get_object, X509_NAME_ENTRY_get_data,
+X509_NAME_ENTRY_set_object, X509_NAME_ENTRY_set_data,
+X509_NAME_ENTRY_create_by_txt, X509_NAME_ENTRY_create_by_NID,
+X509_NAME_ENTRY_create_by_OBJ - X509_NAME_ENTRY utility functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/x509.h>
+
+ ASN1_OBJECT * X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne);
+ ASN1_STRING * X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne);
+
+ int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, ASN1_OBJECT *obj);
+ int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type, const unsigned char *bytes, int len);
+
+ X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne, const char *field, int type, const unsigned char *bytes, int len);
+ X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid, int type,unsigned char *bytes, int len);
+ X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne, ASN1_OBJECT *obj, int type, const unsigned char *bytes, int len);
+
+=head1 DESCRIPTION
+
+X509_NAME_ENTRY_get_object() retrieves the field name of B<ne> in
+and B<ASN1_OBJECT> structure.
+
+X509_NAME_ENTRY_get_data() retrieves the field value of B<ne> in
+and B<ASN1_STRING> structure.
+
+X509_NAME_ENTRY_set_object() sets the field name of B<ne> to B<obj>.
+
+X509_NAME_ENTRY_set_data() sets the field value of B<ne> to string type
+B<type> and value determined by B<bytes> and B<len>.
+
+X509_NAME_ENTRY_create_by_txt(), X509_NAME_ENTRY_create_by_NID()
+and X509_NAME_ENTRY_create_by_OBJ() create and return an 
+B<X509_NAME_ENTRY> structure.
+
+=head1 NOTES
+
+X509_NAME_ENTRY_get_object() and X509_NAME_ENTRY_get_data() can be
+used to examine an B<X509_NAME_ENTRY> function as returned by 
+X509_NAME_get_entry() for example.
+
+X509_NAME_ENTRY_create_by_txt(), X509_NAME_ENTRY_create_by_NID(),
+and X509_NAME_ENTRY_create_by_OBJ() create and return an 
+
+X509_NAME_ENTRY_create_by_txt(), X509_NAME_ENTRY_create_by_OBJ(),
+X509_NAME_ENTRY_create_by_NID() and X509_NAME_ENTRY_set_data()
+are seldom used in practice because B<X509_NAME_ENTRY> structures
+are almost always part of B<X509_NAME> structures and the
+corresponding B<X509_NAME> functions are typically used to
+create and add new entries in a single operation.
+
+The arguments of these functions support similar options to the similarly
+named ones of the corresponding B<X509_NAME> functions such as
+X509_NAME_add_entry_by_txt(). So for example B<type> can be set to
+B<MBSTRING_ASC> but in the case of X509_set_data() the field name must be
+set first so the relevant field information can be looked up internally.
+
+=head1 RETURN VALUES
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<d2i_X509_NAME(3)|d2i_X509_NAME(3)>,
+L<OBJ_nid2obj(3),OBJ_nid2obj(3)>
+
+=head1 HISTORY
+
+TBA
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/X509_NAME_add_entry_by_txt.pod b/deps/openssl/openssl/doc/crypto/X509_NAME_add_entry_by_txt.pod
new file mode 100644 (file)
index 0000000..1afd008
--- /dev/null
@@ -0,0 +1,116 @@
+=pod
+
+=head1 NAME
+
+X509_NAME_add_entry_by_txt, X509_NAME_add_entry_by_OBJ, X509_NAME_add_entry_by_NID,
+X509_NAME_add_entry, X509_NAME_delete_entry - X509_NAME modification functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/x509.h>
+
+ int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type, const unsigned char *bytes, int len, int loc, int set);
+
+ int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type, unsigned char *bytes, int len, int loc, int set);
+
+ int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type, unsigned char *bytes, int len, int loc, int set);
+
+ int X509_NAME_add_entry(X509_NAME *name,X509_NAME_ENTRY *ne, int loc, int set);
+
+ X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc);
+
+=head1 DESCRIPTION
+
+X509_NAME_add_entry_by_txt(), X509_NAME_add_entry_by_OBJ() and
+X509_NAME_add_entry_by_NID() add a field whose name is defined
+by a string B<field>, an object B<obj> or a NID B<nid> respectively.
+The field value to be added is in B<bytes> of length B<len>. If
+B<len> is -1 then the field length is calculated internally using
+strlen(bytes).
+
+The type of field is determined by B<type> which can either be a
+definition of the type of B<bytes> (such as B<MBSTRING_ASC>) or a
+standard ASN1 type (such as B<V_ASN1_IA5STRING>). The new entry is
+added to a position determined by B<loc> and B<set>.
+
+X509_NAME_add_entry() adds a copy of B<X509_NAME_ENTRY> structure B<ne>
+to B<name>. The new entry is added to a position determined by B<loc>
+and B<set>. Since a copy of B<ne> is added B<ne> must be freed up after
+the call.
+
+X509_NAME_delete_entry() deletes an entry from B<name> at position
+B<loc>. The deleted entry is returned and must be freed up.
+
+=head1 NOTES
+
+The use of string types such as B<MBSTRING_ASC> or B<MBSTRING_UTF8>
+is strongly recommened for the B<type> parameter. This allows the
+internal code to correctly determine the type of the field and to
+apply length checks according to the relevant standards. This is
+done using ASN1_STRING_set_by_NID().
+
+If instead an ASN1 type is used no checks are performed and the
+supplied data in B<bytes> is used directly.
+
+In X509_NAME_add_entry_by_txt() the B<field> string represents
+the field name using OBJ_txt2obj(field, 0).
+
+The B<loc> and B<set> parameters determine where a new entry should
+be added. For almost all applications B<loc> can be set to -1 and B<set>
+to 0. This adds a new entry to the end of B<name> as a single valued
+RelativeDistinguishedName (RDN).
+
+B<loc> actually determines the index where the new entry is inserted:
+if it is -1 it is appended. 
+
+B<set> determines how the new type is added. If it is zero a
+new RDN is created.
+
+If B<set> is -1 or 1 it is added to the previous or next RDN
+structure respectively. This will then be a multivalued RDN:
+since multivalues RDNs are very seldom used B<set> is almost
+always set to zero.
+
+=head1 EXAMPLES
+
+Create an B<X509_NAME> structure:
+
+"C=UK, O=Disorganized Organization, CN=Joe Bloggs"
+
+ X509_NAME *nm;
+ nm = X509_NAME_new();
+ if (nm == NULL)
+       /* Some error */
+ if (!X509_NAME_add_entry_by_txt(nm, MBSTRING_ASC,
+                       "C", "UK", -1, -1, 0))
+       /* Error */
+ if (!X509_NAME_add_entry_by_txt(nm, MBSTRING_ASC,
+                       "O", "Disorganized Organization", -1, -1, 0))
+       /* Error */
+ if (!X509_NAME_add_entry_by_txt(nm, MBSTRING_ASC,
+                       "CN", "Joe Bloggs", -1, -1, 0))
+       /* Error */
+
+=head1 RETURN VALUES
+
+X509_NAME_add_entry_by_txt(), X509_NAME_add_entry_by_OBJ(),
+X509_NAME_add_entry_by_NID() and X509_NAME_add_entry() return 1 for
+success of 0 if an error occurred.
+
+X509_NAME_delete_entry() returns either the deleted B<X509_NAME_ENTRY>
+structure of B<NULL> if an error occurred.
+
+=head1 BUGS
+
+B<type> can still be set to B<V_ASN1_APP_CHOOSE> to use a
+different algorithm to determine field types. Since this form does
+not understand multicharacter types, performs no length checks and
+can result in invalid field types its use is strongly discouraged.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<d2i_X509_NAME(3)|d2i_X509_NAME(3)>
+
+=head1 HISTORY
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/X509_NAME_get_index_by_NID.pod b/deps/openssl/openssl/doc/crypto/X509_NAME_get_index_by_NID.pod
new file mode 100644 (file)
index 0000000..3b1f9ff
--- /dev/null
@@ -0,0 +1,108 @@
+=pod
+
+=head1 NAME
+
+X509_NAME_get_index_by_NID, X509_NAME_get_index_by_OBJ, X509_NAME_get_entry,
+X509_NAME_entry_count, X509_NAME_get_text_by_NID, X509_NAME_get_text_by_OBJ -
+X509_NAME lookup and enumeration functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/x509.h>
+
+ int X509_NAME_get_index_by_NID(X509_NAME *name,int nid,int lastpos);
+ int X509_NAME_get_index_by_OBJ(X509_NAME *name,ASN1_OBJECT *obj, int lastpos);
+
+ int X509_NAME_entry_count(X509_NAME *name);
+ X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc);
+
+ int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf,int len);
+ int X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, char *buf,int len);
+
+=head1 DESCRIPTION
+
+These functions allow an B<X509_NAME> structure to be examined. The
+B<X509_NAME> structure is the same as the B<Name> type defined in
+RFC2459 (and elsewhere) and used for example in certificate subject
+and issuer names.
+
+X509_NAME_get_index_by_NID() and X509_NAME_get_index_by_OBJ() retrieve
+the next index matching B<nid> or B<obj> after B<lastpos>. B<lastpos>
+should initially be set to -1. If there are no more entries -1 is returned.
+
+X509_NAME_entry_count() returns the total number of entries in B<name>.
+
+X509_NAME_get_entry() retrieves the B<X509_NAME_ENTRY> from B<name>
+corresponding to index B<loc>. Acceptable values for B<loc> run from
+0 to (X509_NAME_entry_count(name) - 1). The value returned is an
+internal pointer which must not be freed.
+
+X509_NAME_get_text_by_NID(), X509_NAME_get_text_by_OBJ() retrieve
+the "text" from the first entry in B<name> which matches B<nid> or
+B<obj>, if no such entry exists -1 is returned. At most B<len> bytes
+will be written and the text written to B<buf> will be null
+terminated. The length of the output string written is returned
+excluding the terminating null. If B<buf> is <NULL> then the amount
+of space needed in B<buf> (excluding the final null) is returned. 
+
+=head1 NOTES
+
+X509_NAME_get_text_by_NID() and X509_NAME_get_text_by_OBJ() are
+legacy functions which have various limitations which make them
+of minimal use in practice. They can only find the first matching
+entry and will copy the contents of the field verbatim: this can
+be highly confusing if the target is a muticharacter string type
+like a BMPString or a UTF8String.
+
+For a more general solution X509_NAME_get_index_by_NID() or
+X509_NAME_get_index_by_OBJ() should be used followed by
+X509_NAME_get_entry() on any matching indices and then the
+various B<X509_NAME_ENTRY> utility functions on the result.
+
+=head1 EXAMPLES
+
+Process all entries:
+
+ int i;
+ X509_NAME_ENTRY *e;
+
+ for (i = 0; i < X509_NAME_entry_count(nm); i++)
+       {
+       e = X509_NAME_get_entry(nm, i);
+       /* Do something with e */
+       }
+
+Process all commonName entries:
+
+ int loc;
+ X509_NAME_ENTRY *e;
+
+ loc = -1;
+ for (;;)
+       {
+       lastpos = X509_NAME_get_index_by_NID(nm, NID_commonName, lastpos);
+       if (lastpos == -1)
+               break;
+       e = X509_NAME_get_entry(nm, lastpos);
+       /* Do something with e */
+       }
+
+=head1 RETURN VALUES
+
+X509_NAME_get_index_by_NID() and X509_NAME_get_index_by_OBJ()
+return the index of the next matching entry or -1 if not found.
+
+X509_NAME_entry_count() returns the total number of entries.
+
+X509_NAME_get_entry() returns an B<X509_NAME> pointer to the
+requested entry or B<NULL> if the index is invalid.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<d2i_X509_NAME(3)|d2i_X509_NAME(3)>
+
+=head1 HISTORY
+
+TBA
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/X509_NAME_print_ex.pod b/deps/openssl/openssl/doc/crypto/X509_NAME_print_ex.pod
new file mode 100644 (file)
index 0000000..2579a5d
--- /dev/null
@@ -0,0 +1,105 @@
+=pod
+
+=head1 NAME
+
+X509_NAME_print_ex, X509_NAME_print_ex_fp, X509_NAME_print,
+X509_NAME_oneline - X509_NAME printing routines.
+
+=head1 SYNOPSIS
+
+ #include <openssl/x509.h>
+
+ int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags);
+ int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags);
+ char *        X509_NAME_oneline(X509_NAME *a,char *buf,int size);
+ int X509_NAME_print(BIO *bp, X509_NAME *name, int obase);
+
+=head1 DESCRIPTION
+
+X509_NAME_print_ex() prints a human readable version of B<nm> to BIO B<out>. Each
+line (for multiline formats) is indented by B<indent> spaces. The output format
+can be extensively customised by use of the B<flags> parameter.
+
+X509_NAME_print_ex_fp() is identical to X509_NAME_print_ex() except the output is
+written to FILE pointer B<fp>.
+
+X509_NAME_oneline() prints an ASCII version of B<a> to B<buf>. At most B<size>
+bytes will be written. If B<buf> is B<NULL> then a buffer is dynamically allocated
+and returned, otherwise B<buf> is returned.
+
+X509_NAME_print() prints out B<name> to B<bp> indenting each line by B<obase> 
+characters. Multiple lines are used if the output (including indent) exceeds
+80 characters.
+
+=head1 NOTES
+
+The functions X509_NAME_oneline() and X509_NAME_print() are legacy functions which
+produce a non standard output form, they don't handle multi character fields and
+have various quirks and inconsistencies. Their use is strongly discouraged in new
+applications.
+
+Although there are a large number of possible flags for most purposes
+B<XN_FLAG_ONELINE>, B<XN_FLAG_MULTILINE> or B<XN_FLAG_RFC2253> will suffice.
+As noted on the L<ASN1_STRING_print_ex(3)|ASN1_STRING_print_ex(3)> manual page
+for UTF8 terminals the B<ASN1_STRFLGS_ESC_MSB> should be unset: so for example
+B<XN_FLAG_ONELINE & ~ASN1_STRFLGS_ESC_MSB> would be used.
+
+The complete set of the flags supported by X509_NAME_print_ex() is listed below.
+
+Several options can be ored together.
+
+The options B<XN_FLAG_SEP_COMMA_PLUS>, B<XN_FLAG_SEP_CPLUS_SPC>,
+B<XN_FLAG_SEP_SPLUS_SPC> and B<XN_FLAG_SEP_MULTILINE> determine the field separators
+to use. Two distinct separators are used between distinct RelativeDistinguishedName
+components and separate values in the same RDN for a multi-valued RDN. Multi-valued
+RDNs are currently very rare so the second separator will hardly ever be used.
+
+B<XN_FLAG_SEP_COMMA_PLUS> uses comma and plus as separators. B<XN_FLAG_SEP_CPLUS_SPC>
+uses comma and plus with spaces: this is more readable that plain comma and plus.
+B<XN_FLAG_SEP_SPLUS_SPC> uses spaced semicolon and plus. B<XN_FLAG_SEP_MULTILINE> uses
+spaced newline and plus respectively.
+
+If B<XN_FLAG_DN_REV> is set the whole DN is printed in reversed order.
+
+The fields B<XN_FLAG_FN_SN>, B<XN_FLAG_FN_LN>, B<XN_FLAG_FN_OID>,
+B<XN_FLAG_FN_NONE> determine how a field name is displayed. It will
+use the short name (e.g. CN) the long name (e.g. commonName) always
+use OID numerical form (normally OIDs are only used if the field name is not
+recognised) and no field name respectively.
+
+If B<XN_FLAG_SPC_EQ> is set then spaces will be placed around the '=' character
+separating field names and values.
+
+If B<XN_FLAG_DUMP_UNKNOWN_FIELDS> is set then the encoding of unknown fields is
+printed instead of the values.
+
+If B<XN_FLAG_FN_ALIGN> is set then field names are padded to 20 characters: this
+is only of use for multiline format.
+
+Additionally all the options supported by ASN1_STRING_print_ex() can be used to 
+control how each field value is displayed.
+
+In addition a number options can be set for commonly used formats.
+
+B<XN_FLAG_RFC2253> sets options which produce an output compatible with RFC2253 it
+is equivalent to:
+ B<ASN1_STRFLGS_RFC2253 | XN_FLAG_SEP_COMMA_PLUS | XN_FLAG_DN_REV | XN_FLAG_FN_SN | XN_FLAG_DUMP_UNKNOWN_FIELDS>
+
+
+B<XN_FLAG_ONELINE> is a more readable one line format which is the same as:
+ B<ASN1_STRFLGS_RFC2253 | ASN1_STRFLGS_ESC_QUOTE | XN_FLAG_SEP_CPLUS_SPC | XN_FLAG_SPC_EQ | XN_FLAG_FN_SN>
+
+B<XN_FLAG_MULTILINE> is a multiline format which is the same as:
+ B<ASN1_STRFLGS_ESC_CTRL | ASN1_STRFLGS_ESC_MSB | XN_FLAG_SEP_MULTILINE | XN_FLAG_SPC_EQ | XN_FLAG_FN_LN | XN_FLAG_FN_ALIGN>
+
+B<XN_FLAG_COMPAT> uses a format identical to X509_NAME_print(): in fact it calls X509_NAME_print() internally.
+
+=head1 SEE ALSO
+
+L<ASN1_STRING_print_ex(3)|ASN1_STRING_print_ex(3)>
+
+=head1 HISTORY
+
+TBA
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/X509_STORE_CTX_get_error.pod b/deps/openssl/openssl/doc/crypto/X509_STORE_CTX_get_error.pod
new file mode 100644 (file)
index 0000000..a883f6c
--- /dev/null
@@ -0,0 +1,303 @@
+=pod
+
+=head1 NAME
+
+X509_STORE_CTX_get_error, X509_STORE_CTX_set_error, X509_STORE_CTX_get_error_depth, X509_STORE_CTX_get_current_cert, X509_STORE_CTX_get1_chain, X509_verify_cert_error_string - get or set certificate verification status information
+
+=head1 SYNOPSIS
+
+ #include <openssl/x509.h>
+ #include <openssl/x509_vfy.h>
+
+ int   X509_STORE_CTX_get_error(X509_STORE_CTX *ctx);
+ void  X509_STORE_CTX_set_error(X509_STORE_CTX *ctx,int s);
+ int   X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx);
+ X509 *        X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx);
+
+ STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx);
+
+ const char *X509_verify_cert_error_string(long n);
+
+=head1 DESCRIPTION
+
+These functions are typically called after X509_verify_cert() has indicated
+an error or in a verification callback to determine the nature of an error.
+
+X509_STORE_CTX_get_error() returns the error code of B<ctx>, see
+the B<ERROR CODES> section for a full description of all error codes.
+
+X509_STORE_CTX_set_error() sets the error code of B<ctx> to B<s>. For example
+it might be used in a verification callback to set an error based on additional
+checks.
+
+X509_STORE_CTX_get_error_depth() returns the B<depth> of the error. This is a
+non-negative integer representing where in the certificate chain the error
+occurred. If it is zero it occured in the end entity certificate, one if
+it is the certificate which signed the end entity certificate and so on.
+
+X509_STORE_CTX_get_current_cert() returns the certificate in B<ctx> which
+caused the error or B<NULL> if no certificate is relevant.
+
+X509_STORE_CTX_get1_chain() returns a complete validate chain if a previous
+call to X509_verify_cert() is successful. If the call to X509_verify_cert()
+is B<not> successful the returned chain may be incomplete or invalid. The
+returned chain persists after the B<ctx> structure is freed, when it is
+no longer needed it should be free up using:
+
+  sk_X509_pop_free(chain, X509_free);
+
+X509_verify_cert_error_string() returns a human readable error string for
+verification error B<n>.
+
+=head1 RETURN VALUES
+
+X509_STORE_CTX_get_error() returns B<X509_V_OK> or an error code.
+
+X509_STORE_CTX_get_error_depth() returns a non-negative error depth.
+
+X509_STORE_CTX_get_current_cert() returns the cerificate which caused the
+error or B<NULL> if no certificate is relevant to the error.
+
+X509_verify_cert_error_string() returns a human readable error string for
+verification error B<n>.
+
+=head1 ERROR CODES
+
+A list of error codes and messages is shown below.  Some of the
+error codes are defined but currently never returned: these are described as
+"unused".
+
+=over 4
+
+=item B<X509_V_OK: ok>
+
+the operation was successful.
+
+=item B<X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: unable to get issuer certificate>
+
+the issuer certificate could not be found: this occurs if the issuer certificate
+of an untrusted certificate cannot be found.
+
+=item B<X509_V_ERR_UNABLE_TO_GET_CRL: unable to get certificate CRL>
+
+the CRL of a certificate could not be found.
+
+=item B<X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE: unable to decrypt certificate's signature>
+
+the certificate signature could not be decrypted. This means that the actual
+signature value could not be determined rather than it not matching the
+expected value, this is only meaningful for RSA keys.
+
+=item B<X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE: unable to decrypt CRL's signature>
+
+the CRL signature could not be decrypted: this means that the actual signature
+value could not be determined rather than it not matching the expected value.
+Unused.
+
+=item B<X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY: unable to decode issuer public key>
+
+the public key in the certificate SubjectPublicKeyInfo could not be read.
+
+=item B<X509_V_ERR_CERT_SIGNATURE_FAILURE: certificate signature failure>
+
+the signature of the certificate is invalid.
+
+=item B<X509_V_ERR_CRL_SIGNATURE_FAILURE: CRL signature failure>
+
+the signature of the certificate is invalid.
+
+=item B<X509_V_ERR_CERT_NOT_YET_VALID: certificate is not yet valid>
+
+the certificate is not yet valid: the notBefore date is after the current time.
+
+=item B<X509_V_ERR_CERT_HAS_EXPIRED: certificate has expired>
+
+the certificate has expired: that is the notAfter date is before the current time.
+
+=item B<X509_V_ERR_CRL_NOT_YET_VALID: CRL is not yet valid>
+
+the CRL is not yet valid.
+
+=item B<X509_V_ERR_CRL_HAS_EXPIRED: CRL has expired>
+
+the CRL has expired.
+
+=item B<X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD: format error in certificate's notBefore field>
+
+the certificate notBefore field contains an invalid time.
+
+=item B<X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD: format error in certificate's notAfter field>
+
+the certificate notAfter field contains an invalid time.
+
+=item B<X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD: format error in CRL's lastUpdate field>
+
+the CRL lastUpdate field contains an invalid time.
+
+=item B<X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD: format error in CRL's nextUpdate field>
+
+the CRL nextUpdate field contains an invalid time.
+
+=item B<X509_V_ERR_OUT_OF_MEM: out of memory>
+
+an error occurred trying to allocate memory. This should never happen.
+
+=item B<X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: self signed certificate>
+
+the passed certificate is self signed and the same certificate cannot be found
+in the list of trusted certificates.
+
+=item B<X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN: self signed certificate in certificate chain>
+
+the certificate chain could be built up using the untrusted certificates but
+the root could not be found locally.
+
+=item B<X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY: unable to get local issuer certificate>
+
+the issuer certificate of a locally looked up certificate could not be found.
+This normally means the list of trusted certificates is not complete.
+
+=item B<X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE: unable to verify the first certificate>
+
+no signatures could be verified because the chain contains only one certificate
+and it is not self signed.
+
+=item B<X509_V_ERR_CERT_CHAIN_TOO_LONG: certificate chain too long>
+
+the certificate chain length is greater than the supplied maximum depth. Unused.
+
+=item B<X509_V_ERR_CERT_REVOKED: certificate revoked>
+
+the certificate has been revoked.
+
+=item B<X509_V_ERR_INVALID_CA: invalid CA certificate>
+
+a CA certificate is invalid. Either it is not a CA or its extensions are not
+consistent with the supplied purpose.
+
+=item B<X509_V_ERR_PATH_LENGTH_EXCEEDED: path length constraint exceeded>
+
+the basicConstraints pathlength parameter has been exceeded.
+
+=item B<X509_V_ERR_INVALID_PURPOSE: unsupported certificate purpose>
+
+the supplied certificate cannot be used for the specified purpose.
+
+=item B<X509_V_ERR_CERT_UNTRUSTED: certificate not trusted>
+
+the root CA is not marked as trusted for the specified purpose.
+
+=item B<X509_V_ERR_CERT_REJECTED: certificate rejected>
+
+the root CA is marked to reject the specified purpose.
+
+=item B<X509_V_ERR_SUBJECT_ISSUER_MISMATCH: subject issuer mismatch>
+
+the current candidate issuer certificate was rejected because its subject name
+did not match the issuer name of the current certificate. This is only set
+if issuer check debugging is enabled it is used for status notification and
+is B<not> in itself an error.
+
+=item B<X509_V_ERR_AKID_SKID_MISMATCH: authority and subject key identifier mismatch>
+
+the current candidate issuer certificate was rejected because its subject key
+identifier was present and did not match the authority key identifier current
+certificate. This is only set if issuer check debugging is enabled it is used
+for status notification and is B<not> in itself an error.
+
+=item B<X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH: authority and issuer serial number mismatch>
+
+the current candidate issuer certificate was rejected because its issuer name
+and serial number was present and did not match the authority key identifier of
+the current certificate. This is only set if issuer check debugging is enabled
+it is used for status notification and is B<not> in itself an error.
+
+=item B<X509_V_ERR_KEYUSAGE_NO_CERTSIGN:key usage does not include certificate signing>
+
+the current candidate issuer certificate was rejected because its keyUsage
+extension does not permit certificate signing. This is only set if issuer check
+debugging is enabled it is used for status notification and is B<not> in itself
+an error.
+
+=item B<X509_V_ERR_INVALID_EXTENSION: invalid or inconsistent certificate extension>
+
+A certificate extension had an invalid value (for example an incorrect
+encoding) or some value inconsistent with other extensions.
+
+
+=item B<X509_V_ERR_INVALID_POLICY_EXTENSION: invalid or inconsistent certificate policy extension>
+
+A certificate policies extension had an invalid value (for example an incorrect
+encoding) or some value inconsistent with other extensions. This error only
+occurs if policy processing is enabled.
+
+=item B<X509_V_ERR_NO_EXPLICIT_POLICY: no explicit policy>
+
+The verification flags were set to require and explicit policy but none was
+present.
+
+=item B<X509_V_ERR_DIFFERENT_CRL_SCOPE: Different CRL scope>
+
+The only CRLs that could be found did not match the scope of the certificate.
+
+=item B<X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE: Unsupported extension feature>
+
+Some feature of a certificate extension is not supported. Unused.
+
+=item B<X509_V_ERR_PERMITTED_VIOLATION: permitted subtree violation>
+
+A name constraint violation occured in the permitted subtrees.
+
+=item B<X509_V_ERR_EXCLUDED_VIOLATION: excluded subtree violation>
+
+A name constraint violation occured in the excluded subtrees.
+
+=item B<X509_V_ERR_SUBTREE_MINMAX: name constraints minimum and maximum not supported>
+
+A certificate name constraints extension included a minimum or maximum field:
+this is not supported.
+
+=item B<X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE: unsupported name constraint type>
+
+An unsupported name constraint type was encountered. OpenSSL currently only
+supports directory name, DNS name, email and URI types.
+
+=item B<X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX: unsupported or invalid name constraint syntax>
+
+The format of the name constraint is not recognised: for example an email
+address format of a form not mentioned in RFC3280. This could be caused by
+a garbage extension or some new feature not currently supported.
+
+=item B<X509_V_ERR_CRL_PATH_VALIDATION_ERROR: CRL path validation error>
+
+An error occured when attempting to verify the CRL path. This error can only
+happen if extended CRL checking is enabled.
+
+=item B<X509_V_ERR_APPLICATION_VERIFICATION: application verification failure>
+
+an application specific error. This will never be returned unless explicitly
+set by an application.
+
+=head1 NOTES
+
+The above functions should be used instead of directly referencing the fields
+in the B<X509_VERIFY_CTX> structure.
+
+In versions of OpenSSL before 1.0 the current certificate returned by
+X509_STORE_CTX_get_current_cert() was never B<NULL>. Applications should
+check the return value before printing out any debugging information relating
+to the current certificate.
+
+If an unrecognised error code is passed to X509_verify_cert_error_string() the
+numerical value of the unknown code is returned in a static buffer. This is not
+thread safe but will never happen unless an invalid code is passed.
+
+=head1 SEE ALSO
+
+L<X509_verify_cert(3)|X509_verify_cert(3)>
+
+=head1 HISTORY
+
+TBA
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/X509_STORE_CTX_get_ex_new_index.pod b/deps/openssl/openssl/doc/crypto/X509_STORE_CTX_get_ex_new_index.pod
new file mode 100644 (file)
index 0000000..8d6b9dd
--- /dev/null
@@ -0,0 +1,41 @@
+=pod
+
+=head1 NAME
+
+X509_STORE_CTX_get_ex_new_index, X509_STORE_CTX_set_ex_data, X509_STORE_CTX_get_ex_data - add application specific data to X509_STORE_CTX structures
+
+=head1 SYNOPSIS
+
+ #include <openssl/x509_vfy.h>
+
+ int X509_STORE_CTX_get_ex_new_index(long argl, void *argp,
+               CRYPTO_EX_new *new_func,
+               CRYPTO_EX_dup *dup_func,
+               CRYPTO_EX_free *free_func);
+
+ int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *d, int idx, void *arg);
+
+ char *X509_STORE_CTX_get_ex_data(X509_STORE_CTX *d, int idx);
+
+=head1 DESCRIPTION
+
+These functions handle application specific data in X509_STORE_CTX structures.
+Their usage is identical to that of RSA_get_ex_new_index(), RSA_set_ex_data()
+and RSA_get_ex_data() as described in L<RSA_get_ex_new_index(3)>.
+
+=head1 NOTES
+
+This mechanism is used internally by the B<ssl> library to store the B<SSL>
+structure associated with a verification operation in an B<X509_STORE_CTX>
+structure. 
+
+=head1 SEE ALSO
+
+L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>
+
+=head1 HISTORY
+
+X509_STORE_CTX_get_ex_new_index(), X509_STORE_CTX_set_ex_data() and
+X509_STORE_CTX_get_ex_data() are available since OpenSSL 0.9.5.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/X509_STORE_CTX_new.pod b/deps/openssl/openssl/doc/crypto/X509_STORE_CTX_new.pod
new file mode 100644 (file)
index 0000000..b17888f
--- /dev/null
@@ -0,0 +1,122 @@
+=pod
+
+=head1 NAME
+
+X509_STORE_CTX_new, X509_STORE_CTX_cleanup, X509_STORE_CTX_free, X509_STORE_CTX_init, X509_STORE_CTX_trusted_stack, X509_STORE_CTX_set_cert, X509_STORE_CTX_set_chain, X509_STORE_CTX_set0_crls, X509_STORE_CTX_get0_param, X509_STORE_CTX_set0_param, X509_STORE_CTX_set_default - X509_STORE_CTX initialisation
+
+=head1 SYNOPSIS
+
+ #include <openssl/x509_vfy.h>
+
+ X509_STORE_CTX *X509_STORE_CTX_new(void);
+ void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx);
+ void X509_STORE_CTX_free(X509_STORE_CTX *ctx);
+
+ int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store,
+                        X509 *x509, STACK_OF(X509) *chain);
+
+ void X509_STORE_CTX_trusted_stack(X509_STORE_CTX *ctx, STACK_OF(X509) *sk);
+
+ void  X509_STORE_CTX_set_cert(X509_STORE_CTX *ctx,X509 *x);
+ void  X509_STORE_CTX_set_chain(X509_STORE_CTX *ctx,STACK_OF(X509) *sk);
+ void  X509_STORE_CTX_set0_crls(X509_STORE_CTX *ctx, STACK_OF(X509_CRL) *sk);
+
+ X509_VERIFY_PARAM *X509_STORE_CTX_get0_param(X509_STORE_CTX *ctx);
+ void X509_STORE_CTX_set0_param(X509_STORE_CTX *ctx, X509_VERIFY_PARAM *param);
+ int X509_STORE_CTX_set_default(X509_STORE_CTX *ctx, const char *name);
+
+=head1 DESCRIPTION
+
+These functions initialise an B<X509_STORE_CTX> structure for subsequent use
+by X509_verify_cert().
+
+X509_STORE_CTX_new() returns a newly initialised B<X509_STORE_CTX> structure.
+
+X509_STORE_CTX_cleanup() internally cleans up an B<X509_STORE_CTX> structure.
+The context can then be reused with an new call to X509_STORE_CTX_init().
+
+X509_STORE_CTX_free() completely frees up B<ctx>. After this call B<ctx>
+is no longer valid.
+
+X509_STORE_CTX_init() sets up B<ctx> for a subsequent verification operation.
+The trusted certificate store is set to B<store>, the end entity certificate
+to be verified is set to B<x509> and a set of additional certificates (which
+will be untrusted but may be used to build the chain) in B<chain>. Any or
+all of the B<store>, B<x509> and B<chain> parameters can be B<NULL>.
+
+X509_STORE_CTX_trusted_stack() sets the set of trusted certificates of B<ctx>
+to B<sk>. This is an alternative way of specifying trusted certificates 
+instead of using an B<X509_STORE>.
+
+X509_STORE_CTX_set_cert() sets the certificate to be vertified in B<ctx> to
+B<x>.
+
+X509_STORE_CTX_set_chain() sets the additional certificate chain used by B<ctx>
+to B<sk>.
+
+X509_STORE_CTX_set0_crls() sets a set of CRLs to use to aid certificate
+verification to B<sk>. These CRLs will only be used if CRL verification is
+enabled in the associated B<X509_VERIFY_PARAM> structure. This might be
+used where additional "useful" CRLs are supplied as part of a protocol,
+for example in a PKCS#7 structure.
+
+X509_VERIFY_PARAM *X509_STORE_CTX_get0_param() retrieves an intenal pointer
+to the verification parameters associated with B<ctx>.
+
+X509_STORE_CTX_set0_param() sets the intenal verification parameter pointer
+to B<param>. After this call B<param> should not be used.
+
+X509_STORE_CTX_set_default() looks up and sets the default verification
+method to B<name>. This uses the function X509_VERIFY_PARAM_lookup() to
+find an appropriate set of parameters from B<name>.
+
+=head1 NOTES
+
+The certificates and CRLs in a store are used internally and should B<not>
+be freed up until after the associated B<X509_STORE_CTX> is freed. Legacy
+applications might implicitly use an B<X509_STORE_CTX> like this:
+
+  X509_STORE_CTX ctx;
+  X509_STORE_CTX_init(&ctx, store, cert, chain);
+
+this is B<not> recommended in new applications they should instead do:
+
+  X509_STORE_CTX *ctx;
+  ctx = X509_STORE_CTX_new();
+  if (ctx == NULL)
+       /* Bad error */
+  X509_STORE_CTX_init(ctx, store, cert, chain);
+
+=head1 BUGS
+
+The certificates and CRLs in a context are used internally and should B<not>
+be freed up until after the associated B<X509_STORE_CTX> is freed. Copies
+should be made or reference counts increased instead.
+
+=head1 RETURN VALUES
+
+X509_STORE_CTX_new() returns an newly allocates context or B<NULL> is an
+error occurred.
+
+X509_STORE_CTX_init() returns 1 for success or 0 if an error occurred.
+
+X509_STORE_CTX_get0_param() returns a pointer to an B<X509_VERIFY_PARAM>
+structure or B<NULL> if an error occurred.
+
+X509_STORE_CTX_cleanup(), X509_STORE_CTX_free(), X509_STORE_CTX_trusted_stack(),
+X509_STORE_CTX_set_cert(), X509_STORE_CTX_set_chain(),
+X509_STORE_CTX_set0_crls() and X509_STORE_CTX_set0_param() do not return
+values.
+
+X509_STORE_CTX_set_default() returns 1 for success or 0 if an error occurred.
+
+=head1 SEE ALSO
+
+L<X509_verify_cert(3)|X509_verify_cert(3)>
+L<X509_VERIFY_PARAM_set_flags(3)|X509_VERIFY_PARAM_set_flags(3)>
+
+=head1 HISTORY
+
+X509_STORE_CTX_set0_crls() was first added to OpenSSL 1.0.0
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/X509_STORE_CTX_set_verify_cb.pod b/deps/openssl/openssl/doc/crypto/X509_STORE_CTX_set_verify_cb.pod
new file mode 100644 (file)
index 0000000..b9787a6
--- /dev/null
@@ -0,0 +1,161 @@
+=pod
+
+=head1 NAME
+
+X509_STORE_CTX_set_verify_cb - set verification callback
+
+=head1 SYNOPSIS
+
+ #include <openssl/x509_vfy.h>
+
+ void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx,
+                               int (*verify_cb)(int ok, X509_STORE_CTX *ctx));
+
+=head1 DESCRIPTION
+
+X509_STORE_CTX_set_verify_cb() sets the verification callback of B<ctx> to
+B<verify_cb> overwriting any existing callback.
+
+The verification callback can be used to customise the operation of certificate
+verification, either by overriding error conditions or logging errors for
+debugging purposes.
+
+However a verification callback is B<not> essential and the default operation
+is often sufficient.
+
+The B<ok> parameter to the callback indicates the value the callback should
+return to retain the default behaviour. If it is zero then and error condition
+is indicated. If it is 1 then no error occurred. If the flag
+B<X509_V_FLAG_NOTIFY_POLICY> is set then B<ok> is set to 2 to indicate the
+policy checking is complete.
+
+The B<ctx> parameter to the callback is the B<X509_STORE_CTX> structure that
+is performing the verification operation. A callback can examine this
+structure and receive additional information about the error, for example
+by calling X509_STORE_CTX_get_current_cert(). Additional application data can
+be passed to the callback via the B<ex_data> mechanism.
+
+=head1 WARNING
+
+In general a verification callback should B<NOT> unconditionally return 1 in
+all circumstances because this will allow verification to succeed no matter
+what the error. This effectively removes all security from the application
+because B<any> certificate (including untrusted generated ones) will be
+accepted.
+
+=head1 NOTES
+
+The verification callback can be set and inherited from the parent structure
+performing the operation. In some cases (such as S/MIME verification) the
+B<X509_STORE_CTX> structure is created and destroyed internally and the
+only way to set a custom verification callback is by inheriting it from the
+associated B<X509_STORE>.
+
+=head1 RETURN VALUES
+
+X509_STORE_CTX_set_verify_cb() does not return a value.
+
+=head1 EXAMPLES
+
+Default callback operation:
+
+ int verify_callback(int ok, X509_STORE_CTX *ctx)
+       {
+       return ok;
+       }
+
+Simple example, suppose a certificate in the chain is expired and we wish
+to continue after this error:
+
+ int verify_callback(int ok, X509_STORE_CTX *ctx)
+       {
+       /* Tolerate certificate expiration */
+       if (X509_STORE_CTX_get_error(ctx) == X509_V_ERR_CERT_HAS_EXPIRED)
+                       return 1;
+       /* Otherwise don't override */
+       return ok;
+       }
+
+More complex example, we don't wish to continue after B<any> certificate has
+expired just one specific case:
+
+ int verify_callback(int ok, X509_STORE_CTX *ctx)
+       {
+       int err = X509_STORE_CTX_get_error(ctx);
+       X509 *err_cert = X509_STORE_CTX_get_current_cert(ctx);
+       if (err == X509_V_ERR_CERT_HAS_EXPIRED)
+               {
+               if (check_is_acceptable_expired_cert(err_cert)
+                       return 1;
+               }
+       return ok;
+       }
+
+Full featured logging callback. In this case the B<bio_err> is assumed to be
+a global logging B<BIO>, an alternative would to store a BIO in B<ctx> using
+B<ex_data>.
+       
+ int verify_callback(int ok, X509_STORE_CTX *ctx)
+       {
+       X509 *err_cert;
+       int err,depth;
+
+       err_cert = X509_STORE_CTX_get_current_cert(ctx);
+       err =   X509_STORE_CTX_get_error(ctx);
+       depth = X509_STORE_CTX_get_error_depth(ctx);
+
+       BIO_printf(bio_err,"depth=%d ",depth);
+       if (err_cert)
+               {
+               X509_NAME_print_ex(bio_err, X509_get_subject_name(err_cert),
+                                       0, XN_FLAG_ONELINE);
+               BIO_puts(bio_err, "\n");
+               }
+       else
+               BIO_puts(bio_err, "<no cert>\n");
+       if (!ok)
+               BIO_printf(bio_err,"verify error:num=%d:%s\n",err,
+                       X509_verify_cert_error_string(err));
+       switch (err)
+               {
+       case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
+               BIO_puts(bio_err,"issuer= ");
+               X509_NAME_print_ex(bio_err, X509_get_issuer_name(err_cert),
+                                       0, XN_FLAG_ONELINE);
+               BIO_puts(bio_err, "\n");
+               break;
+       case X509_V_ERR_CERT_NOT_YET_VALID:
+       case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
+               BIO_printf(bio_err,"notBefore=");
+               ASN1_TIME_print(bio_err,X509_get_notBefore(err_cert));
+               BIO_printf(bio_err,"\n");
+               break;
+       case X509_V_ERR_CERT_HAS_EXPIRED:
+       case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
+               BIO_printf(bio_err,"notAfter=");
+               ASN1_TIME_print(bio_err,X509_get_notAfter(err_cert));
+               BIO_printf(bio_err,"\n");
+               break;
+       case X509_V_ERR_NO_EXPLICIT_POLICY:
+               policies_print(bio_err, ctx);
+               break;
+               }
+       if (err == X509_V_OK && ok == 2)
+               /* print out policies */
+
+       BIO_printf(bio_err,"verify return:%d\n",ok);
+       return(ok);
+       }
+
+=head1 SEE ALSO
+
+L<X509_STORE_CTX_get_error(3)|X509_STORE_CTX_get_error(3)>
+L<X509_STORE_set_verify_cb_func(3)|X509_STORE_set_verify_cb_func(3)>
+L<X509_STORE_CTX_get_ex_new_index(3)|X509_STORE_CTX_get_ex_new_index(3)>
+
+=head1 HISTORY
+
+X509_STORE_CTX_set_verify_cb() is available in all versions of SSLeay and
+OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/X509_STORE_set_verify_cb_func.pod b/deps/openssl/openssl/doc/crypto/X509_STORE_set_verify_cb_func.pod
new file mode 100644 (file)
index 0000000..29e3bbe
--- /dev/null
@@ -0,0 +1,54 @@
+=pod
+
+=head1 NAME
+
+X509_STORE_set_verify_cb_func, X509_STORE_set_verify_cb - set verification callback
+
+=head1 SYNOPSIS
+
+ #include <openssl/x509_vfy.h>
+
+ void X509_STORE_set_verify_cb(X509_STORE *st,
+                               int (*verify_cb)(int ok, X509_STORE_CTX *ctx));
+
+ void X509_STORE_set_verify_cb_func(X509_STORE *st,
+                               int (*verify_cb)(int ok, X509_STORE_CTX *ctx));
+
+=head1 DESCRIPTION
+
+X509_STORE_set_verify_cb() sets the verification callback of B<ctx> to
+B<verify_cb> overwriting any existing callback.
+
+X509_STORE_set_verify_cb_func() also sets the verification callback but it
+is implemented as a macro.
+
+=head1 NOTES
+
+The verification callback from an B<X509_STORE> is inherited by 
+the corresponding B<X509_STORE_CTX> structure when it is initialized. This can
+be used to set the verification callback when the B<X509_STORE_CTX> is 
+otherwise inaccessible (for example during S/MIME verification).
+
+=head1 BUGS
+
+The macro version of this function was the only one available before 
+OpenSSL 1.0.0.
+
+=head1 RETURN VALUES
+
+X509_STORE_set_verify_cb() and X509_STORE_set_verify_cb_func() do not return
+a value.
+
+=head1 SEE ALSO
+
+L<X509_STORE_CTX_set_verify_cb(3)|X509_STORE_CTX_set_verify_cb(3)>
+L<CMS_verify(3)|CMS_verify(3)>
+
+=head1 HISTORY
+
+X509_STORE_set_verify_cb_func() is available in all versions of SSLeay and
+OpenSSL.
+
+X509_STORE_set_verify_cb() was added to OpenSSL 1.0.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/X509_VERIFY_PARAM_set_flags.pod b/deps/openssl/openssl/doc/crypto/X509_VERIFY_PARAM_set_flags.pod
new file mode 100644 (file)
index 0000000..b68eece
--- /dev/null
@@ -0,0 +1,171 @@
+=pod
+
+=head1 NAME
+
+X509_VERIFY_PARAM_set_flags, X509_VERIFY_PARAM_clear_flags, X509_VERIFY_PARAM_get_flags, X509_VERIFY_PARAM_set_purpose, X509_VERIFY_PARAM_set_trust, X509_VERIFY_PARAM_set_depth, X509_VERIFY_PARAM_get_depth, X509_VERIFY_PARAM_set_time, X509_VERIFY_PARAM_add0_policy, X509_VERIFY_PARAM_set1_policies - X509 verification parameters 
+
+=head1 SYNOPSIS
+
+ #include <openssl/x509_vfy.h>
+
+ int X509_VERIFY_PARAM_set_flags(X509_VERIFY_PARAM *param, unsigned long flags);
+ int X509_VERIFY_PARAM_clear_flags(X509_VERIFY_PARAM *param,
+                                                       unsigned long flags);
+ unsigned long X509_VERIFY_PARAM_get_flags(X509_VERIFY_PARAM *param);
+
+ int X509_VERIFY_PARAM_set_purpose(X509_VERIFY_PARAM *param, int purpose);
+ int X509_VERIFY_PARAM_set_trust(X509_VERIFY_PARAM *param, int trust);
+
+ void X509_VERIFY_PARAM_set_time(X509_VERIFY_PARAM *param, time_t t);
+
+ int X509_VERIFY_PARAM_add0_policy(X509_VERIFY_PARAM *param,
+                                               ASN1_OBJECT *policy);
+ int X509_VERIFY_PARAM_set1_policies(X509_VERIFY_PARAM *param, 
+                                       STACK_OF(ASN1_OBJECT) *policies);
+
+ void X509_VERIFY_PARAM_set_depth(X509_VERIFY_PARAM *param, int depth);
+ int X509_VERIFY_PARAM_get_depth(const X509_VERIFY_PARAM *param);
+
+=head1 DESCRIPTION
+
+These functions manipulate the B<X509_VERIFY_PARAM> structure associated with
+a certificate verification operation. 
+
+The X509_VERIFY_PARAM_set_flags() function sets the flags in B<param> by oring
+it with B<flags>. See the B<VERIFICATION FLAGS> section for a complete
+description of values the B<flags> parameter can take.
+
+X509_VERIFY_PARAM_get_flags() returns the flags in B<param>.
+
+X509_VERIFY_PARAM_clear_flags() clears the flags B<flags> in B<param>.
+
+X509_VERIFY_PARAM_set_purpose() sets the verification purpose in B<param>
+to B<purpose>. This determines the acceptable purpose of the certificate
+chain, for example SSL client or SSL server.
+
+X509_VERIFY_PARAM_set_trust() sets the trust setting in B<param> to 
+B<trust>.
+
+X509_VERIFY_PARAM_set_time() sets the verification time in B<param> to
+B<t>. Normally the current time is used.
+
+X509_VERIFY_PARAM_add0_policy() enables policy checking (it is disabled
+by default) and adds B<policy> to the acceptable policy set.
+
+X509_VERIFY_PARAM_set1_policies() enables policy checking (it is disabled
+by default) and sets the acceptable policy set to B<policies>. Any existing
+policy set is cleared. The B<policies> parameter can be B<NULL> to clear
+an existing policy set.
+
+X509_VERIFY_PARAM_set_depth() sets the maximum verification depth to B<depth>.
+That is the maximum number of untrusted CA certificates that can appear in a
+chain.
+
+=head1 RETURN VALUES
+
+X509_VERIFY_PARAM_set_flags(), X509_VERIFY_PARAM_clear_flags(), 
+X509_VERIFY_PARAM_set_purpose(), X509_VERIFY_PARAM_set_trust(),
+X509_VERIFY_PARAM_add0_policy() and X509_VERIFY_PARAM_set1_policies() return 1
+for success and 0 for failure. 
+
+X509_VERIFY_PARAM_get_flags() returns the current verification flags.
+
+X509_VERIFY_PARAM_set_time() and X509_VERIFY_PARAM_set_depth() do not return
+values.
+
+X509_VERIFY_PARAM_get_depth() returns the current verification depth.
+
+=head1 VERIFICATION FLAGS
+
+The verification flags consists of zero or more of the following flags
+ored together.
+
+B<X509_V_FLAG_CRL_CHECK> enables CRL checking for the certificate chain leaf
+certificate. An error occurs if a suitable CRL cannot be found. 
+
+B<X509_V_FLAG_CRL_CHECK_ALL> enables CRL checking for the entire certificate
+chain.
+
+B<X509_V_FLAG_IGNORE_CRITICAL> disabled critical extension checking. By default
+any unhandled critical extensions in certificates or (if checked) CRLs results
+in a fatal error. If this flag is set unhandled critical extensions are
+ignored. B<WARNING> setting this option for anything other than debugging
+purposes can be a security risk. Finer control over which extensions are
+supported can be performed in the verification callback.
+
+THe B<X509_V_FLAG_X509_STRICT> flag disables workarounds for some broken
+certificates and makes the verification strictly apply B<X509> rules.
+
+B<X509_V_FLAG_ALLOW_PROXY_CERTS> enables proxy certificate verification.
+
+B<X509_V_FLAG_POLICY_CHECK> enables certificate policy checking, by default
+no policy checking is peformed. Additional information is sent to the 
+verification callback relating to policy checking.
+
+B<X509_V_FLAG_EXPLICIT_POLICY>, B<X509_V_FLAG_INHIBIT_ANY> and
+B<X509_V_FLAG_INHIBIT_MAP> set the B<require explicit policy>, B<inhibit any
+policy> and B<inhibit policy mapping> flags respectively as defined in
+B<RFC3280>. Policy checking is automatically enabled if any of these flags
+are set.
+
+If B<X509_V_FLAG_NOTIFY_POLICY> is set and the policy checking is successful
+a special status code is set to the verification callback. This permits it
+to examine the valid policy tree and perform additional checks or simply
+log it for debugging purposes.
+
+By default some addtional features such as indirect CRLs and CRLs signed by
+different keys are disabled. If B<X509_V_FLAG_EXTENDED_CRL_SUPPORT> is set
+they are enabled.
+
+If B<X509_V_FLAG_USE_DELTAS> ise set delta CRLs (if present) are used to
+determine certificate status. If not set deltas are ignored.
+
+B<X509_V_FLAG_CHECK_SS_SIGNATURE> enables checking of the root CA self signed
+cerificate signature. By default this check is disabled because it doesn't
+add any additional security but in some cases applications might want to
+check the signature anyway. A side effect of not checking the root CA
+signature is that disabled or unsupported message digests on the root CA
+are not treated as fatal errors.
+
+The B<X509_V_FLAG_CB_ISSUER_CHECK> flag enables debugging of certificate
+issuer checks. It is B<not> needed unless you are logging certificate
+verification. If this flag is set then additional status codes will be sent
+to the verification callback and it B<must> be prepared to handle such cases
+without assuming they are hard errors.
+
+=head1 NOTES
+
+The above functions should be used to manipulate verification parameters
+instead of legacy functions which work in specific structures such as
+X509_STORE_CTX_set_flags().
+
+=head1 BUGS
+
+Delta CRL checking is currently primitive. Only a single delta can be used and
+(partly due to limitations of B<X509_STORE>) constructed CRLs are not 
+maintained.
+
+If CRLs checking is enable CRLs are expected to be available in the
+corresponding B<X509_STORE> structure. No attempt is made to download
+CRLs from the CRL distribution points extension.
+
+=head1 EXAMPLE
+
+Enable CRL checking when performing certificate verification during SSL 
+connections associated with an B<SSL_CTX> structure B<ctx>:
+
+  X509_VERIFY_PARAM *param;
+  param = X509_VERIFY_PARAM_new();
+  X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_CRL_CHECK);
+  SSL_CTX_set1_param(ctx, param);
+  X509_VERIFY_PARAM_free(param);
+
+=head1 SEE ALSO
+
+L<X509_verify_cert(3)|X509_verify_cert(3)>
+
+=head1 HISTORY
+
+TBA
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/X509_new.pod b/deps/openssl/openssl/doc/crypto/X509_new.pod
new file mode 100644 (file)
index 0000000..d388723
--- /dev/null
@@ -0,0 +1,39 @@
+=pod
+
+=head1 NAME
+
+X509_new, X509_free - X509 certificate ASN1 allocation functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/x509.h>
+
+ X509 *X509_new(void);
+ void X509_free(X509 *a);
+
+=head1 DESCRIPTION
+
+The X509 ASN1 allocation routines, allocate and free an
+X509 structure, which represents an X509 certificate.
+
+X509_new() allocates and initializes a X509 structure.
+
+X509_free() frees up the B<X509> structure B<a>.
+
+=head1 RETURN VALUES
+
+If the allocation fails, X509_new() returns B<NULL> and sets an error
+code that can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+Otherwise it returns a pointer to the newly allocated structure.
+
+X509_free() returns no value.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<d2i_X509(3)|d2i_X509(3)>
+
+=head1 HISTORY
+
+X509_new() and X509_free() are available in all versions of SSLeay and OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/X509_verify_cert.pod b/deps/openssl/openssl/doc/crypto/X509_verify_cert.pod
new file mode 100644 (file)
index 0000000..5253bdc
--- /dev/null
@@ -0,0 +1,53 @@
+=pod
+
+=head1 NAME
+
+X509_verify_cert - discover and verify X509 certificte chain
+
+=head1 SYNOPSIS
+
+ #include <openssl/x509.h>
+
+ int X509_verify_cert(X509_STORE_CTX *ctx);
+
+=head1 DESCRIPTION
+
+The X509_verify_cert() function attempts to discover and validate a
+certificate chain based on parameters in B<ctx>. A complete description of
+the process is contained in the L<verify(1)|verify(1)> manual page.
+
+=head1 RETURN VALUES
+
+If a complete chain can be built and validated this function returns 1,
+otherwise it return zero, in exceptional circumstances it can also
+return a negative code.
+
+If the function fails additional error information can be obtained by
+examining B<ctx> using, for example X509_STORE_CTX_get_error().
+
+=head1 NOTES
+
+Applications rarely call this function directly but it is used by
+OpenSSL internally for certificate validation, in both the S/MIME and
+SSL/TLS code.
+
+The negative return value from X509_verify_cert() can only occur if no
+certificate is set in B<ctx> (due to a programming error) or if a retry
+operation is requested during internal lookups (which never happens with
+standard lookup methods). It is however recommended that application check
+for <= 0 return value on error.
+
+=head1 BUGS
+
+This function uses the header B<x509.h> as opposed to most chain verification
+functiosn which use B<x509_vfy.h>.
+
+=head1 SEE ALSO
+
+L<X509_STORE_CTX_get_error(3)|X509_STORE_CTX_get_error(3)>
+
+=head1 HISTORY
+
+X509_verify_cert() is available in all versions of SSLeay and OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/bio.pod b/deps/openssl/openssl/doc/crypto/bio.pod
new file mode 100644 (file)
index 0000000..f923922
--- /dev/null
@@ -0,0 +1,54 @@
+=pod
+
+=head1 NAME
+
+bio - I/O abstraction
+
+=head1 SYNOPSIS
+
+ #include <openssl/bio.h>
+
+TBA
+
+
+=head1 DESCRIPTION
+
+A BIO is an I/O abstraction, it hides many of the underlying I/O
+details from an application. If an application uses a BIO for its
+I/O it can transparently handle SSL connections, unencrypted network
+connections and file I/O.
+
+There are two type of BIO, a source/sink BIO and a filter BIO.
+
+As its name implies a source/sink BIO is a source and/or sink of data,
+examples include a socket BIO and a file BIO.
+
+A filter BIO takes data from one BIO and passes it through to
+another, or the application. The data may be left unmodified (for
+example a message digest BIO) or translated (for example an
+encryption BIO). The effect of a filter BIO may change according
+to the I/O operation it is performing: for example an encryption
+BIO will encrypt data if it is being written to and decrypt data
+if it is being read from.
+
+BIOs can be joined together to form a chain (a single BIO is a chain
+with one component). A chain normally consist of one source/sink
+BIO and one or more filter BIOs. Data read from or written to the
+first BIO then traverses the chain to the end (normally a source/sink
+BIO).
+
+=head1 SEE ALSO
+
+L<BIO_ctrl(3)|BIO_ctrl(3)>,
+L<BIO_f_base64(3)|BIO_f_base64(3)>, L<BIO_f_buffer(3)|BIO_f_buffer(3)>,
+L<BIO_f_cipher(3)|BIO_f_cipher(3)>, L<BIO_f_md(3)|BIO_f_md(3)>,
+L<BIO_f_null(3)|BIO_f_null(3)>, L<BIO_f_ssl(3)|BIO_f_ssl(3)>,
+L<BIO_find_type(3)|BIO_find_type(3)>, L<BIO_new(3)|BIO_new(3)>,
+L<BIO_new_bio_pair(3)|BIO_new_bio_pair(3)>,
+L<BIO_push(3)|BIO_push(3)>, L<BIO_read(3)|BIO_read(3)>,
+L<BIO_s_accept(3)|BIO_s_accept(3)>, L<BIO_s_bio(3)|BIO_s_bio(3)>,
+L<BIO_s_connect(3)|BIO_s_connect(3)>, L<BIO_s_fd(3)|BIO_s_fd(3)>,
+L<BIO_s_file(3)|BIO_s_file(3)>, L<BIO_s_mem(3)|BIO_s_mem(3)>,
+L<BIO_s_null(3)|BIO_s_null(3)>, L<BIO_s_socket(3)|BIO_s_socket(3)>,
+L<BIO_set_callback(3)|BIO_set_callback(3)>,
+L<BIO_should_retry(3)|BIO_should_retry(3)>
diff --git a/deps/openssl/openssl/doc/crypto/blowfish.pod b/deps/openssl/openssl/doc/crypto/blowfish.pod
new file mode 100644 (file)
index 0000000..5b2d274
--- /dev/null
@@ -0,0 +1,112 @@
+=pod
+
+=head1 NAME
+
+blowfish, BF_set_key, BF_encrypt, BF_decrypt, BF_ecb_encrypt, BF_cbc_encrypt,
+BF_cfb64_encrypt, BF_ofb64_encrypt, BF_options - Blowfish encryption
+
+=head1 SYNOPSIS
+
+ #include <openssl/blowfish.h>
+
+ void BF_set_key(BF_KEY *key, int len, const unsigned char *data);
+
+ void BF_ecb_encrypt(const unsigned char *in, unsigned char *out,
+         BF_KEY *key, int enc);
+ void BF_cbc_encrypt(const unsigned char *in, unsigned char *out,
+        long length, BF_KEY *schedule, unsigned char *ivec, int enc);
+ void BF_cfb64_encrypt(const unsigned char *in, unsigned char *out,
+        long length, BF_KEY *schedule, unsigned char *ivec, int *num,
+         int enc);
+ void BF_ofb64_encrypt(const unsigned char *in, unsigned char *out,
+        long length, BF_KEY *schedule, unsigned char *ivec, int *num);
+ const char *BF_options(void);
+
+ void BF_encrypt(BF_LONG *data,const BF_KEY *key);
+ void BF_decrypt(BF_LONG *data,const BF_KEY *key);
+
+=head1 DESCRIPTION
+
+This library implements the Blowfish cipher, which was invented and described
+by Counterpane (see http://www.counterpane.com/blowfish.html ).
+
+Blowfish is a block cipher that operates on 64 bit (8 byte) blocks of data.
+It uses a variable size key, but typically, 128 bit (16 byte) keys are
+considered good for strong encryption.  Blowfish can be used in the same
+modes as DES (see L<des_modes(7)|des_modes(7)>).  Blowfish is currently one
+of the faster block ciphers.  It is quite a bit faster than DES, and much
+faster than IDEA or RC2.
+
+Blowfish consists of a key setup phase and the actual encryption or decryption
+phase.
+
+BF_set_key() sets up the B<BF_KEY> B<key> using the B<len> bytes long key
+at B<data>.
+
+BF_ecb_encrypt() is the basic Blowfish encryption and decryption function.
+It encrypts or decrypts the first 64 bits of B<in> using the key B<key>,
+putting the result in B<out>.  B<enc> decides if encryption (B<BF_ENCRYPT>)
+or decryption (B<BF_DECRYPT>) shall be performed.  The vector pointed at by
+B<in> and B<out> must be 64 bits in length, no less.  If they are larger,
+everything after the first 64 bits is ignored.
+
+The mode functions BF_cbc_encrypt(), BF_cfb64_encrypt() and BF_ofb64_encrypt()
+all operate on variable length data.  They all take an initialization vector
+B<ivec> which needs to be passed along into the next call of the same function 
+for the same message.  B<ivec> may be initialized with anything, but the
+recipient needs to know what it was initialized with, or it won't be able
+to decrypt.  Some programs and protocols simplify this, like SSH, where
+B<ivec> is simply initialized to zero.
+BF_cbc_encrypt() operates on data that is a multiple of 8 bytes long, while
+BF_cfb64_encrypt() and BF_ofb64_encrypt() are used to encrypt an variable
+number of bytes (the amount does not have to be an exact multiple of 8).  The
+purpose of the latter two is to simulate stream ciphers, and therefore, they
+need the parameter B<num>, which is a pointer to an integer where the current
+offset in B<ivec> is stored between calls.  This integer must be initialized
+to zero when B<ivec> is initialized.
+
+BF_cbc_encrypt() is the Cipher Block Chaining function for Blowfish.  It
+encrypts or decrypts the 64 bits chunks of B<in> using the key B<schedule>,
+putting the result in B<out>.  B<enc> decides if encryption (BF_ENCRYPT) or
+decryption (BF_DECRYPT) shall be performed.  B<ivec> must point at an 8 byte
+long initialization vector.
+
+BF_cfb64_encrypt() is the CFB mode for Blowfish with 64 bit feedback.
+It encrypts or decrypts the bytes in B<in> using the key B<schedule>,
+putting the result in B<out>.  B<enc> decides if encryption (B<BF_ENCRYPT>)
+or decryption (B<BF_DECRYPT>) shall be performed.  B<ivec> must point at an
+8 byte long initialization vector. B<num> must point at an integer which must
+be initially zero.
+
+BF_ofb64_encrypt() is the OFB mode for Blowfish with 64 bit feedback.
+It uses the same parameters as BF_cfb64_encrypt(), which must be initialized
+the same way.
+
+BF_encrypt() and BF_decrypt() are the lowest level functions for Blowfish
+encryption.  They encrypt/decrypt the first 64 bits of the vector pointed by
+B<data>, using the key B<key>.  These functions should not be used unless you
+implement 'modes' of Blowfish.  The alternative is to use BF_ecb_encrypt().
+If you still want to use these functions, you should be aware that they take
+each 32-bit chunk in host-byte order, which is little-endian on little-endian
+platforms and big-endian on big-endian ones.
+
+=head1 RETURN VALUES
+
+None of the functions presented here return any value.
+
+=head1 NOTE
+
+Applications should use the higher level functions
+L<EVP_EncryptInit(3)|EVP_EncryptInit(3)> etc. instead of calling the
+blowfish functions directly.
+
+=head1 SEE ALSO
+
+L<des_modes(7)|des_modes(7)>
+
+=head1 HISTORY
+
+The Blowfish functions are available in all versions of SSLeay and OpenSSL.
+
+=cut
+
diff --git a/deps/openssl/openssl/doc/crypto/bn.pod b/deps/openssl/openssl/doc/crypto/bn.pod
new file mode 100644 (file)
index 0000000..cd2f8e5
--- /dev/null
@@ -0,0 +1,181 @@
+=pod
+
+=head1 NAME
+
+bn - multiprecision integer arithmetics
+
+=head1 SYNOPSIS
+
+ #include <openssl/bn.h>
+
+ BIGNUM *BN_new(void);
+ void BN_free(BIGNUM *a);
+ void BN_init(BIGNUM *);
+ void BN_clear(BIGNUM *a);
+ void BN_clear_free(BIGNUM *a);
+
+ BN_CTX *BN_CTX_new(void);
+ void BN_CTX_init(BN_CTX *c);
+ void BN_CTX_free(BN_CTX *c);
+
+ BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b);
+ BIGNUM *BN_dup(const BIGNUM *a);
+
+ BIGNUM *BN_swap(BIGNUM *a, BIGNUM *b);
+
+ int BN_num_bytes(const BIGNUM *a);
+ int BN_num_bits(const BIGNUM *a);
+ int BN_num_bits_word(BN_ULONG w);
+
+ void BN_set_negative(BIGNUM *a, int n);
+ int  BN_is_negative(const BIGNUM *a);
+
+ int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
+ int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
+ int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
+ int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx);
+ int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *a, const BIGNUM *d,
+         BN_CTX *ctx);
+ int BN_mod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
+ int BN_nnmod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
+ int BN_mod_add(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
+         BN_CTX *ctx);
+ int BN_mod_sub(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
+         BN_CTX *ctx);
+ int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
+         BN_CTX *ctx);
+ int BN_mod_sqr(BIGNUM *ret, BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
+ int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx);
+ int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
+         const BIGNUM *m, BN_CTX *ctx);
+ int BN_gcd(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
+
+ int BN_add_word(BIGNUM *a, BN_ULONG w);
+ int BN_sub_word(BIGNUM *a, BN_ULONG w);
+ int BN_mul_word(BIGNUM *a, BN_ULONG w);
+ BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);
+ BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w);
+
+ int BN_cmp(BIGNUM *a, BIGNUM *b);
+ int BN_ucmp(BIGNUM *a, BIGNUM *b);
+ int BN_is_zero(BIGNUM *a);
+ int BN_is_one(BIGNUM *a);
+ int BN_is_word(BIGNUM *a, BN_ULONG w);
+ int BN_is_odd(BIGNUM *a);
+
+ int BN_zero(BIGNUM *a);
+ int BN_one(BIGNUM *a);
+ const BIGNUM *BN_value_one(void);
+ int BN_set_word(BIGNUM *a, unsigned long w);
+ unsigned long BN_get_word(BIGNUM *a);
+
+ int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
+ int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom);
+ int BN_rand_range(BIGNUM *rnd, BIGNUM *range);
+ int BN_pseudo_rand_range(BIGNUM *rnd, BIGNUM *range);
+
+ BIGNUM *BN_generate_prime(BIGNUM *ret, int bits,int safe, BIGNUM *add,
+         BIGNUM *rem, void (*callback)(int, int, void *), void *cb_arg);
+ int BN_is_prime(const BIGNUM *p, int nchecks,
+         void (*callback)(int, int, void *), BN_CTX *ctx, void *cb_arg);
+
+ int BN_set_bit(BIGNUM *a, int n);
+ int BN_clear_bit(BIGNUM *a, int n);
+ int BN_is_bit_set(const BIGNUM *a, int n);
+ int BN_mask_bits(BIGNUM *a, int n);
+ int BN_lshift(BIGNUM *r, const BIGNUM *a, int n);
+ int BN_lshift1(BIGNUM *r, BIGNUM *a);
+ int BN_rshift(BIGNUM *r, BIGNUM *a, int n);
+ int BN_rshift1(BIGNUM *r, BIGNUM *a);
+
+ int BN_bn2bin(const BIGNUM *a, unsigned char *to);
+ BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret);
+ char *BN_bn2hex(const BIGNUM *a);
+ char *BN_bn2dec(const BIGNUM *a);
+ int BN_hex2bn(BIGNUM **a, const char *str);
+ int BN_dec2bn(BIGNUM **a, const char *str);
+ int BN_print(BIO *fp, const BIGNUM *a);
+ int BN_print_fp(FILE *fp, const BIGNUM *a);
+ int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
+ BIGNUM *BN_mpi2bn(unsigned char *s, int len, BIGNUM *ret);
+
+ BIGNUM *BN_mod_inverse(BIGNUM *r, BIGNUM *a, const BIGNUM *n,
+     BN_CTX *ctx);
+
+ BN_RECP_CTX *BN_RECP_CTX_new(void);
+ void BN_RECP_CTX_init(BN_RECP_CTX *recp);
+ void BN_RECP_CTX_free(BN_RECP_CTX *recp);
+ int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *m, BN_CTX *ctx);
+ int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *a, BIGNUM *b,
+        BN_RECP_CTX *recp, BN_CTX *ctx);
+
+ BN_MONT_CTX *BN_MONT_CTX_new(void);
+ void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
+ void BN_MONT_CTX_free(BN_MONT_CTX *mont);
+ int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *m, BN_CTX *ctx);
+ BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from);
+ int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
+         BN_MONT_CTX *mont, BN_CTX *ctx);
+ int BN_from_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
+         BN_CTX *ctx);
+ int BN_to_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
+         BN_CTX *ctx);
+
+ BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai,
+       BIGNUM *mod);
+ void BN_BLINDING_free(BN_BLINDING *b);
+ int BN_BLINDING_update(BN_BLINDING *b,BN_CTX *ctx);
+ int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
+ int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
+ int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b,
+       BN_CTX *ctx);
+ int BN_BLINDING_invert_ex(BIGNUM *n,const BIGNUM *r,BN_BLINDING *b,
+       BN_CTX *ctx);
+ unsigned long BN_BLINDING_get_thread_id(const BN_BLINDING *);
+ void BN_BLINDING_set_thread_id(BN_BLINDING *, unsigned long);
+ unsigned long BN_BLINDING_get_flags(const BN_BLINDING *);
+ void BN_BLINDING_set_flags(BN_BLINDING *, unsigned long);
+ BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b,
+       const BIGNUM *e, BIGNUM *m, BN_CTX *ctx,
+       int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
+                         const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx),
+       BN_MONT_CTX *m_ctx);
+
+=head1 DESCRIPTION
+
+This library performs arithmetic operations on integers of arbitrary
+size. It was written for use in public key cryptography, such as RSA
+and Diffie-Hellman.
+
+It uses dynamic memory allocation for storing its data structures.
+That means that there is no limit on the size of the numbers
+manipulated by these functions, but return values must always be
+checked in case a memory allocation error has occurred.
+
+The basic object in this library is a B<BIGNUM>. It is used to hold a
+single large integer. This type should be considered opaque and fields
+should not be modified or accessed directly.
+
+The creation of B<BIGNUM> objects is described in L<BN_new(3)|BN_new(3)>;
+L<BN_add(3)|BN_add(3)> describes most of the arithmetic operations.
+Comparison is described in L<BN_cmp(3)|BN_cmp(3)>; L<BN_zero(3)|BN_zero(3)>
+describes certain assignments, L<BN_rand(3)|BN_rand(3)> the generation of
+random numbers, L<BN_generate_prime(3)|BN_generate_prime(3)> deals with prime
+numbers and L<BN_set_bit(3)|BN_set_bit(3)> with bit operations. The conversion
+of B<BIGNUM>s to external formats is described in L<BN_bn2bin(3)|BN_bn2bin(3)>.
+
+=head1 SEE ALSO
+
+L<bn_internal(3)|bn_internal(3)>,
+L<dh(3)|dh(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>,
+L<BN_new(3)|BN_new(3)>, L<BN_CTX_new(3)|BN_CTX_new(3)>,
+L<BN_copy(3)|BN_copy(3)>, L<BN_swap(3)|BN_swap(3)>, L<BN_num_bytes(3)|BN_num_bytes(3)>,
+L<BN_add(3)|BN_add(3)>, L<BN_add_word(3)|BN_add_word(3)>,
+L<BN_cmp(3)|BN_cmp(3)>, L<BN_zero(3)|BN_zero(3)>, L<BN_rand(3)|BN_rand(3)>,
+L<BN_generate_prime(3)|BN_generate_prime(3)>, L<BN_set_bit(3)|BN_set_bit(3)>,
+L<BN_bn2bin(3)|BN_bn2bin(3)>, L<BN_mod_inverse(3)|BN_mod_inverse(3)>,
+L<BN_mod_mul_reciprocal(3)|BN_mod_mul_reciprocal(3)>,
+L<BN_mod_mul_montgomery(3)|BN_mod_mul_montgomery(3)>,
+L<BN_BLINDING_new(3)|BN_BLINDING_new(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/bn_internal.pod b/deps/openssl/openssl/doc/crypto/bn_internal.pod
new file mode 100644 (file)
index 0000000..91840b0
--- /dev/null
@@ -0,0 +1,238 @@
+=pod
+
+=head1 NAME
+
+bn_mul_words, bn_mul_add_words, bn_sqr_words, bn_div_words,
+bn_add_words, bn_sub_words, bn_mul_comba4, bn_mul_comba8,
+bn_sqr_comba4, bn_sqr_comba8, bn_cmp_words, bn_mul_normal,
+bn_mul_low_normal, bn_mul_recursive, bn_mul_part_recursive,
+bn_mul_low_recursive, bn_mul_high, bn_sqr_normal, bn_sqr_recursive,
+bn_expand, bn_wexpand, bn_expand2, bn_fix_top, bn_check_top,
+bn_print, bn_dump, bn_set_max, bn_set_high, bn_set_low - BIGNUM
+library internal functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/bn.h>
+
+ BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w);
+ BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num,
+   BN_ULONG w);
+ void     bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num);
+ BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d);
+ BN_ULONG bn_add_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,
+   int num);
+ BN_ULONG bn_sub_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,
+   int num);
+
+ void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b);
+ void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b);
+ void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a);
+ void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a);
+
+ int bn_cmp_words(BN_ULONG *a, BN_ULONG *b, int n);
+
+ void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b,
+   int nb);
+ void bn_mul_low_normal(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n);
+ void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
+   int dna,int dnb,BN_ULONG *tmp);
+ void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b,
+   int n, int tna,int tnb, BN_ULONG *tmp);
+ void bn_mul_low_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b,
+   int n2, BN_ULONG *tmp);
+ void bn_mul_high(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, BN_ULONG *l,
+   int n2, BN_ULONG *tmp);
+
+ void bn_sqr_normal(BN_ULONG *r, BN_ULONG *a, int n, BN_ULONG *tmp);
+ void bn_sqr_recursive(BN_ULONG *r, BN_ULONG *a, int n2, BN_ULONG *tmp);
+
+ void mul(BN_ULONG r, BN_ULONG a, BN_ULONG w, BN_ULONG c);
+ void mul_add(BN_ULONG r, BN_ULONG a, BN_ULONG w, BN_ULONG c);
+ void sqr(BN_ULONG r0, BN_ULONG r1, BN_ULONG a);
+
+ BIGNUM *bn_expand(BIGNUM *a, int bits);
+ BIGNUM *bn_wexpand(BIGNUM *a, int n);
+ BIGNUM *bn_expand2(BIGNUM *a, int n);
+ void bn_fix_top(BIGNUM *a);
+
+ void bn_check_top(BIGNUM *a);
+ void bn_print(BIGNUM *a);
+ void bn_dump(BN_ULONG *d, int n);
+ void bn_set_max(BIGNUM *a);
+ void bn_set_high(BIGNUM *r, BIGNUM *a, int n);
+ void bn_set_low(BIGNUM *r, BIGNUM *a, int n);
+
+=head1 DESCRIPTION
+
+This page documents the internal functions used by the OpenSSL
+B<BIGNUM> implementation. They are described here to facilitate
+debugging and extending the library. They are I<not> to be used by
+applications.
+
+=head2 The BIGNUM structure
+
+ typedef struct bignum_st BIGNUM;
+
+ struct bignum_st
+        {
+        BN_ULONG *d;    /* Pointer to an array of 'BN_BITS2' bit chunks. */
+        int top;        /* Index of last used d +1. */
+        /* The next are internal book keeping for bn_expand. */
+        int dmax;       /* Size of the d array. */
+        int neg;        /* one if the number is negative */
+        int flags;
+        };
+
+
+The integer value is stored in B<d>, a malloc()ed array of words (B<BN_ULONG>),
+least significant word first. A B<BN_ULONG> can be either 16, 32 or 64 bits
+in size, depending on the 'number of bits' (B<BITS2>) specified in
+C<openssl/bn.h>.
+
+B<dmax> is the size of the B<d> array that has been allocated.  B<top>
+is the number of words being used, so for a value of 4, bn.d[0]=4 and
+bn.top=1.  B<neg> is 1 if the number is negative.  When a B<BIGNUM> is
+B<0>, the B<d> field can be B<NULL> and B<top> == B<0>.
+
+B<flags> is a bit field of flags which are defined in C<openssl/bn.h>. The 
+flags begin with B<BN_FLG_>. The macros BN_set_flags(b,n) and 
+BN_get_flags(b,n) exist to enable or fetch flag(s) B<n> from B<BIGNUM>
+structure B<b>.
+
+Various routines in this library require the use of temporary
+B<BIGNUM> variables during their execution.  Since dynamic memory
+allocation to create B<BIGNUM>s is rather expensive when used in
+conjunction with repeated subroutine calls, the B<BN_CTX> structure is
+used.  This structure contains B<BN_CTX_NUM> B<BIGNUM>s, see
+L<BN_CTX_start(3)|BN_CTX_start(3)>.
+
+=head2 Low-level arithmetic operations
+
+These functions are implemented in C and for several platforms in
+assembly language:
+
+bn_mul_words(B<rp>, B<ap>, B<num>, B<w>) operates on the B<num> word
+arrays B<rp> and B<ap>.  It computes B<ap> * B<w>, places the result
+in B<rp>, and returns the high word (carry).
+
+bn_mul_add_words(B<rp>, B<ap>, B<num>, B<w>) operates on the B<num>
+word arrays B<rp> and B<ap>.  It computes B<ap> * B<w> + B<rp>, places
+the result in B<rp>, and returns the high word (carry).
+
+bn_sqr_words(B<rp>, B<ap>, B<n>) operates on the B<num> word array
+B<ap> and the 2*B<num> word array B<ap>.  It computes B<ap> * B<ap>
+word-wise, and places the low and high bytes of the result in B<rp>.
+
+bn_div_words(B<h>, B<l>, B<d>) divides the two word number (B<h>,B<l>)
+by B<d> and returns the result.
+
+bn_add_words(B<rp>, B<ap>, B<bp>, B<num>) operates on the B<num> word
+arrays B<ap>, B<bp> and B<rp>.  It computes B<ap> + B<bp>, places the
+result in B<rp>, and returns the high word (carry).
+
+bn_sub_words(B<rp>, B<ap>, B<bp>, B<num>) operates on the B<num> word
+arrays B<ap>, B<bp> and B<rp>.  It computes B<ap> - B<bp>, places the
+result in B<rp>, and returns the carry (1 if B<bp> E<gt> B<ap>, 0
+otherwise).
+
+bn_mul_comba4(B<r>, B<a>, B<b>) operates on the 4 word arrays B<a> and
+B<b> and the 8 word array B<r>.  It computes B<a>*B<b> and places the
+result in B<r>.
+
+bn_mul_comba8(B<r>, B<a>, B<b>) operates on the 8 word arrays B<a> and
+B<b> and the 16 word array B<r>.  It computes B<a>*B<b> and places the
+result in B<r>.
+
+bn_sqr_comba4(B<r>, B<a>, B<b>) operates on the 4 word arrays B<a> and
+B<b> and the 8 word array B<r>.
+
+bn_sqr_comba8(B<r>, B<a>, B<b>) operates on the 8 word arrays B<a> and
+B<b> and the 16 word array B<r>.
+
+The following functions are implemented in C:
+
+bn_cmp_words(B<a>, B<b>, B<n>) operates on the B<n> word arrays B<a>
+and B<b>.  It returns 1, 0 and -1 if B<a> is greater than, equal and
+less than B<b>.
+
+bn_mul_normal(B<r>, B<a>, B<na>, B<b>, B<nb>) operates on the B<na>
+word array B<a>, the B<nb> word array B<b> and the B<na>+B<nb> word
+array B<r>.  It computes B<a>*B<b> and places the result in B<r>.
+
+bn_mul_low_normal(B<r>, B<a>, B<b>, B<n>) operates on the B<n> word
+arrays B<r>, B<a> and B<b>.  It computes the B<n> low words of
+B<a>*B<b> and places the result in B<r>.
+
+bn_mul_recursive(B<r>, B<a>, B<b>, B<n2>, B<dna>, B<dnb>, B<t>) operates
+on the word arrays B<a> and B<b> of length B<n2>+B<dna> and B<n2>+B<dnb>
+(B<dna> and B<dnb> are currently allowed to be 0 or negative) and the 2*B<n2>
+word arrays B<r> and B<t>.  B<n2> must be a power of 2.  It computes
+B<a>*B<b> and places the result in B<r>.
+
+bn_mul_part_recursive(B<r>, B<a>, B<b>, B<n>, B<tna>, B<tnb>, B<tmp>)
+operates on the word arrays B<a> and B<b> of length B<n>+B<tna> and
+B<n>+B<tnb> and the 4*B<n> word arrays B<r> and B<tmp>.
+
+bn_mul_low_recursive(B<r>, B<a>, B<b>, B<n2>, B<tmp>) operates on the
+B<n2> word arrays B<r> and B<tmp> and the B<n2>/2 word arrays B<a>
+and B<b>.
+
+bn_mul_high(B<r>, B<a>, B<b>, B<l>, B<n2>, B<tmp>) operates on the
+B<n2> word arrays B<r>, B<a>, B<b> and B<l> (?) and the 3*B<n2> word
+array B<tmp>.
+
+BN_mul() calls bn_mul_normal(), or an optimized implementation if the
+factors have the same size: bn_mul_comba8() is used if they are 8
+words long, bn_mul_recursive() if they are larger than
+B<BN_MULL_SIZE_NORMAL> and the size is an exact multiple of the word
+size, and bn_mul_part_recursive() for others that are larger than
+B<BN_MULL_SIZE_NORMAL>.
+
+bn_sqr_normal(B<r>, B<a>, B<n>, B<tmp>) operates on the B<n> word array
+B<a> and the 2*B<n> word arrays B<tmp> and B<r>.
+
+The implementations use the following macros which, depending on the
+architecture, may use "long long" C operations or inline assembler.
+They are defined in C<bn_lcl.h>.
+
+mul(B<r>, B<a>, B<w>, B<c>) computes B<w>*B<a>+B<c> and places the
+low word of the result in B<r> and the high word in B<c>.
+
+mul_add(B<r>, B<a>, B<w>, B<c>) computes B<w>*B<a>+B<r>+B<c> and
+places the low word of the result in B<r> and the high word in B<c>.
+
+sqr(B<r0>, B<r1>, B<a>) computes B<a>*B<a> and places the low word
+of the result in B<r0> and the high word in B<r1>.
+
+=head2 Size changes
+
+bn_expand() ensures that B<b> has enough space for a B<bits> bit
+number.  bn_wexpand() ensures that B<b> has enough space for an
+B<n> word number.  If the number has to be expanded, both macros
+call bn_expand2(), which allocates a new B<d> array and copies the
+data.  They return B<NULL> on error, B<b> otherwise.
+
+The bn_fix_top() macro reduces B<a-E<gt>top> to point to the most
+significant non-zero word plus one when B<a> has shrunk.
+
+=head2 Debugging
+
+bn_check_top() verifies that C<((a)-E<gt>top E<gt>= 0 && (a)-E<gt>top
+E<lt>= (a)-E<gt>dmax)>.  A violation will cause the program to abort.
+
+bn_print() prints B<a> to stderr. bn_dump() prints B<n> words at B<d>
+(in reverse order, i.e. most significant word first) to stderr.
+
+bn_set_max() makes B<a> a static number with a B<dmax> of its current size.
+This is used by bn_set_low() and bn_set_high() to make B<r> a read-only
+B<BIGNUM> that contains the B<n> low or high words of B<a>.
+
+If B<BN_DEBUG> is not defined, bn_check_top(), bn_print(), bn_dump()
+and bn_set_max() are defined as empty macros.
+
+=head1 SEE ALSO
+
+L<bn(3)|bn(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/buffer.pod b/deps/openssl/openssl/doc/crypto/buffer.pod
new file mode 100644 (file)
index 0000000..781f5b1
--- /dev/null
@@ -0,0 +1,73 @@
+=pod
+
+=head1 NAME
+
+BUF_MEM_new, BUF_MEM_free, BUF_MEM_grow, BUF_strdup - simple
+character arrays structure
+
+=head1 SYNOPSIS
+
+ #include <openssl/buffer.h>
+
+ BUF_MEM *BUF_MEM_new(void);
+
+ void  BUF_MEM_free(BUF_MEM *a);
+
+ int   BUF_MEM_grow(BUF_MEM *str, int len);
+
+ char *        BUF_strdup(const char *str);
+
+=head1 DESCRIPTION
+
+The buffer library handles simple character arrays. Buffers are used for
+various purposes in the library, most notably memory BIOs.
+
+The library uses the BUF_MEM structure defined in buffer.h:
+
+ typedef struct buf_mem_st
+ {
+        int length;     /* current number of bytes */
+        char *data;
+        int max;        /* size of buffer */
+ } BUF_MEM;
+
+B<length> is the current size of the buffer in bytes, B<max> is the amount of
+memory allocated to the buffer. There are three functions which handle these
+and one "miscellaneous" function.
+
+BUF_MEM_new() allocates a new buffer of zero size.
+
+BUF_MEM_free() frees up an already existing buffer. The data is zeroed
+before freeing up in case the buffer contains sensitive data.
+
+BUF_MEM_grow() changes the size of an already existing buffer to
+B<len>. Any data already in the buffer is preserved if it increases in
+size.
+
+BUF_strdup() copies a null terminated string into a block of allocated
+memory and returns a pointer to the allocated block.
+Unlike the standard C library strdup() this function uses OPENSSL_malloc() and so
+should be used in preference to the standard library strdup() because it can
+be used for memory leak checking or replacing the malloc() function.
+
+The memory allocated from BUF_strdup() should be freed up using the OPENSSL_free()
+function.
+
+=head1 RETURN VALUES
+
+BUF_MEM_new() returns the buffer or NULL on error.
+
+BUF_MEM_free() has no return value.
+
+BUF_MEM_grow() returns zero on error or the new size (i.e. B<len>).
+
+=head1 SEE ALSO
+
+L<bio(3)|bio(3)>
+
+=head1 HISTORY
+
+BUF_MEM_new(), BUF_MEM_free() and BUF_MEM_grow() are available in all
+versions of SSLeay and OpenSSL. BUF_strdup() was added in SSLeay 0.8.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/crypto.pod b/deps/openssl/openssl/doc/crypto/crypto.pod
new file mode 100644 (file)
index 0000000..7a52799
--- /dev/null
@@ -0,0 +1,85 @@
+=pod
+
+=head1 NAME
+
+crypto - OpenSSL cryptographic library
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+The OpenSSL B<crypto> library implements a wide range of cryptographic
+algorithms used in various Internet standards. The services provided
+by this library are used by the OpenSSL implementations of SSL, TLS
+and S/MIME, and they have also been used to implement SSH, OpenPGP, and
+other cryptographic standards.
+
+=head1 OVERVIEW
+
+B<libcrypto> consists of a number of sub-libraries that implement the
+individual algorithms.
+
+The functionality includes symmetric encryption, public key
+cryptography and key agreement, certificate handling, cryptographic
+hash functions and a cryptographic pseudo-random number generator.
+
+=over 4
+
+=item SYMMETRIC CIPHERS
+
+L<blowfish(3)|blowfish(3)>, L<cast(3)|cast(3)>, L<des(3)|des(3)>,
+L<idea(3)|idea(3)>, L<rc2(3)|rc2(3)>, L<rc4(3)|rc4(3)>, L<rc5(3)|rc5(3)> 
+
+=item PUBLIC KEY CRYPTOGRAPHY AND KEY AGREEMENT
+
+L<dsa(3)|dsa(3)>, L<dh(3)|dh(3)>, L<rsa(3)|rsa(3)>
+
+=item CERTIFICATES
+
+L<x509(3)|x509(3)>, L<x509v3(3)|x509v3(3)>
+
+=item AUTHENTICATION CODES, HASH FUNCTIONS
+
+L<hmac(3)|hmac(3)>, L<md2(3)|md2(3)>, L<md4(3)|md4(3)>,
+L<md5(3)|md5(3)>, L<mdc2(3)|mdc2(3)>, L<ripemd(3)|ripemd(3)>,
+L<sha(3)|sha(3)>
+
+=item AUXILIARY FUNCTIONS
+
+L<err(3)|err(3)>, L<threads(3)|threads(3)>, L<rand(3)|rand(3)>,
+L<OPENSSL_VERSION_NUMBER(3)|OPENSSL_VERSION_NUMBER(3)>
+
+=item INPUT/OUTPUT, DATA ENCODING
+
+L<asn1(3)|asn1(3)>, L<bio(3)|bio(3)>, L<evp(3)|evp(3)>, L<pem(3)|pem(3)>,
+L<pkcs7(3)|pkcs7(3)>, L<pkcs12(3)|pkcs12(3)> 
+
+=item INTERNAL FUNCTIONS
+
+L<bn(3)|bn(3)>, L<buffer(3)|buffer(3)>, L<lhash(3)|lhash(3)>,
+L<objects(3)|objects(3)>, L<stack(3)|stack(3)>,
+L<txt_db(3)|txt_db(3)> 
+
+=back
+
+=head1 NOTES
+
+Some of the newer functions follow a naming convention using the numbers
+B<0> and B<1>. For example the functions:
+
+ int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev);
+ int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj);
+
+The B<0> version uses the supplied structure pointer directly
+in the parent and it will be freed up when the parent is freed.
+In the above example B<crl> would be freed but B<rev> would not.
+
+The B<1> function uses a copy of the supplied structure pointer
+(or in some cases increases its link count) in the parent and
+so both (B<x> and B<obj> above) should be freed up.
+
+=head1 SEE ALSO
+
+L<openssl(1)|openssl(1)>, L<ssl(3)|ssl(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/d2i_ASN1_OBJECT.pod b/deps/openssl/openssl/doc/crypto/d2i_ASN1_OBJECT.pod
new file mode 100644 (file)
index 0000000..45bb184
--- /dev/null
@@ -0,0 +1,29 @@
+=pod
+
+=head1 NAME
+
+d2i_ASN1_OBJECT, i2d_ASN1_OBJECT - ASN1 OBJECT IDENTIFIER functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/objects.h>
+
+ ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp, long length);
+ int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp);
+
+=head1 DESCRIPTION
+
+These functions decode and encode an ASN1 OBJECT IDENTIFIER.
+
+Othewise these behave in a similar way to d2i_X509() and i2d_X509()
+described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
+
+=head1 SEE ALSO
+
+L<d2i_X509(3)|d2i_X509(3)>
+
+=head1 HISTORY
+
+TBA
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/d2i_DHparams.pod b/deps/openssl/openssl/doc/crypto/d2i_DHparams.pod
new file mode 100644 (file)
index 0000000..1e98aeb
--- /dev/null
@@ -0,0 +1,30 @@
+=pod
+
+=head1 NAME
+
+d2i_DHparams, i2d_DHparams - PKCS#3 DH parameter functions.
+
+=head1 SYNOPSIS
+
+ #include <openssl/dh.h>
+
+ DH *d2i_DHparams(DH **a, unsigned char **pp, long length);
+ int i2d_DHparams(DH *a, unsigned char **pp);
+
+=head1 DESCRIPTION
+
+These functions decode and encode PKCS#3 DH parameters using the
+DHparameter structure described in PKCS#3.
+
+Othewise these behave in a similar way to d2i_X509() and i2d_X509()
+described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
+
+=head1 SEE ALSO
+
+L<d2i_X509(3)|d2i_X509(3)>
+
+=head1 HISTORY
+
+TBA
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/d2i_DSAPublicKey.pod b/deps/openssl/openssl/doc/crypto/d2i_DSAPublicKey.pod
new file mode 100644 (file)
index 0000000..22c1b50
--- /dev/null
@@ -0,0 +1,83 @@
+=pod
+
+=head1 NAME
+
+d2i_DSAPublicKey, i2d_DSAPublicKey, d2i_DSAPrivateKey, i2d_DSAPrivateKey,
+d2i_DSA_PUBKEY, i2d_DSA_PUBKEY, d2i_DSA_SIG, i2d_DSA_SIG - DSA key encoding
+and parsing functions.
+
+=head1 SYNOPSIS
+
+ #include <openssl/dsa.h>
+ #include <openssl/x509.h>
+
+ DSA * d2i_DSAPublicKey(DSA **a, const unsigned char **pp, long length);
+
+ int i2d_DSAPublicKey(const DSA *a, unsigned char **pp);
+
+ DSA * d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, long length);
+
+ int i2d_DSA_PUBKEY(const DSA *a, unsigned char **pp);
+
+ DSA * d2i_DSAPrivateKey(DSA **a, const unsigned char **pp, long length);
+
+ int i2d_DSAPrivateKey(const DSA *a, unsigned char **pp);
+
+ DSA * d2i_DSAparams(DSA **a, const unsigned char **pp, long length);
+
+ int i2d_DSAparams(const DSA *a, unsigned char **pp);
+
+ DSA * d2i_DSA_SIG(DSA_SIG **a, const unsigned char **pp, long length);
+
+ int i2d_DSA_SIG(const DSA_SIG *a, unsigned char **pp);
+
+=head1 DESCRIPTION
+
+d2i_DSAPublicKey() and i2d_DSAPublicKey() decode and encode the DSA public key
+components structure.
+
+d2i_DSA_PUBKEY() and i2d_DSA_PUBKEY() decode and encode an DSA public key using
+a SubjectPublicKeyInfo (certificate public key) structure.
+
+d2i_DSAPrivateKey(), i2d_DSAPrivateKey() decode and encode the DSA private key
+components.
+
+d2i_DSAparams(), i2d_DSAparams() decode and encode the DSA parameters using
+a B<Dss-Parms> structure as defined in RFC2459.
+
+d2i_DSA_SIG(), i2d_DSA_SIG() decode and encode a DSA signature using a
+B<Dss-Sig-Value> structure as defined in RFC2459.
+
+The usage of all of these functions is similar to the d2i_X509() and
+i2d_X509() described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
+
+=head1 NOTES
+
+The B<DSA> structure passed to the private key encoding functions should have
+all the private key components present.
+
+The data encoded by the private key functions is unencrypted and therefore 
+offers no private key security.
+
+The B<DSA_PUBKEY> functions should be used in preference to the B<DSAPublicKey>
+functions when encoding public keys because they use a standard format.
+
+The B<DSAPublicKey> functions use an non standard format the actual data encoded
+depends on the value of the B<write_params> field of the B<a> key parameter.
+If B<write_params> is zero then only the B<pub_key> field is encoded as an
+B<INTEGER>. If B<write_params> is 1 then a B<SEQUENCE> consisting of the
+B<p>, B<q>, B<g> and B<pub_key> respectively fields are encoded.
+
+The B<DSAPrivateKey> functions also use a non standard structure consiting
+consisting of a SEQUENCE containing the B<p>, B<q>, B<g> and B<pub_key> and
+B<priv_key> fields respectively.
+
+=head1 SEE ALSO
+
+L<d2i_X509(3)|d2i_X509(3)>
+
+=head1 HISTORY
+
+TBA
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/d2i_PKCS8PrivateKey.pod b/deps/openssl/openssl/doc/crypto/d2i_PKCS8PrivateKey.pod
new file mode 100644 (file)
index 0000000..a54b779
--- /dev/null
@@ -0,0 +1,56 @@
+=pod
+
+=head1 NAME
+
+d2i_PKCS8PrivateKey_bio, d2i_PKCS8PrivateKey_fp,
+i2d_PKCS8PrivateKey_bio, i2d_PKCS8PrivateKey_fp,
+i2d_PKCS8PrivateKey_nid_bio, i2d_PKCS8PrivateKey_nid_fp - PKCS#8 format private key functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u);
+ EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u);
+
+ int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
+                                 char *kstr, int klen,
+                                 pem_password_cb *cb, void *u);
+
+ int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
+                                 char *kstr, int klen,
+                                 pem_password_cb *cb, void *u);
+
+ int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid,
+                                 char *kstr, int klen,
+                                 pem_password_cb *cb, void *u);
+
+ int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid,
+                                 char *kstr, int klen,
+                                 pem_password_cb *cb, void *u);
+
+=head1 DESCRIPTION
+
+The PKCS#8 functions encode and decode private keys in PKCS#8 format using both
+PKCS#5 v1.5 and PKCS#5 v2.0 password based encryption algorithms.
+
+Other than the use of DER as opposed to PEM these functions are identical to the
+corresponding B<PEM> function as described in the L<pem(3)|pem(3)> manual page.
+
+=head1 NOTES
+
+Before using these functions L<OpenSSL_add_all_algorithms(3)|OpenSSL_add_all_algorithms(3)>
+should be called to initialize the internal algorithm lookup tables otherwise errors about
+unknown algorithms will occur if an attempt is made to decrypt a private key. 
+
+These functions are currently the only way to store encrypted private keys using DER format.
+
+Currently all the functions use BIOs or FILE pointers, there are no functions which
+work directly on memory: this can be readily worked around by converting the buffers
+to memory BIOs, see L<BIO_s_mem(3)|BIO_s_mem(3)> for details.
+
+=head1 SEE ALSO
+
+L<pem(3)|pem(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/d2i_RSAPublicKey.pod b/deps/openssl/openssl/doc/crypto/d2i_RSAPublicKey.pod
new file mode 100644 (file)
index 0000000..aa6078b
--- /dev/null
@@ -0,0 +1,67 @@
+=pod
+
+=head1 NAME
+
+d2i_RSAPublicKey, i2d_RSAPublicKey, d2i_RSAPrivateKey, i2d_RSAPrivateKey,
+d2i_RSA_PUBKEY, i2d_RSA_PUBKEY, i2d_Netscape_RSA,
+d2i_Netscape_RSA - RSA public and private key encoding functions.
+
+=head1 SYNOPSIS
+
+ #include <openssl/rsa.h>
+ #include <openssl/x509.h>
+
+ RSA * d2i_RSAPublicKey(RSA **a, const unsigned char **pp, long length);
+
+ int i2d_RSAPublicKey(RSA *a, unsigned char **pp);
+
+ RSA * d2i_RSA_PUBKEY(RSA **a, const unsigned char **pp, long length);
+
+ int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp);
+
+ RSA * d2i_RSAPrivateKey(RSA **a, const unsigned char **pp, long length);
+
+ int i2d_RSAPrivateKey(RSA *a, unsigned char **pp);
+
+ int i2d_Netscape_RSA(RSA *a, unsigned char **pp, int (*cb)());
+
+ RSA * d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length, int (*cb)());
+
+=head1 DESCRIPTION
+
+d2i_RSAPublicKey() and i2d_RSAPublicKey() decode and encode a PKCS#1 RSAPublicKey
+structure.
+
+d2i_RSA_PUBKEY() and i2d_RSA_PUBKEY() decode and encode an RSA public key using
+a SubjectPublicKeyInfo (certificate public key) structure.
+
+d2i_RSAPrivateKey(), i2d_RSAPrivateKey() decode and encode a PKCS#1 RSAPrivateKey
+structure.
+
+d2i_Netscape_RSA(), i2d_Netscape_RSA() decode and encode an RSA private key in
+NET format.
+
+The usage of all of these functions is similar to the d2i_X509() and
+i2d_X509() described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
+
+=head1 NOTES
+
+The B<RSA> structure passed to the private key encoding functions should have
+all the PKCS#1 private key components present.
+
+The data encoded by the private key functions is unencrypted and therefore 
+offers no private key security. 
+
+The NET format functions are present to provide compatibility with certain very
+old software. This format has some severe security weaknesses and should be
+avoided if possible.
+
+=head1 SEE ALSO
+
+L<d2i_X509(3)|d2i_X509(3)>
+
+=head1 HISTORY
+
+TBA
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/d2i_X509.pod b/deps/openssl/openssl/doc/crypto/d2i_X509.pod
new file mode 100644 (file)
index 0000000..298ec54
--- /dev/null
@@ -0,0 +1,231 @@
+=pod
+
+=head1 NAME
+
+d2i_X509, i2d_X509, d2i_X509_bio, d2i_X509_fp, i2d_X509_bio,
+i2d_X509_fp - X509 encode and decode functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/x509.h>
+
+ X509 *d2i_X509(X509 **px, const unsigned char **in, int len);
+ int i2d_X509(X509 *x, unsigned char **out);
+
+ X509 *d2i_X509_bio(BIO *bp, X509 **x);
+ X509 *d2i_X509_fp(FILE *fp, X509 **x);
+
+ int i2d_X509_bio(BIO *bp, X509 *x);
+ int i2d_X509_fp(FILE *fp, X509 *x);
+
+=head1 DESCRIPTION
+
+The X509 encode and decode routines encode and parse an
+B<X509> structure, which represents an X509 certificate.
+
+d2i_X509() attempts to decode B<len> bytes at B<*in>. If 
+successful a pointer to the B<X509> structure is returned. If an error
+occurred then B<NULL> is returned. If B<px> is not B<NULL> then the
+returned structure is written to B<*px>. If B<*px> is not B<NULL>
+then it is assumed that B<*px> contains a valid B<X509>
+structure and an attempt is made to reuse it. If the call is
+successful B<*in> is incremented to the byte following the
+parsed data.
+
+i2d_X509() encodes the structure pointed to by B<x> into DER format.
+If B<out> is not B<NULL> is writes the DER encoded data to the buffer
+at B<*out>, and increments it to point after the data just written.
+If the return value is negative an error occurred, otherwise it
+returns the length of the encoded data. 
+
+For OpenSSL 0.9.7 and later if B<*out> is B<NULL> memory will be
+allocated for a buffer and the encoded data written to it. In this
+case B<*out> is not incremented and it points to the start of the
+data just written.
+
+d2i_X509_bio() is similar to d2i_X509() except it attempts
+to parse data from BIO B<bp>.
+
+d2i_X509_fp() is similar to d2i_X509() except it attempts
+to parse data from FILE pointer B<fp>.
+
+i2d_X509_bio() is similar to i2d_X509() except it writes
+the encoding of the structure B<x> to BIO B<bp> and it
+returns 1 for success and 0 for failure.
+
+i2d_X509_fp() is similar to i2d_X509() except it writes
+the encoding of the structure B<x> to BIO B<bp> and it
+returns 1 for success and 0 for failure.
+
+=head1 NOTES
+
+The letters B<i> and B<d> in for example B<i2d_X509> stand for
+"internal" (that is an internal C structure) and "DER". So that
+B<i2d_X509> converts from internal to DER.
+
+The functions can also understand B<BER> forms.
+
+The actual X509 structure passed to i2d_X509() must be a valid
+populated B<X509> structure it can B<not> simply be fed with an
+empty structure such as that returned by X509_new().
+
+The encoded data is in binary form and may contain embedded zeroes.
+Therefore any FILE pointers or BIOs should be opened in binary mode.
+Functions such as B<strlen()> will B<not> return the correct length
+of the encoded structure.
+
+The ways that B<*in> and B<*out> are incremented after the operation
+can trap the unwary. See the B<WARNINGS> section for some common
+errors.
+
+The reason for the auto increment behaviour is to reflect a typical
+usage of ASN1 functions: after one structure is encoded or decoded
+another will processed after it.
+
+=head1 EXAMPLES
+
+Allocate and encode the DER encoding of an X509 structure:
+
+ int len;
+ unsigned char *buf, *p;
+
+ len = i2d_X509(x, NULL);
+
+ buf = OPENSSL_malloc(len);
+
+ if (buf == NULL)
+       /* error */
+
+ p = buf;
+
+ i2d_X509(x, &p);
+
+If you are using OpenSSL 0.9.7 or later then this can be
+simplified to:
+
+
+ int len;
+ unsigned char *buf;
+
+ buf = NULL;
+
+ len = i2d_X509(x, &buf);
+
+ if (len < 0)
+       /* error */
+
+Attempt to decode a buffer:
+
+ X509 *x;
+
+ unsigned char *buf, *p;
+
+ int len;
+
+ /* Something to setup buf and len */
+
+ p = buf;
+
+ x = d2i_X509(NULL, &p, len);
+
+ if (x == NULL)
+    /* Some error */
+
+Alternative technique:
+
+ X509 *x;
+
+ unsigned char *buf, *p;
+
+ int len;
+
+ /* Something to setup buf and len */
+
+ p = buf;
+
+ x = NULL;
+
+ if(!d2i_X509(&x, &p, len))
+    /* Some error */
+
+
+=head1 WARNINGS
+
+The use of temporary variable is mandatory. A common
+mistake is to attempt to use a buffer directly as follows:
+
+ int len;
+ unsigned char *buf;
+
+ len = i2d_X509(x, NULL);
+
+ buf = OPENSSL_malloc(len);
+
+ if (buf == NULL)
+       /* error */
+
+ i2d_X509(x, &buf);
+
+ /* Other stuff ... */
+
+ OPENSSL_free(buf);
+
+This code will result in B<buf> apparently containing garbage because
+it was incremented after the call to point after the data just written.
+Also B<buf> will no longer contain the pointer allocated by B<OPENSSL_malloc()>
+and the subsequent call to B<OPENSSL_free()> may well crash.
+
+The auto allocation feature (setting buf to NULL) only works on OpenSSL
+0.9.7 and later. Attempts to use it on earlier versions will typically
+cause a segmentation violation.
+
+Another trap to avoid is misuse of the B<xp> argument to B<d2i_X509()>:
+
+ X509 *x;
+
+ if (!d2i_X509(&x, &p, len))
+       /* Some error */
+
+This will probably crash somewhere in B<d2i_X509()>. The reason for this
+is that the variable B<x> is uninitialized and an attempt will be made to
+interpret its (invalid) value as an B<X509> structure, typically causing
+a segmentation violation. If B<x> is set to NULL first then this will not
+happen.
+
+=head1 BUGS
+
+In some versions of OpenSSL the "reuse" behaviour of d2i_X509() when 
+B<*px> is valid is broken and some parts of the reused structure may
+persist if they are not present in the new one. As a result the use
+of this "reuse" behaviour is strongly discouraged.
+
+i2d_X509() will not return an error in many versions of OpenSSL,
+if mandatory fields are not initialized due to a programming error
+then the encoded structure may contain invalid data or omit the
+fields entirely and will not be parsed by d2i_X509(). This may be
+fixed in future so code should not assume that i2d_X509() will
+always succeed.
+
+=head1 RETURN VALUES
+
+d2i_X509(), d2i_X509_bio() and d2i_X509_fp() return a valid B<X509> structure
+or B<NULL> if an error occurs. The error code that can be obtained by
+L<ERR_get_error(3)|ERR_get_error(3)>. 
+
+i2d_X509() returns the number of bytes successfully encoded or a negative
+value if an error occurs. The error code can be obtained by
+L<ERR_get_error(3)|ERR_get_error(3)>. 
+
+i2d_X509_bio() and i2d_X509_fp() return 1 for success and 0 if an error 
+occurs The error code can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>. 
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>
+
+=head1 HISTORY
+
+d2i_X509, i2d_X509, d2i_X509_bio, d2i_X509_fp, i2d_X509_bio and i2d_X509_fp
+are available in all versions of SSLeay and OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/d2i_X509_ALGOR.pod b/deps/openssl/openssl/doc/crypto/d2i_X509_ALGOR.pod
new file mode 100644 (file)
index 0000000..9e5cd92
--- /dev/null
@@ -0,0 +1,30 @@
+=pod
+
+=head1 NAME
+
+d2i_X509_ALGOR, i2d_X509_ALGOR - AlgorithmIdentifier functions.
+
+=head1 SYNOPSIS
+
+ #include <openssl/x509.h>
+
+ X509_ALGOR *d2i_X509_ALGOR(X509_ALGOR **a, unsigned char **pp, long length);
+ int i2d_X509_ALGOR(X509_ALGOR *a, unsigned char **pp);
+
+=head1 DESCRIPTION
+
+These functions decode and encode an B<X509_ALGOR> structure which is
+equivalent to the B<AlgorithmIdentifier> structure.
+
+Othewise these behave in a similar way to d2i_X509() and i2d_X509()
+described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
+
+=head1 SEE ALSO
+
+L<d2i_X509(3)|d2i_X509(3)>
+
+=head1 HISTORY
+
+TBA
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/d2i_X509_CRL.pod b/deps/openssl/openssl/doc/crypto/d2i_X509_CRL.pod
new file mode 100644 (file)
index 0000000..224f9e0
--- /dev/null
@@ -0,0 +1,37 @@
+=pod
+
+=head1 NAME
+
+d2i_X509_CRL, i2d_X509_CRL, d2i_X509_CRL_bio, d2i_509_CRL_fp,
+i2d_X509_CRL_bio, i2d_X509_CRL_fp - PKCS#10 certificate request functions.
+
+=head1 SYNOPSIS
+
+ #include <openssl/x509.h>
+
+ X509_CRL *d2i_X509_CRL(X509_CRL **a, const unsigned char **pp, long length);
+ int i2d_X509_CRL(X509_CRL *a, unsigned char **pp);
+
+ X509_CRL *d2i_X509_CRL_bio(BIO *bp, X509_CRL **x);
+ X509_CRL *d2i_X509_CRL_fp(FILE *fp, X509_CRL **x);
+
+ int i2d_X509_CRL_bio(BIO *bp, X509_CRL *x);
+ int i2d_X509_CRL_fp(FILE *fp, X509_CRL *x);
+
+=head1 DESCRIPTION
+
+These functions decode and encode an X509 CRL (certificate revocation
+list).
+
+Othewise the functions behave in a similar way to d2i_X509() and i2d_X509()
+described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
+
+=head1 SEE ALSO
+
+L<d2i_X509(3)|d2i_X509(3)>
+
+=head1 HISTORY
+
+TBA
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/d2i_X509_NAME.pod b/deps/openssl/openssl/doc/crypto/d2i_X509_NAME.pod
new file mode 100644 (file)
index 0000000..343ffe1
--- /dev/null
@@ -0,0 +1,31 @@
+=pod
+
+=head1 NAME
+
+d2i_X509_NAME, i2d_X509_NAME - X509_NAME encoding functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/x509.h>
+
+ X509_NAME *d2i_X509_NAME(X509_NAME **a, unsigned char **pp, long length);
+ int i2d_X509_NAME(X509_NAME *a, unsigned char **pp);
+
+=head1 DESCRIPTION
+
+These functions decode and encode an B<X509_NAME> structure which is the
+the same as the B<Name> type defined in RFC2459 (and elsewhere) and used
+for example in certificate subject and issuer names.
+
+Othewise the functions behave in a similar way to d2i_X509() and i2d_X509()
+described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
+
+=head1 SEE ALSO
+
+L<d2i_X509(3)|d2i_X509(3)>
+
+=head1 HISTORY
+
+TBA
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/d2i_X509_REQ.pod b/deps/openssl/openssl/doc/crypto/d2i_X509_REQ.pod
new file mode 100644 (file)
index 0000000..91c0c19
--- /dev/null
@@ -0,0 +1,36 @@
+=pod
+
+=head1 NAME
+
+d2i_X509_REQ, i2d_X509_REQ, d2i_X509_REQ_bio, d2i_X509_REQ_fp,
+i2d_X509_REQ_bio, i2d_X509_REQ_fp - PKCS#10 certificate request functions.
+
+=head1 SYNOPSIS
+
+ #include <openssl/x509.h>
+
+ X509_REQ *d2i_X509_REQ(X509_REQ **a, const unsigned char **pp, long length);
+ int i2d_X509_REQ(X509_REQ *a, unsigned char **pp);
+
+ X509_REQ *d2i_X509_REQ_bio(BIO *bp, X509_REQ **x);
+ X509_REQ *d2i_X509_REQ_fp(FILE *fp, X509_REQ **x);
+
+ int i2d_X509_REQ_bio(BIO *bp, X509_REQ *x);
+ int i2d_X509_REQ_fp(FILE *fp, X509_REQ *x);
+
+=head1 DESCRIPTION
+
+These functions decode and encode a PKCS#10 certificate request.
+
+Othewise these behave in a similar way to d2i_X509() and i2d_X509()
+described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
+
+=head1 SEE ALSO
+
+L<d2i_X509(3)|d2i_X509(3)>
+
+=head1 HISTORY
+
+TBA
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/d2i_X509_SIG.pod b/deps/openssl/openssl/doc/crypto/d2i_X509_SIG.pod
new file mode 100644 (file)
index 0000000..e48fd79
--- /dev/null
@@ -0,0 +1,30 @@
+=pod
+
+=head1 NAME
+
+d2i_X509_SIG, i2d_X509_SIG - DigestInfo functions.
+
+=head1 SYNOPSIS
+
+ #include <openssl/x509.h>
+
+ X509_SIG *d2i_X509_SIG(X509_SIG **a, unsigned char **pp, long length);
+ int i2d_X509_SIG(X509_SIG *a, unsigned char **pp);
+
+=head1 DESCRIPTION
+
+These functions decode and encode an X509_SIG structure which is
+equivalent to the B<DigestInfo> structure defined in PKCS#1 and PKCS#7.
+
+Othewise these behave in a similar way to d2i_X509() and i2d_X509()
+described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
+
+=head1 SEE ALSO
+
+L<d2i_X509(3)|d2i_X509(3)>
+
+=head1 HISTORY
+
+TBA
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/des.pod b/deps/openssl/openssl/doc/crypto/des.pod
new file mode 100644 (file)
index 0000000..6f0cf1c
--- /dev/null
@@ -0,0 +1,358 @@
+=pod
+
+=head1 NAME
+
+DES_random_key, DES_set_key, DES_key_sched, DES_set_key_checked,
+DES_set_key_unchecked, DES_set_odd_parity, DES_is_weak_key,
+DES_ecb_encrypt, DES_ecb2_encrypt, DES_ecb3_encrypt, DES_ncbc_encrypt,
+DES_cfb_encrypt, DES_ofb_encrypt, DES_pcbc_encrypt, DES_cfb64_encrypt,
+DES_ofb64_encrypt, DES_xcbc_encrypt, DES_ede2_cbc_encrypt,
+DES_ede2_cfb64_encrypt, DES_ede2_ofb64_encrypt, DES_ede3_cbc_encrypt,
+DES_ede3_cbcm_encrypt, DES_ede3_cfb64_encrypt, DES_ede3_ofb64_encrypt,
+DES_cbc_cksum, DES_quad_cksum, DES_string_to_key, DES_string_to_2keys,
+DES_fcrypt, DES_crypt, DES_enc_read, DES_enc_write - DES encryption
+
+=head1 SYNOPSIS
+
+ #include <openssl/des.h>
+
+ void DES_random_key(DES_cblock *ret);
+
+ int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule);
+ int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule);
+ int DES_set_key_checked(const_DES_cblock *key,
+        DES_key_schedule *schedule);
+ void DES_set_key_unchecked(const_DES_cblock *key,
+        DES_key_schedule *schedule);
+
+ void DES_set_odd_parity(DES_cblock *key);
+ int DES_is_weak_key(const_DES_cblock *key);
+
+ void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output, 
+        DES_key_schedule *ks, int enc);
+ void DES_ecb2_encrypt(const_DES_cblock *input, DES_cblock *output, 
+        DES_key_schedule *ks1, DES_key_schedule *ks2, int enc);
+ void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output, 
+        DES_key_schedule *ks1, DES_key_schedule *ks2, 
+        DES_key_schedule *ks3, int enc);
+
+ void DES_ncbc_encrypt(const unsigned char *input, unsigned char *output, 
+        long length, DES_key_schedule *schedule, DES_cblock *ivec, 
+        int enc);
+ void DES_cfb_encrypt(const unsigned char *in, unsigned char *out,
+        int numbits, long length, DES_key_schedule *schedule,
+        DES_cblock *ivec, int enc);
+ void DES_ofb_encrypt(const unsigned char *in, unsigned char *out,
+        int numbits, long length, DES_key_schedule *schedule,
+        DES_cblock *ivec);
+ void DES_pcbc_encrypt(const unsigned char *input, unsigned char *output, 
+        long length, DES_key_schedule *schedule, DES_cblock *ivec, 
+        int enc);
+ void DES_cfb64_encrypt(const unsigned char *in, unsigned char *out,
+        long length, DES_key_schedule *schedule, DES_cblock *ivec,
+        int *num, int enc);
+ void DES_ofb64_encrypt(const unsigned char *in, unsigned char *out,
+        long length, DES_key_schedule *schedule, DES_cblock *ivec,
+        int *num);
+
+ void DES_xcbc_encrypt(const unsigned char *input, unsigned char *output, 
+        long length, DES_key_schedule *schedule, DES_cblock *ivec, 
+        const_DES_cblock *inw, const_DES_cblock *outw, int enc);
+
+ void DES_ede2_cbc_encrypt(const unsigned char *input,
+        unsigned char *output, long length, DES_key_schedule *ks1,
+        DES_key_schedule *ks2, DES_cblock *ivec, int enc);
+ void DES_ede2_cfb64_encrypt(const unsigned char *in,
+        unsigned char *out, long length, DES_key_schedule *ks1,
+        DES_key_schedule *ks2, DES_cblock *ivec, int *num, int enc);
+ void DES_ede2_ofb64_encrypt(const unsigned char *in,
+        unsigned char *out, long length, DES_key_schedule *ks1,
+        DES_key_schedule *ks2, DES_cblock *ivec, int *num);
+
+ void DES_ede3_cbc_encrypt(const unsigned char *input,
+        unsigned char *output, long length, DES_key_schedule *ks1,
+        DES_key_schedule *ks2, DES_key_schedule *ks3, DES_cblock *ivec,
+        int enc);
+ void DES_ede3_cbcm_encrypt(const unsigned char *in, unsigned char *out, 
+        long length, DES_key_schedule *ks1, DES_key_schedule *ks2, 
+        DES_key_schedule *ks3, DES_cblock *ivec1, DES_cblock *ivec2, 
+        int enc);
+ void DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out, 
+        long length, DES_key_schedule *ks1, DES_key_schedule *ks2,
+        DES_key_schedule *ks3, DES_cblock *ivec, int *num, int enc);
+ void DES_ede3_ofb64_encrypt(const unsigned char *in, unsigned char *out, 
+        long length, DES_key_schedule *ks1, 
+        DES_key_schedule *ks2, DES_key_schedule *ks3, 
+        DES_cblock *ivec, int *num);
+
+ DES_LONG DES_cbc_cksum(const unsigned char *input, DES_cblock *output, 
+        long length, DES_key_schedule *schedule, 
+        const_DES_cblock *ivec);
+ DES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[], 
+        long length, int out_count, DES_cblock *seed);
+ void DES_string_to_key(const char *str, DES_cblock *key);
+ void DES_string_to_2keys(const char *str, DES_cblock *key1,
+        DES_cblock *key2);
+
+ char *DES_fcrypt(const char *buf, const char *salt, char *ret);
+ char *DES_crypt(const char *buf, const char *salt);
+
+ int DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched,
+        DES_cblock *iv);
+ int DES_enc_write(int fd, const void *buf, int len,
+        DES_key_schedule *sched, DES_cblock *iv);
+
+=head1 DESCRIPTION
+
+This library contains a fast implementation of the DES encryption
+algorithm.
+
+There are two phases to the use of DES encryption.  The first is the
+generation of a I<DES_key_schedule> from a key, the second is the
+actual encryption.  A DES key is of type I<DES_cblock>. This type is
+consists of 8 bytes with odd parity.  The least significant bit in
+each byte is the parity bit.  The key schedule is an expanded form of
+the key; it is used to speed the encryption process.
+
+DES_random_key() generates a random key.  The PRNG must be seeded
+prior to using this function (see L<rand(3)|rand(3)>).  If the PRNG
+could not generate a secure key, 0 is returned.
+
+Before a DES key can be used, it must be converted into the
+architecture dependent I<DES_key_schedule> via the
+DES_set_key_checked() or DES_set_key_unchecked() function.
+
+DES_set_key_checked() will check that the key passed is of odd parity
+and is not a week or semi-weak key.  If the parity is wrong, then -1
+is returned.  If the key is a weak key, then -2 is returned.  If an
+error is returned, the key schedule is not generated.
+
+DES_set_key() works like
+DES_set_key_checked() if the I<DES_check_key> flag is non-zero,
+otherwise like DES_set_key_unchecked().  These functions are available
+for compatibility; it is recommended to use a function that does not
+depend on a global variable.
+
+DES_set_odd_parity() sets the parity of the passed I<key> to odd.
+
+DES_is_weak_key() returns 1 is the passed key is a weak key, 0 if it
+is ok.  The probability that a randomly generated key is weak is
+1/2^52, so it is not really worth checking for them.
+
+The following routines mostly operate on an input and output stream of
+I<DES_cblock>s.
+
+DES_ecb_encrypt() is the basic DES encryption routine that encrypts or
+decrypts a single 8-byte I<DES_cblock> in I<electronic code book>
+(ECB) mode.  It always transforms the input data, pointed to by
+I<input>, into the output data, pointed to by the I<output> argument.
+If the I<encrypt> argument is non-zero (DES_ENCRYPT), the I<input>
+(cleartext) is encrypted in to the I<output> (ciphertext) using the
+key_schedule specified by the I<schedule> argument, previously set via
+I<DES_set_key>. If I<encrypt> is zero (DES_DECRYPT), the I<input> (now
+ciphertext) is decrypted into the I<output> (now cleartext).  Input
+and output may overlap.  DES_ecb_encrypt() does not return a value.
+
+DES_ecb3_encrypt() encrypts/decrypts the I<input> block by using
+three-key Triple-DES encryption in ECB mode.  This involves encrypting
+the input with I<ks1>, decrypting with the key schedule I<ks2>, and
+then encrypting with I<ks3>.  This routine greatly reduces the chances
+of brute force breaking of DES and has the advantage of if I<ks1>,
+I<ks2> and I<ks3> are the same, it is equivalent to just encryption
+using ECB mode and I<ks1> as the key.
+
+The macro DES_ecb2_encrypt() is provided to perform two-key Triple-DES
+encryption by using I<ks1> for the final encryption.
+
+DES_ncbc_encrypt() encrypts/decrypts using the I<cipher-block-chaining>
+(CBC) mode of DES.  If the I<encrypt> argument is non-zero, the
+routine cipher-block-chain encrypts the cleartext data pointed to by
+the I<input> argument into the ciphertext pointed to by the I<output>
+argument, using the key schedule provided by the I<schedule> argument,
+and initialization vector provided by the I<ivec> argument.  If the
+I<length> argument is not an integral multiple of eight bytes, the
+last block is copied to a temporary area and zero filled.  The output
+is always an integral multiple of eight bytes.
+
+DES_xcbc_encrypt() is RSA's DESX mode of DES.  It uses I<inw> and
+I<outw> to 'whiten' the encryption.  I<inw> and I<outw> are secret
+(unlike the iv) and are as such, part of the key.  So the key is sort
+of 24 bytes.  This is much better than CBC DES.
+
+DES_ede3_cbc_encrypt() implements outer triple CBC DES encryption with
+three keys. This means that each DES operation inside the CBC mode is
+really an C<C=E(ks3,D(ks2,E(ks1,M)))>.  This mode is used by SSL.
+
+The DES_ede2_cbc_encrypt() macro implements two-key Triple-DES by
+reusing I<ks1> for the final encryption.  C<C=E(ks1,D(ks2,E(ks1,M)))>.
+This form of Triple-DES is used by the RSAREF library.
+
+DES_pcbc_encrypt() encrypt/decrypts using the propagating cipher block
+chaining mode used by Kerberos v4. Its parameters are the same as
+DES_ncbc_encrypt().
+
+DES_cfb_encrypt() encrypt/decrypts using cipher feedback mode.  This
+method takes an array of characters as input and outputs and array of
+characters.  It does not require any padding to 8 character groups.
+Note: the I<ivec> variable is changed and the new changed value needs to
+be passed to the next call to this function.  Since this function runs
+a complete DES ECB encryption per I<numbits>, this function is only
+suggested for use when sending small numbers of characters.
+
+DES_cfb64_encrypt()
+implements CFB mode of DES with 64bit feedback.  Why is this
+useful you ask?  Because this routine will allow you to encrypt an
+arbitrary number of bytes, no 8 byte padding.  Each call to this
+routine will encrypt the input bytes to output and then update ivec
+and num.  num contains 'how far' we are though ivec.  If this does
+not make much sense, read more about cfb mode of DES :-).
+
+DES_ede3_cfb64_encrypt() and DES_ede2_cfb64_encrypt() is the same as
+DES_cfb64_encrypt() except that Triple-DES is used.
+
+DES_ofb_encrypt() encrypts using output feedback mode.  This method
+takes an array of characters as input and outputs and array of
+characters.  It does not require any padding to 8 character groups.
+Note: the I<ivec> variable is changed and the new changed value needs to
+be passed to the next call to this function.  Since this function runs
+a complete DES ECB encryption per numbits, this function is only
+suggested for use when sending small numbers of characters.
+
+DES_ofb64_encrypt() is the same as DES_cfb64_encrypt() using Output
+Feed Back mode.
+
+DES_ede3_ofb64_encrypt() and DES_ede2_ofb64_encrypt() is the same as
+DES_ofb64_encrypt(), using Triple-DES.
+
+The following functions are included in the DES library for
+compatibility with the MIT Kerberos library.
+
+DES_cbc_cksum() produces an 8 byte checksum based on the input stream
+(via CBC encryption).  The last 4 bytes of the checksum are returned
+and the complete 8 bytes are placed in I<output>. This function is
+used by Kerberos v4.  Other applications should use
+L<EVP_DigestInit(3)|EVP_DigestInit(3)> etc. instead.
+
+DES_quad_cksum() is a Kerberos v4 function.  It returns a 4 byte
+checksum from the input bytes.  The algorithm can be iterated over the
+input, depending on I<out_count>, 1, 2, 3 or 4 times.  If I<output> is
+non-NULL, the 8 bytes generated by each pass are written into
+I<output>.
+
+The following are DES-based transformations:
+
+DES_fcrypt() is a fast version of the Unix crypt(3) function.  This
+version takes only a small amount of space relative to other fast
+crypt() implementations.  This is different to the normal crypt in
+that the third parameter is the buffer that the return value is
+written into.  It needs to be at least 14 bytes long.  This function
+is thread safe, unlike the normal crypt.
+
+DES_crypt() is a faster replacement for the normal system crypt().
+This function calls DES_fcrypt() with a static array passed as the
+third parameter.  This emulates the normal non-thread safe semantics
+of crypt(3).
+
+DES_enc_write() writes I<len> bytes to file descriptor I<fd> from
+buffer I<buf>. The data is encrypted via I<pcbc_encrypt> (default)
+using I<sched> for the key and I<iv> as a starting vector.  The actual
+data send down I<fd> consists of 4 bytes (in network byte order)
+containing the length of the following encrypted data.  The encrypted
+data then follows, padded with random data out to a multiple of 8
+bytes.
+
+DES_enc_read() is used to read I<len> bytes from file descriptor
+I<fd> into buffer I<buf>. The data being read from I<fd> is assumed to
+have come from DES_enc_write() and is decrypted using I<sched> for
+the key schedule and I<iv> for the initial vector.
+
+B<Warning:> The data format used by DES_enc_write() and DES_enc_read()
+has a cryptographic weakness: When asked to write more than MAXWRITE
+bytes, DES_enc_write() will split the data into several chunks that
+are all encrypted using the same IV.  So don't use these functions
+unless you are sure you know what you do (in which case you might not
+want to use them anyway).  They cannot handle non-blocking sockets.
+DES_enc_read() uses an internal state and thus cannot be used on
+multiple files.
+
+I<DES_rw_mode> is used to specify the encryption mode to use with
+DES_enc_read() and DES_end_write().  If set to I<DES_PCBC_MODE> (the
+default), DES_pcbc_encrypt is used.  If set to I<DES_CBC_MODE>
+DES_cbc_encrypt is used.
+
+=head1 NOTES
+
+Single-key DES is insecure due to its short key size.  ECB mode is
+not suitable for most applications; see L<des_modes(7)|des_modes(7)>.
+
+The L<evp(3)|evp(3)> library provides higher-level encryption functions.
+
+=head1 BUGS
+
+DES_3cbc_encrypt() is flawed and must not be used in applications.
+
+DES_cbc_encrypt() does not modify B<ivec>; use DES_ncbc_encrypt()
+instead.
+
+DES_cfb_encrypt() and DES_ofb_encrypt() operates on input of 8 bits.
+What this means is that if you set numbits to 12, and length to 2, the
+first 12 bits will come from the 1st input byte and the low half of
+the second input byte.  The second 12 bits will have the low 8 bits
+taken from the 3rd input byte and the top 4 bits taken from the 4th
+input byte.  The same holds for output.  This function has been
+implemented this way because most people will be using a multiple of 8
+and because once you get into pulling bytes input bytes apart things
+get ugly!
+
+DES_string_to_key() is available for backward compatibility with the
+MIT library.  New applications should use a cryptographic hash function.
+The same applies for DES_string_to_2key().
+
+=head1 CONFORMING TO
+
+ANSI X3.106
+
+The B<des> library was written to be source code compatible with
+the MIT Kerberos library.
+
+=head1 SEE ALSO
+
+crypt(3), L<des_modes(7)|des_modes(7)>, L<evp(3)|evp(3)>, L<rand(3)|rand(3)>
+
+=head1 HISTORY
+
+In OpenSSL 0.9.7, all des_ functions were renamed to DES_ to avoid
+clashes with older versions of libdes.  Compatibility des_ functions
+are provided for a short while, as well as crypt().
+Declarations for these are in <openssl/des_old.h>. There is no DES_
+variant for des_random_seed().
+This will happen to other functions
+as well if they are deemed redundant (des_random_seed() just calls
+RAND_seed() and is present for backward compatibility only), buggy or
+already scheduled for removal.
+
+des_cbc_cksum(), des_cbc_encrypt(), des_ecb_encrypt(),
+des_is_weak_key(), des_key_sched(), des_pcbc_encrypt(),
+des_quad_cksum(), des_random_key() and des_string_to_key()
+are available in the MIT Kerberos library;
+des_check_key_parity(), des_fixup_key_parity() and des_is_weak_key()
+are available in newer versions of that library.
+
+des_set_key_checked() and des_set_key_unchecked() were added in
+OpenSSL 0.9.5.
+
+des_generate_random_block(), des_init_random_number_generator(),
+des_new_random_key(), des_set_random_generator_seed() and
+des_set_sequence_number() and des_rand_data() are used in newer
+versions of Kerberos but are not implemented here.
+
+des_random_key() generated cryptographically weak random data in
+SSLeay and in OpenSSL prior version 0.9.5, as well as in the original
+MIT library.
+
+=head1 AUTHOR
+
+Eric Young (eay@cryptsoft.com). Modified for the OpenSSL project
+(http://www.openssl.org).
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/des_modes.pod b/deps/openssl/openssl/doc/crypto/des_modes.pod
new file mode 100644 (file)
index 0000000..e883ca8
--- /dev/null
@@ -0,0 +1,255 @@
+=pod
+
+=for comment openssl_manual_section:7
+
+=head1 NAME
+
+des_modes - the variants of DES and other crypto algorithms of OpenSSL
+
+=head1 DESCRIPTION
+
+Several crypto algorithms for OpenSSL can be used in a number of modes.  Those
+are used for using block ciphers in a way similar to stream ciphers, among
+other things.
+
+=head1 OVERVIEW
+
+=head2 Electronic Codebook Mode (ECB)
+
+Normally, this is found as the function I<algorithm>_ecb_encrypt().
+
+=over 2
+
+=item *
+
+64 bits are enciphered at a time.
+
+=item *
+
+The order of the blocks can be rearranged without detection.
+
+=item *
+
+The same plaintext block always produces the same ciphertext block
+(for the same key) making it vulnerable to a 'dictionary attack'.
+
+=item *
+
+An error will only affect one ciphertext block.
+
+=back
+
+=head2 Cipher Block Chaining Mode (CBC)
+
+Normally, this is found as the function I<algorithm>_cbc_encrypt().
+Be aware that des_cbc_encrypt() is not really DES CBC (it does
+not update the IV); use des_ncbc_encrypt() instead.
+
+=over 2
+
+=item *
+
+a multiple of 64 bits are enciphered at a time.
+
+=item *
+
+The CBC mode produces the same ciphertext whenever the same
+plaintext is encrypted using the same key and starting variable.
+
+=item *
+
+The chaining operation makes the ciphertext blocks dependent on the
+current and all preceding plaintext blocks and therefore blocks can not
+be rearranged.
+
+=item *
+
+The use of different starting variables prevents the same plaintext
+enciphering to the same ciphertext.
+
+=item *
+
+An error will affect the current and the following ciphertext blocks.
+
+=back
+
+=head2 Cipher Feedback Mode (CFB)
+
+Normally, this is found as the function I<algorithm>_cfb_encrypt().
+
+=over 2
+
+=item *
+
+a number of bits (j) <= 64 are enciphered at a time.
+
+=item *
+
+The CFB mode produces the same ciphertext whenever the same
+plaintext is encrypted using the same key and starting variable.
+
+=item *
+
+The chaining operation makes the ciphertext variables dependent on the
+current and all preceding variables and therefore j-bit variables are
+chained together and can not be rearranged.
+
+=item *
+
+The use of different starting variables prevents the same plaintext
+enciphering to the same ciphertext.
+
+=item *
+
+The strength of the CFB mode depends on the size of k (maximal if
+j == k).  In my implementation this is always the case.
+
+=item *
+
+Selection of a small value for j will require more cycles through
+the encipherment algorithm per unit of plaintext and thus cause
+greater processing overheads.
+
+=item *
+
+Only multiples of j bits can be enciphered.
+
+=item *
+
+An error will affect the current and the following ciphertext variables.
+
+=back
+
+=head2 Output Feedback Mode (OFB)
+
+Normally, this is found as the function I<algorithm>_ofb_encrypt().
+
+=over 2
+
+
+=item *
+
+a number of bits (j) <= 64 are enciphered at a time.
+
+=item *
+
+The OFB mode produces the same ciphertext whenever the same
+plaintext enciphered using the same key and starting variable.  More
+over, in the OFB mode the same key stream is produced when the same
+key and start variable are used.  Consequently, for security reasons
+a specific start variable should be used only once for a given key.
+
+=item *
+
+The absence of chaining makes the OFB more vulnerable to specific attacks.
+
+=item *
+
+The use of different start variables values prevents the same
+plaintext enciphering to the same ciphertext, by producing different
+key streams.
+
+=item *
+
+Selection of a small value for j will require more cycles through
+the encipherment algorithm per unit of plaintext and thus cause
+greater processing overheads.
+
+=item *
+
+Only multiples of j bits can be enciphered.
+
+=item *
+
+OFB mode of operation does not extend ciphertext errors in the
+resultant plaintext output.  Every bit error in the ciphertext causes
+only one bit to be in error in the deciphered plaintext.
+
+=item *
+
+OFB mode is not self-synchronizing.  If the two operation of
+encipherment and decipherment get out of synchronism, the system needs
+to be re-initialized.
+
+=item *
+
+Each re-initialization should use a value of the start variable
+different from the start variable values used before with the same
+key.  The reason for this is that an identical bit stream would be
+produced each time from the same parameters.  This would be
+susceptible to a 'known plaintext' attack.
+
+=back
+
+=head2 Triple ECB Mode
+
+Normally, this is found as the function I<algorithm>_ecb3_encrypt().
+
+=over 2
+
+=item *
+
+Encrypt with key1, decrypt with key2 and encrypt with key3 again.
+
+=item *
+
+As for ECB encryption but increases the key length to 168 bits.
+There are theoretic attacks that can be used that make the effective
+key length 112 bits, but this attack also requires 2^56 blocks of
+memory, not very likely, even for the NSA.
+
+=item *
+
+If both keys are the same it is equivalent to encrypting once with
+just one key.
+
+=item *
+
+If the first and last key are the same, the key length is 112 bits.
+There are attacks that could reduce the effective key strength
+to only slightly more than 56 bits, but these require a lot of memory.
+
+=item *
+
+If all 3 keys are the same, this is effectively the same as normal
+ecb mode.
+
+=back
+
+=head2 Triple CBC Mode
+
+Normally, this is found as the function I<algorithm>_ede3_cbc_encrypt().
+
+=over 2
+
+
+=item *
+
+Encrypt with key1, decrypt with key2 and then encrypt with key3.
+
+=item *
+
+As for CBC encryption but increases the key length to 168 bits with
+the same restrictions as for triple ecb mode.
+
+=back
+
+=head1 NOTES
+
+This text was been written in large parts by Eric Young in his original
+documentation for SSLeay, the predecessor of OpenSSL.  In turn, he attributed
+it to:
+
+       AS 2805.5.2
+       Australian Standard
+       Electronic funds transfer - Requirements for interfaces,
+       Part 5.2: Modes of operation for an n-bit block cipher algorithm
+       Appendix A
+
+=head1 SEE ALSO
+
+L<blowfish(3)|blowfish(3)>, L<des(3)|des(3)>, L<idea(3)|idea(3)>,
+L<rc2(3)|rc2(3)>
+
+=cut
+
diff --git a/deps/openssl/openssl/doc/crypto/dh.pod b/deps/openssl/openssl/doc/crypto/dh.pod
new file mode 100644 (file)
index 0000000..c3ccd06
--- /dev/null
@@ -0,0 +1,78 @@
+=pod
+
+=head1 NAME
+
+dh - Diffie-Hellman key agreement
+
+=head1 SYNOPSIS
+
+ #include <openssl/dh.h>
+ #include <openssl/engine.h>
+
+ DH *  DH_new(void);
+ void  DH_free(DH *dh);
+
+ int   DH_size(const DH *dh);
+
+ DH *  DH_generate_parameters(int prime_len, int generator,
+               void (*callback)(int, int, void *), void *cb_arg);
+ int   DH_check(const DH *dh, int *codes);
+
+ int   DH_generate_key(DH *dh);
+ int   DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh);
+
+ void DH_set_default_method(const DH_METHOD *meth);
+ const DH_METHOD *DH_get_default_method(void);
+ int DH_set_method(DH *dh, const DH_METHOD *meth);
+ DH *DH_new_method(ENGINE *engine);
+ const DH_METHOD *DH_OpenSSL(void);
+
+ int DH_get_ex_new_index(long argl, char *argp, int (*new_func)(),
+            int (*dup_func)(), void (*free_func)());
+ int DH_set_ex_data(DH *d, int idx, char *arg);
+ char *DH_get_ex_data(DH *d, int idx);
+
+ DH *  d2i_DHparams(DH **a, unsigned char **pp, long length);
+ int   i2d_DHparams(const DH *a, unsigned char **pp);
+
+ int   DHparams_print_fp(FILE *fp, const DH *x);
+ int   DHparams_print(BIO *bp, const DH *x);
+
+=head1 DESCRIPTION
+
+These functions implement the Diffie-Hellman key agreement protocol.
+The generation of shared DH parameters is described in
+L<DH_generate_parameters(3)|DH_generate_parameters(3)>; L<DH_generate_key(3)|DH_generate_key(3)> describes how
+to perform a key agreement.
+
+The B<DH> structure consists of several BIGNUM components.
+
+ struct
+        {
+        BIGNUM *p;             // prime number (shared)
+        BIGNUM *g;             // generator of Z_p (shared)
+        BIGNUM *priv_key;      // private DH value x
+        BIGNUM *pub_key;       // public DH value g^x
+        // ...
+        };
+ DH
+
+Note that DH keys may use non-standard B<DH_METHOD> implementations,
+either directly or by the use of B<ENGINE> modules. In some cases (eg. an
+ENGINE providing support for hardware-embedded keys), these BIGNUM values
+will not be used by the implementation or may be used for alternative data
+storage. For this reason, applications should generally avoid using DH
+structure elements directly and instead use API functions to query or
+modify keys.
+
+=head1 SEE ALSO
+
+L<dhparam(1)|dhparam(1)>, L<bn(3)|bn(3)>, L<dsa(3)|dsa(3)>, L<err(3)|err(3)>,
+L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>, L<engine(3)|engine(3)>,
+L<DH_set_method(3)|DH_set_method(3)>, L<DH_new(3)|DH_new(3)>,
+L<DH_get_ex_new_index(3)|DH_get_ex_new_index(3)>,
+L<DH_generate_parameters(3)|DH_generate_parameters(3)>,
+L<DH_compute_key(3)|DH_compute_key(3)>, L<d2i_DHparams(3)|d2i_DHparams(3)>,
+L<RSA_print(3)|RSA_print(3)> 
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/dsa.pod b/deps/openssl/openssl/doc/crypto/dsa.pod
new file mode 100644 (file)
index 0000000..da07d2b
--- /dev/null
@@ -0,0 +1,114 @@
+=pod
+
+=head1 NAME
+
+dsa - Digital Signature Algorithm
+
+=head1 SYNOPSIS
+
+ #include <openssl/dsa.h>
+ #include <openssl/engine.h>
+
+ DSA * DSA_new(void);
+ void  DSA_free(DSA *dsa);
+
+ int   DSA_size(const DSA *dsa);
+
+ DSA * DSA_generate_parameters(int bits, unsigned char *seed,
+                int seed_len, int *counter_ret, unsigned long *h_ret,
+               void (*callback)(int, int, void *), void *cb_arg);
+
+ DH *  DSA_dup_DH(const DSA *r);
+
+ int   DSA_generate_key(DSA *dsa);
+
+ int   DSA_sign(int dummy, const unsigned char *dgst, int len,
+               unsigned char *sigret, unsigned int *siglen, DSA *dsa);
+ int   DSA_sign_setup(DSA *dsa, BN_CTX *ctx, BIGNUM **kinvp,
+                BIGNUM **rp);
+ int   DSA_verify(int dummy, const unsigned char *dgst, int len,
+               const unsigned char *sigbuf, int siglen, DSA *dsa);
+
+ void DSA_set_default_method(const DSA_METHOD *meth);
+ const DSA_METHOD *DSA_get_default_method(void);
+ int DSA_set_method(DSA *dsa, const DSA_METHOD *meth);
+ DSA *DSA_new_method(ENGINE *engine);
+ const DSA_METHOD *DSA_OpenSSL(void);
+
+ int DSA_get_ex_new_index(long argl, char *argp, int (*new_func)(),
+            int (*dup_func)(), void (*free_func)());
+ int DSA_set_ex_data(DSA *d, int idx, char *arg);
+ char *DSA_get_ex_data(DSA *d, int idx);
+
+ DSA_SIG *DSA_SIG_new(void);
+ void  DSA_SIG_free(DSA_SIG *a);
+ int   i2d_DSA_SIG(const DSA_SIG *a, unsigned char **pp);
+ DSA_SIG *d2i_DSA_SIG(DSA_SIG **v, unsigned char **pp, long length);
+
+ DSA_SIG *DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
+ int   DSA_do_verify(const unsigned char *dgst, int dgst_len,
+            DSA_SIG *sig, DSA *dsa);
+
+ DSA * d2i_DSAPublicKey(DSA **a, unsigned char **pp, long length);
+ DSA * d2i_DSAPrivateKey(DSA **a, unsigned char **pp, long length);
+ DSA *         d2i_DSAparams(DSA **a, unsigned char **pp, long length);
+ int   i2d_DSAPublicKey(const DSA *a, unsigned char **pp);
+ int   i2d_DSAPrivateKey(const DSA *a, unsigned char **pp);
+ int   i2d_DSAparams(const DSA *a,unsigned char **pp);
+
+ int   DSAparams_print(BIO *bp, const DSA *x);
+ int   DSAparams_print_fp(FILE *fp, const DSA *x);
+ int   DSA_print(BIO *bp, const DSA *x, int off);
+ int   DSA_print_fp(FILE *bp, const DSA *x, int off);
+
+=head1 DESCRIPTION
+
+These functions implement the Digital Signature Algorithm (DSA).  The
+generation of shared DSA parameters is described in
+L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>;
+L<DSA_generate_key(3)|DSA_generate_key(3)> describes how to
+generate a signature key. Signature generation and verification are
+described in L<DSA_sign(3)|DSA_sign(3)>.
+
+The B<DSA> structure consists of several BIGNUM components.
+
+ struct
+        {
+        BIGNUM *p;             // prime number (public)
+        BIGNUM *q;             // 160-bit subprime, q | p-1 (public)
+        BIGNUM *g;             // generator of subgroup (public)
+        BIGNUM *priv_key;      // private key x
+        BIGNUM *pub_key;       // public key y = g^x
+        // ...
+        }
+ DSA;
+
+In public keys, B<priv_key> is NULL.
+
+Note that DSA keys may use non-standard B<DSA_METHOD> implementations,
+either directly or by the use of B<ENGINE> modules. In some cases (eg. an
+ENGINE providing support for hardware-embedded keys), these BIGNUM values
+will not be used by the implementation or may be used for alternative data
+storage. For this reason, applications should generally avoid using DSA
+structure elements directly and instead use API functions to query or
+modify keys.
+
+=head1 CONFORMING TO
+
+US Federal Information Processing Standard FIPS 186 (Digital Signature
+Standard, DSS), ANSI X9.30
+
+=head1 SEE ALSO
+
+L<bn(3)|bn(3)>, L<dh(3)|dh(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>,
+L<rsa(3)|rsa(3)>, L<sha(3)|sha(3)>, L<engine(3)|engine(3)>,
+L<DSA_new(3)|DSA_new(3)>,
+L<DSA_size(3)|DSA_size(3)>,
+L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>,
+L<DSA_dup_DH(3)|DSA_dup_DH(3)>,
+L<DSA_generate_key(3)|DSA_generate_key(3)>,
+L<DSA_sign(3)|DSA_sign(3)>, L<DSA_set_method(3)|DSA_set_method(3)>,
+L<DSA_get_ex_new_index(3)|DSA_get_ex_new_index(3)>,
+L<RSA_print(3)|RSA_print(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/ecdsa.pod b/deps/openssl/openssl/doc/crypto/ecdsa.pod
new file mode 100644 (file)
index 0000000..49b10f2
--- /dev/null
@@ -0,0 +1,210 @@
+=pod
+
+=head1 NAME
+
+ecdsa - Elliptic Curve Digital Signature Algorithm
+
+=head1 SYNOPSIS
+
+ #include <openssl/ecdsa.h>
+
+ ECDSA_SIG*    ECDSA_SIG_new(void);
+ void          ECDSA_SIG_free(ECDSA_SIG *sig);
+ int           i2d_ECDSA_SIG(const ECDSA_SIG *sig, unsigned char **pp);
+ ECDSA_SIG*    d2i_ECDSA_SIG(ECDSA_SIG **sig, const unsigned char **pp, 
+               long len);
+
+ ECDSA_SIG*    ECDSA_do_sign(const unsigned char *dgst, int dgst_len,
+                       EC_KEY *eckey);
+ ECDSA_SIG*    ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen, 
+                       const BIGNUM *kinv, const BIGNUM *rp,
+                       EC_KEY *eckey);
+ int           ECDSA_do_verify(const unsigned char *dgst, int dgst_len,
+                       const ECDSA_SIG *sig, EC_KEY* eckey);
+ int           ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx,
+                       BIGNUM **kinv, BIGNUM **rp);
+ int           ECDSA_sign(int type, const unsigned char *dgst,
+                       int dgstlen, unsigned char *sig,
+                       unsigned int *siglen, EC_KEY *eckey);
+ int           ECDSA_sign_ex(int type, const unsigned char *dgst,
+                       int dgstlen, unsigned char *sig,
+                       unsigned int *siglen, const BIGNUM *kinv, 
+                       const BIGNUM *rp, EC_KEY *eckey);
+ int           ECDSA_verify(int type, const unsigned char *dgst,
+                       int dgstlen, const unsigned char *sig,
+                       int siglen, EC_KEY *eckey);
+ int           ECDSA_size(const EC_KEY *eckey);
+
+ const ECDSA_METHOD*   ECDSA_OpenSSL(void);
+ void          ECDSA_set_default_method(const ECDSA_METHOD *meth);
+ const ECDSA_METHOD*   ECDSA_get_default_method(void);
+ int           ECDSA_set_method(EC_KEY *eckey,const ECDSA_METHOD *meth);
+
+ int           ECDSA_get_ex_new_index(long argl, void *argp,
+                       CRYPTO_EX_new *new_func,
+                       CRYPTO_EX_dup *dup_func,
+                       CRYPTO_EX_free *free_func);
+ int           ECDSA_set_ex_data(EC_KEY *d, int idx, void *arg);
+ void*         ECDSA_get_ex_data(EC_KEY *d, int idx);
+
+=head1 DESCRIPTION
+
+The B<ECDSA_SIG> structure consists of two BIGNUMs for the
+r and s value of a ECDSA signature (see X9.62 or FIPS 186-2).
+
+ struct
+       {
+       BIGNUM *r;
+       BIGNUM *s;
+ } ECDSA_SIG;
+
+ECDSA_SIG_new() allocates a new B<ECDSA_SIG> structure (note: this
+function also allocates the BIGNUMs) and initialize it.
+
+ECDSA_SIG_free() frees the B<ECDSA_SIG> structure B<sig>.
+
+i2d_ECDSA_SIG() creates the DER encoding of the ECDSA signature
+B<sig> and writes the encoded signature to B<*pp> (note: if B<pp>
+is NULL B<i2d_ECDSA_SIG> returns the expected length in bytes of 
+the DER encoded signature). B<i2d_ECDSA_SIG> returns the length
+of the DER encoded signature (or 0 on error).
+
+d2i_ECDSA_SIG() decodes a DER encoded ECDSA signature and returns
+the decoded signature in a newly allocated B<ECDSA_SIG> structure.
+B<*sig> points to the buffer containing the DER encoded signature
+of size B<len>.
+
+ECDSA_size() returns the maximum length of a DER encoded
+ECDSA signature created with the private EC key B<eckey>.
+
+ECDSA_sign_setup() may be used to precompute parts of the
+signing operation. B<eckey> is the private EC key and B<ctx>
+is a pointer to B<BN_CTX> structure (or NULL). The precomputed
+values or returned in B<kinv> and B<rp> and can be used in a
+later call to B<ECDSA_sign_ex> or B<ECDSA_do_sign_ex>.
+
+ECDSA_sign() is wrapper function for ECDSA_sign_ex with B<kinv>
+and B<rp> set to NULL.
+
+ECDSA_sign_ex() computes a digital signature of the B<dgstlen> bytes
+hash value B<dgst> using the private EC key B<eckey> and the optional
+pre-computed values B<kinv> and B<rp>. The DER encoded signatures is
+stored in B<sig> and it's length is returned in B<sig_len>. Note: B<sig>
+must point to B<ECDSA_size> bytes of memory. The parameter B<type>
+is ignored.
+
+ECDSA_verify() verifies that the signature in B<sig> of size
+B<siglen> is a valid ECDSA signature of the hash value
+value B<dgst> of size B<dgstlen> using the public key B<eckey>.
+The parameter B<type> is ignored.
+
+ECDSA_do_sign() is wrapper function for ECDSA_do_sign_ex with B<kinv>
+and B<rp> set to NULL.
+
+ECDSA_do_sign_ex() computes a digital signature of the B<dgst_len>
+bytes hash value B<dgst> using the private key B<eckey> and the
+optional pre-computed values B<kinv> and B<rp>. The signature is
+returned in a newly allocated B<ECDSA_SIG> structure (or NULL on error).
+
+ECDSA_do_verify() verifies that the signature B<sig> is a valid
+ECDSA signature of the hash value B<dgst> of size B<dgst_len>
+using the public key B<eckey>.
+
+=head1 RETURN VALUES
+
+ECDSA_size() returns the maximum length signature or 0 on error.
+
+ECDSA_sign_setup() and ECDSA_sign() return 1 if successful or -1
+on error.
+
+ECDSA_verify() and ECDSA_do_verify() return 1 for a valid
+signature, 0 for an invalid signature and -1 on error.
+The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
+
+=head1 EXAMPLES
+
+Creating a ECDSA signature of given SHA-1 hash value using the
+named curve secp192k1.
+
+First step: create a EC_KEY object (note: this part is B<not> ECDSA
+specific)
+
+ int        ret;
+ ECDSA_SIG *sig;
+ EC_KEY    *eckey = EC_KEY_new();
+ if (eckey == NULL)
+       {
+       /* error */
+       }
+ key->group = EC_GROUP_new_by_nid(NID_secp192k1);
+ if (key->group == NULL)
+       {
+       /* error */
+       }
+ if (!EC_KEY_generate_key(eckey))
+       {
+       /* error */
+       }
+
+Second step: compute the ECDSA signature of a SHA-1 hash value 
+using B<ECDSA_do_sign> 
+
+ sig = ECDSA_do_sign(digest, 20, eckey);
+ if (sig == NULL)
+       {
+       /* error */
+       }
+
+or using B<ECDSA_sign>
+
+ unsigned char *buffer, *pp;
+ int            buf_len;
+ buf_len = ECDSA_size(eckey);
+ buffer  = OPENSSL_malloc(buf_len);
+ pp = buffer;
+ if (!ECDSA_sign(0, dgst, dgstlen, pp, &buf_len, eckey);
+       {
+       /* error */
+       }
+
+Third step: verify the created ECDSA signature using B<ECDSA_do_verify>
+
+ ret = ECDSA_do_verify(digest, 20, sig, eckey);
+
+or using B<ECDSA_verify>
+
+ ret = ECDSA_verify(0, digest, 20, buffer, buf_len, eckey);
+
+and finally evaluate the return value:
+
+ if (ret == -1)
+       {
+       /* error */
+       }
+ else if (ret == 0)
+       {
+       /* incorrect signature */
+       }
+ else  /* ret == 1 */
+       {
+       /* signature ok */
+       }
+
+=head1 CONFORMING TO
+
+ANSI X9.62, US Federal Information Processing Standard FIPS 186-2
+(Digital Signature Standard, DSS)
+
+=head1 SEE ALSO
+
+L<dsa(3)|dsa(3)>, L<rsa(3)|rsa(3)>
+
+=head1 HISTORY
+
+The ecdsa implementation was first introduced in OpenSSL 0.9.8
+
+=head1 AUTHOR
+
+Nils Larsch for the OpenSSL project (http://www.openssl.org).
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/engine.pod b/deps/openssl/openssl/doc/crypto/engine.pod
new file mode 100644 (file)
index 0000000..f5ab1c3
--- /dev/null
@@ -0,0 +1,599 @@
+=pod
+
+=head1 NAME
+
+engine - ENGINE cryptographic module support
+
+=head1 SYNOPSIS
+
+ #include <openssl/engine.h>
+
+ ENGINE *ENGINE_get_first(void);
+ ENGINE *ENGINE_get_last(void);
+ ENGINE *ENGINE_get_next(ENGINE *e);
+ ENGINE *ENGINE_get_prev(ENGINE *e);
+
+ int ENGINE_add(ENGINE *e);
+ int ENGINE_remove(ENGINE *e);
+
+ ENGINE *ENGINE_by_id(const char *id);
+
+ int ENGINE_init(ENGINE *e);
+ int ENGINE_finish(ENGINE *e);
+
+ void ENGINE_load_openssl(void);
+ void ENGINE_load_dynamic(void);
+ #ifndef OPENSSL_NO_STATIC_ENGINE
+ void ENGINE_load_4758cca(void);
+ void ENGINE_load_aep(void);
+ void ENGINE_load_atalla(void);
+ void ENGINE_load_chil(void);
+ void ENGINE_load_cswift(void);
+ void ENGINE_load_gmp(void);
+ void ENGINE_load_nuron(void);
+ void ENGINE_load_sureware(void);
+ void ENGINE_load_ubsec(void);
+ #endif
+ void ENGINE_load_cryptodev(void);
+ void ENGINE_load_builtin_engines(void);
+
+ void ENGINE_cleanup(void);
+
+ ENGINE *ENGINE_get_default_RSA(void);
+ ENGINE *ENGINE_get_default_DSA(void);
+ ENGINE *ENGINE_get_default_ECDH(void);
+ ENGINE *ENGINE_get_default_ECDSA(void);
+ ENGINE *ENGINE_get_default_DH(void);
+ ENGINE *ENGINE_get_default_RAND(void);
+ ENGINE *ENGINE_get_cipher_engine(int nid);
+ ENGINE *ENGINE_get_digest_engine(int nid);
+
+ int ENGINE_set_default_RSA(ENGINE *e);
+ int ENGINE_set_default_DSA(ENGINE *e);
+ int ENGINE_set_default_ECDH(ENGINE *e);
+ int ENGINE_set_default_ECDSA(ENGINE *e);
+ int ENGINE_set_default_DH(ENGINE *e);
+ int ENGINE_set_default_RAND(ENGINE *e);
+ int ENGINE_set_default_ciphers(ENGINE *e);
+ int ENGINE_set_default_digests(ENGINE *e);
+ int ENGINE_set_default_string(ENGINE *e, const char *list);
+
+ int ENGINE_set_default(ENGINE *e, unsigned int flags);
+
+ unsigned int ENGINE_get_table_flags(void);
+ void ENGINE_set_table_flags(unsigned int flags);
+
+ int ENGINE_register_RSA(ENGINE *e);
+ void ENGINE_unregister_RSA(ENGINE *e);
+ void ENGINE_register_all_RSA(void);
+ int ENGINE_register_DSA(ENGINE *e);
+ void ENGINE_unregister_DSA(ENGINE *e);
+ void ENGINE_register_all_DSA(void);
+ int ENGINE_register_ECDH(ENGINE *e);
+ void ENGINE_unregister_ECDH(ENGINE *e);
+ void ENGINE_register_all_ECDH(void);
+ int ENGINE_register_ECDSA(ENGINE *e);
+ void ENGINE_unregister_ECDSA(ENGINE *e);
+ void ENGINE_register_all_ECDSA(void);
+ int ENGINE_register_DH(ENGINE *e);
+ void ENGINE_unregister_DH(ENGINE *e);
+ void ENGINE_register_all_DH(void);
+ int ENGINE_register_RAND(ENGINE *e);
+ void ENGINE_unregister_RAND(ENGINE *e);
+ void ENGINE_register_all_RAND(void);
+ int ENGINE_register_STORE(ENGINE *e);
+ void ENGINE_unregister_STORE(ENGINE *e);
+ void ENGINE_register_all_STORE(void);
+ int ENGINE_register_ciphers(ENGINE *e);
+ void ENGINE_unregister_ciphers(ENGINE *e);
+ void ENGINE_register_all_ciphers(void);
+ int ENGINE_register_digests(ENGINE *e);
+ void ENGINE_unregister_digests(ENGINE *e);
+ void ENGINE_register_all_digests(void);
+ int ENGINE_register_complete(ENGINE *e);
+ int ENGINE_register_all_complete(void);
+
+ int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void));
+ int ENGINE_cmd_is_executable(ENGINE *e, int cmd);
+ int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
+         long i, void *p, void (*f)(void), int cmd_optional);
+ int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
+         int cmd_optional);
+
+ int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg);
+ void *ENGINE_get_ex_data(const ENGINE *e, int idx);
+
+ int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
+         CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
+
+ ENGINE *ENGINE_new(void);
+ int ENGINE_free(ENGINE *e);
+ int ENGINE_up_ref(ENGINE *e);
+
+ int ENGINE_set_id(ENGINE *e, const char *id);
+ int ENGINE_set_name(ENGINE *e, const char *name);
+ int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);
+ int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);
+ int ENGINE_set_ECDH(ENGINE *e, const ECDH_METHOD *dh_meth);
+ int ENGINE_set_ECDSA(ENGINE *e, const ECDSA_METHOD *dh_meth);
+ int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth);
+ int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth);
+ int ENGINE_set_STORE(ENGINE *e, const STORE_METHOD *rand_meth);
+ int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f);
+ int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f);
+ int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f);
+ int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f);
+ int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f);
+ int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f);
+ int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f);
+ int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f);
+ int ENGINE_set_flags(ENGINE *e, int flags);
+ int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns);
+
+ const char *ENGINE_get_id(const ENGINE *e);
+ const char *ENGINE_get_name(const ENGINE *e);
+ const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e);
+ const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e);
+ const ECDH_METHOD *ENGINE_get_ECDH(const ENGINE *e);
+ const ECDSA_METHOD *ENGINE_get_ECDSA(const ENGINE *e);
+ const DH_METHOD *ENGINE_get_DH(const ENGINE *e);
+ const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e);
+ const STORE_METHOD *ENGINE_get_STORE(const ENGINE *e);
+ ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e);
+ ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e);
+ ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e);
+ ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e);
+ ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e);
+ ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e);
+ ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e);
+ ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e);
+ const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid);
+ const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid);
+ int ENGINE_get_flags(const ENGINE *e);
+ const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e);
+
+ EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
+     UI_METHOD *ui_method, void *callback_data);
+ EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
+     UI_METHOD *ui_method, void *callback_data);
+
+ void ENGINE_add_conf_module(void);
+
+=head1 DESCRIPTION
+
+These functions create, manipulate, and use cryptographic modules in the
+form of B<ENGINE> objects. These objects act as containers for
+implementations of cryptographic algorithms, and support a
+reference-counted mechanism to allow them to be dynamically loaded in and
+out of the running application.
+
+The cryptographic functionality that can be provided by an B<ENGINE>
+implementation includes the following abstractions;
+
+ RSA_METHOD - for providing alternative RSA implementations
+ DSA_METHOD, DH_METHOD, RAND_METHOD, ECDH_METHOD, ECDSA_METHOD,
+       STORE_METHOD - similarly for other OpenSSL APIs
+ EVP_CIPHER - potentially multiple cipher algorithms (indexed by 'nid')
+ EVP_DIGEST - potentially multiple hash algorithms (indexed by 'nid')
+ key-loading - loading public and/or private EVP_PKEY keys
+
+=head2 Reference counting and handles
+
+Due to the modular nature of the ENGINE API, pointers to ENGINEs need to be
+treated as handles - ie. not only as pointers, but also as references to
+the underlying ENGINE object. Ie. one should obtain a new reference when
+making copies of an ENGINE pointer if the copies will be used (and
+released) independently.
+
+ENGINE objects have two levels of reference-counting to match the way in
+which the objects are used. At the most basic level, each ENGINE pointer is
+inherently a B<structural> reference - a structural reference is required
+to use the pointer value at all, as this kind of reference is a guarantee
+that the structure can not be deallocated until the reference is released.
+
+However, a structural reference provides no guarantee that the ENGINE is
+initiliased and able to use any of its cryptographic
+implementations. Indeed it's quite possible that most ENGINEs will not
+initialise at all in typical environments, as ENGINEs are typically used to
+support specialised hardware. To use an ENGINE's functionality, you need a
+B<functional> reference. This kind of reference can be considered a
+specialised form of structural reference, because each functional reference
+implicitly contains a structural reference as well - however to avoid
+difficult-to-find programming bugs, it is recommended to treat the two
+kinds of reference independently. If you have a functional reference to an
+ENGINE, you have a guarantee that the ENGINE has been initialised ready to
+perform cryptographic operations and will remain uninitialised
+until after you have released your reference.
+
+I<Structural references>
+
+This basic type of reference is used for instantiating new ENGINEs,
+iterating across OpenSSL's internal linked-list of loaded
+ENGINEs, reading information about an ENGINE, etc. Essentially a structural
+reference is sufficient if you only need to query or manipulate the data of
+an ENGINE implementation rather than use its functionality.
+
+The ENGINE_new() function returns a structural reference to a new (empty)
+ENGINE object. There are other ENGINE API functions that return structural
+references such as; ENGINE_by_id(), ENGINE_get_first(), ENGINE_get_last(),
+ENGINE_get_next(), ENGINE_get_prev(). All structural references should be
+released by a corresponding to call to the ENGINE_free() function - the
+ENGINE object itself will only actually be cleaned up and deallocated when
+the last structural reference is released.
+
+It should also be noted that many ENGINE API function calls that accept a
+structural reference will internally obtain another reference - typically
+this happens whenever the supplied ENGINE will be needed by OpenSSL after
+the function has returned. Eg. the function to add a new ENGINE to
+OpenSSL's internal list is ENGINE_add() - if this function returns success,
+then OpenSSL will have stored a new structural reference internally so the
+caller is still responsible for freeing their own reference with
+ENGINE_free() when they are finished with it. In a similar way, some
+functions will automatically release the structural reference passed to it
+if part of the function's job is to do so. Eg. the ENGINE_get_next() and
+ENGINE_get_prev() functions are used for iterating across the internal
+ENGINE list - they will return a new structural reference to the next (or
+previous) ENGINE in the list or NULL if at the end (or beginning) of the
+list, but in either case the structural reference passed to the function is
+released on behalf of the caller.
+
+To clarify a particular function's handling of references, one should
+always consult that function's documentation "man" page, or failing that
+the openssl/engine.h header file includes some hints.
+
+I<Functional references>
+
+As mentioned, functional references exist when the cryptographic
+functionality of an ENGINE is required to be available. A functional
+reference can be obtained in one of two ways; from an existing structural
+reference to the required ENGINE, or by asking OpenSSL for the default
+operational ENGINE for a given cryptographic purpose.
+
+To obtain a functional reference from an existing structural reference,
+call the ENGINE_init() function. This returns zero if the ENGINE was not
+already operational and couldn't be successfully initialised (eg. lack of
+system drivers, no special hardware attached, etc), otherwise it will
+return non-zero to indicate that the ENGINE is now operational and will
+have allocated a new B<functional> reference to the ENGINE. All functional
+references are released by calling ENGINE_finish() (which removes the
+implicit structural reference as well).
+
+The second way to get a functional reference is by asking OpenSSL for a
+default implementation for a given task, eg. by ENGINE_get_default_RSA(),
+ENGINE_get_default_cipher_engine(), etc. These are discussed in the next
+section, though they are not usually required by application programmers as
+they are used automatically when creating and using the relevant
+algorithm-specific types in OpenSSL, such as RSA, DSA, EVP_CIPHER_CTX, etc.
+
+=head2 Default implementations
+
+For each supported abstraction, the ENGINE code maintains an internal table
+of state to control which implementations are available for a given
+abstraction and which should be used by default. These implementations are
+registered in the tables and indexed by an 'nid' value, because
+abstractions like EVP_CIPHER and EVP_DIGEST support many distinct
+algorithms and modes, and ENGINEs can support arbitrarily many of them.
+In the case of other abstractions like RSA, DSA, etc, there is only one
+"algorithm" so all implementations implicitly register using the same 'nid'
+index.
+
+When a default ENGINE is requested for a given abstraction/algorithm/mode, (eg.
+when calling RSA_new_method(NULL)), a "get_default" call will be made to the
+ENGINE subsystem to process the corresponding state table and return a
+functional reference to an initialised ENGINE whose implementation should be
+used. If no ENGINE should (or can) be used, it will return NULL and the caller
+will operate with a NULL ENGINE handle - this usually equates to using the
+conventional software implementation. In the latter case, OpenSSL will from
+then on behave the way it used to before the ENGINE API existed.
+
+Each state table has a flag to note whether it has processed this
+"get_default" query since the table was last modified, because to process
+this question it must iterate across all the registered ENGINEs in the
+table trying to initialise each of them in turn, in case one of them is
+operational. If it returns a functional reference to an ENGINE, it will
+also cache another reference to speed up processing future queries (without
+needing to iterate across the table). Likewise, it will cache a NULL
+response if no ENGINE was available so that future queries won't repeat the
+same iteration unless the state table changes. This behaviour can also be
+changed; if the ENGINE_TABLE_FLAG_NOINIT flag is set (using
+ENGINE_set_table_flags()), no attempted initialisations will take place,
+instead the only way for the state table to return a non-NULL ENGINE to the
+"get_default" query will be if one is expressly set in the table. Eg.
+ENGINE_set_default_RSA() does the same job as ENGINE_register_RSA() except
+that it also sets the state table's cached response for the "get_default"
+query. In the case of abstractions like EVP_CIPHER, where implementations are
+indexed by 'nid', these flags and cached-responses are distinct for each 'nid'
+value.
+
+=head2 Application requirements
+
+This section will explain the basic things an application programmer should
+support to make the most useful elements of the ENGINE functionality
+available to the user. The first thing to consider is whether the
+programmer wishes to make alternative ENGINE modules available to the
+application and user. OpenSSL maintains an internal linked list of
+"visible" ENGINEs from which it has to operate - at start-up, this list is
+empty and in fact if an application does not call any ENGINE API calls and
+it uses static linking against openssl, then the resulting application
+binary will not contain any alternative ENGINE code at all. So the first
+consideration is whether any/all available ENGINE implementations should be
+made visible to OpenSSL - this is controlled by calling the various "load"
+functions, eg.
+
+ /* Make the "dynamic" ENGINE available */
+ void ENGINE_load_dynamic(void);
+ /* Make the CryptoSwift hardware acceleration support available */
+ void ENGINE_load_cswift(void);
+ /* Make support for nCipher's "CHIL" hardware available */
+ void ENGINE_load_chil(void);
+ ...
+ /* Make ALL ENGINE implementations bundled with OpenSSL available */
+ void ENGINE_load_builtin_engines(void);
+
+Having called any of these functions, ENGINE objects would have been
+dynamically allocated and populated with these implementations and linked
+into OpenSSL's internal linked list. At this point it is important to
+mention an important API function;
+
+ void ENGINE_cleanup(void);
+
+If no ENGINE API functions are called at all in an application, then there
+are no inherent memory leaks to worry about from the ENGINE functionality,
+however if any ENGINEs are loaded, even if they are never registered or
+used, it is necessary to use the ENGINE_cleanup() function to
+correspondingly cleanup before program exit, if the caller wishes to avoid
+memory leaks. This mechanism uses an internal callback registration table
+so that any ENGINE API functionality that knows it requires cleanup can
+register its cleanup details to be called during ENGINE_cleanup(). This
+approach allows ENGINE_cleanup() to clean up after any ENGINE functionality
+at all that your program uses, yet doesn't automatically create linker
+dependencies to all possible ENGINE functionality - only the cleanup
+callbacks required by the functionality you do use will be required by the
+linker.
+
+The fact that ENGINEs are made visible to OpenSSL (and thus are linked into
+the program and loaded into memory at run-time) does not mean they are
+"registered" or called into use by OpenSSL automatically - that behaviour
+is something for the application to control. Some applications
+will want to allow the user to specify exactly which ENGINE they want used
+if any is to be used at all. Others may prefer to load all support and have
+OpenSSL automatically use at run-time any ENGINE that is able to
+successfully initialise - ie. to assume that this corresponds to
+acceleration hardware attached to the machine or some such thing. There are
+probably numerous other ways in which applications may prefer to handle
+things, so we will simply illustrate the consequences as they apply to a
+couple of simple cases and leave developers to consider these and the
+source code to openssl's builtin utilities as guides.
+
+I<Using a specific ENGINE implementation>
+
+Here we'll assume an application has been configured by its user or admin
+to want to use the "ACME" ENGINE if it is available in the version of
+OpenSSL the application was compiled with. If it is available, it should be
+used by default for all RSA, DSA, and symmetric cipher operation, otherwise
+OpenSSL should use its builtin software as per usual. The following code
+illustrates how to approach this;
+
+ ENGINE *e;
+ const char *engine_id = "ACME";
+ ENGINE_load_builtin_engines();
+ e = ENGINE_by_id(engine_id);
+ if(!e)
+     /* the engine isn't available */
+     return;
+ if(!ENGINE_init(e)) {
+     /* the engine couldn't initialise, release 'e' */
+     ENGINE_free(e);
+     return;
+ }
+ if(!ENGINE_set_default_RSA(e))
+     /* This should only happen when 'e' can't initialise, but the previous
+      * statement suggests it did. */
+     abort();
+ ENGINE_set_default_DSA(e);
+ ENGINE_set_default_ciphers(e);
+ /* Release the functional reference from ENGINE_init() */
+ ENGINE_finish(e);
+ /* Release the structural reference from ENGINE_by_id() */
+ ENGINE_free(e);
+
+I<Automatically using builtin ENGINE implementations>
+
+Here we'll assume we want to load and register all ENGINE implementations
+bundled with OpenSSL, such that for any cryptographic algorithm required by
+OpenSSL - if there is an ENGINE that implements it and can be initialise,
+it should be used. The following code illustrates how this can work;
+
+ /* Load all bundled ENGINEs into memory and make them visible */
+ ENGINE_load_builtin_engines();
+ /* Register all of them for every algorithm they collectively implement */
+ ENGINE_register_all_complete();
+
+That's all that's required. Eg. the next time OpenSSL tries to set up an
+RSA key, any bundled ENGINEs that implement RSA_METHOD will be passed to
+ENGINE_init() and if any of those succeed, that ENGINE will be set as the
+default for RSA use from then on.
+
+=head2 Advanced configuration support
+
+There is a mechanism supported by the ENGINE framework that allows each
+ENGINE implementation to define an arbitrary set of configuration
+"commands" and expose them to OpenSSL and any applications based on
+OpenSSL. This mechanism is entirely based on the use of name-value pairs
+and assumes ASCII input (no unicode or UTF for now!), so it is ideal if
+applications want to provide a transparent way for users to provide
+arbitrary configuration "directives" directly to such ENGINEs. It is also
+possible for the application to dynamically interrogate the loaded ENGINE
+implementations for the names, descriptions, and input flags of their
+available "control commands", providing a more flexible configuration
+scheme. However, if the user is expected to know which ENGINE device he/she
+is using (in the case of specialised hardware, this goes without saying)
+then applications may not need to concern themselves with discovering the
+supported control commands and simply prefer to pass settings into ENGINEs
+exactly as they are provided by the user.
+
+Before illustrating how control commands work, it is worth mentioning what
+they are typically used for. Broadly speaking there are two uses for
+control commands; the first is to provide the necessary details to the
+implementation (which may know nothing at all specific to the host system)
+so that it can be initialised for use. This could include the path to any
+driver or config files it needs to load, required network addresses,
+smart-card identifiers, passwords to initialise protected devices,
+logging information, etc etc. This class of commands typically needs to be
+passed to an ENGINE B<before> attempting to initialise it, ie. before
+calling ENGINE_init(). The other class of commands consist of settings or
+operations that tweak certain behaviour or cause certain operations to take
+place, and these commands may work either before or after ENGINE_init(), or
+in some cases both. ENGINE implementations should provide indications of
+this in the descriptions attached to builtin control commands and/or in
+external product documentation.
+
+I<Issuing control commands to an ENGINE>
+
+Let's illustrate by example; a function for which the caller supplies the
+name of the ENGINE it wishes to use, a table of string-pairs for use before
+initialisation, and another table for use after initialisation. Note that
+the string-pairs used for control commands consist of a command "name"
+followed by the command "parameter" - the parameter could be NULL in some
+cases but the name can not. This function should initialise the ENGINE
+(issuing the "pre" commands beforehand and the "post" commands afterwards)
+and set it as the default for everything except RAND and then return a
+boolean success or failure.
+
+ int generic_load_engine_fn(const char *engine_id,
+                            const char **pre_cmds, int pre_num,
+                            const char **post_cmds, int post_num)
+ {
+     ENGINE *e = ENGINE_by_id(engine_id);
+     if(!e) return 0;
+     while(pre_num--) {
+         if(!ENGINE_ctrl_cmd_string(e, pre_cmds[0], pre_cmds[1], 0)) {
+             fprintf(stderr, "Failed command (%s - %s:%s)\n", engine_id,
+                 pre_cmds[0], pre_cmds[1] ? pre_cmds[1] : "(NULL)");
+             ENGINE_free(e);
+             return 0;
+         }
+        pre_cmds += 2;
+     }
+     if(!ENGINE_init(e)) {
+         fprintf(stderr, "Failed initialisation\n");
+         ENGINE_free(e);
+         return 0;
+     }
+     /* ENGINE_init() returned a functional reference, so free the structural
+      * reference from ENGINE_by_id(). */
+     ENGINE_free(e);
+     while(post_num--) {
+         if(!ENGINE_ctrl_cmd_string(e, post_cmds[0], post_cmds[1], 0)) {
+             fprintf(stderr, "Failed command (%s - %s:%s)\n", engine_id,
+                 post_cmds[0], post_cmds[1] ? post_cmds[1] : "(NULL)");
+             ENGINE_finish(e);
+             return 0;
+         }
+        post_cmds += 2;
+     }
+     ENGINE_set_default(e, ENGINE_METHOD_ALL & ~ENGINE_METHOD_RAND);
+     /* Success */
+     return 1;
+ }
+
+Note that ENGINE_ctrl_cmd_string() accepts a boolean argument that can
+relax the semantics of the function - if set non-zero it will only return
+failure if the ENGINE supported the given command name but failed while
+executing it, if the ENGINE doesn't support the command name it will simply
+return success without doing anything. In this case we assume the user is
+only supplying commands specific to the given ENGINE so we set this to
+FALSE.
+
+I<Discovering supported control commands>
+
+It is possible to discover at run-time the names, numerical-ids, descriptions
+and input parameters of the control commands supported by an ENGINE using a
+structural reference. Note that some control commands are defined by OpenSSL
+itself and it will intercept and handle these control commands on behalf of the
+ENGINE, ie. the ENGINE's ctrl() handler is not used for the control command.
+openssl/engine.h defines an index, ENGINE_CMD_BASE, that all control commands
+implemented by ENGINEs should be numbered from. Any command value lower than
+this symbol is considered a "generic" command is handled directly by the
+OpenSSL core routines.
+
+It is using these "core" control commands that one can discover the the control
+commands implemented by a given ENGINE, specifically the commands;
+
+ #define ENGINE_HAS_CTRL_FUNCTION              10
+ #define ENGINE_CTRL_GET_FIRST_CMD_TYPE                11
+ #define ENGINE_CTRL_GET_NEXT_CMD_TYPE         12
+ #define ENGINE_CTRL_GET_CMD_FROM_NAME         13
+ #define ENGINE_CTRL_GET_NAME_LEN_FROM_CMD     14
+ #define ENGINE_CTRL_GET_NAME_FROM_CMD         15
+ #define ENGINE_CTRL_GET_DESC_LEN_FROM_CMD     16
+ #define ENGINE_CTRL_GET_DESC_FROM_CMD         17
+ #define ENGINE_CTRL_GET_CMD_FLAGS             18
+
+Whilst these commands are automatically processed by the OpenSSL framework code,
+they use various properties exposed by each ENGINE to process these
+queries. An ENGINE has 3 properties it exposes that can affect how this behaves;
+it can supply a ctrl() handler, it can specify ENGINE_FLAGS_MANUAL_CMD_CTRL in
+the ENGINE's flags, and it can expose an array of control command descriptions.
+If an ENGINE specifies the ENGINE_FLAGS_MANUAL_CMD_CTRL flag, then it will
+simply pass all these "core" control commands directly to the ENGINE's ctrl()
+handler (and thus, it must have supplied one), so it is up to the ENGINE to
+reply to these "discovery" commands itself. If that flag is not set, then the
+OpenSSL framework code will work with the following rules;
+
+ if no ctrl() handler supplied;
+     ENGINE_HAS_CTRL_FUNCTION returns FALSE (zero),
+     all other commands fail.
+ if a ctrl() handler was supplied but no array of control commands;
+     ENGINE_HAS_CTRL_FUNCTION returns TRUE,
+     all other commands fail.
+ if a ctrl() handler and array of control commands was supplied;
+     ENGINE_HAS_CTRL_FUNCTION returns TRUE,
+     all other commands proceed processing ...
+
+If the ENGINE's array of control commands is empty then all other commands will
+fail, otherwise; ENGINE_CTRL_GET_FIRST_CMD_TYPE returns the identifier of
+the first command supported by the ENGINE, ENGINE_GET_NEXT_CMD_TYPE takes the
+identifier of a command supported by the ENGINE and returns the next command
+identifier or fails if there are no more, ENGINE_CMD_FROM_NAME takes a string
+name for a command and returns the corresponding identifier or fails if no such
+command name exists, and the remaining commands take a command identifier and
+return properties of the corresponding commands. All except
+ENGINE_CTRL_GET_FLAGS return the string length of a command name or description,
+or populate a supplied character buffer with a copy of the command name or
+description. ENGINE_CTRL_GET_FLAGS returns a bitwise-OR'd mask of the following
+possible values;
+
+ #define ENGINE_CMD_FLAG_NUMERIC               (unsigned int)0x0001
+ #define ENGINE_CMD_FLAG_STRING                        (unsigned int)0x0002
+ #define ENGINE_CMD_FLAG_NO_INPUT              (unsigned int)0x0004
+ #define ENGINE_CMD_FLAG_INTERNAL              (unsigned int)0x0008
+
+If the ENGINE_CMD_FLAG_INTERNAL flag is set, then any other flags are purely
+informational to the caller - this flag will prevent the command being usable
+for any higher-level ENGINE functions such as ENGINE_ctrl_cmd_string().
+"INTERNAL" commands are not intended to be exposed to text-based configuration
+by applications, administrations, users, etc. These can support arbitrary
+operations via ENGINE_ctrl(), including passing to and/or from the control
+commands data of any arbitrary type. These commands are supported in the
+discovery mechanisms simply to allow applications determinie if an ENGINE
+supports certain specific commands it might want to use (eg. application "foo"
+might query various ENGINEs to see if they implement "FOO_GET_VENDOR_LOGO_GIF" -
+and ENGINE could therefore decide whether or not to support this "foo"-specific
+extension).
+
+=head2 Future developments
+
+The ENGINE API and internal architecture is currently being reviewed. Slated for
+possible release in 0.9.8 is support for transparent loading of "dynamic"
+ENGINEs (built as self-contained shared-libraries). This would allow ENGINE
+implementations to be provided independently of OpenSSL libraries and/or
+OpenSSL-based applications, and would also remove any requirement for
+applications to explicitly use the "dynamic" ENGINE to bind to shared-library
+implementations.
+
+=head1 SEE ALSO
+
+L<rsa(3)|rsa(3)>, L<dsa(3)|dsa(3)>, L<dh(3)|dh(3)>, L<rand(3)|rand(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/err.pod b/deps/openssl/openssl/doc/crypto/err.pod
new file mode 100644 (file)
index 0000000..6f72955
--- /dev/null
@@ -0,0 +1,187 @@
+=pod
+
+=head1 NAME
+
+err - error codes
+
+=head1 SYNOPSIS
+
+ #include <openssl/err.h>
+
+ unsigned long ERR_get_error(void);
+ unsigned long ERR_peek_error(void);
+ unsigned long ERR_get_error_line(const char **file, int *line);
+ unsigned long ERR_peek_error_line(const char **file, int *line);
+ unsigned long ERR_get_error_line_data(const char **file, int *line,
+         const char **data, int *flags);
+ unsigned long ERR_peek_error_line_data(const char **file, int *line,
+         const char **data, int *flags);
+
+ int ERR_GET_LIB(unsigned long e);
+ int ERR_GET_FUNC(unsigned long e);
+ int ERR_GET_REASON(unsigned long e);
+
+ void ERR_clear_error(void);
+
+ char *ERR_error_string(unsigned long e, char *buf);
+ const char *ERR_lib_error_string(unsigned long e);
+ const char *ERR_func_error_string(unsigned long e);
+ const char *ERR_reason_error_string(unsigned long e);
+
+ void ERR_print_errors(BIO *bp);
+ void ERR_print_errors_fp(FILE *fp);
+
+ void ERR_load_crypto_strings(void);
+ void ERR_free_strings(void);
+
+ void ERR_remove_state(unsigned long pid);
+
+ void ERR_put_error(int lib, int func, int reason, const char *file,
+         int line);
+ void ERR_add_error_data(int num, ...);
+
+ void ERR_load_strings(int lib,ERR_STRING_DATA str[]);
+ unsigned long ERR_PACK(int lib, int func, int reason);
+ int ERR_get_next_error_library(void);
+
+=head1 DESCRIPTION
+
+When a call to the OpenSSL library fails, this is usually signalled
+by the return value, and an error code is stored in an error queue
+associated with the current thread. The B<err> library provides
+functions to obtain these error codes and textual error messages.
+
+The L<ERR_get_error(3)|ERR_get_error(3)> manpage describes how to
+access error codes.
+
+Error codes contain information about where the error occurred, and
+what went wrong. L<ERR_GET_LIB(3)|ERR_GET_LIB(3)> describes how to
+extract this information. A method to obtain human-readable error
+messages is described in L<ERR_error_string(3)|ERR_error_string(3)>.
+
+L<ERR_clear_error(3)|ERR_clear_error(3)> can be used to clear the
+error queue.
+
+Note that L<ERR_remove_state(3)|ERR_remove_state(3)> should be used to
+avoid memory leaks when threads are terminated.
+
+=head1 ADDING NEW ERROR CODES TO OPENSSL
+
+See L<ERR_put_error(3)> if you want to record error codes in the
+OpenSSL error system from within your application.
+
+The remainder of this section is of interest only if you want to add
+new error codes to OpenSSL or add error codes from external libraries.
+
+=head2 Reporting errors
+
+Each sub-library has a specific macro XXXerr() that is used to report
+errors. Its first argument is a function code B<XXX_F_...>, the second
+argument is a reason code B<XXX_R_...>. Function codes are derived
+from the function names; reason codes consist of textual error
+descriptions. For example, the function ssl23_read() reports a
+"handshake failure" as follows:
+
+ SSLerr(SSL_F_SSL23_READ, SSL_R_SSL_HANDSHAKE_FAILURE);
+
+Function and reason codes should consist of upper case characters,
+numbers and underscores only. The error file generation script translates
+function codes into function names by looking in the header files
+for an appropriate function name, if none is found it just uses
+the capitalized form such as "SSL23_READ" in the above example.
+
+The trailing section of a reason code (after the "_R_") is translated
+into lower case and underscores changed to spaces.
+
+When you are using new function or reason codes, run B<make errors>.
+The necessary B<#define>s will then automatically be added to the
+sub-library's header file.
+
+Although a library will normally report errors using its own specific
+XXXerr macro, another library's macro can be used. This is normally
+only done when a library wants to include ASN1 code which must use
+the ASN1err() macro.
+
+=head2 Adding new libraries
+
+When adding a new sub-library to OpenSSL, assign it a library number
+B<ERR_LIB_XXX>, define a macro XXXerr() (both in B<err.h>), add its
+name to B<ERR_str_libraries[]> (in B<crypto/err/err.c>), and add
+C<ERR_load_XXX_strings()> to the ERR_load_crypto_strings() function
+(in B<crypto/err/err_all.c>). Finally, add an entry
+
+ L     XXX     xxx.h   xxx_err.c
+
+to B<crypto/err/openssl.ec>, and add B<xxx_err.c> to the Makefile.
+Running B<make errors> will then generate a file B<xxx_err.c>, and
+add all error codes used in the library to B<xxx.h>.
+
+Additionally the library include file must have a certain form.
+Typically it will initially look like this:
+
+ #ifndef HEADER_XXX_H
+ #define HEADER_XXX_H
+
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+
+ /* Include files */
+
+ #include <openssl/bio.h>
+ #include <openssl/x509.h>
+
+ /* Macros, structures and function prototypes */
+
+
+ /* BEGIN ERROR CODES */
+
+The B<BEGIN ERROR CODES> sequence is used by the error code
+generation script as the point to place new error codes, any text
+after this point will be overwritten when B<make errors> is run.
+The closing #endif etc will be automatically added by the script.
+
+The generated C error code file B<xxx_err.c> will load the header
+files B<stdio.h>, B<openssl/err.h> and B<openssl/xxx.h> so the
+header file must load any additional header files containing any
+definitions it uses.
+
+=head1 USING ERROR CODES IN EXTERNAL LIBRARIES
+
+It is also possible to use OpenSSL's error code scheme in external
+libraries. The library needs to load its own codes and call the OpenSSL
+error code insertion script B<mkerr.pl> explicitly to add codes to
+the header file and generate the C error code file. This will normally
+be done if the external library needs to generate new ASN1 structures
+but it can also be used to add more general purpose error code handling.
+
+TBA more details
+
+=head1 INTERNALS
+
+The error queues are stored in a hash table with one B<ERR_STATE>
+entry for each pid. ERR_get_state() returns the current thread's
+B<ERR_STATE>. An B<ERR_STATE> can hold up to B<ERR_NUM_ERRORS> error
+codes. When more error codes are added, the old ones are overwritten,
+on the assumption that the most recent errors are most important.
+
+Error strings are also stored in hash table. The hash tables can
+be obtained by calling ERR_get_err_state_table(void) and
+ERR_get_string_table(void) respectively.
+
+=head1 SEE ALSO
+
+L<CRYPTO_set_id_callback(3)|CRYPTO_set_id_callback(3)>,
+L<CRYPTO_set_locking_callback(3)|CRYPTO_set_locking_callback(3)>,
+L<ERR_get_error(3)|ERR_get_error(3)>,
+L<ERR_GET_LIB(3)|ERR_GET_LIB(3)>,
+L<ERR_clear_error(3)|ERR_clear_error(3)>,
+L<ERR_error_string(3)|ERR_error_string(3)>,
+L<ERR_print_errors(3)|ERR_print_errors(3)>,
+L<ERR_load_crypto_strings(3)|ERR_load_crypto_strings(3)>,
+L<ERR_remove_state(3)|ERR_remove_state(3)>,
+L<ERR_put_error(3)|ERR_put_error(3)>,
+L<ERR_load_strings(3)|ERR_load_strings(3)>,
+L<SSL_get_error(3)|SSL_get_error(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/evp.pod b/deps/openssl/openssl/doc/crypto/evp.pod
new file mode 100644 (file)
index 0000000..9faa349
--- /dev/null
@@ -0,0 +1,55 @@
+=pod
+
+=head1 NAME
+
+evp - high-level cryptographic functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+=head1 DESCRIPTION
+
+The EVP library provides a high-level interface to cryptographic
+functions.
+
+B<EVP_Seal>I<...> and B<EVP_Open>I<...> provide public key encryption
+and decryption to implement digital "envelopes".
+
+The B<EVP_Sign>I<...> and B<EVP_Verify>I<...> functions implement
+digital signatures.
+
+Symmetric encryption is available with the B<EVP_Encrypt>I<...>
+functions.  The B<EVP_Digest>I<...> functions provide message digests.
+
+The B<EVP_PKEY>I<...> functions provide a high level interface to
+asymmetric algorithms.
+
+Algorithms are loaded with OpenSSL_add_all_algorithms(3).
+
+All the symmetric algorithms (ciphers), digests and asymmetric algorithms
+(public key algorithms) can be replaced by ENGINE modules providing alternative
+implementations. If ENGINE implementations of ciphers or digests are registered
+as defaults, then the various EVP functions will automatically use those
+implementations automatically in preference to built in software
+implementations. For more information, consult the engine(3) man page.
+
+Although low level algorithm specific functions exist for many algorithms
+their use is discouraged. They cannot be used with an ENGINE and ENGINE
+versions of new algorithms cannot be accessed using the low level functions.
+Also makes code harder to adapt to new algorithms and some options are not 
+cleanly supported at the low level and some operations are more efficient
+using the high level interface.
+
+=head1 SEE ALSO
+
+L<EVP_DigestInit(3)|EVP_DigestInit(3)>,
+L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>,
+L<EVP_OpenInit(3)|EVP_OpenInit(3)>,
+L<EVP_SealInit(3)|EVP_SealInit(3)>,
+L<EVP_SignInit(3)|EVP_SignInit(3)>,
+L<EVP_VerifyInit(3)|EVP_VerifyInit(3)>,
+L<OpenSSL_add_all_algorithms(3)|OpenSSL_add_all_algorithms(3)>,
+L<engine(3)|engine(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/hmac.pod b/deps/openssl/openssl/doc/crypto/hmac.pod
new file mode 100644 (file)
index 0000000..d92138d
--- /dev/null
@@ -0,0 +1,106 @@
+=pod
+
+=head1 NAME
+
+HMAC, HMAC_Init, HMAC_Update, HMAC_Final, HMAC_cleanup - HMAC message
+authentication code
+
+=head1 SYNOPSIS
+
+ #include <openssl/hmac.h>
+
+ unsigned char *HMAC(const EVP_MD *evp_md, const void *key,
+               int key_len, const unsigned char *d, int n,
+               unsigned char *md, unsigned int *md_len);
+
+ void HMAC_CTX_init(HMAC_CTX *ctx);
+
+ int HMAC_Init(HMAC_CTX *ctx, const void *key, int key_len,
+               const EVP_MD *md);
+ int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int key_len,
+                          const EVP_MD *md, ENGINE *impl);
+ int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len);
+ int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
+
+ void HMAC_CTX_cleanup(HMAC_CTX *ctx);
+ void HMAC_cleanup(HMAC_CTX *ctx);
+
+=head1 DESCRIPTION
+
+HMAC is a MAC (message authentication code), i.e. a keyed hash
+function used for message authentication, which is based on a hash
+function.
+
+HMAC() computes the message authentication code of the B<n> bytes at
+B<d> using the hash function B<evp_md> and the key B<key> which is
+B<key_len> bytes long.
+
+It places the result in B<md> (which must have space for the output of
+the hash function, which is no more than B<EVP_MAX_MD_SIZE> bytes).
+If B<md> is NULL, the digest is placed in a static array.  The size of
+the output is placed in B<md_len>, unless it is B<NULL>.
+
+B<evp_md> can be EVP_sha1(), EVP_ripemd160() etc.
+
+HMAC_CTX_init() initialises a B<HMAC_CTX> before first use. It must be
+called.
+
+HMAC_CTX_cleanup() erases the key and other data from the B<HMAC_CTX>
+and releases any associated resources. It must be called when an
+B<HMAC_CTX> is no longer required.
+
+HMAC_cleanup() is an alias for HMAC_CTX_cleanup() included for back
+compatibility with 0.9.6b, it is deprecated.
+
+The following functions may be used if the message is not completely
+stored in memory:
+
+HMAC_Init() initializes a B<HMAC_CTX> structure to use the hash
+function B<evp_md> and the key B<key> which is B<key_len> bytes
+long. It is deprecated and only included for backward compatibility
+with OpenSSL 0.9.6b.
+
+HMAC_Init_ex() initializes or reuses a B<HMAC_CTX> structure to use
+the function B<evp_md> and key B<key>. Either can be NULL, in which
+case the existing one will be reused. HMAC_CTX_init() must have been
+called before the first use of an B<HMAC_CTX> in this
+function. B<N.B. HMAC_Init() had this undocumented behaviour in
+previous versions of OpenSSL - failure to switch to HMAC_Init_ex() in
+programs that expect it will cause them to stop working>.
+
+HMAC_Update() can be called repeatedly with chunks of the message to
+be authenticated (B<len> bytes at B<data>).
+
+HMAC_Final() places the message authentication code in B<md>, which
+must have space for the hash function output.
+
+=head1 RETURN VALUES
+
+HMAC() returns a pointer to the message authentication code or NULL if
+an error occurred.
+
+HMAC_Init_ex(), HMAC_Update() and HMAC_Final() return 1 for success or 0 if
+an error occurred.
+
+HMAC_CTX_init() and HMAC_CTX_cleanup() do not return values.
+
+=head1 CONFORMING TO
+
+RFC 2104
+
+=head1 SEE ALSO
+
+L<sha(3)|sha(3)>, L<evp(3)|evp(3)>
+
+=head1 HISTORY
+
+HMAC(), HMAC_Init(), HMAC_Update(), HMAC_Final() and HMAC_cleanup()
+are available since SSLeay 0.9.0.
+
+HMAC_CTX_init(), HMAC_Init_ex() and HMAC_CTX_cleanup() are available
+since OpenSSL 0.9.7.
+
+HMAC_Init_ex(), HMAC_Update() and HMAC_Final() did not return values in
+versions of OpenSSL before 1.0.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/i2d_CMS_bio_stream.pod b/deps/openssl/openssl/doc/crypto/i2d_CMS_bio_stream.pod
new file mode 100644 (file)
index 0000000..558bdd0
--- /dev/null
@@ -0,0 +1,44 @@
+=pod
+
+=head1 NAME
+
+ i2d_CMS_bio_stream - output CMS_ContentInfo structure in BER format.
+
+=head1 SYNOPSIS
+
+ #include <openssl/cms.h>
+
+ int i2d_CMS_bio_stream(BIO *out, CMS_ContentInfo *cms, BIO *data, int flags);
+
+=head1 DESCRIPTION
+
+i2d_CMS_bio_stream() outputs a CMS_ContentInfo structure in BER format.
+
+It is otherwise identical to the function SMIME_write_CMS().
+
+=head1 NOTES
+
+This function is effectively a version of the i2d_CMS_bio() supporting
+streaming.
+
+=head1 BUGS
+
+The prefix "i2d" is arguably wrong because the function outputs BER format.
+
+=head1 RETURN VALUES
+
+i2d_CMS_bio_stream() returns 1 for success or 0 for failure.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<CMS_sign(3)|CMS_sign(3)>,
+L<CMS_verify(3)|CMS_verify(3)>, L<CMS_encrypt(3)|CMS_encrypt(3)>
+L<CMS_decrypt(3)|CMS_decrypt(3)>,
+L<SMIME_write_CMS(3)|SMIME_write_CMS(3)>,
+L<PEM_write_bio_CMS_stream(3)|PEM_write_bio_CMS_stream(3)>
+
+=head1 HISTORY
+
+i2d_CMS_bio_stream() was added to OpenSSL 1.0.0
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/i2d_PKCS7_bio_stream.pod b/deps/openssl/openssl/doc/crypto/i2d_PKCS7_bio_stream.pod
new file mode 100644 (file)
index 0000000..dc4d884
--- /dev/null
@@ -0,0 +1,44 @@
+=pod
+
+=head1 NAME
+
+i2d_PKCS7_bio_stream - output PKCS7 structure in BER format.
+
+=head1 SYNOPSIS
+
+ #include <openssl/pkcs7.h>
+
+ int i2d_PKCS7_bio_stream(BIO *out, PKCS7 *p7, BIO *data, int flags);
+
+=head1 DESCRIPTION
+
+i2d_PKCS7_bio_stream() outputs a PKCS7 structure in BER format.
+
+It is otherwise identical to the function SMIME_write_PKCS7().
+
+=head1 NOTES
+
+This function is effectively a version of the d2i_PKCS7_bio() supporting
+streaming.
+
+=head1 BUGS
+
+The prefix "d2i" is arguably wrong because the function outputs BER format.
+
+=head1 RETURN VALUES
+
+i2d_PKCS7_bio_stream() returns 1 for success or 0 for failure.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_sign(3)|PKCS7_sign(3)>,
+L<PKCS7_verify(3)|PKCS7_verify(3)>, L<PKCS7_encrypt(3)|PKCS7_encrypt(3)>
+L<PKCS7_decrypt(3)|PKCS7_decrypt(3)>,
+L<SMIME_write_PKCS7(3)|SMIME_write_PKCS7(3)>,
+L<PEM_write_bio_PKCS7_stream(3)|PEM_write_bio_PKCS7_stream(3)>
+
+=head1 HISTORY
+
+i2d_PKCS7_bio_stream() was added to OpenSSL 1.0.0
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/lh_stats.pod b/deps/openssl/openssl/doc/crypto/lh_stats.pod
new file mode 100644 (file)
index 0000000..3eeaa72
--- /dev/null
@@ -0,0 +1,60 @@
+=pod
+
+=head1 NAME
+
+lh_stats, lh_node_stats, lh_node_usage_stats, lh_stats_bio,
+lh_node_stats_bio, lh_node_usage_stats_bio - LHASH statistics
+
+=head1 SYNOPSIS
+
+ #include <openssl/lhash.h>
+
+ void lh_stats(LHASH *table, FILE *out);
+ void lh_node_stats(LHASH *table, FILE *out);
+ void lh_node_usage_stats(LHASH *table, FILE *out);
+
+ void lh_stats_bio(LHASH *table, BIO *out);
+ void lh_node_stats_bio(LHASH *table, BIO *out);
+ void lh_node_usage_stats_bio(LHASH *table, BIO *out);
+
+=head1 DESCRIPTION
+
+The B<LHASH> structure records statistics about most aspects of
+accessing the hash table.  This is mostly a legacy of Eric Young
+writing this library for the reasons of implementing what looked like
+a nice algorithm rather than for a particular software product.
+
+lh_stats() prints out statistics on the size of the hash table, how
+many entries are in it, and the number and result of calls to the
+routines in this library.
+
+lh_node_stats() prints the number of entries for each 'bucket' in the
+hash table.
+
+lh_node_usage_stats() prints out a short summary of the state of the
+hash table.  It prints the 'load' and the 'actual load'.  The load is
+the average number of data items per 'bucket' in the hash table.  The
+'actual load' is the average number of items per 'bucket', but only
+for buckets which contain entries.  So the 'actual load' is the
+average number of searches that will need to find an item in the hash
+table, while the 'load' is the average number that will be done to
+record a miss.
+
+lh_stats_bio(), lh_node_stats_bio() and lh_node_usage_stats_bio()
+are the same as the above, except that the output goes to a B<BIO>.
+
+=head1 RETURN VALUES
+
+These functions do not return values.
+
+=head1 SEE ALSO
+
+L<bio(3)|bio(3)>, L<lhash(3)|lhash(3)>
+
+=head1 HISTORY
+
+These functions are available in all versions of SSLeay and OpenSSL.
+
+This manpage is derived from the SSLeay documentation.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/lhash.pod b/deps/openssl/openssl/doc/crypto/lhash.pod
new file mode 100644 (file)
index 0000000..73a19b6
--- /dev/null
@@ -0,0 +1,302 @@
+=pod
+
+=head1 NAME
+
+lh_new, lh_free, lh_insert, lh_delete, lh_retrieve, lh_doall, lh_doall_arg, lh_error - dynamic hash table
+
+=head1 SYNOPSIS
+
+ #include <openssl/lhash.h>
+
+ DECLARE_LHASH_OF(<type>);
+
+ LHASH *lh_<type>_new();
+ void lh_<type>_free(LHASH_OF(<type> *table);
+
+ <type> *lh_<type>_insert(LHASH_OF(<type> *table, <type> *data);
+ <type> *lh_<type>_delete(LHASH_OF(<type> *table, <type> *data);
+ <type> *lh_retrieve(LHASH_OF<type> *table, <type> *data);
+
+ void lh_<type>_doall(LHASH_OF(<type> *table, LHASH_DOALL_FN_TYPE func);
+ void lh_<type>_doall_arg(LHASH_OF(<type> *table, LHASH_DOALL_ARG_FN_TYPE func,
+          <type2>, <type2> *arg);
+
+ int lh_<type>_error(LHASH_OF(<type> *table);
+
+ typedef int (*LHASH_COMP_FN_TYPE)(const void *, const void *);
+ typedef unsigned long (*LHASH_HASH_FN_TYPE)(const void *);
+ typedef void (*LHASH_DOALL_FN_TYPE)(const void *);
+ typedef void (*LHASH_DOALL_ARG_FN_TYPE)(const void *, const void *);
+
+=head1 DESCRIPTION
+
+This library implements type-checked dynamic hash tables. The hash
+table entries can be arbitrary structures. Usually they consist of key
+and value fields.
+
+lh_<type>_new() creates a new B<LHASH_OF(<type>> structure to store
+arbitrary data entries, and provides the 'hash' and 'compare'
+callbacks to be used in organising the table's entries.  The B<hash>
+callback takes a pointer to a table entry as its argument and returns
+an unsigned long hash value for its key field.  The hash value is
+normally truncated to a power of 2, so make sure that your hash
+function returns well mixed low order bits.  The B<compare> callback
+takes two arguments (pointers to two hash table entries), and returns
+0 if their keys are equal, non-zero otherwise.  If your hash table
+will contain items of some particular type and the B<hash> and
+B<compare> callbacks hash/compare these types, then the
+B<DECLARE_LHASH_HASH_FN> and B<IMPLEMENT_LHASH_COMP_FN> macros can be
+used to create callback wrappers of the prototypes required by
+lh_<type>_new().  These provide per-variable casts before calling the
+type-specific callbacks written by the application author.  These
+macros, as well as those used for the "doall" callbacks, are defined
+as;
+
+ #define DECLARE_LHASH_HASH_FN(name, o_type) \
+        unsigned long name##_LHASH_HASH(const void *);
+ #define IMPLEMENT_LHASH_HASH_FN(name, o_type) \
+        unsigned long name##_LHASH_HASH(const void *arg) { \
+                const o_type *a = arg; \
+                return name##_hash(a); }
+ #define LHASH_HASH_FN(name) name##_LHASH_HASH
+
+ #define DECLARE_LHASH_COMP_FN(name, o_type) \
+        int name##_LHASH_COMP(const void *, const void *);
+ #define IMPLEMENT_LHASH_COMP_FN(name, o_type) \
+        int name##_LHASH_COMP(const void *arg1, const void *arg2) { \
+                const o_type *a = arg1;                    \
+                const o_type *b = arg2; \
+                return name##_cmp(a,b); }
+ #define LHASH_COMP_FN(name) name##_LHASH_COMP
+
+ #define DECLARE_LHASH_DOALL_FN(name, o_type) \
+        void name##_LHASH_DOALL(void *);
+ #define IMPLEMENT_LHASH_DOALL_FN(name, o_type) \
+        void name##_LHASH_DOALL(void *arg) { \
+                o_type *a = arg; \
+                name##_doall(a); }
+ #define LHASH_DOALL_FN(name) name##_LHASH_DOALL
+
+ #define DECLARE_LHASH_DOALL_ARG_FN(name, o_type, a_type) \
+        void name##_LHASH_DOALL_ARG(void *, void *);
+ #define IMPLEMENT_LHASH_DOALL_ARG_FN(name, o_type, a_type) \
+        void name##_LHASH_DOALL_ARG(void *arg1, void *arg2) { \
+                o_type *a = arg1; \
+                a_type *b = arg2; \
+                name##_doall_arg(a, b); }
+ #define LHASH_DOALL_ARG_FN(name) name##_LHASH_DOALL_ARG
+
+ An example of a hash table storing (pointers to) structures of type 'STUFF'
+ could be defined as follows;
+
+ /* Calculates the hash value of 'tohash' (implemented elsewhere) */
+ unsigned long STUFF_hash(const STUFF *tohash);
+ /* Orders 'arg1' and 'arg2' (implemented elsewhere) */
+ int stuff_cmp(const STUFF *arg1, const STUFF *arg2);
+ /* Create the type-safe wrapper functions for use in the LHASH internals */
+ static IMPLEMENT_LHASH_HASH_FN(stuff, STUFF);
+ static IMPLEMENT_LHASH_COMP_FN(stuff, STUFF);
+ /* ... */
+ int main(int argc, char *argv[]) {
+         /* Create the new hash table using the hash/compare wrappers */
+         LHASH_OF(STUFF) *hashtable = lh_STUFF_new(LHASH_HASH_FN(STUFF_hash),
+                                   LHASH_COMP_FN(STUFF_cmp));
+        /* ... */
+ }
+
+lh_<type>_free() frees the B<LHASH_OF(<type>> structure
+B<table>. Allocated hash table entries will not be freed; consider
+using lh_<type>_doall() to deallocate any remaining entries in the
+hash table (see below).
+
+lh_<type>_insert() inserts the structure pointed to by B<data> into
+B<table>.  If there already is an entry with the same key, the old
+value is replaced. Note that lh_<type>_insert() stores pointers, the
+data are not copied.
+
+lh_<type>_delete() deletes an entry from B<table>.
+
+lh_<type>_retrieve() looks up an entry in B<table>. Normally, B<data>
+is a structure with the key field(s) set; the function will return a
+pointer to a fully populated structure.
+
+lh_<type>_doall() will, for every entry in the hash table, call
+B<func> with the data item as its parameter.  For lh_<type>_doall()
+and lh_<type>_doall_arg(), function pointer casting should be avoided
+in the callbacks (see B<NOTE>) - instead use the declare/implement
+macros to create type-checked wrappers that cast variables prior to
+calling your type-specific callbacks.  An example of this is
+illustrated here where the callback is used to cleanup resources for
+items in the hash table prior to the hashtable itself being
+deallocated:
+
+ /* Cleans up resources belonging to 'a' (this is implemented elsewhere) */
+ void STUFF_cleanup_doall(STUFF *a);
+ /* Implement a prototype-compatible wrapper for "STUFF_cleanup" */
+ IMPLEMENT_LHASH_DOALL_FN(STUFF_cleanup, STUFF)
+         /* ... then later in the code ... */
+ /* So to run "STUFF_cleanup" against all items in a hash table ... */
+ lh_STUFF_doall(hashtable, LHASH_DOALL_FN(STUFF_cleanup));
+ /* Then the hash table itself can be deallocated */
+ lh_STUFF_free(hashtable);
+
+When doing this, be careful if you delete entries from the hash table
+in your callbacks: the table may decrease in size, moving the item
+that you are currently on down lower in the hash table - this could
+cause some entries to be skipped during the iteration.  The second
+best solution to this problem is to set hash-E<gt>down_load=0 before
+you start (which will stop the hash table ever decreasing in size).
+The best solution is probably to avoid deleting items from the hash
+table inside a "doall" callback!
+
+lh_<type>_doall_arg() is the same as lh_<type>_doall() except that
+B<func> will be called with B<arg> as the second argument and B<func>
+should be of type B<LHASH_DOALL_ARG_FN_TYPE> (a callback prototype
+that is passed both the table entry and an extra argument).  As with
+lh_doall(), you can instead choose to declare your callback with a
+prototype matching the types you are dealing with and use the
+declare/implement macros to create compatible wrappers that cast
+variables before calling your type-specific callbacks.  An example of
+this is demonstrated here (printing all hash table entries to a BIO
+that is provided by the caller):
+
+ /* Prints item 'a' to 'output_bio' (this is implemented elsewhere) */
+ void STUFF_print_doall_arg(const STUFF *a, BIO *output_bio);
+ /* Implement a prototype-compatible wrapper for "STUFF_print" */
+ static IMPLEMENT_LHASH_DOALL_ARG_FN(STUFF, const STUFF, BIO)
+         /* ... then later in the code ... */
+ /* Print out the entire hashtable to a particular BIO */
+ lh_STUFF_doall_arg(hashtable, LHASH_DOALL_ARG_FN(STUFF_print), BIO,
+                    logging_bio);
+lh_<type>_error() can be used to determine if an error occurred in the last
+operation. lh_<type>_error() is a macro.
+
+=head1 RETURN VALUES
+
+lh_<type>_new() returns B<NULL> on error, otherwise a pointer to the new
+B<LHASH> structure.
+
+When a hash table entry is replaced, lh_<type>_insert() returns the value
+being replaced. B<NULL> is returned on normal operation and on error.
+
+lh_<type>_delete() returns the entry being deleted.  B<NULL> is returned if
+there is no such value in the hash table.
+
+lh_<type>_retrieve() returns the hash table entry if it has been found,
+B<NULL> otherwise.
+
+lh_<type>_error() returns 1 if an error occurred in the last operation, 0
+otherwise.
+
+lh_<type>_free(), lh_<type>_doall() and lh_<type>_doall_arg() return no values.
+
+=head1 NOTE
+
+The various LHASH macros and callback types exist to make it possible
+to write type-checked code without resorting to function-prototype
+casting - an evil that makes application code much harder to
+audit/verify and also opens the window of opportunity for stack
+corruption and other hard-to-find bugs.  It also, apparently, violates
+ANSI-C.
+
+The LHASH code regards table entries as constant data.  As such, it
+internally represents lh_insert()'d items with a "const void *"
+pointer type.  This is why callbacks such as those used by lh_doall()
+and lh_doall_arg() declare their prototypes with "const", even for the
+parameters that pass back the table items' data pointers - for
+consistency, user-provided data is "const" at all times as far as the
+LHASH code is concerned.  However, as callers are themselves providing
+these pointers, they can choose whether they too should be treating
+all such parameters as constant.
+
+As an example, a hash table may be maintained by code that, for
+reasons of encapsulation, has only "const" access to the data being
+indexed in the hash table (ie. it is returned as "const" from
+elsewhere in their code) - in this case the LHASH prototypes are
+appropriate as-is.  Conversely, if the caller is responsible for the
+life-time of the data in question, then they may well wish to make
+modifications to table item passed back in the lh_doall() or
+lh_doall_arg() callbacks (see the "STUFF_cleanup" example above).  If
+so, the caller can either cast the "const" away (if they're providing
+the raw callbacks themselves) or use the macros to declare/implement
+the wrapper functions without "const" types.
+
+Callers that only have "const" access to data they're indexing in a
+table, yet declare callbacks without constant types (or cast the
+"const" away themselves), are therefore creating their own risks/bugs
+without being encouraged to do so by the API.  On a related note,
+those auditing code should pay special attention to any instances of
+DECLARE/IMPLEMENT_LHASH_DOALL_[ARG_]_FN macros that provide types
+without any "const" qualifiers.
+
+=head1 BUGS
+
+lh_<type>_insert() returns B<NULL> both for success and error.
+
+=head1 INTERNALS
+
+The following description is based on the SSLeay documentation:
+
+The B<lhash> library implements a hash table described in the
+I<Communications of the ACM> in 1991.  What makes this hash table
+different is that as the table fills, the hash table is increased (or
+decreased) in size via OPENSSL_realloc().  When a 'resize' is done, instead of
+all hashes being redistributed over twice as many 'buckets', one
+bucket is split.  So when an 'expand' is done, there is only a minimal
+cost to redistribute some values.  Subsequent inserts will cause more
+single 'bucket' redistributions but there will never be a sudden large
+cost due to redistributing all the 'buckets'.
+
+The state for a particular hash table is kept in the B<LHASH> structure.
+The decision to increase or decrease the hash table size is made
+depending on the 'load' of the hash table.  The load is the number of
+items in the hash table divided by the size of the hash table.  The
+default values are as follows.  If (hash->up_load E<lt> load) =E<gt>
+expand.  if (hash-E<gt>down_load E<gt> load) =E<gt> contract.  The
+B<up_load> has a default value of 1 and B<down_load> has a default value
+of 2.  These numbers can be modified by the application by just
+playing with the B<up_load> and B<down_load> variables.  The 'load' is
+kept in a form which is multiplied by 256.  So
+hash-E<gt>up_load=8*256; will cause a load of 8 to be set.
+
+If you are interested in performance the field to watch is
+num_comp_calls.  The hash library keeps track of the 'hash' value for
+each item so when a lookup is done, the 'hashes' are compared, if
+there is a match, then a full compare is done, and
+hash-E<gt>num_comp_calls is incremented.  If num_comp_calls is not equal
+to num_delete plus num_retrieve it means that your hash function is
+generating hashes that are the same for different values.  It is
+probably worth changing your hash function if this is the case because
+even if your hash table has 10 items in a 'bucket', it can be searched
+with 10 B<unsigned long> compares and 10 linked list traverses.  This
+will be much less expensive that 10 calls to your compare function.
+
+lh_strhash() is a demo string hashing function:
+
+ unsigned long lh_strhash(const char *c);
+
+Since the B<LHASH> routines would normally be passed structures, this
+routine would not normally be passed to lh_<type>_new(), rather it would be
+used in the function passed to lh_<type>_new().
+
+=head1 SEE ALSO
+
+L<lh_stats(3)|lh_stats(3)>
+
+=head1 HISTORY
+
+The B<lhash> library is available in all versions of SSLeay and OpenSSL.
+lh_error() was added in SSLeay 0.9.1b.
+
+This manpage is derived from the SSLeay documentation.
+
+In OpenSSL 0.9.7, all lhash functions that were passed function pointers
+were changed for better type safety, and the function types LHASH_COMP_FN_TYPE,
+LHASH_HASH_FN_TYPE, LHASH_DOALL_FN_TYPE and LHASH_DOALL_ARG_FN_TYPE 
+became available.
+
+In OpenSSL 1.0.0, the lhash interface was revamped for even better
+type checking.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/md5.pod b/deps/openssl/openssl/doc/crypto/md5.pod
new file mode 100644 (file)
index 0000000..d11d5c3
--- /dev/null
@@ -0,0 +1,101 @@
+=pod
+
+=head1 NAME
+
+MD2, MD4, MD5, MD2_Init, MD2_Update, MD2_Final, MD4_Init, MD4_Update,
+MD4_Final, MD5_Init, MD5_Update, MD5_Final - MD2, MD4, and MD5 hash functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/md2.h>
+
+ unsigned char *MD2(const unsigned char *d, unsigned long n,
+                  unsigned char *md);
+
+ int MD2_Init(MD2_CTX *c);
+ int MD2_Update(MD2_CTX *c, const unsigned char *data,
+                  unsigned long len);
+ int MD2_Final(unsigned char *md, MD2_CTX *c);
+
+
+ #include <openssl/md4.h>
+
+ unsigned char *MD4(const unsigned char *d, unsigned long n,
+                  unsigned char *md);
+
+ int MD4_Init(MD4_CTX *c);
+ int MD4_Update(MD4_CTX *c, const void *data,
+                  unsigned long len);
+ int MD4_Final(unsigned char *md, MD4_CTX *c);
+
+
+ #include <openssl/md5.h>
+
+ unsigned char *MD5(const unsigned char *d, unsigned long n,
+                  unsigned char *md);
+
+ int MD5_Init(MD5_CTX *c);
+ int MD5_Update(MD5_CTX *c, const void *data,
+                  unsigned long len);
+ int MD5_Final(unsigned char *md, MD5_CTX *c);
+
+=head1 DESCRIPTION
+
+MD2, MD4, and MD5 are cryptographic hash functions with a 128 bit output.
+
+MD2(), MD4(), and MD5() compute the MD2, MD4, and MD5 message digest
+of the B<n> bytes at B<d> and place it in B<md> (which must have space
+for MD2_DIGEST_LENGTH == MD4_DIGEST_LENGTH == MD5_DIGEST_LENGTH == 16
+bytes of output). If B<md> is NULL, the digest is placed in a static
+array.
+
+The following functions may be used if the message is not completely
+stored in memory:
+
+MD2_Init() initializes a B<MD2_CTX> structure.
+
+MD2_Update() can be called repeatedly with chunks of the message to
+be hashed (B<len> bytes at B<data>).
+
+MD2_Final() places the message digest in B<md>, which must have space
+for MD2_DIGEST_LENGTH == 16 bytes of output, and erases the B<MD2_CTX>.
+
+MD4_Init(), MD4_Update(), MD4_Final(), MD5_Init(), MD5_Update(), and
+MD5_Final() are analogous using an B<MD4_CTX> and B<MD5_CTX> structure.
+
+Applications should use the higher level functions
+L<EVP_DigestInit(3)|EVP_DigestInit(3)>
+etc. instead of calling the hash functions directly.
+
+=head1 NOTE
+
+MD2, MD4, and MD5 are recommended only for compatibility with existing
+applications. In new applications, SHA-1 or RIPEMD-160 should be
+preferred.
+
+=head1 RETURN VALUES
+
+MD2(), MD4(), and MD5() return pointers to the hash value. 
+
+MD2_Init(), MD2_Update(), MD2_Final(), MD4_Init(), MD4_Update(),
+MD4_Final(), MD5_Init(), MD5_Update(), and MD5_Final() return 1 for
+success, 0 otherwise.
+
+=head1 CONFORMING TO
+
+RFC 1319, RFC 1320, RFC 1321
+
+=head1 SEE ALSO
+
+L<sha(3)|sha(3)>, L<ripemd(3)|ripemd(3)>, L<EVP_DigestInit(3)|EVP_DigestInit(3)>
+
+=head1 HISTORY
+
+MD2(), MD2_Init(), MD2_Update() MD2_Final(), MD5(), MD5_Init(),
+MD5_Update() and MD5_Final() are available in all versions of SSLeay
+and OpenSSL.
+
+MD4(), MD4_Init(), and MD4_Update() are available in OpenSSL 0.9.6 and
+above.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/mdc2.pod b/deps/openssl/openssl/doc/crypto/mdc2.pod
new file mode 100644 (file)
index 0000000..41f648a
--- /dev/null
@@ -0,0 +1,64 @@
+=pod
+
+=head1 NAME
+
+MDC2, MDC2_Init, MDC2_Update, MDC2_Final - MDC2 hash function
+
+=head1 SYNOPSIS
+
+ #include <openssl/mdc2.h>
+
+ unsigned char *MDC2(const unsigned char *d, unsigned long n,
+                  unsigned char *md);
+
+ int MDC2_Init(MDC2_CTX *c);
+ int MDC2_Update(MDC2_CTX *c, const unsigned char *data,
+                  unsigned long len);
+ int MDC2_Final(unsigned char *md, MDC2_CTX *c);
+
+=head1 DESCRIPTION
+
+MDC2 is a method to construct hash functions with 128 bit output from
+block ciphers.  These functions are an implementation of MDC2 with
+DES.
+
+MDC2() computes the MDC2 message digest of the B<n>
+bytes at B<d> and places it in B<md> (which must have space for
+MDC2_DIGEST_LENGTH == 16 bytes of output). If B<md> is NULL, the digest
+is placed in a static array.
+
+The following functions may be used if the message is not completely
+stored in memory:
+
+MDC2_Init() initializes a B<MDC2_CTX> structure.
+
+MDC2_Update() can be called repeatedly with chunks of the message to
+be hashed (B<len> bytes at B<data>).
+
+MDC2_Final() places the message digest in B<md>, which must have space
+for MDC2_DIGEST_LENGTH == 16 bytes of output, and erases the B<MDC2_CTX>.
+
+Applications should use the higher level functions
+L<EVP_DigestInit(3)|EVP_DigestInit(3)> etc. instead of calling the
+hash functions directly.
+
+=head1 RETURN VALUES
+
+MDC2() returns a pointer to the hash value. 
+
+MDC2_Init(), MDC2_Update() and MDC2_Final() return 1 for success, 0 otherwise.
+
+=head1 CONFORMING TO
+
+ISO/IEC 10118-2, with DES
+
+=head1 SEE ALSO
+
+L<sha(3)|sha(3)>, L<EVP_DigestInit(3)|EVP_DigestInit(3)>
+
+=head1 HISTORY
+
+MDC2(), MDC2_Init(), MDC2_Update() and MDC2_Final() are available since
+SSLeay 0.8.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/pem.pod b/deps/openssl/openssl/doc/crypto/pem.pod
new file mode 100644 (file)
index 0000000..d5b1896
--- /dev/null
@@ -0,0 +1,476 @@
+=pod
+
+=head1 NAME
+
+PEM, PEM_read_bio_PrivateKey, PEM_read_PrivateKey, PEM_write_bio_PrivateKey, PEM_write_PrivateKey, PEM_write_bio_PKCS8PrivateKey, PEM_write_PKCS8PrivateKey, PEM_write_bio_PKCS8PrivateKey_nid, PEM_write_PKCS8PrivateKey_nid, PEM_read_bio_PUBKEY, PEM_read_PUBKEY, PEM_write_bio_PUBKEY, PEM_write_PUBKEY, PEM_read_bio_RSAPrivateKey, PEM_read_RSAPrivateKey, PEM_write_bio_RSAPrivateKey, PEM_write_RSAPrivateKey, PEM_read_bio_RSAPublicKey, PEM_read_RSAPublicKey, PEM_write_bio_RSAPublicKey, PEM_write_RSAPublicKey, PEM_read_bio_RSA_PUBKEY, PEM_read_RSA_PUBKEY, PEM_write_bio_RSA_PUBKEY, PEM_write_RSA_PUBKEY, PEM_read_bio_DSAPrivateKey, PEM_read_DSAPrivateKey, PEM_write_bio_DSAPrivateKey, PEM_write_DSAPrivateKey, PEM_read_bio_DSA_PUBKEY, PEM_read_DSA_PUBKEY, PEM_write_bio_DSA_PUBKEY, PEM_write_DSA_PUBKEY, PEM_read_bio_DSAparams, PEM_read_DSAparams, PEM_write_bio_DSAparams, PEM_write_DSAparams, PEM_read_bio_DHparams, PEM_read_DHparams, PEM_write_bio_DHparams, PEM_write_DHparams, PEM_read_bio_X509, PEM_read_X509, PEM_write_bio_X509, PEM_write_X509, PEM_read_bio_X509_AUX, PEM_read_X509_AUX, PEM_write_bio_X509_AUX, PEM_write_X509_AUX, PEM_read_bio_X509_REQ, PEM_read_X509_REQ, PEM_write_bio_X509_REQ, PEM_write_X509_REQ, PEM_write_bio_X509_REQ_NEW, PEM_write_X509_REQ_NEW, PEM_read_bio_X509_CRL, PEM_read_X509_CRL, PEM_write_bio_X509_CRL, PEM_write_X509_CRL, PEM_read_bio_PKCS7, PEM_read_PKCS7, PEM_write_bio_PKCS7, PEM_write_PKCS7, PEM_read_bio_NETSCAPE_CERT_SEQUENCE, PEM_read_NETSCAPE_CERT_SEQUENCE, PEM_write_bio_NETSCAPE_CERT_SEQUENCE, PEM_write_NETSCAPE_CERT_SEQUENCE - PEM routines
+
+=head1 SYNOPSIS
+
+ #include <openssl/pem.h>
+
+ EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x,
+                                       pem_password_cb *cb, void *u);
+
+ EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x,
+                                       pem_password_cb *cb, void *u);
+
+ int PEM_write_bio_PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
+                                       unsigned char *kstr, int klen,
+                                       pem_password_cb *cb, void *u);
+
+ int PEM_write_PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
+                                       unsigned char *kstr, int klen,
+                                       pem_password_cb *cb, void *u);
+
+ int PEM_write_bio_PKCS8PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
+                                       char *kstr, int klen,
+                                       pem_password_cb *cb, void *u);
+
+ int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
+                                       char *kstr, int klen,
+                                       pem_password_cb *cb, void *u);
+
+ int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
+                                       char *kstr, int klen,
+                                       pem_password_cb *cb, void *u);
+
+ int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
+                                       char *kstr, int klen,
+                                       pem_password_cb *cb, void *u);
+
+ EVP_PKEY *PEM_read_bio_PUBKEY(BIO *bp, EVP_PKEY **x,
+                                       pem_password_cb *cb, void *u);
+
+ EVP_PKEY *PEM_read_PUBKEY(FILE *fp, EVP_PKEY **x,
+                                       pem_password_cb *cb, void *u);
+
+ int PEM_write_bio_PUBKEY(BIO *bp, EVP_PKEY *x);
+ int PEM_write_PUBKEY(FILE *fp, EVP_PKEY *x);
+
+ RSA *PEM_read_bio_RSAPrivateKey(BIO *bp, RSA **x,
+                                       pem_password_cb *cb, void *u);
+
+ RSA *PEM_read_RSAPrivateKey(FILE *fp, RSA **x,
+                                       pem_password_cb *cb, void *u);
+
+ int PEM_write_bio_RSAPrivateKey(BIO *bp, RSA *x, const EVP_CIPHER *enc,
+                                       unsigned char *kstr, int klen,
+                                       pem_password_cb *cb, void *u);
+
+ int PEM_write_RSAPrivateKey(FILE *fp, RSA *x, const EVP_CIPHER *enc,
+                                       unsigned char *kstr, int klen,
+                                       pem_password_cb *cb, void *u);
+
+ RSA *PEM_read_bio_RSAPublicKey(BIO *bp, RSA **x,
+                                       pem_password_cb *cb, void *u);
+
+ RSA *PEM_read_RSAPublicKey(FILE *fp, RSA **x,
+                                       pem_password_cb *cb, void *u);
+
+ int PEM_write_bio_RSAPublicKey(BIO *bp, RSA *x);
+
+ int PEM_write_RSAPublicKey(FILE *fp, RSA *x);
+
+ RSA *PEM_read_bio_RSA_PUBKEY(BIO *bp, RSA **x,
+                                       pem_password_cb *cb, void *u);
+
+ RSA *PEM_read_RSA_PUBKEY(FILE *fp, RSA **x,
+                                       pem_password_cb *cb, void *u);
+
+ int PEM_write_bio_RSA_PUBKEY(BIO *bp, RSA *x);
+
+ int PEM_write_RSA_PUBKEY(FILE *fp, RSA *x);
+
+ DSA *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **x,
+                                       pem_password_cb *cb, void *u);
+
+ DSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **x,
+                                       pem_password_cb *cb, void *u);
+
+ int PEM_write_bio_DSAPrivateKey(BIO *bp, DSA *x, const EVP_CIPHER *enc,
+                                       unsigned char *kstr, int klen,
+                                       pem_password_cb *cb, void *u);
+
+ int PEM_write_DSAPrivateKey(FILE *fp, DSA *x, const EVP_CIPHER *enc,
+                                       unsigned char *kstr, int klen,
+                                       pem_password_cb *cb, void *u);
+
+ DSA *PEM_read_bio_DSA_PUBKEY(BIO *bp, DSA **x,
+                                       pem_password_cb *cb, void *u);
+
+ DSA *PEM_read_DSA_PUBKEY(FILE *fp, DSA **x,
+                                       pem_password_cb *cb, void *u);
+
+ int PEM_write_bio_DSA_PUBKEY(BIO *bp, DSA *x);
+
+ int PEM_write_DSA_PUBKEY(FILE *fp, DSA *x);
+
+ DSA *PEM_read_bio_DSAparams(BIO *bp, DSA **x, pem_password_cb *cb, void *u);
+
+ DSA *PEM_read_DSAparams(FILE *fp, DSA **x, pem_password_cb *cb, void *u);
+
+ int PEM_write_bio_DSAparams(BIO *bp, DSA *x);
+
+ int PEM_write_DSAparams(FILE *fp, DSA *x);
+
+ DH *PEM_read_bio_DHparams(BIO *bp, DH **x, pem_password_cb *cb, void *u);
+
+ DH *PEM_read_DHparams(FILE *fp, DH **x, pem_password_cb *cb, void *u);
+
+ int PEM_write_bio_DHparams(BIO *bp, DH *x);
+
+ int PEM_write_DHparams(FILE *fp, DH *x);
+
+ X509 *PEM_read_bio_X509(BIO *bp, X509 **x, pem_password_cb *cb, void *u);
+
+ X509 *PEM_read_X509(FILE *fp, X509 **x, pem_password_cb *cb, void *u);
+
+ int PEM_write_bio_X509(BIO *bp, X509 *x);
+
+ int PEM_write_X509(FILE *fp, X509 *x);
+
+ X509 *PEM_read_bio_X509_AUX(BIO *bp, X509 **x, pem_password_cb *cb, void *u);
+
+ X509 *PEM_read_X509_AUX(FILE *fp, X509 **x, pem_password_cb *cb, void *u);
+
+ int PEM_write_bio_X509_AUX(BIO *bp, X509 *x);
+
+ int PEM_write_X509_AUX(FILE *fp, X509 *x);
+
+ X509_REQ *PEM_read_bio_X509_REQ(BIO *bp, X509_REQ **x,
+                                       pem_password_cb *cb, void *u);
+
+ X509_REQ *PEM_read_X509_REQ(FILE *fp, X509_REQ **x,
+                                       pem_password_cb *cb, void *u);
+
+ int PEM_write_bio_X509_REQ(BIO *bp, X509_REQ *x);
+
+ int PEM_write_X509_REQ(FILE *fp, X509_REQ *x);
+
+ int PEM_write_bio_X509_REQ_NEW(BIO *bp, X509_REQ *x);
+
+ int PEM_write_X509_REQ_NEW(FILE *fp, X509_REQ *x);
+
+ X509_CRL *PEM_read_bio_X509_CRL(BIO *bp, X509_CRL **x,
+                                       pem_password_cb *cb, void *u);
+ X509_CRL *PEM_read_X509_CRL(FILE *fp, X509_CRL **x,
+                                       pem_password_cb *cb, void *u);
+ int PEM_write_bio_X509_CRL(BIO *bp, X509_CRL *x);
+ int PEM_write_X509_CRL(FILE *fp, X509_CRL *x);
+
+ PKCS7 *PEM_read_bio_PKCS7(BIO *bp, PKCS7 **x, pem_password_cb *cb, void *u);
+
+ PKCS7 *PEM_read_PKCS7(FILE *fp, PKCS7 **x, pem_password_cb *cb, void *u);
+
+ int PEM_write_bio_PKCS7(BIO *bp, PKCS7 *x);
+
+ int PEM_write_PKCS7(FILE *fp, PKCS7 *x);
+
+ NETSCAPE_CERT_SEQUENCE *PEM_read_bio_NETSCAPE_CERT_SEQUENCE(BIO *bp,
+                                               NETSCAPE_CERT_SEQUENCE **x,
+                                               pem_password_cb *cb, void *u);
+
+ NETSCAPE_CERT_SEQUENCE *PEM_read_NETSCAPE_CERT_SEQUENCE(FILE *fp,
+                                               NETSCAPE_CERT_SEQUENCE **x,
+                                               pem_password_cb *cb, void *u);
+
+ int PEM_write_bio_NETSCAPE_CERT_SEQUENCE(BIO *bp, NETSCAPE_CERT_SEQUENCE *x);
+
+ int PEM_write_NETSCAPE_CERT_SEQUENCE(FILE *fp, NETSCAPE_CERT_SEQUENCE *x);
+
+=head1 DESCRIPTION
+
+The PEM functions read or write structures in PEM format. In
+this sense PEM format is simply base64 encoded data surrounded
+by header lines.
+
+For more details about the meaning of arguments see the
+B<PEM FUNCTION ARGUMENTS> section.
+
+Each operation has four functions associated with it. For
+clarity the term "B<foobar> functions" will be used to collectively
+refer to the PEM_read_bio_foobar(), PEM_read_foobar(),
+PEM_write_bio_foobar() and PEM_write_foobar() functions.
+
+The B<PrivateKey> functions read or write a private key in
+PEM format using an EVP_PKEY structure. The write routines use
+"traditional" private key format and can handle both RSA and DSA
+private keys. The read functions can additionally transparently
+handle PKCS#8 format encrypted and unencrypted keys too.
+
+PEM_write_bio_PKCS8PrivateKey() and PEM_write_PKCS8PrivateKey()
+write a private key in an EVP_PKEY structure in PKCS#8
+EncryptedPrivateKeyInfo format using PKCS#5 v2.0 password based encryption
+algorithms. The B<cipher> argument specifies the encryption algoritm to
+use: unlike all other PEM routines the encryption is applied at the
+PKCS#8 level and not in the PEM headers. If B<cipher> is NULL then no
+encryption is used and a PKCS#8 PrivateKeyInfo structure is used instead.
+
+PEM_write_bio_PKCS8PrivateKey_nid() and PEM_write_PKCS8PrivateKey_nid()
+also write out a private key as a PKCS#8 EncryptedPrivateKeyInfo however
+it uses PKCS#5 v1.5 or PKCS#12 encryption algorithms instead. The algorithm
+to use is specified in the B<nid> parameter and should be the NID of the
+corresponding OBJECT IDENTIFIER (see NOTES section).
+
+The B<PUBKEY> functions process a public key using an EVP_PKEY
+structure. The public key is encoded as a SubjectPublicKeyInfo
+structure.
+
+The B<RSAPrivateKey> functions process an RSA private key using an
+RSA structure. It handles the same formats as the B<PrivateKey>
+functions but an error occurs if the private key is not RSA.
+
+The B<RSAPublicKey> functions process an RSA public key using an
+RSA structure. The public key is encoded using a PKCS#1 RSAPublicKey
+structure.
+
+The B<RSA_PUBKEY> functions also process an RSA public key using
+an RSA structure. However the public key is encoded using a
+SubjectPublicKeyInfo structure and an error occurs if the public
+key is not RSA.
+
+The B<DSAPrivateKey> functions process a DSA private key using a
+DSA structure. It handles the same formats as the B<PrivateKey>
+functions but an error occurs if the private key is not DSA.
+
+The B<DSA_PUBKEY> functions process a DSA public key using
+a DSA structure. The public key is encoded using a
+SubjectPublicKeyInfo structure and an error occurs if the public
+key is not DSA.
+
+The B<DSAparams> functions process DSA parameters using a DSA
+structure. The parameters are encoded using a foobar structure.
+
+The B<DHparams> functions process DH parameters using a DH
+structure. The parameters are encoded using a PKCS#3 DHparameter
+structure.
+
+The B<X509> functions process an X509 certificate using an X509
+structure. They will also process a trusted X509 certificate but
+any trust settings are discarded.
+
+The B<X509_AUX> functions process a trusted X509 certificate using
+an X509 structure. 
+
+The B<X509_REQ> and B<X509_REQ_NEW> functions process a PKCS#10
+certificate request using an X509_REQ structure. The B<X509_REQ>
+write functions use B<CERTIFICATE REQUEST> in the header whereas
+the B<X509_REQ_NEW> functions use B<NEW CERTIFICATE REQUEST>
+(as required by some CAs). The B<X509_REQ> read functions will
+handle either form so there are no B<X509_REQ_NEW> read functions.
+
+The B<X509_CRL> functions process an X509 CRL using an X509_CRL
+structure.
+
+The B<PKCS7> functions process a PKCS#7 ContentInfo using a PKCS7
+structure.
+
+The B<NETSCAPE_CERT_SEQUENCE> functions process a Netscape Certificate
+Sequence using a NETSCAPE_CERT_SEQUENCE structure.
+
+=head1 PEM FUNCTION ARGUMENTS
+
+The PEM functions have many common arguments.
+
+The B<bp> BIO parameter (if present) specifies the BIO to read from
+or write to.
+
+The B<fp> FILE parameter (if present) specifies the FILE pointer to
+read from or write to.
+
+The PEM read functions all take an argument B<TYPE **x> and return
+a B<TYPE *> pointer. Where B<TYPE> is whatever structure the function
+uses. If B<x> is NULL then the parameter is ignored. If B<x> is not
+NULL but B<*x> is NULL then the structure returned will be written
+to B<*x>. If neither B<x> nor B<*x> is NULL then an attempt is made
+to reuse the structure at B<*x> (but see BUGS and EXAMPLES sections).
+Irrespective of the value of B<x> a pointer to the structure is always
+returned (or NULL if an error occurred).
+
+The PEM functions which write private keys take an B<enc> parameter
+which specifies the encryption algorithm to use, encryption is done
+at the PEM level. If this parameter is set to NULL then the private
+key is written in unencrypted form.
+
+The B<cb> argument is the callback to use when querying for the pass
+phrase used for encrypted PEM structures (normally only private keys).
+
+For the PEM write routines if the B<kstr> parameter is not NULL then
+B<klen> bytes at B<kstr> are used as the passphrase and B<cb> is
+ignored.
+
+If the B<cb> parameters is set to NULL and the B<u> parameter is not
+NULL then the B<u> parameter is interpreted as a null terminated string
+to use as the passphrase. If both B<cb> and B<u> are NULL then the
+default callback routine is used which will typically prompt for the
+passphrase on the current terminal with echoing turned off.
+
+The default passphrase callback is sometimes inappropriate (for example
+in a GUI application) so an alternative can be supplied. The callback
+routine has the following form:
+
+ int cb(char *buf, int size, int rwflag, void *u);
+
+B<buf> is the buffer to write the passphrase to. B<size> is the maximum
+length of the passphrase (i.e. the size of buf). B<rwflag> is a flag
+which is set to 0 when reading and 1 when writing. A typical routine
+will ask the user to verify the passphrase (for example by prompting
+for it twice) if B<rwflag> is 1. The B<u> parameter has the same
+value as the B<u> parameter passed to the PEM routine. It allows
+arbitrary data to be passed to the callback by the application
+(for example a window handle in a GUI application). The callback
+B<must> return the number of characters in the passphrase or 0 if
+an error occurred.
+
+=head1 EXAMPLES
+
+Although the PEM routines take several arguments in almost all applications
+most of them are set to 0 or NULL.
+
+Read a certificate in PEM format from a BIO:
+
+ X509 *x;
+ x = PEM_read_bio_X509(bp, NULL, 0, NULL);
+ if (x == NULL)
+       {
+       /* Error */
+       }
+
+Alternative method:
+
+ X509 *x = NULL;
+ if (!PEM_read_bio_X509(bp, &x, 0, NULL))
+       {
+       /* Error */
+       }
+
+Write a certificate to a BIO:
+
+ if (!PEM_write_bio_X509(bp, x))
+       {
+       /* Error */
+       }
+
+Write an unencrypted private key to a FILE pointer:
+
+ if (!PEM_write_PrivateKey(fp, key, NULL, NULL, 0, 0, NULL))
+       {
+       /* Error */
+       }
+
+Write a private key (using traditional format) to a BIO using
+triple DES encryption, the pass phrase is prompted for:
+
+ if (!PEM_write_bio_PrivateKey(bp, key, EVP_des_ede3_cbc(), NULL, 0, 0, NULL))
+       {
+       /* Error */
+       }
+
+Write a private key (using PKCS#8 format) to a BIO using triple
+DES encryption, using the pass phrase "hello":
+
+ if (!PEM_write_bio_PKCS8PrivateKey(bp, key, EVP_des_ede3_cbc(), NULL, 0, 0, "hello"))
+       {
+       /* Error */
+       }
+
+Read a private key from a BIO using the pass phrase "hello":
+
+ key = PEM_read_bio_PrivateKey(bp, NULL, 0, "hello");
+ if (key == NULL)
+       {
+       /* Error */
+       }
+
+Read a private key from a BIO using a pass phrase callback:
+
+ key = PEM_read_bio_PrivateKey(bp, NULL, pass_cb, "My Private Key");
+ if (key == NULL)
+       {
+       /* Error */
+       }
+
+Skeleton pass phrase callback:
+
+ int pass_cb(char *buf, int size, int rwflag, void *u);
+       {
+       int len;
+       char *tmp;
+       /* We'd probably do something else if 'rwflag' is 1 */
+       printf("Enter pass phrase for \"%s\"\n", u);
+
+       /* get pass phrase, length 'len' into 'tmp' */
+       tmp = "hello";
+       len = strlen(tmp);
+
+       if (len <= 0) return 0;
+       /* if too long, truncate */
+       if (len > size) len = size;
+       memcpy(buf, tmp, len);
+       return len;
+       }
+
+=head1 NOTES
+
+The old B<PrivateKey> write routines are retained for compatibility.
+New applications should write private keys using the
+PEM_write_bio_PKCS8PrivateKey() or PEM_write_PKCS8PrivateKey() routines
+because they are more secure (they use an iteration count of 2048 whereas
+the traditional routines use a count of 1) unless compatibility with older
+versions of OpenSSL is important.
+
+The B<PrivateKey> read routines can be used in all applications because
+they handle all formats transparently.
+
+A frequent cause of problems is attempting to use the PEM routines like
+this:
+
+ X509 *x;
+ PEM_read_bio_X509(bp, &x, 0, NULL);
+
+this is a bug because an attempt will be made to reuse the data at B<x>
+which is an uninitialised pointer.
+
+=head1 PEM ENCRYPTION FORMAT
+
+This old B<PrivateKey> routines use a non standard technique for encryption.
+
+The private key (or other data) takes the following form: 
+
+ -----BEGIN RSA PRIVATE KEY-----
+ Proc-Type: 4,ENCRYPTED
+ DEK-Info: DES-EDE3-CBC,3F17F5316E2BAC89
+
+ ...base64 encoded data...
+ -----END RSA PRIVATE KEY-----
+
+The line beginning DEK-Info contains two comma separated pieces of information:
+the encryption algorithm name as used by EVP_get_cipherbyname() and an 8
+byte B<salt> encoded as a set of hexadecimal digits.
+
+After this is the base64 encoded encrypted data.
+
+The encryption key is determined using EVP_bytestokey(), using B<salt> and an
+iteration count of 1. The IV used is the value of B<salt> and *not* the IV
+returned by EVP_bytestokey().
+
+=head1 BUGS
+
+The PEM read routines in some versions of OpenSSL will not correctly reuse
+an existing structure. Therefore the following:
+
+ PEM_read_bio_X509(bp, &x, 0, NULL);
+
+where B<x> already contains a valid certificate, may not work, whereas: 
+
+ X509_free(x);
+ x = PEM_read_bio_X509(bp, NULL, 0, NULL);
+
+is guaranteed to work.
+
+=head1 RETURN CODES
+
+The read routines return either a pointer to the structure read or NULL
+if an error occurred.
+
+The write routines return 1 for success or 0 for failure.
diff --git a/deps/openssl/openssl/doc/crypto/rand.pod b/deps/openssl/openssl/doc/crypto/rand.pod
new file mode 100644 (file)
index 0000000..1c068c8
--- /dev/null
@@ -0,0 +1,175 @@
+=pod
+
+=head1 NAME
+
+rand - pseudo-random number generator
+
+=head1 SYNOPSIS
+
+ #include <openssl/rand.h>
+
+ int  RAND_set_rand_engine(ENGINE *engine);
+
+ int  RAND_bytes(unsigned char *buf, int num);
+ int  RAND_pseudo_bytes(unsigned char *buf, int num);
+
+ void RAND_seed(const void *buf, int num);
+ void RAND_add(const void *buf, int num, int entropy);
+ int  RAND_status(void);
+
+ int  RAND_load_file(const char *file, long max_bytes);
+ int  RAND_write_file(const char *file);
+ const char *RAND_file_name(char *file, size_t num);
+
+ int  RAND_egd(const char *path);
+
+ void RAND_set_rand_method(const RAND_METHOD *meth);
+ const RAND_METHOD *RAND_get_rand_method(void);
+ RAND_METHOD *RAND_SSLeay(void);
+
+ void RAND_cleanup(void);
+
+ /* For Win32 only */
+ void RAND_screen(void);
+ int RAND_event(UINT, WPARAM, LPARAM);
+
+=head1 DESCRIPTION
+
+Since the introduction of the ENGINE API, the recommended way of controlling
+default implementations is by using the ENGINE API functions. The default
+B<RAND_METHOD>, as set by RAND_set_rand_method() and returned by
+RAND_get_rand_method(), is only used if no ENGINE has been set as the default
+"rand" implementation. Hence, these two functions are no longer the recommened
+way to control defaults.
+
+If an alternative B<RAND_METHOD> implementation is being used (either set
+directly or as provided by an ENGINE module), then it is entirely responsible
+for the generation and management of a cryptographically secure PRNG stream. The
+mechanisms described below relate solely to the software PRNG implementation
+built in to OpenSSL and used by default.
+
+These functions implement a cryptographically secure pseudo-random
+number generator (PRNG). It is used by other library functions for
+example to generate random keys, and applications can use it when they
+need randomness.
+
+A cryptographic PRNG must be seeded with unpredictable data such as
+mouse movements or keys pressed at random by the user. This is
+described in L<RAND_add(3)|RAND_add(3)>. Its state can be saved in a seed file
+(see L<RAND_load_file(3)|RAND_load_file(3)>) to avoid having to go through the
+seeding process whenever the application is started.
+
+L<RAND_bytes(3)|RAND_bytes(3)> describes how to obtain random data from the
+PRNG. 
+
+=head1 INTERNALS
+
+The RAND_SSLeay() method implements a PRNG based on a cryptographic
+hash function.
+
+The following description of its design is based on the SSLeay
+documentation:
+
+First up I will state the things I believe I need for a good RNG.
+
+=over 4
+
+=item 1
+
+A good hashing algorithm to mix things up and to convert the RNG 'state'
+to random numbers.
+
+=item 2
+
+An initial source of random 'state'.
+
+=item 3
+
+The state should be very large.  If the RNG is being used to generate
+4096 bit RSA keys, 2 2048 bit random strings are required (at a minimum).
+If your RNG state only has 128 bits, you are obviously limiting the
+search space to 128 bits, not 2048.  I'm probably getting a little
+carried away on this last point but it does indicate that it may not be
+a bad idea to keep quite a lot of RNG state.  It should be easier to
+break a cipher than guess the RNG seed data.
+
+=item 4
+
+Any RNG seed data should influence all subsequent random numbers
+generated.  This implies that any random seed data entered will have
+an influence on all subsequent random numbers generated.
+
+=item 5
+
+When using data to seed the RNG state, the data used should not be
+extractable from the RNG state.  I believe this should be a
+requirement because one possible source of 'secret' semi random
+data would be a private key or a password.  This data must
+not be disclosed by either subsequent random numbers or a
+'core' dump left by a program crash.
+
+=item 6
+
+Given the same initial 'state', 2 systems should deviate in their RNG state
+(and hence the random numbers generated) over time if at all possible.
+
+=item 7
+
+Given the random number output stream, it should not be possible to determine
+the RNG state or the next random number.
+
+=back
+
+The algorithm is as follows.
+
+There is global state made up of a 1023 byte buffer (the 'state'), a
+working hash value ('md'), and a counter ('count').
+
+Whenever seed data is added, it is inserted into the 'state' as
+follows.
+
+The input is chopped up into units of 20 bytes (or less for
+the last block).  Each of these blocks is run through the hash
+function as follows:  The data passed to the hash function
+is the current 'md', the same number of bytes from the 'state'
+(the location determined by in incremented looping index) as
+the current 'block', the new key data 'block', and 'count'
+(which is incremented after each use).
+The result of this is kept in 'md' and also xored into the
+'state' at the same locations that were used as input into the
+hash function. I
+believe this system addresses points 1 (hash function; currently
+SHA-1), 3 (the 'state'), 4 (via the 'md'), 5 (by the use of a hash
+function and xor).
+
+When bytes are extracted from the RNG, the following process is used.
+For each group of 10 bytes (or less), we do the following:
+
+Input into the hash function the local 'md' (which is initialized from
+the global 'md' before any bytes are generated), the bytes that are to
+be overwritten by the random bytes, and bytes from the 'state'
+(incrementing looping index). From this digest output (which is kept
+in 'md'), the top (up to) 10 bytes are returned to the caller and the
+bottom 10 bytes are xored into the 'state'.
+
+Finally, after we have finished 'num' random bytes for the caller,
+'count' (which is incremented) and the local and global 'md' are fed
+into the hash function and the results are kept in the global 'md'.
+
+I believe the above addressed points 1 (use of SHA-1), 6 (by hashing
+into the 'state' the 'old' data from the caller that is about to be
+overwritten) and 7 (by not using the 10 bytes given to the caller to
+update the 'state', but they are used to update 'md').
+
+So of the points raised, only 2 is not addressed (but see
+L<RAND_add(3)|RAND_add(3)>).
+
+=head1 SEE ALSO
+
+L<BN_rand(3)|BN_rand(3)>, L<RAND_add(3)|RAND_add(3)>,
+L<RAND_load_file(3)|RAND_load_file(3)>, L<RAND_egd(3)|RAND_egd(3)>,
+L<RAND_bytes(3)|RAND_bytes(3)>,
+L<RAND_set_rand_method(3)|RAND_set_rand_method(3)>,
+L<RAND_cleanup(3)|RAND_cleanup(3)> 
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/rc4.pod b/deps/openssl/openssl/doc/crypto/rc4.pod
new file mode 100644 (file)
index 0000000..b6d3a43
--- /dev/null
@@ -0,0 +1,62 @@
+=pod
+
+=head1 NAME
+
+RC4_set_key, RC4 - RC4 encryption
+
+=head1 SYNOPSIS
+
+ #include <openssl/rc4.h>
+
+ void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data);
+
+ void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
+          unsigned char *outdata);
+
+=head1 DESCRIPTION
+
+This library implements the Alleged RC4 cipher, which is described for
+example in I<Applied Cryptography>.  It is believed to be compatible
+with RC4[TM], a proprietary cipher of RSA Security Inc.
+
+RC4 is a stream cipher with variable key length.  Typically, 128 bit
+(16 byte) keys are used for strong encryption, but shorter insecure
+key sizes have been widely used due to export restrictions.
+
+RC4 consists of a key setup phase and the actual encryption or
+decryption phase.
+
+RC4_set_key() sets up the B<RC4_KEY> B<key> using the B<len> bytes long
+key at B<data>.
+
+RC4() encrypts or decrypts the B<len> bytes of data at B<indata> using
+B<key> and places the result at B<outdata>.  Repeated RC4() calls with
+the same B<key> yield a continuous key stream.
+
+Since RC4 is a stream cipher (the input is XORed with a pseudo-random
+key stream to produce the output), decryption uses the same function
+calls as encryption.
+
+Applications should use the higher level functions
+L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>
+etc. instead of calling the RC4 functions directly.
+
+=head1 RETURN VALUES
+
+RC4_set_key() and RC4() do not return values.
+
+=head1 NOTE
+
+Certain conditions have to be observed to securely use stream ciphers.
+It is not permissible to perform multiple encryptions using the same
+key stream.
+
+=head1 SEE ALSO
+
+L<blowfish(3)|blowfish(3)>, L<des(3)|des(3)>, L<rc2(3)|rc2(3)>
+
+=head1 HISTORY
+
+RC4_set_key() and RC4() are available in all versions of SSLeay and OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/ripemd.pod b/deps/openssl/openssl/doc/crypto/ripemd.pod
new file mode 100644 (file)
index 0000000..264bb99
--- /dev/null
@@ -0,0 +1,66 @@
+=pod
+
+=head1 NAME
+
+RIPEMD160, RIPEMD160_Init, RIPEMD160_Update, RIPEMD160_Final -
+RIPEMD-160 hash function
+
+=head1 SYNOPSIS
+
+ #include <openssl/ripemd.h>
+
+ unsigned char *RIPEMD160(const unsigned char *d, unsigned long n,
+                  unsigned char *md);
+
+ int RIPEMD160_Init(RIPEMD160_CTX *c);
+ int RIPEMD160_Update(RIPEMD_CTX *c, const void *data,
+                  unsigned long len);
+ int RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c);
+
+=head1 DESCRIPTION
+
+RIPEMD-160 is a cryptographic hash function with a
+160 bit output.
+
+RIPEMD160() computes the RIPEMD-160 message digest of the B<n>
+bytes at B<d> and places it in B<md> (which must have space for
+RIPEMD160_DIGEST_LENGTH == 20 bytes of output). If B<md> is NULL, the digest
+is placed in a static array.
+
+The following functions may be used if the message is not completely
+stored in memory:
+
+RIPEMD160_Init() initializes a B<RIPEMD160_CTX> structure.
+
+RIPEMD160_Update() can be called repeatedly with chunks of the message to
+be hashed (B<len> bytes at B<data>).
+
+RIPEMD160_Final() places the message digest in B<md>, which must have
+space for RIPEMD160_DIGEST_LENGTH == 20 bytes of output, and erases
+the B<RIPEMD160_CTX>.
+
+Applications should use the higher level functions
+L<EVP_DigestInit(3)|EVP_DigestInit(3)> etc. instead of calling the
+hash functions directly.
+
+=head1 RETURN VALUES
+
+RIPEMD160() returns a pointer to the hash value. 
+
+RIPEMD160_Init(), RIPEMD160_Update() and RIPEMD160_Final() return 1 for
+success, 0 otherwise.
+
+=head1 CONFORMING TO
+
+ISO/IEC 10118-3 (draft) (??)
+
+=head1 SEE ALSO
+
+L<sha(3)|sha(3)>, L<hmac(3)|hmac(3)>, L<EVP_DigestInit(3)|EVP_DigestInit(3)>
+
+=head1 HISTORY
+
+RIPEMD160(), RIPEMD160_Init(), RIPEMD160_Update() and
+RIPEMD160_Final() are available since SSLeay 0.9.0.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/rsa.pod b/deps/openssl/openssl/doc/crypto/rsa.pod
new file mode 100644 (file)
index 0000000..45ac53f
--- /dev/null
@@ -0,0 +1,123 @@
+=pod
+
+=head1 NAME
+
+rsa - RSA public key cryptosystem
+
+=head1 SYNOPSIS
+
+ #include <openssl/rsa.h>
+ #include <openssl/engine.h>
+
+ RSA * RSA_new(void);
+ void RSA_free(RSA *rsa);
+
+ int RSA_public_encrypt(int flen, unsigned char *from,
+    unsigned char *to, RSA *rsa, int padding);
+ int RSA_private_decrypt(int flen, unsigned char *from,
+    unsigned char *to, RSA *rsa, int padding);
+ int RSA_private_encrypt(int flen, unsigned char *from,
+    unsigned char *to, RSA *rsa,int padding);
+ int RSA_public_decrypt(int flen, unsigned char *from, 
+    unsigned char *to, RSA *rsa,int padding);
+
+ int RSA_sign(int type, unsigned char *m, unsigned int m_len,
+    unsigned char *sigret, unsigned int *siglen, RSA *rsa);
+ int RSA_verify(int type, unsigned char *m, unsigned int m_len,
+    unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
+
+ int RSA_size(const RSA *rsa);
+
+ RSA *RSA_generate_key(int num, unsigned long e,
+    void (*callback)(int,int,void *), void *cb_arg);
+
+ int RSA_check_key(RSA *rsa);
+
+ int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
+ void RSA_blinding_off(RSA *rsa);
+
+ void RSA_set_default_method(const RSA_METHOD *meth);
+ const RSA_METHOD *RSA_get_default_method(void);
+ int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
+ const RSA_METHOD *RSA_get_method(const RSA *rsa);
+ RSA_METHOD *RSA_PKCS1_SSLeay(void);
+ RSA_METHOD *RSA_null_method(void);
+ int RSA_flags(const RSA *rsa);
+ RSA *RSA_new_method(ENGINE *engine);
+
+ int RSA_print(BIO *bp, RSA *x, int offset);
+ int RSA_print_fp(FILE *fp, RSA *x, int offset);
+
+ int RSA_get_ex_new_index(long argl, char *argp, int (*new_func)(),
+    int (*dup_func)(), void (*free_func)());
+ int RSA_set_ex_data(RSA *r,int idx,char *arg);
+ char *RSA_get_ex_data(RSA *r, int idx);
+
+ int RSA_sign_ASN1_OCTET_STRING(int dummy, unsigned char *m,
+    unsigned int m_len, unsigned char *sigret, unsigned int *siglen,
+    RSA *rsa);
+ int RSA_verify_ASN1_OCTET_STRING(int dummy, unsigned char *m,
+    unsigned int m_len, unsigned char *sigbuf, unsigned int siglen,
+    RSA *rsa);
+
+=head1 DESCRIPTION
+
+These functions implement RSA public key encryption and signatures
+as defined in PKCS #1 v2.0 [RFC 2437].
+
+The B<RSA> structure consists of several BIGNUM components. It can
+contain public as well as private RSA keys:
+
+ struct
+        {
+        BIGNUM *n;             // public modulus
+        BIGNUM *e;             // public exponent
+        BIGNUM *d;             // private exponent
+        BIGNUM *p;             // secret prime factor
+        BIGNUM *q;             // secret prime factor
+        BIGNUM *dmp1;          // d mod (p-1)
+        BIGNUM *dmq1;          // d mod (q-1)
+        BIGNUM *iqmp;          // q^-1 mod p
+       // ...
+        };
+ RSA
+
+In public keys, the private exponent and the related secret values are
+B<NULL>.
+
+B<p>, B<q>, B<dmp1>, B<dmq1> and B<iqmp> may be B<NULL> in private
+keys, but the RSA operations are much faster when these values are
+available.
+
+Note that RSA keys may use non-standard B<RSA_METHOD> implementations,
+either directly or by the use of B<ENGINE> modules. In some cases (eg. an
+ENGINE providing support for hardware-embedded keys), these BIGNUM values
+will not be used by the implementation or may be used for alternative data
+storage. For this reason, applications should generally avoid using RSA
+structure elements directly and instead use API functions to query or
+modify keys.
+
+=head1 CONFORMING TO
+
+SSL, PKCS #1 v2.0
+
+=head1 PATENTS
+
+RSA was covered by a US patent which expired in September 2000.
+
+=head1 SEE ALSO
+
+L<rsa(1)|rsa(1)>, L<bn(3)|bn(3)>, L<dsa(3)|dsa(3)>, L<dh(3)|dh(3)>,
+L<rand(3)|rand(3)>, L<engine(3)|engine(3)>, L<RSA_new(3)|RSA_new(3)>,
+L<RSA_public_encrypt(3)|RSA_public_encrypt(3)>,
+L<RSA_sign(3)|RSA_sign(3)>, L<RSA_size(3)|RSA_size(3)>,
+L<RSA_generate_key(3)|RSA_generate_key(3)>,
+L<RSA_check_key(3)|RSA_check_key(3)>,
+L<RSA_blinding_on(3)|RSA_blinding_on(3)>,
+L<RSA_set_method(3)|RSA_set_method(3)>, L<RSA_print(3)|RSA_print(3)>,
+L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>,
+L<RSA_private_encrypt(3)|RSA_private_encrypt(3)>,
+L<RSA_sign_ASN1_OCTET_STRING(3)|RSA_sign_ASN1_OCTET_STRING(3)>,
+L<RSA_padding_add_PKCS1_type_1(3)|RSA_padding_add_PKCS1_type_1(3)> 
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/sha.pod b/deps/openssl/openssl/doc/crypto/sha.pod
new file mode 100644 (file)
index 0000000..94ab7bc
--- /dev/null
@@ -0,0 +1,70 @@
+=pod
+
+=head1 NAME
+
+SHA1, SHA1_Init, SHA1_Update, SHA1_Final - Secure Hash Algorithm
+
+=head1 SYNOPSIS
+
+ #include <openssl/sha.h>
+
+ unsigned char *SHA1(const unsigned char *d, unsigned long n,
+                  unsigned char *md);
+
+ int SHA1_Init(SHA_CTX *c);
+ int SHA1_Update(SHA_CTX *c, const void *data,
+                  unsigned long len);
+ int SHA1_Final(unsigned char *md, SHA_CTX *c);
+
+=head1 DESCRIPTION
+
+SHA-1 (Secure Hash Algorithm) is a cryptographic hash function with a
+160 bit output.
+
+SHA1() computes the SHA-1 message digest of the B<n>
+bytes at B<d> and places it in B<md> (which must have space for
+SHA_DIGEST_LENGTH == 20 bytes of output). If B<md> is NULL, the digest
+is placed in a static array.
+
+The following functions may be used if the message is not completely
+stored in memory:
+
+SHA1_Init() initializes a B<SHA_CTX> structure.
+
+SHA1_Update() can be called repeatedly with chunks of the message to
+be hashed (B<len> bytes at B<data>).
+
+SHA1_Final() places the message digest in B<md>, which must have space
+for SHA_DIGEST_LENGTH == 20 bytes of output, and erases the B<SHA_CTX>.
+
+Applications should use the higher level functions
+L<EVP_DigestInit(3)|EVP_DigestInit(3)>
+etc. instead of calling the hash functions directly.
+
+The predecessor of SHA-1, SHA, is also implemented, but it should be
+used only when backward compatibility is required.
+
+=head1 RETURN VALUES
+
+SHA1() returns a pointer to the hash value. 
+
+SHA1_Init(), SHA1_Update() and SHA1_Final() return 1 for success, 0 otherwise.
+
+=head1 CONFORMING TO
+
+SHA: US Federal Information Processing Standard FIPS PUB 180 (Secure Hash
+Standard),
+SHA-1: US Federal Information Processing Standard FIPS PUB 180-1 (Secure Hash
+Standard),
+ANSI X9.30
+
+=head1 SEE ALSO
+
+L<ripemd(3)|ripemd(3)>, L<hmac(3)|hmac(3)>, L<EVP_DigestInit(3)|EVP_DigestInit(3)>
+
+=head1 HISTORY
+
+SHA1(), SHA1_Init(), SHA1_Update() and SHA1_Final() are available in all
+versions of SSLeay and OpenSSL.
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/threads.pod b/deps/openssl/openssl/doc/crypto/threads.pod
new file mode 100644 (file)
index 0000000..dc0e939
--- /dev/null
@@ -0,0 +1,210 @@
+=pod
+
+=head1 NAME
+
+CRYPTO_THREADID_set_callback, CRYPTO_THREADID_get_callback,
+CRYPTO_THREADID_current, CRYPTO_THREADID_cmp, CRYPTO_THREADID_cpy,
+CRYPTO_THREADID_hash, CRYPTO_set_locking_callback, CRYPTO_num_locks,
+CRYPTO_set_dynlock_create_callback, CRYPTO_set_dynlock_lock_callback,
+CRYPTO_set_dynlock_destroy_callback, CRYPTO_get_new_dynlockid,
+CRYPTO_destroy_dynlockid, CRYPTO_lock - OpenSSL thread support
+
+=head1 SYNOPSIS
+
+ #include <openssl/crypto.h>
+
+ /* Don't use this structure directly. */
+ typedef struct crypto_threadid_st
+         {
+         void *ptr;
+         unsigned long val;
+         } CRYPTO_THREADID;
+ /* Only use CRYPTO_THREADID_set_[numeric|pointer]() within callbacks */
+ void CRYPTO_THREADID_set_numeric(CRYPTO_THREADID *id, unsigned long val);
+ void CRYPTO_THREADID_set_pointer(CRYPTO_THREADID *id, void *ptr);
+ int CRYPTO_THREADID_set_callback(void (*threadid_func)(CRYPTO_THREADID *));
+ void (*CRYPTO_THREADID_get_callback(void))(CRYPTO_THREADID *);
+ void CRYPTO_THREADID_current(CRYPTO_THREADID *id);
+ int CRYPTO_THREADID_cmp(const CRYPTO_THREADID *a,
+                         const CRYPTO_THREADID *b);
+ void CRYPTO_THREADID_cpy(CRYPTO_THREADID *dest,
+                          const CRYPTO_THREADID *src);
+ unsigned long CRYPTO_THREADID_hash(const CRYPTO_THREADID *id);
+
+ int CRYPTO_num_locks(void);
+
+ /* struct CRYPTO_dynlock_value needs to be defined by the user */
+ struct CRYPTO_dynlock_value;
+
+ void CRYPTO_set_dynlock_create_callback(struct CRYPTO_dynlock_value *
+       (*dyn_create_function)(char *file, int line));
+ void CRYPTO_set_dynlock_lock_callback(void (*dyn_lock_function)
+       (int mode, struct CRYPTO_dynlock_value *l,
+       const char *file, int line));
+ void CRYPTO_set_dynlock_destroy_callback(void (*dyn_destroy_function)
+       (struct CRYPTO_dynlock_value *l, const char *file, int line));
+
+ int CRYPTO_get_new_dynlockid(void);
+
+ void CRYPTO_destroy_dynlockid(int i);
+
+ void CRYPTO_lock(int mode, int n, const char *file, int line);
+
+ #define CRYPTO_w_lock(type)   \
+       CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,__FILE__,__LINE__)
+ #define CRYPTO_w_unlock(type) \
+       CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,__FILE__,__LINE__)
+ #define CRYPTO_r_lock(type)   \
+       CRYPTO_lock(CRYPTO_LOCK|CRYPTO_READ,type,__FILE__,__LINE__)
+ #define CRYPTO_r_unlock(type) \
+       CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_READ,type,__FILE__,__LINE__)
+ #define CRYPTO_add(addr,amount,type)  \
+       CRYPTO_add_lock(addr,amount,type,__FILE__,__LINE__)
+
+=head1 DESCRIPTION
+
+OpenSSL can safely be used in multi-threaded applications provided
+that at least two callback functions are set, locking_function and
+threadid_func.
+
+locking_function(int mode, int n, const char *file, int line) is
+needed to perform locking on shared data structures. 
+(Note that OpenSSL uses a number of global data structures that
+will be implicitly shared whenever multiple threads use OpenSSL.)
+Multi-threaded applications will crash at random if it is not set.
+
+locking_function() must be able to handle up to CRYPTO_num_locks()
+different mutex locks. It sets the B<n>-th lock if B<mode> &
+B<CRYPTO_LOCK>, and releases it otherwise.
+
+B<file> and B<line> are the file number of the function setting the
+lock. They can be useful for debugging.
+
+threadid_func(CRYPTO_THREADID *id) is needed to record the currently-executing
+thread's identifier into B<id>. The implementation of this callback should not
+fill in B<id> directly, but should use CRYPTO_THREADID_set_numeric() if thread
+IDs are numeric, or CRYPTO_THREADID_set_pointer() if they are pointer-based.
+If the application does not register such a callback using
+CRYPTO_THREADID_set_callback(), then a default implementation is used - on
+Windows and BeOS this uses the system's default thread identifying APIs, and on
+all other platforms it uses the address of B<errno>. The latter is satisfactory
+for thread-safety if and only if the platform has a thread-local error number
+facility.
+
+Once threadid_func() is registered, or if the built-in default implementation is
+to be used;
+
+=over 4
+
+=item *
+CRYPTO_THREADID_current() records the currently-executing thread ID into the
+given B<id> object.
+
+=item *
+CRYPTO_THREADID_cmp() compares two thread IDs (returning zero for equality, ie.
+the same semantics as memcmp()).
+
+=item *
+CRYPTO_THREADID_cpy() duplicates a thread ID value,
+
+=item *
+CRYPTO_THREADID_hash() returns a numeric value usable as a hash-table key. This
+is usually the exact numeric or pointer-based thread ID used internally, however
+this also handles the unusual case where pointers are larger than 'long'
+variables and the platform's thread IDs are pointer-based - in this case, mixing
+is done to attempt to produce a unique numeric value even though it is not as
+wide as the platform's true thread IDs.
+
+=back
+
+Additionally, OpenSSL supports dynamic locks, and sometimes, some parts
+of OpenSSL need it for better performance.  To enable this, the following
+is required:
+
+=over 4
+
+=item *
+Three additional callback function, dyn_create_function, dyn_lock_function
+and dyn_destroy_function.
+
+=item *
+A structure defined with the data that each lock needs to handle.
+
+=back
+
+struct CRYPTO_dynlock_value has to be defined to contain whatever structure
+is needed to handle locks.
+
+dyn_create_function(const char *file, int line) is needed to create a
+lock.  Multi-threaded applications might crash at random if it is not set.
+
+dyn_lock_function(int mode, CRYPTO_dynlock *l, const char *file, int line)
+is needed to perform locking off dynamic lock numbered n. Multi-threaded
+applications might crash at random if it is not set.
+
+dyn_destroy_function(CRYPTO_dynlock *l, const char *file, int line) is
+needed to destroy the lock l. Multi-threaded applications might crash at
+random if it is not set.
+
+CRYPTO_get_new_dynlockid() is used to create locks.  It will call
+dyn_create_function for the actual creation.
+
+CRYPTO_destroy_dynlockid() is used to destroy locks.  It will call
+dyn_destroy_function for the actual destruction.
+
+CRYPTO_lock() is used to lock and unlock the locks.  mode is a bitfield
+describing what should be done with the lock.  n is the number of the
+lock as returned from CRYPTO_get_new_dynlockid().  mode can be combined
+from the following values.  These values are pairwise exclusive, with
+undefined behaviour if misused (for example, CRYPTO_READ and CRYPTO_WRITE
+should not be used together):
+
+       CRYPTO_LOCK     0x01
+       CRYPTO_UNLOCK   0x02
+       CRYPTO_READ     0x04
+       CRYPTO_WRITE    0x08
+
+=head1 RETURN VALUES
+
+CRYPTO_num_locks() returns the required number of locks.
+
+CRYPTO_get_new_dynlockid() returns the index to the newly created lock.
+
+The other functions return no values.
+
+=head1 NOTES
+
+You can find out if OpenSSL was configured with thread support:
+
+ #define OPENSSL_THREAD_DEFINES
+ #include <openssl/opensslconf.h>
+ #if defined(OPENSSL_THREADS)
+   // thread support enabled
+ #else
+   // no thread support
+ #endif
+
+Also, dynamic locks are currently not used internally by OpenSSL, but
+may do so in the future.
+
+=head1 EXAMPLES
+
+B<crypto/threads/mttest.c> shows examples of the callback functions on
+Solaris, Irix and Win32.
+
+=head1 HISTORY
+
+CRYPTO_set_locking_callback() is
+available in all versions of SSLeay and OpenSSL.
+CRYPTO_num_locks() was added in OpenSSL 0.9.4.
+All functions dealing with dynamic locks were added in OpenSSL 0.9.5b-dev.
+B<CRYPTO_THREADID> and associated functions were introduced in OpenSSL 1.0.0
+to replace (actually, deprecate) the previous CRYPTO_set_id_callback(),
+CRYPTO_get_id_callback(), and CRYPTO_thread_id() functions which assumed
+thread IDs to always be represented by 'unsigned long'.
+
+=head1 SEE ALSO
+
+L<crypto(3)|crypto(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/ui.pod b/deps/openssl/openssl/doc/crypto/ui.pod
new file mode 100644 (file)
index 0000000..6df68d6
--- /dev/null
@@ -0,0 +1,194 @@
+=pod
+
+=head1 NAME
+
+UI_new, UI_new_method, UI_free, UI_add_input_string, UI_dup_input_string,
+UI_add_verify_string, UI_dup_verify_string, UI_add_input_boolean,
+UI_dup_input_boolean, UI_add_info_string, UI_dup_info_string,
+UI_add_error_string, UI_dup_error_string, UI_construct_prompt,
+UI_add_user_data, UI_get0_user_data, UI_get0_result, UI_process,
+UI_ctrl, UI_set_default_method, UI_get_default_method, UI_get_method,
+UI_set_method, UI_OpenSSL, ERR_load_UI_strings - New User Interface
+
+=head1 SYNOPSIS
+
+ #include <openssl/ui.h>
+
+ typedef struct ui_st UI;
+ typedef struct ui_method_st UI_METHOD;
+
+ UI *UI_new(void);
+ UI *UI_new_method(const UI_METHOD *method);
+ void UI_free(UI *ui);
+
+ int UI_add_input_string(UI *ui, const char *prompt, int flags,
+       char *result_buf, int minsize, int maxsize);
+ int UI_dup_input_string(UI *ui, const char *prompt, int flags,
+       char *result_buf, int minsize, int maxsize);
+ int UI_add_verify_string(UI *ui, const char *prompt, int flags,
+       char *result_buf, int minsize, int maxsize, const char *test_buf);
+ int UI_dup_verify_string(UI *ui, const char *prompt, int flags,
+       char *result_buf, int minsize, int maxsize, const char *test_buf);
+ int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc,
+       const char *ok_chars, const char *cancel_chars,
+       int flags, char *result_buf);
+ int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc,
+       const char *ok_chars, const char *cancel_chars,
+       int flags, char *result_buf);
+ int UI_add_info_string(UI *ui, const char *text);
+ int UI_dup_info_string(UI *ui, const char *text);
+ int UI_add_error_string(UI *ui, const char *text);
+ int UI_dup_error_string(UI *ui, const char *text);
+
+ /* These are the possible flags.  They can be or'ed together. */
+ #define UI_INPUT_FLAG_ECHO            0x01
+ #define UI_INPUT_FLAG_DEFAULT_PWD     0x02
+
+ char *UI_construct_prompt(UI *ui_method,
+       const char *object_desc, const char *object_name);
+
+ void *UI_add_user_data(UI *ui, void *user_data);
+ void *UI_get0_user_data(UI *ui);
+
+ const char *UI_get0_result(UI *ui, int i);
+
+ int UI_process(UI *ui);
+
+ int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)());
+ #define UI_CTRL_PRINT_ERRORS          1
+ #define UI_CTRL_IS_REDOABLE           2
+
+ void UI_set_default_method(const UI_METHOD *meth);
+ const UI_METHOD *UI_get_default_method(void);
+ const UI_METHOD *UI_get_method(UI *ui);
+ const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth);
+
+ UI_METHOD *UI_OpenSSL(void);
+
+=head1 DESCRIPTION
+
+UI stands for User Interface, and is general purpose set of routines to
+prompt the user for text-based information.  Through user-written methods
+(see L<ui_create(3)|ui_create(3)>), prompting can be done in any way
+imaginable, be it plain text prompting, through dialog boxes or from a
+cell phone.
+
+All the functions work through a context of the type UI.  This context
+contains all the information needed to prompt correctly as well as a
+reference to a UI_METHOD, which is an ordered vector of functions that
+carry out the actual prompting.
+
+The first thing to do is to create a UI with UI_new() or UI_new_method(),
+then add information to it with the UI_add or UI_dup functions.  Also,
+user-defined random data can be passed down to the underlying method
+through calls to UI_add_user_data.  The default UI method doesn't care
+about these data, but other methods might.  Finally, use UI_process()
+to actually perform the prompting and UI_get0_result() to find the result
+to the prompt.
+
+A UI can contain more than one prompt, which are performed in the given
+sequence.  Each prompt gets an index number which is returned by the
+UI_add and UI_dup functions, and has to be used to get the corresponding
+result with UI_get0_result().
+
+The functions are as follows:
+
+UI_new() creates a new UI using the default UI method.  When done with
+this UI, it should be freed using UI_free().
+
+UI_new_method() creates a new UI using the given UI method.  When done with
+this UI, it should be freed using UI_free().
+
+UI_OpenSSL() returns the built-in UI method (note: not the default one,
+since the default can be changed.  See further on).  This method is the
+most machine/OS dependent part of OpenSSL and normally generates the
+most problems when porting.
+
+UI_free() removes a UI from memory, along with all other pieces of memory
+that's connected to it, like duplicated input strings, results and others.
+
+UI_add_input_string() and UI_add_verify_string() add a prompt to the UI,
+as well as flags and a result buffer and the desired minimum and maximum
+sizes of the result.  The given information is used to prompt for
+information, for example a password, and to verify a password (i.e. having
+the user enter it twice and check that the same string was entered twice).
+UI_add_verify_string() takes and extra argument that should be a pointer
+to the result buffer of the input string that it's supposed to verify, or
+verification will fail.
+
+UI_add_input_boolean() adds a prompt to the UI that's supposed to be answered
+in a boolean way, with a single character for yes and a different character
+for no.  A set of characters that can be used to cancel the prompt is given
+as well.  The prompt itself is really divided in two, one part being the
+descriptive text (given through the I<prompt> argument) and one describing
+the possible answers (given through the I<action_desc> argument).
+
+UI_add_info_string() and UI_add_error_string() add strings that are shown at
+the same time as the prompt for extra information or to show an error string.
+The difference between the two is only conceptual.  With the builtin method,
+there's no technical difference between them.  Other methods may make a
+difference between them, however.
+
+The flags currently supported are UI_INPUT_FLAG_ECHO, which is relevant for
+UI_add_input_string() and will have the users response be echoed (when
+prompting for a password, this flag should obviously not be used, and
+UI_INPUT_FLAG_DEFAULT_PWD, which means that a default password of some
+sort will be used (completely depending on the application and the UI
+method).
+
+UI_dup_input_string(), UI_dup_verify_string(), UI_dup_input_boolean(),
+UI_dup_info_string() and UI_dup_error_string() are basically the same
+as their UI_add counterparts, except that they make their own copies
+of all strings.
+
+UI_construct_prompt() is a helper function that can be used to create
+a prompt from two pieces of information: an description and a name.
+The default constructor (if there is none provided by the method used)
+creates a string "Enter I<description> for I<name>:".  With the
+description "pass phrase" and the file name "foo.key", that becomes
+"Enter pass phrase for foo.key:".  Other methods may create whatever
+string and may include encodings that will be processed by the other
+method functions.
+
+UI_add_user_data() adds a piece of memory for the method to use at any
+time.  The builtin UI method doesn't care about this info.  Note that several
+calls to this function doesn't add data, it replaces the previous blob
+with the one given as argument.
+
+UI_get0_user_data() retrieves the data that has last been given to the
+UI with UI_add_user_data().
+
+UI_get0_result() returns a pointer to the result buffer associated with
+the information indexed by I<i>.
+
+UI_process() goes through the information given so far, does all the printing
+and prompting and returns.
+
+UI_ctrl() adds extra control for the application author.  For now, it
+understands two commands: UI_CTRL_PRINT_ERRORS, which makes UI_process()
+print the OpenSSL error stack as part of processing the UI, and
+UI_CTRL_IS_REDOABLE, which returns a flag saying if the used UI can
+be used again or not.
+
+UI_set_default_method() changes the default UI method to the one given.
+
+UI_get_default_method() returns a pointer to the current default UI method.
+
+UI_get_method() returns the UI method associated with a given UI.
+
+UI_set_method() changes the UI method associated with a given UI.
+
+=head1 SEE ALSO
+
+L<ui_create(3)|ui_create(3)>, L<ui_compat(3)|ui_compat(3)>
+
+=head1 HISTORY
+
+The UI section was first introduced in OpenSSL 0.9.7.
+
+=head1 AUTHOR
+
+Richard Levitte (richard@levitte.org) for the OpenSSL project
+(http://www.openssl.org).
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/ui_compat.pod b/deps/openssl/openssl/doc/crypto/ui_compat.pod
new file mode 100644 (file)
index 0000000..adf2ae5
--- /dev/null
@@ -0,0 +1,57 @@
+=pod
+
+=head1 NAME
+
+des_read_password, des_read_2passwords, des_read_pw_string, des_read_pw -
+Compatibility user interface functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/des_old.h>
+
+ int des_read_password(DES_cblock *key,const char *prompt,int verify);
+ int des_read_2passwords(DES_cblock *key1,DES_cblock *key2,
+       const char *prompt,int verify);
+
+ int des_read_pw_string(char *buf,int length,const char *prompt,int verify);
+ int des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify);
+
+=head1 DESCRIPTION
+
+The DES library contained a few routines to prompt for passwords.  These
+aren't necessarely dependent on DES, and have therefore become part of the
+UI compatibility library.
+
+des_read_pw() writes the string specified by I<prompt> to standard output
+turns echo off and reads an input string from the terminal.  The string is
+returned in I<buf>, which must have spac for at least I<size> bytes.
+If I<verify> is set, the user is asked for the password twice and unless
+the two copies match, an error is returned.  The second password is stored
+in I<buff>, which must therefore also be at least I<size> bytes.  A return
+code of -1 indicates a system error, 1 failure due to use interaction, and
+0 is success.  All other functions described here use des_read_pw() to do
+the work.
+
+des_read_pw_string() is a variant of des_read_pw() that provides a buffer
+for you if I<verify> is set.
+
+des_read_password() calls des_read_pw() and converts the password to a
+DES key by calling DES_string_to_key(); des_read_2password() operates in
+the same way as des_read_password() except that it generates two keys
+by using the DES_string_to_2key() function.
+
+=head1 NOTES
+
+des_read_pw_string() is available in the MIT Kerberos library as well, and
+is also available under the name EVP_read_pw_string().
+
+=head1 SEE ALSO
+
+L<ui(3)|ui(3)>, L<ui_create(3)|ui_create(3)>
+
+=head1 AUTHOR
+
+Richard Levitte (richard@levitte.org) for the OpenSSL project
+(http://www.openssl.org).
+
+=cut
diff --git a/deps/openssl/openssl/doc/crypto/x509.pod b/deps/openssl/openssl/doc/crypto/x509.pod
new file mode 100644 (file)
index 0000000..f9e58e0
--- /dev/null
@@ -0,0 +1,64 @@
+=pod
+
+=head1 NAME
+
+x509 - X.509 certificate handling
+
+=head1 SYNOPSIS
+
+ #include <openssl/x509.h>
+
+=head1 DESCRIPTION
+
+A X.509 certificate is a structured grouping of information about
+an individual, a device, or anything one can imagine.  A X.509 CRL
+(certificate revocation list) is a tool to help determine if a
+certificate is still valid.  The exact definition of those can be
+found in the X.509 document from ITU-T, or in RFC3280 from PKIX.
+In OpenSSL, the type X509 is used to express such a certificate, and
+the type X509_CRL is used to express a CRL.
+
+A related structure is a certificate request, defined in PKCS#10 from
+RSA Security, Inc, also reflected in RFC2896.  In OpenSSL, the type
+X509_REQ is used to express such a certificate request.
+
+To handle some complex parts of a certificate, there are the types
+X509_NAME (to express a certificate name), X509_ATTRIBUTE (to express
+a certificate attributes), X509_EXTENSION (to express a certificate
+extension) and a few more.
+
+Finally, there's the supertype X509_INFO, which can contain a CRL, a
+certificate and a corresponding private key.
+
+B<X509_>I<...>, B<d2i_X509_>I<...> and B<i2d_X509_>I<...> handle X.509
+certificates, with some exceptions, shown below.
+
+B<X509_CRL_>I<...>, B<d2i_X509_CRL_>I<...> and B<i2d_X509_CRL_>I<...>
+handle X.509 CRLs.
+
+B<X509_REQ_>I<...>, B<d2i_X509_REQ_>I<...> and B<i2d_X509_REQ_>I<...>
+handle PKCS#10 certificate requests.
+
+B<X509_NAME_>I<...> handle certificate names.
+
+B<X509_ATTRIBUTE_>I<...> handle certificate attributes.
+
+B<X509_EXTENSION_>I<...> handle certificate extensions.
+
+=head1 SEE ALSO
+
+L<X509_NAME_ENTRY_get_object(3)|X509_NAME_ENTRY_get_object(3)>,
+L<X509_NAME_add_entry_by_txt(3)|X509_NAME_add_entry_by_txt(3)>,
+L<X509_NAME_add_entry_by_NID(3)|X509_NAME_add_entry_by_NID(3)>,
+L<X509_NAME_print_ex(3)|X509_NAME_print_ex(3)>,
+L<X509_NAME_new(3)|X509_NAME_new(3)>,
+L<d2i_X509(3)|d2i_X509(3)>,
+L<d2i_X509_ALGOR(3)|d2i_X509_ALGOR(3)>,
+L<d2i_X509_CRL(3)|d2i_X509_CRL(3)>,
+L<d2i_X509_NAME(3)|d2i_X509_NAME(3)>,
+L<d2i_X509_REQ(3)|d2i_X509_REQ(3)>,
+L<d2i_X509_SIG(3)|d2i_X509_SIG(3)>,
+L<crypto(3)|crypto(3)>,
+L<x509v3(3)|x509v3(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/fingerprints.txt b/deps/openssl/openssl/doc/fingerprints.txt
new file mode 100644 (file)
index 0000000..7d05a85
--- /dev/null
@@ -0,0 +1,57 @@
+                              Fingerprints
+
+OpenSSL releases are signed with PGP/GnuPG keys.  You can find the
+signatures in separate files in the same location you find the
+distributions themselves.  The normal file name is the same as the
+distribution file, with '.asc' added.  For example, the signature for
+the distribution of OpenSSL 0.9.7f, openssl-0.9.7f.tar.gz, is found in
+the file openssl-0.9.7f.tar.gz.asc.
+
+The following is the list of fingerprints for the keys that are
+currently in use (have been used since summer 2004) to sign OpenSSL
+distributions:
+
+pub   1024D/F709453B 2003-10-20
+      Key fingerprint = C4CA B749 C34F 7F4C C04F  DAC9 A7AF 9E78 F709 453B
+uid                  Richard Levitte <richard@levitte.org>
+uid                  Richard Levitte <levitte@openssl.org>
+uid                  Richard Levitte <levitte@lp.se>
+
+pub   2048R/F295C759 1998-12-13
+      Key fingerprint = D0 5D 8C 61 6E 27 E6 60  41 EC B1 B8 D5 7E E5 97
+uid                  Dr S N Henson <shenson@drh-consultancy.demon.co.uk>
+
+pub   1024R/49A563D9 1997-02-24
+      Key fingerprint = 7B 79 19 FA 71 6B 87 25  0E 77 21 E5 52 D9 83 BF
+uid                  Mark Cox <mjc@redhat.com>
+uid                  Mark Cox <mark@awe.com>
+uid                  Mark Cox <mjc@apache.org>
+
+pub   1024R/26BB437D 1997-04-28
+      Key fingerprint = 00 C9 21 8E D1 AB 70 37  DD 67 A2 3A 0A 6F 8D A5
+uid                  Ralf S. Engelschall <rse@engelschall.com>
+
+pub   1024R/9C58A66D 1997-04-03
+      Key fingerprint = 13 D0 B8 9D 37 30 C3 ED  AC 9C 24 7D 45 8C 17 67
+uid                  jaenicke@openssl.org
+uid                  Lutz Jaenicke <Lutz.Jaenicke@aet.TU-Cottbus.DE>
+
+pub   1024D/2118CF83 1998-07-13
+      Key fingerprint = 7656 55DE 62E3 96FF 2587  EB6C 4F6D E156 2118 CF83
+uid                  Ben Laurie <ben@thebunker.net>
+uid                  Ben Laurie <ben@cryptix.org>
+uid                  Ben Laurie <ben@algroup.co.uk>
+sub   4096g/1F5143E7 1998-07-13
+
+pub   1024R/5A6A9B85 1994-03-22
+      Key fingerprint = C7 AC 7E AD 56 6A 65 EC  F6 16 66 83 7E 86 68 28
+uid                  Bodo Moeller <2005@bmoeller.de>
+uid                  Bodo Moeller <2003@bmoeller.de>
+uid                  Bodo Moeller <2004@bmoeller.de>
+uid                  Bodo Moeller <bmoeller@acm.org>
+uid                  Bodo Moeller <bodo@openssl.org>
+uid                  Bodo Moeller <bm@ulf.mali.sub.org>
+uid                  Bodo Moeller <3moeller@informatik.uni-hamburg.de>
+uid                  Bodo Moeller <Bodo_Moeller@public.uni-hamburg.de>
+uid                  Bodo Moeller <3moeller@rzdspc5.informatik.uni-hamburg.de>
+
diff --git a/deps/openssl/openssl/doc/openssl-shared.txt b/deps/openssl/openssl/doc/openssl-shared.txt
new file mode 100644 (file)
index 0000000..5cf84a0
--- /dev/null
@@ -0,0 +1,32 @@
+The OpenSSL  shared libraries are often installed in a directory like
+/usr/local/ssl/lib.
+
+If this directory is not in a standard system path for dynamic/shared
+libraries, then you will have problems linking and executing
+applications that use OpenSSL libraries UNLESS:
+
+* you link with static (archive) libraries.  If you are truly
+  paranoid about security, you should use static libraries.
+* you use the GNU libtool code during linking
+  (http://www.gnu.org/software/libtool/libtool.html)
+* you use pkg-config during linking (this requires that
+  PKG_CONFIG_PATH includes the path to the OpenSSL shared
+  library directory), and make use of -R or -rpath.
+  (http://www.freedesktop.org/software/pkgconfig/)
+* you specify the system-wide link path via a command such
+  as crle(1) on Solaris systems.
+* you add the OpenSSL shared library directory to /etc/ld.so.conf
+  and run ldconfig(8) on Linux systems.
+* you define the LD_LIBRARY_PATH, LIBPATH, SHLIB_PATH (HP),
+  DYLD_LIBRARY_PATH (MacOS X) or PATH (Cygwin and DJGPP)
+  environment variable and add the OpenSSL shared library
+  directory to it.
+
+One common tool to check the dynamic dependencies of an executable
+or dynamic library is ldd(1) on most UNIX systems.
+
+See any operating system documentation and manpages about shared
+libraries for your version of UNIX.  The following manpages may be
+helpful: ld(1), ld.so(1), ld.so.1(1) [Solaris], dld.sl(1) [HP],
+ldd(1), crle(1) [Solaris], pldd(1) [Solaris], ldconfig(8) [Linux],
+chatr(1) [HP].
diff --git a/deps/openssl/openssl/doc/openssl.txt b/deps/openssl/openssl/doc/openssl.txt
new file mode 100644 (file)
index 0000000..f8817b0
--- /dev/null
@@ -0,0 +1,1254 @@
+
+This is some preliminary documentation for OpenSSL.
+
+Contents:
+
+ OpenSSL X509V3 extension configuration
+ X509V3 Extension code: programmers guide
+ PKCS#12 Library
+
+
+==============================================================================
+               OpenSSL X509V3 extension configuration
+==============================================================================
+
+OpenSSL X509V3 extension configuration: preliminary documentation.
+
+INTRODUCTION.
+
+For OpenSSL 0.9.2 the extension code has be considerably enhanced. It is now
+possible to add and print out common X509 V3 certificate and CRL extensions.
+
+BEGINNERS NOTE
+
+For most simple applications you don't need to know too much about extensions:
+the default openssl.cnf values will usually do sensible things.
+
+If you want to know more you can initially quickly look through the sections
+describing how the standard OpenSSL utilities display and add extensions and
+then the list of supported extensions.
+
+For more technical information about the meaning of extensions see:
+
+http://www.imc.org/ietf-pkix/
+http://home.netscape.com/eng/security/certs.html
+
+PRINTING EXTENSIONS.
+
+Extension values are automatically printed out for supported extensions.
+
+openssl x509 -in cert.pem -text
+openssl crl -in crl.pem -text
+
+will give information in the extension printout, for example:
+
+        X509v3 extensions:
+            X509v3 Basic Constraints: 
+                CA:TRUE
+            X509v3 Subject Key Identifier: 
+                73:FE:F7:59:A7:E1:26:84:44:D6:44:36:EE:79:1A:95:7C:B1:4B:15
+            X509v3 Authority Key Identifier: 
+                keyid:73:FE:F7:59:A7:E1:26:84:44:D6:44:36:EE:79:1A:95:7C:B1:4B:15, DirName:/C=AU/ST=Some-State/O=Internet Widgits Pty Ltd/Email=email@1.address/Email=email@2.address, serial:00
+            X509v3 Key Usage: 
+                Certificate Sign, CRL Sign
+            X509v3 Subject Alternative Name: 
+                email:email@1.address, email:email@2.address
+
+CONFIGURATION FILES.
+
+The OpenSSL utilities 'ca' and 'req' can now have extension sections listing
+which certificate extensions to include. In each case a line:
+
+x509_extensions = extension_section
+
+indicates which section contains the extensions. In the case of 'req' the
+extension section is used when the -x509 option is present to create a
+self signed root certificate.
+
+The 'x509' utility also supports extensions when it signs a certificate.
+The -extfile option is used to set the configuration file containing the
+extensions. In this case a line with:
+
+extensions = extension_section
+
+in the nameless (default) section is used. If no such line is included then
+it uses the default section.
+
+You can also add extensions to CRLs: a line
+
+crl_extensions = crl_extension_section
+
+will include extensions when the -gencrl option is used with the 'ca' utility.
+You can add any extension to a CRL but of the supported extensions only
+issuerAltName and authorityKeyIdentifier make any real sense. Note: these are
+CRL extensions NOT CRL *entry* extensions which cannot currently be generated.
+CRL entry extensions can be displayed.
+
+NB. At this time Netscape Communicator rejects V2 CRLs: to get an old V1 CRL
+you should not include a crl_extensions line in the configuration file.
+
+As with all configuration files you can use the inbuilt environment expansion
+to allow the values to be passed in the environment. Therefore if you have
+several extension sections used for different purposes you can have a line:
+
+x509_extensions = $ENV::ENV_EXT
+
+and set the ENV_EXT environment variable before calling the relevant utility.
+
+EXTENSION SYNTAX.
+
+Extensions have the basic form:
+
+extension_name=[critical,] extension_options
+
+the use of the critical option makes the extension critical. Extreme caution
+should be made when using the critical flag. If an extension is marked
+as critical then any client that does not understand the extension should
+reject it as invalid. Some broken software will reject certificates which
+have *any* critical extensions (these violates PKIX but we have to live
+with it).
+
+There are three main types of extension: string extensions, multi-valued
+extensions, and raw extensions.
+
+String extensions simply have a string which contains either the value itself
+or how it is obtained.
+
+For example:
+
+nsComment="This is a Comment"
+
+Multi-valued extensions have a short form and a long form. The short form
+is a list of names and values:
+
+basicConstraints=critical,CA:true,pathlen:1
+
+The long form allows the values to be placed in a separate section:
+
+basicConstraints=critical,@bs_section
+
+[bs_section]
+
+CA=true
+pathlen=1
+
+Both forms are equivalent. However it should be noted that in some cases the
+same name can appear multiple times, for example,
+
+subjectAltName=email:steve@here,email:steve@there
+
+in this case an equivalent long form is:
+
+subjectAltName=@alt_section
+
+[alt_section]
+
+email.1=steve@here
+email.2=steve@there
+
+This is because the configuration file code cannot handle the same name
+occurring twice in the same section.
+
+The syntax of raw extensions is governed by the extension code: it can
+for example contain data in multiple sections. The correct syntax to
+use is defined by the extension code itself: check out the certificate
+policies extension for an example.
+
+There are two ways to encode arbitrary extensions.
+
+The first way is to use the word ASN1 followed by the extension content
+using the same syntax as ASN1_generate_nconf(). For example:
+
+1.2.3.4=critical,ASN1:UTF8String:Some random data
+
+1.2.3.4=ASN1:SEQUENCE:seq_sect
+
+[seq_sect]
+
+field1 = UTF8:field1
+field2 = UTF8:field2
+
+It is also possible to use the word DER to include arbitrary data in any
+extension.
+
+1.2.3.4=critical,DER:01:02:03:04
+1.2.3.4=DER:01020304
+
+The value following DER is a hex dump of the DER encoding of the extension
+Any extension can be placed in this form to override the default behaviour.
+For example:
+
+basicConstraints=critical,DER:00:01:02:03
+
+WARNING: DER should be used with caution. It is possible to create totally
+invalid extensions unless care is taken.
+
+CURRENTLY SUPPORTED EXTENSIONS.
+
+If you aren't sure about extensions then they can be largely ignored: its only
+when you want to do things like restrict certificate usage when you need to
+worry about them. 
+
+The only extension that a beginner might want to look at is Basic Constraints.
+If in addition you want to try Netscape object signing the you should also
+look at Netscape Certificate Type.
+
+Literal String extensions.
+
+In each case the 'value' of the extension is placed directly in the
+extension. Currently supported extensions in this category are: nsBaseUrl,
+nsRevocationUrl, nsCaRevocationUrl, nsRenewalUrl, nsCaPolicyUrl,
+nsSslServerName and nsComment.
+
+For example:
+
+nsComment="This is a test comment"
+
+Bit Strings.
+
+Bit string extensions just consist of a list of supported bits, currently
+two extensions are in this category: PKIX keyUsage and the Netscape specific
+nsCertType.
+
+nsCertType (netscape certificate type) takes the flags: client, server, email,
+objsign, reserved, sslCA, emailCA, objCA.
+
+keyUsage (PKIX key usage) takes the flags: digitalSignature, nonRepudiation,
+keyEncipherment, dataEncipherment, keyAgreement, keyCertSign, cRLSign,
+encipherOnly, decipherOnly.
+
+For example:
+
+nsCertType=server
+
+keyUsage=digitalSignature, nonRepudiation
+
+Hints on Netscape Certificate Type.
+
+Other than Basic Constraints this is the only extension a beginner might
+want to use, if you want to try Netscape object signing, otherwise it can
+be ignored.
+
+If you want a certificate that can be used just for object signing then:
+
+nsCertType=objsign
+
+will do the job. If you want to use it as a normal end user and server
+certificate as well then
+
+nsCertType=objsign,email,server
+
+is more appropriate. You cannot use a self signed certificate for object
+signing (well Netscape signtool can but it cheats!) so you need to create
+a CA certificate and sign an end user certificate with it.
+
+Side note: If you want to conform to the Netscape specifications then you
+should really also set:
+
+nsCertType=objCA
+
+in the *CA* certificate for just an object signing CA and
+
+nsCertType=objCA,emailCA,sslCA
+
+for everything. Current Netscape software doesn't enforce this so it can
+be omitted.
+
+Basic Constraints.
+
+This is generally the only extension you need to worry about for simple
+applications. If you want your certificate to be usable as a CA certificate
+(in addition to an end user certificate) then you set this to:
+
+basicConstraints=CA:TRUE
+
+if you want to be certain the certificate cannot be used as a CA then do:
+
+basicConstraints=CA:FALSE
+
+The rest of this section describes more advanced usage.
+
+Basic constraints is a multi-valued extension that supports a CA and an
+optional pathlen option. The CA option takes the values true and false and
+pathlen takes an integer. Note if the CA option is false the pathlen option
+should be omitted. 
+
+The pathlen parameter indicates the maximum number of CAs that can appear
+below this one in a chain. So if you have a CA with a pathlen of zero it can
+only be used to sign end user certificates and not further CAs. This all
+assumes that the software correctly interprets this extension of course.
+
+Examples:
+
+basicConstraints=CA:TRUE
+basicConstraints=critical,CA:TRUE, pathlen:0
+
+NOTE: for a CA to be considered valid it must have the CA option set to
+TRUE. An end user certificate MUST NOT have the CA value set to true.
+According to PKIX recommendations it should exclude the extension entirely,
+however some software may require CA set to FALSE for end entity certificates.
+
+Extended Key Usage.
+
+This extensions consists of a list of usages.
+
+These can either be object short names of the dotted numerical form of OIDs.
+While any OID can be used only certain values make sense. In particular the
+following PKIX, NS and MS values are meaningful:
+
+Value                  Meaning
+-----                  -------
+serverAuth             SSL/TLS Web Server Authentication.
+clientAuth             SSL/TLS Web Client Authentication.
+codeSigning            Code signing.
+emailProtection                E-mail Protection (S/MIME).
+timeStamping           Trusted Timestamping
+msCodeInd              Microsoft Individual Code Signing (authenticode)
+msCodeCom              Microsoft Commercial Code Signing (authenticode)
+msCTLSign              Microsoft Trust List Signing
+msSGC                  Microsoft Server Gated Crypto
+msEFS                  Microsoft Encrypted File System
+nsSGC                  Netscape Server Gated Crypto
+
+For example, under IE5 a CA can be used for any purpose: by including a list
+of the above usages the CA can be restricted to only authorised uses.
+
+Note: software packages may place additional interpretations on certificate 
+use, in particular some usages may only work for selected CAs. Don't for example
+expect just including msSGC or nsSGC will automatically mean that a certificate
+can be used for SGC ("step up" encryption) otherwise anyone could use it.
+
+Examples:
+
+extendedKeyUsage=critical,codeSigning,1.2.3.4
+extendedKeyUsage=nsSGC,msSGC
+
+Subject Key Identifier.
+
+This is really a string extension and can take two possible values. Either
+a hex string giving details of the extension value to include or the word
+'hash' which then automatically follow PKIX guidelines in selecting and
+appropriate key identifier. The use of the hex string is strongly discouraged.
+
+Example: subjectKeyIdentifier=hash
+
+Authority Key Identifier.
+
+The authority key identifier extension permits two options. keyid and issuer:
+both can take the optional value "always".
+
+If the keyid option is present an attempt is made to copy the subject key
+identifier from the parent certificate. If the value "always" is present
+then an error is returned if the option fails.
+
+The issuer option copies the issuer and serial number from the issuer
+certificate. Normally this will only be done if the keyid option fails or
+is not included: the "always" flag will always include the value.
+
+Subject Alternative Name.
+
+The subject alternative name extension allows various literal values to be
+included in the configuration file. These include "email" (an email address)
+"URI" a uniform resource indicator, "DNS" (a DNS domain name), RID (a
+registered ID: OBJECT IDENTIFIER), IP (and IP address) and otherName.
+
+Also the email option include a special 'copy' value. This will automatically
+include and email addresses contained in the certificate subject name in
+the extension.
+
+otherName can include arbitrary data associated with an OID: the value
+should be the OID followed by a semicolon and the content in standard
+ASN1_generate_nconf() format.
+
+Examples:
+
+subjectAltName=email:copy,email:my@other.address,URI:http://my.url.here/
+subjectAltName=email:my@other.address,RID:1.2.3.4
+subjectAltName=otherName:1.2.3.4;UTF8:some other identifier
+
+Issuer Alternative Name.
+
+The issuer alternative name option supports all the literal options of
+subject alternative name. It does *not* support the email:copy option because
+that would not make sense. It does support an additional issuer:copy option
+that will copy all the subject alternative name values from the issuer 
+certificate (if possible).
+
+Example:
+
+issuserAltName = issuer:copy
+
+Authority Info Access.
+
+The authority information access extension gives details about how to access
+certain information relating to the CA. Its syntax is accessOID;location
+where 'location' has the same syntax as subject alternative name (except
+that email:copy is not supported). accessOID can be any valid OID but only
+certain values are meaningful for example OCSP and caIssuers. OCSP gives the
+location of an OCSP responder: this is used by Netscape PSM and other software.
+
+Example:
+
+authorityInfoAccess = OCSP;URI:http://ocsp.my.host/
+authorityInfoAccess = caIssuers;URI:http://my.ca/ca.html
+
+CRL distribution points.
+
+This is a multi-valued extension that supports all the literal options of
+subject alternative name. Of the few software packages that currently interpret
+this extension most only interpret the URI option.
+
+Currently each option will set a new DistributionPoint with the fullName
+field set to the given value.
+
+Other fields like cRLissuer and reasons cannot currently be set or displayed:
+at this time no examples were available that used these fields.
+
+If you see this extension with <UNSUPPORTED> when you attempt to print it out
+or it doesn't appear to display correctly then let me know, including the
+certificate (mail me at steve@openssl.org) .
+
+Examples:
+
+crlDistributionPoints=URI:http://www.myhost.com/myca.crl
+crlDistributionPoints=URI:http://www.my.com/my.crl,URI:http://www.oth.com/my.crl
+
+Certificate Policies.
+
+This is a RAW extension. It attempts to display the contents of this extension:
+unfortunately this extension is often improperly encoded.
+
+The certificate policies extension will rarely be used in practice: few
+software packages interpret it correctly or at all. IE5 does partially
+support this extension: but it needs the 'ia5org' option because it will
+only correctly support a broken encoding. Of the options below only the
+policy OID, explicitText and CPS options are displayed with IE5.
+
+All the fields of this extension can be set by using the appropriate syntax.
+
+If you follow the PKIX recommendations of not including any qualifiers and just
+using only one OID then you just include the value of that OID. Multiple OIDs
+can be set separated by commas, for example:
+
+certificatePolicies= 1.2.4.5, 1.1.3.4
+
+If you wish to include qualifiers then the policy OID and qualifiers need to
+be specified in a separate section: this is done by using the @section syntax
+instead of a literal OID value.
+
+The section referred to must include the policy OID using the name
+policyIdentifier, cPSuri qualifiers can be included using the syntax:
+
+CPS.nnn=value
+
+userNotice qualifiers can be set using the syntax:
+
+userNotice.nnn=@notice
+
+The value of the userNotice qualifier is specified in the relevant section.
+This section can include explicitText, organization and noticeNumbers
+options. explicitText and organization are text strings, noticeNumbers is a
+comma separated list of numbers. The organization and noticeNumbers options
+(if included) must BOTH be present. If you use the userNotice option with IE5
+then you need the 'ia5org' option at the top level to modify the encoding:
+otherwise it will not be interpreted properly.
+
+Example:
+
+certificatePolicies=ia5org,1.2.3.4,1.5.6.7.8,@polsect
+
+[polsect]
+
+policyIdentifier = 1.3.5.8
+CPS.1="http://my.host.name/"
+CPS.2="http://my.your.name/"
+userNotice.1=@notice
+
+[notice]
+
+explicitText="Explicit Text Here"
+organization="Organisation Name"
+noticeNumbers=1,2,3,4
+
+TECHNICAL NOTE: the ia5org option changes the type of the 'organization' field,
+according to PKIX it should be of type DisplayText but Verisign uses an 
+IA5STRING and IE5 needs this too.
+
+Display only extensions.
+
+Some extensions are only partially supported and currently are only displayed
+but cannot be set. These include private key usage period, CRL number, and
+CRL reason.
+
+==============================================================================
+               X509V3 Extension code: programmers guide
+==============================================================================
+
+The purpose of the extension code is twofold. It allows an extension to be
+created from a string or structure describing its contents and it prints out an
+extension in a human or machine readable form.
+
+1. Initialisation and cleanup.
+
+No special initialisation is needed before calling the extension functions.
+You used to have to call X509V3_add_standard_extensions(); but this is no longer
+required and this function no longer does anything.
+
+void X509V3_EXT_cleanup(void);
+
+This function should be called to cleanup the extension code if any custom
+extensions have been added. If no custom extensions have been added then this
+call does nothing. After this call all custom extension code is freed up but
+you can still use the standard extensions.
+
+2. Printing and parsing extensions.
+
+The simplest way to print out extensions is via the standard X509 printing
+routines: if you use the standard X509_print() function, the supported
+extensions will be printed out automatically.
+
+The following functions allow finer control over extension display:
+
+int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent);
+int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent);
+
+These two functions print out an individual extension to a BIO or FILE pointer.
+Currently the flag argument is unused and should be set to 0. The 'indent'
+argument is the number of spaces to indent each line.
+
+void *X509V3_EXT_d2i(X509_EXTENSION *ext);
+
+This function parses an extension and returns its internal structure. The
+precise structure you get back depends on the extension being parsed. If the
+extension if basicConstraints you will get back a pointer to a
+BASIC_CONSTRAINTS structure. Check out the source in crypto/x509v3 for more
+details about the structures returned. The returned structure should be freed
+after use using the relevant free function, BASIC_CONSTRAINTS_free() for 
+example.
+
+void   *       X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx);
+void   *       X509_CRL_get_ext_d2i(X509_CRL *x, int nid, int *crit, int *idx);
+void   *       X509_REVOKED_get_ext_d2i(X509_REVOKED *x, int nid, int *crit, int *idx);
+void   *       X509V3_get_d2i(STACK_OF(X509_EXTENSION) *x, int nid, int *crit, int *idx);
+
+These functions combine the operations of searching for extensions and
+parsing them. They search a certificate, a CRL a CRL entry or a stack
+of extensions respectively for extension whose NID is 'nid' and return
+the parsed result of NULL if an error occurred. For example:
+
+BASIC_CONSTRAINTS *bs;
+bs = X509_get_ext_d2i(cert, NID_basic_constraints, NULL, NULL);
+
+This will search for the basicConstraints extension and either return
+it value or NULL. NULL can mean either the extension was not found, it
+occurred more than once or it could not be parsed.
+
+If 'idx' is NULL then an extension is only parsed if it occurs precisely
+once. This is standard behaviour because extensions normally cannot occur
+more than once. If however more than one extension of the same type can
+occur it can be used to parse successive extensions for example:
+
+int i;
+void *ext;
+
+i = -1;
+for(;;) {
+       ext = X509_get_ext_d2i(x, nid, crit, &idx);
+       if(ext == NULL) break;
+        /* Do something with ext */
+}
+
+If 'crit' is not NULL and the extension was found then the int it points to
+is set to 1 for critical extensions and 0 for non critical. Therefore if the
+function returns NULL but 'crit' is set to 0 or 1 then the extension was
+found but it could not be parsed.
+
+The int pointed to by crit will be set to -1 if the extension was not found
+and -2 if the extension occurred more than once (this will only happen if
+idx is NULL). In both cases the function will return NULL.
+
+3. Generating extensions.
+
+An extension will typically be generated from a configuration file, or some
+other kind of configuration database.
+
+int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
+                                                                X509 *cert);
+int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
+                                                                X509_CRL *crl);
+
+These functions add all the extensions in the given section to the given
+certificate or CRL. They will normally be called just before the certificate
+or CRL is due to be signed. Both return 0 on error on non zero for success.
+
+In each case 'conf' is the LHASH pointer of the configuration file to use
+and 'section' is the section containing the extension details.
+
+See the 'context functions' section for a description of the ctx parameter.
+
+
+X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name,
+                                                                char *value);
+
+This function returns an extension based on a name and value pair, if the
+pair will not need to access other sections in a config file (or there is no
+config file) then the 'conf' parameter can be set to NULL.
+
+X509_EXTENSION *X509V3_EXT_conf_nid(char *conf, X509V3_CTX *ctx, int nid,
+                                                                char *value);
+
+This function creates an extension in the same way as X509V3_EXT_conf() but
+takes the NID of the extension rather than its name.
+
+For example to produce basicConstraints with the CA flag and a path length of
+10:
+
+x = X509V3_EXT_conf_nid(NULL, NULL, NID_basic_constraints,"CA:TRUE,pathlen:10");
+
+
+X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc);
+
+This function sets up an extension from its internal structure. The ext_nid
+parameter is the NID of the extension and 'crit' is the critical flag.
+
+4. Context functions.
+
+The following functions set and manipulate an extension context structure.
+The purpose of the extension context is to allow the extension code to
+access various structures relating to the "environment" of the certificate:
+for example the issuers certificate or the certificate request.
+
+void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subject,
+                                 X509_REQ *req, X509_CRL *crl, int flags);
+
+This function sets up an X509V3_CTX structure with details of the certificate
+environment: specifically the issuers certificate, the subject certificate,
+the certificate request and the CRL: if these are not relevant or not
+available then they can be set to NULL. The 'flags' parameter should be set
+to zero.
+
+X509V3_set_ctx_test(ctx)
+
+This macro is used to set the 'ctx' structure to a 'test' value: this is to
+allow the syntax of an extension (or configuration file) to be tested.
+
+X509V3_set_ctx_nodb(ctx)
+
+This macro is used when no configuration database is present.
+
+void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash);
+
+This function is used to set the configuration database when it is an LHASH
+structure: typically a configuration file.
+
+The following functions are used to access a configuration database: they
+should only be used in RAW extensions.
+
+char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section);
+
+This function returns the value of the parameter "name" in "section", or NULL
+if there has been an error.
+
+void X509V3_string_free(X509V3_CTX *ctx, char *str);
+
+This function frees up the string returned by the above function.
+
+STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section);
+
+This function returns a whole section as a STACK_OF(CONF_VALUE) .
+
+void X509V3_section_free( X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section);
+
+This function frees up the STACK returned by the above function.
+
+Note: it is possible to use the extension code with a custom configuration
+database. To do this the "db_meth" element of the X509V3_CTX structure should
+be set to an X509V3_CTX_METHOD structure. This structure contains the following
+function pointers:
+
+char * (*get_string)(void *db, char *section, char *value);
+STACK_OF(CONF_VALUE) * (*get_section)(void *db, char *section);
+void (*free_string)(void *db, char * string);
+void (*free_section)(void *db, STACK_OF(CONF_VALUE) *section);
+
+these will be called and passed the 'db' element in the X509V3_CTX structure
+to access the database. If a given function is not implemented or not required
+it can be set to NULL.
+
+5. String helper functions.
+
+There are several "i2s" and "s2i" functions that convert structures to and
+from ASCII strings. In all the "i2s" cases the returned string should be
+freed using Free() after use. Since some of these are part of other extension
+code they may take a 'method' parameter. Unless otherwise stated it can be
+safely set to NULL.
+
+char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *oct);
+
+This returns a hex string from an ASN1_OCTET_STRING.
+
+char * i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, ASN1_INTEGER *aint);
+char * i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint);
+
+These return a string decimal representations of an ASN1_INTEGER and an
+ASN1_ENUMERATED type, respectively.
+
+ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
+                                                   X509V3_CTX *ctx, char *str);
+
+This converts an ASCII hex string to an ASN1_OCTET_STRING.
+
+ASN1_INTEGER * s2i_ASN1_INTEGER(X509V3_EXT_METHOD *meth, char *value);
+
+This converts a decimal ASCII string into an ASN1_INTEGER.
+
+6. Multi valued extension helper functions.
+
+The following functions can be used to manipulate STACKs of CONF_VALUE
+structures, as used by multi valued extensions.
+
+int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool);
+
+This function expects a boolean value in 'value' and sets 'asn1_bool' to
+it. That is it sets it to 0 for FALSE or 0xff for TRUE. The following
+strings are acceptable: "TRUE", "true", "Y", "y", "YES", "yes", "FALSE"
+"false", "N", "n", "NO" or "no".
+
+int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint);
+
+This accepts a decimal integer of arbitrary length and sets an ASN1_INTEGER.
+
+int X509V3_add_value(const char *name, const char *value,
+                                               STACK_OF(CONF_VALUE) **extlist);
+
+This simply adds a string name and value pair.
+
+int X509V3_add_value_uchar(const char *name, const unsigned char *value,
+                                               STACK_OF(CONF_VALUE) **extlist);
+
+The same as above but for an unsigned character value.
+
+int X509V3_add_value_bool(const char *name, int asn1_bool,
+                                               STACK_OF(CONF_VALUE) **extlist);
+
+This adds either "TRUE" or "FALSE" depending on the value of 'asn1_bool'
+
+int X509V3_add_value_bool_nf(char *name, int asn1_bool,
+                                               STACK_OF(CONF_VALUE) **extlist);
+
+This is the same as above except it adds nothing if asn1_bool is FALSE.
+
+int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint,
+                                               STACK_OF(CONF_VALUE) **extlist);
+
+This function adds the value of the ASN1_INTEGER in decimal form.
+
+7. Other helper functions.
+
+<to be added>
+
+ADDING CUSTOM EXTENSIONS.
+
+Currently there are three types of supported extensions. 
+
+String extensions are simple strings where the value is placed directly in the
+extensions, and the string returned is printed out.
+
+Multi value extensions are passed a STACK_OF(CONF_VALUE) name and value pairs
+or return a STACK_OF(CONF_VALUE).
+
+Raw extensions are just passed a BIO or a value and it is the extensions
+responsibility to handle all the necessary printing.
+
+There are two ways to add an extension. One is simply as an alias to an already
+existing extension. An alias is an extension that is identical in ASN1 structure
+to an existing extension but has a different OBJECT IDENTIFIER. This can be
+done by calling:
+
+int X509V3_EXT_add_alias(int nid_to, int nid_from);
+
+'nid_to' is the new extension NID and 'nid_from' is the already existing
+extension NID.
+
+Alternatively an extension can be written from scratch. This involves writing
+the ASN1 code to encode and decode the extension and functions to print out and
+generate the extension from strings. The relevant functions are then placed in
+a X509V3_EXT_METHOD structure and int X509V3_EXT_add(X509V3_EXT_METHOD *ext);
+called.
+
+The X509V3_EXT_METHOD structure is described below.
+
+struct {
+int ext_nid;
+int ext_flags;
+X509V3_EXT_NEW ext_new;
+X509V3_EXT_FREE ext_free;
+X509V3_EXT_D2I d2i;
+X509V3_EXT_I2D i2d;
+X509V3_EXT_I2S i2s;
+X509V3_EXT_S2I s2i;
+X509V3_EXT_I2V i2v;
+X509V3_EXT_V2I v2i;
+X509V3_EXT_R2I r2i;
+X509V3_EXT_I2R i2r;
+
+void *usr_data;
+};
+
+The elements have the following meanings.
+
+ext_nid                is the NID of the object identifier of the extension.
+
+ext_flags      is set of flags. Currently the only external flag is
+               X509V3_EXT_MULTILINE which means a multi valued extensions
+               should be printed on separate lines.
+
+usr_data       is an extension specific pointer to any relevant data. This
+               allows extensions to share identical code but have different
+               uses. An example of this is the bit string extension which uses
+               usr_data to contain a list of the bit names.
+
+All the remaining elements are function pointers.
+
+ext_new                is a pointer to a function that allocates memory for the
+               extension ASN1 structure: for example ASN1_OBJECT_new().
+
+ext_free       is a pointer to a function that free up memory of the extension
+               ASN1 structure: for example ASN1_OBJECT_free().
+
+d2i            is the standard ASN1 function that converts a DER buffer into
+               the internal ASN1 structure: for example d2i_ASN1_IA5STRING().
+
+i2d            is the standard ASN1 function that converts the internal
+               structure into the DER representation: for example
+               i2d_ASN1_IA5STRING().
+
+The remaining functions are depend on the type of extension. One i2X and
+one X2i should be set and the rest set to NULL. The types set do not need
+to match up, for example the extension could be set using the multi valued
+v2i function and printed out using the raw i2r.
+
+All functions have the X509V3_EXT_METHOD passed to them in the 'method'
+parameter and an X509V3_CTX structure. Extension code can then access the
+parent structure via the 'method' parameter to for example make use of the value
+of usr_data. If the code needs to use detail relating to the request it can
+use the 'ctx' parameter.
+
+A note should be given here about the 'flags' member of the 'ctx' parameter.
+If it has the value CTX_TEST then the configuration syntax is being checked
+and no actual certificate or CRL exists. Therefore any attempt in the config
+file to access such information should silently succeed. If the syntax is OK
+then it should simply return a (possibly bogus) extension, otherwise it
+should return NULL.
+
+char *i2s(struct v3_ext_method *method, void *ext);
+
+This function takes the internal structure in the ext parameter and returns
+a Malloc'ed string representing its value.
+
+void * s2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
+
+This function takes the string representation in the ext parameter and returns
+an allocated internal structure: ext_free() will be used on this internal
+structure after use.
+
+i2v and v2i handle a STACK_OF(CONF_VALUE):
+
+typedef struct
+{
+        char *section;
+        char *name;
+        char *value;
+} CONF_VALUE;
+
+Only the name and value members are currently used.
+
+STACK_OF(CONF_VALUE) * i2v(struct v3_ext_method *method, void *ext);
+
+This function is passed the internal structure in the ext parameter and
+returns a STACK of CONF_VALUE structures. The values of name, value,
+section and the structure itself will be freed up with Free after use.
+Several helper functions are available to add values to this STACK.
+
+void * v2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx,
+                                               STACK_OF(CONF_VALUE) *values);
+
+This function takes a STACK_OF(CONF_VALUE) structures and should set the
+values of the external structure. This typically uses the name element to
+determine which structure element to set and the value element to determine
+what to set it to. Several helper functions are available for this
+purpose (see above).
+
+int i2r(struct v3_ext_method *method, void *ext, BIO *out, int indent);
+
+This function is passed the internal extension structure in the ext parameter
+and sends out a human readable version of the extension to out. The 'indent'
+parameter should be noted to determine the necessary amount of indentation
+needed on the output.
+
+void * r2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
+
+This is just passed the string representation of the extension. It is intended
+to be used for more elaborate extensions where the standard single and multi
+valued options are insufficient. They can use the 'ctx' parameter to parse the
+configuration database themselves. See the context functions section for details
+of how to do this.
+
+Note: although this type takes the same parameters as the "r2s" function there
+is a subtle difference. Whereas an "r2i" function can access a configuration
+database an "s2i" function MUST NOT. This is so the internal code can safely
+assume that an "s2i" function will work without a configuration database.
+
+==============================================================================
+                            PKCS#12 Library
+==============================================================================
+
+This section describes the internal PKCS#12 support. There are very few
+differences between the old external library and the new internal code at
+present. This may well change because the external library will not be updated
+much in future.
+
+This version now includes a couple of high level PKCS#12 functions which
+generally "do the right thing" and should make it much easier to handle PKCS#12
+structures.
+
+HIGH LEVEL FUNCTIONS.
+
+For most applications you only need concern yourself with the high level
+functions. They can parse and generate simple PKCS#12 files as produced by
+Netscape and MSIE or indeed any compliant PKCS#12 file containing a single
+private key and certificate pair.
+
+1. Initialisation and cleanup.
+
+No special initialisation is needed for the internal PKCS#12 library: the 
+standard SSLeay_add_all_algorithms() is sufficient. If you do not wish to
+add all algorithms (you should at least add SHA1 though) then you can manually
+initialise the PKCS#12 library with:
+
+PKCS12_PBE_add();
+
+The memory allocated by the PKCS#12 library is freed up when EVP_cleanup() is
+called or it can be directly freed with:
+
+EVP_PBE_cleanup();
+
+after this call (or EVP_cleanup() ) no more PKCS#12 library functions should
+be called.
+
+2. I/O functions.
+
+i2d_PKCS12_bio(bp, p12)
+
+This writes out a PKCS12 structure to a BIO.
+
+i2d_PKCS12_fp(fp, p12)
+
+This is the same but for a FILE pointer.
+
+d2i_PKCS12_bio(bp, p12)
+
+This reads in a PKCS12 structure from a BIO.
+
+d2i_PKCS12_fp(fp, p12)
+
+This is the same but for a FILE pointer.
+
+3. High level functions.
+
+3.1 Parsing with PKCS12_parse().
+
+int PKCS12_parse(PKCS12 *p12, char *pass, EVP_PKEY **pkey, X509 **cert,
+                                                                STACK **ca);
+
+This function takes a PKCS12 structure and a password (ASCII, null terminated)
+and returns the private key, the corresponding certificate and any CA
+certificates. If any of these is not required it can be passed as a NULL.
+The 'ca' parameter should be either NULL, a pointer to NULL or a valid STACK
+structure. Typically to read in a PKCS#12 file you might do:
+
+p12 = d2i_PKCS12_fp(fp, NULL);
+PKCS12_parse(p12, password, &pkey, &cert, NULL);       /* CAs not wanted */
+PKCS12_free(p12);
+
+3.2 PKCS#12 creation with PKCS12_create().
+
+PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,
+                       STACK *ca, int nid_key, int nid_cert, int iter,
+                                                int mac_iter, int keytype);
+
+This function will create a PKCS12 structure from a given password, name,
+private key, certificate and optional STACK of CA certificates. The remaining
+5 parameters can be set to 0 and sensible defaults will be used.
+
+The parameters nid_key and nid_cert are the key and certificate encryption
+algorithms, iter is the encryption iteration count, mac_iter is the MAC
+iteration count and keytype is the type of private key. If you really want
+to know what these last 5 parameters do then read the low level section.
+
+Typically to create a PKCS#12 file the following could be used:
+
+p12 = PKCS12_create(pass, "My Certificate", pkey, cert, NULL, 0,0,0,0,0);
+i2d_PKCS12_fp(fp, p12);
+PKCS12_free(p12);
+
+3.3 Changing a PKCS#12 structure password.
+
+int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass);
+
+This changes the password of an already existing PKCS#12 structure. oldpass
+is the old password and newpass is the new one. An error occurs if the old
+password is incorrect.
+
+LOW LEVEL FUNCTIONS.
+
+In some cases the high level functions do not provide the necessary
+functionality. For example if you want to generate or parse more complex
+PKCS#12 files. The sample pkcs12 application uses the low level functions
+to display details about the internal structure of a PKCS#12 file.
+
+Introduction.
+
+This is a brief description of how a PKCS#12 file is represented internally:
+some knowledge of PKCS#12 is assumed.
+
+A PKCS#12 object contains several levels.
+
+At the lowest level is a PKCS12_SAFEBAG. This can contain a certificate, a
+CRL, a private key, encrypted or unencrypted, a set of safebags (so the
+structure can be nested) or other secrets (not documented at present). 
+A safebag can optionally have attributes, currently these are: a unicode
+friendlyName (a Unicode string) or a localKeyID (a string of bytes).
+
+At the next level is an authSafe which is a set of safebags collected into
+a PKCS#7 ContentInfo. This can be just plain data, or encrypted itself.
+
+At the top level is the PKCS12 structure itself which contains a set of
+authSafes in an embedded PKCS#7 Contentinfo of type data. In addition it
+contains a MAC which is a kind of password protected digest to preserve
+integrity (so any unencrypted stuff below can't be tampered with).
+
+The reason for these levels is so various objects can be encrypted in various
+ways. For example you might want to encrypt a set of private keys with
+triple-DES and then include the related certificates either unencrypted or
+with lower encryption. Yes it's the dreaded crypto laws at work again which
+allow strong encryption on private keys and only weak encryption on other
+stuff.
+
+To build one of these things you turn all certificates and keys into safebags
+(with optional attributes). You collect the safebags into (one or more) STACKS
+and convert these into authsafes (encrypted or unencrypted).  The authsafes
+are collected into a STACK and added to a PKCS12 structure.  Finally a MAC
+inserted.
+
+Pulling one apart is basically the reverse process. The MAC is verified against
+the given password. The authsafes are extracted and each authsafe split into
+a set of safebags (possibly involving decryption). Finally the safebags are
+decomposed into the original keys and certificates and the attributes used to
+match up private key and certificate pairs.
+
+Anyway here are the functions that do the dirty work.
+
+1. Construction functions.
+
+1.1 Safebag functions.
+
+M_PKCS12_x5092certbag(x509)
+
+This macro takes an X509 structure and returns a certificate bag. The
+X509 structure can be freed up after calling this function.
+
+M_PKCS12_x509crl2certbag(crl)
+
+As above but for a CRL.
+
+PKCS8_PRIV_KEY_INFO *PKEY2PKCS8(EVP_PKEY *pkey)
+
+Take a private key and convert it into a PKCS#8 PrivateKeyInfo structure.
+Works for both RSA and DSA private keys. NB since the PKCS#8 PrivateKeyInfo
+structure contains a private key data in plain text form it should be free'd
+up as soon as it has been encrypted for security reasons (freeing up the
+structure zeros out the sensitive data). This can be done with
+PKCS8_PRIV_KEY_INFO_free().
+
+PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage)
+
+This sets the key type when a key is imported into MSIE or Outlook 98. Two
+values are currently supported: KEY_EX and KEY_SIG. KEY_EX is an exchange type
+key that can also be used for signing but its size is limited in the export
+versions of MS software to 512 bits, it is also the default. KEY_SIG is a
+signing only key but the keysize is unlimited (well 16K is supposed to work).
+If you are using the domestic version of MSIE then you can ignore this because
+KEY_EX is not limited and can be used for both.
+
+PKCS12_SAFEBAG *PKCS12_MAKE_KEYBAG(PKCS8_PRIV_KEY_INFO *p8)
+
+Convert a PKCS8 private key structure into a keybag. This routine embeds the
+p8 structure in the keybag so p8 should not be freed up or used after it is
+called.  The p8 structure will be freed up when the safebag is freed.
+
+PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8)
+
+Convert a PKCS#8 structure into a shrouded key bag (encrypted). p8 is not
+embedded and can be freed up after use.
+
+int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen)
+int PKCS12_add_friendlyname(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen)
+
+Add a local key id or a friendlyname to a safebag.
+
+1.2 Authsafe functions.
+
+PKCS7 *PKCS12_pack_p7data(STACK *sk)
+Take a stack of safebags and convert them into an unencrypted authsafe. The
+stack of safebags can be freed up after calling this function.
+
+PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, STACK *bags);
+
+As above but encrypted.
+
+1.3 PKCS12 functions.
+
+PKCS12 *PKCS12_init(int mode)
+
+Initialise a PKCS12 structure (currently mode should be NID_pkcs7_data).
+
+M_PKCS12_pack_authsafes(p12, safes)
+
+This macro takes a STACK of authsafes and adds them to a PKCS#12 structure.
+
+int PKCS12_set_mac(PKCS12 *p12, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, EVP_MD *md_type);
+
+Add a MAC to a PKCS12 structure. If EVP_MD is NULL use SHA-1, the spec suggests
+that SHA-1 should be used.
+
+2. Extraction Functions.
+
+2.1 Safebags.
+
+M_PKCS12_bag_type(bag)
+
+Return the type of "bag". Returns one of the following
+
+NID_keyBag
+NID_pkcs8ShroudedKeyBag                        7
+NID_certBag                            8
+NID_crlBag                             9
+NID_secretBag                          10
+NID_safeContentsBag                    11
+
+M_PKCS12_cert_bag_type(bag)
+
+Returns type of certificate bag, following are understood.
+
+NID_x509Certificate                    14
+NID_sdsiCertificate                    15
+
+M_PKCS12_crl_bag_type(bag)
+
+Returns crl bag type, currently only NID_crlBag is recognised.
+
+M_PKCS12_certbag2x509(bag)
+
+This macro extracts an X509 certificate from a certificate bag.
+
+M_PKCS12_certbag2x509crl(bag)
+
+As above but for a CRL.
+
+EVP_PKEY * PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8)
+
+Extract a private key from a PKCS8 private key info structure.
+
+M_PKCS12_decrypt_skey(bag, pass, passlen) 
+
+Decrypt a shrouded key bag and return a PKCS8 private key info structure.
+Works with both RSA and DSA keys
+
+char *PKCS12_get_friendlyname(bag)
+
+Returns the friendlyName of a bag if present or NULL if none. The returned
+string is a null terminated ASCII string allocated with Malloc(). It should 
+thus be freed up with Free() after use.
+
+2.2 AuthSafe functions.
+
+M_PKCS12_unpack_p7data(p7)
+
+Extract a STACK of safe bags from a PKCS#7 data ContentInfo.
+
+#define M_PKCS12_unpack_p7encdata(p7, pass, passlen)
+
+As above but for an encrypted content info.
+
+2.3 PKCS12 functions.
+
+M_PKCS12_unpack_authsafes(p12)
+
+Extract a STACK of authsafes from a PKCS12 structure.
+
+M_PKCS12_mac_present(p12)
+
+Check to see if a MAC is present.
+
+int PKCS12_verify_mac(PKCS12 *p12, unsigned char *pass, int passlen)
+
+Verify a MAC on a PKCS12 structure. Returns an error if MAC not present.
+
+
+Notes.
+
+1. All the function return 0 or NULL on error.
+2. Encryption based functions take a common set of parameters. These are
+described below.
+
+pass, passlen
+ASCII password and length. The password on the MAC is called the "integrity
+password" the encryption password is called the "privacy password" in the
+PKCS#12 documentation. The passwords do not have to be the same. If -1 is
+passed for the length it is worked out by the function itself (currently
+this is sometimes done whatever is passed as the length but that may change).
+
+salt, saltlen
+A 'salt' if salt is NULL a random salt is used. If saltlen is also zero a
+default length is used.
+
+iter
+Iteration count. This is a measure of how many times an internal function is
+called to encrypt the data. The larger this value is the longer it takes, it
+makes dictionary attacks on passwords harder. NOTE: Some implementations do
+not support an iteration count on the MAC. If the password for the MAC and
+encryption is the same then there is no point in having a high iteration
+count for encryption if the MAC has no count. The MAC could be attacked
+and the password used for the main decryption.
+
+pbe_nid
+This is the NID of the password based encryption method used. The following are
+supported.
+NID_pbe_WithSHA1And128BitRC4
+NID_pbe_WithSHA1And40BitRC4
+NID_pbe_WithSHA1And3_Key_TripleDES_CBC
+NID_pbe_WithSHA1And2_Key_TripleDES_CBC
+NID_pbe_WithSHA1And128BitRC2_CBC
+NID_pbe_WithSHA1And40BitRC2_CBC
+
+Which you use depends on the implementation you are exporting to. "Export
+grade" (i.e. cryptographically challenged) products cannot support all
+algorithms. Typically you may be able to use any encryption on shrouded key
+bags but they must then be placed in an unencrypted authsafe. Other authsafes
+may only support 40bit encryption. Of course if you are using SSLeay
+throughout you can strongly encrypt everything and have high iteration counts
+on everything.
+
+3. For decryption routines only the password and length are needed.
+
+4. Unlike the external version the nid's of objects are the values of the
+constants: that is NID_certBag is the real nid, therefore there is no 
+PKCS12_obj_offset() function.  Note the object constants are not the same as
+those of the external version. If you use these constants then you will need
+to recompile your code.
+
+5. With the exception of PKCS12_MAKE_KEYBAG(), after calling any function or 
+macro of the form PKCS12_MAKE_SOMETHING(other) the "other" structure can be
+reused or freed up safely.
+
diff --git a/deps/openssl/openssl/doc/openssl_button.gif b/deps/openssl/openssl/doc/openssl_button.gif
new file mode 100644 (file)
index 0000000..3d3c90c
Binary files /dev/null and b/deps/openssl/openssl/doc/openssl_button.gif differ
diff --git a/deps/openssl/openssl/doc/openssl_button.html b/deps/openssl/openssl/doc/openssl_button.html
new file mode 100644 (file)
index 0000000..44c91bd
--- /dev/null
@@ -0,0 +1,7 @@
+
+<!-- the `Includes OpenSSL Cryptogaphy Software' button      -->
+<!-- freely usable by any application linked against OpenSSL -->
+<a   href="http://www.openssl.org/">
+<img src="openssl_button.gif" 
+     width=102 height=47 border=0></a>
+
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CIPHER_get_name.pod b/deps/openssl/openssl/doc/ssl/SSL_CIPHER_get_name.pod
new file mode 100644 (file)
index 0000000..eb772b5
--- /dev/null
@@ -0,0 +1,112 @@
+=pod
+
+=head1 NAME
+
+SSL_CIPHER_get_name, SSL_CIPHER_get_bits, SSL_CIPHER_get_version, SSL_CIPHER_description - get SSL_CIPHER properties
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ const char *SSL_CIPHER_get_name(const SSL_CIPHER *cipher);
+ int SSL_CIPHER_get_bits(const SSL_CIPHER *cipher, int *alg_bits);
+ char *SSL_CIPHER_get_version(const SSL_CIPHER *cipher);
+ char *SSL_CIPHER_description(const SSL_CIPHER *cipher, char *buf, int size);
+
+=head1 DESCRIPTION
+
+SSL_CIPHER_get_name() returns a pointer to the name of B<cipher>. If the
+argument is the NULL pointer, a pointer to the constant value "NONE" is
+returned.
+
+SSL_CIPHER_get_bits() returns the number of secret bits used for B<cipher>. If
+B<alg_bits> is not NULL, it contains the number of bits processed by the
+chosen algorithm. If B<cipher> is NULL, 0 is returned.
+
+SSL_CIPHER_get_version() returns the protocol version for B<cipher>, currently
+"SSLv2", "SSLv3", or "TLSv1". If B<cipher> is NULL, "(NONE)" is returned.
+
+SSL_CIPHER_description() returns a textual description of the cipher used
+into the buffer B<buf> of length B<len> provided. B<len> must be at least
+128 bytes, otherwise a pointer to the string "Buffer too small" is
+returned. If B<buf> is NULL, a buffer of 128 bytes is allocated using
+OPENSSL_malloc(). If the allocation fails, a pointer to the string
+"OPENSSL_malloc Error" is returned.
+
+=head1 NOTES
+
+The number of bits processed can be different from the secret bits. An
+export cipher like e.g. EXP-RC4-MD5 has only 40 secret bits. The algorithm
+does use the full 128 bits (which would be returned for B<alg_bits>), of
+which however 88bits are fixed. The search space is hence only 40 bits.
+
+The string returned by SSL_CIPHER_description() in case of success consists
+of cleartext information separated by one or more blanks in the following
+sequence:
+
+=over 4
+
+=item <ciphername>
+
+Textual representation of the cipher name.
+
+=item <protocol version>
+
+Protocol version: B<SSLv2>, B<SSLv3>. The TLSv1 ciphers are flagged with SSLv3.
+
+=item Kx=<key exchange>
+
+Key exchange method: B<RSA> (for export ciphers as B<RSA(512)> or
+B<RSA(1024)>), B<DH> (for export ciphers as B<DH(512)> or B<DH(1024)>),
+B<DH/RSA>, B<DH/DSS>, B<Fortezza>.
+
+=item Au=<authentication>
+
+Authentication method: B<RSA>, B<DSS>, B<DH>, B<None>. None is the
+representation of anonymous ciphers.
+
+=item Enc=<symmetric encryption method>
+
+Encryption method with number of secret bits: B<DES(40)>, B<DES(56)>,
+B<3DES(168)>, B<RC4(40)>, B<RC4(56)>, B<RC4(64)>, B<RC4(128)>,
+B<RC2(40)>, B<RC2(56)>, B<RC2(128)>, B<IDEA(128)>, B<Fortezza>, B<None>.
+
+=item Mac=<message authentication code>
+
+Message digest: B<MD5>, B<SHA1>.
+
+=item <export flag>
+
+If the cipher is flagged exportable with respect to old US crypto
+regulations, the word "B<export>" is printed.
+
+=back
+
+=head1 EXAMPLES
+
+Some examples for the output of SSL_CIPHER_description():
+
+ EDH-RSA-DES-CBC3-SHA    SSLv3 Kx=DH       Au=RSA  Enc=3DES(168) Mac=SHA1
+ EDH-DSS-DES-CBC3-SHA    SSLv3 Kx=DH       Au=DSS  Enc=3DES(168) Mac=SHA1
+ RC4-MD5                 SSLv3 Kx=RSA      Au=RSA  Enc=RC4(128)  Mac=MD5
+ EXP-RC4-MD5             SSLv3 Kx=RSA(512) Au=RSA  Enc=RC4(40)   Mac=MD5  export
+
+=head1 BUGS
+
+If SSL_CIPHER_description() is called with B<cipher> being NULL, the
+library crashes.
+
+If SSL_CIPHER_description() cannot handle a built-in cipher, the according
+description of the cipher property is B<unknown>. This case should not
+occur.
+
+=head1 RETURN VALUES
+
+See DESCRIPTION
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_get_current_cipher(3)|SSL_get_current_cipher(3)>,
+L<SSL_get_ciphers(3)|SSL_get_ciphers(3)>, L<ciphers(1)|ciphers(1)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_COMP_add_compression_method.pod b/deps/openssl/openssl/doc/ssl/SSL_COMP_add_compression_method.pod
new file mode 100644 (file)
index 0000000..42fa66b
--- /dev/null
@@ -0,0 +1,70 @@
+=pod
+
+=head1 NAME
+
+SSL_COMP_add_compression_method - handle SSL/TLS integrated compression methods
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm);
+
+=head1 DESCRIPTION
+
+SSL_COMP_add_compression_method() adds the compression method B<cm> with
+the identifier B<id> to the list of available compression methods. This
+list is globally maintained for all SSL operations within this application.
+It cannot be set for specific SSL_CTX or SSL objects.
+
+=head1 NOTES
+
+The TLS standard (or SSLv3) allows the integration of compression methods
+into the communication. The TLS RFC does however not specify compression
+methods or their corresponding identifiers, so there is currently no compatible
+way to integrate compression with unknown peers. It is therefore currently not
+recommended to integrate compression into applications. Applications for
+non-public use may agree on certain compression methods. Using different
+compression methods with the same identifier will lead to connection failure.
+
+An OpenSSL client speaking a protocol that allows compression (SSLv3, TLSv1)
+will unconditionally send the list of all compression methods enabled with
+SSL_COMP_add_compression_method() to the server during the handshake.
+Unlike the mechanisms to set a cipher list, there is no method available to
+restrict the list of compression method on a per connection basis.
+
+An OpenSSL server will match the identifiers listed by a client against
+its own compression methods and will unconditionally activate compression
+when a matching identifier is found. There is no way to restrict the list
+of compression methods supported on a per connection basis.
+
+The OpenSSL library has the compression methods B<COMP_rle()> and (when
+especially enabled during compilation) B<COMP_zlib()> available.
+
+=head1 WARNINGS
+
+Once the identities of the compression methods for the TLS protocol have
+been standardized, the compression API will most likely be changed. Using
+it in the current state is not recommended.
+
+=head1 RETURN VALUES
+
+SSL_COMP_add_compression_method() may return the following values:
+
+=over 4
+
+=item 0
+
+The operation succeeded.
+
+=item 1
+
+The operation failed. Check the error queue to find out the reason.
+
+=back
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_add_extra_chain_cert.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_add_extra_chain_cert.pod
new file mode 100644 (file)
index 0000000..ee28f5c
--- /dev/null
@@ -0,0 +1,39 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_add_extra_chain_cert - add certificate to chain
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ long SSL_CTX_add_extra_chain_cert(SSL_CTX ctx, X509 *x509)
+
+=head1 DESCRIPTION
+
+SSL_CTX_add_extra_chain_cert() adds the certificate B<x509> to the certificate
+chain presented together with the certificate. Several certificates
+can be added one after the other.
+
+=head1 NOTES
+
+When constructing the certificate chain, the chain will be formed from
+these certificates explicitly specified. If no chain is specified,
+the library will try to complete the chain from the available CA
+certificates in the trusted CA storage, see
+L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>.
+
+=head1 RETURN VALUES
+
+SSL_CTX_add_extra_chain_cert() returns 1 on success. Check out the
+error stack to find out the reason for failure otherwise.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>,
+L<SSL_CTX_use_certificate(3)|SSL_CTX_use_certificate(3)>,
+L<SSL_CTX_set_client_cert_cb(3)|SSL_CTX_set_client_cert_cb(3)>,
+L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_add_session.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_add_session.pod
new file mode 100644 (file)
index 0000000..82676b2
--- /dev/null
@@ -0,0 +1,73 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_add_session, SSL_add_session, SSL_CTX_remove_session, SSL_remove_session - manipulate session cache
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *c);
+ int SSL_add_session(SSL_CTX *ctx, SSL_SESSION *c);
+
+ int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c);
+ int SSL_remove_session(SSL_CTX *ctx, SSL_SESSION *c);
+
+=head1 DESCRIPTION
+
+SSL_CTX_add_session() adds the session B<c> to the context B<ctx>. The
+reference count for session B<c> is incremented by 1. If a session with
+the same session id already exists, the old session is removed by calling
+L<SSL_SESSION_free(3)|SSL_SESSION_free(3)>.
+
+SSL_CTX_remove_session() removes the session B<c> from the context B<ctx>.
+L<SSL_SESSION_free(3)|SSL_SESSION_free(3)> is called once for B<c>.
+
+SSL_add_session() and SSL_remove_session() are synonyms for their
+SSL_CTX_*() counterparts.
+
+=head1 NOTES
+
+When adding a new session to the internal session cache, it is examined
+whether a session with the same session id already exists. In this case
+it is assumed that both sessions are identical. If the same session is
+stored in a different SSL_SESSION object, The old session is
+removed and replaced by the new session. If the session is actually
+identical (the SSL_SESSION object is identical), SSL_CTX_add_session()
+is a no-op, and the return value is 0.
+
+If a server SSL_CTX is configured with the SSL_SESS_CACHE_NO_INTERNAL_STORE
+flag then the internal cache will not be populated automatically by new
+sessions negotiated by the SSL/TLS implementation, even though the internal
+cache will be searched automatically for session-resume requests (the
+latter can be surpressed by SSL_SESS_CACHE_NO_INTERNAL_LOOKUP). So the
+application can use SSL_CTX_add_session() directly to have full control
+over the sessions that can be resumed if desired.
+
+
+=head1 RETURN VALUES
+
+The following values are returned by all functions:
+
+=over 4
+
+=item 0
+
+ The operation failed. In case of the add operation, it was tried to add
+ the same (identical) session twice. In case of the remove operation, the
+ session was not found in the cache.
+
+=item 1
+ The operation succeeded.
+
+=back
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>,
+L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>,
+L<SSL_SESSION_free(3)|SSL_SESSION_free(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_ctrl.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_ctrl.pod
new file mode 100644 (file)
index 0000000..fb6adcf
--- /dev/null
@@ -0,0 +1,34 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_ctrl, SSL_CTX_callback_ctrl, SSL_ctrl, SSL_callback_ctrl - internal handling functions for SSL_CTX and SSL objects
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ long SSL_CTX_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg);
+ long SSL_CTX_callback_ctrl(SSL_CTX *, int cmd, void (*fp)());
+
+ long SSL_ctrl(SSL *ssl, int cmd, long larg, void *parg);
+ long SSL_callback_ctrl(SSL *, int cmd, void (*fp)());
+
+=head1 DESCRIPTION
+
+The SSL_*_ctrl() family of functions is used to manipulate settings of
+the SSL_CTX and SSL objects. Depending on the command B<cmd> the arguments
+B<larg>, B<parg>, or B<fp> are evaluated. These functions should never
+be called directly. All functionalities needed are made available via
+other functions or macros.
+
+=head1 RETURN VALUES
+
+The return values of the SSL*_ctrl() functions depend on the command
+supplied via the B<cmd> parameter.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_flush_sessions.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_flush_sessions.pod
new file mode 100644 (file)
index 0000000..148c36c
--- /dev/null
@@ -0,0 +1,49 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_flush_sessions, SSL_flush_sessions - remove expired sessions
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ void SSL_CTX_flush_sessions(SSL_CTX *ctx, long tm);
+ void SSL_flush_sessions(SSL_CTX *ctx, long tm);
+
+=head1 DESCRIPTION
+
+SSL_CTX_flush_sessions() causes a run through the session cache of
+B<ctx> to remove sessions expired at time B<tm>.
+
+SSL_flush_sessions() is a synonym for SSL_CTX_flush_sessions().
+
+=head1 NOTES
+
+If enabled, the internal session cache will collect all sessions established
+up to the specified maximum number (see SSL_CTX_sess_set_cache_size()).
+As sessions will not be reused ones they are expired, they should be
+removed from the cache to save resources. This can either be done
+ automatically whenever 255 new sessions were established (see
+L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>)
+or manually by calling SSL_CTX_flush_sessions(). 
+
+The parameter B<tm> specifies the time which should be used for the
+expiration test, in most cases the actual time given by time(0)
+will be used.
+
+SSL_CTX_flush_sessions() will only check sessions stored in the internal
+cache. When a session is found and removed, the remove_session_cb is however
+called to synchronize with the external cache (see
+L<SSL_CTX_sess_set_get_cb(3)|SSL_CTX_sess_set_get_cb(3)>).
+
+=head1 RETURN VALUES
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>,
+L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>,
+L<SSL_CTX_set_timeout(3)|SSL_CTX_set_timeout(3)>,
+L<SSL_CTX_sess_set_get_cb(3)|SSL_CTX_sess_set_get_cb(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_free.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_free.pod
new file mode 100644 (file)
index 0000000..51d8676
--- /dev/null
@@ -0,0 +1,41 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_free - free an allocated SSL_CTX object
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ void SSL_CTX_free(SSL_CTX *ctx);
+
+=head1 DESCRIPTION
+
+SSL_CTX_free() decrements the reference count of B<ctx>, and removes the
+SSL_CTX object pointed to by B<ctx> and frees up the allocated memory if the
+the reference count has reached 0.
+
+It also calls the free()ing procedures for indirectly affected items, if
+applicable: the session cache, the list of ciphers, the list of Client CAs,
+the certificates and keys.
+
+=head1 WARNINGS
+
+If a session-remove callback is set (SSL_CTX_sess_set_remove_cb()), this
+callback will be called for each session being freed from B<ctx>'s
+session cache. This implies, that all corresponding sessions from an
+external session cache are removed as well. If this is not desired, the user
+should explicitly unset the callback by calling
+SSL_CTX_sess_set_remove_cb(B<ctx>, NULL) prior to calling SSL_CTX_free().
+
+=head1 RETURN VALUES
+
+SSL_CTX_free() does not provide diagnostic information.
+
+=head1 SEE ALSO
+
+L<SSL_CTX_new(3)|SSL_CTX_new(3)>, L<ssl(3)|ssl(3)>,
+L<SSL_CTX_sess_set_get_cb(3)|SSL_CTX_sess_set_get_cb(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_get_ex_new_index.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_get_ex_new_index.pod
new file mode 100644 (file)
index 0000000..0c40a91
--- /dev/null
@@ -0,0 +1,53 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_get_ex_new_index, SSL_CTX_set_ex_data, SSL_CTX_get_ex_data - internal application specific data functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_CTX_get_ex_new_index(long argl, void *argp,
+                CRYPTO_EX_new *new_func,
+                CRYPTO_EX_dup *dup_func,
+                CRYPTO_EX_free *free_func);
+
+ int SSL_CTX_set_ex_data(SSL_CTX *ctx, int idx, void *arg);
+
+ void *SSL_CTX_get_ex_data(const SSL_CTX *ctx, int idx);
+
+ typedef int new_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
+                int idx, long argl, void *argp);
+ typedef void free_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
+                int idx, long argl, void *argp);
+ typedef int dup_func(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d,
+                int idx, long argl, void *argp);
+
+=head1 DESCRIPTION
+
+Several OpenSSL structures can have application specific data attached to them.
+These functions are used internally by OpenSSL to manipulate application
+specific data attached to a specific structure.
+
+SSL_CTX_get_ex_new_index() is used to register a new index for application
+specific data.
+
+SSL_CTX_set_ex_data() is used to store application data at B<arg> for B<idx>
+into the B<ctx> object.
+
+SSL_CTX_get_ex_data() is used to retrieve the information for B<idx> from
+B<ctx>.
+
+A detailed description for the B<*_get_ex_new_index()> functionality
+can be found in L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>.
+The B<*_get_ex_data()> and B<*_set_ex_data()> functionality is described in
+L<CRYPTO_set_ex_data(3)|CRYPTO_set_ex_data(3)>.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>,
+L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>,
+L<CRYPTO_set_ex_data(3)|CRYPTO_set_ex_data(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_get_verify_mode.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_get_verify_mode.pod
new file mode 100644 (file)
index 0000000..2a3747e
--- /dev/null
@@ -0,0 +1,50 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_get_verify_mode, SSL_get_verify_mode, SSL_CTX_get_verify_depth, SSL_get_verify_depth, SSL_get_verify_callback, SSL_CTX_get_verify_callback - get currently set verification parameters
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_CTX_get_verify_mode(const SSL_CTX *ctx);
+ int SSL_get_verify_mode(const SSL *ssl);
+ int SSL_CTX_get_verify_depth(const SSL_CTX *ctx);
+ int SSL_get_verify_depth(const SSL *ssl);
+ int (*SSL_CTX_get_verify_callback(const SSL_CTX *ctx))(int, X509_STORE_CTX *);
+ int (*SSL_get_verify_callback(const SSL *ssl))(int, X509_STORE_CTX *);
+
+=head1 DESCRIPTION
+
+SSL_CTX_get_verify_mode() returns the verification mode currently set in
+B<ctx>.
+
+SSL_get_verify_mode() returns the verification mode currently set in
+B<ssl>.
+
+SSL_CTX_get_verify_depth() returns the verification depth limit currently set
+in B<ctx>. If no limit has been explicitly set, -1 is returned and the
+default value will be used.
+
+SSL_get_verify_depth() returns the verification depth limit currently set
+in B<ssl>. If no limit has been explicitly set, -1 is returned and the
+default value will be used.
+
+SSL_CTX_get_verify_callback() returns a function pointer to the verification
+callback currently set in B<ctx>. If no callback was explicitly set, the
+NULL pointer is returned and the default callback will be used.
+
+SSL_get_verify_callback() returns a function pointer to the verification
+callback currently set in B<ssl>. If no callback was explicitly set, the
+NULL pointer is returned and the default callback will be used.
+
+=head1 RETURN VALUES
+
+See DESCRIPTION
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_load_verify_locations.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_load_verify_locations.pod
new file mode 100644 (file)
index 0000000..84a799f
--- /dev/null
@@ -0,0 +1,124 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_load_verify_locations - set default locations for trusted CA
+certificates
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
+                                   const char *CApath);
+
+=head1 DESCRIPTION
+
+SSL_CTX_load_verify_locations() specifies the locations for B<ctx>, at
+which CA certificates for verification purposes are located. The certificates
+available via B<CAfile> and B<CApath> are trusted.
+
+=head1 NOTES
+
+If B<CAfile> is not NULL, it points to a file of CA certificates in PEM
+format. The file can contain several CA certificates identified by
+
+ -----BEGIN CERTIFICATE-----
+ ... (CA certificate in base64 encoding) ...
+ -----END CERTIFICATE-----
+
+sequences. Before, between, and after the certificates text is allowed
+which can be used e.g. for descriptions of the certificates.
+
+The B<CAfile> is processed on execution of the SSL_CTX_load_verify_locations()
+function.
+
+If B<CApath> is not NULL, it points to a directory containing CA certificates
+in PEM format. The files each contain one CA certificate. The files are
+looked up by the CA subject name hash value, which must hence be available.
+If more than one CA certificate with the same name hash value exist, the
+extension must be different (e.g. 9d66eef0.0, 9d66eef0.1 etc). The search
+is performed in the ordering of the extension number, regardless of other
+properties of the certificates.
+Use the B<c_rehash> utility to create the necessary links.
+
+The certificates in B<CApath> are only looked up when required, e.g. when
+building the certificate chain or when actually performing the verification
+of a peer certificate.
+
+When looking up CA certificates, the OpenSSL library will first search the
+certificates in B<CAfile>, then those in B<CApath>. Certificate matching
+is done based on the subject name, the key identifier (if present), and the
+serial number as taken from the certificate to be verified. If these data
+do not match, the next certificate will be tried. If a first certificate
+matching the parameters is found, the verification process will be performed;
+no other certificates for the same parameters will be searched in case of
+failure.
+
+In server mode, when requesting a client certificate, the server must send
+the list of CAs of which it will accept client certificates. This list
+is not influenced by the contents of B<CAfile> or B<CApath> and must
+explicitly be set using the
+L<SSL_CTX_set_client_CA_list(3)|SSL_CTX_set_client_CA_list(3)>
+family of functions.
+
+When building its own certificate chain, an OpenSSL client/server will
+try to fill in missing certificates from B<CAfile>/B<CApath>, if the
+certificate chain was not explicitly specified (see
+L<SSL_CTX_add_extra_chain_cert(3)|SSL_CTX_add_extra_chain_cert(3)>,
+L<SSL_CTX_use_certificate(3)|SSL_CTX_use_certificate(3)>.
+
+=head1 WARNINGS
+
+If several CA certificates matching the name, key identifier, and serial
+number condition are available, only the first one will be examined. This
+may lead to unexpected results if the same CA certificate is available
+with different expiration dates. If a "certificate expired" verification
+error occurs, no other certificate will be searched. Make sure to not
+have expired certificates mixed with valid ones.
+
+=head1 EXAMPLES
+
+Generate a CA certificate file with descriptive text from the CA certificates
+ca1.pem ca2.pem ca3.pem:
+
+ #!/bin/sh
+ rm CAfile.pem
+ for i in ca1.pem ca2.pem ca3.pem ; do
+   openssl x509 -in $i -text >> CAfile.pem
+ done
+
+Prepare the directory /some/where/certs containing several CA certificates
+for use as B<CApath>:
+
+ cd /some/where/certs
+ c_rehash .
+
+=head1 RETURN VALUES
+
+The following return values can occur:
+
+=over 4
+
+=item 0
+
+The operation failed because B<CAfile> and B<CApath> are NULL or the
+processing at one of the locations specified failed. Check the error
+stack to find out the reason.
+
+=item 1
+
+The operation succeeded.
+
+=back
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>,
+L<SSL_CTX_set_client_CA_list(3)|SSL_CTX_set_client_CA_list(3)>,
+L<SSL_get_client_CA_list(3)|SSL_get_client_CA_list(3)>,
+L<SSL_CTX_use_certificate(3)|SSL_CTX_use_certificate(3)>,
+L<SSL_CTX_add_extra_chain_cert(3)|SSL_CTX_add_extra_chain_cert(3)>,
+L<SSL_CTX_set_cert_store(3)|SSL_CTX_set_cert_store(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_new.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_new.pod
new file mode 100644 (file)
index 0000000..73e8c47
--- /dev/null
@@ -0,0 +1,94 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_new - create a new SSL_CTX object as framework for TLS/SSL enabled functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ SSL_CTX *SSL_CTX_new(const SSL_METHOD *method);
+
+=head1 DESCRIPTION
+
+SSL_CTX_new() creates a new B<SSL_CTX> object as framework to establish
+TLS/SSL enabled connections.
+
+=head1 NOTES
+
+The SSL_CTX object uses B<method> as connection method. The methods exist
+in a generic type (for client and server use), a server only type, and a
+client only type. B<method> can be of the following types:
+
+=over 4
+
+=item SSLv2_method(void), SSLv2_server_method(void), SSLv2_client_method(void)
+
+A TLS/SSL connection established with these methods will only understand
+the SSLv2 protocol. A client will send out SSLv2 client hello messages
+and will also indicate that it only understand SSLv2. A server will only
+understand SSLv2 client hello messages.
+
+=item SSLv3_method(void), SSLv3_server_method(void), SSLv3_client_method(void)
+
+A TLS/SSL connection established with these methods will only understand the
+SSLv3 protocol. A client will send out SSLv3 client hello messages
+and will indicate that it only understands SSLv3. A server will only understand
+SSLv3 client hello messages. This especially means, that it will
+not understand SSLv2 client hello messages which are widely used for
+compatibility reasons, see SSLv23_*_method().
+
+=item TLSv1_method(void), TLSv1_server_method(void), TLSv1_client_method(void)
+
+A TLS/SSL connection established with these methods will only understand the
+TLSv1 protocol. A client will send out TLSv1 client hello messages
+and will indicate that it only understands TLSv1. A server will only understand
+TLSv1 client hello messages. This especially means, that it will
+not understand SSLv2 client hello messages which are widely used for
+compatibility reasons, see SSLv23_*_method(). It will also not understand
+SSLv3 client hello messages.
+
+=item SSLv23_method(void), SSLv23_server_method(void), SSLv23_client_method(void)
+
+A TLS/SSL connection established with these methods will understand the SSLv2,
+SSLv3, and TLSv1 protocol. A client will send out SSLv2 client hello messages
+and will indicate that it also understands SSLv3 and TLSv1. A server will
+understand SSLv2, SSLv3, and TLSv1 client hello messages. This is the best
+choice when compatibility is a concern.
+
+=back
+
+The list of protocols available can later be limited using the SSL_OP_NO_SSLv2,
+SSL_OP_NO_SSLv3, SSL_OP_NO_TLSv1 options of the B<SSL_CTX_set_options()> or
+B<SSL_set_options()> functions. Using these options it is possible to choose
+e.g. SSLv23_server_method() and be able to negotiate with all possible
+clients, but to only allow newer protocols like SSLv3 or TLSv1.
+
+SSL_CTX_new() initializes the list of ciphers, the session cache setting,
+the callbacks, the keys and certificates, and the options to its default
+values.
+
+=head1 RETURN VALUES
+
+The following return values can occur:
+
+=over 4
+
+=item NULL
+
+The creation of a new SSL_CTX object failed. Check the error stack to
+find out the reason.
+
+=item Pointer to an SSL_CTX object
+
+The return value points to an allocated SSL_CTX object.
+
+=back
+
+=head1 SEE ALSO
+
+L<SSL_CTX_free(3)|SSL_CTX_free(3)>, L<SSL_accept(3)|SSL_accept(3)>,
+L<ssl(3)|ssl(3)>,  L<SSL_set_connect_state(3)|SSL_set_connect_state(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_sess_number.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_sess_number.pod
new file mode 100644 (file)
index 0000000..19aa4e2
--- /dev/null
@@ -0,0 +1,76 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_sess_number, SSL_CTX_sess_connect, SSL_CTX_sess_connect_good, SSL_CTX_sess_connect_renegotiate, SSL_CTX_sess_accept, SSL_CTX_sess_accept_good, SSL_CTX_sess_accept_renegotiate, SSL_CTX_sess_hits, SSL_CTX_sess_cb_hits, SSL_CTX_sess_misses, SSL_CTX_sess_timeouts, SSL_CTX_sess_cache_full - obtain session cache statistics
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ long SSL_CTX_sess_number(SSL_CTX *ctx);
+ long SSL_CTX_sess_connect(SSL_CTX *ctx);
+ long SSL_CTX_sess_connect_good(SSL_CTX *ctx);
+ long SSL_CTX_sess_connect_renegotiate(SSL_CTX *ctx);
+ long SSL_CTX_sess_accept(SSL_CTX *ctx);
+ long SSL_CTX_sess_accept_good(SSL_CTX *ctx);
+ long SSL_CTX_sess_accept_renegotiate(SSL_CTX *ctx);
+ long SSL_CTX_sess_hits(SSL_CTX *ctx);
+ long SSL_CTX_sess_cb_hits(SSL_CTX *ctx);
+ long SSL_CTX_sess_misses(SSL_CTX *ctx);
+ long SSL_CTX_sess_timeouts(SSL_CTX *ctx);
+ long SSL_CTX_sess_cache_full(SSL_CTX *ctx);
+
+=head1 DESCRIPTION
+
+SSL_CTX_sess_number() returns the current number of sessions in the internal
+session cache.
+
+SSL_CTX_sess_connect() returns the number of started SSL/TLS handshakes in
+client mode.
+
+SSL_CTX_sess_connect_good() returns the number of successfully established
+SSL/TLS sessions in client mode.
+
+SSL_CTX_sess_connect_renegotiate() returns the number of start renegotiations
+in client mode.
+
+SSL_CTX_sess_accept() returns the number of started SSL/TLS handshakes in
+server mode.
+
+SSL_CTX_sess_accept_good() returns the number of successfully established
+SSL/TLS sessions in server mode.
+
+SSL_CTX_sess_accept_renegotiate() returns the number of start renegotiations
+in server mode.
+
+SSL_CTX_sess_hits() returns the number of successfully reused sessions.
+In client mode a session set with L<SSL_set_session(3)|SSL_set_session(3)>
+successfully reused is counted as a hit. In server mode a session successfully
+retrieved from internal or external cache is counted as a hit.
+
+SSL_CTX_sess_cb_hits() returns the number of successfully retrieved sessions
+from the external session cache in server mode.
+
+SSL_CTX_sess_misses() returns the number of sessions proposed by clients
+that were not found in the internal session cache in server mode.
+
+SSL_CTX_sess_timeouts() returns the number of sessions proposed by clients
+and either found in the internal or external session cache in server mode,
+ but that were invalid due to timeout. These sessions are not included in
+the SSL_CTX_sess_hits() count.
+
+SSL_CTX_sess_cache_full() returns the number of sessions that were removed
+because the maximum session cache size was exceeded.
+
+=head1 RETURN VALUES
+
+The functions return the values indicated in the DESCRIPTION section.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_set_session(3)|SSL_set_session(3)>,
+L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>
+L<SSL_CTX_sess_set_cache_size(3)|SSL_CTX_sess_set_cache_size(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_sess_set_cache_size.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_sess_set_cache_size.pod
new file mode 100644 (file)
index 0000000..c8b99f4
--- /dev/null
@@ -0,0 +1,51 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_sess_set_cache_size, SSL_CTX_sess_get_cache_size - manipulate session cache size
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ long SSL_CTX_sess_set_cache_size(SSL_CTX *ctx, long t);
+ long SSL_CTX_sess_get_cache_size(SSL_CTX *ctx);
+
+=head1 DESCRIPTION
+
+SSL_CTX_sess_set_cache_size() sets the size of the internal session cache
+of context B<ctx> to B<t>.
+
+SSL_CTX_sess_get_cache_size() returns the currently valid session cache size.
+
+=head1 NOTES
+
+The internal session cache size is SSL_SESSION_CACHE_MAX_SIZE_DEFAULT,
+currently 1024*20, so that up to 20000 sessions can be held. This size
+can be modified using the SSL_CTX_sess_set_cache_size() call. A special
+case is the size 0, which is used for unlimited size.
+
+When the maximum number of sessions is reached, no more new sessions are
+added to the cache. New space may be added by calling
+L<SSL_CTX_flush_sessions(3)|SSL_CTX_flush_sessions(3)> to remove
+expired sessions.
+
+If the size of the session cache is reduced and more sessions are already
+in the session cache, old session will be removed at the next time a
+session shall be added. This removal is not synchronized with the
+expiration of sessions.
+
+=head1 RETURN VALUES
+
+SSL_CTX_sess_set_cache_size() returns the previously valid size.
+
+SSL_CTX_sess_get_cache_size() returns the currently valid size.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>,
+L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>,
+L<SSL_CTX_sess_number(3)|SSL_CTX_sess_number(3)>,
+L<SSL_CTX_flush_sessions(3)|SSL_CTX_flush_sessions(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_sess_set_get_cb.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_sess_set_get_cb.pod
new file mode 100644 (file)
index 0000000..b9d54a4
--- /dev/null
@@ -0,0 +1,87 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_sess_set_new_cb, SSL_CTX_sess_set_remove_cb, SSL_CTX_sess_set_get_cb, SSL_CTX_sess_get_new_cb, SSL_CTX_sess_get_remove_cb, SSL_CTX_sess_get_get_cb - provide callback functions for server side external session caching
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ void SSL_CTX_sess_set_new_cb(SSL_CTX *ctx,
+                             int (*new_session_cb)(SSL *, SSL_SESSION *));
+ void SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx,
+          void (*remove_session_cb)(SSL_CTX *ctx, SSL_SESSION *));
+ void SSL_CTX_sess_set_get_cb(SSL_CTX *ctx,
+          SSL_SESSION (*get_session_cb)(SSL *, unsigned char *, int, int *));
+
+ int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx))(struct ssl_st *ssl, SSL_SESSION *sess);
+ void (*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx))(struct ssl_ctx_st *ctx, SSL_SESSION *sess);
+ SSL_SESSION *(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx))(struct ssl_st *ssl, unsigned char *data, int len, int *copy);
+
+ int (*new_session_cb)(struct ssl_st *ssl, SSL_SESSION *sess);
+ void (*remove_session_cb)(struct ssl_ctx_st *ctx, SSL_SESSION *sess);
+ SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl, unsigned char *data,
+              int len, int *copy);
+
+=head1 DESCRIPTION
+
+SSL_CTX_sess_set_new_cb() sets the callback function, which is automatically
+called whenever a new session was negotiated.
+
+SSL_CTX_sess_set_remove_cb() sets the callback function, which is
+automatically called whenever a session is removed by the SSL engine,
+because it is considered faulty or the session has become obsolete because
+of exceeding the timeout value.
+
+SSL_CTX_sess_set_get_cb() sets the callback function which is called,
+whenever a SSL/TLS client proposed to resume a session but the session
+could not be found in the internal session cache (see
+L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>).
+(SSL/TLS server only.)
+
+SSL_CTX_sess_get_new_cb(), SSL_CTX_sess_get_remove_cb(), and
+SSL_CTX_sess_get_get_cb() allow to retrieve the function pointers of the
+provided callback functions. If a callback function has not been set,
+the NULL pointer is returned.
+
+=head1 NOTES
+
+In order to allow external session caching, synchronization with the internal
+session cache is realized via callback functions. Inside these callback
+functions, session can be saved to disk or put into a database using the
+L<d2i_SSL_SESSION(3)|d2i_SSL_SESSION(3)> interface.
+
+The new_session_cb() is called, whenever a new session has been negotiated
+and session caching is enabled (see
+L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>).
+The new_session_cb() is passed the B<ssl> connection and the ssl session
+B<sess>. If the callback returns B<0>, the session will be immediately
+removed again.
+
+The remove_session_cb() is called, whenever the SSL engine removes a session
+from the internal cache. This happens when the session is removed because
+it is expired or when a connection was not shutdown cleanly. It also happens
+for all sessions in the internal session cache when
+L<SSL_CTX_free(3)|SSL_CTX_free(3)> is called. The remove_session_cb() is passed
+the B<ctx> and the ssl session B<sess>. It does not provide any feedback.
+
+The get_session_cb() is only called on SSL/TLS servers with the session id
+proposed by the client. The get_session_cb() is always called, also when
+session caching was disabled. The get_session_cb() is passed the
+B<ssl> connection, the session id of length B<length> at the memory location
+B<data>. With the parameter B<copy> the callback can require the
+SSL engine to increment the reference count of the SSL_SESSION object,
+Normally the reference count is not incremented and therefore the
+session must not be explicitly freed with
+L<SSL_SESSION_free(3)|SSL_SESSION_free(3)>.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<d2i_SSL_SESSION(3)|d2i_SSL_SESSION(3)>,
+L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>,
+L<SSL_CTX_flush_sessions(3)|SSL_CTX_flush_sessions(3)>,
+L<SSL_SESSION_free(3)|SSL_SESSION_free(3)>,
+L<SSL_CTX_free(3)|SSL_CTX_free(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_sessions.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_sessions.pod
new file mode 100644 (file)
index 0000000..e05aab3
--- /dev/null
@@ -0,0 +1,34 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_sessions - access internal session cache
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx);
+
+=head1 DESCRIPTION
+
+SSL_CTX_sessions() returns a pointer to the lhash databases containing the
+internal session cache for B<ctx>.
+
+=head1 NOTES
+
+The sessions in the internal session cache are kept in an
+L<lhash(3)|lhash(3)> type database. It is possible to directly
+access this database e.g. for searching. In parallel, the sessions
+form a linked list which is maintained separately from the
+L<lhash(3)|lhash(3)> operations, so that the database must not be
+modified directly but by using the
+L<SSL_CTX_add_session(3)|SSL_CTX_add_session(3)> family of functions.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<lhash(3)|lhash(3)>,
+L<SSL_CTX_add_session(3)|SSL_CTX_add_session(3)>,
+L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_set_cert_store.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_set_cert_store.pod
new file mode 100644 (file)
index 0000000..6acf0d9
--- /dev/null
@@ -0,0 +1,57 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_set_cert_store, SSL_CTX_get_cert_store - manipulate X509 certificate verification storage
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ void SSL_CTX_set_cert_store(SSL_CTX *ctx, X509_STORE *store);
+ X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *ctx);
+
+=head1 DESCRIPTION
+
+SSL_CTX_set_cert_store() sets/replaces the certificate verification storage
+of B<ctx> to/with B<store>. If another X509_STORE object is currently
+set in B<ctx>, it will be X509_STORE_free()ed.
+
+SSL_CTX_get_cert_store() returns a pointer to the current certificate
+verification storage.
+
+=head1 NOTES
+
+In order to verify the certificates presented by the peer, trusted CA
+certificates must be accessed. These CA certificates are made available
+via lookup methods, handled inside the X509_STORE. From the X509_STORE
+the X509_STORE_CTX used when verifying certificates is created.
+
+Typically the trusted certificate store is handled indirectly via using
+L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>.
+Using the SSL_CTX_set_cert_store() and SSL_CTX_get_cert_store() functions
+it is possible to manipulate the X509_STORE object beyond the
+L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>
+call.
+
+Currently no detailed documentation on how to use the X509_STORE
+object is available. Not all members of the X509_STORE are used when
+the verification takes place. So will e.g. the verify_callback() be
+overridden with the verify_callback() set via the
+L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)> family of functions.
+This document must therefore be updated when documentation about the
+X509_STORE object and its handling becomes available.
+
+=head1 RETURN VALUES
+
+SSL_CTX_set_cert_store() does not return diagnostic output.
+
+SSL_CTX_get_cert_store() returns the current setting.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>,
+L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>,
+L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_set_cert_verify_callback.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_set_cert_verify_callback.pod
new file mode 100644 (file)
index 0000000..c0f4f85
--- /dev/null
@@ -0,0 +1,75 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_set_cert_verify_callback - set peer certificate verification procedure
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, int (*callback)(X509_STORE_CTX *,void *), void *arg);
+
+=head1 DESCRIPTION
+
+SSL_CTX_set_cert_verify_callback() sets the verification callback function for
+I<ctx>. SSL objects that are created from I<ctx> inherit the setting valid at
+the time when L<SSL_new(3)|SSL_new(3)> is called.
+
+=head1 NOTES
+
+Whenever a certificate is verified during a SSL/TLS handshake, a verification
+function is called. If the application does not explicitly specify a
+verification callback function, the built-in verification function is used.
+If a verification callback I<callback> is specified via
+SSL_CTX_set_cert_verify_callback(), the supplied callback function is called
+instead. By setting I<callback> to NULL, the default behaviour is restored.
+
+When the verification must be performed, I<callback> will be called with
+the arguments callback(X509_STORE_CTX *x509_store_ctx, void *arg). The 
+argument I<arg> is specified by the application when setting I<callback>.
+
+I<callback> should return 1 to indicate verification success and 0 to
+indicate verification failure. If SSL_VERIFY_PEER is set and I<callback>
+returns 0, the handshake will fail. As the verification procedure may
+allow to continue the connection in case of failure (by always returning 1)
+the verification result must be set in any case using the B<error>
+member of I<x509_store_ctx> so that the calling application will be informed
+about the detailed result of the verification procedure! 
+
+Within I<x509_store_ctx>, I<callback> has access to the I<verify_callback>
+function set using L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>.
+
+=head1 WARNINGS
+
+Do not mix the verification callback described in this function with the
+B<verify_callback> function called during the verification process. The
+latter is set using the L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>
+family of functions.
+
+Providing a complete verification procedure including certificate purpose
+settings etc is a complex task. The built-in procedure is quite powerful
+and in most cases it should be sufficient to modify its behaviour using
+the B<verify_callback> function.
+
+=head1 BUGS
+
+=head1 RETURN VALUES
+
+SSL_CTX_set_cert_verify_callback() does not provide diagnostic information.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>,
+L<SSL_get_verify_result(3)|SSL_get_verify_result(3)>,
+L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>
+
+=head1 HISTORY
+
+Previous to OpenSSL 0.9.7, the I<arg> argument to B<SSL_CTX_set_cert_verify_callback>
+was ignored, and I<callback> was called simply as
+ int (*callback)(X509_STORE_CTX *)
+To compile software written for previous versions of OpenSSL, a dummy
+argument will have to be added to I<callback>.
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_set_cipher_list.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_set_cipher_list.pod
new file mode 100644 (file)
index 0000000..ed64f64
--- /dev/null
@@ -0,0 +1,70 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_set_cipher_list, SSL_set_cipher_list - choose list of available SSL_CIPHERs
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str);
+ int SSL_set_cipher_list(SSL *ssl, const char *str);
+
+=head1 DESCRIPTION
+
+SSL_CTX_set_cipher_list() sets the list of available ciphers for B<ctx>
+using the control string B<str>. The format of the string is described
+in L<ciphers(1)|ciphers(1)>. The list of ciphers is inherited by all
+B<ssl> objects created from B<ctx>.
+
+SSL_set_cipher_list() sets the list of ciphers only for B<ssl>.
+
+=head1 NOTES
+
+The control string B<str> should be universally usable and not depend
+on details of the library configuration (ciphers compiled in). Thus no
+syntax checking takes place. Items that are not recognized, because the
+corresponding ciphers are not compiled in or because they are mistyped,
+are simply ignored. Failure is only flagged if no ciphers could be collected
+at all.
+
+It should be noted, that inclusion of a cipher to be used into the list is
+a necessary condition. On the client side, the inclusion into the list is
+also sufficient. On the server side, additional restrictions apply. All ciphers
+have additional requirements. ADH ciphers don't need a certificate, but
+DH-parameters must have been set. All other ciphers need a corresponding
+certificate and key.
+
+A RSA cipher can only be chosen, when a RSA certificate is available.
+RSA export ciphers with a keylength of 512 bits for the RSA key require
+a temporary 512 bit RSA key, as typically the supplied key has a length
+of 1024 bit (see
+L<SSL_CTX_set_tmp_rsa_callback(3)|SSL_CTX_set_tmp_rsa_callback(3)>).
+RSA ciphers using EDH need a certificate and key and additional DH-parameters
+(see L<SSL_CTX_set_tmp_dh_callback(3)|SSL_CTX_set_tmp_dh_callback(3)>).
+
+A DSA cipher can only be chosen, when a DSA certificate is available.
+DSA ciphers always use DH key exchange and therefore need DH-parameters
+(see L<SSL_CTX_set_tmp_dh_callback(3)|SSL_CTX_set_tmp_dh_callback(3)>).
+
+When these conditions are not met for any cipher in the list (e.g. a
+client only supports export RSA ciphers with a asymmetric key length
+of 512 bits and the server is not configured to use temporary RSA
+keys), the "no shared cipher" (SSL_R_NO_SHARED_CIPHER) error is generated
+and the handshake will fail.
+
+=head1 RETURN VALUES
+
+SSL_CTX_set_cipher_list() and SSL_set_cipher_list() return 1 if any cipher
+could be selected and 0 on complete failure.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_get_ciphers(3)|SSL_get_ciphers(3)>,
+L<SSL_CTX_use_certificate(3)|SSL_CTX_use_certificate(3)>,
+L<SSL_CTX_set_tmp_rsa_callback(3)|SSL_CTX_set_tmp_rsa_callback(3)>,
+L<SSL_CTX_set_tmp_dh_callback(3)|SSL_CTX_set_tmp_dh_callback(3)>,
+L<ciphers(1)|ciphers(1)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_set_client_CA_list.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_set_client_CA_list.pod
new file mode 100644 (file)
index 0000000..632b556
--- /dev/null
@@ -0,0 +1,94 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_set_client_CA_list, SSL_set_client_CA_list, SSL_CTX_add_client_CA,
+SSL_add_client_CA - set list of CAs sent to the client when requesting a
+client certificate
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+ void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *list);
+ void SSL_set_client_CA_list(SSL *s, STACK_OF(X509_NAME) *list);
+ int SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *cacert);
+ int SSL_add_client_CA(SSL *ssl, X509 *cacert);
+
+=head1 DESCRIPTION
+
+SSL_CTX_set_client_CA_list() sets the B<list> of CAs sent to the client when
+requesting a client certificate for B<ctx>.
+
+SSL_set_client_CA_list() sets the B<list> of CAs sent to the client when
+requesting a client certificate for the chosen B<ssl>, overriding the
+setting valid for B<ssl>'s SSL_CTX object.
+
+SSL_CTX_add_client_CA() adds the CA name extracted from B<cacert> to the
+list of CAs sent to the client when requesting a client certificate for
+B<ctx>.
+
+SSL_add_client_CA() adds the CA name extracted from B<cacert> to the
+list of CAs sent to the client when requesting a client certificate for
+the chosen B<ssl>, overriding the setting valid for B<ssl>'s SSL_CTX object.
+
+=head1 NOTES
+
+When a TLS/SSL server requests a client certificate (see
+B<SSL_CTX_set_verify_options()>), it sends a list of CAs, for which
+it will accept certificates, to the client.
+
+This list must explicitly be set using SSL_CTX_set_client_CA_list() for
+B<ctx> and SSL_set_client_CA_list() for the specific B<ssl>. The list
+specified overrides the previous setting. The CAs listed do not become
+trusted (B<list> only contains the names, not the complete certificates); use
+L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)> 
+to additionally load them for verification.
+
+If the list of acceptable CAs is compiled in a file, the
+L<SSL_load_client_CA_file(3)|SSL_load_client_CA_file(3)>
+function can be used to help importing the necessary data.
+
+SSL_CTX_add_client_CA() and SSL_add_client_CA() can be used to add additional
+items the list of client CAs. If no list was specified before using
+SSL_CTX_set_client_CA_list() or SSL_set_client_CA_list(), a new client
+CA list for B<ctx> or B<ssl> (as appropriate) is opened.
+
+These functions are only useful for TLS/SSL servers.
+
+=head1 RETURN VALUES
+
+SSL_CTX_set_client_CA_list() and SSL_set_client_CA_list() do not return
+diagnostic information.
+
+SSL_CTX_add_client_CA() and SSL_add_client_CA() have the following return
+values:
+
+=over 4
+
+=item 1
+
+The operation succeeded.
+
+=item 0
+
+A failure while manipulating the STACK_OF(X509_NAME) object occurred or
+the X509_NAME could not be extracted from B<cacert>. Check the error stack
+to find out the reason.
+
+=back
+
+=head1 EXAMPLES
+
+Scan all certificates in B<CAfile> and list them as acceptable CAs:
+
+  SSL_CTX_set_client_CA_list(ctx,SSL_load_client_CA_file(CAfile));
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>,
+L<SSL_get_client_CA_list(3)|SSL_get_client_CA_list(3)>,
+L<SSL_load_client_CA_file(3)|SSL_load_client_CA_file(3)>,
+L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_set_client_cert_cb.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_set_client_cert_cb.pod
new file mode 100644 (file)
index 0000000..3465b5c
--- /dev/null
@@ -0,0 +1,94 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_set_client_cert_cb, SSL_CTX_get_client_cert_cb - handle client certificate callback function
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ void SSL_CTX_set_client_cert_cb(SSL_CTX *ctx, int (*client_cert_cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey));
+ int (*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx))(SSL *ssl, X509 **x509, EVP_PKEY **pkey);
+ int (*client_cert_cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey);
+
+=head1 DESCRIPTION
+
+SSL_CTX_set_client_cert_cb() sets the B<client_cert_cb()> callback, that is
+called when a client certificate is requested by a server and no certificate
+was yet set for the SSL object.
+
+When B<client_cert_cb()> is NULL, no callback function is used.
+
+SSL_CTX_get_client_cert_cb() returns a pointer to the currently set callback
+function.
+
+client_cert_cb() is the application defined callback. If it wants to
+set a certificate, a certificate/private key combination must be set
+using the B<x509> and B<pkey> arguments and "1" must be returned. The
+certificate will be installed into B<ssl>, see the NOTES and BUGS sections.
+If no certificate should be set, "0" has to be returned and no certificate
+will be sent. A negative return value will suspend the handshake and the
+handshake function will return immediatly. L<SSL_get_error(3)|SSL_get_error(3)>
+will return SSL_ERROR_WANT_X509_LOOKUP to indicate, that the handshake was
+suspended. The next call to the handshake function will again lead to the call
+of client_cert_cb(). It is the job of the client_cert_cb() to store information
+about the state of the last call, if required to continue.
+
+=head1 NOTES
+
+During a handshake (or renegotiation) a server may request a certificate
+from the client. A client certificate must only be sent, when the server
+did send the request.
+
+When a certificate was set using the
+L<SSL_CTX_use_certificate(3)|SSL_CTX_use_certificate(3)> family of functions,
+it will be sent to the server. The TLS standard requires that only a
+certificate is sent, if it matches the list of acceptable CAs sent by the
+server. This constraint is violated by the default behavior of the OpenSSL
+library. Using the callback function it is possible to implement a proper
+selection routine or to allow a user interaction to choose the certificate to
+be sent.
+
+If a callback function is defined and no certificate was yet defined for the
+SSL object, the callback function will be called.
+If the callback function returns a certificate, the OpenSSL library
+will try to load the private key and certificate data into the SSL
+object using the SSL_use_certificate() and SSL_use_private_key() functions.
+Thus it will permanently install the certificate and key for this SSL
+object. It will not be reset by calling L<SSL_clear(3)|SSL_clear(3)>.
+If the callback returns no certificate, the OpenSSL library will not send
+a certificate.
+
+=head1 BUGS
+
+The client_cert_cb() cannot return a complete certificate chain, it can
+only return one client certificate. If the chain only has a length of 2,
+the root CA certificate may be omitted according to the TLS standard and
+thus a standard conforming answer can be sent to the server. For a
+longer chain, the client must send the complete chain (with the option
+to leave out the root CA certificate). This can only be accomplished by
+either adding the intermediate CA certificates into the trusted
+certificate store for the SSL_CTX object (resulting in having to add
+CA certificates that otherwise maybe would not be trusted), or by adding
+the chain certificates using the
+L<SSL_CTX_add_extra_chain_cert(3)|SSL_CTX_add_extra_chain_cert(3)>
+function, which is only available for the SSL_CTX object as a whole and that
+therefore probably can only apply for one client certificate, making
+the concept of the callback function (to allow the choice from several
+certificates) questionable.
+
+Once the SSL object has been used in conjunction with the callback function,
+the certificate will be set for the SSL object and will not be cleared
+even when L<SSL_clear(3)|SSL_clear(3)> is being called. It is therefore
+mandatory to destroy the SSL object using L<SSL_free(3)|SSL_free(3)>
+and create a new one to return to the previous state.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_CTX_use_certificate(3)|SSL_CTX_use_certificate(3)>,
+L<SSL_CTX_add_extra_chain_cert(3)|SSL_CTX_add_extra_chain_cert(3)>,
+L<SSL_get_client_CA_list(3)|SSL_get_client_CA_list(3)>,
+L<SSL_clear(3)|SSL_clear(3)>, L<SSL_free(3)|SSL_free(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_set_default_passwd_cb.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_set_default_passwd_cb.pod
new file mode 100644 (file)
index 0000000..2b87f01
--- /dev/null
@@ -0,0 +1,76 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_set_default_passwd_cb, SSL_CTX_set_default_passwd_cb_userdata - set passwd callback for encrypted PEM file handling
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb);
+ void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);
+
+ int pem_passwd_cb(char *buf, int size, int rwflag, void *userdata);
+
+=head1 DESCRIPTION
+
+SSL_CTX_set_default_passwd_cb() sets the default password callback called
+when loading/storing a PEM certificate with encryption.
+
+SSL_CTX_set_default_passwd_cb_userdata() sets a pointer to B<userdata> which
+will be provided to the password callback on invocation.
+
+The pem_passwd_cb(), which must be provided by the application, hands back the
+password to be used during decryption. On invocation a pointer to B<userdata>
+is provided. The pem_passwd_cb must write the password into the provided buffer
+B<buf> which is of size B<size>. The actual length of the password must
+be returned to the calling function. B<rwflag> indicates whether the
+callback is used for reading/decryption (rwflag=0) or writing/encryption
+(rwflag=1).
+
+=head1 NOTES
+
+When loading or storing private keys, a password might be supplied to
+protect the private key. The way this password can be supplied may depend
+on the application. If only one private key is handled, it can be practical
+to have pem_passwd_cb() handle the password dialog interactively. If several
+keys have to be handled, it can be practical to ask for the password once,
+then keep it in memory and use it several times. In the last case, the
+password could be stored into the B<userdata> storage and the
+pem_passwd_cb() only returns the password already stored.
+
+When asking for the password interactively, pem_passwd_cb() can use
+B<rwflag> to check, whether an item shall be encrypted (rwflag=1).
+In this case the password dialog may ask for the same password twice
+for comparison in order to catch typos, that would make decryption
+impossible.
+
+Other items in PEM formatting (certificates) can also be encrypted, it is
+however not usual, as certificate information is considered public.
+
+=head1 RETURN VALUES
+
+SSL_CTX_set_default_passwd_cb() and SSL_CTX_set_default_passwd_cb_userdata()
+do not provide diagnostic information.
+
+=head1 EXAMPLES
+
+The following example returns the password provided as B<userdata> to the
+calling function. The password is considered to be a '\0' terminated
+string. If the password does not fit into the buffer, the password is
+truncated.
+
+ int pem_passwd_cb(char *buf, int size, int rwflag, void *password)
+ {
+  strncpy(buf, (char *)(password), size);
+  buf[size - 1] = '\0';
+  return(strlen(buf));
+ }
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>,
+L<SSL_CTX_use_certificate(3)|SSL_CTX_use_certificate(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_set_generate_session_id.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_set_generate_session_id.pod
new file mode 100644 (file)
index 0000000..798e844
--- /dev/null
@@ -0,0 +1,150 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_set_generate_session_id, SSL_set_generate_session_id, SSL_has_matching_session_id - manipulate generation of SSL session IDs (server only)
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ typedef int (*GEN_SESSION_CB)(const SSL *ssl, unsigned char *id,
+                               unsigned int *id_len);
+
+ int SSL_CTX_set_generate_session_id(SSL_CTX *ctx, GEN_SESSION_CB cb);
+ int SSL_set_generate_session_id(SSL *ssl, GEN_SESSION_CB, cb);
+ int SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id,
+                                unsigned int id_len);
+
+=head1 DESCRIPTION
+
+SSL_CTX_set_generate_session_id() sets the callback function for generating
+new session ids for SSL/TLS sessions for B<ctx> to be B<cb>.
+
+SSL_set_generate_session_id() sets the callback function for generating
+new session ids for SSL/TLS sessions for B<ssl> to be B<cb>.
+
+SSL_has_matching_session_id() checks, whether a session with id B<id>
+(of length B<id_len>) is already contained in the internal session cache
+of the parent context of B<ssl>.
+
+=head1 NOTES
+
+When a new session is established between client and server, the server
+generates a session id. The session id is an arbitrary sequence of bytes.
+The length of the session id is 16 bytes for SSLv2 sessions and between
+1 and 32 bytes for SSLv3/TLSv1. The session id is not security critical
+but must be unique for the server. Additionally, the session id is
+transmitted in the clear when reusing the session so it must not contain
+sensitive information.
+
+Without a callback being set, an OpenSSL server will generate a unique
+session id from pseudo random numbers of the maximum possible length.
+Using the callback function, the session id can be changed to contain
+additional information like e.g. a host id in order to improve load balancing
+or external caching techniques.
+
+The callback function receives a pointer to the memory location to put
+B<id> into and a pointer to the maximum allowed length B<id_len>. The
+buffer at location B<id> is only guaranteed to have the size B<id_len>.
+The callback is only allowed to generate a shorter id and reduce B<id_len>;
+the callback B<must never> increase B<id_len> or write to the location
+B<id> exceeding the given limit.
+
+If a SSLv2 session id is generated and B<id_len> is reduced, it will be
+restored after the callback has finished and the session id will be padded
+with 0x00. It is not recommended to change the B<id_len> for SSLv2 sessions.
+The callback can use the L<SSL_get_version(3)|SSL_get_version(3)> function
+to check, whether the session is of type SSLv2.
+
+The location B<id> is filled with 0x00 before the callback is called, so the
+callback may only fill part of the possible length and leave B<id_len>
+untouched while maintaining reproducibility.
+
+Since the sessions must be distinguished, session ids must be unique.
+Without the callback a random number is used, so that the probability
+of generating the same session id is extremely small (2^128 possible ids
+for an SSLv2 session, 2^256 for SSLv3/TLSv1). In order to assure the
+uniqueness of the generated session id, the callback must call
+SSL_has_matching_session_id() and generate another id if a conflict occurs.
+If an id conflict is not resolved, the handshake will fail.
+If the application codes e.g. a unique host id, a unique process number, and
+a unique sequence number into the session id, uniqueness could easily be
+achieved without randomness added (it should however be taken care that
+no confidential information is leaked this way). If the application can not
+guarantee uniqueness, it is recommended to use the maximum B<id_len> and
+fill in the bytes not used to code special information with random data
+to avoid collisions.
+
+SSL_has_matching_session_id() will only query the internal session cache,
+not the external one. Since the session id is generated before the
+handshake is completed, it is not immediately added to the cache. If
+another thread is using the same internal session cache, a race condition
+can occur in that another thread generates the same session id.
+Collisions can also occur when using an external session cache, since
+the external cache is not tested with SSL_has_matching_session_id()
+and the same race condition applies.
+
+When calling SSL_has_matching_session_id() for an SSLv2 session with
+reduced B<id_len>, the match operation will be performed using the
+fixed length required and with a 0x00 padded id.
+
+The callback must return 0 if it cannot generate a session id for whatever
+reason and return 1 on success.
+
+=head1 EXAMPLES
+
+The callback function listed will generate a session id with the
+server id given, and will fill the rest with pseudo random bytes:
+
+ const char session_id_prefix = "www-18";
+
+ #define MAX_SESSION_ID_ATTEMPTS 10
+ static int generate_session_id(const SSL *ssl, unsigned char *id,
+                              unsigned int *id_len)
+      {
+      unsigned int count = 0;
+      const char *version;
+
+      version = SSL_get_version(ssl);
+      if (!strcmp(version, "SSLv2"))
+         /* we must not change id_len */;
+
+      do      {
+              RAND_pseudo_bytes(id, *id_len);
+              /* Prefix the session_id with the required prefix. NB: If our
+               * prefix is too long, clip it - but there will be worse effects
+               * anyway, eg. the server could only possibly create 1 session
+               * ID (ie. the prefix!) so all future session negotiations will
+               * fail due to conflicts. */
+              memcpy(id, session_id_prefix,
+                      (strlen(session_id_prefix) < *id_len) ?
+                      strlen(session_id_prefix) : *id_len);
+              }
+      while(SSL_has_matching_session_id(ssl, id, *id_len) &&
+              (++count < MAX_SESSION_ID_ATTEMPTS));
+      if(count >= MAX_SESSION_ID_ATTEMPTS)
+              return 0;
+      return 1;
+      }
+
+
+=head1 RETURN VALUES
+
+SSL_CTX_set_generate_session_id() and SSL_set_generate_session_id()
+always return 1.
+
+SSL_has_matching_session_id() returns 1 if another session with the
+same id is already in the cache.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_get_version(3)|SSL_get_version(3)>
+
+=head1 HISTORY
+
+SSL_CTX_set_generate_session_id(), SSL_set_generate_session_id()
+and SSL_has_matching_session_id() have been introduced in
+OpenSSL 0.9.7.
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_set_info_callback.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_set_info_callback.pod
new file mode 100644 (file)
index 0000000..0b4affd
--- /dev/null
@@ -0,0 +1,153 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_set_info_callback, SSL_CTX_get_info_callback, SSL_set_info_callback, SSL_get_info_callback - handle information callback for SSL connections
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ void SSL_CTX_set_info_callback(SSL_CTX *ctx, void (*callback)());
+ void (*SSL_CTX_get_info_callback(const SSL_CTX *ctx))();
+
+ void SSL_set_info_callback(SSL *ssl, void (*callback)());
+ void (*SSL_get_info_callback(const SSL *ssl))();
+
+=head1 DESCRIPTION
+
+SSL_CTX_set_info_callback() sets the B<callback> function, that can be used to
+obtain state information for SSL objects created from B<ctx> during connection
+setup and use. The setting for B<ctx> is overridden from the setting for
+a specific SSL object, if specified.
+When B<callback> is NULL, not callback function is used.
+
+SSL_set_info_callback() sets the B<callback> function, that can be used to
+obtain state information for B<ssl> during connection setup and use.
+When B<callback> is NULL, the callback setting currently valid for
+B<ctx> is used.
+
+SSL_CTX_get_info_callback() returns a pointer to the currently set information
+callback function for B<ctx>.
+
+SSL_get_info_callback() returns a pointer to the currently set information
+callback function for B<ssl>.
+
+=head1 NOTES
+
+When setting up a connection and during use, it is possible to obtain state
+information from the SSL/TLS engine. When set, an information callback function
+is called whenever the state changes, an alert appears, or an error occurs.
+
+The callback function is called as B<callback(SSL *ssl, int where, int ret)>.
+The B<where> argument specifies information about where (in which context)
+the callback function was called. If B<ret> is 0, an error condition occurred.
+If an alert is handled, SSL_CB_ALERT is set and B<ret> specifies the alert
+information.
+
+B<where> is a bitmask made up of the following bits:
+
+=over 4
+
+=item SSL_CB_LOOP
+
+Callback has been called to indicate state change inside a loop.
+
+=item SSL_CB_EXIT
+
+Callback has been called to indicate error exit of a handshake function.
+(May be soft error with retry option for non-blocking setups.)
+
+=item SSL_CB_READ
+
+Callback has been called during read operation.
+
+=item SSL_CB_WRITE
+
+Callback has been called during write operation.
+
+=item SSL_CB_ALERT
+
+Callback has been called due to an alert being sent or received.
+
+=item SSL_CB_READ_ALERT               (SSL_CB_ALERT|SSL_CB_READ)
+
+=item SSL_CB_WRITE_ALERT              (SSL_CB_ALERT|SSL_CB_WRITE)
+
+=item SSL_CB_ACCEPT_LOOP              (SSL_ST_ACCEPT|SSL_CB_LOOP)
+
+=item SSL_CB_ACCEPT_EXIT              (SSL_ST_ACCEPT|SSL_CB_EXIT)
+
+=item SSL_CB_CONNECT_LOOP             (SSL_ST_CONNECT|SSL_CB_LOOP)
+
+=item SSL_CB_CONNECT_EXIT             (SSL_ST_CONNECT|SSL_CB_EXIT)
+
+=item SSL_CB_HANDSHAKE_START
+
+Callback has been called because a new handshake is started.
+
+=item SSL_CB_HANDSHAKE_DONE           0x20
+
+Callback has been called because a handshake is finished.
+
+=back
+
+The current state information can be obtained using the
+L<SSL_state_string(3)|SSL_state_string(3)> family of functions.
+
+The B<ret> information can be evaluated using the
+L<SSL_alert_type_string(3)|SSL_alert_type_string(3)> family of functions.
+
+=head1 RETURN VALUES
+
+SSL_set_info_callback() does not provide diagnostic information.
+
+SSL_get_info_callback() returns the current setting.
+
+=head1 EXAMPLES
+
+The following example callback function prints state strings, information
+about alerts being handled and error messages to the B<bio_err> BIO.
+
+ void apps_ssl_info_callback(SSL *s, int where, int ret)
+       {
+       const char *str;
+       int w;
+
+       w=where& ~SSL_ST_MASK;
+
+       if (w & SSL_ST_CONNECT) str="SSL_connect";
+       else if (w & SSL_ST_ACCEPT) str="SSL_accept";
+       else str="undefined";
+
+       if (where & SSL_CB_LOOP)
+               {
+               BIO_printf(bio_err,"%s:%s\n",str,SSL_state_string_long(s));
+               }
+       else if (where & SSL_CB_ALERT)
+               {
+               str=(where & SSL_CB_READ)?"read":"write";
+               BIO_printf(bio_err,"SSL3 alert %s:%s:%s\n",
+                       str,
+                       SSL_alert_type_string_long(ret),
+                       SSL_alert_desc_string_long(ret));
+               }
+       else if (where & SSL_CB_EXIT)
+               {
+               if (ret == 0)
+                       BIO_printf(bio_err,"%s:failed in %s\n",
+                               str,SSL_state_string_long(s));
+               else if (ret < 0)
+                       {
+                       BIO_printf(bio_err,"%s:error in %s\n",
+                               str,SSL_state_string_long(s));
+                       }
+               }
+       }
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_state_string(3)|SSL_state_string(3)>,
+L<SSL_alert_type_string(3)|SSL_alert_type_string(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_set_max_cert_list.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_set_max_cert_list.pod
new file mode 100644 (file)
index 0000000..da68cb9
--- /dev/null
@@ -0,0 +1,77 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_set_max_cert_list, SSL_CTX_get_max_cert_list, SSL_set_max_cert_list, SSL_get_max_cert_list, - manipulate allowed for the peer's certificate chain
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ long SSL_CTX_set_max_cert_list(SSL_CTX *ctx, long size);
+ long SSL_CTX_get_max_cert_list(SSL_CTX *ctx);
+
+ long SSL_set_max_cert_list(SSL *ssl, long size);
+ long SSL_get_max_cert_list(SSL *ctx);
+
+=head1 DESCRIPTION
+
+SSL_CTX_set_max_cert_list() sets the maximum size allowed for the peer's
+certificate chain for all SSL objects created from B<ctx> to be <size> bytes.
+The SSL objects inherit the setting valid for B<ctx> at the time
+L<SSL_new(3)|SSL_new(3)> is being called.
+
+SSL_CTX_get_max_cert_list() returns the currently set maximum size for B<ctx>.
+
+SSL_set_max_cert_list() sets the maximum size allowed for the peer's
+certificate chain for B<ssl> to be <size> bytes. This setting stays valid
+until a new value is set.
+
+SSL_get_max_cert_list() returns the currently set maximum size for B<ssl>.
+
+=head1 NOTES
+
+During the handshake process, the peer may send a certificate chain.
+The TLS/SSL standard does not give any maximum size of the certificate chain.
+The OpenSSL library handles incoming data by a dynamically allocated buffer.
+In order to prevent this buffer from growing without bounds due to data
+received from a faulty or malicious peer, a maximum size for the certificate
+chain is set.
+
+The default value for the maximum certificate chain size is 100kB (30kB
+on the 16bit DOS platform). This should be sufficient for usual certificate
+chains (OpenSSL's default maximum chain length is 10, see
+L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>, and certificates
+without special extensions have a typical size of 1-2kB).
+
+For special applications it can be necessary to extend the maximum certificate
+chain size allowed to be sent by the peer, see e.g. the work on
+"Internet X.509 Public Key Infrastructure Proxy Certificate Profile"
+and "TLS Delegation Protocol" at http://www.ietf.org/ and
+http://www.globus.org/ .
+
+Under normal conditions it should never be necessary to set a value smaller
+than the default, as the buffer is handled dynamically and only uses the
+memory actually required by the data sent by the peer.
+
+If the maximum certificate chain size allowed is exceeded, the handshake will
+fail with a SSL_R_EXCESSIVE_MESSAGE_SIZE error.
+
+=head1 RETURN VALUES
+
+SSL_CTX_set_max_cert_list() and SSL_set_max_cert_list() return the previously
+set value.
+
+SSL_CTX_get_max_cert_list() and SSL_get_max_cert_list() return the currently
+set value.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_new(3)|SSL_new(3)>,
+L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>
+
+=head1 HISTORY
+
+SSL*_set/get_max_cert_list() have been introduced in OpenSSL 0.9.7.
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_set_mode.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_set_mode.pod
new file mode 100644 (file)
index 0000000..8cb669d
--- /dev/null
@@ -0,0 +1,91 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_set_mode, SSL_set_mode, SSL_CTX_get_mode, SSL_get_mode - manipulate SSL engine mode
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ long SSL_CTX_set_mode(SSL_CTX *ctx, long mode);
+ long SSL_set_mode(SSL *ssl, long mode);
+
+ long SSL_CTX_get_mode(SSL_CTX *ctx);
+ long SSL_get_mode(SSL *ssl);
+
+=head1 DESCRIPTION
+
+SSL_CTX_set_mode() adds the mode set via bitmask in B<mode> to B<ctx>.
+Options already set before are not cleared.
+
+SSL_set_mode() adds the mode set via bitmask in B<mode> to B<ssl>.
+Options already set before are not cleared.
+
+SSL_CTX_get_mode() returns the mode set for B<ctx>.
+
+SSL_get_mode() returns the mode set for B<ssl>.
+
+=head1 NOTES
+
+The following mode changes are available:
+
+=over 4
+
+=item SSL_MODE_ENABLE_PARTIAL_WRITE
+
+Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success
+when just a single record has been written). When not set (the default),
+SSL_write() will only report success once the complete chunk was written.
+Once SSL_write() returns with r, r bytes have been successfully written
+and the next call to SSL_write() must only send the n-r bytes left,
+imitating the behaviour of write().
+
+=item SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER
+
+Make it possible to retry SSL_write() with changed buffer location
+(the buffer contents must stay the same). This is not the default to avoid
+the misconception that non-blocking SSL_write() behaves like
+non-blocking write().
+
+=item SSL_MODE_AUTO_RETRY
+
+Never bother the application with retries if the transport is blocking.
+If a renegotiation take place during normal operation, a
+L<SSL_read(3)|SSL_read(3)> or L<SSL_write(3)|SSL_write(3)> would return
+with -1 and indicate the need to retry with SSL_ERROR_WANT_READ.
+In a non-blocking environment applications must be prepared to handle
+incomplete read/write operations.
+In a blocking environment, applications are not always prepared to
+deal with read/write operations returning without success report. The
+flag SSL_MODE_AUTO_RETRY will cause read/write operations to only
+return after the handshake and successful completion.
+
+=item SSL_MODE_RELEASE_BUFFERS
+
+When we no longer need a read buffer or a write buffer for a given SSL,
+then release the memory we were using to hold it.  Released memory is
+either appended to a list of unused RAM chunks on the SSL_CTX, or simply
+freed if the list of unused chunks would become longer than 
+SSL_CTX->freelist_max_len, which defaults to 32.  Using this flag can
+save around 34k per idle SSL connection.
+This flag has no effect on SSL v2 connections, or on DTLS connections.
+
+=back
+
+=head1 RETURN VALUES
+
+SSL_CTX_set_mode() and SSL_set_mode() return the new mode bitmask
+after adding B<mode>.
+
+SSL_CTX_get_mode() and SSL_get_mode() return the current bitmask.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_read(3)|SSL_read(3)>, L<SSL_write(3)|SSL_write(3)>
+
+=head1 HISTORY
+
+SSL_MODE_AUTO_RETRY as been added in OpenSSL 0.9.6.
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_set_msg_callback.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_set_msg_callback.pod
new file mode 100644 (file)
index 0000000..0015e6e
--- /dev/null
@@ -0,0 +1,99 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_set_msg_callback, SSL_CTX_set_msg_callback_arg, SSL_set_msg_callback, SSL_get_msg_callback_arg - install callback for observing protocol messages
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ void SSL_CTX_set_msg_callback(SSL_CTX *ctx, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg));
+ void SSL_CTX_set_msg_callback_arg(SSL_CTX *ctx, void *arg);
+
+ void SSL_set_msg_callback(SSL_CTX *ctx, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg));
+ void SSL_set_msg_callback_arg(SSL_CTX *ctx, void *arg);
+
+=head1 DESCRIPTION
+
+SSL_CTX_set_msg_callback() or SSL_set_msg_callback() can be used to
+define a message callback function I<cb> for observing all SSL/TLS
+protocol messages (such as handshake messages) that are received or
+sent.  SSL_CTX_set_msg_callback_arg() and SSL_set_msg_callback_arg()
+can be used to set argument I<arg> to the callback function, which is
+available for arbitrary application use.
+
+SSL_CTX_set_msg_callback() and SSL_CTX_set_msg_callback_arg() specify
+default settings that will be copied to new B<SSL> objects by
+L<SSL_new(3)|SSL_new(3)>. SSL_set_msg_callback() and
+SSL_set_msg_callback_arg() modify the actual settings of an B<SSL>
+object. Using a B<0> pointer for I<cb> disables the message callback.
+
+When I<cb> is called by the SSL/TLS library for a protocol message,
+the function arguments have the following meaning:
+
+=over 4
+
+=item I<write_p>
+
+This flag is B<0> when a protocol message has been received and B<1>
+when a protocol message has been sent.
+
+=item I<version>
+
+The protocol version according to which the protocol message is
+interpreted by the library. Currently, this is one of
+B<SSL2_VERSION>, B<SSL3_VERSION> and B<TLS1_VERSION> (for SSL 2.0, SSL
+3.0 and TLS 1.0, respectively).
+
+=item I<content_type>
+
+In the case of SSL 2.0, this is always B<0>.  In the case of SSL 3.0
+or TLS 1.0, this is one of the B<ContentType> values defined in the
+protocol specification (B<change_cipher_spec(20)>, B<alert(21)>,
+B<handshake(22)>; but never B<application_data(23)> because the
+callback will only be called for protocol messages).
+
+=item I<buf>, I<len>
+
+I<buf> points to a buffer containing the protocol message, which
+consists of I<len> bytes. The buffer is no longer valid after the
+callback function has returned.
+
+=item I<ssl>
+
+The B<SSL> object that received or sent the message.
+
+=item I<arg>
+
+The user-defined argument optionally defined by
+SSL_CTX_set_msg_callback_arg() or SSL_set_msg_callback_arg().
+
+=back
+
+=head1 NOTES
+
+Protocol messages are passed to the callback function after decryption
+and fragment collection where applicable. (Thus record boundaries are
+not visible.)
+
+If processing a received protocol message results in an error,
+the callback function may not be called.  For example, the callback
+function will never see messages that are considered too large to be
+processed.
+
+Due to automatic protocol version negotiation, I<version> is not
+necessarily the protocol version used by the sender of the message: If
+a TLS 1.0 ClientHello message is received by an SSL 3.0-only server,
+I<version> will be B<SSL3_VERSION>.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_new(3)|SSL_new(3)>
+
+=head1 HISTORY
+
+SSL_CTX_set_msg_callback(), SSL_CTX_set_msg_callback_arg(),
+SSL_set_msg_callback() and SSL_get_msg_callback_arg() were added in OpenSSL 0.9.7.
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_set_options.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_set_options.pod
new file mode 100644 (file)
index 0000000..cc588f3
--- /dev/null
@@ -0,0 +1,346 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_set_options, SSL_set_options, SSL_CTX_clear_options, SSL_clear_options, SSL_CTX_get_options, SSL_get_options, SSL_get_secure_renegotiation_support - manipulate SSL options
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ long SSL_CTX_set_options(SSL_CTX *ctx, long options);
+ long SSL_set_options(SSL *ssl, long options);
+
+ long SSL_CTX_clear_options(SSL_CTX *ctx, long options);
+ long SSL_clear_options(SSL *ssl, long options);
+
+ long SSL_CTX_get_options(SSL_CTX *ctx);
+ long SSL_get_options(SSL *ssl);
+
+ long SSL_get_secure_renegotiation_support(SSL *ssl);
+
+=head1 DESCRIPTION
+
+Note: all these functions are implemented using macros.
+
+SSL_CTX_set_options() adds the options set via bitmask in B<options> to B<ctx>.
+Options already set before are not cleared!
+
+SSL_set_options() adds the options set via bitmask in B<options> to B<ssl>.
+Options already set before are not cleared!
+
+SSL_CTX_clear_options() clears the options set via bitmask in B<options>
+to B<ctx>.
+
+SSL_clear_options() clears the options set via bitmask in B<options> to B<ssl>.
+
+SSL_CTX_get_options() returns the options set for B<ctx>.
+
+SSL_get_options() returns the options set for B<ssl>.
+
+SSL_get_secure_renegotiation_support() indicates whether the peer supports
+secure renegotiation.
+
+=head1 NOTES
+
+The behaviour of the SSL library can be changed by setting several options.
+The options are coded as bitmasks and can be combined by a logical B<or>
+operation (|).
+
+SSL_CTX_set_options() and SSL_set_options() affect the (external)
+protocol behaviour of the SSL library. The (internal) behaviour of
+the API can be changed by using the similar
+L<SSL_CTX_set_mode(3)|SSL_CTX_set_mode(3)> and SSL_set_mode() functions.
+
+During a handshake, the option settings of the SSL object are used. When
+a new SSL object is created from a context using SSL_new(), the current
+option setting is copied. Changes to B<ctx> do not affect already created
+SSL objects. SSL_clear() does not affect the settings.
+
+The following B<bug workaround> options are available:
+
+=over 4
+
+=item SSL_OP_MICROSOFT_SESS_ID_BUG
+
+www.microsoft.com - when talking SSLv2, if session-id reuse is
+performed, the session-id passed back in the server-finished message
+is different from the one decided upon.
+
+=item SSL_OP_NETSCAPE_CHALLENGE_BUG
+
+Netscape-Commerce/1.12, when talking SSLv2, accepts a 32 byte
+challenge but then appears to only use 16 bytes when generating the
+encryption keys.  Using 16 bytes is ok but it should be ok to use 32.
+According to the SSLv3 spec, one should use 32 bytes for the challenge
+when operating in SSLv2/v3 compatibility mode, but as mentioned above,
+this breaks this server so 16 bytes is the way to go.
+
+=item SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG
+
+As of OpenSSL 0.9.8q and 1.0.0c, this option has no effect.
+
+=item SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG
+
+...
+
+=item SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER
+
+...
+
+=item SSL_OP_MSIE_SSLV2_RSA_PADDING
+
+As of OpenSSL 0.9.7h and 0.9.8a, this option has no effect.
+
+=item SSL_OP_SSLEAY_080_CLIENT_DH_BUG
+
+...
+
+=item SSL_OP_TLS_D5_BUG
+
+...
+
+=item SSL_OP_TLS_BLOCK_PADDING_BUG
+
+...
+
+=item SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS
+
+Disables a countermeasure against a SSL 3.0/TLS 1.0 protocol
+vulnerability affecting CBC ciphers, which cannot be handled by some
+broken SSL implementations.  This option has no effect for connections
+using other ciphers.
+
+=item SSL_OP_ALL
+
+All of the above bug workarounds.
+
+=back
+
+It is usually safe to use B<SSL_OP_ALL> to enable the bug workaround
+options if compatibility with somewhat broken implementations is
+desired.
+
+The following B<modifying> options are available:
+
+=over 4
+
+=item SSL_OP_TLS_ROLLBACK_BUG
+
+Disable version rollback attack detection.
+
+During the client key exchange, the client must send the same information
+about acceptable SSL/TLS protocol levels as during the first hello. Some
+clients violate this rule by adapting to the server's answer. (Example:
+the client sends a SSLv2 hello and accepts up to SSLv3.1=TLSv1, the server
+only understands up to SSLv3. In this case the client must still use the
+same SSLv3.1=TLSv1 announcement. Some clients step down to SSLv3 with respect
+to the server's answer and violate the version rollback protection.)
+
+=item SSL_OP_SINGLE_DH_USE
+
+Always create a new key when using temporary/ephemeral DH parameters
+(see L<SSL_CTX_set_tmp_dh_callback(3)|SSL_CTX_set_tmp_dh_callback(3)>).
+This option must be used to prevent small subgroup attacks, when
+the DH parameters were not generated using "strong" primes
+(e.g. when using DSA-parameters, see L<dhparam(1)|dhparam(1)>).
+If "strong" primes were used, it is not strictly necessary to generate
+a new DH key during each handshake but it is also recommended.
+B<SSL_OP_SINGLE_DH_USE> should therefore be enabled whenever
+temporary/ephemeral DH parameters are used.
+
+=item SSL_OP_EPHEMERAL_RSA
+
+Always use ephemeral (temporary) RSA key when doing RSA operations
+(see L<SSL_CTX_set_tmp_rsa_callback(3)|SSL_CTX_set_tmp_rsa_callback(3)>).
+According to the specifications this is only done, when a RSA key
+can only be used for signature operations (namely under export ciphers
+with restricted RSA keylength). By setting this option, ephemeral
+RSA keys are always used. This option breaks compatibility with the
+SSL/TLS specifications and may lead to interoperability problems with
+clients and should therefore never be used. Ciphers with EDH (ephemeral
+Diffie-Hellman) key exchange should be used instead.
+
+=item SSL_OP_CIPHER_SERVER_PREFERENCE
+
+When choosing a cipher, use the server's preferences instead of the client
+preferences. When not set, the SSL server will always follow the clients
+preferences. When set, the SSLv3/TLSv1 server will choose following its
+own preferences. Because of the different protocol, for SSLv2 the server
+will send its list of preferences to the client and the client chooses.
+
+=item SSL_OP_PKCS1_CHECK_1
+
+...
+
+=item SSL_OP_PKCS1_CHECK_2
+
+...
+
+=item SSL_OP_NETSCAPE_CA_DN_BUG
+
+If we accept a netscape connection, demand a client cert, have a
+non-self-signed CA which does not have its CA in netscape, and the
+browser has a cert, it will crash/hang.  Works for 3.x and 4.xbeta 
+
+=item SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG
+
+...
+
+=item SSL_OP_NO_SSLv2
+
+Do not use the SSLv2 protocol.
+
+=item SSL_OP_NO_SSLv3
+
+Do not use the SSLv3 protocol.
+
+=item SSL_OP_NO_TLSv1
+
+Do not use the TLSv1 protocol.
+
+=item SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION
+
+When performing renegotiation as a server, always start a new session
+(i.e., session resumption requests are only accepted in the initial
+handshake). This option is not needed for clients.
+
+=item SSL_OP_NO_TICKET
+
+Normally clients and servers will, where possible, transparently make use
+of RFC4507bis tickets for stateless session resumption.
+
+If this option is set this functionality is disabled and tickets will
+not be used by clients or servers.
+
+=item SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION
+
+Allow legacy insecure renegotiation between OpenSSL and unpatched clients or
+servers. See the B<SECURE RENEGOTIATION> section for more details.
+
+=item SSL_OP_LEGACY_SERVER_CONNECT
+
+Allow legacy insecure renegotiation between OpenSSL and unpatched servers
+B<only>: this option is currently set by default. See the
+B<SECURE RENEGOTIATION> section for more details.
+
+=back
+
+=head1 SECURE RENEGOTIATION
+
+OpenSSL 0.9.8m and later always attempts to use secure renegotiation as
+described in RFC5746. This counters the prefix attack described in
+CVE-2009-3555 and elsewhere.
+
+The deprecated and highly broken SSLv2 protocol does not support
+renegotiation at all: its use is B<strongly> discouraged.
+
+This attack has far reaching consequences which application writers should be
+aware of. In the description below an implementation supporting secure
+renegotiation is referred to as I<patched>. A server not supporting secure
+renegotiation is referred to as I<unpatched>.
+
+The following sections describe the operations permitted by OpenSSL's secure
+renegotiation implementation.
+
+=head2 Patched client and server
+
+Connections and renegotiation are always permitted by OpenSSL implementations.
+
+=head2 Unpatched client and patched OpenSSL server
+
+The initial connection suceeds but client renegotiation is denied by the
+server with a B<no_renegotiation> warning alert if TLS v1.0 is used or a fatal
+B<handshake_failure> alert in SSL v3.0.
+
+If the patched OpenSSL server attempts to renegotiate a fatal
+B<handshake_failure> alert is sent. This is because the server code may be
+unaware of the unpatched nature of the client.
+
+If the option B<SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION> is set then
+renegotiation B<always> succeeds.
+
+B<NB:> a bug in OpenSSL clients earlier than 0.9.8m (all of which are
+unpatched) will result in the connection hanging if it receives a
+B<no_renegotiation> alert. OpenSSL versions 0.9.8m and later will regard
+a B<no_renegotiation> alert as fatal and respond with a fatal
+B<handshake_failure> alert. This is because the OpenSSL API currently has
+no provision to indicate to an application that a renegotiation attempt
+was refused.
+
+=head2 Patched OpenSSL client and unpatched server.
+
+If the option B<SSL_OP_LEGACY_SERVER_CONNECT> or
+B<SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION> is set then initial connections
+and renegotiation between patched OpenSSL clients and unpatched servers
+succeeds. If neither option is set then initial connections to unpatched
+servers will fail.
+
+The option B<SSL_OP_LEGACY_SERVER_CONNECT> is currently set by default even
+though it has security implications: otherwise it would be impossible to
+connect to unpatched servers (i.e. all of them initially) and this is clearly
+not acceptable. Renegotiation is permitted because this does not add any
+additional security issues: during an attack clients do not see any
+renegotiations anyway.
+
+As more servers become patched the option B<SSL_OP_LEGACY_SERVER_CONNECT> will
+B<not> be set by default in a future version of OpenSSL.
+
+OpenSSL client applications wishing to ensure they can connect to unpatched
+servers should always B<set> B<SSL_OP_LEGACY_SERVER_CONNECT>
+
+OpenSSL client applications that want to ensure they can B<not> connect to
+unpatched servers (and thus avoid any security issues) should always B<clear>
+B<SSL_OP_LEGACY_SERVER_CONNECT> using SSL_CTX_clear_options() or
+SSL_clear_options().
+
+The difference between the B<SSL_OP_LEGACY_SERVER_CONNECT> and
+B<SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION> options is that
+B<SSL_OP_LEGACY_SERVER_CONNECT> enables initial connections and secure
+renegotiation between OpenSSL clients and unpatched servers B<only>, while
+B<SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION> allows initial connections
+and renegotiation between OpenSSL and unpatched clients or servers.
+
+=head1 RETURN VALUES
+
+SSL_CTX_set_options() and SSL_set_options() return the new options bitmask
+after adding B<options>.
+
+SSL_CTX_clear_options() and SSL_clear_options() return the new options bitmask
+after clearing B<options>.
+
+SSL_CTX_get_options() and SSL_get_options() return the current bitmask.
+
+SSL_get_secure_renegotiation_support() returns 1 is the peer supports
+secure renegotiation and 0 if it does not.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_new(3)|SSL_new(3)>, L<SSL_clear(3)|SSL_clear(3)>,
+L<SSL_CTX_set_tmp_dh_callback(3)|SSL_CTX_set_tmp_dh_callback(3)>,
+L<SSL_CTX_set_tmp_rsa_callback(3)|SSL_CTX_set_tmp_rsa_callback(3)>,
+L<dhparam(1)|dhparam(1)>
+
+=head1 HISTORY
+
+B<SSL_OP_CIPHER_SERVER_PREFERENCE> and
+B<SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION> have been added in
+OpenSSL 0.9.7.
+
+B<SSL_OP_TLS_ROLLBACK_BUG> has been added in OpenSSL 0.9.6 and was automatically
+enabled with B<SSL_OP_ALL>. As of 0.9.7, it is no longer included in B<SSL_OP_ALL>
+and must be explicitly set.
+
+B<SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS> has been added in OpenSSL 0.9.6e.
+Versions up to OpenSSL 0.9.6c do not include the countermeasure that
+can be disabled with this option (in OpenSSL 0.9.6d, it was always
+enabled).
+
+SSL_CTX_clear_options() and SSL_clear_options() were first added in OpenSSL
+0.9.8m.
+
+B<SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION>, B<SSL_OP_LEGACY_SERVER_CONNECT>
+and the function SSL_get_secure_renegotiation_support() were first added in
+OpenSSL 0.9.8m.
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_set_psk_client_callback.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_set_psk_client_callback.pod
new file mode 100644 (file)
index 0000000..573f89a
--- /dev/null
@@ -0,0 +1,81 @@
+=pod
+
+=begin comment
+
+Copyright 2005 Nokia. All rights reserved.
+
+The portions of the attached software ("Contribution") is developed by
+Nokia Corporation and is licensed pursuant to the OpenSSL open source
+license.
+
+The Contribution, originally written by Mika Kousa and Pasi Eronen of
+Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
+support (see RFC 4279) to OpenSSL.
+
+No patent licenses or other rights except those expressly stated in
+the OpenSSL open source license shall be deemed granted or received
+expressly, by implication, estoppel, or otherwise.
+
+No assurances are provided by Nokia that the Contribution does not
+infringe the patent or other intellectual property rights of any third
+party or that the license provides you with all the necessary rights
+to make use of the Contribution.
+
+THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
+ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
+SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
+OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
+OTHERWISE.
+
+=end comment
+
+=head1 NAME
+
+SSL_CTX_set_psk_client_callback, SSL_set_psk_client_callback - set PSK client callback
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ void SSL_CTX_set_psk_client_callback(SSL_CTX *ctx,
+       unsigned int (*callback)(SSL *ssl, const char *hint,
+       char *identity, unsigned int max_identity_len,
+       unsigned char *psk, unsigned int max_psk_len));
+ void SSL_set_psk_client_callback(SSL *ssl,
+       unsigned int (*callback)(SSL *ssl, const char *hint,
+       char *identity, unsigned int max_identity_len,
+       unsigned char *psk, unsigned int max_psk_len));
+
+
+=head1 DESCRIPTION
+
+A client application must provide a callback function which is called
+when the client is sending the ClientKeyExchange message to the server.
+
+The purpose of the callback function is to select the PSK identity and
+the pre-shared key to use during the connection setup phase.
+
+The callback is set using functions SSL_CTX_set_psk_client_callback()
+or SSL_set_psk_client_callback(). The callback function is given the
+connection in parameter B<ssl>, a B<NULL>-terminated PSK identity hint
+sent by the server in parameter B<hint>, a buffer B<identity> of
+length B<max_identity_len> bytes where the the resulting
+B<NULL>-terminated identity is to be stored, and a buffer B<psk> of
+length B<max_psk_len> bytes where the resulting pre-shared key is to
+be stored.
+
+=head1 NOTES
+
+Note that parameter B<hint> given to the callback may be B<NULL>.
+
+=head1 RETURN VALUES
+
+Return values from the client callback are interpreted as follows:
+
+On success (callback found a PSK identity and a pre-shared key to use)
+the length (> 0) of B<psk> in bytes is returned.
+
+Otherwise or on errors callback should return 0. In this case
+the connection setup fails.
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_set_quiet_shutdown.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_set_quiet_shutdown.pod
new file mode 100644 (file)
index 0000000..393f8ff
--- /dev/null
@@ -0,0 +1,63 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_set_quiet_shutdown, SSL_CTX_get_quiet_shutdown, SSL_set_quiet_shutdown, SSL_get_quiet_shutdown - manipulate shutdown behaviour
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx, int mode);
+ int SSL_CTX_get_quiet_shutdown(const SSL_CTX *ctx);
+
+ void SSL_set_quiet_shutdown(SSL *ssl, int mode);
+ int SSL_get_quiet_shutdown(const SSL *ssl);
+
+=head1 DESCRIPTION
+
+SSL_CTX_set_quiet_shutdown() sets the "quiet shutdown" flag for B<ctx> to be
+B<mode>. SSL objects created from B<ctx> inherit the B<mode> valid at the time
+L<SSL_new(3)|SSL_new(3)> is called. B<mode> may be 0 or 1.
+
+SSL_CTX_get_quiet_shutdown() returns the "quiet shutdown" setting of B<ctx>.
+
+SSL_set_quiet_shutdown() sets the "quiet shutdown" flag for B<ssl> to be
+B<mode>. The setting stays valid until B<ssl> is removed with
+L<SSL_free(3)|SSL_free(3)> or SSL_set_quiet_shutdown() is called again.
+It is not changed when L<SSL_clear(3)|SSL_clear(3)> is called.
+B<mode> may be 0 or 1.
+
+SSL_get_quiet_shutdown() returns the "quiet shutdown" setting of B<ssl>.
+
+=head1 NOTES
+
+Normally when a SSL connection is finished, the parties must send out
+"close notify" alert messages using L<SSL_shutdown(3)|SSL_shutdown(3)>
+for a clean shutdown.
+
+When setting the "quiet shutdown" flag to 1, L<SSL_shutdown(3)|SSL_shutdown(3)>
+will set the internal flags to SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN.
+(L<SSL_shutdown(3)|SSL_shutdown(3)> then behaves like
+L<SSL_set_shutdown(3)|SSL_set_shutdown(3)> called with
+SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN.)
+The session is thus considered to be shutdown, but no "close notify" alert
+is sent to the peer. This behaviour violates the TLS standard.
+
+The default is normal shutdown behaviour as described by the TLS standard.
+
+=head1 RETURN VALUES
+
+SSL_CTX_set_quiet_shutdown() and SSL_set_quiet_shutdown() do not return
+diagnostic information.
+
+SSL_CTX_get_quiet_shutdown() and SSL_get_quiet_shutdown return the current
+setting.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_shutdown(3)|SSL_shutdown(3)>,
+L<SSL_set_shutdown(3)|SSL_set_shutdown(3)>, L<SSL_new(3)|SSL_new(3)>,
+L<SSL_clear(3)|SSL_clear(3)>, L<SSL_free(3)|SSL_free(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_set_session_cache_mode.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_set_session_cache_mode.pod
new file mode 100644 (file)
index 0000000..c5d2f43
--- /dev/null
@@ -0,0 +1,137 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_set_session_cache_mode, SSL_CTX_get_session_cache_mode - enable/disable session caching
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ long SSL_CTX_set_session_cache_mode(SSL_CTX ctx, long mode);
+ long SSL_CTX_get_session_cache_mode(SSL_CTX ctx);
+
+=head1 DESCRIPTION
+
+SSL_CTX_set_session_cache_mode() enables/disables session caching
+by setting the operational mode for B<ctx> to <mode>.
+
+SSL_CTX_get_session_cache_mode() returns the currently used cache mode.
+
+=head1 NOTES
+
+The OpenSSL library can store/retrieve SSL/TLS sessions for later reuse.
+The sessions can be held in memory for each B<ctx>, if more than one
+SSL_CTX object is being maintained, the sessions are unique for each SSL_CTX
+object.
+
+In order to reuse a session, a client must send the session's id to the
+server. It can only send exactly one id.  The server then either 
+agrees to reuse the session or it starts a full handshake (to create a new
+session).
+
+A server will lookup up the session in its internal session storage. If the
+session is not found in internal storage or lookups for the internal storage
+have been deactivated (SSL_SESS_CACHE_NO_INTERNAL_LOOKUP), the server will try
+the external storage if available.
+
+Since a client may try to reuse a session intended for use in a different
+context, the session id context must be set by the server (see
+L<SSL_CTX_set_session_id_context(3)|SSL_CTX_set_session_id_context(3)>).
+
+The following session cache modes and modifiers are available:
+
+=over 4
+
+=item SSL_SESS_CACHE_OFF
+
+No session caching for client or server takes place.
+
+=item SSL_SESS_CACHE_CLIENT
+
+Client sessions are added to the session cache. As there is no reliable way
+for the OpenSSL library to know whether a session should be reused or which
+session to choose (due to the abstract BIO layer the SSL engine does not
+have details about the connection), the application must select the session
+to be reused by using the L<SSL_set_session(3)|SSL_set_session(3)>
+function. This option is not activated by default.
+
+=item SSL_SESS_CACHE_SERVER
+
+Server sessions are added to the session cache. When a client proposes a
+session to be reused, the server looks for the corresponding session in (first)
+the internal session cache (unless SSL_SESS_CACHE_NO_INTERNAL_LOOKUP is set),
+then (second) in the external cache if available. If the session is found, the
+server will try to reuse the session.  This is the default.
+
+=item SSL_SESS_CACHE_BOTH
+
+Enable both SSL_SESS_CACHE_CLIENT and SSL_SESS_CACHE_SERVER at the same time.
+
+=item SSL_SESS_CACHE_NO_AUTO_CLEAR
+
+Normally the session cache is checked for expired sessions every
+255 connections using the
+L<SSL_CTX_flush_sessions(3)|SSL_CTX_flush_sessions(3)> function. Since
+this may lead to a delay which cannot be controlled, the automatic
+flushing may be disabled and
+L<SSL_CTX_flush_sessions(3)|SSL_CTX_flush_sessions(3)> can be called
+explicitly by the application.
+
+=item SSL_SESS_CACHE_NO_INTERNAL_LOOKUP
+
+By setting this flag, session-resume operations in an SSL/TLS server will not
+automatically look up sessions in the internal cache, even if sessions are
+automatically stored there. If external session caching callbacks are in use,
+this flag guarantees that all lookups are directed to the external cache.
+As automatic lookup only applies for SSL/TLS servers, the flag has no effect on
+clients.
+
+=item SSL_SESS_CACHE_NO_INTERNAL_STORE
+
+Depending on the presence of SSL_SESS_CACHE_CLIENT and/or SSL_SESS_CACHE_SERVER,
+sessions negotiated in an SSL/TLS handshake may be cached for possible reuse.
+Normally a new session is added to the internal cache as well as any external
+session caching (callback) that is configured for the SSL_CTX. This flag will
+prevent sessions being stored in the internal cache (though the application can
+add them manually using L<SSL_CTX_add_session(3)|SSL_CTX_add_session(3)>). Note:
+in any SSL/TLS servers where external caching is configured, any successful
+session lookups in the external cache (ie. for session-resume requests) would
+normally be copied into the local cache before processing continues - this flag
+prevents these additions to the internal cache as well.
+
+=item SSL_SESS_CACHE_NO_INTERNAL
+
+Enable both SSL_SESS_CACHE_NO_INTERNAL_LOOKUP and
+SSL_SESS_CACHE_NO_INTERNAL_STORE at the same time.
+
+
+=back
+
+The default mode is SSL_SESS_CACHE_SERVER.
+
+=head1 RETURN VALUES
+
+SSL_CTX_set_session_cache_mode() returns the previously set cache mode.
+
+SSL_CTX_get_session_cache_mode() returns the currently set cache mode.
+
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_set_session(3)|SSL_set_session(3)>,
+L<SSL_session_reused(3)|SSL_session_reused(3)>,
+L<SSL_CTX_add_session(3)|SSL_CTX_add_session(3)>,
+L<SSL_CTX_sess_number(3)|SSL_CTX_sess_number(3)>,
+L<SSL_CTX_sess_set_cache_size(3)|SSL_CTX_sess_set_cache_size(3)>,
+L<SSL_CTX_sess_set_get_cb(3)|SSL_CTX_sess_set_get_cb(3)>,
+L<SSL_CTX_set_session_id_context(3)|SSL_CTX_set_session_id_context(3)>,
+L<SSL_CTX_set_timeout(3)|SSL_CTX_set_timeout(3)>,
+L<SSL_CTX_flush_sessions(3)|SSL_CTX_flush_sessions(3)>
+
+=head1 HISTORY
+
+SSL_SESS_CACHE_NO_INTERNAL_STORE and SSL_SESS_CACHE_NO_INTERNAL
+were introduced in OpenSSL 0.9.6h.
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_set_session_id_context.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_set_session_id_context.pod
new file mode 100644 (file)
index 0000000..58fc685
--- /dev/null
@@ -0,0 +1,83 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_set_session_id_context, SSL_set_session_id_context - set context within which session can be reused (server side only)
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_CTX_set_session_id_context(SSL_CTX *ctx, const unsigned char *sid_ctx,
+                                    unsigned int sid_ctx_len);
+ int SSL_set_session_id_context(SSL *ssl, const unsigned char *sid_ctx,
+                                unsigned int sid_ctx_len);
+
+=head1 DESCRIPTION
+
+SSL_CTX_set_session_id_context() sets the context B<sid_ctx> of length
+B<sid_ctx_len> within which a session can be reused for the B<ctx> object.
+
+SSL_set_session_id_context() sets the context B<sid_ctx> of length
+B<sid_ctx_len> within which a session can be reused for the B<ssl> object.
+
+=head1 NOTES
+
+Sessions are generated within a certain context. When exporting/importing
+sessions with B<i2d_SSL_SESSION>/B<d2i_SSL_SESSION> it would be possible,
+to re-import a session generated from another context (e.g. another
+application), which might lead to malfunctions. Therefore each application
+must set its own session id context B<sid_ctx> which is used to distinguish
+the contexts and is stored in exported sessions. The B<sid_ctx> can be
+any kind of binary data with a given length, it is therefore possible
+to use e.g. the name of the application and/or the hostname and/or service
+name ...
+
+The session id context becomes part of the session. The session id context
+is set by the SSL/TLS server. The SSL_CTX_set_session_id_context() and
+SSL_set_session_id_context() functions are therefore only useful on the
+server side.
+
+OpenSSL clients will check the session id context returned by the server
+when reusing a session.
+
+The maximum length of the B<sid_ctx> is limited to
+B<SSL_MAX_SSL_SESSION_ID_LENGTH>.
+
+=head1 WARNINGS
+
+If the session id context is not set on an SSL/TLS server and client
+certificates are used, stored sessions
+will not be reused but a fatal error will be flagged and the handshake
+will fail.
+
+If a server returns a different session id context to an OpenSSL client
+when reusing a session, an error will be flagged and the handshake will
+fail. OpenSSL servers will always return the correct session id context,
+as an OpenSSL server checks the session id context itself before reusing
+a session as described above.
+
+=head1 RETURN VALUES
+
+SSL_CTX_set_session_id_context() and SSL_set_session_id_context()
+return the following values:
+
+=over 4
+
+=item 0
+
+The length B<sid_ctx_len> of the session id context B<sid_ctx> exceeded
+the maximum allowed length of B<SSL_MAX_SSL_SESSION_ID_LENGTH>. The error
+is logged to the error stack.
+
+=item 1
+
+The operation succeeded.
+
+=back
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_set_ssl_version.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_set_ssl_version.pod
new file mode 100644 (file)
index 0000000..254f2b4
--- /dev/null
@@ -0,0 +1,61 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_set_ssl_version, SSL_set_ssl_method, SSL_get_ssl_method
+- choose a new TLS/SSL method
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *method);
+ int SSL_set_ssl_method(SSL *s, const SSL_METHOD *method);
+ const SSL_METHOD *SSL_get_ssl_method(SSL *ssl);
+
+=head1 DESCRIPTION
+
+SSL_CTX_set_ssl_version() sets a new default TLS/SSL B<method> for SSL objects
+newly created from this B<ctx>. SSL objects already created with
+L<SSL_new(3)|SSL_new(3)> are not affected, except when
+L<SSL_clear(3)|SSL_clear(3)> is being called.
+
+SSL_set_ssl_method() sets a new TLS/SSL B<method> for a particular B<ssl>
+object. It may be reset, when SSL_clear() is called.
+
+SSL_get_ssl_method() returns a function pointer to the TLS/SSL method
+set in B<ssl>.
+
+=head1 NOTES
+
+The available B<method> choices are described in
+L<SSL_CTX_new(3)|SSL_CTX_new(3)>.
+
+When L<SSL_clear(3)|SSL_clear(3)> is called and no session is connected to
+an SSL object, the method of the SSL object is reset to the method currently
+set in the corresponding SSL_CTX object.
+
+=head1 RETURN VALUES
+
+The following return values can occur for SSL_CTX_set_ssl_version()
+and SSL_set_ssl_method():
+
+=over 4
+
+=item 0
+
+The new choice failed, check the error stack to find out the reason.
+
+=item 1
+
+The operation succeeded.
+
+=back
+
+=head1 SEE ALSO
+
+L<SSL_CTX_new(3)|SSL_CTX_new(3)>, L<SSL_new(3)|SSL_new(3)>,
+L<SSL_clear(3)|SSL_clear(3)>, L<ssl(3)|ssl(3)>,
+L<SSL_set_connect_state(3)|SSL_set_connect_state(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_set_timeout.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_set_timeout.pod
new file mode 100644 (file)
index 0000000..e3de27c
--- /dev/null
@@ -0,0 +1,59 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_set_timeout, SSL_CTX_get_timeout - manipulate timeout values for session caching
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ long SSL_CTX_set_timeout(SSL_CTX *ctx, long t);
+ long SSL_CTX_get_timeout(SSL_CTX *ctx);
+
+=head1 DESCRIPTION
+
+SSL_CTX_set_timeout() sets the timeout for newly created sessions for
+B<ctx> to B<t>. The timeout value B<t> must be given in seconds.
+
+SSL_CTX_get_timeout() returns the currently set timeout value for B<ctx>.
+
+=head1 NOTES
+
+Whenever a new session is created, it is assigned a maximum lifetime. This
+lifetime is specified by storing the creation time of the session and the
+timeout value valid at this time. If the actual time is later than creation
+time plus timeout, the session is not reused.
+
+Due to this realization, all sessions behave according to the timeout value
+valid at the time of the session negotiation. Changes of the timeout value
+do not affect already established sessions.
+
+The expiration time of a single session can be modified using the
+L<SSL_SESSION_get_time(3)|SSL_SESSION_get_time(3)> family of functions.
+
+Expired sessions are removed from the internal session cache, whenever
+L<SSL_CTX_flush_sessions(3)|SSL_CTX_flush_sessions(3)> is called, either
+directly by the application or automatically (see
+L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>)
+
+The default value for session timeout is decided on a per protocol
+basis, see L<SSL_get_default_timeout(3)|SSL_get_default_timeout(3)>.
+All currently supported protocols have the same default timeout value
+of 300 seconds.
+
+=head1 RETURN VALUES
+
+SSL_CTX_set_timeout() returns the previously set timeout value.
+
+SSL_CTX_get_timeout() returns the currently set timeout value.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>,
+L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>,
+L<SSL_SESSION_get_time(3)|SSL_SESSION_get_time(3)>,
+L<SSL_CTX_flush_sessions(3)|SSL_CTX_flush_sessions(3)>,
+L<SSL_get_default_timeout(3)|SSL_get_default_timeout(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_set_tmp_dh_callback.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_set_tmp_dh_callback.pod
new file mode 100644 (file)
index 0000000..29d1f8a
--- /dev/null
@@ -0,0 +1,170 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_set_tmp_dh_callback, SSL_CTX_set_tmp_dh, SSL_set_tmp_dh_callback, SSL_set_tmp_dh - handle DH keys for ephemeral key exchange
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,
+            DH *(*tmp_dh_callback)(SSL *ssl, int is_export, int keylength));
+ long SSL_CTX_set_tmp_dh(SSL_CTX *ctx, DH *dh);
+
+ void SSL_set_tmp_dh_callback(SSL_CTX *ctx,
+            DH *(*tmp_dh_callback)(SSL *ssl, int is_export, int keylength));
+ long SSL_set_tmp_dh(SSL *ssl, DH *dh)
+
+ DH *(*tmp_dh_callback)(SSL *ssl, int is_export, int keylength));
+
+=head1 DESCRIPTION
+
+SSL_CTX_set_tmp_dh_callback() sets the callback function for B<ctx> to be
+used when a DH parameters are required to B<tmp_dh_callback>.
+The callback is inherited by all B<ssl> objects created from B<ctx>.
+
+SSL_CTX_set_tmp_dh() sets DH parameters to be used to be B<dh>.
+The key is inherited by all B<ssl> objects created from B<ctx>.
+
+SSL_set_tmp_dh_callback() sets the callback only for B<ssl>.
+
+SSL_set_tmp_dh() sets the parameters only for B<ssl>.
+
+These functions apply to SSL/TLS servers only.
+
+=head1 NOTES
+
+When using a cipher with RSA authentication, an ephemeral DH key exchange
+can take place. Ciphers with DSA keys always use ephemeral DH keys as well.
+In these cases, the session data are negotiated using the
+ephemeral/temporary DH key and the key supplied and certified
+by the certificate chain is only used for signing.
+Anonymous ciphers (without a permanent server key) also use ephemeral DH keys.
+
+Using ephemeral DH key exchange yields forward secrecy, as the connection
+can only be decrypted, when the DH key is known. By generating a temporary
+DH key inside the server application that is lost when the application
+is left, it becomes impossible for an attacker to decrypt past sessions,
+even if he gets hold of the normal (certified) key, as this key was
+only used for signing.
+
+In order to perform a DH key exchange the server must use a DH group
+(DH parameters) and generate a DH key. The server will always generate a new
+DH key during the negotiation, when the DH parameters are supplied via
+callback and/or when the SSL_OP_SINGLE_DH_USE option of
+L<SSL_CTX_set_options(3)|SSL_CTX_set_options(3)> is set. It will
+immediately create a DH key, when DH parameters are supplied via
+SSL_CTX_set_tmp_dh() and SSL_OP_SINGLE_DH_USE is not set. In this case,
+it may happen that a key is generated on initialization without later
+being needed, while on the other hand the computer time during the
+negotiation is being saved.
+
+If "strong" primes were used to generate the DH parameters, it is not strictly
+necessary to generate a new key for each handshake but it does improve forward
+secrecy. If it is not assured, that "strong" primes were used (see especially
+the section about DSA parameters below), SSL_OP_SINGLE_DH_USE must be used
+in order to prevent small subgroup attacks. Always using SSL_OP_SINGLE_DH_USE
+has an impact on the computer time needed during negotiation, but it is not
+very large, so application authors/users should consider to always enable
+this option.
+
+As generating DH parameters is extremely time consuming, an application
+should not generate the parameters on the fly but supply the parameters.
+DH parameters can be reused, as the actual key is newly generated during
+the negotiation. The risk in reusing DH parameters is that an attacker
+may specialize on a very often used DH group. Applications should therefore
+generate their own DH parameters during the installation process using the
+openssl L<dhparam(1)|dhparam(1)> application. In order to reduce the computer
+time needed for this generation, it is possible to use DSA parameters
+instead (see L<dhparam(1)|dhparam(1)>), but in this case SSL_OP_SINGLE_DH_USE
+is mandatory.
+
+Application authors may compile in DH parameters. Files dh512.pem,
+dh1024.pem, dh2048.pem, and dh4096 in the 'apps' directory of current
+version of the OpenSSL distribution contain the 'SKIP' DH parameters,
+which use safe primes and were generated verifiably pseudo-randomly.
+These files can be converted into C code using the B<-C> option of the
+L<dhparam(1)|dhparam(1)> application.
+Authors may also generate their own set of parameters using
+L<dhparam(1)|dhparam(1)>, but a user may not be sure how the parameters were
+generated. The generation of DH parameters during installation is therefore
+recommended.
+
+An application may either directly specify the DH parameters or
+can supply the DH parameters via a callback function. The callback approach
+has the advantage, that the callback may supply DH parameters for different
+key lengths.
+
+The B<tmp_dh_callback> is called with the B<keylength> needed and
+the B<is_export> information. The B<is_export> flag is set, when the
+ephemeral DH key exchange is performed with an export cipher.
+
+=head1 EXAMPLES
+
+Handle DH parameters for key lengths of 512 and 1024 bits. (Error handling
+partly left out.)
+
+ ...
+ /* Set up ephemeral DH stuff */
+ DH *dh_512 = NULL;
+ DH *dh_1024 = NULL;
+ FILE *paramfile;
+
+ ...
+ /* "openssl dhparam -out dh_param_512.pem -2 512" */
+ paramfile = fopen("dh_param_512.pem", "r");
+ if (paramfile) {
+   dh_512 = PEM_read_DHparams(paramfile, NULL, NULL, NULL);
+   fclose(paramfile);
+ }
+ /* "openssl dhparam -out dh_param_1024.pem -2 1024" */
+ paramfile = fopen("dh_param_1024.pem", "r");
+ if (paramfile) {
+   dh_1024 = PEM_read_DHparams(paramfile, NULL, NULL, NULL);
+   fclose(paramfile);
+ }
+ ...
+
+ /* "openssl dhparam -C -2 512" etc... */
+ DH *get_dh512() { ... }
+ DH *get_dh1024() { ... }
+
+ DH *tmp_dh_callback(SSL *s, int is_export, int keylength)
+ {
+    DH *dh_tmp=NULL;
+
+    switch (keylength) {
+    case 512:
+      if (!dh_512)
+        dh_512 = get_dh512();
+      dh_tmp = dh_512;
+      break;
+    case 1024:
+      if (!dh_1024) 
+        dh_1024 = get_dh1024();
+      dh_tmp = dh_1024;
+      break;
+    default:
+      /* Generating a key on the fly is very costly, so use what is there */
+      setup_dh_parameters_like_above();
+    }
+    return(dh_tmp);
+ }
+
+=head1 RETURN VALUES
+
+SSL_CTX_set_tmp_dh_callback() and SSL_set_tmp_dh_callback() do not return
+diagnostic output.
+
+SSL_CTX_set_tmp_dh() and SSL_set_tmp_dh() do return 1 on success and 0
+on failure. Check the error queue to find out the reason of failure.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_CTX_set_cipher_list(3)|SSL_CTX_set_cipher_list(3)>,
+L<SSL_CTX_set_tmp_rsa_callback(3)|SSL_CTX_set_tmp_rsa_callback(3)>,
+L<SSL_CTX_set_options(3)|SSL_CTX_set_options(3)>,
+L<ciphers(1)|ciphers(1)>, L<dhparam(1)|dhparam(1)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_set_tmp_rsa_callback.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_set_tmp_rsa_callback.pod
new file mode 100644 (file)
index 0000000..534643c
--- /dev/null
@@ -0,0 +1,166 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_set_tmp_rsa_callback, SSL_CTX_set_tmp_rsa, SSL_CTX_need_tmp_rsa, SSL_set_tmp_rsa_callback, SSL_set_tmp_rsa, SSL_need_tmp_rsa - handle RSA keys for ephemeral key exchange
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,
+            RSA *(*tmp_rsa_callback)(SSL *ssl, int is_export, int keylength));
+ long SSL_CTX_set_tmp_rsa(SSL_CTX *ctx, RSA *rsa);
+ long SSL_CTX_need_tmp_rsa(SSL_CTX *ctx);
+
+ void SSL_set_tmp_rsa_callback(SSL_CTX *ctx,
+            RSA *(*tmp_rsa_callback)(SSL *ssl, int is_export, int keylength));
+ long SSL_set_tmp_rsa(SSL *ssl, RSA *rsa)
+ long SSL_need_tmp_rsa(SSL *ssl)
+
+ RSA *(*tmp_rsa_callback)(SSL *ssl, int is_export, int keylength);
+
+=head1 DESCRIPTION
+
+SSL_CTX_set_tmp_rsa_callback() sets the callback function for B<ctx> to be
+used when a temporary/ephemeral RSA key is required to B<tmp_rsa_callback>.
+The callback is inherited by all SSL objects newly created from B<ctx>
+with <SSL_new(3)|SSL_new(3)>. Already created SSL objects are not affected.
+
+SSL_CTX_set_tmp_rsa() sets the temporary/ephemeral RSA key to be used to be
+B<rsa>. The key is inherited by all SSL objects newly created from B<ctx>
+with <SSL_new(3)|SSL_new(3)>. Already created SSL objects are not affected.
+
+SSL_CTX_need_tmp_rsa() returns 1, if a temporary/ephemeral RSA key is needed
+for RSA-based strength-limited 'exportable' ciphersuites because a RSA key
+with a keysize larger than 512 bits is installed.
+
+SSL_set_tmp_rsa_callback() sets the callback only for B<ssl>.
+
+SSL_set_tmp_rsa() sets the key only for B<ssl>.
+
+SSL_need_tmp_rsa() returns 1, if a temporary/ephemeral RSA key is needed,
+for RSA-based strength-limited 'exportable' ciphersuites because a RSA key
+with a keysize larger than 512 bits is installed.
+
+These functions apply to SSL/TLS servers only.
+
+=head1 NOTES
+
+When using a cipher with RSA authentication, an ephemeral RSA key exchange
+can take place. In this case the session data are negotiated using the
+ephemeral/temporary RSA key and the RSA key supplied and certified
+by the certificate chain is only used for signing.
+
+Under previous export restrictions, ciphers with RSA keys shorter (512 bits)
+than the usual key length of 1024 bits were created. To use these ciphers
+with RSA keys of usual length, an ephemeral key exchange must be performed,
+as the normal (certified) key cannot be directly used.
+
+Using ephemeral RSA key exchange yields forward secrecy, as the connection
+can only be decrypted, when the RSA key is known. By generating a temporary
+RSA key inside the server application that is lost when the application
+is left, it becomes impossible for an attacker to decrypt past sessions,
+even if he gets hold of the normal (certified) RSA key, as this key was
+used for signing only. The downside is that creating a RSA key is
+computationally expensive.
+
+Additionally, the use of ephemeral RSA key exchange is only allowed in
+the TLS standard, when the RSA key can be used for signing only, that is
+for export ciphers. Using ephemeral RSA key exchange for other purposes
+violates the standard and can break interoperability with clients.
+It is therefore strongly recommended to not use ephemeral RSA key
+exchange and use EDH (Ephemeral Diffie-Hellman) key exchange instead
+in order to achieve forward secrecy (see
+L<SSL_CTX_set_tmp_dh_callback(3)|SSL_CTX_set_tmp_dh_callback(3)>).
+
+On OpenSSL servers ephemeral RSA key exchange is therefore disabled by default
+and must be explicitly enabled  using the SSL_OP_EPHEMERAL_RSA option of
+L<SSL_CTX_set_options(3)|SSL_CTX_set_options(3)>, violating the TLS/SSL
+standard. When ephemeral RSA key exchange is required for export ciphers,
+it will automatically be used without this option!
+
+An application may either directly specify the key or can supply the key via
+a callback function. The callback approach has the advantage, that the
+callback may generate the key only in case it is actually needed. As the
+generation of a RSA key is however costly, it will lead to a significant
+delay in the handshake procedure.  Another advantage of the callback function
+is that it can supply keys of different size (e.g. for SSL_OP_EPHEMERAL_RSA
+usage) while the explicit setting of the key is only useful for key size of
+512 bits to satisfy the export restricted ciphers and does give away key length
+if a longer key would be allowed.
+
+The B<tmp_rsa_callback> is called with the B<keylength> needed and
+the B<is_export> information. The B<is_export> flag is set, when the
+ephemeral RSA key exchange is performed with an export cipher.
+
+=head1 EXAMPLES
+
+Generate temporary RSA keys to prepare ephemeral RSA key exchange. As the
+generation of a RSA key costs a lot of computer time, they saved for later
+reuse. For demonstration purposes, two keys for 512 bits and 1024 bits
+respectively are generated.
+
+ ...
+ /* Set up ephemeral RSA stuff */
+ RSA *rsa_512 = NULL;
+ RSA *rsa_1024 = NULL;
+
+ rsa_512 = RSA_generate_key(512,RSA_F4,NULL,NULL);
+ if (rsa_512 == NULL)
+     evaluate_error_queue();
+
+ rsa_1024 = RSA_generate_key(1024,RSA_F4,NULL,NULL);
+ if (rsa_1024 == NULL)
+   evaluate_error_queue();
+
+ ...
+
+ RSA *tmp_rsa_callback(SSL *s, int is_export, int keylength)
+ {
+    RSA *rsa_tmp=NULL;
+
+    switch (keylength) {
+    case 512:
+      if (rsa_512)
+        rsa_tmp = rsa_512;
+      else { /* generate on the fly, should not happen in this example */
+        rsa_tmp = RSA_generate_key(keylength,RSA_F4,NULL,NULL);
+        rsa_512 = rsa_tmp; /* Remember for later reuse */
+      }
+      break;
+    case 1024:
+      if (rsa_1024)
+        rsa_tmp=rsa_1024;
+      else
+        should_not_happen_in_this_example();
+      break;
+    default:
+      /* Generating a key on the fly is very costly, so use what is there */
+      if (rsa_1024)
+        rsa_tmp=rsa_1024;
+      else
+        rsa_tmp=rsa_512; /* Use at least a shorter key */
+    }
+    return(rsa_tmp);
+ }
+
+=head1 RETURN VALUES
+
+SSL_CTX_set_tmp_rsa_callback() and SSL_set_tmp_rsa_callback() do not return
+diagnostic output.
+
+SSL_CTX_set_tmp_rsa() and SSL_set_tmp_rsa() do return 1 on success and 0
+on failure. Check the error queue to find out the reason of failure.
+
+SSL_CTX_need_tmp_rsa() and SSL_need_tmp_rsa() return 1 if a temporary
+RSA key is needed and 0 otherwise.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_CTX_set_cipher_list(3)|SSL_CTX_set_cipher_list(3)>,
+L<SSL_CTX_set_options(3)|SSL_CTX_set_options(3)>,
+L<SSL_CTX_set_tmp_dh_callback(3)|SSL_CTX_set_tmp_dh_callback(3)>,
+L<SSL_new(3)|SSL_new(3)>, L<ciphers(1)|ciphers(1)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_set_verify.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_set_verify.pod
new file mode 100644 (file)
index 0000000..8156683
--- /dev/null
@@ -0,0 +1,294 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_set_verify, SSL_set_verify, SSL_CTX_set_verify_depth, SSL_set_verify_depth - set peer certificate verification parameters
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ void SSL_CTX_set_verify(SSL_CTX *ctx, int mode,
+                         int (*verify_callback)(int, X509_STORE_CTX *));
+ void SSL_set_verify(SSL *s, int mode,
+                     int (*verify_callback)(int, X509_STORE_CTX *));
+ void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth);
+ void SSL_set_verify_depth(SSL *s, int depth);
+
+ int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx);
+
+=head1 DESCRIPTION
+
+SSL_CTX_set_verify() sets the verification flags for B<ctx> to be B<mode> and
+specifies the B<verify_callback> function to be used. If no callback function
+shall be specified, the NULL pointer can be used for B<verify_callback>.
+
+SSL_set_verify() sets the verification flags for B<ssl> to be B<mode> and
+specifies the B<verify_callback> function to be used. If no callback function
+shall be specified, the NULL pointer can be used for B<verify_callback>. In
+this case last B<verify_callback> set specifically for this B<ssl> remains. If
+no special B<callback> was set before, the default callback for the underlying
+B<ctx> is used, that was valid at the time B<ssl> was created with
+L<SSL_new(3)|SSL_new(3)>.
+
+SSL_CTX_set_verify_depth() sets the maximum B<depth> for the certificate chain
+verification that shall be allowed for B<ctx>. (See the BUGS section.)
+
+SSL_set_verify_depth() sets the maximum B<depth> for the certificate chain
+verification that shall be allowed for B<ssl>. (See the BUGS section.)
+
+=head1 NOTES
+
+The verification of certificates can be controlled by a set of logically
+or'ed B<mode> flags:
+
+=over 4
+
+=item SSL_VERIFY_NONE
+
+B<Server mode:> the server will not send a client certificate request to the
+client, so the client will not send a certificate.
+
+B<Client mode:> if not using an anonymous cipher (by default disabled), the
+server will send a certificate which will be checked. The result of the
+certificate verification process can be checked after the TLS/SSL handshake
+using the L<SSL_get_verify_result(3)|SSL_get_verify_result(3)> function.
+The handshake will be continued regardless of the verification result.
+
+=item SSL_VERIFY_PEER
+
+B<Server mode:> the server sends a client certificate request to the client.
+The certificate returned (if any) is checked. If the verification process
+fails, the TLS/SSL handshake is
+immediately terminated with an alert message containing the reason for
+the verification failure.
+The behaviour can be controlled by the additional
+SSL_VERIFY_FAIL_IF_NO_PEER_CERT and SSL_VERIFY_CLIENT_ONCE flags.
+
+B<Client mode:> the server certificate is verified. If the verification process
+fails, the TLS/SSL handshake is
+immediately terminated with an alert message containing the reason for
+the verification failure. If no server certificate is sent, because an
+anonymous cipher is used, SSL_VERIFY_PEER is ignored.
+
+=item SSL_VERIFY_FAIL_IF_NO_PEER_CERT
+
+B<Server mode:> if the client did not return a certificate, the TLS/SSL
+handshake is immediately terminated with a "handshake failure" alert.
+This flag must be used together with SSL_VERIFY_PEER.
+
+B<Client mode:> ignored
+
+=item SSL_VERIFY_CLIENT_ONCE
+
+B<Server mode:> only request a client certificate on the initial TLS/SSL
+handshake. Do not ask for a client certificate again in case of a
+renegotiation. This flag must be used together with SSL_VERIFY_PEER.
+
+B<Client mode:> ignored
+
+=back
+
+Exactly one of the B<mode> flags SSL_VERIFY_NONE and SSL_VERIFY_PEER must be
+set at any time.
+
+The actual verification procedure is performed either using the built-in
+verification procedure or using another application provided verification
+function set with
+L<SSL_CTX_set_cert_verify_callback(3)|SSL_CTX_set_cert_verify_callback(3)>.
+The following descriptions apply in the case of the built-in procedure. An
+application provided procedure also has access to the verify depth information
+and the verify_callback() function, but the way this information is used
+may be different.
+
+SSL_CTX_set_verify_depth() and SSL_set_verify_depth() set the limit up
+to which depth certificates in a chain are used during the verification
+procedure. If the certificate chain is longer than allowed, the certificates
+above the limit are ignored. Error messages are generated as if these
+certificates would not be present, most likely a
+X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY will be issued.
+The depth count is "level 0:peer certificate", "level 1: CA certificate",
+"level 2: higher level CA certificate", and so on. Setting the maximum
+depth to 2 allows the levels 0, 1, and 2. The default depth limit is 9,
+allowing for the peer certificate and additional 9 CA certificates.
+
+The B<verify_callback> function is used to control the behaviour when the
+SSL_VERIFY_PEER flag is set. It must be supplied by the application and
+receives two arguments: B<preverify_ok> indicates, whether the verification of
+the certificate in question was passed (preverify_ok=1) or not
+(preverify_ok=0). B<x509_ctx> is a pointer to the complete context used
+for the certificate chain verification.
+
+The certificate chain is checked starting with the deepest nesting level
+(the root CA certificate) and worked upward to the peer's certificate.
+At each level signatures and issuer attributes are checked. Whenever
+a verification error is found, the error number is stored in B<x509_ctx>
+and B<verify_callback> is called with B<preverify_ok>=0. By applying
+X509_CTX_store_* functions B<verify_callback> can locate the certificate
+in question and perform additional steps (see EXAMPLES). If no error is
+found for a certificate, B<verify_callback> is called with B<preverify_ok>=1
+before advancing to the next level.
+
+The return value of B<verify_callback> controls the strategy of the further
+verification process. If B<verify_callback> returns 0, the verification
+process is immediately stopped with "verification failed" state. If
+SSL_VERIFY_PEER is set, a verification failure alert is sent to the peer and
+the TLS/SSL handshake is terminated. If B<verify_callback> returns 1,
+the verification process is continued. If B<verify_callback> always returns
+1, the TLS/SSL handshake will not be terminated with respect to verification
+failures and the connection will be established. The calling process can
+however retrieve the error code of the last verification error using
+L<SSL_get_verify_result(3)|SSL_get_verify_result(3)> or by maintaining its
+own error storage managed by B<verify_callback>.
+
+If no B<verify_callback> is specified, the default callback will be used.
+Its return value is identical to B<preverify_ok>, so that any verification
+failure will lead to a termination of the TLS/SSL handshake with an
+alert message, if SSL_VERIFY_PEER is set.
+
+=head1 BUGS
+
+In client mode, it is not checked whether the SSL_VERIFY_PEER flag
+is set, but whether SSL_VERIFY_NONE is not set. This can lead to
+unexpected behaviour, if the SSL_VERIFY_PEER and SSL_VERIFY_NONE are not
+used as required (exactly one must be set at any time).
+
+The certificate verification depth set with SSL[_CTX]_verify_depth()
+stops the verification at a certain depth. The error message produced
+will be that of an incomplete certificate chain and not
+X509_V_ERR_CERT_CHAIN_TOO_LONG as may be expected.
+
+=head1 RETURN VALUES
+
+The SSL*_set_verify*() functions do not provide diagnostic information.
+
+=head1 EXAMPLES
+
+The following code sequence realizes an example B<verify_callback> function
+that will always continue the TLS/SSL handshake regardless of verification
+failure, if wished. The callback realizes a verification depth limit with
+more informational output.
+
+All verification errors are printed, informations about the certificate chain
+are printed on request.
+The example is realized for a server that does allow but not require client
+certificates.
+
+The example makes use of the ex_data technique to store application data
+into/retrieve application data from the SSL structure
+(see L<SSL_get_ex_new_index(3)|SSL_get_ex_new_index(3)>,
+L<SSL_get_ex_data_X509_STORE_CTX_idx(3)|SSL_get_ex_data_X509_STORE_CTX_idx(3)>).
+
+ ...
+ typedef struct {
+   int verbose_mode;
+   int verify_depth;
+   int always_continue;
+ } mydata_t;
+ int mydata_index;
+ ...
+ static int verify_callback(int preverify_ok, X509_STORE_CTX *ctx)
+ {
+    char    buf[256];
+    X509   *err_cert;
+    int     err, depth;
+    SSL    *ssl;
+    mydata_t *mydata;
+
+    err_cert = X509_STORE_CTX_get_current_cert(ctx);
+    err = X509_STORE_CTX_get_error(ctx);
+    depth = X509_STORE_CTX_get_error_depth(ctx);
+
+    /*
+     * Retrieve the pointer to the SSL of the connection currently treated
+     * and the application specific data stored into the SSL object.
+     */
+    ssl = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
+    mydata = SSL_get_ex_data(ssl, mydata_index);
+
+    X509_NAME_oneline(X509_get_subject_name(err_cert), buf, 256);
+
+    /*
+     * Catch a too long certificate chain. The depth limit set using
+     * SSL_CTX_set_verify_depth() is by purpose set to "limit+1" so
+     * that whenever the "depth>verify_depth" condition is met, we
+     * have violated the limit and want to log this error condition.
+     * We must do it here, because the CHAIN_TOO_LONG error would not
+     * be found explicitly; only errors introduced by cutting off the
+     * additional certificates would be logged.
+     */
+    if (depth > mydata->verify_depth) {
+        preverify_ok = 0;
+        err = X509_V_ERR_CERT_CHAIN_TOO_LONG;
+        X509_STORE_CTX_set_error(ctx, err);
+    } 
+    if (!preverify_ok) {
+        printf("verify error:num=%d:%s:depth=%d:%s\n", err,
+                 X509_verify_cert_error_string(err), depth, buf);
+    }
+    else if (mydata->verbose_mode)
+    {
+        printf("depth=%d:%s\n", depth, buf);
+    }
+
+    /*
+     * At this point, err contains the last verification error. We can use
+     * it for something special
+     */
+    if (!preverify_ok && (err == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT))
+    {
+      X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert), buf, 256);
+      printf("issuer= %s\n", buf);
+    }
+
+    if (mydata->always_continue)
+      return 1;
+    else
+      return preverify_ok;
+ }
+ ...
+
+ mydata_t mydata;
+
+ ...
+ mydata_index = SSL_get_ex_new_index(0, "mydata index", NULL, NULL, NULL);
+
+ ...
+ SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
+                    verify_callback);
+
+ /*
+  * Let the verify_callback catch the verify_depth error so that we get
+  * an appropriate error in the logfile.
+  */
+ SSL_CTX_set_verify_depth(verify_depth + 1);
+
+ /*
+  * Set up the SSL specific data into "mydata" and store it into th SSL
+  * structure.
+  */
+ mydata.verify_depth = verify_depth; ...
+ SSL_set_ex_data(ssl, mydata_index, &mydata);
+                                            
+ ...
+ SSL_accept(ssl);      /* check of success left out for clarity */
+ if (peer = SSL_get_peer_certificate(ssl))
+ {
+   if (SSL_get_verify_result(ssl) == X509_V_OK)
+   {
+     /* The client sent a certificate which verified OK */
+   }
+ }
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_new(3)|SSL_new(3)>,
+L<SSL_CTX_get_verify_mode(3)|SSL_CTX_get_verify_mode(3)>,
+L<SSL_get_verify_result(3)|SSL_get_verify_result(3)>,
+L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>,
+L<SSL_get_peer_certificate(3)|SSL_get_peer_certificate(3)>,
+L<SSL_CTX_set_cert_verify_callback(3)|SSL_CTX_set_cert_verify_callback(3)>,
+L<SSL_get_ex_data_X509_STORE_CTX_idx(3)|SSL_get_ex_data_X509_STORE_CTX_idx(3)>,
+L<SSL_get_ex_new_index(3)|SSL_get_ex_new_index(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_use_certificate.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_use_certificate.pod
new file mode 100644 (file)
index 0000000..10be95f
--- /dev/null
@@ -0,0 +1,169 @@
+=pod
+
+=head1 NAME
+
+SSL_CTX_use_certificate, SSL_CTX_use_certificate_ASN1, SSL_CTX_use_certificate_file, SSL_use_certificate, SSL_use_certificate_ASN1, SSL_use_certificate_file, SSL_CTX_use_certificate_chain_file, SSL_CTX_use_PrivateKey, SSL_CTX_use_PrivateKey_ASN1, SSL_CTX_use_PrivateKey_file, SSL_CTX_use_RSAPrivateKey, SSL_CTX_use_RSAPrivateKey_ASN1, SSL_CTX_use_RSAPrivateKey_file, SSL_use_PrivateKey_file, SSL_use_PrivateKey_ASN1, SSL_use_PrivateKey, SSL_use_RSAPrivateKey, SSL_use_RSAPrivateKey_ASN1, SSL_use_RSAPrivateKey_file, SSL_CTX_check_private_key, SSL_check_private_key - load certificate and key data
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
+ int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char *d);
+ int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type);
+ int SSL_use_certificate(SSL *ssl, X509 *x);
+ int SSL_use_certificate_ASN1(SSL *ssl, unsigned char *d, int len);
+ int SSL_use_certificate_file(SSL *ssl, const char *file, int type);
+
+ int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file);
+
+ int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
+ int SSL_CTX_use_PrivateKey_ASN1(int pk, SSL_CTX *ctx, unsigned char *d,
+                                long len);
+ int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);
+ int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);
+ int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, unsigned char *d, long len);
+ int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type);
+ int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
+ int SSL_use_PrivateKey_ASN1(int pk,SSL *ssl, unsigned char *d, long len);
+ int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type);
+ int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);
+ int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len);
+ int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type);
+
+ int SSL_CTX_check_private_key(const SSL_CTX *ctx);
+ int SSL_check_private_key(const SSL *ssl);
+
+=head1 DESCRIPTION
+
+These functions load the certificates and private keys into the SSL_CTX
+or SSL object, respectively.
+
+The SSL_CTX_* class of functions loads the certificates and keys into the
+SSL_CTX object B<ctx>. The information is passed to SSL objects B<ssl>
+created from B<ctx> with L<SSL_new(3)|SSL_new(3)> by copying, so that
+changes applied to B<ctx> do not propagate to already existing SSL objects.
+
+The SSL_* class of functions only loads certificates and keys into a
+specific SSL object. The specific information is kept, when
+L<SSL_clear(3)|SSL_clear(3)> is called for this SSL object.
+
+SSL_CTX_use_certificate() loads the certificate B<x> into B<ctx>,
+SSL_use_certificate() loads B<x> into B<ssl>. The rest of the
+certificates needed to form the complete certificate chain can be
+specified using the
+L<SSL_CTX_add_extra_chain_cert(3)|SSL_CTX_add_extra_chain_cert(3)>
+function.
+
+SSL_CTX_use_certificate_ASN1() loads the ASN1 encoded certificate from
+the memory location B<d> (with length B<len>) into B<ctx>,
+SSL_use_certificate_ASN1() loads the ASN1 encoded certificate into B<ssl>.
+
+SSL_CTX_use_certificate_file() loads the first certificate stored in B<file>
+into B<ctx>. The formatting B<type> of the certificate must be specified
+from the known types SSL_FILETYPE_PEM, SSL_FILETYPE_ASN1.
+SSL_use_certificate_file() loads the certificate from B<file> into B<ssl>.
+See the NOTES section on why SSL_CTX_use_certificate_chain_file()
+should be preferred.
+
+SSL_CTX_use_certificate_chain_file() loads a certificate chain from 
+B<file> into B<ctx>. The certificates must be in PEM format and must
+be sorted starting with the subject's certificate (actual client or server
+certificate), followed by intermediate CA certificates if applicable, and
+ending at the highest level (root) CA.
+There is no corresponding function working on a single SSL object.
+
+SSL_CTX_use_PrivateKey() adds B<pkey> as private key to B<ctx>.
+SSL_CTX_use_RSAPrivateKey() adds the private key B<rsa> of type RSA
+to B<ctx>. SSL_use_PrivateKey() adds B<pkey> as private key to B<ssl>;
+SSL_use_RSAPrivateKey() adds B<rsa> as private key of type RSA to B<ssl>.
+If a certificate has already been set and the private does not belong
+to the certificate an error is returned. To change a certificate, private
+key pair the new certificate needs to be set with SSL_use_certificate()
+or SSL_CTX_use_certificate() before setting the private key with
+SSL_CTX_use_PrivateKey() or SSL_use_PrivateKey(). 
+
+
+SSL_CTX_use_PrivateKey_ASN1() adds the private key of type B<pk>
+stored at memory location B<d> (length B<len>) to B<ctx>.
+SSL_CTX_use_RSAPrivateKey_ASN1() adds the private key of type RSA
+stored at memory location B<d> (length B<len>) to B<ctx>.
+SSL_use_PrivateKey_ASN1() and SSL_use_RSAPrivateKey_ASN1() add the private
+key to B<ssl>.
+
+SSL_CTX_use_PrivateKey_file() adds the first private key found in
+B<file> to B<ctx>. The formatting B<type> of the certificate must be specified
+from the known types SSL_FILETYPE_PEM, SSL_FILETYPE_ASN1.
+SSL_CTX_use_RSAPrivateKey_file() adds the first private RSA key found in
+B<file> to B<ctx>. SSL_use_PrivateKey_file() adds the first private key found
+in B<file> to B<ssl>; SSL_use_RSAPrivateKey_file() adds the first private
+RSA key found to B<ssl>.
+
+SSL_CTX_check_private_key() checks the consistency of a private key with
+the corresponding certificate loaded into B<ctx>. If more than one
+key/certificate pair (RSA/DSA) is installed, the last item installed will
+be checked. If e.g. the last item was a RSA certificate or key, the RSA
+key/certificate pair will be checked. SSL_check_private_key() performs
+the same check for B<ssl>. If no key/certificate was explicitly added for
+this B<ssl>, the last item added into B<ctx> will be checked.
+
+=head1 NOTES
+  
+The internal certificate store of OpenSSL can hold two private key/certificate
+pairs at a time: one key/certificate of type RSA and one key/certificate
+of type DSA. The certificate used depends on the cipher select, see
+also L<SSL_CTX_set_cipher_list(3)|SSL_CTX_set_cipher_list(3)>.
+
+When reading certificates and private keys from file, files of type
+SSL_FILETYPE_ASN1 (also known as B<DER>, binary encoding) can only contain
+one certificate or private key, consequently 
+SSL_CTX_use_certificate_chain_file() is only applicable to PEM formatting.
+Files of type SSL_FILETYPE_PEM can contain more than one item.
+
+SSL_CTX_use_certificate_chain_file() adds the first certificate found
+in the file to the certificate store. The other certificates are added
+to the store of chain certificates using
+L<SSL_CTX_add_extra_chain_cert(3)|SSL_CTX_add_extra_chain_cert(3)>.
+There exists only one extra chain store, so that the same chain is appended
+to both types of certificates, RSA and DSA! If it is not intended to use
+both type of certificate at the same time, it is recommended to use the
+SSL_CTX_use_certificate_chain_file() instead of the
+SSL_CTX_use_certificate_file() function in order to allow the use of
+complete certificate chains even when no trusted CA storage is used or
+when the CA issuing the certificate shall not be added to the trusted
+CA storage.
+
+If additional certificates are needed to complete the chain during the
+TLS negotiation, CA certificates are additionally looked up in the
+locations of trusted CA certificates, see
+L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>.
+
+The private keys loaded from file can be encrypted. In order to successfully
+load encrypted keys, a function returning the passphrase must have been
+supplied, see
+L<SSL_CTX_set_default_passwd_cb(3)|SSL_CTX_set_default_passwd_cb(3)>.
+(Certificate files might be encrypted as well from the technical point
+of view, it however does not make sense as the data in the certificate
+is considered public anyway.)
+
+=head1 RETURN VALUES
+
+On success, the functions return 1.
+Otherwise check out the error stack to find out the reason.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_new(3)|SSL_new(3)>, L<SSL_clear(3)|SSL_clear(3)>,
+L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>,
+L<SSL_CTX_set_default_passwd_cb(3)|SSL_CTX_set_default_passwd_cb(3)>,
+L<SSL_CTX_set_cipher_list(3)|SSL_CTX_set_cipher_list(3)>,
+L<SSL_CTX_set_client_cert_cb(3)|SSL_CTX_set_client_cert_cb(3)>,
+L<SSL_CTX_add_extra_chain_cert(3)|SSL_CTX_add_extra_chain_cert(3)>
+
+=head1 HISTORY
+
+Support for DER encoded private keys (SSL_FILETYPE_ASN1) in
+SSL_CTX_use_PrivateKey_file() and SSL_use_PrivateKey_file() was added
+in 0.9.8 .
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_CTX_use_psk_identity_hint.pod b/deps/openssl/openssl/doc/ssl/SSL_CTX_use_psk_identity_hint.pod
new file mode 100644 (file)
index 0000000..b80e25b
--- /dev/null
@@ -0,0 +1,102 @@
+=pod
+
+=begin comment
+
+Copyright 2005 Nokia. All rights reserved.
+
+The portions of the attached software ("Contribution") is developed by
+Nokia Corporation and is licensed pursuant to the OpenSSL open source
+license.
+
+The Contribution, originally written by Mika Kousa and Pasi Eronen of
+Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
+support (see RFC 4279) to OpenSSL.
+
+No patent licenses or other rights except those expressly stated in
+the OpenSSL open source license shall be deemed granted or received
+expressly, by implication, estoppel, or otherwise.
+
+No assurances are provided by Nokia that the Contribution does not
+infringe the patent or other intellectual property rights of any third
+party or that the license provides you with all the necessary rights
+to make use of the Contribution.
+
+THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
+ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
+SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
+OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
+OTHERWISE.
+
+=end comment
+
+=head1 NAME
+
+SSL_CTX_use_psk_identity_hint, SSL_use_psk_identity_hint,
+SSL_CTX_set_psk_server_callback, SSL_set_psk_server_callback - set PSK
+identity hint to use
+
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_CTX_use_psk_identity_hint(SSL_CTX *ctx, const char *hint);
+ int SSL_use_psk_identity_hint(SSL *ssl, const char *hint);
+
+ void SSL_CTX_set_psk_server_callback(SSL_CTX *ctx,
+       unsigned int (*callback)(SSL *ssl, const char *identity,
+       unsigned char *psk, int max_psk_len));
+ void SSL_set_psk_server_callback(SSL *ssl,
+       unsigned int (*callback)(SSL *ssl, const char *identity,
+       unsigned char *psk, int max_psk_len));
+
+
+=head1 DESCRIPTION
+
+SSL_CTX_use_psk_identity_hint() sets the given B<NULL>-terminated PSK
+identity hint B<hint> to SSL context object
+B<ctx>. SSL_use_psk_identity_hint() sets the given B<NULL>-terminated
+PSK identity hint B<hint> to SSL connection object B<ssl>. If B<hint>
+is B<NULL> the current hint from B<ctx> or B<ssl> is deleted.
+
+In the case where PSK identity hint is B<NULL>, the server
+does not send the ServerKeyExchange message to the client.
+
+A server application must provide a callback function which is called
+when the server receives the ClientKeyExchange message from the
+client. The purpose of the callback function is to validate the
+received PSK identity and to fetch the pre-shared key used during the
+connection setup phase. The callback is set using functions
+SSL_CTX_set_psk_server_callback() or
+SSL_set_psk_server_callback(). The callback function is given the
+connection in parameter B<ssl>, B<NULL>-terminated PSK identity sent
+by the client in parameter B<identity>, and a buffer B<psk> of length
+B<max_psk_len> bytes where the pre-shared key is to be stored.
+
+
+=head1 RETURN VALUES
+
+SSL_CTX_use_psk_identity_hint() and SSL_use_psk_identity_hint() return
+1 on success, 0 otherwise.
+
+Return values from the server callback are interpreted as follows:
+
+=item > 0
+
+PSK identity was found and the server callback has provided the PSK
+successfully in parameter B<psk>. Return value is the length of
+B<psk> in bytes. It is an error to return a value greater than
+B<max_psk_len>.
+
+If the PSK identity was not found but the callback instructs the
+protocol to continue anyway, the callback must provide some random
+data to B<psk> and return the length of the random data, so the
+connection will fail with decryption_error before it will be finished
+completely.
+
+=item 0
+
+PSK identity was not found. An "unknown_psk_identity" alert message
+will be sent and the connection setup fails.
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_SESSION_free.pod b/deps/openssl/openssl/doc/ssl/SSL_SESSION_free.pod
new file mode 100644 (file)
index 0000000..110ec73
--- /dev/null
@@ -0,0 +1,55 @@
+=pod
+
+=head1 NAME
+
+SSL_SESSION_free - free an allocated SSL_SESSION structure
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ void SSL_SESSION_free(SSL_SESSION *session);
+
+=head1 DESCRIPTION
+
+SSL_SESSION_free() decrements the reference count of B<session> and removes
+the B<SSL_SESSION> structure pointed to by B<session> and frees up the allocated
+memory, if the reference count has reached 0.
+
+=head1 NOTES
+
+SSL_SESSION objects are allocated, when a TLS/SSL handshake operation
+is successfully completed. Depending on the settings, see
+L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>,
+the SSL_SESSION objects are internally referenced by the SSL_CTX and
+linked into its session cache. SSL objects may be using the SSL_SESSION object;
+as a session may be reused, several SSL objects may be using one SSL_SESSION
+object at the same time. It is therefore crucial to keep the reference
+count (usage information) correct and not delete a SSL_SESSION object
+that is still used, as this may lead to program failures due to
+dangling pointers. These failures may also appear delayed, e.g.
+when an SSL_SESSION object was completely freed as the reference count
+incorrectly became 0, but it is still referenced in the internal
+session cache and the cache list is processed during a
+L<SSL_CTX_flush_sessions(3)|SSL_CTX_flush_sessions(3)> operation.
+
+SSL_SESSION_free() must only be called for SSL_SESSION objects, for
+which the reference count was explicitly incremented (e.g.
+by calling SSL_get1_session(), see L<SSL_get_session(3)|SSL_get_session(3)>)
+or when the SSL_SESSION object was generated outside a TLS handshake
+operation, e.g. by using L<d2i_SSL_SESSION(3)|d2i_SSL_SESSION(3)>.
+It must not be called on other SSL_SESSION objects, as this would cause
+incorrect reference counts and therefore program failures.
+
+=head1 RETURN VALUES
+
+SSL_SESSION_free() does not provide diagnostic information.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_get_session(3)|SSL_get_session(3)>,
+L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>,
+L<SSL_CTX_flush_sessions(3)|SSL_CTX_flush_sessions(3)>,
+ L<d2i_SSL_SESSION(3)|d2i_SSL_SESSION(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_SESSION_get_ex_new_index.pod b/deps/openssl/openssl/doc/ssl/SSL_SESSION_get_ex_new_index.pod
new file mode 100644 (file)
index 0000000..657cda9
--- /dev/null
@@ -0,0 +1,61 @@
+=pod
+
+=head1 NAME
+
+SSL_SESSION_get_ex_new_index, SSL_SESSION_set_ex_data, SSL_SESSION_get_ex_data - internal application specific data functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_SESSION_get_ex_new_index(long argl, void *argp,
+                CRYPTO_EX_new *new_func,
+                CRYPTO_EX_dup *dup_func,
+                CRYPTO_EX_free *free_func);
+
+ int SSL_SESSION_set_ex_data(SSL_SESSION *session, int idx, void *arg);
+
+ void *SSL_SESSION_get_ex_data(const SSL_SESSION *session, int idx);
+
+ typedef int new_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
+                int idx, long argl, void *argp);
+ typedef void free_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
+                int idx, long argl, void *argp);
+ typedef int dup_func(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d,
+                int idx, long argl, void *argp);
+
+=head1 DESCRIPTION
+
+Several OpenSSL structures can have application specific data attached to them.
+These functions are used internally by OpenSSL to manipulate application
+specific data attached to a specific structure.
+
+SSL_SESSION_get_ex_new_index() is used to register a new index for application
+specific data.
+
+SSL_SESSION_set_ex_data() is used to store application data at B<arg> for B<idx>
+into the B<session> object.
+
+SSL_SESSION_get_ex_data() is used to retrieve the information for B<idx> from
+B<session>.
+
+A detailed description for the B<*_get_ex_new_index()> functionality
+can be found in L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>.
+The B<*_get_ex_data()> and B<*_set_ex_data()> functionality is described in
+L<CRYPTO_set_ex_data(3)|CRYPTO_set_ex_data(3)>.
+
+=head1 WARNINGS
+
+The application data is only maintained for sessions held in memory. The
+application data is not included when dumping the session with
+i2d_SSL_SESSION() (and all functions indirectly calling the dump functions
+like PEM_write_SSL_SESSION() and PEM_write_bio_SSL_SESSION()) and can
+therefore not be restored.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>,
+L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>,
+L<CRYPTO_set_ex_data(3)|CRYPTO_set_ex_data(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_SESSION_get_time.pod b/deps/openssl/openssl/doc/ssl/SSL_SESSION_get_time.pod
new file mode 100644 (file)
index 0000000..490337a
--- /dev/null
@@ -0,0 +1,64 @@
+=pod
+
+=head1 NAME
+
+SSL_SESSION_get_time, SSL_SESSION_set_time, SSL_SESSION_get_timeout, SSL_SESSION_set_timeout - retrieve and manipulate session time and timeout settings
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ long SSL_SESSION_get_time(const SSL_SESSION *s);
+ long SSL_SESSION_set_time(SSL_SESSION *s, long tm);
+ long SSL_SESSION_get_timeout(const SSL_SESSION *s);
+ long SSL_SESSION_set_timeout(SSL_SESSION *s, long tm);
+
+ long SSL_get_time(const SSL_SESSION *s);
+ long SSL_set_time(SSL_SESSION *s, long tm);
+ long SSL_get_timeout(const SSL_SESSION *s);
+ long SSL_set_timeout(SSL_SESSION *s, long tm);
+
+=head1 DESCRIPTION
+
+SSL_SESSION_get_time() returns the time at which the session B<s> was
+established. The time is given in seconds since the Epoch and therefore
+compatible to the time delivered by the time() call.
+
+SSL_SESSION_set_time() replaces the creation time of the session B<s> with
+the chosen value B<tm>.
+
+SSL_SESSION_get_timeout() returns the timeout value set for session B<s>
+in seconds.
+
+SSL_SESSION_set_timeout() sets the timeout value for session B<s> in seconds
+to B<tm>.
+
+The SSL_get_time(), SSL_set_time(), SSL_get_timeout(), and SSL_set_timeout()
+functions are synonyms for the SSL_SESSION_*() counterparts.
+
+=head1 NOTES
+
+Sessions are expired by examining the creation time and the timeout value.
+Both are set at creation time of the session to the actual time and the
+default timeout value at creation, respectively, as set by
+L<SSL_CTX_set_timeout(3)|SSL_CTX_set_timeout(3)>.
+Using these functions it is possible to extend or shorten the lifetime
+of the session.
+
+=head1 RETURN VALUES
+
+SSL_SESSION_get_time() and SSL_SESSION_get_timeout() return the currently
+valid values.
+
+SSL_SESSION_set_time() and SSL_SESSION_set_timeout() return 1 on success.
+
+If any of the function is passed the NULL pointer for the session B<s>, 
+0 is returned.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>,
+L<SSL_CTX_set_timeout(3)|SSL_CTX_set_timeout(3)>,
+L<SSL_get_default_timeout(3)|SSL_get_default_timeout(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_accept.pod b/deps/openssl/openssl/doc/ssl/SSL_accept.pod
new file mode 100644 (file)
index 0000000..cc724c0
--- /dev/null
@@ -0,0 +1,76 @@
+=pod
+
+=head1 NAME
+
+SSL_accept - wait for a TLS/SSL client to initiate a TLS/SSL handshake
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_accept(SSL *ssl);
+
+=head1 DESCRIPTION
+
+SSL_accept() waits for a TLS/SSL client to initiate the TLS/SSL handshake.
+The communication channel must already have been set and assigned to the
+B<ssl> by setting an underlying B<BIO>.
+
+=head1 NOTES
+
+The behaviour of SSL_accept() depends on the underlying BIO. 
+
+If the underlying BIO is B<blocking>, SSL_accept() will only return once the
+handshake has been finished or an error occurred, except for SGC (Server
+Gated Cryptography). For SGC, SSL_accept() may return with -1, but
+SSL_get_error() will yield B<SSL_ERROR_WANT_READ/WRITE> and SSL_accept()
+should be called again.
+
+If the underlying BIO is B<non-blocking>, SSL_accept() will also return
+when the underlying BIO could not satisfy the needs of SSL_accept()
+to continue the handshake, indicating the problem by the return value -1.
+In this case a call to SSL_get_error() with the
+return value of SSL_accept() will yield B<SSL_ERROR_WANT_READ> or
+B<SSL_ERROR_WANT_WRITE>. The calling process then must repeat the call after
+taking appropriate action to satisfy the needs of SSL_accept().
+The action depends on the underlying BIO. When using a non-blocking socket,
+nothing is to be done, but select() can be used to check for the required
+condition. When using a buffering BIO, like a BIO pair, data must be written
+into or retrieved out of the BIO before being able to continue.
+
+=head1 RETURN VALUES
+
+The following return values can occur:
+
+=over 4
+
+=item 1
+
+The TLS/SSL handshake was successfully completed, a TLS/SSL connection has been
+established.
+
+=item 0
+
+The TLS/SSL handshake was not successful but was shut down controlled and
+by the specifications of the TLS/SSL protocol. Call SSL_get_error() with the
+return value B<ret> to find out the reason.
+
+=item E<lt>0
+
+The TLS/SSL handshake was not successful because a fatal error occurred either
+at the protocol level or a connection failure occurred. The shutdown was
+not clean. It can also occur of action is need to continue the operation
+for non-blocking BIOs. Call SSL_get_error() with the return value B<ret>
+to find out the reason.
+
+=back
+
+=head1 SEE ALSO
+
+L<SSL_get_error(3)|SSL_get_error(3)>, L<SSL_connect(3)|SSL_connect(3)>,
+L<SSL_shutdown(3)|SSL_shutdown(3)>, L<ssl(3)|ssl(3)>, L<bio(3)|bio(3)>,
+L<SSL_set_connect_state(3)|SSL_set_connect_state(3)>,
+L<SSL_do_handshake(3)|SSL_do_handshake(3)>,
+L<SSL_CTX_new(3)|SSL_CTX_new(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_alert_type_string.pod b/deps/openssl/openssl/doc/ssl/SSL_alert_type_string.pod
new file mode 100644 (file)
index 0000000..94e28cc
--- /dev/null
@@ -0,0 +1,228 @@
+=pod
+
+=head1 NAME
+
+SSL_alert_type_string, SSL_alert_type_string_long, SSL_alert_desc_string, SSL_alert_desc_string_long - get textual description of alert information
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ const char *SSL_alert_type_string(int value);
+ const char *SSL_alert_type_string_long(int value);
+
+ const char *SSL_alert_desc_string(int value);
+ const char *SSL_alert_desc_string_long(int value);
+
+=head1 DESCRIPTION
+
+SSL_alert_type_string() returns a one letter string indicating the
+type of the alert specified by B<value>.
+
+SSL_alert_type_string_long() returns a string indicating the type of the alert
+specified by B<value>.
+
+SSL_alert_desc_string() returns a two letter string as a short form
+describing the reason of the alert specified by B<value>.
+
+SSL_alert_desc_string_long() returns a string describing the reason
+of the alert specified by B<value>.
+
+=head1 NOTES
+
+When one side of an SSL/TLS communication wants to inform the peer about
+a special situation, it sends an alert. The alert is sent as a special message
+and does not influence the normal data stream (unless its contents results
+in the communication being canceled).
+
+A warning alert is sent, when a non-fatal error condition occurs. The
+"close notify" alert is sent as a warning alert. Other examples for
+non-fatal errors are certificate errors ("certificate expired",
+"unsupported certificate"), for which a warning alert may be sent.
+(The sending party may however decide to send a fatal error.) The
+receiving side may cancel the connection on reception of a warning
+alert on it discretion.
+
+Several alert messages must be sent as fatal alert messages as specified
+by the TLS RFC. A fatal alert always leads to a connection abort.
+
+=head1 RETURN VALUES
+
+The following strings can occur for SSL_alert_type_string() or
+SSL_alert_type_string_long():
+
+=over 4
+
+=item "W"/"warning"
+
+=item "F"/"fatal"
+
+=item "U"/"unknown"
+
+This indicates that no support is available for this alert type.
+Probably B<value> does not contain a correct alert message.
+
+=back
+
+The following strings can occur for SSL_alert_desc_string() or
+SSL_alert_desc_string_long():
+
+=over 4
+
+=item "CN"/"close notify"
+
+The connection shall be closed. This is a warning alert.
+
+=item "UM"/"unexpected message"
+
+An inappropriate message was received. This alert is always fatal
+and should never be observed in communication between proper
+implementations.
+
+=item "BM"/"bad record mac"
+
+This alert is returned if a record is received with an incorrect
+MAC. This message is always fatal.
+
+=item "DF"/"decompression failure"
+
+The decompression function received improper input (e.g. data
+that would expand to excessive length). This message is always
+fatal.
+
+=item "HF"/"handshake failure"
+
+Reception of a handshake_failure alert message indicates that the
+sender was unable to negotiate an acceptable set of security
+parameters given the options available. This is a fatal error.
+
+=item "NC"/"no certificate"
+
+A client, that was asked to send a certificate, does not send a certificate
+(SSLv3 only).
+
+=item "BC"/"bad certificate"
+
+A certificate was corrupt, contained signatures that did not
+verify correctly, etc
+
+=item "UC"/"unsupported certificate"
+
+A certificate was of an unsupported type.
+
+=item "CR"/"certificate revoked"
+
+A certificate was revoked by its signer.
+
+=item "CE"/"certificate expired"
+
+A certificate has expired or is not currently valid.
+
+=item "CU"/"certificate unknown"
+
+Some other (unspecified) issue arose in processing the
+certificate, rendering it unacceptable.
+
+=item "IP"/"illegal parameter"
+
+A field in the handshake was out of range or inconsistent with
+other fields. This is always fatal.
+
+=item "DC"/"decryption failed"
+
+A TLSCiphertext decrypted in an invalid way: either it wasn't an
+even multiple of the block length or its padding values, when
+checked, weren't correct. This message is always fatal.
+
+=item "RO"/"record overflow"
+
+A TLSCiphertext record was received which had a length more than
+2^14+2048 bytes, or a record decrypted to a TLSCompressed record
+with more than 2^14+1024 bytes. This message is always fatal.
+
+=item "CA"/"unknown CA"
+
+A valid certificate chain or partial chain was received, but the
+certificate was not accepted because the CA certificate could not
+be located or couldn't be matched with a known, trusted CA.  This
+message is always fatal.
+
+=item "AD"/"access denied"
+
+A valid certificate was received, but when access control was
+applied, the sender decided not to proceed with negotiation.
+This message is always fatal.
+
+=item "DE"/"decode error"
+
+A message could not be decoded because some field was out of the
+specified range or the length of the message was incorrect. This
+message is always fatal.
+
+=item "CY"/"decrypt error"
+
+A handshake cryptographic operation failed, including being
+unable to correctly verify a signature, decrypt a key exchange,
+or validate a finished message.
+
+=item "ER"/"export restriction"
+
+A negotiation not in compliance with export restrictions was
+detected; for example, attempting to transfer a 1024 bit
+ephemeral RSA key for the RSA_EXPORT handshake method. This
+message is always fatal.
+
+=item "PV"/"protocol version"
+
+The protocol version the client has attempted to negotiate is
+recognized, but not supported. (For example, old protocol
+versions might be avoided for security reasons). This message is
+always fatal.
+
+=item "IS"/"insufficient security"
+
+Returned instead of handshake_failure when a negotiation has
+failed specifically because the server requires ciphers more
+secure than those supported by the client. This message is always
+fatal.
+
+=item "IE"/"internal error"
+
+An internal error unrelated to the peer or the correctness of the
+protocol makes it impossible to continue (such as a memory
+allocation failure). This message is always fatal.
+
+=item "US"/"user canceled"
+
+This handshake is being canceled for some reason unrelated to a
+protocol failure. If the user cancels an operation after the
+handshake is complete, just closing the connection by sending a
+close_notify is more appropriate. This alert should be followed
+by a close_notify. This message is generally a warning.
+
+=item "NR"/"no renegotiation"
+
+Sent by the client in response to a hello request or by the
+server in response to a client hello after initial handshaking.
+Either of these would normally lead to renegotiation; when that
+is not appropriate, the recipient should respond with this alert;
+at that point, the original requester can decide whether to
+proceed with the connection. One case where this would be
+appropriate would be where a server has spawned a process to
+satisfy a request; the process might receive security parameters
+(key length, authentication, etc.) at startup and it might be
+difficult to communicate changes to these parameters after that
+point. This message is always a warning.
+
+=item "UK"/"unknown"
+
+This indicates that no description is available for this alert type.
+Probably B<value> does not contain a correct alert message.
+
+=back
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_CTX_set_info_callback(3)|SSL_CTX_set_info_callback(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_clear.pod b/deps/openssl/openssl/doc/ssl/SSL_clear.pod
new file mode 100644 (file)
index 0000000..d4df1bf
--- /dev/null
@@ -0,0 +1,75 @@
+=pod
+
+=head1 NAME
+
+SSL_clear - reset SSL object to allow another connection
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_clear(SSL *ssl);
+
+=head1 DESCRIPTION
+
+Reset B<ssl> to allow another connection. All settings (method, ciphers,
+BIOs) are kept.
+
+=head1 NOTES
+
+SSL_clear is used to prepare an SSL object for a new connection. While all
+settings are kept, a side effect is the handling of the current SSL session.
+If a session is still B<open>, it is considered bad and will be removed
+from the session cache, as required by RFC2246. A session is considered open,
+if L<SSL_shutdown(3)|SSL_shutdown(3)> was not called for the connection
+or at least L<SSL_set_shutdown(3)|SSL_set_shutdown(3)> was used to
+set the SSL_SENT_SHUTDOWN state.
+
+If a session was closed cleanly, the session object will be kept and all
+settings corresponding. This explicitly means, that e.g. the special method
+used during the session will be kept for the next handshake. So if the
+session was a TLSv1 session, a SSL client object will use a TLSv1 client
+method for the next handshake and a SSL server object will use a TLSv1
+server method, even if SSLv23_*_methods were chosen on startup. This
+will might lead to connection failures (see L<SSL_new(3)|SSL_new(3)>)
+for a description of the method's properties.
+
+=head1 WARNINGS
+
+SSL_clear() resets the SSL object to allow for another connection. The
+reset operation however keeps several settings of the last sessions
+(some of these settings were made automatically during the last
+handshake). It only makes sense for a new connection with the exact
+same peer that shares these settings, and may fail if that peer
+changes its settings between connections. Use the sequence
+L<SSL_get_session(3)|SSL_get_session(3)>;
+L<SSL_new(3)|SSL_new(3)>;
+L<SSL_set_session(3)|SSL_set_session(3)>;
+L<SSL_free(3)|SSL_free(3)>
+instead to avoid such failures
+(or simply L<SSL_free(3)|SSL_free(3)>; L<SSL_new(3)|SSL_new(3)>
+if session reuse is not desired).
+
+=head1 RETURN VALUES
+
+The following return values can occur:
+
+=over 4
+
+=item 0
+
+The SSL_clear() operation could not be performed. Check the error stack to
+find out the reason.
+
+=item 1
+
+The SSL_clear() operation was successful.
+
+=back
+
+L<SSL_new(3)|SSL_new(3)>, L<SSL_free(3)|SSL_free(3)>,
+L<SSL_shutdown(3)|SSL_shutdown(3)>, L<SSL_set_shutdown(3)|SSL_set_shutdown(3)>,
+L<SSL_CTX_set_options(3)|SSL_CTX_set_options(3)>, L<ssl(3)|ssl(3)>,
+L<SSL_CTX_set_client_cert_cb(3)|SSL_CTX_set_client_cert_cb(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_connect.pod b/deps/openssl/openssl/doc/ssl/SSL_connect.pod
new file mode 100644 (file)
index 0000000..cc56ebb
--- /dev/null
@@ -0,0 +1,73 @@
+=pod
+
+=head1 NAME
+
+SSL_connect - initiate the TLS/SSL handshake with an TLS/SSL server
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_connect(SSL *ssl);
+
+=head1 DESCRIPTION
+
+SSL_connect() initiates the TLS/SSL handshake with a server. The communication
+channel must already have been set and assigned to the B<ssl> by setting an
+underlying B<BIO>.
+
+=head1 NOTES
+
+The behaviour of SSL_connect() depends on the underlying BIO. 
+
+If the underlying BIO is B<blocking>, SSL_connect() will only return once the
+handshake has been finished or an error occurred.
+
+If the underlying BIO is B<non-blocking>, SSL_connect() will also return
+when the underlying BIO could not satisfy the needs of SSL_connect()
+to continue the handshake, indicating the problem by the return value -1.
+In this case a call to SSL_get_error() with the
+return value of SSL_connect() will yield B<SSL_ERROR_WANT_READ> or
+B<SSL_ERROR_WANT_WRITE>. The calling process then must repeat the call after
+taking appropriate action to satisfy the needs of SSL_connect().
+The action depends on the underlying BIO. When using a non-blocking socket,
+nothing is to be done, but select() can be used to check for the required
+condition. When using a buffering BIO, like a BIO pair, data must be written
+into or retrieved out of the BIO before being able to continue.
+
+=head1 RETURN VALUES
+
+The following return values can occur:
+
+=over 4
+
+=item 1
+
+The TLS/SSL handshake was successfully completed, a TLS/SSL connection has been
+established.
+
+=item 0
+
+The TLS/SSL handshake was not successful but was shut down controlled and
+by the specifications of the TLS/SSL protocol. Call SSL_get_error() with the
+return value B<ret> to find out the reason.
+
+=item E<lt>0
+
+The TLS/SSL handshake was not successful, because a fatal error occurred either
+at the protocol level or a connection failure occurred. The shutdown was
+not clean. It can also occur of action is need to continue the operation
+for non-blocking BIOs. Call SSL_get_error() with the return value B<ret>
+to find out the reason.
+
+=back
+
+=head1 SEE ALSO
+
+L<SSL_get_error(3)|SSL_get_error(3)>, L<SSL_accept(3)|SSL_accept(3)>,
+L<SSL_shutdown(3)|SSL_shutdown(3)>, L<ssl(3)|ssl(3)>, L<bio(3)|bio(3)>,
+L<SSL_set_connect_state(3)|SSL_set_connect_state(3)>,
+L<SSL_do_handshake(3)|SSL_do_handshake(3)>,
+L<SSL_CTX_new(3)|SSL_CTX_new(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_do_handshake.pod b/deps/openssl/openssl/doc/ssl/SSL_do_handshake.pod
new file mode 100644 (file)
index 0000000..2435764
--- /dev/null
@@ -0,0 +1,75 @@
+=pod
+
+=head1 NAME
+
+SSL_do_handshake - perform a TLS/SSL handshake
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_do_handshake(SSL *ssl);
+
+=head1 DESCRIPTION
+
+SSL_do_handshake() will wait for a SSL/TLS handshake to take place. If the
+connection is in client mode, the handshake will be started. The handshake
+routines may have to be explicitly set in advance using either
+L<SSL_set_connect_state(3)|SSL_set_connect_state(3)> or
+L<SSL_set_accept_state(3)|SSL_set_accept_state(3)>.
+
+=head1 NOTES
+
+The behaviour of SSL_do_handshake() depends on the underlying BIO.
+
+If the underlying BIO is B<blocking>, SSL_do_handshake() will only return
+once the handshake has been finished or an error occurred, except for SGC
+(Server Gated Cryptography). For SGC, SSL_do_handshake() may return with -1,
+but SSL_get_error() will yield B<SSL_ERROR_WANT_READ/WRITE> and
+SSL_do_handshake() should be called again.
+
+If the underlying BIO is B<non-blocking>, SSL_do_handshake() will also return
+when the underlying BIO could not satisfy the needs of SSL_do_handshake()
+to continue the handshake. In this case a call to SSL_get_error() with the
+return value of SSL_do_handshake() will yield B<SSL_ERROR_WANT_READ> or
+B<SSL_ERROR_WANT_WRITE>. The calling process then must repeat the call after
+taking appropriate action to satisfy the needs of SSL_do_handshake().
+The action depends on the underlying BIO. When using a non-blocking socket,
+nothing is to be done, but select() can be used to check for the required
+condition. When using a buffering BIO, like a BIO pair, data must be written
+into or retrieved out of the BIO before being able to continue.
+
+=head1 RETURN VALUES
+
+The following return values can occur:
+
+=over 4
+
+=item 1
+
+The TLS/SSL handshake was successfully completed, a TLS/SSL connection has been
+established.
+
+=item 0
+
+The TLS/SSL handshake was not successful but was shut down controlled and
+by the specifications of the TLS/SSL protocol. Call SSL_get_error() with the
+return value B<ret> to find out the reason.
+
+=item E<lt>0
+
+The TLS/SSL handshake was not successful because a fatal error occurred either
+at the protocol level or a connection failure occurred. The shutdown was
+not clean. It can also occur of action is need to continue the operation
+for non-blocking BIOs. Call SSL_get_error() with the return value B<ret>
+to find out the reason.
+
+=back
+
+=head1 SEE ALSO
+
+L<SSL_get_error(3)|SSL_get_error(3)>, L<SSL_connect(3)|SSL_connect(3)>,
+L<SSL_accept(3)|SSL_accept(3)>, L<ssl(3)|ssl(3)>, L<bio(3)|bio(3)>,
+L<SSL_set_connect_state(3)|SSL_set_connect_state(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_free.pod b/deps/openssl/openssl/doc/ssl/SSL_free.pod
new file mode 100644 (file)
index 0000000..13c1abd
--- /dev/null
@@ -0,0 +1,44 @@
+=pod
+
+=head1 NAME
+
+SSL_free - free an allocated SSL structure
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ void SSL_free(SSL *ssl);
+
+=head1 DESCRIPTION
+
+SSL_free() decrements the reference count of B<ssl>, and removes the SSL
+structure pointed to by B<ssl> and frees up the allocated memory if the
+reference count has reached 0.
+
+=head1 NOTES
+
+SSL_free() also calls the free()ing procedures for indirectly affected items, if
+applicable: the buffering BIO, the read and write BIOs,
+cipher lists specially created for this B<ssl>, the B<SSL_SESSION>.
+Do not explicitly free these indirectly freed up items before or after
+calling SSL_free(), as trying to free things twice may lead to program
+failure.
+
+The ssl session has reference counts from two users: the SSL object, for
+which the reference count is removed by SSL_free() and the internal
+session cache. If the session is considered bad, because
+L<SSL_shutdown(3)|SSL_shutdown(3)> was not called for the connection
+and L<SSL_set_shutdown(3)|SSL_set_shutdown(3)> was not used to set the
+SSL_SENT_SHUTDOWN state, the session will also be removed
+from the session cache as required by RFC2246.
+
+=head1 RETURN VALUES
+
+SSL_free() does not provide diagnostic information.
+
+L<SSL_new(3)|SSL_new(3)>, L<SSL_clear(3)|SSL_clear(3)>,
+L<SSL_shutdown(3)|SSL_shutdown(3)>, L<SSL_set_shutdown(3)|SSL_set_shutdown(3)>,
+L<ssl(3)|ssl(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_get_SSL_CTX.pod b/deps/openssl/openssl/doc/ssl/SSL_get_SSL_CTX.pod
new file mode 100644 (file)
index 0000000..659c482
--- /dev/null
@@ -0,0 +1,26 @@
+=pod
+
+=head1 NAME
+
+SSL_get_SSL_CTX - get the SSL_CTX from which an SSL is created
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl);
+
+=head1 DESCRIPTION
+
+SSL_get_SSL_CTX() returns a pointer to the SSL_CTX object, from which
+B<ssl> was created with L<SSL_new(3)|SSL_new(3)>.
+
+=head1 RETURN VALUES
+
+The pointer to the SSL_CTX object is returned.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_new(3)|SSL_new(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_get_ciphers.pod b/deps/openssl/openssl/doc/ssl/SSL_get_ciphers.pod
new file mode 100644 (file)
index 0000000..aecadd9
--- /dev/null
@@ -0,0 +1,42 @@
+=pod
+
+=head1 NAME
+
+SSL_get_ciphers, SSL_get_cipher_list - get list of available SSL_CIPHERs
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *ssl);
+ const char *SSL_get_cipher_list(const SSL *ssl, int priority);
+
+=head1 DESCRIPTION
+
+SSL_get_ciphers() returns the stack of available SSL_CIPHERs for B<ssl>,
+sorted by preference. If B<ssl> is NULL or no ciphers are available, NULL
+is returned.
+
+SSL_get_cipher_list() returns a pointer to the name of the SSL_CIPHER
+listed for B<ssl> with B<priority>. If B<ssl> is NULL, no ciphers are
+available, or there are less ciphers than B<priority> available, NULL
+is returned.
+
+=head1 NOTES
+
+The details of the ciphers obtained by SSL_get_ciphers() can be obtained using
+the L<SSL_CIPHER_get_name(3)|SSL_CIPHER_get_name(3)> family of functions.
+
+Call SSL_get_cipher_list() with B<priority> starting from 0 to obtain the
+sorted list of available ciphers, until NULL is returned.
+
+=head1 RETURN VALUES
+
+See DESCRIPTION
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_CTX_set_cipher_list(3)|SSL_CTX_set_cipher_list(3)>,
+L<SSL_CIPHER_get_name(3)|SSL_CIPHER_get_name(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_get_client_CA_list.pod b/deps/openssl/openssl/doc/ssl/SSL_get_client_CA_list.pod
new file mode 100644 (file)
index 0000000..68181b2
--- /dev/null
@@ -0,0 +1,53 @@
+=pod
+
+=head1 NAME
+
+SSL_get_client_CA_list, SSL_CTX_get_client_CA_list - get list of client CAs
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ STACK_OF(X509_NAME) *SSL_get_client_CA_list(const SSL *s);
+ STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(const SSL_CTX *ctx); 
+
+=head1 DESCRIPTION
+
+SSL_CTX_get_client_CA_list() returns the list of client CAs explicitly set for
+B<ctx> using L<SSL_CTX_set_client_CA_list(3)|SSL_CTX_set_client_CA_list(3)>.
+
+SSL_get_client_CA_list() returns the list of client CAs explicitly
+set for B<ssl> using SSL_set_client_CA_list() or B<ssl>'s SSL_CTX object with
+L<SSL_CTX_set_client_CA_list(3)|SSL_CTX_set_client_CA_list(3)>, when in
+server mode. In client mode, SSL_get_client_CA_list returns the list of
+client CAs sent from the server, if any.
+
+=head1 RETURN VALUES
+
+SSL_CTX_set_client_CA_list() and SSL_set_client_CA_list() do not return
+diagnostic information.
+
+SSL_CTX_add_client_CA() and SSL_add_client_CA() have the following return
+values:
+
+=over 4
+
+=item STACK_OF(X509_NAMES)
+
+List of CA names explicitly set (for B<ctx> or in server mode) or send
+by the server (client mode).
+
+=item NULL
+
+No client CA list was explicitly set (for B<ctx> or in server mode) or
+the server did not send a list of CAs (client mode).
+
+=back
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>,
+L<SSL_CTX_set_client_CA_list(3)|SSL_CTX_set_client_CA_list(3)>,
+L<SSL_CTX_set_client_cert_cb(3)|SSL_CTX_set_client_cert_cb(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_get_current_cipher.pod b/deps/openssl/openssl/doc/ssl/SSL_get_current_cipher.pod
new file mode 100644 (file)
index 0000000..e5ab124
--- /dev/null
@@ -0,0 +1,43 @@
+=pod
+
+=head1 NAME
+
+SSL_get_current_cipher, SSL_get_cipher, SSL_get_cipher_name,
+SSL_get_cipher_bits, SSL_get_cipher_version - get SSL_CIPHER of a connection
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ SSL_CIPHER *SSL_get_current_cipher(const SSL *ssl);
+ #define SSL_get_cipher(s) \
+                SSL_CIPHER_get_name(SSL_get_current_cipher(s))
+ #define SSL_get_cipher_name(s) \
+                SSL_CIPHER_get_name(SSL_get_current_cipher(s))
+ #define SSL_get_cipher_bits(s,np) \
+                SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np)
+ #define SSL_get_cipher_version(s) \
+                SSL_CIPHER_get_version(SSL_get_current_cipher(s))
+
+=head1 DESCRIPTION
+
+SSL_get_current_cipher() returns a pointer to an SSL_CIPHER object containing
+the description of the actually used cipher of a connection established with
+the B<ssl> object.
+
+SSL_get_cipher() and SSL_get_cipher_name() are identical macros to obtain the
+name of the currently used cipher. SSL_get_cipher_bits() is a
+macro to obtain the number of secret/algorithm bits used and 
+SSL_get_cipher_version() returns the protocol name.
+See L<SSL_CIPHER_get_name(3)|SSL_CIPHER_get_name(3)> for more details.
+
+=head1 RETURN VALUES
+
+SSL_get_current_cipher() returns the cipher actually used or NULL, when
+no session has been established.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_CIPHER_get_name(3)|SSL_CIPHER_get_name(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_get_default_timeout.pod b/deps/openssl/openssl/doc/ssl/SSL_get_default_timeout.pod
new file mode 100644 (file)
index 0000000..a648a9b
--- /dev/null
@@ -0,0 +1,41 @@
+=pod
+
+=head1 NAME
+
+SSL_get_default_timeout - get default session timeout value
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ long SSL_get_default_timeout(const SSL *ssl);
+
+=head1 DESCRIPTION
+
+SSL_get_default_timeout() returns the default timeout value assigned to
+SSL_SESSION objects negotiated for the protocol valid for B<ssl>.
+
+=head1 NOTES
+
+Whenever a new session is negotiated, it is assigned a timeout value,
+after which it will not be accepted for session reuse. If the timeout
+value was not explicitly set using
+L<SSL_CTX_set_timeout(3)|SSL_CTX_set_timeout(3)>, the hardcoded default
+timeout for the protocol will be used.
+
+SSL_get_default_timeout() return this hardcoded value, which is 300 seconds
+for all currently supported protocols (SSLv2, SSLv3, and TLSv1).
+
+=head1 RETURN VALUES
+
+See description.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>,
+L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>,
+L<SSL_SESSION_get_time(3)|SSL_SESSION_get_time(3)>,
+L<SSL_CTX_flush_sessions(3)|SSL_CTX_flush_sessions(3)>,
+L<SSL_get_default_timeout(3)|SSL_get_default_timeout(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_get_error.pod b/deps/openssl/openssl/doc/ssl/SSL_get_error.pod
new file mode 100644 (file)
index 0000000..48c6b15
--- /dev/null
@@ -0,0 +1,114 @@
+=pod
+
+=head1 NAME
+
+SSL_get_error - obtain result code for TLS/SSL I/O operation
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_get_error(const SSL *ssl, int ret);
+
+=head1 DESCRIPTION
+
+SSL_get_error() returns a result code (suitable for the C "switch"
+statement) for a preceding call to SSL_connect(), SSL_accept(), SSL_do_handshake(),
+SSL_read(), SSL_peek(), or SSL_write() on B<ssl>.  The value returned by
+that TLS/SSL I/O function must be passed to SSL_get_error() in parameter
+B<ret>.
+
+In addition to B<ssl> and B<ret>, SSL_get_error() inspects the
+current thread's OpenSSL error queue.  Thus, SSL_get_error() must be
+used in the same thread that performed the TLS/SSL I/O operation, and no
+other OpenSSL function calls should appear in between.  The current
+thread's error queue must be empty before the TLS/SSL I/O operation is
+attempted, or SSL_get_error() will not work reliably.
+
+=head1 RETURN VALUES
+
+The following return values can currently occur:
+
+=over 4
+
+=item SSL_ERROR_NONE
+
+The TLS/SSL I/O operation completed.  This result code is returned
+if and only if B<ret E<gt> 0>.
+
+=item SSL_ERROR_ZERO_RETURN
+
+The TLS/SSL connection has been closed.  If the protocol version is SSL 3.0
+or TLS 1.0, this result code is returned only if a closure
+alert has occurred in the protocol, i.e. if the connection has been
+closed cleanly. Note that in this case B<SSL_ERROR_ZERO_RETURN>
+does not necessarily indicate that the underlying transport
+has been closed.
+
+=item SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE
+
+The operation did not complete; the same TLS/SSL I/O function should be
+called again later.  If, by then, the underlying B<BIO> has data
+available for reading (if the result code is B<SSL_ERROR_WANT_READ>)
+or allows writing data (B<SSL_ERROR_WANT_WRITE>), then some TLS/SSL
+protocol progress will take place, i.e. at least part of an TLS/SSL
+record will be read or written.  Note that the retry may again lead to
+a B<SSL_ERROR_WANT_READ> or B<SSL_ERROR_WANT_WRITE> condition.
+There is no fixed upper limit for the number of iterations that
+may be necessary until progress becomes visible at application
+protocol level.
+
+For socket B<BIO>s (e.g. when SSL_set_fd() was used), select() or
+poll() on the underlying socket can be used to find out when the
+TLS/SSL I/O function should be retried.
+
+Caveat: Any TLS/SSL I/O function can lead to either of
+B<SSL_ERROR_WANT_READ> and B<SSL_ERROR_WANT_WRITE>.  In particular,
+SSL_read() or SSL_peek() may want to write data and SSL_write() may want
+to read data.  This is mainly because TLS/SSL handshakes may occur at any
+time during the protocol (initiated by either the client or the server);
+SSL_read(), SSL_peek(), and SSL_write() will handle any pending handshakes.
+
+=item SSL_ERROR_WANT_CONNECT, SSL_ERROR_WANT_ACCEPT
+
+The operation did not complete; the same TLS/SSL I/O function should be
+called again later. The underlying BIO was not connected yet to the peer
+and the call would block in connect()/accept(). The SSL function should be
+called again when the connection is established. These messages can only
+appear with a BIO_s_connect() or BIO_s_accept() BIO, respectively.
+In order to find out, when the connection has been successfully established,
+on many platforms select() or poll() for writing on the socket file descriptor
+can be used.
+
+=item SSL_ERROR_WANT_X509_LOOKUP
+
+The operation did not complete because an application callback set by
+SSL_CTX_set_client_cert_cb() has asked to be called again.
+The TLS/SSL I/O function should be called again later.
+Details depend on the application.
+
+=item SSL_ERROR_SYSCALL
+
+Some I/O error occurred.  The OpenSSL error queue may contain more
+information on the error.  If the error queue is empty
+(i.e. ERR_get_error() returns 0), B<ret> can be used to find out more
+about the error: If B<ret == 0>, an EOF was observed that violates
+the protocol.  If B<ret == -1>, the underlying B<BIO> reported an
+I/O error (for socket I/O on Unix systems, consult B<errno> for details).
+
+=item SSL_ERROR_SSL
+
+A failure in the SSL library occurred, usually a protocol error.  The
+OpenSSL error queue contains more information on the error.
+
+=back
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<err(3)|err(3)>
+
+=head1 HISTORY
+
+SSL_get_error() was added in SSLeay 0.8.
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_get_ex_data_X509_STORE_CTX_idx.pod b/deps/openssl/openssl/doc/ssl/SSL_get_ex_data_X509_STORE_CTX_idx.pod
new file mode 100644 (file)
index 0000000..165c6a5
--- /dev/null
@@ -0,0 +1,61 @@
+=pod
+
+=head1 NAME
+
+SSL_get_ex_data_X509_STORE_CTX_idx - get ex_data index to access SSL structure
+from X509_STORE_CTX
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_get_ex_data_X509_STORE_CTX_idx(void);
+
+=head1 DESCRIPTION
+
+SSL_get_ex_data_X509_STORE_CTX_idx() returns the index number under which
+the pointer to the SSL object is stored into the X509_STORE_CTX object.
+
+=head1 NOTES
+
+Whenever a X509_STORE_CTX object is created for the verification of the
+peers certificate during a handshake, a pointer to the SSL object is
+stored into the X509_STORE_CTX object to identify the connection affected.
+To retrieve this pointer the X509_STORE_CTX_get_ex_data() function can
+be used with the correct index. This index is globally the same for all
+X509_STORE_CTX objects and can be retrieved using
+SSL_get_ex_data_X509_STORE_CTX_idx(). The index value is set when
+SSL_get_ex_data_X509_STORE_CTX_idx() is first called either by the application
+program directly or indirectly during other SSL setup functions or during
+the handshake.
+
+The value depends on other index values defined for X509_STORE_CTX objects
+before the SSL index is created.
+
+=head1 RETURN VALUES
+
+=over 4
+
+=item E<gt>=0
+
+The index value to access the pointer.
+
+=item E<lt>0
+
+An error occurred, check the error stack for a detailed error message.
+
+=back
+
+=head1 EXAMPLES
+
+The index returned from SSL_get_ex_data_X509_STORE_CTX_idx() allows to
+access the SSL object for the connection to be accessed during the
+verify_callback() when checking the peers certificate. Please check
+the example in L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>,
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>,
+L<CRYPTO_set_ex_data(3)|CRYPTO_set_ex_data(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_get_ex_new_index.pod b/deps/openssl/openssl/doc/ssl/SSL_get_ex_new_index.pod
new file mode 100644 (file)
index 0000000..228d23d
--- /dev/null
@@ -0,0 +1,59 @@
+=pod
+
+=head1 NAME
+
+SSL_get_ex_new_index, SSL_set_ex_data, SSL_get_ex_data - internal application specific data functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_get_ex_new_index(long argl, void *argp,
+                CRYPTO_EX_new *new_func,
+                CRYPTO_EX_dup *dup_func,
+                CRYPTO_EX_free *free_func);
+
+ int SSL_set_ex_data(SSL *ssl, int idx, void *arg);
+
+ void *SSL_get_ex_data(const SSL *ssl, int idx);
+
+ typedef int new_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
+                int idx, long argl, void *argp);
+ typedef void free_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
+                int idx, long argl, void *argp);
+ typedef int dup_func(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d,
+                int idx, long argl, void *argp);
+
+=head1 DESCRIPTION
+
+Several OpenSSL structures can have application specific data attached to them.
+These functions are used internally by OpenSSL to manipulate application
+specific data attached to a specific structure.
+
+SSL_get_ex_new_index() is used to register a new index for application
+specific data.
+
+SSL_set_ex_data() is used to store application data at B<arg> for B<idx> into
+the B<ssl> object.
+
+SSL_get_ex_data() is used to retrieve the information for B<idx> from
+B<ssl>.
+
+A detailed description for the B<*_get_ex_new_index()> functionality
+can be found in L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>.
+The B<*_get_ex_data()> and B<*_set_ex_data()> functionality is described in
+L<CRYPTO_set_ex_data(3)|CRYPTO_set_ex_data(3)>.
+
+=head1 EXAMPLES
+
+An example on how to use the functionality is included in the example
+verify_callback() in L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>,
+L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>,
+L<CRYPTO_set_ex_data(3)|CRYPTO_set_ex_data(3)>,
+L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_get_fd.pod b/deps/openssl/openssl/doc/ssl/SSL_get_fd.pod
new file mode 100644 (file)
index 0000000..89260b5
--- /dev/null
@@ -0,0 +1,44 @@
+=pod
+
+=head1 NAME
+
+SSL_get_fd - get file descriptor linked to an SSL object
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_get_fd(const SSL *ssl);
+ int SSL_get_rfd(const SSL *ssl);
+ int SSL_get_wfd(const SSL *ssl);
+
+=head1 DESCRIPTION
+
+SSL_get_fd() returns the file descriptor which is linked to B<ssl>.
+SSL_get_rfd() and SSL_get_wfd() return the file descriptors for the
+read or the write channel, which can be different. If the read and the
+write channel are different, SSL_get_fd() will return the file descriptor
+of the read channel.
+
+=head1 RETURN VALUES
+
+The following return values can occur:
+
+=over 4
+
+=item -1
+
+The operation failed, because the underlying BIO is not of the correct type
+(suitable for file descriptors).
+
+=item E<gt>=0
+
+The file descriptor linked to B<ssl>.
+
+=back
+
+=head1 SEE ALSO
+
+L<SSL_set_fd(3)|SSL_set_fd(3)>, L<ssl(3)|ssl(3)> , L<bio(3)|bio(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_get_peer_cert_chain.pod b/deps/openssl/openssl/doc/ssl/SSL_get_peer_cert_chain.pod
new file mode 100644 (file)
index 0000000..49fb88f
--- /dev/null
@@ -0,0 +1,52 @@
+=pod
+
+=head1 NAME
+
+SSL_get_peer_cert_chain - get the X509 certificate chain of the peer
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ STACKOF(X509) *SSL_get_peer_cert_chain(const SSL *ssl);
+
+=head1 DESCRIPTION
+
+SSL_get_peer_cert_chain() returns a pointer to STACKOF(X509) certificates
+forming the certificate chain of the peer. If called on the client side,
+the stack also contains the peer's certificate; if called on the server
+side, the peer's certificate must be obtained separately using
+L<SSL_get_peer_certificate(3)|SSL_get_peer_certificate(3)>.
+If the peer did not present a certificate, NULL is returned.
+
+=head1 NOTES
+
+The peer certificate chain is not necessarily available after reusing
+a session, in which case a NULL pointer is returned.
+
+The reference count of the STACKOF(X509) object is not incremented.
+If the corresponding session is freed, the pointer must not be used
+any longer.
+
+=head1 RETURN VALUES
+
+The following return values can occur:
+
+=over 4
+
+=item NULL
+
+No certificate was presented by the peer or no connection was established
+or the certificate chain is no longer available when a session is reused.
+
+=item Pointer to a STACKOF(X509)
+
+The return value points to the certificate chain presented by the peer.
+
+=back
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_get_peer_certificate(3)|SSL_get_peer_certificate(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_get_peer_certificate.pod b/deps/openssl/openssl/doc/ssl/SSL_get_peer_certificate.pod
new file mode 100644 (file)
index 0000000..ef7c8be
--- /dev/null
@@ -0,0 +1,55 @@
+=pod
+
+=head1 NAME
+
+SSL_get_peer_certificate - get the X509 certificate of the peer
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ X509 *SSL_get_peer_certificate(const SSL *ssl);
+
+=head1 DESCRIPTION
+
+SSL_get_peer_certificate() returns a pointer to the X509 certificate the
+peer presented. If the peer did not present a certificate, NULL is returned.
+
+=head1 NOTES
+
+Due to the protocol definition, a TLS/SSL server will always send a
+certificate, if present. A client will only send a certificate when
+explicitly requested to do so by the server (see
+L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>). If an anonymous cipher
+is used, no certificates are sent.
+
+That a certificate is returned does not indicate information about the
+verification state, use L<SSL_get_verify_result(3)|SSL_get_verify_result(3)>
+to check the verification state.
+
+The reference count of the X509 object is incremented by one, so that it
+will not be destroyed when the session containing the peer certificate is
+freed. The X509 object must be explicitly freed using X509_free().
+
+=head1 RETURN VALUES
+
+The following return values can occur:
+
+=over 4
+
+=item NULL
+
+No certificate was presented by the peer or no connection was established.
+
+=item Pointer to an X509 certificate
+
+The return value points to the certificate presented by the peer.
+
+=back
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_get_verify_result(3)|SSL_get_verify_result(3)>,
+L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_get_psk_identity.pod b/deps/openssl/openssl/doc/ssl/SSL_get_psk_identity.pod
new file mode 100644 (file)
index 0000000..fe62916
--- /dev/null
@@ -0,0 +1,63 @@
+=pod
+
+=begin comment
+
+Copyright 2005 Nokia. All rights reserved.
+
+The portions of the attached software ("Contribution") is developed by
+Nokia Corporation and is licensed pursuant to the OpenSSL open source
+license.
+
+The Contribution, originally written by Mika Kousa and Pasi Eronen of
+Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
+support (see RFC 4279) to OpenSSL.
+
+No patent licenses or other rights except those expressly stated in
+the OpenSSL open source license shall be deemed granted or received
+expressly, by implication, estoppel, or otherwise.
+
+No assurances are provided by Nokia that the Contribution does not
+infringe the patent or other intellectual property rights of any third
+party or that the license provides you with all the necessary rights
+to make use of the Contribution.
+
+THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
+ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
+SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
+OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
+OTHERWISE.
+
+=end comment
+
+=head1 NAME
+
+SSL_get_psk_identity, SSL_get_psk_identity_hint - get PSK client identity and hint
+
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ const char *SSL_get_psk_identity_hint(const SSL *ssl);
+ const char *SSL_get_psk_identity(const SSL *ssl);
+
+
+=head1 DESCRIPTION
+
+SSL_get_psk_identity_hint() is used to retrieve the PSK identity hint
+used during the connection setup related to SSL object
+B<ssl>. Similarly, SSL_get_psk_identity() is used to retrieve the PSK
+identity used during the connection setup.
+
+
+=head1 RETURN VALUES
+
+If non-B<NULL>, SSL_get_psk_identity_hint() returns the PSK identity
+hint and SSL_get_psk_identity() returns the PSK identity. Both are
+B<NULL>-terminated. SSL_get_psk_identity_hint() may return B<NULL> if
+no PSK identity hint was used during the connection setup.
+
+Note that the return value is valid only during the lifetime of the
+SSL object B<ssl>.
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_get_rbio.pod b/deps/openssl/openssl/doc/ssl/SSL_get_rbio.pod
new file mode 100644 (file)
index 0000000..3d98233
--- /dev/null
@@ -0,0 +1,40 @@
+=pod
+
+=head1 NAME
+
+SSL_get_rbio - get BIO linked to an SSL object
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ BIO *SSL_get_rbio(SSL *ssl);
+ BIO *SSL_get_wbio(SSL *ssl);
+
+=head1 DESCRIPTION
+
+SSL_get_rbio() and SSL_get_wbio() return pointers to the BIOs for the
+read or the write channel, which can be different. The reference count
+of the BIO is not incremented.
+
+=head1 RETURN VALUES
+
+The following return values can occur:
+
+=over 4
+
+=item NULL
+
+No BIO was connected to the SSL object
+
+=item Any other pointer
+
+The BIO linked to B<ssl>.
+
+=back
+
+=head1 SEE ALSO
+
+L<SSL_set_bio(3)|SSL_set_bio(3)>, L<ssl(3)|ssl(3)> , L<bio(3)|bio(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_get_session.pod b/deps/openssl/openssl/doc/ssl/SSL_get_session.pod
new file mode 100644 (file)
index 0000000..0c41caa
--- /dev/null
@@ -0,0 +1,73 @@
+=pod
+
+=head1 NAME
+
+SSL_get_session - retrieve TLS/SSL session data
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ SSL_SESSION *SSL_get_session(const SSL *ssl);
+ SSL_SESSION *SSL_get0_session(const SSL *ssl);
+ SSL_SESSION *SSL_get1_session(SSL *ssl);
+
+=head1 DESCRIPTION
+
+SSL_get_session() returns a pointer to the B<SSL_SESSION> actually used in
+B<ssl>. The reference count of the B<SSL_SESSION> is not incremented, so
+that the pointer can become invalid by other operations.
+
+SSL_get0_session() is the same as SSL_get_session().
+
+SSL_get1_session() is the same as SSL_get_session(), but the reference
+count of the B<SSL_SESSION> is incremented by one.
+
+=head1 NOTES
+
+The ssl session contains all information required to re-establish the
+connection without a new handshake.
+
+SSL_get0_session() returns a pointer to the actual session. As the
+reference counter is not incremented, the pointer is only valid while
+the connection is in use. If L<SSL_clear(3)|SSL_clear(3)> or
+L<SSL_free(3)|SSL_free(3)> is called, the session may be removed completely
+(if considered bad), and the pointer obtained will become invalid. Even
+if the session is valid, it can be removed at any time due to timeout
+during L<SSL_CTX_flush_sessions(3)|SSL_CTX_flush_sessions(3)>.
+
+If the data is to be kept, SSL_get1_session() will increment the reference
+count, so that the session will not be implicitly removed by other operations
+but stays in memory. In order to remove the session
+L<SSL_SESSION_free(3)|SSL_SESSION_free(3)> must be explicitly called once
+to decrement the reference count again.
+
+SSL_SESSION objects keep internal link information about the session cache
+list, when being inserted into one SSL_CTX object's session cache.
+One SSL_SESSION object, regardless of its reference count, must therefore
+only be used with one SSL_CTX object (and the SSL objects created
+from this SSL_CTX object).
+
+=head1 RETURN VALUES
+
+The following return values can occur:
+
+=over 4
+
+=item NULL
+
+There is no session available in B<ssl>.
+
+=item Pointer to an SSL
+
+The return value points to the data of an SSL session.
+
+=back
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_free(3)|SSL_free(3)>,
+L<SSL_clear(3)|SSL_clear(3)>,
+L<SSL_SESSION_free(3)|SSL_SESSION_free(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_get_verify_result.pod b/deps/openssl/openssl/doc/ssl/SSL_get_verify_result.pod
new file mode 100644 (file)
index 0000000..55b56a5
--- /dev/null
@@ -0,0 +1,57 @@
+=pod
+
+=head1 NAME
+
+SSL_get_verify_result - get result of peer certificate verification
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ long SSL_get_verify_result(const SSL *ssl);
+
+=head1 DESCRIPTION
+
+SSL_get_verify_result() returns the result of the verification of the
+X509 certificate presented by the peer, if any.
+
+=head1 NOTES
+
+SSL_get_verify_result() can only return one error code while the verification
+of a certificate can fail because of many reasons at the same time. Only
+the last verification error that occurred during the processing is available
+from SSL_get_verify_result().
+
+The verification result is part of the established session and is restored
+when a session is reused.
+
+=head1 BUGS
+
+If no peer certificate was presented, the returned result code is
+X509_V_OK. This is because no verification error occurred, it does however
+not indicate success. SSL_get_verify_result() is only useful in connection
+with L<SSL_get_peer_certificate(3)|SSL_get_peer_certificate(3)>.
+
+=head1 RETURN VALUES
+
+The following return values can currently occur:
+
+=over 4
+
+=item X509_V_OK
+
+The verification succeeded or no peer certificate was presented.
+
+=item Any other value
+
+Documented in L<verify(1)|verify(1)>.
+
+=back
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_set_verify_result(3)|SSL_set_verify_result(3)>,
+L<SSL_get_peer_certificate(3)|SSL_get_peer_certificate(3)>,
+L<verify(1)|verify(1)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_get_version.pod b/deps/openssl/openssl/doc/ssl/SSL_get_version.pod
new file mode 100644 (file)
index 0000000..cc271db
--- /dev/null
@@ -0,0 +1,46 @@
+=pod
+
+=head1 NAME
+
+SSL_get_version - get the protocol version of a connection.
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ const char *SSL_get_version(const SSL *ssl);
+
+=head1 DESCRIPTION
+
+SSL_get_cipher_version() returns the name of the protocol used for the
+connection B<ssl>.
+
+=head1 RETURN VALUES
+
+The following strings can occur:
+
+=over 4
+
+=item SSLv2
+
+The connection uses the SSLv2 protocol.
+
+=item SSLv3
+
+The connection uses the SSLv3 protocol.
+
+=item TLSv1
+
+The connection uses the TLSv1 protocol.
+
+=item unknown
+
+This indicates that no version has been set (no connection established).
+
+=back
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_library_init.pod b/deps/openssl/openssl/doc/ssl/SSL_library_init.pod
new file mode 100644 (file)
index 0000000..8766776
--- /dev/null
@@ -0,0 +1,57 @@
+=pod
+
+=head1 NAME
+
+SSL_library_init, OpenSSL_add_ssl_algorithms, SSLeay_add_ssl_algorithms
+- initialize SSL library by registering algorithms
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_library_init(void);
+ #define OpenSSL_add_ssl_algorithms()    SSL_library_init()
+ #define SSLeay_add_ssl_algorithms()     SSL_library_init()
+
+=head1 DESCRIPTION
+
+SSL_library_init() registers the available SSL/TLS ciphers and digests.
+
+OpenSSL_add_ssl_algorithms() and SSLeay_add_ssl_algorithms() are synonyms
+for SSL_library_init().
+
+=head1 NOTES
+
+SSL_library_init() must be called before any other action takes place.
+SSL_library_init() is not reentrant. 
+
+=head1 WARNING
+
+SSL_library_init() adds ciphers and digests used directly and indirectly by
+SSL/TLS.
+
+=head1 EXAMPLES
+
+A typical TLS/SSL application will start with the library initialization,
+and provide readable error messages.
+
+ SSL_load_error_strings();                /* readable error messages */
+ SSL_library_init();                      /* initialize library */
+
+=head1 RETURN VALUES
+
+SSL_library_init() always returns "1", so it is safe to discard the return
+value.
+
+=head1 NOTES
+
+OpenSSL 0.9.8o and 1.0.0a and later added SHA2 algorithms to SSL_library_init().
+Applications which need to use SHA2 in earlier versions of OpenSSL should call
+OpenSSL_add_all_algorithms() as well.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_load_error_strings(3)|SSL_load_error_strings(3)>,
+L<RAND_add(3)|RAND_add(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_load_client_CA_file.pod b/deps/openssl/openssl/doc/ssl/SSL_load_client_CA_file.pod
new file mode 100644 (file)
index 0000000..02527dc
--- /dev/null
@@ -0,0 +1,62 @@
+=pod
+
+=head1 NAME
+
+SSL_load_client_CA_file - load certificate names from file
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file);
+
+=head1 DESCRIPTION
+
+SSL_load_client_CA_file() reads certificates from B<file> and returns
+a STACK_OF(X509_NAME) with the subject names found.
+
+=head1 NOTES
+
+SSL_load_client_CA_file() reads a file of PEM formatted certificates and
+extracts the X509_NAMES of the certificates found. While the name suggests
+the specific usage as support function for
+L<SSL_CTX_set_client_CA_list(3)|SSL_CTX_set_client_CA_list(3)>,
+it is not limited to CA certificates.
+
+=head1 EXAMPLES
+
+Load names of CAs from file and use it as a client CA list:
+
+ SSL_CTX *ctx;
+ STACK_OF(X509_NAME) *cert_names;
+
+ ... 
+ cert_names = SSL_load_client_CA_file("/path/to/CAfile.pem");
+ if (cert_names != NULL)
+   SSL_CTX_set_client_CA_list(ctx, cert_names);
+ else
+   error_handling();
+ ...
+
+=head1 RETURN VALUES
+
+The following return values can occur:
+
+=over 4
+
+=item NULL
+
+The operation failed, check out the error stack for the reason.
+
+=item Pointer to STACK_OF(X509_NAME)
+
+Pointer to the subject names of the successfully read certificates.
+
+=back
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>,
+L<SSL_CTX_set_client_CA_list(3)|SSL_CTX_set_client_CA_list(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_new.pod b/deps/openssl/openssl/doc/ssl/SSL_new.pod
new file mode 100644 (file)
index 0000000..25300e9
--- /dev/null
@@ -0,0 +1,44 @@
+=pod
+
+=head1 NAME
+
+SSL_new - create a new SSL structure for a connection
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ SSL *SSL_new(SSL_CTX *ctx);
+
+=head1 DESCRIPTION
+
+SSL_new() creates a new B<SSL> structure which is needed to hold the
+data for a TLS/SSL connection. The new structure inherits the settings
+of the underlying context B<ctx>: connection method (SSLv2/v3/TLSv1),
+options, verification settings, timeout settings.
+
+=head1 RETURN VALUES
+
+The following return values can occur:
+
+=over 4
+
+=item NULL
+
+The creation of a new SSL structure failed. Check the error stack to
+find out the reason.
+
+=item Pointer to an SSL structure
+
+The return value points to an allocated SSL structure.
+
+=back
+
+=head1 SEE ALSO
+
+L<SSL_free(3)|SSL_free(3)>, L<SSL_clear(3)|SSL_clear(3)>,
+L<SSL_CTX_set_options(3)|SSL_CTX_set_options(3)>,
+L<SSL_get_SSL_CTX(3)|SSL_get_SSL_CTX(3)>,
+L<ssl(3)|ssl(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_pending.pod b/deps/openssl/openssl/doc/ssl/SSL_pending.pod
new file mode 100644 (file)
index 0000000..43f2874
--- /dev/null
@@ -0,0 +1,43 @@
+=pod
+
+=head1 NAME
+
+SSL_pending - obtain number of readable bytes buffered in an SSL object
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_pending(const SSL *ssl);
+
+=head1 DESCRIPTION
+
+SSL_pending() returns the number of bytes which are available inside
+B<ssl> for immediate read.
+
+=head1 NOTES
+
+Data are received in blocks from the peer. Therefore data can be buffered
+inside B<ssl> and are ready for immediate retrieval with
+L<SSL_read(3)|SSL_read(3)>.
+
+=head1 RETURN VALUES
+
+The number of bytes pending is returned.
+
+=head1 BUGS
+
+SSL_pending() takes into account only bytes from the TLS/SSL record
+that is currently being processed (if any).  If the B<SSL> object's
+I<read_ahead> flag is set, additional protocol bytes may have been
+read containing more TLS/SSL records; these are ignored by
+SSL_pending().
+
+Up to OpenSSL 0.9.6, SSL_pending() does not check if the record type
+of pending data is application data.
+
+=head1 SEE ALSO
+
+L<SSL_read(3)|SSL_read(3)>, L<ssl(3)|ssl(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_read.pod b/deps/openssl/openssl/doc/ssl/SSL_read.pod
new file mode 100644 (file)
index 0000000..7038cd2
--- /dev/null
@@ -0,0 +1,124 @@
+=pod
+
+=head1 NAME
+
+SSL_read - read bytes from a TLS/SSL connection.
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_read(SSL *ssl, void *buf, int num);
+
+=head1 DESCRIPTION
+
+SSL_read() tries to read B<num> bytes from the specified B<ssl> into the
+buffer B<buf>.
+
+=head1 NOTES
+
+If necessary, SSL_read() will negotiate a TLS/SSL session, if
+not already explicitly performed by L<SSL_connect(3)|SSL_connect(3)> or
+L<SSL_accept(3)|SSL_accept(3)>. If the
+peer requests a re-negotiation, it will be performed transparently during
+the SSL_read() operation. The behaviour of SSL_read() depends on the
+underlying BIO. 
+
+For the transparent negotiation to succeed, the B<ssl> must have been
+initialized to client or server mode. This is being done by calling
+L<SSL_set_connect_state(3)|SSL_set_connect_state(3)> or SSL_set_accept_state()
+before the first call to an SSL_read() or L<SSL_write(3)|SSL_write(3)>
+function.
+
+SSL_read() works based on the SSL/TLS records. The data are received in
+records (with a maximum record size of 16kB for SSLv3/TLSv1). Only when a
+record has been completely received, it can be processed (decryption and
+check of integrity). Therefore data that was not retrieved at the last
+call of SSL_read() can still be buffered inside the SSL layer and will be
+retrieved on the next call to SSL_read(). If B<num> is higher than the
+number of bytes buffered, SSL_read() will return with the bytes buffered.
+If no more bytes are in the buffer, SSL_read() will trigger the processing
+of the next record. Only when the record has been received and processed
+completely, SSL_read() will return reporting success. At most the contents
+of the record will be returned. As the size of an SSL/TLS record may exceed
+the maximum packet size of the underlying transport (e.g. TCP), it may
+be necessary to read several packets from the transport layer before the
+record is complete and SSL_read() can succeed.
+
+If the underlying BIO is B<blocking>, SSL_read() will only return, once the
+read operation has been finished or an error occurred, except when a
+renegotiation take place, in which case a SSL_ERROR_WANT_READ may occur. 
+This behaviour can be controlled with the SSL_MODE_AUTO_RETRY flag of the
+L<SSL_CTX_set_mode(3)|SSL_CTX_set_mode(3)> call.
+
+If the underlying BIO is B<non-blocking>, SSL_read() will also return
+when the underlying BIO could not satisfy the needs of SSL_read()
+to continue the operation. In this case a call to
+L<SSL_get_error(3)|SSL_get_error(3)> with the
+return value of SSL_read() will yield B<SSL_ERROR_WANT_READ> or
+B<SSL_ERROR_WANT_WRITE>. As at any time a re-negotiation is possible, a
+call to SSL_read() can also cause write operations! The calling process
+then must repeat the call after taking appropriate action to satisfy the
+needs of SSL_read(). The action depends on the underlying BIO. When using a
+non-blocking socket, nothing is to be done, but select() can be used to check
+for the required condition. When using a buffering BIO, like a BIO pair, data
+must be written into or retrieved out of the BIO before being able to continue.
+
+L<SSL_pending(3)|SSL_pending(3)> can be used to find out whether there
+are buffered bytes available for immediate retrieval. In this case
+SSL_read() can be called without blocking or actually receiving new
+data from the underlying socket.
+
+=head1 WARNING
+
+When an SSL_read() operation has to be repeated because of
+B<SSL_ERROR_WANT_READ> or B<SSL_ERROR_WANT_WRITE>, it must be repeated
+with the same arguments.
+
+=head1 RETURN VALUES
+
+The following return values can occur:
+
+=over 4
+
+=item E<gt>0
+
+The read operation was successful; the return value is the number of
+bytes actually read from the TLS/SSL connection.
+
+=item 0
+
+The read operation was not successful. The reason may either be a clean
+shutdown due to a "close notify" alert sent by the peer (in which case
+the SSL_RECEIVED_SHUTDOWN flag in the ssl shutdown state is set
+(see L<SSL_shutdown(3)|SSL_shutdown(3)>,
+L<SSL_set_shutdown(3)|SSL_set_shutdown(3)>). It is also possible, that
+the peer simply shut down the underlying transport and the shutdown is
+incomplete. Call SSL_get_error() with the return value B<ret> to find out,
+whether an error occurred or the connection was shut down cleanly
+(SSL_ERROR_ZERO_RETURN).
+
+SSLv2 (deprecated) does not support a shutdown alert protocol, so it can
+only be detected, whether the underlying connection was closed. It cannot
+be checked, whether the closure was initiated by the peer or by something
+else.
+
+=item E<lt>0
+
+The read operation was not successful, because either an error occurred
+or action must be taken by the calling process. Call SSL_get_error() with the
+return value B<ret> to find out the reason.
+
+=back
+
+=head1 SEE ALSO
+
+L<SSL_get_error(3)|SSL_get_error(3)>, L<SSL_write(3)|SSL_write(3)>,
+L<SSL_CTX_set_mode(3)|SSL_CTX_set_mode(3)>, L<SSL_CTX_new(3)|SSL_CTX_new(3)>,
+L<SSL_connect(3)|SSL_connect(3)>, L<SSL_accept(3)|SSL_accept(3)>
+L<SSL_set_connect_state(3)|SSL_set_connect_state(3)>,
+L<SSL_pending(3)|SSL_pending(3)>,
+L<SSL_shutdown(3)|SSL_shutdown(3)>, L<SSL_set_shutdown(3)|SSL_set_shutdown(3)>,
+L<ssl(3)|ssl(3)>, L<bio(3)|bio(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_rstate_string.pod b/deps/openssl/openssl/doc/ssl/SSL_rstate_string.pod
new file mode 100644 (file)
index 0000000..bdb8a1f
--- /dev/null
@@ -0,0 +1,59 @@
+=pod
+
+=head1 NAME
+
+SSL_rstate_string, SSL_rstate_string_long - get textual description of state of an SSL object during read operation
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ const char *SSL_rstate_string(SSL *ssl);
+ const char *SSL_rstate_string_long(SSL *ssl);
+
+=head1 DESCRIPTION
+
+SSL_rstate_string() returns a 2 letter string indicating the current read state
+of the SSL object B<ssl>.
+
+SSL_rstate_string_long() returns a string indicating the current read state of
+the SSL object B<ssl>.
+
+=head1 NOTES
+
+When performing a read operation, the SSL/TLS engine must parse the record,
+consisting of header and body. When working in a blocking environment,
+SSL_rstate_string[_long]() should always return "RD"/"read done".
+
+This function should only seldom be needed in applications.
+
+=head1 RETURN VALUES
+
+SSL_rstate_string() and SSL_rstate_string_long() can return the following
+values:
+
+=over 4
+
+=item "RH"/"read header"
+
+The header of the record is being evaluated.
+
+=item "RB"/"read body"
+
+The body of the record is being evaluated.
+
+=item "RD"/"read done"
+
+The record has been completely processed.
+
+=item "unknown"/"unknown"
+
+The read state is unknown. This should never happen.
+
+=back
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_session_reused.pod b/deps/openssl/openssl/doc/ssl/SSL_session_reused.pod
new file mode 100644 (file)
index 0000000..da7d062
--- /dev/null
@@ -0,0 +1,45 @@
+=pod
+
+=head1 NAME
+
+SSL_session_reused - query whether a reused session was negotiated during handshake
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_session_reused(SSL *ssl);
+
+=head1 DESCRIPTION
+
+Query, whether a reused session was negotiated during the handshake.
+
+=head1 NOTES
+
+During the negotiation, a client can propose to reuse a session. The server
+then looks up the session in its cache. If both client and server agree
+on the session, it will be reused and a flag is being set that can be
+queried by the application.
+
+=head1 RETURN VALUES
+
+The following return values can occur:
+
+=over 4
+
+=item 0
+
+A new session was negotiated.
+
+=item 1
+
+A session was reused.
+
+=back
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_set_session(3)|SSL_set_session(3)>,
+L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_set_bio.pod b/deps/openssl/openssl/doc/ssl/SSL_set_bio.pod
new file mode 100644 (file)
index 0000000..67c9756
--- /dev/null
@@ -0,0 +1,34 @@
+=pod
+
+=head1 NAME
+
+SSL_set_bio - connect the SSL object with a BIO
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ void SSL_set_bio(SSL *ssl, BIO *rbio, BIO *wbio);
+
+=head1 DESCRIPTION
+
+SSL_set_bio() connects the BIOs B<rbio> and B<wbio> for the read and write
+operations of the TLS/SSL (encrypted) side of B<ssl>.
+
+The SSL engine inherits the behaviour of B<rbio> and B<wbio>, respectively.
+If a BIO is non-blocking, the B<ssl> will also have non-blocking behaviour.
+
+If there was already a BIO connected to B<ssl>, BIO_free() will be called
+(for both the reading and writing side, if different).
+
+=head1 RETURN VALUES
+
+SSL_set_bio() cannot fail.
+
+=head1 SEE ALSO
+
+L<SSL_get_rbio(3)|SSL_get_rbio(3)>,
+L<SSL_connect(3)|SSL_connect(3)>, L<SSL_accept(3)|SSL_accept(3)>,
+L<SSL_shutdown(3)|SSL_shutdown(3)>, L<ssl(3)|ssl(3)>, L<bio(3)|bio(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_set_connect_state.pod b/deps/openssl/openssl/doc/ssl/SSL_set_connect_state.pod
new file mode 100644 (file)
index 0000000..d88a057
--- /dev/null
@@ -0,0 +1,55 @@
+=pod
+
+=head1 NAME
+
+SSL_set_connect_state, SSL_get_accept_state - prepare SSL object to work in client or server mode
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ void SSL_set_connect_state(SSL *ssl);
+
+ void SSL_set_accept_state(SSL *ssl);
+
+=head1 DESCRIPTION
+
+SSL_set_connect_state() sets B<ssl> to work in client mode.
+
+SSL_set_accept_state() sets B<ssl> to work in server mode.
+
+=head1 NOTES
+
+When the SSL_CTX object was created with L<SSL_CTX_new(3)|SSL_CTX_new(3)>,
+it was either assigned a dedicated client method, a dedicated server
+method, or a generic method, that can be used for both client and
+server connections. (The method might have been changed with
+L<SSL_CTX_set_ssl_version(3)|SSL_CTX_set_ssl_version(3)> or
+SSL_set_ssl_method().)
+
+When beginning a new handshake, the SSL engine must know whether it must
+call the connect (client) or accept (server) routines. Even though it may
+be clear from the method chosen, whether client or server mode was
+requested, the handshake routines must be explicitly set.
+
+When using the L<SSL_connect(3)|SSL_connect(3)> or
+L<SSL_accept(3)|SSL_accept(3)> routines, the correct handshake
+routines are automatically set. When performing a transparent negotiation
+using L<SSL_write(3)|SSL_write(3)> or L<SSL_read(3)|SSL_read(3)>, the
+handshake routines must be explicitly set in advance using either
+SSL_set_connect_state() or SSL_set_accept_state().
+
+=head1 RETURN VALUES
+
+SSL_set_connect_state() and SSL_set_accept_state() do not return diagnostic
+information.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_new(3)|SSL_new(3)>, L<SSL_CTX_new(3)|SSL_CTX_new(3)>,
+L<SSL_connect(3)|SSL_connect(3)>, L<SSL_accept(3)|SSL_accept(3)>,
+L<SSL_write(3)|SSL_write(3)>, L<SSL_read(3)|SSL_read(3)>,
+L<SSL_do_handshake(3)|SSL_do_handshake(3)>,
+L<SSL_CTX_set_ssl_version(3)|SSL_CTX_set_ssl_version(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_set_fd.pod b/deps/openssl/openssl/doc/ssl/SSL_set_fd.pod
new file mode 100644 (file)
index 0000000..7029112
--- /dev/null
@@ -0,0 +1,54 @@
+=pod
+
+=head1 NAME
+
+SSL_set_fd - connect the SSL object with a file descriptor
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_set_fd(SSL *ssl, int fd);
+ int SSL_set_rfd(SSL *ssl, int fd);
+ int SSL_set_wfd(SSL *ssl, int fd);
+
+=head1 DESCRIPTION
+
+SSL_set_fd() sets the file descriptor B<fd> as the input/output facility
+for the TLS/SSL (encrypted) side of B<ssl>. B<fd> will typically be the
+socket file descriptor of a network connection.
+
+When performing the operation, a B<socket BIO> is automatically created to
+interface between the B<ssl> and B<fd>. The BIO and hence the SSL engine
+inherit the behaviour of B<fd>. If B<fd> is non-blocking, the B<ssl> will
+also have non-blocking behaviour.
+
+If there was already a BIO connected to B<ssl>, BIO_free() will be called
+(for both the reading and writing side, if different).
+
+SSL_set_rfd() and SSL_set_wfd() perform the respective action, but only
+for the read channel or the write channel, which can be set independently.
+
+=head1 RETURN VALUES
+
+The following return values can occur:
+
+=over 4
+
+=item 0
+
+The operation failed. Check the error stack to find out why.
+
+=item 1
+
+The operation succeeded.
+
+=back
+
+=head1 SEE ALSO
+
+L<SSL_get_fd(3)|SSL_get_fd(3)>, L<SSL_set_bio(3)|SSL_set_bio(3)>,
+L<SSL_connect(3)|SSL_connect(3)>, L<SSL_accept(3)|SSL_accept(3)>,
+L<SSL_shutdown(3)|SSL_shutdown(3)>, L<ssl(3)|ssl(3)> , L<bio(3)|bio(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_set_session.pod b/deps/openssl/openssl/doc/ssl/SSL_set_session.pod
new file mode 100644 (file)
index 0000000..5f54714
--- /dev/null
@@ -0,0 +1,57 @@
+=pod
+
+=head1 NAME
+
+SSL_set_session - set a TLS/SSL session to be used during TLS/SSL connect
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_set_session(SSL *ssl, SSL_SESSION *session);
+
+=head1 DESCRIPTION
+
+SSL_set_session() sets B<session> to be used when the TLS/SSL connection
+is to be established. SSL_set_session() is only useful for TLS/SSL clients.
+When the session is set, the reference count of B<session> is incremented
+by 1. If the session is not reused, the reference count is decremented
+again during SSL_connect(). Whether the session was reused can be queried
+with the L<SSL_session_reused(3)|SSL_session_reused(3)> call.
+
+If there is already a session set inside B<ssl> (because it was set with
+SSL_set_session() before or because the same B<ssl> was already used for
+a connection), SSL_SESSION_free() will be called for that session.
+
+=head1 NOTES
+
+SSL_SESSION objects keep internal link information about the session cache
+list, when being inserted into one SSL_CTX object's session cache.
+One SSL_SESSION object, regardless of its reference count, must therefore
+only be used with one SSL_CTX object (and the SSL objects created
+from this SSL_CTX object).
+
+=head1 RETURN VALUES
+
+The following return values can occur:
+
+=over 4
+
+=item 0
+
+The operation failed; check the error stack to find out the reason.
+
+=item 1
+
+The operation succeeded.
+
+=back
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_SESSION_free(3)|SSL_SESSION_free(3)>,
+L<SSL_get_session(3)|SSL_get_session(3)>,
+L<SSL_session_reused(3)|SSL_session_reused(3)>,
+L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_set_shutdown.pod b/deps/openssl/openssl/doc/ssl/SSL_set_shutdown.pod
new file mode 100644 (file)
index 0000000..011a022
--- /dev/null
@@ -0,0 +1,72 @@
+=pod
+
+=head1 NAME
+
+SSL_set_shutdown, SSL_get_shutdown - manipulate shutdown state of an SSL connection
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ void SSL_set_shutdown(SSL *ssl, int mode);
+
+ int SSL_get_shutdown(const SSL *ssl);
+
+=head1 DESCRIPTION
+
+SSL_set_shutdown() sets the shutdown state of B<ssl> to B<mode>.
+
+SSL_get_shutdown() returns the shutdown mode of B<ssl>.
+
+=head1 NOTES
+
+The shutdown state of an ssl connection is a bitmask of:
+
+=over 4
+
+=item 0
+
+No shutdown setting, yet.
+
+=item SSL_SENT_SHUTDOWN
+
+A "close notify" shutdown alert was sent to the peer, the connection is being
+considered closed and the session is closed and correct.
+
+=item SSL_RECEIVED_SHUTDOWN
+
+A shutdown alert was received form the peer, either a normal "close notify"
+or a fatal error.
+
+=back
+
+SSL_SENT_SHUTDOWN and SSL_RECEIVED_SHUTDOWN can be set at the same time.
+
+The shutdown state of the connection is used to determine the state of
+the ssl session. If the session is still open, when
+L<SSL_clear(3)|SSL_clear(3)> or L<SSL_free(3)|SSL_free(3)> is called,
+it is considered bad and removed according to RFC2246.
+The actual condition for a correctly closed session is SSL_SENT_SHUTDOWN
+(according to the TLS RFC, it is acceptable to only send the "close notify"
+alert but to not wait for the peer's answer, when the underlying connection
+is closed).
+SSL_set_shutdown() can be used to set this state without sending a
+close alert to the peer (see L<SSL_shutdown(3)|SSL_shutdown(3)>).
+
+If a "close notify" was received, SSL_RECEIVED_SHUTDOWN will be set,
+for setting SSL_SENT_SHUTDOWN the application must however still call
+L<SSL_shutdown(3)|SSL_shutdown(3)> or SSL_set_shutdown() itself.
+
+=head1 RETURN VALUES
+
+SSL_set_shutdown() does not return diagnostic information.
+
+SSL_get_shutdown() returns the current setting.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_shutdown(3)|SSL_shutdown(3)>,
+L<SSL_CTX_set_quiet_shutdown(3)|SSL_CTX_set_quiet_shutdown(3)>,
+L<SSL_clear(3)|SSL_clear(3)>, L<SSL_free(3)|SSL_free(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_set_verify_result.pod b/deps/openssl/openssl/doc/ssl/SSL_set_verify_result.pod
new file mode 100644 (file)
index 0000000..04ab101
--- /dev/null
@@ -0,0 +1,38 @@
+=pod
+
+=head1 NAME
+
+SSL_set_verify_result - override result of peer certificate verification
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ void SSL_set_verify_result(SSL *ssl, long verify_result);
+
+=head1 DESCRIPTION
+
+SSL_set_verify_result() sets B<verify_result> of the object B<ssl> to be the
+result of the verification of the X509 certificate presented by the peer,
+if any.
+
+=head1 NOTES
+
+SSL_set_verify_result() overrides the verification result. It only changes
+the verification result of the B<ssl> object. It does not become part of the
+established session, so if the session is to be reused later, the original
+value will reappear.
+
+The valid codes for B<verify_result> are documented in L<verify(1)|verify(1)>.
+
+=head1 RETURN VALUES
+
+SSL_set_verify_result() does not provide a return value.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_get_verify_result(3)|SSL_get_verify_result(3)>,
+L<SSL_get_peer_certificate(3)|SSL_get_peer_certificate(3)>,
+L<verify(1)|verify(1)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_shutdown.pod b/deps/openssl/openssl/doc/ssl/SSL_shutdown.pod
new file mode 100644 (file)
index 0000000..89911ac
--- /dev/null
@@ -0,0 +1,125 @@
+=pod
+
+=head1 NAME
+
+SSL_shutdown - shut down a TLS/SSL connection
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_shutdown(SSL *ssl);
+
+=head1 DESCRIPTION
+
+SSL_shutdown() shuts down an active TLS/SSL connection. It sends the 
+"close notify" shutdown alert to the peer.
+
+=head1 NOTES
+
+SSL_shutdown() tries to send the "close notify" shutdown alert to the peer.
+Whether the operation succeeds or not, the SSL_SENT_SHUTDOWN flag is set and
+a currently open session is considered closed and good and will be kept in the
+session cache for further reuse.
+
+The shutdown procedure consists of 2 steps: the sending of the "close notify"
+shutdown alert and the reception of the peer's "close notify" shutdown
+alert. According to the TLS standard, it is acceptable for an application
+to only send its shutdown alert and then close the underlying connection
+without waiting for the peer's response (this way resources can be saved,
+as the process can already terminate or serve another connection).
+When the underlying connection shall be used for more communications, the
+complete shutdown procedure (bidirectional "close notify" alerts) must be
+performed, so that the peers stay synchronized.
+
+SSL_shutdown() supports both uni- and bidirectional shutdown by its 2 step
+behaviour.
+
+=over 4
+
+=item When the application is the first party to send the "close notify"
+alert, SSL_shutdown() will only send the alert and then set the
+SSL_SENT_SHUTDOWN flag (so that the session is considered good and will
+be kept in cache). SSL_shutdown() will then return with 0. If a unidirectional
+shutdown is enough (the underlying connection shall be closed anyway), this
+first call to SSL_shutdown() is sufficient. In order to complete the
+bidirectional shutdown handshake, SSL_shutdown() must be called again.
+The second call will make SSL_shutdown() wait for the peer's "close notify"
+shutdown alert. On success, the second call to SSL_shutdown() will return
+with 1.
+
+=item If the peer already sent the "close notify" alert B<and> it was
+already processed implicitly inside another function
+(L<SSL_read(3)|SSL_read(3)>), the SSL_RECEIVED_SHUTDOWN flag is set.
+SSL_shutdown() will send the "close notify" alert, set the SSL_SENT_SHUTDOWN
+flag and will immediately return with 1.
+Whether SSL_RECEIVED_SHUTDOWN is already set can be checked using the
+SSL_get_shutdown() (see also L<SSL_set_shutdown(3)|SSL_set_shutdown(3)> call.
+
+=back
+
+It is therefore recommended, to check the return value of SSL_shutdown()
+and call SSL_shutdown() again, if the bidirectional shutdown is not yet
+complete (return value of the first call is 0). As the shutdown is not
+specially handled in the SSLv2 protocol, SSL_shutdown() will succeed on
+the first call.
+
+The behaviour of SSL_shutdown() additionally depends on the underlying BIO. 
+
+If the underlying BIO is B<blocking>, SSL_shutdown() will only return once the
+handshake step has been finished or an error occurred.
+
+If the underlying BIO is B<non-blocking>, SSL_shutdown() will also return
+when the underlying BIO could not satisfy the needs of SSL_shutdown()
+to continue the handshake. In this case a call to SSL_get_error() with the
+return value of SSL_shutdown() will yield B<SSL_ERROR_WANT_READ> or
+B<SSL_ERROR_WANT_WRITE>. The calling process then must repeat the call after
+taking appropriate action to satisfy the needs of SSL_shutdown().
+The action depends on the underlying BIO. When using a non-blocking socket,
+nothing is to be done, but select() can be used to check for the required
+condition. When using a buffering BIO, like a BIO pair, data must be written
+into or retrieved out of the BIO before being able to continue.
+
+SSL_shutdown() can be modified to only set the connection to "shutdown"
+state but not actually send the "close notify" alert messages,
+see L<SSL_CTX_set_quiet_shutdown(3)|SSL_CTX_set_quiet_shutdown(3)>.
+When "quiet shutdown" is enabled, SSL_shutdown() will always succeed
+and return 1.
+
+=head1 RETURN VALUES
+
+The following return values can occur:
+
+=over 4
+
+=item 1
+
+The shutdown was successfully completed. The "close notify" alert was sent
+and the peer's "close notify" alert was received.
+
+=item 0
+
+The shutdown is not yet finished. Call SSL_shutdown() for a second time,
+if a bidirectional shutdown shall be performed.
+The output of L<SSL_get_error(3)|SSL_get_error(3)> may be misleading, as an
+erroneous SSL_ERROR_SYSCALL may be flagged even though no error occurred.
+
+=item -1
+
+The shutdown was not successful because a fatal error occurred either
+at the protocol level or a connection failure occurred. It can also occur if
+action is need to continue the operation for non-blocking BIOs.
+Call L<SSL_get_error(3)|SSL_get_error(3)> with the return value B<ret>
+to find out the reason.
+
+=back
+
+=head1 SEE ALSO
+
+L<SSL_get_error(3)|SSL_get_error(3)>, L<SSL_connect(3)|SSL_connect(3)>,
+L<SSL_accept(3)|SSL_accept(3)>, L<SSL_set_shutdown(3)|SSL_set_shutdown(3)>,
+L<SSL_CTX_set_quiet_shutdown(3)|SSL_CTX_set_quiet_shutdown(3)>,
+L<SSL_clear(3)|SSL_clear(3)>, L<SSL_free(3)|SSL_free(3)>,
+L<ssl(3)|ssl(3)>, L<bio(3)|bio(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_state_string.pod b/deps/openssl/openssl/doc/ssl/SSL_state_string.pod
new file mode 100644 (file)
index 0000000..fe25d47
--- /dev/null
@@ -0,0 +1,45 @@
+=pod
+
+=head1 NAME
+
+SSL_state_string, SSL_state_string_long - get textual description of state of an SSL object
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ const char *SSL_state_string(const SSL *ssl);
+ const char *SSL_state_string_long(const SSL *ssl);
+
+=head1 DESCRIPTION
+
+SSL_state_string() returns a 6 letter string indicating the current state
+of the SSL object B<ssl>.
+
+SSL_state_string_long() returns a string indicating the current state of
+the SSL object B<ssl>.
+
+=head1 NOTES
+
+During its use, an SSL objects passes several states. The state is internally
+maintained. Querying the state information is not very informative before
+or when a connection has been established. It however can be of significant
+interest during the handshake.
+
+When using non-blocking sockets, the function call performing the handshake
+may return with SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE condition,
+so that SSL_state_string[_long]() may be called.
+
+For both blocking or non-blocking sockets, the details state information
+can be used within the info_callback function set with the
+SSL_set_info_callback() call.
+
+=head1 RETURN VALUES
+
+Detailed description of possible states to be included later.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_CTX_set_info_callback(3)|SSL_CTX_set_info_callback(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_want.pod b/deps/openssl/openssl/doc/ssl/SSL_want.pod
new file mode 100644 (file)
index 0000000..c0059c0
--- /dev/null
@@ -0,0 +1,77 @@
+=pod
+
+=head1 NAME
+
+SSL_want, SSL_want_nothing, SSL_want_read, SSL_want_write, SSL_want_x509_lookup - obtain state information TLS/SSL I/O operation
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_want(const SSL *ssl);
+ int SSL_want_nothing(const SSL *ssl);
+ int SSL_want_read(const SSL *ssl);
+ int SSL_want_write(const SSL *ssl);
+ int SSL_want_x509_lookup(const SSL *ssl);
+
+=head1 DESCRIPTION
+
+SSL_want() returns state information for the SSL object B<ssl>.
+
+The other SSL_want_*() calls are shortcuts for the possible states returned
+by SSL_want().
+
+=head1 NOTES
+
+SSL_want() examines the internal state information of the SSL object. Its
+return values are similar to that of L<SSL_get_error(3)|SSL_get_error(3)>.
+Unlike L<SSL_get_error(3)|SSL_get_error(3)>, which also evaluates the
+error queue, the results are obtained by examining an internal state flag
+only. The information must therefore only be used for normal operation under
+non-blocking I/O. Error conditions are not handled and must be treated
+using L<SSL_get_error(3)|SSL_get_error(3)>.
+
+The result returned by SSL_want() should always be consistent with
+the result of L<SSL_get_error(3)|SSL_get_error(3)>.
+
+=head1 RETURN VALUES
+
+The following return values can currently occur for SSL_want():
+
+=over 4
+
+=item SSL_NOTHING
+
+There is no data to be written or to be read.
+
+=item SSL_WRITING
+
+There are data in the SSL buffer that must be written to the underlying
+B<BIO> layer in order to complete the actual SSL_*() operation.
+A call to L<SSL_get_error(3)|SSL_get_error(3)> should return
+SSL_ERROR_WANT_WRITE.
+
+=item SSL_READING
+
+More data must be read from the underlying B<BIO> layer in order to
+complete the actual SSL_*() operation.
+A call to L<SSL_get_error(3)|SSL_get_error(3)> should return
+SSL_ERROR_WANT_READ.
+
+=item SSL_X509_LOOKUP
+
+The operation did not complete because an application callback set by
+SSL_CTX_set_client_cert_cb() has asked to be called again.
+A call to L<SSL_get_error(3)|SSL_get_error(3)> should return
+SSL_ERROR_WANT_X509_LOOKUP.
+
+=back
+
+SSL_want_nothing(), SSL_want_read(), SSL_want_write(), SSL_want_x509_lookup()
+return 1, when the corresponding condition is true or 0 otherwise.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<err(3)|err(3)>, L<SSL_get_error(3)|SSL_get_error(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/SSL_write.pod b/deps/openssl/openssl/doc/ssl/SSL_write.pod
new file mode 100644 (file)
index 0000000..e013c12
--- /dev/null
@@ -0,0 +1,109 @@
+=pod
+
+=head1 NAME
+
+SSL_write - write bytes to a TLS/SSL connection.
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ int SSL_write(SSL *ssl, const void *buf, int num);
+
+=head1 DESCRIPTION
+
+SSL_write() writes B<num> bytes from the buffer B<buf> into the specified
+B<ssl> connection.
+
+=head1 NOTES
+
+If necessary, SSL_write() will negotiate a TLS/SSL session, if
+not already explicitly performed by L<SSL_connect(3)|SSL_connect(3)> or
+L<SSL_accept(3)|SSL_accept(3)>. If the
+peer requests a re-negotiation, it will be performed transparently during
+the SSL_write() operation. The behaviour of SSL_write() depends on the
+underlying BIO. 
+
+For the transparent negotiation to succeed, the B<ssl> must have been
+initialized to client or server mode. This is being done by calling
+L<SSL_set_connect_state(3)|SSL_set_connect_state(3)> or SSL_set_accept_state()
+before the first call to an L<SSL_read(3)|SSL_read(3)> or SSL_write() function.
+
+If the underlying BIO is B<blocking>, SSL_write() will only return, once the
+write operation has been finished or an error occurred, except when a
+renegotiation take place, in which case a SSL_ERROR_WANT_READ may occur. 
+This behaviour can be controlled with the SSL_MODE_AUTO_RETRY flag of the
+L<SSL_CTX_set_mode(3)|SSL_CTX_set_mode(3)> call.
+
+If the underlying BIO is B<non-blocking>, SSL_write() will also return,
+when the underlying BIO could not satisfy the needs of SSL_write()
+to continue the operation. In this case a call to
+L<SSL_get_error(3)|SSL_get_error(3)> with the
+return value of SSL_write() will yield B<SSL_ERROR_WANT_READ> or
+B<SSL_ERROR_WANT_WRITE>. As at any time a re-negotiation is possible, a
+call to SSL_write() can also cause read operations! The calling process
+then must repeat the call after taking appropriate action to satisfy the
+needs of SSL_write(). The action depends on the underlying BIO. When using a
+non-blocking socket, nothing is to be done, but select() can be used to check
+for the required condition. When using a buffering BIO, like a BIO pair, data
+must be written into or retrieved out of the BIO before being able to continue.
+
+SSL_write() will only return with success, when the complete contents
+of B<buf> of length B<num> has been written. This default behaviour
+can be changed with the SSL_MODE_ENABLE_PARTIAL_WRITE option of
+L<SSL_CTX_set_mode(3)|SSL_CTX_set_mode(3)>. When this flag is set,
+SSL_write() will also return with success, when a partial write has been
+successfully completed. In this case the SSL_write() operation is considered
+completed. The bytes are sent and a new SSL_write() operation with a new
+buffer (with the already sent bytes removed) must be started.
+A partial write is performed with the size of a message block, which is
+16kB for SSLv3/TLSv1.
+
+=head1 WARNING
+
+When an SSL_write() operation has to be repeated because of
+B<SSL_ERROR_WANT_READ> or B<SSL_ERROR_WANT_WRITE>, it must be repeated
+with the same arguments.
+
+When calling SSL_write() with num=0 bytes to be sent the behaviour is
+undefined.
+
+=head1 RETURN VALUES
+
+The following return values can occur:
+
+=over 4
+
+=item E<gt>0
+
+The write operation was successful, the return value is the number of
+bytes actually written to the TLS/SSL connection.
+
+=item 0
+
+The write operation was not successful. Probably the underlying connection
+was closed. Call SSL_get_error() with the return value B<ret> to find out,
+whether an error occurred or the connection was shut down cleanly
+(SSL_ERROR_ZERO_RETURN).
+
+SSLv2 (deprecated) does not support a shutdown alert protocol, so it can
+only be detected, whether the underlying connection was closed. It cannot
+be checked, why the closure happened.
+
+=item E<lt>0
+
+The write operation was not successful, because either an error occurred
+or action must be taken by the calling process. Call SSL_get_error() with the
+return value B<ret> to find out the reason.
+
+=back
+
+=head1 SEE ALSO
+
+L<SSL_get_error(3)|SSL_get_error(3)>, L<SSL_read(3)|SSL_read(3)>,
+L<SSL_CTX_set_mode(3)|SSL_CTX_set_mode(3)>, L<SSL_CTX_new(3)|SSL_CTX_new(3)>,
+L<SSL_connect(3)|SSL_connect(3)>, L<SSL_accept(3)|SSL_accept(3)>
+L<SSL_set_connect_state(3)|SSL_set_connect_state(3)>,
+L<ssl(3)|ssl(3)>, L<bio(3)|bio(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/d2i_SSL_SESSION.pod b/deps/openssl/openssl/doc/ssl/d2i_SSL_SESSION.pod
new file mode 100644 (file)
index 0000000..81d2764
--- /dev/null
@@ -0,0 +1,66 @@
+=pod
+
+=head1 NAME
+
+d2i_SSL_SESSION, i2d_SSL_SESSION - convert SSL_SESSION object from/to ASN1 representation
+
+=head1 SYNOPSIS
+
+ #include <openssl/ssl.h>
+
+ SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp, long length);
+ int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp);
+
+=head1 DESCRIPTION
+
+d2i_SSL_SESSION() transforms the external ASN1 representation of an SSL/TLS
+session, stored as binary data at location B<pp> with length B<length>, into
+an SSL_SESSION object.
+
+i2d_SSL_SESSION() transforms the SSL_SESSION object B<in> into the ASN1
+representation and stores it into the memory location pointed to by B<pp>.
+The length of the resulting ASN1 representation is returned. If B<pp> is
+the NULL pointer, only the length is calculated and returned.
+
+=head1 NOTES
+
+The SSL_SESSION object is built from several malloc()ed parts, it can
+therefore not be moved, copied or stored directly. In order to store
+session data on disk or into a database, it must be transformed into
+a binary ASN1 representation.
+
+When using d2i_SSL_SESSION(), the SSL_SESSION object is automatically
+allocated. The reference count is 1, so that the session must be
+explicitly removed using L<SSL_SESSION_free(3)|SSL_SESSION_free(3)>,
+unless the SSL_SESSION object is completely taken over, when being called
+inside the get_session_cb() (see
+L<SSL_CTX_sess_set_get_cb(3)|SSL_CTX_sess_set_get_cb(3)>).
+
+SSL_SESSION objects keep internal link information about the session cache
+list, when being inserted into one SSL_CTX object's session cache.
+One SSL_SESSION object, regardless of its reference count, must therefore
+only be used with one SSL_CTX object (and the SSL objects created
+from this SSL_CTX object).
+
+When using i2d_SSL_SESSION(), the memory location pointed to by B<pp> must be
+large enough to hold the binary representation of the session. There is no
+known limit on the size of the created ASN1 representation, so the necessary
+amount of space should be obtained by first calling i2d_SSL_SESSION() with
+B<pp=NULL>, and obtain the size needed, then allocate the memory and
+call i2d_SSL_SESSION() again.
+
+=head1 RETURN VALUES
+
+d2i_SSL_SESSION() returns a pointer to the newly allocated SSL_SESSION
+object. In case of failure the NULL-pointer is returned and the error message
+can be retrieved from the error stack.
+
+i2d_SSL_SESSION() returns the size of the ASN1 representation in bytes.
+When the session is not valid, B<0> is returned and no operation is performed.
+
+=head1 SEE ALSO
+
+L<ssl(3)|ssl(3)>, L<SSL_SESSION_free(3)|SSL_SESSION_free(3)>,
+L<SSL_CTX_sess_set_get_cb(3)|SSL_CTX_sess_set_get_cb(3)>
+
+=cut
diff --git a/deps/openssl/openssl/doc/ssl/ssl.pod b/deps/openssl/openssl/doc/ssl/ssl.pod
new file mode 100644 (file)
index 0000000..6d3ee24
--- /dev/null
@@ -0,0 +1,758 @@
+
+=pod
+
+=head1 NAME
+
+SSL - OpenSSL SSL/TLS library
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+The OpenSSL B<ssl> library implements the Secure Sockets Layer (SSL v2/v3) and
+Transport Layer Security (TLS v1) protocols. It provides a rich API which is
+documented here.
+
+At first the library must be initialized; see
+L<SSL_library_init(3)|SSL_library_init(3)>.
+
+Then an B<SSL_CTX> object is created as a framework to establish
+TLS/SSL enabled connections (see L<SSL_CTX_new(3)|SSL_CTX_new(3)>).
+Various options regarding certificates, algorithms etc. can be set
+in this object.
+
+When a network connection has been created, it can be assigned to an
+B<SSL> object. After the B<SSL> object has been created using
+L<SSL_new(3)|SSL_new(3)>, L<SSL_set_fd(3)|SSL_set_fd(3)> or
+L<SSL_set_bio(3)|SSL_set_bio(3)> can be used to associate the network
+connection with the object.
+
+Then the TLS/SSL handshake is performed using
+L<SSL_accept(3)|SSL_accept(3)> or L<SSL_connect(3)|SSL_connect(3)>
+respectively.
+L<SSL_read(3)|SSL_read(3)> and L<SSL_write(3)|SSL_write(3)> are used
+to read and write data on the TLS/SSL connection.
+L<SSL_shutdown(3)|SSL_shutdown(3)> can be used to shut down the
+TLS/SSL connection.
+
+=head1 DATA STRUCTURES
+
+Currently the OpenSSL B<ssl> library functions deals with the following data
+structures:
+
+=over 4
+
+=item B<SSL_METHOD> (SSL Method)
+
+That's a dispatch structure describing the internal B<ssl> library
+methods/functions which implement the various protocol versions (SSLv1, SSLv2
+and TLSv1). It's needed to create an B<SSL_CTX>.
+
+=item B<SSL_CIPHER> (SSL Cipher)
+
+This structure holds the algorithm information for a particular cipher which
+are a core part of the SSL/TLS protocol. The available ciphers are configured
+on a B<SSL_CTX> basis and the actually used ones are then part of the
+B<SSL_SESSION>.
+
+=item B<SSL_CTX> (SSL Context)
+
+That's the global context structure which is created by a server or client
+once per program life-time and which holds mainly default values for the
+B<SSL> structures which are later created for the connections.
+
+=item B<SSL_SESSION> (SSL Session)
+
+This is a structure containing the current TLS/SSL session details for a
+connection: B<SSL_CIPHER>s, client and server certificates, keys, etc.
+
+=item B<SSL> (SSL Connection)
+
+That's the main SSL/TLS structure which is created by a server or client per
+established connection. This actually is the core structure in the SSL API.
+Under run-time the application usually deals with this structure which has
+links to mostly all other structures.
+
+=back
+
+
+=head1 HEADER FILES
+
+Currently the OpenSSL B<ssl> library provides the following C header files
+containing the prototypes for the data structures and and functions:
+
+=over 4
+
+=item B<ssl.h>
+
+That's the common header file for the SSL/TLS API.  Include it into your
+program to make the API of the B<ssl> library available. It internally
+includes both more private SSL headers and headers from the B<crypto> library.
+Whenever you need hard-core details on the internals of the SSL API, look
+inside this header file.
+
+=item B<ssl2.h>
+
+That's the sub header file dealing with the SSLv2 protocol only.
+I<Usually you don't have to include it explicitly because
+it's already included by ssl.h>.
+
+=item B<ssl3.h>
+
+That's the sub header file dealing with the SSLv3 protocol only.
+I<Usually you don't have to include it explicitly because
+it's already included by ssl.h>.
+
+=item B<ssl23.h>
+
+That's the sub header file dealing with the combined use of the SSLv2 and
+SSLv3 protocols.
+I<Usually you don't have to include it explicitly because
+it's already included by ssl.h>.
+
+=item B<tls1.h>
+
+That's the sub header file dealing with the TLSv1 protocol only.
+I<Usually you don't have to include it explicitly because
+it's already included by ssl.h>.
+
+=back
+
+=head1 API FUNCTIONS
+
+Currently the OpenSSL B<ssl> library exports 214 API functions.
+They are documented in the following:
+
+=head2 DEALING WITH PROTOCOL METHODS
+
+Here we document the various API functions which deal with the SSL/TLS
+protocol methods defined in B<SSL_METHOD> structures.
+
+=over 4
+
+=item const SSL_METHOD *B<SSLv2_client_method>(void);
+
+Constructor for the SSLv2 SSL_METHOD structure for a dedicated client.
+
+=item const SSL_METHOD *B<SSLv2_server_method>(void);
+
+Constructor for the SSLv2 SSL_METHOD structure for a dedicated server.
+
+=item const SSL_METHOD *B<SSLv2_method>(void);
+
+Constructor for the SSLv2 SSL_METHOD structure for combined client and server.
+
+=item const SSL_METHOD *B<SSLv3_client_method>(void);
+
+Constructor for the SSLv3 SSL_METHOD structure for a dedicated client.
+
+=item const SSL_METHOD *B<SSLv3_server_method>(void);
+
+Constructor for the SSLv3 SSL_METHOD structure for a dedicated server.
+
+=item const SSL_METHOD *B<SSLv3_method>(void);
+
+Constructor for the SSLv3 SSL_METHOD structure for combined client and server.
+
+=item const SSL_METHOD *B<TLSv1_client_method>(void);
+
+Constructor for the TLSv1 SSL_METHOD structure for a dedicated client.
+
+=item const SSL_METHOD *B<TLSv1_server_method>(void);
+
+Constructor for the TLSv1 SSL_METHOD structure for a dedicated server.
+
+=item const SSL_METHOD *B<TLSv1_method>(void);
+
+Constructor for the TLSv1 SSL_METHOD structure for combined client and server.
+
+=back
+
+=head2 DEALING WITH CIPHERS
+
+Here we document the various API functions which deal with the SSL/TLS
+ciphers defined in B<SSL_CIPHER> structures.
+
+=over 4
+
+=item char *B<SSL_CIPHER_description>(SSL_CIPHER *cipher, char *buf, int len);
+
+Write a string to I<buf> (with a maximum size of I<len>) containing a human
+readable description of I<cipher>. Returns I<buf>.
+
+=item int B<SSL_CIPHER_get_bits>(SSL_CIPHER *cipher, int *alg_bits);
+
+Determine the number of bits in I<cipher>. Because of export crippled ciphers
+there are two bits: The bits the algorithm supports in general (stored to
+I<alg_bits>) and the bits which are actually used (the return value).
+
+=item const char *B<SSL_CIPHER_get_name>(SSL_CIPHER *cipher);
+
+Return the internal name of I<cipher> as a string. These are the various
+strings defined by the I<SSL2_TXT_xxx>, I<SSL3_TXT_xxx> and I<TLS1_TXT_xxx>
+definitions in the header files.
+
+=item char *B<SSL_CIPHER_get_version>(SSL_CIPHER *cipher);
+
+Returns a string like "C<TLSv1/SSLv3>" or "C<SSLv2>" which indicates the
+SSL/TLS protocol version to which I<cipher> belongs (i.e. where it was defined
+in the specification the first time).
+
+=back
+
+=head2 DEALING WITH PROTOCOL CONTEXTS
+
+Here we document the various API functions which deal with the SSL/TLS
+protocol context defined in the B<SSL_CTX> structure.
+
+=over 4
+
+=item int B<SSL_CTX_add_client_CA>(SSL_CTX *ctx, X509 *x);
+
+=item long B<SSL_CTX_add_extra_chain_cert>(SSL_CTX *ctx, X509 *x509);
+
+=item int B<SSL_CTX_add_session>(SSL_CTX *ctx, SSL_SESSION *c);
+
+=item int B<SSL_CTX_check_private_key>(const SSL_CTX *ctx);
+
+=item long B<SSL_CTX_ctrl>(SSL_CTX *ctx, int cmd, long larg, char *parg);
+
+=item void B<SSL_CTX_flush_sessions>(SSL_CTX *s, long t);
+
+=item void B<SSL_CTX_free>(SSL_CTX *a);
+
+=item char *B<SSL_CTX_get_app_data>(SSL_CTX *ctx);
+
+=item X509_STORE *B<SSL_CTX_get_cert_store>(SSL_CTX *ctx);
+
+=item STACK *B<SSL_CTX_get_client_CA_list>(const SSL_CTX *ctx);
+
+=item int (*B<SSL_CTX_get_client_cert_cb>(SSL_CTX *ctx))(SSL *ssl, X509 **x509, EVP_PKEY **pkey);
+
+=item char *B<SSL_CTX_get_ex_data>(const SSL_CTX *s, int idx);
+
+=item int B<SSL_CTX_get_ex_new_index>(long argl, char *argp, int (*new_func);(void), int (*dup_func)(void), void (*free_func)(void))
+
+=item void (*B<SSL_CTX_get_info_callback>(SSL_CTX *ctx))(SSL *ssl, int cb, int ret);
+
+=item int B<SSL_CTX_get_quiet_shutdown>(const SSL_CTX *ctx);
+
+=item int B<SSL_CTX_get_session_cache_mode>(SSL_CTX *ctx);
+
+=item long B<SSL_CTX_get_timeout>(const SSL_CTX *ctx);
+
+=item int (*B<SSL_CTX_get_verify_callback>(const SSL_CTX *ctx))(int ok, X509_STORE_CTX *ctx);
+
+=item int B<SSL_CTX_get_verify_mode>(SSL_CTX *ctx);
+
+=item int B<SSL_CTX_load_verify_locations>(SSL_CTX *ctx, char *CAfile, char *CApath);
+
+=item long B<SSL_CTX_need_tmp_RSA>(SSL_CTX *ctx);
+
+=item SSL_CTX *B<SSL_CTX_new>(const SSL_METHOD *meth);
+
+=item int B<SSL_CTX_remove_session>(SSL_CTX *ctx, SSL_SESSION *c);
+
+=item int B<SSL_CTX_sess_accept>(SSL_CTX *ctx);
+
+=item int B<SSL_CTX_sess_accept_good>(SSL_CTX *ctx);
+
+=item int B<SSL_CTX_sess_accept_renegotiate>(SSL_CTX *ctx);
+
+=item int B<SSL_CTX_sess_cache_full>(SSL_CTX *ctx);
+
+=item int B<SSL_CTX_sess_cb_hits>(SSL_CTX *ctx);
+
+=item int B<SSL_CTX_sess_connect>(SSL_CTX *ctx);
+
+=item int B<SSL_CTX_sess_connect_good>(SSL_CTX *ctx);
+
+=item int B<SSL_CTX_sess_connect_renegotiate>(SSL_CTX *ctx);
+
+=item int B<SSL_CTX_sess_get_cache_size>(SSL_CTX *ctx);
+
+=item SSL_SESSION *(*B<SSL_CTX_sess_get_get_cb>(SSL_CTX *ctx))(SSL *ssl, unsigned char *data, int len, int *copy);
+
+=item int (*B<SSL_CTX_sess_get_new_cb>(SSL_CTX *ctx)(SSL *ssl, SSL_SESSION *sess);
+
+=item void (*B<SSL_CTX_sess_get_remove_cb>(SSL_CTX *ctx)(SSL_CTX *ctx, SSL_SESSION *sess);
+
+=item int B<SSL_CTX_sess_hits>(SSL_CTX *ctx);
+
+=item int B<SSL_CTX_sess_misses>(SSL_CTX *ctx);
+
+=item int B<SSL_CTX_sess_number>(SSL_CTX *ctx);
+
+=item void B<SSL_CTX_sess_set_cache_size>(SSL_CTX *ctx,t);
+
+=item void B<SSL_CTX_sess_set_get_cb>(SSL_CTX *ctx, SSL_SESSION *(*cb)(SSL *ssl, unsigned char *data, int len, int *copy));
+
+=item void B<SSL_CTX_sess_set_new_cb>(SSL_CTX *ctx, int (*cb)(SSL *ssl, SSL_SESSION *sess));
+
+=item void B<SSL_CTX_sess_set_remove_cb>(SSL_CTX *ctx, void (*cb)(SSL_CTX *ctx, SSL_SESSION *sess));
+
+=item int B<SSL_CTX_sess_timeouts>(SSL_CTX *ctx);
+
+=item LHASH *B<SSL_CTX_sessions>(SSL_CTX *ctx);
+
+=item void B<SSL_CTX_set_app_data>(SSL_CTX *ctx, void *arg);
+
+=item void B<SSL_CTX_set_cert_store>(SSL_CTX *ctx, X509_STORE *cs);
+
+=item void B<SSL_CTX_set_cert_verify_cb>(SSL_CTX *ctx, int (*cb)(), char *arg)
+
+=item int B<SSL_CTX_set_cipher_list>(SSL_CTX *ctx, char *str);
+
+=item void B<SSL_CTX_set_client_CA_list>(SSL_CTX *ctx, STACK *list);
+
+=item void B<SSL_CTX_set_client_cert_cb>(SSL_CTX *ctx, int (*cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey));
+
+=item void B<SSL_CTX_set_default_passwd_cb>(SSL_CTX *ctx, int (*cb);(void))
+
+=item void B<SSL_CTX_set_default_read_ahead>(SSL_CTX *ctx, int m);
+
+=item int B<SSL_CTX_set_default_verify_paths>(SSL_CTX *ctx);
+
+=item int B<SSL_CTX_set_ex_data>(SSL_CTX *s, int idx, char *arg);
+
+=item void B<SSL_CTX_set_info_callback>(SSL_CTX *ctx, void (*cb)(SSL *ssl, int cb, int ret));
+
+=item void B<SSL_CTX_set_msg_callback>(SSL_CTX *ctx, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg));
+
+=item void B<SSL_CTX_set_msg_callback_arg>(SSL_CTX *ctx, void *arg);
+
+=item void B<SSL_CTX_set_options>(SSL_CTX *ctx, unsigned long op);
+
+=item void B<SSL_CTX_set_quiet_shutdown>(SSL_CTX *ctx, int mode);
+
+=item void B<SSL_CTX_set_session_cache_mode>(SSL_CTX *ctx, int mode);
+
+=item int B<SSL_CTX_set_ssl_version>(SSL_CTX *ctx, const SSL_METHOD *meth);
+
+=item void B<SSL_CTX_set_timeout>(SSL_CTX *ctx, long t);
+
+=item long B<SSL_CTX_set_tmp_dh>(SSL_CTX* ctx, DH *dh);
+
+=item long B<SSL_CTX_set_tmp_dh_callback>(SSL_CTX *ctx, DH *(*cb)(void));
+
+=item long B<SSL_CTX_set_tmp_rsa>(SSL_CTX *ctx, RSA *rsa);
+
+=item SSL_CTX_set_tmp_rsa_callback
+
+C<long B<SSL_CTX_set_tmp_rsa_callback>(SSL_CTX *B<ctx>, RSA *(*B<cb>)(SSL *B<ssl>, int B<export>, int B<keylength>));>
+
+Sets the callback which will be called when a temporary private key is
+required. The B<C<export>> flag will be set if the reason for needing
+a temp key is that an export ciphersuite is in use, in which case,
+B<C<keylength>> will contain the required keylength in bits. Generate a key of
+appropriate size (using ???) and return it.
+
+=item SSL_set_tmp_rsa_callback
+
+long B<SSL_set_tmp_rsa_callback>(SSL *ssl, RSA *(*cb)(SSL *ssl, int export, int keylength));
+
+The same as B<SSL_CTX_set_tmp_rsa_callback>, except it operates on an SSL
+session instead of a context.
+
+=item void B<SSL_CTX_set_verify>(SSL_CTX *ctx, int mode, int (*cb);(void))
+
+=item int B<SSL_CTX_use_PrivateKey>(SSL_CTX *ctx, EVP_PKEY *pkey);
+
+=item int B<SSL_CTX_use_PrivateKey_ASN1>(int type, SSL_CTX *ctx, unsigned char *d, long len);
+
+=item int B<SSL_CTX_use_PrivateKey_file>(SSL_CTX *ctx, char *file, int type);
+
+=item int B<SSL_CTX_use_RSAPrivateKey>(SSL_CTX *ctx, RSA *rsa);
+
+=item int B<SSL_CTX_use_RSAPrivateKey_ASN1>(SSL_CTX *ctx, unsigned char *d, long len);
+
+=item int B<SSL_CTX_use_RSAPrivateKey_file>(SSL_CTX *ctx, char *file, int type);
+
+=item int B<SSL_CTX_use_certificate>(SSL_CTX *ctx, X509 *x);
+
+=item int B<SSL_CTX_use_certificate_ASN1>(SSL_CTX *ctx, int len, unsigned char *d);
+
+=item int B<SSL_CTX_use_certificate_file>(SSL_CTX *ctx, char *file, int type);
+
+=item void B<SSL_CTX_set_psk_client_callback>(SSL_CTX *ctx, unsigned int (*callback)(SSL *ssl, const char *hint, char *identity, unsigned int max_identity_len, unsigned char *psk, unsigned int max_psk_len));
+
+=item int B<SSL_CTX_use_psk_identity_hint>(SSL_CTX *ctx, const char *hint);
+
+=item void B<SSL_CTX_set_psk_server_callback>(SSL_CTX *ctx, unsigned int (*callback)(SSL *ssl, const char *identity, unsigned char *psk, int max_psk_len));
+
+
+
+
+=back
+
+=head2 DEALING WITH SESSIONS
+
+Here we document the various API functions which deal with the SSL/TLS
+sessions defined in the B<SSL_SESSION> structures.
+
+=over 4
+
+=item int B<SSL_SESSION_cmp>(const SSL_SESSION *a, const SSL_SESSION *b);
+
+=item void B<SSL_SESSION_free>(SSL_SESSION *ss);
+
+=item char *B<SSL_SESSION_get_app_data>(SSL_SESSION *s);
+
+=item char *B<SSL_SESSION_get_ex_data>(const SSL_SESSION *s, int idx);
+
+=item int B<SSL_SESSION_get_ex_new_index>(long argl, char *argp, int (*new_func);(void), int (*dup_func)(void), void (*free_func)(void))
+
+=item long B<SSL_SESSION_get_time>(const SSL_SESSION *s);
+
+=item long B<SSL_SESSION_get_timeout>(const SSL_SESSION *s);
+
+=item unsigned long B<SSL_SESSION_hash>(const SSL_SESSION *a);
+
+=item SSL_SESSION *B<SSL_SESSION_new>(void);
+
+=item int B<SSL_SESSION_print>(BIO *bp, const SSL_SESSION *x);
+
+=item int B<SSL_SESSION_print_fp>(FILE *fp, const SSL_SESSION *x);
+
+=item void B<SSL_SESSION_set_app_data>(SSL_SESSION *s, char *a);
+
+=item int B<SSL_SESSION_set_ex_data>(SSL_SESSION *s, int idx, char *arg);
+
+=item long B<SSL_SESSION_set_time>(SSL_SESSION *s, long t);
+
+=item long B<SSL_SESSION_set_timeout>(SSL_SESSION *s, long t);
+
+=back
+
+=head2 DEALING WITH CONNECTIONS
+
+Here we document the various API functions which deal with the SSL/TLS
+connection defined in the B<SSL> structure.
+
+=over 4
+
+=item int B<SSL_accept>(SSL *ssl);
+
+=item int B<SSL_add_dir_cert_subjects_to_stack>(STACK *stack, const char *dir);
+
+=item int B<SSL_add_file_cert_subjects_to_stack>(STACK *stack, const char *file);
+
+=item int B<SSL_add_client_CA>(SSL *ssl, X509 *x);
+
+=item char *B<SSL_alert_desc_string>(int value);
+
+=item char *B<SSL_alert_desc_string_long>(int value);
+
+=item char *B<SSL_alert_type_string>(int value);
+
+=item char *B<SSL_alert_type_string_long>(int value);
+
+=item int B<SSL_check_private_key>(const SSL *ssl);
+
+=item void B<SSL_clear>(SSL *ssl);
+
+=item long B<SSL_clear_num_renegotiations>(SSL *ssl);
+
+=item int B<SSL_connect>(SSL *ssl);
+
+=item void B<SSL_copy_session_id>(SSL *t, const SSL *f);
+
+=item long B<SSL_ctrl>(SSL *ssl, int cmd, long larg, char *parg);
+
+=item int B<SSL_do_handshake>(SSL *ssl);
+
+=item SSL *B<SSL_dup>(SSL *ssl);
+
+=item STACK *B<SSL_dup_CA_list>(STACK *sk);
+
+=item void B<SSL_free>(SSL *ssl);
+
+=item SSL_CTX *B<SSL_get_SSL_CTX>(const SSL *ssl);
+
+=item char *B<SSL_get_app_data>(SSL *ssl);
+
+=item X509 *B<SSL_get_certificate>(const SSL *ssl);
+
+=item const char *B<SSL_get_cipher>(const SSL *ssl);
+
+=item int B<SSL_get_cipher_bits>(const SSL *ssl, int *alg_bits);
+
+=item char *B<SSL_get_cipher_list>(const SSL *ssl, int n);
+
+=item char *B<SSL_get_cipher_name>(const SSL *ssl);
+
+=item char *B<SSL_get_cipher_version>(const SSL *ssl);
+
+=item STACK *B<SSL_get_ciphers>(const SSL *ssl);
+
+=item STACK *B<SSL_get_client_CA_list>(const SSL *ssl);
+
+=item SSL_CIPHER *B<SSL_get_current_cipher>(SSL *ssl);
+
+=item long B<SSL_get_default_timeout>(const SSL *ssl);
+
+=item int B<SSL_get_error>(const SSL *ssl, int i);
+
+=item char *B<SSL_get_ex_data>(const SSL *ssl, int idx);
+
+=item int B<SSL_get_ex_data_X509_STORE_CTX_idx>(void);
+
+=item int B<SSL_get_ex_new_index>(long argl, char *argp, int (*new_func);(void), int (*dup_func)(void), void (*free_func)(void))
+
+=item int B<SSL_get_fd>(const SSL *ssl);
+
+=item void (*B<SSL_get_info_callback>(const SSL *ssl);)()
+
+=item STACK *B<SSL_get_peer_cert_chain>(const SSL *ssl);
+
+=item X509 *B<SSL_get_peer_certificate>(const SSL *ssl);
+
+=item EVP_PKEY *B<SSL_get_privatekey>(SSL *ssl);
+
+=item int B<SSL_get_quiet_shutdown>(const SSL *ssl);
+
+=item BIO *B<SSL_get_rbio>(const SSL *ssl);
+
+=item int B<SSL_get_read_ahead>(const SSL *ssl);
+
+=item SSL_SESSION *B<SSL_get_session>(const SSL *ssl);
+
+=item char *B<SSL_get_shared_ciphers>(const SSL *ssl, char *buf, int len);
+
+=item int B<SSL_get_shutdown>(const SSL *ssl);
+
+=item const SSL_METHOD *B<SSL_get_ssl_method>(SSL *ssl);
+
+=item int B<SSL_get_state>(const SSL *ssl);
+
+=item long B<SSL_get_time>(const SSL *ssl);
+
+=item long B<SSL_get_timeout>(const SSL *ssl);
+
+=item int (*B<SSL_get_verify_callback>(const SSL *ssl))(int,X509_STORE_CTX *)
+
+=item int B<SSL_get_verify_mode>(const SSL *ssl);
+
+=item long B<SSL_get_verify_result>(const SSL *ssl);
+
+=item char *B<SSL_get_version>(const SSL *ssl);
+
+=item BIO *B<SSL_get_wbio>(const SSL *ssl);
+
+=item int B<SSL_in_accept_init>(SSL *ssl);
+
+=item int B<SSL_in_before>(SSL *ssl);
+
+=item int B<SSL_in_connect_init>(SSL *ssl);
+
+=item int B<SSL_in_init>(SSL *ssl);
+
+=item int B<SSL_is_init_finished>(SSL *ssl);
+
+=item STACK *B<SSL_load_client_CA_file>(char *file);
+
+=item void B<SSL_load_error_strings>(void);
+
+=item SSL *B<SSL_new>(SSL_CTX *ctx);
+
+=item long B<SSL_num_renegotiations>(SSL *ssl);
+
+=item int B<SSL_peek>(SSL *ssl, void *buf, int num);
+
+=item int B<SSL_pending>(const SSL *ssl);
+
+=item int B<SSL_read>(SSL *ssl, void *buf, int num);
+
+=item int B<SSL_renegotiate>(SSL *ssl);
+
+=item char *B<SSL_rstate_string>(SSL *ssl);
+
+=item char *B<SSL_rstate_string_long>(SSL *ssl);
+
+=item long B<SSL_session_reused>(SSL *ssl);
+
+=item void B<SSL_set_accept_state>(SSL *ssl);
+
+=item void B<SSL_set_app_data>(SSL *ssl, char *arg);
+
+=item void B<SSL_set_bio>(SSL *ssl, BIO *rbio, BIO *wbio);
+
+=item int B<SSL_set_cipher_list>(SSL *ssl, char *str);
+
+=item void B<SSL_set_client_CA_list>(SSL *ssl, STACK *list);
+
+=item void B<SSL_set_connect_state>(SSL *ssl);
+
+=item int B<SSL_set_ex_data>(SSL *ssl, int idx, char *arg);
+
+=item int B<SSL_set_fd>(SSL *ssl, int fd);
+
+=item void B<SSL_set_info_callback>(SSL *ssl, void (*cb);(void))
+
+=item void B<SSL_set_msg_callback>(SSL *ctx, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg));
+
+=item void B<SSL_set_msg_callback_arg>(SSL *ctx, void *arg);
+
+=item void B<SSL_set_options>(SSL *ssl, unsigned long op);
+
+=item void B<SSL_set_quiet_shutdown>(SSL *ssl, int mode);
+
+=item void B<SSL_set_read_ahead>(SSL *ssl, int yes);
+
+=item int B<SSL_set_rfd>(SSL *ssl, int fd);
+
+=item int B<SSL_set_session>(SSL *ssl, SSL_SESSION *session);
+
+=item void B<SSL_set_shutdown>(SSL *ssl, int mode);
+
+=item int B<SSL_set_ssl_method>(SSL *ssl, const SSL_METHOD *meth);
+
+=item void B<SSL_set_time>(SSL *ssl, long t);
+
+=item void B<SSL_set_timeout>(SSL *ssl, long t);
+
+=item void B<SSL_set_verify>(SSL *ssl, int mode, int (*callback);(void))
+
+=item void B<SSL_set_verify_result>(SSL *ssl, long arg);
+
+=item int B<SSL_set_wfd>(SSL *ssl, int fd);
+
+=item int B<SSL_shutdown>(SSL *ssl);
+
+=item int B<SSL_state>(const SSL *ssl);
+
+=item char *B<SSL_state_string>(const SSL *ssl);
+
+=item char *B<SSL_state_string_long>(const SSL *ssl);
+
+=item long B<SSL_total_renegotiations>(SSL *ssl);
+
+=item int B<SSL_use_PrivateKey>(SSL *ssl, EVP_PKEY *pkey);
+
+=item int B<SSL_use_PrivateKey_ASN1>(int type, SSL *ssl, unsigned char *d, long len);
+
+=item int B<SSL_use_PrivateKey_file>(SSL *ssl, char *file, int type);
+
+=item int B<SSL_use_RSAPrivateKey>(SSL *ssl, RSA *rsa);
+
+=item int B<SSL_use_RSAPrivateKey_ASN1>(SSL *ssl, unsigned char *d, long len);
+
+=item int B<SSL_use_RSAPrivateKey_file>(SSL *ssl, char *file, int type);
+
+=item int B<SSL_use_certificate>(SSL *ssl, X509 *x);
+
+=item int B<SSL_use_certificate_ASN1>(SSL *ssl, int len, unsigned char *d);
+
+=item int B<SSL_use_certificate_file>(SSL *ssl, char *file, int type);
+
+=item int B<SSL_version>(const SSL *ssl);
+
+=item int B<SSL_want>(const SSL *ssl);
+
+=item int B<SSL_want_nothing>(const SSL *ssl);
+
+=item int B<SSL_want_read>(const SSL *ssl);
+
+=item int B<SSL_want_write>(const SSL *ssl);
+
+=item int B<SSL_want_x509_lookup>(const SSL *ssl);
+
+=item int B<SSL_write>(SSL *ssl, const void *buf, int num);
+
+=item void B<SSL_set_psk_client_callback>(SSL *ssl, unsigned int (*callback)(SSL *ssl, const char *hint, char *identity, unsigned int max_identity_len, unsigned char *psk, unsigned int max_psk_len));
+
+=item int B<SSL_use_psk_identity_hint>(SSL *ssl, const char *hint);
+
+=item void B<SSL_set_psk_server_callback>(SSL *ssl, unsigned int (*callback)(SSL *ssl, const char *identity, unsigned char *psk, int max_psk_len));
+
+=item const char *B<SSL_get_psk_identity_hint>(SSL *ssl);
+
+=item const char *B<SSL_get_psk_identity>(SSL *ssl);
+
+=back
+
+=head1 SEE ALSO
+
+L<openssl(1)|openssl(1)>, L<crypto(3)|crypto(3)>,
+L<SSL_accept(3)|SSL_accept(3)>, L<SSL_clear(3)|SSL_clear(3)>,
+L<SSL_connect(3)|SSL_connect(3)>,
+L<SSL_CIPHER_get_name(3)|SSL_CIPHER_get_name(3)>,
+L<SSL_COMP_add_compression_method(3)|SSL_COMP_add_compression_method(3)>,
+L<SSL_CTX_add_extra_chain_cert(3)|SSL_CTX_add_extra_chain_cert(3)>,
+L<SSL_CTX_add_session(3)|SSL_CTX_add_session(3)>,
+L<SSL_CTX_ctrl(3)|SSL_CTX_ctrl(3)>,
+L<SSL_CTX_flush_sessions(3)|SSL_CTX_flush_sessions(3)>,
+L<SSL_CTX_get_ex_new_index(3)|SSL_CTX_get_ex_new_index(3)>,
+L<SSL_CTX_get_verify_mode(3)|SSL_CTX_get_verify_mode(3)>,
+L<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>
+L<SSL_CTX_new(3)|SSL_CTX_new(3)>,
+L<SSL_CTX_sess_number(3)|SSL_CTX_sess_number(3)>,
+L<SSL_CTX_sess_set_cache_size(3)|SSL_CTX_sess_set_cache_size(3)>,
+L<SSL_CTX_sess_set_get_cb(3)|SSL_CTX_sess_set_get_cb(3)>,
+L<SSL_CTX_sessions(3)|SSL_CTX_sessions(3)>,
+L<SSL_CTX_set_cert_store(3)|SSL_CTX_set_cert_store(3)>,
+L<SSL_CTX_set_cert_verify_callback(3)|SSL_CTX_set_cert_verify_callback(3)>,
+L<SSL_CTX_set_cipher_list(3)|SSL_CTX_set_cipher_list(3)>,
+L<SSL_CTX_set_client_CA_list(3)|SSL_CTX_set_client_CA_list(3)>,
+L<SSL_CTX_set_client_cert_cb(3)|SSL_CTX_set_client_cert_cb(3)>,
+L<SSL_CTX_set_default_passwd_cb(3)|SSL_CTX_set_default_passwd_cb(3)>,
+L<SSL_CTX_set_generate_session_id(3)|SSL_CTX_set_generate_session_id(3)>,
+L<SSL_CTX_set_info_callback(3)|SSL_CTX_set_info_callback(3)>,
+L<SSL_CTX_set_max_cert_list(3)|SSL_CTX_set_max_cert_list(3)>,
+L<SSL_CTX_set_mode(3)|SSL_CTX_set_mode(3)>,
+L<SSL_CTX_set_msg_callback(3)|SSL_CTX_set_msg_callback(3)>,
+L<SSL_CTX_set_options(3)|SSL_CTX_set_options(3)>,
+L<SSL_CTX_set_quiet_shutdown(3)|SSL_CTX_set_quiet_shutdown(3)>,
+L<SSL_CTX_set_session_cache_mode(3)|SSL_CTX_set_session_cache_mode(3)>,
+L<SSL_CTX_set_session_id_context(3)|SSL_CTX_set_session_id_context(3)>,
+L<SSL_CTX_set_ssl_version(3)|SSL_CTX_set_ssl_version(3)>,
+L<SSL_CTX_set_timeout(3)|SSL_CTX_set_timeout(3)>,
+L<SSL_CTX_set_tmp_rsa_callback(3)|SSL_CTX_set_tmp_rsa_callback(3)>,
+L<SSL_CTX_set_tmp_dh_callback(3)|SSL_CTX_set_tmp_dh_callback(3)>,
+L<SSL_CTX_set_verify(3)|SSL_CTX_set_verify(3)>,
+L<SSL_CTX_use_certificate(3)|SSL_CTX_use_certificate(3)>,
+L<SSL_alert_type_string(3)|SSL_alert_type_string(3)>,
+L<SSL_do_handshake(3)|SSL_do_handshake(3)>,
+L<SSL_get_SSL_CTX(3)|SSL_get_SSL_CTX(3)>,
+L<SSL_get_ciphers(3)|SSL_get_ciphers(3)>,
+L<SSL_get_client_CA_list(3)|SSL_get_client_CA_list(3)>,
+L<SSL_get_default_timeout(3)|SSL_get_default_timeout(3)>,
+L<SSL_get_error(3)|SSL_get_error(3)>,
+L<SSL_get_ex_data_X509_STORE_CTX_idx(3)|SSL_get_ex_data_X509_STORE_CTX_idx(3)>,
+L<SSL_get_ex_new_index(3)|SSL_get_ex_new_index(3)>,
+L<SSL_get_fd(3)|SSL_get_fd(3)>,
+L<SSL_get_peer_cert_chain(3)|SSL_get_peer_cert_chain(3)>,
+L<SSL_get_rbio(3)|SSL_get_rbio(3)>,
+L<SSL_get_session(3)|SSL_get_session(3)>,
+L<SSL_get_verify_result(3)|SSL_get_verify_result(3)>,
+L<SSL_get_version(3)|SSL_get_version(3)>,
+L<SSL_library_init(3)|SSL_library_init(3)>,
+L<SSL_load_client_CA_file(3)|SSL_load_client_CA_file(3)>,
+L<SSL_new(3)|SSL_new(3)>,
+L<SSL_pending(3)|SSL_pending(3)>,
+L<SSL_read(3)|SSL_read(3)>,
+L<SSL_rstate_string(3)|SSL_rstate_string(3)>,
+L<SSL_session_reused(3)|SSL_session_reused(3)>,
+L<SSL_set_bio(3)|SSL_set_bio(3)>,
+L<SSL_set_connect_state(3)|SSL_set_connect_state(3)>,
+L<SSL_set_fd(3)|SSL_set_fd(3)>,
+L<SSL_set_session(3)|SSL_set_session(3)>,
+L<SSL_set_shutdown(3)|SSL_set_shutdown(3)>,
+L<SSL_shutdown(3)|SSL_shutdown(3)>,
+L<SSL_state_string(3)|SSL_state_string(3)>,
+L<SSL_want(3)|SSL_want(3)>,
+L<SSL_write(3)|SSL_write(3)>,
+L<SSL_SESSION_free(3)|SSL_SESSION_free(3)>,
+L<SSL_SESSION_get_ex_new_index(3)|SSL_SESSION_get_ex_new_index(3)>,
+L<SSL_SESSION_get_time(3)|SSL_SESSION_get_time(3)>,
+L<d2i_SSL_SESSION(3)|d2i_SSL_SESSION(3)>,
+L<SSL_CTX_set_psk_client_callback(3)|SSL_CTX_set_psk_client_callback(3)>,
+L<SSL_CTX_use_psk_identity_hint(3)|SSL_CTX_use_psk_identity_hint(3)>,
+L<SSL_get_psk_identity(3)|SSL_get_psk_identity(3)>
+
+=head1 HISTORY
+
+The L<ssl(3)|ssl(3)> document appeared in OpenSSL 0.9.2
+
+=cut
+
diff --git a/deps/openssl/openssl/doc/ssleay.txt b/deps/openssl/openssl/doc/ssleay.txt
new file mode 100644 (file)
index 0000000..4d2e714
--- /dev/null
@@ -0,0 +1,7030 @@
+
+Bundle of old SSLeay documentation files [OBSOLETE!]
+
+*** WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! ***
+
+OBSOLETE means that nothing in this document should be trusted.  This
+document is provided mostly for historical purposes (it wasn't even up
+to date at the time SSLeay 0.8.1 was released) and as inspiration.  If
+you copy some snippet of code from this document, please _check_ that
+it really is correct from all points of view.  For example, you can
+check with the other documents in this directory tree, or by comparing
+with relevant parts of the include files.
+
+People have done the mistake of trusting what's written here.  Please
+don't do that.
+
+*** WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! ***
+
+
+==== readme ========================================================
+
+This is the old 0.6.6 docuementation.  Most of the cipher stuff is still
+relevent but I'm working (very slowly) on new documentation.
+The current version can be found online at
+
+http://www.cryptsoft.com/ssleay/doc
+
+==== API.doc ========================================================
+
+SSL - SSLv2/v3/v23 etc.
+
+BIO - methods and how they plug together
+
+MEM - memory allocation callback
+
+CRYPTO - locking for threads
+
+EVP - Ciphers/Digests/signatures
+
+RSA - methods
+
+X509 - certificate retrieval
+
+X509 - validation
+
+X509 - X509v3 extensions
+
+Objects - adding object identifiers
+
+ASN.1 - parsing
+
+PEM - parsing
+
+==== ssl/readme =====================================================
+
+22 Jun 1996
+This file belongs in ../apps, but I'll leave it here because it deals
+with SSL :-)  It is rather dated but it gives you an idea of how
+things work.
+===
+
+17 Jul 1995
+I have been changing things quite a bit and have not fully updated
+this file, so take what you read with a grain of salt
+eric
+===
+The s_client and s_server programs can be used to test SSL capable
+IP/port addresses and the verification of the X509 certificates in use
+by these services.  I strongly advise having a look at the code to get
+an idea of how to use the authentication under SSLeay.  Any feedback
+on changes and improvements would be greatly accepted.
+
+This file will probably be gibberish unless you have read
+rfc1421, rfc1422, rfc1423 and rfc1424 which describe PEM
+authentication.
+
+A Brief outline (and examples) how to use them to do so.
+
+NOTE:
+The environment variable SSL_CIPER is used to specify the prefered
+cipher to use, play around with setting it's value to combinations of
+RC4-MD5, EXP-RC4-MD5, CBC-DES-MD5, CBC3-DES-MD5, CFB-DES-NULL
+in a : separated list.
+
+This directory contains 3 X509 certificates which can be used by these programs.
+client.pem: a file containing a certificate and private key to be used
+       by s_client.
+server.pem :a file containing a certificate and private key to be used
+       by s_server.
+eay1024.pem:the certificate used to sign client.pem and server.pem.
+       This would be your CA's certificate.  There is also a link
+       from the file a8556381.0 to eay1024.PEM.  The value a8556381
+       is returned by 'x509 -hash -noout <eay1024.pem' and is the
+       value used by X509 verification routines to 'find' this
+       certificte when search a directory for it.
+       [the above is not true any more, the CA cert is 
+        ../certs/testca.pem which is signed by ../certs/mincomca.pem]
+
+When testing the s_server, you may get
+bind: Address already in use
+errors.  These indicate the port is still being held by the unix
+kernel and you are going to have to wait for it to let go of it.  If
+this is the case, remember to use the port commands on the s_server and
+s_client to talk on an alternative port.
+
+=====
+s_client.
+This program can be used to connect to any IP/hostname:port that is
+talking SSL.  Once connected, it will attempt to authenticate the
+certificate it was passed and if everything works as expected, a 2
+directional channel will be open.  Any text typed will be sent to the
+other end.  type Q<cr> to exit.  Flags are as follows.
+-host arg      : Arg is the host or IP address to connect to.
+-port arg      : Arg is the port to connect to (https is 443).
+-verify arg    : Turn on authentication of the server certificate.
+               : Arg specifies the 'depth', this will covered below.
+-cert arg      : The optional certificate to use.  This certificate
+               : will be returned to the server if the server
+               : requests it for client authentication.
+-key arg       : The private key that matches the certificate
+               : specified by the -cert option.  If this is not
+               : specified (but -cert is), the -cert file will be
+               : searched for the Private key.  Both files are
+               : assumed to be in PEM format.
+-CApath arg    : When to look for certificates when 'verifying' the
+               : certificate from the server.
+-CAfile arg    : A file containing certificates to be used for
+               : 'verifying' the server certificate.
+-reconnect     : Once a connection has been made, drop it and
+               : reconnect with same session-id.  This is for testing :-).
+
+The '-verify n' parameter specifies not only to verify the servers
+certificate but to also only take notice of 'n' levels.  The best way
+to explain is to show via examples.
+Given
+s_server -cert server.PEM is running.
+
+s_client
+       CONNECTED
+       depth=0 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo server
+       issuer= /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
+       verify error:num=1:unable to get issuer certificate
+       verify return:1
+       CIPHER is CBC-DES-MD5
+What has happened is that the 'SSLeay demo server' certificate's
+issuer ('CA') could not be found but because verify is not on, we
+don't care and the connection has been made anyway.  It is now 'up'
+using CBC-DES-MD5 mode.  This is an unauthenticate secure channel.
+You may not be talking to the right person but the data going to them
+is encrypted.
+
+s_client -verify 0
+       CONNECTED
+       depth=0 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo server
+       issuer= /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
+       verify error:num=1:unable to get issuer certificate
+       verify return:1
+       CIPHER is CBC-DES-MD5
+We are 'verifying' but only to depth 0, so since the 'SSLeay demo server'
+certificate passed the date and checksum, we are happy to proceed.
+
+s_client -verify 1
+       CONNECTED
+       depth=0 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo server
+       issuer= /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
+       verify error:num=1:unable to get issuer certificate
+       verify return:0
+       ERROR
+       verify error:unable to get issuer certificate
+In this case we failed to make the connection because we could not
+authenticate the certificate because we could not find the
+'CA' certificate.
+
+s_client -verify 1 -CAfile eay1024.PEM
+       CONNECTED
+       depth=0 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo server
+       verify return:1
+       depth=1 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
+       verify return:1
+       CIPHER is CBC-DES-MD5
+We loaded the certificates from the file eay1024.PEM.  Everything
+checked out and so we made the connection.
+
+s_client -verify 1 -CApath .
+       CONNECTED
+       depth=0 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo server
+       verify return:1
+       depth=1 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
+       verify return:1
+       CIPHER is CBC-DES-MD5
+We looked in out local directory for issuer certificates and 'found'
+a8556381.0 and so everything is ok.
+
+It is worth noting that 'CA' is a self certified certificate.  If you
+are passed one of these, it will fail to 'verify' at depth 0 because
+we need to lookup the certifier of a certificate from some information
+that we trust and keep locally.
+
+SSL_CIPHER=CBC3-DES-MD5:RC4-MD5
+export SSL_CIPHER
+s_client -verify 10 -CApath . -reconnect
+       CONNECTED
+       depth=0 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo server
+       verify return:1
+       depth=1 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
+       verify return:1
+       drop the connection and reconnect with the same session id
+       CIPHER is CBC3-DES-MD5
+This has done a full connection and then re-estabished it with the
+same session id but a new socket.  No RSA stuff occures on the second
+connection.  Note that we said we would prefer to use CBC3-DES-MD5
+encryption and so, since the server supports it, we are.
+
+=====
+s_server
+This program accepts SSL connections on a specified port
+Once connected, it will estabish an SSL connection and optionaly
+attempt to authenticate the client.  A 2 directional channel will be
+open.  Any text typed will be sent to the other end.  Type Q<cr> to exit.
+Flags are as follows.
+-port arg      : Arg is the port to listen on.
+-verify arg    : Turn on authentication of the client if they have a
+               : certificate.  Arg specifies the 'depth'.
+-Verify arg    : Turn on authentication of the client. If they don't
+               : have a valid certificate, drop the connection.
+-cert arg      : The certificate to use.  This certificate
+               : will be passed to the client.  If it is not
+               : specified, it will default to server.PEM
+-key arg       : The private key that matches the certificate
+               : specified by the -cert option.  If this is not
+               : specified (but -cert is), the -cert file will be
+               : searched for the Private key.  Both files are
+               : assumed to be in PEM format.  Default is server.PEM
+-CApath arg    : When to look for certificates when 'verifying' the
+               : certificate from the client.
+-CAfile arg    : A file containing certificates to be used for
+               : 'verifying' the client certificate.
+
+For the following 'demo'  I will specify the s_server command and
+the s_client command and then list the output from the s_server.
+s_server
+s_client
+       CONNECTED
+       CIPHER is CBC-DES-MD5
+Everything up and running
+
+s_server -verify 0
+s_client  
+       CONNECTED
+       CIPHER is CBC-DES-MD5
+Ok since no certificate was returned and we don't care.
+
+s_server -verify 0
+./s_client -cert client.PEM
+       CONNECTED
+       depth=0 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo client
+       issuer= /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
+       verify error:num=1:unable to get issuer certificate
+       verify return:1
+       CIPHER is CBC-DES-MD5
+Ok since we were only verifying to level 0
+
+s_server -verify 4
+s_client -cert client.PEM
+       CONNECTED
+       depth=0 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo client
+       issuer= /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
+       verify error:num=1:unable to get issuer certificate
+       verify return:0
+       ERROR
+       verify error:unable to get issuer certificate
+Bad because we could not authenticate the returned certificate.
+
+s_server -verify 4 -CApath .
+s_client -cert client.PEM
+       CONNECTED
+       depth=0 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo client
+       verify return:1
+       depth=1 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
+       verify return:1
+       CIPHER is CBC-DES-MD5
+Ok because we could authenticate the returned certificate :-).
+
+s_server -Verify 0 -CApath .
+s_client
+       CONNECTED
+       ERROR
+       SSL error:function is:REQUEST_CERTIFICATE
+                :error is   :client end did not return a certificate
+Error because no certificate returned.
+
+s_server -Verify 4 -CApath .
+s_client -cert client.PEM
+       CONNECTED
+       depth=0 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo client
+       verify return:1
+       depth=1 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
+       verify return:1
+       CIPHER is CBC-DES-MD5
+Full authentication of the client.
+
+So in summary to do full authentication of both ends
+s_server -Verify 9 -CApath .
+s_client -cert client.PEM -CApath . -verify 9
+From the server side
+       CONNECTED
+       depth=0 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo client
+       verify return:1
+       depth=1 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
+       verify return:1
+       CIPHER is CBC-DES-MD5
+From the client side
+       CONNECTED
+       depth=0 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo server
+       verify return:1
+       depth=1 /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
+       verify return:1
+       CIPHER is CBC-DES-MD5
+
+For general probing of the 'internet https' servers for the
+distribution area, run
+s_client -host www.netscape.com -port 443 -verify 4 -CApath ../rsa/hash
+Then enter
+GET /
+and you should be talking to the https server on that host.
+
+www.rsa.com was refusing to respond to connections on 443 when I was
+testing.
+
+have fun :-).
+
+eric
+
+==== a_verify.doc ========================================================
+
+From eay@mincom.com Fri Oct  4 18:29:06 1996
+Received: by orb.mincom.oz.au id AA29080
+  (5.65c/IDA-1.4.4 for eay); Fri, 4 Oct 1996 08:29:07 +1000
+Date: Fri, 4 Oct 1996 08:29:06 +1000 (EST)
+From: Eric Young <eay@mincom.oz.au>
+X-Sender: eay@orb
+To: wplatzer <wplatzer@iaik.tu-graz.ac.at>
+Cc: Eric Young <eay@mincom.oz.au>, SSL Mailing List <ssl-users@mincom.com>
+Subject: Re: Netscape's Public Key
+In-Reply-To: <19961003134837.NTM0049@iaik.tu-graz.ac.at>
+Message-Id: <Pine.SOL.3.91.961004081346.8018K-100000@orb>
+Mime-Version: 1.0
+Content-Type: TEXT/PLAIN; charset=US-ASCII
+Status: RO
+X-Status: 
+
+On Thu, 3 Oct 1996, wplatzer wrote:
+> I get Public Key from Netscape (Gold 3.0b4), but cannot do anything
+> with it... It looks like (asn1parse):
+> 
+> 0:d=0 hl=3 l=180 cons: SEQUENCE
+> 3:d=1 hl=2 l= 96 cons: SEQUENCE
+> 5:d=2 hl=2 l= 92 cons: SEQUENCE
+> 7:d=3 hl=2 l= 13 cons: SEQUENCE
+> 9:d=4 hl=2 l= 9 prim: OBJECT :rsaEncryption
+> 20:d=4 hl=2 l= 0 prim: NULL
+> 22:d=3 hl=2 l= 75 prim: BIT STRING
+> 99:d=2 hl=2 l= 0 prim: IA5STRING :
+> 101:d=1 hl=2 l= 13 cons: SEQUENCE
+> 103:d=2 hl=2 l= 9 prim: OBJECT :md5withRSAEncryption
+> 114:d=2 hl=2 l= 0 prim: NULL
+> 116:d=1 hl=2 l= 65 prim: BIT STRING
+> 
+> The first BIT STRING is the public key and the second BIT STRING is 
+> the signature.
+> But a public key consists of the public exponent and the modulus. Are 
+> both numbers in the first BIT STRING?
+> Is there a document simply describing this coding stuff (checking 
+> signature, get the public key, etc.)?
+
+Minimal in SSLeay.  If you want to see what the modulus and exponent are,
+try asn1parse -offset 25 -length 75 <key.pem
+asn1parse will currently stuff up on the 'length 75' part (fixed in next 
+release) but it will print the stuff.  If you are after more 
+documentation on ASN.1, have a look at www.rsa.com and get their PKCS 
+documents, most of my initial work on SSLeay was done using them.
+
+As for SSLeay,
+util/crypto.num and util/ssl.num are lists of all exported functions in 
+the library (but not macros :-(.
+
+The ones for extracting public keys from certificates and certificate 
+requests are EVP_PKEY *      X509_REQ_extract_key(X509_REQ *req);
+EVP_PKEY *      X509_extract_key(X509 *x509);
+
+To verify a signature on a signed ASN.1 object
+int X509_verify(X509 *a,EVP_PKEY *key);
+int X509_REQ_verify(X509_REQ *a,EVP_PKEY *key);
+int X509_CRL_verify(X509_CRL *a,EVP_PKEY *key);
+int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a,EVP_PKEY *key);
+
+I should mention that EVP_PKEY can be used to hold a public or a private key,
+since for  things like RSA and DSS, a public key is just a subset of what 
+is stored for the private key.
+
+To sign any of the above structures
+
+int X509_sign(X509 *a,EVP_PKEY *key,EVP_MD *md);
+int X509_REQ_sign(X509_REQ *a,EVP_PKEY *key,EVP_MD *md);
+int X509_CRL_sign(X509_CRL *a,EVP_PKEY *key,EVP_MD *md);
+int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *a,EVP_PKEY *key,EVP_MD *md);
+
+where md is the message digest to sign with.
+
+There are all defined in x509.h and all the _sign and _verify functions are
+actually macros to the ASN1_sign() and ASN1_verify() functions.
+These functions will put the correct algorithm identifiers in the correct 
+places in the structures.
+
+eric
+--
+Eric Young                  | BOOL is tri-state according to Bill Gates.
+AARNet: eay@mincom.oz.au    | RTFM Win32 GetMessage().
+
+==== x509 =======================================================
+
+X509_verify()
+X509_sign()
+
+X509_get_version()
+X509_get_serialNumber()
+X509_get_issuer()
+X509_get_subject()
+X509_get_notBefore()
+X509_get_notAfter()
+X509_get_pubkey()
+
+X509_set_version()
+X509_set_serialNumber()
+X509_set_issuer()
+X509_set_subject()
+X509_set_notBefore()
+X509_set_notAfter()
+X509_set_pubkey()
+
+X509_get_extensions()
+X509_set_extensions()
+
+X509_EXTENSIONS_clear()
+X509_EXTENSIONS_retrieve()
+X509_EXTENSIONS_add()
+X509_EXTENSIONS_delete()
+
+==== x509 attribute ================================================
+
+PKCS7
+       STACK of X509_ATTRIBUTES
+               ASN1_OBJECT
+               STACK of ASN1_TYPE
+
+So it is
+
+p7.xa[].obj
+p7.xa[].data[]
+
+get_obj_by_nid(STACK , nid)
+get_num_by_nid(STACK , nid)
+get_data_by_nid(STACK , nid, index)
+
+X509_ATTRIBUTE *X509_ATTRIBUTE_new(void );
+void           X509_ATTRIBUTE_free(X509_ATTRIBUTE *a);
+
+X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **ex,
+                       int nid, STACK *value);
+
+X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **ex,
+                       int nid, STACK *value);
+
+int            X509_ATTRIBUTE_set_object(X509_ATTRIBUTE *ex,ASN1_OBJECT *obj);
+int            X509_ATTRIBUTE_add_data(X509_ATTRIBUTE *ex, int index,
+                       ASN1_TYPE *value);
+
+ASN1_OBJECT *  X509_ATTRIBUTE_get_object(X509_ATTRIBUTE *ex);
+int            X509_ATTRIBUTE_get_num(X509_ATTRIBUTE *ne);
+ASN1_TYPE *    X509_ATTRIBUTE_get_data(X509_ATTRIBUTE *ne,int index);
+
+ASN1_TYPE *    X509_ATTRIBUTE_get_data_by_NID(X509_ATTRIBUTE *ne,
+                       ASN1_OBJECT *obj);
+
+X509_ATTRIBUTE *PKCS7_get_s_att_by_NID(PKCS7 *p7,int nid);
+X509_ATTRIBUTE *PKCS7_get_u_att_by_NID(PKCS7 *p7,int nid);
+
+==== x509 v3 ========================================================
+
+The 'new' system.
+
+The X509_EXTENSION_METHOD includes extensions and attributes and/or names. 
+Basically everthing that can be added to an X509 with an OID identifying it.
+
+It operates via 2 methods per object id.
+int a2i_XXX(X509 *x,char *str,int len);
+int i2a_XXX(BIO *bp,X509 *x);
+
+The a2i_XXX function will add the object with a value converted from the
+string into the X509.  Len can be -1 in which case the length is calculated
+via strlen(str).   Applications can always use direct knowledge to load and
+unload the relevent objects themselves.
+
+i2a_XXX will print to the passed BIO, a text representation of the
+relevet object.  Use a memory BIO if you want it printed to a buffer :-).
+
+X509_add_by_NID(X509 *x,int nid,char *str,int len);
+X509_add_by_OBJ(X509 *x,ASN1_OBJECT *obj,char *str,int len);
+
+X509_print_by_name(BIO *bp,X509 *x);
+X509_print_by_NID(BIO *bp,X509 *x);
+X509_print_by_OBJ(BIO *bp,X509 *x);
+
+==== verify ========================================================
+
+X509_verify_cert_chain(
+       CERT_STORE *cert_store,
+       STACK /* X509 */ *certs,
+       int *verify_result,
+       int (*verify_error_callback)()
+       char *argument_to_callback, /* SSL */
+
+app_verify_callback(
+       char *app_verify_arg, /* from SSL_CTX */
+       STACK /* X509 */ *certs,
+       int *verify_result,
+       int (*verify_error_callback)()
+       SSL *s,
+
+int X509_verify_cert(
+       CERT_STORE *cert_store,
+       X509 *x509,
+       int *verify_result,
+       int (*verify_error_callback)(),
+       char *arg,
+
+==== apps.doc ========================================================
+
+The applications
+
+Ok, where to begin....
+In the begining, when SSLeay was small (April 1995), there
+were but few applications, they did happily cohabit in
+the one bin directory.  Then over time, they did multiply and grow,
+and they started to look like microsoft software; 500k to print 'hello world'.
+A new approach was needed.  They were coalessed into one 'Monolithic'
+application, ssleay.  This one program is composed of many programs that
+can all be compiled independantly.
+
+ssleay has 3 modes of operation.
+1) If the ssleay binary has the name of one of its component programs, it
+executes that program and then exits.  This can be achieved by using hard or
+symbolic links, or failing that, just renaming the binary.
+2) If the first argument to ssleay is the name of one of the component
+programs, that program runs that program and then exits.
+3) If there are no arguments, ssleay enters a 'command' mode.  Each line is
+interpreted as a program name plus arguments.  After each 'program' is run,
+ssleay returns to the comand line.
+
+dgst   - message digests
+enc    - encryption and base64 encoding
+
+ans1parse - 'pulls' appart ASN.1 encoded objects like certificates.
+
+dh     - Diffle-Hellman parameter manipulation.
+rsa    - RSA manipulations.
+crl    - Certificate revokion list manipulations
+x509   - X509 cert fiddles, including signing.
+pkcs7  - pkcs7 manipulation, only DER versions right now.
+
+genrsa - generate an RSA private key.
+gendh  - Generate a set of Diffle-Hellman parameters.
+req    - Generate a PKCS#10 object, a certificate request.
+
+s_client - SSL client program
+s_server - SSL server program
+s_time  - A SSL protocol timing program
+s_mult  - Another SSL server, but it multiplexes
+          connections.
+s_filter - under development
+
+errstr - Convert SSLeay error numbers to strings.
+ca     - Sign certificate requests, and generate
+         certificate revokion lists
+crl2pkcs7 - put a crl and certifcates into a pkcs7 object.
+speed  - Benchmark the ciphers.
+verify - Check certificates
+hashdir - under development
+
+[ there a now a few more options, play with the program to see what they
+  are ]
+
+==== asn1.doc ========================================================
+
+The ASN.1 Routines.
+
+ASN.1 is a specification for how to encode structured 'data' in binary form.
+The approach I have take to the manipulation of structures and their encoding
+into ASN.1 is as follows.
+
+For each distinct structure there are 4 function of the following form
+TYPE *TYPE_new(void);
+void TYPE_free(TYPE *);
+TYPE *d2i_TYPE(TYPE **a,unsigned char **pp,long length);
+long i2d_TYPE(TYPE *a,unsigned char **pp);     /* CHECK RETURN VALUE */
+
+where TYPE is the type of the 'object'.  The TYPE that have these functions
+can be in one of 2 forms, either the internal C malloc()ed data structure
+or in the DER (a variant of ASN.1 encoding) binary encoding which is just
+an array of unsigned bytes.  The 'i2d' functions converts from the internal
+form to the DER form and the 'd2i' functions convert from the DER form to
+the internal form.
+
+The 'new' function returns a malloc()ed version of the structure with all
+substructures either created or left as NULL pointers.  For 'optional'
+fields, they are normally left as NULL to indicate no value.  For variable
+size sub structures (often 'SET OF' or 'SEQUENCE OF' in ASN.1 syntax) the
+STACK data type is used to hold the values.  Have a read of stack.doc
+and have a look at the relevant header files to see what I mean.  If there
+is an error while malloc()ing the structure, NULL is returned.
+
+The 'free' function will free() all the sub components of a particular
+structure.  If any of those sub components have been 'removed', replace
+them with NULL pointers, the 'free' functions are tolerant of NULL fields.
+
+The 'd2i' function copies a binary representation into a C structure.  It
+operates as follows.  'a' is a pointer to a pointer to
+the structure to populate, 'pp' is a pointer to a pointer to where the DER
+byte string is located and 'length' is the length of the '*pp' data.
+If there are no errors, a pointer to the populated structure is returned.
+If there is an error, NULL is returned.  Errors can occur because of
+malloc() failures but normally they will be due to syntax errors in the DER
+encoded data being parsed. It is also an error if there was an
+attempt to read more that 'length' bytes from '*p'.  If
+everything works correctly, the value in '*p' is updated
+to point at the location just beyond where the DER
+structure was read from.  In this way, chained calls to 'd2i' type
+functions can be made, with the pointer into the 'data' array being
+'walked' along the input byte array.
+Depending on the value passed for 'a', different things will be done.  If
+'a' is NULL, a new structure will be malloc()ed and returned.  If '*a' is
+NULL, a new structure will be malloc()ed and put into '*a' and returned.
+If '*a' is not NULL, the structure in '*a' will be populated, or in the
+case of an error, free()ed and then returned.
+Having these semantics means that a structure
+can call a 'd2i' function to populate a field and if the field is currently
+NULL, the structure will be created.
+
+The 'i2d' function type is used to copy a C structure to a byte array.
+The parameter 'a' is the structure to convert and '*p' is where to put it.
+As for the 'd2i' type structure, 'p' is updated to point after the last
+byte written.  If p is NULL, no data is written.  The function also returns
+the number of bytes written.  Where this becomes useful is that if the
+function is called with a NULL 'p' value, the length is returned.  This can
+then be used to malloc() an array of bytes and then the same function can
+be recalled passing the malloced array to be written to. e.g.
+
+int len;
+unsigned char *bytes,*p;
+len=i2d_X509(x,NULL);  /* get the size of the ASN1 encoding of 'x' */
+if ((bytes=(unsigned char *)malloc(len)) == NULL)
+       goto err;
+p=bytes;
+i2d_X509(x,&p);
+
+Please note that a new variable, 'p' was passed to i2d_X509.  After the
+call to i2d_X509 p has been incremented by len bytes.
+
+Now the reason for this functional organisation is that it allows nested
+structures to be built up by calling these functions as required.  There
+are various macros used to help write the general 'i2d', 'd2i', 'new' and
+'free' functions.  They are discussed in another file and would only be
+used by some-one wanting to add new structures to the library.  As you
+might be able to guess, the process of writing ASN.1 files can be a bit CPU
+expensive for complex structures.  I'm willing to live with this since the
+simpler library code make my life easier and hopefully most programs using
+these routines will have their execution profiles dominated by cipher or
+message digest routines.
+What follows is a list of 'TYPE' values and the corresponding ASN.1
+structure and where it is used.
+
+TYPE                   ASN.1
+ASN1_INTEGER           INTEGER
+ASN1_BIT_STRING                BIT STRING
+ASN1_OCTET_STRING      OCTET STRING
+ASN1_OBJECT            OBJECT IDENTIFIER
+ASN1_PRINTABLESTRING   PrintableString
+ASN1_T61STRING         T61String
+ASN1_IA5STRING         IA5String
+ASN1_UTCTIME           UTCTime
+ASN1_TYPE              Any of the above mentioned types plus SEQUENCE and SET
+
+Most of the above mentioned types are actualled stored in the
+ASN1_BIT_STRING type and macros are used to differentiate between them.
+The 3 types used are
+
+typedef struct asn1_object_st
+       {
+       /* both null if a dynamic ASN1_OBJECT, one is
+        * defined if a 'static' ASN1_OBJECT */
+       char *sn,*ln;
+       int nid;
+       int length;
+       unsigned char *data;
+       } ASN1_OBJECT;
+This is used to store ASN1 OBJECTS.  Read 'objects.doc' for details ono
+routines to manipulate this structure.  'sn' and 'ln' are used to hold text
+strings that represent the object (short name and long or lower case name).
+These are used by the 'OBJ' library.  'nid' is a number used by the OBJ
+library to uniquely identify objects.  The ASN1 routines will populate the
+'length' and 'data' fields which will contain the bit string representing
+the object.
+
+typedef struct asn1_bit_string_st
+       {
+       int length;
+       int type;
+       unsigned char *data;
+       } ASN1_BIT_STRING;
+This structure is used to hold all the other base ASN1 types except for
+ASN1_UTCTIME (which is really just a 'char *').  Length is the number of
+bytes held in data and type is the ASN1 type of the object (there is a list
+in asn1.h).
+
+typedef struct asn1_type_st
+       {
+       int type;
+       union   {
+               char *ptr;
+               ASN1_INTEGER *          integer;
+               ASN1_BIT_STRING *       bit_string;
+               ASN1_OCTET_STRING *     octet_string;
+               ASN1_OBJECT *           object;
+               ASN1_PRINTABLESTRING *  printablestring;
+               ASN1_T61STRING *        t61string;
+               ASN1_IA5STRING *        ia5string;
+               ASN1_UTCTIME *          utctime;
+               ASN1_BIT_STRING *       set;
+               ASN1_BIT_STRING *       sequence;
+               } value;
+       } ASN1_TYPE;
+This structure is used in a few places when 'any' type of object can be
+expected.
+
+X509                   Certificate
+X509_CINF              CertificateInfo
+X509_ALGOR             AlgorithmIdentifier
+X509_NAME              Name                    
+X509_NAME_ENTRY                A single sub component of the name.
+X509_VAL               Validity
+X509_PUBKEY            SubjectPublicKeyInfo
+The above mentioned types are declared in x509.h. They are all quite
+straight forward except for the X509_NAME/X509_NAME_ENTRY pair.
+A X509_NAME is a STACK (see stack.doc) of X509_NAME_ENTRY's.
+typedef struct X509_name_entry_st
+       {
+       ASN1_OBJECT *object;
+       ASN1_BIT_STRING *value;
+       int set;
+       int size;       /* temp variable */
+       } X509_NAME_ENTRY;
+The size is a temporary variable used by i2d_NAME and set is the set number
+for the particular NAME_ENTRY.  A X509_NAME is encoded as a sequence of
+sequence of sets.  Normally each set contains only a single item.
+Sometimes it contains more.  Normally throughout this library there will be
+only one item per set.  The set field contains the 'set' that this entry is
+a member of.  So if you have just created a X509_NAME structure and
+populated it with X509_NAME_ENTRYs, you should then traverse the X509_NAME
+(which is just a STACK) and set the 'set/' field to incrementing numbers.
+For more details on why this is done, read the ASN.1 spec for Distinguished
+Names.
+
+X509_REQ               CertificateRequest
+X509_REQ_INFO          CertificateRequestInfo
+These are used to hold certificate requests.
+
+X509_CRL               CertificateRevocationList
+These are used to hold a certificate revocation list
+
+RSAPrivateKey          PrivateKeyInfo
+RSAPublicKey           PublicKeyInfo
+Both these 'function groups' operate on 'RSA' structures (see rsa.doc).
+The difference is that the RSAPublicKey operations only manipulate the m
+and e fields in the RSA structure.
+
+DSAPrivateKey          DSS private key
+DSAPublicKey           DSS public key
+Both these 'function groups' operate on 'DSS' structures (see dsa.doc).
+The difference is that the RSAPublicKey operations only manipulate the 
+XXX fields in the DSA structure.
+
+DHparams               DHParameter
+This is used to hold the p and g value for The Diffie-Hellman operation.
+The function deal with the 'DH' strucure (see dh.doc).
+
+Now all of these function types can be used with several other functions to give
+quite useful set of general manipulation routines.  Normally one would
+not uses these functions directly but use them via macros. 
+
+char *ASN1_dup(int (*i2d)(),char *(*d2i)(),char *x);
+'x' is the input structure case to a 'char *', 'i2d' is the 'i2d_TYPE'
+function for the type that 'x' is and d2i is the 'd2i_TYPE' function for the
+type that 'x' is.  As is obvious from the parameters, this function
+duplicates the strucutre by transforming it into the DER form and then
+re-loading it into a new strucutre and returning the new strucutre.  This
+is obviously a bit cpu intensive but when faced with a complex dynamic
+structure this is the simplest programming approach.  There are macros for
+duplicating the major data types but is simple to add extras.
+
+char *ASN1_d2i_fp(char *(*new)(),char *(*d2i)(),FILE *fp,unsigned char **x);
+'x' is a pointer to a pointer of the 'desired type'.  new and d2i are the
+corresponding 'TYPE_new' and 'd2i_TYPE' functions for the type and 'fp' is
+an open file pointer to read from.  This function reads from 'fp' as much
+data as it can and then uses 'd2i' to parse the bytes to load and return
+the parsed strucutre in 'x' (if it was non-NULL) and to actually return the
+strucutre.  The behavior of 'x' is as per all the other d2i functions.
+
+char *ASN1_d2i_bio(char *(*new)(),char *(*d2i)(),BIO *fp,unsigned char **x);
+The 'BIO' is the new IO type being used in SSLeay (see bio.doc).  This
+function is the same as ASN1_d2i_fp() except for the BIO argument.
+ASN1_d2i_fp() actually calls this function.
+
+int ASN1_i2d_fp(int (*i2d)(),FILE *out,unsigned char *x);
+'x' is converted to bytes by 'i2d' and then written to 'out'.  ASN1_i2d_fp
+and ASN1_d2i_fp are not really symetric since ASN1_i2d_fp will read all
+available data from the file pointer before parsing a single item while
+ASN1_i2d_fp can be used to write a sequence of data objects.  To read a
+series of objects from a file I would sugest loading the file into a buffer
+and calling the relevent 'd2i' functions.
+
+char *ASN1_d2i_bio(char *(*new)(),char *(*d2i)(),BIO *fp,unsigned char **x);
+This function is the same as ASN1_i2d_fp() except for the BIO argument.
+ASN1_i2d_fp() actually calls this function.
+
+char * PEM_ASN1_read(char *(*d2i)(),char *name,FILE *fp,char **x,int (*cb)());
+This function will read the next PEM encoded (base64) object of the same
+type as 'x' (loaded by the d2i function).  'name' is the name that is in
+the '-----BEGIN name-----' that designates the start of that object type.
+If the data is encrypted, 'cb' will be called to prompt for a password.  If
+it is NULL a default function will be used to prompt from the password.
+'x' is delt with as per the standard 'd2i' function interface.  This
+function can be used to read a series of objects from a file.  While any
+data type can be encrypted (see PEM_ASN1_write) only RSA private keys tend
+to be encrypted.
+
+char * PEM_ASN1_read_bio(char *(*d2i)(),char *name,BIO *fp,
+       char **x,int (*cb)());
+Same as PEM_ASN1_read() except using a BIO.  This is called by
+PEM_ASN1_read().
+
+int    PEM_ASN1_write(int (*i2d)(),char *name,FILE *fp,char *x,EVP_CIPHER *enc,
+               unsigned char *kstr,int klen,int (*callback)());
+
+int    PEM_ASN1_write_bio(int (*i2d)(),char *name,BIO *fp,
+               char *x,EVP_CIPHER *enc,unsigned char *kstr,int klen,
+               int (*callback)());
+
+int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
+       ASN1_BIT_STRING *signature, char *data, RSA *rsa, EVP_MD *type);
+int ASN1_verify(int (*i2d)(), X509_ALGOR *algor1,
+       ASN1_BIT_STRING *signature,char *data, RSA *rsa);
+
+int ASN1_BIT_STRING_cmp(ASN1_BIT_STRING *a, ASN1_BIT_STRING *b);
+ASN1_BIT_STRING *ASN1_BIT_STRING_type_new(int type );
+
+int ASN1_UTCTIME_check(ASN1_UTCTIME *a);
+void ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a);
+ASN1_UTCTIME *ASN1_UTCTIME_dup(ASN1_UTCTIME *a);
+
+ASN1_BIT_STRING *d2i_asn1_print_type(ASN1_BIT_STRING **a,unsigned char **pp,
+               long length,int type);
+
+int            i2d_ASN1_SET(STACK *a, unsigned char **pp,
+                       int (*func)(), int ex_tag, int ex_class);
+STACK *                d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
+                       char *(*func)(), int ex_tag, int ex_class);
+
+int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *object);
+int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);
+int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size);
+
+int ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
+long ASN1_INTEGER_get(ASN1_INTEGER *a);
+ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai);
+BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn);
+
+/* given a string, return the correct type.  Max is the maximum number
+ * of bytes to parse.  It stops parsing when 'max' bytes have been
+ * processed or a '\0' is hit */
+int ASN1_PRINTABLE_type(unsigned char *s,int max);
+
+void ASN1_parse(BIO *fp,unsigned char *pp,long len);
+
+int i2d_ASN1_bytes(ASN1_BIT_STRING *a, unsigned char **pp, int tag, int class);
+ASN1_BIT_STRING *d2i_ASN1_bytes(ASN1_OCTET_STRING **a, unsigned char **pp,
+       long length, int Ptag, int Pclass);
+
+/* PARSING */
+int asn1_Finish(ASN1_CTX *c);
+
+/* SPECIALS */
+int ASN1_get_object(unsigned char **pp, long *plength, int *ptag,
+       int *pclass, long omax);
+int ASN1_check_infinite_end(unsigned char **p,long len);
+void ASN1_put_object(unsigned char **pp, int constructed, int length,
+       int tag, int class);
+int ASN1_object_size(int constructed, int length, int tag);
+
+X509 * X509_get_cert(CERTIFICATE_CTX *ctx,X509_NAME * name,X509 *tmp_x509);
+int    X509_add_cert(CERTIFICATE_CTX *ctx,X509 *);
+
+char * X509_cert_verify_error_string(int n);
+int    X509_add_cert_file(CERTIFICATE_CTX *c,char *file, int type);
+char * X509_gmtime (char *s, long adj);
+int    X509_add_cert_dir (CERTIFICATE_CTX *c,char *dir, int type);
+int    X509_load_verify_locations (CERTIFICATE_CTX *ctx,
+               char *file_env, char *dir_env);
+int    X509_set_default_verify_paths(CERTIFICATE_CTX *cts);
+X509 * X509_new_D2i_X509(int len, unsigned char *p);
+char * X509_get_default_cert_area(void );
+char * X509_get_default_cert_dir(void );
+char * X509_get_default_cert_file(void );
+char * X509_get_default_cert_dir_env(void );
+char * X509_get_default_cert_file_env(void );
+char * X509_get_default_private_dir(void );
+X509_REQ *X509_X509_TO_req(X509 *x, RSA *rsa);
+int    X509_cert_verify(CERTIFICATE_CTX *ctx,X509 *xs, int (*cb)()); 
+
+CERTIFICATE_CTX *CERTIFICATE_CTX_new();
+void CERTIFICATE_CTX_free(CERTIFICATE_CTX *c);
+
+void X509_NAME_print(BIO *fp, X509_NAME *name, int obase);
+int            X509_print_fp(FILE *fp,X509 *x);
+int            X509_print(BIO *fp,X509 *x);
+
+X509_INFO *    X509_INFO_new(void);
+void           X509_INFO_free(X509_INFO *a);
+
+char *         X509_NAME_oneline(X509_NAME *a);
+
+#define X509_verify(x,rsa)
+#define X509_REQ_verify(x,rsa)
+#define X509_CRL_verify(x,rsa)
+
+#define X509_sign(x,rsa,md)
+#define X509_REQ_sign(x,rsa,md)
+#define X509_CRL_sign(x,rsa,md)
+
+#define X509_dup(x509)
+#define d2i_X509_fp(fp,x509)
+#define i2d_X509_fp(fp,x509)
+#define d2i_X509_bio(bp,x509)
+#define i2d_X509_bio(bp,x509)
+
+#define X509_CRL_dup(crl)
+#define d2i_X509_CRL_fp(fp,crl)
+#define i2d_X509_CRL_fp(fp,crl)
+#define d2i_X509_CRL_bio(bp,crl)
+#define i2d_X509_CRL_bio(bp,crl)
+
+#define X509_REQ_dup(req)
+#define d2i_X509_REQ_fp(fp,req)
+#define i2d_X509_REQ_fp(fp,req)
+#define d2i_X509_REQ_bio(bp,req)
+#define i2d_X509_REQ_bio(bp,req)
+
+#define RSAPrivateKey_dup(rsa)
+#define d2i_RSAPrivateKey_fp(fp,rsa)
+#define i2d_RSAPrivateKey_fp(fp,rsa)
+#define d2i_RSAPrivateKey_bio(bp,rsa)
+#define i2d_RSAPrivateKey_bio(bp,rsa)
+
+#define X509_NAME_dup(xn)
+#define X509_NAME_ENTRY_dup(ne)
+
+void X509_REQ_print_fp(FILE *fp,X509_REQ *req);
+void X509_REQ_print(BIO *fp,X509_REQ *req);
+
+RSA *X509_REQ_extract_key(X509_REQ *req);
+RSA *X509_extract_key(X509 *x509);
+
+int            X509_issuer_and_serial_cmp(X509 *a, X509 *b);
+unsigned long  X509_issuer_and_serial_hash(X509 *a);
+
+X509_NAME *    X509_get_issuer_name(X509 *a);
+int            X509_issuer_name_cmp(X509 *a, X509 *b);
+unsigned long  X509_issuer_name_hash(X509 *a);
+
+X509_NAME *    X509_get_subject_name(X509 *a);
+int            X509_subject_name_cmp(X509 *a,X509 *b);
+unsigned long  X509_subject_name_hash(X509 *x);
+
+int            X509_NAME_cmp (X509_NAME *a, X509_NAME *b);
+unsigned long  X509_NAME_hash(X509_NAME *x);
+
+
+==== bio.doc ========================================================
+
+BIO Routines
+
+This documentation is rather sparse, you are probably best 
+off looking at the code for specific details.
+
+The BIO library is a IO abstraction that was originally 
+inspired by the need to have callbacks to perform IO to FILE 
+pointers when using Windows 3.1 DLLs.  There are two types 
+of BIO; a source/sink type and a filter type.
+The source/sink methods are as follows:
+-      BIO_s_mem()  memory buffer - a read/write byte array that
+       grows until memory runs out :-).
+-      BIO_s_file()  FILE pointer - A wrapper around the normal 
+       'FILE *' commands, good for use with stdin/stdout.
+-      BIO_s_fd()  File descriptor - A wrapper around file 
+       descriptors, often used with pipes.
+-      BIO_s_socket()  Socket - Used around sockets.  It is 
+       mostly in the Microsoft world that sockets are different 
+       from file descriptors and there are all those ugly winsock 
+       commands.
+-      BIO_s_null()  Null - read nothing and write nothing.; a 
+       useful endpoint for filter type BIO's specifically things 
+       like the message digest BIO.
+
+The filter types are
+-      BIO_f_buffer()  IO buffering - does output buffering into 
+       larger chunks and performs input buffering to allow gets() 
+       type functions.
+-      BIO_f_md()  Message digest - a transparent filter that can 
+       be asked to return a message digest for the data that has 
+       passed through it.
+-      BIO_f_cipher()  Encrypt or decrypt all data passing 
+       through the filter.
+-      BIO_f_base64()  Base64 decode on read and encode on write.
+-      BIO_f_ssl()  A filter that performs SSL encryption on the 
+       data sent through it.
+
+Base BIO functions.
+The BIO library has a set of base functions that are 
+implemented for each particular type.  Filter BIOs will 
+normally call the equivalent function on the source/sink BIO 
+that they are layered on top of after they have performed 
+some modification to the data stream.  Multiple filter BIOs 
+can be 'push' into a stack of modifers, so to read from a 
+file, unbase64 it, then decrypt it, a BIO_f_cipher, 
+BIO_f_base64 and a BIO_s_file would probably be used.  If a 
+sha-1 and md5 message digest needed to be generated, a stack 
+two BIO_f_md() BIOs and a BIO_s_null() BIO could be used.
+The base functions are
+-      BIO *BIO_new(BIO_METHOD *type); Create  a new BIO of  type 'type'.
+-      int BIO_free(BIO *a); Free a BIO structure.  Depending on 
+       the configuration, this will free the underlying data 
+       object for a source/sink BIO.
+-      int BIO_read(BIO *b, char *data, int len); Read upto 'len' 
+       bytes into 'data'. 
+-      int BIO_gets(BIO *bp,char *buf, int size); Depending on 
+       the BIO, this can either be a 'get special' or a get one 
+       line of data, as per fgets();
+-      int BIO_write(BIO *b, char *data, int len); Write 'len' 
+       bytes from 'data' to the 'b' BIO.
+-      int BIO_puts(BIO *bp,char *buf); Either a 'put special' or 
+       a write null terminated string as per fputs().
+-      long BIO_ctrl(BIO *bp,int cmd,long larg,char *parg);  A 
+       control function which is used to manipulate the BIO 
+       structure and modify it's state and or report on it.  This 
+       function is just about never used directly, rather it 
+       should be used in conjunction with BIO_METHOD specific 
+       macros.
+-      BIO *BIO_push(BIO *new_top, BIO *old); new_top is apped to the
+       top of the 'old' BIO list.  new_top should be a filter BIO.
+       All writes will go through 'new_top' first and last on read.
+       'old' is returned.
+-      BIO *BIO_pop(BIO *bio); the new topmost BIO is returned, NULL if
+       there are no more.
+
+If a particular low level BIO method is not supported 
+(normally BIO_gets()), -2 will be returned if that method is 
+called.  Otherwise the IO methods (read, write, gets, puts) 
+will return the number of bytes read or written, and 0 or -1 
+for error (or end of input).  For the -1 case, 
+BIO_should_retry(bio) can be called to determine if it was a 
+genuine error or a temporary problem.  -2 will also be 
+returned if the BIO has not been initalised yet, in all 
+cases, the correct error codes are set (accessible via the 
+ERR library).
+
+
+The following functions are convenience functions:
+-      int BIO_printf(BIO *bio, char * format, ..);  printf but 
+       to a BIO handle.
+-      long BIO_ctrl_int(BIO *bp,int cmd,long larg,int iarg); a 
+       convenience function to allow a different argument types 
+       to be passed to BIO_ctrl().
+-      int BIO_dump(BIO *b,char *bytes,int len); output 'len' 
+       bytes from 'bytes' in a hex dump debug format.
+-      long BIO_debug_callback(BIO *bio, int cmd, char *argp, int 
+       argi, long argl, long ret) - a default debug BIO callback, 
+       this is mentioned below.  To use this one normally has to 
+       use the BIO_set_callback_arg() function to assign an 
+       output BIO for the callback to use.
+-      BIO *BIO_find_type(BIO *bio,int type); when there is a 'stack'
+       of BIOs, this function scan the list and returns the first
+       that is of type 'type', as listed in buffer.h under BIO_TYPE_XXX.
+-      void BIO_free_all(BIO *bio); Free the bio and all other BIOs
+       in the list.  It walks the bio->next_bio list.
+
+
+
+Extra commands are normally implemented as macros calling BIO_ctrl().
+-      BIO_number_read(BIO *bio) - the number of bytes processed 
+       by BIO_read(bio,.).
+-      BIO_number_written(BIO *bio) - the number of bytes written 
+       by BIO_write(bio,.).
+-      BIO_reset(BIO *bio) - 'reset' the BIO.
+-      BIO_eof(BIO *bio) - non zero if we are at the current end 
+       of input.
+-      BIO_set_close(BIO *bio, int close_flag) - set the close flag.
+-      BIO_get_close(BIO *bio) - return the close flag.
+       BIO_pending(BIO *bio) - return the number of bytes waiting 
+       to be read (normally buffered internally).
+-      BIO_flush(BIO *bio) - output any data waiting to be output.
+-      BIO_should_retry(BIO *io) - after a BIO_read/BIO_write 
+       operation returns 0 or -1, a call to this function will 
+       return non zero if you should retry the call later (this 
+       is for non-blocking IO).
+-      BIO_should_read(BIO *io) - we should retry when data can 
+       be read.
+-      BIO_should_write(BIO *io) - we should retry when data can 
+       be written.
+-      BIO_method_name(BIO *io) - return a string for the method name.
+-      BIO_method_type(BIO *io) - return the unique ID of the BIO method.
+-      BIO_set_callback(BIO *io,  long (*callback)(BIO *io, int 
+       cmd, char *argp, int argi, long argl, long ret); - sets 
+       the debug callback.
+-      BIO_get_callback(BIO *io) - return the assigned function 
+       as mentioned above.
+-      BIO_set_callback_arg(BIO *io, char *arg)  - assign some 
+       data against the BIO.  This is normally used by the debug 
+       callback but could in reality be used for anything.  To 
+       get an idea of how all this works, have a look at the code 
+       in the default debug callback mentioned above.  The 
+       callback can modify the return values.
+
+Details of the BIO_METHOD structure.
+typedef struct bio_method_st
+        {
+       int type;
+       char *name;
+       int (*bwrite)();
+       int (*bread)();
+       int (*bputs)();
+       int (*bgets)();
+       long (*ctrl)();
+       int (*create)();
+       int (*destroy)();
+       } BIO_METHOD;
+
+The 'type' is the numeric type of the BIO, these are listed in buffer.h;
+'Name' is a textual representation of the BIO 'type'.
+The 7 function pointers point to the respective function 
+methods, some of which can be NULL if not implemented.
+The BIO structure
+typedef struct bio_st
+       {
+       BIO_METHOD *method;
+       long (*callback)(BIO * bio, int mode, char *argp, int 
+               argi, long argl, long ret);
+       char *cb_arg; /* first argument for the callback */
+       int init;
+       int shutdown;
+       int flags;      /* extra storage */
+       int num;
+       char *ptr;
+       struct bio_st *next_bio; /* used by filter BIOs */
+       int references;
+       unsigned long num_read;
+       unsigned long num_write;
+       } BIO;
+
+-      'Method' is the BIO method.
+-      'callback', when configured, is called before and after 
+       each BIO method is called for that particular BIO.  This 
+       is intended primarily for debugging and of informational feedback.
+-      'init' is 0 when the BIO can be used for operation.  
+       Often, after a BIO is created, a number of operations may 
+       need to be performed before it is available for use.  An 
+       example is for BIO_s_sock().  A socket needs to be 
+       assigned to the BIO before it can be used.
+-      'shutdown', this flag indicates if the underlying 
+       communication primitive being used should be closed/freed 
+       when the BIO is closed.
+-      'flags' is used to hold extra state.  It is primarily used 
+       to hold information about why a non-blocking operation 
+       failed and to record startup protocol information for the 
+       SSL BIO.
+-      'num' and 'ptr' are used to hold instance specific state 
+       like file descriptors or local data structures.
+-      'next_bio' is used by filter BIOs to hold the pointer of the
+       next BIO in the chain. written data is sent to this BIO and
+       data read is taken from it.
+-      'references' is used to indicate the number of pointers to 
+       this structure.  This needs to be '1' before a call to 
+       BIO_free() is made if the BIO_free() function is to 
+       actually free() the structure, otherwise the reference 
+       count is just decreased.  The actual BIO subsystem does 
+       not really use this functionality but it is useful when 
+       used in more advanced applicaion.
+-      num_read and num_write are the total number of bytes 
+       read/written via the 'read()' and 'write()' methods.
+
+BIO_ctrl operations.
+The following is the list of standard commands passed as the 
+second parameter to BIO_ctrl() and should be supported by 
+all BIO as best as possible.  Some are optional, some are 
+manditory, in any case, where is makes sense, a filter BIO 
+should pass such requests to underlying BIO's.
+-      BIO_CTRL_RESET  - Reset the BIO back to an initial state.
+-      BIO_CTRL_EOF    - return 0 if we are not at the end of input, 
+       non 0 if we are.
+-      BIO_CTRL_INFO   - BIO specific special command, normal
+       information return.
+-      BIO_CTRL_SET    - set IO specific parameter.
+-      BIO_CTRL_GET    - get IO specific parameter.
+-      BIO_CTRL_GET_CLOSE - Get the close on BIO_free() flag, one 
+       of BIO_CLOSE or BIO_NOCLOSE.
+-      BIO_CTRL_SET_CLOSE - Set the close on BIO_free() flag.
+-      BIO_CTRL_PENDING - Return the number of bytes available 
+       for instant reading
+-      BIO_CTRL_FLUSH  - Output pending data, return number of bytes output.
+-      BIO_CTRL_SHOULD_RETRY - After an IO error (-1 returned) 
+       should we 'retry' when IO is possible on the underlying IO object.
+-      BIO_CTRL_RETRY_TYPE - What kind of IO are we waiting on.
+
+The following command is a special BIO_s_file() specific option.
+-      BIO_CTRL_SET_FILENAME - specify a file to open for IO.
+
+The BIO_CTRL_RETRY_TYPE needs a little more explanation.  
+When performing non-blocking IO, or say reading on a memory 
+BIO, when no data is present (or cannot be written), 
+BIO_read() and/or BIO_write() will return -1.  
+BIO_should_retry(bio) will return true if this is due to an 
+IO condition rather than an actual error.  In the case of 
+BIO_s_mem(), a read when there is no data will return -1 and 
+a should retry when there is more 'read' data.
+The retry type is deduced from 2 macros
+BIO_should_read(bio) and BIO_should_write(bio).
+Now while it may appear obvious that a BIO_read() failure 
+should indicate that a retry should be performed when more 
+read data is available, this is often not true when using 
+things like an SSL BIO.  During the SSL protocol startup 
+multiple reads and writes are performed, triggered by any 
+SSL_read or SSL_write.
+So to write code that will transparently handle either a 
+socket or SSL BIO,
+       i=BIO_read(bio,..)
+       if (I == -1)
+               {
+               if (BIO_should_retry(bio))
+                       {
+                       if (BIO_should_read(bio))
+                               {
+                               /* call us again when BIO can be read */
+                               }
+                       if (BIO_should_write(bio))
+                               {
+                               /* call us again when BIO can be written */
+                               }
+                       }
+               }
+
+At this point in time only read and write conditions can be 
+used but in the future I can see the situation for other 
+conditions, specifically with SSL there could be a condition 
+of a X509 certificate lookup taking place and so the non-
+blocking BIO_read would require a retry when the certificate 
+lookup subsystem has finished it's lookup.  This is all 
+makes more sense and is easy to use in a event loop type 
+setup.
+When using the SSL BIO, either SSL_read() or SSL_write()s 
+can be called during the protocol startup and things will 
+still work correctly.
+The nice aspect of the use of the BIO_should_retry() macro 
+is that all the errno codes that indicate a non-fatal error 
+are encapsulated in one place.  The Windows specific error 
+codes and WSAGetLastError() calls are also hidden from the 
+application.
+
+Notes on each BIO method.
+Normally buffer.h is just required but depending on the 
+BIO_METHOD, ssl.h or evp.h will also be required.
+
+BIO_METHOD *BIO_s_mem(void);
+-      BIO_set_mem_buf(BIO *bio, BUF_MEM *bm, int close_flag) - 
+       set the underlying BUF_MEM structure for the BIO to use.
+-      BIO_get_mem_ptr(BIO *bio, char **pp) - if pp is not NULL, 
+       set it to point to the memory array and return the number 
+       of bytes available.
+A read/write BIO.  Any data written is appended to the 
+memory array and any read is read from the front.  This BIO 
+can be used for read/write at the same time. BIO_gets() is 
+supported in the fgets() sense.
+BIO_CTRL_INFO can be used to retrieve pointers to the memory 
+buffer and it's length.
+
+BIO_METHOD *BIO_s_file(void);
+-      BIO_set_fp(BIO *bio, FILE *fp, int close_flag) - set 'FILE *' to use.
+-      BIO_get_fp(BIO *bio, FILE **fp) - get the 'FILE *' in use.
+-      BIO_read_filename(BIO *bio, char *name) - read from file.
+-      BIO_write_filename(BIO *bio, char *name) - write to file.
+-      BIO_append_filename(BIO *bio, char *name) - append to file.
+This BIO sits over the normal system fread()/fgets() type 
+functions. Gets() is supported.  This BIO in theory could be 
+used for read and write but it is best to think of each BIO 
+of this type as either a read or a write BIO, not both.
+
+BIO_METHOD *BIO_s_socket(void);
+BIO_METHOD *BIO_s_fd(void);
+-      BIO_sock_should_retry(int i) - the underlying function 
+       used to determine if a call should be retried; the 
+       argument is the '0' or '-1' returned by the previous BIO 
+       operation.
+-      BIO_fd_should_retry(int i) - same as the 
+-      BIO_sock_should_retry() except that it is different internally.
+-      BIO_set_fd(BIO *bio, int fd, int close_flag) - set the 
+       file descriptor to use
+-      BIO_get_fd(BIO *bio, int *fd) - get the file descriptor.
+These two methods are very similar.  Gets() is not 
+supported, if you want this functionality, put a 
+BIO_f_buffer() onto it.  This BIO is bi-directional if the 
+underlying file descriptor is.  This is normally the case 
+for sockets but not the case for stdio descriptors.
+
+BIO_METHOD *BIO_s_null(void);
+Read and write as much data as you like, it all disappears 
+into this BIO.
+
+BIO_METHOD *BIO_f_buffer(void);
+-      BIO_get_buffer_num_lines(BIO *bio) - return the number of 
+       complete lines in the buffer.
+-      BIO_set_buffer_size(BIO *bio, long size) - set the size of 
+       the buffers.
+This type performs input and output buffering.  It performs 
+both at the same time.  The size of the buffer can be set 
+via the set buffer size option.  Data buffered for output is 
+only written when the buffer fills.
+
+BIO_METHOD *BIO_f_ssl(void);
+-      BIO_set_ssl(BIO *bio, SSL *ssl, int close_flag) - the SSL 
+       structure to use.
+-      BIO_get_ssl(BIO *bio, SSL **ssl) - get the SSL structure 
+       in use.
+The SSL bio is a little different from normal BIOs because 
+the underlying SSL structure is a little different.  A SSL 
+structure performs IO via a read and write BIO.  These can 
+be different and are normally set via the
+SSL_set_rbio()/SSL_set_wbio() calls.  The SSL_set_fd() calls 
+are just wrappers that create socket BIOs and then call 
+SSL_set_bio() where the read and write BIOs are the same.  
+The BIO_push() operation makes the SSLs IO BIOs the same, so 
+make sure the BIO pushed is capable of two directional 
+traffic.  If it is not, you will have to install the BIOs 
+via the more conventional SSL_set_bio() call.  BIO_pop() will retrieve
+the 'SSL read' BIO.
+
+BIO_METHOD *BIO_f_md(void);
+-      BIO_set_md(BIO *bio, EVP_MD *md) - set the message digest 
+       to use.
+-      BIO_get_md(BIO *bio, EVP_MD **mdp) - return the digest 
+       method in use in mdp, return 0 if not set yet.
+-      BIO_reset() reinitializes the digest (EVP_DigestInit()) 
+       and passes the reset to the underlying BIOs.
+All data read or written via BIO_read() or BIO_write() to 
+this BIO will be added to the calculated digest.  This 
+implies that this BIO is only one directional.  If read and 
+write operations are performed, two separate BIO_f_md() BIOs 
+are reuqired to generate digests on both the input and the 
+output.  BIO_gets(BIO *bio, char *md, int size) will place the 
+generated digest into 'md' and return the number of bytes.  
+The EVP_MAX_MD_SIZE should probably be used to size the 'md' 
+array.  Reading the digest will also reset it.
+
+BIO_METHOD *BIO_f_cipher(void);
+-      BIO_reset() reinitializes the cipher.
+-      BIO_flush() should be called when the last bytes have been 
+       output to flush the final block of block ciphers.
+-      BIO_get_cipher_status(BIO *b), when called after the last 
+       read from a cipher BIO, returns non-zero if the data 
+       decrypted correctly, otherwise, 0.
+-      BIO_set_cipher(BIO *b, EVP_CIPHER *c, unsigned char *key, 
+       unsigned char *iv, int encrypt)   This function is used to 
+       setup a cipher BIO.  The length of key and iv are 
+       specified by the choice of EVP_CIPHER.  Encrypt is 1 to 
+       encrypt and 0 to decrypt.
+
+BIO_METHOD *BIO_f_base64(void);
+-      BIO_flush() should be called when the last bytes have been output.
+This BIO base64 encodes when writing and base64 decodes when 
+reading.  It will scan the input until a suitable begin line 
+is found.  After reading data, BIO_reset() will reset the 
+BIO to start scanning again.  Do not mix reading and writing 
+on the same base64 BIO.  It is meant as a single stream BIO.
+
+Directions     type
+both           BIO_s_mem()
+one/both       BIO_s_file()
+both           BIO_s_fd()
+both           BIO_s_socket() 
+both           BIO_s_null()
+both           BIO_f_buffer()
+one            BIO_f_md()  
+one            BIO_f_cipher()  
+one            BIO_f_base64()  
+both           BIO_f_ssl()
+
+It is easy to mix one and two directional BIOs, all one has 
+to do is to keep two separate BIO pointers for reading and 
+writing and be careful about usage of underlying BIOs.  The 
+SSL bio by it's very nature has to be two directional but 
+the BIO_push() command will push the one BIO into the SSL 
+BIO for both reading and writing.
+
+The best example program to look at is apps/enc.c and/or perhaps apps/dgst.c.
+
+
+==== blowfish.doc ========================================================
+
+The Blowfish library.
+
+Blowfish is a block cipher that operates on 64bit (8 byte) quantities.  It
+uses variable size key, but 128bit (16 byte) key would normally be considered
+good.  It can be used in all the modes that DES can be used.  This
+library implements the ecb, cbc, cfb64, ofb64 modes.
+
+Blowfish is quite a bit faster that DES, and much faster than IDEA or
+RC2.  It is one of the faster block ciphers.
+
+For all calls that have an 'input' and 'output' variables, they can be the
+same.
+
+This library requires the inclusion of 'blowfish.h'.
+
+All of the encryption functions take what is called an BF_KEY as an 
+argument.  An BF_KEY is an expanded form of the Blowfish key.
+For all modes of the Blowfish algorithm, the BF_KEY used for
+decryption is the same one that was used for encryption.
+
+The define BF_ENCRYPT is passed to specify encryption for the functions
+that require an encryption/decryption flag. BF_DECRYPT is passed to
+specify decryption.
+
+Please note that any of the encryption modes specified in my DES library
+could be used with Blowfish.  I have only implemented ecb, cbc, cfb64 and
+ofb64 for the following reasons.
+- ecb is the basic Blowfish encryption.
+- cbc is the normal 'chaining' form for block ciphers.
+- cfb64 can be used to encrypt single characters, therefore input and output
+  do not need to be a multiple of 8.
+- ofb64 is similar to cfb64 but is more like a stream cipher, not as
+  secure (not cipher feedback) but it does not have an encrypt/decrypt mode.
+- If you want triple Blowfish, thats 384 bits of key and you must be totally
+  obsessed with security.  Still, if you want it, it is simple enough to
+  copy the function from the DES library and change the des_encrypt to
+  BF_encrypt; an exercise left for the paranoid reader :-).
+
+The functions are as follows:
+
+void BF_set_key(
+BF_KEY *ks;
+int len;
+unsigned char *key;
+        BF_set_key converts an 'len' byte key into a BF_KEY.
+        A 'ks' is an expanded form of the 'key' which is used to
+        perform actual encryption.  It can be regenerated from the Blowfish key
+        so it only needs to be kept when encryption or decryption is about
+        to occur.  Don't save or pass around BF_KEY's since they
+        are CPU architecture dependent, 'key's are not.  Blowfish is an
+       interesting cipher in that it can be used with a variable length
+       key.  'len' is the length of 'key' to be used as the key.
+       A 'len' of 16 is recomended by me, but blowfish can use upto
+       72 bytes.  As a warning, blowfish has a very very slow set_key
+       function, it actually runs BF_encrypt 521 times.
+       
+void BF_encrypt(unsigned long *data, BF_KEY *key);
+void BF_decrypt(unsigned long *data, BF_KEY *key);
+       These are the Blowfish encryption function that gets called by just
+       about every other Blowfish routine in the library.  You should not
+       use this function except to implement 'modes' of Blowfish.
+       I say this because the
+       functions that call this routine do the conversion from 'char *' to
+       long, and this needs to be done to make sure 'non-aligned' memory
+       access do not occur.
+       Data is a pointer to 2 unsigned long's and key is the
+       BF_KEY to use. 
+
+void BF_ecb_encrypt(
+unsigned char *in,
+unsigned char *out,
+BF_KEY *key,
+int encrypt);
+       This is the basic Electronic Code Book form of Blowfish (in DES this
+       mode is called Electronic Code Book so I'm going to use the term
+       for blowfish as well.
+       Input is encrypted into output using the key represented by
+       key.  Depending on the encrypt, encryption or
+       decryption occurs.  Input is 8 bytes long and output is 8 bytes.
+       
+void BF_cbc_encrypt(
+unsigned char *in,
+unsigned char *out,
+long length,
+BF_KEY *ks,
+unsigned char *ivec,
+int encrypt);
+       This routine implements Blowfish in Cipher Block Chaining mode.
+       Input, which should be a multiple of 8 bytes is encrypted
+       (or decrypted) to output which will also be a multiple of 8 bytes.
+       The number of bytes is in length (and from what I've said above,
+       should be a multiple of 8).  If length is not a multiple of 8, bad 
+       things will probably happen.  ivec is the initialisation vector.
+       This function updates iv after each call so that it can be passed to
+       the next call to BF_cbc_encrypt().
+       
+void BF_cfb64_encrypt(
+unsigned char *in,
+unsigned char *out,
+long length,
+BF_KEY *schedule,
+unsigned char *ivec,
+int *num,
+int encrypt);
+       This is one of the more useful functions in this Blowfish library, it
+       implements CFB mode of Blowfish with 64bit feedback.
+       This allows you to encrypt an arbitrary number of bytes,
+       you do not require 8 byte padding.  Each call to this
+       routine will encrypt the input bytes to output and then update ivec
+       and num.  Num contains 'how far' we are though ivec.
+       'Encrypt' is used to indicate encryption or decryption.
+       CFB64 mode operates by using the cipher to generate a stream
+       of bytes which is used to encrypt the plain text.
+       The cipher text is then encrypted to generate the next 64 bits to
+       be xored (incrementally) with the next 64 bits of plain
+       text.  As can be seen from this, to encrypt or decrypt,
+       the same 'cipher stream' needs to be generated but the way the next
+       block of data is gathered for encryption is different for
+       encryption and decryption.
+       
+void BF_ofb64_encrypt(
+unsigned char *in,
+unsigned char *out,
+long length,
+BF_KEY *schedule,
+unsigned char *ivec,
+int *num);
+       This functions implements OFB mode of Blowfish with 64bit feedback.
+       This allows you to encrypt an arbitrary number of bytes,
+       you do not require 8 byte padding.  Each call to this
+       routine will encrypt the input bytes to output and then update ivec
+       and num.  Num contains 'how far' we are though ivec.
+       This is in effect a stream cipher, there is no encryption or
+       decryption mode.
+       
+For reading passwords, I suggest using des_read_pw_string() from my DES library.
+To generate a password from a text string, I suggest using MD5 (or MD2) to
+produce a 16 byte message digest that can then be passed directly to
+BF_set_key().
+
+=====
+For more information about the specific Blowfish modes in this library
+(ecb, cbc, cfb and ofb), read the section entitled 'Modes of DES' from the
+documentation on my DES library.  What is said about DES is directly
+applicable for Blowfish.
+
+
+==== bn.doc ========================================================
+
+The Big Number library.
+
+#include "bn.h" when using this library.
+
+This big number library was written for use in implementing the RSA and DH
+public key encryption algorithms.  As such, features such as negative
+numbers have not been extensively tested but they should work as expected.
+This library uses dynamic memory allocation for storing its data structures
+and so there are no limit on the size of the numbers manipulated by these
+routines but there is always the requirement to check return codes from
+functions just in case a memory allocation error has occurred.
+
+The basic object in this library is a BIGNUM.  It is used to hold a single
+large integer.  This type should be considered opaque and fields should not
+be modified or accessed directly.
+typedef struct bignum_st
+       {
+       int top;        /* Index of last used d. */
+       BN_ULONG *d;    /* Pointer to an array of 'BITS2' bit chunks. */
+       int max;        /* Size of the d array. */
+       int neg;
+       } BIGNUM;
+The big number is stored in a malloced array of BN_ULONG's.  A BN_ULONG can
+be either 16, 32 or 64 bits in size, depending on the 'number of  bits'
+specified in bn.h. 
+The 'd' field is this array.  'max' is the size of the 'd' array that has
+been allocated.  'top' is the 'last' entry being used, so for a value of 4,
+bn.d[0]=4 and bn.top=1.  'neg' is 1 if the number is negative.
+When a BIGNUM is '0', the 'd' field can be NULL and top == 0.
+
+Various routines in this library require the use of 'temporary' BIGNUM
+variables during their execution.  Due to the use of dynamic memory
+allocation to create BIGNUMs being rather expensive when used in
+conjunction with repeated subroutine calls, the BN_CTX structure is
+used.  This structure contains BN_CTX BIGNUMs.  BN_CTX
+is the maximum number of temporary BIGNUMs any publicly exported 
+function will use.
+
+#define BN_CTX 12
+typedef struct bignum_ctx
+       {
+       int tos;                        /* top of stack */
+       BIGNUM *bn[BN_CTX];     /* The variables */
+       } BN_CTX;
+
+The functions that follow have been grouped according to function.  Most
+arithmetic functions return a result in the first argument, sometimes this
+first argument can also be an input parameter, sometimes it cannot.  These
+restrictions are documented.
+
+extern BIGNUM *BN_value_one;
+There is one variable defined by this library, a BIGNUM which contains the
+number 1.  This variable is useful for use in comparisons and assignment.
+
+Get Size functions.
+
+int BN_num_bits(BIGNUM *a);
+       This function returns the size of 'a' in bits.
+       
+int BN_num_bytes(BIGNUM *a);
+       This function (macro) returns the size of 'a' in bytes.
+       For conversion of BIGNUMs to byte streams, this is the number of
+       bytes the output string will occupy.  If the output byte
+       format specifies that the 'top' bit indicates if the number is
+       signed, so an extra '0' byte is required if the top bit on a
+       positive number is being written, it is upto the application to
+       make this adjustment.  Like I said at the start, I don't
+       really support negative numbers :-).
+
+Creation/Destruction routines.
+
+BIGNUM *BN_new();
+       Return a new BIGNUM object.  The number initially has a value of 0.  If
+       there is an error, NULL is returned.
+       
+void   BN_free(BIGNUM *a);
+       Free()s a BIGNUM.
+       
+void   BN_clear(BIGNUM *a);
+       Sets 'a' to a value of 0 and also zeros all unused allocated
+       memory.  This function is used to clear a variable of 'sensitive'
+       data that was held in it.
+       
+void   BN_clear_free(BIGNUM *a);
+       This function zeros the memory used by 'a' and then free()'s it.
+       This function should be used to BN_free() BIGNUMS that have held
+       sensitive numeric values like RSA private key values.  Both this
+       function and BN_clear tend to only be used by RSA and DH routines.
+
+BN_CTX *BN_CTX_new(void);
+       Returns a new BN_CTX.  NULL on error.
+       
+void   BN_CTX_free(BN_CTX *c);
+       Free a BN_CTX structure.  The BIGNUMs in 'c' are BN_clear_free()ed.
+       
+BIGNUM *bn_expand(BIGNUM *b, int bits);
+       This is an internal function that should not normally be used.  It
+       ensures that 'b' has enough room for a 'bits' bit number.  It is
+       mostly used by the various BIGNUM routines.  If there is an error,
+       NULL is returned. if not, 'b' is returned.
+       
+BIGNUM *BN_copy(BIGNUM *to, BIGNUM *from);
+       The 'from' is copied into 'to'.  NULL is returned if there is an
+       error, otherwise 'to' is returned.
+
+BIGNUM *BN_dup(BIGNUM *a);
+       A new BIGNUM is created and returned containing the value of 'a'.
+       NULL is returned on error.
+
+Comparison and Test Functions.
+
+int BN_is_zero(BIGNUM *a)
+       Return 1 if 'a' is zero, else 0.
+
+int BN_is_one(a)
+       Return 1 is 'a' is one, else 0.
+
+int BN_is_word(a,w)
+       Return 1 if 'a' == w, else 0.  'w' is a BN_ULONG.
+
+int BN_cmp(BIGNUM *a, BIGNUM *b);
+       Return -1 if 'a' is less than 'b', 0 if 'a' and 'b' are the same
+       and 1 is 'a' is greater than 'b'.  This is a signed comparison.
+       
+int BN_ucmp(BIGNUM *a, BIGNUM *b);
+       This function is the same as BN_cmp except that the comparison
+       ignores the sign of the numbers.
+       
+Arithmetic Functions
+For all of these functions, 0 is returned if there is an error and 1 is
+returned for success.  The return value should always be checked.  eg.
+if (!BN_add(r,a,b)) goto err;
+Unless explicitly mentioned, the 'return' value can be one of the
+'parameters' to the function.
+
+int BN_add(BIGNUM *r, BIGNUM *a, BIGNUM *b);
+       Add 'a' and 'b' and return the result in 'r'.  This is r=a+b.
+       
+int BN_sub(BIGNUM *r, BIGNUM *a, BIGNUM *b);
+       Subtract 'a' from 'b' and put the result in 'r'. This is r=a-b.
+       
+int BN_lshift(BIGNUM *r, BIGNUM *a, int n);
+       Shift 'a' left by 'n' bits.  This is r=a*(2^n).
+       
+int BN_lshift1(BIGNUM *r, BIGNUM *a);
+       Shift 'a' left by 1 bit.  This form is more efficient than
+       BN_lshift(r,a,1).  This is r=a*2.
+       
+int BN_rshift(BIGNUM *r, BIGNUM *a, int n);
+       Shift 'a' right by 'n' bits.  This is r=int(a/(2^n)).
+       
+int BN_rshift1(BIGNUM *r, BIGNUM *a);
+       Shift 'a' right by 1 bit.  This form is more efficient than
+       BN_rshift(r,a,1).  This is r=int(a/2).
+       
+int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b);
+       Multiply a by b and return the result in 'r'. 'r' must not be
+       either 'a' or 'b'.  It has to be a different BIGNUM.
+       This is r=a*b.
+
+int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx);
+       Multiply a by a and return the result in 'r'. 'r' must not be
+       'a'.  This function is alot faster than BN_mul(r,a,a).  This is r=a*a.
+
+int BN_div(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx);
+       Divide 'm' by 'd' and return the result in 'dv' and the remainder
+       in 'rem'.  Either of 'dv' or 'rem' can be NULL in which case that
+       value is not returned.  'ctx' needs to be passed as a source of
+       temporary BIGNUM variables.
+       This is dv=int(m/d), rem=m%d.
+       
+int BN_mod(BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx);
+       Find the remainder of 'm' divided by 'd' and return it in 'rem'.
+       'ctx' holds the temporary BIGNUMs required by this function.
+       This function is more efficient than BN_div(NULL,rem,m,d,ctx);
+       This is rem=m%d.
+
+int BN_mod_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BIGNUM *m,BN_CTX *ctx);
+       Multiply 'a' by 'b' and return the remainder when divided by 'm'.
+       'ctx' holds the temporary BIGNUMs required by this function.
+       This is r=(a*b)%m.
+
+int BN_mod_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m,BN_CTX *ctx);
+       Raise 'a' to the 'p' power and return the remainder when divided by
+       'm'.  'ctx' holds the temporary BIGNUMs required by this function.
+       This is r=(a^p)%m.
+
+int BN_reciprocal(BIGNUM *r, BIGNUM *m, BN_CTX *ctx);
+       Return the reciprocal of 'm'.  'ctx' holds the temporary variables
+       required.  This function returns -1 on error, otherwise it returns
+       the number of bits 'r' is shifted left to make 'r' into an integer.
+       This number of bits shifted is required in BN_mod_mul_reciprocal().
+       This is r=(1/m)<<(BN_num_bits(m)+1).
+       
+int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *x, BIGNUM *y, BIGNUM *m, 
+       BIGNUM *i, int nb, BN_CTX *ctx);
+       This function is used to perform an efficient BN_mod_mul()
+       operation.  If one is going to repeatedly perform BN_mod_mul() with
+       the same modulus is worth calculating the reciprocal of the modulus
+       and then using this function.  This operation uses the fact that
+       a/b == a*r where r is the reciprocal of b.  On modern computers
+       multiplication is very fast and big number division is very slow.
+       'x' is multiplied by 'y' and then divided by 'm' and the remainder
+       is returned.  'i' is the reciprocal of 'm' and 'nb' is the number
+       of bits as returned from BN_reciprocal().  Normal usage is as follows.
+       bn=BN_reciprocal(i,m);
+       for (...)
+               { BN_mod_mul_reciprocal(r,x,y,m,i,bn,ctx); }
+       This is r=(x*y)%m.  Internally it is approximately
+       r=(x*y)-m*(x*y/m) or r=(x*y)-m*((x*y*i) >> bn)
+       This function is used in BN_mod_exp() and BN_is_prime().
+
+Assignment Operations
+
+int BN_one(BIGNUM *a)
+       Set 'a' to hold the value one.
+       This is a=1.
+       
+int BN_zero(BIGNUM *a)
+       Set 'a' to hold the value zero.
+       This is a=0.
+       
+int BN_set_word(BIGNUM *a, unsigned long w);
+       Set 'a' to hold the value of 'w'.  'w' is an unsigned long.
+       This is a=w.
+
+unsigned long BN_get_word(BIGNUM *a);
+       Returns 'a' in an unsigned long.  Not remarkably, often 'a' will
+       be bigger than a word, in which case 0xffffffffL is returned.
+
+Word Operations
+These functions are much more efficient that the normal bignum arithmetic
+operations.
+
+BN_ULONG BN_mod_word(BIGNUM *a, unsigned long w);
+       Return the remainder of 'a' divided by 'w'.
+       This is return(a%w).
+       
+int BN_add_word(BIGNUM *a, unsigned long w);
+       Add 'w' to 'a'.  This function does not take the sign of 'a' into
+       account.  This is a+=w;
+       
+Bit operations.
+
+int BN_is_bit_set(BIGNUM *a, int n);
+       This function return 1 if bit 'n' is set in 'a' else 0.
+
+int BN_set_bit(BIGNUM *a, int n);
+       This function sets bit 'n' to 1 in 'a'. 
+       This is a&= ~(1<<n);
+
+int BN_clear_bit(BIGNUM *a, int n);
+       This function sets bit 'n' to zero in 'a'.  Return 0 if less
+       than 'n' bits in 'a' else 1.  This is a&= ~(1<<n);
+
+int BN_mask_bits(BIGNUM *a, int n);
+       Truncate 'a' to n bits long.  This is a&= ~((~0)<<n)
+
+Format conversion routines.
+
+BIGNUM *BN_bin2bn(unsigned char *s, int len,BIGNUM *ret);
+       This function converts 'len' bytes in 's' into a BIGNUM which
+       is put in 'ret'.  If ret is NULL, a new BIGNUM is created.
+       Either this new BIGNUM or ret is returned.  The number is
+       assumed to be in bigendian form in 's'.  By this I mean that
+       to 'ret' is created as follows for 'len' == 5.
+       ret = s[0]*2^32 + s[1]*2^24 + s[2]*2^16 + s[3]*2^8 + s[4];
+       This function cannot be used to convert negative numbers.  It
+       is always assumed the number is positive.  The application
+       needs to diddle the 'neg' field of th BIGNUM its self.
+       The better solution would be to save the numbers in ASN.1 format
+       since this is a defined standard for storing big numbers.
+       Look at the functions
+
+       ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai);
+       BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn);
+       int i2d_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp);
+       ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp,
+               long length;
+
+int BN_bn2bin(BIGNUM *a, unsigned char *to);
+       This function converts 'a' to a byte string which is put into
+       'to'.  The representation is big-endian in that the most
+       significant byte of 'a' is put into to[0].  This function
+       returns the number of bytes used to hold 'a'.  BN_num_bytes(a)
+       would return the same value and can be used to determine how
+       large 'to' needs to be.  If the number is negative, this
+       information is lost.  Since this library was written to
+       manipulate large positive integers, the inability to save and
+       restore them is not considered to be a problem by me :-).
+       As for BN_bin2bn(), look at the ASN.1 integer encoding funtions
+       for SSLeay.  They use BN_bin2bn() and BN_bn2bin() internally.
+       
+char *BN_bn2ascii(BIGNUM *a);
+       This function returns a malloc()ed string that contains the
+       ascii hexadecimal encoding of 'a'.  The number is in bigendian
+       format with a '-' in front if the number is negative.
+
+int BN_ascii2bn(BIGNUM **bn, char *a);
+       The inverse of BN_bn2ascii.  The function returns the number of
+       characters from 'a' were processed in generating a the bignum.
+       error is inticated by 0 being returned.  The number is a
+       hex digit string, optionally with a leading '-'.  If *bn
+       is null, a BIGNUM is created and returned via that variable.
+       
+int BN_print_fp(FILE *fp, BIGNUM *a);
+       'a' is printed to file pointer 'fp'.  It is in the same format
+       that is output from BN_bn2ascii().  0 is returned on error,
+       1 if things are ok.
+
+int BN_print(BIO *bp, BIGNUM *a);
+       Same as BN_print except that the output is done to the SSLeay libraries
+       BIO routines.  BN_print_fp() actually calls this function.
+
+Miscellaneous Routines.
+
+int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
+       This function returns in 'rnd' a random BIGNUM that is bits
+       long.  If bottom is 1, the number returned is odd.  If top is set,
+       the top 2 bits of the number are set.  This is useful because if
+       this is set, 2 'n; bit numbers multiplied together will return a 2n
+       bit number.  If top was not set, they could produce a 2n-1 bit
+       number.
+
+BIGNUM *BN_mod_inverse(BIGNUM *a, BIGNUM *n,BN_CTX *ctx);
+       This function create a new BIGNUM and returns it.  This number
+       is the inverse mod 'n' of 'a'.  By this it is meant that the
+       returned value 'r' satisfies (a*r)%n == 1.  This function is
+       used in the generation of RSA keys.  'ctx', as per usual,
+       is used to hold temporary variables that are required by the
+       function.  NULL is returned on error.
+
+int BN_gcd(BIGNUM *r,BIGNUM *a,BIGNUM *b,BN_CTX *ctx);
+       'r' has the greatest common divisor of 'a' and 'b'.  'ctx' is
+       used for temporary variables and 0 is returned on error.
+
+int BN_is_prime(BIGNUM *p,int nchecks,void (*callback)(),BN_CTX *ctx,
+       char *cb_arg);
+       This function is used to check if a BIGNUM ('p') is prime.
+       It performs this test by using the Miller-Rabin randomised
+       primality test.  This is a probalistic test that requires a
+       number of rounds to ensure the number is prime to a high
+       degree of probability.  Since this can take quite some time, a
+       callback function can be passed and it will be called each
+       time 'p' passes a round of the prime testing.  'callback' will
+       be called as follows, callback(1,n,cb_arg) where n is the number of
+       the round, just passed.  As per usual 'ctx' contains temporary
+       variables used.  If ctx is NULL, it does not matter, a local version
+       will be malloced.  This parameter is present to save some mallocing
+       inside the function but probably could be removed.
+       0 is returned on error.
+       'ncheck' is the number of Miller-Rabin tests to run.  It is
+       suggested to use the value 'BN_prime_checks' by default.
+
+BIGNUM *BN_generate_prime(
+int bits,
+int strong,
+BIGNUM *a,
+BIGNUM *rems,
+void (*callback)());
+char *cb_arg
+       This function is used to generate prime numbers.  It returns a
+       new BIGNUM that has a high probability of being a prime.
+       'bits' is the number of bits that
+       are to be in the prime.  If 'strong' is true, the returned prime
+       will also be a strong prime ((p-1)/2 is also prime).
+       While searching for the prime ('p'), we
+       can add the requirement that the prime fill the following
+       condition p%a == rem.  This can be used to help search for
+       primes with specific features, which is required when looking
+       for primes suitable for use with certain 'g' values in the
+       Diffie-Hellman key exchange algorithm.  If 'a' is NULL,
+       this condition is not checked.  If rem is NULL, rem is assumed
+       to be 1.  Since this search for a prime
+       can take quite some time, if callback is not NULL, it is called
+       in the following situations.
+       We have a suspected prime (from a quick sieve),
+       callback(0,sus_prime++,cb_arg). Each item to be passed to BN_is_prime().
+       callback(1,round++,cb_arg).  Each successful 'round' in BN_is_prime().
+       callback(2,round,cb_arg). For each successful BN_is_prime() test.
+
+Hints
+-----
+
+DSA wants 64*32 to use word mont mul, but RSA wants to use full.
+
+==== callback.doc ========================================================
+
+Callback functions used in SSLeay.
+
+--------------------------
+The BIO library.  
+
+Each BIO structure can have a callback defined against it.  This callback is
+called 2 times for each BIO 'function'.  It is passed 6 parameters.
+BIO_debug_callback() is an example callback which is defined in
+crypto/buffer/bio_cb.c and is used in apps/dgst.c  This is intended mostly
+for debuging or to notify the application of IO.
+
+long BIO_debug_callback(BIO *bio,int cmd,char *argp,int argi,long argl,
+       long ret);
+bio is the BIO being called, cmd is the type of BIO function being called.
+Look at the BIO_CB_* defines in buffer.h.  Argp and argi are the arguments
+passed to BIO_read(), BIO_write, BIO_gets(), BIO_puts().  In the case of
+BIO_ctrl(), argl is also defined.  The first time the callback is called,
+before the underlying function has been executed, 0 is passed as 'ret', and
+if the return code from the callback is not > 0, the call is aborted
+and the returned <= 0 value is returned.
+The second time the callback is called, the 'cmd' value also has
+BIO_CB_RETURN logically 'or'ed with it.  The 'ret' value is the value returned
+from the actuall function call and whatever the callback returns is returned
+from the BIO function.
+
+BIO_set_callback(b,cb) can be used to set the callback function
+(b is a BIO), and BIO_set_callback_arg(b,arg) can be used to
+set the cb_arg argument in the BIO strucutre.  This field is only intended
+to be used by application, primarily in the callback function since it is
+accessable since the BIO is passed.
+
+--------------------------
+The PEM library.
+
+The pem library only really uses one type of callback,
+static int def_callback(char *buf, int num, int verify);
+which is used to return a password string if required.
+'buf' is the buffer to put the string in.  'num' is the size of 'buf'
+and 'verify' is used to indicate that the password should be checked.
+This last flag is mostly used when reading a password for encryption.
+
+For all of these functions, a NULL callback will call the above mentioned
+default callback.  This default function does not work under Windows 3.1.
+For other machines, it will use an application defined prompt string
+(EVP_set_pw_prompt(), which defines a library wide prompt string)
+if defined, otherwise it will use it's own PEM password prompt.
+It will then call EVP_read_pw_string() to get a password from the console.
+If your application wishes to use nice fancy windows to retrieve passwords,
+replace this function.  The callback should return the number of bytes read
+into 'buf'.  If the number of bytes <= 0, it is considered an error.
+
+Functions that take this callback are listed below.  For the 'read' type
+functions, the callback will only be required if the PEM data is encrypted.
+
+For the Write functions, normally a password can be passed in 'kstr', of
+'klen' bytes which will be used if the 'enc' cipher is not NULL.  If
+'kstr' is NULL, the callback will be used to retrieve a password.
+
+int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len,
+       int (*callback)());
+char *PEM_ASN1_read_bio(char *(*d2i)(),char *name,BIO *bp,char **x,int (*cb)());
+char *PEM_ASN1_read(char *(*d2i)(),char *name,FILE *fp,char **x,int (*cb)());
+int PEM_ASN1_write_bio(int (*i2d)(),char *name,BIO *bp,char *x,
+       EVP_CIPHER *enc,unsigned char *kstr,int klen,int (*callback)());
+int PEM_ASN1_write(int (*i2d)(),char *name,FILE *fp,char *x,
+       EVP_CIPHER *enc,unsigned char *kstr,int klen,int (*callback)());
+STACK *PEM_X509_INFO_read(FILE *fp, STACK *sk, int (*cb)());
+STACK *PEM_X509_INFO_read_bio(BIO *fp, STACK *sk, int (*cb)());
+
+#define        PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb)
+#define        PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb)
+#define        PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb)
+#define        PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb)
+#define        PEM_read_SSL_SESSION(fp,x,cb)
+#define        PEM_read_X509(fp,x,cb)
+#define        PEM_read_X509_REQ(fp,x,cb)
+#define        PEM_read_X509_CRL(fp,x,cb)
+#define        PEM_read_RSAPrivateKey(fp,x,cb)
+#define        PEM_read_DSAPrivateKey(fp,x,cb)
+#define        PEM_read_PrivateKey(fp,x,cb)
+#define        PEM_read_PKCS7(fp,x,cb)
+#define        PEM_read_DHparams(fp,x,cb)
+#define        PEM_read_bio_SSL_SESSION(bp,x,cb)
+#define        PEM_read_bio_X509(bp,x,cb)
+#define        PEM_read_bio_X509_REQ(bp,x,cb)
+#define        PEM_read_bio_X509_CRL(bp,x,cb)
+#define        PEM_read_bio_RSAPrivateKey(bp,x,cb)
+#define        PEM_read_bio_DSAPrivateKey(bp,x,cb)
+#define        PEM_read_bio_PrivateKey(bp,x,cb)
+#define        PEM_read_bio_PKCS7(bp,x,cb)
+#define        PEM_read_bio_DHparams(bp,x,cb)
+int i2d_Netscape_RSA(RSA *a, unsigned char **pp, int (*cb)());
+RSA *d2i_Netscape_RSA(RSA **a, unsigned char **pp, long length, int (*cb)());
+
+Now you will notice that macros like
+#define PEM_write_X509(fp,x) \
+                PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \
+                                       (char *)x, NULL,NULL,0,NULL)
+Don't do encryption normally.  If you want to PEM encrypt your X509 structure,
+either just call PEM_ASN1_write directly or just define your own
+macro variant.  As you can see, this macro just sets all encryption related
+parameters to NULL.
+
+
+--------------------------
+The SSL library.
+
+#define SSL_set_info_callback(ssl,cb)
+#define SSL_CTX_set_info_callback(ctx,cb)
+void callback(SSL *ssl,int location,int ret)
+This callback is called each time around the SSL_connect()/SSL_accept() 
+state machine.  So it will be called each time the SSL protocol progresses.
+It is mostly present for use when debugging.  When SSL_connect() or
+SSL_accept() return, the location flag is SSL_CB_ACCEPT_EXIT or
+SSL_CB_CONNECT_EXIT and 'ret' is the value about to be returned.
+Have a look at the SSL_CB_* defines in ssl.h.  If an info callback is defined
+against the SSL_CTX, it is called unless there is one set against the SSL.
+Have a look at
+void client_info_callback() in apps/s_client() for an example.
+
+Certificate verification.
+void SSL_set_verify(SSL *s, int mode, int (*callback) ());
+void SSL_CTX_set_verify(SSL_CTX *ctx,int mode,int (*callback)());
+This callback is used to help verify client and server X509 certificates.
+It is actually passed to X509_cert_verify(), along with the SSL structure
+so you have to read about X509_cert_verify() :-).  The SSL_CTX version is used
+if the SSL version is not defined.  X509_cert_verify() is the function used
+by the SSL part of the library to verify certificates.  This function is
+nearly always defined by the application.
+
+void SSL_CTX_set_cert_verify_cb(SSL_CTX *ctx, int (*cb)(),char *arg);
+int callback(char *arg,SSL *s,X509 *xs,STACK *cert_chain);
+This call is used to replace the SSLeay certificate verification code.
+The 'arg' is kept in the SSL_CTX and is passed to the callback.
+If the callback returns 0, the certificate is rejected, otherwise it
+is accepted.  The callback is replacing the X509_cert_verify() call.
+This feature is not often used, but if you wished to implement
+some totally different certificate authentication system, this 'hook' is
+vital.
+
+SSLeay keeps a cache of session-ids against each SSL_CTX.  These callbacks can
+be used to notify the application when a SSL_SESSION is added to the cache
+or to retrieve a SSL_SESSION that is not in the cache from the application.
+#define SSL_CTX_sess_set_get_cb(ctx,cb)
+SSL_SESSION *callback(SSL *s,char *session_id,int session_id_len,int *copy);
+If defined, this callback is called to return the SESSION_ID for the
+session-id in 'session_id', of 'session_id_len' bytes.  'copy' is set to 1
+if the server is to 'take a copy' of the SSL_SESSION structure.  It is 0
+if the SSL_SESSION is being 'passed in' so the SSLeay library is now
+responsible for 'free()ing' the structure.  Basically it is used to indicate
+if the reference count on the SSL_SESSION structure needs to be incremented.
+
+#define SSL_CTX_sess_set_new_cb(ctx,cb)
+int callback(SSL *s, SSL_SESSION *sess);
+When a new connection is established, if the SSL_SESSION is going to be added
+to the cache, this callback is called.  Return 1 if a 'copy' is required,
+otherwise, return 0.  This return value just causes the reference count
+to be incremented (on return of a 1), this means the application does
+not need to worry about incrementing the refernece count (and the
+locking that implies in a multi-threaded application).
+
+void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx,int (*cb)());
+This sets the SSL password reading function.
+It is mostly used for windowing applications
+and used by PEM_read_bio_X509() and PEM_read_bio_RSAPrivateKey()
+calls inside the SSL library.   The only reason this is present is because the
+calls to PEM_* functions is hidden in the SSLeay library so you have to
+pass in the callback some how.
+
+#define SSL_CTX_set_client_cert_cb(ctx,cb)
+int callback(SSL *s,X509 **x509, EVP_PKEY **pkey);
+Called when a client certificate is requested but there is not one set
+against the SSL_CTX or the SSL.  If the callback returns 1, x509 and
+pkey need to point to valid data.  The library will free these when
+required so if the application wants to keep these around, increment
+their reference counts.  If 0 is returned, no client cert is
+available.  If -1 is returned, it is assumed that the callback needs
+to be called again at a later point in time.  SSL_connect will return
+-1 and SSL_want_x509_lookup(ssl) returns true.  Remember that
+application data can be attached to an SSL structure via the
+SSL_set_app_data(SSL *ssl,char *data) call.
+
+--------------------------
+The X509 library.
+
+int X509_cert_verify(CERTIFICATE_CTX *ctx,X509 *xs, int (*cb)(),
+       int *error,char *arg,STACK *cert_chain);
+int verify_callback(int ok,X509 *xs,X509 *xi,int depth,int error,char *arg,
+       STACK *cert_chain);
+
+X509_cert_verify() is used to authenticate X509 certificates.  The 'ctx' holds
+the details of the various caches and files used to locate certificates.
+'xs' is the certificate to verify and 'cb' is the application callback (more
+detail later).  'error' will be set to the error code and 'arg' is passed
+to the 'cb' callback.  Look at the VERIFY_* defines in crypto/x509/x509.h
+
+When ever X509_cert_verify() makes a 'negative' decision about a
+certitificate, the callback is called.  If everything checks out, the
+callback is called with 'VERIFY_OK' or 'VERIFY_ROOT_OK' (for a self
+signed cert that is not the passed certificate).
+
+The callback is passed the X509_cert_verify opinion of the certificate 
+in 'ok', the certificate in 'xs', the issuer certificate in 'xi',
+the 'depth' of the certificate in the verification 'chain', the
+VERIFY_* code in 'error' and the argument passed to X509_cert_verify()
+in 'arg'. cert_chain is a list of extra certs to use if they are not
+in the cache.
+
+The callback can be used to look at the error reason, and then return 0
+for an 'error' or '1' for ok.  This will override the X509_cert_verify()
+opinion of the certificates validity.  Processing will continue depending on
+the return value.  If one just wishes to use the callback for informational
+reason, just return the 'ok' parameter.
+
+--------------------------
+The BN and DH library.
+
+BIGNUM *BN_generate_prime(int bits,int strong,BIGNUM *add,
+       BIGNUM *rem,void (*callback)(int,int));
+int BN_is_prime(BIGNUM *p,int nchecks,void (*callback)(int,int),
+
+Read doc/bn.doc for the description of these 2.
+
+DH *DH_generate_parameters(int prime_len,int generator,
+       void (*callback)(int,int));
+Read doc/bn.doc for the description of the callback, since it is just passed
+to BN_generate_prime(), except that it is also called as
+callback(3,0) by this function.
+
+--------------------------
+The CRYPTO library.
+
+void CRYPTO_set_locking_callback(void (*func)(int mode,int type,char *file,
+       int line));
+void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,
+       int type,char *file, int line));
+void CRYPTO_set_id_callback(unsigned long (*func)(void));
+
+Read threads.doc for info on these ones.
+
+
+==== cipher.doc ========================================================
+
+The Cipher subroutines.
+
+These routines require "evp.h" to be included.
+
+These functions are a higher level interface to the various cipher
+routines found in this library.  As such, they allow the same code to be
+used to encrypt and decrypt via different ciphers with only a change
+in an initial parameter.  These routines also provide buffering for block
+ciphers.
+
+These routines all take a pointer to the following structure to specify
+which cipher to use.  If you wish to use a new cipher with these routines,
+you would probably be best off looking an how an existing cipher is
+implemented and copying it.  At this point in time, I'm not going to go
+into many details.  This structure should be considered opaque
+
+typedef struct pem_cipher_st
+       {
+       int type;
+       int block_size;
+       int key_len;
+       int iv_len;
+       void (*enc_init)();     /* init for encryption */
+       void (*dec_init)();     /* init for decryption */
+       void (*do_cipher)();    /* encrypt data */
+       } EVP_CIPHER;
+       
+The type field is the object NID of the cipher type
+(read the section on Objects for an explanation of what a NID is).
+The cipher block_size is how many bytes need to be passed
+to the cipher at a time.  Key_len is the
+length of the key the cipher requires and iv_len is the length of the
+initialisation vector required.  enc_init is the function
+called to initialise the ciphers context for encryption and dec_init is the
+function to initialise for decryption (they need to be different, especially
+for the IDEA cipher).
+
+One reason for specifying the Cipher via a pointer to a structure
+is that if you only use des-cbc, only the des-cbc routines will
+be included when you link the program.  If you passed an integer
+that specified which cipher to use, the routine that mapped that
+integer to a set of cipher functions would cause all the ciphers
+to be link into the code.  This setup also allows new ciphers
+to be added by the application (with some restrictions).
+
+The thirteen ciphers currently defined in this library are
+
+EVP_CIPHER *EVP_des_ecb();     /* DES in ecb mode,     iv=0, block=8, key= 8 */
+EVP_CIPHER *EVP_des_ede();     /* DES in ecb ede mode, iv=0, block=8, key=16 */
+EVP_CIPHER *EVP_des_ede3();    /* DES in ecb ede mode, iv=0, block=8, key=24 */
+EVP_CIPHER *EVP_des_cfb();     /* DES in cfb mode,     iv=8, block=1, key= 8 */
+EVP_CIPHER *EVP_des_ede_cfb(); /* DES in ede cfb mode, iv=8, block=1, key=16 */
+EVP_CIPHER *EVP_des_ede3_cfb();/* DES in ede cfb mode, iv=8, block=1, key=24 */
+EVP_CIPHER *EVP_des_ofb();     /* DES in ofb mode,     iv=8, block=1, key= 8 */
+EVP_CIPHER *EVP_des_ede_ofb(); /* DES in ede ofb mode, iv=8, block=1, key=16 */
+EVP_CIPHER *EVP_des_ede3_ofb();/* DES in ede ofb mode, iv=8, block=1, key=24 */
+EVP_CIPHER *EVP_des_cbc();     /* DES in cbc mode,     iv=8, block=8, key= 8 */
+EVP_CIPHER *EVP_des_ede_cbc(); /* DES in cbc ede mode, iv=8, block=8, key=16 */
+EVP_CIPHER *EVP_des_ede3_cbc();/* DES in cbc ede mode, iv=8, block=8, key=24 */
+EVP_CIPHER *EVP_desx_cbc();    /* DES in desx cbc mode,iv=8, block=8, key=24 */
+EVP_CIPHER *EVP_rc4();         /* RC4,                 iv=0, block=1, key=16 */
+EVP_CIPHER *EVP_idea_ecb();    /* IDEA in ecb mode,    iv=0, block=8, key=16 */
+EVP_CIPHER *EVP_idea_cfb();    /* IDEA in cfb mode,    iv=8, block=1, key=16 */
+EVP_CIPHER *EVP_idea_ofb();    /* IDEA in ofb mode,    iv=8, block=1, key=16 */
+EVP_CIPHER *EVP_idea_cbc();    /* IDEA in cbc mode,    iv=8, block=8, key=16 */
+EVP_CIPHER *EVP_rc2_ecb();     /* RC2 in ecb mode,     iv=0, block=8, key=16 */
+EVP_CIPHER *EVP_rc2_cfb();     /* RC2 in cfb mode,     iv=8, block=1, key=16 */
+EVP_CIPHER *EVP_rc2_ofb();     /* RC2 in ofb mode,     iv=8, block=1, key=16 */
+EVP_CIPHER *EVP_rc2_cbc();     /* RC2 in cbc mode,     iv=8, block=8, key=16 */
+EVP_CIPHER *EVP_bf_ecb();      /* Blowfish in ecb mode,iv=0, block=8, key=16 */
+EVP_CIPHER *EVP_bf_cfb();      /* Blowfish in cfb mode,iv=8, block=1, key=16 */
+EVP_CIPHER *EVP_bf_ofb();      /* Blowfish in ofb mode,iv=8, block=1, key=16 */
+EVP_CIPHER *EVP_bf_cbc();      /* Blowfish in cbc mode,iv=8, block=8, key=16 */
+
+The meaning of the compound names is as follows.
+des    The base cipher is DES.
+idea   The base cipher is IDEA
+rc4    The base cipher is RC4-128
+rc2    The base cipher is RC2-128
+ecb    Electronic Code Book form of the cipher.
+cbc    Cipher Block Chaining form of the cipher.
+cfb    64 bit Cipher Feedback form of the cipher.
+ofb    64 bit Output Feedback form of the cipher.
+ede    The cipher is used in Encrypt, Decrypt, Encrypt mode.  The first
+       and last keys are the same.
+ede3   The cipher is used in Encrypt, Decrypt, Encrypt mode.
+
+All the Cipher routines take a EVP_CIPHER_CTX pointer as an argument.
+The state of the cipher is kept in this structure.
+
+typedef struct EVP_CIPHER_Ctx_st
+       {
+       EVP_CIPHER *cipher;
+       int encrypt;            /* encrypt or decrypt */
+       int buf_len;            /* number we have left */
+       unsigned char buf[8];
+       union   {
+               .... /* cipher specific stuff */
+               } c;
+       } EVP_CIPHER_CTX;
+
+Cipher is a pointer the the EVP_CIPHER for the current context.  The encrypt
+flag indicates encryption or decryption.  buf_len is the number of bytes
+currently being held in buf.
+The 'c' union holds the cipher specify context.
+
+The following functions are to be used.
+
+int EVP_read_pw_string(
+char *buf,
+int len,
+char *prompt,
+int verify,
+       This function is the same as des_read_pw_string() (des.doc).
+
+void EVP_set_pw_prompt(char *prompt);
+       This function sets the 'default' prompt to use to use in
+       EVP_read_pw_string when the prompt parameter is NULL.  If the
+       prompt parameter is NULL, this 'default prompt' feature is turned
+       off.  Be warned, this is a global variable so weird things
+       will happen if it is used under Win16 and care must be taken
+       with a multi-threaded version of the library.
+
+char *EVP_get_pw_prompt();
+       This returns a pointer to the default prompt string.  NULL
+       if it is not set.
+
+int EVP_BytesToKey(
+EVP_CIPHER *type,
+EVP_MD *md,
+unsigned char *salt,
+unsigned char *data,
+int datal,
+int count,
+unsigned char *key,
+unsigned char *iv);
+       This function is used to generate a key and an initialisation vector
+       for a specified cipher from a key string and a salt.  Type
+       specifies the cipher the 'key' is being generated for.  Md is the
+       message digest algorithm to use to generate the key and iv.  The salt
+       is an optional 8 byte object that is used to help seed the key
+       generator.
+       If the salt value is NULL, it is just not used.  Datal is the
+       number of bytes to use from 'data' in the key generation.  
+       This function returns the key size for the specified cipher, if
+       data is NULL, this value is returns and no other
+       computation is performed.  Count is
+       the number of times to loop around the key generator.  I would
+       suggest leaving it's value as 1.  Key and iv are the structures to
+       place the returning iv and key in.  If they are NULL, no value is
+       generated for that particular value.
+       The algorithm used is as follows
+       
+       /* M[] is an array of message digests
+        * MD() is the message digest function */
+       M[0]=MD(data . salt);
+       for (i=1; i<count; i++) M[0]=MD(M[0]);
+
+       i=1
+       while (data still needed for key and iv)
+               {
+               M[i]=MD(M[i-1] . data . salt);
+               for (i=1; i<count; i++) M[i]=MD(M[i]);
+               i++;
+               }
+
+       If the salt is NULL, it is not used.
+       The digests are concatenated together.
+       M = M[0] . M[1] . M[2] .......
+
+       For key= 8, iv=8 => key=M[0.. 8], iv=M[ 9 .. 16].
+       For key=16, iv=0 => key=M[0..16].
+       For key=16, iv=8 => key=M[0..16], iv=M[17 .. 24].
+       For key=24, iv=8 => key=M[0..24], iv=M[25 .. 32].
+
+       This routine will produce DES-CBC keys and iv that are compatible
+       with the PKCS-5 standard when md2 or md5 are used.  If md5 is
+       used, the salt is NULL and count is 1, this routine will produce
+       the password to key mapping normally used with RC4.
+       I have attempted to logically extend the PKCS-5 standard to
+       generate keys and iv for ciphers that require more than 16 bytes,
+       if anyone knows what the correct standard is, please inform me.
+       When using sha or sha1, things are a bit different under this scheme,
+       since sha produces a 20 byte digest.  So for ciphers requiring
+       24 bits of data, 20 will come from the first MD and 4 will
+       come from the second.
+
+       I have considered having a separate function so this 'routine'
+       can be used without the requirement of passing a EVP_CIPHER *,
+       but I have decided to not bother.  If you wish to use the
+       function without official EVP_CIPHER structures, just declare
+       a local one and set the key_len and iv_len fields to the
+       length you desire.
+
+The following routines perform encryption and decryption 'by parts'.  By
+this I mean that there are groups of 3 routines.  An Init function that is
+used to specify a cipher and initialise data structures.  An Update routine
+that does encryption/decryption, one 'chunk' at a time.  And finally a
+'Final' function that finishes the encryption/decryption process.
+All these functions take a EVP_CIPHER pointer to specify which cipher to
+encrypt/decrypt with.  They also take a EVP_CIPHER_CTX object as an
+argument.  This structure is used to hold the state information associated
+with the operation in progress.
+
+void EVP_EncryptInit(
+EVP_CIPHER_CTX *ctx,
+EVP_CIPHER *type,
+unsigned char *key,
+unsigned char *iv);
+       This function initialise a EVP_CIPHER_CTX for encryption using the
+       cipher passed in the 'type' field.  The cipher is initialised to use
+       'key' as the key and 'iv' for the initialisation vector (if one is
+       required).  If the type, key or iv is NULL, the value currently in the
+       EVP_CIPHER_CTX is reused.  So to perform several decrypt
+       using the same cipher, key and iv, initialise with the cipher,
+       key and iv the first time and then for subsequent calls,
+       reuse 'ctx' but pass NULL for type, key and iv.  You must make sure
+       to pass a key that is large enough for a particular cipher.  I
+       would suggest using the EVP_BytesToKey() function.
+
+void EVP_EncryptUpdate(
+EVP_CIPHER_CTX *ctx,
+unsigned char *out,
+int *outl,
+unsigned char *in,
+int inl);
+       This function takes 'inl' bytes from 'in' and outputs bytes
+       encrypted by the cipher 'ctx' was initialised with into 'out'.  The
+       number of bytes written to 'out' is put into outl.  If a particular
+       cipher encrypts in blocks, less or more bytes than input may be
+       output.  Currently the largest block size used by supported ciphers
+       is 8 bytes, so 'out' should have room for 'inl+7' bytes.  Normally
+       EVP_EncryptInit() is called once, followed by lots and lots of
+       calls to EVP_EncryptUpdate, followed by a single EVP_EncryptFinal
+       call.
+
+void EVP_EncryptFinal(
+EVP_CIPHER_CTX *ctx,
+unsigned char *out,
+int *outl);
+       Because quite a large number of ciphers are block ciphers, there is
+       often an incomplete block to write out at the end of the
+       encryption.  EVP_EncryptFinal() performs processing on this last
+       block.  The last block in encoded in such a way that it is possible
+       to determine how many bytes in the last block are valid.  For 8 byte
+       block size ciphers, if only 5 bytes in the last block are valid, the
+       last three bytes will be filled with the value 3.  If only 2 were
+       valid, the other 6 would be filled with sixes.  If all 8 bytes are
+       valid, a extra 8 bytes are appended to the cipher stream containing
+       nothing but 8 eights.  These last bytes are output into 'out' and
+       the number of bytes written is put into 'outl'  These last bytes
+       are output into 'out' and the number of bytes written is put into
+       'outl'.  This form of block cipher finalisation is compatible with
+       PKCS-5.  Please remember that even if you are using ciphers like
+       RC4 that has no blocking and so the function will not write
+       anything into 'out', it would still be a good idea to pass a
+       variable for 'out' that can hold 8 bytes just in case the cipher is
+       changed some time in the future.  It should also be remembered
+       that the EVP_CIPHER_CTX contains the password and so when one has
+       finished encryption with a particular EVP_CIPHER_CTX, it is good
+       practice to zero the structure 
+       (ie. memset(ctx,0,sizeof(EVP_CIPHER_CTX)).
+       
+void EVP_DecryptInit(
+EVP_CIPHER_CTX *ctx,
+EVP_CIPHER *type,
+unsigned char *key,
+unsigned char *iv);
+       This function is basically the same as EVP_EncryptInit() accept that
+       is prepares the EVP_CIPHER_CTX for decryption.
+
+void EVP_DecryptUpdate(
+EVP_CIPHER_CTX *ctx,
+unsigned char *out,
+int *outl,
+unsigned char *in,
+int inl);
+       This function is basically the same as EVP_EncryptUpdate()
+       except that it performs decryption.  There is one
+       fundamental difference though.  'out' can not be the same as
+       'in' for any ciphers with a block size greater than 1 if more
+       than one call to EVP_DecryptUpdate() will be made.  This
+       is because this routine can hold a 'partial' block between
+       calls.  When a partial block is decrypted (due to more bytes
+       being passed via this function, they will be written to 'out'
+       overwriting the input bytes in 'in' that have not been read
+       yet.  From this it should also be noted that 'out' should
+       be at least one 'block size' larger than 'inl'.  This problem
+       only occurs on the second and subsequent call to
+       EVP_DecryptUpdate() when using a block cipher.
+
+int EVP_DecryptFinal(
+EVP_CIPHER_CTX *ctx,
+unsigned char *out,
+int *outl);
+       This function is different to EVP_EncryptFinal in that it 'removes'
+       any padding bytes appended when the data was encrypted.  Due to the
+       way in which 1 to 8 bytes may have been appended when encryption
+       using a block cipher, 'out' can end up with 0 to 7 bytes being put
+       into it.  When decoding the padding bytes, it is possible to detect
+       an incorrect decryption.  If the decryption appears to be wrong, 0
+       is returned.  If everything seems ok, 1 is returned.  For ciphers
+       with a block size of 1 (RC4), this function would normally not
+       return any bytes and would always return 1.  Just because this
+       function returns 1 does not mean the decryption was correct. It
+       would normally be wrong due to either the wrong key/iv or
+       corruption of the cipher data fed to EVP_DecryptUpdate().
+       As for EVP_EncryptFinal, it is a good idea to zero the
+       EVP_CIPHER_CTX after use since the structure contains the key used
+       to decrypt the data.
+       
+The following Cipher routines are convenience routines that call either
+EVP_EncryptXxx or EVP_DecryptXxx depending on weather the EVP_CIPHER_CTX
+was setup to encrypt or decrypt.  
+
+void EVP_CipherInit(
+EVP_CIPHER_CTX *ctx,
+EVP_CIPHER *type,
+unsigned char *key,
+unsigned char *iv,
+int enc);
+       This function take arguments that are the same as EVP_EncryptInit()
+       and EVP_DecryptInit() except for the extra 'enc' flag.  If 1, the
+       EVP_CIPHER_CTX is setup for encryption, if 0, decryption.
+
+void EVP_CipherUpdate(
+EVP_CIPHER_CTX *ctx,
+unsigned char *out,
+int *outl,
+unsigned char *in,
+int inl);
+       Again this function calls either EVP_EncryptUpdate() or
+       EVP_DecryptUpdate() depending on state in the 'ctx' structure.
+       As noted for EVP_DecryptUpdate(), when this routine is used
+       for decryption with block ciphers, 'out' should not be the
+       same as 'in'.
+
+int EVP_CipherFinal(
+EVP_CIPHER_CTX *ctx,
+unsigned char *outm,
+int *outl);
+       This routine call EVP_EncryptFinal() or EVP_DecryptFinal()
+       depending on the state information in 'ctx'.  1 is always returned
+       if the mode is encryption, otherwise the return value is the return
+       value of EVP_DecryptFinal().
+
+==== cipher.m ========================================================
+
+Date: Tue, 15 Oct 1996 08:16:14 +1000 (EST)
+From: Eric Young <eay@mincom.com>
+X-Sender: eay@orb
+To: Roland Haring <rharing@tandem.cl>
+Cc: ssl-users@mincom.com
+Subject: Re: Symmetric encryption with ssleay
+In-Reply-To: <m0vBpyq-00001aC@tandemnet.tandem.cl>
+Message-Id: <Pine.SOL.3.91.961015075623.11394A-100000@orb>
+Mime-Version: 1.0
+Content-Type: TEXT/PLAIN; charset=US-ASCII
+Sender: ssl-lists-owner@mincom.com
+Precedence: bulk
+Status: RO
+X-Status: 
+
+On Fri, 11 Oct 1996, Roland Haring wrote:
+> THE_POINT:
+>      Would somebody be so kind to give me the minimum basic 
+>      calls I need to do to libcrypto.a to get some text encrypted
+>      and decrypted again? ...hopefully with code included to do
+>      base64 encryption and decryption ... e.g. that sign-it.c code
+>      posted some while ago was a big help :-) (please, do not point
+>      me to apps/enc.c where I suspect my Heissenbug to be hidden :-)
+
+Ok, the base64 encoding stuff in 'enc.c' does the wrong thing sometimes 
+when the data is less than a line long (this is for decoding).  I'll dig 
+up the exact fix today and post it.  I am taking longer on 0.6.5 than I 
+intended so I'll just post this patch.
+
+The documentation to read is in
+doc/cipher.doc,
+doc/encode.doc (very sparse :-).
+and perhaps
+doc/digest.doc,
+
+The basic calls to encrypt with say triple DES are
+
+Given
+char key[EVP_MAX_KEY_LENGTH];
+char iv[EVP_MAX_IV_LENGTH];
+EVP_CIPHER_CTX ctx;
+unsigned char out[512+8];
+int outl;
+
+/* optional generation of key/iv data from text password using md5
+ * via an upward compatable verson of PKCS#5. */
+EVP_BytesToKey(EVP_des_ede3_cbc,EVP_md5,NULL,passwd,strlen(passwd),
+       key,iv);
+
+/* Initalise the EVP_CIPHER_CTX */
+EVP_EncryptInit(ctx,EVP_des_ede3_cbc,key,iv);
+
+while (....)
+       {
+       /* This is processing 512 bytes at a time, the bytes are being
+        * copied into 'out', outl bytes are output.  'out' should not be the
+        * same as 'in' for reasons mentioned in the documentation. */
+       EVP_EncryptUpdate(ctx,out,&outl,in,512);
+       }
+
+/* Output the last 'block'.  If the cipher is a block cipher, the last
+ * block is encoded in such a way so that a wrong decryption will normally be
+ * detected - again, one of the PKCS standards. */
+
+EVP_EncryptFinal(ctx,out,&outl);
+
+To decrypt, use the EVP_DecryptXXXXX functions except that EVP_DecryptFinal()
+will return 0 if the decryption fails (only detectable on block ciphers).
+
+You can also use
+EVP_CipherInit()
+EVP_CipherUpdate()
+EVP_CipherFinal()
+which does either encryption or decryption depending on an extra 
+parameter to EVP_CipherInit().
+
+
+To do the base64 encoding,
+EVP_EncodeInit()
+EVP_EncodeUpdate()
+EVP_EncodeFinal()
+
+EVP_DecodeInit()
+EVP_DecodeUpdate()
+EVP_DecodeFinal()
+
+where the encoding is quite simple, but the decoding can be a bit more 
+fun (due to dud input).
+
+EVP_DecodeUpdate() returns -1 for an error on an input line, 0 if the 
+'last line' was just processed, and 1 if more lines should be submitted.
+
+EVP_DecodeFinal() returns -1 for an error or 1 if things are ok.
+
+So the loop becomes
+EVP_DecodeInit(....)
+for (;;)
+       {
+       i=EVP_DecodeUpdate(....);
+       if (i < 0) goto err;
+
+       /* process the data */
+
+       if (i == 0) break;
+       }
+EVP_DecodeFinal(....);
+/* process the data */
+
+The problem in 'enc.c' is that I was stuff the processing up after the 
+EVP_DecodeFinal(...) when the for(..) loop was not being run (one line of 
+base64 data) and this was because 'enc.c' tries to scan over a file until
+it hits the first valid base64 encoded line.
+
+hope this helps a bit.
+eric
+--
+Eric Young                  | BOOL is tri-state according to Bill Gates.
+AARNet: eay@mincom.oz.au    | RTFM Win32 GetMessage().
+
+==== conf.doc ========================================================
+
+The CONF library.
+
+The CONF library is a simple set of routines that can be used to configure
+programs.  It is a superset of the genenv() function with some extra
+structure.
+
+The library consists of 5 functions.
+
+LHASH *CONF_load(LHASH *config,char *file);
+This function is called to load in a configuration file.  Multiple
+configuration files can be loaded, with each subsequent 'load' overwriting
+any already defined 'variables'.  If there is an error, NULL is returned.
+If config is NULL, a new LHASH structure is created and returned, otherwise
+the new data in the 'file' is loaded into the 'config' structure.
+
+void CONF_free(LHASH *config);
+This function free()s the data in config.
+
+char *CONF_get_string(LHASH *config,char *section,char *name);
+This function returns the string found in 'config' that corresponds to the
+'section' and 'name' specified.  Classes and the naming system used will be
+discussed later in this document.  If the variable is not defined, an NULL
+is returned.
+
+long CONF_get_long(LHASH *config,char *section, char *name);
+This function is the same as CONF_get_string() except that it converts the
+string to an long and returns it.  If variable is not a number or the
+variable does not exist, 0 is returned.  This is a little problematic but I
+don't know of a simple way around it.
+
+STACK *CONF_get_section(LHASH *config, char *section);
+This function returns a 'stack' of CONF_VALUE items that are all the
+items defined in a particular section.  DO NOT free() any of the
+variable returned.  They will disappear when CONF_free() is called.
+
+The 'lookup' model.
+The configuration file is divided into 'sections'.  Each section is started by
+a line of the form '[ section ]'.  All subsequent variable definitions are
+of this section.  A variable definition is a simple alpha-numeric name
+followed by an '=' and then the data.  A section or variable name can be
+described by a regular expression of the following form '[A-Za-z0-9_]+'.
+The value of the variable is the text after the '=' until the end of the
+line, stripped of leading and trailing white space.
+At this point I should mention that a '#' is a comment character, \ is the
+escape character, and all three types of quote can be used to stop any
+special interpretation of the data.
+Now when the data is being loaded, variable expansion can occur.  This is
+done by expanding any $NAME sequences into the value represented by the
+variable NAME.  If the variable is not in the current section, the different
+section can be specified by using the $SECTION::NAME form.  The ${NAME} form
+also works and is very useful for expanding variables inside strings.
+
+When a variable is looked up, there are 2 special section. 'default', which
+is the initial section, and 'ENV' which is the processes environment
+variables (accessed via getenv()).  When a variable is looked up, it is
+first 'matched' with it's section (if one was specified), if this fails, the
+'default' section is matched.
+If the 'lhash' variable passed was NULL, the environment is searched.
+
+Now why do we bother with sections?  So we can have multiple programs using
+the same configuration file, or multiple instances of the same program
+using different variables.  It also provides a nice mechanism to override
+the processes environment variables (eg ENV::HOME=/tmp).  If there is a
+program specific variable missing, we can have default values.
+Multiple configuration files can be loaded, with each new value clearing
+any predefined values.  A system config file can provide 'default' values,
+and application/usr specific files can provide overriding values.
+
+Examples
+
+# This is a simple example
+SSLEAY_HOME    = /usr/local/ssl
+ENV::PATH      = $SSLEAY_HOME/bin:$PATH        # override my path
+
+[X509]
+cert_dir       = $SSLEAY_HOME/certs    # /usr/local/ssl/certs
+
+[SSL]
+CIPHER         = DES-EDE-MD5:RC4-MD5
+USER_CERT      = $HOME/${USER}di'r 5'  # /home/eay/eaydir 5
+USER_CERT      = $HOME/\${USER}di\'r   # /home/eay/${USER}di'r
+USER_CERT      = "$HOME/${US"ER}di\'r  # $HOME/${USER}di'r
+
+TEST           = 1234\
+5678\
+9ab                                    # TEST=123456789ab
+TTT            = 1234\n\n              # TTT=1234<nl><nl>
+
+
+
+==== des.doc ========================================================
+
+The DES library.
+
+Please note that this library was originally written to operate with
+eBones, a version of Kerberos that had had encryption removed when it left
+the USA and then put back in.  As such there are some routines that I will
+advise not using but they are still in the library for historical reasons.
+For all calls that have an 'input' and 'output' variables, they can be the
+same.
+
+This library requires the inclusion of 'des.h'.
+
+All of the encryption functions take what is called a des_key_schedule as an 
+argument.  A des_key_schedule is an expanded form of the des key.
+A des_key is 8 bytes of odd parity, the type used to hold the key is a
+des_cblock.  A des_cblock is an array of 8 bytes, often in this library
+description I will refer to input bytes when the function specifies
+des_cblock's as input or output, this just means that the variable should
+be a multiple of 8 bytes.
+
+The define DES_ENCRYPT is passed to specify encryption, DES_DECRYPT to
+specify decryption.  The functions and global variable are as follows:
+
+int des_check_key;
+       DES keys are supposed to be odd parity.  If this variable is set to
+       a non-zero value, des_set_key() will check that the key has odd
+       parity and is not one of the known weak DES keys.  By default this
+       variable is turned off;
+       
+void des_set_odd_parity(
+des_cblock *key );
+       This function takes a DES key (8 bytes) and sets the parity to odd.
+       
+int des_is_weak_key(
+des_cblock *key );
+       This function returns a non-zero value if the DES key passed is a
+       weak, DES key.  If it is a weak key, don't use it, try a different
+       one.  If you are using 'random' keys, the chances of hitting a weak
+       key are 1/2^52 so it is probably not worth checking for them.
+       
+int des_set_key(
+des_cblock *key,
+des_key_schedule schedule);
+       Des_set_key converts an 8 byte DES key into a des_key_schedule.
+       A des_key_schedule is an expanded form of the key which is used to
+       perform actual encryption.  It can be regenerated from the DES key
+       so it only needs to be kept when encryption or decryption is about
+       to occur.  Don't save or pass around des_key_schedule's since they
+       are CPU architecture dependent, DES keys are not.  If des_check_key
+       is non zero, zero is returned if the key has the wrong parity or
+       the key is a weak key, else 1 is returned.
+       
+int des_key_sched(
+des_cblock *key,
+des_key_schedule schedule);
+       An alternative name for des_set_key().
+
+int des_rw_mode;               /* defaults to DES_PCBC_MODE */
+       This flag holds either DES_CBC_MODE or DES_PCBC_MODE (default).
+       This specifies the function to use in the enc_read() and enc_write()
+       functions.
+
+void des_encrypt(
+unsigned long *data,
+des_key_schedule ks,
+int enc);
+       This is the DES encryption function that gets called by just about
+       every other DES routine in the library.  You should not use this
+       function except to implement 'modes' of DES.  I say this because the
+       functions that call this routine do the conversion from 'char *' to
+       long, and this needs to be done to make sure 'non-aligned' memory
+       access do not occur.  The characters are loaded 'little endian',
+       have a look at my source code for more details on how I use this
+       function.
+       Data is a pointer to 2 unsigned long's and ks is the
+       des_key_schedule to use.  enc, is non zero specifies encryption,
+       zero if decryption.
+
+void des_encrypt2(
+unsigned long *data,
+des_key_schedule ks,
+int enc);
+       This functions is the same as des_encrypt() except that the DES
+       initial permutation (IP) and final permutation (FP) have been left
+       out.  As for des_encrypt(), you should not use this function.
+       It is used by the routines in my library that implement triple DES.
+       IP() des_encrypt2() des_encrypt2() des_encrypt2() FP() is the same
+       as des_encrypt() des_encrypt() des_encrypt() except faster :-).
+
+void des_ecb_encrypt(
+des_cblock *input,
+des_cblock *output,
+des_key_schedule ks,
+int enc);
+       This is the basic Electronic Code Book form of DES, the most basic
+       form.  Input is encrypted into output using the key represented by
+       ks.  If enc is non zero (DES_ENCRYPT), encryption occurs, otherwise
+       decryption occurs.  Input is 8 bytes long and output is 8 bytes.
+       (the des_cblock structure is 8 chars).
+       
+void des_ecb3_encrypt(
+des_cblock *input,
+des_cblock *output,
+des_key_schedule ks1,
+des_key_schedule ks2,
+des_key_schedule ks3,
+int enc);
+       This is the 3 key EDE mode of ECB DES.  What this means is that 
+       the 8 bytes of input is encrypted with ks1, decrypted with ks2 and
+       then encrypted again with ks3, before being put into output;
+       C=E(ks3,D(ks2,E(ks1,M))).  There is a macro, des_ecb2_encrypt()
+       that only takes 2 des_key_schedules that implements,
+       C=E(ks1,D(ks2,E(ks1,M))) in that the final encrypt is done with ks1.
+       
+void des_cbc_encrypt(
+des_cblock *input,
+des_cblock *output,
+long length,
+des_key_schedule ks,
+des_cblock *ivec,
+int enc);
+       This routine implements DES in Cipher Block Chaining mode.
+       Input, which should be a multiple of 8 bytes is encrypted
+       (or decrypted) to output which will also be a multiple of 8 bytes.
+       The number of bytes is in length (and from what I've said above,
+       should be a multiple of 8).  If length is not a multiple of 8, I'm
+       not being held responsible :-).  ivec is the initialisation vector.
+       This function does not modify this variable.  To correctly implement
+       cbc mode, you need to do one of 2 things; copy the last 8 bytes of
+       cipher text for use as the next ivec in your application,
+       or use des_ncbc_encrypt(). 
+       Only this routine has this problem with updating the ivec, all
+       other routines that are implementing cbc mode update ivec.
+       
+void des_ncbc_encrypt(
+des_cblock *input,
+des_cblock *output,
+long length,
+des_key_schedule sk,
+des_cblock *ivec,
+int enc);
+       For historical reasons, des_cbc_encrypt() did not update the
+       ivec with the value requires so that subsequent calls to
+       des_cbc_encrypt() would 'chain'.  This was needed so that the same
+       'length' values would not need to be used when decrypting.
+       des_ncbc_encrypt() does the right thing.  It is the same as
+       des_cbc_encrypt accept that ivec is updates with the correct value
+       to pass in subsequent calls to des_ncbc_encrypt().  I advise using
+       des_ncbc_encrypt() instead of des_cbc_encrypt();
+
+void des_xcbc_encrypt(
+des_cblock *input,
+des_cblock *output,
+long length,
+des_key_schedule sk,
+des_cblock *ivec,
+des_cblock *inw,
+des_cblock *outw,
+int enc);
+       This is RSA's DESX mode of DES.  It uses inw and outw to
+       'whiten' the encryption.  inw and outw are secret (unlike the iv)
+       and are as such, part of the key.  So the key is sort of 24 bytes.
+       This is much better than cbc des.
+       
+void des_3cbc_encrypt(
+des_cblock *input,
+des_cblock *output,
+long length,
+des_key_schedule sk1,
+des_key_schedule sk2,
+des_cblock *ivec1,
+des_cblock *ivec2,
+int enc);
+       This function is flawed, do not use it.  I have left it in the
+       library because it is used in my des(1) program and will function
+       correctly when used by des(1).  If I removed the function, people
+       could end up unable to decrypt files.
+       This routine implements outer triple cbc encryption using 2 ks and
+       2 ivec's.  Use des_ede2_cbc_encrypt() instead.
+       
+void des_ede3_cbc_encrypt(
+des_cblock *input,
+des_cblock *output, 
+long length,
+des_key_schedule ks1,
+des_key_schedule ks2, 
+des_key_schedule ks3, 
+des_cblock *ivec,
+int enc);
+       This function implements outer triple CBC DES encryption with 3
+       keys.  What this means is that each 'DES' operation
+       inside the cbc mode is really an C=E(ks3,D(ks2,E(ks1,M))).
+       Again, this is cbc mode so an ivec is requires.
+       This mode is used by SSL.
+       There is also a des_ede2_cbc_encrypt() that only uses 2
+       des_key_schedule's, the first being reused for the final
+       encryption.  C=E(ks1,D(ks2,E(ks1,M))).  This form of triple DES
+       is used by the RSAref library.
+       
+void des_pcbc_encrypt(
+des_cblock *input,
+des_cblock *output,
+long length,
+des_key_schedule ks,
+des_cblock *ivec,
+int enc);
+       This is Propagating Cipher Block Chaining mode of DES.  It is used
+       by Kerberos v4.  It's parameters are the same as des_ncbc_encrypt().
+       
+void des_cfb_encrypt(
+unsigned char *in,
+unsigned char *out,
+int numbits,
+long length,
+des_key_schedule ks,
+des_cblock *ivec,
+int enc);
+       Cipher Feedback Back mode of DES.  This implementation 'feeds back'
+       in numbit blocks.  The input (and output) is in multiples of numbits
+       bits.  numbits should to be a multiple of 8 bits.  Length is the
+       number of bytes input.  If numbits is not a multiple of 8 bits,
+       the extra bits in the bytes will be considered padding.  So if
+       numbits is 12, for each 2 input bytes, the 4 high bits of the
+       second byte will be ignored.  So to encode 72 bits when using
+       a numbits of 12 take 12 bytes.  To encode 72 bits when using
+       numbits of 9 will take 16 bytes.  To encode 80 bits when using
+       numbits of 16 will take 10 bytes. etc, etc.  This padding will
+       apply to both input and output.
+
+       
+void des_cfb64_encrypt(
+unsigned char *in,
+unsigned char *out,
+long length,
+des_key_schedule ks,
+des_cblock *ivec,
+int *num,
+int enc);
+       This is one of the more useful functions in this DES library, it
+       implements CFB mode of DES with 64bit feedback.  Why is this
+       useful you ask?  Because this routine will allow you to encrypt an
+       arbitrary number of bytes, no 8 byte padding.  Each call to this
+       routine will encrypt the input bytes to output and then update ivec
+       and num.  num contains 'how far' we are though ivec.  If this does
+       not make much sense, read more about cfb mode of DES :-).
+       
+void des_ede3_cfb64_encrypt(
+unsigned char *in,
+unsigned char *out,
+long length,
+des_key_schedule ks1,
+des_key_schedule ks2,
+des_key_schedule ks3,
+des_cblock *ivec,
+int *num,
+int enc);
+       Same as des_cfb64_encrypt() accept that the DES operation is
+       triple DES.  As usual, there is a macro for
+       des_ede2_cfb64_encrypt() which reuses ks1.
+
+void des_ofb_encrypt(
+unsigned char *in,
+unsigned char *out,
+int numbits,
+long length,
+des_key_schedule ks,
+des_cblock *ivec);
+       This is a implementation of Output Feed Back mode of DES.  It is
+       the same as des_cfb_encrypt() in that numbits is the size of the
+       units dealt with during input and output (in bits).
+       
+void des_ofb64_encrypt(
+unsigned char *in,
+unsigned char *out,
+long length,
+des_key_schedule ks,
+des_cblock *ivec,
+int *num);
+       The same as des_cfb64_encrypt() except that it is Output Feed Back
+       mode.
+
+void des_ede3_ofb64_encrypt(
+unsigned char *in,
+unsigned char *out,
+long length,
+des_key_schedule ks1,
+des_key_schedule ks2,
+des_key_schedule ks3,
+des_cblock *ivec,
+int *num);
+       Same as des_ofb64_encrypt() accept that the DES operation is
+       triple DES.  As usual, there is a macro for
+       des_ede2_ofb64_encrypt() which reuses ks1.
+
+int des_read_pw_string(
+char *buf,
+int length,
+char *prompt,
+int verify);
+       This routine is used to get a password from the terminal with echo
+       turned off.  Buf is where the string will end up and length is the
+       size of buf.  Prompt is a string presented to the 'user' and if
+       verify is set, the key is asked for twice and unless the 2 copies
+       match, an error is returned.  A return code of -1 indicates a
+       system error, 1 failure due to use interaction, and 0 is success.
+
+unsigned long des_cbc_cksum(
+des_cblock *input,
+des_cblock *output,
+long length,
+des_key_schedule ks,
+des_cblock *ivec);
+       This function produces an 8 byte checksum from input that it puts in
+       output and returns the last 4 bytes as a long.  The checksum is
+       generated via cbc mode of DES in which only the last 8 byes are
+       kept.  I would recommend not using this function but instead using
+       the EVP_Digest routines, or at least using MD5 or SHA.  This
+       function is used by Kerberos v4 so that is why it stays in the
+       library.
+       
+char *des_fcrypt(
+const char *buf,
+const char *salt
+char *ret);
+       This is my fast version of the unix crypt(3) function.  This version
+       takes only a small amount of space relative to other fast
+       crypt() implementations.  This is different to the normal crypt
+       in that the third parameter is the buffer that the return value
+       is written into.  It needs to be at least 14 bytes long.  This
+       function is thread safe, unlike the normal crypt.
+
+char *crypt(
+const char *buf,
+const char *salt);
+       This function calls des_fcrypt() with a static array passed as the
+       third parameter.  This emulates the normal non-thread safe semantics
+       of crypt(3).
+
+void des_string_to_key(
+char *str,
+des_cblock *key);
+       This function takes str and converts it into a DES key.  I would
+       recommend using MD5 instead and use the first 8 bytes of output.
+       When I wrote the first version of these routines back in 1990, MD5
+       did not exist but I feel these routines are still sound.  This
+       routines is compatible with the one in MIT's libdes.
+       
+void des_string_to_2keys(
+char *str,
+des_cblock *key1,
+des_cblock *key2);
+       This function takes str and converts it into 2 DES keys.
+       I would recommend using MD5 and using the 16 bytes as the 2 keys.
+       I have nothing against these 2 'string_to_key' routines, it's just
+       that if you say that your encryption key is generated by using the
+       16 bytes of an MD5 hash, every-one knows how you generated your
+       keys.
+
+int des_read_password(
+des_cblock *key,
+char *prompt,
+int verify);
+       This routine combines des_read_pw_string() with des_string_to_key().
+
+int des_read_2passwords(
+des_cblock *key1,
+des_cblock *key2,
+char *prompt,
+int verify);
+       This routine combines des_read_pw_string() with des_string_to_2key().
+
+void des_random_seed(
+des_cblock key);
+       This routine sets a starting point for des_random_key().
+       
+void des_random_key(
+des_cblock ret);
+       This function return a random key.  Make sure to 'seed' the random
+       number generator (with des_random_seed()) before using this function.
+       I personally now use a MD5 based random number system.
+
+int des_enc_read(
+int fd,
+char *buf,
+int len,
+des_key_schedule ks,
+des_cblock *iv);
+       This function will write to a file descriptor the encrypted data
+       from buf.  This data will be preceded by a 4 byte 'byte count' and
+       will be padded out to 8 bytes.  The encryption is either CBC of
+       PCBC depending on the value of des_rw_mode.  If it is DES_PCBC_MODE,
+       pcbc is used, if DES_CBC_MODE, cbc is used.  The default is to use
+       DES_PCBC_MODE.
+
+int des_enc_write(
+int fd,
+char *buf,
+int len,
+des_key_schedule ks,
+des_cblock *iv);
+       This routines read stuff written by des_enc_read() and decrypts it.
+       I have used these routines quite a lot but I don't believe they are
+       suitable for non-blocking io.  If you are after a full
+       authentication/encryption over networks, have a look at SSL instead.
+
+unsigned long des_quad_cksum(
+des_cblock *input,
+des_cblock *output,
+long length,
+int out_count,
+des_cblock *seed);
+       This is a function from Kerberos v4 that is not anything to do with
+       DES but was needed.  It is a cksum that is quicker to generate than
+       des_cbc_cksum();  I personally would use MD5 routines now.
+=====
+Modes of DES
+Quite a bit of the following information has been taken from
+       AS 2805.5.2
+       Australian Standard
+       Electronic funds transfer - Requirements for interfaces,
+       Part 5.2: Modes of operation for an n-bit block cipher algorithm
+       Appendix A
+
+There are several different modes in which DES can be used, they are
+as follows.
+
+Electronic Codebook Mode (ECB) (des_ecb_encrypt())
+- 64 bits are enciphered at a time.
+- The order of the blocks can be rearranged without detection.
+- The same plaintext block always produces the same ciphertext block
+  (for the same key) making it vulnerable to a 'dictionary attack'.
+- An error will only affect one ciphertext block.
+
+Cipher Block Chaining Mode (CBC) (des_cbc_encrypt())
+- a multiple of 64 bits are enciphered at a time.
+- The CBC mode produces the same ciphertext whenever the same
+  plaintext is encrypted using the same key and starting variable.
+- The chaining operation makes the ciphertext blocks dependent on the
+  current and all preceding plaintext blocks and therefore blocks can not
+  be rearranged.
+- The use of different starting variables prevents the same plaintext
+  enciphering to the same ciphertext.
+- An error will affect the current and the following ciphertext blocks.
+
+Cipher Feedback Mode (CFB) (des_cfb_encrypt())
+- a number of bits (j) <= 64 are enciphered at a time.
+- The CFB mode produces the same ciphertext whenever the same
+  plaintext is encrypted using the same key and starting variable.
+- The chaining operation makes the ciphertext variables dependent on the
+  current and all preceding variables and therefore j-bit variables are
+  chained together and can not be rearranged.
+- The use of different starting variables prevents the same plaintext
+  enciphering to the same ciphertext.
+- The strength of the CFB mode depends on the size of k (maximal if
+  j == k).  In my implementation this is always the case.
+- Selection of a small value for j will require more cycles through
+  the encipherment algorithm per unit of plaintext and thus cause
+  greater processing overheads.
+- Only multiples of j bits can be enciphered.
+- An error will affect the current and the following ciphertext variables.
+
+Output Feedback Mode (OFB) (des_ofb_encrypt())
+- a number of bits (j) <= 64 are enciphered at a time.
+- The OFB mode produces the same ciphertext whenever the same
+  plaintext enciphered using the same key and starting variable.  More
+  over, in the OFB mode the same key stream is produced when the same
+  key and start variable are used.  Consequently, for security reasons
+  a specific start variable should be used only once for a given key.
+- The absence of chaining makes the OFB more vulnerable to specific attacks.
+- The use of different start variables values prevents the same
+  plaintext enciphering to the same ciphertext, by producing different
+  key streams.
+- Selection of a small value for j will require more cycles through
+  the encipherment algorithm per unit of plaintext and thus cause
+  greater processing overheads.
+- Only multiples of j bits can be enciphered.
+- OFB mode of operation does not extend ciphertext errors in the
+  resultant plaintext output.  Every bit error in the ciphertext causes
+  only one bit to be in error in the deciphered plaintext.
+- OFB mode is not self-synchronising.  If the two operation of
+  encipherment and decipherment get out of synchronism, the system needs
+  to be re-initialised.
+- Each re-initialisation should use a value of the start variable
+ different from the start variable values used before with the same
+ key.  The reason for this is that an identical bit stream would be
+ produced each time from the same parameters.  This would be
+ susceptible to a ' known plaintext' attack.
+
+Triple ECB Mode (des_ecb3_encrypt())
+- Encrypt with key1, decrypt with key2 and encrypt with key3 again.
+- As for ECB encryption but increases the key length to 168 bits.
+  There are theoretic attacks that can be used that make the effective
+  key length 112 bits, but this attack also requires 2^56 blocks of
+  memory, not very likely, even for the NSA.
+- If both keys are the same it is equivalent to encrypting once with
+  just one key.
+- If the first and last key are the same, the key length is 112 bits.
+  There are attacks that could reduce the key space to 55 bit's but it
+  requires 2^56 blocks of memory.
+- If all 3 keys are the same, this is effectively the same as normal
+  ecb mode.
+
+Triple CBC Mode (des_ede3_cbc_encrypt())
+- Encrypt with key1, decrypt with key2 and then encrypt with key3.
+- As for CBC encryption but increases the key length to 168 bits with
+  the same restrictions as for triple ecb mode.
+
+==== digest.doc ========================================================
+
+
+The Message Digest subroutines.
+
+These routines require "evp.h" to be included.
+
+These functions are a higher level interface to the various message digest
+routines found in this library.  As such, they allow the same code to be
+used to digest via different algorithms with only a change in an initial
+parameter.  They are basically just a front-end to the MD2, MD5, SHA
+and SHA1
+routines.
+
+These routines all take a pointer to the following structure to specify
+which message digest algorithm to use.
+typedef struct evp_md_st
+       {
+       int type;
+       int pkey_type;
+       int md_size;
+       void (*init)();
+       void (*update)();
+       void (*final)();
+
+       int required_pkey_type; /*EVP_PKEY_xxx */
+       int (*sign)();
+       int (*verify)();
+       } EVP_MD;
+
+If additional message digest algorithms are to be supported, a structure of
+this type needs to be declared and populated and then the Digest routines
+can be used with that algorithm.  The type field is the object NID of the
+digest type (read the section on Objects for an explanation).  The pkey_type
+is the Object type to use when the a message digest is generated by there
+routines and then is to be signed with the pkey algorithm.  Md_size is
+the size of the message digest returned.  Init, update
+and final are the relevant functions to perform the message digest function
+by parts.  One reason for specifying the message digest to use via this
+mechanism is that if you only use md5, only the md5 routines will
+be included in you linked program.  If you passed an integer
+that specified which message digest to use, the routine that mapped that
+integer to a set of message digest functions would cause all the message
+digests functions to be link into the code.  This setup also allows new
+message digest functions to be added by the application.
+
+The six message digests defined in this library are
+
+EVP_MD *EVP_md2(void); /* RSA sign/verify */
+EVP_MD *EVP_md5(void); /* RSA sign/verify */
+EVP_MD *EVP_sha(void); /* RSA sign/verify */
+EVP_MD *EVP_sha1(void);        /* RSA sign/verify */
+EVP_MD *EVP_dss(void); /* DSA sign/verify */
+EVP_MD *EVP_dss1(void);        /* DSA sign/verify */
+
+All the message digest routines take a EVP_MD_CTX pointer as an argument.
+The state of the message digest is kept in this structure.
+
+typedef struct pem_md_ctx_st
+       {
+       EVP_MD *digest;
+       union   {
+               unsigned char base[4]; /* this is used in my library as a
+                                       * 'pointer' to all union elements
+                                       * structures. */
+               MD2_CTX md2;
+               MD5_CTX md5;
+               SHA_CTX sha;
+               } md;
+       } EVP_MD_CTX;
+
+The Digest functions are as follows.
+
+void EVP_DigestInit(
+EVP_MD_CTX *ctx,
+EVP_MD *type);
+       This function is used to initialise the EVP_MD_CTX.  The message
+       digest that will associated with 'ctx' is specified by 'type'.
+
+void EVP_DigestUpdate(
+EVP_MD_CTX *ctx,
+unsigned char *data,
+unsigned int cnt);
+       This function is used to pass more data to the message digest
+       function.  'cnt' bytes are digested from 'data'.
+
+void EVP_DigestFinal(
+EVP_MD_CTX *ctx,
+unsigned char *md,
+unsigned int *len);
+       This function finishes the digestion and puts the message digest
+       into 'md'.  The length of the message digest is put into len;
+       EVP_MAX_MD_SIZE is the size of the largest message digest that
+       can be returned from this function.  Len can be NULL if the
+       size of the digest is not required.
+       
+
+==== encode.doc ========================================================
+
+
+void    EVP_EncodeInit(EVP_ENCODE_CTX *ctx);
+void    EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,
+               int *outl,unsigned char *in,int inl);
+void    EVP_EncodeFinal(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl);
+int     EVP_EncodeBlock(unsigned char *t, unsigned char *f, int n);
+
+void    EVP_DecodeInit(EVP_ENCODE_CTX *ctx);
+int     EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl,
+               unsigned char *in, int inl);
+int     EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned
+               char *out, int *outl);
+int     EVP_DecodeBlock(unsigned char *t, unsigned
+               char *f, int n);
+
+
+==== envelope.doc ========================================================
+
+The following routines are use to create 'digital' envelopes.
+By this I mean that they perform various 'higher' level cryptographic
+functions.  Have a read of 'cipher.doc' and 'digest.doc' since those
+routines are used by these functions.
+cipher.doc contains documentation about the cipher part of the
+envelope library and digest.doc contatins the description of the
+message digests supported.
+
+To 'sign' a document involves generating a message digest and then encrypting
+the digest with an private key.
+
+#define EVP_SignInit(a,b)              EVP_DigestInit(a,b)
+#define EVP_SignUpdate(a,b,c)          EVP_DigestUpdate(a,b,c)
+Due to the fact this operation is basically just an extended message
+digest, the first 2 functions are macro calls to Digest generating
+functions.
+
+int     EVP_SignFinal(
+EVP_MD_CTX *ctx,
+unsigned char *md,
+unsigned int *s,
+EVP_PKEY *pkey);
+       This finalisation function finishes the generation of the message
+digest and then encrypts the digest (with the correct message digest 
+object identifier) with the EVP_PKEY private key.  'ctx' is the message digest
+context.  'md' will end up containing the encrypted message digest.  This
+array needs to be EVP_PKEY_size(pkey) bytes long.  's' will actually
+contain the exact length.  'pkey' of course is the private key.  It is
+one of EVP_PKEY_RSA or EVP_PKEY_DSA type.
+If there is an error, 0 is returned, otherwise 1.
+               
+Verify is used to check an signed message digest.
+
+#define EVP_VerifyInit(a,b)            EVP_DigestInit(a,b)
+#define EVP_VerifyUpdate(a,b,c)                EVP_DigestUpdate(a,b,c)
+Since the first step is to generate a message digest, the first 2 functions
+are macros.
+
+int EVP_VerifyFinal(
+EVP_MD_CTX *ctx,
+unsigned char *md,
+unsigned int s,
+EVP_PKEY *pkey);
+       This function finishes the generation of the message digest and then
+compares it with the supplied encrypted message digest.  'md' contains the
+'s' bytes of encrypted message digest.  'pkey' is used to public key decrypt
+the digest.  It is then compared with the message digest just generated.
+If they match, 1 is returned else 0.
+
+int    EVP_SealInit(EVP_CIPHER_CTX *ctx, EVP_CIPHER *type, unsigned char **ek,
+               int *ekl, unsigned char *iv, EVP_PKEY **pubk, int npubk);
+Must have at least one public key, error is 0.  I should also mention that
+the buffers pointed to by 'ek' need to be EVP_PKEY_size(pubk[n]) is size.
+
+#define EVP_SealUpdate(a,b,c,d,e)      EVP_EncryptUpdate(a,b,c,d,e)    
+void   EVP_SealFinal(EVP_CIPHER_CTX *ctx,unsigned char *out,int *outl);
+
+
+int    EVP_OpenInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type,unsigned char *ek,
+               int ekl,unsigned char *iv,EVP_PKEY *priv);
+0 on failure
+
+#define EVP_OpenUpdate(a,b,c,d,e)      EVP_DecryptUpdate(a,b,c,d,e)
+
+int    EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
+Decrypt final return code
+
+
+==== error.doc ========================================================
+
+The error routines.
+
+The 'error' system I've implemented is intended to server 2 purpose, to
+record the reason why a command failed and to record where in the libraries
+the failure occurred.  It is more or less setup to record a 'trace' of which
+library components were being traversed when the error occurred.
+
+When an error is recorded, it is done so a as single unsigned long which is
+composed of three parts.  The top byte is the 'library' number, the middle
+12 bytes is the function code, and the bottom 12 bits is the 'reason' code.
+
+Each 'library', or should a say, 'section' of the SSLeay library has a
+different unique 'library' error number.  Each function in the library has
+a number that is unique for that library.  Each 'library' also has a number
+for each 'error reason' that is only unique for that 'library'.
+
+Due to the way these error routines record a 'error trace', there is an
+array per thread that is used to store the error codes.
+The various functions in this library are used to access
+and manipulate this array.
+
+void ERR_put_error(int lib, int func,int reason);
+       This routine records an error in library 'lib', function 'func'
+and reason 'reason'.  As errors get 'put' into the buffer, they wrap
+around and overwrite old errors if too many are written.  It is assumed
+that the last errors are the most important.
+
+unsigned long ERR_get_error(void );
+       This function returns the last error added to the error buffer.
+In effect it is popping the value off the buffer so repeated calls will
+continue to return values until there are no more errors to return in which
+case 0 is returned.
+
+unsigned long ERR_peek_error(void );
+       This function returns the value of the last error added to the
+error buffer but does not 'pop' it from the buffer.
+
+void ERR_clear_error(void );
+       This function clears the error buffer, discarding all unread
+errors.
+
+While the above described error system obviously produces lots of different
+error number, a method for 'reporting' these errors in a human readable
+form is required.  To achieve this, each library has the option of
+'registering' error strings.
+
+typedef struct ERR_string_data_st
+       {
+       unsigned long error;
+       char *string;
+       } ERR_STRING_DATA;
+
+The 'ERR_STRING_DATA' contains an error code and the corresponding text
+string.  To add new function error strings for a library, the
+ERR_STRING_DATA needs to be 'registered' with the library.
+
+void ERR_load_strings(unsigned long lib,ERR_STRING_DATA *err);
+       This function 'registers' the array of ERR_STRING_DATA pointed to by
+'err' as error text strings for the error library 'lib'.
+
+void ERR_free_strings(void);
+       This function free()s all the loaded error strings.
+
+char *ERR_error_string(unsigned long error,char *buf);
+       This function returns a text string that is a human readable
+version of the error represented by 'error'.  Buff should be at least 120
+bytes long and if it is NULL, the return value is a pointer to a static
+variable that will contain the error string, otherwise 'buf' is returned.
+If there is not a text string registered for a particular error, a text
+string containing the error number is returned instead.
+
+void ERR_print_errors(BIO *bp);
+void ERR_print_errors_fp(FILE *fp);
+       This function is a convenience routine that prints the error string
+for each error until all errors have been accounted for.
+
+char *ERR_lib_error_string(unsigned long e);
+char *ERR_func_error_string(unsigned long e);
+char *ERR_reason_error_string(unsigned long e);
+The above three functions return the 3 different components strings for the
+error 'e'.  ERR_error_string() uses these functions.
+
+void ERR_load_ERR_strings(void );
+       This function 'registers' the error strings for the 'ERR' module.
+
+void ERR_load_crypto_strings(void );
+       This function 'register' the error strings for just about every
+library in the SSLeay package except for the SSL routines.  There is no
+need to ever register any error text strings and you will probably save in
+program size.  If on the other hand you do 'register' all errors, it is
+quite easy to determine why a particular routine failed.
+
+As a final footnote as to why the error system is designed as it is.
+1) I did not want a single 'global' error code.
+2) I wanted to know which subroutine a failure occurred in.
+3) For Windows NT etc, it should be simple to replace the 'key' routines
+   with code to pass error codes back to the application.
+4) I wanted the option of meaningful error text strings.
+
+Late breaking news - the changes to support threads.
+
+Each 'thread' has an 'ERR_STATE' state associated with it.
+ERR_STATE *ERR_get_state(void ) will return the 'state' for the calling
+thread/process.
+
+ERR_remove_state(unsigned long pid); will 'free()' this state.  If pid == 0
+the current 'thread/process' will have it's error state removed.
+If you do not remove the error state of a thread, this could be considered a
+form of memory leak, so just after 'reaping' a thread that has died,
+call ERR_remove_state(pid).
+
+Have a read of thread.doc for more details for what is required for
+multi-threading support.  All the other error routines will
+work correctly when using threads.
+
+
+==== idea.doc ========================================================
+
+The IDEA library.
+IDEA is a block cipher that operates on 64bit (8 byte) quantities.  It
+uses a 128bit (16 byte) key.  It can be used in all the modes that DES can
+be used.  This library implements the ecb, cbc, cfb64 and ofb64 modes.
+
+For all calls that have an 'input' and 'output' variables, they can be the
+same.
+
+This library requires the inclusion of 'idea.h'.
+
+All of the encryption functions take what is called an IDEA_KEY_SCHEDULE as an 
+argument.  An IDEA_KEY_SCHEDULE is an expanded form of the idea key.
+For all modes of the IDEA algorithm, the IDEA_KEY_SCHEDULE used for
+decryption is different to the one used for encryption.
+
+The define IDEA_ENCRYPT is passed to specify encryption for the functions
+that require an encryption/decryption flag. IDEA_DECRYPT is passed to
+specify decryption.  For some mode there is no encryption/decryption
+flag since this is determined by the IDEA_KEY_SCHEDULE.
+
+So to encrypt you would do the following
+idea_set_encrypt_key(key,encrypt_ks);
+idea_ecb_encrypt(...,encrypt_ks);
+idea_cbc_encrypt(....,encrypt_ks,...,IDEA_ENCRYPT);
+
+To Decrypt
+idea_set_encrypt_key(key,encrypt_ks);
+idea_set_decrypt_key(encrypt_ks,decrypt_ks);
+idea_ecb_encrypt(...,decrypt_ks);
+idea_cbc_encrypt(....,decrypt_ks,...,IDEA_DECRYPT);
+
+Please note that any of the encryption modes specified in my DES library
+could be used with IDEA.  I have only implemented ecb, cbc, cfb64 and
+ofb64 for the following reasons.
+- ecb is the basic IDEA encryption.
+- cbc is the normal 'chaining' form for block ciphers.
+- cfb64 can be used to encrypt single characters, therefore input and output
+  do not need to be a multiple of 8.
+- ofb64 is similar to cfb64 but is more like a stream cipher, not as
+  secure (not cipher feedback) but it does not have an encrypt/decrypt mode.
+- If you want triple IDEA, thats 384 bits of key and you must be totally
+  obsessed with security.  Still, if you want it, it is simple enough to
+  copy the function from the DES library and change the des_encrypt to
+  idea_encrypt; an exercise left for the paranoid reader :-).
+
+The functions are as follows:
+
+void idea_set_encrypt_key(
+unsigned char *key;
+IDEA_KEY_SCHEDULE *ks);
+       idea_set_encrypt_key converts a 16 byte IDEA key into an
+       IDEA_KEY_SCHEDULE.  The IDEA_KEY_SCHEDULE is an expanded form of
+       the key which can be used to perform IDEA encryption.
+       An IDEA_KEY_SCHEDULE is an expanded form of the key which is used to
+       perform actual encryption.  It can be regenerated from the IDEA key
+       so it only needs to be kept when encryption is about
+       to occur.  Don't save or pass around IDEA_KEY_SCHEDULE's since they
+       are CPU architecture dependent, IDEA keys are not.
+       
+void idea_set_decrypt_key(
+IDEA_KEY_SCHEDULE *encrypt_ks,
+IDEA_KEY_SCHEDULE *decrypt_ks);
+       This functions converts an encryption IDEA_KEY_SCHEDULE into a
+       decryption IDEA_KEY_SCHEDULE.  For all decryption, this conversion
+       of the key must be done.  In some modes of IDEA, an
+       encryption/decryption flag is also required, this is because these
+       functions involve block chaining and the way this is done changes
+       depending on which of encryption of decryption is being done.
+       Please note that there is no quick way to generate the decryption
+       key schedule other than generating the encryption key schedule and
+       then converting it.
+
+void idea_encrypt(
+unsigned long *data,
+IDEA_KEY_SCHEDULE *ks);
+       This is the IDEA encryption function that gets called by just about
+       every other IDEA routine in the library.  You should not use this
+       function except to implement 'modes' of IDEA.  I say this because the
+       functions that call this routine do the conversion from 'char *' to
+       long, and this needs to be done to make sure 'non-aligned' memory
+       access do not occur.
+       Data is a pointer to 2 unsigned long's and ks is the
+       IDEA_KEY_SCHEDULE to use.  Encryption or decryption depends on the
+       IDEA_KEY_SCHEDULE.
+
+void idea_ecb_encrypt(
+unsigned char *input,
+unsigned char *output,
+IDEA_KEY_SCHEDULE *ks);
+       This is the basic Electronic Code Book form of IDEA (in DES this
+       mode is called Electronic Code Book so I'm going to use the term
+       for idea as well :-).
+       Input is encrypted into output using the key represented by
+       ks.  Depending on the IDEA_KEY_SCHEDULE, encryption or
+       decryption occurs.  Input is 8 bytes long and output is 8 bytes.
+       
+void idea_cbc_encrypt(
+unsigned char *input,
+unsigned char *output,
+long length,
+IDEA_KEY_SCHEDULE *ks,
+unsigned char *ivec,
+int enc);
+       This routine implements IDEA in Cipher Block Chaining mode.
+       Input, which should be a multiple of 8 bytes is encrypted
+       (or decrypted) to output which will also be a multiple of 8 bytes.
+       The number of bytes is in length (and from what I've said above,
+       should be a multiple of 8).  If length is not a multiple of 8, bad 
+       things will probably happen.  ivec is the initialisation vector.
+       This function updates iv after each call so that it can be passed to
+       the next call to idea_cbc_encrypt().
+       
+void idea_cfb64_encrypt(
+unsigned char *in,
+unsigned char *out,
+long length,
+des_key_schedule ks,
+des_cblock *ivec,
+int *num,
+int enc);
+       This is one of the more useful functions in this IDEA library, it
+       implements CFB mode of IDEA with 64bit feedback.
+       This allows you to encrypt an arbitrary number of bytes,
+       you do not require 8 byte padding.  Each call to this
+       routine will encrypt the input bytes to output and then update ivec
+       and num.  Num contains 'how far' we are though ivec.
+       Enc is used to indicate encryption or decryption.
+       One very important thing to remember is that when decrypting, use
+       the encryption form of the key.
+       CFB64 mode operates by using the cipher to
+       generate a stream of bytes which is used to encrypt the plain text.
+       The cipher text is then encrypted to generate the next 64 bits to
+       be xored (incrementally) with the next 64 bits of plain
+       text.  As can be seen from this, to encrypt or decrypt,
+       the same 'cipher stream' needs to be generated but the way the next
+       block of data is gathered for encryption is different for
+       encryption and decryption.  What this means is that to encrypt
+       idea_set_encrypt_key(key,ks);
+       idea_cfb64_encrypt(...,ks,..,IDEA_ENCRYPT)
+       do decrypt
+       idea_set_encrypt_key(key,ks)
+       idea_cfb64_encrypt(...,ks,...,IDEA_DECRYPT)
+       Note: The same IDEA_KEY_SCHEDULE but different encryption flags.
+       For idea_cbc or idea_ecb, idea_set_decrypt_key() would need to be
+       used to generate the IDEA_KEY_SCHEDULE for decryption.
+       The reason I'm stressing this point is that I just wasted 3 hours
+       today trying to decrypt using this mode and the decryption form of
+       the key :-(.
+       
+void idea_ofb64_encrypt(
+unsigned char *in,
+unsigned char *out,
+long length,
+des_key_schedule ks,
+des_cblock *ivec,
+int *num);
+       This functions implements OFB mode of IDEA with 64bit feedback.
+       This allows you to encrypt an arbitrary number of bytes,
+       you do not require 8 byte padding.  Each call to this
+       routine will encrypt the input bytes to output and then update ivec
+       and num.  Num contains 'how far' we are though ivec.
+       This is in effect a stream cipher, there is no encryption or
+       decryption mode.  The same key and iv should be used to
+       encrypt and decrypt.
+       
+For reading passwords, I suggest using des_read_pw_string() from my DES library.
+To generate a password from a text string, I suggest using MD5 (or MD2) to
+produce a 16 byte message digest that can then be passed directly to
+idea_set_encrypt_key().
+
+=====
+For more information about the specific IDEA modes in this library
+(ecb, cbc, cfb and ofb), read the section entitled 'Modes of DES' from the
+documentation on my DES library.  What is said about DES is directly
+applicable for IDEA.
+
+
+==== legal.doc ========================================================
+
+From eay@mincom.com Thu Jun 27 00:25:45 1996
+Received: by orb.mincom.oz.au id AA15821
+  (5.65c/IDA-1.4.4 for eay); Wed, 26 Jun 1996 14:25:45 +1000
+Date: Wed, 26 Jun 1996 14:25:45 +1000 (EST)
+From: Eric Young <eay@mincom.oz.au>
+X-Sender: eay@orb
+To: Ken Toll <ktoll@ren.digitalage.com>
+Cc: Eric Young <eay@mincom.oz.au>, ssl-talk@netscape.com
+Subject: Re: Unidentified subject!
+In-Reply-To: <9606261950.ZM28943@ren.digitalage.com>
+Message-Id: <Pine.SOL.3.91.960626131156.28573K-100000@orb>
+Mime-Version: 1.0
+Content-Type: TEXT/PLAIN; charset=US-ASCII
+Status: O
+X-Status: 
+
+
+This is a little off topic but since SSLeay is a free implementation of
+the SSLv2 protocol, I feel it is worth responding on the topic of if it 
+is actually legal for Americans to use free cryptographic software.
+
+On Wed, 26 Jun 1996, Ken Toll wrote:
+> Is the U.S the only country that SSLeay cannot be used commercially 
+> (because of RSAref) or is that going to be an issue with every country 
+> that a client/server application (non-web browser/server) is deployed 
+> and sold?
+
+>From what I understand, the software patents that apply to algorithms 
+like RSA and DH only apply in the USA.  The IDEA algorithm I believe is 
+patened in europe (USA?), but considing how little it is used by other SSL 
+implementations, it quite easily be left out of the SSLeay build
+(this can be done with a compile flag).
+
+Actually if the RSA patent did apply outside the USA, it could be rather
+interesting since RSA is not alowed to let RSA toolkits outside of the USA
+[1], and since these are the only forms that they will alow the algorithm
+to be used in, it would mean that non-one outside of the USA could produce
+public key software which would be a very strong statment for
+international patent law to make :-).  This logic is a little flawed but
+it still points out some of the more interesting permutations of USA
+patent law and ITAR restrictions. 
+
+Inside the USA there is also the unresolved issue of RC4/RC2 which were
+made public on sci.crypt in Sep 1994 (RC4) and Feb 1996 (RC2).  I have
+copies of the origional postings if people are interested.  RSA I believe 
+claim that they were 'trade-secrets' and that some-one broke an NDA in 
+revealing them.  Other claim they reverse engineered the algorithms from 
+compiled binaries.  If the algorithms were reverse engineered, I believe 
+RSA had no legal leg to stand on.  If an NDA was broken, I don't know.
+Regardless, RSA, I believe, is willing to go to court over the issue so 
+licencing is probably the best idea, or at least talk to them.
+If there are people who actually know more about this, pease let me know, I 
+don't want to vilify or spread miss-information if I can help it.
+
+If you are not producing a web browser, it is easy to build SSLeay with
+RC2/RC4 removed. Since RC4 is the defacto standard cipher in 
+all web software (and it is damn fast) it is more or less required for 
+www use. For non www use of SSL, especially for an application where 
+interoperability with other vendors is not critical just leave it out.
+
+Removing IDEA, RC2 and RC4 would only leave DES and Triple DES but 
+they should be ok.  Considing that Triple DES can encrypt at rates of
+410k/sec on a pentium 100, and 940k/sec on a P6/200, this is quite 
+reasonable performance.  Single DES clocks in at 1160k/s and 2467k/s
+respectivly is actually quite fast for those not so paranoid (56 bit key).[1]
+
+> Is it possible to get a certificate for commercial use outside of the U.S.?
+yes.
+
+Thawte Consulting issues certificates (they are the people who sell the
+       Sioux httpd server and are based in South Africa)
+Verisign will issue certificates for Sioux (sold from South Africa), so this
+       proves that they will issue certificate for OS use if they are
+       happy with the quality of the software.
+
+(The above mentioned companies just the ones that I know for sure are issuing
+ certificates outside the USA).
+
+There is always the point that if you are using SSL for an intra net, 
+SSLeay provides programs that can be used so you can issue your own 
+certificates.  They need polishing but at least it is a good starting point.
+
+I am not doing anything outside Australian law by implementing these
+algorithms (to the best of my knowedge).  It is another example of how 
+the world legal system does not cope with the internet very well.
+
+I may start making shared libraries available (I have now got DLL's for 
+Windows).  This will mean that distributions into the usa could be 
+shipped with a version with a reduced cipher set and the versions outside 
+could use the DLL/shared library with all the ciphers (and without RSAref).
+
+This could be completly hidden from the application, so this would not 
+even require a re-linking.
+
+This is the reverse of what people were talking about doing to get around 
+USA export regulations :-)
+
+eric
+
+[1]:   The RSAref2.0 tookit is available on at least 3 ftp sites in Europe
+       and one in South Africa.
+
+[2]:   Since I always get questions when I post benchmark numbers :-),
+       DES performace figures are in 1000's of bytes per second in cbc 
+       mode using an 8192 byte buffer.  The pentium 100 was running Windows NT 
+       3.51 DLLs and the 686/200 was running NextStep.
+       I quote pentium 100 benchmarks because it is basically the
+       'entry level' computer that most people buy for personal use.
+       Windows 95 is the OS shipping on those boxes, so I'll give
+       NT numbers (the same Win32 runtime environment).  The 686
+       numbers are present as an indication of where we will be in a
+       few years.
+--
+Eric Young                  | BOOL is tri-state according to Bill Gates.
+AARNet: eay@mincom.oz.au    | RTFM Win32 GetMessage().
+
+
+
+==== lhash.doc ========================================================
+
+The LHASH library.
+
+I wrote this library in 1991 and have since forgotten why I called it lhash.
+It implements a hash table from an article I read at the
+time from 'Communications of the ACM'.  What makes this hash
+table different is that as the table fills, the hash table is
+increased (or decreased) in size via realloc().
+When a 'resize' is done, instead of all hashes being redistributed over
+twice as many 'buckets', one bucket is split.  So when an 'expand' is done,
+there is only a minimal cost to redistribute some values.  Subsequent
+inserts will cause more single 'bucket' redistributions but there will
+never be a sudden large cost due to redistributing all the 'buckets'.
+
+The state for a particular hash table is kept in the LHASH structure.
+The LHASH structure also records statistics about most aspects of accessing
+the hash table.  This is mostly a legacy of my writing this library for
+the reasons of implementing what looked like a nice algorithm rather than
+for a particular software product.
+
+Internal stuff you probably don't want to know about.
+The decision to increase or decrease the hash table size is made depending
+on the 'load' of the hash table.  The load is the number of items in the
+hash table divided by the size of the hash table.  The default values are
+as follows.  If (hash->up_load < load) => expand.
+if (hash->down_load > load) =>  contract.  The 'up_load' has a default value of
+1 and 'down_load' has a default value of 2.  These numbers can be modified
+by the application by just playing with the 'up_load' and 'down_load'
+variables.  The 'load' is kept in a form which is multiplied by 256.  So
+hash->up_load=8*256; will cause a load of 8 to be set.
+
+If you are interested in performance the field to watch is
+num_comp_calls.  The hash library keeps track of the 'hash' value for
+each item so when a lookup is done, the 'hashes' are compared, if
+there is a match, then a full compare is done, and
+hash->num_comp_calls is incremented.  If num_comp_calls is not equal
+to num_delete plus num_retrieve it means that your hash function is
+generating hashes that are the same for different values.  It is
+probably worth changing your hash function if this is the case because
+even if your hash table has 10 items in a 'bucked', it can be searched
+with 10 'unsigned long' compares and 10 linked list traverses.  This
+will be much less expensive that 10 calls to you compare function.
+
+LHASH *lh_new(
+unsigned long (*hash)(),
+int (*cmp)());
+       This function is used to create a new LHASH structure.  It is passed
+       function pointers that are used to store and retrieve values passed
+       into the hash table.  The 'hash'
+       function is a hashing function that will return a hashed value of
+       it's passed structure.  'cmp' is passed 2 parameters, it returns 0
+       is they are equal, otherwise, non zero.
+       If there are any problems (usually malloc failures), NULL is
+       returned, otherwise a new LHASH structure is returned.  The
+       hash value is normally truncated to a power of 2, so make sure
+       that your hash function returns well mixed low order bits.
+       
+void lh_free(
+LHASH *lh);
+       This function free()s a LHASH structure.  If there is malloced
+       data in the hash table, it will not be freed.  Consider using the
+       lh_doall function to deallocate any remaining entries in the hash
+       table.
+       
+char *lh_insert(
+LHASH *lh,
+char *data);
+       This function inserts the data pointed to by data into the lh hash
+       table.  If there is already and entry in the hash table entry, the
+       value being replaced is returned.  A NULL is returned if the new
+       entry does not clash with an entry already in the table (the normal
+       case) or on a malloc() failure (perhaps I should change this....).
+       The 'char *data' is exactly what is passed to the hash and
+       comparison functions specified in lh_new().
+       
+char *lh_delete(
+LHASH *lh,
+char *data);
+       This routine deletes an entry from the hash table.  The value being
+       deleted is returned.  NULL is returned if there is no such value in
+       the hash table.
+
+char *lh_retrieve(
+LHASH *lh,
+char *data);
+       If 'data' is in the hash table it is returned, else NULL is
+       returned.  The way these routines would normally be uses is that a
+       dummy structure would have key fields populated and then
+       ret=lh_retrieve(hash,&dummy);.  Ret would now be a pointer to a fully
+       populated structure.
+
+void lh_doall(
+LHASH *lh,
+void (*func)(char *a));
+       This function will, for every entry in the hash table, call function
+       'func' with the data item as parameters.
+       This function can be quite useful when used as follows.
+       void cleanup(STUFF *a)
+               { STUFF_free(a); }
+       lh_doall(hash,cleanup);
+       lh_free(hash);
+       This can be used to free all the entries, lh_free() then
+       cleans up the 'buckets' that point to nothing.  Be careful
+       when doing this.  If you delete entries from the hash table,
+       in the call back function, the table may decrease in size,
+       moving item that you are
+       currently on down lower in the hash table.  This could cause
+       some entries to be skipped.  The best solution to this problem
+       is to set lh->down_load=0 before you start.  This will stop
+       the hash table ever being decreased in size.
+
+void lh_doall_arg(
+LHASH *lh;
+void(*func)(char *a,char *arg));
+char *arg;
+       This function is the same as lh_doall except that the function
+       called will be passed 'arg' as the second argument.
+       
+unsigned long lh_strhash(
+char *c);
+       This function is a demo string hashing function.  Since the LHASH
+       routines would normally be passed structures, this routine would
+       not normally be passed to lh_new(), rather it would be used in the
+       function passed to lh_new().
+
+The next three routines print out various statistics about the state of the
+passed hash table.  These numbers are all kept in the lhash structure.
+
+void lh_stats(
+LHASH *lh,
+FILE *out);
+       This function prints out statistics on the size of the hash table,
+       how many entries are in it, and the number and result of calls to
+       the routines in this library.
+
+void lh_node_stats(
+LHASH *lh,
+FILE *out);
+       For each 'bucket' in the hash table, the number of entries is
+       printed.
+       
+void lh_node_usage_stats(
+LHASH *lh,
+FILE *out);
+       This function prints out a short summary of the state of the hash
+       table.  It prints what I call the 'load' and the 'actual load'.
+       The load is the average number of data items per 'bucket' in the
+       hash table.  The 'actual load' is the average number of items per
+       'bucket', but only for buckets which contain entries.  So the
+       'actual load' is the average number of searches that will need to
+       find an item in the hash table, while the 'load' is the average number
+       that will be done to record a miss.
+
+==== md2.doc ========================================================
+
+The MD2 library.
+MD2 is a message digest algorithm that can be used to condense an arbitrary
+length message down to a 16 byte hash.  The functions all need to be passed
+a MD2_CTX which is used to hold the MD2 context during multiple MD2_Update()
+function calls.  The normal method of use for this library is as follows
+
+MD2_Init(...);
+MD2_Update(...);
+...
+MD2_Update(...);
+MD2_Final(...);
+
+This library requires the inclusion of 'md2.h'.
+
+The main negative about MD2 is that it is slow, especially when compared
+to MD5.
+
+The functions are as follows:
+
+void MD2_Init(
+MD2_CTX *c);
+       This function needs to be called to initiate a MD2_CTX structure for
+       use.
+       
+void MD2_Update(
+MD2_CTX *c;
+unsigned char *data;
+unsigned long len);
+       This updates the message digest context being generated with 'len'
+       bytes from the 'data' pointer.  The number of bytes can be any
+       length.
+
+void MD2_Final(
+unsigned char *md;
+MD2_CTX *c;
+       This function is called when a message digest of the data digested
+       with MD2_Update() is wanted.  The message digest is put in the 'md'
+       array and is MD2_DIGEST_LENGTH (16) bytes long.
+
+unsigned char *MD2(
+unsigned long n;
+unsigned char *d;
+unsigned char *md;
+       This function performs a MD2_Init(), followed by a MD2_Update()
+       followed by a MD2_Final() (using a local MD2_CTX).
+       The resulting digest is put into 'md' if it is not NULL.
+       Regardless of the value of 'md', the message
+       digest is returned from the function.  If 'md' was NULL, the message
+       digest returned is being stored in a static structure.
+
+==== md5.doc ========================================================
+
+The MD5 library.
+MD5 is a message digest algorithm that can be used to condense an arbitrary
+length message down to a 16 byte hash.  The functions all need to be passed
+a MD5_CTX which is used to hold the MD5 context during multiple MD5_Update()
+function calls.  This library also contains random number routines that are
+based on MD5
+
+The normal method of use for this library is as follows
+
+MD5_Init(...);
+MD5_Update(...);
+...
+MD5_Update(...);
+MD5_Final(...);
+
+This library requires the inclusion of 'md5.h'.
+
+The functions are as follows:
+
+void MD5_Init(
+MD5_CTX *c);
+       This function needs to be called to initiate a MD5_CTX structure for
+       use.
+       
+void MD5_Update(
+MD5_CTX *c;
+unsigned char *data;
+unsigned long len);
+       This updates the message digest context being generated with 'len'
+       bytes from the 'data' pointer.  The number of bytes can be any
+       length.
+
+void MD5_Final(
+unsigned char *md;
+MD5_CTX *c;
+       This function is called when a message digest of the data digested
+       with MD5_Update() is wanted.  The message digest is put in the 'md'
+       array and is MD5_DIGEST_LENGTH (16) bytes long.
+
+unsigned char *MD5(
+unsigned char *d;
+unsigned long n;
+unsigned char *md;
+       This function performs a MD5_Init(), followed by a MD5_Update()
+       followed by a MD5_Final() (using a local MD5_CTX).
+       The resulting digest is put into 'md' if it is not NULL.
+       Regardless of the value of 'md', the message
+       digest is returned from the function.  If 'md' was NULL, the message
+       digest returned is being stored in a static structure.
+
+
+==== memory.doc ========================================================
+
+In the interests of debugging SSLeay, there is an option to compile
+using some simple memory leak checking.
+
+All malloc(), free() and realloc() calls in SSLeay now go via
+Malloc(), Free() and Realloc() (except those in crypto/lhash).
+
+If CRYPTO_MDEBUG is defined, these calls are #defined to
+CRYPTO_malloc(), CRYPTO_free() and CRYPTO_realloc().
+If it is not defined, they are #defined to malloc(), free() and realloc().
+
+the CRYPTO_malloc() routines by default just call the underlying library
+functons.
+
+If CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON) is called, memory leak detection is
+turned on.  CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF) turns it off.
+
+When turned on, each Malloc() or Realloc() call is recored along with the file
+and line number from where the call was made.   (This is done using the
+lhash library which always uses normal system malloc(3) routines).
+
+void CRYPTO_mem_leaks(BIO *b);
+void CRYPTO_mem_leaks_fp(FILE *fp);
+These both print out the list of memory that has not been free()ed.
+This will probably be rather hard to read, but if you look for the 'top level'
+structure allocation, this will often give an idea as to what is not being
+free()ed.  I don't expect people to use this stuff normally.
+
+==== ca.1 ========================================================
+
+From eay@orb.mincom.oz.au Thu Dec 28 23:56:45 1995
+Received: by orb.mincom.oz.au id AA07374
+  (5.65c/IDA-1.4.4 for eay); Thu, 28 Dec 1995 13:56:45 +1000
+Date: Thu, 28 Dec 1995 13:56:45 +1000 (EST)
+From: Eric Young <eay@mincom.oz.au>
+X-Sender: eay@orb
+To: sameer <sameer@c2.org>
+Cc: ssleay@mincom.oz.au
+Subject: Re: 'ca'
+In-Reply-To: <199512230440.UAA23410@infinity.c2.org>
+Message-Id: <Pine.SOL.3.91.951228133525.7269A-100000@orb>
+Mime-Version: 1.0
+Content-Type: TEXT/PLAIN; charset=US-ASCII
+Status: RO
+X-Status: 
+
+On Fri, 22 Dec 1995, sameer wrote:
+>      I could use documentation on 'ca'. Thanks.
+
+Very quickly.
+The ca program uses the ssleay.conf file for most of its configuration
+
+./ca -help
+
+ -verbose        - Talk alot while doing things
+ -config file    - A config file. If you don't want to use the
+                  default config file
+ -name arg       - The particular CA definition to use
+       In the config file, the section to use for parameters.  This lets 
+       multiple setups to be contained in the one file.  By default, the 
+       default_ca variable is looked up in the [ ca ] section.  So in the 
+       shipped ssleay.conf, the CA definition used is CA_default.  It could be 
+       any other name.
+ -gencrl days    - Generate a new CRL, days is when the next CRL is due
+       This will generate a new certificate revocion list.
+ -days arg       - number of days to certify the certificate for
+       When certifiying certificates, this is the number of days to use.
+ -md arg         - md to use, one of md2, md5, sha or sha1
+ -policy arg     - The CA 'policy' to support
+       I'll describe this later, but there are 2 policies definied in the 
+       shipped ssleay.conf
+ -keyfile arg    - PEM RSA private key file
+ -key arg        - key to decode the RSA private key if it is encrypted
+       since we need to keep the CA's RSA key encrypted
+ -cert           - The CA certificate
+ -in file        - The input PEM encoded certificate request(s)
+ -out file       - Where to put the output file(s)
+ -outdir dir     - Where to put output certificates
+       The -out options concatinates all the output certificied
+       certificates to one file, -outdir puts them in a directory,
+       named by serial number.
+ -infiles ....   - The last argument, requests to process
+       The certificate requests to process, -in is the same.
+
+Just about all the above have default values defined in ssleay.conf.
+
+The key variables in ssleay.conf are (for the pariticular '-name' being 
+used, in the default, it is CA_default).
+
+dir is where all the CA database stuff is kept.
+certs is where all the previously issued certificates are kept.
+The database is a simple text database containing the following tab separated 
+fields.
+status: a value of 'R' - revoked, 'E' -expired or 'V' valid.
+issued date:  When the certificate was certified.
+revoked date:  When it was revoked, blank if not revoked.
+serial number:  The certificate serial number.
+certificate:   Where the certificate is located.
+CN:    The name of the certificate.
+
+The demo file has quite a few made up values it it.  The last 2 were 
+added by the ca program and are acurate.
+The CA program does not update the 'certificate' file correctly right now.
+The serial field should be unique as should the CN/status combination.
+The ca program checks these at startup.  What still needs to be 
+wrtten is a program to 'regenerate' the data base file from the issued 
+certificate list (and a CRL list).
+
+Back to the CA_default variables.
+
+Most of the variables are commented.
+
+policy is the default policy.
+
+Ok for policies, they define the order and which fields must be present 
+in the certificate request and what gets filled in.
+
+So a value of
+countryName             = match
+means that the country name must match the CA certificate.
+organizationalUnitName  = optional
+The org.Unit,Name does not have to be present and
+commonName              = supplied
+commonName must be supplied in the certificate request.
+
+For the 'policy_match' polocy, the order of the attributes in the 
+generated certiticate would be
+countryName
+stateOrProvinceName
+organizationName
+organizationalUnitName
+commonName
+emailAddress
+
+Have a play, it sort of makes sense.  If you think about how the persona 
+requests operate, it is similar to the 'policy_match' policy and the
+'policy_anything' is similar to what versign is doing.
+
+I hope this helps a bit.  Some backend scripts are definitly needed to 
+update the database and to make certificate revocion easy.  All 
+certificates issued should also be kept forever (or until they expire?)
+
+hope this helps
+eric (who has to run off an buy some cheap knee pads for the caving in 4 
+days time :-)
+
+--
+Eric Young                  | Signature removed since it was generating
+AARNet: eay@mincom.oz.au    | more followups than the message contents :-)
+
+
+==== ms3-ca.doc ========================================================
+
+Date: Mon, 9 Jun 97 08:00:33 +0200
+From: Holger.Reif@PrakInf.TU-Ilmenau.DE (Holger Reif)
+Subject: ms3-ca.doc
+Organization: TU Ilmenau, Fak. IA, FG Telematik
+Content-Length: 14575
+Status: RO
+X-Status: 
+
+Loading client certs into MSIE 3.01
+===================================
+
+This document contains all the information necessary to successfully set up 
+some scripts to issue client certs to Microsoft Internet Explorer. It 
+includes the required knowledge about the model MSIE uses for client 
+certification and includes complete sample scripts ready to play with. The 
+scripts were tested against a modified ca program of SSLeay 0.6.6 and should 
+work with the regular ca program that comes with version 0.8.0. I haven't 
+tested against MSIE 4.0
+
+You can use the information contained in this document in either way you 
+want. However if you feel it saved you a lot of time I ask you to be as fair 
+as to mention my name: Holger Reif <reif@prakinf.tu-ilmenau.de>.
+
+1.) The model used by MSIE
+--------------------------
+
+The Internet Explorer doesn't come with a embedded engine for installing 
+client certs like Netscape's Navigator. It rather uses the CryptoAPI (CAPI) 
+defined by Microsoft. CAPI comes with WindowsNT 4.0 or is installed together 
+with Internet Explorer since 3.01. The advantage of this approach is a higher 
+flexibility because the certificates in the (per user) system open 
+certificate store may be used by other applications as well. The drawback 
+however is that you need to do a bit more work to get a client cert issued.
+
+CAPI defines functions which will handle basic cryptographic work, eg. 
+generating keys, encrypting some data, signing text or building a certificate 
+request. The procedure is as follows: A CAPI function generates you a key 
+pair and saves it into the certificate store. After that one builds a 
+Distinguished Name. Together with that key pair another CAPI function forms a 
+PKCS#10 request which you somehow need to submit to a CA. Finally the issued 
+cert is given to a yet another CAPI function which saves it into the 
+certificate store.
+
+The certificate store with the user's keys and certs is in the registry. You 
+will find it under HKEY_CURRENT_USER/Software/Microsoft/Cryptography/ (I 
+leave it to you as a little exercise to figure out what all the entries mean 
+;-). Note that the keys are protected only with the user's usual Windows 
+login password.
+
+2.) The practical usage
+-----------------------
+
+Unfortunatly since CAPI is a system API you can't access its functions from 
+HTML code directly. For this purpose Microsoft provides a wrapper called 
+certenr3.dll. This DLL accesses the CAPI functions and provides an interface 
+usable from Visual Basic Script. One needs to install that library on the 
+computer which wants to have client cert. The easiest way is to load it as an 
+ActiveX control (certenr3.dll is properly authenticode signed by MS ;-). If 
+you have ever enrolled e cert request at a CA you will have installed it.
+
+At time of writing certenr3.dll is contained in 
+http://www.microsoft.com/workshop/prog/security/csa/certenr3.exe. It comes 
+with an README file which explains the available functions. It is labeled 
+beta but every CA seems to use it anyway. The license.txt allows you the 
+usage for your own purposes (as far as I understood) and a somehow limited 
+distribution. 
+
+The two functions of main interest are GenerateKeyPair and AcceptCredentials. 
+For complete explanation of all possible parameters see the README file. Here 
+are only minimal required parameters and their values.
+
+GenerateKeyPair(sessionID, FASLE, szName, 0, "ClientAuth", TRUE, FALSE, 1)
+- sessionID is a (locally to that computer) unique string to correlate the 
+generated key pair with a cert installed later.
+- szName is the DN of the form "C=DE; S=Thueringen; L=Ilmenau; CN=Holger 
+Reif; 1.2.840.113549.1.9.1=reif@prakinf.tu-ilmenau.de". Note that S is the 
+abreviation for StateOrProvince. The recognized abreviation include CN, O, C, 
+OU, G, I, L, S, T. If the abreviation is unknown (eg. for PKCS#9 email addr) 
+you need to use the full object identifier. The starting point for searching 
+them could be crypto/objects.h since all OIDs know to SSLeay are listed 
+there.
+- note: the possible ninth parameter which should give a default name to the 
+certificate storage location doesn't seem to work. Changes to the constant 
+values in the call above doesn't seem to make sense. You can't generate 
+PKCS#10 extensions with that function.
+
+The result of GenerateKeyPair is the base64 encoded PKCS#10 request. However 
+it has a little strange format that SSLeay doesn't accept. (BTW I feel the 
+decision of rejecting that format as standard conforming.) It looks like 
+follows:
+       1st line with 76 chars
+       2nd line with 76 chars
+       ...
+       (n-2)th line with 76 chars
+       (n-1)th line contains a multiple of 4 chars less then 76 (possible 
+empty)
+       (n)th line has zero or 4 chars (then with 1 or 2 equal signs - the 
+               original text's lenght wasn'T a multiple of 3) 
+       The line separator has two chars: 0x0d 0x0a
+
+AcceptCredentials(sessionID, credentials, 0, FALSE)
+- sessionID needs to be the same as while generating the key pair
+- credentials is the base64 encoded PKCS#7 object containing the cert. 
+
+CRL's and CA certs are not required simply just the client cert. (It seems to 
+me that both are not even checked somehow.) The only format of the base64 
+encoded object I succesfully used was all characters in a very long string 
+without line feeds or carriage returns. (Hey, it doesn't matter, only a 
+computer reads it!)
+
+The result should be S_OK. For error handling see the example that comes with 
+certenr3.dll.
+
+A note about ASN.1 character encodings. certenr3.dll seems to know only about 
+2 of them: UniversalString and PrintableString. First it is definitely wrong 
+for an email address which is IA5STRING (checked by ssleay's ca). Second 
+unfortunately MSIE (at least until version 3.02) can't handle UniversalString 
+correctly - they just blow up you cert store! Therefore ssleay's ca (starting 
+from version 0.8.0) tries to convert the encodings automatically to IA5STRING 
+or TeletexString. The beef is it will work only for the latin-1 (western) 
+charset. Microsoft still has to do abit of homework...
+
+3.) An example
+--------------
+
+At least you need two steps: generating the key & request and then installing 
+the certificate. A real world CA would have some more steps involved, eg. 
+accepting some license. Note that both scripts shown below are just 
+experimental state without any warrenty!
+
+First how to generate a request. Note that we can't use a static page because 
+of the sessionID. I generate it from system time plus pid and hope it is 
+unique enough. Your are free to feed it through md5 to get more impressive 
+ID's ;-) Then the intended text is read in with sed which inserts the 
+sessionID. 
+
+-----BEGIN ms-enroll.cgi-----
+#!/bin/sh
+SESSION_ID=`date '+%y%m%d%H%M%S'`$$
+echo Content-type: text/html
+echo
+sed s/template_for_sessId/$SESSION_ID/ <<EOF
+<HTML><HEAD>
+<TITLE>Certificate Enrollment Test Page</TITLE>
+</HEAD><BODY>
+
+<OBJECT
+    classid="clsid:33BEC9E0-F78F-11cf-B782-00C04FD7BF43"
+    codebase=certenr3.dll
+    id=certHelper
+    >
+</OBJECT>
+
+<CENTER>
+<H2>enrollment for a personal cert</H2>
+<BR><HR WIDTH=50%><BR><P>
+<FORM NAME="MSIE_Enrollment" ACTION="ms-gencert.cgi" ENCTYPE=x-www-form-
+encoded METHOD=POST>
+<TABLE>
+    <TR><TD>Country</TD><TD><INPUT NAME="Country" VALUE=""></TD></TR>
+    <TR><TD>State</TD><TD><INPUT NAME="StateOrProvince" VALUE=""></TD></TR>
+    <TR><TD>Location</TD><TD><INPUT NAME="Location" VALUE=""></TD></TR>
+    <TR><TD>Organization</TD><TD><INPUT NAME="Organization" 
+VALUE=""></TD></TR>
+    <TR><TD>Organizational Unit</TD>
+        <TD><INPUT NAME="OrganizationalUnit" VALUE=""></TD></TR>
+    <TR><TD>Name</TD><TD><INPUT NAME="CommonName" VALUE=""></TD></TR>
+    <TR><TD>eMail Address</TD>
+        <TD><INPUT NAME="EmailAddress" VALUE=""></TD></TR>
+    <TR><TD></TD>
+        <TD><INPUT TYPE="BUTTON" NAME="submit" VALUE="Beantragen"></TD></TR>
+</TABLE>
+       <INPUT TYPE="hidden" NAME="SessionId" VALUE="template_for_sessId">
+       <INPUT TYPE="hidden" NAME="Request" VALUE="">
+</FORM>
+<BR><HR WIDTH=50%><BR><P>
+</CENTER>
+
+<SCRIPT LANGUAGE=VBS>
+    Dim DN
+
+    Sub Submit_OnClick
+       Dim TheForm
+       Set TheForm = Document.MSIE_Enrollment
+       sessionId       = TheForm.SessionId.value
+       reqHardware     = FALSE
+       C               = TheForm.Country.value
+       SP              = TheForm.StateOrProvince.value
+       L               = TheForm.Location.value
+       O               = TheForm.Organization.value
+       OU              = TheForm.OrganizationalUnit.value
+       CN              = TheForm.CommonName.value
+       Email           = TheForm.EmailAddress.value
+        szPurpose       = "ClientAuth"
+        doAcceptanceUINow   = FALSE
+        doOnline        = TRUE
+
+       DN = ""
+
+       Call Add_RDN("C", C)
+       Call Add_RDN("S", SP)
+       Call Add_RDN("L", L)
+       Call Add_RDN("O", O)
+       Call Add_RDN("OU", OU)
+       Call Add_RDN("CN", CN)
+       Call Add_RDN("1.2.840.113549.1.9.1", Email)
+                     ' rsadsi
+                                    ' pkcs
+                                      ' pkcs9
+                                        ' eMailAddress
+        On Error Resume Next
+        sz10 = certHelper.GenerateKeyPair(sessionId, _
+                FALSE, DN, 0, ClientAuth, FASLE, TRUE, 1)_
+        theError = Err.Number
+        On Error Goto 0
+        if (sz10 = Empty OR theError <> 0) Then
+            sz = "The error '" & Hex(theError) & "' occurred." & chr(13) & _
+                chr(10) & "Your credentials could not be generated."
+            result = MsgBox(sz, 0, "Credentials Enrollment")
+            Exit Sub
+       else 
+           TheForm.Request.value = sz10
+           TheForm.Submit
+        end if
+    End Sub
+
+    Sub Add_RDN(sn, value)
+       if (value <> "") then
+           if (DN <> "") then
+               DN = DN & "; "
+           end if
+           DN = DN & sn & "=" & value
+       end if
+    End Sub
+</SCRIPT>
+</BODY>
+</HTML>
+EOF
+-----END ms-enroll.cgi-----
+
+Second, how to extract the request and feed the certificate back? We need to 
+"normalize" the base64 encoding of the PKCS#10 format which means 
+regenerating the lines and wrapping with BEGIN and END line. This is done by 
+gawk. The request is taken by ca the normal way. Then the cert needs to be 
+packed into a PKCS#7 structure (note: the use of a CRL is necessary for 
+crl2pkcs7 as of version 0.6.6. Starting with 0.8.0 it it might probably be 
+ommited). Finally we need to format the PKCS#7 object and generate the HTML 
+text. I use two templates to have a clearer script.
+
+1st note: postit2 is slightly modified from a program I found at ncsa's ftp 
+site. Grab it from http://www.easterngraphics.com/certs/IX9704/postit2.c. You 
+need utils.c from there too.
+
+2nd note: I'm note quite sure wether the gawk script really handles all 
+possible inputs for the request right! Today I don't use this construction 
+anymore myself.
+
+3d note: the cert must be of version 3! This could be done with the nsComment 
+line in ssleay.cnf...
+
+------BEGIN ms-gencert.cgi-----
+#!/bin/sh
+FILE="/tmp/"`date '+%y%m%d%H%M%S'-`$$
+rm -f "$FILE".*
+
+HOME=`pwd`; export HOME  # as ssleay.cnf insists on having such an env var
+cd /usr/local/ssl #where demoCA (as named in ssleay.conf) is located
+
+postit2 -s " " -i 0x0d > "$FILE".inp  # process the FORM vars
+
+SESSION_ID=`gawk '$1 == "SessionId" { print $2; exit }' "$FILE".inp`
+
+gawk \
+       'BEGIN { \
+               OFS = ""; \
+               print "-----BEGIN CERTIFICATE REQUEST-----"; \
+               req_seen=0 \
+       } \
+       $1 == "Request" { \
+               req_seen=1; \
+               if (length($2) == 72) print($2); \
+               lastline=$2; \
+               next; \
+       } \
+       { \
+               if (req_seen == 1) { \
+                       if (length($1) >= 72) print($1); \
+                       else if (length(lastline) < 72) { \
+                               req_seen=0; \
+                               print (lastline,$1); \
+                       } \
+               lastline=$1; \
+               } \
+       } \
+       END { \
+               print "-----END CERTIFICATE REQUEST-----"; \
+       }' > "$FILE".pem < "$FILE".inp 
+
+ssleay ca -batch -in "$FILE".pem -key passwd -out "$FILE".out
+ssleay crl2pkcs7 -certfile "$FILE".out -out "$FILE".pkcs7 -in demoCA/crl.pem
+
+sed s/template_for_sessId/$SESSION_ID/ <ms-enroll2a.html >"$FILE".cert
+/usr/local/bin/gawk \
+       'BEGIN  { \
+               OFS = ""; \
+               dq = sprintf("%c",34); \
+       } \
+       $0 ~ "PKCS7" { next; } \
+       { \
+               print dq$0dq" & _"; \
+       }' <"$FILE".pkcs7 >> "$FILE".cert
+cat  ms-enroll2b.html >>"$FILE".cert
+
+echo Content-type: text/html
+echo Content-length: `wc -c "$FILE".cert`
+echo
+cat "$FILE".cert
+rm -f "$FILE".*
+-----END ms-gencert.cgi-----
+
+----BEGIN ms-enroll2a.html----
+<HTML><HEAD><TITLE>Certificate Acceptance Test Page</TITLE></HEAD><BODY>
+
+<OBJECT
+    classid="clsid:33BEC9E0-F78F-11cf-B782-00C04FD7BF43"
+    codebase=certenr3.dll
+    id=certHelper
+    >
+</OBJECT>
+
+<CENTER>
+<H2>Your personal certificate</H2>
+<BR><HR WIDTH=50%><BR><P>
+Press the button!
+<P><INPUT TYPE=BUTTON VALUE="Nimm mich!" NAME="InstallCert">
+</CENTER>
+<BR><HR WIDTH=50%><BR>
+
+<SCRIPT LANGUAGE=VBS>
+    Sub InstallCert_OnClick
+
+       sessionId       = "template_for_sessId"
+credentials = "" & _
+----END ms-enroll2a.html----
+
+----BEGIN ms-enroll2b.html----
+""
+        On Error Resume Next
+        result = certHelper.AcceptCredentials(sessionId, credentials, 0, 
+FALSE)
+        if (IsEmpty(result)) Then
+           sz = "The error '" & Err.Number & "' occurred." & chr(13) & 
+chr(10) & "This Digital ID could not be registered."
+           msgOut = MsgBox(sz, 0, "Credentials Registration Error")
+           navigate "error.html"
+        else
+           sz = "Digital ID successfully registered."
+           msgOut = MsgBox(sz, 0, "Credentials Registration")
+           navigate "success.html"
+        end if
+       Exit Sub
+    End Sub
+</SCRIPT>
+</BODY>
+</HTML>
+----END ms-enroll2b.html----
+
+4.) What do do with the cert?
+-----------------------------
+
+The cert is visible (without restarting MSIE) under the following menu:
+View->Options->Security->Personal certs. You can examine it's contents at 
+least partially.
+
+To use it for client authentication you need to use SSL3.0 (fortunately 
+SSLeay supports it with 0.8.0). Furthermore MSIE is told to only supports a 
+kind of automatic selection of certs (I personally wasn't able to test it 
+myself). But there is a requirement that the issuer of the server cert and 
+the issuer of the client cert needs to be the same (according to a developer 
+from MS). Which means: you need may more then one cert to talk to all 
+servers...
+
+I'm sure we will get a bit more experience after ApacheSSL is available for 
+SSLeay 0.8.8.
+
+
+I hope you enjoyed reading and that in future questions on this topic will 
+rarely appear on ssl-users@moncom.com ;-)
+
+Ilmenau, 9th of June 1997
+Holger Reif <reif@prakinf.tu-ilmenau.de>
+-- 
+read you later  -  Holger Reif
+----------------------------------------  Signaturprojekt Deutsche Einheit
+TU Ilmenau - Informatik - Telematik                      (Verdamp lang her)
+Holger.Reif@PrakInf.TU-Ilmenau.DE         Alt wie ein Baum werden, um ueber
+http://Remus.PrakInf.TU-Ilmenau.DE/Reif/  alle 7 Bruecken gehen zu koennen
+
+
+==== ns-ca.doc ========================================================
+
+The following documentation was supplied by Jeff Barber, who provided the
+patch to the CA program to add this functionality.
+
+eric
+--
+Jeff Barber                                Email: jeffb@issl.atl.hp.com
+
+Hewlett Packard                            Phone: (404) 648-9503
+Internet and System Security Lab           Fax:   (404) 648-9516
+
+                         oo
+---------------------cut /\ here for ns-ca.doc ------------------------------
+
+This document briefly describes how to use SSLeay to implement a 
+certificate authority capable of dynamically serving up client
+certificates for version 3.0 beta 5 (and presumably later) versions of
+the Netscape Navigator.  Before describing how this is done, it's
+important to understand a little about how the browser implements its
+client certificate support.  This is documented in some detail in the
+URLs based at <URL:http://home.netscape.com/eng/security/certs.html>.
+Here's a brief overview:
+
+-      The Navigator supports a new HTML tag "KEYGEN" which will cause
+       the browser to generate an RSA key pair when you submit a form
+       containing the tag.  The public key, along with an optional
+       challenge (supposedly provided for use in certificate revocation
+       but I don't use it) is signed, DER-encoded, base-64 encoded
+       and sent to the web server as the value of the variable
+       whose NAME is provided in the KEYGEN tag.  The private key is
+       stored by the browser in a local key database.
+
+       This "Signed Public Key And Challenge" (SPKAC) arrives formatted
+       into 64 character lines (which are of course URL-encoded when 
+       sent via HTTP -- i.e. spaces, newlines and most punctuatation are
+       encoded as "%HH" where HH is the hex equivalent of the ASCII code).
+       Note that the SPKAC does not contain the other usual attributes
+       of a certificate request, especially the subject name fields.
+       These must be otherwise encoded in the form for submission along
+       with the SPKAC.
+
+-      Either immediately (in response to this form submission), or at
+       some later date (a real CA will probably verify your identity in
+       some way before issuing the certificate), a web server can send a
+       certificate based on the public key and other attributes back to
+       the browser by encoding it in DER (the binary form) and sending it
+       to the browser as MIME type:
+       "Content-type: application/x-x509-user-cert"
+
+       The browser uses the public key encoded in the certificate to
+       associate the certificate with the appropriate private key in
+       its local key database.  Now, the certificate is "installed".
+
+-      When a server wants to require authentication based on client
+       certificates, it uses the right signals via the SSL protocol to
+       trigger the Navigator to ask you which certificate you want to
+       send.  Whether the certificate is accepted is dependent on CA
+       certificates and so forth installed in the server and is beyond
+       the scope of this document.
+
+
+Now, here's how the SSLeay package can be used to provide client 
+certficates:
+
+-      You prepare a file for input to the SSLeay ca application.
+       The file contains a number of "name = value" pairs that identify
+       the subject.  The names here are the same subject name component
+       identifiers used in the CA section of the lib/ssleay.conf file,
+       such as "emailAddress", "commonName" "organizationName" and so
+       forth.  Both the long version and the short version (e.g. "Email",
+       "CN", "O") can be used.
+
+       One more name is supported: this one is "SPKAC".  Its value
+       is simply the value of the base-64 encoded SPKAC sent by the
+       browser (with all the newlines and other space charaters
+       removed -- and newline escapes are NOT supported).
+
+       [ As of SSLeay 0.6.4, multiple lines are supported.
+         Put a \ at the end of each line and it will be joined with the
+         previous line with the '\n' removed - eay ]
+       
+       Here's a sample input file:
+
+C = US
+SP = Georgia
+O = Some Organization, Inc.
+OU = Netscape Compatibility Group
+CN = John X. Doe
+Email = jxdoe@someorg.com
+SPKAC = MIG0MGAwXDANBgkqhkiG9w0BAQEFAANLADBIAkEAwmk6FMJ4uAVIYbcvIOx5+bDGTfvL8X5gE+R67ccMk6rCSGbVQz2cetyQtnI+VIs0NwdD6wjuSuVtVFbLoHonowIDAQABFgAwDQYJKoZIhvcNAQEEBQADQQBFZDUWFl6BJdomtN1Bi53mwijy1rRgJ4YirF15yBEDM3DjAQkKXHYOIX+qpz4KXKnl6EYxTnGSFL5wWt8X2iyx
+
+-      You execute the ca command (either from a CGI program run out of
+       the web server, or as a later manual task) giving it the above
+       file as input.  For example, if the file were named /tmp/cert.req,
+       you'd run:
+       $SSLDIR/bin/ca -spkac /tmp/cert.req -out /tmp/cert
+
+       The output is in DER format (binary) if a -out argument is 
+       provided, as above; otherwise, it's in the PEM format (base-64
+       encoded DER).  Also, the "-batch" switch is implied by the
+       "-spkac" so you don't get asked whether to complete the signing
+       (probably it shouldn't work this way but I was only interested
+       in hacking together an online CA that could be used for issuing
+       test certificates).
+
+       The "-spkac" capability doesn't support multiple files (I think).
+
+       Any CHALLENGE provided in the SPKAC is simply ignored.
+
+       The interactions between the identification fields you provide
+       and those identified in your lib/ssleay.conf are the same as if
+       you did an ordinary "ca -in infile -out outfile" -- that is, if
+       something is marked as required in the ssleay.conf file and it
+       isn't found in the -spkac file, the certificate won't be issued.
+
+-      Now, you pick up the output from /tmp/cert and pass it back to
+       the Navigator prepending the Content-type string described earlier.
+
+-      In order to run the ca command out of a CGI program, you must
+       provide a password to decrypt the CA's private key.  You can
+       do this by using "echo MyKeyPassword | $SSLDIR/bin/ca ..."
+       I think there's a way to not encrypt the key file in the first
+       place, but I didn't see how to do that, so I made a small change
+       to the library that allows the password to be accepted from a pipe.
+       Either way is UTTERLY INSECURE and a real CA would never do that.
+
+       [ You can use the 'ssleay rsa' command to remove the password
+         from the private key, or you can use the '-key' option to the
+         ca command to specify the decryption key on the command line
+         or use the -nodes option when generating the key.
+         ca will try to clear the command line version of the password
+         but for quite a few operating systems, this is not possible.
+         - eric ]
+
+So, what do you have to do to make use of this stuff to create an online 
+demo CA capability with SSLeay?
+
+1      Create an HTML form for your users.  The form should contain
+       fields for all of the required or optional fields in ssleay.conf.
+       The form must contain a KEYGEN tag somewhere with at least a NAME
+       attribute.
+
+2      Create a CGI program to process the form input submitted by the
+       browser.  The CGI program must URL-decode the variables and create
+       the file described above, containing subject identification info
+       as well as the SPKAC block.  It should then run the the ca program
+       with the -spkac option.  If it works (check the exit status),
+       return the new certificate with the appropriate MIME type.  If not,
+       return the output of the ca command with MIME type "text/plain".
+
+3      Set up your web server to accept connections signed by your demo
+       CA.  This probably involves obtaining the PEM-encoded CA certificate
+       (ordinarily in $SSLDIR/CA/cacert.pem) and installing it into a
+       server database.  See your server manual for instructions.
+
+
+==== obj.doc ========================================================
+
+The Object library.
+
+As part of my Crypto library, I found I required a method of identifying various
+objects.  These objects normally had 3 different values associated with
+them, a short text name, a long (or lower case) text name, and an
+ASN.1 Object Identifier (which is a sequence of numbers).
+This library contains a static list of objects and functions to lookup
+according to one type and to return the other types.
+
+To use these routines, 'Object.h' needs to be included.
+
+For each supported object, #define entries are defined as follows
+#define SN_Algorithm                   "Algorithm"
+#define LN_algorithm                   "algorithm"
+#define NID_algorithm                  38
+#define OBJ_algorithm                  1L,3L,14L,3L,2L
+
+SN_  stands for short name.
+LN_  stands for either long name or lowercase name.
+NID_ stands for Numeric ID.  I each object has a unique NID and this
+     should be used internally to identify objects.
+OBJ_ stands for ASN.1 Object Identifier or ASN1_OBJECT as defined in the
+     ASN1 routines.  These values are used in ASN1 encoding.
+
+The following functions are to be used to return pointers into a static
+definition of these types.  What this means is "don't try to free() any
+pointers returned from these functions.
+
+ASN1_OBJECT *OBJ_nid2obj(
+int n);
+       Return the ASN1_OBJECT that corresponds to a NID of n.
+       
+char *OBJ_nid2ln(
+int n);
+       Return the long/lower case name of the object represented by the
+       NID of n.
+       
+char *OBJ_nid2sn(
+int n);
+       Return the short name for the object represented by the NID of n.
+
+ASN1_OBJECT *OBJ_dup(
+ASN1_OBJECT *o);
+       Duplicate and return a new ASN1_OBJECT that is the same as the
+       passed parameter.
+       
+int OBJ_obj2nid(
+ASN1_OBJECT *o);
+       Given ASN1_OBJECT o, return the NID that corresponds.
+       
+int OBJ_ln2nid(
+char *s);
+       Given the long/lower case name 's', return the NID of the object.
+       
+int OBJ_sn2nid(
+char *s);
+       Given the short name 's', return the NID of the object.
+       
+char *OBJ_bsearch(
+char *key,
+char *base,
+int num,
+int size,
+int (*cmp)());
+       Since I have come across a few platforms that do not have the
+       bsearch() function, OBJ_bsearch is my version of that function.
+       Feel free to use this function, but you may as well just use the
+       normal system bsearch(3) if it is present.  This version also
+       has tolerance of being passed NULL pointers.
+
+==== keys ===========================================================
+
+EVP_PKEY_DSA
+EVP_PKEY_DSA2
+EVP_PKEY_DSA3
+EVP_PKEY_DSA4
+
+EVP_PKEY_RSA
+EVP_PKEY_RSA2
+
+valid DSA pkey types
+       NID_dsa
+       NID_dsaWithSHA
+       NID_dsaWithSHA1
+       NID_dsaWithSHA1_2
+
+valid RSA pkey types
+       NID_rsaEncryption
+       NID_rsa
+
+NID_dsaWithSHA NID_dsaWithSHA                  DSA             SHA
+NID_dsa                NID_dsaWithSHA1                 DSA             SHA1
+NID_md2                NID_md2WithRSAEncryption        RSA-pkcs1       MD2
+NID_md5                NID_md5WithRSAEncryption        RSA-pkcs1       MD5
+NID_mdc2       NID_mdc2WithRSA                 RSA-none        MDC2
+NID_ripemd160  NID_ripemd160WithRSA            RSA-pkcs1       RIPEMD160
+NID_sha                NID_shaWithRSAEncryption        RSA-pkcs1       SHA
+NID_sha1       NID_sha1WithRSAEncryption       RSA-pkcs1       SHA1
+
+==== rand.doc ========================================================
+
+My Random number library.
+
+These routines can be used to generate pseudo random numbers and can be
+used to 'seed' the pseudo random number generator (RNG).  The RNG make no
+effort to reproduce the same random number stream with each execution.
+Various other routines in the SSLeay library 'seed' the RNG when suitable
+'random' input data is available.  Read the section at the end for details
+on the design of the RNG.
+
+void RAND_bytes(
+unsigned char *buf,
+int num);
+       This routine puts 'num' random bytes into 'buf'.  One should make
+       sure RAND_seed() has been called before using this routine.
+       
+void RAND_seed(
+unsigned char *buf,
+int num);
+       This routine adds more 'seed' data the RNG state.  'num' bytes
+       are added to the RNG state, they are taken from 'buf'.  This
+       routine can be called with sensitive data such as user entered
+       passwords.  This sensitive data is in no way recoverable from
+       the RAND library routines or state.  Try to pass as much data
+       from 'random' sources as possible into the RNG via this function.
+       Also strongly consider using the RAND_load_file() and
+       RAND_write_file() routines.
+
+void RAND_cleanup();
+       When a program has finished with the RAND library, if it so
+       desires, it can 'zero' all RNG state.
+       
+The following 3 routines are convenience routines that can be used to
+'save' and 'restore' data from/to the RNG and it's state.
+Since the more 'random' data that is feed as seed data the better, why not
+keep it around between executions of the program?  Of course the
+application should pass more 'random' data in via RAND_seed() and 
+make sure no-one can read the 'random' data file.
+       
+char *RAND_file_name(
+char *buf,
+int size);
+       This routine returns a 'default' name for the location of a 'rand'
+       file.  The 'rand' file should keep a sequence of random bytes used
+       to initialise the RNG.  The filename is put in 'buf'.  Buf is 'size'
+       bytes long.  Buf is returned if things go well, if they do not,
+       NULL is returned.  The 'rand' file name is generated in the
+       following way.  First, if there is a 'RANDFILE' environment
+       variable, it is returned.  Second, if there is a 'HOME' environment
+       variable, $HOME/.rand is returned.  Third, NULL is returned.  NULL
+       is also returned if a buf would overflow.
+
+int RAND_load_file(
+char *file,
+long number);
+       This function 'adds' the 'file' into the RNG state.  It does this by
+       doing a RAND_seed() on the value returned from a stat() system call
+       on the file and if 'number' is non-zero, upto 'number' bytes read
+       from the file.  The number of bytes passed to RAND_seed() is returned.
+
+int RAND_write_file(
+char *file),
+       RAND_write_file() writes N random bytes to the file 'file', where
+       N is the size of the internal RND state (currently 1k).
+       This is a suitable method of saving RNG state for reloading via
+       RAND_load_file().
+
+What follows is a description of this RNG and a description of the rational
+behind it's design.
+
+It should be noted that this RNG is intended to be used to generate
+'random' keys for various ciphers including generation of DH and RSA keys.  
+
+It should also be noted that I have just created a system that I am happy with.
+It may be overkill but that does not worry me.  I have not spent that much
+time on this algorithm so if there are glaring errors, please let me know.
+Speed has not been a consideration in the design of these routines.
+
+First up I will state the things I believe I need for a good RNG.
+1) A good hashing algorithm to mix things up and to convert the RNG 'state'
+   to random numbers.
+2) An initial source of random 'state'.
+3) The state should be very large.  If the RNG is being used to generate
+   4096 bit RSA keys, 2 2048 bit random strings are required (at a minimum).
+   If your RNG state only has 128 bits, you are obviously limiting the
+   search space to 128 bits, not 2048.  I'm probably getting a little
+   carried away on this last point but it does indicate that it may not be
+   a bad idea to keep quite a lot of RNG state.  It should be easier to
+   break a cipher than guess the RNG seed data.
+4) Any RNG seed data should influence all subsequent random numbers
+   generated.  This implies that any random seed data entered will have
+   an influence on all subsequent random numbers generated.
+5) When using data to seed the RNG state, the data used should not be
+   extractable from the RNG state.  I believe this should be a
+   requirement because one possible source of 'secret' semi random
+   data would be a private key or a password.  This data must
+   not be disclosed by either subsequent random numbers or a
+   'core' dump left by a program crash.
+6) Given the same initial 'state', 2 systems should deviate in their RNG state
+   (and hence the random numbers generated) over time if at all possible.
+7) Given the random number output stream, it should not be possible to determine
+   the RNG state or the next random number.
+
+
+The algorithm is as follows.
+
+There is global state made up of a 1023 byte buffer (the 'state'), a
+working message digest ('md') and a counter ('count').
+
+Whenever seed data is added, it is inserted into the 'state' as
+follows.
+       The input is chopped up into units of 16 bytes (or less for
+       the last block).  Each of these blocks is run through the MD5
+       message digest.  The data passed to the MD5 digest is the
+       current 'md', the same number of bytes from the 'state'
+       (the location determined by in incremented looping index) as
+       the current 'block' and the new key data 'block'.  The result
+       of this is kept in 'md' and also xored into the 'state' at the
+       same locations that were used as input into the MD5.
+       I believe this system addresses points 1 (MD5), 3 (the 'state'),
+       4 (via the 'md'), 5 (by the use of MD5 and xor).
+
+When bytes are extracted from the RNG, the following process is used.
+For each group of 8 bytes (or less), we do the following,
+       Input into MD5, the top 8 bytes from 'md', the byte that are
+       to be overwritten by the random bytes and bytes from the
+       'state' (incrementing looping index).  From this digest output
+       (which is kept in 'md'), the top (upto) 8 bytes are
+       returned to the caller and the bottom (upto) 8 bytes are xored
+       into the 'state'.
+       Finally, after we have finished 'generation' random bytes for the
+       called, 'count' (which is incremented) and 'md' are fed into MD5 and
+       the results are kept in 'md'.
+       I believe the above addressed points 1 (use of MD5), 6 (by
+       hashing into the 'state' the 'old' data from the caller that
+       is about to be overwritten) and 7 (by not using the 8 bytes
+       given to the caller to update the 'state', but they are used
+       to update 'md').
+
+So of the points raised, only 2 is not addressed, but sources of
+random data will always be a problem.
+       
+
+==== rc2.doc ========================================================
+
+The RC2 library.
+
+RC2 is a block cipher that operates on 64bit (8 byte) quantities.  It
+uses variable size key, but 128bit (16 byte) key would normally be considered
+good.  It can be used in all the modes that DES can be used.  This
+library implements the ecb, cbc, cfb64, ofb64 modes.
+
+I have implemented this library from an article posted to sci.crypt on
+11-Feb-1996.  I personally don't know how far to trust the RC2 cipher.
+While it is capable of having a key of any size, not much reseach has
+publically been done on it at this point in time (Apr-1996)
+since the cipher has only been public for a few months :-)
+It is of a similar speed to DES and IDEA, so unless it is required for
+meeting some standard (SSLv2, perhaps S/MIME), it would probably be advisable
+to stick to IDEA, or for the paranoid, Tripple DES.
+
+Mind you, having said all that, I should mention that I just read alot and
+implement ciphers, I'm a 'babe in the woods' when it comes to evaluating
+ciphers :-).
+
+For all calls that have an 'input' and 'output' variables, they can be the
+same.
+
+This library requires the inclusion of 'rc2.h'.
+
+All of the encryption functions take what is called an RC2_KEY as an 
+argument.  An RC2_KEY is an expanded form of the RC2 key.
+For all modes of the RC2 algorithm, the RC2_KEY used for
+decryption is the same one that was used for encryption.
+
+The define RC2_ENCRYPT is passed to specify encryption for the functions
+that require an encryption/decryption flag. RC2_DECRYPT is passed to
+specify decryption.
+
+Please note that any of the encryption modes specified in my DES library
+could be used with RC2.  I have only implemented ecb, cbc, cfb64 and
+ofb64 for the following reasons.
+- ecb is the basic RC2 encryption.
+- cbc is the normal 'chaining' form for block ciphers.
+- cfb64 can be used to encrypt single characters, therefore input and output
+  do not need to be a multiple of 8.
+- ofb64 is similar to cfb64 but is more like a stream cipher, not as
+  secure (not cipher feedback) but it does not have an encrypt/decrypt mode.
+- If you want triple RC2, thats 384 bits of key and you must be totally
+  obsessed with security.  Still, if you want it, it is simple enough to
+  copy the function from the DES library and change the des_encrypt to
+  RC2_encrypt; an exercise left for the paranoid reader :-).
+
+The functions are as follows:
+
+void RC2_set_key(
+RC2_KEY *ks;
+int len;
+unsigned char *key;
+int bits;
+        RC2_set_key converts an 'len' byte key into a RC2_KEY.
+        A 'ks' is an expanded form of the 'key' which is used to
+        perform actual encryption.  It can be regenerated from the RC2 key
+        so it only needs to be kept when encryption or decryption is about
+        to occur.  Don't save or pass around RC2_KEY's since they
+        are CPU architecture dependent, 'key's are not.  RC2 is an
+       interesting cipher in that it can be used with a variable length
+       key.  'len' is the length of 'key' to be used as the key.
+       A 'len' of 16 is recomended.  The 'bits' argument is an
+       interesting addition which I only found out about in Aug 96.
+       BSAFE uses this parameter to 'limit' the number of bits used
+       for the key.  To use the 'key' unmodified, set bits to 1024.
+       This is what old versions of my RC2 library did (SSLeay 0.6.3).
+       RSAs BSAFE library sets this parameter to be 128 if 128 bit
+       keys are being used.  So to be compatable with BSAFE, set it
+       to 128, if you don't want to reduce RC2's key length, leave it
+       at 1024.
+       
+void RC2_encrypt(
+unsigned long *data,
+RC2_KEY *key,
+int encrypt);
+       This is the RC2 encryption function that gets called by just about
+       every other RC2 routine in the library.  You should not use this
+       function except to implement 'modes' of RC2.  I say this because the
+       functions that call this routine do the conversion from 'char *' to
+       long, and this needs to be done to make sure 'non-aligned' memory
+       access do not occur.
+       Data is a pointer to 2 unsigned long's and key is the
+       RC2_KEY to use.  Encryption or decryption is indicated by 'encrypt'.
+       which can have the values RC2_ENCRYPT or RC2_DECRYPT.
+
+void RC2_ecb_encrypt(
+unsigned char *in,
+unsigned char *out,
+RC2_KEY *key,
+int encrypt);
+       This is the basic Electronic Code Book form of RC2 (in DES this
+       mode is called Electronic Code Book so I'm going to use the term
+       for rc2 as well.
+       Input is encrypted into output using the key represented by
+       key.  Depending on the encrypt, encryption or
+       decryption occurs.  Input is 8 bytes long and output is 8 bytes.
+       
+void RC2_cbc_encrypt(
+unsigned char *in,
+unsigned char *out,
+long length,
+RC2_KEY *ks,
+unsigned char *ivec,
+int encrypt);
+       This routine implements RC2 in Cipher Block Chaining mode.
+       Input, which should be a multiple of 8 bytes is encrypted
+       (or decrypted) to output which will also be a multiple of 8 bytes.
+       The number of bytes is in length (and from what I've said above,
+       should be a multiple of 8).  If length is not a multiple of 8, bad 
+       things will probably happen.  ivec is the initialisation vector.
+       This function updates iv after each call so that it can be passed to
+       the next call to RC2_cbc_encrypt().
+       
+void RC2_cfb64_encrypt(
+unsigned char *in,
+unsigned char *out,
+long length,
+RC2_KEY *schedule,
+unsigned char *ivec,
+int *num,
+int encrypt);
+       This is one of the more useful functions in this RC2 library, it
+       implements CFB mode of RC2 with 64bit feedback.
+       This allows you to encrypt an arbitrary number of bytes,
+       you do not require 8 byte padding.  Each call to this
+       routine will encrypt the input bytes to output and then update ivec
+       and num.  Num contains 'how far' we are though ivec.
+       'Encrypt' is used to indicate encryption or decryption.
+       CFB64 mode operates by using the cipher to generate a stream
+       of bytes which is used to encrypt the plain text.
+       The cipher text is then encrypted to generate the next 64 bits to
+       be xored (incrementally) with the next 64 bits of plain
+       text.  As can be seen from this, to encrypt or decrypt,
+       the same 'cipher stream' needs to be generated but the way the next
+       block of data is gathered for encryption is different for
+       encryption and decryption.
+       
+void RC2_ofb64_encrypt(
+unsigned char *in,
+unsigned char *out,
+long length,
+RC2_KEY *schedule,
+unsigned char *ivec,
+int *num);
+       This functions implements OFB mode of RC2 with 64bit feedback.
+       This allows you to encrypt an arbitrary number of bytes,
+       you do not require 8 byte padding.  Each call to this
+       routine will encrypt the input bytes to output and then update ivec
+       and num.  Num contains 'how far' we are though ivec.
+       This is in effect a stream cipher, there is no encryption or
+       decryption mode.
+       
+For reading passwords, I suggest using des_read_pw_string() from my DES library.
+To generate a password from a text string, I suggest using MD5 (or MD2) to
+produce a 16 byte message digest that can then be passed directly to
+RC2_set_key().
+
+=====
+For more information about the specific RC2 modes in this library
+(ecb, cbc, cfb and ofb), read the section entitled 'Modes of DES' from the
+documentation on my DES library.  What is said about DES is directly
+applicable for RC2.
+
+
+==== rc4.doc ========================================================
+
+The RC4 library.
+RC4 is a stream cipher that operates on a byte stream.  It can be used with
+any length key but I would recommend normally using 16 bytes.
+
+This library requires the inclusion of 'rc4.h'.
+
+The RC4 encryption function takes what is called an RC4_KEY as an argument.
+The RC4_KEY is generated by the RC4_set_key function from the key bytes.
+
+RC4, being a stream cipher, does not have an encryption or decryption mode.
+It produces a stream of bytes that the input stream is xor'ed against and
+so decryption is just a case of 'encrypting' again with the same key.
+
+I have only put in one 'mode' for RC4 which is the normal one.  This means
+there is no initialisation vector and there is no feedback of the cipher
+text into the cipher.  This implies that you should not ever use the
+same key twice if you can help it.  If you do, you leave yourself open to
+known plain text attacks; if you know the plain text and
+corresponding cipher text in one message, all messages that used the same
+key can have the cipher text decoded for the corresponding positions in the
+cipher stream.
+
+The main positive feature of RC4 is that it is a very fast cipher; about 4
+times faster that DES.  This makes it ideally suited to protocols where the
+key is randomly chosen, like SSL.
+
+The functions are as follows:
+
+void RC4_set_key(
+RC4_KEY *key;
+int len;
+unsigned char *data);
+       This function initialises the RC4_KEY structure with the key passed
+       in 'data', which is 'len' bytes long.  The key data can be any
+       length but 16 bytes seems to be a good number.
+
+void RC4(
+RC4_KEY *key;
+unsigned long len;
+unsigned char *in;
+unsigned char *out);
+       Do the actual RC4 encryption/decryption.  Using the 'key', 'len'
+       bytes are transformed from 'in' to 'out'.  As mentioned above,
+       decryption is the operation as encryption.
+
+==== ref.doc ========================================================
+
+I have lots more references etc, and will update this list in the future,
+30 Aug 1996 - eay
+
+
+SSL    The SSL Protocol - from Netscapes.
+
+RC4    Newsgroups: sci.crypt
+       From: sterndark@netcom.com (David Sterndark)
+       Subject: RC4 Algorithm revealed.
+       Message-ID: <sternCvKL4B.Hyy@netcom.com>
+
+RC2    Newsgroups: sci.crypt
+       From: pgut01@cs.auckland.ac.nz (Peter Gutmann)
+       Subject: Specification for Ron Rivests Cipher No.2
+       Message-ID: <4fk39f$f70@net.auckland.ac.nz>
+
+MD2    RFC1319 The MD2 Message-Digest Algorithm
+MD5    RFC1321 The MD5 Message-Digest Algorithm
+
+X509 Certificates
+       RFC1421 Privacy Enhancement for Internet Electronic Mail: Part I
+       RFC1422 Privacy Enhancement for Internet Electronic Mail: Part II
+       RFC1423 Privacy Enhancement for Internet Electronic Mail: Part III
+       RFC1424 Privacy Enhancement for Internet Electronic Mail: Part IV
+
+RSA and various standard encoding
+       PKCS#1 RSA Encryption Standard
+       PKCS#5 Password-Based Encryption Standard
+       PKCS#7 Cryptographic Message Syntax Standard
+       A Layman's Guide to a Subset of ASN.1, BER, and DER
+       An Overview of the PKCS Standards
+       Some Examples of the PKCS Standards
+
+IDEA   Chapter 3 The Block Cipher IDEA
+
+RSA, prime number generation and bignum algorithms
+       Introduction To Algorithms,
+       Thomas Cormen, Charles Leiserson, Ronald Rivest,
+       Section 29 Arithmetic Circuits
+       Section 33 Number-Theoretic Algorithms
+
+Fast Private Key algorithm
+       Fast Decipherment Algorithm for RSA Public-Key Cryptosystem
+       J.-J. Quisquater and C. Couvreur, Electronics Letters,
+       14th October 1982, Vol. 18 No. 21
+
+Prime number generation and bignum algorithms.
+       PGP-2.3a
+
+==== rsa.doc ========================================================
+
+The RSA encryption and utility routines.
+
+The RSA routines are built on top of a big number library (the BN library).
+There are support routines in the X509 library for loading and manipulating
+the various objects in the RSA library.  When errors are returned, read
+about the ERR library for how to access the error codes.
+
+All RSA encryption is done according to the PKCS-1 standard which is
+compatible with PEM and RSAref.  This means that any values being encrypted
+must be less than the size of the modulus in bytes, minus 10, bytes long.
+
+This library uses RAND_bytes()() for it's random data, make sure to feed
+RAND_seed() with lots of interesting and varied data before using these
+routines.
+
+The RSA library has one specific data type, the RSA structure.
+It is composed of 8 BIGNUM variables (see the BN library for details) and
+can hold either a private RSA key or a public RSA key.
+Some RSA libraries have different structures for public and private keys, I
+don't.  For my libraries, a public key is determined by the fact that the
+RSA->d value is NULL.  These routines will operate on any size RSA keys.
+While I'm sure 4096 bit keys are very very secure, they take a lot longer
+to process that 1024 bit keys :-).
+
+The function in the RSA library are as follows.
+
+RSA *RSA_new();
+       This function creates a new RSA object.  The sub-fields of the RSA
+       type are also malloced so you should always use this routine to
+       create RSA variables.
+       
+void RSA_free(
+RSA *rsa);
+       This function 'frees' an RSA structure.  This routine should always
+       be used to free the RSA structure since it will also 'free' any
+       sub-fields of the RSA type that need freeing.
+       
+int RSA_size(
+RSA *rsa);     
+       This function returns the size of the RSA modulus in bytes.  Why do
+       I need this you may ask, well the reason is that when you encrypt
+       with RSA, the output string will be the size of the RSA modulus.
+       So the output for the RSA_encrypt and the input for the RSA_decrypt
+       routines need to be RSA_size() bytes long, because this is how many
+       bytes are expected.
+       
+For the following 4 RSA encryption routines, it should be noted that
+RSA_private_decrypt() should be used on the output from 
+RSA_public_encrypt() and RSA_public_decrypt() should be used on
+the output from RSA_private_encrypt().
+       
+int RSA_public_encrypt(
+int from_len;
+unsigned char *from    
+unsigned char *to      
+RSA *rsa);
+       This function implements RSA public encryption, the rsa variable
+       should be a public key (but can be a private key).  'from_len'
+       bytes taken from 'from' and encrypted and put into 'to'.  'to' needs
+       to be at least RSA_size(rsa) bytes long.  The number of bytes
+       written into 'to' is returned.  -1 is returned on an error.  The
+       operation performed is
+       to = from^rsa->e mod rsa->n.
+       
+int RSA_private_encrypt(
+int from_len;
+unsigned char *from    
+unsigned char *to      
+RSA *rsa);
+       This function implements RSA private encryption, the rsa variable
+       should be a private key.  'from_len' bytes taken from
+       'from' and encrypted and put into 'to'.  'to' needs
+       to be at least RSA_size(rsa) bytes long.  The number of bytes
+       written into 'to' is returned.  -1 is returned on an error.  The
+       operation performed is
+       to = from^rsa->d mod rsa->n.
+
+int RSA_public_decrypt(
+int from_len;
+unsigned char *from    
+unsigned char *to      
+RSA *rsa);
+       This function implements RSA public decryption, the rsa variable
+       should be a public key (but can be a private key).  'from_len'
+       bytes are taken from 'from' and decrypted.  The decrypted data is
+       put into 'to'.  The number of bytes encrypted is returned.  -1 is
+       returned to indicate an error. The operation performed is
+       to = from^rsa->e mod rsa->n.
+
+int RSA_private_decrypt(
+int from_len;
+unsigned char *from    
+unsigned char *to      
+RSA *rsa);
+       This function implements RSA private decryption, the rsa variable
+       should be a private key.  'from_len' bytes are taken
+       from 'from' and decrypted.  The decrypted data is
+       put into 'to'.  The number of bytes encrypted is returned.  -1 is
+       returned to indicate an error. The operation performed is
+       to = from^rsa->d mod rsa->n.
+
+int RSA_mod_exp(
+BIGNUM *n;
+BIGNUM *p;
+RSA *rsa);
+       Normally you will never use this routine.
+       This is really an internal function which is called by
+       RSA_private_encrypt() and RSA_private_decrypt().  It performs
+       n=n^p mod rsa->n except that it uses the 5 extra variables in the
+       RSA structure to make this more efficient.
+       
+RSA *RSA_generate_key(
+int bits;
+unsigned long e;
+void (*callback)();
+char *cb_arg;
+       This routine is used to generate RSA private keys.  It takes
+       quite a period of time to run and should only be used to
+       generate initial private keys that should then be stored
+       for later use.  The passed callback function 
+       will be called periodically so that feedback can be given
+       as to how this function is progressing.
+       'bits' is the length desired for the modulus, so it would be 1024
+       to generate a 1024 bit private key.
+       'e' is the value to use for the public exponent 'e'.  Traditionally
+       it is set to either 3 or 0x10001.
+       The callback function (if not NULL) is called in the following
+       situations.
+       when we have generated a suspected prime number to test,
+       callback(0,num1++,cb_arg).  When it passes a prime number test,
+       callback(1,num2++,cb_arg).  When it is rejected as one of
+       the 2 primes required due to gcd(prime,e value) != 0,
+       callback(2,num3++,cb_arg).  When finally accepted as one
+       of the 2 primes, callback(3,num4++,cb_arg).
+
+
+==== rsaref.doc ========================================================
+
+This package can be compiled to use the RSAref library.
+This library is not allowed outside of the USA but inside the USA it is
+claimed by RSA to be the only RSA public key library that can be used
+besides BSAFE..
+
+There are 2 files, rsaref/rsaref.c and rsaref/rsaref.h that contain the glue
+code to use RSAref.  These files were written by looking at the PGP
+source code and seeing which routines it used to access RSAref.
+I have also been sent by some-one a copy of the RSAref header file that
+contains the library error codes.
+
+[ Jun 1996 update - I have recently gotten hold of RSAref 2.0 from
+  South Africa and have been doing some performace tests. ]
+       
+They have now been tested against the recently announced RSAEURO
+library.
+
+There are 2 ways to use SSLeay and RSAref.  First, to build so that
+the programs must be linked with RSAref, add '-DRSAref' to CFLAG in the top
+level makefile and -lrsaref (or where ever you are keeping RSAref) to
+EX_LIBS.
+
+To build a makefile via util/mk1mf.pl to do this, use the 'rsaref' option.
+
+The second method is to build as per normal and link applications with
+the RSAglue library.  The correct library order would be
+cc -o cmd cmd.o -lssl -lRSAglue -lcrypto -lrsaref -ldes
+The RSAglue library is built in the rsa directory and is NOT
+automatically installed.
+
+Be warned that the RSAEURO library, that is claimed to be compatible
+with RSAref contains a different value for the maximum number of bits
+supported.  This changes structure sizes and so if you are using
+RSAEURO, change the value of RSAref_MAX_BITS in rsa/rsaref.h
+
+
+==== s_mult.doc ========================================================
+
+s_mult is a test program I hacked up on a Sunday for testing non-blocking
+IO.  It has a select loop at it's centre that handles multiple readers
+and writers.
+
+Try the following command
+ssleay s_mult -echo -nbio -ssl -v
+echo - sends any sent text back to the sender
+nbio - turns on non-blocking IO
+ssl  - accept SSL connections, default is normal text
+v    - print lots
+       type Q<cr> to quit
+
+In another window, run the following
+ssleay s_client -pause </etc/termcap
+
+The pause option puts in a 1 second pause in each read(2)/write(2) call
+so the other end will have read()s fail.
+
+==== session.doc ========================================================
+
+I have just checked over and re-worked the session stuff.
+The following brief example will ignore all setup information to do with
+authentication.
+
+Things operate as follows.
+
+The SSL environment has a 'context', a SSL_CTX structure.  This holds the
+cached SSL_SESSIONS (which can be reused) and the certificate lookup
+information.  Each SSL structure needs to be associated with a SSL_CTX.
+Normally only one SSL_CTX structure is needed per program.
+
+SSL_CTX *SSL_CTX_new(void ); 
+void    SSL_CTX_free(SSL_CTX *);
+These 2 functions create and destroy SSL_CTX structures
+
+The SSL_CTX has a session_cache_mode which is by default,
+in SSL_SESS_CACHE_SERVER mode.  What this means is that the library
+will automatically add new session-id's to the cache upon successful
+SSL_accept() calls.
+If SSL_SESS_CACHE_CLIENT is set, then client certificates are also added
+to the cache.
+SSL_set_session_cache_mode(ctx,mode)  will set the 'mode' and
+SSL_get_session_cache_mode(ctx) will get the cache 'mode'.
+The modes can be
+SSL_SESS_CACHE_OFF     - no caching
+SSL_SESS_CACHE_CLIENT  - only SSL_connect()
+SSL_SESS_CACHE_SERVER  - only SSL_accept()
+SSL_SESS_NO_CACHE_BOTH - Either SSL_accept() or SSL_connect().
+If SSL_SESS_CACHE_NO_AUTO_CLEAR is set, old timed out sessions are
+not automatically removed each 255, SSL_connect()s or SSL_accept()s.
+
+By default, upon every 255 successful SSL_connect() or SSL_accept()s,
+the cache is flush.  Please note that this could be expensive on
+a heavily loaded SSL server, in which case, turn this off and
+clear the cache of old entries 'manually' (with one of the functions
+listed below) every few hours.  Perhaps I should up this number, it is hard
+to say.  Remember, the '255' new calls is just a mechanism to get called
+every now and then, in theory at most 255 new session-id's will have been
+added but if 100 are added every minute, you would still have
+500 in the cache before any would start being flushed (assuming a 3 minute
+timeout)..
+
+int SSL_CTX_sess_hits(SSL_CTX *ctx);
+int SSL_CTX_sess_misses(SSL_CTX *ctx);
+int SSL_CTX_sess_timeouts(SSL_CTX *ctx);
+These 3 functions return statistics about the SSL_CTX.  These 3 are the
+number of session id reuses.  hits is the number of reuses, misses are the
+number of lookups that failed, and timeouts is the number of cached
+entries ignored because they had timeouted.
+
+ctx->new_session_cb is a function pointer to a function of type
+int new_session_callback(SSL *ssl,SSL_SESSION *new);
+This function, if set in the SSL_CTX structure is called whenever a new
+SSL_SESSION is added to the cache.  If the callback returns non-zero, it
+means that the application will have to do a SSL_SESSION_free()
+on the structure (this is
+to do with the cache keeping the reference counts correct, without the
+application needing to know about it.
+The 'active' parameter is the current SSL session for which this connection
+was created.
+
+void SSL_CTX_sess_set_new_cb(SSL_CTX *ctx,int (*cb)());
+to set the callback,
+int (*cb)() SSL_CTX_sess_get_new_cb(SSL_CTX *ctx)
+to get the callback.
+
+If the 'get session' callback is set, when a session id is looked up and
+it is not in the session-id cache, this callback is called.  The callback is
+of the form
+SSL_SESSION *get_session_callback(unsigned char *sess_id,int sess_id_len,
+       int *copy);
+
+The get_session_callback is intended to return null if no session id is found.
+The reference count on the SSL_SESSION in incremented by the SSL library,
+if copy is 1.  Otherwise, the reference count is not modified.
+
+void SSL_CTX_sess_set_get_cb(ctx,cb) sets the callback and
+int (*cb)()SSL_CTX_sess_get_get_cb(ctx) returns the callback.
+
+These callbacks are basically intended to be used by processes to
+send their session-id's to other processes.  I currently have not implemented
+non-blocking semantics for these callbacks, it is upto the application
+to make the callbacks efficient if they require blocking (perhaps
+by 'saving' them and then 'posting them' when control returns from
+the SSL_accept().
+
+LHASH *SSL_CTX_sessions(SSL_CTX *ctx)
+This returns the session cache.  The lhash strucutre can be accessed for
+statistics about the cache.
+
+void lh_stats(LHASH *lh, FILE *out);
+void lh_node_stats(LHASH *lh, FILE *out);
+void lh_node_usage_stats(LHASH *lh, FILE *out);
+
+can be used to print details about it's activity and current state.
+You can also delve directly into the lhash structure for 14 different
+counters that are kept against the structure.  When I wrote the lhash library,
+I was interested in gathering statistics :-).
+Have a read of doc/lhash.doc in the SSLeay distribution area for more details
+on the lhash library.
+
+Now as mentioned ealier, when a SSL is created, it needs a SSL_CTX.
+SSL *   SSL_new(SSL_CTX *);
+
+This stores a session.  A session is secret information shared between 2
+SSL contexts.  It will only be created if both ends of the connection have
+authenticated their peer to their satisfaction.  It basically contains
+the information required to use a particular secret key cipher.
+
+To retrieve the SSL_CTX being used by a SSL,
+SSL_CTX *SSL_get_SSL_CTX(SSL *s);
+
+Now when a SSL session is established between to programs, the 'session'
+information that is cached in the SSL_CTX can me manipulated by the
+following functions.
+int SSL_set_session(SSL *s, SSL_SESSION *session);
+This will set the SSL_SESSION to use for the next SSL_connect().  If you use
+this function on an already 'open' established SSL connection, 'bad things
+will happen'.  This function is meaning-less when used on a ssl strucutre
+that is just about to be used in a SSL_accept() call since the
+SSL_accept() will either create a new session or retrieve one from the
+cache.
+
+SSL_SESSION *SSL_get_session(SSL *s);
+This will return the SSL_SESSION for the current SSL, NULL if there is
+no session associated with the SSL structure.
+
+The SSL sessions are kept in the SSL_CTX in a hash table, to remove a
+session
+void    SSL_CTX_remove_session(SSL_CTX *,SSL_SESSION *c);
+and to add one
+int    SSL_CTX_add_session(SSL_CTX *s, SSL_SESSION *c);
+SSL_CTX_add_session() returns 1 if the session was already in the cache (so it
+was not added).
+Whenever a new session is created via SSL_connect()/SSL_accept(),
+they are automatically added to the cache, depending on the session_cache_mode
+settings.  SSL_set_session()
+does not add it to the cache.  Just call SSL_CTX_add_session() if you do want the
+session added.  For a 'client' this would not normally be the case.
+SSL_CTX_add_session() is not normally ever used, except for doing 'evil' things
+which the next 2 funtions help you do.
+
+int     i2d_SSL_SESSION(SSL_SESSION *in,unsigned char **pp);
+SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a,unsigned char **pp,long length);
+These 2 functions are in the standard ASN1 library form and can be used to
+load and save to a byte format, the SSL_SESSION structure.
+With these functions, you can save and read these structures to a files or
+arbitary byte string.
+The PEM_write_SSL_SESSION(fp,x) and PEM_read_SSL_SESSION(fp,x,cb) will
+write to a file pointer in base64 encoding.
+
+What you can do with this, is pass session information between separate
+processes.  Please note, that you will probably also need to modify the
+timeout information on the SSL_SESSIONs.
+
+long SSL_get_time(SSL_SESSION *s)
+will return the 'time' that the session
+was loaded.  The timeout is relative to this time.  This information is
+saved when the SSL_SESSION is converted to binarary but it is stored
+in as a unix long, which is rather OS dependant, but easy to convert back.
+
+long SSL_set_time(SSL_SESSION *s,long t) will set the above mentioned time.
+The time value is just the value returned from time(3), and should really
+be defined by be to be time_t.
+
+long SSL_get_timeout(SSL_SESSION *s);
+long SSL_set_timeout(SSL_SESSION *s,long t);
+These 2 retrieve and set the timeout which is just a number of secconds
+from the 'SSL_get_time()' value.  When this time period has elapesed,
+the session will no longer be in the cache (well it will actually be removed
+the next time it is attempted to be retrieved, so you could 'bump'
+the timeout so it remains valid).
+The 'time' and 'timeout' are set on a session when it is created, not reset
+each time it is reused.  If you did wish to 'bump it', just after establishing
+a connection, do a
+SSL_set_time(ssl,time(NULL));
+
+You can also use
+SSL_CTX_set_timeout(SSL_CTX *ctx,unsigned long t) and
+SSL_CTX_get_timeout(SSL_CTX *ctx) to manipulate the default timeouts for
+all SSL connections created against a SSL_CTX.  If you set a timeout in
+an SSL_CTX, all new SSL's created will inherit the timeout.  It can be over
+written by the SSL_set_timeout(SSL *s,unsigned long t) function call.
+If you 'set' the timeout back to 0, the system default will be used.
+
+SSL_SESSION *SSL_SESSION_new();
+void SSL_SESSION_free(SSL_SESSION *ses);
+These 2 functions are used to create and dispose of SSL_SESSION functions.
+You should not ever normally need to use them unless you are using 
+i2d_SSL_SESSION() and/or d2i_SSL_SESSION().  If you 'load' a SSL_SESSION
+via d2i_SSL_SESSION(), you will need to SSL_SESSION_free() it.
+Both SSL_set_session() and SSL_CTX_add_session() will 'take copies' of the
+structure (via reference counts) when it is passed to them.
+
+SSL_CTX_flush_sessions(ctx,time);
+The first function will clear all sessions from the cache, which have expired
+relative to 'time' (which could just be time(NULL)).
+
+SSL_CTX_flush_sessions(ctx,0);
+This is a special case that clears everything.
+
+As a final comment, a 'session' is not enough to establish a new
+connection.  If a session has timed out, a certificate and private key
+need to have been associated with the SSL structure.
+SSL_copy_session_id(SSL *to,SSL *from); will copy not only the session
+strucutre but also the private key and certificate associated with
+'from'.
+
+EXAMPLES.
+
+So lets play at being a weird SSL server.
+
+/* setup a context */
+ctx=SSL_CTX_new();
+
+/* Lets load some session from binary into the cache, why one would do
+ * this is not toally clear, but passing between programs does make sense
+ * Perhaps you are using 4096 bit keys and are happy to keep them
+ * valid for a week, to avoid the RSA overhead of 15 seconds, I'm not toally
+ * sure, perhaps this is a process called from an SSL inetd and this is being 
+ * passed to the application. */
+session=d2i_SSL_SESSION(....)
+SSL_CTX_add_session(ctx,session);
+
+/* Lets even add a session from a file */
+session=PEM_read_SSL_SESSION(....)
+SSL_CTX_add_session(ctx,session);
+
+/* create a new SSL structure */
+ssl=SSL_new(ctx);
+
+/* At this point we want to be able to 'create' new session if
+ * required, so we need a certificate and RSAkey. */
+SSL_use_RSAPrivateKey_file(ssl,...)
+SSL_use_certificate_file(ssl,...)
+
+/* Now since we are a server, it make little sence to load a session against
+ * the ssl strucutre since a SSL_accept() will either create a new session or
+ * grab an existing one from the cache. */
+
+/* grab a socket descriptor */
+fd=accept(...);
+
+/* associated it with the ssl strucutre */
+SSL_set_fd(ssl,fd);
+
+SSL_accept(ssl); /* 'do' SSL using out cert and RSA key */
+
+/* Lets print out the session details or lets save it to a file,
+ * perhaps with a secret key cipher, so that we can pass it to the FBI
+ * when they want to decode the session :-).  While we have RSA
+ * this does not matter much but when I do SSLv3, this will allow a mechanism
+ * for the server/client to record the information needed to decode
+ * the traffic that went over the wire, even when using Diffie-Hellman */
+PEM_write_SSL_SESSION(SSL_get_session(ssl),stdout,....)
+
+Lets 'connect' back to the caller using the same session id.
+
+ssl2=SSL_new(ctx);
+fd2=connect(them);
+SSL_set_fd(ssl2,fd2);
+SSL_set_session(ssl2,SSL_get_session(ssl));
+SSL_connect(ssl2);
+
+/* what the hell, lets accept no more connections using this session */
+SSL_CTX_remove_session(SSL_get_SSL_CTX(ssl),SSL_get_session(ssl));
+
+/* we could have just as easily used ssl2 since they both are using the
+ * same session.
+ * You will note that both ssl and ssl2 are still using the session, and
+ * the SSL_SESSION structure will be free()ed when both ssl and ssl2
+ * finish using the session.  Also note that you could continue to initiate
+ * connections using this session by doing SSL_get_session(ssl) to get the
+ * existing session, but SSL_accept() will not be able to find it to
+ * use for incoming connections.
+ * Of corse, the session will timeout at the far end and it will no
+ * longer be accepted after a while.  The time and timeout are ignored except
+ * by SSL_accept(). */
+
+/* Since we have had our server running for 10 weeks, and memory is getting
+ * short, perhaps we should clear the session cache to remove those
+ * 100000 session entries that have expired.  Some may consider this
+ * a memory leak :-) */
+
+SSL_CTX_flush_sessions(ctx,time(NULL));
+
+/* Ok, after a bit more time we wish to flush all sessions from the cache
+ * so that all new connections will be authenticated and incure the
+ * public key operation overhead */
+
+SSL_CTX_flush_sessions(ctx,0);
+
+/* As a final note, to copy everything to do with a SSL, use */
+SSL_copy_session_id(SSL *to,SSL *from);
+/* as this also copies the certificate and RSA key so new session can
+ * be established using the same details */
+
+
+==== sha.doc ========================================================
+
+The SHA (Secure Hash Algorithm) library.
+SHA is a message digest algorithm that can be used to condense an arbitrary
+length message down to a 20 byte hash.  The functions all need to be passed
+a SHA_CTX which is used to hold the SHA context during multiple SHA_Update()
+function calls.  The normal method of use for this library is as follows
+This library contains both SHA and SHA-1 digest algorithms.  SHA-1 is
+an update to SHA (which should really be called SHA-0 now) which
+tweaks the algorithm slightly.  The SHA-1 algorithm is used by simply
+using SHA1_Init(), SHA1_Update(), SHA1_Final() and SHA1() instead of the
+SHA*() calls
+
+SHA_Init(...);
+SHA_Update(...);
+...
+SHA_Update(...);
+SHA_Final(...);
+
+This library requires the inclusion of 'sha.h'.
+
+The functions are as follows:
+
+void SHA_Init(
+SHA_CTX *c);
+       This function needs to be called to initiate a SHA_CTX structure for
+       use.
+       
+void SHA_Update(
+SHA_CTX *c;
+unsigned char *data;
+unsigned long len);
+       This updates the message digest context being generated with 'len'
+       bytes from the 'data' pointer.  The number of bytes can be any
+       length.
+
+void SHA_Final(
+unsigned char *md;
+SHA_CTX *c;
+       This function is called when a message digest of the data digested
+       with SHA_Update() is wanted.  The message digest is put in the 'md'
+       array and is SHA_DIGEST_LENGTH (20) bytes long.
+
+unsigned char *SHA(
+unsigned char *d;
+unsigned long n;
+unsigned char *md;
+       This function performs a SHA_Init(), followed by a SHA_Update()
+       followed by a SHA_Final() (using a local SHA_CTX).
+       The resulting digest is put into 'md' if it is not NULL.
+       Regardless of the value of 'md', the message
+       digest is returned from the function.  If 'md' was NULL, the message
+       digest returned is being stored in a static structure.
+       
+
+==== speed.doc ========================================================
+
+To get an idea of the performance of this library, use
+ssleay speed
+
+perl util/sp-diff.pl file1 file2
+
+will print out the relative differences between the 2 files which are
+expected to be the output from the speed program.
+
+The performace of the library is very dependant on the Compiler
+quality and various flags used to build.
+
+---
+
+These are some numbers I did comparing RSAref and SSLeay on a Pentium 100.
+[ These numbers are all out of date, as of SSL - 0.6.1 the RSA
+operations are about 2 times faster, so check the version number ]
+
+RSA performance.
+
+SSLeay 0.6.0
+Pentium 100, 32meg, Windows NT Workstation 3.51
+linux - gcc v 2.7.0 -O3 -fomit-frame-pointer -m486
+and
+Windows NT  - Windows NT 3.51 - Visual C++ 4.1   - 586 code + 32bit assember
+Windows 3.1 - Windows NT 3.51 - Visual C++ 1.52c - 286 code + 32bit assember
+NT Dos Shell- Windows NT 3.51 - Visual C++ 1.52c - 286 code + 16bit assember
+
+Times are how long it takes to do an RSA private key operation.
+
+              512bits 1024bits
+-------------------------------
+SSLeay NT dll  0.042s   0.202s see above
+SSLeay linux   0.046s   0.218s Assember inner loops (normal build) 
+SSLeay linux   0.067s   0.380s Pure C code with BN_LLONG defined
+SSLeay W3.1 dll        0.108s   0.478s see above
+SSLeay linux   0.109s   0.713s C without BN_LLONG.
+RSAref2.0 linux        0.149s   0.936s
+SSLeay MS-DOS  0.197s   1.049s see above
+
+486DX66, 32meg, Windows NT Server 3.51
+              512bits 1024bits
+-------------------------------
+SSLeay NT dll   0.084s  0.495s <- SSLeay 0.6.3
+SSLeay NT dll   0.154s   0.882s
+SSLeay W3.1 dll 0.335s   1.538s
+SSLeay MS-DOS  0.490s   2.790s
+
+What I find cute is that I'm still faster than RSAref when using standard C,
+without using the 'long long' data type :-), %35 faster for 512bit and we
+scale up to 3.2 times faster for the 'default linux' build.  I should mention
+that people should 'try' to use either x86-lnx.s (elf), x86-lnxa.s or
+x86-sol.s for any x86 based unix they are building on.  The only problems
+with be with syntax but the performance gain is quite large, especially for
+servers.  The code is very simple, you just need to modify the 'header'.
+
+The message is, if you are stuck using RSAref, the RSA performance will be
+bad. Considering the code was compiled for a pentium, the 486DX66 number
+would indicate 'Use RSAref and turn you Pentium 100 into a 486DX66' :-). 
+[ As of verson 0.6.1, it would be correct to say 'turn you pentium 100
+ into a 486DX33' :-) ]
+
+I won't tell people if the DLL's are using RSAref or my stuff if no-one
+asks :-).
+
+eric
+
+PS while I know I could speed things up further, I will probably not do
+   so due to the effort involved.  I did do some timings on the
+   SSLeay bignum format -> RSAref number format conversion that occurs
+   each time RSAref is used by SSLeay, and the numbers are trivial.
+   0.00012s a call for 512bit vs 0.149s for the time spent in the function.
+   0.00018s for 1024bit vs 0.938s.  Insignificant.
+   So the 'way to go', to support faster RSA libraries, if people are keen,
+   is to write 'glue' code in a similar way that I do for RSAref and send it
+   to me :-).
+   My base library still has the advantage of being able to operate on 
+   any size numbers, and is not that far from the performance from the
+   leaders in the field. (-%30?)
+   [ Well as of 0.6.1 I am now the leader in the filed on x86 (we at
+     least very close :-) ]
+
+   I suppose I should also mention some other numbers RSAref numbers, again
+   on my Pentium.
+               DES CBC         EDE-DES         MD5
+   RSAref linux         830k/s          302k/s         4390k/s
+   SSLeay linux  855k/s          319k/s        10025k/s
+   SSLeay NT   1158k/s          410k/s        10470k/s
+   SSLeay w31   378k/s          143k/s         2383k/s (fully 16bit)
+
+   Got to admit that Visual C++ 4.[01] is a damn fine compiler :-)
+--
+Eric Young                  | BOOL is tri-state according to Bill Gates.
+AARNet: eay@cryptsoft.com   | RTFM Win32 GetMessage().
+
+
+
+
+==== ssl-ciph.doc ========================================================
+
+This is a quick high level summery of how things work now.
+
+Each SSLv2 and SSLv3 cipher is composed of 4 major attributes plus a few extra
+minor ones.
+
+They are 'The key exchange algorithm', which is RSA for SSLv2 but can also
+be Diffle-Hellman for SSLv3.
+
+An 'Authenticion algorithm', which can be RSA, Diffle-Helman, DSS or
+none.
+
+The cipher
+
+The MAC digest.
+
+A cipher can also be an export cipher and is either an SSLv2 or a
+SSLv3 ciphers.
+
+To specify which ciphers to use, one can either specify all the ciphers,
+one at a time, or use 'aliases' to specify the preference and order for
+the ciphers.
+
+There are a large number of aliases, but the most importaint are
+kRSA, kDHr, kDHd and kEDH for key exchange types.
+
+aRSA, aDSS, aNULL and aDH for authentication
+DES, 3DES, RC4, RC2, IDEA and eNULL for ciphers
+MD5, SHA0 and SHA1 digests
+
+Now where this becomes interesting is that these can be put together to
+specify the order and ciphers you wish to use.
+
+To speed this up there are also aliases for certian groups of ciphers.
+The main ones are
+SSLv2  - all SSLv2 ciphers
+SSLv3  - all SSLv3 ciphers
+EXP    - all export ciphers
+LOW    - all low strngth ciphers (no export ciphers, normally single DES)
+MEDIUM - 128 bit encryption
+HIGH   - Triple DES
+
+These aliases can be joined in a : separated list which specifies to
+add ciphers, move them to the current location and delete them.
+
+A simpler way to look at all of this is to use the 'ssleay ciphers -v' command.
+The default library cipher spec is
+!ADH:RC4+RSA:HIGH:MEDIUM:LOW:EXP:+SSLv2:+EXP
+which means, first, remove from consideration any ciphers that do not
+authenticate.  Next up, use ciphers using RC4 and RSA.  Next include the HIGH,
+MEDIUM and the LOW security ciphers.  Finish up by adding all the export
+ciphers on the end, then 'pull' all the SSLv2 and export ciphers to
+the end of the list.
+
+The results are
+$ ssleay ciphers -v '!ADH:RC4+RSA:HIGH:MEDIUM:LOW:EXP:+SSLv2:+EXP'
+
+RC4-SHA                 SSLv3 Kx=RSA      Au=RSA  Enc=RC4(128)  Mac=SHA1
+RC4-MD5                 SSLv3 Kx=RSA      Au=RSA  Enc=RC4(128)  Mac=MD5 
+EDH-RSA-DES-CBC3-SHA    SSLv3 Kx=DH       Au=RSA  Enc=3DES(168) Mac=SHA1
+EDH-DSS-DES-CBC3-SHA    SSLv3 Kx=DH       Au=DSS  Enc=3DES(168) Mac=SHA1
+DES-CBC3-SHA            SSLv3 Kx=RSA      Au=RSA  Enc=3DES(168) Mac=SHA1
+IDEA-CBC-MD5            SSLv3 Kx=RSA      Au=RSA  Enc=IDEA(128) Mac=SHA1
+EDH-RSA-DES-CBC-SHA     SSLv3 Kx=DH       Au=RSA  Enc=DES(56)   Mac=SHA1
+EDH-DSS-DES-CBC-SHA     SSLv3 Kx=DH       Au=DSS  Enc=DES(56)   Mac=SHA1
+DES-CBC-SHA             SSLv3 Kx=RSA      Au=RSA  Enc=DES(56)   Mac=SHA1
+DES-CBC3-MD5            SSLv2 Kx=RSA      Au=RSA  Enc=3DES(168) Mac=MD5 
+DES-CBC-MD5             SSLv2 Kx=RSA      Au=RSA  Enc=DES(56)   Mac=MD5 
+IDEA-CBC-MD5            SSLv2 Kx=RSA      Au=RSA  Enc=IDEA(128) Mac=MD5 
+RC2-CBC-MD5             SSLv2 Kx=RSA      Au=RSA  Enc=RC2(128)  Mac=MD5 
+RC4-MD5                 SSLv2 Kx=RSA      Au=RSA  Enc=RC4(128)  Mac=MD5 
+EXP-EDH-RSA-DES-CBC     SSLv3 Kx=DH(512)  Au=RSA  Enc=DES(40)   Mac=SHA1 export
+EXP-EDH-DSS-DES-CBC-SHA SSLv3 Kx=DH(512)  Au=DSS  Enc=DES(40)   Mac=SHA1 export
+EXP-DES-CBC-SHA         SSLv3 Kx=RSA(512) Au=RSA  Enc=DES(40)   Mac=SHA1 export
+EXP-RC2-CBC-MD5         SSLv3 Kx=RSA(512) Au=RSA  Enc=RC2(40)   Mac=MD5  export
+EXP-RC4-MD5             SSLv3 Kx=RSA(512) Au=RSA  Enc=RC4(40)   Mac=MD5  export
+EXP-RC2-CBC-MD5         SSLv2 Kx=RSA(512) Au=RSA  Enc=RC2(40)   Mac=MD5  export
+EXP-RC4-MD5             SSLv2 Kx=RSA(512) Au=RSA  Enc=RC4(40)   Mac=MD5  export
+
+I would recoment people use the 'ssleay ciphers -v "text"'
+command to check what they are going to use.
+
+Anyway, I'm falling asleep here so I'll do some more tomorrow.
+
+eric
+
+==== ssl.doc ========================================================
+
+SSL_CTX_sessions(SSL_CTX *ctx) - the session-id hash table.
+
+/* Session-id cache stats */
+SSL_CTX_sess_number
+SSL_CTX_sess_connect
+SSL_CTX_sess_connect_good
+SSL_CTX_sess_accept
+SSL_CTX_sess_accept_good
+SSL_CTX_sess_hits
+SSL_CTX_sess_cb_hits
+SSL_CTX_sess_misses
+SSL_CTX_sess_timeouts
+
+/* Session-id application notification callbacks */
+SSL_CTX_sess_set_new_cb
+SSL_CTX_sess_get_new_cb
+SSL_CTX_sess_set_get_cb
+SSL_CTX_sess_get_get_cb
+
+/* Session-id cache operation mode */
+SSL_CTX_set_session_cache_mode
+SSL_CTX_get_session_cache_mode
+
+/* Set default timeout values to use. */
+SSL_CTX_set_timeout
+SSL_CTX_get_timeout
+
+/* Global  SSL initalisation informational callback */
+SSL_CTX_set_info_callback
+SSL_CTX_get_info_callback
+SSL_set_info_callback
+SSL_get_info_callback
+
+/* If the SSL_accept/SSL_connect returned with -1, these indicate when
+ * we should re-call *.
+SSL_want
+SSL_want_nothing
+SSL_want_read
+SSL_want_write
+SSL_want_x509_lookup
+
+/* Where we are in SSL initalisation, used in non-blocking, perhaps
+ * have a look at ssl/bio_ssl.c */
+SSL_state
+SSL_is_init_finished
+SSL_in_init
+SSL_in_connect_init
+SSL_in_accept_init
+
+/* Used to set the 'inital' state so SSL_in_connect_init and SSL_in_accept_init
+ * can be used to work out which function to call. */
+SSL_set_connect_state
+SSL_set_accept_state
+
+/* Where to look for certificates for authentication */
+SSL_set_default_verify_paths /* calles SSL_load_verify_locations */
+SSL_load_verify_locations
+
+/* get info from an established connection */
+SSL_get_session
+SSL_get_certificate
+SSL_get_SSL_CTX
+
+SSL_CTX_new
+SSL_CTX_free
+SSL_new
+SSL_clear
+SSL_free
+
+SSL_CTX_set_cipher_list
+SSL_get_cipher
+SSL_set_cipher_list
+SSL_get_cipher_list
+SSL_get_shared_ciphers
+
+SSL_accept
+SSL_connect
+SSL_read
+SSL_write
+
+SSL_debug
+
+SSL_get_read_ahead
+SSL_set_read_ahead
+SSL_set_verify
+
+SSL_pending
+
+SSL_set_fd
+SSL_set_rfd
+SSL_set_wfd
+SSL_set_bio
+SSL_get_fd
+SSL_get_rbio
+SSL_get_wbio
+
+SSL_use_RSAPrivateKey
+SSL_use_RSAPrivateKey_ASN1
+SSL_use_RSAPrivateKey_file
+SSL_use_PrivateKey
+SSL_use_PrivateKey_ASN1
+SSL_use_PrivateKey_file
+SSL_use_certificate
+SSL_use_certificate_ASN1
+SSL_use_certificate_file
+
+ERR_load_SSL_strings
+SSL_load_error_strings
+
+/* human readable version of the 'state' of the SSL connection. */
+SSL_state_string
+SSL_state_string_long
+/* These 2 report what kind of IO operation the library was trying to
+ * perform last.  Probably not very usefull. */
+SSL_rstate_string
+SSL_rstate_string_long
+
+SSL_get_peer_certificate
+
+SSL_SESSION_new
+SSL_SESSION_print_fp
+SSL_SESSION_print
+SSL_SESSION_free
+i2d_SSL_SESSION
+d2i_SSL_SESSION
+
+SSL_get_time
+SSL_set_time
+SSL_get_timeout
+SSL_set_timeout
+SSL_copy_session_id
+SSL_set_session
+SSL_CTX_add_session
+SSL_CTX_remove_session
+SSL_CTX_flush_sessions
+
+BIO_f_ssl
+
+/* used to hold information as to why a certificate verification failed */
+SSL_set_verify_result
+SSL_get_verify_result
+
+/* can be used by the application to associate data with an SSL structure.
+ * It needs to be 'free()ed' by the application */
+SSL_set_app_data
+SSL_get_app_data
+
+/* The following all set values that are kept in the SSL_CTX but
+ * are used as the default values when an SSL session is created.
+ * They are over writen by the relevent SSL_xxxx functions */
+
+/* SSL_set_verify */
+void SSL_CTX_set_default_verify
+
+/* This callback, if set, totaly overrides the normal SSLeay verification
+ * functions and should return 1 on success and 0 on failure */
+void SSL_CTX_set_cert_verify_callback
+
+/* The following are the same as the equivilent SSL_xxx functions.
+ * Only one copy of this information is kept and if a particular
+ * SSL structure has a local override, it is totally separate structure.
+ */
+int SSL_CTX_use_RSAPrivateKey
+int SSL_CTX_use_RSAPrivateKey_ASN1
+int SSL_CTX_use_RSAPrivateKey_file
+int SSL_CTX_use_PrivateKey
+int SSL_CTX_use_PrivateKey_ASN1
+int SSL_CTX_use_PrivateKey_file
+int SSL_CTX_use_certificate
+int SSL_CTX_use_certificate_ASN1
+int SSL_CTX_use_certificate_file
+
+
+==== ssl_ctx.doc ========================================================
+
+This is now a bit dated, quite a few of the SSL_ functions could be
+SSL_CTX_ functions.  I will update this in the future. 30 Aug 1996
+
+From eay@orb.mincom.oz.au Mon Dec 11 21:37:08 1995
+Received: by orb.mincom.oz.au id AA00696
+  (5.65c/IDA-1.4.4 for eay); Mon, 11 Dec 1995 11:37:08 +1000
+Date: Mon, 11 Dec 1995 11:37:08 +1000 (EST)
+From: Eric Young <eay@mincom.oz.au>
+X-Sender: eay@orb
+To: sameer <sameer@c2.org>
+Cc: Eric Young <eay@mincom.oz.au>
+Subject: Re: PEM_readX509 oesn't seem to be working
+In-Reply-To: <199512110102.RAA12521@infinity.c2.org>
+Message-Id: <Pine.SOL.3.91.951211112115.28608D-100000@orb>
+Mime-Version: 1.0
+Content-Type: TEXT/PLAIN; charset=US-ASCII
+Status: RO
+X-Status: 
+
+On Sun, 10 Dec 1995, sameer wrote:
+>      OK, that's solved. I've found out that it is saying "no
+> certificate set" in SSL_accept because s->conn == NULL
+> so there is some place I need to initialize s->conn that I am
+> not initializing it.
+
+The full order of things for a server should be.
+
+ctx=SSL_CTX_new();
+
+/* The next line should not really be using ctx->cert but I'll leave it 
+ * this way right now... I don't want a X509_ routine to know about an SSL
+ * structure, there should be an SSL_load_verify_locations... hmm, I may 
+ * add it tonight.
+ */
+X509_load_verify_locations(ctx->cert,CAfile,CApath);
+
+/* Ok now for each new connection we do the following */
+con=SSL_new(ctx);
+SSL_set_fd(con,s);
+SSL_set_verify(con,verify,verify_callback);
+
+/* set the certificate and private key to use. */
+SSL_use_certificate_ASN1(con,X509_certificate);
+SSL_use_RSAPrivateKey_ASN1(con,RSA_private_key);
+
+SSL_accept(con);
+
+SSL_read(con)/SSL_write(con);
+
+There is a bit more than that but that is basically the structure.
+
+Create a context and specify where to lookup certificates.
+
+foreach connection
+       {
+       create a SSL structure
+       set the certificate and private key
+       do a SSL_accept
+       
+       we should now be ok
+       }
+
+eric
+--
+Eric Young                  | Signature removed since it was generating
+AARNet: eay@mincom.oz.au    | more followups than the message contents :-)
+
+
+
+==== ssleay.doc ========================================================
+
+SSLeay: a cryptographic kitchen sink.
+
+1st December 1995
+Way back at the start of April 1995, I was looking for a mindless
+programming project.  A friend of mine (Tim Hudson) said "why don't you do SSL,
+it has DES encryption in it and I would not mind using it in a SSL telnet".
+While it was true I had written a DES library in previous years, litle
+did I know what an expansive task SSL would turn into.
+
+First of all, the SSL protocol contains DES encryption.  Well and good.  My
+DES library was fast and portable.  It also contained the RSA's RC4 stream
+cipher.  Again, not a problem, some-one had just posted to sci.crypt
+something that was claimed to be RC4.  It also contained IDEA, I had the
+specifications, not a problem to implement.  MD5, an RFC, trivial, at most
+I could spend a week or so trying to see if I could speed up the
+implementation.  All in all a nice set of ciphers.
+Then the first 'expantion of the scope', RSA public key
+encryption.  Since I did not knowing a thing about public key encryption
+or number theory, this appeared quite a daunting task.  Just writing a
+big number library would be problomatic in itself, let alone making it fast.
+At this point the scope of 'implementing SSL' expands eponentialy.
+First of all, the RSA private keys  were being kept in ASN.1 format.
+Thankfully the RSA PKCS series of documents explains this format.  So I now
+needed to be able to encode and decode arbitary ASN.1 objects.  The Public
+keys were embeded in X509 certificates.  Hmm... these are not only
+ASN.1 objects but they make up a heirachy of authentication.  To
+authenticate a X509 certificate one needs to retrieve it's issuers
+certificate etc etc.  Hmm..., so I also need to implement some kind
+of certificate management software.  I would also have to implement
+software to authenticate certificates.  At this point the support code made
+the SSL part of my library look quite small.
+Around this time, the first version of SSLeay was released.
+
+Ah, but here was the problem, I was not happy with the code so far.  As may
+have become obvious, I had been treating all of this as a learning
+exersize, so I have completely written the library myself.  As such, due
+to the way it had grown like a fungus, much of the library was not
+'elagent' or neat.  There were global and static variables all over the
+place, the SSL part did not even handle non-blocking IO.
+The Great rewrite began.
+
+As of this point in time, the 'Great rewrite' has almost finished.  So what
+follows is an approximate list of what is actually SSLeay 0.5.0
+
+/********* This needs to be updated for 0.6.0+ *************/
+
+---
+The library contains the following routines.  Please note that most of these
+functions are not specfic for SSL or any other particular cipher
+implementation.  I have tried to make all the routines as general purpose
+as possible.  So you should not think of this library as an SSL
+implemtation, but rather as a library of cryptographic functions
+that also contains SSL.  I refer to each of these function groupings as
+libraries since they are often capable of functioning as independant
+libraries
+
+First up, the general ciphers and message digests supported by the library.
+
+MD2    rfc???, a standard 'by parts' interface to this algorithm.
+MD5    rfc???, the same type of interface as for the MD2 library except a
+       different algorithm.
+SHA    THe Secure Hash Algorithm.  Again the same type of interface as
+       MD2/MD5 except the digest is 20 bytes.
+SHA1   The 'revised' version of SHA.  Just about identical to SHA except
+       for one tweak of an inner loop.
+DES    This is my libdes library that has been floating around for the last
+       few years.  It has been enhanced for no other reason than completeness.
+       It now supports ecb, cbc, cfb, ofb, cfb64, ofb64 in normal mode and
+       triple DES modes of ecb, cbc, cfb64 and ofb64.  cfb64 and ofb64 are
+       functional interfaces to the 64 bit modes of cfb and ofb used in
+       such a way thay they function as single character interfaces.
+RC4    The RSA Inc. stream cipher.
+RC2    The RSA Inc. block cipher.
+IDEA   An implmentation of the IDEA cipher, the library supports ecb, cbc,
+       cfb64 and ofb64 modes of operation.
+
+Now all the above mentioned ciphers and digests libraries support high
+speed, minimal 'crap in the way' type interfaces.  For fastest and
+lowest level access, these routines should be used directly.
+
+Now there was also the matter of public key crypto systems.  These are
+based on large integer arithmatic.
+
+BN     This is my large integer library.  It supports all the normal
+       arithmentic operations.  It uses malloc extensivly and as such has
+       no limits of the size of the numbers being manipulated.  If you
+       wish to use 4000 bit RSA moduli, these routines will handle it.
+       This library also contains routines to 'generate' prime numbers and
+       to test for primality.  The RSA and DH libraries sit on top of this
+       library.  As of this point in time, I don't support SHA, but
+       when I do add it, it will just sit on top of the routines contained
+       in this library.
+RSA    This implements the RSA public key algorithm.  It also contains
+       routines that will generate a new private/public key pair.
+       All the RSA functions conform to the PKCS#1 standard.
+DH     This is an implementation of the
+       Diffie-Hellman protocol.  There are all the require routines for
+       the protocol, plus extra routines that can be used to generate a
+       strong prime for use with a specified generator.  While this last
+       routine is not generally required by applications implementing DH,
+       It is present for completeness and because I thing it is much
+       better to be able to 'generate' your own 'magic' numbers as oposed
+       to using numbers suplied by others.  I conform to the PKCS#3
+       standard where required.
+
+You may have noticed the preceeding section mentions the 'generation' of
+prime numbers.  Now this requries the use of 'random numbers'. 
+
+RAND   This psuedo-random number library is based on MD5 at it's core
+       and a large internal state (2k bytes).  Once you have entered enough
+       seed data into this random number algorithm I don't feel
+       you will ever need to worry about it generating predictable output.
+       Due to the way I am writing a portable library, I have left the
+       issue of how to get good initial random seed data upto the
+       application but I do have support routines for saving and loading a
+       persistant random number state for use between program runs.
+       
+Now to make all these ciphers easier to use, a higher level
+interface was required.  In this form, the same function would be used to
+encrypt 'by parts', via any one of the above mentioned ciphers.
+
+EVP    The Digital EnVeloPe library is quite large.  At it's core are
+       function to perform encryption and decryption by parts while using
+       an initial parameter to specify which of the 17 different ciphers
+       or 4 different message digests to use.  On top of these are implmented
+       the digital signature functions, sign, verify, seal and open.
+       Base64 encoding of binary data is also done in this library.
+
+PEM    rfc???? describe the format for Privacy Enhanced eMail.
+       As part of this standard, methods of encoding digital enveloped
+       data is an ascii format are defined.  As such, I use a form of these
+       to encode enveloped data.  While at this point in time full support
+       for PEM has not been built into the library, a minimal subset of
+       the secret key and Base64 encoding is present.  These reoutines are
+       mostly used to Ascii encode binary data with a 'type' associated
+       with it and perhaps details of private key encryption used to
+       encrypt the data.
+       
+PKCS7  This is another Digital Envelope encoding standard which uses ASN.1
+       to encode the data.  At this point in time, while there are some
+       routines to encode and decode this binary format, full support is
+       not present.
+       
+As Mentioned, above, there are several different ways to encode
+data structures.
+
+ASN1   This library is more a set of primatives used to encode the packing
+       and unpacking of data structures.  It is used by the X509
+       certificate standard and by the PKCS standards which are used by
+       this library.  It also contains routines for duplicating and signing
+       the structures asocisated with X509.
+       
+X509   The X509 library contains routines for packing and unpacking,
+       verifying and just about every thing else you would want to do with
+       X509 certificates.
+
+PKCS7  PKCS-7 is a standard for encoding digital envelope data
+       structures.  At this point in time the routines will load and save
+       DER forms of these structees.  They need to be re-worked to support
+       the BER form which is the normal way PKCS-7 is encoded.  If the
+       previous 2 sentances don't make much sense, don't worry, this
+       library is not used by this version of SSLeay anyway.
+
+OBJ    ASN.1 uses 'object identifiers' to identify objects.  A set of
+       functions were requred to translate from ASN.1 to an intenger, to a
+       character string.  This library provieds these translations
+       
+Now I mentioned an X509 library.  X509 specified a hieachy of certificates
+which needs to be traversed to authenticate particular certificates.
+
+METH   This library is used to push 'methods' of retrieving certificates
+       into the library.  There are some supplied 'methods' with SSLeay
+       but applications can add new methods if they so desire.
+       This library has not been finished and is not being used in this
+       version.
+       
+Now all the above are required for use in the initial point of this project.
+
+SSL    The SSL protocol.  This is a full implmentation of SSL v 2.  It
+       support both server and client authentication.  SSL v 3 support
+       will be added when the SSL v 3 specification is released in it's
+       final form.
+
+Now quite a few of the above mentioned libraries rely on a few 'complex'
+data structures.  For each of these I have a library.
+
+Lhash  This is a hash table library which is used extensivly.
+
+STACK  An implemetation of a Stack data structure.
+
+BUF    A simple character array structure that also support a function to
+       check that the array is greater that a certain size, if it is not,
+       it is realloced so that is it.
+       
+TXT_DB A simple memory based text file data base.  The application can specify
+       unique indexes that will be enforced at update time.
+
+CONF   Most of the programs written for this library require a configuration
+       file.  Instead of letting programs constantly re-implment this
+       subsystem, the CONF library provides a consistant and flexable
+       interface to not only configuration files but also environment
+       variables.
+
+But what about when something goes wrong?
+The one advantage (and perhaps disadvantage) of all of these
+functions being in one library was the ability to implement a
+single error reporting system.
+       
+ERR    This library is used to report errors.  The error system records
+       library number, function number (in the library) and reason
+       number.  Multiple errors can be reported so that an 'error' trace
+       is created.  The errors can be printed in numeric or textual form.
+
+
+==== ssluse.doc ========================================================
+
+We have an SSL_CTX which contains global information for lots of
+SSL connections.  The session-id cache and the certificate verificate cache.
+It also contains default values for use when certificates are used.
+
+SSL_CTX
+       default cipher list
+       session-id cache
+       certificate cache
+       default session-id timeout period
+       New session-id callback
+       Required session-id callback
+       session-id stats
+       Informational callback
+       Callback that is set, overrides the SSLeay X509 certificate
+         verification
+       The default Certificate/Private Key pair
+       Default read ahead mode.
+       Default verify mode and verify callback.  These are not used
+         if the over ride callback mentioned above is used.
+       
+Each SSL can have the following defined for it before a connection is made.
+
+Certificate
+Private key
+Ciphers to use
+Certificate verify mode and callback
+IO object to use in the comunication.
+Some 'read-ahead' mode information.
+A previous session-id to re-use.
+
+A connection is made by using SSL_connect or SSL_accept.
+When non-blocking IO is being used, there are functions that can be used
+to determin where and why the SSL_connect or SSL_accept did not complete.
+This information can be used to recall the functions when the 'error'
+condition has dissapeared.
+
+After the connection has been made, information can be retrived about the
+SSL session and the session-id values that have been decided upon.
+The 'peer' certificate can be retrieved.
+
+The session-id values include
+'start time'
+'timeout length'
+
+
+
+==== stack.doc ========================================================
+
+The stack data structure is used to store an ordered list of objects.
+It is basically misnamed to call it a stack but it can function that way
+and that is what I originally used it for.  Due to the way element
+pointers are kept in a malloc()ed array, the most efficient way to use this
+structure is to add and delete elements from the end via sk_pop() and
+sk_push().  If you wish to do 'lookups' sk_find() is quite efficient since
+it will sort the stack (if required) and then do a binary search to lookup 
+the requested item.  This sorting occurs automatically so just sk_push()
+elements on the stack and don't worry about the order.  Do remember that if
+you do a sk_find(), the order of the elements will change.
+
+You should never need to 'touch' this structure directly.
+typedef struct stack_st
+       {
+       unsigned int num;
+       char **data;
+       int sorted;
+
+       unsigned int num_alloc;
+       int (*comp)();
+       } STACK;
+
+'num' holds the number of elements in the stack, 'data' is the array of
+elements.  'sorted' is 1 is the list has been sorted, 0 if not.
+
+num_alloc is the number of 'nodes' allocated in 'data'.  When num becomes
+larger than num_alloc, data is realloced to a larger size.
+If 'comp' is set, it is a function that is used to compare 2 of the items
+in the stack.  The function should return -1, 0 or 1, depending on the
+ordering.
+
+#define sk_num(sk)     ((sk)->num)
+#define sk_value(sk,n) ((sk)->data[n])
+
+These 2 macros should be used to access the number of elements in the
+'stack' and to access a pointer to one of the values.
+
+STACK *sk_new(int (*c)());
+       This creates a new stack.  If 'c', the comparison function, is not
+specified, the various functions that operate on a sorted 'stack' will not
+work (sk_find()).  NULL is returned on failure.
+
+void sk_free(STACK *);
+       This function free()'s a stack structure.  The elements in the
+stack will not be freed so one should 'pop' and free all elements from the
+stack before calling this function or call sk_pop_free() instead.
+
+void sk_pop_free(STACK *st; void (*func)());
+       This function calls 'func' for each element on the stack, passing
+the element as the argument.  sk_free() is then called to free the 'stack'
+structure.
+
+int sk_insert(STACK *sk,char *data,int where);
+       This function inserts 'data' into stack 'sk' at location 'where'.
+If 'where' is larger that the number of elements in the stack, the element
+is put at the end.  This function tends to be used by other 'stack'
+functions.  Returns 0 on failure, otherwise the number of elements in the
+new stack.
+
+char *sk_delete(STACK *st,int loc);
+       Remove the item a location 'loc' from the stack and returns it.
+Returns NULL if the 'loc' is out of range.
+
+char *sk_delete_ptr(STACK *st, char *p);
+       If the data item pointed to by 'p' is in the stack, it is deleted
+from the stack and returned.  NULL is returned if the element is not in the
+stack.
+
+int sk_find(STACK *st,char *data);
+       Returns the location that contains a value that is equal to 
+the 'data' item.  If the comparison function was not set, this function
+does a linear search.  This function actually qsort()s the stack if it is not
+in order and then uses bsearch() to do the initial search.  If the
+search fails,, -1 is returned.  For mutliple items with the same
+value, the index of the first in the array is returned.
+
+int sk_push(STACK *st,char *data);
+       Append 'data' to the stack.  0 is returned if there is a failure
+(due to a malloc failure), else 1.  This is 
+sk_insert(st,data,sk_num(st));
+
+int sk_unshift(STACK *st,char *data);
+       Prepend 'data' to the front (location 0) of the stack.  This is
+sk_insert(st,data,0);
+
+char *sk_shift(STACK *st);
+       Return and delete from the stack the first element in the stack.
+This is sk_delete(st,0);
+
+char *sk_pop(STACK *st);
+       Return and delete the last element on the stack.  This is
+sk_delete(st,sk_num(sk)-1);
+
+void sk_zero(STACK *st);
+       Removes all items from the stack.  It does not 'free'
+pointers but is a quick way to clear a 'stack of references'.
+
+==== threads.doc ========================================================
+
+How to compile SSLeay for multi-threading.
+
+Well basically it is quite simple, set the compiler flags and build.
+I have only really done much testing under Solaris and Windows NT.
+If you library supports localtime_r() and gmtime_r() add,
+-DTHREADS to the makefile parameters.  You can probably survive with out
+this define unless you are going to have multiple threads generating
+certificates at once.  It will not affect the SSL side of things.
+
+The approach I have taken to doing locking is to make the application provide
+callbacks to perform locking and so that the SSLeay library can distinguish
+between threads (for the error state).
+
+To have a look at an example program, 'cd mt; vi mttest.c'.
+To build under solaris, sh solaris.sh, for Windows NT or Windows 95,
+win32.bat
+
+This will build mttest which will fire up 10 threads that talk SSL
+to each other 10 times.
+To enable everything to work, the application needs to call
+
+CRYPTO_set_id_callback(id_function);
+CRYPTO_set_locking_callback(locking_function);
+
+before any multithreading is started.
+id_function does not need to be defined under Windows NT or 95, the
+correct function will be called if it is not.  Under unix, getpid()
+is call if the id_callback is not defined, for Solaris this is wrong
+(since threads id's are not pid's) but under Linux it is correct
+(threads are just processes sharing the data segement).
+
+The locking_callback is used to perform locking by the SSLeay library.
+eg.
+
+void solaris_locking_callback(mode,type,file,line)
+int mode;
+int type;
+char *file;
+int line;
+       {
+       if (mode & CRYPTO_LOCK)
+               mutex_lock(&(lock_cs[type]));
+       else
+               mutex_unlock(&(lock_cs[type]));
+       }
+
+Now in this case I have used mutexes instead of read/write locks, since they
+are faster and there are not many read locks in SSLeay, you may as well
+always use write locks.  file and line are __FILE__ and __LINE__ from
+the compile and can be usefull when debugging.
+
+Now as you can see, 'type' can be one of a range of values, these values are
+defined in crypto/crypto.h
+CRYPTO_get_lock_name(type) will return a text version of what the lock is.
+There are CRYPTO_NUM_LOCKS locks required, so under solaris, the setup
+for multi-threading can be
+
+static mutex_t lock_cs[CRYPTO_NUM_LOCKS];
+
+void thread_setup()
+       {
+       int i;
+
+       for (i=0; i<CRYPTO_NUM_LOCKS; i++)
+               mutex_init(&(lock_cs[i]),USYNC_THREAD,NULL);
+       CRYPTO_set_id_callback((unsigned long (*)())solaris_thread_id);
+       CRYPTO_set_locking_callback((void (*)())solaris_locking_callback);
+       }
+
+As a final note, under Windows NT or Windows 95, you have to be careful
+not to mix the various threaded, unthreaded and debug libraries.
+Normally if they are mixed incorrectly, mttest will crash just after printing
+out some usage statistics at the end.  This is because the
+different system libraries use different malloc routines and if
+data is malloc()ed inside crypt32.dll or ssl32.dll and then free()ed by a
+different library malloc, things get very confused.
+
+The default SSLeay DLL builds use /MD, so if you use this on your
+application, things will work as expected.  If you use /MDd,
+you will probably have to rebuild SSLeay using this flag.
+I should modify util/mk1mf.pl so it does all this correctly, but 
+this has not been done yet.
+
+One last warning.  Because locking overheads are actually quite large, the
+statistics collected against the SSL_CTX for successfull connections etc
+are not locked when updated.  This does make it possible for these
+values to be slightly lower than they should be, if you are
+running multithreaded on a multi-processor box, but this does not really
+matter much.
+
+
+==== txt_db.doc ========================================================
+
+TXT_DB, a simple text based in memory database.
+
+It holds rows of ascii data, for which the only special character is '\0'.
+The rows can be of an unlimited length.
+
+==== why.doc ========================================================
+
+This file is more of a note for other people who wish to understand why
+the build environment is the way it is :-).
+
+The include files 'depend' as follows.
+Each of 
+crypto/*/*.c includes crypto/cryptlib.h
+ssl/*.c include ssl/ssl_locl.h
+apps/*.c include apps/apps.h
+crypto/cryptlib.h, ssl/ssl_locl.h and apps/apps.h
+all include e_os.h which contains OS/environment specific information.
+If you need to add something todo with a particular environment,
+add it to this file.  It is worth remembering that quite a few libraries,
+like lhash, des, md, sha etc etc do not include crypto/cryptlib.h.  This
+is because these libraries should be 'independantly compilable' and so I
+try to keep them this way.
+e_os.h is not so much a part of SSLeay, as the placing in one spot all the
+evil OS dependant muck.
+
+I wanted to automate as many things as possible.  This includes
+error number generation.  A
+make errors
+will scan the source files for error codes, append them to the correct
+header files, and generate the functions to print the text version
+of the error numbers.  So don't even think about adding error numbers by
+hand, put them in the form
+XXXerr(XXXX_F_XXXX,YYYY_R_YYYY);
+on line and it will be automatically picked up my a make errors.
+
+In a similar vein, programs to be added into ssleay in the apps directory
+just need to have an entry added to E_EXE in makefile.ssl and
+everthing will work as expected.  Don't edit progs.h by hand.
+
+make links re-generates the symbolic links that are used.  The reason why
+I keep everything in its own directory, and don't put all the
+test programs and header files in 'test' and 'include' is because I want
+to keep the 'sub-libraries' independant.  I still 'pull' out
+indervidual libraries for use in specific projects where the code is
+required.  I have used the 'lhash' library in just about every software
+project I have worked on :-).
+
+make depend generates dependancies and
+make dclean removes them.
+
+You will notice that I use perl quite a bit when I could be using 'sed'.
+The reason I decided to do this was to just stick to one 'extra' program.
+For Windows NT, I have perl and no sed.
+
+The util/mk1mf.pl program can be used to generate a single makefile.
+I use this because makefiles under Microsoft are horrific.
+Each C compiler seems to have different linker formats, which have
+to be used because the retarted C compilers explode when you do
+cl -o file *.o.
+
+Now some would argue that I should just use the single makefile.  I don't
+like it during develoment for 2 reasons.  First, the actuall make
+command takes a long time.  For my current setup, if I'm in
+crypto/bn and I type make, only the crypto/bn directory gets rebuilt,
+which is nice when you are modifying prototypes in bn.h which
+half the SSLeay depends on.  The second is that to add a new souce file
+I just plonk it in at the required spot in the local makefile.  This
+then alows me to keep things local, I don't need to modify a 'global'
+tables (the make for unix, the make for NT, the make for w31...).
+When I am ripping apart a library structure, it is nice to only
+have to worry about one directory :-).
+
+Having said all this, for the hell of it I put together 2 files that
+#include all the souce code (generated by doing a ls */*.o after a build).
+crypto.c takes only 30 seconds to build under NT and 2 minutes under linux
+for my pentium100.  Much faster that the normal build :-).
+Again, the problem is that when using libraries, every program linked
+to libcrypto.a would suddenly get 330k of library when it may only need
+1k.  This technique does look like a nice way to do shared libraries though.
+
+Oh yes, as a final note, to 'build' a distribution, I just type
+make dist.
+This cleans and packages everything.  The directory needs to be called
+SSLeay since the make does a 'cd ..' and renames and tars things up.
+
+==== req.1 ========================================================
+
+The 'req' command is used to manipulate and deal with pkcs#10
+certificate requests.
+
+It's default mode of operation is to load a certificate and then
+write it out again.
+
+By default the 'req' is read from stdin in 'PEM' format.
+The -inform option can be used to specify 'pem' format or 'der'
+format.  PEM format is the base64 encoding of the DER format.
+
+By default 'req' then writes the request back out. -outform can be used
+to indicate the desired output format, be it 'pem' or 'der'.
+
+To specify an input file, use the '-in' option and the '-out' option
+can be used to specify the output file.
+
+If you wish to perform a command and not output the certificate
+request afterwards, use the '-noout' option.
+
+When a certificate is loaded, it can be printed in a human readable
+ascii format via the '-text' option.
+
+To check that the signature on a certificate request is correct, use
+the '-verify' option to make sure that the private key contained in the
+certificate request corresponds to the signature.
+
+Besides the default mode, there is also the 'generate a certificate
+request' mode.  There are several flags that trigger this mode.
+
+-new will generate a new RSA key (if required) and then prompts
+the user for details for the certificate request.
+-newkey has an argument that is the number of bits to make the new
+key.  This function also triggers '-new'.
+
+The '-new' option can have a key to use specified instead of having to
+load one, '-key' is used to specify the file containg the key.
+-keyform can be used to specify the format of the key.  Only
+'pem' and 'der' formats are supported, later, 'netscape' format may be added.
+
+Finally there is the '-x509' options which makes req output a self
+signed x509 certificate instead of a certificate request.
+
+Now as you may have noticed, there are lots of default options that
+cannot be specified via the command line.  They are held in a 'template'
+or 'configuration file'.  The -config option specifies which configuration
+file to use.  See conf.doc for details on the syntax of this file.
+
+The req command uses the 'req' section of the config file.
+
+---
+# The following variables are defined.  For this example I will populate
+# the various values
+[ req ]
+default_bits   = 512           # default number of bits to use.
+default_keyfile        = testkey.pem   # Where to write the generated keyfile
+                               # if not specified.
+distinguished_name= req_dn     # The section that contains the
+                               # information about which 'object' we
+                               # want to put in the DN.
+attributes     = req_attr      # The objects we want for the
+                               # attributes field.
+encrypt_rsa_key        = no            # Should we encrypt newly generated
+                               # keys.  I strongly recommend 'yes'.
+
+# The distinguished name section.  For the following entries, the
+# object names must exist in the SSLeay header file objects.h.  If they
+# do not, they will be silently ignored.  The entries have the following
+# format.
+# <object_name>                => string to prompt with
+# <object_name>_default        => default value for people
+# <object_name>_value  => Automatically use this value for this field.
+# <object_name>_min    => minimum number of characters for data (def. 0)
+# <object_name>_max    => maximum number of characters for data (def. inf.)
+# All of these entries are optional except for the first one.
+[ req_dn ]
+countryName                    = Country Name (2 letter code)
+countryName_default            = AU
+
+stateOrProvinceName            = State or Province Name (full name)
+stateOrProvinceName_default    = Queensland
+
+localityName                   = Locality Name (eg, city)
+
+organizationName               = Organization Name (eg, company)
+organizationName_default       = Mincom Pty Ltd
+
+organizationalUnitName         = Organizational Unit Name (eg, section)
+organizationalUnitName_default = MTR
+
+commonName                     = Common Name (eg, YOUR name)
+commonName_max                 = 64
+
+emailAddress                   = Email Address
+emailAddress_max               = 40
+
+# The next section is the attributes section.  This is exactly the
+# same as for the previous section except that the resulting objects are
+# put in the attributes field. 
+[ req_attr ]
+challengePassword              = A challenge password
+challengePassword_min          = 4
+challengePassword_max          = 20
+
+unstructuredName               = An optional company name
+
+----
+Also note that the order that attributes appear in this file is the
+order they will be put into the distinguished name.
+
+Once this request has been generated, it can be sent to a CA for
+certifying.
+
+----
+A few quick examples....
+
+To generate a new request and a new key
+req -new
+
+To generate a new request and a 1058 bit key
+req -newkey 1058
+
+To generate a new request using a pre-existing key
+req -new -key key.pem
+
+To generate a self signed x509 certificate from a certificate
+request using a supplied key, and we want to see the text form of the
+output certificate (which we will put in the file selfSign.pem
+req -x509 -in req.pem -key key.pem -text -out selfSign.pem
+
+Verify that the signature is correct on a certificate request.
+req -verify -in req.pem
+
+Verify that the signature was made using a specified public key.
+req -verify -in req.pem -key key.pem
+
+Print the contents of a certificate request
+req -text -in req.pem
+
+==== danger ========================================================
+
+If you specify a SSLv2 cipher, and the mode is SSLv23 and the server
+can talk SSLv3, it will claim there is no cipher since you should be
+using SSLv3.
+
+When tracing debug stuff, remember BIO_s_socket() is different to
+BIO_s_connect().
+
+BSD/OS assember is not working
+
diff --git a/deps/openssl/openssl/doc/standards.txt b/deps/openssl/openssl/doc/standards.txt
new file mode 100644 (file)
index 0000000..7bada8d
--- /dev/null
@@ -0,0 +1,285 @@
+Standards related to OpenSSL
+============================
+
+[Please, this is currently a draft.  I made a first try at finding
+ documents that describe parts of what OpenSSL implements.  There are
+ big gaps, and I've most certainly done something wrong.  Please
+ correct whatever is...  Also, this note should be removed when this
+ file is reaching a somewhat correct state.        -- Richard Levitte]
+
+
+All pointers in here will be either URL's or blobs of text borrowed
+from miscellaneous indexes, like rfc-index.txt (index of RFCs),
+1id-index.txt (index of Internet drafts) and the like.
+
+To find the latest possible RFCs, it's recommended to either browse
+ftp://ftp.isi.edu/in-notes/ or go to http://www.rfc-editor.org/ and
+use the search mechanism found there.
+To find the latest possible Internet drafts, it's recommended to
+browse ftp://ftp.isi.edu/internet-drafts/.
+To find the latest possible PKCS, it's recommended to browse
+http://www.rsasecurity.com/rsalabs/pkcs/.
+
+
+Implemented:
+------------
+
+These are documents that describe things that are implemented (in
+whole or at least great parts) in OpenSSL.
+
+1319 The MD2 Message-Digest Algorithm. B. Kaliski. April 1992.
+     (Format: TXT=25661 bytes) (Status: INFORMATIONAL)
+
+1320 The MD4 Message-Digest Algorithm. R. Rivest. April 1992. (Format:
+     TXT=32407 bytes) (Status: INFORMATIONAL)
+
+1321 The MD5 Message-Digest Algorithm. R. Rivest. April 1992. (Format:
+     TXT=35222 bytes) (Status: INFORMATIONAL)
+
+2246 The TLS Protocol Version 1.0. T. Dierks, C. Allen. January 1999.
+     (Format: TXT=170401 bytes) (Status: PROPOSED STANDARD)
+
+2268 A Description of the RC2(r) Encryption Algorithm. R. Rivest.
+     January 1998. (Format: TXT=19048 bytes) (Status: INFORMATIONAL)
+
+2315 PKCS 7: Cryptographic Message Syntax Version 1.5. B. Kaliski.
+     March 1998. (Format: TXT=69679 bytes) (Status: INFORMATIONAL)
+
+PKCS#8: Private-Key Information Syntax Standard
+
+PKCS#12: Personal Information Exchange Syntax Standard, version 1.0.
+
+2560 X.509 Internet Public Key Infrastructure Online Certificate
+     Status Protocol - OCSP. M. Myers, R. Ankney, A. Malpani, S. Galperin,
+     C. Adams. June 1999. (Format: TXT=43243 bytes) (Status: PROPOSED
+     STANDARD)
+
+2712 Addition of Kerberos Cipher Suites to Transport Layer Security
+     (TLS). A. Medvinsky, M. Hur. October 1999. (Format: TXT=13763 bytes)
+     (Status: PROPOSED STANDARD)
+
+2898 PKCS #5: Password-Based Cryptography Specification Version 2.0.
+     B. Kaliski. September 2000. (Format: TXT=68692 bytes) (Status:
+     INFORMATIONAL)
+
+2986 PKCS #10: Certification Request Syntax Specification Version 1.7.
+     M. Nystrom, B. Kaliski. November 2000. (Format: TXT=27794 bytes)
+     (Obsoletes RFC2314) (Status: INFORMATIONAL)
+
+3174 US Secure Hash Algorithm 1 (SHA1). D. Eastlake 3rd, P. Jones.
+     September 2001. (Format: TXT=35525 bytes) (Status: INFORMATIONAL)
+
+3161 Internet X.509 Public Key Infrastructure, Time-Stamp Protocol (TSP)
+     C. Adams, P. Cain, D. Pinkas, R. Zuccherato. August 2001
+     (Status: PROPOSED STANDARD)
+
+3268 Advanced Encryption Standard (AES) Ciphersuites for Transport
+     Layer Security (TLS). P. Chown. June 2002. (Format: TXT=13530 bytes)
+     (Status: PROPOSED STANDARD)
+
+3279 Algorithms and Identifiers for the Internet X.509 Public Key
+     Infrastructure Certificate and Certificate Revocation List (CRL)
+     Profile. L. Bassham, W. Polk, R. Housley. April 2002. (Format:
+     TXT=53833 bytes) (Status: PROPOSED STANDARD)
+
+3280 Internet X.509 Public Key Infrastructure Certificate and
+     Certificate Revocation List (CRL) Profile. R. Housley, W. Polk, W.
+     Ford, D. Solo. April 2002. (Format: TXT=295556 bytes) (Obsoletes
+     RFC2459) (Status: PROPOSED STANDARD)
+
+3447 Public-Key Cryptography Standards (PKCS) #1: RSA Cryptography
+     Specifications Version 2.1. J. Jonsson, B. Kaliski. February 2003.
+     (Format: TXT=143173 bytes) (Obsoletes RFC2437) (Status:           
+     INFORMATIONAL)                                         
+
+3713 A Description of the Camellia Encryption Algorithm. M. Matsui,
+     J. Nakajima, S. Moriai. April 2004. (Format: TXT=25031 bytes)
+     (Status: INFORMATIONAL)
+
+3820 Internet X.509 Public Key Infrastructure (PKI) Proxy Certificate
+     Profile. S. Tuecke, V. Welch, D. Engert, L. Pearlman, M. Thompson.
+     June 2004. (Format: TXT=86374 bytes) (Status: PROPOSED STANDARD)
+
+4132 Addition of Camellia Cipher Suites to Transport Layer Security
+     (TLS). S. Moriai, A. Kato, M. Kanda. July 2005. (Format: TXT=13590
+     bytes) (Status: PROPOSED STANDARD)
+
+4162 Addition of SEED Cipher Suites to Transport Layer Security (TLS).
+     H.J. Lee, J.H. Yoon, J.I. Lee. August 2005. (Format: TXT=10578 bytes)
+     (Status: PROPOSED STANDARD)
+
+4269 The SEED Encryption Algorithm. H.J. Lee, S.J. Lee, J.H. Yoon,
+     D.H. Cheon, J.I. Lee. December 2005. (Format: TXT=34390 bytes)
+     (Obsoletes RFC4009) (Status: INFORMATIONAL)
+
+
+Related:
+--------
+
+These are documents that are close to OpenSSL, for example the
+STARTTLS documents.
+
+1421 Privacy Enhancement for Internet Electronic Mail: Part I: Message
+     Encryption and Authentication Procedures. J. Linn. February 1993.
+     (Format: TXT=103894 bytes) (Obsoletes RFC1113) (Status: PROPOSED
+     STANDARD)
+
+1422 Privacy Enhancement for Internet Electronic Mail: Part II:
+     Certificate-Based Key Management. S. Kent. February 1993. (Format:
+     TXT=86085 bytes) (Obsoletes RFC1114) (Status: PROPOSED STANDARD)
+
+1423 Privacy Enhancement for Internet Electronic Mail: Part III:
+     Algorithms, Modes, and Identifiers. D. Balenson. February 1993.
+     (Format: TXT=33277 bytes) (Obsoletes RFC1115) (Status: PROPOSED
+     STANDARD)
+
+1424 Privacy Enhancement for Internet Electronic Mail: Part IV: Key
+     Certification and Related Services. B. Kaliski. February 1993.
+     (Format: TXT=17537 bytes) (Status: PROPOSED STANDARD)
+
+2025 The Simple Public-Key GSS-API Mechanism (SPKM). C. Adams. October
+     1996. (Format: TXT=101692 bytes) (Status: PROPOSED STANDARD)
+
+2510 Internet X.509 Public Key Infrastructure Certificate Management
+     Protocols. C. Adams, S. Farrell. March 1999. (Format: TXT=158178
+     bytes) (Status: PROPOSED STANDARD)
+
+2511 Internet X.509 Certificate Request Message Format. M. Myers, C.
+     Adams, D. Solo, D. Kemp. March 1999. (Format: TXT=48278 bytes)
+     (Status: PROPOSED STANDARD)
+
+2527 Internet X.509 Public Key Infrastructure Certificate Policy and
+     Certification Practices Framework. S. Chokhani, W. Ford. March 1999.
+     (Format: TXT=91860 bytes) (Status: INFORMATIONAL)
+
+2538 Storing Certificates in the Domain Name System (DNS). D. Eastlake
+     3rd, O. Gudmundsson. March 1999. (Format: TXT=19857 bytes) (Status:
+     PROPOSED STANDARD)
+
+2539 Storage of Diffie-Hellman Keys in the Domain Name System (DNS).
+     D. Eastlake 3rd. March 1999. (Format: TXT=21049 bytes) (Status:
+     PROPOSED STANDARD)
+
+2559 Internet X.509 Public Key Infrastructure Operational Protocols -
+     LDAPv2. S. Boeyen, T. Howes, P. Richard. April 1999. (Format:
+     TXT=22889 bytes) (Updates RFC1778) (Status: PROPOSED STANDARD)
+
+2585 Internet X.509 Public Key Infrastructure Operational Protocols:
+     FTP and HTTP. R. Housley, P. Hoffman. May 1999. (Format: TXT=14813
+     bytes) (Status: PROPOSED STANDARD)
+
+2587 Internet X.509 Public Key Infrastructure LDAPv2 Schema. S.
+     Boeyen, T. Howes, P. Richard. June 1999. (Format: TXT=15102 bytes)
+     (Status: PROPOSED STANDARD)
+
+2595 Using TLS with IMAP, POP3 and ACAP. C. Newman. June 1999.
+     (Format: TXT=32440 bytes) (Status: PROPOSED STANDARD)
+
+2631 Diffie-Hellman Key Agreement Method. E. Rescorla. June 1999.
+     (Format: TXT=25932 bytes) (Status: PROPOSED STANDARD)
+
+2632 S/MIME Version 3 Certificate Handling. B. Ramsdell, Ed.. June
+     1999. (Format: TXT=27925 bytes) (Status: PROPOSED STANDARD)
+
+2716 PPP EAP TLS Authentication Protocol. B. Aboba, D. Simon. October
+     1999. (Format: TXT=50108 bytes) (Status: EXPERIMENTAL)
+
+2773 Encryption using KEA and SKIPJACK. R. Housley, P. Yee, W. Nace.
+     February 2000. (Format: TXT=20008 bytes) (Updates RFC0959) (Status:
+     EXPERIMENTAL)
+
+2797 Certificate Management Messages over CMS. M. Myers, X. Liu, J.
+     Schaad, J. Weinstein. April 2000. (Format: TXT=103357 bytes) (Status:
+     PROPOSED STANDARD)
+
+2817 Upgrading to TLS Within HTTP/1.1. R. Khare, S. Lawrence. May
+     2000. (Format: TXT=27598 bytes) (Updates RFC2616) (Status: PROPOSED
+     STANDARD)
+
+2818 HTTP Over TLS. E. Rescorla. May 2000. (Format: TXT=15170 bytes)
+     (Status: INFORMATIONAL)
+
+2876 Use of the KEA and SKIPJACK Algorithms in CMS. J. Pawling. July
+     2000. (Format: TXT=29265 bytes) (Status: INFORMATIONAL)
+
+2984 Use of the CAST-128 Encryption Algorithm in CMS. C. Adams.
+     October 2000. (Format: TXT=11591 bytes) (Status: PROPOSED STANDARD)
+
+2985 PKCS #9: Selected Object Classes and Attribute Types Version 2.0.
+     M. Nystrom, B. Kaliski. November 2000. (Format: TXT=70703 bytes)
+     (Status: INFORMATIONAL)
+
+3029 Internet X.509 Public Key Infrastructure Data Validation and
+     Certification Server Protocols. C. Adams, P. Sylvester, M. Zolotarev,
+     R. Zuccherato. February 2001. (Format: TXT=107347 bytes) (Status:
+     EXPERIMENTAL)
+
+3039 Internet X.509 Public Key Infrastructure Qualified Certificates
+     Profile. S. Santesson, W. Polk, P. Barzin, M. Nystrom. January 2001.
+     (Format: TXT=67619 bytes) (Status: PROPOSED STANDARD)
+
+3058 Use of the IDEA Encryption Algorithm in CMS. S. Teiwes, P.
+     Hartmann, D. Kuenzi. February 2001. (Format: TXT=17257 bytes)
+     (Status: INFORMATIONAL)
+
+3161 Internet X.509 Public Key Infrastructure Time-Stamp Protocol
+     (TSP). C. Adams, P. Cain, D. Pinkas, R. Zuccherato. August 2001.
+     (Format: TXT=54585 bytes) (Status: PROPOSED STANDARD)
+
+3185 Reuse of CMS Content Encryption Keys. S. Farrell, S. Turner.
+     October 2001. (Format: TXT=20404 bytes) (Status: PROPOSED STANDARD)
+
+3207 SMTP Service Extension for Secure SMTP over Transport Layer
+     Security. P. Hoffman. February 2002. (Format: TXT=18679 bytes)
+     (Obsoletes RFC2487) (Status: PROPOSED STANDARD)
+
+3217 Triple-DES and RC2 Key Wrapping. R. Housley. December 2001.
+     (Format: TXT=19855 bytes) (Status: INFORMATIONAL)
+
+3274 Compressed Data Content Type for Cryptographic Message Syntax
+     (CMS). P. Gutmann. June 2002. (Format: TXT=11276 bytes) (Status:
+     PROPOSED STANDARD)
+
+3278 Use of Elliptic Curve Cryptography (ECC) Algorithms in
+     Cryptographic Message Syntax (CMS). S. Blake-Wilson, D. Brown, P.
+     Lambert. April 2002. (Format: TXT=33779 bytes) (Status:
+     INFORMATIONAL)
+
+3281 An Internet Attribute Certificate Profile for Authorization. S.
+     Farrell, R. Housley. April 2002. (Format: TXT=90580 bytes) (Status:
+     PROPOSED STANDARD)
+
+3369 Cryptographic Message Syntax (CMS). R. Housley. August 2002.
+     (Format: TXT=113975 bytes) (Obsoletes RFC2630, RFC3211) (Status:
+     PROPOSED STANDARD)
+
+3370 Cryptographic Message Syntax (CMS) Algorithms. R. Housley. August
+     2002. (Format: TXT=51001 bytes) (Obsoletes RFC2630, RFC3211) (Status:
+     PROPOSED STANDARD)
+
+3377 Lightweight Directory Access Protocol (v3): Technical
+     Specification. J. Hodges, R. Morgan. September 2002. (Format:
+     TXT=9981 bytes) (Updates RFC2251, RFC2252, RFC2253, RFC2254, RFC2255,
+     RFC2256, RFC2829, RFC2830) (Status: PROPOSED STANDARD)
+
+3394 Advanced Encryption Standard (AES) Key Wrap Algorithm. J. Schaad,
+     R. Housley. September 2002. (Format: TXT=73072 bytes) (Status:
+     INFORMATIONAL)
+
+3436 Transport Layer Security over Stream Control Transmission
+     Protocol. A. Jungmaier, E. Rescorla, M. Tuexen. December 2002.
+     (Format: TXT=16333 bytes) (Status: PROPOSED STANDARD)
+
+3657 Use of the Camellia Encryption Algorithm in Cryptographic 
+     Message Syntax (CMS). S. Moriai, A. Kato. January 2004.
+     (Format: TXT=26282 bytes) (Status: PROPOSED STANDARD)
+
+"Securing FTP with TLS", 01/27/2000, <draft-murray-auth-ftp-ssl-05.txt>  
+
+To be implemented:
+------------------
+
+These are documents that describe things that are planed to be
+implemented in the hopefully short future.
+
index cc90f5e..5ceeeeb 100644 (file)
@@ -112,7 +112,7 @@ extern "C" {
 /********************************************************************
  The Microsoft section
  ********************************************************************/
-/* The following is used becaue of the small stack in some
+/* The following is used because of the small stack in some
  * Microsoft operating systems */
 #if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYSNAME_WIN32)
 #  define MS_STATIC    static
@@ -123,9 +123,6 @@ extern "C" {
 #if defined(OPENSSL_SYS_WIN32) && !defined(WIN32)
 #  define WIN32
 #endif
-#if defined(OPENSSL_SYS_WIN16) && !defined(WIN16)
-#  define WIN16
-#endif
 #if defined(OPENSSL_SYS_WINDOWS) && !defined(WINDOWS)
 #  define WINDOWS
 #endif
@@ -180,6 +177,13 @@ extern "C" {
 #define closesocket(s)             close(s)
 #define readsocket(s,b,n)          read((s),(b),(n))
 #define writesocket(s,b,n)         write((s),(char *)(b),(n))
+#elif defined(OPENSSL_SYS_BEOS_R5)
+#define get_last_socket_error() errno
+#define clear_socket_error()    errno=0
+#define FIONBIO SO_NONBLOCK
+#define ioctlsocket(a,b,c)               setsockopt((a),SOL_SOCKET,(b),(c),sizeof(*(c)))
+#define readsocket(s,b,n)       recv((s),(b),(n),0)
+#define writesocket(s,b,n)      send((s),(b),(n),0)
 #elif defined(OPENSSL_SYS_NETWARE)
 #if defined(NETWARE_BSDSOCK)
 #define get_last_socket_error() errno
@@ -208,7 +212,7 @@ extern "C" {
 #define writesocket(s,b,n)     write((s),(b),(n))
 #endif
 
-#ifdef WIN16
+#ifdef WIN16 /* never the case */
 #  define MS_CALLBACK  _far _loadds
 #  define MS_FAR       _far
 #else
@@ -254,19 +258,31 @@ extern "C" {
        /*
        * Defining _WIN32_WINNT here in e_os.h implies certain "discipline."
        * Most notably we ought to check for availability of each specific
-       * routine with GetProcAddress() and/or quard NT-specific calls with
+       * routine with GetProcAddress() and/or guard NT-specific calls with
        * GetVersion() < 0x80000000. One can argue that in latter "or" case
        * we ought to /DELAYLOAD some .DLLs in order to protect ourselves
        * against run-time link errors. This doesn't seem to be necessary,
        * because it turned out that already Windows 95, first non-NT Win32
        * implementation, is equipped with at least NT 3.51 stubs, dummy
        * routines with same name, but which do nothing. Meaning that it's
-       * apparently appropriate to guard generic NT calls with GetVersion
-       * alone, while NT 4.0 and above calls ought to be additionally
-       * checked upon with GetProcAddress.
+       * apparently sufficient to guard "vanilla" NT calls with GetVersion
+       * alone, while NT 4.0 and above interfaces ought to be linked with
+       * GetProcAddress at run-time.
        */
 #      define _WIN32_WINNT 0x0400
 #    endif
+#    if !defined(OPENSSL_NO_SOCK) && defined(_WIN32_WINNT)
+       /*
+        * Just like defining _WIN32_WINNT including winsock2.h implies
+        * certain "discipline" for maintaining [broad] binary compatibility.
+        * As long as structures are invariant among Winsock versions,
+        * it's sufficient to check for specific Winsock2 API availability
+        * at run-time [DSO_global_lookup is recommended]...
+        */
+#      include <winsock2.h>
+#      include <ws2tcpip.h>
+       /* yes, they have to be #included prior to <windows.h> */
+#    endif
 #    include <windows.h>
 #    include <stdio.h>
 #    include <stddef.h>
@@ -307,8 +323,8 @@ static unsigned int _strlen31(const char *str)
          /* pre-1300 has __p__iob(), but it's available only in msvcrt.lib,
           * or in other words with /MD. Declaring implicit import, i.e.
           * with _imp_ prefix, works correctly with all compiler options,
-          * but without /MD results in LINK warning LNK4049:
-          * 'locally defined symbol "__iob" imported'.
+         * but without /MD results in LINK warning LNK4049:
+         * 'locally defined symbol "__iob" imported'.
           */
          extern FILE *_imp___iob;
 #        define stdin  (&_imp___iob[0])
@@ -321,7 +337,7 @@ static unsigned int _strlen31(const char *str)
 #  include <fcntl.h>
 
 #  ifdef OPENSSL_SYS_WINCE
-#    include <winsock_extras.h>
+#    define OPENSSL_NO_POSIX_IO
 #  endif
 
 #  define ssize_t long
@@ -334,12 +350,7 @@ static unsigned int _strlen31(const char *str)
 #    define _kbhit kbhit
 #  endif
 
-#  if defined(WIN16) && defined(SSLEAY) && defined(_WINEXITNOPERSIST)
-#    define EXIT(n) _wsetexit(_WINEXITNOPERSIST)
-#    define OPENSSL_EXIT(n) do { if (n == 0) EXIT(n); return(n); } while(0)
-#  else
-#    define EXIT(n) exit(n)
-#  endif
+#  define EXIT(n) exit(n)
 #  define LIST_SEPARATOR_CHAR ';'
 #  ifndef X_OK
 #    define X_OK       0
@@ -360,7 +371,7 @@ static unsigned int _strlen31(const char *str)
 #    define DEFAULT_HOME  "C:"
 #  endif
 
-#else /* The non-microsoft world world */
+#else /* The non-microsoft world */
 
 #  ifdef OPENSSL_SYS_VMS
 #    define VMS 1
@@ -413,7 +424,6 @@ static unsigned int _strlen31(const char *str)
        extern int GetThreadID(void);
 /* #      include <conio.h> */
        extern int kbhit(void);
-       extern void delay(unsigned milliseconds);
 #    else
 #      include <screen.h>
 #    endif
@@ -453,6 +463,10 @@ static unsigned int _strlen31(const char *str)
 #      define setvbuf(a, b, c, d) setbuffer((a), (b), (d))
        typedef unsigned long clock_t;
 #    endif
+#    ifdef OPENSSL_SYS_WIN32_CYGWIN
+#      include <io.h>
+#      include <fcntl.h>
+#    endif
 
 #    define OPENSSL_CONF       "openssl.cnf"
 #    define SSLEAY_CONF                OPENSSL_CONF
@@ -479,8 +493,19 @@ static unsigned int _strlen31(const char *str)
 #      define SHUTDOWN(fd)             close(fd)
 #      define SHUTDOWN2(fd)            close(fd)
 #    elif !defined(__DJGPP__)
-#      include <winsock.h>
-extern HINSTANCE _hInstance;
+#      if defined(_WIN32_WCE) && _WIN32_WCE<410
+#        define getservbyname _masked_declaration_getservbyname
+#      endif
+#      if !defined(IPPROTO_IP)
+         /* winsock[2].h was included already? */
+#        include <winsock.h>
+#      endif
+#      ifdef getservbyname
+#        undef getservbyname
+         /* this is used to be wcecompat/include/winsock_extras.h */
+         struct servent* PASCAL getservbyname(const char*,const char*);
+#      endif
+
 #      ifdef _WIN64
 /*
  * Even though sizeof(SOCKET) is 8, it's safe to cast it to int, because
@@ -552,8 +577,10 @@ extern HINSTANCE _hInstance;
 #        include <sys/filio.h> /* Added for FIONBIO under unixware */
 #      endif
 #      include <netinet/in.h>
+#      if !defined(OPENSSL_SYS_BEOS_R5)
 #      include <arpa/inet.h>
 #    endif
+#    endif
 
 #    if defined(NeXT) || defined(_NEXT_SOURCE)
 #      include <sys/fcntl.h>
@@ -596,6 +623,18 @@ extern HINSTANCE _hInstance;
 #    define INVALID_SOCKET     (-1)
 #    endif /* INVALID_SOCKET */
 #  endif
+
+/* Some IPv6 implementations are broken, disable them in known bad
+ * versions.
+ */
+#  if !defined(OPENSSL_USE_IPV6)
+#    if defined(AF_INET6) && !defined(OPENSSL_SYS_BEOS_BONE) && !defined(NETWARE_CLIB)
+#      define OPENSSL_USE_IPV6 1
+#    else
+#      define OPENSSL_USE_IPV6 0
+#    endif
+#  endif
+
 #endif
 
 #if defined(__ultrix)
@@ -629,18 +668,6 @@ extern char *sys_errlist[]; extern int sys_nerr;
 
 /***********************************************/
 
-/* do we need to do this for getenv.
- * Just define getenv for use under windows */
-
-#ifdef WIN16
-/* How to do this needs to be thought out a bit more.... */
-/*char *GETENV(char *);
-#define Getenv GETENV*/
-#define Getenv getenv
-#else
-#define Getenv getenv
-#endif
-
 #define DG_GCC_BUG     /* gcc < 2.6.3 on DGUX */
 
 #ifdef sgi
@@ -702,6 +729,15 @@ struct servent *getservbyname(const char *name, const char *proto);
 #endif
 /* end vxworks */
 
+/* beos */
+#if defined(OPENSSL_SYS_BEOS_R5)
+#define SO_ERROR 0
+#define NO_SYS_UN
+#define IPPROTO_IP 0
+#include <OS.h>
+#endif
+
+
 #ifdef  __cplusplus
 }
 #endif
index 9da0b65..d30724d 100644 (file)
@@ -193,8 +193,14 @@ extern "C" {
 #endif
 
 /* --------------------------------- VOS ----------------------------------- */
-#ifdef OPENSSL_SYSNAME_VOS
+#if defined(__VOS__) || defined(OPENSSL_SYSNAME_VOS)
 # define OPENSSL_SYS_VOS
+#ifdef __HPPA__
+# define OPENSSL_SYS_VOS_HPPA
+#endif
+#ifdef __IA32__
+# define OPENSSL_SYS_VOS_IA32
+#endif
 #endif
 
 /* ------------------------------- VxWorks --------------------------------- */
@@ -202,6 +208,17 @@ extern "C" {
 # define OPENSSL_SYS_VXWORKS
 #endif
 
+/* --------------------------------- BeOS ---------------------------------- */
+#if defined(__BEOS__)
+# define OPENSSL_SYS_BEOS
+# include <sys/socket.h>
+# if defined(BONE_VERSION)
+#  define OPENSSL_SYS_BEOS_BONE
+# else
+#  define OPENSSL_SYS_BEOS_R5
+# endif
+#endif
+
 /**
  * That's it for OS-specific stuff
  *****************************************************************************/
@@ -251,24 +268,23 @@ extern "C" {
 #define OPENSSL_EXTERN OPENSSL_IMPORT
 
 /* Macros to allow global variables to be reached through function calls when
-   required (if a shared library version requvres it, for example.
+   required (if a shared library version requires it, for example.
    The way it's done allows definitions like this:
 
        // in foobar.c
-       OPENSSL_IMPLEMENT_GLOBAL(int,foobar) = 0;
+       OPENSSL_IMPLEMENT_GLOBAL(int,foobar,0)
        // in foobar.h
        OPENSSL_DECLARE_GLOBAL(int,foobar);
        #define foobar OPENSSL_GLOBAL_REF(foobar)
 */
 #ifdef OPENSSL_EXPORT_VAR_AS_FUNCTION
-# define OPENSSL_IMPLEMENT_GLOBAL(type,name)                        \
-       extern type _hide_##name;                                    \
-       type *_shadow_##name(void) { return &_hide_##name; }         \
-       static type _hide_##name
+# define OPENSSL_IMPLEMENT_GLOBAL(type,name,value)                     \
+       type *_shadow_##name(void)                                      \
+       { static type _hide_##name=value; return &_hide_##name; }
 # define OPENSSL_DECLARE_GLOBAL(type,name) type *_shadow_##name(void)
 # define OPENSSL_GLOBAL_REF(name) (*(_shadow_##name()))
 #else
-# define OPENSSL_IMPLEMENT_GLOBAL(type,name) OPENSSL_GLOBAL type _shadow_##name
+# define OPENSSL_IMPLEMENT_GLOBAL(type,name,value) OPENSSL_GLOBAL type _shadow_##name=value;
 # define OPENSSL_DECLARE_GLOBAL(type,name) OPENSSL_EXPORT type _shadow_##name
 # define OPENSSL_GLOBAL_REF(name) _shadow_##name
 #endif
index 7f13cd9..2fa9534 100644 (file)
@@ -9,6 +9,12 @@ INCLUDES= -I../include
 CFLAG=-g
 MAKEFILE=      Makefile
 AR=            ar r
+ENGDIRS= ccgost
+
+RECURSIVE_MAKE=        [ -z "$(ENGDIRS)" ] || for i in $(ENGDIRS) ; do \
+                   (cd $$i && echo "making $$target in $(DIR)/$$i..." && \
+                   $(MAKE) -e TOP=../.. DIR=$$i $$target ) || exit 1; \
+               done;
 
 PEX_LIBS=
 EX_LIBS=
@@ -20,7 +26,7 @@ TEST=
 APPS=
 
 LIB=$(TOP)/libcrypto.a
-LIBNAMES= 4758cca aep atalla cswift gmp chil nuron sureware ubsec capi
+LIBNAMES= 4758cca aep atalla cswift gmp chil nuron sureware ubsec padlock capi
 
 LIBSRC=        e_4758cca.c \
        e_aep.c \
@@ -31,6 +37,7 @@ LIBSRC=       e_4758cca.c \
        e_nuron.c \
        e_sureware.c \
        e_ubsec.c \
+       e_padlock.c \
        e_capi.c
 LIBOBJ= e_4758cca.o \
        e_aep.o \
@@ -41,6 +48,7 @@ LIBOBJ= e_4758cca.o \
        e_nuron.o \
        e_sureware.o \
        e_ubsec.o \
+       e_padlock.o \
        e_capi.o
 
 SRC= $(LIBSRC)
@@ -62,7 +70,7 @@ ALL=    $(GENERAL) $(SRC) $(HEADER)
 top:
        (cd ..; $(MAKE) DIRS=$(DIR) all)
 
-all:   lib
+all:   lib subdirs
 
 lib:   $(LIBOBJ)
        @if [ -n "$(SHARED_LIBS)" ]; then \
@@ -79,37 +87,48 @@ lib:        $(LIBOBJ)
        fi; \
        touch lib
 
+subdirs:
+       echo $(EDIRS)
+       @target=all; $(RECURSIVE_MAKE)
+
 files:
        $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
+       @target=files; $(RECURSIVE_MAKE)
 
 links:
+       @target=links; $(RECURSIVE_MAKE)
 
 # XXXXX This currently only works on systems that use .so as suffix
 # for shared libraries as well as for Cygwin which uses the
 # dlfcn_name_converter and therefore stores the engines with .so suffix, too.
 # XXXXX This was extended to HP-UX dl targets, which use .sl suffix.
+# XXXXX This was extended to mingw targets, which use eay32.dll suffix without lib as prefix.
 install:
        @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
        @if [ -n "$(SHARED_LIBS)" ]; then \
                set -e; \
-               $(PERL) $(TOP)/util/mkdir-p.pl $(INSTALL_PREFIX)$(INSTALLTOP)/lib/engines; \
+               $(PERL) $(TOP)/util/mkdir-p.pl $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines; \
                for l in $(LIBNAMES); do \
                        ( echo installing $$l; \
+                         pfx=lib; \
                          if [ "$(PLATFORM)" != "Cygwin" ]; then \
                                case "$(CFLAGS)" in \
-                               *DSO_DLFCN*)    sfx="so";;      \
-                               *DSO_DL*)       sfx="sl";;      \
-                               *)              sfx="bad";;     \
+                               *DSO_BEOS*)     sfx=".so";;     \
+                               *DSO_DLFCN*)    sfx=`expr "$(SHLIB_EXT)" : '.*\(\.[a-z][a-z]*\)' \| ".so"`;;    \
+                               *DSO_DL*)       sfx=".sl";;     \
+                               *DSO_WIN32*)    sfx="eay32.dll"; pfx=;; \
+                               *)              sfx=".bad";;    \
                                esac; \
-                               cp lib$$l.$$sfx $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/lib$$l.$$sfx.new; \
+                               cp $$pfx$$l$$sfx $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$$pfx$$l$$sfx.new; \
                          else \
-                               sfx="so"; \
-                               cp cyg$$l.dll $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/lib$$l.$$sfx.new; \
+                               sfx=".so"; \
+                               cp cyg$$l.dll $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$$pfx$$l$$sfx.new; \
                          fi; \
-                         chmod 555 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/lib$$l.$$sfx.new; \
-                         mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/lib$$l.$$sfx.new $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/lib$$l.$$sfx ); \
+                         chmod 555 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$$pfx$$l$$sfx.new; \
+                         mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$$pfx$$l$$sfx.new $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$$pfx$$l$$sfx ); \
                done; \
        fi
+       @target=install; $(RECURSIVE_MAKE)
 
 tags:
        ctags $(SRC)
@@ -119,25 +138,29 @@ errors:
                $(PERL) ../util/mkerr.pl -conf e_$$l.ec \
                        -nostatic -staticloader -write e_$$l.c; \
        done
+       (cd ccgost; $(MAKE) PERL=$(PERL) errors)
 
 tests:
 
 lint:
        lint -DLINT $(INCLUDES) $(SRC)>fluff
+       @target=lint; $(RECURSIVE_MAKE)
 
 depend:
        @if [ -z "$(THIS)" ]; then \
            $(MAKE) -f $(TOP)/Makefile reflect THIS=$@; \
-       else \
-           $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC); \
        fi
+       @[ -z "$(THIS)" ] || $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
+       @[ -z "$(THIS)" ] || (set -e; target=depend; $(RECURSIVE_MAKE) )
 
 dclean:
        $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
        mv -f Makefile.new $(MAKEFILE)
+       @target=dclean; $(RECURSIVE_MAKE)
 
 clean:
        rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
+       @target=clean; $(RECURSIVE_MAKE)
 
 # DO NOT DELETE THIS LINE -- make depend depends on it.
 
@@ -147,16 +170,16 @@ e_4758cca.o: ../include/openssl/crypto.h ../include/openssl/dso.h
 e_4758cca.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
 e_4758cca.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
 e_4758cca.o: ../include/openssl/engine.h ../include/openssl/err.h
-e_4758cca.o: ../include/openssl/evp.h ../include/openssl/fips.h
-e_4758cca.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-e_4758cca.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
-e_4758cca.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-e_4758cca.o: ../include/openssl/pkcs7.h ../include/openssl/rand.h
-e_4758cca.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-e_4758cca.o: ../include/openssl/sha.h ../include/openssl/stack.h
-e_4758cca.o: ../include/openssl/symhacks.h ../include/openssl/x509.h
-e_4758cca.o: ../include/openssl/x509_vfy.h e_4758cca.c e_4758cca_err.c
-e_4758cca.o: e_4758cca_err.h vendor_defns/hw_4758_cca.h
+e_4758cca.o: ../include/openssl/evp.h ../include/openssl/lhash.h
+e_4758cca.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+e_4758cca.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+e_4758cca.o: ../include/openssl/ossl_typ.h ../include/openssl/pkcs7.h
+e_4758cca.o: ../include/openssl/rand.h ../include/openssl/rsa.h
+e_4758cca.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+e_4758cca.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+e_4758cca.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
+e_4758cca.o: e_4758cca.c e_4758cca_err.c e_4758cca_err.h
+e_4758cca.o: vendor_defns/hw_4758_cca.h
 e_aep.o: ../include/openssl/asn1.h ../include/openssl/bio.h
 e_aep.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 e_aep.o: ../include/openssl/crypto.h ../include/openssl/dh.h
@@ -164,15 +187,15 @@ e_aep.o: ../include/openssl/dsa.h ../include/openssl/dso.h
 e_aep.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
 e_aep.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
 e_aep.o: ../include/openssl/engine.h ../include/openssl/err.h
-e_aep.o: ../include/openssl/evp.h ../include/openssl/fips.h
-e_aep.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-e_aep.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
-e_aep.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-e_aep.o: ../include/openssl/pkcs7.h ../include/openssl/rsa.h
-e_aep.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-e_aep.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-e_aep.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h e_aep.c
-e_aep.o: e_aep_err.c e_aep_err.h vendor_defns/aep.h
+e_aep.o: ../include/openssl/evp.h ../include/openssl/lhash.h
+e_aep.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+e_aep.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+e_aep.o: ../include/openssl/ossl_typ.h ../include/openssl/pkcs7.h
+e_aep.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+e_aep.o: ../include/openssl/sha.h ../include/openssl/stack.h
+e_aep.o: ../include/openssl/symhacks.h ../include/openssl/x509.h
+e_aep.o: ../include/openssl/x509_vfy.h e_aep.c e_aep_err.c e_aep_err.h
+e_aep.o: vendor_defns/aep.h
 e_atalla.o: ../include/openssl/asn1.h ../include/openssl/bio.h
 e_atalla.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 e_atalla.o: ../include/openssl/crypto.h ../include/openssl/dh.h
@@ -180,28 +203,27 @@ e_atalla.o: ../include/openssl/dsa.h ../include/openssl/dso.h
 e_atalla.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
 e_atalla.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
 e_atalla.o: ../include/openssl/engine.h ../include/openssl/err.h
-e_atalla.o: ../include/openssl/evp.h ../include/openssl/fips.h
-e_atalla.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-e_atalla.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
-e_atalla.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-e_atalla.o: ../include/openssl/pkcs7.h ../include/openssl/rsa.h
-e_atalla.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-e_atalla.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-e_atalla.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h e_atalla.c
-e_atalla.o: e_atalla_err.c e_atalla_err.h vendor_defns/atalla.h
+e_atalla.o: ../include/openssl/evp.h ../include/openssl/lhash.h
+e_atalla.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+e_atalla.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+e_atalla.o: ../include/openssl/ossl_typ.h ../include/openssl/pkcs7.h
+e_atalla.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+e_atalla.o: ../include/openssl/sha.h ../include/openssl/stack.h
+e_atalla.o: ../include/openssl/symhacks.h ../include/openssl/x509.h
+e_atalla.o: ../include/openssl/x509_vfy.h e_atalla.c e_atalla_err.c
+e_atalla.o: e_atalla_err.h vendor_defns/atalla.h
 e_capi.o: ../include/openssl/asn1.h ../include/openssl/bio.h
 e_capi.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 e_capi.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
 e_capi.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 e_capi.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
-e_capi.o: ../include/openssl/evp.h ../include/openssl/fips.h
-e_capi.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-e_capi.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
-e_capi.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-e_capi.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
-e_capi.o: ../include/openssl/sha.h ../include/openssl/stack.h
-e_capi.o: ../include/openssl/symhacks.h ../include/openssl/x509.h
-e_capi.o: ../include/openssl/x509_vfy.h e_capi.c
+e_capi.o: ../include/openssl/evp.h ../include/openssl/lhash.h
+e_capi.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+e_capi.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+e_capi.o: ../include/openssl/ossl_typ.h ../include/openssl/pkcs7.h
+e_capi.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+e_capi.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+e_capi.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h e_capi.c
 e_chil.o: ../include/openssl/asn1.h ../include/openssl/bio.h
 e_chil.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 e_chil.o: ../include/openssl/crypto.h ../include/openssl/dh.h
@@ -209,17 +231,16 @@ e_chil.o: ../include/openssl/dso.h ../include/openssl/e_os2.h
 e_chil.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 e_chil.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
 e_chil.o: ../include/openssl/err.h ../include/openssl/evp.h
-e_chil.o: ../include/openssl/fips.h ../include/openssl/lhash.h
-e_chil.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
-e_chil.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
-e_chil.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
-e_chil.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-e_chil.o: ../include/openssl/rand.h ../include/openssl/rsa.h
-e_chil.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-e_chil.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-e_chil.o: ../include/openssl/ui.h ../include/openssl/x509.h
-e_chil.o: ../include/openssl/x509_vfy.h e_chil.c e_chil_err.c e_chil_err.h
-e_chil.o: vendor_defns/hwcryptohook.h
+e_chil.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+e_chil.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
+e_chil.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+e_chil.o: ../include/openssl/pem.h ../include/openssl/pem2.h
+e_chil.o: ../include/openssl/pkcs7.h ../include/openssl/rand.h
+e_chil.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+e_chil.o: ../include/openssl/sha.h ../include/openssl/stack.h
+e_chil.o: ../include/openssl/symhacks.h ../include/openssl/ui.h
+e_chil.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h e_chil.c
+e_chil.o: e_chil_err.c e_chil_err.h vendor_defns/hwcryptohook.h
 e_cswift.o: ../include/openssl/asn1.h ../include/openssl/bio.h
 e_cswift.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 e_cswift.o: ../include/openssl/crypto.h ../include/openssl/dh.h
@@ -227,29 +248,28 @@ e_cswift.o: ../include/openssl/dsa.h ../include/openssl/dso.h
 e_cswift.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
 e_cswift.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
 e_cswift.o: ../include/openssl/engine.h ../include/openssl/err.h
-e_cswift.o: ../include/openssl/evp.h ../include/openssl/fips.h
-e_cswift.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-e_cswift.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
-e_cswift.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-e_cswift.o: ../include/openssl/pkcs7.h ../include/openssl/rand.h
-e_cswift.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-e_cswift.o: ../include/openssl/sha.h ../include/openssl/stack.h
-e_cswift.o: ../include/openssl/symhacks.h ../include/openssl/x509.h
-e_cswift.o: ../include/openssl/x509_vfy.h e_cswift.c e_cswift_err.c
-e_cswift.o: e_cswift_err.h vendor_defns/cswift.h
+e_cswift.o: ../include/openssl/evp.h ../include/openssl/lhash.h
+e_cswift.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+e_cswift.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+e_cswift.o: ../include/openssl/ossl_typ.h ../include/openssl/pkcs7.h
+e_cswift.o: ../include/openssl/rand.h ../include/openssl/rsa.h
+e_cswift.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+e_cswift.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+e_cswift.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h e_cswift.c
+e_cswift.o: e_cswift_err.c e_cswift_err.h vendor_defns/cswift.h
 e_gmp.o: ../include/openssl/asn1.h ../include/openssl/bio.h
 e_gmp.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 e_gmp.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
 e_gmp.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 e_gmp.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
-e_gmp.o: ../include/openssl/evp.h ../include/openssl/fips.h
-e_gmp.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-e_gmp.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
-e_gmp.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-e_gmp.o: ../include/openssl/pkcs7.h ../include/openssl/rsa.h
-e_gmp.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-e_gmp.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-e_gmp.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h e_gmp.c
+e_gmp.o: ../include/openssl/evp.h ../include/openssl/lhash.h
+e_gmp.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+e_gmp.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+e_gmp.o: ../include/openssl/ossl_typ.h ../include/openssl/pkcs7.h
+e_gmp.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+e_gmp.o: ../include/openssl/sha.h ../include/openssl/stack.h
+e_gmp.o: ../include/openssl/symhacks.h ../include/openssl/x509.h
+e_gmp.o: ../include/openssl/x509_vfy.h e_gmp.c
 e_nuron.o: ../include/openssl/asn1.h ../include/openssl/bio.h
 e_nuron.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 e_nuron.o: ../include/openssl/crypto.h ../include/openssl/dh.h
@@ -257,15 +277,28 @@ e_nuron.o: ../include/openssl/dsa.h ../include/openssl/dso.h
 e_nuron.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
 e_nuron.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
 e_nuron.o: ../include/openssl/engine.h ../include/openssl/err.h
-e_nuron.o: ../include/openssl/evp.h ../include/openssl/fips.h
-e_nuron.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-e_nuron.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
-e_nuron.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-e_nuron.o: ../include/openssl/pkcs7.h ../include/openssl/rsa.h
-e_nuron.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-e_nuron.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-e_nuron.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h e_nuron.c
-e_nuron.o: e_nuron_err.c e_nuron_err.h
+e_nuron.o: ../include/openssl/evp.h ../include/openssl/lhash.h
+e_nuron.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+e_nuron.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+e_nuron.o: ../include/openssl/ossl_typ.h ../include/openssl/pkcs7.h
+e_nuron.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+e_nuron.o: ../include/openssl/sha.h ../include/openssl/stack.h
+e_nuron.o: ../include/openssl/symhacks.h ../include/openssl/x509.h
+e_nuron.o: ../include/openssl/x509_vfy.h e_nuron.c e_nuron_err.c e_nuron_err.h
+e_padlock.o: ../include/openssl/aes.h ../include/openssl/asn1.h
+e_padlock.o: ../include/openssl/bio.h ../include/openssl/buffer.h
+e_padlock.o: ../include/openssl/crypto.h ../include/openssl/dso.h
+e_padlock.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
+e_padlock.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
+e_padlock.o: ../include/openssl/engine.h ../include/openssl/err.h
+e_padlock.o: ../include/openssl/evp.h ../include/openssl/lhash.h
+e_padlock.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+e_padlock.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+e_padlock.o: ../include/openssl/ossl_typ.h ../include/openssl/pkcs7.h
+e_padlock.o: ../include/openssl/rand.h ../include/openssl/safestack.h
+e_padlock.o: ../include/openssl/sha.h ../include/openssl/stack.h
+e_padlock.o: ../include/openssl/symhacks.h ../include/openssl/x509.h
+e_padlock.o: ../include/openssl/x509_vfy.h e_padlock.c
 e_sureware.o: ../include/openssl/asn1.h ../include/openssl/bio.h
 e_sureware.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 e_sureware.o: ../include/openssl/crypto.h ../include/openssl/dh.h
@@ -273,17 +306,17 @@ e_sureware.o: ../include/openssl/dsa.h ../include/openssl/dso.h
 e_sureware.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
 e_sureware.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
 e_sureware.o: ../include/openssl/engine.h ../include/openssl/err.h
-e_sureware.o: ../include/openssl/evp.h ../include/openssl/fips.h
-e_sureware.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-e_sureware.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
-e_sureware.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-e_sureware.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-e_sureware.o: ../include/openssl/pkcs7.h ../include/openssl/rand.h
-e_sureware.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-e_sureware.o: ../include/openssl/sha.h ../include/openssl/stack.h
-e_sureware.o: ../include/openssl/symhacks.h ../include/openssl/x509.h
-e_sureware.o: ../include/openssl/x509_vfy.h e_sureware.c e_sureware_err.c
-e_sureware.o: e_sureware_err.h vendor_defns/sureware.h
+e_sureware.o: ../include/openssl/evp.h ../include/openssl/lhash.h
+e_sureware.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+e_sureware.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+e_sureware.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+e_sureware.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
+e_sureware.o: ../include/openssl/rand.h ../include/openssl/rsa.h
+e_sureware.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+e_sureware.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+e_sureware.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
+e_sureware.o: e_sureware.c e_sureware_err.c e_sureware_err.h
+e_sureware.o: vendor_defns/sureware.h
 e_ubsec.o: ../include/openssl/asn1.h ../include/openssl/bio.h
 e_ubsec.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 e_ubsec.o: ../include/openssl/crypto.h ../include/openssl/dh.h
@@ -291,12 +324,12 @@ e_ubsec.o: ../include/openssl/dsa.h ../include/openssl/dso.h
 e_ubsec.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
 e_ubsec.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
 e_ubsec.o: ../include/openssl/engine.h ../include/openssl/err.h
-e_ubsec.o: ../include/openssl/evp.h ../include/openssl/fips.h
-e_ubsec.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-e_ubsec.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
-e_ubsec.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-e_ubsec.o: ../include/openssl/pkcs7.h ../include/openssl/rsa.h
-e_ubsec.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-e_ubsec.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-e_ubsec.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h e_ubsec.c
-e_ubsec.o: e_ubsec_err.c e_ubsec_err.h vendor_defns/hw_ubsec.h
+e_ubsec.o: ../include/openssl/evp.h ../include/openssl/lhash.h
+e_ubsec.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+e_ubsec.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+e_ubsec.o: ../include/openssl/ossl_typ.h ../include/openssl/pkcs7.h
+e_ubsec.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+e_ubsec.o: ../include/openssl/sha.h ../include/openssl/stack.h
+e_ubsec.o: ../include/openssl/symhacks.h ../include/openssl/x509.h
+e_ubsec.o: ../include/openssl/x509_vfy.h e_ubsec.c e_ubsec_err.c e_ubsec_err.h
+e_ubsec.o: vendor_defns/hw_ubsec.h
diff --git a/deps/openssl/openssl/engines/axp.opt b/deps/openssl/openssl/engines/axp.opt
new file mode 100644 (file)
index 0000000..1dc71bf
--- /dev/null
@@ -0,0 +1 @@
+SYMBOL_VECTOR=(bind_engine=PROCEDURE,v_check=PROCEDURE)
diff --git a/deps/openssl/openssl/engines/capierr.bat b/deps/openssl/openssl/engines/capierr.bat
new file mode 100644 (file)
index 0000000..274ffac
--- /dev/null
@@ -0,0 +1 @@
+perl ../util/mkerr.pl -conf e_capi.ec -nostatic -staticloader -write e_capi.c
diff --git a/deps/openssl/openssl/engines/ccgost/Makefile b/deps/openssl/openssl/engines/ccgost/Makefile
new file mode 100644 (file)
index 0000000..dadb523
--- /dev/null
@@ -0,0 +1,275 @@
+DIR=ccgost
+TOP=../..
+CC=cc
+INCLUDES= -I../../include
+CFLAG=-g
+MAKEFILE= Makefile
+AR= ar r
+CFLAGS= $(INCLUDES) $(CFLAG)
+LIB=$(TOP)/libcrypto.a
+
+LIBSRC= gost2001.c gost2001_keyx.c gost89.c gost94_keyx.c gost_ameth.c gost_asn1.c gost_crypt.c gost_ctl.c gost_eng.c gosthash.c gost_keywrap.c gost_md.c gost_params.c gost_pmeth.c gost_sign.c
+
+LIBOBJ= e_gost_err.o gost2001_keyx.o gost2001.o gost89.o gost94_keyx.o gost_ameth.o gost_asn1.o gost_crypt.o gost_ctl.o gost_eng.o gosthash.o gost_keywrap.o gost_md.o gost_params.o gost_pmeth.o gost_sign.o
+
+SRC=$(LIBSRC)
+
+LIBNAME=gost
+
+top: 
+       (cd $(TOP); $(MAKE) DIRS=engines EDIRS=$(DIR) sub_all)
+
+all: lib
+
+tags:
+       ctags $(SRC)
+
+errors:
+       $(PERL) ../../util/mkerr.pl -conf gost.ec -nostatic -write $(SRC)
+
+lib: $(LIBOBJ)
+       if [ -n "$(SHARED_LIBS)" ]; then \
+               $(MAKE) -f $(TOP)/Makefile.shared -e \
+                       LIBNAME=$(LIBNAME) \
+                       LIBEXTRAS='$(LIBOBJ)' \
+                       LIBDEPS='-L$(TOP) -lcrypto' \
+                       link_o.$(SHLIB_TARGET); \
+       else \
+               $(AR) $(LIB) $(LIBOBJ); \
+       fi
+       @touch lib
+
+install:
+       [ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
+       if [ -n "$(SHARED_LIBS)" ]; then \
+               set -e; \
+               echo installing $(LIBNAME); \
+               pfx=lib; \
+               if [ "$(PLATFORM)" != "Cygwin" ]; then \
+                       case "$(CFLAGS)" in \
+                       *DSO_BEOS*) sfx=".so";; \
+                       *DSO_DLFCN*) sfx=`expr "$(SHLIB_EXT)" : '.*\(\.[a-z][a-z]*\)' \| ".so"`;; \
+                       *DSO_DL*) sfx=".sl";; \
+                       *DSO_WIN32*) sfx="eay32.dll"; pfx=;; \
+                       *) sfx=".bad";; \
+                       esac; \
+                       cp $${pfx}$(LIBNAME)$$sfx $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$${pfx}$(LIBNAME)$$sfx.new; \
+               else \
+                       sfx=".so"; \
+                       cp cyg$(LIBNAME).dll $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$${pfx}$(LIBNAME)$$sfx.new; \
+               fi; \
+               chmod 555 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$${pfx}$(LIBNAME)$$sfx.new; \
+               mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$${pfx}$(LIBNAME)$$sfx.new $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$${pfx}$(LIBNAME)$$sfx; \
+       fi
+
+links:
+
+tests:
+
+depend:
+       @if [ -z "$(THIS)" ]; then \
+           $(MAKE) -f $(TOP)/Makefile reflect THIS=$@; \
+       else \
+           $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC); \
+       fi
+
+files:
+
+
+
+lint:
+       lint -DLINT $(INCLUDES) $(SRC)>fluff
+
+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 *.so *.sl *.dll
+
+# DO NOT DELETE THIS LINE -- make depend depends on it.
+
+gost2001.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
+gost2001.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
+gost2001.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
+gost2001.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
+gost2001.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+gost2001.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
+gost2001.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+gost2001.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+gost2001.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+gost2001.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+gost2001.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
+gost2001.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+gost2001.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+gost2001.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+gost2001.o: e_gost_err.h gost2001.c gost89.h gost_lcl.h gost_params.h
+gost2001.o: gosthash.h
+gost2001_keyx.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
+gost2001_keyx.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
+gost2001_keyx.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
+gost2001_keyx.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
+gost2001_keyx.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+gost2001_keyx.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
+gost2001_keyx.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+gost2001_keyx.o: ../../include/openssl/obj_mac.h
+gost2001_keyx.o: ../../include/openssl/objects.h
+gost2001_keyx.o: ../../include/openssl/opensslconf.h
+gost2001_keyx.o: ../../include/openssl/opensslv.h
+gost2001_keyx.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+gost2001_keyx.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
+gost2001_keyx.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+gost2001_keyx.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+gost2001_keyx.o: ../../include/openssl/x509_vfy.h e_gost_err.h gost2001_keyx.c
+gost2001_keyx.o: gost2001_keyx.h gost89.h gost_keywrap.h gost_lcl.h gosthash.h
+gost89.o: gost89.c gost89.h
+gost94_keyx.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
+gost94_keyx.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
+gost94_keyx.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
+gost94_keyx.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
+gost94_keyx.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+gost94_keyx.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
+gost94_keyx.o: ../../include/openssl/engine.h ../../include/openssl/evp.h
+gost94_keyx.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+gost94_keyx.o: ../../include/openssl/objects.h
+gost94_keyx.o: ../../include/openssl/opensslconf.h
+gost94_keyx.o: ../../include/openssl/opensslv.h
+gost94_keyx.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+gost94_keyx.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
+gost94_keyx.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+gost94_keyx.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+gost94_keyx.o: ../../include/openssl/x509_vfy.h e_gost_err.h gost89.h
+gost94_keyx.o: gost94_keyx.c gost_keywrap.h gost_lcl.h gosthash.h
+gost_ameth.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
+gost_ameth.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
+gost_ameth.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
+gost_ameth.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
+gost_ameth.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+gost_ameth.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
+gost_ameth.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+gost_ameth.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+gost_ameth.o: ../../include/openssl/objects.h
+gost_ameth.o: ../../include/openssl/opensslconf.h
+gost_ameth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+gost_ameth.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+gost_ameth.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+gost_ameth.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+gost_ameth.o: ../../include/openssl/x509_vfy.h e_gost_err.h gost89.h
+gost_ameth.o: gost_ameth.c gost_lcl.h gost_params.h gosthash.h
+gost_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
+gost_asn1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
+gost_asn1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
+gost_asn1.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
+gost_asn1.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+gost_asn1.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
+gost_asn1.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+gost_asn1.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+gost_asn1.o: ../../include/openssl/opensslconf.h
+gost_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+gost_asn1.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+gost_asn1.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+gost_asn1.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+gost_asn1.o: ../../include/openssl/x509_vfy.h gost89.h gost_asn1.c gost_lcl.h
+gost_asn1.o: gosthash.h
+gost_crypt.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
+gost_crypt.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
+gost_crypt.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
+gost_crypt.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
+gost_crypt.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+gost_crypt.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
+gost_crypt.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+gost_crypt.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+gost_crypt.o: ../../include/openssl/opensslconf.h
+gost_crypt.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+gost_crypt.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
+gost_crypt.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+gost_crypt.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+gost_crypt.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+gost_crypt.o: e_gost_err.h gost89.h gost_crypt.c gost_lcl.h gosthash.h
+gost_ctl.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
+gost_ctl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
+gost_ctl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
+gost_ctl.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
+gost_ctl.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+gost_ctl.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
+gost_ctl.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+gost_ctl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+gost_ctl.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+gost_ctl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+gost_ctl.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+gost_ctl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+gost_ctl.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+gost_ctl.o: ../../include/openssl/x509_vfy.h gost89.h gost_ctl.c gost_lcl.h
+gost_ctl.o: gosthash.h
+gost_eng.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
+gost_eng.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
+gost_eng.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
+gost_eng.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
+gost_eng.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+gost_eng.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
+gost_eng.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+gost_eng.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+gost_eng.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+gost_eng.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+gost_eng.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+gost_eng.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+gost_eng.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+gost_eng.o: ../../include/openssl/x509_vfy.h e_gost_err.h gost89.h gost_eng.c
+gost_eng.o: gost_lcl.h gosthash.h
+gost_keywrap.o: gost89.h gost_keywrap.c gost_keywrap.h
+gost_md.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
+gost_md.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
+gost_md.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
+gost_md.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
+gost_md.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+gost_md.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
+gost_md.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+gost_md.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+gost_md.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+gost_md.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
+gost_md.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+gost_md.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+gost_md.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+gost_md.o: e_gost_err.h gost89.h gost_lcl.h gost_md.c gosthash.h
+gost_params.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
+gost_params.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+gost_params.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+gost_params.o: ../../include/openssl/opensslconf.h
+gost_params.o: ../../include/openssl/opensslv.h
+gost_params.o: ../../include/openssl/ossl_typ.h
+gost_params.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+gost_params.o: ../../include/openssl/symhacks.h gost_params.c gost_params.h
+gost_pmeth.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
+gost_pmeth.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
+gost_pmeth.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
+gost_pmeth.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
+gost_pmeth.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+gost_pmeth.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
+gost_pmeth.o: ../../include/openssl/engine.h ../../include/openssl/evp.h
+gost_pmeth.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+gost_pmeth.o: ../../include/openssl/objects.h
+gost_pmeth.o: ../../include/openssl/opensslconf.h
+gost_pmeth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+gost_pmeth.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+gost_pmeth.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+gost_pmeth.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+gost_pmeth.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+gost_pmeth.o: e_gost_err.h gost89.h gost_lcl.h gost_params.h gost_pmeth.c
+gost_pmeth.o: gosthash.h
+gost_sign.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
+gost_sign.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
+gost_sign.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
+gost_sign.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
+gost_sign.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+gost_sign.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
+gost_sign.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+gost_sign.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+gost_sign.o: ../../include/openssl/opensslconf.h
+gost_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+gost_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
+gost_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+gost_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+gost_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+gost_sign.o: e_gost_err.h gost89.h gost_lcl.h gost_params.h gost_sign.c
+gost_sign.o: gosthash.h
+gosthash.o: gost89.h gosthash.c gosthash.h
diff --git a/deps/openssl/openssl/engines/ccgost/README.gost b/deps/openssl/openssl/engines/ccgost/README.gost
new file mode 100644 (file)
index 0000000..c96cccc
--- /dev/null
@@ -0,0 +1,300 @@
+GOST ENGINE
+
+This engine provides implementation of Russian cryptography standard.
+This is also an example of adding new cryptoalgorithms into OpenSSL
+without changing its core. If OpenSSL is compiled with dynamic engine
+support, new algorithms can be added even without recompilation of
+OpenSSL and applications which use it.
+
+ALGORITHMS SUPPORTED
+
+GOST R 34.10-94 and GOST R 34.10-2001 - digital signature algorithms.
+   Also support key exchange based on public keys. See RFC 4357 for
+   details of VKO key exchange algorithm. These algorithms use
+   256 bit private keys. Public keys are 1024 bit for 94 and 512 bit for
+   2001 (which is elliptic-curve based). Key exchange algorithms
+   (VKO R 34.10) are supported on these keys too.
+   
+GOST R 34.11-94  Message digest algorithm. 256-bit hash value
+
+GOST 28147-89 - Symmetric cipher  with 256-bit key. Various modes are
+   defined in the standard, but only CFB and CNT modes are implemented
+   in the engine. To make statistical analysis more difficult, key
+   meshing is supported (see RFC 4357).
+
+GOST 28147-89 MAC mode. Message authentication code. While most MAC
+    algorithms  out there are based on hash functions using HMAC
+       algorithm, this algoritm is based on symmetric cipher. 
+       It has 256-bit symmetric key and only 32 bits of MAC value
+       (while HMAC has same key size and value size). 
+
+       It is implemented as combination of EVP_PKEY type and EVP_MD type.
+
+USAGE OF THESE ALGORITHMS
+
+This engine is designed to allow usage of this algorithms in the
+high-level openssl functions, such as PKI, S/MIME and TLS.
+
+See RFC 4490 for S/MIME with GOST algorithms and RFC 4491 for PKI.
+TLS support is implemented according IETF
+draft-chudov-cryptopro-cptls-03.txt and is compatible with
+CryptoPro CSP 3.0 and 3.6 as well as with MagPro CSP. 
+GOST ciphersuites implemented in CryptoPro CSP 2.0 are not supported
+because they use ciphersuite numbers used now by AES ciphersuites.
+
+To use the engine you have to load it via openssl configuration
+file. Applications should read openssl configuration file or provide
+their own means to load engines. Also, applications which operate with
+private keys, should use generic EVP_PKEY API instead of using RSA or
+other algorithm-specific API.
+
+CONFIGURATION FILE
+
+Configuration file should include following statement in the global
+section, i.e. before first bracketed section header (see config(5) for details)
+
+   openssl_conf = openssl_def
+
+where openssl_def is name of the section in configuration file which
+describes global defaults.
+
+This section should contain following statement:
+
+   [openssl_def]
+   engines = engine_section
+
+which points to the section which describes list of the engines to be
+loaded. This section should contain:
+
+       [engine_section]
+       gost = gost_section
+
+And section which describes configuration of the engine should contain
+
+       [gost_section]
+       engine_id = gost
+       dynamic_path = /usr/lib/ssl/engines/libgost.so
+       default_algorithms = ALL
+       CRYPT_PARAMS = id-Gost28147-89-CryptoPro-A-ParamSet
+
+Where engine_id parameter specifies name of engine (should be "gost").
+dynamic_path is a location of the loadable shared library implementing the
+engine. If the engine is compiled statically or is located in the OpenSSL
+engines directory, this line can be omitted. 
+default_algorithms parameter specifies that all algorithms, provided by
+engine, should be used.
+
+The CRYPT_PARAMS parameter is engine-specific. It allows the user to choose
+between different parameter sets of symmetric cipher algorithm. RFC 4357
+specifies several parameters for the GOST 28147-89 algorithm, but OpenSSL
+doesn't provide user interface to choose one when encrypting. So use engine
+configuration parameter instead.
+
+Value of this parameter can be either short name, defined in OpenSSL
+obj_dat.h header file or numeric representation of OID, defined in RFC
+4357. 
+
+USAGE WITH COMMAND LINE openssl UTILITY
+
+1. Generation of private key
+
+       openssl genpkey -algorithm gost2001 -pkeyopt paramset:A -out seckey.pem
+
+  Use -algorithm option to specify algorithm.
+  Use -pkeyopt option to pass paramset to algorithm. The following paramsets
+  are supported by 
+       gost94: 0,A,B,C,D,XA,XB,XC
+       gost2001: 0,A,B,C,XA,XB
+  You can also use numeric representation of OID as to destinate
+  paramset.
+
+  Paramsets starting with X are intended to use for key exchange keys.
+  Paramsets without X are for digital signature keys.
+
+  Paramset for both algorithms 0 is the test paramset which should be used
+  only for test purposes.
+
+There are no algorithm-specific things with generation of certificate
+request once you have a private key.
+
+2. Generation of certificate request along with private/public keypar
+
+   openssl req -newkey gost2001 -pkeyopt paramset:A
+
+   Syntax of -pkeyopt parameter is identical with genpkey command.
+
+   You can also use oldstyle syntax -newkey gost2001:paramfile, but in
+   this case you should create parameter file first. 
+
+   It can be created with
+
+   openssl genpkey -genparam -algorithm gost2001 -pkeyopt paramset:A\
+      -out paramfile.
+
+3. S/MIME operations
+
+If you want to send encrypted mail using GOST algorithms, don't forget
+to specify -gost89 as encryption algorithm for OpenSSL smime command.
+While OpenSSL is clever enough to find out that GOST R 34.11-94 digest
+must be used for digital signing with GOST private key, it have no way
+to derive symmetric encryption algorithm from key exchange keys.
+
+4. TLS operations
+
+OpenSSL supports all four ciphersuites defined in the IETF draft.
+Once you've loaded GOST key and certificate into your TLS server,
+ciphersuites which use GOST 28147-89 encryption are enabled.
+
+Ciphersuites with NULL encryption should be enabled explicitely if
+needed.
+
+GOST2001-GOST89-GOST89 Uses GOST R 34.10-2001 for auth and key exchange
+               GOST 28147-89 for encryption and GOST 28147-89 MAC
+GOST94-GOST89-GOST89 Uses GOST R 34.10-94 for auth and key exchange
+               GOST 28147-89 for encryption and GOST 28147-89 MAC
+GOST2001-NULL-GOST94 Uses GOST R 34.10-2001 for auth and key exchange,
+        no encryption and HMAC, based on GOST R 34.11-94
+GOST94-NULL-GOST94 Uses GOST R 34.10-94 for auth and key exchange,
+        no encryption and HMAC, based on GOST R 34.11-94
+
+Gost 94 and gost 2001 keys can be used simultaneously in the TLS server.
+RSA, DSA and EC keys can be used simultaneously with GOST keys, if
+server implementation supports loading more than two private
+key/certificate pairs. In this case ciphersuites which use any of loaded
+keys would be supported and clients can negotiate ones they wish.
+
+This allows creation of TLS servers which use GOST ciphersuites for
+Russian clients and RSA/DSA ciphersuites for foreign clients.
+
+5. Calculation of digests and symmetric encryption
+ OpenSSL provides specific commands (like sha1, aes etc) for calculation
+ of digests and symmetric encryption. Since such commands cannot be
+ added dynamically, no such commands are provided for GOST algorithms.
+ Use generic commands 'dgst' and 'enc'.
+
+ Calculation of GOST R 34.11-94 message digest
+
+ openssl dgst -md_gost94 datafile
+
+ Note that GOST R 34.11-94 specifies that digest value should be
+ interpreted as little-endian number, but OpenSSL outputs just hex dump
+ of digest value.
+
+ So, to obtain correct digest value, such as produced by gostsum utility
+ included in the engine distribution, bytes of output should be
+ reversed.
+ Calculation of HMAC based on GOST R 34.11-94
+
+ openssl dgst -md_gost94 -mac hmac -macopt key:<32 bytes of key> datafile
+  
+  (or use hexkey if key contain NUL bytes)
+ Calculation of GOST 28147 MAC
+
+ openssl dgst -mac gost-mac -macopt key:<32 bytes of key> datafile
+
+ Note absense of an option that specifies digest algorithm. gost-mac
+ algorithm supports only one digest (which is actually part of
+ implementation of this mac) and OpenSSL is clever enough to find out
+ this.
+
+ Encryption with GOST 28147 CFB mode
+ openssl enc -gost89 -out encrypted-file -in plain-text-file -k <passphrase>  
+ Encryption with GOST 28147 CNT mode
+ openssl enc -gost89-cnt -out encrypted-file -in plain-text-file -k <passphrase>
+
+
+6. Encrypting private keys and PKCS12
+
+To produce PKCS12 files compatible with MagPro CSP, you need to use
+GOST algorithm for encryption of PKCS12 file and also GOST R 34.11-94
+hash to derive key from password.
+
+openssl pksc12 -export -inkey gost.pem -in gost_cert.pem -keypbe gost89\
+   -certpbe gost89 -macalg md_gost94
+7. Testing speed of symmetric ciphers.
+   
+To test performance of GOST symmetric ciphers you should use -evp switch
+of the openssl speed command. Engine-provided ciphers couldn't be
+accessed by cipher-specific functions, only via generic evp interface
+
+ openssl speed -evp gost89
+ openssl speed -evp gost89-cnt
+
+
+PROGRAMMING INTERFACES DETAILS
+
+Applications never should access engine directly. They only use provided
+EVP_PKEY API. But there are some details, which should be taken into
+account.
+
+EVP provides two kinds of API for key exchange:
+
+1. EVP_PKEY_encrypt/EVP_PKEY_decrypt functions, intended to use with
+       RSA-like public key encryption algorithms
+
+2. EVP_PKEY_derive, intended to use with Diffie-Hellman-like shared key
+computing algorithms.
+
+Although VKO R 34.10 algorithms, described in the RFC 4357 are
+definitely second case, engine provides BOTH API for GOST R 34.10 keys.
+
+EVP_PKEY_derive just invokes appropriate VKO algorithm and computes
+256 bit shared key. VKO R 34.10-2001 requires 64 bits of random user key
+material (UKM). This UKM should be transmitted to other party, so it is
+not generated inside derive function.
+
+It should be set by EVP_PKEY_CTX_ctrl function using
+EVP_PKEY_CTRL_SET_IV command after call of EVP_PKEY_derive_init, but
+before EVP_PKEY_derive.
+       unsigned char ukm[8];
+       RAND_bytes(ukm,8);
+   EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_DERIVE, 8, ukm)
+
+EVP_PKEY_encrypt encrypts provided session key with VKO shared key and
+packs it into GOST key transport structure, described in the RFC 4490.
+
+It typically uses ephemeral key pair to compute shared key and packs its
+public part along with encrypted key. So, for most cases use of 
+EVP_PKEY_encrypt/EVP_PKEY_decrypt with GOST keys is almost same as with
+RSA.
+
+However, if peerkey field in the EVP_PKEY_CTX structure is set (using
+EVP_PKEY_derive_set_peerkey function) to EVP_PKEY structure which has private
+key and uses same parameters as the public key from which this EVP_PKEY_CTX is
+created, EVP_PKEY_encrypt will use this private key to compute shared key and
+set ephemeral key in the GOST_key_transport structure to NULL. In this case
+pkey and peerkey fields in the EVP_PKEY_CTX are used upside-down.
+
+If EVP_PKEY_decrypt encounters GOST_key_transport structure with NULL
+public key field, it tries to use peerkey field from the context to
+compute shared key. In this case peerkey field should really contain
+peer public key.
+
+Encrypt operation supports EVP_PKEY_CTRL_SET_IV operation as well.
+It can be used when some specific restriction on UKM are imposed by
+higher level protocol. For instance, description of GOST ciphersuites
+requires UKM to be derived from shared secret. 
+
+If UKM is not set by this control command, encrypt operation would
+generate random UKM.
+
+
+This sources include implementation of GOST 28147-89 and GOST R 34.11-94
+which are completely indepentent from OpenSSL and can be used separately
+(files gost89.c, gost89.h, gosthash.c, gosthash.h) Utility gostsum (file
+gostsum.c) is provided as example of such separate usage. This is
+program, simular to md5sum and sha1sum utilities, but calculates GOST R
+34.11-94 hash.
+
+Makefile doesn't include rule for compiling gostsum.
+Use command
+
+$(CC) -o gostsum gostsum.c gost89.c gosthash.c
+where $(CC) is name of your C compiler.
+
+Implementations of GOST R 34.10-xx, including VKO algorithms heavily
+depends on OpenSSL BIGNUM and Elliptic Curve libraries.
+
+
diff --git a/deps/openssl/openssl/engines/ccgost/e_gost_err.c b/deps/openssl/openssl/engines/ccgost/e_gost_err.c
new file mode 100644 (file)
index 0000000..9a79a37
--- /dev/null
@@ -0,0 +1,212 @@
+/* e_gost_err.c */
+/* ====================================================================
+ * Copyright (c) 1999-2009 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    openssl-core@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+/* NOTE: this file was auto generated by the mkerr.pl script: any changes
+ * made to it will be overwritten when the script next updates this file,
+ * only reason strings will be preserved.
+ */
+
+#include <stdio.h>
+#include <openssl/err.h>
+#include "e_gost_err.h"
+
+/* BEGIN ERROR CODES */
+#ifndef OPENSSL_NO_ERR
+
+#define ERR_FUNC(func) ERR_PACK(0,func,0)
+#define ERR_REASON(reason) ERR_PACK(0,0,reason)
+
+static ERR_STRING_DATA GOST_str_functs[]=
+       {
+{ERR_FUNC(GOST_F_DECODE_GOST_ALGOR_PARAMS),    "DECODE_GOST_ALGOR_PARAMS"},
+{ERR_FUNC(GOST_F_ENCODE_GOST_ALGOR_PARAMS),    "ENCODE_GOST_ALGOR_PARAMS"},
+{ERR_FUNC(GOST_F_FILL_GOST2001_PARAMS),        "FILL_GOST2001_PARAMS"},
+{ERR_FUNC(GOST_F_FILL_GOST94_PARAMS),  "FILL_GOST94_PARAMS"},
+{ERR_FUNC(GOST_F_GET_ENCRYPTION_PARAMS),       "GET_ENCRYPTION_PARAMS"},
+{ERR_FUNC(GOST_F_GOST2001_COMPUTE_PUBLIC),     "GOST2001_COMPUTE_PUBLIC"},
+{ERR_FUNC(GOST_F_GOST2001_DO_SIGN),    "GOST2001_DO_SIGN"},
+{ERR_FUNC(GOST_F_GOST2001_DO_VERIFY),  "GOST2001_DO_VERIFY"},
+{ERR_FUNC(GOST_F_GOST2001_KEYGEN),     "GOST2001_KEYGEN"},
+{ERR_FUNC(GOST_F_GOST89_GET_ASN1_PARAMETERS),  "GOST89_GET_ASN1_PARAMETERS"},
+{ERR_FUNC(GOST_F_GOST89_SET_ASN1_PARAMETERS),  "GOST89_SET_ASN1_PARAMETERS"},
+{ERR_FUNC(GOST_F_GOST94_COMPUTE_PUBLIC),       "GOST94_COMPUTE_PUBLIC"},
+{ERR_FUNC(GOST_F_GOST_CIPHER_CTL),     "GOST_CIPHER_CTL"},
+{ERR_FUNC(GOST_F_GOST_DO_SIGN),        "GOST_DO_SIGN"},
+{ERR_FUNC(GOST_F_GOST_DO_VERIFY),      "GOST_DO_VERIFY"},
+{ERR_FUNC(GOST_F_GOST_IMIT_CTRL),      "GOST_IMIT_CTRL"},
+{ERR_FUNC(GOST_F_GOST_IMIT_FINAL),     "GOST_IMIT_FINAL"},
+{ERR_FUNC(GOST_F_GOST_IMIT_UPDATE),    "GOST_IMIT_UPDATE"},
+{ERR_FUNC(GOST_F_PARAM_COPY_GOST01),   "PARAM_COPY_GOST01"},
+{ERR_FUNC(GOST_F_PARAM_COPY_GOST94),   "PARAM_COPY_GOST94"},
+{ERR_FUNC(GOST_F_PKEY_GOST01CP_DECRYPT),       "PKEY_GOST01CP_DECRYPT"},
+{ERR_FUNC(GOST_F_PKEY_GOST01CP_ENCRYPT),       "PKEY_GOST01CP_ENCRYPT"},
+{ERR_FUNC(GOST_F_PKEY_GOST01CP_KEYGEN),        "PKEY_GOST01CP_KEYGEN"},
+{ERR_FUNC(GOST_F_PKEY_GOST01_PARAMGEN),        "PKEY_GOST01_PARAMGEN"},
+{ERR_FUNC(GOST_F_PKEY_GOST2001_DERIVE),        "PKEY_GOST2001_DERIVE"},
+{ERR_FUNC(GOST_F_PKEY_GOST94CP_DECRYPT),       "PKEY_GOST94CP_DECRYPT"},
+{ERR_FUNC(GOST_F_PKEY_GOST94CP_ENCRYPT),       "PKEY_GOST94CP_ENCRYPT"},
+{ERR_FUNC(GOST_F_PKEY_GOST94CP_KEYGEN),        "PKEY_GOST94CP_KEYGEN"},
+{ERR_FUNC(GOST_F_PKEY_GOST94_PARAMGEN),        "PKEY_GOST94_PARAMGEN"},
+{ERR_FUNC(GOST_F_PKEY_GOST_CTRL),      "PKEY_GOST_CTRL"},
+{ERR_FUNC(GOST_F_PKEY_GOST_CTRL01_STR),        "PKEY_GOST_CTRL01_STR"},
+{ERR_FUNC(GOST_F_PKEY_GOST_CTRL94_STR),        "PKEY_GOST_CTRL94_STR"},
+{ERR_FUNC(GOST_F_PKEY_GOST_MAC_CTRL),  "PKEY_GOST_MAC_CTRL"},
+{ERR_FUNC(GOST_F_PKEY_GOST_MAC_CTRL_STR),      "PKEY_GOST_MAC_CTRL_STR"},
+{ERR_FUNC(GOST_F_PKEY_GOST_MAC_KEYGEN),        "PKEY_GOST_MAC_KEYGEN"},
+{ERR_FUNC(GOST_F_PRINT_GOST_01),       "PRINT_GOST_01"},
+{ERR_FUNC(GOST_F_PRIV_DECODE_GOST),    "PRIV_DECODE_GOST"},
+{ERR_FUNC(GOST_F_PUB_DECODE_GOST01),   "PUB_DECODE_GOST01"},
+{ERR_FUNC(GOST_F_PUB_DECODE_GOST94),   "PUB_DECODE_GOST94"},
+{ERR_FUNC(GOST_F_PUB_ENCODE_GOST01),   "PUB_ENCODE_GOST01"},
+{ERR_FUNC(GOST_F_UNPACK_CC_SIGNATURE), "UNPACK_CC_SIGNATURE"},
+{ERR_FUNC(GOST_F_UNPACK_CP_SIGNATURE), "UNPACK_CP_SIGNATURE"},
+{0,NULL}
+       };
+
+static ERR_STRING_DATA GOST_str_reasons[]=
+       {
+{ERR_REASON(GOST_R_BAD_KEY_PARAMETERS_FORMAT),"bad key parameters format"},
+{ERR_REASON(GOST_R_BAD_PKEY_PARAMETERS_FORMAT),"bad pkey parameters format"},
+{ERR_REASON(GOST_R_CANNOT_PACK_EPHEMERAL_KEY),"cannot pack ephemeral key"},
+{ERR_REASON(GOST_R_CTRL_CALL_FAILED)     ,"ctrl call failed"},
+{ERR_REASON(GOST_R_ERROR_COMPUTING_SHARED_KEY),"error computing shared key"},
+{ERR_REASON(GOST_R_ERROR_PACKING_KEY_TRANSPORT_INFO),"error packing key transport info"},
+{ERR_REASON(GOST_R_ERROR_PARSING_KEY_TRANSPORT_INFO),"error parsing key transport info"},
+{ERR_REASON(GOST_R_INCOMPATIBLE_ALGORITHMS),"incompatible algorithms"},
+{ERR_REASON(GOST_R_INCOMPATIBLE_PEER_KEY),"incompatible peer key"},
+{ERR_REASON(GOST_R_INVALID_CIPHER_PARAMS),"invalid cipher params"},
+{ERR_REASON(GOST_R_INVALID_CIPHER_PARAM_OID),"invalid cipher param oid"},
+{ERR_REASON(GOST_R_INVALID_DIGEST_TYPE)  ,"invalid digest type"},
+{ERR_REASON(GOST_R_INVALID_GOST94_PARMSET),"invalid gost94 parmset"},
+{ERR_REASON(GOST_R_INVALID_IV_LENGTH)    ,"invalid iv length"},
+{ERR_REASON(GOST_R_INVALID_MAC_KEY_LENGTH),"invalid mac key length"},
+{ERR_REASON(GOST_R_INVALID_PARAMSET)     ,"invalid paramset"},
+{ERR_REASON(GOST_R_KEY_IS_NOT_INITALIZED),"key is not initalized"},
+{ERR_REASON(GOST_R_KEY_IS_NOT_INITIALIZED),"key is not initialized"},
+{ERR_REASON(GOST_R_KEY_PARAMETERS_MISSING),"key parameters missing"},
+{ERR_REASON(GOST_R_MAC_KEY_NOT_SET)      ,"mac key not set"},
+{ERR_REASON(GOST_R_MALLOC_FAILURE)       ,"malloc failure"},
+{ERR_REASON(GOST_R_NO_MEMORY)            ,"no memory"},
+{ERR_REASON(GOST_R_NO_PARAMETERS_SET)    ,"no parameters set"},
+{ERR_REASON(GOST_R_NO_PEER_KEY)          ,"no peer key"},
+{ERR_REASON(GOST_R_NO_PRIVATE_PART_OF_NON_EPHEMERAL_KEYPAIR),"no private part of non ephemeral keypair"},
+{ERR_REASON(GOST_R_PUBLIC_KEY_UNDEFINED) ,"public key undefined"},
+{ERR_REASON(GOST_R_RANDOM_GENERATOR_ERROR),"random generator error"},
+{ERR_REASON(GOST_R_RANDOM_GENERATOR_FAILURE),"random generator failure"},
+{ERR_REASON(GOST_R_RANDOM_NUMBER_GENERATOR_FAILED),"random number generator failed"},
+{ERR_REASON(GOST_R_SIGNATURE_MISMATCH)   ,"signature mismatch"},
+{ERR_REASON(GOST_R_SIGNATURE_PARTS_GREATER_THAN_Q),"signature parts greater than q"},
+{ERR_REASON(GOST_R_UKM_NOT_SET)          ,"ukm not set"},
+{ERR_REASON(GOST_R_UNSUPPORTED_CIPHER_CTL_COMMAND),"unsupported cipher ctl command"},
+{ERR_REASON(GOST_R_UNSUPPORTED_PARAMETER_SET),"unsupported parameter set"},
+{0,NULL}
+       };
+
+#endif
+
+#ifdef GOST_LIB_NAME
+static ERR_STRING_DATA GOST_lib_name[]=
+        {
+{0     ,GOST_LIB_NAME},
+{0,NULL}
+       };
+#endif
+
+
+static int GOST_lib_error_code=0;
+static int GOST_error_init=1;
+
+void ERR_load_GOST_strings(void)
+       {
+       if (GOST_lib_error_code == 0)
+               GOST_lib_error_code=ERR_get_next_error_library();
+
+       if (GOST_error_init)
+               {
+               GOST_error_init=0;
+#ifndef OPENSSL_NO_ERR
+               ERR_load_strings(GOST_lib_error_code,GOST_str_functs);
+               ERR_load_strings(GOST_lib_error_code,GOST_str_reasons);
+#endif
+
+#ifdef GOST_LIB_NAME
+               GOST_lib_name->error = ERR_PACK(GOST_lib_error_code,0,0);
+               ERR_load_strings(0,GOST_lib_name);
+#endif
+               }
+       }
+
+void ERR_unload_GOST_strings(void)
+       {
+       if (GOST_error_init == 0)
+               {
+#ifndef OPENSSL_NO_ERR
+               ERR_unload_strings(GOST_lib_error_code,GOST_str_functs);
+               ERR_unload_strings(GOST_lib_error_code,GOST_str_reasons);
+#endif
+
+#ifdef GOST_LIB_NAME
+               ERR_unload_strings(0,GOST_lib_name);
+#endif
+               GOST_error_init=1;
+               }
+       }
+
+void ERR_GOST_error(int function, int reason, char *file, int line)
+       {
+       if (GOST_lib_error_code == 0)
+               GOST_lib_error_code=ERR_get_next_error_library();
+       ERR_PUT_error(GOST_lib_error_code,function,reason,file,line);
+       }
diff --git a/deps/openssl/openssl/engines/ccgost/e_gost_err.h b/deps/openssl/openssl/engines/ccgost/e_gost_err.h
new file mode 100644 (file)
index 0000000..6dc5000
--- /dev/null
@@ -0,0 +1,156 @@
+/* ====================================================================
+ * Copyright (c) 2001-2005 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    openssl-core@openssl.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#ifndef HEADER_GOST_ERR_H
+#define HEADER_GOST_ERR_H
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+/* BEGIN ERROR CODES */
+/* The following lines are auto generated by the script mkerr.pl. Any changes
+ * made after this point may be overwritten when the script is next run.
+ */
+void ERR_load_GOST_strings(void);
+void ERR_unload_GOST_strings(void);
+void ERR_GOST_error(int function, int reason, char *file, int line);
+#define GOSTerr(f,r) ERR_GOST_error((f),(r),__FILE__,__LINE__)
+
+/* Error codes for the GOST functions. */
+
+/* Function codes. */
+#define GOST_F_DECODE_GOST_ALGOR_PARAMS                         99
+#define GOST_F_ENCODE_GOST_ALGOR_PARAMS                         100
+#define GOST_F_FILL_GOST2001_PARAMS                     101
+#define GOST_F_FILL_GOST94_PARAMS                       102
+#define GOST_F_GET_ENCRYPTION_PARAMS                    103
+#define GOST_F_GOST2001_COMPUTE_PUBLIC                  104
+#define GOST_F_GOST2001_DO_SIGN                                 105
+#define GOST_F_GOST2001_DO_VERIFY                       106
+#define GOST_F_GOST2001_KEYGEN                          107
+#define GOST_F_GOST89_GET_ASN1_PARAMETERS               108
+#define GOST_F_GOST89_SET_ASN1_PARAMETERS               109
+#define GOST_F_GOST94_COMPUTE_PUBLIC                    110
+#define GOST_F_GOST_CIPHER_CTL                          111
+#define GOST_F_GOST_DO_SIGN                             112
+#define GOST_F_GOST_DO_VERIFY                           113
+#define GOST_F_GOST_IMIT_CTRL                           114
+#define GOST_F_GOST_IMIT_FINAL                          140
+#define GOST_F_GOST_IMIT_UPDATE                                 115
+#define GOST_F_PARAM_COPY_GOST01                        116
+#define GOST_F_PARAM_COPY_GOST94                        117
+#define GOST_F_PKEY_GOST01CP_DECRYPT                    118
+#define GOST_F_PKEY_GOST01CP_ENCRYPT                    119
+#define GOST_F_PKEY_GOST01CP_KEYGEN                     120
+#define GOST_F_PKEY_GOST01_PARAMGEN                     138
+#define GOST_F_PKEY_GOST2001_DERIVE                     121
+#define GOST_F_PKEY_GOST94CP_DECRYPT                    122
+#define GOST_F_PKEY_GOST94CP_ENCRYPT                    123
+#define GOST_F_PKEY_GOST94CP_KEYGEN                     124
+#define GOST_F_PKEY_GOST94_PARAMGEN                     139
+#define GOST_F_PKEY_GOST_CTRL                           125
+#define GOST_F_PKEY_GOST_CTRL01_STR                     126
+#define GOST_F_PKEY_GOST_CTRL94_STR                     127
+#define GOST_F_PKEY_GOST_MAC_CTRL                       128
+#define GOST_F_PKEY_GOST_MAC_CTRL_STR                   129
+#define GOST_F_PKEY_GOST_MAC_KEYGEN                     130
+#define GOST_F_PRINT_GOST_01                            131
+#define GOST_F_PRIV_DECODE_GOST                                 132
+#define GOST_F_PUB_DECODE_GOST01                        133
+#define GOST_F_PUB_DECODE_GOST94                        134
+#define GOST_F_PUB_ENCODE_GOST01                        135
+#define GOST_F_UNPACK_CC_SIGNATURE                      136
+#define GOST_F_UNPACK_CP_SIGNATURE                      137
+
+/* Reason codes. */
+#define GOST_R_BAD_KEY_PARAMETERS_FORMAT                99
+#define GOST_R_BAD_PKEY_PARAMETERS_FORMAT               100
+#define GOST_R_CANNOT_PACK_EPHEMERAL_KEY                101
+#define GOST_R_CTRL_CALL_FAILED                                 132
+#define GOST_R_ERROR_COMPUTING_SHARED_KEY               102
+#define GOST_R_ERROR_PACKING_KEY_TRANSPORT_INFO                 103
+#define GOST_R_ERROR_PARSING_KEY_TRANSPORT_INFO                 104
+#define GOST_R_INCOMPATIBLE_ALGORITHMS                  105
+#define GOST_R_INCOMPATIBLE_PEER_KEY                    131
+#define GOST_R_INVALID_CIPHER_PARAMS                    106
+#define GOST_R_INVALID_CIPHER_PARAM_OID                         107
+#define GOST_R_INVALID_DIGEST_TYPE                      108
+#define GOST_R_INVALID_GOST94_PARMSET                   109
+#define GOST_R_INVALID_IV_LENGTH                        110
+#define GOST_R_INVALID_MAC_KEY_LENGTH                   111
+#define GOST_R_INVALID_PARAMSET                                 112
+#define GOST_R_KEY_IS_NOT_INITALIZED                    113
+#define GOST_R_KEY_IS_NOT_INITIALIZED                   114
+#define GOST_R_KEY_PARAMETERS_MISSING                   115
+#define GOST_R_MAC_KEY_NOT_SET                          116
+#define GOST_R_MALLOC_FAILURE                           117
+#define GOST_R_NO_MEMORY                                118
+#define GOST_R_NO_PARAMETERS_SET                        119
+#define GOST_R_NO_PEER_KEY                              120
+#define GOST_R_NO_PRIVATE_PART_OF_NON_EPHEMERAL_KEYPAIR         121
+#define GOST_R_PUBLIC_KEY_UNDEFINED                     122
+#define GOST_R_RANDOM_GENERATOR_ERROR                   123
+#define GOST_R_RANDOM_GENERATOR_FAILURE                         124
+#define GOST_R_RANDOM_NUMBER_GENERATOR_FAILED           125
+#define GOST_R_SIGNATURE_MISMATCH                       126
+#define GOST_R_SIGNATURE_PARTS_GREATER_THAN_Q           127
+#define GOST_R_UKM_NOT_SET                              128
+#define GOST_R_UNSUPPORTED_CIPHER_CTL_COMMAND           129
+#define GOST_R_UNSUPPORTED_PARAMETER_SET                130
+
+#ifdef  __cplusplus
+}
+#endif
+#endif
similarity index 80%
rename from deps/openssl/openssl/fips/fips_locl.h
rename to deps/openssl/openssl/engines/ccgost/e_gost_err.proto
index b3ea289..c57bd1b 100644 (file)
@@ -1,5 +1,5 @@
 /* ====================================================================
- * Copyright (c) 2003 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 2001-2005 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
  *
  */
 
-#ifdef OPENSSL_FIPS
-
-#ifdef  __cplusplus
-extern "C" {
-#endif
-
-void fips_w_lock(void);
-void fips_w_unlock(void);
-void fips_r_lock(void);
-void fips_r_unlock(void);
-int fips_is_started(void);
-void fips_set_started(void);
-int fips_is_owning_thread(void);
-int fips_set_owning_thread(void);
-void fips_set_selftest_fail(void);
-int fips_clear_owning_thread(void);
-unsigned char *fips_signature_witness(void);
-int fips_check_rsa(RSA *rsa);
-
-#define FIPS_MAX_CIPHER_TEST_SIZE      16
+#ifndef HEADER_GOST_ERR_H
+#define HEADER_GOST_ERR_H
 
-#ifdef  __cplusplus
-}
-#endif
+#define GOST_LIB_NAME "GOST engine"
+#ifdef __cplusplus
+ extern "C" {
 #endif
diff --git a/deps/openssl/openssl/engines/ccgost/gost.ec b/deps/openssl/openssl/engines/ccgost/gost.ec
new file mode 100644 (file)
index 0000000..6c2c85e
--- /dev/null
@@ -0,0 +1,5 @@
+L GOST                         e_gost_err.h                    e_gost_err.c
+L NONE                 asymm.h                         NONE
+L NONE                 md.h                            NONE
+L NONE                 crypt.h                         NONE
+L NONE                 gostkeyx.h                      NONE
diff --git a/deps/openssl/openssl/engines/ccgost/gost2001.c b/deps/openssl/openssl/engines/ccgost/gost2001.c
new file mode 100644 (file)
index 0000000..dacd82d
--- /dev/null
@@ -0,0 +1,343 @@
+/**********************************************************************
+ *                          gost2001.c                                *
+ *             Copyright (c) 2005-2006 Cryptocom LTD                  *
+ *         This file is distributed under the same license as OpenSSL *
+ *                                                                    *
+ *          Implementation of GOST R 34.10-2001                                  *
+ *          Requires OpenSSL 0.9.9 for compilation                    *
+ **********************************************************************/
+#include "gost_lcl.h"
+#include "gost_params.h"
+#include <string.h>
+#include <openssl/rand.h>
+#include <openssl/ecdsa.h>
+#include <openssl/err.h>
+#include "e_gost_err.h"
+#ifdef DEBUG_SIGN
+extern 
+void dump_signature(const char *message,const unsigned char *buffer,size_t len);
+void dump_dsa_sig(const char *message, DSA_SIG *sig);
+#else
+
+#define dump_signature(a,b,c)
+#define dump_dsa_sig(a,b)
+#endif
+
+/*
+ * Fills EC_KEY structure hidden in the app_data field of DSA structure
+ * with parameter information, extracted from parameter array in
+ * params.c file.
+ *
+ * Also fils DSA->q field with copy of EC_GROUP order field to make
+ * DSA_size function work
+ */ 
+int fill_GOST2001_params(EC_KEY *eckey, int nid)
+       {
+       R3410_2001_params *params = R3410_2001_paramset;
+       EC_GROUP *grp=NULL;
+       BIGNUM *p=NULL,*q=NULL,*a=NULL,*b=NULL,*x=NULL,*y=NULL;
+       EC_POINT *P=NULL;
+       BN_CTX *ctx=BN_CTX_new();
+       int ok=0;
+       
+       BN_CTX_start(ctx);
+       p=BN_CTX_get(ctx);
+       a=BN_CTX_get(ctx);
+       b=BN_CTX_get(ctx);
+       x=BN_CTX_get(ctx);
+       y=BN_CTX_get(ctx);
+       q=BN_CTX_get(ctx);
+       while (params->nid!=NID_undef && params->nid != nid) params++;
+       if (params->nid == NID_undef)
+               {
+               GOSTerr(GOST_F_FILL_GOST2001_PARAMS,GOST_R_UNSUPPORTED_PARAMETER_SET);
+               goto err;
+               }       
+       BN_hex2bn(&p,params->p);
+       BN_hex2bn(&a,params->a);
+       BN_hex2bn(&b,params->b);
+       
+       grp = EC_GROUP_new_curve_GFp(p,a,b,ctx);
+
+       P = EC_POINT_new(grp);
+
+       BN_hex2bn(&x,params->x);
+       BN_hex2bn(&y,params->y);
+       EC_POINT_set_affine_coordinates_GFp(grp,P,x,y,ctx);
+       BN_hex2bn(&q,params->q);
+#ifdef DEBUG_KEYS
+       fprintf(stderr,"Set params index %d oid %s\nq=",
+               (params-R3410_2001_paramset),OBJ_nid2sn(params->nid));
+       BN_print_fp(stderr,q);
+       fprintf(stderr,"\n");
+#endif 
+
+       EC_GROUP_set_generator(grp,P,q,NULL);
+       EC_GROUP_set_curve_name(grp,params->nid);
+
+       EC_KEY_set_group(eckey,grp);
+       ok=1;
+       err:
+       EC_POINT_free(P);
+       EC_GROUP_free(grp);
+       BN_CTX_end(ctx);
+       BN_CTX_free(ctx);
+       return ok;
+       }       
+
+
+/*
+ * Computes gost2001 signature as DSA_SIG structure 
+ *
+ *
+ */ 
+DSA_SIG *gost2001_do_sign(const unsigned char *dgst,int dlen, EC_KEY *eckey)
+       {
+       DSA_SIG *newsig = NULL;
+       BIGNUM *md = hashsum2bn(dgst);
+       BIGNUM *order = NULL;
+       const EC_GROUP *group;
+       const BIGNUM *priv_key;
+       BIGNUM *r=NULL,*s=NULL,*X=NULL,*tmp=NULL,*tmp2=NULL, *k=NULL,*e=NULL;
+       EC_POINT *C=NULL;
+       BN_CTX *ctx = BN_CTX_new();     
+       BN_CTX_start(ctx);
+       OPENSSL_assert(dlen==32);
+       newsig=DSA_SIG_new();
+       if (!newsig) 
+               {
+               GOSTerr(GOST_F_GOST2001_DO_SIGN,GOST_R_NO_MEMORY);
+               goto err;
+               }       
+       group = EC_KEY_get0_group(eckey);
+       order=BN_CTX_get(ctx);
+       EC_GROUP_get_order(group,order,ctx);
+       priv_key = EC_KEY_get0_private_key(eckey);
+       e = BN_CTX_get(ctx);
+       BN_mod(e,md,order,ctx);
+#ifdef DEBUG_SIGN
+       fprintf(stderr,"digest as bignum=");
+       BN_print_fp(stderr,md);
+       fprintf(stderr,"\ndigest mod q=");
+       BN_print_fp(stderr,e);
+       fprintf(stderr,"\n");
+#endif         
+       if (BN_is_zero(e))
+               {
+               BN_one(e);
+               }   
+       k =BN_CTX_get(ctx);
+       C=EC_POINT_new(group);
+       do 
+               {
+               do 
+                       {
+                       if (!BN_rand_range(k,order)) 
+                               {
+                               GOSTerr(GOST_F_GOST2001_DO_SIGN,GOST_R_RANDOM_NUMBER_GENERATOR_FAILED);
+                               DSA_SIG_free(newsig);
+                               newsig = NULL;
+                               goto err;
+                               }       
+                       if (!EC_POINT_mul(group,C,k,NULL,NULL,ctx))
+                               {
+                               GOSTerr(GOST_F_GOST2001_DO_SIGN,ERR_R_EC_LIB);
+                               DSA_SIG_free(newsig);
+                               newsig = NULL;
+                               goto err;
+                               }       
+                       if (!X) X=BN_CTX_get(ctx);
+                       if (!EC_POINT_get_affine_coordinates_GFp(group,C,X,NULL,ctx))
+                               {
+                               GOSTerr(GOST_F_GOST2001_DO_SIGN,ERR_R_EC_LIB);
+                               DSA_SIG_free(newsig);
+                               newsig = NULL;
+                               goto err;
+                               }       
+                       if (!r) r=BN_CTX_get(ctx);
+                       BN_nnmod(r,X,order,ctx);
+                       }
+               while (BN_is_zero(r));
+               /* s =  (r*priv_key+k*e) mod order */
+               if (!tmp) tmp = BN_CTX_get(ctx);
+               BN_mod_mul(tmp,priv_key,r,order,ctx);
+               if (!tmp2) tmp2 = BN_CTX_get(ctx);
+               BN_mod_mul(tmp2,k,e,order,ctx);
+               if (!s) s=BN_CTX_get(ctx);
+               BN_mod_add(s,tmp,tmp2,order,ctx);
+               }
+       while (BN_is_zero(s));  
+
+       newsig->s=BN_dup(s);
+       newsig->r=BN_dup(r);
+       err:                    
+       BN_CTX_end(ctx);
+       BN_CTX_free(ctx);
+       EC_POINT_free(C);
+       BN_free(md);
+       return newsig;
+       }
+/*
+ * Verifies gost 2001 signature
+ *
+ */ 
+int gost2001_do_verify(const unsigned char *dgst,int dgst_len,
+       DSA_SIG *sig, EC_KEY *ec)
+       {
+       BN_CTX *ctx=BN_CTX_new();
+       const EC_GROUP *group = EC_KEY_get0_group(ec);
+       BIGNUM *order;
+       BIGNUM *md = NULL,*e=NULL,*R=NULL,*v=NULL,*z1=NULL,*z2=NULL;
+       BIGNUM *X=NULL,*tmp=NULL;
+       EC_POINT *C = NULL;
+       const EC_POINT *pub_key=NULL;
+       int ok=0;
+
+       BN_CTX_start(ctx);
+       order = BN_CTX_get(ctx);
+       e = BN_CTX_get(ctx);
+       z1 = BN_CTX_get(ctx);
+       z2 = BN_CTX_get(ctx);
+       tmp = BN_CTX_get(ctx);
+       X= BN_CTX_get(ctx);     
+       R=BN_CTX_get(ctx);
+       v=BN_CTX_get(ctx);
+       
+       EC_GROUP_get_order(group,order,ctx);
+       pub_key = EC_KEY_get0_public_key(ec);
+       if (BN_is_zero(sig->s) || BN_is_zero(sig->r) ||
+               (BN_cmp(sig->s,order)>=1) || (BN_cmp(sig->r,order)>=1)) 
+               {
+               GOSTerr(GOST_F_GOST2001_DO_VERIFY,GOST_R_SIGNATURE_PARTS_GREATER_THAN_Q);
+               goto err;
+
+               }
+       md = hashsum2bn(dgst);
+
+       BN_mod(e,md,order,ctx);
+#ifdef DEBUG_SIGN
+       fprintf(stderr,"digest as bignum: ");
+       BN_print_fp(stderr,md);
+       fprintf(stderr,"\ndigest mod q: ");
+       BN_print_fp(stderr,e);
+#endif 
+       if (BN_is_zero(e)) BN_one(e);
+       v=BN_mod_inverse(v,e,order,ctx);
+       BN_mod_mul(z1,sig->s,v,order,ctx);
+       BN_sub(tmp,order,sig->r);
+       BN_mod_mul(z2,tmp,v,order,ctx);
+#ifdef DEBUG_SIGN
+       fprintf(stderr,"\nInverted digest value: ");
+       BN_print_fp(stderr,v);
+       fprintf(stderr,"\nz1: ");
+       BN_print_fp(stderr,z1);
+       fprintf(stderr,"\nz2: ");
+       BN_print_fp(stderr,z2);
+#endif 
+       C = EC_POINT_new(group);
+       if (!EC_POINT_mul(group,C,z1,pub_key,z2,ctx)) 
+               {       
+               GOSTerr(GOST_F_GOST2001_DO_VERIFY,ERR_R_EC_LIB);
+               goto err;
+               }       
+       if (!EC_POINT_get_affine_coordinates_GFp(group,C,X,NULL,ctx)) 
+               {
+               GOSTerr(GOST_F_GOST2001_DO_VERIFY,ERR_R_EC_LIB);
+               goto err;
+               }
+       BN_mod(R,X,order,ctx);
+#ifdef DEBUG_SIGN
+       fprintf(stderr,"\nX=");
+       BN_print_fp(stderr,X);
+       fprintf(stderr,"\nX mod q=");
+       BN_print_fp(stderr,R);
+       fprintf(stderr,"\n");
+#endif 
+       if (BN_cmp(R,sig->r)!=0)
+               {
+               GOSTerr(GOST_F_GOST2001_DO_VERIFY,GOST_R_SIGNATURE_MISMATCH);
+               }
+       else
+               {
+               ok = 1;
+               }
+       err:
+       EC_POINT_free(C);
+       BN_CTX_end(ctx);
+       BN_CTX_free(ctx);
+       BN_free(md);
+       return ok;
+       }
+/*
+ * Computes GOST R 34.10-2001 public key
+ *
+ *
+ */ 
+int gost2001_compute_public(EC_KEY *ec) 
+       {
+       const EC_GROUP *group = EC_KEY_get0_group(ec);
+       EC_POINT *pub_key=NULL;
+       const BIGNUM *priv_key=NULL;
+       BN_CTX *ctx=NULL;
+       int ok=0;
+
+       if (!group)
+               {
+               GOSTerr(GOST_F_GOST2001_COMPUTE_PUBLIC,GOST_R_KEY_IS_NOT_INITIALIZED);
+               return 0;
+               }       
+       ctx=BN_CTX_new();
+       BN_CTX_start(ctx);
+       if (!(priv_key=EC_KEY_get0_private_key(ec))) 
+               {
+               GOSTerr(GOST_F_GOST2001_COMPUTE_PUBLIC,ERR_R_EC_LIB);
+               goto err;
+               }       
+
+       pub_key = EC_POINT_new(group);
+       if (!EC_POINT_mul(group,pub_key,priv_key,NULL,NULL,ctx)) 
+               {
+               GOSTerr(GOST_F_GOST2001_COMPUTE_PUBLIC,ERR_R_EC_LIB);
+               goto err;
+               }       
+       if (!EC_KEY_set_public_key(ec,pub_key))
+               {
+               GOSTerr(GOST_F_GOST2001_COMPUTE_PUBLIC,ERR_R_EC_LIB);
+               goto err;
+               }       
+       ok = 256;
+       err:
+       BN_CTX_end(ctx);
+       EC_POINT_free(pub_key);
+       BN_CTX_free(ctx);
+       return ok;
+       }
+/*
+ * 
+ * Generates GOST R 34.10-2001 keypair
+ *
+ *
+ */ 
+int gost2001_keygen(EC_KEY *ec)
+       {
+       BIGNUM *order = BN_new(),*d=BN_new();
+       const EC_GROUP *group = EC_KEY_get0_group(ec);
+       EC_GROUP_get_order(group,order,NULL);
+       
+       do 
+               {
+               if (!BN_rand_range(d,order)) 
+                       {
+                       GOSTerr(GOST_F_GOST2001_KEYGEN,GOST_R_RANDOM_NUMBER_GENERATOR_FAILED);
+                       BN_free(d);
+                       BN_free(order);
+                       return 0;
+                       }       
+               }
+       while (BN_is_zero(d));
+       EC_KEY_set_private_key(ec,d);
+       BN_free(d);
+       BN_free(order);
+       return gost2001_compute_public(ec);
+       }
+
diff --git a/deps/openssl/openssl/engines/ccgost/gost2001_keyx.c b/deps/openssl/openssl/engines/ccgost/gost2001_keyx.c
new file mode 100644 (file)
index 0000000..c748102
--- /dev/null
@@ -0,0 +1,308 @@
+/**********************************************************************
+ *                          gost_keyx.c                               *
+ *             Copyright (c) 2005-2006 Cryptocom LTD                  *
+ *         This file is distributed under the same license as OpenSSL *
+ *                                                                    *
+ *   VK0 34.10-2001 key exchange and GOST R 34.10-2001                *
+ *   based PKCS7/SMIME support                                        *
+ *          Requires OpenSSL 0.9.9 for compilation                    *
+ **********************************************************************/
+#include <openssl/evp.h>
+#include <openssl/rand.h>
+#include <string.h>
+#include <openssl/objects.h>
+#include "gost89.h"
+#include "gosthash.h"
+#include "e_gost_err.h"
+#include "gost_keywrap.h"
+#include "gost_lcl.h"
+#include "gost2001_keyx.h"
+
+
+
+/* Implementation of CryptoPro VKO 34.10-2001 algorithm */
+static int VKO_compute_key(unsigned char *shared_key,size_t shared_key_size,const EC_POINT *pub_key,EC_KEY *priv_key,const unsigned char *ukm)
+       {
+       unsigned char ukm_be[8],databuf[64],hashbuf[64];
+       BIGNUM *UKM=NULL,*p=NULL,*order=NULL,*X=NULL,*Y=NULL;
+       const BIGNUM* key=EC_KEY_get0_private_key(priv_key);
+       EC_POINT *pnt=EC_POINT_new(EC_KEY_get0_group(priv_key));
+       int i;
+       gost_hash_ctx hash_ctx;
+       BN_CTX *ctx = BN_CTX_new();
+
+       for (i=0;i<8;i++)
+               {
+               ukm_be[7-i]=ukm[i];
+               }
+       BN_CTX_start(ctx);
+       UKM=getbnfrombuf(ukm_be,8);
+       p=BN_CTX_get(ctx);
+       order = BN_CTX_get(ctx);
+       X=BN_CTX_get(ctx);
+       Y=BN_CTX_get(ctx);
+       EC_GROUP_get_order(EC_KEY_get0_group(priv_key),order,ctx);
+       BN_mod_mul(p,key,UKM,order,ctx);        
+       EC_POINT_mul(EC_KEY_get0_group(priv_key),pnt,NULL,pub_key,p,ctx);
+       EC_POINT_get_affine_coordinates_GFp(EC_KEY_get0_group(priv_key),
+               pnt,X,Y,ctx);
+       /*Serialize elliptic curve point same way as we do it when saving
+        * key */
+       store_bignum(Y,databuf,32);
+       store_bignum(X,databuf+32,32);
+       /* And reverse byte order of whole buffer */
+       for (i=0;i<64;i++)
+               {
+               hashbuf[63-i]=databuf[i];
+               }
+       init_gost_hash_ctx(&hash_ctx,&GostR3411_94_CryptoProParamSet);
+       start_hash(&hash_ctx);
+       hash_block(&hash_ctx,hashbuf,64);
+       finish_hash(&hash_ctx,shared_key);
+       done_gost_hash_ctx(&hash_ctx);
+       BN_free(UKM);
+       BN_CTX_end(ctx);
+       BN_CTX_free(ctx);
+       EC_POINT_free(pnt);
+       return 32;
+       }
+
+
+/*
+ * EVP_PKEY_METHOD callback derive. Implements VKO R 34.10-2001
+ * algorithm
+ */
+int pkey_gost2001_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen)
+{
+       /* Public key of peer in the ctx field peerkey
+        * Our private key in the ctx pkey
+        * ukm is in the algorithm specific context data
+        */
+       EVP_PKEY *my_key = EVP_PKEY_CTX_get0_pkey(ctx);
+       EVP_PKEY *peer_key = EVP_PKEY_CTX_get0_peerkey(ctx);
+       struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
+       
+       if (!data->shared_ukm) {
+               GOSTerr(GOST_F_PKEY_GOST2001_DERIVE, GOST_R_UKM_NOT_SET);
+               return 0;
+       }       
+
+       if (key == NULL) {
+               *keylen = 32;
+               return 32;
+       }       
+       
+       *keylen=VKO_compute_key(key, 32, EC_KEY_get0_public_key(EVP_PKEY_get0(peer_key)),
+               (EC_KEY *)EVP_PKEY_get0(my_key),data->shared_ukm);
+       return 1;       
+}
+
+
+
+
+/*  
+ * EVP_PKEY_METHOD callback encrypt  
+ * Implementation of GOST2001 key transport, cryptocom variation 
+ */
+/* Generates ephemeral key based on pubk algorithm
+ * computes shared key using VKO and returns filled up
+ * GOST_KEY_TRANSPORT structure
+ */
+
+/*  
+ * EVP_PKEY_METHOD callback encrypt  
+ * Implementation of GOST2001 key transport, cryptopo variation 
+ */
+
+int pkey_GOST01cp_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out, size_t *out_len, const unsigned char *key,size_t key_len) 
+       {
+       GOST_KEY_TRANSPORT *gkt=NULL; 
+       EVP_PKEY *pubk = EVP_PKEY_CTX_get0_pkey(pctx);
+       struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(pctx);
+       const struct gost_cipher_info *param=get_encryption_params(NULL);
+       unsigned char ukm[8], shared_key[32], crypted_key[44];
+       int ret=0;
+       int key_is_ephemeral=1;
+       gost_ctx cctx;
+       EVP_PKEY *sec_key=EVP_PKEY_CTX_get0_peerkey(pctx);
+       if (data->shared_ukm) 
+               {
+               memcpy(ukm, data->shared_ukm,8);
+               } 
+       else if (out) 
+               {
+               
+               if (RAND_bytes(ukm,8)<=0)
+                       {
+                       GOSTerr(GOST_F_PKEY_GOST01CP_ENCRYPT,
+                               GOST_R_RANDOM_GENERATOR_FAILURE);
+                       return 0;
+                       }       
+               }       
+       /* Check for private key in the peer_key of context */  
+       if (sec_key) 
+               {
+               key_is_ephemeral=0;
+               if (!gost_get0_priv_key(sec_key)) 
+                       {
+                       GOSTerr(GOST_F_PKEY_GOST01CP_ENCRYPT,
+                       GOST_R_NO_PRIVATE_PART_OF_NON_EPHEMERAL_KEYPAIR);
+                       goto err;
+                       }       
+               } 
+       else 
+               {
+               key_is_ephemeral=1;
+               if (out) 
+                       {
+                       sec_key = EVP_PKEY_new();
+                       EVP_PKEY_assign(sec_key,EVP_PKEY_base_id(pubk),EC_KEY_new());
+                       EVP_PKEY_copy_parameters(sec_key,pubk);
+                       if (!gost2001_keygen(EVP_PKEY_get0(sec_key))) 
+                               {
+                               goto err;
+                               }       
+                       }
+               }
+       if (!get_gost_engine_param(GOST_PARAM_CRYPT_PARAMS) && param ==  gost_cipher_list)
+               {
+               param= gost_cipher_list+1;
+               }       
+    if (out) 
+               {
+               VKO_compute_key(shared_key,32,EC_KEY_get0_public_key(EVP_PKEY_get0(pubk)),EVP_PKEY_get0(sec_key),ukm);
+               gost_init(&cctx,param->sblock); 
+               keyWrapCryptoPro(&cctx,shared_key,ukm,key,crypted_key);
+               }
+       gkt = GOST_KEY_TRANSPORT_new();
+       if (!gkt)
+               {
+               goto err;
+               }       
+       if(!ASN1_OCTET_STRING_set(gkt->key_agreement_info->eph_iv,
+                       ukm,8))
+               {
+               goto err;
+               }       
+       if (!ASN1_OCTET_STRING_set(gkt->key_info->imit,crypted_key+40,4))
+               {
+               goto err;
+               }
+       if (!ASN1_OCTET_STRING_set(gkt->key_info->encrypted_key,crypted_key+8,32))
+               {
+               goto err;
+               }
+       if (key_is_ephemeral) { 
+               if (!X509_PUBKEY_set(&gkt->key_agreement_info->ephem_key,out?sec_key:pubk))
+                       {
+                       GOSTerr(GOST_F_PKEY_GOST01CP_ENCRYPT,
+                                       GOST_R_CANNOT_PACK_EPHEMERAL_KEY);
+                       goto err;
+                       }       
+       }               
+       ASN1_OBJECT_free(gkt->key_agreement_info->cipher);
+       gkt->key_agreement_info->cipher = OBJ_nid2obj(param->nid);
+       if (key_is_ephemeral && sec_key) EVP_PKEY_free(sec_key);
+       if (!key_is_ephemeral)
+               {
+               /* Set control "public key from client certificate used" */
+               if (EVP_PKEY_CTX_ctrl(pctx, -1, -1, EVP_PKEY_CTRL_PEER_KEY, 3, NULL) <= 0)
+                       {
+                       GOSTerr(GOST_F_PKEY_GOST01CP_ENCRYPT,
+                               GOST_R_CTRL_CALL_FAILED);
+                       goto err;
+                       }
+               }
+       if ((*out_len = i2d_GOST_KEY_TRANSPORT(gkt,out?&out:NULL))>0) ret =1;
+       GOST_KEY_TRANSPORT_free(gkt);
+       return ret;     
+       err:            
+       if (key_is_ephemeral && sec_key) EVP_PKEY_free(sec_key);
+       GOST_KEY_TRANSPORT_free(gkt);
+       return -1;
+       }
+/*  
+ * EVP_PKEY_METHOD callback decrypt  
+ * Implementation of GOST2001 key transport, cryptopo variation 
+ */
+int pkey_GOST01cp_decrypt(EVP_PKEY_CTX *pctx, unsigned char *key, size_t * key_len, const unsigned char *in, size_t in_len)
+       {
+       const unsigned char *p = in;
+       EVP_PKEY *priv = EVP_PKEY_CTX_get0_pkey(pctx);
+       GOST_KEY_TRANSPORT *gkt = NULL;
+       int ret=0;      
+       unsigned char wrappedKey[44];
+       unsigned char sharedKey[32];
+       gost_ctx ctx;
+       const struct gost_cipher_info *param=NULL;
+       EVP_PKEY *eph_key=NULL, *peerkey=NULL;
+
+       if (!key)
+               {
+               *key_len = 32;
+               return 1;
+               }       
+       gkt = d2i_GOST_KEY_TRANSPORT(NULL,(const unsigned char **)&p,
+               in_len);
+       if (!gkt)
+               {
+               GOSTerr(GOST_F_PKEY_GOST01CP_DECRYPT,GOST_R_ERROR_PARSING_KEY_TRANSPORT_INFO);
+               return -1;
+               }       
+
+       /* If key transport structure contains public key, use it */
+       eph_key = X509_PUBKEY_get(gkt->key_agreement_info->ephem_key);
+       if (eph_key)
+               {
+               if (EVP_PKEY_derive_set_peer(pctx, eph_key) <= 0)
+                       {
+                       GOSTerr(GOST_F_PKEY_GOST01CP_DECRYPT,
+                               GOST_R_INCOMPATIBLE_PEER_KEY);
+                       goto err;
+                       }
+               }
+       else
+               {
+               /* Set control "public key from client certificate used" */
+               if (EVP_PKEY_CTX_ctrl(pctx, -1, -1, EVP_PKEY_CTRL_PEER_KEY, 3, NULL) <= 0)
+                       {
+                       GOSTerr(GOST_F_PKEY_GOST01CP_DECRYPT,
+                               GOST_R_CTRL_CALL_FAILED);
+                       goto err;
+                       }
+               }
+       peerkey = EVP_PKEY_CTX_get0_peerkey(pctx);
+       if (!peerkey)
+               {
+               GOSTerr(GOST_F_PKEY_GOST01CP_DECRYPT,
+                       GOST_R_NO_PEER_KEY);
+               goto err;
+               }
+               
+       param = get_encryption_params(gkt->key_agreement_info->cipher);
+    if(!param){
+        goto err;
+    }
+
+       gost_init(&ctx,param->sblock);  
+       OPENSSL_assert(gkt->key_agreement_info->eph_iv->length==8);
+       memcpy(wrappedKey,gkt->key_agreement_info->eph_iv->data,8);
+       OPENSSL_assert(gkt->key_info->encrypted_key->length==32);
+       memcpy(wrappedKey+8,gkt->key_info->encrypted_key->data,32);
+       OPENSSL_assert(gkt->key_info->imit->length==4);
+       memcpy(wrappedKey+40,gkt->key_info->imit->data,4);      
+       VKO_compute_key(sharedKey,32,EC_KEY_get0_public_key(EVP_PKEY_get0(peerkey)),
+               EVP_PKEY_get0(priv),wrappedKey);
+       if (!keyUnwrapCryptoPro(&ctx,sharedKey,wrappedKey,key))
+               {
+               GOSTerr(GOST_F_PKEY_GOST01CP_DECRYPT,
+                       GOST_R_ERROR_COMPUTING_SHARED_KEY);
+               goto err;
+               }       
+                               
+       ret=1;
+err:   
+       if (eph_key) EVP_PKEY_free(eph_key);
+       if (gkt) GOST_KEY_TRANSPORT_free(gkt);
+       return ret;
+       }
diff --git a/deps/openssl/openssl/engines/ccgost/gost2001_keyx.h b/deps/openssl/openssl/engines/ccgost/gost2001_keyx.h
new file mode 100644 (file)
index 0000000..a014d9c
--- /dev/null
@@ -0,0 +1,10 @@
+GOST_KEY_TRANSPORT *
+make_rfc4490_keytransport_2001(EVP_PKEY *pubk, BIGNUM *eph_key,
+                               const unsigned char *key, size_t keylen,
+                               unsigned char *ukm, size_t ukm_len);
+
+int decrypt_rfc4490_shared_key_2001(EVP_PKEY *priv,
+                                    GOST_KEY_TRANSPORT *gkt,
+                                    unsigned char *key_buf,
+                                    int key_buf_len) ;
+
diff --git a/deps/openssl/openssl/engines/ccgost/gost89.c b/deps/openssl/openssl/engines/ccgost/gost89.c
new file mode 100644 (file)
index 0000000..7ebae0f
--- /dev/null
@@ -0,0 +1,409 @@
+/**********************************************************************
+ *                        gost89.c                                    *
+ *             Copyright (c) 2005-2006 Cryptocom LTD                  *
+ *         This file is distributed under the same license as OpenSSL *
+ *                                                                    *
+ *          Implementation of GOST 28147-89 encryption algorithm      *
+ *            No OpenSSL libraries required to compile and use        *
+ *                              this code                             *
+ **********************************************************************/ 
+#include <string.h>
+#include "gost89.h"
+/* Substitution blocks from RFC 4357 
+   
+   Note: our implementation of gost 28147-89 algorithm 
+   uses S-box matrix rotated 90 degrees counterclockwise, relative to 
+   examples given in RFC.
+  
+
+*/
+
+/* Substitution blocks from test examples for GOST R 34.11-94*/
+gost_subst_block GostR3411_94_TestParamSet = {
+       {0X1,0XF,0XD,0X0,0X5,0X7,0XA,0X4,0X9,0X2,0X3,0XE,0X6,0XB,0X8,0XC},
+       {0XD,0XB,0X4,0X1,0X3,0XF,0X5,0X9,0X0,0XA,0XE,0X7,0X6,0X8,0X2,0XC},
+       {0X4,0XB,0XA,0X0,0X7,0X2,0X1,0XD,0X3,0X6,0X8,0X5,0X9,0XC,0XF,0XE},
+       {0X6,0XC,0X7,0X1,0X5,0XF,0XD,0X8,0X4,0XA,0X9,0XE,0X0,0X3,0XB,0X2},
+       {0X7,0XD,0XA,0X1,0X0,0X8,0X9,0XF,0XE,0X4,0X6,0XC,0XB,0X2,0X5,0X3},
+       {0X5,0X8,0X1,0XD,0XA,0X3,0X4,0X2,0XE,0XF,0XC,0X7,0X6,0X0,0X9,0XB},
+       {0XE,0XB,0X4,0XC,0X6,0XD,0XF,0XA,0X2,0X3,0X8,0X1,0X0,0X7,0X5,0X9},
+       {0X4,0XA,0X9,0X2,0XD,0X8,0X0,0XE,0X6,0XB,0X1,0XC,0X7,0XF,0X5,0X3}
+       };  
+/* Substitution blocks for hash function 1.2.643.2.9.1.6.1  */
+gost_subst_block GostR3411_94_CryptoProParamSet= {
+       {0x1,0x3,0xA,0x9,0x5,0xB,0x4,0xF,0x8,0x6,0x7,0xE,0xD,0x0,0x2,0xC},
+       {0xD,0xE,0x4,0x1,0x7,0x0,0x5,0xA,0x3,0xC,0x8,0xF,0x6,0x2,0x9,0xB},
+       {0x7,0x6,0x2,0x4,0xD,0x9,0xF,0x0,0xA,0x1,0x5,0xB,0x8,0xE,0xC,0x3},
+       {0x7,0x6,0x4,0xB,0x9,0xC,0x2,0xA,0x1,0x8,0x0,0xE,0xF,0xD,0x3,0x5},
+       {0x4,0xA,0x7,0xC,0x0,0xF,0x2,0x8,0xE,0x1,0x6,0x5,0xD,0xB,0x9,0x3},
+       {0x7,0xF,0xC,0xE,0x9,0x4,0x1,0x0,0x3,0xB,0x5,0x2,0x6,0xA,0x8,0xD},
+       {0x5,0xF,0x4,0x0,0x2,0xD,0xB,0x9,0x1,0x7,0x6,0x3,0xC,0xE,0xA,0x8},
+       {0xA,0x4,0x5,0x6,0x8,0x1,0x3,0x7,0xD,0xC,0xE,0x0,0x9,0x2,0xB,0xF}
+       } ;
+
+/* Test paramset from GOST 28147 */
+gost_subst_block Gost28147_TestParamSet =
+       {
+       {0xC,0x6,0x5,0x2,0xB,0x0,0x9,0xD,0x3,0xE,0x7,0xA,0xF,0x4,0x1,0x8},
+       {0x9,0xB,0xC,0x0,0x3,0x6,0x7,0x5,0x4,0x8,0xE,0xF,0x1,0xA,0x2,0xD},
+       {0x8,0xF,0x6,0xB,0x1,0x9,0xC,0x5,0xD,0x3,0x7,0xA,0x0,0xE,0x2,0x4},
+       {0x3,0xE,0x5,0x9,0x6,0x8,0x0,0xD,0xA,0xB,0x7,0xC,0x2,0x1,0xF,0x4},
+       {0xE,0x9,0xB,0x2,0x5,0xF,0x7,0x1,0x0,0xD,0xC,0x6,0xA,0x4,0x3,0x8},
+       {0xD,0x8,0xE,0xC,0x7,0x3,0x9,0xA,0x1,0x5,0x2,0x4,0x6,0xF,0x0,0xB},
+       {0xC,0x9,0xF,0xE,0x8,0x1,0x3,0xA,0x2,0x7,0x4,0xD,0x6,0x0,0xB,0x5},
+       {0x4,0x2,0xF,0x5,0x9,0x1,0x0,0x8,0xE,0x3,0xB,0xC,0xD,0x7,0xA,0x6}
+       };
+
+
+
+
+/* 1.2.643.2.2.31.1 */
+gost_subst_block Gost28147_CryptoProParamSetA= {
+       {0xB,0xA,0xF,0x5,0x0,0xC,0xE,0x8,0x6,0x2,0x3,0x9,0x1,0x7,0xD,0x4},
+       {0x1,0xD,0x2,0x9,0x7,0xA,0x6,0x0,0x8,0xC,0x4,0x5,0xF,0x3,0xB,0xE},
+       {0x3,0xA,0xD,0xC,0x1,0x2,0x0,0xB,0x7,0x5,0x9,0x4,0x8,0xF,0xE,0x6},
+       {0xB,0x5,0x1,0x9,0x8,0xD,0xF,0x0,0xE,0x4,0x2,0x3,0xC,0x7,0xA,0x6},
+       {0xE,0x7,0xA,0xC,0xD,0x1,0x3,0x9,0x0,0x2,0xB,0x4,0xF,0x8,0x5,0x6},
+       {0xE,0x4,0x6,0x2,0xB,0x3,0xD,0x8,0xC,0xF,0x5,0xA,0x0,0x7,0x1,0x9},
+       {0x3,0x7,0xE,0x9,0x8,0xA,0xF,0x0,0x5,0x2,0x6,0xC,0xB,0x4,0xD,0x1},
+       {0x9,0x6,0x3,0x2,0x8,0xB,0x1,0x7,0xA,0x4,0xE,0xF,0xC,0x0,0xD,0x5}
+       };
+/* 1.2.643.2.2.31.2 */
+gost_subst_block Gost28147_CryptoProParamSetB= 
+       {
+       {0x0,0x4,0xB,0xE,0x8,0x3,0x7,0x1,0xA,0x2,0x9,0x6,0xF,0xD,0x5,0xC},
+       {0x5,0x2,0xA,0xB,0x9,0x1,0xC,0x3,0x7,0x4,0xD,0x0,0x6,0xF,0x8,0xE},
+       {0x8,0x3,0x2,0x6,0x4,0xD,0xE,0xB,0xC,0x1,0x7,0xF,0xA,0x0,0x9,0x5},
+       {0x2,0x7,0xC,0xF,0x9,0x5,0xA,0xB,0x1,0x4,0x0,0xD,0x6,0x8,0xE,0x3},
+       {0x7,0x5,0x0,0xD,0xB,0x6,0x1,0x2,0x3,0xA,0xC,0xF,0x4,0xE,0x9,0x8},
+       {0xE,0xC,0x0,0xA,0x9,0x2,0xD,0xB,0x7,0x5,0x8,0xF,0x3,0x6,0x1,0x4},
+       {0x0,0x1,0x2,0xA,0x4,0xD,0x5,0xC,0x9,0x7,0x3,0xF,0xB,0x8,0x6,0xE},
+       {0x8,0x4,0xB,0x1,0x3,0x5,0x0,0x9,0x2,0xE,0xA,0xC,0xD,0x6,0x7,0xF}
+       };
+/* 1.2.643.2.2.31.3 */
+gost_subst_block Gost28147_CryptoProParamSetC= 
+       {
+       {0x7,0x4,0x0,0x5,0xA,0x2,0xF,0xE,0xC,0x6,0x1,0xB,0xD,0x9,0x3,0x8},
+       {0xA,0x9,0x6,0x8,0xD,0xE,0x2,0x0,0xF,0x3,0x5,0xB,0x4,0x1,0xC,0x7},
+       {0xC,0x9,0xB,0x1,0x8,0xE,0x2,0x4,0x7,0x3,0x6,0x5,0xA,0x0,0xF,0xD},
+       {0x8,0xD,0xB,0x0,0x4,0x5,0x1,0x2,0x9,0x3,0xC,0xE,0x6,0xF,0xA,0x7},
+       {0x3,0x6,0x0,0x1,0x5,0xD,0xA,0x8,0xB,0x2,0x9,0x7,0xE,0xF,0xC,0x4},
+       {0x8,0x2,0x5,0x0,0x4,0x9,0xF,0xA,0x3,0x7,0xC,0xD,0x6,0xE,0x1,0xB},
+       {0x0,0x1,0x7,0xD,0xB,0x4,0x5,0x2,0x8,0xE,0xF,0xC,0x9,0xA,0x6,0x3},
+       {0x1,0xB,0xC,0x2,0x9,0xD,0x0,0xF,0x4,0x5,0x8,0xE,0xA,0x7,0x6,0x3}
+       };
+
+/* 1.2.643.2.2.31.4 */ 
+gost_subst_block Gost28147_CryptoProParamSetD=
+       {
+       {0x1,0xA,0x6,0x8,0xF,0xB,0x0,0x4,0xC,0x3,0x5,0x9,0x7,0xD,0x2,0xE},
+       {0x3,0x0,0x6,0xF,0x1,0xE,0x9,0x2,0xD,0x8,0xC,0x4,0xB,0xA,0x5,0x7},
+       {0x8,0x0,0xF,0x3,0x2,0x5,0xE,0xB,0x1,0xA,0x4,0x7,0xC,0x9,0xD,0x6},
+       {0x0,0xC,0x8,0x9,0xD,0x2,0xA,0xB,0x7,0x3,0x6,0x5,0x4,0xE,0xF,0x1},
+       {0x1,0x5,0xE,0xC,0xA,0x7,0x0,0xD,0x6,0x2,0xB,0x4,0x9,0x3,0xF,0x8},
+       {0x1,0xC,0xB,0x0,0xF,0xE,0x6,0x5,0xA,0xD,0x4,0x8,0x9,0x3,0x7,0x2},
+       {0xB,0x6,0x3,0x4,0xC,0xF,0xE,0x2,0x7,0xD,0x8,0x0,0x5,0xA,0x9,0x1},
+       {0xF,0xC,0x2,0xA,0x6,0x4,0x5,0x0,0x7,0x9,0xE,0xD,0x1,0xB,0x8,0x3}
+       };
+
+
+const byte CryptoProKeyMeshingKey[]={
+       0x69, 0x00, 0x72, 0x22,   0x64, 0xC9, 0x04, 0x23,
+    0x8D, 0x3A, 0xDB, 0x96,   0x46, 0xE9, 0x2A, 0xC4,
+    0x18, 0xFE, 0xAC, 0x94,   0x00, 0xED, 0x07, 0x12,
+    0xC0, 0x86, 0xDC, 0xC2,   0xEF, 0x4C, 0xA9, 0x2B
+       };      
+/* Initialization of gost_ctx subst blocks*/
+static void kboxinit(gost_ctx *c, const gost_subst_block *b)
+       { 
+       int i; 
+       
+       for (i = 0; i < 256; i++)
+               {
+               c->k87[i] = (b->k8[i>>4] <<4 | b->k7 [i &15])<<24;
+               c->k65[i] = (b->k6[i>>4] << 4 | b->k5 [i &15])<<16;
+               c->k43[i] = (b->k4[i>>4] <<4  | b->k3 [i &15])<<8;
+               c->k21[i] = b->k2[i>>4] <<4  | b->k1 [i &15];
+
+               }
+       }
+
+/* Part of GOST 28147 algorithm moved into separate function */
+static word32 f(gost_ctx *c,word32 x) 
+       {
+       x = c->k87[x>>24 & 255] | c->k65[x>>16 & 255]| 
+               c->k43[x>> 8 & 255] | c->k21[x & 255]; 
+       /* Rotate left 11 bits */ 
+       return x<<11 | x>>(32-11);
+       }
+/* Low-level encryption routine - encrypts one 64 bit block*/
+void gostcrypt(gost_ctx *c, const byte *in, byte *out)
+       { 
+       register word32 n1, n2; /* As named in the GOST */ 
+       n1 = in[0]|(in[1]<<8)|(in[2]<<16)|(in[3]<<24); 
+       n2 = in[4]|(in[5]<<8)|(in[6]<<16)|(in[7]<<24); 
+       /* Instead of swapping halves, swap names each round */ 
+        
+       n2 ^= f(c,n1+c->k[0]); n1 ^= f(c,n2+c->k[1]); 
+       n2 ^= f(c,n1+c->k[2]); n1 ^= f(c,n2+c->k[3]); 
+       n2 ^= f(c,n1+c->k[4]); n1 ^= f(c,n2+c->k[5]); 
+       n2 ^= f(c,n1+c->k[6]); n1 ^= f(c,n2+c->k[7]); 
+  
+       n2 ^= f(c,n1+c->k[0]); n1 ^= f(c,n2+c->k[1]);
+       n2 ^= f(c,n1+c->k[2]); n1 ^= f(c,n2+c->k[3]);
+       n2 ^= f(c,n1+c->k[4]); n1 ^= f(c,n2+c->k[5]);
+       n2 ^= f(c,n1+c->k[6]); n1 ^= f(c,n2+c->k[7]);
+                               
+       n2 ^= f(c,n1+c->k[0]); n1 ^= f(c,n2+c->k[1]);
+       n2 ^= f(c,n1+c->k[2]); n1 ^= f(c,n2+c->k[3]);
+       n2 ^= f(c,n1+c->k[4]); n1 ^= f(c,n2+c->k[5]);
+       n2 ^= f(c,n1+c->k[6]); n1 ^= f(c,n2+c->k[7]);
+                               
+       n2 ^= f(c,n1+c->k[7]); n1 ^= f(c,n2+c->k[6]);
+       n2 ^= f(c,n1+c->k[5]); n1 ^= f(c,n2+c->k[4]);
+       n2 ^= f(c,n1+c->k[3]); n1 ^= f(c,n2+c->k[2]);
+       n2 ^= f(c,n1+c->k[1]); n1 ^= f(c,n2+c->k[0]);
+       out[0] = (byte)(n2&0xff);  out[1] = (byte)((n2>>8)&0xff);
+       out[2] = (byte)((n2>>16)&0xff); out[3]=(byte)(n2>>24); 
+       out[4] = (byte)(n1&0xff);  out[5] = (byte)((n1>>8)&0xff);
+       out[6] = (byte)((n1>>16)&0xff); out[7] = (byte)(n1>>24);
+       } 
+/* Low-level decryption routine. Decrypts one 64-bit block */
+void gostdecrypt(gost_ctx *c, const byte *in,byte *out)
+       { 
+       register word32 n1, n2; /* As named in the GOST */ 
+       n1 = in[0]|(in[1]<<8)|(in[2]<<16)|(in[3]<<24); 
+       n2 = in[4]|(in[5]<<8)|(in[6]<<16)|(in[7]<<24); 
+       
+       n2 ^= f(c,n1+c->k[0]); n1 ^= f(c,n2+c->k[1]); 
+       n2 ^= f(c,n1+c->k[2]); n1 ^= f(c,n2+c->k[3]); 
+       n2 ^= f(c,n1+c->k[4]); n1 ^= f(c,n2+c->k[5]);
+       n2 ^= f(c,n1+c->k[6]); n1 ^= f(c,n2+c->k[7]); 
+       
+       n2 ^= f(c,n1+c->k[7]); n1 ^= f(c,n2+c->k[6]);
+       n2 ^= f(c,n1+c->k[5]); n1 ^= f(c,n2+c->k[4]);
+       n2 ^= f(c,n1+c->k[3]); n1 ^= f(c,n2+c->k[2]);
+       n2 ^= f(c,n1+c->k[1]); n1 ^= f(c,n2+c->k[0]);
+       
+       n2 ^= f(c,n1+c->k[7]); n1 ^= f(c,n2+c->k[6]);
+       n2 ^= f(c,n1+c->k[5]); n1 ^= f(c,n2+c->k[4]);
+       n2 ^= f(c,n1+c->k[3]); n1 ^= f(c,n2+c->k[2]);
+       n2 ^= f(c,n1+c->k[1]); n1 ^= f(c,n2+c->k[0]);
+       
+       n2 ^= f(c,n1+c->k[7]); n1 ^= f(c,n2+c->k[6]);
+       n2 ^= f(c,n1+c->k[5]); n1 ^= f(c,n2+c->k[4]);
+       n2 ^= f(c,n1+c->k[3]); n1 ^= f(c,n2+c->k[2]);
+       n2 ^= f(c,n1+c->k[1]); n1 ^= f(c,n2+c->k[0]);
+
+       out[0] = (byte)(n2&0xff);  out[1] = (byte)((n2>>8)&0xff);
+       out[2] = (byte)((n2>>16)&0xff); out[3]=(byte)(n2>>24);
+       out[4] = (byte)(n1&0xff);  out[5] = (byte)((n1>>8)&0xff);
+       out[6] = (byte)((n1>>16)&0xff); out[7] = (byte)(n1>>24);
+       } 
+
+/* Encrypts several blocks in ECB mode */
+void gost_enc(gost_ctx *c,const byte *clear,byte *cipher, int blocks)
+       { 
+       int i; 
+       for(i=0;i<blocks;i++)
+               { 
+               gostcrypt(c,clear,cipher); 
+               clear+=8;
+               cipher+=8;
+               }
+       }
+/* Decrypts several blocks in ECB mode */
+void gost_dec(gost_ctx *c, const byte *cipher,byte *clear, int blocks)
+       { 
+       int i; 
+       for(i=0;i<blocks;i++)
+               { 
+               gostdecrypt(c,cipher,clear); 
+               clear+=8; 
+               cipher+=8;
+               }
+       }
+
+/* Encrypts several full blocks in CFB mode using 8byte IV */
+void gost_enc_cfb(gost_ctx *ctx,const byte *iv,const byte *clear,byte *cipher, int blocks)
+       {
+       byte cur_iv[8];
+       byte gamma[8];
+       int i,j;
+       const byte *in;
+       byte *out;
+       memcpy(cur_iv,iv,8);
+       for(i=0,in=clear,out=cipher;i<blocks;i++,in+=8,out+=8)
+               {
+               gostcrypt(ctx,cur_iv,gamma);
+               for (j=0;j<8;j++)
+                       {
+                       cur_iv[j]=out[j]=in[j]^gamma[j];
+                       }
+               }       
+       }       
+/* Decrypts several full blocks in CFB mode using 8byte IV */
+void gost_dec_cfb(gost_ctx *ctx,const byte *iv,const byte *cipher,byte *clear,  int blocks)
+       {
+       byte cur_iv[8];
+       byte gamma[8];
+       int i,j;
+       const byte *in;
+       byte *out;
+       memcpy(cur_iv,iv,8);
+       for(i=0,in=cipher,out=clear;i<blocks;i++,in+=8,out+=8)
+               {
+               gostcrypt(ctx,cur_iv,gamma);
+               for (j=0;j<8;j++)
+                       {
+                       out[j]=(cur_iv[j]=in[j])^gamma[j];
+                       }
+               }       
+       }       
+
+/* Encrypts one block using specified key */
+void gost_enc_with_key(gost_ctx *c,byte *key,byte *inblock,byte *outblock) 
+       {
+       gost_key(c,key);
+       gostcrypt(c,inblock,outblock);
+       }
+
+/* Set 256 bit  key into context */
+void gost_key(gost_ctx *c, const byte *k) 
+       { 
+       int i,j; 
+       for(i=0,j=0;i<8;i++,j+=4)
+               {
+               c->k[i]=k[j]|(k[j+1]<<8)|(k[j+2]<<16)|(k[j+3]<<24);
+               }               
+       } 
+
+/* Retrieve 256-bit key from context */
+void gost_get_key(gost_ctx *c, byte *k) 
+       {
+       int i,j; 
+       for(i=0,j=0;i<8;i++,j+=4)
+               {
+               k[j]=(byte)(c->k[i]& 0xFF);
+               k[j+1]=(byte)((c->k[i]>>8 )&0xFF);
+               k[j+2]=(byte)((c->k[i]>>16) &0xFF);
+               k[j+3]=(byte)((c->k[i]>>24) &0xFF);
+               }               
+       }
+
+/* Initalize context. Provides default value for subst_block */
+void gost_init(gost_ctx *c, const gost_subst_block *b)
+       {       
+       if(!b)
+               {
+               b=&GostR3411_94_TestParamSet;
+               }       
+       kboxinit(c,b); 
+       }
+
+/* Cleans up key from context */
+void gost_destroy(gost_ctx *c)
+       { 
+       int i; for(i=0;i<8;i++) c->k[i]=0; 
+       } 
+
+/* Compute GOST 28147 mac block 
+ * 
+ * Parameters
+ *   gost_ctx *c - context initalized with substitution blocks and key
+ *   buffer - 8-byte mac state buffer
+ *   block 8-byte block to process.
+ * */
+void mac_block(gost_ctx *c,byte *buffer,const  byte *block)
+       {
+       register word32 n1, n2; /* As named in the GOST */ 
+       int i;
+       for (i=0; i<8; i++)
+               {
+               buffer[i]^=block[i];
+               }         
+       n1 = buffer[0]|(buffer[1]<<8)|(buffer[2]<<16)|(buffer[3]<<24); 
+       n2 = buffer[4]|(buffer[5]<<8)|(buffer[6]<<16)|(buffer[7]<<24); 
+       /* Instead of swapping halves, swap names each round */ 
+        
+       n2 ^= f(c,n1+c->k[0]); n1 ^= f(c,n2+c->k[1]); 
+       n2 ^= f(c,n1+c->k[2]); n1 ^= f(c,n2+c->k[3]); 
+       n2 ^= f(c,n1+c->k[4]); n1 ^= f(c,n2+c->k[5]); 
+       n2 ^= f(c,n1+c->k[6]); n1 ^= f(c,n2+c->k[7]); 
+  
+       n2 ^= f(c,n1+c->k[0]); n1 ^= f(c,n2+c->k[1]);
+       n2 ^= f(c,n1+c->k[2]); n1 ^= f(c,n2+c->k[3]);
+       n2 ^= f(c,n1+c->k[4]); n1 ^= f(c,n2+c->k[5]);
+       n2 ^= f(c,n1+c->k[6]); n1 ^= f(c,n2+c->k[7]);
+
+       buffer[0] = (byte)(n1&0xff);  buffer[1] = (byte)((n1>>8)&0xff);
+       buffer[2] = (byte)((n1>>16)&0xff); buffer[3] = (byte)(n1>>24);
+       buffer[4] = (byte)(n2&0xff);  buffer[5] = (byte)((n2>>8)&0xff);
+       buffer[6] = (byte)((n2>>16)&0xff); buffer[7] = (byte)(n2>>24);
+       }
+
+/* Get mac with specified number of bits from MAC state buffer */
+void get_mac(byte *buffer,int nbits,byte *out)
+       {
+       int nbytes= nbits >> 3;
+       int rembits = nbits & 7;
+       int mask =rembits?((1<rembits)-1):0;
+       int i;
+       for (i=0;i<nbytes;i++) out[i]=buffer[i];
+       if (rembits) out[i]=buffer[i]&mask;
+       }       
+
+/* Compute mac of specified length (in bits) from data. 
+ * Context should be initialized with key and subst blocks */
+int gost_mac(gost_ctx *ctx,int mac_len,const unsigned char *data,
+       unsigned int data_len,unsigned char *mac) 
+       {
+       byte buffer[8]={0,0,0,0,0,0,0,0};
+       byte buf2[8];
+       unsigned int i;
+       for (i=0;i+8<=data_len;i+=8) 
+               mac_block(ctx,buffer,data+i);
+       if (i<data_len)
+               {
+               memset(buf2,0,8);
+               memcpy(buf2,data+i,data_len-i);
+               mac_block(ctx,buffer,buf2);
+               }       
+       get_mac(buffer,mac_len,mac);
+       return 1;
+       }
+
+/* Compute MAC with non-zero IV. Used in some RFC 4357 algorithms */
+int gost_mac_iv(gost_ctx *ctx,int mac_len,const unsigned char *iv,const unsigned char *data,
+       unsigned int data_len,unsigned char *mac) 
+       {
+       byte buffer[8];
+       byte buf2[8];
+       unsigned int i;
+       memcpy (buffer,iv,8);
+       for (i=0;i+8<=data_len;i+=8) 
+               mac_block(ctx,buffer,data+i);
+       if (i<data_len)
+               {
+               memset(buf2,0,8);
+               memcpy(buf2,data+i,data_len-i);
+               mac_block(ctx,buffer,buf2);
+               }       
+       get_mac(buffer,mac_len,mac);
+       return 1;
+       }
+
+/* Implements key meshing algorithm by modifing ctx and IV in place */
+void cryptopro_key_meshing(gost_ctx *ctx, unsigned char *iv)
+       {
+       unsigned char newkey[32],newiv[8];
+       /* Set static keymeshing key */
+       /* "Decrypt" key with keymeshing key */
+       gost_dec(ctx,CryptoProKeyMeshingKey,newkey,4);
+       /* set new key */
+       gost_key(ctx,newkey);
+       /* Encrypt iv with new key */
+       gostcrypt(ctx,iv,newiv);
+       memcpy(iv,newiv,8);
+       }
diff --git a/deps/openssl/openssl/engines/ccgost/gost89.h b/deps/openssl/openssl/engines/ccgost/gost89.h
new file mode 100644 (file)
index 0000000..2157852
--- /dev/null
@@ -0,0 +1,96 @@
+/**********************************************************************
+ *                        gost89.h                                    *
+ *             Copyright (c) 2005-2006 Cryptocom LTD                  *
+ *     This file is distributed under the same license as OpenSSL     *
+ *                                                                    *
+ *          Declarations for GOST 28147-89 encryption algorithm       *
+ *            No OpenSSL libraries required to compile and use        *
+ *                       this code                                    *
+ **********************************************************************/            
+#ifndef GOST89_H
+#define GOST89_H
+
+/* Typedef for unsigned 32-bit integer */
+#if __LONG_MAX__ > 2147483647L 
+typedef unsigned int u4; 
+#else 
+typedef unsigned long u4; 
+#endif 
+/* Typedef for unsigned 8-bit integer */
+typedef unsigned char byte; 
+
+/* Internal representation of GOST substitution blocks */
+typedef struct {
+               byte k8[16];
+               byte k7[16];
+               byte k6[16];
+               byte k5[16];
+               byte k4[16];
+               byte k3[16];
+               byte k2[16];
+               byte k1[16];
+} gost_subst_block;            
+
+
+/* Cipher context includes key and preprocessed  substitution block */
+typedef struct { 
+               u4 k[8]; 
+               /* Constant s-boxes -- set up in gost_init(). */ 
+               u4 k87[256],k65[256],k43[256],k21[256]; 
+} gost_ctx; 
+/* Note: encrypt and decrypt expect full blocks--padding blocks is 
+         caller's responsibility. All bulk encryption is done in 
+                ECB mode by these calls. Other modes may be added easily 
+                enough.                                            */
+/* Encrypt several full blocks in ECB mode */
+void gost_enc(gost_ctx *ctx, const byte *clear,byte *cipher, int blocks); 
+/* Decrypt several full blocks in ECB mode */
+void gost_dec(gost_ctx *ctx, const byte *cipher,byte *clear, int blocks); 
+/* Encrypts several full blocks in CFB mode using 8byte IV */
+void gost_enc_cfb(gost_ctx *ctx,const byte *iv,const byte *clear,byte *cipher,int  blocks);
+/* Decrypts several full blocks in CFB mode using 8byte IV */
+void gost_dec_cfb(gost_ctx *ctx,const byte *iv,const byte *cipher,byte *clear,int  blocks);
+
+/* Encrypt one  block */
+void gostcrypt(gost_ctx *c, const byte *in, byte *out);
+/* Decrypt one  block */
+void gostdecrypt(gost_ctx *c, const byte *in,byte *out);
+/* Set key into context */
+void gost_key(gost_ctx *ctx, const byte *key); 
+/* Get key from context */
+void gost_get_key(gost_ctx *ctx, byte *key);
+/* Set S-blocks into context */
+void gost_init(gost_ctx *ctx, const gost_subst_block *subst_block); 
+/* Clean up context */
+void gost_destroy(gost_ctx *ctx);
+/* Intermediate function used for calculate hash */
+void gost_enc_with_key(gost_ctx *,byte *key,byte *inblock,byte *outblock);
+/* Compute MAC of given length in bits from data */
+int gost_mac(gost_ctx *ctx,int hmac_len,const unsigned char *data,
+               unsigned int data_len,unsigned char *hmac) ;
+/* Compute MAC of given length in bits from data, using non-zero 8-byte
+ * IV (non-standard, for use in CryptoPro key transport only */
+int gost_mac_iv(gost_ctx *ctx,int hmac_len,const unsigned char *iv,const unsigned char *data,
+               unsigned int data_len,unsigned char *hmac) ;
+/* Perform one step of MAC calculation like gostcrypt */
+void mac_block(gost_ctx *c,byte *buffer,const  byte *block); 
+/* Extracts MAC value from mac state buffer */
+void get_mac(byte *buffer,int nbits,byte *out);
+/* Implements cryptopro key meshing algorithm. Expect IV to be 8-byte size*/
+void cryptopro_key_meshing(gost_ctx *ctx, unsigned char *iv);
+/* Parameter sets specified in RFC 4357 */
+extern gost_subst_block GostR3411_94_TestParamSet;
+extern gost_subst_block GostR3411_94_CryptoProParamSet;
+extern gost_subst_block Gost28147_TestParamSet;
+extern gost_subst_block Gost28147_CryptoProParamSetA;
+extern gost_subst_block Gost28147_CryptoProParamSetB;
+extern gost_subst_block Gost28147_CryptoProParamSetC;
+extern gost_subst_block Gost28147_CryptoProParamSetD;
+extern const byte CryptoProKeyMeshingKey[]; 
+#if __LONG_MAX__ > 2147483647L 
+typedef unsigned int word32; 
+#else 
+typedef unsigned long word32; 
+#endif 
+
+#endif
diff --git a/deps/openssl/openssl/engines/ccgost/gost94_keyx.c b/deps/openssl/openssl/engines/ccgost/gost94_keyx.c
new file mode 100644 (file)
index 0000000..0d7d3ff
--- /dev/null
@@ -0,0 +1,291 @@
+/**********************************************************************
+ *                             gost94_keyx.c                          *
+ *             Copyright (c) 2005-2006 Cryptocom LTD                  *
+ *         This file is distributed under the same license as OpenSSL *
+ *                                                                    *
+ *     Implements generation and parsing of GOST_KEY_TRANSPORT for    *
+ *                             GOST R 34.10-94 algorithms                            *
+ *                                                                                                                                       *
+ *          Requires OpenSSL 0.9.9 for compilation                    *
+ **********************************************************************/
+#include <string.h>
+#include <openssl/dh.h>
+#include <openssl/rand.h>
+#include <openssl/evp.h>
+#include <openssl/objects.h>
+
+#include "gost89.h"
+#include "gosthash.h"
+#include "e_gost_err.h"
+#include "gost_keywrap.h"
+#include "gost_lcl.h"
+/* Common functions for both 94 and 2001 key exchange schemes */
+/* Implementation of the Diffi-Hellman key agreement scheme based on
+ * GOST-94 keys */
+
+/* Computes Diffie-Hellman key and stores it into buffer in
+ * little-endian byte order as expected by both versions of GOST 94
+ * algorithm
+ */
+static int compute_pair_key_le(unsigned char *pair_key,BIGNUM *pub_key,DH *dh) 
+       {
+       unsigned char be_key[128];
+       int i,key_size;
+       key_size=DH_compute_key(be_key,pub_key,dh);
+       if (!key_size) return 0;
+       memset(pair_key,0,128);
+       for (i=0;i<key_size;i++)
+               {
+               pair_key[i]=be_key[key_size-1-i];
+               }
+       return key_size;        
+       }       
+
+/*
+ * Computes 256 bit Key exchange key as specified in RFC 4357 
+ */
+static int make_cp_exchange_key(BIGNUM *priv_key,EVP_PKEY *pubk, unsigned char *shared_key)
+       {
+       unsigned char dh_key [128];
+       int ret;
+       gost_hash_ctx hash_ctx;
+       DH *dh = DH_new();
+       
+       if (!dh)
+               return 0;
+       memset(dh_key,0,128);
+       dh->g = BN_dup(pubk->pkey.dsa->g);
+       dh->p = BN_dup(pubk->pkey.dsa->p);
+       dh->priv_key = BN_dup(priv_key);
+       ret=compute_pair_key_le(dh_key,((DSA *)(EVP_PKEY_get0(pubk)))->pub_key,dh) ;
+       DH_free(dh);
+       if (!ret)       return 0;
+       init_gost_hash_ctx(&hash_ctx,&GostR3411_94_CryptoProParamSet);
+       start_hash(&hash_ctx);
+       hash_block(&hash_ctx,dh_key,128);
+       finish_hash(&hash_ctx,shared_key);
+       done_gost_hash_ctx(&hash_ctx);
+       return 1;
+       }
+
+/* EVP_PKEY_METHOD callback derive. Implements VKO R 34.10-94 */
+
+int pkey_gost94_derive(EVP_PKEY_CTX *ctx,unsigned char *key,size_t *keylen)
+       {
+               EVP_PKEY *pubk = EVP_PKEY_CTX_get0_peerkey(ctx);
+               EVP_PKEY *mykey = EVP_PKEY_CTX_get0_pkey(ctx);
+               *keylen = 32;
+               if (key == NULL) return 1;
+
+               return make_cp_exchange_key(gost_get0_priv_key(mykey), pubk, key);
+       }
+
+/* EVP_PKEY_METHOD callback encrypt for
+ * GOST R 34.10-94 cryptopro modification
+ */
+
+
+int pkey_GOST94cp_encrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, const unsigned char* key, size_t key_len ) 
+       {
+       GOST_KEY_TRANSPORT *gkt=NULL;
+       unsigned char shared_key[32], ukm[8],crypted_key[44];
+       const struct gost_cipher_info *param=get_encryption_params(NULL);
+       EVP_PKEY *pubk = EVP_PKEY_CTX_get0_pkey(ctx);
+       struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
+       gost_ctx cctx;
+       int key_is_ephemeral=1;
+       EVP_PKEY *mykey = EVP_PKEY_CTX_get0_peerkey(ctx);
+
+       /* Do not use vizir cipher parameters with cryptopro */
+       if (!get_gost_engine_param(GOST_PARAM_CRYPT_PARAMS) && param ==  gost_cipher_list)
+               {
+               param= gost_cipher_list+1;
+               }       
+
+       if (mykey) 
+               {
+               /* If key already set, it is not ephemeral */
+               key_is_ephemeral=0;
+               if (!gost_get0_priv_key(mykey)) 
+                       {
+                       GOSTerr(GOST_F_PKEY_GOST94CP_ENCRYPT,
+                       GOST_R_NO_PRIVATE_PART_OF_NON_EPHEMERAL_KEYPAIR);
+                       goto err;
+                       }       
+               } 
+       else 
+               {
+               /* Otherwise generate ephemeral key */
+               key_is_ephemeral = 1;
+               if (out) 
+                       {
+                       mykey = EVP_PKEY_new();
+                       EVP_PKEY_assign(mykey, EVP_PKEY_base_id(pubk),DSA_new());
+                       EVP_PKEY_copy_parameters(mykey,pubk);
+                       if (!gost_sign_keygen(EVP_PKEY_get0(mykey))) 
+                               {
+                               goto err;
+                               }       
+                       }
+               }       
+       if (out)
+               make_cp_exchange_key(gost_get0_priv_key(mykey),pubk,shared_key);
+       if (data->shared_ukm) 
+               {
+               memcpy(ukm,data->shared_ukm,8);
+               }
+       else if (out) 
+               {       
+               if (RAND_bytes(ukm,8)<=0)
+                       {
+                       GOSTerr(GOST_F_PKEY_GOST94CP_ENCRYPT,
+                                       GOST_R_RANDOM_GENERATOR_FAILURE);
+                       goto err;
+                       }       
+               }
+               
+       if (out) {
+               gost_init(&cctx,param->sblock);
+               keyWrapCryptoPro(&cctx,shared_key,ukm,key,crypted_key);
+       }       
+       gkt = GOST_KEY_TRANSPORT_new();
+       if (!gkt)
+               {
+               goto memerr;
+               }       
+       if(!ASN1_OCTET_STRING_set(gkt->key_agreement_info->eph_iv,
+                       ukm,8))
+               {
+               goto memerr;
+               }       
+       if (!ASN1_OCTET_STRING_set(gkt->key_info->imit,crypted_key+40,4))
+               {
+               goto memerr;
+               }
+       if (!ASN1_OCTET_STRING_set(gkt->key_info->encrypted_key,crypted_key+8,32))
+               {
+               goto memerr;
+               }
+       if (key_is_ephemeral) { 
+       if (!X509_PUBKEY_set(&gkt->key_agreement_info->ephem_key,out?mykey:pubk))
+               {
+               GOSTerr(GOST_F_PKEY_GOST94CP_ENCRYPT,GOST_R_CANNOT_PACK_EPHEMERAL_KEY);
+               goto err;
+               }
+               if (out) EVP_PKEY_free(mykey);
+       }       
+       ASN1_OBJECT_free(gkt->key_agreement_info->cipher);
+       gkt->key_agreement_info->cipher = OBJ_nid2obj(param->nid);
+       *outlen = i2d_GOST_KEY_TRANSPORT(gkt,out?&out:NULL);
+       if (*outlen <= 0)
+               {
+               GOSTerr(GOST_F_PKEY_GOST94CP_ENCRYPT,GOST_R_ERROR_PACKING_KEY_TRANSPORT_INFO);
+               goto err;
+               }
+       if (!key_is_ephemeral)
+               {
+               /* Set control "public key from client certificate used" */
+               if (EVP_PKEY_CTX_ctrl(ctx, -1, -1, EVP_PKEY_CTRL_PEER_KEY, 3, NULL) <= 0)
+                       {
+                       GOSTerr(GOST_F_PKEY_GOST94CP_ENCRYPT,
+                               GOST_R_CTRL_CALL_FAILED);
+                       goto err;
+                       }
+               }
+       GOST_KEY_TRANSPORT_free(gkt);
+       return 1;       
+       memerr:
+               if (key_is_ephemeral) {
+                       EVP_PKEY_free(mykey);
+               }       
+       GOSTerr(GOST_F_PKEY_GOST94CP_ENCRYPT,
+               GOST_R_MALLOC_FAILURE);
+       err:            
+       GOST_KEY_TRANSPORT_free(gkt);
+       return -1;
+       }
+
+       
+/* EVP_PLEY_METHOD callback decrypt for
+ * GOST R 34.10-94 cryptopro modification
+ */
+int pkey_GOST94cp_decrypt(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *key_len,const unsigned char *in, size_t in_len) {
+       const unsigned char *p = in;
+       GOST_KEY_TRANSPORT *gkt = NULL;
+       unsigned char wrappedKey[44];
+       unsigned char sharedKey[32];
+       gost_ctx cctx;
+       const struct gost_cipher_info *param=NULL;
+       EVP_PKEY *eph_key=NULL, *peerkey=NULL;
+       EVP_PKEY *priv= EVP_PKEY_CTX_get0_pkey(ctx); 
+       
+       if (!key)
+               {
+               *key_len = 32;
+               return 1;
+               }       
+       
+       gkt = d2i_GOST_KEY_TRANSPORT(NULL,(const unsigned char **)&p,
+               in_len);
+       if (!gkt)
+               {
+               GOSTerr(GOST_F_PKEY_GOST94CP_DECRYPT,GOST_R_ERROR_PARSING_KEY_TRANSPORT_INFO);
+               return 0;
+               }       
+       eph_key = X509_PUBKEY_get(gkt->key_agreement_info->ephem_key);
+       if (eph_key)
+               {
+               if (EVP_PKEY_derive_set_peer(ctx, eph_key) <= 0)
+                       {
+                       GOSTerr(GOST_F_PKEY_GOST94CP_DECRYPT,
+                               GOST_R_INCOMPATIBLE_PEER_KEY);
+                       goto err;
+                       }
+               }
+       else
+               {
+               /* Set control "public key from client certificate used" */
+               if (EVP_PKEY_CTX_ctrl(ctx, -1, -1, EVP_PKEY_CTRL_PEER_KEY, 3, NULL) <= 0)
+                       {
+                       GOSTerr(GOST_F_PKEY_GOST94CP_DECRYPT,
+                               GOST_R_CTRL_CALL_FAILED);
+                       goto err;
+                       }
+               }
+       peerkey = EVP_PKEY_CTX_get0_peerkey(ctx);
+       if (!peerkey)
+               {
+               GOSTerr(GOST_F_PKEY_GOST94CP_DECRYPT,
+                       GOST_R_NO_PEER_KEY);
+               goto err;
+               }
+
+       param = get_encryption_params(gkt->key_agreement_info->cipher);
+    if(!param){
+        goto err;
+    }
+       
+       gost_init(&cctx,param->sblock); 
+       OPENSSL_assert(gkt->key_agreement_info->eph_iv->length==8);
+       memcpy(wrappedKey,gkt->key_agreement_info->eph_iv->data,8);
+       OPENSSL_assert(gkt->key_info->encrypted_key->length==32);
+       memcpy(wrappedKey+8,gkt->key_info->encrypted_key->data,32);
+       OPENSSL_assert(gkt->key_info->imit->length==4);
+       memcpy(wrappedKey+40,gkt->key_info->imit->data,4);      
+       make_cp_exchange_key(gost_get0_priv_key(priv),peerkey,sharedKey);
+       if (!keyUnwrapCryptoPro(&cctx,sharedKey,wrappedKey,key))
+               {
+               GOSTerr(GOST_F_PKEY_GOST94CP_DECRYPT,
+                       GOST_R_ERROR_COMPUTING_SHARED_KEY);
+               goto err;
+               }       
+                               
+       EVP_PKEY_free(eph_key);
+       GOST_KEY_TRANSPORT_free(gkt);
+       return 1;
+err:
+       EVP_PKEY_free(eph_key);
+       GOST_KEY_TRANSPORT_free(gkt);
+       return -1;
+       }       
+
diff --git a/deps/openssl/openssl/engines/ccgost/gost_ameth.c b/deps/openssl/openssl/engines/ccgost/gost_ameth.c
new file mode 100644 (file)
index 0000000..e6c2839
--- /dev/null
@@ -0,0 +1,908 @@
+/**********************************************************************
+ *                          gost_ameth.c                              *
+ *             Copyright (c) 2005-2006 Cryptocom LTD                  *
+ *         This file is distributed under the same license as OpenSSL *
+ *                                                                    *
+ *       Implementation of RFC 4490/4491 ASN1 method                  *
+ *       for OpenSSL                                                  *
+ *          Requires OpenSSL 0.9.9 for compilation                    *
+ **********************************************************************/
+#include <string.h>
+#include <openssl/crypto.h>
+#include <openssl/err.h>
+#include <openssl/engine.h>
+#include <openssl/evp.h>
+#include <openssl/asn1.h>
+#include "gost_params.h"
+#include "gost_lcl.h"
+#include "e_gost_err.h"
+
+int gost94_nid_by_params(DSA *p) 
+       {
+       R3410_params *gost_params;
+       BIGNUM *q=BN_new();
+       for (gost_params = R3410_paramset;gost_params->q!=NULL; gost_params++) 
+               {
+               BN_dec2bn(&q,gost_params->q);
+               if (!BN_cmp(q,p->q)) 
+                       {
+                       BN_free(q);
+                       return gost_params->nid;
+                       }
+               }       
+       BN_free(q);
+       return NID_undef;
+       }
+
+static ASN1_STRING  *encode_gost_algor_params(const EVP_PKEY *key)
+       {
+       ASN1_STRING *params = ASN1_STRING_new();
+       GOST_KEY_PARAMS *gkp = GOST_KEY_PARAMS_new();
+       int pkey_param_nid = NID_undef;
+
+       if (!params || !gkp) 
+               {
+               GOSTerr(GOST_F_ENCODE_GOST_ALGOR_PARAMS,
+                       ERR_R_MALLOC_FAILURE);
+               ASN1_STRING_free(params);
+               params = NULL;
+               goto err;
+               }       
+       switch (EVP_PKEY_base_id(key)) 
+               {
+               case NID_id_GostR3410_2001:
+                       pkey_param_nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(EVP_PKEY_get0((EVP_PKEY *)key)));
+                       break;
+               case NID_id_GostR3410_94:
+                       pkey_param_nid = (int) gost94_nid_by_params(EVP_PKEY_get0((EVP_PKEY *)key));
+                       if (pkey_param_nid == NID_undef) 
+                               {
+                               GOSTerr(GOST_F_ENCODE_GOST_ALGOR_PARAMS,
+                                       GOST_R_INVALID_GOST94_PARMSET);
+                               ASN1_STRING_free(params);
+                               params=NULL;
+                               goto err;
+                               }       
+                       break;
+               }       
+       gkp->key_params = OBJ_nid2obj(pkey_param_nid);
+       gkp->hash_params = OBJ_nid2obj(NID_id_GostR3411_94_CryptoProParamSet);
+       /*gkp->cipher_params = OBJ_nid2obj(cipher_param_nid);*/
+       params->length = i2d_GOST_KEY_PARAMS(gkp, &params->data);
+       if (params->length <=0 ) 
+               {
+               GOSTerr(GOST_F_ENCODE_GOST_ALGOR_PARAMS,
+                       ERR_R_MALLOC_FAILURE);
+               ASN1_STRING_free(params);
+               params = NULL;
+               goto err;
+               }
+       params ->type = V_ASN1_SEQUENCE;
+       err:
+       GOST_KEY_PARAMS_free(gkp);
+       return params;
+       }
+
+/* Parses GOST algorithm parameters from X509_ALGOR and
+ * modifies pkey setting NID and parameters
+ */
+static int decode_gost_algor_params(EVP_PKEY *pkey, X509_ALGOR *palg) 
+       {
+       ASN1_OBJECT *palg_obj =NULL;
+       int ptype = V_ASN1_UNDEF;
+       int pkey_nid = NID_undef,param_nid = NID_undef;
+        void *_pval;
+       ASN1_STRING *pval = NULL;
+       const unsigned char  *p;
+       GOST_KEY_PARAMS *gkp = NULL;
+
+       X509_ALGOR_get0(&palg_obj, &ptype, &_pval, palg);
+        pval = _pval;
+       if (ptype != V_ASN1_SEQUENCE) 
+               {
+               GOSTerr(GOST_F_DECODE_GOST_ALGOR_PARAMS,
+                       GOST_R_BAD_KEY_PARAMETERS_FORMAT);
+               return 0;
+               }       
+       p=pval->data;
+       pkey_nid = OBJ_obj2nid(palg_obj);
+
+       gkp = d2i_GOST_KEY_PARAMS(NULL,&p,pval->length);
+       if (!gkp) 
+               {
+               GOSTerr(GOST_F_DECODE_GOST_ALGOR_PARAMS,
+                       GOST_R_BAD_PKEY_PARAMETERS_FORMAT);
+               return 0;
+               }       
+       param_nid = OBJ_obj2nid(gkp->key_params);
+       GOST_KEY_PARAMS_free(gkp);
+       EVP_PKEY_set_type(pkey,pkey_nid);
+       switch (pkey_nid) 
+               {
+               case NID_id_GostR3410_94:
+               {
+               DSA *dsa= EVP_PKEY_get0(pkey);
+               if (!dsa) 
+                       {
+                       dsa = DSA_new();
+                       if (!EVP_PKEY_assign(pkey,pkey_nid,dsa)) return 0;
+                       }
+               if (!fill_GOST94_params(dsa,param_nid)) return 0;
+               break;
+               }
+               case NID_id_GostR3410_2001:
+               {
+               EC_KEY *ec = EVP_PKEY_get0(pkey);
+               if (!ec) 
+                       {
+                       ec = EC_KEY_new();
+                       if (!EVP_PKEY_assign(pkey,pkey_nid,ec)) return 0;
+                       }
+               if (!fill_GOST2001_params(ec,param_nid)) return 0;
+               }
+               }
+
+       return 1;
+       }
+
+static int gost_set_priv_key(EVP_PKEY *pkey,BIGNUM *priv) 
+       {
+       switch (EVP_PKEY_base_id(pkey)) 
+               {
+               case NID_id_GostR3410_94:
+               {
+               DSA *dsa = EVP_PKEY_get0(pkey);
+               if (!dsa) 
+                       {
+                       dsa = DSA_new();
+                       EVP_PKEY_assign(pkey,EVP_PKEY_base_id(pkey),dsa);
+                       }       
+               dsa->priv_key = BN_dup(priv);
+               if (!EVP_PKEY_missing_parameters(pkey)) 
+                       gost94_compute_public(dsa);
+               break;
+               }       
+               case NID_id_GostR3410_2001:
+               {
+               EC_KEY *ec = EVP_PKEY_get0(pkey);
+               if (!ec) 
+                       {
+                       ec = EC_KEY_new();
+                       EVP_PKEY_assign(pkey,EVP_PKEY_base_id(pkey),ec);
+                       }       
+               if (!EC_KEY_set_private_key(ec,priv)) return 0;
+               if (!EVP_PKEY_missing_parameters(pkey)) 
+                       gost2001_compute_public(ec);
+               break;
+               }
+               }
+       return 1;               
+       }
+BIGNUM* gost_get0_priv_key(const EVP_PKEY *pkey) 
+       {
+       switch (EVP_PKEY_base_id(pkey)) 
+               {
+               case NID_id_GostR3410_94:
+               {
+               DSA *dsa = EVP_PKEY_get0((EVP_PKEY *)pkey);
+               if (!dsa) 
+                       {
+                       return NULL;
+                       }       
+               if (!dsa->priv_key) return NULL;
+               return dsa->priv_key;
+               break;
+               }       
+               case NID_id_GostR3410_2001:
+               {
+               EC_KEY *ec = EVP_PKEY_get0((EVP_PKEY *)pkey);
+               const BIGNUM* priv;
+               if (!ec) 
+                       {
+                       return NULL;
+                       }       
+               if (!(priv=EC_KEY_get0_private_key(ec))) return NULL;
+               return (BIGNUM *)priv;
+               break;
+               }
+               }
+       return NULL;            
+       }
+
+static int pkey_ctrl_gost(EVP_PKEY *pkey, int op,
+       long arg1, void *arg2)
+       {
+       switch (op)
+               {
+               case ASN1_PKEY_CTRL_PKCS7_SIGN:
+                       if (arg1 == 0) 
+                               {
+                               X509_ALGOR *alg1 = NULL, *alg2 = NULL;
+                               int nid = EVP_PKEY_base_id(pkey);
+                               PKCS7_SIGNER_INFO_get0_algs((PKCS7_SIGNER_INFO*)arg2, 
+                                       NULL, &alg1, &alg2);
+                               X509_ALGOR_set0(alg1, OBJ_nid2obj(NID_id_GostR3411_94),
+                                       V_ASN1_NULL, 0);
+                               if (nid == NID_undef) 
+                                       {
+                                       return (-1);
+                                       }
+                               X509_ALGOR_set0(alg2, OBJ_nid2obj(nid), V_ASN1_NULL, 0);
+                               }
+                       return 1;
+               case ASN1_PKEY_CTRL_PKCS7_ENCRYPT:
+                       if (arg1 == 0)
+                               {
+                               X509_ALGOR *alg;
+                               ASN1_STRING * params = encode_gost_algor_params(pkey);
+                               if (!params) 
+                                       {
+                                       return -1;
+                                       }
+                               PKCS7_RECIP_INFO_get0_alg((PKCS7_RECIP_INFO*)arg2, &alg);
+                               X509_ALGOR_set0(alg, OBJ_nid2obj(pkey->type),
+                                       V_ASN1_SEQUENCE, params);
+                               }
+                       return 1;
+               case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
+                       *(int *)arg2 = NID_id_GostR3411_94;
+                       return 2;
+               }
+       
+       return -2;
+       }
+/*----------------------- free functions * ------------------------------*/
+static void pkey_free_gost94(EVP_PKEY *key) 
+       {
+       if (key->pkey.dsa) 
+               {
+               DSA_free(key->pkey.dsa);
+               }
+       }
+
+static void pkey_free_gost01(EVP_PKEY *key) 
+       {
+       if (key->pkey.ec) 
+               {
+               EC_KEY_free(key->pkey.ec);
+               }
+       }       
+
+/* ------------------ private key functions  -----------------------------*/
+static int priv_decode_gost( EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf) 
+       {
+       const unsigned char *pkey_buf = NULL,*p=NULL;
+       int priv_len = 0;
+       BIGNUM *pk_num=NULL;
+       int ret =0;
+       X509_ALGOR *palg =NULL;
+       ASN1_OBJECT *palg_obj = NULL;
+       ASN1_INTEGER *priv_key=NULL;
+
+       if (!PKCS8_pkey_get0(&palg_obj,&pkey_buf,&priv_len,&palg,p8inf)) 
+               return 0;
+       p = pkey_buf;
+       if (!decode_gost_algor_params(pk,palg)) 
+               {
+               return 0;
+               }
+       if (V_ASN1_OCTET_STRING == *p) 
+               {
+               /* New format - Little endian octet string */
+               unsigned char rev_buf[32];
+               int i;
+               ASN1_OCTET_STRING *s = d2i_ASN1_OCTET_STRING(NULL,&p,priv_len);
+               if (!s||s->length !=32) 
+                       {
+                       GOSTerr(GOST_F_PRIV_DECODE_GOST,
+                               EVP_R_DECODE_ERROR);
+                       return 0;       
+                       }
+               for (i=0;i<32;i++)
+                       {
+                       rev_buf[31-i]=s->data[i];
+                       }
+               ASN1_STRING_free(s);
+               pk_num = getbnfrombuf(rev_buf,32);
+               } 
+       else
+               {
+               priv_key=d2i_ASN1_INTEGER(NULL,&p,priv_len);
+               if (!priv_key) return 0;
+               ret= ((pk_num =  ASN1_INTEGER_to_BN(priv_key, NULL))!=NULL) ;
+               ASN1_INTEGER_free(priv_key);
+               if (!ret)
+                       {
+                       GOSTerr(GOST_F_PRIV_DECODE_GOST,
+                               EVP_R_DECODE_ERROR);
+                       return 0;       
+                       }
+               }
+
+       ret= gost_set_priv_key(pk,pk_num);
+       BN_free(pk_num);
+       return ret;
+       }
+
+/* ----------------------------------------------------------------------*/
+static int priv_encode_gost(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk)
+       {
+       ASN1_OBJECT *algobj = OBJ_nid2obj(EVP_PKEY_base_id(pk));
+       ASN1_STRING *params = encode_gost_algor_params(pk);
+       unsigned char *priv_buf = NULL;
+       int priv_len;
+
+       ASN1_INTEGER *asn1key=NULL;
+       if (!params) 
+               {
+               return 0;
+               }
+       asn1key = BN_to_ASN1_INTEGER(gost_get0_priv_key(pk),NULL);
+       priv_len = i2d_ASN1_INTEGER(asn1key,&priv_buf);
+       ASN1_INTEGER_free(asn1key);
+       return PKCS8_pkey_set0(p8,algobj,0,V_ASN1_SEQUENCE,params,
+               priv_buf,priv_len);
+       }
+/* --------- printing keys --------------------------------*/
+static int print_gost_94(BIO *out, const EVP_PKEY *pkey, int indent,
+       ASN1_PCTX *pctx, int type) 
+       {
+       int param_nid = NID_undef;
+
+       if (type == 2) 
+               {
+               BIGNUM *key;
+
+               if (!BIO_indent(out,indent,128)) return 0;
+               BIO_printf(out,"Private key: ");
+               key = gost_get0_priv_key(pkey);
+               if (!key) 
+                       BIO_printf(out,"<undefined>");
+               else 
+                       BN_print(out,key);
+               BIO_printf(out,"\n");
+               }
+       if (type >= 1)
+               {
+               BIGNUM *pubkey;
+               
+               pubkey = ((DSA *)EVP_PKEY_get0((EVP_PKEY *)pkey))->pub_key;
+               BIO_indent(out,indent,128);
+               BIO_printf(out,"Public key: ");
+               BN_print(out,pubkey);
+               BIO_printf(out,"\n");
+       }       
+
+       param_nid = gost94_nid_by_params(EVP_PKEY_get0((EVP_PKEY *)pkey));
+       BIO_indent(out,indent,128);
+       BIO_printf(out, "Parameter set: %s\n",OBJ_nid2ln(param_nid));
+       return 1;
+}
+
+static int param_print_gost94(BIO *out, const EVP_PKEY *pkey, int indent,
+       ASN1_PCTX *pctx) 
+       {
+       return print_gost_94(out, pkey, indent, pctx,0);
+       }
+
+static int pub_print_gost94(BIO *out, const EVP_PKEY *pkey, int indent,
+       ASN1_PCTX *pctx)
+       {
+       return print_gost_94(out,pkey, indent, pctx,1);
+       }
+static int priv_print_gost94(BIO *out,const EVP_PKEY *pkey, int indent,
+       ASN1_PCTX *pctx) 
+       {
+       return print_gost_94(out,pkey,indent,pctx,2);
+       }
+
+static int print_gost_01(BIO *out, const EVP_PKEY *pkey, int indent,
+       ASN1_PCTX *pctx, int type)
+       {
+       int param_nid = NID_undef;
+       if (type == 2) 
+               {
+               BIGNUM *key;
+
+               if (!BIO_indent(out,indent,128)) return 0;
+               BIO_printf(out,"Private key: ");
+               key = gost_get0_priv_key(pkey);
+               if (!key) 
+                       BIO_printf(out,"<undefined)");
+               else 
+                       BN_print(out,key);
+               BIO_printf(out,"\n");
+               }
+       if (type >= 1) 
+               {
+               BN_CTX *ctx = BN_CTX_new();
+               BIGNUM *X,*Y;
+               const EC_POINT *pubkey;
+               const EC_GROUP *group;
+
+               if (!ctx) 
+                       {
+                       GOSTerr(GOST_F_PRINT_GOST_01,ERR_R_MALLOC_FAILURE);
+                       return 0;
+                       }
+               BN_CTX_start(ctx);
+               X = BN_CTX_get(ctx);
+               Y = BN_CTX_get(ctx);
+               pubkey = EC_KEY_get0_public_key((EC_KEY *)EVP_PKEY_get0((EVP_PKEY *)pkey));
+               group = EC_KEY_get0_group((EC_KEY *)EVP_PKEY_get0((EVP_PKEY *)pkey));
+               if (!EC_POINT_get_affine_coordinates_GFp(group,pubkey,X,Y,ctx)) 
+                       {
+                       GOSTerr(GOST_F_PRINT_GOST_01,ERR_R_EC_LIB);
+                       BN_CTX_free(ctx);
+                       return 0;
+                       }
+               if (!BIO_indent(out,indent,128)) return 0;
+               BIO_printf(out,"Public key:\n");
+               if (!BIO_indent(out,indent+3,128)) return 0;
+               BIO_printf(out,"X:");
+               BN_print(out,X);
+               BIO_printf(out,"\n");
+               BIO_indent(out,indent+3,128);
+               BIO_printf(out,"Y:");
+               BN_print(out,Y);
+               BIO_printf(out,"\n");
+               BN_CTX_end(ctx);
+               BN_CTX_free(ctx);
+               }
+
+       param_nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(EVP_PKEY_get0((EVP_PKEY *)pkey)));
+       if (!BIO_indent(out,indent,128)) return 0;
+       BIO_printf(out,"Parameter set: %s\n",OBJ_nid2ln(param_nid));
+       return 1;
+}
+static int param_print_gost01(BIO *out, const EVP_PKEY *pkey, int indent,
+       ASN1_PCTX *pctx) 
+       {       
+       return print_gost_01(out,pkey,indent,pctx,0);
+       }
+static int pub_print_gost01(BIO *out, const EVP_PKEY *pkey, int indent,
+       ASN1_PCTX *pctx)
+       {
+       return print_gost_01(out,pkey, indent, pctx,1);
+       }
+static int priv_print_gost01(BIO *out,const EVP_PKEY *pkey, int indent,
+       ASN1_PCTX *pctx) 
+       {
+       return print_gost_01(out,pkey,indent,pctx,2);
+       }
+/* ---------------------------------------------------------------------*/
+static int param_missing_gost94(const EVP_PKEY *pk) 
+       {
+       const DSA *dsa = EVP_PKEY_get0((EVP_PKEY *)pk);
+       if (!dsa) return 1;
+       if (!dsa->q) return 1;
+       return 0;
+       }
+
+static int param_missing_gost01(const EVP_PKEY *pk) 
+       {
+       const EC_KEY *ec = EVP_PKEY_get0((EVP_PKEY *)pk);
+       if (!ec) return 1;
+       if (!EC_KEY_get0_group(ec)) return 1;
+       return 0;
+       }
+
+static int param_copy_gost94(EVP_PKEY *to, const EVP_PKEY *from) 
+       {
+       const DSA *dfrom = EVP_PKEY_get0((EVP_PKEY *)from);
+       DSA *dto = EVP_PKEY_get0(to);
+       if (EVP_PKEY_base_id(from) != EVP_PKEY_base_id(to)) 
+               {
+               GOSTerr(GOST_F_PARAM_COPY_GOST94,
+                       GOST_R_INCOMPATIBLE_ALGORITHMS);
+               return 0;
+               }       
+       if (!dfrom) 
+               {
+               GOSTerr(GOST_F_PARAM_COPY_GOST94,
+                       GOST_R_KEY_PARAMETERS_MISSING);
+               return 0;
+               }       
+       if (!dto) 
+               {
+               dto = DSA_new();
+               EVP_PKEY_assign(to,EVP_PKEY_base_id(from),dto);
+               }       
+#define COPYBIGNUM(a,b,x) if (a->x) BN_free(a->x); a->x=BN_dup(b->x);  
+       COPYBIGNUM(dto,dfrom,p)
+               COPYBIGNUM(dto,dfrom,q)
+               COPYBIGNUM(dto,dfrom,g)
+
+               if (dto->priv_key) 
+                       gost94_compute_public(dto);
+       return 1;       
+       }
+static int param_copy_gost01(EVP_PKEY *to, const EVP_PKEY *from) 
+       {
+       EC_KEY *eto = EVP_PKEY_get0(to);
+       const EC_KEY *efrom = EVP_PKEY_get0((EVP_PKEY *)from);
+       if (EVP_PKEY_base_id(from) != EVP_PKEY_base_id(to)) 
+               {
+               GOSTerr(GOST_F_PARAM_COPY_GOST01,
+                       GOST_R_INCOMPATIBLE_ALGORITHMS);
+               return 0;
+               }       
+       if (!efrom) 
+               {
+               GOSTerr(GOST_F_PARAM_COPY_GOST01,
+                       GOST_R_KEY_PARAMETERS_MISSING);
+               return 0;
+               }       
+       if (!eto) 
+               {
+               eto = EC_KEY_new();
+               EVP_PKEY_assign(to,EVP_PKEY_base_id(from),eto);
+               }       
+       EC_KEY_set_group(eto,EC_KEY_get0_group(efrom));
+       if (EC_KEY_get0_private_key(eto)) 
+               {
+               gost2001_compute_public(eto);
+               }
+       return 1;
+       }
+
+static int param_cmp_gost94(const EVP_PKEY *a, const EVP_PKEY *b) 
+       {
+       const DSA *da = EVP_PKEY_get0((EVP_PKEY *)a);
+       const DSA *db = EVP_PKEY_get0((EVP_PKEY *)b);
+       if (!BN_cmp(da->q,db->q)) return 1;
+       return 0;
+       }
+
+static int param_cmp_gost01(const EVP_PKEY *a, const EVP_PKEY *b) 
+       {
+       if (EC_GROUP_get_curve_name(EC_KEY_get0_group(EVP_PKEY_get0((EVP_PKEY *)a)))==
+               EC_GROUP_get_curve_name(EC_KEY_get0_group(EVP_PKEY_get0((EVP_PKEY *)b)))) 
+               {
+               return 1;
+               }
+       return 0;
+
+       }
+
+/* ---------- Public key functions * --------------------------------------*/
+static int pub_decode_gost94(EVP_PKEY *pk, X509_PUBKEY *pub)
+       {
+       X509_ALGOR *palg = NULL;
+       const unsigned char *pubkey_buf = NULL;
+       unsigned char *databuf;
+       ASN1_OBJECT *palgobj = NULL;
+       int pub_len,i,j;
+       DSA *dsa;
+       ASN1_OCTET_STRING *octet= NULL;
+
+       if (!X509_PUBKEY_get0_param(&palgobj,&pubkey_buf,&pub_len,
+                       &palg, pub)) return 0;
+       EVP_PKEY_assign(pk,OBJ_obj2nid(palgobj),NULL);  
+       if (!decode_gost_algor_params(pk,palg)) return 0;
+       octet = d2i_ASN1_OCTET_STRING(NULL,&pubkey_buf,pub_len);
+       if (!octet) 
+               {
+               GOSTerr(GOST_F_PUB_DECODE_GOST94,ERR_R_MALLOC_FAILURE);
+               return 0;
+               }       
+       databuf = OPENSSL_malloc(octet->length);
+       for (i=0,j=octet->length-1;i<octet->length;i++,j--)
+               {
+               databuf[j]=octet->data[i];
+               }       
+       dsa = EVP_PKEY_get0(pk);
+       dsa->pub_key=BN_bin2bn(databuf,octet->length,NULL);
+       ASN1_OCTET_STRING_free(octet);
+       OPENSSL_free(databuf);
+       return 1;
+
+       }
+
+static int pub_encode_gost94(X509_PUBKEY *pub,const EVP_PKEY *pk)
+       {
+       ASN1_OBJECT *algobj = NULL;
+       ASN1_OCTET_STRING *octet = NULL;
+       void *pval = NULL;
+       unsigned char *buf=NULL,*databuf,*sptr;
+       int i,j,data_len,ret=0;
+
+       int ptype = V_ASN1_UNDEF;
+       DSA *dsa = EVP_PKEY_get0((EVP_PKEY *)pk);
+       algobj = OBJ_nid2obj(EVP_PKEY_base_id(pk));
+       if (pk->save_parameters) 
+               {
+               ASN1_STRING *params = encode_gost_algor_params(pk);
+               pval = params;
+               ptype = V_ASN1_SEQUENCE;
+               }       
+       data_len = BN_num_bytes(dsa->pub_key);
+       databuf = OPENSSL_malloc(data_len);
+       BN_bn2bin(dsa->pub_key,databuf);
+       octet = ASN1_OCTET_STRING_new();
+       ASN1_STRING_set(octet,NULL,data_len);
+       sptr = ASN1_STRING_data(octet);
+       for (i=0,j=data_len-1; i< data_len;i++,j--)
+               {
+               sptr[i]=databuf[j];
+               }
+       OPENSSL_free(databuf);
+       ret = i2d_ASN1_OCTET_STRING(octet,&buf);
+       ASN1_BIT_STRING_free(octet);
+       if (ret <0)  return 0;
+       return X509_PUBKEY_set0_param(pub,algobj,ptype,pval,buf,ret);
+       }
+
+static int pub_decode_gost01(EVP_PKEY *pk,X509_PUBKEY *pub)
+       {
+       X509_ALGOR *palg = NULL;
+       const unsigned char *pubkey_buf = NULL;
+       unsigned char *databuf;
+       ASN1_OBJECT *palgobj = NULL;
+       int pub_len,i,j;
+       EC_POINT *pub_key;
+       BIGNUM *X,*Y;
+       ASN1_OCTET_STRING *octet= NULL;
+       int len;
+       const EC_GROUP *group;
+
+       if (!X509_PUBKEY_get0_param(&palgobj,&pubkey_buf,&pub_len,
+                       &palg, pub)) return 0;
+       EVP_PKEY_assign(pk,OBJ_obj2nid(palgobj),NULL);  
+       if (!decode_gost_algor_params(pk,palg)) return 0;
+       group = EC_KEY_get0_group(EVP_PKEY_get0(pk));
+       octet = d2i_ASN1_OCTET_STRING(NULL,&pubkey_buf,pub_len);
+       if (!octet) 
+               {
+               GOSTerr(GOST_F_PUB_DECODE_GOST01,ERR_R_MALLOC_FAILURE);
+               return 0;
+               }       
+       databuf = OPENSSL_malloc(octet->length);
+       for (i=0,j=octet->length-1;i<octet->length;i++,j--)
+               {
+               databuf[j]=octet->data[i];
+               }
+       len=octet->length/2;
+       ASN1_OCTET_STRING_free(octet);  
+       
+       Y= getbnfrombuf(databuf,len);
+       X= getbnfrombuf(databuf+len,len);
+       OPENSSL_free(databuf);
+       pub_key = EC_POINT_new(group);
+       if (!EC_POINT_set_affine_coordinates_GFp(group
+                       ,pub_key,X,Y,NULL))
+               {
+               GOSTerr(GOST_F_PUB_DECODE_GOST01,
+                       ERR_R_EC_LIB);
+               EC_POINT_free(pub_key);
+               BN_free(X);
+               BN_free(Y);
+               return 0;
+               }       
+       BN_free(X);
+       BN_free(Y);
+       if (!EC_KEY_set_public_key(EVP_PKEY_get0(pk),pub_key))
+               {
+               GOSTerr(GOST_F_PUB_DECODE_GOST01,
+                       ERR_R_EC_LIB);
+               EC_POINT_free(pub_key);
+               return 0;
+               }       
+       EC_POINT_free(pub_key);
+       return 1;
+
+       }
+
+static int pub_encode_gost01(X509_PUBKEY *pub,const EVP_PKEY *pk)
+       {
+       ASN1_OBJECT *algobj = NULL;
+       ASN1_OCTET_STRING *octet = NULL;
+       void *pval = NULL;
+       unsigned char *buf=NULL,*databuf,*sptr;
+       int i,j,data_len,ret=0;
+       const EC_POINT *pub_key;
+       BIGNUM *X,*Y,*order;
+       const EC_KEY *ec = EVP_PKEY_get0((EVP_PKEY *)pk);
+       int ptype = V_ASN1_UNDEF;
+
+       algobj = OBJ_nid2obj(EVP_PKEY_base_id(pk));
+       if (pk->save_parameters) 
+               {
+               ASN1_STRING *params = encode_gost_algor_params(pk);
+               pval = params;
+               ptype = V_ASN1_SEQUENCE;
+               }
+       order = BN_new();
+       EC_GROUP_get_order(EC_KEY_get0_group(ec),order,NULL);
+       pub_key=EC_KEY_get0_public_key(ec);
+       if (!pub_key) 
+               {
+               GOSTerr(GOST_F_PUB_ENCODE_GOST01,
+                       GOST_R_PUBLIC_KEY_UNDEFINED);
+               return 0;
+               }       
+       X=BN_new();
+       Y=BN_new();
+       EC_POINT_get_affine_coordinates_GFp(EC_KEY_get0_group(ec),
+               pub_key,X,Y,NULL);
+       data_len = 2*BN_num_bytes(order);
+       BN_free(order);
+       databuf = OPENSSL_malloc(data_len);
+       memset(databuf,0,data_len);
+       
+       store_bignum(X,databuf+data_len/2,data_len/2);
+       store_bignum(Y,databuf,data_len/2);
+
+       BN_free(X);
+       BN_free(Y);
+       octet = ASN1_OCTET_STRING_new();
+       ASN1_STRING_set(octet,NULL,data_len);
+       sptr=ASN1_STRING_data(octet);
+    for (i=0,j=data_len-1;i<data_len;i++,j--) 
+               {
+        sptr[i]=databuf[j];
+               }
+    OPENSSL_free(databuf);
+       ret = i2d_ASN1_OCTET_STRING(octet,&buf);
+       ASN1_BIT_STRING_free(octet);
+       if (ret <0)  return 0;
+       return X509_PUBKEY_set0_param(pub,algobj,ptype,pval,buf,ret);
+       }
+
+static int pub_cmp_gost94(const EVP_PKEY *a, const EVP_PKEY *b)
+       {
+       const DSA *da = EVP_PKEY_get0((EVP_PKEY *)a);
+       const DSA *db = EVP_PKEY_get0((EVP_PKEY *)b);
+       if (da && db && da->pub_key && db->pub_key
+               && !BN_cmp(da->pub_key,db->pub_key)) 
+               {
+               return 1;
+               }               
+       return 0;
+       }
+
+static int pub_cmp_gost01(const EVP_PKEY *a,const EVP_PKEY *b)
+       {
+       const EC_KEY *ea = EVP_PKEY_get0((EVP_PKEY *)a);
+       const EC_KEY *eb = EVP_PKEY_get0((EVP_PKEY *)b);
+       const EC_POINT *ka,*kb;
+       int ret=0;
+       if (!ea || !eb) return 0;
+       ka = EC_KEY_get0_public_key(ea);
+       kb = EC_KEY_get0_public_key(eb);
+       if (!ka || !kb) return 0;
+       ret = (0==EC_POINT_cmp(EC_KEY_get0_group(ea),ka,kb,NULL)) ;
+       return ret;
+       }
+
+
+
+
+static int pkey_size_gost(const EVP_PKEY *pk)
+       {
+       return 64;
+       }
+
+static int pkey_bits_gost(const EVP_PKEY *pk)
+       {
+       return 256;
+       }
+/*------------------------ ASN1 METHOD for GOST MAC  -------------------*/
+static void  mackey_free_gost(EVP_PKEY *pk)
+       {
+               if (pk->pkey.ptr) {
+                       OPENSSL_free(pk->pkey.ptr);
+               }       
+       }
+static int mac_ctrl_gost(EVP_PKEY *pkey, int op, long arg1, void *arg2)
+{
+       switch (op)
+               {
+               case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
+                       *(int *)arg2 = NID_id_Gost28147_89_MAC;
+                       return 2;
+               }
+       return -2;
+}      
+
+static int gost94_param_encode(const EVP_PKEY *pkey, unsigned char **pder) 
+{
+   int nid=gost94_nid_by_params(EVP_PKEY_get0((EVP_PKEY *)pkey));
+   return i2d_ASN1_OBJECT(OBJ_nid2obj(nid),pder);
+}
+static int gost2001_param_encode(const EVP_PKEY *pkey, unsigned char **pder) 
+{
+   int nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(EVP_PKEY_get0((EVP_PKEY *)pkey)));
+   return i2d_ASN1_OBJECT(OBJ_nid2obj(nid),pder);
+}
+
+static int gost94_param_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen)
+{
+       ASN1_OBJECT *obj=NULL;
+       DSA *dsa = EVP_PKEY_get0(pkey);
+       int nid;
+       if (d2i_ASN1_OBJECT(&obj,pder,derlen)==NULL) {
+               return 0;
+       }
+       nid = OBJ_obj2nid(obj);
+       ASN1_OBJECT_free(obj);
+       if (!dsa) 
+               {
+               dsa=DSA_new();
+               if (!EVP_PKEY_assign(pkey,NID_id_GostR3410_94,dsa)) return 0;
+               }
+       if (!fill_GOST94_params(dsa,nid)) return 0;
+       return 1;
+}      
+
+static int gost2001_param_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen) {
+       ASN1_OBJECT *obj=NULL;
+       int nid;
+       EC_KEY *ec = EVP_PKEY_get0(pkey);
+       if (d2i_ASN1_OBJECT(&obj,pder,derlen)==NULL) {
+               return 0;
+       }
+       nid = OBJ_obj2nid(obj);
+       ASN1_OBJECT_free(obj);
+       if (!ec) 
+               {
+               ec = EC_KEY_new();
+               if (!EVP_PKEY_assign(pkey,NID_id_GostR3410_2001,ec)) return 0;
+               }       
+       if (!fill_GOST2001_params(ec, nid)) return 0;
+       return 1;
+}      
+
+
+
+
+
+/* ----------------------------------------------------------------------*/
+int register_ameth_gost (int nid, EVP_PKEY_ASN1_METHOD **ameth, const char* pemstr, const char* info) 
+       {
+       *ameth =        EVP_PKEY_asn1_new(nid, 
+               ASN1_PKEY_SIGPARAM_NULL, pemstr, info); 
+       if (!*ameth) return 0;
+       switch (nid) 
+               {
+               case NID_id_GostR3410_94:
+                       EVP_PKEY_asn1_set_free (*ameth, pkey_free_gost94);
+                       EVP_PKEY_asn1_set_private (*ameth, 
+                               priv_decode_gost, priv_encode_gost, 
+                               priv_print_gost94);
+
+                       EVP_PKEY_asn1_set_param (*ameth, 
+                               gost94_param_decode, gost94_param_encode,
+                               param_missing_gost94, param_copy_gost94, 
+                               param_cmp_gost94,param_print_gost94 );
+                       EVP_PKEY_asn1_set_public (*ameth,
+                               pub_decode_gost94, pub_encode_gost94,
+                               pub_cmp_gost94, pub_print_gost94,
+                               pkey_size_gost, pkey_bits_gost);
+       
+                       EVP_PKEY_asn1_set_ctrl (*ameth, pkey_ctrl_gost);
+                       break;
+               case NID_id_GostR3410_2001:
+                       EVP_PKEY_asn1_set_free (*ameth, pkey_free_gost01);
+                       EVP_PKEY_asn1_set_private (*ameth, 
+                               priv_decode_gost, priv_encode_gost, 
+                               priv_print_gost01);
+
+                       EVP_PKEY_asn1_set_param (*ameth, 
+                               gost2001_param_decode, gost2001_param_encode,
+                               param_missing_gost01, param_copy_gost01, 
+                               param_cmp_gost01, param_print_gost01);
+                       EVP_PKEY_asn1_set_public (*ameth,
+                               pub_decode_gost01, pub_encode_gost01,
+                               pub_cmp_gost01, pub_print_gost01,
+                               pkey_size_gost, pkey_bits_gost);
+       
+                       EVP_PKEY_asn1_set_ctrl (*ameth, pkey_ctrl_gost);
+                       break;
+               case NID_id_Gost28147_89_MAC:
+                       EVP_PKEY_asn1_set_free(*ameth, mackey_free_gost);
+                       EVP_PKEY_asn1_set_ctrl(*ameth,mac_ctrl_gost);   
+                       break;
+               }               
+       return 1;
+       }
diff --git a/deps/openssl/openssl/engines/ccgost/gost_asn1.c b/deps/openssl/openssl/engines/ccgost/gost_asn1.c
new file mode 100644 (file)
index 0000000..318ecfc
--- /dev/null
@@ -0,0 +1,55 @@
+/**********************************************************************
+ *                          gost_keytrans.c                           *
+ *             Copyright (c) 2005-2006 Cryptocom LTD                  *
+ *         This file is distributed under the same license as OpenSSL *
+ *                                                                    *
+ *   ASN1 structure definition for GOST key transport                 *
+ *          Requires OpenSSL 0.9.9 for compilation                    *
+ **********************************************************************/
+#include <stdio.h>
+#include <openssl/asn1t.h>
+#include <openssl/x509.h>
+#include "gost_lcl.h"
+
+ASN1_NDEF_SEQUENCE(GOST_KEY_TRANSPORT) = {
+       ASN1_SIMPLE(GOST_KEY_TRANSPORT, key_info, GOST_KEY_INFO),
+       ASN1_IMP(GOST_KEY_TRANSPORT, key_agreement_info, GOST_KEY_AGREEMENT_INFO, 0)
+} ASN1_NDEF_SEQUENCE_END(GOST_KEY_TRANSPORT)
+
+IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_TRANSPORT)
+
+ASN1_NDEF_SEQUENCE(GOST_KEY_INFO) = {
+       ASN1_SIMPLE(GOST_KEY_INFO, encrypted_key, ASN1_OCTET_STRING),
+       ASN1_SIMPLE(GOST_KEY_INFO, imit,          ASN1_OCTET_STRING)
+} ASN1_NDEF_SEQUENCE_END(GOST_KEY_INFO)
+
+IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_INFO)
+
+ASN1_NDEF_SEQUENCE(GOST_KEY_AGREEMENT_INFO) = {
+       ASN1_SIMPLE(GOST_KEY_AGREEMENT_INFO, cipher, ASN1_OBJECT),
+       ASN1_IMP_OPT(GOST_KEY_AGREEMENT_INFO, ephem_key, X509_PUBKEY, 0),
+       ASN1_SIMPLE(GOST_KEY_AGREEMENT_INFO, eph_iv, ASN1_OCTET_STRING)
+} ASN1_NDEF_SEQUENCE_END(GOST_KEY_AGREEMENT_INFO)
+
+IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_AGREEMENT_INFO)
+
+ASN1_NDEF_SEQUENCE(GOST_KEY_PARAMS) = {
+       ASN1_SIMPLE(GOST_KEY_PARAMS, key_params, ASN1_OBJECT),
+       ASN1_SIMPLE(GOST_KEY_PARAMS, hash_params, ASN1_OBJECT),
+       ASN1_OPT(GOST_KEY_PARAMS, cipher_params, ASN1_OBJECT),
+} ASN1_NDEF_SEQUENCE_END(GOST_KEY_PARAMS)
+
+IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_PARAMS)
+
+ASN1_NDEF_SEQUENCE(GOST_CIPHER_PARAMS) = {
+       ASN1_SIMPLE(GOST_CIPHER_PARAMS, iv, ASN1_OCTET_STRING),
+       ASN1_SIMPLE(GOST_CIPHER_PARAMS, enc_param_set, ASN1_OBJECT),
+} ASN1_NDEF_SEQUENCE_END(GOST_CIPHER_PARAMS)
+
+IMPLEMENT_ASN1_FUNCTIONS(GOST_CIPHER_PARAMS)
+
+ASN1_NDEF_SEQUENCE(GOST_CLIENT_KEY_EXCHANGE_PARAMS) = { /*FIXME incomplete*/
+       ASN1_SIMPLE(GOST_CLIENT_KEY_EXCHANGE_PARAMS, gkt, GOST_KEY_TRANSPORT)
+} ASN1_NDEF_SEQUENCE_END(GOST_CLIENT_KEY_EXCHANGE_PARAMS)
+
+IMPLEMENT_ASN1_FUNCTIONS(GOST_CLIENT_KEY_EXCHANGE_PARAMS)
diff --git a/deps/openssl/openssl/engines/ccgost/gost_crypt.c b/deps/openssl/openssl/engines/ccgost/gost_crypt.c
new file mode 100644 (file)
index 0000000..cde58c0
--- /dev/null
@@ -0,0 +1,617 @@
+/**********************************************************************
+ *                          gost_crypt.c                              *
+ *             Copyright (c) 2005-2006 Cryptocom LTD                  *
+ *         This file is distributed under the same license as OpenSSL *
+ *                                                                    *
+ *       OpenSSL interface to GOST 28147-89 cipher functions          *
+ *          Requires OpenSSL 0.9.9 for compilation                    *
+ **********************************************************************/
+#include <string.h>
+#include "gost89.h"
+#include <openssl/rand.h>
+#include "e_gost_err.h"
+#include "gost_lcl.h"
+static int gost_cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, 
+       const unsigned char *iv, int enc);
+static int     gost_cipher_init_cpa(EVP_CIPHER_CTX *ctx, const unsigned char *key,
+       const unsigned char *iv, int enc);
+/* Handles block of data in CFB mode */                        
+static int     gost_cipher_do_cfb(EVP_CIPHER_CTX *ctx, unsigned char *out,
+       const unsigned char *in, size_t inl);
+/* Handles block of data in CNT mode */                        
+static int     gost_cipher_do_cnt(EVP_CIPHER_CTX *ctx, unsigned char *out,
+       const unsigned char *in, size_t inl);
+/* Cleanup function */                 
+static int gost_cipher_cleanup(EVP_CIPHER_CTX *);
+/* set/get cipher parameters */
+static int gost89_set_asn1_parameters(EVP_CIPHER_CTX *ctx,ASN1_TYPE *params);
+static int gost89_get_asn1_parameters(EVP_CIPHER_CTX *ctx,ASN1_TYPE *params);
+/* Control function */
+static int gost_cipher_ctl(EVP_CIPHER_CTX *ctx,int type,int arg,void *ptr);
+
+EVP_CIPHER cipher_gost = 
+       {
+       NID_id_Gost28147_89,
+       1,/*block_size*/
+       32,/*key_size*/
+       8,/*iv_len */
+       EVP_CIPH_CFB_MODE| EVP_CIPH_NO_PADDING |
+       EVP_CIPH_CUSTOM_IV| EVP_CIPH_RAND_KEY | EVP_CIPH_ALWAYS_CALL_INIT,
+       gost_cipher_init,
+       gost_cipher_do_cfb,
+       gost_cipher_cleanup,
+       sizeof(struct ossl_gost_cipher_ctx),/* ctx_size */
+       gost89_set_asn1_parameters,
+       gost89_get_asn1_parameters,
+       gost_cipher_ctl,
+       NULL,
+       };
+
+EVP_CIPHER cipher_gost_cpacnt = 
+       {
+       NID_gost89_cnt,
+       1,/*block_size*/
+       32,/*key_size*/
+       8,/*iv_len */
+       EVP_CIPH_OFB_MODE| EVP_CIPH_NO_PADDING |
+       EVP_CIPH_CUSTOM_IV| EVP_CIPH_RAND_KEY | EVP_CIPH_ALWAYS_CALL_INIT,
+       gost_cipher_init_cpa,
+       gost_cipher_do_cnt,
+       gost_cipher_cleanup,
+       sizeof(struct ossl_gost_cipher_ctx), /* ctx_size */
+       gost89_set_asn1_parameters,
+       gost89_get_asn1_parameters,
+       gost_cipher_ctl,
+       NULL,
+       };
+
+/* Implementation of GOST 28147-89 in MAC (imitovstavka) mode */
+/* Init functions which set specific parameters */
+static int gost_imit_init_cpa(EVP_MD_CTX *ctx);
+/* process block of data */
+static int gost_imit_update(EVP_MD_CTX *ctx, const void *data, size_t count);
+/* Return computed value */
+static int gost_imit_final(EVP_MD_CTX *ctx,unsigned char *md);
+/* Copies context */
+static int gost_imit_copy(EVP_MD_CTX *to,const EVP_MD_CTX *from);
+static int gost_imit_cleanup(EVP_MD_CTX *ctx);
+/* Control function, knows how to set MAC key.*/
+static int gost_imit_ctrl(EVP_MD_CTX *ctx,int type, int arg, void *ptr);
+
+EVP_MD imit_gost_cpa =
+       {
+       NID_id_Gost28147_89_MAC,
+       NID_undef,
+       4,
+       0,
+       gost_imit_init_cpa,
+       gost_imit_update,
+       gost_imit_final,
+       gost_imit_copy,
+       gost_imit_cleanup,
+       NULL,
+       NULL,
+       {0,0,0,0,0},
+       8,
+       sizeof(struct ossl_gost_imit_ctx), 
+       gost_imit_ctrl
+       };
+
+/* 
+ * Correspondence between gost parameter OIDs and substitution blocks
+ * NID field is filed by register_gost_NID function in engine.c
+ * upon engine initialization
+ */
+
+struct gost_cipher_info gost_cipher_list[]=
+       {
+/* NID */  /* Subst block */          /* Key meshing*/
+/*{NID_id_GostR3411_94_CryptoProParamSet,&GostR3411_94_CryptoProParamSet,0},*/
+       {NID_id_Gost28147_89_cc,&GostR3411_94_CryptoProParamSet,0},
+       {NID_id_Gost28147_89_CryptoPro_A_ParamSet,&Gost28147_CryptoProParamSetA,1},
+       {NID_id_Gost28147_89_CryptoPro_B_ParamSet,&Gost28147_CryptoProParamSetB,1},
+       {NID_id_Gost28147_89_CryptoPro_C_ParamSet,&Gost28147_CryptoProParamSetC,1},
+       {NID_id_Gost28147_89_CryptoPro_D_ParamSet,&Gost28147_CryptoProParamSetD,1},
+       {NID_id_Gost28147_89_TestParamSet,&Gost28147_TestParamSet,1},
+       {NID_undef,NULL,0}
+       };      
+
+/*  get encryption parameters from crypto network settings
+       FIXME For now we use environment var CRYPT_PARAMS as place to 
+       store these settings. Actually, it is better to use engine control   command, read from configuration file to set them */
+const struct gost_cipher_info *get_encryption_params(ASN1_OBJECT *obj)
+       {
+       int nid;
+       struct gost_cipher_info *param;
+       if (!obj)
+               {
+               const char * params = get_gost_engine_param(GOST_PARAM_CRYPT_PARAMS);
+               if (!params || !strlen(params)) 
+                       return &gost_cipher_list[1];
+
+               nid = OBJ_txt2nid(params);
+               if (nid == NID_undef)
+                       {
+                       GOSTerr(GOST_F_GET_ENCRYPTION_PARAMS,
+                               GOST_R_INVALID_CIPHER_PARAM_OID);
+                       return NULL;
+                       }       
+               }
+       else
+               {
+               nid= OBJ_obj2nid(obj);
+               }
+       for (param=gost_cipher_list;param->sblock!=NULL && param->nid!=nid; 
+                param++);
+       if (!param->sblock)
+               {
+               GOSTerr(GOST_F_GET_ENCRYPTION_PARAMS,GOST_R_INVALID_CIPHER_PARAMS);
+               return NULL;
+               }       
+       return param;
+       }
+
+/* Sets cipher param from paramset NID. */
+static int gost_cipher_set_param(struct ossl_gost_cipher_ctx *c,int nid)
+       {
+       const struct gost_cipher_info *param;
+       param=get_encryption_params((nid==NID_undef?NULL:OBJ_nid2obj(nid)));
+       if (!param) return 0;
+       
+       c->paramNID = param->nid;
+       c->key_meshing=param->key_meshing;
+       c->count=0;
+       gost_init(&(c->cctx), param->sblock);
+       return 1;
+       }
+
+/* Initializes EVP_CIPHER_CTX by paramset NID */
+static int gost_cipher_init_param(EVP_CIPHER_CTX *ctx, const unsigned char *key,
+       const unsigned char *iv, int enc, int paramNID,int mode)
+       {
+       struct ossl_gost_cipher_ctx *c=ctx->cipher_data;
+       if (ctx->app_data == NULL)
+               {
+               if (!gost_cipher_set_param(c,paramNID)) return 0;
+               ctx->app_data = ctx->cipher_data;
+               }
+       if (key) gost_key(&(c->cctx),key);
+       if(iv) memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx));
+       memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx));
+       return 1;
+       }       
+
+static int gost_cipher_init_cpa(EVP_CIPHER_CTX *ctx, const unsigned char *key,
+       const unsigned char *iv, int enc)
+       {
+       struct ossl_gost_cipher_ctx *c=ctx->cipher_data;
+       gost_init(&(c->cctx),&Gost28147_CryptoProParamSetA);
+       c->key_meshing=1;
+       c->count=0;
+       if(key) gost_key(&(c->cctx),key);
+       if(iv) memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx));
+       memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx));
+       return 1;
+       }
+
+/* Initializes EVP_CIPHER_CTX with default values */
+int gost_cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
+       const unsigned char *iv, int enc)
+       {
+       return gost_cipher_init_param(ctx,key,iv,enc,NID_undef,EVP_CIPH_CFB_MODE);
+       }       
+/* Wrapper around gostcrypt function from gost89.c which perform
+ * key meshing when nesseccary 
+ */
+static void gost_crypt_mesh (void *ctx,unsigned char *iv,unsigned char *buf)
+       {
+       struct ossl_gost_cipher_ctx *c = ctx;
+       if (c->count&&c->key_meshing && c->count%1024==0)
+               {
+               cryptopro_key_meshing(&(c->cctx),iv);
+               }       
+       gostcrypt(&(c->cctx),iv,buf);
+       c->count+=8;
+       }
+
+static void gost_cnt_next (void *ctx, unsigned char *iv, unsigned char *buf)
+       {
+       struct ossl_gost_cipher_ctx *c = ctx;
+       word32 g,go;
+       unsigned char buf1[8];
+       if (c->count && c->key_meshing && c->count %1024 ==0)
+               {
+               cryptopro_key_meshing(&(c->cctx),iv);
+               }
+       if (c->count==0)
+               {
+               gostcrypt(&(c->cctx),iv,buf1);
+               }
+       else
+               {
+               memcpy(buf1,iv,8);
+               }       
+       g = buf1[0]|(buf1[1]<<8)|(buf1[2]<<16)|(buf1[3]<<24);
+       g += 0x01010101;
+       buf1[0]=(unsigned char)(g&0xff);
+       buf1[1]=(unsigned char)((g>>8)&0xff);
+       buf1[2]=(unsigned char)((g>>16)&0xff);
+       buf1[3]=(unsigned char)((g>>24)&0xff);
+       g = buf1[4]|(buf1[5]<<8)|(buf1[6]<<16)|(buf1[7]<<24);
+       go = g;
+       g += 0x01010104;
+       if (go > g)      /*  overflow*/
+               g++;
+       buf1[4]=(unsigned char)(g&0xff);
+       buf1[5]=(unsigned char)((g>>8)&0xff);
+       buf1[6]=(unsigned char)((g>>16)&0xff);
+       buf1[7]=(unsigned char)((g>>24)&0xff);
+       memcpy(iv,buf1,8);
+       gostcrypt(&(c->cctx),buf1,buf);
+       c->count +=8;
+       }
+
+/* GOST encryption in CFB mode */
+int    gost_cipher_do_cfb(EVP_CIPHER_CTX *ctx, unsigned char *out,
+       const unsigned char *in, size_t inl)
+       {
+       const unsigned char *in_ptr=in;
+       unsigned char *out_ptr=out;
+       size_t i=0;
+       size_t j=0;
+/* process partial block if any */
+       if (ctx->num) 
+               {
+               for (j=ctx->num,i=0;j<8 && i<inl;j++,i++,in_ptr++,out_ptr++) 
+                       {
+                       if (!ctx->encrypt) ctx->buf[j+8]=*in_ptr;
+                       *out_ptr=ctx->buf[j]^(*in_ptr);
+                       if (ctx->encrypt) ctx->buf[j+8]=*out_ptr;
+                       }       
+               if (j==8)
+                       {
+                       memcpy(ctx->iv,ctx->buf+8,8);
+                       ctx->num=0;
+                       }
+               else
+                       {
+                       ctx->num=j;
+                       return 1;
+                       }       
+               }       
+
+       for (;i+8<inl;i+=8,in_ptr+=8,out_ptr+=8)
+               {
+               /*block cipher current iv */
+               gost_crypt_mesh(ctx->cipher_data,ctx->iv,ctx->buf);
+               /*xor next block of input text with it and output it*/
+               /*output this block */
+               if (!ctx->encrypt) memcpy(ctx->iv,in_ptr,8);
+               for (j=0;j<8;j++)
+                       {
+                       out_ptr[j]=ctx->buf[j]^in_ptr[j];
+                       }       
+               /* Encrypt */
+               /* Next iv is next block of cipher text*/
+               if (ctx->encrypt) memcpy(ctx->iv,out_ptr,8);
+               }
+/* Process rest of buffer */
+       if (i<inl)
+               {
+               gost_crypt_mesh(ctx->cipher_data,ctx->iv,ctx->buf);
+               if (!ctx->encrypt) memcpy(ctx->buf+8,in_ptr,inl-i);
+               for (j=0;i<inl;j++,i++)
+                       {
+                       out_ptr[j]=ctx->buf[j]^in_ptr[j];
+                       }                       
+               ctx->num = j;
+               if (ctx->encrypt) memcpy(ctx->buf+8,out_ptr,j);
+               }
+       else
+               {
+               ctx->num = 0;
+               }       
+       return 1;
+       }
+
+static int gost_cipher_do_cnt(EVP_CIPHER_CTX *ctx, unsigned char *out,
+       const unsigned char *in, size_t inl)
+       {
+       const unsigned char *in_ptr=in;
+       unsigned char *out_ptr=out;
+       size_t i=0;
+       size_t j;
+/* process partial block if any */
+       if (ctx->num) 
+               {
+               for (j=ctx->num,i=0;j<8 && i<inl;j++,i++,in_ptr++,out_ptr++) 
+                       {
+                       *out_ptr=ctx->buf[j]^(*in_ptr);
+                       }       
+               if (j==8)
+                       {
+                       ctx->num=0;
+                       }
+               else
+                       {
+                       ctx->num=j;
+                       return 1;
+                       }       
+               }       
+
+       for (;i+8<inl;i+=8,in_ptr+=8,out_ptr+=8)
+               {
+               /*block cipher current iv */
+               /* Encrypt */
+               gost_cnt_next(ctx->cipher_data,ctx->iv,ctx->buf);
+               /*xor next block of input text with it and output it*/
+               /*output this block */
+               for (j=0;j<8;j++)
+                       {
+                       out_ptr[j]=ctx->buf[j]^in_ptr[j];
+                       }       
+               }
+/* Process rest of buffer */
+       if (i<inl)
+               {
+               gost_cnt_next(ctx->cipher_data,ctx->iv,ctx->buf);
+               for (j=0;i<inl;j++,i++)
+                       {
+                       out_ptr[j]=ctx->buf[j]^in_ptr[j];
+                       }                       
+               ctx->num = j;
+               }
+       else
+               {
+               ctx->num = 0;
+               }       
+       return 1;
+       }
+
+/* Cleaning up of EVP_CIPHER_CTX */
+int gost_cipher_cleanup(EVP_CIPHER_CTX *ctx) 
+       {
+       gost_destroy(&((struct ossl_gost_cipher_ctx *)ctx->cipher_data)->cctx);
+       ctx->app_data = NULL;
+       return 1;
+       }       
+
+/* Control function for gost cipher */
+int gost_cipher_ctl(EVP_CIPHER_CTX *ctx,int type,int arg,void *ptr)
+       {
+       switch (type)
+               {
+               case EVP_CTRL_RAND_KEY:
+               {
+               if (RAND_bytes((unsigned char *)ptr,ctx->key_len)<=0)
+                       {
+                       GOSTerr(GOST_F_GOST_CIPHER_CTL,GOST_R_RANDOM_GENERATOR_ERROR);
+                       return -1;
+                       }
+               break;
+               }
+               case EVP_CTRL_PBE_PRF_NID:
+                       if (ptr) {
+                               *((int *)ptr)=  NID_id_HMACGostR3411_94;
+                               return 1;
+                       } else {
+                               return 0;
+                       }       
+                               
+               default:
+                       GOSTerr(GOST_F_GOST_CIPHER_CTL,GOST_R_UNSUPPORTED_CIPHER_CTL_COMMAND);
+                       return -1;
+               }
+       return 1;
+       }
+
+/* Set cipher parameters from ASN1 structure */
+int gost89_set_asn1_parameters(EVP_CIPHER_CTX *ctx,ASN1_TYPE *params)
+       {
+       int len=0;
+       unsigned char *buf=NULL;
+       unsigned char *p=NULL;
+       struct ossl_gost_cipher_ctx *c = ctx->cipher_data;
+       GOST_CIPHER_PARAMS *gcp = GOST_CIPHER_PARAMS_new();
+       ASN1_OCTET_STRING *os = NULL;
+       if (!gcp)
+               {
+               GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, GOST_R_NO_MEMORY);
+               return 0;
+               }
+       if (!ASN1_OCTET_STRING_set(gcp->iv, ctx->iv, ctx->cipher->iv_len))
+               {
+               GOST_CIPHER_PARAMS_free(gcp);
+               GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, GOST_R_NO_MEMORY);
+               return 0;
+               }
+       ASN1_OBJECT_free(gcp->enc_param_set);
+       gcp->enc_param_set = OBJ_nid2obj(c->paramNID);
+
+       len = i2d_GOST_CIPHER_PARAMS(gcp, NULL);
+       p = buf = (unsigned char*)OPENSSL_malloc(len);
+       if (!buf)
+               {
+               GOST_CIPHER_PARAMS_free(gcp);
+               GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, GOST_R_NO_MEMORY);
+               return 0;
+               }
+       i2d_GOST_CIPHER_PARAMS(gcp, &p);
+       GOST_CIPHER_PARAMS_free(gcp);
+
+       os = ASN1_OCTET_STRING_new();
+
+       if(!os || !ASN1_OCTET_STRING_set(os, buf, len))
+               {
+               OPENSSL_free(buf);
+               GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, GOST_R_NO_MEMORY);
+               return 0;
+               }
+       OPENSSL_free(buf);
+
+       ASN1_TYPE_set(params, V_ASN1_SEQUENCE, os);
+       return 1;
+       }
+
+/* Store parameters into ASN1 structure */
+int  gost89_get_asn1_parameters(EVP_CIPHER_CTX *ctx,ASN1_TYPE *params)
+       {
+       int ret = -1;
+       int len; 
+       GOST_CIPHER_PARAMS *gcp = NULL;
+       unsigned char *p;
+       struct ossl_gost_cipher_ctx *c=ctx->cipher_data;
+       if (ASN1_TYPE_get(params) != V_ASN1_SEQUENCE)
+               {
+               return ret;
+               }
+
+       p = params->value.sequence->data;
+
+       gcp = d2i_GOST_CIPHER_PARAMS(NULL, (const unsigned char **)&p,
+               params->value.sequence->length);
+
+       len = gcp->iv->length;
+       if (len != ctx->cipher->iv_len)
+               {
+               GOST_CIPHER_PARAMS_free(gcp);
+               GOSTerr(GOST_F_GOST89_GET_ASN1_PARAMETERS,
+                       GOST_R_INVALID_IV_LENGTH);
+               return -1;
+               }
+       if (!gost_cipher_set_param(c,OBJ_obj2nid(gcp->enc_param_set)))
+               {
+               GOST_CIPHER_PARAMS_free(gcp);
+               return -1;
+               }
+       memcpy(ctx->oiv, gcp->iv->data, len);
+
+       GOST_CIPHER_PARAMS_free(gcp);
+
+       return 1;
+       }
+
+
+int gost_imit_init_cpa(EVP_MD_CTX *ctx)
+       {
+       struct ossl_gost_imit_ctx *c = ctx->md_data;
+       memset(c->buffer,0,sizeof(c->buffer));
+       memset(c->partial_block,0,sizeof(c->partial_block));
+       c->count = 0;
+       c->bytes_left=0;
+       c->key_meshing=1;
+       gost_init(&(c->cctx),&Gost28147_CryptoProParamSetA);
+       return 1;
+       }
+
+static void mac_block_mesh(struct ossl_gost_imit_ctx *c,const unsigned char *data)
+       {
+       unsigned char buffer[8];
+       /* We are using local buffer for iv because CryptoPro doesn't 
+        * interpret internal state of MAC algorithm as iv during keymeshing
+        * (but does initialize internal state from iv in key transport
+        */
+       if (c->key_meshing&& c->count && c->count %1024 ==0)
+               {
+               cryptopro_key_meshing(&(c->cctx),buffer);
+               }
+       mac_block(&(c->cctx),c->buffer,data);
+       c->count +=8;
+       }
+
+int gost_imit_update(EVP_MD_CTX *ctx, const void *data, size_t count)
+       {
+       struct ossl_gost_imit_ctx *c = ctx->md_data;
+       const unsigned char *p = data;
+       size_t bytes = count,i;
+       if (!(c->key_set)) {
+               GOSTerr(GOST_F_GOST_IMIT_UPDATE, GOST_R_MAC_KEY_NOT_SET);
+               return 0;
+       }
+       if (c->bytes_left)
+               {
+               for (i=c->bytes_left;i<8&&bytes>0;bytes--,i++,p++)
+                       {
+                       c->partial_block[i]=*p;
+                       }
+               if (i==8)
+                       {
+                       mac_block_mesh(c,c->partial_block);
+                       }
+               else
+                       {
+                       c->bytes_left = i;
+                       return 1;
+                       }               
+               }       
+       while (bytes>8)
+               {
+               mac_block_mesh(c,p);
+               p+=8;
+               bytes-=8;
+               }
+       if (bytes>0)
+               {
+               memcpy(c->partial_block,p,bytes);
+               }       
+       c->bytes_left=bytes;
+       return 1;
+       }
+
+int gost_imit_final(EVP_MD_CTX *ctx,unsigned char *md)
+       {
+       struct ossl_gost_imit_ctx *c = ctx->md_data;
+       if (!c->key_set) {
+               GOSTerr(GOST_F_GOST_IMIT_FINAL, GOST_R_MAC_KEY_NOT_SET);
+               return 0;
+       }
+       if (c->bytes_left)
+               {
+               int i;
+               for (i=c->bytes_left;i<8;i++)
+                       {
+                       c->partial_block[i]=0;
+                       }
+               mac_block_mesh(c,c->partial_block);
+               }
+       get_mac(c->buffer,32,md);
+       return 1;
+       }
+
+int gost_imit_ctrl(EVP_MD_CTX *ctx,int type, int arg, void *ptr)
+       {
+       switch (type)
+               {
+               case EVP_MD_CTRL_KEY_LEN:
+                       *((unsigned int*)(ptr)) = 32;
+                       return 1;
+               case EVP_MD_CTRL_SET_KEY:
+               {
+               if (arg!=32) {
+                       GOSTerr(GOST_F_GOST_IMIT_CTRL, GOST_R_INVALID_MAC_KEY_LENGTH);
+                       return 0;
+               }
+
+               gost_key(&(((struct ossl_gost_imit_ctx*)(ctx->md_data))->cctx),ptr)     ;
+               ((struct ossl_gost_imit_ctx*)(ctx->md_data))->key_set = 1;
+               return 1;
+
+               }
+               default:
+                       return 0;
+               }               
+       }
+
+int gost_imit_copy(EVP_MD_CTX *to,const EVP_MD_CTX *from)
+       {
+       memcpy(to->md_data,from->md_data,sizeof(struct ossl_gost_imit_ctx));
+       return 1;
+       }
+
+/* Clean up imit ctx */
+int gost_imit_cleanup(EVP_MD_CTX *ctx)
+       {
+       memset(ctx->md_data,0,sizeof(struct ossl_gost_imit_ctx));
+       return 1;
+       }
+
diff --git a/deps/openssl/openssl/engines/ccgost/gost_ctl.c b/deps/openssl/openssl/engines/ccgost/gost_ctl.c
new file mode 100644 (file)
index 0000000..d3cd171
--- /dev/null
@@ -0,0 +1,89 @@
+/**********************************************************************
+ *                        gost_ctl.c                                  *
+ *             Copyright (c) 2005-2006 Cryptocom LTD                  *
+ *       This file is distributed under the same license as OpenSSL   *
+ *                                                                    *
+ *        Implementation of control commands for GOST engine          *
+ *            OpenSSL 0.9.9 libraries required                        *
+ **********************************************************************/            
+#include <stdlib.h>
+#include <string.h>
+#include <openssl/crypto.h>
+#include <openssl/err.h>
+#include <openssl/engine.h>
+#include <openssl/buffer.h>
+#include "gost_lcl.h"
+
+static char *gost_params[GOST_PARAM_MAX+1]={NULL};
+static const char *gost_envnames[]={"CRYPT_PARAMS"};
+const ENGINE_CMD_DEFN gost_cmds[]=
+       {
+/*     { GOST_CTRL_RNG,
+       "RNG",
+       "Type of random number generator to use",
+       ENGINE_CMD_FLAG_STRING
+       },
+       { GOST_CTRL_RNG_PARAMS,
+       "RNG_PARAMS",
+       "Parameter for random number generator",
+       ENGINE_CMD_FLAG_STRING
+       },
+*/       { GOST_CTRL_CRYPT_PARAMS,
+               "CRYPT_PARAMS",
+               "OID of default GOST 28147-89 parameters",
+               ENGINE_CMD_FLAG_STRING
+                       },
+{0,NULL,NULL,0}
+       };
+
+void gost_param_free() 
+{
+       int i;
+       for (i=0;i<=GOST_PARAM_MAX;i++) 
+               if (gost_params[i]!=NULL) 
+                       {
+                       OPENSSL_free(gost_params[i]);
+                       gost_params[i]=NULL;
+                       }
+               
+}
+
+int gost_control_func(ENGINE *e,int cmd,long i, void *p, void (*f)(void))
+       {
+       int param = cmd-ENGINE_CMD_BASE;
+       int ret=0;
+       if (param <0 || param >GOST_PARAM_MAX) return -1;
+       ret=gost_set_default_param(param,p);
+       return ret;
+       }
+
+const char *get_gost_engine_param(int param) 
+       {
+       char *tmp;
+       if (param <0 || param >GOST_PARAM_MAX) return NULL;
+       if (gost_params[param]!=NULL) 
+               {
+               return gost_params[param];
+               }
+       tmp = getenv(gost_envnames[param]);
+       if (tmp) 
+               {
+               if (gost_params[param]) OPENSSL_free(gost_params[param]);
+               gost_params[param] = BUF_strdup(tmp);
+               return gost_params[param];
+               }       
+       return NULL;
+       }       
+
+int gost_set_default_param(int param, const char *value) 
+       {
+       const char *tmp;
+       if (param <0 || param >GOST_PARAM_MAX) return 0;
+       tmp = getenv(gost_envnames[param]);
+       /* if there is value in the environment, use it, else -passed string * */
+       if (!tmp) tmp=value;
+       if (gost_params[param]) OPENSSL_free(gost_params[param]);
+       gost_params[param] = BUF_strdup(tmp);
+
+       return 1;
+       }       
diff --git a/deps/openssl/openssl/engines/ccgost/gost_eng.c b/deps/openssl/openssl/engines/ccgost/gost_eng.c
new file mode 100644 (file)
index 0000000..d2cbe3b
--- /dev/null
@@ -0,0 +1,273 @@
+/**********************************************************************
+ *                          gost_eng.c                                *
+ *             Copyright (c) 2005-2006 Cryptocom LTD                  *
+ *         This file is distributed under the same license as OpenSSL *
+ *                                                                    *
+ *              Main file of GOST engine                              *
+ *       for OpenSSL                                                  *
+ *          Requires OpenSSL 0.9.9 for compilation                    *
+ **********************************************************************/
+#include <string.h>
+#include <openssl/crypto.h>
+#include <openssl/err.h>
+#include <openssl/evp.h>
+#include <openssl/engine.h>
+#include <openssl/obj_mac.h>
+#include "e_gost_err.h"
+#include "gost_lcl.h"
+static const char *engine_gost_id = "gost";
+static const char *engine_gost_name = "Reference implementation of GOST engine";
+
+/* Symmetric cipher and digest function registrar */
+
+static int gost_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
+       const int **nids, int nid);
+
+static int gost_digests(ENGINE *e, const EVP_MD **digest,
+       const int **nids, int ind);
+
+static int gost_pkey_meths (ENGINE *e, EVP_PKEY_METHOD **pmeth,
+       const int **nids, int nid);
+
+static int gost_pkey_asn1_meths (ENGINE *e, EVP_PKEY_ASN1_METHOD **ameth,
+       const int **nids, int nid);
+
+static int gost_cipher_nids[] =
+    {NID_id_Gost28147_89, NID_gost89_cnt,0};
+
+static int gost_digest_nids[] =
+       {NID_id_GostR3411_94,NID_id_Gost28147_89_MAC, 0};
+
+static int gost_pkey_meth_nids[] = 
+       {NID_id_GostR3410_94,
+        NID_id_GostR3410_2001, NID_id_Gost28147_89_MAC, 0};
+
+static EVP_PKEY_METHOD *pmeth_GostR3410_94 = NULL,
+        *pmeth_GostR3410_2001 = NULL,
+       *pmeth_Gost28147_MAC = NULL;
+
+static EVP_PKEY_ASN1_METHOD *ameth_GostR3410_94 = NULL,
+       *ameth_GostR3410_2001 = NULL,
+       *ameth_Gost28147_MAC = NULL;
+
+
+static int gost_engine_init(ENGINE *e)
+       { 
+       return 1;
+       }
+
+static int gost_engine_finish(ENGINE *e)
+       { 
+       return 1;
+       }
+
+static int gost_engine_destroy(ENGINE *e)
+       { 
+       gost_param_free();
+       return 1;
+       }
+
+static int bind_gost (ENGINE *e,const char *id) 
+       {
+       int ret = 0;
+       if (id && strcmp(id, engine_gost_id)) return 0;
+
+       if (!ENGINE_set_id(e, engine_gost_id)) 
+               {
+               printf("ENGINE_set_id failed\n"); 
+               goto end;
+               }       
+       if (!ENGINE_set_name(e, engine_gost_name)) 
+               {
+               printf("ENGINE_set_name failed\n");
+               goto end;
+               }       
+       if (!ENGINE_set_digests(e, gost_digests)) 
+               {
+               printf("ENGINE_set_digests failed\n");
+               goto end;
+               }       
+       if (! ENGINE_set_ciphers(e, gost_ciphers)) 
+               {
+               printf("ENGINE_set_ciphers failed\n");
+               goto end;
+               }       
+       if (! ENGINE_set_pkey_meths(e, gost_pkey_meths)) 
+               {
+               printf("ENGINE_set_pkey_meths failed\n");
+               goto end;
+               }       
+       if (! ENGINE_set_pkey_asn1_meths(e, gost_pkey_asn1_meths)) 
+               {
+               printf("ENGINE_set_pkey_asn1_meths failed\n");
+               goto end;
+               }       
+       /* Control function and commands */
+       if (!ENGINE_set_cmd_defns(e,gost_cmds)) 
+               {
+               fprintf(stderr,"ENGINE_set_cmd_defns failed\n");
+               goto end;
+               }       
+       if (!ENGINE_set_ctrl_function(e,gost_control_func)) 
+               {
+               fprintf(stderr,"ENGINE_set_ctrl_func failed\n");
+               goto end;
+               }       
+       if ( ! ENGINE_set_destroy_function(e, gost_engine_destroy)
+               || ! ENGINE_set_init_function(e,gost_engine_init)
+               || ! ENGINE_set_finish_function(e,gost_engine_finish))
+               {
+               goto end;
+               }
+
+       if (!register_ameth_gost(NID_id_GostR3410_94, &ameth_GostR3410_94, "GOST94", "GOST R 34.10-94")) goto end;
+       if (!register_ameth_gost(NID_id_GostR3410_2001, &ameth_GostR3410_2001, "GOST2001", "GOST R 34.10-2001")) goto end;
+       if (!register_ameth_gost(NID_id_Gost28147_89_MAC, &ameth_Gost28147_MAC,
+               "GOST-MAC", "GOST 28147-89 MAC")) goto end;
+
+       if (!register_pmeth_gost(NID_id_GostR3410_94, &pmeth_GostR3410_94, 0)) goto end;
+       if (!register_pmeth_gost(NID_id_GostR3410_2001, &pmeth_GostR3410_2001, 0)) goto end;
+       if (!register_pmeth_gost(NID_id_Gost28147_89_MAC, &pmeth_Gost28147_MAC, 0))
+               goto end;
+       if ( ! ENGINE_register_ciphers(e)
+               || ! ENGINE_register_digests(e)
+               || ! ENGINE_register_pkey_meths(e)
+               /* These two actually should go in LIST_ADD command */
+               || ! EVP_add_cipher(&cipher_gost)
+               || ! EVP_add_cipher(&cipher_gost_cpacnt)
+               || ! EVP_add_digest(&digest_gost)
+               || ! EVP_add_digest(&imit_gost_cpa)
+               )
+               {
+               goto end;
+               }
+
+       ERR_load_GOST_strings();
+       ret = 1;
+       end:
+       return ret;
+       }       
+
+#ifndef OPENSSL_NO_DYNAMIC_ENGINE
+IMPLEMENT_DYNAMIC_BIND_FN(bind_gost)
+IMPLEMENT_DYNAMIC_CHECK_FN()
+#endif  /* ndef OPENSSL_NO_DYNAMIC_ENGINE */
+
+static int gost_digests(ENGINE *e, const EVP_MD **digest,
+       const int **nids, int nid)
+       { 
+       int ok =1 ;
+       if (!digest) 
+               {
+               *nids = gost_digest_nids;
+               return 2; 
+               }
+       /*printf("Digest no %d requested\n",nid);*/
+       if(nid == NID_id_GostR3411_94) 
+               {
+               *digest = &digest_gost;
+               }
+       else if (nid == NID_id_Gost28147_89_MAC) 
+               {
+               *digest = &imit_gost_cpa;
+               }
+       else
+               {
+               ok =0;
+               *digest = NULL;
+               }
+       return ok;
+       }       
+       
+static int gost_ciphers (ENGINE *e,const EVP_CIPHER **cipher,
+       const int **nids, int nid) 
+       {
+       int ok = 1;
+       if (!cipher) 
+               {
+               *nids = gost_cipher_nids;
+               return 2; /* two ciphers are supported */
+               }
+
+       if(nid == NID_id_Gost28147_89) 
+               {
+               *cipher = &cipher_gost;
+               }
+       else if  (nid == NID_gost89_cnt) 
+               {
+               *cipher = &cipher_gost_cpacnt;
+               }
+       else    
+               {
+               ok = 0;
+               *cipher = NULL;
+               }
+       return ok;
+       }       
+
+static int gost_pkey_meths (ENGINE *e, EVP_PKEY_METHOD **pmeth,
+       const int **nids, int nid)
+       {
+       if (!pmeth) 
+               {
+               *nids = gost_pkey_meth_nids;
+               return 3;
+               }
+
+       switch (nid) 
+               {
+               case NID_id_GostR3410_94: *pmeth = pmeth_GostR3410_94; return 1;
+               case NID_id_GostR3410_2001: *pmeth = pmeth_GostR3410_2001; return 1;
+               case NID_id_Gost28147_89_MAC: *pmeth = pmeth_Gost28147_MAC; return 1;
+               default:;
+               }
+       
+       *pmeth = NULL;
+       return 0;
+       }
+
+static int gost_pkey_asn1_meths (ENGINE *e, EVP_PKEY_ASN1_METHOD **ameth,
+       const int **nids, int nid)
+       {
+       if (!ameth) 
+               {
+               *nids = gost_pkey_meth_nids;
+               return 3;
+               }
+       switch (nid) 
+               {
+               case NID_id_GostR3410_94: *ameth = ameth_GostR3410_94; return 1;
+               case NID_id_GostR3410_2001: *ameth = ameth_GostR3410_2001; return 1;
+               case NID_id_Gost28147_89_MAC: *ameth = ameth_Gost28147_MAC; return 1;
+       
+               default:;
+               }
+       
+       *ameth = NULL;
+       return 0;
+       }
+
+#ifdef OPENSSL_NO_DYNAMIC_ENGINE
+static ENGINE *engine_gost(void)
+       {       
+       ENGINE *ret = ENGINE_new();
+       if (!ret)
+               return NULL;
+       if (!bind_gost(ret,engine_gost_id)) 
+               {
+               ENGINE_free(ret);
+               return NULL;
+               }
+       return ret;
+       }
+       
+void ENGINE_load_gost(void)
+       {
+       ENGINE *toadd =engine_gost();
+       if (!toadd) return;
+       ENGINE_add(toadd);
+       ENGINE_free(toadd);
+       ERR_clear_error();
+       }
+#endif 
+
diff --git a/deps/openssl/openssl/engines/ccgost/gost_keywrap.c b/deps/openssl/openssl/engines/ccgost/gost_keywrap.c
new file mode 100644 (file)
index 0000000..c618f6d
--- /dev/null
@@ -0,0 +1,109 @@
+/**********************************************************************
+ *                          keywrap.c                                 *
+ *             Copyright (c) 2005-2006 Cryptocom LTD                  *
+ *         This file is distributed under the same license as OpenSSL *
+ *                                                                    *
+ * Implementation of CryptoPro key wrap algorithm, as defined in      *
+ *               RFC 4357 p 6.3 and 6.4                               *
+ *                  Doesn't need OpenSSL                              *
+ **********************************************************************/
+#include <string.h>
+#include "gost89.h"
+#include "gost_keywrap.h"
+
+/* Diversifies key using random UserKey Material
+ * Implements RFC 4357 p 6.5 key diversification algorithm 
+ * 
+ * inputKey - 32byte key to be diversified
+ * ukm - 8byte user key material
+ * outputKey - 32byte buffer to store diversified key 
+ *
+ */
+void keyDiversifyCryptoPro(gost_ctx *ctx,const unsigned char *inputKey, const unsigned char *ukm, unsigned char *outputKey)
+       {
+
+       u4 k,s1,s2;
+       int i,j,mask;
+       unsigned char S[8];
+       memcpy(outputKey,inputKey,32);
+       for (i=0;i<8;i++) 
+               {
+               /* Make array of integers from key */
+               /* Compute IV S*/
+               s1=0,s2=0;
+               for (j=0,mask=1;j<8;j++,mask<<=1) 
+                       {
+                       k=((u4)outputKey[4*j])|(outputKey[4*j+1]<<8)|
+                               (outputKey[4*j+2]<<16)|(outputKey[4*j+3]<<24);
+                       if (mask & ukm[i]) 
+                               {
+                               s1+=k;
+                               }
+                       else 
+                               {
+                               s2+=k;
+                               }
+                       }
+               S[0]=(unsigned char)(s1&0xff);
+               S[1]=(unsigned char)((s1>>8)&0xff);
+               S[2]=(unsigned char)((s1>>16)&0xff);
+               S[3]=(unsigned char)((s1>>24)&0xff); 
+               S[4]=(unsigned char)(s2&0xff);
+               S[5]=(unsigned char)((s2>>8)&0xff);
+               S[6]=(unsigned char)((s2>>16)&0xff);
+               S[7]=(unsigned char)((s2>>24)&0xff); 
+               gost_key(ctx,outputKey);
+               gost_enc_cfb(ctx,S,outputKey,outputKey,4);
+               }
+       }       
+       
+
+/*
+ * Wraps key using RFC 4357 6.3
+ * ctx - gost encryption context, initialized with some S-boxes 
+ * keyExchangeKey (KEK) 32-byte (256-bit) shared key
+ * ukm - 8 byte (64 bit) user key material, 
+ * sessionKey - 32-byte (256-bit) key to be wrapped
+ * wrappedKey - 44-byte buffer to store wrapped key
+ */ 
+
+int keyWrapCryptoPro(gost_ctx *ctx,const unsigned char *keyExchangeKey, const unsigned char *ukm,
+       const   unsigned char *sessionKey, unsigned char *wrappedKey) 
+       {
+       unsigned char kek_ukm[32];
+       keyDiversifyCryptoPro(ctx,keyExchangeKey,ukm,kek_ukm);
+       gost_key(ctx,kek_ukm);
+       memcpy(wrappedKey,ukm,8);
+       gost_enc(ctx,sessionKey,wrappedKey+8,4);
+       gost_mac_iv(ctx,32,ukm,sessionKey,32,wrappedKey+40);
+       return 1;
+       }
+/*
+ * Unwraps key using RFC 4357 6.4
+ * ctx - gost encryption context, initialized with some S-boxes 
+ * keyExchangeKey 32-byte shared key
+ * wrappedKey  44 byte key to be unwrapped (concatenation of 8-byte UKM,
+ * 32 byte  encrypted key and 4 byte MAC  
+ * 
+ * sessionKEy - 32byte buffer to store sessionKey in
+ * Returns 1 if key is decrypted successfully, and 0 if MAC doesn't match
+ */ 
+
+int keyUnwrapCryptoPro(gost_ctx *ctx,const unsigned char *keyExchangeKey,
+       const unsigned char *wrappedKey, unsigned char *sessionKey) 
+       {
+       unsigned char kek_ukm[32],cek_mac[4];
+       keyDiversifyCryptoPro(ctx,keyExchangeKey,wrappedKey 
+               /* First 8 bytes of wrapped Key is ukm */
+               ,kek_ukm);
+       gost_key(ctx,kek_ukm);
+       gost_dec(ctx,wrappedKey+8,sessionKey,4);
+       gost_mac_iv(ctx,32,wrappedKey,sessionKey,32,cek_mac);
+       if (memcmp(cek_mac,wrappedKey+40,4)) 
+               {
+               return 0;
+               }               
+       return 1;               
+       }       
+
+
diff --git a/deps/openssl/openssl/engines/ccgost/gost_keywrap.h b/deps/openssl/openssl/engines/ccgost/gost_keywrap.h
new file mode 100644 (file)
index 0000000..37c2a0f
--- /dev/null
@@ -0,0 +1,56 @@
+/**********************************************************************
+ *                         gost_keywrap.h                             *
+ *             Copyright (c) 2005-2006 Cryptocom LTD                  *
+ *       This file is distributed under the same license as OpenSSL   *
+ *                                                                    *
+ * Implementation of CryptoPro key wrap algorithm, as defined in      *
+ * RFC 4357 p 6.3 and 6.4                                             *
+ * Doesn't need OpenSSL                                               *
+ **********************************************************************/
+#ifndef GOST_KEYWRAP_H
+#define GOST_KEYWRAP_H
+#include <string.h>
+#include "gost89.h"
+/* Diversifies key using random UserKey Material
+ * Implements RFC 4357 p 6.5 key diversification algorithm 
+ * 
+ * inputKey - 32byte key to be diversified
+ * ukm - 8byte user key material
+ * outputKey - 32byte buffer to store diversified key 
+ *
+ */
+void keyDiversifyCryptoPro(gost_ctx *ctx,
+       const unsigned char *inputKey, 
+       const unsigned char *ukm, 
+       unsigned char *outputKey);
+/*
+ * Wraps key using RFC 4357 6.3
+ * ctx - gost encryption context, initialized with some S-boxes 
+ * keyExchangeKey (KEK) 32-byte (256-bit) shared key
+ * ukm - 8 byte (64 bit) user key material, 
+ * sessionKey - 32-byte (256-bit) key to be wrapped
+ * wrappedKey - 44-byte buffer to store wrapped key
+ */ 
+
+int keyWrapCryptoPro(gost_ctx *ctx,
+       const unsigned char *keyExchangeKey, 
+       const unsigned char *ukm,
+       const   unsigned char *sessionKey, 
+       unsigned char *wrappedKey) ;
+/*
+ * Unwraps key using RFC 4357 6.4
+ * ctx - gost encryption context, initialized with some S-boxes 
+ * keyExchangeKey 32-byte shared key
+ * wrappedKey  44 byte key to be unwrapped (concatenation of 8-byte UKM,
+ * 32 byte  encrypted key and 4 byte MAC  
+ * 
+ * sessionKEy - 32byte buffer to store sessionKey in
+ * Returns 1 if key is decrypted successfully, and 0 if MAC doesn't match
+ */ 
+
+
+int keyUnwrapCryptoPro(gost_ctx *ctx,
+       const unsigned char *keyExchangeKey,
+       const unsigned char *wrappedKey, 
+       unsigned char *sessionKey) ;
+#endif
diff --git a/deps/openssl/openssl/engines/ccgost/gost_lcl.h b/deps/openssl/openssl/engines/ccgost/gost_lcl.h
new file mode 100644 (file)
index 0000000..437a48c
--- /dev/null
@@ -0,0 +1,218 @@
+#ifndef GOST_TOOLS_H
+#define GOST_TOOLS_H
+/**********************************************************************
+ *                        gost_lcl.h                                  *
+ *             Copyright (c) 2006 Cryptocom LTD                       *
+ *       This file is distributed under the same license as OpenSSL   *
+ *                                                                    *
+ *         Internal declarations  used in GOST engine                *
+ *         OpenSSL 0.9.9 libraries required to compile and use        *
+ *                              this code                             *
+ **********************************************************************/ 
+#include <openssl/bn.h>
+#include <openssl/evp.h>
+#include <openssl/dsa.h>
+#include <openssl/asn1t.h>
+#include <openssl/x509.h>
+#include <openssl/engine.h>
+#include <openssl/ec.h>
+#include "gost89.h"
+#include "gosthash.h"
+/* Control commands */
+#define GOST_PARAM_CRYPT_PARAMS 0
+#define GOST_PARAM_MAX 0
+#define GOST_CTRL_CRYPT_PARAMS (ENGINE_CMD_BASE+GOST_PARAM_CRYPT_PARAMS)
+
+       extern const ENGINE_CMD_DEFN gost_cmds[];
+       int gost_control_func(ENGINE *e,int cmd, long i, void *p, void (*f)(void));
+       const char *get_gost_engine_param(int param);   
+       int gost_set_default_param(int param, const char *value); 
+       void gost_param_free(void);
+
+/* method registration */
+
+       int register_ameth_gost (int nid, EVP_PKEY_ASN1_METHOD **ameth, const char* pemstr, const char* info);
+       int register_pmeth_gost (int id, EVP_PKEY_METHOD **pmeth, int flags);
+
+/* Gost-specific pmeth control-function parameters */
+/* For GOST R34.10 parameters */
+#define param_ctrl_string "paramset"
+#define EVP_PKEY_CTRL_GOST_PARAMSET (EVP_PKEY_ALG_CTRL+1)
+/* For GOST 28147 MAC */
+#define key_ctrl_string "key"
+#define hexkey_ctrl_string "hexkey"
+#define EVP_PKEY_CTRL_GOST_MAC_HEXKEY (EVP_PKEY_ALG_CTRL+3)
+/* Pmeth internal representation */
+       struct gost_pmeth_data {
+           int sign_param_nid; /* Should be set whenever parameters are filled */
+               EVP_MD *md;
+               unsigned char *shared_ukm;
+               int peer_key_used;
+       };
+
+       struct gost_mac_pmeth_data {
+               int key_set;
+               EVP_MD *md;
+               unsigned char key[32];
+       }       ;
+/* GOST-specific ASN1 structures */
+
+
+typedef struct {
+       ASN1_OCTET_STRING *encrypted_key;
+       ASN1_OCTET_STRING *imit;
+} GOST_KEY_INFO;
+
+DECLARE_ASN1_FUNCTIONS(GOST_KEY_INFO)
+
+typedef struct {
+       ASN1_OBJECT *cipher;
+       X509_PUBKEY *ephem_key;
+       ASN1_OCTET_STRING *eph_iv;
+} GOST_KEY_AGREEMENT_INFO;
+
+DECLARE_ASN1_FUNCTIONS(GOST_KEY_AGREEMENT_INFO)
+       
+typedef struct {
+       GOST_KEY_INFO *key_info;
+       GOST_KEY_AGREEMENT_INFO *key_agreement_info;
+} GOST_KEY_TRANSPORT;
+
+DECLARE_ASN1_FUNCTIONS(GOST_KEY_TRANSPORT)
+
+typedef struct { /* FIXME incomplete */
+       GOST_KEY_TRANSPORT *gkt;
+} GOST_CLIENT_KEY_EXCHANGE_PARAMS;
+
+/* Hacks to shorten symbols to 31 characters or less, or OpenVMS.
+   This mimics what's done in symhacks.h, but since this is a very
+   local header file, I prefered to put this hack directly here.
+   -- Richard Levitte */
+#ifdef OPENSSL_SYS_VMS
+#undef GOST_CLIENT_KEY_EXCHANGE_PARAMS_it
+#define GOST_CLIENT_KEY_EXCHANGE_PARAMS_it     GOST_CLIENT_KEY_EXC_PARAMS_it
+#undef GOST_CLIENT_KEY_EXCHANGE_PARAMS_new
+#define GOST_CLIENT_KEY_EXCHANGE_PARAMS_new    GOST_CLIENT_KEY_EXC_PARAMS_new
+#undef GOST_CLIENT_KEY_EXCHANGE_PARAMS_free
+#define GOST_CLIENT_KEY_EXCHANGE_PARAMS_free   GOST_CLIENT_KEY_EXC_PARAMS_free
+#undef d2i_GOST_CLIENT_KEY_EXCHANGE_PARAMS
+#define d2i_GOST_CLIENT_KEY_EXCHANGE_PARAMS    d2i_GOST_CLIENT_KEY_EXC_PARAMS
+#undef i2d_GOST_CLIENT_KEY_EXCHANGE_PARAMS
+#define i2d_GOST_CLIENT_KEY_EXCHANGE_PARAMS    i2d_GOST_CLIENT_KEY_EXC_PARAMS
+#endif /* End of hack */
+DECLARE_ASN1_FUNCTIONS(GOST_CLIENT_KEY_EXCHANGE_PARAMS)
+typedef struct {
+       ASN1_OBJECT *key_params;
+       ASN1_OBJECT *hash_params;
+       ASN1_OBJECT *cipher_params;
+} GOST_KEY_PARAMS;
+
+DECLARE_ASN1_FUNCTIONS(GOST_KEY_PARAMS)
+
+typedef struct {
+       ASN1_OCTET_STRING *iv;
+       ASN1_OBJECT *enc_param_set;
+} GOST_CIPHER_PARAMS; 
+
+DECLARE_ASN1_FUNCTIONS(GOST_CIPHER_PARAMS)
+/*============== Message digest  and cipher related structures  ==========*/
+        /* Structure used as EVP_MD_CTX-md_data. 
+         * It allows to avoid storing in the md-data pointers to
+         * dynamically allocated memory.
+         *
+         * I cannot invent better way to avoid memory leaks, because
+         * openssl insist on invoking Init on Final-ed digests, and there
+         * is no reliable way to find out whether pointer in the passed
+         * md_data is valid or not.
+         * */
+struct ossl_gost_digest_ctx {
+       gost_hash_ctx dctx;
+       gost_ctx cctx;
+};     
+/* EVP_MD structure for GOST R 34.11 */
+extern EVP_MD digest_gost;
+/* EVP_MD structure for GOST 28147 in MAC mode */
+extern EVP_MD imit_gost_cpa;
+/* Cipher context used for EVP_CIPHER operation */
+struct ossl_gost_cipher_ctx {
+       int paramNID;
+       off_t count;
+       int key_meshing;
+       gost_ctx cctx;
+};     
+/* Structure to map parameter NID to S-block */
+struct gost_cipher_info {
+       int nid;
+       gost_subst_block *sblock;
+       int key_meshing;
+};
+/* Context for MAC */
+struct ossl_gost_imit_ctx {
+       gost_ctx cctx;
+       unsigned char buffer[8];
+       unsigned char partial_block[8];
+       off_t count;
+       int key_meshing;
+       int bytes_left;
+       int key_set;
+};     
+/* Table which maps parameter NID to S-blocks */
+extern struct gost_cipher_info gost_cipher_list[];
+/* Find encryption params from ASN1_OBJECT */
+const struct gost_cipher_info *get_encryption_params(ASN1_OBJECT *obj);
+/* Implementation of GOST 28147-89 cipher in CFB and CNT modes */
+extern EVP_CIPHER cipher_gost;
+extern EVP_CIPHER cipher_gost_cpacnt;
+#define EVP_MD_CTRL_KEY_LEN (EVP_MD_CTRL_ALG_CTRL+3)
+#define EVP_MD_CTRL_SET_KEY (EVP_MD_CTRL_ALG_CTRL+4)
+/* EVP_PKEY_METHOD key encryption callbacks */
+/* From gost94_keyx.c */
+int pkey_GOST94cp_encrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, const unsigned char* key, size_t key_len );
+
+int pkey_GOST94cp_decrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, const unsigned char* in, size_t in_len );
+/* From gost2001_keyx.c */
+int pkey_GOST01cp_encrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, const unsigned char* key, size_t key_len );
+
+int pkey_GOST01cp_decrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, const unsigned char* in, size_t in_len );
+/* derive functions */
+/* From gost2001_keyx.c */
+int pkey_gost2001_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen);
+/* From gost94_keyx.c */
+int pkey_gost94_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen);
+/* Internal functions for signature algorithms */
+int fill_GOST94_params(DSA *dsa,int nid);
+int fill_GOST2001_params(EC_KEY *eckey, int nid);
+int gost_sign_keygen(DSA *dsa) ;
+int gost2001_keygen(EC_KEY *ec) ;
+
+DSA_SIG *gost_do_sign(const unsigned char *dgst,int dlen, DSA *dsa) ;
+DSA_SIG *gost2001_do_sign(const unsigned char *dgst,int dlen, EC_KEY *eckey);
+
+int gost_do_verify(const unsigned char *dgst, int dgst_len,
+               DSA_SIG *sig, DSA *dsa) ;
+int gost2001_do_verify(const unsigned char *dgst,int dgst_len,
+                       DSA_SIG *sig, EC_KEY *ec);
+int gost2001_compute_public(EC_KEY *ec) ;
+int gost94_compute_public(DSA *dsa) ;
+/*============== miscellaneous functions============================= */
+/* from gost_sign.c */
+/* Convert GOST R 34.11 hash sum to bignum according to standard */
+BIGNUM *hashsum2bn(const unsigned char *dgst) ;
+/* Store bignum in byte array of given length, prepending by zeros
+ * if nesseccary */
+int store_bignum(BIGNUM *bn, unsigned char *buf,int len);
+/* Read bignum, which can have few MSB all-zeros    from buffer*/ 
+BIGNUM *getbnfrombuf(const unsigned char *buf,size_t len);
+/* Pack GOST R 34.10 signature according to CryptoPro rules */
+int pack_sign_cp(DSA_SIG *s,int order,unsigned char *sig, size_t *siglen); 
+/* Unpack GOST R 34.10 signature according to CryptoPro rules */
+DSA_SIG *unpack_cp_signature(const unsigned char *sig,size_t siglen) ;
+/* from ameth.c */
+/* Get private key as BIGNUM from both R 34.10-94 and R 34.10-2001  keys*/
+/* Returns pointer into EVP_PKEY structure */
+BIGNUM* gost_get0_priv_key(const EVP_PKEY *pkey) ;
+/* Find NID by GOST 94 parameters */
+int gost94_nid_by_params(DSA *p) ;
+
+
+#endif
diff --git a/deps/openssl/openssl/engines/ccgost/gost_md.c b/deps/openssl/openssl/engines/ccgost/gost_md.c
new file mode 100644 (file)
index 0000000..417e108
--- /dev/null
@@ -0,0 +1,75 @@
+/**********************************************************************
+ *                          md_gost.c                                 *
+ *             Copyright (c) 2005-2006 Cryptocom LTD                  *
+ *         This file is distributed under the same license as OpenSSL *
+ *                                                                    *
+ *       OpenSSL interface to GOST R 34.11-94 hash functions          *
+ *          Requires OpenSSL 0.9.9 for compilation                    *
+ **********************************************************************/
+#include <string.h>
+#include "gost_lcl.h"
+#include "gosthash.h"
+#include "e_gost_err.h"
+
+/* implementation of GOST 34.11 hash function See gost_md.c*/
+static int gost_digest_init(EVP_MD_CTX *ctx);
+static int gost_digest_update(EVP_MD_CTX *ctx, const void *data, size_t count);
+static int gost_digest_final(EVP_MD_CTX *ctx,unsigned char *md);
+static int gost_digest_copy(EVP_MD_CTX *to,const EVP_MD_CTX *from);
+static int gost_digest_cleanup(EVP_MD_CTX *ctx);
+
+EVP_MD digest_gost=  
+       {
+       NID_id_GostR3411_94,
+       NID_undef,
+       32,
+       EVP_MD_FLAG_PKEY_METHOD_SIGNATURE,
+       gost_digest_init,
+       gost_digest_update,
+       gost_digest_final,
+       gost_digest_copy,
+       gost_digest_cleanup,
+       NULL,
+       NULL,
+       {NID_undef,NID_undef,0,0,0},
+       32,
+       sizeof(struct ossl_gost_digest_ctx ),
+       NULL
+       };
+
+int gost_digest_init(EVP_MD_CTX *ctx) 
+       {
+       struct ossl_gost_digest_ctx *c = ctx->md_data;
+       memset(&(c->dctx),0,sizeof(gost_hash_ctx));
+       gost_init(&(c->cctx),&GostR3411_94_CryptoProParamSet);
+       c->dctx.cipher_ctx= &(c->cctx);
+       return 1;
+       }
+
+int gost_digest_update(EVP_MD_CTX *ctx,const void *data,size_t count) 
+       {
+       return hash_block((gost_hash_ctx *)ctx->md_data,data,count);    
+       }
+
+int gost_digest_final(EVP_MD_CTX *ctx,unsigned char *md)
+       {
+       return finish_hash((gost_hash_ctx *)ctx->md_data,md);
+       
+       }
+
+int gost_digest_copy(EVP_MD_CTX *to,const EVP_MD_CTX *from) 
+       {
+       struct ossl_gost_digest_ctx *md_ctx=to->md_data;
+       if (to->md_data && from->md_data) {
+               memcpy(to->md_data,from->md_data,sizeof(struct ossl_gost_digest_ctx));
+               md_ctx->dctx.cipher_ctx=&(md_ctx->cctx);
+       }
+       return 1;
+       }               
+
+int gost_digest_cleanup(EVP_MD_CTX *ctx) 
+       {
+       if (ctx->md_data)
+       memset(ctx->md_data,0,sizeof(struct ossl_gost_digest_ctx));
+       return 1;
+       }       
diff --git a/deps/openssl/openssl/engines/ccgost/gost_params.c b/deps/openssl/openssl/engines/ccgost/gost_params.c
new file mode 100644 (file)
index 0000000..40fc343
--- /dev/null
@@ -0,0 +1,198 @@
+/**********************************************************************
+ *                        params.c                                    *
+ *             Copyright (c) 2005-2006 Cryptocom LTD                  *
+ *         This file is distributed under the same license as OpenSSL *
+ *                                                                    *
+ * Definitions of GOST R 34.10 parameter sets, defined in RFC 4357    *
+ *         OpenSSL 0.9.9 libraries required to compile and use        *
+ *                              this code                             *
+ **********************************************************************/ 
+#include "gost_params.h"
+#include <openssl/objects.h>
+/* Parameters of GOST 34.10 */
+
+R3410_params R3410_paramset[]={
+/* Paramset A */
+{NID_id_GostR3410_94_CryptoPro_A_ParamSet,
+"100997906755055304772081815535925224869"
+"8410825720534578748235158755771479905292727772441528526992987964833"
+"5669968284202797289605274717317548059048560713474685214192868091256"
+"1502802222185647539190902656116367847270145019066794290930185446216"
+"3997308722217328898303231940973554032134009725883228768509467406639"
+"62",
+"127021248288932417465907042777176443525"
+"7876535089165358128175072657050312609850984974231883334834011809259"
+"9999512098893413065920561499672425412104927434935707492031276956145"
+"1689224110579311248812610229678534638401693520013288995000362260684"
+"2227508135323070045173416336850045410625869714168836867788425378203"
+"83",
+"683631961449557007844441656118272528951"
+"02170888761442055095051287550314083023"},
+{NID_id_GostR3410_94_CryptoPro_B_ParamSet,
+"429418261486158041438734477379555023926"
+"7234596860714306679811299408947123142002706038521669956384871995765"
+"7284814898909770759462613437669456364882730370838934791080835932647"
+"9767786019153434744009610342313166725786869204821949328786333602033"
+"8479709268434224762105576023501613261478065276102850944540333865234"
+"1",
+"139454871199115825601409655107690713107"
+"0417070599280317977580014543757653577229840941243685222882398330391"
+"1468164807668823692122073732267216074074777170091113455043205380464"
+"7694904686120113087816240740184800477047157336662926249423571248823"
+"9685422217536601433914856808405203368594584948031873412885804895251"
+"63",
+"79885141663410976897627118935756323747307951916507639758300472692338873533959"
+},
+{NID_id_GostR3410_94_CryptoPro_C_ParamSet,
+"816552717970881016017893191415300348226"
+"2544051353358162468249467681876621283478212884286545844013955142622"
+"2087723485023722868022275009502224827866201744494021697716482008353"
+"6398202298024892620480898699335508064332313529725332208819456895108"
+"5155178100221003459370588291073071186553005962149936840737128710832"
+"3",
+"110624679233511963040518952417017040248"
+"5862954819831383774196396298584395948970608956170224210628525560327"
+"8638246716655439297654402921844747893079518669992827880792192992701"
+"1428546551433875806377110443534293554066712653034996277099320715774"
+"3542287621283671843703709141350171945045805050291770503634517804938"
+"01",
+"113468861199819350564868233378875198043"
+"267947776488510997961231672532899549103"
+},
+{NID_id_GostR3410_94_CryptoPro_D_ParamSet,
+"756976611021707301782128757801610628085"
+"5283803109571158829574281419208532589041660017017859858216341400371"
+"4687551412794400562878935266630754392677014598582103365983119173924"
+"4732511225464712252386803315902707727668715343476086350472025298282"
+"7271461690125050616858238384366331089777463541013033926723743254833"
+"7",
+"905457649621929965904290958774625315611"
+"3056083907389766971404812524422262512556054474620855996091570786713"
+"5849550236741915584185990627801066465809510095784713989819413820871"
+"5964648914493053407920737078890520482730623038837767710173664838239"
+"8574828787891286471201460474326612697849693665518073864436497893214"
+"9",
+"108988435796353506912374591498972192620"
+"190487557619582334771735390599299211593"
+},
+
+{NID_id_GostR3410_94_CryptoPro_XchA_ParamSet,
+"1335318132727206734338595199483190012179423759678474868994823595993"
+"6964252873471246159040332773182141032801252925387191478859899310331"
+"0567744136196364803064721377826656898686468463277710150809401182608"
+"7702016153249904683329312949209127762411378780302243557466062839716"
+"59376426832674269780880061631528163475887",
+"14201174159756348119636828602231808974327613839524373876287257344192"
+"74593935127189736311660784676003608489466235676257952827747192122419"
+"29071046134208380636394084512691828894000571524625445295769349356752"
+"72895683154177544176313938445719175509684710784659566254794231229333"
+"8483924514339614727760681880609734239",
+"91771529896554605945588149018382750217296858393520724172743325725474"
+"374979801"
+},
+{NID_id_GostR3410_94_CryptoPro_XchB_ParamSet,
+"8890864727828423151699995801875757891031463338652579140051973659"
+"3048131440685857067369829407947744496306656291505503608252399443"
+"7900272386749145996230867832228661977543992816745254823298629859"
+"8753575466286051738837854736167685769017780335804511440773337196"
+"2538423532919394477873664752824509986617878992443177",
+"1028946126624994859676552074360530315217970499989304888248413244"
+"8474923022758470167998871003604670704877377286176171227694098633"
+"1539089568784129110109512690503345393869871295783467257264868341"
+"7200196629860561193666752429682367397084815179752036423595736533"
+"68957392061769855284593965042530895046088067160269433",
+"9109671391802626916582318050603555673628769498182593088388796888"
+"5281641595199"
+},
+{NID_id_GostR3410_94_CryptoPro_XchC_ParamSet,
+"4430618464297584182473135030809859326863990650118941756995270074"
+"8609973181426950235239623239110557450826919295792878938752101867"
+"7047181623251027516953100431855964837602657827828194249605561893"
+"6965865325513137194483136247773653468410118796740709840825496997"
+"9375560722345106704721086025979309968763193072908334",
+"1246996366993477513607147265794064436203408861395055989217248455"
+"7299870737698999651480662364723992859320868822848751165438350943"
+"3276647222625940615560580450040947211826027729977563540237169063"
+"0448079715771649447778447000597419032457722226253269698374446528"
+"35352729304393746106576383349151001715930924115499549",
+"6787876137336591234380295020065682527118129468050147943114675429"
+"4748422492761"
+},
+
+
+{NID_undef,NULL, NULL, NULL}
+};
+       
+R3410_2001_params R3410_2001_paramset[]={
+       /* default_cc_sign01_param 1.2.643.2.9.1.8.1 */
+       {NID_id_GostR3410_2001_ParamSet_cc,
+       /* A */ 
+       "C0000000000000000000000000000000000000000000000000000000000003c4",
+       /* B */
+       "2d06B4265ebc749ff7d0f1f1f88232e81632e9088fd44b7787d5e407e955080c",
+       /* P */
+       "C0000000000000000000000000000000000000000000000000000000000003C7",
+       /* Q */
+       "5fffffffffffffffffffffffffffffff606117a2f4bde428b7458a54b6e87b85",
+       /* X */
+       "2",
+       /* Y */
+       "a20e034bf8813ef5c18d01105e726a17eb248b264ae9706f440bedc8ccb6b22c"
+       },
+       /* 1.2.643.2.2.35.0 */
+       {NID_id_GostR3410_2001_TestParamSet,
+       "7",
+       "5FBFF498AA938CE739B8E022FBAFEF40563F6E6A3472FC2A514C0CE9DAE23B7E",
+       "8000000000000000000000000000000000000000000000000000000000000431",
+       "8000000000000000000000000000000150FE8A1892976154C59CFC193ACCF5B3",
+       "2",
+       "08E2A8A0E65147D4BD6316030E16D19C85C97F0A9CA267122B96ABBCEA7E8FC8"
+       },
+       /*1.2.643.2.2.35.1*/
+       {NID_id_GostR3410_2001_CryptoPro_A_ParamSet,
+       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD94",
+       "a6",
+       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD97",
+       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6C611070995AD10045841B09B761B893",
+       "1",
+       "8D91E471E0989CDA27DF505A453F2B7635294F2DDF23E3B122ACC99C9E9F1E14"
+       },
+       /*1.2.643.2.2.35.2*/
+       {NID_id_GostR3410_2001_CryptoPro_B_ParamSet,    
+       "8000000000000000000000000000000000000000000000000000000000000C96",
+       "3E1AF419A269A5F866A7D3C25C3DF80AE979259373FF2B182F49D4CE7E1BBC8B",
+       "8000000000000000000000000000000000000000000000000000000000000C99",
+       "800000000000000000000000000000015F700CFFF1A624E5E497161BCC8A198F",
+       "1",    
+       "3FA8124359F96680B83D1C3EB2C070E5C545C9858D03ECFB744BF8D717717EFC"
+       },
+       /*1.2.643.2.2.35.3*/
+       {NID_id_GostR3410_2001_CryptoPro_C_ParamSet,
+       "9B9F605F5A858107AB1EC85E6B41C8AACF846E86789051D37998F7B9022D7598",
+       "805a",
+       "9B9F605F5A858107AB1EC85E6B41C8AACF846E86789051D37998F7B9022D759B",
+       "9B9F605F5A858107AB1EC85E6B41C8AA582CA3511EDDFB74F02F3A6598980BB9",
+       "0",
+       "41ECE55743711A8C3CBF3783CD08C0EE4D4DC440D4641A8F366E550DFDB3BB67"
+       },
+       /*1.2.643.2.2.36.0*/
+       {NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet,
+       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD94",
+       "a6",
+       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD97",
+       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6C611070995AD10045841B09B761B893",
+       "1",
+       "8D91E471E0989CDA27DF505A453F2B7635294F2DDF23E3B122ACC99C9E9F1E14"
+       },
+       /*1.2.643.2.2.36.1*/
+       {NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet,
+       "9B9F605F5A858107AB1EC85E6B41C8AACF846E86789051D37998F7B9022D7598",
+       "805a",
+       "9B9F605F5A858107AB1EC85E6B41C8AACF846E86789051D37998F7B9022D759B",
+       "9B9F605F5A858107AB1EC85E6B41C8AA582CA3511EDDFB74F02F3A6598980BB9",
+       "0",
+       "41ECE55743711A8C3CBF3783CD08C0EE4D4DC440D4641A8F366E550DFDB3BB67"
+       },
+       { 0,NULL,NULL,NULL,NULL,NULL,NULL
+       }
+};
diff --git a/deps/openssl/openssl/engines/ccgost/gost_params.h b/deps/openssl/openssl/engines/ccgost/gost_params.h
new file mode 100644 (file)
index 0000000..4c3f556
--- /dev/null
@@ -0,0 +1,34 @@
+/**********************************************************************
+ *                        gost_params.h                               *
+ *             Copyright (c) 2005-2006 Cryptocom LTD                  *
+ *       This file is distributed under the same license as OpenSSL   *
+ *                                                                    *
+ *       Declaration of structures used to represent  GOST R 34.10    *
+ *                    parameter sets, defined in RFC 4357                *
+ *         OpenSSL 0.9.9 libraries required to compile and use        *
+ *                              this code                             *
+ **********************************************************************/ 
+#ifndef GOST_PARAMSET_H
+#define GOST_PARAMSET_H
+typedef struct R3410 {
+               int nid;
+               char *a;
+               char *p;
+               char *q;
+} R3410_params;
+
+extern R3410_params R3410_paramset[];
+
+typedef struct R3410_2001 {
+               int nid;
+               char *a;
+               char *b;
+               char *p;
+               char *q;
+               char *x;
+               char *y;
+} R3410_2001_params;
+
+extern R3410_2001_params R3410_2001_paramset[];
+
+#endif
diff --git a/deps/openssl/openssl/engines/ccgost/gost_pmeth.c b/deps/openssl/openssl/engines/ccgost/gost_pmeth.c
new file mode 100644 (file)
index 0000000..caaea99
--- /dev/null
@@ -0,0 +1,621 @@
+/**********************************************************************
+ *                          gost_pmeth.c                              *
+ *             Copyright (c) 2005-2006 Cryptocom LTD                  *
+ *         This file is distributed under the same license as OpenSSL *
+ *                                                                    *
+ *   Implementation of RFC 4357 (GOST R 34.10) Publick key method     *
+ *       for OpenSSL                                                  *
+ *          Requires OpenSSL 0.9.9 for compilation                    *
+ **********************************************************************/
+#include <openssl/evp.h>
+#include <openssl/objects.h>
+#include <openssl/ec.h>
+#include <openssl/x509v3.h> /*For string_to_hex */
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include "gost_params.h"
+#include "gost_lcl.h"
+#include "e_gost_err.h"
+/*-------init, cleanup, copy - uniform for all algs  ---------------*/
+/* Allocates new gost_pmeth_data structure and assigns it as data */
+static int pkey_gost_init(EVP_PKEY_CTX *ctx)
+       {
+       struct gost_pmeth_data *data;
+       EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
+       data = OPENSSL_malloc(sizeof(struct gost_pmeth_data));
+       if (!data) return 0;
+       memset(data,0,sizeof(struct gost_pmeth_data));
+       if (pkey && EVP_PKEY_get0(pkey)) 
+               {
+               switch (EVP_PKEY_base_id(pkey)) {
+               case NID_id_GostR3410_94:
+                 data->sign_param_nid = gost94_nid_by_params(EVP_PKEY_get0(pkey));
+                 break;
+               case NID_id_GostR3410_2001:
+                  data->sign_param_nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(EVP_PKEY_get0((EVP_PKEY *)pkey)));
+               break;
+               default:
+                       return 0;
+               }         
+               }
+       EVP_PKEY_CTX_set_data(ctx,data);
+       return 1;
+       }
+
+/* Copies contents of gost_pmeth_data structure */
+static int pkey_gost_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
+       {
+       struct gost_pmeth_data *dst_data,*src_data;
+       if (!pkey_gost_init(dst))
+               {
+               return 0;
+               }
+       src_data = EVP_PKEY_CTX_get_data(src);
+       dst_data = EVP_PKEY_CTX_get_data(dst);
+       *dst_data = *src_data;
+       if (src_data -> shared_ukm) {
+               dst_data->shared_ukm=NULL;
+       }       
+       return 1;
+       }
+
+/* Frees up gost_pmeth_data structure */
+static void pkey_gost_cleanup (EVP_PKEY_CTX *ctx)
+       {
+       struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
+       if (data->shared_ukm) OPENSSL_free(data->shared_ukm);
+       OPENSSL_free(data);
+       }       
+
+/* --------------------- control functions  ------------------------------*/
+static int pkey_gost_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
+       {
+       struct gost_pmeth_data *pctx = (struct gost_pmeth_data*)EVP_PKEY_CTX_get_data(ctx);
+       switch (type)
+               {
+               case EVP_PKEY_CTRL_MD:
+               {
+               if (EVP_MD_type((const EVP_MD *)p2) != NID_id_GostR3411_94)
+                       {
+                       GOSTerr(GOST_F_PKEY_GOST_CTRL, GOST_R_INVALID_DIGEST_TYPE);
+                       return 0;
+                       }
+               pctx->md = (EVP_MD *)p2;
+               return 1;
+               }
+               break;
+
+               case EVP_PKEY_CTRL_PKCS7_ENCRYPT:
+               case EVP_PKEY_CTRL_PKCS7_DECRYPT:
+               case EVP_PKEY_CTRL_PKCS7_SIGN:
+                       return 1;
+
+               case EVP_PKEY_CTRL_GOST_PARAMSET:
+                       pctx->sign_param_nid = (int)p1;
+                       return 1;
+               case EVP_PKEY_CTRL_SET_IV:
+                       pctx->shared_ukm=OPENSSL_malloc((int)p1);
+                       memcpy(pctx->shared_ukm,p2,(int) p1);
+                       return 1;
+               case EVP_PKEY_CTRL_PEER_KEY:
+                       if (p1 == 0 || p1 == 1) /* call from EVP_PKEY_derive_set_peer */
+                               return 1;
+                       if (p1 == 2)            /* TLS: peer key used? */
+                               return pctx->peer_key_used;
+                       if (p1 == 3)            /* TLS: peer key used! */
+                               return (pctx->peer_key_used = 1);
+                       return -2;
+               }
+       return -2;
+       }
+
+
+static int pkey_gost_ctrl94_str(EVP_PKEY_CTX *ctx,
+       const char *type, const char *value)
+       {
+       int param_nid=0;
+       if(!strcmp(type, param_ctrl_string))
+               {
+               if (!value)
+                       {
+                       return 0;
+                       }
+               if (strlen(value) == 1)
+                       {
+                       switch(toupper(value[0]))
+                               {
+                               case 'A':
+                                       param_nid = NID_id_GostR3410_94_CryptoPro_A_ParamSet;
+                                       break;
+                               case 'B':
+                                       param_nid = NID_id_GostR3410_94_CryptoPro_B_ParamSet;
+                                       break;
+                               case 'C':
+                                       param_nid = NID_id_GostR3410_94_CryptoPro_C_ParamSet;
+                                       break;
+                               case 'D':
+                                       param_nid = NID_id_GostR3410_94_CryptoPro_D_ParamSet;
+                                       break;
+                               default:
+                                       return 0;
+                                       break;
+                               }
+                       }
+               else if ((strlen(value) == 2) && (toupper(value[0]) == 'X'))
+                       {
+                       switch (toupper(value[1]))
+                               {
+                               case 'A':
+                                       param_nid = NID_id_GostR3410_94_CryptoPro_XchA_ParamSet;
+                                       break;
+                               case 'B':
+                                       param_nid = NID_id_GostR3410_94_CryptoPro_XchB_ParamSet;
+                                       break;
+                               case 'C':
+                                       param_nid = NID_id_GostR3410_94_CryptoPro_XchC_ParamSet;
+                                       break;
+                               default:
+                                       return 0;
+                                       break;
+                               }
+                       }
+               else
+                       {
+                       R3410_params *p = R3410_paramset;
+                       param_nid = OBJ_txt2nid(value);
+                       if (param_nid == NID_undef)
+                               {
+                               return 0;
+                               }
+                       for (;p->nid != NID_undef;p++)
+                               {
+                               if (p->nid == param_nid) break;
+                               }
+                       if (p->nid == NID_undef)
+                               {
+                               GOSTerr(GOST_F_PKEY_GOST_CTRL94_STR,
+                                       GOST_R_INVALID_PARAMSET);
+                               return 0;
+                               }
+                       }
+
+               return pkey_gost_ctrl(ctx, EVP_PKEY_CTRL_GOST_PARAMSET,
+                       param_nid, NULL);
+               }
+       return -2;
+       }
+
+static int pkey_gost_ctrl01_str(EVP_PKEY_CTX *ctx,
+       const char *type, const char *value)
+       {
+       int param_nid=0;
+       if(!strcmp(type, param_ctrl_string))
+               {
+               if (!value)
+                       {
+                       return 0;
+                       }
+               if (strlen(value) == 1)
+                       {
+                       switch(toupper(value[0]))
+                               {
+                               case 'A':
+                                       param_nid = NID_id_GostR3410_2001_CryptoPro_A_ParamSet;
+                                       break;  
+                               case 'B':
+                                       param_nid = NID_id_GostR3410_2001_CryptoPro_B_ParamSet;
+                                       break;
+                               case 'C':
+                                       param_nid = NID_id_GostR3410_2001_CryptoPro_C_ParamSet;
+                                       break;
+                               case '0':
+                                       param_nid = NID_id_GostR3410_2001_TestParamSet;
+                                       break;
+                               default:
+                                       return 0;
+                                       break;
+                               }
+                       }
+               else if ((strlen(value) == 2) && (toupper(value[0]) == 'X'))
+                       {
+                       switch (toupper(value[1]))
+                               {
+                               case 'A':
+                                       param_nid = NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet;
+                                       break;
+                               case 'B':
+                                       param_nid = NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet;
+                                       break;
+                               default:
+                                       return 0;
+                                       break;
+                               }
+                       }
+               else
+                       {
+                       R3410_2001_params *p = R3410_2001_paramset;
+                       param_nid = OBJ_txt2nid(value);
+                       if (param_nid == NID_undef)
+                               {
+                               return 0;
+                               }
+                       for (;p->nid != NID_undef;p++)
+                               {
+                               if (p->nid == param_nid) break;
+                               }
+                       if (p->nid == NID_undef)
+                               {
+                               GOSTerr(GOST_F_PKEY_GOST_CTRL01_STR,
+                                       GOST_R_INVALID_PARAMSET);
+                               return 0;
+                               }
+                       }
+
+               return pkey_gost_ctrl(ctx, EVP_PKEY_CTRL_GOST_PARAMSET,
+                       param_nid, NULL);
+               }
+       return -2;
+       }
+
+/* --------------------- key generation  --------------------------------*/
+
+static int pkey_gost_paramgen_init(EVP_PKEY_CTX *ctx) {
+       return 1;
+}      
+static int pkey_gost94_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) 
+       {
+       struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
+       DSA *dsa=NULL;
+       if (data->sign_param_nid == NID_undef)
+               {
+                       GOSTerr(GOST_F_PKEY_GOST94_PARAMGEN,
+                               GOST_R_NO_PARAMETERS_SET);
+                       return 0;
+               }
+       dsa = DSA_new();
+       if (!fill_GOST94_params(dsa,data->sign_param_nid))
+               {
+               DSA_free(dsa);
+               return 0;
+               }
+       EVP_PKEY_assign(pkey,NID_id_GostR3410_94,dsa);
+       return 1;
+       }
+static int pkey_gost01_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
+       {
+       struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
+       EC_KEY *ec=NULL;
+
+       if (data->sign_param_nid == NID_undef)
+               {
+                       GOSTerr(GOST_F_PKEY_GOST01_PARAMGEN,
+                               GOST_R_NO_PARAMETERS_SET);
+                       return 0;
+               }
+       if (!ec)        
+               ec = EC_KEY_new();
+       if (!fill_GOST2001_params(ec,data->sign_param_nid))
+               {
+               EC_KEY_free(ec);
+               return 0;
+               }
+       EVP_PKEY_assign(pkey,NID_id_GostR3410_2001,ec);
+       return 1;
+       }
+
+/* Generates Gost_R3410_94_cp key */
+static int pkey_gost94cp_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
+       {
+       DSA *dsa;
+       if (!pkey_gost94_paramgen(ctx,pkey)) return 0;
+       dsa = EVP_PKEY_get0(pkey);
+       gost_sign_keygen(dsa);
+       return 1;
+       }
+
+/* Generates GOST_R3410 2001 key and assigns it using specified type */
+static int pkey_gost01cp_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
+       {
+       EC_KEY *ec;
+    if (!pkey_gost01_paramgen(ctx,pkey)) return 0;
+       ec = EVP_PKEY_get0(pkey);
+       gost2001_keygen(ec);
+       return 1;
+       }
+
+
+
+/* ----------- sign callbacks --------------------------------------*/
+
+static int pkey_gost94_cp_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
+       const unsigned char *tbs, size_t tbs_len)
+       {
+       DSA_SIG *unpacked_sig=NULL;
+       EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
+       if (!siglen) return 0;
+       if (!sig)
+               {
+               *siglen= 64; /* better to check size of pkey->pkey.dsa-q */
+               return 1;
+               }       
+       unpacked_sig = gost_do_sign(tbs,tbs_len,EVP_PKEY_get0(pkey));
+       if (!unpacked_sig)
+               {
+               return 0;
+               }
+       return pack_sign_cp(unpacked_sig,32,sig,siglen);
+       }
+
+static int pkey_gost01_cp_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
+       const unsigned char *tbs, size_t tbs_len)
+       {
+       DSA_SIG *unpacked_sig=NULL;
+       EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
+       if (!siglen) return 0;
+       if (!sig)
+               {
+               *siglen= 64; /* better to check size of curve order*/
+               return 1;
+               }       
+       unpacked_sig = gost2001_do_sign(tbs,tbs_len,EVP_PKEY_get0(pkey));
+       if (!unpacked_sig)
+               {
+               return 0;
+               }
+       return pack_sign_cp(unpacked_sig,32,sig,siglen);
+       }
+
+/* ------------------- verify callbacks ---------------------------*/
+
+static int pkey_gost94_cp_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig,
+       size_t siglen, const unsigned char *tbs, size_t tbs_len)
+       {
+       int ok = 0;
+       EVP_PKEY* pub_key = EVP_PKEY_CTX_get0_pkey(ctx);
+       DSA_SIG *s=unpack_cp_signature(sig,siglen);
+       if (!s) return 0;
+       if (pub_key) ok = gost_do_verify(tbs,tbs_len,s,EVP_PKEY_get0(pub_key));
+       DSA_SIG_free(s);
+       return ok;
+       }
+
+
+static int pkey_gost01_cp_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig,
+       size_t siglen, const unsigned char *tbs, size_t tbs_len)
+       {
+       int ok = 0;
+       EVP_PKEY* pub_key = EVP_PKEY_CTX_get0_pkey(ctx);
+       DSA_SIG *s=unpack_cp_signature(sig,siglen);
+       if (!s) return 0;
+#ifdef DEBUG_SIGN      
+       fprintf(stderr,"R=");
+       BN_print_fp(stderr,s->r);
+       fprintf(stderr,"\nS=");
+       BN_print_fp(stderr,s->s);
+       fprintf(stderr,"\n");
+#endif 
+       if (pub_key) ok = gost2001_do_verify(tbs,tbs_len,s,EVP_PKEY_get0(pub_key));
+       DSA_SIG_free(s);
+       return ok;
+       }
+
+/* ------------- encrypt init -------------------------------------*/
+/* Generates ephermeral key */
+static int pkey_gost_encrypt_init(EVP_PKEY_CTX *ctx)
+       {
+       return 1;
+       }
+/* --------------- Derive init ------------------------------------*/
+static int pkey_gost_derive_init(EVP_PKEY_CTX *ctx)
+{
+       return 1;
+}
+/* -------- PKEY_METHOD for GOST MAC algorithm --------------------*/
+static int pkey_gost_mac_init(EVP_PKEY_CTX *ctx)
+       {
+       struct gost_mac_pmeth_data *data;
+       data = OPENSSL_malloc(sizeof(struct gost_mac_pmeth_data));
+       if (!data) return 0;
+       memset(data,0,sizeof(struct gost_mac_pmeth_data));
+       EVP_PKEY_CTX_set_data(ctx,data);
+       return 1;
+       }       
+static void pkey_gost_mac_cleanup (EVP_PKEY_CTX *ctx)
+       {
+       struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
+       OPENSSL_free(data);
+       }       
+static int pkey_gost_mac_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
+       {
+       struct gost_mac_pmeth_data *dst_data,*src_data;
+       if (!pkey_gost_mac_init(dst))
+               {
+               return 0;
+               }
+       src_data = EVP_PKEY_CTX_get_data(src);
+       dst_data = EVP_PKEY_CTX_get_data(dst);
+       *dst_data = *src_data;
+       return 1;
+       }
+       
+static int pkey_gost_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
+       {
+       struct gost_mac_pmeth_data *data =
+(struct gost_mac_pmeth_data*)EVP_PKEY_CTX_get_data(ctx);
+
+       switch (type)
+               {
+               case EVP_PKEY_CTRL_MD:
+               {
+               if (EVP_MD_type((const EVP_MD *)p2) != NID_id_Gost28147_89_MAC)
+                       {
+                       GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, GOST_R_INVALID_DIGEST_TYPE);
+                       return 0;
+                       }
+               data->md = (EVP_MD *)p2;
+               return 1;
+               }
+               break;
+
+               case EVP_PKEY_CTRL_PKCS7_ENCRYPT:
+               case EVP_PKEY_CTRL_PKCS7_DECRYPT:
+               case EVP_PKEY_CTRL_PKCS7_SIGN:
+                       return 1;
+               case EVP_PKEY_CTRL_SET_MAC_KEY:
+                       if (p1 != 32) 
+                               {
+                               GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL,
+                                       GOST_R_INVALID_MAC_KEY_LENGTH);
+                               return 0;
+                               }
+
+                       memcpy(data->key,p2,32);
+                       data->key_set = 1;
+                       return 1;
+               case EVP_PKEY_CTRL_DIGESTINIT:
+                       { 
+                       EVP_MD_CTX *mctx = p2;
+                       void *key;
+                       if (!data->key_set)
+                               { 
+                               EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
+                               if (!pkey) 
+                                       {
+                                       GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL,GOST_R_MAC_KEY_NOT_SET);
+                                       return 0;
+                                       }
+                               key = EVP_PKEY_get0(pkey);
+                               if (!key) 
+                                       {
+                                       GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL,GOST_R_MAC_KEY_NOT_SET);
+                                       return 0;
+                                       }
+                               } else {
+                               key = &(data->key);
+                               }
+                       return mctx->digest->md_ctrl(mctx,EVP_MD_CTRL_SET_KEY,32,key);
+                       }  
+               }       
+       return -2;
+       }
+static int pkey_gost_mac_ctrl_str(EVP_PKEY_CTX *ctx,
+       const char *type, const char *value)
+       {
+       if (!strcmp(type, key_ctrl_string)) 
+               {
+               if (strlen(value)!=32) 
+                       {
+                       GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR,
+                               GOST_R_INVALID_MAC_KEY_LENGTH);
+                       return 0;       
+                       }
+               return pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY,
+                       32,(char *)value);
+               }
+       if (!strcmp(type, hexkey_ctrl_string)) 
+               {
+                       long keylen; int ret;
+                       unsigned char *keybuf=string_to_hex(value,&keylen);
+                       if (keylen != 32) 
+                               {
+                               GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR,
+                                       GOST_R_INVALID_MAC_KEY_LENGTH);
+                               return 0;       
+                               }
+                       ret= pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY,
+                               32,keybuf);
+                       OPENSSL_free(keybuf);
+                       return ret;
+       
+               }
+       return -2;
+       }       
+
+static int pkey_gost_mac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
+       {
+               struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
+               unsigned char *keydata;
+               if (!data->key_set) 
+               {
+                       GOSTerr(GOST_F_PKEY_GOST_MAC_KEYGEN,GOST_R_MAC_KEY_NOT_SET);
+                       return 0;
+               }
+               keydata = OPENSSL_malloc(32);
+               memcpy(keydata,data->key,32);
+               EVP_PKEY_assign(pkey, NID_id_Gost28147_89_MAC, keydata);
+               return 1;
+       }
+
+static int pkey_gost_mac_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)
+       {
+       return 1;
+}
+
+static int pkey_gost_mac_signctx(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, EVP_MD_CTX *mctx)
+       {
+               unsigned int tmpsiglen=*siglen; /* for platforms where sizeof(int)!=sizeof(size_t)*/
+               int ret;
+               if (!sig) 
+                       {
+                       *siglen = 4;
+                       return 1;
+                       }
+               ret=EVP_DigestFinal_ex(mctx,sig,&tmpsiglen);
+               *siglen = tmpsiglen;
+               return ret;
+       }
+/* ----------------------------------------------------------------*/
+int register_pmeth_gost(int id, EVP_PKEY_METHOD **pmeth,int flags)
+       {
+       *pmeth = EVP_PKEY_meth_new(id, flags);
+       if (!*pmeth) return 0;
+
+       switch (id)
+               {
+               case NID_id_GostR3410_94:
+                       EVP_PKEY_meth_set_ctrl(*pmeth,pkey_gost_ctrl, pkey_gost_ctrl94_str);
+                       EVP_PKEY_meth_set_keygen(*pmeth,NULL,pkey_gost94cp_keygen);
+                       EVP_PKEY_meth_set_sign(*pmeth, NULL, pkey_gost94_cp_sign);
+                       EVP_PKEY_meth_set_verify(*pmeth, NULL, pkey_gost94_cp_verify);
+                       EVP_PKEY_meth_set_encrypt(*pmeth,
+                               pkey_gost_encrypt_init, pkey_GOST94cp_encrypt);
+                       EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_GOST94cp_decrypt);
+                       EVP_PKEY_meth_set_derive(*pmeth,
+                               pkey_gost_derive_init, pkey_gost94_derive);
+                       EVP_PKEY_meth_set_paramgen(*pmeth, pkey_gost_paramgen_init,pkey_gost94_paramgen);       
+                       break;
+               case NID_id_GostR3410_2001:
+                       EVP_PKEY_meth_set_ctrl(*pmeth,pkey_gost_ctrl, pkey_gost_ctrl01_str);
+                       EVP_PKEY_meth_set_sign(*pmeth, NULL, pkey_gost01_cp_sign);
+                       EVP_PKEY_meth_set_verify(*pmeth, NULL, pkey_gost01_cp_verify);
+
+                       EVP_PKEY_meth_set_keygen(*pmeth, NULL, pkey_gost01cp_keygen);
+
+                       EVP_PKEY_meth_set_encrypt(*pmeth,
+                               pkey_gost_encrypt_init, pkey_GOST01cp_encrypt);
+                       EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_GOST01cp_decrypt);
+                       EVP_PKEY_meth_set_derive(*pmeth,
+                               pkey_gost_derive_init, pkey_gost2001_derive);
+                       EVP_PKEY_meth_set_paramgen(*pmeth, pkey_gost_paramgen_init,pkey_gost01_paramgen);       
+                       break;
+               case NID_id_Gost28147_89_MAC:
+                       EVP_PKEY_meth_set_ctrl(*pmeth,pkey_gost_mac_ctrl, pkey_gost_mac_ctrl_str);
+                       EVP_PKEY_meth_set_signctx(*pmeth,pkey_gost_mac_signctx_init, pkey_gost_mac_signctx);
+                       EVP_PKEY_meth_set_keygen(*pmeth,NULL, pkey_gost_mac_keygen);
+                       EVP_PKEY_meth_set_init(*pmeth,pkey_gost_mac_init);
+                       EVP_PKEY_meth_set_cleanup(*pmeth,pkey_gost_mac_cleanup);
+                       EVP_PKEY_meth_set_copy(*pmeth,pkey_gost_mac_copy);
+                       return 1;
+               default: /*Unsupported method*/
+                       return 0;
+               }
+       EVP_PKEY_meth_set_init(*pmeth, pkey_gost_init);
+       EVP_PKEY_meth_set_cleanup(*pmeth, pkey_gost_cleanup);
+
+       EVP_PKEY_meth_set_copy(*pmeth, pkey_gost_copy);
+       /*FIXME derive etc...*/
+       
+       return 1;
+       }
+
diff --git a/deps/openssl/openssl/engines/ccgost/gost_sign.c b/deps/openssl/openssl/engines/ccgost/gost_sign.c
new file mode 100644 (file)
index 0000000..4095654
--- /dev/null
@@ -0,0 +1,321 @@
+/**********************************************************************
+ *                          gost_sign.c                               *
+ *             Copyright (c) 2005-2006 Cryptocom LTD                  *
+ *         This file is distributed under the same license as OpenSSL *
+ *                                                                    *
+ *       Implementation of GOST R 34.10-94 signature algorithm        *
+ *       for OpenSSL                                                  *
+ *          Requires OpenSSL 0.9.9 for compilation                    *
+ **********************************************************************/
+#include <string.h>
+#include <openssl/rand.h>
+#include <openssl/bn.h>
+#include <openssl/dsa.h>
+#include <openssl/evp.h>
+
+#include "gost_params.h"
+#include "gost_lcl.h"
+#include "e_gost_err.h"
+
+#ifdef DEBUG_SIGN
+void dump_signature(const char *message,const unsigned char *buffer,size_t len)
+       {
+       size_t i;
+       fprintf(stderr,"signature %s Length=%d",message,len);
+       for (i=0; i<len; i++)
+               {
+               if (i% 16 ==0) fputc('\n',stderr);
+               fprintf (stderr," %02x",buffer[i]);
+               }
+       fprintf(stderr,"\nEnd of signature\n");
+       }
+
+void dump_dsa_sig(const char *message, DSA_SIG *sig)
+       {
+       fprintf(stderr,"%s\nR=",message);
+       BN_print_fp(stderr,sig->r);
+       fprintf(stderr,"\nS=");
+       BN_print_fp(stderr,sig->s);
+       fprintf(stderr,"\n");
+       }
+
+#else
+
+#define dump_signature(a,b,c)
+#define dump_dsa_sig(a,b)
+#endif
+
+/*
+ * Computes signature and returns it as DSA_SIG structure
+ */
+DSA_SIG *gost_do_sign(const unsigned char *dgst,int dlen, DSA *dsa)
+       {
+       BIGNUM *k=NULL,*tmp=NULL,*tmp2=NULL;
+       DSA_SIG *newsig = DSA_SIG_new();
+       BIGNUM *md = hashsum2bn(dgst);
+       /* check if H(M) mod q is zero */
+       BN_CTX *ctx=BN_CTX_new();
+       BN_CTX_start(ctx);
+       if (!newsig)
+               {
+               GOSTerr(GOST_F_GOST_DO_SIGN,GOST_R_NO_MEMORY);
+               goto err;
+               }       
+       tmp=BN_CTX_get(ctx);
+       k = BN_CTX_get(ctx);
+       tmp2 = BN_CTX_get(ctx);
+       BN_mod(tmp,md,dsa->q,ctx);
+       if (BN_is_zero(tmp))
+               {
+               BN_one(md);
+               }       
+       do
+               {
+               do
+                       {
+                       /*Generate random number k less than q*/
+                       BN_rand_range(k,dsa->q);
+                       /* generate r = (a^x mod p) mod q */
+                       BN_mod_exp(tmp,dsa->g, k, dsa->p,ctx);
+                       if (!(newsig->r)) newsig->r=BN_new();
+                       BN_mod(newsig->r,tmp,dsa->q,ctx);
+                       }
+               while (BN_is_zero(newsig->r));
+               /* generate s = (xr + k(Hm)) mod q */
+               BN_mod_mul(tmp,dsa->priv_key,newsig->r,dsa->q,ctx);
+               BN_mod_mul(tmp2,k,md,dsa->q,ctx);
+               if (!newsig->s) newsig->s=BN_new();
+               BN_mod_add(newsig->s,tmp,tmp2,dsa->q,ctx);
+               }
+       while (BN_is_zero(newsig->s));          
+       err:
+       BN_free(md);
+       BN_CTX_end(ctx);
+       BN_CTX_free(ctx);
+       return newsig;
+       }       
+
+
+/*
+ * Packs signature according to Cryptocom rules
+ * and frees up DSA_SIG structure
+ */
+/*
+int pack_sign_cc(DSA_SIG *s,int order,unsigned char *sig, size_t *siglen)
+       {
+       *siglen = 2*order;
+       memset(sig,0,*siglen);
+       store_bignum(s->r, sig,order);
+       store_bignum(s->s, sig + order,order);
+       dump_signature("serialized",sig,*siglen);
+       DSA_SIG_free(s);
+       return 1;
+       }
+*/
+/*
+ * Packs signature according to Cryptopro rules
+ * and frees up DSA_SIG structure
+ */
+int pack_sign_cp(DSA_SIG *s,int order,unsigned char *sig, size_t *siglen)
+       {
+       *siglen = 2*order;
+       memset(sig,0,*siglen);
+       store_bignum(s->s, sig, order);
+       store_bignum(s->r, sig+order,order);
+       dump_signature("serialized",sig,*siglen);
+       DSA_SIG_free(s);
+       return 1;
+       }
+
+/*
+ * Verifies signature passed as DSA_SIG structure
+ *
+ */
+
+int gost_do_verify(const unsigned char *dgst, int dgst_len,
+       DSA_SIG *sig, DSA *dsa)
+       {
+       BIGNUM *md, *tmp=NULL;
+       BIGNUM *q2=NULL;
+       BIGNUM *u=NULL,*v=NULL,*z1=NULL,*z2=NULL;
+       BIGNUM *tmp2=NULL,*tmp3=NULL;
+       int ok;
+       BN_CTX *ctx = BN_CTX_new();
+
+       BN_CTX_start(ctx);
+       if (BN_cmp(sig->s,dsa->q)>=1||
+               BN_cmp(sig->r,dsa->q)>=1)
+               {
+               GOSTerr(GOST_F_GOST_DO_VERIFY,GOST_R_SIGNATURE_PARTS_GREATER_THAN_Q);
+               return 0;
+               }
+       md=hashsum2bn(dgst);
+       
+       tmp=BN_CTX_get(ctx);
+       v=BN_CTX_get(ctx);
+       q2=BN_CTX_get(ctx);
+       z1=BN_CTX_get(ctx);
+       z2=BN_CTX_get(ctx);
+       tmp2=BN_CTX_get(ctx);
+       tmp3=BN_CTX_get(ctx);
+       u = BN_CTX_get(ctx);
+       
+       BN_mod(tmp,md,dsa->q,ctx);
+       if (BN_is_zero(tmp))
+               {
+               BN_one(md);
+               }
+       BN_copy(q2,dsa->q);
+       BN_sub_word(q2,2);
+       BN_mod_exp(v,md,q2,dsa->q,ctx);
+       BN_mod_mul(z1,sig->s,v,dsa->q,ctx);
+       BN_sub(tmp,dsa->q,sig->r);
+       BN_mod_mul(z2,tmp,v,dsa->p,ctx);
+       BN_mod_exp(tmp,dsa->g,z1,dsa->p,ctx);
+       BN_mod_exp(tmp2,dsa->pub_key,z2,dsa->p,ctx);
+       BN_mod_mul(tmp3,tmp,tmp2,dsa->p,ctx);
+       BN_mod(u,tmp3,dsa->q,ctx);
+       ok= BN_cmp(u,sig->r);
+       
+       BN_free(md);
+       BN_CTX_end(ctx);
+       BN_CTX_free(ctx);
+       if (ok!=0)
+               {
+               GOSTerr(GOST_F_GOST_DO_VERIFY,GOST_R_SIGNATURE_MISMATCH);
+               }       
+       return (ok==0);
+       }
+
+/*
+ * Computes public keys for GOST R 34.10-94 algorithm
+ *
+ */
+int gost94_compute_public(DSA *dsa)
+       {
+       /* Now fill algorithm parameters with correct values */
+       BN_CTX *ctx = BN_CTX_new();
+       if (!dsa->g)
+               {
+               GOSTerr(GOST_F_GOST94_COMPUTE_PUBLIC,GOST_R_KEY_IS_NOT_INITALIZED);
+               return 0;
+               }       
+       /* Compute public key  y = a^x mod p */
+       dsa->pub_key=BN_new();
+       BN_mod_exp(dsa->pub_key, dsa->g,dsa->priv_key,dsa->p,ctx);
+       BN_CTX_free(ctx);
+       return 1;
+       }
+
+/*
+ * Fill GOST 94 params, searching them in R3410_paramset array
+ * by nid of paramset
+ *
+ */
+int fill_GOST94_params(DSA *dsa,int nid)
+       {
+       R3410_params *params=R3410_paramset;
+       while (params->nid!=NID_undef && params->nid !=nid) params++;
+       if (params->nid == NID_undef)
+               {
+               GOSTerr(GOST_F_FILL_GOST94_PARAMS,GOST_R_UNSUPPORTED_PARAMETER_SET);
+               return 0;
+               }       
+#define dump_signature(a,b,c)
+       if (dsa->p) { BN_free(dsa->p); }
+       dsa->p=NULL;
+       BN_dec2bn(&(dsa->p),params->p);
+       if (dsa->q) { BN_free(dsa->q); }
+       dsa->q=NULL;
+       BN_dec2bn(&(dsa->q),params->q);
+       if (dsa->g) { BN_free(dsa->g); }
+       dsa->g=NULL;
+       BN_dec2bn(&(dsa->g),params->a);
+       return 1;
+       }       
+
+/*
+ *  Generate GOST R 34.10-94 keypair
+ *
+ *
+ */
+int gost_sign_keygen(DSA *dsa)
+       {
+       dsa->priv_key = BN_new();
+       BN_rand_range(dsa->priv_key,dsa->q);
+       return gost94_compute_public( dsa);
+       }
+
+/* Unpack signature according to cryptocom rules  */
+/*
+DSA_SIG *unpack_cc_signature(const unsigned char *sig,size_t siglen)
+       {
+       DSA_SIG *s;
+       s = DSA_SIG_new();
+       if (s == NULL)
+               {
+               GOSTerr(GOST_F_UNPACK_CC_SIGNATURE,GOST_R_NO_MEMORY);
+               return(NULL);
+               }
+       s->r = getbnfrombuf(sig, siglen/2);
+       s->s = getbnfrombuf(sig + siglen/2, siglen/2);
+       return s;
+       }
+*/
+/* Unpack signature according to cryptopro rules  */
+DSA_SIG *unpack_cp_signature(const unsigned char *sig,size_t siglen)
+       {
+       DSA_SIG *s;
+
+       s = DSA_SIG_new();
+       if (s == NULL)
+               {
+               GOSTerr(GOST_F_UNPACK_CP_SIGNATURE,GOST_R_NO_MEMORY);
+               return NULL;
+               }
+       s->s = getbnfrombuf(sig , siglen/2);
+       s->r = getbnfrombuf(sig + siglen/2, siglen/2);
+       return s;
+       }
+
+/* Convert little-endian byte array into bignum */
+BIGNUM *hashsum2bn(const unsigned char *dgst)
+       {
+       unsigned char buf[32];
+       int i;
+       for (i=0;i<32;i++)
+               {
+               buf[31-i]=dgst[i];
+               }
+       return getbnfrombuf(buf,32);
+       }
+
+/* Convert byte buffer to bignum, skipping leading zeros*/
+BIGNUM *getbnfrombuf(const unsigned char *buf,size_t len)
+       {
+       while (*buf==0&&len>0)
+               {
+               buf++; len--;
+               }
+       if (len)
+               {
+               return BN_bin2bn(buf,len,NULL);
+               }
+       else
+               {
+               BIGNUM *b=BN_new();
+               BN_zero(b);
+               return b;
+               }
+       }
+
+/* Pack bignum into byte buffer of given size, filling all leading bytes
+ * by zeros */
+int store_bignum(BIGNUM *bn, unsigned char *buf,int len)
+       {
+       int bytes = BN_num_bytes(bn);
+       if (bytes>len) return 0;
+       memset(buf,0,len);
+       BN_bn2bin(bn,buf+len-bytes);
+       return 1;
+       }       
diff --git a/deps/openssl/openssl/engines/ccgost/gosthash.c b/deps/openssl/openssl/engines/ccgost/gosthash.c
new file mode 100644 (file)
index 0000000..a5c0662
--- /dev/null
@@ -0,0 +1,255 @@
+/**********************************************************************
+ *                          gosthash.c                                *
+ *             Copyright (c) 2005-2006 Cryptocom LTD                  *
+ *         This file is distributed under the same license as OpenSSL *
+ *                                                                    *
+ *    Implementation of GOST R 34.11-94 hash function                 *
+ *       uses on gost89.c and gost89.h Doesn't need OpenSSL           *
+ **********************************************************************/
+#include <string.h>
+
+#include "gost89.h"
+#include "gosthash.h"
+
+
+/* Use OPENSSL_malloc for memory allocation if compiled with 
+ * -DOPENSSL_BUILD, and libc malloc otherwise
+ */
+#ifndef MYALLOC
+# ifdef OPENSSL_BUILD
+#  include <openssl/crypto.h>
+#  define MYALLOC(size) OPENSSL_malloc(size)
+#  define MYFREE(ptr) OPENSSL_free(ptr)
+# else
+#  define MYALLOC(size) malloc(size)
+#  define MYFREE(ptr) free(ptr)
+# endif
+#endif
+/* Following functions are various bit meshing routines used in
+ * GOST R 34.11-94 algorithms */
+static void swap_bytes (byte *w, byte *k) 
+       {
+       int i,j;
+       for (i=0;i<4;i++)       
+               for (j=0;j<8;j++) 
+                       k[i+4*j]=w[8*i+j];
+
+       }
+
+/* was A_A */
+static void circle_xor8 (const byte *w, byte *k) 
+       {
+       byte buf[8];
+       int i;
+       memcpy(buf,w,8);
+       memcpy(k,w+8,24);
+       for(i=0;i<8;i++) 
+               k[i+24]=buf[i]^k[i];
+       }
+
+/* was R_R */
+static void transform_3 (byte *data) 
+       {
+       unsigned short int acc;
+       acc=(data[0]^data[2]^data[4]^data[6]^data[24]^data[30])|
+               ((data[1]^data[3]^data[5]^data[7]^data[25]^data[31])<<8);
+       memmove(data,data+2,30);
+       data[30]=acc&0xff;
+       data[31]=acc>>8;
+       }
+
+/* Adds blocks of N bytes modulo 2**(8*n). Returns carry*/
+static int add_blocks(int n,byte *left, const byte *right) 
+       {
+       int i;
+       int carry=0;
+       int sum;
+       for (i=0;i<n;i++) 
+               {
+               sum=(int)left[i]+(int)right[i]+carry;
+               left[i]=sum & 0xff;
+               carry=sum>>8;
+               }
+       return carry;
+       } 
+
+/* Xor two sequences of bytes */
+static void xor_blocks (byte *result,const byte *a,const byte *b,size_t len)
+       {
+       size_t i;
+       for (i=0;i<len;i++) result[i]=a[i]^b[i];
+       }       
+
+/* 
+ *     Calculate H(i+1) = Hash(Hi,Mi) 
+ *     Where H and M are 32 bytes long
+ */
+static int hash_step(gost_ctx *c,byte *H,const byte *M) 
+       {
+       byte U[32],W[32],V[32],S[32],Key[32];
+       int i;
+       /* Compute first key */
+       xor_blocks(W,H,M,32);
+       swap_bytes(W,Key);
+       /* Encrypt first 8 bytes of H with first key*/
+       gost_enc_with_key(c,Key,H,S);
+       /* Compute second key*/
+       circle_xor8(H,U);
+       circle_xor8(M,V);
+       circle_xor8(V,V);
+       xor_blocks(W,U,V,32);
+       swap_bytes(W,Key);
+       /* encrypt second 8 bytes of H with second key*/
+       gost_enc_with_key(c,Key,H+8,S+8);
+       /* compute third key */
+       circle_xor8(U,U);
+       U[31]=~U[31]; U[29]=~U[29]; U[28]=~U[28]; U[24]=~U[24];
+       U[23]=~U[23]; U[20]=~U[20]; U[18]=~U[18]; U[17]=~U[17];
+       U[14]=~U[14]; U[12]=~U[12]; U[10]=~U[10]; U[ 8]=~U[ 8];
+       U[ 7]=~U[ 7]; U[ 5]=~U[ 5]; U[ 3]=~U[ 3]; U[ 1]=~U[ 1];
+       circle_xor8(V,V);
+       circle_xor8(V,V);
+       xor_blocks(W,U,V,32);
+       swap_bytes(W,Key);
+       /* encrypt third 8 bytes of H with third key*/
+       gost_enc_with_key(c,Key,H+16,S+16);
+       /* Compute fourth key */
+       circle_xor8(U,U);
+       circle_xor8(V,V);
+       circle_xor8(V,V);
+       xor_blocks(W,U,V,32);
+       swap_bytes(W,Key);
+       /* Encrypt last 8 bytes with fourth key */
+       gost_enc_with_key(c,Key,H+24,S+24);
+       for (i=0;i<12;i++) 
+               transform_3(S);
+       xor_blocks(S,S,M,32);
+       transform_3(S);
+       xor_blocks(S,S,H,32);
+       for (i=0;i<61;i++) 
+               transform_3(S);
+       memcpy(H,S,32);
+       return 1;
+       }
+
+/* Initialize gost_hash ctx - cleans up temporary structures and
+ * set up substitution blocks
+ */
+int init_gost_hash_ctx(gost_hash_ctx *ctx, const gost_subst_block *subst_block)
+       {       
+       memset(ctx,0,sizeof(gost_hash_ctx));
+       ctx->cipher_ctx = (gost_ctx *)MYALLOC(sizeof(gost_ctx));
+       if (!ctx->cipher_ctx)
+               {
+               return 0;
+               }               
+       gost_init(ctx->cipher_ctx,subst_block);
+       return 1;
+       }
+
+/*
+ * Free cipher CTX if it is dynamically allocated. Do not use
+ * if cipher ctx is statically allocated as in OpenSSL implementation of
+ * GOST hash algroritm
+ *
+ */ 
+void done_gost_hash_ctx(gost_hash_ctx *ctx) 
+       {
+       /* No need to use gost_destroy, because cipher keys are not really
+        * secret when hashing */
+       MYFREE(ctx->cipher_ctx);
+       }
+
+/*
+ * reset state of hash context to begin hashing new message
+ */
+int start_hash(gost_hash_ctx *ctx)
+       {
+       if (!ctx->cipher_ctx) return 0;
+       memset(&(ctx->H),0,32);
+       memset(&(ctx->S),0,32);
+       ctx->len = 0L;
+       ctx->left=0;
+       return 1;
+       }
+
+/*
+ * Hash block of arbitrary length
+ *
+ *
+ */
+int hash_block(gost_hash_ctx *ctx,const byte *block, size_t length)
+       {
+       const byte *curptr=block;
+       const byte *barrier=block+(length-32);/* Last byte we can safely hash*/
+       if (ctx->left)
+               {
+               /*There are some bytes from previous step*/
+               unsigned int add_bytes = 32-ctx->left;
+               if (add_bytes>length)
+                       {
+                       add_bytes = length;
+                       }       
+               memcpy(&(ctx->remainder[ctx->left]),block,add_bytes);
+               ctx->left+=add_bytes;
+               if (ctx->left<32)
+                       {
+                       return 1;
+                       }       
+               curptr=block+add_bytes;
+               hash_step(ctx->cipher_ctx,ctx->H,ctx->remainder);
+               add_blocks(32,ctx->S,ctx->remainder);
+               ctx->len+=32;
+               ctx->left=0;
+               }
+       while (curptr<=barrier)
+               {       
+               hash_step(ctx->cipher_ctx,ctx->H,curptr);
+                       
+               add_blocks(32,ctx->S,curptr);
+               ctx->len+=32;
+               curptr+=32;
+               }       
+       if (curptr!=block+length)
+               {
+               ctx->left=block+length-curptr;
+               memcpy(ctx->remainder,curptr,ctx->left);
+               }       
+       return 1;       
+       }
+
+/*
+ * Compute hash value from current state of ctx
+ * state of hash ctx becomes invalid and cannot be used for further
+ * hashing.
+ */ 
+int finish_hash(gost_hash_ctx *ctx,byte *hashval)
+       {
+       byte buf[32];
+       byte H[32];
+       byte S[32];
+       ghosthash_len fin_len=ctx->len;
+       byte *bptr;
+       memcpy(H,ctx->H,32);
+       memcpy(S,ctx->S,32);
+       if (ctx->left)
+               {
+               memset(buf,0,32);
+               memcpy(buf,ctx->remainder,ctx->left);
+               hash_step(ctx->cipher_ctx,H,buf);
+               add_blocks(32,S,buf);
+               fin_len+=ctx->left;
+               }
+       memset(buf,0,32);
+       bptr=buf;
+       fin_len<<=3; /* Hash length in BITS!!*/
+       while(fin_len>0)
+               {
+               *(bptr++)=(byte)(fin_len&0xFF);
+               fin_len>>=8;
+               };
+       hash_step(ctx->cipher_ctx,H,buf);
+       hash_step(ctx->cipher_ctx,H,S);
+       memcpy(hashval,H,32);
+       return 1;
+       }
diff --git a/deps/openssl/openssl/engines/ccgost/gosthash.h b/deps/openssl/openssl/engines/ccgost/gosthash.h
new file mode 100644 (file)
index 0000000..4a2e441
--- /dev/null
@@ -0,0 +1,48 @@
+/**********************************************************************
+ *                          gosthash.h                                *
+ *             Copyright (c) 2005-2006 Cryptocom LTD                  *
+ *       This file is distributed under the same license as OpenSSL   *
+ *                                                                    *
+ *    Declaration of GOST R 34.11-94 hash functions                   *
+ *       uses  and gost89.h Doesn't need OpenSSL                      *
+ **********************************************************************/
+#ifndef GOSTHASH_H
+#define GOSTHASH_H
+#include "gost89.h"
+#include <stdlib.h>
+
+#if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__)
+typedef __int64 ghosthash_len;
+#elif defined(__arch64__)
+typedef long ghosthash_len;
+#else
+typedef long long ghosthash_len;
+#endif
+
+typedef struct gost_hash_ctx {
+               ghosthash_len len;
+               gost_ctx *cipher_ctx;
+               int left;
+               byte H[32];
+               byte S[32];
+               byte remainder[32];
+} gost_hash_ctx;               
+
+
+/* Initalizes gost hash ctx, including creation of gost cipher ctx */
+
+int init_gost_hash_ctx(gost_hash_ctx *ctx, const gost_subst_block *subst_block);
+void done_gost_hash_ctx(gost_hash_ctx *ctx);
+
+/* Cleans up all fields, except cipher ctx preparing ctx for computing
+ * of new hash value */
+int start_hash(gost_hash_ctx *ctx);
+
+/* Hashes block of data */
+int hash_block(gost_hash_ctx *ctx, const byte *block, size_t length);
+
+/* Finalizes computation of hash  and fills buffer (which should be at
+ * least 32 bytes long) with value of computed hash. */
+int finish_hash(gost_hash_ctx *ctx, byte *hashval);
+
+#endif 
diff --git a/deps/openssl/openssl/engines/ccgost/gostsum.c b/deps/openssl/openssl/engines/ccgost/gostsum.c
new file mode 100644 (file)
index 0000000..d57112e
--- /dev/null
@@ -0,0 +1,210 @@
+/**********************************************************************
+ *                        gostsum.c                                   *
+ *             Copyright (c) 2005-2006 Cryptocom LTD                  *
+ *         This file is distributed under the same license as OpenSSL *
+ *                                                                    *
+ *        Almost drop-in replacement for md5sum and sha1sum           *
+ *          which computes GOST R 34.11-94 hashsum instead            *
+ *                                                                    *
+ **********************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <limits.h>
+#include <fcntl.h>
+#include <string.h>
+#include "gosthash.h"
+#define BUF_SIZE 262144
+int hash_file(gost_hash_ctx *ctx,char *filename,char *sum,int mode);
+int hash_stream(gost_hash_ctx *ctx,int fd, char *sum);
+int get_line(FILE *f,char *hash,char *filename);
+void help()
+       {
+       fprintf(stderr,"gostsum [-bvt] [-c [file]]| [files]\n"
+               "\t-c check message digests (default is generate)\n"
+               "\t-v verbose, print file names when checking\n"
+               "\t-b read files in binary mode\n"
+               "\t-t use test GOST paramset (default is CryptoPro paramset)\n"
+               "The input for -c should be the list of message digests and file names\n"
+               "that is printed on stdout by this program when it generates digests.\n");
+       exit(3);
+       }
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
+int main(int argc,char **argv)
+       {
+       int c,i;
+       int verbose=0;
+       int errors=0;
+       int open_mode = O_RDONLY;
+       gost_subst_block *b=  &GostR3411_94_CryptoProParamSet;
+       FILE *check_file = NULL;
+       gost_hash_ctx ctx;
+       
+       while( (c=getopt(argc,argv,"bc::tv"))!=-1)
+               {
+               switch (c)
+                       {
+                       case 'v': verbose=1; break;
+                       case 't': b= &GostR3411_94_TestParamSet; break;
+                       case 'b': open_mode |= O_BINARY; break;
+                       case 'c':
+                               if (optarg)
+                                       {
+                                       check_file = fopen(optarg,"r");
+                                       if (!check_file)
+                                               {
+                                               perror(optarg);
+                                               exit(2);
+                                               }
+                                       }
+                               else
+                                       {
+                                       check_file= stdin;
+                                       }
+                               break;
+                       default:
+                               fprintf(stderr,"invalid option %c",optopt);
+                               help();
+                       }
+               }
+       init_gost_hash_ctx(&ctx,b);
+       if (check_file)
+               {
+               char inhash[65],calcsum[65],filename[PATH_MAX];
+               int failcount=0,count=0;;
+               if (check_file==stdin && optind<argc)
+                       {
+                       check_file=fopen(argv[optind],"r");
+                       if (!check_file)
+                               {       
+                               perror(argv[optind]);
+                               exit(2);
+                               }
+                       }       
+               while (get_line(check_file,inhash,filename))
+                       {
+                       if (!hash_file(&ctx,filename,calcsum,open_mode))
+                               {
+                               exit (2);
+                               }       
+                       count++;
+                       if (!strncmp(calcsum,inhash,65))
+                               {
+                               if (verbose)
+                                       {
+                                       fprintf(stderr,"%s\tOK\n",filename);
+                                       }
+                               }
+                       else
+                               {
+                               if (verbose)
+                                       {
+                                       fprintf(stderr,"%s\tFAILED\n",filename);
+                                       }
+                               else
+                                       {
+                                       fprintf(stderr,"%s: GOST hash sum check failed for '%s'\n",
+                                               argv[0],filename);
+                                       }
+                               failcount++;
+                               }
+                       }       
+               if (verbose && failcount)
+                       {
+                       fprintf(stderr,"%s: %d of %d file(f) failed GOST hash sum check\n",
+                               argv[0],failcount,count);
+                       }
+               exit (failcount?1:0);
+               }
+       if (optind==argc)
+               {
+               char sum[65];
+               if (!hash_stream(&ctx,fileno(stdin),sum))
+                       {
+                       perror("stdin");
+                       exit(1);
+                       }       
+               printf("%s -\n",sum);
+               exit(0);
+               }       
+       for (i=optind;i<argc;i++)
+               {
+               char sum[65];
+               if (!hash_file(&ctx,argv[i],sum,open_mode))
+                       {
+                       errors++;
+                       }
+               else
+                       {       
+                       printf("%s %s\n",sum,argv[i]);
+                       }
+               }       
+       exit(errors?1:0);       
+       }
+
+int hash_file(gost_hash_ctx *ctx,char *filename,char *sum,int mode)
+       {
+       int fd;
+       if ((fd=open(filename,mode))<0)
+               {
+               perror(filename);
+               return 0;
+               }
+       if (!hash_stream(ctx,fd,sum))
+               {
+               perror(filename);
+               return 0;
+               }       
+       close(fd);
+       return 1;
+       }
+
+int hash_stream(gost_hash_ctx *ctx,int fd, char *sum)
+       {
+       unsigned char buffer[BUF_SIZE];
+       ssize_t bytes;
+       int i;
+       start_hash(ctx);
+       while ((bytes=read(fd,buffer,BUF_SIZE))>0)
+               {
+               hash_block(ctx,buffer,bytes);
+               }
+       if (bytes<0)
+               {
+               return 0;
+               }       
+       finish_hash(ctx,buffer);
+       for (i=0;i<32;i++)
+               {
+               sprintf(sum+2*i,"%02x",buffer[31-i]);
+               }
+       return 1;
+       }       
+       
+int get_line(FILE *f,char *hash,char *filename)
+       {
+       int i;
+       if (fread(hash,1,64,f)<64) return 0;
+       hash[64]=0;
+       for (i=0;i<64;i++)
+               {
+               if (hash[i]<'0' || (hash[i]>'9' && hash[i]<'A') || (hash[i]>'F'
+                               && hash[i]<'a')||hash[i]>'f')
+                       {
+                       fprintf(stderr,"Not a hash value '%s'\n",hash);
+                       return 0;
+                       }
+               }       
+       if (fgetc(f)!=' ')
+               {
+               fprintf(stderr,"Malformed input line\n");
+               return 0;
+               }
+       i=strlen(fgets(filename,PATH_MAX,f));
+       while (filename[--i]=='\n'||filename[i]=='\r') filename[i]=0;
+       return 1;
+       }       
index 0f1dae7..443182b 100644 (file)
@@ -92,7 +92,7 @@ static int cca_rsa_priv_dec(int flen, const unsigned char *from,
 static int cca_rsa_sign(int type, const unsigned char *m, unsigned int m_len,
                unsigned char *sigret, unsigned int *siglen, const RSA *rsa);
 static int cca_rsa_verify(int dtype, const unsigned char *m, unsigned int m_len,
-               unsigned char *sigbuf, unsigned int siglen, const RSA *rsa);
+       const unsigned char *sigbuf, unsigned int siglen, const RSA *rsa);
 
 /* utility functions */
 /*-----------------------*/
@@ -108,7 +108,7 @@ static int getModulusAndExponent(const unsigned char *token, long *exponentLengt
 
 /* RAND number functions */
 /*-----------------------*/
-static int cca_get_random_bytes(unsigned char*, int );
+static int cca_get_random_bytes(unsigned char*, int);
 static int cca_random_status(void);
 
 #ifndef OPENSSL_NO_RSA
@@ -482,10 +482,6 @@ static EVP_PKEY *ibm_4758_load_privkey(ENGINE* e, const char* key_id,
 err:
        if (keyToken)
                OPENSSL_free(keyToken);
-       if (res)
-               EVP_PKEY_free(res);
-       if (rtmp)
-               RSA_free(rtmp);
        return NULL;
        }
 
@@ -560,10 +556,6 @@ static EVP_PKEY *ibm_4758_load_pubkey(ENGINE* e, const char* key_id,
 err:
        if (keyToken)
                OPENSSL_free(keyToken);
-       if (res)
-               EVP_PKEY_free(res);
-       if (rtmp)
-               RSA_free(rtmp);
        return NULL;
        }
 
@@ -626,7 +618,7 @@ static int cca_rsa_priv_dec(int flen, const unsigned char *from,
 #define SSL_SIG_LEN 36
 
 static int cca_rsa_verify(int type, const unsigned char *m, unsigned int m_len,
-               unsigned char *sigbuf, unsigned int siglen, const RSA *rsa)
+       const unsigned char *sigbuf, unsigned int siglen, const RSA *rsa)
        {
        long returnCode;
        long reasonCode;
@@ -735,7 +727,8 @@ static int cca_rsa_verify(int type, const unsigned char *m, unsigned int m_len,
 
        digitalSignatureVerify(&returnCode, &reasonCode, &exitDataLength,
                exitData, &ruleArrayLength, ruleArray, &keyTokenLength,
-               keyToken, &length, hashBuffer, &lsiglen, sigbuf);
+               keyToken, &length, hashBuffer, &lsiglen,
+                                               (unsigned char *)sigbuf);
 
        if (type == NID_sha1 || type == NID_md5)
                {
index e24e4b4..d7f89e5 100644 (file)
@@ -57,7 +57,7 @@
 #include <string.h>
 
 #include <openssl/e_os2.h>
-#if !defined(OPENSSL_SYS_MSDOS) || defined(__DJGPP__)
+#if !defined(OPENSSL_SYS_MSDOS) || defined(__DJGPP__) || defined(__MINGW32__)
 #include <sys/types.h>
 #include <unistd.h>
 #else
@@ -68,6 +68,8 @@ typedef int pid_t;
 #if defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB)
 #define getpid GetThreadID
 extern int GetThreadID(void);
+#elif defined(_WIN32) && !defined(__WATCOMC__)
+#define getpid _getpid
 #endif
 
 #include <openssl/crypto.h>
@@ -867,13 +869,7 @@ static AEP_RV aep_get_connection(AEP_CONNECTION_HNDL_PTR phConnection)
 
        CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
 
-#ifdef NETWARE_CLIB
-       curr_pid = GetThreadID();
-#elif defined(_WIN32)
-       curr_pid = _getpid();
-#else
        curr_pid = getpid();
-#endif
 
        /*Check if this is the first time this is being called from the current
          process*/
index 59b2ab7..24b620f 100644 (file)
 
 #include <wincrypt.h>
 
+/*
+ * This module uses several "new" interfaces, among which is
+ * CertGetCertificateContextProperty. CERT_KEY_PROV_INFO_PROP_ID is
+ * one of possible values you can pass to function in question. By
+ * checking if it's defined we can see if wincrypt.h and accompanying
+ * crypt32.lib are in shape. The native MingW32 headers up to and
+ * including __W32API_VERSION 3.14 lack of struct DSSPUBKEY and the
+ * defines CERT_STORE_PROV_SYSTEM_A and CERT_STORE_READONLY_FLAG,
+ * so we check for these too and avoid compiling.
+ * Yes, it's rather "weak" test and if compilation fails,
+ * then re-configure with -DOPENSSL_NO_CAPIENG.
+ */
+#if defined(CERT_KEY_PROV_INFO_PROP_ID) && \
+    defined(CERT_STORE_PROV_SYSTEM_A) && \
+    defined(CERT_STORE_READONLY_FLAG)
+# define __COMPILE_CAPIENG
+#endif /* CERT_KEY_PROV_INFO_PROP_ID */
+#endif /* OPENSSL_NO_CAPIENG */
+#endif /* OPENSSL_SYS_WIN32 */
+
+#ifdef __COMPILE_CAPIENG
+
 #undef X509_EXTENSIONS
 #undef X509_CERT_PAIR
 
@@ -1788,12 +1810,15 @@ static int cert_select_dialog(ENGINE *e, SSL *ssl, STACK_OF(X509) *certs)
        }
 #endif
 
-#endif
-#else /* !WIN32 */
+#else /* !__COMPILE_CAPIENG */
 #include <openssl/engine.h>
 #ifndef OPENSSL_NO_DYNAMIC_ENGINE
 OPENSSL_EXPORT
+int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns);
+OPENSSL_EXPORT
 int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) { return 0; }
 IMPLEMENT_DYNAMIC_CHECK_FN()
+#else
+void ENGINE_load_capi(void){}
 #endif
 #endif
index eaaefb2..a1fbd04 100644 (file)
@@ -1,6 +1,6 @@
 /* e_capi_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2008 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2009 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
index 4c749ec..efa7001 100644 (file)
 #ifndef HEADER_CAPI_ERR_H
 #define HEADER_CAPI_ERR_H
 
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
 /* BEGIN ERROR CODES */
 /* The following lines are auto generated by the script mkerr.pl. Any changes
  * made after this point may be overwritten when the script is next run.
index fca7a9c..fdc2100 100644 (file)
@@ -227,7 +227,6 @@ static RAND_METHOD hwcrhk_rand =
 /* Constants used when creating the ENGINE */
 static const char *engine_hwcrhk_id = "chil";
 static const char *engine_hwcrhk_name = "CHIL hardware engine support";
-
 #ifndef OPENSSL_NO_DYNAMIC_ENGINE 
 /* Compatibility hack, the dynamic library uses this form in the path */
 static const char *engine_hwcrhk_id_alt = "ncipher";
@@ -842,8 +841,6 @@ static EVP_PKEY *hwcrhk_load_privkey(ENGINE *eng, const char *key_id,
 
        return res;
  err:
-       if (res)
-               EVP_PKEY_free(res);
 #ifndef OPENSSL_NO_RSA
        if (rtmp)
                RSA_free(rtmp);
index a1a2d2b..a3d4715 100644 (file)
@@ -85,7 +85,9 @@
 #include <openssl/crypto.h>
 #include <openssl/buffer.h>
 #include <openssl/engine.h>
+#ifndef OPENSSL_NO_RSA
 #include <openssl/rsa.h>
+#endif
 #include <openssl/bn.h>
 
 #ifndef OPENSSL_NO_HW
@@ -469,8 +471,10 @@ static int bind_fn(ENGINE *e, const char *id)
 IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
 #else
 OPENSSL_EXPORT
+int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns);
+OPENSSL_EXPORT
 int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) { return 0; }
 #endif
-#endif /* OPENSSL_NO_DYNAMIC_ENGINE */
+#endif /* !OPENSSL_NO_DYNAMIC_ENGINE */
 
 #endif /* !OPENSSL_NO_HW */
similarity index 98%
rename from deps/openssl/openssl/crypto/engine/eng_padlock.c
rename to deps/openssl/openssl/engines/e_padlock.c
index 743558a..7d09419 100644 (file)
@@ -108,6 +108,8 @@ static ENGINE *ENGINE_padlock (void);
 # endif
 #endif
 
+#ifdef OPENSSL_NO_DYNAMIC_ENGINE
+
 void ENGINE_load_padlock (void)
 {
 /* On non-x86 CPUs it just returns. */
@@ -120,17 +122,21 @@ void ENGINE_load_padlock (void)
 #endif
 }
 
+#endif
+
 #ifdef COMPILE_HW_PADLOCK
 /* We do these includes here to avoid header problems on platforms that
    do not have the VIA padlock anyway... */
-#ifdef _MSC_VER
+#include <stdlib.h>
+#ifdef _WIN32
 # include <malloc.h>
-# define alloca _alloca
-#elif defined(NETWARE_CLIB) && defined(__GNUC__)
-  void *alloca(size_t);
-# define alloca(s) __builtin_alloca(s)
-#else
-# include <stdlib.h>
+# ifndef alloca
+#  define alloca _alloca
+# endif
+#elif defined(__GNUC__)
+# ifndef alloca
+#  define alloca(s) __builtin_alloca(s)
+# endif
 #endif
 
 /* Function for ENGINE detection and control */
@@ -234,7 +240,7 @@ padlock_bind_fn(ENGINE *e, const char *id)
        return 1;
 }
 
-IMPLEMENT_DYNAMIC_CHECK_FN ()
+IMPLEMENT_DYNAMIC_CHECK_FN()
 IMPLEMENT_DYNAMIC_BIND_FN (padlock_bind_fn)
 #endif /* DYNAMIC_ENGINE */
 
@@ -1213,6 +1219,14 @@ static RAND_METHOD padlock_rand = {
        padlock_rand_status,    /* rand status */
 };
 
+#else  /* !COMPILE_HW_PADLOCK */
+#ifndef OPENSSL_NO_DYNAMIC_ENGINE
+OPENSSL_EXPORT
+int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns);
+OPENSSL_EXPORT
+int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) { return 0; }
+IMPLEMENT_DYNAMIC_CHECK_FN()
+#endif
 #endif /* COMPILE_HW_PADLOCK */
 
 #endif /* !OPENSSL_NO_HW_PADLOCK */
diff --git a/deps/openssl/openssl/engines/e_padlock.ec b/deps/openssl/openssl/engines/e_padlock.ec
new file mode 100644 (file)
index 0000000..5c8a1d2
--- /dev/null
@@ -0,0 +1 @@
+L PADLOCK      e_padlock_err.h                 e_padlock_err.c
index 58fa9a9..cd0fa4c 100644 (file)
@@ -758,8 +758,6 @@ static EVP_PKEY* sureware_load_public(ENGINE *e,const char *key_id,char *hptr,un
        }
        return res;
  err:
-       if (res)
-               EVP_PKEY_free(res);
 #ifndef OPENSSL_NO_RSA
        if (rsatmp)
                RSA_free(rsatmp);
index f1c8101..aa5709b 100644 (file)
@@ -95,14 +95,14 @@ static int ubsec_finish(ENGINE *e);
 static int ubsec_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void));
 static int ubsec_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
                const BIGNUM *m, BN_CTX *ctx);
+#ifndef OPENSSL_NO_RSA
 static int ubsec_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
                        const BIGNUM *q, const BIGNUM *dp,
                        const BIGNUM *dq, const BIGNUM *qinv, BN_CTX *ctx);
-#ifndef OPENSSL_NO_RSA
 static int ubsec_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx);
-#endif
 static int ubsec_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
                const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
+#endif
 #ifndef OPENSSL_NO_DSA
 #ifdef NOT_USED
 static int ubsec_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
@@ -302,10 +302,10 @@ static t_UBSEC_diffie_hellman_generate_ioctl
        *p_UBSEC_diffie_hellman_generate_ioctl = NULL;
 static t_UBSEC_diffie_hellman_agree_ioctl *p_UBSEC_diffie_hellman_agree_ioctl = NULL;
 #endif
-/* #ifndef OPENSSL_NO_RSA */
+#ifndef OPENSSL_NO_RSA
 static t_UBSEC_rsa_mod_exp_ioctl *p_UBSEC_rsa_mod_exp_ioctl = NULL;
 static t_UBSEC_rsa_mod_exp_crt_ioctl *p_UBSEC_rsa_mod_exp_crt_ioctl = NULL;
-/* #endif */
+#endif
 #ifndef OPENSSL_NO_DSA
 static t_UBSEC_dsa_sign_ioctl *p_UBSEC_dsa_sign_ioctl = NULL;
 static t_UBSEC_dsa_verify_ioctl *p_UBSEC_dsa_verify_ioctl = NULL;
@@ -624,7 +624,6 @@ static int ubsec_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
 err:
        return to_return;
        }
-#endif
 
 static int ubsec_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
                        const BIGNUM *q, const BIGNUM *dp,
@@ -670,6 +669,7 @@ static int ubsec_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
        r->top = (BN_num_bits(p) + BN_num_bits(q) + BN_BITS2 - 1)/BN_BITS2;
        return 1;
 }
+#endif
 
 #ifndef OPENSSL_NO_DSA
 #ifdef NOT_USED
@@ -702,6 +702,8 @@ static int ubsec_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
 #endif
 #endif
 
+#ifndef OPENSSL_NO_RSA
+
 /*
  * This function is aliased to mod_exp (with the mont stuff dropped).
  */
@@ -710,7 +712,6 @@ static int ubsec_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
         {
        int ret = 0;
 
-#ifndef OPENSSL_NO_RSA
        /* Do in software if the key is too large for the hardware. */
        if (BN_num_bits(m) > max_key_len)
                 {
@@ -718,13 +719,13 @@ static int ubsec_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
                ret = (*meth->bn_mod_exp)(r, a, p, m, ctx, m_ctx);
                 }
         else
-#endif
                 {
                ret = ubsec_mod_exp(r, a, p, m, ctx);
                 }
        
        return ret;
         }
+#endif
 
 #ifndef OPENSSL_NO_DH
 /* This function is aliased to mod_exp (with the dh and mont dropped). */
index b702538..6329fbb 100644 (file)
@@ -1,5 +1,5 @@
 $!
-$!  MAKEAPPS.COM
+$!  MAKEENGINES.COM
 $!  Written By:  Richard Levitte
 $!               richard@levitte.org
 $!
@@ -28,22 +28,35 @@ $!
 $!  P6 if defined, denotes which engines to build.  If not defined,
 $!     all available engines are built.
 $!
+$!  P7, if defined, specifies the C pointer size.  Ignored on VAX.
+$!      ("64=ARGV" gives more efficient code with HP C V7.3 or newer.)
+$!      Supported values are:
+$!
+$!     ""      Compile with default (/NOPOINTER_SIZE)
+$!     32      Compile with /POINTER_SIZE=32 (SHORT)
+$!     64      Compile with /POINTER_SIZE=64[=ARGV] (LONG[=ARGV])
+$!               (Automatically select ARGV if compiler supports it.)
+$!      64=      Compile with /POINTER_SIZE=64 (LONG).
+$!      64=ARGV  Compile with /POINTER_SIZE=64=ARGV (LONG=ARGV).
+$!
+$!  P8, if defined, specifies a directory where ZLIB files (zlib.h,
+$!  libz.olb) may be found.  Optionally, a non-default object library
+$!  name may be included ("dev:[dir]libz_64.olb", for example).
+$!
 $!-----------------------------------------------------------------------------
 $!
-$! Set the names of the engines we want to build
-$! NOTE: Some might think this list ugly.  However, it's made this way to
-$! reflect the LIBNAMES variable in Makefile as closely as possible,
-$! thereby making it fairly easy to verify that the lists are the same.
-$! NOTE: gmp isn't built, as it's mostly a test engine and brings in another
-$! library that isn't necessarely ported to VMS.
+$! Announce/identify.
 $!
-$ ENGINES = "," + P6
-$ IF ENGINES .EQS. "," THEN -
-       ENGINES = ",4758cca,aep,atalla,cswift,chil,nuron,sureware,ubsec,capi"
+$ proc = f$environment( "procedure")
+$ write sys$output "@@@ "+ -
+   f$parse( proc, , , "name")+ f$parse( proc, , , "type")
+$!
+$ on control_c then goto exit
 $!
 $! Set the default TCP/IP library to link against if needed
 $!
 $ TCPIP_LIB = ""
+$ ZLIB_LIB = ""
 $!
 $! Check What Architecture We Are Using.
 $!
@@ -52,7 +65,7 @@ $ THEN
 $!
 $!  The Architecture Is VAX.
 $!
-$   ARCH := VAX
+$   ARCH = "VAX"
 $!
 $! Else...
 $!
@@ -67,19 +80,28 @@ $! End The Architecture Check.
 $!
 $ ENDIF
 $!
-$! Set the goal directories, and creat them if necessary
+$ ARCHD = ARCH
+$ LIB32 = "32"
+$ OPT_FILE = ""
+$ POINTER_SIZE = ""
 $!
-$ OBJ_DIR := SYS$DISK:[-.'ARCH'.OBJ.ENGINES]
-$ EXE_DIR := SYS$DISK:[-.'ARCH'.EXE.ENGINES]
-$ IF F$PARSE(OBJ_DIR) .EQS. "" THEN CREATE/DIRECTORY 'OBJ_DIR'
-$ IF F$PARSE(EXE_DIR) .EQS. "" THEN CREATE/DIRECTORY 'EXE_DIR'
+$! Set the names of the engines we want to build
+$! NOTE: Some might think this list ugly.  However, it's made this way to
+$! reflect the LIBNAMES variable in Makefile as closely as possible,
+$! thereby making it fairly easy to verify that the lists are the same.
+$! NOTE: gmp isn't built, as it's mostly a test engine and brings in another
+$! library that isn't necessarely ported to VMS.
 $!
-$! Set the goal files, and create them if necessary
+$ ENGINES = "," + P6
+$ IF ENGINES .EQS. "," THEN -
+       ENGINES = ",4758cca,aep,atalla,cswift,chil,nuron,sureware,ubsec,padlock,"
 $!
-$ CRYPTO_LIB :=SYS$DISK:[-.'ARCH'.EXE.CRYPTO]LIBCRYPTO.OLB
-$ IF F$SEARCH(CRYPTO_LIB) .EQS. "" THEN LIBRARY/CREATE/OBJECT 'CRYPTO_LIB'
+$! GOST requires a 64-bit integer type, unavailable on VAX.
 $!
-$! OK, time to check options and initialise
+$ IF (ARCH .NES. "VAX") THEN -
+       ENGINES = ENGINES+ ",ccgost"
+$!
+$! Check options.
 $!
 $ OPT_PHASE = P1
 $ ACCEPT_PHASE = "ALL,ENGINES"
@@ -87,8 +109,39 @@ $ OPT_DEBUG = P2
 $ OPT_COMPILER = P3
 $ OPT_TCPIP_LIB = P4
 $ OPT_SPECIAL_THREADS = P5
+$ OPT_POINTER_SIZE = P7
+$ ZLIB = P8
 $
 $ GOSUB CHECK_OPTIONS
+$!
+$! Set the goal directories, and create them if necessary
+$!
+$ OBJ_DIR := SYS$DISK:[-.'ARCHD'.OBJ.ENGINES]
+$ EXE_DIR := SYS$DISK:[-.'ARCHD'.EXE.ENGINES]
+$ IF F$PARSE(OBJ_DIR) .EQS. "" THEN CREATE/DIRECTORY 'OBJ_DIR'
+$ IF F$PARSE(EXE_DIR) .EQS. "" THEN CREATE/DIRECTORY 'EXE_DIR'
+$!
+$! Set the goal files, and create them if necessary
+$!
+$ CRYPTO_LIB := SYS$DISK:[-.'ARCHD'.EXE.CRYPTO]SSL_LIBCRYPTO'LIB32'.OLB
+$ IF F$SEARCH(CRYPTO_LIB) .EQS. "" THEN LIBRARY/CREATE/OBJECT 'CRYPTO_LIB'
+$!
+$! Specify the destination directory in any /MAP option.
+$!
+$ if (LINKMAP .eqs. "MAP")
+$ then
+$   LINKMAP = LINKMAP+ "=''EXE_DIR'"
+$ endif
+$!
+$! Add the location prefix to the linker options file name.
+$!
+$ if (OPT_FILE .nes. "")
+$ then
+$   OPT_FILE = EXE_DIR+ OPT_FILE
+$ endif
+$!
+$! Initialise.
+$!
 $ GOSUB INITIALISE
 $ GOSUB CHECK_OPT_FILE
 $!
@@ -110,7 +163,13 @@ $ ENGINE_chil = "e_chil"
 $ ENGINE_nuron = "e_nuron"
 $ ENGINE_sureware = "e_sureware"
 $ ENGINE_ubsec = "e_ubsec"
-$ ENGINE_capi = "e_capi"
+$ ENGINE_padlock = "e_padlock"
+$
+$ ENGINE_ccgost_SUBDIR = "ccgost"
+$ ENGINE_ccgost = "e_gost_err,gost2001_keyx,gost2001,gost89,gost94_keyx,"+ -
+                 "gost_ameth,gost_asn1,gost_crypt,gost_ctl,gost_eng,"+ -
+                 "gosthash,gost_keywrap,gost_md,gost_params,gost_pmeth,"+ -
+                 "gost_sign"
 $!
 $! Define which programs need to be linked with a TCP/IP library
 $!
@@ -157,6 +216,13 @@ $ ELSE
 $   WRITE SYS$OUTPUT "Compiling Support Files. (",BUILDALL,")"
 $ ENDIF
 $!
+$! Create a .OPT file for the object files (for a real engine name).
+$!
+$ IF ENGINE_NAME .NES. ""
+$ THEN
+$   OPEN /WRITE OBJECTS 'EXE_DIR''ENGINE_NAME'.OPT
+$ ENDIF
+$!
 $! Here's the start of per-engine module loop.
 $!
 $ FILE_COUNTER = 0
@@ -173,7 +239,12 @@ $ IF FILE_NAME .EQS. "" THEN GOTO FILE_NEXT
 $!
 $! Set up the source and object reference
 $!
-$ SOURCE_FILE = F$PARSE(FILE_NAME,"SYS$DISK:[].C",,,"SYNTAX_ONLY")
+$ IF F$TYPE('LIB_ENGINE'_SUBDIR) .EQS. ""
+$ THEN
+$     SOURCE_FILE = F$PARSE(FILE_NAME,"SYS$DISK:[].C",,,"SYNTAX_ONLY")
+$ ELSE
+$     SOURCE_FILE = F$PARSE(FILE_NAME,"SYS$DISK:[."+'LIB_ENGINE'_SUBDIR+"].C",,,"SYNTAX_ONLY")
+$ ENDIF
 $ OBJECT_FILE = OBJ_DIR + F$PARSE(FILE_NAME,,,"NAME","SYNTAX_ONLY") + ".OBJ"
 $!
 $! If we get some problem, we just go on trying to build the next module.
@@ -203,10 +274,27 @@ $ ELSE
 $   CC/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
 $ ENDIF
 $!
+$! Write the entry to the .OPT file (for a real engine name).
+$!
+$ IF ENGINE_NAME .NES. ""
+$ THEN
+$   WRITE OBJECTS OBJECT_FILE
+$ ENDIF
+$!
+$! Next file
+$!
+$ GOTO FILE_NEXT
+$!
+$ FILE_DONE:
+$!
 $! Do not link the support files.
 $!
 $ IF ENGINE_NAME .EQS. "" THEN GOTO ENGINE_NEXT
 $!
+$! Close the linker options file (for a real engine name).
+$!
+$ CLOSE OBJECTS
+$!
 $! Now, there are two ways to handle this.  We can either build 
 $! shareable images or stick the engine object file into libcrypto.
 $! For now, the latter is NOT supported.
@@ -217,28 +305,14 @@ $! For shareable libraries, we need to do things a little differently
 $! depending on if we link with a TCP/IP library or not.
 $!
 $ ENGINE_OPT := SYS$DISK:[]'ARCH'.OPT
-$ IF TCPIP_LIB .NES. ""
-$ THEN
-$   LINK/'DEBUGGER'/'TRACEBACK' /SHARE='EXE_DIR''ENGINE_NAME'.EXE -
-       'OBJECT_FILE''TV_OBJ', -
-       'CRYPTO_LIB'/LIBRARY, -
-       'ENGINE_OPT'/OPTION,'TCPIP_LIB','OPT_FILE'/OPTION
-$ ELSE
-$   LINK/'DEBUGGER'/'TRACEBACK' /SHARE='EXE_DIR''ENGINE_NAME'.EXE -
-       'OBJECT_FILE''TV_OBJ', -
-        'CRYPTO_LIB'/LIBRARY, -
-       'ENGINE_OPT'/OPTION,'OPT_FILE'/OPTION
-$ ENDIF
-$!
-$! Clean up
-$!
-$ DELETE 'OBJECT_FILE';*
-$!
-$! Next file
-$!
-$ GOTO FILE_NEXT
-$!
-$ FILE_DONE:
+$ LINK /'DEBUGGER' /'LINKMAP' /'TRACEBACK' /SHARE='EXE_DIR''ENGINE_NAME'.EXE -
+   'EXE_DIR''ENGINE_NAME'.OPT /OPTIONS -
+   'TV_OBJ', -
+   'CRYPTO_LIB' /LIBRARY, -
+   'ENGINE_OPT' /OPTIONS -
+   'TCPIP_LIB' -
+   'ZLIB_LIB' -
+   ,'OPT_FILE' /OPTIONS
 $!
 $! Next engine
 $!
@@ -272,7 +346,7 @@ $!
 $     CREATE 'OPT_FILE'
 $DECK
 !
-! Default System Options File To Link Agianst 
+! Default System Options File To Link Against 
 ! The Sharable VAX C Runtime Library.
 !
 SYS$SHARE:VAXCRTL.EXE/SHARE
@@ -301,7 +375,7 @@ $!
 $     CREATE 'OPT_FILE'
 $DECK
 !
-! Default System Options File To Link Agianst 
+! Default System Options File To Link Against 
 ! The Sharable C Runtime Library.
 !
 GNU_CC:[000000]GCCLIB/LIBRARY
@@ -336,7 +410,7 @@ $!
 $       CREATE 'OPT_FILE'
 $DECK
 !
-! Default System Options File To Link Agianst 
+! Default System Options File To Link Against 
 ! The Sharable DEC C Runtime Library.
 !
 SYS$SHARE:DECC$SHR.EXE/SHARE
@@ -351,7 +425,7 @@ $!
 $       CREATE 'OPT_FILE'
 $DECK
 !
-! Default System Options File For non-VAX To Link Agianst 
+! Default System Options File For non-VAX To Link Against 
 ! The Sharable C Runtime Library.
 !
 SYS$SHARE:CMA$OPEN_LIB_SHR/SHARE
@@ -395,13 +469,13 @@ $! Else...
 $!
 $ ELSE
 $!
-$!  Else, Check To See If OPT_PHASE Has A Valid Arguement.
+$!  Else, Check To See If OPT_PHASE Has A Valid Argument.
 $!
 $   IF ("," + ACCEPT_PHASE + ",") - ("," + OPT_PHASE + ",") -
        .NES. ("," + ACCEPT_PHASE + ",")
 $   THEN
 $!
-$!    A Valid Arguement.
+$!    A Valid Argument.
 $!
 $     BUILDALL = OPT_PHASE
 $!
@@ -423,8 +497,8 @@ $     IF ("," + ACCEPT_PHASE + ",") - ",ENGINES," -
 $     WRITE SYS$OUTPUT ""
 $     WRITE SYS$OUTPUT " where 'xxx' stands for:"
 $     WRITE SYS$OUTPUT ""
-$     WRITE SYS$OUTPUT "    ALPHA    :  Alpha architecture."
-$     WRITE SYS$OUTPUT "    IA64     :  IA64 architecture."
+$     WRITE SYS$OUTPUT "    ALPHA[64]:  Alpha architecture."
+$     WRITE SYS$OUTPUT "    IA64[64] :  IA64 architecture."
 $     WRITE SYS$OUTPUT "    VAX      :  VAX architecture."
 $     WRITE SYS$OUTPUT ""
 $!
@@ -432,7 +506,7 @@ $!    Time To EXIT.
 $!
 $     EXIT
 $!
-$!  End The Valid Arguement Check.
+$!  End The Valid Argument Check.
 $!
 $   ENDIF
 $!
@@ -445,15 +519,16 @@ $!
 $ IF (OPT_DEBUG.EQS."NODEBUG")
 $ THEN
 $!
-$!   OPT_DEBUG Is NODEBUG, So Compile Without The Debugger Information.
+$!  OPT_DEBUG Is NODEBUG, So Compile Without The Debugger Information.
 $!
-$    DEBUGGER = "NODEBUG"
-$    TRACEBACK = "NOTRACEBACK" 
-$    GCC_OPTIMIZE = "OPTIMIZE"
-$    CC_OPTIMIZE = "OPTIMIZE"
-$    MACRO_OPTIMIZE = "OPTIMIZE"
-$    WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile."
-$    WRITE SYS$OUTPUT "Compiling With Compiler Optimization."
+$   DEBUGGER = "NODEBUG"
+$   LINKMAP = "NOMAP"
+$   TRACEBACK = "NOTRACEBACK" 
+$   GCC_OPTIMIZE = "OPTIMIZE"
+$   CC_OPTIMIZE = "OPTIMIZE"
+$   MACRO_OPTIMIZE = "OPTIMIZE"
+$   WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile."
+$   WRITE SYS$OUTPUT "Compiling With Compiler Optimization."
 $ ELSE
 $!
 $!  Check To See If We Are To Compile With Debugger Information.
@@ -464,6 +539,7 @@ $!
 $!    Compile With Debugger Information.
 $!
 $     DEBUGGER = "DEBUG"
+$     LINKMAP = "MAP"
 $     TRACEBACK = "TRACEBACK"
 $     GCC_OPTIMIZE = "NOOPTIMIZE"
 $     CC_OPTIMIZE = "NOOPTIMIZE"
@@ -472,7 +548,7 @@ $     WRITE SYS$OUTPUT "Debugger Information Will Be Produced During Compile."
 $     WRITE SYS$OUTPUT "Compiling Without Compiler Optimization."
 $   ELSE 
 $!
-$!    They Entered An Invalid Option..
+$!    They Entered An Invalid Option.
 $!
 $     WRITE SYS$OUTPUT ""
 $     WRITE SYS$OUTPUT "The Option ",OPT_DEBUG," Is Invalid.  The Valid Options Are:"
@@ -485,7 +561,7 @@ $!    Time To EXIT.
 $!
 $     EXIT
 $!
-$!  End The Valid Arguement Check.
+$!  End The Valid Argument Check.
 $!
 $   ENDIF
 $!
@@ -527,6 +603,59 @@ $! End The OPT_SPECIAL_THREADS Check.
 $!
 $ ENDIF
 $!
+$! Check OPT_POINTER_SIZE (P7).
+$!
+$ IF (OPT_POINTER_SIZE .NES. "") .AND. (ARCH .NES. "VAX")
+$ THEN
+$!
+$   IF (OPT_POINTER_SIZE .EQS. "32")
+$   THEN
+$     POINTER_SIZE = " /POINTER_SIZE=32"
+$   ELSE
+$     POINTER_SIZE = F$EDIT( OPT_POINTER_SIZE, "COLLAPSE, UPCASE")
+$     IF ((POINTER_SIZE .EQS. "64") .OR. -
+       (POINTER_SIZE .EQS. "64=") .OR. -
+       (POINTER_SIZE .EQS. "64=ARGV"))
+$     THEN
+$       ARCHD = ARCH+ "_64"
+$       LIB32 = ""
+$       POINTER_SIZE = " /POINTER_SIZE=64"
+$     ELSE
+$!
+$!      Tell The User Entered An Invalid Option.
+$!
+$       WRITE SYS$OUTPUT ""
+$       WRITE SYS$OUTPUT "The Option ", OPT_POINTER_SIZE, -
+         " Is Invalid.  The Valid Options Are:"
+$       WRITE SYS$OUTPUT ""
+$       WRITE SYS$OUTPUT -
+         "    """"       :  Compile with default (short) pointers."
+$       WRITE SYS$OUTPUT -
+         "    32       :  Compile with 32-bit (short) pointers."
+$       WRITE SYS$OUTPUT -
+         "    64       :  Compile with 64-bit (long) pointers (auto ARGV)."
+$       WRITE SYS$OUTPUT -
+         "    64=      :  Compile with 64-bit (long) pointers (no ARGV)."
+$       WRITE SYS$OUTPUT -
+         "    64=ARGV  :  Compile with 64-bit (long) pointers (ARGV)."
+$       WRITE SYS$OUTPUT ""
+$! 
+$!      Time To EXIT.
+$!
+$       EXIT
+$!
+$     ENDIF
+$!
+$   ENDIF
+$!
+$! End The OPT_POINTER_SIZE Check.
+$!
+$ ENDIF
+$!
+$! Set basic C compiler /INCLUDE directories.
+$!
+$ CC_INCLUDES = "SYS$DISK:[],SYS$DISK:[.VENDOR_DEFNS]"
+$!
 $! Check To See If OPT_COMPILER Is Blank.
 $!
 $ IF (OPT_COMPILER.EQS."")
@@ -627,11 +756,63 @@ $ CCDEFS = "TCPIP_TYPE_''OPT_TCPIP_LIB',DSO_VMS"
 $ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS
 $ CCEXTRAFLAGS = ""
 $ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS
-$ CCDISABLEWARNINGS = "LONGLONGTYPE,LONGLONGSUFX"
+$ CCDISABLEWARNINGS = "" !!! "LONGLONGTYPE,LONGLONGSUFX"
 $ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN -
        CCDISABLEWARNINGS = CCDISABLEWARNINGS + "," + USER_CCDISABLEWARNINGS
 $!
-$!  Check To See If The User Entered A Valid Paramter.
+$! Check To See If We Have A ZLIB Option.
+$!
+$ IF (ZLIB .NES. "")
+$ THEN
+$!
+$!  Check for expected ZLIB files.
+$!
+$   err = 0
+$   file1 = f$parse( "zlib.h", ZLIB, , , "SYNTAX_ONLY")
+$   if (f$search( file1) .eqs. "")
+$   then
+$     WRITE SYS$OUTPUT ""
+$     WRITE SYS$OUTPUT "The Option ", ZLIB, " Is Invalid."
+$     WRITE SYS$OUTPUT "    Can't find header: ''file1'"
+$     err = 1
+$   endif
+$   file1 = f$parse( "A.;", ZLIB)- "A.;"
+$!
+$   file2 = f$parse( ZLIB, "libz.olb", , , "SYNTAX_ONLY")
+$   if (f$search( file2) .eqs. "")
+$   then
+$     if (err .eq. 0)
+$     then
+$       WRITE SYS$OUTPUT ""
+$       WRITE SYS$OUTPUT "The Option ", ZLIB, " Is Invalid."
+$     endif
+$     WRITE SYS$OUTPUT "    Can't find library: ''file2'"
+$     WRITE SYS$OUTPUT ""
+$     err = err+ 2
+$   endif
+$   if (err .eq. 1)
+$   then
+$     WRITE SYS$OUTPUT ""
+$   endif
+$!
+$   if (err .ne. 0)
+$   then
+$     EXIT
+$   endif
+$!
+$   CCDEFS = """ZLIB=1"", "+ CCDEFS
+$   CC_INCLUDES = CC_INCLUDES+ ", "+ file1
+$   ZLIB_LIB = ", ''file2' /library"
+$!
+$!  Print info
+$!
+$   WRITE SYS$OUTPUT "ZLIB library spec: ", file2
+$!
+$! End The ZLIB Check.
+$!
+$ ENDIF
+$!
+$!  Check To See If The User Entered A Valid Parameter.
 $!
 $ IF (OPT_COMPILER.EQS."VAXC").OR.(OPT_COMPILER.EQS."DECC").OR.(OPT_COMPILER.EQS."GNUC")
 $ THEN
@@ -654,14 +835,14 @@ $!
 $     CC = "CC"
 $     IF ARCH.EQS."VAX" .AND. F$TRNLNM("DECC$CC_DEFAULT").NES."/DECC" -
         THEN CC = "CC/DECC"
-$     CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/STANDARD=ANSI89" + -
-           "/NOLIST/PREFIX=ALL" + -
-          "/INCLUDE=(SYS$DISK:[],SYS$DISK:[.VENDOR_DEFNS])" + -
-          CCEXTRAFLAGS
+$     CC = CC + " /''CC_OPTIMIZE' /''DEBUGGER' /STANDARD=RELAXED"+ -
+       "''POINTER_SIZE' /NOLIST /PREFIX=ALL" + -
+       " /INCLUDE=(''CC_INCLUDES') " + -
+       CCEXTRAFLAGS
 $!
 $!    Define The Linker Options File Name.
 $!
-$     OPT_FILE = "''EXE_DIR'VAX_DECC_OPTIONS.OPT"
+$     OPT_FILE = "VAX_DECC_OPTIONS.OPT"
 $!
 $!  End DECC Check.
 $!
@@ -690,7 +871,7 @@ $   EXIT
 $     ENDIF
 $     IF F$TRNLNM("DECC$CC_DEFAULT").EQS."/DECC" THEN CC = "CC/VAXC"
 $     CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/NOLIST" + -
-          "/INCLUDE=(SYS$DISK:[],SYS$DISK:[-],SYS$DISK:[.ENGINE.VENDOR_DEFNS])" + -
+          "/INCLUDE=(''CC_INCLUDES')" + -
           CCEXTRAFLAGS
 $     CCDEFS = """VAXC""," + CCDEFS
 $!
@@ -700,7 +881,7 @@ $     DEFINE/NOLOG SYS SYS$COMMON:[SYSLIB]
 $!
 $!    Define The Linker Options File Name.
 $!
-$     OPT_FILE = "''EXE_DIR'VAX_VAXC_OPTIONS.OPT"
+$     OPT_FILE = "VAX_VAXC_OPTIONS.OPT"
 $!
 $!  End VAXC Check
 $!
@@ -722,12 +903,12 @@ $!
 $!    Use GNU C...
 $!
 $     CC = "GCC/NOCASE_HACK/''GCC_OPTIMIZE'/''DEBUGGER'/NOLIST" + -
-          "/INCLUDE=(SYS$DISK:[],SYS$DISK:[-],SYS$DISK:[.ENGINE.VENDOR_DEFNS])" + -
+          "/INCLUDE=(''CC_INCLUDES')" + -
           CCEXTRAFLAGS
 $!
 $!    Define The Linker Options File Name.
 $!
-$     OPT_FILE = "''EXE_DIR'VAX_GNUC_OPTIONS.OPT"
+$     OPT_FILE = "VAX_GNUC_OPTIONS.OPT"
 $!
 $!  End The GNU C Check.
 $!
@@ -743,18 +924,18 @@ $   IF COMPILER .EQS. "DECC"
 $   THEN
 $     IF CCDISABLEWARNINGS .NES. ""
 $     THEN
-$       CCDISABLEWARNINGS = "/WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))"
+$       CCDISABLEWARNINGS = " /WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))"
 $     ENDIF
 $   ELSE
 $     CCDISABLEWARNINGS = ""
 $   ENDIF
-$   CC = CC + "/DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS
+$   CC = CC + " /DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS
 $!
 $!  Show user the result
 $!
 $   WRITE/SYMBOL SYS$OUTPUT "Main C Compiling Command: ",CC
 $!
-$!  Else The User Entered An Invalid Arguement.
+$!  Else The User Entered An Invalid Argument.
 $!
 $ ELSE
 $!
@@ -772,14 +953,18 @@ $!  Time To EXIT.
 $!
 $   EXIT
 $!
-$! End The Valid Arguement Check.
+$! End The Valid Argument Check.
 $!
 $ ENDIF
 $!
 $! Build a MACRO command for the architecture at hand
 $!
-$ IF ARCH .EQS. "VAX" THEN MACRO = "MACRO/''DEBUGGER'"
-$ IF ARCH .NES. "VAX" THEN MACRO = "MACRO/MIGRATION/''DEBUGGER'/''MACRO_OPTIMIZE'"
+$ IF ARCH .EQS. "VAX"
+$ THEN
+$   MACRO = "MACRO/''DEBUGGER'"
+$ ELSE
+$   MACRO = "MACRO/MIGRATION/''DEBUGGER'/''MACRO_OPTIMIZE'"
+$ ENDIF
 $!
 $!  Show user the result
 $!
@@ -799,7 +984,7 @@ $   THEN
 $!
 $!    Set the library to use SOCKETSHR
 $!
-$     TCPIP_LIB = "SYS$DISK:[-.VMS]SOCKETSHR_SHR.OPT/OPT"
+$     TCPIP_LIB = ",SYS$DISK:[-.VMS]SOCKETSHR_SHR.OPT /OPTIONS"
 $!
 $!    Done with SOCKETSHR
 $!
@@ -825,13 +1010,13 @@ $   THEN
 $!
 $!    Set the library to use UCX.
 $!
-$     TCPIP_LIB = "SYS$DISK:[-.VMS]UCX_SHR_DECC.OPT/OPT"
+$     TCPIP_LIB = "SYS$DISK:[-.VMS]UCX_SHR_DECC.OPT /OPTIONS"
 $     IF F$TRNLNM("UCX$IPC_SHR") .NES. ""
 $     THEN
-$       TCPIP_LIB = "SYS$DISK:[-.VMS]UCX_SHR_DECC_LOG.OPT/OPT"
+$       TCPIP_LIB = ",SYS$DISK:[-.VMS]UCX_SHR_DECC_LOG.OPT /OPTIONS"
 $     ELSE
 $       IF COMPILER .NES. "DECC" .AND. ARCH .EQS. "VAX" THEN -
-         TCPIP_LIB = "SYS$DISK:[-.VMS]UCX_SHR_VAXC.OPT/OPT"
+         TCPIP_LIB = ",SYS$DISK:[-.VMS]UCX_SHR_VAXC.OPT /OPTIONS"
 $     ENDIF
 $!
 $!    Done with UCX
@@ -845,7 +1030,7 @@ $   THEN
 $!
 $!    Set the library to use TCPIP (post UCX).
 $!
-$     TCPIP_LIB = "SYS$DISK:[-.VMS]TCPIP_SHR_DECC.OPT/OPT"
+$     TCPIP_LIB = ",SYS$DISK:[-.VMS]TCPIP_SHR_DECC.OPT /OPTIONS"
 $!
 $!    Done with TCPIP
 $!
@@ -866,9 +1051,9 @@ $   ENDIF
 $!
 $!  Print info
 $!
-$   WRITE SYS$OUTPUT "TCP/IP library spec: ", TCPIP_LIB
+$   WRITE SYS$OUTPUT "TCP/IP library spec: ", TCPIP_LIB- ","
 $!
-$!  Else The User Entered An Invalid Arguement.
+$!  Else The User Entered An Invalid Argument.
 $!
 $ ELSE
 $!
@@ -909,7 +1094,7 @@ $ __INCLUDE = __TOP + "INCLUDE.OPENSSL]"
 $!
 $! Set up the logical name OPENSSL to point at the include directory
 $!
-$ DEFINE OPENSSL/NOLOG '__INCLUDE'
+$ DEFINE OPENSSL /NOLOG '__INCLUDE'
 $!
 $! Done
 $!
@@ -917,15 +1102,24 @@ $ RETURN
 $!
 $ CLEANUP:
 $!
-$! Restore the logical name OPENSSL if it had a value
+$! Restore the saved logical name OPENSSL, if it had a value.
 $!
-$ IF __SAVE_OPENSSL .EQS. ""
-$ THEN
-$   DEASSIGN OPENSSL
-$ ELSE
-$   DEFINE/NOLOG OPENSSL '__SAVE_OPENSSL'
-$ ENDIF
+$ if (f$type( __SAVE_OPENSSL) .nes. "")
+$ then
+$   IF __SAVE_OPENSSL .EQS. ""
+$   THEN
+$     DEASSIGN OPENSSL
+$   ELSE
+$     DEFINE /NOLOG OPENSSL '__SAVE_OPENSSL'
+$   ENDIF
+$ endif
+$!
+$! Close any open files.
+$!
+$ if (f$trnlnm( "objects", "LNM$PROCESS", 0, "SUPERVISOR") .nes. "") then -
+   close objects
 $!
 $! Done
 $!
 $ RETURN
+$!
diff --git a/deps/openssl/openssl/fips/Makefile b/deps/openssl/openssl/fips/Makefile
deleted file mode 100644 (file)
index 546b54b..0000000
+++ /dev/null
@@ -1,230 +0,0 @@
-#
-# OpenSSL/crypto/Makefile
-#
-
-DIR=           fips
-TOP=           ..
-CC=            cc
-INCLUDE=       -I. -I$(TOP) -I../include
-# INCLUDES targets sudbirs!
-INCLUDES=      -I.. -I../.. -I../../include
-CFLAG=         -g
-MAKEDEPPROG=   makedepend
-MAKEDEPEND=    $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
-MAKEFILE=       Makefile
-RM=             rm -f
-AR=            ar r
-ARD=           ar d
-TEST=          fips_test_suite.c
-FIPS_TVDIR=    testvectors
-FIPS_TVOK=     $$HOME/fips/tv.ok
-
-FIPSCANLOC=    $(FIPSLIBDIR)fipscanister.o
-
-RECURSIVE_MAKE=        [ -n "$(FDIRS)" ] && for i in $(FDIRS) ; do \
-                   (cd $$i && echo "making $$target in $(DIR)/$$i..." && \
-                   $(MAKE) -e TOP=../.. DIR=$$i INCLUDES='${INCLUDES}' $$target ) || exit 1; \
-               done;
-
-PEX_LIBS=
-EX_LIBS=
-CFLAGS= $(INCLUDE) $(CFLAG) -DHMAC_EXT=\"$${HMAC_EXT:-sha1}\"
-ASFLAGS= $(INCLUDE) $(ASFLAG)
-AFLAGS=$(ASFLAGS)
-
-LIBS=
-
-FDIRS=sha rand des aes dsa rsa dh hmac
-
-GENERAL=Makefile README fips-lib.com install.com
-
-LIB= $(TOP)/libcrypto.a
-SHARED_LIB= $(FIPSCANLIB)$(SHLIB_EXT)
-LIBSRC=fips.c 
-LIBOBJ=fips.o
-
-FIPS_OBJ_LISTS=sha/lib hmac/lib rand/lib des/lib aes/lib dsa/lib rsa/lib dh/lib
-
-SRC= $(LIBSRC)
-
-EXHEADER=fips.h
-HEADER=$(EXHEADER) fips_utl.h fips_locl.h
-EXE=fipsld
-
-ALL=    $(GENERAL) $(SRC) $(HEADER)
-
-top:
-       @(cd ..; $(MAKE) DIRS=$(DIR) all)
-
-testapps:
-       @if [ -z "$(THIS)" ]; then $(MAKE) -f $(TOP)/Makefile reflect THIS=$@; fi
-
-all:
-       @if [ -z "$(FIPSLIBDIR)" ]; then \
-               $(MAKE) -e subdirs lib fips_premain_dso$(EXE_EXT); \
-       else  \
-               $(MAKE) -e lib fips_premain_dso$(EXE_EXT) fips_standalone_sha1$(EXE_EXT); \
-       fi
-
-# Idea behind fipscanister.o is to "seize" the sequestered code between
-# known symbols for fingerprinting purposes, which would be commonly
-# done with ld -r start.o ... end.o. The latter however presents a minor
-# challenge on multi-ABI platforms. As just implied, we'd rather use ld,
-# but the trouble is that we don't generally know how ABI-selection
-# compiler flag is translated to corresponding linker flag. All compiler
-# drivers seem to recognize -r flag and pass it down to linker, but some
-# of them, including gcc, erroneously add -lc, as well as run-time
-# components, such as crt1.o and alike. Fortunately among those vendor
-# compilers which were observed to misinterpret -r flag multi-ABI ones
-# are equipped with smart linkers, which don't require any ABI-selection
-# flag and simply assume that all objects are of the same type as first
-# one in command line. So the idea is to identify gcc and deficient
-# vendor compiler drivers...
-
-fipscanister.o: fips_start.o $(LIBOBJ) $(FIPS_OBJ_LISTS) fips_end.o
-       FIPS_ASM=""; \
-       list="$(BN_ASM)"; for i in $$list; do FIPS_ASM="$$FIPS_ASM ../crypto/bn/$$i" ; done; \
-       list="$(AES_ASM_OBJ)"; for i in $$list; do FIPS_ASM="$$FIPS_ASM ../crypto/aes/$$i" ; done; \
-       list="$(DES_ENC)"; for i in $$list; do FIPS_ASM="$$FIPS_ASM ../crypto/des/$$i" ; done; \
-       list="$(SHA1_ASM_OBJ)"; for i in $$list; do FIPS_ASM="$$FIPS_ASM ../crypto/sha/$$i" ; done; \
-       if [ -n "$(CPUID_OBJ)" ]; then \
-               CPUID=../crypto/$(CPUID_OBJ) ; \
-       else \
-               CPUID="" ; \
-       fi ; \
-       objs="fips_start.o $(LIBOBJ) $(FIPS_EX_OBJ) $$CPUID $$FIPS_ASM"; \
-       for i in $(FIPS_OBJ_LISTS); do \
-               dir=`dirname $$i`; script="s|^|$$dir/|;s| | $$dir/|g"; \
-               objs="$$objs `sed "$$script" $$i`"; \
-       done; \
-       objs="$$objs fips_end.o" ; \
-       os="`(uname -s) 2>/dev/null`"; cflags="$(CFLAGS)"; \
-       [ "$$os" = "AIX" ] && cflags="$$cflags -Wl,-bnoobjreorder"; \
-       if [ -n "${FIPS_SITE_LD}" ]; then \
-               set -x; ${FIPS_SITE_LD} -r -o $@ $$objs; \
-       elif $(CC) -dumpversion >/dev/null 2>&1; then \
-               set -x; $(CC) $$cflags -r -nostdlib -o $@ $$objs ; \
-       else case "$$os" in \
-               HP-UX|OSF1|SunOS) set -x; /usr/ccs/bin/ld -r -o $@ $$objs ;; \
-               *) set -x; $(CC) $$cflags -r -o $@ $$objs ;; \
-       esac fi
-       ./fips_standalone_sha1$(EXE_EXT) fipscanister.o > fipscanister.o.sha1
-
-# If another exception is immediately required, assign approprite
-# site-specific ld command to FIPS_SITE_LD environment variable.
-
-fips_start.o: fips_canister.c
-       $(CC) $(CFLAGS) -DFIPS_START -c -o $@ fips_canister.c
-fips_end.o: fips_canister.c
-       $(CC) $(CFLAGS) -DFIPS_END -c -o $@ fips_canister.c
-fips_premain_dso$(EXE_EXT): fips_premain.c
-       $(CC) $(CFLAGS) -DFINGERPRINT_PREMAIN_DSO_LOAD -o $@ fips_premain.c \
-               $(FIPSLIBDIR)fipscanister.o ../libcrypto.a $(EX_LIBS)
-# this is executed only when linking with external fipscanister.o
-fips_standalone_sha1$(EXE_EXT):        sha/fips_standalone_sha1.c
-       if [ -z "$(HOSTCC)" ] ; then \
-               $(CC) $(CFLAGS) -DFIPSCANISTER_O -o $@ sha/fips_standalone_sha1.c $(FIPSLIBDIR)fipscanister.o $(EX_LIBS) ; \
-       else \
-               $(HOSTCC) $(HOSTCFLAGS) -o $ $@ -I../include -I../crypto sha/fips_standalone_sha1.c ../crypto/sha/sha1dgst.c ; \
-       fi
-
-subdirs:
-       @target=all; $(RECURSIVE_MAKE)
-
-files:
-       $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
-       @target=files; $(RECURSIVE_MAKE)
-
-links:
-       @$(PERL) $(TOP)/util/mklink.pl ../include/openssl $(EXHEADER)
-       @$(PERL) $(TOP)/util/mklink.pl ../test $(TEST)
-       @target=links; $(RECURSIVE_MAKE)
-
-# lib: and $(LIB): are splitted to avoid end-less loop
-lib:   $(LIB)
-       if [ "$(FIPSCANISTERINTERNAL)" = "n" -a -n "$(FIPSCANLOC)" ]; then $(AR) ../$(FIPSCANLIB).a $(FIPSCANLOC); fi
-       @touch lib
-
-$(LIB):        $(FIPSLIBDIR)fipscanister.o
-       $(AR) $(LIB) $(FIPSLIBDIR)fipscanister.o
-       $(RANLIB) $(LIB) || echo Never mind.
-
-$(FIPSCANLIB): $(FIPSCANLOC)
-       $(AR) ../$(FIPSCANLIB).a $(FIPSCANLOC)
-       if [ "$(FIPSCANLIB)" = "libfips" ]; then \
-               $(AR) $(LIB) $(FIPSCANLOC) ; \
-               $(RANLIB) $(LIB) || echo Never Mind. ; \
-       fi
-       $(RANLIB) ../$(FIPSCANLIB).a || echo Never mind.
-       @touch lib
-
-shared:        lib subdirs fips_premain_dso$(EXE_EXT)
-
-libs:
-       @target=lib; $(RECURSIVE_MAKE)
-
-fips_test: top
-       @target=fips_test; $(RECURSIVE_MAKE)
-
-fips_test_diff:
-       @if diff -b -B -I '^\#' -cr -X fips-nodiff.txt $(FIPS_TVDIR) $(FIPS_TVOK) ; then \
-               echo "FIPS diff OK" ; \
-       else \
-               echo "***FIPS DIFF ERROR***" ; exit 1 ; \
-       fi
-
-
-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;
-       @target=install; $(RECURSIVE_MAKE)
-       for i in $(EXE) ; \
-       do \
-               echo "installing $$i"; \
-               cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new; \
-               chmod 755 $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new; \
-               mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i; \
-       done
-       cp -p -f $(FIPSLIBDIR)fipscanister.o $(FIPSLIBDIR)fipscanister.o.sha1 \
-               $(FIPSLIBDIR)fips_premain.c $(FIPSLIBDIR)fips_premain.c.sha1 \
-               $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/; \
-       chmod 0444 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/fips*
-
-lint:
-       @target=lint; $(RECURSIVE_MAKE)
-
-depend:
-       @[ -z "$(THIS)" ] || $(MAKEDEPEND) -- $(CFLAG) $(INCLUDE) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
-       @[ -z "$(THIS)" ] || (set -e; target=depend; $(RECURSIVE_MAKE) )
-       @if [ -z "$(THIS)" ]; then $(MAKE) -f $(TOP)/Makefile reflect THIS=$@; fi
-
-clean:
-       rm -f fipscanister.o.sha1 fips_premain_dso$(EXE_EXT) fips_standalone_sha1$(EXE_EXT) \
-               *.s *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
-       @target=clean; $(RECURSIVE_MAKE)
-
-dclean:
-       $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
-       mv -f Makefile.new $(MAKEFILE)
-       @target=dclean; $(RECURSIVE_MAKE)
-
-# DO NOT DELETE THIS LINE -- make depend depends on it.
-
-fips.o: ../include/openssl/asn1.h ../include/openssl/bio.h
-fips.o: ../include/openssl/crypto.h ../include/openssl/des.h
-fips.o: ../include/openssl/des_old.h ../include/openssl/e_os2.h
-fips.o: ../include/openssl/err.h ../include/openssl/evp.h
-fips.o: ../include/openssl/fips.h ../include/openssl/fips_rand.h
-fips.o: ../include/openssl/hmac.h ../include/openssl/lhash.h
-fips.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
-fips.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
-fips.o: ../include/openssl/ossl_typ.h ../include/openssl/rand.h
-fips.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-fips.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-fips.o: ../include/openssl/ui.h ../include/openssl/ui_compat.h fips.c
-fips.o: fips_locl.h
diff --git a/deps/openssl/openssl/fips/aes/Makefile b/deps/openssl/openssl/fips/aes/Makefile
deleted file mode 100644 (file)
index 7b8b3a2..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-#
-# OpenSSL/fips/aes/Makefile
-#
-
-DIR=   aes
-TOP=   ../..
-CC=    cc
-INCLUDES=
-CFLAG=-g
-INSTALL_PREFIX=
-OPENSSLDIR=     /usr/local/ssl
-INSTALLTOP=/usr/local/ssl
-MAKEDEPPROG=   makedepend
-MAKEDEPEND=    $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
-MAKEFILE=      Makefile
-AR=            ar r
-
-ASFLAGS= $(INCLUDES) $(ASFLAG)
-AFLAGS= $(ASFLAGS)
-
-CFLAGS= $(INCLUDES) $(CFLAG)
-
-GENERAL=Makefile
-TEST=fips_aesavs.c
-APPS=
-
-LIB=$(TOP)/libcrypto.a
-LIBSRC=fips_aes_selftest.c
-LIBOBJ=fips_aes_selftest.o
-
-SRC= $(LIBSRC)
-
-EXHEADER=
-HEADER=
-
-ALL=    $(GENERAL) $(SRC) $(HEADER)
-
-top:
-       (cd $(TOP); $(MAKE) DIRS=fips FDIRS=$(DIR) sub_all)
-
-all:   lib
-
-lib:   $(LIBOBJ)
-       @echo $(LIBOBJ) > lib
-
-files:
-       $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
-
-links:
-       @$(PERL) $(TOP)/util/mklink.pl $(TOP)/include/openssl $(EXHEADER)
-       @$(PERL) $(TOP)/util/mklink.pl $(TOP)/test $(TEST)
-       @$(PERL) $(TOP)/util/mklink.pl $(TOP)/apps $(APPS)
-
-install:
-       @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:
-
-fips_test:
-       -find ../testvectors/aes/req -name '*.req' > testlist
-       -rm -rf ../testvectors/aes/rsp
-       mkdir ../testvectors/aes/rsp
-       if [ -s testlist ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_aesavs -d testlist; fi
-
-lint:
-       lint -DLINT $(INCLUDES) $(SRC)>fluff
-
-depend:
-       $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) \
-               $(SRC) $(TEST)
-
-dclean:
-       $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
-       mv -f Makefile.new $(MAKEFILE)
-
-clean:
-       rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff testlist
-# DO NOT DELETE THIS LINE -- make depend depends on it.
-
-fips_aes_selftest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-fips_aes_selftest.o: ../../include/openssl/crypto.h
-fips_aes_selftest.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-fips_aes_selftest.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-fips_aes_selftest.o: ../../include/openssl/lhash.h
-fips_aes_selftest.o: ../../include/openssl/obj_mac.h
-fips_aes_selftest.o: ../../include/openssl/objects.h
-fips_aes_selftest.o: ../../include/openssl/opensslconf.h
-fips_aes_selftest.o: ../../include/openssl/opensslv.h
-fips_aes_selftest.o: ../../include/openssl/ossl_typ.h
-fips_aes_selftest.o: ../../include/openssl/safestack.h
-fips_aes_selftest.o: ../../include/openssl/stack.h
-fips_aes_selftest.o: ../../include/openssl/symhacks.h fips_aes_selftest.c
-fips_aesavs.o: ../../e_os.h ../../include/openssl/aes.h
-fips_aesavs.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-fips_aesavs.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
-fips_aesavs.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-fips_aesavs.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-fips_aesavs.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-fips_aesavs.o: ../../include/openssl/objects.h
-fips_aesavs.o: ../../include/openssl/opensslconf.h
-fips_aesavs.o: ../../include/openssl/opensslv.h
-fips_aesavs.o: ../../include/openssl/ossl_typ.h
-fips_aesavs.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-fips_aesavs.o: ../../include/openssl/symhacks.h ../fips_utl.h fips_aesavs.c
diff --git a/deps/openssl/openssl/fips/aes/fips_aes_selftest.c b/deps/openssl/openssl/fips/aes/fips_aes_selftest.c
deleted file mode 100644 (file)
index 441bbc1..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/* ====================================================================
- * Copyright (c) 2003 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    openssl-core@openssl.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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 <string.h>
-#include <openssl/err.h>
-#include <openssl/fips.h>
-#include <openssl/evp.h>
-
-#ifdef OPENSSL_FIPS
-static struct
-    {
-    unsigned char key[16];
-    unsigned char plaintext[16];
-    unsigned char ciphertext[16];
-    } tests[]=
-       {
-       {
-       { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
-         0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F },
-       { 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,
-         0x88,0x99,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF },
-       { 0x69,0xC4,0xE0,0xD8,0x6A,0x7B,0x04,0x30,
-         0xD8,0xCD,0xB7,0x80,0x70,0xB4,0xC5,0x5A },
-       },
-       };
-
-void FIPS_corrupt_aes()
-    {
-    tests[0].key[0]++;
-    }
-
-int FIPS_selftest_aes()
-    {
-    int n;
-    int ret = 0;
-    EVP_CIPHER_CTX ctx;
-    EVP_CIPHER_CTX_init(&ctx);
-
-    for(n=0 ; n < 1 ; ++n)
-       {
-       if (fips_cipher_test(&ctx, EVP_aes_128_ecb(),
-                               tests[n].key, NULL,
-                               tests[n].plaintext,
-                               tests[n].ciphertext,
-                               16) <= 0)
-               goto err;
-       }
-    ret = 1;
-    err:
-    EVP_CIPHER_CTX_cleanup(&ctx);
-    if (ret == 0)
-           FIPSerr(FIPS_F_FIPS_SELFTEST_AES,FIPS_R_SELFTEST_FAILED);
-    return ret;
-    }
-#endif
diff --git a/deps/openssl/openssl/fips/aes/fips_aesavs.c b/deps/openssl/openssl/fips/aes/fips_aesavs.c
deleted file mode 100644 (file)
index a3c8b40..0000000
+++ /dev/null
@@ -1,939 +0,0 @@
-/* ====================================================================
- * Copyright (c) 2004 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    openssl-core@openssl.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
- *
- */
-/*---------------------------------------------
-  NIST AES Algorithm Validation Suite
-  Test Program
-
-  Donated to OpenSSL by:
-  V-ONE Corporation
-  20250 Century Blvd, Suite 300
-  Germantown, MD 20874
-  U.S.A.
-  ----------------------------------------------*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-#include <ctype.h>
-#include <openssl/aes.h>
-#include <openssl/evp.h>
-#include <openssl/bn.h>
-
-#include <openssl/err.h>
-#include "e_os.h"
-
-#ifndef OPENSSL_FIPS
-
-int main(int argc, char *argv[])
-{
-    printf("No FIPS AES support\n");
-    return(0);
-}
-
-#else
-
-#include <openssl/fips.h>
-#include "fips_utl.h"
-
-#define AES_BLOCK_SIZE 16
-
-#define VERBOSE 0
-
-/*-----------------------------------------------*/
-
-static int AESTest(EVP_CIPHER_CTX *ctx,
-           char *amode, int akeysz, unsigned char *aKey, 
-           unsigned char *iVec, 
-           int dir,  /* 0 = decrypt, 1 = encrypt */
-           unsigned char *plaintext, unsigned char *ciphertext, int len)
-    {
-    const EVP_CIPHER *cipher = NULL;
-
-    if (strcasecmp(amode, "CBC") == 0)
-       {
-       switch (akeysz)
-               {
-               case 128:
-               cipher = EVP_aes_128_cbc();
-               break;
-
-               case 192:
-               cipher = EVP_aes_192_cbc();
-               break;
-
-               case 256:
-               cipher = EVP_aes_256_cbc();
-               break;
-               }
-
-       }
-    else if (strcasecmp(amode, "ECB") == 0)
-       {
-       switch (akeysz)
-               {
-               case 128:
-               cipher = EVP_aes_128_ecb();
-               break;
-
-               case 192:
-               cipher = EVP_aes_192_ecb();
-               break;
-
-               case 256:
-               cipher = EVP_aes_256_ecb();
-               break;
-               }
-       }
-    else if (strcasecmp(amode, "CFB128") == 0)
-       {
-       switch (akeysz)
-               {
-               case 128:
-               cipher = EVP_aes_128_cfb128();
-               break;
-
-               case 192:
-               cipher = EVP_aes_192_cfb128();
-               break;
-
-               case 256:
-               cipher = EVP_aes_256_cfb128();
-               break;
-               }
-
-       }
-    else if (strncasecmp(amode, "OFB", 3) == 0)
-       {
-       switch (akeysz)
-               {
-               case 128:
-               cipher = EVP_aes_128_ofb();
-               break;
-
-               case 192:
-               cipher = EVP_aes_192_ofb();
-               break;
-
-               case 256:
-               cipher = EVP_aes_256_ofb();
-               break;
-               }
-       }
-    else if(!strcasecmp(amode,"CFB1"))
-       {
-       switch (akeysz)
-               {
-               case 128:
-               cipher = EVP_aes_128_cfb1();
-               break;
-
-               case 192:
-               cipher = EVP_aes_192_cfb1();
-               break;
-
-               case 256:
-               cipher = EVP_aes_256_cfb1();
-               break;
-               }
-       }
-    else if(!strcasecmp(amode,"CFB8"))
-       {
-       switch (akeysz)
-               {
-               case 128:
-               cipher = EVP_aes_128_cfb8();
-               break;
-
-               case 192:
-               cipher = EVP_aes_192_cfb8();
-               break;
-
-               case 256:
-               cipher = EVP_aes_256_cfb8();
-               break;
-               }
-       }
-    else
-       {
-       printf("Unknown mode: %s\n", amode);
-       return 0;
-       }
-    if (!cipher)
-       {
-       printf("Invalid key size: %d\n", akeysz);
-       return 0; 
-       }
-    if (EVP_CipherInit_ex(ctx, cipher, NULL, aKey, iVec, dir) <= 0)
-       return 0;
-    if(!strcasecmp(amode,"CFB1"))
-       M_EVP_CIPHER_CTX_set_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS);
-    if (dir)
-               EVP_Cipher(ctx, ciphertext, plaintext, len);
-       else
-               EVP_Cipher(ctx, plaintext, ciphertext, len);
-    return 1;
-    }
-
-/*-----------------------------------------------*/
-char *t_tag[2] = {"PLAINTEXT", "CIPHERTEXT"};
-char *t_mode[6] = {"CBC","ECB","OFB","CFB1","CFB8","CFB128"};
-enum Mode {CBC, ECB, OFB, CFB1, CFB8, CFB128};
-enum XCrypt {XDECRYPT, XENCRYPT};
-
-/*=============================*/
-/*  Monte Carlo Tests          */
-/*-----------------------------*/
-
-/*#define gb(a,b) (((a)[(b)/8] >> ((b)%8))&1)*/
-/*#define sb(a,b,v) ((a)[(b)/8]=((a)[(b)/8]&~(1 << ((b)%8)))|(!!(v) << ((b)%8)))*/
-
-#define gb(a,b) (((a)[(b)/8] >> (7-(b)%8))&1)
-#define sb(a,b,v) ((a)[(b)/8]=((a)[(b)/8]&~(1 << (7-(b)%8)))|(!!(v) << (7-(b)%8)))
-
-static int do_mct(char *amode, 
-          int akeysz, unsigned char *aKey,unsigned char *iVec,
-          int dir, unsigned char *text, int len,
-          FILE *rfp)
-    {
-    int ret = 0;
-    unsigned char key[101][32];
-    unsigned char iv[101][AES_BLOCK_SIZE];
-    unsigned char ptext[1001][32];
-    unsigned char ctext[1001][32];
-    unsigned char ciphertext[64+4];
-    int i, j, n, n1, n2;
-    int imode = 0, nkeysz = akeysz/8;
-    EVP_CIPHER_CTX ctx;
-    EVP_CIPHER_CTX_init(&ctx);
-
-    if (len > 32)
-       {
-       printf("\n>>>> Length exceeds 32 for %s %d <<<<\n\n", 
-              amode, akeysz);
-       return -1;
-       }
-    for (imode = 0; imode < 6; ++imode)
-       if (strcmp(amode, t_mode[imode]) == 0)
-           break;
-    if (imode == 6)
-       { 
-       printf("Unrecognized mode: %s\n", amode);
-       return -1;
-       }
-
-    memcpy(key[0], aKey, nkeysz);
-    if (iVec)
-       memcpy(iv[0], iVec, AES_BLOCK_SIZE);
-    if (dir == XENCRYPT)
-       memcpy(ptext[0], text, len);
-    else
-       memcpy(ctext[0], text, len);
-    for (i = 0; i < 100; ++i)
-       {
-       /* printf("Iteration %d\n", i); */
-       if (i > 0)
-           {
-           fprintf(rfp,"COUNT = %d\n",i);
-           OutputValue("KEY",key[i],nkeysz,rfp,0);
-           if (imode != ECB)  /* ECB */
-               OutputValue("IV",iv[i],AES_BLOCK_SIZE,rfp,0);
-           /* Output Ciphertext | Plaintext */
-           OutputValue(t_tag[dir^1],dir ? ptext[0] : ctext[0],len,rfp,
-                       imode == CFB1);
-           }
-       for (j = 0; j < 1000; ++j)
-           {
-           switch (imode)
-               {
-           case ECB:
-               if (j == 0)
-                   { /* set up encryption */
-                   ret = AESTest(&ctx, amode, akeysz, key[i], NULL, 
-                                 dir,  /* 0 = decrypt, 1 = encrypt */
-                                 ptext[j], ctext[j], len);
-                   if (dir == XENCRYPT)
-                       memcpy(ptext[j+1], ctext[j], len);
-                   else
-                       memcpy(ctext[j+1], ptext[j], len);
-                   }
-               else
-                   {
-                   if (dir == XENCRYPT)
-                       {
-                       EVP_Cipher(&ctx, ctext[j], ptext[j], len);
-                       memcpy(ptext[j+1], ctext[j], len);
-                       }
-                   else
-                       {
-                       EVP_Cipher(&ctx, ptext[j], ctext[j], len);
-                       memcpy(ctext[j+1], ptext[j], len);
-                       }
-                   }
-               break;
-
-           case CBC:
-           case OFB:  
-           case CFB128:
-               if (j == 0)
-                   {
-                   ret = AESTest(&ctx, amode, akeysz, key[i], iv[i], 
-                                 dir,  /* 0 = decrypt, 1 = encrypt */
-                                 ptext[j], ctext[j], len);
-                   if (dir == XENCRYPT)
-                       memcpy(ptext[j+1], iv[i], len);
-                   else
-                       memcpy(ctext[j+1], iv[i], len);
-                   }
-               else
-                   {
-                   if (dir == XENCRYPT)
-                       {
-                       EVP_Cipher(&ctx, ctext[j], ptext[j], len);
-                       memcpy(ptext[j+1], ctext[j-1], len);
-                       }
-                   else
-                       {
-                       EVP_Cipher(&ctx, ptext[j], ctext[j], len);
-                       memcpy(ctext[j+1], ptext[j-1], len);
-                       }
-                   }
-               break;
-
-           case CFB8:
-               if (j == 0)
-                   {
-                   ret = AESTest(&ctx, amode, akeysz, key[i], iv[i], 
-                                 dir,  /* 0 = decrypt, 1 = encrypt */
-                                 ptext[j], ctext[j], len);
-                   }
-               else
-                   {
-                   if (dir == XENCRYPT)
-                       EVP_Cipher(&ctx, ctext[j], ptext[j], len);
-                   else
-                       EVP_Cipher(&ctx, ptext[j], ctext[j], len);
-                   }
-               if (dir == XENCRYPT)
-                   {
-                   if (j < 16)
-                       memcpy(ptext[j+1], &iv[i][j], len);
-                   else
-                       memcpy(ptext[j+1], ctext[j-16], len);
-                   }
-               else
-                   {
-                   if (j < 16)
-                       memcpy(ctext[j+1], &iv[i][j], len);
-                   else
-                       memcpy(ctext[j+1], ptext[j-16], len);
-                   }
-               break;
-
-           case CFB1:
-               if(j == 0)
-                   {
-#if 0
-                   /* compensate for wrong endianness of input file */
-                   if(i == 0)
-                       ptext[0][0]<<=7;
-#endif
-                   ret = AESTest(&ctx,amode,akeysz,key[i],iv[i],dir,
-                               ptext[j], ctext[j], len);
-                   }
-               else
-                   {
-                   if (dir == XENCRYPT)
-                       EVP_Cipher(&ctx, ctext[j], ptext[j], len);
-                   else
-                       EVP_Cipher(&ctx, ptext[j], ctext[j], len);
-
-                   }
-               if(dir == XENCRYPT)
-                   {
-                   if(j < 128)
-                       sb(ptext[j+1],0,gb(iv[i],j));
-                   else
-                       sb(ptext[j+1],0,gb(ctext[j-128],0));
-                   }
-               else
-                   {
-                   if(j < 128)
-                       sb(ctext[j+1],0,gb(iv[i],j));
-                   else
-                       sb(ctext[j+1],0,gb(ptext[j-128],0));
-                   }
-               break;
-               }
-           }
-       --j; /* reset to last of range */
-       /* Output Ciphertext | Plaintext */
-       OutputValue(t_tag[dir],dir ? ctext[j] : ptext[j],len,rfp,
-                   imode == CFB1);
-       fprintf(rfp, "\n");  /* add separator */
-
-       /* Compute next KEY */
-       if (dir == XENCRYPT)
-           {
-           if (imode == CFB8)
-               { /* ct = CT[j-15] || CT[j-14] || ... || CT[j] */
-               for (n1 = 0, n2 = nkeysz-1; n1 < nkeysz; ++n1, --n2)
-                   ciphertext[n1] = ctext[j-n2][0];
-               }
-           else if(imode == CFB1)
-               {
-               for(n1=0,n2=akeysz-1 ; n1 < akeysz ; ++n1,--n2)
-                   sb(ciphertext,n1,gb(ctext[j-n2],0));
-               }
-           else
-               switch (akeysz)
-                   {
-               case 128:
-                   memcpy(ciphertext, ctext[j], 16);
-                   break;
-               case 192:
-                   memcpy(ciphertext, ctext[j-1]+8, 8);
-                   memcpy(ciphertext+8, ctext[j], 16);
-                   break;
-               case 256:
-                   memcpy(ciphertext, ctext[j-1], 16);
-                   memcpy(ciphertext+16, ctext[j], 16);
-                   break;
-                   }
-           }
-       else
-           {
-           if (imode == CFB8)
-               { /* ct = CT[j-15] || CT[j-14] || ... || CT[j] */
-               for (n1 = 0, n2 = nkeysz-1; n1 < nkeysz; ++n1, --n2)
-                   ciphertext[n1] = ptext[j-n2][0];
-               }
-           else if(imode == CFB1)
-               {
-               for(n1=0,n2=akeysz-1 ; n1 < akeysz ; ++n1,--n2)
-                   sb(ciphertext,n1,gb(ptext[j-n2],0));
-               }
-           else
-               switch (akeysz)
-                   {
-               case 128:
-                   memcpy(ciphertext, ptext[j], 16);
-                   break;
-               case 192:
-                   memcpy(ciphertext, ptext[j-1]+8, 8);
-                   memcpy(ciphertext+8, ptext[j], 16);
-                   break;
-               case 256:
-                   memcpy(ciphertext, ptext[j-1], 16);
-                   memcpy(ciphertext+16, ptext[j], 16);
-                   break;
-                   }
-           }
-       /* Compute next key: Key[i+1] = Key[i] xor ct */
-       for (n = 0; n < nkeysz; ++n)
-           key[i+1][n] = key[i][n] ^ ciphertext[n];
-       
-       /* Compute next IV and text */
-       if (dir == XENCRYPT)
-           {
-           switch (imode)
-               {
-           case ECB:
-               memcpy(ptext[0], ctext[j], AES_BLOCK_SIZE);
-               break;
-           case CBC:
-           case OFB:
-           case CFB128:
-               memcpy(iv[i+1], ctext[j], AES_BLOCK_SIZE);
-               memcpy(ptext[0], ctext[j-1], AES_BLOCK_SIZE);
-               break;
-           case CFB8:
-               /* IV[i+1] = ct */
-               for (n1 = 0, n2 = 15; n1 < 16; ++n1, --n2)
-                   iv[i+1][n1] = ctext[j-n2][0];
-               ptext[0][0] = ctext[j-16][0];
-               break;
-           case CFB1:
-               for(n1=0,n2=127 ; n1 < 128 ; ++n1,--n2)
-                   sb(iv[i+1],n1,gb(ctext[j-n2],0));
-               ptext[0][0]=ctext[j-128][0]&0x80;
-               break;
-               }
-           }
-       else
-           {
-           switch (imode)
-               {
-           case ECB:
-               memcpy(ctext[0], ptext[j], AES_BLOCK_SIZE);
-               break;
-           case CBC:
-           case OFB:
-           case CFB128:
-               memcpy(iv[i+1], ptext[j], AES_BLOCK_SIZE);
-               memcpy(ctext[0], ptext[j-1], AES_BLOCK_SIZE);
-               break;
-           case CFB8:
-               for (n1 = 0, n2 = 15; n1 < 16; ++n1, --n2)
-                   iv[i+1][n1] = ptext[j-n2][0];
-               ctext[0][0] = ptext[j-16][0];
-               break;
-           case CFB1:
-               for(n1=0,n2=127 ; n1 < 128 ; ++n1,--n2)
-                   sb(iv[i+1],n1,gb(ptext[j-n2],0));
-               ctext[0][0]=ptext[j-128][0]&0x80;
-               break;
-               }
-           }
-       }
-    
-    return ret;
-    }
-
-/*================================================*/
-/*----------------------------
-  # Config info for v-one
-  # AESVS MMT test data for ECB
-  # State : Encrypt and Decrypt
-  # Key Length : 256
-  # Fri Aug 30 04:07:22 PM
-  ----------------------------*/
-
-static int proc_file(char *rqfile, char *rspfile)
-    {
-    char afn[256], rfn[256];
-    FILE *afp = NULL, *rfp = NULL;
-    char ibuf[2048];
-    char tbuf[2048];
-    int ilen, len, ret = 0;
-    char algo[8] = "";
-    char amode[8] = "";
-    char atest[8] = "";
-    int akeysz = 0;
-    unsigned char iVec[20], aKey[40];
-    int dir = -1, err = 0, step = 0;
-    unsigned char plaintext[2048];
-    unsigned char ciphertext[2048];
-    char *rp;
-    EVP_CIPHER_CTX ctx;
-    EVP_CIPHER_CTX_init(&ctx);
-
-    if (!rqfile || !(*rqfile))
-       {
-       printf("No req file\n");
-       return -1;
-       }
-    strcpy(afn, rqfile);
-
-    if ((afp = fopen(afn, "r")) == NULL)
-       {
-       printf("Cannot open file: %s, %s\n", 
-              afn, strerror(errno));
-       return -1;
-       }
-    if (!rspfile)
-       {
-       strcpy(rfn,afn);
-       rp=strstr(rfn,"req/");
-#ifdef OPENSSL_SYS_WIN32
-       if (!rp)
-           rp=strstr(rfn,"req\\");
-#endif
-       assert(rp);
-       memcpy(rp,"rsp",3);
-       rp = strstr(rfn, ".req");
-       memcpy(rp, ".rsp", 4);
-       rspfile = rfn;
-       }
-    if ((rfp = fopen(rspfile, "w")) == NULL)
-       {
-       printf("Cannot open file: %s, %s\n", 
-              rfn, strerror(errno));
-       fclose(afp);
-       afp = NULL;
-       return -1;
-       }
-    while (!err && (fgets(ibuf, sizeof(ibuf), afp)) != NULL)
-       {
-       tidy_line(tbuf, ibuf);
-       ilen = strlen(ibuf);
-       /*      printf("step=%d ibuf=%s",step,ibuf); */
-       switch (step)
-           {
-       case 0:  /* read preamble */
-           if (ibuf[0] == '\n')
-               { /* end of preamble */
-               if ((*algo == '\0') ||
-                   (*amode == '\0') ||
-                   (akeysz == 0))
-                   {
-                   printf("Missing Algorithm, Mode or KeySize (%s/%s/%d)\n",
-                          algo,amode,akeysz);
-                   err = 1;
-                   }
-               else
-                   {
-                   fputs(ibuf, rfp);
-                   ++ step;
-                   }
-               }
-           else if (ibuf[0] != '#')
-               {
-               printf("Invalid preamble item: %s\n", ibuf);
-               err = 1;
-               }
-           else
-               { /* process preamble */
-               char *xp, *pp = ibuf+2;
-               int n;
-               if (akeysz)
-                   { /* insert current time & date */
-                   time_t rtim = time(0);
-                   fprintf(rfp, "# %s", ctime(&rtim));
-                   }
-               else
-                   {
-                   fputs(ibuf, rfp);
-                   if (strncmp(pp, "AESVS ", 6) == 0)
-                       {
-                       strcpy(algo, "AES");
-                       /* get test type */
-                       pp += 6;
-                       xp = strchr(pp, ' ');
-                       n = xp-pp;
-                       strncpy(atest, pp, n);
-                       atest[n] = '\0';
-                       /* get mode */
-                       xp = strrchr(pp, ' '); /* get mode" */
-                       n = strlen(xp+1)-1;
-                       strncpy(amode, xp+1, n);
-                       amode[n] = '\0';
-                       /* amode[3] = '\0'; */
-                       if (VERBOSE)
-                               printf("Test = %s, Mode = %s\n", atest, amode);
-                       }
-                   else if (strncasecmp(pp, "Key Length : ", 13) == 0)
-                       {
-                       akeysz = atoi(pp+13);
-                       if (VERBOSE)
-                               printf("Key size = %d\n", akeysz);
-                       }
-                   }
-               }
-           break;
-
-       case 1:  /* [ENCRYPT] | [DECRYPT] */
-           if (ibuf[0] == '[')
-               {
-               fputs(ibuf, rfp);
-               ++step;
-               if (strncasecmp(ibuf, "[ENCRYPT]", 9) == 0)
-                   dir = 1;
-               else if (strncasecmp(ibuf, "[DECRYPT]", 9) == 0)
-                   dir = 0;
-               else
-                   {
-                   printf("Invalid keyword: %s\n", ibuf);
-                   err = 1;
-                   }
-               break;
-               }
-           else if (dir == -1)
-               {
-               err = 1;
-               printf("Missing ENCRYPT/DECRYPT keyword\n");
-               break;
-               }
-           else 
-               step = 2;
-
-       case 2: /* KEY = xxxx */
-           fputs(ibuf, rfp);
-           if(*ibuf == '\n')
-               break;
-           if(!strncasecmp(ibuf,"COUNT = ",8))
-               break;
-
-           if (strncasecmp(ibuf, "KEY = ", 6) != 0)
-               {
-               printf("Missing KEY\n");
-               err = 1;
-               }
-           else
-               {
-               len = hex2bin((char*)ibuf+6, aKey);
-               if (len < 0)
-                   {
-                   printf("Invalid KEY\n");
-                   err =1;
-                   break;
-                   }
-               PrintValue("KEY", aKey, len);
-               if (strcmp(amode, "ECB") == 0)
-                   {
-                   memset(iVec, 0, sizeof(iVec));
-                   step = (dir)? 4: 5;  /* no ivec for ECB */
-                   }
-               else
-                   ++step;
-               }
-           break;
-
-       case 3: /* IV = xxxx */
-           fputs(ibuf, rfp);
-           if (strncasecmp(ibuf, "IV = ", 5) != 0)
-               {
-               printf("Missing IV\n");
-               err = 1;
-               }
-           else
-               {
-               len = hex2bin((char*)ibuf+5, iVec);
-               if (len < 0)
-                   {
-                   printf("Invalid IV\n");
-                   err =1;
-                   break;
-                   }
-               PrintValue("IV", iVec, len);
-               step = (dir)? 4: 5;
-               }
-           break;
-
-       case 4: /* PLAINTEXT = xxxx */
-           fputs(ibuf, rfp);
-           if (strncasecmp(ibuf, "PLAINTEXT = ", 12) != 0)
-               {
-               printf("Missing PLAINTEXT\n");
-               err = 1;
-               }
-           else
-               {
-               int nn = strlen(ibuf+12);
-               if(!strcmp(amode,"CFB1"))
-                   len=bint2bin(ibuf+12,nn-1,plaintext);
-               else
-                   len=hex2bin(ibuf+12, plaintext);
-               if (len < 0)
-                   {
-                   printf("Invalid PLAINTEXT: %s", ibuf+12);
-                   err =1;
-                   break;
-                   }
-               if (len >= (int)sizeof(plaintext))
-                   {
-                   printf("Buffer overflow\n");
-                   }
-               PrintValue("PLAINTEXT", (unsigned char*)plaintext, len);
-               if (strcmp(atest, "MCT") == 0)  /* Monte Carlo Test */
-                   {
-                   if(do_mct(amode, akeysz, aKey, iVec, 
-                             dir, (unsigned char*)plaintext, len, 
-                             rfp) < 0)
-                       EXIT(1);
-                   }
-               else
-                   {
-                   ret = AESTest(&ctx, amode, akeysz, aKey, iVec, 
-                                 dir,  /* 0 = decrypt, 1 = encrypt */
-                                 plaintext, ciphertext, len);
-                   OutputValue("CIPHERTEXT",ciphertext,len,rfp,
-                               !strcmp(amode,"CFB1"));
-                   }
-               step = 6;
-               }
-           break;
-
-       case 5: /* CIPHERTEXT = xxxx */
-           fputs(ibuf, rfp);
-           if (strncasecmp(ibuf, "CIPHERTEXT = ", 13) != 0)
-               {
-               printf("Missing KEY\n");
-               err = 1;
-               }
-           else
-               {
-               if(!strcmp(amode,"CFB1"))
-                   len=bint2bin(ibuf+13,strlen(ibuf+13)-1,ciphertext);
-               else
-                   len = hex2bin(ibuf+13,ciphertext);
-               if (len < 0)
-                   {
-                   printf("Invalid CIPHERTEXT\n");
-                   err =1;
-                   break;
-                   }
-
-               PrintValue("CIPHERTEXT", ciphertext, len);
-               if (strcmp(atest, "MCT") == 0)  /* Monte Carlo Test */
-                   {
-                   do_mct(amode, akeysz, aKey, iVec, 
-                          dir, ciphertext, len, rfp);
-                   }
-               else
-                   {
-                   ret = AESTest(&ctx, amode, akeysz, aKey, iVec, 
-                                 dir,  /* 0 = decrypt, 1 = encrypt */
-                                 plaintext, ciphertext, len);
-                   OutputValue("PLAINTEXT",(unsigned char *)plaintext,len,rfp,
-                               !strcmp(amode,"CFB1"));
-                   }
-               step = 6;
-               }
-           break;
-
-       case 6:
-           if (ibuf[0] != '\n')
-               {
-               err = 1;
-               printf("Missing terminator\n");
-               }
-           else if (strcmp(atest, "MCT") != 0)
-               { /* MCT already added terminating nl */
-               fputs(ibuf, rfp);
-               }
-           step = 1;
-           break;
-           }
-       }
-    if (rfp)
-       fclose(rfp);
-    if (afp)
-       fclose(afp);
-    return err;
-    }
-
-/*--------------------------------------------------
-  Processes either a single file or 
-  a set of files whose names are passed in a file.
-  A single file is specified as:
-    aes_test -f xxx.req
-  A set of files is specified as:
-    aes_test -d xxxxx.xxx
-  The default is: -d req.txt
---------------------------------------------------*/
-int main(int argc, char **argv)
-    {
-    char *rqlist = "req.txt", *rspfile = NULL;
-    FILE *fp = NULL;
-    char fn[250] = "", rfn[256] = "";
-    int f_opt = 0, d_opt = 1;
-
-#ifdef OPENSSL_FIPS
-    if(!FIPS_mode_set(1))
-       {
-       do_print_errors();
-       EXIT(1);
-       }
-#endif
-    if (argc > 1)
-       {
-       if (strcasecmp(argv[1], "-d") == 0)
-           {
-           d_opt = 1;
-           }
-       else if (strcasecmp(argv[1], "-f") == 0)
-           {
-           f_opt = 1;
-           d_opt = 0;
-           }
-       else
-           {
-           printf("Invalid parameter: %s\n", argv[1]);
-           return 0;
-           }
-       if (argc < 3)
-           {
-           printf("Missing parameter\n");
-           return 0;
-           }
-       if (d_opt)
-           rqlist = argv[2];
-       else
-           {
-           strcpy(fn, argv[2]);
-           rspfile = argv[3];
-           }
-       }
-    if (d_opt)
-       { /* list of files (directory) */
-       if (!(fp = fopen(rqlist, "r")))
-           {
-           printf("Cannot open req list file\n");
-           return -1;
-           }
-       while (fgets(fn, sizeof(fn), fp))
-           {
-           strtok(fn, "\r\n");
-           strcpy(rfn, fn);
-           if (VERBOSE)
-               printf("Processing: %s\n", rfn);
-           if (proc_file(rfn, rspfile))
-               {
-               printf(">>> Processing failed for: %s <<<\n", rfn);
-               EXIT(1);
-               }
-           }
-       fclose(fp);
-       }
-    else /* single file */
-       {
-       if (VERBOSE)
-           printf("Processing: %s\n", fn);
-       if (proc_file(fn, rspfile))
-           {
-           printf(">>> Processing failed for: %s <<<\n", fn);
-           }
-       }
-    EXIT(0);
-    return 0;
-    }
-
-#endif
diff --git a/deps/openssl/openssl/fips/des/Makefile b/deps/openssl/openssl/fips/des/Makefile
deleted file mode 100644 (file)
index ba1d095..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-#
-# OpenSSL/fips/des/Makefile
-#
-
-DIR=   des
-TOP=   ../..
-CC=    cc
-INCLUDES=
-CFLAG=-g
-INSTALL_PREFIX=
-OPENSSLDIR=     /usr/local/ssl
-INSTALLTOP=/usr/local/ssl
-MAKEDEPPROG=   makedepend
-MAKEDEPEND=    $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
-MAKEFILE=      Makefile
-AR=            ar r
-
-ASFLAGS= $(INCLUDES) $(ASFLAG)
-AFLAGS= $(ASFLAGS)
-
-CFLAGS= $(INCLUDES) $(CFLAG)
-
-GENERAL=Makefile
-TEST= fips_desmovs.c
-APPS=
-
-LIB=$(TOP)/libcrypto.a
-LIBSRC=fips_des_selftest.c
-LIBOBJ=fips_des_selftest.o
-
-SRC= $(LIBSRC)
-
-EXHEADER=
-HEADER=
-
-ALL=    $(GENERAL) $(SRC) $(HEADER)
-
-top:
-       (cd $(TOP); $(MAKE) DIRS=fips FDIRS=$(DIR) sub_all)
-
-all:   lib
-
-lib:   $(LIBOBJ)
-       @echo $(LIBOBJ) > lib
-
-files:
-       $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
-
-links:
-       @$(PERL) $(TOP)/util/mklink.pl $(TOP)/include/openssl $(EXHEADER)
-       @$(PERL) $(TOP)/util/mklink.pl $(TOP)/test $(TEST)
-       @$(PERL) $(TOP)/util/mklink.pl $(TOP)/apps $(APPS)
-
-install:
-       @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:
-
-fips_test:
-       -find ../testvectors/tdes/req -name '*.req' > testlist
-       -rm -rf ../testvectors/tdes/rsp
-       mkdir ../testvectors/tdes/rsp
-       if [ -s testlist ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_desmovs -d testlist; fi
-
-lint:
-       lint -DLINT $(INCLUDES) $(SRC)>fluff
-
-depend:
-       $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) \
-               $(SRC) $(TEST)
-dclean:
-       $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
-       mv -f Makefile.new $(MAKEFILE)
-
-clean:
-       rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff testlist
-# DO NOT DELETE THIS LINE -- make depend depends on it.
-
-fips_des_selftest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-fips_des_selftest.o: ../../include/openssl/crypto.h
-fips_des_selftest.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-fips_des_selftest.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-fips_des_selftest.o: ../../include/openssl/lhash.h
-fips_des_selftest.o: ../../include/openssl/obj_mac.h
-fips_des_selftest.o: ../../include/openssl/objects.h
-fips_des_selftest.o: ../../include/openssl/opensslconf.h
-fips_des_selftest.o: ../../include/openssl/opensslv.h
-fips_des_selftest.o: ../../include/openssl/ossl_typ.h
-fips_des_selftest.o: ../../include/openssl/safestack.h
-fips_des_selftest.o: ../../include/openssl/stack.h
-fips_des_selftest.o: ../../include/openssl/symhacks.h fips_des_selftest.c
-fips_desmovs.o: ../../e_os.h ../../include/openssl/asn1.h
-fips_desmovs.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
-fips_desmovs.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
-fips_desmovs.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
-fips_desmovs.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-fips_desmovs.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-fips_desmovs.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-fips_desmovs.o: ../../include/openssl/opensslconf.h
-fips_desmovs.o: ../../include/openssl/opensslv.h
-fips_desmovs.o: ../../include/openssl/ossl_typ.h
-fips_desmovs.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-fips_desmovs.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
-fips_desmovs.o: ../../include/openssl/ui_compat.h ../fips_utl.h fips_desmovs.c
diff --git a/deps/openssl/openssl/fips/des/fips_des_selftest.c b/deps/openssl/openssl/fips/des/fips_des_selftest.c
deleted file mode 100644 (file)
index 61c39ce..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-/* ====================================================================
- * Copyright (c) 2003 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    openssl-core@openssl.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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 <string.h>
-#include <openssl/err.h>
-#include <openssl/fips.h>
-#include <openssl/evp.h>
-#include <openssl/opensslconf.h>
-
-#ifdef OPENSSL_FIPS
-
-static struct
-    {
-    unsigned char key[16];
-    unsigned char plaintext[8];
-    unsigned char ciphertext[8];
-    } tests2[]=
-       {
-       {
-       { 0x7c,0x4f,0x6e,0xf7,0xa2,0x04,0x16,0xec,
-         0x0b,0x6b,0x7c,0x9e,0x5e,0x19,0xa7,0xc4 },
-       { 0x06,0xa7,0xd8,0x79,0xaa,0xce,0x69,0xef },
-       { 0x4c,0x11,0x17,0x55,0xbf,0xc4,0x4e,0xfd }
-       },
-       {
-       { 0x5d,0x9e,0x01,0xd3,0x25,0xc7,0x3e,0x34,
-         0x01,0x16,0x7c,0x85,0x23,0xdf,0xe0,0x68 },
-       { 0x9c,0x50,0x09,0x0f,0x5e,0x7d,0x69,0x7e },
-       { 0xd2,0x0b,0x18,0xdf,0xd9,0x0d,0x9e,0xff },
-       }
-       };
-
-static struct
-    {
-    unsigned char key[24];
-    unsigned char plaintext[8];
-    unsigned char ciphertext[8];
-    } tests3[]=
-       {
-       {
-       { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-         0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10,
-         0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0 },
-       { 0x8f,0x8f,0xbf,0x9b,0x5d,0x48,0xb4,0x1c },
-       { 0x59,0x8c,0xe5,0xd3,0x6c,0xa2,0xea,0x1b },
-       },
-       {
-       { 0xDC,0xBA,0x98,0x76,0x54,0x32,0x10,0xFE,
-         0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
-         0xED,0x39,0xD9,0x50,0xFA,0x74,0xBC,0xC4 },
-       { 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF },
-       { 0x11,0x25,0xb0,0x35,0xbe,0xa0,0x82,0x86 },
-       },
-       };
-
-void FIPS_corrupt_des()
-    {
-    tests2[0].plaintext[0]++;
-    }
-
-int FIPS_selftest_des()
-    {
-    int n, ret = 0;
-    EVP_CIPHER_CTX ctx;
-    EVP_CIPHER_CTX_init(&ctx);
-    /* Encrypt/decrypt with 2-key 3DES and compare to known answers */
-    for(n=0 ; n < 2 ; ++n)
-       {
-       if (!fips_cipher_test(&ctx, EVP_des_ede_ecb(),
-                               tests2[n].key, NULL,
-                               tests2[n].plaintext, tests2[n].ciphertext, 8))
-               goto err;
-       }
-
-    /* Encrypt/decrypt with 3DES and compare to known answers */
-    for(n=0 ; n < 2 ; ++n)
-       {
-       if (!fips_cipher_test(&ctx, EVP_des_ede3_ecb(),
-                               tests3[n].key, NULL,
-                               tests3[n].plaintext, tests3[n].ciphertext, 8))
-               goto err;
-       }
-    ret = 1;
-    err:
-    EVP_CIPHER_CTX_cleanup(&ctx);
-    if (ret == 0)
-           FIPSerr(FIPS_F_FIPS_SELFTEST_DES,FIPS_R_SELFTEST_FAILED);
-
-    return ret;
-    }
-#endif
diff --git a/deps/openssl/openssl/fips/des/fips_desmovs.c b/deps/openssl/openssl/fips/des/fips_desmovs.c
deleted file mode 100644 (file)
index f96a5ca..0000000
+++ /dev/null
@@ -1,702 +0,0 @@
-/* ====================================================================
- * Copyright (c) 2004 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    openssl-core@openssl.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
- *
- */
-/*---------------------------------------------
-  NIST DES Modes of Operation Validation System
-  Test Program
-
-  Based on the AES Validation Suite, which was:
-  Donated to OpenSSL by:
-  V-ONE Corporation
-  20250 Century Blvd, Suite 300
-  Germantown, MD 20874
-  U.S.A.
-  ----------------------------------------------*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-#include <ctype.h>
-#include <openssl/des.h>
-#include <openssl/evp.h>
-#include <openssl/bn.h>
-
-#include <openssl/err.h>
-#include "e_os.h"
-
-#ifndef OPENSSL_FIPS
-
-int main(int argc, char *argv[])
-{
-    printf("No FIPS DES support\n");
-    return(0);
-}
-
-#else
-
-#include <openssl/fips.h>
-#include "fips_utl.h"
-
-#define DES_BLOCK_SIZE 8
-
-#define VERBOSE 0
-
-static int DESTest(EVP_CIPHER_CTX *ctx,
-           char *amode, int akeysz, unsigned char *aKey, 
-           unsigned char *iVec, 
-           int dir,  /* 0 = decrypt, 1 = encrypt */
-           unsigned char *out, unsigned char *in, int len)
-    {
-    const EVP_CIPHER *cipher = NULL;
-
-    if (akeysz != 192)
-       {
-       printf("Invalid key size: %d\n", akeysz);
-       EXIT(1);
-       }
-
-    if (strcasecmp(amode, "CBC") == 0)
-       cipher = EVP_des_ede3_cbc();
-    else if (strcasecmp(amode, "ECB") == 0)
-       cipher = EVP_des_ede3_ecb();
-    else if (strcasecmp(amode, "CFB64") == 0)
-       cipher = EVP_des_ede3_cfb64();
-    else if (strncasecmp(amode, "OFB", 3) == 0)
-       cipher = EVP_des_ede3_ofb();
-    else if(!strcasecmp(amode,"CFB8"))
-       cipher = EVP_des_ede3_cfb8();
-    else if(!strcasecmp(amode,"CFB1"))
-       cipher = EVP_des_ede3_cfb1();
-    else
-       {
-       printf("Unknown mode: %s\n", amode);
-       EXIT(1);
-       }
-
-    if (EVP_CipherInit_ex(ctx, cipher, NULL, aKey, iVec, dir) <= 0)
-       return 0;
-    if(!strcasecmp(amode,"CFB1"))
-       M_EVP_CIPHER_CTX_set_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS);
-    EVP_Cipher(ctx, out, in, len);
-
-    return 1;
-    }
-#if 0
-static void DebugValue(char *tag, unsigned char *val, int len)
-    {
-    char obuf[2048];
-    int olen;
-    olen = bin2hex(val, len, obuf);
-    printf("%s = %.*s\n", tag, olen, obuf);
-    }
-#endif
-static void shiftin(unsigned char *dst,unsigned char *src,int nbits)
-    {
-    int n;
-
-    /* move the bytes... */
-    memmove(dst,dst+nbits/8,3*8-nbits/8);
-    /* append new data */
-    memcpy(dst+3*8-nbits/8,src,(nbits+7)/8);
-    /* left shift the bits */
-    if(nbits%8)
-       for(n=0 ; n < 3*8 ; ++n)
-           dst[n]=(dst[n] << (nbits%8))|(dst[n+1] >> (8-nbits%8));
-    }  
-
-/*-----------------------------------------------*/
-char *t_tag[2] = {"PLAINTEXT", "CIPHERTEXT"};
-char *t_mode[6] = {"CBC","ECB","OFB","CFB1","CFB8","CFB64"};
-enum Mode {CBC, ECB, OFB, CFB1, CFB8, CFB64};
-int Sizes[6]={64,64,64,1,8,64};
-
-static void do_mct(char *amode, 
-           int akeysz, int numkeys, unsigned char *akey,unsigned char *ivec,
-           int dir, unsigned char *text, int len,
-           FILE *rfp)
-    {
-    int i,imode;
-    unsigned char nk[4*8]; /* longest key+8 */
-    unsigned char text0[8];
-
-    for (imode=0 ; imode < 6 ; ++imode)
-       if(!strcmp(amode,t_mode[imode]))
-           break;
-    if (imode == 6)
-       { 
-       printf("Unrecognized mode: %s\n", amode);
-       EXIT(1);
-       }
-
-    for(i=0 ; i < 400 ; ++i)
-       {
-       int j;
-       int n;
-       int kp=akeysz/64;
-       unsigned char old_iv[8];
-       EVP_CIPHER_CTX ctx;
-       EVP_CIPHER_CTX_init(&ctx);
-
-       fprintf(rfp,"\nCOUNT = %d\n",i);
-       if(kp == 1)
-           OutputValue("KEY",akey,8,rfp,0);
-       else
-           for(n=0 ; n < kp ; ++n)
-               {
-               fprintf(rfp,"KEY%d",n+1);
-               OutputValue("",akey+n*8,8,rfp,0);
-               }
-
-       if(imode != ECB)
-           OutputValue("IV",ivec,8,rfp,0);
-       OutputValue(t_tag[dir^1],text,len,rfp,imode == CFB1);
-#if 0
-       /* compensate for endianness */
-       if(imode == CFB1)
-           text[0]<<=7;
-#endif
-       memcpy(text0,text,8);
-
-       for(j=0 ; j < 10000 ; ++j)
-           {
-           unsigned char old_text[8];
-
-           memcpy(old_text,text,8);
-           if(j == 0)
-               {
-               memcpy(old_iv,ivec,8);
-               DESTest(&ctx,amode,akeysz,akey,ivec,dir,text,text,len);
-               }
-           else
-               {
-               memcpy(old_iv,ctx.iv,8);
-               EVP_Cipher(&ctx,text,text,len);
-               }
-           if(j == 9999)
-               {
-               OutputValue(t_tag[dir],text,len,rfp,imode == CFB1);
-               /*              memcpy(ivec,text,8); */
-               }
-           /*      DebugValue("iv",ctx.iv,8); */
-           /* accumulate material for the next key */
-           shiftin(nk,text,Sizes[imode]);
-           /*      DebugValue("nk",nk,24);*/
-           if((dir && (imode == CFB1 || imode == CFB8 || imode == CFB64
-                       || imode == CBC)) || imode == OFB)
-               memcpy(text,old_iv,8);
-
-           if(!dir && (imode == CFB1 || imode == CFB8 || imode == CFB64))
-               {
-               /* the test specifies using the output of the raw DES operation
-                  which we don't have, so reconstruct it... */
-               for(n=0 ; n < 8 ; ++n)
-                   text[n]^=old_text[n];
-               }
-           }
-       for(n=0 ; n < 8 ; ++n)
-           akey[n]^=nk[16+n];
-       for(n=0 ; n < 8 ; ++n)
-           akey[8+n]^=nk[8+n];
-       for(n=0 ; n < 8 ; ++n)
-           akey[16+n]^=nk[n];
-       if(numkeys < 3)
-           memcpy(&akey[2*8],akey,8);
-       if(numkeys < 2)
-           memcpy(&akey[8],akey,8);
-       DES_set_odd_parity((DES_cblock *)akey);
-       DES_set_odd_parity((DES_cblock *)(akey+8));
-       DES_set_odd_parity((DES_cblock *)(akey+16));
-       memcpy(ivec,ctx.iv,8);
-
-       /* pointless exercise - the final text doesn't depend on the
-          initial text in OFB mode, so who cares what it is? (Who
-          designed these tests?) */
-       if(imode == OFB)
-           for(n=0 ; n < 8 ; ++n)
-               text[n]=text0[n]^old_iv[n];
-       }
-    }
-    
-static int proc_file(char *rqfile, char *rspfile)
-    {
-    char afn[256], rfn[256];
-    FILE *afp = NULL, *rfp = NULL;
-    char ibuf[2048], tbuf[2048];
-    int ilen, len, ret = 0;
-    char amode[8] = "";
-    char atest[100] = "";
-    int akeysz=0;
-    unsigned char iVec[20], aKey[40];
-    int dir = -1, err = 0, step = 0;
-    unsigned char plaintext[2048];
-    unsigned char ciphertext[2048];
-    char *rp;
-    EVP_CIPHER_CTX ctx;
-    int numkeys=1;
-    EVP_CIPHER_CTX_init(&ctx);
-
-    if (!rqfile || !(*rqfile))
-       {
-       printf("No req file\n");
-       return -1;
-       }
-    strcpy(afn, rqfile);
-
-    if ((afp = fopen(afn, "r")) == NULL)
-       {
-       printf("Cannot open file: %s, %s\n", 
-              afn, strerror(errno));
-       return -1;
-       }
-    if (!rspfile)
-       {
-       strcpy(rfn,afn);
-       rp=strstr(rfn,"req/");
-#ifdef OPENSSL_SYS_WIN32
-       if (!rp)
-           rp=strstr(rfn,"req\\");
-#endif
-       assert(rp);
-       memcpy(rp,"rsp",3);
-       rp = strstr(rfn, ".req");
-       memcpy(rp, ".rsp", 4);
-       rspfile = rfn;
-       }
-    if ((rfp = fopen(rspfile, "w")) == NULL)
-       {
-       printf("Cannot open file: %s, %s\n", 
-              rfn, strerror(errno));
-       fclose(afp);
-       afp = NULL;
-       return -1;
-       }
-    while (!err && (fgets(ibuf, sizeof(ibuf), afp)) != NULL)
-       {
-       tidy_line(tbuf, ibuf);
-       ilen = strlen(ibuf);
-       /*      printf("step=%d ibuf=%s",step,ibuf);*/
-       if(step == 3 && !strcmp(amode,"ECB"))
-           {
-           memset(iVec, 0, sizeof(iVec));
-           step = (dir)? 4: 5;  /* no ivec for ECB */
-           }
-       switch (step)
-           {
-       case 0:  /* read preamble */
-           if (ibuf[0] == '\n')
-               { /* end of preamble */
-               if (*amode == '\0')
-                   {
-                   printf("Missing Mode\n");
-                   err = 1;
-                   }
-               else
-                   {
-                   fputs(ibuf, rfp);
-                   ++ step;
-                   }
-               }
-           else if (ibuf[0] != '#')
-               {
-               printf("Invalid preamble item: %s\n", ibuf);
-               err = 1;
-               }
-           else
-               { /* process preamble */
-               char *xp, *pp = ibuf+2;
-               int n;
-               if(*amode)
-                   { /* insert current time & date */
-                   time_t rtim = time(0);
-                   fprintf(rfp, "# %s", ctime(&rtim));
-                   }
-               else
-                   {
-                   fputs(ibuf, rfp);
-                   if(!strncmp(pp,"INVERSE ",8) || !strncmp(pp,"DES ",4)
-                      || !strncmp(pp,"TDES ",5)
-                      || !strncmp(pp,"PERMUTATION ",12)
-                      || !strncmp(pp,"SUBSTITUTION ",13)
-                      || !strncmp(pp,"VARIABLE ",9))
-                       {
-                       /* get test type */
-                       if(!strncmp(pp,"DES ",4))
-                           pp+=4;
-                       else if(!strncmp(pp,"TDES ",5))
-                           pp+=5;
-                       xp = strchr(pp, ' ');
-                       n = xp-pp;
-                       strncpy(atest, pp, n);
-                       atest[n] = '\0';
-                       /* get mode */
-                       xp = strrchr(pp, ' '); /* get mode" */
-                       n = strlen(xp+1)-1;
-                       strncpy(amode, xp+1, n);
-                       amode[n] = '\0';
-                       /* amode[3] = '\0'; */
-                       if (VERBOSE)
-                               printf("Test=%s, Mode=%s\n",atest,amode);
-                       }
-                   }
-               }
-           break;
-
-       case 1:  /* [ENCRYPT] | [DECRYPT] */
-           if(ibuf[0] == '\n')
-               break;
-           if (ibuf[0] == '[')
-               {
-               fputs(ibuf, rfp);
-               ++step;
-               if (strncasecmp(ibuf, "[ENCRYPT]", 9) == 0)
-                   dir = 1;
-               else if (strncasecmp(ibuf, "[DECRYPT]", 9) == 0)
-                   dir = 0;
-               else
-                   {
-                   printf("Invalid keyword: %s\n", ibuf);
-                   err = 1;
-                   }
-               break;
-               }
-           else if (dir == -1)
-               {
-               err = 1;
-               printf("Missing ENCRYPT/DECRYPT keyword\n");
-               break;
-               }
-           else 
-               step = 2;
-
-       case 2: /* KEY = xxxx */
-           if(*ibuf == '\n')
-               {
-               fputs(ibuf, rfp);
-               break;
-                }
-           if(!strncasecmp(ibuf,"COUNT = ",8))
-               {
-               fputs(ibuf, rfp);
-               break;
-                }
-           if(!strncasecmp(ibuf,"COUNT=",6))
-               {
-               fputs(ibuf, rfp);
-               break;
-                }
-           if(!strncasecmp(ibuf,"NumKeys = ",10))
-               {
-               numkeys=atoi(ibuf+10);
-               break;
-               }
-         
-           fputs(ibuf, rfp);
-           if(!strncasecmp(ibuf,"KEY = ",6))
-               {
-               akeysz=64;
-               len = hex2bin((char*)ibuf+6, aKey);
-               if (len < 0)
-                   {
-                   printf("Invalid KEY\n");
-                   err=1;
-                   break;
-                   }
-               PrintValue("KEY", aKey, len);
-               ++step;
-               }
-           else if(!strncasecmp(ibuf,"KEYs = ",7))
-               {
-               akeysz=64*3;
-               len=hex2bin(ibuf+7,aKey);
-               if(len != 8)
-                   {
-                   printf("Invalid KEY\n");
-                   err=1;
-                   break;
-                   }
-               memcpy(aKey+8,aKey,8);
-               memcpy(aKey+16,aKey,8);
-               ibuf[4]='\0';
-               PrintValue("KEYs",aKey,len);
-               ++step;
-               }
-           else if(!strncasecmp(ibuf,"KEY",3))
-               {
-               int n=ibuf[3]-'1';
-
-               akeysz=64*3;
-               len=hex2bin(ibuf+7,aKey+n*8);
-               if(len != 8)
-                   {
-                   printf("Invalid KEY\n");
-                   err=1;
-                   break;
-                   }
-               ibuf[4]='\0';
-               PrintValue(ibuf,aKey,len);
-               if(n == 2)
-                   ++step;
-               }
-           else
-               {
-               printf("Missing KEY\n");
-               err = 1;
-               }
-           break;
-
-       case 3: /* IV = xxxx */
-           fputs(ibuf, rfp);
-           if (strncasecmp(ibuf, "IV = ", 5) != 0)
-               {
-               printf("Missing IV\n");
-               err = 1;
-               }
-           else
-               {
-               len = hex2bin((char*)ibuf+5, iVec);
-               if (len < 0)
-                   {
-                   printf("Invalid IV\n");
-                   err =1;
-                   break;
-                   }
-               PrintValue("IV", iVec, len);
-               step = (dir)? 4: 5;
-               }
-           break;
-
-       case 4: /* PLAINTEXT = xxxx */
-           fputs(ibuf, rfp);
-           if (strncasecmp(ibuf, "PLAINTEXT = ", 12) != 0)
-               {
-               printf("Missing PLAINTEXT\n");
-               err = 1;
-               }
-           else
-               {
-               int nn = strlen(ibuf+12);
-               if(!strcmp(amode,"CFB1"))
-                   len=bint2bin(ibuf+12,nn-1,plaintext);
-               else
-                   len=hex2bin(ibuf+12, plaintext);
-               if (len < 0)
-                   {
-                   printf("Invalid PLAINTEXT: %s", ibuf+12);
-                   err =1;
-                   break;
-                   }
-               if (len >= (int)sizeof(plaintext))
-                   {
-                   printf("Buffer overflow\n");
-                   }
-               PrintValue("PLAINTEXT", (unsigned char*)plaintext, len);
-               if (strcmp(atest, "Monte") == 0)  /* Monte Carlo Test */
-                   {
-                   do_mct(amode,akeysz,numkeys,aKey,iVec,dir,plaintext,len,rfp);
-                   }
-               else
-                   {
-                   assert(dir == 1);
-                   ret = DESTest(&ctx, amode, akeysz, aKey, iVec, 
-                                 dir,  /* 0 = decrypt, 1 = encrypt */
-                                 ciphertext, plaintext, len);
-                   OutputValue("CIPHERTEXT",ciphertext,len,rfp,
-                               !strcmp(amode,"CFB1"));
-                   }
-               step = 6;
-               }
-           break;
-
-       case 5: /* CIPHERTEXT = xxxx */
-           fputs(ibuf, rfp);
-           if (strncasecmp(ibuf, "CIPHERTEXT = ", 13) != 0)
-               {
-               printf("Missing KEY\n");
-               err = 1;
-               }
-           else
-               {
-               if(!strcmp(amode,"CFB1"))
-                   len=bint2bin(ibuf+13,strlen(ibuf+13)-1,ciphertext);
-               else
-                   len = hex2bin(ibuf+13,ciphertext);
-               if (len < 0)
-                   {
-                   printf("Invalid CIPHERTEXT\n");
-                   err =1;
-                   break;
-                   }
-               
-               PrintValue("CIPHERTEXT", ciphertext, len);
-               if (strcmp(atest, "Monte") == 0)  /* Monte Carlo Test */
-                   {
-                   do_mct(amode, akeysz, numkeys, aKey, iVec, 
-                          dir, ciphertext, len, rfp);
-                   }
-               else
-                   {
-                   assert(dir == 0);
-                   ret = DESTest(&ctx, amode, akeysz, aKey, iVec, 
-                                 dir,  /* 0 = decrypt, 1 = encrypt */
-                                 plaintext, ciphertext, len);
-                   OutputValue("PLAINTEXT",(unsigned char *)plaintext,len,rfp,
-                               !strcmp(amode,"CFB1"));
-                   }
-               step = 6;
-               }
-           break;
-
-       case 6:
-           if (ibuf[0] != '\n')
-               {
-               err = 1;
-               printf("Missing terminator\n");
-               }
-           else if (strcmp(atest, "MCT") != 0)
-               { /* MCT already added terminating nl */
-               fputs(ibuf, rfp);
-               }
-           step = 1;
-           break;
-           }
-       }
-    if (rfp)
-       fclose(rfp);
-    if (afp)
-       fclose(afp);
-    return err;
-    }
-
-/*--------------------------------------------------
-  Processes either a single file or 
-  a set of files whose names are passed in a file.
-  A single file is specified as:
-    aes_test -f xxx.req
-  A set of files is specified as:
-    aes_test -d xxxxx.xxx
-  The default is: -d req.txt
---------------------------------------------------*/
-int main(int argc, char **argv)
-    {
-    char *rqlist = "req.txt", *rspfile = NULL;
-    FILE *fp = NULL;
-    char fn[250] = "", rfn[256] = "";
-    int f_opt = 0, d_opt = 1;
-
-#ifdef OPENSSL_FIPS
-    if(!FIPS_mode_set(1))
-       {
-       do_print_errors();
-       EXIT(1);
-       }
-#endif
-    if (argc > 1)
-       {
-       if (strcasecmp(argv[1], "-d") == 0)
-           {
-           d_opt = 1;
-           }
-       else if (strcasecmp(argv[1], "-f") == 0)
-           {
-           f_opt = 1;
-           d_opt = 0;
-           }
-       else
-           {
-           printf("Invalid parameter: %s\n", argv[1]);
-           return 0;
-           }
-       if (argc < 3)
-           {
-           printf("Missing parameter\n");
-           return 0;
-           }
-       if (d_opt)
-           rqlist = argv[2];
-       else
-           {
-           strcpy(fn, argv[2]);
-           rspfile = argv[3];
-           }
-       }
-    if (d_opt)
-       { /* list of files (directory) */
-       if (!(fp = fopen(rqlist, "r")))
-           {
-           printf("Cannot open req list file\n");
-           return -1;
-           }
-       while (fgets(fn, sizeof(fn), fp))
-           {
-           strtok(fn, "\r\n");
-           strcpy(rfn, fn);
-           printf("Processing: %s\n", rfn);
-           if (proc_file(rfn, rspfile))
-               {
-               printf(">>> Processing failed for: %s <<<\n", rfn);
-               EXIT(1);
-               }
-           }
-       fclose(fp);
-       }
-    else /* single file */
-       {
-       if (VERBOSE)
-               printf("Processing: %s\n", fn);
-       if (proc_file(fn, rspfile))
-           {
-           printf(">>> Processing failed for: %s <<<\n", fn);
-           }
-       }
-    EXIT(0);
-    return 0;
-    }
-
-#endif
diff --git a/deps/openssl/openssl/fips/dh/Makefile b/deps/openssl/openssl/fips/dh/Makefile
deleted file mode 100644 (file)
index 2d3833a..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-#
-# OpenSSL/fips/dh/Makefile
-#
-
-DIR=   dh
-TOP=   ../..
-CC=    cc
-INCLUDES=
-CFLAG=-g
-INSTALL_PREFIX=
-OPENSSLDIR=     /usr/local/ssl
-INSTALLTOP=/usr/local/ssl
-MAKEDEPPROG=   makedepend
-MAKEDEPEND=    $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
-MAKEFILE=      Makefile
-AR=            ar r
-
-CFLAGS= $(INCLUDES) $(CFLAG)
-
-GENERAL=Makefile
-TEST=
-APPS=
-
-LIB=$(TOP)/libcrypto.a
-LIBSRC=fips_dh_check.c fips_dh_gen.c fips_dh_key.c fips_dh_lib.c
-LIBOBJ=fips_dh_check.o fips_dh_gen.o fips_dh_key.o fips_dh_lib.o
-
-SRC= $(LIBSRC)
-
-EXHEADER=
-HEADER=        $(EXHEADER)
-
-ALL=    $(GENERAL) $(SRC) $(HEADER)
-
-top:
-       (cd $(TOP); $(MAKE) DIRS=fips FDIRS=$(DIR) sub_all)
-
-all:   lib
-
-lib:   $(LIBOBJ)
-       @echo $(LIBOBJ) > lib
-
-files:
-       $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
-
-links:
-       @$(PERL) $(TOP)/util/mklink.pl $(TOP)/include/openssl $(EXHEADER)
-       @$(PERL) $(TOP)/util/mklink.pl $(TOP)/test $(TEST)
-       @$(PERL) $(TOP)/util/mklink.pl $(TOP)/apps $(APPS)
-
-install:
-       @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:
-
-fips_test:
-
-lint:
-       lint -DLINT $(INCLUDES) $(SRC)>fluff
-
-depend:
-       $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(SRC) $(TEST)
-
-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.
-
-fips_dh_check.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
-fips_dh_check.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
-fips_dh_check.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-fips_dh_check.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-fips_dh_check.o: ../../include/openssl/opensslconf.h
-fips_dh_check.o: ../../include/openssl/opensslv.h
-fips_dh_check.o: ../../include/openssl/ossl_typ.h
-fips_dh_check.o: ../../include/openssl/safestack.h
-fips_dh_check.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-fips_dh_check.o: fips_dh_check.c
-fips_dh_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
-fips_dh_gen.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
-fips_dh_gen.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-fips_dh_gen.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-fips_dh_gen.o: ../../include/openssl/opensslconf.h
-fips_dh_gen.o: ../../include/openssl/opensslv.h
-fips_dh_gen.o: ../../include/openssl/ossl_typ.h
-fips_dh_gen.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-fips_dh_gen.o: ../../include/openssl/symhacks.h fips_dh_gen.c
-fips_dh_key.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
-fips_dh_key.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
-fips_dh_key.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-fips_dh_key.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-fips_dh_key.o: ../../include/openssl/opensslconf.h
-fips_dh_key.o: ../../include/openssl/opensslv.h
-fips_dh_key.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
-fips_dh_key.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-fips_dh_key.o: ../../include/openssl/symhacks.h fips_dh_key.c
-fips_dh_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
-fips_dh_lib.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
-fips_dh_lib.o: ../../include/openssl/e_os2.h
-fips_dh_lib.o: ../../include/openssl/opensslconf.h
-fips_dh_lib.o: ../../include/openssl/opensslv.h
-fips_dh_lib.o: ../../include/openssl/ossl_typ.h
-fips_dh_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-fips_dh_lib.o: ../../include/openssl/symhacks.h fips_dh_lib.c
diff --git a/deps/openssl/openssl/fips/dh/dh_gen.c b/deps/openssl/openssl/fips/dh/dh_gen.c
deleted file mode 100644 (file)
index 999e1de..0000000
+++ /dev/null
@@ -1,179 +0,0 @@
-/* crypto/dh/dh_gen.c */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-/* NB: These functions have been upgraded - the previous prototypes are in
- * dh_depr.c as wrappers to these ones.
- *  - Geoff
- */
-
-#include <stdio.h>
-#include "cryptlib.h"
-#include <openssl/bn.h>
-#include <openssl/dh.h>
-
-#ifndef OPENSSL_FIPS
-
-static int dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_GENCB *cb);
-
-int DH_generate_parameters_ex(DH *ret, int prime_len, int generator, BN_GENCB *cb)
-       {
-       if(ret->meth->generate_params)
-               return ret->meth->generate_params(ret, prime_len, generator, cb);
-       return dh_builtin_genparams(ret, prime_len, generator, cb);
-       }
-
-/* We generate DH parameters as follows
- * find a prime q which is prime_len/2 bits long.
- * p=(2*q)+1 or (p-1)/2 = q
- * For this case, g is a generator if
- * g^((p-1)/q) mod p != 1 for values of q which are the factors of p-1.
- * Since the factors of p-1 are q and 2, we just need to check
- * g^2 mod p != 1 and g^q mod p != 1.
- *
- * Having said all that,
- * there is another special case method for the generators 2, 3 and 5.
- * for 2, p mod 24 == 11
- * for 3, p mod 12 == 5  <<<<< does not work for safe primes.
- * for 5, p mod 10 == 3 or 7
- *
- * Thanks to Phil Karn <karn@qualcomm.com> for the pointers about the
- * special generators and for answering some of my questions.
- *
- * I've implemented the second simple method :-).
- * Since DH should be using a safe prime (both p and q are prime),
- * this generator function can take a very very long time to run.
- */
-/* Actually there is no reason to insist that 'generator' be a generator.
- * It's just as OK (and in some sense better) to use a generator of the
- * order-q subgroup.
- */
-static int dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_GENCB *cb)
-       {
-       BIGNUM *t1,*t2;
-       int g,ok= -1;
-       BN_CTX *ctx=NULL;
-
-       ctx=BN_CTX_new();
-       if (ctx == NULL) goto err;
-       BN_CTX_start(ctx);
-       t1 = BN_CTX_get(ctx);
-       t2 = BN_CTX_get(ctx);
-       if (t1 == NULL || t2 == NULL) goto err;
-
-       /* Make sure 'ret' has the necessary elements */
-       if(!ret->p && ((ret->p = BN_new()) == NULL)) goto err;
-       if(!ret->g && ((ret->g = BN_new()) == NULL)) goto err;
-       
-       if (generator <= 1)
-               {
-               DHerr(DH_F_DH_BUILTIN_GENPARAMS, DH_R_BAD_GENERATOR);
-               goto err;
-               }
-       if (generator == DH_GENERATOR_2)
-               {
-               if (!BN_set_word(t1,24)) goto err;
-               if (!BN_set_word(t2,11)) goto err;
-               g=2;
-               }
-#if 0 /* does not work for safe primes */
-       else if (generator == DH_GENERATOR_3)
-               {
-               if (!BN_set_word(t1,12)) goto err;
-               if (!BN_set_word(t2,5)) goto err;
-               g=3;
-               }
-#endif
-       else if (generator == DH_GENERATOR_5)
-               {
-               if (!BN_set_word(t1,10)) goto err;
-               if (!BN_set_word(t2,3)) goto err;
-               /* BN_set_word(t3,7); just have to miss
-                * out on these ones :-( */
-               g=5;
-               }
-       else
-               {
-               /* in the general case, don't worry if 'generator' is a
-                * generator or not: since we are using safe primes,
-                * it will generate either an order-q or an order-2q group,
-                * which both is OK */
-               if (!BN_set_word(t1,2)) goto err;
-               if (!BN_set_word(t2,1)) goto err;
-               g=generator;
-               }
-       
-       if(!BN_generate_prime_ex(ret->p,prime_len,1,t1,t2,cb)) goto err;
-       if(!BN_GENCB_call(cb, 3, 0)) goto err;
-       if (!BN_set_word(ret->g,g)) goto err;
-       ok=1;
-err:
-       if (ok == -1)
-               {
-               DHerr(DH_F_DH_BUILTIN_GENPARAMS,ERR_R_BN_LIB);
-               ok=0;
-               }
-
-       if (ctx != NULL)
-               {
-               BN_CTX_end(ctx);
-               BN_CTX_free(ctx);
-               }
-       return ok;
-       }
-
-#endif
diff --git a/deps/openssl/openssl/fips/dh/fips_dh_check.c b/deps/openssl/openssl/fips/dh/fips_dh_check.c
deleted file mode 100644 (file)
index 7333f7c..0000000
+++ /dev/null
@@ -1,147 +0,0 @@
-/* crypto/dh/dh_check.c */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-#include <stdio.h>
-#include <openssl/bn.h>
-#include <openssl/dh.h>
-#include <openssl/err.h>
-#include <openssl/fips.h>
-
-/* Check that p is a safe prime and
- * if g is 2, 3 or 5, check that is is a suitable generator
- * where
- * for 2, p mod 24 == 11
- * for 3, p mod 12 == 5
- * for 5, p mod 10 == 3 or 7
- * should hold.
- */
-
-#ifdef OPENSSL_FIPS
-
-int DH_check(const DH *dh, int *ret)
-       {
-       int ok=0;
-       BN_CTX *ctx=NULL;
-       BN_ULONG l;
-       BIGNUM *q=NULL;
-
-       *ret=0;
-       ctx=BN_CTX_new();
-       if (ctx == NULL) goto err;
-       q=BN_new();
-       if (q == NULL) goto err;
-
-       if (BN_is_word(dh->g,DH_GENERATOR_2))
-               {
-               l=BN_mod_word(dh->p,24);
-               if (l != 11) *ret|=DH_NOT_SUITABLE_GENERATOR;
-               }
-#if 0
-       else if (BN_is_word(dh->g,DH_GENERATOR_3))
-               {
-               l=BN_mod_word(dh->p,12);
-               if (l != 5) *ret|=DH_NOT_SUITABLE_GENERATOR;
-               }
-#endif
-       else if (BN_is_word(dh->g,DH_GENERATOR_5))
-               {
-               l=BN_mod_word(dh->p,10);
-               if ((l != 3) && (l != 7))
-                       *ret|=DH_NOT_SUITABLE_GENERATOR;
-               }
-       else
-               *ret|=DH_UNABLE_TO_CHECK_GENERATOR;
-
-       if (!BN_is_prime_ex(dh->p,BN_prime_checks,ctx,NULL))
-               *ret|=DH_CHECK_P_NOT_PRIME;
-       else
-               {
-               if (!BN_rshift1(q,dh->p)) goto err;
-               if (!BN_is_prime_ex(q,BN_prime_checks,ctx,NULL))
-                       *ret|=DH_CHECK_P_NOT_SAFE_PRIME;
-               }
-       ok=1;
-err:
-       if (ctx != NULL) BN_CTX_free(ctx);
-       if (q != NULL) BN_free(q);
-       return(ok);
-       }
-
-int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *ret)
-       {
-       int ok=0;
-       BIGNUM *q=NULL;
-
-       *ret=0;
-       q=BN_new();
-       if (q == NULL) goto err;
-       BN_set_word(q,1);
-       if (BN_cmp(pub_key,q) <= 0)
-               *ret|=DH_CHECK_PUBKEY_TOO_SMALL;
-       BN_copy(q,dh->p);
-       BN_sub_word(q,1);
-       if (BN_cmp(pub_key,q) >= 0)
-               *ret|=DH_CHECK_PUBKEY_TOO_LARGE;
-
-       ok = 1;
-err:
-       if (q != NULL) BN_free(q);
-       return(ok);
-       }
-
-#endif
diff --git a/deps/openssl/openssl/fips/dh/fips_dh_gen.c b/deps/openssl/openssl/fips/dh/fips_dh_gen.c
deleted file mode 100644 (file)
index d115f9d..0000000
+++ /dev/null
@@ -1,192 +0,0 @@
-/* crypto/dh/dh_gen.c */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-/* NB: These functions have been upgraded - the previous prototypes are in
- * dh_depr.c as wrappers to these ones.
- *  - Geoff
- */
-
-#include <stdio.h>
-#include <openssl/bn.h>
-#include <openssl/dh.h>
-#include <openssl/err.h>
-#include <openssl/fips.h>
-
-#ifdef OPENSSL_FIPS
-
-static int dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_GENCB *cb);
-
-int DH_generate_parameters_ex(DH *ret, int prime_len, int generator, BN_GENCB *cb)
-       {
-       if(ret->meth->generate_params)
-               return ret->meth->generate_params(ret, prime_len, generator, cb);
-       return dh_builtin_genparams(ret, prime_len, generator, cb);
-       }
-
-/* We generate DH parameters as follows
- * find a prime q which is prime_len/2 bits long.
- * p=(2*q)+1 or (p-1)/2 = q
- * For this case, g is a generator if
- * g^((p-1)/q) mod p != 1 for values of q which are the factors of p-1.
- * Since the factors of p-1 are q and 2, we just need to check
- * g^2 mod p != 1 and g^q mod p != 1.
- *
- * Having said all that,
- * there is another special case method for the generators 2, 3 and 5.
- * for 2, p mod 24 == 11
- * for 3, p mod 12 == 5  <<<<< does not work for safe primes.
- * for 5, p mod 10 == 3 or 7
- *
- * Thanks to Phil Karn <karn@qualcomm.com> for the pointers about the
- * special generators and for answering some of my questions.
- *
- * I've implemented the second simple method :-).
- * Since DH should be using a safe prime (both p and q are prime),
- * this generator function can take a very very long time to run.
- */
-/* Actually there is no reason to insist that 'generator' be a generator.
- * It's just as OK (and in some sense better) to use a generator of the
- * order-q subgroup.
- */
-static int dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_GENCB *cb)
-       {
-       BIGNUM *t1,*t2;
-       int g,ok= -1;
-       BN_CTX *ctx=NULL;
-
-       if(FIPS_selftest_failed())
-               {
-               FIPSerr(FIPS_F_DH_BUILTIN_GENPARAMS,FIPS_R_FIPS_SELFTEST_FAILED);
-               return 0;
-               }
-
-       if (FIPS_mode() && (prime_len < OPENSSL_DH_FIPS_MIN_MODULUS_BITS))
-               {
-               DHerr(DH_F_DH_BUILTIN_GENPARAMS, DH_R_KEY_SIZE_TOO_SMALL);
-               goto err;
-               }
-
-       ctx=BN_CTX_new();
-       if (ctx == NULL) goto err;
-       BN_CTX_start(ctx);
-       t1 = BN_CTX_get(ctx);
-       t2 = BN_CTX_get(ctx);
-       if (t1 == NULL || t2 == NULL) goto err;
-
-       /* Make sure 'ret' has the necessary elements */
-       if(!ret->p && ((ret->p = BN_new()) == NULL)) goto err;
-       if(!ret->g && ((ret->g = BN_new()) == NULL)) goto err;
-       
-       if (generator <= 1)
-               {
-               DHerr(DH_F_DH_BUILTIN_GENPARAMS, DH_R_BAD_GENERATOR);
-               goto err;
-               }
-       if (generator == DH_GENERATOR_2)
-               {
-               if (!BN_set_word(t1,24)) goto err;
-               if (!BN_set_word(t2,11)) goto err;
-               g=2;
-               }
-#if 0 /* does not work for safe primes */
-       else if (generator == DH_GENERATOR_3)
-               {
-               if (!BN_set_word(t1,12)) goto err;
-               if (!BN_set_word(t2,5)) goto err;
-               g=3;
-               }
-#endif
-       else if (generator == DH_GENERATOR_5)
-               {
-               if (!BN_set_word(t1,10)) goto err;
-               if (!BN_set_word(t2,3)) goto err;
-               /* BN_set_word(t3,7); just have to miss
-                * out on these ones :-( */
-               g=5;
-               }
-       else
-               {
-               /* in the general case, don't worry if 'generator' is a
-                * generator or not: since we are using safe primes,
-                * it will generate either an order-q or an order-2q group,
-                * which both is OK */
-               if (!BN_set_word(t1,2)) goto err;
-               if (!BN_set_word(t2,1)) goto err;
-               g=generator;
-               }
-       
-       if(!BN_generate_prime_ex(ret->p,prime_len,1,t1,t2,cb)) goto err;
-       if(!BN_GENCB_call(cb, 3, 0)) goto err;
-       if (!BN_set_word(ret->g,g)) goto err;
-       ok=1;
-err:
-       if (ok == -1)
-               {
-               DHerr(DH_F_DH_BUILTIN_GENPARAMS,ERR_R_BN_LIB);
-               ok=0;
-               }
-
-       if (ctx != NULL)
-               {
-               BN_CTX_end(ctx);
-               BN_CTX_free(ctx);
-               }
-       return ok;
-       }
-
-#endif
diff --git a/deps/openssl/openssl/fips/dh/fips_dh_key.c b/deps/openssl/openssl/fips/dh/fips_dh_key.c
deleted file mode 100644 (file)
index d20fa91..0000000
+++ /dev/null
@@ -1,276 +0,0 @@
-/* crypto/dh/dh_key.c */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-#include <stdio.h>
-#include <openssl/err.h>
-#include <openssl/bn.h>
-#ifndef OPENSSL_NO_RAND
-#include <openssl/rand.h>
-#endif
-#ifndef OPENSSL_NO_DH
-#include <openssl/dh.h>
-#include <openssl/fips.h>
-
-#ifdef OPENSSL_FIPS
-
-static int generate_key(DH *dh);
-static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh);
-static int dh_bn_mod_exp(const DH *dh, BIGNUM *r,
-                       const BIGNUM *a, const BIGNUM *p,
-                       const BIGNUM *m, BN_CTX *ctx,
-                       BN_MONT_CTX *m_ctx);
-static int dh_init(DH *dh);
-static int dh_finish(DH *dh);
-
-int DH_generate_key(DH *dh)
-       {
-       return dh->meth->generate_key(dh);
-       }
-
-int DH_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
-       {
-       return dh->meth->compute_key(key, pub_key, dh);
-       }
-
-static const DH_METHOD dh_ossl = {
-"OpenSSL DH Method",
-generate_key,
-compute_key,
-dh_bn_mod_exp,
-dh_init,
-dh_finish,
-0,
-NULL
-};
-
-const DH_METHOD *DH_OpenSSL(void)
-{
-       return &dh_ossl;
-}
-
-static int generate_key(DH *dh)
-       {
-       int ok=0;
-       int generate_new_key=0;
-       unsigned l;
-       BN_CTX *ctx;
-       BN_MONT_CTX *mont=NULL;
-       BIGNUM *pub_key=NULL,*priv_key=NULL;
-
-       if (FIPS_mode() && (BN_num_bits(dh->p) < OPENSSL_DH_FIPS_MIN_MODULUS_BITS))
-               {
-               DHerr(DH_F_GENERATE_KEY, DH_R_KEY_SIZE_TOO_SMALL);
-               return 0;
-               }
-
-       ctx = BN_CTX_new();
-       if (ctx == NULL) goto err;
-
-       if (dh->priv_key == NULL)
-               {
-               priv_key=BN_new();
-               if (priv_key == NULL) goto err;
-               generate_new_key=1;
-               }
-       else
-               priv_key=dh->priv_key;
-
-       if (dh->pub_key == NULL)
-               {
-               pub_key=BN_new();
-               if (pub_key == NULL) goto err;
-               }
-       else
-               pub_key=dh->pub_key;
-
-       if (dh->flags & DH_FLAG_CACHE_MONT_P)
-               {
-               mont = BN_MONT_CTX_set_locked(
-                               (BN_MONT_CTX **)&dh->method_mont_p,
-                               CRYPTO_LOCK_DH, dh->p, ctx);
-               if (!mont)
-                       goto err;
-               }
-
-       if (generate_new_key)
-               {
-               l = dh->length ? dh->length : BN_num_bits(dh->p)-1; /* secret exponent length */
-               if (!BN_rand(priv_key, l, 0, 0)) goto err;
-               }
-
-       {
-               BIGNUM local_prk;
-               BIGNUM *prk;
-
-               if ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) == 0)
-                       {
-                       BN_init(&local_prk);
-                       prk = &local_prk;
-                       BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME);
-                       }
-               else
-                       prk = priv_key;
-
-               if (!dh->meth->bn_mod_exp(dh, pub_key, dh->g, prk, dh->p, ctx, mont))
-                       goto err;
-       }
-               
-       dh->pub_key=pub_key;
-       dh->priv_key=priv_key;
-       ok=1;
-err:
-       if (ok != 1)
-               DHerr(DH_F_GENERATE_KEY,ERR_R_BN_LIB);
-
-       if ((pub_key != NULL)  && (dh->pub_key == NULL))  BN_free(pub_key);
-       if ((priv_key != NULL) && (dh->priv_key == NULL)) BN_free(priv_key);
-       BN_CTX_free(ctx);
-       return(ok);
-       }
-
-static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
-       {
-       BN_CTX *ctx;
-       BN_MONT_CTX *mont=NULL;
-       BIGNUM *tmp;
-       int ret= -1;
-
-       ctx = BN_CTX_new();
-       if (ctx == NULL) goto err;
-       BN_CTX_start(ctx);
-       tmp = BN_CTX_get(ctx);
-
-       if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS)
-               {
-               DHerr(DH_F_COMPUTE_KEY,DH_R_MODULUS_TOO_LARGE);
-               goto err;
-               }
-
-       if (FIPS_mode() && (BN_num_bits(dh->p) < OPENSSL_DH_FIPS_MIN_MODULUS_BITS))
-               {
-               DHerr(DH_F_COMPUTE_KEY, DH_R_KEY_SIZE_TOO_SMALL);
-               goto err;
-               }
-
-       if (dh->priv_key == NULL)
-               {
-               DHerr(DH_F_COMPUTE_KEY,DH_R_NO_PRIVATE_VALUE);
-               goto err;
-               }
-
-       if (dh->flags & DH_FLAG_CACHE_MONT_P)
-               {
-               mont = BN_MONT_CTX_set_locked(
-                               (BN_MONT_CTX **)&dh->method_mont_p,
-                               CRYPTO_LOCK_DH, dh->p, ctx);
-               if ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) == 0)
-                       {
-                       /* XXX */
-                       BN_set_flags(dh->priv_key, BN_FLG_CONSTTIME);
-                       }
-               if (!mont)
-                       goto err;
-               }
-
-       if (!dh->meth->bn_mod_exp(dh, tmp, pub_key, dh->priv_key,dh->p,ctx,mont))
-               {
-               DHerr(DH_F_COMPUTE_KEY,ERR_R_BN_LIB);
-               goto err;
-               }
-
-       ret=BN_bn2bin(tmp,key);
-err:
-       BN_CTX_end(ctx);
-       BN_CTX_free(ctx);
-       return(ret);
-       }
-
-static int dh_bn_mod_exp(const DH *dh, BIGNUM *r,
-                       const BIGNUM *a, const BIGNUM *p,
-                       const BIGNUM *m, BN_CTX *ctx,
-                       BN_MONT_CTX *m_ctx)
-       {
-       /* If a is only one word long and constant time is false, use the faster
-        * exponenentiation function.
-        */
-       if (a->top == 1 && ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) != 0))
-               {
-               BN_ULONG A = a->d[0];
-               return BN_mod_exp_mont_word(r,A,p,m,ctx,m_ctx);
-               }
-       else
-               return BN_mod_exp_mont(r,a,p,m,ctx,m_ctx);
-       }
-
-
-static int dh_init(DH *dh)
-       {
-       FIPS_selftest_check();
-       dh->flags |= DH_FLAG_CACHE_MONT_P;
-       return(1);
-       }
-
-static int dh_finish(DH *dh)
-       {
-       if(dh->method_mont_p)
-               BN_MONT_CTX_free((BN_MONT_CTX *)dh->method_mont_p);
-       return(1);
-       }
-
-#endif
-#endif
diff --git a/deps/openssl/openssl/fips/dsa/Makefile b/deps/openssl/openssl/fips/dsa/Makefile
deleted file mode 100644 (file)
index 251615e..0000000
+++ /dev/null
@@ -1,191 +0,0 @@
-#
-# OpenSSL/fips/dsa/Makefile
-#
-
-DIR=   dsa
-TOP=   ../..
-CC=    cc
-INCLUDES=
-CFLAG=-g
-INSTALL_PREFIX=
-OPENSSLDIR=     /usr/local/ssl
-INSTALLTOP=/usr/local/ssl
-MAKEDEPPROG=   makedepend
-MAKEDEPEND=    $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
-MAKEFILE=      Makefile
-AR=            ar r
-
-CFLAGS= $(INCLUDES) $(CFLAG)
-
-GENERAL=Makefile
-TEST=fips_dsatest.c fips_dssvs.c
-APPS=
-
-LIB=$(TOP)/libcrypto.a
-LIBSRC=fips_dsa_ossl.c fips_dsa_gen.c fips_dsa_selftest.c fips_dsa_key.c \
-       fips_dsa_lib.c fips_dsa_sign.c
-LIBOBJ=fips_dsa_ossl.o fips_dsa_gen.o fips_dsa_selftest.o fips_dsa_key.o \
-       fips_dsa_lib.o fips_dsa_sign.o
-
-SRC= $(LIBSRC)
-
-EXHEADER=
-HEADER=        $(EXHEADER)
-
-ALL=    $(GENERAL) $(SRC) $(HEADER)
-
-top:
-       (cd $(TOP); $(MAKE) DIRS=fips FDIRS=$(DIR) sub_all)
-
-all:   lib
-
-lib:   $(LIBOBJ)
-       @echo $(LIBOBJ) > lib
-
-files:
-       $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
-
-links:
-       @$(PERL) $(TOP)/util/mklink.pl $(TOP)/include/openssl $(EXHEADER)
-       @$(PERL) $(TOP)/util/mklink.pl $(TOP)/test $(TEST)
-       @$(PERL) $(TOP)/util/mklink.pl $(TOP)/apps $(APPS)
-
-install:
-       @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:
-
-Q=../testvectors/dsa/req
-A=../testvectors/dsa/rsp
-
-fips_test:
-       -rm -rf $A
-       mkdir $A
-       if [ -f $(Q)/PQGGen.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_dssvs pqg < $(Q)/PQGGen.req > $(A)/PQGGen.rsp; fi
-       if [ -f $(Q)/KeyPair.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_dssvs keypair < $(Q)/KeyPair.req > $(A)/KeyPair.rsp; fi
-       if [ -f $(Q)/SigGen.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_dssvs siggen < $(Q)/SigGen.req > $(A)/SigGen.rsp; fi
-       if [ -f $(Q)/SigVer.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_dssvs sigver < $Q/SigVer.req > $A/SigVer.rsp; fi
-
-lint:
-       lint -DLINT $(INCLUDES) $(SRC)>fluff
-
-depend:
-       $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(SRC) $(TEST)
-
-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.
-
-fips_dsa_gen.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-fips_dsa_gen.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
-fips_dsa_gen.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
-fips_dsa_gen.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-fips_dsa_gen.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-fips_dsa_gen.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-fips_dsa_gen.o: ../../include/openssl/opensslconf.h
-fips_dsa_gen.o: ../../include/openssl/opensslv.h
-fips_dsa_gen.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
-fips_dsa_gen.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-fips_dsa_gen.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-fips_dsa_gen.o: fips_dsa_gen.c
-fips_dsa_key.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-fips_dsa_key.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
-fips_dsa_key.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
-fips_dsa_key.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-fips_dsa_key.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-fips_dsa_key.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-fips_dsa_key.o: ../../include/openssl/opensslconf.h
-fips_dsa_key.o: ../../include/openssl/opensslv.h
-fips_dsa_key.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
-fips_dsa_key.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-fips_dsa_key.o: ../../include/openssl/symhacks.h ../fips_locl.h fips_dsa_key.c
-fips_dsa_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
-fips_dsa_lib.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
-fips_dsa_lib.o: ../../include/openssl/e_os2.h
-fips_dsa_lib.o: ../../include/openssl/opensslconf.h
-fips_dsa_lib.o: ../../include/openssl/opensslv.h
-fips_dsa_lib.o: ../../include/openssl/ossl_typ.h
-fips_dsa_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-fips_dsa_lib.o: ../../include/openssl/symhacks.h fips_dsa_lib.c
-fips_dsa_ossl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-fips_dsa_ossl.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
-fips_dsa_ossl.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
-fips_dsa_ossl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-fips_dsa_ossl.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
-fips_dsa_ossl.o: ../../include/openssl/engine.h ../../include/openssl/err.h
-fips_dsa_ossl.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-fips_dsa_ossl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-fips_dsa_ossl.o: ../../include/openssl/objects.h
-fips_dsa_ossl.o: ../../include/openssl/opensslconf.h
-fips_dsa_ossl.o: ../../include/openssl/opensslv.h
-fips_dsa_ossl.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-fips_dsa_ossl.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
-fips_dsa_ossl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-fips_dsa_ossl.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-fips_dsa_ossl.o: ../../include/openssl/x509_vfy.h fips_dsa_ossl.c
-fips_dsa_selftest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-fips_dsa_selftest.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
-fips_dsa_selftest.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
-fips_dsa_selftest.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-fips_dsa_selftest.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-fips_dsa_selftest.o: ../../include/openssl/obj_mac.h
-fips_dsa_selftest.o: ../../include/openssl/objects.h
-fips_dsa_selftest.o: ../../include/openssl/opensslconf.h
-fips_dsa_selftest.o: ../../include/openssl/opensslv.h
-fips_dsa_selftest.o: ../../include/openssl/ossl_typ.h
-fips_dsa_selftest.o: ../../include/openssl/safestack.h
-fips_dsa_selftest.o: ../../include/openssl/stack.h
-fips_dsa_selftest.o: ../../include/openssl/symhacks.h fips_dsa_selftest.c
-fips_dsa_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-fips_dsa_sign.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
-fips_dsa_sign.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
-fips_dsa_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-fips_dsa_sign.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-fips_dsa_sign.o: ../../include/openssl/obj_mac.h
-fips_dsa_sign.o: ../../include/openssl/objects.h
-fips_dsa_sign.o: ../../include/openssl/opensslconf.h
-fips_dsa_sign.o: ../../include/openssl/opensslv.h
-fips_dsa_sign.o: ../../include/openssl/ossl_typ.h
-fips_dsa_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-fips_dsa_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-fips_dsa_sign.o: fips_dsa_sign.c
-fips_dsatest.o: ../../e_os.h ../../include/openssl/asn1.h
-fips_dsatest.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
-fips_dsatest.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
-fips_dsatest.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
-fips_dsatest.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
-fips_dsatest.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
-fips_dsatest.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
-fips_dsatest.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-fips_dsatest.o: ../../include/openssl/fips.h ../../include/openssl/fips_rand.h
-fips_dsatest.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-fips_dsatest.o: ../../include/openssl/objects.h
-fips_dsatest.o: ../../include/openssl/opensslconf.h
-fips_dsatest.o: ../../include/openssl/opensslv.h
-fips_dsatest.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-fips_dsatest.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
-fips_dsatest.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-fips_dsatest.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
-fips_dsatest.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
-fips_dsatest.o: ../../include/openssl/x509_vfy.h ../fips_utl.h fips_dsatest.c
-fips_dssvs.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-fips_dssvs.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
-fips_dssvs.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
-fips_dssvs.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-fips_dssvs.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-fips_dssvs.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-fips_dssvs.o: ../../include/openssl/opensslconf.h
-fips_dssvs.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-fips_dssvs.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-fips_dssvs.o: ../../include/openssl/symhacks.h ../fips_utl.h fips_dssvs.c
diff --git a/deps/openssl/openssl/fips/dsa/fips_dsa_gen.c b/deps/openssl/openssl/fips/dsa/fips_dsa_gen.c
deleted file mode 100644 (file)
index 0cecf34..0000000
+++ /dev/null
@@ -1,339 +0,0 @@
-/* crypto/dsa/dsa_gen.c */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-#undef GENUINE_DSA
-
-#ifdef GENUINE_DSA
-/* Parameter generation follows the original release of FIPS PUB 186,
- * Appendix 2.2 (i.e. use SHA as defined in FIPS PUB 180) */
-#define HASH    EVP_sha()
-#else
-/* Parameter generation follows the updated Appendix 2.2 for FIPS PUB 186,
- * also Appendix 2.2 of FIPS PUB 186-1 (i.e. use SHA as defined in
- * FIPS PUB 180-1) */
-#define HASH    EVP_sha1()
-#endif 
-
-#include <openssl/opensslconf.h> /* To see if OPENSSL_NO_SHA is defined */
-
-#ifndef OPENSSL_NO_SHA
-
-#include <stdio.h>
-#include <time.h>
-#include <string.h>
-#include <openssl/evp.h>
-#include <openssl/bn.h>
-#include <openssl/dsa.h>
-#include <openssl/rand.h>
-#include <openssl/sha.h>
-#include <openssl/err.h>
-
-#ifdef OPENSSL_FIPS
-
-static int dsa_builtin_paramgen(DSA *ret, int bits,
-               unsigned char *seed_in, int seed_len,
-               int *counter_ret, unsigned long *h_ret, BN_GENCB *cb);
-
-int DSA_generate_parameters_ex(DSA *ret, int bits,
-               unsigned char *seed_in, int seed_len,
-               int *counter_ret, unsigned long *h_ret, BN_GENCB *cb)
-       {
-       if(ret->meth->dsa_paramgen)
-               return ret->meth->dsa_paramgen(ret, bits, seed_in, seed_len,
-                               counter_ret, h_ret, cb);
-       return dsa_builtin_paramgen(ret, bits, seed_in, seed_len,
-                       counter_ret, h_ret, cb);
-       }
-
-static int dsa_builtin_paramgen(DSA *ret, int bits,
-               unsigned char *seed_in, int seed_len,
-               int *counter_ret, unsigned long *h_ret, BN_GENCB *cb)
-       {
-       int ok=0;
-       unsigned char seed[SHA_DIGEST_LENGTH];
-       unsigned char md[SHA_DIGEST_LENGTH];
-       unsigned char buf[SHA_DIGEST_LENGTH],buf2[SHA_DIGEST_LENGTH];
-       BIGNUM *r0,*W,*X,*c,*test;
-       BIGNUM *g=NULL,*q=NULL,*p=NULL;
-       BN_MONT_CTX *mont=NULL;
-       int k,n=0,i,b,m=0;
-       int counter=0;
-       int r=0;
-       BN_CTX *ctx=NULL;
-       unsigned int h=2;
-
-       if(FIPS_selftest_failed())
-           {
-           FIPSerr(FIPS_F_DSA_BUILTIN_PARAMGEN,
-                   FIPS_R_FIPS_SELFTEST_FAILED);
-           goto err;
-           }
-
-       if (FIPS_mode() && (bits < OPENSSL_DSA_FIPS_MIN_MODULUS_BITS))
-               {
-               DSAerr(DSA_F_DSA_BUILTIN_PARAMGEN, DSA_R_KEY_SIZE_TOO_SMALL);
-               goto err;
-               }
-
-       if (bits < 512) bits=512;
-       bits=(bits+63)/64*64;
-
-       /* NB: seed_len == 0 is special case: copy generated seed to
-        * seed_in if it is not NULL.
-        */
-       if (seed_len && (seed_len < 20))
-               seed_in = NULL; /* seed buffer too small -- ignore */
-       if (seed_len > 20) 
-               seed_len = 20; /* App. 2.2 of FIPS PUB 186 allows larger SEED,
-                               * but our internal buffers are restricted to 160 bits*/
-       if ((seed_in != NULL) && (seed_len == 20))
-               {
-               memcpy(seed,seed_in,seed_len);
-               /* set seed_in to NULL to avoid it being copied back */
-               seed_in = NULL;
-               }
-
-       if ((ctx=BN_CTX_new()) == NULL) goto err;
-
-       if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
-
-       BN_CTX_start(ctx);
-       r0 = BN_CTX_get(ctx);
-       g = BN_CTX_get(ctx);
-       W = BN_CTX_get(ctx);
-       q = BN_CTX_get(ctx);
-       X = BN_CTX_get(ctx);
-       c = BN_CTX_get(ctx);
-       p = BN_CTX_get(ctx);
-       test = BN_CTX_get(ctx);
-
-       if (!BN_lshift(test,BN_value_one(),bits-1))
-               goto err;
-
-       for (;;)
-               {
-               for (;;) /* find q */
-                       {
-                       int seed_is_random;
-
-                       /* step 1 */
-                       if(!BN_GENCB_call(cb, 0, m++))
-                               goto err;
-
-                       if (!seed_len)
-                               {
-                               RAND_pseudo_bytes(seed,SHA_DIGEST_LENGTH);
-                               seed_is_random = 1;
-                               }
-                       else
-                               {
-                               seed_is_random = 0;
-                               seed_len=0; /* use random seed if 'seed_in' turns out to be bad*/
-                               }
-                       memcpy(buf,seed,SHA_DIGEST_LENGTH);
-                       memcpy(buf2,seed,SHA_DIGEST_LENGTH);
-                       /* precompute "SEED + 1" for step 7: */
-                       for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--)
-                               {
-                               buf[i]++;
-                               if (buf[i] != 0) break;
-                               }
-
-                       /* step 2 */
-                       EVP_Digest(seed,SHA_DIGEST_LENGTH,md,NULL,HASH, NULL);
-                       EVP_Digest(buf,SHA_DIGEST_LENGTH,buf2,NULL,HASH, NULL);
-                       for (i=0; i<SHA_DIGEST_LENGTH; i++)
-                               md[i]^=buf2[i];
-
-                       /* step 3 */
-                       md[0]|=0x80;
-                       md[SHA_DIGEST_LENGTH-1]|=0x01;
-                       if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,q)) goto err;
-
-                       /* step 4 */
-                       r = BN_is_prime_fasttest_ex(q, DSS_prime_checks, ctx,
-                                       seed_is_random, cb);
-                       if (r > 0)
-                               break;
-                       if (r != 0)
-                               goto err;
-
-                       /* do a callback call */
-                       /* step 5 */
-                       }
-
-               if(!BN_GENCB_call(cb, 2, 0)) goto err;
-               if(!BN_GENCB_call(cb, 3, 0)) goto err;
-
-               /* step 6 */
-               counter=0;
-               /* "offset = 2" */
-
-               n=(bits-1)/160;
-               b=(bits-1)-n*160;
-
-               for (;;)
-                       {
-                       if ((counter != 0) && !BN_GENCB_call(cb, 0, counter))
-                               goto err;
-
-                       /* step 7 */
-                       BN_zero(W);
-                       /* now 'buf' contains "SEED + offset - 1" */
-                       for (k=0; k<=n; k++)
-                               {
-                               /* obtain "SEED + offset + k" by incrementing: */
-                               for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--)
-                                       {
-                                       buf[i]++;
-                                       if (buf[i] != 0) break;
-                                       }
-
-                               EVP_Digest(buf,SHA_DIGEST_LENGTH,md,NULL,HASH, NULL);
-
-                               /* step 8 */
-                               if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,r0))
-                                       goto err;
-                               if (!BN_lshift(r0,r0,160*k)) goto err;
-                               if (!BN_add(W,W,r0)) goto err;
-                               }
-
-                       /* more of step 8 */
-                       if (!BN_mask_bits(W,bits-1)) goto err;
-                       if (!BN_copy(X,W)) goto err;
-                       if (!BN_add(X,X,test)) goto err;
-
-                       /* step 9 */
-                       if (!BN_lshift1(r0,q)) goto err;
-                       if (!BN_mod(c,X,r0,ctx)) goto err;
-                       if (!BN_sub(r0,c,BN_value_one())) goto err;
-                       if (!BN_sub(p,X,r0)) goto err;
-
-                       /* step 10 */
-                       if (BN_cmp(p,test) >= 0)
-                               {
-                               /* step 11 */
-                               r = BN_is_prime_fasttest_ex(p, DSS_prime_checks,
-                                               ctx, 1, cb);
-                               if (r > 0)
-                                               goto end; /* found it */
-                               if (r != 0)
-                                       goto err;
-                               }
-
-                       /* step 13 */
-                       counter++;
-                       /* "offset = offset + n + 1" */
-
-                       /* step 14 */
-                       if (counter >= 4096) break;
-                       }
-               }
-end:
-       if(!BN_GENCB_call(cb, 2, 1))
-               goto err;
-
-       /* We now need to generate g */
-       /* Set r0=(p-1)/q */
-       if (!BN_sub(test,p,BN_value_one())) goto err;
-       if (!BN_div(r0,NULL,test,q,ctx)) goto err;
-
-       if (!BN_set_word(test,h)) goto err;
-       if (!BN_MONT_CTX_set(mont,p,ctx)) goto err;
-
-       for (;;)
-               {
-               /* g=test^r0%p */
-               if (!BN_mod_exp_mont(g,test,r0,p,ctx,mont)) goto err;
-               if (!BN_is_one(g)) break;
-               if (!BN_add(test,test,BN_value_one())) goto err;
-               h++;
-               }
-
-       if(!BN_GENCB_call(cb, 3, 1))
-               goto err;
-
-       ok=1;
-err:
-       if (ok)
-               {
-               if(ret->p) BN_free(ret->p);
-               if(ret->q) BN_free(ret->q);
-               if(ret->g) BN_free(ret->g);
-               ret->p=BN_dup(p);
-               ret->q=BN_dup(q);
-               ret->g=BN_dup(g);
-               if (ret->p == NULL || ret->q == NULL || ret->g == NULL)
-                       {
-                       ok=0;
-                       goto err;
-                       }
-               if (seed_in != NULL) memcpy(seed_in,seed,20);
-               if (counter_ret != NULL) *counter_ret=counter;
-               if (h_ret != NULL) *h_ret=h;
-               }
-       if(ctx)
-               {
-               BN_CTX_end(ctx);
-               BN_CTX_free(ctx);
-               }
-       if (mont != NULL) BN_MONT_CTX_free(mont);
-       return ok;
-       }
-#endif
-#endif
diff --git a/deps/openssl/openssl/fips/dsa/fips_dsa_key.c b/deps/openssl/openssl/fips/dsa/fips_dsa_key.c
deleted file mode 100644 (file)
index 9f21033..0000000
+++ /dev/null
@@ -1,169 +0,0 @@
-/* crypto/dsa/dsa_key.c */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-#include <stdio.h>
-#include <time.h>
-#ifndef OPENSSL_NO_SHA
-#include <openssl/bn.h>
-#include <openssl/dsa.h>
-#include <openssl/rand.h>
-#include <openssl/err.h>
-#include <openssl/evp.h>
-#include <openssl/fips.h>
-#include "fips_locl.h"
-
-#ifdef OPENSSL_FIPS
-
-static int fips_dsa_pairwise_fail = 0;
-
-void FIPS_corrupt_dsa_keygen(void)
-       {
-       fips_dsa_pairwise_fail = 1;
-       }
-
-static int dsa_builtin_keygen(DSA *dsa);
-
-static int fips_check_dsa(DSA *dsa)
-       {
-       EVP_PKEY pk;
-       unsigned char tbs[] = "DSA Pairwise Check Data";
-       pk.type = EVP_PKEY_DSA;
-       pk.pkey.dsa = dsa;
-
-       if (!fips_pkey_signature_test(&pk, tbs, -1,
-                                       NULL, 0, EVP_dss1(), 0, NULL))
-               {
-               FIPSerr(FIPS_F_FIPS_CHECK_DSA,FIPS_R_PAIRWISE_TEST_FAILED);
-               fips_set_selftest_fail();
-               return 0;
-               }
-       return 1;
-       }
-
-int DSA_generate_key(DSA *dsa)
-       {
-       if(dsa->meth->dsa_keygen)
-               return dsa->meth->dsa_keygen(dsa);
-       return dsa_builtin_keygen(dsa);
-       }
-
-static int dsa_builtin_keygen(DSA *dsa)
-       {
-       int ok=0;
-       BN_CTX *ctx=NULL;
-       BIGNUM *pub_key=NULL,*priv_key=NULL;
-
-       if (FIPS_mode() && (BN_num_bits(dsa->p) < OPENSSL_DSA_FIPS_MIN_MODULUS_BITS))
-               {
-               DSAerr(DSA_F_DSA_BUILTIN_KEYGEN, DSA_R_KEY_SIZE_TOO_SMALL);
-               goto err;
-               }
-
-       if ((ctx=BN_CTX_new()) == NULL) goto err;
-
-       if (dsa->priv_key == NULL)
-               {
-               if ((priv_key=BN_new()) == NULL) goto err;
-               }
-       else
-               priv_key=dsa->priv_key;
-
-       do
-               if (!BN_rand_range(priv_key,dsa->q)) goto err;
-       while (BN_is_zero(priv_key));
-
-       if (dsa->pub_key == NULL)
-               {
-               if ((pub_key=BN_new()) == NULL) goto err;
-               }
-       else
-               pub_key=dsa->pub_key;
-       
-       {
-               BIGNUM local_prk;
-               BIGNUM *prk;
-
-               if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0)
-                       {
-                       BN_init(&local_prk);
-                       prk = &local_prk;
-                       BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME);
-                       }
-               else
-                       prk = priv_key;
-
-               if (!BN_mod_exp(pub_key,dsa->g,prk,dsa->p,ctx)) goto err;
-       }
-
-       dsa->priv_key=priv_key;
-       dsa->pub_key=pub_key;
-       if (fips_dsa_pairwise_fail)
-               BN_add_word(dsa->pub_key, 1);
-       if(!fips_check_dsa(dsa))
-           goto err;
-       ok=1;
-
-err:
-       if ((pub_key != NULL) && (dsa->pub_key == NULL)) BN_free(pub_key);
-       if ((priv_key != NULL) && (dsa->priv_key == NULL)) BN_free(priv_key);
-       if (ctx != NULL) BN_CTX_free(ctx);
-       return(ok);
-       }
-#endif
-
-#endif
diff --git a/deps/openssl/openssl/fips/dsa/fips_dsa_ossl.c b/deps/openssl/openssl/fips/dsa/fips_dsa_ossl.c
deleted file mode 100644 (file)
index 50a6c13..0000000
+++ /dev/null
@@ -1,435 +0,0 @@
-/* crypto/dsa/dsa_ossl.c */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-/* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
-
-#include <stdio.h>
-#include <openssl/bn.h>
-#include <openssl/dsa.h>
-#include <openssl/rand.h>
-#include <openssl/asn1.h>
-#include <openssl/err.h>
-#ifndef OPENSSL_NO_ENGINE
-#include <openssl/engine.h>
-#endif
-#include <openssl/fips.h>
-
-#ifdef OPENSSL_FIPS
-
-static DSA_SIG *dsa_do_sign(const unsigned char *dgst, FIPS_DSA_SIZE_T dlen, DSA *dsa);
-static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp);
-static int dsa_do_verify(const unsigned char *dgst, FIPS_DSA_SIZE_T dgst_len, DSA_SIG *sig,
-                 DSA *dsa);
-static int dsa_init(DSA *dsa);
-static int dsa_finish(DSA *dsa);
-static int dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
-               BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
-               BN_MONT_CTX *in_mont);
-static int dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
-                               const BIGNUM *m, BN_CTX *ctx,
-                               BN_MONT_CTX *m_ctx);
-
-static const DSA_METHOD openssl_dsa_meth = {
-"OpenSSL FIPS DSA method",
-dsa_do_sign,
-dsa_sign_setup,
-dsa_do_verify,
-dsa_mod_exp,
-dsa_bn_mod_exp,
-dsa_init,
-dsa_finish,
-DSA_FLAG_FIPS_METHOD,
-NULL
-};
-#if 0
-int FIPS_dsa_check(struct dsa_st *dsa)
-    {
-    if(dsa->meth != &openssl_dsa_meth || dsa->meth->dsa_do_sign != dsa_do_sign
-       || dsa->meth->dsa_sign_setup != dsa_sign_setup
-       || dsa->meth->dsa_mod_exp != dsa_mod_exp
-       || dsa->meth->bn_mod_exp != dsa_bn_mod_exp
-       || dsa->meth->init != dsa_init
-       || dsa->meth->finish != dsa_finish)
-       {
-       FIPSerr(FIPS_F_FIPS_DSA_CHECK,FIPS_R_NON_FIPS_METHOD);
-       return 0;
-       }
-    return 1;
-    }
-#endif
-
-const DSA_METHOD *DSA_OpenSSL(void)
-{
-       return &openssl_dsa_meth;
-}
-
-static DSA_SIG *dsa_do_sign(const unsigned char *dgst, FIPS_DSA_SIZE_T dlen, DSA *dsa)
-       {
-       BIGNUM *kinv=NULL,*r=NULL,*s=NULL;
-       BIGNUM m;
-       BIGNUM xr;
-       BN_CTX *ctx=NULL;
-       int i,reason=ERR_R_BN_LIB;
-       DSA_SIG *ret=NULL;
-
-       if(FIPS_selftest_failed())
-           {
-           FIPSerr(FIPS_F_DSA_DO_SIGN,FIPS_R_FIPS_SELFTEST_FAILED);
-           return NULL;
-           }
-
-       if (FIPS_mode() && (BN_num_bits(dsa->p) < OPENSSL_DSA_FIPS_MIN_MODULUS_BITS))
-               {
-               DSAerr(DSA_F_DSA_DO_SIGN, DSA_R_KEY_SIZE_TOO_SMALL);
-               return NULL;
-               }
-
-       BN_init(&m);
-       BN_init(&xr);
-
-       if (!dsa->p || !dsa->q || !dsa->g)
-               {
-               reason=DSA_R_MISSING_PARAMETERS;
-               goto err;
-               }
-
-       s=BN_new();
-       if (s == NULL) goto err;
-
-       i=BN_num_bytes(dsa->q); /* should be 20 */
-       if ((dlen > i) || (dlen > 50))
-               {
-               reason=DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE;
-               goto err;
-               }
-
-       ctx=BN_CTX_new();
-       if (ctx == NULL) goto err;
-
-       if (!dsa->meth->dsa_sign_setup(dsa,ctx,&kinv,&r)) goto err;
-
-       if (BN_bin2bn(dgst,dlen,&m) == NULL) goto err;
-
-       /* Compute  s = inv(k) (m + xr) mod q */
-       if (!BN_mod_mul(&xr,dsa->priv_key,r,dsa->q,ctx)) goto err;/* s = xr */
-       if (!BN_add(s, &xr, &m)) goto err;              /* s = m + xr */
-       if (BN_cmp(s,dsa->q) > 0)
-               BN_sub(s,s,dsa->q);
-       if (!BN_mod_mul(s,s,kinv,dsa->q,ctx)) goto err;
-
-       ret= DSA_SIG_new();
-       if (ret == NULL) goto err;
-       ret->r = r;
-       ret->s = s;
-       
-err:
-       if (!ret)
-               {
-               DSAerr(DSA_F_DSA_DO_SIGN,reason);
-               BN_free(r);
-               BN_free(s);
-               }
-       if (ctx != NULL) BN_CTX_free(ctx);
-       BN_clear_free(&m);
-       BN_clear_free(&xr);
-       if (kinv != NULL) /* dsa->kinv is NULL now if we used it */
-           BN_clear_free(kinv);
-       return(ret);
-       }
-
-static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
-       {
-       BN_CTX *ctx;
-       BIGNUM k,kq,*K,*kinv=NULL,*r=NULL;
-       int ret=0;
-
-       if (!dsa->p || !dsa->q || !dsa->g)
-               {
-               DSAerr(DSA_F_DSA_SIGN_SETUP,DSA_R_MISSING_PARAMETERS);
-               return 0;
-               }
-
-       BN_init(&k);
-       BN_init(&kq);
-
-       if (ctx_in == NULL)
-               {
-               if ((ctx=BN_CTX_new()) == NULL) goto err;
-               }
-       else
-               ctx=ctx_in;
-
-       if ((r=BN_new()) == NULL) goto err;
-
-       /* Get random k */
-       do
-               if (!BN_rand_range(&k, dsa->q)) goto err;
-       while (BN_is_zero(&k));
-       if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0)
-               {
-               BN_set_flags(&k, BN_FLG_CONSTTIME);
-               }
-
-       if (dsa->flags & DSA_FLAG_CACHE_MONT_P)
-               {
-               if (!BN_MONT_CTX_set_locked((BN_MONT_CTX **)&dsa->method_mont_p,
-                                               CRYPTO_LOCK_DSA,
-                                               dsa->p, ctx))
-                       goto err;
-               }
-
-       /* Compute r = (g^k mod p) mod q */
-
-       if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0)
-               {
-               if (!BN_copy(&kq, &k)) goto err;
-
-               /* We do not want timing information to leak the length of k,
-                * so we compute g^k using an equivalent exponent of fixed length.
-                *
-                * (This is a kludge that we need because the BN_mod_exp_mont()
-                * does not let us specify the desired timing behaviour.) */
-
-               if (!BN_add(&kq, &kq, dsa->q)) goto err;
-               if (BN_num_bits(&kq) <= BN_num_bits(dsa->q))
-                       {
-                       if (!BN_add(&kq, &kq, dsa->q)) goto err;
-                       }
-
-               K = &kq;
-               }
-       else
-               {
-               K = &k;
-               }
-       if (!dsa->meth->bn_mod_exp(dsa, r,dsa->g,K,dsa->p,ctx,
-               (BN_MONT_CTX *)dsa->method_mont_p)) goto err;
-       if (!BN_mod(r,r,dsa->q,ctx)) goto err;
-
-       /* Compute  part of 's = inv(k) (m + xr) mod q' */
-       if ((kinv=BN_mod_inverse(NULL,&k,dsa->q,ctx)) == NULL) goto err;
-
-       if (*kinvp != NULL) BN_clear_free(*kinvp);
-       *kinvp=kinv;
-       kinv=NULL;
-       if (*rp != NULL) BN_clear_free(*rp);
-       *rp=r;
-       ret=1;
-err:
-       if (!ret)
-               {
-               DSAerr(DSA_F_DSA_SIGN_SETUP,ERR_R_BN_LIB);
-               if (kinv != NULL) BN_clear_free(kinv);
-               if (r != NULL) BN_clear_free(r);
-               }
-       if (ctx_in == NULL) BN_CTX_free(ctx);
-       if (kinv != NULL) BN_clear_free(kinv);
-       BN_clear_free(&k);
-       BN_clear_free(&kq);
-       return(ret);
-       }
-
-static int dsa_do_verify(const unsigned char *dgst, FIPS_DSA_SIZE_T dgst_len, DSA_SIG *sig,
-                 DSA *dsa)
-       {
-       BN_CTX *ctx;
-       BIGNUM u1,u2,t1;
-       BN_MONT_CTX *mont=NULL;
-       int ret = -1;
-
-       if (!dsa->p || !dsa->q || !dsa->g)
-               {
-               DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_MISSING_PARAMETERS);
-               return -1;
-               }
-
-       if(FIPS_selftest_failed())
-           {
-           FIPSerr(FIPS_F_DSA_DO_VERIFY,FIPS_R_FIPS_SELFTEST_FAILED);
-           return -1;
-           }
-
-       if (BN_num_bits(dsa->q) != 160)
-               {
-               DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_BAD_Q_VALUE);
-               return -1;
-               }
-
-       if (BN_num_bits(dsa->p) > OPENSSL_DSA_MAX_MODULUS_BITS)
-               {
-               DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_MODULUS_TOO_LARGE);
-               return -1;
-               }
-
-       if (FIPS_mode() && (BN_num_bits(dsa->p) < OPENSSL_DSA_FIPS_MIN_MODULUS_BITS))
-               {
-               DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_KEY_SIZE_TOO_SMALL);
-               return -1;
-               }
-
-       BN_init(&u1);
-       BN_init(&u2);
-       BN_init(&t1);
-
-       if ((ctx=BN_CTX_new()) == NULL) goto err;
-
-       if (BN_is_zero(sig->r) || sig->r->neg || BN_ucmp(sig->r, dsa->q) >= 0)
-               {
-               ret = 0;
-               goto err;
-               }
-       if (BN_is_zero(sig->s) || sig->s->neg || BN_ucmp(sig->s, dsa->q) >= 0)
-               {
-               ret = 0;
-               goto err;
-               }
-
-       /* Calculate W = inv(S) mod Q
-        * save W in u2 */
-       if ((BN_mod_inverse(&u2,sig->s,dsa->q,ctx)) == NULL) goto err;
-
-       /* save M in u1 */
-       if (BN_bin2bn(dgst,dgst_len,&u1) == NULL) goto err;
-
-       /* u1 = M * w mod q */
-       if (!BN_mod_mul(&u1,&u1,&u2,dsa->q,ctx)) goto err;
-
-       /* u2 = r * w mod q */
-       if (!BN_mod_mul(&u2,sig->r,&u2,dsa->q,ctx)) goto err;
-
-
-       if (dsa->flags & DSA_FLAG_CACHE_MONT_P)
-               {
-               mont = BN_MONT_CTX_set_locked(
-                                       (BN_MONT_CTX **)&dsa->method_mont_p,
-                                       CRYPTO_LOCK_DSA, dsa->p, ctx);
-               if (!mont)
-                       goto err;
-               }
-
-#if 0
-       {
-       BIGNUM t2;
-
-       BN_init(&t2);
-       /* v = ( g^u1 * y^u2 mod p ) mod q */
-       /* let t1 = g ^ u1 mod p */
-       if (!BN_mod_exp_mont(&t1,dsa->g,&u1,dsa->p,ctx,mont)) goto err;
-       /* let t2 = y ^ u2 mod p */
-       if (!BN_mod_exp_mont(&t2,dsa->pub_key,&u2,dsa->p,ctx,mont)) goto err;
-       /* let u1 = t1 * t2 mod p */
-       if (!BN_mod_mul(&u1,&t1,&t2,dsa->p,ctx)) goto err_bn;
-       BN_free(&t2);
-       }
-       /* let u1 = u1 mod q */
-       if (!BN_mod(&u1,&u1,dsa->q,ctx)) goto err;
-#else
-       {
-       if (!dsa->meth->dsa_mod_exp(dsa, &t1,dsa->g,&u1,dsa->pub_key,&u2,
-                                               dsa->p,ctx,mont)) goto err;
-       /* BN_copy(&u1,&t1); */
-       /* let u1 = u1 mod q */
-       if (!BN_mod(&u1,&t1,dsa->q,ctx)) goto err;
-       }
-#endif
-       /* V is now in u1.  If the signature is correct, it will be
-        * equal to R. */
-       ret=(BN_ucmp(&u1, sig->r) == 0);
-
-       err:
-       if (ret != 1) DSAerr(DSA_F_DSA_DO_VERIFY,ERR_R_BN_LIB);
-       if (ctx != NULL) BN_CTX_free(ctx);
-       BN_free(&u1);
-       BN_free(&u2);
-       BN_free(&t1);
-       return(ret);
-       }
-
-static int dsa_init(DSA *dsa)
-{
-       FIPS_selftest_check();
-       dsa->flags|=DSA_FLAG_CACHE_MONT_P;
-       return(1);
-}
-
-static int dsa_finish(DSA *dsa)
-{
-       if(dsa->method_mont_p)
-               BN_MONT_CTX_free((BN_MONT_CTX *)dsa->method_mont_p);
-       return(1);
-}
-
-static int dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
-               BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
-               BN_MONT_CTX *in_mont)
-{
-       return BN_mod_exp2_mont(rr, a1, p1, a2, p2, m, ctx, in_mont);
-}
-       
-static int dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
-                               const BIGNUM *m, BN_CTX *ctx,
-                               BN_MONT_CTX *m_ctx)
-{
-       return BN_mod_exp_mont(r, a, p, m, ctx, m_ctx);
-}
-
-#else /* ndef OPENSSL_FIPS */
-
-static void *dummy=&dummy;
-
-#endif /* ndef OPENSSL_FIPS */
diff --git a/deps/openssl/openssl/fips/dsa/fips_dsa_selftest.c b/deps/openssl/openssl/fips/dsa/fips_dsa_selftest.c
deleted file mode 100644 (file)
index 6880760..0000000
+++ /dev/null
@@ -1,180 +0,0 @@
-/* crypto/dsa/dsatest.c */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-#include <string.h>
-#include <openssl/crypto.h>
-#include <openssl/dsa.h>
-#include <openssl/fips.h>
-#include <openssl/err.h>
-#include <openssl/evp.h>
-#include <openssl/bn.h>
-
-#ifdef OPENSSL_FIPS
-
-/* seed, out_p, out_q, out_g are taken the NIST test vectors */
-
-static unsigned char seed[20] = {
-       0x77, 0x8f, 0x40, 0x74, 0x6f, 0x66, 0xbe, 0x33, 0xce, 0xbe, 0x99, 0x34,
-       0x4c, 0xfc, 0xf3, 0x28, 0xaa, 0x70, 0x2d, 0x3a
-       };
-
-static unsigned char out_p[] = {
-       0xf7, 0x7c, 0x1b, 0x83, 0xd8, 0xe8, 0x5c, 0x7f, 0x85, 0x30, 0x17, 0x57,
-       0x21, 0x95, 0xfe, 0x26, 0x04, 0xeb, 0x47, 0x4c, 0x3a, 0x4a, 0x81, 0x4b,
-       0x71, 0x2e, 0xed, 0x6e, 0x4f, 0x3d, 0x11, 0x0f, 0x7c, 0xfe, 0x36, 0x43,
-       0x51, 0xd9, 0x81, 0x39, 0x17, 0xdf, 0x62, 0xf6, 0x9c, 0x01, 0xa8, 0x69,
-       0x71, 0xdd, 0x29, 0x7f, 0x47, 0xe6, 0x65, 0xa6, 0x22, 0xe8, 0x6a, 0x12,
-       0x2b, 0xc2, 0x81, 0xff, 0x32, 0x70, 0x2f, 0x9e, 0xca, 0x53, 0x26, 0x47,
-       0x0f, 0x59, 0xd7, 0x9e, 0x2c, 0xa5, 0x07, 0xc4, 0x49, 0x52, 0xa3, 0xe4,
-       0x6b, 0x04, 0x00, 0x25, 0x49, 0xe2, 0xe6, 0x7f, 0x28, 0x78, 0x97, 0xb8,
-       0x3a, 0x32, 0x14, 0x38, 0xa2, 0x51, 0x33, 0x22, 0x44, 0x7e, 0xd7, 0xef,
-       0x45, 0xdb, 0x06, 0x4a, 0xd2, 0x82, 0x4a, 0x82, 0x2c, 0xb1, 0xd7, 0xd8,
-       0xb6, 0x73, 0x00, 0x4d, 0x94, 0x77, 0x94, 0xef
-       };
-
-static unsigned char out_q[] = {
-       0xd4, 0x0a, 0xac, 0x9f, 0xbd, 0x8c, 0x80, 0xc2, 0x38, 0x7e, 0x2e, 0x0c,
-       0x52, 0x5c, 0xea, 0x34, 0xa1, 0x83, 0x32, 0xf3
-       };
-
-static unsigned char out_g[] = {
-       0x34, 0x73, 0x8b, 0x57, 0x84, 0x8e, 0x55, 0xbf, 0x57, 0xcc, 0x41, 0xbb,
-       0x5e, 0x2b, 0xd5, 0x42, 0xdd, 0x24, 0x22, 0x2a, 0x09, 0xea, 0x26, 0x1e,
-       0x17, 0x65, 0xcb, 0x1a, 0xb3, 0x12, 0x44, 0xa3, 0x9e, 0x99, 0xe9, 0x63,
-       0xeb, 0x30, 0xb1, 0x78, 0x7b, 0x09, 0x40, 0x30, 0xfa, 0x83, 0xc2, 0x35,
-       0xe1, 0xc4, 0x2d, 0x74, 0x1a, 0xb1, 0x83, 0x54, 0xd8, 0x29, 0xf4, 0xcf,
-       0x7f, 0x6f, 0x67, 0x1c, 0x36, 0x49, 0xee, 0x6c, 0xa2, 0x3c, 0x2d, 0x6a,
-       0xe9, 0xd3, 0x9a, 0xf6, 0x57, 0x78, 0x6f, 0xfd, 0x33, 0xcd, 0x3c, 0xed,
-       0xfd, 0xd4, 0x41, 0xe6, 0x5c, 0x8b, 0xe0, 0x68, 0x31, 0x47, 0x47, 0xaf,
-       0x12, 0xa7, 0xf9, 0x32, 0x0d, 0x94, 0x15, 0x48, 0xd0, 0x54, 0x85, 0xb2,
-       0x04, 0xb5, 0x4d, 0xd4, 0x9d, 0x05, 0x22, 0x25, 0xd9, 0xfd, 0x6c, 0x36,
-       0xef, 0xbe, 0x69, 0x6c, 0x55, 0xf4, 0xee, 0xec
-       };
-
-static const unsigned char str1[]="12345678901234567890";
-
-void FIPS_corrupt_dsa()
-    {
-    ++seed[0];
-    }
-
-int FIPS_selftest_dsa()
-    {
-    DSA *dsa=NULL;
-    int counter,i,j, ret = 0;
-    unsigned int slen;
-    unsigned char buf[256];
-    unsigned long h;
-    EVP_MD_CTX mctx;
-    EVP_PKEY pk;
-
-    EVP_MD_CTX_init(&mctx);
-
-    dsa = FIPS_dsa_new();
-
-    if(dsa == NULL)
-       goto err;
-    if(!DSA_generate_parameters_ex(dsa, 1024,seed,20,&counter,&h,NULL))
-       goto err;
-    if (counter != 378) 
-       goto err;
-    if (h != 2)
-       goto err;
-    i=BN_bn2bin(dsa->q,buf);
-    j=sizeof(out_q);
-    if (i != j || memcmp(buf,out_q,i) != 0)
-       goto err;
-
-    i=BN_bn2bin(dsa->p,buf);
-    j=sizeof(out_p);
-    if (i != j || memcmp(buf,out_p,i) != 0)
-       goto err;
-
-    i=BN_bn2bin(dsa->g,buf);
-    j=sizeof(out_g);
-    if (i != j || memcmp(buf,out_g,i) != 0)
-       goto err;
-    DSA_generate_key(dsa);
-    pk.type = EVP_PKEY_DSA;
-    pk.pkey.dsa = dsa;
-
-    if (!EVP_SignInit_ex(&mctx, EVP_dss1(), NULL))
-       goto err;
-    if (!EVP_SignUpdate(&mctx, str1, 20))
-       goto err;
-    if (!EVP_SignFinal(&mctx, buf, &slen, &pk))
-       goto err;
-
-    if (!EVP_VerifyInit_ex(&mctx, EVP_dss1(), NULL))
-       goto err;
-    if (!EVP_VerifyUpdate(&mctx, str1, 20))
-       goto err;
-    if (EVP_VerifyFinal(&mctx, buf, slen, &pk) != 1)
-       goto err;
-
-    ret = 1;
-
-    err:
-    EVP_MD_CTX_cleanup(&mctx);
-    if (dsa)
-       FIPS_dsa_free(dsa);
-    if (ret == 0)
-           FIPSerr(FIPS_F_FIPS_SELFTEST_DSA,FIPS_R_SELFTEST_FAILED);
-    return ret;
-    }
-#endif
diff --git a/deps/openssl/openssl/fips/dsa/fips_dsa_sign.c b/deps/openssl/openssl/fips/dsa/fips_dsa_sign.c
deleted file mode 100644 (file)
index 7a4d51d..0000000
+++ /dev/null
@@ -1,258 +0,0 @@
-/* fips_dsa_sign.c */
-/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
- * project 2007.
- */
-/* ====================================================================
- * Copyright (c) 2007 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    licensing@OpenSSL.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
- * ====================================================================
- *
- * This product includes cryptographic software written by Eric Young
- * (eay@cryptsoft.com).  This product includes software written by Tim
- * Hudson (tjh@cryptsoft.com).
- *
- */
-
-#include <string.h>
-#include <openssl/evp.h>
-#include <openssl/dsa.h>
-#include <openssl/err.h>
-#include <openssl/sha.h>
-#include <openssl/bn.h>
-
-#ifdef OPENSSL_FIPS
-
-/* FIPS versions of DSA_sign() and DSA_verify().
- * These include a tiny ASN1 encoder/decoder to handle the specific
- * case of a DSA signature.
- */
-
-#if 0
-int FIPS_dsa_size(DSA *r)
-       {
-       int ilen;
-       ilen = BN_num_bytes(r->q);
-       if (ilen > 20)
-               return -1;
-       /* If MSB set need padding byte */
-       ilen ++;
-       /* Also need 2 bytes INTEGER header for r and s plus
-        * 2 bytes SEQUENCE header making 6 in total.
-        */
-       return ilen * 2 + 6;
-       }
-#endif
-
-/* Tiny ASN1 encoder for DSA_SIG structure. We can assume r, s smaller than
- * 0x80 octets as by the DSA standards they will be less than 2^160
- */
-
-int FIPS_dsa_sig_encode(unsigned char *out, DSA_SIG *sig)
-       {
-       int rlen, slen, rpad, spad, seqlen;
-       rlen = BN_num_bytes(sig->r);
-       if (rlen > 20)
-               return -1;
-       if (BN_num_bits(sig->r) & 0x7)
-               rpad = 0;
-       else
-               rpad = 1;
-       slen = BN_num_bytes(sig->s);
-       if (slen > 20)
-               return -1;
-       if (BN_num_bits(sig->s) & 0x7)
-               spad = 0;
-       else
-               spad = 1;
-       /* Length of SEQUENCE, (1 tag + 1 len octet) * 2 + content octets */
-       seqlen = rlen + rpad + slen + spad + 4;
-       /* Actual encoded length: include SEQUENCE header */
-       if (!out)
-               return seqlen + 2;
-
-       /* Output SEQUENCE header */
-       *out++ = V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED;
-       *out++ = (unsigned char)seqlen;
-
-       /* Output r */
-       *out++ = V_ASN1_INTEGER;
-       *out++ = (unsigned char)(rlen + rpad);
-       if (rpad)
-               *out++ = 0;
-       BN_bn2bin(sig->r, out);
-       out += rlen;
-
-       /* Output s */
-       *out++ = V_ASN1_INTEGER;
-       *out++ = (unsigned char)(slen + spad);
-       if (spad)
-               *out++ = 0;
-       BN_bn2bin(sig->s, out);
-       return seqlen + 2;
-       }
-
-/* Companion DSA_SIG decoder */
-
-int FIPS_dsa_sig_decode(DSA_SIG *sig, const unsigned char *in, int inlen)
-       {
-       int seqlen, rlen, slen;
-       const unsigned char *rbin;
-       /* Sanity check */
-
-       /* Need SEQUENCE tag */
-       if (*in++ != (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED))
-               return 0;
-       /* Get length octet */
-       seqlen = *in++;
-       /* Check sensible length value */
-       if (seqlen < 4 || seqlen > 0x7F)
-               return 0;
-       /* Check INTEGER tag */
-       if (*in++ != V_ASN1_INTEGER)
-               return 0;
-       rlen = *in++;
-       seqlen -= 2 + rlen;
-       /* Check sensible seqlen value */
-       if (seqlen < 2)
-               return 0;
-       rbin = in;
-       in += rlen;
-       /* Check INTEGER tag */
-       if (*in++ != V_ASN1_INTEGER)
-               return 0;
-       slen = *in++;
-       /* Remaining bytes of SEQUENCE should exactly match
-        * encoding of s
-        */
-       if (seqlen != (slen + 2))
-               return 0;
-       if (!sig->r && !(sig->r = BN_new()))
-               return 0;
-       if (!sig->s && !(sig->s = BN_new()))
-               return 0;
-       if (!BN_bin2bn(rbin, rlen, sig->r))
-               return 0;
-       if (!BN_bin2bn(in, slen, sig->s))
-               return 0;
-       return 1;
-       }
-
-static int fips_dsa_sign(int type, const unsigned char *x, int y,
-            unsigned char *sig, unsigned int *siglen, EVP_MD_SVCTX *sv)
-       {
-       DSA *dsa = sv->key;
-       unsigned char dig[EVP_MAX_MD_SIZE];
-       unsigned int dlen;
-       DSA_SIG *s;
-        EVP_DigestFinal_ex(sv->mctx, dig, &dlen);
-       s=dsa->meth->dsa_do_sign(dig,dlen,dsa);
-       OPENSSL_cleanse(dig, dlen);
-       if (s == NULL)
-               {
-               *siglen=0;
-               return 0;
-               }
-       *siglen= FIPS_dsa_sig_encode(sig, s);
-       DSA_SIG_free(s);
-       if (*siglen < 0)
-               return 0;
-       return 1;
-       }
-
-static int fips_dsa_verify(int type, const unsigned char *x, int y,
-            const unsigned char *sigbuf, unsigned int siglen, EVP_MD_SVCTX *sv)
-       {
-       DSA *dsa = sv->key;
-       DSA_SIG *s;
-       int ret=-1;
-       unsigned char dig[EVP_MAX_MD_SIZE];
-       unsigned int dlen;
-
-       s = DSA_SIG_new();
-       if (s == NULL)
-               return ret;
-       if (!FIPS_dsa_sig_decode(s,sigbuf,siglen))
-               goto err;
-        EVP_DigestFinal_ex(sv->mctx, dig, &dlen);
-       ret=dsa->meth->dsa_do_verify(dig,dlen,s,dsa);
-       OPENSSL_cleanse(dig, dlen);
-err:
-       DSA_SIG_free(s);
-       return ret;
-       }
-
-static int init(EVP_MD_CTX *ctx)
-       { return SHA1_Init(ctx->md_data); }
-
-static int update(EVP_MD_CTX *ctx,const void *data,size_t count)
-       { return SHA1_Update(ctx->md_data,data,count); }
-
-static int final(EVP_MD_CTX *ctx,unsigned char *md)
-       { return SHA1_Final(md,ctx->md_data); }
-
-static const EVP_MD dss1_md=
-       {
-       NID_dsa,
-       NID_dsaWithSHA1,
-       SHA_DIGEST_LENGTH,
-       EVP_MD_FLAG_FIPS|EVP_MD_FLAG_SVCTX,
-       init,
-       update,
-       final,
-       NULL,
-       NULL,
-       (evp_sign_method *)fips_dsa_sign,
-       (evp_verify_method *)fips_dsa_verify,
-       {EVP_PKEY_DSA,EVP_PKEY_DSA2,EVP_PKEY_DSA3, EVP_PKEY_DSA4,0},
-       SHA_CBLOCK,
-       sizeof(EVP_MD *)+sizeof(SHA_CTX),
-       };
-
-const EVP_MD *EVP_dss1(void)
-       {
-       return(&dss1_md);
-       }
-#endif
diff --git a/deps/openssl/openssl/fips/dsa/fips_dsatest.c b/deps/openssl/openssl/fips/dsa/fips_dsatest.c
deleted file mode 100644 (file)
index 1aec089..0000000
+++ /dev/null
@@ -1,271 +0,0 @@
-/* crypto/dsa/dsatest.c */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include "e_os.h"
-
-#include <openssl/crypto.h>
-#include <openssl/rand.h>
-#include <openssl/bio.h>
-#include <openssl/err.h>
-#include <openssl/bn.h>
-#ifndef OPENSSL_NO_ENGINE
-#include <openssl/engine.h>
-#endif
-
-
-#if defined(OPENSSL_NO_DSA) || !defined(OPENSSL_FIPS)
-int main(int argc, char *argv[])
-{
-    printf("No FIPS DSA support\n");
-    return(0);
-}
-#else
-#include <openssl/dsa.h>
-#include <openssl/fips.h>
-#include <openssl/fips_rand.h>
-#include <openssl/dsa.h>
-
-#ifdef OPENSSL_SYS_WIN16
-#define MS_CALLBACK     _far _loadds
-#else
-#define MS_CALLBACK
-#endif
-
-#include "fips_utl.h"
-
-static int MS_CALLBACK dsa_cb(int p, int n, BN_GENCB *cb);
-
-/* seed, out_p, out_q, out_g are taken from the earlier validation test
- * vectors.
- */
-
-static unsigned char seed[20] = {
-       0x1c, 0xfb, 0xa9, 0x6c, 0xf7, 0x95, 0xb3, 0x2e, 0x01, 0x01, 0x3c, 0x8d,
-       0x7f, 0x6e, 0xf4, 0x59, 0xcc, 0x2f, 0x19, 0x59
-       };
-
-static unsigned char out_p[] = {
-       0xc2, 0x3c, 0x48, 0x31, 0x7e, 0x3b, 0x4e, 0x5d, 0x3c, 0x93, 0x78, 0x60,
-       0x5c, 0xf2, 0x60, 0xbb, 0x5a, 0xfa, 0x7f, 0x17, 0xf9, 0x26, 0x69, 0x46,
-       0xe7, 0x07, 0xbb, 0x3b, 0x2e, 0xc4, 0xb5, 0x66, 0xf7, 0x4d, 0xae, 0x9b,
-       0x8f, 0xf0, 0x42, 0xea, 0xb3, 0xa0, 0x7e, 0x81, 0x85, 0x89, 0xe6, 0xb0,
-       0x29, 0x03, 0x6b, 0xcc, 0xfb, 0x8e, 0x46, 0x15, 0x4d, 0xc1, 0x69, 0xd8,
-       0x2f, 0xef, 0x5c, 0x8b, 0x29, 0x32, 0x41, 0xbd, 0x13, 0x72, 0x3d, 0xac,
-       0x81, 0xcc, 0x86, 0x6c, 0x06, 0x5d, 0x51, 0xa1, 0xa5, 0x07, 0x0c, 0x3e,
-       0xbe, 0xdd, 0xf4, 0x6e, 0xa8, 0xed, 0xb4, 0x2f, 0xbd, 0x3e, 0x64, 0xea,
-       0xee, 0x92, 0xec, 0x51, 0xe1, 0x0d, 0xab, 0x25, 0x45, 0xae, 0x55, 0x21,
-       0x4d, 0xd6, 0x96, 0x6f, 0xe6, 0xaa, 0xd3, 0xca, 0x87, 0x92, 0xb1, 0x1c,
-       0x3c, 0xaf, 0x29, 0x09, 0x8b, 0xc6, 0xed, 0xe1
-       };
-
-static unsigned char out_q[] = {
-       0xae, 0x0a, 0x8c, 0xfb, 0x80, 0xe1, 0xc6, 0xd1, 0x09, 0x0f, 0x26, 0xde,
-       0x91, 0x53, 0xc2, 0x8b, 0x2b, 0x0f, 0xde, 0x7f
-       };
-
-static unsigned char out_g[] = {
-       0x0d, 0x7d, 0x92, 0x74, 0x10, 0xf6, 0xa4, 0x43, 0x86, 0x9a, 0xd1, 0xd9,
-       0x56, 0x00, 0xbc, 0x18, 0x97, 0x99, 0x4e, 0x9a, 0x93, 0xfb, 0x00, 0x3d,
-       0x6c, 0xa0, 0x1b, 0x95, 0x6b, 0xbd, 0xf7, 0x7a, 0xbc, 0x36, 0x3f, 0x3d,
-       0xb9, 0xbf, 0xf9, 0x91, 0x37, 0x68, 0xd1, 0xb9, 0x1e, 0xfe, 0x7f, 0x10,
-       0xc0, 0x6a, 0xcd, 0x5f, 0xc1, 0x65, 0x1a, 0xb8, 0xe7, 0xab, 0xb5, 0xc6,
-       0x8d, 0xb7, 0x86, 0xad, 0x3a, 0xbf, 0x6b, 0x7b, 0x0a, 0x66, 0xbe, 0xd5,
-       0x58, 0x23, 0x16, 0x48, 0x83, 0x29, 0xb6, 0xa7, 0x64, 0xc7, 0x08, 0xbe,
-       0x55, 0x4c, 0x6f, 0xcb, 0x34, 0xc1, 0x73, 0xb0, 0x39, 0x68, 0x52, 0xdf,
-       0x27, 0x7f, 0x32, 0xbc, 0x2b, 0x0d, 0x63, 0xed, 0x75, 0x3e, 0xb5, 0x54,
-       0xac, 0xc8, 0x20, 0x2a, 0x73, 0xe8, 0x29, 0x51, 0x03, 0x77, 0xe8, 0xc9,
-       0x61, 0x32, 0x25, 0xaf, 0x21, 0x5b, 0x6e, 0xda
-       };
-
-
-static const unsigned char str1[]="12345678901234567890";
-
-static const char rnd_seed[] = "string to make the random number generator think it has entropy";
-
-int main(int argc, char **argv)
-       {
-       DSA *dsa=NULL;
-       EVP_PKEY pk;
-       int counter,ret=0,i,j;
-       unsigned int slen;
-       unsigned char buf[256];
-       unsigned long h;
-       BN_GENCB cb;
-       EVP_MD_CTX mctx;
-       BN_GENCB_set(&cb, dsa_cb, stderr);
-       EVP_MD_CTX_init(&mctx);
-
-       if(!FIPS_mode_set(1))
-           {
-           do_print_errors();
-           EXIT(1);
-           }
-
-       fprintf(stderr,"test generation of DSA parameters\n");
-
-       dsa = FIPS_dsa_new();
-       DSA_generate_parameters_ex(dsa, 1024,seed,20,&counter,&h,&cb);
-
-       fprintf(stderr,"seed\n");
-       for (i=0; i<20; i+=4)
-               {
-               fprintf(stderr,"%02X%02X%02X%02X ",
-                       seed[i],seed[i+1],seed[i+2],seed[i+3]);
-               }
-       fprintf(stderr,"\ncounter=%d h=%ld\n",counter,h);
-
-       if (dsa == NULL) goto end;
-       if (counter != 16) 
-               {
-               fprintf(stderr,"counter should be 105\n");
-               goto end;
-               }
-       if (h != 2)
-               {
-               fprintf(stderr,"h should be 2\n");
-               goto end;
-               }
-
-       i=BN_bn2bin(dsa->q,buf);
-       j=sizeof(out_q);
-       if ((i != j) || (memcmp(buf,out_q,i) != 0))
-               {
-               fprintf(stderr,"q value is wrong\n");
-               goto end;
-               }
-
-       i=BN_bn2bin(dsa->p,buf);
-       j=sizeof(out_p);
-       if ((i != j) || (memcmp(buf,out_p,i) != 0))
-               {
-               fprintf(stderr,"p value is wrong\n");
-               goto end;
-               }
-
-       i=BN_bn2bin(dsa->g,buf);
-       j=sizeof(out_g);
-       if ((i != j) || (memcmp(buf,out_g,i) != 0))
-               {
-               fprintf(stderr,"g value is wrong\n");
-               goto end;
-               }
-       DSA_generate_key(dsa);
-       pk.type = EVP_PKEY_DSA;
-       pk.pkey.dsa = dsa;
-
-       if (!EVP_SignInit_ex(&mctx, EVP_dss1(), NULL))
-               goto end;
-       if (!EVP_SignUpdate(&mctx, str1, 20))
-               goto end;
-       if (!EVP_SignFinal(&mctx, buf, &slen, &pk))
-               goto end;
-
-       if (!EVP_VerifyInit_ex(&mctx, EVP_dss1(), NULL))
-               goto end;
-       if (!EVP_VerifyUpdate(&mctx, str1, 20))
-               goto end;
-       if (EVP_VerifyFinal(&mctx, buf, slen, &pk) != 1)
-               goto end;
-
-       ret = 1;
-
-end:
-       if (!ret)
-               do_print_errors();
-       if (dsa != NULL) FIPS_dsa_free(dsa);
-       EVP_MD_CTX_cleanup(&mctx);
-#if 0
-       CRYPTO_mem_leaks(bio_err);
-#endif
-       EXIT(!ret);
-       return(!ret);
-       }
-
-static int cb_exit(int ec)
-       {
-       EXIT(ec);
-       return(0);              /* To keep some compilers quiet */
-       }
-
-static int MS_CALLBACK dsa_cb(int p, int n, BN_GENCB *cb)
-       {
-       char c='*';
-       static int ok=0,num=0;
-
-       if (p == 0) { c='.'; num++; };
-       if (p == 1) c='+';
-       if (p == 2) { c='*'; ok++; }
-       if (p == 3) c='\n';
-       fwrite(&c,1, 1, cb->arg);
-       fflush(cb->arg);
-
-       if (!ok && (p == 0) && (num > 1))
-               {
-               fprintf(cb->arg,"error in dsatest\n");
-               cb_exit(1);
-               }
-       return 1;
-       }
-#endif
diff --git a/deps/openssl/openssl/fips/dsa/fips_dssvs.c b/deps/openssl/openssl/fips/dsa/fips_dssvs.c
deleted file mode 100644 (file)
index 45f4e1c..0000000
+++ /dev/null
@@ -1,537 +0,0 @@
-#include <openssl/opensslconf.h>
-
-#ifndef OPENSSL_FIPS
-#include <stdio.h>
-
-int main(int argc, char **argv)
-{
-    printf("No FIPS DSA support\n");
-    return(0);
-}
-#else
-
-#include <openssl/bn.h>
-#include <openssl/dsa.h>
-#include <openssl/fips.h>
-#include <openssl/err.h>
-#include <openssl/evp.h>
-#include <string.h>
-#include <ctype.h>
-
-#include "fips_utl.h"
-
-static void pbn(const char *name, BIGNUM *bn)
-       {
-       int len, i;
-       unsigned char *tmp;
-       len = BN_num_bytes(bn);
-       tmp = OPENSSL_malloc(len);
-       if (!tmp)
-               {
-               fprintf(stderr, "Memory allocation error\n");
-               return;
-               }
-       BN_bn2bin(bn, tmp);
-       printf("%s = ", name);
-       for (i = 0; i < len; i++)
-               printf("%02X", tmp[i]);
-       fputs("\n", stdout);
-       OPENSSL_free(tmp);
-       return;
-       }
-
-static void primes()
-    {
-    char buf[10240];
-    char lbuf[10240];
-    char *keyword, *value;
-
-    while(fgets(buf,sizeof buf,stdin) != NULL)
-       {
-       fputs(buf,stdout);
-       if (!parse_line(&keyword, &value, lbuf, buf))
-               continue;
-       if(!strcmp(keyword,"Prime"))
-           {
-           BIGNUM *pp;
-
-           pp=BN_new();
-           do_hex2bn(&pp,value);
-           printf("result= %c\n",
-                  BN_is_prime_ex(pp,20,NULL,NULL) ? 'P' : 'F');
-           }       
-       }
-    }
-
-static void pqg()
-    {
-    char buf[1024];
-    char lbuf[1024];
-    char *keyword, *value;
-    int nmod=0;
-
-    while(fgets(buf,sizeof buf,stdin) != NULL)
-       {
-       if (!parse_line(&keyword, &value, lbuf, buf))
-               {
-               fputs(buf,stdout);
-               continue;
-               }
-       if(!strcmp(keyword,"[mod"))
-           nmod=atoi(value);
-       else if(!strcmp(keyword,"N"))
-           {
-           int n=atoi(value);
-
-           printf("[mod = %d]\n\n",nmod);
-
-           while(n--)
-               {
-               unsigned char seed[20];
-               DSA *dsa;
-               int counter;
-               unsigned long h;
-               dsa = FIPS_dsa_new();
-
-               if (!DSA_generate_parameters_ex(dsa, nmod,seed,0,&counter,&h,NULL))
-                       {
-                       do_print_errors();
-                       exit(1);
-                       }
-               pbn("P",dsa->p);
-               pbn("Q",dsa->q);
-               pbn("G",dsa->g);
-               pv("Seed",seed,20);
-               printf("c = %d\n",counter);
-               printf("H = %lx\n",h);
-               putc('\n',stdout);
-               }
-           }
-       else
-           fputs(buf,stdout);
-       }
-    }
-
-static void pqgver()
-    {
-    char buf[1024];
-    char lbuf[1024];
-    char *keyword, *value;
-    BIGNUM *p = NULL, *q = NULL, *g = NULL;
-    int counter, counter2;
-    unsigned long h, h2;
-    DSA *dsa=NULL;
-    int nmod=0;
-    unsigned char seed[1024];
-
-    while(fgets(buf,sizeof buf,stdin) != NULL)
-       {
-       if (!parse_line(&keyword, &value, lbuf, buf))
-               {
-               fputs(buf,stdout);
-               continue;
-               }
-       fputs(buf, stdout);
-       if(!strcmp(keyword,"[mod"))
-           nmod=atoi(value);
-       else if(!strcmp(keyword,"P"))
-           p=hex2bn(value);
-       else if(!strcmp(keyword,"Q"))
-           q=hex2bn(value);
-       else if(!strcmp(keyword,"G"))
-           g=hex2bn(value);
-       else if(!strcmp(keyword,"Seed"))
-           {
-           int slen = hex2bin(value, seed);
-           if (slen != 20)
-               {
-               fprintf(stderr, "Seed parse length error\n");
-               exit (1);
-               }
-           }
-       else if(!strcmp(keyword,"c"))
-           counter =atoi(buf+4);
-       else if(!strcmp(keyword,"H"))
-           {
-           h = atoi(value);
-           if (!p || !q || !g)
-               {
-               fprintf(stderr, "Parse Error\n");
-               exit (1);
-               }
-           dsa = FIPS_dsa_new();
-           if (!DSA_generate_parameters_ex(dsa, nmod,seed,20 ,&counter2,&h2,NULL))
-                       {
-                       do_print_errors();
-                       exit(1);
-                       }
-            if (BN_cmp(dsa->p, p) || BN_cmp(dsa->q, q) || BN_cmp(dsa->g, g)
-               || (counter != counter2) || (h != h2))
-               printf("Result = F\n");
-           else
-               printf("Result = P\n");
-           BN_free(p);
-           BN_free(q);
-           BN_free(g);
-           p = NULL;
-           q = NULL;
-           g = NULL;
-           FIPS_dsa_free(dsa);
-           dsa = NULL;
-           }
-       }
-    }
-
-/* Keypair verification routine. NB: this isn't part of the standard FIPS140-2
- * algorithm tests. It is an additional test to perform sanity checks on the
- * output of the KeyPair test.
- */
-
-static int dss_paramcheck(int nmod, BIGNUM *p, BIGNUM *q, BIGNUM *g,
-                                                       BN_CTX *ctx)
-    {
-    BIGNUM *rem = NULL;
-    if (BN_num_bits(p) != nmod)
-       return 0;
-    if (BN_num_bits(q) != 160)
-       return 0;
-    if (BN_is_prime_ex(p, BN_prime_checks, ctx, NULL) != 1)
-       return 0;
-    if (BN_is_prime_ex(q, BN_prime_checks, ctx, NULL) != 1)
-       return 0;
-    rem = BN_new();
-    if (!BN_mod(rem, p, q, ctx) || !BN_is_one(rem)
-       || (BN_cmp(g, BN_value_one()) <= 0)
-       || !BN_mod_exp(rem, g, q, p, ctx) || !BN_is_one(rem))
-       {
-       BN_free(rem);
-       return 0;
-       }
-    /* Todo: check g */
-    BN_free(rem);
-    return 1;
-    }
-
-static void keyver()
-    {
-    char buf[1024];
-    char lbuf[1024];
-    char *keyword, *value;
-    BIGNUM *p = NULL, *q = NULL, *g = NULL, *X = NULL, *Y = NULL;
-    BIGNUM *Y2;
-    BN_CTX *ctx = NULL;
-    int nmod=0, paramcheck = 0;
-
-    ctx = BN_CTX_new();
-    Y2 = BN_new();
-
-    while(fgets(buf,sizeof buf,stdin) != NULL)
-       {
-       if (!parse_line(&keyword, &value, lbuf, buf))
-               {
-               fputs(buf,stdout);
-               continue;
-               }
-       if(!strcmp(keyword,"[mod"))
-           {
-           if (p)
-               BN_free(p);
-           p = NULL;
-           if (q)
-               BN_free(q);
-           q = NULL;
-           if (g)
-               BN_free(g);
-           g = NULL;
-           paramcheck = 0;
-           nmod=atoi(value);
-           }
-       else if(!strcmp(keyword,"P"))
-           p=hex2bn(value);
-       else if(!strcmp(keyword,"Q"))
-           q=hex2bn(value);
-       else if(!strcmp(keyword,"G"))
-           g=hex2bn(value);
-       else if(!strcmp(keyword,"X"))
-           X=hex2bn(value);
-       else if(!strcmp(keyword,"Y"))
-           {
-           Y=hex2bn(value);
-           if (!p || !q || !g || !X || !Y)
-               {
-               fprintf(stderr, "Parse Error\n");
-               exit (1);
-               }
-           pbn("P",p);
-           pbn("Q",q);
-           pbn("G",g);
-           pbn("X",X);
-           pbn("Y",Y);
-           if (!paramcheck)
-               {
-               if (dss_paramcheck(nmod, p, q, g, ctx))
-                       paramcheck = 1;
-               else
-                       paramcheck = -1;
-               }
-           if (paramcheck != 1)
-               printf("Result = F\n");
-           else
-               {
-               if (!BN_mod_exp(Y2, g, X, p, ctx) || BN_cmp(Y2, Y))
-                       printf("Result = F\n");
-               else
-                       printf("Result = P\n");
-               }
-           BN_free(X);
-           BN_free(Y);
-           X = NULL;
-           Y = NULL;
-           }
-       }
-       if (p)
-           BN_free(p);
-       if (q)
-           BN_free(q);
-       if (g)
-           BN_free(g);
-       if (Y2)
-           BN_free(Y2);
-    }
-
-static void keypair()
-    {
-    char buf[1024];
-    char lbuf[1024];
-    char *keyword, *value;
-    int nmod=0;
-
-    while(fgets(buf,sizeof buf,stdin) != NULL)
-       {
-       if (!parse_line(&keyword, &value, lbuf, buf))
-               {
-               fputs(buf,stdout);
-               continue;
-               }
-       if(!strcmp(keyword,"[mod"))
-           nmod=atoi(value);
-       else if(!strcmp(keyword,"N"))
-           {
-           DSA *dsa;
-           int n=atoi(value);
-
-           printf("[mod = %d]\n\n",nmod);
-           dsa = FIPS_dsa_new();
-           if (!DSA_generate_parameters_ex(dsa, nmod,NULL,0,NULL,NULL,NULL))
-               {
-               do_print_errors();
-               exit(1);
-               }
-           pbn("P",dsa->p);
-           pbn("Q",dsa->q);
-           pbn("G",dsa->g);
-           putc('\n',stdout);
-
-           while(n--)
-               {
-               if (!DSA_generate_key(dsa))
-                       {
-                       do_print_errors();
-                       exit(1);
-                       }
-
-               pbn("X",dsa->priv_key);
-               pbn("Y",dsa->pub_key);
-               putc('\n',stdout);
-               }
-           }
-       }
-    }
-
-static void siggen()
-    {
-    char buf[1024];
-    char lbuf[1024];
-    char *keyword, *value;
-    int nmod=0;
-    DSA *dsa=NULL;
-
-    while(fgets(buf,sizeof buf,stdin) != NULL)
-       {
-       if (!parse_line(&keyword, &value, lbuf, buf))
-               {
-               fputs(buf,stdout);
-               continue;
-               }
-       if(!strcmp(keyword,"[mod"))
-           {
-           nmod=atoi(value);
-           printf("[mod = %d]\n\n",nmod);
-           if (dsa)
-               FIPS_dsa_free(dsa);
-           dsa = FIPS_dsa_new();
-           if (!DSA_generate_parameters_ex(dsa, nmod,NULL,0,NULL,NULL,NULL))
-               {
-               do_print_errors();
-               exit(1);
-               }
-           pbn("P",dsa->p);
-           pbn("Q",dsa->q);
-           pbn("G",dsa->g);
-           putc('\n',stdout);
-           }
-       else if(!strcmp(keyword,"Msg"))
-           {
-           unsigned char msg[1024];
-           unsigned char sbuf[60];
-           unsigned int slen;
-           int n;
-           EVP_PKEY pk;
-           EVP_MD_CTX mctx;
-           DSA_SIG *sig;
-           EVP_MD_CTX_init(&mctx);
-
-           n=hex2bin(value,msg);
-           pv("Msg",msg,n);
-
-           if (!DSA_generate_key(dsa))
-               {
-               do_print_errors();
-               exit(1);
-               }
-           pk.type = EVP_PKEY_DSA;
-           pk.pkey.dsa = dsa;
-           pbn("Y",dsa->pub_key);
-
-           EVP_SignInit_ex(&mctx, EVP_dss1(), NULL);
-           EVP_SignUpdate(&mctx, msg, n);
-           EVP_SignFinal(&mctx, sbuf, &slen, &pk);
-
-           sig = DSA_SIG_new();
-           FIPS_dsa_sig_decode(sig, sbuf, slen);
-
-           pbn("R",sig->r);
-           pbn("S",sig->s);
-           putc('\n',stdout);
-           DSA_SIG_free(sig);
-           EVP_MD_CTX_cleanup(&mctx);
-           }
-       }
-       if (dsa)
-               FIPS_dsa_free(dsa);
-    }
-
-static void sigver()
-    {
-    DSA *dsa=NULL;
-    char buf[1024];
-    char lbuf[1024];
-    unsigned char msg[1024];
-    char *keyword, *value;
-    int nmod=0, n=0;
-    DSA_SIG sg, *sig = &sg;
-
-    sig->r = NULL;
-    sig->s = NULL;
-
-    while(fgets(buf,sizeof buf,stdin) != NULL)
-       {
-       if (!parse_line(&keyword, &value, lbuf, buf))
-               {
-               fputs(buf,stdout);
-               continue;
-               }
-       if(!strcmp(keyword,"[mod"))
-           {
-           nmod=atoi(value);
-           if(dsa)
-               FIPS_dsa_free(dsa);
-           dsa=FIPS_dsa_new();
-           }
-       else if(!strcmp(keyword,"P"))
-           dsa->p=hex2bn(value);
-       else if(!strcmp(keyword,"Q"))
-           dsa->q=hex2bn(value);
-       else if(!strcmp(keyword,"G"))
-           {
-           dsa->g=hex2bn(value);
-
-           printf("[mod = %d]\n\n",nmod);
-           pbn("P",dsa->p);
-           pbn("Q",dsa->q);
-           pbn("G",dsa->g);
-           putc('\n',stdout);
-           }
-       else if(!strcmp(keyword,"Msg"))
-           {
-           n=hex2bin(value,msg);
-           pv("Msg",msg,n);
-           }
-       else if(!strcmp(keyword,"Y"))
-           dsa->pub_key=hex2bn(value);
-       else if(!strcmp(keyword,"R"))
-           sig->r=hex2bn(value);
-       else if(!strcmp(keyword,"S"))
-           {
-           EVP_MD_CTX mctx;
-           EVP_PKEY pk;
-           unsigned char sigbuf[60];
-           unsigned int slen;
-           int r;
-           EVP_MD_CTX_init(&mctx);
-           pk.type = EVP_PKEY_DSA;
-           pk.pkey.dsa = dsa;
-           sig->s=hex2bn(value);
-       
-           pbn("Y",dsa->pub_key);
-           pbn("R",sig->r);
-           pbn("S",sig->s);
-
-           slen = FIPS_dsa_sig_encode(sigbuf, sig);
-           EVP_VerifyInit_ex(&mctx, EVP_dss1(), NULL);
-           EVP_VerifyUpdate(&mctx, msg, n);
-           r = EVP_VerifyFinal(&mctx, sigbuf, slen, &pk);
-           EVP_MD_CTX_cleanup(&mctx);
-       
-           printf("Result = %c\n", r == 1 ? 'P' : 'F');
-           putc('\n',stdout);
-           }
-       }
-    }
-
-int main(int argc,char **argv)
-    {
-    if(argc != 2)
-       {
-       fprintf(stderr,"%s [prime|pqg|pqgver|keypair|siggen|sigver]\n",argv[0]);
-       exit(1);
-       }
-    if(!FIPS_mode_set(1))
-       {
-       do_print_errors();
-       exit(1);
-       }
-    if(!strcmp(argv[1],"prime"))
-       primes();
-    else if(!strcmp(argv[1],"pqg"))
-       pqg();
-    else if(!strcmp(argv[1],"pqgver"))
-       pqgver();
-    else if(!strcmp(argv[1],"keypair"))
-       keypair();
-    else if(!strcmp(argv[1],"keyver"))
-       keyver();
-    else if(!strcmp(argv[1],"siggen"))
-       siggen();
-    else if(!strcmp(argv[1],"sigver"))
-       sigver();
-    else
-       {
-       fprintf(stderr,"Don't know how to %s.\n",argv[1]);
-       exit(1);
-       }
-
-    return 0;
-    }
-
-#endif
diff --git a/deps/openssl/openssl/fips/fips-lib.com b/deps/openssl/openssl/fips/fips-lib.com
deleted file mode 100644 (file)
index 7ef6da8..0000000
+++ /dev/null
@@ -1,1198 +0,0 @@
-$!
-$!  FIPS-LIB.COM
-$!  Written By:  Robert Byer
-$!               Vice-President
-$!               A-Com Computing, Inc.
-$!               byer@mail.all-net.net
-$!
-$!  Changes by Richard Levitte <richard@levitte.org>
-$!
-$!  This command files compiles and creates the FIPS parts of the
-$!  "[.xxx.EXE.CRYPTO]LIBCRYPTO.OLB" library for OpenSSL.  The "xxx"
-$!  denotes the machine architecture of ALPHA, IA64 or VAX.
-$!
-$!  It was re-written so it would try to determine what "C" compiler to use 
-$!  or you can specify which "C" compiler to use.
-$!
-$!  Specify the following as P1 to build just that part or ALL to just
-$!  build everything.
-$!
-$!             LIBRARY    To just compile the [.xxx.EXE.CRYPTO]LIBCRYPTO.OLB Library.
-$!             APPS       To just compile the [.xxx.EXE.CRYPTO]*.EXE
-$!             ALL        To do both LIBRARY and APPS
-$!
-$!  Specify DEBUG or NODEBUG as P2 to compile with or without debugger
-$!  information.
-$!
-$!  Specify which compiler at P3 to try to compile under.
-$!
-$!        VAXC  For VAX C.
-$!        DECC  For DEC C.
-$!        GNUC  For GNU C.
-$!
-$!  If you don't speficy a compiler, it will try to determine which
-$!  "C" compiler to use.
-$!
-$!  P4, if defined, sets a TCP/IP library to use, through one of the following
-$!  keywords:
-$!
-$!     UCX             for UCX
-$!     TCPIP           for TCPIP (post UCX)
-$!     SOCKETSHR       for SOCKETSHR+NETLIB
-$!
-$!  P5, if defined, sets a compiler thread NOT needed on OpenVMS 7.1 (and up)
-$!
-$!  P6, if defined, sets a choice of crypto methods to compile.
-$!  WARNING: this should only be done to recompile some part of an already
-$!  fully compiled library.
-$!
-$!
-$! Define A TCP/IP Library That We Will Need To Link To.
-$! (That Is, If We Need To Link To One.)
-$!
-$ TCPIP_LIB = ""
-$!
-$! Check What Architecture We Are Using.
-$!
-$ IF (F$GETSYI("CPU").LT.128)
-$ THEN
-$!
-$!  The Architecture Is VAX.
-$!
-$   ARCH := VAX
-$!
-$! Else...
-$!
-$ ELSE
-$!
-$!  The Architecture Is Alpha, IA64 or whatever comes in the future.
-$!
-$   ARCH = F$EDIT( F$GETSYI( "ARCH_NAME"), "UPCASE")
-$   IF (ARCH .EQS. "") THEN ARCH = "UNK"
-$!
-$! End The Architecture Check.
-$!
-$ ENDIF
-$!
-$! Define The Different Encryption Types.
-$!
-$ ENCRYPT_TYPES = "Basic,SHA,RAND,DES,AES,DSA,RSA,DH,HMAC"
-$!
-$! Define The OBJ Directory.
-$!
-$ OBJ_DIR := SYS$DISK:[-.'ARCH'.OBJ.CRYPTO]
-$!
-$! Define The EXE Directory.
-$!
-$ EXE_DIR := SYS$DISK:[-.'ARCH'.EXE.CRYPTO]
-$!
-$! Check To Make Sure We Have Valid Command Line Parameters.
-$!
-$ GOSUB CHECK_OPTIONS
-$!
-$! Initialise logical names and such
-$!
-$ GOSUB INITIALISE
-$!
-$! Tell The User What Kind of Machine We Run On.
-$!
-$ WRITE SYS$OUTPUT "Compiling On A ",ARCH," Machine."
-$!
-$! Check To See If The Architecture Specific OBJ Directory Exists.
-$!
-$ IF (F$PARSE(OBJ_DIR).EQS."")
-$ THEN
-$!
-$!  It Dosen't Exist, So Create It.
-$!
-$   CREATE/DIR 'OBJ_DIR'
-$!
-$! End The Architecture Specific OBJ Directory Check.
-$!
-$ ENDIF
-$!
-$! Check To See If The Architecture Specific Directory Exists.
-$!
-$ IF (F$PARSE(EXE_DIR).EQS."")
-$ THEN
-$!
-$!  It Dosen't Exist, So Create It.
-$!
-$   CREATE/DIRECTORY 'EXE_DIR'
-$!
-$! End The Architecture Specific Directory Check.
-$!
-$ ENDIF
-$!
-$! Define The Library Name.
-$!
-$ LIB_NAME := 'EXE_DIR'LIBCRYPTO.OLB
-$!
-$! Define The CRYPTO-LIB We Are To Use.
-$!
-$ CRYPTO_LIB := 'EXE_DIR'LIBCRYPTO.OLB
-$!
-$! Check To See If We Already Have A "[.xxx.EXE.CRYPTO]LIBCRYPTO.OLB" Library...
-$!
-$ IF (F$SEARCH(LIB_NAME).EQS."")
-$ THEN
-$!
-$! Guess Not, Create The Library.
-$!
-$   LIBRARY/CREATE/OBJECT 'LIB_NAME'
-$!
-$! End The Library Check.
-$!
-$ ENDIF
-$!
-$! Build our options file for the application
-$!
-$ GOSUB CHECK_OPT_FILE
-$!
-$! Define The Different Encryption "library" Strings.
-$!
-$ LIB_ = "fips,fips_err_wrapper"
-$ LIB_SHA = "fips_sha1dgst,fips_sha1_selftest,fips_sha256,fips_sha512"
-$ LIB_RAND = "fips_rand,fips_rand_selftest"
-$ LIB_DES = "fips_des_enc,fips_des_selftest,fips_set_key"
-$ LIB_AES = "fips_aes_core,fips_aes_selftest"
-$ LIB_DSA = "fips_dsa_ossl,fips_dsa_gen,fips_dsa_selftest"
-$ LIB_RSA = "fips_rsa_eay,fips_rsa_gen,fips_rsa_selftest,fips_rsa_x931g"
-$ LIB_DH = "fips_dh_check,fips_dh_gen,fips_dh_key"
-$ LIB_HMAC = "fips_hmac,fips_hmac_selftest"
-$!
-$! Setup exceptional compilations
-$!
-$ ! Add definitions for no threads on OpenVMS 7.1 and higher
-$ COMPILEWITH_CC3 = ",bss_rtcp,"
-$ ! Disable the DOLLARID warning
-$ COMPILEWITH_CC4 = ",a_utctm,bss_log,o_time,"
-$ ! Disable disjoint optimization
-$ COMPILEWITH_CC5 = ",md2_dgst,md4_dgst,md5_dgst,mdc2dgst," + -
-                    "sha_dgst,sha1dgst,rmd_dgst,bf_enc,"
-$ ! Disable the MIXLINKAGE warning
-$ COMPILEWITH_CC6 = ",fips_set_key,"
-$!
-$! Figure Out What Other Modules We Are To Build.
-$!
-$ BUILD_SET:
-$!
-$! Define A Module Counter.
-$!
-$ MODULE_COUNTER = 0
-$!
-$! Top Of The Loop.
-$!
-$ MODULE_NEXT:
-$!
-$! Extract The Module Name From The Encryption List.
-$!
-$ MODULE_NAME = F$ELEMENT(MODULE_COUNTER,",",ENCRYPT_TYPES)
-$ IF MODULE_NAME.EQS."Basic" THEN MODULE_NAME = ""
-$ MODULE_NAME1 = MODULE_NAME
-$!
-$! Check To See If We Are At The End Of The Module List.
-$!
-$ IF (MODULE_NAME.EQS.",") 
-$ THEN 
-$!
-$!  We Are At The End Of The Module List, Go To MODULE_DONE.
-$!
-$   GOTO MODULE_DONE
-$!
-$! End The Module List Check.
-$!
-$ ENDIF
-$!
-$! Increment The Moudle Counter.
-$!
-$ MODULE_COUNTER = MODULE_COUNTER + 1
-$!
-$! Create The Library and Apps Module Names.
-$!
-$ LIB_MODULE = "LIB_" + MODULE_NAME
-$ APPS_MODULE = "APPS_" + MODULE_NAME
-$ IF (MODULE_NAME.EQS."ASN1_2")
-$ THEN
-$   MODULE_NAME = "ASN1"
-$ ENDIF
-$ IF (MODULE_NAME.EQS."EVP_2")
-$ THEN
-$   MODULE_NAME = "EVP"
-$ ENDIF
-$!
-$! Set state (can be LIB and APPS)
-$!
-$ STATE = "LIB"
-$ IF BUILDALL .EQS. "APPS" THEN STATE = "APPS"
-$!
-$! Check if the library module name actually is defined
-$!
-$ IF F$TYPE('LIB_MODULE') .EQS. ""
-$ THEN
-$   WRITE SYS$ERROR ""
-$   WRITE SYS$ERROR "The module ",MODULE_NAME," does not exist.  Continuing..."
-$   WRITE SYS$ERROR ""
-$   GOTO MODULE_NEXT
-$ ENDIF
-$!
-$! Top Of The Module Loop.
-$!
-$ MODULE_AGAIN:
-$!
-$! Tell The User What Module We Are Building.
-$!
-$ IF (MODULE_NAME1.NES."") 
-$ THEN
-$   IF STATE .EQS. "LIB"
-$   THEN
-$     WRITE SYS$OUTPUT "Compiling The ",MODULE_NAME1," Library Files. (",BUILDALL,",",STATE,")"
-$   ELSE IF F$TYPE('APPS_MODULE') .NES. ""
-$     THEN
-$       WRITE SYS$OUTPUT "Compiling The ",MODULE_NAME1," Applications. (",BUILDALL,",",STATE,")"
-$     ENDIF
-$   ENDIF
-$ ENDIF
-$!
-$!  Define A File Counter And Set It To "0".
-$!
-$ FILE_COUNTER = 0
-$ APPLICATION = ""
-$ APPLICATION_COUNTER = 0
-$!
-$! Top Of The File Loop.
-$!
-$ NEXT_FILE:
-$!
-$! Look in the LIB_MODULE is we're in state LIB
-$!
-$ IF STATE .EQS. "LIB"
-$ THEN
-$!
-$!   O.K, Extract The File Name From The File List.
-$!
-$   FILE_NAME = F$ELEMENT(FILE_COUNTER,",",'LIB_MODULE')
-$!
-$!   else
-$!
-$ ELSE
-$   FILE_NAME = ","
-$!
-$   IF F$TYPE('APPS_MODULE') .NES. ""
-$   THEN
-$!
-$!     Extract The File Name From The File List.
-$!     This part is a bit more complicated.
-$!
-$     IF APPLICATION .EQS. ""
-$     THEN
-$       APPLICATION = F$ELEMENT(APPLICATION_COUNTER,";",'APPS_MODULE')
-$       APPLICATION_COUNTER = APPLICATION_COUNTER + 1
-$       APPLICATION_OBJECTS = F$ELEMENT(1,"/",APPLICATION)
-$       APPLICATION = F$ELEMENT(0,"/",APPLICATION)
-$       FILE_COUNTER = 0
-$     ENDIF
-$
-$!     WRITE SYS$OUTPUT "DEBUG: SHOW SYMBOL APPLICATION*"
-$!     SHOW SYMBOL APPLICATION*
-$!
-$     IF APPLICATION .NES. ";"
-$     THEN
-$       FILE_NAME = F$ELEMENT(FILE_COUNTER,",",APPLICATION_OBJECTS)
-$       IF FILE_NAME .EQS. ","
-$       THEN
-$         APPLICATION = ""
-$         GOTO NEXT_FILE
-$       ENDIF
-$     ENDIF
-$   ENDIF
-$ ENDIF
-$!
-$! Check To See If We Are At The End Of The File List.
-$!
-$ IF (FILE_NAME.EQS.",") 
-$ THEN 
-$!
-$!  We Are At The End Of The File List, Change State Or Goto FILE_DONE.
-$!
-$   IF STATE .EQS. "LIB" .AND. BUILDALL .NES. "LIBRARY"
-$   THEN
-$     STATE = "APPS"
-$     GOTO MODULE_AGAIN
-$   ELSE
-$     GOTO FILE_DONE
-$   ENDIF
-$!
-$! End The File List Check.
-$!
-$ ENDIF
-$!
-$! Increment The Counter.
-$!
-$ FILE_COUNTER = FILE_COUNTER + 1
-$!
-$! Create The Source File Name.
-$!
-$ TMP_FILE_NAME = F$ELEMENT(1,"]",FILE_NAME)
-$ IF TMP_FILE_NAME .EQS. "]" THEN TMP_FILE_NAME = FILE_NAME
-$ IF F$ELEMENT(0,".",TMP_FILE_NAME) .EQS. TMP_FILE_NAME THEN -
-       FILE_NAME = FILE_NAME + ".c"
-$ IF (MODULE_NAME.NES."")
-$ THEN
-$   SOURCE_FILE = "SYS$DISK:[." + MODULE_NAME+ "]" + FILE_NAME
-$ ELSE
-$   SOURCE_FILE = "SYS$DISK:[]" + FILE_NAME
-$ ENDIF
-$ SOURCE_FILE = SOURCE_FILE - "]["
-$!
-$! Create The Object File Name.
-$!
-$ OBJECT_FILE = OBJ_DIR + F$PARSE(FILE_NAME,,,"NAME","SYNTAX_ONLY") + ".OBJ"
-$ ON WARNING THEN GOTO NEXT_FILE
-$!
-$! Check To See If The File We Want To Compile Is Actually There.
-$!
-$ IF (F$SEARCH(SOURCE_FILE).EQS."")
-$ THEN
-$!
-$!  Tell The User That The File Doesn't Exist.
-$!
-$   WRITE SYS$OUTPUT ""
-$   WRITE SYS$OUTPUT "The File ",SOURCE_FILE," Doesn't Exist."
-$   WRITE SYS$OUTPUT ""
-$!
-$!  Exit The Build.
-$!
-$   GOTO EXIT
-$!
-$! End The File Exist Check.
-$!
-$ ENDIF
-$!
-$! Tell The User We Are Compiling The File.
-$!
-$ IF (MODULE_NAME.EQS."")
-$ THEN
-$   WRITE SYS$OUTPUT "Compiling The ",FILE_NAME," File.  (",BUILDALL,",",STATE,")"
-$ ENDIF
-$ IF (MODULE_NAME.NES."")
-$ THEN 
-$   WRITE SYS$OUTPUT " ",FILE_NAME,""
-$ ENDIF
-$!
-$! Compile The File.
-$!
-$ ON ERROR THEN GOTO NEXT_FILE
-$ FILE_NAME0 = F$ELEMENT(0,".",FILE_NAME)
-$ IF FILE_NAME - ".mar" .NES. FILE_NAME
-$ THEN
-$   MACRO/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
-$ ELSE
-$   IF COMPILEWITH_CC3 - FILE_NAME0 .NES. COMPILEWITH_CC3
-$   THEN
-$     CC3/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
-$   ELSE
-$     IF COMPILEWITH_CC4 - FILE_NAME0 .NES. COMPILEWITH_CC4
-$     THEN
-$       CC4/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
-$     ELSE
-$       IF COMPILEWITH_CC5 - FILE_NAME0 .NES. COMPILEWITH_CC5
-$       THEN
-$         CC5/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
-$       ELSE
-$         IF COMPILEWITH_CC6 - FILE_NAME0 .NES. COMPILEWITH_CC6
-$         THEN
-$           CC6/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
-$         ELSE
-$           CC/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
-$         ENDIF
-$       ENDIF
-$     ENDIF
-$   ENDIF
-$ ENDIF
-$ IF STATE .EQS. "LIB"
-$ THEN 
-$!
-$!   Add It To The Library.
-$!
-$   LIBRARY/REPLACE 'LIB_NAME' 'OBJECT_FILE'
-$!
-$!   Time To Clean Up The Object File.
-$!
-$   DELETE 'OBJECT_FILE';*
-$ ENDIF
-$!
-$! Go Back And Do It Again.
-$!
-$ GOTO NEXT_FILE
-$!
-$! All Done With This Library Part.
-$!
-$ FILE_DONE:
-$!
-$! Time To Build Some Applications
-$!
-$ IF F$TYPE('APPS_MODULE') .NES. "" .AND. BUILDALL .NES. "LIBRARY"
-$ THEN
-$   APPLICATION_COUNTER = 0
-$ NEXT_APPLICATION:
-$   APPLICATION = F$ELEMENT(APPLICATION_COUNTER,";",'APPS_MODULE')
-$   IF APPLICATION .EQS. ";" THEN GOTO APPLICATION_DONE
-$
-$   APPLICATION_COUNTER = APPLICATION_COUNTER + 1
-$   APPLICATION_OBJECTS = F$ELEMENT(1,"/",APPLICATION)
-$   APPLICATION = F$ELEMENT(0,"/",APPLICATION)
-$
-$!   WRITE SYS$OUTPUT "DEBUG: SHOW SYMBOL APPLICATION*"
-$!   SHOW SYMBOL APPLICATION*
-$!
-$! Tell the user what happens
-$!
-$   WRITE SYS$OUTPUT " ",APPLICATION,".exe"
-$!
-$! Link The Program.
-$!
-$   ON ERROR THEN GOTO NEXT_APPLICATION
-$!
-$! Check To See If We Are To Link With A Specific TCP/IP Library.
-$!
-$   IF (TCPIP_LIB.NES."")
-$   THEN
-$!
-$!    Link With A TCP/IP Library.
-$!
-$     LINK/'DEBUGGER'/'TRACEBACK'/EXE='EXE_DIR''APPLICATION'.EXE -
-          'OBJ_DIR''APPLICATION_OBJECTS', -
-         'CRYPTO_LIB'/LIBRARY, -
-          'TCPIP_LIB','OPT_FILE'/OPTION
-$!
-$! Else...
-$!
-$   ELSE
-$!
-$!    Don't Link With A TCP/IP Library.
-$!
-$     LINK/'DEBUGGER'/'TRACEBACK'/EXE='EXE_DIR''APPLICATION'.EXE -
-          'OBJ_DIR''APPLICATION_OBJECTS',-
-         'CRYPTO_LIB'/LIBRARY, -
-          'OPT_FILE'/OPTION
-$!
-$! End The TCP/IP Library Check.
-$!
-$   ENDIF
-$   GOTO NEXT_APPLICATION
-$  APPLICATION_DONE:
-$ ENDIF
-$!
-$! Go Back And Get The Next Module.
-$!
-$ GOTO MODULE_NEXT
-$!
-$! All Done With This Module.
-$!
-$ MODULE_DONE:
-$!
-$! Tell The User That We Are All Done.
-$!
-$ WRITE SYS$OUTPUT "All Done..."
-$ EXIT:
-$ GOSUB CLEANUP
-$ EXIT
-$!
-$! Check For The Link Option FIle.
-$!
-$ CHECK_OPT_FILE:
-$!
-$! Check To See If We Need To Make A VAX C Option File.
-$!
-$ IF (COMPILER.EQS."VAXC")
-$ THEN
-$!
-$!  Check To See If We Already Have A VAX C Linker Option File.
-$!
-$   IF (F$SEARCH(OPT_FILE).EQS."")
-$   THEN
-$!
-$!    We Need A VAX C Linker Option File.
-$!
-$     CREATE 'OPT_FILE'
-$DECK
-!
-! Default System Options File To Link Agianst 
-! The Sharable VAX C Runtime Library.
-!
-SYS$SHARE:VAXCRTL.EXE/SHARE
-$EOD
-$!
-$!  End The Option File Check.
-$!
-$   ENDIF
-$!
-$! End The VAXC Check.
-$!
-$ ENDIF
-$!
-$! Check To See If We Need A GNU C Option File.
-$!
-$ IF (COMPILER.EQS."GNUC")
-$ THEN
-$!
-$!  Check To See If We Already Have A GNU C Linker Option File.
-$!
-$   IF (F$SEARCH(OPT_FILE).EQS."")
-$   THEN
-$!
-$!    We Need A GNU C Linker Option File.
-$!
-$     CREATE 'OPT_FILE'
-$DECK
-!
-! Default System Options File To Link Agianst 
-! The Sharable C Runtime Library.
-!
-GNU_CC:[000000]GCCLIB/LIBRARY
-SYS$SHARE:VAXCRTL/SHARE
-$EOD
-$!
-$!  End The Option File Check.
-$!
-$   ENDIF
-$!
-$! End The GNU C Check.
-$!
-$ ENDIF
-$!
-$! Check To See If We Need A DEC C Option File.
-$!
-$ IF (COMPILER.EQS."DECC")
-$ THEN
-$!
-$!  Check To See If We Already Have A DEC C Linker Option File.
-$!
-$   IF (F$SEARCH(OPT_FILE).EQS."")
-$   THEN
-$!
-$!    Figure Out If We Need A non-VAX Or A VAX Linker Option File.
-$!
-$     IF ARCH .EQS. "VAX"
-$     THEN
-$!
-$!      We Need A DEC C Linker Option File For VAX.
-$!
-$       CREATE 'OPT_FILE'
-$DECK
-!
-! Default System Options File To Link Agianst 
-! The Sharable DEC C Runtime Library.
-!
-SYS$SHARE:DECC$SHR.EXE/SHARE
-$EOD
-$!
-$!    Else...
-$!
-$     ELSE
-$!
-$!      Create The non-VAX Linker Option File.
-$!
-$       CREATE 'OPT_FILE'
-$DECK
-!
-! Default System Options File For non-VAX To Link Agianst 
-! The Sharable C Runtime Library.
-!
-SYS$SHARE:CMA$OPEN_LIB_SHR/SHARE
-SYS$SHARE:CMA$OPEN_RTL/SHARE
-$EOD
-$!
-$!    End The DEC C Option File Check.
-$!
-$     ENDIF
-$!
-$!  End The Option File Search.
-$!
-$   ENDIF
-$!
-$! End The DEC C Check.
-$!
-$ ENDIF
-$!
-$!  Tell The User What Linker Option File We Are Using.
-$!
-$ WRITE SYS$OUTPUT "Using Linker Option File ",OPT_FILE,"."    
-$!
-$! Time To RETURN.
-$!
-$ RETURN
-$!
-$! Check The User's Options.
-$!
-$ CHECK_OPTIONS:
-$!
-$! Check To See If P1 Is Blank.
-$!
-$ IF (P1.EQS."ALL")
-$ THEN
-$!
-$!   P1 Is Blank, So Build Everything.
-$!
-$    BUILDALL = "TRUE"
-$!
-$! Else...
-$!
-$ ELSE
-$!
-$!  Else, Check To See If P1 Has A Valid Arguement.
-$!
-$   IF (P1.EQS."LIBRARY").OR.(P1.EQS."APPS")
-$   THEN
-$!
-$!    A Valid Arguement.
-$!
-$     BUILDALL = P1
-$!
-$!  Else...
-$!
-$   ELSE
-$!
-$!    Tell The User We Don't Know What They Want.
-$!
-$     WRITE SYS$OUTPUT ""
-$     WRITE SYS$OUTPUT "The Option ",P1," Is Invalid.  The Valid Options Are:"
-$     WRITE SYS$OUTPUT ""
-$     WRITE SYS$OUTPUT "    ALL      :  Just Build Everything."
-$     WRITE SYS$OUTPUT "    LIBRARY  :  To Compile Just The [.xxx.EXE.CRYPTO]LIBCRYPTO.OLB Library."
-$     WRITE SYS$OUTPUT "    APPS     :  To Compile Just The [.xxx.EXE.CRYPTO]*.EXE Programs."
-$     WRITE SYS$OUTPUT ""
-$     WRITE SYS$OUTPUT " Where 'xxx' Stands For:"
-$     WRITE SYS$OUTPUT ""
-$     WRITE SYS$OUTPUT "    ALPHA    :  Alpha Architecture."
-$     WRITE SYS$OUTPUT "    IA64     :  IA64 Architecture."
-$     WRITE SYS$OUTPUT "    VAX      :  VAX Architecture."
-$     WRITE SYS$OUTPUT ""
-$!
-$!    Time To EXIT.
-$!
-$     EXIT
-$!
-$!  End The Valid Arguement Check.
-$!
-$   ENDIF
-$!
-$! End The P1 Check.
-$!
-$ ENDIF
-$!
-$! Check To See If P2 Is Blank.
-$!
-$ IF (P2.EQS."NODEBUG")
-$ THEN
-$!
-$!   P2 Is NODEBUG, So Compile Without The Debugger Information.
-$!
-$    DEBUGGER = "NODEBUG"
-$    TRACEBACK = "NOTRACEBACK" 
-$    GCC_OPTIMIZE = "OPTIMIZE"
-$    CC_OPTIMIZE = "OPTIMIZE"
-$    MACRO_OPTIMIZE = "OPTIMIZE"
-$    WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile."
-$    WRITE SYS$OUTPUT "Compiling With Compiler Optimization."
-$ ELSE
-$!
-$!  Check To See If We Are To Compile With Debugger Information.
-$!
-$   IF (P2.EQS."DEBUG")
-$   THEN
-$!
-$!    Compile With Debugger Information.
-$!
-$     DEBUGGER = "DEBUG"
-$     TRACEBACK = "TRACEBACK"
-$     GCC_OPTIMIZE = "NOOPTIMIZE"
-$     CC_OPTIMIZE = "NOOPTIMIZE"
-$     MACRO_OPTIMIZE = "NOOPTIMIZE"
-$     WRITE SYS$OUTPUT "Debugger Information Will Be Produced During Compile."
-$     WRITE SYS$OUTPUT "Compiling Without Compiler Optimization."
-$   ELSE 
-$!
-$!    They Entered An Invalid Option..
-$!
-$     WRITE SYS$OUTPUT ""
-$     WRITE SYS$OUTPUT "The Option ",P2," Is Invalid.  The Valid Options Are:"
-$     WRITE SYS$OUTPUT ""
-$     WRITE SYS$OUTPUT "     DEBUG   :  Compile With The Debugger Information."
-$     WRITE SYS$OUTPUT "     NODEBUG :  Compile Without The Debugger Information."
-$     WRITE SYS$OUTPUT ""
-$!
-$!    Time To EXIT.
-$!
-$     EXIT
-$!
-$!  End The Valid Arguement Check.
-$!
-$   ENDIF
-$!
-$! End The P2 Check.
-$!
-$ ENDIF
-$!
-$! Special Threads For OpenVMS v7.1 Or Later
-$!
-$! Written By:  Richard Levitte
-$!              richard@levitte.org
-$!
-$!
-$! Check To See If We Have A Option For P5.
-$!
-$ IF (P5.EQS."")
-$ THEN
-$!
-$!  Get The Version Of VMS We Are Using.
-$!
-$   ISSEVEN :=
-$   TMP = F$ELEMENT(0,"-",F$EXTRACT(1,4,F$GETSYI("VERSION")))
-$   TMP = F$INTEGER(F$ELEMENT(0,".",TMP)+F$ELEMENT(1,".",TMP))
-$!
-$!  Check To See If The VMS Version Is v7.1 Or Later.
-$!
-$   IF (TMP.GE.71)
-$   THEN
-$!
-$!    We Have OpenVMS v7.1 Or Later, So Use The Special Threads.
-$!
-$     ISSEVEN := ,PTHREAD_USE_D4
-$!
-$!  End The VMS Version Check.
-$!
-$   ENDIF
-$!
-$! End The P5 Check.
-$!
-$ ENDIF
-$!
-$! Check To See If P3 Is Blank.
-$!
-$ IF (P3.EQS."")
-$ THEN
-$!
-$!  O.K., The User Didn't Specify A Compiler, Let's Try To
-$!  Find Out Which One To Use.
-$!
-$!  Check To See If We Have GNU C.
-$!
-$   IF (F$TRNLNM("GNU_CC").NES."")
-$   THEN
-$!
-$!    Looks Like GNUC, Set To Use GNUC.
-$!
-$     P3 = "GNUC"
-$!
-$!  Else...
-$!
-$   ELSE
-$!
-$!    Check To See If We Have VAXC Or DECC.
-$!
-$     IF (ARCH.NES."VAX").OR.(F$TRNLNM("DECC$CC_DEFAULT").NES."")
-$     THEN 
-$!
-$!      Looks Like DECC, Set To Use DECC.
-$!
-$       P3 = "DECC"
-$!
-$!    Else...
-$!
-$     ELSE
-$!
-$!      Looks Like VAXC, Set To Use VAXC.
-$!
-$       P3 = "VAXC"
-$!
-$!    End The VAXC Compiler Check.
-$!
-$     ENDIF
-$!
-$!  End The DECC & VAXC Compiler Check.
-$!
-$   ENDIF
-$!
-$!  End The Compiler Check.
-$!
-$ ENDIF
-$!
-$! Check To See If We Have A Option For P4.
-$!
-$ IF (P4.EQS."")
-$ THEN
-$!
-$!  Find out what socket library we have available
-$!
-$   IF F$PARSE("SOCKETSHR:") .NES. ""
-$   THEN
-$!
-$!    We have SOCKETSHR, and it is my opinion that it's the best to use.
-$!
-$     P4 = "SOCKETSHR"
-$!
-$!    Tell the user
-$!
-$     WRITE SYS$OUTPUT "Using SOCKETSHR for TCP/IP"
-$!
-$!    Else, let's look for something else
-$!
-$   ELSE
-$!
-$!    Like UCX (the reason to do this before Multinet is that the UCX
-$!    emulation is easier to use...)
-$!
-$     IF F$TRNLNM("UCX$IPC_SHR") .NES. "" -
-        .OR. F$PARSE("SYS$SHARE:UCX$IPC_SHR.EXE") .NES. "" -
-        .OR. F$PARSE("SYS$LIBRARY:UCX$IPC.OLB") .NES. ""
-$     THEN
-$!
-$!     Last resort: a UCX or UCX-compatible library
-$!
-$      P4 = "UCX"
-$!
-$!      Tell the user
-$!
-$       WRITE SYS$OUTPUT "Using UCX or an emulation thereof for TCP/IP"
-$!
-$!     That was all...
-$!
-$     ENDIF
-$   ENDIF
-$ ENDIF
-$!
-$! Set Up Initial CC Definitions, Possibly With User Ones
-$!
-$ CCDEFS = "TCPIP_TYPE_''P4',DSO_VMS"
-$ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS
-$ CCEXTRAFLAGS = ""
-$ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS
-$ CCDISABLEWARNINGS = "LONGLONGTYPE,LONGLONGSUFX,FOUNDCR"
-$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN -
-       CCDISABLEWARNINGS = CCDISABLEWARNINGS + "," + USER_CCDISABLEWARNINGS
-$!
-$!  Check To See If The User Entered A Valid Paramter.
-$!
-$ IF (P3.EQS."VAXC").OR.(P3.EQS."DECC").OR.(P3.EQS."GNUC")
-$ THEN
-$!
-$!    Check To See If The User Wanted DECC.
-$!
-$   IF (P3.EQS."DECC")
-$   THEN
-$!
-$!    Looks Like DECC, Set To Use DECC.
-$!
-$     COMPILER = "DECC"
-$!
-$!    Tell The User We Are Using DECC.
-$!
-$     WRITE SYS$OUTPUT "Using DECC 'C' Compiler."
-$!
-$!    Use DECC...
-$!
-$     CC = "CC"
-$     IF ARCH.EQS."VAX" .AND. F$TRNLNM("DECC$CC_DEFAULT").NES."/DECC" -
-        THEN CC = "CC/DECC"
-$     CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/STANDARD=ANSI89" + -
-           "/NOLIST/PREFIX=ALL" + -
-          "/INCLUDE=(SYS$DISK:[],SYS$DISK:[-],SYS$DISK:[-.CRYPTO])" + -
-          CCEXTRAFLAGS
-$!
-$!    Define The Linker Options File Name.
-$!
-$     OPT_FILE = "''EXE_DIR'VAX_DECC_OPTIONS.OPT"
-$!
-$!  End DECC Check.
-$!
-$   ENDIF
-$!
-$!  Check To See If We Are To Use VAXC.
-$!
-$   IF (P3.EQS."VAXC")
-$   THEN
-$!
-$!    Looks Like VAXC, Set To Use VAXC.
-$!
-$     COMPILER = "VAXC"
-$!
-$!    Tell The User We Are Using VAX C.
-$!
-$     WRITE SYS$OUTPUT "Using VAXC 'C' Compiler."
-$!
-$!    Compile Using VAXC.
-$!
-$     CC = "CC"
-$     IF ARCH.NES."VAX"
-$     THEN
-$      WRITE SYS$OUTPUT "There is no VAX C on ''ARCH'!"
-$      EXIT
-$     ENDIF
-$     IF F$TRNLNM("DECC$CC_DEFAULT").EQS."/DECC" THEN CC = "CC/VAXC"
-$     CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/NOLIST" + -
-          "/INCLUDE=(SYS$DISK:[],SYS$DISK:[-],SYS$DISK:[-.CRYPTO])" + -
-          CCEXTRAFLAGS
-$     CCDEFS = """VAXC""," + CCDEFS
-$!
-$!    Define <sys> As SYS$COMMON:[SYSLIB]
-$!
-$     DEFINE/NOLOG SYS SYS$COMMON:[SYSLIB]
-$!
-$!    Define The Linker Options File Name.
-$!
-$     OPT_FILE = "''EXE_DIR'VAX_VAXC_OPTIONS.OPT"
-$!
-$!  End VAXC Check
-$!
-$   ENDIF
-$!
-$!  Check To See If We Are To Use GNU C.
-$!
-$   IF (P3.EQS."GNUC")
-$   THEN
-$!
-$!    Looks Like GNUC, Set To Use GNUC.
-$!
-$     COMPILER = "GNUC"
-$!
-$!    Tell The User We Are Using GNUC.
-$!
-$     WRITE SYS$OUTPUT "Using GNU 'C' Compiler."
-$!
-$!    Use GNU C...
-$!
-$     CC = "GCC/NOCASE_HACK/''GCC_OPTIMIZE'/''DEBUGGER'/NOLIST" + -
-          "/INCLUDE=(SYS$DISK:[],SYS$DISK:[-],SYS$DISK:[-.CRYPTO])" + -
-          CCEXTRAFLAGS
-$!
-$!    Define The Linker Options File Name.
-$!
-$     OPT_FILE = "''EXE_DIR'VAX_GNUC_OPTIONS.OPT"
-$!
-$!  End The GNU C Check.
-$!
-$   ENDIF
-$!
-$!  Set up default defines
-$!
-$   CCDEFS = """FLAT_INC=1""," + CCDEFS
-$!
-$!  Finish up the definition of CC.
-$!
-$   IF COMPILER .EQS. "DECC"
-$   THEN
-$     IF CCDISABLEWARNINGS .EQS. ""
-$     THEN
-$       CC4DISABLEWARNINGS = "DOLLARID"
-$       CC6DISABLEWARNINGS = "MIXLINKAGE"
-$     ELSE
-$       CC4DISABLEWARNINGS = CCDISABLEWARNINGS + ",DOLLARID"
-$       CC6DISABLEWARNINGS = CCDISABLEWARNINGS + ",MIXLINKAGE"
-$       CCDISABLEWARNINGS = "/WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))"
-$     ENDIF
-$     CC4DISABLEWARNINGS = "/WARNING=(DISABLE=(" + CC4DISABLEWARNINGS + "))"
-$     CC6DISABLEWARNINGS = "/WARNING=(DISABLE=(" + CC6DISABLEWARNINGS + "))"
-$   ELSE
-$     CCDISABLEWARNINGS = ""
-$     CC4DISABLEWARNINGS = ""
-$     CC6DISABLEWARNINGS = ""
-$   ENDIF
-$   CC3 = CC + "/DEFINE=(" + CCDEFS + ISSEVEN + ")" + CCDISABLEWARNINGS
-$   CC = CC + "/DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS
-$   IF ARCH .EQS. "VAX" .AND. COMPILER .EQS. "DECC" .AND. P2 .NES. "DEBUG"
-$   THEN
-$     CC5 = CC + "/OPTIMIZE=NODISJOINT"
-$   ELSE
-$     CC5 = CC + "/NOOPTIMIZE"
-$   ENDIF
-$   CC4 = CC - CCDISABLEWARNINGS + CC4DISABLEWARNINGS
-$   CC6 = CC - CCDISABLEWARNINGS + CC6DISABLEWARNINGS
-$!
-$!  Show user the result
-$!
-$   WRITE/SYMBOL SYS$OUTPUT "Main C Compiling Command: ",CC
-$!
-$!  Else The User Entered An Invalid Arguement.
-$!
-$ ELSE
-$!
-$!  Tell The User We Don't Know What They Want.
-$!
-$   WRITE SYS$OUTPUT ""
-$   WRITE SYS$OUTPUT "The Option ",P3," Is Invalid.  The Valid Options Are:"
-$   WRITE SYS$OUTPUT ""
-$   WRITE SYS$OUTPUT "    VAXC  :  To Compile With VAX C."
-$   WRITE SYS$OUTPUT "    DECC  :  To Compile With DEC C."
-$   WRITE SYS$OUTPUT "    GNUC  :  To Compile With GNU C."
-$   WRITE SYS$OUTPUT ""
-$!
-$!  Time To EXIT.
-$!
-$   EXIT
-$!
-$! End The Valid Arguement Check.
-$!
-$ ENDIF
-$!
-$! Build a MACRO command for the architecture at hand
-$!
-$ IF ARCH .EQS. "VAX" THEN MACRO = "MACRO/''DEBUGGER'"
-$ IF ARCH .NES. "VAX" THEN MACRO = "MACRO/MIGRATION/''DEBUGGER'/''MACRO_OPTIMIZE'"
-$!
-$!  Show user the result
-$!
-$   WRITE/SYMBOL SYS$OUTPUT "Main MACRO Compiling Command: ",MACRO
-$!
-$! Time to check the contents, and to make sure we get the correct library.
-$!
-$ IF P4.EQS."SOCKETSHR" .OR. P4.EQS."MULTINET" .OR. P4.EQS."UCX" -
-     .OR. P4.EQS."TCPIP" .OR. P4.EQS."NONE"
-$ THEN
-$!
-$!  Check to see if SOCKETSHR was chosen
-$!
-$   IF P4.EQS."SOCKETSHR"
-$   THEN
-$!
-$!    Set the library to use SOCKETSHR
-$!
-$     TCPIP_LIB = "SYS$DISK:[-.VMS]SOCKETSHR_SHR.OPT/OPT"
-$!
-$!    Done with SOCKETSHR
-$!
-$   ENDIF
-$!
-$!  Check to see if MULTINET was chosen
-$!
-$   IF P4.EQS."MULTINET"
-$   THEN
-$!
-$!    Set the library to use UCX emulation.
-$!
-$     P4 = "UCX"
-$!
-$!    Done with MULTINET
-$!
-$   ENDIF
-$!
-$!  Check to see if UCX was chosen
-$!
-$   IF P4.EQS."UCX"
-$   THEN
-$!
-$!    Set the library to use UCX.
-$!
-$     TCPIP_LIB = "SYS$DISK:[-.VMS]UCX_SHR_DECC.OPT/OPT"
-$     IF F$TRNLNM("UCX$IPC_SHR") .NES. ""
-$     THEN
-$       TCPIP_LIB = "SYS$DISK:[-.VMS]UCX_SHR_DECC_LOG.OPT/OPT"
-$     ELSE
-$       IF COMPILER .NES. "DECC" .AND. ARCH .EQS. "VAX" THEN -
-         TCPIP_LIB = "SYS$DISK:[-.VMS]UCX_SHR_VAXC.OPT/OPT"
-$     ENDIF
-$!
-$!    Done with UCX
-$!
-$   ENDIF
-$!
-$!  Check to see if TCPIP was chosen
-$!
-$   IF P4.EQS."TCPIP"
-$   THEN
-$!
-$!    Set the library to use TCPIP (post UCX).
-$!
-$     TCPIP_LIB = "SYS$DISK:[-.VMS]TCPIP_SHR_DECC.OPT/OPT"
-$!
-$!    Done with TCPIP
-$!
-$   ENDIF
-$!
-$!  Check to see if NONE was chosen
-$!
-$   IF P4.EQS."NONE"
-$   THEN
-$!
-$!    Do not use a TCPIP library.
-$!
-$     TCPIP_LIB = ""
-$!
-$!    Done with TCPIP
-$!
-$   ENDIF
-$!
-$!  Print info
-$!
-$   WRITE SYS$OUTPUT "TCP/IP library spec: ", TCPIP_LIB
-$!
-$!  Else The User Entered An Invalid Arguement.
-$!
-$ ELSE
-$!
-$!  Tell The User We Don't Know What They Want.
-$!
-$   WRITE SYS$OUTPUT ""
-$   WRITE SYS$OUTPUT "The Option ",P4," Is Invalid.  The Valid Options Are:"
-$   WRITE SYS$OUTPUT ""
-$   WRITE SYS$OUTPUT "    SOCKETSHR  :  To link with SOCKETSHR TCP/IP library."
-$   WRITE SYS$OUTPUT "    UCX        :  To link with UCX TCP/IP library."
-$   WRITE SYS$OUTPUT "    TCPIP      :  To link with TCPIP (post UCX) TCP/IP library."
-$   WRITE SYS$OUTPUT ""
-$!
-$!  Time To EXIT.
-$!
-$   EXIT
-$!
-$!  Done with TCP/IP libraries
-$!
-$ ENDIF
-$!
-$! Check if the user wanted to compile just a subset of all the encryption
-$! methods.
-$!
-$ IF P6 .NES. ""
-$ THEN
-$   ENCRYPT_TYPES = P6
-$ ENDIF
-$!
-$!  Time To RETURN...
-$!
-$ RETURN
-$!
-$ INITIALISE:
-$!
-$! Save old value of the logical name OPENSSL
-$!
-$ __SAVE_OPENSSL = F$TRNLNM("OPENSSL","LNM$PROCESS_TABLE")
-$!
-$! Save directory information
-$!
-$ __HERE = F$PARSE(F$PARSE("A.;",F$ENVIRONMENT("PROCEDURE"))-"A.;","[]A.;") - "A.;"
-$ __HERE = F$EDIT(__HERE,"UPCASE")
-$ __TOP = __HERE - "FIPS-1_0]"
-$ __INCLUDE = __TOP + "INCLUDE.OPENSSL]"
-$!
-$! Set up the logical name OPENSSL to point at the include directory
-$!
-$ DEFINE OPENSSL/NOLOG '__INCLUDE'
-$!
-$! Done
-$!
-$ RETURN
-$!
-$ CLEANUP:
-$!
-$! Restore the logical name OPENSSL if it had a value
-$!
-$ IF __SAVE_OPENSSL .EQS. ""
-$ THEN
-$   DEASSIGN OPENSSL
-$ ELSE
-$   DEFINE/NOLOG OPENSSL '__SAVE_OPENSSL'
-$ ENDIF
-$!
-$! Done
-$!
-$ RETURN
diff --git a/deps/openssl/openssl/fips/fips-nodiff.txt b/deps/openssl/openssl/fips/fips-nodiff.txt
deleted file mode 100644 (file)
index fb2944b..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-KeyPair.rsp
-PQGGen.rsp
-SigGen.rsp
-SigGen15.rsp
-SigGenPSS.rsp
-SigGenRSA.rsp
-SigGenPSS.rsp
diff --git a/deps/openssl/openssl/fips/fips.c b/deps/openssl/openssl/fips/fips.c
deleted file mode 100644 (file)
index 7dcc344..0000000
+++ /dev/null
@@ -1,519 +0,0 @@
-/* ====================================================================
- * Copyright (c) 2003 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    openssl-core@openssl.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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 <openssl/rand.h>
-#include <openssl/fips_rand.h>
-#include <openssl/err.h>
-#include <openssl/bio.h>
-#include <openssl/hmac.h>
-#include <openssl/rsa.h>
-#include <string.h>
-#include <limits.h>
-#include "fips_locl.h"
-
-#ifdef OPENSSL_FIPS
-
-#include <openssl/fips.h>
-
-#ifndef PATH_MAX
-#define PATH_MAX 1024
-#endif
-
-static int fips_selftest_fail;
-static int fips_mode;
-static const void *fips_rand_check;
-
-static void fips_set_mode(int onoff)
-       {
-       int owning_thread = fips_is_owning_thread();
-
-       if (fips_is_started())
-               {
-               if (!owning_thread) fips_w_lock();
-               fips_mode = onoff;
-               if (!owning_thread) fips_w_unlock();
-               }
-       }
-
-static void fips_set_rand_check(const void *rand_check)
-       {
-       int owning_thread = fips_is_owning_thread();
-
-       if (fips_is_started())
-               {
-               if (!owning_thread) fips_w_lock();
-               fips_rand_check = rand_check;
-               if (!owning_thread) fips_w_unlock();
-               }
-       }
-
-int FIPS_mode(void)
-       {
-       int ret = 0;
-       int owning_thread = fips_is_owning_thread();
-
-       if (fips_is_started())
-               {
-               if (!owning_thread) fips_r_lock();
-               ret = fips_mode;
-               if (!owning_thread) fips_r_unlock();
-               }
-       return ret;
-       }
-
-const void *FIPS_rand_check(void)
-       {
-       const void *ret = 0;
-       int owning_thread = fips_is_owning_thread();
-
-       if (fips_is_started())
-               {
-               if (!owning_thread) fips_r_lock();
-               ret = fips_rand_check;
-               if (!owning_thread) fips_r_unlock();
-               }
-       return ret;
-       }
-
-int FIPS_selftest_failed(void)
-    {
-    int ret = 0;
-    if (fips_is_started())
-       {
-       int owning_thread = fips_is_owning_thread();
-
-       if (!owning_thread) fips_r_lock();
-       ret = fips_selftest_fail;
-       if (!owning_thread) fips_r_unlock();
-       }
-    return ret;
-    }
-
-/* Selftest failure fatal exit routine. This will be called
- * during *any* cryptographic operation. It has the minimum
- * overhead possible to avoid too big a performance hit.
- */
-
-void FIPS_selftest_check(void)
-    {
-    if (fips_selftest_fail)
-       {
-       OpenSSLDie(__FILE__,__LINE__, "FATAL FIPS SELFTEST FAILURE");
-       }
-    }
-
-void fips_set_selftest_fail(void)
-    {
-    fips_selftest_fail = 1;
-    }
-
-int FIPS_selftest()
-    {
-
-    return FIPS_selftest_sha1()
-       && FIPS_selftest_hmac()
-       && FIPS_selftest_aes()
-       && FIPS_selftest_des()
-       && FIPS_selftest_rsa()
-       && FIPS_selftest_dsa();
-    }
-
-extern const void         *FIPS_text_start(),  *FIPS_text_end();
-extern const unsigned char FIPS_rodata_start[], FIPS_rodata_end[];
-unsigned char              FIPS_signature [20] = { 0 };
-static const char          FIPS_hmac_key[]="etaonrishdlcupfm";
-
-unsigned int FIPS_incore_fingerprint(unsigned char *sig,unsigned int len)
-    {
-    const unsigned char *p1 = FIPS_text_start();
-    const unsigned char *p2 = FIPS_text_end();
-    const unsigned char *p3 = FIPS_rodata_start;
-    const unsigned char *p4 = FIPS_rodata_end;
-    HMAC_CTX c;
-
-    HMAC_CTX_init(&c);
-    HMAC_Init(&c,FIPS_hmac_key,strlen(FIPS_hmac_key),EVP_sha1());
-
-    /* detect overlapping regions */
-    if (p1<=p3 && p2>=p3)
-       p3=p1, p4=p2>p4?p2:p4, p1=NULL, p2=NULL;
-    else if (p3<=p1 && p4>=p1)
-       p3=p3, p4=p2>p4?p2:p4, p1=NULL, p2=NULL;
-
-    if (p1)
-       HMAC_Update(&c,p1,(size_t)p2-(size_t)p1);
-
-    if (FIPS_signature>=p3 && FIPS_signature<p4)
-       {
-       /* "punch" hole */
-       HMAC_Update(&c,p3,(size_t)FIPS_signature-(size_t)p3);
-       p3 = FIPS_signature+sizeof(FIPS_signature);
-       if (p3<p4)
-           HMAC_Update(&c,p3,(size_t)p4-(size_t)p3);
-       }
-    else
-       HMAC_Update(&c,p3,(size_t)p4-(size_t)p3);
-
-    HMAC_Final(&c,sig,&len);
-    HMAC_CTX_cleanup(&c);
-
-    return len;
-    }
-
-int FIPS_check_incore_fingerprint(void)
-    {
-    unsigned char sig[EVP_MAX_MD_SIZE];
-    unsigned int len;
-#if defined(__sgi) && (defined(__mips) || defined(mips))
-    extern int __dso_displacement[];
-#else
-    extern int OPENSSL_NONPIC_relocated;
-#endif
-
-    if (FIPS_text_start()==NULL)
-       {
-       FIPSerr(FIPS_F_FIPS_CHECK_INCORE_FINGERPRINT,FIPS_R_UNSUPPORTED_PLATFORM);
-       return 0;
-       }
-
-    len=FIPS_incore_fingerprint (sig,sizeof(sig));
-
-    if (len!=sizeof(FIPS_signature) ||
-       memcmp(FIPS_signature,sig,sizeof(FIPS_signature)))
-       {
-       if (FIPS_signature>=FIPS_rodata_start && FIPS_signature<FIPS_rodata_end)
-           FIPSerr(FIPS_F_FIPS_CHECK_INCORE_FINGERPRINT,FIPS_R_FINGERPRINT_DOES_NOT_MATCH_SEGMENT_ALIASING);
-#if defined(__sgi) && (defined(__mips) || defined(mips))
-       else if (__dso_displacement!=NULL)
-#else
-       else if (OPENSSL_NONPIC_relocated)
-#endif
-           FIPSerr(FIPS_F_FIPS_CHECK_INCORE_FINGERPRINT,FIPS_R_FINGERPRINT_DOES_NOT_MATCH_NONPIC_RELOCATED);
-       else
-           FIPSerr(FIPS_F_FIPS_CHECK_INCORE_FINGERPRINT,FIPS_R_FINGERPRINT_DOES_NOT_MATCH);
-       return 0;
-       }
-
-    return 1;
-    }
-
-int FIPS_mode_set(int onoff)
-    {
-    int fips_set_owning_thread();
-    int fips_clear_owning_thread();
-    int ret = 0;
-
-    fips_w_lock();
-    fips_set_started();
-    fips_set_owning_thread();
-
-    if(onoff)
-       {
-       unsigned char buf[48];
-
-       fips_selftest_fail = 0;
-
-       /* Don't go into FIPS mode twice, just so we can do automagic
-          seeding */
-       if(FIPS_mode())
-           {
-           FIPSerr(FIPS_F_FIPS_MODE_SET,FIPS_R_FIPS_MODE_ALREADY_SET);
-           fips_selftest_fail = 1;
-           ret = 0;
-           goto end;
-           }
-
-#ifdef OPENSSL_IA32_SSE2
-       if ((OPENSSL_ia32cap & (1<<25|1<<26)) != (1<<25|1<<26))
-           {
-           FIPSerr(FIPS_F_FIPS_MODE_SET,FIPS_R_UNSUPPORTED_PLATFORM);
-           fips_selftest_fail = 1;
-           ret = 0;
-           goto end;
-           }
-#endif
-
-       if(fips_signature_witness() != FIPS_signature)
-           {
-           FIPSerr(FIPS_F_FIPS_MODE_SET,FIPS_R_CONTRADICTING_EVIDENCE);
-           fips_selftest_fail = 1;
-           ret = 0;
-           goto end;
-           }
-
-       if(!FIPS_check_incore_fingerprint())
-           {
-           fips_selftest_fail = 1;
-           ret = 0;
-           goto end;
-           }
-
-       /* Perform RNG KAT before seeding */
-       if (!FIPS_selftest_rng())
-           {
-           fips_selftest_fail = 1;
-           ret = 0;
-           goto end;
-           }
-
-       /* automagically seed PRNG if not already seeded */
-       if(!FIPS_rand_status())
-           {
-           if(RAND_bytes(buf,sizeof buf) <= 0)
-               {
-               fips_selftest_fail = 1;
-               ret = 0;
-               goto end;
-               }
-           FIPS_rand_set_key(buf,32);
-           FIPS_rand_seed(buf+32,16);
-           }
-
-       /* now switch into FIPS mode */
-       fips_set_rand_check(FIPS_rand_method());
-       RAND_set_rand_method(FIPS_rand_method());
-       if(FIPS_selftest())
-           fips_set_mode(1);
-       else
-           {
-           fips_selftest_fail = 1;
-           ret = 0;
-           goto end;
-           }
-       ret = 1;
-       goto end;
-       }
-    fips_set_mode(0);
-    fips_selftest_fail = 0;
-    ret = 1;
-end:
-    fips_clear_owning_thread();
-    fips_w_unlock();
-    return ret;
-    }
-
-void fips_w_lock(void)         { CRYPTO_w_lock(CRYPTO_LOCK_FIPS); }
-void fips_w_unlock(void)       { CRYPTO_w_unlock(CRYPTO_LOCK_FIPS); }
-void fips_r_lock(void)         { CRYPTO_r_lock(CRYPTO_LOCK_FIPS); }
-void fips_r_unlock(void)       { CRYPTO_r_unlock(CRYPTO_LOCK_FIPS); }
-
-static int fips_started = 0;
-static unsigned long fips_thread = 0;
-
-void fips_set_started(void)
-       {
-       fips_started = 1;
-       }
-
-int fips_is_started(void)
-       {
-       return fips_started;
-       }
-
-int fips_is_owning_thread(void)
-       {
-       int ret = 0;
-
-       if (fips_is_started())
-               {
-               CRYPTO_r_lock(CRYPTO_LOCK_FIPS2);
-               if (fips_thread != 0 && fips_thread == CRYPTO_thread_id())
-                       ret = 1;
-               CRYPTO_r_unlock(CRYPTO_LOCK_FIPS2);
-               }
-       return ret;
-       }
-
-int fips_set_owning_thread(void)
-       {
-       int ret = 0;
-
-       if (fips_is_started())
-               {
-               CRYPTO_w_lock(CRYPTO_LOCK_FIPS2);
-               if (fips_thread == 0)
-                       {
-                       fips_thread = CRYPTO_thread_id();
-                       ret = 1;
-                       }
-               CRYPTO_w_unlock(CRYPTO_LOCK_FIPS2);
-               }
-       return ret;
-       }
-
-int fips_clear_owning_thread(void)
-       {
-       int ret = 0;
-
-       if (fips_is_started())
-               {
-               CRYPTO_w_lock(CRYPTO_LOCK_FIPS2);
-               if (fips_thread == CRYPTO_thread_id())
-                       {
-                       fips_thread = 0;
-                       ret = 1;
-                       }
-               CRYPTO_w_unlock(CRYPTO_LOCK_FIPS2);
-               }
-       return ret;
-       }
-
-unsigned char *fips_signature_witness(void)
-       {
-       extern unsigned char FIPS_signature[];
-       return FIPS_signature;
-       }
-
-/* Generalized public key test routine. Signs and verifies the data
- * supplied in tbs using mesage digest md and setting option digest
- * flags md_flags. If the 'kat' parameter is not NULL it will
- * additionally check the signature matches it: a known answer test
- * The string "fail_str" is used for identification purposes in case
- * of failure.
- */
-
-int fips_pkey_signature_test(EVP_PKEY *pkey,
-                       const unsigned char *tbs, int tbslen,
-                       const unsigned char *kat, unsigned int katlen,
-                       const EVP_MD *digest, unsigned int md_flags,
-                       const char *fail_str)
-       {       
-       int ret = 0;
-       unsigned char sigtmp[256], *sig = sigtmp;
-       unsigned int siglen;
-       EVP_MD_CTX mctx;
-       EVP_MD_CTX_init(&mctx);
-
-       if ((pkey->type == EVP_PKEY_RSA)
-               && (RSA_size(pkey->pkey.rsa) > sizeof(sigtmp)))
-               {
-               sig = OPENSSL_malloc(RSA_size(pkey->pkey.rsa));
-               if (!sig)
-                       {
-                       FIPSerr(FIPS_F_FIPS_PKEY_SIGNATURE_TEST,ERR_R_MALLOC_FAILURE);
-                       return 0;
-                       }
-               }
-
-       if (tbslen == -1)
-               tbslen = strlen((char *)tbs);
-
-       if (md_flags)
-               M_EVP_MD_CTX_set_flags(&mctx, md_flags);
-
-       if (!EVP_SignInit_ex(&mctx, digest, NULL))
-               goto error;
-       if (!EVP_SignUpdate(&mctx, tbs, tbslen))
-               goto error;
-       if (!EVP_SignFinal(&mctx, sig, &siglen, pkey))
-               goto error;
-
-       if (kat && ((siglen != katlen) || memcmp(kat, sig, katlen)))
-               goto error;
-
-       if (!EVP_VerifyInit_ex(&mctx, digest, NULL))
-               goto error;
-       if (!EVP_VerifyUpdate(&mctx, tbs, tbslen))
-               goto error;
-       ret = EVP_VerifyFinal(&mctx, sig, siglen, pkey);
-
-       error:
-       if (sig != sigtmp)
-               OPENSSL_free(sig);
-       EVP_MD_CTX_cleanup(&mctx);
-       if (ret != 1)
-               {
-               FIPSerr(FIPS_F_FIPS_PKEY_SIGNATURE_TEST,FIPS_R_TEST_FAILURE);
-               if (fail_str)
-                       ERR_add_error_data(2, "Type=", fail_str);
-               return 0;
-               }
-       return 1;
-       }
-
-/* Generalized symmetric cipher test routine. Encrypt data, verify result
- * against known answer, decrypt and compare with original plaintext.
- */
-
-int fips_cipher_test(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
-                       const unsigned char *key,
-                       const unsigned char *iv,
-                       const unsigned char *plaintext,
-                       const unsigned char *ciphertext,
-                       int len)
-       {
-       unsigned char pltmp[FIPS_MAX_CIPHER_TEST_SIZE];
-       unsigned char citmp[FIPS_MAX_CIPHER_TEST_SIZE];
-       OPENSSL_assert(len <= FIPS_MAX_CIPHER_TEST_SIZE);
-       if (EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, 1) <= 0)
-               return 0;
-       EVP_Cipher(ctx, citmp, plaintext, len);
-       if (memcmp(citmp, ciphertext, len))
-               return 0;
-       if (EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, 0) <= 0)
-               return 0;
-       EVP_Cipher(ctx, pltmp, citmp, len);
-       if (memcmp(pltmp, plaintext, len))
-               return 0;
-       return 1;
-       }
-
-#if 0
-/* The purpose of this is to ensure the error code exists and the function
- * name is to keep the error checking script quiet
- */
-void hash_final(void)
-       {
-       FIPSerr(FIPS_F_HASH_FINAL,FIPS_R_NON_FIPS_METHOD);
-       }
-#endif
-
-
-#endif
diff --git a/deps/openssl/openssl/fips/fips.h b/deps/openssl/openssl/fips/fips.h
deleted file mode 100644 (file)
index 42bdcf2..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-/* ====================================================================
- * Copyright (c) 2003 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    openssl-core@openssl.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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 <openssl/opensslconf.h>
-
-#ifndef OPENSSL_FIPS
-#error FIPS is disabled.
-#endif
-
-#ifdef OPENSSL_FIPS
-
-#ifdef  __cplusplus
-extern "C" {
-#endif
-
-struct dsa_st;
-struct evp_pkey_st;
-struct env_md_st;
-struct evp_cipher_st;
-struct evp_cipher_ctx_st;
-
-int FIPS_mode_set(int onoff);
-int FIPS_mode(void);
-const void *FIPS_rand_check(void);
-int FIPS_selftest_failed(void);
-void FIPS_selftest_check(void);
-void FIPS_corrupt_sha1(void);
-int FIPS_selftest_sha1(void);
-void FIPS_corrupt_aes(void);
-int FIPS_selftest_aes(void);
-void FIPS_corrupt_des(void);
-int FIPS_selftest_des(void);
-void FIPS_corrupt_rsa(void);
-void FIPS_corrupt_rsa_keygen(void);
-int FIPS_selftest_rsa(void);
-void FIPS_corrupt_dsa(void);
-void FIPS_corrupt_dsa_keygen(void);
-int FIPS_selftest_dsa(void);
-void FIPS_corrupt_rng(void);
-void FIPS_rng_stick(void);
-int FIPS_selftest_rng(void);
-int FIPS_selftest_hmac(void);
-
-int fips_pkey_signature_test(struct evp_pkey_st *pkey,
-                       const unsigned char *tbs, int tbslen,
-                       const unsigned char *kat, unsigned int katlen,
-                       const struct env_md_st *digest, unsigned int md_flags,
-                       const char *fail_str);
-
-int fips_cipher_test(struct evp_cipher_ctx_st *ctx,
-                       const struct evp_cipher_st *cipher,
-                       const unsigned char *key,
-                       const unsigned char *iv,
-                       const unsigned char *plaintext,
-                       const unsigned char *ciphertext,
-                       int len);
-
-/* BEGIN ERROR CODES */
-/* The following lines are auto generated by the script mkerr.pl. Any changes
- * made after this point may be overwritten when the script is next run.
- */
-void ERR_load_FIPS_strings(void);
-
-/* Error codes for the FIPS functions. */
-
-/* Function codes. */
-#define FIPS_F_DH_BUILTIN_GENPARAMS                     100
-#define FIPS_F_DSA_BUILTIN_PARAMGEN                     101
-#define FIPS_F_DSA_DO_SIGN                              102
-#define FIPS_F_DSA_DO_VERIFY                            103
-#define FIPS_F_EVP_CIPHERINIT_EX                        124
-#define FIPS_F_EVP_DIGESTINIT_EX                        125
-#define FIPS_F_FIPS_CHECK_DSA                           104
-#define FIPS_F_FIPS_CHECK_INCORE_FINGERPRINT            105
-#define FIPS_F_FIPS_CHECK_RSA                           106
-#define FIPS_F_FIPS_DSA_CHECK                           107
-#define FIPS_F_FIPS_MODE_SET                            108
-#define FIPS_F_FIPS_PKEY_SIGNATURE_TEST                         109
-#define FIPS_F_FIPS_SELFTEST_AES                        110
-#define FIPS_F_FIPS_SELFTEST_DES                        111
-#define FIPS_F_FIPS_SELFTEST_DSA                        112
-#define FIPS_F_FIPS_SELFTEST_HMAC                       113
-#define FIPS_F_FIPS_SELFTEST_RNG                        114
-#define FIPS_F_FIPS_SELFTEST_SHA1                       115
-#define FIPS_F_HASH_FINAL                               123
-#define FIPS_F_RSA_BUILTIN_KEYGEN                       116
-#define FIPS_F_RSA_EAY_PRIVATE_DECRYPT                  117
-#define FIPS_F_RSA_EAY_PRIVATE_ENCRYPT                  118
-#define FIPS_F_RSA_EAY_PUBLIC_DECRYPT                   119
-#define FIPS_F_RSA_EAY_PUBLIC_ENCRYPT                   120
-#define FIPS_F_RSA_X931_GENERATE_KEY_EX                         121
-#define FIPS_F_SSLEAY_RAND_BYTES                        122
-
-/* Reason codes. */
-#define FIPS_R_CANNOT_READ_EXE                          103
-#define FIPS_R_CANNOT_READ_EXE_DIGEST                   104
-#define FIPS_R_CONTRADICTING_EVIDENCE                   114
-#define FIPS_R_EXE_DIGEST_DOES_NOT_MATCH                105
-#define FIPS_R_FINGERPRINT_DOES_NOT_MATCH               110
-#define FIPS_R_FINGERPRINT_DOES_NOT_MATCH_NONPIC_RELOCATED 111
-#define FIPS_R_FINGERPRINT_DOES_NOT_MATCH_SEGMENT_ALIASING 112
-#define FIPS_R_FIPS_MODE_ALREADY_SET                    102
-#define FIPS_R_FIPS_SELFTEST_FAILED                     106
-#define FIPS_R_INVALID_KEY_LENGTH                       109
-#define FIPS_R_KEY_TOO_SHORT                            108
-#define FIPS_R_NON_FIPS_METHOD                          100
-#define FIPS_R_PAIRWISE_TEST_FAILED                     107
-#define FIPS_R_RSA_DECRYPT_ERROR                        115
-#define FIPS_R_RSA_ENCRYPT_ERROR                        116
-#define FIPS_R_SELFTEST_FAILED                          101
-#define FIPS_R_TEST_FAILURE                             117
-#define FIPS_R_UNSUPPORTED_PLATFORM                     113
-
-#ifdef  __cplusplus
-}
-#endif
-#endif
diff --git a/deps/openssl/openssl/fips/fips_canister.c b/deps/openssl/openssl/fips/fips_canister.c
deleted file mode 100644 (file)
index 1744661..0000000
+++ /dev/null
@@ -1,187 +0,0 @@
-/* ====================================================================
- * Copyright (c) 2005 The OpenSSL Project. Rights for redistribution
- * and usage in source and binary forms are granted according to the
- * OpenSSL license.
- */
-
-#include <stdio.h>
-#if defined(__DECC)
-# include <c_asm.h>
-# pragma __nostandard
-#endif
-
-#include "e_os.h"
-
-#if !defined(POINTER_TO_FUNCTION_IS_POINTER_TO_1ST_INSTRUCTION)
-# if   (defined(__sun) && (defined(__sparc) || defined(__sparcv9)))    || \
-       (defined(__sgi) && (defined(__mips) || defined(mips)))          || \
-       (defined(__osf__) && defined(__alpha))                          || \
-       (defined(__linux) && (defined(__arm) || defined(__arm__)))      || \
-       (defined(__i386) || defined(__i386__))                          || \
-       (defined(__x86_64) || defined(__x86_64__))                      || \
-       defined(__ANDROID__)                                            || \
-       (defined(vax) || defined(__vax__))
-#  define POINTER_TO_FUNCTION_IS_POINTER_TO_1ST_INSTRUCTION
-# endif
-#endif
-
-#if defined(__xlC__) && __xlC__>=0x600 && (defined(_POWER) || defined(_ARCH_PPC))
-static void *instruction_pointer_xlc(void);
-# pragma mc_func instruction_pointer_xlc {\
-       "7c0802a6"      /* mflr r0  */  \
-       "48000005"      /* bl   $+4 */  \
-       "7c6802a6"      /* mflr r3  */  \
-       "7c0803a6"      /* mtlr r0  */  }
-# pragma reg_killed_by instruction_pointer_xlc gr0 gr3
-# define INSTRUCTION_POINTER_IMPLEMENTED(ret) (ret=instruction_pointer_xlc());
-#endif
-
-#ifdef FIPS_START
-#define FIPS_ref_point FIPS_text_start
-/* Some compilers put string literals into a separate segment. As we
- * are mostly interested to hash AES tables in .rodata, we declare
- * reference points accordingly. In case you wonder, the values are
- * big-endian encoded variable names, just to prevent these arrays
- * from being merged by linker. */
-const unsigned int FIPS_rodata_start[]=
-       { 0x46495053, 0x5f726f64, 0x6174615f, 0x73746172 };
-#else
-#define FIPS_ref_point FIPS_text_end
-const unsigned int FIPS_rodata_end[]=
-       { 0x46495053, 0x5f726f64, 0x6174615f, 0x656e645b };
-#endif
-
-/*
- * I declare reference function as static in order to avoid certain
- * pitfalls in -dynamic linker behaviour...
- */
-static void *instruction_pointer(void)
-{ void *ret=NULL;
-/* These are ABI-neutral CPU-specific snippets. ABI-neutrality means
- * that they are designed to work under any OS running on particular
- * CPU, which is why you don't find any #ifdef THIS_OR_THAT_OS in
- * this function. */
-#if    defined(INSTRUCTION_POINTER_IMPLEMENTED)
-    INSTRUCTION_POINTER_IMPLEMENTED(ret);
-#elif  defined(__GNUC__) && __GNUC__>=2
-# if   defined(__alpha) || defined(__alpha__)
-#   define INSTRUCTION_POINTER_IMPLEMENTED
-    __asm __volatile ( "br     %0,1f\n1:" : "=r"(ret) );
-# elif defined(__i386) || defined(__i386__)
-#   define INSTRUCTION_POINTER_IMPLEMENTED
-    __asm __volatile ( "call 1f\n1:    popl %0" : "=r"(ret) );
-    ret = (void *)((size_t)ret&~3UL); /* align for better performance */
-# elif defined(__ia64) || defined(__ia64__)
-#   define INSTRUCTION_POINTER_IMPLEMENTED
-    __asm __volatile ( "mov    %0=ip" : "=r"(ret) );
-# elif defined(__hppa) || defined(__hppa__) || defined(__pa_risc)
-#   define INSTRUCTION_POINTER_IMPLEMENTED
-    __asm __volatile ( "blr    %%r0,%0\n\tnop" : "=r"(ret) );
-    ret = (void *)((size_t)ret&~3UL); /* mask privilege level */
-# elif defined(__mips) || defined(__mips__)
-#   define INSTRUCTION_POINTER_IMPLEMENTED
-    void *scratch;
-    __asm __volatile ( "move   %1,$31\n\t"     /* save ra */
-                       "bal    .+8; nop\n\t"
-                       "move   %0,$31\n\t"
-                       "move   $31,%1"         /* restore ra */
-                       : "=r"(ret),"=r"(scratch) );
-# elif defined(__ppc__) || defined(__powerpc) || defined(__powerpc__) || \
-       defined(__POWERPC__) || defined(_POWER) || defined(__PPC__) || \
-       defined(__PPC64__) || defined(__powerpc64__)
-#   define INSTRUCTION_POINTER_IMPLEMENTED
-    void *scratch;
-    __asm __volatile ( "mfspr  %1,8\n\t"       /* save lr */
-                       "bl     $+4\n\t"
-                       "mfspr  %0,8\n\t"       /* mflr ret */
-                       "mtspr  8,%1"           /* restore lr */
-                       : "=r"(ret),"=r"(scratch) );
-# elif defined(__s390__) || defined(__s390x__)
-#   define INSTRUCTION_POINTER_IMPLEMENTED
-    __asm __volatile ( "bras   %0,1f\n1:" : "=r"(ret) );
-    ret = (void *)((size_t)ret&~3UL);
-# elif defined(__sparc) || defined(__sparc__) || defined(__sparcv9)
-#   define INSTRUCTION_POINTER_IMPLEMENTED
-    void *scratch;
-    __asm __volatile ( "mov    %%o7,%1\n\t"
-                       "call   .+8; nop\n\t"
-                       "mov    %%o7,%0\n\t"
-                       "mov    %1,%%o7"
-                       : "=r"(ret),"=r"(scratch) );
-# elif defined(__x86_64) || defined(__x86_64__)
-#   define INSTRUCTION_POINTER_IMPLEMENTED
-    __asm __volatile ( "leaq   0(%%rip),%0" : "=r"(ret) );
-    ret = (void *)((size_t)ret&~3UL); /* align for better performance */
-# endif
-#elif  defined(__DECC) && defined(__alpha)
-#   define INSTRUCTION_POINTER_IMPLEMENTED
-    ret = (void *)(size_t)asm("br %v0,1f\n1:");
-#elif   defined(_MSC_VER) && defined(_M_IX86)
-#   define INSTRUCTION_POINTER_IMPLEMENTED
-    void *scratch;
-    _asm {
-            call    self
-    self:   pop     eax
-            mov     scratch,eax
-         }
-    ret = (void *)((size_t)scratch&~3UL);
-#endif
-  return ret;
-}
-
-/*
- * This function returns pointer to an instruction in the vicinity of
- * its entry point, but not outside this object module. This guarantees
- * that sequestered code is covered...
- */
-void *FIPS_ref_point()
-{
-#if    defined(INSTRUCTION_POINTER_IMPLEMENTED)
-    return instruction_pointer();
-/* Below we essentially cover vendor compilers which do not support
- * inline assembler... */
-#elif  defined(_AIX)
-    struct { void *ip,*gp,*env; } *p = (void *)instruction_pointer;
-    return p->ip;
-#elif  defined(_HPUX_SOURCE)
-# if   defined(__hppa) || defined(__hppa__)
-    struct { void *i[4]; } *p = (void *)FIPS_ref_point;
-
-    if (sizeof(p) == 8)        /* 64-bit */
-       return p->i[2];
-    else if ((size_t)p & 2)
-    {  p = (void *)((size_t)p&~3UL);
-       return p->i[0];
-    }
-    else
-       return (void *)p;
-# elif defined(__ia64) || defined(__ia64__)
-    struct { unsigned long long ip,gp; } *p=(void *)instruction_pointer;
-    return (void *)(size_t)p->ip;
-# endif
-#elif  (defined(__VMS) || defined(VMS)) && !(defined(vax) || defined(__vax__))
-    /* applies to both alpha and ia64 */
-    struct { unsigned __int64 opaque,ip; } *p=(void *)instruction_pointer;
-    return (void *)(size_t)p->ip;
-#elif  defined(__VOS__)
-    /* applies to both pa-risc and ia32 */
-    struct { void *dp,*ip,*gp; } *p = (void *)instruction_pointer;
-    return p->ip;
-#elif  defined(_WIN32)
-# if   defined(_WIN64) && defined(_M_IA64)
-    struct { void *ip,*gp; } *p = (void *)FIPS_ref_point;
-    return p->ip;
-# else
-    return (void *)FIPS_ref_point;
-# endif
-/*
- * In case you wonder why there is no #ifdef __linux. All Linux targets
- * are GCC-based and therefore are covered by instruction_pointer above
- * [well, some are covered by by the one below]...
- */ 
-#elif  defined(POINTER_TO_FUNCTION_IS_POINTER_TO_1ST_INSTRUCTION)
-    return (void *)instruction_pointer;
-#else
-    return NULL;
-#endif
-}
diff --git a/deps/openssl/openssl/fips/fips_premain.c b/deps/openssl/openssl/fips/fips_premain.c
deleted file mode 100644 (file)
index 165d2c5..0000000
+++ /dev/null
@@ -1,176 +0,0 @@
-/* ====================================================================
- * Copyright (c) 2005 The OpenSSL Project. Rights for redistribution
- * and usage in source and binary forms are granted according to the
- * OpenSSL license.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#if defined(__unix) || defined(__unix__)
-#include <unistd.h>
-#endif
-
-#ifndef FINGERPRINT_PREMAIN_DSO_LOAD
-
-#if defined(__GNUC__) && __GNUC__>=2
-  void FINGERPRINT_premain(void) __attribute__((constructor));
-  /* Most commonly this results in pointer to premain to be dropped
-   * to .ctors segment, which is traversed by GCC crtbegin.o upon
-   * program startup. Except on a.out OpenBSD where it results in
-   * _GLOBAL_$I$premain() {premain();} being auto-generated by
-   * compiler... But one way or another this is believed to cover
-   * *all* GCC targets. */
-#elif defined(_MSC_VER)
-# ifdef _WINDLL
-  __declspec(dllexport)        /* this is essentially cosmetics... */
-# endif
-  void FINGERPRINT_premain(void);
-  static int premain_wrapper(void) { FINGERPRINT_premain(); return 0; }
-# ifdef _WIN64
-# pragma section(".CRT$XCU",read)
-  __declspec(allocate(".CRT$XCU"))
-# else
-# pragma data_seg(".CRT$XCU")
-# endif
-  static int (*p)(void) = premain_wrapper;
-  /* This results in pointer to premain to appear in .CRT segment,
-   * which is traversed by Visual C run-time initialization code.
-   * This applies to both Win32 and [all flavors of] Win64. */
-# pragma data_seg()
-#elif defined(__SUNPRO_C)
-  void FINGERPRINT_premain(void);
-# pragma init(FINGERPRINT_premain)
-  /* This results in a call to premain to appear in .init segment. */
-#elif defined(__DECC) && (defined(__VMS) || defined(VMS))
-  void FINGERPRINT_premain(void);
-# pragma __nostandard
-  globaldef { "LIB$INITIALIZ" } readonly _align (LONGWORD)
-       int spare[8] = {0};
-  globaldef { "LIB$INITIALIZE" } readonly _align (LONGWORD)
-       void (*x_FINGERPRINT_premain)(void) = FINGERPRINT_premain;
-  /* Refer to LIB$INITIALIZE to ensure it exists in the image. */
-  int lib$initialize();
-  globaldef int (*lib_init_ref)() = lib$initialize;
-# pragma __standard
-#elif 0
-  The rest has to be taken care of through command line:
-
-       -Wl,-init,FINGERPRINT_premain           on OSF1 and IRIX
-       -Wl,+init,FINGERPRINT_premain           on HP-UX
-       -Wl,-binitfini:FINGERPRINT_premain      on AIX
-
-  On ELF platforms this results in a call to premain to appear in
-  .init segment...
-#endif
-
-#ifndef HMAC_SHA1_SIG
-#define HMAC_SHA1_SIG "?have to make sure this string is unique"
-#endif
-
-static const unsigned char FINGERPRINT_ascii_value[40] = HMAC_SHA1_SIG;
-
-#define atox(c) ((c)>='a'?((c)-'a'+10):((c)>='A'?(c)-'A'+10:(c)-'0'))
-
-extern const void         *FIPS_text_start(),  *FIPS_text_end();
-extern const unsigned char FIPS_rodata_start[], FIPS_rodata_end[];
-extern unsigned char       FIPS_signature[20];
-extern unsigned int        FIPS_incore_fingerprint(unsigned char *,unsigned int);
-
-/*
- * As name suggests this code is executed prior main(). We use this
- * opportunity to fingerprint sequestered code in virtual address
- * space of target application.
- */
-void FINGERPRINT_premain(void)
-{ unsigned char sig[sizeof(FIPS_signature)];
-  const unsigned char * volatile p=FINGERPRINT_ascii_value;
-  unsigned int len=sizeof(sig),i;
-
-    /* "volatilization" is done to disengage unwanted optimization... */
-    if (*((volatile unsigned char *)p)=='?')
-    {  if (FIPS_text_start()==NULL)
-       {   fprintf(stderr,"FIPS_text_start() returns NULL\n");
-           _exit(1);
-       }
-#if defined(DEBUG_FINGERPRINT_PREMAIN)
-       fprintf(stderr,".text:%p+%d=%p\n",FIPS_text_start(),
-               (int)((size_t)FIPS_text_end()-(size_t)FIPS_text_start()),
-               FIPS_text_end());
-       fprintf(stderr,".rodata:%p+%d=%p\n",FIPS_rodata_start,
-               (int)((size_t)FIPS_rodata_end-(size_t)FIPS_rodata_start),
-               FIPS_rodata_end);
-#endif
-
-       len=FIPS_incore_fingerprint(sig,sizeof(sig));
-
-       if (len!=sizeof(sig))
-       {   fprintf(stderr,"fingerprint length mismatch: %u\n",len);
-           _exit(1);
-       }
-
-       for (i=0;i<len;i++) printf("%02x",sig[i]);
-       printf("\n");
-       fflush(stdout);
-       _exit(0);
-    }
-    else if (FIPS_signature[0]=='\0') do
-    {  for (i=0;i<sizeof(FIPS_signature);i++,p+=2)
-           FIPS_signature[i] = (atox(p[0])<<4)|atox(p[1]);
-
-#if defined(DEBUG_FINGERPRINT_PREMAIN)
-       if (getenv("OPENSSL_FIPS")==NULL) break;
-
-       len=FIPS_incore_fingerprint(sig,sizeof(sig));
-
-       if (memcmp(FIPS_signature,sig,sizeof(FIPS_signature)))
-       {   fprintf(stderr,"FINGERPRINT_premain: FIPS_signature mismatch\n");
-           _exit(1);
-       }
-#endif
-    } while(0);
-}
-
-#else
-
-#include <openssl/bio.h>
-#include <openssl/dso.h>
-#include <openssl/err.h>
-
-int main(int argc,char *argv[])
-{ DSO *dso;
-  DSO_FUNC_TYPE func;
-  BIO *bio_err;
-
-    if (argc < 2)
-    {  fprintf (stderr,"usage: %s libcrypto.dso\n",argv[0]);
-       return 1;
-    }
-
-    if ((bio_err=BIO_new(BIO_s_file())) == NULL)
-    {  fprintf (stderr,"unable to allocate BIO\n");
-       return 1;
-    }
-    BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
-    ERR_load_crypto_strings();
-
-    dso = DSO_load(NULL,argv[1],NULL,DSO_FLAG_NO_NAME_TRANSLATION);
-    if (dso == NULL)
-    {  ERR_print_errors(bio_err);
-       return 1;
-    }
-
-    /* This is not normally reached, because FINGERPRINT_premain should
-     * have executed and terminated application already upon DSO_load... */
-    func = DSO_bind_func(dso,"FINGERPRINT_premain");
-    if (func == NULL)
-    {  ERR_print_errors(bio_err);
-       return 1;
-    }
-
-    (*func)();
-
-  return 0;
-}
-
-#endif
diff --git a/deps/openssl/openssl/fips/fips_premain.c.sha1 b/deps/openssl/openssl/fips/fips_premain.c.sha1
deleted file mode 100644 (file)
index c16f964..0000000
+++ /dev/null
@@ -1 +0,0 @@
-HMAC-SHA1(fips_premain.c)= 9e5ddba185ac446e0cf36fcf8e1b3acffe5d0b2c
diff --git a/deps/openssl/openssl/fips/fips_test_suite.c b/deps/openssl/openssl/fips/fips_test_suite.c
deleted file mode 100644 (file)
index 2bc0ba9..0000000
+++ /dev/null
@@ -1,579 +0,0 @@
-/* ====================================================================
- * Copyright (c) 2003 The OpenSSL Project.  All rights reserved.
- *
- *
- * This command is intended as a test driver for the FIPS-140 testing
- * lab performing FIPS-140 validation.  It demonstrates the use of the
- * OpenSSL library ito perform a variety of common cryptographic
- * functions.  A power-up self test is demonstrated by deliberately
- * pointing to an invalid executable hash
- *
- * Contributed by Steve Marquess.
- *
- */
-#include <stdio.h>
-#include <assert.h>
-#include <ctype.h>
-#include <string.h>
-#include <stdlib.h>
-#include <openssl/aes.h>
-#include <openssl/des.h>
-#include <openssl/hmac.h>
-#include <openssl/err.h>
-
-#include <openssl/bn.h>
-#include <openssl/rand.h>
-#include <openssl/sha.h>
-
-
-#ifndef OPENSSL_FIPS
-int main(int argc, char *argv[])
-    {
-    printf("No FIPS support\n");
-    return(0);
-    }
-#else
-
-#include <openssl/rsa.h>
-#include <openssl/dsa.h>
-#include <openssl/dh.h>
-
-#include <openssl/fips.h>
-#include "fips_utl.h"
-
-/* AES: encrypt and decrypt known plaintext, verify result matches original plaintext
-*/
-static int FIPS_aes_test(void)
-       {
-       int ret = 0;
-       unsigned char pltmp[16];
-       unsigned char citmp[16];
-       unsigned char key[16] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
-       unsigned char plaintext[16] = "etaonrishdlcu";
-       EVP_CIPHER_CTX ctx;
-       EVP_CIPHER_CTX_init(&ctx);
-       if (EVP_CipherInit_ex(&ctx, EVP_aes_128_ecb(),NULL, key, NULL, 1) <= 0)
-               goto err;
-       EVP_Cipher(&ctx, citmp, plaintext, 16);
-       if (EVP_CipherInit_ex(&ctx, EVP_aes_128_ecb(),NULL, key, NULL, 0) <= 0)
-               goto err;
-       EVP_Cipher(&ctx, pltmp, citmp, 16);
-       if (memcmp(pltmp, plaintext, 16))
-               goto err;
-       ret = 1;
-       err:
-       EVP_CIPHER_CTX_cleanup(&ctx);
-       return ret;
-       }
-
-static int FIPS_des3_test(void)
-       {
-       int ret = 0;
-       unsigned char pltmp[8];
-       unsigned char citmp[8];
-       unsigned char key[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,
-                             19,20,21,22,23,24};
-       unsigned char plaintext[] = { 'e', 't', 'a', 'o', 'n', 'r', 'i', 's' };
-       EVP_CIPHER_CTX ctx;
-       EVP_CIPHER_CTX_init(&ctx);
-       if (EVP_CipherInit_ex(&ctx, EVP_des_ede3_ecb(),NULL, key, NULL, 1) <= 0)
-               goto err;
-       EVP_Cipher(&ctx, citmp, plaintext, 8);
-       if (EVP_CipherInit_ex(&ctx, EVP_des_ede3_ecb(),NULL, key, NULL, 0) <= 0)
-               goto err;
-       EVP_Cipher(&ctx, pltmp, citmp, 8);
-       if (memcmp(pltmp, plaintext, 8))
-               goto err;
-       ret = 1;
-       err:
-       EVP_CIPHER_CTX_cleanup(&ctx);
-       return ret;
-       }
-
-/*
- * DSA: generate keys and sign, verify input plaintext.
- */
-static int FIPS_dsa_test(int bad)
-    {
-    DSA *dsa = NULL;
-    EVP_PKEY pk;
-    unsigned char dgst[] = "etaonrishdlc";
-    unsigned char buf[60];
-    unsigned int slen;
-    int r = 0;
-    EVP_MD_CTX mctx;
-
-    ERR_clear_error();
-    EVP_MD_CTX_init(&mctx);
-    dsa = FIPS_dsa_new();
-    if (!dsa)
-       goto end;
-    if (!DSA_generate_parameters_ex(dsa, 1024,NULL,0,NULL,NULL,NULL))
-       goto end;
-    if (!DSA_generate_key(dsa))
-       goto end;
-    if (bad)
-           BN_add_word(dsa->pub_key, 1);
-
-    pk.type = EVP_PKEY_DSA;
-    pk.pkey.dsa = dsa;
-
-    if (!EVP_SignInit_ex(&mctx, EVP_dss1(), NULL))
-       goto end;
-    if (!EVP_SignUpdate(&mctx, dgst, sizeof(dgst) - 1))
-       goto end;
-    if (!EVP_SignFinal(&mctx, buf, &slen, &pk))
-       goto end;
-
-    if (!EVP_VerifyInit_ex(&mctx, EVP_dss1(), NULL))
-       goto end;
-    if (!EVP_VerifyUpdate(&mctx, dgst, sizeof(dgst) - 1))
-       goto end;
-    r = EVP_VerifyFinal(&mctx, buf, slen, &pk);
-    end:
-    EVP_MD_CTX_cleanup(&mctx);
-    if (dsa)
-         FIPS_dsa_free(dsa);
-    if (r != 1)
-       return 0;
-    return 1;
-    }
-
-/*
- * RSA: generate keys and sign, verify input plaintext.
- */
-static int FIPS_rsa_test(int bad)
-    {
-    RSA *key;
-    unsigned char input_ptext[] = "etaonrishdlc";
-    unsigned char buf[256];
-    unsigned int slen;
-    BIGNUM *bn;
-    EVP_MD_CTX mctx;
-    EVP_PKEY pk;
-    int r = 0;
-
-    ERR_clear_error();
-    EVP_MD_CTX_init(&mctx);
-    key = FIPS_rsa_new();
-    bn = BN_new();
-    if (!key || !bn)
-       return 0;
-    BN_set_word(bn, 65537);
-    if (!RSA_generate_key_ex(key, 1024,bn,NULL))
-       return 0;
-    BN_free(bn);
-    if (bad)
-           BN_add_word(key->n, 1);
-
-    pk.type = EVP_PKEY_RSA;
-    pk.pkey.rsa = key;
-
-    if (!EVP_SignInit_ex(&mctx, EVP_sha1(), NULL))
-       goto end;
-    if (!EVP_SignUpdate(&mctx, input_ptext, sizeof(input_ptext) - 1))
-       goto end;
-    if (!EVP_SignFinal(&mctx, buf, &slen, &pk))
-       goto end;
-
-    if (!EVP_VerifyInit_ex(&mctx, EVP_sha1(), NULL))
-       goto end;
-    if (!EVP_VerifyUpdate(&mctx, input_ptext, sizeof(input_ptext) - 1))
-       goto end;
-    r = EVP_VerifyFinal(&mctx, buf, slen, &pk);
-    end:
-    EVP_MD_CTX_cleanup(&mctx);
-    if (key)
-         FIPS_rsa_free(key);
-    if (r != 1)
-       return 0;
-    return 1;
-    }
-
-/* SHA1: generate hash of known digest value and compare to known
-   precomputed correct hash
-*/
-static int FIPS_sha1_test()
-    {
-    unsigned char digest[SHA_DIGEST_LENGTH] =
-        { 0x11, 0xf1, 0x9a, 0x3a, 0xec, 0x1a, 0x1e, 0x8e, 0x65, 0xd4, 0x9a, 0x38, 0x0c, 0x8b, 0x1e, 0x2c, 0xe8, 0xb3, 0xc5, 0x18 };
-    unsigned char str[] = "etaonrishd";
-
-    unsigned char md[SHA_DIGEST_LENGTH];
-
-    ERR_clear_error();
-    if (!EVP_Digest(str,sizeof(str) - 1,md, NULL, EVP_sha1(), NULL)) return 0;
-    if (memcmp(md,digest,sizeof(md)))
-        return 0;
-    return 1;
-    }
-
-/* SHA256: generate hash of known digest value and compare to known
-   precomputed correct hash
-*/
-static int FIPS_sha256_test()
-    {
-    unsigned char digest[SHA256_DIGEST_LENGTH] =
-       {0xf5, 0x53, 0xcd, 0xb8, 0xcf, 0x1, 0xee, 0x17, 0x9b, 0x93, 0xc9, 0x68, 0xc0, 0xea, 0x40, 0x91,
-        0x6, 0xec, 0x8e, 0x11, 0x96, 0xc8, 0x5d, 0x1c, 0xaf, 0x64, 0x22, 0xe6, 0x50, 0x4f, 0x47, 0x57};
-    unsigned char str[] = "etaonrishd";
-
-    unsigned char md[SHA256_DIGEST_LENGTH];
-
-    ERR_clear_error();
-    if (!EVP_Digest(str,sizeof(str) - 1,md, NULL, EVP_sha256(), NULL)) return 0;
-    if (memcmp(md,digest,sizeof(md)))
-        return 0;
-    return 1;
-    }
-
-/* SHA512: generate hash of known digest value and compare to known
-   precomputed correct hash
-*/
-static int FIPS_sha512_test()
-    {
-    unsigned char digest[SHA512_DIGEST_LENGTH] =
-       {0x99, 0xc9, 0xe9, 0x5b, 0x88, 0xd4, 0x78, 0x88, 0xdf, 0x88, 0x5f, 0x94, 0x71, 0x64, 0x28, 0xca,
-        0x16, 0x1f, 0x3d, 0xf4, 0x1f, 0xf3, 0x0f, 0xc5, 0x03, 0x99, 0xb2, 0xd0, 0xe7, 0x0b, 0x94, 0x4a,
-        0x45, 0xd2, 0x6c, 0x4f, 0x20, 0x06, 0xef, 0x71, 0xa9, 0x25, 0x7f, 0x24, 0xb1, 0xd9, 0x40, 0x22,
-        0x49, 0x54, 0x10, 0xc2, 0x22, 0x9d, 0x27, 0xfe, 0xbd, 0xd6, 0xd6, 0xeb, 0x2d, 0x42, 0x1d, 0xa3};
-    unsigned char str[] = "etaonrishd";
-
-    unsigned char md[SHA512_DIGEST_LENGTH];
-
-    ERR_clear_error();
-    if (!EVP_Digest(str,sizeof(str) - 1,md, NULL, EVP_sha512(), NULL)) return 0;
-    if (memcmp(md,digest,sizeof(md)))
-        return 0;
-    return 1;
-    }
-
-/* HMAC-SHA1: generate hash of known digest value and compare to known
-   precomputed correct hash
-*/
-static int FIPS_hmac_sha1_test()
-    {
-    unsigned char key[] = "etaonrishd";
-    unsigned char iv[] = "Sample text";
-    unsigned char kaval[EVP_MAX_MD_SIZE] =
-       {0x73, 0xf7, 0xa0, 0x48, 0xf8, 0x94, 0xed, 0xdd, 0x0a, 0xea, 0xea, 0x56, 0x1b, 0x61, 0x2e, 0x70,
-        0xb2, 0xfb, 0xec, 0xc6};
-
-    unsigned char out[EVP_MAX_MD_SIZE];
-    unsigned int outlen;
-
-    ERR_clear_error();
-    if (!HMAC(EVP_sha1(),key,sizeof(key)-1,iv,sizeof(iv)-1,out,&outlen)) return 0;
-    if (memcmp(out,kaval,outlen))
-        return 0;
-    return 1;
-    }
-
-/* HMAC-SHA224: generate hash of known digest value and compare to known
-   precomputed correct hash
-*/
-static int FIPS_hmac_sha224_test()
-    {
-    unsigned char key[] = "etaonrishd";
-    unsigned char iv[] = "Sample text";
-    unsigned char kaval[EVP_MAX_MD_SIZE] =
-       {0x75, 0x58, 0xd5, 0xbd, 0x55, 0x6d, 0x87, 0x0f, 0x75, 0xff, 0xbe, 0x1c, 0xb2, 0xf0, 0x20, 0x35,
-        0xe5, 0x62, 0x49, 0xb6, 0x94, 0xb9, 0xfc, 0x65, 0x34, 0x33, 0x3a, 0x19};
-
-    unsigned char out[EVP_MAX_MD_SIZE];
-    unsigned int outlen;
-
-    ERR_clear_error();
-    if (!HMAC(EVP_sha224(),key,sizeof(key)-1,iv,sizeof(iv)-1,out,&outlen)) return 0;
-    if (memcmp(out,kaval,outlen))
-        return 0;
-    return 1;
-    }
-
-/* HMAC-SHA256: generate hash of known digest value and compare to known
-   precomputed correct hash
-*/
-static int FIPS_hmac_sha256_test()
-    {
-    unsigned char key[] = "etaonrishd";
-    unsigned char iv[] = "Sample text";
-    unsigned char kaval[EVP_MAX_MD_SIZE] =
-       {0xe9, 0x17, 0xc1, 0x7b, 0x4c, 0x6b, 0x77, 0xda, 0xd2, 0x30, 0x36, 0x02, 0xf5, 0x72, 0x33, 0x87,
-        0x9f, 0xc6, 0x6e, 0x7b, 0x7e, 0xa8, 0xea, 0xaa, 0x9f, 0xba, 0xee, 0x51, 0xff, 0xda, 0x24, 0xf4};
-
-    unsigned char out[EVP_MAX_MD_SIZE];
-    unsigned int outlen;
-
-    ERR_clear_error();
-    if (!HMAC(EVP_sha256(),key,sizeof(key)-1,iv,sizeof(iv)-1,out,&outlen)) return 0;
-    if (memcmp(out,kaval,outlen))
-        return 0;
-    return 1;
-    }
-
-/* HMAC-SHA384: generate hash of known digest value and compare to known
-   precomputed correct hash
-*/
-static int FIPS_hmac_sha384_test()
-    {
-    unsigned char key[] = "etaonrishd";
-    unsigned char iv[] = "Sample text";
-    unsigned char kaval[EVP_MAX_MD_SIZE] =
-       {0xb2, 0x9d, 0x40, 0x58, 0x32, 0xc4, 0xe3, 0x31, 0xb6, 0x63, 0x08, 0x26, 0x99, 0xef, 0x3b, 0x10,
-        0xe2, 0xdf, 0xf8, 0xff, 0xc6, 0xe1, 0x03, 0x29, 0x81, 0x2a, 0x1b, 0xac, 0xb0, 0x07, 0x39, 0x08,
-        0xf3, 0x91, 0x35, 0x11, 0x76, 0xd6, 0x4c, 0x20, 0xfb, 0x4d, 0xc3, 0xf3, 0xb8, 0x9b, 0x88, 0x1c};
-
-    unsigned char out[EVP_MAX_MD_SIZE];
-    unsigned int outlen;
-
-    ERR_clear_error();
-    if (!HMAC(EVP_sha384(),key,sizeof(key)-1,iv,sizeof(iv)-1,out,&outlen)) return 0;
-    if (memcmp(out,kaval,outlen))
-        return 0;
-    return 1;
-    }
-
-/* HMAC-SHA512: generate hash of known digest value and compare to known
-   precomputed correct hash
-*/
-static int FIPS_hmac_sha512_test()
-    {
-    unsigned char key[] = "etaonrishd";
-    unsigned char iv[] = "Sample text";
-    unsigned char kaval[EVP_MAX_MD_SIZE] =
-       {0xcd, 0x3e, 0xb9, 0x51, 0xb8, 0xbc, 0x7f, 0x9a, 0x23, 0xaf, 0xf3, 0x77, 0x59, 0x85, 0xa9, 0xe6,
-        0xf7, 0xd1, 0x51, 0x96, 0x17, 0xe0, 0x92, 0xd8, 0xa6, 0x3b, 0xc1, 0xad, 0x7e, 0x24, 0xca, 0xb1,
-        0xd7, 0x79, 0x0a, 0xa5, 0xea, 0x2c, 0x02, 0x58, 0x0b, 0xa6, 0x52, 0x6b, 0x61, 0x7f, 0xeb, 0x9c,
-        0x47, 0x86, 0x5d, 0x74, 0x2b, 0x88, 0xdf, 0xee, 0x46, 0x69, 0x96, 0x3d, 0xa6, 0xd9, 0x2a, 0x53};
-
-    unsigned char out[EVP_MAX_MD_SIZE];
-    unsigned int outlen;
-
-    ERR_clear_error();
-    if (!HMAC(EVP_sha512(),key,sizeof(key)-1,iv,sizeof(iv)-1,out,&outlen)) return 0;
-    if (memcmp(out,kaval,outlen))
-        return 0;
-    return 1;
-    }
-
-
-/* DH: generate shared parameters
-*/
-static int dh_test()
-    {
-    DH *dh;
-    ERR_clear_error();
-    dh = FIPS_dh_new();
-    if (!dh)
-       return 0;
-    if (!DH_generate_parameters_ex(dh, 1024, 2, NULL))
-       return 0;
-    FIPS_dh_free(dh);
-    return 1;
-    }
-
-/* Zeroize
-*/
-static int Zeroize()
-    {
-    RSA *key;
-    BIGNUM *bn;
-    unsigned char userkey[16] = 
-       { 0x48, 0x50, 0xf0, 0xa3, 0x3a, 0xed, 0xd3, 0xaf, 0x6e, 0x47, 0x7f, 0x83, 0x02, 0xb1, 0x09, 0x68 };
-    size_t i;
-    int n;
-
-    key = FIPS_rsa_new();
-    bn = BN_new();
-    if (!key || !bn)
-       return 0;
-    BN_set_word(bn, 65537);
-    if (!RSA_generate_key_ex(key, 1024,bn,NULL))
-       return 0;
-    BN_free(bn);
-    
-    n = BN_num_bytes(key->d);
-    printf(" Generated %d byte RSA private key\n", n);
-    printf("\tBN key before overwriting:\n");
-    do_bn_print(stdout, key->d);
-    BN_rand(key->d,n*8,-1,0);
-    printf("\tBN key after overwriting:\n");
-    do_bn_print(stdout, key->d);
-
-    printf("\tchar buffer key before overwriting: \n\t\t");
-    for(i = 0; i < sizeof(userkey); i++) printf("%02x", userkey[i]);
-        printf("\n");
-    RAND_bytes(userkey, sizeof userkey);
-    printf("\tchar buffer key after overwriting: \n\t\t");
-    for(i = 0; i < sizeof(userkey); i++) printf("%02x", userkey[i]);
-        printf("\n");
-
-    return 1;
-    }
-
-static int Error;
-static const char * Fail(const char *msg)
-    {
-    do_print_errors();
-    Error++;
-    return msg; 
-    }
-
-static void test_msg(const char *msg, int result)
-       {
-       printf("%s...%s\n", msg, result ? "successful" : Fail("Failed!"));
-       }
-
-int main(int argc,char **argv)
-    {
-
-    int do_corrupt_rsa_keygen = 0, do_corrupt_dsa_keygen = 0;
-    int bad_rsa = 0, bad_dsa = 0;
-    int do_rng_stick = 0;
-    int no_exit = 0;
-
-    printf("\tFIPS-mode test application\n\n");
-
-    /* Load entropy from external file, if any */
-    RAND_load_file(".rnd", 1024);
-
-    if (argv[1]) {
-        /* Corrupted KAT tests */
-        if (!strcmp(argv[1], "aes")) {
-            FIPS_corrupt_aes();
-            printf("AES encryption/decryption with corrupted KAT...\n");
-        } else if (!strcmp(argv[1], "des")) {
-            FIPS_corrupt_des();
-            printf("DES3-ECB encryption/decryption with corrupted KAT...\n");
-        } else if (!strcmp(argv[1], "dsa")) {
-            FIPS_corrupt_dsa();
-            printf("DSA key generation and signature validation with corrupted KAT...\n");
-        } else if (!strcmp(argv[1], "rsa")) {
-            FIPS_corrupt_rsa();
-            printf("RSA key generation and signature validation with corrupted KAT...\n");
-        } else if (!strcmp(argv[1], "rsakey")) {
-            printf("RSA key generation and signature validation with corrupted key...\n");
-           bad_rsa = 1;
-           no_exit = 1;
-        } else if (!strcmp(argv[1], "rsakeygen")) {
-           do_corrupt_rsa_keygen = 1;
-           no_exit = 1;
-            printf("RSA key generation and signature validation with corrupted keygen...\n");
-        } else if (!strcmp(argv[1], "dsakey")) {
-            printf("DSA key generation and signature validation with corrupted key...\n");
-           bad_dsa = 1;
-           no_exit = 1;
-        } else if (!strcmp(argv[1], "dsakeygen")) {
-           do_corrupt_dsa_keygen = 1;
-           no_exit = 1;
-            printf("DSA key generation and signature validation with corrupted keygen...\n");
-        } else if (!strcmp(argv[1], "sha1")) {
-            FIPS_corrupt_sha1();
-            printf("SHA-1 hash with corrupted KAT...\n");
-       } else if (!strcmp(argv[1], "rng")) {
-           FIPS_corrupt_rng();
-       } else if (!strcmp(argv[1], "rngstick")) {
-           do_rng_stick = 1;
-           no_exit = 1;
-           printf("RNG test with stuck continuous test...\n");
-        } else {
-            printf("Bad argument \"%s\"\n", argv[1]);
-            exit(1);
-        }
-       if (!no_exit) {
-               if (!FIPS_mode_set(1)) {
-                   do_print_errors();
-                   printf("Power-up self test failed\n");
-                   exit(1);
-               }
-               printf("Power-up self test successful\n");
-               exit(0);
-       }
-    }
-
-    /* Non-Approved cryptographic operation
-    */
-    printf("1. Non-Approved cryptographic operation test...\n");
-    test_msg("\ta. Included algorithm (D-H)...", dh_test());
-
-    /* Power-up self test
-    */
-    ERR_clear_error();
-    test_msg("2. Automatic power-up self test", FIPS_mode_set(1));
-    if (!FIPS_mode())
-       exit(1);
-    if (do_corrupt_dsa_keygen)
-            FIPS_corrupt_dsa_keygen();
-    if (do_corrupt_rsa_keygen)
-            FIPS_corrupt_rsa_keygen();
-    if (do_rng_stick)
-            FIPS_rng_stick();
-
-    /* AES encryption/decryption
-    */
-    test_msg("3. AES encryption/decryption", FIPS_aes_test());
-
-    /* RSA key generation and encryption/decryption
-    */
-    test_msg("4. RSA key generation and encryption/decryption",
-                                               FIPS_rsa_test(bad_rsa));
-
-    /* DES-CBC encryption/decryption
-    */
-    test_msg("5. DES-ECB encryption/decryption", FIPS_des3_test());
-
-    /* DSA key generation and signature validation
-    */
-    test_msg("6. DSA key generation and signature validation",
-                                               FIPS_dsa_test(bad_dsa));
-
-    /* SHA-1 hash
-    */
-    test_msg("7a. SHA-1 hash", FIPS_sha1_test());
-
-    /* SHA-256 hash
-    */
-    test_msg("7b. SHA-256 hash", FIPS_sha256_test());
-
-    /* SHA-512 hash
-    */
-    test_msg("7c. SHA-512 hash", FIPS_sha512_test());
-
-    /* HMAC-SHA-1 hash
-    */
-    test_msg("7d. HMAC-SHA-1 hash", FIPS_hmac_sha1_test());
-
-    /* HMAC-SHA-224 hash
-    */
-    test_msg("7e. HMAC-SHA-224 hash", FIPS_hmac_sha224_test());
-
-    /* HMAC-SHA-256 hash
-    */
-    test_msg("7f. HMAC-SHA-256 hash", FIPS_hmac_sha256_test());
-
-    /* HMAC-SHA-384 hash
-    */
-    test_msg("7g. HMAC-SHA-384 hash", FIPS_hmac_sha384_test());
-
-    /* HMAC-SHA-512 hash
-    */
-    test_msg("7h. HMAC-SHA-512 hash", FIPS_hmac_sha512_test());
-
-    /* Non-Approved cryptographic operation
-    */
-    printf("8. Non-Approved cryptographic operation test...\n");
-    printf("\ta. Included algorithm (D-H)...%s\n",
-               dh_test() ? "successful as expected"
-                                               : Fail("failed INCORRECTLY!") );
-
-    /* Zeroization
-    */
-    printf("9. Zero-ization...\n\t%s\n",
-               Zeroize() ? "successful as expected"
-                                       : Fail("failed INCORRECTLY!") );
-
-    printf("\nAll tests completed with %d errors\n", Error);
-    return Error ? 1 : 0;
-    }
-
-#endif
diff --git a/deps/openssl/openssl/fips/fips_utl.h b/deps/openssl/openssl/fips/fips_utl.h
deleted file mode 100644 (file)
index 85d9e12..0000000
+++ /dev/null
@@ -1,359 +0,0 @@
-/* ====================================================================
- * Copyright (c) 2007 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    openssl-core@openssl.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
- *
- */
-
-void do_print_errors(void);
-int hex2bin(const char *in, unsigned char *out);
-unsigned char *hex2bin_m(const char *in, long *plen);
-int do_hex2bn(BIGNUM **pr, const char *in);
-int do_bn_print(FILE *out, BIGNUM *bn);
-int do_bn_print_name(FILE *out, const char *name, BIGNUM *bn);
-int parse_line(char **pkw, char **pval, char *linebuf, char *olinebuf);
-BIGNUM *hex2bn(const char *in);
-int bin2hex(const unsigned char *in,int len,char *out);
-void pv(const char *tag,const unsigned char *val,int len);
-int tidy_line(char *linebuf, char *olinebuf);
-int bint2bin(const char *in, int len, unsigned char *out);
-int bin2bint(const unsigned char *in,int len,char *out);
-void PrintValue(char *tag, unsigned char *val, int len);
-void OutputValue(char *tag, unsigned char *val, int len, FILE *rfp,int bitmode);
-
-void do_print_errors(void)
-       {
-       const char *file, *data;
-       int line, flags;
-       unsigned long l;
-       while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)))
-               {
-               fprintf(stderr, "ERROR:%lx:lib=%d,func=%d,reason=%d"
-                               ":file=%s:line=%d:%s\n",
-                       l, ERR_GET_LIB(l), ERR_GET_FUNC(l), ERR_GET_REASON(l),
-                       file, line, flags & ERR_TXT_STRING ? data : "");
-               }
-       }
-
-int hex2bin(const char *in, unsigned char *out)
-    {
-    int n1, n2;
-    unsigned char ch;
-
-    for (n1=0,n2=0 ; in[n1] && in[n1] != '\n' ; )
-       { /* first byte */
-       if ((in[n1] >= '0') && (in[n1] <= '9'))
-           ch = in[n1++] - '0';
-       else if ((in[n1] >= 'A') && (in[n1] <= 'F'))
-           ch = in[n1++] - 'A' + 10;
-       else if ((in[n1] >= 'a') && (in[n1] <= 'f'))
-           ch = in[n1++] - 'a' + 10;
-       else
-           return -1;
-       if(!in[n1])
-           {
-           out[n2++]=ch;
-           break;
-           }
-       out[n2] = ch << 4;
-       /* second byte */
-       if ((in[n1] >= '0') && (in[n1] <= '9'))
-           ch = in[n1++] - '0';
-       else if ((in[n1] >= 'A') && (in[n1] <= 'F'))
-           ch = in[n1++] - 'A' + 10;
-       else if ((in[n1] >= 'a') && (in[n1] <= 'f'))
-           ch = in[n1++] - 'a' + 10;
-       else
-           return -1;
-       out[n2++] |= ch;
-       }
-    return n2;
-    }
-
-unsigned char *hex2bin_m(const char *in, long *plen)
-       {
-       unsigned char *p;
-       p = OPENSSL_malloc((strlen(in) + 1)/2);
-       *plen = hex2bin(in, p);
-       return p;
-       }
-
-int do_hex2bn(BIGNUM **pr, const char *in)
-       {
-       unsigned char *p;
-       long plen;
-       int r = 0;
-       p = hex2bin_m(in, &plen);
-       if (!p)
-               return 0;
-       if (!*pr)
-               *pr = BN_new();
-       if (!*pr)
-               return 0;
-       if (BN_bin2bn(p, plen, *pr))
-               r = 1;
-       OPENSSL_free(p);
-       return r;
-       }
-
-int do_bn_print(FILE *out, BIGNUM *bn)
-       {
-       int len, i;
-       unsigned char *tmp;
-       len = BN_num_bytes(bn);
-       if (len == 0)
-               {
-               fputs("00", out);
-               return 1;
-               }
-
-       tmp = OPENSSL_malloc(len);
-       if (!tmp)
-               {
-               fprintf(stderr, "Memory allocation error\n");
-               return 0;
-               }
-       BN_bn2bin(bn, tmp);
-       for (i = 0; i < len; i++)
-               fprintf(out, "%02x", tmp[i]);
-       OPENSSL_free(tmp);
-       return 1;
-       }
-
-int do_bn_print_name(FILE *out, const char *name, BIGNUM *bn)
-       {
-       int r;
-       fprintf(out, "%s = ", name);
-       r = do_bn_print(out, bn);
-       if (!r)
-               return 0;
-       fputs("\n", out);
-       return 1;
-       }
-
-int parse_line(char **pkw, char **pval, char *linebuf, char *olinebuf)
-       {
-       char *keyword, *value, *p, *q;
-       strcpy(linebuf, olinebuf);
-       keyword = linebuf;
-       /* Skip leading space */
-       while (isspace((unsigned char)*keyword))
-               keyword++;
-
-       /* Look for = sign */
-       p = strchr(linebuf, '=');
-
-       /* If no '=' exit */
-       if (!p)
-               return 0;
-
-       q = p - 1;
-
-       /* Remove trailing space */
-       while (isspace((unsigned char)*q))
-               *q-- = 0;
-
-       *p = 0;
-       value = p + 1;
-
-       /* Remove leading space from value */
-       while (isspace((unsigned char)*value))
-               value++;
-
-       /* Remove trailing space from value */
-       p = value + strlen(value) - 1;
-
-       while (*p == '\n' || isspace((unsigned char)*p))
-               *p-- = 0;
-
-       *pkw = keyword;
-       *pval = value;
-       return 1;
-       }
-
-BIGNUM *hex2bn(const char *in)
-    {
-    BIGNUM *p=NULL;
-
-    if (!do_hex2bn(&p, in))
-       return NULL;
-
-    return p;
-    }
-
-int bin2hex(const unsigned char *in,int len,char *out)
-    {
-    int n1, n2;
-    unsigned char ch;
-
-    for (n1=0,n2=0 ; n1 < len ; ++n1)
-       {
-       ch=in[n1] >> 4;
-       if (ch <= 0x09)
-           out[n2++]=ch+'0';
-       else
-           out[n2++]=ch-10+'a';
-       ch=in[n1] & 0x0f;
-       if(ch <= 0x09)
-           out[n2++]=ch+'0';
-       else
-           out[n2++]=ch-10+'a';
-       }
-    out[n2]='\0';
-    return n2;
-    }
-
-void pv(const char *tag,const unsigned char *val,int len)
-    {
-    char obuf[2048];
-
-    bin2hex(val,len,obuf);
-    printf("%s = %s\n",tag,obuf);
-    }
-
-/* To avoid extensive changes to test program at this stage just convert
- * the input line into an acceptable form. Keyword lines converted to form
- * "keyword = value\n" no matter what white space present, all other lines
- * just have leading and trailing space removed.
- */
-
-int tidy_line(char *linebuf, char *olinebuf)
-       {
-       char *keyword, *value, *p, *q;
-       strcpy(linebuf, olinebuf);
-       keyword = linebuf;
-       /* Skip leading space */
-       while (isspace((unsigned char)*keyword))
-               keyword++;
-       /* Look for = sign */
-       p = strchr(linebuf, '=');
-
-       /* If no '=' just chop leading, trailing ws */
-       if (!p)
-               {
-               p = keyword + strlen(keyword) - 1;
-               while (*p == '\n' || isspace((unsigned char)*p))
-                       *p-- = 0;
-               strcpy(olinebuf, keyword);
-               strcat(olinebuf, "\n");
-               return 1;
-               }
-
-       q = p - 1;
-
-       /* Remove trailing space */
-       while (isspace((unsigned char)*q))
-               *q-- = 0;
-
-       *p = 0;
-       value = p + 1;
-
-       /* Remove leading space from value */
-       while (isspace((unsigned char)*value))
-               value++;
-
-       /* Remove trailing space from value */
-       p = value + strlen(value) - 1;
-
-       while (*p == '\n' || isspace((unsigned char)*p))
-               *p-- = 0;
-
-       strcpy(olinebuf, keyword);
-       strcat(olinebuf, " = ");
-       strcat(olinebuf, value);
-       strcat(olinebuf, "\n");
-
-       return 1;
-       }
-
-/* NB: this return the number of _bits_ read */
-int bint2bin(const char *in, int len, unsigned char *out)
-    {
-    int n;
-
-    memset(out,0,len);
-    for(n=0 ; n < len ; ++n)
-       if(in[n] == '1')
-           out[n/8]|=(0x80 >> (n%8));
-    return len;
-    }
-
-int bin2bint(const unsigned char *in,int len,char *out)
-    {
-    int n;
-
-    for(n=0 ; n < len ; ++n)
-       out[n]=(in[n/8]&(0x80 >> (n%8))) ? '1' : '0';
-    return n;
-    }
-
-/*-----------------------------------------------*/
-
-void PrintValue(char *tag, unsigned char *val, int len)
-{
-#if VERBOSE
-  char obuf[2048];
-  int olen;
-  olen = bin2hex(val, len, obuf);
-  printf("%s = %.*s\n", tag, olen, obuf);
-#endif
-}
-
-void OutputValue(char *tag, unsigned char *val, int len, FILE *rfp,int bitmode)
-    {
-    char obuf[2048];
-    int olen;
-
-    if(bitmode)
-       olen=bin2bint(val,len,obuf);
-    else
-       olen=bin2hex(val,len,obuf);
-
-    fprintf(rfp, "%s = %.*s\n", tag, olen, obuf);
-#if VERBOSE
-    printf("%s = %.*s\n", tag, olen, obuf);
-#endif
-    }
-
diff --git a/deps/openssl/openssl/fips/fipsalgtest.pl b/deps/openssl/openssl/fips/fipsalgtest.pl
deleted file mode 100644 (file)
index 851cc98..0000000
+++ /dev/null
@@ -1,887 +0,0 @@
-#!/usr/bin/perl -w
-# Perl utility to run or verify FIPS 140-2 CMVP algorithm tests based on the
-# pathnames of input algorithm test files actually present (the unqualified
-# file names are consistent but the pathnames are not).
-#
-
-# FIPS test definitions
-# List of all the unqualified file names we expect and command lines to run
-
-# DSA tests
-my @fips_dsa_test_list = (
-
-    "DSA",
-
-    [ "PQGGen",  "fips_dssvs pqg" ],
-    [ "KeyPair", "fips_dssvs keypair" ],
-    [ "SigGen",  "fips_dssvs siggen" ],
-    [ "SigVer",  "fips_dssvs sigver" ]
-
-);
-
-my @fips_dsa_pqgver_test_list = (
-
-    [ "PQGVer",  "fips_dssvs pqgver" ]
-
-);
-
-# RSA tests
-
-my @fips_rsa_test_list = (
-
-    "RSA",
-
-    [ "SigGen15",  "fips_rsastest" ],
-    [ "SigVer15",  "fips_rsavtest" ],
-    [ "SigVerRSA", "fips_rsavtest -x931" ],
-    [ "KeyGenRSA", "fips_rsagtest" ],
-    [ "SigGenRSA", "fips_rsastest -x931" ]
-
-);
-
-# Special cases for PSS. The filename itself is
-# not sufficient to determine the test. Addditionally we
-# need to examine the file contents to determine the salt length
-# In these cases the test filename has (saltlen) appended.
-
-# RSA PSS salt length 0 tests
-
-my @fips_rsa_pss0_test_list = (
-
-    [ "SigGenPSS(0)", "fips_rsastest -saltlen 0" ],
-    [ "SigVerPSS(0)", "fips_rsavtest -saltlen 0" ]
-
-);
-
-# RSA PSS salt length 62 tests
-
-my @fips_rsa_pss62_test_list = (
-    [ "SigGenPSS(62)", "fips_rsastest -saltlen 62" ],
-    [ "SigVerPSS(62)", "fips_rsavtest -saltlen 62" ]
-
-);
-
-# SHA tests
-
-my @fips_sha_test_list = (
-
-    "SHA",
-
-    [ "SHA1LongMsg",    "fips_shatest" ],
-    [ "SHA1Monte",      "fips_shatest" ],
-    [ "SHA1ShortMsg",   "fips_shatest" ],
-    [ "SHA224LongMsg",  "fips_shatest" ],
-    [ "SHA224Monte",    "fips_shatest" ],
-    [ "SHA224ShortMsg", "fips_shatest" ],
-    [ "SHA256LongMsg",  "fips_shatest" ],
-    [ "SHA256Monte",    "fips_shatest" ],
-    [ "SHA256ShortMsg", "fips_shatest" ],
-    [ "SHA384LongMsg",  "fips_shatest" ],
-    [ "SHA384Monte",    "fips_shatest" ],
-    [ "SHA384ShortMsg", "fips_shatest" ],
-    [ "SHA512LongMsg",  "fips_shatest" ],
-    [ "SHA512Monte",    "fips_shatest" ],
-    [ "SHA512ShortMsg", "fips_shatest" ]
-
-);
-
-# HMAC
-
-my @fips_hmac_test_list = (
-
-    "HMAC",
-
-    [ "HMAC", "fips_hmactest" ]
-
-);
-
-# RAND tests, AES version
-
-my @fips_rand_aes_test_list = (
-
-    "RAND (AES)",
-
-    [ "ANSI931_AES128MCT", "fips_rngvs mct" ],
-    [ "ANSI931_AES192MCT", "fips_rngvs mct" ],
-    [ "ANSI931_AES256MCT", "fips_rngvs mct" ],
-    [ "ANSI931_AES128VST", "fips_rngvs vst" ],
-    [ "ANSI931_AES192VST", "fips_rngvs vst" ],
-    [ "ANSI931_AES256VST", "fips_rngvs vst" ]
-
-);
-
-# RAND tests, DES2 version
-
-my @fips_rand_des2_test_list = (
-
-    "RAND (DES2)",
-
-    [ "ANSI931_TDES2MCT", "fips_rngvs mct" ],
-    [ "ANSI931_TDES2VST", "fips_rngvs vst" ]
-
-);
-
-# AES tests
-
-my @fips_aes_test_list = (
-
-    "AES",
-
-    [ "CBCGFSbox128",     "fips_aesavs -f" ],
-    [ "CBCGFSbox192",     "fips_aesavs -f" ],
-    [ "CBCGFSbox256",     "fips_aesavs -f" ],
-    [ "CBCKeySbox128",    "fips_aesavs -f" ],
-    [ "CBCKeySbox192",    "fips_aesavs -f" ],
-    [ "CBCKeySbox256",    "fips_aesavs -f" ],
-    [ "CBCMCT128",        "fips_aesavs -f" ],
-    [ "CBCMCT192",        "fips_aesavs -f" ],
-    [ "CBCMCT256",        "fips_aesavs -f" ],
-    [ "CBCMMT128",        "fips_aesavs -f" ],
-    [ "CBCMMT192",        "fips_aesavs -f" ],
-    [ "CBCMMT256",        "fips_aesavs -f" ],
-    [ "CBCVarKey128",     "fips_aesavs -f" ],
-    [ "CBCVarKey192",     "fips_aesavs -f" ],
-    [ "CBCVarKey256",     "fips_aesavs -f" ],
-    [ "CBCVarTxt128",     "fips_aesavs -f" ],
-    [ "CBCVarTxt192",     "fips_aesavs -f" ],
-    [ "CBCVarTxt256",     "fips_aesavs -f" ],
-    [ "CFB128GFSbox128",  "fips_aesavs -f" ],
-    [ "CFB128GFSbox192",  "fips_aesavs -f" ],
-    [ "CFB128GFSbox256",  "fips_aesavs -f" ],
-    [ "CFB128KeySbox128", "fips_aesavs -f" ],
-    [ "CFB128KeySbox192", "fips_aesavs -f" ],
-    [ "CFB128KeySbox256", "fips_aesavs -f" ],
-    [ "CFB128MCT128",     "fips_aesavs -f" ],
-    [ "CFB128MCT192",     "fips_aesavs -f" ],
-    [ "CFB128MCT256",     "fips_aesavs -f" ],
-    [ "CFB128MMT128",     "fips_aesavs -f" ],
-    [ "CFB128MMT192",     "fips_aesavs -f" ],
-    [ "CFB128MMT256",     "fips_aesavs -f" ],
-    [ "CFB128VarKey128",  "fips_aesavs -f" ],
-    [ "CFB128VarKey192",  "fips_aesavs -f" ],
-    [ "CFB128VarKey256",  "fips_aesavs -f" ],
-    [ "CFB128VarTxt128",  "fips_aesavs -f" ],
-    [ "CFB128VarTxt192",  "fips_aesavs -f" ],
-    [ "CFB128VarTxt256",  "fips_aesavs -f" ],
-    [ "CFB8GFSbox128",    "fips_aesavs -f" ],
-    [ "CFB8GFSbox192",    "fips_aesavs -f" ],
-    [ "CFB8GFSbox256",    "fips_aesavs -f" ],
-    [ "CFB8KeySbox128",   "fips_aesavs -f" ],
-    [ "CFB8KeySbox192",   "fips_aesavs -f" ],
-    [ "CFB8KeySbox256",   "fips_aesavs -f" ],
-    [ "CFB8MCT128",       "fips_aesavs -f" ],
-    [ "CFB8MCT192",       "fips_aesavs -f" ],
-    [ "CFB8MCT256",       "fips_aesavs -f" ],
-    [ "CFB8MMT128",       "fips_aesavs -f" ],
-    [ "CFB8MMT192",       "fips_aesavs -f" ],
-    [ "CFB8MMT256",       "fips_aesavs -f" ],
-    [ "CFB8VarKey128",    "fips_aesavs -f" ],
-    [ "CFB8VarKey192",    "fips_aesavs -f" ],
-    [ "CFB8VarKey256",    "fips_aesavs -f" ],
-    [ "CFB8VarTxt128",    "fips_aesavs -f" ],
-    [ "CFB8VarTxt192",    "fips_aesavs -f" ],
-    [ "CFB8VarTxt256",    "fips_aesavs -f" ],
-
-    [ "ECBGFSbox128",  "fips_aesavs -f" ],
-    [ "ECBGFSbox192",  "fips_aesavs -f" ],
-    [ "ECBGFSbox256",  "fips_aesavs -f" ],
-    [ "ECBKeySbox128", "fips_aesavs -f" ],
-    [ "ECBKeySbox192", "fips_aesavs -f" ],
-    [ "ECBKeySbox256", "fips_aesavs -f" ],
-    [ "ECBMCT128",     "fips_aesavs -f" ],
-    [ "ECBMCT192",     "fips_aesavs -f" ],
-    [ "ECBMCT256",     "fips_aesavs -f" ],
-    [ "ECBMMT128",     "fips_aesavs -f" ],
-    [ "ECBMMT192",     "fips_aesavs -f" ],
-    [ "ECBMMT256",     "fips_aesavs -f" ],
-    [ "ECBVarKey128",  "fips_aesavs -f" ],
-    [ "ECBVarKey192",  "fips_aesavs -f" ],
-    [ "ECBVarKey256",  "fips_aesavs -f" ],
-    [ "ECBVarTxt128",  "fips_aesavs -f" ],
-    [ "ECBVarTxt192",  "fips_aesavs -f" ],
-    [ "ECBVarTxt256",  "fips_aesavs -f" ],
-    [ "OFBGFSbox128",  "fips_aesavs -f" ],
-    [ "OFBGFSbox192",  "fips_aesavs -f" ],
-    [ "OFBGFSbox256",  "fips_aesavs -f" ],
-    [ "OFBKeySbox128", "fips_aesavs -f" ],
-    [ "OFBKeySbox192", "fips_aesavs -f" ],
-    [ "OFBKeySbox256", "fips_aesavs -f" ],
-    [ "OFBMCT128",     "fips_aesavs -f" ],
-    [ "OFBMCT192",     "fips_aesavs -f" ],
-    [ "OFBMCT256",     "fips_aesavs -f" ],
-    [ "OFBMMT128",     "fips_aesavs -f" ],
-    [ "OFBMMT192",     "fips_aesavs -f" ],
-    [ "OFBMMT256",     "fips_aesavs -f" ],
-    [ "OFBVarKey128",  "fips_aesavs -f" ],
-    [ "OFBVarKey192",  "fips_aesavs -f" ],
-    [ "OFBVarKey256",  "fips_aesavs -f" ],
-    [ "OFBVarTxt128",  "fips_aesavs -f" ],
-    [ "OFBVarTxt192",  "fips_aesavs -f" ],
-    [ "OFBVarTxt256",  "fips_aesavs -f" ]
-
-);
-
-my @fips_aes_cfb1_test_list = (
-
-    # AES CFB1 tests
-
-    [ "CFB1GFSbox128",  "fips_aesavs -f" ],
-    [ "CFB1GFSbox192",  "fips_aesavs -f" ],
-    [ "CFB1GFSbox256",  "fips_aesavs -f" ],
-    [ "CFB1KeySbox128", "fips_aesavs -f" ],
-    [ "CFB1KeySbox192", "fips_aesavs -f" ],
-    [ "CFB1KeySbox256", "fips_aesavs -f" ],
-    [ "CFB1MCT128",     "fips_aesavs -f" ],
-    [ "CFB1MCT192",     "fips_aesavs -f" ],
-    [ "CFB1MCT256",     "fips_aesavs -f" ],
-    [ "CFB1MMT128",     "fips_aesavs -f" ],
-    [ "CFB1MMT192",     "fips_aesavs -f" ],
-    [ "CFB1MMT256",     "fips_aesavs -f" ],
-    [ "CFB1VarKey128",  "fips_aesavs -f" ],
-    [ "CFB1VarKey192",  "fips_aesavs -f" ],
-    [ "CFB1VarKey256",  "fips_aesavs -f" ],
-    [ "CFB1VarTxt128",  "fips_aesavs -f" ],
-    [ "CFB1VarTxt192",  "fips_aesavs -f" ],
-    [ "CFB1VarTxt256",  "fips_aesavs -f" ]
-
-);
-
-# Triple DES tests
-
-my @fips_des3_test_list = (
-
-    "Triple DES",
-
-    [ "TCBCinvperm",   "fips_desmovs -f" ],
-    [ "TCBCMMT1",      "fips_desmovs -f" ],
-    [ "TCBCMMT2",      "fips_desmovs -f" ],
-    [ "TCBCMMT3",      "fips_desmovs -f" ],
-    [ "TCBCMonte1",    "fips_desmovs -f" ],
-    [ "TCBCMonte2",    "fips_desmovs -f" ],
-    [ "TCBCMonte3",    "fips_desmovs -f" ],
-    [ "TCBCpermop",    "fips_desmovs -f" ],
-    [ "TCBCsubtab",    "fips_desmovs -f" ],
-    [ "TCBCvarkey",    "fips_desmovs -f" ],
-    [ "TCBCvartext",   "fips_desmovs -f" ],
-    [ "TCFB64invperm", "fips_desmovs -f" ],
-    [ "TCFB64MMT1",    "fips_desmovs -f" ],
-    [ "TCFB64MMT2",    "fips_desmovs -f" ],
-    [ "TCFB64MMT3",    "fips_desmovs -f" ],
-    [ "TCFB64Monte1",  "fips_desmovs -f" ],
-    [ "TCFB64Monte2",  "fips_desmovs -f" ],
-    [ "TCFB64Monte3",  "fips_desmovs -f" ],
-    [ "TCFB64permop",  "fips_desmovs -f" ],
-    [ "TCFB64subtab",  "fips_desmovs -f" ],
-    [ "TCFB64varkey",  "fips_desmovs -f" ],
-    [ "TCFB64vartext", "fips_desmovs -f" ],
-    [ "TCFB8invperm",  "fips_desmovs -f" ],
-    [ "TCFB8MMT1",     "fips_desmovs -f" ],
-    [ "TCFB8MMT2",     "fips_desmovs -f" ],
-    [ "TCFB8MMT3",     "fips_desmovs -f" ],
-    [ "TCFB8Monte1",   "fips_desmovs -f" ],
-    [ "TCFB8Monte2",   "fips_desmovs -f" ],
-    [ "TCFB8Monte3",   "fips_desmovs -f" ],
-    [ "TCFB8permop",   "fips_desmovs -f" ],
-    [ "TCFB8subtab",   "fips_desmovs -f" ],
-    [ "TCFB8varkey",   "fips_desmovs -f" ],
-    [ "TCFB8vartext",  "fips_desmovs -f" ],
-    [ "TECBinvperm",   "fips_desmovs -f" ],
-    [ "TECBMMT1",      "fips_desmovs -f" ],
-    [ "TECBMMT2",      "fips_desmovs -f" ],
-    [ "TECBMMT3",      "fips_desmovs -f" ],
-    [ "TECBMonte1",    "fips_desmovs -f" ],
-    [ "TECBMonte2",    "fips_desmovs -f" ],
-    [ "TECBMonte3",    "fips_desmovs -f" ],
-    [ "TECBpermop",    "fips_desmovs -f" ],
-    [ "TECBsubtab",    "fips_desmovs -f" ],
-    [ "TECBvarkey",    "fips_desmovs -f" ],
-    [ "TECBvartext",   "fips_desmovs -f" ],
-    [ "TOFBinvperm",   "fips_desmovs -f" ],
-    [ "TOFBMMT1",      "fips_desmovs -f" ],
-    [ "TOFBMMT2",      "fips_desmovs -f" ],
-    [ "TOFBMMT3",      "fips_desmovs -f" ],
-    [ "TOFBMonte1",    "fips_desmovs -f" ],
-    [ "TOFBMonte2",    "fips_desmovs -f" ],
-    [ "TOFBMonte3",    "fips_desmovs -f" ],
-    [ "TOFBpermop",    "fips_desmovs -f" ],
-    [ "TOFBsubtab",    "fips_desmovs -f" ],
-    [ "TOFBvarkey",    "fips_desmovs -f" ],
-    [ "TOFBvartext",   "fips_desmovs -f" ]
-
-);
-
-my @fips_des3_cfb1_test_list = (
-
-    # DES3 CFB1 tests
-
-    [ "TCFB1invperm",  "fips_desmovs -f" ],
-    [ "TCFB1MMT1",     "fips_desmovs -f" ],
-    [ "TCFB1MMT2",     "fips_desmovs -f" ],
-    [ "TCFB1MMT3",     "fips_desmovs -f" ],
-    [ "TCFB1Monte1",   "fips_desmovs -f" ],
-    [ "TCFB1Monte2",   "fips_desmovs -f" ],
-    [ "TCFB1Monte3",   "fips_desmovs -f" ],
-    [ "TCFB1permop",   "fips_desmovs -f" ],
-    [ "TCFB1subtab",   "fips_desmovs -f" ],
-    [ "TCFB1varkey",   "fips_desmovs -f" ],
-    [ "TCFB1vartext",  "fips_desmovs -f" ],
-
-);
-
-# Verification special cases.
-# In most cases the output of a test is deterministic and
-# it can be compared to a known good result. A few involve
-# the genration and use of random keys and the output will
-# be different each time. In thoses cases we perform special tests
-# to simply check their consistency. For example signature generation
-# output will be run through signature verification to see if all outputs
-# show as valid.
-#
-
-my %verify_special = (
-    "PQGGen"        => "fips_dssvs pqgver",
-    "KeyPair"       => "fips_dssvs keyver",
-    "SigGen"        => "fips_dssvs sigver",
-    "SigGen15"      => "fips_rsavtest",
-    "SigGenRSA"     => "fips_rsavtest -x931",
-    "SigGenPSS(0)"  => "fips_rsavtest -saltlen 0",
-    "SigGenPSS(62)" => "fips_rsavtest -saltlen 62",
-);
-
-my $win32  = $^O =~ m/mswin/i;
-my $onedir = 0;
-my $filter = "";
-my $tvdir;
-my $tprefix;
-my $shwrap_prefix;
-my $debug          = 0;
-my $quiet          = 0;
-my $notest         = 0;
-my $verify         = 1;
-my $rspdir         = "rsp";
-my $ignore_missing = 0;
-my $ignore_bogus   = 0;
-my $bufout         = '';
-my $list_tests     = 0;
-
-my %fips_enabled = (
-    dsa         => 1,
-    "dsa-pqgver"  => 0,
-    rsa         => 1,
-    "rsa-pss0"  => 0,
-    "rsa-pss62" => 1,
-    sha         => 1,
-    hmac        => 1,
-    "rand-aes"  => 1,
-    "rand-des2" => 0,
-    aes         => 1,
-    "aes-cfb1"  => 0,
-    des3        => 1,
-    "des3-cfb1" => 0
-);
-
-foreach (@ARGV) {
-    if ( $_ eq "--win32" ) {
-        $win32 = 1;
-    }
-    elsif ( $_ eq "--onedir" ) {
-        $onedir = 1;
-    }
-    elsif ( $_ eq "--debug" ) {
-        $debug = 1;
-    }
-    elsif ( $_ eq "--ignore-missing" ) {
-        $ignore_missing = 1;
-    }
-    elsif ( $_ eq "--ignore-bogus" ) {
-        $ignore_bogus = 1;
-    }
-    elsif ( $_ eq "--generate" ) {
-        $verify = 0;
-    }
-    elsif ( $_ eq "--notest" ) {
-        $notest = 1;
-    }
-    elsif ( $_ eq "--quiet" ) {
-        $quiet = 1;
-    }
-    elsif (/--dir=(.*)$/) {
-        $tvdir = $1;
-    }
-    elsif (/--rspdir=(.*)$/) {
-        $rspdir = $1;
-    }
-    elsif (/--tprefix=(.*)$/) {
-        $tprefix = $1;
-    }
-    elsif (/--shwrap_prefix=(.*)$/) {
-        $shwrap_prefix = $1;
-    }
-    elsif (/^--(enable|disable)-(.*)$/) {
-        if ( !exists $fips_enabled{$2} ) {
-            print STDERR "Unknown test $2\n";
-        }
-        if ( $1 eq "enable" ) {
-            $fips_enabled{$2} = 1;
-        }
-        else {
-            $fips_enabled{$2} = 0;
-        }
-    }
-    elsif (/--filter=(.*)$/) {
-        $filter = $1;
-    }
-    elsif (/^--list-tests$/) {
-        $list_tests = 1;
-    }
-    else {
-        Help();
-        exit(1);
-    }
-}
-
-my @fips_test_list;
-
-push @fips_test_list, @fips_dsa_test_list       if $fips_enabled{"dsa"};
-push @fips_test_list, @fips_dsa_pqgver_test_list if $fips_enabled{"dsa-pqgver"};
-push @fips_test_list, @fips_rsa_test_list       if $fips_enabled{"rsa"};
-push @fips_test_list, @fips_rsa_pss0_test_list  if $fips_enabled{"rsa-pss0"};
-push @fips_test_list, @fips_rsa_pss62_test_list if $fips_enabled{"rsa-pss62"};
-push @fips_test_list, @fips_sha_test_list       if $fips_enabled{"sha"};
-push @fips_test_list, @fips_hmac_test_list      if $fips_enabled{"hmac"};
-push @fips_test_list, @fips_rand_aes_test_list  if $fips_enabled{"rand-aes"};
-push @fips_test_list, @fips_rand_des2_test_list if $fips_enabled{"rand-des2"};
-push @fips_test_list, @fips_aes_test_list       if $fips_enabled{"aes"};
-push @fips_test_list, @fips_aes_cfb1_test_list  if $fips_enabled{"aes-cfb1"};
-push @fips_test_list, @fips_des3_test_list      if $fips_enabled{"des3"};
-push @fips_test_list, @fips_des3_cfb1_test_list if $fips_enabled{"des3-cfb1"};
-
-if ($list_tests) {
-    my ( $test, $en );
-    print "=====TEST LIST=====\n";
-    foreach $test ( sort keys %fips_enabled ) {
-        $en = $fips_enabled{$test};
-        $test =~ tr/[a-z]/[A-Z]/;
-        printf "%-10s %s\n", $test, $en ? "enabled" : "disabled";
-    }
-    exit(0);
-}
-
-foreach (@fips_test_list) {
-    next unless ref($_);
-    my $nm = $_->[0];
-    $_->[2] = "";
-    $_->[3] = "";
-    print STDERR "Duplicate test $nm\n" if exists $fips_tests{$nm};
-    $fips_tests{$nm} = $_;
-}
-
-$tvdir = "." unless defined $tvdir;
-
-if ($win32) {
-    if ( !defined $tprefix ) {
-        if ($onedir) {
-            $tprefix = ".\\";
-        }
-        else {
-            $tprefix = "..\\out32dll\\";
-        }
-    }
-}
-else {
-    if ($onedir) {
-        $tprefix       = "./" unless defined $tprefix;
-        $shwrap_prefix = "./" unless defined $shwrap_prefix;
-    }
-    else {
-        $tprefix       = "../test/" unless defined $tprefix;
-        $shwrap_prefix = "../util/" unless defined $shwrap_prefix;
-    }
-}
-
-sanity_check_exe( $win32, $tprefix, $shwrap_prefix );
-
-my $cmd_prefix = $win32 ? "" : "${shwrap_prefix}shlib_wrap.sh ";
-
-find_files( $filter, $tvdir );
-
-sanity_check_files();
-
-my ( $runerr, $cmperr, $cmpok, $scheckrunerr, $scheckerr, $scheckok, $skipcnt )
-  = ( 0, 0, 0, 0, 0, 0, 0 );
-
-exit(0) if $notest;
-
-run_tests( $verify, $win32, $tprefix, $filter, $tvdir );
-
-if ($verify) {
-    print "ALGORITHM TEST VERIFY SUMMARY REPORT:\n";
-    print "Tests skipped due to missing files:        $skipcnt\n";
-    print "Algorithm test program execution failures: $runerr\n";
-    print "Test comparisons successful:               $cmpok\n";
-    print "Test comparisons failed:                   $cmperr\n";
-    print "Test sanity checks successful:             $scheckok\n";
-    print "Test sanity checks failed:                 $scheckerr\n";
-    print "Sanity check program execution failures:   $scheckrunerr\n";
-
-    if ( $runerr || $cmperr || $scheckrunerr || $scheckerr ) {
-        print "***TEST FAILURE***\n";
-    }
-    else {
-        print "***ALL TESTS SUCCESSFUL***\n";
-    }
-}
-else {
-    print "ALGORITHM TEST SUMMARY REPORT:\n";
-    print "Tests skipped due to missing files:        $skipcnt\n";
-    print "Algorithm test program execution failures: $runerr\n";
-
-    if ($runerr) {
-        print "***TEST FAILURE***\n";
-    }
-    else {
-        print "***ALL TESTS SUCCESSFUL***\n";
-    }
-}
-
-#--------------------------------
-sub Help {
-    ( my $cmd ) = ( $0 =~ m#([^/]+)$# );
-    print <<EOF;
-$cmd: generate run CMVP algorithm tests
-       --debug                     Enable debug output
-       --dir=<dirname>             Optional root for *.req file search
-       --filter=<regexp>
-       --onedir <dirname>          Assume all components in current directory
-       --rspdir=<dirname>          Name of subdirectories containing *.rsp files, default "rsp"
-       --shwrap_prefix=<prefix>
-       --tprefix=<prefix>
-       --ignore-bogus              Ignore duplicate or bogus files
-       --ignore-missing            Ignore missing test files
-       --quiet                     Shhh....
-       --generate                  Generate algorithm test output
-       --win32                     Win32 environment
-       --enable-<alg>              Enable algorithm set <alg>.
-       --disable-<alg>             Disable algorithm set <alg>.
-       Where <alg> can be one of:
-EOF
-
-while (my ($key, $value) = each %fips_enabled)
-       {
-       printf "\t\t%-20s(%s by default)\n", $key ,
-                       $value ? "enabled" : "disabled";
-       }
-}
-
-# Sanity check to see if all necessary executables exist
-
-sub sanity_check_exe {
-    my ( $win32, $tprefix, $shwrap_prefix ) = @_;
-    my %exe_list;
-    my $bad = 0;
-    $exe_list{ $shwrap_prefix . "shlib_wrap.sh" } = 1 unless $win32;
-    foreach (@fips_test_list) {
-        next unless ref($_);
-        my $cmd = $_->[1];
-        $cmd =~ s/ .*$//;
-        $cmd = $tprefix . $cmd;
-        $cmd .= ".exe" if $win32;
-        $exe_list{$cmd} = 1;
-    }
-
-    foreach ( sort keys %exe_list ) {
-        if ( !-f $_ ) {
-            print STDERR "ERROR: can't find executable $_\n";
-            $bad = 1;
-        }
-    }
-    if ($bad) {
-        print STDERR "FATAL ERROR: executables missing\n";
-        exit(1);
-    }
-    elsif ($debug) {
-        print STDERR "Executable sanity check passed OK\n";
-    }
-}
-
-# Search for all request and response files
-
-sub find_files {
-    my ( $filter, $dir ) = @_;
-    my ( $dirh, $testname );
-    opendir( $dirh, $dir );
-    while ( $_ = readdir($dirh) ) {
-        next if ( $_ eq "." || $_ eq ".." );
-        $_ = "$dir/$_";
-        if ( -f "$_" ) {
-            if (/\/([^\/]*)\.rsp$/) {
-                $testname = fix_pss( $1, $_ );
-                if ( exists $fips_tests{$testname} ) {
-                    if ( $fips_tests{$testname}->[3] eq "" ) {
-                        $fips_tests{$testname}->[3] = $_;
-                    }
-                    else {
-                        print STDERR
-"WARNING: duplicate response file $_ for test $testname\n";
-                        $nbogus++;
-                    }
-                }
-                else {
-                    print STDERR "WARNING: bogus file $_\n";
-                    $nbogus++;
-                }
-            }
-            next unless /$filter.*\.req$/i;
-            if (/\/([^\/]*)\.req$/) {
-                $testname = fix_pss( $1, $_ );
-                if ( exists $fips_tests{$testname} ) {
-                    if ( $fips_tests{$testname}->[2] eq "" ) {
-                        $fips_tests{$testname}->[2] = $_;
-                    }
-                    else {
-                        print STDERR
-"WARNING: duplicate request file $_ for test $testname\n";
-                        $nbogus++;
-                    }
-
-                }
-                elsif ( !/SHAmix\.req$/ ) {
-                    print STDERR "WARNING: unrecognized filename $_\n";
-                    $nbogus++;
-                }
-            }
-        }
-        elsif ( -d "$_" ) {
-            find_files( $filter, $_ );
-        }
-    }
-    closedir($dirh);
-}
-
-sub fix_pss {
-    my ( $test, $path ) = @_;
-    my $sl = "";
-    local $_;
-    if ( $test =~ /PSS/ ) {
-        open( IN, $path ) || die "Can't Open File $path";
-        while (<IN>) {
-            if (/^\s*#\s*salt\s+len:\s+(\d+)\s*$/i) {
-                $sl = $1;
-                last;
-            }
-        }
-        close IN;
-        if ( $sl eq "" ) {
-            print STDERR "WARNING: No Salt length detected for file $path\n";
-        }
-        else {
-            return $test . "($sl)";
-        }
-    }
-    return $test;
-}
-
-sub sanity_check_files {
-    my $bad = 0;
-    foreach (@fips_test_list) {
-        next unless ref($_);
-        my ( $tst, $cmd, $req, $resp ) = @$_;
-
-        #print STDERR "FILES $tst, $cmd, $req, $resp\n";
-        if ( $req eq "" ) {
-            print STDERR "WARNING: missing request file for $tst\n";
-            $bad = 1;
-            next;
-        }
-        if ( $verify && $resp eq "" ) {
-            print STDERR "WARNING: no response file for test $tst\n";
-            $bad = 1;
-        }
-        elsif ( !$verify && $resp ne "" ) {
-            print STDERR "WARNING: response file $resp will be overwritten\n";
-        }
-    }
-    if ($bad) {
-        print STDERR "ERROR: test vector file set not complete\n";
-        exit(1) unless $ignore_missing;
-    }
-    if ($nbogus) {
-        print STDERR
-          "ERROR: $nbogus bogus or duplicate request and response files\n";
-        exit(1) unless $ignore_bogus;
-    }
-    if ( $debug && !$nbogus && !$bad ) {
-        print STDERR "test vector file set complete\n";
-    }
-}
-
-sub run_tests {
-    my ( $verify, $win32, $tprefix, $filter, $tvdir ) = @_;
-    my ( $tname, $tref );
-    my $bad = 0;
-    foreach (@fips_test_list) {
-        if ( !ref($_) ) {
-            print "Running $_ tests\n" unless $quiet;
-            next;
-        }
-        my ( $tname, $tcmd, $req, $rsp ) = @$_;
-        my $out = $rsp;
-        if ($verify) {
-            $out =~ s/\.rsp$/.tst/;
-        }
-        if ( $req eq "" ) {
-            print STDERR
-              "WARNING: Request file for $tname missing: test skipped\n";
-            $skipcnt++;
-            next;
-        }
-        if ( $verify && $rsp eq "" ) {
-            print STDERR
-              "WARNING: Response file for $tname missing: test skipped\n";
-            $skipcnt++;
-            next;
-        }
-        elsif ( !$verify ) {
-            if ( $rsp ne "" ) {
-                print STDERR "WARNING: Response file for $tname deleted\n";
-                unlink $rsp;
-            }
-            $out = $req;
-            $out =~ s|/req/(\S+)\.req|/$rspdir/$1.rsp|;
-            my $outdir = $out;
-            $outdir =~ s|/[^/]*$||;
-            if ( !-d $outdir ) {
-                print STDERR "DEBUG: Creating directory $outdir\n" if $debug;
-                mkdir($outdir) || die "Can't create directory $outdir";
-            }
-        }
-        my $cmd = "$cmd_prefix$tprefix$tcmd ";
-        if ( $tcmd =~ /-f$/ ) {
-            $cmd .= "\"$req\" \"$out\"";
-        }
-        else {
-            $cmd .= "<\"$req\" >\"$out\"";
-        }
-        print STDERR "DEBUG: running test $tname\n" if ( $debug && !$verify );
-        system($cmd);
-        if ( $? != 0 ) {
-            print STDERR
-              "WARNING: error executing test $tname for command: $cmd\n";
-            $runerr++;
-            next;
-        }
-        if ($verify) {
-            if ( exists $verify_special{$tname} ) {
-                my $vout = $rsp;
-                $vout =~ s/\.rsp$/.ver/;
-                $tcmd = $verify_special{$tname};
-                $cmd  = "$cmd_prefix$tprefix$tcmd ";
-                $cmd .= "<\"$out\" >\"$vout\"";
-                system($cmd);
-                if ( $? != 0 ) {
-                    print STDERR
-                      "WARNING: error executing verify test $tname $cmd\n";
-                    $scheckrunerr++;
-                    next;
-                }
-                my ( $fcount, $pcount ) = ( 0, 0 );
-                open VER, "$vout";
-                while (<VER>) {
-                    if (/^Result\s*=\s*(\S*)\s*$/i)
-
-                    {
-                        if ( $1 eq "F" ) {
-                            $fcount++;
-                        }
-                        else {
-                            $pcount++;
-                        }
-                    }
-                }
-                close VER;
-
-                unlink $vout;
-                if ( $fcount || $debug ) {
-                    print STDERR "DEBUG: $tname, Pass=$pcount, Fail=$fcount\n";
-                }
-                if ( $fcount || !$pcount ) {
-                    $scheckerr++;
-                }
-                else {
-                    $scheckok++;
-                }
-
-            }
-            elsif ( !cmp_file( $tname, $rsp, $out ) ) {
-                $cmperr++;
-            }
-            else {
-                $cmpok++;
-            }
-            unlink $out;
-        }
-    }
-}
-
-sub cmp_file {
-    my ( $tname, $rsp, $tst ) = @_;
-    my ( $rspf,    $tstf );
-    my ( $rspline, $tstline );
-    if ( !open( $rspf, $rsp ) ) {
-        print STDERR "ERROR: can't open request file $rsp\n";
-        return 0;
-    }
-    if ( !open( $tstf, $tst ) ) {
-        print STDERR "ERROR: can't open output file $tst\n";
-        return 0;
-    }
-    for ( ; ; ) {
-        $rspline = next_line($rspf);
-        $tstline = next_line($tstf);
-        if ( !defined($rspline) && !defined($tstline) ) {
-            print STDERR "DEBUG: $tname file comparison OK\n" if $debug;
-            return 1;
-        }
-        if ( !defined($rspline) ) {
-            print STDERR "ERROR: $tname EOF on $rsp\n";
-            return 0;
-        }
-        if ( !defined($tstline) ) {
-            print STDERR "ERROR: $tname EOF on $tst\n";
-            return 0;
-        }
-
-        # Workaround for bug in RAND des2 test output */
-        if ( $tstline =~ /^Key2 =/ && $rspline =~ /^Key1 =/ ) {
-            $rspline =~ s/^Key1/Key2/;
-        }
-
-        if ( $tstline ne $rspline ) {
-            print STDERR "ERROR: $tname mismatch:\n";
-            print STDERR "\t \"$tstline\" != \"$rspline\"\n";
-            return 0;
-        }
-    }
-    return 1;
-}
-
-sub next_line {
-    my ($in) = @_;
-
-    while (<$in>) {
-        chomp;
-
-        # Delete comments
-        s/#.*$//;
-
-        # Ignore blank lines
-        next if (/^\s*$/);
-
-        # Translate multiple space into one
-        s/\s+/ /g;
-       # Delete trailing whitespace
-       s/\s+$//;
-        return $_;
-    }
-    return undef;
-}
diff --git a/deps/openssl/openssl/fips/fipsld b/deps/openssl/openssl/fips/fipsld
deleted file mode 100755 (executable)
index 8c26c85..0000000
+++ /dev/null
@@ -1,178 +0,0 @@
-#!/bin/sh -e
-#
-# Copyright (c) 2005-2007 The OpenSSL Project.
-#
-# Depending on output file name, the script either embeds fingerprint
-# into libcrypto.so or static application. "Static" refers to static
-# libcrypto.a, not [necessarily] application per se.
-#
-# Even though this script is called fipsld, it expects C compiler
-# command line syntax and $FIPSLD_CC or $CC environment variable set
-# and can even be used to compile source files.
-
-#set -x
-
-CC=${FIPSLD_CC:-${CC}}
-[ -n "${CC}" ] || { echo '$CC is not defined'; exit 1; }
-
-# Initially -c wasn't intended to be interpreted here, but it might
-# make life easier for those who want to build FIPS-ified applications
-# with minimal [if any] modifications to their Makefiles...
-(   while [ "x$1" != "x" -a "x$1" != "x-c" -a "x$1" != "x-E" ]; do shift; done;
-    [ $# -ge 1 ]
-) && exec ${CC} "$@"
-
-TARGET=`(while [ "x$1" != "x" -a "x$1" != "x-o" ]; do shift; done; echo $2)`
-
-# If using an auto-tooled (autoconf/automake/libtool) project,
-# configure will fail when testing the compiler or even performing
-# simple checks. Pass-through to compiler directly if application is
-# is not being linked with libcrypto, allowing auto-tooled applications
-# to utilize fipsld (e.g. CC=/usr/local/ssl/bin/fipsld FIPSLD_CC=gcc
-# ./configure && make). But keep in mind[!] that if certified code
-# resides in a shared library, then fipsld *may not* be used and
-# end-developer should not modify application configuration and build
-# procedures. This is because in-core fingerprint and associated
-# procedures are already embedded into and executed in shared library
-# context.
-case `basename "${TARGET}"` in
-libcrypto*|libfips*|*.dll)             ;;
-*)     case "$*" in
-       *libcrypto.a*|*-lcrypto*|*fipscanister.o*)      ;;
-       *)      exec ${CC} "$@"         ;;
-       esac
-esac
-
-[ -n "${TARGET}" ] || { echo 'no -o specified'; exit 1; }
-
-# Turn on debugging output?
-(   while [ "x$1" != "x" -a "x$1" != "x-DDEBUG_FINGERPRINT_PREMAIN" ]; do shift; done;
-    [ $# -ge 1 ]
-) && set -x
-
-THERE="`echo $0 | sed -e 's|[^/]*$||'`"..
-
-# fipscanister.o can appear in command line
-CANISTER_O=`(while [ "x$1" != "x" ]; do case "$1" in *fipscanister.o) echo $1; exit;; esac; shift; done)`
-if [ -z "${CANISTER_O}" ]; then
-       # If set, FIPSLIBDIR is location of installed validated FIPS module
-       if [ -n "${FIPSLIBDIR}" ]; then
-               CANISTER_O="${FIPSLIBDIR}/fipscanister.o"
-       elif [ -f "${THERE}/fips/fipscanister.o" ]; then
-               CANISTER_O="${THERE}/fips/fipscanister.o"
-       elif [ -f "${THERE}/lib/fipscanister.o" ]; then
-               CANISTER_O="${THERE}/lib/fipscanister.o"
-       fi
-       CANISTER_O_CMD="${CANISTER_O}"
-fi
-[ -f ${CANISTER_O} ] || { echo "unable to find ${CANISTER_O}"; exit 1; }
-
-PREMAIN_C=`dirname "${CANISTER_O}"`/fips_premain.c
-
-HMAC_KEY="etaonrishdlcupfm"
-
-case "`(uname -s) 2>/dev/null`" in
-OSF1|IRIX*)    _WL_PREMAIN="-Wl,-init,FINGERPRINT_premain"     ;;
-HP-UX)         _WL_PREMAIN="-Wl,+init,FINGERPRINT_premain"     ;;
-AIX)           _WL_PREMAIN="-Wl,-binitfini:FINGERPRINT_premain,-bnoobjreorder";;
-Darwin)                (   while [ "x$1" != "x" -a "x$1" != "x-dynamiclib" ]; do shift; done;
-                   [ $# -ge 1 ]
-               ) && _WL_PREMAIN="-Wl,-init,_FINGERPRINT_premain" ;;
-esac
-
-case "${TARGET}" in
-[!/]*) TARGET=./${TARGET} ;;
-esac
-
-case `basename "${TARGET}"` in
-lib*|*.dll)    # must be linking a shared lib...
-       # Shared lib creation can be taking place in the source
-       # directory only, but fipscanister.o can reside elsewhere...
-       FINGERTYPE="${THERE}/fips/fips_standalone_sha1"
-
-       # verify fipspremain.c against its detached signature...
-       ${FINGERTYPE} "${PREMAIN_C}" | sed "s/(.*\//(/" | \
-               diff -w "${PREMAIN_C}.sha1" - || \
-       { echo "${PREMAIN_C} fingerprint mismatch"; exit 1; }
-       # verify fipscanister.o against its detached signature...
-       ${FINGERTYPE} "${CANISTER_O}" | sed "s/(.*\//(/" | \
-               diff -w "${CANISTER_O}.sha1" - || \
-       { echo "${CANISTER_O} fingerprint mismatch"; exit 1; }
-
-       # Temporarily remove fipscanister.o from libcrypto.a!
-       # We are required to use the standalone copy...
-       if [ -f "${THERE}/libcrypto.a" ]; then
-           if ar d "${THERE}/libcrypto.a" fipscanister.o; then
-               (ranlib "${THERE}/libcrypto.a") 2>/dev/null || :
-               trap    'ar r "${THERE}/libcrypto.a" "${CANISTER_O}";
-                        (ranlib "${THERE}/libcrypto.a") 2>/dev/null || :;
-                        sleep 1;
-                        touch -c "${TARGET}"' 0
-           fi
-       fi
-
-       /bin/rm -f "${TARGET}"
-       ${CC}   ${CANISTER_O_CMD:+"${CANISTER_O_CMD}"} \
-               "${PREMAIN_C}" \
-               ${_WL_PREMAIN} "$@"
-
-       # generate signature...
-       if [ -z "${FIPS_SIG}" ]; then
-               SIG=`"${THERE}/fips/fips_premain_dso" "${TARGET}"`
-       else
-               SIG=`"${FIPS_SIG}" -dso "${TARGET}"`
-       fi
-       /bin/rm -f "${TARGET}"
-       if [ -z "${SIG}" ]; then
-          echo "unable to collect signature"; exit 1
-       fi
-
-       # recompile with signature...
-       ${CC}   ${CANISTER_O_CMD:+"${CANISTER_O_CMD}"} \
-               -DHMAC_SHA1_SIG=\"${SIG}\" "${PREMAIN_C}" \
-               ${_WL_PREMAIN} "$@"
-       ;;
-
-*)     # must be linking statically...
-       # Static linking can be taking place either in the source
-       # directory or off the installed binary target destination.
-       if [ -x "${THERE}/fips/fips_standalone_sha1" ]; then
-               FINGERTYPE="${THERE}/fips/fips_standalone_sha1"
-       else    # Installed tree is expected to contain
-               # lib/fipscanister.o, lib/fipscanister.o.sha1 and
-               # lib/fips_premain.c [not to mention bin/openssl].
-               FINGERTYPE="${THERE}/bin/openssl sha1 -hmac ${HMAC_KEY}"
-       fi
-
-       # verify fipscanister.o against its detached signature...
-       ${FINGERTYPE} "${CANISTER_O}" | sed "s/(.*\//(/" | \
-               diff -w "${CANISTER_O}.sha1" - || \
-       { echo "${CANISTER_O} fingerprint mismatch"; exit 1; }
-
-       # verify fips_premain.c against its detached signature...
-       ${FINGERTYPE} "${PREMAIN_C}" | sed "s/(.*\//(/" | \
-               diff -w "${PREMAIN_C}.sha1" - || \
-       { echo "${PREMAIN_C} fingerprint mismatch"; exit 1; }
-
-       /bin/rm -f "${TARGET}"
-       ${CC}   ${CANISTER_O_CMD:+"${CANISTER_O_CMD}"} \
-               "${PREMAIN_C}" \
-               ${_WL_PREMAIN} "$@"
-
-       # generate signature...
-       if [ -z "${FIPS_SIG}" ]; then
-               SIG=`"${TARGET}"`
-       else
-               SIG=`"${FIPS_SIG}" -exe "${TARGET}"`
-       fi
-       /bin/rm -f "${TARGET}"
-       if [ -z "${SIG}" ]; then
-          echo "unable to collect signature"; exit 1
-       fi
-
-       # recompile with signature...
-       ${CC}   ${CANISTER_O_CMD:+"${CANISTER_O_CMD}"} \
-               -DHMAC_SHA1_SIG=\"${SIG}\" "${PREMAIN_C}" \
-               ${_WL_PREMAIN} "$@"
-       ;;
-esac
diff --git a/deps/openssl/openssl/fips/fipstests.bat b/deps/openssl/openssl/fips/fipstests.bat
deleted file mode 100644 (file)
index aae3b13..0000000
+++ /dev/null
@@ -1,229 +0,0 @@
-@echo off
-rem Test vector run script
-rem Auto generated by mkfipsscr.pl script
-rem Do not edit
-
-
-echo Running tests in .\testvectors\AES\req
-if exist ".\testvectors\AES\rsp" rd /s /q ".\testvectors\AES\rsp"
-md ".\testvectors\AES\rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CBCGFSbox128.req" ".\testvectors\AES\rsp\CBCGFSbox128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CBCGFSbox192.req" ".\testvectors\AES\rsp\CBCGFSbox192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CBCGFSbox256.req" ".\testvectors\AES\rsp\CBCGFSbox256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CBCKeySbox128.req" ".\testvectors\AES\rsp\CBCKeySbox128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CBCKeySbox192.req" ".\testvectors\AES\rsp\CBCKeySbox192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CBCKeySbox256.req" ".\testvectors\AES\rsp\CBCKeySbox256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CBCMCT128.req" ".\testvectors\AES\rsp\CBCMCT128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CBCMCT192.req" ".\testvectors\AES\rsp\CBCMCT192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CBCMCT256.req" ".\testvectors\AES\rsp\CBCMCT256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CBCMMT128.req" ".\testvectors\AES\rsp\CBCMMT128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CBCMMT192.req" ".\testvectors\AES\rsp\CBCMMT192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CBCMMT256.req" ".\testvectors\AES\rsp\CBCMMT256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CBCVarKey128.req" ".\testvectors\AES\rsp\CBCVarKey128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CBCVarKey192.req" ".\testvectors\AES\rsp\CBCVarKey192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CBCVarKey256.req" ".\testvectors\AES\rsp\CBCVarKey256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CBCVarTxt128.req" ".\testvectors\AES\rsp\CBCVarTxt128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CBCVarTxt192.req" ".\testvectors\AES\rsp\CBCVarTxt192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CBCVarTxt256.req" ".\testvectors\AES\rsp\CBCVarTxt256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB128GFSbox128.req" ".\testvectors\AES\rsp\CFB128GFSbox128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB128GFSbox192.req" ".\testvectors\AES\rsp\CFB128GFSbox192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB128GFSbox256.req" ".\testvectors\AES\rsp\CFB128GFSbox256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB128KeySbox128.req" ".\testvectors\AES\rsp\CFB128KeySbox128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB128KeySbox192.req" ".\testvectors\AES\rsp\CFB128KeySbox192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB128KeySbox256.req" ".\testvectors\AES\rsp\CFB128KeySbox256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB128MCT128.req" ".\testvectors\AES\rsp\CFB128MCT128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB128MCT192.req" ".\testvectors\AES\rsp\CFB128MCT192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB128MCT256.req" ".\testvectors\AES\rsp\CFB128MCT256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB128MMT128.req" ".\testvectors\AES\rsp\CFB128MMT128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB128MMT192.req" ".\testvectors\AES\rsp\CFB128MMT192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB128MMT256.req" ".\testvectors\AES\rsp\CFB128MMT256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB128VarKey128.req" ".\testvectors\AES\rsp\CFB128VarKey128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB128VarKey192.req" ".\testvectors\AES\rsp\CFB128VarKey192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB128VarKey256.req" ".\testvectors\AES\rsp\CFB128VarKey256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB128VarTxt128.req" ".\testvectors\AES\rsp\CFB128VarTxt128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB128VarTxt192.req" ".\testvectors\AES\rsp\CFB128VarTxt192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB128VarTxt256.req" ".\testvectors\AES\rsp\CFB128VarTxt256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB1GFSbox128.req" ".\testvectors\AES\rsp\CFB1GFSbox128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB1GFSbox192.req" ".\testvectors\AES\rsp\CFB1GFSbox192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB1GFSbox256.req" ".\testvectors\AES\rsp\CFB1GFSbox256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB1KeySbox128.req" ".\testvectors\AES\rsp\CFB1KeySbox128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB1KeySbox192.req" ".\testvectors\AES\rsp\CFB1KeySbox192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB1KeySbox256.req" ".\testvectors\AES\rsp\CFB1KeySbox256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB1MCT128.req" ".\testvectors\AES\rsp\CFB1MCT128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB1MCT192.req" ".\testvectors\AES\rsp\CFB1MCT192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB1MCT256.req" ".\testvectors\AES\rsp\CFB1MCT256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB1MMT128.req" ".\testvectors\AES\rsp\CFB1MMT128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB1MMT192.req" ".\testvectors\AES\rsp\CFB1MMT192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB1MMT256.req" ".\testvectors\AES\rsp\CFB1MMT256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB1VarKey128.req" ".\testvectors\AES\rsp\CFB1VarKey128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB1VarKey192.req" ".\testvectors\AES\rsp\CFB1VarKey192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB1VarKey256.req" ".\testvectors\AES\rsp\CFB1VarKey256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB1VarTxt128.req" ".\testvectors\AES\rsp\CFB1VarTxt128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB1VarTxt192.req" ".\testvectors\AES\rsp\CFB1VarTxt192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB1VarTxt256.req" ".\testvectors\AES\rsp\CFB1VarTxt256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB8GFSbox128.req" ".\testvectors\AES\rsp\CFB8GFSbox128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB8GFSbox192.req" ".\testvectors\AES\rsp\CFB8GFSbox192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB8GFSbox256.req" ".\testvectors\AES\rsp\CFB8GFSbox256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB8KeySbox128.req" ".\testvectors\AES\rsp\CFB8KeySbox128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB8KeySbox192.req" ".\testvectors\AES\rsp\CFB8KeySbox192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB8KeySbox256.req" ".\testvectors\AES\rsp\CFB8KeySbox256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB8MCT128.req" ".\testvectors\AES\rsp\CFB8MCT128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB8MCT192.req" ".\testvectors\AES\rsp\CFB8MCT192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB8MCT256.req" ".\testvectors\AES\rsp\CFB8MCT256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB8MMT128.req" ".\testvectors\AES\rsp\CFB8MMT128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB8MMT192.req" ".\testvectors\AES\rsp\CFB8MMT192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB8MMT256.req" ".\testvectors\AES\rsp\CFB8MMT256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB8VarKey128.req" ".\testvectors\AES\rsp\CFB8VarKey128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB8VarKey192.req" ".\testvectors\AES\rsp\CFB8VarKey192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB8VarKey256.req" ".\testvectors\AES\rsp\CFB8VarKey256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB8VarTxt128.req" ".\testvectors\AES\rsp\CFB8VarTxt128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB8VarTxt192.req" ".\testvectors\AES\rsp\CFB8VarTxt192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\CFB8VarTxt256.req" ".\testvectors\AES\rsp\CFB8VarTxt256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\ECBGFSbox128.req" ".\testvectors\AES\rsp\ECBGFSbox128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\ECBGFSbox192.req" ".\testvectors\AES\rsp\ECBGFSbox192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\ECBGFSbox256.req" ".\testvectors\AES\rsp\ECBGFSbox256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\ECBKeySbox128.req" ".\testvectors\AES\rsp\ECBKeySbox128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\ECBKeySbox192.req" ".\testvectors\AES\rsp\ECBKeySbox192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\ECBKeySbox256.req" ".\testvectors\AES\rsp\ECBKeySbox256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\ECBMCT128.req" ".\testvectors\AES\rsp\ECBMCT128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\ECBMCT192.req" ".\testvectors\AES\rsp\ECBMCT192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\ECBMCT256.req" ".\testvectors\AES\rsp\ECBMCT256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\ECBMMT128.req" ".\testvectors\AES\rsp\ECBMMT128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\ECBMMT192.req" ".\testvectors\AES\rsp\ECBMMT192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\ECBMMT256.req" ".\testvectors\AES\rsp\ECBMMT256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\ECBVarKey128.req" ".\testvectors\AES\rsp\ECBVarKey128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\ECBVarKey192.req" ".\testvectors\AES\rsp\ECBVarKey192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\ECBVarKey256.req" ".\testvectors\AES\rsp\ECBVarKey256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\ECBVarTxt128.req" ".\testvectors\AES\rsp\ECBVarTxt128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\ECBVarTxt192.req" ".\testvectors\AES\rsp\ECBVarTxt192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\ECBVarTxt256.req" ".\testvectors\AES\rsp\ECBVarTxt256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\OFBGFSbox128.req" ".\testvectors\AES\rsp\OFBGFSbox128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\OFBGFSbox192.req" ".\testvectors\AES\rsp\OFBGFSbox192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\OFBGFSbox256.req" ".\testvectors\AES\rsp\OFBGFSbox256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\OFBKeySbox128.req" ".\testvectors\AES\rsp\OFBKeySbox128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\OFBKeySbox192.req" ".\testvectors\AES\rsp\OFBKeySbox192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\OFBKeySbox256.req" ".\testvectors\AES\rsp\OFBKeySbox256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\OFBMCT128.req" ".\testvectors\AES\rsp\OFBMCT128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\OFBMCT192.req" ".\testvectors\AES\rsp\OFBMCT192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\OFBMCT256.req" ".\testvectors\AES\rsp\OFBMCT256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\OFBMMT128.req" ".\testvectors\AES\rsp\OFBMMT128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\OFBMMT192.req" ".\testvectors\AES\rsp\OFBMMT192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\OFBMMT256.req" ".\testvectors\AES\rsp\OFBMMT256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\OFBVarKey128.req" ".\testvectors\AES\rsp\OFBVarKey128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\OFBVarKey192.req" ".\testvectors\AES\rsp\OFBVarKey192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\OFBVarKey256.req" ".\testvectors\AES\rsp\OFBVarKey256.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\OFBVarTxt128.req" ".\testvectors\AES\rsp\OFBVarTxt128.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\OFBVarTxt192.req" ".\testvectors\AES\rsp\OFBVarTxt192.rsp"
-..\out32dll\fips_aesavs -f ".\testvectors\AES\req\OFBVarTxt256.req" ".\testvectors\AES\rsp\OFBVarTxt256.rsp"
-
-echo Running tests in .\testvectors\DSA\req
-if exist ".\testvectors\DSA\rsp" rd /s /q ".\testvectors\DSA\rsp"
-md ".\testvectors\DSA\rsp"
-..\out32dll\fips_dssvs keypair < ".\testvectors\DSA\req\KeyPair.req" > ".\testvectors\DSA\rsp\KeyPair.rsp"
-..\out32dll\fips_dssvs pqg < ".\testvectors\DSA\req\PQGGen.req" > ".\testvectors\DSA\rsp\PQGGen.rsp"
-..\out32dll\fips_dssvs siggen < ".\testvectors\DSA\req\SigGen.req" > ".\testvectors\DSA\rsp\SigGen.rsp"
-..\out32dll\fips_dssvs sigver < ".\testvectors\DSA\req\SigVer.req" > ".\testvectors\DSA\rsp\SigVer.rsp"
-
-echo Running tests in .\testvectors\HMAC\req
-if exist ".\testvectors\HMAC\rsp" rd /s /q ".\testvectors\HMAC\rsp"
-md ".\testvectors\HMAC\rsp"
-..\out32dll\fips_hmactest < ".\testvectors\HMAC\req\HMAC.req" > ".\testvectors\HMAC\rsp\HMAC.rsp"
-
-echo Running tests in .\testvectors\RNG\req
-if exist ".\testvectors\RNG\rsp" rd /s /q ".\testvectors\RNG\rsp"
-md ".\testvectors\RNG\rsp"
-..\out32dll\fips_rngvs mct < ".\testvectors\RNG\req\ANSI931_AES128MCT.req" > ".\testvectors\RNG\rsp\ANSI931_AES128MCT.rsp"
-..\out32dll\fips_rngvs vst < ".\testvectors\RNG\req\ANSI931_AES128VST.req" > ".\testvectors\RNG\rsp\ANSI931_AES128VST.rsp"
-..\out32dll\fips_rngvs mct < ".\testvectors\RNG\req\ANSI931_AES192MCT.req" > ".\testvectors\RNG\rsp\ANSI931_AES192MCT.rsp"
-..\out32dll\fips_rngvs vst < ".\testvectors\RNG\req\ANSI931_AES192VST.req" > ".\testvectors\RNG\rsp\ANSI931_AES192VST.rsp"
-..\out32dll\fips_rngvs mct < ".\testvectors\RNG\req\ANSI931_AES256MCT.req" > ".\testvectors\RNG\rsp\ANSI931_AES256MCT.rsp"
-..\out32dll\fips_rngvs vst < ".\testvectors\RNG\req\ANSI931_AES256VST.req" > ".\testvectors\RNG\rsp\ANSI931_AES256VST.rsp"
-
-echo Running tests in .\testvectors\RSA\req
-if exist ".\testvectors\RSA\rsp" rd /s /q ".\testvectors\RSA\rsp"
-md ".\testvectors\RSA\rsp"
-..\out32dll\fips_rsagtest < ".\testvectors\RSA\req\KeyGenRSA.req" > ".\testvectors\RSA\rsp\KeyGenRSA.rsp"
-..\out32dll\fips_rsastest < ".\testvectors\RSA\req\SigGen15.req" > ".\testvectors\RSA\rsp\SigGen15.rsp"
-..\out32dll\fips_rsastest -saltlen 0 < ".\testvectors\RSA\req\SigGenPSS.req" > ".\testvectors\RSA\rsp\SigGenPSS.rsp"
-..\out32dll\fips_rsastest -x931 < ".\testvectors\RSA\req\SigGenRSA.req" > ".\testvectors\RSA\rsp\SigGenRSA.rsp"
-..\out32dll\fips_rsavtest < ".\testvectors\RSA\req\SigVer15.req" > ".\testvectors\RSA\rsp\SigVer15.rsp"
-..\out32dll\fips_rsavtest -saltlen 0 < ".\testvectors\RSA\req\SigVerPSS.req" > ".\testvectors\RSA\rsp\SigVerPSS.rsp"
-..\out32dll\fips_rsavtest -x931 < ".\testvectors\RSA\req\SigVerRSA.req" > ".\testvectors\RSA\rsp\SigVerRSA.rsp"
-
-echo Running tests in .\testvectors\SHA\req
-if exist ".\testvectors\SHA\rsp" rd /s /q ".\testvectors\SHA\rsp"
-md ".\testvectors\SHA\rsp"
-..\out32dll\fips_shatest < ".\testvectors\SHA\req\SHA1LongMsg.req" > ".\testvectors\SHA\rsp\SHA1LongMsg.rsp"
-..\out32dll\fips_shatest < ".\testvectors\SHA\req\SHA1Monte.req" > ".\testvectors\SHA\rsp\SHA1Monte.rsp"
-..\out32dll\fips_shatest < ".\testvectors\SHA\req\SHA1ShortMsg.req" > ".\testvectors\SHA\rsp\SHA1ShortMsg.rsp"
-..\out32dll\fips_shatest < ".\testvectors\SHA\req\SHA224LongMsg.req" > ".\testvectors\SHA\rsp\SHA224LongMsg.rsp"
-..\out32dll\fips_shatest < ".\testvectors\SHA\req\SHA224Monte.req" > ".\testvectors\SHA\rsp\SHA224Monte.rsp"
-..\out32dll\fips_shatest < ".\testvectors\SHA\req\SHA224ShortMsg.req" > ".\testvectors\SHA\rsp\SHA224ShortMsg.rsp"
-..\out32dll\fips_shatest < ".\testvectors\SHA\req\SHA256LongMsg.req" > ".\testvectors\SHA\rsp\SHA256LongMsg.rsp"
-..\out32dll\fips_shatest < ".\testvectors\SHA\req\SHA256Monte.req" > ".\testvectors\SHA\rsp\SHA256Monte.rsp"
-..\out32dll\fips_shatest < ".\testvectors\SHA\req\SHA256ShortMsg.req" > ".\testvectors\SHA\rsp\SHA256ShortMsg.rsp"
-..\out32dll\fips_shatest < ".\testvectors\SHA\req\SHA384LongMsg.req" > ".\testvectors\SHA\rsp\SHA384LongMsg.rsp"
-..\out32dll\fips_shatest < ".\testvectors\SHA\req\SHA384Monte.req" > ".\testvectors\SHA\rsp\SHA384Monte.rsp"
-..\out32dll\fips_shatest < ".\testvectors\SHA\req\SHA384ShortMsg.req" > ".\testvectors\SHA\rsp\SHA384ShortMsg.rsp"
-..\out32dll\fips_shatest < ".\testvectors\SHA\req\SHA512LongMsg.req" > ".\testvectors\SHA\rsp\SHA512LongMsg.rsp"
-..\out32dll\fips_shatest < ".\testvectors\SHA\req\SHA512Monte.req" > ".\testvectors\SHA\rsp\SHA512Monte.rsp"
-..\out32dll\fips_shatest < ".\testvectors\SHA\req\SHA512ShortMsg.req" > ".\testvectors\SHA\rsp\SHA512ShortMsg.rsp"
-
-echo Running tests in .\testvectors\TDES\req
-if exist ".\testvectors\TDES\rsp" rd /s /q ".\testvectors\TDES\rsp"
-md ".\testvectors\TDES\rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCBCinvperm.req" ".\testvectors\TDES\rsp\TCBCinvperm.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCBCMMT1.req" ".\testvectors\TDES\rsp\TCBCMMT1.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCBCMMT2.req" ".\testvectors\TDES\rsp\TCBCMMT2.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCBCMMT3.req" ".\testvectors\TDES\rsp\TCBCMMT3.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCBCMonte1.req" ".\testvectors\TDES\rsp\TCBCMonte1.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCBCMonte2.req" ".\testvectors\TDES\rsp\TCBCMonte2.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCBCMonte3.req" ".\testvectors\TDES\rsp\TCBCMonte3.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCBCpermop.req" ".\testvectors\TDES\rsp\TCBCpermop.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCBCsubtab.req" ".\testvectors\TDES\rsp\TCBCsubtab.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCBCvarkey.req" ".\testvectors\TDES\rsp\TCBCvarkey.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCBCvartext.req" ".\testvectors\TDES\rsp\TCBCvartext.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCFB64invperm.req" ".\testvectors\TDES\rsp\TCFB64invperm.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCFB64MMT1.req" ".\testvectors\TDES\rsp\TCFB64MMT1.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCFB64MMT2.req" ".\testvectors\TDES\rsp\TCFB64MMT2.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCFB64MMT3.req" ".\testvectors\TDES\rsp\TCFB64MMT3.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCFB64Monte1.req" ".\testvectors\TDES\rsp\TCFB64Monte1.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCFB64Monte2.req" ".\testvectors\TDES\rsp\TCFB64Monte2.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCFB64Monte3.req" ".\testvectors\TDES\rsp\TCFB64Monte3.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCFB64permop.req" ".\testvectors\TDES\rsp\TCFB64permop.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCFB64subtab.req" ".\testvectors\TDES\rsp\TCFB64subtab.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCFB64varkey.req" ".\testvectors\TDES\rsp\TCFB64varkey.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCFB64vartext.req" ".\testvectors\TDES\rsp\TCFB64vartext.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCFB8invperm.req" ".\testvectors\TDES\rsp\TCFB8invperm.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCFB8MMT1.req" ".\testvectors\TDES\rsp\TCFB8MMT1.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCFB8MMT2.req" ".\testvectors\TDES\rsp\TCFB8MMT2.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCFB8MMT3.req" ".\testvectors\TDES\rsp\TCFB8MMT3.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCFB8Monte1.req" ".\testvectors\TDES\rsp\TCFB8Monte1.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCFB8Monte2.req" ".\testvectors\TDES\rsp\TCFB8Monte2.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCFB8Monte3.req" ".\testvectors\TDES\rsp\TCFB8Monte3.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCFB8permop.req" ".\testvectors\TDES\rsp\TCFB8permop.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCFB8subtab.req" ".\testvectors\TDES\rsp\TCFB8subtab.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCFB8varkey.req" ".\testvectors\TDES\rsp\TCFB8varkey.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TCFB8vartext.req" ".\testvectors\TDES\rsp\TCFB8vartext.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TECBinvperm.req" ".\testvectors\TDES\rsp\TECBinvperm.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TECBMMT1.req" ".\testvectors\TDES\rsp\TECBMMT1.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TECBMMT2.req" ".\testvectors\TDES\rsp\TECBMMT2.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TECBMMT3.req" ".\testvectors\TDES\rsp\TECBMMT3.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TECBMonte1.req" ".\testvectors\TDES\rsp\TECBMonte1.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TECBMonte2.req" ".\testvectors\TDES\rsp\TECBMonte2.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TECBMonte3.req" ".\testvectors\TDES\rsp\TECBMonte3.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TECBpermop.req" ".\testvectors\TDES\rsp\TECBpermop.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TECBsubtab.req" ".\testvectors\TDES\rsp\TECBsubtab.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TECBvarkey.req" ".\testvectors\TDES\rsp\TECBvarkey.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TECBvartext.req" ".\testvectors\TDES\rsp\TECBvartext.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TOFBinvperm.req" ".\testvectors\TDES\rsp\TOFBinvperm.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TOFBMMT1.req" ".\testvectors\TDES\rsp\TOFBMMT1.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TOFBMMT2.req" ".\testvectors\TDES\rsp\TOFBMMT2.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TOFBMMT3.req" ".\testvectors\TDES\rsp\TOFBMMT3.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TOFBMonte1.req" ".\testvectors\TDES\rsp\TOFBMonte1.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TOFBMonte2.req" ".\testvectors\TDES\rsp\TOFBMonte2.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TOFBMonte3.req" ".\testvectors\TDES\rsp\TOFBMonte3.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TOFBpermop.req" ".\testvectors\TDES\rsp\TOFBpermop.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TOFBsubtab.req" ".\testvectors\TDES\rsp\TOFBsubtab.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TOFBvarkey.req" ".\testvectors\TDES\rsp\TOFBvarkey.rsp"
-..\out32dll\fips_desmovs -f ".\testvectors\TDES\req\TOFBvartext.req" ".\testvectors\TDES\rsp\TOFBvartext.rsp"
diff --git a/deps/openssl/openssl/fips/fipstests.sh b/deps/openssl/openssl/fips/fipstests.sh
deleted file mode 100644 (file)
index a351446..0000000
+++ /dev/null
@@ -1,400 +0,0 @@
-#!/bin/sh
-
-# Test vector run script
-# Auto generated by mkfipsscr.pl script
-# Do not edit
-
-
-echo Running tests in "./testvectors/AES/req"
-rm -rf "./testvectors/AES/rsp"
-mkdir "./testvectors/AES/rsp"
-
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCGFSbox128.req" "./testvectors/AES/rsp/CBCGFSbox128.rsp" || { echo "./testvectors/AES/req/CBCGFSbox128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCGFSbox192.req" "./testvectors/AES/rsp/CBCGFSbox192.rsp" || { echo "./testvectors/AES/req/CBCGFSbox192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCGFSbox256.req" "./testvectors/AES/rsp/CBCGFSbox256.rsp" || { echo "./testvectors/AES/req/CBCGFSbox256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCKeySbox128.req" "./testvectors/AES/rsp/CBCKeySbox128.rsp" || { echo "./testvectors/AES/req/CBCKeySbox128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCKeySbox192.req" "./testvectors/AES/rsp/CBCKeySbox192.rsp" || { echo "./testvectors/AES/req/CBCKeySbox192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCKeySbox256.req" "./testvectors/AES/rsp/CBCKeySbox256.rsp" || { echo "./testvectors/AES/req/CBCKeySbox256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCMCT128.req" "./testvectors/AES/rsp/CBCMCT128.rsp" || { echo "./testvectors/AES/req/CBCMCT128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCMCT192.req" "./testvectors/AES/rsp/CBCMCT192.rsp" || { echo "./testvectors/AES/req/CBCMCT192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCMCT256.req" "./testvectors/AES/rsp/CBCMCT256.rsp" || { echo "./testvectors/AES/req/CBCMCT256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCMMT128.req" "./testvectors/AES/rsp/CBCMMT128.rsp" || { echo "./testvectors/AES/req/CBCMMT128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCMMT192.req" "./testvectors/AES/rsp/CBCMMT192.rsp" || { echo "./testvectors/AES/req/CBCMMT192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCMMT256.req" "./testvectors/AES/rsp/CBCMMT256.rsp" || { echo "./testvectors/AES/req/CBCMMT256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCVarKey128.req" "./testvectors/AES/rsp/CBCVarKey128.rsp" || { echo "./testvectors/AES/req/CBCVarKey128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCVarKey192.req" "./testvectors/AES/rsp/CBCVarKey192.rsp" || { echo "./testvectors/AES/req/CBCVarKey192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCVarKey256.req" "./testvectors/AES/rsp/CBCVarKey256.rsp" || { echo "./testvectors/AES/req/CBCVarKey256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCVarTxt128.req" "./testvectors/AES/rsp/CBCVarTxt128.rsp" || { echo "./testvectors/AES/req/CBCVarTxt128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCVarTxt192.req" "./testvectors/AES/rsp/CBCVarTxt192.rsp" || { echo "./testvectors/AES/req/CBCVarTxt192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCVarTxt256.req" "./testvectors/AES/rsp/CBCVarTxt256.rsp" || { echo "./testvectors/AES/req/CBCVarTxt256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128GFSbox128.req" "./testvectors/AES/rsp/CFB128GFSbox128.rsp" || { echo "./testvectors/AES/req/CFB128GFSbox128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128GFSbox192.req" "./testvectors/AES/rsp/CFB128GFSbox192.rsp" || { echo "./testvectors/AES/req/CFB128GFSbox192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128GFSbox256.req" "./testvectors/AES/rsp/CFB128GFSbox256.rsp" || { echo "./testvectors/AES/req/CFB128GFSbox256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128KeySbox128.req" "./testvectors/AES/rsp/CFB128KeySbox128.rsp" || { echo "./testvectors/AES/req/CFB128KeySbox128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128KeySbox192.req" "./testvectors/AES/rsp/CFB128KeySbox192.rsp" || { echo "./testvectors/AES/req/CFB128KeySbox192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128KeySbox256.req" "./testvectors/AES/rsp/CFB128KeySbox256.rsp" || { echo "./testvectors/AES/req/CFB128KeySbox256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128MCT128.req" "./testvectors/AES/rsp/CFB128MCT128.rsp" || { echo "./testvectors/AES/req/CFB128MCT128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128MCT192.req" "./testvectors/AES/rsp/CFB128MCT192.rsp" || { echo "./testvectors/AES/req/CFB128MCT192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128MCT256.req" "./testvectors/AES/rsp/CFB128MCT256.rsp" || { echo "./testvectors/AES/req/CFB128MCT256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128MMT128.req" "./testvectors/AES/rsp/CFB128MMT128.rsp" || { echo "./testvectors/AES/req/CFB128MMT128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128MMT192.req" "./testvectors/AES/rsp/CFB128MMT192.rsp" || { echo "./testvectors/AES/req/CFB128MMT192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128MMT256.req" "./testvectors/AES/rsp/CFB128MMT256.rsp" || { echo "./testvectors/AES/req/CFB128MMT256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128VarKey128.req" "./testvectors/AES/rsp/CFB128VarKey128.rsp" || { echo "./testvectors/AES/req/CFB128VarKey128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128VarKey192.req" "./testvectors/AES/rsp/CFB128VarKey192.rsp" || { echo "./testvectors/AES/req/CFB128VarKey192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128VarKey256.req" "./testvectors/AES/rsp/CFB128VarKey256.rsp" || { echo "./testvectors/AES/req/CFB128VarKey256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128VarTxt128.req" "./testvectors/AES/rsp/CFB128VarTxt128.rsp" || { echo "./testvectors/AES/req/CFB128VarTxt128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128VarTxt192.req" "./testvectors/AES/rsp/CFB128VarTxt192.rsp" || { echo "./testvectors/AES/req/CFB128VarTxt192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128VarTxt256.req" "./testvectors/AES/rsp/CFB128VarTxt256.rsp" || { echo "./testvectors/AES/req/CFB128VarTxt256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1GFSbox128.req" "./testvectors/AES/rsp/CFB1GFSbox128.rsp" || { echo "./testvectors/AES/req/CFB1GFSbox128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1GFSbox192.req" "./testvectors/AES/rsp/CFB1GFSbox192.rsp" || { echo "./testvectors/AES/req/CFB1GFSbox192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1GFSbox256.req" "./testvectors/AES/rsp/CFB1GFSbox256.rsp" || { echo "./testvectors/AES/req/CFB1GFSbox256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1KeySbox128.req" "./testvectors/AES/rsp/CFB1KeySbox128.rsp" || { echo "./testvectors/AES/req/CFB1KeySbox128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1KeySbox192.req" "./testvectors/AES/rsp/CFB1KeySbox192.rsp" || { echo "./testvectors/AES/req/CFB1KeySbox192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1KeySbox256.req" "./testvectors/AES/rsp/CFB1KeySbox256.rsp" || { echo "./testvectors/AES/req/CFB1KeySbox256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1MCT128.req" "./testvectors/AES/rsp/CFB1MCT128.rsp" || { echo "./testvectors/AES/req/CFB1MCT128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1MCT192.req" "./testvectors/AES/rsp/CFB1MCT192.rsp" || { echo "./testvectors/AES/req/CFB1MCT192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1MCT256.req" "./testvectors/AES/rsp/CFB1MCT256.rsp" || { echo "./testvectors/AES/req/CFB1MCT256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1MMT128.req" "./testvectors/AES/rsp/CFB1MMT128.rsp" || { echo "./testvectors/AES/req/CFB1MMT128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1MMT192.req" "./testvectors/AES/rsp/CFB1MMT192.rsp" || { echo "./testvectors/AES/req/CFB1MMT192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1MMT256.req" "./testvectors/AES/rsp/CFB1MMT256.rsp" || { echo "./testvectors/AES/req/CFB1MMT256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1VarKey128.req" "./testvectors/AES/rsp/CFB1VarKey128.rsp" || { echo "./testvectors/AES/req/CFB1VarKey128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1VarKey192.req" "./testvectors/AES/rsp/CFB1VarKey192.rsp" || { echo "./testvectors/AES/req/CFB1VarKey192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1VarKey256.req" "./testvectors/AES/rsp/CFB1VarKey256.rsp" || { echo "./testvectors/AES/req/CFB1VarKey256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1VarTxt128.req" "./testvectors/AES/rsp/CFB1VarTxt128.rsp" || { echo "./testvectors/AES/req/CFB1VarTxt128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1VarTxt192.req" "./testvectors/AES/rsp/CFB1VarTxt192.rsp" || { echo "./testvectors/AES/req/CFB1VarTxt192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1VarTxt256.req" "./testvectors/AES/rsp/CFB1VarTxt256.rsp" || { echo "./testvectors/AES/req/CFB1VarTxt256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8GFSbox128.req" "./testvectors/AES/rsp/CFB8GFSbox128.rsp" || { echo "./testvectors/AES/req/CFB8GFSbox128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8GFSbox192.req" "./testvectors/AES/rsp/CFB8GFSbox192.rsp" || { echo "./testvectors/AES/req/CFB8GFSbox192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8GFSbox256.req" "./testvectors/AES/rsp/CFB8GFSbox256.rsp" || { echo "./testvectors/AES/req/CFB8GFSbox256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8KeySbox128.req" "./testvectors/AES/rsp/CFB8KeySbox128.rsp" || { echo "./testvectors/AES/req/CFB8KeySbox128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8KeySbox192.req" "./testvectors/AES/rsp/CFB8KeySbox192.rsp" || { echo "./testvectors/AES/req/CFB8KeySbox192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8KeySbox256.req" "./testvectors/AES/rsp/CFB8KeySbox256.rsp" || { echo "./testvectors/AES/req/CFB8KeySbox256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8MCT128.req" "./testvectors/AES/rsp/CFB8MCT128.rsp" || { echo "./testvectors/AES/req/CFB8MCT128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8MCT192.req" "./testvectors/AES/rsp/CFB8MCT192.rsp" || { echo "./testvectors/AES/req/CFB8MCT192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8MCT256.req" "./testvectors/AES/rsp/CFB8MCT256.rsp" || { echo "./testvectors/AES/req/CFB8MCT256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8MMT128.req" "./testvectors/AES/rsp/CFB8MMT128.rsp" || { echo "./testvectors/AES/req/CFB8MMT128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8MMT192.req" "./testvectors/AES/rsp/CFB8MMT192.rsp" || { echo "./testvectors/AES/req/CFB8MMT192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8MMT256.req" "./testvectors/AES/rsp/CFB8MMT256.rsp" || { echo "./testvectors/AES/req/CFB8MMT256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8VarKey128.req" "./testvectors/AES/rsp/CFB8VarKey128.rsp" || { echo "./testvectors/AES/req/CFB8VarKey128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8VarKey192.req" "./testvectors/AES/rsp/CFB8VarKey192.rsp" || { echo "./testvectors/AES/req/CFB8VarKey192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8VarKey256.req" "./testvectors/AES/rsp/CFB8VarKey256.rsp" || { echo "./testvectors/AES/req/CFB8VarKey256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8VarTxt128.req" "./testvectors/AES/rsp/CFB8VarTxt128.rsp" || { echo "./testvectors/AES/req/CFB8VarTxt128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8VarTxt192.req" "./testvectors/AES/rsp/CFB8VarTxt192.rsp" || { echo "./testvectors/AES/req/CFB8VarTxt192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8VarTxt256.req" "./testvectors/AES/rsp/CFB8VarTxt256.rsp" || { echo "./testvectors/AES/req/CFB8VarTxt256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBGFSbox128.req" "./testvectors/AES/rsp/ECBGFSbox128.rsp" || { echo "./testvectors/AES/req/ECBGFSbox128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBGFSbox192.req" "./testvectors/AES/rsp/ECBGFSbox192.rsp" || { echo "./testvectors/AES/req/ECBGFSbox192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBGFSbox256.req" "./testvectors/AES/rsp/ECBGFSbox256.rsp" || { echo "./testvectors/AES/req/ECBGFSbox256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBKeySbox128.req" "./testvectors/AES/rsp/ECBKeySbox128.rsp" || { echo "./testvectors/AES/req/ECBKeySbox128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBKeySbox192.req" "./testvectors/AES/rsp/ECBKeySbox192.rsp" || { echo "./testvectors/AES/req/ECBKeySbox192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBKeySbox256.req" "./testvectors/AES/rsp/ECBKeySbox256.rsp" || { echo "./testvectors/AES/req/ECBKeySbox256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBMCT128.req" "./testvectors/AES/rsp/ECBMCT128.rsp" || { echo "./testvectors/AES/req/ECBMCT128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBMCT192.req" "./testvectors/AES/rsp/ECBMCT192.rsp" || { echo "./testvectors/AES/req/ECBMCT192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBMCT256.req" "./testvectors/AES/rsp/ECBMCT256.rsp" || { echo "./testvectors/AES/req/ECBMCT256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBMMT128.req" "./testvectors/AES/rsp/ECBMMT128.rsp" || { echo "./testvectors/AES/req/ECBMMT128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBMMT192.req" "./testvectors/AES/rsp/ECBMMT192.rsp" || { echo "./testvectors/AES/req/ECBMMT192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBMMT256.req" "./testvectors/AES/rsp/ECBMMT256.rsp" || { echo "./testvectors/AES/req/ECBMMT256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBVarKey128.req" "./testvectors/AES/rsp/ECBVarKey128.rsp" || { echo "./testvectors/AES/req/ECBVarKey128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBVarKey192.req" "./testvectors/AES/rsp/ECBVarKey192.rsp" || { echo "./testvectors/AES/req/ECBVarKey192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBVarKey256.req" "./testvectors/AES/rsp/ECBVarKey256.rsp" || { echo "./testvectors/AES/req/ECBVarKey256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBVarTxt128.req" "./testvectors/AES/rsp/ECBVarTxt128.rsp" || { echo "./testvectors/AES/req/ECBVarTxt128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBVarTxt192.req" "./testvectors/AES/rsp/ECBVarTxt192.rsp" || { echo "./testvectors/AES/req/ECBVarTxt192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBVarTxt256.req" "./testvectors/AES/rsp/ECBVarTxt256.rsp" || { echo "./testvectors/AES/req/ECBVarTxt256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBGFSbox128.req" "./testvectors/AES/rsp/OFBGFSbox128.rsp" || { echo "./testvectors/AES/req/OFBGFSbox128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBGFSbox192.req" "./testvectors/AES/rsp/OFBGFSbox192.rsp" || { echo "./testvectors/AES/req/OFBGFSbox192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBGFSbox256.req" "./testvectors/AES/rsp/OFBGFSbox256.rsp" || { echo "./testvectors/AES/req/OFBGFSbox256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBKeySbox128.req" "./testvectors/AES/rsp/OFBKeySbox128.rsp" || { echo "./testvectors/AES/req/OFBKeySbox128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBKeySbox192.req" "./testvectors/AES/rsp/OFBKeySbox192.rsp" || { echo "./testvectors/AES/req/OFBKeySbox192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBKeySbox256.req" "./testvectors/AES/rsp/OFBKeySbox256.rsp" || { echo "./testvectors/AES/req/OFBKeySbox256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBMCT128.req" "./testvectors/AES/rsp/OFBMCT128.rsp" || { echo "./testvectors/AES/req/OFBMCT128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBMCT192.req" "./testvectors/AES/rsp/OFBMCT192.rsp" || { echo "./testvectors/AES/req/OFBMCT192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBMCT256.req" "./testvectors/AES/rsp/OFBMCT256.rsp" || { echo "./testvectors/AES/req/OFBMCT256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBMMT128.req" "./testvectors/AES/rsp/OFBMMT128.rsp" || { echo "./testvectors/AES/req/OFBMMT128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBMMT192.req" "./testvectors/AES/rsp/OFBMMT192.rsp" || { echo "./testvectors/AES/req/OFBMMT192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBMMT256.req" "./testvectors/AES/rsp/OFBMMT256.rsp" || { echo "./testvectors/AES/req/OFBMMT256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBVarKey128.req" "./testvectors/AES/rsp/OFBVarKey128.rsp" || { echo "./testvectors/AES/req/OFBVarKey128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBVarKey192.req" "./testvectors/AES/rsp/OFBVarKey192.rsp" || { echo "./testvectors/AES/req/OFBVarKey192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBVarKey256.req" "./testvectors/AES/rsp/OFBVarKey256.rsp" || { echo "./testvectors/AES/req/OFBVarKey256.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBVarTxt128.req" "./testvectors/AES/rsp/OFBVarTxt128.rsp" || { echo "./testvectors/AES/req/OFBVarTxt128.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBVarTxt192.req" "./testvectors/AES/rsp/OFBVarTxt192.rsp" || { echo "./testvectors/AES/req/OFBVarTxt192.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBVarTxt256.req" "./testvectors/AES/rsp/OFBVarTxt256.rsp" || { echo "./testvectors/AES/req/OFBVarTxt256.req failure" ; exit 1 
-}
-
-echo Running tests in "./testvectors/DSA/req"
-rm -rf "./testvectors/DSA/rsp"
-mkdir "./testvectors/DSA/rsp"
-
-../util/shlib_wrap.sh ../test/fips_dssvs keypair < "./testvectors/DSA/req/KeyPair.req" > "./testvectors/DSA/rsp/KeyPair.rsp" || { echo "./testvectors/DSA/req/KeyPair.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_dssvs pqg < "./testvectors/DSA/req/PQGGen.req" > "./testvectors/DSA/rsp/PQGGen.rsp" || { echo "./testvectors/DSA/req/PQGGen.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_dssvs siggen < "./testvectors/DSA/req/SigGen.req" > "./testvectors/DSA/rsp/SigGen.rsp" || { echo "./testvectors/DSA/req/SigGen.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_dssvs sigver < "./testvectors/DSA/req/SigVer.req" > "./testvectors/DSA/rsp/SigVer.rsp" || { echo "./testvectors/DSA/req/SigVer.req failure" ; exit 1; }
-
-echo Running tests in "./testvectors/HMAC/req"
-rm -rf "./testvectors/HMAC/rsp"
-mkdir "./testvectors/HMAC/rsp"
-
-../util/shlib_wrap.sh ../test/fips_hmactest < "./testvectors/HMAC/req/HMAC.req" > "./testvectors/HMAC/rsp/HMAC.rsp" || { echo "./testvectors/HMAC/req/HMAC.req failure" ; exit 1; }
-
-echo Running tests in "./testvectors/RNG/req"
-rm -rf "./testvectors/RNG/rsp"
-mkdir "./testvectors/RNG/rsp"
-
-../util/shlib_wrap.sh ../test/fips_rngvs mct < "./testvectors/RNG/req/ANSI931_AES128MCT.req" > "./testvectors/RNG/rsp/ANSI931_AES128MCT.rsp" || { echo "./testvectors/RNG/req/ANSI931_AES128MCT.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_rngvs vst < "./testvectors/RNG/req/ANSI931_AES128VST.req" > "./testvectors/RNG/rsp/ANSI931_AES128VST.rsp" || { echo "./testvectors/RNG/req/ANSI931_AES128VST.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_rngvs mct < "./testvectors/RNG/req/ANSI931_AES192MCT.req" > "./testvectors/RNG/rsp/ANSI931_AES192MCT.rsp" || { echo "./testvectors/RNG/req/ANSI931_AES192MCT.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_rngvs vst < "./testvectors/RNG/req/ANSI931_AES192VST.req" > "./testvectors/RNG/rsp/ANSI931_AES192VST.rsp" || { echo "./testvectors/RNG/req/ANSI931_AES192VST.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_rngvs mct < "./testvectors/RNG/req/ANSI931_AES256MCT.req" > "./testvectors/RNG/rsp/ANSI931_AES256MCT.rsp" || { echo "./testvectors/RNG/req/ANSI931_AES256MCT.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_rngvs vst < "./testvectors/RNG/req/ANSI931_AES256VST.req" > "./testvectors/RNG/rsp/ANSI931_AES256VST.rsp" || { echo "./testvectors/RNG/req/ANSI931_AES256VST.req failure" ; exit 1; }
-
-echo Running tests in "./testvectors/RSA/req"
-rm -rf "./testvectors/RSA/rsp"
-mkdir "./testvectors/RSA/rsp"
-
-../util/shlib_wrap.sh ../test/fips_rsagtest < "./testvectors/RSA/req/KeyGenRSA.req" > "./testvectors/RSA/rsp/KeyGenRSA.rsp" || { echo "./testvectors/RSA/req/KeyGenRSA.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_rsastest < "./testvectors/RSA/req/SigGen15.req" > "./testvectors/RSA/rsp/SigGen15.rsp" || { echo "./testvectors/RSA/req/SigGen15.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_rsastest -saltlen 0 < "./testvectors/RSA/req/SigGenPSS.req" > "./testvectors/RSA/rsp/SigGenPSS.rsp" || { echo "./testvectors/RSA/req/SigGenPSS.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_rsastest -x931 < "./testvectors/RSA/req/SigGenRSA.req" > "./testvectors/RSA/rsp/SigGenRSA.rsp" || { echo "./testvectors/RSA/req/SigGenRSA.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_rsavtest < "./testvectors/RSA/req/SigVer15.req" > "./testvectors/RSA/rsp/SigVer15.rsp" || { echo "./testvectors/RSA/req/SigVer15.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_rsavtest -saltlen 0 < "./testvectors/RSA/req/SigVerPSS.req" > "./testvectors/RSA/rsp/SigVerPSS.rsp" || { echo "./testvectors/RSA/req/SigVerPSS.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_rsavtest -x931 < "./testvectors/RSA/req/SigVerRSA.req" > "./testvectors/RSA/rsp/SigVerRSA.rsp" || { echo "./testvectors/RSA/req/SigVerRSA.req failure" ; exit 1; }
-
-echo Running tests in "./testvectors/SHA/req"
-rm -rf "./testvectors/SHA/rsp"
-mkdir "./testvectors/SHA/rsp"
-
-../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA1LongMsg.req" > "./testvectors/SHA/rsp/SHA1LongMsg.rsp" || { echo "./testvectors/SHA/req/SHA1LongMsg.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA1Monte.req" > "./testvectors/SHA/rsp/SHA1Monte.rsp" || { echo "./testvectors/SHA/req/SHA1Monte.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA1ShortMsg.req" > "./testvectors/SHA/rsp/SHA1ShortMsg.rsp" || { echo "./testvectors/SHA/req/SHA1ShortMsg.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA224LongMsg.req" > "./testvectors/SHA/rsp/SHA224LongMsg.rsp" || { echo "./testvectors/SHA/req/SHA224LongMsg.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA224Monte.req" > "./testvectors/SHA/rsp/SHA224Monte.rsp" || { echo "./testvectors/SHA/req/SHA224Monte.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA224ShortMsg.req" > "./testvectors/SHA/rsp/SHA224ShortMsg.rsp" || { echo "./testvectors/SHA/req/SHA224ShortMsg.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA256LongMsg.req" > "./testvectors/SHA/rsp/SHA256LongMsg.rsp" || { echo "./testvectors/SHA/req/SHA256LongMsg.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA256Monte.req" > "./testvectors/SHA/rsp/SHA256Monte.rsp" || { echo "./testvectors/SHA/req/SHA256Monte.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA256ShortMsg.req" > "./testvectors/SHA/rsp/SHA256ShortMsg.rsp" || { echo "./testvectors/SHA/req/SHA256ShortMsg.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA384LongMsg.req" > "./testvectors/SHA/rsp/SHA384LongMsg.rsp" || { echo "./testvectors/SHA/req/SHA384LongMsg.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA384Monte.req" > "./testvectors/SHA/rsp/SHA384Monte.rsp" || { echo "./testvectors/SHA/req/SHA384Monte.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA384ShortMsg.req" > "./testvectors/SHA/rsp/SHA384ShortMsg.rsp" || { echo "./testvectors/SHA/req/SHA384ShortMsg.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA512LongMsg.req" > "./testvectors/SHA/rsp/SHA512LongMsg.rsp" || { echo "./testvectors/SHA/req/SHA512LongMsg.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA512Monte.req" > "./testvectors/SHA/rsp/SHA512Monte.rsp" || { echo "./testvectors/SHA/req/SHA512Monte.req failure" ; exit 1; }
-../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA512ShortMsg.req" > "./testvectors/SHA/rsp/SHA512ShortMsg.rsp" || { echo "./testvectors/SHA/req/SHA512ShortMsg.req failure" ; exit 1; }
-
-echo Running tests in "./testvectors/TDES/req"
-rm -rf "./testvectors/TDES/rsp"
-mkdir "./testvectors/TDES/rsp"
-
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCBCinvperm.req" "./testvectors/TDES/rsp/TCBCinvperm.rsp" || { echo "./testvectors/TDES/req/TCBCinvperm.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCBCMMT1.req" "./testvectors/TDES/rsp/TCBCMMT1.rsp" || { echo "./testvectors/TDES/req/TCBCMMT1.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCBCMMT2.req" "./testvectors/TDES/rsp/TCBCMMT2.rsp" || { echo "./testvectors/TDES/req/TCBCMMT2.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCBCMMT3.req" "./testvectors/TDES/rsp/TCBCMMT3.rsp" || { echo "./testvectors/TDES/req/TCBCMMT3.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCBCMonte1.req" "./testvectors/TDES/rsp/TCBCMonte1.rsp" || { echo "./testvectors/TDES/req/TCBCMonte1.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCBCMonte2.req" "./testvectors/TDES/rsp/TCBCMonte2.rsp" || { echo "./testvectors/TDES/req/TCBCMonte2.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCBCMonte3.req" "./testvectors/TDES/rsp/TCBCMonte3.rsp" || { echo "./testvectors/TDES/req/TCBCMonte3.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCBCpermop.req" "./testvectors/TDES/rsp/TCBCpermop.rsp" || { echo "./testvectors/TDES/req/TCBCpermop.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCBCsubtab.req" "./testvectors/TDES/rsp/TCBCsubtab.rsp" || { echo "./testvectors/TDES/req/TCBCsubtab.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCBCvarkey.req" "./testvectors/TDES/rsp/TCBCvarkey.rsp" || { echo "./testvectors/TDES/req/TCBCvarkey.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCBCvartext.req" "./testvectors/TDES/rsp/TCBCvartext.rsp" || { echo "./testvectors/TDES/req/TCBCvartext.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB64invperm.req" "./testvectors/TDES/rsp/TCFB64invperm.rsp" || { echo "./testvectors/TDES/req/TCFB64invperm.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB64MMT1.req" "./testvectors/TDES/rsp/TCFB64MMT1.rsp" || { echo "./testvectors/TDES/req/TCFB64MMT1.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB64MMT2.req" "./testvectors/TDES/rsp/TCFB64MMT2.rsp" || { echo "./testvectors/TDES/req/TCFB64MMT2.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB64MMT3.req" "./testvectors/TDES/rsp/TCFB64MMT3.rsp" || { echo "./testvectors/TDES/req/TCFB64MMT3.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB64Monte1.req" "./testvectors/TDES/rsp/TCFB64Monte1.rsp" || { echo "./testvectors/TDES/req/TCFB64Monte1.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB64Monte2.req" "./testvectors/TDES/rsp/TCFB64Monte2.rsp" || { echo "./testvectors/TDES/req/TCFB64Monte2.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB64Monte3.req" "./testvectors/TDES/rsp/TCFB64Monte3.rsp" || { echo "./testvectors/TDES/req/TCFB64Monte3.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB64permop.req" "./testvectors/TDES/rsp/TCFB64permop.rsp" || { echo "./testvectors/TDES/req/TCFB64permop.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB64subtab.req" "./testvectors/TDES/rsp/TCFB64subtab.rsp" || { echo "./testvectors/TDES/req/TCFB64subtab.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB64varkey.req" "./testvectors/TDES/rsp/TCFB64varkey.rsp" || { echo "./testvectors/TDES/req/TCFB64varkey.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB64vartext.req" "./testvectors/TDES/rsp/TCFB64vartext.rsp" || { echo "./testvectors/TDES/req/TCFB64vartext.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB8invperm.req" "./testvectors/TDES/rsp/TCFB8invperm.rsp" || { echo "./testvectors/TDES/req/TCFB8invperm.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB8MMT1.req" "./testvectors/TDES/rsp/TCFB8MMT1.rsp" || { echo "./testvectors/TDES/req/TCFB8MMT1.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB8MMT2.req" "./testvectors/TDES/rsp/TCFB8MMT2.rsp" || { echo "./testvectors/TDES/req/TCFB8MMT2.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB8MMT3.req" "./testvectors/TDES/rsp/TCFB8MMT3.rsp" || { echo "./testvectors/TDES/req/TCFB8MMT3.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB8Monte1.req" "./testvectors/TDES/rsp/TCFB8Monte1.rsp" || { echo "./testvectors/TDES/req/TCFB8Monte1.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB8Monte2.req" "./testvectors/TDES/rsp/TCFB8Monte2.rsp" || { echo "./testvectors/TDES/req/TCFB8Monte2.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB8Monte3.req" "./testvectors/TDES/rsp/TCFB8Monte3.rsp" || { echo "./testvectors/TDES/req/TCFB8Monte3.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB8permop.req" "./testvectors/TDES/rsp/TCFB8permop.rsp" || { echo "./testvectors/TDES/req/TCFB8permop.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB8subtab.req" "./testvectors/TDES/rsp/TCFB8subtab.rsp" || { echo "./testvectors/TDES/req/TCFB8subtab.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB8varkey.req" "./testvectors/TDES/rsp/TCFB8varkey.rsp" || { echo "./testvectors/TDES/req/TCFB8varkey.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB8vartext.req" "./testvectors/TDES/rsp/TCFB8vartext.rsp" || { echo "./testvectors/TDES/req/TCFB8vartext.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TECBinvperm.req" "./testvectors/TDES/rsp/TECBinvperm.rsp" || { echo "./testvectors/TDES/req/TECBinvperm.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TECBMMT1.req" "./testvectors/TDES/rsp/TECBMMT1.rsp" || { echo "./testvectors/TDES/req/TECBMMT1.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TECBMMT2.req" "./testvectors/TDES/rsp/TECBMMT2.rsp" || { echo "./testvectors/TDES/req/TECBMMT2.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TECBMMT3.req" "./testvectors/TDES/rsp/TECBMMT3.rsp" || { echo "./testvectors/TDES/req/TECBMMT3.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TECBMonte1.req" "./testvectors/TDES/rsp/TECBMonte1.rsp" || { echo "./testvectors/TDES/req/TECBMonte1.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TECBMonte2.req" "./testvectors/TDES/rsp/TECBMonte2.rsp" || { echo "./testvectors/TDES/req/TECBMonte2.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TECBMonte3.req" "./testvectors/TDES/rsp/TECBMonte3.rsp" || { echo "./testvectors/TDES/req/TECBMonte3.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TECBpermop.req" "./testvectors/TDES/rsp/TECBpermop.rsp" || { echo "./testvectors/TDES/req/TECBpermop.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TECBsubtab.req" "./testvectors/TDES/rsp/TECBsubtab.rsp" || { echo "./testvectors/TDES/req/TECBsubtab.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TECBvarkey.req" "./testvectors/TDES/rsp/TECBvarkey.rsp" || { echo "./testvectors/TDES/req/TECBvarkey.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TECBvartext.req" "./testvectors/TDES/rsp/TECBvartext.rsp" || { echo "./testvectors/TDES/req/TECBvartext.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TOFBinvperm.req" "./testvectors/TDES/rsp/TOFBinvperm.rsp" || { echo "./testvectors/TDES/req/TOFBinvperm.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TOFBMMT1.req" "./testvectors/TDES/rsp/TOFBMMT1.rsp" || { echo "./testvectors/TDES/req/TOFBMMT1.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TOFBMMT2.req" "./testvectors/TDES/rsp/TOFBMMT2.rsp" || { echo "./testvectors/TDES/req/TOFBMMT2.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TOFBMMT3.req" "./testvectors/TDES/rsp/TOFBMMT3.rsp" || { echo "./testvectors/TDES/req/TOFBMMT3.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TOFBMonte1.req" "./testvectors/TDES/rsp/TOFBMonte1.rsp" || { echo "./testvectors/TDES/req/TOFBMonte1.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TOFBMonte2.req" "./testvectors/TDES/rsp/TOFBMonte2.rsp" || { echo "./testvectors/TDES/req/TOFBMonte2.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TOFBMonte3.req" "./testvectors/TDES/rsp/TOFBMonte3.rsp" || { echo "./testvectors/TDES/req/TOFBMonte3.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TOFBpermop.req" "./testvectors/TDES/rsp/TOFBpermop.rsp" || { echo "./testvectors/TDES/req/TOFBpermop.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TOFBsubtab.req" "./testvectors/TDES/rsp/TOFBsubtab.rsp" || { echo "./testvectors/TDES/req/TOFBsubtab.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TOFBvarkey.req" "./testvectors/TDES/rsp/TOFBvarkey.rsp" || { echo "./testvectors/TDES/req/TOFBvarkey.req failure" ; exit 1 
-}
-../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TOFBvartext.req" "./testvectors/TDES/rsp/TOFBvartext.rsp" || { echo "./testvectors/TDES/req/TOFBvartext.req failure" ; exit 1 
-}
diff --git a/deps/openssl/openssl/fips/hmac/Makefile b/deps/openssl/openssl/fips/hmac/Makefile
deleted file mode 100644 (file)
index be230ad..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-#
-# OpenSSL/fips/hmac/Makefile
-#
-
-DIR=   hmac
-TOP=   ../..
-CC=    cc
-INCLUDES=
-CFLAG=-g
-INSTALL_PREFIX=
-OPENSSLDIR=     /usr/local/ssl
-INSTALLTOP=/usr/local/ssl
-MAKEDEPPROG=   makedepend
-MAKEDEPEND=    $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
-MAKEFILE=      Makefile
-AR=            ar r
-
-CFLAGS= $(INCLUDES) $(CFLAG)
-
-GENERAL=Makefile
-TEST=fips_hmactest.c
-APPS=
-
-LIB=$(TOP)/libcrypto.a
-LIBSRC=fips_hmac.c fips_hmac_selftest.c
-LIBOBJ=fips_hmac.o fips_hmac_selftest.o
-
-SRC= $(LIBSRC)
-
-EXHEADER=
-HEADER=        $(EXHEADER)
-
-ALL=    $(GENERAL) $(SRC) $(HEADER)
-
-top:
-       (cd $(TOP); $(MAKE) DIRS=fips FDIRS=$(DIR) sub_all)
-
-all:   lib
-
-lib:   $(LIBOBJ)
-       @echo $(LIBOBJ) > lib
-
-files:
-       $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
-
-links:
-       @$(PERL) $(TOP)/util/mklink.pl $(TOP)/include/openssl $(EXHEADER)
-       @$(PERL) $(TOP)/util/mklink.pl $(TOP)/test $(TEST)
-       @$(PERL) $(TOP)/util/mklink.pl $(TOP)/apps $(APPS)
-
-install:
-       @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:
-
-Q=../testvectors/hmac/req
-A=../testvectors/hmac/rsp
-
-fips_test:
-       -rm -rf $(A)
-       mkdir $(A)
-       if [ -f $(Q)/HMAC.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_hmactest < $(Q)/HMAC.req > $(A)/HMAC.rsp; fi
-
-lint:
-       lint -DLINT $(INCLUDES) $(SRC)>fluff
-
-depend:
-       $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(SRC) $(TEST)
-
-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.
-
-fips_hmac.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-fips_hmac.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
-fips_hmac.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-fips_hmac.o: ../../include/openssl/hmac.h ../../include/openssl/obj_mac.h
-fips_hmac.o: ../../include/openssl/objects.h
-fips_hmac.o: ../../include/openssl/opensslconf.h
-fips_hmac.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-fips_hmac.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-fips_hmac.o: ../../include/openssl/symhacks.h fips_hmac.c
-fips_hmac_selftest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-fips_hmac_selftest.o: ../../include/openssl/crypto.h
-fips_hmac_selftest.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-fips_hmac_selftest.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-fips_hmac_selftest.o: ../../include/openssl/hmac.h
-fips_hmac_selftest.o: ../../include/openssl/lhash.h
-fips_hmac_selftest.o: ../../include/openssl/obj_mac.h
-fips_hmac_selftest.o: ../../include/openssl/objects.h
-fips_hmac_selftest.o: ../../include/openssl/opensslconf.h
-fips_hmac_selftest.o: ../../include/openssl/opensslv.h
-fips_hmac_selftest.o: ../../include/openssl/ossl_typ.h
-fips_hmac_selftest.o: ../../include/openssl/safestack.h
-fips_hmac_selftest.o: ../../include/openssl/stack.h
-fips_hmac_selftest.o: ../../include/openssl/symhacks.h fips_hmac_selftest.c
-fips_hmactest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-fips_hmactest.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
-fips_hmactest.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
-fips_hmactest.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-fips_hmactest.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
-fips_hmactest.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-fips_hmactest.o: ../../include/openssl/fips.h ../../include/openssl/hmac.h
-fips_hmactest.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-fips_hmactest.o: ../../include/openssl/objects.h
-fips_hmactest.o: ../../include/openssl/opensslconf.h
-fips_hmactest.o: ../../include/openssl/opensslv.h
-fips_hmactest.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-fips_hmactest.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-fips_hmactest.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-fips_hmactest.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-fips_hmactest.o: ../../include/openssl/x509v3.h ../fips_utl.h fips_hmactest.c
diff --git a/deps/openssl/openssl/fips/hmac/fips_hmac.c b/deps/openssl/openssl/fips/hmac/fips_hmac.c
deleted file mode 100644 (file)
index 69a10da..0000000
+++ /dev/null
@@ -1,191 +0,0 @@
-/* crypto/hmac/hmac.c */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <openssl/hmac.h>
-#include <openssl/fips.h>
-
-#ifdef OPENSSL_FIPS
-
-void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
-                 const EVP_MD *md, ENGINE *impl)
-       {
-       int i,j,reset=0;
-       unsigned char pad[HMAC_MAX_MD_CBLOCK];
-
-       if (md != NULL)
-               {
-               reset=1;
-               ctx->md=md;
-               }
-       else
-               md=ctx->md;
-
-       if (key != NULL)
-               {
-               if (FIPS_mode() && !(md->flags & EVP_MD_FLAG_FIPS)
-               && (!(ctx->md_ctx.flags & EVP_MD_CTX_FLAG_NON_FIPS_ALLOW)
-                || !(ctx->i_ctx.flags & EVP_MD_CTX_FLAG_NON_FIPS_ALLOW)
-                || !(ctx->o_ctx.flags & EVP_MD_CTX_FLAG_NON_FIPS_ALLOW)))
-               OpenSSLDie(__FILE__,__LINE__,
-                       "HMAC: digest not allowed in FIPS mode");
-               
-               reset=1;
-               j=M_EVP_MD_block_size(md);
-               OPENSSL_assert(j <= (int)sizeof ctx->key);
-               if (j < len)
-                       {
-                       EVP_DigestInit_ex(&ctx->md_ctx,md, impl);
-                       EVP_DigestUpdate(&ctx->md_ctx,key,len);
-                       EVP_DigestFinal_ex(&(ctx->md_ctx),ctx->key,
-                               &ctx->key_length);
-                       }
-               else
-                       {
-                       OPENSSL_assert(len <= (int)sizeof ctx->key);
-                       memcpy(ctx->key,key,len);
-                       ctx->key_length=len;
-                       }
-               if(ctx->key_length != HMAC_MAX_MD_CBLOCK)
-                       memset(&ctx->key[ctx->key_length], 0,
-                               HMAC_MAX_MD_CBLOCK - ctx->key_length);
-               }
-
-       if (reset)      
-               {
-               for (i=0; i<HMAC_MAX_MD_CBLOCK; i++)
-                       pad[i]=0x36^ctx->key[i];
-               EVP_DigestInit_ex(&ctx->i_ctx,md, impl);
-               EVP_DigestUpdate(&ctx->i_ctx,pad,M_EVP_MD_block_size(md));
-
-               for (i=0; i<HMAC_MAX_MD_CBLOCK; i++)
-                       pad[i]=0x5c^ctx->key[i];
-               EVP_DigestInit_ex(&ctx->o_ctx,md, impl);
-               EVP_DigestUpdate(&ctx->o_ctx,pad,M_EVP_MD_block_size(md));
-               }
-       EVP_MD_CTX_copy_ex(&ctx->md_ctx,&ctx->i_ctx);
-       }
-
-void HMAC_Init(HMAC_CTX *ctx, const void *key, int len,
-              const EVP_MD *md)
-       {
-       if(key && md)
-           HMAC_CTX_init(ctx);
-       HMAC_Init_ex(ctx,key,len,md, NULL);
-       }
-
-void HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len)
-       {
-       EVP_DigestUpdate(&ctx->md_ctx,data,len);
-       }
-
-void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len)
-       {
-       int j;
-       unsigned int i;
-       unsigned char buf[EVP_MAX_MD_SIZE];
-
-       j=M_EVP_MD_block_size(ctx->md);
-
-       EVP_DigestFinal_ex(&ctx->md_ctx,buf,&i);
-       EVP_MD_CTX_copy_ex(&ctx->md_ctx,&ctx->o_ctx);
-       EVP_DigestUpdate(&ctx->md_ctx,buf,i);
-       EVP_DigestFinal_ex(&ctx->md_ctx,md,len);
-       }
-
-void HMAC_CTX_init(HMAC_CTX *ctx)
-       {
-       EVP_MD_CTX_init(&ctx->i_ctx);
-       EVP_MD_CTX_init(&ctx->o_ctx);
-       EVP_MD_CTX_init(&ctx->md_ctx);
-       }
-
-void HMAC_CTX_cleanup(HMAC_CTX *ctx)
-       {
-       EVP_MD_CTX_cleanup(&ctx->i_ctx);
-       EVP_MD_CTX_cleanup(&ctx->o_ctx);
-       EVP_MD_CTX_cleanup(&ctx->md_ctx);
-       memset(ctx,0,sizeof *ctx);
-       }
-
-unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
-                   const unsigned char *d, size_t n, unsigned char *md,
-                   unsigned int *md_len)
-       {
-       HMAC_CTX c;
-       static unsigned char m[EVP_MAX_MD_SIZE];
-
-       if (md == NULL) md=m;
-       HMAC_CTX_init(&c);
-       HMAC_Init(&c,key,key_len,evp_md);
-       HMAC_Update(&c,d,n);
-       HMAC_Final(&c,md,md_len);
-       HMAC_CTX_cleanup(&c);
-       return(md);
-       }
-
-void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags)
-       {
-       M_EVP_MD_CTX_set_flags(&ctx->i_ctx, flags);
-       M_EVP_MD_CTX_set_flags(&ctx->o_ctx, flags);
-       M_EVP_MD_CTX_set_flags(&ctx->md_ctx, flags);
-       }
-
-#endif
-
diff --git a/deps/openssl/openssl/fips/hmac/fips_hmac_selftest.c b/deps/openssl/openssl/fips/hmac/fips_hmac_selftest.c
deleted file mode 100644 (file)
index 73455ff..0000000
+++ /dev/null
@@ -1,135 +0,0 @@
-/* ====================================================================
- * Copyright (c) 2005 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    openssl-core@openssl.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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 <string.h>
-#include <openssl/err.h>
-#include <openssl/fips.h>
-#include <openssl/hmac.h>
-
-#ifdef OPENSSL_FIPS
-typedef struct {
-       const EVP_MD *(*alg)(void);
-       const char *key, *iv;
-       unsigned char kaval[EVP_MAX_MD_SIZE];
-} HMAC_KAT;
-
-static const HMAC_KAT vector[] = {
-    {  EVP_sha1,
-       /* from http://csrc.nist.gov/publications/fips/fips198/fips-198a.pdf */
-       "0123456789:;<=>?@ABC",
-       "Sample #2",
-       { 0x09,0x22,0xd3,0x40,0x5f,0xaa,0x3d,0x19,
-         0x4f,0x82,0xa4,0x58,0x30,0x73,0x7d,0x5c,
-         0xc6,0xc7,0x5d,0x24 }
-    },
-    {  EVP_sha224,
-       /* just keep extending the above... */
-       "0123456789:;<=>?@ABC",
-       "Sample #2",
-       { 0xdd,0xef,0x0a,0x40,0xcb,0x7d,0x50,0xfb,
-         0x6e,0xe6,0xce,0xa1,0x20,0xba,0x26,0xaa,
-         0x08,0xf3,0x07,0x75,0x87,0xb8,0xad,0x1b,
-         0x8c,0x8d,0x12,0xc7 }
-    },
-    {  EVP_sha256,
-       "0123456789:;<=>?@ABC",
-       "Sample #2",
-       { 0xb8,0xf2,0x0d,0xb5,0x41,0xea,0x43,0x09,
-         0xca,0x4e,0xa9,0x38,0x0c,0xd0,0xe8,0x34,
-         0xf7,0x1f,0xbe,0x91,0x74,0xa2,0x61,0x38,
-         0x0d,0xc1,0x7e,0xae,0x6a,0x34,0x51,0xd9 }
-    },
-    {  EVP_sha384,
-       "0123456789:;<=>?@ABC",
-       "Sample #2",
-       { 0x08,0xbc,0xb0,0xda,0x49,0x1e,0x87,0xad,
-         0x9a,0x1d,0x6a,0xce,0x23,0xc5,0x0b,0xf6,
-         0xb7,0x18,0x06,0xa5,0x77,0xcd,0x49,0x04,
-         0x89,0xf1,0xe6,0x23,0x44,0x51,0x51,0x9f,
-         0x85,0x56,0x80,0x79,0x0c,0xbd,0x4d,0x50,
-         0xa4,0x5f,0x29,0xe3,0x93,0xf0,0xe8,0x7f }
-    },
-    {  EVP_sha512,
-       "0123456789:;<=>?@ABC",
-       "Sample #2",
-       { 0x80,0x9d,0x44,0x05,0x7c,0x5b,0x95,0x41,
-         0x05,0xbd,0x04,0x13,0x16,0xdb,0x0f,0xac,
-         0x44,0xd5,0xa4,0xd5,0xd0,0x89,0x2b,0xd0,
-         0x4e,0x86,0x64,0x12,0xc0,0x90,0x77,0x68,
-         0xf1,0x87,0xb7,0x7c,0x4f,0xae,0x2c,0x2f,
-         0x21,0xa5,0xb5,0x65,0x9a,0x4f,0x4b,0xa7,
-         0x47,0x02,0xa3,0xde,0x9b,0x51,0xf1,0x45,
-         0xbd,0x4f,0x25,0x27,0x42,0x98,0x99,0x05 }
-    },
-};
-
-int FIPS_selftest_hmac()
-    {
-    size_t n;
-    unsigned int    outlen;
-    unsigned char   out[EVP_MAX_MD_SIZE];
-    const EVP_MD   *md;
-    const HMAC_KAT *t;
-
-    for(n=0,t=vector; n<sizeof(vector)/sizeof(vector[0]); n++,t++)
-       {
-       md = (*t->alg)();
-       HMAC(md,t->key,strlen(t->key),
-               (const unsigned char *)t->iv,strlen(t->iv),
-               out,&outlen);
-
-       if(memcmp(out,t->kaval,outlen))
-           {
-           FIPSerr(FIPS_F_FIPS_SELFTEST_HMAC,FIPS_R_SELFTEST_FAILED);
-           return 0;
-           }
-       }
-    return 1;
-    }
-#endif
diff --git a/deps/openssl/openssl/fips/hmac/fips_hmactest.c b/deps/openssl/openssl/fips/hmac/fips_hmactest.c
deleted file mode 100644 (file)
index 69ebf68..0000000
+++ /dev/null
@@ -1,328 +0,0 @@
-/* fips_hmactest.c */
-/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
- * project 2005.
- */
-/* ====================================================================
- * Copyright (c) 2005 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    licensing@OpenSSL.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
- * ====================================================================
- *
- * This product includes cryptographic software written by Eric Young
- * (eay@cryptsoft.com).  This product includes software written by Tim
- * Hudson (tjh@cryptsoft.com).
- *
- */
-
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-#include <openssl/bio.h>
-#include <openssl/evp.h>
-#include <openssl/hmac.h>
-#include <openssl/err.h>
-#include <openssl/bn.h>
-
-#include <openssl/x509v3.h>
-
-#ifndef OPENSSL_FIPS
-
-int main(int argc, char *argv[])
-{
-    printf("No FIPS HMAC support\n");
-    return(0);
-}
-
-#else
-
-#include <openssl/fips.h>
-#include "fips_utl.h"
-
-static int hmac_test(const EVP_MD *md, FILE *out, FILE *in);
-static int print_hmac(const EVP_MD *md, FILE *out,
-               unsigned char *Key, int Klen,
-               unsigned char *Msg, int Msglen, int Tlen);
-
-int main(int argc, char **argv)
-       {
-       FILE *in = NULL, *out = NULL;
-
-       int ret = 1;
-
-       if(!FIPS_mode_set(1))
-               {
-               do_print_errors();
-               goto end;
-               }
-
-       if (argc == 1)
-               in = stdin;
-       else
-               in = fopen(argv[1], "r");
-
-       if (argc < 2)
-               out = stdout;
-       else
-               out = fopen(argv[2], "w");
-
-       if (!in)
-               {
-               fprintf(stderr, "FATAL input initialization error\n");
-               goto end;
-               }
-
-       if (!out)
-               {
-               fprintf(stderr, "FATAL output initialization error\n");
-               goto end;
-               }
-
-       if (!hmac_test(EVP_sha1(), out, in))
-               {
-               fprintf(stderr, "FATAL hmac file processing error\n");
-               goto end;
-               }
-       else
-               ret = 0;
-
-       end:
-
-       if (ret)
-               do_print_errors();
-
-       if (in && (in != stdin))
-               fclose(in);
-       if (out && (out != stdout))
-               fclose(out);
-
-       return ret;
-
-       }
-
-#define HMAC_TEST_MAXLINELEN   1024
-
-int hmac_test(const EVP_MD *md, FILE *out, FILE *in)
-       {
-       char *linebuf, *olinebuf, *p, *q;
-       char *keyword, *value;
-       unsigned char *Key = NULL, *Msg = NULL;
-       int Count, Klen, Tlen;
-       long Keylen, Msglen;
-       int ret = 0;
-       int lnum = 0;
-
-       olinebuf = OPENSSL_malloc(HMAC_TEST_MAXLINELEN);
-       linebuf = OPENSSL_malloc(HMAC_TEST_MAXLINELEN);
-
-       if (!linebuf || !olinebuf)
-               goto error;
-
-       Count = -1;
-       Klen = -1;
-       Tlen = -1;
-
-       while (fgets(olinebuf, HMAC_TEST_MAXLINELEN, in))
-               {
-               lnum++;
-               strcpy(linebuf, olinebuf);
-               keyword = linebuf;
-               /* Skip leading space */
-               while (isspace((unsigned char)*keyword))
-                       keyword++;
-
-               /* Look for = sign */
-               p = strchr(linebuf, '=');
-
-               /* If no = or starts with [ (for [L=20] line) just copy */
-               if (!p)
-                       {
-                       if (fputs(olinebuf, out) < 0)
-                               goto error;
-                       continue;
-                       }
-
-               q = p - 1;
-
-               /* Remove trailing space */
-               while (isspace((unsigned char)*q))
-                       *q-- = 0;
-
-               *p = 0;
-               value = p + 1;
-
-               /* Remove leading space from value */
-               while (isspace((unsigned char)*value))
-                       value++;
-
-               /* Remove trailing space from value */
-               p = value + strlen(value) - 1;
-
-               while (*p == '\n' || isspace((unsigned char)*p))
-                       *p-- = 0;
-
-               if (!strcmp(keyword,"[L") && *p==']')
-                       {
-                       switch (atoi(value))
-                               {
-                               case 20: md=EVP_sha1();   break;
-                               case 28: md=EVP_sha224(); break;
-                               case 32: md=EVP_sha256(); break;
-                               case 48: md=EVP_sha384(); break;
-                               case 64: md=EVP_sha512(); break;
-                               default: goto parse_error;
-                               }
-                       }
-               else if (!strcmp(keyword, "Count"))
-                       {
-                       if (Count != -1)
-                               goto parse_error;
-                       Count = atoi(value);
-                       if (Count < 0)
-                               goto parse_error;
-                       }
-               else if (!strcmp(keyword, "Klen"))
-                       {
-                       if (Klen != -1)
-                               goto parse_error;
-                       Klen = atoi(value);
-                       if (Klen < 0)
-                               goto parse_error;
-                       }
-               else if (!strcmp(keyword, "Tlen"))
-                       {
-                       if (Tlen != -1)
-                               goto parse_error;
-                       Tlen = atoi(value);
-                       if (Tlen < 0)
-                               goto parse_error;
-                       }
-               else if (!strcmp(keyword, "Msg"))
-                       {
-                       if (Msg)
-                               goto parse_error;
-                       Msg = hex2bin_m(value, &Msglen);
-                       if (!Msg)
-                               goto parse_error;
-                       }
-               else if (!strcmp(keyword, "Key"))
-                       {
-                       if (Key)
-                               goto parse_error;
-                       Key = hex2bin_m(value, &Keylen);
-                       if (!Key)
-                               goto parse_error;
-                       }
-               else if (!strcmp(keyword, "Mac"))
-                       continue;
-               else
-                       goto parse_error;
-
-               fputs(olinebuf, out);
-
-               if (Key && Msg && (Tlen > 0) && (Klen > 0))
-                       {
-                       if (!print_hmac(md, out, Key, Klen, Msg, Msglen, Tlen))
-                               goto error;
-                       OPENSSL_free(Key);
-                       Key = NULL;
-                       OPENSSL_free(Msg);
-                       Msg = NULL;
-                       Klen = -1;
-                       Tlen = -1;
-                       Count = -1;
-                       }
-
-               }
-
-
-       ret = 1;
-
-
-       error:
-
-       if (olinebuf)
-               OPENSSL_free(olinebuf);
-       if (linebuf)
-               OPENSSL_free(linebuf);
-       if (Key)
-               OPENSSL_free(Key);
-       if (Msg)
-               OPENSSL_free(Msg);
-
-       return ret;
-
-       parse_error:
-
-       fprintf(stderr, "FATAL parse error processing line %d\n", lnum);
-
-       goto error;
-
-       }
-
-static int print_hmac(const EVP_MD *emd, FILE *out,
-               unsigned char *Key, int Klen,
-               unsigned char *Msg, int Msglen, int Tlen)
-       {
-       int i, mdlen;
-       unsigned char md[EVP_MAX_MD_SIZE];
-       if (!HMAC(emd, Key, Klen, Msg, Msglen, md,
-                                               (unsigned int *)&mdlen))
-               {
-               fputs("Error calculating HMAC\n", stderr);
-               return 0;
-               }
-       if (Tlen > mdlen)
-               {
-               fputs("Parameter error, Tlen > HMAC length\n", stderr);
-               return 0;
-               }
-       fputs("Mac = ", out);
-       for (i = 0; i < Tlen; i++)
-               fprintf(out, "%02x", md[i]);
-       fputs("\n", out);
-       return 1;
-       }
-
-#endif
diff --git a/deps/openssl/openssl/fips/install.com b/deps/openssl/openssl/fips/install.com
deleted file mode 100644 (file)
index 48ad12d..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-$! INSTALL.COM -- Installs the files in a given directory tree
-$!
-$! Author: Richard Levitte <richard@levitte.org>
-$! Time of creation: 27-MAY-2004 11:47
-$!
-$! P1  root of the directory tree
-$!
-$      IF P1 .EQS. ""
-$      THEN
-$          WRITE SYS$OUTPUT "First argument missing."
-$          WRITE SYS$OUTPUT "Should be the directory where you want things installed."
-$          EXIT
-$      ENDIF
-$
-$      IF (F$GETSYI("CPU").LT.128)
-$      THEN
-$          ARCH := VAX
-$      ELSE
-$          ARCH = F$EDIT( F$GETSYI( "ARCH_NAME"), "UPCASE")
-$          IF (ARCH .EQS. "") THEN ARCH = "UNK"
-$      ENDIF
-$
-$      ROOT = F$PARSE(P1,"[]A.;0",,,"SYNTAX_ONLY,NO_CONCEAL") - "A.;0"
-$      ROOT_DEV = F$PARSE(ROOT,,,"DEVICE","SYNTAX_ONLY")
-$      ROOT_DIR = F$PARSE(ROOT,,,"DIRECTORY","SYNTAX_ONLY") -
-                  - "[000000." - "][" - "[" - "]"
-$      ROOT = ROOT_DEV + "[" + ROOT_DIR
-$
-$      DEFINE/NOLOG WRK_SSLROOT 'ROOT'.] /TRANS=CONC
-$      DEFINE/NOLOG WRK_SSLINCLUDE WRK_SSLROOT:[INCLUDE]
-$
-$      IF F$PARSE("WRK_SSLROOT:[000000]") .EQS. "" THEN -
-          CREATE/DIR/LOG WRK_SSLROOT:[000000]
-$      IF F$PARSE("WRK_SSLINCLUDE:") .EQS. "" THEN -
-          CREATE/DIR/LOG WRK_SSLINCLUDE:
-$
-$      FDIRS := ,RAND,SHA,DES,AES,DSA,RSA,DH,HMAC
-$      EXHEADER_ := fips.h
-$      EXHEADER_SHA := fips_sha.h
-$      EXHEADER_RAND := fips_rand.h
-$      EXHEADER_DES :=
-$      EXHEADER_AES :=
-$      EXHEADER_DSA :=
-$      EXHEADER_RSA :=
-$      EXHEADER_DH :=
-$      EXHEADER_HMAC :=
-$
-$      I = 0
-$ LOOP_FDIRS: 
-$      D = F$EDIT(F$ELEMENT(I, ",", FDIRS),"TRIM")
-$      I = I + 1
-$      IF D .EQS. "," THEN GOTO LOOP_FDIRS_END
-$      tmp = EXHEADER_'D'
-$      IF tmp .EQS. "" THEN GOTO LOOP_FDIRS
-$      IF D .EQS. ""
-$      THEN
-$        COPY 'tmp' WRK_SSLINCLUDE: /LOG
-$      ELSE
-$        COPY [.'D']'tmp' WRK_SSLINCLUDE: /LOG
-$      ENDIF
-$      SET FILE/PROT=WORLD:RE WRK_SSLINCLUDE:'tmp'
-$      GOTO LOOP_FDIRS
-$ LOOP_FDIRS_END:
-$
-$      EXIT
diff --git a/deps/openssl/openssl/fips/mkfipsscr.pl b/deps/openssl/openssl/fips/mkfipsscr.pl
deleted file mode 100644 (file)
index 361641d..0000000
+++ /dev/null
@@ -1,657 +0,0 @@
-#!/usr/local/bin/perl -w
-# Quick & dirty utility to generate a script for executing the
-# FIPS 140-2 CMVP algorithm tests based on the pathnames of
-# input algorithm test files actually present (the unqualified
-# file names are consistent but the pathnames are not).
-#
-
-# List of all the unqualified file names we expect.
-my %fips_tests = (
-
-# FIPS test definitions
-
-# DSA tests
-
-"PQGGen" => "fips_dssvs pqg",
-"KeyPair" => "fips_dssvs keypair",
-"SigGen" => "fips_dssvs siggen",
-"SigVer" => "fips_dssvs sigver",
-
-# SHA tests
-
-"SHA1LongMsg" => "fips_shatest",
-"SHA1Monte" => "fips_shatest",
-"SHA1ShortMsg" => "fips_shatest",
-"SHA224LongMsg" => "fips_shatest",
-"SHA224Monte" => "fips_shatest",
-"SHA224ShortMsg" => "fips_shatest",
-"SHA256LongMsg" => "fips_shatest",
-"SHA256Monte" => "fips_shatest",
-"SHA256ShortMsg" => "fips_shatest",
-"SHA384LongMsg" => "fips_shatest",
-"SHA384Monte" => "fips_shatest",
-"SHA384ShortMsg" => "fips_shatest",
-"SHA512LongMsg" => "fips_shatest",
-"SHA512Monte" => "fips_shatest",
-"SHA512ShortMsg" => "fips_shatest",
-
-# HMAC
-
-"HMAC" => "fips_hmactest",
-
-# RAND tests
-
-"ANSI931_AES128MCT" => "fips_rngvs mct",
-"ANSI931_AES192MCT" => "fips_rngvs mct",
-"ANSI931_AES256MCT" => "fips_rngvs mct",
-"ANSI931_AES128VST" => "fips_rngvs vst",
-"ANSI931_AES192VST" => "fips_rngvs vst",
-"ANSI931_AES256VST" => "fips_rngvs vst",
-
-# RSA tests
-
-"SigGen15" => "fips_rsastest",
-"SigVer15" => "fips_rsavtest",
-"SigGenPSS" => "fips_rsastest -saltlen SALT",
-"SigVerPSS" => "fips_rsavtest -saltlen SALT",
-"SigGenRSA" => "fips_rsastest -x931",
-"SigVerRSA" => "fips_rsavtest -x931",
-"KeyGenRSA" => "fips_rsagtest",
-
-# AES tests
-
-"CBCGFSbox128" => "fips_aesavs -f",
-"CBCGFSbox192" => "fips_aesavs -f",
-"CBCGFSbox256" => "fips_aesavs -f",
-"CBCKeySbox128" => "fips_aesavs -f",
-"CBCKeySbox192" => "fips_aesavs -f",
-"CBCKeySbox256" => "fips_aesavs -f",
-"CBCMCT128" => "fips_aesavs -f",
-"CBCMCT192" => "fips_aesavs -f",
-"CBCMCT256" => "fips_aesavs -f",
-"CBCMMT128" => "fips_aesavs -f",
-"CBCMMT192" => "fips_aesavs -f",
-"CBCMMT256" => "fips_aesavs -f",
-"CBCVarKey128" => "fips_aesavs -f",
-"CBCVarKey192" => "fips_aesavs -f",
-"CBCVarKey256" => "fips_aesavs -f",
-"CBCVarTxt128" => "fips_aesavs -f",
-"CBCVarTxt192" => "fips_aesavs -f",
-"CBCVarTxt256" => "fips_aesavs -f",
-"CFB128GFSbox128" => "fips_aesavs -f",
-"CFB128GFSbox192" => "fips_aesavs -f",
-"CFB128GFSbox256" => "fips_aesavs -f",
-"CFB128KeySbox128" => "fips_aesavs -f",
-"CFB128KeySbox192" => "fips_aesavs -f",
-"CFB128KeySbox256" => "fips_aesavs -f",
-"CFB128MCT128" => "fips_aesavs -f",
-"CFB128MCT192" => "fips_aesavs -f",
-"CFB128MCT256" => "fips_aesavs -f",
-"CFB128MMT128" => "fips_aesavs -f",
-"CFB128MMT192" => "fips_aesavs -f",
-"CFB128MMT256" => "fips_aesavs -f",
-"CFB128VarKey128" => "fips_aesavs -f",
-"CFB128VarKey192" => "fips_aesavs -f",
-"CFB128VarKey256" => "fips_aesavs -f",
-"CFB128VarTxt128" => "fips_aesavs -f",
-"CFB128VarTxt192" => "fips_aesavs -f",
-"CFB128VarTxt256" => "fips_aesavs -f",
-"CFB8GFSbox128" => "fips_aesavs -f",
-"CFB8GFSbox192" => "fips_aesavs -f",
-"CFB8GFSbox256" => "fips_aesavs -f",
-"CFB8KeySbox128" => "fips_aesavs -f",
-"CFB8KeySbox192" => "fips_aesavs -f",
-"CFB8KeySbox256" => "fips_aesavs -f",
-"CFB8MCT128" => "fips_aesavs -f",
-"CFB8MCT192" => "fips_aesavs -f",
-"CFB8MCT256" => "fips_aesavs -f",
-"CFB8MMT128" => "fips_aesavs -f",
-"CFB8MMT192" => "fips_aesavs -f",
-"CFB8MMT256" => "fips_aesavs -f",
-"CFB8VarKey128" => "fips_aesavs -f",
-"CFB8VarKey192" => "fips_aesavs -f",
-"CFB8VarKey256" => "fips_aesavs -f",
-"CFB8VarTxt128" => "fips_aesavs -f",
-"CFB8VarTxt192" => "fips_aesavs -f",
-"CFB8VarTxt256" => "fips_aesavs -f",
-#"CFB1GFSbox128" => "fips_aesavs -f",
-#"CFB1GFSbox192" => "fips_aesavs -f",
-#"CFB1GFSbox256" => "fips_aesavs -f",
-#"CFB1KeySbox128" => "fips_aesavs -f",
-#"CFB1KeySbox192" => "fips_aesavs -f",
-#"CFB1KeySbox256" => "fips_aesavs -f",
-#"CFB1MCT128" => "fips_aesavs -f",
-#"CFB1MCT192" => "fips_aesavs -f",
-#"CFB1MCT256" => "fips_aesavs -f",
-#"CFB1MMT128" => "fips_aesavs -f",
-#"CFB1MMT192" => "fips_aesavs -f",
-#"CFB1MMT256" => "fips_aesavs -f",
-#"CFB1VarKey128" => "fips_aesavs -f",
-#"CFB1VarKey192" => "fips_aesavs -f",
-#"CFB1VarKey256" => "fips_aesavs -f",
-#"CFB1VarTxt128" => "fips_aesavs -f",
-#"CFB1VarTxt192" => "fips_aesavs -f",
-#"CFB1VarTxt256" => "fips_aesavs -f",
-"ECBGFSbox128" => "fips_aesavs -f",
-"ECBGFSbox192" => "fips_aesavs -f",
-"ECBGFSbox256" => "fips_aesavs -f",
-"ECBKeySbox128" => "fips_aesavs -f",
-"ECBKeySbox192" => "fips_aesavs -f",
-"ECBKeySbox256" => "fips_aesavs -f",
-"ECBMCT128" => "fips_aesavs -f",
-"ECBMCT192" => "fips_aesavs -f",
-"ECBMCT256" => "fips_aesavs -f",
-"ECBMMT128" => "fips_aesavs -f",
-"ECBMMT192" => "fips_aesavs -f",
-"ECBMMT256" => "fips_aesavs -f",
-"ECBVarKey128" => "fips_aesavs -f",
-"ECBVarKey192" => "fips_aesavs -f",
-"ECBVarKey256" => "fips_aesavs -f",
-"ECBVarTxt128" => "fips_aesavs -f",
-"ECBVarTxt192" => "fips_aesavs -f",
-"ECBVarTxt256" => "fips_aesavs -f",
-"OFBGFSbox128" => "fips_aesavs -f",
-"OFBGFSbox192" => "fips_aesavs -f",
-"OFBGFSbox256" => "fips_aesavs -f",
-"OFBKeySbox128" => "fips_aesavs -f",
-"OFBKeySbox192" => "fips_aesavs -f",
-"OFBKeySbox256" => "fips_aesavs -f",
-"OFBMCT128" => "fips_aesavs -f",
-"OFBMCT192" => "fips_aesavs -f",
-"OFBMCT256" => "fips_aesavs -f",
-"OFBMMT128" => "fips_aesavs -f",
-"OFBMMT192" => "fips_aesavs -f",
-"OFBMMT256" => "fips_aesavs -f",
-"OFBVarKey128" => "fips_aesavs -f",
-"OFBVarKey192" => "fips_aesavs -f",
-"OFBVarKey256" => "fips_aesavs -f",
-"OFBVarTxt128" => "fips_aesavs -f",
-"OFBVarTxt192" => "fips_aesavs -f",
-"OFBVarTxt256" => "fips_aesavs -f",
-
-# Triple DES tests
-
-"TCBCinvperm" => "fips_desmovs -f",
-"TCBCMMT1" => "fips_desmovs -f",
-"TCBCMMT2" => "fips_desmovs -f",
-"TCBCMMT3" => "fips_desmovs -f",
-"TCBCMonte1" => "fips_desmovs -f",
-"TCBCMonte2" => "fips_desmovs -f",
-"TCBCMonte3" => "fips_desmovs -f",
-"TCBCpermop" => "fips_desmovs -f",
-"TCBCsubtab" => "fips_desmovs -f",
-"TCBCvarkey" => "fips_desmovs -f",
-"TCBCvartext" => "fips_desmovs -f",
-"TCFB64invperm" => "fips_desmovs -f",
-"TCFB64MMT1" => "fips_desmovs -f",
-"TCFB64MMT2" => "fips_desmovs -f",
-"TCFB64MMT3" => "fips_desmovs -f",
-"TCFB64Monte1" => "fips_desmovs -f",
-"TCFB64Monte2" => "fips_desmovs -f",
-"TCFB64Monte3" => "fips_desmovs -f",
-"TCFB64permop" => "fips_desmovs -f",
-"TCFB64subtab" => "fips_desmovs -f",
-"TCFB64varkey" => "fips_desmovs -f",
-"TCFB64vartext" => "fips_desmovs -f",
-"TCFB8invperm" => "fips_desmovs -f",
-"TCFB8MMT1" => "fips_desmovs -f",
-"TCFB8MMT2" => "fips_desmovs -f",
-"TCFB8MMT3" => "fips_desmovs -f",
-"TCFB8Monte1" => "fips_desmovs -f",
-"TCFB8Monte2" => "fips_desmovs -f",
-"TCFB8Monte3" => "fips_desmovs -f",
-"TCFB8permop" => "fips_desmovs -f",
-"TCFB8subtab" => "fips_desmovs -f",
-"TCFB8varkey" => "fips_desmovs -f",
-"TCFB8vartext" => "fips_desmovs -f",
-"TECBinvperm" => "fips_desmovs -f",
-"TECBMMT1" => "fips_desmovs -f",
-"TECBMMT2" => "fips_desmovs -f",
-"TECBMMT3" => "fips_desmovs -f",
-"TECBMonte1" => "fips_desmovs -f",
-"TECBMonte2" => "fips_desmovs -f",
-"TECBMonte3" => "fips_desmovs -f",
-"TECBpermop" => "fips_desmovs -f",
-"TECBsubtab" => "fips_desmovs -f",
-"TECBvarkey" => "fips_desmovs -f",
-"TECBvartext" => "fips_desmovs -f",
-"TOFBinvperm" => "fips_desmovs -f",
-"TOFBMMT1" => "fips_desmovs -f",
-"TOFBMMT2" => "fips_desmovs -f",
-"TOFBMMT3" => "fips_desmovs -f",
-"TOFBMonte1" => "fips_desmovs -f",
-"TOFBMonte2" => "fips_desmovs -f",
-"TOFBMonte3" => "fips_desmovs -f",
-"TOFBpermop" => "fips_desmovs -f",
-"TOFBsubtab" => "fips_desmovs -f",
-"TOFBvarkey" => "fips_desmovs -f",
-"TOFBvartext" => "fips_desmovs -f",
-"TCBCinvperm" => "fips_desmovs -f",
-"TCBCMMT1" => "fips_desmovs -f",
-"TCBCMMT2" => "fips_desmovs -f",
-"TCBCMMT3" => "fips_desmovs -f",
-"TCBCMonte1" => "fips_desmovs -f",
-"TCBCMonte2" => "fips_desmovs -f",
-"TCBCMonte3" => "fips_desmovs -f",
-"TCBCpermop" => "fips_desmovs -f",
-"TCBCsubtab" => "fips_desmovs -f",
-"TCBCvarkey" => "fips_desmovs -f",
-"TCBCvartext" => "fips_desmovs -f",
-"TCFB64invperm" => "fips_desmovs -f",
-"TCFB64MMT1" => "fips_desmovs -f",
-"TCFB64MMT2" => "fips_desmovs -f",
-"TCFB64MMT3" => "fips_desmovs -f",
-"TCFB64Monte1" => "fips_desmovs -f",
-"TCFB64Monte2" => "fips_desmovs -f",
-"TCFB64Monte3" => "fips_desmovs -f",
-"TCFB64permop" => "fips_desmovs -f",
-"TCFB64subtab" => "fips_desmovs -f",
-"TCFB64varkey" => "fips_desmovs -f",
-"TCFB64vartext" => "fips_desmovs -f",
-"TCFB8invperm" => "fips_desmovs -f",
-"TCFB8MMT1" => "fips_desmovs -f",
-"TCFB8MMT2" => "fips_desmovs -f",
-"TCFB8MMT3" => "fips_desmovs -f",
-"TCFB8Monte1" => "fips_desmovs -f",
-"TCFB8Monte2" => "fips_desmovs -f",
-"TCFB8Monte3" => "fips_desmovs -f",
-"TCFB8permop" => "fips_desmovs -f",
-"TCFB8subtab" => "fips_desmovs -f",
-"TCFB8varkey" => "fips_desmovs -f",
-"TCFB8vartext" => "fips_desmovs -f",
-"TECBinvperm" => "fips_desmovs -f",
-"TECBMMT1" => "fips_desmovs -f",
-"TECBMMT2" => "fips_desmovs -f",
-"TECBMMT3" => "fips_desmovs -f",
-"TECBMonte1" => "fips_desmovs -f",
-"TECBMonte2" => "fips_desmovs -f",
-"TECBMonte3" => "fips_desmovs -f",
-"TECBpermop" => "fips_desmovs -f",
-"TECBsubtab" => "fips_desmovs -f",
-"TECBvarkey" => "fips_desmovs -f",
-"TECBvartext" => "fips_desmovs -f",
-"TOFBinvperm" => "fips_desmovs -f",
-"TOFBMMT1" => "fips_desmovs -f",
-"TOFBMMT2" => "fips_desmovs -f",
-"TOFBMMT3" => "fips_desmovs -f",
-"TOFBMonte1" => "fips_desmovs -f",
-"TOFBMonte2" => "fips_desmovs -f",
-"TOFBMonte3" => "fips_desmovs -f",
-"TOFBpermop" => "fips_desmovs -f",
-"TOFBsubtab" => "fips_desmovs -f",
-"TOFBvarkey" => "fips_desmovs -f",
-"TOFBvartext" => "fips_desmovs -f"
-
-);
-my %salt_names = (
-"SigVerPSS (salt 0)" => "SigVerPSS",
-"SigVerPSS (salt 62)" => "SigVerPSS",
-"SigGenPSS (salt 0)" => "SigGenPSS",
-"SigGenPSS (salt 62)" => "SigGenPSS",
-);
-
-
-my $win32 = $^O =~ m/mswin/i;
-my $onedir = 0;
-my $filter = "";
-my $tvdir;
-my $tprefix;
-my $shwrap_prefix;
-my $shwrap;
-my $rmcmd = "rm -rf";
-my $mkcmd = "mkdir";
-my $debug = 0;
-my $quiet = 0;
-my $rspdir = "rsp";
-my $rspignore = 0;
-my @bogus = ();                        # list of unmatched *.rsp files
-my $bufout = '';
-my $bufdir = '';
-my %_programs = ();            # list of external programs to check
-
-foreach (@ARGV)
-       {
-       if ($_ eq "--win32")
-               {
-               $win32 = 1;
-               }
-       elsif ($_ eq "--onedir")
-               {
-               $onedir = 1;
-               }
-       elsif ($_ eq "--debug")
-               {
-               $debug = 1;
-               }
-       elsif ($_ eq "--quiet")
-               {
-               $quiet = 1;
-               }
-       elsif (/--dir=(.*)$/)
-               {
-               $tvdir = $1;
-               }
-       elsif (/--rspdir=(.*)$/)
-               {
-               $rspdir = $1;
-               }
-       elsif (/--noshwrap$/)
-               {
-               $shwrap = "";
-               }
-       elsif (/--rspignore$/)
-               {
-               $rspignore = 1;
-               }
-       elsif (/--tprefix=(.*)$/)
-               {
-               $tprefix = $1;
-               }
-       elsif (/--shwrap_prefix=(.*)$/)
-               {
-               $shwrap_prefix = $1;
-               }
-       elsif (/--filter=(.*)$/)
-               {
-               $filter = $1;
-               }
-       elsif (/--mkdir=(.*)$/)
-               {
-               $mkcmd = $1;
-               }
-       elsif (/--rm=(.*)$/)
-               {
-               $rmcmd = $1;
-               }
-       elsif (/--outfile=(.*)$/)
-               {
-               $outfile = $1;
-               }
-       else
-               {
-               &Help();
-               exit(1);
-               }
-       }
-
-$tvdir = "." unless defined $tvdir;
-
-if ($win32)
-       {
-       if (!defined $tprefix)
-               {
-               if ($onedir)
-                       {
-                       $tprefix = ".\\";
-                       }
-               else
-                       {
-                       $tprefix = "..\\out32dll\\";
-                       }
-               }
-
-       $bufinit .= <<END;
-\@echo off
-rem Test vector run script
-rem Auto generated by mkfipsscr.pl script
-rem Do not edit
-
-END
-
-       }
-else
-       {
-       if ($onedir)
-               {
-               $tprefix = "./" unless defined $tprefix;
-               $shwrap_prefix = "./" unless defined $shwrap_prefix;
-               }
-       else
-               {
-               $tprefix = "../test/" unless defined $tprefix;
-               $shwrap_prefix = "../util/" unless defined $shwrap_prefix;
-               }
-
-       $shwrap = "${shwrap_prefix}shlib_wrap.sh " unless defined $shwrap;
-
-       $bufinit .= <<END;
-#!/bin/sh
-
-# Test vector run script
-# Auto generated by mkfipsscr.pl script
-# Do not edit
-
-RM="$rmcmd"
-MKDIR="$mkcmd"
-TPREFIX=$tprefix
-END
-
-       }
-my %fips_found;
-foreach (keys %fips_tests)
-       {
-       $fips_found{$_} = 0;
-       }
-my %saltPSS;
-for (keys %salt_names)
-       {
-       $salt_found{$_} = 0;
-       }
-
-recurse_test($win32, $tprefix, $filter, $tvdir);
-
-while (($key, $value) = each %salt_found)
-       {
-       &countentry($key, $value);
-       delete $fips_found{$salt_names{$key}};
-       }
-while (($key, $value) = each %fips_found)
-       {
-       &countentry($key, $value);
-       }
-
-# If no fatal errors write out the script file
-       $outfile = "fipstests.sh" unless defined $outfile;
-       open(OUT, ">$outfile") || die "Error opening $outfile: $!";
-       print OUT $bufinit;
-       if (!$rspignore && @bogus)
-               {
-               print STDERR "ERROR: please remove bogus *.rsp files\n";
-               print OUT <<EOF;
-echo $outfile generation failed due to presence of bogus *.rsp files
-EOF
-               }
-       else
-               {
-               print OUT $bufout;
-               }
-       close OUT;
-
-# Check for external programs
-       for (keys %_programs)
-               {
-               s/ .*$//;
-               -x $_ || print STDERR "WARNING: program $_ not found\n";
-               }
-
-#--------------------------------
-sub Help {
-(my $cmd) = ($0 =~ m#([^/]+)$#);
-       print <<EOF;
-$cmd: generate script for CMVP algorithm tests
-       --debug                     Enable debug output
-       --dir=<dirname>             Optional root for *.req file search
-       --filter=<regexp>
-       --onedir <dirname>          Assume all components in current directory
-       --outfile=<filename>        Optional name of output script, default fipstests.{sh|bat}
-       --rspdir=<dirname>          Name of subdirectories containing *.rsp files, default "resp"
-       --rspignore                 Ignore any bogus *.rsp files
-       --shwrap_prefix=<prefix>
-       --tprefix=<prefix>
-       --quiet                     Shhh....
-       --win32                     Generate script for Win32 environment
-EOF
-}
-
-#--------------------------------
-sub countentry {
-       my ($key,$value) = @_;
-       if ($value == 0)
-               {
-               print STDERR "WARNING: test file $key not found\n" unless $quiet;
-               }
-       elsif ($value > 1)
-               {
-               print STDERR "WARNING: test file $key found $value times\n" unless $quiet;
-               }
-       else 
-               {
-               print STDERR "Found test file $key\n" if $debug;
-               }
-       }
-
-#--------------------------------
-sub recurse_test
-       {
-       my ($win32, $tprefix, $filter, $dir) = @_;
-       my $dirh;
-       opendir($dirh, $dir);
-       while ($_ = readdir($dirh))
-               {
-               next if ($_ eq "." || $_ eq "..");
-               $_ = "$dir/$_";
-               if (-f "$_")
-                       {
-                       if (/\/([^\/]*)\.rsp$/)
-                               {
-                               if (exists $fips_tests{$1})
-                                       {
-                                       $debug && print "DEBUG: $1 found, will be overwritten\n";
-                                       }
-                               else
-                                       {
-                                       print STDERR "ERROR: bogus file $_\n";
-                                       push @bogus, $_;
-                                       }
-                               }
-                       next unless /$filter.*\.req$/i;
-                       if (/\/([^\/]*)\.req$/ && exists $fips_tests{$1})
-                               {
-                               $fips_found{$1}++;
-                               test_line($win32, $_, $tprefix, $1);
-                               }
-                       elsif (! /SHAmix\.req$/)
-                               {
-                               print STDERR "WARNING: unrecognized filename $_\n";
-                               }
-                       }
-               elsif (-d "$_")
-                       {
-                       if (/$filter.*req$/i)
-                               {
-                               test_dir($win32, $_);
-                               }
-                       recurse_test($win32, $tprefix, $filter, $_);
-                       }
-               }
-       closedir($dirh);
-       }
-
-#--------------------------------
-sub test_dir
-       {
-       my ($win32, $req) = @_;
-       my $rsp = $req;
-       $rsp =~ s/req$/$rspdir/;
-       if ($win32)
-               {
-               $rsp =~ tr|/|\\|;
-               $req =~ tr|/|\\|;
-               $bufdir = <<END;
-
-echo Running tests in $req
-if exist "$rsp" rd /s /q "$rsp"
-md "$rsp"
-END
-               }
-       else
-               {
-               $bufdir = <<END;
-
-echo Running tests in "$req"
-\$RM "$rsp"
-\$MKDIR "$rsp"
-
-END
-               }
-       }
-
-#--------------------------------
-sub test_line
-       {
-       my ($win32, $req, $tprefix, $tnam) = @_;
-       my $rsp = $req;
-       my $tcmd = $fips_tests{$tnam};
-
-       $bufout .= $bufdir;
-       $bufdir = "";
-               
-       $rsp =~ s/req\/([^\/]*).req$/$rspdir\/$1.rsp/;
-       if ($tcmd =~ /-f$/)
-               {
-               if ($win32)
-                       {
-                       $req =~ tr|/|\\|;
-                       $rsp =~ tr|/|\\|;
-                       $bufout .= "$tprefix$tcmd \"$req\" \"$rsp\"\n";
-                       $_programs{"$tprefix$tcmd.exe"} = 1;
-                       }
-               else
-                       {
-                       $bufout .= <<END;
-${shwrap}\${TPREFIX}$tcmd "$req" "$rsp" || { echo "$req failure" ; exit 1 
-}
-END
-                       $_programs{"${shwrap_prefix}shlib_wrap.sh"} = 1;
-                       $_programs{"$tprefix$tcmd"} = 1;
-                       }
-               return;
-               }
-       if ($tcmd =~ /SALT$/)
-               {
-               open (IN, $req) || die "Can't Open File $req";
-               my $saltlen;
-               while (<IN>)
-                       {
-                       if (/^\s*#\s*salt\s+len:\s+(\d+)\s*$/i)
-                               {
-                               my $sl = $1;
-                               print STDERR "$req salt length $sl\n" if $debug;
-                               $tcmd =~ s/SALT$/$sl/;
-                               $salt_found{"$tnam (salt $sl)"}++;
-                               last;
-                               }
-                       }
-               close IN;
-               if ($tcmd =~ /SALT$/)
-                       {
-                       die "Can't detect salt length for $req";
-                       }
-               }
-               
-       if ($win32)
-               {
-               $req =~ tr|/|\\|;
-               $rsp =~ tr|/|\\|;
-               $bufout .= "$tprefix$tcmd < \"$req\" > \"$rsp\"\n";
-               $_programs{"$tprefix$tcmd.exe"} = 1;
-               }
-       else
-               {
-               $bufout .= <<END;
-${shwrap}\${TPREFIX}$tcmd < "$req" > "$rsp" || { echo "$req failure" ; exit 1; }
-END
-               $_programs{"$tprefix$tcmd"} = 1;
-               }
-       }
-
diff --git a/deps/openssl/openssl/fips/openssl_fips_fingerprint b/deps/openssl/openssl/fips/openssl_fips_fingerprint
deleted file mode 100755 (executable)
index f59a67d..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/bin/sh
-#
-# Check the library fingerprint and generate an executable fingerprint, or
-# return an error
-
-lib=$1
-exe=$2
-ext=${HMAC_EXT:-sha1}
-
-# deal with the case where we're run from within the build and OpenSSL is
-# not yet installed.  Also, make sure LD_LIBRARY_PATH is properly set in
-# case shared libraries are built.
-if [ "X$TOP" != "X" ]
-then
-    if test "$OSTYPE" = msdosdjgpp; then
-       PATH="$TOP/apps;$TOP;$PATH"
-    else
-       PATH="$TOP/apps:$TOP:$PATH"
-    fi
-    LD_LIBRARY_PATH=$TOP; export LD_LIBRARY_PATH
-else
-    LD_LIBRARY_PATH=.; export LD_LIBRARY_PATH
-fi
-
-echo "Checking library fingerprint for $lib"
-openssl sha1 -hmac etaonrishdlcupfm $lib | sed "s/(.*\//(/" | diff -w $lib.sha1 - || { echo "$libs fingerprint mismatch"; exit 1; }
-
-[ -x $exe.exe ] && exe=$exe.exe
-
-echo "Making fingerprint for $exe"
-openssl sha1 -hmac etaonrishdlcupfm -binary $exe > $exe.$ext || rm $exe.$ext
diff --git a/deps/openssl/openssl/fips/rand/Makefile b/deps/openssl/openssl/fips/rand/Makefile
deleted file mode 100644 (file)
index 20303c8..0000000
+++ /dev/null
@@ -1,149 +0,0 @@
-#
-# OpenSSL/fips/rand/Makefile
-#
-
-DIR=   rand
-TOP=   ../..
-CC=    cc
-INCLUDES=
-CFLAG=-g
-INSTALL_PREFIX=
-OPENSSLDIR=     /usr/local/ssl
-INSTALLTOP=/usr/local/ssl
-MAKEDEPPROG=   makedepend
-MAKEDEPEND=    $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
-MAKEFILE=      Makefile
-AR=            ar r
-
-CFLAGS= $(INCLUDES) $(CFLAG)
-
-GENERAL=Makefile
-TEST= fips_randtest.c fips_rngvs.c
-APPS=
-
-LIB=$(TOP)/libcrypto.a
-LIBSRC=fips_rand.c fips_rand_selftest.c
-LIBOBJ=fips_rand.o fips_rand_selftest.o
-
-SRC= $(LIBSRC)
-
-EXHEADER= fips_rand.h
-HEADER=        $(EXHEADER)
-
-ALL=    $(GENERAL) $(SRC) $(HEADER)
-
-top:
-       (cd $(TOP); $(MAKE) DIRS=fips SDIRS=$(DIR) sub_all)
-
-all:   lib
-
-lib:   $(LIBOBJ)
-       @echo $(LIBOBJ) > lib
-
-files:
-       $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
-
-links:
-       @$(PERL) $(TOP)/util/mklink.pl $(TOP)/include/openssl $(EXHEADER)
-       @$(PERL) $(TOP)/util/mklink.pl $(TOP)/test $(TEST)
-       @$(PERL) $(TOP)/util/mklink.pl $(TOP)/apps $(APPS)
-
-install:
-       @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:
-
-Q=../testvectors/rng/req
-A=../testvectors/rng/rsp
-
-fips_test:
-       -rm -rf $(A)
-       mkdir $(A)
-       if [ -f $(Q)/ANSI931_AES128MCT.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_rngvs mct < $(Q)/ANSI931_AES128MCT.req > $(A)/ANSI931_AES128MCT.rsp; fi
-       if [ -f $(Q)/ANSI931_AES192MCT.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_rngvs mct < $(Q)/ANSI931_AES192MCT.req > $(A)/ANSI931_AES192MCT.rsp; fi
-       if [ -f $(Q)/ANSI931_AES256MCT.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_rngvs mct < $(Q)/ANSI931_AES256MCT.req > $(A)/ANSI931_AES256MCT.rsp; fi
-       if [ -f $(Q)/ANSI931_AES128VST.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_rngvs vst < $(Q)/ANSI931_AES128VST.req > $(A)/ANSI931_AES128VST.rsp; fi
-       if [ -f $(Q)/ANSI931_AES192VST.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_rngvs vst < $(Q)/ANSI931_AES192VST.req > $(A)/ANSI931_AES192VST.rsp; fi
-       if [ -f $(Q)/ANSI931_AES256VST.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_rngvs vst < $(Q)/ANSI931_AES256VST.req > $(A)/ANSI931_AES256VST.rsp; fi
-
-lint:
-       lint -DLINT $(INCLUDES) $(SRC)>fluff
-
-depend:
-       $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(SRC) $(TEST)
-
-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.
-
-fips_rand.o: ../../e_os.h ../../include/openssl/aes.h
-fips_rand.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
-fips_rand.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
-fips_rand.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-fips_rand.o: ../../include/openssl/fips.h ../../include/openssl/fips_rand.h
-fips_rand.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
-fips_rand.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-fips_rand.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
-fips_rand.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-fips_rand.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
-fips_rand.o: ../fips_locl.h fips_rand.c
-fips_rand_selftest.o: ../../include/openssl/bio.h
-fips_rand_selftest.o: ../../include/openssl/crypto.h
-fips_rand_selftest.o: ../../include/openssl/des.h
-fips_rand_selftest.o: ../../include/openssl/des_old.h
-fips_rand_selftest.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-fips_rand_selftest.o: ../../include/openssl/fips.h
-fips_rand_selftest.o: ../../include/openssl/fips_rand.h
-fips_rand_selftest.o: ../../include/openssl/lhash.h
-fips_rand_selftest.o: ../../include/openssl/opensslconf.h
-fips_rand_selftest.o: ../../include/openssl/opensslv.h
-fips_rand_selftest.o: ../../include/openssl/ossl_typ.h
-fips_rand_selftest.o: ../../include/openssl/rand.h
-fips_rand_selftest.o: ../../include/openssl/safestack.h
-fips_rand_selftest.o: ../../include/openssl/stack.h
-fips_rand_selftest.o: ../../include/openssl/symhacks.h
-fips_rand_selftest.o: ../../include/openssl/ui.h
-fips_rand_selftest.o: ../../include/openssl/ui_compat.h fips_rand_selftest.c
-fips_randtest.o: ../../e_os.h ../../include/openssl/bio.h
-fips_randtest.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
-fips_randtest.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
-fips_randtest.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-fips_randtest.o: ../../include/openssl/fips_rand.h
-fips_randtest.o: ../../include/openssl/lhash.h
-fips_randtest.o: ../../include/openssl/opensslconf.h
-fips_randtest.o: ../../include/openssl/opensslv.h
-fips_randtest.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
-fips_randtest.o: ../../include/openssl/safestack.h
-fips_randtest.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-fips_randtest.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
-fips_randtest.o: ../fips_utl.h fips_randtest.c
-fips_rngvs.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-fips_rngvs.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
-fips_rngvs.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
-fips_rngvs.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
-fips_rngvs.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
-fips_rngvs.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
-fips_rngvs.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
-fips_rngvs.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-fips_rngvs.o: ../../include/openssl/fips_rand.h ../../include/openssl/lhash.h
-fips_rngvs.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-fips_rngvs.o: ../../include/openssl/opensslconf.h
-fips_rngvs.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-fips_rngvs.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
-fips_rngvs.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-fips_rngvs.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-fips_rngvs.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
-fips_rngvs.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-fips_rngvs.o: ../../include/openssl/x509v3.h ../fips_utl.h fips_rngvs.c
diff --git a/deps/openssl/openssl/fips/rand/fips_rand.c b/deps/openssl/openssl/fips/rand/fips_rand.c
deleted file mode 100644 (file)
index 9492b15..0000000
+++ /dev/null
@@ -1,410 +0,0 @@
-/* ====================================================================
- * Copyright (c) 2007 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    openssl-core@openssl.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
- *
- */
-
-/*
- * This is a FIPS approved AES PRNG based on ANSI X9.31 A.2.4.
- */
-
-#include "e_os.h"
-
-/* If we don't define _XOPEN_SOURCE_EXTENDED, struct timeval won't
-   be defined and gettimeofday() won't be declared with strict compilers
-   like DEC C in ANSI C mode.  */
-#ifndef _XOPEN_SOURCE_EXTENDED
-#define _XOPEN_SOURCE_EXTENDED 1
-#endif
-
-#include <openssl/rand.h>
-#include <openssl/aes.h>
-#include <openssl/err.h>
-#include <openssl/fips_rand.h>
-#ifndef OPENSSL_SYS_WIN32
-#include <sys/time.h>
-#endif
-#include <assert.h>
-#ifndef OPENSSL_SYS_WIN32
-# ifdef OPENSSL_UNISTD
-#  include OPENSSL_UNISTD
-# else
-#  include <unistd.h>
-# endif
-#endif
-#include <string.h>
-#include <openssl/fips.h>
-#include "fips_locl.h"
-
-#ifdef OPENSSL_FIPS
-
-void *OPENSSL_stderr(void);
-
-#define AES_BLOCK_LENGTH       16
-
-
-/* AES FIPS PRNG implementation */
-
-typedef struct 
-       {
-       int seeded;
-       int keyed;
-       int test_mode;
-       int second;
-       int error;
-       unsigned long counter;
-       AES_KEY ks;
-       int vpos;
-       /* Temporary storage for key if it equals seed length */
-       unsigned char tmp_key[AES_BLOCK_LENGTH];
-       unsigned char V[AES_BLOCK_LENGTH];
-       unsigned char DT[AES_BLOCK_LENGTH];
-       unsigned char last[AES_BLOCK_LENGTH];
-       } FIPS_PRNG_CTX;
-
-static FIPS_PRNG_CTX sctx;
-
-static int fips_prng_fail = 0;
-
-void FIPS_rng_stick(void)
-       {
-       fips_prng_fail = 1;
-       }
-
-static void fips_rand_prng_reset(FIPS_PRNG_CTX *ctx)
-       {
-       ctx->seeded = 0;
-       ctx->keyed = 0;
-       ctx->test_mode = 0;
-       ctx->counter = 0;
-       ctx->second = 0;
-       ctx->error = 0;
-       ctx->vpos = 0;
-       OPENSSL_cleanse(ctx->V, AES_BLOCK_LENGTH);
-       OPENSSL_cleanse(&ctx->ks, sizeof(AES_KEY));
-       }
-       
-
-static int fips_set_prng_key(FIPS_PRNG_CTX *ctx,
-                       const unsigned char *key, FIPS_RAND_SIZE_T keylen)
-       {
-       FIPS_selftest_check();
-       if (keylen != 16 && keylen != 24 && keylen != 32)
-               {
-               /* error: invalid key size */
-               return 0;
-               }
-       AES_set_encrypt_key(key, keylen << 3, &ctx->ks);
-       if (keylen == 16)
-               {
-               memcpy(ctx->tmp_key, key, 16);
-               ctx->keyed = 2;
-               }
-       else
-               ctx->keyed = 1;
-       ctx->seeded = 0;
-       ctx->second = 0;
-       return 1;
-       }
-
-static int fips_set_prng_seed(FIPS_PRNG_CTX *ctx,
-                       const unsigned char *seed, FIPS_RAND_SIZE_T seedlen)
-       {
-       int i;
-       if (!ctx->keyed)
-               return 0;
-       /* In test mode seed is just supplied data */
-       if (ctx->test_mode)
-               {
-               if (seedlen != AES_BLOCK_LENGTH)
-                       return 0;
-               memcpy(ctx->V, seed, AES_BLOCK_LENGTH);
-               ctx->seeded = 1;
-               return 1;
-               }
-       /* Outside test mode XOR supplied data with existing seed */
-       for (i = 0; i < seedlen; i++)
-               {
-               ctx->V[ctx->vpos++] ^= seed[i];
-               if (ctx->vpos == AES_BLOCK_LENGTH)
-                       {
-                       ctx->vpos = 0;
-                       /* Special case if first seed and key length equals
-                        * block size check key and seed do not match.
-                        */ 
-                       if (ctx->keyed == 2)
-                               {
-                               if (!memcmp(ctx->tmp_key, ctx->V, 16))
-                                       {
-                                       RANDerr(RAND_F_FIPS_SET_PRNG_SEED,
-                                               RAND_R_PRNG_SEED_MUST_NOT_MATCH_KEY);
-                                       return 0;
-                                       }
-                               OPENSSL_cleanse(ctx->tmp_key, 16);
-                               ctx->keyed = 1;
-                               }
-                       ctx->seeded = 1;
-                       }
-               }
-       return 1;
-       }
-
-static int fips_set_test_mode(FIPS_PRNG_CTX *ctx)
-       {
-       if (ctx->keyed)
-               {
-               RANDerr(RAND_F_FIPS_SET_TEST_MODE,RAND_R_PRNG_KEYED);
-               return 0;
-               }
-       ctx->test_mode = 1;
-       return 1;
-       }
-
-int FIPS_rand_test_mode(void)
-       {
-       return fips_set_test_mode(&sctx);
-       }
-
-int FIPS_rand_set_dt(unsigned char *dt)
-       {
-       if (!sctx.test_mode)
-               {
-               RANDerr(RAND_F_FIPS_RAND_SET_DT,RAND_R_NOT_IN_TEST_MODE);
-               return 0;
-               }
-       memcpy(sctx.DT, dt, AES_BLOCK_LENGTH);
-       return 1;
-       }
-
-static void fips_get_dt(FIPS_PRNG_CTX *ctx)
-    {
-#ifdef OPENSSL_SYS_WIN32
-       FILETIME ft;
-#else
-       struct timeval tv;
-#endif
-       unsigned char *buf = ctx->DT;
-
-#ifndef GETPID_IS_MEANINGLESS
-       unsigned long pid;
-#endif
-
-#ifdef OPENSSL_SYS_WIN32
-       GetSystemTimeAsFileTime(&ft);
-       buf[0] = (unsigned char) (ft.dwHighDateTime & 0xff);
-       buf[1] = (unsigned char) ((ft.dwHighDateTime >> 8) & 0xff);
-       buf[2] = (unsigned char) ((ft.dwHighDateTime >> 16) & 0xff);
-       buf[3] = (unsigned char) ((ft.dwHighDateTime >> 24) & 0xff);
-       buf[4] = (unsigned char) (ft.dwLowDateTime & 0xff);
-       buf[5] = (unsigned char) ((ft.dwLowDateTime >> 8) & 0xff);
-       buf[6] = (unsigned char) ((ft.dwLowDateTime >> 16) & 0xff);
-       buf[7] = (unsigned char) ((ft.dwLowDateTime >> 24) & 0xff);
-#else
-       gettimeofday(&tv,NULL);
-       buf[0] = (unsigned char) (tv.tv_sec & 0xff);
-       buf[1] = (unsigned char) ((tv.tv_sec >> 8) & 0xff);
-       buf[2] = (unsigned char) ((tv.tv_sec >> 16) & 0xff);
-       buf[3] = (unsigned char) ((tv.tv_sec >> 24) & 0xff);
-       buf[4] = (unsigned char) (tv.tv_usec & 0xff);
-       buf[5] = (unsigned char) ((tv.tv_usec >> 8) & 0xff);
-       buf[6] = (unsigned char) ((tv.tv_usec >> 16) & 0xff);
-       buf[7] = (unsigned char) ((tv.tv_usec >> 24) & 0xff);
-#endif
-       buf[8] = (unsigned char) (ctx->counter & 0xff);
-       buf[9] = (unsigned char) ((ctx->counter >> 8) & 0xff);
-       buf[10] = (unsigned char) ((ctx->counter >> 16) & 0xff);
-       buf[11] = (unsigned char) ((ctx->counter >> 24) & 0xff);
-
-       ctx->counter++;
-
-
-#ifndef GETPID_IS_MEANINGLESS
-       pid=(unsigned long)getpid();
-       buf[12] = (unsigned char) (pid & 0xff);
-       buf[13] = (unsigned char) ((pid >> 8) & 0xff);
-       buf[14] = (unsigned char) ((pid >> 16) & 0xff);
-       buf[15] = (unsigned char) ((pid >> 24) & 0xff);
-#endif
-    }
-
-static int fips_rand(FIPS_PRNG_CTX *ctx,
-                       unsigned char *out, FIPS_RAND_SIZE_T outlen)
-       {
-       unsigned char R[AES_BLOCK_LENGTH], I[AES_BLOCK_LENGTH];
-       unsigned char tmp[AES_BLOCK_LENGTH];
-       int i;
-       if (ctx->error)
-               {
-               RANDerr(RAND_F_FIPS_RAND,RAND_R_PRNG_ERROR);
-               return 0;
-               }
-       if (!ctx->keyed)
-               {
-               RANDerr(RAND_F_FIPS_RAND,RAND_R_NO_KEY_SET);
-               return 0;
-               }
-       if (!ctx->seeded)
-               {
-               RANDerr(RAND_F_FIPS_RAND,RAND_R_PRNG_NOT_SEEDED);
-               return 0;
-               }
-       for (;;)
-               {
-               if (!ctx->test_mode)
-                       fips_get_dt(ctx);
-               AES_encrypt(ctx->DT, I, &ctx->ks);
-               for (i = 0; i < AES_BLOCK_LENGTH; i++)
-                       tmp[i] = I[i] ^ ctx->V[i];
-               AES_encrypt(tmp, R, &ctx->ks);
-               for (i = 0; i < AES_BLOCK_LENGTH; i++)
-                       tmp[i] = R[i] ^ I[i];
-               AES_encrypt(tmp, ctx->V, &ctx->ks);
-               /* Continuous PRNG test */
-               if (ctx->second)
-                       {
-                       if (fips_prng_fail)
-                               memcpy(ctx->last, R, AES_BLOCK_LENGTH);
-                       if (!memcmp(R, ctx->last, AES_BLOCK_LENGTH))
-                               {
-                               RANDerr(RAND_F_FIPS_RAND,RAND_R_PRNG_STUCK);
-                               ctx->error = 1;
-                               fips_set_selftest_fail();
-                               return 0;
-                               }
-                       }
-               memcpy(ctx->last, R, AES_BLOCK_LENGTH);
-               if (!ctx->second)
-                       {
-                       ctx->second = 1;
-                       if (!ctx->test_mode)
-                               continue;
-                       }
-
-               if (outlen <= AES_BLOCK_LENGTH)
-                       {
-                       memcpy(out, R, outlen);
-                       break;
-                       }
-
-               memcpy(out, R, AES_BLOCK_LENGTH);
-               out += AES_BLOCK_LENGTH;
-               outlen -= AES_BLOCK_LENGTH;
-               }
-       return 1;
-       }
-
-
-int FIPS_rand_set_key(const unsigned char *key, FIPS_RAND_SIZE_T keylen)
-       {
-       int ret;
-       CRYPTO_w_lock(CRYPTO_LOCK_RAND);
-       ret = fips_set_prng_key(&sctx, key, keylen);
-       CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
-       return ret;
-       }
-
-int FIPS_rand_seed(const void *seed, FIPS_RAND_SIZE_T seedlen)
-       {
-       int ret;
-       CRYPTO_w_lock(CRYPTO_LOCK_RAND);
-       ret = fips_set_prng_seed(&sctx, seed, seedlen);
-       CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
-       return ret;
-       }
-
-
-int FIPS_rand_bytes(unsigned char *out, FIPS_RAND_SIZE_T count)
-       {
-       int ret;
-       CRYPTO_w_lock(CRYPTO_LOCK_RAND);
-       ret = fips_rand(&sctx, out, count);
-       CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
-       return ret;
-       }
-
-int FIPS_rand_status(void)
-       {
-       int ret;
-       CRYPTO_r_lock(CRYPTO_LOCK_RAND);
-       ret = sctx.seeded;
-       CRYPTO_r_unlock(CRYPTO_LOCK_RAND);
-       return ret;
-       }
-
-void FIPS_rand_reset(void)
-       {
-       CRYPTO_w_lock(CRYPTO_LOCK_RAND);
-       fips_rand_prng_reset(&sctx);
-       CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
-       }
-
-static void fips_do_rand_seed(const void *seed, FIPS_RAND_SIZE_T seedlen)
-       {
-       FIPS_rand_seed(seed, seedlen);
-       }
-
-static void fips_do_rand_add(const void *seed, FIPS_RAND_SIZE_T seedlen,
-                                       double add_entropy)
-       {
-       FIPS_rand_seed(seed, seedlen);
-       }
-
-static const RAND_METHOD rand_fips_meth=
-    {
-    fips_do_rand_seed,
-    FIPS_rand_bytes,
-    FIPS_rand_reset,
-    fips_do_rand_add,
-    FIPS_rand_bytes,
-    FIPS_rand_status
-    };
-
-const RAND_METHOD *FIPS_rand_method(void)
-{
-  return &rand_fips_meth;
-}
-
-#endif
diff --git a/deps/openssl/openssl/fips/rand/fips_rand_selftest.c b/deps/openssl/openssl/fips/rand/fips_rand_selftest.c
deleted file mode 100644 (file)
index 2194a76..0000000
+++ /dev/null
@@ -1,371 +0,0 @@
-/* ====================================================================
- * Copyright (c) 2003 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    openssl-core@openssl.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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 <string.h>
-#include <openssl/err.h>
-#include <openssl/fips.h>
-#include <openssl/rand.h>
-#include <openssl/fips_rand.h>
-
-#ifdef OPENSSL_FIPS
-
-
-
-typedef struct
-       {
-       unsigned char DT[16];
-       unsigned char V[16];
-       unsigned char R[16];
-       } AES_PRNG_TV;
-
-/* The following test vectors are taken directly from the RGNVS spec */
-
-static unsigned char aes_128_key[16] =
-               {0xf3,0xb1,0x66,0x6d,0x13,0x60,0x72,0x42,
-                0xed,0x06,0x1c,0xab,0xb8,0xd4,0x62,0x02};
-
-static AES_PRNG_TV aes_128_tv[] = {
-       {
-                               /* DT */
-               {0xe6,0xb3,0xbe,0x78,0x2a,0x23,0xfa,0x62,
-                0xd7,0x1d,0x4a,0xfb,0xb0,0xe9,0x22,0xf9},
-                               /* V */
-               {0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
-                               /* R */
-               {0x59,0x53,0x1e,0xd1,0x3b,0xb0,0xc0,0x55,
-                0x84,0x79,0x66,0x85,0xc1,0x2f,0x76,0x41}
-       },
-       {
-                               /* DT */
-               {0xe6,0xb3,0xbe,0x78,0x2a,0x23,0xfa,0x62,
-                0xd7,0x1d,0x4a,0xfb,0xb0,0xe9,0x22,0xfa},
-                               /* V */
-               {0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
-                               /* R */
-               {0x7c,0x22,0x2c,0xf4,0xca,0x8f,0xa2,0x4c,
-                0x1c,0x9c,0xb6,0x41,0xa9,0xf3,0x22,0x0d}
-       },
-       {
-                               /* DT */
-               {0xe6,0xb3,0xbe,0x78,0x2a,0x23,0xfa,0x62,
-                0xd7,0x1d,0x4a,0xfb,0xb0,0xe9,0x22,0xfb},
-                               /* V */
-               {0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
-                               /* R */
-               {0x8a,0xaa,0x00,0x39,0x66,0x67,0x5b,0xe5,
-                0x29,0x14,0x28,0x81,0xa9,0x4d,0x4e,0xc7}
-       },
-       {
-                               /* DT */
-               {0xe6,0xb3,0xbe,0x78,0x2a,0x23,0xfa,0x62,
-                0xd7,0x1d,0x4a,0xfb,0xb0,0xe9,0x22,0xfc},
-                               /* V */
-               {0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
-                               /* R */
-               {0x88,0xdd,0xa4,0x56,0x30,0x24,0x23,0xe5,
-                0xf6,0x9d,0xa5,0x7e,0x7b,0x95,0xc7,0x3a}
-       },
-       {
-                               /* DT */
-               {0xe6,0xb3,0xbe,0x78,0x2a,0x23,0xfa,0x62,
-                0xd7,0x1d,0x4a,0xfb,0xb0,0xe9,0x22,0xfd},
-                               /* V */
-               {0xf8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
-                               /* R */
-               {0x05,0x25,0x92,0x46,0x61,0x79,0xd2,0xcb,
-                0x78,0xc4,0x0b,0x14,0x0a,0x5a,0x9a,0xc8}
-       },
-       {
-                               /* DT */
-               {0xe6,0xb3,0xbe,0x78,0x2a,0x23,0xfa,0x62,
-                0xd7,0x1d,0x4a,0xfb,0xb0,0xe9,0x23,0x77},
-                               /* V */
-               {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-                0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe},
-                               /* R */
-               {0x0d,0xd5,0xa0,0x36,0x7a,0x59,0x26,0xbc,
-                0x48,0xd9,0x38,0xbf,0xf0,0x85,0x8f,0xea}
-       },
-       {
-                               /* DT */
-               {0xe6,0xb3,0xbe,0x78,0x2a,0x23,0xfa,0x62,
-                0xd7,0x1d,0x4a,0xfb,0xb0,0xe9,0x23,0x78},
-                               /* V */
-               {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-                0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
-                               /* R */
-               {0xae,0x53,0x87,0xee,0x8c,0xd9,0x12,0xf5,
-                0x73,0x53,0xae,0x03,0xf9,0xd5,0x13,0x33}
-       },
-};
-
-static unsigned char aes_192_key[24] =
-               {0x15,0xd8,0x78,0x0d,0x62,0xd3,0x25,0x6e,
-                0x44,0x64,0x10,0x13,0x60,0x2b,0xa9,0xbc,
-                0x4a,0xfb,0xca,0xeb,0x4c,0x8b,0x99,0x3b};
-
-static AES_PRNG_TV aes_192_tv[] = {
-       {
-                               /* DT */
-               {0x3f,0xd8,0xff,0xe8,0x80,0x69,0x8b,0xc1,
-                0xbf,0x99,0x7d,0xa4,0x24,0x78,0xf3,0x4b},
-                               /* V */
-               {0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
-                               /* R */
-               {0x17,0x07,0xd5,0x28,0x19,0x79,0x1e,0xef,
-                0xa5,0x0c,0xbf,0x25,0xe5,0x56,0xb4,0x93}
-       },
-       {
-                               /* DT */
-               {0x3f,0xd8,0xff,0xe8,0x80,0x69,0x8b,0xc1,
-                0xbf,0x99,0x7d,0xa4,0x24,0x78,0xf3,0x4c},
-                               /* V */
-               {0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
-                               /* R */
-               {0x92,0x8d,0xbe,0x07,0xdd,0xc7,0x58,0xc0,
-                0x6f,0x35,0x41,0x9b,0x17,0xc9,0xbd,0x9b}
-       },
-       {
-                               /* DT */
-               {0x3f,0xd8,0xff,0xe8,0x80,0x69,0x8b,0xc1,
-                0xbf,0x99,0x7d,0xa4,0x24,0x78,0xf3,0x4d},
-                               /* V */
-               {0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
-                               /* R */
-               {0xd5,0xde,0xf4,0x50,0xf3,0xb7,0x10,0x4e,
-                0xb8,0xc6,0xf8,0xcf,0xe2,0xb1,0xca,0xa2}
-       },
-       {
-                               /* DT */
-               {0x3f,0xd8,0xff,0xe8,0x80,0x69,0x8b,0xc1,
-                0xbf,0x99,0x7d,0xa4,0x24,0x78,0xf3,0x4e},
-                               /* V */
-               {0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
-                               /* R */
-               {0xce,0x29,0x08,0x43,0xfc,0x34,0x41,0xe7,
-                0x47,0x8f,0xb3,0x66,0x2b,0x46,0xb1,0xbb}
-       },
-       {
-                               /* DT */
-               {0x3f,0xd8,0xff,0xe8,0x80,0x69,0x8b,0xc1,
-                0xbf,0x99,0x7d,0xa4,0x24,0x78,0xf3,0x4f},
-                               /* V */
-               {0xf8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
-                               /* R */
-               {0xb3,0x26,0x0f,0xf5,0xd6,0xca,0xa8,0xbf,
-                0x89,0xb8,0x5e,0x2f,0x22,0x56,0x92,0x2f}
-       },
-       {
-                               /* DT */
-               {0x3f,0xd8,0xff,0xe8,0x80,0x69,0x8b,0xc1,
-                0xbf,0x99,0x7d,0xa4,0x24,0x78,0xf3,0xc9},
-                               /* V */
-               {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-                0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe},
-                               /* R */
-               {0x05,0xeb,0x18,0x52,0x34,0x43,0x00,0x43,
-                0x6e,0x5a,0xa5,0xfe,0x7b,0x32,0xc4,0x2d}
-       },
-       {
-                               /* DT */
-               {0x3f,0xd8,0xff,0xe8,0x80,0x69,0x8b,0xc1,
-                0xbf,0x99,0x7d,0xa4,0x24,0x78,0xf3,0xca},
-                               /* V */
-               {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-                0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
-                               /* R */
-               {0x15,0x3c,0xe8,0xd1,0x04,0xc7,0xad,0x50,
-                0x0b,0xf0,0x07,0x16,0xe7,0x56,0x7a,0xea}
-       },
-};
-
-static unsigned char aes_256_key[32] =
-               {0x6d,0x14,0x06,0x6c,0xb6,0xd8,0x21,0x2d,
-                0x82,0x8d,0xfa,0xf2,0x7a,0x03,0xb7,0x9f,
-                0x0c,0xc7,0x3e,0xcd,0x76,0xeb,0xee,0xb5,
-                0x21,0x05,0x8c,0x4f,0x31,0x7a,0x80,0xbb};
-
-static AES_PRNG_TV aes_256_tv[] = {
-       {
-                               /* DT */
-               {0xda,0x3a,0x41,0xec,0x1d,0xa3,0xb0,0xd5,
-                0xf2,0xa9,0x4e,0x34,0x74,0x8e,0x9e,0x88},
-                               /* V */
-               {0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
-                               /* R */
-               {0x35,0xc7,0xef,0xa7,0x78,0x4d,0x29,0xbc,
-                0x82,0x79,0x99,0xfb,0xd0,0xb3,0x3b,0x72}
-       },
-       {
-                               /* DT */
-               {0xda,0x3a,0x41,0xec,0x1d,0xa3,0xb0,0xd5,
-                0xf2,0xa9,0x4e,0x34,0x74,0x8e,0x9e,0x89},
-                               /* V */
-               {0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
-                               /* R */
-               {0x6c,0xf4,0x42,0x5d,0xc7,0x04,0x1a,0x41,
-                0x28,0x2a,0x78,0xa9,0xb0,0x12,0xc4,0x95}
-       },
-       {
-                               /* DT */
-               {0xda,0x3a,0x41,0xec,0x1d,0xa3,0xb0,0xd5,
-                0xf2,0xa9,0x4e,0x34,0x74,0x8e,0x9e,0x8a},
-                               /* V */
-               {0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
-                               /* R */
-               {0x16,0x90,0xa4,0xff,0x7b,0x7e,0xb9,0x30,
-                0xdb,0x67,0x4b,0xac,0x2d,0xe1,0xd1,0x75}
-       },
-       {
-                               /* DT */
-               {0xda,0x3a,0x41,0xec,0x1d,0xa3,0xb0,0xd5,
-                0xf2,0xa9,0x4e,0x34,0x74,0x8e,0x9e,0x8b},
-                               /* V */
-               {0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
-                               /* R */
-               {0x14,0x6f,0xf5,0x95,0xa1,0x46,0x65,0x30,
-                0xbc,0x57,0xe2,0x4a,0xf7,0x45,0x62,0x05}
-       },
-       {
-                               /* DT */
-               {0xda,0x3a,0x41,0xec,0x1d,0xa3,0xb0,0xd5,
-                0xf2,0xa9,0x4e,0x34,0x74,0x8e,0x9e,0x8c},
-                               /* V */
-               {0xf8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
-                               /* R */
-               {0x96,0xe2,0xb4,0x1e,0x66,0x5e,0x0f,0xa4,
-                0xc5,0xcd,0xa2,0x07,0xcc,0xb7,0x94,0x40}
-       },
-       {
-                               /* DT */
-               {0xda,0x3a,0x41,0xec,0x1d,0xa3,0xb0,0xd5,
-                0xf2,0xa9,0x4e,0x34,0x74,0x8e,0x9f,0x06},
-                               /* V */
-               {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-                0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe},
-                               /* R */
-               {0x61,0xce,0x1d,0x6a,0x48,0x75,0x97,0x28,
-                0x4b,0x41,0xde,0x18,0x44,0x4f,0x56,0xec}
-       },
-       {
-                               /* DT */
-               {0xda,0x3a,0x41,0xec,0x1d,0xa3,0xb0,0xd5,
-                0xf2,0xa9,0x4e,0x34,0x74,0x8e,0x9f,0x07},
-                               /* V */
-               {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-                0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
-                               /* R */
-               {0x52,0x89,0x59,0x79,0x2d,0xaa,0x28,0xb3,
-                0xb0,0x8a,0x3e,0x70,0xfa,0x71,0x59,0x84}
-       },
-};
-
-
-void FIPS_corrupt_rng()
-    {
-    aes_192_tv[0].V[0]++;
-    }
-
-#define fips_rand_test(key, tv) \
-       do_rand_test(key, sizeof key, tv, sizeof(tv)/sizeof(AES_PRNG_TV))
-
-static int do_rand_test(unsigned char *key, int keylen,
-                       AES_PRNG_TV *tv, int ntv)
-       {
-       unsigned char R[16];
-       int i;
-       if (!FIPS_rand_set_key(key, keylen))
-               return 0;
-       for (i = 0; i < ntv; i++)
-               {
-               FIPS_rand_seed(tv[i].V, 16);
-               FIPS_rand_set_dt(tv[i].DT);
-               FIPS_rand_bytes(R, 16);
-               if (memcmp(R, tv[i].R, 16))
-                       return 0;
-               }
-       return 1;
-       }
-       
-
-int FIPS_selftest_rng()
-       {
-       FIPS_rand_reset();
-       if (!FIPS_rand_test_mode())
-               {
-               FIPSerr(FIPS_F_FIPS_SELFTEST_RNG,FIPS_R_SELFTEST_FAILED);
-               return 0;
-               }
-       if (!fips_rand_test(aes_128_key,aes_128_tv)
-               || !fips_rand_test(aes_192_key, aes_192_tv)
-               || !fips_rand_test(aes_256_key, aes_256_tv))
-               {
-               FIPSerr(FIPS_F_FIPS_SELFTEST_RNG,FIPS_R_SELFTEST_FAILED);
-               return 0;
-               }
-       FIPS_rand_reset();
-       return 1;
-       }
-
-#endif
diff --git a/deps/openssl/openssl/fips/rand/fips_randtest.c b/deps/openssl/openssl/fips/rand/fips_randtest.c
deleted file mode 100644 (file)
index 5582941..0000000
+++ /dev/null
@@ -1,248 +0,0 @@
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-/* ====================================================================
- * Copyright (c) 2003 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    openssl-core@openssl.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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 <string.h>
-#include <ctype.h>
-#include <openssl/rand.h>
-#include <openssl/fips_rand.h>
-#include <openssl/err.h>
-#include <openssl/bn.h>
-
-#include "e_os.h"
-
-#ifndef OPENSSL_FIPS
-int main(int argc, char *argv[])
-{
-    printf("No FIPS RAND support\n");
-    return(0);
-}
-
-#else
-
-#include "fips_utl.h"
-
-typedef struct
-       {
-       unsigned char DT[16];
-       unsigned char V[16];
-       unsigned char R[16];
-       } AES_PRNG_MCT;
-
-static unsigned char aes_128_mct_key[16] =
-       {0x9f,0x5b,0x51,0x20,0x0b,0xf3,0x34,0xb5,
-        0xd8,0x2b,0xe8,0xc3,0x72,0x55,0xc8,0x48};
-
-static AES_PRNG_MCT aes_128_mct_tv = {
-                       /* DT */
-       {0x63,0x76,0xbb,0xe5,0x29,0x02,0xba,0x3b,
-        0x67,0xc9,0x25,0xfa,0x70,0x1f,0x11,0xac},
-                       /* V */
-       {0x57,0x2c,0x8e,0x76,0x87,0x26,0x47,0x97,
-        0x7e,0x74,0xfb,0xdd,0xc4,0x95,0x01,0xd1},
-                       /* R */
-       {0x48,0xe9,0xbd,0x0d,0x06,0xee,0x18,0xfb,
-        0xe4,0x57,0x90,0xd5,0xc3,0xfc,0x9b,0x73}
-};
-
-static unsigned char aes_192_mct_key[24] =
-       {0xb7,0x6c,0x34,0xd1,0x09,0x67,0xab,0x73,
-        0x4d,0x5a,0xd5,0x34,0x98,0x16,0x0b,0x91,
-        0xbc,0x35,0x51,0x16,0x6b,0xae,0x93,0x8a};
-
-static AES_PRNG_MCT aes_192_mct_tv = {
-                       /* DT */
-       {0x84,0xce,0x22,0x7d,0x91,0x5a,0xa3,0xc9,
-        0x84,0x3c,0x0a,0xb3,0xa9,0x63,0x15,0x52},
-                       /* V */
-       {0xb6,0xaf,0xe6,0x8f,0x99,0x9e,0x90,0x64,
-        0xdd,0xc7,0x7a,0xc1,0xbb,0x90,0x3a,0x6d},
-                       /* R */
-       {0xfc,0x85,0x60,0x9a,0x29,0x6f,0xef,0x21,
-        0xdd,0x86,0x20,0x32,0x8a,0x29,0x6f,0x47}
-};
-
-static unsigned char aes_256_mct_key[32] =
-       {0x9b,0x05,0xc8,0x68,0xff,0x47,0xf8,0x3a,
-        0xa6,0x3a,0xa8,0xcb,0x4e,0x71,0xb2,0xe0,
-        0xb8,0x7e,0xf1,0x37,0xb6,0xb4,0xf6,0x6d,
-        0x86,0x32,0xfc,0x1f,0x5e,0x1d,0x1e,0x50};
-
-static AES_PRNG_MCT aes_256_mct_tv = {
-                       /* DT */
-       {0x31,0x6e,0x35,0x9a,0xb1,0x44,0xf0,0xee,
-        0x62,0x6d,0x04,0x46,0xe0,0xa3,0x92,0x4c},
-                       /* V */
-       {0x4f,0xcd,0xc1,0x87,0x82,0x1f,0x4d,0xa1,
-        0x3e,0x0e,0x56,0x44,0x59,0xe8,0x83,0xca},
-                       /* R */
-       {0xc8,0x87,0xc2,0x61,0x5b,0xd0,0xb9,0xe1,
-        0xe7,0xf3,0x8b,0xd7,0x5b,0xd5,0xf1,0x8d}
-};
-
-static void dump(const unsigned char *b,int n)
-    {
-    while(n-- > 0)
-       {
-       printf(" %02x",*b++);
-       }
-    }
-
-static void compare(const unsigned char *result,const unsigned char *expected,
-                   int n)
-    {
-    int i;
-
-    for(i=0 ; i < n ; ++i)
-       if(result[i] != expected[i])
-           {
-           puts("Random test failed, got:");
-           dump(result,n);
-           puts("\n               expected:");
-           dump(expected,n);
-           putchar('\n');
-           EXIT(1);
-           }
-    }
-
-
-static void run_test(unsigned char *key, int keylen, AES_PRNG_MCT *tv)
-    {
-    unsigned char buf[16], dt[16];
-    int i, j;
-    FIPS_rand_reset();
-    FIPS_rand_test_mode();
-    FIPS_rand_set_key(key, keylen);
-    FIPS_rand_seed(tv->V, 16);
-    memcpy(dt, tv->DT, 16);
-    for (i = 0; i < 10000; i++)
-       {
-       FIPS_rand_set_dt(dt);
-       FIPS_rand_bytes(buf, 16);
-       /* Increment DT */
-       for (j = 15; j >= 0; j--)
-               {
-               dt[j]++;
-               if (dt[j])
-                       break;
-               }
-       }
-
-    compare(buf,tv->R, 16);
-    }
-
-int main()
-       {
-       run_test(aes_128_mct_key, 16, &aes_128_mct_tv);
-       printf("FIPS PRNG test 1 done\n");
-       run_test(aes_192_mct_key, 24, &aes_192_mct_tv);
-       printf("FIPS PRNG test 2 done\n");
-       run_test(aes_256_mct_key, 32, &aes_256_mct_tv);
-       printf("FIPS PRNG test 3 done\n");
-       return 0;
-       }
-
-#endif
diff --git a/deps/openssl/openssl/fips/rand/fips_rngvs.c b/deps/openssl/openssl/fips/rand/fips_rngvs.c
deleted file mode 100644 (file)
index 80a8017..0000000
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- * Crude test driver for processing the VST and MCT testvector files
- * generated by the CMVP RNGVS product.
- *
- * Note the input files are assumed to have a _very_ specific format
- * as described in the NIST document "The Random Number Generator
- * Validation System (RNGVS)", May 25, 2004.
- *
- */
-#include <openssl/opensslconf.h>
-
-#ifndef OPENSSL_FIPS
-#include <stdio.h>
-
-int main(int argc, char **argv)
-{
-    printf("No FIPS RNG support\n");
-    return 0;
-}
-#else
-
-#include <openssl/bn.h>
-#include <openssl/dsa.h>
-#include <openssl/fips.h>
-#include <openssl/err.h>
-#include <openssl/rand.h>
-#include <openssl/fips_rand.h>
-#include <openssl/x509v3.h>
-#include <string.h>
-#include <ctype.h>
-
-#include "fips_utl.h"
-
-static void vst()
-    {
-    unsigned char *key = NULL;
-    unsigned char *v = NULL;
-    unsigned char *dt = NULL;
-    unsigned char ret[16];
-    char buf[1024];
-    char lbuf[1024];
-    char *keyword, *value;
-    long i, keylen;
-
-    keylen = 0;
-
-    while(fgets(buf,sizeof buf,stdin) != NULL)
-       {
-       fputs(buf,stdout);
-       if(!strncmp(buf,"[AES 128-Key]", 13))
-               keylen = 16;
-       else if(!strncmp(buf,"[AES 192-Key]", 13))
-               keylen = 24;
-       else if(!strncmp(buf,"[AES 256-Key]", 13))
-               keylen = 32;
-       if (!parse_line(&keyword, &value, lbuf, buf))
-               continue;
-       if(!strcmp(keyword,"Key"))
-           {
-           key=hex2bin_m(value,&i);
-           if (i != keylen)
-               {
-               fprintf(stderr, "Invalid key length, expecting %ld\n", keylen);
-               return;
-               }
-           }
-       else if(!strcmp(keyword,"DT"))
-           {
-           dt=hex2bin_m(value,&i);
-           if (i != 16)
-               {
-               fprintf(stderr, "Invalid DT length\n");
-               return;
-               }
-           }
-       else if(!strcmp(keyword,"V"))
-           {
-           v=hex2bin_m(value,&i);
-           if (i != 16)
-               {
-               fprintf(stderr, "Invalid V length\n");
-               return;
-               }
-
-           if (!key || !dt)
-               {
-               fprintf(stderr, "Missing key or DT\n");
-               return;
-               }
-
-           FIPS_rand_set_key(key, keylen);
-           FIPS_rand_seed(v,16);
-           FIPS_rand_set_dt(dt);
-           if (FIPS_rand_bytes(ret,16) <= 0)
-               {
-               fprintf(stderr, "Error getting PRNG value\n");
-               return;
-               }
-
-           pv("R",ret,16);
-           OPENSSL_free(key);
-           key = NULL;
-           OPENSSL_free(dt);
-           dt = NULL;
-           OPENSSL_free(v);
-           v = NULL;
-           }
-       }
-    }
-
-static void mct()
-    {
-    unsigned char *key = NULL;
-    unsigned char *v = NULL;
-    unsigned char *dt = NULL;
-    unsigned char ret[16];
-    char buf[1024];
-    char lbuf[1024];
-    char *keyword, *value;
-    long i, keylen;
-    int j;
-
-    keylen = 0;
-
-    while(fgets(buf,sizeof buf,stdin) != NULL)
-       {
-       fputs(buf,stdout);
-       if(!strncmp(buf,"[AES 128-Key]", 13))
-               keylen = 16;
-       else if(!strncmp(buf,"[AES 192-Key]", 13))
-               keylen = 24;
-       else if(!strncmp(buf,"[AES 256-Key]", 13))
-               keylen = 32;
-       if (!parse_line(&keyword, &value, lbuf, buf))
-               continue;
-       if(!strcmp(keyword,"Key"))
-           {
-           key=hex2bin_m(value,&i);
-           if (i != keylen)
-               {
-               fprintf(stderr, "Invalid key length, expecting %ld\n", keylen);
-               return;
-               }
-           }
-       else if(!strcmp(keyword,"DT"))
-           {
-           dt=hex2bin_m(value,&i);
-           if (i != 16)
-               {
-               fprintf(stderr, "Invalid DT length\n");
-               return;
-               }
-           }
-       else if(!strcmp(keyword,"V"))
-           {
-           v=hex2bin_m(value,&i);
-           if (i != 16)
-               {
-               fprintf(stderr, "Invalid V length\n");
-               return;
-               }
-
-           if (!key || !dt)
-               {
-               fprintf(stderr, "Missing key or DT\n");
-               return;
-               }
-
-           FIPS_rand_set_key(key, keylen);
-           FIPS_rand_seed(v,16);
-           for (i = 0; i < 10000; i++)
-               {
-                   FIPS_rand_set_dt(dt);
-                   if (FIPS_rand_bytes(ret,16) <= 0)
-                       {
-                       fprintf(stderr, "Error getting PRNG value\n");
-                       return;
-                       }
-                   /* Increment DT */
-                   for (j = 15; j >= 0; j--)
-                       {
-                       dt[j]++;
-                       if (dt[j])
-                               break;
-                       }
-               }
-
-           pv("R",ret,16);
-           OPENSSL_free(key);
-           key = NULL;
-           OPENSSL_free(dt);
-           dt = NULL;
-           OPENSSL_free(v);
-           v = NULL;
-           }
-       }
-    }
-
-int main(int argc,char **argv)
-    {
-    if(argc != 2)
-       {
-       fprintf(stderr,"%s [mct|vst]\n",argv[0]);
-       exit(1);
-       }
-    if(!FIPS_mode_set(1))
-       {
-       do_print_errors();
-       exit(1);
-       }
-    FIPS_rand_reset();
-    if (!FIPS_rand_test_mode())
-       {
-       fprintf(stderr, "Error setting PRNG test mode\n");
-       do_print_errors();
-       exit(1);
-       }
-    if(!strcmp(argv[1],"mct"))
-       mct();
-    else if(!strcmp(argv[1],"vst"))
-       vst();
-    else
-       {
-       fprintf(stderr,"Don't know how to %s.\n",argv[1]);
-       exit(1);
-       }
-
-    return 0;
-    }
-#endif
diff --git a/deps/openssl/openssl/fips/rsa/Makefile b/deps/openssl/openssl/fips/rsa/Makefile
deleted file mode 100644 (file)
index da28c13..0000000
+++ /dev/null
@@ -1,215 +0,0 @@
-#
-# OpenSSL/fips/rsa/Makefile
-#
-
-DIR=   rsa
-TOP=   ../..
-CC=    cc
-INCLUDES=
-CFLAG=-g
-INSTALL_PREFIX=
-OPENSSLDIR=     /usr/local/ssl
-INSTALLTOP=/usr/local/ssl
-MAKEDEPPROG=   makedepend
-MAKEDEPEND=    $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
-MAKEFILE=      Makefile
-AR=            ar r
-
-CFLAGS= $(INCLUDES) $(CFLAG)
-
-GENERAL=Makefile
-TEST= fips_rsavtest.c fips_rsastest.c fips_rsagtest.c
-APPS=
-
-LIB=$(TOP)/libcrypto.a
-LIBSRC=fips_rsa_eay.c fips_rsa_gen.c fips_rsa_selftest.c fips_rsa_x931g.c \
-       fips_rsa_sign.c fips_rsa_lib.c
-LIBOBJ=fips_rsa_eay.o fips_rsa_gen.o fips_rsa_selftest.o fips_rsa_x931g.o \
-       fips_rsa_sign.o fips_rsa_lib.o
-
-SRC= $(LIBSRC)
-
-EXHEADER=
-HEADER=        $(EXHEADER)
-
-ALL=    $(GENERAL) $(SRC) $(HEADER)
-
-top:
-       (cd $(TOP); $(MAKE) DIRS=fips FDIRS=$(DIR) sub_all)
-
-all:   lib
-
-lib:   $(LIBOBJ)
-       @echo $(LIBOBJ) > lib
-
-files:
-       $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
-
-links:
-       @$(PERL) $(TOP)/util/mklink.pl $(TOP)/include/openssl $(EXHEADER)
-       @$(PERL) $(TOP)/util/mklink.pl $(TOP)/test $(TEST)
-       @$(PERL) $(TOP)/util/mklink.pl $(TOP)/apps $(APPS)
-
-install:
-       @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:
-
-Q=../testvectors/rsa/req
-A=../testvectors/rsa/rsp
-Q62=../testvectors/rsa_salt_62/req
-A62=../testvectors/rsa_salt_62/rsp
-
-fips_test:
-       -rm -rf $(A) $(A62)
-       mkdir $(A) $(A62)
-       if [ -f $(Q)/SigGen15.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_rsastest < $(Q)/SigGen15.req  > $(A)/SigGen15.rsp; fi
-       if [ -f $(Q)/SigVer15.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_rsavtest < $(Q)/SigVer15.req > $(A)/SigVer15.rsp; fi
-       if [ -f $(Q)/SigGenPSS.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_rsastest -saltlen 0 < $(Q)/SigGenPSS.req > $(A)/SigGenPSS.rsp; fi
-       if [ -f $(Q)/SigVerPSS.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_rsavtest -saltlen 0 < $(Q)/SigVerPSS.req > $(A)/SigVerPSS.rsp; fi
-       if [ -f $(Q)/SigGenRSA.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_rsastest -x931 < $(Q)/SigGenRSA.req > $(A)/SigGenRSA.rsp; fi
-       if [ -f $(Q)/SigVerRSA.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_rsavtest -x931 < $(Q)/SigVerRSA.req > $(A)/SigVerRSA.rsp; fi
-       if [ -f $(Q62)/SigGenPSS.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_rsastest -saltlen 62 < $(Q62)/SigGenPSS.req >$(A62)/SigGenPSS.rsp; fi
-       if [ -f $(Q62)/SigVerPSS.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_rsavtest -saltlen 62 <$(Q62)/SigVerPSS.req >$(A62)/SigVerPSS.rsp; fi
-       if [ -f $(Q)/KeyGenRSA.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_rsagtest < $(Q)/KeyGenRSA.req > $(A)/KeyGenRSA.rsp; fi
-
-lint:
-       lint -DLINT $(INCLUDES) $(SRC)>fluff
-
-depend:
-       $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(SRC) $(TEST)
-
-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.
-
-fips_rsa_eay.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-fips_rsa_eay.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
-fips_rsa_eay.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-fips_rsa_eay.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-fips_rsa_eay.o: ../../include/openssl/opensslconf.h
-fips_rsa_eay.o: ../../include/openssl/opensslv.h
-fips_rsa_eay.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
-fips_rsa_eay.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
-fips_rsa_eay.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-fips_rsa_eay.o: fips_rsa_eay.c
-fips_rsa_gen.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-fips_rsa_gen.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
-fips_rsa_gen.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-fips_rsa_gen.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-fips_rsa_gen.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-fips_rsa_gen.o: ../../include/openssl/objects.h
-fips_rsa_gen.o: ../../include/openssl/opensslconf.h
-fips_rsa_gen.o: ../../include/openssl/opensslv.h
-fips_rsa_gen.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rsa.h
-fips_rsa_gen.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-fips_rsa_gen.o: ../../include/openssl/symhacks.h ../fips_locl.h fips_rsa_gen.c
-fips_rsa_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-fips_rsa_lib.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
-fips_rsa_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-fips_rsa_lib.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-fips_rsa_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-fips_rsa_lib.o: ../../include/openssl/objects.h
-fips_rsa_lib.o: ../../include/openssl/opensslconf.h
-fips_rsa_lib.o: ../../include/openssl/opensslv.h
-fips_rsa_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rsa.h
-fips_rsa_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-fips_rsa_lib.o: ../../include/openssl/symhacks.h fips_rsa_lib.c
-fips_rsa_selftest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-fips_rsa_selftest.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
-fips_rsa_selftest.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-fips_rsa_selftest.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-fips_rsa_selftest.o: ../../include/openssl/lhash.h
-fips_rsa_selftest.o: ../../include/openssl/obj_mac.h
-fips_rsa_selftest.o: ../../include/openssl/objects.h
-fips_rsa_selftest.o: ../../include/openssl/opensslconf.h
-fips_rsa_selftest.o: ../../include/openssl/opensslv.h
-fips_rsa_selftest.o: ../../include/openssl/ossl_typ.h
-fips_rsa_selftest.o: ../../include/openssl/rsa.h
-fips_rsa_selftest.o: ../../include/openssl/safestack.h
-fips_rsa_selftest.o: ../../include/openssl/stack.h
-fips_rsa_selftest.o: ../../include/openssl/symhacks.h fips_rsa_selftest.c
-fips_rsa_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-fips_rsa_sign.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
-fips_rsa_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-fips_rsa_sign.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-fips_rsa_sign.o: ../../include/openssl/obj_mac.h
-fips_rsa_sign.o: ../../include/openssl/objects.h
-fips_rsa_sign.o: ../../include/openssl/opensslconf.h
-fips_rsa_sign.o: ../../include/openssl/opensslv.h
-fips_rsa_sign.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rsa.h
-fips_rsa_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-fips_rsa_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-fips_rsa_sign.o: fips_rsa_sign.c
-fips_rsa_x931g.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-fips_rsa_x931g.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
-fips_rsa_x931g.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-fips_rsa_x931g.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-fips_rsa_x931g.o: ../../include/openssl/opensslconf.h
-fips_rsa_x931g.o: ../../include/openssl/opensslv.h
-fips_rsa_x931g.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rsa.h
-fips_rsa_x931g.o: ../../include/openssl/safestack.h
-fips_rsa_x931g.o: ../../include/openssl/stack.h
-fips_rsa_x931g.o: ../../include/openssl/symhacks.h fips_rsa_x931g.c
-fips_rsagtest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-fips_rsagtest.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
-fips_rsagtest.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
-fips_rsagtest.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-fips_rsagtest.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
-fips_rsagtest.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-fips_rsagtest.o: ../../include/openssl/fips.h ../../include/openssl/hmac.h
-fips_rsagtest.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-fips_rsagtest.o: ../../include/openssl/objects.h
-fips_rsagtest.o: ../../include/openssl/opensslconf.h
-fips_rsagtest.o: ../../include/openssl/opensslv.h
-fips_rsagtest.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-fips_rsagtest.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
-fips_rsagtest.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-fips_rsagtest.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-fips_rsagtest.o: ../../include/openssl/x509_vfy.h
-fips_rsagtest.o: ../../include/openssl/x509v3.h ../fips_utl.h fips_rsagtest.c
-fips_rsastest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-fips_rsastest.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
-fips_rsastest.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
-fips_rsastest.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-fips_rsastest.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
-fips_rsastest.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-fips_rsastest.o: ../../include/openssl/fips.h ../../include/openssl/hmac.h
-fips_rsastest.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-fips_rsastest.o: ../../include/openssl/objects.h
-fips_rsastest.o: ../../include/openssl/opensslconf.h
-fips_rsastest.o: ../../include/openssl/opensslv.h
-fips_rsastest.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-fips_rsastest.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
-fips_rsastest.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-fips_rsastest.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-fips_rsastest.o: ../../include/openssl/x509_vfy.h
-fips_rsastest.o: ../../include/openssl/x509v3.h ../fips_utl.h fips_rsastest.c
-fips_rsavtest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-fips_rsavtest.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
-fips_rsavtest.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
-fips_rsavtest.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-fips_rsavtest.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
-fips_rsavtest.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-fips_rsavtest.o: ../../include/openssl/fips.h ../../include/openssl/hmac.h
-fips_rsavtest.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-fips_rsavtest.o: ../../include/openssl/objects.h
-fips_rsavtest.o: ../../include/openssl/opensslconf.h
-fips_rsavtest.o: ../../include/openssl/opensslv.h
-fips_rsavtest.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-fips_rsavtest.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
-fips_rsavtest.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-fips_rsavtest.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-fips_rsavtest.o: ../../include/openssl/x509_vfy.h
-fips_rsavtest.o: ../../include/openssl/x509v3.h ../fips_utl.h fips_rsavtest.c
diff --git a/deps/openssl/openssl/fips/rsa/fips_rsa_eay.c b/deps/openssl/openssl/fips/rsa/fips_rsa_eay.c
deleted file mode 100644 (file)
index 937a14e..0000000
+++ /dev/null
@@ -1,934 +0,0 @@
-/* crypto/rsa/rsa_eay.c */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-/* ====================================================================
- * Copyright (c) 1998-2006 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    openssl-core@openssl.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
- * ====================================================================
- *
- * This product includes cryptographic software written by Eric Young
- * (eay@cryptsoft.com).  This product includes software written by Tim
- * Hudson (tjh@cryptsoft.com).
- *
- */
-
-#include <stdio.h>
-#include <openssl/bn.h>
-#include <openssl/rsa.h>
-#include <openssl/rand.h>
-#include <openssl/err.h>
-#include <openssl/fips.h>
-
-#if !defined(RSA_NULL) && defined(OPENSSL_FIPS)
-
-static int RSA_eay_public_encrypt(int flen, const unsigned char *from,
-               unsigned char *to, RSA *rsa,int padding);
-static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
-               unsigned char *to, RSA *rsa,int padding);
-static int RSA_eay_public_decrypt(int flen, const unsigned char *from,
-               unsigned char *to, RSA *rsa,int padding);
-static int RSA_eay_private_decrypt(int flen, const unsigned char *from,
-               unsigned char *to, RSA *rsa,int padding);
-static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *i, RSA *rsa, BN_CTX *ctx);
-static int RSA_eay_init(RSA *rsa);
-static int RSA_eay_finish(RSA *rsa);
-static RSA_METHOD rsa_pkcs1_eay_meth={
-       "Eric Young's PKCS#1 RSA",
-       RSA_eay_public_encrypt,
-       RSA_eay_public_decrypt, /* signature verification */
-       RSA_eay_private_encrypt, /* signing */
-       RSA_eay_private_decrypt,
-       RSA_eay_mod_exp,
-       BN_mod_exp_mont, /* XXX probably we should not use Montgomery if  e == 3 */
-       RSA_eay_init,
-       RSA_eay_finish,
-       RSA_FLAG_FIPS_METHOD, /* flags */
-       NULL,
-       0, /* rsa_sign */
-       0, /* rsa_verify */
-       NULL /* rsa_keygen */
-       };
-
-const RSA_METHOD *RSA_PKCS1_SSLeay(void)
-       {
-       return(&rsa_pkcs1_eay_meth);
-       }
-
-/* Usage example;
- *    MONT_HELPER(rsa, bn_ctx, p, rsa->flags & RSA_FLAG_CACHE_PRIVATE, goto err);
- */
-#define MONT_HELPER(rsa, ctx, m, pre_cond, err_instr) \
-       if((pre_cond) && ((rsa)->_method_mod_##m == NULL) && \
-                       !BN_MONT_CTX_set_locked(&((rsa)->_method_mod_##m), \
-                               CRYPTO_LOCK_RSA, \
-                               (rsa)->m, (ctx))) \
-               err_instr
-
-static int RSA_eay_public_encrypt(int flen, const unsigned char *from,
-            unsigned char *to, RSA *rsa, int padding)
-       {
-       BIGNUM *f,*ret;
-       int i,j,k,num=0,r= -1;
-       unsigned char *buf=NULL;
-       BN_CTX *ctx=NULL;
-
-       if(FIPS_selftest_failed())
-               {
-               FIPSerr(FIPS_F_RSA_EAY_PUBLIC_ENCRYPT,FIPS_R_FIPS_SELFTEST_FAILED);
-               goto err;
-               }
-
-       if (FIPS_mode() && (BN_num_bits(rsa->n) < OPENSSL_RSA_FIPS_MIN_MODULUS_BITS))
-               {
-               RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_KEY_SIZE_TOO_SMALL);
-               return -1;
-               }
-
-       if (BN_num_bits(rsa->n) > OPENSSL_RSA_MAX_MODULUS_BITS)
-               {
-               RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_MODULUS_TOO_LARGE);
-               return -1;
-               }
-
-       if (BN_ucmp(rsa->n, rsa->e) <= 0)
-               {
-               RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE);
-               return -1;
-               }
-
-       /* for large moduli, enforce exponent limit */
-       if (BN_num_bits(rsa->n) > OPENSSL_RSA_SMALL_MODULUS_BITS)
-               {
-               if (BN_num_bits(rsa->e) > OPENSSL_RSA_MAX_PUBEXP_BITS)
-                       {
-                       RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE);
-                       return -1;
-                       }
-               }
-       
-       if ((ctx=BN_CTX_new()) == NULL) goto err;
-       BN_CTX_start(ctx);
-       f = BN_CTX_get(ctx);
-       ret = BN_CTX_get(ctx);
-       num=BN_num_bytes(rsa->n);
-       buf = OPENSSL_malloc(num);
-       if (!f || !ret || !buf)
-               {
-               RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,ERR_R_MALLOC_FAILURE);
-               goto err;
-               }
-
-       switch (padding)
-               {
-       case RSA_PKCS1_PADDING:
-               i=RSA_padding_add_PKCS1_type_2(buf,num,from,flen);
-               break;
-#ifndef OPENSSL_NO_SHA
-       case RSA_PKCS1_OAEP_PADDING:
-               i=RSA_padding_add_PKCS1_OAEP(buf,num,from,flen,NULL,0);
-               break;
-#endif
-       case RSA_SSLV23_PADDING:
-               i=RSA_padding_add_SSLv23(buf,num,from,flen);
-               break;
-       case RSA_NO_PADDING:
-               i=RSA_padding_add_none(buf,num,from,flen);
-               break;
-       default:
-               RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,RSA_R_UNKNOWN_PADDING_TYPE);
-               goto err;
-               }
-       if (i <= 0) goto err;
-
-       if (BN_bin2bn(buf,num,f) == NULL) goto err;
-       
-       if (BN_ucmp(f, rsa->n) >= 0)
-               {       
-               /* usually the padding functions would catch this */
-               RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
-               goto err;
-               }
-
-       MONT_HELPER(rsa, ctx, n, rsa->flags & RSA_FLAG_CACHE_PUBLIC, goto err);
-
-       if (!rsa->meth->bn_mod_exp(ret,f,rsa->e,rsa->n,ctx,
-               rsa->_method_mod_n)) goto err;
-
-       /* put in leading 0 bytes if the number is less than the
-        * length of the modulus */
-       j=BN_num_bytes(ret);
-       i=BN_bn2bin(ret,&(to[num-j]));
-       for (k=0; k<(num-i); k++)
-               to[k]=0;
-
-       r=num;
-err:
-       if (ctx != NULL)
-               {
-               BN_CTX_end(ctx);
-               BN_CTX_free(ctx);
-               }
-       if (buf != NULL) 
-               {
-               OPENSSL_cleanse(buf,num);
-               OPENSSL_free(buf);
-               }
-       return(r);
-       }
-
-static BN_BLINDING *rsa_get_blinding(RSA *rsa, int *local, BN_CTX *ctx)
-{
-       BN_BLINDING *ret;
-       int got_write_lock = 0;
-
-       CRYPTO_r_lock(CRYPTO_LOCK_RSA);
-
-       if (rsa->blinding == NULL)
-               {
-               CRYPTO_r_unlock(CRYPTO_LOCK_RSA);
-               CRYPTO_w_lock(CRYPTO_LOCK_RSA);
-               got_write_lock = 1;
-
-               if (rsa->blinding == NULL)
-                       rsa->blinding = RSA_setup_blinding(rsa, ctx);
-               }
-
-       ret = rsa->blinding;
-       if (ret == NULL)
-               goto err;
-
-       if (BN_BLINDING_get_thread_id(ret) == CRYPTO_thread_id())
-               {
-               /* rsa->blinding is ours! */
-
-               *local = 1;
-               }
-       else
-               {
-               /* resort to rsa->mt_blinding instead */
-
-               *local = 0; /* instructs rsa_blinding_convert(), rsa_blinding_invert()
-                            * that the BN_BLINDING is shared, meaning that accesses
-                            * require locks, and that the blinding factor must be
-                            * stored outside the BN_BLINDING
-                            */
-
-               if (rsa->mt_blinding == NULL)
-                       {
-                       if (!got_write_lock)
-                               {
-                               CRYPTO_r_unlock(CRYPTO_LOCK_RSA);
-                               CRYPTO_w_lock(CRYPTO_LOCK_RSA);
-                               got_write_lock = 1;
-                               }
-                       
-                       if (rsa->mt_blinding == NULL)
-                               rsa->mt_blinding = RSA_setup_blinding(rsa, ctx);
-                       }
-               ret = rsa->mt_blinding;
-               }
-
- err:
-       if (got_write_lock)
-               CRYPTO_w_unlock(CRYPTO_LOCK_RSA);
-       else
-               CRYPTO_r_unlock(CRYPTO_LOCK_RSA);
-       return ret;
-}
-
-static int rsa_blinding_convert(BN_BLINDING *b, int local, BIGNUM *f,
-       BIGNUM *r, BN_CTX *ctx)
-{
-       if (local)
-               return BN_BLINDING_convert_ex(f, NULL, b, ctx);
-       else
-               {
-               int ret;
-               CRYPTO_r_lock(CRYPTO_LOCK_RSA_BLINDING);
-               ret = BN_BLINDING_convert_ex(f, r, b, ctx);
-               CRYPTO_r_unlock(CRYPTO_LOCK_RSA_BLINDING);
-               return ret;
-               }
-}
-
-static int rsa_blinding_invert(BN_BLINDING *b, int local, BIGNUM *f,
-       BIGNUM *r, BN_CTX *ctx)
-{
-       if (local)
-               return BN_BLINDING_invert_ex(f, NULL, b, ctx);
-       else
-               {
-               int ret;
-               CRYPTO_w_lock(CRYPTO_LOCK_RSA_BLINDING);
-               ret = BN_BLINDING_invert_ex(f, r, b, ctx);
-               CRYPTO_w_unlock(CRYPTO_LOCK_RSA_BLINDING);
-               return ret;
-               }
-}
-
-/* signing */
-static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
-            unsigned char *to, RSA *rsa, int padding)
-       {
-       BIGNUM *f, *ret, *br, *res;
-       int i,j,k,num=0,r= -1;
-       unsigned char *buf=NULL;
-       BN_CTX *ctx=NULL;
-       int local_blinding = 0;
-       BN_BLINDING *blinding = NULL;
-
-       if(FIPS_selftest_failed())
-               {
-               FIPSerr(FIPS_F_RSA_EAY_PRIVATE_ENCRYPT,FIPS_R_FIPS_SELFTEST_FAILED);
-               goto err;
-               }
-
-       if (FIPS_mode() && (BN_num_bits(rsa->n) < OPENSSL_RSA_FIPS_MIN_MODULUS_BITS))
-               {
-               RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT, RSA_R_KEY_SIZE_TOO_SMALL);
-               return -1;
-               }
-
-       if ((ctx=BN_CTX_new()) == NULL) goto err;
-       BN_CTX_start(ctx);
-       f   = BN_CTX_get(ctx);
-       br  = BN_CTX_get(ctx);
-       ret = BN_CTX_get(ctx);
-       num = BN_num_bytes(rsa->n);
-       buf = OPENSSL_malloc(num);
-       if(!f || !ret || !buf)
-               {
-               RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,ERR_R_MALLOC_FAILURE);
-               goto err;
-               }
-
-       switch (padding)
-               {
-       case RSA_PKCS1_PADDING:
-               i=RSA_padding_add_PKCS1_type_1(buf,num,from,flen);
-               break;
-       case RSA_X931_PADDING:
-               i=RSA_padding_add_X931(buf,num,from,flen);
-               break;
-       case RSA_NO_PADDING:
-               i=RSA_padding_add_none(buf,num,from,flen);
-               break;
-       case RSA_SSLV23_PADDING:
-       default:
-               RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,RSA_R_UNKNOWN_PADDING_TYPE);
-               goto err;
-               }
-       if (i <= 0) goto err;
-
-       if (BN_bin2bn(buf,num,f) == NULL) goto err;
-       
-       if (BN_ucmp(f, rsa->n) >= 0)
-               {       
-               /* usually the padding functions would catch this */
-               RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
-               goto err;
-               }
-
-       if (!(rsa->flags & RSA_FLAG_NO_BLINDING))
-               {
-               blinding = rsa_get_blinding(rsa, &local_blinding, ctx);
-               if (blinding == NULL)
-                       {
-                       RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT, ERR_R_INTERNAL_ERROR);
-                       goto err;
-                       }
-               }
-       
-       if (blinding != NULL)
-               if (!rsa_blinding_convert(blinding, local_blinding, f, br, ctx))
-                       goto err;
-
-       if ( (rsa->flags & RSA_FLAG_EXT_PKEY) ||
-               ((rsa->p != NULL) &&
-               (rsa->q != NULL) &&
-               (rsa->dmp1 != NULL) &&
-               (rsa->dmq1 != NULL) &&
-               (rsa->iqmp != NULL)) )
-               { 
-               if (!rsa->meth->rsa_mod_exp(ret, f, rsa, ctx)) goto err;
-               }
-       else
-               {
-               BIGNUM local_d;
-               BIGNUM *d = NULL;
-               
-               if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))
-                       {
-                       BN_init(&local_d);
-                       d = &local_d;
-                       BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);
-                       }
-               else
-                       d = rsa->d;
-
-               MONT_HELPER(rsa, ctx, n, rsa->flags & RSA_FLAG_CACHE_PUBLIC, goto err);
-
-               if (!rsa->meth->bn_mod_exp(ret,f,d,rsa->n,ctx,
-                               rsa->_method_mod_n)) goto err;
-               }
-
-       if (blinding)
-               if (!rsa_blinding_invert(blinding, local_blinding, ret, br, ctx))
-                       goto err;
-
-       if (padding == RSA_X931_PADDING)
-               {
-               BN_sub(f, rsa->n, ret);
-               if (BN_cmp(ret, f))
-                       res = f;
-               else
-                       res = ret;
-               }
-       else
-               res = ret;
-
-       /* put in leading 0 bytes if the number is less than the
-        * length of the modulus */
-       j=BN_num_bytes(res);
-       i=BN_bn2bin(res,&(to[num-j]));
-       for (k=0; k<(num-i); k++)
-               to[k]=0;
-
-       r=num;
-err:
-       if (ctx != NULL)
-               {
-               BN_CTX_end(ctx);
-               BN_CTX_free(ctx);
-               }
-       if (buf != NULL)
-               {
-               OPENSSL_cleanse(buf,num);
-               OPENSSL_free(buf);
-               }
-       return(r);
-       }
-
-static int RSA_eay_private_decrypt(int flen, const unsigned char *from,
-            unsigned char *to, RSA *rsa, int padding)
-       {
-       BIGNUM *f, *ret, *br;
-       int j,num=0,r= -1;
-       unsigned char *p;
-       unsigned char *buf=NULL;
-       BN_CTX *ctx=NULL;
-       int local_blinding = 0;
-       BN_BLINDING *blinding = NULL;
-
-       if(FIPS_selftest_failed())
-               {
-               FIPSerr(FIPS_F_RSA_EAY_PRIVATE_DECRYPT,FIPS_R_FIPS_SELFTEST_FAILED);
-               goto err;
-               }
-
-       if (FIPS_mode() && (BN_num_bits(rsa->n) < OPENSSL_RSA_FIPS_MIN_MODULUS_BITS))
-               {
-               RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, RSA_R_KEY_SIZE_TOO_SMALL);
-               return -1;
-               }
-
-       if((ctx = BN_CTX_new()) == NULL) goto err;
-       BN_CTX_start(ctx);
-       f   = BN_CTX_get(ctx);
-       br  = BN_CTX_get(ctx);
-       ret = BN_CTX_get(ctx);
-       num = BN_num_bytes(rsa->n);
-       buf = OPENSSL_malloc(num);
-       if(!f || !ret || !buf)
-               {
-               RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,ERR_R_MALLOC_FAILURE);
-               goto err;
-               }
-
-       /* This check was for equality but PGP does evil things
-        * and chops off the top '0' bytes */
-       if (flen > num)
-               {
-               RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN);
-               goto err;
-               }
-
-       /* make data into a big number */
-       if (BN_bin2bn(from,(int)flen,f) == NULL) goto err;
-
-       if (BN_ucmp(f, rsa->n) >= 0)
-               {
-               RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
-               goto err;
-               }
-
-       if (!(rsa->flags & RSA_FLAG_NO_BLINDING))
-               {
-               blinding = rsa_get_blinding(rsa, &local_blinding, ctx);
-               if (blinding == NULL)
-                       {
-                       RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, ERR_R_INTERNAL_ERROR);
-                       goto err;
-                       }
-               }
-       
-       if (blinding != NULL)
-               if (!rsa_blinding_convert(blinding, local_blinding, f, br, ctx))
-                       goto err;
-
-       /* do the decrypt */
-       if ( (rsa->flags & RSA_FLAG_EXT_PKEY) ||
-               ((rsa->p != NULL) &&
-               (rsa->q != NULL) &&
-               (rsa->dmp1 != NULL) &&
-               (rsa->dmq1 != NULL) &&
-               (rsa->iqmp != NULL)) )
-               {
-               if (!rsa->meth->rsa_mod_exp(ret, f, rsa, ctx)) goto err;
-               }
-       else
-               {
-               BIGNUM local_d;
-               BIGNUM *d = NULL;
-               
-               if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))
-                       {
-                       d = &local_d;
-                       BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);
-                       }
-               else
-                       d = rsa->d;
-
-               MONT_HELPER(rsa, ctx, n, rsa->flags & RSA_FLAG_CACHE_PUBLIC, goto err);
-               if (!rsa->meth->bn_mod_exp(ret,f,d,rsa->n,ctx,
-                               rsa->_method_mod_n))
-                 goto err;
-               }
-
-       if (blinding)
-               if (!rsa_blinding_invert(blinding, local_blinding, ret, br, ctx))
-                       goto err;
-
-       p=buf;
-       j=BN_bn2bin(ret,p); /* j is only used with no-padding mode */
-
-       switch (padding)
-               {
-       case RSA_PKCS1_PADDING:
-               r=RSA_padding_check_PKCS1_type_2(to,num,buf,j,num);
-               break;
-#ifndef OPENSSL_NO_SHA
-        case RSA_PKCS1_OAEP_PADDING:
-               r=RSA_padding_check_PKCS1_OAEP(to,num,buf,j,num,NULL,0);
-                break;
-#endif
-       case RSA_SSLV23_PADDING:
-               r=RSA_padding_check_SSLv23(to,num,buf,j,num);
-               break;
-       case RSA_NO_PADDING:
-               r=RSA_padding_check_none(to,num,buf,j,num);
-               break;
-       default:
-               RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE);
-               goto err;
-               }
-       if (r < 0)
-               RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_PADDING_CHECK_FAILED);
-
-err:
-       if (ctx != NULL)
-               {
-               BN_CTX_end(ctx);
-               BN_CTX_free(ctx);
-               }
-       if (buf != NULL)
-               {
-               OPENSSL_cleanse(buf,num);
-               OPENSSL_free(buf);
-               }
-       return(r);
-       }
-
-/* signature verification */
-static int RSA_eay_public_decrypt(int flen, const unsigned char *from,
-            unsigned char *to, RSA *rsa, int padding)
-       {
-       BIGNUM *f,*ret;
-       int i,num=0,r= -1;
-       unsigned char *p;
-       unsigned char *buf=NULL;
-       BN_CTX *ctx=NULL;
-
-       if(FIPS_selftest_failed())
-               {
-               FIPSerr(FIPS_F_RSA_EAY_PUBLIC_DECRYPT,FIPS_R_FIPS_SELFTEST_FAILED);
-               goto err;
-               }
-
-       if (FIPS_mode() && (BN_num_bits(rsa->n) < OPENSSL_RSA_FIPS_MIN_MODULUS_BITS))
-               {
-               RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_KEY_SIZE_TOO_SMALL);
-               return -1;
-               }
-
-       if (BN_num_bits(rsa->n) > OPENSSL_RSA_MAX_MODULUS_BITS)
-               {
-               RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_MODULUS_TOO_LARGE);
-               return -1;
-               }
-
-       if (BN_ucmp(rsa->n, rsa->e) <= 0)
-               {
-               RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_BAD_E_VALUE);
-               return -1;
-               }
-
-       /* for large moduli, enforce exponent limit */
-       if (BN_num_bits(rsa->n) > OPENSSL_RSA_SMALL_MODULUS_BITS)
-               {
-               if (BN_num_bits(rsa->e) > OPENSSL_RSA_MAX_PUBEXP_BITS)
-                       {
-                       RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_BAD_E_VALUE);
-                       return -1;
-                       }
-               }
-       
-       if((ctx = BN_CTX_new()) == NULL) goto err;
-       BN_CTX_start(ctx);
-       f = BN_CTX_get(ctx);
-       ret = BN_CTX_get(ctx);
-       num=BN_num_bytes(rsa->n);
-       buf = OPENSSL_malloc(num);
-       if(!f || !ret || !buf)
-               {
-               RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,ERR_R_MALLOC_FAILURE);
-               goto err;
-               }
-
-       /* This check was for equality but PGP does evil things
-        * and chops off the top '0' bytes */
-       if (flen > num)
-               {
-               RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN);
-               goto err;
-               }
-
-       if (BN_bin2bn(from,flen,f) == NULL) goto err;
-
-       if (BN_ucmp(f, rsa->n) >= 0)
-               {
-               RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
-               goto err;
-               }
-
-       MONT_HELPER(rsa, ctx, n, rsa->flags & RSA_FLAG_CACHE_PUBLIC, goto err);
-
-       if (!rsa->meth->bn_mod_exp(ret,f,rsa->e,rsa->n,ctx,
-               rsa->_method_mod_n)) goto err;
-
-       if ((padding == RSA_X931_PADDING) && ((ret->d[0] & 0xf) != 12))
-               BN_sub(ret, rsa->n, ret);
-
-       p=buf;
-       i=BN_bn2bin(ret,p);
-
-       switch (padding)
-               {
-       case RSA_PKCS1_PADDING:
-               r=RSA_padding_check_PKCS1_type_1(to,num,buf,i,num);
-               break;
-       case RSA_X931_PADDING:
-               r=RSA_padding_check_X931(to,num,buf,i,num);
-               break;
-       case RSA_NO_PADDING:
-               r=RSA_padding_check_none(to,num,buf,i,num);
-               break;
-       default:
-               RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE);
-               goto err;
-               }
-       if (r < 0)
-               RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_PADDING_CHECK_FAILED);
-
-err:
-       if (ctx != NULL)
-               {
-               BN_CTX_end(ctx);
-               BN_CTX_free(ctx);
-               }
-       if (buf != NULL)
-               {
-               OPENSSL_cleanse(buf,num);
-               OPENSSL_free(buf);
-               }
-       return(r);
-       }
-
-static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
-       {
-       BIGNUM *r1,*m1,*vrfy;
-       BIGNUM local_dmp1,local_dmq1,local_c,local_r1;
-       BIGNUM *dmp1,*dmq1,*c,*pr1;
-       int bn_flags;
-       int ret=0;
-
-       BN_CTX_start(ctx);
-       r1 = BN_CTX_get(ctx);
-       m1 = BN_CTX_get(ctx);
-       vrfy = BN_CTX_get(ctx);
-
-       /* Make sure mod_inverse in montgomerey intialization use correct 
-        * BN_FLG_CONSTTIME flag.
-        */
-       bn_flags = rsa->p->flags;
-       if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))
-               {
-               rsa->p->flags |= BN_FLG_CONSTTIME;
-               }
-       MONT_HELPER(rsa, ctx, p, rsa->flags & RSA_FLAG_CACHE_PRIVATE, goto err);
-       /* We restore bn_flags back */
-       rsa->p->flags = bn_flags;
-
-        /* Make sure mod_inverse in montgomerey intialization use correct
-         * BN_FLG_CONSTTIME flag.
-         */
-       bn_flags = rsa->q->flags;
-       if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))
-               {
-               rsa->q->flags |= BN_FLG_CONSTTIME;
-               }
-       MONT_HELPER(rsa, ctx, q, rsa->flags & RSA_FLAG_CACHE_PRIVATE, goto err);
-       /* We restore bn_flags back */
-       rsa->q->flags = bn_flags;       
-
-       MONT_HELPER(rsa, ctx, n, rsa->flags & RSA_FLAG_CACHE_PUBLIC, goto err);
-
-       /* compute I mod q */
-       if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))
-               {
-               c = &local_c;
-               BN_with_flags(c, I, BN_FLG_CONSTTIME);
-               if (!BN_mod(r1,c,rsa->q,ctx)) goto err;
-               }
-       else
-               {
-               if (!BN_mod(r1,I,rsa->q,ctx)) goto err;
-               }
-
-       /* compute r1^dmq1 mod q */
-       if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))
-               {
-               dmq1 = &local_dmq1;
-               BN_with_flags(dmq1, rsa->dmq1, BN_FLG_CONSTTIME);
-               }
-       else
-               dmq1 = rsa->dmq1;
-       if (!rsa->meth->bn_mod_exp(m1,r1,dmq1,rsa->q,ctx,
-               rsa->_method_mod_q)) goto err;
-
-       /* compute I mod p */
-       if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))
-               {
-               c = &local_c;
-               BN_with_flags(c, I, BN_FLG_CONSTTIME);
-               if (!BN_mod(r1,c,rsa->p,ctx)) goto err;
-               }
-       else
-               {
-               if (!BN_mod(r1,I,rsa->p,ctx)) goto err;
-               }
-
-       /* compute r1^dmp1 mod p */
-       if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))
-               {
-               dmp1 = &local_dmp1;
-               BN_with_flags(dmp1, rsa->dmp1, BN_FLG_CONSTTIME);
-               }
-       else
-               dmp1 = rsa->dmp1;
-       if (!rsa->meth->bn_mod_exp(r0,r1,dmp1,rsa->p,ctx,
-               rsa->_method_mod_p)) goto err;
-
-       if (!BN_sub(r0,r0,m1)) goto err;
-       /* This will help stop the size of r0 increasing, which does
-        * affect the multiply if it optimised for a power of 2 size */
-       if (BN_is_negative(r0))
-               if (!BN_add(r0,r0,rsa->p)) goto err;
-
-       if (!BN_mul(r1,r0,rsa->iqmp,ctx)) goto err;
-
-       /* Turn BN_FLG_CONSTTIME flag on before division operation */
-       if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))
-               {
-               pr1 = &local_r1;
-               BN_with_flags(pr1, r1, BN_FLG_CONSTTIME);
-               }
-       else
-               pr1 = r1;
-       if (!BN_mod(r0,pr1,rsa->p,ctx)) goto err;
-
-       /* If p < q it is occasionally possible for the correction of
-         * adding 'p' if r0 is negative above to leave the result still
-        * negative. This can break the private key operations: the following
-        * second correction should *always* correct this rare occurrence.
-        * This will *never* happen with OpenSSL generated keys because
-         * they ensure p > q [steve]
-         */
-       if (BN_is_negative(r0))
-               if (!BN_add(r0,r0,rsa->p)) goto err;
-       if (!BN_mul(r1,r0,rsa->q,ctx)) goto err;
-       if (!BN_add(r0,r1,m1)) goto err;
-
-       if (rsa->e && rsa->n)
-               {
-               if (!rsa->meth->bn_mod_exp(vrfy,r0,rsa->e,rsa->n,ctx,rsa->_method_mod_n)) goto err;
-               /* If 'I' was greater than (or equal to) rsa->n, the operation
-                * will be equivalent to using 'I mod n'. However, the result of
-                * the verify will *always* be less than 'n' so we don't check
-                * for absolute equality, just congruency. */
-               if (!BN_sub(vrfy, vrfy, I)) goto err;
-               if (!BN_mod(vrfy, vrfy, rsa->n, ctx)) goto err;
-               if (BN_is_negative(vrfy))
-                       if (!BN_add(vrfy, vrfy, rsa->n)) goto err;
-               if (!BN_is_zero(vrfy))
-                       {
-                       /* 'I' and 'vrfy' aren't congruent mod n. Don't leak
-                        * miscalculated CRT output, just do a raw (slower)
-                        * mod_exp and return that instead. */
-
-                       BIGNUM local_d;
-                       BIGNUM *d = NULL;
-               
-                       if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))
-                               {
-                               d = &local_d;
-                               BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);
-                               }
-                       else
-                               d = rsa->d;
-                       if (!rsa->meth->bn_mod_exp(r0,I,d,rsa->n,ctx,
-                                                  rsa->_method_mod_n)) goto err;
-                       }
-               }
-       ret=1;
-err:
-       BN_CTX_end(ctx);
-       return(ret);
-       }
-
-static int RSA_eay_init(RSA *rsa)
-       {
-       FIPS_selftest_check();
-       rsa->flags|=RSA_FLAG_CACHE_PUBLIC|RSA_FLAG_CACHE_PRIVATE;
-       return(1);
-       }
-
-static int RSA_eay_finish(RSA *rsa)
-       {
-       if (rsa->_method_mod_n != NULL)
-               BN_MONT_CTX_free(rsa->_method_mod_n);
-       if (rsa->_method_mod_p != NULL)
-               BN_MONT_CTX_free(rsa->_method_mod_p);
-       if (rsa->_method_mod_q != NULL)
-               BN_MONT_CTX_free(rsa->_method_mod_q);
-       return(1);
-       }
-
-#endif
diff --git a/deps/openssl/openssl/fips/rsa/fips_rsa_gen.c b/deps/openssl/openssl/fips/rsa/fips_rsa_gen.c
deleted file mode 100644 (file)
index 90aaa2f..0000000
+++ /dev/null
@@ -1,310 +0,0 @@
-/* crypto/rsa/rsa_gen.c */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-
-/* NB: these functions have been "upgraded", the deprecated versions (which are
- * compatibility wrappers using these functions) are in rsa_depr.c.
- * - Geoff
- */
-
-#include <stdio.h>
-#include <time.h>
-#include <string.h>
-#include <openssl/crypto.h>
-#include <openssl/bn.h>
-#include <openssl/rsa.h>
-#include <openssl/err.h>
-#include <openssl/evp.h>
-#include <openssl/fips.h>
-#include "fips_locl.h"
-
-#ifdef OPENSSL_FIPS
-
-static int fips_rsa_pairwise_fail = 0;
-
-void FIPS_corrupt_rsa_keygen(void)
-       {
-       fips_rsa_pairwise_fail = 1;
-       }
-
-int fips_check_rsa(RSA *rsa)
-       {
-       const unsigned char tbs[] = "RSA Pairwise Check Data";
-       unsigned char *ctbuf = NULL, *ptbuf = NULL;
-       int len, ret = 0;
-       EVP_PKEY pk;
-       pk.type = EVP_PKEY_RSA;
-       pk.pkey.rsa = rsa;
-
-       /* Perform pairwise consistency signature test */
-       if (!fips_pkey_signature_test(&pk, tbs, -1,
-                       NULL, 0, EVP_sha1(), EVP_MD_CTX_FLAG_PAD_PKCS1, NULL)
-               || !fips_pkey_signature_test(&pk, tbs, -1,
-                       NULL, 0, EVP_sha1(), EVP_MD_CTX_FLAG_PAD_X931, NULL)
-               || !fips_pkey_signature_test(&pk, tbs, -1,
-                       NULL, 0, EVP_sha1(), EVP_MD_CTX_FLAG_PAD_PSS, NULL))
-               goto err;
-       /* Now perform pairwise consistency encrypt/decrypt test */
-       ctbuf = OPENSSL_malloc(RSA_size(rsa));
-       if (!ctbuf)
-               goto err;
-
-       len = RSA_public_encrypt(sizeof(tbs) - 1, tbs, ctbuf, rsa, RSA_PKCS1_PADDING);
-       if (len <= 0)
-               goto err;
-       /* Check ciphertext doesn't match plaintext */
-       if ((len == (sizeof(tbs) - 1)) && !memcmp(tbs, ctbuf, len))
-               goto err;
-       ptbuf = OPENSSL_malloc(RSA_size(rsa));
-
-       if (!ptbuf)
-               goto err;
-       len = RSA_private_decrypt(len, ctbuf, ptbuf, rsa, RSA_PKCS1_PADDING);
-       if (len != (sizeof(tbs) - 1))
-               goto err;
-       if (memcmp(ptbuf, tbs, len))
-               goto err;
-
-       ret = 1;
-
-       if (!ptbuf)
-               goto err;
-       
-       err:
-       if (ret == 0)
-               {
-               fips_set_selftest_fail();
-               FIPSerr(FIPS_F_FIPS_CHECK_RSA,FIPS_R_PAIRWISE_TEST_FAILED);
-               }
-
-       if (ctbuf)
-               OPENSSL_free(ctbuf);
-       if (ptbuf)
-               OPENSSL_free(ptbuf);
-
-       return ret;
-       }
-
-static int rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb);
-
-/* NB: this wrapper would normally be placed in rsa_lib.c and the static
- * implementation would probably be in rsa_eay.c. Nonetheless, is kept here so
- * that we don't introduce a new linker dependency. Eg. any application that
- * wasn't previously linking object code related to key-generation won't have to
- * now just because key-generation is part of RSA_METHOD. */
-int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb)
-       {
-       if(rsa->meth->rsa_keygen)
-               return rsa->meth->rsa_keygen(rsa, bits, e_value, cb);
-       return rsa_builtin_keygen(rsa, bits, e_value, cb);
-       }
-
-static int rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb)
-       {
-       BIGNUM *r0=NULL,*r1=NULL,*r2=NULL,*r3=NULL,*tmp;
-       BIGNUM local_r0,local_d,local_p;
-       BIGNUM *pr0,*d,*p;
-       int bitsp,bitsq,ok= -1,n=0;
-       BN_CTX *ctx=NULL;
-
-       if(FIPS_selftest_failed())
-           {
-           FIPSerr(FIPS_F_RSA_BUILTIN_KEYGEN,FIPS_R_FIPS_SELFTEST_FAILED);
-           return 0;
-           }
-
-       if (FIPS_mode() && (bits < OPENSSL_RSA_FIPS_MIN_MODULUS_BITS))
-           {
-           FIPSerr(FIPS_F_RSA_BUILTIN_KEYGEN,FIPS_R_KEY_TOO_SHORT);
-           return 0;
-           }
-
-       ctx=BN_CTX_new();
-       if (ctx == NULL) goto err;
-       BN_CTX_start(ctx);
-       r0 = BN_CTX_get(ctx);
-       r1 = BN_CTX_get(ctx);
-       r2 = BN_CTX_get(ctx);
-       r3 = BN_CTX_get(ctx);
-       if (r3 == NULL) goto err;
-
-       bitsp=(bits+1)/2;
-       bitsq=bits-bitsp;
-
-       /* We need the RSA components non-NULL */
-       if(!rsa->n && ((rsa->n=BN_new()) == NULL)) goto err;
-       if(!rsa->d && ((rsa->d=BN_new()) == NULL)) goto err;
-       if(!rsa->e && ((rsa->e=BN_new()) == NULL)) goto err;
-       if(!rsa->p && ((rsa->p=BN_new()) == NULL)) goto err;
-       if(!rsa->q && ((rsa->q=BN_new()) == NULL)) goto err;
-       if(!rsa->dmp1 && ((rsa->dmp1=BN_new()) == NULL)) goto err;
-       if(!rsa->dmq1 && ((rsa->dmq1=BN_new()) == NULL)) goto err;
-       if(!rsa->iqmp && ((rsa->iqmp=BN_new()) == NULL)) goto err;
-
-       BN_copy(rsa->e, e_value);
-
-       /* generate p and q */
-       for (;;)
-               {
-               if(!BN_generate_prime_ex(rsa->p, bitsp, 0, NULL, NULL, cb))
-                       goto err;
-               if (!BN_sub(r2,rsa->p,BN_value_one())) goto err;
-               if (!BN_gcd(r1,r2,rsa->e,ctx)) goto err;
-               if (BN_is_one(r1)) break;
-               if(!BN_GENCB_call(cb, 2, n++))
-                       goto err;
-               }
-       if(!BN_GENCB_call(cb, 3, 0))
-               goto err;
-       for (;;)
-               {
-               /* When generating ridiculously small keys, we can get stuck
-                * continually regenerating the same prime values. Check for
-                * this and bail if it happens 3 times. */
-               unsigned int degenerate = 0;
-               do
-                       {
-                       if(!BN_generate_prime_ex(rsa->q, bitsq, 0, NULL, NULL, cb))
-                               goto err;
-                       } while((BN_cmp(rsa->p, rsa->q) == 0) && (++degenerate < 3));
-               if(degenerate == 3)
-                       {
-                       ok = 0; /* we set our own err */
-                       RSAerr(RSA_F_RSA_BUILTIN_KEYGEN,RSA_R_KEY_SIZE_TOO_SMALL);
-                       goto err;
-                       }
-               if (!BN_sub(r2,rsa->q,BN_value_one())) goto err;
-               if (!BN_gcd(r1,r2,rsa->e,ctx)) goto err;
-               if (BN_is_one(r1))
-                       break;
-               if(!BN_GENCB_call(cb, 2, n++))
-                       goto err;
-               }
-       if(!BN_GENCB_call(cb, 3, 1))
-               goto err;
-       if (BN_cmp(rsa->p,rsa->q) < 0)
-               {
-               tmp=rsa->p;
-               rsa->p=rsa->q;
-               rsa->q=tmp;
-               }
-
-       /* calculate n */
-       if (!BN_mul(rsa->n,rsa->p,rsa->q,ctx)) goto err;
-
-       /* calculate d */
-       if (!BN_sub(r1,rsa->p,BN_value_one())) goto err;        /* p-1 */
-       if (!BN_sub(r2,rsa->q,BN_value_one())) goto err;        /* q-1 */
-       if (!BN_mul(r0,r1,r2,ctx)) goto err;    /* (p-1)(q-1) */
-       if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))
-               {
-                 pr0 = &local_r0;
-                 BN_with_flags(pr0, r0, BN_FLG_CONSTTIME);
-               }
-       else
-         pr0 = r0;
-       if (!BN_mod_inverse(rsa->d,rsa->e,pr0,ctx)) goto err;   /* d */
-
-       /* set up d for correct BN_FLG_CONSTTIME flag */
-       if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))
-               {
-               d = &local_d;
-               BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);
-               }
-       else
-               d = rsa->d;
-
-       /* calculate d mod (p-1) */
-       if (!BN_mod(rsa->dmp1,d,r1,ctx)) goto err;
-
-       /* calculate d mod (q-1) */
-       if (!BN_mod(rsa->dmq1,d,r2,ctx)) goto err;
-
-       /* calculate inverse of q mod p */
-       if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))
-               {
-               p = &local_p;
-               BN_with_flags(p, rsa->p, BN_FLG_CONSTTIME);
-               }
-       else
-               p = rsa->p;
-       if (!BN_mod_inverse(rsa->iqmp,rsa->q,p,ctx)) goto err;
-
-       if (fips_rsa_pairwise_fail)
-               BN_add_word(rsa->n, 1);
-
-       if(!fips_check_rsa(rsa))
-           goto err;
-
-       ok=1;
-err:
-       if (ok == -1)
-               {
-               RSAerr(RSA_F_RSA_BUILTIN_KEYGEN,ERR_LIB_BN);
-               ok=0;
-               }
-       if (ctx != NULL)
-               {
-               BN_CTX_end(ctx);
-               BN_CTX_free(ctx);
-               }
-
-       return ok;
-       }
-
-#endif
diff --git a/deps/openssl/openssl/fips/rsa/fips_rsa_selftest.c b/deps/openssl/openssl/fips/rsa/fips_rsa_selftest.c
deleted file mode 100644 (file)
index bead61f..0000000
+++ /dev/null
@@ -1,432 +0,0 @@
-/* ====================================================================
- * Copyright (c) 2003-2007 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    openssl-core@openssl.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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 <string.h>
-#include <openssl/err.h>
-#include <openssl/fips.h>
-#include <openssl/rsa.h>
-#include <openssl/evp.h>
-#include <openssl/bn.h>
-#include <openssl/opensslconf.h>
-
-#ifdef OPENSSL_FIPS
-
-static unsigned char n[] =
-"\x00\xBB\xF8\x2F\x09\x06\x82\xCE\x9C\x23\x38\xAC\x2B\x9D\xA8\x71"
-"\xF7\x36\x8D\x07\xEE\xD4\x10\x43\xA4\x40\xD6\xB6\xF0\x74\x54\xF5"
-"\x1F\xB8\xDF\xBA\xAF\x03\x5C\x02\xAB\x61\xEA\x48\xCE\xEB\x6F\xCD"
-"\x48\x76\xED\x52\x0D\x60\xE1\xEC\x46\x19\x71\x9D\x8A\x5B\x8B\x80"
-"\x7F\xAF\xB8\xE0\xA3\xDF\xC7\x37\x72\x3E\xE6\xB4\xB7\xD9\x3A\x25"
-"\x84\xEE\x6A\x64\x9D\x06\x09\x53\x74\x88\x34\xB2\x45\x45\x98\x39"
-"\x4E\xE0\xAA\xB1\x2D\x7B\x61\xA5\x1F\x52\x7A\x9A\x41\xF6\xC1\x68"
-"\x7F\xE2\x53\x72\x98\xCA\x2A\x8F\x59\x46\xF8\xE5\xFD\x09\x1D\xBD"
-"\xCB";
-
-
-static int setrsakey(RSA *key)
-    {
-    static const unsigned char e[] = "\x11";
-
-    static const unsigned char d[] =
-"\x00\xA5\xDA\xFC\x53\x41\xFA\xF2\x89\xC4\xB9\x88\xDB\x30\xC1\xCD"
-"\xF8\x3F\x31\x25\x1E\x06\x68\xB4\x27\x84\x81\x38\x01\x57\x96\x41"
-"\xB2\x94\x10\xB3\xC7\x99\x8D\x6B\xC4\x65\x74\x5E\x5C\x39\x26\x69"
-"\xD6\x87\x0D\xA2\xC0\x82\xA9\x39\xE3\x7F\xDC\xB8\x2E\xC9\x3E\xDA"
-"\xC9\x7F\xF3\xAD\x59\x50\xAC\xCF\xBC\x11\x1C\x76\xF1\xA9\x52\x94"
-"\x44\xE5\x6A\xAF\x68\xC5\x6C\x09\x2C\xD3\x8D\xC3\xBE\xF5\xD2\x0A"
-"\x93\x99\x26\xED\x4F\x74\xA1\x3E\xDD\xFB\xE1\xA1\xCE\xCC\x48\x94"
-"\xAF\x94\x28\xC2\xB7\xB8\x88\x3F\xE4\x46\x3A\x4B\xC8\x5B\x1C\xB3"
-"\xC1";
-
-    static const unsigned char p[] =
-"\x00\xEE\xCF\xAE\x81\xB1\xB9\xB3\xC9\x08\x81\x0B\x10\xA1\xB5\x60"
-"\x01\x99\xEB\x9F\x44\xAE\xF4\xFD\xA4\x93\xB8\x1A\x9E\x3D\x84\xF6"
-"\x32\x12\x4E\xF0\x23\x6E\x5D\x1E\x3B\x7E\x28\xFA\xE7\xAA\x04\x0A"
-"\x2D\x5B\x25\x21\x76\x45\x9D\x1F\x39\x75\x41\xBA\x2A\x58\xFB\x65"
-"\x99";
-
-    static const unsigned char q[] =
-"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
-"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D"
-"\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5"
-"\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x15"
-"\x03";
-
-    static const unsigned char dmp1[] =
-"\x54\x49\x4C\xA6\x3E\xBA\x03\x37\xE4\xE2\x40\x23\xFC\xD6\x9A\x5A"
-"\xEB\x07\xDD\xDC\x01\x83\xA4\xD0\xAC\x9B\x54\xB0\x51\xF2\xB1\x3E"
-"\xD9\x49\x09\x75\xEA\xB7\x74\x14\xFF\x59\xC1\xF7\x69\x2E\x9A\x2E"
-"\x20\x2B\x38\xFC\x91\x0A\x47\x41\x74\xAD\xC9\x3C\x1F\x67\xC9\x81";
-
-    static const unsigned char dmq1[] =
-"\x47\x1E\x02\x90\xFF\x0A\xF0\x75\x03\x51\xB7\xF8\x78\x86\x4C\xA9"
-"\x61\xAD\xBD\x3A\x8A\x7E\x99\x1C\x5C\x05\x56\xA9\x4C\x31\x46\xA7"
-"\xF9\x80\x3F\x8F\x6F\x8A\xE3\x42\xE9\x31\xFD\x8A\xE4\x7A\x22\x0D"
-"\x1B\x99\xA4\x95\x84\x98\x07\xFE\x39\xF9\x24\x5A\x98\x36\xDA\x3D";
-    
-    static const unsigned char iqmp[] =
-"\x00\xB0\x6C\x4F\xDA\xBB\x63\x01\x19\x8D\x26\x5B\xDB\xAE\x94\x23"
-"\xB3\x80\xF2\x71\xF7\x34\x53\x88\x50\x93\x07\x7F\xCD\x39\xE2\x11"
-"\x9F\xC9\x86\x32\x15\x4F\x58\x83\xB1\x67\xA9\x67\xBF\x40\x2B\x4E"
-"\x9E\x2E\x0F\x96\x56\xE6\x98\xEA\x36\x66\xED\xFB\x25\x79\x80\x39"
-"\xF7";
-
-    key->n = BN_bin2bn(n, sizeof(n)-1, key->n);
-    key->e = BN_bin2bn(e, sizeof(e)-1, key->e);
-    key->d = BN_bin2bn(d, sizeof(d)-1, key->d);
-    key->p = BN_bin2bn(p, sizeof(p)-1, key->p);
-    key->q = BN_bin2bn(q, sizeof(q)-1, key->q);
-    key->dmp1 = BN_bin2bn(dmp1, sizeof(dmp1)-1, key->dmp1);
-    key->dmq1 = BN_bin2bn(dmq1, sizeof(dmq1)-1, key->dmq1);
-    key->iqmp = BN_bin2bn(iqmp, sizeof(iqmp)-1, key->iqmp);
-    return 1;
-    }
-
-void FIPS_corrupt_rsa()
-    {
-    n[0]++;
-    }
-
-/* Known Answer Test (KAT) data for the above RSA private key signing
- * kat_tbs.
- */
-
-static const unsigned char kat_tbs[] = "OpenSSL FIPS 140-2 Public Key RSA KAT";
-
-static const unsigned char kat_RSA_PSS_SHA1[] = {
-  0x2D, 0xAF, 0x6E, 0xC2, 0x98, 0xFB, 0x8A, 0xA1, 0xB9, 0x46, 0xDA, 0x0F,
-  0x01, 0x1E, 0x37, 0x93, 0xC2, 0x55, 0x27, 0xE4, 0x1D, 0xD2, 0x90, 0xBB,
-  0xF4, 0xBF, 0x4A, 0x74, 0x39, 0x51, 0xBB, 0xE8, 0x0C, 0xB7, 0xF8, 0xD3,
-  0xD1, 0xDF, 0xE7, 0xBE, 0x80, 0x05, 0xC3, 0xB5, 0xC7, 0x83, 0xD5, 0x4C,
-  0x7F, 0x49, 0xFB, 0x3F, 0x29, 0x9B, 0xE1, 0x12, 0x51, 0x60, 0xD0, 0xA7,
-  0x0D, 0xA9, 0x28, 0x56, 0x73, 0xD9, 0x07, 0xE3, 0x5E, 0x3F, 0x9B, 0xF5,
-  0xB6, 0xF3, 0xF2, 0x5E, 0x74, 0xC9, 0x83, 0x81, 0x47, 0xF0, 0xC5, 0x45,
-  0x0A, 0xE9, 0x8E, 0x38, 0xD7, 0x18, 0xC6, 0x2A, 0x0F, 0xF8, 0xB7, 0x31,
-  0xD6, 0x55, 0xE4, 0x66, 0x78, 0x81, 0xD4, 0xE6, 0xDB, 0x9F, 0xBA, 0xE8,
-  0x23, 0xB5, 0x7F, 0xDC, 0x08, 0xEA, 0xD5, 0x26, 0x1E, 0x20, 0x25, 0x84,
-  0x26, 0xC6, 0x79, 0xC9, 0x9B, 0x3D, 0x7E, 0xA9
-};
-
-static const unsigned char kat_RSA_PSS_SHA224[] = {
-  0x39, 0x4A, 0x6A, 0x20, 0xBC, 0xE9, 0x33, 0xED, 0xEF, 0xC5, 0x58, 0xA7,
-  0xFE, 0x81, 0xC4, 0x36, 0x50, 0x9A, 0x2C, 0x82, 0x98, 0x08, 0x95, 0xFA,
-  0xB1, 0x9E, 0xD2, 0x55, 0x61, 0x87, 0x21, 0x59, 0x87, 0x7B, 0x1F, 0x57,
-  0x30, 0x9D, 0x0D, 0x4A, 0x06, 0xEB, 0x52, 0x37, 0x55, 0x54, 0x1C, 0x89,
-  0x83, 0x75, 0x59, 0x65, 0x64, 0x90, 0x2E, 0x16, 0xCC, 0x86, 0x05, 0xEE,
-  0xB1, 0xE6, 0x7B, 0xBA, 0x16, 0x75, 0x0D, 0x0C, 0x64, 0x0B, 0xAB, 0x22,
-  0x15, 0x78, 0x6B, 0x6F, 0xA4, 0xFB, 0x77, 0x40, 0x64, 0x62, 0xD1, 0xB5,
-  0x37, 0x1E, 0xE0, 0x3D, 0xA8, 0xF9, 0xD2, 0xBD, 0xAA, 0x38, 0x24, 0x49,
-  0x58, 0xD2, 0x74, 0x85, 0xF4, 0xB5, 0x93, 0x8E, 0xF5, 0x03, 0xEA, 0x2D,
-  0xC8, 0x52, 0xFA, 0xCF, 0x7E, 0x35, 0xB0, 0x6A, 0xAF, 0x95, 0xC0, 0x00,
-  0x54, 0x76, 0x3D, 0x0C, 0x9C, 0xB2, 0xEE, 0xC0
-};
-
-static const unsigned char kat_RSA_PSS_SHA256[] = {
-  0x6D, 0x3D, 0xBE, 0x8F, 0x60, 0x6D, 0x25, 0x14, 0xF0, 0x31, 0xE3, 0x89,
-  0x00, 0x97, 0xFA, 0x99, 0x71, 0x28, 0xE5, 0x10, 0x25, 0x9A, 0xF3, 0x8F,
-  0x7B, 0xC5, 0xA8, 0x4A, 0x74, 0x51, 0x36, 0xE2, 0x8D, 0x7D, 0x73, 0x28,
-  0xC1, 0x77, 0xC6, 0x27, 0x97, 0x00, 0x8B, 0x00, 0xA3, 0x96, 0x73, 0x4E,
-  0x7D, 0x2E, 0x2C, 0x34, 0x68, 0x8C, 0x8E, 0xDF, 0x9D, 0x49, 0x47, 0x05,
-  0xAB, 0xF5, 0x01, 0xD6, 0x81, 0x47, 0x70, 0xF5, 0x1D, 0x6D, 0x26, 0xBA,
-  0x2F, 0x7A, 0x54, 0x53, 0x4E, 0xED, 0x71, 0xD9, 0x5A, 0xF3, 0xDA, 0xB6,
-  0x0B, 0x47, 0x34, 0xAF, 0x90, 0xDC, 0xC8, 0xD9, 0x6F, 0x56, 0xCD, 0x9F,
-  0x21, 0xB7, 0x7E, 0xAD, 0x7C, 0x2F, 0x75, 0x50, 0x47, 0x12, 0xE4, 0x6D,
-  0x5F, 0xB7, 0x01, 0xDF, 0xC3, 0x11, 0x6C, 0xA9, 0x9E, 0x49, 0xB9, 0xF6,
-  0x72, 0xF4, 0xF6, 0xEF, 0x88, 0x1E, 0x2D, 0x1C
-};
-
-static const unsigned char kat_RSA_PSS_SHA384[] = {
-  0x40, 0xFB, 0xA1, 0x21, 0xF4, 0xB2, 0x40, 0x9A, 0xB4, 0x31, 0xA8, 0xF2,
-  0xEC, 0x1C, 0xC4, 0xC8, 0x7C, 0x22, 0x65, 0x9C, 0x57, 0x45, 0xCD, 0x5E,
-  0x86, 0x00, 0xF7, 0x25, 0x78, 0xDE, 0xDC, 0x7A, 0x71, 0x44, 0x9A, 0xCD,
-  0xAA, 0x25, 0xF4, 0xB2, 0xFC, 0xF0, 0x75, 0xD9, 0x2F, 0x78, 0x23, 0x7F,
-  0x6F, 0x02, 0xEF, 0xC1, 0xAF, 0xA6, 0x28, 0x16, 0x31, 0xDC, 0x42, 0x6C,
-  0xB2, 0x44, 0xE5, 0x4D, 0x66, 0xA2, 0xE6, 0x71, 0xF3, 0xAC, 0x4F, 0xFB,
-  0x91, 0xCA, 0xF5, 0x70, 0xEF, 0x6B, 0x9D, 0xA4, 0xEF, 0xD9, 0x3D, 0x2F,
-  0x3A, 0xBE, 0x89, 0x38, 0x59, 0x01, 0xBA, 0xDA, 0x32, 0xAD, 0x42, 0x89,
-  0x98, 0x8B, 0x39, 0x44, 0xF0, 0xFC, 0x38, 0xAC, 0x87, 0x1F, 0xCA, 0x6F,
-  0x48, 0xF6, 0xAE, 0xD7, 0x45, 0xEE, 0xAE, 0x88, 0x0E, 0x60, 0xF4, 0x55,
-  0x48, 0x44, 0xEE, 0x1F, 0x90, 0x18, 0x4B, 0xF1
-};
-
-static const unsigned char kat_RSA_PSS_SHA512[] = {
-  0x07, 0x1E, 0xD8, 0xD5, 0x05, 0xE8, 0xE6, 0xE6, 0x57, 0xAE, 0x63, 0x8C,
-  0xC6, 0x83, 0xB7, 0xA0, 0x59, 0xBB, 0xF2, 0xC6, 0x8F, 0x12, 0x53, 0x9A,
-  0x9B, 0x54, 0x9E, 0xB3, 0xC1, 0x1D, 0x23, 0x4D, 0x51, 0xED, 0x9E, 0xDD,
-  0x4B, 0xF3, 0x46, 0x9B, 0x6B, 0xF6, 0x7C, 0x24, 0x60, 0x79, 0x23, 0x39,
-  0x01, 0x1C, 0x51, 0xCB, 0xD8, 0xE9, 0x9A, 0x01, 0x67, 0x5F, 0xFE, 0xD7,
-  0x7C, 0xE3, 0x7F, 0xED, 0xDB, 0x87, 0xBB, 0xF0, 0x3D, 0x78, 0x55, 0x61,
-  0x57, 0xE3, 0x0F, 0xE3, 0xD2, 0x9D, 0x0C, 0x2A, 0x20, 0xB0, 0x85, 0x13,
-  0xC5, 0x47, 0x34, 0x0D, 0x32, 0x15, 0xC8, 0xAE, 0x9A, 0x6A, 0x39, 0x63,
-  0x2D, 0x60, 0xF5, 0x4C, 0xDF, 0x8A, 0x48, 0x4B, 0xBF, 0xF4, 0xA8, 0xFE,
-  0x76, 0xF2, 0x32, 0x1B, 0x9C, 0x7C, 0xCA, 0xFE, 0x7F, 0x80, 0xC2, 0x88,
-  0x5C, 0x97, 0x70, 0xB4, 0x26, 0xC9, 0x14, 0x8B
-};
-
-static const unsigned char kat_RSA_SHA1[] = {
-  0x71, 0xEE, 0x1A, 0xC0, 0xFE, 0x01, 0x93, 0x54, 0x79, 0x5C, 0xF2, 0x4C,
-  0x4A, 0xFD, 0x1A, 0x05, 0x8F, 0x64, 0xB1, 0x6D, 0x61, 0x33, 0x8D, 0x9B,
-  0xE7, 0xFD, 0x60, 0xA3, 0x83, 0xB5, 0xA3, 0x51, 0x55, 0x77, 0x90, 0xCF,
-  0xDC, 0x22, 0x37, 0x8E, 0xD0, 0xE1, 0xAE, 0x09, 0xE3, 0x3D, 0x1E, 0xF8,
-  0x80, 0xD1, 0x8B, 0xC2, 0xEC, 0x0A, 0xD7, 0x6B, 0x88, 0x8B, 0x8B, 0xA1,
-  0x20, 0x22, 0xBE, 0x59, 0x5B, 0xE0, 0x23, 0x24, 0xA1, 0x49, 0x30, 0xBA,
-  0xA9, 0x9E, 0xE8, 0xB1, 0x8A, 0x62, 0x16, 0xBF, 0x4E, 0xCA, 0x2E, 0x4E,
-  0xBC, 0x29, 0xA8, 0x67, 0x13, 0xB7, 0x9F, 0x1D, 0x04, 0x44, 0xE5, 0x5F,
-  0x35, 0x07, 0x11, 0xBC, 0xED, 0x19, 0x37, 0x21, 0xCF, 0x23, 0x48, 0x1F,
-  0x72, 0x05, 0xDE, 0xE6, 0xE8, 0x7F, 0x33, 0x8A, 0x76, 0x4B, 0x2F, 0x95,
-  0xDF, 0xF1, 0x5F, 0x84, 0x80, 0xD9, 0x46, 0xB4
-};
-
-static const unsigned char kat_RSA_SHA224[] = {
-  0x62, 0xAA, 0x79, 0xA9, 0x18, 0x0E, 0x5F, 0x8C, 0xBB, 0xB7, 0x15, 0xF9,
-  0x25, 0xBB, 0xFA, 0xD4, 0x3A, 0x34, 0xED, 0x9E, 0xA0, 0xA9, 0x18, 0x8D,
-  0x5B, 0x55, 0x9A, 0x7E, 0x1E, 0x08, 0x08, 0x60, 0xC5, 0x1A, 0xC5, 0x89,
-  0x08, 0xE2, 0x1B, 0xBD, 0x62, 0x50, 0x17, 0x76, 0x30, 0x2C, 0x9E, 0xCD,
-  0xA4, 0x02, 0xAD, 0xB1, 0x6D, 0x44, 0x6D, 0xD5, 0xC6, 0x45, 0x41, 0xE5,
-  0xEE, 0x1F, 0x8D, 0x7E, 0x08, 0x16, 0xA6, 0xE1, 0x5E, 0x0B, 0xA9, 0xCC,
-  0xDB, 0x59, 0x55, 0x87, 0x09, 0x25, 0x70, 0x86, 0x84, 0x02, 0xC6, 0x3B,
-  0x0B, 0x44, 0x4C, 0x46, 0x95, 0xF4, 0xF8, 0x5A, 0x91, 0x28, 0x3E, 0xB2,
-  0x58, 0x2E, 0x06, 0x45, 0x49, 0xE0, 0x92, 0xE2, 0xC0, 0x66, 0xE6, 0x35,
-  0xD9, 0x79, 0x7F, 0x17, 0x5E, 0x02, 0x73, 0x04, 0x77, 0x82, 0xE6, 0xDC,
-  0x40, 0x21, 0x89, 0x8B, 0x37, 0x3E, 0x1E, 0x8D
-};
-
-static const unsigned char kat_RSA_SHA256[] = {
-  0x0D, 0x55, 0xE2, 0xAA, 0x81, 0xDB, 0x8E, 0x82, 0x05, 0x17, 0xA5, 0x23,
-  0xE7, 0x3B, 0x1D, 0xAF, 0xFB, 0x8C, 0xD0, 0x81, 0x20, 0x7B, 0xAA, 0x23,
-  0x92, 0x87, 0x8C, 0xD1, 0x53, 0x85, 0x16, 0xDC, 0xBE, 0xAD, 0x6F, 0x35,
-  0x98, 0x2D, 0x69, 0x84, 0xBF, 0xD9, 0x8A, 0x01, 0x17, 0x58, 0xB2, 0x6E,
-  0x2C, 0x44, 0x9B, 0x90, 0xF1, 0xFB, 0x51, 0xE8, 0x6A, 0x90, 0x2D, 0x18,
-  0x0E, 0xC0, 0x90, 0x10, 0x24, 0xA9, 0x1D, 0xB3, 0x58, 0x7A, 0x91, 0x30,
-  0xBE, 0x22, 0xC7, 0xD3, 0xEC, 0xC3, 0x09, 0x5D, 0xBF, 0xE2, 0x80, 0x3A,
-  0x7C, 0x85, 0xB4, 0xBC, 0xD1, 0xE9, 0xF0, 0x5C, 0xDE, 0x81, 0xA6, 0x38,
-  0xB8, 0x42, 0xBB, 0x86, 0xC5, 0x9D, 0xCE, 0x7C, 0x2C, 0xEE, 0xD1, 0xDA,
-  0x27, 0x48, 0x2B, 0xF5, 0xAB, 0xB9, 0xF7, 0x80, 0xD1, 0x90, 0x27, 0x90,
-  0xBD, 0x44, 0x97, 0x60, 0xCD, 0x57, 0xC0, 0x7A
-};
-
-static const unsigned char kat_RSA_SHA384[] = {
-  0x1D, 0xE3, 0x6A, 0xDD, 0x27, 0x4C, 0xC0, 0xA5, 0x27, 0xEF, 0xE6, 0x1F,
-  0xD2, 0x91, 0x68, 0x59, 0x04, 0xAE, 0xBD, 0x99, 0x63, 0x56, 0x47, 0xC7,
-  0x6F, 0x22, 0x16, 0x48, 0xD0, 0xF9, 0x18, 0xA9, 0xCA, 0xFA, 0x5D, 0x5C,
-  0xA7, 0x65, 0x52, 0x8A, 0xC8, 0x44, 0x7E, 0x86, 0x5D, 0xA9, 0xA6, 0x55,
-  0x65, 0x3E, 0xD9, 0x2D, 0x02, 0x38, 0xA8, 0x79, 0x28, 0x7F, 0xB6, 0xCF,
-  0x82, 0xDD, 0x7E, 0x55, 0xE1, 0xB1, 0xBC, 0xE2, 0x19, 0x2B, 0x30, 0xC2,
-  0x1B, 0x2B, 0xB0, 0x82, 0x46, 0xAC, 0x4B, 0xD1, 0xE2, 0x7D, 0xEB, 0x8C,
-  0xFF, 0x95, 0xE9, 0x6A, 0x1C, 0x3D, 0x4D, 0xBF, 0x8F, 0x8B, 0x9C, 0xCD,
-  0xEA, 0x85, 0xEE, 0x00, 0xDC, 0x1C, 0xA7, 0xEB, 0xD0, 0x8F, 0x99, 0xF1,
-  0x16, 0x28, 0x24, 0x64, 0x04, 0x39, 0x2D, 0x58, 0x1E, 0x37, 0xDC, 0x04,
-  0xBD, 0x31, 0xA2, 0x2F, 0xB3, 0x35, 0x56, 0xBF
-};
-
-static const unsigned char kat_RSA_SHA512[] = {
-  0x69, 0x52, 0x1B, 0x51, 0x5E, 0x06, 0xCA, 0x9B, 0x16, 0x51, 0x5D, 0xCF,
-  0x49, 0x25, 0x4A, 0xA1, 0x6A, 0x77, 0x4C, 0x36, 0x40, 0xF8, 0xB2, 0x9A,
-  0x15, 0xEA, 0x5C, 0xE5, 0xE6, 0x82, 0xE0, 0x86, 0x82, 0x6B, 0x32, 0xF1,
-  0x04, 0xC1, 0x5A, 0x1A, 0xED, 0x1E, 0x9A, 0xB6, 0x4C, 0x54, 0x9F, 0xD8,
-  0x8D, 0xCC, 0xAC, 0x8A, 0xBB, 0x9C, 0x82, 0x3F, 0xA6, 0x53, 0x62, 0xB5,
-  0x80, 0xE2, 0xBC, 0xDD, 0x67, 0x2B, 0xD9, 0x3F, 0xE4, 0x75, 0x92, 0x6B,
-  0xAF, 0x62, 0x7C, 0x52, 0xF0, 0xEE, 0x33, 0xDF, 0x1B, 0x1D, 0x47, 0xE6,
-  0x59, 0x56, 0xA5, 0xB9, 0x5C, 0xE6, 0x77, 0x78, 0x16, 0x63, 0x84, 0x05,
-  0x6F, 0x0E, 0x2B, 0x31, 0x9D, 0xF7, 0x7F, 0xB2, 0x64, 0x71, 0xE0, 0x2D,
-  0x3E, 0x62, 0xCE, 0xB5, 0x3F, 0x88, 0xDF, 0x2D, 0xAB, 0x98, 0x65, 0x91,
-  0xDF, 0x70, 0x14, 0xA5, 0x3F, 0x36, 0xAB, 0x84
-};
-
-static const unsigned char kat_RSA_X931_SHA1[] = {
-  0x86, 0xB4, 0x18, 0xBA, 0xD1, 0x80, 0xB6, 0x7C, 0x42, 0x45, 0x4D, 0xDF,
-  0xE9, 0x2D, 0xE1, 0x83, 0x5F, 0xB5, 0x2F, 0xC9, 0xCD, 0xC4, 0xB2, 0x75,
-  0x80, 0xA4, 0xF1, 0x4A, 0xE7, 0x83, 0x12, 0x1E, 0x1E, 0x14, 0xB8, 0xAC,
-  0x35, 0xE2, 0xAA, 0x0B, 0x5C, 0xF8, 0x38, 0x4D, 0x04, 0xEE, 0xA9, 0x97,
-  0x70, 0xFB, 0x5E, 0xE7, 0xB7, 0xE3, 0x62, 0x23, 0x4B, 0x38, 0xBE, 0xD6,
-  0x53, 0x15, 0xF7, 0xDF, 0x87, 0xB4, 0x0E, 0xCC, 0xB1, 0x1A, 0x11, 0x19,
-  0xEE, 0x51, 0xCC, 0x92, 0xDD, 0xBC, 0x63, 0x29, 0x63, 0x0C, 0x59, 0xD7,
-  0x6F, 0x4C, 0x3C, 0x37, 0x5B, 0x37, 0x03, 0x61, 0x7D, 0x24, 0x1C, 0x99,
-  0x48, 0xAF, 0x82, 0xFE, 0x32, 0x41, 0x9B, 0xB2, 0xDB, 0xEA, 0xED, 0x76,
-  0x8E, 0x6E, 0xCA, 0x7E, 0x4E, 0x14, 0xBA, 0x30, 0x84, 0x1C, 0xB3, 0x67,
-  0xA3, 0x29, 0x80, 0x70, 0x54, 0x68, 0x7D, 0x49
-};
-
-static const unsigned char kat_RSA_X931_SHA256[] = {
-  0x7E, 0xA2, 0x77, 0xFE, 0xB8, 0x54, 0x8A, 0xC7, 0x7F, 0x64, 0x54, 0x89,
-  0xE5, 0x52, 0x15, 0x8E, 0x52, 0x96, 0x4E, 0xA6, 0x58, 0x92, 0x1C, 0xDD,
-  0xEA, 0xA2, 0x2D, 0x5C, 0xD1, 0x62, 0x00, 0x49, 0x05, 0x95, 0x73, 0xCF,
-  0x16, 0x76, 0x68, 0xF6, 0xC6, 0x5E, 0x80, 0xB8, 0xB8, 0x7B, 0xC8, 0x9B,
-  0xC6, 0x53, 0x88, 0x26, 0x20, 0x88, 0x73, 0xB6, 0x13, 0xB8, 0xF0, 0x4B,
-  0x00, 0x85, 0xF3, 0xDD, 0x07, 0x50, 0xEB, 0x20, 0xC4, 0x38, 0x0E, 0x98,
-  0xAD, 0x4E, 0x49, 0x2C, 0xD7, 0x65, 0xA5, 0x19, 0x0E, 0x59, 0x01, 0xEC,
-  0x7E, 0x75, 0x89, 0x69, 0x2E, 0x63, 0x76, 0x85, 0x46, 0x8D, 0xA0, 0x8C,
-  0x33, 0x1D, 0x82, 0x8C, 0x03, 0xEA, 0x69, 0x88, 0x35, 0xA1, 0x42, 0xBD,
-  0x21, 0xED, 0x8D, 0xBC, 0xBC, 0xDB, 0x30, 0xFF, 0x86, 0xF0, 0x5B, 0xDC,
-  0xE3, 0xE2, 0xE8, 0x0A, 0x0A, 0x29, 0x94, 0x80
-};
-
-static const unsigned char kat_RSA_X931_SHA384[] = {
-  0x5C, 0x7D, 0x96, 0x35, 0xEC, 0x7E, 0x11, 0x38, 0xBB, 0x7B, 0xEC, 0x7B,
-  0xF2, 0x82, 0x8E, 0x99, 0xBD, 0xEF, 0xD8, 0xAE, 0xD7, 0x39, 0x37, 0xCB,
-  0xE6, 0x4F, 0x5E, 0x0A, 0x13, 0xE4, 0x2E, 0x40, 0xB9, 0xBE, 0x2E, 0xE3,
-  0xEF, 0x78, 0x83, 0x18, 0x44, 0x35, 0x9C, 0x8E, 0xD7, 0x4A, 0x63, 0xF6,
-  0x57, 0xC2, 0xB0, 0x08, 0x51, 0x73, 0xCF, 0xCA, 0x99, 0x66, 0xEE, 0x31,
-  0xD8, 0x69, 0xE9, 0xAB, 0x13, 0x27, 0x7B, 0x41, 0x1E, 0x6D, 0x8D, 0xF1,
-  0x3E, 0x9C, 0x35, 0x95, 0x58, 0xDD, 0x2B, 0xD5, 0xA0, 0x60, 0x41, 0x79,
-  0x24, 0x22, 0xE4, 0xB7, 0xBF, 0x47, 0x53, 0xF6, 0x34, 0xD5, 0x7C, 0xFF,
-  0x0E, 0x09, 0xEE, 0x2E, 0xE2, 0x37, 0xB9, 0xDE, 0xC5, 0x12, 0x44, 0x35,
-  0xEF, 0x01, 0xE6, 0x5E, 0x39, 0x31, 0x2D, 0x71, 0xA5, 0xDC, 0xC6, 0x6D,
-  0xE2, 0xCD, 0x85, 0xDB, 0x73, 0x82, 0x65, 0x28
-};
-
-static const unsigned char kat_RSA_X931_SHA512[] = {
-  0xA6, 0x65, 0xA2, 0x77, 0x4F, 0xB3, 0x86, 0xCB, 0x64, 0x3A, 0xC1, 0x63,
-  0xFC, 0xA1, 0xAA, 0xCB, 0x9B, 0x79, 0xDD, 0x4B, 0xE1, 0xD9, 0xDA, 0xAC,
-  0xE7, 0x47, 0x09, 0xB2, 0x11, 0x4B, 0x8A, 0xAA, 0x05, 0x9E, 0x77, 0xD7,
-  0x3A, 0xBD, 0x5E, 0x53, 0x09, 0x4A, 0xE6, 0x0F, 0x5E, 0xF9, 0x14, 0x28,
-  0xA0, 0x99, 0x74, 0x64, 0x70, 0x4E, 0xF2, 0xE3, 0xFA, 0xC7, 0xF8, 0xC5,
-  0x6E, 0x2B, 0x79, 0x96, 0x0D, 0x0C, 0xC8, 0x10, 0x34, 0x53, 0xD2, 0xAF,
-  0x17, 0x0E, 0xE0, 0xBF, 0x79, 0xF6, 0x04, 0x72, 0x10, 0xE0, 0xF6, 0xD0,
-  0xCE, 0x8A, 0x6F, 0xA1, 0x95, 0x89, 0xBF, 0x58, 0x8F, 0x46, 0x5F, 0x09,
-  0x9F, 0x09, 0xCA, 0x84, 0x15, 0x85, 0xE0, 0xED, 0x04, 0x2D, 0xFB, 0x7C,
-  0x36, 0x35, 0x21, 0x31, 0xC3, 0xFD, 0x92, 0x42, 0x11, 0x30, 0x71, 0x1B,
-  0x60, 0x83, 0x18, 0x88, 0xA3, 0xF5, 0x59, 0xC3
-};
-
-
-int FIPS_selftest_rsa()
-       {
-       int ret = 0;
-       RSA *key = NULL;
-       EVP_PKEY pk;
-       key=FIPS_rsa_new();
-       setrsakey(key);
-       pk.type = EVP_PKEY_RSA;
-       pk.pkey.rsa = key;
-
-       if (!fips_pkey_signature_test(&pk, kat_tbs, sizeof(kat_tbs) - 1,
-                               kat_RSA_SHA1, sizeof(kat_RSA_SHA1),
-                               EVP_sha1(), EVP_MD_CTX_FLAG_PAD_PKCS1,
-                               "RSA SHA1 PKCS#1"))
-               goto err;
-       if (!fips_pkey_signature_test(&pk, kat_tbs, sizeof(kat_tbs) - 1,
-                               kat_RSA_SHA224, sizeof(kat_RSA_SHA224),
-                               EVP_sha224(), EVP_MD_CTX_FLAG_PAD_PKCS1,
-                               "RSA SHA224 PKCS#1"))
-               goto err;
-       if (!fips_pkey_signature_test(&pk, kat_tbs, sizeof(kat_tbs) - 1,
-                               kat_RSA_SHA256, sizeof(kat_RSA_SHA256),
-                               EVP_sha256(), EVP_MD_CTX_FLAG_PAD_PKCS1,
-                               "RSA SHA256 PKCS#1"))
-               goto err;
-       if (!fips_pkey_signature_test(&pk, kat_tbs, sizeof(kat_tbs) - 1,
-                               kat_RSA_SHA384, sizeof(kat_RSA_SHA384),
-                               EVP_sha384(), EVP_MD_CTX_FLAG_PAD_PKCS1,
-                               "RSA SHA384 PKCS#1"))
-               goto err;
-       if (!fips_pkey_signature_test(&pk, kat_tbs, sizeof(kat_tbs) - 1,
-                               kat_RSA_SHA512, sizeof(kat_RSA_SHA512),
-                               EVP_sha512(), EVP_MD_CTX_FLAG_PAD_PKCS1,
-                               "RSA SHA512 PKCS#1"))
-               goto err;
-
-       if (!fips_pkey_signature_test(&pk, kat_tbs, sizeof(kat_tbs) - 1,
-                               kat_RSA_PSS_SHA1, sizeof(kat_RSA_PSS_SHA1),
-                               EVP_sha1(), EVP_MD_CTX_FLAG_PAD_PSS,
-                               "RSA SHA1 PSS"))
-               goto err;
-       if (!fips_pkey_signature_test(&pk, kat_tbs, sizeof(kat_tbs) - 1,
-                               kat_RSA_PSS_SHA224, sizeof(kat_RSA_PSS_SHA224),
-                               EVP_sha224(), EVP_MD_CTX_FLAG_PAD_PSS,
-                               "RSA SHA224 PSS"))
-               goto err;
-       if (!fips_pkey_signature_test(&pk, kat_tbs, sizeof(kat_tbs) - 1,
-                               kat_RSA_PSS_SHA256, sizeof(kat_RSA_PSS_SHA256),
-                               EVP_sha256(), EVP_MD_CTX_FLAG_PAD_PSS,
-                               "RSA SHA256 PSS"))
-               goto err;
-       if (!fips_pkey_signature_test(&pk, kat_tbs, sizeof(kat_tbs) - 1,
-                               kat_RSA_PSS_SHA384, sizeof(kat_RSA_PSS_SHA384),
-                               EVP_sha384(), EVP_MD_CTX_FLAG_PAD_PSS,
-                               "RSA SHA384 PSS"))
-               goto err;
-       if (!fips_pkey_signature_test(&pk, kat_tbs, sizeof(kat_tbs) - 1,
-                               kat_RSA_PSS_SHA512, sizeof(kat_RSA_PSS_SHA512),
-                               EVP_sha512(), EVP_MD_CTX_FLAG_PAD_PSS,
-                               "RSA SHA512 PSS"))
-               goto err;
-
-
-       if (!fips_pkey_signature_test(&pk, kat_tbs, sizeof(kat_tbs) - 1,
-                       kat_RSA_X931_SHA1, sizeof(kat_RSA_X931_SHA1),
-                       EVP_sha1(), EVP_MD_CTX_FLAG_PAD_X931,
-                       "RSA SHA1 X931"))
-               goto err;
-       /* NB: SHA224 not supported in X9.31 */
-       if (!fips_pkey_signature_test(&pk, kat_tbs, sizeof(kat_tbs) - 1,
-                       kat_RSA_X931_SHA256, sizeof(kat_RSA_X931_SHA256),
-                       EVP_sha256(), EVP_MD_CTX_FLAG_PAD_X931,
-                       "RSA SHA256 X931"))
-               goto err;
-       if (!fips_pkey_signature_test(&pk, kat_tbs, sizeof(kat_tbs) - 1,
-                       kat_RSA_X931_SHA384, sizeof(kat_RSA_X931_SHA384),
-                       EVP_sha384(), EVP_MD_CTX_FLAG_PAD_X931,
-                       "RSA SHA384 X931"))
-               goto err;
-       if (!fips_pkey_signature_test(&pk, kat_tbs, sizeof(kat_tbs) - 1,
-                       kat_RSA_X931_SHA512, sizeof(kat_RSA_X931_SHA512),
-                       EVP_sha512(), EVP_MD_CTX_FLAG_PAD_X931,
-                       "RSA SHA512 X931"))
-               goto err;
-
-
-       ret = 1;
-
-       err:
-       FIPS_rsa_free(key);
-       return ret;
-       }
-
-#endif /* def OPENSSL_FIPS */
diff --git a/deps/openssl/openssl/fips/rsa/fips_rsa_sign.c b/deps/openssl/openssl/fips/rsa/fips_rsa_sign.c
deleted file mode 100644 (file)
index 3736462..0000000
+++ /dev/null
@@ -1,554 +0,0 @@
-/* fips_rsa_sign.c */
-/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
- * project 2007.
- */
-/* ====================================================================
- * Copyright (c) 2007 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    licensing@OpenSSL.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
- * ====================================================================
- *
- * This product includes cryptographic software written by Eric Young
- * (eay@cryptsoft.com).  This product includes software written by Tim
- * Hudson (tjh@cryptsoft.com).
- *
- */
-
-#include <string.h>
-#include <openssl/evp.h>
-#include <openssl/rsa.h>
-#include <openssl/err.h>
-#include <openssl/sha.h>
-
-#ifdef OPENSSL_FIPS
-
-/* FIPS versions of RSA_sign() and RSA_verify().
- * These will only have to deal with SHA* signatures and by including
- * pregenerated encodings all ASN1 dependencies can be avoided
- */
-
-/* Standard encodings including NULL parameter */
-
-static const unsigned char sha1_bin[] = {
-  0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05,
-  0x00, 0x04, 0x14
-};
-
-static const unsigned char sha224_bin[] = {
-  0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
-  0x04, 0x02, 0x04, 0x05, 0x00, 0x04, 0x1c
-};
-
-static const unsigned char sha256_bin[] = {
-  0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
-  0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20
-};
-
-static const unsigned char sha384_bin[] = {
-  0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
-  0x04, 0x02, 0x02, 0x05, 0x00, 0x04, 0x30
-};
-
-static const unsigned char sha512_bin[] = {
-  0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
-  0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40
-};
-
-/* Alternate encodings with absent parameters. We don't generate signature
- * using this format but do tolerate received signatures of this form.
- */
-
-static unsigned char sha1_nn_bin[] = {
-  0x30, 0x1f, 0x30, 0x07, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x04,
-  0x14
-};
-
-static unsigned char sha224_nn_bin[] = {
-  0x30, 0x2b, 0x30, 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
-  0x04, 0x02, 0x04, 0x04, 0x1c
-};
-
-static unsigned char sha256_nn_bin[] = {
-  0x30, 0x2f, 0x30, 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
-  0x04, 0x02, 0x01, 0x04, 0x20
-};
-
-static unsigned char sha384_nn_bin[] = {
-  0x30, 0x3f, 0x30, 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
-  0x04, 0x02, 0x02, 0x04, 0x30
-};
-
-static unsigned char sha512_nn_bin[] = {
-  0x30, 0x4f, 0x30, 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
-  0x04, 0x02, 0x03, 0x04, 0x40
-};
-
-
-static const unsigned char *fips_digestinfo_encoding(int nid, unsigned int *len)
-       {
-       switch (nid)
-               {
-
-               case NID_sha1:
-               *len = sizeof(sha1_bin);
-               return sha1_bin;
-
-               case NID_sha224:
-               *len = sizeof(sha224_bin);
-               return sha224_bin;
-
-               case NID_sha256:
-               *len = sizeof(sha256_bin);
-               return sha256_bin;
-
-               case NID_sha384:
-               *len = sizeof(sha384_bin);
-               return sha384_bin;
-
-               case NID_sha512:
-               *len = sizeof(sha512_bin);
-               return sha512_bin;
-
-               default:
-               return NULL;
-
-               }
-       }
-
-static const unsigned char *fips_digestinfo_nn_encoding(int nid, unsigned int *len)
-       {
-       switch (nid)
-               {
-
-               case NID_sha1:
-               *len = sizeof(sha1_nn_bin);
-               return sha1_nn_bin;
-
-               case NID_sha224:
-               *len = sizeof(sha224_nn_bin);
-               return sha224_nn_bin;
-
-               case NID_sha256:
-               *len = sizeof(sha256_nn_bin);
-               return sha256_nn_bin;
-
-               case NID_sha384:
-               *len = sizeof(sha384_nn_bin);
-               return sha384_nn_bin;
-
-               case NID_sha512:
-               *len = sizeof(sha512_nn_bin);
-               return sha512_nn_bin;
-
-               default:
-               return NULL;
-
-               }
-       }
-
-static int fips_rsa_sign(int type, const unsigned char *x, unsigned int y,
-            unsigned char *sigret, unsigned int *siglen, EVP_MD_SVCTX *sv)
-       {
-       int i=0,j,ret=0;
-       unsigned int dlen;
-       const unsigned char *der;
-       unsigned int m_len;
-       int pad_mode = sv->mctx->flags & EVP_MD_CTX_FLAG_PAD_MASK;
-       int rsa_pad_mode = 0;
-       RSA *rsa = sv->key;
-       /* Largest DigestInfo: 19 (max encoding) + max MD */
-       unsigned char tmpdinfo[19 + EVP_MAX_MD_SIZE];
-       unsigned char md[EVP_MAX_MD_SIZE + 1];
-
-        EVP_DigestFinal_ex(sv->mctx, md, &m_len);
-
-       if((rsa->flags & RSA_FLAG_SIGN_VER) && rsa->meth->rsa_sign)
-               {
-               ret = rsa->meth->rsa_sign(type, md, m_len,
-                       sigret, siglen, rsa);
-               goto done;
-               }
-
-       if (pad_mode == EVP_MD_CTX_FLAG_PAD_X931)
-               {
-               int hash_id;
-               memcpy(tmpdinfo, md, m_len);
-               hash_id = RSA_X931_hash_id(M_EVP_MD_CTX_type(sv->mctx));
-               if (hash_id == -1)
-                       {
-                       RSAerr(RSA_F_FIPS_RSA_SIGN,RSA_R_UNKNOWN_ALGORITHM_TYPE);
-                       return 0;
-                       }
-               tmpdinfo[m_len] = (unsigned char)hash_id;
-               i = m_len + 1;
-               rsa_pad_mode = RSA_X931_PADDING;
-               }
-       else if (pad_mode == EVP_MD_CTX_FLAG_PAD_PKCS1)
-               {
-
-               der = fips_digestinfo_encoding(type, &dlen);
-               
-               if (!der)
-                       {
-                       RSAerr(RSA_F_FIPS_RSA_SIGN,RSA_R_UNKNOWN_ALGORITHM_TYPE);
-                       return 0;
-                       }
-               memcpy(tmpdinfo, der, dlen);
-               memcpy(tmpdinfo + dlen, md, m_len);
-
-               i = dlen + m_len;
-               rsa_pad_mode = RSA_PKCS1_PADDING;
-
-               }
-       else if (pad_mode == EVP_MD_CTX_FLAG_PAD_PSS)
-               {
-               unsigned char *sbuf;
-               int saltlen;
-               i = RSA_size(rsa);
-               sbuf = OPENSSL_malloc(RSA_size(rsa));
-               saltlen = M_EVP_MD_CTX_FLAG_PSS_SALT(sv->mctx);
-               if (saltlen == EVP_MD_CTX_FLAG_PSS_MDLEN)
-                       saltlen = -1;
-               else if (saltlen == EVP_MD_CTX_FLAG_PSS_MREC)
-                       saltlen = -2;
-               if (!sbuf)
-                       {
-                       RSAerr(RSA_F_FIPS_RSA_SIGN,ERR_R_MALLOC_FAILURE);
-                       goto psserr;
-                       }
-               if (!RSA_padding_add_PKCS1_PSS(rsa, sbuf, md,
-                                       M_EVP_MD_CTX_md(sv->mctx), saltlen))
-                       goto psserr;
-               j=rsa->meth->rsa_priv_enc(i,sbuf,sigret,rsa,RSA_NO_PADDING);
-               if (j > 0)
-                       {
-                       ret=1;
-                       *siglen=j;
-                       }
-               psserr:
-               OPENSSL_cleanse(md,m_len);
-               OPENSSL_cleanse(sbuf, i);
-               OPENSSL_free(sbuf);
-               return ret;
-               }
-
-       j=RSA_size(rsa);
-       if (i > (j-RSA_PKCS1_PADDING_SIZE))
-               {
-               RSAerr(RSA_F_FIPS_RSA_SIGN,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY);
-               goto done;
-               }
-       /* NB: call underlying method directly to avoid FIPS blocking */
-       j=rsa->meth->rsa_priv_enc(i,tmpdinfo,sigret,rsa,rsa_pad_mode);
-       if (j > 0)
-               {
-               ret=1;
-               *siglen=j;
-               }
-
-       done:
-       OPENSSL_cleanse(tmpdinfo,i);
-       OPENSSL_cleanse(md,m_len);
-       return ret;
-       }
-
-static int fips_rsa_verify(int dtype,
-               const unsigned char *x, unsigned int y,
-               unsigned char *sigbuf, unsigned int siglen, EVP_MD_SVCTX *sv)
-       {
-       int i,ret=0;
-       unsigned int dlen, diglen;
-       int pad_mode = sv->mctx->flags & EVP_MD_CTX_FLAG_PAD_MASK;
-       int rsa_pad_mode = 0;
-       unsigned char *s;
-       const unsigned char *der;
-       unsigned char dig[EVP_MAX_MD_SIZE];
-       RSA *rsa = sv->key;
-
-       if (siglen != (unsigned int)RSA_size(sv->key))
-               {
-               RSAerr(RSA_F_FIPS_RSA_VERIFY,RSA_R_WRONG_SIGNATURE_LENGTH);
-               return(0);
-               }
-
-        EVP_DigestFinal_ex(sv->mctx, dig, &diglen);
-
-       if((rsa->flags & RSA_FLAG_SIGN_VER) && rsa->meth->rsa_verify)
-               {
-               return rsa->meth->rsa_verify(dtype, dig, diglen,
-                       sigbuf, siglen, rsa);
-               }
-
-
-       s= OPENSSL_malloc((unsigned int)siglen);
-       if (s == NULL)
-               {
-               RSAerr(RSA_F_FIPS_RSA_VERIFY,ERR_R_MALLOC_FAILURE);
-               goto err;
-               }
-       if (pad_mode == EVP_MD_CTX_FLAG_PAD_X931)
-               rsa_pad_mode = RSA_X931_PADDING;
-       else if (pad_mode == EVP_MD_CTX_FLAG_PAD_PKCS1)
-               rsa_pad_mode = RSA_PKCS1_PADDING;
-       else if (pad_mode == EVP_MD_CTX_FLAG_PAD_PSS)
-               rsa_pad_mode = RSA_NO_PADDING;
-
-       /* NB: call underlying method directly to avoid FIPS blocking */
-       i=rsa->meth->rsa_pub_dec((int)siglen,sigbuf,s, rsa, rsa_pad_mode);
-
-       if (i <= 0) goto err;
-
-       if (pad_mode == EVP_MD_CTX_FLAG_PAD_X931)
-               {
-               int hash_id;
-               if (i != (int)(diglen + 1))
-                       {
-                       RSAerr(RSA_F_FIPS_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
-                       goto err;
-                       }
-               hash_id = RSA_X931_hash_id(M_EVP_MD_CTX_type(sv->mctx));
-               if (hash_id == -1)
-                       {
-                       RSAerr(RSA_F_FIPS_RSA_VERIFY,RSA_R_UNKNOWN_ALGORITHM_TYPE);
-                       goto err;
-                       }
-               if (s[diglen] != (unsigned char)hash_id)
-                       {
-                       RSAerr(RSA_F_FIPS_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
-                       goto err;
-                       }
-               if (memcmp(s, dig, diglen))
-                       {
-                       RSAerr(RSA_F_FIPS_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
-                       goto err;
-                       }
-               ret = 1;
-               }
-       else if (pad_mode == EVP_MD_CTX_FLAG_PAD_PKCS1)
-               {
-
-               der = fips_digestinfo_encoding(dtype, &dlen);
-               
-               if (!der)
-                       {
-                       RSAerr(RSA_F_FIPS_RSA_VERIFY,RSA_R_UNKNOWN_ALGORITHM_TYPE);
-                       return(0);
-                       }
-
-               /* Compare, DigestInfo length, DigestInfo header and finally
-                * digest value itself
-                */
-
-               /* If length mismatch try alternate encoding */
-               if (i != (int)(dlen + diglen))
-                       der = fips_digestinfo_nn_encoding(dtype, &dlen);
-
-               if ((i != (int)(dlen + diglen)) || memcmp(der, s, dlen)
-                       || memcmp(s + dlen, dig, diglen))
-                       {
-                       RSAerr(RSA_F_FIPS_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
-                       goto err;
-                       }
-               ret = 1;
-
-               }
-       else if (pad_mode == EVP_MD_CTX_FLAG_PAD_PSS)
-               {
-               int saltlen;
-               saltlen = M_EVP_MD_CTX_FLAG_PSS_SALT(sv->mctx);
-               if (saltlen == EVP_MD_CTX_FLAG_PSS_MDLEN)
-                       saltlen = -1;
-               else if (saltlen == EVP_MD_CTX_FLAG_PSS_MREC)
-                       saltlen = -2;
-               ret = RSA_verify_PKCS1_PSS(rsa, dig, M_EVP_MD_CTX_md(sv->mctx),
-                                               s, saltlen);
-               if (ret < 0)
-                       ret = 0;
-               }
-err:
-       if (s != NULL)
-               {
-               OPENSSL_cleanse(s, siglen);
-               OPENSSL_free(s);
-               }
-       return(ret);
-       }
-
-#define EVP_PKEY_RSA_fips_method \
-                               (evp_sign_method *)fips_rsa_sign, \
-                               (evp_verify_method *)fips_rsa_verify, \
-                               {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0}
-
-static int init(EVP_MD_CTX *ctx)
-       { return SHA1_Init(ctx->md_data); }
-
-static int update(EVP_MD_CTX *ctx,const void *data,size_t count)
-       { return SHA1_Update(ctx->md_data,data,count); }
-
-static int final(EVP_MD_CTX *ctx,unsigned char *md)
-       { return SHA1_Final(md,ctx->md_data); }
-
-static const EVP_MD sha1_md=
-       {
-       NID_sha1,
-       NID_sha1WithRSAEncryption,
-       SHA_DIGEST_LENGTH,
-       EVP_MD_FLAG_FIPS|EVP_MD_FLAG_SVCTX,
-       init,
-       update,
-       final,
-       NULL,
-       NULL,
-       EVP_PKEY_RSA_fips_method,
-       SHA_CBLOCK,
-       sizeof(EVP_MD *)+sizeof(SHA_CTX),
-       };
-
-const EVP_MD *EVP_sha1(void)
-       {
-       return(&sha1_md);
-       }
-
-static int init224(EVP_MD_CTX *ctx)
-       { return SHA224_Init(ctx->md_data); }
-static int init256(EVP_MD_CTX *ctx)
-       { return SHA256_Init(ctx->md_data); }
-/*
- * Even though there're separate SHA224_[Update|Final], we call
- * SHA256 functions even in SHA224 context. This is what happens
- * there anyway, so we can spare few CPU cycles:-)
- */
-static int update256(EVP_MD_CTX *ctx,const void *data,size_t count)
-       { return SHA256_Update(ctx->md_data,data,count); }
-static int final256(EVP_MD_CTX *ctx,unsigned char *md)
-       { return SHA256_Final(md,ctx->md_data); }
-
-static const EVP_MD sha224_md=
-       {
-       NID_sha224,
-       NID_sha224WithRSAEncryption,
-       SHA224_DIGEST_LENGTH,
-       EVP_MD_FLAG_FIPS|EVP_MD_FLAG_SVCTX,
-       init224,
-       update256,
-       final256,
-       NULL,
-       NULL,
-       EVP_PKEY_RSA_fips_method,
-       SHA256_CBLOCK,
-       sizeof(EVP_MD *)+sizeof(SHA256_CTX),
-       };
-
-const EVP_MD *EVP_sha224(void)
-       { return(&sha224_md); }
-
-static const EVP_MD sha256_md=
-       {
-       NID_sha256,
-       NID_sha256WithRSAEncryption,
-       SHA256_DIGEST_LENGTH,
-       EVP_MD_FLAG_FIPS|EVP_MD_FLAG_SVCTX,
-       init256,
-       update256,
-       final256,
-       NULL,
-       NULL,
-       EVP_PKEY_RSA_fips_method,
-       SHA256_CBLOCK,
-       sizeof(EVP_MD *)+sizeof(SHA256_CTX),
-       };
-
-const EVP_MD *EVP_sha256(void)
-       { return(&sha256_md); }
-
-static int init384(EVP_MD_CTX *ctx)
-       { return SHA384_Init(ctx->md_data); }
-static int init512(EVP_MD_CTX *ctx)
-       { return SHA512_Init(ctx->md_data); }
-/* See comment in SHA224/256 section */
-static int update512(EVP_MD_CTX *ctx,const void *data,size_t count)
-       { return SHA512_Update(ctx->md_data,data,count); }
-static int final512(EVP_MD_CTX *ctx,unsigned char *md)
-       { return SHA512_Final(md,ctx->md_data); }
-
-static const EVP_MD sha384_md=
-       {
-       NID_sha384,
-       NID_sha384WithRSAEncryption,
-       SHA384_DIGEST_LENGTH,
-       EVP_MD_FLAG_FIPS|EVP_MD_FLAG_SVCTX,
-       init384,
-       update512,
-       final512,
-       NULL,
-       NULL,
-       EVP_PKEY_RSA_fips_method,
-       SHA512_CBLOCK,
-       sizeof(EVP_MD *)+sizeof(SHA512_CTX),
-       };
-
-const EVP_MD *EVP_sha384(void)
-       { return(&sha384_md); }
-
-static const EVP_MD sha512_md=
-       {
-       NID_sha512,
-       NID_sha512WithRSAEncryption,
-       SHA512_DIGEST_LENGTH,
-       EVP_MD_FLAG_FIPS|EVP_MD_FLAG_SVCTX,
-       init512,
-       update512,
-       final512,
-       NULL,
-       NULL,
-       EVP_PKEY_RSA_fips_method,
-       SHA512_CBLOCK,
-       sizeof(EVP_MD *)+sizeof(SHA512_CTX),
-       };
-
-const EVP_MD *EVP_sha512(void)
-       { return(&sha512_md); }
-
-#endif
diff --git a/deps/openssl/openssl/fips/rsa/fips_rsa_x931g.c b/deps/openssl/openssl/fips/rsa/fips_rsa_x931g.c
deleted file mode 100644 (file)
index d9f9a81..0000000
+++ /dev/null
@@ -1,280 +0,0 @@
-/* crypto/rsa/rsa_gen.c */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 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 acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-#include <openssl/err.h>
-#include <openssl/bn.h>
-#include <openssl/rsa.h>
-#include <openssl/fips.h>
-
-#ifdef OPENSSL_FIPS
-
-extern int fips_check_rsa(RSA *rsa);
-
-
-/* X9.31 RSA key derivation and generation */
-
-int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1, BIGNUM *q2,
-                       const BIGNUM *Xp1, const BIGNUM *Xp2, const BIGNUM *Xp,
-                       const BIGNUM *Xq1, const BIGNUM *Xq2, const BIGNUM *Xq,
-                       const BIGNUM *e, BN_GENCB *cb)
-       {
-       BIGNUM *r0=NULL,*r1=NULL,*r2=NULL,*r3=NULL;
-       BN_CTX *ctx=NULL,*ctx2=NULL;
-
-       if (!rsa) 
-               goto err;
-
-       ctx = BN_CTX_new();
-       BN_CTX_start(ctx);
-       if (!ctx) 
-               goto err;
-
-       r0 = BN_CTX_get(ctx);
-       r1 = BN_CTX_get(ctx);
-       r2 = BN_CTX_get(ctx);
-       r3 = BN_CTX_get(ctx);
-
-       if (r3 == NULL)
-               goto err;
-       if (!rsa->e)
-               {
-               rsa->e = BN_dup(e);
-               if (!rsa->e)
-                       goto err;
-               }
-       else
-               e = rsa->e;
-
-       /* If not all parameters present only calculate what we can.
-        * This allows test programs to output selective parameters.
-        */
-
-       if (Xp && !rsa->p)
-               {
-               rsa->p = BN_new();
-               if (!rsa->p)
-                       goto err;
-
-               if (!BN_X931_derive_prime_ex(rsa->p, p1, p2,
-                                       Xp, Xp1, Xp2, e, ctx, cb))
-                       goto err;
-               }
-
-       if (Xq && !rsa->q)
-               {
-               rsa->q = BN_new();
-               if (!rsa->q)
-                       goto err;
-               if (!BN_X931_derive_prime_ex(rsa->q, q1, q2,
-                                       Xq, Xq1, Xq2, e, ctx, cb))
-                       goto err;
-               }
-
-       if (!rsa->p || !rsa->q)
-               {
-               BN_CTX_end(ctx);
-               BN_CTX_free(ctx);
-               return 2;
-               }
-
-       /* Since both primes are set we can now calculate all remaining 
-        * components.
-        */
-
-       /* calculate n */
-       rsa->n=BN_new();
-       if (rsa->n == NULL)
-               goto err;
-       if (!BN_mul(rsa->n,rsa->p,rsa->q,ctx))
-               goto err;
-
-       /* calculate d */
-       if (!BN_sub(r1,rsa->p,BN_value_one()))
-               goto err;       /* p-1 */
-       if (!BN_sub(r2,rsa->q,BN_value_one()))
-               goto err;       /* q-1 */
-       if (!BN_mul(r0,r1,r2,ctx))
-               goto err;       /* (p-1)(q-1) */
-
-       if (!BN_gcd(r3, r1, r2, ctx))
-               goto err;
-
-       if (!BN_div(r0, NULL, r0, r3, ctx))
-               goto err;       /* LCM((p-1)(q-1)) */
-
-       ctx2 = BN_CTX_new();
-       if (!ctx2)
-               goto err;
-
-       rsa->d=BN_mod_inverse(NULL,rsa->e,r0,ctx2);     /* d */
-       if (rsa->d == NULL)
-               goto err;
-
-       /* calculate d mod (p-1) */
-       rsa->dmp1=BN_new();
-       if (rsa->dmp1 == NULL)
-               goto err;
-       if (!BN_mod(rsa->dmp1,rsa->d,r1,ctx))
-               goto err;
-
-       /* calculate d mod (q-1) */
-       rsa->dmq1=BN_new();
-       if (rsa->dmq1 == NULL)
-               goto err;
-       if (!BN_mod(rsa->dmq1,rsa->d,r2,ctx))
-               goto err;
-
-       /* calculate inverse of q mod p */
-       rsa->iqmp=BN_mod_inverse(NULL,rsa->q,rsa->p,ctx2);
-
-       err:
-       if (ctx)
-               {
-               BN_CTX_end(ctx);
-               BN_CTX_free(ctx);
-               }
-       if (ctx2)
-               BN_CTX_free(ctx2);
-       /* If this is set all calls successful */
-       if (rsa->iqmp != NULL)
-               return 1;
-
-       return 0;
-
-       }
-
-int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e, BN_GENCB *cb)
-       {
-       int ok = 0;
-       BIGNUM *Xp = NULL, *Xq = NULL;
-       BN_CTX *ctx = NULL;
-       
-       if (bits < OPENSSL_RSA_FIPS_MIN_MODULUS_BITS)
-           {
-           FIPSerr(FIPS_F_RSA_X931_GENERATE_KEY_EX,FIPS_R_KEY_TOO_SHORT);
-           return 0;
-           }
-
-       if (bits & 0xff)
-           {
-           FIPSerr(FIPS_F_RSA_X931_GENERATE_KEY_EX,FIPS_R_INVALID_KEY_LENGTH);
-           return 0;
-           }
-
-       if(FIPS_selftest_failed())
-           {
-           FIPSerr(FIPS_F_RSA_X931_GENERATE_KEY_EX,FIPS_R_FIPS_SELFTEST_FAILED);
-           return 0;
-           }
-
-       ctx = BN_CTX_new();
-       if (!ctx)
-               goto error;
-
-       BN_CTX_start(ctx);
-       Xp = BN_CTX_get(ctx);
-       Xq = BN_CTX_get(ctx);
-       if (!BN_X931_generate_Xpq(Xp, Xq, bits, ctx))
-               goto error;
-
-       rsa->p = BN_new();
-       rsa->q = BN_new();
-       if (!rsa->p || !rsa->q)
-               goto error;
-
-       /* Generate two primes from Xp, Xq */
-
-       if (!BN_X931_generate_prime_ex(rsa->p, NULL, NULL, NULL, NULL, Xp,
-                                       e, ctx, cb))
-               goto error;
-
-       if (!BN_X931_generate_prime_ex(rsa->q, NULL, NULL, NULL, NULL, Xq,
-                                       e, ctx, cb))
-               goto error;
-
-       /* Since rsa->p and rsa->q are valid this call will just derive
-        * remaining RSA components.
-        */
-
-       if (!RSA_X931_derive_ex(rsa, NULL, NULL, NULL, NULL,
-                               NULL, NULL, NULL, NULL, NULL, NULL, e, cb))
-               goto error;
-
-       if(!fips_check_rsa(rsa))
-           goto error;
-
-       ok = 1;
-
-       error:
-       if (ctx)
-               {
-               BN_CTX_end(ctx);
-               BN_CTX_free(ctx);
-               }
-
-       if (ok)
-               return 1;
-
-       return 0;
-
-       }
-
-#endif
diff --git a/deps/openssl/openssl/fips/rsa/fips_rsagtest.c b/deps/openssl/openssl/fips/rsa/fips_rsagtest.c
deleted file mode 100644 (file)
index 657e1b6..0000000
+++ /dev/null
@@ -1,390 +0,0 @@
-/* fips_rsagtest.c */
-/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
- * project 2005.
- */
-/* ====================================================================
- * Copyright (c) 2005,2007 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    licensing@OpenSSL.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
- * ====================================================================
- *
- * This product includes cryptographic software written by Eric Young
- * (eay@cryptsoft.com).  This product includes software written by Tim
- * Hudson (tjh@cryptsoft.com).
- *
- */
-
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-#include <openssl/bio.h>
-#include <openssl/evp.h>
-#include <openssl/hmac.h>
-#include <openssl/err.h>
-#include <openssl/bn.h>
-#include <openssl/x509v3.h>
-
-#ifndef OPENSSL_FIPS
-
-int main(int argc, char *argv[])
-{
-    printf("No FIPS RSA support\n");
-    return(0);
-}
-
-#else
-
-#include <openssl/rsa.h>
-#include "fips_utl.h"
-
-int rsa_test(FILE *out, FILE *in);
-static int rsa_printkey1(FILE *out, RSA *rsa,
-               BIGNUM *Xp1, BIGNUM *Xp2, BIGNUM *Xp,
-               BIGNUM *e);
-static int rsa_printkey2(FILE *out, RSA *rsa,
-               BIGNUM *Xq1, BIGNUM *Xq2, BIGNUM *Xq);
-
-int main(int argc, char **argv)
-       {
-       FILE *in = NULL, *out = NULL;
-
-       int ret = 1;
-
-       if(!FIPS_mode_set(1))
-               {
-               do_print_errors();
-               goto end;
-               }
-
-       if (argc == 1)
-               in = stdin;
-       else
-               in = fopen(argv[1], "r");
-
-       if (argc < 2)
-               out = stdout;
-       else
-               out = fopen(argv[2], "w");
-
-       if (!in)
-               {
-               fprintf(stderr, "FATAL input initialization error\n");
-               goto end;
-               }
-
-       if (!out)
-               {
-               fprintf(stderr, "FATAL output initialization error\n");
-               goto end;
-               }
-
-       if (!rsa_test(out, in))
-               {
-               fprintf(stderr, "FATAL RSAGTEST file processing error\n");
-               goto end;
-               }
-       else
-               ret = 0;
-
-       end:
-
-       if (ret)
-               do_print_errors();
-
-       if (in && (in != stdin))
-               fclose(in);
-       if (out && (out != stdout))
-               fclose(out);
-
-       return ret;
-
-       }
-
-#define RSA_TEST_MAXLINELEN    10240
-
-int rsa_test(FILE *out, FILE *in)
-       {
-       char *linebuf, *olinebuf, *p, *q;
-       char *keyword, *value;
-       RSA *rsa = NULL;
-       BIGNUM *Xp1 = NULL, *Xp2 = NULL, *Xp = NULL;
-       BIGNUM *Xq1 = NULL, *Xq2 = NULL, *Xq = NULL;
-       BIGNUM *e = NULL;
-       int ret = 0;
-       int lnum = 0;
-
-       olinebuf = OPENSSL_malloc(RSA_TEST_MAXLINELEN);
-       linebuf = OPENSSL_malloc(RSA_TEST_MAXLINELEN);
-
-       if (!linebuf || !olinebuf)
-               goto error;
-
-       while (fgets(olinebuf, RSA_TEST_MAXLINELEN, in))
-               {
-               lnum++;
-               strcpy(linebuf, olinebuf);
-               keyword = linebuf;
-               /* Skip leading space */
-               while (isspace((unsigned char)*keyword))
-                       keyword++;
-
-               /* Look for = sign */
-               p = strchr(linebuf, '=');
-
-               /* If no = or starts with [ (for [foo = bar] line) just copy */
-               if (!p || *keyword=='[')
-                       {
-                       if (fputs(olinebuf, out) < 0)
-                               goto error;
-                       continue;
-                       }
-
-               q = p - 1;
-
-               /* Remove trailing space */
-               while (isspace((unsigned char)*q))
-                       *q-- = 0;
-
-               *p = 0;
-               value = p + 1;
-
-               /* Remove leading space from value */
-               while (isspace((unsigned char)*value))
-                       value++;
-
-               /* Remove trailing space from value */
-               p = value + strlen(value) - 1;
-
-               while (*p == '\n' || isspace((unsigned char)*p))
-                       *p-- = 0;
-
-               if (!strcmp(keyword, "xp1"))
-                       {
-                       if (Xp1 || !do_hex2bn(&Xp1,value))
-                               goto parse_error;
-                       }
-               else if (!strcmp(keyword, "xp2"))
-                       {
-                       if (Xp2 || !do_hex2bn(&Xp2,value))
-                               goto parse_error;
-                       }
-               else if (!strcmp(keyword, "Xp"))
-                       {
-                       if (Xp || !do_hex2bn(&Xp,value))
-                               goto parse_error;
-                       }
-               else if (!strcmp(keyword, "xq1"))
-                       {
-                       if (Xq1 || !do_hex2bn(&Xq1,value))
-                               goto parse_error;
-                       }
-               else if (!strcmp(keyword, "xq2"))
-                       {
-                       if (Xq2 || !do_hex2bn(&Xq2,value))
-                               goto parse_error;
-                       }
-               else if (!strcmp(keyword, "Xq"))
-                       {
-                       if (Xq || !do_hex2bn(&Xq,value))
-                               goto parse_error;
-                       }
-               else if (!strcmp(keyword, "e"))
-                       {
-                       if (e || !do_hex2bn(&e,value))
-                               goto parse_error;
-                       }
-               else if (!strcmp(keyword, "p1"))
-                       continue;
-               else if (!strcmp(keyword, "p2"))
-                       continue;
-               else if (!strcmp(keyword, "p"))
-                       continue;
-               else if (!strcmp(keyword, "q1"))
-                       continue;
-               else if (!strcmp(keyword, "q2"))
-                       continue;
-               else if (!strcmp(keyword, "q"))
-                       continue;
-               else if (!strcmp(keyword, "n"))
-                       continue;
-               else if (!strcmp(keyword, "d"))
-                       continue;
-               else
-                       goto parse_error;
-
-               fputs(olinebuf, out);
-
-               if (e && Xp1 && Xp2 && Xp)
-                       {
-                       rsa = FIPS_rsa_new();
-                       if (!rsa)
-                               goto error;
-                       if (!rsa_printkey1(out, rsa, Xp1, Xp2, Xp, e))
-                               goto error;
-                       BN_free(Xp1);
-                       Xp1 = NULL;
-                       BN_free(Xp2);
-                       Xp2 = NULL;
-                       BN_free(Xp);
-                       Xp = NULL;
-                       BN_free(e);
-                       e = NULL;
-                       }
-
-               if (rsa && Xq1 && Xq2 && Xq)
-                       {
-                       if (!rsa_printkey2(out, rsa, Xq1, Xq2, Xq))
-                               goto error;
-                       BN_free(Xq1);
-                       Xq1 = NULL;
-                       BN_free(Xq2);
-                       Xq2 = NULL;
-                       BN_free(Xq);
-                       Xq = NULL;
-                       FIPS_rsa_free(rsa);
-                       rsa = NULL;
-                       }
-               }
-
-       ret = 1;
-
-       error:
-
-       if (olinebuf)
-               OPENSSL_free(olinebuf);
-       if (linebuf)
-               OPENSSL_free(linebuf);
-
-       if (Xp1)
-               BN_free(Xp1);
-       if (Xp2)
-               BN_free(Xp2);
-       if (Xp)
-               BN_free(Xp);
-       if (Xq1)
-               BN_free(Xq1);
-       if (Xq1)
-               BN_free(Xq1);
-       if (Xq2)
-               BN_free(Xq2);
-       if (Xq)
-               BN_free(Xq);
-       if (e)
-               BN_free(e);
-       if (rsa)
-               FIPS_rsa_free(rsa);
-
-       return ret;
-
-       parse_error:
-
-       fprintf(stderr, "FATAL parse error processing line %d\n", lnum);
-
-       goto error;
-
-       }
-
-static int rsa_printkey1(FILE *out, RSA *rsa,
-               BIGNUM *Xp1, BIGNUM *Xp2, BIGNUM *Xp,
-               BIGNUM *e)
-       {
-       int ret = 0;
-       BIGNUM *p1 = NULL, *p2 = NULL;
-       p1 = BN_new();
-       p2 = BN_new();
-       if (!p1 || !p2)
-               goto error;
-
-       if (!RSA_X931_derive_ex(rsa, p1, p2, NULL, NULL, Xp1, Xp2, Xp,
-                                               NULL, NULL, NULL, e, NULL))
-               goto error;
-
-       do_bn_print_name(out, "p1", p1);
-       do_bn_print_name(out, "p2", p2);
-       do_bn_print_name(out, "p", rsa->p);
-
-       ret = 1;
-
-       error:
-       if (p1)
-               BN_free(p1);
-       if (p2)
-               BN_free(p2);
-
-       return ret;
-       }
-
-static int rsa_printkey2(FILE *out, RSA *rsa,
-               BIGNUM *Xq1, BIGNUM *Xq2, BIGNUM *Xq)
-       {
-       int ret = 0;
-       BIGNUM *q1 = NULL, *q2 = NULL;
-       q1 = BN_new();
-       q2 = BN_new();
-       if (!q1 || !q2)
-               goto error;
-
-       if (!RSA_X931_derive_ex(rsa, NULL, NULL, q1, q2, NULL, NULL, NULL,
-                                               Xq1, Xq2, Xq, NULL, NULL))
-               goto error;
-
-       do_bn_print_name(out, "q1", q1);
-       do_bn_print_name(out, "q2", q2);
-       do_bn_print_name(out, "q", rsa->q);
-       do_bn_print_name(out, "n", rsa->n);
-       do_bn_print_name(out, "d", rsa->d);
-
-       ret = 1;
-
-       error:
-       if (q1)
-               BN_free(q1);
-       if (q2)
-               BN_free(q2);
-
-       return ret;
-       }
-
-#endif
diff --git a/deps/openssl/openssl/fips/rsa/fips_rsastest.c b/deps/openssl/openssl/fips/rsa/fips_rsastest.c
deleted file mode 100644 (file)
index 452084f..0000000
+++ /dev/null
@@ -1,370 +0,0 @@
-/* fips_rsastest.c */
-/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
- * project 2005.
- */
-/* ====================================================================
- * Copyright (c) 2005 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    licensing@OpenSSL.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
- * ====================================================================
- *
- * This product includes cryptographic software written by Eric Young
- * (eay@cryptsoft.com).  This product includes software written by Tim
- * Hudson (tjh@cryptsoft.com).
- *
- */
-
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-#include <openssl/bio.h>
-#include <openssl/evp.h>
-#include <openssl/hmac.h>
-#include <openssl/err.h>
-#include <openssl/bn.h>
-#include <openssl/x509v3.h>
-
-#ifndef OPENSSL_FIPS
-
-int main(int argc, char *argv[])
-{
-    printf("No FIPS RSA support\n");
-    return(0);
-}
-
-#else
-
-#include <openssl/rsa.h>
-#include "fips_utl.h"
-
-static int rsa_stest(FILE *out, FILE *in, int Saltlen);
-static int rsa_printsig(FILE *out, RSA *rsa, const EVP_MD *dgst,
-               unsigned char *Msg, long Msglen, int Saltlen);
-
-int main(int argc, char **argv)
-       {
-       FILE *in = NULL, *out = NULL;
-
-       int ret = 1, Saltlen = -1;
-
-       if(!FIPS_mode_set(1))
-               {
-               do_print_errors();
-               goto end;
-               }
-
-       if ((argc > 2) && !strcmp("-saltlen", argv[1]))
-               {
-               Saltlen = atoi(argv[2]);
-               if (Saltlen < 0)
-                       {
-                       fprintf(stderr, "FATAL: Invalid salt length\n");
-                       goto end;
-                       }
-               argc -= 2;
-               argv += 2;
-               }
-       else if ((argc > 1) && !strcmp("-x931", argv[1]))
-               {
-               Saltlen = -2;
-               argc--;
-               argv++;
-               }
-
-       if (argc == 1)
-               in = stdin;
-       else
-               in = fopen(argv[1], "r");
-
-       if (argc < 2)
-               out = stdout;
-       else
-               out = fopen(argv[2], "w");
-
-       if (!in)
-               {
-               fprintf(stderr, "FATAL input initialization error\n");
-               goto end;
-               }
-
-       if (!out)
-               {
-               fprintf(stderr, "FATAL output initialization error\n");
-               goto end;
-               }
-
-       if (!rsa_stest(out, in, Saltlen))
-               {
-               fprintf(stderr, "FATAL RSASTEST file processing error\n");
-               goto end;
-               }
-       else
-               ret = 0;
-
-       end:
-
-       if (ret)
-               do_print_errors();
-
-       if (in && (in != stdin))
-               fclose(in);
-       if (out && (out != stdout))
-               fclose(out);
-
-       return ret;
-
-       }
-
-#define RSA_TEST_MAXLINELEN    10240
-
-int rsa_stest(FILE *out, FILE *in, int Saltlen)
-       {
-       char *linebuf, *olinebuf, *p, *q;
-       char *keyword, *value;
-       RSA *rsa = NULL;
-       const EVP_MD *dgst = NULL;
-       unsigned char *Msg = NULL;
-       long Msglen = -1;
-       int keylen = -1, current_keylen = -1;
-       int ret = 0;
-       int lnum = 0;
-
-       olinebuf = OPENSSL_malloc(RSA_TEST_MAXLINELEN);
-       linebuf = OPENSSL_malloc(RSA_TEST_MAXLINELEN);
-
-       if (!linebuf || !olinebuf)
-               goto error;
-
-       while (fgets(olinebuf, RSA_TEST_MAXLINELEN, in))
-               {
-               lnum++;
-               strcpy(linebuf, olinebuf);
-               keyword = linebuf;
-               /* Skip leading space */
-               while (isspace((unsigned char)*keyword))
-                       keyword++;
-
-               /* Look for = sign */
-               p = strchr(linebuf, '=');
-
-               /* If no = just copy */
-               if (!p)
-                       {
-                       if (fputs(olinebuf, out) < 0)
-                               goto error;
-                       continue;
-                       }
-
-               q = p - 1;
-
-               /* Remove trailing space */
-               while (isspace((unsigned char)*q))
-                       *q-- = 0;
-
-               *p = 0;
-               value = p + 1;
-
-               /* Remove leading space from value */
-               while (isspace((unsigned char)*value))
-                       value++;
-
-               /* Remove trailing space from value */
-               p = value + strlen(value) - 1;
-
-               while (*p == '\n' || isspace((unsigned char)*p))
-                       *p-- = 0;
-
-               /* Look for [mod = XXX] for key length */
-
-               if (!strcmp(keyword, "[mod"))
-                       {
-                       p = value + strlen(value) - 1;
-                       if (*p != ']')
-                               goto parse_error;
-                       *p = 0;
-                       keylen = atoi(value);
-                       if (keylen < 0)
-                               goto parse_error;
-                       }
-               else if (!strcmp(keyword, "SHAAlg"))
-                       {
-                       if (!strcmp(value, "SHA1"))
-                               dgst = EVP_sha1();
-                       else if (!strcmp(value, "SHA224"))
-                               dgst = EVP_sha224();
-                       else if (!strcmp(value, "SHA256"))
-                               dgst = EVP_sha256();
-                       else if (!strcmp(value, "SHA384"))
-                               dgst = EVP_sha384();
-                       else if (!strcmp(value, "SHA512"))
-                               dgst = EVP_sha512();
-                       else
-                               {
-                               fprintf(stderr,
-                                       "FATAL: unsupported algorithm \"%s\"\n",
-                                                               value);
-                               goto parse_error;
-                               }
-                       }
-               else if (!strcmp(keyword, "Msg"))
-                       {
-                       if (Msg)
-                               goto parse_error;
-                       if (strlen(value) & 1)
-                               *(--value) = '0';
-                       Msg = hex2bin_m(value, &Msglen);
-                       if (!Msg)
-                               goto parse_error;
-                       }
-
-               fputs(olinebuf, out);
-
-               /* If key length has changed, generate and output public
-                * key components of new RSA private key.
-                */
-
-               if (keylen != current_keylen)
-                       {
-                       BIGNUM *bn_e;
-                       if (rsa)
-                               FIPS_rsa_free(rsa);
-                       rsa = FIPS_rsa_new();
-                       if (!rsa)
-                               goto error;
-                       bn_e = BN_new();
-                       if (!bn_e || !BN_set_word(bn_e, 0x1001))
-                               goto error;
-                       if (!RSA_X931_generate_key_ex(rsa, keylen, bn_e, NULL))
-                               goto error;
-                       BN_free(bn_e);
-                       fputs("n = ", out);
-                       do_bn_print(out, rsa->n);
-                       fputs("\ne = ", out);
-                       do_bn_print(out, rsa->e);
-                       fputs("\n", out);
-                       current_keylen = keylen;
-                       }
-
-               if (Msg && dgst)
-                       {
-                       if (!rsa_printsig(out, rsa, dgst, Msg, Msglen,
-                                                               Saltlen))
-                               goto error;
-                       OPENSSL_free(Msg);
-                       Msg = NULL;
-                       }
-
-               }
-
-       ret = 1;
-
-       error:
-
-       if (olinebuf)
-               OPENSSL_free(olinebuf);
-       if (linebuf)
-               OPENSSL_free(linebuf);
-       if (rsa)
-               FIPS_rsa_free(rsa);
-
-       return ret;
-
-       parse_error:
-
-       fprintf(stderr, "FATAL parse error processing line %d\n", lnum);
-
-       goto error;
-
-       }
-
-static int rsa_printsig(FILE *out, RSA *rsa, const EVP_MD *dgst,
-               unsigned char *Msg, long Msglen, int Saltlen)
-       {
-       int ret = 0;
-       unsigned char *sigbuf = NULL;
-       int i, siglen;
-       /* EVP_PKEY structure */
-       EVP_PKEY pk;
-       EVP_MD_CTX ctx;
-       pk.type = EVP_PKEY_RSA;
-       pk.pkey.rsa = rsa;
-
-       siglen = RSA_size(rsa);
-       sigbuf = OPENSSL_malloc(siglen);
-       if (!sigbuf)
-               goto error;
-
-       EVP_MD_CTX_init(&ctx);
-
-       if (Saltlen >= 0)
-               {
-               M_EVP_MD_CTX_set_flags(&ctx,
-                       EVP_MD_CTX_FLAG_PAD_PSS | (Saltlen << 16));
-               }
-       else if (Saltlen == -2)
-               M_EVP_MD_CTX_set_flags(&ctx, EVP_MD_CTX_FLAG_PAD_X931);
-       if (!EVP_SignInit_ex(&ctx, dgst, NULL))
-               goto error;
-       if (!EVP_SignUpdate(&ctx, Msg, Msglen))
-               goto error;
-       if (!EVP_SignFinal(&ctx, sigbuf, (unsigned int *)&siglen, &pk))
-               goto error;
-
-       EVP_MD_CTX_cleanup(&ctx);
-
-       fputs("S = ", out);
-
-       for (i = 0; i < siglen; i++)
-               fprintf(out, "%02X", sigbuf[i]);
-
-       fputs("\n", out);
-
-       ret = 1;
-
-       error:
-
-       return ret;
-       }
-#endif
diff --git a/deps/openssl/openssl/fips/rsa/fips_rsavtest.c b/deps/openssl/openssl/fips/rsa/fips_rsavtest.c
deleted file mode 100644 (file)
index aadab27..0000000
+++ /dev/null
@@ -1,378 +0,0 @@
-/* fips_rsavtest.c */
-/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
- * project 2005.
- */
-/* ====================================================================
- * Copyright (c) 2005 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    licensing@OpenSSL.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
- * ====================================================================
- *
- * This product includes cryptographic software written by Eric Young
- * (eay@cryptsoft.com).  This product includes software written by Tim
- * Hudson (tjh@cryptsoft.com).
- *
- */
-
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-#include <openssl/bio.h>
-#include <openssl/evp.h>
-#include <openssl/hmac.h>
-#include <openssl/err.h>
-#include <openssl/x509v3.h>
-#include <openssl/bn.h>
-
-#ifndef OPENSSL_FIPS
-
-int main(int argc, char *argv[])
-{
-    printf("No FIPS RSA support\n");
-    return(0);
-}
-
-#else
-
-#include <openssl/rsa.h>
-
-#include "fips_utl.h"
-
-int rsa_test(FILE *out, FILE *in, int saltlen);
-static int rsa_printver(FILE *out,
-               BIGNUM *n, BIGNUM *e,
-               const EVP_MD *dgst,
-               unsigned char *Msg, long Msglen,
-               unsigned char *S, long Slen, int Saltlen);
-
-int main(int argc, char **argv)
-       {
-       FILE *in = NULL, *out = NULL;
-
-       int ret = 1;
-       int Saltlen = -1;
-
-       if(!FIPS_mode_set(1))
-               {
-               do_print_errors();
-               goto end;
-               }
-
-       if ((argc > 2) && !strcmp("-saltlen", argv[1]))
-               {
-               Saltlen = atoi(argv[2]);
-               if (Saltlen < 0)
-                       {
-                       fprintf(stderr, "FATAL: Invalid salt length\n");
-                       goto end;
-                       }
-               argc -= 2;
-               argv += 2;
-               }
-       else if ((argc > 1) && !strcmp("-x931", argv[1]))
-               {
-               Saltlen = -2;
-               argc--;
-               argv++;
-               }
-
-       if (argc == 1)
-               in = stdin;
-       else
-               in = fopen(argv[1], "r");
-
-       if (argc < 2)
-               out = stdout;
-       else
-               out = fopen(argv[2], "w");
-
-       if (!in)
-               {
-               fprintf(stderr, "FATAL input initialization error\n");
-               goto end;
-               }
-
-       if (!out)
-               {
-               fprintf(stderr, "FATAL output initialization error\n");
-               goto end;
-               }
-
-       if (!rsa_test(out, in, Saltlen))
-               {
-               fprintf(stderr, "FATAL RSAVTEST file processing error\n");
-               goto end;
-               }
-       else
-               ret = 0;
-
-       end:
-
-       if (ret)
-               do_print_errors();
-
-       if (in && (in != stdin))
-               fclose(in);
-       if (out && (out != stdout))
-               fclose(out);
-
-       return ret;
-
-       }
-
-#define RSA_TEST_MAXLINELEN    10240
-
-int rsa_test(FILE *out, FILE *in, int Saltlen)
-       {
-       char *linebuf, *olinebuf, *p, *q;
-       char *keyword, *value;
-       const EVP_MD *dgst = NULL;
-       BIGNUM *n = NULL, *e = NULL;
-       unsigned char *Msg = NULL, *S = NULL;
-       long Msglen, Slen;
-       int ret = 0;
-       int lnum = 0;
-
-       olinebuf = OPENSSL_malloc(RSA_TEST_MAXLINELEN);
-       linebuf = OPENSSL_malloc(RSA_TEST_MAXLINELEN);
-
-       if (!linebuf || !olinebuf)
-               goto error;
-
-       while (fgets(olinebuf, RSA_TEST_MAXLINELEN, in))
-               {
-               lnum++;
-               strcpy(linebuf, olinebuf);
-               keyword = linebuf;
-               /* Skip leading space */
-               while (isspace((unsigned char)*keyword))
-                       keyword++;
-
-               /* Look for = sign */
-               p = strchr(linebuf, '=');
-
-               /* If no = or starts with [ (for [foo = bar] line) just copy */
-               if (!p || *keyword=='[')
-                       {
-                       if (fputs(olinebuf, out) < 0)
-                               goto error;
-                       continue;
-                       }
-
-               q = p - 1;
-
-               /* Remove trailing space */
-               while (isspace((unsigned char)*q))
-                       *q-- = 0;
-
-               *p = 0;
-               value = p + 1;
-
-               /* Remove leading space from value */
-               while (isspace((unsigned char)*value))
-                       value++;
-
-               /* Remove trailing space from value */
-               p = value + strlen(value) - 1;
-
-               while (*p == '\n' || isspace((unsigned char)*p))
-                       *p-- = 0;
-
-               if (!strcmp(keyword, "n"))
-                       {
-                       if (!do_hex2bn(&n,value))
-                               goto parse_error;
-                       }
-               else if (!strcmp(keyword, "e"))
-                       {
-                       if (!do_hex2bn(&e,value))
-                               goto parse_error;
-                       }
-               else if (!strcmp(keyword, "SHAAlg"))
-                       {
-                       if (!strcmp(value, "SHA1"))
-                               dgst = EVP_sha1();
-                       else if (!strcmp(value, "SHA224"))
-                               dgst = EVP_sha224();
-                       else if (!strcmp(value, "SHA256"))
-                               dgst = EVP_sha256();
-                       else if (!strcmp(value, "SHA384"))
-                               dgst = EVP_sha384();
-                       else if (!strcmp(value, "SHA512"))
-                               dgst = EVP_sha512();
-                       else
-                               {
-                               fprintf(stderr,
-                                       "FATAL: unsupported algorithm \"%s\"\n",
-                                                               value);
-                               goto parse_error;
-                               }
-                       }
-               else if (!strcmp(keyword, "Msg"))
-                       {
-                       if (Msg)
-                               goto parse_error;
-                       if (strlen(value) & 1)
-                               *(--value) = '0';
-                       Msg = hex2bin_m(value, &Msglen);
-                       if (!Msg)
-                               goto parse_error;
-                       }
-               else if (!strcmp(keyword, "S"))
-                       {
-                       if (S)
-                               goto parse_error;
-                       if (strlen(value) & 1)
-                               *(--value) = '0';
-                       S = hex2bin_m(value, &Slen);
-                       if (!S)
-                               goto parse_error;
-                       }
-               else if (!strcmp(keyword, "Result"))
-                       continue;
-               else
-                       goto parse_error;
-
-               fputs(olinebuf, out);
-
-               if (n && e && Msg && S && dgst)
-                       {
-                       if (!rsa_printver(out, n, e, dgst,
-                                       Msg, Msglen, S, Slen, Saltlen))
-                               goto error;
-                       OPENSSL_free(Msg);
-                       Msg = NULL;
-                       OPENSSL_free(S);
-                       S = NULL;
-                       }
-
-               }
-
-
-       ret = 1;
-
-
-       error:
-
-       if (olinebuf)
-               OPENSSL_free(olinebuf);
-       if (linebuf)
-               OPENSSL_free(linebuf);
-       if (n)
-               BN_free(n);
-       if (e)
-               BN_free(e);
-
-       return ret;
-
-       parse_error:
-
-       fprintf(stderr, "FATAL parse error processing line %d\n", lnum);
-
-       goto error;
-
-       }
-
-static int rsa_printver(FILE *out,
-               BIGNUM *n, BIGNUM *e,
-               const EVP_MD *dgst,
-               unsigned char *Msg, long Msglen,
-               unsigned char *S, long Slen, int Saltlen)
-       {
-       int ret = 0, r;
-       /* Setup RSA and EVP_PKEY structures */
-       RSA *rsa_pubkey = NULL;
-       EVP_PKEY pk;
-       EVP_MD_CTX ctx;
-       unsigned char *buf = NULL;
-       rsa_pubkey = FIPS_rsa_new();
-       if (!rsa_pubkey)
-               goto error;
-       rsa_pubkey->n = BN_dup(n);
-       rsa_pubkey->e = BN_dup(e);
-       if (!rsa_pubkey->n || !rsa_pubkey->e)
-               goto error;
-       pk.type = EVP_PKEY_RSA;
-       pk.pkey.rsa = rsa_pubkey;
-
-       EVP_MD_CTX_init(&ctx);
-
-       if (Saltlen >= 0)
-               {
-               M_EVP_MD_CTX_set_flags(&ctx,
-                       EVP_MD_CTX_FLAG_PAD_PSS | (Saltlen << 16));
-               }
-       else if (Saltlen == -2)
-               M_EVP_MD_CTX_set_flags(&ctx, EVP_MD_CTX_FLAG_PAD_X931);
-       if (!EVP_VerifyInit_ex(&ctx, dgst, NULL))
-               goto error;
-       if (!EVP_VerifyUpdate(&ctx, Msg, Msglen))
-               goto error;
-
-       r = EVP_VerifyFinal(&ctx, S, Slen, &pk);
-
-
-       EVP_MD_CTX_cleanup(&ctx);
-
-       if (r < 0)
-               goto error;
-       ERR_clear_error();
-
-       if (r == 0)
-               fputs("Result = F\n", out);
-       else
-               fputs("Result = P\n", out);
-
-       ret = 1;
-
-       error:
-       if (rsa_pubkey)
-               FIPS_rsa_free(rsa_pubkey);
-       if (buf)
-               OPENSSL_free(buf);
-
-       return ret;
-       }
-#endif
diff --git a/deps/openssl/openssl/fips/sha/Makefile b/deps/openssl/openssl/fips/sha/Makefile
deleted file mode 100644 (file)
index 0f8cca9..0000000
+++ /dev/null
@@ -1,162 +0,0 @@
-#
-# OpenSSL/fips/sha/Makefile
-#
-
-DIR=   sha
-TOP=   ../..
-CC=    cc
-INCLUDES=
-CFLAG=-g
-INSTALL_PREFIX=
-OPENSSLDIR=     /usr/local/ssl
-INSTALLTOP=/usr/local/ssl
-MAKEDEPPROG=   makedepend
-MAKEDEPEND=    $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
-MAKEFILE=      Makefile
-AR=            ar r
-EXE_EXT=
-
-ASFLAGS= $(INCLUDES) $(ASFLAG)
-AFLAGS= $(ASFLAGS)
-
-CFLAGS= $(INCLUDES) $(CFLAG)
-
-GENERAL=Makefile
-TEST= fips_shatest.c
-APPS=
-EXE= fips_standalone_sha1$(EXE_EXT)
-
-LIB=$(TOP)/libcrypto.a
-LIBSRC=fips_sha1_selftest.c
-LIBOBJ=fips_sha1_selftest.o
-
-SRC= $(LIBSRC) fips_standalone_sha1.c
-
-EXHEADER=
-HEADER=        
-
-ALL=    $(GENERAL) $(SRC) $(HEADER)
-
-top:
-       (cd $(TOP); $(MAKE) DIRS=fips SDIRS=$(DIR) sub_all)
-
-all:   ../fips_standalone_sha1$(EXE_EXT) lib
-
-lib:   $(LIBOBJ)
-       @echo $(LIBOBJ) > lib
-
-../fips_standalone_sha1$(EXE_EXT): fips_standalone_sha1.o
-       if [ -z "$(HOSTCC)" ] ; then \
-       FIPS_SHA_ASM=""; for i in $(SHA1_ASM_OBJ) sha1dgst.o ; do FIPS_SHA_ASM="$$FIPS_SHA_ASM ../../crypto/sha/$$i" ; done; \
-       $(CC) -o $@ $(CFLAGS) fips_standalone_sha1.o $$FIPS_SHA_ASM ; \
-       else \
-               $(HOSTCC) $(HOSTCFLAGS) -o $ $@ -I../../include -I../../crypto fips_standalone_sha1.c ../../crypto/sha/sha1dgst.c ; \
-       fi
-
-files:
-       $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
-
-links:
-       @$(PERL) $(TOP)/util/mklink.pl $(TOP)/include/openssl $(EXHEADER)
-       @$(PERL) $(TOP)/util/mklink.pl $(TOP)/test $(TEST)
-       @$(PERL) $(TOP)/util/mklink.pl $(TOP)/apps $(APPS)
-
-install:
-       @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:
-
-Q=../testvectors/sha/req
-A=../testvectors/sha/rsp
-
-VECTORS = SHA1LongMsg \
-       SHA1Monte \
-       SHA1ShortMsg \
-       SHA224LongMsg \
-       SHA224Monte \
-       SHA224ShortMsg \
-       SHA256LongMsg \
-       SHA256Monte \
-       SHA256ShortMsg \
-       SHA384LongMsg \
-       SHA384Monte \
-       SHA384ShortMsg \
-       SHA512LongMsg \
-       SHA512Monte \
-       SHA512ShortMsg
-
-fips_test:
-       -rm -rf $(A)
-       mkdir $(A)
-       for file in $(VECTORS); do \
-           if [ -f $(Q)/$$file.req ]; then \
-               $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_shatest $(Q)/$$file.req $(A)/$$file.rsp; \
-           fi; \
-       done
-
-lint:
-       lint -DLINT $(INCLUDES) $(SRC)>fluff
-
-depend:
-       $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(SRC) $(TEST)
-
-dclean:
-       $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
-       mv -f Makefile.new $(MAKEFILE)
-
-clean:
-       rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff $(EXE)
-
-# DO NOT DELETE THIS LINE -- make depend depends on it.
-
-fips_sha1_selftest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-fips_sha1_selftest.o: ../../include/openssl/crypto.h
-fips_sha1_selftest.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-fips_sha1_selftest.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
-fips_sha1_selftest.o: ../../include/openssl/lhash.h
-fips_sha1_selftest.o: ../../include/openssl/obj_mac.h
-fips_sha1_selftest.o: ../../include/openssl/objects.h
-fips_sha1_selftest.o: ../../include/openssl/opensslconf.h
-fips_sha1_selftest.o: ../../include/openssl/opensslv.h
-fips_sha1_selftest.o: ../../include/openssl/ossl_typ.h
-fips_sha1_selftest.o: ../../include/openssl/safestack.h
-fips_sha1_selftest.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-fips_sha1_selftest.o: ../../include/openssl/symhacks.h fips_sha1_selftest.c
-fips_shatest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-fips_shatest.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
-fips_shatest.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
-fips_shatest.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-fips_shatest.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
-fips_shatest.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-fips_shatest.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
-fips_shatest.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-fips_shatest.o: ../../include/openssl/opensslconf.h
-fips_shatest.o: ../../include/openssl/opensslv.h
-fips_shatest.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-fips_shatest.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-fips_shatest.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-fips_shatest.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-fips_shatest.o: ../../include/openssl/x509v3.h ../fips_utl.h fips_shatest.c
-fips_standalone_sha1.o: ../../include/openssl/asn1.h
-fips_standalone_sha1.o: ../../include/openssl/bio.h
-fips_standalone_sha1.o: ../../include/openssl/crypto.h
-fips_standalone_sha1.o: ../../include/openssl/e_os2.h
-fips_standalone_sha1.o: ../../include/openssl/evp.h
-fips_standalone_sha1.o: ../../include/openssl/fips.h
-fips_standalone_sha1.o: ../../include/openssl/hmac.h
-fips_standalone_sha1.o: ../../include/openssl/obj_mac.h
-fips_standalone_sha1.o: ../../include/openssl/objects.h
-fips_standalone_sha1.o: ../../include/openssl/opensslconf.h
-fips_standalone_sha1.o: ../../include/openssl/opensslv.h
-fips_standalone_sha1.o: ../../include/openssl/ossl_typ.h
-fips_standalone_sha1.o: ../../include/openssl/safestack.h
-fips_standalone_sha1.o: ../../include/openssl/sha.h
-fips_standalone_sha1.o: ../../include/openssl/stack.h
-fips_standalone_sha1.o: ../../include/openssl/symhacks.h fips_standalone_sha1.c
diff --git a/deps/openssl/openssl/fips/sha/fips_sha1_selftest.c b/deps/openssl/openssl/fips/sha/fips_sha1_selftest.c
deleted file mode 100644 (file)
index 4c0d463..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/* ====================================================================
- * Copyright (c) 2003 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    openssl-core@openssl.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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 <string.h>
-#include <openssl/err.h>
-#include <openssl/fips.h>
-#include <openssl/evp.h>
-#include <openssl/sha.h>
-
-#ifdef OPENSSL_FIPS
-static char test[][60]=
-    {
-    "",
-    "abc",
-    "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
-    };
-
-static const unsigned char ret[][SHA_DIGEST_LENGTH]=
-    {
-    { 0xda,0x39,0xa3,0xee,0x5e,0x6b,0x4b,0x0d,0x32,0x55,
-      0xbf,0xef,0x95,0x60,0x18,0x90,0xaf,0xd8,0x07,0x09 },
-    { 0xa9,0x99,0x3e,0x36,0x47,0x06,0x81,0x6a,0xba,0x3e,
-      0x25,0x71,0x78,0x50,0xc2,0x6c,0x9c,0xd0,0xd8,0x9d },
-    { 0x84,0x98,0x3e,0x44,0x1c,0x3b,0xd2,0x6e,0xba,0xae,
-      0x4a,0xa1,0xf9,0x51,0x29,0xe5,0xe5,0x46,0x70,0xf1 },
-    };
-
-void FIPS_corrupt_sha1()
-    {
-    test[2][0]++;
-    }
-
-int FIPS_selftest_sha1()
-    {
-    size_t n;
-
-    for(n=0 ; n<sizeof(test)/sizeof(test[0]) ; ++n)
-       {
-       unsigned char md[SHA_DIGEST_LENGTH];
-
-       EVP_Digest(test[n],strlen(test[n]),md, NULL, EVP_sha1(), NULL);
-       if(memcmp(md,ret[n],sizeof md))
-           {
-           FIPSerr(FIPS_F_FIPS_SELFTEST_SHA1,FIPS_R_SELFTEST_FAILED);
-           return 0;
-           }
-       }
-    return 1;
-    }
-
-#endif
diff --git a/deps/openssl/openssl/fips/sha/fips_shatest.c b/deps/openssl/openssl/fips/sha/fips_shatest.c
deleted file mode 100644 (file)
index ae5ecdd..0000000
+++ /dev/null
@@ -1,388 +0,0 @@
-/* fips_shatest.c */
-/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
- * project 2005.
- */
-/* ====================================================================
- * Copyright (c) 2005 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    licensing@OpenSSL.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
- * ====================================================================
- *
- * This product includes cryptographic software written by Eric Young
- * (eay@cryptsoft.com).  This product includes software written by Tim
- * Hudson (tjh@cryptsoft.com).
- *
- */
-
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-#include <openssl/bio.h>
-#include <openssl/evp.h>
-#include <openssl/err.h>
-#include <openssl/bn.h>
-#include <openssl/x509v3.h>
-
-#ifndef OPENSSL_FIPS
-
-int main(int argc, char *argv[])
-{
-    printf("No FIPS SHAXXX support\n");
-    return(0);
-}
-
-#else
-
-#include "fips_utl.h"
-
-static int dgst_test(FILE *out, FILE *in);
-static int print_dgst(const EVP_MD *md, FILE *out,
-               unsigned char *Msg, int Msglen);
-static int print_monte(const EVP_MD *md, FILE *out,
-               unsigned char *Seed, int SeedLen);
-
-int main(int argc, char **argv)
-       {
-       FILE *in = NULL, *out = NULL;
-
-       int ret = 1;
-
-       if(!FIPS_mode_set(1))
-               {
-               do_print_errors();
-               goto end;
-               }
-
-       if (argc == 1)
-               in = stdin;
-       else
-               in = fopen(argv[1], "r");
-
-       if (argc < 2)
-               out = stdout;
-       else
-               out = fopen(argv[2], "w");
-
-       if (!in)
-               {
-               fprintf(stderr, "FATAL input initialization error\n");
-               goto end;
-               }
-
-       if (!out)
-               {
-               fprintf(stderr, "FATAL output initialization error\n");
-               goto end;
-               }
-
-       if (!dgst_test(out, in))
-               {
-               fprintf(stderr, "FATAL digest file processing error\n");
-               goto end;
-               }
-       else
-               ret = 0;
-
-       end:
-
-       if (ret)
-               do_print_errors();
-
-       if (in && (in != stdin))
-               fclose(in);
-       if (out && (out != stdout))
-               fclose(out);
-
-       return ret;
-
-       }
-
-#define SHA_TEST_MAX_BITS      102400
-#define SHA_TEST_MAXLINELEN    (((SHA_TEST_MAX_BITS >> 3) * 2) + 100)
-
-int dgst_test(FILE *out, FILE *in)
-       {
-       const EVP_MD *md = NULL;
-       char *linebuf, *olinebuf, *p, *q;
-       char *keyword, *value;
-       unsigned char *Msg = NULL, *Seed = NULL;
-       long MsgLen = -1, Len = -1, SeedLen = -1;
-       int ret = 0;
-       int lnum = 0;
-
-       olinebuf = OPENSSL_malloc(SHA_TEST_MAXLINELEN);
-       linebuf = OPENSSL_malloc(SHA_TEST_MAXLINELEN);
-
-       if (!linebuf || !olinebuf)
-               goto error;
-
-
-       while (fgets(olinebuf, SHA_TEST_MAXLINELEN, in))
-               {
-               lnum++;
-               strcpy(linebuf, olinebuf);
-               keyword = linebuf;
-               /* Skip leading space */
-               while (isspace((unsigned char)*keyword))
-                       keyword++;
-
-               /* Look for = sign */
-               p = strchr(linebuf, '=');
-
-               /* If no = or starts with [ (for [L=20] line) just copy */
-               if (!p)
-                       {
-                       fputs(olinebuf, out);
-                       continue;
-                       }
-
-               q = p - 1;
-
-               /* Remove trailing space */
-               while (isspace((unsigned char)*q))
-                       *q-- = 0;
-
-               *p = 0;
-               value = p + 1;
-
-               /* Remove leading space from value */
-               while (isspace((unsigned char)*value))
-                       value++;
-
-               /* Remove trailing space from value */
-               p = value + strlen(value) - 1;
-               while (*p == '\n' || isspace((unsigned char)*p))
-                       *p-- = 0;
-
-               if (!strcmp(keyword,"[L") && *p==']')
-                       {
-                       switch (atoi(value))
-                               {
-                               case 20: md=EVP_sha1();   break;
-                               case 28: md=EVP_sha224(); break;
-                               case 32: md=EVP_sha256(); break;
-                               case 48: md=EVP_sha384(); break;
-                               case 64: md=EVP_sha512(); break;
-                               default: goto parse_error;
-                               }
-                       }
-               else if (!strcmp(keyword, "Len"))
-                       {
-                       if (Len != -1)
-                               goto parse_error;
-                       Len = atoi(value);
-                       if (Len < 0)
-                               goto parse_error;
-                       /* Only handle multiples of 8 bits */
-                       if (Len & 0x7)
-                               goto parse_error;
-                       if (Len > SHA_TEST_MAX_BITS)
-                               goto parse_error;
-                       MsgLen = Len >> 3;
-                       }
-
-               else if (!strcmp(keyword, "Msg"))
-                       {
-                       long tmplen;
-                       if (strlen(value) & 1)
-                               *(--value) = '0';
-                       if (Msg)
-                               goto parse_error;
-                       Msg = hex2bin_m(value, &tmplen);
-                       if (!Msg)
-                               goto parse_error;
-                       }
-               else if (!strcmp(keyword, "Seed"))
-                       {
-                       if (strlen(value) & 1)
-                               *(--value) = '0';
-                       if (Seed)
-                               goto parse_error;
-                       Seed = hex2bin_m(value, &SeedLen);
-                       if (!Seed)
-                               goto parse_error;
-                       }
-               else if (!strcmp(keyword, "MD"))
-                       continue;
-               else
-                       goto parse_error;
-
-               fputs(olinebuf, out);
-
-               if (md && Msg && (MsgLen >= 0))
-                       {
-                       if (!print_dgst(md, out, Msg, MsgLen))
-                               goto error;
-                       OPENSSL_free(Msg);
-                       Msg = NULL;
-                       MsgLen = -1;
-                       Len = -1;
-                       }
-               else if (md && Seed && (SeedLen > 0))
-                       {
-                       if (!print_monte(md, out, Seed, SeedLen))
-                               goto error;
-                       OPENSSL_free(Seed);
-                       Seed = NULL;
-                       SeedLen = -1;
-                       }
-       
-
-               }
-
-
-       ret = 1;
-
-
-       error:
-
-       if (olinebuf)
-               OPENSSL_free(olinebuf);
-       if (linebuf)
-               OPENSSL_free(linebuf);
-       if (Msg)
-               OPENSSL_free(Msg);
-       if (Seed)
-               OPENSSL_free(Seed);
-
-       return ret;
-
-       parse_error:
-
-       fprintf(stderr, "FATAL parse error processing line %d\n", lnum);
-
-       goto error;
-
-       }
-
-static int print_dgst(const EVP_MD *emd, FILE *out,
-               unsigned char *Msg, int Msglen)
-       {
-       int i, mdlen;
-       unsigned char md[EVP_MAX_MD_SIZE];
-       if (!EVP_Digest(Msg, Msglen, md, (unsigned int *)&mdlen, emd, NULL))
-               {
-               fputs("Error calculating HASH\n", stderr);
-               return 0;
-               }
-       fputs("MD = ", out);
-       for (i = 0; i < mdlen; i++)
-               fprintf(out, "%02x", md[i]);
-       fputs("\n", out);
-       return 1;
-       }
-
-static int print_monte(const EVP_MD *md, FILE *out,
-               unsigned char *Seed, int SeedLen)
-       {
-       unsigned int i, j, k;
-       int ret = 0;
-       EVP_MD_CTX ctx;
-       unsigned char *m1, *m2, *m3, *p;
-       unsigned int mlen, m1len, m2len, m3len;
-
-       EVP_MD_CTX_init(&ctx);
-
-       if (SeedLen > EVP_MAX_MD_SIZE)
-               mlen = SeedLen;
-       else
-               mlen = EVP_MAX_MD_SIZE;
-
-       m1 = OPENSSL_malloc(mlen);
-       m2 = OPENSSL_malloc(mlen);
-       m3 = OPENSSL_malloc(mlen);
-
-       if (!m1 || !m2 || !m3)
-               goto mc_error;
-
-       m1len = m2len = m3len = SeedLen;
-       memcpy(m1, Seed, SeedLen);
-       memcpy(m2, Seed, SeedLen);
-       memcpy(m3, Seed, SeedLen);
-
-       fputs("\n", out);
-
-       for (j = 0; j < 100; j++)
-               {
-               for (i = 0; i < 1000; i++)
-                       {
-                       EVP_DigestInit_ex(&ctx, md, NULL);
-                       EVP_DigestUpdate(&ctx, m1, m1len);
-                       EVP_DigestUpdate(&ctx, m2, m2len);
-                       EVP_DigestUpdate(&ctx, m3, m3len);
-                       p = m1;
-                       m1 = m2;
-                       m1len = m2len;
-                       m2 = m3;
-                       m2len = m3len;
-                       m3 = p;
-                       EVP_DigestFinal_ex(&ctx, m3, &m3len);
-                       }
-               fprintf(out, "COUNT = %d\n", j);
-               fputs("MD = ", out);
-               for (k = 0; k < m3len; k++)
-                       fprintf(out, "%02x", m3[k]);
-               fputs("\n\n", out);
-               memcpy(m1, m3, m3len);
-               memcpy(m2, m3, m3len);
-               m1len = m2len = m3len;
-               }
-
-       ret = 1;
-
-       mc_error:
-       if (m1)
-               OPENSSL_free(m1);
-       if (m2)
-               OPENSSL_free(m2);
-       if (m3)
-               OPENSSL_free(m3);
-
-       EVP_MD_CTX_cleanup(&ctx);
-
-       return ret;
-       }
-
-#endif
diff --git a/deps/openssl/openssl/fips/sha/fips_standalone_sha1.c b/deps/openssl/openssl/fips/sha/fips_standalone_sha1.c
deleted file mode 100644 (file)
index eec65dc..0000000
+++ /dev/null
@@ -1,173 +0,0 @@
-/* ====================================================================
- * Copyright (c) 2003 The OpenSSL 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 OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    openssl-core@openssl.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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 <string.h>
-#include <openssl/opensslconf.h>
-#include <openssl/sha.h>
-#include <openssl/hmac.h>
-
-#ifndef FIPSCANISTER_O
-int FIPS_selftest_failed() { return 0; }
-void FIPS_selftest_check() {}
-void OPENSSL_cleanse(void *p,size_t len) {}
-#endif
-
-#ifdef OPENSSL_FIPS
-
-static void hmac_init(SHA_CTX *md_ctx,SHA_CTX *o_ctx,
-                     const char *key)
-    {
-    size_t len=strlen(key);
-    int i;
-    unsigned char keymd[HMAC_MAX_MD_CBLOCK];
-    unsigned char pad[HMAC_MAX_MD_CBLOCK];
-
-    if (len > SHA_CBLOCK)
-       {
-       SHA1_Init(md_ctx);
-       SHA1_Update(md_ctx,key,len);
-       SHA1_Final(keymd,md_ctx);
-       len=20;
-       }
-    else
-       memcpy(keymd,key,len);
-    memset(&keymd[len],'\0',HMAC_MAX_MD_CBLOCK-len);
-
-    for(i=0 ; i < HMAC_MAX_MD_CBLOCK ; i++)
-       pad[i]=0x36^keymd[i];
-    SHA1_Init(md_ctx);
-    SHA1_Update(md_ctx,pad,SHA_CBLOCK);
-
-    for(i=0 ; i < HMAC_MAX_MD_CBLOCK ; i++)
-       pad[i]=0x5c^keymd[i];
-    SHA1_Init(o_ctx);
-    SHA1_Update(o_ctx,pad,SHA_CBLOCK);
-    }
-
-static void hmac_final(unsigned char *md,SHA_CTX *md_ctx,SHA_CTX *o_ctx)
-    {
-    unsigned char buf[20];
-
-    SHA1_Final(buf,md_ctx);
-    SHA1_Update(o_ctx,buf,sizeof buf);
-    SHA1_Final(md,o_ctx);
-    }
-
-#endif
-
-int main(int argc,char **argv)
-    {
-#ifdef OPENSSL_FIPS
-    static char key[]="etaonrishdlcupfm";
-    int n,binary=0;
-
-    if(argc < 2)
-       {
-       fprintf(stderr,"%s [<file>]+\n",argv[0]);
-       exit(1);
-       }
-
-    n=1;
-    if (!strcmp(argv[n],"-binary"))
-       {
-       n++;
-       binary=1;       /* emit binary fingerprint... */
-       }
-
-    for(; n < argc ; ++n)
-       {
-       FILE *f=fopen(argv[n],"rb");
-       SHA_CTX md_ctx,o_ctx;
-       unsigned char md[20];
-       int i;
-
-       if(!f)
-           {
-           perror(argv[n]);
-           exit(2);
-           }
-
-       hmac_init(&md_ctx,&o_ctx,key);
-       for( ; ; )
-           {
-           char buf[1024];
-           size_t l=fread(buf,1,sizeof buf,f);
-
-           if(l == 0)
-               {
-               if(ferror(f))
-                   {
-                   perror(argv[n]);
-                   exit(3);
-                   }
-               else
-                   break;
-               }
-           SHA1_Update(&md_ctx,buf,l);
-           }
-       hmac_final(md,&md_ctx,&o_ctx);
-
-       if (binary)
-           {
-           fwrite(md,20,1,stdout);
-           break;      /* ... for single(!) file */
-           }
-
-       printf("HMAC-SHA1(%s)= ",argv[n]);
-       for(i=0 ; i < 20 ; ++i)
-           printf("%02x",md[i]);
-       printf("\n");
-       }
-#endif
-    return 0;
-    }
-
-
diff --git a/deps/openssl/openssl/include/openssl/camellia.h b/deps/openssl/openssl/include/openssl/camellia.h
new file mode 100644 (file)
index 0000000..5a0a141
--- /dev/null
@@ -0,0 +1 @@
+#include "../../crypto/camellia/camellia.h"
diff --git a/deps/openssl/openssl/include/openssl/cms.h b/deps/openssl/openssl/include/openssl/cms.h
new file mode 100644 (file)
index 0000000..8687c7f
--- /dev/null
@@ -0,0 +1 @@
+#include "../../crypto/cms/cms.h"
diff --git a/deps/openssl/openssl/include/openssl/fips.h b/deps/openssl/openssl/include/openssl/fips.h
deleted file mode 100644 (file)
index b5931d3..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#include "../../fips/fips.h"
diff --git a/deps/openssl/openssl/include/openssl/fips_rand.h b/deps/openssl/openssl/include/openssl/fips_rand.h
deleted file mode 100644 (file)
index c971f6e..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#include "../../fips/rand/fips_rand.h"
diff --git a/deps/openssl/openssl/include/openssl/mdc2.h b/deps/openssl/openssl/include/openssl/mdc2.h
new file mode 100644 (file)
index 0000000..ac284a1
--- /dev/null
@@ -0,0 +1 @@
+#include "../../crypto/mdc2/mdc2.h"
diff --git a/deps/openssl/openssl/include/openssl/modes.h b/deps/openssl/openssl/include/openssl/modes.h
new file mode 100644 (file)
index 0000000..f57fcfe
--- /dev/null
@@ -0,0 +1 @@
+#include "../../crypto/modes/modes.h"
diff --git a/deps/openssl/openssl/include/openssl/pq_compat.h b/deps/openssl/openssl/include/openssl/pq_compat.h
deleted file mode 100644 (file)
index 8185d15..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#include "../../crypto/pqueue/pq_compat.h"
diff --git a/deps/openssl/openssl/include/openssl/seed.h b/deps/openssl/openssl/include/openssl/seed.h
new file mode 100644 (file)
index 0000000..bbbf596
--- /dev/null
@@ -0,0 +1 @@
+#include "../../crypto/seed/seed.h"
diff --git a/deps/openssl/openssl/include/openssl/tmdiff.h b/deps/openssl/openssl/include/openssl/tmdiff.h
deleted file mode 100644 (file)
index 568d8ed..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#include "../../crypto/tmdiff.h"
diff --git a/deps/openssl/openssl/include/openssl/ts.h b/deps/openssl/openssl/include/openssl/ts.h
new file mode 100644 (file)
index 0000000..fe8a2cb
--- /dev/null
@@ -0,0 +1 @@
+#include "../../crypto/ts/ts.h"
diff --git a/deps/openssl/openssl/include/openssl/whrlpool.h b/deps/openssl/openssl/include/openssl/whrlpool.h
new file mode 100644 (file)
index 0000000..e2424fa
--- /dev/null
@@ -0,0 +1 @@
+#include "../../crypto/whrlpool/whrlpool.h"
index d15c23a..6a0ea2d 100644 (file)
@@ -3,99 +3,134 @@ $!
 $! Author: Richard Levitte <richard@levitte.org>
 $! Time of creation: 22-MAY-1998 10:13
 $!
-$! P1  root of the directory tree
-$!
-$      DEF_ORIG = F$ENVIRONMENT( "DEFAULT")
-$      ON ERROR THEN GOTO TIDY
-$      ON CONTROL_C THEN GOTO TIDY
-$
-$      IF P1 .EQS. ""
-$      THEN
-$          WRITE SYS$OUTPUT "First argument missing."
-$          WRITE SYS$OUTPUT -
-                 "It Should be the directory where you want things installed."
-$          EXIT
-$      ENDIF
-$
-$      IF (F$GETSYI("CPU").LT.128)
-$      THEN
-$          ARCH := VAX
-$      ELSE
-$          ARCH = F$EDIT( F$GETSYI( "ARCH_NAME"), "UPCASE")
-$          IF (ARCH .EQS. "") THEN ARCH = "UNK"
-$      ENDIF
-$
-$      ROOT = F$PARSE(P1,"[]A.;0",,,"SYNTAX_ONLY,NO_CONCEAL") - "A.;0"
-$      ROOT_DEV = F$PARSE(ROOT,,,"DEVICE","SYNTAX_ONLY")
-$      ROOT_DIR = F$PARSE(ROOT,,,"DIRECTORY","SYNTAX_ONLY") -
+$! P1  root of the directory tree
+$! P2  "64" for 64-bit pointers.
+$!
+$!
+$! Announce/identify.
+$!
+$ proc = f$environment( "procedure")
+$ write sys$output "@@@ "+ -
+   f$parse( proc, , , "name")+ f$parse( proc, , , "type")
+$!
+$ def_orig = f$environment( "default")
+$ on error then goto tidy
+$ on control_c then goto tidy
+$!
+$ if (p1 .eqs. "")
+$ then
+$   write sys$output "First argument missing."
+$   write sys$output -
+     "It should be the directory where you want things installed."
+$   exit
+$ endif
+$!
+$ if (f$getsyi("cpu") .lt. 128)
+$ then
+$   arch = "VAX"
+$ else
+$   arch = f$edit( f$getsyi( "arch_name"), "upcase")
+$   if (arch .eqs. "") then arch = "UNK"
+$ endif
+$!
+$ archd = arch
+$!
+$ if (p2 .nes. "")
+$ then
+$   if (p2 .eqs. "64")
+$   then
+$     archd = arch+ "_64"
+$   else
+$     if (p2 .nes. "32")
+$     then
+$       write sys$output "Second argument invalid."
+$       write sys$output "It should be "32", "64", or nothing."
+$       exit
+$     endif
+$   endif
+$ endif
+$!
+$ root = f$parse( p1, "[]A.;0", , , "syntax_only, no_conceal") - "A.;0"
+$ root_dev = f$parse( root, , , "device", "syntax_only")
+$ root_dir = f$parse( root, , , "directory", "syntax_only") -
                   - ".][000000" - "[000000." - "][" - "[" - "]"
-$      ROOT = ROOT_DEV + "[" + ROOT_DIR
-$
-$      DEFINE/NOLOG WRK_SSLROOT 'ROOT'.] /TRANS=CONC
-$      DEFINE/NOLOG WRK_SSLXLIB WRK_SSLROOT:['ARCH'_LIB]
-$      DEFINE/NOLOG WRK_SSLLIB WRK_SSLROOT:[LIB]
-$      DEFINE/NOLOG WRK_SSLINCLUDE WRK_SSLROOT:[INCLUDE]
-$      DEFINE/NOLOG WRK_SSLXEXE WRK_SSLROOT:['ARCH'_EXE]
-$      DEFINE/NOLOG WRK_SSLCERTS WRK_SSLROOT:[CERTS]
-$      DEFINE/NOLOG WRK_SSLPRIVATE WRK_SSLROOT:[PRIVATE]
-$
+$ root = root_dev + "[" + root_dir
+$!
+$ define /nolog wrk_sslroot 'root'.] /trans=conc
+$ define /nolog wrk_sslcerts wrk_sslroot:[certs]
+$ define /nolog wrk_sslinclude wrk_sslroot:[include]
+$ define /nolog wrk_ssllib wrk_sslroot:[lib]
+$ define /nolog wrk_sslprivate wrk_sslroot:[private]
+$ define /nolog wrk_sslxexe wrk_sslroot:['archd'_exe]
+$ define /nolog wrk_sslxlib wrk_sslroot:['arch'_lib]
 $!
 $! Exhibit the destination directory.
 $!
-$      WRITE SYS$OUTPUT "   Installing to (WRK_SSLROOT) ="
-$      WRITE SYS$OUTPUT "    ''f$trnlnm( "WRK_SSLROOT")'"
-$      WRITE SYS$OUTPUT ""
-$
-$      IF F$PARSE("WRK_SSLROOT:[000000]") .EQS. "" THEN -
-          CREATE/DIR/LOG WRK_SSLROOT:[000000]
-$      IF F$PARSE("WRK_SSLXEXE:") .EQS. "" THEN -
-          CREATE/DIR/LOG WRK_SSLXEXE:
-$      IF F$PARSE("WRK_SSLXLIB:") .EQS. "" THEN -
-          CREATE/DIR/LOG WRK_SSLXLIB:
-$      IF F$PARSE("WRK_SSLLIB:") .EQS. "" THEN -
-          CREATE/DIR/LOG WRK_SSLLIB:
-$      IF F$PARSE("WRK_SSLINCLUDE:") .EQS. "" THEN -
-          CREATE/DIR/LOG WRK_SSLINCLUDE:
-$      IF F$PARSE("WRK_SSLCERTS:") .EQS. "" THEN -
-          CREATE/DIR/LOG WRK_SSLCERTS:
-$      IF F$PARSE("WRK_SSLPRIVATE:") .EQS. "" THEN -
-          CREATE/DIR/LOG WRK_SSLPRIVATE:
-$      IF F$PARSE("WRK_SSLROOT:[VMS]") .EQS. "" THEN -
-          CREATE/DIR/LOG WRK_SSLROOT:[VMS]
-$
-$      SDIRS := CRYPTO,SSL,APPS,VMS!,RSAREF,TEST,TOOLS
-$      EXHEADER := e_os2.h
-$
-$      COPY 'EXHEADER' WRK_SSLINCLUDE: /LOG
-$      SET FILE/PROT=WORLD:RE WRK_SSLINCLUDE:'EXHEADER'
-$
-$      I = 0
-$ LOOP_SDIRS: 
-$      D = F$ELEMENT(I, ",", SDIRS)
-$      I = I + 1
-$      IF D .EQS. "," THEN GOTO LOOP_SDIRS_END
-$      WRITE SYS$OUTPUT "Installing ",D," files."
-$      SET DEFAULT [.'D']
-$      @INSTALL 'ROOT']
-$      SET DEFAULT [-]
-$      GOTO LOOP_SDIRS
-$ LOOP_SDIRS_END:
-$
-$      WRITE SYS$OUTPUT ""
-$      WRITE SYS$OUTPUT "      Installation done!"
-$      WRITE SYS$OUTPUT ""
-$      WRITE SYS$OUTPUT "      You might want to purge ",ROOT,"...]"
-$      WRITE SYS$OUTPUT ""
-$
-$ TIDY:
-$      SET DEFAULT 'DEF_ORIG'
-$
-$      DEASSIGN WRK_SSLROOT
-$      DEASSIGN WRK_SSLXLIB
-$      DEASSIGN WRK_SSLLIB
-$      DEASSIGN WRK_SSLINCLUDE
-$      DEASSIGN WRK_SSLXEXE
-$      DEASSIGN WRK_SSLCERTS
-$      DEASSIGN WRK_SSLPRIVATE
-$
-$      EXIT
+$ write sys$output "   Installing to (WRK_SSLROOT) ="
+$ write sys$output "    ''f$trnlnm( "wrk_sslroot")'"
+$ write sys$output ""
+$!
+$ if f$parse("wrk_sslroot:[000000]") .eqs. "" then -
+   create /directory /log wrk_sslroot:[000000]
+$ if f$parse("wrk_sslxexe:") .eqs. "" then -
+   create /directory /log wrk_sslxexe:
+$ if f$parse("wrk_sslxlib:") .eqs. "" then -
+   create /directory /log wrk_sslxlib:
+$ if f$parse("wrk_ssllib:") .eqs. "" then -
+   create /directory /log wrk_ssllib:
+$ if f$parse("wrk_sslinclude:") .eqs. "" then -
+   create /directory /log wrk_sslinclude:
+$ if f$parse("wrk_sslcerts:") .eqs. "" then -
+   create /directory /log wrk_sslcerts:
+$ if f$parse("wrk_sslprivate:") .eqs. "" then -
+   create /directory /log wrk_sslprivate:
+$ if f$parse("wrk_sslroot:[VMS]") .EQS. "" THEN -
+   create /directory /log wrk_sslroot:[VMS]
+$!
+$ sdirs := CRYPTO, SSL, APPS, VMS !!!, RSAREF, TEST, TOOLS
+$ exheader := e_os2.h
+$!
+$ copy /protection = w:re 'exheader' wrk_sslinclude: /log
+$!
+$ i = 0
+$ loop_sdirs: 
+$   d = f$edit( f$element(i, ",", sdirs), "trim")
+$   i = i + 1
+$   if d .eqs. "," then goto loop_sdirs_end
+$   write sys$output "Installing ", d, " files."
+$   set default [.'d']
+$   @ install-'d'.com 'root'] 'p2'
+$   set default 'def_orig'
+$ goto loop_sdirs
+$ loop_sdirs_end:
+$!
+$ write sys$output ""
+$ write sys$output "   Installation done!"
+$ write sys$output ""
+$ if (f$search( root+ "...]*.*;-1") .nes. "")
+$ then
+$   write sys$output " You might want to purge ", root, "...]"
+$   write sys$output ""
+$ endif
+$!
+$ tidy:
+$!
+$ set default 'def_orig'
+$!
+$ call deass wrk_sslroot
+$ call deass wrk_sslcerts
+$ call deass wrk_sslinclude
+$ call deass wrk_ssllib
+$ call deass wrk_sslprivate
+$ call deass wrk_sslxexe
+$ call deass wrk_sslxlib
+$!
+$ exit
+$!
+$ deass: subroutine
+$ if (f$trnlnm( p1, "LNM$PROCESS") .nes. "")
+$ then
+$   deassign /process 'p1'
+$ endif
+$ endsubroutine
+$!
index 04d559f..eb22f20 100755 (executable)
@@ -15,11 +15,11 @@ $! The "xxx" denotes the machine architecture of ALPHA, IA64 or VAX.
 $!
 $! This procedures accepts two command line options listed below.
 $!
-$! Specify one of the following build options for P1.
+$! P1 specifies one of the following build options:
 $!
 $!      ALL       Just build "everything".
-$!      CONFIG    Just build the "[.CRYPTO._<ARCH>]OPENSSLCONF.H" file.
-$!      BUILDINF  Just build the "[.CRYPTO._<ARCH>]BUILDINF.H" file.
+$!      CONFIG    Just build the "[.CRYPTO._xxx]OPENSSLCONF.H" file.
+$!      BUILDINF  Just build the "[.CRYPTO._xxx]BUILDINF.H" file.
 $!      SOFTLINKS Just fix the Unix soft links.
 $!      BUILDALL  Same as ALL, except CONFIG, BUILDINF and SOFTILNKS aren't done.
 $!      CRYPTO    Just build the "[.xxx.EXE.CRYPTO]LIBCRYPTO.OLB" library.
@@ -31,14 +31,21 @@ $!      TEST      Just build the "[.xxx.EXE.TEST]" test programs for OpenSSL.
 $!      APPS      Just build the "[.xxx.EXE.APPS]" application programs for OpenSSL.
 $!      ENGINES   Just build the "[.xxx.EXE.ENGINES]" application programs for OpenSSL.
 $!
+$! P2, if defined, specifies the C pointer size.  Ignored on VAX.
+$!      ("64=ARGV" gives more efficient code with HP C V7.3 or newer.)
+$!      Supported values are:
 $!
-$! P2 is ignored (it was used to denote if RSAref should be used or not,
-$! and is simply kept so surrounding scripts don't get confused)
+$!      ""       Compile with default (/NOPOINTER_SIZE).
+$!      32       Compile with /POINTER_SIZE=32 (SHORT).
+$!      64       Compile with /POINTER_SIZE=64[=ARGV] (LONG[=ARGV]).
+$!               (Automatically select ARGV if compiler supports it.)
+$!      64=      Compile with /POINTER_SIZE=64 (LONG).
+$!      64=ARGV  Compile with /POINTER_SIZE=64=ARGV (LONG=ARGV).
 $!
-$! Speficy DEBUG or NODEBUG as P3 to compile with or without debugging
-$! information.
+$! P3 specifies DEBUG or NODEBUG, to compile with or without debugging
+$!    information.
 $!
-$! Specify which compiler at P4 to try to compile under.
+$! P4 specifies which compiler to try to compile under.
 $!
 $!       VAXC   For VAX C.
 $!       DECC   For DEC C.
@@ -46,7 +53,7 @@ $!      GNUC   For GNU C.
 $!       LINK   To only link the programs from existing object files.
 $!               (not yet implemented)
 $!
-$! If you don't speficy a compiler, it will try to determine which
+$! If you don't specify a compiler, it will try to determine which
 $! "C" compiler to use.
 $!
 $! P5, if defined, sets a TCP/IP library to use, through one of the following
@@ -60,8 +67,18 @@ $!   NONE            to avoid specifying which TCP/IP implementation to
 $!                     use at build time (this works with DEC C).  This is
 $!                     the default.
 $!
-$! P6, if defined, sets a compiler thread NOT needed on OpenVMS 7.1 (and up)
+$! P6, if defined, sets a compiler thread NOT needed on OpenVMS 7.1 (and up).
 $!
+$! P7, if defined, specifies a directory where ZLIB files (zlib.h,
+$! libz.olb) may be found.  Optionally, a non-default object library
+$! name may be included ("dev:[dir]libz_64.olb", for example).
+$!
+$!
+$! Announce/identify.
+$!
+$ proc = f$environment( "procedure")
+$ write sys$output "@@@ "+ -
+   f$parse( proc, , , "name")+ f$parse( proc, , , "type")
 $!
 $ DEF_ORIG = F$ENVIRONMENT( "DEFAULT")
 $ ON ERROR THEN GOTO TIDY
@@ -84,7 +101,7 @@ $ THEN
 $!
 $!  The Architecture Is VAX.
 $!
-$   ARCH := VAX
+$   ARCH = "VAX"
 $!
 $! Else...
 $!
@@ -99,6 +116,14 @@ $! End The Architecture Check.
 $!
 $ ENDIF
 $!
+$ ARCHD = ARCH
+$ LIB32 = "32"
+$ POINTER_SIZE = ""
+$!
+$! Get VMS version.
+$!
+$ VMS_VERSION = f$edit( f$getsyi( "VERSION"), "TRIM")
+$!
 $! Check To Make Sure We Have Valid Command Line Parameters.
 $!
 $ GOSUB CHECK_OPTIONS
@@ -163,32 +188,53 @@ $! Time To EXIT.
 $!
 $ GOTO TIDY
 $!
-$! Rebuild The "[.CRYPTO._''ARCH']OPENSSLCONF.H" file.
+$! Rebuild The [.CRYPTO._xxx]OPENSSLCONF.H" file.
 $!
 $ CONFIG:
 $!
-$! Tell The User We Are Creating The [.CRYPTO._<ARCH>]OPENSSLCONF.H File.
+$! Tell The User We Are Creating The [.CRYPTO._xxx]OPENSSLCONF.H File.
 $!
-$ WRITE SYS$OUTPUT "Creating [.CRYPTO._''ARCH']OPENSSLCONF.H Include File."
+$ WRITE SYS$OUTPUT "Creating [.CRYPTO.''ARCHD']OPENSSLCONF.H Include File."
 $!
 $! First, make sure the directory exists.
 $!
-$ IF F$PARSE("SYS$DISK:[.CRYPTO._''ARCH']") .EQS. "" THEN -
-     CREATE/DIRECTORY SYS$DISK:[.CRYPTO._'ARCH']
+$ IF F$PARSE("SYS$DISK:[.CRYPTO.''ARCHD']") .EQS. "" THEN -
+     CREATE/DIRECTORY SYS$DISK:[.CRYPTO.'ARCHD']
+$!
+$! Different tar/UnZip versions/option may have named the file differently
+$ IF F$SEARCH("[.crypto]opensslconf.h_in") .NES. ""
+$ THEN
+$   OPENSSLCONF_H_IN = "[.crypto]opensslconf.h_in"
+$ ELSE
+$   IF F$SEARCH( "[.crypto]opensslconf_h.in") .NES. ""
+$   THEN
+$     OPENSSLCONF_H_IN = "[.crypto]opensslconf_h.in"
+$   ELSE
+$     ! For ODS-5
+$     IF F$SEARCH( "[.crypto]opensslconf.h.in") .NES. ""
+$     THEN
+$       OPENSSLCONF_H_IN = "[.crypto]opensslconf.h.in"
+$     ELSE
+$       WRITE SYS$ERROR "Couldn't find a [.crypto]opensslconf.h.in.  Exiting!"
+$       $STATUS = %X00018294 ! "%RMS-F-FNF, file not found".
+$       GOTO TIDY
+$     ENDIF
+$   ENDIF
+$ ENDIF
 $!
-$! Create The [.CRYPTO._<ARCH>]OPENSSLCONF.H File.
+$! Create The [.CRYPTO._xxx]OPENSSLCONF.H File.
 $! Make sure it has the right format.
 $!
-$ OSCH_NAME = "SYS$DISK:[.CRYPTO._''ARCH']OPENSSLCONF.H"
+$ OSCH_NAME = "SYS$DISK:[.CRYPTO.''ARCHD']OPENSSLCONF.H"
 $ CREATE /FDL=SYS$INPUT: 'OSCH_NAME'
 RECORD
         FORMAT stream_lf
 $ OPEN /APPEND H_FILE 'OSCH_NAME'
 $!
-$! Write The [.CRYPTO._<ARCH>]OPENSSLCONF.H File.
+$! Write The [.CRYPTO._xxx]OPENSSLCONF.H File.
 $!
 $ WRITE H_FILE "/* This file was automatically built using makevms.com */"
-$ WRITE H_FILE "/* and [.CRYPTO._''ARCH']OPENSSLCONF.H_IN */"
+$ WRITE H_FILE "/* and ''OPENSSLCONF_H_IN' */"
 $!
 $! Write a few macros that indicate how this system was built.
 $!
@@ -196,79 +242,272 @@ $ WRITE H_FILE ""
 $ WRITE H_FILE "#ifndef OPENSSL_SYS_VMS"
 $ WRITE H_FILE "# define OPENSSL_SYS_VMS"
 $ WRITE H_FILE "#endif"
-$ CONFIG_LOGICALS := NO_ASM,NO_RSA,NO_DSA,NO_DH,NO_MD2,NO_MD5,NO_RIPEMD,-
-       NO_SHA,NO_SHA0,NO_SHA1,NO_DES/NO_MDC2;NO_MDC2,NO_RC2,NO_RC4,NO_RC5,-
-       NO_IDEA,NO_BF,NO_CAST,NO_CAMELLIA,NO_SEED,NO_HMAC,NO_SSL2
+$
+$! One of the best way to figure out what the list should be is to do
+$! the following on a Unix system:
+$!   grep OPENSSL_NO_ crypto/*/*.h ssl/*.h engines/*.h engines/*/*.h|grep ':# *if'|sed -e 's/^.*def //'|sort|uniq
+$! For that reason, the list will also always end up in alphabetical order
+$ CONFIG_LOGICALS := AES,-
+                    ASM,INLINE_ASM,-
+                    BF,-
+                    BIO,-
+                    BUFFER,-
+                    BUF_FREELISTS,-
+                    CAMELLIA,-
+                    CAST,-
+                    CMS,-
+                    COMP,-
+                    DEPRECATED,-
+                    DES,-
+                    DGRAM,-
+                    DH,-
+                    DSA,-
+                    EC,-
+                    ECDH,-
+                    ECDSA,-
+                    ENGINE,-
+                    ERR,-
+                    EVP,-
+                    FP_API,-
+                    GMP,-
+                    GOST,-
+                    HASH_COMP,-
+                    HMAC,-
+                    IDEA,-
+                    JPAKE,-
+                    KRB5,-
+                    LHASH,-
+                    MD2,-
+                    MD4,-
+                    MD5,-
+                    MDC2,-
+                    OCSP,-
+                    PSK,-
+                    RC2,-
+                    RC4,-
+                    RC5,-
+                    RFC3779,-
+                    RIPEMD,-
+                    RSA,-
+                    SEED,-
+                    SHA,-
+                    SHA0,-
+                    SHA1,-
+                    SHA256,-
+                    SHA512,-
+                    SOCK,-
+                    SSL2,-
+                    STACK,-
+                    STATIC_ENGINE,-
+                    STDIO,-
+                    STORE,-
+                    TLSEXT,-
+                    WHIRLPOOL,-
+                    X509
+$! Add a few that we know about
+$ CONFIG_LOGICALS := 'CONFIG_LOGICALS',-
+                    THREADS
+$! The following rules, which dictate how some algorithm choices affect
+$! others, are picked from Configure.
+$! Quick syntax:
+$!  list = item[ ; list]
+$!  item = algos / dependents
+$!  algos = algo [, algos]
+$!  dependents = dependent [, dependents]
+$! When a list of algos is specified in one item, it means that they must
+$! all be disabled for the rule to apply.
+$! When a list of dependents is specified in one item, it means that they
+$! will all be disabled if the rule applies.
+$! Rules are checked sequentially.  If a rule disables an algorithm, it will
+$! affect all following rules that depend on that algorithm being disabled.
+$! To force something to be enabled or disabled, have no algorithms in the
+$! algos part.
+$ CONFIG_DISABLE_RULES := RIJNDAEL/AES;-
+                         DES/MDC2;-
+                         EC/ECDSA,ECDH;-
+                         MD5/SSL2,SSL3,TLS1;-
+                         SHA/SSL3,TLS1;-
+                         RSA/SSL2;-
+                         RSA,DSA/SSL2;-
+                         DH/SSL3,TLS1;-
+                         TLS1/TLSEXT;-
+                         EC/GOST;-
+                         DSA/GOST;-
+                         DH/GOST;-
+                         /STATIC_ENGINE;-
+                         /KRB5
+$ CONFIG_ENABLE_RULES := ZLIB_DYNAMIC/ZLIB;-
+                        /THREADS
+$
+$! Architecture specific rule addtions
+$ IF ARCH .EQS. "VAX"
+$ THEN
+$   ! Disable algorithms that require 64-bit integers in C
+$   CONFIG_DISABLE_RULES = CONFIG_DISABLE_RULES + -
+                          ";/GOST" + -
+                          ";/WHIRLPOOL"
+$ ENDIF
+$
 $ CONFIG_LOG_I = 0
-$ CONFIG_LOG_LOOP:
-$   CONFIG_LOG_E1 = F$ELEMENT(CONFIG_LOG_I,",",CONFIG_LOGICALS)
+$ CONFIG_LOG_LOOP1:
+$   CONFIG_LOG_E = F$EDIT(F$ELEMENT(CONFIG_LOG_I,",",CONFIG_LOGICALS),"TRIM")
 $   CONFIG_LOG_I = CONFIG_LOG_I + 1
-$   IF CONFIG_LOG_E1 .EQS. "" THEN GOTO CONFIG_LOG_LOOP
-$   IF CONFIG_LOG_E1 .EQS. "," THEN GOTO CONFIG_LOG_LOOP_END
-$   CONFIG_LOG_E2 = F$EDIT(CONFIG_LOG_E1,"TRIM")
-$   CONFIG_LOG_E1 = F$ELEMENT(0,";",CONFIG_LOG_E2)
-$   CONFIG_LOG_E2 = F$ELEMENT(1,";",CONFIG_LOG_E2)
-$   CONFIG_LOG_E0 = F$ELEMENT(0,"/",CONFIG_LOG_E1)
-$   CONFIG_LOG_E1 = F$ELEMENT(1,"/",CONFIG_LOG_E1)
-$   IF F$TRNLNM("OPENSSL_"+CONFIG_LOG_E0)
+$   IF CONFIG_LOG_E .EQS. "" THEN GOTO CONFIG_LOG_LOOP1
+$   IF CONFIG_LOG_E .EQS. "," THEN GOTO CONFIG_LOG_LOOP1_END
+$   IF F$TRNLNM("OPENSSL_NO_"+CONFIG_LOG_E)
 $   THEN
-$     WRITE H_FILE "#ifndef OPENSSL_",CONFIG_LOG_E0
-$     WRITE H_FILE "# define OPENSSL_",CONFIG_LOG_E0
-$     WRITE H_FILE "#endif"
-$     IF CONFIG_LOG_E1 .NES. "/"
+$       CONFIG_DISABLED_'CONFIG_LOG_E' := YES
+$       CONFIG_ENABLED_'CONFIG_LOG_E' := NO
+$      CONFIG_CHANGED_'CONFIG_LOG_E' := YES
+$   ELSE
+$       CONFIG_DISABLED_'CONFIG_LOG_E' := NO
+$       CONFIG_ENABLED_'CONFIG_LOG_E' := YES
+$      ! Because all algorithms are assumed enabled by default
+$      CONFIG_CHANGED_'CONFIG_LOG_E' := NO
+$   ENDIF
+$   GOTO CONFIG_LOG_LOOP1
+$ CONFIG_LOG_LOOP1_END:
+$
+$! Apply cascading disable rules
+$ CONFIG_DISABLE_I = 0
+$ CONFIG_DISABLE_LOOP0:
+$   CONFIG_DISABLE_E = F$EDIT(F$ELEMENT(CONFIG_DISABLE_I,";", -
+     CONFIG_DISABLE_RULES),"TRIM")
+$   CONFIG_DISABLE_I = CONFIG_DISABLE_I + 1
+$   IF CONFIG_DISABLE_E .EQS. "" THEN GOTO CONFIG_DISABLE_LOOP0
+$   IF CONFIG_DISABLE_E .EQS. ";" THEN GOTO CONFIG_DISABLE_LOOP0_END
+$
+$   CONFIG_DISABLE_ALGOS = F$EDIT(F$ELEMENT(0,"/",CONFIG_DISABLE_E),"TRIM")
+$   CONFIG_DISABLE_DEPENDENTS = F$EDIT(F$ELEMENT(1,"/",CONFIG_DISABLE_E),"TRIM")
+$   TO_DISABLE := YES
+$   CONFIG_ALGO_I = 0
+$   CONFIG_DISABLE_LOOP1:
+$     CONFIG_ALGO_E = F$EDIT(F$ELEMENT(CONFIG_ALGO_I,",", -
+       CONFIG_DISABLE_ALGOS),"TRIM")
+$     CONFIG_ALGO_I = CONFIG_ALGO_I + 1
+$     IF CONFIG_ALGO_E .EQS. "" THEN GOTO CONFIG_DISABLE_LOOP1
+$     IF CONFIG_ALGO_E .EQS. "," THEN GOTO CONFIG_DISABLE_LOOP1_END
+$     IF F$TYPE(CONFIG_DISABLED_'CONFIG_ALGO_E') .EQS. ""
 $     THEN
-$       WRITE H_FILE "#ifndef OPENSSL_",CONFIG_LOG_E1
-$       WRITE H_FILE "# define OPENSSL_",CONFIG_LOG_E1
-$       WRITE H_FILE "#endif"
+$      TO_DISABLE := NO
+$     ELSE
+$      IF .NOT. CONFIG_DISABLED_'CONFIG_ALGO_E' THEN TO_DISABLE := NO
 $     ENDIF
-$   ELSE
-$     IF CONFIG_LOG_E2 .NES. ";"
+$     GOTO CONFIG_DISABLE_LOOP1
+$   CONFIG_DISABLE_LOOP1_END:
+$
+$   IF TO_DISABLE
+$   THEN
+$     CONFIG_DEPENDENT_I = 0
+$     CONFIG_DISABLE_LOOP2:
+$      CONFIG_DEPENDENT_E = F$EDIT(F$ELEMENT(CONFIG_DEPENDENT_I,",", -
+         CONFIG_DISABLE_DEPENDENTS),"TRIM")
+$      CONFIG_DEPENDENT_I = CONFIG_DEPENDENT_I + 1
+$      IF CONFIG_DEPENDENT_E .EQS. "" THEN GOTO CONFIG_DISABLE_LOOP2
+$      IF CONFIG_DEPENDENT_E .EQS. "," THEN GOTO CONFIG_DISABLE_LOOP2_END
+$       CONFIG_DISABLED_'CONFIG_DEPENDENT_E' := YES
+$       CONFIG_ENABLED_'CONFIG_DEPENDENT_E' := NO
+$      ! Better not to assume defaults at this point...
+$      CONFIG_CHANGED_'CONFIG_DEPENDENT_E' := YES
+$      WRITE SYS$ERROR -
+         "''CONFIG_DEPENDENT_E' disabled by rule ''CONFIG_DISABLE_E'"
+$      GOTO CONFIG_DISABLE_LOOP2
+$     CONFIG_DISABLE_LOOP2_END:
+$   ENDIF
+$   GOTO CONFIG_DISABLE_LOOP0
+$ CONFIG_DISABLE_LOOP0_END:
+$      
+$! Apply cascading enable rules
+$ CONFIG_ENABLE_I = 0
+$ CONFIG_ENABLE_LOOP0:
+$   CONFIG_ENABLE_E = F$EDIT(F$ELEMENT(CONFIG_ENABLE_I,";", -
+     CONFIG_ENABLE_RULES),"TRIM")
+$   CONFIG_ENABLE_I = CONFIG_ENABLE_I + 1
+$   IF CONFIG_ENABLE_E .EQS. "" THEN GOTO CONFIG_ENABLE_LOOP0
+$   IF CONFIG_ENABLE_E .EQS. ";" THEN GOTO CONFIG_ENABLE_LOOP0_END
+$
+$   CONFIG_ENABLE_ALGOS = F$EDIT(F$ELEMENT(0,"/",CONFIG_ENABLE_E),"TRIM")
+$   CONFIG_ENABLE_DEPENDENTS = F$EDIT(F$ELEMENT(1,"/",CONFIG_ENABLE_E),"TRIM")
+$   TO_ENABLE := YES
+$   CONFIG_ALGO_I = 0
+$   CONFIG_ENABLE_LOOP1:
+$     CONFIG_ALGO_E = F$EDIT(F$ELEMENT(CONFIG_ALGO_I,",", -
+       CONFIG_ENABLE_ALGOS),"TRIM")
+$     CONFIG_ALGO_I = CONFIG_ALGO_I + 1
+$     IF CONFIG_ALGO_E .EQS. "" THEN GOTO CONFIG_ENABLE_LOOP1
+$     IF CONFIG_ALGO_E .EQS. "," THEN GOTO CONFIG_ENABLE_LOOP1_END
+$     IF F$TYPE(CONFIG_ENABLED_'CONFIG_ALGO_E') .EQS. ""
 $     THEN
-$       IF F$TRNLNM("OPENSSL_"+CONFIG_LOG_E2)
-$       THEN
-$         WRITE H_FILE "#ifndef OPENSSL_",CONFIG_LOG_E2
-$         WRITE H_FILE "# define OPENSSL_",CONFIG_LOG_E2
-$         WRITE H_FILE "#endif"
-$       ENDIF
+$      TO_ENABLE := NO
+$     ELSE
+$      IF .NOT. CONFIG_ENABLED_'CONFIG_ALGO_E' THEN TO_ENABLE := NO
 $     ENDIF
+$     GOTO CONFIG_ENABLE_LOOP1
+$   CONFIG_ENABLE_LOOP1_END:
+$
+$   IF TO_ENABLE
+$   THEN
+$     CONFIG_DEPENDENT_I = 0
+$     CONFIG_ENABLE_LOOP2:
+$      CONFIG_DEPENDENT_E = F$EDIT(F$ELEMENT(CONFIG_DEPENDENT_I,",", -
+         CONFIG_ENABLE_DEPENDENTS),"TRIM")
+$      CONFIG_DEPENDENT_I = CONFIG_DEPENDENT_I + 1
+$      IF CONFIG_DEPENDENT_E .EQS. "" THEN GOTO CONFIG_ENABLE_LOOP2
+$      IF CONFIG_DEPENDENT_E .EQS. "," THEN GOTO CONFIG_ENABLE_LOOP2_END
+$       CONFIG_DISABLED_'CONFIG_DEPENDENT_E' := NO
+$       CONFIG_ENABLED_'CONFIG_DEPENDENT_E' := YES
+$      ! Better not to assume defaults at this point...
+$      CONFIG_CHANGED_'CONFIG_DEPENDENT_E' := YES
+$      WRITE SYS$ERROR -
+         "''CONFIG_DEPENDENT_E' enabled by rule ''CONFIG_ENABLE_E'"
+$      GOTO CONFIG_ENABLE_LOOP2
+$     CONFIG_ENABLE_LOOP2_END:
 $   ENDIF
-$   GOTO CONFIG_LOG_LOOP
-$ CONFIG_LOG_LOOP_END:
-$ WRITE H_FILE "#ifndef OPENSSL_NO_STATIC_ENGINE"
-$ WRITE H_FILE "# define OPENSSL_NO_STATIC_ENGINE"
-$ WRITE H_FILE "#endif"
-$ WRITE H_FILE "#ifndef OPENSSL_THREADS"
-$ WRITE H_FILE "# define OPENSSL_THREADS"
-$ WRITE H_FILE "#endif"
-$ WRITE H_FILE "#ifndef OPENSSL_NO_KRB5"
-$ WRITE H_FILE "# define OPENSSL_NO_KRB5"
-$ WRITE H_FILE "#endif"
-$ WRITE H_FILE ""
-$!
-$! Different tar version may have named the file differently
-$ IF F$SEARCH("[.CRYPTO]OPENSSLCONF.H_IN") .NES. ""
-$ THEN
-$   TYPE [.CRYPTO]OPENSSLCONF.H_IN /OUTPUT=H_FILE:
-$ ELSE
-$   IF F$SEARCH("[.CRYPTO]OPENSSLCONF_H.IN") .NES. ""
+$   GOTO CONFIG_ENABLE_LOOP0
+$ CONFIG_ENABLE_LOOP0_END:
+$
+$! Write to the configuration
+$ CONFIG_LOG_I = 0
+$ CONFIG_LOG_LOOP2:
+$   CONFIG_LOG_E = F$EDIT(F$ELEMENT(CONFIG_LOG_I,",",CONFIG_LOGICALS),"TRIM")
+$   CONFIG_LOG_I = CONFIG_LOG_I + 1
+$   IF CONFIG_LOG_E .EQS. "" THEN GOTO CONFIG_LOG_LOOP2
+$   IF CONFIG_LOG_E .EQS. "," THEN GOTO CONFIG_LOG_LOOP2_END
+$   IF CONFIG_CHANGED_'CONFIG_LOG_E'
 $   THEN
-$     TYPE [.CRYPTO]OPENSSLCONF_H.IN /OUTPUT=H_FILE:
-$   ELSE
-$     ! For ODS-5
-$     IF F$SEARCH("[.CRYPTO]OPENSSLCONF.H.IN") .NES. ""
+$     IF CONFIG_DISABLED_'CONFIG_LOG_E'
 $     THEN
-$       TYPE [.CRYPTO]OPENSSLCONF.H.IN /OUTPUT=H_FILE:
+$      WRITE H_FILE "#ifndef OPENSSL_NO_",CONFIG_LOG_E
+$      WRITE H_FILE "# define OPENSSL_NO_",CONFIG_LOG_E
+$      WRITE H_FILE "#endif"
 $     ELSE
-$       WRITE SYS$ERROR "Couldn't find a [.CRYPTO]OPENSSLCONF.H_IN.  Exiting!"
-$       $STATUS = %X00018294 ! "%RMS-F-FNF, file not found".
-$       GOTO TIDY
+$      WRITE H_FILE "#ifndef OPENSSL_",CONFIG_LOG_E
+$      WRITE H_FILE "# define OPENSSL_",CONFIG_LOG_E
+$      WRITE H_FILE "#endif"
 $     ENDIF
 $   ENDIF
-$ ENDIF
+$   GOTO CONFIG_LOG_LOOP2
+$ CONFIG_LOG_LOOP2_END:
+$!
+$ WRITE H_FILE ""
+$ WRITE H_FILE "/* 2011-02-23 SMS."
+$ WRITE H_FILE " * On VMS (V8.3), setvbuf() doesn't support a 64-bit"
+$ WRITE H_FILE " * ""in"" pointer, and the help says:"
+$ WRITE H_FILE " *       Please note that the previously documented"
+$ WRITE H_FILE " *       value _IONBF is not supported."
+$ WRITE H_FILE " * So, skip it on VMS."
+$ WRITE H_FILE " */"
+$ WRITE H_FILE "#define OPENSSL_NO_SETVBUF_IONBF"
+$ WRITE H_FILE ""
+$!
+$! Add in the common "crypto/opensslconf.h.in".
+$!
+$ TYPE 'OPENSSLCONF_H_IN' /OUTPUT=H_FILE:
+$!
 $ IF ARCH .NES. "VAX"
 $ THEN
 $!
-$!  Write the Alpha specific data
+$!  Write the non-VAX specific data
 $!
 $   WRITE H_FILE "#if defined(HEADER_RC4_H)"
 $   WRITE H_FILE "#undef RC4_INT"
@@ -347,33 +586,29 @@ $!  End
 $!
 $ ENDIF
 $!
-$! There are many places where this is needed.
-$!
-$!!! WRITE H_FILE "#define _XOPEN_SOURCE_EXTENDED"
-$!
-$! Close the [.CRYPTO._<ARCH>]OPENSSLCONF.H file
+$! Close the [.CRYPTO._xxx]OPENSSLCONF.H file
 $!
 $ CLOSE H_FILE
 $!
-$! Purge The [.CRYPTO._<ARCH>]OPENSSLCONF.H file
+$! Purge The [.CRYPTO._xxx]OPENSSLCONF.H file
 $!
-$ PURGE SYS$DISK:[.CRYPTO._'ARCH']OPENSSLCONF.H
+$ PURGE SYS$DISK:[.CRYPTO.'ARCHD']OPENSSLCONF.H
 $!
 $! That's All, Time To RETURN.
 $!
 $ RETURN
 $!
-$! Rebuild The "[.CRYPTO._<ARCH>]BUILDINF.H" file.
+$! Rebuild The "[.CRYPTO._xxx]BUILDINF.H" file.
 $!
 $ BUILDINF:
 $!
-$! Tell The User We Are Creating The [.CRYPTO._<ARCH>]BUILDINF.H File.
+$! Tell The User We Are Creating The [.CRYPTO._xxx]BUILDINF.H File.
 $!
-$ WRITE SYS$OUTPUT "Creating [.CRYPTO._''ARCH']BUILDINF.H Include File."
+$ WRITE SYS$OUTPUT "Creating [.CRYPTO.''ARCHD']BUILDINF.H Include File."
 $!
-$! Create The [.CRYPTO._<ARCH>]BUILDINF.H File.
+$! Create The [.CRYPTO._xxx]BUILDINF.H File.
 $!
-$ BIH_NAME = "SYS$DISK:[.CRYPTO._''ARCH']BUILDINF.H"
+$ BIH_NAME = "SYS$DISK:[.CRYPTO.''ARCHD']BUILDINF.H"
 $ CREATE /FDL=SYS$INPUT: 'BIH_NAME'
 RECORD
         FORMAT stream_lf
@@ -384,19 +619,35 @@ $! Get The Current Date & Time.
 $!
 $ TIME = F$TIME()
 $!
-$! Write The [.CRYPTO._<ARCH>]BUILDINF.H File.
-$!
-$ WRITE H_FILE "#define CFLAGS """" /* Not filled in for now */"
-$ WRITE H_FILE "#define PLATFORM ""VMS ''ARCH' ''VMS_VER'"""
+$! Write The [.CRYPTO._xxx]BUILDINF.H File.
+$!
+$ CFLAGS = ""
+$ if (POINTER_SIZE .nes. "")
+$ then
+$   CFLAGS = CFLAGS+ "/POINTER_SIZE=''POINTER_SIZE'"
+$ endif
+$ if (ZLIB .nes. "")
+$ then
+$   if (CFLAGS .nes. "") then CFLAGS = CFLAGS+ " "
+$   CFLAGS = CFLAGS+ "/DEFINE=ZLIB"
+$ endif
+$! 
+$ WRITE H_FILE "#define CFLAGS ""''CFLAGS'"""
+$ WRITE H_FILE "#define PLATFORM ""VMS ''ARCHD' ''VMS_VERSION'"""
 $ WRITE H_FILE "#define DATE ""''TIME'"" "
 $!
-$! Close The [.CRYPTO._<ARCH>]BUILDINF.H File.
+$! Close The [.CRYPTO._xxx]BUILDINF.H File.
 $!
 $ CLOSE H_FILE
 $!
-$! Purge The [.CRYPTO._<ARCH>]BUILDINF.H File.
+$! Purge The [.CRYPTO._xxx]BUILDINF.H File.
+$!
+$ PURGE SYS$DISK:[.CRYPTO.'ARCHD']BUILDINF.H
+$!
+$! Delete [.CRYPTO]BUILDINF.H File, as there might be some residue from Unix.
 $!
-$ PURGE SYS$DISK:[.CRYPTO._'ARCH']BUILDINF.H
+$ IF F$SEARCH("[.CRYPTO]BUILDINF.H") .NES. "" THEN -
+     DELETE SYS$DISK:[.CRYPTO]BUILDINF.H;*
 $!
 $! That's All, Time To RETURN.
 $!
@@ -406,45 +657,58 @@ $! Copy a lot of files around.
 $!
 $ SOFTLINKS: 
 $!
-$! Tell The User We Are Partly Rebuilding The [.APPS] Directory.
-$!
-$ WRITE SYS$OUTPUT "Rebuilding The '[.APPS]MD4.C' File."
-$!
-$ DELETE SYS$DISK:[.APPS]MD4.C;*
-$!
-$! Copy MD4.C from [.CRYPTO.MD4] into [.APPS]
-$!
-$ COPY SYS$DISK:[.CRYPTO.MD4]MD4.C SYS$DISK:[.APPS]
-$!
-$! Tell The User We Are Rebuilding The [.INCLUDE.OPENSSL] Directory.
-$!
-$ WRITE SYS$OUTPUT "Rebuilding The '[.INCLUDE.OPENSSL]' Directory."
-$!
-$! First, make sure the directory exists
-$!
-$ IF F$PARSE("SYS$DISK:[.INCLUDE.OPENSSL]") .EQS. "" THEN -
-     CREATE/DIRECTORY SYS$DISK:[.INCLUDE.OPENSSL]
+$!!!! Tell The User We Are Partly Rebuilding The [.APPS] Directory.
+$!!!!
+$!!! WRITE SYS$OUTPUT "Rebuilding The '[.APPS]MD4.C' File."
+$!!!!
+$!!! DELETE SYS$DISK:[.APPS]MD4.C;*
+$!!!!
+$!!!! Copy MD4.C from [.CRYPTO.MD4] into [.APPS]
+$!!!!
+$!!! COPY SYS$DISK:[.CRYPTO.MD4]MD4.C SYS$DISK:[.APPS]
+$!
+$! Ensure that the [.include.openssl] directory contains a full set of
+$! real header files.  The distribution kit may have left real or fake
+$! symlinks there.  Rather than think about what's there, simply delete
+$! the destination files (fake or real symlinks) before copying the real
+$! header files in.  (Copying a real header file onto a real symlink
+$! merely duplicates the real header file at its source.)
+$!
+$! Tell The User We Are Rebuilding The [.include.openssl] Directory.
+$!
+$ WRITE SYS$OUTPUT "Rebuilding The '[.include.openssl]' Directory."
+$!
+$! First, make sure the directory exists.  If it did exist, delete all
+$! the existing header files (or fake or real symlinks).
+$!
+$ if f$parse( "sys$disk:[.include.openssl]") .eqs. ""
+$ then
+$   create /directory sys$disk:[.include.openssl]
+$ else
+$   delete sys$disk:[.include.openssl]*.h;*
+$ endif
 $!
 $! Copy All The ".H" Files From The Main Directory.
 $!
 $ EXHEADER := e_os2.h
-$ COPY 'EXHEADER' SYS$DISK:[.INCLUDE.OPENSSL]
+$ copy 'exheader' sys$disk:[.include.openssl]
 $!
 $! Copy All The ".H" Files From The [.CRYPTO] Directory Tree.
 $!
-$ SDIRS := ,-
-   _'ARCH',-
-   OBJECTS,-
-   MD2,MD4,MD5,SHA,MDC2,HMAC,RIPEMD,-
-   DES,AES,RC2,RC4,RC5,IDEA,BF,CAST,CAMELLIA,SEED,-
-   BN,EC,RSA,DSA,ECDSA,DH,ECDH,DSO,ENGINE,-
-   BUFFER,BIO,STACK,LHASH,RAND,ERR,-
-   EVP,ASN1,PEM,X509,X509V3,CONF,TXT_DB,PKCS7,PKCS12,COMP,OCSP,UI,KRB5,-
-   STORE,CMS,PQUEUE,JPAKE
-$ EXHEADER_ := crypto.h,tmdiff.h,opensslv.h,ebcdic.h,symhacks.h,-
-               ossl_typ.h
-$ EXHEADER__'ARCH' := opensslconf.h
-$ EXHEADER_OBJECTS := objects.h,obj_mac.h
+$ SDIRS := , -
+   'ARCHD', -
+   OBJECTS, -
+   MD2, MD4, MD5, SHA, MDC2, HMAC, RIPEMD, WHRLPOOL, -
+   DES, AES, RC2, RC4, RC5, IDEA, BF, CAST, CAMELLIA, SEED, MODES, -
+   BN, EC, RSA, DSA, ECDSA, DH, ECDH, DSO, ENGINE, -
+   BUFFER, BIO, STACK, LHASH, RAND, ERR, -
+   EVP, ASN1, PEM, X509, X509V3, CONF, TXT_DB, PKCS7, PKCS12, -
+   COMP, OCSP, UI, KRB5, -
+   STORE, CMS, PQUEUE, TS, JPAKE
+$!
+$ EXHEADER_ := crypto.h, opensslv.h, ebcdic.h, symhacks.h, ossl_typ.h
+$ EXHEADER_'ARCHD' := opensslconf.h
+$ EXHEADER_OBJECTS := objects.h, obj_mac.h
 $ EXHEADER_MD2 := md2.h
 $ EXHEADER_MD4 := md4.h
 $ EXHEADER_MD5 := md5.h
@@ -452,7 +716,8 @@ $ EXHEADER_SHA := sha.h
 $ EXHEADER_MDC2 := mdc2.h
 $ EXHEADER_HMAC := hmac.h
 $ EXHEADER_RIPEMD := ripemd.h
-$ EXHEADER_DES := des.h,des_old.h
+$ EXHEADER_WHRLPOOL := whrlpool.h
+$ EXHEADER_DES := des.h, des_old.h
 $ EXHEADER_AES := aes.h
 $ EXHEADER_RC2 := rc2.h
 $ EXHEADER_RC4 := rc4.h
@@ -462,6 +727,7 @@ $ EXHEADER_BF := blowfish.h
 $ EXHEADER_CAST := cast.h
 $ EXHEADER_CAMELLIA := camellia.h
 $ EXHEADER_SEED := seed.h
+$ EXHEADER_MODES := modes.h
 $ EXHEADER_BN := bn.h
 $ EXHEADER_EC := ec.h
 $ EXHEADER_RSA := rsa.h
@@ -473,65 +739,64 @@ $ EXHEADER_DSO := dso.h
 $ EXHEADER_ENGINE := engine.h
 $ EXHEADER_BUFFER := buffer.h
 $ EXHEADER_BIO := bio.h
-$ EXHEADER_STACK := stack.h,safestack.h
+$ EXHEADER_STACK := stack.h, safestack.h
 $ EXHEADER_LHASH := lhash.h
 $ EXHEADER_RAND := rand.h
 $ EXHEADER_ERR := err.h
 $ EXHEADER_EVP := evp.h
-$ EXHEADER_ASN1 := asn1.h,asn1_mac.h,asn1t.h
-$ EXHEADER_PEM := pem.h,pem2.h
-$ EXHEADER_X509 := x509.h,x509_vfy.h
+$ EXHEADER_ASN1 := asn1.h, asn1_mac.h, asn1t.h
+$ EXHEADER_PEM := pem.h, pem2.h
+$ EXHEADER_X509 := x509.h, x509_vfy.h
 $ EXHEADER_X509V3 := x509v3.h
-$ EXHEADER_CONF := conf.h,conf_api.h
+$ EXHEADER_CONF := conf.h, conf_api.h
 $ EXHEADER_TXT_DB := txt_db.h
 $ EXHEADER_PKCS7 := pkcs7.h
 $ EXHEADER_PKCS12 := pkcs12.h
 $ EXHEADER_COMP := comp.h
 $ EXHEADER_OCSP := ocsp.h
-$ EXHEADER_UI := ui.h,ui_compat.h
+$ EXHEADER_UI := ui.h, ui_compat.h
 $ EXHEADER_KRB5 := krb5_asn.h
-$!EXHEADER_STORE := store.h,str_compat.h
+$!!! EXHEADER_STORE := store.h, str_compat.h
 $ EXHEADER_STORE := store.h
 $ EXHEADER_CMS := cms.h
-$ EXHEADER_PQUEUE := pqueue.h,pq_compat.h
+$ EXHEADER_PQUEUE := pqueue.h
+$ EXHEADER_TS := ts.h
 $ EXHEADER_JPAKE := jpake.h
-$
-$ I = 0
-$ LOOP_SDIRS: 
-$ D = F$EDIT(F$ELEMENT(I, ",", SDIRS),"TRIM")
-$ I = I + 1
-$ IF D .EQS. "," THEN GOTO LOOP_SDIRS_END
-$ tmp = EXHEADER_'D'
-$ IF D .EQS. ""
-$ THEN
-$   COPY [.CRYPTO]'tmp' SYS$DISK:[.INCLUDE.OPENSSL] !/LOG
-$ ELSE
-$   COPY [.CRYPTO.'D']'tmp' SYS$DISK:[.INCLUDE.OPENSSL] !/LOG
-$ ENDIF
-$ GOTO LOOP_SDIRS
-$ LOOP_SDIRS_END:
+$!
+$ i = 0
+$ loop_sdirs:
+$   sdir = f$edit( f$element( i, ",", sdirs), "trim")
+$   i = i + 1
+$   if (sdir .eqs. ",") then goto loop_sdirs_end
+$   hdr_list = exheader_'sdir'
+$   if (sdir .nes. "") then sdir = "."+ sdir
+$   copy [.crypto'sdir']'hdr_list' sys$disk:[.include.openssl]
+$ goto loop_sdirs
+$ loop_sdirs_end:
 $!
 $! Copy All The ".H" Files From The [.SSL] Directory.
 $!
-$ EXHEADER := ssl.h,ssl2.h,ssl3.h,ssl23.h,tls1.h,dtls1.h,kssl.h
-$ COPY SYS$DISK:[.SSL]'EXHEADER' SYS$DISK:[.INCLUDE.OPENSSL]
+$! (keep these in the same order as ssl/Makefile)
+$ EXHEADER := ssl.h, ssl2.h, ssl3.h, ssl23.h, tls1.h, dtls1.h, kssl.h
+$ copy sys$disk:[.ssl]'exheader' sys$disk:[.include.openssl]
 $!
-$! Purge all doubles
+$! Purge the [.include.openssl] header files.
 $!
-$ PURGE SYS$DISK:[.INCLUDE.OPENSSL]*.H
+$ purge sys$disk:[.include.openssl]*.h
 $!
 $! That's All, Time To RETURN.
 $!
 $ RETURN
 $!
-$! Build The "[.xxx.EXE.CRYPTO]LIBCRYPTO.OLB" Library.
+$! Build The "[.xxx.EXE.CRYPTO]SSL_LIBCRYPTO''LIB32'.OLB" Library.
 $!
 $ CRYPTO:
 $!
 $! Tell The User What We Are Doing.
 $!
 $ WRITE SYS$OUTPUT ""
-$ WRITE SYS$OUTPUT "Building The [.",ARCH,".EXE.CRYPTO]LIBCRYPTO.OLB Library."
+$ WRITE SYS$OUTPUT -
+   "Building The [.",ARCHD,".EXE.CRYPTO]SSL_LIBCRYPTO''LIB32'.OLB Library."
 $!
 $! Go To The [.CRYPTO] Directory.
 $!
@@ -539,11 +804,13 @@ $ SET DEFAULT SYS$DISK:[.CRYPTO]
 $!
 $! Build The [.xxx.EXE.CRYPTO]LIBCRYPTO.OLB Library.
 $!  
-$ @CRYPTO-LIB LIBRARY 'DEBUGGER' "''COMPILER'" "''TCPIP_TYPE'" "''ISSEVEN'" "''BUILDPART'"
+$ @CRYPTO-LIB LIBRARY 'DEBUGGER' "''COMPILER'" "''TCPIP_TYPE'" -
+   "''ISSEVEN'" "''BUILDPART'" "''POINTER_SIZE'" "''ZLIB'"
 $!
 $! Build The [.xxx.EXE.CRYPTO]*.EXE Test Applications.
 $!  
-$ @CRYPTO-LIB APPS 'DEBUGGER' "''COMPILER'" "''TCPIP_TYPE'" 'ISSEVEN' "''BUILDPART'"
+$ @CRYPTO-LIB APPS 'DEBUGGER' "''COMPILER'" "''TCPIP_TYPE'" -
+   "''ISSEVEN'" "''BUILDPART'" "''POINTER_SIZE'" "''ZLIB'"
 $!
 $! Go Back To The Main Directory.
 $!
@@ -553,14 +820,15 @@ $! Time To RETURN.
 $!
 $ RETURN
 $!
-$! Build The "[.xxx.EXE.SSL]LIBSSL.OLB" Library.
+$! Build The "[.xxx.EXE.SSL]SSL_LIBSSL''LIB32'.OLB" Library.
 $!
 $ SSL:
 $!
 $! Tell The User What We Are Doing.
 $!
 $ WRITE SYS$OUTPUT ""
-$ WRITE SYS$OUTPUT "Building The [.",ARCH,".EXE.SSL]LIBSSL.OLB Library."
+$ WRITE SYS$OUTPUT -
+   "Building The [.",ARCHD,".EXE.SSL]SSL_LIBSSL''LIB32'.OLB Library."
 $!
 $! Go To The [.SSL] Directory.
 $!
@@ -568,7 +836,8 @@ $ SET DEFAULT SYS$DISK:[.SSL]
 $!
 $! Build The [.xxx.EXE.SSL]LIBSSL.OLB Library.
 $!
-$ @SSL-LIB LIBRARY 'DEBUGGER' "''COMPILER'" "''TCPIP_TYPE'" 'ISSEVEN'
+$ @SSL-LIB LIBRARY 'DEBUGGER' "''COMPILER'" "''TCPIP_TYPE'" -
+   "''ISSEVEN'" "''POINTER_SIZE'" "''ZLIB'"
 $!
 $! Go Back To The Main Directory.
 $!
@@ -585,7 +854,8 @@ $!
 $! Tell The User What We Are Doing.
 $!
 $ WRITE SYS$OUTPUT ""
-$ WRITE SYS$OUTPUT "Building DECNet Based SSL Engine, [.",ARCH,".EXE.SSL]SSL_TASK.EXE"
+$ WRITE SYS$OUTPUT -
+   "Building DECNet Based SSL Engine, [.",ARCHD,".EXE.SSL]SSL_TASK.EXE"
 $!
 $! Go To The [.SSL] Directory.
 $!
@@ -593,7 +863,8 @@ $ SET DEFAULT SYS$DISK:[.SSL]
 $!
 $! Build The [.xxx.EXE.SSL]SSL_TASK.EXE
 $!
-$ @SSL-LIB SSL_TASK 'DEBUGGER' "''COMPILER'" "''TCPIP_TYPE'" 'ISSEVEN'
+$ @SSL-LIB SSL_TASK 'DEBUGGER' "''COMPILER'" "''TCPIP_TYPE'" -
+   "''ISSEVEN'" "''POINTER_SIZE'" "''ZLIB'"
 $!
 $! Go Back To The Main Directory.
 $!
@@ -610,7 +881,7 @@ $!
 $! Tell The User What We Are Doing.
 $!
 $ WRITE SYS$OUTPUT ""
-$ WRITE SYS$OUTPUT "Building The OpenSSL [.",ARCH,".EXE.TEST] Test Utilities."
+$ WRITE SYS$OUTPUT "Building The OpenSSL [.",ARCHD,".EXE.TEST] Test Utilities."
 $!
 $! Go To The [.TEST] Directory.
 $!
@@ -618,7 +889,8 @@ $ SET DEFAULT SYS$DISK:[.TEST]
 $!
 $! Build The Test Programs.
 $!
-$ @MAKETESTS 'DEBUGGER' "''COMPILER'" "''TCPIP_TYPE'" 'ISSEVEN'
+$ @MAKETESTS 'DEBUGGER' "''COMPILER'" "''TCPIP_TYPE'" "''ISSEVEN'" -
+   "''POINTER_SIZE'" "''ZLIB'"
 $!
 $! Go Back To The Main Directory.
 $!
@@ -635,7 +907,7 @@ $!
 $! Tell The User What We Are Doing.
 $!
 $ WRITE SYS$OUTPUT ""
-$ WRITE SYS$OUTPUT "Building OpenSSL [.",ARCH,".EXE.APPS] Applications."
+$ WRITE SYS$OUTPUT "Building OpenSSL [.",ARCHD,".EXE.APPS] Applications."
 $!
 $! Go To The [.APPS] Directory.
 $!
@@ -643,7 +915,8 @@ $ SET DEFAULT SYS$DISK:[.APPS]
 $!
 $! Build The Application Programs.
 $!
-$ @MAKEAPPS 'DEBUGGER' "''COMPILER'" "''TCPIP_TYPE'" 'ISSEVEN'
+$ @MAKEAPPS 'DEBUGGER' "''COMPILER'" "''TCPIP_TYPE'" "''ISSEVEN'" -
+   "" "''POINTER_SIZE'" "''ZLIB'"
 $!
 $! Go Back To The Main Directory.
 $!
@@ -660,7 +933,7 @@ $!
 $! Tell The User What We Are Doing.
 $!
 $ WRITE SYS$OUTPUT ""
-$ WRITE SYS$OUTPUT "Building OpenSSL [.",ARCH,".EXE.ENGINES] Engines."
+$ WRITE SYS$OUTPUT "Building OpenSSL [.",ARCHD,".EXE.ENGINES] Engines."
 $!
 $! Go To The [.ENGINES] Directory.
 $!
@@ -668,7 +941,8 @@ $ SET DEFAULT SYS$DISK:[.ENGINES]
 $!
 $! Build The Application Programs.
 $!
-$ @MAKEENGINES ENGINES 'DEBUGGER' "''COMPILER'" "''TCPIP_TYPE'" 'ISSEVEN' "''BUILDPART'"
+$ @MAKEENGINES ENGINES 'DEBUGGER' "''COMPILER'" "''TCPIP_TYPE'" -
+   "''ISSEVEN'" "''BUILDPART'" "''POINTER_SIZE'" "''ZLIB'"
 $!
 $! Go Back To The Main Directory.
 $!
@@ -705,7 +979,7 @@ $! Else...
 $!
 $ ELSE
 $!
-$!  Else, Check To See If P1 Has A Valid Arguement.
+$!  Else, Check To See If P1 Has A Valid Argument.
 $!
 $   IF (P1.EQS."CONFIG").OR.(P1.EQS."BUILDINF").OR.(P1.EQS."SOFTLINKS") -
        .OR.(P1.EQS."BUILDALL") -
@@ -714,7 +988,7 @@ $   IF (P1.EQS."CONFIG").OR.(P1.EQS."BUILDINF").OR.(P1.EQS."SOFTLINKS") -
        .OR.(P1.EQS."ENGINES")
 $   THEN
 $!
-$!    A Valid Arguement.
+$!    A Valid Argument.
 $!
 $     BUILDCOMMAND = P1
 $!
@@ -725,15 +999,15 @@ $!
 $!    Tell The User We Don't Know What They Want.
 $!
 $     WRITE SYS$OUTPUT ""
-$     WRITE SYS$OUTPUT "USAGE:   @MAKEVMS.COM [Target] [not-used option] [Debug option] <Compiler>"
+$     WRITE SYS$OUTPUT "USAGE:   @MAKEVMS.COM [Target] [Pointer size] [Debug option] <Compiler>"
 $     WRITE SYS$OUTPUT ""
-$     WRITE SYS$OUTPUT "Example: @MAKEVMS.COM ALL NORSAREF NODEBUG "
+$     WRITE SYS$OUTPUT "Example: @MAKEVMS.COM ALL """" NODEBUG "
 $     WRITE SYS$OUTPUT ""
 $     WRITE SYS$OUTPUT "The Target ",P1," Is Invalid.  The Valid Target Options Are:"
 $     WRITE SYS$OUTPUT ""
 $     WRITE SYS$OUTPUT "    ALL      :  Just Build Everything."
-$     WRITE SYS$OUTPUT "    CONFIG   :  Just build the [.CRYPTO._''ARCH']OPENSSLCONF.H file."
-$     WRITE SYS$OUTPUT "    BUILDINF :  Just build the [.CRYPTO._''ARCH']BUILDINF.H file."
+$     WRITE SYS$OUTPUT "    CONFIG   :  Just build the [.CRYPTO._xxx]OPENSSLCONF.H file."
+$     WRITE SYS$OUTPUT "    BUILDINF :  Just build the [.CRYPTO._xxx]BUILDINF.H file."
 $     WRITE SYS$OUTPUT "    SOFTLINKS:  Just Fix The Unix soft links."
 $     WRITE SYS$OUTPUT "    BUILDALL :  Same as ALL, except CONFIG, BUILDINF and SOFTILNKS aren't done."
 $     WRITE SYS$OUTPUT "    CRYPTO   :  To Build Just The [.xxx.EXE.CRYPTO]LIBCRYPTO.OLB Library."
@@ -747,8 +1021,8 @@ $     WRITE SYS$OUTPUT "    ENGINES  :  To Build Just The ENGINES"
 $     WRITE SYS$OUTPUT ""
 $     WRITE SYS$OUTPUT " Where 'xxx' Stands For:"
 $     WRITE SYS$OUTPUT ""
-$     WRITE SYS$OUTPUT "    ALPHA    :  Alpha Architecture."
-$     WRITE SYS$OUTPUT "    IA64     :  IA64 Architecture."
+$     WRITE SYS$OUTPUT "    ALPHA[64]:  Alpha Architecture."
+$     WRITE SYS$OUTPUT "    IA64[64] :  IA64 Architecture."
 $     WRITE SYS$OUTPUT "    VAX      :  VAX Architecture."
 $     WRITE SYS$OUTPUT ""
 $!
@@ -764,6 +1038,54 @@ $! End The P1 Check.
 $!
 $ ENDIF
 $!
+$! Check P2 (POINTER_SIZE).
+$!
+$ IF (P2 .NES. "") .AND. (ARCH .NES. "VAX")
+$ THEN
+$!
+$   IF (P2 .EQS. "32")
+$   THEN
+$     POINTER_SIZE = "32"
+$   ELSE
+$     POINTER_SIZE = F$EDIT( P2, "COLLAPSE, UPCASE")
+$     IF ((POINTER_SIZE .EQS. "64") .OR. -
+       (POINTER_SIZE .EQS. "64=") .OR. -
+       (POINTER_SIZE .EQS. "64=ARGV"))
+$     THEN
+$       ARCHD = ARCH+ "_64"
+$       LIB32 = ""
+$     ELSE
+$!
+$!      Tell The User Entered An Invalid Option.
+$!
+$       WRITE SYS$OUTPUT ""
+$       WRITE SYS$OUTPUT "The Option ", P2, -
+         " Is Invalid.  The Valid Options Are:"
+$       WRITE SYS$OUTPUT ""
+$       WRITE SYS$OUTPUT -
+         "    """"       :  Compile with default (short) pointers."
+$       WRITE SYS$OUTPUT -
+         "    32       :  Compile with 32-bit (short) pointers."
+$       WRITE SYS$OUTPUT -
+         "    64       :  Compile with 64-bit (long) pointers (auto ARGV)."
+$       WRITE SYS$OUTPUT -
+         "    64=      :  Compile with 64-bit (long) pointers (no ARGV)."
+$       WRITE SYS$OUTPUT -
+         "    64=ARGV  :  Compile with 64-bit (long) pointers (ARGV)."
+$       WRITE SYS$OUTPUT ""
+$! 
+$!      Time To EXIT.
+$!
+$       GOTO TIDY
+$!
+$     ENDIF
+$!
+$   ENDIF
+$!
+$! End The P2 (POINTER_SIZE) Check.
+$!
+$ ENDIF
+$!
 $! Check To See If P3 Is Blank.
 $!
 $ IF (P3.EQS."NODEBUG")
@@ -790,7 +1112,7 @@ $!  Else...
 $!
 $   ELSE
 $!
-$!    Tell The User Entered An Invalid Option..
+$!    Tell The User Entered An Invalid Option.
 $!
 $     WRITE SYS$OUTPUT ""
 $     WRITE SYS$OUTPUT "The Option ",P3," Is Invalid.  The Valid Options Are:"
@@ -803,7 +1125,7 @@ $!    Time To EXIT.
 $!
 $     GOTO TIDY
 $!
-$!  End The Valid Arguement Check.
+$!  End The Valid Argument Check.
 $!
 $   ENDIF
 $!
@@ -869,7 +1191,7 @@ $! Else...
 $!
 $ ELSE
 $!
-$!  Check To See If The User Entered A Valid Paramter.
+$!  Check To See If The User Entered A Valid Parameter.
 $!
 $   IF (P4.EQS."VAXC").OR.(P4.EQS."DECC").OR.(P4.EQS."GNUC")!.OR.(P4.EQS."LINK")
 $   THEN
@@ -942,7 +1264,7 @@ $!    End The GNU C Check.
 $!
 $     ENDIF
 $!
-$!  Else The User Entered An Invalid Arguement.
+$!  Else The User Entered An Invalid Argument.
 $!
 $   ELSE
 $!
@@ -960,7 +1282,7 @@ $!    Time To EXIT.
 $!
 $     GOTO TIDY
 $!
-$!  End The Valid Arguement Check.
+$!  End The Valid Argument Check.
 $!
 $   ENDIF
 $!
@@ -968,7 +1290,8 @@ $! End The P4 Check.
 $!
 $ ENDIF
 $!
-$! Time to check the contents of P5, and to make sure we get the correct library.
+$! Time to check the contents of P5, and to make sure we get the correct
+$! library.
 $!
 $ IF P5.EQS."SOCKETSHR" .OR. P5.EQS."MULTINET" .OR. P5.EQS."UCX" -
      .OR. P5.EQS."TCPIP" .OR. P5.EQS."NONE"
@@ -981,7 +1304,7 @@ $   THEN
 $!
 $!    Set the library to use SOCKETSHR
 $!
-$     TCPIP_LIB = "SYS$DISK:[-.VMS]SOCKETSHR_SHR.OPT/OPT"
+$     TCPIP_LIB = "SYS$DISK:[-.VMS]SOCKETSHR_SHR.OPT /OPTIONS"
 $!
 $!    Tell the user
 $!
@@ -1015,7 +1338,7 @@ $   THEN
 $!
 $!    Set the library to use UCX.
 $!
-$     TCPIP_LIB = "SYS$DISK:[-.VMS]UCX_SHR_DECC.OPT/OPT"
+$     TCPIP_LIB = "SYS$DISK:[-.VMS]UCX_SHR_DECC.OPT /OPTIONS"
 $!
 $!    Tell the user
 $!
@@ -1032,7 +1355,7 @@ $   THEN
 $!
 $!    Set the library to use TCPIP (post UCX).
 $!
-$     TCPIP_LIB = "SYS$DISK:[-.VMS]TCPIP_SHR_DECC.OPT/OPT"
+$     TCPIP_LIB = "SYS$DISK:[-.VMS]TCPIP_SHR_DECC.OPT /OPTIONS"
 $!
 $!    Tell the user
 $!
@@ -1067,7 +1390,7 @@ $!  Print info
 $!
 $   WRITE SYS$OUTPUT "TCP/IP library spec: ", TCPIP_LIB
 $!
-$!  Else The User Entered An Invalid Arguement.
+$!  Else The User Entered An Invalid Argument.
 $!
 $ ELSE
 $   IF P5 .NES. ""
@@ -1122,7 +1445,7 @@ $!
 $!  Get The Version Of VMS We Are Using.
 $!
 $   ISSEVEN :=
-$   TMP = F$ELEMENT(0,"-",F$EXTRACT(1,4,F$GETSYI("VERSION")))
+$   TMP = F$ELEMENT(0,"-",F$EXTRACT(1,4,VMS_VERSION))
 $   TMP = F$INTEGER(F$ELEMENT(0,".",TMP)+F$ELEMENT(1,".",TMP))
 $!
 $!  Check To See If The VMS Version Is v7.1 Or Later.
@@ -1142,11 +1465,69 @@ $! End The P6 Check.
 $!
 $ ENDIF
 $!
+$!
+$! Check To See If We Have A ZLIB Option.
+$!
+$ ZLIB = P7
+$ IF (ZLIB .NES. "")
+$ THEN
+$!
+$!  Check for expected ZLIB files.
+$!
+$   err = 0
+$   file1 = f$parse( "zlib.h", ZLIB, , , "SYNTAX_ONLY")
+$   if (f$search( file1) .eqs. "")
+$   then
+$     WRITE SYS$OUTPUT ""
+$     WRITE SYS$OUTPUT "The Option ", ZLIB, " Is Invalid."
+$     WRITE SYS$OUTPUT "    Can't find header: ''file1'"
+$     err = 1
+$   endif
+$!
+$   file2 = f$parse( ZLIB, "libz.olb", , , "SYNTAX_ONLY")
+$   if (f$search( file2) .eqs. "")
+$   then
+$     if (err .eq. 0)
+$     then
+$       WRITE SYS$OUTPUT ""
+$       WRITE SYS$OUTPUT "The Option ", ZLIB, " Is Invalid."
+$     endif
+$     WRITE SYS$OUTPUT "    Can't find library: ''file2'"
+$     WRITE SYS$OUTPUT ""
+$     err = err+ 2
+$   endif
+$   if (err .eq. 1)
+$   then
+$     WRITE SYS$OUTPUT ""
+$   endif
+$!
+$   if (err .ne. 0)
+$   then
+$     GOTO TIDY
+$   endif
+$!
+$!  Print info
+$!
+$   WRITE SYS$OUTPUT "ZLIB library spec: ", file2
+$!
+$! End The ZLIB Check.
+$!
+$ ENDIF
+$!
 $!  Time To RETURN...
 $!
 $ RETURN
 $!
 $ TIDY:
+$!
+$! Close any open files.
+$!
+$ if (f$trnlnm( "h_file", "LNM$PROCESS", 0, "SUPERVISOR") .nes. "") then -
+   close h_file
+$!
+$! Restore the original default device:[directory].
+$!
 $ SET DEFAULT 'DEF_ORIG'
+$!
 $ EXIT
 $!
index 7a45db1..07f1925 100644 (file)
@@ -4,7 +4,7 @@ to build with visual C++ 4.[01].
 
 The results will be in the out directory.
 
-These makefiles and def files were generated my typing
+These makefiles and def files were generated by typing
 
 perl util\mk1mf.pl VC-NT >ms/nt.mak
 perl util\mk1mf.pl VC-NT dll >ms/ntdll.mak
index 71a670e..00fb9e8 100755 (executable)
@@ -1,6 +1,6 @@
-perl Configure BC-32\r
-perl util\mkfiles.pl > MINFO\r
-\r
-@rem create make file\r
-perl util\mk1mf.pl no-asm BC-NT > bcb.mak\r
-\r
+perl Configure BC-32
+perl util\mkfiles.pl > MINFO
+
+@rem create make file
+perl util\mk1mf.pl no-asm BC-NT > bcb.mak
+
diff --git a/deps/openssl/openssl/ms/do_fips.bat b/deps/openssl/openssl/ms/do_fips.bat
deleted file mode 100644 (file)
index 8d27eb0..0000000
+++ /dev/null
@@ -1,204 +0,0 @@
-@echo off
-
-SET ASM=%1
-
-if NOT X%PROCESSOR_ARCHITECTURE% == X goto defined 
-
-echo Processor Architecture Undefined: defaulting to X86
-
-goto X86
-
-:defined
-
-if %PROCESSOR_ARCHITECTURE% == x86 goto X86
-
-if %PROCESSOR_ARCHITECTURE% == IA64 goto IA64
-
-if %PROCESSOR_ARCHITECTURE% == AMD64 goto AMD64
-
-echo Processor Architecture Unrecognized: defaulting to X86
-
-:X86
-echo Auto Configuring for X86
-
-SET TARGET=VC-WIN32
-
-if x%ASM% == xno-asm goto compile
-echo Generating x86 for NASM assember
-SET ASM=nasm
-SET ASMOPTS=-DOPENSSL_IA32_SSE2
-
-echo Bignum
-cd crypto\bn\asm
-perl bn-586.pl win32n %ASMOPTS% > bn_win32.asm
-if ERRORLEVEL 1 goto error
-perl co-586.pl win32n %ASMOPTS% > co_win32.asm
-if ERRORLEVEL 1 goto error
-perl mo-586.pl win32n %ASMOPTS% > mt_win32.asm
-if ERRORLEVEL 1 goto error
-cd ..\..\..
-
-echo AES
-cd crypto\aes\asm
-perl aes-586.pl win32n %ASMOPTS% > a_win32.asm
-if ERRORLEVEL 1 goto error
-cd ..\..\..
-
-echo DES
-cd crypto\des\asm
-perl des-586.pl win32n %ASMOPTS% > d_win32.asm
-if ERRORLEVEL 1 goto error
-cd ..\..\..
-
-echo "crypt(3)"
-
-cd crypto\des\asm
-perl crypt586.pl win32n %ASMOPTS% > y_win32.asm
-if ERRORLEVEL 1 goto error
-cd ..\..\..
-
-echo Blowfish
-
-cd crypto\bf\asm
-perl bf-586.pl win32n %ASMOPTS% > b_win32.asm
-if ERRORLEVEL 1 goto error
-cd ..\..\..
-
-echo CAST5
-cd crypto\cast\asm
-perl cast-586.pl win32n %ASMOPTS% > c_win32.asm
-if ERRORLEVEL 1 goto error
-cd ..\..\..
-
-echo RC4
-cd crypto\rc4\asm
-perl rc4-586.pl win32n %ASMOPTS% > r4_win32.asm
-if ERRORLEVEL 1 goto error
-cd ..\..\..
-
-echo MD5
-cd crypto\md5\asm
-perl md5-586.pl win32n %ASMOPTS% > m5_win32.asm
-if ERRORLEVEL 1 goto error
-cd ..\..\..
-
-echo SHA1
-cd crypto\sha\asm
-perl sha1-586.pl win32n %ASMOPTS% > s1_win32.asm
-if ERRORLEVEL 1 goto error
-perl sha512-sse2.pl win32n %ASMOPTS% > sha512-sse2.asm
-if ERRORLEVEL 1 goto error
-cd ..\..\..
-
-echo RIPEMD160
-cd crypto\ripemd\asm
-perl rmd-586.pl win32n %ASMOPTS% > rm_win32.asm
-if ERRORLEVEL 1 goto error
-cd ..\..\..
-
-echo RC5\32
-cd crypto\rc5\asm
-perl rc5-586.pl win32n %ASMOPTS% > r5_win32.asm
-if ERRORLEVEL 1 goto error
-cd ..\..\..
-
-echo CPU-ID
-cd crypto
-perl x86cpuid.pl win32n %ASMOPTS% > cpu_win32.asm
-if ERRORLEVEL 1 goto error
-cd ..
-
-goto compile
-
-:IA64
-
-echo Auto Configuring for IA64
-SET TARGET=VC-WIN64I
-perl ms\uplink.pl win64i > ms\uptable.asm
-if ERRORLEVEL 1 goto error
-ias -o ms\uptable.obj ms\uptable.asm
-if ERRORLEVEL 1 goto error
-
-goto compile
-
-:AMD64
-
-echo Auto Configuring for AMD64
-SET TARGET=VC-WIN64A
-perl ms\uplink.pl win64a > ms\uptable.asm
-if ERRORLEVEL 1 goto error
-ml64 -c -Foms\uptable.obj ms\uptable.asm
-if ERRORLEVEL 1 goto error
-
-if x%ASM% == xno-asm goto compile
-echo Generating x86_64 for ML64 assember
-SET ASM=ml64
-
-echo Bignum
-cd crypto\bn\asm
-perl x86_64-mont.pl x86_64-mont.asm
-if ERRORLEVEL 1 goto error
-cd ..\..\..
-
-echo AES
-cd crypto\aes\asm
-perl aes-x86_64.pl aes-x86_64.asm
-if ERRORLEVEL 1 goto error
-cd ..\..\..
-
-echo SHA
-cd crypto\sha\asm
-perl sha1-x86_64.pl sha1-x86_64.asm
-if ERRORLEVEL 1 goto error
-perl sha512-x86_64.pl sha256-x86_64.asm
-if ERRORLEVEL 1 goto error
-perl sha512-x86_64.pl sha512-x86_64.asm
-if ERRORLEVEL 1 goto error
-cd ..\..\..
-
-echo CPU-ID
-cd crypto
-perl x86_64cpuid.pl cpuid-x86_64.asm
-if ERRORLEVEL 1 goto error
-cd ..
-
-:compile
-
-perl Configure %TARGET% fipscanisterbuild
-pause
-
-echo on
-
-perl util\mkfiles.pl >MINFO
-@if ERRORLEVEL 1 goto error
-perl util\mk1mf.pl dll %ASM% %TARGET% >ms\ntdll.mak
-@if ERRORLEVEL 1 goto error
-
-perl util\mkdef.pl 32 libeay > ms\libeay32.def
-@if ERRORLEVEL 1 goto error
-perl util\mkdef.pl 32 ssleay > ms\ssleay32.def
-@if ERRORLEVEL 1 goto error
-
-nmake -f ms\ntdll.mak clean
-nmake -f ms\ntdll.mak
-@if ERRORLEVEL 1 goto error
-
-@echo.
-@echo.
-@echo.
-@echo ***************************
-@echo ****FIPS BUILD SUCCESS*****
-@echo ***************************
-
-@goto end
-
-:error
-
-@echo.
-@echo.
-@echo.
-@echo ***************************
-@echo ****FIPS BUILD FAILURE*****
-@echo ***************************
-
-:end
diff --git a/deps/openssl/openssl/ms/do_masm.bat b/deps/openssl/openssl/ms/do_masm.bat
deleted file mode 100755 (executable)
index a857532..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-@SET ASMOPTS=-DOPENSSL_IA32_SSE2
-@echo Generating x86 for MASM assember
-
-@echo Bignum
-@cd crypto\bn\asm
-@perl bn-586.pl win32 %ASMOPTS% > bn_win32.asm
-@perl co-586.pl win32 %ASMOPTS% > co_win32.asm
-@perl mo-586.pl win32 %ASMOPTS% > mt_win32.asm
-@cd ..\..\..
-
-@echo AES
-@cd crypto\aes\asm
-@perl aes-586.pl win32 %ASMOPTS% > a_win32.asm
-@cd ..\..\..
-
-@echo DES
-@cd crypto\des\asm
-@perl des-586.pl win32 %ASMOPTS% > d_win32.asm
-@cd ..\..\..
-
-@echo "crypt(3)"
-
-@cd crypto\des\asm
-@perl crypt586.pl win32 %ASMOPTS% > y_win32.asm
-@cd ..\..\..
-
-@echo Blowfish
-
-@cd crypto\bf\asm
-@perl bf-586.pl win32 %ASMOPTS% > b_win32.asm
-@cd ..\..\..
-
-@echo CAST5
-@cd crypto\cast\asm
-@perl cast-586.pl win32 %ASMOPTS% > c_win32.asm
-@cd ..\..\..
-
-@echo RC4
-@cd crypto\rc4\asm
-@perl rc4-586.pl win32 %ASMOPTS% > r4_win32.asm
-@cd ..\..\..
-
-@echo MD5
-@cd crypto\md5\asm
-@perl md5-586.pl win32 %ASMOPTS% > m5_win32.asm
-@cd ..\..\..
-
-@echo SHA1
-@cd crypto\sha\asm
-@perl sha1-586.pl win32 %ASMOPTS% > s1_win32.asm
-@perl sha512-sse2.pl win32 %ASMOPTS% > sha512-sse2.asm
-@cd ..\..\..
-
-@echo RIPEMD160
-@cd crypto\ripemd\asm
-@perl rmd-586.pl win32 %ASMOPTS% > rm_win32.asm
-@cd ..\..\..
-
-@echo RC5\32
-@cd crypto\rc5\asm
-@perl rc5-586.pl win32 %ASMOPTS% > r5_win32.asm
-@cd ..\..\..
-
-@echo CPU-ID
-@cd crypto
-@perl x86cpuid.pl win32 %ASMOPTS% > cpu_win32.asm
-@cd ..
-
-perl util\mkfiles.pl >MINFO
-perl util\mk1mf.pl VC-WIN32 >ms\nt.mak
-perl util\mk1mf.pl dll VC-WIN32 >ms\ntdll.mak
-
-perl util\mkdef.pl 32 libeay > ms\libeay32.def
-perl util\mkdef.pl 32 ssleay > ms\ssleay32.def
index 7656c49..7b3f3ed 100755 (executable)
@@ -1,76 +1,4 @@
 
-@echo off
-
-SET ASMOPTS=-DOPENSSL_IA32_SSE2
-echo Generating x86 for NASM assember
-
-echo Bignum
-cd crypto\bn\asm
-perl bn-586.pl win32n %ASMOPTS% > bn_win32.asm
-perl co-586.pl win32n %ASMOPTS% > co_win32.asm
-perl mo-586.pl win32n %ASMOPTS% > mt_win32.asm
-cd ..\..\..
-
-echo AES
-cd crypto\aes\asm
-perl aes-586.pl win32n %ASMOPTS% > a_win32.asm
-cd ..\..\..
-
-echo DES
-cd crypto\des\asm
-perl des-586.pl win32n %ASMOPTS% > d_win32.asm
-cd ..\..\..
-
-echo "crypt(3)"
-
-cd crypto\des\asm
-perl crypt586.pl win32n %ASMOPTS% > y_win32.asm
-cd ..\..\..
-
-echo Blowfish
-
-cd crypto\bf\asm
-perl bf-586.pl win32n %ASMOPTS% > b_win32.asm
-cd ..\..\..
-
-echo CAST5
-cd crypto\cast\asm
-perl cast-586.pl win32n %ASMOPTS% > c_win32.asm
-cd ..\..\..
-
-echo RC4
-cd crypto\rc4\asm
-perl rc4-586.pl win32n %ASMOPTS% > r4_win32.asm
-cd ..\..\..
-
-echo MD5
-cd crypto\md5\asm
-perl md5-586.pl win32n %ASMOPTS% > m5_win32.asm
-cd ..\..\..
-
-echo SHA1
-cd crypto\sha\asm
-perl sha1-586.pl win32n %ASMOPTS% > s1_win32.asm
-perl sha512-sse2.pl win32n %ASMOPTS% > sha512-sse2.asm
-cd ..\..\..
-
-echo RIPEMD160
-cd crypto\ripemd\asm
-perl rmd-586.pl win32n %ASMOPTS% > rm_win32.asm
-cd ..\..\..
-
-echo RC5\32
-cd crypto\rc5\asm
-perl rc5-586.pl win32n %ASMOPTS% > r5_win32.asm
-cd ..\..\..
-
-echo CPU-ID
-cd crypto
-perl x86cpuid.pl win32n %ASMOPTS% > cpu_win32.asm
-cd ..
-
-echo on
-
 perl util\mkfiles.pl >MINFO
 perl util\mk1mf.pl nasm VC-WIN32 >ms\nt.mak
 perl util\mk1mf.pl dll nasm VC-WIN32 >ms\ntdll.mak
index 9c06c27..e2d525e 100755 (executable)
@@ -1,7 +1,7 @@
-\r
-perl util\mkfiles.pl >MINFO\r
-perl util\mk1mf.pl no-asm VC-NT >ms\nt.mak\r
-perl util\mk1mf.pl dll no-asm VC-NT >ms\ntdll.mak\r
-\r
-perl util\mkdef.pl libeay NT > ms\libeay32.def\r
-perl util\mkdef.pl ssleay NT > ms\ssleay32.def\r
+
+perl util\mkfiles.pl >MINFO
+perl util\mk1mf.pl no-asm VC-NT >ms\nt.mak
+perl util\mk1mf.pl dll no-asm VC-NT >ms\ntdll.mak
+
+perl util\mkdef.pl libeay NT > ms\libeay32.def
+perl util\mkdef.pl ssleay NT > ms\ssleay32.def
index 825c690..495f1ea 100755 (executable)
@@ -1,9 +1,9 @@
-\r
-perl util\mkfiles.pl >MINFO\r
-perl ms\uplink.pl win64a > ms\uptable.asm\r
-ml64 -c -Foms\uptable.obj ms\uptable.asm\r
-perl util\mk1mf.pl no-asm VC-WIN64A >ms\nt.mak\r
-perl util\mk1mf.pl dll no-asm VC-WIN64A >ms\ntdll.mak\r
-\r
-perl util\mkdef.pl 32 libeay > ms\libeay32.def\r
-perl util\mkdef.pl 32 ssleay > ms\ssleay32.def\r
+
+perl util\mkfiles.pl >MINFO
+perl ms\uplink.pl win64a > ms\uptable.asm
+ml64 -c -Foms\uptable.obj ms\uptable.asm
+perl util\mk1mf.pl no-asm VC-WIN64A >ms\nt.mak
+perl util\mk1mf.pl dll no-asm VC-WIN64A >ms\ntdll.mak
+
+perl util\mkdef.pl 32 libeay > ms\libeay32.def
+perl util\mkdef.pl 32 ssleay > ms\ssleay32.def
index 7bfc2f1..15ebcaa 100755 (executable)
@@ -1,9 +1,9 @@
-\r
-perl util\mkfiles.pl >MINFO\r
-perl ms\uplink.pl win64i > ms\uptable.asm\r
-ias -o ms\uptable.obj ms\uptable.asm\r
-perl util\mk1mf.pl no-asm VC-WIN64I >ms\nt.mak\r
-perl util\mk1mf.pl dll no-asm VC-WIN64I >ms\ntdll.mak\r
-\r
-perl util\mkdef.pl 32 libeay > ms\libeay32.def\r
-perl util\mkdef.pl 32 ssleay > ms\ssleay32.def\r
+
+perl util\mkfiles.pl >MINFO
+perl ms\uplink.pl win64i > ms\uptable.asm
+ias -o ms\uptable.obj ms\uptable.asm
+perl util\mk1mf.pl no-asm VC-WIN64I >ms\nt.mak
+perl util\mk1mf.pl dll no-asm VC-WIN64I >ms\ntdll.mak
+
+perl util\mkdef.pl 32 libeay > ms\libeay32.def
+perl util\mkdef.pl 32 ssleay > ms\ssleay32.def
index f9377a8..06b5733 100644 (file)
@@ -60,10 +60,6 @@ echo RC5\32
 cd crypto\rc5\asm
 perl rc5-586.pl gaswin > r5-win32.s
 cd ..\..\..
-echo CPUID
-cd crypto
-perl x86cpuid.pl gaswin > cpu-win32.s
-cd ..
 
 :noasm
 
@@ -83,7 +79,7 @@ mingw32-make -f ms/mingw32a.mak
 if errorlevel 1 goto end
 
 echo Generating the DLLs and input libraries
-dllwrap --dllname libeay32.dll --output-lib out/libeay32.a --def ms/libeay32.def out/libcrypto.a -lwsock32 -lgdi32
+dllwrap --dllname libeay32.dll --output-lib out/libeay32.a --def ms/libeay32.def out/libcrypto.a -lws2_32 -lgdi32
 if errorlevel 1 goto end
 dllwrap --dllname libssl32.dll --output-lib out/libssl32.a --def ms/ssleay32.def out/libssl.a out/libeay32.a
 if errorlevel 1 goto end
index c5ccd69..35e00a4 100644 (file)
@@ -1,26 +1,26 @@
-@rem OpenSSL with Mingw32\r
-@rem --------------------\r
-\r
-@rem Makefile\r
-perl util\mkfiles.pl >MINFO\r
-perl util\mk1mf.pl Mingw32 >ms\mingw32.mak\r
-@rem DLL definition files\r
-perl util\mkdef.pl 32 libeay >ms\libeay32.def\r
-if errorlevel 1 goto end\r
-perl util\mkdef.pl 32 ssleay >ms\ssleay32.def\r
-if errorlevel 1 goto end\r
-\r
-@rem Build the libraries\r
-make -f ms/mingw32.mak\r
-if errorlevel 1 goto end\r
-\r
-@rem Generate the DLLs and input libraries\r
-dllwrap --dllname libeay32.dll --output-lib out/libeay32.a --def ms/libeay32.def out/libcrypto.a -lwsock32 -lgdi32\r
-if errorlevel 1 goto end\r
-dllwrap --dllname libssl32.dll --output-lib out/libssl32.a --def ms/ssleay32.def out/libssl.a out/libeay32.a\r
-if errorlevel 1 goto end\r
-\r
-echo Done compiling OpenSSL\r
-\r
-:end\r
-\r
+@rem OpenSSL with Mingw32
+@rem --------------------
+
+@rem Makefile
+perl util\mkfiles.pl >MINFO
+perl util\mk1mf.pl Mingw32 >ms\mingw32.mak
+@rem DLL definition files
+perl util\mkdef.pl 32 libeay >ms\libeay32.def
+if errorlevel 1 goto end
+perl util\mkdef.pl 32 ssleay >ms\ssleay32.def
+if errorlevel 1 goto end
+
+@rem Build the libraries
+make -f ms/mingw32.mak
+if errorlevel 1 goto end
+
+@rem Generate the DLLs and input libraries
+dllwrap --dllname libeay32.dll --output-lib out/libeay32.a --def ms/libeay32.def out/libcrypto.a -lws2_32 -lgdi32
+if errorlevel 1 goto end
+dllwrap --dllname libssl32.dll --output-lib out/libssl32.a --def ms/ssleay32.def out/libssl.a out/libeay32.a
+if errorlevel 1 goto end
+
+echo Done compiling OpenSSL
+
+:end
+
diff --git a/deps/openssl/openssl/ms/segrenam.pl b/deps/openssl/openssl/ms/segrenam.pl
deleted file mode 100644 (file)
index 2ab22a0..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-#!/usr/bin/env perl
-
-my $quiet = 1;
-
-unpack("L",pack("N",1))!=1 || die "only little-endian hosts are supported";
-
-# first argument can specify custom suffix...
-$suffix=(@ARGV[0]=~/^\$/) ? shift(@ARGV) : "\$m";
-#################################################################
-# rename segments in COFF modules according to %map table below        #
-%map=( ".text" => "fipstx$suffix",                             #
-       ".text\$"=> "fipstx$suffix",                            #
-       ".rdata"=> "fipsrd$suffix",                             #
-       ".data" => "fipsda$suffix"      );                      #
-#################################################################
-
-# collect file list
-foreach (@ARGV) {
-    if (/\*/)  { push(@files,glob($_)); }
-    else       { push(@files,$_);       }
-}
-
-use Fcntl;
-use Fcntl ":seek";
-
-foreach (@files) {
-    $file=$_;
-    print "processing $file\n" unless $quiet;
-
-    sysopen(FD,$file,O_RDWR|O_BINARY) || die "sysopen($file): $!";
-
-    # read IMAGE_DOS_HEADER
-    sysread(FD,$mz,64)==64 || die "$file is too short";
-    @dos_header=unpack("a2C58I",$mz);
-    if (@dos_header[0] eq "MZ") {
-       $e_lfanew=pop(@dos_header);
-       sysseek(FD,$e_lfanew,SEEK_SET)  || die "$file is too short";
-       sysread(FD,$Magic,4)==4         || die "$file is too short";
-       unpack("I",$Magic)==0x4550      || die "$file is not COFF image";
-    } elsif ($file =~ /\.obj$/i) {
-       # .obj files have no IMAGE_DOS_HEADER
-       sysseek(FD,0,SEEK_SET)          || die "unable to rewind $file";
-    } else { next; }
-
-    # read IMAGE_FILE_HEADER
-    sysread(FD,$coff,20)==20 || die "$file is too short";
-    ($Machine,$NumberOfSections,$TimeDateStamp,
-     $PointerToSymbolTable,$NumberOfSysmbols,
-     $SizeOfOptionalHeader,$Characteristics)=unpack("SSIIISS",$coff);
-
-    # skip over IMAGE_OPTIONAL_HEADER
-    sysseek(FD,$SizeOfOptionalHeader,SEEK_CUR) || die "$file is too short";
-
-    # traverse IMAGE_SECTION_HEADER table
-    for($i=0;$i<$NumberOfSections;$i++) {
-       sysread(FD,$SectionHeader,40)==40 || die "$file is too short";
-       ($Name,@opaque)=unpack("Z8C*",$SectionHeader);
-       if ($map{$Name}) {
-           sysseek(FD,-40,SEEK_CUR) || die "unable to rewind $file";
-           syswrite(FD,pack("a8C*",$map{$Name},@opaque))==40 || die "syswrite failed: $!";
-           printf "    %-8s -> %.8s\n",$Name,$map{$Name} unless $quiet;
-       }
-    }
-    close(FD);
-}
index 466fdfc..a4fa7f3 100755 (executable)
@@ -1,14 +1,14 @@
-rem called by testenc\r
-\r
-echo test %1 %2 %3 %4 %5 %6 \r
-%ssleay% %1 %2 %3 %4 %5 %6 -e -bufsize 113 -k test -in %input% -out %tmp1%\r
-%ssleay% %1 %2 %3 %4 %5 %6 -d -bufsize 157 -k test -in %tmp1% -out %out1%\r
-%cmp% %input% %out1%\r
-if errorlevel 1 goto err\r
-\r
-echo test base64 %1 %2 %3 %4 %5 %6 \r
-%ssleay% %1 %2 %3 %4 %5 %6 -a -e -bufsize 113 -k test -in %input% -out %tmp1%\r
-%ssleay% %1 %2 %3 %4 %5 %6 -a -d -bufsize 157 -k test -in %tmp1% -out %out1%\r
-%cmp% %input% %out1%\r
-\r
-:err\r
+rem called by testenc
+
+echo test %1 %2 %3 %4 %5 %6 
+%ssleay% %1 %2 %3 %4 %5 %6 -e -bufsize 113 -k test -in %input% -out %tmp1%
+%ssleay% %1 %2 %3 %4 %5 %6 -d -bufsize 157 -k test -in %tmp1% -out %out1%
+%cmp% %input% %out1%
+if errorlevel 1 goto err
+
+echo test base64 %1 %2 %3 %4 %5 %6 
+%ssleay% %1 %2 %3 %4 %5 %6 -a -e -bufsize 113 -k test -in %input% -out %tmp1%
+%ssleay% %1 %2 %3 %4 %5 %6 -a -d -bufsize 157 -k test -in %tmp1% -out %out1%
+%cmp% %input% %out1%
+
+:err
index 6a944d7..c8b1acd 100644 (file)
@@ -1,19 +1,19 @@
-rem called by testencce\r
-\r
-echo test %1 %2 %3 %4 %5 %6 \r
-cecopy %input% CE:\OpenSSL\r
-cerun CE:\OpenSSL\%ssleay% %1 %2 %3 %4 %5 %6 -e -bufsize 113 -k test -in \OpenSSL\%input% -out \OpenSSL\%tmp1%\r
-cerun CE:\OpenSSL\%ssleay% %1 %2 %3 %4 %5 %6 -d -bufsize 157 -k test -in \OpenSSL\%tmp1% -out \OpenSSL\%out1%\r
-del %out1% >nul 2>&1\r
-cecopy CE:\OpenSSL\%out1% .\r
-%cmp% %input% %out1%\r
-if errorlevel 1 goto err\r
-\r
-echo test base64 %1 %2 %3 %4 %5 %6 \r
-cerun CE:\OpenSSL\%ssleay% %1 %2 %3 %4 %5 %6 -a -e -bufsize 113 -k test -in \OpenSSL\%input% -out \OpenSSL\%tmp1%\r
-cerun CE:\OpenSSL\%ssleay% %1 %2 %3 %4 %5 %6 -a -d -bufsize 157 -k test -in \OpenSSL\%tmp1% -out \OpenSSL\%out1%\r
-del %out1% >nul 2>&1\r
-cecopy CE:\OpenSSL\%out1% .\r
-%cmp% %input% %out1%\r
-\r
-:err\r
+rem called by testencce
+
+echo test %1 %2 %3 %4 %5 %6 
+cecopy %input% CE:\OpenSSL
+cerun CE:\OpenSSL\%ssleay% %1 %2 %3 %4 %5 %6 -e -bufsize 113 -k test -in \OpenSSL\%input% -out \OpenSSL\%tmp1%
+cerun CE:\OpenSSL\%ssleay% %1 %2 %3 %4 %5 %6 -d -bufsize 157 -k test -in \OpenSSL\%tmp1% -out \OpenSSL\%out1%
+del %out1% >nul 2>&1
+cecopy CE:\OpenSSL\%out1% .
+%cmp% %input% %out1%
+if errorlevel 1 goto err
+
+echo test base64 %1 %2 %3 %4 %5 %6 
+cerun CE:\OpenSSL\%ssleay% %1 %2 %3 %4 %5 %6 -a -e -bufsize 113 -k test -in \OpenSSL\%input% -out \OpenSSL\%tmp1%
+cerun CE:\OpenSSL\%ssleay% %1 %2 %3 %4 %5 %6 -a -d -bufsize 157 -k test -in \OpenSSL\%tmp1% -out \OpenSSL\%out1%
+del %out1% >nul 2>&1
+cecopy CE:\OpenSSL\%out1% .
+%cmp% %input% %out1%
+
+:err
index f729261..f490546 100755 (executable)
@@ -35,10 +35,6 @@ echo md5test
 md5test
 if errorlevel 1 goto done
 
-echo md2test
-md2test
-if errorlevel 1 goto done
-
 echo rc2test
 rc2test
 if errorlevel 1 goto done
@@ -181,7 +177,6 @@ echo test sslv2/sslv3 with both client and server authentication via BIO pair
 %SSL_TEST% -bio_pair -server_auth -client_auth
 if errorlevel 1 goto done
 
-
 echo passed all tests
 goto end
 :done
index 4b99bd5..f8e9093 100755 (executable)
@@ -1,94 +1,94 @@
-@echo off\r
-echo start testenc\r
-\r
-path=..\ms;%path%\r
-set ssleay=%1%\r
-set input=..\ms\testenc.bat\r
-set tmp1=..\ms\cipher.out\r
-set out1=..\ms\clear.out\r
-set cmp=perl ..\ms\cmp.pl\r
-\r
-cd\r
-call tenc.bat enc\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat rc4\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat des-cfb\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat des-ede-cfb\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat des-ede3-cfb\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat des-ofb\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat des-ede-ofb\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat des-ede3-ofb\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat des-ecb\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat des-ede\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat des-ede3\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat des-cbc\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat des-ede-cbc\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat des-ede3-cbc\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat idea-ecb\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat idea-cfb\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat idea-ofb\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat idea-cbc\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat rc2-ecb\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat rc2-cfb\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat rc2-ofb\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat rc2-cbc\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat bf-ecb\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat bf-cfb\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat bf-ofb\r
-if errorlevel 1 goto err\r
-\r
-call tenc.bat bf-cbc\r
-if errorlevel 1 goto err\r
-\r
-echo OK\r
-del %out1%\r
-del %tmp1%\r
-:err\r
-\r
+@echo off
+echo start testenc
+
+path=..\ms;%path%
+set ssleay=%1%
+set input=..\ms\testenc.bat
+set tmp1=..\ms\cipher.out
+set out1=..\ms\clear.out
+set cmp=perl ..\ms\cmp.pl
+
+cd
+call tenc.bat enc
+if errorlevel 1 goto err
+
+call tenc.bat rc4
+if errorlevel 1 goto err
+
+call tenc.bat des-cfb
+if errorlevel 1 goto err
+
+call tenc.bat des-ede-cfb
+if errorlevel 1 goto err
+
+call tenc.bat des-ede3-cfb
+if errorlevel 1 goto err
+
+call tenc.bat des-ofb
+if errorlevel 1 goto err
+
+call tenc.bat des-ede-ofb
+if errorlevel 1 goto err
+
+call tenc.bat des-ede3-ofb
+if errorlevel 1 goto err
+
+call tenc.bat des-ecb
+if errorlevel 1 goto err
+
+call tenc.bat des-ede
+if errorlevel 1 goto err
+
+call tenc.bat des-ede3
+if errorlevel 1 goto err
+
+call tenc.bat des-cbc
+if errorlevel 1 goto err
+
+call tenc.bat des-ede-cbc
+if errorlevel 1 goto err
+
+call tenc.bat des-ede3-cbc
+if errorlevel 1 goto err
+
+call tenc.bat idea-ecb
+if errorlevel 1 goto err
+
+call tenc.bat idea-cfb
+if errorlevel 1 goto err
+
+call tenc.bat idea-ofb
+if errorlevel 1 goto err
+
+call tenc.bat idea-cbc
+if errorlevel 1 goto err
+
+call tenc.bat rc2-ecb
+if errorlevel 1 goto err
+
+call tenc.bat rc2-cfb
+if errorlevel 1 goto err
+
+call tenc.bat rc2-ofb
+if errorlevel 1 goto err
+
+call tenc.bat rc2-cbc
+if errorlevel 1 goto err
+
+call tenc.bat bf-ecb
+if errorlevel 1 goto err
+
+call tenc.bat bf-cfb
+if errorlevel 1 goto err
+
+call tenc.bat bf-ofb
+if errorlevel 1 goto err
+
+call tenc.bat bf-cbc
+if errorlevel 1 goto err
+
+echo OK
+del %out1%
+del %tmp1%
+:err
+
index 04faa5d..1da3e08 100644 (file)
@@ -1,97 +1,97 @@
-@echo off\r
-echo start testenc\r
-\r
-path=..\ms;%path%\r
-set ssleay=%1%\r
-copy ..\ms\testenc.bat >nul\r
-set input=testenc.bat\r
-set tmp1=cipher.out\r
-set out1=clear.out\r
-set cmp=perl ..\ms\cmp.pl\r
-\r
-cecopy %ssleay% CE:\OpenSSL\r
-\r
-cd\r
-call tencce.bat enc\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat rc4\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat des-cfb\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat des-ede-cfb\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat des-ede3-cfb\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat des-ofb\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat des-ede-ofb\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat des-ede3-ofb\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat des-ecb\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat des-ede\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat des-ede3\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat des-cbc\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat des-ede-cbc\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat des-ede3-cbc\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat idea-ecb\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat idea-cfb\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat idea-ofb\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat idea-cbc\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat rc2-ecb\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat rc2-cfb\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat rc2-ofb\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat rc2-cbc\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat bf-ecb\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat bf-cfb\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat bf-ofb\r
-if errorlevel 1 goto err\r
-\r
-call tencce.bat bf-cbc\r
-if errorlevel 1 goto err\r
-\r
-echo OK\r
-del %out1% >nul 2>&1\r
-del %tmp1% >nul 2>&1\r
-:err\r
-\r
+@echo off
+echo start testenc
+
+path=..\ms;%path%
+set ssleay=%1%
+copy ..\ms\testenc.bat >nul
+set input=testenc.bat
+set tmp1=cipher.out
+set out1=clear.out
+set cmp=perl ..\ms\cmp.pl
+
+cecopy %ssleay% CE:\OpenSSL
+
+cd
+call tencce.bat enc
+if errorlevel 1 goto err
+
+call tencce.bat rc4
+if errorlevel 1 goto err
+
+call tencce.bat des-cfb
+if errorlevel 1 goto err
+
+call tencce.bat des-ede-cfb
+if errorlevel 1 goto err
+
+call tencce.bat des-ede3-cfb
+if errorlevel 1 goto err
+
+call tencce.bat des-ofb
+if errorlevel 1 goto err
+
+call tencce.bat des-ede-ofb
+if errorlevel 1 goto err
+
+call tencce.bat des-ede3-ofb
+if errorlevel 1 goto err
+
+call tencce.bat des-ecb
+if errorlevel 1 goto err
+
+call tencce.bat des-ede
+if errorlevel 1 goto err
+
+call tencce.bat des-ede3
+if errorlevel 1 goto err
+
+call tencce.bat des-cbc
+if errorlevel 1 goto err
+
+call tencce.bat des-ede-cbc
+if errorlevel 1 goto err
+
+call tencce.bat des-ede3-cbc
+if errorlevel 1 goto err
+
+call tencce.bat idea-ecb
+if errorlevel 1 goto err
+
+call tencce.bat idea-cfb
+if errorlevel 1 goto err
+
+call tencce.bat idea-ofb
+if errorlevel 1 goto err
+
+call tencce.bat idea-cbc
+if errorlevel 1 goto err
+
+call tencce.bat rc2-ecb
+if errorlevel 1 goto err
+
+call tencce.bat rc2-cfb
+if errorlevel 1 goto err
+
+call tencce.bat rc2-ofb
+if errorlevel 1 goto err
+
+call tencce.bat rc2-cbc
+if errorlevel 1 goto err
+
+call tencce.bat bf-ecb
+if errorlevel 1 goto err
+
+call tencce.bat bf-cfb
+if errorlevel 1 goto err
+
+call tencce.bat bf-ofb
+if errorlevel 1 goto err
+
+call tencce.bat bf-cbc
+if errorlevel 1 goto err
+
+echo OK
+del %out1% >nul 2>&1
+del %tmp1% >nul 2>&1
+:err
+
index 005f13b..8b2e844 100755 (executable)
@@ -1,32 +1,32 @@
-@echo off\r
-set ssleay=%1%\r
-set tmp1=pem.out\r
-set cmp=fc.exe\r
-\r
-call tpem.bat crl ..\test\testcrl.pem\r
-if errorlevel 1 goto err\r
-\r
-call tpem.bat pkcs7 ..\test\testp7.pem\r
-if errorlevel 1 goto err\r
-\r
-call tpem.bat req ..\test\testreq2.pem\r
-if errorlevel 1 goto err\r
-\r
-call tpem.bat rsa ..\test\testrsa.pem\r
-if errorlevel 1 goto err\r
-\r
-call tpem.bat x509 ..\test\testx509.pem\r
-if errorlevel 1 goto err\r
-\r
-call tpem.bat x509 ..\test\v3-cert1.pem\r
-if errorlevel 1 goto err\r
-\r
-call tpem.bat x509 ..\test\v3-cert1.pem\r
-if errorlevel 1 goto err\r
-\r
-call tpem.bat sess_id ..\test\testsid.pem\r
-if errorlevel 1 goto err\r
-\r
-echo OK\r
-del %tmp1%\r
-:err\r
+@echo off
+set ssleay=%1%
+set tmp1=pem.out
+set cmp=fc.exe
+
+call tpem.bat crl ..\test\testcrl.pem
+if errorlevel 1 goto err
+
+call tpem.bat pkcs7 ..\test\testp7.pem
+if errorlevel 1 goto err
+
+call tpem.bat req ..\test\testreq2.pem
+if errorlevel 1 goto err
+
+call tpem.bat rsa ..\test\testrsa.pem
+if errorlevel 1 goto err
+
+call tpem.bat x509 ..\test\testx509.pem
+if errorlevel 1 goto err
+
+call tpem.bat x509 ..\test\v3-cert1.pem
+if errorlevel 1 goto err
+
+call tpem.bat x509 ..\test\v3-cert1.pem
+if errorlevel 1 goto err
+
+call tpem.bat sess_id ..\test\testsid.pem
+if errorlevel 1 goto err
+
+echo OK
+del %tmp1%
+:err
index c793c3e..ac64a79 100644 (file)
@@ -1,42 +1,42 @@
-@echo off\r
-set ssleay=%1%\r
-set tmp1=pem.out\r
-set cmp=fc.exe\r
-\r
-cecopy %ssleay% CE:\OpenSSL\r
-\r
-copy ..\test\testcrl.pem >nul\r
-call tpemce.bat crl testcrl.pem\r
-if errorlevel 1 goto err\r
-\r
-copy ..\test\testp7.pem >nul\r
-call tpemce.bat pkcs7 testp7.pem\r
-if errorlevel 1 goto err\r
-\r
-copy ..\test\testreq2.pem >nul\r
-call tpemce.bat req testreq2.pem\r
-if errorlevel 1 goto err\r
-\r
-copy ..\test\testrsa.pem >nul\r
-call tpemce.bat rsa testrsa.pem\r
-if errorlevel 1 goto err\r
-\r
-copy ..\test\testx509.pem >nul\r
-call tpemce.bat x509 testx509.pem\r
-if errorlevel 1 goto err\r
-\r
-copy ..\test\v3-cert1.pem >nul\r
-call tpemce.bat x509 v3-cert1.pem\r
-if errorlevel 1 goto err\r
-\r
-copy ..\test\v3-cert1.pem >nul\r
-call tpemce.bat x509 v3-cert1.pem\r
-if errorlevel 1 goto err\r
-\r
-copy ..\test\testsid.pem >nul\r
-call tpemce.bat sess_id testsid.pem\r
-if errorlevel 1 goto err\r
-\r
-echo OK\r
-del %tmp1% >nul 2>&1\r
-:err\r
+@echo off
+set ssleay=%1%
+set tmp1=pem.out
+set cmp=fc.exe
+
+cecopy %ssleay% CE:\OpenSSL
+
+copy ..\test\testcrl.pem >nul
+call tpemce.bat crl testcrl.pem
+if errorlevel 1 goto err
+
+copy ..\test\testp7.pem >nul
+call tpemce.bat pkcs7 testp7.pem
+if errorlevel 1 goto err
+
+copy ..\test\testreq2.pem >nul
+call tpemce.bat req testreq2.pem
+if errorlevel 1 goto err
+
+copy ..\test\testrsa.pem >nul
+call tpemce.bat rsa testrsa.pem
+if errorlevel 1 goto err
+
+copy ..\test\testx509.pem >nul
+call tpemce.bat x509 testx509.pem
+if errorlevel 1 goto err
+
+copy ..\test\v3-cert1.pem >nul
+call tpemce.bat x509 v3-cert1.pem
+if errorlevel 1 goto err
+
+copy ..\test\v3-cert1.pem >nul
+call tpemce.bat x509 v3-cert1.pem
+if errorlevel 1 goto err
+
+copy ..\test\testsid.pem >nul
+call tpemce.bat sess_id testsid.pem
+if errorlevel 1 goto err
+
+echo OK
+del %tmp1% >nul 2>&1
+:err
index b4aaf3c..5afa131 100755 (executable)
@@ -1,98 +1,98 @@
-@echo off\r
-\r
-rem set ssleay=..\out\ssleay\r
-set ssleay=%1\r
-\r
-set reqcmd=%ssleay% req\r
-set x509cmd=%ssleay% x509 -sha1\r
-set verifycmd=%ssleay% verify\r
-\r
-set CAkey=keyCA.ss\r
-set CAcert=certCA.ss\r
-set CAserial=certCA.srl\r
-set CAreq=reqCA.ss\r
-set CAconf=..\test\CAss.cnf\r
-set CAreq2=req2CA.ss   \r
-\r
-set Uconf=..\test\Uss.cnf\r
-set Ukey=keyU.ss\r
-set Ureq=reqU.ss\r
-set Ucert=certU.ss\r
-\r
-echo make a certificate request using 'req'\r
-%reqcmd% -config %CAconf% -out %CAreq% -keyout %CAkey% -new\r
-if errorlevel 1 goto e_req\r
-\r
-echo convert the certificate request into a self signed certificate using 'x509'\r
-%x509cmd% -CAcreateserial -in %CAreq% -days 30 -req -out %CAcert% -signkey %CAkey% >err.ss\r
-if errorlevel 1 goto e_x509\r
-\r
-echo --\r
-echo convert a certificate into a certificate request using 'x509'\r
-%x509cmd% -in %CAcert% -x509toreq -signkey %CAkey% -out %CAreq2% >err.ss\r
-if errorlevel 1 goto e_x509_2\r
-\r
-%reqcmd% -verify -in %CAreq% -noout\r
-if errorlevel 1 goto e_vrfy_1\r
-\r
-%reqcmd% -verify -in %CAreq2% -noout\r
-if errorlevel 1 goto e_vrfy_2\r
-\r
-%verifycmd% -CAfile %CAcert% %CAcert%\r
-if errorlevel 1 goto e_vrfy_3\r
-\r
-echo --\r
-echo make another certificate request using 'req'\r
-%reqcmd% -config %Uconf% -out %Ureq% -keyout %Ukey% -new >err.ss\r
-if errorlevel 1 goto e_req_gen\r
-\r
-echo --\r
-echo sign certificate request with the just created CA via 'x509'\r
-%x509cmd% -CAcreateserial -in %Ureq% -days 30 -req -out %Ucert% -CA %CAcert% -CAkey %CAkey% -CAserial %CAserial%\r
-if errorlevel 1 goto e_x_sign\r
-\r
-%verifycmd% -CAfile %CAcert% %Ucert%\r
-echo --\r
-echo Certificate details\r
-%x509cmd% -subject -issuer -startdate -enddate -noout -in %Ucert%\r
-\r
-echo Everything appeared to work\r
-echo --\r
-echo The generated CA certificate is %CAcert%\r
-echo The generated CA private key is %CAkey%\r
-echo The current CA signing serial number is in %CAserial%\r
-\r
-echo The generated user certificate is %Ucert%\r
-echo The generated user private key is %Ukey%\r
-echo --\r
-\r
-del err.ss\r
-\r
-goto end\r
-\r
-:e_req\r
-echo error using 'req' to generate a certificate request\r
-goto end\r
-:e_x509\r
-echo error using 'x509' to self sign a certificate request\r
-goto end\r
-:e_x509_2\r
-echo error using 'x509' convert a certificate to a certificate request\r
-goto end\r
-:e_vrfy_1\r
-echo first generated request is invalid\r
-goto end\r
-:e_vrfy_2\r
-echo second generated request is invalid\r
-goto end\r
-:e_vrfy_3\r
-echo first generated cert is invalid\r
-goto end\r
-:e_req_gen\r
-echo error using 'req' to generate a certificate request\r
-goto end\r
-:e_x_sign\r
-echo error using 'x509' to sign a certificate request\r
-goto end\r
-\r
-:end\r
+@echo off
+
+rem set ssleay=..\out\ssleay
+set ssleay=%1
+
+set reqcmd=%ssleay% req
+set x509cmd=%ssleay% x509 -sha1
+set verifycmd=%ssleay% verify
+
+set CAkey=keyCA.ss
+set CAcert=certCA.ss
+set CAserial=certCA.srl
+set CAreq=reqCA.ss
+set CAconf=..\test\CAss.cnf
+set CAreq2=req2CA.ss   
+
+set Uconf=..\test\Uss.cnf
+set Ukey=keyU.ss
+set Ureq=reqU.ss
+set Ucert=certU.ss
+
+echo make a certificate request using 'req'
+%reqcmd% -config %CAconf% -out %CAreq% -keyout %CAkey% -new
+if errorlevel 1 goto e_req
+
+echo convert the certificate request into a self signed certificate using 'x509'
+%x509cmd% -CAcreateserial -in %CAreq% -days 30 -req -out %CAcert% -signkey %CAkey% >err.ss
+if errorlevel 1 goto e_x509
+
+echo --
+echo convert a certificate into a certificate request using 'x509'
+%x509cmd% -in %CAcert% -x509toreq -signkey %CAkey% -out %CAreq2% >err.ss
+if errorlevel 1 goto e_x509_2
+
+%reqcmd% -verify -in %CAreq% -noout
+if errorlevel 1 goto e_vrfy_1
+
+%reqcmd% -verify -in %CAreq2% -noout
+if errorlevel 1 goto e_vrfy_2
+
+%verifycmd% -CAfile %CAcert% %CAcert%
+if errorlevel 1 goto e_vrfy_3
+
+echo --
+echo make another certificate request using 'req'
+%reqcmd% -config %Uconf% -out %Ureq% -keyout %Ukey% -new >err.ss
+if errorlevel 1 goto e_req_gen
+
+echo --
+echo sign certificate request with the just created CA via 'x509'
+%x509cmd% -CAcreateserial -in %Ureq% -days 30 -req -out %Ucert% -CA %CAcert% -CAkey %CAkey% -CAserial %CAserial%
+if errorlevel 1 goto e_x_sign
+
+%verifycmd% -CAfile %CAcert% %Ucert%
+echo --
+echo Certificate details
+%x509cmd% -subject -issuer -startdate -enddate -noout -in %Ucert%
+
+echo Everything appeared to work
+echo --
+echo The generated CA certificate is %CAcert%
+echo The generated CA private key is %CAkey%
+echo The current CA signing serial number is in %CAserial%
+
+echo The generated user certificate is %Ucert%
+echo The generated user private key is %Ukey%
+echo --
+
+del err.ss
+
+goto end
+
+:e_req
+echo error using 'req' to generate a certificate request
+goto end
+:e_x509
+echo error using 'x509' to self sign a certificate request
+goto end
+:e_x509_2
+echo error using 'x509' convert a certificate to a certificate request
+goto end
+:e_vrfy_1
+echo first generated request is invalid
+goto end
+:e_vrfy_2
+echo second generated request is invalid
+goto end
+:e_vrfy_3
+echo first generated cert is invalid
+goto end
+:e_req_gen
+echo error using 'req' to generate a certificate request
+goto end
+:e_x_sign
+echo error using 'x509' to sign a certificate request
+goto end
+
+:end
index dbb25ab..18381ed 100644 (file)
-rem set ssleay=..\out\ssleay\r
-set ssleay=%1\r
-\r
-set reqcmd=%ssleay% req\r
-set x509cmd=%ssleay% x509\r
-set verifycmd=%ssleay% verify\r
-\r
-set CAkey=\OpenSSL\keyCA.ss\r
-set CAcert=\OpenSSL\certCA.ss\r
-set CAserial=\OpenSSL\certCA.srl\r
-set CAreq=\OpenSSL\reqCA.ss\r
-cecopy ..\test\CAss.cnf CE:\OpenSSL\r
-set CAconf=\OpenSSL\CAss.cnf\r
-set CAreq2=\OpenSSL\req2CA.ss  \r
-\r
-cecopy ..\test\Uss.cnf CE:\OpenSSL\r
-set Uconf=\OpenSSL\Uss.cnf\r
-set Ukey=\OpenSSL\keyU.ss\r
-set Ureq=\OpenSSL\reqU.ss\r
-set Ucert=\OpenSSL\certU.ss\r
-\r
-echo make a certificate request using 'req'\r
-cerun CE:\OpenSSL\%reqcmd% -config %CAconf% -out %CAreq% -keyout %CAkey% -new\r
-if errorlevel 1 goto e_req\r
-\r
-echo convert the certificate request into a self signed certificate using 'x509'\r
-cerun CE:\OpenSSL\%x509cmd% -CAcreateserial -in %CAreq% -days 30 -req -out %CAcert% -signkey %CAkey% "> \OpenSSL\err.ss"\r
-if errorlevel 1 goto e_x509\r
-\r
-echo --\r
-echo convert a certificate into a certificate request using 'x509'\r
-cerun CE:\OpenSSL\%x509cmd% -in %CAcert% -x509toreq -signkey %CAkey% -out %CAreq2% "> \OpenSSL\err.ss"\r
-if errorlevel 1 goto e_x509_2\r
-\r
-cerun CE:\OpenSSL\%reqcmd% -verify -in %CAreq% -noout\r
-if errorlevel 1 goto e_vrfy_1\r
-\r
-cerun CE:\OpenSSL\%reqcmd% -verify -in %CAreq2% -noout\r
-if errorlevel 1 goto e_vrfy_2\r
-\r
-cerun CE:\OpenSSL\%verifycmd% -CAfile %CAcert% %CAcert%\r
-if errorlevel 1 goto e_vrfy_3\r
-\r
-echo --\r
-echo make another certificate request using 'req'\r
-cerun CE:\OpenSSL\%reqcmd% -config %Uconf% -out %Ureq% -keyout %Ukey% -new "> \OpenSSL\err.ss"\r
-if errorlevel 1 goto e_req_gen\r
-\r
-echo --\r
-echo sign certificate request with the just created CA via 'x509'\r
-cerun CE:\OpenSSL\%x509cmd% -CAcreateserial -in %Ureq% -days 30 -req -out %Ucert% -CA %CAcert% -CAkey %CAkey% -CAserial %CAserial%\r
-if errorlevel 1 goto e_x_sign\r
-\r
-cerun CE:\OpenSSL\%verifycmd% -CAfile %CAcert% %Ucert%\r
-echo --\r
-echo Certificate details\r
-cerun CE:\OpenSSL\%x509cmd% -subject -issuer -startdate -enddate -noout -in %Ucert%\r
-\r
-cecopy CE:%CAcert% .\r
-cecopy CE:%CAkey% .\r
-cecopy CE:%CAserial% .\r
-cecopy CE:%Ucert% .\r
-cecopy CE:%Ukey% .\r
-\r
-echo Everything appeared to work\r
-echo --\r
-echo The generated CA certificate is %CAcert%\r
-echo The generated CA private key is %CAkey%\r
-echo The current CA signing serial number is in %CAserial%\r
-\r
-echo The generated user certificate is %Ucert%\r
-echo The generated user private key is %Ukey%\r
-echo --\r
-\r
-cedel CE:\OpenSSL\err.ss\r
-\r
-goto end\r
-\r
-:e_req\r
-echo error using 'req' to generate a certificate request\r
-goto end\r
-:e_x509\r
-echo error using 'x509' to self sign a certificate request\r
-goto end\r
-:e_x509_2\r
-echo error using 'x509' convert a certificate to a certificate request\r
-goto end\r
-:e_vrfy_1\r
-echo first generated request is invalid\r
-goto end\r
-:e_vrfy_2\r
-echo second generated request is invalid\r
-goto end\r
-:e_vrfy_3\r
-echo first generated cert is invalid\r
-goto end\r
-:e_req_gen\r
-echo error using 'req' to generate a certificate request\r
-goto end\r
-:e_x_sign\r
-echo error using 'x509' to sign a certificate request\r
-goto end\r
-\r
-:end\r
+rem set ssleay=..\out\ssleay
+set ssleay=%1
+
+set reqcmd=%ssleay% req
+set x509cmd=%ssleay% x509
+set verifycmd=%ssleay% verify
+
+set CAkey=\OpenSSL\keyCA.ss
+set CAcert=\OpenSSL\certCA.ss
+set CAserial=\OpenSSL\certCA.srl
+set CAreq=\OpenSSL\reqCA.ss
+cecopy ..\test\CAss.cnf CE:\OpenSSL
+set CAconf=\OpenSSL\CAss.cnf
+set CAreq2=\OpenSSL\req2CA.ss  
+
+cecopy ..\test\Uss.cnf CE:\OpenSSL
+set Uconf=\OpenSSL\Uss.cnf
+set Ukey=\OpenSSL\keyU.ss
+set Ureq=\OpenSSL\reqU.ss
+set Ucert=\OpenSSL\certU.ss
+
+echo make a certificate request using 'req'
+cerun CE:\OpenSSL\%reqcmd% -config %CAconf% -out %CAreq% -keyout %CAkey% -new
+if errorlevel 1 goto e_req
+
+echo convert the certificate request into a self signed certificate using 'x509'
+cerun CE:\OpenSSL\%x509cmd% -CAcreateserial -in %CAreq% -days 30 -req -out %CAcert% -signkey %CAkey% "> \OpenSSL\err.ss"
+if errorlevel 1 goto e_x509
+
+echo --
+echo convert a certificate into a certificate request using 'x509'
+cerun CE:\OpenSSL\%x509cmd% -in %CAcert% -x509toreq -signkey %CAkey% -out %CAreq2% "> \OpenSSL\err.ss"
+if errorlevel 1 goto e_x509_2
+
+cerun CE:\OpenSSL\%reqcmd% -verify -in %CAreq% -noout
+if errorlevel 1 goto e_vrfy_1
+
+cerun CE:\OpenSSL\%reqcmd% -verify -in %CAreq2% -noout
+if errorlevel 1 goto e_vrfy_2
+
+cerun CE:\OpenSSL\%verifycmd% -CAfile %CAcert% %CAcert%
+if errorlevel 1 goto e_vrfy_3
+
+echo --
+echo make another certificate request using 'req'
+cerun CE:\OpenSSL\%reqcmd% -config %Uconf% -out %Ureq% -keyout %Ukey% -new "> \OpenSSL\err.ss"
+if errorlevel 1 goto e_req_gen
+
+echo --
+echo sign certificate request with the just created CA via 'x509'
+cerun CE:\OpenSSL\%x509cmd% -CAcreateserial -in %Ureq% -days 30 -req -out %Ucert% -CA %CAcert% -CAkey %CAkey% -CAserial %CAserial%
+if errorlevel 1 goto e_x_sign
+
+cerun CE:\OpenSSL\%verifycmd% -CAfile %CAcert% %Ucert%
+echo --
+echo Certificate details
+cerun CE:\OpenSSL\%x509cmd% -subject -issuer -startdate -enddate -noout -in %Ucert%
+
+cecopy CE:%CAcert% .
+cecopy CE:%CAkey% .
+cecopy CE:%CAserial% .
+cecopy CE:%Ucert% .
+cecopy CE:%Ukey% .
+
+echo Everything appeared to work
+echo --
+echo The generated CA certificate is %CAcert%
+echo The generated CA private key is %CAkey%
+echo The current CA signing serial number is in %CAserial%
+
+echo The generated user certificate is %Ucert%
+echo The generated user private key is %Ukey%
+echo --
+
+cedel CE:\OpenSSL\err.ss
+
+goto end
+
+:e_req
+echo error using 'req' to generate a certificate request
+goto end
+:e_x509
+echo error using 'x509' to self sign a certificate request
+goto end
+:e_x509_2
+echo error using 'x509' convert a certificate to a certificate request
+goto end
+:e_vrfy_1
+echo first generated request is invalid
+goto end
+:e_vrfy_2
+echo second generated request is invalid
+goto end
+:e_vrfy_3
+echo first generated cert is invalid
+goto end
+:e_req_gen
+echo error using 'req' to generate a certificate request
+goto end
+:e_x_sign
+echo error using 'x509' to sign a certificate request
+goto end
+
+:end
index 7fc7a83..cd01792 100755 (executable)
@@ -1,6 +1,6 @@
-rem called by testpem\r
-\r
-echo test %1 %2\r
-%ssleay% %1 -in %2 -out %tmp1%\r
-%cmp% %2 %tmp1%\r
-\r
+rem called by testpem
+
+echo test %1 %2
+%ssleay% %1 -in %2 -out %tmp1%
+%cmp% %2 %tmp1%
+
index 17b2acd..483f559 100644 (file)
@@ -1,8 +1,8 @@
-rem called by testpemce\r
-\r
-echo test %1 %2\r
-cecopy %2 CE:\OpenSSL\r
-cerun CE:\OpenSSL\%ssleay% %1 -in \OpenSSL\%2 -out \OpenSSL\%tmp1%\r
-del %tmp1% >nul 2>&1\r
-cecopy CE:\OpenSSL\%tmp1% .\r
-%cmp% %2 %tmp1%\r
+rem called by testpemce
+
+echo test %1 %2
+cecopy %2 CE:\OpenSSL
+cerun CE:\OpenSSL\%ssleay% %1 -in \OpenSSL\%2 -out \OpenSSL\%tmp1%
+del %tmp1% >nul 2>&1
+cecopy CE:\OpenSSL\%tmp1% .
+%cmp% %2 %tmp1%
diff --git a/deps/openssl/openssl/ms/uplink-common.pl b/deps/openssl/openssl/ms/uplink-common.pl
new file mode 100644 (file)
index 0000000..1d20e6e
--- /dev/null
@@ -0,0 +1,22 @@
+#!/usr/bin/env perl
+#
+# pull APPLINK_MAX value from applink.c...
+$applink_c=$0;
+$applink_c=~s|[^/\\]+$||g;
+$applink_c.="applink.c";
+open(INPUT,$applink_c) || die "can't open $applink_c: $!";
+@max=grep {/APPLINK_MAX\s+(\d+)/} <INPUT>;
+close(INPUT);
+($#max==0) or die "can't find APPLINK_MAX in $applink_c";
+
+$max[0]=~/APPLINK_MAX\s+(\d+)/;
+$N=$1; # number of entries in OPENSSL_UplinkTable not including
+       # OPENSSL_UplinkTable[0], which contains this value...
+
+1;
+
+# Idea is to fill the OPENSSL_UplinkTable with pointers to stubs
+# which invoke 'void OPENSSL_Uplink (ULONG_PTR *table,int index)';
+# and then dereference themselves. Latter shall result in endless
+# loop *unless* OPENSSL_Uplink does not replace 'table[index]' with
+# something else, e.g. as 'table[index]=unimplemented;'...
diff --git a/deps/openssl/openssl/ms/uplink-ia64.pl b/deps/openssl/openssl/ms/uplink-ia64.pl
new file mode 100644 (file)
index 0000000..4204c73
--- /dev/null
@@ -0,0 +1,50 @@
+#!/usr/bin/env perl
+
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+push(@INC,"${dir}.");
+
+require "uplink-common.pl";
+
+local $V=8;    # max number of args uplink functions may accept...
+my $loc0 = "r".(32+$V);
+print <<___;
+.text
+.global        OPENSSL_Uplink#
+.type  OPENSSL_Uplink#,\@function
+
+___
+for ($i=1;$i<=$N;$i++) {
+print <<___;
+.proc  lazy$i#
+lazy$i:
+       .prologue
+{ .mii;        .save   ar.pfs,$loc0
+       alloc   loc0=ar.pfs,$V,3,2,0
+       .save   b0,loc1
+       mov     loc1=b0
+       addl    loc2=\@ltoff(OPENSSL_UplinkTable#),gp   };;
+       .body
+{ .mmi;        ld8     out0=[loc2]
+       mov     out1=$i                                 };;
+{ .mib;        add     loc2=8*$i,out0
+       br.call.sptk.many       b0=OPENSSL_Uplink#      };;
+{ .mmi;        ld8     r31=[loc2];;
+       ld8     r30=[r31],8                             };;
+{ .mii;        ld8     gp=[r31]
+       mov     b6=r30
+       mov     b0=loc1                                 };;
+{ .mib;        mov     ar.pfs=loc0
+       br.many b6                                      };;
+.endp  lazy$i#
+
+___
+}
+print <<___;
+.data
+.global OPENSSL_UplinkTable#
+OPENSSL_UplinkTable:    data8   $N      // amount of following entries
+___
+for ($i=1;$i<=$N;$i++) {   print "      data8   \@fptr(lazy$i#)\n";   }
+print <<___;
+.size   OPENSSL_UplinkTable,.-OPENSSL_UplinkTable#
+___
diff --git a/deps/openssl/openssl/ms/uplink-x86.pl b/deps/openssl/openssl/ms/uplink-x86.pl
new file mode 100644 (file)
index 0000000..0dffc14
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/env perl
+
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+push(@INC, "${dir}.", "${dir}../crypto/perlasm");
+require "x86asm.pl";
+
+require "uplink-common.pl";
+
+&asm_init($ARGV[0],"uplink-x86");
+
+&external_label("OPENSSL_Uplink");
+&public_label("OPENSSL_UplinkTable");
+
+for ($i=1;$i<=$N;$i++) {
+&function_begin_B("_\$lazy${i}");
+       &lea    ("eax",&DWP(&label("OPENSSL_UplinkTable")));
+       &push   ("eax");
+       &push   ($i);
+       &call   (&label("OPENSSL_Uplink"));
+       &add    ("esp",8);
+       &pop    ("eax");
+       &jmp_ptr(&DWP(4*$i,"eax"));
+&function_end_B("_\$lazy${i}");
+}
+
+&dataseg();
+&align(4);
+&set_label("OPENSSL_UplinkTable");
+&data_word($N);
+for ($i=1;$i<=$N;$i++) {
+&data_word(&label("_\$lazy${i}"));
+}
+&asm_finish();
diff --git a/deps/openssl/openssl/ms/uplink-x86_64.pl b/deps/openssl/openssl/ms/uplink-x86_64.pl
new file mode 100644 (file)
index 0000000..9acbf6b
--- /dev/null
@@ -0,0 +1,64 @@
+#!/usr/bin/env perl
+
+$output=shift;
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+open STDOUT,"| $^X ${dir}../crypto/perlasm/x86_64-xlate.pl $output";
+push(@INC,"${dir}.");
+
+require "uplink-common.pl";
+
+$prefix="_lazy";
+
+print <<___;
+.text
+.extern        OPENSSL_Uplink
+.globl OPENSSL_UplinkTable
+___
+for ($i=1;$i<=$N;$i++) {
+print <<___;
+.type  $prefix${i},\@abi-omnipotent
+.align 16
+$prefix${i}:
+       .byte   0x48,0x83,0xEC,0x28     # sub rsp,40
+       mov     %rcx,48(%rsp)
+       mov     %rdx,56(%rsp)
+       mov     %r8,64(%rsp)
+       mov     %r9,72(%rsp)
+       lea     OPENSSL_UplinkTable(%rip),%rcx
+       mov     \$$i,%rdx
+       call    OPENSSL_Uplink
+       mov     48(%rsp),%rcx
+       mov     56(%rsp),%rdx
+       mov     64(%rsp),%r8
+       mov     72(%rsp),%r9
+       lea     OPENSSL_UplinkTable(%rip),%rax
+       add     \$40,%rsp
+       jmp     *8*$i(%rax)
+$prefix${i}_end:
+.size  $prefix${i},.-$prefix${i}
+___
+}
+print <<___;
+.data
+OPENSSL_UplinkTable:
+        .quad   $N
+___
+for ($i=1;$i<=$N;$i++) {   print "      .quad   $prefix$i\n";   }
+print <<___;
+.section       .pdata,"r"
+.align         4
+___
+for ($i=1;$i<=$N;$i++) {
+print <<___;
+       .rva    $prefix${i},$prefix${i}_end,${prefix}_unwind_info
+___
+}
+print <<___;
+.section       .xdata,"r"
+.align         8
+${prefix}_unwind_info:
+       .byte   0x01,0x04,0x01,0x00
+       .byte   0x04,0x42,0x00,0x00
+___
+
+close STDOUT;
index 7b7da08..6d59cb1 100644 (file)
@@ -40,7 +40,8 @@ void OPENSSL_Uplink (volatile void **table, int index)
      * should be sufficient [it prohibits compiler to reorder memory
      * access instructions]. */
     do {
-       len = _stprintf (msg,_T("OPENSSL_Uplink(%p,%02X): "),table,index);
+       len = _sntprintf (msg,sizeof(msg)/sizeof(TCHAR),
+                         _T("OPENSSL_Uplink(%p,%02X): "),table,index);
        _tcscpy (msg+len,_T("unimplemented function"));
 
        if ((h=apphandle)==NULL)
index ba26637..03563c6 100755 (executable)
@@ -1,63 +1,57 @@
 
 @echo off
+echo Generating x86 assember
+
 echo Bignum
 cd crypto\bn\asm
-perl x86.pl %1 > bn%2
-perl bn-586.pl %1 > bn%2
-perl co-586.pl %1 > co%2
+perl x86.pl win32n > bn-win32.asm
 cd ..\..\..
 
 echo DES
 cd crypto\des\asm
-perl des-586.pl %1 > d%2
+perl des-586.pl win32n > d-win32.asm
 cd ..\..\..
 
 echo "crypt(3)"
 
 cd crypto\des\asm
-perl crypt586.pl %1 > y%2
+perl crypt586.pl win32n > y-win32.asm
 cd ..\..\..
 
 echo Blowfish
 
 cd crypto\bf\asm
-perl bf-586.pl %1 > b%2
+perl bf-586.pl win32n > b-win32.asm
 cd ..\..\..
 
 echo CAST5
 cd crypto\cast\asm
-perl cast-586.pl %1 > c%2
+perl cast-586.pl win32n > c-win32.asm
 cd ..\..\..
 
 echo RC4
 cd crypto\rc4\asm
-perl rc4-586.pl %1 > r4%2
+perl rc4-586.pl win32n > r4-win32.asm
 cd ..\..\..
 
 echo MD5
 cd crypto\md5\asm
-perl md5-586.pl %1 > m5%2
+perl md5-586.pl win32n > m5-win32.asm
 cd ..\..\..
 
 echo SHA1
 cd crypto\sha\asm
-perl sha1-586.pl %1 > s1%2
+perl sha1-586.pl win32n > s1-win32.asm
 cd ..\..\..
 
 echo RIPEMD160
 cd crypto\ripemd\asm
-perl rmd-586.pl %1 > rm%2
+perl rmd-586.pl win32n > rm-win32.asm
 cd ..\..\..
 
 echo RC5\32
 cd crypto\rc5\asm
-perl rc5-586.pl %1 > r5%2
+perl rc5-586.pl win32n > r5-win32.asm
 cd ..\..\..
 
-echo CPUID
-cd crypto
-perl x86cpuid.pl %1 > x86cpuid%2
-cd ..\
-
-
 echo on
index 9b68b3e..703cea2 100644 (file)
@@ -1,8 +1,8 @@
 %define _unpackaged_files_terminate_build 0
-%define libmaj 0
-%define libmin 9
-%define librel 8
-%define librev r
+%define libmaj 1
+%define libmin 0
+%define librel 0
+%define librev f
 Release: 1
 
 %define openssldir /var/ssl
index c807a99..2b0faaa 100755 (executable)
@@ -14,5 +14,5 @@ cl /Focrypto.obj -DWIN32 %OPTIONS% -c crypto\crypto.c
 cl /Fossl.obj -DWIN32 %OPTIONS% -c ssl\ssl.c
 cl /Foeay.obj -DWIN32 %OPTIONS% -c apps\eay.c
 
-cl /Fessleay.exe %OPTIONS% eay.obj ssl.obj crypto.obj crypto\bf\asm\b-win32.obj crypto\des\asm\c-win32.obj crypto\des\asm\d-win32.obj crypto\bn\asm\x86nt32.obj user32.lib gdi32.lib wsock32.lib
+cl /Fessleay.exe %OPTIONS% eay.obj ssl.obj crypto.obj crypto\bf\asm\b-win32.obj crypto\des\asm\c-win32.obj crypto\des\asm\d-win32.obj crypto\bn\asm\x86nt32.obj user32.lib gdi32.lib ws2_32.lib
 
index 294c94c..844e353 100755 (executable)
@@ -5,9 +5,9 @@ set OPTIONS2=/W3 /WX /Ox /Gf /nologo
 
 set OPTIONS=%OPTIONS1% %OPTIONS2%
 
-cl /Felibeay32.dll /GD /MD /LD -DWIN32 %OPTIONS% ms\libeay32.def crypto\crypto.c crypto\bf\asm\b-win32.obj crypto\des\asm\c-win32.obj crypto\des\asm\d-win32.obj crypto\bn\asm\x86nt32.obj user32.lib gdi32.lib wsock32.lib
+cl /Felibeay32.dll /GD /MD /LD -DWIN32 %OPTIONS% ms\libeay32.def crypto\crypto.c crypto\bf\asm\b-win32.obj crypto\des\asm\c-win32.obj crypto\des\asm\d-win32.obj crypto\bn\asm\x86nt32.obj user32.lib gdi32.lib ws2_32.lib
 
 cl /Fessleay32.dll /GD /MD /LD -DWIN32 %OPTIONS% ms\ssleay32.def ssl\ssl.c libeay32.lib
 
-cl /Fessleay.exe /MD -DWIN32 %OPTIONS% apps\eay.c ssleay32.lib libeay32.lib user32.lib wsock32.lib
+cl /Fessleay.exe /MD -DWIN32 %OPTIONS% apps\eay.c ssleay32.lib libeay32.lib user32.lib ws2_32.lib
 
index 5ac3507..2b275fa 100644 (file)
@@ -53,7 +53,7 @@ ALL=    $(GENERAL) $(SRC) $(HEADER)
 top:
        (cd ..; $(MAKE) DIRS=$(DIR) all)
 
-all:   lib
+all:   shared
 
 lib:   $(LIBOBJ)
        $(AR) $(LIB) $(LIBOBJ)
@@ -106,45 +106,43 @@ clean:
 # DO NOT DELETE THIS LINE -- make depend depends on it.
 
 bio_ssl.o: ../include/openssl/asn1.h ../include/openssl/bio.h
-bio_ssl.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-bio_ssl.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-bio_ssl.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
-bio_ssl.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
-bio_ssl.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
-bio_ssl.o: ../include/openssl/evp.h ../include/openssl/fips.h
+bio_ssl.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+bio_ssl.o: ../include/openssl/crypto.h ../include/openssl/dtls1.h
+bio_ssl.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
+bio_ssl.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
+bio_ssl.o: ../include/openssl/err.h ../include/openssl/evp.h
 bio_ssl.o: ../include/openssl/hmac.h ../include/openssl/kssl.h
 bio_ssl.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
 bio_ssl.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
 bio_ssl.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
 bio_ssl.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-bio_ssl.o: ../include/openssl/pkcs7.h ../include/openssl/pq_compat.h
-bio_ssl.o: ../include/openssl/pqueue.h ../include/openssl/safestack.h
-bio_ssl.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-bio_ssl.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-bio_ssl.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-bio_ssl.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-bio_ssl.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h bio_ssl.c
+bio_ssl.o: ../include/openssl/pkcs7.h ../include/openssl/pqueue.h
+bio_ssl.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+bio_ssl.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+bio_ssl.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+bio_ssl.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+bio_ssl.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+bio_ssl.o: ../include/openssl/x509_vfy.h bio_ssl.c
 d1_both.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-d1_both.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-d1_both.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-d1_both.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-d1_both.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-d1_both.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-d1_both.o: ../include/openssl/err.h ../include/openssl/evp.h
-d1_both.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+d1_both.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+d1_both.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+d1_both.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+d1_both.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+d1_both.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+d1_both.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 d1_both.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 d1_both.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 d1_both.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 d1_both.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 d1_both.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-d1_both.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-d1_both.o: ../include/openssl/rand.h ../include/openssl/rsa.h
-d1_both.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-d1_both.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
-d1_both.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
-d1_both.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-d1_both.o: ../include/openssl/tls1.h ../include/openssl/x509.h
-d1_both.o: ../include/openssl/x509_vfy.h d1_both.c ssl_locl.h
+d1_both.o: ../include/openssl/pqueue.h ../include/openssl/rand.h
+d1_both.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+d1_both.o: ../include/openssl/sha.h ../include/openssl/ssl.h
+d1_both.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
+d1_both.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
+d1_both.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
+d1_both.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h d1_both.c
+d1_both.o: ssl_locl.h
 d1_clnt.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 d1_clnt.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 d1_clnt.o: ../include/openssl/comp.h ../include/openssl/crypto.h
@@ -152,14 +150,13 @@ d1_clnt.o: ../include/openssl/dh.h ../include/openssl/dsa.h
 d1_clnt.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
 d1_clnt.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 d1_clnt.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
-d1_clnt.o: ../include/openssl/evp.h ../include/openssl/fips.h
-d1_clnt.o: ../include/openssl/hmac.h ../include/openssl/kssl.h
-d1_clnt.o: ../include/openssl/lhash.h ../include/openssl/md5.h
-d1_clnt.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
-d1_clnt.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
-d1_clnt.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
-d1_clnt.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-d1_clnt.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
+d1_clnt.o: ../include/openssl/evp.h ../include/openssl/hmac.h
+d1_clnt.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
+d1_clnt.o: ../include/openssl/md5.h ../include/openssl/obj_mac.h
+d1_clnt.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
+d1_clnt.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+d1_clnt.o: ../include/openssl/pem.h ../include/openssl/pem2.h
+d1_clnt.o: ../include/openssl/pkcs7.h ../include/openssl/pqueue.h
 d1_clnt.o: ../include/openssl/rand.h ../include/openssl/rsa.h
 d1_clnt.o: ../include/openssl/safestack.h ../include/openssl/sha.h
 d1_clnt.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
@@ -168,90 +165,83 @@ d1_clnt.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
 d1_clnt.o: ../include/openssl/tls1.h ../include/openssl/x509.h
 d1_clnt.o: ../include/openssl/x509_vfy.h d1_clnt.c kssl_lcl.h ssl_locl.h
 d1_enc.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-d1_enc.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-d1_enc.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-d1_enc.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-d1_enc.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-d1_enc.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-d1_enc.o: ../include/openssl/err.h ../include/openssl/evp.h
-d1_enc.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+d1_enc.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+d1_enc.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+d1_enc.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+d1_enc.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+d1_enc.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+d1_enc.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 d1_enc.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 d1_enc.o: ../include/openssl/md5.h ../include/openssl/obj_mac.h
 d1_enc.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
 d1_enc.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
 d1_enc.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-d1_enc.o: ../include/openssl/pkcs7.h ../include/openssl/pq_compat.h
-d1_enc.o: ../include/openssl/pqueue.h ../include/openssl/rand.h
-d1_enc.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-d1_enc.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-d1_enc.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-d1_enc.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-d1_enc.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-d1_enc.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h d1_enc.c
-d1_enc.o: ssl_locl.h
+d1_enc.o: ../include/openssl/pkcs7.h ../include/openssl/pqueue.h
+d1_enc.o: ../include/openssl/rand.h ../include/openssl/rsa.h
+d1_enc.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+d1_enc.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+d1_enc.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+d1_enc.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+d1_enc.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+d1_enc.o: ../include/openssl/x509_vfy.h d1_enc.c ssl_locl.h
 d1_lib.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-d1_lib.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-d1_lib.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-d1_lib.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-d1_lib.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-d1_lib.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-d1_lib.o: ../include/openssl/err.h ../include/openssl/evp.h
-d1_lib.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+d1_lib.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+d1_lib.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+d1_lib.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+d1_lib.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+d1_lib.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+d1_lib.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 d1_lib.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 d1_lib.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 d1_lib.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 d1_lib.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 d1_lib.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-d1_lib.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-d1_lib.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-d1_lib.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-d1_lib.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-d1_lib.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-d1_lib.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-d1_lib.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h d1_lib.c
-d1_lib.o: ssl_locl.h
+d1_lib.o: ../include/openssl/pqueue.h ../include/openssl/rsa.h
+d1_lib.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+d1_lib.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+d1_lib.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+d1_lib.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+d1_lib.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+d1_lib.o: ../include/openssl/x509_vfy.h d1_lib.c ssl_locl.h
 d1_meth.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-d1_meth.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-d1_meth.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-d1_meth.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-d1_meth.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-d1_meth.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-d1_meth.o: ../include/openssl/err.h ../include/openssl/evp.h
-d1_meth.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+d1_meth.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+d1_meth.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+d1_meth.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+d1_meth.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+d1_meth.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+d1_meth.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 d1_meth.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 d1_meth.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 d1_meth.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 d1_meth.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 d1_meth.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-d1_meth.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-d1_meth.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-d1_meth.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-d1_meth.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-d1_meth.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-d1_meth.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-d1_meth.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h d1_meth.c
-d1_meth.o: ssl_locl.h
+d1_meth.o: ../include/openssl/pqueue.h ../include/openssl/rsa.h
+d1_meth.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+d1_meth.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+d1_meth.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+d1_meth.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+d1_meth.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+d1_meth.o: ../include/openssl/x509_vfy.h d1_meth.c ssl_locl.h
 d1_pkt.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-d1_pkt.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-d1_pkt.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-d1_pkt.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-d1_pkt.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-d1_pkt.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-d1_pkt.o: ../include/openssl/err.h ../include/openssl/evp.h
-d1_pkt.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+d1_pkt.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+d1_pkt.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+d1_pkt.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+d1_pkt.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+d1_pkt.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+d1_pkt.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 d1_pkt.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 d1_pkt.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 d1_pkt.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 d1_pkt.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 d1_pkt.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-d1_pkt.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-d1_pkt.o: ../include/openssl/rand.h ../include/openssl/rsa.h
-d1_pkt.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-d1_pkt.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
-d1_pkt.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
-d1_pkt.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-d1_pkt.o: ../include/openssl/tls1.h ../include/openssl/x509.h
-d1_pkt.o: ../include/openssl/x509_vfy.h d1_pkt.c ssl_locl.h
+d1_pkt.o: ../include/openssl/pqueue.h ../include/openssl/rand.h
+d1_pkt.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+d1_pkt.o: ../include/openssl/sha.h ../include/openssl/ssl.h
+d1_pkt.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
+d1_pkt.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
+d1_pkt.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
+d1_pkt.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h d1_pkt.c
+d1_pkt.o: ssl_locl.h
 d1_srvr.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 d1_srvr.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 d1_srvr.o: ../include/openssl/comp.h ../include/openssl/crypto.h
@@ -259,14 +249,13 @@ d1_srvr.o: ../include/openssl/dh.h ../include/openssl/dsa.h
 d1_srvr.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
 d1_srvr.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 d1_srvr.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
-d1_srvr.o: ../include/openssl/evp.h ../include/openssl/fips.h
-d1_srvr.o: ../include/openssl/hmac.h ../include/openssl/kssl.h
-d1_srvr.o: ../include/openssl/lhash.h ../include/openssl/md5.h
-d1_srvr.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
-d1_srvr.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
-d1_srvr.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
-d1_srvr.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-d1_srvr.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
+d1_srvr.o: ../include/openssl/evp.h ../include/openssl/hmac.h
+d1_srvr.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
+d1_srvr.o: ../include/openssl/md5.h ../include/openssl/obj_mac.h
+d1_srvr.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
+d1_srvr.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+d1_srvr.o: ../include/openssl/pem.h ../include/openssl/pem2.h
+d1_srvr.o: ../include/openssl/pkcs7.h ../include/openssl/pqueue.h
 d1_srvr.o: ../include/openssl/rand.h ../include/openssl/rsa.h
 d1_srvr.o: ../include/openssl/safestack.h ../include/openssl/sha.h
 d1_srvr.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
@@ -275,276 +264,257 @@ d1_srvr.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
 d1_srvr.o: ../include/openssl/tls1.h ../include/openssl/x509.h
 d1_srvr.o: ../include/openssl/x509_vfy.h d1_srvr.c ssl_locl.h
 kssl.o: ../include/openssl/asn1.h ../include/openssl/bio.h
-kssl.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-kssl.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-kssl.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
-kssl.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
-kssl.o: ../include/openssl/ecdsa.h ../include/openssl/evp.h
-kssl.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+kssl.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+kssl.o: ../include/openssl/crypto.h ../include/openssl/dtls1.h
+kssl.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
+kssl.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
+kssl.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 kssl.o: ../include/openssl/krb5_asn.h ../include/openssl/kssl.h
 kssl.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
 kssl.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
 kssl.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
 kssl.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-kssl.o: ../include/openssl/pkcs7.h ../include/openssl/pq_compat.h
-kssl.o: ../include/openssl/pqueue.h ../include/openssl/safestack.h
-kssl.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-kssl.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-kssl.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-kssl.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-kssl.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h kssl.c
+kssl.o: ../include/openssl/pkcs7.h ../include/openssl/pqueue.h
+kssl.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+kssl.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+kssl.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+kssl.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+kssl.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+kssl.o: ../include/openssl/x509_vfy.h kssl.c kssl_lcl.h
 s23_clnt.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-s23_clnt.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-s23_clnt.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-s23_clnt.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-s23_clnt.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-s23_clnt.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-s23_clnt.o: ../include/openssl/err.h ../include/openssl/evp.h
-s23_clnt.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+s23_clnt.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+s23_clnt.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+s23_clnt.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+s23_clnt.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+s23_clnt.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+s23_clnt.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 s23_clnt.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 s23_clnt.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 s23_clnt.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 s23_clnt.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 s23_clnt.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-s23_clnt.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-s23_clnt.o: ../include/openssl/rand.h ../include/openssl/rsa.h
-s23_clnt.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-s23_clnt.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
-s23_clnt.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
-s23_clnt.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-s23_clnt.o: ../include/openssl/tls1.h ../include/openssl/x509.h
-s23_clnt.o: ../include/openssl/x509_vfy.h s23_clnt.c ssl_locl.h
+s23_clnt.o: ../include/openssl/pqueue.h ../include/openssl/rand.h
+s23_clnt.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+s23_clnt.o: ../include/openssl/sha.h ../include/openssl/ssl.h
+s23_clnt.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
+s23_clnt.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
+s23_clnt.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
+s23_clnt.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h s23_clnt.c
+s23_clnt.o: ssl_locl.h
 s23_lib.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-s23_lib.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-s23_lib.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-s23_lib.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-s23_lib.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-s23_lib.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-s23_lib.o: ../include/openssl/err.h ../include/openssl/evp.h
-s23_lib.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+s23_lib.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+s23_lib.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+s23_lib.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+s23_lib.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+s23_lib.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+s23_lib.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 s23_lib.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 s23_lib.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 s23_lib.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 s23_lib.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 s23_lib.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-s23_lib.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-s23_lib.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-s23_lib.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-s23_lib.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-s23_lib.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-s23_lib.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-s23_lib.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h s23_lib.c
-s23_lib.o: ssl_locl.h
+s23_lib.o: ../include/openssl/pqueue.h ../include/openssl/rsa.h
+s23_lib.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+s23_lib.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+s23_lib.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+s23_lib.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+s23_lib.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+s23_lib.o: ../include/openssl/x509_vfy.h s23_lib.c ssl_locl.h
 s23_meth.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-s23_meth.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-s23_meth.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-s23_meth.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-s23_meth.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-s23_meth.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-s23_meth.o: ../include/openssl/err.h ../include/openssl/evp.h
-s23_meth.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+s23_meth.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+s23_meth.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+s23_meth.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+s23_meth.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+s23_meth.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+s23_meth.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 s23_meth.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 s23_meth.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 s23_meth.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 s23_meth.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 s23_meth.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-s23_meth.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-s23_meth.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-s23_meth.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-s23_meth.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-s23_meth.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-s23_meth.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-s23_meth.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h s23_meth.c
-s23_meth.o: ssl_locl.h
+s23_meth.o: ../include/openssl/pqueue.h ../include/openssl/rsa.h
+s23_meth.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+s23_meth.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+s23_meth.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+s23_meth.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+s23_meth.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+s23_meth.o: ../include/openssl/x509_vfy.h s23_meth.c ssl_locl.h
 s23_pkt.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-s23_pkt.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-s23_pkt.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-s23_pkt.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-s23_pkt.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-s23_pkt.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-s23_pkt.o: ../include/openssl/err.h ../include/openssl/evp.h
-s23_pkt.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+s23_pkt.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+s23_pkt.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+s23_pkt.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+s23_pkt.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+s23_pkt.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+s23_pkt.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 s23_pkt.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 s23_pkt.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 s23_pkt.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 s23_pkt.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 s23_pkt.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-s23_pkt.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-s23_pkt.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-s23_pkt.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-s23_pkt.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-s23_pkt.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-s23_pkt.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-s23_pkt.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h s23_pkt.c
-s23_pkt.o: ssl_locl.h
+s23_pkt.o: ../include/openssl/pqueue.h ../include/openssl/rsa.h
+s23_pkt.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+s23_pkt.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+s23_pkt.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+s23_pkt.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+s23_pkt.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+s23_pkt.o: ../include/openssl/x509_vfy.h s23_pkt.c ssl_locl.h
 s23_srvr.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-s23_srvr.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-s23_srvr.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-s23_srvr.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-s23_srvr.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-s23_srvr.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-s23_srvr.o: ../include/openssl/err.h ../include/openssl/evp.h
-s23_srvr.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+s23_srvr.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+s23_srvr.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+s23_srvr.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+s23_srvr.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+s23_srvr.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+s23_srvr.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 s23_srvr.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 s23_srvr.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 s23_srvr.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 s23_srvr.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 s23_srvr.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-s23_srvr.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-s23_srvr.o: ../include/openssl/rand.h ../include/openssl/rsa.h
-s23_srvr.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-s23_srvr.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
-s23_srvr.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
-s23_srvr.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-s23_srvr.o: ../include/openssl/tls1.h ../include/openssl/x509.h
-s23_srvr.o: ../include/openssl/x509_vfy.h s23_srvr.c ssl_locl.h
+s23_srvr.o: ../include/openssl/pqueue.h ../include/openssl/rand.h
+s23_srvr.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+s23_srvr.o: ../include/openssl/sha.h ../include/openssl/ssl.h
+s23_srvr.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
+s23_srvr.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
+s23_srvr.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
+s23_srvr.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h s23_srvr.c
+s23_srvr.o: ssl_locl.h
 s2_clnt.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-s2_clnt.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-s2_clnt.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-s2_clnt.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-s2_clnt.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-s2_clnt.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-s2_clnt.o: ../include/openssl/err.h ../include/openssl/evp.h
-s2_clnt.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+s2_clnt.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+s2_clnt.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+s2_clnt.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+s2_clnt.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+s2_clnt.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+s2_clnt.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 s2_clnt.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 s2_clnt.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 s2_clnt.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 s2_clnt.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 s2_clnt.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-s2_clnt.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-s2_clnt.o: ../include/openssl/rand.h ../include/openssl/rsa.h
-s2_clnt.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-s2_clnt.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
-s2_clnt.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
-s2_clnt.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-s2_clnt.o: ../include/openssl/tls1.h ../include/openssl/x509.h
-s2_clnt.o: ../include/openssl/x509_vfy.h s2_clnt.c ssl_locl.h
+s2_clnt.o: ../include/openssl/pqueue.h ../include/openssl/rand.h
+s2_clnt.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+s2_clnt.o: ../include/openssl/sha.h ../include/openssl/ssl.h
+s2_clnt.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
+s2_clnt.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
+s2_clnt.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
+s2_clnt.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h s2_clnt.c
+s2_clnt.o: ssl_locl.h
 s2_enc.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-s2_enc.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-s2_enc.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-s2_enc.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-s2_enc.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-s2_enc.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-s2_enc.o: ../include/openssl/err.h ../include/openssl/evp.h
-s2_enc.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+s2_enc.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+s2_enc.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+s2_enc.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+s2_enc.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+s2_enc.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+s2_enc.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 s2_enc.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 s2_enc.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 s2_enc.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 s2_enc.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 s2_enc.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-s2_enc.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-s2_enc.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-s2_enc.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-s2_enc.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-s2_enc.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-s2_enc.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-s2_enc.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h s2_enc.c
-s2_enc.o: ssl_locl.h
+s2_enc.o: ../include/openssl/pqueue.h ../include/openssl/rsa.h
+s2_enc.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+s2_enc.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+s2_enc.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+s2_enc.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+s2_enc.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+s2_enc.o: ../include/openssl/x509_vfy.h s2_enc.c ssl_locl.h
 s2_lib.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-s2_lib.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-s2_lib.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-s2_lib.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-s2_lib.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-s2_lib.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-s2_lib.o: ../include/openssl/err.h ../include/openssl/evp.h
-s2_lib.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+s2_lib.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+s2_lib.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+s2_lib.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+s2_lib.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+s2_lib.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+s2_lib.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 s2_lib.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 s2_lib.o: ../include/openssl/md5.h ../include/openssl/obj_mac.h
 s2_lib.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
 s2_lib.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
 s2_lib.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-s2_lib.o: ../include/openssl/pkcs7.h ../include/openssl/pq_compat.h
-s2_lib.o: ../include/openssl/pqueue.h ../include/openssl/rsa.h
-s2_lib.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-s2_lib.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
-s2_lib.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
-s2_lib.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-s2_lib.o: ../include/openssl/tls1.h ../include/openssl/x509.h
-s2_lib.o: ../include/openssl/x509_vfy.h s2_lib.c ssl_locl.h
+s2_lib.o: ../include/openssl/pkcs7.h ../include/openssl/pqueue.h
+s2_lib.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+s2_lib.o: ../include/openssl/sha.h ../include/openssl/ssl.h
+s2_lib.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
+s2_lib.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
+s2_lib.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
+s2_lib.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h s2_lib.c
+s2_lib.o: ssl_locl.h
 s2_meth.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-s2_meth.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-s2_meth.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-s2_meth.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-s2_meth.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-s2_meth.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-s2_meth.o: ../include/openssl/err.h ../include/openssl/evp.h
-s2_meth.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+s2_meth.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+s2_meth.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+s2_meth.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+s2_meth.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+s2_meth.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+s2_meth.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 s2_meth.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 s2_meth.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 s2_meth.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 s2_meth.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 s2_meth.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-s2_meth.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-s2_meth.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-s2_meth.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-s2_meth.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-s2_meth.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-s2_meth.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-s2_meth.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h s2_meth.c
-s2_meth.o: ssl_locl.h
+s2_meth.o: ../include/openssl/pqueue.h ../include/openssl/rsa.h
+s2_meth.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+s2_meth.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+s2_meth.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+s2_meth.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+s2_meth.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+s2_meth.o: ../include/openssl/x509_vfy.h s2_meth.c ssl_locl.h
 s2_pkt.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-s2_pkt.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-s2_pkt.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-s2_pkt.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-s2_pkt.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-s2_pkt.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-s2_pkt.o: ../include/openssl/err.h ../include/openssl/evp.h
-s2_pkt.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+s2_pkt.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+s2_pkt.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+s2_pkt.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+s2_pkt.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+s2_pkt.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+s2_pkt.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 s2_pkt.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 s2_pkt.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 s2_pkt.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 s2_pkt.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 s2_pkt.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-s2_pkt.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-s2_pkt.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-s2_pkt.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-s2_pkt.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-s2_pkt.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-s2_pkt.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-s2_pkt.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h s2_pkt.c
-s2_pkt.o: ssl_locl.h
+s2_pkt.o: ../include/openssl/pqueue.h ../include/openssl/rsa.h
+s2_pkt.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+s2_pkt.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+s2_pkt.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+s2_pkt.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+s2_pkt.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+s2_pkt.o: ../include/openssl/x509_vfy.h s2_pkt.c ssl_locl.h
 s2_srvr.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-s2_srvr.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-s2_srvr.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-s2_srvr.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-s2_srvr.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-s2_srvr.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-s2_srvr.o: ../include/openssl/err.h ../include/openssl/evp.h
-s2_srvr.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+s2_srvr.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+s2_srvr.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+s2_srvr.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+s2_srvr.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+s2_srvr.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+s2_srvr.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 s2_srvr.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 s2_srvr.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 s2_srvr.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 s2_srvr.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 s2_srvr.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-s2_srvr.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-s2_srvr.o: ../include/openssl/rand.h ../include/openssl/rsa.h
-s2_srvr.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-s2_srvr.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
-s2_srvr.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
-s2_srvr.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-s2_srvr.o: ../include/openssl/tls1.h ../include/openssl/x509.h
-s2_srvr.o: ../include/openssl/x509_vfy.h s2_srvr.c ssl_locl.h
+s2_srvr.o: ../include/openssl/pqueue.h ../include/openssl/rand.h
+s2_srvr.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+s2_srvr.o: ../include/openssl/sha.h ../include/openssl/ssl.h
+s2_srvr.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
+s2_srvr.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
+s2_srvr.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
+s2_srvr.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h s2_srvr.c
+s2_srvr.o: ssl_locl.h
 s3_both.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-s3_both.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-s3_both.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-s3_both.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-s3_both.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-s3_both.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-s3_both.o: ../include/openssl/err.h ../include/openssl/evp.h
-s3_both.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+s3_both.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+s3_both.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+s3_both.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+s3_both.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+s3_both.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+s3_both.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 s3_both.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 s3_both.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 s3_both.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 s3_both.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 s3_both.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-s3_both.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-s3_both.o: ../include/openssl/rand.h ../include/openssl/rsa.h
-s3_both.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-s3_both.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
-s3_both.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
-s3_both.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-s3_both.o: ../include/openssl/tls1.h ../include/openssl/x509.h
-s3_both.o: ../include/openssl/x509_vfy.h s3_both.c ssl_locl.h
+s3_both.o: ../include/openssl/pqueue.h ../include/openssl/rand.h
+s3_both.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+s3_both.o: ../include/openssl/sha.h ../include/openssl/ssl.h
+s3_both.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
+s3_both.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
+s3_both.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
+s3_both.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h s3_both.c
+s3_both.o: ssl_locl.h
 s3_clnt.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 s3_clnt.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 s3_clnt.o: ../include/openssl/comp.h ../include/openssl/crypto.h
@@ -553,13 +523,12 @@ s3_clnt.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
 s3_clnt.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 s3_clnt.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
 s3_clnt.o: ../include/openssl/err.h ../include/openssl/evp.h
-s3_clnt.o: ../include/openssl/fips.h ../include/openssl/hmac.h
-s3_clnt.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
-s3_clnt.o: ../include/openssl/md5.h ../include/openssl/obj_mac.h
-s3_clnt.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
-s3_clnt.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-s3_clnt.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-s3_clnt.o: ../include/openssl/pkcs7.h ../include/openssl/pq_compat.h
+s3_clnt.o: ../include/openssl/hmac.h ../include/openssl/kssl.h
+s3_clnt.o: ../include/openssl/lhash.h ../include/openssl/md5.h
+s3_clnt.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+s3_clnt.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+s3_clnt.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+s3_clnt.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
 s3_clnt.o: ../include/openssl/pqueue.h ../include/openssl/rand.h
 s3_clnt.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
 s3_clnt.o: ../include/openssl/sha.h ../include/openssl/ssl.h
@@ -569,90 +538,84 @@ s3_clnt.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
 s3_clnt.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h kssl_lcl.h
 s3_clnt.o: s3_clnt.c ssl_locl.h
 s3_enc.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-s3_enc.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-s3_enc.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-s3_enc.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-s3_enc.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-s3_enc.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-s3_enc.o: ../include/openssl/err.h ../include/openssl/evp.h
-s3_enc.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+s3_enc.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+s3_enc.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+s3_enc.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+s3_enc.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+s3_enc.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+s3_enc.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 s3_enc.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 s3_enc.o: ../include/openssl/md5.h ../include/openssl/obj_mac.h
 s3_enc.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
 s3_enc.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
 s3_enc.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-s3_enc.o: ../include/openssl/pkcs7.h ../include/openssl/pq_compat.h
-s3_enc.o: ../include/openssl/pqueue.h ../include/openssl/rsa.h
-s3_enc.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-s3_enc.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
-s3_enc.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
-s3_enc.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-s3_enc.o: ../include/openssl/tls1.h ../include/openssl/x509.h
-s3_enc.o: ../include/openssl/x509_vfy.h s3_enc.c ssl_locl.h
-s3_lib.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-s3_lib.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-s3_lib.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-s3_lib.o: ../include/openssl/dh.h ../include/openssl/dsa.h
-s3_lib.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
-s3_lib.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
-s3_lib.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
-s3_lib.o: ../include/openssl/evp.h ../include/openssl/fips.h
+s3_enc.o: ../include/openssl/pkcs7.h ../include/openssl/pqueue.h
+s3_enc.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+s3_enc.o: ../include/openssl/sha.h ../include/openssl/ssl.h
+s3_enc.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
+s3_enc.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
+s3_enc.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
+s3_enc.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h s3_enc.c
+s3_enc.o: ssl_locl.h
+s3_lib.o: ../crypto/ec/ec_lcl.h ../e_os.h ../include/openssl/asn1.h
+s3_lib.o: ../include/openssl/bio.h ../include/openssl/bn.h
+s3_lib.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+s3_lib.o: ../include/openssl/crypto.h ../include/openssl/dh.h
+s3_lib.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
+s3_lib.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
+s3_lib.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
+s3_lib.o: ../include/openssl/err.h ../include/openssl/evp.h
 s3_lib.o: ../include/openssl/hmac.h ../include/openssl/kssl.h
 s3_lib.o: ../include/openssl/lhash.h ../include/openssl/md5.h
 s3_lib.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 s3_lib.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 s3_lib.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 s3_lib.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-s3_lib.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-s3_lib.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-s3_lib.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-s3_lib.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-s3_lib.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-s3_lib.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-s3_lib.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h kssl_lcl.h
-s3_lib.o: s3_lib.c ssl_locl.h
+s3_lib.o: ../include/openssl/pqueue.h ../include/openssl/rsa.h
+s3_lib.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+s3_lib.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+s3_lib.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+s3_lib.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+s3_lib.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+s3_lib.o: ../include/openssl/x509_vfy.h kssl_lcl.h s3_lib.c ssl_locl.h
 s3_meth.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-s3_meth.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-s3_meth.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-s3_meth.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-s3_meth.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-s3_meth.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-s3_meth.o: ../include/openssl/err.h ../include/openssl/evp.h
-s3_meth.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+s3_meth.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+s3_meth.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+s3_meth.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+s3_meth.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+s3_meth.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+s3_meth.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 s3_meth.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 s3_meth.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 s3_meth.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 s3_meth.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 s3_meth.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-s3_meth.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-s3_meth.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-s3_meth.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-s3_meth.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-s3_meth.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-s3_meth.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-s3_meth.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h s3_meth.c
-s3_meth.o: ssl_locl.h
+s3_meth.o: ../include/openssl/pqueue.h ../include/openssl/rsa.h
+s3_meth.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+s3_meth.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+s3_meth.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+s3_meth.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+s3_meth.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+s3_meth.o: ../include/openssl/x509_vfy.h s3_meth.c ssl_locl.h
 s3_pkt.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-s3_pkt.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-s3_pkt.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-s3_pkt.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-s3_pkt.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-s3_pkt.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-s3_pkt.o: ../include/openssl/err.h ../include/openssl/evp.h
-s3_pkt.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+s3_pkt.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+s3_pkt.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+s3_pkt.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+s3_pkt.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+s3_pkt.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+s3_pkt.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 s3_pkt.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 s3_pkt.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 s3_pkt.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 s3_pkt.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 s3_pkt.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-s3_pkt.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-s3_pkt.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-s3_pkt.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-s3_pkt.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-s3_pkt.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-s3_pkt.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-s3_pkt.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h s3_pkt.c
-s3_pkt.o: ssl_locl.h
+s3_pkt.o: ../include/openssl/pqueue.h ../include/openssl/rsa.h
+s3_pkt.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+s3_pkt.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+s3_pkt.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+s3_pkt.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+s3_pkt.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+s3_pkt.o: ../include/openssl/x509_vfy.h s3_pkt.c ssl_locl.h
 s3_srvr.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 s3_srvr.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 s3_srvr.o: ../include/openssl/comp.h ../include/openssl/crypto.h
@@ -660,14 +623,13 @@ s3_srvr.o: ../include/openssl/dh.h ../include/openssl/dsa.h
 s3_srvr.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
 s3_srvr.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 s3_srvr.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
-s3_srvr.o: ../include/openssl/evp.h ../include/openssl/fips.h
-s3_srvr.o: ../include/openssl/hmac.h ../include/openssl/krb5_asn.h
-s3_srvr.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
-s3_srvr.o: ../include/openssl/md5.h ../include/openssl/obj_mac.h
-s3_srvr.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
-s3_srvr.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-s3_srvr.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-s3_srvr.o: ../include/openssl/pkcs7.h ../include/openssl/pq_compat.h
+s3_srvr.o: ../include/openssl/evp.h ../include/openssl/hmac.h
+s3_srvr.o: ../include/openssl/krb5_asn.h ../include/openssl/kssl.h
+s3_srvr.o: ../include/openssl/lhash.h ../include/openssl/md5.h
+s3_srvr.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+s3_srvr.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+s3_srvr.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+s3_srvr.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
 s3_srvr.o: ../include/openssl/pqueue.h ../include/openssl/rand.h
 s3_srvr.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
 s3_srvr.o: ../include/openssl/sha.h ../include/openssl/ssl.h
@@ -677,47 +639,44 @@ s3_srvr.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
 s3_srvr.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h kssl_lcl.h
 s3_srvr.o: s3_srvr.c ssl_locl.h
 ssl_algs.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-ssl_algs.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-ssl_algs.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-ssl_algs.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-ssl_algs.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-ssl_algs.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-ssl_algs.o: ../include/openssl/err.h ../include/openssl/evp.h
-ssl_algs.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+ssl_algs.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+ssl_algs.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+ssl_algs.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+ssl_algs.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+ssl_algs.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+ssl_algs.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 ssl_algs.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 ssl_algs.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 ssl_algs.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 ssl_algs.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 ssl_algs.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-ssl_algs.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-ssl_algs.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-ssl_algs.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-ssl_algs.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-ssl_algs.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-ssl_algs.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-ssl_algs.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h ssl_algs.c
-ssl_algs.o: ssl_locl.h
+ssl_algs.o: ../include/openssl/pqueue.h ../include/openssl/rsa.h
+ssl_algs.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+ssl_algs.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+ssl_algs.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+ssl_algs.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+ssl_algs.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+ssl_algs.o: ../include/openssl/x509_vfy.h ssl_algs.c ssl_locl.h
 ssl_asn1.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/asn1_mac.h
-ssl_asn1.o: ../include/openssl/bio.h ../include/openssl/bn.h
-ssl_asn1.o: ../include/openssl/buffer.h ../include/openssl/comp.h
-ssl_asn1.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
-ssl_asn1.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
-ssl_asn1.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
-ssl_asn1.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
-ssl_asn1.o: ../include/openssl/evp.h ../include/openssl/fips.h
+ssl_asn1.o: ../include/openssl/bio.h ../include/openssl/buffer.h
+ssl_asn1.o: ../include/openssl/comp.h ../include/openssl/crypto.h
+ssl_asn1.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
+ssl_asn1.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
+ssl_asn1.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
+ssl_asn1.o: ../include/openssl/err.h ../include/openssl/evp.h
 ssl_asn1.o: ../include/openssl/hmac.h ../include/openssl/kssl.h
 ssl_asn1.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
 ssl_asn1.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
 ssl_asn1.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
 ssl_asn1.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-ssl_asn1.o: ../include/openssl/pkcs7.h ../include/openssl/pq_compat.h
-ssl_asn1.o: ../include/openssl/pqueue.h ../include/openssl/rsa.h
-ssl_asn1.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-ssl_asn1.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
-ssl_asn1.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
-ssl_asn1.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-ssl_asn1.o: ../include/openssl/tls1.h ../include/openssl/x509.h
-ssl_asn1.o: ../include/openssl/x509_vfy.h ssl_asn1.c ssl_locl.h
+ssl_asn1.o: ../include/openssl/pkcs7.h ../include/openssl/pqueue.h
+ssl_asn1.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+ssl_asn1.o: ../include/openssl/sha.h ../include/openssl/ssl.h
+ssl_asn1.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
+ssl_asn1.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
+ssl_asn1.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
+ssl_asn1.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h ssl_asn1.c
+ssl_asn1.o: ssl_locl.h
 ssl_cert.o: ../crypto/o_dir.h ../e_os.h ../include/openssl/asn1.h
 ssl_cert.o: ../include/openssl/bio.h ../include/openssl/bn.h
 ssl_cert.o: ../include/openssl/buffer.h ../include/openssl/comp.h
@@ -726,13 +685,12 @@ ssl_cert.o: ../include/openssl/dh.h ../include/openssl/dsa.h
 ssl_cert.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
 ssl_cert.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
 ssl_cert.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
-ssl_cert.o: ../include/openssl/evp.h ../include/openssl/fips.h
-ssl_cert.o: ../include/openssl/hmac.h ../include/openssl/kssl.h
-ssl_cert.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-ssl_cert.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
-ssl_cert.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-ssl_cert.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-ssl_cert.o: ../include/openssl/pkcs7.h ../include/openssl/pq_compat.h
+ssl_cert.o: ../include/openssl/evp.h ../include/openssl/hmac.h
+ssl_cert.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
+ssl_cert.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+ssl_cert.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+ssl_cert.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+ssl_cert.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
 ssl_cert.o: ../include/openssl/pqueue.h ../include/openssl/rsa.h
 ssl_cert.o: ../include/openssl/safestack.h ../include/openssl/sha.h
 ssl_cert.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
@@ -742,19 +700,18 @@ ssl_cert.o: ../include/openssl/tls1.h ../include/openssl/x509.h
 ssl_cert.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h
 ssl_cert.o: ssl_cert.c ssl_locl.h
 ssl_ciph.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-ssl_ciph.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-ssl_ciph.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-ssl_ciph.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-ssl_ciph.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-ssl_ciph.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
+ssl_ciph.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+ssl_ciph.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+ssl_ciph.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+ssl_ciph.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+ssl_ciph.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
 ssl_ciph.o: ../include/openssl/err.h ../include/openssl/evp.h
-ssl_ciph.o: ../include/openssl/fips.h ../include/openssl/hmac.h
-ssl_ciph.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
-ssl_ciph.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
-ssl_ciph.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
-ssl_ciph.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
-ssl_ciph.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-ssl_ciph.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
+ssl_ciph.o: ../include/openssl/hmac.h ../include/openssl/kssl.h
+ssl_ciph.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+ssl_ciph.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
+ssl_ciph.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+ssl_ciph.o: ../include/openssl/pem.h ../include/openssl/pem2.h
+ssl_ciph.o: ../include/openssl/pkcs7.h ../include/openssl/pqueue.h
 ssl_ciph.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
 ssl_ciph.o: ../include/openssl/sha.h ../include/openssl/ssl.h
 ssl_ciph.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
@@ -763,276 +720,256 @@ ssl_ciph.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
 ssl_ciph.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h ssl_ciph.c
 ssl_ciph.o: ssl_locl.h
 ssl_err.o: ../include/openssl/asn1.h ../include/openssl/bio.h
-ssl_err.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-ssl_err.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-ssl_err.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
-ssl_err.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
-ssl_err.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
-ssl_err.o: ../include/openssl/evp.h ../include/openssl/fips.h
+ssl_err.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+ssl_err.o: ../include/openssl/crypto.h ../include/openssl/dtls1.h
+ssl_err.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
+ssl_err.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
+ssl_err.o: ../include/openssl/err.h ../include/openssl/evp.h
 ssl_err.o: ../include/openssl/hmac.h ../include/openssl/kssl.h
 ssl_err.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
 ssl_err.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
 ssl_err.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
 ssl_err.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-ssl_err.o: ../include/openssl/pkcs7.h ../include/openssl/pq_compat.h
-ssl_err.o: ../include/openssl/pqueue.h ../include/openssl/safestack.h
-ssl_err.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-ssl_err.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-ssl_err.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-ssl_err.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-ssl_err.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h ssl_err.c
+ssl_err.o: ../include/openssl/pkcs7.h ../include/openssl/pqueue.h
+ssl_err.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+ssl_err.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+ssl_err.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+ssl_err.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+ssl_err.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+ssl_err.o: ../include/openssl/x509_vfy.h ssl_err.c
 ssl_err2.o: ../include/openssl/asn1.h ../include/openssl/bio.h
-ssl_err2.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-ssl_err2.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-ssl_err2.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
-ssl_err2.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
-ssl_err2.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
-ssl_err2.o: ../include/openssl/evp.h ../include/openssl/fips.h
+ssl_err2.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+ssl_err2.o: ../include/openssl/crypto.h ../include/openssl/dtls1.h
+ssl_err2.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
+ssl_err2.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
+ssl_err2.o: ../include/openssl/err.h ../include/openssl/evp.h
 ssl_err2.o: ../include/openssl/hmac.h ../include/openssl/kssl.h
 ssl_err2.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
 ssl_err2.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
 ssl_err2.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
 ssl_err2.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-ssl_err2.o: ../include/openssl/pkcs7.h ../include/openssl/pq_compat.h
-ssl_err2.o: ../include/openssl/pqueue.h ../include/openssl/safestack.h
-ssl_err2.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-ssl_err2.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-ssl_err2.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-ssl_err2.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-ssl_err2.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h ssl_err2.c
+ssl_err2.o: ../include/openssl/pkcs7.h ../include/openssl/pqueue.h
+ssl_err2.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+ssl_err2.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+ssl_err2.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+ssl_err2.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+ssl_err2.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+ssl_err2.o: ../include/openssl/x509_vfy.h ssl_err2.c
 ssl_lib.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-ssl_lib.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-ssl_lib.o: ../include/openssl/comp.h ../include/openssl/conf.h
-ssl_lib.o: ../include/openssl/crypto.h ../include/openssl/dh.h
-ssl_lib.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-ssl_lib.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-ssl_lib.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-ssl_lib.o: ../include/openssl/engine.h ../include/openssl/err.h
-ssl_lib.o: ../include/openssl/evp.h ../include/openssl/fips.h
+ssl_lib.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+ssl_lib.o: ../include/openssl/conf.h ../include/openssl/crypto.h
+ssl_lib.o: ../include/openssl/dh.h ../include/openssl/dsa.h
+ssl_lib.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+ssl_lib.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+ssl_lib.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
+ssl_lib.o: ../include/openssl/err.h ../include/openssl/evp.h
 ssl_lib.o: ../include/openssl/hmac.h ../include/openssl/kssl.h
 ssl_lib.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
 ssl_lib.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
 ssl_lib.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 ssl_lib.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 ssl_lib.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-ssl_lib.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-ssl_lib.o: ../include/openssl/rand.h ../include/openssl/rsa.h
-ssl_lib.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-ssl_lib.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
-ssl_lib.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
-ssl_lib.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-ssl_lib.o: ../include/openssl/tls1.h ../include/openssl/x509.h
-ssl_lib.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h kssl_lcl.h
-ssl_lib.o: ssl_lib.c ssl_locl.h
+ssl_lib.o: ../include/openssl/pqueue.h ../include/openssl/rand.h
+ssl_lib.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+ssl_lib.o: ../include/openssl/sha.h ../include/openssl/ssl.h
+ssl_lib.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
+ssl_lib.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
+ssl_lib.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
+ssl_lib.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
+ssl_lib.o: ../include/openssl/x509v3.h kssl_lcl.h ssl_lib.c ssl_locl.h
 ssl_rsa.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-ssl_rsa.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-ssl_rsa.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-ssl_rsa.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-ssl_rsa.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-ssl_rsa.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-ssl_rsa.o: ../include/openssl/err.h ../include/openssl/evp.h
-ssl_rsa.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+ssl_rsa.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+ssl_rsa.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+ssl_rsa.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+ssl_rsa.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+ssl_rsa.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+ssl_rsa.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 ssl_rsa.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 ssl_rsa.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 ssl_rsa.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 ssl_rsa.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 ssl_rsa.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-ssl_rsa.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-ssl_rsa.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-ssl_rsa.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-ssl_rsa.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-ssl_rsa.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-ssl_rsa.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-ssl_rsa.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h ssl_locl.h
-ssl_rsa.o: ssl_rsa.c
+ssl_rsa.o: ../include/openssl/pqueue.h ../include/openssl/rsa.h
+ssl_rsa.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+ssl_rsa.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+ssl_rsa.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+ssl_rsa.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+ssl_rsa.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+ssl_rsa.o: ../include/openssl/x509_vfy.h ssl_locl.h ssl_rsa.c
 ssl_sess.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-ssl_sess.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-ssl_sess.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-ssl_sess.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-ssl_sess.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-ssl_sess.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-ssl_sess.o: ../include/openssl/engine.h ../include/openssl/err.h
-ssl_sess.o: ../include/openssl/evp.h ../include/openssl/fips.h
+ssl_sess.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+ssl_sess.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+ssl_sess.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+ssl_sess.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+ssl_sess.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
+ssl_sess.o: ../include/openssl/err.h ../include/openssl/evp.h
 ssl_sess.o: ../include/openssl/hmac.h ../include/openssl/kssl.h
 ssl_sess.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
 ssl_sess.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
 ssl_sess.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
 ssl_sess.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-ssl_sess.o: ../include/openssl/pkcs7.h ../include/openssl/pq_compat.h
-ssl_sess.o: ../include/openssl/pqueue.h ../include/openssl/rand.h
-ssl_sess.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-ssl_sess.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-ssl_sess.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-ssl_sess.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-ssl_sess.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-ssl_sess.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h ssl_locl.h
-ssl_sess.o: ssl_sess.c
+ssl_sess.o: ../include/openssl/pkcs7.h ../include/openssl/pqueue.h
+ssl_sess.o: ../include/openssl/rand.h ../include/openssl/rsa.h
+ssl_sess.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+ssl_sess.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+ssl_sess.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+ssl_sess.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+ssl_sess.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+ssl_sess.o: ../include/openssl/x509_vfy.h ssl_locl.h ssl_sess.c
 ssl_stat.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-ssl_stat.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-ssl_stat.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-ssl_stat.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-ssl_stat.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-ssl_stat.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-ssl_stat.o: ../include/openssl/err.h ../include/openssl/evp.h
-ssl_stat.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+ssl_stat.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+ssl_stat.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+ssl_stat.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+ssl_stat.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+ssl_stat.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+ssl_stat.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 ssl_stat.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 ssl_stat.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 ssl_stat.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 ssl_stat.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 ssl_stat.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-ssl_stat.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-ssl_stat.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-ssl_stat.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-ssl_stat.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-ssl_stat.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-ssl_stat.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-ssl_stat.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h ssl_locl.h
-ssl_stat.o: ssl_stat.c
+ssl_stat.o: ../include/openssl/pqueue.h ../include/openssl/rsa.h
+ssl_stat.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+ssl_stat.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+ssl_stat.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+ssl_stat.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+ssl_stat.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+ssl_stat.o: ../include/openssl/x509_vfy.h ssl_locl.h ssl_stat.c
 ssl_txt.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-ssl_txt.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-ssl_txt.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-ssl_txt.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-ssl_txt.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-ssl_txt.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-ssl_txt.o: ../include/openssl/err.h ../include/openssl/evp.h
-ssl_txt.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+ssl_txt.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+ssl_txt.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+ssl_txt.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+ssl_txt.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+ssl_txt.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+ssl_txt.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 ssl_txt.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 ssl_txt.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 ssl_txt.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 ssl_txt.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 ssl_txt.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-ssl_txt.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-ssl_txt.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-ssl_txt.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-ssl_txt.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-ssl_txt.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-ssl_txt.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-ssl_txt.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h ssl_locl.h
-ssl_txt.o: ssl_txt.c
+ssl_txt.o: ../include/openssl/pqueue.h ../include/openssl/rsa.h
+ssl_txt.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+ssl_txt.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+ssl_txt.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+ssl_txt.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+ssl_txt.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+ssl_txt.o: ../include/openssl/x509_vfy.h ssl_locl.h ssl_txt.c
 t1_clnt.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-t1_clnt.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-t1_clnt.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-t1_clnt.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-t1_clnt.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-t1_clnt.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-t1_clnt.o: ../include/openssl/err.h ../include/openssl/evp.h
-t1_clnt.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+t1_clnt.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+t1_clnt.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+t1_clnt.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+t1_clnt.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+t1_clnt.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+t1_clnt.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 t1_clnt.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 t1_clnt.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 t1_clnt.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 t1_clnt.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 t1_clnt.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-t1_clnt.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-t1_clnt.o: ../include/openssl/rand.h ../include/openssl/rsa.h
-t1_clnt.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-t1_clnt.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
-t1_clnt.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
-t1_clnt.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-t1_clnt.o: ../include/openssl/tls1.h ../include/openssl/x509.h
-t1_clnt.o: ../include/openssl/x509_vfy.h ssl_locl.h t1_clnt.c
+t1_clnt.o: ../include/openssl/pqueue.h ../include/openssl/rand.h
+t1_clnt.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+t1_clnt.o: ../include/openssl/sha.h ../include/openssl/ssl.h
+t1_clnt.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
+t1_clnt.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
+t1_clnt.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
+t1_clnt.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h ssl_locl.h
+t1_clnt.o: t1_clnt.c
 t1_enc.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-t1_enc.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-t1_enc.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-t1_enc.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-t1_enc.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-t1_enc.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-t1_enc.o: ../include/openssl/err.h ../include/openssl/evp.h
-t1_enc.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+t1_enc.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+t1_enc.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+t1_enc.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+t1_enc.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+t1_enc.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+t1_enc.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 t1_enc.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 t1_enc.o: ../include/openssl/md5.h ../include/openssl/obj_mac.h
 t1_enc.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
 t1_enc.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
 t1_enc.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-t1_enc.o: ../include/openssl/pkcs7.h ../include/openssl/pq_compat.h
-t1_enc.o: ../include/openssl/pqueue.h ../include/openssl/rsa.h
-t1_enc.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-t1_enc.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
-t1_enc.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
-t1_enc.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-t1_enc.o: ../include/openssl/tls1.h ../include/openssl/x509.h
-t1_enc.o: ../include/openssl/x509_vfy.h ssl_locl.h t1_enc.c
+t1_enc.o: ../include/openssl/pkcs7.h ../include/openssl/pqueue.h
+t1_enc.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+t1_enc.o: ../include/openssl/sha.h ../include/openssl/ssl.h
+t1_enc.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
+t1_enc.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
+t1_enc.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
+t1_enc.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h ssl_locl.h
+t1_enc.o: t1_enc.c
 t1_lib.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-t1_lib.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-t1_lib.o: ../include/openssl/comp.h ../include/openssl/conf.h
-t1_lib.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
-t1_lib.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
-t1_lib.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
-t1_lib.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
-t1_lib.o: ../include/openssl/evp.h ../include/openssl/fips.h
+t1_lib.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+t1_lib.o: ../include/openssl/conf.h ../include/openssl/crypto.h
+t1_lib.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
+t1_lib.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
+t1_lib.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
+t1_lib.o: ../include/openssl/err.h ../include/openssl/evp.h
 t1_lib.o: ../include/openssl/hmac.h ../include/openssl/kssl.h
 t1_lib.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
 t1_lib.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
 t1_lib.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 t1_lib.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 t1_lib.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-t1_lib.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-t1_lib.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-t1_lib.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-t1_lib.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-t1_lib.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-t1_lib.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-t1_lib.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
-t1_lib.o: ../include/openssl/x509v3.h ssl_locl.h t1_lib.c
+t1_lib.o: ../include/openssl/pqueue.h ../include/openssl/rsa.h
+t1_lib.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+t1_lib.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+t1_lib.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+t1_lib.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+t1_lib.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+t1_lib.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h ssl_locl.h
+t1_lib.o: t1_lib.c
 t1_meth.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-t1_meth.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-t1_meth.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-t1_meth.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-t1_meth.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-t1_meth.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-t1_meth.o: ../include/openssl/err.h ../include/openssl/evp.h
-t1_meth.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+t1_meth.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+t1_meth.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+t1_meth.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+t1_meth.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+t1_meth.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+t1_meth.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 t1_meth.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 t1_meth.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 t1_meth.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 t1_meth.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 t1_meth.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-t1_meth.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-t1_meth.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-t1_meth.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-t1_meth.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-t1_meth.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-t1_meth.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-t1_meth.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h ssl_locl.h
-t1_meth.o: t1_meth.c
+t1_meth.o: ../include/openssl/pqueue.h ../include/openssl/rsa.h
+t1_meth.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+t1_meth.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+t1_meth.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+t1_meth.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+t1_meth.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+t1_meth.o: ../include/openssl/x509_vfy.h ssl_locl.h t1_meth.c
 t1_reneg.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-t1_reneg.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-t1_reneg.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-t1_reneg.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-t1_reneg.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-t1_reneg.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-t1_reneg.o: ../include/openssl/err.h ../include/openssl/evp.h
-t1_reneg.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+t1_reneg.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+t1_reneg.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+t1_reneg.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+t1_reneg.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+t1_reneg.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+t1_reneg.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 t1_reneg.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 t1_reneg.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 t1_reneg.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 t1_reneg.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 t1_reneg.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-t1_reneg.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-t1_reneg.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
-t1_reneg.o: ../include/openssl/sha.h ../include/openssl/ssl.h
-t1_reneg.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
-t1_reneg.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
-t1_reneg.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
-t1_reneg.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h ssl_locl.h
-t1_reneg.o: t1_reneg.c
+t1_reneg.o: ../include/openssl/pqueue.h ../include/openssl/rsa.h
+t1_reneg.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+t1_reneg.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+t1_reneg.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
+t1_reneg.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+t1_reneg.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+t1_reneg.o: ../include/openssl/x509_vfy.h ssl_locl.h t1_reneg.c
 t1_srvr.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
-t1_srvr.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-t1_srvr.o: ../include/openssl/comp.h ../include/openssl/crypto.h
-t1_srvr.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
-t1_srvr.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-t1_srvr.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-t1_srvr.o: ../include/openssl/err.h ../include/openssl/evp.h
-t1_srvr.o: ../include/openssl/fips.h ../include/openssl/hmac.h
+t1_srvr.o: ../include/openssl/buffer.h ../include/openssl/comp.h
+t1_srvr.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
+t1_srvr.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
+t1_srvr.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+t1_srvr.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+t1_srvr.o: ../include/openssl/evp.h ../include/openssl/hmac.h
 t1_srvr.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
 t1_srvr.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
 t1_srvr.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
 t1_srvr.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
 t1_srvr.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
-t1_srvr.o: ../include/openssl/pq_compat.h ../include/openssl/pqueue.h
-t1_srvr.o: ../include/openssl/rand.h ../include/openssl/rsa.h
-t1_srvr.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-t1_srvr.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
-t1_srvr.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
-t1_srvr.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-t1_srvr.o: ../include/openssl/tls1.h ../include/openssl/x509.h
-t1_srvr.o: ../include/openssl/x509_vfy.h ssl_locl.h t1_srvr.c
+t1_srvr.o: ../include/openssl/pqueue.h ../include/openssl/rand.h
+t1_srvr.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+t1_srvr.o: ../include/openssl/sha.h ../include/openssl/ssl.h
+t1_srvr.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
+t1_srvr.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
+t1_srvr.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
+t1_srvr.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h ssl_locl.h
+t1_srvr.o: t1_srvr.c
index 420deb7..eedac8a 100644 (file)
@@ -348,7 +348,11 @@ static long ssl_ctrl(BIO *b, int cmd, long num, void *ptr)
                break;
        case BIO_C_SET_SSL:
                if (ssl != NULL)
+                       {
                        ssl_free(b);
+                       if (!ssl_new(b))
+                               return 0;
+                       }
                b->shutdown=(int)num;
                ssl=(SSL *)ptr;
                ((BIO_SSL *)b->ptr)->ssl=ssl;
@@ -398,17 +402,19 @@ static long ssl_ctrl(BIO *b, int cmd, long num, void *ptr)
                        }
                break;
        case BIO_CTRL_POP:
-               /* ugly bit of a hack */
-               if (ssl->rbio != ssl->wbio) /* we are in trouble :-( */
+               /* Only detach if we are the BIO explicitly being popped */
+               if (b == ptr)
                        {
-                       BIO_free_all(ssl->wbio);
-                       }
-               if (b->next_bio != NULL)
-                       {
-                       CRYPTO_add(&b->next_bio->references,1,CRYPTO_LOCK_BIO);
+                       /* Shouldn't happen in practice because the
+                        * rbio and wbio are the same when pushed.
+                        */
+                       if (ssl->rbio != ssl->wbio)
+                               BIO_free_all(ssl->wbio);
+                       if (b->next_bio != NULL)
+                               CRYPTO_add(&b->next_bio->references,-1,CRYPTO_LOCK_BIO);
+                       ssl->wbio=NULL;
+                       ssl->rbio=NULL;
                        }
-               ssl->wbio=NULL;
-               ssl->rbio=NULL;
                break;
        case BIO_C_DO_STATE_MACHINE:
                BIO_clear_retry_flags(b);
@@ -543,7 +549,6 @@ BIO *BIO_new_ssl_connect(SSL_CTX *ctx)
        return(ret);
 err:
        if (con != NULL) BIO_free(con);
-       if (ret != NULL) BIO_free(ret);
        return(NULL);
        }
 
index 920fb1f..9f898d6 100644 (file)
 #endif
 
 static unsigned char bitmask_start_values[] = {0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80};
-static unsigned char bitmask_end_values[]   = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f};
+static unsigned char bitmask_end_values[]   = {0xff, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f};
 
 /* XDTLS:  figure out the right values */
 static unsigned int g_probable_mtu[] = {1500 - 28, 512 - 28, 256 - 28};
 
-static unsigned int dtls1_min_mtu(void);
 static unsigned int dtls1_guess_mtu(unsigned int curr_mtu);
 static void dtls1_fix_message_header(SSL *s, unsigned long frag_off, 
        unsigned long frag_len);
@@ -264,17 +263,16 @@ int dtls1_do_write(SSL *s, int type)
                        return ret;
                mtu = s->d1->mtu - (DTLS1_HM_HEADER_LENGTH + DTLS1_RT_HEADER_LENGTH);
                }
-
-       OPENSSL_assert(mtu > 0);  /* should have something reasonable now */
-
 #endif
 
+       OPENSSL_assert(s->d1->mtu >= dtls1_min_mtu());  /* should have something reasonable now */
+
        if ( s->init_off == 0  && type == SSL3_RT_HANDSHAKE)
                OPENSSL_assert(s->init_num == 
                        (int)s->d1->w_msg_hdr.msg_len + DTLS1_HM_HEADER_LENGTH);
 
        if (s->write_hash)
-               mac_size = EVP_MD_size(s->write_hash);
+               mac_size = EVP_MD_CTX_size(s->write_hash);
        else
                mac_size = 0;
 
@@ -360,7 +358,7 @@ int dtls1_do_write(SSL *s, int type)
                                const struct hm_header_st *msg_hdr = &s->d1->w_msg_hdr;
                                int xlen;
 
-                               if (frag_off == 0 && s->client_version != DTLS1_BAD_VER)
+                               if (frag_off == 0 && s->version != DTLS1_BAD_VER)
                                        {
                                        /* reconstruct message header is if it
                                         * is being sent in single fragment */
@@ -464,20 +462,9 @@ again:
 
        memset(msg_hdr, 0x00, sizeof(struct hm_header_st));
 
-       s->d1->handshake_read_seq++;
-       /* we just read a handshake message from the other side:
-        * this means that we don't need to retransmit of the
-        * buffered messages.  
-        * XDTLS: may be able clear out this
-        * buffer a little sooner (i.e if an out-of-order
-        * handshake message/record is received at the record
-        * layer.  
-        * XDTLS: exception is that the server needs to
-        * know that change cipher spec and finished messages
-        * have been received by the client before clearing this
-        * buffer.  this can simply be done by waiting for the
-        * first data  segment, but is there a better way?  */
-       dtls1_clear_record_buffer(s);
+       /* Don't change sequence numbers while listening */
+       if (!s->d1->listen)
+               s->d1->handshake_read_seq++;
 
        s->init_msg = s->init_buf->data + DTLS1_HM_HEADER_LENGTH;
        return s->init_num;
@@ -514,7 +501,7 @@ static int dtls1_preprocess_fragment(SSL *s,struct hm_header_st *msg_hdr,int max
                {
                /* msg_len is limited to 2^24, but is effectively checked
                 * against max above */
-               if (!BUF_MEM_grow_clean(s->init_buf,(int)msg_len+DTLS1_HM_HEADER_LENGTH))
+               if (!BUF_MEM_grow_clean(s->init_buf,msg_len+DTLS1_HM_HEADER_LENGTH))
                        {
                        SSLerr(SSL_F_DTLS1_PREPROCESS_FRAGMENT,ERR_R_BUF_LIB);
                        return SSL_AD_INTERNAL_ERROR;
@@ -600,7 +587,7 @@ dtls1_reassemble_fragment(SSL *s, struct hm_header_st* msg_hdr, int *ok)
        hm_fragment *frag = NULL;
        pitem *item = NULL;
        int i = -1, is_complete;
-       PQ_64BIT seq64;
+       unsigned char seq64be[8];
        unsigned long frag_len = msg_hdr->frag_len, max_len;
 
        if ((msg_hdr->frag_off+frag_len) > msg_hdr->msg_len)
@@ -618,10 +605,10 @@ dtls1_reassemble_fragment(SSL *s, struct hm_header_st* msg_hdr, int *ok)
                goto err;
 
        /* Try to find item in queue */
-       pq_64bit_init(&seq64);
-       pq_64bit_assign_word(&seq64, msg_hdr->seq);
-       item = pqueue_find(s->d1->buffered_messages, seq64);
-       pq_64bit_free(&seq64);
+       memset(seq64be,0,sizeof(seq64be));
+       seq64be[6] = (unsigned char) (msg_hdr->seq>>8);
+       seq64be[7] = (unsigned char) msg_hdr->seq;
+       item = pqueue_find(s->d1->buffered_messages, seq64be);
 
        if (item == NULL)
                {
@@ -673,11 +660,11 @@ dtls1_reassemble_fragment(SSL *s, struct hm_header_st* msg_hdr, int *ok)
 
        if (item == NULL)
                {
-               pq_64bit_init(&seq64);
-               pq_64bit_assign_word(&seq64, msg_hdr->seq);
-               item = pitem_new(seq64, frag);
-               pq_64bit_free(&seq64);
+               memset(seq64be,0,sizeof(seq64be));
+               seq64be[6] = (unsigned char)(msg_hdr->seq>>8);
+               seq64be[7] = (unsigned char)(msg_hdr->seq);
 
+               item = pitem_new(seq64be, frag);
                if (item == NULL)
                        {
                        goto err;
@@ -703,17 +690,17 @@ dtls1_process_out_of_seq_message(SSL *s, struct hm_header_st* msg_hdr, int *ok)
        int i=-1;
        hm_fragment *frag = NULL;
        pitem *item = NULL;
-       PQ_64BIT seq64;
+       unsigned char seq64be[8];
        unsigned long frag_len = msg_hdr->frag_len;
 
        if ((msg_hdr->frag_off+frag_len) > msg_hdr->msg_len)
                goto err;
 
        /* Try to find item in queue, to prevent duplicate entries */
-       pq_64bit_init(&seq64);
-       pq_64bit_assign_word(&seq64, msg_hdr->seq);
-       item = pqueue_find(s->d1->buffered_messages, seq64);
-       pq_64bit_free(&seq64);
+       memset(seq64be,0,sizeof(seq64be));
+       seq64be[6] = (unsigned char) (msg_hdr->seq>>8);
+       seq64be[7] = (unsigned char) msg_hdr->seq;
+       item = pqueue_find(s->d1->buffered_messages, seq64be);
 
        /* If we already have an entry and this one is a fragment,
         * don't discard it and rather try to reassemble it.
@@ -754,18 +741,18 @@ dtls1_process_out_of_seq_message(SSL *s, struct hm_header_st* msg_hdr, int *ok)
 
                if (frag_len)
                        {
-                       /* read the body of the fragment (header has already been read) */
+                       /* read the body of the fragment (header has already been read */
                        i = s->method->ssl_read_bytes(s,SSL3_RT_HANDSHAKE,
                                frag->fragment,frag_len,0);
                        if (i<=0 || (unsigned long)i!=frag_len)
                                goto err;
                        }
 
-               pq_64bit_init(&seq64);
-               pq_64bit_assign_word(&seq64, msg_hdr->seq);
+               memset(seq64be,0,sizeof(seq64be));
+               seq64be[6] = (unsigned char)(msg_hdr->seq>>8);
+               seq64be[7] = (unsigned char)(msg_hdr->seq);
 
-               item = pitem_new(seq64, frag);
-               pq_64bit_free(&seq64);
+               item = pitem_new(seq64be, frag);
                if ( item == NULL)
                        goto err;
 
@@ -806,16 +793,24 @@ dtls1_get_message_fragment(SSL *s, int st1, int stn, long max, int *ok)
                *ok = 0;
                return i;
                }
-       OPENSSL_assert(i == DTLS1_HM_HEADER_LENGTH);
+       /* Handshake fails if message header is incomplete */
+       if (i != DTLS1_HM_HEADER_LENGTH)
+               {
+               al=SSL_AD_UNEXPECTED_MESSAGE;
+               SSLerr(SSL_F_DTLS1_GET_MESSAGE_FRAGMENT,SSL_R_UNEXPECTED_MESSAGE);
+               goto f_err;
+               }
 
        /* parse the message fragment header */
        dtls1_get_message_header(wire, &msg_hdr);
 
        /* 
         * if this is a future (or stale) message it gets buffered
-        * (or dropped)--no further processing at this time 
+        * (or dropped)--no further processing at this time
+        * While listening, we accept seq 1 (ClientHello with cookie)
+        * although we're still expecting seq 0 (ClientHello)
         */
-       if ( msg_hdr.seq != s->d1->handshake_read_seq)
+       if (msg_hdr.seq != s->d1->handshake_read_seq && !(s->d1->listen && msg_hdr.seq == 1))
                return dtls1_process_out_of_seq_message(s, &msg_hdr, ok);
 
        len = msg_hdr.msg_len;
@@ -876,7 +871,12 @@ dtls1_get_message_fragment(SSL *s, int st1, int stn, long max, int *ok)
 
        /* XDTLS:  an incorrectly formatted fragment should cause the 
         * handshake to fail */
-       OPENSSL_assert(i == (int)frag_len);
+       if (i != (int)frag_len)
+               {
+               al=SSL3_AD_ILLEGAL_PARAMETER;
+               SSLerr(SSL_F_DTLS1_GET_MESSAGE_FRAGMENT,SSL3_AD_ILLEGAL_PARAMETER);
+               goto f_err;
+               }
 
        *ok = 1;
 
@@ -907,8 +907,6 @@ int dtls1_send_finished(SSL *s, int a, int b, const char *sender, int slen)
                p= &(d[DTLS1_HM_HEADER_LENGTH]);
 
                i=s->method->ssl3_enc->final_finish_mac(s,
-                       &(s->s3->finish_dgst1),
-                       &(s->s3->finish_dgst2),
                        sender,slen,s->s3->tmp.finish_md);
                s->s3->tmp.finish_md_len = i;
                memcpy(p, s->s3->tmp.finish_md, i);
@@ -973,12 +971,11 @@ int dtls1_send_change_cipher_spec(SSL *s, int a, int b)
                s->d1->handshake_write_seq = s->d1->next_handshake_write_seq;
                s->init_num=DTLS1_CCS_HEADER_LENGTH;
 
-               if (s->client_version == DTLS1_BAD_VER)
-                       {
+               if (s->version == DTLS1_BAD_VER) {
                        s->d1->next_handshake_write_seq++;
                        s2n(s->d1->handshake_write_seq,p);
                        s->init_num+=2;
-                       }
+               }
 
                s->init_off=0;
 
@@ -997,21 +994,21 @@ int dtls1_send_change_cipher_spec(SSL *s, int a, int b)
 
 static int dtls1_add_cert_to_buf(BUF_MEM *buf, unsigned long *l, X509 *x)
        {
-               int n;
-               unsigned char *p;
+       int n;
+       unsigned char *p;
 
-               n=i2d_X509(x,NULL);
-               if (!BUF_MEM_grow_clean(buf,(int)(n+(*l)+3)))
-                       {
-                       SSLerr(SSL_F_DTLS1_ADD_CERT_TO_BUF,ERR_R_BUF_LIB);
-                       return 0;
-                       }
-               p=(unsigned char *)&(buf->data[*l]);
-               l2n3(n,p);
-               i2d_X509(x,&p);
-               *l+=n+3;
+       n=i2d_X509(x,NULL);
+       if (!BUF_MEM_grow_clean(buf,(int)(n+(*l)+3)))
+               {
+               SSLerr(SSL_F_DTLS1_ADD_CERT_TO_BUF,ERR_R_BUF_LIB);
+               return 0;
+               }
+       p=(unsigned char *)&(buf->data[*l]);
+       l2n3(n,p);
+       i2d_X509(x,&p);
+       *l+=n+3;
 
-               return 1;
+       return 1;
        }
 unsigned long dtls1_output_cert_chain(SSL *s, X509 *x)
        {
@@ -1030,7 +1027,7 @@ unsigned long dtls1_output_cert_chain(SSL *s, X509 *x)
        if (x != NULL)
                {
                X509_STORE_CTX xs_ctx;
-  
+
                if (!X509_STORE_CTX_init(&xs_ctx,s->ctx->cert_store,x,NULL))
                        {
                        SSLerr(SSL_F_DTLS1_OUTPUT_CERT_CHAIN,ERR_R_X509_LIB);
@@ -1052,7 +1049,7 @@ unsigned long dtls1_output_cert_chain(SSL *s, X509 *x)
                        }
                X509_STORE_CTX_cleanup(&xs_ctx);
                }
-       /* Thawte special :-) */
+       /* Thawte special :-) */
        for (i=0; i<sk_X509_num(s->ctx->extra_certs); i++)
                {
                x=sk_X509_value(s->ctx->extra_certs,i);
@@ -1156,7 +1153,7 @@ dtls1_buffer_message(SSL *s, int is_ccs)
        {
        pitem *item;
        hm_fragment *frag;
-       PQ_64BIT seq64;
+       unsigned char seq64be[8];
 
        /* this function is called immediately after a message has 
         * been serialized */
@@ -1169,7 +1166,7 @@ dtls1_buffer_message(SSL *s, int is_ccs)
        if ( is_ccs)
                {
                OPENSSL_assert(s->d1->w_msg_hdr.msg_len + 
-                       DTLS1_CCS_HEADER_LENGTH <= (unsigned int)s->init_num);
+                              ((s->version==DTLS1_VERSION)?DTLS1_CCS_HEADER_LENGTH:3) == (unsigned int)s->init_num);
                }
        else
                {
@@ -1190,15 +1187,14 @@ dtls1_buffer_message(SSL *s, int is_ccs)
        frag->msg_header.saved_retransmit_state.compress = s->compress;
        frag->msg_header.saved_retransmit_state.session = s->session;
        frag->msg_header.saved_retransmit_state.epoch = s->d1->w_epoch;
+       
+       memset(seq64be,0,sizeof(seq64be));
+       seq64be[6] = (unsigned char)(dtls1_get_queue_priority(frag->msg_header.seq,
+                                                                                                                 frag->msg_header.is_ccs)>>8);
+       seq64be[7] = (unsigned char)(dtls1_get_queue_priority(frag->msg_header.seq,
+                                                                                                                 frag->msg_header.is_ccs));
 
-       pq_64bit_init(&seq64);
-
-       pq_64bit_assign_word(&seq64,
-                                                dtls1_get_queue_priority(frag->msg_header.seq,
-                                                                                                 frag->msg_header.is_ccs));
-               
-       item = pitem_new(seq64, frag);
-       pq_64bit_free(&seq64);
+       item = pitem_new(seq64be, frag);
        if ( item == NULL)
                {
                dtls1_hm_fragment_free(frag);
@@ -1224,7 +1220,7 @@ dtls1_retransmit_message(SSL *s, unsigned short seq, unsigned long frag_off,
        pitem *item;
        hm_fragment *frag ;
        unsigned long header_length;
-       PQ_64BIT seq64;
+       unsigned char seq64be[8];
        struct dtls1_retransmit_state saved_state;
        unsigned char save_write_sequence[8];
 
@@ -1234,11 +1230,11 @@ dtls1_retransmit_message(SSL *s, unsigned short seq, unsigned long frag_off,
         */
 
        /* XDTLS:  the requested message ought to be found, otherwise error */
-       pq_64bit_init(&seq64);
-       pq_64bit_assign_word(&seq64, seq);
+       memset(seq64be,0,sizeof(seq64be));
+       seq64be[6] = (unsigned char)(seq>>8);
+       seq64be[7] = (unsigned char)seq;
 
-       item = pqueue_find(s->d1->sent_messages, seq64);
-       pq_64bit_free(&seq64);
+       item = pqueue_find(s->d1->sent_messages, seq64be);
        if ( item == NULL)
                {
                fprintf(stderr, "retransmit:  message %d non-existant\n", seq);
@@ -1326,7 +1322,8 @@ unsigned char *
 dtls1_set_message_header(SSL *s, unsigned char *p, unsigned char mt,
                        unsigned long len, unsigned long frag_off, unsigned long frag_len)
        {
-       if ( frag_off == 0)
+       /* Don't change sequence numbers while listening */
+       if (frag_off == 0 && !s->d1->listen)
                {
                s->d1->handshake_write_seq = s->d1->next_handshake_write_seq;
                s->d1->next_handshake_write_seq++;
@@ -1379,7 +1376,7 @@ dtls1_write_message_header(SSL *s, unsigned char *p)
        return p;
        }
 
-static unsigned int 
+unsigned int 
 dtls1_min_mtu(void)
        {
        return (g_probable_mtu[(sizeof(g_probable_mtu) / 
@@ -1389,7 +1386,7 @@ dtls1_min_mtu(void)
 static unsigned int 
 dtls1_guess_mtu(unsigned int curr_mtu)
        {
-       size_t i;
+       unsigned int i;
 
        if ( curr_mtu == 0 )
                return g_probable_mtu[0] ;
index 0aa77ee..5776671 100644 (file)
@@ -4,7 +4,7 @@
  * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.  
  */
 /* ====================================================================
- * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2007 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 #include <stdio.h>
 #include "ssl_locl.h"
+#ifndef OPENSSL_NO_KRB5
 #include "kssl_lcl.h"
+#endif
 #include <openssl/buffer.h>
 #include <openssl/rand.h>
 #include <openssl/objects.h>
 #include <openssl/evp.h>
 #include <openssl/md5.h>
+#include <openssl/bn.h>
 #ifndef OPENSSL_NO_DH
 #include <openssl/dh.h>
 #endif
 
-static SSL_METHOD *dtls1_get_client_method(int ver);
+static const SSL_METHOD *dtls1_get_client_method(int ver);
 static int dtls1_get_hello_verify(SSL *s);
 
-static SSL_METHOD *dtls1_get_client_method(int ver)
+static const SSL_METHOD *dtls1_get_client_method(int ver)
        {
        if (ver == DTLS1_VERSION || ver == DTLS1_BAD_VER)
                return(DTLSv1_client_method());
@@ -296,8 +299,9 @@ int dtls1_connect(SSL *s)
                                break;
                                }
 #endif
-                       /* Check if it is anon DH */
-                       if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL))
+                       /* Check if it is anon DH or PSK */
+                       if (!(s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL) &&
+                           !(s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK))
                                {
                                ret=ssl3_get_server_certificate(s);
                                if (ret <= 0) goto end;
@@ -403,7 +407,8 @@ int dtls1_connect(SSL *s)
 
                case SSL3_ST_CW_CHANGE_A:
                case SSL3_ST_CW_CHANGE_B:
-                       dtls1_start_timer(s);
+                       if (!s->hit)
+                               dtls1_start_timer(s);
                        ret=dtls1_send_change_cipher_spec(s,
                                SSL3_ST_CW_CHANGE_A,SSL3_ST_CW_CHANGE_B);
                        if (ret <= 0) goto end;
@@ -438,7 +443,8 @@ int dtls1_connect(SSL *s)
 
                case SSL3_ST_CW_FINISHED_A:
                case SSL3_ST_CW_FINISHED_B:
-                       dtls1_start_timer(s);
+                       if (!s->hit)
+                               dtls1_start_timer(s);
                        ret=dtls1_send_finished(s,
                                SSL3_ST_CW_FINISHED_A,SSL3_ST_CW_FINISHED_B,
                                s->method->ssl3_enc->client_finished_label,
@@ -470,7 +476,6 @@ int dtls1_connect(SSL *s)
                                s->s3->tmp.next_state=SSL3_ST_CR_FINISHED_A;
                                }
                        s->init_num=0;
-
                        break;
 
 #ifndef OPENSSL_NO_TLSEXT
@@ -610,12 +615,19 @@ int dtls1_client_hello(SSL *s)
 #endif
                        (s->session->not_resumable))
                        {
+                       if (!s->session_creation_enabled)
+                               {
+                               ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
+                               SSLerr(SSL_F_DTLS1_CLIENT_HELLO,SSL_R_SESSION_MAY_NOT_BE_CREATED);
+                               goto err;
+                               }
                        if (!ssl_get_new_session(s,0))
                                goto err;
                        }
                /* else use the pre-loaded session */
 
                p=s->s3->client_random;
+
                /* if client_random is initialized, reuse it, we are
                 * required to use same upon reply to HelloVerify */
                for (i=0;p[i]=='\0' && i<sizeof(s->s3->client_random);i++) ;
@@ -623,7 +635,7 @@ int dtls1_client_hello(SSL *s)
                        {
                        Time=(unsigned long)time(NULL); /* Time */
                        l2n(Time,p);
-                       RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4);
+                       RAND_pseudo_bytes(p,sizeof(s->s3->client_random)-4);
                        }
 
                /* Do the message type and length last */
@@ -770,7 +782,7 @@ int dtls1_send_client_key_exchange(SSL *s)
        {
        unsigned char *p,*d;
        int n;
-       unsigned long l;
+       unsigned long alg_k;
 #ifndef OPENSSL_NO_RSA
        unsigned char *q;
        EVP_PKEY *pkey=NULL;
@@ -778,18 +790,26 @@ int dtls1_send_client_key_exchange(SSL *s)
 #ifndef OPENSSL_NO_KRB5
         KSSL_ERR kssl_err;
 #endif /* OPENSSL_NO_KRB5 */
+#ifndef OPENSSL_NO_ECDH
+       EC_KEY *clnt_ecdh = NULL;
+       const EC_POINT *srvr_ecpoint = NULL;
+       EVP_PKEY *srvr_pub_pkey = NULL;
+       unsigned char *encodedPoint = NULL;
+       int encoded_pt_len = 0;
+       BN_CTX * bn_ctx = NULL;
+#endif
 
        if (s->state == SSL3_ST_CW_KEY_EXCH_A)
                {
                d=(unsigned char *)s->init_buf->data;
                p= &(d[DTLS1_HM_HEADER_LENGTH]);
-
-               l=s->s3->tmp.new_cipher->algorithms;
+               
+               alg_k=s->s3->tmp.new_cipher->algorithm_mkey;
 
                 /* Fool emacs indentation */
                 if (0) {}
 #ifndef OPENSSL_NO_RSA
-               else if (l & SSL_kRSA)
+               else if (alg_k & SSL_kRSA)
                        {
                        RSA *rsa;
                        unsigned char tmp_buf[SSL_MAX_MASTER_KEY_LENGTH];
@@ -848,7 +868,7 @@ int dtls1_send_client_key_exchange(SSL *s)
                        }
 #endif
 #ifndef OPENSSL_NO_KRB5
-               else if (l & SSL_kKRB5)
+               else if (alg_k & SSL_kKRB5)
                         {
                         krb5_error_code        krb5rc;
                         KSSL_CTX       *kssl_ctx = s->kssl_ctx;
@@ -856,7 +876,7 @@ int dtls1_send_client_key_exchange(SSL *s)
                         krb5_data      *enc_ticket;
                         krb5_data      authenticator, *authp = NULL;
                        EVP_CIPHER_CTX  ciph_ctx;
-                       EVP_CIPHER      *enc = NULL;
+                       const EVP_CIPHER *enc = NULL;
                        unsigned char   iv[EVP_MAX_IV_LENGTH];
                        unsigned char   tmp_buf[SSL_MAX_MASTER_KEY_LENGTH];
                        unsigned char   epms[SSL_MAX_MASTER_KEY_LENGTH 
@@ -867,7 +887,7 @@ int dtls1_send_client_key_exchange(SSL *s)
 
 #ifdef KSSL_DEBUG
                         printf("ssl3_send_client_key_exchange(%lx & %lx)\n",
-                                l, SSL_kKRB5);
+                                alg_k, SSL_kKRB5);
 #endif /* KSSL_DEBUG */
 
                        authp = NULL;
@@ -957,7 +977,7 @@ int dtls1_send_client_key_exchange(SSL *s)
                                sizeof tmp_buf);
                        EVP_EncryptFinal_ex(&ciph_ctx,&(epms[outl]),&padl);
                        outl += padl;
-                       if (outl > sizeof epms)
+                       if (outl > (int)sizeof epms)
                                {
                                SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);
                                goto err;
@@ -980,7 +1000,7 @@ int dtls1_send_client_key_exchange(SSL *s)
                         }
 #endif
 #ifndef OPENSSL_NO_DH
-               else if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
+               else if (alg_k & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
                        {
                        DH *dh_srvr,*dh_clnt;
 
@@ -1035,6 +1055,274 @@ int dtls1_send_client_key_exchange(SSL *s)
                        /* perhaps clean things up a bit EAY EAY EAY EAY*/
                        }
 #endif
+#ifndef OPENSSL_NO_ECDH 
+               else if (alg_k & (SSL_kEECDH|SSL_kECDHr|SSL_kECDHe))
+                       {
+                       const EC_GROUP *srvr_group = NULL;
+                       EC_KEY *tkey;
+                       int ecdh_clnt_cert = 0;
+                       int field_size = 0;
+
+                       /* Did we send out the client's
+                        * ECDH share for use in premaster
+                        * computation as part of client certificate?
+                        * If so, set ecdh_clnt_cert to 1.
+                        */
+                       if ((alg_k & (SSL_kECDHr|SSL_kECDHe)) && (s->cert != NULL)) 
+                               {
+                               /* XXX: For now, we do not support client
+                                * authentication using ECDH certificates.
+                                * To add such support, one needs to add
+                                * code that checks for appropriate 
+                                * conditions and sets ecdh_clnt_cert to 1.
+                                * For example, the cert have an ECC
+                                * key on the same curve as the server's
+                                * and the key should be authorized for
+                                * key agreement.
+                                *
+                                * One also needs to add code in ssl3_connect
+                                * to skip sending the certificate verify
+                                * message.
+                                *
+                                * if ((s->cert->key->privatekey != NULL) &&
+                                *     (s->cert->key->privatekey->type ==
+                                *      EVP_PKEY_EC) && ...)
+                                * ecdh_clnt_cert = 1;
+                                */
+                               }
+
+                       if (s->session->sess_cert->peer_ecdh_tmp != NULL)
+                               {
+                               tkey = s->session->sess_cert->peer_ecdh_tmp;
+                               }
+                       else
+                               {
+                               /* Get the Server Public Key from Cert */
+                               srvr_pub_pkey = X509_get_pubkey(s->session-> \
+                                   sess_cert->peer_pkeys[SSL_PKEY_ECC].x509);
+                               if ((srvr_pub_pkey == NULL) ||
+                                   (srvr_pub_pkey->type != EVP_PKEY_EC) ||
+                                   (srvr_pub_pkey->pkey.ec == NULL))
+                                       {
+                                       SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,
+                                           ERR_R_INTERNAL_ERROR);
+                                       goto err;
+                                       }
+
+                               tkey = srvr_pub_pkey->pkey.ec;
+                               }
+
+                       srvr_group   = EC_KEY_get0_group(tkey);
+                       srvr_ecpoint = EC_KEY_get0_public_key(tkey);
+
+                       if ((srvr_group == NULL) || (srvr_ecpoint == NULL))
+                               {
+                               SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,
+                                   ERR_R_INTERNAL_ERROR);
+                               goto err;
+                               }
+
+                       if ((clnt_ecdh=EC_KEY_new()) == NULL) 
+                               {
+                               SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE);
+                               goto err;
+                               }
+
+                       if (!EC_KEY_set_group(clnt_ecdh, srvr_group))
+                               {
+                               SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,ERR_R_EC_LIB);
+                               goto err;
+                               }
+                       if (ecdh_clnt_cert) 
+                               { 
+                               /* Reuse key info from our certificate
+                                * We only need our private key to perform
+                                * the ECDH computation.
+                                */
+                               const BIGNUM *priv_key;
+                               tkey = s->cert->key->privatekey->pkey.ec;
+                               priv_key = EC_KEY_get0_private_key(tkey);
+                               if (priv_key == NULL)
+                                       {
+                                       SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE);
+                                       goto err;
+                                       }
+                               if (!EC_KEY_set_private_key(clnt_ecdh, priv_key))
+                                       {
+                                       SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,ERR_R_EC_LIB);
+                                       goto err;
+                                       }
+                               }
+                       else 
+                               {
+                               /* Generate a new ECDH key pair */
+                               if (!(EC_KEY_generate_key(clnt_ecdh)))
+                                       {
+                                       SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE, ERR_R_ECDH_LIB);
+                                       goto err;
+                                       }
+                               }
+
+                       /* use the 'p' output buffer for the ECDH key, but
+                        * make sure to clear it out afterwards
+                        */
+
+                       field_size = EC_GROUP_get_degree(srvr_group);
+                       if (field_size <= 0)
+                               {
+                               SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE, 
+                                      ERR_R_ECDH_LIB);
+                               goto err;
+                               }
+                       n=ECDH_compute_key(p, (field_size+7)/8, srvr_ecpoint, clnt_ecdh, NULL);
+                       if (n <= 0)
+                               {
+                               SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE, 
+                                      ERR_R_ECDH_LIB);
+                               goto err;
+                               }
+
+                       /* generate master key from the result */
+                       s->session->master_key_length = s->method->ssl3_enc \
+                           -> generate_master_secret(s, 
+                               s->session->master_key,
+                               p, n);
+
+                       memset(p, 0, n); /* clean up */
+
+                       if (ecdh_clnt_cert) 
+                               {
+                               /* Send empty client key exch message */
+                               n = 0;
+                               }
+                       else 
+                               {
+                               /* First check the size of encoding and
+                                * allocate memory accordingly.
+                                */
+                               encoded_pt_len = 
+                                   EC_POINT_point2oct(srvr_group, 
+                                       EC_KEY_get0_public_key(clnt_ecdh), 
+                                       POINT_CONVERSION_UNCOMPRESSED, 
+                                       NULL, 0, NULL);
+
+                               encodedPoint = (unsigned char *) 
+                                   OPENSSL_malloc(encoded_pt_len * 
+                                       sizeof(unsigned char)); 
+                               bn_ctx = BN_CTX_new();
+                               if ((encodedPoint == NULL) || 
+                                   (bn_ctx == NULL)) 
+                                       {
+                                       SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE);
+                                       goto err;
+                                       }
+
+                               /* Encode the public key */
+                               n = EC_POINT_point2oct(srvr_group, 
+                                   EC_KEY_get0_public_key(clnt_ecdh), 
+                                   POINT_CONVERSION_UNCOMPRESSED, 
+                                   encodedPoint, encoded_pt_len, bn_ctx);
+
+                               *p = n; /* length of encoded point */
+                               /* Encoded point will be copied here */
+                               p += 1; 
+                               /* copy the point */
+                               memcpy((unsigned char *)p, encodedPoint, n);
+                               /* increment n to account for length field */
+                               n += 1; 
+                               }
+
+                       /* Free allocated memory */
+                       BN_CTX_free(bn_ctx);
+                       if (encodedPoint != NULL) OPENSSL_free(encodedPoint);
+                       if (clnt_ecdh != NULL) 
+                                EC_KEY_free(clnt_ecdh);
+                       EVP_PKEY_free(srvr_pub_pkey);
+                       }
+#endif /* !OPENSSL_NO_ECDH */
+
+#ifndef OPENSSL_NO_PSK
+               else if (alg_k & SSL_kPSK)
+                       {
+                       char identity[PSK_MAX_IDENTITY_LEN];
+                       unsigned char *t = NULL;
+                       unsigned char psk_or_pre_ms[PSK_MAX_PSK_LEN*2+4];
+                       unsigned int pre_ms_len = 0, psk_len = 0;
+                       int psk_err = 1;
+
+                       n = 0;
+                       if (s->psk_client_callback == NULL)
+                               {
+                               SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,
+                                       SSL_R_PSK_NO_CLIENT_CB);
+                               goto err;
+                               }
+
+                       psk_len = s->psk_client_callback(s, s->ctx->psk_identity_hint,
+                               identity, PSK_MAX_IDENTITY_LEN,
+                               psk_or_pre_ms, sizeof(psk_or_pre_ms));
+                       if (psk_len > PSK_MAX_PSK_LEN)
+                               {
+                               SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,
+                                       ERR_R_INTERNAL_ERROR);
+                               goto psk_err;
+                               }
+                       else if (psk_len == 0)
+                               {
+                               SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,
+                                       SSL_R_PSK_IDENTITY_NOT_FOUND);
+                               goto psk_err;
+                               }
+
+                       /* create PSK pre_master_secret */
+                       pre_ms_len = 2+psk_len+2+psk_len;
+                       t = psk_or_pre_ms;
+                       memmove(psk_or_pre_ms+psk_len+4, psk_or_pre_ms, psk_len);
+                       s2n(psk_len, t);
+                       memset(t, 0, psk_len);
+                       t+=psk_len;
+                       s2n(psk_len, t);
+
+                       if (s->session->psk_identity_hint != NULL)
+                               OPENSSL_free(s->session->psk_identity_hint);
+                       s->session->psk_identity_hint = BUF_strdup(s->ctx->psk_identity_hint);
+                       if (s->ctx->psk_identity_hint != NULL &&
+                               s->session->psk_identity_hint == NULL)
+                               {
+                               SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,
+                                       ERR_R_MALLOC_FAILURE);
+                               goto psk_err;
+                               }
+
+                       if (s->session->psk_identity != NULL)
+                               OPENSSL_free(s->session->psk_identity);
+                       s->session->psk_identity = BUF_strdup(identity);
+                       if (s->session->psk_identity == NULL)
+                               {
+                               SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,
+                                       ERR_R_MALLOC_FAILURE);
+                               goto psk_err;
+                               }
+
+                       s->session->master_key_length =
+                               s->method->ssl3_enc->generate_master_secret(s,
+                                       s->session->master_key,
+                                       psk_or_pre_ms, pre_ms_len); 
+                       n = strlen(identity);
+                       s2n(n, p);
+                       memcpy(p, identity, n);
+                       n+=2;
+                       psk_err = 0;
+               psk_err:
+                       OPENSSL_cleanse(identity, PSK_MAX_IDENTITY_LEN);
+                       OPENSSL_cleanse(psk_or_pre_ms, sizeof(psk_or_pre_ms));
+                       if (psk_err != 0)
+                               {
+                               ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
+                               goto err;
+                               }
+                       }
+#endif
                else
                        {
                        ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
@@ -1063,6 +1351,13 @@ int dtls1_send_client_key_exchange(SSL *s)
        /* SSL3_ST_CW_KEY_EXCH_B */
        return(dtls1_do_write(s,SSL3_RT_HANDSHAKE));
 err:
+#ifndef OPENSSL_NO_ECDH
+       BN_CTX_free(bn_ctx);
+       if (encodedPoint != NULL) OPENSSL_free(encodedPoint);
+       if (clnt_ecdh != NULL) 
+               EC_KEY_free(clnt_ecdh);
+       EVP_PKEY_free(srvr_pub_pkey);
+#endif
        return(-1);
        }
 
@@ -1075,7 +1370,7 @@ int dtls1_send_client_verify(SSL *s)
        unsigned u=0;
 #endif
        unsigned long n;
-#ifndef OPENSSL_NO_DSA
+#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_ECDSA)
        int j;
 #endif
 
@@ -1085,14 +1380,16 @@ int dtls1_send_client_verify(SSL *s)
                p= &(d[DTLS1_HM_HEADER_LENGTH]);
                pkey=s->cert->key->privatekey;
 
-               s->method->ssl3_enc->cert_verify_mac(s,&(s->s3->finish_dgst2),
+               s->method->ssl3_enc->cert_verify_mac(s,
+               NID_sha1,
                        &(data[MD5_DIGEST_LENGTH]));
 
 #ifndef OPENSSL_NO_RSA
                if (pkey->type == EVP_PKEY_RSA)
                        {
                        s->method->ssl3_enc->cert_verify_mac(s,
-                               &(s->s3->finish_dgst1),&(data[0]));
+                               NID_md5,
+                               &(data[0]));
                        if (RSA_sign(NID_md5_sha1, data,
                                         MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH,
                                        &(p[2]), &u, pkey->pkey.rsa) <= 0 )
@@ -1121,6 +1418,23 @@ int dtls1_send_client_verify(SSL *s)
                        }
                else
 #endif
+#ifndef OPENSSL_NO_ECDSA
+                       if (pkey->type == EVP_PKEY_EC)
+                       {
+                       if (!ECDSA_sign(pkey->save_type,
+                               &(data[MD5_DIGEST_LENGTH]),
+                               SHA_DIGEST_LENGTH,&(p[2]),
+                               (unsigned int *)&j,pkey->pkey.ec))
+                               {
+                               SSLerr(SSL_F_DTLS1_SEND_CLIENT_VERIFY,
+                                   ERR_R_ECDSA_LIB);
+                               goto err;
+                               }
+                       s2n(j,p);
+                       n=j+2;
+                       }
+               else
+#endif
                        {
                        SSLerr(SSL_F_DTLS1_SEND_CLIENT_VERIFY,ERR_R_INTERNAL_ERROR);
                        goto err;
index bb96c8a..becbab9 100644 (file)
@@ -131,11 +131,17 @@ int dtls1_enc(SSL *s, int send)
        SSL3_RECORD *rec;
        EVP_CIPHER_CTX *ds;
        unsigned long l;
-       int bs,i,ii,j,k;
+       int bs,i,ii,j,k,n=0;
        const EVP_CIPHER *enc;
 
        if (send)
                {
+               if (EVP_MD_CTX_md(s->write_hash))
+                       {
+                       n=EVP_MD_CTX_size(s->write_hash);
+                       if (n < 0)
+                               return -1;
+                       }
                ds=s->enc_write_ctx;
                rec= &(s->s3->wrec);
                if (s->enc_write_ctx == NULL)
@@ -156,6 +162,12 @@ int dtls1_enc(SSL *s, int send)
                }
        else
                {
+               if (EVP_MD_CTX_md(s->read_hash))
+                       {
+                       n=EVP_MD_CTX_size(s->read_hash);
+                       if (n < 0)
+                               return -1;
+                       }
                ds=s->enc_read_ctx;
                rec= &(s->s3->rrec);
                if (s->enc_read_ctx == NULL)
@@ -202,11 +214,10 @@ int dtls1_enc(SSL *s, int send)
                {
                 unsigned long ui;
                printf("EVP_Cipher(ds=%p,rec->data=%p,rec->input=%p,l=%ld) ==>\n",
-                        (void *)ds,rec->data,rec->input,l);
-               printf("\tEVP_CIPHER_CTX: %d buf_len, %d key_len [%ld %ld], %d iv_len\n",
+                        ds,rec->data,rec->input,l);
+               printf("\tEVP_CIPHER_CTX: %d buf_len, %d key_len [%d %d], %d iv_len\n",
                         ds->buf_len, ds->cipher->key_len,
-                        (unsigned long)DES_KEY_SZ,
-                       (unsigned long)DES_SCHEDULE_SZ,
+                        DES_KEY_SZ, DES_SCHEDULE_SZ,
                         ds->cipher->iv_len);
                printf("\t\tIV: ");
                for (i=0; i<ds->cipher->iv_len; i++) printf("%02X", ds->iv[i]);
@@ -227,10 +238,10 @@ int dtls1_enc(SSL *s, int send)
 
 #ifdef KSSL_DEBUG
                {
-                unsigned long ki;
+                unsigned long i;
                 printf("\trec->data=");
-               for (ki=0; ki<l; ki++)
-                        printf(" %02x", rec->data[ki]);  printf("\n");
+               for (i=0; i<l; i++)
+                        printf(" %02x", rec->data[i]);  printf("\n");
                 }
 #endif /* KSSL_DEBUG */
 
index 54e1640..a94290a 100644 (file)
@@ -82,6 +82,7 @@ SSL3_ENC_METHOD DTLSv1_enc_data={
        TLS_MD_CLIENT_FINISH_CONST,TLS_MD_CLIENT_FINISH_CONST_SIZE,
        TLS_MD_SERVER_FINISH_CONST,TLS_MD_SERVER_FINISH_CONST_SIZE,
        tls1_alert_code,
+       tls1_export_keying_material,
        };
 
 long dtls1_default_timeout(void)
@@ -91,11 +92,6 @@ long dtls1_default_timeout(void)
        return(60*60*2);
        }
 
-IMPLEMENT_dtls1_meth_func(dtlsv1_base_method,
-                       ssl_undefined_function,
-                       ssl_undefined_function,
-                       ssl_bad_method)
-
 int dtls1_new(SSL *s)
        {
        DTLS1_STATE *d1;
@@ -105,17 +101,6 @@ int dtls1_new(SSL *s)
        memset(d1,0, sizeof *d1);
 
        /* d1->handshake_epoch=0; */
-#if defined(OPENSSL_SYS_VMS) || defined(VMS_TEST)
-       d1->bitmap.length=64;
-#else
-       d1->bitmap.length=sizeof(d1->bitmap.map) * 8;
-#endif
-       pq_64bit_init(&(d1->bitmap.map));
-       pq_64bit_init(&(d1->bitmap.max_seq_num));
-       
-       d1->next_bitmap.length = d1->bitmap.length;
-       pq_64bit_init(&(d1->next_bitmap.map));
-       pq_64bit_init(&(d1->next_bitmap.max_seq_num));
 
        d1->unprocessed_rcds.q=pqueue_new();
        d1->processed_rcds.q=pqueue_new();
@@ -145,26 +130,33 @@ int dtls1_new(SSL *s)
        return(1);
        }
 
-void dtls1_free(SSL *s)
+static void dtls1_clear_queues(SSL *s)
        {
     pitem *item = NULL;
     hm_fragment *frag = NULL;
-
-       ssl3_free(s);
+       DTLS1_RECORD_DATA *rdata;
 
     while( (item = pqueue_pop(s->d1->unprocessed_rcds.q)) != NULL)
         {
+               rdata = (DTLS1_RECORD_DATA *) item->data;
+               if (rdata->rbuf.buf)
+                       {
+                       OPENSSL_free(rdata->rbuf.buf);
+                       }
         OPENSSL_free(item->data);
         pitem_free(item);
         }
-    pqueue_free(s->d1->unprocessed_rcds.q);
 
     while( (item = pqueue_pop(s->d1->processed_rcds.q)) != NULL)
         {
+               rdata = (DTLS1_RECORD_DATA *) item->data;
+               if (rdata->rbuf.buf)
+                       {
+                       OPENSSL_free(rdata->rbuf.buf);
+                       }
         OPENSSL_free(item->data);
         pitem_free(item);
         }
-    pqueue_free(s->d1->processed_rcds.q);
 
     while( (item = pqueue_pop(s->d1->buffered_messages)) != NULL)
         {
@@ -173,7 +165,6 @@ void dtls1_free(SSL *s)
         OPENSSL_free(frag);
         pitem_free(item);
         }
-    pqueue_free(s->d1->buffered_messages);
 
     while ( (item = pqueue_pop(s->d1->sent_messages)) != NULL)
         {
@@ -182,28 +173,70 @@ void dtls1_free(SSL *s)
         OPENSSL_free(frag);
         pitem_free(item);
         }
-       pqueue_free(s->d1->sent_messages);
 
        while ( (item = pqueue_pop(s->d1->buffered_app_data.q)) != NULL)
-       {
+               {
                frag = (hm_fragment *)item->data;
                OPENSSL_free(frag->fragment);
                OPENSSL_free(frag);
                pitem_free(item);
+               }
        }
-       pqueue_free(s->d1->buffered_app_data.q);
-       
-       pq_64bit_free(&(s->d1->bitmap.map));
-       pq_64bit_free(&(s->d1->bitmap.max_seq_num));
 
-       pq_64bit_free(&(s->d1->next_bitmap.map));
-       pq_64bit_free(&(s->d1->next_bitmap.max_seq_num));
+void dtls1_free(SSL *s)
+       {
+       ssl3_free(s);
+
+       dtls1_clear_queues(s);
+
+    pqueue_free(s->d1->unprocessed_rcds.q);
+    pqueue_free(s->d1->processed_rcds.q);
+    pqueue_free(s->d1->buffered_messages);
+       pqueue_free(s->d1->sent_messages);
+       pqueue_free(s->d1->buffered_app_data.q);
 
        OPENSSL_free(s->d1);
        }
 
 void dtls1_clear(SSL *s)
        {
+    pqueue unprocessed_rcds;
+    pqueue processed_rcds;
+    pqueue buffered_messages;
+       pqueue sent_messages;
+       pqueue buffered_app_data;
+       unsigned int mtu;
+
+       if (s->d1)
+               {
+               unprocessed_rcds = s->d1->unprocessed_rcds.q;
+               processed_rcds = s->d1->processed_rcds.q;
+               buffered_messages = s->d1->buffered_messages;
+               sent_messages = s->d1->sent_messages;
+               buffered_app_data = s->d1->buffered_app_data.q;
+               mtu = s->d1->mtu;
+
+               dtls1_clear_queues(s);
+
+               memset(s->d1, 0, sizeof(*(s->d1)));
+
+               if (s->server)
+                       {
+                       s->d1->cookie_len = sizeof(s->d1->cookie);
+                       }
+
+               if (SSL_get_options(s) & SSL_OP_NO_QUERY_MTU)
+                       {
+                       s->d1->mtu = mtu;
+                       }
+
+               s->d1->unprocessed_rcds.q = unprocessed_rcds;
+               s->d1->processed_rcds.q = processed_rcds;
+               s->d1->buffered_messages = buffered_messages;
+               s->d1->sent_messages = sent_messages;
+               s->d1->buffered_app_data.q = buffered_app_data;
+               }
+
        ssl3_clear(s);
        if (s->options & SSL_OP_CISCO_ANYCONNECT)
                s->version=DTLS1_BAD_VER;
@@ -244,13 +277,13 @@ long dtls1_ctrl(SSL *s, int cmd, long larg, void *parg)
  * to explicitly list their SSL_* codes. Currently RC4 is the only one
  * available, but if new ones emerge, they will have to be added...
  */
-SSL_CIPHER *dtls1_get_cipher(unsigned int u)
+const SSL_CIPHER *dtls1_get_cipher(unsigned int u)
        {
-       SSL_CIPHER *ciph = ssl3_get_cipher(u);
+       const SSL_CIPHER *ciph = ssl3_get_cipher(u);
 
        if (ciph != NULL)
                {
-               if ((ciph->algorithms&SSL_ENC_MASK) == SSL_RC4)
+               if (ciph->algorithm_enc == SSL_RC4)
                        return NULL;
                }
 
@@ -352,6 +385,8 @@ void dtls1_stop_timer(SSL *s)
        memset(&(s->d1->next_timeout), 0, sizeof(struct timeval));
        s->d1->timeout_duration = 1;
        BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT, 0, &(s->d1->next_timeout));
+       /* Clear retransmission buffer */
+       dtls1_clear_record_buffer(s);
        }
 
 int dtls1_handle_timeout(SSL *s)
@@ -371,7 +406,7 @@ int dtls1_handle_timeout(SSL *s)
                {
                /* fail the connection, enough alerts have been sent */
                SSLerr(SSL_F_DTLS1_HANDLE_TIMEOUT,SSL_R_READ_TIMEOUT_EXPIRED);
-               return 0;
+               return -1;
                }
 
        state->timeout.read_timeouts++;
index 8a6cf31..5c4004b 100644 (file)
@@ -61,8 +61,8 @@
 #include <openssl/objects.h>
 #include "ssl_locl.h"
 
-static SSL_METHOD *dtls1_get_method(int ver);
-static SSL_METHOD *dtls1_get_method(int ver)
+static const SSL_METHOD *dtls1_get_method(int ver);
+static const SSL_METHOD *dtls1_get_method(int ver)
        {
        if (ver == DTLS1_VERSION)
                return(DTLSv1_method());
index b840a15..3927dad 100644 (file)
 #include <openssl/pqueue.h>
 #include <openssl/rand.h>
 
+/* mod 128 saturating subtract of two 64-bit values in big-endian order */
+static int satsub64be(const unsigned char *v1,const unsigned char *v2)
+{      int ret,sat,brw,i;
+
+       if (sizeof(long) == 8) do
+       {       const union { long one; char little; } is_endian = {1};
+               long l;
+
+               if (is_endian.little)                   break;
+               /* not reached on little-endians */
+               /* following test is redundant, because input is
+                * always aligned, but I take no chances... */
+               if (((size_t)v1|(size_t)v2)&0x7)        break;
+
+               l  = *((long *)v1);
+               l -= *((long *)v2);
+               if (l>128)              return 128;
+               else if (l<-128)        return -128;
+               else                    return (int)l;
+       } while (0);
+
+       ret = (int)v1[7]-(int)v2[7];
+       sat = 0;
+       brw = ret>>8;   /* brw is either 0 or -1 */
+       if (ret & 0x80)
+       {       for (i=6;i>=0;i--)
+               {       brw += (int)v1[i]-(int)v2[i];
+                       sat |= ~brw;
+                       brw >>= 8;
+               }
+       }
+       else
+       {       for (i=6;i>=0;i--)
+               {       brw += (int)v1[i]-(int)v2[i];
+                       sat |= brw;
+                       brw >>= 8;
+               }
+       }
+       brw <<= 8;      /* brw is either 0 or -256 */
+
+       if (sat&0xff)   return brw | 0x80;
+       else            return brw + (ret&0xFF);
+}
+
 static int have_handshake_fragment(SSL *s, int type, unsigned char *buf, 
        int len, int peek);
-static int dtls1_record_replay_check(SSL *s, DTLS1_BITMAP *bitmap,
-       PQ_64BIT *seq_num);
+static int dtls1_record_replay_check(SSL *s, DTLS1_BITMAP *bitmap);
 static void dtls1_record_bitmap_update(SSL *s, DTLS1_BITMAP *bitmap);
 static DTLS1_BITMAP *dtls1_get_bitmap(SSL *s, SSL3_RECORD *rr, 
     unsigned int *is_next_epoch);
@@ -134,11 +177,8 @@ static int dtls1_record_needs_buffering(SSL *s, SSL3_RECORD *rr,
        unsigned short *priority, unsigned long *offset);
 #endif
 static int dtls1_buffer_record(SSL *s, record_pqueue *q,
-       PQ_64BIT *priority);
+       unsigned char *priority);
 static int dtls1_process_record(SSL *s);
-#if PQ_64BIT_IS_INTEGER
-static PQ_64BIT bytes_to_long_long(unsigned char *bytes, PQ_64BIT *num);
-#endif
 static void dtls1_clear_timeouts(SSL *s);
 
 /* copy buffered record into SSL structure */
@@ -165,9 +205,9 @@ dtls1_copy_record(SSL *s, pitem *item)
 
 
 static int
-dtls1_buffer_record(SSL *s, record_pqueue *queue, PQ_64BIT *priority)
-{
-    DTLS1_RECORD_DATA *rdata;
+dtls1_buffer_record(SSL *s, record_pqueue *queue, unsigned char *priority)
+       {
+       DTLS1_RECORD_DATA *rdata;
        pitem *item;
 
        /* Limit the size of the queue to prevent DOS attacks */
@@ -175,7 +215,7 @@ dtls1_buffer_record(SSL *s, record_pqueue *queue, PQ_64BIT *priority)
                return 0;
                
        rdata = OPENSSL_malloc(sizeof(DTLS1_RECORD_DATA));
-       item = pitem_new(*priority, rdata);
+       item = pitem_new(priority, rdata);
        if (rdata == NULL || item == NULL)
                {
                if (rdata != NULL) OPENSSL_free(rdata);
@@ -214,7 +254,7 @@ dtls1_buffer_record(SSL *s, record_pqueue *queue, PQ_64BIT *priority)
                }
        
        return(1);
-    }
+       }
 
 
 static int
@@ -267,7 +307,7 @@ dtls1_process_buffered_records(SSL *s)
             if ( ! dtls1_process_record(s))
                 return(0);
             dtls1_buffer_record(s, &(s->d1->processed_rcds), 
-                &s->s3->rrec.seq_num);
+                s->s3->rrec.seq_num);
             }
         }
 
@@ -328,17 +368,18 @@ dtls1_get_buffered_record(SSL *s)
 static int
 dtls1_process_record(SSL *s)
 {
-    int al;
+       int i,al;
        int clear=0;
-    int enc_err;
+       int enc_err;
        SSL_SESSION *sess;
-    SSL3_RECORD *rr;
+       SSL3_RECORD *rr;
        unsigned int mac_size;
        unsigned char md[EVP_MAX_MD_SIZE];
+       int decryption_failed_or_bad_record_mac = 0;
 
 
        rr= &(s->s3->rrec);
-    sess = s->session;
+       sess = s->session;
 
        /* At this point, s->packet_length == SSL3_RT_HEADER_LNGTH + rr->length,
         * and we have that many bytes in s->packet
@@ -369,13 +410,10 @@ dtls1_process_record(SSL *s)
        enc_err = s->method->ssl3_enc->enc(s,0);
        if (enc_err <= 0)
                {
-               if (enc_err == 0)
-                       /* SSLerr() and ssl3_send_alert() have been called */
-                       goto err;
-
-               /* otherwise enc_err == -1 */
-               al=SSL_AD_BAD_RECORD_MAC;
-               goto f_err;
+               /* To minimize information leaked via timing, we will always
+                * perform all computations before discarding the message.
+                */
+               decryption_failed_or_bad_record_mac = 1;
                }
 
 #ifdef TLS_DEBUG
@@ -385,14 +423,18 @@ printf("\n");
 #endif
 
        /* r->length is now the compressed data plus mac */
-if (   (sess == NULL) ||
+       if (    (sess == NULL) ||
                (s->enc_read_ctx == NULL) ||
                (s->read_hash == NULL))
-    clear=1;
+               clear=1;
 
        if (!clear)
                {
-               mac_size=EVP_MD_size(s->read_hash);
+               /* !clear => s->read_hash != NULL => mac_size != -1 */
+               int t;
+               t=EVP_MD_CTX_size(s->read_hash);
+               OPENSSL_assert(t >= 0);
+               mac_size=t;
 
                if (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH+mac_size)
                        {
@@ -401,7 +443,7 @@ if (        (sess == NULL) ||
                        SSLerr(SSL_F_DTLS1_PROCESS_RECORD,SSL_R_PRE_MAC_LENGTH_TOO_LONG);
                        goto f_err;
 #else
-                       goto err;
+                       decryption_failed_or_bad_record_mac = 1;
 #endif                 
                        }
                /* check the MAC for rr->input (it's in mac_size bytes at the tail) */
@@ -412,17 +454,25 @@ if (      (sess == NULL) ||
                        SSLerr(SSL_F_DTLS1_PROCESS_RECORD,SSL_R_LENGTH_TOO_SHORT);
                        goto f_err;
 #else
-                       goto err;
+                       decryption_failed_or_bad_record_mac = 1;
 #endif
                        }
                rr->length-=mac_size;
-               s->method->ssl3_enc->mac(s,md,0);
-               if (memcmp(md,&(rr->data[rr->length]),mac_size) != 0)
+               i=s->method->ssl3_enc->mac(s,md,0);
+               if (i < 0 || memcmp(md,&(rr->data[rr->length]),mac_size) != 0)
                        {
-                       goto err;
+                       decryption_failed_or_bad_record_mac = 1;
                        }
                }
 
+       if (decryption_failed_or_bad_record_mac)
+               {
+               /* decryption failed, silently discard message */
+               rr->length = 0;
+               s->packet_length = 0;
+               goto err;
+               }
+
        /* r->length is now just compressed */
        if (s->expand != NULL)
                {
@@ -458,8 +508,8 @@ if (        (sess == NULL) ||
 
        /* we have pulled in a full packet so zero things */
        s->packet_length=0;
-    dtls1_record_bitmap_update(s, &(s->d1->bitmap));/* Mark receipt of record. */
-    return(1);
+       dtls1_record_bitmap_update(s, &(s->d1->bitmap));/* Mark receipt of record. */
+       return(1);
 
 f_err:
        ssl3_send_alert(s,SSL3_AL_FATAL,al);
@@ -489,9 +539,9 @@ int dtls1_get_record(SSL *s)
 
        rr= &(s->s3->rrec);
 
-    /* The epoch may have changed.  If so, process all the
-     * pending records.  This is a non-blocking operation. */
-    dtls1_process_buffered_records(s);
+       /* The epoch may have changed.  If so, process all the
+        * pending records.  This is a non-blocking operation. */
+       dtls1_process_buffered_records(s);
 
        /* if we're renegotiating, then there may be buffered records */
        if (dtls1_get_processed_record(s))
@@ -535,7 +585,7 @@ again:
                /* Lets check version */
                if (!s->first_packet)
                        {
-                       if (version != s->version && version != DTLS1_BAD_VER)
+                       if (version != s->version)
                                {
                                /* unexpected version, silently discard */
                                rr->length = 0;
@@ -544,8 +594,7 @@ again:
                                }
                        }
 
-               if ((version & 0xff00) != (DTLS1_VERSION & 0xff00) &&
-                   (version & 0xff00) != (DTLS1_BAD_VER & 0xff00))
+               if ((version & 0xff00) != (s->version & 0xff00))
                        {
                        /* wrong version, silently discard record */
                        rr->length = 0;
@@ -561,7 +610,24 @@ again:
                        goto again;
                        }
 
-               s->client_version = version;
+               /* If we receive a valid record larger than the current buffer size,
+                * allocate some memory for it.
+                */
+               if (rr->length > s->s3->rbuf.len - DTLS1_RT_HEADER_LENGTH)
+                       {
+                       unsigned char *pp;
+                       unsigned int newlen = rr->length + DTLS1_RT_HEADER_LENGTH;
+                       if ((pp=OPENSSL_realloc(s->s3->rbuf.buf, newlen))==NULL)
+                               {
+                               SSLerr(SSL_F_DTLS1_GET_RECORD,ERR_R_MALLOC_FAILURE);
+                               return(-1);
+                               }
+                       p = pp + (p - s->s3->rbuf.buf);
+                       s->s3->rbuf.buf=pp;
+                       s->s3->rbuf.len=newlen;
+                       s->packet= &(s->s3->rbuf.buf[0]);
+                       }
+
                /* now s->rstate == SSL_ST_READ_BODY */
                }
 
@@ -590,13 +656,13 @@ again:
        /* match epochs.  NULL means the packet is dropped on the floor */
        bitmap = dtls1_get_bitmap(s, rr, &is_next_epoch);
        if ( bitmap == NULL)
-        {
-       rr->length = 0;
-        s->packet_length = 0;  /* dump this record */
-        goto again;   /* get another record */
+               {
+               rr->length = 0;
+               s->packet_length = 0;  /* dump this record */
+               goto again;   /* get another record */
                }
 
-       /* Check whether this is a repeat, or aged record.
+       /* Check whether this is a repeat, or aged record.
         * Don't check if we're listening and this message is
         * a ClientHello. They can look as if they're replayed,
         * since they arrive from different connections and
@@ -604,7 +670,7 @@ again:
         */
        if (!(s->d1->listen && rr->type == SSL3_RT_HANDSHAKE &&
                *p == SSL3_MT_CLIENT_HELLO) &&
-               ! dtls1_record_replay_check(s, bitmap, &(rr->seq_num)))
+               !dtls1_record_replay_check(s, bitmap))
                {
                rr->length = 0;
                s->packet_length=0; /* dump this record */
@@ -616,23 +682,25 @@ again:
 
        /* If this record is from the next epoch (either HM or ALERT),
         * and a handshake is currently in progress, buffer it since it
-        * cannot be processed at this time. */
+        * cannot be processed at this time. However, do not buffer
+        * anything while listening.
+        */
        if (is_next_epoch)
                {
-               if (SSL_in_init(s) || s->in_handshake)
+               if ((SSL_in_init(s) || s->in_handshake) && !s->d1->listen)
                        {
-                       dtls1_buffer_record(s, &(s->d1->unprocessed_rcds), &rr->seq_num);
+                       dtls1_buffer_record(s, &(s->d1->unprocessed_rcds), rr->seq_num);
                        }
                rr->length = 0;
-        s->packet_length = 0;
-        goto again;
-        }
+               s->packet_length = 0;
+               goto again;
+               }
 
-    if (!dtls1_process_record(s))
+       if (!dtls1_process_record(s))
                {
                rr->length = 0;
-               s->packet_length=0; /* dump this record */
-               goto again;     /* get another record */
+               s->packet_length = 0;  /* dump this record */
+               goto again;   /* get another record */
                }
 
        dtls1_clear_timeouts(s);  /* done waiting */
@@ -761,7 +829,7 @@ start:
                 * buffer the application data for later processing rather
                 * than dropping the connection.
                 */
-               dtls1_buffer_record(s, &(s->d1->buffered_app_data), &rr->seq_num);
+               dtls1_buffer_record(s, &(s->d1->buffered_app_data), rr->seq_num);
                rr->length = 0;
                goto start;
                }
@@ -1043,13 +1111,14 @@ start:
 
                dtls1_get_ccs_header(rr->data, &ccs_hdr);
 
+               if (s->version == DTLS1_BAD_VER)
+                       ccs_hdr_len = 3;
+
                /* 'Change Cipher Spec' is just a single byte, so we know
                 * exactly what the record payload has to look like */
                /* XDTLS: check that epoch is consistent */
-               if (s->client_version == DTLS1_BAD_VER || s->version == DTLS1_BAD_VER)
-                       ccs_hdr_len = 3;
-
-               if ((rr->length != ccs_hdr_len) || (rr->off != 0) || (rr->data[0] != SSL3_MT_CCS))
+               if (    (rr->length != ccs_hdr_len) || 
+                       (rr->off != 0) || (rr->data[0] != SSL3_MT_CCS))
                        {
                        i=SSL_AD_ILLEGAL_PARAMETER;
                        SSLerr(SSL_F_DTLS1_READ_BYTES,SSL_R_BAD_CHANGE_CIPHER_SPEC);
@@ -1079,7 +1148,7 @@ start:
                /* do this whenever CCS is processed */
                dtls1_reset_seq_numbers(s, SSL3_CC_READ);
 
-               if (s->client_version == DTLS1_BAD_VER)
+               if (s->version == DTLS1_BAD_VER)
                        s->d1->handshake_read_seq++;
 
                goto start;
@@ -1295,6 +1364,7 @@ int do_dtls1_write(SSL *s, int type, const unsigned char *buf, unsigned int len,
        SSL3_BUFFER *wb;
        SSL_SESSION *sess;
        int bs;
+       unsigned int len_with_overhead = len + SSL3_RT_DEFAULT_WRITE_OVERHEAD;
 
        /* first check if there is a SSL3_BUFFER still being written
         * out.  This will happen with non blocking IO */
@@ -1304,6 +1374,16 @@ int do_dtls1_write(SSL *s, int type, const unsigned char *buf, unsigned int len,
                return(ssl3_write_pending(s,type,buf,len));
                }
 
+       if (s->s3->wbuf.len < len_with_overhead)
+               {
+               if ((p=OPENSSL_realloc(s->s3->wbuf.buf, len_with_overhead)) == NULL) {
+                       SSLerr(SSL_F_DO_DTLS1_WRITE,ERR_R_MALLOC_FAILURE);
+                       goto err;
+               }
+               s->s3->wbuf.buf = p;
+               s->s3->wbuf.len = len_with_overhead;
+               }
+
        /* If we have an alert to send, lets send it */
        if (s->s3->alert_dispatch)
                {
@@ -1322,13 +1402,17 @@ int do_dtls1_write(SSL *s, int type, const unsigned char *buf, unsigned int len,
 
        if (    (sess == NULL) ||
                (s->enc_write_ctx == NULL) ||
-               (s->write_hash == NULL))
+               (EVP_MD_CTX_md(s->write_hash) == NULL))
                clear=1;
 
        if (clear)
                mac_size=0;
        else
-               mac_size=EVP_MD_size(s->write_hash);
+               {
+               mac_size=EVP_MD_CTX_size(s->write_hash);
+               if (mac_size < 0)
+                       goto err;
+               }
 
        /* DTLS implements explicit IV, so no need for empty fragments */
 #if 0
@@ -1361,7 +1445,6 @@ int do_dtls1_write(SSL *s, int type, const unsigned char *buf, unsigned int len,
                s->s3->empty_fragment_done = 1;
                }
 #endif
-
        p = wb->buf + prefix_len;
 
        /* write the header */
@@ -1369,12 +1452,8 @@ int do_dtls1_write(SSL *s, int type, const unsigned char *buf, unsigned int len,
        *(p++)=type&0xff;
        wr->type=type;
 
-       if (s->client_version == DTLS1_BAD_VER)
-               *(p++) = DTLS1_BAD_VER>>8,
-               *(p++) = DTLS1_BAD_VER&0xff;
-       else
-               *(p++)=(s->version>>8),
-               *(p++)=s->version&0xff;
+       *(p++)=(s->version>>8);
+       *(p++)=s->version&0xff;
 
        /* field where we are to write out packet epoch, seq num and len */
        pseq=p; 
@@ -1419,7 +1498,8 @@ int do_dtls1_write(SSL *s, int type, const unsigned char *buf, unsigned int len,
 
        if (mac_size != 0)
                {
-               s->method->ssl3_enc->mac(s,&(p[wr->length + bs]),1);
+               if(s->method->ssl3_enc->mac(s,&(p[wr->length + bs]),1) < 0)
+                       goto err;
                wr->length+=mac_size;
                }
 
@@ -1496,111 +1576,50 @@ err:
 
 
 
-static int dtls1_record_replay_check(SSL *s, DTLS1_BITMAP *bitmap,
-       PQ_64BIT *seq_num)
+static int dtls1_record_replay_check(SSL *s, DTLS1_BITMAP *bitmap)
        {
-#if PQ_64BIT_IS_INTEGER
-       PQ_64BIT mask = 0x0000000000000001L;
-#endif
-       PQ_64BIT rcd_num, tmp;
-
-       pq_64bit_init(&rcd_num);
-       pq_64bit_init(&tmp);
-
-       /* this is the sequence number for the record just read */
-       pq_64bit_bin2num(&rcd_num, s->s3->read_sequence, 8);
-
-       
-       if (pq_64bit_gt(&rcd_num, &(bitmap->max_seq_num)) ||
-               pq_64bit_eq(&rcd_num, &(bitmap->max_seq_num)))
-               {
-               pq_64bit_assign(seq_num, &rcd_num);
-               pq_64bit_free(&rcd_num);
-               pq_64bit_free(&tmp);
-               return 1;  /* this record is new */
-               }
-
-       pq_64bit_sub(&tmp, &(bitmap->max_seq_num), &rcd_num);
-
-       if ( pq_64bit_get_word(&tmp) > bitmap->length)
-               {
-               pq_64bit_free(&rcd_num);
-               pq_64bit_free(&tmp);
-               return 0;  /* stale, outside the window */
-               }
+       int cmp;
+       unsigned int shift;
+       const unsigned char *seq = s->s3->read_sequence;
 
-#if PQ_64BIT_IS_BIGNUM
-       {
-       int offset;
-       pq_64bit_sub(&tmp, &(bitmap->max_seq_num), &rcd_num);
-       pq_64bit_sub_word(&tmp, 1);
-       offset = pq_64bit_get_word(&tmp);
-       if ( pq_64bit_is_bit_set(&(bitmap->map), offset))
+       cmp = satsub64be(seq,bitmap->max_seq_num);
+       if (cmp > 0)
                {
-               pq_64bit_free(&rcd_num);
-               pq_64bit_free(&tmp);
-               return 0;
+               memcpy (s->s3->rrec.seq_num,seq,8);
+               return 1; /* this record in new */
                }
-       }
-#else
-       mask <<= (bitmap->max_seq_num - rcd_num - 1);
-       if (bitmap->map & mask)
+       shift = -cmp;
+       if (shift >= sizeof(bitmap->map)*8)
+               return 0; /* stale, outside the window */
+       else if (bitmap->map & (1UL<<shift))
                return 0; /* record previously received */
-#endif
-       
-       pq_64bit_assign(seq_num, &rcd_num);
-       pq_64bit_free(&rcd_num);
-       pq_64bit_free(&tmp);
+
+       memcpy (s->s3->rrec.seq_num,seq,8);
        return 1;
        }
 
 
 static void dtls1_record_bitmap_update(SSL *s, DTLS1_BITMAP *bitmap)
        {
+       int cmp;
        unsigned int shift;
-       PQ_64BIT rcd_num;
-       PQ_64BIT tmp;
-       PQ_64BIT_CTX *ctx;
-
-       pq_64bit_init(&rcd_num);
-       pq_64bit_init(&tmp);
+       const unsigned char *seq = s->s3->read_sequence;
 
-       pq_64bit_bin2num(&rcd_num, s->s3->read_sequence, 8);
-
-       /* unfortunate code complexity due to 64-bit manipulation support
-        * on 32-bit machines */
-       if ( pq_64bit_gt(&rcd_num, &(bitmap->max_seq_num)) ||
-               pq_64bit_eq(&rcd_num, &(bitmap->max_seq_num)))
+       cmp = satsub64be(seq,bitmap->max_seq_num);
+       if (cmp > 0)
                {
-               pq_64bit_sub(&tmp, &rcd_num, &(bitmap->max_seq_num));
-               pq_64bit_add_word(&tmp, 1);
-
-               shift = (unsigned int)pq_64bit_get_word(&tmp);
-
-               pq_64bit_lshift(&(tmp), &(bitmap->map), shift);
-               pq_64bit_assign(&(bitmap->map), &tmp);
-
-               pq_64bit_set_bit(&(bitmap->map), 0);
-               pq_64bit_add_word(&rcd_num, 1);
-               pq_64bit_assign(&(bitmap->max_seq_num), &rcd_num);
-
-               pq_64bit_assign_word(&tmp, 1);
-               pq_64bit_lshift(&tmp, &tmp, bitmap->length);
-               ctx = pq_64bit_ctx_new(&ctx);
-               pq_64bit_mod(&(bitmap->map), &(bitmap->map), &tmp, ctx);
-               pq_64bit_ctx_free(ctx);
+               shift = cmp;
+               if (shift < sizeof(bitmap->map)*8)
+                       bitmap->map <<= shift, bitmap->map |= 1UL;
+               else
+                       bitmap->map = 1UL;
+               memcpy(bitmap->max_seq_num,seq,8);
                }
-       else
-               {
-               pq_64bit_sub(&tmp, &(bitmap->max_seq_num), &rcd_num);
-               pq_64bit_sub_word(&tmp, 1);
-               shift = (unsigned int)pq_64bit_get_word(&tmp);
-
-               pq_64bit_set_bit(&(bitmap->map), shift);
+       else    {
+               shift = -cmp;
+               if (shift < sizeof(bitmap->map)*8)
+                       bitmap->map |= 1UL<<shift;
                }
-
-       pq_64bit_free(&rcd_num);
-       pq_64bit_free(&tmp);
        }
 
 
@@ -1647,7 +1666,7 @@ int dtls1_dispatch_alert(SSL *s)
 #ifdef DTLS1_AD_MISSING_HANDSHAKE_MESSAGE
                    || s->s3->send_alert[1] == DTLS1_AD_MISSING_HANDSHAKE_MESSAGE
 #endif
-                  )
+                   )
                        (void)BIO_flush(s->wbio);
 
                if (s->msg_callback)
@@ -1766,17 +1785,8 @@ dtls1_reset_seq_numbers(SSL *s, int rw)
                {
                seq = s->s3->read_sequence;
                s->d1->r_epoch++;
-
-               pq_64bit_assign(&(s->d1->bitmap.map), &(s->d1->next_bitmap.map));
-               s->d1->bitmap.length = s->d1->next_bitmap.length;
-               pq_64bit_assign(&(s->d1->bitmap.max_seq_num), 
-                       &(s->d1->next_bitmap.max_seq_num));
-
-               pq_64bit_free(&(s->d1->next_bitmap.map));
-               pq_64bit_free(&(s->d1->next_bitmap.max_seq_num));
+               memcpy(&(s->d1->bitmap), &(s->d1->next_bitmap), sizeof(DTLS1_BITMAP));
                memset(&(s->d1->next_bitmap), 0x00, sizeof(DTLS1_BITMAP));
-               pq_64bit_init(&(s->d1->next_bitmap.map));
-               pq_64bit_init(&(s->d1->next_bitmap.max_seq_num));
                }
        else
                {
@@ -1788,26 +1798,6 @@ dtls1_reset_seq_numbers(SSL *s, int rw)
        memset(seq, 0x00, seq_bytes);
        }
 
-#if PQ_64BIT_IS_INTEGER
-static PQ_64BIT
-bytes_to_long_long(unsigned char *bytes, PQ_64BIT *num)
-       {
-       PQ_64BIT _num;
-
-       _num = (((PQ_64BIT)bytes[0]) << 56) |
-               (((PQ_64BIT)bytes[1]) << 48) |
-               (((PQ_64BIT)bytes[2]) << 40) |
-               (((PQ_64BIT)bytes[3]) << 32) |
-               (((PQ_64BIT)bytes[4]) << 24) |
-               (((PQ_64BIT)bytes[5]) << 16) |
-               (((PQ_64BIT)bytes[6]) <<  8) |
-               (((PQ_64BIT)bytes[7])      );
-
-          *num = _num ;
-       return _num;
-       }
-#endif
-
 
 static void
 dtls1_clear_timeouts(SSL *s)
index 5b31366..149983b 100644 (file)
@@ -4,7 +4,7 @@
  * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.  
  */
 /* ====================================================================
- * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2007 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include <openssl/evp.h>
 #include <openssl/x509.h>
 #include <openssl/md5.h>
+#include <openssl/bn.h>
 #ifndef OPENSSL_NO_DH
 #include <openssl/dh.h>
 #endif
 
-static SSL_METHOD *dtls1_get_server_method(int ver);
+static const SSL_METHOD *dtls1_get_server_method(int ver);
 static int dtls1_send_hello_verify_request(SSL *s);
 
-static SSL_METHOD *dtls1_get_server_method(int ver)
+static const SSL_METHOD *dtls1_get_server_method(int ver)
        {
        if (ver == DTLS1_VERSION)
                return(DTLSv1_server_method());
@@ -144,10 +145,12 @@ IMPLEMENT_dtls1_meth_func(DTLSv1_server_method,
 int dtls1_accept(SSL *s)
        {
        BUF_MEM *buf;
-       unsigned long l,Time=(unsigned long)time(NULL);
+       unsigned long Time=(unsigned long)time(NULL);
        void (*cb)(const SSL *ssl,int type,int val)=NULL;
+       unsigned long alg_k;
        int ret= -1;
        int new_state,state,skip=0;
+       int listen;
 
        RAND_add(&Time,sizeof(Time),0);
        ERR_clear_error();
@@ -157,11 +160,15 @@ int dtls1_accept(SSL *s)
                cb=s->info_callback;
        else if (s->ctx->info_callback != NULL)
                cb=s->ctx->info_callback;
+       
+       listen = s->d1->listen;
 
        /* init things to blank */
        s->in_handshake++;
        if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);
 
+       s->d1->listen = listen;
+
        if (s->cert == NULL)
                {
                SSLerr(SSL_F_DTLS1_ACCEPT,SSL_R_NO_CERTIFICATE_SET);
@@ -271,11 +278,23 @@ int dtls1_accept(SSL *s)
 
                        s->init_num=0;
 
+                       /* Reflect ClientHello sequence to remain stateless while listening */
+                       if (listen)
+                               {
+                               memcpy(s->s3->write_sequence, s->s3->read_sequence, sizeof(s->s3->write_sequence));
+                               }
+
                        /* If we're just listening, stop here */
-                       if (s->d1->listen && s->state == SSL3_ST_SW_SRVR_HELLO_A)
+                       if (listen && s->state == SSL3_ST_SW_SRVR_HELLO_A)
                                {
                                ret = 2;
                                s->d1->listen = 0;
+                               /* Set expected sequence numbers
+                                * to continue the handshake.
+                                */
+                               s->d1->handshake_read_seq = 2;
+                               s->d1->handshake_write_seq = 1;
+                               s->d1->next_handshake_write_seq = 1;
                                goto end;
                                }
                        
@@ -284,14 +303,13 @@ int dtls1_accept(SSL *s)
                case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A:
                case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B:
 
-                       dtls1_start_timer(s);
                        ret = dtls1_send_hello_verify_request(s);
                        if ( ret <= 0) goto end;
                        s->state=SSL3_ST_SW_FLUSH;
                        s->s3->tmp.next_state=SSL3_ST_SR_CLNT_HELLO_A;
 
-                       /* HelloVerifyRequests resets Finished MAC */
-                       if (s->client_version != DTLS1_BAD_VER)
+                       /* HelloVerifyRequest resets Finished MAC */
+                       if (s->version != DTLS1_BAD_VER)
                                ssl3_init_finished_mac(s);
                        break;
                        
@@ -321,8 +339,9 @@ int dtls1_accept(SSL *s)
 
                case SSL3_ST_SW_CERT_A:
                case SSL3_ST_SW_CERT_B:
-                       /* Check if it is anon DH */
-                       if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL))
+                       /* Check if it is anon DH or normal PSK */
+                       if (!(s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL)
+                               && !(s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK))
                                {
                                dtls1_start_timer(s);
                                ret=dtls1_send_server_certificate(s);
@@ -350,13 +369,13 @@ int dtls1_accept(SSL *s)
 
                case SSL3_ST_SW_KEY_EXCH_A:
                case SSL3_ST_SW_KEY_EXCH_B:
-                       l=s->s3->tmp.new_cipher->algorithms;
+                       alg_k = s->s3->tmp.new_cipher->algorithm_mkey;
 
                        /* clear this, it may get reset by
                         * send_server_key_exchange */
                        if ((s->options & SSL_OP_EPHEMERAL_RSA)
 #ifndef OPENSSL_NO_KRB5
-                               && !(l & SSL_KRB5)
+                               && !(alg_k & SSL_kKRB5)
 #endif /* OPENSSL_NO_KRB5 */
                                )
                                /* option SSL_OP_EPHEMERAL_RSA sends temporary RSA key
@@ -367,11 +386,17 @@ int dtls1_accept(SSL *s)
                        else
                                s->s3->tmp.use_rsa_tmp=0;
 
-                       /* only send if a DH key exchange, fortezza or
+                       /* only send if a DH key exchange or
                         * RSA but we have a sign only certificate */
                        if (s->s3->tmp.use_rsa_tmp
-                           || (l & (SSL_DH|SSL_kFZA))
-                           || ((l & SSL_kRSA)
+                       /* PSK: send ServerKeyExchange if PSK identity
+                        * hint if provided */
+#ifndef OPENSSL_NO_PSK
+                           || ((alg_k & SSL_kPSK) && s->ctx->psk_identity_hint)
+#endif
+                           || (alg_k & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
+                           || (alg_k & SSL_kEECDH)
+                           || ((alg_k & SSL_kRSA)
                                && (s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL
                                    || (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher)
                                        && EVP_PKEY_size(s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey)*8 > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)
@@ -402,12 +427,15 @@ int dtls1_accept(SSL *s)
                                /* never request cert in anonymous ciphersuites
                                 * (see section "Certificate request" in SSL 3 drafts
                                 * and in RFC 2246): */
-                               ((s->s3->tmp.new_cipher->algorithms & SSL_aNULL) &&
+                               ((s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL) &&
                                 /* ... except when the application insists on verification
                                  * (against the specs, but s3_clnt.c accepts this for SSL 3) */
                                 !(s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) ||
-                                 /* never request cert in Kerberos ciphersuites */
-                                (s->s3->tmp.new_cipher->algorithms & SSL_aKRB5))
+                                /* never request cert in Kerberos ciphersuites */
+                               (s->s3->tmp.new_cipher->algorithm_auth & SSL_aKRB5)
+                               /* With normal PSK Certificates and
+                                * Certificate Requests are omitted */
+                               || (s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK))
                                {
                                /* no cert request */
                                skip=1;
@@ -479,15 +507,30 @@ int dtls1_accept(SSL *s)
                        s->state=SSL3_ST_SR_CERT_VRFY_A;
                        s->init_num=0;
 
-                       /* We need to get hashes here so if there is
-                        * a client cert, it can be verified */ 
-                       s->method->ssl3_enc->cert_verify_mac(s,
-                               &(s->s3->finish_dgst1),
-                               &(s->s3->tmp.cert_verify_md[0]));
-                       s->method->ssl3_enc->cert_verify_mac(s,
-                               &(s->s3->finish_dgst2),
-                               &(s->s3->tmp.cert_verify_md[MD5_DIGEST_LENGTH]));
+                       if (ret == 2)
+                               {
+                               /* For the ECDH ciphersuites when
+                                * the client sends its ECDH pub key in
+                                * a certificate, the CertificateVerify
+                                * message is not sent.
+                                */
+                               s->state=SSL3_ST_SR_FINISHED_A;
+                               s->init_num = 0;
+                               }
+                       else
+                               {
+                               s->state=SSL3_ST_SR_CERT_VRFY_A;
+                               s->init_num=0;
 
+                               /* We need to get hashes here so if there is
+                                * a client cert, it can be verified */ 
+                               s->method->ssl3_enc->cert_verify_mac(s,
+                                       NID_md5,
+                                       &(s->s3->tmp.cert_verify_md[0]));
+                               s->method->ssl3_enc->cert_verify_mac(s,
+                                       NID_sha1,
+                                       &(s->s3->tmp.cert_verify_md[MD5_DIGEST_LENGTH]));
+                               }
                        break;
 
                case SSL3_ST_SR_CERT_VRFY_A:
@@ -686,12 +729,8 @@ int dtls1_send_hello_verify_request(SSL *s)
                buf = (unsigned char *)s->init_buf->data;
 
                msg = p = &(buf[DTLS1_HM_HEADER_LENGTH]);
-               if (s->client_version == DTLS1_BAD_VER)
-                       *(p++) = DTLS1_BAD_VER>>8,
-                       *(p++) = DTLS1_BAD_VER&0xff;
-               else
-                       *(p++) = s->version >> 8,
-                       *(p++) = s->version & 0xFF;
+               *(p++) = s->version >> 8;
+               *(p++) = s->version & 0xFF;
 
                if (s->ctx->app_gen_cookie_cb == NULL ||
                     s->ctx->app_gen_cookie_cb(s, s->d1->cookie,
@@ -713,9 +752,6 @@ int dtls1_send_hello_verify_request(SSL *s)
                /* number of bytes to write */
                s->init_num=p-buf;
                s->init_off=0;
-
-               /* buffer the message to handle re-xmits */
-               dtls1_buffer_message(s, 0);
                }
 
        /* s->state = DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B */
@@ -740,12 +776,8 @@ int dtls1_send_server_hello(SSL *s)
                /* Do the message type and length last */
                d=p= &(buf[DTLS1_HM_HEADER_LENGTH]);
 
-               if (s->client_version == DTLS1_BAD_VER)
-                       *(p++)=DTLS1_BAD_VER>>8,
-                       *(p++)=DTLS1_BAD_VER&0xff;
-               else
-                       *(p++)=s->version>>8,
-                       *(p++)=s->version&0xff;
+               *(p++)=s->version>>8;
+               *(p++)=s->version&0xff;
 
                /* Random stuff */
                memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE);
@@ -851,6 +883,13 @@ int dtls1_send_server_key_exchange(SSL *s)
 #ifndef OPENSSL_NO_DH
        DH *dh=NULL,*dhp;
 #endif
+#ifndef OPENSSL_NO_ECDH
+       EC_KEY *ecdh=NULL, *ecdhp;
+       unsigned char *encodedPoint = NULL;
+       int encodedlen = 0;
+       int curve_id = 0;
+       BN_CTX *bn_ctx = NULL; 
+#endif
        EVP_PKEY *pkey;
        unsigned char *p,*d;
        int al,i;
@@ -865,7 +904,7 @@ int dtls1_send_server_key_exchange(SSL *s)
        EVP_MD_CTX_init(&md_ctx);
        if (s->state == SSL3_ST_SW_KEY_EXCH_A)
                {
-               type=s->s3->tmp.new_cipher->algorithms & SSL_MKEY_MASK;
+               type=s->s3->tmp.new_cipher->algorithm_mkey;
                cert=s->cert;
 
                buf=s->init_buf;
@@ -959,6 +998,141 @@ int dtls1_send_server_key_exchange(SSL *s)
                        }
                else 
 #endif
+#ifndef OPENSSL_NO_ECDH
+                       if (type & SSL_kEECDH)
+                       {
+                       const EC_GROUP *group;
+
+                       ecdhp=cert->ecdh_tmp;
+                       if ((ecdhp == NULL) && (s->cert->ecdh_tmp_cb != NULL))
+                               {
+                               ecdhp=s->cert->ecdh_tmp_cb(s,
+                                     SSL_C_IS_EXPORT(s->s3->tmp.new_cipher),
+                                     SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher));
+                               }
+                       if (ecdhp == NULL)
+                               {
+                               al=SSL_AD_HANDSHAKE_FAILURE;
+                               SSLerr(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE,SSL_R_MISSING_TMP_ECDH_KEY);
+                               goto f_err;
+                               }
+
+                       if (s->s3->tmp.ecdh != NULL)
+                               {
+                               EC_KEY_free(s->s3->tmp.ecdh); 
+                               SSLerr(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);
+                               goto err;
+                               }
+
+                       /* Duplicate the ECDH structure. */
+                       if (ecdhp == NULL)
+                               {
+                               SSLerr(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE,ERR_R_ECDH_LIB);
+                               goto err;
+                               }
+                       if ((ecdh = EC_KEY_dup(ecdhp)) == NULL)
+                               {
+                               SSLerr(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE,ERR_R_ECDH_LIB);
+                               goto err;
+                               }
+
+                       s->s3->tmp.ecdh=ecdh;
+                       if ((EC_KEY_get0_public_key(ecdh) == NULL) ||
+                           (EC_KEY_get0_private_key(ecdh) == NULL) ||
+                           (s->options & SSL_OP_SINGLE_ECDH_USE))
+                               {
+                               if(!EC_KEY_generate_key(ecdh))
+                                   {
+                                   SSLerr(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE,ERR_R_ECDH_LIB);
+                                   goto err;
+                                   }
+                               }
+
+                       if (((group = EC_KEY_get0_group(ecdh)) == NULL) ||
+                           (EC_KEY_get0_public_key(ecdh)  == NULL) ||
+                           (EC_KEY_get0_private_key(ecdh) == NULL))
+                               {
+                               SSLerr(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE,ERR_R_ECDH_LIB);
+                               goto err;
+                               }
+
+                       if (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) &&
+                           (EC_GROUP_get_degree(group) > 163)) 
+                               {
+                               SSLerr(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE,SSL_R_ECGROUP_TOO_LARGE_FOR_CIPHER);
+                               goto err;
+                               }
+
+                       /* XXX: For now, we only support ephemeral ECDH
+                        * keys over named (not generic) curves. For 
+                        * supported named curves, curve_id is non-zero.
+                        */
+                       if ((curve_id = 
+                           tls1_ec_nid2curve_id(EC_GROUP_get_curve_name(group)))
+                           == 0)
+                               {
+                               SSLerr(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNSUPPORTED_ELLIPTIC_CURVE);
+                               goto err;
+                               }
+
+                       /* Encode the public key.
+                        * First check the size of encoding and
+                        * allocate memory accordingly.
+                        */
+                       encodedlen = EC_POINT_point2oct(group, 
+                           EC_KEY_get0_public_key(ecdh),
+                           POINT_CONVERSION_UNCOMPRESSED, 
+                           NULL, 0, NULL);
+
+                       encodedPoint = (unsigned char *) 
+                           OPENSSL_malloc(encodedlen*sizeof(unsigned char)); 
+                       bn_ctx = BN_CTX_new();
+                       if ((encodedPoint == NULL) || (bn_ctx == NULL))
+                               {
+                               SSLerr(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE);
+                               goto err;
+                               }
+
+
+                       encodedlen = EC_POINT_point2oct(group, 
+                           EC_KEY_get0_public_key(ecdh), 
+                           POINT_CONVERSION_UNCOMPRESSED, 
+                           encodedPoint, encodedlen, bn_ctx);
+
+                       if (encodedlen == 0) 
+                               {
+                               SSLerr(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE,ERR_R_ECDH_LIB);
+                               goto err;
+                               }
+
+                       BN_CTX_free(bn_ctx);  bn_ctx=NULL;
+
+                       /* XXX: For now, we only support named (not 
+                        * generic) curves in ECDH ephemeral key exchanges.
+                        * In this situation, we need four additional bytes
+                        * to encode the entire ServerECDHParams
+                        * structure. 
+                        */
+                       n = 4 + encodedlen;
+
+                       /* We'll generate the serverKeyExchange message
+                        * explicitly so we can set these to NULLs
+                        */
+                       r[0]=NULL;
+                       r[1]=NULL;
+                       r[2]=NULL;
+                       r[3]=NULL;
+                       }
+               else 
+#endif /* !OPENSSL_NO_ECDH */
+#ifndef OPENSSL_NO_PSK
+                       if (type & SSL_kPSK)
+                               {
+                               /* reserve size for record length and PSK identity hint*/
+                               n+=2+strlen(s->ctx->psk_identity_hint);
+                               }
+                       else
+#endif /* !OPENSSL_NO_PSK */
                        {
                        al=SSL_AD_HANDSHAKE_FAILURE;
                        SSLerr(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE);
@@ -970,7 +1144,8 @@ int dtls1_send_server_key_exchange(SSL *s)
                        n+=2+nr[i];
                        }
 
-               if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL))
+               if (!(s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL)
+                       && !(s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK))
                        {
                        if ((pkey=ssl_get_sign_pkey(s,s->s3->tmp.new_cipher))
                                == NULL)
@@ -1001,6 +1176,41 @@ int dtls1_send_server_key_exchange(SSL *s)
                        p+=nr[i];
                        }
 
+#ifndef OPENSSL_NO_ECDH
+               if (type & SSL_kEECDH) 
+                       {
+                       /* XXX: For now, we only support named (not generic) curves.
+                        * In this situation, the serverKeyExchange message has:
+                        * [1 byte CurveType], [2 byte CurveName]
+                        * [1 byte length of encoded point], followed by
+                        * the actual encoded point itself
+                        */
+                       *p = NAMED_CURVE_TYPE;
+                       p += 1;
+                       *p = 0;
+                       p += 1;
+                       *p = curve_id;
+                       p += 1;
+                       *p = encodedlen;
+                       p += 1;
+                       memcpy((unsigned char*)p, 
+                           (unsigned char *)encodedPoint, 
+                           encodedlen);
+                       OPENSSL_free(encodedPoint);
+                       p += encodedlen;
+                       }
+#endif
+
+#ifndef OPENSSL_NO_PSK
+               if (type & SSL_kPSK)
+                       {
+                       /* copy PSK identity hint */
+                       s2n(strlen(s->ctx->psk_identity_hint), p); 
+                       strncpy((char *)p, s->ctx->psk_identity_hint, strlen(s->ctx->psk_identity_hint));
+                       p+=strlen(s->ctx->psk_identity_hint);
+                       }
+#endif
+
                /* not anonymous */
                if (pkey != NULL)
                        {
@@ -1054,6 +1264,25 @@ int dtls1_send_server_key_exchange(SSL *s)
                                }
                        else
 #endif
+#if !defined(OPENSSL_NO_ECDSA)
+                               if (pkey->type == EVP_PKEY_EC)
+                               {
+                               /* let's do ECDSA */
+                               EVP_SignInit_ex(&md_ctx,EVP_ecdsa(), NULL);
+                               EVP_SignUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
+                               EVP_SignUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
+                               EVP_SignUpdate(&md_ctx,&(d[DTLS1_HM_HEADER_LENGTH]),n);
+                               if (!EVP_SignFinal(&md_ctx,&(p[2]),
+                                       (unsigned int *)&i,pkey))
+                                       {
+                                       SSLerr(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_ECDSA);
+                                       goto err;
+                                       }
+                               s2n(i,p);
+                               n+=i+2;
+                               }
+                       else
+#endif
                                {
                                /* Is this error check actually needed? */
                                al=SSL_AD_HANDSHAKE_FAILURE;
@@ -1080,6 +1309,10 @@ int dtls1_send_server_key_exchange(SSL *s)
 f_err:
        ssl3_send_alert(s,SSL3_AL_FATAL,al);
 err:
+#ifndef OPENSSL_NO_ECDH
+       if (encodedPoint != NULL) OPENSSL_free(encodedPoint);
+       BN_CTX_free(bn_ctx);
+#endif
        EVP_MD_CTX_cleanup(&md_ctx);
        return(-1);
        }
@@ -1193,14 +1426,15 @@ int dtls1_send_server_certificate(SSL *s)
        if (s->state == SSL3_ST_SW_CERT_A)
                {
                x=ssl_get_server_send_cert(s);
-               if (x == NULL &&
-                        /* VRS: allow null cert if auth == KRB5 */
-                        (s->s3->tmp.new_cipher->algorithms
-                                & (SSL_MKEY_MASK|SSL_AUTH_MASK))
-                        != (SSL_aKRB5|SSL_kKRB5))
+               if (x == NULL)
                        {
-                       SSLerr(SSL_F_DTLS1_SEND_SERVER_CERTIFICATE,ERR_R_INTERNAL_ERROR);
-                       return(0);
+                       /* VRS: allow null cert if auth == KRB5 */
+                       if ((s->s3->tmp.new_cipher->algorithm_mkey != SSL_kKRB5) ||
+                           (s->s3->tmp.new_cipher->algorithm_auth != SSL_aKRB5))
+                               {
+                               SSLerr(SSL_F_DTLS1_SEND_SERVER_CERTIFICATE,ERR_R_INTERNAL_ERROR);
+                               return(0);
+                               }
                        }
 
                l=dtls1_output_cert_chain(s,x);
index 697ff6e..2900d1d 100644 (file)
@@ -108,15 +108,17 @@ extern "C" {
 
 typedef struct dtls1_bitmap_st
        {
-       PQ_64BIT map;
-       unsigned long length;     /* sizeof the bitmap in bits */
-       PQ_64BIT max_seq_num;  /* max record number seen so far */
+       unsigned long map;              /* track 32 packets on 32-bit systems
+                                          and 64 - on 64-bit systems */
+       unsigned char max_seq_num[8];   /* max record number seen so far,
+                                          64-bit value in big-endian
+                                          encoding */
        } DTLS1_BITMAP;
 
 struct dtls1_retransmit_state
        {
        EVP_CIPHER_CTX *enc_write_ctx;  /* cryptographic state */
-       const EVP_MD *write_hash;               /* used for mac generation */
+       EVP_MD_CTX *write_hash;                 /* used for mac generation */
 #ifndef OPENSSL_NO_COMP
        COMP_CTX *compress;                             /* compression */
 #else
diff --git a/deps/openssl/openssl/ssl/fnv1a64.c b/deps/openssl/openssl/ssl/fnv1a64.c
deleted file mode 100644 (file)
index aba3673..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/* ssl/fnv1a64.c */
-
-/* Open sourcing FIXME: include correct copyright header here. */
-
-/* Fowler-Noll-Vo (FNV) hash: http://isthe.com/chongo/tech/comp/fnv/ */
-
-#include "fnv1a64.h"
-
-/* http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param */
-static const FNV1A64 FNV1A64_OFFSET_BASIS = 14695981039346656037ull;
-static const FNV1A64 FNV1A64_PRIME = 1099511628211ull;
-
-void fnv1a64_init(FNV1A64* ctx)
-       {
-       *ctx = FNV1A64_OFFSET_BASIS;
-       }
-
-void fnv1a64_update(FNV1A64* ctx, const void* voiddata, unsigned int length)
-       {
-       const unsigned char *data = voiddata;
-       unsigned int i;
-
-       for (i = 0; i < length; i++)
-               {
-               *ctx ^= data[i];
-               *ctx *= FNV1A64_PRIME;
-               }
-       }
-
-void fnv1a64_final(unsigned char out[8], const FNV1A64 *ctx)
-       {
-       const FNV1A64 native_endian_result = *ctx;
-       unsigned int i;
-
-       for (i = 0; i < 8; i++)
-               out[i] = (unsigned char) (native_endian_result >> (8 * (sizeof(FNV1A64) - i - 1)));
-       }
diff --git a/deps/openssl/openssl/ssl/fnv1a64.h b/deps/openssl/openssl/ssl/fnv1a64.h
deleted file mode 100644 (file)
index cc5c468..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-/* ssl/fnv1a64.h */
-
-/* Open sourcing FIXME: include correct copyright header here. */
-
-/* Fowler-Noll-Vo (FNV) hash: http://isthe.com/chongo/tech/comp/fnv/ */
-
-#ifndef HEADER_FNV1A64_H
-#define HEADER_FNV1A64_H
-
-#include <stdint.h>
-
-typedef uint64_t FNV1A64;
-
-void fnv1a64_init(FNV1A64* ctx);
-void fnv1a64_update(FNV1A64* ctx, const void* data, unsigned int length);
-void fnv1a64_final(unsigned char out[8], const FNV1A64 *ctx);
-
-#endif  // HEADER_FNV1A64_H
diff --git a/deps/openssl/openssl/ssl/install-ssl.com b/deps/openssl/openssl/ssl/install-ssl.com
new file mode 100644 (file)
index 0000000..1bd6cca
--- /dev/null
@@ -0,0 +1,136 @@
+$! INSTALL-SSL.COM -- Installs the files in a given directory tree
+$!
+$! Author: Richard Levitte <richard@levitte.org>
+$! Time of creation: 22-MAY-1998 10:13
+$!
+$! P1  root of the directory tree
+$! P2  "64" for 64-bit pointers.
+$!
+$!
+$! Announce/identify.
+$!
+$ proc = f$environment( "procedure")
+$ write sys$output "@@@ "+ -
+   f$parse( proc, , , "name")+ f$parse( proc, , , "type")
+$!
+$ on error then goto tidy
+$ on control_c then goto tidy
+$!
+$ if p1 .eqs. ""
+$ then
+$   write sys$output "First argument missing."
+$   write sys$output -
+     "It should be the directory where you want things installed."
+$   exit
+$ endif
+$!
+$ if (f$getsyi( "cpu") .lt. 128)
+$ then
+$     arch = "VAX"
+$ else
+$     arch = f$edit( f$getsyi( "arch_name"), "upcase")
+$     if (arch .eqs. "") then arch = "UNK"
+$ endif
+$!
+$ archd = arch
+$ lib32 = "32"
+$ shr = "_SHR32"
+$!
+$ if (p2 .nes. "")
+$ then
+$   if (p2 .eqs. "64")
+$   then
+$     archd = arch+ "_64"
+$     lib32 = ""
+$     shr = "_SHR"
+$   else
+$     if (p2 .nes. "32")
+$     then
+$       write sys$output "Second argument invalid."
+$       write sys$output "It should be "32", "64", or nothing."
+$       exit
+$     endif
+$   endif
+$ endif
+$!
+$ root = f$parse( p1, "[]A.;0", , , "syntax_only, no_conceal") - "A.;0"
+$ root_dev = f$parse(root,,,"device","syntax_only")
+$ root_dir = f$parse(root,,,"directory","syntax_only") - -
+   "[000000." - "][" - "[" - "]"
+$ root = root_dev + "[" + root_dir
+$!
+$ define /nolog wrk_sslroot 'root'.] /trans=conc
+$ define /nolog wrk_sslinclude wrk_sslroot:[include]
+$ define /nolog wrk_sslxexe wrk_sslroot:['archd'_exe]
+$ define /nolog wrk_sslxlib wrk_sslroot:['arch'_lib]
+$!
+$ if f$parse("wrk_sslroot:[000000]") .eqs. "" then -
+   create /directory /log wrk_sslroot:[000000]
+$ if f$parse("wrk_sslinclude:") .eqs. "" then -
+   create /directory /log wrk_sslinclude:
+$ if f$parse("wrk_sslxexe:") .eqs. "" then -
+   create /directory /log wrk_sslxexe:
+$ if f$parse("wrk_sslxlib:") .eqs. "" then -
+   create /directory /log wrk_sslxlib:
+$!
+$ exheader := ssl.h, ssl2.h, ssl3.h, ssl23.h, tls1.h, dtls1.h, kssl.h
+$ e_exe := ssl_task
+$ libs := ssl_libssl
+$!
+$ xexe_dir := [-.'archd'.exe.ssl]
+$!
+$ copy /protection = w:re 'exheader' wrk_sslinclude: /log
+$!
+$ i = 0
+$ loop_exe:
+$   e = f$edit( f$element( i, ",", e_exe), "trim")
+$   i = i + 1
+$   if e .eqs. "," then goto loop_exe_end
+$   set noon
+$   file = xexe_dir+ e+ ".exe"
+$   if f$search( file) .nes. ""
+$   then
+$     copy /protection = w:re 'file' wrk_sslxexe: /log
+$   endif
+$   set on
+$ goto loop_exe
+$ loop_exe_end:
+$!
+$ i = 0
+$ loop_lib: 
+$   e = f$edit(f$element(i, ",", libs),"trim")
+$   i = i + 1
+$   if e .eqs. "," then goto loop_lib_end
+$   set noon
+$! Object library.
+$   file = xexe_dir+ e+ lib32+ ".olb"
+$   if f$search( file) .nes. ""
+$   then
+$     copy /protection = w:re 'file' wrk_sslxlib: /log
+$   endif
+$! Shareable image.
+$   file = xexe_dir+ e+ shr+ ".exe"
+$   if f$search( file) .nes. ""
+$   then
+$     copy /protection = w:re 'file' wrk_sslxlib: /log
+$   endif
+$   set on
+$ goto loop_lib
+$ loop_lib_end:
+$!
+$ tidy:
+$!
+$ call deass wrk_sslroot
+$ call deass wrk_sslinclude
+$ call deass wrk_sslxexe
+$ call deass wrk_sslxlib
+$!
+$ exit
+$!
+$ deass: subroutine
+$ if (f$trnlnm( p1, "LNM$PROCESS") .nes. "")
+$ then
+$   deassign /process 'p1'
+$ endif
+$ endsubroutine
+$!
diff --git a/deps/openssl/openssl/ssl/install.com b/deps/openssl/openssl/ssl/install.com
deleted file mode 100644 (file)
index 7f56067..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-$! INSTALL.COM -- Installs the files in a given directory tree
-$!
-$! Author: Richard Levitte <richard@levitte.org>
-$! Time of creation: 22-MAY-1998 10:13
-$!
-$! P1  root of the directory tree
-$!
-$      IF P1 .EQS. ""
-$      THEN
-$          WRITE SYS$OUTPUT "First argument missing."
-$          WRITE SYS$OUTPUT -
-                 "It should be the directory where you want things installed."
-$          EXIT
-$      ENDIF
-$
-$      IF (F$GETSYI("CPU").LT.128)
-$      THEN
-$          ARCH := VAX
-$      ELSE
-$          ARCH = F$EDIT( F$GETSYI( "ARCH_NAME"), "UPCASE")
-$          IF (ARCH .EQS. "") THEN ARCH = "UNK"
-$      ENDIF
-$
-$      ROOT = F$PARSE(P1,"[]A.;0",,,"SYNTAX_ONLY,NO_CONCEAL") - "A.;0"
-$      ROOT_DEV = F$PARSE(ROOT,,,"DEVICE","SYNTAX_ONLY")
-$      ROOT_DIR = F$PARSE(ROOT,,,"DIRECTORY","SYNTAX_ONLY") -
-                  - "[000000." - "][" - "[" - "]"
-$      ROOT = ROOT_DEV + "[" + ROOT_DIR
-$
-$      DEFINE/NOLOG WRK_SSLROOT 'ROOT'.] /TRANS=CONC
-$      DEFINE/NOLOG WRK_SSLXLIB WRK_SSLROOT:['ARCH'_LIB]
-$      DEFINE/NOLOG WRK_SSLINCLUDE WRK_SSLROOT:[INCLUDE]
-$      DEFINE/NOLOG WRK_SSLXEXE WRK_SSLROOT:['ARCH'_EXE]
-$
-$      IF F$PARSE("WRK_SSLROOT:[000000]") .EQS. "" THEN -
-          CREATE/DIR/LOG WRK_SSLROOT:[000000]
-$      IF F$PARSE("WRK_SSLXLIB:") .EQS. "" THEN -
-          CREATE/DIR/LOG WRK_SSLXLIB:
-$      IF F$PARSE("WRK_SSLINCLUDE:") .EQS. "" THEN -
-          CREATE/DIR/LOG WRK_SSLINCLUDE:
-$      IF F$PARSE("WRK_SSLXEXE:") .EQS. "" THEN -
-          CREATE/DIR/LOG WRK_SSLXEXE:
-$
-$      EXHEADER := ssl.h,ssl2.h,ssl3.h,ssl23.h,tls1.h,dtls1.h,kssl.h
-$      E_EXE := ssl_task
-$      LIBS := LIBSSL
-$
-$      XEXE_DIR := [-.'ARCH'.EXE.SSL]
-$
-$      COPY 'EXHEADER' WRK_SSLINCLUDE:/LOG
-$      SET FILE/PROT=WORLD:RE WRK_SSLINCLUDE:'EXHEADER'
-$
-$      I = 0
-$ LOOP_EXE: 
-$      E = F$EDIT(F$ELEMENT(I, ",", E_EXE),"TRIM")
-$      I = I + 1
-$      IF E .EQS. "," THEN GOTO LOOP_EXE_END
-$      SET NOON
-$      IF F$SEARCH(XEXE_DIR+E+".EXE") .NES. ""
-$      THEN
-$        COPY 'XEXE_DIR''E'.EXE WRK_SSLXEXE:'E'.EXE/log
-$        SET FILE/PROT=W:RE WRK_SSLXEXE:'E'.EXE
-$      ENDIF
-$      SET ON
-$      GOTO LOOP_EXE
-$ LOOP_EXE_END:
-$
-$      I = 0
-$ LOOP_LIB: 
-$      E = F$EDIT(F$ELEMENT(I, ",", LIBS),"TRIM")
-$      I = I + 1
-$      IF E .EQS. "," THEN GOTO LOOP_LIB_END
-$      SET NOON
-$! Object library.
-$      IF F$SEARCH(XEXE_DIR+E+".OLB") .NES. ""
-$      THEN
-$        COPY 'XEXE_DIR''E'.OLB WRK_SSLXLIB:'E'.OLB/log
-$        SET FILE/PROT=W:RE WRK_SSLXLIB:'E'.OLB
-$      ENDIF
-$! Shareable image.
-$      IF F$SEARCH(XEXE_DIR+E+".EXE") .NES. ""
-$      THEN
-$        COPY 'XEXE_DIR''E'.EXE WRK_SSLXLIB:'E'.EXE/log
-$        SET FILE/PROT=W:RE WRK_SSLXLIB:'E'.EXE
-$      ENDIF
-$      SET ON
-$      GOTO LOOP_LIB
-$ LOOP_LIB_END:
-$
-$      EXIT
index 5cba28b..b820e37 100644 (file)
@@ -76,6 +76,7 @@
 #include <openssl/evp.h>
 #include <openssl/objects.h>
 #include <openssl/krb5_asn.h>
+#include "kssl_lcl.h"
 
 #ifndef OPENSSL_NO_KRB5
 
 #define krb5_principal_compare   kssl_krb5_principal_compare
 #define krb5_decrypt_tkt_part    kssl_krb5_decrypt_tkt_part
 #define krb5_timeofday           kssl_krb5_timeofday
-#define krb5_rc_default           kssl_krb5_rc_default
+#define krb5_rc_default          kssl_krb5_rc_default
 
 #ifdef krb5_rc_initialize
 #undef krb5_rc_initialize
@@ -839,7 +840,7 @@ kssl_map_enc(krb5_enctype enctype)
 **     "62 xx 30 yy" (APPLICATION-2, SEQUENCE), where xx-yy =~ 2, and
 **     xx and yy are possibly multi-byte length fields.
 */
-int    kssl_test_confound(unsigned char *p)
+static int     kssl_test_confound(unsigned char *p)
        {
        int     len = 2;
        int     xx = 0, yy = 0;
@@ -874,7 +875,7 @@ int         kssl_test_confound(unsigned char *p)
 **      what the highest assigned CKSUMTYPE_ constant is.  As of 1.2.2
 **      it is 0x000c (CKSUMTYPE_HMAC_SHA1_DES3).  So we will use 0x0010.
 */
-size_t  *populate_cksumlens(void)
+static size_t  *populate_cksumlens(void)
        {
        int             i, j, n;
        static size_t   *cklens = NULL;
@@ -1025,7 +1026,7 @@ print_krb5_keyblock(char *label, krb5_keyblock *keyblk)
 /*     Display contents of krb5_principal_data struct, for debugging
 **     (krb5_principal is typedef'd == krb5_principal_data *)
 */
-void
+static void
 print_krb5_princ(char *label, krb5_principal_data *princ)
         {
        int i, ui, uj;
@@ -1224,7 +1225,7 @@ kssl_cget_tkt(    /* UPDATE */    KSSL_CTX *kssl_ctx,
 **                             code here.  This tkt should alloc/free just
 **                             like the real thing.
 */
-krb5_error_code
+static krb5_error_code
 kssl_TKT2tkt(  /* IN     */    krb5_context    krb5context,
                /* IN     */    KRB5_TKTBODY    *asn1ticket,
                /* OUT    */    krb5_ticket     **krb5ticket,
@@ -1902,7 +1903,7 @@ void kssl_krb5_free_data_contents(krb5_context context, krb5_data *data)
 **  Return pointer to the (partially) filled in struct tm on success,
 **  return NULL on failure.
 */
-struct tm      *k_gmtime(ASN1_GENERALIZEDTIME *gtime, struct tm *k_tm)
+static struct tm *k_gmtime(ASN1_GENERALIZEDTIME *gtime, struct tm *k_tm)
        {
        char            c, *p;
 
@@ -1928,7 +1929,7 @@ struct tm *k_gmtime(ASN1_GENERALIZEDTIME *gtime, struct tm *k_tm)
 **  So we try to sneek the clockskew out through the replay cache.
 **     If that fails just return a likely default (300 seconds).
 */
-krb5_deltat    get_rc_clockskew(krb5_context context)
+static krb5_deltat get_rc_clockskew(krb5_context context)
        {
        krb5_rcache     rc;
        krb5_deltat     clockskew;
@@ -2092,9 +2093,12 @@ krb5_error_code  kssl_check_authent(
         EVP_CIPHER_CTX_cleanup(&ciph_ctx);
 
 #ifdef KSSL_DEBUG
+       {
+       int padl;
        printf("kssl_check_authent: decrypted authenticator[%d] =\n", outl);
        for (padl=0; padl < outl; padl++) printf("%02x ",unenc_authent[padl]);
        printf("\n");
+       }
 #endif /* KSSL_DEBUG */
 
        if ((p = kssl_skip_confound(enctype, unenc_authent)) == NULL)
@@ -2124,7 +2128,7 @@ krb5_error_code  kssl_check_authent(
                tm_g = gmtime(&now);            tg = mktime(tm_g);
                tz_offset = tg - tl;
 
-               *atimep = tr - tz_offset;
+               *atimep = (krb5_timestamp)(tr - tz_offset);
                }
 
 #ifdef KSSL_DEBUG
index 4cd8dd2..c039c91 100644 (file)
@@ -75,7 +75,7 @@ void print_krb5_keyblock(char *label, krb5_keyblock *keyblk);
 char *kstring(char *string);
 char *knumber(int len, krb5_octet *contents);
 
-EVP_CIPHER *kssl_map_enc(krb5_enctype enctype);
+const EVP_CIPHER *kssl_map_enc(krb5_enctype enctype);
 
 int kssl_keytab_is_available(KSSL_CTX *kssl_ctx);
 int kssl_tgt_is_available(KSSL_CTX *kssl_ctx);
index c6b9142..f41fe3a 100644 (file)
  * copied and put under another distribution licence
  * [including the GNU Public Licence.]
  */
+/* ====================================================================
+ * Copyright (c) 1998-2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    openssl-core@openssl.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
 
 #include <stdio.h>
 #include "ssl_locl.h"
 #include <openssl/objects.h>
 #include <openssl/evp.h>
 
-static SSL_METHOD *ssl23_get_client_method(int ver);
+static const SSL_METHOD *ssl23_get_client_method(int ver);
 static int ssl23_client_hello(SSL *s);
 static int ssl23_get_server_hello(SSL *s);
-static SSL_METHOD *ssl23_get_client_method(int ver)
+static const SSL_METHOD *ssl23_get_client_method(int ver)
        {
 #ifndef OPENSSL_NO_SSL2
        if (ver == SSL2_VERSION)
@@ -197,6 +250,20 @@ end:
        return(ret);
        }
 
+static int ssl23_no_ssl2_ciphers(SSL *s)
+       {
+       SSL_CIPHER *cipher;
+       STACK_OF(SSL_CIPHER) *ciphers;
+       int i;
+       ciphers = SSL_get_ciphers(s);
+       for (i = 0; i < sk_SSL_CIPHER_num(ciphers); i++)
+               {
+               cipher = sk_SSL_CIPHER_value(ciphers, i);
+               if (cipher->algorithm_ssl == SSL_SSLV2)
+                       return 0;
+               }
+       return 1;
+       }
 
 static int ssl23_client_hello(SSL *s)
        {
@@ -214,6 +281,9 @@ static int ssl23_client_hello(SSL *s)
 
        ssl2_compat = (s->options & SSL_OP_NO_SSLv2) ? 0 : 1;
 
+       if (ssl2_compat && ssl23_no_ssl2_ciphers(s))
+               ssl2_compat = 0;
+
        if (!(s->options & SSL_OP_NO_TLSv1))
                {
                version = TLS1_VERSION;
@@ -226,7 +296,7 @@ static int ssl23_client_hello(SSL *s)
                {
                version = SSL2_VERSION;
                }
-#ifndef OPENSSL_NO_TLSEXT 
+#ifndef OPENSSL_NO_TLSEXT
        if (version != SSL2_VERSION)
                {
                /* have to disable SSL 2.0 compatibility if we need TLS extensions */
@@ -235,6 +305,10 @@ static int ssl23_client_hello(SSL *s)
                        ssl2_compat = 0;
                if (s->tlsext_status_type != -1)
                        ssl2_compat = 0;
+#ifdef TLSEXT_TYPE_opaque_prf_input
+               if (s->ctx->tlsext_opaque_prf_input_callback != 0 || s->tlsext_opaque_prf_input != NULL)
+                       ssl2_compat = 0;
+#endif
                }
 #endif
 
@@ -260,14 +334,6 @@ static int ssl23_client_hello(SSL *s)
                        version_major = TLS1_VERSION_MAJOR;
                        version_minor = TLS1_VERSION_MINOR;
                        }
-#ifdef OPENSSL_FIPS
-               else if(FIPS_mode())
-                       {
-                       SSLerr(SSL_F_SSL23_CLIENT_HELLO,
-                                       SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE);
-                       return -1;
-                       }
-#endif
                else if (version == SSL3_VERSION)
                        {
                        version_major = SSL3_VERSION_MAJOR;
@@ -321,6 +387,10 @@ static int ssl23_client_hello(SSL *s)
                                ch_len=SSL2_MAX_CHALLENGE_LENGTH;
 
                        /* write out sslv2 challenge */
+                       /* Note that ch_len must be <= SSL3_RANDOM_SIZE (32),
+                          because it is one of SSL2_MAX_CHALLENGE_LENGTH (32)
+                          or SSL2_MAX_CHALLENGE_LENGTH (16), but leave the
+                          check in for futurproofing */
                        if (SSL3_RANDOM_SIZE < ch_len)
                                i=SSL3_RANDOM_SIZE;
                        else
@@ -369,11 +439,13 @@ static int ssl23_client_hello(SSL *s)
                                }
                        s2n(i,p);
                        p+=i;
+
+                       /* COMPRESSION */
 #ifdef OPENSSL_NO_COMP
                        *(p++)=1;
 #else
-                       /* COMPRESSION */
-                       if (s->ctx->comp_methods == NULL)
+                       if ((s->options & SSL_OP_NO_COMPRESSION)
+                                               || !s->ctx->comp_methods)
                                j=0;
                        else
                                j=sk_SSL_COMP_num(s->ctx->comp_methods);
@@ -385,7 +457,14 @@ static int ssl23_client_hello(SSL *s)
                                }
 #endif
                        *(p++)=0; /* Add the NULL method */
+
 #ifndef OPENSSL_NO_TLSEXT
+                       /* TLS extensions*/
+                       if (ssl_prepare_clienthello_tlsext(s) <= 0)
+                               {
+                               SSLerr(SSL_F_SSL23_CLIENT_HELLO,SSL_R_CLIENTHELLO_TLSEXT);
+                               return -1;
+                               }
                        if ((p = ssl_add_clienthello_tlsext(s, p, buf+SSL3_RT_MAX_PLAIN_LENGTH)) == NULL)
                                {
                                SSLerr(SSL_F_SSL23_CLIENT_HELLO,ERR_R_INTERNAL_ERROR);
@@ -394,7 +473,6 @@ static int ssl23_client_hello(SSL *s)
 #endif
                        
                        l = p-d;
-                       *p = 42;
 
                        /* fill in 4-byte handshake header */
                        d=&(buf[5]);
@@ -489,6 +567,10 @@ static int ssl23_get_server_hello(SSL *s)
                        ch_len=SSL2_MAX_CHALLENGE_LENGTH;
 
                /* write out sslv2 challenge */
+               /* Note that ch_len must be <= SSL3_RANDOM_SIZE (32), because
+                  it is one of SSL2_MAX_CHALLENGE_LENGTH (32) or
+                  SSL2_MAX_CHALLENGE_LENGTH (16), but leave the check in for
+                  futurproofing */
                i=(SSL3_RANDOM_SIZE < ch_len)
                        ?SSL3_RANDOM_SIZE:ch_len;
                s->s2->challenge_length=i;
@@ -509,7 +591,7 @@ static int ssl23_get_server_hello(SSL *s)
                        /* use special padding (SSL 3.0 draft/RFC 2246, App. E.2) */
                        s->s2->ssl2_rollback=1;
 
-               /* setup the 5 bytes we have read so we get them from
+               /* setup the 7 bytes we have read so we get them from
                 * the sslv2 buffer */
                s->rstate=SSL_ST_READ_HEADER;
                s->packet_length=n;
@@ -525,39 +607,16 @@ static int ssl23_get_server_hello(SSL *s)
                s->handshake_func=s->method->ssl_connect;
 #endif
                }
-       else if ((p[0] == SSL3_RT_HANDSHAKE) &&
-                (p[1] == SSL3_VERSION_MAJOR) &&
-                ((p[2] == SSL3_VERSION_MINOR) ||
-                 (p[2] == TLS1_VERSION_MINOR)) &&
-                (p[5] == SSL3_MT_SERVER_HELLO))
+       else if (p[1] == SSL3_VERSION_MAJOR &&
+                (p[2] == SSL3_VERSION_MINOR || p[2] == TLS1_VERSION_MINOR) &&
+                ((p[0] == SSL3_RT_HANDSHAKE && p[5] == SSL3_MT_SERVER_HELLO) ||
+                 (p[0] == SSL3_RT_ALERT && p[3] == 0 && p[4] == 2)))
                {
-               /* we have sslv3 or tls1 */
-
-               if (!ssl_init_wbio_buffer(s,1)) goto err;
-
-               /* we are in this state */
-               s->state=SSL3_ST_CR_SRVR_HELLO_A;
-
-               /* put the 5 bytes we have read into the input buffer
-                * for SSLv3 */
-               s->rstate=SSL_ST_READ_HEADER;
-               s->packet_length=n;
-               s->packet= &(s->s3->rbuf.buf[0]);
-               memcpy(s->packet,buf,n);
-               s->s3->rbuf.left=n;
-               s->s3->rbuf.offset=0;
+               /* we have sslv3 or tls1 (server hello or alert) */
 
                if ((p[2] == SSL3_VERSION_MINOR) &&
                        !(s->options & SSL_OP_NO_SSLv3))
                        {
-#ifdef OPENSSL_FIPS
-                       if(FIPS_mode())
-                               {
-                               SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,
-                                       SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE);
-                               goto err;
-                               }
-#endif
                        s->version=SSL3_VERSION;
                        s->method=SSLv3_client_method();
                        }
@@ -572,35 +631,52 @@ static int ssl23_get_server_hello(SSL *s)
                        SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_PROTOCOL);
                        goto err;
                        }
-                       
-               s->handshake_func=s->method->ssl_connect;
-               }
-       else if ((p[0] == SSL3_RT_ALERT) &&
-                (p[1] == SSL3_VERSION_MAJOR) &&
-                ((p[2] == SSL3_VERSION_MINOR) ||
-                 (p[2] == TLS1_VERSION_MINOR)) &&
-                (p[3] == 0) &&
-                (p[4] == 2))
-               {
-               void (*cb)(const SSL *ssl,int type,int val)=NULL;
-               int j;
-
-               /* An alert */
-               if (s->info_callback != NULL)
-                       cb=s->info_callback;
-               else if (s->ctx->info_callback != NULL)
-                       cb=s->ctx->info_callback;
-               i=p[5];
-               if (cb != NULL)
+
+               if (p[0] == SSL3_RT_ALERT && p[5] != SSL3_AL_WARNING)
                        {
-                       j=(i<<8)|p[6];
-                       cb(s,SSL_CB_READ_ALERT,j);
+                       /* fatal alert */
+
+                       void (*cb)(const SSL *ssl,int type,int val)=NULL;
+                       int j;
+
+                       if (s->info_callback != NULL)
+                               cb=s->info_callback;
+                       else if (s->ctx->info_callback != NULL)
+                               cb=s->ctx->info_callback;
+                       i=p[5];
+                       if (cb != NULL)
+                               {
+                               j=(i<<8)|p[6];
+                               cb(s,SSL_CB_READ_ALERT,j);
+                               }
+                       
+                       if (s->msg_callback)
+                               s->msg_callback(0, s->version, SSL3_RT_ALERT, p+5, 2, s, s->msg_callback_arg);
+
+                       s->rwstate=SSL_NOTHING;
+                       SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_AD_REASON_OFFSET+p[6]);
+                       goto err;
                        }
 
-               s->rwstate=SSL_NOTHING;
-               SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_AD_REASON_OFFSET+p[6]);
-               goto err;
+               if (!ssl_init_wbio_buffer(s,1)) goto err;
+
+               /* we are in this state */
+               s->state=SSL3_ST_CR_SRVR_HELLO_A;
+
+               /* put the 7 bytes we have read into the input buffer
+                * for SSLv3 */
+               s->rstate=SSL_ST_READ_HEADER;
+               s->packet_length=n;
+               if (s->s3->rbuf.buf == NULL)
+                       if (!ssl3_setup_read_buffer(s))
+                               goto err;
+               s->packet= &(s->s3->rbuf.buf[0]);
+               memcpy(s->packet,buf,n);
+               s->s3->rbuf.left=n;
+               s->s3->rbuf.offset=0;
+
+               s->handshake_func=s->method->ssl_connect;
                }
        else
                {
@@ -611,6 +687,13 @@ static int ssl23_get_server_hello(SSL *s)
 
        /* Since, if we are sending a ssl23 client hello, we are not
         * reusing a session-id */
+        if (!s->session_creation_enabled)
+               {
+               if (!(s->client_version == SSL2_VERSION))
+                       ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
+               SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_SESSION_MAY_NOT_BE_CREATED);
+               goto err;
+               }
        if (!ssl_get_new_session(s,0))
                goto err;
 
@@ -618,4 +701,3 @@ static int ssl23_get_server_hello(SSL *s)
 err:
        return(-1);
        }
-
index 0b82777..3bf7283 100644 (file)
@@ -65,11 +65,6 @@ long ssl23_default_timeout(void)
        return(300);
        }
 
-IMPLEMENT_ssl23_meth_func(sslv23_base_method,
-                       ssl_undefined_function,
-                       ssl_undefined_function,
-                       ssl_bad_method)
-
 int ssl23_num_ciphers(void)
        {
        return(ssl3_num_ciphers()
@@ -79,7 +74,7 @@ int ssl23_num_ciphers(void)
            );
        }
 
-SSL_CIPHER *ssl23_get_cipher(unsigned int u)
+const SSL_CIPHER *ssl23_get_cipher(unsigned int u)
        {
        unsigned int uu=ssl3_num_ciphers();
 
@@ -95,9 +90,9 @@ SSL_CIPHER *ssl23_get_cipher(unsigned int u)
 
 /* This function needs to check if the ciphers required are actually
  * available */
-SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p)
+const SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p)
        {
-       SSL_CIPHER *cp;
+       const SSL_CIPHER *cp;
 
        cp=ssl3_get_cipher_by_char(p);
 #ifndef OPENSSL_NO_SSL2
index 950d9aa..c6099ef 100644 (file)
@@ -60,8 +60,8 @@
 #include <openssl/objects.h>
 #include "ssl_locl.h"
 
-static SSL_METHOD *ssl23_get_method(int ver);
-static SSL_METHOD *ssl23_get_method(int ver)
+static const SSL_METHOD *ssl23_get_method(int ver);
+static const SSL_METHOD *ssl23_get_method(int ver)
        {
 #ifndef OPENSSL_NO_SSL2
        if (ver == SSL2_VERSION)
index be05911..e22879c 100644 (file)
@@ -56,7 +56,7 @@
  * [including the GNU Public Licence.]
  */
 /* ====================================================================
- * Copyright (c) 1998-2001 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include <openssl/objects.h>
 #include <openssl/evp.h>
 
-static SSL_METHOD *ssl23_get_server_method(int ver);
+static const SSL_METHOD *ssl23_get_server_method(int ver);
 int ssl23_get_client_hello(SSL *s);
-static SSL_METHOD *ssl23_get_server_method(int ver)
+static const SSL_METHOD *ssl23_get_server_method(int ver)
        {
 #ifndef OPENSSL_NO_SSL2
        if (ver == SSL2_VERSION)
@@ -393,15 +393,6 @@ int ssl23_get_client_hello(SSL *s)
                        }
                }
 
-#ifdef OPENSSL_FIPS
-       if (FIPS_mode() && (s->version < TLS1_VERSION))
-               {
-               SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,
-                                       SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE);
-               goto err;
-               }
-#endif
-
        if (s->state == SSL23_ST_SR_CLNT_HELLO_B)
                {
                /* we have SSLv3/TLSv1 in an SSLv2 header
@@ -412,8 +403,13 @@ int ssl23_get_client_hello(SSL *s)
                v[0] = p[3]; /* == SSL3_VERSION_MAJOR */
                v[1] = p[4];
 
+/* The SSL2 protocol allows n to be larger, just pick
+ * a reasonable buffer size. */
+#if SSL3_RT_DEFAULT_PACKET_SIZE < 1024*4 - SSL3_RT_DEFAULT_WRITE_OVERHEAD
+#error "SSL3_RT_DEFAULT_PACKET_SIZE is too small."
+#endif
                n=((p[0]&0x7f)<<8)|p[1];
-               if (n > (1024*4))
+               if (n > SSL3_RT_DEFAULT_PACKET_SIZE - 2)
                        {
                        SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_TOO_LARGE);
                        goto err;
@@ -432,7 +428,9 @@ int ssl23_get_client_hello(SSL *s)
                n2s(p,sil);
                n2s(p,cl);
                d=(unsigned char *)s->init_buf->data;
-               if ((csl+sil+cl+11) != s->packet_length)
+               if ((csl+sil+cl+11) != s->packet_length) /* We can't have TLS extensions in SSL 2.0 format
+                                                         * Client Hello, can we? Error condition should be
+                                                         * '>' otherweise */
                        {
                        SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_LENGTH_MISMATCH);
                        goto err;
@@ -475,6 +473,15 @@ int ssl23_get_client_hello(SSL *s)
                *(d++)=1;
                *(d++)=0;
                
+#if 0
+                /* copy any remaining data with may be extensions */
+               p = p+csl+sil+cl;
+               while (p <  s->packet+s->packet_length)
+                       {
+                       *(d++)=*(p++);
+                       }
+#endif
+
                i = (d-(unsigned char *)s->init_buf->data) - 4;
                l2n3((long)i, d_len);
 
@@ -550,6 +557,10 @@ int ssl23_get_client_hello(SSL *s)
                         * for SSLv3 */
                        s->rstate=SSL_ST_READ_HEADER;
                        s->packet_length=n;
+                       if (s->s3->rbuf.buf == NULL)
+                               if (!ssl3_setup_read_buffer(s))
+                                       goto err;
+
                        s->packet= &(s->s3->rbuf.buf[0]);
                        memcpy(s->packet,buf,n);
                        s->s3->rbuf.left=n;
index 782129c..00ac158 100644 (file)
 #include <openssl/objects.h>
 #include <openssl/evp.h>
 
-static SSL_METHOD *ssl2_get_client_method(int ver);
+static const SSL_METHOD *ssl2_get_client_method(int ver);
 static int get_server_finished(SSL *s);
 static int get_server_verify(SSL *s);
 static int get_server_hello(SSL *s);
@@ -129,7 +129,7 @@ static int ssl_rsa_public_encrypt(SESS_CERT *sc, int len, unsigned char *from,
        unsigned char *to,int padding);
 #define BREAK  break
 
-static SSL_METHOD *ssl2_get_client_method(int ver)
+static const SSL_METHOD *ssl2_get_client_method(int ver)
        {
        if (ver == SSL2_VERSION)
                return(SSLv2_client_method());
@@ -621,7 +621,7 @@ static int client_master_key(SSL *s)
        if (s->state == SSL2_ST_SEND_CLIENT_MASTER_KEY_A)
                {
 
-               if (!ssl_cipher_get_evp(s->session,&c,&md,NULL))
+               if (!ssl_cipher_get_evp(s->session,&c,&md,NULL,NULL,NULL))
                        {
                        ssl2_return_error(s,SSL2_PE_NO_CIPHER);
                        SSLerr(SSL_F_CLIENT_MASTER_KEY,SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS);
@@ -863,8 +863,10 @@ static int client_certificate(SSL *s)
                EVP_SignUpdate(&ctx,s->s2->key_material,
                               s->s2->key_material_length);
                EVP_SignUpdate(&ctx,cert_ch,(unsigned int)cert_ch_len);
-               n=i2d_X509(s->session->sess_cert->peer_key->x509,&p);
-               EVP_SignUpdate(&ctx,buf,(unsigned int)n);
+               i=i2d_X509(s->session->sess_cert->peer_key->x509,&p);
+               /* Don't update the signature if it fails - FIXME: probably should handle this better */
+               if(i > 0)
+                       EVP_SignUpdate(&ctx,buf,(unsigned int)i);
 
                p=buf;
                d=p+6;
index 1f62acd..ff3395f 100644 (file)
@@ -68,15 +68,14 @@ int ssl2_enc_init(SSL *s, int client)
        const EVP_MD *md;
        int num;
 
-       if (!ssl_cipher_get_evp(s->session,&c,&md,NULL))
+       if (!ssl_cipher_get_evp(s->session,&c,&md,NULL,NULL,NULL))
                {
                ssl2_return_error(s,SSL2_PE_NO_CIPHER);
                SSLerr(SSL_F_SSL2_ENC_INIT,SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS);
                return(0);
                }
-
-       s->read_hash=md;
-       s->write_hash=md;
+       ssl_replace_hash(&s->read_hash,md);
+       ssl_replace_hash(&s->write_hash,md);
 
        if ((s->enc_read_ctx == NULL) &&
                ((s->enc_read_ctx=(EVP_CIPHER_CTX *)
@@ -176,7 +175,7 @@ void ssl2_mac(SSL *s, unsigned char *md, int send)
 
        /* There has to be a MAC algorithm. */
        EVP_MD_CTX_init(&c);
-       EVP_DigestInit_ex(&c, s->read_hash, NULL);
+       EVP_MD_CTX_copy(&c, s->read_hash);
        EVP_DigestUpdate(&c,sec,
                EVP_CIPHER_CTX_key_length(s->enc_read_ctx));
        EVP_DigestUpdate(&c,act,len); 
index 10751b2..9914604 100644 (file)
  * copied and put under another distribution licence
  * [including the GNU Public Licence.]
  */
+/* ====================================================================
+ * Copyright (c) 1998-2007 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    openssl-core@openssl.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
 
 #include "ssl_locl.h"
 #ifndef OPENSSL_NO_SSL2
@@ -68,143 +121,172 @@ const char ssl2_version_str[]="SSLv2" OPENSSL_VERSION_PTEXT;
 #define SSL2_NUM_CIPHERS (sizeof(ssl2_ciphers)/sizeof(SSL_CIPHER))
 
 /* list of available SSLv2 ciphers (sorted by id) */
-OPENSSL_GLOBAL SSL_CIPHER ssl2_ciphers[]={
-/* NULL_WITH_MD5 v3 */
+OPENSSL_GLOBAL const SSL_CIPHER ssl2_ciphers[]={
 #if 0
+/* NULL_WITH_MD5 v3 */
        {
        1,
        SSL2_TXT_NULL_WITH_MD5,
        SSL2_CK_NULL_WITH_MD5,
-       SSL_kRSA|SSL_aRSA|SSL_eNULL|SSL_MD5|SSL_SSLV2,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_eNULL,
+       SSL_MD5,
+       SSL_SSLV2,
        SSL_EXPORT|SSL_EXP40|SSL_STRONG_NONE,
        0,
        0,
        0,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 #endif
+
 /* RC4_128_WITH_MD5 */
        {
        1,
        SSL2_TXT_RC4_128_WITH_MD5,
        SSL2_CK_RC4_128_WITH_MD5,
-       SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_MD5|SSL_SSLV2,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_RC4,
+       SSL_MD5,
+       SSL_SSLV2,
        SSL_NOT_EXP|SSL_MEDIUM,
        0,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* RC4_128_EXPORT40_WITH_MD5 */
        {
        1,
        SSL2_TXT_RC4_128_EXPORT40_WITH_MD5,
        SSL2_CK_RC4_128_EXPORT40_WITH_MD5,
-       SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_MD5|SSL_SSLV2,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_RC4,
+       SSL_MD5,
+       SSL_SSLV2,
        SSL_EXPORT|SSL_EXP40,
        SSL2_CF_5_BYTE_ENC,
        40,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* RC2_128_CBC_WITH_MD5 */
        {
        1,
        SSL2_TXT_RC2_128_CBC_WITH_MD5,
        SSL2_CK_RC2_128_CBC_WITH_MD5,
-       SSL_kRSA|SSL_aRSA|SSL_RC2|SSL_MD5|SSL_SSLV2,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_RC2,
+       SSL_MD5,
+       SSL_SSLV2,
        SSL_NOT_EXP|SSL_MEDIUM,
        0,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* RC2_128_CBC_EXPORT40_WITH_MD5 */
        {
        1,
        SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5,
        SSL2_CK_RC2_128_CBC_EXPORT40_WITH_MD5,
-       SSL_kRSA|SSL_aRSA|SSL_RC2|SSL_MD5|SSL_SSLV2,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_RC2,
+       SSL_MD5,
+       SSL_SSLV2,
        SSL_EXPORT|SSL_EXP40,
        SSL2_CF_5_BYTE_ENC,
        40,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
-/* IDEA_128_CBC_WITH_MD5 */
+
 #ifndef OPENSSL_NO_IDEA
+/* IDEA_128_CBC_WITH_MD5 */
        {
        1,
        SSL2_TXT_IDEA_128_CBC_WITH_MD5,
        SSL2_CK_IDEA_128_CBC_WITH_MD5,
-       SSL_kRSA|SSL_aRSA|SSL_IDEA|SSL_MD5|SSL_SSLV2,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_IDEA,
+       SSL_MD5,
+       SSL_SSLV2,
        SSL_NOT_EXP|SSL_MEDIUM,
        0,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 #endif
+
 /* DES_64_CBC_WITH_MD5 */
        {
        1,
        SSL2_TXT_DES_64_CBC_WITH_MD5,
        SSL2_CK_DES_64_CBC_WITH_MD5,
-       SSL_kRSA|SSL_aRSA|SSL_DES|SSL_MD5|SSL_SSLV2,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_DES,
+       SSL_MD5,
+       SSL_SSLV2,
        SSL_NOT_EXP|SSL_LOW,
        0,
        56,
        56,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* DES_192_EDE3_CBC_WITH_MD5 */
        {
        1,
        SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5,
        SSL2_CK_DES_192_EDE3_CBC_WITH_MD5,
-       SSL_kRSA|SSL_aRSA|SSL_3DES|SSL_MD5|SSL_SSLV2,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_3DES,
+       SSL_MD5,
+       SSL_SSLV2,
        SSL_NOT_EXP|SSL_HIGH,
        0,
        168,
        168,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
-/* RC4_64_WITH_MD5 */
+
 #if 0
+/* RC4_64_WITH_MD5 */
        {
        1,
        SSL2_TXT_RC4_64_WITH_MD5,
        SSL2_CK_RC4_64_WITH_MD5,
-       SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_MD5|SSL_SSLV2,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_RC4,
+       SSL_MD5,
+       SSL_SSLV2,
        SSL_NOT_EXP|SSL_LOW,
        SSL2_CF_8_BYTE_ENC,
        64,
        64,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 #endif
-/* NULL SSLeay (testing) */
+
 #if 0
+/* NULL SSLeay (testing) */
        {       
        0,
        SSL2_TXT_NULL,
        SSL2_CK_NULL,
        0,
+       0,
+       0,
+       0,
+       SSL_SSLV2,
        SSL_STRONG_NONE,
        0,
        0,
        0,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 #endif
 
@@ -216,17 +298,12 @@ long ssl2_default_timeout(void)
        return(300);
        }
 
-IMPLEMENT_ssl2_meth_func(sslv2_base_method,
-                       ssl_undefined_function,
-                       ssl_undefined_function,
-                       ssl_bad_method)
-
 int ssl2_num_ciphers(void)
        {
        return(SSL2_NUM_CIPHERS);
        }
 
-SSL_CIPHER *ssl2_get_cipher(unsigned int u)
+const SSL_CIPHER *ssl2_get_cipher(unsigned int u)
        {
        if (u < SSL2_NUM_CIPHERS)
                return(&(ssl2_ciphers[SSL2_NUM_CIPHERS-1-u]));
@@ -337,18 +414,16 @@ long ssl2_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)(void))
 
 /* This function needs to check if the ciphers required are actually
  * available */
-SSL_CIPHER *ssl2_get_cipher_by_char(const unsigned char *p)
+const SSL_CIPHER *ssl2_get_cipher_by_char(const unsigned char *p)
        {
-       SSL_CIPHER c,*cp;
+       SSL_CIPHER c;
+       const SSL_CIPHER *cp;
        unsigned long id;
 
        id=0x02000000L|((unsigned long)p[0]<<16L)|
                ((unsigned long)p[1]<<8L)|(unsigned long)p[2];
        c.id=id;
-       cp = (SSL_CIPHER *)OBJ_bsearch((char *)&c,
-               (char *)ssl2_ciphers,
-               SSL2_NUM_CIPHERS,sizeof(SSL_CIPHER),
-               FP_ICC ssl_cipher_id_cmp);
+       cp = OBJ_bsearch_ssl_cipher_id(&c, ssl2_ciphers, SSL2_NUM_CIPHERS);
        if ((cp == NULL) || (cp->valid == 0))
                return NULL;
        else
@@ -377,6 +452,7 @@ int ssl2_generate_key_material(SSL *s)
        unsigned char *km;
        unsigned char c='0';
        const EVP_MD *md5;
+       int md_size;
 
        md5 = EVP_md5();
 
@@ -393,10 +469,12 @@ int ssl2_generate_key_material(SSL *s)
                SSLerr(SSL_F_SSL2_GENERATE_KEY_MATERIAL, ERR_R_INTERNAL_ERROR);
                return 0;
                }
-
-       for (i=0; i<s->s2->key_material_length; i += EVP_MD_size(md5))
+       md_size = EVP_MD_size(md5);
+       if (md_size < 0)
+           return 0;
+       for (i=0; i<s->s2->key_material_length; i += md_size)
                {
-               if (((km - s->s2->key_material) + EVP_MD_size(md5)) >
+               if (((km - s->s2->key_material) + md_size) >
                                (int)sizeof(s->s2->key_material))
                        {
                        /* EVP_DigestFinal_ex() below would write beyond buffer */
@@ -415,7 +493,7 @@ int ssl2_generate_key_material(SSL *s)
                EVP_DigestUpdate(&ctx,s->s2->challenge,s->s2->challenge_length);
                EVP_DigestUpdate(&ctx,s->s2->conn_id,s->s2->conn_id_length);
                EVP_DigestFinal_ex(&ctx,km,NULL);
-               km += EVP_MD_size(md5);
+               km += md_size;
                }
 
        EVP_MD_CTX_cleanup(&ctx);
index a35e435..f0e8ca5 100644 (file)
@@ -61,8 +61,8 @@
 #include <stdio.h>
 #include <openssl/objects.h>
 
-static SSL_METHOD *ssl2_get_method(int ver);
-static SSL_METHOD *ssl2_get_method(int ver)
+static const SSL_METHOD *ssl2_get_method(int ver);
+static const SSL_METHOD *ssl2_get_method(int ver)
        {
        if (ver == SSL2_VERSION)
                return(SSLv2_method());
@@ -71,9 +71,9 @@ static SSL_METHOD *ssl2_get_method(int ver)
        }
 
 IMPLEMENT_ssl2_meth_func(SSLv2_method,
-                       ssl2_accept,
-                       ssl2_connect,
-                       ssl2_get_method)
+                        ssl2_accept,
+                        ssl2_connect,
+                        ssl2_get_method)
 
 #else /* !OPENSSL_NO_SSL2 */
 
index a10929a..ac963b2 100644 (file)
 #define USE_SOCKETS
 
 static int read_n(SSL *s,unsigned int n,unsigned int max,unsigned int extend);
-static int do_ssl_write(SSL *s, const unsigned char *buf, unsigned int len);
+static int n_do_ssl_write(SSL *s, const unsigned char *buf, unsigned int len);
 static int write_pending(SSL *s, const unsigned char *buf, unsigned int len);
 static int ssl_mt_error(int n);
 
@@ -130,7 +130,7 @@ static int ssl2_read_internal(SSL *s, void *buf, int len, int peek)
        unsigned char mac[MAX_MAC_SIZE];
        unsigned char *p;
        int i;
-       unsigned int mac_size;
+       int mac_size;
 
  ssl2_read_again:
        if (SSL_in_init(s) && !s->in_handshake)
@@ -246,7 +246,9 @@ static int ssl2_read_internal(SSL *s, void *buf, int len, int peek)
                        }
                else
                        {
-                       mac_size=EVP_MD_size(s->read_hash);
+                       mac_size=EVP_MD_CTX_size(s->read_hash);
+                       if (mac_size < 0)
+                               return -1;
                        OPENSSL_assert(mac_size <= MAX_MAC_SIZE);
                        s->s2->mac_data=p;
                        s->s2->ract_data= &p[mac_size];
@@ -261,7 +263,7 @@ static int ssl2_read_internal(SSL *s, void *buf, int len, int peek)
                /* added a check for length > max_size in case
                 * encryption was not turned on yet due to an error */
                if ((!s->s2->clear_text) &&
-                       (s->s2->rlength >= mac_size))
+                       (s->s2->rlength >= (unsigned int)mac_size))
                        {
                        ssl2_enc(s,0);
                        s->s2->ract_data_length-=mac_size;
@@ -447,7 +449,7 @@ int ssl2_write(SSL *s, const void *_buf, int len)
        n=(len-tot);
        for (;;)
                {
-               i=do_ssl_write(s,&(buf[tot]),n);
+               i=n_do_ssl_write(s,&(buf[tot]),n);
                if (i <= 0)
                        {
                        s->s2->wnum=tot;
@@ -511,9 +513,10 @@ static int write_pending(SSL *s, const unsigned char *buf, unsigned int len)
                }
        }
 
-static int do_ssl_write(SSL *s, const unsigned char *buf, unsigned int len)
+static int n_do_ssl_write(SSL *s, const unsigned char *buf, unsigned int len)
        {
-       unsigned int j,k,olen,p,mac_size,bs;
+       unsigned int j,k,olen,p,bs;
+       int mac_size;
        register unsigned char *pp;
 
        olen=len;
@@ -529,7 +532,11 @@ static int do_ssl_write(SSL *s, const unsigned char *buf, unsigned int len)
        if (s->s2->clear_text)
                mac_size=0;
        else
-               mac_size=EVP_MD_size(s->write_hash);
+               {
+               mac_size=EVP_MD_CTX_size(s->write_hash);
+               if (mac_size < 0)
+                       return -1;
+               }
 
        /* lets set the pad p */
        if (s->s2->clear_text)
index c87d844..bc885e8 100644 (file)
 #include <openssl/objects.h>
 #include <openssl/evp.h>
 
-static SSL_METHOD *ssl2_get_server_method(int ver);
+static const SSL_METHOD *ssl2_get_server_method(int ver);
 static int get_client_master_key(SSL *s);
 static int get_client_hello(SSL *s);
 static int server_hello(SSL *s); 
@@ -129,7 +129,7 @@ static int ssl_rsa_private_decrypt(CERT *c, int len, unsigned char *from,
        unsigned char *to,int padding);
 #define BREAK  break
 
-static SSL_METHOD *ssl2_get_server_method(int ver)
+static const SSL_METHOD *ssl2_get_server_method(int ver)
        {
        if (ver == SSL2_VERSION)
                return(SSLv2_server_method());
@@ -366,7 +366,7 @@ static int get_client_master_key(SSL *s)
        int is_export,i,n,keya,ek;
        unsigned long len;
        unsigned char *p;
-       SSL_CIPHER *cp;
+       const SSL_CIPHER *cp;
        const EVP_CIPHER *c;
        const EVP_MD *md;
 
@@ -452,7 +452,7 @@ static int get_client_master_key(SSL *s)
 
        is_export=SSL_C_IS_EXPORT(s->session->cipher);
        
-       if (!ssl_cipher_get_evp(s->session,&c,&md,NULL))
+       if (!ssl_cipher_get_evp(s->session,&c,&md,NULL,NULL,NULL))
                {
                ssl2_return_error(s,SSL2_PE_NO_CIPHER);
                SSLerr(SSL_F_GET_CLIENT_MASTER_KEY,SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS);
index b88288e..508e390 100644 (file)
@@ -160,8 +160,6 @@ int ssl3_send_finished(SSL *s, int a, int b, const char *sender, int slen)
                p= &(d[4]);
 
                i=s->method->ssl3_enc->final_finish_mac(s,
-                       &(s->s3->finish_dgst1),
-                       &(s->s3->finish_dgst2),
                        sender,slen,s->s3->tmp.finish_md);
                s->s3->tmp.finish_md_len = i;
                memcpy(p, s->s3->tmp.finish_md, i);
@@ -204,8 +202,10 @@ int ssl3_send_finished(SSL *s, int a, int b, const char *sender, int slen)
        return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
        }
 
+#ifndef OPENSSL_NO_NEXTPROTONEG
 /* ssl3_take_mac calculates the Finished MAC for the handshakes messages seen to far. */
-void ssl3_take_mac(SSL *s) {
+static void ssl3_take_mac(SSL *s)
+       {
        const char *sender;
        int slen;
 
@@ -221,10 +221,9 @@ void ssl3_take_mac(SSL *s) {
                }
 
        s->s3->tmp.peer_finish_md_len = s->method->ssl3_enc->final_finish_mac(s,
-               &(s->s3->finish_dgst1),
-               &(s->s3->finish_dgst2),
                sender,slen,s->s3->tmp.peer_finish_md);
-}
+       }
+#endif
 
 int ssl3_get_finished(SSL *s, int a, int b)
        {
@@ -232,6 +231,12 @@ int ssl3_get_finished(SSL *s, int a, int b)
        long n;
        unsigned char *p;
 
+#ifdef OPENSSL_NO_NEXTPROTONEG
+       /* the mac has already been generated when we received the
+        * change cipher spec message and is in s->s3->tmp.peer_finish_md
+        */ 
+#endif
+
        n=s->method->ssl_get_message(s,
                a,
                b,
@@ -318,21 +323,21 @@ int ssl3_send_change_cipher_spec(SSL *s, int a, int b)
 
 static int ssl3_add_cert_to_buf(BUF_MEM *buf, unsigned long *l, X509 *x)
        {
-               int n;
-               unsigned char *p;
+       int n;
+       unsigned char *p;
 
-               n=i2d_X509(x,NULL);
-               if (!BUF_MEM_grow_clean(buf,(int)(n+(*l)+3)))
-                       {
-                               SSLerr(SSL_F_SSL3_ADD_CERT_TO_BUF,ERR_R_BUF_LIB);
-                               return(-1);
-                       }
-               p=(unsigned char *)&(buf->data[*l]);
-               l2n3(n,p);
-               i2d_X509(x,&p);
-               *l+=n+3;
+       n=i2d_X509(x,NULL);
+       if (!BUF_MEM_grow_clean(buf,(int)(n+(*l)+3)))
+               {
+               SSLerr(SSL_F_SSL3_ADD_CERT_TO_BUF,ERR_R_BUF_LIB);
+               return(-1);
+               }
+       p=(unsigned char *)&(buf->data[*l]);
+       l2n3(n,p);
+       i2d_X509(x,&p);
+       *l+=n+3;
 
-               return(0);
+       return(0);
        }
 
 unsigned long ssl3_output_cert_chain(SSL *s, X509 *x)
@@ -342,8 +347,11 @@ unsigned long ssl3_output_cert_chain(SSL *s, X509 *x)
        unsigned long l=7;
        BUF_MEM *buf;
        int no_chain;
+       STACK_OF(X509) *cert_chain;
+
+       cert_chain = SSL_get_certificate_chain(s, x);
 
-       if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || s->ctx->extra_certs)
+       if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || s->ctx->extra_certs || cert_chain)
                no_chain = 1;
        else
                no_chain = 0;
@@ -395,6 +403,10 @@ unsigned long ssl3_output_cert_chain(SSL *s, X509 *x)
                        return(0);
                }
 
+       for (i=0; i<sk_X509_num(cert_chain); i++)
+               if (ssl3_add_cert_to_buf(buf, &l, sk_X509_value(cert_chain,i)))
+                       return(0);
+
        l-=7;
        p=(unsigned char *)&(buf->data[4]);
        l2n3(l,p);
@@ -534,10 +546,14 @@ long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok)
                s->init_num += i;
                n -= i;
                }
+
+#ifndef OPENSSL_NO_NEXTPROTONEG
        /* If receiving Finished, record MAC of prior handshake messages for
         * Finished verification. */
        if (*s->init_buf->data == SSL3_MT_FINISHED)
                ssl3_take_mac(s);
+#endif
+
        /* Feed this message into MAC computation. */
        ssl3_finish_mac(s, (unsigned char *)s->init_buf->data, s->init_num + 4);
        if (s->msg_callback)
@@ -575,9 +591,16 @@ int ssl_cert_type(X509 *x, EVP_PKEY *pkey)
        else if (i == EVP_PKEY_EC)
                {
                ret = SSL_PKEY_ECC;
-               }
+               }       
 #endif
-
+       else if (i == NID_id_GostR3410_94 || i == NID_id_GostR3410_94_cc) 
+               {
+               ret = SSL_PKEY_GOST94;
+               }
+       else if (i == NID_id_GostR3410_2001 || i == NID_id_GostR3410_2001_cc) 
+               {
+               ret = SSL_PKEY_GOST01;
+               }
 err:
        if(!pkey) EVP_PKEY_free(pk);
        return(ret);
@@ -643,42 +666,202 @@ int ssl_verify_alarm_type(long type)
        return(al);
        }
 
-int ssl3_setup_buffers(SSL *s)
+#ifndef OPENSSL_NO_BUF_FREELISTS
+/* On some platforms, malloc() performance is bad enough that you can't just
+ * free() and malloc() buffers all the time, so we need to use freelists from
+ * unused buffers.  Currently, each freelist holds memory chunks of only a
+ * given size (list->chunklen); other sized chunks are freed and malloced.
+ * This doesn't help much if you're using many different SSL option settings
+ * with a given context.  (The options affecting buffer size are
+ * max_send_fragment, read buffer vs write buffer,
+ * SSL_OP_MICROSOFT_BIG_WRITE_BUFFER, SSL_OP_NO_COMPRESSION, and
+ * SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS.)  Using a separate freelist for every
+ * possible size is not an option, since max_send_fragment can take on many
+ * different values.
+ *
+ * If you are on a platform with a slow malloc(), and you're using SSL
+ * connections with many different settings for these options, and you need to
+ * use the SSL_MOD_RELEASE_BUFFERS feature, you have a few options:
+ *    - Link against a faster malloc implementation.
+ *    - Use a separate SSL_CTX for each option set.
+ *    - Improve this code.
+ */
+static void *
+freelist_extract(SSL_CTX *ctx, int for_read, int sz)
        {
-       unsigned char *p;
-       unsigned int extra,headerlen;
-       size_t len;
+       SSL3_BUF_FREELIST *list;
+       SSL3_BUF_FREELIST_ENTRY *ent = NULL;
+       void *result = NULL;
+
+       CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
+       list = for_read ? ctx->rbuf_freelist : ctx->wbuf_freelist;
+       if (list != NULL && sz == (int)list->chunklen)
+               ent = list->head;
+       if (ent != NULL)
+               {
+               list->head = ent->next;
+               result = ent;
+               if (--list->len == 0)
+                       list->chunklen = 0;
+               }
+       CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
+       if (!result)
+               result = OPENSSL_malloc(sz);
+       return result;
+}
 
+static void
+freelist_insert(SSL_CTX *ctx, int for_read, size_t sz, void *mem)
+       {
+       SSL3_BUF_FREELIST *list;
+       SSL3_BUF_FREELIST_ENTRY *ent;
+
+       CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
+       list = for_read ? ctx->rbuf_freelist : ctx->wbuf_freelist;
+       if (list != NULL &&
+           (sz == list->chunklen || list->chunklen == 0) &&
+           list->len < ctx->freelist_max_len &&
+           sz >= sizeof(*ent))
+               {
+               list->chunklen = sz;
+               ent = mem;
+               ent->next = list->head;
+               list->head = ent;
+               ++list->len;
+               mem = NULL;
+               }
+
+       CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
+       if (mem)
+               OPENSSL_free(mem);
+       }
+#else
+#define freelist_extract(c,fr,sz) OPENSSL_malloc(sz)
+#define freelist_insert(c,fr,sz,m) OPENSSL_free(m)
+#endif
+
+int ssl3_setup_read_buffer(SSL *s)
+       {
+       unsigned char *p;
+       size_t len,align=0,headerlen;
+       
        if (SSL_version(s) == DTLS1_VERSION || SSL_version(s) == DTLS1_BAD_VER)
                headerlen = DTLS1_RT_HEADER_LENGTH;
        else
                headerlen = SSL3_RT_HEADER_LENGTH;
 
+#if defined(SSL3_ALIGN_PAYLOAD) && SSL3_ALIGN_PAYLOAD!=0
+       align = (-SSL3_RT_HEADER_LENGTH)&(SSL3_ALIGN_PAYLOAD-1);
+#endif
+
        if (s->s3->rbuf.buf == NULL)
                {
-               if (s->options & SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER)
-                       extra=SSL3_RT_MAX_EXTRA;
-               else
-                       extra=0;
-               len = SSL3_RT_MAX_PACKET_SIZE + extra;
-               if ((p=OPENSSL_malloc(len)) == NULL)
+               if (SSL_get_mode(s) & SSL_MODE_SMALL_BUFFERS)
+                       {
+                       len = SSL3_RT_DEFAULT_PACKET_SIZE;
+                       }
+               else
+                       {
+                       len = SSL3_RT_MAX_PLAIN_LENGTH
+                               + SSL3_RT_MAX_ENCRYPTED_OVERHEAD
+                               + headerlen + align;
+                       if (s->options & SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER)
+                               {
+                               s->s3->init_extra = 1;
+                               len += SSL3_RT_MAX_EXTRA;
+                               }
+                       }
+#ifndef OPENSSL_NO_COMP
+               if (!(s->options & SSL_OP_NO_COMPRESSION))
+                       len += SSL3_RT_MAX_COMPRESSED_OVERHEAD;
+#endif
+               if ((p=freelist_extract(s->ctx, 1, len)) == NULL)
                        goto err;
                s->s3->rbuf.buf = p;
                s->s3->rbuf.len = len;
                }
 
+       s->packet= &(s->s3->rbuf.buf[0]);
+       return 1;
+
+err:
+       SSLerr(SSL_F_SSL3_SETUP_READ_BUFFER,ERR_R_MALLOC_FAILURE);
+       return 0;
+       }
+
+int ssl3_setup_write_buffer(SSL *s)
+       {
+       unsigned char *p;
+       size_t len,align=0,headerlen;
+
+       if (SSL_version(s) == DTLS1_VERSION || SSL_version(s) == DTLS1_BAD_VER)
+               headerlen = DTLS1_RT_HEADER_LENGTH + 1;
+       else
+               headerlen = SSL3_RT_HEADER_LENGTH;
+
+#if defined(SSL3_ALIGN_PAYLOAD) && SSL3_ALIGN_PAYLOAD!=0
+       align = (-SSL3_RT_HEADER_LENGTH)&(SSL3_ALIGN_PAYLOAD-1);
+#endif
+
        if (s->s3->wbuf.buf == NULL)
                {
-               len = SSL3_RT_MAX_PACKET_SIZE;
-               len += headerlen + 256; /* extra space for empty fragment */
-               if ((p=OPENSSL_malloc(len)) == NULL)
+               if (SSL_get_mode(s) & SSL_MODE_SMALL_BUFFERS)
+                       {
+                       len = SSL3_RT_DEFAULT_PACKET_SIZE;
+                       }
+               else
+                       {
+                       len = s->max_send_fragment;
+                       }
+               len += 0
+                       + SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD
+                       + headerlen + align;
+#ifndef OPENSSL_NO_COMP
+               if (!(s->options & SSL_OP_NO_COMPRESSION))
+                       len += SSL3_RT_MAX_COMPRESSED_OVERHEAD;
+#endif
+               if (!(s->options & SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS))
+                       len += headerlen + align
+                               + SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD;
+               if ((p=freelist_extract(s->ctx, 0, len)) == NULL)
                        goto err;
                s->s3->wbuf.buf = p;
                s->s3->wbuf.len = len;
                }
-       s->packet= &(s->s3->rbuf.buf[0]);
-       return(1);
+
+       return 1;
+
 err:
-       SSLerr(SSL_F_SSL3_SETUP_BUFFERS,ERR_R_MALLOC_FAILURE);
-       return(0);
+       SSLerr(SSL_F_SSL3_SETUP_WRITE_BUFFER,ERR_R_MALLOC_FAILURE);
+       return 0;
+       }
+
+
+int ssl3_setup_buffers(SSL *s)
+       {
+       if (!ssl3_setup_read_buffer(s))
+               return 0;
+       if (!ssl3_setup_write_buffer(s))
+               return 0;
+       return 1;
+       }
+
+int ssl3_release_write_buffer(SSL *s)
+       {
+       if (s->s3->wbuf.buf != NULL)
+               {
+               freelist_insert(s->ctx, 0, s->s3->wbuf.len, s->s3->wbuf.buf);
+               s->s3->wbuf.buf = NULL;
+               }
+       return 1;
+       }
+
+int ssl3_release_read_buffer(SSL *s)
+       {
+       if (s->s3->rbuf.buf != NULL)
+               {
+               freelist_insert(s->ctx, 1, s->s3->rbuf.len, s->s3->rbuf.buf);
+               s->s3->rbuf.buf = NULL;
+               }
+       return 1;
        }
index bf8ad48..04d6e5b 100644 (file)
@@ -56,7 +56,7 @@
  * [including the GNU Public Licence.]
  */
 /* ====================================================================
- * Copyright (c) 1998-2003 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2007 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * Vipul Gupta and Sumit Gupta of Sun Microsystems Laboratories.
  *
  */
+/* ====================================================================
+ * Copyright 2005 Nokia. All rights reserved.
+ *
+ * The portions of the attached software ("Contribution") is developed by
+ * Nokia Corporation and is licensed pursuant to the OpenSSL open source
+ * license.
+ *
+ * The Contribution, originally written by Mika Kousa and Pasi Eronen of
+ * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
+ * support (see RFC 4279) to OpenSSL.
+ *
+ * No patent licenses or other rights except those expressly stated in
+ * the OpenSSL open source license shall be deemed granted or received
+ * expressly, by implication, estoppel, or otherwise.
+ *
+ * No assurances are provided by Nokia that the Contribution does not
+ * infringe the patent or other intellectual property rights of any third
+ * party or that the license provides you with all the necessary rights
+ * to make use of the Contribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
+ * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
+ * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
+ * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
+ * OTHERWISE.
+ */
 
 #include <stdio.h>
 #include "ssl_locl.h"
 #include <openssl/objects.h>
 #include <openssl/evp.h>
 #include <openssl/md5.h>
-#ifdef OPENSSL_FIPS
-#include <openssl/fips.h>
-#endif
-
 #ifndef OPENSSL_NO_DH
 #include <openssl/dh.h>
 #endif
 #include <openssl/engine.h>
 #endif
 
-static SSL_METHOD *ssl3_get_client_method(int ver);
+static const SSL_METHOD *ssl3_get_client_method(int ver);
 static int ca_dn_cmp(const X509_NAME * const *a,const X509_NAME * const *b);
 
-#ifndef OPENSSL_NO_ECDH
-static int curve_id2nid(int curve_id);
-int check_srvr_ecc_cert_and_alg(X509 *x, SSL_CIPHER *cs);
-#endif
-
-static SSL_METHOD *ssl3_get_client_method(int ver)
+static const SSL_METHOD *ssl3_get_client_method(int ver)
        {
        if (ver == SSL3_VERSION)
                return(SSLv3_client_method());
@@ -182,11 +199,18 @@ int ssl3_connect(SSL *s)
        
        s->in_handshake++;
        if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s); 
+#if 0  /* Send app data in separate packet, otherwise, some particular site
+        * (only one site so far) closes the socket.
+        * Note: there is a very small chance that two TCP packets
+        * could be arriving at server combined into a single TCP packet,
+        * then trigger that site to break. We haven't encounter that though.
+        */
        if (SSL_get_mode(s) & SSL_MODE_HANDSHAKE_CUTTHROUGH)
                {
                /* Send app data along with CCS/Finished */
                s->s3->flags |= SSL3_FLAGS_DELAY_CLIENT_FINISHED;
                }
+#endif
 
        for (;;)
                {
@@ -266,6 +290,7 @@ int ssl3_connect(SSL *s)
                case SSL3_ST_CR_SRVR_HELLO_B:
                        ret=ssl3_get_server_hello(s);
                        if (ret <= 0) goto end;
+
                        if (s->hit)
                                s->state=SSL3_ST_CR_FINISHED_A;
                        else
@@ -290,7 +315,9 @@ int ssl3_connect(SSL *s)
                                }
 #endif
                        /* Check if it is anon DH/ECDH */
-                       if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL))
+                       /* or PSK */
+                       if (!(s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL) &&
+                           !(s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK))
                                {
                                ret=ssl3_get_server_certificate(s);
                                if (ret <= 0) goto end;
@@ -385,6 +412,11 @@ int ssl3_connect(SSL *s)
                                s->state=SSL3_ST_CW_CHANGE_A;
                                s->s3->change_cipher_spec=0;
                                }
+                       if (s->s3->flags & TLS1_FLAGS_SKIP_CERT_VERIFY)
+                               {
+                               s->state=SSL3_ST_CW_CHANGE_A;
+                               s->s3->change_cipher_spec=0;
+                               }
 
                        s->init_num=0;
                        break;
@@ -404,10 +436,15 @@ int ssl3_connect(SSL *s)
                                SSL3_ST_CW_CHANGE_A,SSL3_ST_CW_CHANGE_B);
                        if (ret <= 0) goto end;
 
+#if defined(OPENSSL_NO_TLSEXT) || defined(OPENSSL_NO_NEXTPROTONEG)
+                       s->state=SSL3_ST_CW_FINISHED_A;
+#else
                        if (s->next_proto_negotiated)
                                s->state=SSL3_ST_CW_NEXT_PROTO_A;
                        else
                                s->state=SSL3_ST_CW_FINISHED_A;
+#endif
+
                        s->init_num=0;
 
                        s->session->cipher=s->s3->tmp.new_cipher;
@@ -435,12 +472,14 @@ int ssl3_connect(SSL *s)
 
                        break;
 
+#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
                case SSL3_ST_CW_NEXT_PROTO_A:
                case SSL3_ST_CW_NEXT_PROTO_B:
                        ret=ssl3_send_next_proto(s);
                        if (ret <= 0) goto end;
                        s->state=SSL3_ST_CW_FINISHED_A;
                        break;
+#endif
 
                case SSL3_ST_CW_FINISHED_A:
                case SSL3_ST_CW_FINISHED_B:
@@ -647,6 +686,12 @@ int ssl3_client_hello(SSL *s)
 #endif
                        (sess->not_resumable))
                        {
+                       if (!s->session_creation_enabled)
+                               {
+                               ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
+                               SSLerr(SSL_F_SSL3_CLIENT_HELLO,SSL_R_SESSION_MAY_NOT_BE_CREATED);
+                               goto err;
+                               }
                        if (!ssl_get_new_session(s,0))
                                goto err;
                        }
@@ -700,7 +745,9 @@ int ssl3_client_hello(SSL *s)
 #ifdef OPENSSL_NO_COMP
                *(p++)=1;
 #else
-               if (s->ctx->comp_methods == NULL)
+
+               if ((s->options & SSL_OP_NO_COMPRESSION)
+                                       || !s->ctx->comp_methods)
                        j=0;
                else
                        j=sk_SSL_COMP_num(s->ctx->comp_methods);
@@ -712,13 +759,21 @@ int ssl3_client_hello(SSL *s)
                        }
 #endif
                *(p++)=0; /* Add the NULL method */
+
 #ifndef OPENSSL_NO_TLSEXT
+               /* TLS extensions*/
+               if (ssl_prepare_clienthello_tlsext(s) <= 0)
+                       {
+                       SSLerr(SSL_F_SSL3_CLIENT_HELLO,SSL_R_CLIENTHELLO_TLSEXT);
+                       goto err;
+                       }
                if ((p = ssl_add_clienthello_tlsext(s, p, buf+SSL3_RT_MAX_PLAIN_LENGTH)) == NULL)
                        {
                        SSLerr(SSL_F_SSL3_CLIENT_HELLO,ERR_R_INTERNAL_ERROR);
                        goto err;
                        }
-#endif         
+#endif
+               
                l=(p-d);
                d=buf;
                *(d++)=SSL3_MT_CLIENT_HELLO;
@@ -739,7 +794,7 @@ err:
 int ssl3_get_server_hello(SSL *s)
        {
        STACK_OF(SSL_CIPHER) *sk;
-       SSL_CIPHER *c;
+       const SSL_CIPHER *c;
        unsigned char *p,*d;
        int i,al,ok;
        unsigned int j;
@@ -808,6 +863,23 @@ int ssl3_get_server_hello(SSL *s)
                goto f_err;
                }
 
+#ifndef OPENSSL_NO_TLSEXT
+       /* check if we want to resume the session based on external pre-shared secret */
+       if (s->version >= TLS1_VERSION && s->tls_session_secret_cb)
+               {
+               SSL_CIPHER *pref_cipher=NULL;
+               s->session->master_key_length=sizeof(s->session->master_key);
+               if (s->tls_session_secret_cb(s, s->session->master_key,
+                                            &s->session->master_key_length,
+                                            NULL, &pref_cipher,
+                                            s->tls_session_secret_cb_arg))
+                       {
+                       s->session->cipher = pref_cipher ?
+                               pref_cipher : ssl_get_cipher_by_char(s, p+j);
+                       }
+               }
+#endif /* OPENSSL_NO_TLSEXT */
+
        if (j != 0 && j == s->session->session_id_length
            && memcmp(p,s->session->session_id,j) == 0)
            {
@@ -828,6 +900,12 @@ int ssl3_get_server_hello(SSL *s)
                s->hit=0;
                if (s->session->session_id_length > 0)
                        {
+                       if (!s->session_creation_enabled)
+                               {
+                               ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
+                               SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_SESSION_MAY_NOT_BE_CREATED);
+                               goto err;
+                               }
                        if (!ssl_get_new_session(s,0))
                                {
                                al=SSL_AD_INTERNAL_ERROR;
@@ -877,6 +955,8 @@ int ssl3_get_server_hello(SSL *s)
                        }
                }
        s->s3->tmp.new_cipher=c;
+       if (!ssl3_digest_cached_records(s))
+               goto f_err;
 
        /* lets get the compression algorithm */
        /* COMPRESSION */
@@ -887,10 +967,31 @@ int ssl3_get_server_hello(SSL *s)
                SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM);
                goto f_err;
                }
+       /* If compression is disabled we'd better not try to resume a session
+        * using compression.
+        */
+       if (s->session->compress_meth != 0)
+               {
+               al=SSL_AD_INTERNAL_ERROR;
+               SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_INCONSISTENT_COMPRESSION);
+               goto f_err;
+               }
 #else
        j= *(p++);
+       if (s->hit && j != s->session->compress_meth)
+               {
+               al=SSL_AD_ILLEGAL_PARAMETER;
+               SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_OLD_SESSION_COMPRESSION_ALGORITHM_NOT_RETURNED);
+               goto f_err;
+               }
        if (j == 0)
                comp=NULL;
+       else if (s->options & SSL_OP_NO_COMPRESSION)
+               {
+               al=SSL_AD_ILLEGAL_PARAMETER;
+               SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_COMPRESSION_DISABLED);
+               goto f_err;
+               }
        else
                comp=ssl3_comp_find(s->ctx->comp_methods,j);
        
@@ -905,6 +1006,7 @@ int ssl3_get_server_hello(SSL *s)
                s->s3->tmp.new_compression=comp;
                }
 #endif
+
 #ifndef OPENSSL_NO_TLSEXT
        /* TLS extensions*/
        if (s->version >= SSL3_VERSION)
@@ -923,13 +1025,12 @@ int ssl3_get_server_hello(SSL *s)
                }
 #endif
 
-
        if (p != (d+n))
                {
                /* wrong packet length */
                al=SSL_AD_DECODE_ERROR;
                SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_BAD_PACKET_LENGTH);
-               goto err;
+               goto f_err;
                }
 
        return(1);
@@ -961,7 +1062,7 @@ int ssl3_get_server_certificate(SSL *s)
        if (!ok) return((int)n);
 
        if ((s->s3->tmp.message_type == SSL3_MT_SERVER_KEY_EXCHANGE) ||
-               ((s->s3->tmp.new_cipher->algorithms & SSL_aKRB5) && 
+               ((s->s3->tmp.new_cipher->algorithm_auth & SSL_aKRB5) && 
                (s->s3->tmp.message_type == SSL3_MT_SERVER_DONE)))
                {
                s->s3->tmp.reuse_message=1;
@@ -1026,10 +1127,10 @@ int ssl3_get_server_certificate(SSL *s)
        i=ssl_verify_cert_chain(s,sk);
        if ((s->verify_mode != SSL_VERIFY_NONE) && (i <= 0)
 #ifndef OPENSSL_NO_KRB5
-               && (s->s3->tmp.new_cipher->algorithms & (SSL_MKEY_MASK|SSL_AUTH_MASK))
-               != (SSL_aKRB5|SSL_kKRB5)
+           && !((s->s3->tmp.new_cipher->algorithm_mkey & SSL_kKRB5) &&
+                (s->s3->tmp.new_cipher->algorithm_auth & SSL_aKRB5))
 #endif /* OPENSSL_NO_KRB5 */
-               )
+               )
                {
                al=ssl_verify_alarm_type(s->verify_result);
                SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERTIFICATE_VERIFY_FAILED);
@@ -1053,15 +1154,15 @@ int ssl3_get_server_certificate(SSL *s)
        pkey=X509_get_pubkey(x);
 
        /* VRS: allow null cert if auth == KRB5 */
-       need_cert =     ((s->s3->tmp.new_cipher->algorithms
-                        & (SSL_MKEY_MASK|SSL_AUTH_MASK))
-                        == (SSL_aKRB5|SSL_kKRB5))? 0: 1;
+       need_cert = ((s->s3->tmp.new_cipher->algorithm_mkey & SSL_kKRB5) &&
+                   (s->s3->tmp.new_cipher->algorithm_auth & SSL_aKRB5))
+                   ? 0 : 1;
 
 #ifdef KSSL_DEBUG
-       printf("pkey,x = %p, %p\n", (void *)pkey,(void *)x);
+       printf("pkey,x = %p, %p\n", pkey,x);
        printf("ssl_cert_type(x,pkey) = %d\n", ssl_cert_type(x,pkey));
-       printf("cipher, alg, nc = %s, %lx, %d\n", s->s3->tmp.new_cipher->name,
-               s->s3->tmp.new_cipher->algorithms, need_cert);
+       printf("cipher, alg, nc = %s, %lx, %lx, %d\n", s->s3->tmp.new_cipher->name,
+               s->s3->tmp.new_cipher->algorithm_mkey, s->s3->tmp.new_cipher->algorithm_auth, need_cert);
 #endif    /* KSSL_DEBUG */
 
        if (need_cert && ((pkey == NULL) || EVP_PKEY_missing_parameters(pkey)))
@@ -1133,7 +1234,7 @@ int ssl3_get_key_exchange(SSL *s)
        EVP_MD_CTX md_ctx;
        unsigned char *param,*p;
        int al,i,j,param_len,ok;
-       long n,alg;
+       long n,alg_k,alg_a;
        EVP_PKEY *pkey=NULL;
 #ifndef OPENSSL_NO_RSA
        RSA *rsa=NULL;
@@ -1157,17 +1258,28 @@ int ssl3_get_key_exchange(SSL *s)
                -1,
                s->max_cert_list,
                &ok);
-
        if (!ok) return((int)n);
 
        if (s->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE)
                {
+#ifndef OPENSSL_NO_PSK
+               /* In plain PSK ciphersuite, ServerKeyExchange can be
+                  omitted if no identity hint is sent. Set
+                  session->sess_cert anyway to avoid problems
+                  later.*/
+               if (s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK)
+                       {
+                       s->session->sess_cert=ssl_sess_cert_new();
+                       if (s->ctx->psk_identity_hint)
+                               OPENSSL_free(s->ctx->psk_identity_hint);
+                       s->ctx->psk_identity_hint = NULL;
+                       }
+#endif
                s->s3->tmp.reuse_message=1;
                return(1);
                }
 
        param=p=(unsigned char *)s->init_msg;
-
        if (s->session->sess_cert != NULL)
                {
 #ifndef OPENSSL_NO_RSA
@@ -1198,11 +1310,57 @@ int ssl3_get_key_exchange(SSL *s)
                }
 
        param_len=0;
-       alg=s->s3->tmp.new_cipher->algorithms;
+       alg_k=s->s3->tmp.new_cipher->algorithm_mkey;
+       alg_a=s->s3->tmp.new_cipher->algorithm_auth;
        EVP_MD_CTX_init(&md_ctx);
 
+#ifndef OPENSSL_NO_PSK
+       if (alg_k & SSL_kPSK)
+               {
+               char tmp_id_hint[PSK_MAX_IDENTITY_LEN+1];
+
+               al=SSL_AD_HANDSHAKE_FAILURE;
+               n2s(p,i);
+               param_len=i+2;
+               /* Store PSK identity hint for later use, hint is used
+                * in ssl3_send_client_key_exchange.  Assume that the
+                * maximum length of a PSK identity hint can be as
+                * long as the maximum length of a PSK identity. */
+               if (i > PSK_MAX_IDENTITY_LEN)
+                       {
+                       SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,
+                               SSL_R_DATA_LENGTH_TOO_LONG);
+                       goto f_err;
+                       }
+               if (param_len > n)
+                       {
+                       al=SSL_AD_DECODE_ERROR;
+                       SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,
+                               SSL_R_BAD_PSK_IDENTITY_HINT_LENGTH);
+                       goto f_err;
+                       }
+               /* If received PSK identity hint contains NULL
+                * characters, the hint is truncated from the first
+                * NULL. p may not be ending with NULL, so create a
+                * NULL-terminated string. */
+               memcpy(tmp_id_hint, p, i);
+               memset(tmp_id_hint+i, 0, PSK_MAX_IDENTITY_LEN+1-i);
+               if (s->ctx->psk_identity_hint != NULL)
+                       OPENSSL_free(s->ctx->psk_identity_hint);
+               s->ctx->psk_identity_hint = BUF_strdup(tmp_id_hint);
+               if (s->ctx->psk_identity_hint == NULL)
+                       {
+                       SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE);
+                       goto f_err;
+                       }          
+
+               p+=i;
+               n-=param_len;
+               }
+       else
+#endif /* !OPENSSL_NO_PSK */
 #ifndef OPENSSL_NO_RSA
-       if (alg & SSL_kRSA)
+       if (alg_k & SSL_kRSA)
                {
                if ((rsa=RSA_new()) == NULL)
                        {
@@ -1241,7 +1399,7 @@ int ssl3_get_key_exchange(SSL *s)
                n-=param_len;
 
                /* this should be because we are using an export cipher */
-               if (alg & SSL_aRSA)
+               if (alg_a & SSL_aRSA)
                        pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509);
                else
                        {
@@ -1256,7 +1414,7 @@ int ssl3_get_key_exchange(SSL *s)
                ;
 #endif
 #ifndef OPENSSL_NO_DH
-       else if (alg & SSL_kEDH)
+       else if (alg_k & SSL_kEDH)
                {
                if ((dh=DH_new()) == NULL)
                        {
@@ -1310,14 +1468,14 @@ int ssl3_get_key_exchange(SSL *s)
                n-=param_len;
 
 #ifndef OPENSSL_NO_RSA
-               if (alg & SSL_aRSA)
+               if (alg_a & SSL_aRSA)
                        pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509);
 #else
                if (0)
                        ;
 #endif
 #ifndef OPENSSL_NO_DSA
-               else if (alg & SSL_aDSS)
+               else if (alg_a & SSL_aDSS)
                        pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_DSA_SIGN].x509);
 #endif
                /* else anonymous DH, so no certificate or pkey. */
@@ -1325,7 +1483,7 @@ int ssl3_get_key_exchange(SSL *s)
                s->session->sess_cert->peer_dh_tmp=dh;
                dh=NULL;
                }
-       else if ((alg & SSL_kDHr) || (alg & SSL_kDHd))
+       else if ((alg_k & SSL_kDHr) || (alg_k & SSL_kDHd))
                {
                al=SSL_AD_ILLEGAL_PARAMETER;
                SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER);
@@ -1334,7 +1492,7 @@ int ssl3_get_key_exchange(SSL *s)
 #endif /* !OPENSSL_NO_DH */
 
 #ifndef OPENSSL_NO_ECDH
-       else if (alg & SSL_kECDHE)
+       else if (alg_k & SSL_kEECDH)
                {
                EC_GROUP *ngroup;
                const EC_GROUP *group;
@@ -1357,7 +1515,7 @@ int ssl3_get_key_exchange(SSL *s)
                param_len=3;
                if ((param_len > n) ||
                    (*p != NAMED_CURVE_TYPE) || 
-                   ((curve_nid = curve_id2nid(*(p + 2))) == 0)) 
+                   ((curve_nid = tls1_ec_curve_id2nid(*(p + 2))) == 0)) 
                        {
                        al=SSL_AD_INTERNAL_ERROR;
                        SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_UNABLE_TO_FIND_ECDH_PARAMETERS);
@@ -1418,11 +1576,11 @@ int ssl3_get_key_exchange(SSL *s)
                 */
                if (0) ;
 #ifndef OPENSSL_NO_RSA
-               else if (alg & SSL_aRSA)
+               else if (alg_a & SSL_aRSA)
                        pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509);
 #endif
 #ifndef OPENSSL_NO_ECDSA
-               else if (alg & SSL_aECDSA)
+               else if (alg_a & SSL_aECDSA)
                        pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_ECC].x509);
 #endif
                /* else anonymous ECDH, so no certificate or pkey. */
@@ -1434,19 +1592,13 @@ int ssl3_get_key_exchange(SSL *s)
                EC_POINT_free(srvr_ecpoint);
                srvr_ecpoint = NULL;
                }
-       else if (alg & SSL_kECDH)
+       else if (alg_k)
                {
                al=SSL_AD_UNEXPECTED_MESSAGE;
                SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_UNEXPECTED_MESSAGE);
                goto f_err;
                }
 #endif /* !OPENSSL_NO_ECDH */
-       if (alg & SSL_aFZA)
-               {
-               al=SSL_AD_HANDSHAKE_FAILURE;
-               SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER);
-               goto f_err;
-               }
 
 
        /* p points to the next byte, there are 'n' bytes left */
@@ -1475,8 +1627,6 @@ int ssl3_get_key_exchange(SSL *s)
                        q=md_buf;
                        for (num=2; num > 0; num--)
                                {
-                               EVP_MD_CTX_set_flags(&md_ctx,
-                                       EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
                                EVP_DigestInit_ex(&md_ctx,(num == 2)
                                        ?s->ctx->md5:s->ctx->sha1, NULL);
                                EVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
@@ -1547,12 +1697,13 @@ int ssl3_get_key_exchange(SSL *s)
                }
        else
                {
-               /* still data left over */
-               if (!(alg & SSL_aNULL))
+               if (!(alg_a & SSL_aNULL) && !(alg_k & SSL_kPSK))
+                       /* aNULL or kPSK do not need public keys */
                        {
                        SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_INTERNAL_ERROR);
                        goto err;
                        }
+               /* still data left over */
                if (n != 0)
                        {
                        al=SSL_AD_DECODE_ERROR;
@@ -1622,8 +1773,7 @@ int ssl3_get_certificate_request(SSL *s)
        /* TLS does not like anon-DH with client cert */
        if (s->version > SSL3_VERSION)
                {
-               l=s->s3->tmp.new_cipher->algorithms;
-               if (l & SSL_aNULL)
+               if (s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL)
                        {
                        ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE);
                        SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER);
@@ -1764,7 +1914,7 @@ int ssl3_get_new_session_ticket(SSL *s)
        if (n < 6)
                {
                /* need at least ticket_lifetime_hint + ticket length */
-               al = SSL3_AL_FATAL,SSL_AD_DECODE_ERROR;
+               al = SSL_AD_DECODE_ERROR;
                SSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET,SSL_R_LENGTH_MISMATCH);
                goto f_err;
                }
@@ -1775,7 +1925,7 @@ int ssl3_get_new_session_ticket(SSL *s)
        /* ticket_lifetime_hint + ticket_length + ticket */
        if (ticklen + 6 != n)
                {
-               al = SSL3_AL_FATAL,SSL_AD_DECODE_ERROR;
+               al = SSL_AD_DECODE_ERROR;
                SSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET,SSL_R_LENGTH_MISMATCH);
                goto f_err;
                }
@@ -1825,8 +1975,7 @@ err:
 int ssl3_get_cert_status(SSL *s)
        {
        int ok, al;
-       unsigned long resplen;
-       long n;
+       unsigned long resplen,n;
        const unsigned char *p;
 
        n=s->method->ssl_get_message(s,
@@ -1852,7 +2001,7 @@ int ssl3_get_cert_status(SSL *s)
                goto f_err;
                }
        n2l3(p, resplen);
-       if (resplen + 4 != (unsigned long)n)
+       if (resplen + 4 != n)
                {
                al = SSL_AD_DECODE_ERROR;
                SSLerr(SSL_F_SSL3_GET_CERT_STATUS,SSL_R_LENGTH_MISMATCH);
@@ -1921,7 +2070,7 @@ int ssl3_send_client_key_exchange(SSL *s)
        {
        unsigned char *p,*d;
        int n;
-       unsigned long l;
+       unsigned long alg_k;
 #ifndef OPENSSL_NO_RSA
        unsigned char *q;
        EVP_PKEY *pkey=NULL;
@@ -1943,12 +2092,12 @@ int ssl3_send_client_key_exchange(SSL *s)
                d=(unsigned char *)s->init_buf->data;
                p= &(d[4]);
 
-               l=s->s3->tmp.new_cipher->algorithms;
+               alg_k=s->s3->tmp.new_cipher->algorithm_mkey;
 
                /* Fool emacs indentation */
                if (0) {}
 #ifndef OPENSSL_NO_RSA
-               else if (l & SSL_kRSA)
+               else if (alg_k & SSL_kRSA)
                        {
                        RSA *rsa;
                        unsigned char tmp_buf[SSL_MAX_MASTER_KEY_LENGTH];
@@ -2007,7 +2156,7 @@ int ssl3_send_client_key_exchange(SSL *s)
                        }
 #endif
 #ifndef OPENSSL_NO_KRB5
-               else if (l & SSL_kKRB5)
+               else if (alg_k & SSL_kKRB5)
                        {
                        krb5_error_code krb5rc;
                        KSSL_CTX        *kssl_ctx = s->kssl_ctx;
@@ -2015,7 +2164,7 @@ int ssl3_send_client_key_exchange(SSL *s)
                        krb5_data       *enc_ticket;
                        krb5_data       authenticator, *authp = NULL;
                        EVP_CIPHER_CTX  ciph_ctx;
-                       EVP_CIPHER      *enc = NULL;
+                       const EVP_CIPHER *enc = NULL;
                        unsigned char   iv[EVP_MAX_IV_LENGTH];
                        unsigned char   tmp_buf[SSL_MAX_MASTER_KEY_LENGTH];
                        unsigned char   epms[SSL_MAX_MASTER_KEY_LENGTH 
@@ -2026,7 +2175,7 @@ int ssl3_send_client_key_exchange(SSL *s)
 
 #ifdef KSSL_DEBUG
                        printf("ssl3_send_client_key_exchange(%lx & %lx)\n",
-                               l, SSL_kKRB5);
+                               alg_k, SSL_kKRB5);
 #endif /* KSSL_DEBUG */
 
                        authp = NULL;
@@ -2118,7 +2267,7 @@ int ssl3_send_client_key_exchange(SSL *s)
                                sizeof tmp_buf);
                        EVP_EncryptFinal_ex(&ciph_ctx,&(epms[outl]),&padl);
                        outl += padl;
-                       if (outl > sizeof epms)
+                       if (outl > (int)sizeof epms)
                                {
                                SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);
                                goto err;
@@ -2132,7 +2281,7 @@ int ssl3_send_client_key_exchange(SSL *s)
                        n+=outl + 2;
 
                        s->session->master_key_length=
-                               s->method->ssl3_enc->generate_master_secret(s,
+                               s->method->ssl3_enc->generate_master_secret(s,
                                        s->session->master_key,
                                        tmp_buf, sizeof tmp_buf);
 
@@ -2141,7 +2290,7 @@ int ssl3_send_client_key_exchange(SSL *s)
                        }
 #endif
 #ifndef OPENSSL_NO_DH
-               else if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
+               else if (alg_k & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
                        {
                        DH *dh_srvr,*dh_clnt;
 
@@ -2150,7 +2299,7 @@ int ssl3_send_client_key_exchange(SSL *s)
                                ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE);
                                SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_UNEXPECTED_MESSAGE);
                                goto err;
-                               }
+                               }
 
                        if (s->session->sess_cert->peer_dh_tmp != NULL)
                                dh_srvr=s->session->sess_cert->peer_dh_tmp;
@@ -2171,6 +2320,7 @@ int ssl3_send_client_key_exchange(SSL *s)
                        if (!DH_generate_key(dh_clnt))
                                {
                                SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
+                               DH_free(dh_clnt);
                                goto err;
                                }
 
@@ -2182,6 +2332,7 @@ int ssl3_send_client_key_exchange(SSL *s)
                        if (n <= 0)
                                {
                                SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
+                               DH_free(dh_clnt);
                                goto err;
                                }
 
@@ -2205,7 +2356,7 @@ int ssl3_send_client_key_exchange(SSL *s)
 #endif
 
 #ifndef OPENSSL_NO_ECDH 
-               else if ((l & SSL_kECDH) || (l & SSL_kECDHE))
+               else if (alg_k & (SSL_kEECDH|SSL_kECDHr|SSL_kECDHe))
                        {
                        const EC_GROUP *srvr_group = NULL;
                        EC_KEY *tkey;
@@ -2217,7 +2368,7 @@ int ssl3_send_client_key_exchange(SSL *s)
                         * computation as part of client certificate?
                         * If so, set ecdh_clnt_cert to 1.
                         */
-                       if ((l & SSL_kECDH) && (s->cert != NULL)) 
+                       if ((alg_k & (SSL_kECDHr|SSL_kECDHe)) && (s->cert != NULL)) 
                                {
                                /* XXX: For now, we do not support client
                                 * authentication using ECDH certificates.
@@ -2389,6 +2540,178 @@ int ssl3_send_client_key_exchange(SSL *s)
                        EVP_PKEY_free(srvr_pub_pkey);
                        }
 #endif /* !OPENSSL_NO_ECDH */
+               else if (alg_k & SSL_kGOST) 
+                       {
+                       /* GOST key exchange message creation */
+                       EVP_PKEY_CTX *pkey_ctx;
+                       X509 *peer_cert; 
+                       size_t msglen;
+                       unsigned int md_len;
+                       int keytype;
+                       unsigned char premaster_secret[32],shared_ukm[32], tmp[256];
+                       EVP_MD_CTX *ukm_hash;
+                       EVP_PKEY *pub_key;
+
+                       /* Get server sertificate PKEY and create ctx from it */
+                       peer_cert=s->session->sess_cert->peer_pkeys[(keytype=SSL_PKEY_GOST01)].x509;
+                       if (!peer_cert) 
+                               peer_cert=s->session->sess_cert->peer_pkeys[(keytype=SSL_PKEY_GOST94)].x509;
+                       if (!peer_cert)         {
+                                       SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_NO_GOST_CERTIFICATE_SENT_BY_PEER);
+                                       goto err;
+                               }       
+                               
+                       pkey_ctx=EVP_PKEY_CTX_new(pub_key=X509_get_pubkey(peer_cert),NULL);
+                       /* If we have send a certificate, and certificate key
+
+                        * parameters match those of server certificate, use
+                        * certificate key for key exchange
+                        */
+
+                        /* Otherwise, generate ephemeral key pair */
+                                       
+                       EVP_PKEY_encrypt_init(pkey_ctx);
+                         /* Generate session key */    
+                   RAND_bytes(premaster_secret,32);
+                       /* If we have client certificate, use its secret as peer key */
+                       if (s->s3->tmp.cert_req && s->cert->key->privatekey) {
+                               if (EVP_PKEY_derive_set_peer(pkey_ctx,s->cert->key->privatekey) <=0) {
+                                       /* If there was an error - just ignore it. Ephemeral key
+                                       * would be used
+                                       */
+                                       ERR_clear_error();
+                               }
+                       }                       
+                       /* Compute shared IV and store it in algorithm-specific
+                        * context data */
+                       ukm_hash = EVP_MD_CTX_create();
+                       EVP_DigestInit(ukm_hash,EVP_get_digestbynid(NID_id_GostR3411_94));
+                       EVP_DigestUpdate(ukm_hash,s->s3->client_random,SSL3_RANDOM_SIZE);
+                       EVP_DigestUpdate(ukm_hash,s->s3->server_random,SSL3_RANDOM_SIZE);
+                       EVP_DigestFinal_ex(ukm_hash, shared_ukm, &md_len);
+                       EVP_MD_CTX_destroy(ukm_hash);
+                       if (EVP_PKEY_CTX_ctrl(pkey_ctx,-1,EVP_PKEY_OP_ENCRYPT,EVP_PKEY_CTRL_SET_IV,
+                               8,shared_ukm)<0) {
+                                       SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
+                                               SSL_R_LIBRARY_BUG);
+                                       goto err;
+                               }       
+                       /* Make GOST keytransport blob message */
+                       /*Encapsulate it into sequence */
+                       *(p++)=V_ASN1_SEQUENCE | V_ASN1_CONSTRUCTED;
+                       msglen=255;
+                       if (EVP_PKEY_encrypt(pkey_ctx,tmp,&msglen,premaster_secret,32)<0) {
+                       SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
+                                       SSL_R_LIBRARY_BUG);
+                               goto err;
+                       }
+                       if (msglen >= 0x80)
+                               {
+                               *(p++)=0x81;
+                               *(p++)= msglen & 0xff;
+                               n=msglen+3;
+                               }
+                       else
+                               {
+                               *(p++)= msglen & 0xff;
+                               n=msglen+2;
+                               }
+                       memcpy(p, tmp, msglen);
+                       /* Check if pubkey from client certificate was used */
+                       if (EVP_PKEY_CTX_ctrl(pkey_ctx, -1, -1, EVP_PKEY_CTRL_PEER_KEY, 2, NULL) > 0)
+                               {
+                               /* Set flag "skip certificate verify" */
+                               s->s3->flags |= TLS1_FLAGS_SKIP_CERT_VERIFY;
+                               }
+                       EVP_PKEY_CTX_free(pkey_ctx);
+                       s->session->master_key_length=
+                               s->method->ssl3_enc->generate_master_secret(s,
+                                       s->session->master_key,premaster_secret,32);
+                       EVP_PKEY_free(pub_key);
+
+                       }
+#ifndef OPENSSL_NO_PSK
+               else if (alg_k & SSL_kPSK)
+                       {
+                       char identity[PSK_MAX_IDENTITY_LEN];
+                       unsigned char *t = NULL;
+                       unsigned char psk_or_pre_ms[PSK_MAX_PSK_LEN*2+4];
+                       unsigned int pre_ms_len = 0, psk_len = 0;
+                       int psk_err = 1;
+
+                       n = 0;
+                       if (s->psk_client_callback == NULL)
+                               {
+                               SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
+                                       SSL_R_PSK_NO_CLIENT_CB);
+                               goto err;
+                               }
+
+                       psk_len = s->psk_client_callback(s, s->ctx->psk_identity_hint,
+                               identity, PSK_MAX_IDENTITY_LEN,
+                               psk_or_pre_ms, sizeof(psk_or_pre_ms));
+                       if (psk_len > PSK_MAX_PSK_LEN)
+                               {
+                               SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
+                                       ERR_R_INTERNAL_ERROR);
+                               goto psk_err;
+                               }
+                       else if (psk_len == 0)
+                               {
+                               SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
+                                       SSL_R_PSK_IDENTITY_NOT_FOUND);
+                               goto psk_err;
+                               }
+
+                       /* create PSK pre_master_secret */
+                       pre_ms_len = 2+psk_len+2+psk_len;
+                       t = psk_or_pre_ms;
+                       memmove(psk_or_pre_ms+psk_len+4, psk_or_pre_ms, psk_len);
+                       s2n(psk_len, t);
+                       memset(t, 0, psk_len);
+                       t+=psk_len;
+                       s2n(psk_len, t);
+
+                       if (s->session->psk_identity_hint != NULL)
+                               OPENSSL_free(s->session->psk_identity_hint);
+                       s->session->psk_identity_hint = BUF_strdup(s->ctx->psk_identity_hint);
+                       if (s->ctx->psk_identity_hint != NULL &&
+                               s->session->psk_identity_hint == NULL)
+                               {
+                               SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
+                                       ERR_R_MALLOC_FAILURE);
+                               goto psk_err;
+                               }
+
+                       if (s->session->psk_identity != NULL)
+                               OPENSSL_free(s->session->psk_identity);
+                       s->session->psk_identity = BUF_strdup(identity);
+                       if (s->session->psk_identity == NULL)
+                               {
+                               SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
+                                       ERR_R_MALLOC_FAILURE);
+                               goto psk_err;
+                               }
+
+                       s->session->master_key_length =
+                               s->method->ssl3_enc->generate_master_secret(s,
+                                       s->session->master_key,
+                                       psk_or_pre_ms, pre_ms_len); 
+                       n = strlen(identity);
+                       s2n(n, p);
+                       memcpy(p, identity, n);
+                       n+=2;
+                       psk_err = 0;
+               psk_err:
+                       OPENSSL_cleanse(identity, PSK_MAX_IDENTITY_LEN);
+                       OPENSSL_cleanse(psk_or_pre_ms, sizeof(psk_or_pre_ms));
+                       if (psk_err != 0)
+                               {
+                               ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
+                               goto err;
+                               }
+                       }
+#endif
                else
                        {
                        ssl3_send_alert(s, SSL3_AL_FATAL,
@@ -2425,28 +2748,37 @@ int ssl3_send_client_verify(SSL *s)
        unsigned char *p,*d;
        unsigned char data[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH];
        EVP_PKEY *pkey;
+       EVP_PKEY_CTX *pctx=NULL;
 #ifndef OPENSSL_NO_RSA
        unsigned u=0;
 #endif
        unsigned long n;
-#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_ECDSA)
        int j;
-#endif
 
        if (s->state == SSL3_ST_CW_CERT_VRFY_A)
                {
                d=(unsigned char *)s->init_buf->data;
                p= &(d[4]);
                pkey=s->cert->key->privatekey;
-
-               s->method->ssl3_enc->cert_verify_mac(s,&(s->s3->finish_dgst2),
-                       &(data[MD5_DIGEST_LENGTH]));
-
+/* Create context from key and test if sha1 is allowed as digest */
+               pctx = EVP_PKEY_CTX_new(pkey,NULL);
+               EVP_PKEY_sign_init(pctx);
+               if (EVP_PKEY_CTX_set_signature_md(pctx, EVP_sha1())>0)
+                       {
+                       s->method->ssl3_enc->cert_verify_mac(s,
+                                               NID_sha1,
+                                               &(data[MD5_DIGEST_LENGTH]));
+                       }
+               else
+                       {
+                       ERR_clear_error();
+                       }
 #ifndef OPENSSL_NO_RSA
                if (pkey->type == EVP_PKEY_RSA)
                        {
                        s->method->ssl3_enc->cert_verify_mac(s,
-                               &(s->s3->finish_dgst1),&(data[0]));
+                               NID_md5,
+                               &(data[0]));
                        if (RSA_sign(NID_md5_sha1, data,
                                         MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH,
                                        &(p[2]), &u, pkey->pkey.rsa) <= 0 )
@@ -2492,10 +2824,30 @@ int ssl3_send_client_verify(SSL *s)
                        }
                else
 #endif
-                       {
+               if (pkey->type == NID_id_GostR3410_94 || pkey->type == NID_id_GostR3410_2001) 
+               {
+               unsigned char signbuf[64];
+               int i;
+               size_t sigsize=64;
+               s->method->ssl3_enc->cert_verify_mac(s,
+                       NID_id_GostR3411_94,
+                       data);
+               if (EVP_PKEY_sign(pctx, signbuf, &sigsize, data, 32) <= 0) {
+                       SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,
+                       ERR_R_INTERNAL_ERROR);
+                       goto err;
+               }
+               for (i=63,j=0; i>=0; j++, i--) {
+                       p[2+j]=signbuf[i];
+               }       
+               s2n(j,p);
+               n=j+2;
+               }
+               else
+               {
                        SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,ERR_R_INTERNAL_ERROR);
                        goto err;
-                       }
+               }
                *(d++)=SSL3_MT_CERTIFICATE_VERIFY;
                l2n3(n,d);
 
@@ -2503,8 +2855,10 @@ int ssl3_send_client_verify(SSL *s)
                s->init_num=(int)n+4;
                s->init_off=0;
                }
+       EVP_PKEY_CTX_free(pctx);
        return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
 err:
+       EVP_PKEY_CTX_free(pctx);
        return(-1);
        }
 
@@ -2589,7 +2943,7 @@ int ssl3_send_client_certificate(SSL *s)
 int ssl3_check_cert_and_algorithm(SSL *s)
        {
        int i,idx;
-       long algs;
+       long alg_k,alg_a;
        EVP_PKEY *pkey=NULL;
        SESS_CERT *sc;
 #ifndef OPENSSL_NO_RSA
@@ -2599,14 +2953,14 @@ int ssl3_check_cert_and_algorithm(SSL *s)
        DH *dh;
 #endif
 
-       sc=s->session->sess_cert;
-
-       algs=s->s3->tmp.new_cipher->algorithms;
+       alg_k=s->s3->tmp.new_cipher->algorithm_mkey;
+       alg_a=s->s3->tmp.new_cipher->algorithm_auth;
 
        /* we don't have a certificate */
-       if (algs & (SSL_aDH|SSL_aNULL|SSL_aKRB5))
+       if ((alg_a & (SSL_aDH|SSL_aNULL|SSL_aKRB5)) || (alg_k & SSL_kPSK))
                return(1);
 
+       sc=s->session->sess_cert;
        if (sc == NULL)
                {
                SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,ERR_R_INTERNAL_ERROR);
@@ -2626,11 +2980,11 @@ int ssl3_check_cert_and_algorithm(SSL *s)
 #ifndef OPENSSL_NO_ECDH
        if (idx == SSL_PKEY_ECC)
                {
-               if (check_srvr_ecc_cert_and_alg(sc->peer_pkeys[idx].x509,
+               if (ssl_check_srvr_ecc_cert_and_alg(sc->peer_pkeys[idx].x509,
                    s->s3->tmp.new_cipher) == 0) 
                        { /* check failed */
                        SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_BAD_ECC_CERT);
-                       goto f_err;                     
+                       goto f_err;
                        }
                else 
                        {
@@ -2644,20 +2998,20 @@ int ssl3_check_cert_and_algorithm(SSL *s)
 
        
        /* Check that we have a certificate if we require one */
-       if ((algs & SSL_aRSA) && !has_bits(i,EVP_PK_RSA|EVP_PKT_SIGN))
+       if ((alg_a & SSL_aRSA) && !has_bits(i,EVP_PK_RSA|EVP_PKT_SIGN))
                {
                SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_SIGNING_CERT);
                goto f_err;
                }
 #ifndef OPENSSL_NO_DSA
-       else if ((algs & SSL_aDSS) && !has_bits(i,EVP_PK_DSA|EVP_PKT_SIGN))
+       else if ((alg_a & SSL_aDSS) && !has_bits(i,EVP_PK_DSA|EVP_PKT_SIGN))
                {
                SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DSA_SIGNING_CERT);
                goto f_err;
                }
 #endif
 #ifndef OPENSSL_NO_RSA
-       if ((algs & SSL_kRSA) &&
+       if ((alg_k & SSL_kRSA) &&
                !(has_bits(i,EVP_PK_RSA|EVP_PKT_ENC) || (rsa != NULL)))
                {
                SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_ENCRYPTING_CERT);
@@ -2665,19 +3019,19 @@ int ssl3_check_cert_and_algorithm(SSL *s)
                }
 #endif
 #ifndef OPENSSL_NO_DH
-       if ((algs & SSL_kEDH) &&
+       if ((alg_k & SSL_kEDH) &&
                !(has_bits(i,EVP_PK_DH|EVP_PKT_EXCH) || (dh != NULL)))
                {
                SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_KEY);
                goto f_err;
                }
-       else if ((algs & SSL_kDHr) && !has_bits(i,EVP_PK_DH|EVP_PKS_RSA))
+       else if ((alg_k & SSL_kDHr) && !has_bits(i,EVP_PK_DH|EVP_PKS_RSA))
                {
                SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_RSA_CERT);
                goto f_err;
                }
 #ifndef OPENSSL_NO_DSA
-       else if ((algs & SSL_kDHd) && !has_bits(i,EVP_PK_DH|EVP_PKS_DSA))
+       else if ((alg_k & SSL_kDHd) && !has_bits(i,EVP_PK_DH|EVP_PKS_DSA))
                {
                SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_DSA_CERT);
                goto f_err;
@@ -2688,7 +3042,7 @@ int ssl3_check_cert_and_algorithm(SSL *s)
        if (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && !has_bits(i,EVP_PKT_EXP))
                {
 #ifndef OPENSSL_NO_RSA
-               if (algs & SSL_kRSA)
+               if (alg_k & SSL_kRSA)
                        {
                        if (rsa == NULL
                            || RSA_size(rsa)*8 > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher))
@@ -2700,7 +3054,7 @@ int ssl3_check_cert_and_algorithm(SSL *s)
                else
 #endif
 #ifndef OPENSSL_NO_DH
-                       if (algs & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
+                       if (alg_k & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
                            {
                            if (dh == NULL
                                || DH_size(dh)*8 > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher))
@@ -2723,49 +3077,13 @@ err:
        return(0);
        }
 
+/* Check to see if handshake is full or resumed. Usually this is just a
+ * case of checking to see if a cache hit has occurred. In the case of
+ * session tickets we have to check the next message to be sure.
+ */
 
-#ifndef OPENSSL_NO_ECDH
-/* This is the complement of nid2curve_id in s3_srvr.c. */
-static int curve_id2nid(int curve_id)
-{
-       /* ECC curves from draft-ietf-tls-ecc-01.txt (Mar 15, 2001)
-        * (no changes in draft-ietf-tls-ecc-03.txt [June 2003]) */
-       static int nid_list[26] =
-       {
-               0,
-               NID_sect163k1, /* sect163k1 (1) */
-               NID_sect163r1, /* sect163r1 (2) */
-               NID_sect163r2, /* sect163r2 (3) */
-               NID_sect193r1, /* sect193r1 (4) */ 
-               NID_sect193r2, /* sect193r2 (5) */ 
-               NID_sect233k1, /* sect233k1 (6) */
-               NID_sect233r1, /* sect233r1 (7) */ 
-               NID_sect239k1, /* sect239k1 (8) */ 
-               NID_sect283k1, /* sect283k1 (9) */
-               NID_sect283r1, /* sect283r1 (10) */ 
-               NID_sect409k1, /* sect409k1 (11) */ 
-               NID_sect409r1, /* sect409r1 (12) */
-               NID_sect571k1, /* sect571k1 (13) */ 
-               NID_sect571r1, /* sect571r1 (14) */ 
-               NID_secp160k1, /* secp160k1 (15) */
-               NID_secp160r1, /* secp160r1 (16) */ 
-               NID_secp160r2, /* secp160r2 (17) */ 
-               NID_secp192k1, /* secp192k1 (18) */
-               NID_X9_62_prime192v1, /* secp192r1 (19) */ 
-               NID_secp224k1, /* secp224k1 (20) */ 
-               NID_secp224r1, /* secp224r1 (21) */
-               NID_secp256k1, /* secp256k1 (22) */ 
-               NID_X9_62_prime256v1, /* secp256r1 (23) */ 
-               NID_secp384r1, /* secp384r1 (24) */
-               NID_secp521r1  /* secp521r1 (25) */     
-       };
-       
-       if ((curve_id < 1) || (curve_id > 25)) return 0;
-
-       return nid_list[curve_id];
-}
-#endif
-
+#ifndef OPENSSL_NO_TLSEXT
+# ifndef OPENSSL_NO_NEXTPROTONEG
 int ssl3_send_next_proto(SSL *s)
        {
        unsigned int len, padding_len;
@@ -2788,23 +3106,15 @@ int ssl3_send_next_proto(SSL *s)
                }
 
        return ssl3_do_write(s, SSL3_RT_HANDSHAKE);
-}
-
-/* Check to see if handshake is full or resumed. Usually this is just a
- * case of checking to see if a cache hit has occurred. In the case of
- * session tickets we have to check the next message to be sure.
- */
+       }
+# endif
 
-#ifndef OPENSSL_NO_TLSEXT
 int ssl3_check_finished(SSL *s)
        {
        int ok;
        long n;
-       /* If we have no ticket or session ID is non-zero length (a match of
-        * a non-zero session length would never reach here) it cannot be a
-        * resumed session.
-        */
-       if (!s->session->tlsext_tick || s->session->session_id_length)
+       /* If we have no ticket it cannot be a resumed session. */
+       if (!s->session->tlsext_tick)
                return 1;
        /* this function is called when we really expect a Certificate
         * message, so permit appropriate message length */
index c7e74ac..b145970 100644 (file)
@@ -56,7 +56,7 @@
  * [including the GNU Public Licence.]
  */
 /* ====================================================================
- * Copyright (c) 1998-2002 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2007 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * Hudson (tjh@cryptsoft.com).
  *
  */
+/* ====================================================================
+ * Copyright 2005 Nokia. All rights reserved.
+ *
+ * The portions of the attached software ("Contribution") is developed by
+ * Nokia Corporation and is licensed pursuant to the OpenSSL open source
+ * license.
+ *
+ * The Contribution, originally written by Mika Kousa and Pasi Eronen of
+ * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
+ * support (see RFC 4279) to OpenSSL.
+ *
+ * No patent licenses or other rights except those expressly stated in
+ * the OpenSSL open source license shall be deemed granted or received
+ * expressly, by implication, estoppel, or otherwise.
+ *
+ * No assurances are provided by Nokia that the Contribution does not
+ * infringe the patent or other intellectual property rights of any third
+ * party or that the license provides you with all the necessary rights
+ * to make use of the Contribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
+ * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
+ * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
+ * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
+ * OTHERWISE.
+ */
 
 #include <stdio.h>
 #include "ssl_locl.h"
-#include "fnv1a64.h"
 #include <openssl/evp.h>
 #include <openssl/md5.h>
 
@@ -130,10 +155,8 @@ static unsigned char ssl3_pad_2[48]={
        0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,
        0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,
        0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,0x5c };
-
-static int ssl3_handshake_mac(SSL *s, EVP_MD_CTX *in_ctx,
+static int ssl3_handshake_mac(SSL *s, int md_nid,
        const char *sender, int len, unsigned char *p);
-
 static int ssl3_generate_key_block(SSL *s, unsigned char *km, int num)
        {
        EVP_MD_CTX m5;
@@ -147,7 +170,6 @@ static int ssl3_generate_key_block(SSL *s, unsigned char *km, int num)
 #endif
        k=0;
        EVP_MD_CTX_init(&m5);
-       EVP_MD_CTX_set_flags(&m5, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
        EVP_MD_CTX_init(&s1);
        for (i=0; (int)i<num; i+=MD5_DIGEST_LENGTH)
                {
@@ -209,6 +231,8 @@ int ssl3_change_cipher_state(SSL *s, int which)
        is_exp=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher);
        c=s->s3->tmp.new_sym_enc;
        m=s->s3->tmp.new_hash;
+       /* m == NULL will lead to a crash later */
+       OPENSSL_assert(m);
 #ifndef OPENSSL_NO_COMP
        if (s->s3->tmp.new_compression == NULL)
                comp=NULL;
@@ -226,7 +250,8 @@ int ssl3_change_cipher_state(SSL *s, int which)
                        /* make sure it's intialized in case we exit later with an error */
                        EVP_CIPHER_CTX_init(s->enc_read_ctx);
                dd= s->enc_read_ctx;
-               s->read_hash=m;
+
+               ssl_replace_hash(&s->read_hash,m);
 #ifndef OPENSSL_NO_COMP
                /* COMPRESS */
                if (s->expand != NULL)
@@ -262,7 +287,7 @@ int ssl3_change_cipher_state(SSL *s, int which)
                        /* make sure it's intialized in case we exit later with an error */
                        EVP_CIPHER_CTX_init(s->enc_write_ctx);
                dd= s->enc_write_ctx;
-               s->write_hash=m;
+               ssl_replace_hash(&s->write_hash,m);
 #ifndef OPENSSL_NO_COMP
                /* COMPRESS */
                if (s->compress != NULL)
@@ -289,6 +314,8 @@ int ssl3_change_cipher_state(SSL *s, int which)
 
        p=s->s3->tmp.key_block;
        i=EVP_MD_size(m);
+       if (i < 0)
+               goto err2;
        cl=EVP_CIPHER_key_length(c);
        j=is_exp ? (cl < SSL_C_EXPORT_KEYLENGTH(s->s3->tmp.new_cipher) ?
                 cl : SSL_C_EXPORT_KEYLENGTH(s->s3->tmp.new_cipher)) : cl;
@@ -369,7 +396,7 @@ int ssl3_setup_key_block(SSL *s)
        if (s->s3->tmp.key_block_length != 0)
                return(1);
 
-       if (!ssl_cipher_get_evp(s->session,&c,&hash,&comp))
+       if (!ssl_cipher_get_evp(s->session,&c,&hash,NULL,NULL,&comp))
                {
                SSLerr(SSL_F_SSL3_SETUP_KEY_BLOCK,SSL_R_CIPHER_OR_HASH_UNAVAILABLE);
                return(0);
@@ -383,7 +410,11 @@ int ssl3_setup_key_block(SSL *s)
        s->s3->tmp.new_compression=comp;
 #endif
 
-       num=EVP_CIPHER_key_length(c)+EVP_MD_size(hash)+EVP_CIPHER_iv_length(c);
+       num=EVP_MD_size(hash);
+       if (num < 0)
+               return 0;
+
+       num=EVP_CIPHER_key_length(c)+num+EVP_CIPHER_iv_length(c);
        num*=2;
 
        ssl3_cleanup_key_block(s);
@@ -405,11 +436,11 @@ int ssl3_setup_key_block(SSL *s)
 
                if (s->session->cipher != NULL)
                        {
-                       if ((s->session->cipher->algorithms & SSL_ENC_MASK) == SSL_eNULL)
+                       if (s->session->cipher->algorithm_enc == SSL_eNULL)
                                s->s3->need_empty_fragments = 0;
                        
 #ifndef OPENSSL_NO_RC4
-                       if ((s->session->cipher->algorithms & SSL_ENC_MASK) == SSL_RC4)
+                       if (s->session->cipher->algorithm_enc == SSL_RC4)
                                s->s3->need_empty_fragments = 0;
 #endif
                        }
@@ -480,6 +511,9 @@ int ssl3_enc(SSL *s, int send)
 
                        /* we need to add 'i-1' padding bytes */
                        l+=i;
+                       /* the last of these zero bytes will be overwritten
+                        * with the padding length. */
+                       memset(&rec->input[rec->length], 0, i);
                        rec->length+=i;
                        rec->input[l-1]=(i-1);
                        }
@@ -519,55 +553,131 @@ int ssl3_enc(SSL *s, int send)
 
 void ssl3_init_finished_mac(SSL *s)
        {
-       EVP_MD_CTX_set_flags(&(s->s3->finish_dgst1),
-               EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
-       EVP_DigestInit_ex(&(s->s3->finish_dgst1),s->ctx->md5, NULL);
-       EVP_DigestInit_ex(&(s->s3->finish_dgst2),s->ctx->sha1, NULL);
+       if (s->s3->handshake_buffer) BIO_free(s->s3->handshake_buffer);
+       if (s->s3->handshake_dgst) ssl3_free_digest_list(s);
+    s->s3->handshake_buffer=BIO_new(BIO_s_mem());      
+       (void)BIO_set_close(s->s3->handshake_buffer,BIO_CLOSE);
        }
 
-void ssl3_finish_mac(SSL *s, const unsigned char *buf, int len)
+void ssl3_free_digest_list(SSL *s) 
        {
-       EVP_DigestUpdate(&(s->s3->finish_dgst1),buf,len);
-       EVP_DigestUpdate(&(s->s3->finish_dgst2),buf,len);
-       if (s->s3->snap_start_requested)
+       int i;
+       if (!s->s3->handshake_dgst) return;
+       for (i=0;i<SSL_MAX_DIGEST;i++) 
                {
-               /* Compute Fowler-Noll-Vo (FNV) hash for Snap Start handshake */
-               fnv1a64_update((FNV1A64*) s->s3->response_hash, buf, len);
+               if (s->s3->handshake_dgst[i])
+                       EVP_MD_CTX_destroy(s->s3->handshake_dgst[i]);
                }
+       OPENSSL_free(s->s3->handshake_dgst);
+       s->s3->handshake_dgst=NULL;
+       }       
+               
+
+
+void ssl3_finish_mac(SSL *s, const unsigned char *buf, int len)
+       {
+       if (s->s3->handshake_buffer) 
+               {
+               BIO_write (s->s3->handshake_buffer,(void *)buf,len);
+               } 
+       else 
+               {
+               int i;
+               for (i=0;i< SSL_MAX_DIGEST;i++) 
+                       {
+                       if (s->s3->handshake_dgst[i]!= NULL)
+                       EVP_DigestUpdate(s->s3->handshake_dgst[i],buf,len);
+                       }
+               }       
        }
 
-int ssl3_cert_verify_mac(SSL *s, EVP_MD_CTX *ctx, unsigned char *p)
+int ssl3_digest_cached_records(SSL *s)
        {
-       return(ssl3_handshake_mac(s,ctx,NULL,0,p));
+       int i;
+       long mask;
+       const EVP_MD *md;
+       long hdatalen;
+       void *hdata;
+
+       /* Allocate handshake_dgst array */
+       ssl3_free_digest_list(s);
+       s->s3->handshake_dgst = OPENSSL_malloc(SSL_MAX_DIGEST * sizeof(EVP_MD_CTX *));
+       memset(s->s3->handshake_dgst,0,SSL_MAX_DIGEST *sizeof(EVP_MD_CTX *));
+       hdatalen = BIO_get_mem_data(s->s3->handshake_buffer,&hdata);
+       if (hdatalen <= 0)
+               {
+               SSLerr(SSL_F_SSL3_DIGEST_CACHED_RECORDS, SSL_R_BAD_HANDSHAKE_LENGTH);
+               return 0;
+               }
+
+       /* Loop through bitso of algorithm2 field and create MD_CTX-es */
+       for (i=0;ssl_get_handshake_digest(i,&mask,&md); i++) 
+               {
+               if ((mask & s->s3->tmp.new_cipher->algorithm2) && md) 
+                       {
+                       s->s3->handshake_dgst[i]=EVP_MD_CTX_create();
+                       EVP_DigestInit_ex(s->s3->handshake_dgst[i],md,NULL);
+                       EVP_DigestUpdate(s->s3->handshake_dgst[i],hdata,hdatalen);
+                       } 
+               else 
+                       {       
+                       s->s3->handshake_dgst[i]=NULL;
+                       }
+               }
+       /* Free handshake_buffer BIO */
+       BIO_free(s->s3->handshake_buffer);
+       s->s3->handshake_buffer = NULL;
+
+       return 1;
        }
 
-int ssl3_final_finish_mac(SSL *s, EVP_MD_CTX *ctx1, EVP_MD_CTX *ctx2,
+int ssl3_cert_verify_mac(SSL *s, int md_nid, unsigned char *p)
+       {
+       return(ssl3_handshake_mac(s,md_nid,NULL,0,p));
+       }
+int ssl3_final_finish_mac(SSL *s, 
             const char *sender, int len, unsigned char *p)
        {
        int ret;
-
-       ret=ssl3_handshake_mac(s,ctx1,sender,len,p);
+       ret=ssl3_handshake_mac(s,NID_md5,sender,len,p);
        p+=ret;
-       ret+=ssl3_handshake_mac(s,ctx2,sender,len,p);
+       ret+=ssl3_handshake_mac(s,NID_sha1,sender,len,p);
        return(ret);
        }
-
-static int ssl3_handshake_mac(SSL *s, EVP_MD_CTX *in_ctx,
+static int ssl3_handshake_mac(SSL *s, int md_nid,
             const char *sender, int len, unsigned char *p)
        {
        unsigned int ret;
        int npad,n;
        unsigned int i;
        unsigned char md_buf[EVP_MAX_MD_SIZE];
-       EVP_MD_CTX ctx;
+       EVP_MD_CTX ctx,*d=NULL;
 
-       EVP_MD_CTX_init(&ctx);
-       EVP_MD_CTX_set_flags(&ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
-       EVP_MD_CTX_copy_ex(&ctx,in_ctx);
+       if (s->s3->handshake_buffer) 
+               if (!ssl3_digest_cached_records(s))
+                       return 0;
 
+       /* Search for digest of specified type in the handshake_dgst
+        * array*/
+       for (i=0;i<SSL_MAX_DIGEST;i++) 
+               {
+                 if (s->s3->handshake_dgst[i]&&EVP_MD_CTX_type(s->s3->handshake_dgst[i])==md_nid) 
+                       {
+                       d=s->s3->handshake_dgst[i];
+                       break;
+                       }
+               }
+       if (!d) {
+               SSLerr(SSL_F_SSL3_HANDSHAKE_MAC,SSL_R_NO_REQUIRED_DIGEST);
+               return 0;
+       }       
+       EVP_MD_CTX_init(&ctx);
+       EVP_MD_CTX_copy_ex(&ctx,d);
        n=EVP_MD_CTX_size(&ctx);
-       npad=(48/n)*n;
+       if (n < 0)
+               return 0;
 
+       npad=(48/n)*n;
        if (sender != NULL)
                EVP_DigestUpdate(&ctx,sender,len);
        EVP_DigestUpdate(&ctx,s->session->master_key,
@@ -587,15 +697,16 @@ static int ssl3_handshake_mac(SSL *s, EVP_MD_CTX *in_ctx,
        return((int)ret);
        }
 
-int ssl3_mac(SSL *ssl, unsigned char *md, int send)
+int n_ssl3_mac(SSL *ssl, unsigned char *md, int send)
        {
        SSL3_RECORD *rec;
        unsigned char *mac_sec,*seq;
        EVP_MD_CTX md_ctx;
-       const EVP_MD *hash;
+       const EVP_MD_CTX *hash;
        unsigned char *p,rec_char;
        unsigned int md_size;
        int npad;
+       int t;
 
        if (send)
                {
@@ -612,13 +723,16 @@ int ssl3_mac(SSL *ssl, unsigned char *md, int send)
                hash=ssl->read_hash;
                }
 
-       md_size=EVP_MD_size(hash);
+       t=EVP_MD_CTX_size(hash);
+       if (t < 0)
+               return -1;
+       md_size=t;
        npad=(48/md_size)*md_size;
 
        /* Chop the digest off the end :-) */
        EVP_MD_CTX_init(&md_ctx);
 
-       EVP_DigestInit_ex(  &md_ctx,hash, NULL);
+       EVP_MD_CTX_copy_ex( &md_ctx,hash);
        EVP_DigestUpdate(&md_ctx,mac_sec,md_size);
        EVP_DigestUpdate(&md_ctx,ssl3_pad_1,npad);
        EVP_DigestUpdate(&md_ctx,seq,8);
@@ -630,7 +744,7 @@ int ssl3_mac(SSL *ssl, unsigned char *md, int send)
        EVP_DigestUpdate(&md_ctx,rec->input,rec->length);
        EVP_DigestFinal_ex( &md_ctx,md,NULL);
 
-       EVP_DigestInit_ex(  &md_ctx,hash, NULL);
+       EVP_MD_CTX_copy_ex( &md_ctx,hash);
        EVP_DigestUpdate(&md_ctx,mac_sec,md_size);
        EVP_DigestUpdate(&md_ctx,ssl3_pad_2,npad);
        EVP_DigestUpdate(&md_ctx,md,md_size);
@@ -723,6 +837,12 @@ int ssl3_alert_code(int code)
        case SSL_AD_INTERNAL_ERROR:     return(SSL3_AD_HANDSHAKE_FAILURE);
        case SSL_AD_USER_CANCELLED:     return(SSL3_AD_HANDSHAKE_FAILURE);
        case SSL_AD_NO_RENEGOTIATION:   return(-1); /* Don't send it :-) */
+       case SSL_AD_UNSUPPORTED_EXTENSION: return(SSL3_AD_HANDSHAKE_FAILURE);
+       case SSL_AD_CERTIFICATE_UNOBTAINABLE: return(SSL3_AD_HANDSHAKE_FAILURE);
+       case SSL_AD_UNRECOGNIZED_NAME:  return(SSL3_AD_HANDSHAKE_FAILURE);
+       case SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE: return(SSL3_AD_HANDSHAKE_FAILURE);
+       case SSL_AD_BAD_CERTIFICATE_HASH_VALUE: return(SSL3_AD_HANDSHAKE_FAILURE);
+       case SSL_AD_UNKNOWN_PSK_IDENTITY:return(TLS1_AD_UNKNOWN_PSK_IDENTITY);
        default:                        return(-1);
                }
        }
index b3981cf..72d3f1f 100644 (file)
@@ -56,7 +56,7 @@
  * [including the GNU Public Licence.]
  */
 /* ====================================================================
- * Copyright (c) 1998-2006 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2007 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * Vipul Gupta and Sumit Gupta of Sun Microsystems Laboratories.
  *
  */
+/* ====================================================================
+ * Copyright 2005 Nokia. All rights reserved.
+ *
+ * The portions of the attached software ("Contribution") is developed by
+ * Nokia Corporation and is licensed pursuant to the OpenSSL open source
+ * license.
+ *
+ * The Contribution, originally written by Mika Kousa and Pasi Eronen of
+ * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
+ * support (see RFC 4279) to OpenSSL.
+ *
+ * No patent licenses or other rights except those expressly stated in
+ * the OpenSSL open source license shall be deemed granted or received
+ * expressly, by implication, estoppel, or otherwise.
+ *
+ * No assurances are provided by Nokia that the Contribution does not
+ * infringe the patent or other intellectual property rights of any third
+ * party or that the license provides you with all the necessary rights
+ * to make use of the Contribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
+ * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
+ * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
+ * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
+ * OTHERWISE.
+ */
 
 #include <stdio.h>
 #include <openssl/objects.h>
 #include "ssl_locl.h"
 #include "kssl_lcl.h"
+#ifndef OPENSSL_NO_TLSEXT
+#ifndef OPENSSL_NO_EC
+#include "../crypto/ec/ec_lcl.h"
+#endif /* OPENSSL_NO_EC */
+#endif /* OPENSSL_NO_TLSEXT */
 #include <openssl/md5.h>
 #ifndef OPENSSL_NO_DH
 #include <openssl/dh.h>
 #endif
-#include <openssl/pq_compat.h>
 
 const char ssl3_version_str[]="SSLv3" OPENSSL_VERSION_PTEXT;
 
@@ -138,217 +168,265 @@ const char ssl3_version_str[]="SSLv3" OPENSSL_VERSION_PTEXT;
 
 /* list of available SSLv3 ciphers (sorted by id) */
 OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
+
 /* The RSA ciphers */
 /* Cipher 01 */
        {
        1,
        SSL3_TXT_RSA_NULL_MD5,
        SSL3_CK_RSA_NULL_MD5,
-       SSL_kRSA|SSL_aRSA|SSL_eNULL |SSL_MD5|SSL_SSLV3,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_eNULL,
+       SSL_MD5,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_STRONG_NONE,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        0,
        0,
-       0,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 02 */
        {
        1,
        SSL3_TXT_RSA_NULL_SHA,
        SSL3_CK_RSA_NULL_SHA,
-       SSL_kRSA|SSL_aRSA|SSL_eNULL |SSL_SHA1|SSL_SSLV3,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_eNULL,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_STRONG_NONE|SSL_FIPS,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        0,
        0,
-       0,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 03 */
        {
        1,
        SSL3_TXT_RSA_RC4_40_MD5,
        SSL3_CK_RSA_RC4_40_MD5,
-       SSL_kRSA|SSL_aRSA|SSL_RC4  |SSL_MD5 |SSL_SSLV3,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_RC4,
+       SSL_MD5,
+       SSL_SSLV3,
        SSL_EXPORT|SSL_EXP40,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        40,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 04 */
        {
        1,
        SSL3_TXT_RSA_RC4_128_MD5,
        SSL3_CK_RSA_RC4_128_MD5,
-       SSL_kRSA|SSL_aRSA|SSL_RC4  |SSL_MD5|SSL_SSLV3,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_RC4,
+       SSL_MD5,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_MEDIUM,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 05 */
        {
        1,
        SSL3_TXT_RSA_RC4_128_SHA,
        SSL3_CK_RSA_RC4_128_SHA,
-       SSL_kRSA|SSL_aRSA|SSL_RC4  |SSL_SHA1|SSL_SSLV3,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_RC4,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_MEDIUM,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 06 */
        {
        1,
        SSL3_TXT_RSA_RC2_40_MD5,
        SSL3_CK_RSA_RC2_40_MD5,
-       SSL_kRSA|SSL_aRSA|SSL_RC2  |SSL_MD5 |SSL_SSLV3,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_RC2,
+       SSL_MD5,
+       SSL_SSLV3,
        SSL_EXPORT|SSL_EXP40,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        40,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 07 */
 #ifndef OPENSSL_NO_IDEA
        {
        1,
        SSL3_TXT_RSA_IDEA_128_SHA,
        SSL3_CK_RSA_IDEA_128_SHA,
-       SSL_kRSA|SSL_aRSA|SSL_IDEA |SSL_SHA1|SSL_SSLV3,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_IDEA,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_MEDIUM,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 #endif
+
 /* Cipher 08 */
        {
        1,
        SSL3_TXT_RSA_DES_40_CBC_SHA,
        SSL3_CK_RSA_DES_40_CBC_SHA,
-       SSL_kRSA|SSL_aRSA|SSL_DES|SSL_SHA1|SSL_SSLV3,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_DES,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_EXPORT|SSL_EXP40,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        40,
        56,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 09 */
        {
        1,
        SSL3_TXT_RSA_DES_64_CBC_SHA,
        SSL3_CK_RSA_DES_64_CBC_SHA,
-       SSL_kRSA|SSL_aRSA|SSL_DES  |SSL_SHA1|SSL_SSLV3,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_DES,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_LOW,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        56,
        56,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 0A */
        {
        1,
        SSL3_TXT_RSA_DES_192_CBC3_SHA,
        SSL3_CK_RSA_DES_192_CBC3_SHA,
-       SSL_kRSA|SSL_aRSA|SSL_3DES |SSL_SHA1|SSL_SSLV3,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_3DES,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        168,
        168,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* The DH ciphers */
 /* Cipher 0B */
        {
        0,
        SSL3_TXT_DH_DSS_DES_40_CBC_SHA,
        SSL3_CK_DH_DSS_DES_40_CBC_SHA,
-       SSL_kDHd |SSL_aDH|SSL_DES|SSL_SHA1|SSL_SSLV3,
+       SSL_kDHd,
+       SSL_aDH,
+       SSL_DES,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_EXPORT|SSL_EXP40,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        40,
        56,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 0C */
        {
-       0,
+       0, /* not implemented (non-ephemeral DH) */
        SSL3_TXT_DH_DSS_DES_64_CBC_SHA,
        SSL3_CK_DH_DSS_DES_64_CBC_SHA,
-       SSL_kDHd |SSL_aDH|SSL_DES  |SSL_SHA1|SSL_SSLV3,
+       SSL_kDHd,
+       SSL_aDH,
+       SSL_DES,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_LOW,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        56,
        56,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 0D */
        {
-       0,
+       0, /* not implemented (non-ephemeral DH) */
        SSL3_TXT_DH_DSS_DES_192_CBC3_SHA,
        SSL3_CK_DH_DSS_DES_192_CBC3_SHA,
-       SSL_kDHd |SSL_aDH|SSL_3DES |SSL_SHA1|SSL_SSLV3,
+       SSL_kDHd,
+       SSL_aDH,
+       SSL_3DES,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        168,
        168,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 0E */
        {
-       0,
+       0, /* not implemented (non-ephemeral DH) */
        SSL3_TXT_DH_RSA_DES_40_CBC_SHA,
        SSL3_CK_DH_RSA_DES_40_CBC_SHA,
-       SSL_kDHr |SSL_aDH|SSL_DES|SSL_SHA1|SSL_SSLV3,
+       SSL_kDHr,
+       SSL_aDH,
+       SSL_DES,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_EXPORT|SSL_EXP40,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        40,
        56,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 0F */
        {
-       0,
+       0, /* not implemented (non-ephemeral DH) */
        SSL3_TXT_DH_RSA_DES_64_CBC_SHA,
        SSL3_CK_DH_RSA_DES_64_CBC_SHA,
-       SSL_kDHr |SSL_aDH|SSL_DES  |SSL_SHA1|SSL_SSLV3,
+       SSL_kDHr,
+       SSL_aDH,
+       SSL_DES,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_LOW,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        56,
        56,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 10 */
        {
-       0,
+       0, /* not implemented (non-ephemeral DH) */
        SSL3_TXT_DH_RSA_DES_192_CBC3_SHA,
        SSL3_CK_DH_RSA_DES_192_CBC3_SHA,
-       SSL_kDHr |SSL_aDH|SSL_3DES |SSL_SHA1|SSL_SSLV3,
+       SSL_kDHr,
+       SSL_aDH,
+       SSL_3DES,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        168,
        168,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
 /* The Ephemeral DH ciphers */
@@ -357,158 +435,193 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        1,
        SSL3_TXT_EDH_DSS_DES_40_CBC_SHA,
        SSL3_CK_EDH_DSS_DES_40_CBC_SHA,
-       SSL_kEDH|SSL_aDSS|SSL_DES|SSL_SHA1|SSL_SSLV3,
+       SSL_kEDH,
+       SSL_aDSS,
+       SSL_DES,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_EXPORT|SSL_EXP40,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        40,
        56,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 12 */
        {
        1,
        SSL3_TXT_EDH_DSS_DES_64_CBC_SHA,
        SSL3_CK_EDH_DSS_DES_64_CBC_SHA,
-       SSL_kEDH|SSL_aDSS|SSL_DES  |SSL_SHA1|SSL_SSLV3,
+       SSL_kEDH,
+       SSL_aDSS,
+       SSL_DES,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_LOW,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        56,
        56,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 13 */
        {
        1,
        SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA,
        SSL3_CK_EDH_DSS_DES_192_CBC3_SHA,
-       SSL_kEDH|SSL_aDSS|SSL_3DES |SSL_SHA1|SSL_SSLV3,
+       SSL_kEDH,
+       SSL_aDSS,
+       SSL_3DES,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        168,
        168,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 14 */
        {
        1,
        SSL3_TXT_EDH_RSA_DES_40_CBC_SHA,
        SSL3_CK_EDH_RSA_DES_40_CBC_SHA,
-       SSL_kEDH|SSL_aRSA|SSL_DES|SSL_SHA1|SSL_SSLV3,
+       SSL_kEDH,
+       SSL_aRSA,
+       SSL_DES,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_EXPORT|SSL_EXP40,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        40,
        56,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 15 */
        {
        1,
        SSL3_TXT_EDH_RSA_DES_64_CBC_SHA,
        SSL3_CK_EDH_RSA_DES_64_CBC_SHA,
-       SSL_kEDH|SSL_aRSA|SSL_DES  |SSL_SHA1|SSL_SSLV3,
+       SSL_kEDH,
+       SSL_aRSA,
+       SSL_DES,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_LOW,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        56,
        56,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 16 */
        {
        1,
        SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA,
        SSL3_CK_EDH_RSA_DES_192_CBC3_SHA,
-       SSL_kEDH|SSL_aRSA|SSL_3DES |SSL_SHA1|SSL_SSLV3,
+       SSL_kEDH,
+       SSL_aRSA,
+       SSL_3DES,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        168,
        168,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 17 */
        {
        1,
        SSL3_TXT_ADH_RC4_40_MD5,
        SSL3_CK_ADH_RC4_40_MD5,
-       SSL_kEDH |SSL_aNULL|SSL_RC4  |SSL_MD5 |SSL_SSLV3,
+       SSL_kEDH,
+       SSL_aNULL,
+       SSL_RC4,
+       SSL_MD5,
+       SSL_SSLV3,
        SSL_EXPORT|SSL_EXP40,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        40,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 18 */
        {
        1,
        SSL3_TXT_ADH_RC4_128_MD5,
        SSL3_CK_ADH_RC4_128_MD5,
-       SSL_kEDH |SSL_aNULL|SSL_RC4  |SSL_MD5 |SSL_SSLV3,
+       SSL_kEDH,
+       SSL_aNULL,
+       SSL_RC4,
+       SSL_MD5,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_MEDIUM,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 19 */
        {
        1,
        SSL3_TXT_ADH_DES_40_CBC_SHA,
        SSL3_CK_ADH_DES_40_CBC_SHA,
-       SSL_kEDH |SSL_aNULL|SSL_DES|SSL_SHA1|SSL_SSLV3,
+       SSL_kEDH,
+       SSL_aNULL,
+       SSL_DES,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_EXPORT|SSL_EXP40,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        40,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 1A */
        {
        1,
        SSL3_TXT_ADH_DES_64_CBC_SHA,
        SSL3_CK_ADH_DES_64_CBC_SHA,
-       SSL_kEDH |SSL_aNULL|SSL_DES  |SSL_SHA1|SSL_SSLV3,
+       SSL_kEDH,
+       SSL_aNULL,
+       SSL_DES,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_LOW,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        56,
        56,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 1B */
        {
        1,
        SSL3_TXT_ADH_DES_192_CBC_SHA,
        SSL3_CK_ADH_DES_192_CBC_SHA,
-       SSL_kEDH |SSL_aNULL|SSL_3DES |SSL_SHA1|SSL_SSLV3,
+       SSL_kEDH,
+       SSL_aNULL,
+       SSL_3DES,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        168,
        168,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
-/* Fortezza */
+/* Fortezza ciphersuite from SSL 3.0 spec */
+#if 0
 /* Cipher 1C */
        {
        0,
        SSL3_TXT_FZA_DMS_NULL_SHA,
        SSL3_CK_FZA_DMS_NULL_SHA,
-       SSL_kFZA|SSL_aFZA |SSL_eNULL |SSL_SHA1|SSL_SSLV3,
+       SSL_kFZA,
+       SSL_aFZA,
+       SSL_eNULL,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_STRONG_NONE,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        0,
        0,
-       0,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
 /* Cipher 1D */
@@ -516,45 +629,50 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        0,
        SSL3_TXT_FZA_DMS_FZA_SHA,
        SSL3_CK_FZA_DMS_FZA_SHA,
-       SSL_kFZA|SSL_aFZA |SSL_eFZA |SSL_SHA1|SSL_SSLV3,
+       SSL_kFZA,
+       SSL_aFZA,
+       SSL_eFZA,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_STRONG_NONE,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        0,
        0,
-       0,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
-#if 0
 /* Cipher 1E */
        {
        0,
        SSL3_TXT_FZA_DMS_RC4_SHA,
        SSL3_CK_FZA_DMS_RC4_SHA,
-       SSL_kFZA|SSL_aFZA |SSL_RC4  |SSL_SHA1|SSL_SSLV3,
+       SSL_kFZA,
+       SSL_aFZA,
+       SSL_RC4,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_MEDIUM,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 #endif
 
 #ifndef OPENSSL_NO_KRB5
-/* The Kerberos ciphers */
+/* The Kerberos ciphers*/
 /* Cipher 1E */
        {
        1,
        SSL3_TXT_KRB5_DES_64_CBC_SHA,
        SSL3_CK_KRB5_DES_64_CBC_SHA,
-       SSL_kKRB5|SSL_aKRB5|  SSL_DES|SSL_SHA1   |SSL_SSLV3,
+       SSL_kKRB5,
+       SSL_aKRB5,
+       SSL_DES,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_LOW,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        56,
        56,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
 /* Cipher 1F */
@@ -562,13 +680,15 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        1,
        SSL3_TXT_KRB5_DES_192_CBC3_SHA,
        SSL3_CK_KRB5_DES_192_CBC3_SHA,
-       SSL_kKRB5|SSL_aKRB5|  SSL_3DES|SSL_SHA1  |SSL_SSLV3,
+       SSL_kKRB5,
+       SSL_aKRB5,
+       SSL_3DES,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        168,
        168,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
 /* Cipher 20 */
@@ -576,13 +696,15 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        1,
        SSL3_TXT_KRB5_RC4_128_SHA,
        SSL3_CK_KRB5_RC4_128_SHA,
-       SSL_kKRB5|SSL_aKRB5|  SSL_RC4|SSL_SHA1  |SSL_SSLV3,
+       SSL_kKRB5,
+       SSL_aKRB5,
+       SSL_RC4,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_MEDIUM,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
 /* Cipher 21 */
@@ -590,13 +712,15 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        1,
        SSL3_TXT_KRB5_IDEA_128_CBC_SHA,
        SSL3_CK_KRB5_IDEA_128_CBC_SHA,
-       SSL_kKRB5|SSL_aKRB5|  SSL_IDEA|SSL_SHA1  |SSL_SSLV3,
+       SSL_kKRB5,
+       SSL_aKRB5,
+       SSL_IDEA,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_MEDIUM,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
 /* Cipher 22 */
@@ -604,13 +728,15 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        1,
        SSL3_TXT_KRB5_DES_64_CBC_MD5,
        SSL3_CK_KRB5_DES_64_CBC_MD5,
-       SSL_kKRB5|SSL_aKRB5|  SSL_DES|SSL_MD5    |SSL_SSLV3,
+       SSL_kKRB5,
+       SSL_aKRB5,
+       SSL_DES,
+       SSL_MD5,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_LOW,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        56,
        56,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
 /* Cipher 23 */
@@ -618,13 +744,15 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        1,
        SSL3_TXT_KRB5_DES_192_CBC3_MD5,
        SSL3_CK_KRB5_DES_192_CBC3_MD5,
-       SSL_kKRB5|SSL_aKRB5|  SSL_3DES|SSL_MD5   |SSL_SSLV3,
+       SSL_kKRB5,
+       SSL_aKRB5,
+       SSL_3DES,
+       SSL_MD5,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_HIGH,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        168,
        168,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
 /* Cipher 24 */
@@ -632,13 +760,15 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        1,
        SSL3_TXT_KRB5_RC4_128_MD5,
        SSL3_CK_KRB5_RC4_128_MD5,
-       SSL_kKRB5|SSL_aKRB5|  SSL_RC4|SSL_MD5  |SSL_SSLV3,
+       SSL_kKRB5,
+       SSL_aKRB5,
+       SSL_RC4,
+       SSL_MD5,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_MEDIUM,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
 /* Cipher 25 */
@@ -646,13 +776,15 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        1,
        SSL3_TXT_KRB5_IDEA_128_CBC_MD5,
        SSL3_CK_KRB5_IDEA_128_CBC_MD5,
-       SSL_kKRB5|SSL_aKRB5|  SSL_IDEA|SSL_MD5  |SSL_SSLV3,
+       SSL_kKRB5,
+       SSL_aKRB5,
+       SSL_IDEA,
+       SSL_MD5,
+       SSL_SSLV3,
        SSL_NOT_EXP|SSL_MEDIUM,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
 /* Cipher 26 */
@@ -660,13 +792,15 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        1,
        SSL3_TXT_KRB5_DES_40_CBC_SHA,
        SSL3_CK_KRB5_DES_40_CBC_SHA,
-       SSL_kKRB5|SSL_aKRB5|  SSL_DES|SSL_SHA1   |SSL_SSLV3,
+       SSL_kKRB5,
+       SSL_aKRB5,
+       SSL_DES,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_EXPORT|SSL_EXP40,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        40,
        56,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
 /* Cipher 27 */
@@ -674,13 +808,15 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        1,
        SSL3_TXT_KRB5_RC2_40_CBC_SHA,
        SSL3_CK_KRB5_RC2_40_CBC_SHA,
-       SSL_kKRB5|SSL_aKRB5|  SSL_RC2|SSL_SHA1   |SSL_SSLV3,
+       SSL_kKRB5,
+       SSL_aKRB5,
+       SSL_RC2,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_EXPORT|SSL_EXP40,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        40,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
 /* Cipher 28 */
@@ -688,13 +824,15 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        1,
        SSL3_TXT_KRB5_RC4_40_SHA,
        SSL3_CK_KRB5_RC4_40_SHA,
-       SSL_kKRB5|SSL_aKRB5|  SSL_RC4|SSL_SHA1   |SSL_SSLV3,
+       SSL_kKRB5,
+       SSL_aKRB5,
+       SSL_RC4,
+       SSL_SHA1,
+       SSL_SSLV3,
        SSL_EXPORT|SSL_EXP40,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        40,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
 /* Cipher 29 */
@@ -702,13 +840,15 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        1,
        SSL3_TXT_KRB5_DES_40_CBC_MD5,
        SSL3_CK_KRB5_DES_40_CBC_MD5,
-       SSL_kKRB5|SSL_aKRB5|  SSL_DES|SSL_MD5    |SSL_SSLV3,
+       SSL_kKRB5,
+       SSL_aKRB5,
+       SSL_DES,
+       SSL_MD5,
+       SSL_SSLV3,
        SSL_EXPORT|SSL_EXP40,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        40,
        56,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
 /* Cipher 2A */
@@ -716,13 +856,15 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        1,
        SSL3_TXT_KRB5_RC2_40_CBC_MD5,
        SSL3_CK_KRB5_RC2_40_CBC_MD5,
-       SSL_kKRB5|SSL_aKRB5|  SSL_RC2|SSL_MD5    |SSL_SSLV3,
+       SSL_kKRB5,
+       SSL_aKRB5,
+       SSL_RC2,
+       SSL_MD5,
+       SSL_SSLV3,
        SSL_EXPORT|SSL_EXP40,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        40,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
 /* Cipher 2B */
@@ -730,13 +872,15 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        1,
        SSL3_TXT_KRB5_RC4_40_MD5,
        SSL3_CK_KRB5_RC4_40_MD5,
-       SSL_kKRB5|SSL_aKRB5|  SSL_RC4|SSL_MD5    |SSL_SSLV3,
+       SSL_kKRB5,
+       SSL_aKRB5,
+       SSL_RC4,
+       SSL_MD5,
+       SSL_SSLV3,
        SSL_EXPORT|SSL_EXP40,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        40,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 #endif /* OPENSSL_NO_KRB5 */
 
@@ -746,78 +890,90 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        1,
        TLS1_TXT_RSA_WITH_AES_128_SHA,
        TLS1_CK_RSA_WITH_AES_128_SHA,
-       SSL_kRSA|SSL_aRSA|SSL_AES|SSL_SHA |SSL_TLSV1,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_AES128,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 /* Cipher 30 */
        {
        0,
        TLS1_TXT_DH_DSS_WITH_AES_128_SHA,
        TLS1_CK_DH_DSS_WITH_AES_128_SHA,
-       SSL_kDHd|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1,
+       SSL_kDHd,
+       SSL_aDH,
+       SSL_AES128,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 /* Cipher 31 */
        {
        0,
        TLS1_TXT_DH_RSA_WITH_AES_128_SHA,
        TLS1_CK_DH_RSA_WITH_AES_128_SHA,
-       SSL_kDHr|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1,
+       SSL_kDHr,
+       SSL_aDH,
+       SSL_AES128,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 /* Cipher 32 */
        {
        1,
        TLS1_TXT_DHE_DSS_WITH_AES_128_SHA,
        TLS1_CK_DHE_DSS_WITH_AES_128_SHA,
-       SSL_kEDH|SSL_aDSS|SSL_AES|SSL_SHA|SSL_TLSV1,
+       SSL_kEDH,
+       SSL_aDSS,
+       SSL_AES128,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 /* Cipher 33 */
        {
        1,
        TLS1_TXT_DHE_RSA_WITH_AES_128_SHA,
        TLS1_CK_DHE_RSA_WITH_AES_128_SHA,
-       SSL_kEDH|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1,
+       SSL_kEDH,
+       SSL_aRSA,
+       SSL_AES128,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 /* Cipher 34 */
        {
        1,
        TLS1_TXT_ADH_WITH_AES_128_SHA,
        TLS1_CK_ADH_WITH_AES_128_SHA,
-       SSL_kEDH|SSL_aNULL|SSL_AES|SSL_SHA|SSL_TLSV1,
+       SSL_kEDH,
+       SSL_aNULL,
+       SSL_AES128,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
 /* Cipher 35 */
@@ -825,78 +981,94 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        1,
        TLS1_TXT_RSA_WITH_AES_256_SHA,
        TLS1_CK_RSA_WITH_AES_256_SHA,
-       SSL_kRSA|SSL_aRSA|SSL_AES|SSL_SHA |SSL_TLSV1,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_AES256,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        256,
        256,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 /* Cipher 36 */
        {
        0,
        TLS1_TXT_DH_DSS_WITH_AES_256_SHA,
        TLS1_CK_DH_DSS_WITH_AES_256_SHA,
-       SSL_kDHd|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1,
+       SSL_kDHd,
+       SSL_aDH,
+       SSL_AES256,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        256,
        256,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 37 */
        {
-       0,
+       0, /* not implemented (non-ephemeral DH) */
        TLS1_TXT_DH_RSA_WITH_AES_256_SHA,
        TLS1_CK_DH_RSA_WITH_AES_256_SHA,
-       SSL_kDHr|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1,
+       SSL_kDHr,
+       SSL_aDH,
+       SSL_AES256,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        256,
        256,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 38 */
        {
        1,
        TLS1_TXT_DHE_DSS_WITH_AES_256_SHA,
        TLS1_CK_DHE_DSS_WITH_AES_256_SHA,
-       SSL_kEDH|SSL_aDSS|SSL_AES|SSL_SHA|SSL_TLSV1,
+       SSL_kEDH,
+       SSL_aDSS,
+       SSL_AES256,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        256,
        256,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
 /* Cipher 39 */
        {
        1,
        TLS1_TXT_DHE_RSA_WITH_AES_256_SHA,
        TLS1_CK_DHE_RSA_WITH_AES_256_SHA,
-       SSL_kEDH|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1,
+       SSL_kEDH,
+       SSL_aRSA,
+       SSL_AES256,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        256,
        256,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
+
        /* Cipher 3A */
        {
        1,
        TLS1_TXT_ADH_WITH_AES_256_SHA,
        TLS1_CK_ADH_WITH_AES_256_SHA,
-       SSL_kEDH|SSL_aNULL|SSL_AES|SSL_SHA|SSL_TLSV1,
+       SSL_kEDH,
+       SSL_aNULL,
+       SSL_AES256,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        256,
        256,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
 #ifndef OPENSSL_NO_CAMELLIA
@@ -907,78 +1079,95 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        1,
        TLS1_TXT_RSA_WITH_CAMELLIA_128_CBC_SHA,
        TLS1_CK_RSA_WITH_CAMELLIA_128_CBC_SHA,
-       SSL_kRSA|SSL_aRSA|SSL_CAMELLIA|SSL_SHA|SSL_TLSV1,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_CAMELLIA128,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_HIGH,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS
        },
+
        /* Cipher 42 */
        {
        0, /* not implemented (non-ephemeral DH) */
        TLS1_TXT_DH_DSS_WITH_CAMELLIA_128_CBC_SHA,
        TLS1_CK_DH_DSS_WITH_CAMELLIA_128_CBC_SHA,
-       SSL_kDHd|SSL_aDH|SSL_CAMELLIA|SSL_SHA|SSL_TLSV1,
+       SSL_kDHd,
+       SSL_aDH,
+       SSL_CAMELLIA128,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_HIGH,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS
        },
+
        /* Cipher 43 */
        {
        0, /* not implemented (non-ephemeral DH) */
        TLS1_TXT_DH_RSA_WITH_CAMELLIA_128_CBC_SHA,
        TLS1_CK_DH_RSA_WITH_CAMELLIA_128_CBC_SHA,
-       SSL_kDHr|SSL_aDH|SSL_CAMELLIA|SSL_SHA|SSL_TLSV1,
+       SSL_kDHr,
+       SSL_aDH,
+       SSL_CAMELLIA128,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_HIGH,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS
        },
+
        /* Cipher 44 */
        {
        1,
        TLS1_TXT_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA,
        TLS1_CK_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA,
-       SSL_kEDH|SSL_aDSS|SSL_CAMELLIA|SSL_SHA|SSL_TLSV1,
+       SSL_kEDH,
+       SSL_aDSS,
+       SSL_CAMELLIA128,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_HIGH,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS
        },
+
        /* Cipher 45 */
        {
        1,
        TLS1_TXT_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA,
        TLS1_CK_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA,
-       SSL_kEDH|SSL_aRSA|SSL_CAMELLIA|SSL_SHA|SSL_TLSV1,
+       SSL_kEDH,
+       SSL_aRSA,
+       SSL_CAMELLIA128,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_HIGH,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS
        },
+
        /* Cipher 46 */
        {
        1,
        TLS1_TXT_ADH_WITH_CAMELLIA_128_CBC_SHA,
        TLS1_CK_ADH_WITH_CAMELLIA_128_CBC_SHA,
-       SSL_kEDH|SSL_aNULL|SSL_CAMELLIA|SSL_SHA|SSL_TLSV1,
+       SSL_kEDH,
+       SSL_aNULL,
+       SSL_CAMELLIA128,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_HIGH,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS
        },
 #endif /* OPENSSL_NO_CAMELLIA */
 
@@ -986,98 +1175,174 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        /* New TLS Export CipherSuites from expired ID */
 #if 0
        /* Cipher 60 */
-           {
-           1,
-           TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_MD5,
-           TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_MD5,
-           SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_MD5|SSL_TLSV1,
-           SSL_EXPORT|SSL_EXP56,
-           0,
-           56,
-           128,
-           SSL_ALL_CIPHERS,
-           SSL_ALL_STRENGTHS,
-           },
+       {
+       1,
+       TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_MD5,
+       TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_MD5,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_RC4,
+       SSL_MD5,
+       SSL_TLSV1,
+       SSL_EXPORT|SSL_EXP56,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       56,
+       128,
+       },
+
        /* Cipher 61 */
-           {
-           1,
-           TLS1_TXT_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5,
-           TLS1_CK_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5,
-           SSL_kRSA|SSL_aRSA|SSL_RC2|SSL_MD5|SSL_TLSV1,
-           SSL_EXPORT|SSL_EXP56,
-           0,
-           56,
-           128,
-           SSL_ALL_CIPHERS,
-           SSL_ALL_STRENGTHS,
-           },
+       {
+       1,
+       TLS1_TXT_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5,
+       TLS1_CK_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_RC2,
+       SSL_MD5,
+       SSL_TLSV1,
+       SSL_EXPORT|SSL_EXP56,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       56,
+       128,
+       },
 #endif
+
        /* Cipher 62 */
-           {
-           1,
-           TLS1_TXT_RSA_EXPORT1024_WITH_DES_CBC_SHA,
-           TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA,
-           SSL_kRSA|SSL_aRSA|SSL_DES|SSL_SHA|SSL_TLSV1,
-           SSL_EXPORT|SSL_EXP56,
-           0,
-           56,
-           56,
-           SSL_ALL_CIPHERS,
-           SSL_ALL_STRENGTHS,
-           },
+       {
+       1,
+       TLS1_TXT_RSA_EXPORT1024_WITH_DES_CBC_SHA,
+       TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_DES,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_EXPORT|SSL_EXP56,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       56,
+       56,
+       },
+
        /* Cipher 63 */
-           {
-           1,
-           TLS1_TXT_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA,
-           TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA,
-           SSL_kEDH|SSL_aDSS|SSL_DES|SSL_SHA|SSL_TLSV1,
-           SSL_EXPORT|SSL_EXP56,
-           0,
-           56,
-           56,
-           SSL_ALL_CIPHERS,
-           SSL_ALL_STRENGTHS,
-           },
+       {
+       1,
+       TLS1_TXT_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA,
+       TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA,
+       SSL_kEDH,
+       SSL_aDSS,
+       SSL_DES,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_EXPORT|SSL_EXP56,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       56,
+       56,
+       },
+
        /* Cipher 64 */
-           {
-           1,
-           TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_SHA,
-           TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_SHA,
-           SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_SHA|SSL_TLSV1,
-           SSL_EXPORT|SSL_EXP56,
-           0,
-           56,
-           128,
-           SSL_ALL_CIPHERS,
-           SSL_ALL_STRENGTHS,
-           },
+       {
+       1,
+       TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_SHA,
+       TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_SHA,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_RC4,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_EXPORT|SSL_EXP56,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       56,
+       128,
+       },
+
        /* Cipher 65 */
-           {
-           1,
-           TLS1_TXT_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA,
-           TLS1_CK_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA,
-           SSL_kEDH|SSL_aDSS|SSL_RC4|SSL_SHA|SSL_TLSV1,
-           SSL_EXPORT|SSL_EXP56,
-           0,
-           56,
-           128,
-           SSL_ALL_CIPHERS,
-           SSL_ALL_STRENGTHS,
-           },
+       {
+       1,
+       TLS1_TXT_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA,
+       TLS1_CK_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA,
+       SSL_kEDH,
+       SSL_aDSS,
+       SSL_RC4,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_EXPORT|SSL_EXP56,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       56,
+       128,
+       },
+
        /* Cipher 66 */
-           {
-           1,
-           TLS1_TXT_DHE_DSS_WITH_RC4_128_SHA,
-           TLS1_CK_DHE_DSS_WITH_RC4_128_SHA,
-           SSL_kEDH|SSL_aDSS|SSL_RC4|SSL_SHA|SSL_TLSV1,
-           SSL_NOT_EXP|SSL_MEDIUM,
-           0,
-           128,
-           128,
-           SSL_ALL_CIPHERS,
-           SSL_ALL_STRENGTHS
-           },
+       {
+       1,
+       TLS1_TXT_DHE_DSS_WITH_RC4_128_SHA,
+       TLS1_CK_DHE_DSS_WITH_RC4_128_SHA,
+       SSL_kEDH,
+       SSL_aDSS,
+       SSL_RC4,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_MEDIUM,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       128,
+       128,
+       },
 #endif
+       {
+       1,
+       "GOST94-GOST89-GOST89",
+       0x3000080,
+       SSL_kGOST,
+       SSL_aGOST94,
+       SSL_eGOST2814789CNT,
+       SSL_GOST89MAC,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_HIGH,
+       SSL_HANDSHAKE_MAC_GOST94|TLS1_PRF_GOST94|TLS1_STREAM_MAC,
+       256,
+       256
+       },
+       {
+       1,
+       "GOST2001-GOST89-GOST89",
+       0x3000081,
+       SSL_kGOST,
+       SSL_aGOST01,
+       SSL_eGOST2814789CNT,
+       SSL_GOST89MAC,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_HIGH,
+       SSL_HANDSHAKE_MAC_GOST94|TLS1_PRF_GOST94|TLS1_STREAM_MAC,
+       256,
+       256
+       },
+       {
+       1,
+       "GOST94-NULL-GOST94",
+       0x3000082,
+       SSL_kGOST,
+       SSL_aGOST94,
+       SSL_eNULL,
+       SSL_GOST94,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_STRONG_NONE,
+       SSL_HANDSHAKE_MAC_GOST94|TLS1_PRF_GOST94,
+       0,
+       0
+       },
+       {
+       1,
+       "GOST2001-NULL-GOST94",
+       0x3000083,
+       SSL_kGOST,
+       SSL_aGOST01,
+       SSL_eNULL,
+       SSL_GOST94,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_STRONG_NONE,
+       SSL_HANDSHAKE_MAC_GOST94|TLS1_PRF_GOST94,
+       0,
+       0
+       },
 
 #ifndef OPENSSL_NO_CAMELLIA
        /* Camellia ciphersuites from RFC4132 (256-bit portion) */
@@ -1087,81 +1352,163 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        1,
        TLS1_TXT_RSA_WITH_CAMELLIA_256_CBC_SHA,
        TLS1_CK_RSA_WITH_CAMELLIA_256_CBC_SHA,
-       SSL_kRSA|SSL_aRSA|SSL_CAMELLIA|SSL_SHA|SSL_TLSV1,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_CAMELLIA256,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_HIGH,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        256,
        256,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS
        },
        /* Cipher 85 */
        {
        0, /* not implemented (non-ephemeral DH) */
        TLS1_TXT_DH_DSS_WITH_CAMELLIA_256_CBC_SHA,
        TLS1_CK_DH_DSS_WITH_CAMELLIA_256_CBC_SHA,
-       SSL_kDHd|SSL_aDH|SSL_CAMELLIA|SSL_SHA|SSL_TLSV1,
+       SSL_kDHd,
+       SSL_aDH,
+       SSL_CAMELLIA256,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_HIGH,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        256,
        256,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS
        },
+
        /* Cipher 86 */
        {
        0, /* not implemented (non-ephemeral DH) */
        TLS1_TXT_DH_RSA_WITH_CAMELLIA_256_CBC_SHA,
        TLS1_CK_DH_RSA_WITH_CAMELLIA_256_CBC_SHA,
-       SSL_kDHr|SSL_aDH|SSL_CAMELLIA|SSL_SHA|SSL_TLSV1,
+       SSL_kDHr,
+       SSL_aDH,
+       SSL_CAMELLIA256,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_HIGH,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        256,
        256,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS
        },
+
        /* Cipher 87 */
        {
        1,
        TLS1_TXT_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA,
        TLS1_CK_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA,
-       SSL_kEDH|SSL_aDSS|SSL_CAMELLIA|SSL_SHA|SSL_TLSV1,
+       SSL_kEDH,
+       SSL_aDSS,
+       SSL_CAMELLIA256,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_HIGH,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        256,
        256,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS
        },
+
        /* Cipher 88 */
        {
        1,
        TLS1_TXT_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA,
        TLS1_CK_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA,
-       SSL_kEDH|SSL_aRSA|SSL_CAMELLIA|SSL_SHA|SSL_TLSV1,
+       SSL_kEDH,
+       SSL_aRSA,
+       SSL_CAMELLIA256,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_HIGH,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        256,
        256,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS
        },
+
        /* Cipher 89 */
        {
        1,
        TLS1_TXT_ADH_WITH_CAMELLIA_256_CBC_SHA,
        TLS1_CK_ADH_WITH_CAMELLIA_256_CBC_SHA,
-       SSL_kEDH|SSL_aNULL|SSL_CAMELLIA|SSL_SHA|SSL_TLSV1,
+       SSL_kEDH,
+       SSL_aNULL,
+       SSL_CAMELLIA256,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_HIGH,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        256,
        256,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS
        },
 #endif /* OPENSSL_NO_CAMELLIA */
 
+#ifndef OPENSSL_NO_PSK
+       /* Cipher 8A */
+       {
+       1,
+       TLS1_TXT_PSK_WITH_RC4_128_SHA,
+       TLS1_CK_PSK_WITH_RC4_128_SHA,
+       SSL_kPSK,
+       SSL_aPSK,
+       SSL_RC4,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_MEDIUM,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       128,
+       128,
+       },
+
+       /* Cipher 8B */
+       {
+       1,
+       TLS1_TXT_PSK_WITH_3DES_EDE_CBC_SHA,
+       TLS1_CK_PSK_WITH_3DES_EDE_CBC_SHA,
+       SSL_kPSK,
+       SSL_aPSK,
+       SSL_3DES,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_HIGH,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       168,
+       168,
+       },
+
+       /* Cipher 8C */
+       {
+       1,
+       TLS1_TXT_PSK_WITH_AES_128_CBC_SHA,
+       TLS1_CK_PSK_WITH_AES_128_CBC_SHA,
+       SSL_kPSK,
+       SSL_aPSK,
+       SSL_AES128,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_HIGH,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       128,
+       128,
+       },
+
+       /* Cipher 8D */
+       {
+       1,
+       TLS1_TXT_PSK_WITH_AES_256_CBC_SHA,
+       TLS1_CK_PSK_WITH_AES_256_CBC_SHA,
+       SSL_kPSK,
+       SSL_aPSK,
+       SSL_AES256,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_HIGH,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       256,
+       256,
+       },
+#endif  /* OPENSSL_NO_PSK */
+
 #ifndef OPENSSL_NO_SEED
        /* SEED ciphersuites from RFC4162 */
 
@@ -1170,13 +1517,15 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        1,
        TLS1_TXT_RSA_WITH_SEED_SHA,
        TLS1_CK_RSA_WITH_SEED_SHA,
-       SSL_kRSA|SSL_aRSA|SSL_SEED|SSL_SHA1|SSL_TLSV1,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_SEED,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_MEDIUM,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
        /* Cipher 97 */
@@ -1184,13 +1533,15 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        0, /* not implemented (non-ephemeral DH) */
        TLS1_TXT_DH_DSS_WITH_SEED_SHA,
        TLS1_CK_DH_DSS_WITH_SEED_SHA,
-       SSL_kDHd|SSL_aDH|SSL_SEED|SSL_SHA1|SSL_TLSV1,
+       SSL_kDHd,
+       SSL_aDH,
+       SSL_SEED,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_MEDIUM,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
        /* Cipher 98 */
@@ -1198,13 +1549,15 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        0, /* not implemented (non-ephemeral DH) */
        TLS1_TXT_DH_RSA_WITH_SEED_SHA,
        TLS1_CK_DH_RSA_WITH_SEED_SHA,
-       SSL_kDHr|SSL_aDH|SSL_SEED|SSL_SHA1|SSL_TLSV1,
+       SSL_kDHr,
+       SSL_aDH,
+       SSL_SEED,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_MEDIUM,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
        /* Cipher 99 */
@@ -1212,13 +1565,15 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        1,
        TLS1_TXT_DHE_DSS_WITH_SEED_SHA,
        TLS1_CK_DHE_DSS_WITH_SEED_SHA,
-       SSL_kEDH|SSL_aDSS|SSL_SEED|SSL_SHA1|SSL_TLSV1,
+       SSL_kEDH,
+       SSL_aDSS,
+       SSL_SEED,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_MEDIUM,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
        /* Cipher 9A */
@@ -1226,13 +1581,15 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        1,
        TLS1_TXT_DHE_RSA_WITH_SEED_SHA,
        TLS1_CK_DHE_RSA_WITH_SEED_SHA,
-       SSL_kEDH|SSL_aRSA|SSL_SEED|SSL_SHA1|SSL_TLSV1,
+       SSL_kEDH,
+       SSL_aRSA,
+       SSL_SEED,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_MEDIUM,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
        /* Cipher 9B */
@@ -1240,376 +1597,487 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
        1,
        TLS1_TXT_ADH_WITH_SEED_SHA,
        TLS1_CK_ADH_WITH_SEED_SHA,
-       SSL_kEDH|SSL_aNULL|SSL_SEED|SSL_SHA1|SSL_TLSV1,
+       SSL_kEDH,
+       SSL_aNULL,
+       SSL_SEED,
+       SSL_SHA1,
+       SSL_TLSV1,
        SSL_NOT_EXP|SSL_MEDIUM,
-       0,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
        128,
        128,
-       SSL_ALL_CIPHERS,
-       SSL_ALL_STRENGTHS,
        },
 
 #endif /* OPENSSL_NO_SEED */
 
 #ifndef OPENSSL_NO_ECDH
        /* Cipher C001 */
-           {
-            1,
-            TLS1_TXT_ECDH_ECDSA_WITH_NULL_SHA,
-            TLS1_CK_ECDH_ECDSA_WITH_NULL_SHA,
-            SSL_kECDH|SSL_aECDSA|SSL_eNULL|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP,
-            0,
-            0,
-            0,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-            },
+       {
+       1,
+       TLS1_TXT_ECDH_ECDSA_WITH_NULL_SHA,
+       TLS1_CK_ECDH_ECDSA_WITH_NULL_SHA,
+       SSL_kECDHe,
+       SSL_aECDH,
+       SSL_eNULL,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_STRONG_NONE,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       0,
+       0,
+       },
 
        /* Cipher C002 */
-           {
-            1,
-            TLS1_TXT_ECDH_ECDSA_WITH_RC4_128_SHA,
-            TLS1_CK_ECDH_ECDSA_WITH_RC4_128_SHA,
-            SSL_kECDH|SSL_aECDSA|SSL_RC4|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP,
-            0,
-            128,
-            128,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-            },
+       {
+       1,
+       TLS1_TXT_ECDH_ECDSA_WITH_RC4_128_SHA,
+       TLS1_CK_ECDH_ECDSA_WITH_RC4_128_SHA,
+       SSL_kECDHe,
+       SSL_aECDH,
+       SSL_RC4,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_MEDIUM,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       128,
+       128,
+       },
 
        /* Cipher C003 */
-           {
-            1,
-            TLS1_TXT_ECDH_ECDSA_WITH_DES_192_CBC3_SHA,
-            TLS1_CK_ECDH_ECDSA_WITH_DES_192_CBC3_SHA,
-            SSL_kECDH|SSL_aECDSA|SSL_3DES|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP|SSL_HIGH,
-            0,
-            168,
-            168,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-            },
+       {
+       1,
+       TLS1_TXT_ECDH_ECDSA_WITH_DES_192_CBC3_SHA,
+       TLS1_CK_ECDH_ECDSA_WITH_DES_192_CBC3_SHA,
+       SSL_kECDHe,
+       SSL_aECDH,
+       SSL_3DES,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_HIGH,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       168,
+       168,
+       },
 
        /* Cipher C004 */
-           {
-            1,
-            TLS1_TXT_ECDH_ECDSA_WITH_AES_128_CBC_SHA,
-            TLS1_CK_ECDH_ECDSA_WITH_AES_128_CBC_SHA,
-            SSL_kECDH|SSL_aECDSA|SSL_AES|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP|SSL_HIGH,
-            0,
-            128,
-            128,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-            },
+       {
+       1,
+       TLS1_TXT_ECDH_ECDSA_WITH_AES_128_CBC_SHA,
+       TLS1_CK_ECDH_ECDSA_WITH_AES_128_CBC_SHA,
+       SSL_kECDHe,
+       SSL_aECDH,
+       SSL_AES128,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_HIGH,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       128,
+       128,
+       },
 
        /* Cipher C005 */
-           {
-            1,
-            TLS1_TXT_ECDH_ECDSA_WITH_AES_256_CBC_SHA,
-            TLS1_CK_ECDH_ECDSA_WITH_AES_256_CBC_SHA,
-            SSL_kECDH|SSL_aECDSA|SSL_AES|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP|SSL_HIGH,
-            0,
-            256,
-            256,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-            },
+       {
+       1,
+       TLS1_TXT_ECDH_ECDSA_WITH_AES_256_CBC_SHA,
+       TLS1_CK_ECDH_ECDSA_WITH_AES_256_CBC_SHA,
+       SSL_kECDHe,
+       SSL_aECDH,
+       SSL_AES256,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_HIGH,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       256,
+       256,
+       },
 
        /* Cipher C006 */
-           {
-            1,
-            TLS1_TXT_ECDHE_ECDSA_WITH_NULL_SHA,
-            TLS1_CK_ECDHE_ECDSA_WITH_NULL_SHA,
-            SSL_kECDHE|SSL_aECDSA|SSL_eNULL|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP,
-            0,
-            0,
-            0,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-            },
+       {
+       1,
+       TLS1_TXT_ECDHE_ECDSA_WITH_NULL_SHA,
+       TLS1_CK_ECDHE_ECDSA_WITH_NULL_SHA,
+       SSL_kEECDH,
+       SSL_aECDSA,
+       SSL_eNULL,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_STRONG_NONE,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       0,
+       0,
+       },
 
        /* Cipher C007 */
-           {
-            1,
-            TLS1_TXT_ECDHE_ECDSA_WITH_RC4_128_SHA,
-            TLS1_CK_ECDHE_ECDSA_WITH_RC4_128_SHA,
-            SSL_kECDHE|SSL_aECDSA|SSL_RC4|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP,
-            0,
-            128,
-            128,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-            },
+       {
+       1,
+       TLS1_TXT_ECDHE_ECDSA_WITH_RC4_128_SHA,
+       TLS1_CK_ECDHE_ECDSA_WITH_RC4_128_SHA,
+       SSL_kEECDH,
+       SSL_aECDSA,
+       SSL_RC4,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_MEDIUM,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       128,
+       128,
+       },
 
        /* Cipher C008 */
-           {
-            1,
-            TLS1_TXT_ECDHE_ECDSA_WITH_DES_192_CBC3_SHA,
-            TLS1_CK_ECDHE_ECDSA_WITH_DES_192_CBC3_SHA,
-            SSL_kECDHE|SSL_aECDSA|SSL_3DES|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP|SSL_HIGH,
-            0,
-            168,
-            168,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-            },
+       {
+       1,
+       TLS1_TXT_ECDHE_ECDSA_WITH_DES_192_CBC3_SHA,
+       TLS1_CK_ECDHE_ECDSA_WITH_DES_192_CBC3_SHA,
+       SSL_kEECDH,
+       SSL_aECDSA,
+       SSL_3DES,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_HIGH,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       168,
+       168,
+       },
 
        /* Cipher C009 */
-           {
-            1,
-            TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
-            TLS1_CK_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
-            SSL_kECDHE|SSL_aECDSA|SSL_AES|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP|SSL_HIGH,
-            0,
-            128,
-            128,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-            },
+       {
+       1,
+       TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
+       TLS1_CK_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
+       SSL_kEECDH,
+       SSL_aECDSA,
+       SSL_AES128,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_HIGH,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       128,
+       128,
+       },
 
        /* Cipher C00A */
-           {
-            1,
-            TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
-            TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
-            SSL_kECDHE|SSL_aECDSA|SSL_AES|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP|SSL_HIGH,
-            0,
-            256,
-            256,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-            },
+       {
+       1,
+       TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
+       TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
+       SSL_kEECDH,
+       SSL_aECDSA,
+       SSL_AES256,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_HIGH,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       256,
+       256,
+       },
 
        /* Cipher C00B */
-           {
-            1,
-            TLS1_TXT_ECDH_RSA_WITH_NULL_SHA,
-            TLS1_CK_ECDH_RSA_WITH_NULL_SHA,
-            SSL_kECDH|SSL_aRSA|SSL_eNULL|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP,
-            0,
-            0,
-            0,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-            },
+       {
+       1,
+       TLS1_TXT_ECDH_RSA_WITH_NULL_SHA,
+       TLS1_CK_ECDH_RSA_WITH_NULL_SHA,
+       SSL_kECDHr,
+       SSL_aECDH,
+       SSL_eNULL,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_STRONG_NONE,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       0,
+       0,
+       },
 
        /* Cipher C00C */
-           {
-            1,
-            TLS1_TXT_ECDH_RSA_WITH_RC4_128_SHA,
-            TLS1_CK_ECDH_RSA_WITH_RC4_128_SHA,
-            SSL_kECDH|SSL_aRSA|SSL_RC4|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP,
-            0,
-            128,
-            128,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-            },
+       {
+       1,
+       TLS1_TXT_ECDH_RSA_WITH_RC4_128_SHA,
+       TLS1_CK_ECDH_RSA_WITH_RC4_128_SHA,
+       SSL_kECDHr,
+       SSL_aECDH,
+       SSL_RC4,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_MEDIUM,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       128,
+       128,
+       },
 
        /* Cipher C00D */
-           {
-            1,
-            TLS1_TXT_ECDH_RSA_WITH_DES_192_CBC3_SHA,
-            TLS1_CK_ECDH_RSA_WITH_DES_192_CBC3_SHA,
-            SSL_kECDH|SSL_aRSA|SSL_3DES|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP|SSL_HIGH,
-            0,
-            168,
-            168,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-            },
+       {
+       1,
+       TLS1_TXT_ECDH_RSA_WITH_DES_192_CBC3_SHA,
+       TLS1_CK_ECDH_RSA_WITH_DES_192_CBC3_SHA,
+       SSL_kECDHr,
+       SSL_aECDH,
+       SSL_3DES,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_HIGH,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       168,
+       168,
+       },
 
        /* Cipher C00E */
-           {
-            1,
-            TLS1_TXT_ECDH_RSA_WITH_AES_128_CBC_SHA,
-            TLS1_CK_ECDH_RSA_WITH_AES_128_CBC_SHA,
-            SSL_kECDH|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP|SSL_HIGH,
-            0,
-            128,
-            128,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-            },
+       {
+       1,
+       TLS1_TXT_ECDH_RSA_WITH_AES_128_CBC_SHA,
+       TLS1_CK_ECDH_RSA_WITH_AES_128_CBC_SHA,
+       SSL_kECDHr,
+       SSL_aECDH,
+       SSL_AES128,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_HIGH,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       128,
+       128,
+       },
 
        /* Cipher C00F */
-           {
-            1,
-            TLS1_TXT_ECDH_RSA_WITH_AES_256_CBC_SHA,
-            TLS1_CK_ECDH_RSA_WITH_AES_256_CBC_SHA,
-            SSL_kECDH|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP|SSL_HIGH,
-            0,
-            256,
-            256,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-            },
+       {
+       1,
+       TLS1_TXT_ECDH_RSA_WITH_AES_256_CBC_SHA,
+       TLS1_CK_ECDH_RSA_WITH_AES_256_CBC_SHA,
+       SSL_kECDHr,
+       SSL_aECDH,
+       SSL_AES256,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_HIGH,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       256,
+       256,
+       },
 
        /* Cipher C010 */
-           {
-            1,
-            TLS1_TXT_ECDHE_RSA_WITH_NULL_SHA,
-            TLS1_CK_ECDHE_RSA_WITH_NULL_SHA,
-            SSL_kECDHE|SSL_aRSA|SSL_eNULL|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP,
-            0,
-            0,
-            0,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-            },
+       {
+       1,
+       TLS1_TXT_ECDHE_RSA_WITH_NULL_SHA,
+       TLS1_CK_ECDHE_RSA_WITH_NULL_SHA,
+       SSL_kEECDH,
+       SSL_aRSA,
+       SSL_eNULL,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_STRONG_NONE,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       0,
+       0,
+       },
 
        /* Cipher C011 */
-           {
-            1,
-            TLS1_TXT_ECDHE_RSA_WITH_RC4_128_SHA,
-            TLS1_CK_ECDHE_RSA_WITH_RC4_128_SHA,
-            SSL_kECDHE|SSL_aRSA|SSL_RC4|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP,
-            0,
-            128,
-            128,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-            },
+       {
+       1,
+       TLS1_TXT_ECDHE_RSA_WITH_RC4_128_SHA,
+       TLS1_CK_ECDHE_RSA_WITH_RC4_128_SHA,
+       SSL_kEECDH,
+       SSL_aRSA,
+       SSL_RC4,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_MEDIUM,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       128,
+       128,
+       },
 
        /* Cipher C012 */
-           {
-            1,
-            TLS1_TXT_ECDHE_RSA_WITH_DES_192_CBC3_SHA,
-            TLS1_CK_ECDHE_RSA_WITH_DES_192_CBC3_SHA,
-            SSL_kECDHE|SSL_aRSA|SSL_3DES|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP|SSL_HIGH,
-            0,
-            168,
-            168,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-            },
+       {
+       1,
+       TLS1_TXT_ECDHE_RSA_WITH_DES_192_CBC3_SHA,
+       TLS1_CK_ECDHE_RSA_WITH_DES_192_CBC3_SHA,
+       SSL_kEECDH,
+       SSL_aRSA,
+       SSL_3DES,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_HIGH,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       168,
+       168,
+       },
 
        /* Cipher C013 */
-           {
-            1,
-            TLS1_TXT_ECDHE_RSA_WITH_AES_128_CBC_SHA,
-            TLS1_CK_ECDHE_RSA_WITH_AES_128_CBC_SHA,
-            SSL_kECDHE|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP|SSL_HIGH,
-            0,
-            128,
-            128,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-            },
+       {
+       1,
+       TLS1_TXT_ECDHE_RSA_WITH_AES_128_CBC_SHA,
+       TLS1_CK_ECDHE_RSA_WITH_AES_128_CBC_SHA,
+       SSL_kEECDH,
+       SSL_aRSA,
+       SSL_AES128,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_HIGH,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       128,
+       128,
+       },
 
        /* Cipher C014 */
-           {
-            1,
-            TLS1_TXT_ECDHE_RSA_WITH_AES_256_CBC_SHA,
-            TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA,
-            SSL_kECDHE|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP|SSL_HIGH,
-            0,
-            256,
-            256,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-            },
+       {
+       1,
+       TLS1_TXT_ECDHE_RSA_WITH_AES_256_CBC_SHA,
+       TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA,
+       SSL_kEECDH,
+       SSL_aRSA,
+       SSL_AES256,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_HIGH,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       256,
+       256,
+       },
 
        /* Cipher C015 */
-            {
-            1,
-            TLS1_TXT_ECDH_anon_WITH_NULL_SHA,
-            TLS1_CK_ECDH_anon_WITH_NULL_SHA,
-            SSL_kECDHE|SSL_aNULL|SSL_eNULL|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP,
-            0,
-            0,
-            0,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-           },
+       {
+       1,
+       TLS1_TXT_ECDH_anon_WITH_NULL_SHA,
+       TLS1_CK_ECDH_anon_WITH_NULL_SHA,
+       SSL_kEECDH,
+       SSL_aNULL,
+       SSL_eNULL,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_STRONG_NONE,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       0,
+       0,
+       },
 
        /* Cipher C016 */
-            {
-            1,
-            TLS1_TXT_ECDH_anon_WITH_RC4_128_SHA,
-            TLS1_CK_ECDH_anon_WITH_RC4_128_SHA,
-            SSL_kECDHE|SSL_aNULL|SSL_RC4|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP,
-            0,
-            128,
-            128,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-           },
+       {
+       1,
+       TLS1_TXT_ECDH_anon_WITH_RC4_128_SHA,
+       TLS1_CK_ECDH_anon_WITH_RC4_128_SHA,
+       SSL_kEECDH,
+       SSL_aNULL,
+       SSL_RC4,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_MEDIUM,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       128,
+       128,
+       },
 
        /* Cipher C017 */
-           {
-            1,
-            TLS1_TXT_ECDH_anon_WITH_DES_192_CBC3_SHA,
-            TLS1_CK_ECDH_anon_WITH_DES_192_CBC3_SHA,
-            SSL_kECDHE|SSL_aNULL|SSL_3DES|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP|SSL_HIGH,
-            0,
-            168,
-            168,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-            },
+       {
+       1,
+       TLS1_TXT_ECDH_anon_WITH_DES_192_CBC3_SHA,
+       TLS1_CK_ECDH_anon_WITH_DES_192_CBC3_SHA,
+       SSL_kEECDH,
+       SSL_aNULL,
+       SSL_3DES,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_HIGH,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       168,
+       168,
+       },
 
        /* Cipher C018 */
-           {
-            1,
-            TLS1_TXT_ECDH_anon_WITH_AES_128_CBC_SHA,
-            TLS1_CK_ECDH_anon_WITH_AES_128_CBC_SHA,
-            SSL_kECDHE|SSL_aNULL|SSL_AES|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP|SSL_HIGH,
-            0,
-            128,
-            128,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-            },
+       {
+       1,
+       TLS1_TXT_ECDH_anon_WITH_AES_128_CBC_SHA,
+       TLS1_CK_ECDH_anon_WITH_AES_128_CBC_SHA,
+       SSL_kEECDH,
+       SSL_aNULL,
+       SSL_AES128,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_HIGH,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       128,
+       128,
+       },
 
        /* Cipher C019 */
-           {
-            1,
-            TLS1_TXT_ECDH_anon_WITH_AES_256_CBC_SHA,
-            TLS1_CK_ECDH_anon_WITH_AES_256_CBC_SHA,
-            SSL_kECDHE|SSL_aNULL|SSL_AES|SSL_SHA|SSL_TLSV1,
-            SSL_NOT_EXP|SSL_HIGH,
-            0,
-            256,
-            256,
-            SSL_ALL_CIPHERS,
-            SSL_ALL_STRENGTHS,
-            },
+       {
+       1,
+       TLS1_TXT_ECDH_anon_WITH_AES_256_CBC_SHA,
+       TLS1_CK_ECDH_anon_WITH_AES_256_CBC_SHA,
+       SSL_kEECDH,
+       SSL_aNULL,
+       SSL_AES256,
+       SSL_SHA1,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_HIGH,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       256,
+       256,
+       },
 #endif /* OPENSSL_NO_ECDH */
 
+#ifdef TEMP_GOST_TLS
+/* Cipher FF00 */
+       {
+       1,
+       "GOST-MD5",
+       0x0300ff00,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_eGOST2814789CNT,
+       SSL_MD5,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_HIGH,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       256,
+       256,
+       },
+       {
+       1,
+       "GOST-GOST94",
+       0x0300ff01,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_eGOST2814789CNT,
+       SSL_GOST94,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_HIGH,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       256,
+       256
+       },
+       {
+       1,
+       "GOST-GOST89MAC",
+       0x0300ff02,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_eGOST2814789CNT,
+       SSL_GOST89MAC,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_HIGH,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
+       256,
+       256
+       },
+       {
+       1,
+       "GOST-GOST89STREAM",
+       0x0300ff03,
+       SSL_kRSA,
+       SSL_aRSA,
+       SSL_eGOST2814789CNT,
+       SSL_GOST89MAC,
+       SSL_TLSV1,
+       SSL_NOT_EXP|SSL_HIGH,
+       SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF|TLS1_STREAM_MAC,
+       256,
+       256
+       },
+#endif
 
 /* end of list */
        };
 
 SSL3_ENC_METHOD SSLv3_enc_data={
        ssl3_enc,
-       ssl3_mac,
+       n_ssl3_mac,
        ssl3_setup_key_block,
        ssl3_generate_master_secret,
        ssl3_change_cipher_state,
@@ -1619,6 +2087,9 @@ SSL3_ENC_METHOD SSLv3_enc_data={
        SSL3_MD_CLIENT_FINISHED_CONST,4,
        SSL3_MD_SERVER_FINISHED_CONST,4,
        ssl3_alert_code,
+       (int (*)(SSL *, unsigned char *, size_t, const char *,
+                size_t, const unsigned char *, size_t,
+                int use_context)) ssl_undefined_function,
        };
 
 long ssl3_default_timeout(void)
@@ -1628,17 +2099,12 @@ long ssl3_default_timeout(void)
        return(60*60*2);
        }
 
-IMPLEMENT_ssl3_meth_func(sslv3_base_method,
-                       ssl_undefined_function,
-                       ssl_undefined_function,
-                       ssl_bad_method)
-
 int ssl3_num_ciphers(void)
        {
        return(SSL3_NUM_CIPHERS);
        }
 
-SSL_CIPHER *ssl3_get_cipher(unsigned int u)
+const SSL_CIPHER *ssl3_get_cipher(unsigned int u)
        {
        if (u < SSL3_NUM_CIPHERS)
                return(&(ssl3_ciphers[SSL3_NUM_CIPHERS-1-u]));
@@ -1660,10 +2126,8 @@ int ssl3_new(SSL *s)
 
        if ((s3=OPENSSL_malloc(sizeof *s3)) == NULL) goto err;
        memset(s3,0,sizeof *s3);
-       EVP_MD_CTX_init(&s3->finish_dgst1);
-       EVP_MD_CTX_init(&s3->finish_dgst2);
-       pq_64bit_init(&(s3->rrec.seq_num));
-       pq_64bit_init(&(s3->wrec.seq_num));
+       memset(s3->rrec.seq_num,0,sizeof(s3->rrec.seq_num));
+       memset(s3->wrec.seq_num,0,sizeof(s3->wrec.seq_num));
 
        s->s3=s3;
 
@@ -1678,11 +2142,18 @@ void ssl3_free(SSL *s)
        if(s == NULL)
            return;
 
+#ifdef TLSEXT_TYPE_opaque_prf_input
+       if (s->s3->client_opaque_prf_input != NULL)
+               OPENSSL_free(s->s3->client_opaque_prf_input);
+       if (s->s3->server_opaque_prf_input != NULL)
+               OPENSSL_free(s->s3->server_opaque_prf_input);
+#endif
+
        ssl3_cleanup_key_block(s);
        if (s->s3->rbuf.buf != NULL)
-               OPENSSL_free(s->s3->rbuf.buf);
+               ssl3_release_read_buffer(s);
        if (s->s3->wbuf.buf != NULL)
-               OPENSSL_free(s->s3->wbuf.buf);
+               ssl3_release_write_buffer(s);
        if (s->s3->rrec.comp != NULL)
                OPENSSL_free(s->s3->rrec.comp);
 #ifndef OPENSSL_NO_DH
@@ -1696,17 +2167,10 @@ void ssl3_free(SSL *s)
 
        if (s->s3->tmp.ca_names != NULL)
                sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free);
-       EVP_MD_CTX_cleanup(&s->s3->finish_dgst1);
-       EVP_MD_CTX_cleanup(&s->s3->finish_dgst2);
-       pq_64bit_free(&(s->s3->rrec.seq_num));
-       pq_64bit_free(&(s->s3->wrec.seq_num));
-
-       if (s->s3->snap_start_client_hello.buf)
-               {
-               /* s->s3->snap_start_records, if set, uses the same buffer */
-               OPENSSL_free(s->s3->snap_start_client_hello.buf);
-               }
-
+       if (s->s3->handshake_buffer) {
+               BIO_free(s->s3->handshake_buffer);
+       }
+       if (s->s3->handshake_dgst) ssl3_free_digest_list(s);
        OPENSSL_cleanse(s->s3,sizeof *s->s3);
        OPENSSL_free(s->s3);
        s->s3=NULL;
@@ -1716,6 +2180,16 @@ void ssl3_clear(SSL *s)
        {
        unsigned char *rp,*wp;
        size_t rlen, wlen;
+       int init_extra;
+
+#ifdef TLSEXT_TYPE_opaque_prf_input
+       if (s->s3->client_opaque_prf_input != NULL)
+               OPENSSL_free(s->s3->client_opaque_prf_input);
+       s->s3->client_opaque_prf_input = NULL;
+       if (s->s3->server_opaque_prf_input != NULL)
+               OPENSSL_free(s->s3->server_opaque_prf_input);
+       s->s3->server_opaque_prf_input = NULL;
+#endif
 
        ssl3_cleanup_key_block(s);
        if (s->s3->tmp.ca_names != NULL)
@@ -1728,26 +2202,37 @@ void ssl3_clear(SSL *s)
                }
 #ifndef OPENSSL_NO_DH
        if (s->s3->tmp.dh != NULL)
+               {
                DH_free(s->s3->tmp.dh);
+               s->s3->tmp.dh = NULL;
+               }
 #endif
 #ifndef OPENSSL_NO_ECDH
        if (s->s3->tmp.ecdh != NULL)
+               {
                EC_KEY_free(s->s3->tmp.ecdh);
+               s->s3->tmp.ecdh = NULL;
+               }
 #endif
 
        rp = s->s3->rbuf.buf;
        wp = s->s3->wbuf.buf;
        rlen = s->s3->rbuf.len;
        wlen = s->s3->wbuf.len;
-
-       EVP_MD_CTX_cleanup(&s->s3->finish_dgst1);
-       EVP_MD_CTX_cleanup(&s->s3->finish_dgst2);
-
+       init_extra = s->s3->init_extra;
+       if (s->s3->handshake_buffer) {
+               BIO_free(s->s3->handshake_buffer);
+               s->s3->handshake_buffer = NULL;
+       }
+       if (s->s3->handshake_dgst) {
+               ssl3_free_digest_list(s);
+       }       
        memset(s->s3,0,sizeof *s->s3);
        s->s3->rbuf.buf = rp;
        s->s3->wbuf.buf = wp;
        s->s3->rbuf.len = rlen;
        s->s3->wbuf.len = wlen;
+       s->s3->init_extra = init_extra;
 
        ssl_free_wbio_buffer(s);
 
@@ -1758,12 +2243,13 @@ void ssl3_clear(SSL *s)
        s->s3->in_read_app_data=0;
        s->version=SSL3_VERSION;
 
-#ifndef OPENSSL_NO_TLSEXT
-       if (s->next_proto_negotiated) {
+#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
+       if (s->next_proto_negotiated)
+               {
                OPENSSL_free(s->next_proto_negotiated);
-               s->next_proto_negotiated = 0;
+               s->next_proto_negotiated = NULL;
                s->next_proto_negotiated_len = 0;
-       }
+               }
 #endif
        }
 
@@ -1950,7 +2436,31 @@ long ssl3_ctrl(SSL *s, int cmd, long larg, void *parg)
                s->tlsext_debug_arg=parg;
                ret = 1;
                break;
-  
+
+#ifdef TLSEXT_TYPE_opaque_prf_input
+       case SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT:
+               if (larg > 12288) /* actual internal limit is 2^16 for the complete hello message
+                                  * (including the cert chain and everything) */
+                       {
+                       SSLerr(SSL_F_SSL3_CTRL, SSL_R_OPAQUE_PRF_INPUT_TOO_LONG);
+                       break;
+                       }
+               if (s->tlsext_opaque_prf_input != NULL)
+                       OPENSSL_free(s->tlsext_opaque_prf_input);
+               if ((size_t)larg == 0)
+                       s->tlsext_opaque_prf_input = OPENSSL_malloc(1); /* dummy byte just to get non-NULL */
+               else
+                       s->tlsext_opaque_prf_input = BUF_memdup(parg, (size_t)larg);
+               if (s->tlsext_opaque_prf_input != NULL)
+                       {
+                       s->tlsext_opaque_prf_input_len = (size_t)larg;
+                       ret = 1;
+                       }
+               else
+                       s->tlsext_opaque_prf_input_len = 0;
+               break;
+#endif
+
        case SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE:
                s->tlsext_status_type=larg;
                ret = 1;
@@ -2208,13 +2718,20 @@ long ssl3_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg)
                        }
                return 1;
                }
-  
+
+#ifdef TLSEXT_TYPE_opaque_prf_input
+       case SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB_ARG:
+               ctx->tlsext_opaque_prf_input_callback_arg = parg;
+               return 1;
+#endif
+
        case SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG:
                ctx->tlsext_status_arg=parg;
                return 1;
                break;
 
 #endif /* !OPENSSL_NO_TLSEXT */
+
        /* A Thawte special :-) */
        case SSL_CTRL_EXTRA_CHAIN_CERT:
                if (ctx->extra_certs == NULL)
@@ -2264,7 +2781,13 @@ long ssl3_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)(void))
        case SSL_CTRL_SET_TLSEXT_SERVERNAME_CB:
                ctx->tlsext_servername_callback=(int (*)(SSL *,int *,void *))fp;
                break;
-  
+
+#ifdef TLSEXT_TYPE_opaque_prf_input
+       case SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB:
+               ctx->tlsext_opaque_prf_input_callback = (int (*)(SSL *,void *, size_t, void *))fp;
+               break;
+#endif
+
        case SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB:
                ctx->tlsext_status_cb=(int (*)(SSL *,void *))fp;
                break;
@@ -2285,17 +2808,15 @@ long ssl3_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)(void))
 
 /* This function needs to check if the ciphers required are actually
  * available */
-SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p)
+const SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p)
        {
-       SSL_CIPHER c,*cp;
+       SSL_CIPHER c;
+       const SSL_CIPHER *cp;
        unsigned long id;
 
        id=0x03000000L|((unsigned long)p[0]<<8L)|(unsigned long)p[1];
        c.id=id;
-       cp = (SSL_CIPHER *)OBJ_bsearch((char *)&c,
-               (char *)ssl3_ciphers,
-               SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER),
-               FP_ICC ssl_cipher_id_cmp);
+       cp = OBJ_bsearch_ssl_cipher_id(&c, ssl3_ciphers, SSL3_NUM_CIPHERS);
        if (cp == NULL || cp->valid == 0)
                return NULL;
        else
@@ -2321,10 +2842,14 @@ SSL_CIPHER *ssl3_choose_cipher(SSL *s, STACK_OF(SSL_CIPHER) *clnt,
        {
        SSL_CIPHER *c,*ret=NULL;
        STACK_OF(SSL_CIPHER) *prio, *allow;
-       int i,j,ok;
-
+       int i,ii,ok;
+#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_EC)
+       unsigned int j;
+       int ec_ok, ec_nid;
+       unsigned char ec_search1 = 0, ec_search2 = 0;
+#endif
        CERT *cert;
-       unsigned long alg,mask,emask;
+       unsigned long alg_k,alg_a,mask_k,mask_a,emask_k,emask_a;
 
        /* Let's see which ciphers we can support */
        cert=s->cert;
@@ -2340,73 +2865,237 @@ SSL_CIPHER *ssl3_choose_cipher(SSL *s, STACK_OF(SSL_CIPHER) *clnt,
 #endif
 
 #ifdef CIPHER_DEBUG
-        printf("Server has %d from %p:\n", sk_SSL_CIPHER_num(srvr), srvr);
-        for(i=0 ; i < sk_SSL_CIPHER_num(srvr) ; ++i)
-           {
-           c=sk_SSL_CIPHER_value(srvr,i);
-           printf("%p:%s\n",c,c->name);
-           }
-        printf("Client sent %d from %p:\n", sk_SSL_CIPHER_num(clnt), clnt);
-        for(i=0 ; i < sk_SSL_CIPHER_num(clnt) ; ++i)
+       printf("Server has %d from %p:\n", sk_SSL_CIPHER_num(srvr), (void *)srvr);
+       for(i=0 ; i < sk_SSL_CIPHER_num(srvr) ; ++i)
+               {
+               c=sk_SSL_CIPHER_value(srvr,i);
+               printf("%p:%s\n",(void *)c,c->name);
+               }
+       printf("Client sent %d from %p:\n", sk_SSL_CIPHER_num(clnt), (void *)clnt);
+       for(i=0 ; i < sk_SSL_CIPHER_num(clnt) ; ++i)
            {
            c=sk_SSL_CIPHER_value(clnt,i);
-           printf("%p:%s\n",c,c->name);
+           printf("%p:%s\n",(void *)c,c->name);
            }
 #endif
 
        if (s->options & SSL_OP_CIPHER_SERVER_PREFERENCE)
-           {
-           prio = srvr;
-           allow = clnt;
-           }
+               {
+               prio = srvr;
+               allow = clnt;
+               }
        else
-           {
-           prio = clnt;
-           allow = srvr;
-           }
+               {
+               prio = clnt;
+               allow = srvr;
+               }
 
        for (i=0; i<sk_SSL_CIPHER_num(prio); i++)
                {
                c=sk_SSL_CIPHER_value(prio,i);
 
                ssl_set_cert_masks(cert,c);
-               mask=cert->mask;
-               emask=cert->export_mask;
+               mask_k = cert->mask_k;
+               mask_a = cert->mask_a;
+               emask_k = cert->export_mask_k;
+               emask_a = cert->export_mask_a;
                        
 #ifdef KSSL_DEBUG
-               printf("ssl3_choose_cipher %d alg= %lx\n", i,c->algorithms);
+/*             printf("ssl3_choose_cipher %d alg= %lx\n", i,c->algorithms);*/
 #endif    /* KSSL_DEBUG */
 
-               alg=c->algorithms&(SSL_MKEY_MASK|SSL_AUTH_MASK);
+               alg_k=c->algorithm_mkey;
+               alg_a=c->algorithm_auth;
+
 #ifndef OPENSSL_NO_KRB5
-                if (alg & SSL_KRB5) 
-                        {
-                        if ( !kssl_keytab_is_available(s->kssl_ctx) )
-                            continue;
-                        }
+               if (alg_k & SSL_kKRB5)
+                       {
+                       if ( !kssl_keytab_is_available(s->kssl_ctx) )
+                           continue;
+                       }
 #endif /* OPENSSL_NO_KRB5 */
+#ifndef OPENSSL_NO_PSK
+               /* with PSK there must be server callback set */
+               if ((alg_k & SSL_kPSK) && s->psk_server_callback == NULL)
+                       continue;
+#endif /* OPENSSL_NO_PSK */
+
                if (SSL_C_IS_EXPORT(c))
                        {
-                       ok=((alg & emask) == alg)?1:0;
+                       ok = (alg_k & emask_k) && (alg_a & emask_a);
 #ifdef CIPHER_DEBUG
-                       printf("%d:[%08lX:%08lX]%p:%s (export)\n",ok,alg,emask,
-                              c,c->name);
+                       printf("%d:[%08lX:%08lX:%08lX:%08lX]%p:%s (export)\n",ok,alg_k,alg_a,emask_k,emask_a,
+                              (void *)c,c->name);
 #endif
                        }
                else
                        {
-                       ok=((alg & mask) == alg)?1:0;
+                       ok = (alg_k & mask_k) && (alg_a & mask_a);
 #ifdef CIPHER_DEBUG
-                       printf("%d:[%08lX:%08lX]%p:%s\n",ok,alg,mask,c,
+                       printf("%d:[%08lX:%08lX:%08lX:%08lX]%p:%s\n",ok,alg_k,alg_a,mask_k,mask_a,(void *)c,
                               c->name);
 #endif
                        }
 
+#ifndef OPENSSL_NO_TLSEXT
+#ifndef OPENSSL_NO_EC
+               if (
+                       /* if we are considering an ECC cipher suite that uses our certificate */
+                       (alg_a & SSL_aECDSA || alg_a & SSL_aECDH)
+                       /* and we have an ECC certificate */
+                       && (s->cert->pkeys[SSL_PKEY_ECC].x509 != NULL)
+                       /* and the client specified a Supported Point Formats extension */
+                       && ((s->session->tlsext_ecpointformatlist_length > 0) && (s->session->tlsext_ecpointformatlist != NULL))
+                       /* and our certificate's point is compressed */
+                       && (
+                               (s->cert->pkeys[SSL_PKEY_ECC].x509->cert_info != NULL)
+                               && (s->cert->pkeys[SSL_PKEY_ECC].x509->cert_info->key != NULL)
+                               && (s->cert->pkeys[SSL_PKEY_ECC].x509->cert_info->key->public_key != NULL)
+                               && (s->cert->pkeys[SSL_PKEY_ECC].x509->cert_info->key->public_key->data != NULL)
+                               && (
+                                       (*(s->cert->pkeys[SSL_PKEY_ECC].x509->cert_info->key->public_key->data) == POINT_CONVERSION_COMPRESSED)
+                                       || (*(s->cert->pkeys[SSL_PKEY_ECC].x509->cert_info->key->public_key->data) == POINT_CONVERSION_COMPRESSED + 1)
+                                       )
+                               )
+               )
+                       {
+                       ec_ok = 0;
+                       /* if our certificate's curve is over a field type that the client does not support
+                        * then do not allow this cipher suite to be negotiated */
+                       if (
+                               (s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec != NULL)
+                               && (s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group != NULL)
+                               && (s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group->meth != NULL)
+                               && (EC_METHOD_get_field_type(s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group->meth) == NID_X9_62_prime_field)
+                       )
+                               {
+                               for (j = 0; j < s->session->tlsext_ecpointformatlist_length; j++)
+                                       {
+                                       if (s->session->tlsext_ecpointformatlist[j] == TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime)
+                                               {
+                                               ec_ok = 1;
+                                               break;
+                                               }
+                                       }
+                               }
+                       else if (EC_METHOD_get_field_type(s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group->meth) == NID_X9_62_characteristic_two_field)
+                               {
+                               for (j = 0; j < s->session->tlsext_ecpointformatlist_length; j++)
+                                       {
+                                       if (s->session->tlsext_ecpointformatlist[j] == TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2)
+                                               {
+                                               ec_ok = 1;
+                                               break;
+                                               }
+                                       }
+                               }
+                       ok = ok && ec_ok;
+                       }
+               if (
+                       /* if we are considering an ECC cipher suite that uses our certificate */
+                       (alg_a & SSL_aECDSA || alg_a & SSL_aECDH)
+                       /* and we have an ECC certificate */
+                       && (s->cert->pkeys[SSL_PKEY_ECC].x509 != NULL)
+                       /* and the client specified an EllipticCurves extension */
+                       && ((s->session->tlsext_ellipticcurvelist_length > 0) && (s->session->tlsext_ellipticcurvelist != NULL))
+               )
+                       {
+                       ec_ok = 0;
+                       if (
+                               (s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec != NULL)
+                               && (s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group != NULL)
+                       )
+                               {
+                               ec_nid = EC_GROUP_get_curve_name(s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group);
+                               if ((ec_nid == 0)
+                                       && (s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group->meth != NULL)
+                               )
+                                       {
+                                       if (EC_METHOD_get_field_type(s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group->meth) == NID_X9_62_prime_field)
+                                               {
+                                               ec_search1 = 0xFF;
+                                               ec_search2 = 0x01;
+                                               }
+                                       else if (EC_METHOD_get_field_type(s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group->meth) == NID_X9_62_characteristic_two_field)
+                                               {
+                                               ec_search1 = 0xFF;
+                                               ec_search2 = 0x02;
+                                               }
+                                       }
+                               else
+                                       {
+                                       ec_search1 = 0x00;
+                                       ec_search2 = tls1_ec_nid2curve_id(ec_nid);
+                                       }
+                               if ((ec_search1 != 0) || (ec_search2 != 0))
+                                       {
+                                       for (j = 0; j < s->session->tlsext_ellipticcurvelist_length / 2; j++)
+                                               {
+                                               if ((s->session->tlsext_ellipticcurvelist[2*j] == ec_search1) && (s->session->tlsext_ellipticcurvelist[2*j+1] == ec_search2))
+                                                       {
+                                                       ec_ok = 1;
+                                                       break;
+                                                       }
+                                               }
+                                       }
+                               }
+                       ok = ok && ec_ok;
+                       }
+               if (
+                       /* if we are considering an ECC cipher suite that uses an ephemeral EC key */
+                       (alg_k & SSL_kEECDH)
+                       /* and we have an ephemeral EC key */
+                       && (s->cert->ecdh_tmp != NULL)
+                       /* and the client specified an EllipticCurves extension */
+                       && ((s->session->tlsext_ellipticcurvelist_length > 0) && (s->session->tlsext_ellipticcurvelist != NULL))
+               )
+                       {
+                       ec_ok = 0;
+                       if (s->cert->ecdh_tmp->group != NULL)
+                               {
+                               ec_nid = EC_GROUP_get_curve_name(s->cert->ecdh_tmp->group);
+                               if ((ec_nid == 0)
+                                       && (s->cert->ecdh_tmp->group->meth != NULL)
+                               )
+                                       {
+                                       if (EC_METHOD_get_field_type(s->cert->ecdh_tmp->group->meth) == NID_X9_62_prime_field)
+                                               {
+                                               ec_search1 = 0xFF;
+                                               ec_search2 = 0x01;
+                                               }
+                                       else if (EC_METHOD_get_field_type(s->cert->ecdh_tmp->group->meth) == NID_X9_62_characteristic_two_field)
+                                               {
+                                               ec_search1 = 0xFF;
+                                               ec_search2 = 0x02;
+                                               }
+                                       }
+                               else
+                                       {
+                                       ec_search1 = 0x00;
+                                       ec_search2 = tls1_ec_nid2curve_id(ec_nid);
+                                       }
+                               if ((ec_search1 != 0) || (ec_search2 != 0))
+                                       {
+                                       for (j = 0; j < s->session->tlsext_ellipticcurvelist_length / 2; j++)
+                                               {
+                                               if ((s->session->tlsext_ellipticcurvelist[2*j] == ec_search1) && (s->session->tlsext_ellipticcurvelist[2*j+1] == ec_search2))
+                                                       {
+                                                       ec_ok = 1;
+                                                       break;
+                                                       }
+                                               }
+                                       }
+                               }
+                       ok = ok && ec_ok;
+                       }
+#endif /* OPENSSL_NO_EC */
+#endif /* OPENSSL_NO_TLSEXT */
+
                if (!ok) continue;
-               j=sk_SSL_CIPHER_find(allow,c);
-               if (j >= 0)
+               ii=sk_SSL_CIPHER_find(allow,c);
+               if (ii >= 0)
                        {
-                       ret=sk_SSL_CIPHER_value(allow,j);
+                       ret=sk_SSL_CIPHER_value(allow,ii);
                        break;
                        }
                }
@@ -2416,12 +3105,24 @@ SSL_CIPHER *ssl3_choose_cipher(SSL *s, STACK_OF(SSL_CIPHER) *clnt,
 int ssl3_get_req_cert_type(SSL *s, unsigned char *p)
        {
        int ret=0;
-       unsigned long alg;
+       unsigned long alg_k;
+
+       alg_k = s->s3->tmp.new_cipher->algorithm_mkey;
 
-       alg=s->s3->tmp.new_cipher->algorithms;
+#ifndef OPENSSL_NO_GOST
+       if (s->version >= TLS1_VERSION)
+               {
+               if (alg_k & SSL_kGOST)
+                       {
+                       p[ret++]=TLS_CT_GOST94_SIGN;
+                       p[ret++]=TLS_CT_GOST01_SIGN;
+                       return(ret);
+                       }
+               }
+#endif
 
 #ifndef OPENSSL_NO_DH
-       if (alg & (SSL_kDHr|SSL_kEDH))
+       if (alg_k & (SSL_kDHr|SSL_kEDH))
                {
 #  ifndef OPENSSL_NO_RSA
                p[ret++]=SSL3_CT_RSA_FIXED_DH;
@@ -2431,7 +3132,7 @@ int ssl3_get_req_cert_type(SSL *s, unsigned char *p)
 #  endif
                }
        if ((s->version == SSL3_VERSION) &&
-               (alg & (SSL_kEDH|SSL_kDHd|SSL_kDHr)))
+               (alg_k & (SSL_kEDH|SSL_kDHd|SSL_kDHr)))
                {
 #  ifndef OPENSSL_NO_RSA
                p[ret++]=SSL3_CT_RSA_EPHEMERAL_DH;
@@ -2448,10 +3149,7 @@ int ssl3_get_req_cert_type(SSL *s, unsigned char *p)
        p[ret++]=SSL3_CT_DSS_SIGN;
 #endif
 #ifndef OPENSSL_NO_ECDH
-       /* We should ask for fixed ECDH certificates only
-        * for SSL_kECDH (and not SSL_kECDHE)
-        */
-       if ((alg & SSL_kECDH) && (s->version >= TLS1_VERSION))
+       if ((alg_k & (SSL_kECDHr|SSL_kECDHe)) && (s->version >= TLS1_VERSION))
                {
                p[ret++]=TLS_CT_RSA_FIXED_ECDH;
                p[ret++]=TLS_CT_ECDSA_FIXED_ECDH;
@@ -2460,7 +3158,7 @@ int ssl3_get_req_cert_type(SSL *s, unsigned char *p)
 
 #ifndef OPENSSL_NO_ECDSA
        /* ECDSA certs can be used with RSA cipher suites as well 
-        * so we don't need to check for SSL_kECDH or SSL_kECDHE
+        * so we don't need to check for SSL_kECDH or SSL_kEECDH
         */
        if (s->version >= TLS1_VERSION)
                {
index 6a6eb1c..cdddb17 100644 (file)
@@ -60,8 +60,8 @@
 #include <openssl/objects.h>
 #include "ssl_locl.h"
 
-static SSL_METHOD *ssl3_get_method(int ver);
-static SSL_METHOD *ssl3_get_method(int ver)
+static const SSL_METHOD *ssl3_get_method(int ver);
+static const SSL_METHOD *ssl3_get_method(int ver)
        {
        if (ver == SSL3_VERSION)
                return(SSLv3_method());
@@ -70,8 +70,8 @@ static SSL_METHOD *ssl3_get_method(int ver)
        }
 
 IMPLEMENT_ssl3_meth_func(SSLv3_method,
-                       ssl3_accept,
-                       ssl3_connect,
-                       ssl3_get_method)
+                        ssl3_accept,
+                        ssl3_connect,
+                        ssl3_get_method)
 
 
index ad6a0b3..0d3874a 100644 (file)
@@ -120,52 +120,8 @@ static int do_ssl3_write(SSL *s, int type, const unsigned char *buf,
                         unsigned int len, int create_empty_fragment);
 static int ssl3_get_record(SSL *s);
 
-/* ssl3_read_snap_start_n reads from the opportunistic records contained within
- * a Snap Start extension. |s->packet| and |s->packet_length| are set to frame
- * a record within this area. Partial records are not allowed. The Snap Start
- * records are held in |s->s3->snap_start_records| and the |left| member must
- * be non-zero on entry.
- *
- * If |extend| is true then we'll expand the currently framed record by |n|
- * bytes, otherwise we frame a new record. */
-static int ssl3_read_snap_start_n(SSL *s, int n, int extend)
-       {
-       if (!extend)
-               {
-               s->packet = s->s3->snap_start_records.buf + s->s3->snap_start_records.offset;
-               s->packet_length = 0;
-               }
-
-       if (s->s3->snap_start_records.left < n)
-               {
-               /* We aren't called unless .left is non-zero, therefore this
-                * means that we wanted to read more than we have. Since
-                * partial records aren't allowed, this is fatal. */
-               SSLerr(SSL_F_SSL3_READ_SNAP_START_N,SSL_R_BAD_PACKET_LENGTH);
-               return -1;
-               }
-
-       s->packet_length += n;
-       s->s3->snap_start_records.left -= n;
-       s->s3->snap_start_records.offset += n;
-
-       return n;
-       }
-
 int ssl3_read_n(SSL *s, int n, int max, int extend)
        {
-       int i,off,newb;
-       if (s->s3->snap_start_records.left)
-               return ssl3_read_snap_start_n(s, n, extend);
-       else if (s->s3->snap_start_client_hello.buf && !extend)
-               {
-               /* If we started reading the opportunistic records then we know
-                * that we didn't enter recovery. Thus it's safe to free the
-                * copy of the ClientHello now because we'll not need it again. */
-               OPENSSL_free(s->s3->snap_start_client_hello.buf);
-               s->s3->snap_start_client_hello.buf = NULL;
-               }
-
        /* If extend == 0, obtain new n-byte packet; if extend == 1, increase
         * packet by another n bytes.
         * The packet will be in the sub-array of s->s3->rbuf.buf specified
@@ -173,13 +129,49 @@ int ssl3_read_n(SSL *s, int n, int max, int extend)
         * (If s->read_ahead is set, 'max' bytes may be stored in rbuf
         * [plus s->packet_length bytes if extend == 1].)
         */
+       int i,len,left;
+       long align=0;
+       unsigned char *pkt;
+       SSL3_BUFFER *rb;
+
+       if (n <= 0) return n;
+
+       rb    = &(s->s3->rbuf);
+       if (rb->buf == NULL)
+               if (!ssl3_setup_read_buffer(s))
+                       return -1;
+
+       left  = rb->left;
+#if defined(SSL3_ALIGN_PAYLOAD) && SSL3_ALIGN_PAYLOAD!=0
+       align = (long)rb->buf + SSL3_RT_HEADER_LENGTH;
+       align = (-align)&(SSL3_ALIGN_PAYLOAD-1);
+#endif
 
        if (!extend)
                {
                /* start with empty packet ... */
-               if (s->s3->rbuf.left == 0)
-                       s->s3->rbuf.offset = 0;
-               s->packet = s->s3->rbuf.buf + s->s3->rbuf.offset;
+               if (left == 0)
+                       rb->offset = align;
+               else if (align != 0 && left >= SSL3_RT_HEADER_LENGTH)
+                       {
+                       /* check if next packet length is large
+                        * enough to justify payload alignment... */
+                       pkt = rb->buf + rb->offset;
+                       if (pkt[0] == SSL3_RT_APPLICATION_DATA
+                           && (pkt[3]<<8|pkt[4]) >= 128)
+                               {
+                               /* Note that even if packet is corrupted
+                                * and its length field is insane, we can
+                                * only be led to wrong decision about
+                                * whether memmove will occur or not.
+                                * Header values has no effect on memmove
+                                * arguments and therefore no buffer
+                                * overrun can be triggered. */
+                               memmove (rb->buf+align,pkt,left);
+                               rb->offset = align;
+                               }
+                       }
+               s->packet = rb->buf + rb->offset;
                s->packet_length = 0;
                /* ... now we can act as if 'extend' was set */
                }
@@ -187,59 +179,63 @@ int ssl3_read_n(SSL *s, int n, int max, int extend)
        /* For DTLS/UDP reads should not span multiple packets
         * because the read operation returns the whole packet
         * at once (as long as it fits into the buffer). */
-       if (SSL_version(s) == DTLS1_VERSION)
+       if (SSL_version(s) == DTLS1_VERSION || SSL_version(s) == DTLS1_BAD_VER)
                {
-               if ( s->s3->rbuf.left > 0 && n > s->s3->rbuf.left)
-                       n = s->s3->rbuf.left;
+               if (left > 0 && n > left)
+                       n = left;
                }
 
        /* if there is enough in the buffer from a previous read, take some */
-       if (s->s3->rbuf.left >= (int)n)
+       if (left >= n)
                {
                s->packet_length+=n;
-               s->s3->rbuf.left-=n;
-               s->s3->rbuf.offset+=n;
+               rb->left=left-n;
+               rb->offset+=n;
                return(n);
                }
 
        /* else we need to read more data */
-       if (!s->read_ahead)
-               max=n;
 
-       {
-               /* avoid buffer overflow */
-               int max_max = s->s3->rbuf.len - s->packet_length;
-               if (max > max_max)
-                       max = max_max;
-       }
-       if (n > max) /* does not happen */
+       len = s->packet_length;
+       pkt = rb->buf+align;
+       /* Move any available bytes to front of buffer:
+        * 'len' bytes already pointed to by 'packet',
+        * 'left' extra ones at the end */
+       if (s->packet != pkt) /* len > 0 */
+               {
+               memmove(pkt, s->packet, len+left);
+               s->packet = pkt;
+               rb->offset = len + align;
+               }
+
+       if (n > (int)(rb->len - rb->offset)) /* does not happen */
                {
                SSLerr(SSL_F_SSL3_READ_N,ERR_R_INTERNAL_ERROR);
                return -1;
                }
 
-       off = s->packet_length;
-       newb = s->s3->rbuf.left;
-       /* Move any available bytes to front of buffer:
-        * 'off' bytes already pointed to by 'packet',
-        * 'newb' extra ones at the end */
-       if (s->packet != s->s3->rbuf.buf)
+       if (!s->read_ahead)
+               /* ignore max parameter */
+               max = n;
+       else
                {
-               /*  off > 0 */
-               memmove(s->s3->rbuf.buf, s->packet, off+newb);
-               s->packet = s->s3->rbuf.buf;
+               if (max < n)
+                       max = n;
+               if (max > (int)(rb->len - rb->offset))
+                       max = rb->len - rb->offset;
                }
 
-       while (newb < n)
+       while (left < n)
                {
-               /* Now we have off+newb bytes at the front of s->s3->rbuf.buf and need
-                * to read in more until we have off+n (up to off+max if possible) */
+               /* Now we have len+left bytes at the front of s->s3->rbuf.buf
+                * and need to read in more until we have len+n (up to
+                * len+max if possible) */
 
                clear_sys_error();
                if (s->rbio != NULL)
                        {
                        s->rwstate=SSL_READING;
-                       i=BIO_read(s->rbio,     &(s->s3->rbuf.buf[off+newb]), max-newb);
+                       i=BIO_read(s->rbio,pkt+len+left, max-left);
                        }
                else
                        {
@@ -249,23 +245,27 @@ int ssl3_read_n(SSL *s, int n, int max, int extend)
 
                if (i <= 0)
                        {
-                       s->s3->rbuf.left = newb;
+                       rb->left = left;
+                       if (s->mode & SSL_MODE_RELEASE_BUFFERS &&
+                           SSL_version(s) != DTLS1_VERSION && SSL_version(s) != DTLS1_BAD_VER)
+                               if (len+left == 0)
+                                       ssl3_release_read_buffer(s);
                        return(i);
                        }
-               newb+=i;
+               left+=i;
                /* reads should *never* span multiple packets for DTLS because
                 * the underlying transport protocol is message oriented as opposed
                 * to byte oriented as in the TLS case. */
-               if (SSL_version(s) == DTLS1_VERSION)
+               if (SSL_version(s) == DTLS1_VERSION || SSL_version(s) == DTLS1_BAD_VER)
                        {
-                       if (n > newb)
-                               n = newb; /* makes the while condition false */
+                       if (n > left)
+                               n = left; /* makes the while condition false */
                        }
                }
 
        /* done reading, now the book-keeping */
-       s->s3->rbuf.offset = off + n;
-       s->s3->rbuf.left = newb - n;
+       rb->offset += n;
+       rb->left = left - n;
        s->packet_length += n;
        s->rwstate=SSL_NOTHING;
        return(n);
@@ -289,11 +289,16 @@ static int ssl3_get_record(SSL *s)
        unsigned char *p;
        unsigned char md[EVP_MAX_MD_SIZE];
        short version;
-       unsigned int mac_size;
+       int mac_size;
        int clear=0;
        size_t extra;
        int decryption_failed_or_bad_record_mac = 0;
        unsigned char *mac = NULL;
+#if defined(SSL3_ALIGN_PAYLOAD) && SSL3_ALIGN_PAYLOAD!=0
+       long align=SSL3_ALIGN_PAYLOAD;
+#else
+       long align=0;
+#endif
 
        rr= &(s->s3->rrec);
        sess=s->session;
@@ -302,9 +307,10 @@ static int ssl3_get_record(SSL *s)
                extra=SSL3_RT_MAX_EXTRA;
        else
                extra=0;
-       if (extra != s->s3->rbuf.len - SSL3_RT_MAX_PACKET_SIZE)
+       if (!(SSL_get_mode(s) & SSL_MODE_SMALL_BUFFERS) &&
+               extra && !s->s3->init_extra)
                {
-               /* actually likely an application error: SLS_OP_MICROSOFT_BIG_SSLV3_BUFFER
+               /* An application error: SLS_OP_MICROSOFT_BIG_SSLV3_BUFFER
                 * set after ssl3_setup_buffers() was done */
                SSLerr(SSL_F_SSL3_GET_RECORD, ERR_R_INTERNAL_ERROR);
                return -1;
@@ -327,6 +333,9 @@ again:
                ssl_minor= *(p++);
                version=(ssl_major<<8)|ssl_minor;
                n2s(p,rr->length);
+#if 0
+fprintf(stderr, "Record type=%d, Length=%d\n", rr->type, rr->length);
+#endif
 
                /* Lets check version */
                if (!s->first_packet)
@@ -348,7 +357,22 @@ again:
                        goto err;
                        }
 
-               if (rr->length > SSL3_RT_MAX_ENCRYPTED_LENGTH+extra)
+               /* If we receive a valid record larger than the current buffer size,
+                * allocate some memory for it.
+                */
+               if (rr->length > s->s3->rbuf.len - SSL3_RT_HEADER_LENGTH - align)
+                       {
+                       if ((p=OPENSSL_realloc(s->s3->rbuf.buf, rr->length + SSL3_RT_HEADER_LENGTH + align))==NULL)
+                               {
+                               SSLerr(SSL_F_SSL3_GET_RECORD,ERR_R_MALLOC_FAILURE);
+                               goto err;
+                               }
+                       s->s3->rbuf.buf=p;
+                       s->s3->rbuf.len=rr->length + SSL3_RT_HEADER_LENGTH + align;
+                       s->packet= &(s->s3->rbuf.buf[0]);
+                       }
+
+               if (rr->length > s->s3->rbuf.len - SSL3_RT_HEADER_LENGTH)
                        {
                        al=SSL_AD_RECORD_OVERFLOW;
                        SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_PACKET_LENGTH_TOO_LONG);
@@ -421,12 +445,14 @@ printf("\n");
        /* r->length is now the compressed data plus mac */
        if (    (sess == NULL) ||
                (s->enc_read_ctx == NULL) ||
-               (s->read_hash == NULL))
+               (EVP_MD_CTX_md(s->read_hash) == NULL))
                clear=1;
 
        if (!clear)
                {
-               mac_size=EVP_MD_size(s->read_hash);
+               /* !clear => s->read_hash != NULL => mac_size != -1 */
+               mac_size=EVP_MD_CTX_size(s->read_hash);
+               OPENSSL_assert(mac_size >= 0);
 
                if (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH+extra+mac_size)
                        {
@@ -439,7 +465,7 @@ printf("\n");
 #endif                 
                        }
                /* check the MAC for rr->input (it's in mac_size bytes at the tail) */
-               if (rr->length >= mac_size)
+               if (rr->length >= (unsigned int)mac_size)
                        {
                        rr->length -= mac_size;
                        mac = &rr->data[rr->length];
@@ -457,7 +483,7 @@ printf("\n");
 #endif
                        }
                i=s->method->ssl3_enc->mac(s,md,0);
-               if (mac == NULL || memcmp(md, mac, mac_size) != 0)
+               if (i < 0 || mac == NULL || memcmp(md, mac, (size_t)mac_size) != 0)
                        {
                        decryption_failed_or_bad_record_mac = 1;
                        }
@@ -514,6 +540,10 @@ printf("\n");
        /* just read a 0 length packet */
        if (rr->length == 0) goto again;
 
+#if 0
+fprintf(stderr, "Ultimate Record type=%d, Length=%d\n", rr->type, rr->length);
+#endif
+
        return(1);
 
 f_err:
@@ -568,6 +598,7 @@ int ssl3_write_bytes(SSL *s, int type, const void *buf_, int len)
        const unsigned char *buf=buf_;
        unsigned int tot,n,nw;
        int i;
+       unsigned int max_plain_length;
 
        s->rwstate=SSL_NOTHING;
        tot=s->s3->wnum;
@@ -587,8 +618,13 @@ int ssl3_write_bytes(SSL *s, int type, const void *buf_, int len)
        n=(len-tot);
        for (;;)
                {
-               if (n > SSL3_RT_MAX_PLAIN_LENGTH)
-                       nw=SSL3_RT_MAX_PLAIN_LENGTH;
+               if (type == SSL3_RT_APPLICATION_DATA && (SSL_get_mode(s) & SSL_MODE_SMALL_BUFFERS))
+                       max_plain_length = SSL3_RT_DEFAULT_PLAIN_LENGTH;
+               else
+                       max_plain_length = s->max_send_fragment;
+
+               if (n > max_plain_length)
+                       nw = max_plain_length;
                else
                        nw=n;
 
@@ -620,14 +656,19 @@ static int do_ssl3_write(SSL *s, int type, const unsigned char *buf,
        {
        unsigned char *p,*plen;
        int i,mac_size,clear=0;
-       int prefix_len = 0;
+       int prefix_len=0;
+       long align=0;
        SSL3_RECORD *wr;
-       SSL3_BUFFER *wb;
+       SSL3_BUFFER *wb=&(s->s3->wbuf);
        SSL_SESSION *sess;
 
+       if (wb->buf == NULL)
+               if (!ssl3_setup_write_buffer(s))
+                       return -1;
+
        /* first check if there is a SSL3_BUFFER still being written
         * out.  This will happen with non blocking IO */
-       if (s->s3->wbuf.left != 0)
+       if (wb->left != 0)
                return(ssl3_write_pending(s,type,buf,len));
 
        /* If we have an alert to send, lets send it */
@@ -643,18 +684,21 @@ static int do_ssl3_write(SSL *s, int type, const unsigned char *buf,
                return 0;
 
        wr= &(s->s3->wrec);
-       wb= &(s->s3->wbuf);
        sess=s->session;
 
        if (    (sess == NULL) ||
                (s->enc_write_ctx == NULL) ||
-               (s->write_hash == NULL))
+               (EVP_MD_CTX_md(s->write_hash) == NULL))
                clear=1;
 
        if (clear)
                mac_size=0;
        else
-               mac_size=EVP_MD_size(s->write_hash);
+               {
+               mac_size=EVP_MD_CTX_size(s->write_hash);
+               if (mac_size < 0)
+                       goto err;
+               }
 
        /* 'create_empty_fragment' is true only when this function calls itself */
        if (!clear && !create_empty_fragment && !s->s3->empty_fragment_done)
@@ -672,7 +716,8 @@ static int do_ssl3_write(SSL *s, int type, const unsigned char *buf,
                        if (prefix_len <= 0)
                                goto err;
 
-                       if (s->s3->wbuf.len < (size_t)prefix_len + SSL3_RT_MAX_PACKET_SIZE)
+                       if (prefix_len >
+               (SSL3_RT_HEADER_LENGTH + SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD))
                                {
                                /* insufficient space */
                                SSLerr(SSL_F_DO_SSL3_WRITE, ERR_R_INTERNAL_ERROR);
@@ -683,7 +728,44 @@ static int do_ssl3_write(SSL *s, int type, const unsigned char *buf,
                s->s3->empty_fragment_done = 1;
                }
 
-       p = wb->buf + prefix_len;
+       /* resize if necessary to hold the data. */
+       if (len + SSL3_RT_DEFAULT_WRITE_OVERHEAD > wb->len)
+               {
+               if ((p=OPENSSL_realloc(wb->buf, len + SSL3_RT_DEFAULT_WRITE_OVERHEAD))==NULL)
+                       {
+                       SSLerr(SSL_F_DO_SSL3_WRITE,ERR_R_MALLOC_FAILURE);
+                       goto err;
+                       }
+               wb->buf = p;
+               wb->len = len + SSL3_RT_DEFAULT_WRITE_OVERHEAD;
+               }
+
+       if (create_empty_fragment)
+               {
+#if defined(SSL3_ALIGN_PAYLOAD) && SSL3_ALIGN_PAYLOAD!=0
+               /* extra fragment would be couple of cipher blocks,
+                * which would be multiple of SSL3_ALIGN_PAYLOAD, so
+                * if we want to align the real payload, then we can
+                * just pretent we simply have two headers. */
+               align = (long)wb->buf + 2*SSL3_RT_HEADER_LENGTH;
+               align = (-align)&(SSL3_ALIGN_PAYLOAD-1);
+#endif
+               p = wb->buf + align;
+               wb->offset  = align;
+               }
+       else if (prefix_len)
+               {
+               p = wb->buf + wb->offset + prefix_len;
+               }
+       else
+               {
+#if defined(SSL3_ALIGN_PAYLOAD) && SSL3_ALIGN_PAYLOAD!=0
+               align = (long)wb->buf + SSL3_RT_HEADER_LENGTH;
+               align = (-align)&(SSL3_ALIGN_PAYLOAD-1);
+#endif
+               p = wb->buf + align;
+               wb->offset  = align;
+               }
 
        /* write the header */
 
@@ -726,7 +808,8 @@ static int do_ssl3_write(SSL *s, int type, const unsigned char *buf,
 
        if (mac_size != 0)
                {
-               s->method->ssl3_enc->mac(s,&(p[wr->length]),1);
+               if (s->method->ssl3_enc->mac(s,&(p[wr->length]),1) < 0)
+                       goto err;
                wr->length+=mac_size;
                wr->input=p;
                wr->data=p;
@@ -754,7 +837,6 @@ static int do_ssl3_write(SSL *s, int type, const unsigned char *buf,
 
        /* now let's set up wb */
        wb->left = prefix_len + wr->length;
-       wb->offset = 0;
 
        /* memorize arguments so that ssl3_write_pending can detect bad write retries later */
        s->s3->wpend_tot=len;
@@ -773,6 +855,7 @@ int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,
        unsigned int len)
        {
        int i;
+       SSL3_BUFFER *wb=&(s->s3->wbuf);
 
 /* XXXX */
        if ((s->s3->wpend_tot > (int)len)
@@ -791,17 +874,21 @@ int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,
                        {
                        s->rwstate=SSL_WRITING;
                        i=BIO_write(s->wbio,
-                               (char *)&(s->s3->wbuf.buf[s->s3->wbuf.offset]),
-                               (unsigned int)s->s3->wbuf.left);
+                               (char *)&(wb->buf[wb->offset]),
+                               (unsigned int)wb->left);
                        }
                else
                        {
                        SSLerr(SSL_F_SSL3_WRITE_PENDING,SSL_R_BIO_NOT_SET);
                        i= -1;
                        }
-               if (i == s->s3->wbuf.left)
+               if (i == wb->left)
                        {
-                       s->s3->wbuf.left=0;
+                       wb->left=0;
+                       wb->offset+=i;
+                       if (s->mode & SSL_MODE_RELEASE_BUFFERS &&
+                           SSL_version(s) != DTLS1_VERSION && SSL_version(s) != DTLS1_BAD_VER)
+                               ssl3_release_write_buffer(s);
                        s->rwstate=SSL_NOTHING;
                        return(s->s3->wpend_ret);
                        }
@@ -810,12 +897,12 @@ int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,
                            s->version == DTLS1_BAD_VER) {
                                /* For DTLS, just drop it. That's kind of the whole
                                   point in using a datagram service */
-                               s->s3->wbuf.left = 0;
+                               wb->left = 0;
                        }
                        return(i);
                }
-               s->s3->wbuf.offset+=i;
-               s->s3->wbuf.left-=i;
+               wb->offset+=i;
+               wb->left-=i;
                }
        }
 
@@ -854,7 +941,7 @@ int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek)
        void (*cb)(const SSL *ssl,int type2,int val)=NULL;
 
        if (s->s3->rbuf.buf == NULL) /* Not initialized yet */
-               if (!ssl3_setup_buffers(s))
+               if (!ssl3_setup_read_buffer(s))
                        return(-1);
 
        if ((type && (type != SSL3_RT_APPLICATION_DATA) && (type != SSL3_RT_HANDSHAKE) && type) ||
@@ -963,6 +1050,8 @@ start:
                                {
                                s->rstate=SSL_ST_READ_HEADER;
                                rr->off=0;
+                               if (s->mode & SSL_MODE_RELEASE_BUFFERS)
+                                       ssl3_release_read_buffer(s);
                                }
                        }
                return(n);
@@ -1307,6 +1396,10 @@ err:
 int ssl3_do_change_cipher_spec(SSL *s)
        {
        int i;
+#ifdef OPENSSL_NO_NEXTPROTONEG
+       const char *sender;
+       int slen;
+#endif
 
        if (s->state & SSL_ST_ACCEPT)
                i=SSL3_CHANGE_CIPHER_SERVER_READ;
@@ -1329,6 +1422,25 @@ int ssl3_do_change_cipher_spec(SSL *s)
        if (!s->method->ssl3_enc->change_cipher_state(s,i))
                return(0);
 
+#ifdef OPENSSL_NO_NEXTPROTONEG
+       /* we have to record the message digest at
+        * this point so we can get it before we read
+        * the finished message */
+       if (s->state & SSL_ST_CONNECT)
+               {
+               sender=s->method->ssl3_enc->server_finished_label;
+               slen=s->method->ssl3_enc->server_finished_label_len;
+               }
+       else
+               {
+               sender=s->method->ssl3_enc->client_finished_label;
+               slen=s->method->ssl3_enc->client_finished_label_len;
+               }
+
+       s->s3->tmp.peer_finish_md_len = s->method->ssl3_enc->final_finish_mac(s,
+               sender,slen,s->s3->tmp.peer_finish_md);
+#endif
+
        return(1);
        }
 
index b970882..41e597f 100644 (file)
@@ -1,4 +1,4 @@
-/* ssl/s3_srvr.c */
+/* ssl/s3_srvr.c -*- mode:C; c-file-style: "eay" -*- */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
@@ -56,7 +56,7 @@
  * [including the GNU Public Licence.]
  */
 /* ====================================================================
- * Copyright (c) 1998-2005 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2007 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * Vipul Gupta and Sumit Gupta of Sun Microsystems Laboratories.
  *
  */
+/* ====================================================================
+ * Copyright 2005 Nokia. All rights reserved.
+ *
+ * The portions of the attached software ("Contribution") is developed by
+ * Nokia Corporation and is licensed pursuant to the OpenSSL open source
+ * license.
+ *
+ * The Contribution, originally written by Mika Kousa and Pasi Eronen of
+ * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
+ * support (see RFC 4279) to OpenSSL.
+ *
+ * No patent licenses or other rights except those expressly stated in
+ * the OpenSSL open source license shall be deemed granted or received
+ * expressly, by implication, estoppel, or otherwise.
+ *
+ * No assurances are provided by Nokia that the Contribution does not
+ * infringe the patent or other intellectual property rights of any third
+ * party or that the license provides you with all the necessary rights
+ * to make use of the Contribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
+ * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
+ * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
+ * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
+ * OTHERWISE.
+ */
 
 #define REUSE_CIPHER_BUG
 #define NETSCAPE_HANG_BUG
 #endif
 #include <openssl/md5.h>
 
-#include "fnv1a64.h"
-
-static SSL_METHOD *ssl3_get_server_method(int ver);
-static int ssl3_snap_start_evaluate_handshake(SSL* s);
-#ifndef OPENSSL_NO_ECDH
-static int nid2curve_id(int nid);
-#endif
+static const SSL_METHOD *ssl3_get_server_method(int ver);
 
-static SSL_METHOD *ssl3_get_server_method(int ver)
+static const SSL_METHOD *ssl3_get_server_method(int ver)
        {
        if (ver == SSL3_VERSION)
                return(SSLv3_server_method());
@@ -167,7 +187,7 @@ IMPLEMENT_ssl3_meth_func(SSLv3_server_method,
 int ssl3_accept(SSL *s)
        {
        BUF_MEM *buf;
-       unsigned long l,Time=(unsigned long)time(NULL);
+       unsigned long alg_k,Time=(unsigned long)time(NULL);
        void (*cb)(const SSL *ssl,int type,int val)=NULL;
        int ret= -1;
        int new_state,state,skip=0;
@@ -238,6 +258,7 @@ int ssl3_accept(SSL *s)
                                }
 
                        s->init_num=0;
+                       s->s3->flags &= ~SSL3_FLAGS_SGC_RESTART_DONE;
 
                        if (s->state != SSL_ST_RENEGOTIATE)
                                {
@@ -295,6 +316,7 @@ int ssl3_accept(SSL *s)
                        s->shutdown=0;
                        ret=ssl3_get_client_hello(s);
                        if (ret <= 0) goto end;
+                       
                        s->new_session = 2;
                        s->state=SSL3_ST_SW_SRVR_HELLO_A;
                        s->init_num=0;
@@ -303,36 +325,10 @@ int ssl3_accept(SSL *s)
                case SSL3_ST_SW_SRVR_HELLO_A:
                case SSL3_ST_SW_SRVR_HELLO_B:
                        ret=ssl3_send_server_hello(s);
-                       if (ret == SERVER_RANDOM_VALIDATION_PENDING)
-                               {
-                               s->rwstate = SSL_SERVER_RANDOM_VALIDATE;
-                               s->state = SSL3_ST_SW_SRVR_HELLO_A;
-                               s->init_num = 0;
-                               goto end;
-                               }
                        if (ret <= 0) goto end;
 #ifndef OPENSSL_NO_TLSEXT
-                       if ((s->s3->tmp.new_cipher->algorithms & SSL_MKEY_MASK) != SSL_kRSA &&
-                           (s->s3->tmp.new_cipher->algorithms & SSL_MKEY_MASK) != SSL_kKRB5 &&
-                           (s->s3->tmp.new_cipher->algorithms & SSL_MKEY_MASK) != SSL_kDHr &&
-                           (s->s3->tmp.new_cipher->algorithms & SSL_MKEY_MASK) != SSL_kDHd &&
-                           (s->s3->tmp.new_cipher->algorithms & SSL_MKEY_MASK) != SSL_kECDH &&
-                           s->s3->snap_start_requested)
-                               {
-                               /* There's no point in carrying on with a Snap
-                                * Start handshake if we're using a cipher
-                                * suite which is going to send a
-                                * ServerKeyExchange message. */
-                               ssl3_snap_start_reset_for_recovery(s);
-                               s->state = SSL3_ST_SW_SRVR_HELLO_A;
-                               break;
-                               }
-
                        if (s->hit)
                                {
-                               if (ssl3_snap_start_evaluate_handshake(s))
-                                       break;
-
                                if (s->tlsext_ticket_expected)
                                        s->state=SSL3_ST_SW_SESSION_TICKET_A;
                                else
@@ -349,9 +345,11 @@ int ssl3_accept(SSL *s)
 
                case SSL3_ST_SW_CERT_A:
                case SSL3_ST_SW_CERT_B:
-                       /* Check if it is anon DH or anon ECDH or KRB5 */
-                       if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL)
-                               && !(s->s3->tmp.new_cipher->algorithms & SSL_aKRB5))
+                       /* Check if it is anon DH or anon ECDH, */
+                       /* normal PSK or KRB5 */
+                       if (!(s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL)
+                               && !(s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK)
+                               && !(s->s3->tmp.new_cipher->algorithm_auth & SSL_aKRB5))
                                {
                                ret=ssl3_send_server_certificate(s);
                                if (ret <= 0) goto end;
@@ -378,13 +376,13 @@ int ssl3_accept(SSL *s)
 
                case SSL3_ST_SW_KEY_EXCH_A:
                case SSL3_ST_SW_KEY_EXCH_B:
-                       l=s->s3->tmp.new_cipher->algorithms;
+                       alg_k = s->s3->tmp.new_cipher->algorithm_mkey;
 
                        /* clear this, it may get reset by
                         * send_server_key_exchange */
                        if ((s->options & SSL_OP_EPHEMERAL_RSA)
 #ifndef OPENSSL_NO_KRB5
-                               && !(l & SSL_KRB5)
+                               && !(alg_k & SSL_kKRB5)
 #endif /* OPENSSL_NO_KRB5 */
                                )
                                /* option SSL_OP_EPHEMERAL_RSA sends temporary RSA key
@@ -399,16 +397,23 @@ int ssl3_accept(SSL *s)
                        /* only send if a DH key exchange, fortezza or
                         * RSA but we have a sign only certificate
                         *
+                        * PSK: may send PSK identity hints
+                        *
                         * For ECC ciphersuites, we send a serverKeyExchange
                         * message only if the cipher suite is either
                         * ECDH-anon or ECDHE. In other cases, the
-                        * server certificate contains the server's 
+                        * server certificate contains the server's
                         * public key for key exchange.
                         */
                        if (s->s3->tmp.use_rsa_tmp
-                           || (l & SSL_kECDHE)
-                           || (l & (SSL_DH|SSL_kFZA))
-                           || ((l & SSL_kRSA)
+                       /* PSK: send ServerKeyExchange if PSK identity
+                        * hint if provided */
+#ifndef OPENSSL_NO_PSK
+                           || ((alg_k & SSL_kPSK) && s->ctx->psk_identity_hint)
+#endif
+                           || (alg_k & (SSL_kDHr|SSL_kDHd|SSL_kEDH))
+                           || (alg_k & SSL_kEECDH)
+                           || ((alg_k & SSL_kRSA)
                                && (s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL
                                    || (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher)
                                        && EVP_PKEY_size(s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey)*8 > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)
@@ -438,12 +443,15 @@ int ssl3_accept(SSL *s)
                                /* never request cert in anonymous ciphersuites
                                 * (see section "Certificate request" in SSL 3 drafts
                                 * and in RFC 2246): */
-                               ((s->s3->tmp.new_cipher->algorithms & SSL_aNULL) &&
+                               ((s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL) &&
                                 /* ... except when the application insists on verification
                                  * (against the specs, but s3_clnt.c accepts this for SSL 3) */
                                 !(s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) ||
-                                 /* never request cert in Kerberos ciphersuites */
-                                (s->s3->tmp.new_cipher->algorithms & SSL_aKRB5))
+                                /* never request cert in Kerberos ciphersuites */
+                               (s->s3->tmp.new_cipher->algorithm_auth & SSL_aKRB5)
+                               /* With normal PSK Certificates and
+                                * Certificate Requests are omitted */
+                               || (s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK))
                                {
                                /* no cert request */
                                skip=1;
@@ -469,19 +477,8 @@ int ssl3_accept(SSL *s)
                case SSL3_ST_SW_SRVR_DONE_B:
                        ret=ssl3_send_server_done(s);
                        if (ret <= 0) goto end;
-
-                       if (s->s3->snap_start_requested)
-                               {
-                               if (ssl3_snap_start_evaluate_handshake(s))
-                                       break;
-                               s->state = SSL3_ST_SR_CERT_A;
-                               }
-                       else
-                               {
-                                       s->s3->tmp.next_state=SSL3_ST_SR_CERT_A;
-                                       s->state=SSL3_ST_SW_FLUSH;
-                               }
-
+                       s->s3->tmp.next_state=SSL3_ST_SR_CERT_A;
+                       s->state=SSL3_ST_SW_FLUSH;
                        s->init_num=0;
                        break;
                
@@ -530,7 +527,7 @@ int ssl3_accept(SSL *s)
                case SSL3_ST_SR_KEY_EXCH_A:
                case SSL3_ST_SR_KEY_EXCH_B:
                        ret=ssl3_get_client_key_exchange(s);
-                       if (ret <= 0) 
+                       if (ret <= 0)
                                goto end;
                        if (ret == 2)
                                {
@@ -538,27 +535,50 @@ int ssl3_accept(SSL *s)
                                 * the client sends its ECDH pub key in
                                 * a certificate, the CertificateVerify
                                 * message is not sent.
+                                * Also for GOST ciphersuites when
+                                * the client uses its key from the certificate
+                                * for key exchange.
                                 */
+#if defined(OPENSSL_NO_TLSEXT) || defined(OPENSSL_NO_NEXTPROTONEG)
+                               s->state=SSL3_ST_SR_FINISHED_A;
+#else
                                if (s->s3->next_proto_neg_seen)
                                        s->state=SSL3_ST_SR_NEXT_PROTO_A;
                                else
                                        s->state=SSL3_ST_SR_FINISHED_A;
+#endif
                                s->init_num = 0;
                                }
-                       else   
+                       else
                                {
+                               int offset=0;
+                               int dgst_num;
+
                                s->state=SSL3_ST_SR_CERT_VRFY_A;
                                s->init_num=0;
 
                                /* We need to get hashes here so if there is
                                 * a client cert, it can be verified
-                                */ 
-                               s->method->ssl3_enc->cert_verify_mac(s,
-                                   &(s->s3->finish_dgst1),
-                                   &(s->s3->tmp.cert_verify_md[0]));
-                               s->method->ssl3_enc->cert_verify_mac(s,
-                                   &(s->s3->finish_dgst2),
-                                   &(s->s3->tmp.cert_verify_md[MD5_DIGEST_LENGTH]));
+                                * FIXME - digest processing for CertificateVerify
+                                * should be generalized. But it is next step
+                                */
+                               if (s->s3->handshake_buffer)
+                                       if (!ssl3_digest_cached_records(s))
+                                               return -1;
+                               for (dgst_num=0; dgst_num<SSL_MAX_DIGEST;dgst_num++)    
+                                       if (s->s3->handshake_dgst[dgst_num]) 
+                                               {
+                                               int dgst_size;
+
+                                               s->method->ssl3_enc->cert_verify_mac(s,EVP_MD_CTX_type(s->s3->handshake_dgst[dgst_num]),&(s->s3->tmp.cert_verify_md[offset]));
+                                               dgst_size=EVP_MD_CTX_size(s->s3->handshake_dgst[dgst_num]);
+                                               if (dgst_size < 0)
+                                                       {
+                                                       ret = -1;
+                                                       goto end;
+                                                       }
+                                               offset+=dgst_size;
+                                               }               
                                }
                        break;
 
@@ -569,13 +589,18 @@ int ssl3_accept(SSL *s)
                        ret=ssl3_get_cert_verify(s);
                        if (ret <= 0) goto end;
 
+#if defined(OPENSSL_NO_TLSEXT) || defined(OPENSSL_NO_NEXTPROTONEG)
+                       s->state=SSL3_ST_SR_FINISHED_A;
+#else
                        if (s->s3->next_proto_neg_seen)
                                s->state=SSL3_ST_SR_NEXT_PROTO_A;
                        else
                                s->state=SSL3_ST_SR_FINISHED_A;
+#endif
                        s->init_num=0;
                        break;
 
+#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
                case SSL3_ST_SR_NEXT_PROTO_A:
                case SSL3_ST_SR_NEXT_PROTO_B:
                        ret=ssl3_get_next_proto(s);
@@ -583,17 +608,21 @@ int ssl3_accept(SSL *s)
                        s->init_num = 0;
                        s->state=SSL3_ST_SR_FINISHED_A;
                        break;
+#endif
 
                case SSL3_ST_SR_FINISHED_A:
                case SSL3_ST_SR_FINISHED_B:
                        ret=ssl3_get_finished(s,SSL3_ST_SR_FINISHED_A,
                                SSL3_ST_SR_FINISHED_B);
                        if (ret <= 0) goto end;
-                       if (s->hit)
-                               s->state=SSL_ST_OK;
 #ifndef OPENSSL_NO_TLSEXT
-                       else if (s->tlsext_ticket_expected)
+                       if (s->tlsext_ticket_expected)
                                s->state=SSL3_ST_SW_SESSION_TICKET_A;
+                       else if (s->hit)
+                               s->state=SSL_ST_OK;
+#else
+                       if (s->hit)
+                               s->state=SSL_ST_OK;
 #endif
                        else
                                s->state=SSL3_ST_SW_CHANGE_A;
@@ -652,10 +681,14 @@ int ssl3_accept(SSL *s)
                        s->state=SSL3_ST_SW_FLUSH;
                        if (s->hit)
                                {
+#if defined(OPENSSL_NO_TLSEXT) || defined(OPENSSL_NO_NEXTPROTONEG)
+                               s->s3->tmp.next_state=SSL3_ST_SR_FINISHED_A;
+#else
                                if (s->s3->next_proto_neg_seen)
                                        s->s3->tmp.next_state=SSL3_ST_SR_NEXT_PROTO_A;
                                else
                                        s->s3->tmp.next_state=SSL3_ST_SR_FINISHED_A;
+#endif
                                }
                        else
                                s->s3->tmp.next_state=SSL_ST_OK;
@@ -756,6 +789,14 @@ int ssl3_check_client_hello(SSL *s)
        int ok;
        long n;
 
+       /* We only allow the client to restart the handshake once per
+        * negotiation. */
+       if (s->s3->flags & SSL3_FLAGS_SGC_RESTART_DONE)
+               {
+               SSLerr(SSL_F_SSL3_CHECK_CLIENT_HELLO, SSL_R_MULTIPLE_SGC_RESTARTS);
+               return -1;
+               }
+
        /* this function is called when we really expect a Certificate message,
         * so permit appropriate message length */
        n=s->method->ssl_get_message(s,
@@ -769,9 +810,7 @@ int ssl3_check_client_hello(SSL *s)
        if (s->s3->tmp.message_type == SSL3_MT_CLIENT_HELLO)
                {
                /* Throw away what we have done so far in the current handshake,
-                * which will now be aborted. (A full SSL_clear would be too much.)
-                * I hope that tmp.dh is the only thing that may need to be cleared
-                * when a handshake is not completed ... */
+                * which will now be aborted. (A full SSL_clear would be too much.) */
 #ifndef OPENSSL_NO_DH
                if (s->s3->tmp.dh != NULL)
                        {
@@ -779,6 +818,14 @@ int ssl3_check_client_hello(SSL *s)
                        s->s3->tmp.dh = NULL;
                        }
 #endif
+#ifndef OPENSSL_NO_ECDH
+               if (s->s3->tmp.ecdh != NULL)
+                       {
+                       EC_KEY_free(s->s3->tmp.ecdh);
+                       s->s3->tmp.ecdh = NULL;
+                       }
+#endif
+               s->s3->flags |= SSL3_FLAGS_SGC_RESTART_DONE;
                return 2;
                }
        return 1;
@@ -828,7 +875,7 @@ int ssl3_get_client_hello(SSL *s)
            (s->version != DTLS1_VERSION && s->client_version < s->version))
                {
                SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_WRONG_VERSION_NUMBER);
-               if ((s->client_version>>8) == SSL3_VERSION_MAJOR) 
+               if ((s->client_version>>8) == SSL3_VERSION_MAJOR)
                        {
                        /* similar to ssl3_get_record, send alert using remote version number */
                        s->version = s->client_version;
@@ -870,6 +917,12 @@ int ssl3_get_client_hello(SSL *s)
         */
        if ((s->new_session && (s->options & SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION)))
                {
+               if (!s->session_creation_enabled)
+                       {
+                       ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
+                       SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_SESSION_MAY_NOT_BE_CREATED);
+                       goto err;
+               }
                if (!ssl_get_new_session(s,1))
                        goto err;
                }
@@ -884,6 +937,12 @@ int ssl3_get_client_hello(SSL *s)
                        goto err;
                else /* i == 0 */
                        {
+                       if (!s->session_creation_enabled)
+                               {
+                               ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
+                               SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_SESSION_MAY_NOT_BE_CREATED);
+                               goto err;
+                               }
                        if (!ssl_get_new_session(s,1))
                                goto err;
                        }
@@ -1054,13 +1113,110 @@ int ssl3_get_client_hello(SSL *s)
                        SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_CLIENTHELLO_TLSEXT);
                        goto err;
                }
+
+       /* Check if we want to use external pre-shared secret for this
+        * handshake for not reused session only. We need to generate
+        * server_random before calling tls_session_secret_cb in order to allow
+        * SessionTicket processing to use it in key derivation. */
+       {
+               unsigned long Time;
+               unsigned char *pos;
+               Time=(unsigned long)time(NULL);                 /* Time */
+               pos=s->s3->server_random;
+               l2n(Time,pos);
+               if (RAND_pseudo_bytes(pos,SSL3_RANDOM_SIZE-4) <= 0)
+                       {
+                       al=SSL_AD_INTERNAL_ERROR;
+                       goto f_err;
+                       }
+       }
+
+       if (!s->hit && s->version >= TLS1_VERSION && s->tls_session_secret_cb)
+               {
+               SSL_CIPHER *pref_cipher=NULL;
+
+               s->session->master_key_length=sizeof(s->session->master_key);
+               if(s->tls_session_secret_cb(s, s->session->master_key, &s->session->master_key_length,
+                       ciphers, &pref_cipher, s->tls_session_secret_cb_arg))
+                       {
+                       s->hit=1;
+                       s->session->ciphers=ciphers;
+                       s->session->verify_result=X509_V_OK;
+
+                       ciphers=NULL;
+
+                       /* check if some cipher was preferred by call back */
+                       pref_cipher=pref_cipher ? pref_cipher : ssl3_choose_cipher(s, s->session->ciphers, SSL_get_ciphers(s));
+                       if (pref_cipher == NULL)
+                               {
+                               al=SSL_AD_HANDSHAKE_FAILURE;
+                               SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_SHARED_CIPHER);
+                               goto f_err;
+                               }
+
+                       s->session->cipher=pref_cipher;
+
+                       if (s->cipher_list)
+                               sk_SSL_CIPHER_free(s->cipher_list);
+
+                       if (s->cipher_list_by_id)
+                               sk_SSL_CIPHER_free(s->cipher_list_by_id);
+
+                       s->cipher_list = sk_SSL_CIPHER_dup(s->session->ciphers);
+                       s->cipher_list_by_id = sk_SSL_CIPHER_dup(s->session->ciphers);
+                       }
+               }
 #endif
+
        /* Worst case, we will use the NULL compression, but if we have other
         * options, we will now look for them.  We have i-1 compression
         * algorithms from the client, starting at q. */
        s->s3->tmp.new_compression=NULL;
 #ifndef OPENSSL_NO_COMP
-       if (s->ctx->comp_methods != NULL)
+       /* This only happens if we have a cache hit */
+       if (s->session->compress_meth != 0)
+               {
+               int m, comp_id = s->session->compress_meth;
+               /* Perform sanity checks on resumed compression algorithm */
+               /* Can't disable compression */
+               if (s->options & SSL_OP_NO_COMPRESSION)
+                       {
+                       al=SSL_AD_INTERNAL_ERROR;
+                       SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_INCONSISTENT_COMPRESSION);
+                       goto f_err;
+                       }
+               /* Look for resumed compression method */
+               for (m = 0; m < sk_SSL_COMP_num(s->ctx->comp_methods); m++)
+                       {
+                       comp=sk_SSL_COMP_value(s->ctx->comp_methods,m);
+                       if (comp_id == comp->id)
+                               {
+                               s->s3->tmp.new_compression=comp;
+                               break;
+                               }
+                       }
+               if (s->s3->tmp.new_compression == NULL)
+                       {
+                       al=SSL_AD_INTERNAL_ERROR;
+                       SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_INVALID_COMPRESSION_ALGORITHM);
+                       goto f_err;
+                       }
+               /* Look for resumed method in compression list */
+               for (m = 0; m < i; m++)
+                       {
+                       if (q[m] == comp_id)
+                               break;
+                       }
+               if (m >= i)
+                       {
+                       al=SSL_AD_ILLEGAL_PARAMETER;
+                       SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_REQUIRED_COMPRESSSION_ALGORITHM_MISSING);
+                       goto f_err;
+                       }
+               }
+       else if (s->hit)
+               comp = NULL;
+       else if (!(s->options & SSL_OP_NO_COMPRESSION) && s->ctx->comp_methods)
                { /* See if we have a match */
                int m,nn,o,v,done=0;
 
@@ -1084,22 +1240,15 @@ int ssl3_get_client_hello(SSL *s)
                else
                        comp=NULL;
                }
-#endif
-
-       /* TLS does not mind if there is extra stuff */
-#if 0   /* SSL 3.0 does not mind either, so we should disable this test
-         * (was enabled in 0.9.6d through 0.9.6j and 0.9.7 through 0.9.7b,
-         * in earlier SSLeay/OpenSSL releases this test existed but was buggy) */
-       if (s->version == SSL3_VERSION)
+#else
+       /* If compression is disabled we'd better not try to resume a session
+        * using compression.
+        */
+       if (s->session->compress_meth != 0)
                {
-               if (p < (d+n))
-                       {
-                       /* wrong number of bytes,
-                        * there could be more to follow */
-                       al=SSL_AD_DECODE_ERROR;
-                       SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH);
-                       goto f_err;
-                       }
+               al=SSL_AD_INTERNAL_ERROR;
+               SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_INCONSISTENT_COMPRESSION);
+               goto f_err;
                }
 #endif
 
@@ -1148,7 +1297,7 @@ int ssl3_get_client_hello(SSL *s)
                        for (i=0; i<sk_SSL_CIPHER_num(sk); i++)
                                {
                                c=sk_SSL_CIPHER_value(sk,i);
-                               if (c->algorithms & SSL_eNULL)
+                               if (c->algorithm_enc & SSL_eNULL)
                                        nc=c;
                                if (SSL_C_IS_EXPORT(c))
                                        ec=c;
@@ -1164,6 +1313,9 @@ int ssl3_get_client_hello(SSL *s)
 #endif
                s->s3->tmp.new_cipher=s->session->cipher;
                }
+
+       if (!ssl3_digest_cached_records(s))
+               goto f_err;
        
        /* we now have the following setup. 
         * client_random
@@ -1192,24 +1344,22 @@ int ssl3_send_server_hello(SSL *s)
        unsigned char *buf;
        unsigned char *p,*d;
        int i,sl;
-       unsigned long l,Time;
+       unsigned long l;
+#ifdef OPENSSL_NO_TLSEXT
+       unsigned long Time;
+#endif
 
        if (s->state == SSL3_ST_SW_SRVR_HELLO_A)
                {
                buf=(unsigned char *)s->init_buf->data;
-               if (!s->s3->snap_start_requested)
-                       {
-                       p=s->s3->server_random;
-                       Time=(unsigned long)time(NULL);                 /* Time */
-                       l2n(Time,p);
-                       if (RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0)
-                               return -1;
-                       }
-               else if (s->s3->server_random_suggestion_valid == 0)
-                       {
-                       return SERVER_RANDOM_VALIDATION_PENDING;
-                       }
-
+#ifdef OPENSSL_NO_TLSEXT
+               p=s->s3->server_random;
+               /* Generate server_random if it was not needed previously */
+               Time=(unsigned long)time(NULL);                 /* Time */
+               l2n(Time,p);
+               if (RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0)
+                       return -1;
+#endif
                /* Do the message type and length last */
                d=p= &(buf[4]);
 
@@ -1263,6 +1413,11 @@ int ssl3_send_server_hello(SSL *s)
                        *(p++)=s->s3->tmp.new_compression->id;
 #endif
 #ifndef OPENSSL_NO_TLSEXT
+               if (ssl_prepare_serverhello_tlsext(s) <= 0)
+                       {
+                       SSLerr(SSL_F_SSL3_SEND_SERVER_HELLO,SSL_R_SERVERHELLO_TLSEXT);
+                       return -1;
+                       }
                if ((p = ssl_add_serverhello_tlsext(s, p, buf+SSL3_RT_MAX_PLAIN_LENGTH)) == NULL)
                        {
                        SSLerr(SSL_F_SSL3_SEND_SERVER_HELLO,ERR_R_INTERNAL_ERROR);
@@ -1342,7 +1497,7 @@ int ssl3_send_server_key_exchange(SSL *s)
        EVP_MD_CTX_init(&md_ctx);
        if (s->state == SSL3_ST_SW_KEY_EXCH_A)
                {
-               type=s->s3->tmp.new_cipher->algorithms & SSL_MKEY_MASK;
+               type=s->s3->tmp.new_cipher->algorithm_mkey;
                cert=s->cert;
 
                buf=s->init_buf;
@@ -1396,7 +1551,6 @@ int ssl3_send_server_key_exchange(SSL *s)
 
                        if (s->s3->tmp.dh != NULL)
                                {
-                               DH_free(dh);
                                SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);
                                goto err;
                                }
@@ -1437,7 +1591,7 @@ int ssl3_send_server_key_exchange(SSL *s)
                else 
 #endif
 #ifndef OPENSSL_NO_ECDH
-                       if (type & SSL_kECDHE)
+                       if (type & SSL_kEECDH)
                        {
                        const EC_GROUP *group;
 
@@ -1457,7 +1611,6 @@ int ssl3_send_server_key_exchange(SSL *s)
 
                        if (s->s3->tmp.ecdh != NULL)
                                {
-                               EC_KEY_free(s->s3->tmp.ecdh); 
                                SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);
                                goto err;
                                }
@@ -1468,12 +1621,11 @@ int ssl3_send_server_key_exchange(SSL *s)
                                SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_ECDH_LIB);
                                goto err;
                                }
-                       if (!EC_KEY_up_ref(ecdhp))
+                       if ((ecdh = EC_KEY_dup(ecdhp)) == NULL)
                                {
                                SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_ECDH_LIB);
                                goto err;
                                }
-                       ecdh = ecdhp;
 
                        s->s3->tmp.ecdh=ecdh;
                        if ((EC_KEY_get0_public_key(ecdh) == NULL) ||
@@ -1507,7 +1659,7 @@ int ssl3_send_server_key_exchange(SSL *s)
                         * supported named curves, curve_id is non-zero.
                         */
                        if ((curve_id = 
-                           nid2curve_id(EC_GROUP_get_curve_name(group)))
+                           tls1_ec_nid2curve_id(EC_GROUP_get_curve_name(group)))
                            == 0)
                                {
                                SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNSUPPORTED_ELLIPTIC_CURVE);
@@ -1564,6 +1716,14 @@ int ssl3_send_server_key_exchange(SSL *s)
                        }
                else 
 #endif /* !OPENSSL_NO_ECDH */
+#ifndef OPENSSL_NO_PSK
+                       if (type & SSL_kPSK)
+                               {
+                               /* reserve size for record length and PSK identity hint*/
+                               n+=2+strlen(s->ctx->psk_identity_hint);
+                               }
+                       else
+#endif /* !OPENSSL_NO_PSK */
                        {
                        al=SSL_AD_HANDSHAKE_FAILURE;
                        SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE);
@@ -1575,7 +1735,8 @@ int ssl3_send_server_key_exchange(SSL *s)
                        n+=2+nr[i];
                        }
 
-               if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL))
+               if (!(s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL)
+                       && !(s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK))
                        {
                        if ((pkey=ssl_get_sign_pkey(s,s->s3->tmp.new_cipher))
                                == NULL)
@@ -1607,7 +1768,7 @@ int ssl3_send_server_key_exchange(SSL *s)
                        }
 
 #ifndef OPENSSL_NO_ECDH
-               if (type & SSL_kECDHE
+               if (type & SSL_kEECDH
                        {
                        /* XXX: For now, we only support named (not generic) curves.
                         * In this situation, the serverKeyExchange message has:
@@ -1627,10 +1788,21 @@ int ssl3_send_server_key_exchange(SSL *s)
                            (unsigned char *)encodedPoint, 
                            encodedlen);
                        OPENSSL_free(encodedPoint);
+                       encodedPoint = NULL;
                        p += encodedlen;
                        }
 #endif
 
+#ifndef OPENSSL_NO_PSK
+               if (type & SSL_kPSK)
+                       {
+                       /* copy PSK identity hint */
+                       s2n(strlen(s->ctx->psk_identity_hint), p); 
+                       strncpy((char *)p, s->ctx->psk_identity_hint, strlen(s->ctx->psk_identity_hint));
+                       p+=strlen(s->ctx->psk_identity_hint);
+                       }
+#endif
+
                /* not anonymous */
                if (pkey != NULL)
                        {
@@ -1643,8 +1815,6 @@ int ssl3_send_server_key_exchange(SSL *s)
                                j=0;
                                for (num=2; num > 0; num--)
                                        {
-                                       EVP_MD_CTX_set_flags(&md_ctx,
-                                               EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
                                        EVP_DigestInit_ex(&md_ctx,(num == 2)
                                                ?s->ctx->md5:s->ctx->sha1, NULL);
                                        EVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
@@ -1828,7 +1998,7 @@ int ssl3_get_client_key_exchange(SSL *s)
        {
        int i,al,ok;
        long n;
-       unsigned long l;
+       unsigned long alg_k;
        unsigned char *p;
 #ifndef OPENSSL_NO_RSA
        RSA *rsa=NULL;
@@ -1839,7 +2009,7 @@ int ssl3_get_client_key_exchange(SSL *s)
        DH *dh_srvr;
 #endif
 #ifndef OPENSSL_NO_KRB5
-        KSSL_ERR kssl_err;
+       KSSL_ERR kssl_err;
 #endif /* OPENSSL_NO_KRB5 */
 
 #ifndef OPENSSL_NO_ECDH
@@ -1859,10 +2029,10 @@ int ssl3_get_client_key_exchange(SSL *s)
        if (!ok) return((int)n);
        p=(unsigned char *)s->init_msg;
 
-       l=s->s3->tmp.new_cipher->algorithms;
+       alg_k=s->s3->tmp.new_cipher->algorithm_mkey;
 
 #ifndef OPENSSL_NO_RSA
-       if (l & SSL_kRSA)
+       if (alg_k & SSL_kRSA)
                {
                /* FIX THIS UP EAY EAY EAY EAY */
                if (s->s3->tmp.use_rsa_tmp)
@@ -1893,9 +2063,8 @@ int ssl3_get_client_key_exchange(SSL *s)
                        rsa=pkey->pkey.rsa;
                        }
 
-               /* TLS and [incidentally] DTLS, including pre-0.9.8f */
-               if (s->version > SSL3_VERSION &&
-                   s->client_version != DTLS1_BAD_VER)
+               /* TLS and [incidentally] DTLS{0xFEFF} */
+               if (s->version > SSL3_VERSION && s->version != DTLS1_BAD_VER)
                        {
                        n2s(p,i);
                        if (n != i+2)
@@ -1969,7 +2138,7 @@ int ssl3_get_client_key_exchange(SSL *s)
        else
 #endif
 #ifndef OPENSSL_NO_DH
-               if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
+               if (alg_k & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
                {
                n2s(p,i);
                if (n != i+2)
@@ -2016,6 +2185,7 @@ int ssl3_get_client_key_exchange(SSL *s)
                if (i <= 0)
                        {
                        SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
+                       BN_clear_free(pub);
                        goto err;
                        }
 
@@ -2032,30 +2202,30 @@ int ssl3_get_client_key_exchange(SSL *s)
        else
 #endif
 #ifndef OPENSSL_NO_KRB5
-        if (l & SSL_kKRB5)
-                {
-                krb5_error_code                krb5rc;
+       if (alg_k & SSL_kKRB5)
+               {
+               krb5_error_code         krb5rc;
                krb5_data               enc_ticket;
                krb5_data               authenticator;
                krb5_data               enc_pms;
-                KSSL_CTX               *kssl_ctx = s->kssl_ctx;
+               KSSL_CTX                *kssl_ctx = s->kssl_ctx;
                EVP_CIPHER_CTX          ciph_ctx;
-               EVP_CIPHER              *enc = NULL;
+               const EVP_CIPHER        *enc = NULL;
                unsigned char           iv[EVP_MAX_IV_LENGTH];
                unsigned char           pms[SSL_MAX_MASTER_KEY_LENGTH
-                                               + EVP_MAX_BLOCK_LENGTH];
-               int                     padl, outl;
+                                              + EVP_MAX_BLOCK_LENGTH];
+               int                  padl, outl;
                krb5_timestamp          authtime = 0;
                krb5_ticket_times       ttimes;
 
                EVP_CIPHER_CTX_init(&ciph_ctx);
 
-                if (!kssl_ctx)  kssl_ctx = kssl_ctx_new();
+               if (!kssl_ctx)  kssl_ctx = kssl_ctx_new();
 
                n2s(p,i);
                enc_ticket.length = i;
 
-               if (n < (int)enc_ticket.length + 6)
+               if (n < (long)(enc_ticket.length + 6))
                        {
                        SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
                                SSL_R_DATA_LENGTH_TOO_LONG);
@@ -2068,7 +2238,7 @@ int ssl3_get_client_key_exchange(SSL *s)
                n2s(p,i);
                authenticator.length = i;
 
-               if (n < (int)(enc_ticket.length + authenticator.length) + 6)
+               if (n < (long)(enc_ticket.length + authenticator.length + 6))
                        {
                        SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
                                SSL_R_DATA_LENGTH_TOO_LONG);
@@ -2101,19 +2271,19 @@ int ssl3_get_client_key_exchange(SSL *s)
                        goto err;
                        }
 
-                if ((krb5rc = kssl_sget_tkt(kssl_ctx, &enc_ticket, &ttimes,
+               if ((krb5rc = kssl_sget_tkt(kssl_ctx, &enc_ticket, &ttimes,
                                        &kssl_err)) != 0)
-                        {
+                       {
 #ifdef KSSL_DEBUG
-                        printf("kssl_sget_tkt rtn %d [%d]\n",
-                                krb5rc, kssl_err.reason);
-                        if (kssl_err.text)
-                                printf("kssl_err text= %s\n", kssl_err.text);
+                       printf("kssl_sget_tkt rtn %d [%d]\n",
+                               krb5rc, kssl_err.reason);
+                       if (kssl_err.text)
+                               printf("kssl_err text= %s\n", kssl_err.text);
 #endif /* KSSL_DEBUG */
-                        SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
-                                kssl_err.reason);
-                        goto err;
-                        }
+                       SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
+                               kssl_err.reason);
+                       goto err;
+                       }
 
                /*  Note: no authenticator is not considered an error,
                **  but will return authtime == 0.
@@ -2122,29 +2292,29 @@ int ssl3_get_client_key_exchange(SSL *s)
                                        &authtime, &kssl_err)) != 0)
                        {
 #ifdef KSSL_DEBUG
-                        printf("kssl_check_authent rtn %d [%d]\n",
-                                krb5rc, kssl_err.reason);
-                        if (kssl_err.text)
-                                printf("kssl_err text= %s\n", kssl_err.text);
+                       printf("kssl_check_authent rtn %d [%d]\n",
+                               krb5rc, kssl_err.reason);
+                       if (kssl_err.text)
+                               printf("kssl_err text= %s\n", kssl_err.text);
 #endif /* KSSL_DEBUG */
-                        SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
-                                kssl_err.reason);
-                        goto err;
+                       SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
+                               kssl_err.reason);
+                       goto err;
                        }
 
                if ((krb5rc = kssl_validate_times(authtime, &ttimes)) != 0)
                        {
                        SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, krb5rc);
-                        goto err;
+                       goto err;
                        }
 
 #ifdef KSSL_DEBUG
-                kssl_ctx_show(kssl_ctx);
+               kssl_ctx_show(kssl_ctx);
 #endif /* KSSL_DEBUG */
 
                enc = kssl_map_enc(kssl_ctx->enctype);
-                if (enc == NULL)
-                    goto err;
+               if (enc == NULL)
+                   goto err;
 
                memset(iv, 0, sizeof iv);       /* per RFC 1510 */
 
@@ -2191,7 +2361,7 @@ int ssl3_get_client_key_exchange(SSL *s)
                     * (Perhaps we should have a separate BUG value for the Kerberos cipher)
                     */
                    if (!(s->options & SSL_OP_TLS_ROLLBACK_BUG))
-                       {
+                       {
                        SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
                               SSL_AD_DECODE_ERROR);
                        goto err;
@@ -2200,32 +2370,32 @@ int ssl3_get_client_key_exchange(SSL *s)
 
                EVP_CIPHER_CTX_cleanup(&ciph_ctx);
 
-                s->session->master_key_length=
-                        s->method->ssl3_enc->generate_master_secret(s,
-                                s->session->master_key, pms, outl);
+               s->session->master_key_length=
+                       s->method->ssl3_enc->generate_master_secret(s,
+                               s->session->master_key, pms, outl);
 
-                if (kssl_ctx->client_princ)
-                        {
-                        size_t len = strlen(kssl_ctx->client_princ);
-                        if ( len < SSL_MAX_KRB5_PRINCIPAL_LENGTH ) 
-                                {
-                                s->session->krb5_client_princ_len = len;
-                                memcpy(s->session->krb5_client_princ,kssl_ctx->client_princ,len);
-                                }
-                        }
+               if (kssl_ctx->client_princ)
+                       {
+                       size_t len = strlen(kssl_ctx->client_princ);
+                       if ( len < SSL_MAX_KRB5_PRINCIPAL_LENGTH ) 
+                               {
+                               s->session->krb5_client_princ_len = len;
+                               memcpy(s->session->krb5_client_princ,kssl_ctx->client_princ,len);
+                               }
+                       }
 
 
-                /*  Was doing kssl_ctx_free() here,
+               /*  Was doing kssl_ctx_free() here,
                **  but it caused problems for apache.
-                **  kssl_ctx = kssl_ctx_free(kssl_ctx);
-                **  if (s->kssl_ctx)  s->kssl_ctx = NULL;
-                */
-                }
+               **  kssl_ctx = kssl_ctx_free(kssl_ctx);
+               **  if (s->kssl_ctx)  s->kssl_ctx = NULL;
+               */
+               }
        else
 #endif /* OPENSSL_NO_KRB5 */
 
 #ifndef OPENSSL_NO_ECDH
-               if ((l & SSL_kECDH) || (l & SSL_kECDHE))
+               if (alg_k & (SSL_kEECDH|SSL_kECDHr|SSL_kECDHe))
                {
                int ret = 1;
                int field_size = 0;
@@ -2233,18 +2403,18 @@ int ssl3_get_client_key_exchange(SSL *s)
                const EC_GROUP *group;
                const BIGNUM *priv_key;
 
-                /* initialize structures for server's ECDH key pair */
+               /* initialize structures for server's ECDH key pair */
                if ((srvr_ecdh = EC_KEY_new()) == NULL) 
                        {
-                       SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
+                       SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
                            ERR_R_MALLOC_FAILURE);
-                       goto err;
+                       goto err;
                        }
 
                /* Let's get server private key and group information */
-               if (l & SSL_kECDH) 
+               if (alg_k & (SSL_kECDHr|SSL_kECDHe))
                        { 
-                        /* use the certificate */
+                       /* use the certificate */
                        tkey = s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec;
                        }
                else
@@ -2274,20 +2444,20 @@ int ssl3_get_client_key_exchange(SSL *s)
                        goto err;
                        }
 
-                if (n == 0L) 
-                        {
+               if (n == 0L) 
+                       {
                        /* Client Publickey was in Client Certificate */
 
-                        if (l & SSL_kECDHE) 
+                        if (alg_k & SSL_kEECDH)
                                 {
                                 al=SSL_AD_HANDSHAKE_FAILURE;
                                 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_ECDH_KEY);
                                 goto f_err;
                                 }
-                        if (((clnt_pub_pkey=X509_get_pubkey(s->session->peer))
+                       if (((clnt_pub_pkey=X509_get_pubkey(s->session->peer))
                            == NULL) || 
                            (clnt_pub_pkey->type != EVP_PKEY_EC))
-                               {
+                               {
                                /* XXX: For now, we do not support client
                                 * authentication using ECDH certificates
                                 * so this branch (n == 0L) of the code is
@@ -2299,11 +2469,11 @@ int ssl3_get_client_key_exchange(SSL *s)
                                 * the two ECDH shares are for the same
                                 * group.
                                 */
-                               al=SSL_AD_HANDSHAKE_FAILURE;
-                               SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
+                               al=SSL_AD_HANDSHAKE_FAILURE;
+                               SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
                                    SSL_R_UNABLE_TO_DECODE_ECDH_CERTS);
-                               goto f_err;
-                               }
+                               goto f_err;
+                               }
 
                        if (EC_POINT_copy(clnt_ecpoint,
                            EC_KEY_get0_public_key(clnt_pub_pkey->pkey.ec)) == 0)
@@ -2312,10 +2482,10 @@ int ssl3_get_client_key_exchange(SSL *s)
                                        ERR_R_EC_LIB);
                                goto err;
                                }
-                        ret = 2; /* Skip certificate verify processing */
-                        }
-                else
-                        {
+                       ret = 2; /* Skip certificate verify processing */
+                       }
+               else
+                       {
                        /* Get client's public key from encoded point
                         * in the ClientKeyExchange message.
                         */
@@ -2326,21 +2496,27 @@ int ssl3_get_client_key_exchange(SSL *s)
                                goto err;
                                }
 
-                        /* Get encoded point length */
-                        i = *p; 
+                       /* Get encoded point length */
+                       i = *p; 
                        p += 1;
-                        if (EC_POINT_oct2point(group, 
+                       if (n != 1 + i)
+                               {
+                               SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
+                                   ERR_R_EC_LIB);
+                               goto err;
+                               }
+                       if (EC_POINT_oct2point(group, 
                            clnt_ecpoint, p, i, bn_ctx) == 0)
                                {
                                SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
                                    ERR_R_EC_LIB);
                                goto err;
                                }
-                        /* p is pointing to somewhere in the buffer
-                         * currently, so set it to the start 
-                         */ 
-                        p=(unsigned char *)s->init_buf->data;
-                        }
+                       /* p is pointing to somewhere in the buffer
+                        * currently, so set it to the start 
+                        */ 
+                       p=(unsigned char *)s->init_buf->data;
+                       }
 
                /* Compute the shared pre-master secret */
                field_size = EC_GROUP_get_degree(group);
@@ -2351,28 +2527,197 @@ int ssl3_get_client_key_exchange(SSL *s)
                        goto err;
                        }
                i = ECDH_compute_key(p, (field_size+7)/8, clnt_ecpoint, srvr_ecdh, NULL);
-                if (i <= 0)
-                        {
-                        SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
+               if (i <= 0)
+                       {
+                       SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
                            ERR_R_ECDH_LIB);
-                        goto err;
-                        }
+                       goto err;
+                       }
 
                EVP_PKEY_free(clnt_pub_pkey);
                EC_POINT_free(clnt_ecpoint);
-               if (srvr_ecdh != NULL) 
-                       EC_KEY_free(srvr_ecdh);
+               EC_KEY_free(srvr_ecdh);
                BN_CTX_free(bn_ctx);
+               EC_KEY_free(s->s3->tmp.ecdh);
+               s->s3->tmp.ecdh = NULL; 
 
                /* Compute the master secret */
-                s->session->master_key_length = s->method->ssl3_enc-> \
+               s->session->master_key_length = s->method->ssl3_enc-> \
                    generate_master_secret(s, s->session->master_key, p, i);
                
-                OPENSSL_cleanse(p, i);
-                return (ret);
+               OPENSSL_cleanse(p, i);
+               return (ret);
                }
        else
 #endif
+#ifndef OPENSSL_NO_PSK
+               if (alg_k & SSL_kPSK)
+                       {
+                       unsigned char *t = NULL;
+                       unsigned char psk_or_pre_ms[PSK_MAX_PSK_LEN*2+4];
+                       unsigned int pre_ms_len = 0, psk_len = 0;
+                       int psk_err = 1;
+                       char tmp_id[PSK_MAX_IDENTITY_LEN+1];
+
+                       al=SSL_AD_HANDSHAKE_FAILURE;
+
+                       n2s(p,i);
+                       if (n != i+2)
+                               {
+                               SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
+                                       SSL_R_LENGTH_MISMATCH);
+                               goto psk_err;
+                               }
+                       if (i > PSK_MAX_IDENTITY_LEN)
+                               {
+                               SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
+                                       SSL_R_DATA_LENGTH_TOO_LONG);
+                               goto psk_err;
+                               }
+                       if (s->psk_server_callback == NULL)
+                               {
+                               SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
+                                      SSL_R_PSK_NO_SERVER_CB);
+                               goto psk_err;
+                               }
+
+                       /* Create guaranteed NULL-terminated identity
+                        * string for the callback */
+                       memcpy(tmp_id, p, i);
+                       memset(tmp_id+i, 0, PSK_MAX_IDENTITY_LEN+1-i);
+                       psk_len = s->psk_server_callback(s, tmp_id,
+                               psk_or_pre_ms, sizeof(psk_or_pre_ms));
+                       OPENSSL_cleanse(tmp_id, PSK_MAX_IDENTITY_LEN+1);
+
+                       if (psk_len > PSK_MAX_PSK_LEN)
+                               {
+                               SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
+                                       ERR_R_INTERNAL_ERROR);
+                               goto psk_err;
+                               }
+                       else if (psk_len == 0)
+                               {
+                               /* PSK related to the given identity not found */
+                               SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
+                                      SSL_R_PSK_IDENTITY_NOT_FOUND);
+                               al=SSL_AD_UNKNOWN_PSK_IDENTITY;
+                               goto psk_err;
+                               }
+
+                       /* create PSK pre_master_secret */
+                       pre_ms_len=2+psk_len+2+psk_len;
+                       t = psk_or_pre_ms;
+                       memmove(psk_or_pre_ms+psk_len+4, psk_or_pre_ms, psk_len);
+                       s2n(psk_len, t);
+                       memset(t, 0, psk_len);
+                       t+=psk_len;
+                       s2n(psk_len, t);
+
+                       if (s->session->psk_identity != NULL)
+                               OPENSSL_free(s->session->psk_identity);
+                       s->session->psk_identity = BUF_strdup((char *)p);
+                       if (s->session->psk_identity == NULL)
+                               {
+                               SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
+                                       ERR_R_MALLOC_FAILURE);
+                               goto psk_err;
+                               }
+
+                       if (s->session->psk_identity_hint != NULL)
+                               OPENSSL_free(s->session->psk_identity_hint);
+                       s->session->psk_identity_hint = BUF_strdup(s->ctx->psk_identity_hint);
+                       if (s->ctx->psk_identity_hint != NULL &&
+                               s->session->psk_identity_hint == NULL)
+                               {
+                               SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
+                                       ERR_R_MALLOC_FAILURE);
+                               goto psk_err;
+                               }
+
+                       s->session->master_key_length=
+                               s->method->ssl3_enc->generate_master_secret(s,
+                                       s->session->master_key, psk_or_pre_ms, pre_ms_len);
+                       psk_err = 0;
+               psk_err:
+                       OPENSSL_cleanse(psk_or_pre_ms, sizeof(psk_or_pre_ms));
+                       if (psk_err != 0)
+                               goto f_err;
+                       }
+               else
+#endif
+               if (alg_k & SSL_kGOST) 
+                       {
+                       int ret = 0;
+                       EVP_PKEY_CTX *pkey_ctx;
+                       EVP_PKEY *client_pub_pkey = NULL, *pk = NULL;
+                       unsigned char premaster_secret[32], *start;
+                       size_t outlen=32, inlen;
+                       unsigned long alg_a;
+
+                       /* Get our certificate private key*/
+                       alg_a = s->s3->tmp.new_cipher->algorithm_auth;
+                       if (alg_a & SSL_aGOST94)
+                               pk = s->cert->pkeys[SSL_PKEY_GOST94].privatekey;
+                       else if (alg_a & SSL_aGOST01)
+                               pk = s->cert->pkeys[SSL_PKEY_GOST01].privatekey;
+
+                       pkey_ctx = EVP_PKEY_CTX_new(pk,NULL);
+                       EVP_PKEY_decrypt_init(pkey_ctx);
+                       /* If client certificate is present and is of the same type, maybe
+                        * use it for key exchange.  Don't mind errors from
+                        * EVP_PKEY_derive_set_peer, because it is completely valid to use
+                        * a client certificate for authorization only. */
+                       client_pub_pkey = X509_get_pubkey(s->session->peer);
+                       if (client_pub_pkey)
+                               {
+                               if (EVP_PKEY_derive_set_peer(pkey_ctx, client_pub_pkey) <= 0)
+                                       ERR_clear_error();
+                               }
+                       /* Decrypt session key */
+                       if ((*p!=( V_ASN1_SEQUENCE| V_ASN1_CONSTRUCTED))) 
+                               {
+                               SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_DECRYPTION_FAILED);
+                               goto gerr;
+                               }
+                       if (p[1] == 0x81)
+                               {
+                               start = p+3;
+                               inlen = p[2];
+                               }
+                       else if (p[1] < 0x80)
+                               {
+                               start = p+2;
+                               inlen = p[1];
+                               }
+                       else
+                               {
+                               SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_DECRYPTION_FAILED);
+                               goto gerr;
+                               }
+                       if (EVP_PKEY_decrypt(pkey_ctx,premaster_secret,&outlen,start,inlen) <=0) 
+
+                               {
+                               SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_DECRYPTION_FAILED);
+                               goto gerr;
+                               }
+                       /* Generate master secret */
+                       s->session->master_key_length=
+                               s->method->ssl3_enc->generate_master_secret(s,
+                                       s->session->master_key,premaster_secret,32);
+                       /* Check if pubkey from client certificate was used */
+                       if (EVP_PKEY_CTX_ctrl(pkey_ctx, -1, -1, EVP_PKEY_CTRL_PEER_KEY, 2, NULL) > 0)
+                               ret = 2;
+                       else
+                               ret = 1;
+               gerr:
+                       EVP_PKEY_free(client_pub_pkey);
+                       EVP_PKEY_CTX_free(pkey_ctx);
+                       if (ret)
+                               return ret;
+                       else
+                               goto err;
+                       }
+               else
                {
                al=SSL_AD_HANDSHAKE_FAILURE;
                SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
@@ -2396,70 +2741,6 @@ err:
        return(-1);
        }
 
-/* ssl3_get_next_proto reads a Next Protocol Negotiation handshake message. It
- * sets the next_proto member in s if found */
-int ssl3_get_next_proto(SSL *s)
-       {
-       int ok;
-       unsigned proto_len, padding_len;
-       long n;
-       const unsigned char *p;
-
-       /* Clients cannot send a NextProtocol message if we didn't see the
-        * extension in their ClientHello */
-       if (!s->s3->next_proto_neg_seen) {
-               SSLerr(SSL_F_SSL3_GET_NEXT_PROTO,SSL_R_GOT_NEXT_PROTO_WITHOUT_EXTENSION);
-               return -1;
-       }
-
-       n=s->method->ssl_get_message(s,
-               SSL3_ST_SR_NEXT_PROTO_A,
-               SSL3_ST_SR_NEXT_PROTO_B,
-               SSL3_MT_NEXT_PROTO,
-               129,
-               &ok);
-
-       if (!ok)
-               return((int)n);
-
-       /* s->state doesn't reflect whether ChangeCipherSpec has been received
-        * in this handshake, but s->s3->change_cipher_spec does (will be reset
-        * by ssl3_get_finished). */
-       if (!s->s3->change_cipher_spec)
-               {
-               SSLerr(SSL_F_SSL3_GET_NEXT_PROTO,SSL_R_GOT_NEXT_PROTO_BEFORE_A_CCS);
-               return -1;
-               }
-
-       if (n < 2)
-               return 0;  // The body must be > 1 bytes long */
-
-       p=(unsigned char *)s->init_msg;
-
-       /* The payload looks like:
-        *   uint8 proto_len;
-        *   uint8 proto[proto_len];
-        *   uint8 padding_len;
-        *   uint8 padding[padding_len];
-        */
-       proto_len = p[0];
-       if (proto_len + 2 > s->init_num)
-               return 0;
-       padding_len = p[proto_len + 1];
-       if (proto_len + padding_len + 2 != s->init_num)
-               return 0;
-
-       s->next_proto_negotiated = OPENSSL_malloc(proto_len);
-       if (!s->next_proto_negotiated) {
-               SSLerr(SSL_F_SSL3_GET_NEXT_PROTO,ERR_R_MALLOC_FAILURE);
-               return 0;
-       }
-       memcpy(s->next_proto_negotiated, p + 1, proto_len);
-       s->next_proto_negotiated_len = proto_len;
-
-       return 1;
-       }
-
 int ssl3_get_cert_verify(SSL *s)
        {
        EVP_PKEY *pkey=NULL;
@@ -2526,15 +2807,25 @@ int ssl3_get_cert_verify(SSL *s)
 
        /* we now have a signature that we need to verify */
        p=(unsigned char *)s->init_msg;
-       n2s(p,i);
-       n-=2;
-       if (i > n)
+       /* Check for broken implementations of GOST ciphersuites */
+       /* If key is GOST and n is exactly 64, it is bare
+        * signature without length field */
+       if (n==64 && (pkey->type==NID_id_GostR3410_94 ||
+               pkey->type == NID_id_GostR3410_2001) )
                {
-               SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_LENGTH_MISMATCH);
-               al=SSL_AD_DECODE_ERROR;
-               goto f_err;
-               }
-
+               i=64;
+               } 
+       else 
+               {       
+               n2s(p,i);
+               n-=2;
+               if (i > n)
+                       {
+                       SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_LENGTH_MISMATCH);
+                       al=SSL_AD_DECODE_ERROR;
+                       goto f_err;
+                       }
+       }
        j=EVP_PKEY_size(pkey);
        if ((i > j) || (n > j) || (n <= 0))
                {
@@ -2597,6 +2888,28 @@ int ssl3_get_cert_verify(SSL *s)
                }
        else
 #endif
+       if (pkey->type == NID_id_GostR3410_94 || pkey->type == NID_id_GostR3410_2001)
+               {   unsigned char signature[64];
+                       int idx;
+                       EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new(pkey,NULL);
+                       EVP_PKEY_verify_init(pctx);
+                       if (i!=64) {
+                               fprintf(stderr,"GOST signature length is %d",i);
+                       }       
+                       for (idx=0;idx<64;idx++) {
+                               signature[63-idx]=p[idx];
+                       }       
+                       j=EVP_PKEY_verify(pctx,signature,64,s->s3->tmp.cert_verify_md,32);
+                       EVP_PKEY_CTX_free(pctx);
+                       if (j<=0) 
+                               {
+                               al=SSL_AD_DECRYPT_ERROR;
+                               SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,
+                                       SSL_R_BAD_ECDSA_SIGNATURE);
+                               goto f_err;
+                               }       
+               }
+       else    
                {
                SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,ERR_R_INTERNAL_ERROR);
                al=SSL_AD_UNSUPPORTED_CERTIFICATE;
@@ -2779,14 +3092,15 @@ int ssl3_send_server_certificate(SSL *s)
        if (s->state == SSL3_ST_SW_CERT_A)
                {
                x=ssl_get_server_send_cert(s);
-               if (x == NULL &&
-                        /* VRS: allow null cert if auth == KRB5 */
-                        (s->s3->tmp.new_cipher->algorithms
-                                & (SSL_MKEY_MASK|SSL_AUTH_MASK))
-                        != (SSL_aKRB5|SSL_kKRB5))
+               if (x == NULL)
                        {
-                       SSLerr(SSL_F_SSL3_SEND_SERVER_CERTIFICATE,ERR_R_INTERNAL_ERROR);
-                       return(0);
+                       /* VRS: allow null cert if auth == KRB5 */
+                       if ((s->s3->tmp.new_cipher->algorithm_auth != SSL_aKRB5) ||
+                           (s->s3->tmp.new_cipher->algorithm_mkey & SSL_kKRB5))
+                               {
+                               SSLerr(SSL_F_SSL3_SEND_SERVER_CERTIFICATE,ERR_R_INTERNAL_ERROR);
+                               return(0);
+                               }
                        }
 
                l=ssl3_output_cert_chain(s,x);
@@ -2798,70 +3112,6 @@ int ssl3_send_server_certificate(SSL *s)
        /* SSL3_ST_SW_CERT_B */
        return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
        }
-
-
-#ifndef OPENSSL_NO_ECDH
-/* This is the complement of curve_id2nid in s3_clnt.c. */
-static int nid2curve_id(int nid)
-{
-       /* ECC curves from draft-ietf-tls-ecc-01.txt (Mar 15, 2001)
-        * (no changes in draft-ietf-tls-ecc-03.txt [June 2003]) */
-       switch (nid) {
-       case NID_sect163k1: /* sect163k1 (1) */
-               return 1;
-       case NID_sect163r1: /* sect163r1 (2) */
-               return 2;
-       case NID_sect163r2: /* sect163r2 (3) */
-               return 3;
-       case NID_sect193r1: /* sect193r1 (4) */ 
-               return 4;
-       case NID_sect193r2: /* sect193r2 (5) */ 
-               return 5;
-       case NID_sect233k1: /* sect233k1 (6) */
-               return 6;
-       case NID_sect233r1: /* sect233r1 (7) */ 
-               return 7;
-       case NID_sect239k1: /* sect239k1 (8) */ 
-               return 8;
-       case NID_sect283k1: /* sect283k1 (9) */
-               return 9;
-       case NID_sect283r1: /* sect283r1 (10) */ 
-               return 10;
-       case NID_sect409k1: /* sect409k1 (11) */ 
-               return 11;
-       case NID_sect409r1: /* sect409r1 (12) */
-               return 12;
-       case NID_sect571k1: /* sect571k1 (13) */ 
-               return 13;
-       case NID_sect571r1: /* sect571r1 (14) */ 
-               return 14;
-       case NID_secp160k1: /* secp160k1 (15) */
-               return 15;
-       case NID_secp160r1: /* secp160r1 (16) */ 
-               return 16;
-       case NID_secp160r2: /* secp160r2 (17) */ 
-               return 17;
-       case NID_secp192k1: /* secp192k1 (18) */
-               return 18;
-       case NID_X9_62_prime192v1: /* secp192r1 (19) */ 
-               return 19;
-       case NID_secp224k1: /* secp224k1 (20) */ 
-               return 20;
-       case NID_secp224r1: /* secp224r1 (21) */
-               return 21;
-       case NID_secp256k1: /* secp256k1 (22) */ 
-               return 22;
-       case NID_X9_62_prime256v1: /* secp256r1 (23) */ 
-               return 23;
-       case NID_secp384r1: /* secp384r1 (24) */
-               return 24;
-       case NID_secp521r1:  /* secp521r1 (25) */       
-               return 25;
-       default:
-               return 0;
-       }
-}
-#endif
 #ifndef OPENSSL_NO_TLSEXT
 int ssl3_send_newsession_ticket(SSL *s)
        {
@@ -3004,56 +3254,72 @@ int ssl3_send_cert_status(SSL *s)
        /* SSL3_ST_SW_CERT_STATUS_B */
        return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
        }
-#endif
 
-/* ssl3_snap_start_evaluate_handshake verifies the Snap Start prediction (if
- * this is a Snap Start handshake). If it returns non-zero, then we are
- * entering recovery and |s->state| has been set accordingly. */
-static int ssl3_snap_start_evaluate_handshake(SSL* s)
+# ifndef OPENSSL_NO_NPN
+/* ssl3_get_next_proto reads a Next Protocol Negotiation handshake message. It
+ * sets the next_proto member in s if found */
+int ssl3_get_next_proto(SSL *s)
        {
-       unsigned char digest[8];
-
-       if (!s->s3->snap_start_requested)
-               return 0;
+       int ok;
+       unsigned proto_len, padding_len;
+       long n;
+       const unsigned char *p;
 
-       /* Drop the currently queued messages. Either we're entering recovery,
-        * in which case they're wrong, or we're doing snap start, in which
-        * case we don't want to send them. */
-       if (!ssl_init_wbio_buffer(s, 1 /* push new BIO */))
+       /* Clients cannot send a NextProtocol message if we didn't see the
+        * extension in their ClientHello */
+       if (!s->s3->next_proto_neg_seen)
+               {
+               SSLerr(SSL_F_SSL3_GET_NEXT_PROTO,SSL_R_GOT_NEXT_PROTO_WITHOUT_EXTENSION);
                return -1;
+               }
 
-       fnv1a64_final(digest, (FNV1A64*) s->s3->response_hash);
+       n=s->method->ssl_get_message(s,
+               SSL3_ST_SR_NEXT_PROTO_A,
+               SSL3_ST_SR_NEXT_PROTO_B,
+               SSL3_MT_NEXT_PROTO,
+               514,  /* See the payload format below */
+               &ok);
 
-       /* Turn off FNV hashing of handshake messages. */
-       s->s3->snap_start_requested = 0;
+       if (!ok)
+               return((int)n);
 
-       if (memcmp(digest, s->s3->predicted_response_hash, sizeof(digest)) != 0)
+       /* s->state doesn't reflect whether ChangeCipherSpec has been received
+        * in this handshake, but s->s3->change_cipher_spec does (will be reset
+        * by ssl3_get_finished). */
+       if (!s->s3->change_cipher_spec)
                {
-               /* The predicted handshake didn't match. */
-               ssl3_snap_start_reset_for_recovery(s);
-               s->state = SSL3_ST_SW_SRVR_HELLO_A;
-               return 1;
+               SSLerr(SSL_F_SSL3_GET_NEXT_PROTO,SSL_R_GOT_NEXT_PROTO_BEFORE_A_CCS);
+               return -1;
                }
 
-       return 0;
-       }
+       if (n < 2)
+               return 0;  /* The body must be > 1 bytes long */
 
-/* ssl3_snap_start_reset_for_recovery is called is called when a Snap Start
- * handshake is impossible because either the application layer has rejected
- * the client's suggested server random, or predicated_response_hash failed to
- * match response_hash */
-int ssl3_snap_start_reset_for_recovery(SSL* s)
-       {
-       s->s3->snap_start_requested = 0;
-       s->s3->snap_start_records.left = 0;
-       s->init_num = 0;
+       p=(unsigned char *)s->init_msg;
 
-       /* Reset the handshake hash and hash in the original ClientHello. */
-       ssl3_init_finished_mac(s);
-       ssl3_finish_mac(s, s->s3->snap_start_client_hello.buf, s->s3->snap_start_client_hello.left);
+       /* The payload looks like:
+        *   uint8 proto_len;
+        *   uint8 proto[proto_len];
+        *   uint8 padding_len;
+        *   uint8 padding[padding_len];
+        */
+       proto_len = p[0];
+       if (proto_len + 2 > s->init_num)
+               return 0;
+       padding_len = p[proto_len + 1];
+       if (proto_len + padding_len + 2 != s->init_num)
+               return 0;
 
-       OPENSSL_free(s->s3->snap_start_client_hello.buf);
-       s->s3->snap_start_client_hello.buf = NULL;
+       s->next_proto_negotiated = OPENSSL_malloc(proto_len);
+       if (!s->next_proto_negotiated)
+               {
+               SSLerr(SSL_F_SSL3_GET_NEXT_PROTO,ERR_R_MALLOC_FAILURE);
+               return 0;
+               }
+       memcpy(s->next_proto_negotiated, p + 1, proto_len);
+       s->next_proto_negotiated_len = proto_len;
 
-       return 0;
+       return 1;
        }
+# endif
+#endif
index 85ab2f6..180f3a2 100644 (file)
@@ -30,7 +30,7 @@ $!       VAXC  For VAX C.
 $!        DECC  For DEC C.
 $!        GNUC  For GNU C.
 $!
-$!  If you don't speficy a compiler, it will try to determine which
+$!  If you don't specify a compiler, it will try to determine which
 $!  "C" compiler to use.
 $!
 $!  P4, if defined, sets a TCP/IP library to use, through one of the following
@@ -42,11 +42,33 @@ $!  SOCKETSHR       for SOCKETSHR+NETLIB
 $!
 $!  P5, if defined, sets a compiler thread NOT needed on OpenVMS 7.1 (and up)
 $!
+$!  P6, if defined, specifies the C pointer size.  Ignored on VAX.
+$!      ("64=ARGV" gives more efficient code with HP C V7.3 or newer.)
+$!      Supported values are:
+$!
+$!      ""       Compile with default (/NOPOINTER_SIZE)
+$!      32       Compile with /POINTER_SIZE=32 (SHORT)
+$!      64       Compile with /POINTER_SIZE=64[=ARGV] (LONG[=ARGV])
+$!               (Automatically select ARGV if compiler supports it.)
+$!      64=      Compile with /POINTER_SIZE=64 (LONG).
+$!      64=ARGV  Compile with /POINTER_SIZE=64=ARGV (LONG=ARGV).
+$!
+$!  P7, if defined, specifies a directory where ZLIB files (zlib.h,
+$!  libz.olb) may be found.  Optionally, a non-default object library
+$!  name may be included ("dev:[dir]libz_64.olb", for example).
+$!
+$!
+$! Announce/identify.
+$!
+$ proc = f$environment( "procedure")
+$ write sys$output "@@@ "+ -
+   f$parse( proc, , , "name")+ f$parse( proc, , , "type")
 $!
 $! Define A TCP/IP Library That We Will Need To Link To.
 $! (That Is, If We Need To Link To One.)
 $!
 $ TCPIP_LIB = ""
+$ ZLIB_LIB = ""
 $!
 $! Check What Architecture We Are Using.
 $!
@@ -55,7 +77,7 @@ $ THEN
 $!
 $!  The Architecture Is VAX.
 $!
-$   ARCH := VAX
+$   ARCH = "VAX"
 $!
 $! Else...
 $!
@@ -70,17 +92,33 @@ $! End The Architecture Check.
 $!
 $ ENDIF
 $!
-$! Define The OBJ Directory.
+$ ARCHD = ARCH
+$ LIB32 = "32"
+$ OPT_FILE = ""
+$ POINTER_SIZE = ""
 $!
-$ OBJ_DIR := SYS$DISK:[-.'ARCH'.OBJ.SSL]
+$! Check To Make Sure We Have Valid Command Line Parameters.
 $!
-$! Define The EXE Directory.
+$ GOSUB CHECK_OPTIONS
 $!
-$ EXE_DIR := SYS$DISK:[-.'ARCH'.EXE.SSL]
+$! Define The OBJ and EXE Directories.
 $!
-$! Check To Make Sure We Have Valid Command Line Parameters.
+$ OBJ_DIR := SYS$DISK:[-.'ARCHD'.OBJ.SSL]
+$ EXE_DIR := SYS$DISK:[-.'ARCHD'.EXE.SSL]
 $!
-$ GOSUB CHECK_OPTIONS
+$! Specify the destination directory in any /MAP option.
+$!
+$ if (LINKMAP .eqs. "MAP")
+$ then
+$   LINKMAP = LINKMAP+ "=''EXE_DIR'"
+$ endif
+$!
+$! Add the location prefix to the linker options file name.
+$!
+$ if (OPT_FILE .nes. "")
+$ then
+$   OPT_FILE = EXE_DIR+ OPT_FILE
+$ endif
 $!
 $! Initialise logical names and such
 $!
@@ -88,7 +126,7 @@ $ GOSUB INITIALISE
 $!
 $! Tell The User What Kind of Machine We Run On.
 $!
-$ WRITE SYS$OUTPUT "Compiling On A ",ARCH," Machine."
+$ WRITE SYS$OUTPUT "Host system architecture: ''ARCHD'"
 $!
 $! Check To See If The Architecture Specific OBJ Directory Exists.
 $!
@@ -118,11 +156,15 @@ $ ENDIF
 $!
 $! Define The Library Name.
 $!
-$ SSL_LIB := 'EXE_DIR'LIBSSL.OLB
+$ SSL_LIB := 'EXE_DIR'SSL_LIBSSL'LIB32'.OLB
 $!
 $! Define The CRYPTO-LIB We Are To Use.
 $!
-$ CRYPTO_LIB := SYS$DISK:[-.'ARCH'.EXE.CRYPTO]LIBCRYPTO.OLB
+$ CRYPTO_LIB := SYS$DISK:[-.'ARCHD'.EXE.CRYPTO]SSL_LIBCRYPTO'LIB32'.OLB
+$!
+$! Set up exceptional compilations.
+$!
+$ CC5_SHOWN = 0
 $!
 $! Check To See What We Are To Do.
 $!
@@ -156,7 +198,7 @@ $! Compile The Library.
 $!
 $ LIBRARY:
 $!
-$! Check To See If We Already Have A "[.xxx.EXE.SSL]LIBSSL.OLB" Library...
+$! Check To See If We Already Have A "[.xxx.EXE.SSL]SSL_LIBSSL''LIB32'.OLB" Library...
 $!
 $ IF (F$SEARCH(SSL_LIB).EQS."")
 $ THEN
@@ -182,6 +224,8 @@ $ LIB_SSL = "s2_meth,s2_srvr,s2_clnt,s2_lib,s2_enc,s2_pkt,"+ -
            "ssl_asn1,ssl_txt,ssl_algs,"+ -
            "bio_ssl,ssl_err,kssl,t1_reneg"
 $!
+$ COMPILEWITH_CC5 = ""
+$!
 $! Tell The User That We Are Compiling The Library.
 $!
 $ WRITE SYS$OUTPUT "Building The ",SSL_LIB," Library."
@@ -295,42 +339,47 @@ $! End The SSL_TASK.C File Check.
 $!
 $ ENDIF
 $!
+$ COMPILEWITH_CC5 = "" !!! ",ssl_task,"
+$!
+$! Tell The User We Are Creating The SSL_TASK.
+$!
 $! Tell The User We Are Creating The SSL_TASK.
 $!
 $ WRITE SYS$OUTPUT "Creating SSL_TASK OSU HTTP SSL Engine."    
 $!
+$!  Tell The User What File We Are Compiling.
+$!
+$ FILE_NAME = "ssl_task"
+$ WRITE SYS$OUTPUT "   ",FILE_NAME,".c"
+$!
 $! Compile The File.
 $!
 $ ON ERROR THEN GOTO SSL_TASK_END
-$ CC5/OBJECT='OBJ_DIR'SSL_TASK.OBJ SYS$DISK:[]SSL_TASK.C
 $!
-$! Link The Program.
-$! Check To See If We Are To Link With A Specific TCP/IP Library.
-$!
-$ IF (TCPIP_LIB.NES."")
+$ FILE_NAME0 = ","+ F$ELEMENT(0,".",FILE_NAME)+ ","
+$ IF COMPILEWITH_CC5 - FILE_NAME0 .NES. COMPILEWITH_CC5
 $ THEN
-$!
-$!  Link With TCP/IP Library.
-$!
-$   LINK/'DEBUGGER'/'TRACEBACK'/EXE='EXE_DIR'SSL_TASK.EXE -
-        'OBJ_DIR'SSL_TASK.OBJ, -
-       'SSL_LIB'/LIBRARY,'CRYPTO_LIB'/LIBRARY, -
-        'TCPIP_LIB','OPT_FILE'/OPTION
-$!
-$! Else...
-$!
+$   if (.not. CC5_SHOWN)
+$   then
+$     CC5_SHOWN = 1
+$     write sys$output "        \Using special rule (5)"
+$     x = "    "+ CC5
+$     write /symbol sys$output x
+$   endif
+$   CC5 /OBJECT='OBJ_DIR''FILE_NAME'.OBJ SYS$DISK:[]'FILE_NAME'.C
 $ ELSE
+$   CC /OBJECT='OBJ_DIR''FILE_NAME'.OBJ SYS$DISK:[]'FILE_NAME'.C
+$ ENDIF
 $!
-$!  Don't Link With TCP/IP Library.
-$!
-$   LINK/'DEBUGGER'/'TRACEBACK'/EXE='EXE_DIR'SSL_TASK.EXE -
-        'OBJ_DIR'SSL_TASK.OBJ,-
-       'SSL_LIB'/LIBRARY,'CRYPTO_LIB'/LIBRARY, -
-        'OPT_FILE'/OPTION
-$!
-$! End The TCP/IP Library Check.
+$! Link The Program.
 $!
-$ ENDIF
+$ LINK /'DEBUGGER' /'LINKMAP' /'TRACEBACK' /EXE='EXE_DIR'SSL_TASK.EXE -
+   'OBJ_DIR'SSL_TASK.OBJ, -
+   'SSL_LIB'/LIBRARY, -
+   'CRYPTO_LIB'/LIBRARY -
+   'TCPIP_LIB' -
+   'ZLIB_LIB' -
+   ,'OPT_FILE' /OPTIONS
 $!
 $! Time To Return.
 $!
@@ -356,7 +405,7 @@ $!
 $     CREATE 'OPT_FILE'
 $DECK
 !
-! Default System Options File To Link Agianst 
+! Default System Options File To Link Against 
 ! The Sharable VAX C Runtime Library.
 !
 SYS$SHARE:VAXCRTL.EXE/SHARE
@@ -385,7 +434,7 @@ $!
 $     CREATE 'OPT_FILE'
 $DECK
 !
-! Default System Options File To Link Agianst 
+! Default System Options File To Link Against 
 ! The Sharable C Runtime Library.
 !
 GNU_CC:[000000]GCCLIB/LIBRARY
@@ -420,7 +469,7 @@ $!
 $       CREATE 'OPT_FILE'
 $DECK
 !
-! Default System Options File To Link Agianst 
+! Default System Options File To Link Against 
 ! The Sharable DEC C Runtime Library.
 !
 SYS$SHARE:DECC$SHR.EXE/SHARE
@@ -435,7 +484,7 @@ $!
 $       CREATE 'OPT_FILE'
 $DECK
 !
-! Default System Options File For non-VAX To Link Agianst 
+! Default System Options File For non-VAX To Link Against 
 ! The Sharable C Runtime Library.
 !
 SYS$SHARE:CMA$OPEN_LIB_SHR/SHARE
@@ -524,12 +573,12 @@ $! Else...
 $!
 $ ELSE
 $!
-$!  Else, Check To See If P1 Has A Valid Arguement.
+$!  Else, Check To See If P1 Has A Valid Argument.
 $!
 $   IF (P1.EQS."LIBRARY").OR.(P1.EQS."SSL_TASK")
 $   THEN
 $!
-$!    A Valid Arguement.
+$!    A Valid Argument.
 $!
 $     BUILDALL = P1
 $!
@@ -548,8 +597,8 @@ $     WRITE SYS$OUTPUT "    SSL_TASK :  To Compile Just The [.xxx.EXE.SSL]SSL_TA
 $     WRITE SYS$OUTPUT ""
 $     WRITE SYS$OUTPUT " Where 'xxx' Stands For:"
 $     WRITE SYS$OUTPUT ""
-$     WRITE SYS$OUTPUT "    ALPHA    :  Alpha Architecture."
-$     WRITE SYS$OUTPUT "    IA64     :  IA64 Architecture."
+$     WRITE SYS$OUTPUT "    ALPHA[64]:  Alpha Architecture."
+$     WRITE SYS$OUTPUT "    IA64[64] :  IA64 Architecture."
 $     WRITE SYS$OUTPUT "    VAX      :  VAX Architecture."
 $     WRITE SYS$OUTPUT ""
 $!
@@ -557,7 +606,7 @@ $!    Time To EXIT.
 $!
 $     EXIT
 $!
-$!  End The Valid Arguement Check.
+$!  End The Valid Argument Check.
 $!
 $   ENDIF
 $!
@@ -570,14 +619,15 @@ $!
 $ IF (P2.EQS."NODEBUG")
 $ THEN
 $!
-$!   P2 Is NODEBUG, So Compile Without Debugger Information.
+$!  P2 Is NODEBUG, So Compile Without Debugger Information.
 $!
-$    DEBUGGER  = "NODEBUG"
-$    TRACEBACK = "NOTRACEBACK" 
-$    GCC_OPTIMIZE = "OPTIMIZE"
-$    CC_OPTIMIZE = "OPTIMIZE"
-$    WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile."
-$    WRITE SYS$OUTPUT "Compiling With Compiler Optimization."
+$   DEBUGGER  = "NODEBUG"
+$   LINKMAP = "NOMAP"
+$   TRACEBACK = "NOTRACEBACK" 
+$   GCC_OPTIMIZE = "OPTIMIZE"
+$   CC_OPTIMIZE = "OPTIMIZE"
+$   WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile."
+$   WRITE SYS$OUTPUT "Compiling With Compiler Optimization."
 $!
 $! Else...
 $!
@@ -591,6 +641,7 @@ $!
 $!    Compile With Debugger Information.
 $!
 $     DEBUGGER  = "DEBUG"
+$     LINKMAP = "MAP"
 $     TRACEBACK = "TRACEBACK"
 $     GCC_OPTIMIZE = "NOOPTIMIZE"
 $     CC_OPTIMIZE = "NOOPTIMIZE"
@@ -598,7 +649,7 @@ $     WRITE SYS$OUTPUT "Debugger Information Will Be Produced During Compile."
 $     WRITE SYS$OUTPUT "Compiling Without Compiler Optimization."
 $   ELSE
 $!
-$!    Tell The User Entered An Invalid Option..
+$!    Tell The User Entered An Invalid Option.
 $!
 $     WRITE SYS$OUTPUT ""
 $     WRITE SYS$OUTPUT "The Option ",P2," Is Invalid.  The Valid Options Are:"
@@ -611,7 +662,7 @@ $!    Time To EXIT.
 $!
 $     EXIT
 $!
-$!  End The Valid Arguement Check.
+$!  End The Valid Argument Check.
 $!
 $   ENDIF
 $!
@@ -653,6 +704,59 @@ $! End The P5 Check.
 $!
 $ ENDIF
 $!
+$! Check P6 (POINTER_SIZE).
+$!
+$ IF (P6 .NES. "") .AND. (ARCH .NES. "VAX")
+$ THEN
+$!
+$   IF (P6 .EQS. "32")
+$   THEN
+$     POINTER_SIZE = " /POINTER_SIZE=32"
+$   ELSE
+$     POINTER_SIZE = F$EDIT( P6, "COLLAPSE, UPCASE")
+$     IF ((POINTER_SIZE .EQS. "64") .OR. -
+       (POINTER_SIZE .EQS. "64=") .OR. -
+       (POINTER_SIZE .EQS. "64=ARGV"))
+$     THEN
+$       ARCHD = ARCH+ "_64"
+$       LIB32 = ""
+$       POINTER_SIZE = " /POINTER_SIZE=64"
+$     ELSE
+$!
+$!      Tell The User Entered An Invalid Option.
+$!
+$       WRITE SYS$OUTPUT ""
+$       WRITE SYS$OUTPUT "The Option ", P6, -
+         " Is Invalid.  The Valid Options Are:"
+$       WRITE SYS$OUTPUT ""
+$       WRITE SYS$OUTPUT -
+         "    """"       :  Compile with default (short) pointers."
+$       WRITE SYS$OUTPUT -
+         "    32       :  Compile with 32-bit (short) pointers."
+$       WRITE SYS$OUTPUT -
+         "    64       :  Compile with 64-bit (long) pointers (auto ARGV)."
+$       WRITE SYS$OUTPUT -
+         "    64=      :  Compile with 64-bit (long) pointers (no ARGV)."
+$       WRITE SYS$OUTPUT -
+         "    64=ARGV  :  Compile with 64-bit (long) pointers (ARGV)."
+$       WRITE SYS$OUTPUT ""
+$! 
+$!      Time To EXIT.
+$!
+$       EXIT
+$!
+$     ENDIF
+$!
+$   ENDIF
+$!
+$! End The P6 (POINTER_SIZE) Check.
+$!
+$ ENDIF
+$!
+$! Set basic C compiler /INCLUDE directories.
+$!
+$ CC_INCLUDES = "SYS$DISK:[-.CRYPTO],SYS$DISK:[-]"
+$!
 $! Check To See If P3 Is Blank.
 $!
 $ IF (P3.EQS."")
@@ -753,11 +857,64 @@ $ CCDEFS = "TCPIP_TYPE_''P4'"
 $ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS
 $ CCEXTRAFLAGS = ""
 $ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS
-$ CCDISABLEWARNINGS = "LONGLONGTYPE,LONGLONGSUFX,FOUNDCR"
+$ CCDISABLEWARNINGS = "" !!! "LONGLONGTYPE,LONGLONGSUFX,FOUNDCR"
 $ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN -
        CCDISABLEWARNINGS = CCDISABLEWARNINGS + "," + USER_CCDISABLEWARNINGS
 $!
-$!  Check To See If The User Entered A Valid Paramter.
+$! Check To See If We Have A ZLIB Option.
+$!
+$ ZLIB = P7
+$ IF (ZLIB .NES. "")
+$ THEN
+$!
+$!  Check for expected ZLIB files.
+$!
+$   err = 0
+$   file1 = f$parse( "zlib.h", ZLIB, , , "SYNTAX_ONLY")
+$   if (f$search( file1) .eqs. "")
+$   then
+$     WRITE SYS$OUTPUT ""
+$     WRITE SYS$OUTPUT "The Option ", ZLIB, " Is Invalid."
+$     WRITE SYS$OUTPUT "    Can't find header: ''file1'"
+$     err = 1
+$   endif
+$   file1 = f$parse( "A.;", ZLIB)- "A.;"
+$!
+$   file2 = f$parse( ZLIB, "libz.olb", , , "SYNTAX_ONLY")
+$   if (f$search( file2) .eqs. "")
+$   then
+$     if (err .eq. 0)
+$     then
+$       WRITE SYS$OUTPUT ""
+$       WRITE SYS$OUTPUT "The Option ", ZLIB, " Is Invalid."
+$     endif
+$     WRITE SYS$OUTPUT "    Can't find library: ''file2'"
+$     WRITE SYS$OUTPUT ""
+$     err = err+ 2
+$   endif
+$   if (err .eq. 1)
+$   then
+$     WRITE SYS$OUTPUT ""
+$   endif
+$!
+$   if (err .ne. 0)
+$   then
+$     EXIT
+$   endif
+$!
+$   CCDEFS = """ZLIB=1"", "+ CCDEFS
+$   CC_INCLUDES = CC_INCLUDES+ ", "+ file1
+$   ZLIB_LIB = ", ''file2' /library"
+$!
+$!  Print info
+$!
+$   WRITE SYS$OUTPUT "ZLIB library spec: ", file2
+$!
+$! End The ZLIB Check.
+$!
+$ ENDIF
+$!
+$!  Check To See If The User Entered A Valid Parameter.
 $!
 $ IF (P3.EQS."VAXC").OR.(P3.EQS."DECC").OR.(P3.EQS."GNUC")
 $ THEN
@@ -780,13 +937,13 @@ $!
 $     CC = "CC"
 $     IF ARCH.EQS."VAX" .AND. F$TRNLNM("DECC$CC_DEFAULT").NES."/DECC" -
         THEN CC = "CC/DECC"
-$     CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/STANDARD=ANSI89" + -
-           "/NOLIST/PREFIX=ALL" + -
-          "/INCLUDE=(SYS$DISK:[-.CRYPTO],SYS$DISK:[-])" + CCEXTRAFLAGS
+$     CC = CC + " /''CC_OPTIMIZE' /''DEBUGGER' /STANDARD=RELAXED"+ -
+       "''POINTER_SIZE' /NOLIST /PREFIX=ALL" + -
+       " /INCLUDE=(''CC_INCLUDES') " + CCEXTRAFLAGS
 $!
 $!    Define The Linker Options File Name.
 $!
-$     OPT_FILE = "''EXE_DIR'VAX_DECC_OPTIONS.OPT"
+$     OPT_FILE = "VAX_DECC_OPTIONS.OPT"
 $!
 $!  End DECC Check.
 $!
@@ -815,7 +972,7 @@ $   EXIT
 $     ENDIF
 $     IF F$TRNLNM("DECC$CC_DEFAULT").EQS."/DECC" THEN CC = "CC/VAXC"
 $     CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/NOLIST" + -
-          "/INCLUDE=(SYS$DISK:[-.CRYPTO],SYS$DISK:[-])" + CCEXTRAFLAGS
+          "/INCLUDE=(''CC_INCLUDES')" + CCEXTRAFLAGS
 $     CCDEFS = CCDEFS + ",""VAXC"""
 $!
 $!    Define <sys> As SYS$COMMON:[SYSLIB]
@@ -824,7 +981,7 @@ $     DEFINE/NOLOG SYS SYS$COMMON:[SYSLIB]
 $!
 $!    Define The Linker Options File Name.
 $!
-$     OPT_FILE = "''EXE_DIR'VAX_VAXC_OPTIONS.OPT"
+$     OPT_FILE = "VAX_VAXC_OPTIONS.OPT"
 $!
 $!  End VAXC Check
 $!
@@ -847,11 +1004,11 @@ $!    Use GNU C...
 $!
 $     IF F$TYPE(GCC) .EQS. "" THEN GCC := GCC
 $     CC = GCC+"/NOCASE_HACK/''GCC_OPTIMIZE'/''DEBUGGER'/NOLIST" + -
-          "/INCLUDE=(SYS$DISK:[-.CRYPTO],SYS$DISK:[-])" + CCEXTRAFLAGS
+          "/INCLUDE=(''CC_INCLUDES')" + CCEXTRAFLAGS
 $!
 $!    Define The Linker Options File Name.
 $!
-$     OPT_FILE = "''EXE_DIR'VAX_GNUC_OPTIONS.OPT"
+$     OPT_FILE = "VAX_GNUC_OPTIONS.OPT"
 $!
 $!  End The GNU C Check.
 $!
@@ -870,16 +1027,16 @@ $     THEN
 $       CC4DISABLEWARNINGS = "DOLLARID"
 $     ELSE
 $       CC4DISABLEWARNINGS = CCDISABLEWARNINGS + ",DOLLARID"
-$       CCDISABLEWARNINGS = "/WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))"
+$       CCDISABLEWARNINGS = " /WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))"
 $     ENDIF
-$     CC4DISABLEWARNINGS = "/WARNING=(DISABLE=(" + CC4DISABLEWARNINGS + "))"
+$     CC4DISABLEWARNINGS = " /WARNING=(DISABLE=(" + CC4DISABLEWARNINGS + "))"
 $   ELSE
 $     CCDISABLEWARNINGS = ""
 $     CC4DISABLEWARNINGS = ""
 $   ENDIF
-$   CC2 = CC + "/DEFINE=(" + CCDEFS + ",_POSIX_C_SOURCE)" + CCDISABLEWARNINGS
-$   CC3 = CC + "/DEFINE=(" + CCDEFS + ISSEVEN + ")" + CCDISABLEWARNINGS
-$   CC = CC + "/DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS
+$   CC2 = CC + " /DEFINE=(" + CCDEFS + ",_POSIX_C_SOURCE)" + CCDISABLEWARNINGS
+$   CC3 = CC + " /DEFINE=(" + CCDEFS + ISSEVEN + ")" + CCDISABLEWARNINGS
+$   CC = CC + " /DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS
 $   IF COMPILER .EQS. "DECC"
 $   THEN
 $     CC4 = CC - CCDISABLEWARNINGS + CC4DISABLEWARNINGS
@@ -893,7 +1050,7 @@ $!  Show user the result
 $!
 $   WRITE/SYMBOL SYS$OUTPUT "Main Compiling Command: ",CC
 $!
-$!  Else The User Entered An Invalid Arguement.
+$!  Else The User Entered An Invalid Argument.
 $!
 $ ELSE
 $!
@@ -925,7 +1082,7 @@ $   THEN
 $!
 $!    Set the library to use SOCKETSHR
 $!
-$     TCPIP_LIB = "SYS$DISK:[-.VMS]SOCKETSHR_SHR.OPT/OPT"
+$     TCPIP_LIB = ",SYS$DISK:[-.VMS]SOCKETSHR_SHR.OPT /OPTIONS"
 $!
 $!    Done with SOCKETSHR
 $!
@@ -951,13 +1108,13 @@ $   THEN
 $!
 $!    Set the library to use UCX.
 $!
-$     TCPIP_LIB = "SYS$DISK:[-.VMS]UCX_SHR_DECC.OPT/OPT"
+$     TCPIP_LIB = ",SYS$DISK:[-.VMS]UCX_SHR_DECC.OPT /OPTIONS"
 $     IF F$TRNLNM("UCX$IPC_SHR") .NES. ""
 $     THEN
-$       TCPIP_LIB = "SYS$DISK:[-.VMS]UCX_SHR_DECC_LOG.OPT/OPT"
+$       TCPIP_LIB = ",SYS$DISK:[-.VMS]UCX_SHR_DECC_LOG.OPT /OPTIONS"
 $     ELSE
 $       IF COMPILER .NES. "DECC" .AND. ARCH .EQS. "VAX" THEN -
-         TCPIP_LIB = "SYS$DISK:[-.VMS]UCX_SHR_VAXC.OPT/OPT"
+         TCPIP_LIB = ",SYS$DISK:[-.VMS]UCX_SHR_VAXC.OPT /OPTIONS"
 $     ENDIF
 $!
 $!    Done with UCX
@@ -971,7 +1128,7 @@ $   THEN
 $!
 $!    Set the library to use TCPIP (post UCX).
 $!
-$     TCPIP_LIB = "SYS$DISK:[-.VMS]TCPIP_SHR_DECC.OPT/OPT"
+$     TCPIP_LIB = ",SYS$DISK:[-.VMS]TCPIP_SHR_DECC.OPT /OPTIONS"
 $!
 $!    Done with TCPIP
 $!
@@ -992,9 +1149,9 @@ $   ENDIF
 $!
 $!  Print info
 $!
-$   WRITE SYS$OUTPUT "TCP/IP library spec: ", TCPIP_LIB
+$   WRITE SYS$OUTPUT "TCP/IP library spec: ", TCPIP_LIB- ","
 $!
-$!  Else The User Entered An Invalid Arguement.
+$!  Else The User Entered An Invalid Argument.
 $!
 $ ELSE
 $!
index bbe2543..fdcab6f 100644 (file)
@@ -56,7 +56,7 @@
  * [including the GNU Public Licence.]
  */
 /* ====================================================================
- * Copyright (c) 1998-2001 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2007 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  *
  */
 /* ====================================================================
- * Copyright (c) 1998-2006 The OpenSSL 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.
+ * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
+ * ECC cipher suite support in OpenSSL originally developed by 
+ * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
+ */
+/* ====================================================================
+ * Copyright 2005 Nokia. All rights reserved.
  *
- * 3. All advertising materials mentioning features or use of this
- *    software must display the following acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
+ * The portions of the attached software ("Contribution") is developed by
+ * Nokia Corporation and is licensed pursuant to the OpenSSL open source
+ * license.
  *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For written permission, please contact
- *    openssl-core@openssl.org.
+ * The Contribution, originally written by Mika Kousa and Pasi Eronen of
+ * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
+ * support (see RFC 4279) to OpenSSL.
  *
- * 5. Products derived from this software may not be called "OpenSSL"
- *    nor may "OpenSSL" appear in their names without prior written
- *    permission of the OpenSSL Project.
+ * No patent licenses or other rights except those expressly stated in
+ * the OpenSSL open source license shall be deemed granted or received
+ * expressly, by implication, estoppel, or otherwise.
  *
- * 6. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by the OpenSSL Project
- *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
+ * No assurances are provided by Nokia that the Contribution does not
+ * infringe the patent or other intellectual property rights of any third
+ * party or that the license provides you with all the necessary rights
+ * to make use of the Contribution.
  *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
- * ====================================================================
- *
- * This product includes cryptographic software written by Eric Young
- * (eay@cryptsoft.com).  This product includes software written by Tim
- * Hudson (tjh@cryptsoft.com).
- *
- */
-/* ====================================================================
- * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
- * ECC cipher suite support in OpenSSL originally developed by 
- * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
+ * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
+ * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
+ * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
+ * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
+ * OTHERWISE.
  */
 
 #ifndef HEADER_SSL_H 
@@ -248,56 +221,88 @@ extern "C" {
 #define SSL_MAX_KEY_ARG_LENGTH                 8
 #define SSL_MAX_MASTER_KEY_LENGTH              48
 
+
 /* These are used to specify which ciphers to use and not to use */
+
+#define SSL_TXT_EXP40          "EXPORT40"
+#define SSL_TXT_EXP56          "EXPORT56"
 #define SSL_TXT_LOW            "LOW"
 #define SSL_TXT_MEDIUM         "MEDIUM"
 #define SSL_TXT_HIGH           "HIGH"
 #define SSL_TXT_FIPS           "FIPS"
-#define SSL_TXT_kFZA           "kFZA"
-#define        SSL_TXT_aFZA            "aFZA"
-#define SSL_TXT_eFZA           "eFZA"
-#define SSL_TXT_FZA            "FZA"
+
+#define SSL_TXT_kFZA           "kFZA" /* unused! */
+#define        SSL_TXT_aFZA            "aFZA" /* unused! */
+#define SSL_TXT_eFZA           "eFZA" /* unused! */
+#define SSL_TXT_FZA            "FZA"  /* unused! */
 
 #define        SSL_TXT_aNULL           "aNULL"
 #define        SSL_TXT_eNULL           "eNULL"
 #define        SSL_TXT_NULL            "NULL"
 
-#define SSL_TXT_kKRB5          "kKRB5"
-#define SSL_TXT_aKRB5          "aKRB5"
-#define SSL_TXT_KRB5           "KRB5"
-
 #define SSL_TXT_kRSA           "kRSA"
-#define SSL_TXT_kDHr           "kDHr"
-#define SSL_TXT_kDHd           "kDHd"
+#define SSL_TXT_kDHr           "kDHr" /* no such ciphersuites supported! */
+#define SSL_TXT_kDHd           "kDHd" /* no such ciphersuites supported! */
+#define SSL_TXT_kDH            "kDH"  /* no such ciphersuites supported! */
 #define SSL_TXT_kEDH           "kEDH"
+#define SSL_TXT_kKRB5          "kKRB5"
+#define SSL_TXT_kECDHr         "kECDHr"
+#define SSL_TXT_kECDHe         "kECDHe"
+#define SSL_TXT_kECDH          "kECDH"
+#define SSL_TXT_kEECDH         "kEECDH"
+#define SSL_TXT_kPSK            "kPSK"
+#define SSL_TXT_kGOST          "kGOST"
+
 #define        SSL_TXT_aRSA            "aRSA"
 #define        SSL_TXT_aDSS            "aDSS"
-#define        SSL_TXT_aDH             "aDH"
+#define        SSL_TXT_aDH             "aDH" /* no such ciphersuites supported! */
+#define        SSL_TXT_aECDH           "aECDH"
+#define SSL_TXT_aKRB5          "aKRB5"
+#define SSL_TXT_aECDSA         "aECDSA"
+#define SSL_TXT_aPSK            "aPSK"
+#define SSL_TXT_aGOST94        "aGOST94"
+#define SSL_TXT_aGOST01 "aGOST01"
+#define SSL_TXT_aGOST  "aGOST"
+
 #define        SSL_TXT_DSS             "DSS"
 #define SSL_TXT_DH             "DH"
-#define SSL_TXT_EDH            "EDH"
+#define SSL_TXT_EDH            "EDH" /* same as "kEDH:-ADH" */
 #define SSL_TXT_ADH            "ADH"
 #define SSL_TXT_RSA            "RSA"
+#define SSL_TXT_ECDH           "ECDH"
+#define SSL_TXT_EECDH          "EECDH" /* same as "kEECDH:-AECDH" */
+#define SSL_TXT_AECDH          "AECDH"
+#define SSL_TXT_ECDSA          "ECDSA"
+#define SSL_TXT_KRB5           "KRB5"
+#define SSL_TXT_PSK             "PSK"
+
 #define SSL_TXT_DES            "DES"
 #define SSL_TXT_3DES           "3DES"
 #define SSL_TXT_RC4            "RC4"
 #define SSL_TXT_RC2            "RC2"
 #define SSL_TXT_IDEA           "IDEA"
 #define SSL_TXT_SEED           "SEED"
+#define SSL_TXT_AES128         "AES128"
+#define SSL_TXT_AES256         "AES256"
 #define SSL_TXT_AES            "AES"
+#define SSL_TXT_CAMELLIA128    "CAMELLIA128"
+#define SSL_TXT_CAMELLIA256    "CAMELLIA256"
 #define SSL_TXT_CAMELLIA       "CAMELLIA"
+
 #define SSL_TXT_MD5            "MD5"
 #define SSL_TXT_SHA1           "SHA1"
-#define SSL_TXT_SHA            "SHA"
-#define SSL_TXT_EXP            "EXP"
-#define SSL_TXT_EXPORT         "EXPORT"
-#define SSL_TXT_EXP40          "EXPORT40"
-#define SSL_TXT_EXP56          "EXPORT56"
+#define SSL_TXT_SHA            "SHA" /* same as "SHA1" */
+#define SSL_TXT_GOST94         "GOST94" 
+#define SSL_TXT_GOST89MAC              "GOST89MAC" 
+
 #define SSL_TXT_SSLV2          "SSLv2"
 #define SSL_TXT_SSLV3          "SSLv3"
 #define SSL_TXT_TLSV1          "TLSv1"
+
+#define SSL_TXT_EXP            "EXP"
+#define SSL_TXT_EXPORT         "EXPORT"
+
 #define SSL_TXT_ALL            "ALL"
-#define SSL_TXT_ECC            "ECCdraft" /* ECC ciphersuites are not yet official */
 
 /*
  * COMPLEMENTOF* definitions. These identifiers are used to (de-select)
@@ -319,7 +324,13 @@ extern "C" {
 /* The following cipher list is used by default.
  * It also is substituted when an application-defined cipher list string
  * starts with 'DEFAULT'. */
-#define SSL_DEFAULT_CIPHER_LIST        "AES:ALL:!aNULL:!eNULL:+RC4:@STRENGTH" /* low priority for RC4 */
+#define SSL_DEFAULT_CIPHER_LIST        "ALL:!aNULL:!eNULL:!SSLv2"
+/* As of OpenSSL 1.0.0, ssl_create_cipher_list() in ssl/ssl_ciph.c always
+ * starts with a reasonable order, and all we have to do for DEFAULT is
+ * throwing out anonymous and unencrypted ciphersuites!
+ * (The latter are not actually enabled by ALL, but "ALL:RSA" would enable
+ * some of them.)
+ */
 
 /* Used in SSL_set_shutdown()/SSL_get_shutdown(); */
 #define SSL_SENT_SHUTDOWN      1
@@ -344,6 +355,7 @@ extern "C" {
  * 'struct ssl_st *' function parameters used to prototype callbacks
  * in SSL_CTX. */
 typedef struct ssl_st *ssl_crock_st;
+typedef struct tls_session_ticket_ext_st TLS_SESSION_TICKET_EXT;
 
 /* used to hold info on the particular ciphers used */
 typedef struct ssl_cipher_st
@@ -351,17 +363,25 @@ typedef struct ssl_cipher_st
        int valid;
        const char *name;               /* text name */
        unsigned long id;               /* id, 4 bytes, first is version */
-       unsigned long algorithms;       /* what ciphers are used */
+
+       /* changed in 0.9.9: these four used to be portions of a single value 'algorithms' */
+       unsigned long algorithm_mkey;   /* key exchange algorithm */
+       unsigned long algorithm_auth;   /* server authentication */
+       unsigned long algorithm_enc;    /* symmetric encryption */
+       unsigned long algorithm_mac;    /* symmetric authentication */
+       unsigned long algorithm_ssl;    /* (major) protocol version */
+
        unsigned long algo_strength;    /* strength and export flags */
        unsigned long algorithm2;       /* Extra flags */
        int strength_bits;              /* Number of bits really used */
        int alg_bits;                   /* Number of bits for algorithm */
-       unsigned long mask;             /* used for matching */
-       unsigned long mask_strength;    /* also used for matching */
        } SSL_CIPHER;
 
 DECLARE_STACK_OF(SSL_CIPHER)
 
+typedef int (*tls_session_ticket_ext_cb_fn)(SSL *s, const unsigned char *data, int len, void *arg);
+typedef int (*tls_session_secret_cb_fn)(SSL *s, void *secret, int *secret_len, STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg);
+
 /* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */
 typedef struct ssl_method_st
        {
@@ -385,12 +405,12 @@ typedef struct ssl_method_st
        int (*ssl_dispatch_alert)(SSL *s);
        long (*ssl_ctrl)(SSL *s,int cmd,long larg,void *parg);
        long (*ssl_ctx_ctrl)(SSL_CTX *ctx,int cmd,long larg,void *parg);
-       SSL_CIPHER *(*get_cipher_by_char)(const unsigned char *ptr);
+       const SSL_CIPHER *(*get_cipher_by_char)(const unsigned char *ptr);
        int (*put_cipher_by_char)(const SSL_CIPHER *cipher,unsigned char *ptr);
        int (*ssl_pending)(const SSL *s);
        int (*num_ciphers)(void);
-       SSL_CIPHER *(*get_cipher)(unsigned ncipher);
-       struct ssl_method_st *(*get_ssl_method)(int version);
+       const SSL_CIPHER *(*get_cipher)(unsigned ncipher);
+       const struct ssl_method_st *(*get_ssl_method)(int version);
        long (*get_timeout)(void);
        struct ssl3_enc_method *ssl3_enc; /* Extra SSLv3/TLS stuff */
        int (*ssl_version)(void);
@@ -402,17 +422,20 @@ typedef struct ssl_method_st
  * SSL_SESSION_ID ::= SEQUENCE {
  *     version                 INTEGER,        -- structure version number
  *     SSLversion              INTEGER,        -- SSL version number
- *     Cipher                  OCTET_STRING,   -- the 3 byte cipher ID
- *     Session_ID              OCTET_STRING,   -- the Session ID
- *     Master_key              OCTET_STRING,   -- the master key
- *     KRB5_principal          OCTET_STRING    -- optional Kerberos principal
- *     Key_Arg [ 0 ] IMPLICIT  OCTET_STRING,   -- the optional Key argument
+ *     Cipher                  OCTET STRING,   -- the 3 byte cipher ID
+ *     Session_ID              OCTET STRING,   -- the Session ID
+ *     Master_key              OCTET STRING,   -- the master key
+ *     KRB5_principal          OCTET STRING    -- optional Kerberos principal
+ *     Key_Arg [ 0 ] IMPLICIT  OCTET STRING,   -- the optional Key argument
  *     Time [ 1 ] EXPLICIT     INTEGER,        -- optional Start Time
  *     Timeout [ 2 ] EXPLICIT  INTEGER,        -- optional Timeout ins seconds
  *     Peer [ 3 ] EXPLICIT     X509,           -- optional Peer Certificate
- *     Session_ID_context [ 4 ] EXPLICIT OCTET_STRING,   -- the Session ID context
- *     Verify_result [ 5 ] EXPLICIT INTEGER    -- X509_V_... code for `Peer'
- *     Compression [6] IMPLICIT ASN1_OBJECT    -- compression OID XXXXX
+ *     Session_ID_context [ 4 ] EXPLICIT OCTET STRING,   -- the Session ID context
+ *     Verify_result [ 5 ] EXPLICIT INTEGER,   -- X509_V_... code for `Peer'
+ *     HostName [ 6 ] EXPLICIT OCTET STRING,   -- optional HostName from servername TLS extension 
+ *     ECPointFormatList [ 7 ] OCTET STRING,     -- optional EC point format list from TLS extension
+ *     PSK_identity_hint [ 8 ] EXPLICIT OCTET STRING, -- optional PSK identity hint
+ *     PSK_identity [ 9 ] EXPLICIT OCTET STRING -- optional PSK identity
  *     }
  * Look in ssl/ssl_asn1.c for more details
  * I'm using EXPLICIT tags so I can read the damn things using asn1parse :-).
@@ -440,7 +463,10 @@ typedef struct ssl_session_st
         unsigned int krb5_client_princ_len;
         unsigned char krb5_client_princ[SSL_MAX_KRB5_PRINCIPAL_LENGTH];
 #endif /* OPENSSL_NO_KRB5 */
-
+#ifndef OPENSSL_NO_PSK
+       char *psk_identity_hint;
+       char *psk_identity;
+#endif
        int not_resumable;
 
        /* The cert is the certificate used to establish this connection */
@@ -459,9 +485,9 @@ typedef struct ssl_session_st
        long timeout;
        long time;
 
-       int compress_meth;              /* Need to lookup the method */
+       unsigned int compress_meth;     /* Need to lookup the method */
 
-       SSL_CIPHER *cipher;
+       const SSL_CIPHER *cipher;
        unsigned long cipher_id;        /* when ASN.1 loaded, this
                                         * needs to be used to load
                                         * the 'cipher' structure */
@@ -475,6 +501,12 @@ typedef struct ssl_session_st
        struct ssl_session_st *prev,*next;
 #ifndef OPENSSL_NO_TLSEXT
        char *tlsext_hostname;
+#ifndef OPENSSL_NO_EC
+       size_t tlsext_ecpointformatlist_length;
+       unsigned char *tlsext_ecpointformatlist; /* peer's list */
+       size_t tlsext_ellipticcurvelist_length;
+       unsigned char *tlsext_ellipticcurvelist; /* peer's list */
+#endif /* OPENSSL_NO_EC */
        /* RFC4507 info */
        unsigned char *tlsext_tick;     /* Session ticket */
        size_t  tlsext_ticklen;         /* Session ticket length */     
@@ -504,7 +536,7 @@ typedef struct ssl_session_st
 
 /* SSL_OP_ALL: various bug workarounds that should be rather harmless.
  *             This used to be 0x000FFFFFL before 0.9.7. */
-#define SSL_OP_ALL                                     0x00000FFFL
+#define SSL_OP_ALL                                     0x80000FFFL
 
 /* DTLS options */
 #define SSL_OP_NO_QUERY_MTU                 0x00001000L
@@ -517,6 +549,8 @@ typedef struct ssl_session_st
 
 /* As server, disallow session resumption on renegotiation */
 #define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION  0x00010000L
+/* Don't use compression even if supported */
+#define SSL_OP_NO_COMPRESSION                          0x00020000L
 /* Permit unsafe legacy renegotiation */
 #define SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION       0x00040000L
 /* If set, always create a new key when using tmp_ecdh parameters */
@@ -545,7 +579,11 @@ typedef struct ssl_session_st
 #define SSL_OP_PKCS1_CHECK_2                           0x10000000L
 #define SSL_OP_NETSCAPE_CA_DN_BUG                      0x20000000L
 #define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG         0x40000000L
-
+/* Make server add server-hello extension from early version of
+ * cryptopro draft, when GOST ciphersuite is negotiated. 
+ * Required for interoperability with CryptoPro CSP 3.x 
+ */
+#define SSL_OP_CRYPTOPRO_TLSEXT_BUG                    0x80000000L
 
 /* Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success
  * when just a single record has been written): */
@@ -560,10 +598,17 @@ typedef struct ssl_session_st
 #define SSL_MODE_AUTO_RETRY 0x00000004L
 /* Don't attempt to automatically build certificate chain */
 #define SSL_MODE_NO_AUTO_CHAIN 0x00000008L
+/* Save RAM by releasing read and write buffers when they're empty. (SSL3 and
+ * TLS only.)  "Released" buffers are put onto a free-list in the context
+ * or just freed (depending on the context's setting for freelist_max_len). */
+#define SSL_MODE_RELEASE_BUFFERS 0x00000010L
+/* Use small read and write buffers: (a) lazy allocate read buffers for
+ * large incoming records, and (b) limit the size of outgoing records. */
+#define SSL_MODE_SMALL_BUFFERS 0x00000020L
 /* When set, clients may send application data before receipt of CCS
  * and Finished.  This mode enables full-handshakes to 'complete' in
  * one RTT. */
-#define SSL_MODE_HANDSHAKE_CUTTHROUGH 0x00000020L
+#define SSL_MODE_HANDSHAKE_CUTTHROUGH 0x00000040L
 
 /* Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value,
  * they cannot be used to clear bits. */
@@ -642,17 +687,18 @@ typedef struct ssl_comp_st
        } SSL_COMP;
 
 DECLARE_STACK_OF(SSL_COMP)
+DECLARE_LHASH_OF(SSL_SESSION);
 
 struct ssl_ctx_st
        {
-       SSL_METHOD *method;
+       const SSL_METHOD *method;
 
        STACK_OF(SSL_CIPHER) *cipher_list;
        /* same as above but sorted for lookup */
        STACK_OF(SSL_CIPHER) *cipher_list_by_id;
 
        struct x509_store_st /* X509_STORE */ *cert_store;
-       struct lhash_st /* LHASH */ *sessions;  /* a set of SSL_SESSIONs */
+       LHASH_OF(SSL_SESSION) *sessions;
        /* Most session-ids that will be cached, default is
         * SSL_SESSION_CACHE_MAX_SIZE_DEFAULT. 0 is unlimited. */
        unsigned long session_cache_size;
@@ -770,11 +816,6 @@ struct ssl_ctx_st
 
        X509_VERIFY_PARAM *param;
 
-       /* The configured Snap Start orbit value, if set. */
-       char snap_start_orbit_valid;
-       unsigned char snap_start_orbit[8];
-
-
 #if 0
        int purpose;            /* Purpose setting */
        int trust;              /* Trust setting */
@@ -782,6 +823,12 @@ struct ssl_ctx_st
 
        int quiet_shutdown;
 
+       /* Maximum amount of data to send in one fragment.
+        * actual record size can be more than this due to
+        * padding and MAC overheads.
+        */
+       unsigned int max_send_fragment;
+
 #ifndef OPENSSL_ENGINE
        /* Engine to pass requests for client certs to
         */
@@ -800,13 +847,18 @@ struct ssl_ctx_st
        int (*tlsext_ticket_key_cb)(SSL *ssl,
                                        unsigned char *name, unsigned char *iv,
                                        EVP_CIPHER_CTX *ectx,
-                                       HMAC_CTX *hctx, int enc);
+                                       HMAC_CTX *hctx, int enc);
 
        /* certificate status request info */
        /* Callback for status request */
        int (*tlsext_status_cb)(SSL *ssl, void *arg);
        void *tlsext_status_arg;
 
+       /* draft-rescorla-tls-opaque-prf-input-00.txt information */
+       int (*tlsext_opaque_prf_input_callback)(SSL *, void *peerinput, size_t len, void *arg);
+       void *tlsext_opaque_prf_input_callback_arg;
+
+# ifndef OPENSSL_NO_NEXTPROTONEG
        /* Next protocol negotiation information */
        /* (for experimental NPN extension). */
 
@@ -823,8 +875,24 @@ struct ssl_ctx_st
                                    unsigned int inlen,
                                    void *arg);
        void *next_proto_select_cb_arg;
+# endif
+#endif
+
+#ifndef OPENSSL_NO_PSK
+       char *psk_identity_hint;
+       unsigned int (*psk_client_callback)(SSL *ssl, const char *hint, char *identity,
+               unsigned int max_identity_len, unsigned char *psk,
+               unsigned int max_psk_len);
+       unsigned int (*psk_server_callback)(SSL *ssl, const char *identity,
+               unsigned char *psk, unsigned int max_psk_len);
 #endif
 
+#ifndef OPENSSL_NO_BUF_FREELISTS
+#define SSL_MAX_BUF_FREELIST_LEN_DEFAULT 32
+       unsigned int freelist_max_len;
+       struct ssl3_buf_freelist_st *wbuf_freelist;
+       struct ssl3_buf_freelist_st *rbuf_freelist;
+#endif
        };
 
 #define SSL_SESS_CACHE_OFF                     0x0000
@@ -838,7 +906,7 @@ struct ssl_ctx_st
 #define SSL_SESS_CACHE_NO_INTERNAL \
        (SSL_SESS_CACHE_NO_INTERNAL_LOOKUP|SSL_SESS_CACHE_NO_INTERNAL_STORE)
 
-  struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx);
+LHASH_OF(SSL_SESSION) *SSL_CTX_sessions(SSL_CTX *ctx);
 #define SSL_CTX_sess_number(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_NUMBER,0,NULL)
 #define SSL_CTX_sess_connect(ctx) \
@@ -879,32 +947,69 @@ int SSL_CTX_set_client_cert_engine(SSL_CTX *ctx, ENGINE *e);
 #endif
 void SSL_CTX_set_cookie_generate_cb(SSL_CTX *ctx, int (*app_gen_cookie_cb)(SSL *ssl, unsigned char *cookie, unsigned int *cookie_len));
 void SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx, int (*app_verify_cookie_cb)(SSL *ssl, unsigned char *cookie, unsigned int cookie_len));
-void SSL_CTX_set_next_protos_advertised_cb(SSL_CTX *s, int (*cb) (SSL *ssl, const unsigned char **out, unsigned int *outlen, void *arg), void *arg);
-void SSL_CTX_set_next_proto_select_cb(SSL_CTX *s, int (*cb) (SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg), void *arg);
-void SSL_CTX_set_snap_start_orbit(SSL_CTX *s, const unsigned char orbit[8]);
-
-int SSL_select_next_proto(unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, const unsigned char *client, unsigned int client_len);
-void SSL_get0_next_proto_negotiated(const SSL *s, const unsigned char **data, unsigned *len);
-
-void SSL_get0_suggested_server_random(const SSL *s, const unsigned char **data, unsigned *len);
-void SSL_set_suggested_server_random_validity(SSL *s, char is_valid);
+#ifndef OPENSSL_NO_NEXTPROTONEG
+void SSL_CTX_set_next_protos_advertised_cb(SSL_CTX *s,
+                                          int (*cb) (SSL *ssl,
+                                                     const unsigned char **out,
+                                                     unsigned int *outlen,
+                                                     void *arg), void *arg);
+void SSL_CTX_set_next_proto_select_cb(SSL_CTX *s,
+                                     int (*cb) (SSL *ssl, unsigned char **out,
+                                                unsigned char *outlen,
+                                                const unsigned char *in,
+                                                unsigned int inlen, void *arg),
+                                     void *arg);
+
+int SSL_select_next_proto(unsigned char **out, unsigned char *outlen,
+                         const unsigned char *in, unsigned int inlen,
+                         const unsigned char *client, unsigned int client_len);
+void SSL_get0_next_proto_negotiated(const SSL *s, const unsigned char **data,
+                                   unsigned *len);
 
 #define OPENSSL_NPN_UNSUPPORTED        0
 #define OPENSSL_NPN_NEGOTIATED 1
 #define OPENSSL_NPN_NO_OVERLAP 2
 
+#endif
+
+#ifndef OPENSSL_NO_PSK
+/* the maximum length of the buffer given to callbacks containing the
+ * resulting identity/psk */
+#define PSK_MAX_IDENTITY_LEN 128
+#define PSK_MAX_PSK_LEN 256
+void SSL_CTX_set_psk_client_callback(SSL_CTX *ctx, 
+       unsigned int (*psk_client_callback)(SSL *ssl, const char *hint, 
+               char *identity, unsigned int max_identity_len, unsigned char *psk,
+               unsigned int max_psk_len));
+void SSL_set_psk_client_callback(SSL *ssl, 
+       unsigned int (*psk_client_callback)(SSL *ssl, const char *hint, 
+               char *identity, unsigned int max_identity_len, unsigned char *psk,
+               unsigned int max_psk_len));
+void SSL_CTX_set_psk_server_callback(SSL_CTX *ctx, 
+       unsigned int (*psk_server_callback)(SSL *ssl, const char *identity,
+               unsigned char *psk, unsigned int max_psk_len));
+void SSL_set_psk_server_callback(SSL *ssl,
+       unsigned int (*psk_server_callback)(SSL *ssl, const char *identity,
+               unsigned char *psk, unsigned int max_psk_len));
+int SSL_CTX_use_psk_identity_hint(SSL_CTX *ctx, const char *identity_hint);
+int SSL_use_psk_identity_hint(SSL *s, const char *identity_hint);
+const char *SSL_get_psk_identity_hint(const SSL *s);
+const char *SSL_get_psk_identity(const SSL *s);
+#endif
+
 #define SSL_NOTHING    1
 #define SSL_WRITING    2
 #define SSL_READING    3
 #define SSL_X509_LOOKUP        4
-#define SSL_SERVER_RANDOM_VALIDATE     6
 
 /* These will only be used when doing non-blocking IO */
 #define SSL_want_nothing(s)    (SSL_want(s) == SSL_NOTHING)
 #define SSL_want_read(s)       (SSL_want(s) == SSL_READING)
 #define SSL_want_write(s)      (SSL_want(s) == SSL_WRITING)
 #define SSL_want_x509_lookup(s)        (SSL_want(s) == SSL_X509_LOOKUP)
-#define SSL_want_server_random_validation(s)   (SSL_want(s) == SSL_SERVER_RANDOM_VALIDATE)
+
+#define SSL_MAC_FLAG_READ_MAC_STREAM 1
+#define SSL_MAC_FLAG_WRITE_MAC_STREAM 2
 
 struct ssl_st
        {
@@ -914,7 +1019,7 @@ struct ssl_st
        int version;
        int type; /* SSL_ST_CONNECT or SSL_ST_ACCEPT */
 
-       SSL_METHOD *method; /* SSLv3 */
+       const SSL_METHOD *method; /* SSLv3 */
 
        /* There are 2 BIO's even though they are normally both the
         * same.  This is so data can be read and written to different
@@ -997,9 +1102,9 @@ struct ssl_st
 
        /* These are the ones being used, the ones in SSL_SESSION are
         * the ones to be 'copied' into these ones */
-
+       int mac_flags; 
        EVP_CIPHER_CTX *enc_read_ctx;           /* cryptographic state */
-       const EVP_MD *read_hash;                /* used for mac generation */
+       EVP_MD_CTX *read_hash;          /* used for mac generation */
 #ifndef OPENSSL_NO_COMP
        COMP_CTX *expand;                       /* uncompress */
 #else
@@ -1007,7 +1112,7 @@ struct ssl_st
 #endif
 
        EVP_CIPHER_CTX *enc_write_ctx;          /* cryptographic state */
-       const EVP_MD *write_hash;               /* used for mac generation */
+       EVP_MD_CTX *write_hash;         /* used for mac generation */
 #ifndef OPENSSL_NO_COMP
        COMP_CTX *compress;                     /* compression */
 #else
@@ -1028,6 +1133,9 @@ struct ssl_st
        /* This can also be in the session once a session is established */
        SSL_SESSION *session;
 
+        /* This can be disabled to prevent the use of uncached sessions */
+       int session_creation_enabled;
+
        /* Default generate session ID callback. */
        GEN_SESSION_CB generate_session_id;
 
@@ -1045,6 +1153,14 @@ struct ssl_st
        KSSL_CTX *kssl_ctx;     /* Kerberos 5 context */
 #endif /* OPENSSL_NO_KRB5 */
 
+#ifndef OPENSSL_NO_PSK
+       unsigned int (*psk_client_callback)(SSL *ssl, const char *hint, char *identity,
+               unsigned int max_identity_len, unsigned char *psk,
+               unsigned int max_psk_len);
+       unsigned int (*psk_server_callback)(SSL *ssl, const char *identity,
+               unsigned char *psk, unsigned int max_psk_len);
+#endif
+
        SSL_CTX *ctx;
        /* set this flag to 1 and a sleep(1) is put into all SSL_read()
         * and SSL_write() calls, good for nbio debuging :-) */
@@ -1064,6 +1180,7 @@ struct ssl_st
        int first_packet;
        int client_version;     /* what was passed, used for
                                 * SSLv3/TLS rollback check */
+       unsigned int max_send_fragment;
 #ifndef OPENSSL_NO_TLSEXT
        /* TLS extension debug callback */
        void (*tlsext_debug_cb)(SSL *s, int client_server, int type,
@@ -1090,8 +1207,31 @@ struct ssl_st
 
        /* RFC4507 session ticket expected to be received or sent */
        int tlsext_ticket_expected;
+#ifndef OPENSSL_NO_EC
+       size_t tlsext_ecpointformatlist_length;
+       unsigned char *tlsext_ecpointformatlist; /* our list */
+       size_t tlsext_ellipticcurvelist_length;
+       unsigned char *tlsext_ellipticcurvelist; /* our list */
+#endif /* OPENSSL_NO_EC */
+
+       /* draft-rescorla-tls-opaque-prf-input-00.txt information to be used for handshakes */
+       void *tlsext_opaque_prf_input;
+       size_t tlsext_opaque_prf_input_len;
+
+       /* TLS Session Ticket extension override */
+       TLS_SESSION_TICKET_EXT *tlsext_session_ticket;
+
+       /* TLS Session Ticket extension callback */
+       tls_session_ticket_ext_cb_fn tls_session_ticket_ext_cb;
+       void *tls_session_ticket_ext_cb_arg;
+
+       /* TLS pre-shared secret session resumption */
+       tls_session_secret_cb_fn tls_session_secret_cb;
+       void *tls_session_secret_cb_arg;
+
        SSL_CTX * initial_ctx; /* initial ctx, used to store sessions */
 
+#ifndef OPENSSL_NO_NEXTPROTONEG
        /* Next protocol negotiation. For the client, this is the protocol that
         * we sent in NextProtocol and is set when handling ServerHello
         * extensions.
@@ -1101,10 +1241,12 @@ struct ssl_st
         * before the Finished message. */
        unsigned char *next_proto_negotiated;
        unsigned char next_proto_negotiated_len;
+#endif
+
 #define session_ctx initial_ctx
 #else
 #define session_ctx ctx
-#endif
+#endif /* OPENSSL_NO_TLSEXT */
        };
 
 #ifdef __cplusplus
@@ -1213,20 +1355,13 @@ size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count);
 #define SSL_get_timeout(a)     SSL_SESSION_get_timeout(a)
 #define SSL_set_timeout(a,b)   SSL_SESSION_set_timeout((a),(b))
 
-#if 1 /*SSLEAY_MACROS*/
 #define d2i_SSL_SESSION_bio(bp,s_id) ASN1_d2i_bio_of(SSL_SESSION,SSL_SESSION_new,d2i_SSL_SESSION,bp,s_id)
 #define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio_of(SSL_SESSION,i2d_SSL_SESSION,bp,s_id)
-#define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \
-       (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u)
-#define PEM_read_bio_SSL_SESSION(bp,x,cb,u) PEM_ASN1_read_bio_of(SSL_SESSION,d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,x,cb,u)
-#define PEM_write_SSL_SESSION(fp,x) \
-       PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \
-               PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL)
-#define PEM_write_bio_SSL_SESSION(bp,x) \
-       PEM_ASN1_write_bio_of(SSL_SESSION,i2d_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,x,NULL,NULL,0,NULL,NULL)
-#endif
 
-#define SSL_AD_REASON_OFFSET           1000
+DECLARE_PEM_rw(SSL_SESSION, SSL_SESSION)
+
+#define SSL_AD_REASON_OFFSET           1000 /* offset to get SSL_R_... value from SSL_AD_... */
+
 /* These alert types are for SSLv3 and TLSv1 */
 #define SSL_AD_CLOSE_NOTIFY            SSL3_AD_CLOSE_NOTIFY
 #define SSL_AD_UNEXPECTED_MESSAGE      SSL3_AD_UNEXPECTED_MESSAGE /* fatal */
@@ -1256,6 +1391,8 @@ size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count);
 #define SSL_AD_CERTIFICATE_UNOBTAINABLE TLS1_AD_CERTIFICATE_UNOBTAINABLE
 #define SSL_AD_UNRECOGNIZED_NAME       TLS1_AD_UNRECOGNIZED_NAME
 #define SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE
+#define SSL_AD_BAD_CERTIFICATE_HASH_VALUE TLS1_AD_BAD_CERTIFICATE_HASH_VALUE
+#define SSL_AD_UNKNOWN_PSK_IDENTITY     TLS1_AD_UNKNOWN_PSK_IDENTITY /* fatal */
 
 #define SSL_ERROR_NONE                 0
 #define SSL_ERROR_SSL                  1
@@ -1266,7 +1403,6 @@ size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count);
 #define SSL_ERROR_ZERO_RETURN          6
 #define SSL_ERROR_WANT_CONNECT         7
 #define SSL_ERROR_WANT_ACCEPT          8
-#define SSL_ERROR_SERVER_RANDOM_VALIDATION_PENDING     10
 
 #define SSL_CTRL_NEED_TMP_RSA                  1
 #define SSL_CTRL_SET_TMP_RSA                   2
@@ -1315,6 +1451,8 @@ size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count);
 #define SSL_CTRL_GET_MAX_CERT_LIST             50
 #define SSL_CTRL_SET_MAX_CERT_LIST             51
 
+#define SSL_CTRL_SET_MAX_SEND_FRAGMENT         52
+
 /* see tls1.h for macros based on these */
 #ifndef OPENSSL_NO_TLSEXT
 #define SSL_CTRL_SET_TLSEXT_SERVERNAME_CB      53
@@ -1324,7 +1462,9 @@ size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count);
 #define SSL_CTRL_SET_TLSEXT_DEBUG_ARG          57
 #define SSL_CTRL_GET_TLSEXT_TICKET_KEYS                58
 #define SSL_CTRL_SET_TLSEXT_TICKET_KEYS                59
-
+#define SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT   60
+#define SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB        61
+#define SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB_ARG 62
 #define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB      63
 #define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG  64
 #define SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE    65
@@ -1394,7 +1534,7 @@ void BIO_ssl_shutdown(BIO *ssl_bio);
 #endif
 
 int    SSL_CTX_set_cipher_list(SSL_CTX *,const char *str);
-SSL_CTX *SSL_CTX_new(SSL_METHOD *meth);
+SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth);
 void   SSL_CTX_free(SSL_CTX *);
 long SSL_CTX_set_timeout(SSL_CTX *ctx,long t);
 long SSL_CTX_get_timeout(const SSL_CTX *ctx);
@@ -1405,10 +1545,11 @@ int     SSL_clear(SSL *s);
 
 void   SSL_CTX_flush_sessions(SSL_CTX *ctx,long tm);
 
-SSL_CIPHER *SSL_get_current_cipher(const SSL *s);
+const SSL_CIPHER *SSL_get_current_cipher(const SSL *s);
 int    SSL_CIPHER_get_bits(const SSL_CIPHER *c,int *alg_bits);
 char * SSL_CIPHER_get_version(const SSL_CIPHER *c);
 const char *   SSL_CIPHER_get_name(const SSL_CIPHER *c);
+const char *   SSL_CIPHER_authentication_method(const SSL_CIPHER *c);
 
 int    SSL_get_fd(const SSL *s);
 int    SSL_get_rfd(const SSL *s);
@@ -1417,6 +1558,7 @@ const char  * SSL_get_cipher_list(const SSL *s,int n);
 char * SSL_get_shared_ciphers(const SSL *s, char *buf, int len);
 int    SSL_get_read_ahead(const SSL * s);
 int    SSL_pending(const SSL *s);
+const char *   SSL_authentication_method(const SSL *c);
 #ifndef OPENSSL_NO_SOCK
 int    SSL_set_fd(SSL *s, int fd);
 int    SSL_set_rfd(SSL *s, int fd);
@@ -1428,6 +1570,7 @@ BIO *     SSL_get_rbio(const SSL *s);
 BIO *  SSL_get_wbio(const SSL *s);
 #endif
 int    SSL_set_cipher_list(SSL *s, const char *str);
+int    SSL_set_cipher_lists(SSL *s, STACK_OF(SSL_CIPHER) *sk);
 void   SSL_set_read_ahead(SSL *s, int yes);
 int    SSL_get_verify_mode(const SSL *s);
 int    SSL_get_verify_depth(const SSL *s);
@@ -1443,6 +1586,8 @@ int       SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
 int    SSL_use_PrivateKey_ASN1(int pk,SSL *ssl, const unsigned char *d, long len);
 int    SSL_use_certificate(SSL *ssl, X509 *x);
 int    SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len);
+int    SSL_use_certificate_chain(SSL *ssl, STACK_OF(X509) *cert_chain);
+STACK_OF(X509) * SSL_get_certificate_chain(SSL *ssl, X509 *x);
 
 #ifndef OPENSSL_NO_STDIO
 int    SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type);
@@ -1476,9 +1621,9 @@ long      SSL_SESSION_set_timeout(SSL_SESSION *s, long t);
 void   SSL_copy_session_id(SSL *to,const SSL *from);
 
 SSL_SESSION *SSL_SESSION_new(void);
-unsigned long SSL_SESSION_hash(const SSL_SESSION *a);
-int    SSL_SESSION_cmp(const SSL_SESSION *a,const SSL_SESSION *b);
-const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s, unsigned int *len);
+const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s,
+                                       unsigned int *len);
+const char *   SSL_SESSION_get_version(const SSL_SESSION *s);
 #ifndef OPENSSL_NO_FP_API
 int    SSL_SESSION_print_fp(FILE *fp,const SSL_SESSION *ses);
 #endif
@@ -1488,6 +1633,7 @@ int       SSL_SESSION_print(BIO *fp,const SSL_SESSION *ses);
 void   SSL_SESSION_free(SSL_SESSION *ses);
 int    i2d_SSL_SESSION(SSL_SESSION *in,unsigned char **pp);
 int    SSL_set_session(SSL *to, SSL_SESSION *session);
+void   SSL_set_session_creation_enabled(SSL *, int);
 int    SSL_CTX_add_session(SSL_CTX *s, SSL_SESSION *c);
 int    SSL_CTX_remove_session(SSL_CTX *,SSL_SESSION *c);
 int    SSL_CTX_set_generate_session_id(SSL_CTX *, GEN_SESSION_CB);
@@ -1538,6 +1684,9 @@ int SSL_set_purpose(SSL *s, int purpose);
 int SSL_CTX_set_trust(SSL_CTX *s, int trust);
 int SSL_set_trust(SSL *s, int trust);
 
+int SSL_CTX_set1_param(SSL_CTX *ctx, X509_VERIFY_PARAM *vpm);
+int SSL_set1_param(SSL *ssl, X509_VERIFY_PARAM *vpm);
+
 void   SSL_free(SSL *ssl);
 int    SSL_accept(SSL *ssl);
 int    SSL_connect(SSL *ssl);
@@ -1553,27 +1702,29 @@ int     SSL_get_error(const SSL *s,int ret_code);
 const char *SSL_get_version(const SSL *s);
 
 /* This sets the 'default' SSL version that SSL_new() will create */
-int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth);
+int SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *meth);
 
-SSL_METHOD *SSLv2_method(void);                /* SSLv2 */
-SSL_METHOD *SSLv2_server_method(void); /* SSLv2 */
-SSL_METHOD *SSLv2_client_method(void); /* SSLv2 */
+#ifndef OPENSSL_NO_SSL2
+const SSL_METHOD *SSLv2_method(void);          /* SSLv2 */
+const SSL_METHOD *SSLv2_server_method(void);   /* SSLv2 */
+const SSL_METHOD *SSLv2_client_method(void);   /* SSLv2 */
+#endif
 
-SSL_METHOD *SSLv3_method(void);                /* SSLv3 */
-SSL_METHOD *SSLv3_server_method(void); /* SSLv3 */
-SSL_METHOD *SSLv3_client_method(void); /* SSLv3 */
+const SSL_METHOD *SSLv3_method(void);          /* SSLv3 */
+const SSL_METHOD *SSLv3_server_method(void);   /* SSLv3 */
+const SSL_METHOD *SSLv3_client_method(void);   /* SSLv3 */
 
-SSL_METHOD *SSLv23_method(void);       /* SSLv3 but can rollback to v2 */
-SSL_METHOD *SSLv23_server_method(void);        /* SSLv3 but can rollback to v2 */
-SSL_METHOD *SSLv23_client_method(void);        /* SSLv3 but can rollback to v2 */
+const SSL_METHOD *SSLv23_method(void); /* SSLv3 but can rollback to v2 */
+const SSL_METHOD *SSLv23_server_method(void);  /* SSLv3 but can rollback to v2 */
+const SSL_METHOD *SSLv23_client_method(void);  /* SSLv3 but can rollback to v2 */
 
-SSL_METHOD *TLSv1_method(void);                /* TLSv1.0 */
-SSL_METHOD *TLSv1_server_method(void); /* TLSv1.0 */
-SSL_METHOD *TLSv1_client_method(void); /* TLSv1.0 */
+const SSL_METHOD *TLSv1_method(void);          /* TLSv1.0 */
+const SSL_METHOD *TLSv1_server_method(void);   /* TLSv1.0 */
+const SSL_METHOD *TLSv1_client_method(void);   /* TLSv1.0 */
 
-SSL_METHOD *DTLSv1_method(void);               /* DTLSv1.0 */
-SSL_METHOD *DTLSv1_server_method(void);        /* DTLSv1.0 */
-SSL_METHOD *DTLSv1_client_method(void);        /* DTLSv1.0 */
+const SSL_METHOD *DTLSv1_method(void);         /* DTLSv1.0 */
+const SSL_METHOD *DTLSv1_server_method(void);  /* DTLSv1.0 */
+const SSL_METHOD *DTLSv1_client_method(void);  /* DTLSv1.0 */
 
 STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *s);
 
@@ -1582,8 +1733,8 @@ int SSL_renegotiate(SSL *s);
 int SSL_renegotiate_pending(SSL *s);
 int SSL_shutdown(SSL *s);
 
-SSL_METHOD *SSL_get_ssl_method(SSL *s);
-int SSL_set_ssl_method(SSL *s,SSL_METHOD *method);
+const SSL_METHOD *SSL_get_ssl_method(SSL *s);
+int SSL_set_ssl_method(SSL *s, const SSL_METHOD *method);
 const char *SSL_alert_type_string_long(int value);
 const char *SSL_alert_type_string(int value);
 const char *SSL_alert_desc_string_long(int value);
@@ -1675,6 +1826,11 @@ int SSL_get_ex_data_X509_STORE_CTX_idx(void );
 #define SSL_set_max_cert_list(ssl,m) \
        SSL_ctrl(ssl,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL)
 
+#define SSL_CTX_set_max_send_fragment(ctx,m) \
+       SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_SEND_FRAGMENT,m,NULL)
+#define SSL_set_max_send_fragment(ssl,m) \
+       SSL_ctrl(ssl,SSL_CTRL_SET_MAX_SEND_FRAGMENT,m,NULL)
+
      /* NB: the keylength is only applicable when is_export is true */
 #ifndef OPENSSL_NO_RSA
 void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,
@@ -1716,6 +1872,15 @@ void *SSL_COMP_get_compression_methods(void);
 int SSL_COMP_add_compression_method(int id,void *cm);
 #endif
 
+/* TLS extensions functions */
+int SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len);
+
+int SSL_set_session_ticket_ext_cb(SSL *s, tls_session_ticket_ext_cb_fn cb,
+                                 void *arg);
+
+/* Pre-shared secret session resumption functions */
+int SSL_set_session_secret_cb(SSL *s, tls_session_secret_cb_fn tls_session_secret_cb, void *arg);
+
 /* BEGIN ERROR CODES */
 /* The following lines are auto generated by the script mkerr.pl. Any changes
  * made after this point may be overwritten when the script is next run.
@@ -1733,7 +1898,7 @@ void ERR_load_SSL_strings(void);
 #define SSL_F_DO_DTLS1_WRITE                            245
 #define SSL_F_DO_SSL3_WRITE                             104
 #define SSL_F_DTLS1_ACCEPT                              246
-#define SSL_F_DTLS1_ADD_CERT_TO_BUF                     280
+#define SSL_F_DTLS1_ADD_CERT_TO_BUF                     295
 #define SSL_F_DTLS1_BUFFER_RECORD                       247
 #define SSL_F_DTLS1_CLIENT_HELLO                        248
 #define SSL_F_DTLS1_CONNECT                             249
@@ -1742,9 +1907,9 @@ void ERR_load_SSL_strings(void);
 #define SSL_F_DTLS1_GET_MESSAGE                                 252
 #define SSL_F_DTLS1_GET_MESSAGE_FRAGMENT                253
 #define SSL_F_DTLS1_GET_RECORD                          254
-#define SSL_F_DTLS1_HANDLE_TIMEOUT                      282
+#define SSL_F_DTLS1_HANDLE_TIMEOUT                      297
 #define SSL_F_DTLS1_OUTPUT_CERT_CHAIN                   255
-#define SSL_F_DTLS1_PREPROCESS_FRAGMENT                         277
+#define SSL_F_DTLS1_PREPROCESS_FRAGMENT                         288
 #define SSL_F_DTLS1_PROCESS_OUT_OF_SEQ_MESSAGE          256
 #define SSL_F_DTLS1_PROCESS_RECORD                      257
 #define SSL_F_DTLS1_READ_BYTES                          258
@@ -1766,7 +1931,6 @@ void ERR_load_SSL_strings(void);
 #define SSL_F_GET_SERVER_VERIFY                                 110
 #define SSL_F_I2D_SSL_SESSION                           111
 #define SSL_F_READ_N                                    112
-#define SSL_F_SSL3_READ_SNAP_START_N                    300
 #define SSL_F_REQUEST_CERTIFICATE                       113
 #define SSL_F_SERVER_FINISH                             239
 #define SSL_F_SERVER_HELLO                              114
@@ -1789,19 +1953,21 @@ void ERR_load_SSL_strings(void);
 #define SSL_F_SSL2_SET_CERTIFICATE                      126
 #define SSL_F_SSL2_WRITE                                127
 #define SSL_F_SSL3_ACCEPT                               128
-#define SSL_F_SSL3_ADD_CERT_TO_BUF                      281
+#define SSL_F_SSL3_ADD_CERT_TO_BUF                      296
 #define SSL_F_SSL3_CALLBACK_CTRL                        233
 #define SSL_F_SSL3_CHANGE_CIPHER_STATE                  129
 #define SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM             130
+#define SSL_F_SSL3_CHECK_CLIENT_HELLO                   304
 #define SSL_F_SSL3_CLIENT_HELLO                                 131
 #define SSL_F_SSL3_CONNECT                              132
 #define SSL_F_SSL3_CTRL                                         213
 #define SSL_F_SSL3_CTX_CTRL                             133
-#define SSL_F_SSL3_DO_CHANGE_CIPHER_SPEC                279
+#define SSL_F_SSL3_DIGEST_CACHED_RECORDS                293
+#define SSL_F_SSL3_DO_CHANGE_CIPHER_SPEC                292
 #define SSL_F_SSL3_ENC                                  134
 #define SSL_F_SSL3_GENERATE_KEY_BLOCK                   238
 #define SSL_F_SSL3_GET_CERTIFICATE_REQUEST              135
-#define SSL_F_SSL3_GET_CERT_STATUS                      288
+#define SSL_F_SSL3_GET_CERT_STATUS                      289
 #define SSL_F_SSL3_GET_CERT_VERIFY                      136
 #define SSL_F_SSL3_GET_CLIENT_CERTIFICATE               137
 #define SSL_F_SSL3_GET_CLIENT_HELLO                     138
@@ -1810,12 +1976,13 @@ void ERR_load_SSL_strings(void);
 #define SSL_F_SSL3_GET_KEY_EXCHANGE                     141
 #define SSL_F_SSL3_GET_MESSAGE                          142
 #define SSL_F_SSL3_GET_NEW_SESSION_TICKET               283
-#define SSL_F_SSL3_GET_NEXT_PROTO                       297
+#define SSL_F_SSL3_GET_NEXT_PROTO                       304
 #define SSL_F_SSL3_GET_RECORD                           143
 #define SSL_F_SSL3_GET_SERVER_CERTIFICATE               144
 #define SSL_F_SSL3_GET_SERVER_DONE                      145
 #define SSL_F_SSL3_GET_SERVER_HELLO                     146
-#define SSL_F_SSL3_NEW_SESSION_TICKET                   284
+#define SSL_F_SSL3_HANDSHAKE_MAC                        285
+#define SSL_F_SSL3_NEW_SESSION_TICKET                   287
 #define SSL_F_SSL3_OUTPUT_CERT_CHAIN                    147
 #define SSL_F_SSL3_PEEK                                         235
 #define SSL_F_SSL3_READ_BYTES                           148
@@ -1827,16 +1994,17 @@ void ERR_load_SSL_strings(void);
 #define SSL_F_SSL3_SEND_SERVER_CERTIFICATE              154
 #define SSL_F_SSL3_SEND_SERVER_HELLO                    242
 #define SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE             155
-#define SSL_F_SSL3_SETUP_BUFFERS                        156
 #define SSL_F_SSL3_SETUP_KEY_BLOCK                      157
+#define SSL_F_SSL3_SETUP_READ_BUFFER                    156
+#define SSL_F_SSL3_SETUP_WRITE_BUFFER                   291
 #define SSL_F_SSL3_WRITE_BYTES                          158
 #define SSL_F_SSL3_WRITE_PENDING                        159
-#define SSL_F_SSL_ADD_CLIENTHELLO_RENEGOTIATE_EXT       285
-#define SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT                272
+#define SSL_F_SSL_ADD_CLIENTHELLO_RENEGOTIATE_EXT       298
+#define SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT                277
 #define SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK        215
 #define SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK       216
-#define SSL_F_SSL_ADD_SERVERHELLO_RENEGOTIATE_EXT       286
-#define SSL_F_SSL_ADD_SERVERHELLO_TLSEXT                273
+#define SSL_F_SSL_ADD_SERVERHELLO_RENEGOTIATE_EXT       299
+#define SSL_F_SSL_ADD_SERVERHELLO_TLSEXT                278
 #define SSL_F_SSL_BAD_METHOD                            160
 #define SSL_F_SSL_BYTES_TO_CIPHER_LIST                  161
 #define SSL_F_SSL_CERT_DUP                              221
@@ -1844,7 +2012,8 @@ void ERR_load_SSL_strings(void);
 #define SSL_F_SSL_CERT_INSTANTIATE                      214
 #define SSL_F_SSL_CERT_NEW                              162
 #define SSL_F_SSL_CHECK_PRIVATE_KEY                     163
-#define SSL_F_SSL_CHECK_SERVERHELLO_TLSEXT              274
+#define SSL_F_SSL_CHECK_SERVERHELLO_TLSEXT              280
+#define SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG           279
 #define SSL_F_SSL_CIPHER_PROCESS_RULESTR                230
 #define SSL_F_SSL_CIPHER_STRENGTH_SORT                  231
 #define SSL_F_SSL_CLEAR                                         164
@@ -1854,7 +2023,7 @@ void ERR_load_SSL_strings(void);
 #define SSL_F_SSL_CTX_CHECK_PRIVATE_KEY                         168
 #define SSL_F_SSL_CTX_NEW                               169
 #define SSL_F_SSL_CTX_SET_CIPHER_LIST                   269
-#define SSL_F_SSL_CTX_SET_CLIENT_CERT_ENGINE            278
+#define SSL_F_SSL_CTX_SET_CLIENT_CERT_ENGINE            290
 #define SSL_F_SSL_CTX_SET_PURPOSE                       226
 #define SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT            219
 #define SSL_F_SSL_CTX_SET_SSL_VERSION                   170
@@ -1866,6 +2035,7 @@ void ERR_load_SSL_strings(void);
 #define SSL_F_SSL_CTX_USE_PRIVATEKEY                    174
 #define SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1               175
 #define SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE               176
+#define SSL_F_SSL_CTX_USE_PSK_IDENTITY_HINT             272
 #define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY                         177
 #define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1            178
 #define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE            179
@@ -1877,14 +2047,14 @@ void ERR_load_SSL_strings(void);
 #define SSL_F_SSL_INIT_WBIO_BUFFER                      184
 #define SSL_F_SSL_LOAD_CLIENT_CA_FILE                   185
 #define SSL_F_SSL_NEW                                   186
-#define SSL_F_SSL_NEXT_PROTOS_PARSE                     298
-#define SSL_F_SSL_PARSE_CLIENTHELLO_RENEGOTIATE_EXT     287
-#define SSL_F_SSL_PARSE_CLIENTHELLO_TLSEXT              290
-#define SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT     289
-#define SSL_F_SSL_PARSE_SERVERHELLO_TLSEXT              291
+#define SSL_F_SSL_PARSE_CLIENTHELLO_RENEGOTIATE_EXT     300
+#define SSL_F_SSL_PARSE_CLIENTHELLO_TLSEXT              302
+#define SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT     301
+#define SSL_F_SSL_PARSE_SERVERHELLO_TLSEXT              303
 #define SSL_F_SSL_PEEK                                  270
-#define SSL_F_SSL_PREPARE_CLIENTHELLO_TLSEXT            275
-#define SSL_F_SSL_PREPARE_SERVERHELLO_TLSEXT            276
+#define SSL_F_TLS1_EXPORT_KEYING_MATERIAL               312
+#define SSL_F_SSL_PREPARE_CLIENTHELLO_TLSEXT            281
+#define SSL_F_SSL_PREPARE_SERVERHELLO_TLSEXT            282
 #define SSL_F_SSL_READ                                  223
 #define SSL_F_SSL_RSA_PRIVATE_DECRYPT                   187
 #define SSL_F_SSL_RSA_PUBLIC_ENCRYPT                    188
@@ -1899,6 +2069,7 @@ void ERR_load_SSL_strings(void);
 #define SSL_F_SSL_SET_RFD                               194
 #define SSL_F_SSL_SET_SESSION                           195
 #define SSL_F_SSL_SET_SESSION_ID_CONTEXT                218
+#define SSL_F_SSL_SET_SESSION_TICKET_EXT                294
 #define SSL_F_SSL_SET_TRUST                             228
 #define SSL_F_SSL_SET_WFD                               196
 #define SSL_F_SSL_SHUTDOWN                              224
@@ -1907,20 +2078,26 @@ void ERR_load_SSL_strings(void);
 #define SSL_F_SSL_UNDEFINED_VOID_FUNCTION               244
 #define SSL_F_SSL_USE_CERTIFICATE                       198
 #define SSL_F_SSL_USE_CERTIFICATE_ASN1                  199
+#define SSL_F_SSL_USE_CERTIFICATE_CHAIN                         2000
 #define SSL_F_SSL_USE_CERTIFICATE_FILE                  200
 #define SSL_F_SSL_USE_PRIVATEKEY                        201
 #define SSL_F_SSL_USE_PRIVATEKEY_ASN1                   202
 #define SSL_F_SSL_USE_PRIVATEKEY_FILE                   203
+#define SSL_F_SSL_USE_PSK_IDENTITY_HINT                         273
 #define SSL_F_SSL_USE_RSAPRIVATEKEY                     204
 #define SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1                205
 #define SSL_F_SSL_USE_RSAPRIVATEKEY_FILE                206
 #define SSL_F_SSL_VERIFY_CERT_CHAIN                     207
 #define SSL_F_SSL_WRITE                                         208
+#define SSL_F_TLS1_CERT_VERIFY_MAC                      286
 #define SSL_F_TLS1_CHANGE_CIPHER_STATE                  209
+#define SSL_F_TLS1_CHECK_SERVERHELLO_TLSEXT             274
 #define SSL_F_TLS1_ENC                                  210
+#define SSL_F_TLS1_PREPARE_CLIENTHELLO_TLSEXT           275
+#define SSL_F_TLS1_PREPARE_SERVERHELLO_TLSEXT           276
+#define SSL_F_TLS1_PRF                                  284
 #define SSL_F_TLS1_SETUP_KEY_BLOCK                      211
 #define SSL_F_WRITE_PENDING                             212
-/* Next entry: 300 */
 
 /* Reason codes. */
 #define SSL_R_APP_DATA_IN_HANDSHAKE                     100
@@ -1939,12 +2116,15 @@ void ERR_load_SSL_strings(void);
 #define SSL_R_BAD_ECC_CERT                              304
 #define SSL_R_BAD_ECDSA_SIGNATURE                       305
 #define SSL_R_BAD_ECPOINT                               306
+#define SSL_R_BAD_HANDSHAKE_LENGTH                      332
 #define SSL_R_BAD_HELLO_REQUEST                                 105
 #define SSL_R_BAD_LENGTH                                271
 #define SSL_R_BAD_MAC_DECODE                            113
+#define SSL_R_BAD_MAC_LENGTH                            333
 #define SSL_R_BAD_MESSAGE_TYPE                          114
 #define SSL_R_BAD_PACKET_LENGTH                                 115
 #define SSL_R_BAD_PROTOCOL_VERSION_NUMBER               116
+#define SSL_R_BAD_PSK_IDENTITY_HINT_LENGTH              316
 #define SSL_R_BAD_RESPONSE_ARGUMENT                     117
 #define SSL_R_BAD_RSA_DECRYPT                           118
 #define SSL_R_BAD_RSA_ENCRYPT                           119
@@ -1968,8 +2148,9 @@ void ERR_load_SSL_strings(void);
 #define SSL_R_CIPHER_CODE_WRONG_LENGTH                  137
 #define SSL_R_CIPHER_OR_HASH_UNAVAILABLE                138
 #define SSL_R_CIPHER_TABLE_SRC_ERROR                    139
-#define SSL_R_CLIENTHELLO_TLSEXT                        157
+#define SSL_R_CLIENTHELLO_TLSEXT                        226
 #define SSL_R_COMPRESSED_LENGTH_TOO_LONG                140
+#define SSL_R_COMPRESSION_DISABLED                      343
 #define SSL_R_COMPRESSION_FAILURE                       141
 #define SSL_R_COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE   307
 #define SSL_R_COMPRESSION_LIBRARY_ERROR                         142
@@ -1982,8 +2163,12 @@ void ERR_load_SSL_strings(void);
 #define SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC       281
 #define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG           148
 #define SSL_R_DIGEST_CHECK_FAILED                       149
-#define SSL_R_DTLS_MESSAGE_TOO_BIG                      318
+#define SSL_R_DTLS_MESSAGE_TOO_BIG                      334
 #define SSL_R_DUPLICATE_COMPRESSION_ID                  309
+#define SSL_R_ECC_CERT_NOT_FOR_KEY_AGREEMENT            317
+#define SSL_R_ECC_CERT_NOT_FOR_SIGNING                  318
+#define SSL_R_ECC_CERT_SHOULD_HAVE_RSA_SIGNATURE        322
+#define SSL_R_ECC_CERT_SHOULD_HAVE_SHA1_SIGNATURE       323
 #define SSL_R_ECGROUP_TOO_LARGE_FOR_CIPHER              310
 #define SSL_R_ENCRYPTED_LENGTH_TOO_LONG                         150
 #define SSL_R_ERROR_GENERATING_TMP_RSA_KEY              282
@@ -1991,16 +2176,18 @@ void ERR_load_SSL_strings(void);
 #define SSL_R_EXCESSIVE_MESSAGE_SIZE                    152
 #define SSL_R_EXTRA_DATA_IN_MESSAGE                     153
 #define SSL_R_GOT_A_FIN_BEFORE_A_CCS                    154
-#define SSL_R_GOT_NEXT_PROTO_BEFORE_A_CCS               334
-#define SSL_R_GOT_NEXT_PROTO_WITHOUT_EXTENSION          335
+#define SSL_R_GOT_NEXT_PROTO_BEFORE_A_CCS               346
+#define SSL_R_GOT_NEXT_PROTO_WITHOUT_EXTENSION          347
 #define SSL_R_HTTPS_PROXY_REQUEST                       155
 #define SSL_R_HTTP_REQUEST                              156
 #define SSL_R_ILLEGAL_PADDING                           283
+#define SSL_R_INCONSISTENT_COMPRESSION                  340
 #define SSL_R_INVALID_CHALLENGE_LENGTH                  158
 #define SSL_R_INVALID_COMMAND                           280
+#define SSL_R_INVALID_COMPRESSION_ALGORITHM             341
 #define SSL_R_INVALID_PURPOSE                           278
-#define SSL_R_INVALID_STATUS_RESPONSE                   316
-#define SSL_R_INVALID_TICKET_KEYS_LENGTH                275
+#define SSL_R_INVALID_STATUS_RESPONSE                   328
+#define SSL_R_INVALID_TICKET_KEYS_LENGTH                325
 #define SSL_R_INVALID_TRUST                             279
 #define SSL_R_KEY_ARG_TOO_LONG                          284
 #define SSL_R_KRB5                                      285
@@ -2033,6 +2220,7 @@ void ERR_load_SSL_strings(void);
 #define SSL_R_MISSING_TMP_RSA_KEY                       172
 #define SSL_R_MISSING_TMP_RSA_PKEY                      173
 #define SSL_R_MISSING_VERIFY_MESSAGE                    174
+#define SSL_R_MULTIPLE_SGC_RESTARTS                     346
 #define SSL_R_NON_SSLV2_INITIAL_PACKET                  175
 #define SSL_R_NO_CERTIFICATES_RETURNED                  176
 #define SSL_R_NO_CERTIFICATE_ASSIGNED                   177
@@ -2044,23 +2232,27 @@ void ERR_load_SSL_strings(void);
 #define SSL_R_NO_CIPHERS_SPECIFIED                      183
 #define SSL_R_NO_CIPHER_LIST                            184
 #define SSL_R_NO_CIPHER_MATCH                           185
-#define SSL_R_NO_CLIENT_CERT_METHOD                     317
+#define SSL_R_NO_CLIENT_CERT_METHOD                     331
 #define SSL_R_NO_CLIENT_CERT_RECEIVED                   186
 #define SSL_R_NO_COMPRESSION_SPECIFIED                  187
+#define SSL_R_NO_GOST_CERTIFICATE_SENT_BY_PEER          330
 #define SSL_R_NO_METHOD_SPECIFIED                       188
 #define SSL_R_NO_PRIVATEKEY                             189
 #define SSL_R_NO_PRIVATE_KEY_ASSIGNED                   190
 #define SSL_R_NO_PROTOCOLS_AVAILABLE                    191
 #define SSL_R_NO_PUBLICKEY                              192
-#define SSL_R_NO_RENEGOTIATION                          319
+#define SSL_R_NO_RENEGOTIATION                          339
+#define SSL_R_NO_REQUIRED_DIGEST                        324
 #define SSL_R_NO_SHARED_CIPHER                          193
 #define SSL_R_NO_VERIFY_CALLBACK                        194
 #define SSL_R_NULL_SSL_CTX                              195
 #define SSL_R_NULL_SSL_METHOD_PASSED                    196
 #define SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED           197
+#define SSL_R_OLD_SESSION_COMPRESSION_ALGORITHM_NOT_RETURNED 344
 #define SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE             297
+#define SSL_R_OPAQUE_PRF_INPUT_TOO_LONG                         327
 #define SSL_R_PACKET_LENGTH_TOO_LONG                    198
-#define SSL_R_PARSE_TLSEXT                              223
+#define SSL_R_PARSE_TLSEXT                              227
 #define SSL_R_PATH_TOO_LONG                             270
 #define SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE                 199
 #define SSL_R_PEER_ERROR                                200
@@ -2071,6 +2263,9 @@ void ERR_load_SSL_strings(void);
 #define SSL_R_PRE_MAC_LENGTH_TOO_LONG                   205
 #define SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS                 206
 #define SSL_R_PROTOCOL_IS_SHUTDOWN                      207
+#define SSL_R_PSK_IDENTITY_NOT_FOUND                    223
+#define SSL_R_PSK_NO_CLIENT_CB                          224
+#define SSL_R_PSK_NO_SERVER_CB                          225
 #define SSL_R_PUBLIC_KEY_ENCRYPT_ERROR                  208
 #define SSL_R_PUBLIC_KEY_IS_NOT_RSA                     209
 #define SSL_R_PUBLIC_KEY_NOT_RSA                        210
@@ -2080,22 +2275,25 @@ void ERR_load_SSL_strings(void);
 #define SSL_R_RECORD_LENGTH_MISMATCH                    213
 #define SSL_R_RECORD_TOO_LARGE                          214
 #define SSL_R_RECORD_TOO_SMALL                          298
-#define SSL_R_RENEGOTIATE_EXT_TOO_LONG                  320
-#define SSL_R_RENEGOTIATION_ENCODING_ERR                321
-#define SSL_R_RENEGOTIATION_MISMATCH                    322
+#define SSL_R_RENEGOTIATE_EXT_TOO_LONG                  335
+#define SSL_R_RENEGOTIATION_ENCODING_ERR                336
+#define SSL_R_RENEGOTIATION_MISMATCH                    337
 #define SSL_R_REQUIRED_CIPHER_MISSING                   215
+#define SSL_R_REQUIRED_COMPRESSSION_ALGORITHM_MISSING   342
 #define SSL_R_REUSE_CERT_LENGTH_NOT_ZERO                216
 #define SSL_R_REUSE_CERT_TYPE_NOT_ZERO                  217
 #define SSL_R_REUSE_CIPHER_LIST_NOT_ZERO                218
-#define SSL_R_SCSV_RECEIVED_WHEN_RENEGOTIATING          324
-#define SSL_R_SERVERHELLO_TLSEXT                        224
+#define SSL_R_SCSV_RECEIVED_WHEN_RENEGOTIATING          345
+#define SSL_R_SERVERHELLO_TLSEXT                        275
 #define SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED          277
+#define SSL_R_SESSION_MAY_NOT_BE_CREATED                2000
 #define SSL_R_SHORT_READ                                219
 #define SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE     220
 #define SSL_R_SSL23_DOING_SESSION_ID_REUSE              221
 #define SSL_R_SSL2_CONNECTION_ID_TOO_LONG               299
-#define SSL_R_SSL3_EXT_INVALID_SERVERNAME               225
-#define SSL_R_SSL3_EXT_INVALID_SERVERNAME_TYPE          226
+#define SSL_R_SSL3_EXT_INVALID_ECPOINTFORMAT            321
+#define SSL_R_SSL3_EXT_INVALID_SERVERNAME               319
+#define SSL_R_SSL3_EXT_INVALID_SERVERNAME_TYPE          320
 #define SSL_R_SSL3_SESSION_ID_TOO_LONG                  300
 #define SSL_R_SSL3_SESSION_ID_TOO_SHORT                         222
 #define SSL_R_SSLV3_ALERT_BAD_CERTIFICATE               1042
@@ -2129,8 +2327,14 @@ void ERR_load_SSL_strings(void);
 #define SSL_R_TLSV1_ALERT_RECORD_OVERFLOW               1022
 #define SSL_R_TLSV1_ALERT_UNKNOWN_CA                    1048
 #define SSL_R_TLSV1_ALERT_USER_CANCELLED                1090
+#define SSL_R_TLSV1_BAD_CERTIFICATE_HASH_VALUE          1114
+#define SSL_R_TLSV1_BAD_CERTIFICATE_STATUS_RESPONSE     1113
+#define SSL_R_TLSV1_CERTIFICATE_UNOBTAINABLE            1111
+#define SSL_R_TLSV1_UNRECOGNIZED_NAME                   1112
+#define SSL_R_TLSV1_UNSUPPORTED_EXTENSION               1110
 #define SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER      232
-#define SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST            227
+#define SSL_R_TLS_ILLEGAL_EXPORTER_LABEL                367
+#define SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST            157
 #define SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST 233
 #define SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG   234
 #define SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER           235
@@ -2157,9 +2361,10 @@ void ERR_load_SSL_strings(void);
 #define SSL_R_UNKNOWN_REMOTE_ERROR_TYPE                         253
 #define SSL_R_UNKNOWN_SSL_VERSION                       254
 #define SSL_R_UNKNOWN_STATE                             255
-#define SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED      323
+#define SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED      338
 #define SSL_R_UNSUPPORTED_CIPHER                        256
 #define SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM                 257
+#define SSL_R_UNSUPPORTED_DIGEST_TYPE                   326
 #define SSL_R_UNSUPPORTED_ELLIPTIC_CURVE                315
 #define SSL_R_UNSUPPORTED_PROTOCOL                      258
 #define SSL_R_UNSUPPORTED_SSL_VERSION                   259
@@ -2174,7 +2379,6 @@ void ERR_load_SSL_strings(void);
 #define SSL_R_WRONG_VERSION_NUMBER                      267
 #define SSL_R_X509_LIB                                  268
 #define SSL_R_X509_VERIFICATION_SETUP_PROBLEMS          269
-/* Next entry: 335 or 1115 */
 
 #ifdef  __cplusplus
 }
index 4a6e8cf..d6425e5 100644 (file)
 #include <openssl/buffer.h>
 #include <openssl/evp.h>
 #include <openssl/ssl.h>
-#include <openssl/pq_compat.h>
 
 #ifdef  __cplusplus
 extern "C" {
@@ -163,12 +162,14 @@ extern "C" {
 #define SSL3_CK_ADH_DES_64_CBC_SHA             0x0300001A
 #define SSL3_CK_ADH_DES_192_CBC_SHA            0x0300001B
 
-#define SSL3_CK_FZA_DMS_NULL_SHA               0x0300001C
-#define SSL3_CK_FZA_DMS_FZA_SHA                        0x0300001D
-#if 0 /* Because it clashes with KRB5, is never used any more, and is safe
-        to remove according to David Hopwood <david.hopwood@zetnet.co.uk>
-        of the ietf-tls list */
-#define SSL3_CK_FZA_DMS_RC4_SHA                        0x0300001E
+#if 0
+       #define SSL3_CK_FZA_DMS_NULL_SHA                0x0300001C
+       #define SSL3_CK_FZA_DMS_FZA_SHA                 0x0300001D
+       #if 0 /* Because it clashes with KRB5, is never used any more, and is safe
+                to remove according to David Hopwood <david.hopwood@zetnet.co.uk>
+                of the ietf-tls list */
+       #define SSL3_CK_FZA_DMS_RC4_SHA                 0x0300001E
+       #endif
 #endif
 
 /*    VRS Additional Kerberos5 entries
@@ -220,9 +221,11 @@ extern "C" {
 #define SSL3_TXT_ADH_DES_64_CBC_SHA            "ADH-DES-CBC-SHA"
 #define SSL3_TXT_ADH_DES_192_CBC_SHA           "ADH-DES-CBC3-SHA"
 
-#define SSL3_TXT_FZA_DMS_NULL_SHA              "FZA-NULL-SHA"
-#define SSL3_TXT_FZA_DMS_FZA_SHA               "FZA-FZA-CBC-SHA"
-#define SSL3_TXT_FZA_DMS_RC4_SHA               "FZA-RC4-SHA"
+#if 0
+       #define SSL3_TXT_FZA_DMS_NULL_SHA               "FZA-NULL-SHA"
+       #define SSL3_TXT_FZA_DMS_FZA_SHA                "FZA-FZA-CBC-SHA"
+       #define SSL3_TXT_FZA_DMS_RC4_SHA                "FZA-RC4-SHA"
+#endif
 
 #define SSL3_TXT_KRB5_DES_64_CBC_SHA           "KRB5-DES-CBC-SHA"
 #define SSL3_TXT_KRB5_DES_192_CBC3_SHA         "KRB5-DES-CBC3-SHA"
@@ -248,23 +251,75 @@ extern "C" {
 #define SSL3_SESSION_ID_SIZE                   32
 #define SSL3_RT_HEADER_LENGTH                  5
 
-/* Due to MS stuffing up, this can change.... */
-#if defined(OPENSSL_SYS_WIN16) || \
-       (defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN32))
-#define SSL3_RT_MAX_EXTRA                      (14000)
+#ifndef SSL3_ALIGN_PAYLOAD
+ /* Some will argue that this increases memory footprint, but it's
+  * not actually true. Point is that malloc has to return at least
+  * 64-bit aligned pointers, meaning that allocating 5 bytes wastes
+  * 3 bytes in either case. Suggested pre-gaping simply moves these
+  * wasted bytes from the end of allocated region to its front,
+  * but makes data payload aligned, which improves performance:-) */
+# define SSL3_ALIGN_PAYLOAD                    8
 #else
-#define SSL3_RT_MAX_EXTRA                      (16384)
+# if (SSL3_ALIGN_PAYLOAD&(SSL3_ALIGN_PAYLOAD-1))!=0
+#  error "insane SSL3_ALIGN_PAYLOAD"
+#  undef SSL3_ALIGN_PAYLOAD
+# endif
 #endif
 
+/* This is the maximum MAC (digest) size used by the SSL library.
+ * Currently maximum of 20 is used by SHA1, but we reserve for
+ * future extension for 512-bit hashes.
+ */
+
+#define SSL3_RT_MAX_MD_SIZE                    64
+
+/* Maximum block size used in all ciphersuites. Currently 16 for AES.
+ */
+
+#define        SSL_RT_MAX_CIPHER_BLOCK_SIZE            16
+
+#define SSL3_RT_MAX_EXTRA                      (16384)
+
+/* Default buffer length used for writen records.  Thus a generated record
+ * will contain plaintext no larger than this value. */
+#define SSL3_RT_DEFAULT_PLAIN_LENGTH   2048
+/* Maximum plaintext length: defined by SSL/TLS standards */
 #define SSL3_RT_MAX_PLAIN_LENGTH               16384
+/* Maximum compression overhead: defined by SSL/TLS standards */
+#define SSL3_RT_MAX_COMPRESSED_OVERHEAD                1024
+
+/* The standards give a maximum encryption overhead of 1024 bytes.
+ * In practice the value is lower than this. The overhead is the maximum
+ * number of padding bytes (256) plus the mac size.
+ */
+#define SSL3_RT_MAX_ENCRYPTED_OVERHEAD (256 + SSL3_RT_MAX_MD_SIZE)
+
+/* OpenSSL currently only uses a padding length of at most one block so
+ * the send overhead is smaller.
+ */
+
+#define SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD \
+                       (SSL_RT_MAX_CIPHER_BLOCK_SIZE + SSL3_RT_MAX_MD_SIZE)
+
+/* If compression isn't used don't include the compression overhead */
+
 #ifdef OPENSSL_NO_COMP
-#define SSL3_RT_MAX_COMPRESSED_LENGTH  SSL3_RT_MAX_PLAIN_LENGTH
+#define SSL3_RT_MAX_COMPRESSED_LENGTH          SSL3_RT_MAX_PLAIN_LENGTH
 #else
-#define SSL3_RT_MAX_COMPRESSED_LENGTH  (1024+SSL3_RT_MAX_PLAIN_LENGTH)
+#define SSL3_RT_MAX_COMPRESSED_LENGTH  \
+               (SSL3_RT_MAX_PLAIN_LENGTH+SSL3_RT_MAX_COMPRESSED_OVERHEAD)
+#endif
+#define SSL3_RT_MAX_ENCRYPTED_LENGTH   \
+               (SSL3_RT_MAX_ENCRYPTED_OVERHEAD+SSL3_RT_MAX_COMPRESSED_LENGTH)
+#define SSL3_RT_MAX_PACKET_SIZE                \
+               (SSL3_RT_MAX_ENCRYPTED_LENGTH+SSL3_RT_HEADER_LENGTH)
+
+/* Extra space for empty fragment, headers, MAC, and padding. */
+#define SSL3_RT_DEFAULT_WRITE_OVERHEAD  256
+#define SSL3_RT_DEFAULT_PACKET_SIZE     4096 - SSL3_RT_DEFAULT_WRITE_OVERHEAD
+#if SSL3_RT_DEFAULT_PLAIN_LENGTH + SSL3_RT_DEFAULT_WRITE_OVERHEAD > SSL3_RT_DEFAULT_PACKET_SIZE
+#error "Insufficient space allocated for write buffers."
 #endif
-#define SSL3_RT_MAX_ENCRYPTED_LENGTH   (1024+SSL3_RT_MAX_COMPRESSED_LENGTH)
-#define SSL3_RT_MAX_PACKET_SIZE                (SSL3_RT_MAX_ENCRYPTED_LENGTH+SSL3_RT_HEADER_LENGTH)
-#define SSL3_RT_MAX_DATA_SIZE                  (1024*1024)
 
 #define SSL3_MD_CLIENT_FINISHED_CONST  "\x43\x4C\x4E\x54"
 #define SSL3_MD_SERVER_FINISHED_CONST  "\x53\x52\x56\x52"
@@ -303,7 +358,7 @@ typedef struct ssl3_record_st
 /*rw*/ unsigned char *input;   /* where the decode bytes are */
 /*r */ unsigned char *comp;    /* only used with decompression - malloc()ed */
 /*r */  unsigned long epoch;    /* epoch number, needed by DTLS1 */
-/*r */  PQ_64BIT seq_num;       /* sequence number, needed by DTLS1 */
+/*r */  unsigned char seq_num[8]; /* sequence number, needed by DTLS1 */
        } SSL3_RECORD;
 
 typedef struct ssl3_buffer_st
@@ -326,13 +381,25 @@ typedef struct ssl3_buffer_st
  * enough to contain all of the cert types defined either for
  * SSLv3 and TLSv1.
  */
-#define SSL3_CT_NUMBER                 7
+#define SSL3_CT_NUMBER                 9
 
 
 #define SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS      0x0001
 #define SSL3_FLAGS_DELAY_CLIENT_FINISHED       0x0002
 #define SSL3_FLAGS_POP_BUFFER                  0x0004
 #define TLS1_FLAGS_TLS_PADDING_BUG             0x0008
+#define TLS1_FLAGS_SKIP_CERT_VERIFY            0x0010
+/* SSL3_FLAGS_SGC_RESTART_DONE is set when we
+ * restart a handshake because of MS SGC and so prevents us
+ * from restarting the handshake in a loop. It's reset on a
+ * renegotiation, so effectively limits the client to one restart
+ * per negotiation. This limits the possibility of a DDoS
+ * attack where the client handshakes in a loop using SGC to
+ * restart. Servers which permit renegotiation can still be
+ * effected, but we can't prevent that.
+ */
+#define SSL3_FLAGS_SGC_RESTART_DONE            0x0040
 
 typedef struct ssl3_state_st
        {
@@ -340,8 +407,10 @@ typedef struct ssl3_state_st
        int delay_buf_pop_ret;
 
        unsigned char read_sequence[8];
+       int read_mac_secret_size;
        unsigned char read_mac_secret[EVP_MAX_MD_SIZE];
        unsigned char write_sequence[8];
+       int write_mac_secret_size;
        unsigned char write_mac_secret[EVP_MAX_MD_SIZE];
 
        unsigned char server_random[SSL3_RANDOM_SIZE];
@@ -351,6 +420,9 @@ typedef struct ssl3_state_st
        int need_empty_fragments;
        int empty_fragment_done;
 
+       /* The value of 'extra' when the buffers were initialized */
+       int init_extra;
+
        SSL3_BUFFER rbuf;       /* read IO goes into here */
        SSL3_BUFFER wbuf;       /* write IO goes into here */
 
@@ -372,9 +444,11 @@ typedef struct ssl3_state_st
        const unsigned char *wpend_buf;
 
        /* used during startup, digest all incoming/outgoing packets */
-       EVP_MD_CTX finish_dgst1;
-       EVP_MD_CTX finish_dgst2;
-
+       BIO *handshake_buffer;
+       /* When set of handshake digests is determined, buffer is hashed
+        * and freed and MD_CTX-es for all required digests are stored in
+        * this array */
+       EVP_MD_CTX **handshake_dgst;
        /* this is set whenerver we see a change_cipher_spec message
         * come in when we are not looking for one */
        int change_cipher_spec;
@@ -394,8 +468,19 @@ typedef struct ssl3_state_st
 
        int in_read_app_data;
 
-       /* Set if we saw the Next Protocol Negotiation extension from our peer. */
+       /* Opaque PRF input as used for the current handshake.
+        * These fields are used only if TLSEXT_TYPE_opaque_prf_input is defined
+        * (otherwise, they are merely present to improve binary compatibility) */
+       void *client_opaque_prf_input;
+       size_t client_opaque_prf_input_len;
+       void *server_opaque_prf_input;
+       size_t server_opaque_prf_input_len;
+
+#ifndef OPENSSL_NO_NEXTPROTONEG
+       /* Set if we saw the Next Protocol Negotiation extension from
+          our peer. */
        int next_proto_neg_seen;
+#endif
 
        struct  {
                /* actually only needs to be 16+20 */
@@ -411,7 +496,7 @@ typedef struct ssl3_state_st
                int message_type;
 
                /* used to hold the new cipher we are going to use */
-               SSL_CIPHER *new_cipher;
+               const SSL_CIPHER *new_cipher;
 #ifndef OPENSSL_NO_DH
                DH *dh;
 #endif
@@ -438,6 +523,8 @@ typedef struct ssl3_state_st
 
                const EVP_CIPHER *new_sym_enc;
                const EVP_MD *new_hash;
+               int new_mac_pkey_type;
+               int new_mac_secret_size;
 #ifndef OPENSSL_NO_COMP
                const SSL_COMP *new_compression;
 #else
@@ -452,48 +539,6 @@ typedef struct ssl3_state_st
         unsigned char previous_server_finished[EVP_MAX_MD_SIZE];
         unsigned char previous_server_finished_len;
         int send_connection_binding; /* TODOEKR */
-
-       /* Snap Start support (server-side only):
-        *
-        * Snap Start allows the client to 'suggest' the value of our random
-        * nonce. Assuming that we accept this suggestion, then the client can
-        * predict our exact reply and calculate a complete handshake based on
-        * that. These opportunistic handshake messages are embedded in the
-        * Snap Start extension, possibly including application data.
-        *
-        * (Note that if the handshake doesn't resume a session, the client
-        * couldn't hope to predict the exact server reply unless it uses the
-        * session ticket extension to suppress session ID generation.)
-        *
-        * All this allows for a TLS handshake that doesn't incur additional
-        * latency if the client side sends application data first. */
-
-       /* Set if the client presented a Snap Start extension (empty or
-        * otherwise and the SSL_CTX has a cell configured. Server side only. */
-       int snap_start_ext_seen;
-       /* Set if the client-suggested a server random value (which is stored
-        * in |server_random|) */
-       char snap_start_requested;
-       /* Set if the appplication has indicated that the client's
-        * server_random suggestion is acceptable (see
-        * SSL_set_suggested_server_random_validity). If so, a Snap Start
-        * handshake will be attempted. */
-       char server_random_suggestion_valid;
-       /* Client's predicted response_hash from client snap start extension.
-        * Valid if |snap_start_requested| is set. */
-       unsigned char predicted_response_hash[8];
-       /* Actual server handshake message hash.  A Snap Start handshake is
-        * possible only if predicated_response_hash matches this. */
-       unsigned char response_hash[8];
-       /* If we need to enter snap start recovery then we need to reset the
-        * Finished hash with a different value for the ClientHello. Thus, we
-        * need a copy of the whole ClientHello: */
-       SSL3_BUFFER snap_start_client_hello;
-       /* A snap start ClientHello can contain records embedded in an
-        * extension. If we wish to read them then this points to the records
-        * within |snap_start_client_hello|. */
-       SSL3_BUFFER snap_start_records;
-
        } SSL3_STATE;
 
 
@@ -501,7 +546,7 @@ typedef struct ssl3_state_st
 /*client */
 /* extra state */
 #define SSL3_ST_CW_FLUSH               (0x100|SSL_ST_CONNECT)
-#define SSL3_ST_CUTTHROUGH_COMPLETE (0x101|SSL_ST_CONNECT)
+#define SSL3_ST_CUTTHROUGH_COMPLETE    (0x101|SSL_ST_CONNECT)
 /* write to server */
 #define SSL3_ST_CW_CLNT_HELLO_A                (0x110|SSL_ST_CONNECT)
 #define SSL3_ST_CW_CLNT_HELLO_B                (0x111|SSL_ST_CONNECT)
@@ -529,8 +574,10 @@ typedef struct ssl3_state_st
 #define SSL3_ST_CW_CERT_VRFY_B         (0x191|SSL_ST_CONNECT)
 #define SSL3_ST_CW_CHANGE_A            (0x1A0|SSL_ST_CONNECT)
 #define SSL3_ST_CW_CHANGE_B            (0x1A1|SSL_ST_CONNECT)
+#ifndef OPENSSL_NO_NEXTPROTONEG
 #define SSL3_ST_CW_NEXT_PROTO_A                (0x200|SSL_ST_CONNECT)
 #define SSL3_ST_CW_NEXT_PROTO_B                (0x201|SSL_ST_CONNECT)
+#endif
 #define SSL3_ST_CW_FINISHED_A          (0x1B0|SSL_ST_CONNECT)
 #define SSL3_ST_CW_FINISHED_B          (0x1B1|SSL_ST_CONNECT)
 /* read from server */
@@ -576,8 +623,10 @@ typedef struct ssl3_state_st
 #define SSL3_ST_SR_CERT_VRFY_B         (0x1A1|SSL_ST_ACCEPT)
 #define SSL3_ST_SR_CHANGE_A            (0x1B0|SSL_ST_ACCEPT)
 #define SSL3_ST_SR_CHANGE_B            (0x1B1|SSL_ST_ACCEPT)
+#ifndef OPENSSL_NO_NEXTPROTONEG
 #define SSL3_ST_SR_NEXT_PROTO_A                (0x210|SSL_ST_ACCEPT)
 #define SSL3_ST_SR_NEXT_PROTO_B                (0x211|SSL_ST_ACCEPT)
+#endif
 #define SSL3_ST_SR_FINISHED_A          (0x1C0|SSL_ST_ACCEPT)
 #define SSL3_ST_SR_FINISHED_B          (0x1C1|SSL_ST_ACCEPT)
 /* write to client */
@@ -602,7 +651,9 @@ typedef struct ssl3_state_st
 #define SSL3_MT_CLIENT_KEY_EXCHANGE            16
 #define SSL3_MT_FINISHED                       20
 #define SSL3_MT_CERTIFICATE_STATUS             22
+#ifndef OPENSSL_NO_NEXTPROTONEG
 #define SSL3_MT_NEXT_PROTO                     67
+#endif
 #define DTLS1_MT_HELLO_VERIFY_REQUEST    3
 
 
@@ -622,4 +673,3 @@ typedef struct ssl3_state_st
 }
 #endif
 #endif
-
index 6488cdf..0967b2d 100644 (file)
@@ -76,13 +76,16 @@ int SSL_library_init(void)
 #endif  
 #ifndef OPENSSL_NO_RC2
        EVP_add_cipher(EVP_rc2_cbc());
+       /* Not actually used for SSL/TLS but this makes PKCS#12 work
+        * if an application only calls SSL_library_init().
+        */
+       EVP_add_cipher(EVP_rc2_40_cbc());
 #endif
 #ifndef OPENSSL_NO_AES
        EVP_add_cipher(EVP_aes_128_cbc());
        EVP_add_cipher(EVP_aes_192_cbc());
        EVP_add_cipher(EVP_aes_256_cbc());
 #endif
-
 #ifndef OPENSSL_NO_CAMELLIA
        EVP_add_cipher(EVP_camellia_128_cbc());
        EVP_add_cipher(EVP_camellia_256_cbc());
@@ -91,7 +94,7 @@ int SSL_library_init(void)
 #ifndef OPENSSL_NO_SEED
        EVP_add_cipher(EVP_seed_cbc());
 #endif
-
+  
 #ifndef OPENSSL_NO_MD5
        EVP_add_digest(EVP_md5());
        EVP_add_digest_alias(SN_md5,"ssl2-md5");
index df8ec82..d7f4c60 100644 (file)
  * copied and put under another distribution licence
  * [including the GNU Public Licence.]
  */
+/* ====================================================================
+ * Copyright 2005 Nokia. All rights reserved.
+ *
+ * The portions of the attached software ("Contribution") is developed by
+ * Nokia Corporation and is licensed pursuant to the OpenSSL open source
+ * license.
+ *
+ * The Contribution, originally written by Mika Kousa and Pasi Eronen of
+ * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
+ * support (see RFC 4279) to OpenSSL.
+ *
+ * No patent licenses or other rights except those expressly stated in
+ * the OpenSSL open source license shall be deemed granted or received
+ * expressly, by implication, estoppel, or otherwise.
+ *
+ * No assurances are provided by Nokia that the Contribution does not
+ * infringe the patent or other intellectual property rights of any third
+ * party or that the license provides you with all the necessary rights
+ * to make use of the Contribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
+ * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
+ * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
+ * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
+ * OTHERWISE.
+ */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -84,12 +110,16 @@ typedef struct ssl_session_asn1_st
        ASN1_INTEGER tlsext_tick_lifetime;
        ASN1_OCTET_STRING tlsext_tick;
 #endif /* OPENSSL_NO_TLSEXT */
+#ifndef OPENSSL_NO_PSK
+       ASN1_OCTET_STRING psk_identity_hint;
+       ASN1_OCTET_STRING psk_identity;
+#endif /* OPENSSL_NO_PSK */
        } SSL_SESSION_ASN1;
 
 int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
        {
 #define LSIZE2 (sizeof(long)*2)
-       int v1=0,v2=0,v3=0,v4=0,v5=0;
+       int v1=0,v2=0,v3=0,v4=0,v5=0,v7=0,v8=0;
        unsigned char buf[4],ibuf1[LSIZE2],ibuf2[LSIZE2];
        unsigned char ibuf3[LSIZE2],ibuf4[LSIZE2],ibuf5[LSIZE2];
 #ifndef OPENSSL_NO_TLSEXT
@@ -97,8 +127,8 @@ int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
        unsigned char ibuf6[LSIZE2];
 #endif
 #ifndef OPENSSL_NO_COMP
-       int v11=0;
        unsigned char cbuf;
+       int v11=0;
 #endif
        long l;
        SSL_SESSION_ASN1 a;
@@ -177,7 +207,7 @@ int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
                a.krb5_princ.data=in->krb5_client_princ;
                }
 #endif /* OPENSSL_NO_KRB5 */
+
        if (in->time != 0L)
                {
                a.time.length=LSIZE2;
@@ -223,6 +253,21 @@ int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
                ASN1_INTEGER_set(&a.tlsext_tick_lifetime,in->tlsext_tick_lifetime_hint);
                }
 #endif /* OPENSSL_NO_TLSEXT */
+#ifndef OPENSSL_NO_PSK
+       if (in->psk_identity_hint)
+               {
+               a.psk_identity_hint.length=strlen(in->psk_identity_hint);
+               a.psk_identity_hint.type=V_ASN1_OCTET_STRING;
+               a.psk_identity_hint.data=(unsigned char *)(in->psk_identity_hint);
+               }
+       if (in->psk_identity)
+               {
+               a.psk_identity.length=strlen(in->psk_identity);
+               a.psk_identity.type=V_ASN1_OCTET_STRING;
+               a.psk_identity.data=(unsigned char *)(in->psk_identity);
+               }
+#endif /* OPENSSL_NO_PSK */
+
        M_ASN1_I2D_len(&(a.version),            i2d_ASN1_INTEGER);
        M_ASN1_I2D_len(&(a.ssl_version),        i2d_ASN1_INTEGER);
        M_ASN1_I2D_len(&(a.cipher),             i2d_ASN1_OCTET_STRING);
@@ -256,6 +301,13 @@ int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
                M_ASN1_I2D_len_EXP_opt(&(a.comp_id), i2d_ASN1_OCTET_STRING,11,v11);
 #endif
 #endif /* OPENSSL_NO_TLSEXT */
+#ifndef OPENSSL_NO_PSK
+       if (in->psk_identity_hint)
+               M_ASN1_I2D_len_EXP_opt(&(a.psk_identity_hint), i2d_ASN1_OCTET_STRING,7,v7);
+       if (in->psk_identity)
+               M_ASN1_I2D_len_EXP_opt(&(a.psk_identity), i2d_ASN1_OCTET_STRING,8,v8);
+#endif /* OPENSSL_NO_PSK */
+
        M_ASN1_I2D_seq_total();
 
        M_ASN1_I2D_put(&(a.version),            i2d_ASN1_INTEGER);
@@ -282,6 +334,14 @@ int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
 #ifndef OPENSSL_NO_TLSEXT
        if (in->tlsext_hostname)
                M_ASN1_I2D_put_EXP_opt(&(a.tlsext_hostname), i2d_ASN1_OCTET_STRING,6,v6);
+#endif /* OPENSSL_NO_TLSEXT */
+#ifndef OPENSSL_NO_PSK
+       if (in->psk_identity_hint)
+               M_ASN1_I2D_put_EXP_opt(&(a.psk_identity_hint), i2d_ASN1_OCTET_STRING,7,v7);
+       if (in->psk_identity)
+               M_ASN1_I2D_put_EXP_opt(&(a.psk_identity), i2d_ASN1_OCTET_STRING,8,v8);
+#endif /* OPENSSL_NO_PSK */
+#ifndef OPENSSL_NO_TLSEXT
        if (in->tlsext_tick_lifetime_hint > 0)
                M_ASN1_I2D_put_EXP_opt(&a.tlsext_tick_lifetime, i2d_ASN1_INTEGER,9,v9);
        if (in->tlsext_tick)
@@ -295,7 +355,7 @@ int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
        }
 
 SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp,
-            long length)
+                            long length)
        {
        int ssl_version=0,i;
        long id;
@@ -474,6 +534,24 @@ SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp,
                }
        else
                ret->tlsext_hostname=NULL;
+#endif /* OPENSSL_NO_TLSEXT */
+
+#ifndef OPENSSL_NO_PSK
+       os.length=0;
+       os.data=NULL;
+       M_ASN1_D2I_get_EXP_opt(osp,d2i_ASN1_OCTET_STRING,7);
+       if (os.data)
+               {
+               ret->psk_identity_hint = BUF_strndup((char *)os.data, os.length);
+               OPENSSL_free(os.data);
+               os.data = NULL;
+               os.length = 0;
+               }
+       else
+               ret->psk_identity_hint=NULL;
+#endif /* OPENSSL_NO_PSK */
+
+#ifndef OPENSSL_NO_TLSEXT
        ai.length=0;
        M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,9);
        if (ai.data != NULL)
@@ -484,17 +562,17 @@ SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp,
        else if (ret->tlsext_ticklen && ret->session_id_length)
                ret->tlsext_tick_lifetime_hint = -1;
        else
-               ret->tlsext_tick_lifetime_hint = 0;
-       os.length=0;
-       os.data=NULL;
-       M_ASN1_D2I_get_EXP_opt(osp,d2i_ASN1_OCTET_STRING,10);
-       if (os.data)
-               {
+               ret->tlsext_tick_lifetime_hint=0;
+       os.length=0;
+       os.data=NULL;
+       M_ASN1_D2I_get_EXP_opt(osp,d2i_ASN1_OCTET_STRING,10);
+       if (os.data)
+               {
                ret->tlsext_tick = os.data;
                ret->tlsext_ticklen = os.length;
-               os.data = NULL;
-               os.length = 0;
-               }
+               os.data = NULL;
+               os.length = 0;
+               }
        else
                ret->tlsext_tick=NULL;
 #endif /* OPENSSL_NO_TLSEXT */
index 361cd9c..27256ee 100644 (file)
@@ -56,7 +56,7 @@
  * [including the GNU Public Licence.]
  */
 /* ====================================================================
- * Copyright (c) 1998-2006 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2007 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -197,8 +197,10 @@ CERT *ssl_cert_dup(CERT *cert)
         * if you find that more readable */
 
        ret->valid = cert->valid;
-       ret->mask = cert->mask;
-       ret->export_mask = cert->export_mask;
+       ret->mask_k = cert->mask_k;
+       ret->mask_a = cert->mask_a;
+       ret->export_mask_k = cert->export_mask_k;
+       ret->export_mask_a = cert->export_mask_a;
 
 #ifndef OPENSSL_NO_RSA
        if (cert->rsa_tmp != NULL)
index a34680e..462c45a 100644 (file)
@@ -56,7 +56,7 @@
  * [including the GNU Public Licence.]
  */
 /* ====================================================================
- * Copyright (c) 1998-2006 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2007 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * ECC cipher suite support in OpenSSL originally developed by 
  * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
  */
+/* ====================================================================
+ * Copyright 2005 Nokia. All rights reserved.
+ *
+ * The portions of the attached software ("Contribution") is developed by
+ * Nokia Corporation and is licensed pursuant to the OpenSSL open source
+ * license.
+ *
+ * The Contribution, originally written by Mika Kousa and Pasi Eronen of
+ * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
+ * support (see RFC 4279) to OpenSSL.
+ *
+ * No patent licenses or other rights except those expressly stated in
+ * the OpenSSL open source license shall be deemed granted or received
+ * expressly, by implication, estoppel, or otherwise.
+ *
+ * No assurances are provided by Nokia that the Contribution does not
+ * infringe the patent or other intellectual property rights of any third
+ * party or that the license provides you with all the necessary rights
+ * to make use of the Contribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
+ * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
+ * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
+ * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
+ * OTHERWISE.
+ */
+
 #include <stdio.h>
 #include <openssl/objects.h>
 #ifndef OPENSSL_NO_COMP
 #include <openssl/comp.h>
 #endif
-
+#ifndef OPENSSL_NO_ENGINE
+#include <openssl/engine.h>
+#endif
 #include "ssl_locl.h"
 
 #define SSL_ENC_DES_IDX                0
 #define SSL_ENC_RC4_IDX                2
 #define SSL_ENC_RC2_IDX                3
 #define SSL_ENC_IDEA_IDX       4
-#define SSL_ENC_eFZA_IDX       5
-#define SSL_ENC_NULL_IDX       6
-#define SSL_ENC_AES128_IDX     7
-#define SSL_ENC_AES256_IDX     8
-#define SSL_ENC_CAMELLIA128_IDX        9
-#define SSL_ENC_CAMELLIA256_IDX        10
+#define SSL_ENC_NULL_IDX       5
+#define SSL_ENC_AES128_IDX     6
+#define SSL_ENC_AES256_IDX     7
+#define SSL_ENC_CAMELLIA128_IDX        8
+#define SSL_ENC_CAMELLIA256_IDX        9
+#define SSL_ENC_GOST89_IDX     10
 #define SSL_ENC_SEED_IDX       11
 #define SSL_ENC_NUM_IDX                12
 
 
 static const EVP_CIPHER *ssl_cipher_methods[SSL_ENC_NUM_IDX]={
-       NULL,NULL,NULL,NULL,NULL,NULL,
+       NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
        };
 
 #define SSL_COMP_NULL_IDX      0
@@ -148,9 +177,30 @@ static STACK_OF(SSL_COMP) *ssl_comp_methods=NULL;
 
 #define SSL_MD_MD5_IDX 0
 #define SSL_MD_SHA1_IDX        1
-#define SSL_MD_NUM_IDX 2
+#define SSL_MD_GOST94_IDX 2
+#define SSL_MD_GOST89MAC_IDX 3
+/*Constant SSL_MAX_DIGEST equal to size of digests array should be 
+ * defined in the
+ * ssl_locl.h */
+#define SSL_MD_NUM_IDX SSL_MAX_DIGEST 
 static const EVP_MD *ssl_digest_methods[SSL_MD_NUM_IDX]={
-       NULL,NULL,
+       NULL,NULL,NULL,NULL
+       };
+/* PKEY_TYPE for GOST89MAC is known in advance, but, because
+ * implementation is engine-provided, we'll fill it only if
+ * corresponding EVP_PKEY_METHOD is found 
+ */
+static int  ssl_mac_pkey_id[SSL_MD_NUM_IDX]={
+       EVP_PKEY_HMAC,EVP_PKEY_HMAC,EVP_PKEY_HMAC,NID_undef
+       };
+
+static int ssl_mac_secret_size[SSL_MD_NUM_IDX]={
+       0,0,0,0
+       };
+
+static int ssl_handshake_digest_flag[SSL_MD_NUM_IDX]={
+       SSL_HANDSHAKE_MAC_MD5,SSL_HANDSHAKE_MAC_SHA,
+       SSL_HANDSHAKE_MAC_GOST94,0
        };
 
 #define CIPHER_ADD     1
@@ -161,72 +211,144 @@ static const EVP_MD *ssl_digest_methods[SSL_MD_NUM_IDX]={
 
 typedef struct cipher_order_st
        {
-       SSL_CIPHER *cipher;
+       const SSL_CIPHER *cipher;
        int active;
        int dead;
        struct cipher_order_st *next,*prev;
        } CIPHER_ORDER;
 
 static const SSL_CIPHER cipher_aliases[]={
-       /* Don't include eNULL unless specifically enabled. */
-       /* Don't include ECC in ALL because these ciphers are not yet official. */
-       {0,SSL_TXT_ALL, 0,SSL_ALL & ~SSL_eNULL & ~SSL_kECDH & ~SSL_kECDHE, SSL_ALL ,0,0,0,SSL_ALL,SSL_ALL}, /* must be first */
-       /* TODO: COMPLEMENT OF ALL and COMPLEMENT OF DEFAULT do not have ECC cipher suites handled properly. */
-       {0,SSL_TXT_CMPALL,0,SSL_eNULL,0,0,0,0,SSL_ENC_MASK,0},  /* COMPLEMENT OF ALL */
-       {0,SSL_TXT_CMPDEF,0,SSL_ADH, 0,0,0,0,SSL_AUTH_MASK,0},
-       {0,SSL_TXT_kKRB5,0,SSL_kKRB5,0,0,0,0,SSL_MKEY_MASK,0},  /* VRS Kerberos5 */
-       {0,SSL_TXT_kRSA,0,SSL_kRSA,  0,0,0,0,SSL_MKEY_MASK,0},
-       {0,SSL_TXT_kDHr,0,SSL_kDHr,  0,0,0,0,SSL_MKEY_MASK,0},
-       {0,SSL_TXT_kDHd,0,SSL_kDHd,  0,0,0,0,SSL_MKEY_MASK,0},
-       {0,SSL_TXT_kEDH,0,SSL_kEDH,  0,0,0,0,SSL_MKEY_MASK,0},
-       {0,SSL_TXT_kFZA,0,SSL_kFZA,  0,0,0,0,SSL_MKEY_MASK,0},
-       {0,SSL_TXT_DH,  0,SSL_DH,    0,0,0,0,SSL_MKEY_MASK,0},
-       {0,SSL_TXT_ECC, 0,(SSL_kECDH|SSL_kECDHE), 0,0,0,0,SSL_MKEY_MASK,0},
-       {0,SSL_TXT_EDH, 0,SSL_EDH,   0,0,0,0,SSL_MKEY_MASK|SSL_AUTH_MASK,0},
-       {0,SSL_TXT_aKRB5,0,SSL_aKRB5,0,0,0,0,SSL_AUTH_MASK,0},  /* VRS Kerberos5 */
-       {0,SSL_TXT_aRSA,0,SSL_aRSA,  0,0,0,0,SSL_AUTH_MASK,0},
-       {0,SSL_TXT_aDSS,0,SSL_aDSS,  0,0,0,0,SSL_AUTH_MASK,0},
-       {0,SSL_TXT_aFZA,0,SSL_aFZA,  0,0,0,0,SSL_AUTH_MASK,0},
-       {0,SSL_TXT_aNULL,0,SSL_aNULL,0,0,0,0,SSL_AUTH_MASK,0},
-       {0,SSL_TXT_aDH, 0,SSL_aDH,   0,0,0,0,SSL_AUTH_MASK,0},
-       {0,SSL_TXT_DSS, 0,SSL_DSS,   0,0,0,0,SSL_AUTH_MASK,0},
-
-       {0,SSL_TXT_DES, 0,SSL_DES,   0,0,0,0,SSL_ENC_MASK,0},
-       {0,SSL_TXT_3DES,0,SSL_3DES,  0,0,0,0,SSL_ENC_MASK,0},
-       {0,SSL_TXT_RC4, 0,SSL_RC4,   0,0,0,0,SSL_ENC_MASK,0},
-       {0,SSL_TXT_RC2, 0,SSL_RC2,   0,0,0,0,SSL_ENC_MASK,0},
-#ifndef OPENSSL_NO_IDEA
-       {0,SSL_TXT_IDEA,0,SSL_IDEA,  0,0,0,0,SSL_ENC_MASK,0},
-#endif
-       {0,SSL_TXT_SEED,0,SSL_SEED,  0,0,0,0,SSL_ENC_MASK,0},
-       {0,SSL_TXT_eNULL,0,SSL_eNULL,0,0,0,0,SSL_ENC_MASK,0},
-       {0,SSL_TXT_eFZA,0,SSL_eFZA,  0,0,0,0,SSL_ENC_MASK,0},
-       {0,SSL_TXT_AES, 0,SSL_AES,   0,0,0,0,SSL_ENC_MASK,0},
-       {0,SSL_TXT_CAMELLIA,0,SSL_CAMELLIA, 0,0,0,0,SSL_ENC_MASK,0},
-
-       {0,SSL_TXT_MD5, 0,SSL_MD5,   0,0,0,0,SSL_MAC_MASK,0},
-       {0,SSL_TXT_SHA1,0,SSL_SHA1,  0,0,0,0,SSL_MAC_MASK,0},
-       {0,SSL_TXT_SHA, 0,SSL_SHA,   0,0,0,0,SSL_MAC_MASK,0},
-
-       {0,SSL_TXT_NULL,0,SSL_NULL,  0,0,0,0,SSL_ENC_MASK,0},
-       {0,SSL_TXT_KRB5,0,SSL_KRB5,  0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK,0},
-       {0,SSL_TXT_RSA, 0,SSL_RSA,   0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK,0},
-       {0,SSL_TXT_ADH, 0,SSL_ADH,   0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK,0},
-       {0,SSL_TXT_FZA, 0,SSL_FZA,   0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK|SSL_ENC_MASK,0},
-
-       {0,SSL_TXT_SSLV2, 0,SSL_SSLV2, 0,0,0,0,SSL_SSL_MASK,0},
-       {0,SSL_TXT_SSLV3, 0,SSL_SSLV3, 0,0,0,0,SSL_SSL_MASK,0},
-       {0,SSL_TXT_TLSV1, 0,SSL_TLSV1, 0,0,0,0,SSL_SSL_MASK,0},
-
-       {0,SSL_TXT_EXP   ,0, 0,SSL_EXPORT, 0,0,0,0,SSL_EXP_MASK},
-       {0,SSL_TXT_EXPORT,0, 0,SSL_EXPORT, 0,0,0,0,SSL_EXP_MASK},
-       {0,SSL_TXT_EXP40, 0, 0, SSL_EXP40, 0,0,0,0,SSL_STRONG_MASK},
-       {0,SSL_TXT_EXP56, 0, 0, SSL_EXP56, 0,0,0,0,SSL_STRONG_MASK},
-       {0,SSL_TXT_LOW,   0, 0,   SSL_LOW, 0,0,0,0,SSL_STRONG_MASK},
-       {0,SSL_TXT_MEDIUM,0, 0,SSL_MEDIUM, 0,0,0,0,SSL_STRONG_MASK},
-       {0,SSL_TXT_HIGH,  0, 0,  SSL_HIGH, 0,0,0,0,SSL_STRONG_MASK},
-       {0,SSL_TXT_FIPS,  0, 0,  SSL_FIPS, 0,0,0,0,SSL_FIPS|SSL_STRONG_NONE},
+       /* "ALL" doesn't include eNULL (must be specifically enabled) */
+       {0,SSL_TXT_ALL,0,     0,0,~SSL_eNULL,0,0,0,0,0,0},
+       /* "COMPLEMENTOFALL" */
+       {0,SSL_TXT_CMPALL,0,  0,0,SSL_eNULL,0,0,0,0,0,0},
+
+       /* "COMPLEMENTOFDEFAULT" (does *not* include ciphersuites not found in ALL!) */
+       {0,SSL_TXT_CMPDEF,0,  SSL_kEDH|SSL_kEECDH,SSL_aNULL,~SSL_eNULL,0,0,0,0,0,0},
+
+       /* key exchange aliases
+        * (some of those using only a single bit here combine
+        * multiple key exchange algs according to the RFCs,
+        * e.g. kEDH combines DHE_DSS and DHE_RSA) */
+       {0,SSL_TXT_kRSA,0,    SSL_kRSA,  0,0,0,0,0,0,0,0},
+
+       {0,SSL_TXT_kDHr,0,    SSL_kDHr,  0,0,0,0,0,0,0,0}, /* no such ciphersuites supported! */
+       {0,SSL_TXT_kDHd,0,    SSL_kDHd,  0,0,0,0,0,0,0,0}, /* no such ciphersuites supported! */
+       {0,SSL_TXT_kDH,0,     SSL_kDHr|SSL_kDHd,0,0,0,0,0,0,0,0}, /* no such ciphersuites supported! */
+       {0,SSL_TXT_kEDH,0,    SSL_kEDH,  0,0,0,0,0,0,0,0},
+       {0,SSL_TXT_DH,0,      SSL_kDHr|SSL_kDHd|SSL_kEDH,0,0,0,0,0,0,0,0},
+
+       {0,SSL_TXT_kKRB5,0,   SSL_kKRB5, 0,0,0,0,0,0,0,0},
+
+       {0,SSL_TXT_kECDHr,0,  SSL_kECDHr,0,0,0,0,0,0,0,0},
+       {0,SSL_TXT_kECDHe,0,  SSL_kECDHe,0,0,0,0,0,0,0,0},
+       {0,SSL_TXT_kECDH,0,   SSL_kECDHr|SSL_kECDHe,0,0,0,0,0,0,0,0},
+       {0,SSL_TXT_kEECDH,0,  SSL_kEECDH,0,0,0,0,0,0,0,0},
+       {0,SSL_TXT_ECDH,0,    SSL_kECDHr|SSL_kECDHe|SSL_kEECDH,0,0,0,0,0,0,0,0},
+
+        {0,SSL_TXT_kPSK,0,    SSL_kPSK,  0,0,0,0,0,0,0,0},
+       {0,SSL_TXT_kGOST,0, SSL_kGOST,0,0,0,0,0,0,0,0},
+
+       /* server authentication aliases */
+       {0,SSL_TXT_aRSA,0,    0,SSL_aRSA,  0,0,0,0,0,0,0},
+       {0,SSL_TXT_aDSS,0,    0,SSL_aDSS,  0,0,0,0,0,0,0},
+       {0,SSL_TXT_DSS,0,     0,SSL_aDSS,   0,0,0,0,0,0,0},
+       {0,SSL_TXT_aKRB5,0,   0,SSL_aKRB5, 0,0,0,0,0,0,0},
+       {0,SSL_TXT_aNULL,0,   0,SSL_aNULL, 0,0,0,0,0,0,0},
+       {0,SSL_TXT_aDH,0,     0,SSL_aDH,   0,0,0,0,0,0,0}, /* no such ciphersuites supported! */
+       {0,SSL_TXT_aECDH,0,   0,SSL_aECDH, 0,0,0,0,0,0,0},
+       {0,SSL_TXT_aECDSA,0,  0,SSL_aECDSA,0,0,0,0,0,0,0},
+       {0,SSL_TXT_ECDSA,0,   0,SSL_aECDSA, 0,0,0,0,0,0,0},
+        {0,SSL_TXT_aPSK,0,    0,SSL_aPSK,  0,0,0,0,0,0,0},
+       {0,SSL_TXT_aGOST94,0,0,SSL_aGOST94,0,0,0,0,0,0,0},
+       {0,SSL_TXT_aGOST01,0,0,SSL_aGOST01,0,0,0,0,0,0,0},
+       {0,SSL_TXT_aGOST,0,0,SSL_aGOST94|SSL_aGOST01,0,0,0,0,0,0,0},
+
+       /* aliases combining key exchange and server authentication */
+       {0,SSL_TXT_EDH,0,     SSL_kEDH,~SSL_aNULL,0,0,0,0,0,0,0},
+       {0,SSL_TXT_EECDH,0,   SSL_kEECDH,~SSL_aNULL,0,0,0,0,0,0,0},
+       {0,SSL_TXT_NULL,0,    0,0,SSL_eNULL, 0,0,0,0,0,0},
+       {0,SSL_TXT_KRB5,0,    SSL_kKRB5,SSL_aKRB5,0,0,0,0,0,0,0},
+       {0,SSL_TXT_RSA,0,     SSL_kRSA,SSL_aRSA,0,0,0,0,0,0,0},
+       {0,SSL_TXT_ADH,0,     SSL_kEDH,SSL_aNULL,0,0,0,0,0,0,0},
+       {0,SSL_TXT_AECDH,0,   SSL_kEECDH,SSL_aNULL,0,0,0,0,0,0,0},
+        {0,SSL_TXT_PSK,0,     SSL_kPSK,SSL_aPSK,0,0,0,0,0,0,0},
+
+
+       /* symmetric encryption aliases */
+       {0,SSL_TXT_DES,0,     0,0,SSL_DES,   0,0,0,0,0,0},
+       {0,SSL_TXT_3DES,0,    0,0,SSL_3DES,  0,0,0,0,0,0},
+       {0,SSL_TXT_RC4,0,     0,0,SSL_RC4,   0,0,0,0,0,0},
+       {0,SSL_TXT_RC2,0,     0,0,SSL_RC2,   0,0,0,0,0,0},
+       {0,SSL_TXT_IDEA,0,    0,0,SSL_IDEA,  0,0,0,0,0,0},
+       {0,SSL_TXT_SEED,0,    0,0,SSL_SEED,  0,0,0,0,0,0},
+       {0,SSL_TXT_eNULL,0,   0,0,SSL_eNULL, 0,0,0,0,0,0},
+       {0,SSL_TXT_AES128,0,  0,0,SSL_AES128,0,0,0,0,0,0},
+       {0,SSL_TXT_AES256,0,  0,0,SSL_AES256,0,0,0,0,0,0},
+       {0,SSL_TXT_AES,0,     0,0,SSL_AES128|SSL_AES256,0,0,0,0,0,0},
+       {0,SSL_TXT_CAMELLIA128,0,0,0,SSL_CAMELLIA128,0,0,0,0,0,0},
+       {0,SSL_TXT_CAMELLIA256,0,0,0,SSL_CAMELLIA256,0,0,0,0,0,0},
+       {0,SSL_TXT_CAMELLIA   ,0,0,0,SSL_CAMELLIA128|SSL_CAMELLIA256,0,0,0,0,0,0},
+
+       /* MAC aliases */       
+       {0,SSL_TXT_MD5,0,     0,0,0,SSL_MD5,   0,0,0,0,0},
+       {0,SSL_TXT_SHA1,0,    0,0,0,SSL_SHA1,  0,0,0,0,0},
+       {0,SSL_TXT_SHA,0,     0,0,0,SSL_SHA1,  0,0,0,0,0},
+       {0,SSL_TXT_GOST94,0,     0,0,0,SSL_GOST94,  0,0,0,0,0},
+       {0,SSL_TXT_GOST89MAC,0,     0,0,0,SSL_GOST89MAC,  0,0,0,0,0},
+
+       /* protocol version aliases */
+       {0,SSL_TXT_SSLV2,0,   0,0,0,0,SSL_SSLV2, 0,0,0,0},
+       {0,SSL_TXT_SSLV3,0,   0,0,0,0,SSL_SSLV3, 0,0,0,0},
+       {0,SSL_TXT_TLSV1,0,   0,0,0,0,SSL_TLSV1, 0,0,0,0},
+
+       /* export flag */
+       {0,SSL_TXT_EXP,0,     0,0,0,0,0,SSL_EXPORT,0,0,0},
+       {0,SSL_TXT_EXPORT,0,  0,0,0,0,0,SSL_EXPORT,0,0,0},
+
+       /* strength classes */
+       {0,SSL_TXT_EXP40,0,   0,0,0,0,0,SSL_EXP40, 0,0,0},
+       {0,SSL_TXT_EXP56,0,   0,0,0,0,0,SSL_EXP56, 0,0,0},
+       {0,SSL_TXT_LOW,0,     0,0,0,0,0,SSL_LOW,   0,0,0},
+       {0,SSL_TXT_MEDIUM,0,  0,0,0,0,0,SSL_MEDIUM,0,0,0},
+       {0,SSL_TXT_HIGH,0,    0,0,0,0,0,SSL_HIGH,  0,0,0},
+       /* FIPS 140-2 approved ciphersuite */
+       {0,SSL_TXT_FIPS,0,    0,0,~SSL_eNULL,0,0,SSL_FIPS,  0,0,0},
        };
+/* Search for public key algorithm with given name and 
+ * return its pkey_id if it is available. Otherwise return 0
+ */
+#ifdef OPENSSL_NO_ENGINE
+
+static int get_optional_pkey_id(const char *pkey_name)
+       {
+       const EVP_PKEY_ASN1_METHOD *ameth;
+       int pkey_id=0;
+       ameth = EVP_PKEY_asn1_find_str(NULL,pkey_name,-1);
+       if (ameth) 
+               {
+               EVP_PKEY_asn1_get0_info(&pkey_id, NULL,NULL,NULL,NULL,ameth);
+               }               
+       return pkey_id;
+       }
+
+#else
+
+static int get_optional_pkey_id(const char *pkey_name)
+       {
+       const EVP_PKEY_ASN1_METHOD *ameth;
+       ENGINE *tmpeng = NULL;
+       int pkey_id=0;
+       ameth = EVP_PKEY_asn1_find_str(&tmpeng,pkey_name,-1);
+       if (ameth)
+               {
+               EVP_PKEY_asn1_get0_info(&pkey_id, NULL,NULL,NULL,NULL,ameth);
+               }
+       if (tmpeng) ENGINE_finish(tmpeng);
+       return pkey_id;
+       }
+
+#endif
 
 void ssl_load_ciphers(void)
        {
@@ -252,16 +374,37 @@ void ssl_load_ciphers(void)
          EVP_get_cipherbyname(SN_camellia_128_cbc);
        ssl_cipher_methods[SSL_ENC_CAMELLIA256_IDX]=
          EVP_get_cipherbyname(SN_camellia_256_cbc);
+       ssl_cipher_methods[SSL_ENC_GOST89_IDX]=
+         EVP_get_cipherbyname(SN_gost89_cnt);
        ssl_cipher_methods[SSL_ENC_SEED_IDX]=
          EVP_get_cipherbyname(SN_seed_cbc);
 
        ssl_digest_methods[SSL_MD_MD5_IDX]=
                EVP_get_digestbyname(SN_md5);
+       ssl_mac_secret_size[SSL_MD_MD5_IDX]=
+               EVP_MD_size(ssl_digest_methods[SSL_MD_MD5_IDX]);
+       OPENSSL_assert(ssl_mac_secret_size[SSL_MD_MD5_IDX] >= 0);
        ssl_digest_methods[SSL_MD_SHA1_IDX]=
                EVP_get_digestbyname(SN_sha1);
-       }
-
+       ssl_mac_secret_size[SSL_MD_SHA1_IDX]=
+               EVP_MD_size(ssl_digest_methods[SSL_MD_SHA1_IDX]);
+       OPENSSL_assert(ssl_mac_secret_size[SSL_MD_SHA1_IDX] >= 0);
+       ssl_digest_methods[SSL_MD_GOST94_IDX]=
+               EVP_get_digestbyname(SN_id_GostR3411_94);
+       if (ssl_digest_methods[SSL_MD_GOST94_IDX])
+               {       
+               ssl_mac_secret_size[SSL_MD_GOST94_IDX]=
+                       EVP_MD_size(ssl_digest_methods[SSL_MD_GOST94_IDX]);
+               OPENSSL_assert(ssl_mac_secret_size[SSL_MD_GOST94_IDX] >= 0);
+               }
+       ssl_digest_methods[SSL_MD_GOST89MAC_IDX]=
+               EVP_get_digestbyname(SN_id_Gost28147_89_MAC);
+               ssl_mac_pkey_id[SSL_MD_GOST89MAC_IDX] = get_optional_pkey_id("gost-mac");
+               if (ssl_mac_pkey_id[SSL_MD_GOST89MAC_IDX]) {
+                       ssl_mac_secret_size[SSL_MD_GOST89MAC_IDX]=32;
+               }               
 
+       }
 #ifndef OPENSSL_NO_COMP
 
 static int sk_comp_cmp(const SSL_COMP * const *a,
@@ -303,6 +446,7 @@ static void load_builtin_compressions(void)
                                                sk_SSL_COMP_push(ssl_comp_methods,comp);
                                                }
                                        }
+                                       sk_SSL_COMP_sort(ssl_comp_methods);
                                }
                        MemCheck_on();
                        }
@@ -316,10 +460,10 @@ static void load_builtin_compressions(void)
 #endif
 
 int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc,
-            const EVP_MD **md, SSL_COMP **comp)
+            const EVP_MD **md, int *mac_pkey_type, int *mac_secret_size,SSL_COMP **comp)
        {
        int i;
-       SSL_CIPHER *c;
+       const SSL_CIPHER *c;
 
        c=s->cipher;
        if (c == NULL) return(0);
@@ -344,7 +488,7 @@ int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc,
 
        if ((enc == NULL) || (md == NULL)) return(0);
 
-       switch (c->algorithms & SSL_ENC_MASK)
+       switch (c->algorithm_enc)
                {
        case SSL_DES:
                i=SSL_ENC_DES_IDX;
@@ -364,26 +508,24 @@ int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc,
        case SSL_eNULL:
                i=SSL_ENC_NULL_IDX;
                break;
-       case SSL_AES:
-               switch(c->alg_bits)
-                       {
-               case 128: i=SSL_ENC_AES128_IDX; break;
-               case 256: i=SSL_ENC_AES256_IDX; break;
-               default: i=-1; break;
-                       }
+       case SSL_AES128:
+               i=SSL_ENC_AES128_IDX;
                break;
-       case SSL_CAMELLIA:
-               switch(c->alg_bits)
-                       {
-               case 128: i=SSL_ENC_CAMELLIA128_IDX; break;
-               case 256: i=SSL_ENC_CAMELLIA256_IDX; break;
-               default: i=-1; break;
-                       }
+       case SSL_AES256:
+               i=SSL_ENC_AES256_IDX;
+               break;
+       case SSL_CAMELLIA128:
+               i=SSL_ENC_CAMELLIA128_IDX;
+               break;
+       case SSL_CAMELLIA256:
+               i=SSL_ENC_CAMELLIA256_IDX;
+               break;
+       case SSL_eGOST2814789CNT:
+               i=SSL_ENC_GOST89_IDX;
                break;
        case SSL_SEED:
                i=SSL_ENC_SEED_IDX;
                break;
-
        default:
                i= -1;
                break;
@@ -399,7 +541,7 @@ int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc,
                        *enc=ssl_cipher_methods[i];
                }
 
-       switch (c->algorithms & SSL_MAC_MASK)
+       switch (c->algorithm_mac)
                {
        case SSL_MD5:
                i=SSL_MD_MD5_IDX;
@@ -407,21 +549,48 @@ int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc,
        case SSL_SHA1:
                i=SSL_MD_SHA1_IDX;
                break;
+       case SSL_GOST94:
+               i = SSL_MD_GOST94_IDX;
+               break;
+       case SSL_GOST89MAC:
+               i = SSL_MD_GOST89MAC_IDX;
+               break;
        default:
                i= -1;
                break;
                }
        if ((i < 0) || (i > SSL_MD_NUM_IDX))
-               *md=NULL;
+       {
+               *md=NULL; 
+               if (mac_pkey_type!=NULL) *mac_pkey_type = NID_undef;
+               if (mac_secret_size!=NULL) *mac_secret_size = 0;
+
+       }
        else
+       {
                *md=ssl_digest_methods[i];
+               if (mac_pkey_type!=NULL) *mac_pkey_type = ssl_mac_pkey_id[i];
+               if (mac_secret_size!=NULL) *mac_secret_size = ssl_mac_secret_size[i];
+       }       
 
-       if ((*enc != NULL) && (*md != NULL))
+       if ((*enc != NULL) && (*md != NULL) && (!mac_pkey_type||*mac_pkey_type != NID_undef))
                return(1);
        else
                return(0);
        }
 
+int ssl_get_handshake_digest(int idx, long *mask, const EVP_MD **md) 
+{
+       if (idx <0||idx>=SSL_MD_NUM_IDX) 
+               {
+               return 0;
+               }
+       if (ssl_handshake_digest_flag[idx]==0) return 0;
+       *mask = ssl_handshake_digest_flag[idx];
+       *md = ssl_digest_methods[idx];
+       return 1;
+}
+
 #define ITEM_SEP(a) \
        (((a) == ':') || ((a) == ' ') || ((a) == ';') || ((a) == ','))
 
@@ -433,7 +602,7 @@ static void ll_append_tail(CIPHER_ORDER **head, CIPHER_ORDER *curr,
                *head=curr->next;
        if (curr->prev != NULL)
                curr->prev->next=curr->next;
-       if (curr->next != NULL) /* should always be true */
+       if (curr->next != NULL)
                curr->next->prev=curr->prev;
        (*tail)->next=curr;
        curr->prev= *tail;
@@ -441,69 +610,105 @@ static void ll_append_tail(CIPHER_ORDER **head, CIPHER_ORDER *curr,
        *tail=curr;
        }
 
-struct disabled_masks { /* This is a kludge no longer needed with OpenSSL 0.9.9,
-                         * where 128-bit and 256-bit algorithms simply will get
-                         * separate bits. */
-  unsigned long mask; /* everything except m256 */
-  unsigned long m256; /* applies to 256-bit algorithms only */
-};
+static void ll_append_head(CIPHER_ORDER **head, CIPHER_ORDER *curr,
+            CIPHER_ORDER **tail)
+       {
+       if (curr == *head) return;
+       if (curr == *tail)
+               *tail=curr->prev;
+       if (curr->next != NULL)
+               curr->next->prev=curr->prev;
+       if (curr->prev != NULL)
+               curr->prev->next=curr->next;
+       (*head)->prev=curr;
+       curr->next= *head;
+       curr->prev=NULL;
+       *head=curr;
+       }
 
-static struct disabled_masks ssl_cipher_get_disabled(void)
+static void ssl_cipher_get_disabled(unsigned long *mkey, unsigned long *auth, unsigned long *enc, unsigned long *mac, unsigned long *ssl)
        {
-       unsigned long mask;
-       unsigned long m256;
-       struct disabled_masks ret;
+       *mkey = 0;
+       *auth = 0;
+       *enc = 0;
+       *mac = 0;
+       *ssl = 0;
 
-       mask = SSL_kFZA;
 #ifdef OPENSSL_NO_RSA
-       mask |= SSL_aRSA|SSL_kRSA;
+       *mkey |= SSL_kRSA;
+       *auth |= SSL_aRSA;
 #endif
 #ifdef OPENSSL_NO_DSA
-       mask |= SSL_aDSS;
+       *auth |= SSL_aDSS;
 #endif
+       *mkey |= SSL_kDHr|SSL_kDHd; /* no such ciphersuites supported! */
+       *auth |= SSL_aDH;
 #ifdef OPENSSL_NO_DH
-       mask |= SSL_kDHr|SSL_kDHd|SSL_kEDH|SSL_aDH;
+       *mkey |= SSL_kDHr|SSL_kDHd|SSL_kEDH;
+       *auth |= SSL_aDH;
 #endif
 #ifdef OPENSSL_NO_KRB5
-       mask |= SSL_kKRB5|SSL_aKRB5;
+       *mkey |= SSL_kKRB5;
+       *auth |= SSL_aKRB5;
+#endif
+#ifdef OPENSSL_NO_ECDSA
+       *auth |= SSL_aECDSA;
 #endif
 #ifdef OPENSSL_NO_ECDH
-       mask |= SSL_kECDH|SSL_kECDHE;
+       *mkey |= SSL_kECDHe|SSL_kECDHr;
+       *auth |= SSL_aECDH;
+#endif
+#ifdef OPENSSL_NO_PSK
+       *mkey |= SSL_kPSK;
+       *auth |= SSL_aPSK;
 #endif
+       /* Check for presence of GOST 34.10 algorithms, and if they
+        * do not present, disable  appropriate auth and key exchange */
+       if (!get_optional_pkey_id("gost94")) {
+               *auth |= SSL_aGOST94;
+       }
+       if (!get_optional_pkey_id("gost2001")) {
+               *auth |= SSL_aGOST01;
+       }
+       /* Disable GOST key exchange if no GOST signature algs are available * */
+       if ((*auth & (SSL_aGOST94|SSL_aGOST01)) == (SSL_aGOST94|SSL_aGOST01)) {
+               *mkey |= SSL_kGOST;
+       }       
 #ifdef SSL_FORBID_ENULL
-       mask |= SSL_eNULL;
+       *enc |= SSL_eNULL;
 #endif
+               
+
+
+       *enc |= (ssl_cipher_methods[SSL_ENC_DES_IDX ] == NULL) ? SSL_DES :0;
+       *enc |= (ssl_cipher_methods[SSL_ENC_3DES_IDX] == NULL) ? SSL_3DES:0;
+       *enc |= (ssl_cipher_methods[SSL_ENC_RC4_IDX ] == NULL) ? SSL_RC4 :0;
+       *enc |= (ssl_cipher_methods[SSL_ENC_RC2_IDX ] == NULL) ? SSL_RC2 :0;
+       *enc |= (ssl_cipher_methods[SSL_ENC_IDEA_IDX] == NULL) ? SSL_IDEA:0;
+       *enc |= (ssl_cipher_methods[SSL_ENC_AES128_IDX] == NULL) ? SSL_AES128:0;
+       *enc |= (ssl_cipher_methods[SSL_ENC_AES256_IDX] == NULL) ? SSL_AES256:0;
+       *enc |= (ssl_cipher_methods[SSL_ENC_CAMELLIA128_IDX] == NULL) ? SSL_CAMELLIA128:0;
+       *enc |= (ssl_cipher_methods[SSL_ENC_CAMELLIA256_IDX] == NULL) ? SSL_CAMELLIA256:0;
+       *enc |= (ssl_cipher_methods[SSL_ENC_GOST89_IDX] == NULL) ? SSL_eGOST2814789CNT:0;
+       *enc |= (ssl_cipher_methods[SSL_ENC_SEED_IDX] == NULL) ? SSL_SEED:0;
+
+       *mac |= (ssl_digest_methods[SSL_MD_MD5_IDX ] == NULL) ? SSL_MD5 :0;
+       *mac |= (ssl_digest_methods[SSL_MD_SHA1_IDX] == NULL) ? SSL_SHA1:0;
+       *mac |= (ssl_digest_methods[SSL_MD_GOST94_IDX] == NULL) ? SSL_GOST94:0;
+       *mac |= (ssl_digest_methods[SSL_MD_GOST89MAC_IDX] == NULL || ssl_mac_pkey_id[SSL_MD_GOST89MAC_IDX]==NID_undef)? SSL_GOST89MAC:0;
 
-       mask |= (ssl_cipher_methods[SSL_ENC_DES_IDX ] == NULL) ? SSL_DES :0;
-       mask |= (ssl_cipher_methods[SSL_ENC_3DES_IDX] == NULL) ? SSL_3DES:0;
-       mask |= (ssl_cipher_methods[SSL_ENC_RC4_IDX ] == NULL) ? SSL_RC4 :0;
-       mask |= (ssl_cipher_methods[SSL_ENC_RC2_IDX ] == NULL) ? SSL_RC2 :0;
-       mask |= (ssl_cipher_methods[SSL_ENC_IDEA_IDX] == NULL) ? SSL_IDEA:0;
-       mask |= (ssl_cipher_methods[SSL_ENC_eFZA_IDX] == NULL) ? SSL_eFZA:0;
-       mask |= (ssl_cipher_methods[SSL_ENC_SEED_IDX] == NULL) ? SSL_SEED:0;
-
-       mask |= (ssl_digest_methods[SSL_MD_MD5_IDX ] == NULL) ? SSL_MD5 :0;
-       mask |= (ssl_digest_methods[SSL_MD_SHA1_IDX] == NULL) ? SSL_SHA1:0;
-
-       /* finally consider algorithms where mask and m256 differ */
-       m256 = mask;
-       mask |= (ssl_cipher_methods[SSL_ENC_AES128_IDX] == NULL) ? SSL_AES:0;
-       mask |= (ssl_cipher_methods[SSL_ENC_CAMELLIA128_IDX] == NULL) ? SSL_CAMELLIA:0;
-       m256 |= (ssl_cipher_methods[SSL_ENC_AES256_IDX] == NULL) ? SSL_AES:0;
-       m256 |= (ssl_cipher_methods[SSL_ENC_CAMELLIA256_IDX] == NULL) ? SSL_CAMELLIA:0;
-
-       ret.mask = mask;
-       ret.m256 = m256;
-       return ret;
        }
 
 static void ssl_cipher_collect_ciphers(const SSL_METHOD *ssl_method,
-               int num_of_ciphers, unsigned long mask, unsigned long m256,
-               CIPHER_ORDER *co_list, CIPHER_ORDER **head_p,
-               CIPHER_ORDER **tail_p)
+                int num_of_ciphers,
+                unsigned long disabled_mkey, unsigned long disabled_auth,
+                unsigned long disabled_enc, unsigned long disabled_mac,
+                unsigned long disabled_ssl,
+                CIPHER_ORDER *co_list,
+                CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p)
        {
        int i, co_list_num;
-       SSL_CIPHER *c;
+       const SSL_CIPHER *c;
 
        /*
         * We have num_of_ciphers descriptions compiled in, depending on the
@@ -517,14 +722,13 @@ static void ssl_cipher_collect_ciphers(const SSL_METHOD *ssl_method,
        for (i = 0; i < num_of_ciphers; i++)
                {
                c = ssl_method->get_cipher(i);
-#define IS_MASKED(c) ((c)->algorithms & (((c)->alg_bits == 256) ? m256 : mask))
                /* drop those that use any of that is not available */
-#ifdef OPENSSL_FIPS
-               if ((c != NULL) && c->valid && !IS_MASKED(c)
-                       && (!FIPS_mode() || (c->algo_strength & SSL_FIPS)))
-#else
-               if ((c != NULL) && c->valid && !IS_MASKED(c))
-#endif
+               if ((c != NULL) && c->valid &&
+                   !(c->algorithm_mkey & disabled_mkey) &&
+                   !(c->algorithm_auth & disabled_auth) &&
+                   !(c->algorithm_enc & disabled_enc) &&
+                   !(c->algorithm_mac & disabled_mac) &&
+                   !(c->algorithm_ssl & disabled_ssl))
                        {
                        co_list[co_list_num].cipher = c;
                        co_list[co_list_num].next = NULL;
@@ -532,7 +736,7 @@ static void ssl_cipher_collect_ciphers(const SSL_METHOD *ssl_method,
                        co_list[co_list_num].active = 0;
                        co_list_num++;
 #ifdef KSSL_DEBUG
-                       printf("\t%d: %s %lx %lx\n",i,c->name,c->id,c->algorithms);
+                       printf("\t%d: %s %lx %lx %lx\n",i,c->name,c->id,c->algorithm_mkey,c->algorithm_auth);
 #endif /* KSSL_DEBUG */
                        /*
                        if (!sk_push(ca_list,(char *)c)) goto err;
@@ -543,29 +747,45 @@ static void ssl_cipher_collect_ciphers(const SSL_METHOD *ssl_method,
        /*
         * Prepare linked list from list entries
         */     
-       for (i = 1; i < co_list_num - 1; i++)
-               {
-               co_list[i].prev = &(co_list[i-1]);
-               co_list[i].next = &(co_list[i+1]);
-               }
        if (co_list_num > 0)
                {
-               (*head_p) = &(co_list[0]);
-               (*head_p)->prev = NULL;
-               (*head_p)->next = &(co_list[1]);
-               (*tail_p) = &(co_list[co_list_num - 1]);
-               (*tail_p)->prev = &(co_list[co_list_num - 2]);
-               (*tail_p)->next = NULL;
+               co_list[0].prev = NULL;
+
+               if (co_list_num > 1)
+                       {
+                       co_list[0].next = &co_list[1];
+                       
+                       for (i = 1; i < co_list_num - 1; i++)
+                               {
+                               co_list[i].prev = &co_list[i - 1];
+                               co_list[i].next = &co_list[i + 1];
+                               }
+
+                       co_list[co_list_num - 1].prev = &co_list[co_list_num - 2];
+                       }
+               
+               co_list[co_list_num - 1].next = NULL;
+
+               *head_p = &co_list[0];
+               *tail_p = &co_list[co_list_num - 1];
                }
        }
 
-static void ssl_cipher_collect_aliases(SSL_CIPHER **ca_list,
-                       int num_of_group_aliases, unsigned long mask,
+static void ssl_cipher_collect_aliases(const SSL_CIPHER **ca_list,
+                        int num_of_group_aliases,
+                        unsigned long disabled_mkey, unsigned long disabled_auth,
+                        unsigned long disabled_enc, unsigned long disabled_mac,
+                        unsigned long disabled_ssl,
                        CIPHER_ORDER *head)
        {
        CIPHER_ORDER *ciph_curr;
-       SSL_CIPHER **ca_curr;
+       const SSL_CIPHER **ca_curr;
        int i;
+       unsigned long mask_mkey = ~disabled_mkey;
+       unsigned long mask_auth = ~disabled_auth;
+       unsigned long mask_enc = ~disabled_enc;
+       unsigned long mask_mac = ~disabled_mac;
+       unsigned long mask_ssl = ~disabled_ssl;
 
        /*
         * First, add the real ciphers as already collected
@@ -581,84 +801,118 @@ static void ssl_cipher_collect_aliases(SSL_CIPHER **ca_list,
 
        /*
         * Now we add the available ones from the cipher_aliases[] table.
-        * They represent either an algorithm, that must be fully
-        * supported (not match any bit in mask) or represent a cipher
-        * strength value (will be added in any case because algorithms=0).
+        * They represent either one or more algorithms, some of which
+        * in any affected category must be supported (set in enabled_mask),
+        * or represent a cipher strength value (will be added in any case because algorithms=0).
         */
        for (i = 0; i < num_of_group_aliases; i++)
                {
-               if ((i == 0) ||         /* always fetch "ALL" */
-                   !(cipher_aliases[i].algorithms & mask))
-                       {
-                       *ca_curr = (SSL_CIPHER *)(cipher_aliases + i);
-                       ca_curr++;
-                       }
+               unsigned long algorithm_mkey = cipher_aliases[i].algorithm_mkey;
+               unsigned long algorithm_auth = cipher_aliases[i].algorithm_auth;
+               unsigned long algorithm_enc = cipher_aliases[i].algorithm_enc;
+               unsigned long algorithm_mac = cipher_aliases[i].algorithm_mac;
+               unsigned long algorithm_ssl = cipher_aliases[i].algorithm_ssl;
+
+               if (algorithm_mkey)
+                       if ((algorithm_mkey & mask_mkey) == 0)
+                               continue;
+       
+               if (algorithm_auth)
+                       if ((algorithm_auth & mask_auth) == 0)
+                               continue;
+               
+               if (algorithm_enc)
+                       if ((algorithm_enc & mask_enc) == 0)
+                               continue;
+               
+               if (algorithm_mac)
+                       if ((algorithm_mac & mask_mac) == 0)
+                               continue;
+               
+               if (algorithm_ssl)
+                       if ((algorithm_ssl & mask_ssl) == 0)
+                               continue;
+               
+               *ca_curr = (SSL_CIPHER *)(cipher_aliases + i);
+               ca_curr++;
                }
 
        *ca_curr = NULL;        /* end of list */
        }
 
-static void ssl_cipher_apply_rule(unsigned long cipher_id, unsigned long ssl_version,
-               unsigned long algorithms, unsigned long mask,
-               unsigned long algo_strength, unsigned long mask_strength,
-               int rule, int strength_bits, CIPHER_ORDER *co_list,
+static void ssl_cipher_apply_rule(unsigned long cipher_id,
+                unsigned long alg_mkey, unsigned long alg_auth,
+                unsigned long alg_enc, unsigned long alg_mac,
+                unsigned long alg_ssl,
+               unsigned long algo_strength,
+               int rule, int strength_bits,
                CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p)
        {
-       CIPHER_ORDER *head, *tail, *curr, *curr2, *tail2;
-       SSL_CIPHER *cp;
-       unsigned long ma, ma_s;
+       CIPHER_ORDER *head, *tail, *curr, *curr2, *last;
+       const SSL_CIPHER *cp;
+       int reverse = 0;
 
 #ifdef CIPHER_DEBUG
-       printf("Applying rule %d with %08lx %08lx %08lx %08lx (%d)\n",
-               rule, algorithms, mask, algo_strength, mask_strength,
-               strength_bits);
+       printf("Applying rule %d with %08lx/%08lx/%08lx/%08lx/%08lx %08lx (%d)\n",
+               rule, alg_mkey, alg_auth, alg_enc, alg_mac, alg_ssl, algo_strength, strength_bits);
 #endif
 
-       curr = head = *head_p;
-       curr2 = head;
-       tail2 = tail = *tail_p;
+       if (rule == CIPHER_DEL)
+               reverse = 1; /* needed to maintain sorting between currently deleted ciphers */
+
+       head = *head_p;
+       tail = *tail_p;
+
+       if (reverse)
+               {
+               curr = tail;
+               last = head;
+               }
+       else
+               {
+               curr = head;
+               last = tail;
+               }
+
+       curr2 = curr;
        for (;;)
                {
-               if ((curr == NULL) || (curr == tail2)) break;
+               if ((curr == NULL) || (curr == last)) break;
                curr = curr2;
-               curr2 = curr->next;
+               curr2 = reverse ? curr->prev : curr->next;
 
                cp = curr->cipher;
 
-               /* If explicit cipher suite, match only that one for its own protocol version.
-                * Usual selection criteria will be used for similar ciphersuites from other version! */
-
-               if (cipher_id && (cp->algorithms & SSL_SSL_MASK) == ssl_version)
+               /*
+                * Selection criteria is either the value of strength_bits
+                * or the algorithms used.
+                */
+               if (strength_bits >= 0)
                        {
-                       if (cp->id != cipher_id)
+                       if (strength_bits != cp->strength_bits)
                                continue;
                        }
-
-               /*
-                * Selection criteria is either the number of strength_bits
-                * or the algorithm used.
-                */
-               else if (strength_bits == -1)
+               else
                        {
-                       ma = mask & cp->algorithms;
-                       ma_s = mask_strength & cp->algo_strength;
-
 #ifdef CIPHER_DEBUG
-                       printf("\nName: %s:\nAlgo = %08lx Algo_strength = %08lx\nMask = %08lx Mask_strength %08lx\n", cp->name, cp->algorithms, cp->algo_strength, mask, mask_strength);
-                       printf("ma = %08lx ma_s %08lx, ma&algo=%08lx, ma_s&algos=%08lx\n", ma, ma_s, ma&algorithms, ma_s&algo_strength);
+                       printf("\nName: %s:\nAlgo = %08lx/%08lx/%08lx/%08lx/%08lx Algo_strength = %08lx\n", cp->name, cp->algorithm_mkey, cp->algorithm_auth, cp->algorithm_enc, cp->algorithm_mac, cp->algorithm_ssl, cp->algo_strength);
 #endif
-                       /*
-                        * Select: if none of the mask bit was met from the
-                        * cipher or not all of the bits were met, the
-                        * selection does not apply.
-                        */
-                       if (((ma == 0) && (ma_s == 0)) ||
-                           ((ma & algorithms) != ma) ||
-                           ((ma_s & algo_strength) != ma_s))
-                               continue; /* does not apply */
+
+                       if (alg_mkey && !(alg_mkey & cp->algorithm_mkey))
+                               continue;
+                       if (alg_auth && !(alg_auth & cp->algorithm_auth))
+                               continue;
+                       if (alg_enc && !(alg_enc & cp->algorithm_enc))
+                               continue;
+                       if (alg_mac && !(alg_mac & cp->algorithm_mac))
+                               continue;
+                       if (alg_ssl && !(alg_ssl & cp->algorithm_ssl))
+                               continue;
+                       if ((algo_strength & SSL_EXP_MASK) && !(algo_strength & SSL_EXP_MASK & cp->algo_strength))
+                               continue;
+                       if ((algo_strength & SSL_STRONG_MASK) && !(algo_strength & SSL_STRONG_MASK & cp->algo_strength))
+                               continue;
                        }
-               else if (strength_bits != cp->strength_bits)
-                       continue;       /* does not apply */
 
 #ifdef CIPHER_DEBUG
                printf("Action = %d\n", rule);
@@ -667,38 +921,37 @@ static void ssl_cipher_apply_rule(unsigned long cipher_id, unsigned long ssl_ver
                /* add the cipher if it has not been added yet. */
                if (rule == CIPHER_ADD)
                        {
+                       /* reverse == 0 */
                        if (!curr->active)
                                {
-                               int add_this_cipher = 1;
-
-                               if (((cp->algorithms & (SSL_kECDHE|SSL_kECDH|SSL_aECDSA)) != 0))
-                                       {
-                                       /* Make sure "ECCdraft" ciphersuites are activated only if
-                                        * *explicitly* requested, but not implicitly (such as
-                                        * as part of the "AES" alias). */
-
-                                       add_this_cipher = (mask & (SSL_kECDHE|SSL_kECDH|SSL_aECDSA)) != 0 || cipher_id != 0;
-                                       }
-                               
-                               if (add_this_cipher)
-                                       {
-                                       ll_append_tail(&head, curr, &tail);
-                                       curr->active = 1;
-                                       }
+                               ll_append_tail(&head, curr, &tail);
+                               curr->active = 1;
                                }
                        }
                /* Move the added cipher to this location */
                else if (rule == CIPHER_ORD)
                        {
+                       /* reverse == 0 */
                        if (curr->active)
                                {
                                ll_append_tail(&head, curr, &tail);
                                }
                        }
                else if (rule == CIPHER_DEL)
-                       curr->active = 0;
+                       {
+                       /* reverse == 1 */
+                       if (curr->active)
+                               {
+                               /* most recently deleted ciphersuites get best positions
+                                * for any future CIPHER_ADD (note that the CIPHER_DEL loop
+                                * works in reverse to maintain the order) */
+                               ll_append_head(&head, curr, &tail);
+                               curr->active = 0;
+                               }
+                       }
                else if (rule == CIPHER_KILL)
                        {
+                       /* reverse == 0 */
                        if (head == curr)
                                head = curr->next;
                        else
@@ -719,8 +972,7 @@ static void ssl_cipher_apply_rule(unsigned long cipher_id, unsigned long ssl_ver
        *tail_p = tail;
        }
 
-static int ssl_cipher_strength_sort(CIPHER_ORDER *co_list,
-                                   CIPHER_ORDER **head_p,
+static int ssl_cipher_strength_sort(CIPHER_ORDER **head_p,
                                    CIPHER_ORDER **tail_p)
        {
        int max_strength_bits, i, *number_uses;
@@ -743,10 +995,10 @@ static int ssl_cipher_strength_sort(CIPHER_ORDER *co_list,
 
        number_uses = OPENSSL_malloc((max_strength_bits + 1) * sizeof(int));
        if (!number_uses)
-       {
+               {
                SSLerr(SSL_F_SSL_CIPHER_STRENGTH_SORT,ERR_R_MALLOC_FAILURE);
                return(0);
-       }
+               }
        memset(number_uses, 0, (max_strength_bits + 1) * sizeof(int));
 
        /*
@@ -765,21 +1017,20 @@ static int ssl_cipher_strength_sort(CIPHER_ORDER *co_list,
         */
        for (i = max_strength_bits; i >= 0; i--)
                if (number_uses[i] > 0)
-                       ssl_cipher_apply_rule(0, 0, 0, 0, 0, 0, CIPHER_ORD, i,
-                                       co_list, head_p, tail_p);
+                       ssl_cipher_apply_rule(0, 0, 0, 0, 0, 0, 0, CIPHER_ORD, i, head_p, tail_p);
 
        OPENSSL_free(number_uses);
        return(1);
        }
 
 static int ssl_cipher_process_rulestr(const char *rule_str,
-               CIPHER_ORDER *co_list, CIPHER_ORDER **head_p,
-               CIPHER_ORDER **tail_p, SSL_CIPHER **ca_list)
+                CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p,
+                const SSL_CIPHER **ca_list)
        {
-       unsigned long algorithms, mask, algo_strength, mask_strength;
+       unsigned long alg_mkey, alg_auth, alg_enc, alg_mac, alg_ssl, algo_strength;
        const char *l, *buf;
        int j, multi, found, rule, retval, ok, buflen;
-       unsigned long cipher_id = 0, ssl_version = 0;
+       unsigned long cipher_id = 0;
        char ch;
 
        retval = 1;
@@ -807,7 +1058,12 @@ static int ssl_cipher_process_rulestr(const char *rule_str,
                        continue;
                        }
 
-               algorithms = mask = algo_strength = mask_strength = 0;
+               alg_mkey = 0;
+               alg_auth = 0;
+               alg_enc = 0;
+               alg_mac = 0;
+               alg_ssl = 0;
+               algo_strength = 0;
 
                for (;;)
                        {
@@ -867,10 +1123,9 @@ static int ssl_cipher_process_rulestr(const char *rule_str,
                         * sufficient, we have to strncmp() anyway. (We cannot
                         * use strcmp(), because buf is not '\0' terminated.)
                         */
-                        j = found = 0;
-                        cipher_id = 0;
-                        ssl_version = 0;
-                        while (ca_list[j])
+                       j = found = 0;
+                       cipher_id = 0;
+                       while (ca_list[j])
                                {
                                if (!strncmp(buf, ca_list[j]->name, buflen) &&
                                    (ca_list[j]->name[buflen] == '\0'))
@@ -881,31 +1136,100 @@ static int ssl_cipher_process_rulestr(const char *rule_str,
                                else
                                        j++;
                                }
+
                        if (!found)
                                break;  /* ignore this entry */
 
-                       /* New algorithms:
-                        *  1 - any old restrictions apply outside new mask
-                        *  2 - any new restrictions apply outside old mask
-                        *  3 - enforce old & new where masks intersect
-                        */
-                       algorithms = (algorithms & ~ca_list[j]->mask) |         /* 1 */
-                                    (ca_list[j]->algorithms & ~mask) |         /* 2 */
-                                    (algorithms & ca_list[j]->algorithms);     /* 3 */
-                       mask |= ca_list[j]->mask;
-                       algo_strength = (algo_strength & ~ca_list[j]->mask_strength) |
-                                       (ca_list[j]->algo_strength & ~mask_strength) |
-                                       (algo_strength & ca_list[j]->algo_strength);
-                       mask_strength |= ca_list[j]->mask_strength;
-
-                       /* explicit ciphersuite found */
+                       if (ca_list[j]->algorithm_mkey)
+                               {
+                               if (alg_mkey)
+                                       {
+                                       alg_mkey &= ca_list[j]->algorithm_mkey;
+                                       if (!alg_mkey) { found = 0; break; }
+                                       }
+                               else
+                                       alg_mkey = ca_list[j]->algorithm_mkey;
+                               }
+
+                       if (ca_list[j]->algorithm_auth)
+                               {
+                               if (alg_auth)
+                                       {
+                                       alg_auth &= ca_list[j]->algorithm_auth;
+                                       if (!alg_auth) { found = 0; break; }
+                                       }
+                               else
+                                       alg_auth = ca_list[j]->algorithm_auth;
+                               }
+                       
+                       if (ca_list[j]->algorithm_enc)
+                               {
+                               if (alg_enc)
+                                       {
+                                       alg_enc &= ca_list[j]->algorithm_enc;
+                                       if (!alg_enc) { found = 0; break; }
+                                       }
+                               else
+                                       alg_enc = ca_list[j]->algorithm_enc;
+                               }
+                                               
+                       if (ca_list[j]->algorithm_mac)
+                               {
+                               if (alg_mac)
+                                       {
+                                       alg_mac &= ca_list[j]->algorithm_mac;
+                                       if (!alg_mac) { found = 0; break; }
+                                       }
+                               else
+                                       alg_mac = ca_list[j]->algorithm_mac;
+                               }
+                       
+                       if (ca_list[j]->algo_strength & SSL_EXP_MASK)
+                               {
+                               if (algo_strength & SSL_EXP_MASK)
+                                       {
+                                       algo_strength &= (ca_list[j]->algo_strength & SSL_EXP_MASK) | ~SSL_EXP_MASK;
+                                       if (!(algo_strength & SSL_EXP_MASK)) { found = 0; break; }
+                                       }
+                               else
+                                       algo_strength |= ca_list[j]->algo_strength & SSL_EXP_MASK;
+                               }
+
+                       if (ca_list[j]->algo_strength & SSL_STRONG_MASK)
+                               {
+                               if (algo_strength & SSL_STRONG_MASK)
+                                       {
+                                       algo_strength &= (ca_list[j]->algo_strength & SSL_STRONG_MASK) | ~SSL_STRONG_MASK;
+                                       if (!(algo_strength & SSL_STRONG_MASK)) { found = 0; break; }
+                                       }
+                               else
+                                       algo_strength |= ca_list[j]->algo_strength & SSL_STRONG_MASK;
+                               }
+                       
                        if (ca_list[j]->valid)
                                {
+                               /* explicit ciphersuite found; its protocol version
+                                * does not become part of the search pattern!*/
+
                                cipher_id = ca_list[j]->id;
-                               ssl_version = ca_list[j]->algorithms & SSL_SSL_MASK;
-                               break;
                                }
+                       else
+                               {
+                               /* not an explicit ciphersuite; only in this case, the
+                                * protocol version is considered part of the search pattern */
 
+                               if (ca_list[j]->algorithm_ssl)
+                                       {
+                                       if (alg_ssl)
+                                               {
+                                               alg_ssl &= ca_list[j]->algorithm_ssl;
+                                               if (!alg_ssl) { found = 0; break; }
+                                               }
+                                       else
+                                               alg_ssl = ca_list[j]->algorithm_ssl;
+                                       }
+                               }
+                       
                        if (!multi) break;
                        }
 
@@ -917,8 +1241,7 @@ static int ssl_cipher_process_rulestr(const char *rule_str,
                        ok = 0;
                        if ((buflen == 8) &&
                                !strncmp(buf, "STRENGTH", 8))
-                               ok = ssl_cipher_strength_sort(co_list,
-                                       head_p, tail_p);
+                               ok = ssl_cipher_strength_sort(head_p, tail_p);
                        else
                                SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR,
                                        SSL_R_INVALID_COMMAND);
@@ -935,9 +1258,9 @@ static int ssl_cipher_process_rulestr(const char *rule_str,
                        }
                else if (found)
                        {
-                       ssl_cipher_apply_rule(cipher_id, ssl_version, algorithms, mask,
-                               algo_strength, mask_strength, rule, -1,
-                               co_list, head_p, tail_p);
+                       ssl_cipher_apply_rule(cipher_id,
+                               alg_mkey, alg_auth, alg_enc, alg_mac, alg_ssl, algo_strength,
+                               rule, -1, head_p, tail_p);
                        }
                else
                        {
@@ -956,12 +1279,11 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method,
                const char *rule_str)
        {
        int ok, num_of_ciphers, num_of_alias_max, num_of_group_aliases;
-       unsigned long disabled_mask;
-       unsigned long disabled_m256;
+       unsigned long disabled_mkey, disabled_auth, disabled_enc, disabled_mac, disabled_ssl;
        STACK_OF(SSL_CIPHER) *cipherstack, *tmp_cipher_list;
        const char *rule_p;
        CIPHER_ORDER *co_list = NULL, *head = NULL, *tail = NULL, *curr;
-       SSL_CIPHER **ca_list = NULL;
+       const SSL_CIPHER **ca_list = NULL;
 
        /*
         * Return with error if nothing to do.
@@ -973,12 +1295,7 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method,
         * To reduce the work to do we only want to process the compiled
         * in algorithms, so we first get the mask of disabled ciphers.
         */
-       {
-               struct disabled_masks d;
-               d = ssl_cipher_get_disabled();
-               disabled_mask = d.mask;
-               disabled_m256 = d.m256;
-       }
+       ssl_cipher_get_disabled(&disabled_mkey, &disabled_auth, &disabled_enc, &disabled_mac, &disabled_ssl);
 
        /*
         * Now we have to collect the available ciphers from the compiled
@@ -996,8 +1313,52 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method,
                return(NULL);   /* Failure */
                }
 
-       ssl_cipher_collect_ciphers(ssl_method, num_of_ciphers, disabled_mask,
-                                  disabled_m256, co_list, &head, &tail);
+       ssl_cipher_collect_ciphers(ssl_method, num_of_ciphers,
+                                  disabled_mkey, disabled_auth, disabled_enc, disabled_mac, disabled_ssl,
+                                  co_list, &head, &tail);
+
+
+       /* Now arrange all ciphers by preference: */
+
+       /* Everything else being equal, prefer ephemeral ECDH over other key exchange mechanisms */
+       ssl_cipher_apply_rule(0, SSL_kEECDH, 0, 0, 0, 0, 0, CIPHER_ADD, -1, &head, &tail);
+       ssl_cipher_apply_rule(0, SSL_kEECDH, 0, 0, 0, 0, 0, CIPHER_DEL, -1, &head, &tail);
+
+       /* AES is our preferred symmetric cipher */
+       ssl_cipher_apply_rule(0, 0, 0, SSL_AES, 0, 0, 0, CIPHER_ADD, -1, &head, &tail);
+
+       /* Temporarily enable everything else for sorting */
+       ssl_cipher_apply_rule(0, 0, 0, 0, 0, 0, 0, CIPHER_ADD, -1, &head, &tail);
+
+       /* Low priority for MD5 */
+       ssl_cipher_apply_rule(0, 0, 0, 0, SSL_MD5, 0, 0, CIPHER_ORD, -1, &head, &tail);
+
+       /* Move anonymous ciphers to the end.  Usually, these will remain disabled.
+        * (For applications that allow them, they aren't too bad, but we prefer
+        * authenticated ciphers.) */
+       ssl_cipher_apply_rule(0, 0, SSL_aNULL, 0, 0, 0, 0, CIPHER_ORD, -1, &head, &tail);
+
+       /* Move ciphers without forward secrecy to the end */
+       ssl_cipher_apply_rule(0, 0, SSL_aECDH, 0, 0, 0, 0, CIPHER_ORD, -1, &head, &tail);
+       /* ssl_cipher_apply_rule(0, 0, SSL_aDH, 0, 0, 0, 0, CIPHER_ORD, -1, &head, &tail); */
+       ssl_cipher_apply_rule(0, SSL_kRSA, 0, 0, 0, 0, 0, CIPHER_ORD, -1, &head, &tail);
+       ssl_cipher_apply_rule(0, SSL_kPSK, 0,0, 0, 0, 0, CIPHER_ORD, -1, &head, &tail);
+       ssl_cipher_apply_rule(0, SSL_kKRB5, 0,0, 0, 0, 0, CIPHER_ORD, -1, &head, &tail);
+
+       /* RC4 is sort-of broken -- move the the end */
+       ssl_cipher_apply_rule(0, 0, 0, SSL_RC4, 0, 0, 0, CIPHER_ORD, -1, &head, &tail);
+
+       /* Now sort by symmetric encryption strength.  The above ordering remains
+        * in force within each class */
+       if (!ssl_cipher_strength_sort(&head, &tail))
+               {
+               OPENSSL_free(co_list);
+               return NULL;
+               }
+
+       /* Now disable everything (maintaining the ordering!) */
+       ssl_cipher_apply_rule(0, 0, 0, 0, 0, 0, 0, CIPHER_DEL, -1, &head, &tail);
+
 
        /*
         * We also need cipher aliases for selecting based on the rule_str.
@@ -1009,8 +1370,7 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method,
         */
        num_of_group_aliases = sizeof(cipher_aliases) / sizeof(SSL_CIPHER);
        num_of_alias_max = num_of_ciphers + num_of_group_aliases + 1;
-       ca_list =
-               (SSL_CIPHER **)OPENSSL_malloc(sizeof(SSL_CIPHER *) * num_of_alias_max);
+       ca_list = OPENSSL_malloc(sizeof(SSL_CIPHER *) * num_of_alias_max);
        if (ca_list == NULL)
                {
                OPENSSL_free(co_list);
@@ -1018,7 +1378,8 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method,
                return(NULL);   /* Failure */
                }
        ssl_cipher_collect_aliases(ca_list, num_of_group_aliases,
-                                  (disabled_mask & disabled_m256), head);
+                                  disabled_mkey, disabled_auth, disabled_enc,
+                                  disabled_mac, disabled_ssl, head);
 
        /*
         * If the rule_string begins with DEFAULT, apply the default rule
@@ -1029,23 +1390,23 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method,
        if (strncmp(rule_str,"DEFAULT",7) == 0)
                {
                ok = ssl_cipher_process_rulestr(SSL_DEFAULT_CIPHER_LIST,
-                       co_list, &head, &tail, ca_list);
+                       &head, &tail, ca_list);
                rule_p += 7;
                if (*rule_p == ':')
                        rule_p++;
                }
 
        if (ok && (strlen(rule_p) > 0))
-               ok = ssl_cipher_process_rulestr(rule_p, co_list, &head, &tail,
-                                               ca_list);
+               ok = ssl_cipher_process_rulestr(rule_p, &head, &tail, ca_list);
 
-       OPENSSL_free(ca_list);  /* Not needed anymore */
+       OPENSSL_free((void *)ca_list);  /* Not needed anymore */
 
        if (!ok)
                {       /* Rule processing failure */
                OPENSSL_free(co_list);
                return(NULL);
                }
+       
        /*
         * Allocate new "cipherstack" for the result, return with error
         * if we cannot get one.
@@ -1062,11 +1423,7 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method,
         */
        for (curr = head; curr != NULL; curr = curr->next)
                {
-#ifdef OPENSSL_FIPS
-               if (curr->active && (!FIPS_mode() || curr->cipher->algo_strength & SSL_FIPS))
-#else
                if (curr->active)
-#endif
                        {
                        sk_SSL_CIPHER_push(cipherstack, curr->cipher);
 #ifdef CIPHER_DEBUG
@@ -1099,14 +1456,19 @@ char *SSL_CIPHER_description(const SSL_CIPHER *cipher, char *buf, int len)
        int is_export,pkl,kl;
        const char *ver,*exp_str;
        const char *kx,*au,*enc,*mac;
-       unsigned long alg,alg2;
+       unsigned long alg_mkey,alg_auth,alg_enc,alg_mac,alg_ssl,alg2;
 #ifdef KSSL_DEBUG
-       static const char *format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s AL=%lx\n";
+       static const char *format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s AL=%lx/%lx/%lx/%lx/%lx\n";
 #else
        static const char *format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s\n";
 #endif /* KSSL_DEBUG */
 
-       alg=cipher->algorithms;
+       alg_mkey = cipher->algorithm_mkey;
+       alg_auth = cipher->algorithm_auth;
+       alg_enc = cipher->algorithm_enc;
+       alg_mac = cipher->algorithm_mac;
+       alg_ssl = cipher->algorithm_ssl;
+
        alg2=cipher->algorithm2;
 
        is_export=SSL_C_IS_EXPORT(cipher);
@@ -1114,14 +1476,14 @@ char *SSL_CIPHER_description(const SSL_CIPHER *cipher, char *buf, int len)
        kl=SSL_C_EXPORT_KEYLENGTH(cipher);
        exp_str=is_export?" export":"";
        
-       if (alg & SSL_SSLV2)
+       if (alg_ssl & SSL_SSLV2)
                ver="SSLv2";
-       else if (alg & SSL_SSLV3)
+       else if (alg_ssl & SSL_SSLV3)
                ver="SSLv3";
        else
                ver="unknown";
 
-       switch (alg&SSL_MKEY_MASK)
+       switch (alg_mkey)
                {
        case SSL_kRSA:
                kx=is_export?(pkl == 512 ? "RSA(512)" : "RSA(1024)"):"RSA";
@@ -1132,25 +1494,29 @@ char *SSL_CIPHER_description(const SSL_CIPHER *cipher, char *buf, int len)
        case SSL_kDHd:
                kx="DH/DSS";
                break;
-        case SSL_kKRB5:         /* VRS */
-        case SSL_KRB5:          /* VRS */
-            kx="KRB5";
-            break;
-       case SSL_kFZA:
-               kx="Fortezza";
+        case SSL_kKRB5:
+               kx="KRB5";
                break;
        case SSL_kEDH:
                kx=is_export?(pkl == 512 ? "DH(512)" : "DH(1024)"):"DH";
                break;
-       case SSL_kECDH:
-       case SSL_kECDHE:
-               kx=is_export?"ECDH(<=163)":"ECDH";
+       case SSL_kECDHr:
+               kx="ECDH/RSA";
+               break;
+       case SSL_kECDHe:
+               kx="ECDH/ECDSA";
+               break;
+       case SSL_kEECDH:
+               kx="ECDH";
+               break;
+       case SSL_kPSK:
+               kx="PSK";
                break;
        default:
                kx="unknown";
                }
 
-       switch (alg&SSL_AUTH_MASK)
+       switch (alg_auth)
                {
        case SSL_aRSA:
                au="RSA";
@@ -1161,23 +1527,27 @@ char *SSL_CIPHER_description(const SSL_CIPHER *cipher, char *buf, int len)
        case SSL_aDH:
                au="DH";
                break;
-        case SSL_aKRB5:         /* VRS */
-        case SSL_KRB5:          /* VRS */
-            au="KRB5";
-            break;
-       case SSL_aFZA:
+        case SSL_aKRB5:
+               au="KRB5";
+               break;
+        case SSL_aECDH:
+               au="ECDH";
+               break;
        case SSL_aNULL:
                au="None";
                break;
        case SSL_aECDSA:
                au="ECDSA";
                break;
+       case SSL_aPSK:
+               au="PSK";
+               break;
        default:
                au="unknown";
                break;
                }
 
-       switch (alg&SSL_ENC_MASK)
+       switch (alg_enc)
                {
        case SSL_DES:
                enc=(is_export && kl == 5)?"DES(40)":"DES(56)";
@@ -1195,39 +1565,30 @@ char *SSL_CIPHER_description(const SSL_CIPHER *cipher, char *buf, int len)
        case SSL_IDEA:
                enc="IDEA(128)";
                break;
-       case SSL_eFZA:
-               enc="Fortezza";
-               break;
        case SSL_eNULL:
                enc="None";
                break;
-       case SSL_AES:
-               switch(cipher->strength_bits)
-                       {
-               case 128: enc="AES(128)"; break;
-               case 192: enc="AES(192)"; break;
-               case 256: enc="AES(256)"; break;
-               default: enc="AES(?""?""?)"; break;
-                       }
+       case SSL_AES128:
+               enc="AES(128)";
                break;
-       case SSL_CAMELLIA:
-               switch(cipher->strength_bits)
-                       {
-               case 128: enc="Camellia(128)"; break;
-               case 256: enc="Camellia(256)"; break;
-               default: enc="Camellia(?""?""?)"; break;
-                       }
+       case SSL_AES256:
+               enc="AES(256)";
+               break;
+       case SSL_CAMELLIA128:
+               enc="Camellia(128)";
+               break;
+       case SSL_CAMELLIA256:
+               enc="Camellia(256)";
                break;
        case SSL_SEED:
                enc="SEED(128)";
                break;
-
        default:
                enc="unknown";
                break;
                }
 
-       switch (alg&SSL_MAC_MASK)
+       switch (alg_mac)
                {
        case SSL_MD5:
                mac="MD5";
@@ -1250,7 +1611,7 @@ char *SSL_CIPHER_description(const SSL_CIPHER *cipher, char *buf, int len)
                return("Buffer too small");
 
 #ifdef KSSL_DEBUG
-       BIO_snprintf(buf,len,format,cipher->name,ver,kx,au,enc,mac,exp_str,alg);
+       BIO_snprintf(buf,len,format,cipher->name,ver,kx,au,enc,mac,exp_str,alg_mkey,alg_auth,alg_enc,alg_mac,alg_ssl);
 #else
        BIO_snprintf(buf,len,format,cipher->name,ver,kx,au,enc,mac,exp_str);
 #endif /* KSSL_DEBUG */
@@ -1292,6 +1653,52 @@ int SSL_CIPHER_get_bits(const SSL_CIPHER *c, int *alg_bits)
        return(ret);
        }
 
+/* return string version of key exchange algorithm */
+const char* SSL_CIPHER_authentication_method(const SSL_CIPHER* cipher)
+       {
+       switch (cipher->algorithm_mkey)
+               {
+       case SSL_kRSA:
+               return SSL_TXT_RSA;
+       case SSL_kDHr:
+               return SSL_TXT_DH "_" SSL_TXT_RSA;
+       case SSL_kDHd:
+               return SSL_TXT_DH "_" SSL_TXT_DSS;
+       case SSL_kEDH:
+               switch (cipher->algorithm_auth)
+                       {
+               case SSL_aDSS:
+                       return "DHE_" SSL_TXT_DSS;
+               case SSL_aRSA:
+                       return "DHE_" SSL_TXT_RSA;
+               case SSL_aNULL:
+                       return SSL_TXT_DH "_anon";
+               default:
+                       return "UNKNOWN";
+                        }
+       case SSL_kKRB5:
+               return SSL_TXT_KRB5;
+       case SSL_kECDHr:
+               return SSL_TXT_ECDH "_" SSL_TXT_RSA;
+       case SSL_kECDHe:
+               return SSL_TXT_ECDH "_" SSL_TXT_ECDSA;
+       case SSL_kEECDH:
+               switch (cipher->algorithm_auth)
+                       {
+               case SSL_aECDSA:
+                       return "ECDHE_" SSL_TXT_ECDSA;
+               case SSL_aRSA:
+                       return "ECDHE_" SSL_TXT_RSA;
+               case SSL_aNULL:
+                       return SSL_TXT_ECDH "_anon";
+               default:
+                       return "UNKNOWN";
+                        }
+        default:
+               return "UNKNOWN";
+               }
+       }
+
 SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n)
        {
        SSL_COMP *ctmp;
index ff9c856..4fcd5c0 100644 (file)
@@ -1,6 +1,6 @@
 /* ssl/ssl_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2008 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2011 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -137,10 +137,12 @@ static ERR_STRING_DATA SSL_str_functs[]=
 {ERR_FUNC(SSL_F_SSL3_CALLBACK_CTRL),   "SSL3_CALLBACK_CTRL"},
 {ERR_FUNC(SSL_F_SSL3_CHANGE_CIPHER_STATE),     "SSL3_CHANGE_CIPHER_STATE"},
 {ERR_FUNC(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM),        "SSL3_CHECK_CERT_AND_ALGORITHM"},
+{ERR_FUNC(SSL_F_SSL3_CHECK_CLIENT_HELLO),      "SSL3_CHECK_CLIENT_HELLO"},
 {ERR_FUNC(SSL_F_SSL3_CLIENT_HELLO),    "SSL3_CLIENT_HELLO"},
 {ERR_FUNC(SSL_F_SSL3_CONNECT), "SSL3_CONNECT"},
 {ERR_FUNC(SSL_F_SSL3_CTRL),    "SSL3_CTRL"},
 {ERR_FUNC(SSL_F_SSL3_CTX_CTRL),        "SSL3_CTX_CTRL"},
+{ERR_FUNC(SSL_F_SSL3_DIGEST_CACHED_RECORDS),   "SSL3_DIGEST_CACHED_RECORDS"},
 {ERR_FUNC(SSL_F_SSL3_DO_CHANGE_CIPHER_SPEC),   "SSL3_DO_CHANGE_CIPHER_SPEC"},
 {ERR_FUNC(SSL_F_SSL3_ENC),     "SSL3_ENC"},
 {ERR_FUNC(SSL_F_SSL3_GENERATE_KEY_BLOCK),      "SSL3_GENERATE_KEY_BLOCK"},
@@ -159,6 +161,7 @@ static ERR_STRING_DATA SSL_str_functs[]=
 {ERR_FUNC(SSL_F_SSL3_GET_SERVER_CERTIFICATE),  "SSL3_GET_SERVER_CERTIFICATE"},
 {ERR_FUNC(SSL_F_SSL3_GET_SERVER_DONE), "SSL3_GET_SERVER_DONE"},
 {ERR_FUNC(SSL_F_SSL3_GET_SERVER_HELLO),        "SSL3_GET_SERVER_HELLO"},
+{ERR_FUNC(SSL_F_SSL3_HANDSHAKE_MAC),   "ssl3_handshake_mac"},
 {ERR_FUNC(SSL_F_SSL3_NEW_SESSION_TICKET),      "SSL3_NEW_SESSION_TICKET"},
 {ERR_FUNC(SSL_F_SSL3_OUTPUT_CERT_CHAIN),       "SSL3_OUTPUT_CERT_CHAIN"},
 {ERR_FUNC(SSL_F_SSL3_PEEK),    "SSL3_PEEK"},
@@ -171,8 +174,9 @@ static ERR_STRING_DATA SSL_str_functs[]=
 {ERR_FUNC(SSL_F_SSL3_SEND_SERVER_CERTIFICATE), "SSL3_SEND_SERVER_CERTIFICATE"},
 {ERR_FUNC(SSL_F_SSL3_SEND_SERVER_HELLO),       "SSL3_SEND_SERVER_HELLO"},
 {ERR_FUNC(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE),        "SSL3_SEND_SERVER_KEY_EXCHANGE"},
-{ERR_FUNC(SSL_F_SSL3_SETUP_BUFFERS),   "SSL3_SETUP_BUFFERS"},
 {ERR_FUNC(SSL_F_SSL3_SETUP_KEY_BLOCK), "SSL3_SETUP_KEY_BLOCK"},
+{ERR_FUNC(SSL_F_SSL3_SETUP_READ_BUFFER),       "SSL3_SETUP_READ_BUFFER"},
+{ERR_FUNC(SSL_F_SSL3_SETUP_WRITE_BUFFER),      "SSL3_SETUP_WRITE_BUFFER"},
 {ERR_FUNC(SSL_F_SSL3_WRITE_BYTES),     "SSL3_WRITE_BYTES"},
 {ERR_FUNC(SSL_F_SSL3_WRITE_PENDING),   "SSL3_WRITE_PENDING"},
 {ERR_FUNC(SSL_F_SSL_ADD_CLIENTHELLO_RENEGOTIATE_EXT),  "SSL_ADD_CLIENTHELLO_RENEGOTIATE_EXT"},
@@ -189,6 +193,7 @@ static ERR_STRING_DATA SSL_str_functs[]=
 {ERR_FUNC(SSL_F_SSL_CERT_NEW), "SSL_CERT_NEW"},
 {ERR_FUNC(SSL_F_SSL_CHECK_PRIVATE_KEY),        "SSL_check_private_key"},
 {ERR_FUNC(SSL_F_SSL_CHECK_SERVERHELLO_TLSEXT), "SSL_CHECK_SERVERHELLO_TLSEXT"},
+{ERR_FUNC(SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG),      "SSL_CHECK_SRVR_ECC_CERT_AND_ALG"},
 {ERR_FUNC(SSL_F_SSL_CIPHER_PROCESS_RULESTR),   "SSL_CIPHER_PROCESS_RULESTR"},
 {ERR_FUNC(SSL_F_SSL_CIPHER_STRENGTH_SORT),     "SSL_CIPHER_STRENGTH_SORT"},
 {ERR_FUNC(SSL_F_SSL_CLEAR),    "SSL_clear"},
@@ -210,6 +215,7 @@ static ERR_STRING_DATA SSL_str_functs[]=
 {ERR_FUNC(SSL_F_SSL_CTX_USE_PRIVATEKEY),       "SSL_CTX_use_PrivateKey"},
 {ERR_FUNC(SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1),  "SSL_CTX_use_PrivateKey_ASN1"},
 {ERR_FUNC(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE),  "SSL_CTX_use_PrivateKey_file"},
+{ERR_FUNC(SSL_F_SSL_CTX_USE_PSK_IDENTITY_HINT),        "SSL_CTX_use_psk_identity_hint"},
 {ERR_FUNC(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY),    "SSL_CTX_use_RSAPrivateKey"},
 {ERR_FUNC(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1),       "SSL_CTX_use_RSAPrivateKey_ASN1"},
 {ERR_FUNC(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE),       "SSL_CTX_use_RSAPrivateKey_file"},
@@ -221,7 +227,6 @@ static ERR_STRING_DATA SSL_str_functs[]=
 {ERR_FUNC(SSL_F_SSL_INIT_WBIO_BUFFER), "SSL_INIT_WBIO_BUFFER"},
 {ERR_FUNC(SSL_F_SSL_LOAD_CLIENT_CA_FILE),      "SSL_load_client_CA_file"},
 {ERR_FUNC(SSL_F_SSL_NEW),      "SSL_new"},
-{ERR_FUNC(SSL_F_SSL_NEXT_PROTOS_PARSE),        "SSL_next_protos_parse"},
 {ERR_FUNC(SSL_F_SSL_PARSE_CLIENTHELLO_RENEGOTIATE_EXT),        "SSL_PARSE_CLIENTHELLO_RENEGOTIATE_EXT"},
 {ERR_FUNC(SSL_F_SSL_PARSE_CLIENTHELLO_TLSEXT), "SSL_PARSE_CLIENTHELLO_TLSEXT"},
 {ERR_FUNC(SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT),        "SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT"},
@@ -243,6 +248,7 @@ static ERR_STRING_DATA SSL_str_functs[]=
 {ERR_FUNC(SSL_F_SSL_SET_RFD),  "SSL_set_rfd"},
 {ERR_FUNC(SSL_F_SSL_SET_SESSION),      "SSL_set_session"},
 {ERR_FUNC(SSL_F_SSL_SET_SESSION_ID_CONTEXT),   "SSL_set_session_id_context"},
+{ERR_FUNC(SSL_F_SSL_SET_SESSION_TICKET_EXT),   "SSL_set_session_ticket_ext"},
 {ERR_FUNC(SSL_F_SSL_SET_TRUST),        "SSL_set_trust"},
 {ERR_FUNC(SSL_F_SSL_SET_WFD),  "SSL_set_wfd"},
 {ERR_FUNC(SSL_F_SSL_SHUTDOWN), "SSL_shutdown"},
@@ -255,13 +261,19 @@ static ERR_STRING_DATA SSL_str_functs[]=
 {ERR_FUNC(SSL_F_SSL_USE_PRIVATEKEY),   "SSL_use_PrivateKey"},
 {ERR_FUNC(SSL_F_SSL_USE_PRIVATEKEY_ASN1),      "SSL_use_PrivateKey_ASN1"},
 {ERR_FUNC(SSL_F_SSL_USE_PRIVATEKEY_FILE),      "SSL_use_PrivateKey_file"},
+{ERR_FUNC(SSL_F_SSL_USE_PSK_IDENTITY_HINT),    "SSL_use_psk_identity_hint"},
 {ERR_FUNC(SSL_F_SSL_USE_RSAPRIVATEKEY),        "SSL_use_RSAPrivateKey"},
 {ERR_FUNC(SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1),   "SSL_use_RSAPrivateKey_ASN1"},
 {ERR_FUNC(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE),   "SSL_use_RSAPrivateKey_file"},
 {ERR_FUNC(SSL_F_SSL_VERIFY_CERT_CHAIN),        "SSL_VERIFY_CERT_CHAIN"},
 {ERR_FUNC(SSL_F_SSL_WRITE),    "SSL_write"},
+{ERR_FUNC(SSL_F_TLS1_CERT_VERIFY_MAC), "tls1_cert_verify_mac"},
 {ERR_FUNC(SSL_F_TLS1_CHANGE_CIPHER_STATE),     "TLS1_CHANGE_CIPHER_STATE"},
+{ERR_FUNC(SSL_F_TLS1_CHECK_SERVERHELLO_TLSEXT),        "TLS1_CHECK_SERVERHELLO_TLSEXT"},
 {ERR_FUNC(SSL_F_TLS1_ENC),     "TLS1_ENC"},
+{ERR_FUNC(SSL_F_TLS1_PREPARE_CLIENTHELLO_TLSEXT),      "TLS1_PREPARE_CLIENTHELLO_TLSEXT"},
+{ERR_FUNC(SSL_F_TLS1_PREPARE_SERVERHELLO_TLSEXT),      "TLS1_PREPARE_SERVERHELLO_TLSEXT"},
+{ERR_FUNC(SSL_F_TLS1_PRF),     "tls1_prf"},
 {ERR_FUNC(SSL_F_TLS1_SETUP_KEY_BLOCK), "TLS1_SETUP_KEY_BLOCK"},
 {ERR_FUNC(SSL_F_WRITE_PENDING),        "WRITE_PENDING"},
 {0,NULL}
@@ -285,12 +297,15 @@ static ERR_STRING_DATA SSL_str_reasons[]=
 {ERR_REASON(SSL_R_BAD_ECC_CERT)          ,"bad ecc cert"},
 {ERR_REASON(SSL_R_BAD_ECDSA_SIGNATURE)   ,"bad ecdsa signature"},
 {ERR_REASON(SSL_R_BAD_ECPOINT)           ,"bad ecpoint"},
+{ERR_REASON(SSL_R_BAD_HANDSHAKE_LENGTH)  ,"bad handshake length"},
 {ERR_REASON(SSL_R_BAD_HELLO_REQUEST)     ,"bad hello request"},
 {ERR_REASON(SSL_R_BAD_LENGTH)            ,"bad length"},
 {ERR_REASON(SSL_R_BAD_MAC_DECODE)        ,"bad mac decode"},
+{ERR_REASON(SSL_R_BAD_MAC_LENGTH)        ,"bad mac length"},
 {ERR_REASON(SSL_R_BAD_MESSAGE_TYPE)      ,"bad message type"},
 {ERR_REASON(SSL_R_BAD_PACKET_LENGTH)     ,"bad packet length"},
 {ERR_REASON(SSL_R_BAD_PROTOCOL_VERSION_NUMBER),"bad protocol version number"},
+{ERR_REASON(SSL_R_BAD_PSK_IDENTITY_HINT_LENGTH),"bad psk identity hint length"},
 {ERR_REASON(SSL_R_BAD_RESPONSE_ARGUMENT) ,"bad response argument"},
 {ERR_REASON(SSL_R_BAD_RSA_DECRYPT)       ,"bad rsa decrypt"},
 {ERR_REASON(SSL_R_BAD_RSA_ENCRYPT)       ,"bad rsa encrypt"},
@@ -316,6 +331,7 @@ static ERR_STRING_DATA SSL_str_reasons[]=
 {ERR_REASON(SSL_R_CIPHER_TABLE_SRC_ERROR),"cipher table src error"},
 {ERR_REASON(SSL_R_CLIENTHELLO_TLSEXT)    ,"clienthello tlsext"},
 {ERR_REASON(SSL_R_COMPRESSED_LENGTH_TOO_LONG),"compressed length too long"},
+{ERR_REASON(SSL_R_COMPRESSION_DISABLED)  ,"compression disabled"},
 {ERR_REASON(SSL_R_COMPRESSION_FAILURE)   ,"compression failure"},
 {ERR_REASON(SSL_R_COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE),"compression id not within private range"},
 {ERR_REASON(SSL_R_COMPRESSION_LIBRARY_ERROR),"compression library error"},
@@ -330,6 +346,10 @@ static ERR_STRING_DATA SSL_str_reasons[]=
 {ERR_REASON(SSL_R_DIGEST_CHECK_FAILED)   ,"digest check failed"},
 {ERR_REASON(SSL_R_DTLS_MESSAGE_TOO_BIG)  ,"dtls message too big"},
 {ERR_REASON(SSL_R_DUPLICATE_COMPRESSION_ID),"duplicate compression id"},
+{ERR_REASON(SSL_R_ECC_CERT_NOT_FOR_KEY_AGREEMENT),"ecc cert not for key agreement"},
+{ERR_REASON(SSL_R_ECC_CERT_NOT_FOR_SIGNING),"ecc cert not for signing"},
+{ERR_REASON(SSL_R_ECC_CERT_SHOULD_HAVE_RSA_SIGNATURE),"ecc cert should have rsa signature"},
+{ERR_REASON(SSL_R_ECC_CERT_SHOULD_HAVE_SHA1_SIGNATURE),"ecc cert should have sha1 signature"},
 {ERR_REASON(SSL_R_ECGROUP_TOO_LARGE_FOR_CIPHER),"ecgroup too large for cipher"},
 {ERR_REASON(SSL_R_ENCRYPTED_LENGTH_TOO_LONG),"encrypted length too long"},
 {ERR_REASON(SSL_R_ERROR_GENERATING_TMP_RSA_KEY),"error generating tmp rsa key"},
@@ -342,8 +362,10 @@ static ERR_STRING_DATA SSL_str_reasons[]=
 {ERR_REASON(SSL_R_HTTPS_PROXY_REQUEST)   ,"https proxy request"},
 {ERR_REASON(SSL_R_HTTP_REQUEST)          ,"http request"},
 {ERR_REASON(SSL_R_ILLEGAL_PADDING)       ,"illegal padding"},
+{ERR_REASON(SSL_R_INCONSISTENT_COMPRESSION),"inconsistent compression"},
 {ERR_REASON(SSL_R_INVALID_CHALLENGE_LENGTH),"invalid challenge length"},
 {ERR_REASON(SSL_R_INVALID_COMMAND)       ,"invalid command"},
+{ERR_REASON(SSL_R_INVALID_COMPRESSION_ALGORITHM),"invalid compression algorithm"},
 {ERR_REASON(SSL_R_INVALID_PURPOSE)       ,"invalid purpose"},
 {ERR_REASON(SSL_R_INVALID_STATUS_RESPONSE),"invalid status response"},
 {ERR_REASON(SSL_R_INVALID_TICKET_KEYS_LENGTH),"invalid ticket keys length"},
@@ -379,6 +401,7 @@ static ERR_STRING_DATA SSL_str_reasons[]=
 {ERR_REASON(SSL_R_MISSING_TMP_RSA_KEY)   ,"missing tmp rsa key"},
 {ERR_REASON(SSL_R_MISSING_TMP_RSA_PKEY)  ,"missing tmp rsa pkey"},
 {ERR_REASON(SSL_R_MISSING_VERIFY_MESSAGE),"missing verify message"},
+{ERR_REASON(SSL_R_MULTIPLE_SGC_RESTARTS) ,"multiple sgc restarts"},
 {ERR_REASON(SSL_R_NON_SSLV2_INITIAL_PACKET),"non sslv2 initial packet"},
 {ERR_REASON(SSL_R_NO_CERTIFICATES_RETURNED),"no certificates returned"},
 {ERR_REASON(SSL_R_NO_CERTIFICATE_ASSIGNED),"no certificate assigned"},
@@ -393,18 +416,22 @@ static ERR_STRING_DATA SSL_str_reasons[]=
 {ERR_REASON(SSL_R_NO_CLIENT_CERT_METHOD) ,"no client cert method"},
 {ERR_REASON(SSL_R_NO_CLIENT_CERT_RECEIVED),"no client cert received"},
 {ERR_REASON(SSL_R_NO_COMPRESSION_SPECIFIED),"no compression specified"},
+{ERR_REASON(SSL_R_NO_GOST_CERTIFICATE_SENT_BY_PEER),"Peer haven't sent GOST certificate, required for selected ciphersuite"},
 {ERR_REASON(SSL_R_NO_METHOD_SPECIFIED)   ,"no method specified"},
 {ERR_REASON(SSL_R_NO_PRIVATEKEY)         ,"no privatekey"},
 {ERR_REASON(SSL_R_NO_PRIVATE_KEY_ASSIGNED),"no private key assigned"},
 {ERR_REASON(SSL_R_NO_PROTOCOLS_AVAILABLE),"no protocols available"},
 {ERR_REASON(SSL_R_NO_PUBLICKEY)          ,"no publickey"},
 {ERR_REASON(SSL_R_NO_RENEGOTIATION)      ,"no renegotiation"},
+{ERR_REASON(SSL_R_NO_REQUIRED_DIGEST)    ,"digest requred for handshake isn't computed"},
 {ERR_REASON(SSL_R_NO_SHARED_CIPHER)      ,"no shared cipher"},
 {ERR_REASON(SSL_R_NO_VERIFY_CALLBACK)    ,"no verify callback"},
 {ERR_REASON(SSL_R_NULL_SSL_CTX)          ,"null ssl ctx"},
 {ERR_REASON(SSL_R_NULL_SSL_METHOD_PASSED),"null ssl method passed"},
 {ERR_REASON(SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED),"old session cipher not returned"},
+{ERR_REASON(SSL_R_OLD_SESSION_COMPRESSION_ALGORITHM_NOT_RETURNED),"old session compression algorithm not returned"},
 {ERR_REASON(SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE),"only tls allowed in fips mode"},
+{ERR_REASON(SSL_R_OPAQUE_PRF_INPUT_TOO_LONG),"opaque PRF input too long"},
 {ERR_REASON(SSL_R_PACKET_LENGTH_TOO_LONG),"packet length too long"},
 {ERR_REASON(SSL_R_PARSE_TLSEXT)          ,"parse tlsext"},
 {ERR_REASON(SSL_R_PATH_TOO_LONG)         ,"path too long"},
@@ -417,6 +444,9 @@ static ERR_STRING_DATA SSL_str_reasons[]=
 {ERR_REASON(SSL_R_PRE_MAC_LENGTH_TOO_LONG),"pre mac length too long"},
 {ERR_REASON(SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS),"problems mapping cipher functions"},
 {ERR_REASON(SSL_R_PROTOCOL_IS_SHUTDOWN)  ,"protocol is shutdown"},
+{ERR_REASON(SSL_R_PSK_IDENTITY_NOT_FOUND),"psk identity not found"},
+{ERR_REASON(SSL_R_PSK_NO_CLIENT_CB)      ,"psk no client cb"},
+{ERR_REASON(SSL_R_PSK_NO_SERVER_CB)      ,"psk no server cb"},
 {ERR_REASON(SSL_R_PUBLIC_KEY_ENCRYPT_ERROR),"public key encrypt error"},
 {ERR_REASON(SSL_R_PUBLIC_KEY_IS_NOT_RSA) ,"public key is not rsa"},
 {ERR_REASON(SSL_R_PUBLIC_KEY_NOT_RSA)    ,"public key not rsa"},
@@ -430,16 +460,19 @@ static ERR_STRING_DATA SSL_str_reasons[]=
 {ERR_REASON(SSL_R_RENEGOTIATION_ENCODING_ERR),"renegotiation encoding err"},
 {ERR_REASON(SSL_R_RENEGOTIATION_MISMATCH),"renegotiation mismatch"},
 {ERR_REASON(SSL_R_REQUIRED_CIPHER_MISSING),"required cipher missing"},
+{ERR_REASON(SSL_R_REQUIRED_COMPRESSSION_ALGORITHM_MISSING),"required compresssion algorithm missing"},
 {ERR_REASON(SSL_R_REUSE_CERT_LENGTH_NOT_ZERO),"reuse cert length not zero"},
 {ERR_REASON(SSL_R_REUSE_CERT_TYPE_NOT_ZERO),"reuse cert type not zero"},
 {ERR_REASON(SSL_R_REUSE_CIPHER_LIST_NOT_ZERO),"reuse cipher list not zero"},
 {ERR_REASON(SSL_R_SCSV_RECEIVED_WHEN_RENEGOTIATING),"scsv received when renegotiating"},
 {ERR_REASON(SSL_R_SERVERHELLO_TLSEXT)    ,"serverhello tlsext"},
 {ERR_REASON(SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED),"session id context uninitialized"},
+{ERR_REASON(SSL_R_SESSION_MAY_NOT_BE_CREATED),"session may not be created"},
 {ERR_REASON(SSL_R_SHORT_READ)            ,"short read"},
 {ERR_REASON(SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE),"signature for non signing certificate"},
 {ERR_REASON(SSL_R_SSL23_DOING_SESSION_ID_REUSE),"ssl23 doing session id reuse"},
 {ERR_REASON(SSL_R_SSL2_CONNECTION_ID_TOO_LONG),"ssl2 connection id too long"},
+{ERR_REASON(SSL_R_SSL3_EXT_INVALID_ECPOINTFORMAT),"ssl3 ext invalid ecpointformat"},
 {ERR_REASON(SSL_R_SSL3_EXT_INVALID_SERVERNAME),"ssl3 ext invalid servername"},
 {ERR_REASON(SSL_R_SSL3_EXT_INVALID_SERVERNAME_TYPE),"ssl3 ext invalid servername type"},
 {ERR_REASON(SSL_R_SSL3_SESSION_ID_TOO_LONG),"ssl3 session id too long"},
@@ -475,6 +508,11 @@ static ERR_STRING_DATA SSL_str_reasons[]=
 {ERR_REASON(SSL_R_TLSV1_ALERT_RECORD_OVERFLOW),"tlsv1 alert record overflow"},
 {ERR_REASON(SSL_R_TLSV1_ALERT_UNKNOWN_CA),"tlsv1 alert unknown ca"},
 {ERR_REASON(SSL_R_TLSV1_ALERT_USER_CANCELLED),"tlsv1 alert user cancelled"},
+{ERR_REASON(SSL_R_TLSV1_BAD_CERTIFICATE_HASH_VALUE),"tlsv1 bad certificate hash value"},
+{ERR_REASON(SSL_R_TLSV1_BAD_CERTIFICATE_STATUS_RESPONSE),"tlsv1 bad certificate status response"},
+{ERR_REASON(SSL_R_TLSV1_CERTIFICATE_UNOBTAINABLE),"tlsv1 certificate unobtainable"},
+{ERR_REASON(SSL_R_TLSV1_UNRECOGNIZED_NAME),"tlsv1 unrecognized name"},
+{ERR_REASON(SSL_R_TLSV1_UNSUPPORTED_EXTENSION),"tlsv1 unsupported extension"},
 {ERR_REASON(SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER),"tls client cert req with anon cipher"},
 {ERR_REASON(SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST),"tls invalid ecpointformat list"},
 {ERR_REASON(SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST),"tls peer did not respond with certificate list"},
@@ -506,6 +544,7 @@ static ERR_STRING_DATA SSL_str_reasons[]=
 {ERR_REASON(SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED),"unsafe legacy renegotiation disabled"},
 {ERR_REASON(SSL_R_UNSUPPORTED_CIPHER)    ,"unsupported cipher"},
 {ERR_REASON(SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM),"unsupported compression algorithm"},
+{ERR_REASON(SSL_R_UNSUPPORTED_DIGEST_TYPE),"unsupported digest type"},
 {ERR_REASON(SSL_R_UNSUPPORTED_ELLIPTIC_CURVE),"unsupported elliptic curve"},
 {ERR_REASON(SSL_R_UNSUPPORTED_PROTOCOL)  ,"unsupported protocol"},
 {ERR_REASON(SSL_R_UNSUPPORTED_SSL_VERSION),"unsupported ssl version"},
index 51bcc73..add3058 100644 (file)
@@ -58,7 +58,7 @@
  * [including the GNU Public Licence.]
  */
 /* ====================================================================
- * Copyright (c) 1998-2001 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2007 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * ECC cipher suite support in OpenSSL originally developed by 
  * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
  */
+/* ====================================================================
+ * Copyright 2005 Nokia. All rights reserved.
+ *
+ * The portions of the attached software ("Contribution") is developed by
+ * Nokia Corporation and is licensed pursuant to the OpenSSL open source
+ * license.
+ *
+ * The Contribution, originally written by Mika Kousa and Pasi Eronen of
+ * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
+ * support (see RFC 4279) to OpenSSL.
+ *
+ * No patent licenses or other rights except those expressly stated in
+ * the OpenSSL open source license shall be deemed granted or received
+ * expressly, by implication, estoppel, or otherwise.
+ *
+ * No assurances are provided by Nokia that the Contribution does not
+ * infringe the patent or other intellectual property rights of any third
+ * party or that the license provides you with all the necessary rights
+ * to make use of the Contribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
+ * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
+ * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
+ * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
+ * OTHERWISE.
+ */
 
 #ifdef REF_CHECK
 #  include <assert.h>
@@ -143,9 +169,9 @@ SSL3_ENC_METHOD ssl3_undef_enc_method={
        ssl_undefined_function,
        (int (*)(SSL *, unsigned char *, unsigned char *, int))ssl_undefined_function,
        (int (*)(SSL*, int))ssl_undefined_function,
-       (int (*)(SSL *, EVP_MD_CTX *, EVP_MD_CTX *, const char*, int, unsigned char *))ssl_undefined_function,
+       (int (*)(SSL *,  const char*, int, unsigned char *))ssl_undefined_function,
        0,      /* finish_mac_length */
-       (int (*)(SSL *, EVP_MD_CTX *, unsigned char *))ssl_undefined_function,
+       (int (*)(SSL *, int, unsigned char *))ssl_undefined_function,
        NULL,   /* client_finished_label */
        0,      /* client_finished_label_len */
        NULL,   /* server_finished_label */
@@ -204,6 +230,8 @@ int SSL_clear(SSL *s)
                }
 
        ssl_clear_cipher_ctx(s);
+       ssl_clear_hash_ctx(&s->read_hash);
+       ssl_clear_hash_ctx(&s->write_hash);
 
        s->first_packet=0;
 
@@ -224,14 +252,15 @@ int SSL_clear(SSL *s)
        }
 
 /** Used to change an SSL_CTXs default SSL method type */
-int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth)
+int SSL_CTX_set_ssl_version(SSL_CTX *ctx,const SSL_METHOD *meth)
        {
        STACK_OF(SSL_CIPHER) *sk;
 
        ctx->method=meth;
 
        sk=ssl_create_cipher_list(ctx->method,&(ctx->cipher_list),
-               &(ctx->cipher_list_by_id),SSL_DEFAULT_CIPHER_LIST);
+               &(ctx->cipher_list_by_id),
+               meth->version == SSL2_VERSION ? "SSLv2" : SSL_DEFAULT_CIPHER_LIST);
        if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= 0))
                {
                SSLerr(SSL_F_SSL_CTX_SET_SSL_VERSION,SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS);
@@ -297,6 +326,7 @@ SSL *SSL_new(SSL_CTX *ctx)
        OPENSSL_assert(s->sid_ctx_length <= sizeof s->sid_ctx);
        memcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx));
        s->verify_callback=ctx->default_verify_callback;
+       s->session_creation_enabled=1;
        s->generate_session_id=ctx->generate_session_id;
 
        s->param = X509_VERIFY_PARAM_new();
@@ -308,6 +338,7 @@ SSL *SSL_new(SSL_CTX *ctx)
        s->trust = ctx->trust;
 #endif
        s->quiet_shutdown=ctx->quiet_shutdown;
+       s->max_send_fragment = ctx->max_send_fragment;
 
        CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);
        s->ctx=ctx;
@@ -323,8 +354,11 @@ SSL *SSL_new(SSL_CTX *ctx)
        s->tlsext_ocsp_resplen = -1;
        CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);
        s->initial_ctx=ctx;
+# ifndef OPENSSL_NO_NEXTPROTONEG
        s->next_proto_negotiated = NULL;
+# endif
 #endif
+
        s->verify_result=X509_V_OK;
 
        s->method=ctx->method;
@@ -339,6 +373,11 @@ SSL *SSL_new(SSL_CTX *ctx)
 
        CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);
 
+#ifndef OPENSSL_NO_PSK
+       s->psk_client_callback=ctx->psk_client_callback;
+       s->psk_server_callback=ctx->psk_server_callback;
+#endif
+
        return(s);
 err:
        if (s != NULL)
@@ -426,7 +465,7 @@ int SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id,
                }
 
        CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
-       p = (SSL_SESSION *)lh_retrieve(ssl->ctx->sessions, &r);
+       p = lh_SSL_SESSION_retrieve(ssl->ctx->sessions, &r);
        CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
        return (p != NULL);
        }
@@ -451,6 +490,16 @@ int SSL_set_trust(SSL *s, int trust)
        return X509_VERIFY_PARAM_set_trust(s->param, trust);
        }
 
+int SSL_CTX_set1_param(SSL_CTX *ctx, X509_VERIFY_PARAM *vpm)
+       {
+       return X509_VERIFY_PARAM_set1(ctx->param, vpm);
+       }
+
+int SSL_set1_param(SSL *ssl, X509_VERIFY_PARAM *vpm)
+       {
+       return X509_VERIFY_PARAM_set1(ssl->param, vpm);
+       }
+
 void SSL_free(SSL *s)
        {
        int i;
@@ -505,6 +554,8 @@ void SSL_free(SSL *s)
                }
 
        ssl_clear_cipher_ctx(s);
+       ssl_clear_hash_ctx(&s->read_hash);
+       ssl_clear_hash_ctx(&s->write_hash);
 
        if (s->cert != NULL) ssl_cert_free(s->cert);
        /* Free up if allocated */
@@ -513,6 +564,11 @@ void SSL_free(SSL *s)
        if (s->tlsext_hostname)
                OPENSSL_free(s->tlsext_hostname);
        if (s->initial_ctx) SSL_CTX_free(s->initial_ctx);
+#ifndef OPENSSL_NO_EC
+       if (s->tlsext_ecpointformatlist) OPENSSL_free(s->tlsext_ecpointformatlist);
+       if (s->tlsext_ellipticcurvelist) OPENSSL_free(s->tlsext_ellipticcurvelist);
+#endif /* OPENSSL_NO_EC */
+       if (s->tlsext_opaque_prf_input) OPENSSL_free(s->tlsext_opaque_prf_input);
        if (s->tlsext_ocsp_exts)
                sk_X509_EXTENSION_pop_free(s->tlsext_ocsp_exts,
                                                X509_EXTENSION_free);
@@ -521,6 +577,7 @@ void SSL_free(SSL *s)
        if (s->tlsext_ocsp_resp)
                OPENSSL_free(s->tlsext_ocsp_resp);
 #endif
+
        if (s->client_CA != NULL)
                sk_X509_NAME_pop_free(s->client_CA,X509_NAME_free);
 
@@ -533,7 +590,7 @@ void SSL_free(SSL *s)
                kssl_ctx_free(s->kssl_ctx);
 #endif /* OPENSSL_NO_KRB5 */
 
-#ifndef OPENSSL_NO_TLSEXT
+#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
        if (s->next_proto_negotiated)
                OPENSSL_free(s->next_proto_negotiated);
 #endif
@@ -850,7 +907,7 @@ int SSL_check_private_key(const SSL *ssl)
                }
        if (ssl->cert == NULL)
                {
-                SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED);
+               SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED);
                return 0;
                }
        if (ssl->cert->key->x509 == NULL)
@@ -1006,6 +1063,11 @@ long SSL_ctrl(SSL *s,int cmd,long larg,void *parg)
                s->max_cert_list=larg;
                return(l);
        case SSL_CTRL_SET_MTU:
+#ifndef OPENSSL_NO_DTLS1
+               if (larg < (long)dtls1_min_mtu())
+                       return 0;
+#endif
+
                if (SSL_version(s) == DTLS1_VERSION ||
                    SSL_version(s) == DTLS1_BAD_VER)
                        {
@@ -1013,6 +1075,11 @@ long SSL_ctrl(SSL *s,int cmd,long larg,void *parg)
                        return larg;
                        }
                return 0;
+       case SSL_CTRL_SET_MAX_SEND_FRAGMENT:
+               if (larg < 512 || larg > SSL3_RT_MAX_PLAIN_LENGTH)
+                       return 0;
+               s->max_send_fragment = larg;
+               return 1;
        case SSL_CTRL_GET_RI_SUPPORT:
                if (s->s3)
                        return s->s3->send_connection_binding;
@@ -1035,7 +1102,7 @@ long SSL_callback_ctrl(SSL *s, int cmd, void (*fp)(void))
                }
        }
 
-struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx)
+LHASH_OF(SSL_SESSION) *SSL_CTX_sessions(SSL_CTX *ctx)
        {
        return ctx->sessions;
        }
@@ -1078,7 +1145,7 @@ long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd,long larg,void *parg)
                return(ctx->session_cache_mode);
 
        case SSL_CTRL_SESS_NUMBER:
-               return(ctx->sessions->num_items);
+               return(lh_SSL_SESSION_num_items(ctx->sessions));
        case SSL_CTRL_SESS_CONNECT:
                return(ctx->stats.sess_connect);
        case SSL_CTRL_SESS_CONNECT_GOOD:
@@ -1109,6 +1176,11 @@ long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd,long larg,void *parg)
                return(ctx->mode|=larg);
        case SSL_CTRL_CLEAR_MODE:
                return(ctx->mode&=~larg);
+       case SSL_CTRL_SET_MAX_SEND_FRAGMENT:
+               if (larg < 512 || larg > SSL3_RT_MAX_PLAIN_LENGTH)
+                       return 0;
+               ctx->max_send_fragment = larg;
+               return 1;
        default:
                return(ctx->method->ssl_ctx_ctrl(ctx,cmd,larg,parg));
                }
@@ -1213,8 +1285,8 @@ int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str)
        /* ssl_create_cipher_list may return an empty stack if it
         * was unable to find a cipher matching the given rule string
         * (for example if the rule string specifies a cipher which
-        * has been disabled). This is not an error as far as 
-        * ssl_create_cipher_list is concerned, and hence 
+        * has been disabled). This is not an error as far as
+        * ssl_create_cipher_list is concerned, and hence
         * ctx->cipher_list and ctx->cipher_list_by_id has been
         * updated. */
        if (sk == NULL)
@@ -1245,6 +1317,32 @@ int SSL_set_cipher_list(SSL *s,const char *str)
        return 1;
        }
 
+/** specify the ciphers to be used by the SSL */
+int SSL_set_cipher_lists(SSL *s,STACK_OF(SSL_CIPHER) *sk)
+       {
+       STACK_OF(SSL_CIPHER) *tmp_cipher_list;
+
+       if (sk == NULL)
+               return 0;
+
+        /* Based on end of ssl_create_cipher_list */
+       tmp_cipher_list = sk_SSL_CIPHER_dup(sk);
+       if (tmp_cipher_list == NULL)
+               {
+               return 0;
+               }
+       if (s->cipher_list != NULL)
+               sk_SSL_CIPHER_free(s->cipher_list);
+       s->cipher_list = sk;
+       if (s->cipher_list_by_id != NULL)
+               sk_SSL_CIPHER_free(s->cipher_list_by_id);
+       s->cipher_list_by_id = tmp_cipher_list;
+       (void)sk_SSL_CIPHER_set_cmp_func(s->cipher_list_by_id,ssl_cipher_ptr_id_cmp);
+
+       sk_SSL_CIPHER_sort(s->cipher_list_by_id);
+       return 1;
+       }
+
 /* works well for SSLv2, not so good for SSLv3 */
 char *SSL_get_shared_ciphers(const SSL *s,char *buf,int len)
        {
@@ -1282,13 +1380,13 @@ char *SSL_get_shared_ciphers(const SSL *s,char *buf,int len)
        }
 
 int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p,
-                             int (*put_cb)(const SSL_CIPHER *, unsigned char *))
+                            int (*put_cb)(const SSL_CIPHER *, unsigned char *))
        {
        int i,j=0;
        SSL_CIPHER *c;
        unsigned char *q;
 #ifndef OPENSSL_NO_KRB5
-        int nokrb5 = !kssl_tgt_is_available(s->kssl_ctx);
+       int nokrb5 = !kssl_tgt_is_available(s->kssl_ctx);
 #endif /* OPENSSL_NO_KRB5 */
 
        if (sk == NULL) return(0);
@@ -1298,10 +1396,16 @@ int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p,
                {
                c=sk_SSL_CIPHER_value(sk,i);
 #ifndef OPENSSL_NO_KRB5
-                if ((c->algorithms & SSL_KRB5) && nokrb5)
-                    continue;
-#endif /* OPENSSL_NO_KRB5 */                    
-
+               if (((c->algorithm_mkey & SSL_kKRB5) || (c->algorithm_auth & SSL_aKRB5)) &&
+                   nokrb5)
+                   continue;
+#endif /* OPENSSL_NO_KRB5 */
+#ifndef OPENSSL_NO_PSK
+               /* with PSK there must be client callback set */
+               if (((c->algorithm_mkey & SSL_kPSK) || (c->algorithm_auth & SSL_aPSK)) &&
+                   s->psk_client_callback == NULL)
+                       continue;
+#endif /* OPENSSL_NO_PSK */
                j = put_cb ? put_cb(c,p) : ssl_put_cipher_by_char(s,c,p);
                p+=j;
                }
@@ -1312,7 +1416,7 @@ int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p,
                {
                static SSL_CIPHER scsv =
                        {
-                       0, NULL, SSL3_CK_SCSV, 0, 0, 0, 0, 0, 0, 0,
+                       0, NULL, SSL3_CK_SCSV, 0, 0, 0, 0, 0, 0, 0, 0, 0
                        };
                j = put_cb ? put_cb(&scsv,p) : ssl_put_cipher_by_char(s,&scsv,p);
                p+=j;
@@ -1327,7 +1431,7 @@ int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p,
 STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num,
                                               STACK_OF(SSL_CIPHER) **skp)
        {
-       SSL_CIPHER *c;
+       const SSL_CIPHER *c;
        STACK_OF(SSL_CIPHER) *sk;
        int i,n;
        if (s->s3)
@@ -1390,6 +1494,7 @@ err:
        return(NULL);
        }
 
+
 #ifndef OPENSSL_NO_TLSEXT
 /** return a servername extension value if provided in Client Hello, or NULL.
  * So far, only host_name types are defined (RFC 3546).
@@ -1411,9 +1516,127 @@ int SSL_get_servername_type(const SSL *s)
                return TLSEXT_NAMETYPE_host_name;
        return -1;
        }
+
+# ifndef OPENSSL_NO_NEXTPROTONEG
+/* SSL_select_next_proto implements the standard protocol selection. It is
+ * expected that this function is called from the callback set by
+ * SSL_CTX_set_next_proto_select_cb.
+ *
+ * The protocol data is assumed to be a vector of 8-bit, length prefixed byte
+ * strings. The length byte itself is not included in the length. A byte
+ * string of length 0 is invalid. No byte string may be truncated.
+ *
+ * The current, but experimental algorithm for selecting the protocol is:
+ *
+ * 1) If the server doesn't support NPN then this is indicated to the
+ * callback. In this case, the client application has to abort the connection
+ * or have a default application level protocol.
+ *
+ * 2) If the server supports NPN, but advertises an empty list then the
+ * client selects the first protcol in its list, but indicates via the
+ * API that this fallback case was enacted.
+ *
+ * 3) Otherwise, the client finds the first protocol in the server's list
+ * that it supports and selects this protocol. This is because it's
+ * assumed that the server has better information about which protocol
+ * a client should use.
+ *
+ * 4) If the client doesn't support any of the server's advertised
+ * protocols, then this is treated the same as case 2.
+ *
+ * It returns either
+ * OPENSSL_NPN_NEGOTIATED if a common protocol was found, or
+ * OPENSSL_NPN_NO_OVERLAP if the fallback case was reached.
+ */
+int SSL_select_next_proto(unsigned char **out, unsigned char *outlen, const unsigned char *server, unsigned int server_len, const unsigned char *client, unsigned int client_len)
+       {
+       unsigned int i, j;
+       const unsigned char *result;
+       int status = OPENSSL_NPN_UNSUPPORTED;
+
+       /* For each protocol in server preference order, see if we support it. */
+       for (i = 0; i < server_len; )
+               {
+               for (j = 0; j < client_len; )
+                       {
+                       if (server[i] == client[j] &&
+                           memcmp(&server[i+1], &client[j+1], server[i]) == 0)
+                               {
+                               /* We found a match */
+                               result = &server[i];
+                               status = OPENSSL_NPN_NEGOTIATED;
+                               goto found;
+                               }
+                       j += client[j];
+                       j++;
+                       }
+               i += server[i];
+               i++;
+               }
+
+       /* There's no overlap between our protocols and the server's list. */
+       result = client;
+       status = OPENSSL_NPN_NO_OVERLAP;
+
+       found:
+       *out = (unsigned char *) result + 1;
+       *outlen = result[0];
+       return status;
+       }
+
+/* SSL_get0_next_proto_negotiated sets *data and *len to point to the client's
+ * requested protocol for this connection and returns 0. If the client didn't
+ * request any protocol, then *data is set to NULL.
+ *
+ * Note that the client can request any protocol it chooses. The value returned
+ * from this function need not be a member of the list of supported protocols
+ * provided by the callback.
+ */
+void SSL_get0_next_proto_negotiated(const SSL *s, const unsigned char **data, unsigned *len)
+       {
+       *data = s->next_proto_negotiated;
+       if (!*data) {
+               *len = 0;
+       } else {
+               *len = s->next_proto_negotiated_len;
+       }
+}
+
+/* SSL_CTX_set_next_protos_advertised_cb sets a callback that is called when a
+ * TLS server needs a list of supported protocols for Next Protocol
+ * Negotiation. The returned list must be in wire format.  The list is returned
+ * by setting |out| to point to it and |outlen| to its length. This memory will
+ * not be modified, but one should assume that the SSL* keeps a reference to
+ * it.
+ *
+ * The callback should return SSL_TLSEXT_ERR_OK if it wishes to advertise. Otherwise, no
+ * such extension will be included in the ServerHello. */
+void SSL_CTX_set_next_protos_advertised_cb(SSL_CTX *ctx, int (*cb) (SSL *ssl, const unsigned char **out, unsigned int *outlen, void *arg), void *arg)
+       {
+       ctx->next_protos_advertised_cb = cb;
+       ctx->next_protos_advertised_cb_arg = arg;
+       }
+
+/* SSL_CTX_set_next_proto_select_cb sets a callback that is called when a
+ * client needs to select a protocol from the server's provided list. |out|
+ * must be set to point to the selected protocol (which may be within |in|).
+ * The length of the protocol name must be written into |outlen|. The server's
+ * advertised protocols are provided in |in| and |inlen|. The callback can
+ * assume that |in| is syntactically valid.
+ *
+ * The client must select a protocol. It is fatal to the connection if this
+ * callback returns a value other than SSL_TLSEXT_ERR_OK.
+ */
+void SSL_CTX_set_next_proto_select_cb(SSL_CTX *ctx, int (*cb) (SSL *s, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg), void *arg)
+       {
+       ctx->next_proto_select_cb = cb;
+       ctx->next_proto_select_cb_arg = arg;
+       }
+
+# endif
 #endif
 
-unsigned long SSL_SESSION_hash(const SSL_SESSION *a)
+static unsigned long ssl_session_hash(const SSL_SESSION *a)
        {
        unsigned long l;
 
@@ -1430,7 +1653,7 @@ unsigned long SSL_SESSION_hash(const SSL_SESSION *a)
  * SSL_CTX_has_matching_session_id() is checked accordingly. It relies on being
  * able to construct an SSL_SESSION that will collide with any existing session
  * with a matching session ID. */
-int SSL_SESSION_cmp(const SSL_SESSION *a,const SSL_SESSION *b)
+static int ssl_session_cmp(const SSL_SESSION *a,const SSL_SESSION *b)
        {
        if (a->ssl_version != b->ssl_version)
                return(1);
@@ -1443,27 +1666,19 @@ int SSL_SESSION_cmp(const SSL_SESSION *a,const SSL_SESSION *b)
  * SSL_SESSION_hash and SSL_SESSION_cmp for void* types and casting each
  * variable. The reason is that the functions aren't static, they're exposed via
  * ssl.h. */
-static IMPLEMENT_LHASH_HASH_FN(SSL_SESSION_hash, SSL_SESSION *)
-static IMPLEMENT_LHASH_COMP_FN(SSL_SESSION_cmp, SSL_SESSION *)
+static IMPLEMENT_LHASH_HASH_FN(ssl_session, SSL_SESSION)
+static IMPLEMENT_LHASH_COMP_FN(ssl_session, SSL_SESSION)
 
-SSL_CTX *SSL_CTX_new(SSL_METHOD *meth)
+SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth)
        {
        SSL_CTX *ret=NULL;
-       
+
        if (meth == NULL)
                {
                SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_NULL_SSL_METHOD_PASSED);
                return(NULL);
                }
 
-#ifdef OPENSSL_FIPS
-       if (FIPS_mode() && (meth->version < TLS1_VERSION))      
-               {
-               SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE);
-               return NULL;
-               }
-#endif
-
        if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0)
                {
                SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS);
@@ -1526,15 +1741,14 @@ SSL_CTX *SSL_CTX_new(SSL_METHOD *meth)
        ret->app_gen_cookie_cb=0;
        ret->app_verify_cookie_cb=0;
 
-       ret->sessions=lh_new(LHASH_HASH_FN(SSL_SESSION_hash),
-                       LHASH_COMP_FN(SSL_SESSION_cmp));
+       ret->sessions=lh_SSL_SESSION_new();
        if (ret->sessions == NULL) goto err;
        ret->cert_store=X509_STORE_new();
        if (ret->cert_store == NULL) goto err;
 
        ssl_create_cipher_list(ret->method,
                &ret->cipher_list,&ret->cipher_list_by_id,
-               SSL_DEFAULT_CIPHER_LIST);
+               meth->version == SSL2_VERSION ? "SSLv2" : SSL_DEFAULT_CIPHER_LIST);
        if (ret->cipher_list == NULL
            || sk_SSL_CIPHER_num(ret->cipher_list) <= 0)
                {
@@ -1570,6 +1784,8 @@ SSL_CTX *SSL_CTX_new(SSL_METHOD *meth)
        ret->extra_certs=NULL;
        ret->comp_methods=SSL_COMP_get_compression_methods();
 
+       ret->max_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH;
+
 #ifndef OPENSSL_NO_TLSEXT
        ret->tlsext_servername_callback = 0;
        ret->tlsext_servername_arg = NULL;
@@ -1582,10 +1798,34 @@ SSL_CTX *SSL_CTX_new(SSL_METHOD *meth)
        ret->tlsext_status_cb = 0;
        ret->tlsext_status_arg = NULL;
 
+# ifndef OPENSSL_NO_NEXTPROTONEG
        ret->next_protos_advertised_cb = 0;
        ret->next_proto_select_cb = 0;
+# endif
+#endif
+#ifndef OPENSSL_NO_PSK
+       ret->psk_identity_hint=NULL;
+       ret->psk_client_callback=NULL;
+       ret->psk_server_callback=NULL;
+#endif
+#ifndef OPENSSL_NO_BUF_FREELISTS
+       ret->freelist_max_len = SSL_MAX_BUF_FREELIST_LEN_DEFAULT;
+       ret->rbuf_freelist = OPENSSL_malloc(sizeof(SSL3_BUF_FREELIST));
+       if (!ret->rbuf_freelist)
+               goto err;
+       ret->rbuf_freelist->chunklen = 0;
+       ret->rbuf_freelist->len = 0;
+       ret->rbuf_freelist->head = NULL;
+       ret->wbuf_freelist = OPENSSL_malloc(sizeof(SSL3_BUF_FREELIST));
+       if (!ret->wbuf_freelist)
+               {
+               OPENSSL_free(ret->rbuf_freelist);
+               goto err;
+               }
+       ret->wbuf_freelist->chunklen = 0;
+       ret->wbuf_freelist->len = 0;
+       ret->wbuf_freelist->head = NULL;
 #endif
-
 #ifndef OPENSSL_NO_ENGINE
        ret->client_cert_engine = NULL;
 #ifdef OPENSSL_SSL_CLIENT_ENGINE_AUTO
@@ -1624,6 +1864,20 @@ static void SSL_COMP_free(SSL_COMP *comp)
     { OPENSSL_free(comp); }
 #endif
 
+#ifndef OPENSSL_NO_BUF_FREELISTS
+static void
+ssl_buf_freelist_free(SSL3_BUF_FREELIST *list)
+       {
+       SSL3_BUF_FREELIST_ENTRY *ent, *next;
+       for (ent = list->head; ent; ent = next)
+               {
+               next = ent->next;
+               OPENSSL_free(ent);
+               }
+       OPENSSL_free(list);
+       }
+#endif
+
 void SSL_CTX_free(SSL_CTX *a)
        {
        int i;
@@ -1661,7 +1915,7 @@ void SSL_CTX_free(SSL_CTX *a)
        CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);
 
        if (a->sessions != NULL)
-               lh_free(a->sessions);
+               lh_SSL_SESSION_free(a->sessions);
 
        if (a->cert_store != NULL)
                X509_STORE_free(a->cert_store);
@@ -1681,11 +1935,23 @@ void SSL_CTX_free(SSL_CTX *a)
 #else
        a->comp_methods = NULL;
 #endif
+
+#ifndef OPENSSL_NO_PSK
+       if (a->psk_identity_hint)
+               OPENSSL_free(a->psk_identity_hint);
+#endif
 #ifndef OPENSSL_NO_ENGINE
        if (a->client_cert_engine)
                ENGINE_finish(a->client_cert_engine);
 #endif
 
+#ifndef OPENSSL_NO_BUF_FREELISTS
+       if (a->wbuf_freelist)
+               ssl_buf_freelist_free(a->wbuf_freelist);
+       if (a->rbuf_freelist)
+               ssl_buf_freelist_free(a->rbuf_freelist);
+#endif
+
        OPENSSL_free(a);
        }
 
@@ -1716,20 +1982,20 @@ void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth)
        X509_VERIFY_PARAM_set_depth(ctx->param, depth);
        }
 
-void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher)
+void ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher)
        {
        CERT_PKEY *cpk;
        int rsa_enc,rsa_tmp,rsa_sign,dh_tmp,dh_rsa,dh_dsa,dsa_sign;
        int rsa_enc_export,dh_rsa_export,dh_dsa_export;
        int rsa_tmp_export,dh_tmp_export,kl;
-       unsigned long mask,emask;
+       unsigned long mask_k,mask_a,emask_k,emask_a;
        int have_ecc_cert, ecdh_ok, ecdsa_ok, ecc_pkey_size;
 #ifndef OPENSSL_NO_ECDH
        int have_ecdh_tmp;
 #endif
        X509 *x = NULL;
        EVP_PKEY *ecc_pkey = NULL;
-       int signature_nid = 0;
+       int signature_nid = 0, pk_nid = 0, md_nid = 0;
 
        if (c == NULL) return;
 
@@ -1769,60 +2035,77 @@ void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher)
        dh_dsa_export=(dh_dsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl);
        cpk= &(c->pkeys[SSL_PKEY_ECC]);
        have_ecc_cert= (cpk->x509 != NULL && cpk->privatekey != NULL);
-       mask=0;
-       emask=0;
+       mask_k=0;
+       mask_a=0;
+       emask_k=0;
+       emask_a=0;
+
+       
 
 #ifdef CIPHER_DEBUG
-       printf("rt=%d rte=%d dht=%d re=%d ree=%d rs=%d ds=%d dhr=%d dhd=%d\n",
-               rsa_tmp,rsa_tmp_export,dh_tmp,
+       printf("rt=%d rte=%d dht=%d ecdht=%d re=%d ree=%d rs=%d ds=%d dhr=%d dhd=%d\n",
+               rsa_tmp,rsa_tmp_export,dh_tmp,have_ecdh_tmp,
                rsa_enc,rsa_enc_export,rsa_sign,dsa_sign,dh_rsa,dh_dsa);
 #endif
+       
+       cpk = &(c->pkeys[SSL_PKEY_GOST01]);
+       if (cpk->x509 != NULL && cpk->privatekey !=NULL) {
+               mask_k |= SSL_kGOST;
+               mask_a |= SSL_aGOST01;
+       }
+       cpk = &(c->pkeys[SSL_PKEY_GOST94]);
+       if (cpk->x509 != NULL && cpk->privatekey !=NULL) {
+               mask_k |= SSL_kGOST;
+               mask_a |= SSL_aGOST94;
+       }
 
        if (rsa_enc || (rsa_tmp && rsa_sign))
-               mask|=SSL_kRSA;
+               mask_k|=SSL_kRSA;
        if (rsa_enc_export || (rsa_tmp_export && (rsa_sign || rsa_enc)))
-               emask|=SSL_kRSA;
+               emask_k|=SSL_kRSA;
 
 #if 0
        /* The match needs to be both kEDH and aRSA or aDSA, so don't worry */
-       if (    (dh_tmp || dh_rsa || dh_dsa) && 
+       if (    (dh_tmp || dh_rsa || dh_dsa) &&
                (rsa_enc || rsa_sign || dsa_sign))
-               mask|=SSL_kEDH;
+               mask_k|=SSL_kEDH;
        if ((dh_tmp_export || dh_rsa_export || dh_dsa_export) &&
                (rsa_enc || rsa_sign || dsa_sign))
-               emask|=SSL_kEDH;
+               emask_k|=SSL_kEDH;
 #endif
 
-       if (dh_tmp_export) 
-               emask|=SSL_kEDH;
+       if (dh_tmp_export)
+               emask_k|=SSL_kEDH;
 
        if (dh_tmp)
-               mask|=SSL_kEDH;
+               mask_k|=SSL_kEDH;
 
-       if (dh_rsa) mask|=SSL_kDHr;
-       if (dh_rsa_export) emask|=SSL_kDHr;
+       if (dh_rsa) mask_k|=SSL_kDHr;
+       if (dh_rsa_export) emask_k|=SSL_kDHr;
 
-       if (dh_dsa) mask|=SSL_kDHd;
-       if (dh_dsa_export) emask|=SSL_kDHd;
+       if (dh_dsa) mask_k|=SSL_kDHd;
+       if (dh_dsa_export) emask_k|=SSL_kDHd;
 
        if (rsa_enc || rsa_sign)
                {
-               mask|=SSL_aRSA;
-               emask|=SSL_aRSA;
+               mask_a|=SSL_aRSA;
+               emask_a|=SSL_aRSA;
                }
 
        if (dsa_sign)
                {
-               mask|=SSL_aDSS;
-               emask|=SSL_aDSS;
+               mask_a|=SSL_aDSS;
+               emask_a|=SSL_aDSS;
                }
 
-       mask|=SSL_aNULL;
-       emask|=SSL_aNULL;
+       mask_a|=SSL_aNULL;
+       emask_a|=SSL_aNULL;
 
 #ifndef OPENSSL_NO_KRB5
-       mask|=SSL_kKRB5|SSL_aKRB5;
-       emask|=SSL_kKRB5|SSL_aKRB5;
+       mask_k|=SSL_kKRB5;
+       mask_a|=SSL_aKRB5;
+       emask_k|=SSL_kKRB5;
+       emask_a|=SSL_aKRB5;
 #endif
 
        /* An ECC certificate may be usable for ECDH and/or
@@ -1830,7 +2113,7 @@ void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher)
         */
        if (have_ecc_cert)
                {
-                /* This call populates extension flags (ex_flags) */
+               /* This call populates extension flags (ex_flags) */
                x = (c->pkeys[SSL_PKEY_ECC]).x509;
                X509_check_purpose(x, -1, 0);
                ecdh_ok = (x->ex_flags & EXFLAG_KUSAGE) ?
@@ -1838,35 +2121,46 @@ void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher)
                ecdsa_ok = (x->ex_flags & EXFLAG_KUSAGE) ?
                    (x->ex_kusage & X509v3_KU_DIGITAL_SIGNATURE) : 1;
                ecc_pkey = X509_get_pubkey(x);
-               ecc_pkey_size = (ecc_pkey != NULL) ? 
+               ecc_pkey_size = (ecc_pkey != NULL) ?
                    EVP_PKEY_bits(ecc_pkey) : 0;
                EVP_PKEY_free(ecc_pkey);
                if ((x->sig_alg) && (x->sig_alg->algorithm))
+                       {
                        signature_nid = OBJ_obj2nid(x->sig_alg->algorithm);
+                       OBJ_find_sigid_algs(signature_nid, &md_nid, &pk_nid);
+                       }
 #ifndef OPENSSL_NO_ECDH
                if (ecdh_ok)
                        {
-                       if ((signature_nid == NID_md5WithRSAEncryption) ||
-                           (signature_nid == NID_md4WithRSAEncryption) ||
-                           (signature_nid == NID_md2WithRSAEncryption))
+
+                       if (pk_nid == NID_rsaEncryption || pk_nid == NID_rsa)
                                {
-                               mask|=SSL_kECDH|SSL_aRSA;
+                               mask_k|=SSL_kECDHr;
+                               mask_a|=SSL_aECDH;
                                if (ecc_pkey_size <= 163)
-                                       emask|=SSL_kECDH|SSL_aRSA;
+                                       {
+                                       emask_k|=SSL_kECDHr;
+                                       emask_a|=SSL_aECDH;
+                                       }
                                }
-                       if (signature_nid == NID_ecdsa_with_SHA1)
+
+                       if (pk_nid == NID_X9_62_id_ecPublicKey)
                                {
-                               mask|=SSL_kECDH|SSL_aECDSA;
+                               mask_k|=SSL_kECDHe;
+                               mask_a|=SSL_aECDH;
                                if (ecc_pkey_size <= 163)
-                                       emask|=SSL_kECDH|SSL_aECDSA;
+                                       {
+                                       emask_k|=SSL_kECDHe;
+                                       emask_a|=SSL_aECDH;
+                                       }
                                }
                        }
 #endif
 #ifndef OPENSSL_NO_ECDSA
                if (ecdsa_ok)
                        {
-                       mask|=SSL_aECDSA;
-                       emask|=SSL_aECDSA;
+                       mask_a|=SSL_aECDSA;
+                       emask_a|=SSL_aECDSA;
                        }
 #endif
                }
@@ -1874,12 +2168,22 @@ void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher)
 #ifndef OPENSSL_NO_ECDH
        if (have_ecdh_tmp)
                {
-               mask|=SSL_kECDHE;
-               emask|=SSL_kECDHE;
+               mask_k|=SSL_kEECDH;
+               emask_k|=SSL_kEECDH;
                }
 #endif
-       c->mask=mask;
-       c->export_mask=emask;
+
+#ifndef OPENSSL_NO_PSK
+       mask_k |= SSL_kPSK;
+       mask_a |= SSL_aPSK;
+       emask_k |= SSL_kPSK;
+       emask_a |= SSL_aPSK;
+#endif
+
+       c->mask_k=mask_k;
+       c->mask_a=mask_a;
+       c->export_mask_k=emask_k;
+       c->export_mask_a=emask_a;
        c->valid=1;
        }
 
@@ -1887,12 +2191,17 @@ void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher)
 #define ku_reject(x, usage) \
        (((x)->ex_flags & EXFLAG_KUSAGE) && !((x)->ex_kusage & (usage)))
 
-int check_srvr_ecc_cert_and_alg(X509 *x, SSL_CIPHER *cs)
+#ifndef OPENSSL_NO_EC
+
+int ssl_check_srvr_ecc_cert_and_alg(X509 *x, const SSL_CIPHER *cs)
        {
-       unsigned long alg = cs->algorithms;
+       unsigned long alg_k, alg_a;
        EVP_PKEY *pkey = NULL;
        int keysize = 0;
-       int signature_nid = 0;
+       int signature_nid = 0, md_nid = 0, pk_nid = 0;
+
+       alg_k = cs->algorithm_mkey;
+       alg_a = cs->algorithm_auth;
 
        if (SSL_C_IS_EXPORT(cs))
                {
@@ -1907,38 +2216,44 @@ int check_srvr_ecc_cert_and_alg(X509 *x, SSL_CIPHER *cs)
        /* This call populates the ex_flags field correctly */
        X509_check_purpose(x, -1, 0);
        if ((x->sig_alg) && (x->sig_alg->algorithm))
+               {
                signature_nid = OBJ_obj2nid(x->sig_alg->algorithm);
-       if (alg & SSL_kECDH) 
+               OBJ_find_sigid_algs(signature_nid, &md_nid, &pk_nid);
+               }
+       if (alg_k & SSL_kECDHe || alg_k & SSL_kECDHr)
                {
                /* key usage, if present, must allow key agreement */
                if (ku_reject(x, X509v3_KU_KEY_AGREEMENT))
                        {
+                       SSLerr(SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG, SSL_R_ECC_CERT_NOT_FOR_KEY_AGREEMENT);
                        return 0;
                        }
-               if (alg & SSL_aECDSA) 
+               if (alg_k & SSL_kECDHe)
                        {
                        /* signature alg must be ECDSA */
-                       if (signature_nid != NID_ecdsa_with_SHA1)
+                       if (pk_nid != NID_X9_62_id_ecPublicKey)
                                {
+                               SSLerr(SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG, SSL_R_ECC_CERT_SHOULD_HAVE_SHA1_SIGNATURE);
                                return 0;
                                }
                        }
-               if (alg & SSL_aRSA)
+               if (alg_k & SSL_kECDHr)
                        {
                        /* signature alg must be RSA */
-                       if ((signature_nid != NID_md5WithRSAEncryption) &&
-                           (signature_nid != NID_md4WithRSAEncryption) &&
-                           (signature_nid != NID_md2WithRSAEncryption))
+
+                       if (pk_nid != NID_rsaEncryption && pk_nid != NID_rsa)
                                {
+                               SSLerr(SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG, SSL_R_ECC_CERT_SHOULD_HAVE_RSA_SIGNATURE);
                                return 0;
                                }
                        }
-               } 
-       else if (alg & SSL_aECDSA)
+               }
+       if (alg_a & SSL_aECDSA)
                {
                /* key usage, if present, must allow signing */
                if (ku_reject(x, X509v3_KU_DIGITAL_SIGNATURE))
                        {
+                       SSLerr(SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG, SSL_R_ECC_CERT_NOT_FOR_SIGNING);
                        return 0;
                        }
                }
@@ -1946,56 +2261,63 @@ int check_srvr_ecc_cert_and_alg(X509 *x, SSL_CIPHER *cs)
        return 1;  /* all checks are ok */
        }
 
+#endif
+
 /* THIS NEEDS CLEANING UP */
 X509 *ssl_get_server_send_cert(SSL *s)
        {
-       unsigned long alg,kalg;
+       unsigned long alg_k,alg_a;
        CERT *c;
        int i;
 
        c=s->cert;
        ssl_set_cert_masks(c, s->s3->tmp.new_cipher);
-       alg=s->s3->tmp.new_cipher->algorithms;
-       kalg=alg&(SSL_MKEY_MASK|SSL_AUTH_MASK);
+       
+       alg_k = s->s3->tmp.new_cipher->algorithm_mkey;
+       alg_a = s->s3->tmp.new_cipher->algorithm_auth;
 
-       if (kalg & SSL_kECDH)
+       if (alg_k & (SSL_kECDHr|SSL_kECDHe))
                {
-               /* we don't need to look at SSL_kECDHE 
+               /* we don't need to look at SSL_kEECDH
                 * since no certificate is needed for
                 * anon ECDH and for authenticated
-                * ECDHE, the check for the auth 
+                * EECDH, the check for the auth
                 * algorithm will set i correctly
                 * NOTE: For ECDH-RSA, we need an ECC
-                * not an RSA cert but for ECDHE-RSA
+                * not an RSA cert but for EECDH-RSA
                 * we need an RSA cert. Placing the
                 * checks for SSL_kECDH before RSA
                 * checks ensures the correct cert is chosen.
                 */
                i=SSL_PKEY_ECC;
                }
-       else if (kalg & SSL_aECDSA)
+       else if (alg_a & SSL_aECDSA)
                {
                i=SSL_PKEY_ECC;
                }
-       else if (kalg & SSL_kDHr)
+       else if (alg_k & SSL_kDHr)
                i=SSL_PKEY_DH_RSA;
-       else if (kalg & SSL_kDHd)
+       else if (alg_k & SSL_kDHd)
                i=SSL_PKEY_DH_DSA;
-       else if (kalg & SSL_aDSS)
+       else if (alg_a & SSL_aDSS)
                i=SSL_PKEY_DSA_SIGN;
-       else if (kalg & SSL_aRSA)
+       else if (alg_a & SSL_aRSA)
                {
                if (c->pkeys[SSL_PKEY_RSA_ENC].x509 == NULL)
                        i=SSL_PKEY_RSA_SIGN;
                else
                        i=SSL_PKEY_RSA_ENC;
                }
-       else if (kalg & SSL_aKRB5)
+       else if (alg_a & SSL_aKRB5)
                {
                /* VRS something else here? */
                return(NULL);
                }
-       else /* if (kalg & SSL_aNULL) */
+       else if (alg_a & SSL_aGOST94) 
+               i=SSL_PKEY_GOST94;
+       else if (alg_a & SSL_aGOST01)
+               i=SSL_PKEY_GOST01;
+       else /* if (alg_a & SSL_aNULL) */
                {
                SSLerr(SSL_F_SSL_GET_SERVER_SEND_CERT,ERR_R_INTERNAL_ERROR);
                return(NULL);
@@ -2005,18 +2327,18 @@ X509 *ssl_get_server_send_cert(SSL *s)
        return(c->pkeys[i].x509);
        }
 
-EVP_PKEY *ssl_get_sign_pkey(SSL *s,SSL_CIPHER *cipher)
+EVP_PKEY *ssl_get_sign_pkey(SSL *s,const SSL_CIPHER *cipher)
        {
-       unsigned long alg;
+       unsigned long alg_a;
        CERT *c;
 
-       alg=cipher->algorithms;
+       alg_a = cipher->algorithm_auth;
        c=s->cert;
 
-       if ((alg & SSL_aDSS) &&
+       if ((alg_a & SSL_aDSS) &&
                (c->pkeys[SSL_PKEY_DSA_SIGN].privatekey != NULL))
                return(c->pkeys[SSL_PKEY_DSA_SIGN].privatekey);
-       else if (alg & SSL_aRSA)
+       else if (alg_a & SSL_aRSA)
                {
                if (c->pkeys[SSL_PKEY_RSA_SIGN].privatekey != NULL)
                        return(c->pkeys[SSL_PKEY_RSA_SIGN].privatekey);
@@ -2025,10 +2347,10 @@ EVP_PKEY *ssl_get_sign_pkey(SSL *s,SSL_CIPHER *cipher)
                else
                        return(NULL);
                }
-       else if ((alg & SSL_aECDSA) &&
+       else if ((alg_a & SSL_aECDSA) &&
                 (c->pkeys[SSL_PKEY_ECC].privatekey != NULL))
                return(c->pkeys[SSL_PKEY_ECC].privatekey);
-       else /* if (alg & SSL_aNULL) */
+       else /* if (alg_a & SSL_aNULL) */
                {
                SSLerr(SSL_F_SSL_GET_SIGN_PKEY,ERR_R_INTERNAL_ERROR);
                return(NULL);
@@ -2043,14 +2365,14 @@ void ssl_update_cache(SSL *s,int mode)
         * and it would be rather hard to do anyway :-) */
        if (s->session->session_id_length == 0) return;
 
-       i=s->ctx->session_cache_mode;
+       i=s->session_ctx->session_cache_mode;
        if ((i & mode) && (!s->hit)
                && ((i & SSL_SESS_CACHE_NO_INTERNAL_STORE)
-                   || SSL_CTX_add_session(s->ctx,s->session))
-               && (s->ctx->new_session_cb != NULL))
+                   || SSL_CTX_add_session(s->session_ctx,s->session))
+               && (s->session_ctx->new_session_cb != NULL))
                {
                CRYPTO_add(&s->session->references,1,CRYPTO_LOCK_SSL_SESSION);
-               if (!s->ctx->new_session_cb(s,s->session))
+               if (!s->session_ctx->new_session_cb(s,s->session))
                        SSL_SESSION_free(s->session);
                }
 
@@ -2059,20 +2381,20 @@ void ssl_update_cache(SSL *s,int mode)
                ((i & mode) == mode))
                {
                if (  (((mode & SSL_SESS_CACHE_CLIENT)
-                       ?s->ctx->stats.sess_connect_good
-                       :s->ctx->stats.sess_accept_good) & 0xff) == 0xff)
+                       ?s->session_ctx->stats.sess_connect_good
+                       :s->session_ctx->stats.sess_accept_good) & 0xff) == 0xff)
                        {
-                       SSL_CTX_flush_sessions(s->ctx,(unsigned long)time(NULL));
+                       SSL_CTX_flush_sessions(s->session_ctx,(unsigned long)time(NULL));
                        }
                }
        }
 
-SSL_METHOD *SSL_get_ssl_method(SSL *s)
+const SSL_METHOD *SSL_get_ssl_method(SSL *s)
        {
        return(s->method);
        }
 
-int SSL_set_ssl_method(SSL *s,SSL_METHOD *meth)
+int SSL_set_ssl_method(SSL *s, const SSL_METHOD *meth)
        {
        int conn= -1;
        int ret=1;
@@ -2117,9 +2439,6 @@ int SSL_get_error(const SSL *s,int i)
                        return(SSL_ERROR_SSL);
                }
 
-       if ((i < 0) && SSL_want_server_random_validation(s))
-               return(SSL_ERROR_SERVER_RANDOM_VALIDATION_PENDING);
-
        if ((i < 0) && SSL_want_read(s))
                {
                bio=SSL_get_rbio(s);
@@ -2218,6 +2537,8 @@ void SSL_set_accept_state(SSL *s)
        s->handshake_func=s->method->ssl_accept;
        /* clear the current cipher */
        ssl_clear_cipher_ctx(s);
+       ssl_clear_hash_ctx(&s->read_hash);
+       ssl_clear_hash_ctx(&s->write_hash);
        }
 
 void SSL_set_connect_state(SSL *s)
@@ -2228,6 +2549,8 @@ void SSL_set_connect_state(SSL *s)
        s->handshake_func=s->method->ssl_connect;
        /* clear the current cipher */
        ssl_clear_cipher_ctx(s);
+       ssl_clear_hash_ctx(&s->read_hash);
+       ssl_clear_hash_ctx(&s->write_hash);
        }
 
 int ssl_undefined_function(SSL *s)
@@ -2254,25 +2577,52 @@ SSL_METHOD *ssl_bad_method(int ver)
        return(NULL);
        }
 
-const char *SSL_get_version(const SSL *s)
+static const char *ssl_get_version(int version)
        {
-       if (s->version == TLS1_VERSION)
+       if (version == TLS1_VERSION)
                return("TLSv1");
-       else if (s->version == SSL3_VERSION)
+       else if (version == SSL3_VERSION)
                return("SSLv3");
-       else if (s->version == SSL2_VERSION)
+       else if (version == SSL2_VERSION)
                return("SSLv2");
        else
                return("unknown");
        }
 
+const char *SSL_get_version(const SSL *s)
+       {
+               return ssl_get_version(s->version);
+       }
+
+const char *SSL_SESSION_get_version(const SSL_SESSION *s)
+       {
+               return ssl_get_version(s->ssl_version);
+       }
+
+const char* SSL_authentication_method(const SSL* ssl)
+       {
+       if (ssl->cert != NULL && ssl->cert->rsa_tmp != NULL)
+               return SSL_TXT_RSA "_" SSL_TXT_EXPORT;
+       switch (ssl->version)
+               {
+       case SSL2_VERSION:
+               return SSL_TXT_RSA;
+       case SSL3_VERSION:
+       case TLS1_VERSION:
+       case DTLS1_VERSION:
+               return SSL_CIPHER_authentication_method(ssl->s3->tmp.new_cipher);
+       default:
+               return "UNKNOWN";
+               }
+       }
+
 SSL *SSL_dup(SSL *s)
        {
        STACK_OF(X509_NAME) *sk;
        X509_NAME *xn;
        SSL *ret;
        int i;
-                
+       
        if ((ret=SSL_new(SSL_get_SSL_CTX(s))) == NULL)
            return(NULL);
 
@@ -2442,7 +2792,7 @@ EVP_PKEY *SSL_get_privatekey(SSL *s)
                return(NULL);
        }
 
-SSL_CIPHER *SSL_get_current_cipher(const SSL *s)
+const SSL_CIPHER *SSL_get_current_cipher(const SSL *s)
        {
        if ((s->session != NULL) && (s->session->cipher != NULL))
                return(s->session->cipher);
@@ -2520,7 +2870,7 @@ void ssl_free_wbio_buffer(SSL *s)
                s->wbio=BIO_pop(s->wbio);
 #ifdef REF_CHECK /* not the usual REF_CHECK, but this avoids adding one more preprocessor symbol */
                assert(s->wbio != NULL);
-#endif 
+#endif
        }
        BIO_free(s->bbio);
        s->bbio=NULL;
@@ -2605,7 +2955,7 @@ void SSL_set_info_callback(SSL *ssl,
 
 /* One compiler (Diab DCC) doesn't like argument names in returned
    function pointer.  */
-void (*SSL_get_info_callback(const SSL *ssl))(const SSL * /*ssl*/,int /*type*/,int /*val*/) 
+void (*SSL_get_info_callback(const SSL *ssl))(const SSL * /*ssl*/,int /*type*/,int /*val*/)
        {
        return ssl->info_callback;
        }
@@ -2726,13 +3076,13 @@ RSA *cb(SSL *ssl,int is_export,int keylength)
 
 #ifndef OPENSSL_NO_DH
 void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,DH *(*dh)(SSL *ssl,int is_export,
-                                                       int keylength))
+                                                        int keylength))
        {
        SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_DH_CB,(void (*)(void))dh);
        }
 
 void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int is_export,
-                                               int keylength))
+                                                int keylength))
        {
        SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_DH_CB,(void (*)(void))dh);
        }
@@ -2740,199 +3090,130 @@ void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int is_export,
 
 #ifndef OPENSSL_NO_ECDH
 void SSL_CTX_set_tmp_ecdh_callback(SSL_CTX *ctx,EC_KEY *(*ecdh)(SSL *ssl,int is_export,
-                                                       int keylength))
+                                                                int keylength))
        {
        SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_ECDH_CB,(void (*)(void))ecdh);
        }
 
 void SSL_set_tmp_ecdh_callback(SSL *ssl,EC_KEY *(*ecdh)(SSL *ssl,int is_export,
-                                               int keylength))
+                                                        int keylength))
        {
        SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_ECDH_CB,(void (*)(void))ecdh);
        }
 #endif
 
-
-void SSL_CTX_set_msg_callback(SSL_CTX *ctx, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg))
-       {
-       SSL_CTX_callback_ctrl(ctx, SSL_CTRL_SET_MSG_CALLBACK, (void (*)(void))cb);
-       }
-void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg))
+#ifndef OPENSSL_NO_PSK
+int SSL_CTX_use_psk_identity_hint(SSL_CTX *ctx, const char *identity_hint)
        {
-       SSL_callback_ctrl(ssl, SSL_CTRL_SET_MSG_CALLBACK, (void (*)(void))cb);
+       if (identity_hint != NULL && strlen(identity_hint) > PSK_MAX_IDENTITY_LEN)
+               {
+               SSLerr(SSL_F_SSL_CTX_USE_PSK_IDENTITY_HINT, SSL_R_DATA_LENGTH_TOO_LONG);
+               return 0;
+               }
+       if (ctx->psk_identity_hint != NULL)
+               OPENSSL_free(ctx->psk_identity_hint);
+       if (identity_hint != NULL)
+               {
+               ctx->psk_identity_hint = BUF_strdup(identity_hint);
+               if (ctx->psk_identity_hint == NULL)
+                       return 0;
+               }
+       else
+               ctx->psk_identity_hint = NULL;
+       return 1;
        }
 
-#ifndef OPENSSL_NO_TLSEXT
-/* SSL_select_next_proto implements the standard protocol selection. It is
- * expected that this function is called from the callback set by
- * SSL_CTX_set_next_proto_select_cb.
- *
- * The protocol data is assumed to be a vector of 8-bit, length prefixed byte
- * strings. The length byte itself is not included in the length. A byte
- * string of length 0 is invalid. No byte string may be truncated.
- *
- * The current, but experimental algorithm for selecting the protocol is:
- *
- * 1) If the server doesn't support NPN then this is indicated to the
- * callback. In this case, the client application has to abort the connection
- * or have a default application level protocol.
- *
- * 2) If the server supports NPN, but advertises an empty list then the
- * client selects the first protcol in its list, but indicates via the
- * API that this fallback case was enacted.
- *
- * 3) Otherwise, the client finds the first protocol in the server's list
- * that it supports and selects this protocol. This is because it's
- * assumed that the server has better information about which protocol
- * a client should use.
- *
- * 4) If the client doesn't support any of the server's advertised
- * protocols, then this is treated the same as case 2.
- *
- * It returns either
- * OPENSSL_NPN_NEGOTIATED if a common protocol was found, or
- * OPENSSL_NPN_NO_OVERLAP if the fallback case was reached.
- */
-int SSL_select_next_proto(unsigned char **out, unsigned char *outlen, const unsigned char *server, unsigned int server_len, const unsigned char *client, unsigned int client_len)
+int SSL_use_psk_identity_hint(SSL *s, const char *identity_hint)
        {
-       unsigned int i, j;
-       const unsigned char *result;
-       int status = OPENSSL_NPN_UNSUPPORTED;
+       if (s == NULL)
+               return 0;
 
-       /* For each protocol in server preference order, see if we support it. */
-       for (i = 0; i < server_len; )
+       if (s->session == NULL)
+               return 1; /* session not created yet, ignored */
+
+       if (identity_hint != NULL && strlen(identity_hint) > PSK_MAX_IDENTITY_LEN)
                {
-               for (j = 0; j < client_len; )
-                       {
-                       if (server[i] == client[j] &&
-                           memcmp(&server[i+1], &client[j+1], server[i]) == 0)
-                               {
-                               /* We found a match */
-                               result = &server[i];
-                               status = OPENSSL_NPN_NEGOTIATED;
-                               goto found;
-                               }
-                       j += client[j];
-                       j++;
-                       }
-               i += server[i];
-               i++;
+               SSLerr(SSL_F_SSL_USE_PSK_IDENTITY_HINT, SSL_R_DATA_LENGTH_TOO_LONG);
+               return 0;
                }
+       if (s->session->psk_identity_hint != NULL)
+               OPENSSL_free(s->session->psk_identity_hint);
+       if (identity_hint != NULL)
+               {
+               s->session->psk_identity_hint = BUF_strdup(identity_hint);
+               if (s->session->psk_identity_hint == NULL)
+                       return 0;
+               }
+       else
+               s->session->psk_identity_hint = NULL;
+       return 1;
+       }
 
-       /* There's no overlap between our protocols and the server's list. */
-       result = client;
-       status = OPENSSL_NPN_NO_OVERLAP;
-
-       found:
-       *out = (unsigned char *) result + 1;
-       *outlen = result[0];
-       return status;
+const char *SSL_get_psk_identity_hint(const SSL *s)
+       {
+       if (s == NULL || s->session == NULL)
+               return NULL;
+       return(s->session->psk_identity_hint);
        }
 
-/* SSL_get0_next_proto_negotiated sets *data and *len to point to the client's
- * requested protocol for this connection and returns 0. If the client didn't
- * request any protocol, then *data is set to NULL.
- *
- * Note that the client can request any protocol it chooses. The value returned
- * from this function need not be a member of the list of supported protocols
- * provided by the callback.
- */
-void SSL_get0_next_proto_negotiated(const SSL *s, const unsigned char **data, unsigned *len)
+const char *SSL_get_psk_identity(const SSL *s)
        {
-       *data = s->next_proto_negotiated;
-       if (!*data) {
-               *len = 0;
-       } else {
-               *len = s->next_proto_negotiated_len;
+       if (s == NULL || s->session == NULL)
+               return NULL;
+       return(s->session->psk_identity);
        }
-}
 
-/* SSL_CTX_set_next_protos_advertised_cb sets a callback that is called when a
- * TLS server needs a list of supported protocols for Next Protocol
- * Negotiation. The returned list must be in wire format.  The list is returned
- * by setting |out| to point to it and |outlen| to its length. This memory will
- * not be modified, but one should assume that the SSL* keeps a reference to
- * it.
- *
- * The callback should return SSL_TLSEXT_ERR_OK if it wishes to advertise. Otherwise, no
- * such extension will be included in the ServerHello. */
-void SSL_CTX_set_next_protos_advertised_cb(SSL_CTX *ctx, int (*cb) (SSL *ssl, const unsigned char **out, unsigned int *outlen, void *arg), void *arg)
+void SSL_set_psk_client_callback(SSL *s,
+    unsigned int (*cb)(SSL *ssl, const char *hint,
+                       char *identity, unsigned int max_identity_len, unsigned char *psk,
+                       unsigned int max_psk_len))
        {
-       ctx->next_protos_advertised_cb = cb;
-       ctx->next_protos_advertised_cb_arg = arg;
+       s->psk_client_callback = cb;
        }
 
-/* SSL_CTX_set_next_proto_select_cb sets a callback that is called when a
- * client needs to select a protocol from the server's provided list. |out|
- * must be set to point to the selected protocol (which may be within |in|).
- * The length of the protocol name must be written into |outlen|. The server's
- * advertised protocols are provided in |in| and |inlen|. The callback can
- * assume that |in| is syntactically valid.
- *
- * The client must select a protocol. It is fatal to the connection if this
- * callback returns a value other than SSL_TLSEXT_ERR_OK.
- */
-void SSL_CTX_set_next_proto_select_cb(SSL_CTX *ctx, int (*cb) (SSL *s, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg), void *arg)
+void SSL_CTX_set_psk_client_callback(SSL_CTX *ctx,
+    unsigned int (*cb)(SSL *ssl, const char *hint,
+                       char *identity, unsigned int max_identity_len, unsigned char *psk,
+                       unsigned int max_psk_len))
        {
-       ctx->next_proto_select_cb = cb;
-       ctx->next_proto_select_cb_arg = arg;
+       ctx->psk_client_callback = cb;
        }
 
-/* SSL_CTX_set_snap_start_orbit sets the orbit value which will be echoed back
- * to the client and enables Snap Start for this context.
- *
- * An orbit value can be used to spatially partition the state needed to support
- * Snap Start. See the comments above SSL_set_suggested_server_random_validity
- * (below).  */
-void SSL_CTX_set_snap_start_orbit(SSL_CTX *ctx, const unsigned char orbit[8])
+void SSL_set_psk_server_callback(SSL *s,
+    unsigned int (*cb)(SSL *ssl, const char *identity,
+                       unsigned char *psk, unsigned int max_psk_len))
        {
-       memcpy(ctx->snap_start_orbit, orbit, sizeof(ctx->snap_start_orbit));
-       ctx->snap_start_orbit_valid = 1;
+       s->psk_server_callback = cb;
        }
 
-/* Once SSL_accept has returned with SSL_SERVER_RANDOM_VALIDATE, then one can
- * call this function in order to get the client's suggested server random
- * value. */
-void SSL_get0_suggested_server_random(const SSL* s, const unsigned char **data, unsigned *length)
+void SSL_CTX_set_psk_server_callback(SSL_CTX *ctx,
+    unsigned int (*cb)(SSL *ssl, const char *identity,
+                       unsigned char *psk, unsigned int max_psk_len))
        {
-       if (!s->s3->snap_start_requested)
-               {
-               *data = NULL;
-               *length = 0;
-               return;
-               }
-       *length = 32;
-       *data = s->s3->server_random;
+       ctx->psk_server_callback = cb;
        }
+#endif
 
-/* SSL_set_suggested_server_random_validity passes judgement on a
- * client-suggested random value (obtained from
- * SSL_get0_suggested_server_random). Rejecting the value triggers a recovery,
- * while accepting the value /may/ result in a successful Snap Start, as long
- * as the client predicted the handshake correctly.
- *
- * In order to accept a random value the user must ensure that it has NEVER
- * been used before by this server, or any server configured with any of the
- * same certificates. It may reject more if necessary.
- *
- * The first four bytes of the random value contain a timestamp (UNIX seconds
- * since the epoch) which can be used to manage a time window.  Additionally,
- * the following eight bytes contain the orbit which which can also bound the
- * state required if geographically separate servers share certificates.
- *
- * It's recommended that the time window have a maximum size, independent of
- * the resources available, in order to prevent an attacker from arbitrarily
- * delaying a Snap Start handshake.
- */
-void SSL_set_suggested_server_random_validity(SSL *s, char is_valid)
+void SSL_CTX_set_msg_callback(SSL_CTX *ctx, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg))
        {
-       if (is_valid)
-               s->s3->server_random_suggestion_valid = 1;
-       else
-               ssl3_snap_start_reset_for_recovery(s);
+       SSL_CTX_callback_ctrl(ctx, SSL_CTRL_SET_MSG_CALLBACK, (void (*)(void))cb);
+       }
+void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg))
+       {
+       SSL_callback_ctrl(ssl, SSL_CTRL_SET_MSG_CALLBACK, (void (*)(void))cb);
        }
 
-#endif
+int SSL_export_keying_material(SSL *s, unsigned char *out, size_t olen,
+        const char *label, size_t llen, const unsigned char *p, size_t plen,
+        int use_context)
+       {
+       if (s->version < TLS1_VERSION)
+               return -1;
+
+       return s->method->ssl3_enc->export_keying_material(s, out, olen, label,
+                                                          llen, p, plen,
+                                                          use_context);
+       }
 
 int SSL_cutthrough_complete(const SSL *s)
        {
@@ -2947,9 +3228,32 @@ int SSL_cutthrough_complete(const SSL *s)
                        s->state == SSL3_ST_CR_FINISHED_A));
        }
 
+/* Allocates new EVP_MD_CTX and sets pointer to it into given pointer
+ * vairable, freeing  EVP_MD_CTX previously stored in that variable, if
+ * any. If EVP_MD pointer is passed, initializes ctx with this md
+ * Returns newly allocated ctx;
+ */
+
+EVP_MD_CTX *ssl_replace_hash(EVP_MD_CTX **hash,const EVP_MD *md) 
+{
+       ssl_clear_hash_ctx(hash);
+       *hash = EVP_MD_CTX_create();
+       if (md) EVP_DigestInit_ex(*hash,md,NULL);
+       return *hash;
+}
+void ssl_clear_hash_ctx(EVP_MD_CTX **hash) 
+{
+
+       if (*hash) EVP_MD_CTX_destroy(*hash);
+       *hash=NULL;
+}
+
 #if defined(_WINDLL) && defined(OPENSSL_SYS_WIN16)
 #include "../crypto/bio/bss_file.c"
 #endif
 
 IMPLEMENT_STACK_OF(SSL_CIPHER)
 IMPLEMENT_STACK_OF(SSL_COMP)
+IMPLEMENT_OBJ_BSEARCH_GLOBAL_CMP_FN(SSL_CIPHER, SSL_CIPHER,
+                                   ssl_cipher_id);
+
index 639a185..af607e6 100644 (file)
@@ -56,7 +56,7 @@
  * [including the GNU Public Licence.]
  */
 /* ====================================================================
- * Copyright (c) 1998-2001 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2007 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * ECC cipher suite support in OpenSSL originally developed by 
  * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
  */
+/* ====================================================================
+ * Copyright 2005 Nokia. All rights reserved.
+ *
+ * The portions of the attached software ("Contribution") is developed by
+ * Nokia Corporation and is licensed pursuant to the OpenSSL open source
+ * license.
+ *
+ * The Contribution, originally written by Mika Kousa and Pasi Eronen of
+ * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
+ * support (see RFC 4279) to OpenSSL.
+ *
+ * No patent licenses or other rights except those expressly stated in
+ * the OpenSSL open source license shall be deemed granted or received
+ * expressly, by implication, estoppel, or otherwise.
+ *
+ * No assurances are provided by Nokia that the Contribution does not
+ * infringe the patent or other intellectual property rights of any third
+ * party or that the license provides you with all the necessary rights
+ * to make use of the Contribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
+ * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
+ * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
+ * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
+ * OTHERWISE.
+ */
 
 #ifndef HEADER_SSL_LOCL_H
 #define HEADER_SSL_LOCL_H
  * that the different entities within are mutually exclusive:
  * ONLY ONE BIT PER MASK CAN BE SET AT A TIME.
  */
-#define SSL_MKEY_MASK          0x000000FFL
+
+/* Bits for algorithm_mkey (key exchange algorithm) */
 #define SSL_kRSA               0x00000001L /* RSA key exchange */
-#define SSL_kDHr               0x00000002L /* DH cert RSA CA cert */
-#define SSL_kDHd               0x00000004L /* DH cert DSA CA cert */
-#define SSL_kFZA               0x00000008L
-#define SSL_kEDH               0x00000010L /* tmp DH key no DH cert */
-#define SSL_kKRB5              0x00000020L /* Kerberos5 key exchange */
-#define SSL_kECDH               0x00000040L /* ECDH w/ long-term keys */
-#define SSL_kECDHE              0x00000080L /* ephemeral ECDH */
-#define SSL_EDH                        (SSL_kEDH|(SSL_AUTH_MASK^SSL_aNULL))
-
-#define SSL_AUTH_MASK          0x00007F00L
-#define SSL_aRSA               0x00000100L /* Authenticate with RSA */
-#define SSL_aDSS               0x00000200L /* Authenticate with DSS */
-#define SSL_DSS                SSL_aDSS
-#define SSL_aFZA               0x00000400L
-#define SSL_aNULL              0x00000800L /* no Authenticate, ADH */
-#define SSL_aDH                0x00001000L /* no Authenticate, ADH */
-#define SSL_aKRB5               0x00002000L /* Authenticate with KRB5 */
-#define SSL_aECDSA              0x00004000L /* Authenticate with ECDSA */
-
-#define SSL_NULL               (SSL_eNULL)
-#define SSL_ADH                        (SSL_kEDH|SSL_aNULL)
-#define SSL_RSA                        (SSL_kRSA|SSL_aRSA)
-#define SSL_DH                 (SSL_kDHr|SSL_kDHd|SSL_kEDH)
-#define SSL_ECDH               (SSL_kECDH|SSL_kECDHE)
-#define SSL_FZA                        (SSL_aFZA|SSL_kFZA|SSL_eFZA)
-#define SSL_KRB5                (SSL_kKRB5|SSL_aKRB5)
-
-#define SSL_ENC_MASK           0x1C3F8000L
-#define SSL_DES                        0x00008000L
-#define SSL_3DES               0x00010000L
-#define SSL_RC4                        0x00020000L
-#define SSL_RC2                        0x00040000L
-#define SSL_IDEA               0x00080000L
-#define SSL_eFZA               0x00100000L
-#define SSL_eNULL              0x00200000L
-#define SSL_AES                        0x04000000L
-#define SSL_CAMELLIA           0x08000000L
-#define SSL_SEED               0x10000000L
-
-#define SSL_MAC_MASK           0x00c00000L
-#define SSL_MD5                        0x00400000L
-#define SSL_SHA1               0x00800000L
-#define SSL_SHA                        (SSL_SHA1)
-
-#define SSL_SSL_MASK           0x03000000L
-#define SSL_SSLV2              0x01000000L
-#define SSL_SSLV3              0x02000000L
+#define SSL_kDHr               0x00000002L /* DH cert, RSA CA cert */ /* no such ciphersuites supported! */
+#define SSL_kDHd               0x00000004L /* DH cert, DSA CA cert */ /* no such ciphersuite supported! */
+#define SSL_kEDH               0x00000008L /* tmp DH key no DH cert */
+#define SSL_kKRB5              0x00000010L /* Kerberos5 key exchange */
+#define SSL_kECDHr             0x00000020L /* ECDH cert, RSA CA cert */
+#define SSL_kECDHe             0x00000040L /* ECDH cert, ECDSA CA cert */
+#define SSL_kEECDH             0x00000080L /* ephemeral ECDH */
+#define SSL_kPSK               0x00000100L /* PSK */
+#define SSL_kGOST       0x00000200L /* GOST key exchange */
+
+/* Bits for algorithm_auth (server authentication) */
+#define SSL_aRSA               0x00000001L /* RSA auth */
+#define SSL_aDSS               0x00000002L /* DSS auth */
+#define SSL_aNULL              0x00000004L /* no auth (i.e. use ADH or AECDH) */
+#define SSL_aDH                0x00000008L /* Fixed DH auth (kDHd or kDHr) */ /* no such ciphersuites supported! */
+#define SSL_aECDH              0x00000010L /* Fixed ECDH auth (kECDHe or kECDHr) */
+#define SSL_aKRB5               0x00000020L /* KRB5 auth */
+#define SSL_aECDSA              0x00000040L /* ECDSA auth*/
+#define SSL_aPSK                0x00000080L /* PSK auth */
+#define SSL_aGOST94                            0x00000100L /* GOST R 34.10-94 signature auth */
+#define SSL_aGOST01                    0x00000200L /* GOST R 34.10-2001 signature auth */
+
+
+/* Bits for algorithm_enc (symmetric encryption) */
+#define SSL_DES                        0x00000001L
+#define SSL_3DES               0x00000002L
+#define SSL_RC4                        0x00000004L
+#define SSL_RC2                        0x00000008L
+#define SSL_IDEA               0x00000010L
+#define SSL_eNULL              0x00000020L
+#define SSL_AES128             0x00000040L
+#define SSL_AES256             0x00000080L
+#define SSL_CAMELLIA128                0x00000100L
+#define SSL_CAMELLIA256                0x00000200L
+#define SSL_eGOST2814789CNT    0x00000400L
+#define SSL_SEED               0x00000800L
+
+#define SSL_AES                        (SSL_AES128|SSL_AES256)
+#define SSL_CAMELLIA           (SSL_CAMELLIA128|SSL_CAMELLIA256)
+
+
+/* Bits for algorithm_mac (symmetric authentication) */
+#define SSL_MD5                        0x00000001L
+#define SSL_SHA1               0x00000002L
+#define SSL_GOST94      0x00000004L
+#define SSL_GOST89MAC   0x00000008L
+
+/* Bits for algorithm_ssl (protocol version) */
+#define SSL_SSLV2              0x00000001L
+#define SSL_SSLV3              0x00000002L
 #define SSL_TLSV1              SSL_SSLV3       /* for now */
 
-/* we have used 1fffffff - 3 bits left to go. */
+
+/* Bits for algorithm2 (handshake digests and other extra flags) */
+
+#define SSL_HANDSHAKE_MAC_MD5 0x10
+#define SSL_HANDSHAKE_MAC_SHA 0x20
+#define SSL_HANDSHAKE_MAC_GOST94 0x40
+#define SSL_HANDSHAKE_MAC_DEFAULT (SSL_HANDSHAKE_MAC_MD5 | SSL_HANDSHAKE_MAC_SHA)
+
+/* When adding new digest in the ssl_ciph.c and increment SSM_MD_NUM_IDX
+ * make sure to update this constant too */
+#define SSL_MAX_DIGEST 4
+
+#define TLS1_PRF_DGST_SHIFT 8
+#define TLS1_PRF_MD5 (SSL_HANDSHAKE_MAC_MD5 << TLS1_PRF_DGST_SHIFT)
+#define TLS1_PRF_SHA1 (SSL_HANDSHAKE_MAC_SHA << TLS1_PRF_DGST_SHIFT)
+#define TLS1_PRF_GOST94 (SSL_HANDSHAKE_MAC_GOST94 << TLS1_PRF_DGST_SHIFT)
+#define TLS1_PRF (TLS1_PRF_MD5 | TLS1_PRF_SHA1)
+
+/* Stream MAC for GOST ciphersuites from cryptopro draft
+ * (currently this also goes into algorithm2) */
+#define TLS1_STREAM_MAC 0x04
+
+
 
 /*
  * Export and cipher strength information. For each cipher we have to decide
  * be possible.
  */
 #define SSL_EXP_MASK           0x00000003L
+#define SSL_STRONG_MASK                0x000001fcL
+
 #define SSL_NOT_EXP            0x00000001L
 #define SSL_EXPORT             0x00000002L
 
-#define SSL_STRONG_MASK                0x000000fcL
 #define SSL_STRONG_NONE                0x00000004L
 #define SSL_EXP40              0x00000008L
 #define SSL_MICRO              (SSL_EXP40)
 #define SSL_C_IS_EXPORT40(c)   SSL_IS_EXPORT40((c)->algo_strength)
 
 #define SSL_EXPORT_KEYLENGTH(a,s)      (SSL_IS_EXPORT40(s) ? 5 : \
-                                ((a)&SSL_ENC_MASK) == SSL_DES ? 8 : 7)
+                                (a) == SSL_DES ? 8 : 7)
 #define SSL_EXPORT_PKEYLENGTH(a) (SSL_IS_EXPORT40(a) ? 512 : 1024)
-#define SSL_C_EXPORT_KEYLENGTH(c)      SSL_EXPORT_KEYLENGTH((c)->algorithms, \
+#define SSL_C_EXPORT_KEYLENGTH(c)      SSL_EXPORT_KEYLENGTH((c)->algorithm_enc, \
                                (c)->algo_strength)
 #define SSL_C_EXPORT_PKEYLENGTH(c)     SSL_EXPORT_PKEYLENGTH((c)->algo_strength)
 
 
-#define SSL_ALL                        0xffffffffL
-#define SSL_ALL_CIPHERS                (SSL_MKEY_MASK|SSL_AUTH_MASK|SSL_ENC_MASK|\
-                               SSL_MAC_MASK)
-#define SSL_ALL_STRENGTHS      (SSL_EXP_MASK|SSL_STRONG_MASK)
+
 
 /* Mostly for SSLv3 */
 #define SSL_PKEY_RSA_ENC       0
 #define SSL_PKEY_DH_RSA                3
 #define SSL_PKEY_DH_DSA                4
 #define SSL_PKEY_ECC            5
-#define SSL_PKEY_NUM           6
+#define SSL_PKEY_GOST94                6
+#define SSL_PKEY_GOST01                7
+#define SSL_PKEY_NUM           8
 
 /* SSL_kRSA <- RSA_ENC | (RSA_TMP & RSA_SIGN) |
  *         <- (EXPORT & (RSA_ENC | RSA_TMP) & RSA_SIGN)
 #define CERT_PRIVATE_KEY       2
 */
 
-/* This can be returned from ssl3_send_server_hello to indicate that an
- * offline validation of a client-suggested server_random needs to be
- * performed. */
-#define SERVER_RANDOM_VALIDATION_PENDING -(TLSEXT_TYPE_snap_start)
-
 #ifndef OPENSSL_NO_EC
 /* From ECC-TLS draft, used in encoding the curve type in 
  * ECParameters
 typedef struct cert_pkey_st
        {
        X509 *x509;
+       STACK_OF(X509) *cert_chain;
        EVP_PKEY *privatekey;
        } CERT_PKEY;
 
@@ -422,8 +470,10 @@ typedef struct cert_st
        /* The following masks are for the key and auth
         * algorithms that are supported by the certs below */
        int valid;
-       unsigned long mask;
-       unsigned long export_mask;
+       unsigned long mask_k;
+       unsigned long mask_a;
+       unsigned long export_mask_k;
+       unsigned long export_mask_a;
 #ifndef OPENSSL_NO_RSA
        RSA *rsa_tmp;
        RSA *(*rsa_tmp_cb)(SSL *ssl,int is_export,int keysize);
@@ -497,14 +547,18 @@ typedef struct ssl3_enc_method
        int (*setup_key_block)(SSL *);
        int (*generate_master_secret)(SSL *, unsigned char *, unsigned char *, int);
        int (*change_cipher_state)(SSL *, int);
-       int (*final_finish_mac)(SSL *, EVP_MD_CTX *, EVP_MD_CTX *, const char *, int, unsigned char *);
+       int (*final_finish_mac)(SSL *,  const char *, int, unsigned char *);
        int finish_mac_length;
-       int (*cert_verify_mac)(SSL *, EVP_MD_CTX *, unsigned char *);
+       int (*cert_verify_mac)(SSL *, int, unsigned char *);
        const char *client_finished_label;
        int client_finished_label_len;
        const char *server_finished_label;
        int server_finished_label_len;
        int (*alert_value)(int);
+       int (*export_keying_material)(SSL *, unsigned char *, size_t,
+                                     const char *, size_t,
+                                     const unsigned char *, size_t,
+                                     int use_context);
        } SSL3_ENC_METHOD;
 
 #ifndef OPENSSL_NO_COMP
@@ -517,24 +571,35 @@ typedef struct ssl3_comp_st
        } SSL3_COMP;
 #endif
 
+#ifndef OPENSSL_NO_BUF_FREELISTS
+typedef struct ssl3_buf_freelist_st
+       {
+       size_t chunklen;
+       unsigned int len;
+       struct ssl3_buf_freelist_entry_st *head;
+       } SSL3_BUF_FREELIST;
+
+typedef struct ssl3_buf_freelist_entry_st
+       {
+       struct ssl3_buf_freelist_entry_st *next;
+       } SSL3_BUF_FREELIST_ENTRY;
+#endif
+
 extern SSL3_ENC_METHOD ssl3_undef_enc_method;
-OPENSSL_EXTERN SSL_CIPHER ssl2_ciphers[];
+OPENSSL_EXTERN const SSL_CIPHER ssl2_ciphers[];
 OPENSSL_EXTERN SSL_CIPHER ssl3_ciphers[];
 
 
 SSL_METHOD *ssl_bad_method(int ver);
-SSL_METHOD *sslv2_base_method(void);
-SSL_METHOD *sslv23_base_method(void);
-SSL_METHOD *sslv3_base_method(void);
 
 extern SSL3_ENC_METHOD TLSv1_enc_data;
 extern SSL3_ENC_METHOD SSLv3_enc_data;
 extern SSL3_ENC_METHOD DTLSv1_enc_data;
 
 #define IMPLEMENT_tls1_meth_func(func_name, s_accept, s_connect, s_get_meth) \
-SSL_METHOD *func_name(void)  \
+const SSL_METHOD *func_name(void)  \
        { \
-       static SSL_METHOD func_name##_data= { \
+       static const SSL_METHOD func_name##_data= { \
                TLS1_VERSION, \
                tls1_new, \
                tls1_clear, \
@@ -569,9 +634,9 @@ SSL_METHOD *func_name(void)  \
        }
 
 #define IMPLEMENT_ssl3_meth_func(func_name, s_accept, s_connect, s_get_meth) \
-SSL_METHOD *func_name(void)  \
+const SSL_METHOD *func_name(void)  \
        { \
-       static SSL_METHOD func_name##_data= { \
+       static const SSL_METHOD func_name##_data= { \
                SSL3_VERSION, \
                ssl3_new, \
                ssl3_clear, \
@@ -606,9 +671,9 @@ SSL_METHOD *func_name(void)  \
        }
 
 #define IMPLEMENT_ssl23_meth_func(func_name, s_accept, s_connect, s_get_meth) \
-SSL_METHOD *func_name(void)  \
+const SSL_METHOD *func_name(void)  \
        { \
-       static SSL_METHOD func_name##_data= { \
+       static const SSL_METHOD func_name##_data= { \
        TLS1_VERSION, \
        tls1_new, \
        tls1_clear, \
@@ -643,9 +708,9 @@ SSL_METHOD *func_name(void)  \
        }
 
 #define IMPLEMENT_ssl2_meth_func(func_name, s_accept, s_connect, s_get_meth) \
-SSL_METHOD *func_name(void)  \
+const SSL_METHOD *func_name(void)  \
        { \
-       static SSL_METHOD func_name##_data= { \
+       static const SSL_METHOD func_name##_data= { \
                SSL2_VERSION, \
                ssl2_new,       /* local */ \
                ssl2_clear,     /* local */ \
@@ -680,9 +745,9 @@ SSL_METHOD *func_name(void)  \
        }
 
 #define IMPLEMENT_dtls1_meth_func(func_name, s_accept, s_connect, s_get_meth) \
-SSL_METHOD *func_name(void)  \
+const SSL_METHOD *func_name(void)  \
        { \
-       static SSL_METHOD func_name##_data= { \
+       static const SSL_METHOD func_name##_data= { \
                DTLS1_VERSION, \
                dtls1_new, \
                dtls1_clear, \
@@ -728,6 +793,8 @@ int ssl_set_peer_cert_type(SESS_CERT *c, int type);
 int ssl_get_new_session(SSL *s, int session);
 int ssl_get_prev_session(SSL *s, unsigned char *session,int len, const unsigned char *limit);
 int ssl_cipher_id_cmp(const SSL_CIPHER *a,const SSL_CIPHER *b);
+DECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(SSL_CIPHER, SSL_CIPHER,
+                                 ssl_cipher_id);
 int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap,
                        const SSL_CIPHER * const *bp);
 STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num,
@@ -740,15 +807,16 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth,
                                             const char *rule_str);
 void ssl_update_cache(SSL *s, int mode);
 int ssl_cipher_get_evp(const SSL_SESSION *s,const EVP_CIPHER **enc,
-                      const EVP_MD **md,SSL_COMP **comp);
+                      const EVP_MD **md,int *mac_pkey_type,int *mac_secret_size, SSL_COMP **comp);
+int ssl_get_handshake_digest(int i,long *mask,const EVP_MD **md);                         
 int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk);
 int ssl_undefined_function(SSL *s);
 int ssl_undefined_void_function(void);
 int ssl_undefined_const_function(const SSL *s);
 X509 *ssl_get_server_send_cert(SSL *);
-EVP_PKEY *ssl_get_sign_pkey(SSL *,SSL_CIPHER *);
+EVP_PKEY *ssl_get_sign_pkey(SSL *,const SSL_CIPHER *);
 int ssl_cert_type(X509 *x,EVP_PKEY *pkey);
-void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher);
+void ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher);
 STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s);
 int ssl_verify_alarm_type(long type);
 void ssl_load_ciphers(void);
@@ -757,7 +825,7 @@ int ssl2_enc_init(SSL *s, int client);
 int ssl2_generate_key_material(SSL *s);
 void ssl2_enc(SSL *s,int send_data);
 void ssl2_mac(SSL *s,unsigned char *mac,int send_data);
-SSL_CIPHER *ssl2_get_cipher_by_char(const unsigned char *p);
+const SSL_CIPHER *ssl2_get_cipher_by_char(const unsigned char *p);
 int ssl2_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p);
 int ssl2_part_read(SSL *s, unsigned long f, int i);
 int ssl2_do_write(SSL *s);
@@ -765,7 +833,7 @@ int ssl2_set_certificate(SSL *s, int type, int len, const unsigned char *data);
 void ssl2_return_error(SSL *s,int reason);
 void ssl2_write_error(SSL *s);
 int ssl2_num_ciphers(void);
-SSL_CIPHER *ssl2_get_cipher(unsigned int u);
+const SSL_CIPHER *ssl2_get_cipher(unsigned int u);
 int    ssl2_new(SSL *s);
 void   ssl2_free(SSL *s);
 int    ssl2_accept(SSL *s);
@@ -782,7 +850,7 @@ long        ssl2_ctx_callback_ctrl(SSL_CTX *s,int cmd, void (*fp)(void));
 int    ssl2_pending(const SSL *s);
 long   ssl2_default_timeout(void );
 
-SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p);
+const SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p);
 int ssl3_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p);
 void ssl3_init_finished_mac(SSL *s);
 int ssl3_send_server_certificate(SSL *s);
@@ -801,22 +869,27 @@ int ssl3_get_req_cert_type(SSL *s,unsigned char *p);
 long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok);
 int ssl3_send_finished(SSL *s, int a, int b, const char *sender,int slen);
 int ssl3_num_ciphers(void);
-SSL_CIPHER *ssl3_get_cipher(unsigned int u);
+const SSL_CIPHER *ssl3_get_cipher(unsigned int u);
 int ssl3_renegotiate(SSL *ssl); 
 int ssl3_renegotiate_check(SSL *ssl); 
 int ssl3_dispatch_alert(SSL *s);
 int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek);
 int ssl3_write_bytes(SSL *s, int type, const void *buf, int len);
-int ssl3_final_finish_mac(SSL *s, EVP_MD_CTX *ctx1, EVP_MD_CTX *ctx2,
-       const char *sender, int slen,unsigned char *p);
-int ssl3_cert_verify_mac(SSL *s, EVP_MD_CTX *in, unsigned char *p);
+int ssl3_final_finish_mac(SSL *s, const char *sender, int slen,unsigned char *p);
+int ssl3_cert_verify_mac(SSL *s, int md_nid, unsigned char *p);
 void ssl3_finish_mac(SSL *s, const unsigned char *buf, int len);
 int ssl3_enc(SSL *s, int send_data);
-int ssl3_mac(SSL *ssl, unsigned char *md, int send_data);
+int n_ssl3_mac(SSL *ssl, unsigned char *md, int send_data);
+void ssl3_free_digest_list(SSL *s);
 unsigned long ssl3_output_cert_chain(SSL *s, X509 *x);
 SSL_CIPHER *ssl3_choose_cipher(SSL *ssl,STACK_OF(SSL_CIPHER) *clnt,
                               STACK_OF(SSL_CIPHER) *srvr);
 int    ssl3_setup_buffers(SSL *s);
+int    ssl3_setup_read_buffer(SSL *s);
+int    ssl3_setup_write_buffer(SSL *s);
+int    ssl3_release_read_buffer(SSL *s);
+int    ssl3_release_write_buffer(SSL *s);
+int    ssl3_digest_cached_records(SSL *s);
 int    ssl3_new(SSL *s);
 void   ssl3_free(SSL *s);
 int    ssl3_accept(SSL *s);
@@ -837,12 +910,12 @@ int ssl3_do_change_cipher_spec(SSL *ssl);
 long ssl3_default_timeout(void );
 
 int ssl23_num_ciphers(void );
-SSL_CIPHER *ssl23_get_cipher(unsigned int u);
+const SSL_CIPHER *ssl23_get_cipher(unsigned int u);
 int ssl23_read(SSL *s, void *buf, int len);
 int ssl23_peek(SSL *s, void *buf, int len);
 int ssl23_write(SSL *s, const void *buf, int len);
 int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p);
-SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p);
+const SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p);
 long ssl23_default_timeout(void );
 
 long tls1_default_timeout(void);
@@ -876,13 +949,13 @@ void dtls1_reset_seq_numbers(SSL *s, int rw);
 long dtls1_default_timeout(void);
 struct timeval* dtls1_get_timeout(SSL *s, struct timeval* timeleft);
 int dtls1_handle_timeout(SSL *s);
-SSL_CIPHER *dtls1_get_cipher(unsigned int u);
+const SSL_CIPHER *dtls1_get_cipher(unsigned int u);
 void dtls1_start_timer(SSL *s);
 void dtls1_stop_timer(SSL *s);
 int dtls1_is_timer_expired(SSL *s);
 void dtls1_double_timeout(SSL *s);
 int dtls1_send_newsession_ticket(SSL *s);
-
+unsigned int dtls1_min_mtu(void);
 
 /* some client-only functions */
 int ssl3_client_hello(SSL *s);
@@ -892,15 +965,17 @@ int ssl3_get_new_session_ticket(SSL *s);
 int ssl3_get_cert_status(SSL *s);
 int ssl3_get_server_done(SSL *s);
 int ssl3_send_client_verify(SSL *s);
-int ssl_do_client_cert_cb(SSL *s, X509 **px509, EVP_PKEY **ppkey);
 int ssl3_send_client_certificate(SSL *s);
+int ssl_do_client_cert_cb(SSL *s, X509 **px509, EVP_PKEY **ppkey);
 int ssl3_send_client_key_exchange(SSL *s);
 int ssl3_get_key_exchange(SSL *s);
 int ssl3_get_server_certificate(SSL *s);
 int ssl3_check_cert_and_algorithm(SSL *s);
 #ifndef OPENSSL_NO_TLSEXT
 int ssl3_check_finished(SSL *s);
+# ifndef OPENSSL_NO_NEXTPROTONEG
 int ssl3_send_next_proto(SSL *s);
+# endif
 #endif
 
 int dtls1_client_hello(SSL *s);
@@ -919,8 +994,9 @@ int ssl3_check_client_hello(SSL *s);
 int ssl3_get_client_certificate(SSL *s);
 int ssl3_get_client_key_exchange(SSL *s);
 int ssl3_get_cert_verify(SSL *s);
+#ifndef OPENSSL_NO_NEXTPROTONEG
 int ssl3_get_next_proto(SSL *s);
-int ssl3_snap_start_reset_for_recovery(SSL* s);
+#endif
 
 int dtls1_send_hello_request(SSL *s);
 int dtls1_send_server_hello(SSL *s);
@@ -941,7 +1017,6 @@ void tls1_free(SSL *s);
 void tls1_clear(SSL *s);
 long tls1_ctrl(SSL *s,int cmd, long larg, void *parg);
 long tls1_callback_ctrl(SSL *s,int cmd, void (*fp)(void));
-SSL_METHOD *tlsv1_base_method(void );
 
 int dtls1_new(SSL *s);
 int    dtls1_accept(SSL *s);
@@ -949,7 +1024,6 @@ int        dtls1_connect(SSL *s);
 void dtls1_free(SSL *s);
 void dtls1_clear(SSL *s);
 long dtls1_ctrl(SSL *s,int cmd, long larg, void *parg);
-SSL_METHOD *dtlsv1_base_method(void );
 
 long dtls1_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok);
 int dtls1_get_record(SSL *s);
@@ -964,20 +1038,30 @@ void ssl_free_wbio_buffer(SSL *s);
 int tls1_change_cipher_state(SSL *s, int which);
 int tls1_setup_key_block(SSL *s);
 int tls1_enc(SSL *s, int snd);
-int tls1_final_finish_mac(SSL *s, EVP_MD_CTX *in1_ctx, EVP_MD_CTX *in2_ctx,
+int tls1_final_finish_mac(SSL *s,
        const char *str, int slen, unsigned char *p);
-int tls1_cert_verify_mac(SSL *s, EVP_MD_CTX *in, unsigned char *p);
+int tls1_cert_verify_mac(SSL *s, int md_nid, unsigned char *p);
 int tls1_mac(SSL *ssl, unsigned char *md, int snd);
 int tls1_generate_master_secret(SSL *s, unsigned char *out,
        unsigned char *p, int len);
+int tls1_export_keying_material(SSL *s, unsigned char *out, size_t olen,
+       const char *label, size_t llen, const unsigned char *p,
+       size_t plen, int use_context);
 int tls1_alert_code(int code);
 int ssl3_alert_code(int code);
 int ssl_ok(SSL *s);
 
-int check_srvr_ecc_cert_and_alg(X509 *x, SSL_CIPHER *cs);
+#ifndef OPENSSL_NO_ECDH
+int ssl_check_srvr_ecc_cert_and_alg(X509 *x, const SSL_CIPHER *cs);
+#endif
 
 SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n);
 
+#ifndef OPENSSL_NO_EC
+int tls1_ec_curve_id2nid(int curve_id);
+int tls1_ec_nid2curve_id(int nid);
+#endif /* OPENSSL_NO_EC */
+
 #ifndef OPENSSL_NO_TLSEXT
 unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, unsigned char *limit); 
 unsigned char *ssl_add_serverhello_tlsext(SSL *s, unsigned char *p, unsigned char *limit); 
@@ -995,9 +1079,9 @@ int ssl_check_serverhello_tlsext(SSL *s);
 #endif
 int tls1_process_ticket(SSL *s, unsigned char *session_id, int len,
                                const unsigned char *limit, SSL_SESSION **ret);
+#endif
 EVP_MD_CTX* ssl_replace_hash(EVP_MD_CTX **hash,const EVP_MD *md) ;
 void ssl_clear_hash_ctx(EVP_MD_CTX **hash);
-
 int ssl_add_serverhello_renegotiate_ext(SSL *s, unsigned char *p, int *len,
                                        int maxlen);
 int ssl_parse_serverhello_renegotiate_ext(SSL *s, unsigned char *d, int len,
@@ -1007,5 +1091,3 @@ int ssl_add_clienthello_renegotiate_ext(SSL *s, unsigned char *p, int *len,
 int ssl_parse_clienthello_renegotiate_ext(SSL *s, unsigned char *d, int len,
                                          int *al);
 #endif
-
-#endif
index c0960b5..c43f3e2 100644 (file)
@@ -697,6 +697,42 @@ int SSL_CTX_use_PrivateKey_ASN1(int type, SSL_CTX *ctx, const unsigned char *d,
        }
 
 
+int SSL_use_certificate_chain(SSL *ssl, STACK_OF(X509) *cert_chain)
+       {
+       if (ssl == NULL)
+               {
+               SSLerr(SSL_F_SSL_USE_CERTIFICATE_CHAIN,ERR_R_PASSED_NULL_PARAMETER);
+               return(0);
+               }
+       if (ssl->cert == NULL)
+               {
+               SSLerr(SSL_F_SSL_USE_CERTIFICATE_CHAIN,SSL_R_NO_CERTIFICATE_ASSIGNED);
+               return(0);
+               }
+       if (ssl->cert->key == NULL)
+               {
+               SSLerr(SSL_F_SSL_USE_CERTIFICATE_CHAIN,SSL_R_NO_CERTIFICATE_ASSIGNED);
+               return(0);
+               }
+       ssl->cert->key->cert_chain = cert_chain;
+       return(1);
+       }
+
+STACK_OF(X509) *SSL_get_certificate_chain(SSL *ssl, X509 *x)
+       {
+       int i;
+       if (x == NULL)
+               return NULL;
+       if (ssl == NULL)
+               return NULL;
+       if (ssl->cert == NULL)
+               return NULL;
+       for (i = 0; i < SSL_PKEY_NUM; i++)
+               if (ssl->cert->pkeys[i].x509 == x)
+                       return ssl->cert->pkeys[i].cert_chain;
+       return NULL;
+       }
+
 #ifndef OPENSSL_NO_STDIO
 /* Read a file that contains our certificate in "PEM" format,
  * possibly followed by a sequence of CA certificates that should be
index e7802e1..93954e4 100644 (file)
  * copied and put under another distribution licence
  * [including the GNU Public Licence.]
  */
+/* ====================================================================
+ * Copyright (c) 1998-2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    openssl-core@openssl.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+/* ====================================================================
+ * Copyright 2005 Nokia. All rights reserved.
+ *
+ * The portions of the attached software ("Contribution") is developed by
+ * Nokia Corporation and is licensed pursuant to the OpenSSL open source
+ * license.
+ *
+ * The Contribution, originally written by Mika Kousa and Pasi Eronen of
+ * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
+ * support (see RFC 4279) to OpenSSL.
+ *
+ * No patent licenses or other rights except those expressly stated in
+ * the OpenSSL open source license shall be deemed granted or received
+ * expressly, by implication, estoppel, or otherwise.
+ *
+ * No assurances are provided by Nokia that the Contribution does not
+ * infringe the patent or other intellectual property rights of any third
+ * party or that the license provides you with all the necessary rights
+ * to make use of the Contribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
+ * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
+ * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
+ * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
+ * OTHERWISE.
+ */
 
 #include <stdio.h>
 #include <openssl/lhash.h>
@@ -127,8 +206,18 @@ SSL_SESSION *SSL_SESSION_new(void)
        ss->compress_meth=0;
 #ifndef OPENSSL_NO_TLSEXT
        ss->tlsext_hostname = NULL; 
+#ifndef OPENSSL_NO_EC
+       ss->tlsext_ecpointformatlist_length = 0;
+       ss->tlsext_ecpointformatlist = NULL;
+       ss->tlsext_ellipticcurvelist_length = 0;
+       ss->tlsext_ellipticcurvelist = NULL;
+#endif
 #endif
        CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data);
+#ifndef OPENSSL_NO_PSK
+       ss->psk_identity_hint=NULL;
+       ss->psk_identity=NULL;
+#endif
        return(ss);
        }
 
@@ -172,6 +261,11 @@ static int def_generate_session_id(const SSL *ssl, unsigned char *id,
        return 0;
 }
 
+void SSL_set_session_creation_enabled (SSL *s, int creation_enabled)
+       {
+       s->session_creation_enabled = creation_enabled;
+       }
+
 int ssl_get_new_session(SSL *s, int session)
        {
        /* This gets used by clients and servers. */
@@ -180,13 +274,15 @@ int ssl_get_new_session(SSL *s, int session)
        SSL_SESSION *ss=NULL;
        GEN_SESSION_CB cb = def_generate_session_id;
 
+       /* caller should check this if they can do better error handling */
+        if (!s->session_creation_enabled) return(0);
        if ((ss=SSL_SESSION_new()) == NULL) return(0);
 
        /* If the context has a default timeout, use it */
-       if (s->ctx->session_timeout == 0)
+       if (s->session_ctx->session_timeout == 0)
                ss->timeout=SSL_get_default_timeout(s);
        else
-               ss->timeout=s->ctx->session_timeout;
+               ss->timeout=s->session_ctx->session_timeout;
 
        if (s->session != NULL)
                {
@@ -239,8 +335,8 @@ int ssl_get_new_session(SSL *s, int session)
                CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
                if(s->generate_session_id)
                        cb = s->generate_session_id;
-               else if(s->ctx->generate_session_id)
-                       cb = s->ctx->generate_session_id;
+               else if(s->session_ctx->generate_session_id)
+                       cb = s->session_ctx->generate_session_id;
                CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
                /* Choose a session ID */
                tmp = ss->session_id_length;
@@ -286,6 +382,32 @@ int ssl_get_new_session(SSL *s, int session)
                                return 0;
                                }
                        }
+#ifndef OPENSSL_NO_EC
+               if (s->tlsext_ecpointformatlist)
+                       {
+                       if (ss->tlsext_ecpointformatlist != NULL) OPENSSL_free(ss->tlsext_ecpointformatlist);
+                       if ((ss->tlsext_ecpointformatlist = OPENSSL_malloc(s->tlsext_ecpointformatlist_length)) == NULL)
+                               {
+                               SSLerr(SSL_F_SSL_GET_NEW_SESSION, ERR_R_MALLOC_FAILURE);
+                               SSL_SESSION_free(ss);
+                               return 0;
+                               }
+                       ss->tlsext_ecpointformatlist_length = s->tlsext_ecpointformatlist_length;
+                       memcpy(ss->tlsext_ecpointformatlist, s->tlsext_ecpointformatlist, s->tlsext_ecpointformatlist_length);
+                       }
+               if (s->tlsext_ellipticcurvelist)
+                       {
+                       if (ss->tlsext_ellipticcurvelist != NULL) OPENSSL_free(ss->tlsext_ellipticcurvelist);
+                       if ((ss->tlsext_ellipticcurvelist = OPENSSL_malloc(s->tlsext_ellipticcurvelist_length)) == NULL)
+                               {
+                               SSLerr(SSL_F_SSL_GET_NEW_SESSION, ERR_R_MALLOC_FAILURE);
+                               SSL_SESSION_free(ss);
+                               return 0;
+                               }
+                       ss->tlsext_ellipticcurvelist_length = s->tlsext_ellipticcurvelist_length;
+                       memcpy(ss->tlsext_ellipticcurvelist, s->tlsext_ellipticcurvelist, s->tlsext_ellipticcurvelist_length);
+                       }
+#endif
 #endif
                }
        else
@@ -318,15 +440,15 @@ int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len,
 #ifndef OPENSSL_NO_TLSEXT
        int r;
 #endif
-  
+
        if (len > SSL_MAX_SSL_SESSION_ID_LENGTH)
                goto err;
 #ifndef OPENSSL_NO_TLSEXT
-       r = tls1_process_ticket(s, session_id, len, limit, &ret);
+       r = tls1_process_ticket(s, session_id, len, limit, &ret);
        if (r == -1)
                {
                fatal = 1;
-               goto err;
+               goto err;
                }
        else if (r == 0 || (!ret && !len))
                goto err;
@@ -334,7 +456,7 @@ int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len,
 #else
        if (len == 0)
                goto err;
-       if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_LOOKUP))
+       if (!(s->session_ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_LOOKUP))
 #endif
                {
                SSL_SESSION data;
@@ -342,9 +464,9 @@ int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len,
                data.session_id_length=len;
                if (len == 0)
                        return 0;
-               memcpy(data.session_id,session_id,len);
+               memcpy(data.session_id,session_id,len);
                CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
-               ret=(SSL_SESSION *)lh_retrieve(s->ctx->sessions,&data);
+               ret=lh_SSL_SESSION_retrieve(s->session_ctx->sessions,&data);
                if (ret != NULL)
                    /* don't allow other threads to steal it: */
                    CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);
@@ -355,13 +477,13 @@ int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len,
                {
                int copy=1;
        
-               s->ctx->stats.sess_miss++;
+               s->session_ctx->stats.sess_miss++;
                ret=NULL;
-               if (s->ctx->get_session_cb != NULL
-                   && (ret=s->ctx->get_session_cb(s,session_id,len,&copy))
+               if (s->session_ctx->get_session_cb != NULL
+                   && (ret=s->session_ctx->get_session_cb(s,session_id,len,&copy))
                       != NULL)
                        {
-                       s->ctx->stats.sess_cb_hit++;
+                       s->session_ctx->stats.sess_cb_hit++;
 
                        /* Increment reference count now if the session callback
                         * asks us to do so (note that if the session structures
@@ -373,10 +495,10 @@ int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len,
 
                        /* Add the externally cached session to the internal
                         * cache as well if and only if we are supposed to. */
-                       if(!(s->ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_STORE))
+                       if(!(s->session_ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_STORE))
                                /* The following should not return 1, otherwise,
                                 * things are very strange */
-                               SSL_CTX_add_session(s->ctx,ret);
+                               SSL_CTX_add_session(s->session_ctx,ret);
                        }
                if (ret == NULL)
                        goto err;
@@ -443,13 +565,13 @@ int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len,
 
        if (ret->timeout < (long)(time(NULL) - ret->time)) /* timeout */
                {
-               s->ctx->stats.sess_timeout++;
+               s->session_ctx->stats.sess_timeout++;
                /* remove it from the cache */
-               SSL_CTX_remove_session(s->ctx,ret);
+               SSL_CTX_remove_session(s->session_ctx,ret);
                goto err;
                }
 
-       s->ctx->stats.sess_hit++;
+       s->session_ctx->stats.sess_hit++;
 
        /* ret->time=time(NULL); */ /* rezero timeout? */
        /* again, just leave the session 
@@ -482,7 +604,7 @@ int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *c)
        /* if session c is in already in cache, we take back the increment later */
 
        CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
-       s=(SSL_SESSION *)lh_insert(ctx->sessions,c);
+       s=lh_SSL_SESSION_insert(ctx->sessions,c);
        
        /* s != NULL iff we already had a session with the given PID.
         * In this case, s == c should hold (then we did not really modify
@@ -548,10 +670,10 @@ static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)
        if ((c != NULL) && (c->session_id_length != 0))
                {
                if(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
-               if ((r = (SSL_SESSION *)lh_retrieve(ctx->sessions,c)) == c)
+               if ((r = lh_SSL_SESSION_retrieve(ctx->sessions,c)) == c)
                        {
                        ret=1;
-                       r=(SSL_SESSION *)lh_delete(ctx->sessions,c);
+                       r=lh_SSL_SESSION_delete(ctx->sessions,c);
                        SSL_SESSION_list_remove(ctx,c);
                        }
 
@@ -601,6 +723,18 @@ void SSL_SESSION_free(SSL_SESSION *ss)
 #ifndef OPENSSL_NO_TLSEXT
        if (ss->tlsext_hostname != NULL) OPENSSL_free(ss->tlsext_hostname);
        if (ss->tlsext_tick != NULL) OPENSSL_free(ss->tlsext_tick);
+#ifndef OPENSSL_NO_EC
+       ss->tlsext_ecpointformatlist_length = 0;
+       if (ss->tlsext_ecpointformatlist != NULL) OPENSSL_free(ss->tlsext_ecpointformatlist);
+       ss->tlsext_ellipticcurvelist_length = 0;
+       if (ss->tlsext_ellipticcurvelist != NULL) OPENSSL_free(ss->tlsext_ellipticcurvelist);
+#endif /* OPENSSL_NO_EC */
+#endif
+#ifndef OPENSSL_NO_PSK
+       if (ss->psk_identity_hint != NULL)
+               OPENSSL_free(ss->psk_identity_hint);
+       if (ss->psk_identity != NULL)
+               OPENSSL_free(ss->psk_identity);
 #endif
        OPENSSL_cleanse(ss,sizeof(*ss));
        OPENSSL_free(ss);
@@ -609,7 +743,7 @@ void SSL_SESSION_free(SSL_SESSION *ss)
 int SSL_set_session(SSL *s, SSL_SESSION *session)
        {
        int ret=0;
-       SSL_METHOD *meth;
+       const SSL_METHOD *meth;
 
        if (session != NULL)
                {
@@ -712,20 +846,75 @@ long SSL_CTX_get_timeout(const SSL_CTX *s)
        return(s->session_timeout);
        }
 
+#ifndef OPENSSL_NO_TLSEXT
+int SSL_set_session_secret_cb(SSL *s, int (*tls_session_secret_cb)(SSL *s, void *secret, int *secret_len,
+       STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg), void *arg)
+       {
+       if (s == NULL) return(0);
+       s->tls_session_secret_cb = tls_session_secret_cb;
+       s->tls_session_secret_cb_arg = arg;
+       return(1);
+       }
+
+int SSL_set_session_ticket_ext_cb(SSL *s, tls_session_ticket_ext_cb_fn cb,
+                                 void *arg)
+       {
+       if (s == NULL) return(0);
+       s->tls_session_ticket_ext_cb = cb;
+       s->tls_session_ticket_ext_cb_arg = arg;
+       return(1);
+       }
+
+int SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len)
+       {
+       if (s->version >= TLS1_VERSION)
+               {
+               if (s->tlsext_session_ticket)
+                       {
+                       OPENSSL_free(s->tlsext_session_ticket);
+                       s->tlsext_session_ticket = NULL;
+                       }
+
+               s->tlsext_session_ticket = OPENSSL_malloc(sizeof(TLS_SESSION_TICKET_EXT) + ext_len);
+               if (!s->tlsext_session_ticket)
+                       {
+                       SSLerr(SSL_F_SSL_SET_SESSION_TICKET_EXT, ERR_R_MALLOC_FAILURE);
+                       return 0;
+                       }
+
+               if (ext_data)
+                       {
+                       s->tlsext_session_ticket->length = ext_len;
+                       s->tlsext_session_ticket->data = s->tlsext_session_ticket + 1;
+                       memcpy(s->tlsext_session_ticket->data, ext_data, ext_len);
+                       }
+               else
+                       {
+                       s->tlsext_session_ticket->length = 0;
+                       s->tlsext_session_ticket->data = NULL;
+                       }
+
+               return 1;
+               }
+
+       return 0;
+       }
+#endif /* OPENSSL_NO_TLSEXT */
+
 typedef struct timeout_param_st
        {
        SSL_CTX *ctx;
        long time;
-       LHASH *cache;
+       LHASH_OF(SSL_SESSION) *cache;
        } TIMEOUT_PARAM;
 
-static void timeout(SSL_SESSION *s, TIMEOUT_PARAM *p)
+static void timeout_doall_arg(SSL_SESSION *s, TIMEOUT_PARAM *p)
        {
        if ((p->time == 0) || (p->time > (s->time+s->timeout))) /* timeout */
                {
                /* The reason we don't call SSL_CTX_remove_session() is to
                 * save on locking overhead */
-               lh_delete(p->cache,s);
+               (void)lh_SSL_SESSION_delete(p->cache,s);
                SSL_SESSION_list_remove(p->ctx,s);
                s->not_resumable=1;
                if (p->ctx->remove_session_cb != NULL)
@@ -734,7 +923,7 @@ static void timeout(SSL_SESSION *s, TIMEOUT_PARAM *p)
                }
        }
 
-static IMPLEMENT_LHASH_DOALL_ARG_FN(timeout, SSL_SESSION *, TIMEOUT_PARAM *)
+static IMPLEMENT_LHASH_DOALL_ARG_FN(timeout, SSL_SESSION, TIMEOUT_PARAM)
 
 void SSL_CTX_flush_sessions(SSL_CTX *s, long t)
        {
@@ -746,10 +935,11 @@ void SSL_CTX_flush_sessions(SSL_CTX *s, long t)
        if (tp.cache == NULL) return;
        tp.time=t;
        CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
-       i=tp.cache->down_load;
-       tp.cache->down_load=0;
-       lh_doall_arg(tp.cache, LHASH_DOALL_ARG_FN(timeout), &tp);
-       tp.cache->down_load=i;
+       i=CHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load;
+       CHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load=0;
+       lh_SSL_SESSION_doall_arg(tp.cache, LHASH_DOALL_ARG_FN(timeout),
+                                TIMEOUT_PARAM, &tp);
+       CHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load=i;
        CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
        }
 
@@ -909,3 +1099,4 @@ void SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx,
        ctx->app_verify_cookie_cb=cb;
        }
 
+IMPLEMENT_PEM_rw(SSL_SESSION, SSL_SESSION, PEM_STRING_SSL_SESSION, SSL_SESSION)
index e7509f0..144b81e 100644 (file)
  * copied and put under another distribution licence
  * [including the GNU Public Licence.]
  */
+/* ====================================================================
+ * Copyright 2005 Nokia. All rights reserved.
+ *
+ * The portions of the attached software ("Contribution") is developed by
+ * Nokia Corporation and is licensed pursuant to the OpenSSL open source
+ * license.
+ *
+ * The Contribution, originally written by Mika Kousa and Pasi Eronen of
+ * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
+ * support (see RFC 4279) to OpenSSL.
+ *
+ * No patent licenses or other rights except those expressly stated in
+ * the OpenSSL open source license shall be deemed granted or received
+ * expressly, by implication, estoppel, or otherwise.
+ *
+ * No assurances are provided by Nokia that the Contribution does not
+ * infringe the patent or other intellectual property rights of any third
+ * party or that the license provides you with all the necessary rights
+ * to make use of the Contribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
+ * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
+ * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
+ * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
+ * OTHERWISE.
+ */
 
 #include <stdio.h>
 #include "ssl_locl.h"
@@ -414,6 +440,12 @@ const char *SSL_alert_desc_string(int value)
        case TLS1_AD_INTERNAL_ERROR:            str="IE"; break;
        case TLS1_AD_USER_CANCELLED:            str="US"; break;
        case TLS1_AD_NO_RENEGOTIATION:          str="NR"; break;
+       case TLS1_AD_UNSUPPORTED_EXTENSION:     str="UE"; break;
+       case TLS1_AD_CERTIFICATE_UNOBTAINABLE:  str="CO"; break;
+       case TLS1_AD_UNRECOGNIZED_NAME:         str="UN"; break;
+       case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE: str="BR"; break;
+       case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE: str="BH"; break;
+       case TLS1_AD_UNKNOWN_PSK_IDENTITY:      str="UP"; break;
        default:                                str="UK"; break;
                }
        return(str);
@@ -497,6 +529,24 @@ const char *SSL_alert_desc_string_long(int value)
        case TLS1_AD_NO_RENEGOTIATION:
                str="no renegotiation";
                break;
+       case TLS1_AD_UNSUPPORTED_EXTENSION:
+               str="unsupported extension";
+               break;
+       case TLS1_AD_CERTIFICATE_UNOBTAINABLE:
+               str="certificate unobtainable";
+               break;
+       case TLS1_AD_UNRECOGNIZED_NAME:
+               str="unrecognized name";
+               break;
+       case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
+               str="bad certificate status response";
+               break;
+       case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE:
+               str="bad certificate hash value";
+               break;
+       case TLS1_AD_UNKNOWN_PSK_IDENTITY:
+               str="unknown PSK identity";
+               break;
        default: str="unknown"; break;
                }
        return(str);
index 81c1361..3122440 100644 (file)
  * copied and put under another distribution licence
  * [including the GNU Public Licence.]
  */
+/* ====================================================================
+ * Copyright 2005 Nokia. All rights reserved.
+ *
+ * The portions of the attached software ("Contribution") is developed by
+ * Nokia Corporation and is licensed pursuant to the OpenSSL open source
+ * license.
+ *
+ * The Contribution, originally written by Mika Kousa and Pasi Eronen of
+ * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
+ * support (see RFC 4279) to OpenSSL.
+ *
+ * No patent licenses or other rights except those expressly stated in
+ * the OpenSSL open source license shall be deemed granted or received
+ * expressly, by implication, estoppel, or otherwise.
+ *
+ * No assurances are provided by Nokia that the Contribution does not
+ * infringe the patent or other intellectual property rights of any third
+ * party or that the license provides you with all the necessary rights
+ * to make use of the Contribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
+ * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
+ * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
+ * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
+ * OTHERWISE.
+ */
 
 #include <stdio.h>
 #include <openssl/buffer.h>
@@ -155,6 +181,12 @@ int SSL_SESSION_print(BIO *bp, const SSL_SESSION *x)
                        if (BIO_printf(bp,"%02X",x->krb5_client_princ[i]) <= 0) goto err;
                        }
 #endif /* OPENSSL_NO_KRB5 */
+#ifndef OPENSSL_NO_PSK
+       if (BIO_puts(bp,"\n    PSK identity: ") <= 0) goto err;
+       if (BIO_printf(bp, "%s", x->psk_identity ? x->psk_identity : "None") <= 0) goto err;
+       if (BIO_puts(bp,"\n    PSK identity hint: ") <= 0) goto err;
+       if (BIO_printf(bp, "%s", x->psk_identity_hint ? x->psk_identity_hint : "None") <= 0) goto err;
+#endif
 #ifndef OPENSSL_NO_TLSEXT
        if (x->tlsext_tick_lifetime_hint)
                {
@@ -170,12 +202,13 @@ int SSL_SESSION_print(BIO *bp, const SSL_SESSION *x)
                        goto err;
                }
 #endif
+
 #ifndef OPENSSL_NO_COMP
        if (x->compress_meth != 0)
                {
                SSL_COMP *comp = NULL;
 
-               ssl_cipher_get_evp(x,NULL,NULL,&comp);
+               ssl_cipher_get_evp(x,NULL,NULL,NULL,NULL,&comp);
                if (comp == NULL)
                        {
                        if (BIO_printf(bp,"\n    Compression: %d",x->compress_meth) <= 0) goto err;
index 82768d9..f6a2c79 100644 (file)
  * ECC cipher suite support in OpenSSL originally developed by 
  * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
  */
+/* ====================================================================
+ * Copyright 2005 Nokia. All rights reserved.
+ *
+ * The portions of the attached software ("Contribution") is developed by
+ * Nokia Corporation and is licensed pursuant to the OpenSSL open source
+ * license.
+ *
+ * The Contribution, originally written by Mika Kousa and Pasi Eronen of
+ * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
+ * support (see RFC 4279) to OpenSSL.
+ *
+ * No patent licenses or other rights except those expressly stated in
+ * the OpenSSL open source license shall be deemed granted or received
+ * expressly, by implication, estoppel, or otherwise.
+ *
+ * No assurances are provided by Nokia that the Contribution does not
+ * infringe the patent or other intellectual property rights of any third
+ * party or that the license provides you with all the necessary rights
+ * to make use of the Contribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
+ * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
+ * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
+ * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
+ * OTHERWISE.
+ */
 
 #define _BSD_SOURCE 1          /* Or gethostname won't be declared properly
                                   on Linux and GNU platforms. */
 #define USE_SOCKETS
 #include "e_os.h"
 
+#ifdef OPENSSL_SYS_VMS
 #define _XOPEN_SOURCE 500      /* Or isascii won't be declared properly on
                                   VMS (at least with DECompHP C).  */
+#endif
+
 #include <ctype.h>
 
 #include <openssl/bio.h>
@@ -207,6 +236,16 @@ static DH *get_dh1024(void);
 static DH *get_dh1024dsa(void);
 #endif
 
+
+static char *psk_key=NULL; /* by default PSK is not used */
+#ifndef OPENSSL_NO_PSK
+static unsigned int psk_client_callback(SSL *ssl, const char *hint, char *identity,
+       unsigned int max_identity_len, unsigned char *psk,
+       unsigned int max_psk_len);
+static unsigned int psk_server_callback(SSL *ssl, const char *identity, unsigned char *psk,
+       unsigned int max_psk_len);
+#endif
+
 static BIO *bio_err=NULL;
 static BIO *bio_stdout=NULL;
 
@@ -229,9 +268,6 @@ static void sv_usage(void)
        {
        fprintf(stderr,"usage: ssltest [args ...]\n");
        fprintf(stderr,"\n");
-#ifdef OPENSSL_FIPS
-       fprintf(stderr,"-F             - run test in FIPS mode\n");
-#endif
        fprintf(stderr," -server_auth  - check server certificate\n");
        fprintf(stderr," -client_auth  - do client authentication\n");
        fprintf(stderr," -proxy        - allow proxy certificates\n");
@@ -250,6 +286,9 @@ static void sv_usage(void)
 #ifndef OPENSSL_NO_ECDH
        fprintf(stderr," -no_ecdhe     - disable ECDHE\n");
 #endif
+#ifndef OPENSSL_NO_PSK
+       fprintf(stderr," -psk arg      - PSK in hex (without 0x)\n");
+#endif
 #ifndef OPENSSL_NO_SSL2
        fprintf(stderr," -ssl2         - use SSLv2\n");
 #endif
@@ -277,12 +316,14 @@ static void sv_usage(void)
                       "                 (default is sect163r2).\n");
 #endif
        fprintf(stderr," -test_cipherlist - verifies the order of the ssl cipher lists\n");
-       fprintf(stderr," -cutthrough       - enable 1-RTT full-handshake for strong ciphers\n");
+       fprintf(stderr," -c_small_records - enable client side use of small SSL record buffers\n");
+       fprintf(stderr," -s_small_records - enable server side use of small SSL record buffers\n");
+       fprintf(stderr," -cutthrough      - enable 1-RTT full-handshake for strong ciphers\n");
        }
 
 static void print_details(SSL *c_ssl, const char *prefix)
        {
-       SSL_CIPHER *ciph;
+       const SSL_CIPHER *ciph;
        X509 *cert;
                
        ciph=SSL_get_current_cipher(c_ssl);
@@ -387,6 +428,29 @@ static void lock_dbg_cb(int mode, int type, const char *file, int line)
                }
        }
 
+#ifdef TLSEXT_TYPE_opaque_prf_input
+struct cb_info_st { void *input; size_t len; int ret; };
+struct cb_info_st co1 = { "C", 1, 1 }; /* try to negotiate oqaque PRF input */
+struct cb_info_st co2 = { "C", 1, 2 }; /* insist on oqaque PRF input */
+struct cb_info_st so1 = { "S", 1, 1 }; /* try to negotiate oqaque PRF input */
+struct cb_info_st so2 = { "S", 1, 2 }; /* insist on oqaque PRF input */
+
+int opaque_prf_input_cb(SSL *ssl, void *peerinput, size_t len, void *arg_)
+       {
+       struct cb_info_st *arg = arg_;
+
+       if (arg == NULL)
+               return 1;
+       
+       if (!SSL_set_tlsext_opaque_prf_input(ssl, arg->input, arg->len))
+               return 0;
+       return arg->ret;
+       }
+#endif
+       int ssl_mode = 0;
+       int c_small_records=0;
+       int s_small_records=0;
+       int cutthrough = 0;
 
 int main(int argc, char *argv[])
        {
@@ -408,19 +472,20 @@ int main(int argc, char *argv[])
 #endif
        SSL_CTX *s_ctx=NULL;
        SSL_CTX *c_ctx=NULL;
-       SSL_METHOD *meth=NULL;
+       const SSL_METHOD *meth=NULL;
        SSL *c_ssl,*s_ssl;
        int number=1,reuse=0;
        long bytes=256L;
 #ifndef OPENSSL_NO_DH
        DH *dh;
-       int dhe1024 = 1, dhe1024dsa = 0;
+       int dhe1024 = 0, dhe1024dsa = 0;
 #endif
 #ifndef OPENSSL_NO_ECDH
        EC_KEY *ecdh = NULL;
 #endif
        int no_dhe = 0;
        int no_ecdhe = 0;
+       int no_psk = 0;
        int print_time = 0;
        clock_t s_time = 0, c_time = 0;
        int comp = 0;
@@ -429,17 +494,12 @@ int main(int argc, char *argv[])
 #endif
        STACK_OF(SSL_COMP) *ssl_comp_methods = NULL;
        int test_cipherlist = 0;
-#ifdef OPENSSL_FIPS
-       int fips_mode=0;
-#endif
-       int ssl_mode = 0;
-       int cutthrough = 0;
 
        verbose = 0;
        debug = 0;
        cipher = 0;
 
-       bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); 
+       bio_err=BIO_new_fp(stderr,BIO_NOCLOSE|BIO_FP_TEXT);     
 
        CRYPTO_set_locking_callback(lock_dbg_cb);
 
@@ -458,23 +518,14 @@ int main(int argc, char *argv[])
 
        RAND_seed(rnd_seed, sizeof rnd_seed);
 
-       bio_stdout=BIO_new_fp(stdout,BIO_NOCLOSE);
+       bio_stdout=BIO_new_fp(stdout,BIO_NOCLOSE|BIO_FP_TEXT);
 
        argc--;
        argv++;
 
        while (argc >= 1)
                {
-               if(!strcmp(*argv,"-F"))
-                       {
-#ifdef OPENSSL_FIPS
-                       fips_mode=1;
-#else
-                       fprintf(stderr,"not compiled with FIPS support, so exitting without running.\n");
-                       EXIT(0);
-#endif
-                       }
-               else if (strcmp(*argv,"-server_auth") == 0)
+               if      (strcmp(*argv,"-server_auth") == 0)
                        server_auth=1;
                else if (strcmp(*argv,"-client_auth") == 0)
                        client_auth=1;
@@ -514,6 +565,20 @@ int main(int argc, char *argv[])
                        no_dhe=1;
                else if (strcmp(*argv,"-no_ecdhe") == 0)
                        no_ecdhe=1;
+               else if (strcmp(*argv,"-psk") == 0)
+                       {
+                       if (--argc < 1) goto bad;
+                       psk_key=*(++argv);
+#ifndef OPENSSL_NO_PSK
+                       if (strspn(psk_key, "abcdefABCDEF1234567890") != strlen(psk_key))
+                               {
+                               BIO_printf(bio_err,"Not a hex number '%s'\n",*argv);
+                               goto bad;
+                               }
+#else
+                       no_psk=1;
+#endif
+                       }
                else if (strcmp(*argv,"-ssl2") == 0)
                        ssl2=1;
                else if (strcmp(*argv,"-tls1") == 0)
@@ -622,6 +687,14 @@ int main(int argc, char *argv[])
                        {
                        test_cipherlist = 1;
                        }
+               else if (strcmp(*argv, "-c_small_records") == 0)
+                       {
+                       c_small_records = 1;
+                       }
+               else if (strcmp(*argv, "-s_small_records") == 0)
+                       {
+                       s_small_records = 1;
+                       }
                else if (strcmp(*argv, "-cutthrough") == 0)
                        {
                        cutthrough = 1;
@@ -660,20 +733,6 @@ bad:
                EXIT(1);
                }
 
-#ifdef OPENSSL_FIPS
-       if(fips_mode)
-               {
-               if(!FIPS_mode_set(1))
-                       {
-                       ERR_load_crypto_strings();
-                       ERR_print_errors(BIO_new_fp(stderr,BIO_NOCLOSE));
-                       EXIT(1);
-                       }
-               else
-                       fprintf(stderr,"*** IN FIPS MODE ***\n");
-               }
-#endif
-
        if (print_time)
                {
                if (!bio_pair)
@@ -761,6 +820,21 @@ bad:
                SSL_CTX_set_cipher_list(c_ctx,cipher);
                SSL_CTX_set_cipher_list(s_ctx,cipher);
                }
+
+       ssl_mode = 0;
+       if (c_small_records)
+               {
+               ssl_mode = SSL_CTX_get_mode(c_ctx);
+               ssl_mode |= SSL_MODE_SMALL_BUFFERS;
+               SSL_CTX_set_mode(c_ctx, ssl_mode);
+               }
+       ssl_mode = 0;
+       if (s_small_records)
+               {
+               ssl_mode = SSL_CTX_get_mode(s_ctx);
+               ssl_mode |= SSL_MODE_SMALL_BUFFERS;
+               SSL_CTX_set_mode(s_ctx, ssl_mode);
+               }
        ssl_mode = 0;
        if (cutthrough)
                {
@@ -825,6 +899,13 @@ bad:
        SSL_CTX_set_tmp_rsa_callback(s_ctx,tmp_rsa_cb);
 #endif
 
+#ifdef TLSEXT_TYPE_opaque_prf_input
+       SSL_CTX_set_tlsext_opaque_prf_input_callback(c_ctx, opaque_prf_input_cb);
+       SSL_CTX_set_tlsext_opaque_prf_input_callback(s_ctx, opaque_prf_input_cb);
+       SSL_CTX_set_tlsext_opaque_prf_input_callback_arg(c_ctx, &co1); /* or &co2 or NULL */
+       SSL_CTX_set_tlsext_opaque_prf_input_callback_arg(s_ctx, &so1); /* or &so2 or NULL */
+#endif
+
        if (!SSL_CTX_use_certificate_file(s_ctx,server_cert,SSL_FILETYPE_PEM))
                {
                ERR_print_errors(bio_err);
@@ -876,6 +957,31 @@ bad:
                SSL_CTX_set_session_id_context(s_ctx, (void *)&session_id_context, sizeof session_id_context);
        }
 
+       /* Use PSK only if PSK key is given */
+       if (psk_key != NULL)
+               {
+               /* no_psk is used to avoid putting psk command to openssl tool */
+               if (no_psk)
+                       {
+                       /* if PSK is not compiled in and psk key is
+                        * given, do nothing and exit successfully */
+                       ret=0;
+                       goto end;
+                       }
+#ifndef OPENSSL_NO_PSK
+               SSL_CTX_set_psk_client_callback(c_ctx, psk_client_callback);
+               SSL_CTX_set_psk_server_callback(s_ctx, psk_server_callback);
+               if (debug)
+                       BIO_printf(bio_err,"setting PSK identity hint to s_ctx\n");
+               if (!SSL_CTX_use_psk_identity_hint(s_ctx, "ctx server identity_hint"))
+                       {
+                       BIO_printf(bio_err,"error setting PSK identity hint to s_ctx\n");
+                       ERR_print_errors(bio_err);
+                       goto end;
+                       }
+#endif
+               }
+
        c_ssl=SSL_new(c_ctx);
        s_ssl=SSL_new(s_ctx);
 
@@ -952,7 +1058,7 @@ end:
 #endif
        CRYPTO_cleanup_all_ex_data();
        ERR_free_strings();
-       ERR_remove_state(0);
+       ERR_remove_thread_state(NULL);
        EVP_cleanup();
        CRYPTO_mem_leaks(bio_err);
        if (bio_err != NULL) BIO_free(bio_err);
@@ -2099,7 +2205,15 @@ static int MS_CALLBACK app_verify_callback(X509_STORE_CTX *ctx, void *arg)
                }
 
 #ifndef OPENSSL_NO_X509_VERIFY
+# ifdef OPENSSL_FIPS
+       if(s->version == TLS1_VERSION)
+               FIPS_allow_md5(1);
+# endif
        ok = X509_verify_cert(ctx);
+# ifdef OPENSSL_FIPS
+       if(s->version == TLS1_VERSION)
+               FIPS_allow_md5(0);
+# endif
 #endif
 
        if (cb_arg->proxy_auth)
@@ -2268,11 +2382,74 @@ static DH *get_dh1024dsa()
        }
 #endif
 
+#ifndef OPENSSL_NO_PSK
+/* convert the PSK key (psk_key) in ascii to binary (psk) */
+static int psk_key2bn(const char *pskkey, unsigned char *psk,
+       unsigned int max_psk_len)
+       {
+       int ret;
+       BIGNUM *bn = NULL;
+
+       ret = BN_hex2bn(&bn, pskkey);
+       if (!ret)
+               {
+               BIO_printf(bio_err,"Could not convert PSK key '%s' to BIGNUM\n", pskkey); 
+               if (bn)
+                       BN_free(bn);
+               return 0;
+               }
+       if (BN_num_bytes(bn) > (int)max_psk_len)
+               {
+               BIO_printf(bio_err,"psk buffer of callback is too small (%d) for key (%d)\n",
+                       max_psk_len, BN_num_bytes(bn));
+               BN_free(bn);
+               return 0;
+               }
+       ret = BN_bn2bin(bn, psk);
+       BN_free(bn);
+       return ret;
+       }
+
+static unsigned int psk_client_callback(SSL *ssl, const char *hint, char *identity,
+       unsigned int max_identity_len, unsigned char *psk,
+       unsigned int max_psk_len)
+       {
+       int ret;
+       unsigned int psk_len = 0;
+
+       ret = BIO_snprintf(identity, max_identity_len, "Client_identity");
+       if (ret < 0)
+               goto out_err;
+       if (debug)
+               fprintf(stderr, "client: created identity '%s' len=%d\n", identity, ret);
+       ret = psk_key2bn(psk_key, psk, max_psk_len);
+       if (ret < 0)
+               goto out_err;
+       psk_len = ret;
+out_err:
+       return psk_len;
+       }
+
+static unsigned int psk_server_callback(SSL *ssl, const char *identity,
+       unsigned char *psk, unsigned int max_psk_len)
+       {
+       unsigned int psk_len=0;
+
+       if (strcmp(identity, "Client_identity") != 0)
+               {
+               BIO_printf(bio_err, "server: PSK error: client identity not found\n");
+               return 0;
+               }
+       psk_len=psk_key2bn(psk_key, psk, max_psk_len);
+       return psk_len;
+       }
+#endif
+
 static int do_test_cipherlist(void)
        {
        int i = 0;
        const SSL_METHOD *meth;
-       SSL_CIPHER *ci, *tci = NULL;
+       const SSL_CIPHER *ci, *tci = NULL;
 
 #ifndef OPENSSL_NO_SSL2
        fprintf(stderr, "testing SSLv2 cipher list order: ");
index 4d1e198..c87af17 100644 (file)
@@ -63,8 +63,8 @@
 #include <openssl/objects.h>
 #include <openssl/evp.h>
 
-static SSL_METHOD *tls1_get_client_method(int ver);
-static SSL_METHOD *tls1_get_client_method(int ver)
+static const SSL_METHOD *tls1_get_client_method(int ver);
+static const SSL_METHOD *tls1_get_client_method(int ver)
        {
        if (ver == TLS1_VERSION)
                return(TLSv1_client_method());
index 3483098..b1d5b28 100644 (file)
@@ -56,7 +56,7 @@
  * [including the GNU Public Licence.]
  */
 /* ====================================================================
- * Copyright (c) 1998-2002 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2007 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * Hudson (tjh@cryptsoft.com).
  *
  */
+/* ====================================================================
+ * Copyright 2005 Nokia. All rights reserved.
+ *
+ * The portions of the attached software ("Contribution") is developed by
+ * Nokia Corporation and is licensed pursuant to the OpenSSL open source
+ * license.
+ *
+ * The Contribution, originally written by Mika Kousa and Pasi Eronen of
+ * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
+ * support (see RFC 4279) to OpenSSL.
+ *
+ * No patent licenses or other rights except those expressly stated in
+ * the OpenSSL open source license shall be deemed granted or received
+ * expressly, by implication, estoppel, or otherwise.
+ *
+ * No assurances are provided by Nokia that the Contribution does not
+ * infringe the patent or other intellectual property rights of any third
+ * party or that the license provides you with all the necessary rights
+ * to make use of the Contribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
+ * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
+ * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
+ * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
+ * OTHERWISE.
+ */
 
 #include <stdio.h>
 #include "ssl_locl.h"
 #include <openssl/des.h>
 #endif
 
-static void tls1_P_hash(const EVP_MD *md, const unsigned char *sec,
-                       int sec_len, unsigned char *seed, int seed_len,
+/* seed1 through seed5 are virtually concatenated */
+static int tls1_P_hash(const EVP_MD *md, const unsigned char *sec,
+                       int sec_len,
+                       const void *seed1, int seed1_len,
+                       const void *seed2, int seed2_len,
+                       const void *seed3, int seed3_len,
+                       const void *seed4, int seed4_len,
+                       const void *seed5, int seed5_len,
                        unsigned char *out, int olen)
        {
        int chunk;
@@ -131,83 +163,132 @@ static void tls1_P_hash(const EVP_MD *md, const unsigned char *sec,
        HMAC_CTX ctx_tmp;
        unsigned char A1[EVP_MAX_MD_SIZE];
        unsigned int A1_len;
+       int ret = 0;
        
        chunk=EVP_MD_size(md);
+       OPENSSL_assert(chunk >= 0);
 
        HMAC_CTX_init(&ctx);
        HMAC_CTX_init(&ctx_tmp);
-       HMAC_CTX_set_flags(&ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
-       HMAC_CTX_set_flags(&ctx_tmp, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
-       HMAC_Init_ex(&ctx,sec,sec_len,md, NULL);
-       HMAC_Init_ex(&ctx_tmp,sec,sec_len,md, NULL);
-       HMAC_Update(&ctx,seed,seed_len);
-       HMAC_Final(&ctx,A1,&A1_len);
+       if (!HMAC_Init_ex(&ctx,sec,sec_len,md, NULL))
+               goto err;
+       if (!HMAC_Init_ex(&ctx_tmp,sec,sec_len,md, NULL))
+               goto err;
+       if (seed1 != NULL && !HMAC_Update(&ctx,seed1,seed1_len))
+               goto err;
+       if (seed2 != NULL && !HMAC_Update(&ctx,seed2,seed2_len))
+               goto err;
+       if (seed3 != NULL && !HMAC_Update(&ctx,seed3,seed3_len))
+               goto err;
+       if (seed4 != NULL && !HMAC_Update(&ctx,seed4,seed4_len))
+               goto err;
+       if (seed5 != NULL && !HMAC_Update(&ctx,seed5,seed5_len))
+               goto err;
+       if (!HMAC_Final(&ctx,A1,&A1_len))
+               goto err;
 
        for (;;)
                {
-               HMAC_Init_ex(&ctx,NULL,0,NULL,NULL); /* re-init */
-               HMAC_Init_ex(&ctx_tmp,NULL,0,NULL,NULL); /* re-init */
-               HMAC_Update(&ctx,A1,A1_len);
-               HMAC_Update(&ctx_tmp,A1,A1_len);
-               HMAC_Update(&ctx,seed,seed_len);
+               if (!HMAC_Init_ex(&ctx,NULL,0,NULL,NULL)) /* re-init */
+                       goto err;
+               if (!HMAC_Init_ex(&ctx_tmp,NULL,0,NULL,NULL)) /* re-init */
+                       goto err;
+               if (!HMAC_Update(&ctx,A1,A1_len))
+                       goto err;
+               if (!HMAC_Update(&ctx_tmp,A1,A1_len))
+                       goto err;
+               if (seed1 != NULL && !HMAC_Update(&ctx,seed1,seed1_len))
+                       goto err;
+               if (seed2 != NULL && !HMAC_Update(&ctx,seed2,seed2_len))
+                       goto err;
+               if (seed3 != NULL && !HMAC_Update(&ctx,seed3,seed3_len))
+                       goto err;
+               if (seed4 != NULL && !HMAC_Update(&ctx,seed4,seed4_len))
+                       goto err;
+               if (seed5 != NULL && !HMAC_Update(&ctx,seed5,seed5_len))
+                       goto err;
 
                if (olen > chunk)
                        {
-                       HMAC_Final(&ctx,out,&j);
+                       if (!HMAC_Final(&ctx,out,&j))
+                               goto err;
                        out+=j;
                        olen-=j;
-                       HMAC_Final(&ctx_tmp,A1,&A1_len); /* calc the next A1 value */
+                       if (!HMAC_Final(&ctx_tmp,A1,&A1_len)) /* calc the next A1 value */
+                               goto err;
                        }
                else    /* last one */
                        {
-                       HMAC_Final(&ctx,A1,&A1_len);
+                       if (!HMAC_Final(&ctx,A1,&A1_len))
+                               goto err;
                        memcpy(out,A1,olen);
                        break;
                        }
                }
+       ret = 1;
+err:
        HMAC_CTX_cleanup(&ctx);
        HMAC_CTX_cleanup(&ctx_tmp);
        OPENSSL_cleanse(A1,sizeof(A1));
+       return ret;
        }
 
-static void tls1_PRF(const EVP_MD *md5, const EVP_MD *sha1,
-                    unsigned char *label, int label_len,
-                    const unsigned char *sec, int slen, unsigned char *out1,
+/* seed1 through seed5 are virtually concatenated */
+static int tls1_PRF(long digest_mask,
+                    const void *seed1, int seed1_len,
+                    const void *seed2, int seed2_len,
+                    const void *seed3, int seed3_len,
+                    const void *seed4, int seed4_len,
+                    const void *seed5, int seed5_len,
+                    const unsigned char *sec, int slen,
+                    unsigned char *out1,
                     unsigned char *out2, int olen)
        {
-       int len,i;
-       const unsigned char *S1,*S2;
-
-       len=slen/2;
+       int len,i,idx,count;
+       const unsigned char *S1;
+       long m;
+       const EVP_MD *md;
+       int ret = 0;
+
+       /* Count number of digests and partition sec evenly */
+       count=0;
+       for (idx=0;ssl_get_handshake_digest(idx,&m,&md);idx++) {
+               if ((m<<TLS1_PRF_DGST_SHIFT) & digest_mask) count++;
+       }       
+       len=slen/count;
        S1=sec;
-       S2= &(sec[len]);
-       len+=(slen&1); /* add for odd, make longer */
-
-       
-       tls1_P_hash(md5 ,S1,len,label,label_len,out1,olen);
-       tls1_P_hash(sha1,S2,len,label,label_len,out2,olen);
-
-       for (i=0; i<olen; i++)
-               out1[i]^=out2[i];
+       memset(out1,0,olen);
+       for (idx=0;ssl_get_handshake_digest(idx,&m,&md);idx++) {
+               if ((m<<TLS1_PRF_DGST_SHIFT) & digest_mask) {
+                       if (!md) {
+                               SSLerr(SSL_F_TLS1_PRF,
+                               SSL_R_UNSUPPORTED_DIGEST_TYPE);
+                               goto err;                               
+                       }
+                       if (!tls1_P_hash(md ,S1,len+(slen&1),
+                                       seed1,seed1_len,seed2,seed2_len,seed3,seed3_len,seed4,seed4_len,seed5,seed5_len,
+                                       out2,olen))
+                               goto err;
+                       S1+=len;
+                       for (i=0; i<olen; i++)
+                       {
+                               out1[i]^=out2[i];
+                       }
+               }
        }
-
-static void tls1_generate_key_block(SSL *s, unsigned char *km,
+       ret = 1;
+err:
+       return ret;
+}
+static int tls1_generate_key_block(SSL *s, unsigned char *km,
             unsigned char *tmp, int num)
        {
-       unsigned char *p;
-       unsigned char buf[SSL3_RANDOM_SIZE*2+
-               TLS_MD_MAX_CONST_SIZE];
-       p=buf;
-
-       memcpy(p,TLS_MD_KEY_EXPANSION_CONST,
-               TLS_MD_KEY_EXPANSION_CONST_SIZE);
-       p+=TLS_MD_KEY_EXPANSION_CONST_SIZE;
-       memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE);
-       p+=SSL3_RANDOM_SIZE;
-       memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE);
-       p+=SSL3_RANDOM_SIZE;
-
-       tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,(int)(p-buf),
+       int ret;
+       ret = tls1_PRF(s->s3->tmp.new_cipher->algorithm2,
+                TLS_MD_KEY_EXPANSION_CONST,TLS_MD_KEY_EXPANSION_CONST_SIZE,
+                s->s3->server_random,SSL3_RANDOM_SIZE,
+                s->s3->client_random,SSL3_RANDOM_SIZE,
+                NULL,0,NULL,0,
                 s->session->master_key,s->session->master_key_length,
                 km,tmp,num);
 #ifdef KSSL_DEBUG
@@ -221,14 +302,14 @@ static void tls1_generate_key_block(SSL *s, unsigned char *km,
                 }
         printf("\n");  }
 #endif    /* KSSL_DEBUG */
+       return ret;
        }
 
 int tls1_change_cipher_state(SSL *s, int which)
        {
        static const unsigned char empty[]="";
        unsigned char *p,*mac_secret;
-       unsigned char *exp_label,buf[TLS_MD_MAX_CONST_SIZE+
-               SSL3_RANDOM_SIZE*2];
+       unsigned char *exp_label;
        unsigned char tmp1[EVP_MAX_KEY_LENGTH];
        unsigned char tmp2[EVP_MAX_KEY_LENGTH];
        unsigned char iv1[EVP_MAX_IV_LENGTH*2];
@@ -241,35 +322,45 @@ int tls1_change_cipher_state(SSL *s, int which)
        const SSL_COMP *comp;
 #endif
        const EVP_MD *m;
+       int mac_type;
+       int *mac_secret_size;
+       EVP_MD_CTX *mac_ctx;
+       EVP_PKEY *mac_key;
        int is_export,n,i,j,k,exp_label_len,cl;
        int reuse_dd = 0;
 
        is_export=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher);
        c=s->s3->tmp.new_sym_enc;
        m=s->s3->tmp.new_hash;
+       mac_type = s->s3->tmp.new_mac_pkey_type;
 #ifndef OPENSSL_NO_COMP
        comp=s->s3->tmp.new_compression;
 #endif
 
 #ifdef KSSL_DEBUG
-       key_block=s->s3->tmp.key_block;
-
        printf("tls1_change_cipher_state(which= %d) w/\n", which);
-       printf("\talg= %ld, comp= %p\n", s->s3->tmp.new_cipher->algorithms,
-                (void *)comp);
-       printf("\tevp_cipher == %p ==? &d_cbc_ede_cipher3\n", (void *)c);
+       printf("\talg= %ld/%ld, comp= %p\n",
+              s->s3->tmp.new_cipher->algorithm_mkey,
+              s->s3->tmp.new_cipher->algorithm_auth,
+              comp);
+       printf("\tevp_cipher == %p ==? &d_cbc_ede_cipher3\n", c);
        printf("\tevp_cipher: nid, blksz= %d, %d, keylen=%d, ivlen=%d\n",
                 c->nid,c->block_size,c->key_len,c->iv_len);
        printf("\tkey_block: len= %d, data= ", s->s3->tmp.key_block_length);
        {
-        int ki;
-        for (ki=0; ki<s->s3->tmp.key_block_length; ki++)
-               printf("%02x", key_block[ki]);  printf("\n");
+        int i;
+        for (i=0; i<s->s3->tmp.key_block_length; i++)
+               printf("%02x", key_block[i]);  printf("\n");
         }
 #endif /* KSSL_DEBUG */
 
        if (which & SSL3_CC_READ)
                {
+               if (s->s3->tmp.new_cipher->algorithm2 & TLS1_STREAM_MAC)
+                       s->mac_flags |= SSL_MAC_FLAG_READ_MAC_STREAM;
+                       else
+                       s->mac_flags &= ~SSL_MAC_FLAG_READ_MAC_STREAM;
+
                if (s->enc_read_ctx != NULL)
                        reuse_dd = 1;
                else if ((s->enc_read_ctx=OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL)
@@ -278,7 +369,7 @@ int tls1_change_cipher_state(SSL *s, int which)
                        /* make sure it's intialized in case we exit later with an error */
                        EVP_CIPHER_CTX_init(s->enc_read_ctx);
                dd= s->enc_read_ctx;
-               s->read_hash=m;
+               mac_ctx=ssl_replace_hash(&s->read_hash,NULL);
 #ifndef OPENSSL_NO_COMP
                if (s->expand != NULL)
                        {
@@ -304,9 +395,14 @@ int tls1_change_cipher_state(SSL *s, int which)
                if (s->version != DTLS1_VERSION)
                        memset(&(s->s3->read_sequence[0]),0,8);
                mac_secret= &(s->s3->read_mac_secret[0]);
+               mac_secret_size=&(s->s3->read_mac_secret_size);
                }
        else
                {
+               if (s->s3->tmp.new_cipher->algorithm2 & TLS1_STREAM_MAC)
+                       s->mac_flags |= SSL_MAC_FLAG_WRITE_MAC_STREAM;
+                       else
+                       s->mac_flags &= ~SSL_MAC_FLAG_WRITE_MAC_STREAM;
                if (s->enc_write_ctx != NULL)
                        reuse_dd = 1;
                else if ((s->enc_write_ctx=OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL)
@@ -315,7 +411,7 @@ int tls1_change_cipher_state(SSL *s, int which)
                        /* make sure it's intialized in case we exit later with an error */
                        EVP_CIPHER_CTX_init(s->enc_write_ctx);
                dd= s->enc_write_ctx;
-               s->write_hash=m;
+               mac_ctx = ssl_replace_hash(&s->write_hash,NULL);
 #ifndef OPENSSL_NO_COMP
                if (s->compress != NULL)
                        {
@@ -336,13 +432,15 @@ int tls1_change_cipher_state(SSL *s, int which)
                if (s->version != DTLS1_VERSION)
                        memset(&(s->s3->write_sequence[0]),0,8);
                mac_secret= &(s->s3->write_mac_secret[0]);
+               mac_secret_size = &(s->s3->write_mac_secret_size);
                }
 
        if (reuse_dd)
                EVP_CIPHER_CTX_cleanup(dd);
 
        p=s->s3->tmp.key_block;
-       i=EVP_MD_size(m);
+       i=*mac_secret_size=s->s3->tmp.new_mac_secret_size;
+
        cl=EVP_CIPHER_key_length(c);
        j=is_export ? (cl < SSL_C_EXPORT_KEYLENGTH(s->s3->tmp.new_cipher) ?
                       cl : SSL_C_EXPORT_KEYLENGTH(s->s3->tmp.new_cipher)) : cl;
@@ -376,6 +474,10 @@ int tls1_change_cipher_state(SSL *s, int which)
                }
 
        memcpy(mac_secret,ms,i);
+       mac_key = EVP_PKEY_new_mac_key(mac_type, NULL,
+                       mac_secret,*mac_secret_size);
+       EVP_DigestSignInit(mac_ctx,NULL,m,NULL,mac_key);
+       EVP_PKEY_free(mac_key);
 #ifdef TLS_DEBUG
 printf("which = %04X\nmac key=",which);
 { int z; for (z=0; z<i; z++) printf("%02X%c",ms[z],((z+1)%16)?' ':'\n'); }
@@ -385,29 +487,24 @@ printf("which = %04X\nmac key=",which);
                /* In here I set both the read and write key/iv to the
                 * same value since only the correct one will be used :-).
                 */
-               p=buf;
-               memcpy(p,exp_label,exp_label_len);
-               p+=exp_label_len;
-               memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE);
-               p+=SSL3_RANDOM_SIZE;
-               memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE);
-               p+=SSL3_RANDOM_SIZE;
-               tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,(int)(p-buf),key,j,
-                        tmp1,tmp2,EVP_CIPHER_key_length(c));
+               if (!tls1_PRF(s->s3->tmp.new_cipher->algorithm2,
+                               exp_label,exp_label_len,
+                               s->s3->client_random,SSL3_RANDOM_SIZE,
+                               s->s3->server_random,SSL3_RANDOM_SIZE,
+                               NULL,0,NULL,0,
+                               key,j,tmp1,tmp2,EVP_CIPHER_key_length(c)))
+                       goto err2;
                key=tmp1;
 
                if (k > 0)
                        {
-                       p=buf;
-                       memcpy(p,TLS_MD_IV_BLOCK_CONST,
-                               TLS_MD_IV_BLOCK_CONST_SIZE);
-                       p+=TLS_MD_IV_BLOCK_CONST_SIZE;
-                       memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE);
-                       p+=SSL3_RANDOM_SIZE;
-                       memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE);
-                       p+=SSL3_RANDOM_SIZE;
-                       tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,p-buf,empty,0,
-                                iv1,iv2,k*2);
+                       if (!tls1_PRF(s->s3->tmp.new_cipher->algorithm2,
+                                       TLS_MD_IV_BLOCK_CONST,TLS_MD_IV_BLOCK_CONST_SIZE,
+                                       s->s3->client_random,SSL3_RANDOM_SIZE,
+                                       s->s3->server_random,SSL3_RANDOM_SIZE,
+                                       NULL,0,NULL,0,
+                                       empty,0,iv1,iv2,k*2))
+                               goto err2;
                        if (client_write)
                                iv=iv1;
                        else
@@ -418,13 +515,11 @@ printf("which = %04X\nmac key=",which);
        s->session->key_arg_length=0;
 #ifdef KSSL_DEBUG
        {
-        int ki;
+        int i;
        printf("EVP_CipherInit_ex(dd,c,key=,iv=,which)\n");
-       printf("\tkey= ");
-       for (ki=0; ki<c->key_len; ki++) printf("%02x", key[ki]);
+       printf("\tkey= "); for (i=0; i<c->key_len; i++) printf("%02x", key[i]);
        printf("\n");
-       printf("\t iv= ");
-       for (ki=0; ki<c->iv_len; ki++) printf("%02x", iv[ki]);
+       printf("\t iv= "); for (i=0; i<c->iv_len; i++) printf("%02x", iv[i]);
        printf("\n");
        }
 #endif /* KSSL_DEBUG */
@@ -451,11 +546,13 @@ err2:
 
 int tls1_setup_key_block(SSL *s)
        {
-       unsigned char *p1,*p2;
+       unsigned char *p1,*p2=NULL;
        const EVP_CIPHER *c;
        const EVP_MD *hash;
        int num;
        SSL_COMP *comp;
+       int mac_type= NID_undef,mac_secret_size=0;
+       int ret=0;
 
 #ifdef KSSL_DEBUG
        printf ("tls1_setup_key_block()\n");
@@ -464,7 +561,7 @@ int tls1_setup_key_block(SSL *s)
        if (s->s3->tmp.key_block_length != 0)
                return(1);
 
-       if (!ssl_cipher_get_evp(s->session,&c,&hash,&comp))
+       if (!ssl_cipher_get_evp(s->session,&c,&hash,&mac_type,&mac_secret_size,&comp))
                {
                SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK,SSL_R_CIPHER_OR_HASH_UNAVAILABLE);
                return(0);
@@ -472,20 +569,27 @@ int tls1_setup_key_block(SSL *s)
 
        s->s3->tmp.new_sym_enc=c;
        s->s3->tmp.new_hash=hash;
-
-       num=EVP_CIPHER_key_length(c)+EVP_MD_size(hash)+EVP_CIPHER_iv_length(c);
+       s->s3->tmp.new_mac_pkey_type = mac_type;
+       s->s3->tmp.new_mac_secret_size = mac_secret_size;
+       num=EVP_CIPHER_key_length(c)+mac_secret_size+EVP_CIPHER_iv_length(c);
        num*=2;
 
        ssl3_cleanup_key_block(s);
 
        if ((p1=(unsigned char *)OPENSSL_malloc(num)) == NULL)
+               {
+               SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK,ERR_R_MALLOC_FAILURE);
                goto err;
-       if ((p2=(unsigned char *)OPENSSL_malloc(num)) == NULL)
-               goto err;
+               }
 
        s->s3->tmp.key_block_length=num;
        s->s3->tmp.key_block=p1;
 
+       if ((p2=(unsigned char *)OPENSSL_malloc(num)) == NULL)
+               {
+               SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK,ERR_R_MALLOC_FAILURE);
+               goto err;
+               }
 
 #ifdef TLS_DEBUG
 printf("client random\n");
@@ -495,9 +599,8 @@ printf("server random\n");
 printf("pre-master\n");
 { int z; for (z=0; z<s->session->master_key_length; z++) printf("%02X%c",s->session->master_key[z],((z+1)%16)?' ':'\n'); }
 #endif
-       tls1_generate_key_block(s,p1,p2,num);
-       OPENSSL_cleanse(p2,num);
-       OPENSSL_free(p2);
+       if (!tls1_generate_key_block(s,p1,p2,num))
+               goto err;
 #ifdef TLS_DEBUG
 printf("\nkey block\n");
 { int z; for (z=0; z<num; z++) printf("%02X%c",p1[z],((z+1)%16)?' ':'\n'); }
@@ -512,20 +615,24 @@ printf("\nkey block\n");
 
                if (s->session->cipher != NULL)
                        {
-                       if ((s->session->cipher->algorithms & SSL_ENC_MASK) == SSL_eNULL)
+                       if (s->session->cipher->algorithm_enc == SSL_eNULL)
                                s->s3->need_empty_fragments = 0;
                        
 #ifndef OPENSSL_NO_RC4
-                       if ((s->session->cipher->algorithms & SSL_ENC_MASK) == SSL_RC4)
+                       if (s->session->cipher->algorithm_enc == SSL_RC4)
                                s->s3->need_empty_fragments = 0;
 #endif
                        }
                }
                
-       return(1);
+       ret = 1;
 err:
-       SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK,ERR_R_MALLOC_FAILURE);
-       return(0);
+       if (p2)
+               {
+               OPENSSL_cleanse(p2,num);
+               OPENSSL_free(p2);
+               }
+       return(ret);
        }
 
 int tls1_enc(SSL *s, int send)
@@ -533,11 +640,16 @@ int tls1_enc(SSL *s, int send)
        SSL3_RECORD *rec;
        EVP_CIPHER_CTX *ds;
        unsigned long l;
-       int bs,i,ii,j,k;
+       int bs,i,ii,j,k,n=0;
        const EVP_CIPHER *enc;
 
        if (send)
                {
+               if (EVP_MD_CTX_md(s->write_hash))
+                       {
+                       n=EVP_MD_CTX_size(s->write_hash);
+                       OPENSSL_assert(n >= 0);
+                       }
                ds=s->enc_write_ctx;
                rec= &(s->s3->wrec);
                if (s->enc_write_ctx == NULL)
@@ -547,6 +659,11 @@ int tls1_enc(SSL *s, int send)
                }
        else
                {
+               if (EVP_MD_CTX_md(s->read_hash))
+                       {
+                       n=EVP_MD_CTX_size(s->read_hash);
+                       OPENSSL_assert(n >= 0);
+                       }
                ds=s->enc_read_ctx;
                rec= &(s->s3->rrec);
                if (s->enc_read_ctx == NULL)
@@ -593,11 +710,10 @@ int tls1_enc(SSL *s, int send)
                {
                 unsigned long ui;
                printf("EVP_Cipher(ds=%p,rec->data=%p,rec->input=%p,l=%ld) ==>\n",
-                        (void *)ds,rec->data,rec->input,l);
-               printf("\tEVP_CIPHER_CTX: %d buf_len, %d key_len [%ld %ld], %d iv_len\n",
+                        ds,rec->data,rec->input,l);
+               printf("\tEVP_CIPHER_CTX: %d buf_len, %d key_len [%d %d], %d iv_len\n",
                         ds->buf_len, ds->cipher->key_len,
-                        (unsigned long)DES_KEY_SZ,
-                       (unsigned long)DES_SCHEDULE_SZ,
+                        DES_KEY_SZ, DES_SCHEDULE_SZ,
                         ds->cipher->iv_len);
                printf("\t\tIV: ");
                for (i=0; i<ds->cipher->iv_len; i++) printf("%02X", ds->iv[i]);
@@ -622,10 +738,10 @@ int tls1_enc(SSL *s, int send)
 
 #ifdef KSSL_DEBUG
                {
-                unsigned long ki;
+                unsigned long i;
                 printf("\trec->data=");
-               for (ki=0; ki<l; i++)
-                        printf(" %02x", rec->data[ki]);  printf("\n");
+               for (i=0; i<l; i++)
+                        printf(" %02x", rec->data[i]);  printf("\n");
                 }
 #endif /* KSSL_DEBUG */
 
@@ -673,109 +789,154 @@ int tls1_enc(SSL *s, int send)
                }
        return(1);
        }
-
-int tls1_cert_verify_mac(SSL *s, EVP_MD_CTX *in_ctx, unsigned char *out)
+int tls1_cert_verify_mac(SSL *s, int md_nid, unsigned char *out)
        {
        unsigned int ret;
-       EVP_MD_CTX ctx;
+       EVP_MD_CTX ctx, *d=NULL;
+       int i;
+
+       if (s->s3->handshake_buffer) 
+               if (!ssl3_digest_cached_records(s))
+                       return 0;
+
+       for (i=0;i<SSL_MAX_DIGEST;i++) 
+               {
+                 if (s->s3->handshake_dgst[i]&&EVP_MD_CTX_type(s->s3->handshake_dgst[i])==md_nid) 
+                       {
+                       d=s->s3->handshake_dgst[i];
+                       break;
+                       }
+               }
+       if (!d) {
+               SSLerr(SSL_F_TLS1_CERT_VERIFY_MAC,SSL_R_NO_REQUIRED_DIGEST);
+               return 0;
+       }       
 
        EVP_MD_CTX_init(&ctx);
-       EVP_MD_CTX_copy_ex(&ctx,in_ctx);
+       EVP_MD_CTX_copy_ex(&ctx,d);
        EVP_DigestFinal_ex(&ctx,out,&ret);
        EVP_MD_CTX_cleanup(&ctx);
        return((int)ret);
        }
 
-int tls1_final_finish_mac(SSL *s, EVP_MD_CTX *in1_ctx, EVP_MD_CTX *in2_ctx,
+int tls1_final_finish_mac(SSL *s,
             const char *str, int slen, unsigned char *out)
        {
        unsigned int i;
        EVP_MD_CTX ctx;
-       unsigned char buf[TLS_MD_MAX_CONST_SIZE+MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH];
+       unsigned char buf[2*EVP_MAX_MD_SIZE];
        unsigned char *q,buf2[12];
+       int idx;
+       long mask;
+       int err=0;
+       const EVP_MD *md; 
 
        q=buf;
-       memcpy(q,str,slen);
-       q+=slen;
+
+       if (s->s3->handshake_buffer) 
+               if (!ssl3_digest_cached_records(s))
+                       return 0;
 
        EVP_MD_CTX_init(&ctx);
-       EVP_MD_CTX_copy_ex(&ctx,in1_ctx);
-       EVP_DigestFinal_ex(&ctx,q,&i);
-       q+=i;
-       EVP_MD_CTX_copy_ex(&ctx,in2_ctx);
-       EVP_DigestFinal_ex(&ctx,q,&i);
-       q+=i;
-
-       tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,(int)(q-buf),
-               s->session->master_key,s->session->master_key_length,
-               out,buf2,sizeof buf2);
+
+       for (idx=0;ssl_get_handshake_digest(idx,&mask,&md);idx++)
+               {
+               if (mask & s->s3->tmp.new_cipher->algorithm2)
+                       {
+                       int hashsize = EVP_MD_size(md);
+                       if (hashsize < 0 || hashsize > (int)(sizeof buf - (size_t)(q-buf)))
+                               {
+                               /* internal error: 'buf' is too small for this cipersuite! */
+                               err = 1;
+                               }
+                       else
+                               {
+                               EVP_MD_CTX_copy_ex(&ctx,s->s3->handshake_dgst[idx]);
+                               EVP_DigestFinal_ex(&ctx,q,&i);
+                               if (i != (unsigned int)hashsize) /* can't really happen */
+                                       err = 1;
+                               q+=i;
+                               }
+                       }
+               }
+               
+       if (!tls1_PRF(s->s3->tmp.new_cipher->algorithm2,
+                       str,slen, buf,(int)(q-buf), NULL,0, NULL,0, NULL,0,
+                       s->session->master_key,s->session->master_key_length,
+                       out,buf2,sizeof buf2))
+               err = 1;
        EVP_MD_CTX_cleanup(&ctx);
 
-       return sizeof buf2;
+       if (err)
+               return 0;
+       else
+               return sizeof buf2;
        }
 
 int tls1_mac(SSL *ssl, unsigned char *md, int send)
        {
        SSL3_RECORD *rec;
-       unsigned char *mac_sec,*seq;
-       const EVP_MD *hash;
-       unsigned int md_size;
+       unsigned char *seq;
+       EVP_MD_CTX *hash;
+       size_t md_size;
        int i;
-       HMAC_CTX hmac;
+       EVP_MD_CTX hmac, *mac_ctx;
        unsigned char buf[5]; 
+       int stream_mac = (send?(ssl->mac_flags & SSL_MAC_FLAG_WRITE_MAC_STREAM):(ssl->mac_flags&SSL_MAC_FLAG_READ_MAC_STREAM));
+       int t;
 
        if (send)
                {
                rec= &(ssl->s3->wrec);
-               mac_sec= &(ssl->s3->write_mac_secret[0]);
                seq= &(ssl->s3->write_sequence[0]);
                hash=ssl->write_hash;
                }
        else
                {
                rec= &(ssl->s3->rrec);
-               mac_sec= &(ssl->s3->read_mac_secret[0]);
                seq= &(ssl->s3->read_sequence[0]);
                hash=ssl->read_hash;
                }
 
-       md_size=EVP_MD_size(hash);
+       t=EVP_MD_CTX_size(hash);
+       OPENSSL_assert(t >= 0);
+       md_size=t;
 
        buf[0]=rec->type;
-       if (ssl->version == DTLS1_VERSION && ssl->client_version == DTLS1_BAD_VER)
-               {
-               buf[1]=TLS1_VERSION_MAJOR;
-               buf[2]=TLS1_VERSION_MINOR;
-               }
-       else    {
-               buf[1]=(unsigned char)(ssl->version>>8);
-               buf[2]=(unsigned char)(ssl->version);
-               }
-
+       buf[1]=(unsigned char)(ssl->version>>8);
+       buf[2]=(unsigned char)(ssl->version);
        buf[3]=rec->length>>8;
        buf[4]=rec->length&0xff;
 
        /* I should fix this up TLS TLS TLS TLS TLS XXXXXXXX */
-       HMAC_CTX_init(&hmac);
-       HMAC_Init_ex(&hmac,mac_sec,EVP_MD_size(hash),hash,NULL);
+       if (stream_mac) 
+               {
+                       mac_ctx = hash;
+               }
+               else
+               {
+                       EVP_MD_CTX_copy(&hmac,hash);
+                       mac_ctx = &hmac;
+               }
 
-       if (ssl->version == DTLS1_BAD_VER ||
-           (ssl->version == DTLS1_VERSION && ssl->client_version != DTLS1_BAD_VER))
+       if (ssl->version == DTLS1_VERSION || ssl->version == DTLS1_BAD_VER)
                {
                unsigned char dtlsseq[8],*p=dtlsseq;
+
                s2n(send?ssl->d1->w_epoch:ssl->d1->r_epoch, p);
                memcpy (p,&seq[2],6);
 
-               HMAC_Update(&hmac,dtlsseq,8);
+               EVP_DigestSignUpdate(mac_ctx,dtlsseq,8);
                }
        else
-               HMAC_Update(&hmac,seq,8);
-
-       HMAC_Update(&hmac,buf,5);
-       HMAC_Update(&hmac,rec->input,rec->length);
-       HMAC_Final(&hmac,md,&md_size);
-       HMAC_CTX_cleanup(&hmac);
+               EVP_DigestSignUpdate(mac_ctx,seq,8);
 
+       EVP_DigestSignUpdate(mac_ctx,buf,5);
+       EVP_DigestSignUpdate(mac_ctx,rec->input,rec->length);
+       t=EVP_DigestSignFinal(mac_ctx,md,&md_size);
+       OPENSSL_assert(t > 0);
+               
+       if (!stream_mac) EVP_MD_CTX_cleanup(&hmac);
 #ifdef TLS_DEBUG
 printf("sec=");
 {unsigned int z; for (z=0; z<md_size; z++) printf("%02X ",mac_sec[z]); printf("\n"); }
@@ -787,7 +948,7 @@ printf("rec=");
 {unsigned int z; for (z=0; z<rec->length; z++) printf("%02X ",buf[z]); printf("\n"); }
 #endif
 
-       if ( SSL_version(ssl) != DTLS1_VERSION && SSL_version(ssl) != DTLS1_BAD_VER)
+       if (ssl->version != DTLS1_VERSION && ssl->version != DTLS1_BAD_VER)
                {
                for (i=7; i>=0; i--)
                        {
@@ -805,29 +966,130 @@ printf("rec=");
 int tls1_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p,
             int len)
        {
-       unsigned char buf[SSL3_RANDOM_SIZE*2+TLS_MD_MASTER_SECRET_CONST_SIZE];
        unsigned char buff[SSL_MAX_MASTER_KEY_LENGTH];
+       const void *co = NULL, *so = NULL;
+       int col = 0, sol = 0;
 
 #ifdef KSSL_DEBUG
-       printf ("tls1_generate_master_secret(%p,%p, %p, %d)\n", (void *)s,out, p,len);
+       printf ("tls1_generate_master_secret(%p,%p, %p, %d)\n", s,out, p,len);
 #endif /* KSSL_DEBUG */
 
-       /* Setup the stuff to munge */
-       memcpy(buf,TLS_MD_MASTER_SECRET_CONST,
-               TLS_MD_MASTER_SECRET_CONST_SIZE);
-       memcpy(&(buf[TLS_MD_MASTER_SECRET_CONST_SIZE]),
-               s->s3->client_random,SSL3_RANDOM_SIZE);
-       memcpy(&(buf[SSL3_RANDOM_SIZE+TLS_MD_MASTER_SECRET_CONST_SIZE]),
-               s->s3->server_random,SSL3_RANDOM_SIZE);
-       tls1_PRF(s->ctx->md5,s->ctx->sha1,
-               buf,TLS_MD_MASTER_SECRET_CONST_SIZE+SSL3_RANDOM_SIZE*2,p,len,
+#ifdef TLSEXT_TYPE_opaque_prf_input
+       if (s->s3->client_opaque_prf_input != NULL && s->s3->server_opaque_prf_input != NULL &&
+           s->s3->client_opaque_prf_input_len > 0 &&
+           s->s3->client_opaque_prf_input_len == s->s3->server_opaque_prf_input_len)
+               {
+               co = s->s3->client_opaque_prf_input;
+               col = s->s3->server_opaque_prf_input_len;
+               so = s->s3->server_opaque_prf_input;
+               sol = s->s3->client_opaque_prf_input_len; /* must be same as col (see draft-rescorla-tls-opaque-prf-input-00.txt, section 3.1) */
+               }
+#endif
+
+       tls1_PRF(s->s3->tmp.new_cipher->algorithm2,
+               TLS_MD_MASTER_SECRET_CONST,TLS_MD_MASTER_SECRET_CONST_SIZE,
+               s->s3->client_random,SSL3_RANDOM_SIZE,
+               co, col,
+               s->s3->server_random,SSL3_RANDOM_SIZE,
+               so, sol,
+               p,len,
                s->session->master_key,buff,sizeof buff);
+
 #ifdef KSSL_DEBUG
        printf ("tls1_generate_master_secret() complete\n");
 #endif /* KSSL_DEBUG */
        return(SSL3_MASTER_SECRET_SIZE);
        }
 
+int tls1_export_keying_material(SSL *s, unsigned char *out, size_t olen,
+        const char *label, size_t llen, const unsigned char *context,
+        size_t contextlen, int use_context)
+       {
+       unsigned char *buff;
+       unsigned char *val = NULL;
+       size_t vallen, currentvalpos;
+       int rv;
+
+#ifdef KSSL_DEBUG
+       printf ("tls1_export_keying_material(%p,%p,%d,%s,%d,%p,%d)\n", s, out, olen, label, llen, p, plen);
+#endif /* KSSL_DEBUG */
+
+       buff = OPENSSL_malloc(olen);
+       if (buff == NULL) goto err2;
+
+       /* construct PRF arguments
+        * we construct the PRF argument ourself rather than passing separate
+        * values into the TLS PRF to ensure that the concatenation of values
+        * does not create a prohibited label.
+        */
+       vallen = llen + SSL3_RANDOM_SIZE * 2;
+       if (use_context)
+               {
+               vallen += 2 + contextlen;
+               }
+
+       val = OPENSSL_malloc(vallen);
+       if (val == NULL) goto err2;
+       currentvalpos = 0;
+       memcpy(val + currentvalpos, (unsigned char *) label, llen);
+       currentvalpos += llen;
+       memcpy(val + currentvalpos, s->s3->client_random, SSL3_RANDOM_SIZE);
+       currentvalpos += SSL3_RANDOM_SIZE;
+       memcpy(val + currentvalpos, s->s3->server_random, SSL3_RANDOM_SIZE);
+       currentvalpos += SSL3_RANDOM_SIZE;
+
+       if (use_context)
+               {
+               val[currentvalpos] = (contextlen >> 8) & 0xff;
+               currentvalpos++;
+               val[currentvalpos] = contextlen & 0xff;
+               currentvalpos++;
+               if ((contextlen > 0) || (context != NULL))
+                       {
+                       memcpy(val + currentvalpos, context, contextlen);
+                       }
+               }
+
+       /* disallow prohibited labels
+        * note that SSL3_RANDOM_SIZE > max(prohibited label len) =
+        * 15, so size of val > max(prohibited label len) = 15 and the
+        * comparisons won't have buffer overflow
+        */
+       if (memcmp(val, TLS_MD_CLIENT_FINISH_CONST,
+                TLS_MD_CLIENT_FINISH_CONST_SIZE) == 0) goto err1;
+       if (memcmp(val, TLS_MD_SERVER_FINISH_CONST,
+                TLS_MD_SERVER_FINISH_CONST_SIZE) == 0) goto err1;
+       if (memcmp(val, TLS_MD_MASTER_SECRET_CONST,
+                TLS_MD_MASTER_SECRET_CONST_SIZE) == 0) goto err1;
+       if (memcmp(val, TLS_MD_KEY_EXPANSION_CONST,
+                TLS_MD_KEY_EXPANSION_CONST_SIZE) == 0) goto err1;
+
+       rv = tls1_PRF(s->s3->tmp.new_cipher->algorithm2,
+                     val, vallen,
+                     NULL, 0,
+                     NULL, 0,
+                     NULL, 0,
+                     NULL, 0,
+                     s->session->master_key,s->session->master_key_length,
+                     out,buff,olen);
+
+#ifdef KSSL_DEBUG
+       printf ("tls1_export_keying_material() complete\n");
+#endif /* KSSL_DEBUG */
+       goto ret;
+err1:
+       SSLerr(SSL_F_TLS1_EXPORT_KEYING_MATERIAL, SSL_R_TLS_ILLEGAL_EXPORTER_LABEL);
+       rv = 0;
+       goto ret;
+err2:
+       SSLerr(SSL_F_TLS1_EXPORT_KEYING_MATERIAL, ERR_R_MALLOC_FAILURE);
+       rv = 0;
+ret:
+       if (buff != NULL) OPENSSL_free(buff);
+       if (val != NULL) OPENSSL_free(val);
+       return(rv);
+       }
+
 int tls1_alert_code(int code)
        {
        switch (code)
@@ -856,7 +1118,13 @@ int tls1_alert_code(int code)
        case SSL_AD_INTERNAL_ERROR:     return(TLS1_AD_INTERNAL_ERROR);
        case SSL_AD_USER_CANCELLED:     return(TLS1_AD_USER_CANCELLED);
        case SSL_AD_NO_RENEGOTIATION:   return(TLS1_AD_NO_RENEGOTIATION);
-#ifdef DTLS1_AD_MISSING_HANDSHAKE_MESSAGE
+       case SSL_AD_UNSUPPORTED_EXTENSION: return(TLS1_AD_UNSUPPORTED_EXTENSION);
+       case SSL_AD_CERTIFICATE_UNOBTAINABLE: return(TLS1_AD_CERTIFICATE_UNOBTAINABLE);
+       case SSL_AD_UNRECOGNIZED_NAME:  return(TLS1_AD_UNRECOGNIZED_NAME);
+       case SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE: return(TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE);
+       case SSL_AD_BAD_CERTIFICATE_HASH_VALUE: return(TLS1_AD_BAD_CERTIFICATE_HASH_VALUE);
+       case SSL_AD_UNKNOWN_PSK_IDENTITY:return(TLS1_AD_UNKNOWN_PSK_IDENTITY);
+#if 0 /* not appropriate for TLS, not used for DTLS */
        case DTLS1_AD_MISSING_HANDSHAKE_MESSAGE: return 
                                          (DTLS1_AD_MISSING_HANDSHAKE_MESSAGE);
 #endif
index 6e5de3e..03becbc 100644 (file)
  * copied and put under another distribution licence
  * [including the GNU Public Licence.]
  */
+/* ====================================================================
+ * Copyright (c) 1998-2007 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    openssl-core@openssl.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
 
 #include <stdio.h>
 #include <openssl/objects.h>
 #include <openssl/hmac.h>
 #include <openssl/ocsp.h>
 #include "ssl_locl.h"
-#include "fnv1a64.h"
 
 const char tls1_version_str[]="TLSv1" OPENSSL_VERSION_PTEXT;
 
@@ -84,6 +136,7 @@ SSL3_ENC_METHOD TLSv1_enc_data={
        TLS_MD_CLIENT_FINISH_CONST,TLS_MD_CLIENT_FINISH_CONST_SIZE,
        TLS_MD_SERVER_FINISH_CONST,TLS_MD_SERVER_FINISH_CONST_SIZE,
        tls1_alert_code,
+       tls1_export_keying_material,
        };
 
 long tls1_default_timeout(void)
@@ -93,11 +146,6 @@ long tls1_default_timeout(void)
        return(60*60*2);
        }
 
-IMPLEMENT_tls1_meth_func(tlsv1_base_method,
-                       ssl_undefined_function,
-                       ssl_undefined_function,
-                       ssl_bad_method)
-
 int tls1_new(SSL *s)
        {
        if (!ssl3_new(s)) return(0);
@@ -107,6 +155,12 @@ int tls1_new(SSL *s)
 
 void tls1_free(SSL *s)
        {
+#ifndef OPENSSL_NO_TLSEXT
+       if (s->tlsext_session_ticket)
+               {
+               OPENSSL_free(s->tlsext_session_ticket);
+               }
+#endif /* OPENSSL_NO_TLSEXT */
        ssl3_free(s);
        }
 
@@ -116,17 +170,105 @@ void tls1_clear(SSL *s)
        s->version=TLS1_VERSION;
        }
 
-#if 0
-long tls1_ctrl(SSL *s, int cmd, long larg, char *parg)
+#ifndef OPENSSL_NO_EC
+static int nid_list[] =
+       {
+               NID_sect163k1, /* sect163k1 (1) */
+               NID_sect163r1, /* sect163r1 (2) */
+               NID_sect163r2, /* sect163r2 (3) */
+               NID_sect193r1, /* sect193r1 (4) */ 
+               NID_sect193r2, /* sect193r2 (5) */ 
+               NID_sect233k1, /* sect233k1 (6) */
+               NID_sect233r1, /* sect233r1 (7) */ 
+               NID_sect239k1, /* sect239k1 (8) */ 
+               NID_sect283k1, /* sect283k1 (9) */
+               NID_sect283r1, /* sect283r1 (10) */ 
+               NID_sect409k1, /* sect409k1 (11) */ 
+               NID_sect409r1, /* sect409r1 (12) */
+               NID_sect571k1, /* sect571k1 (13) */ 
+               NID_sect571r1, /* sect571r1 (14) */ 
+               NID_secp160k1, /* secp160k1 (15) */
+               NID_secp160r1, /* secp160r1 (16) */ 
+               NID_secp160r2, /* secp160r2 (17) */ 
+               NID_secp192k1, /* secp192k1 (18) */
+               NID_X9_62_prime192v1, /* secp192r1 (19) */ 
+               NID_secp224k1, /* secp224k1 (20) */ 
+               NID_secp224r1, /* secp224r1 (21) */
+               NID_secp256k1, /* secp256k1 (22) */ 
+               NID_X9_62_prime256v1, /* secp256r1 (23) */ 
+               NID_secp384r1, /* secp384r1 (24) */
+               NID_secp521r1  /* secp521r1 (25) */     
+       };
+       
+int tls1_ec_curve_id2nid(int curve_id)
        {
-       return(0);
+       /* ECC curves from draft-ietf-tls-ecc-12.txt (Oct. 17, 2005) */
+       if ((curve_id < 1) || ((unsigned int)curve_id >
+                               sizeof(nid_list)/sizeof(nid_list[0])))
+               return 0;
+       return nid_list[curve_id-1];
        }
 
-long tls1_callback_ctrl(SSL *s, int cmd, void *(*fp)())
+int tls1_ec_nid2curve_id(int nid)
        {
-       return(0);
+       /* ECC curves from draft-ietf-tls-ecc-12.txt (Oct. 17, 2005) */
+       switch (nid)
+               {
+       case NID_sect163k1: /* sect163k1 (1) */
+               return 1;
+       case NID_sect163r1: /* sect163r1 (2) */
+               return 2;
+       case NID_sect163r2: /* sect163r2 (3) */
+               return 3;
+       case NID_sect193r1: /* sect193r1 (4) */ 
+               return 4;
+       case NID_sect193r2: /* sect193r2 (5) */ 
+               return 5;
+       case NID_sect233k1: /* sect233k1 (6) */
+               return 6;
+       case NID_sect233r1: /* sect233r1 (7) */ 
+               return 7;
+       case NID_sect239k1: /* sect239k1 (8) */ 
+               return 8;
+       case NID_sect283k1: /* sect283k1 (9) */
+               return 9;
+       case NID_sect283r1: /* sect283r1 (10) */ 
+               return 10;
+       case NID_sect409k1: /* sect409k1 (11) */ 
+               return 11;
+       case NID_sect409r1: /* sect409r1 (12) */
+               return 12;
+       case NID_sect571k1: /* sect571k1 (13) */ 
+               return 13;
+       case NID_sect571r1: /* sect571r1 (14) */ 
+               return 14;
+       case NID_secp160k1: /* secp160k1 (15) */
+               return 15;
+       case NID_secp160r1: /* secp160r1 (16) */ 
+               return 16;
+       case NID_secp160r2: /* secp160r2 (17) */ 
+               return 17;
+       case NID_secp192k1: /* secp192k1 (18) */
+               return 18;
+       case NID_X9_62_prime192v1: /* secp192r1 (19) */ 
+               return 19;
+       case NID_secp224k1: /* secp224k1 (20) */ 
+               return 20;
+       case NID_secp224r1: /* secp224r1 (21) */
+               return 21;
+       case NID_secp256k1: /* secp256k1 (22) */ 
+               return 22;
+       case NID_X9_62_prime256v1: /* secp256r1 (23) */ 
+               return 23;
+       case NID_secp384r1: /* secp384r1 (24) */
+               return 24;
+       case NID_secp521r1:  /* secp521r1 (25) */       
+               return 25;
+       default:
+               return 0;
+               }
        }
-#endif
+#endif /* OPENSSL_NO_EC */
 
 #ifndef OPENSSL_NO_TLSEXT
 unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, unsigned char *limit)
@@ -158,7 +300,7 @@ unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, unsigned cha
                */
                   
                if ((lenmax = limit - ret - 9) < 0 
-               || (size_str = strlen(s->tlsext_hostname)) > (unsigned long)lenmax) 
+                   || (size_str = strlen(s->tlsext_hostname)) > (unsigned long)lenmax) 
                        return NULL;
                        
                /* extension type and length */
@@ -173,9 +315,8 @@ unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, unsigned cha
                s2n(size_str,ret);
                memcpy(ret, s->tlsext_hostname, size_str);
                ret+=size_str;
-
                }
+
         /* Add RI if renegotiating */
         if (s->new_session)
           {
@@ -201,19 +342,81 @@ unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, unsigned cha
           ret += el;
         }
 
-           
+#ifndef OPENSSL_NO_EC
+       if (s->tlsext_ecpointformatlist != NULL &&
+           s->version != DTLS1_VERSION)
+               {
+               /* Add TLS extension ECPointFormats to the ClientHello message */
+               long lenmax; 
+
+               if ((lenmax = limit - ret - 5) < 0) return NULL; 
+               if (s->tlsext_ecpointformatlist_length > (unsigned long)lenmax) return NULL;
+               if (s->tlsext_ecpointformatlist_length > 255)
+                       {
+                       SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);
+                       return NULL;
+                       }
+               
+               s2n(TLSEXT_TYPE_ec_point_formats,ret);
+               s2n(s->tlsext_ecpointformatlist_length + 1,ret);
+               *(ret++) = (unsigned char) s->tlsext_ecpointformatlist_length;
+               memcpy(ret, s->tlsext_ecpointformatlist, s->tlsext_ecpointformatlist_length);
+               ret+=s->tlsext_ecpointformatlist_length;
+               }
+       if (s->tlsext_ellipticcurvelist != NULL &&
+           s->version != DTLS1_VERSION)
+               {
+               /* Add TLS extension EllipticCurves to the ClientHello message */
+               long lenmax; 
+
+               if ((lenmax = limit - ret - 6) < 0) return NULL; 
+               if (s->tlsext_ellipticcurvelist_length > (unsigned long)lenmax) return NULL;
+               if (s->tlsext_ellipticcurvelist_length > 65532)
+                       {
+                       SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);
+                       return NULL;
+                       }
+               
+               s2n(TLSEXT_TYPE_elliptic_curves,ret);
+               s2n(s->tlsext_ellipticcurvelist_length + 2, ret);
+
+               /* NB: draft-ietf-tls-ecc-12.txt uses a one-byte prefix for
+                * elliptic_curve_list, but the examples use two bytes.
+                * http://www1.ietf.org/mail-archive/web/tls/current/msg00538.html
+                * resolves this to two bytes.
+                */
+               s2n(s->tlsext_ellipticcurvelist_length, ret);
+               memcpy(ret, s->tlsext_ellipticcurvelist, s->tlsext_ellipticcurvelist_length);
+               ret+=s->tlsext_ellipticcurvelist_length;
+               }
+#endif /* OPENSSL_NO_EC */
+
        if (!(SSL_get_options(s) & SSL_OP_NO_TICKET))
                {
                int ticklen;
                if (!s->new_session && s->session && s->session->tlsext_tick)
                        ticklen = s->session->tlsext_ticklen;
+               else if (s->session && s->tlsext_session_ticket &&
+                        s->tlsext_session_ticket->data)
+                       {
+                       ticklen = s->tlsext_session_ticket->length;
+                       s->session->tlsext_tick = OPENSSL_malloc(ticklen);
+                       if (!s->session->tlsext_tick)
+                               return NULL;
+                       memcpy(s->session->tlsext_tick,
+                              s->tlsext_session_ticket->data,
+                              ticklen);
+                       s->session->tlsext_ticklen = ticklen;
+                       }
                else
                        ticklen = 0;
+               if (ticklen == 0 && s->tlsext_session_ticket &&
+                   s->tlsext_session_ticket->data == NULL)
+                       goto skip_ext;
                /* Check for enough room 2 for extension type, 2 for len
                 * rest for ticket
                 */
-               if (limit - ret - 4 - ticklen < 0)
-                       return NULL;
+               if ((long)(limit - ret - 4 - ticklen) < 0) return NULL;
                s2n(TLSEXT_TYPE_session_ticket,ret); 
                s2n(ticklen,ret);
                if (ticklen)
@@ -222,6 +425,26 @@ unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, unsigned cha
                        ret += ticklen;
                        }
                }
+               skip_ext:
+
+#ifdef TLSEXT_TYPE_opaque_prf_input
+       if (s->s3->client_opaque_prf_input != NULL &&
+           s->version != DTLS1_VERSION)
+               {
+               size_t col = s->s3->client_opaque_prf_input_len;
+               
+               if ((long)(limit - ret - 6 - col < 0))
+                       return NULL;
+               if (col > 0xFFFD) /* can't happen */
+                       return NULL;
+
+               s2n(TLSEXT_TYPE_opaque_prf_input, ret); 
+               s2n(col + 2, ret);
+               s2n(col, ret);
+               memcpy(ret, s->s3->client_opaque_prf_input, col);
+               ret += col;
+               }
+#endif
 
        if (s->tlsext_status_type == TLSEXT_STATUSTYPE_ocsp &&
            s->version != DTLS1_VERSION)
@@ -272,7 +495,8 @@ unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, unsigned cha
                        i2d_X509_EXTENSIONS(s->tlsext_ocsp_exts, &ret);
                }
 
-       if (s->ctx->next_proto_select_cb)
+#ifndef OPENSSL_NO_NEXTPROTONEG
+       if (s->ctx->next_proto_select_cb && !s->s3->tmp.finish_md_len)
                {
                /* The client advertises an emtpy extension to indicate its
                 * support for Next Protocol Negotiation */
@@ -281,6 +505,7 @@ unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, unsigned cha
                s2n(TLSEXT_TYPE_next_proto_neg,ret);
                s2n(0,ret);
                }
+#endif
 
        if ((extdatalen = ret-p-2)== 0) 
                return p;
@@ -293,7 +518,9 @@ unsigned char *ssl_add_serverhello_tlsext(SSL *s, unsigned char *p, unsigned cha
        {
        int extdatalen=0;
        unsigned char *ret = p;
-       char next_proto_neg_seen;
+#ifndef OPENSSL_NO_NEXTPROTONEG
+       int next_proto_neg_seen;
+#endif
 
        /* don't add extensions for SSLv3, unless doing secure renegotiation */
        if (s->version == SSL3_VERSION && !s->s3->send_connection_binding)
@@ -304,7 +531,7 @@ unsigned char *ssl_add_serverhello_tlsext(SSL *s, unsigned char *p, unsigned cha
 
        if (!s->hit && s->servername_done == 1 && s->session->tlsext_hostname != NULL)
                { 
-               if (limit - ret - 4 < 0) return NULL; 
+               if ((long)(limit - ret - 4) < 0) return NULL; 
 
                s2n(TLSEXT_TYPE_server_name,ret);
                s2n(0,ret);
@@ -333,11 +560,36 @@ unsigned char *ssl_add_serverhello_tlsext(SSL *s, unsigned char *p, unsigned cha
 
           ret += el;
         }
-       
+
+#ifndef OPENSSL_NO_EC
+       if (s->tlsext_ecpointformatlist != NULL &&
+           s->version != DTLS1_VERSION)
+               {
+               /* Add TLS extension ECPointFormats to the ServerHello message */
+               long lenmax; 
+
+               if ((lenmax = limit - ret - 5) < 0) return NULL; 
+               if (s->tlsext_ecpointformatlist_length > (unsigned long)lenmax) return NULL;
+               if (s->tlsext_ecpointformatlist_length > 255)
+                       {
+                       SSLerr(SSL_F_SSL_ADD_SERVERHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);
+                       return NULL;
+                       }
+               
+               s2n(TLSEXT_TYPE_ec_point_formats,ret);
+               s2n(s->tlsext_ecpointformatlist_length + 1,ret);
+               *(ret++) = (unsigned char) s->tlsext_ecpointformatlist_length;
+               memcpy(ret, s->tlsext_ecpointformatlist, s->tlsext_ecpointformatlist_length);
+               ret+=s->tlsext_ecpointformatlist_length;
+
+               }
+       /* Currently the server should not respond with a SupportedCurves extension */
+#endif /* OPENSSL_NO_EC */
+
        if (s->tlsext_ticket_expected
                && !(SSL_get_options(s) & SSL_OP_NO_TICKET)) 
                { 
-               if (limit - ret - 4 < 0) return NULL; 
+               if ((long)(limit - ret - 4) < 0) return NULL; 
                s2n(TLSEXT_TYPE_session_ticket,ret);
                s2n(0,ret);
                }
@@ -349,6 +601,40 @@ unsigned char *ssl_add_serverhello_tlsext(SSL *s, unsigned char *p, unsigned cha
                s2n(0,ret);
                }
 
+#ifdef TLSEXT_TYPE_opaque_prf_input
+       if (s->s3->server_opaque_prf_input != NULL &&
+           s->version != DTLS1_VERSION)
+               {
+               size_t sol = s->s3->server_opaque_prf_input_len;
+               
+               if ((long)(limit - ret - 6 - sol) < 0)
+                       return NULL;
+               if (sol > 0xFFFD) /* can't happen */
+                       return NULL;
+
+               s2n(TLSEXT_TYPE_opaque_prf_input, ret); 
+               s2n(sol + 2, ret);
+               s2n(sol, ret);
+               memcpy(ret, s->s3->server_opaque_prf_input, sol);
+               ret += sol;
+               }
+#endif
+       if (((s->s3->tmp.new_cipher->id & 0xFFFF)==0x80 || (s->s3->tmp.new_cipher->id & 0xFFFF)==0x81) 
+               && (SSL_get_options(s) & SSL_OP_CRYPTOPRO_TLSEXT_BUG))
+               { const unsigned char cryptopro_ext[36] = {
+                       0xfd, 0xe8, /*65000*/
+                       0x00, 0x20, /*32 bytes length*/
+                       0x30, 0x1e, 0x30, 0x08, 0x06, 0x06, 0x2a, 0x85, 
+                       0x03,   0x02, 0x02, 0x09, 0x30, 0x08, 0x06, 0x06, 
+                       0x2a, 0x85, 0x03, 0x02, 0x02, 0x16, 0x30, 0x08, 
+                       0x06, 0x06, 0x2a, 0x85, 0x03, 0x02, 0x02, 0x17};
+                       if (limit-ret<36) return NULL;
+                       memcpy(ret,cryptopro_ext,36);
+                       ret+=36;
+
+               }
+
+#ifndef OPENSSL_NO_NEXTPROTONEG
        next_proto_neg_seen = s->s3->next_proto_neg_seen;
        s->s3->next_proto_neg_seen = 0;
        if (next_proto_neg_seen && s->ctx->next_protos_advertised_cb)
@@ -368,21 +654,7 @@ unsigned char *ssl_add_serverhello_tlsext(SSL *s, unsigned char *p, unsigned cha
                        s->s3->next_proto_neg_seen = 1;
                        }
                }
-
-       if (s->s3->snap_start_ext_seen)
-               {
-               if ((long)(limit - ret - 14) < 0) return NULL;
-               s2n(TLSEXT_TYPE_snap_start,ret);
-               s2n(10,ret); /* extension length */
-               memcpy(ret, s->ctx->snap_start_orbit, 8);
-               ret += 8;
-               /* This is the ciphersuite that we would pick in the event of a
-                * Snap Start handshake. (Maybe the server wants to do EDH
-                * unless the client is Snap Start capable). At the moment we
-                * don't have any logic to pick a different cipher suite so we
-                * repeat the choice from the ServerHello. */
-               s2n(s->s3->tmp.new_cipher->id & 0xffff,ret);
-               }
+#endif
 
        if ((extdatalen = ret-p-2)== 0) 
                return p;
@@ -391,174 +663,6 @@ unsigned char *ssl_add_serverhello_tlsext(SSL *s, unsigned char *p, unsigned cha
        return ret;
        }
 
-
-static int ssl_hash_snap_start_client_hello(SSL* s,
-                                           const char* data,
-                                           unsigned len,
-                                           unsigned ext_len)
-       {
-       /* We walk the ClientHello from the beginning, writing
-        * adjusted lengths into |b| and hashing as we go.
-        *
-        * The resulting ClientHello is going to be shorter by the length of
-        * this extension, which is |ext_len + 4| (two bytes for the type and two for
-        * the length). */
-
-       const unsigned char *p;
-       unsigned remaining;
-       unsigned char b[3], *c;
-       unsigned long l;
-
-       p = (unsigned char*) data;
-       remaining = len;
-       /* Handshake header: type */
-       if (!remaining)
-               return 0;
-       ssl3_finish_mac(s, p, 1);
-       p++;
-       remaining--;
-       /* Handshake header: length */
-       if (remaining < 3)
-               return 0;
-       n2l3(p, l);
-       l -= ext_len + 4;
-       c = b;
-       l2n3(l, c);
-       ssl3_finish_mac(s, b, 3);
-       remaining -= 3;
-       /* ClientHello: version and random */
-       if (remaining < 34)
-               return 0;
-       ssl3_finish_mac(s, p, 34);
-       p += 34;
-       remaining -= 34;
-       /* ClientHello: session id length */
-       if (!remaining)
-               return 0;
-       l = *p;
-       ssl3_finish_mac(s, p, 1);
-       p++;
-       remaining--;
-       /* ClientHello: session id */
-       if (remaining < l)
-               return 0;
-       ssl3_finish_mac(s, p, l);
-       p += l;
-       remaining -= l;
-       /* ClientHello: cipher suites length */
-       if (remaining < 2)
-               return 0;
-       ssl3_finish_mac(s, p, 2);
-       n2s(p, l);
-       remaining -= 2;
-       /* ClientHello: cipher suites */
-       if (remaining < l)
-               return 0;
-       ssl3_finish_mac(s, p, l);
-       p += l;
-       remaining -= l;
-       /* ClientHello: compression methods length */
-       if (!remaining)
-               return 0;
-       l = *p;
-       ssl3_finish_mac(s, p, 1);
-       p++;
-       remaining--;
-       /* ClientHello: compression methods */
-       if (remaining < l)
-               return 0;
-       ssl3_finish_mac(s, p, l);
-       p += l;
-       remaining -= l;
-       /* ClientHello: extensions length (must exist given that we're already
-        * parsing the extensions from it */
-       if (remaining < 2)
-               return 0;
-       n2s(p, l);
-       remaining -= 2;
-       if (l != remaining || l < ext_len + 4)
-               return 0;
-       l -= ext_len + 4;
-       c = b;
-       s2n(l, c);
-       ssl3_finish_mac(s, b, 2);
-
-       while (remaining)
-               {
-               unsigned long extension_type, extension_len;
-               if (remaining < 4)
-                       return 0;
-               n2s(p, extension_type);
-               n2s(p, extension_len);
-               remaining -= 4;
-               if (remaining < extension_len)
-                       return 0;
-               if (extension_type != TLSEXT_TYPE_snap_start)
-                       ssl3_finish_mac(s, p - 4, extension_len + 4);
-               p += extension_len;
-               remaining -= extension_len;
-               }
-
-       return 1;
-       }
-
-static char ssl_parse_snap_start_tlsext(SSL *s, const unsigned char *data, unsigned short len)
-       {
-       ptrdiff_t extension_offset = data - (unsigned char *) s->init_buf->data;
-
-       if (len > 0 && len < 36)
-               return 0;
-       s->s3->snap_start_ext_seen = 1;
-       if (len == 0)
-               return 1;
-
-       fnv1a64_init((FNV1A64*) s->s3->response_hash);
-
-       /* We need to make a copy of the ClientHello because we'll be hashing a
-        * modified version. However, if we enter recovery then we need to hash
-        * the unchanged message.
-        *
-        * We are adding 4 bytes to the length here because we're including the
-        * handshake header. */
-       s->s3->snap_start_client_hello.left = s->init_num + 4;
-       s->s3->snap_start_client_hello.offset = 0;
-       s->s3->snap_start_client_hello.buf = OPENSSL_malloc(s->init_num + 4);
-       if (!s->s3->snap_start_client_hello.buf)
-               {
-               /* If we're out of memory then we pretend that we
-                * didn't see the extension. */
-               s->s3->snap_start_ext_seen = 0;
-               return 1;
-               }
-
-       memcpy(s->s3->snap_start_client_hello.buf, s->init_buf->data, s->init_num + 4);
-       memcpy(s->s3->server_random, s->s3->client_random, 4); /* time */
-       memcpy(s->s3->server_random + 4, data, 28); /* orbit and random bytes */
-       memcpy(s->s3->predicted_response_hash, data + 28, 8);
-
-       /* Point snap_start_records to within the copy of the ClientHello */
-       s->s3->snap_start_records.offset = 0;
-       s->s3->snap_start_records.left = len - 36;
-       s->s3->snap_start_records.buf = s->s3->snap_start_client_hello.buf + extension_offset + 36;
-
-       /* Reset the handshake hash */
-       ssl3_init_finished_mac(s);
-
-       /* Need to hash the ClientHello as if the snap start extension wasn't
-        * included. */
-       if (!ssl_hash_snap_start_client_hello(
-                       s,
-                       s->init_buf->data,
-                       s->init_num + 4 /* four bytes of handshake header */,
-                       len))
-               {
-               return 0;
-               }
-
-       s->s3->snap_start_requested = 1;
-       return 1;
-       }
-
 int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, int n, int *al)
        {
        unsigned short type;
@@ -572,7 +676,6 @@ int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
 
        if (data >= (d+n-2))
                goto ri_check;
-
        n2s(data,len);
 
        if (data > (d+n-len)) 
@@ -585,7 +688,9 @@ int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
 
                if (data+size > (d+n))
                        goto ri_check;
-
+#if 0
+               fprintf(stderr,"Received extension type %d size %d\n",type,size);
+#endif
                if (s->tlsext_debug_cb)
                        s->tlsext_debug_cb(s, 0, type, data, size,
                                                s->tlsext_debug_arg);
@@ -695,6 +800,120 @@ int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
                                }
 
                        }
+
+#ifndef OPENSSL_NO_EC
+               else if (type == TLSEXT_TYPE_ec_point_formats &&
+                    s->version != DTLS1_VERSION)
+                       {
+                       unsigned char *sdata = data;
+                       int ecpointformatlist_length = *(sdata++);
+
+                       if (ecpointformatlist_length != size - 1)
+                               {
+                               *al = TLS1_AD_DECODE_ERROR;
+                               return 0;
+                               }
+                       if (!s->hit)
+                               {
+                               if(s->session->tlsext_ecpointformatlist)
+                                       {
+                                       OPENSSL_free(s->session->tlsext_ecpointformatlist);
+                                       s->session->tlsext_ecpointformatlist = NULL;
+                                       }
+                               s->session->tlsext_ecpointformatlist_length = 0;
+                               if ((s->session->tlsext_ecpointformatlist = OPENSSL_malloc(ecpointformatlist_length)) == NULL)
+                                       {
+                                       *al = TLS1_AD_INTERNAL_ERROR;
+                                       return 0;
+                                       }
+                               s->session->tlsext_ecpointformatlist_length = ecpointformatlist_length;
+                               memcpy(s->session->tlsext_ecpointformatlist, sdata, ecpointformatlist_length);
+                               }
+#if 0
+                       fprintf(stderr,"ssl_parse_clienthello_tlsext s->session->tlsext_ecpointformatlist (length=%i) ", s->session->tlsext_ecpointformatlist_length);
+                       sdata = s->session->tlsext_ecpointformatlist;
+                       for (i = 0; i < s->session->tlsext_ecpointformatlist_length; i++)
+                               fprintf(stderr,"%i ",*(sdata++));
+                       fprintf(stderr,"\n");
+#endif
+                       }
+               else if (type == TLSEXT_TYPE_elliptic_curves &&
+                    s->version != DTLS1_VERSION)
+                       {
+                       unsigned char *sdata = data;
+                       int ellipticcurvelist_length = (*(sdata++) << 8);
+                       ellipticcurvelist_length += (*(sdata++));
+
+                       if (ellipticcurvelist_length != size - 2)
+                               {
+                               *al = TLS1_AD_DECODE_ERROR;
+                               return 0;
+                               }
+                       if (!s->hit)
+                               {
+                               if(s->session->tlsext_ellipticcurvelist)
+                                       {
+                                       *al = TLS1_AD_DECODE_ERROR;
+                                       return 0;
+                                       }
+                               s->session->tlsext_ellipticcurvelist_length = 0;
+                               if ((s->session->tlsext_ellipticcurvelist = OPENSSL_malloc(ellipticcurvelist_length)) == NULL)
+                                       {
+                                       *al = TLS1_AD_INTERNAL_ERROR;
+                                       return 0;
+                                       }
+                               s->session->tlsext_ellipticcurvelist_length = ellipticcurvelist_length;
+                               memcpy(s->session->tlsext_ellipticcurvelist, sdata, ellipticcurvelist_length);
+                               }
+#if 0
+                       fprintf(stderr,"ssl_parse_clienthello_tlsext s->session->tlsext_ellipticcurvelist (length=%i) ", s->session->tlsext_ellipticcurvelist_length);
+                       sdata = s->session->tlsext_ellipticcurvelist;
+                       for (i = 0; i < s->session->tlsext_ellipticcurvelist_length; i++)
+                               fprintf(stderr,"%i ",*(sdata++));
+                       fprintf(stderr,"\n");
+#endif
+                       }
+#endif /* OPENSSL_NO_EC */
+#ifdef TLSEXT_TYPE_opaque_prf_input
+               else if (type == TLSEXT_TYPE_opaque_prf_input &&
+                    s->version != DTLS1_VERSION)
+                       {
+                       unsigned char *sdata = data;
+
+                       if (size < 2)
+                               {
+                               *al = SSL_AD_DECODE_ERROR;
+                               return 0;
+                               }
+                       n2s(sdata, s->s3->client_opaque_prf_input_len);
+                       if (s->s3->client_opaque_prf_input_len != size - 2)
+                               {
+                               *al = SSL_AD_DECODE_ERROR;
+                               return 0;
+                               }
+
+                       if (s->s3->client_opaque_prf_input != NULL) /* shouldn't really happen */
+                               OPENSSL_free(s->s3->client_opaque_prf_input);
+                       if (s->s3->client_opaque_prf_input_len == 0)
+                               s->s3->client_opaque_prf_input = OPENSSL_malloc(1); /* dummy byte just to get non-NULL */
+                       else
+                               s->s3->client_opaque_prf_input = BUF_memdup(sdata, s->s3->client_opaque_prf_input_len);
+                       if (s->s3->client_opaque_prf_input == NULL)
+                               {
+                               *al = TLS1_AD_INTERNAL_ERROR;
+                               return 0;
+                               }
+                       }
+#endif
+               else if (type == TLSEXT_TYPE_session_ticket)
+                       {
+                       if (s->tls_session_ticket_ext_cb &&
+                           !s->tls_session_ticket_ext_cb(s, data, size, s->tls_session_ticket_ext_cb_arg))
+                               {
+                               *al = TLS1_AD_INTERNAL_ERROR;
+                               return 0;
+                               }
+                       }
                else if (type == TLSEXT_TYPE_renegotiate)
                        {
                        if(!ssl_parse_clienthello_renegotiate_ext(s, data, size, al))
@@ -790,6 +1009,12 @@ int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
                                sdata = data;
                                if (dsize > 0)
                                        {
+                                       if (s->tlsext_ocsp_exts)
+                                               {
+                                               sk_X509_EXTENSION_pop_free(s->tlsext_ocsp_exts,
+                                                                          X509_EXTENSION_free);
+                                               }
+
                                        s->tlsext_ocsp_exts =
                                                d2i_X509_EXTENSIONS(NULL,
                                                        &sdata, dsize);
@@ -807,10 +1032,12 @@ int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
                                else
                                        s->tlsext_status_type = -1;
                        }
-               else if (type == TLSEXT_TYPE_next_proto_neg)
+#ifndef OPENSSL_NO_NEXTPROTONEG
+               else if (type == TLSEXT_TYPE_next_proto_neg &&
+                         s->s3->tmp.finish_md_len == 0)
                        {
                        /* We shouldn't accept this extension on a
-                        * renegotiation, but we currently do.
+                        * renegotiation.
                         *
                         * s->new_session will be set on renegotiation, but we
                         * probably shouldn't rely that it couldn't be set on
@@ -826,17 +1053,12 @@ int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
                         * Finished message could have been computed.) */
                        s->s3->next_proto_neg_seen = 1;
                        }
-
-               else if (type == TLSEXT_TYPE_snap_start && s->ctx->snap_start_orbit_valid)
-                       {
-                       if (ssl_parse_snap_start_tlsext(s, data, size) == 0)
-                               return 0;
-                       }
+#endif
 
                /* session ticket processed earlier */
-
-               data+=size;             
+               data+=size;
                }
+                               
        *p = data;
 
        ri_check:
@@ -855,10 +1077,11 @@ int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
        return 1;
        }
 
+#ifndef OPENSSL_NO_NEXTPROTONEG
 /* ssl_next_proto_validate validates a Next Protocol Negotiation block. No
  * elements of zero length are allowed and the set of elements must exactly fill
  * the length of the block. */
-static char ssl_next_proto_validate(unsigned char *d, unsigned len)
+static int ssl_next_proto_validate(unsigned char *d, unsigned len)
        {
        unsigned int off = 0;
 
@@ -872,6 +1095,7 @@ static char ssl_next_proto_validate(unsigned char *d, unsigned len)
 
        return off == len;
        }
+#endif
 
 int ssl_parse_serverhello_tlsext(SSL *s, unsigned char **p, unsigned char *d, int n, int *al)
        {
@@ -913,8 +1137,46 @@ int ssl_parse_serverhello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
                                }
                        tlsext_servername = 1;   
                        }
+
+#ifndef OPENSSL_NO_EC
+               else if (type == TLSEXT_TYPE_ec_point_formats &&
+                    s->version != DTLS1_VERSION)
+                       {
+                       unsigned char *sdata = data;
+                       int ecpointformatlist_length = *(sdata++);
+
+                       if (ecpointformatlist_length != size - 1)
+                               {
+                               *al = TLS1_AD_DECODE_ERROR;
+                               return 0;
+                               }
+                       s->session->tlsext_ecpointformatlist_length = 0;
+                       if (s->session->tlsext_ecpointformatlist != NULL) OPENSSL_free(s->session->tlsext_ecpointformatlist);
+                       if ((s->session->tlsext_ecpointformatlist = OPENSSL_malloc(ecpointformatlist_length)) == NULL)
+                               {
+                               *al = TLS1_AD_INTERNAL_ERROR;
+                               return 0;
+                               }
+                       s->session->tlsext_ecpointformatlist_length = ecpointformatlist_length;
+                       memcpy(s->session->tlsext_ecpointformatlist, sdata, ecpointformatlist_length);
+#if 0
+                       fprintf(stderr,"ssl_parse_serverhello_tlsext s->session->tlsext_ecpointformatlist ");
+                       sdata = s->session->tlsext_ecpointformatlist;
+                       for (i = 0; i < s->session->tlsext_ecpointformatlist_length; i++)
+                               fprintf(stderr,"%i ",*(sdata++));
+                       fprintf(stderr,"\n");
+#endif
+                       }
+#endif /* OPENSSL_NO_EC */
+
                else if (type == TLSEXT_TYPE_session_ticket)
                        {
+                       if (s->tls_session_ticket_ext_cb &&
+                           !s->tls_session_ticket_ext_cb(s, data, size, s->tls_session_ticket_ext_cb_arg))
+                               {
+                               *al = TLS1_AD_INTERNAL_ERROR;
+                               return 0;
+                               }
                        if ((SSL_get_options(s) & SSL_OP_NO_TICKET)
                                || (size > 0))
                                {
@@ -923,6 +1185,38 @@ int ssl_parse_serverhello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
                                }
                        s->tlsext_ticket_expected = 1;
                        }
+#ifdef TLSEXT_TYPE_opaque_prf_input
+               else if (type == TLSEXT_TYPE_opaque_prf_input &&
+                    s->version != DTLS1_VERSION)
+                       {
+                       unsigned char *sdata = data;
+
+                       if (size < 2)
+                               {
+                               *al = SSL_AD_DECODE_ERROR;
+                               return 0;
+                               }
+                       n2s(sdata, s->s3->server_opaque_prf_input_len);
+                       if (s->s3->server_opaque_prf_input_len != size - 2)
+                               {
+                               *al = SSL_AD_DECODE_ERROR;
+                               return 0;
+                               }
+                       
+                       if (s->s3->server_opaque_prf_input != NULL) /* shouldn't really happen */
+                               OPENSSL_free(s->s3->server_opaque_prf_input);
+                       if (s->s3->server_opaque_prf_input_len == 0)
+                               s->s3->server_opaque_prf_input = OPENSSL_malloc(1); /* dummy byte just to get non-NULL */
+                       else
+                               s->s3->server_opaque_prf_input = BUF_memdup(sdata, s->s3->server_opaque_prf_input_len);
+
+                       if (s->s3->server_opaque_prf_input == NULL)
+                               {
+                               *al = TLS1_AD_INTERNAL_ERROR;
+                               return 0;
+                               }
+                       }
+#endif
                else if (type == TLSEXT_TYPE_status_request &&
                         s->version != DTLS1_VERSION)
                        {
@@ -937,6 +1231,7 @@ int ssl_parse_serverhello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
                        /* Set flag to expect CertificateStatus message */
                        s->tlsext_status_expected = 1;
                        }
+#ifndef OPENSSL_NO_NEXTPROTONEG
                else if (type == TLSEXT_TYPE_next_proto_neg)
                        {
                        unsigned char *selected;
@@ -968,6 +1263,7 @@ int ssl_parse_serverhello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
                        memcpy(s->next_proto_negotiated, selected, selected_len);
                        s->next_proto_negotiated_len = selected_len;
                        }
+#endif
                else if (type == TLSEXT_TYPE_renegotiate)
                        {
                        if(!ssl_parse_serverhello_renegotiate_ext(s, data, size, al))
@@ -1028,11 +1324,142 @@ int ssl_parse_serverhello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
        return 1;
        }
 
+
+int ssl_prepare_clienthello_tlsext(SSL *s)
+       {
+#ifndef OPENSSL_NO_EC
+       /* If we are client and using an elliptic curve cryptography cipher suite, send the point formats 
+        * and elliptic curves we support.
+        */
+       int using_ecc = 0;
+       int i;
+       unsigned char *j;
+       unsigned long alg_k, alg_a;
+       STACK_OF(SSL_CIPHER) *cipher_stack = SSL_get_ciphers(s);
+
+       for (i = 0; i < sk_SSL_CIPHER_num(cipher_stack); i++)
+               {
+               SSL_CIPHER *c = sk_SSL_CIPHER_value(cipher_stack, i);
+
+               alg_k = c->algorithm_mkey;
+               alg_a = c->algorithm_auth;
+               if ((alg_k & (SSL_kEECDH|SSL_kECDHr|SSL_kECDHe) || (alg_a & SSL_aECDSA)))
+                       {
+                       using_ecc = 1;
+                       break;
+                       }
+               }
+       using_ecc = using_ecc && (s->version == TLS1_VERSION);
+       if (using_ecc)
+               {
+               if (s->tlsext_ecpointformatlist != NULL) OPENSSL_free(s->tlsext_ecpointformatlist);
+               if ((s->tlsext_ecpointformatlist = OPENSSL_malloc(3)) == NULL)
+                       {
+                       SSLerr(SSL_F_SSL_PREPARE_CLIENTHELLO_TLSEXT,ERR_R_MALLOC_FAILURE);
+                       return -1;
+                       }
+               s->tlsext_ecpointformatlist_length = 3;
+               s->tlsext_ecpointformatlist[0] = TLSEXT_ECPOINTFORMAT_uncompressed;
+               s->tlsext_ecpointformatlist[1] = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime;
+               s->tlsext_ecpointformatlist[2] = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2;
+
+               /* we support all named elliptic curves in draft-ietf-tls-ecc-12 */
+               if (s->tlsext_ellipticcurvelist != NULL) OPENSSL_free(s->tlsext_ellipticcurvelist);
+               s->tlsext_ellipticcurvelist_length = sizeof(nid_list)/sizeof(nid_list[0]) * 2;
+               if ((s->tlsext_ellipticcurvelist = OPENSSL_malloc(s->tlsext_ellipticcurvelist_length)) == NULL)
+                       {
+                       s->tlsext_ellipticcurvelist_length = 0;
+                       SSLerr(SSL_F_SSL_PREPARE_CLIENTHELLO_TLSEXT,ERR_R_MALLOC_FAILURE);
+                       return -1;
+                       }
+               for (i = 1, j = s->tlsext_ellipticcurvelist; (unsigned int)i <=
+                               sizeof(nid_list)/sizeof(nid_list[0]); i++)
+                       s2n(i,j);
+               }
+#endif /* OPENSSL_NO_EC */
+
+#ifdef TLSEXT_TYPE_opaque_prf_input
+       {
+               int r = 1;
+       
+               if (s->ctx->tlsext_opaque_prf_input_callback != 0)
+                       {
+                       r = s->ctx->tlsext_opaque_prf_input_callback(s, NULL, 0, s->ctx->tlsext_opaque_prf_input_callback_arg);
+                       if (!r)
+                               return -1;
+                       }
+
+               if (s->tlsext_opaque_prf_input != NULL)
+                       {
+                       if (s->s3->client_opaque_prf_input != NULL) /* shouldn't really happen */
+                               OPENSSL_free(s->s3->client_opaque_prf_input);
+
+                       if (s->tlsext_opaque_prf_input_len == 0)
+                               s->s3->client_opaque_prf_input = OPENSSL_malloc(1); /* dummy byte just to get non-NULL */
+                       else
+                               s->s3->client_opaque_prf_input = BUF_memdup(s->tlsext_opaque_prf_input, s->tlsext_opaque_prf_input_len);
+                       if (s->s3->client_opaque_prf_input == NULL)
+                               {
+                               SSLerr(SSL_F_SSL_PREPARE_CLIENTHELLO_TLSEXT,ERR_R_MALLOC_FAILURE);
+                               return -1;
+                               }
+                       s->s3->client_opaque_prf_input_len = s->tlsext_opaque_prf_input_len;
+                       }
+
+               if (r == 2)
+                       /* at callback's request, insist on receiving an appropriate server opaque PRF input */
+                       s->s3->server_opaque_prf_input_len = s->tlsext_opaque_prf_input_len;
+       }
+#endif
+
+       return 1;
+       }
+
+int ssl_prepare_serverhello_tlsext(SSL *s)
+       {
+#ifndef OPENSSL_NO_EC
+       /* If we are server and using an ECC cipher suite, send the point formats we support 
+        * if the client sent us an ECPointsFormat extension.  Note that the server is not
+        * supposed to send an EllipticCurves extension.
+        */
+
+       unsigned long alg_k = s->s3->tmp.new_cipher->algorithm_mkey;
+       unsigned long alg_a = s->s3->tmp.new_cipher->algorithm_auth;
+       int using_ecc = (alg_k & (SSL_kEECDH|SSL_kECDHr|SSL_kECDHe)) || (alg_a & SSL_aECDSA);
+       using_ecc = using_ecc && (s->session->tlsext_ecpointformatlist != NULL);
+       
+       if (using_ecc)
+               {
+               if (s->tlsext_ecpointformatlist != NULL) OPENSSL_free(s->tlsext_ecpointformatlist);
+               if ((s->tlsext_ecpointformatlist = OPENSSL_malloc(3)) == NULL)
+                       {
+                       SSLerr(SSL_F_SSL_PREPARE_SERVERHELLO_TLSEXT,ERR_R_MALLOC_FAILURE);
+                       return -1;
+                       }
+               s->tlsext_ecpointformatlist_length = 3;
+               s->tlsext_ecpointformatlist[0] = TLSEXT_ECPOINTFORMAT_uncompressed;
+               s->tlsext_ecpointformatlist[1] = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime;
+               s->tlsext_ecpointformatlist[2] = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2;
+               }
+#endif /* OPENSSL_NO_EC */
+
+       return 1;
+       }
+
 int ssl_check_clienthello_tlsext(SSL *s)
        {
        int ret=SSL_TLSEXT_ERR_NOACK;
        int al = SSL_AD_UNRECOGNIZED_NAME;
 
+#ifndef OPENSSL_NO_EC
+       /* The handling of the ECPointFormats extension is done elsewhere, namely in 
+        * ssl3_choose_cipher in s3_lib.c.
+        */
+       /* The handling of the EllipticCurves extension is done elsewhere, namely in 
+        * ssl3_choose_cipher in s3_lib.c.
+        */
+#endif
+
        if (s->ctx != NULL && s->ctx->tlsext_servername_callback != 0) 
                ret = s->ctx->tlsext_servername_callback(s, &al, s->ctx->tlsext_servername_arg);
        else if (s->initial_ctx != NULL && s->initial_ctx->tlsext_servername_callback != 0)             
@@ -1042,7 +1469,7 @@ int ssl_check_clienthello_tlsext(SSL *s)
         * Note: this must be called after servername callbacks in case 
         * the certificate has changed.
         */
-       if ((s->tlsext_status_type != -1) && s->ctx->tlsext_status_cb)
+       if ((s->tlsext_status_type != -1) && s->ctx && s->ctx->tlsext_status_cb)
                {
                int r;
                r = s->ctx->tlsext_status_cb(s, s->ctx->tlsext_status_arg);
@@ -1068,7 +1495,65 @@ int ssl_check_clienthello_tlsext(SSL *s)
                }
        else
                s->tlsext_status_expected = 0;
-       err:
+
+#ifdef TLSEXT_TYPE_opaque_prf_input
+       {
+               /* This sort of belongs into ssl_prepare_serverhello_tlsext(),
+                * but we might be sending an alert in response to the client hello,
+                * so this has to happen here in ssl_check_clienthello_tlsext(). */
+
+               int r = 1;
+       
+               if (s->ctx->tlsext_opaque_prf_input_callback != 0)
+                       {
+                       r = s->ctx->tlsext_opaque_prf_input_callback(s, NULL, 0, s->ctx->tlsext_opaque_prf_input_callback_arg);
+                       if (!r)
+                               {
+                               ret = SSL_TLSEXT_ERR_ALERT_FATAL;
+                               al = SSL_AD_INTERNAL_ERROR;
+                               goto err;
+                               }
+                       }
+
+               if (s->s3->server_opaque_prf_input != NULL) /* shouldn't really happen */
+                       OPENSSL_free(s->s3->server_opaque_prf_input);
+               s->s3->server_opaque_prf_input = NULL;
+
+               if (s->tlsext_opaque_prf_input != NULL)
+                       {
+                       if (s->s3->client_opaque_prf_input != NULL &&
+                               s->s3->client_opaque_prf_input_len == s->tlsext_opaque_prf_input_len)
+                               {
+                               /* can only use this extension if we have a server opaque PRF input
+                                * of the same length as the client opaque PRF input! */
+
+                               if (s->tlsext_opaque_prf_input_len == 0)
+                                       s->s3->server_opaque_prf_input = OPENSSL_malloc(1); /* dummy byte just to get non-NULL */
+                               else
+                                       s->s3->server_opaque_prf_input = BUF_memdup(s->tlsext_opaque_prf_input, s->tlsext_opaque_prf_input_len);
+                               if (s->s3->server_opaque_prf_input == NULL)
+                                       {
+                                       ret = SSL_TLSEXT_ERR_ALERT_FATAL;
+                                       al = SSL_AD_INTERNAL_ERROR;
+                                       goto err;
+                                       }
+                               s->s3->server_opaque_prf_input_len = s->tlsext_opaque_prf_input_len;
+                               }
+                       }
+
+               if (r == 2 && s->s3->server_opaque_prf_input == NULL)
+                       {
+                       /* The callback wants to enforce use of the extension,
+                        * but we can't do that with the client opaque PRF input;
+                        * abort the handshake.
+                        */
+                       ret = SSL_TLSEXT_ERR_ALERT_FATAL;
+                       al = SSL_AD_HANDSHAKE_FAILURE;
+                       }
+       }
+
+#endif
+ err:
        switch (ret)
                {
                case SSL_TLSEXT_ERR_ALERT_FATAL:
@@ -1091,16 +1576,72 @@ int ssl_check_serverhello_tlsext(SSL *s)
        int ret=SSL_TLSEXT_ERR_NOACK;
        int al = SSL_AD_UNRECOGNIZED_NAME;
 
+#ifndef OPENSSL_NO_EC
+       /* If we are client and using an elliptic curve cryptography cipher
+        * suite, then if server returns an EC point formats lists extension
+        * it must contain uncompressed.
+        */
+       unsigned long alg_k = s->s3->tmp.new_cipher->algorithm_mkey;
+       unsigned long alg_a = s->s3->tmp.new_cipher->algorithm_auth;
+       if ((s->tlsext_ecpointformatlist != NULL) && (s->tlsext_ecpointformatlist_length > 0) && 
+           (s->session->tlsext_ecpointformatlist != NULL) && (s->session->tlsext_ecpointformatlist_length > 0) && 
+           ((alg_k & (SSL_kEECDH|SSL_kECDHr|SSL_kECDHe)) || (alg_a & SSL_aECDSA)))
+               {
+               /* we are using an ECC cipher */
+               size_t i;
+               unsigned char *list;
+               int found_uncompressed = 0;
+               list = s->session->tlsext_ecpointformatlist;
+               for (i = 0; i < s->session->tlsext_ecpointformatlist_length; i++)
+                       {
+                       if (*(list++) == TLSEXT_ECPOINTFORMAT_uncompressed)
+                               {
+                               found_uncompressed = 1;
+                               break;
+                               }
+                       }
+               if (!found_uncompressed)
+                       {
+                       SSLerr(SSL_F_SSL_CHECK_SERVERHELLO_TLSEXT,SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST);
+                       return -1;
+                       }
+               }
+       ret = SSL_TLSEXT_ERR_OK;
+#endif /* OPENSSL_NO_EC */
+
        if (s->ctx != NULL && s->ctx->tlsext_servername_callback != 0) 
                ret = s->ctx->tlsext_servername_callback(s, &al, s->ctx->tlsext_servername_arg);
        else if (s->initial_ctx != NULL && s->initial_ctx->tlsext_servername_callback != 0)             
                ret = s->initial_ctx->tlsext_servername_callback(s, &al, s->initial_ctx->tlsext_servername_arg);
 
+#ifdef TLSEXT_TYPE_opaque_prf_input
+       if (s->s3->server_opaque_prf_input_len > 0)
+               {
+               /* This case may indicate that we, as a client, want to insist on using opaque PRF inputs.
+                * So first verify that we really have a value from the server too. */
+
+               if (s->s3->server_opaque_prf_input == NULL)
+                       {
+                       ret = SSL_TLSEXT_ERR_ALERT_FATAL;
+                       al = SSL_AD_HANDSHAKE_FAILURE;
+                       }
+               
+               /* Anytime the server *has* sent an opaque PRF input, we need to check
+                * that we have a client opaque PRF input of the same size. */
+               if (s->s3->client_opaque_prf_input == NULL ||
+                   s->s3->client_opaque_prf_input_len != s->s3->server_opaque_prf_input_len)
+                       {
+                       ret = SSL_TLSEXT_ERR_ALERT_FATAL;
+                       al = SSL_AD_ILLEGAL_PARAMETER;
+                       }
+               }
+#endif
+
        /* If we've requested certificate status and we wont get one
         * tell the callback
         */
        if ((s->tlsext_status_type != -1) && !(s->tlsext_status_expected)
-                       && s->ctx->tlsext_status_cb)
+                       && s->ctx && s->ctx->tlsext_status_cb)
                {
                int r;
                /* Set resp to NULL, resplen to -1 so callback knows
@@ -1195,6 +1736,11 @@ int tls1_process_ticket(SSL *s, unsigned char *session_id, int len,
                        return 1;
                if (type == TLSEXT_TYPE_session_ticket)
                        {
+                       /* If tickets disabled indicate cache miss which will
+                        * trigger a full handshake
+                        */
+                       if (SSL_get_options(s) & SSL_OP_NO_TICKET)
+                               return 1;
                        /* If zero length note client will accept a ticket
                         * and indicate cache miss to trigger full handshake
                         */
@@ -1203,6 +1749,15 @@ int tls1_process_ticket(SSL *s, unsigned char *session_id, int len,
                                s->tlsext_ticket_expected = 1;
                                return 0;       /* Cache miss */
                                }
+                       if (s->tls_session_secret_cb)
+                               {
+                               /* Indicate cache miss here and instead of
+                                * generating the session from ticket now,
+                                * trigger abbreviated handshake based on
+                                * external mechanism to calculate the master
+                                * secret later. */
+                               return 0;
+                               }
                        return tls_decrypt_ticket(s, p, size, session_id, len,
                                                                        ret);
                        }
@@ -1255,6 +1810,11 @@ static int tls_decrypt_ticket(SSL *s, const unsigned char *etick, int eticklen,
         * integrity checks on ticket.
         */
        mlen = HMAC_size(&hctx);
+       if (mlen < 0)
+               {
+               EVP_CIPHER_CTX_cleanup(&ctx);
+               return -1;
+               }
        eticklen -= mlen;
        /* Check HMAC of encrypted ticket */
        HMAC_Update(&hctx, etick, eticklen);
index f5d8df6..6ce7c0b 100644 (file)
@@ -60,8 +60,8 @@
 #include <openssl/objects.h>
 #include "ssl_locl.h"
 
-static SSL_METHOD *tls1_get_method(int ver);
-static SSL_METHOD *tls1_get_method(int ver)
+static const SSL_METHOD *tls1_get_method(int ver);
+static const SSL_METHOD *tls1_get_method(int ver)
        {
        if (ver == TLS1_VERSION)
                return(TLSv1_method());
index b75636a..42525e9 100644 (file)
@@ -64,8 +64,8 @@
 #include <openssl/evp.h>
 #include <openssl/x509.h>
 
-static SSL_METHOD *tls1_get_server_method(int ver);
-static SSL_METHOD *tls1_get_server_method(int ver)
+static const SSL_METHOD *tls1_get_server_method(int ver);
+static const SSL_METHOD *tls1_get_server_method(int ver)
        {
        if (ver == TLS1_VERSION)
                return(TLSv1_server_method());
index 52ff325..71f9722 100644 (file)
  * [including the GNU Public Licence.]
  */
 /* ====================================================================
+ * Copyright (c) 1998-2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    openssl-core@openssl.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+/* ====================================================================
  * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
  *
  * Portions of the attached software ("Contribution") are developed by 
  * Vipul Gupta and Sumit Gupta of Sun Microsystems Laboratories.
  *
  */
+/* ====================================================================
+ * Copyright 2005 Nokia. All rights reserved.
+ *
+ * The portions of the attached software ("Contribution") is developed by
+ * Nokia Corporation and is licensed pursuant to the OpenSSL open source
+ * license.
+ *
+ * The Contribution, originally written by Mika Kousa and Pasi Eronen of
+ * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
+ * support (see RFC 4279) to OpenSSL.
+ *
+ * No patent licenses or other rights except those expressly stated in
+ * the OpenSSL open source license shall be deemed granted or received
+ * expressly, by implication, estoppel, or otherwise.
+ *
+ * No assurances are provided by Nokia that the Contribution does not
+ * infringe the patent or other intellectual property rights of any third
+ * party or that the license provides you with all the necessary rights
+ * to make use of the Contribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
+ * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
+ * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
+ * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
+ * OTHERWISE.
+ */
 
 #ifndef HEADER_TLS1_H 
 #define HEADER_TLS1_H 
@@ -104,36 +183,53 @@ extern "C" {
 #define TLS1_AD_BAD_CERTIFICATE_HASH_VALUE 114
 #define TLS1_AD_UNKNOWN_PSK_IDENTITY   115     /* fatal */
 
-/* ExtensionType values from RFC 3546 */
+/* ExtensionType values from RFC3546 / RFC4366 */
 #define TLSEXT_TYPE_server_name                        0
 #define TLSEXT_TYPE_max_fragment_length                1
 #define TLSEXT_TYPE_client_certificate_url     2
 #define TLSEXT_TYPE_trusted_ca_keys            3
 #define TLSEXT_TYPE_truncated_hmac             4
 #define TLSEXT_TYPE_status_request             5
+/* ExtensionType values from RFC4492 */
 #define TLSEXT_TYPE_elliptic_curves            10
 #define TLSEXT_TYPE_ec_point_formats           11
 #define TLSEXT_TYPE_session_ticket             35
+/* ExtensionType value from draft-rescorla-tls-opaque-prf-input-00.txt */
+#if 0 /* will have to be provided externally for now ,
+       * i.e. build with -DTLSEXT_TYPE_opaque_prf_input=38183
+       * using whatever extension number you'd like to try */
+# define TLSEXT_TYPE_opaque_prf_input          ?? */
+#endif
 
 /* Temporary extension type */
 #define TLSEXT_TYPE_renegotiate                 0xff01
 
+#ifndef OPENSSL_NO_NEXTPROTONEG
 /* This is not an IANA defined extension number */
 #define TLSEXT_TYPE_next_proto_neg             13172
-  /* http://tools.ietf.org/html/draft-agl-tls-snapstart-00 */
-#define TLSEXT_TYPE_snap_start                 13174
+#endif
 
 /* NameType value from RFC 3546 */
 #define TLSEXT_NAMETYPE_host_name 0
 /* status request value from RFC 3546 */
 #define TLSEXT_STATUSTYPE_ocsp 1
 
+/* ECPointFormat values from draft-ietf-tls-ecc-12 */
+#define TLSEXT_ECPOINTFORMAT_first                     0
+#define TLSEXT_ECPOINTFORMAT_uncompressed              0
+#define TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime 1
+#define TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2 2
+#define TLSEXT_ECPOINTFORMAT_last                      2
+
 #ifndef OPENSSL_NO_TLSEXT
 
 #define TLSEXT_MAXLEN_host_name 255
 
 const char *SSL_get_servername(const SSL *s, const int type) ;
 int SSL_get_servername_type(const SSL *s) ;
+int SSL_export_keying_material(SSL *s, unsigned char *out, size_t olen,
+       const char *label, size_t llen, const unsigned char *p, size_t plen,
+       int use_context);
 
 #define SSL_set_tlsext_host_name(s,name) \
 SSL_ctrl(s,SSL_CTRL_SET_TLSEXT_HOSTNAME,TLSEXT_NAMETYPE_host_name,(char *)name)
@@ -187,17 +283,31 @@ SSL_CTX_callback_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB,(void (*)(void))cb)
 #define SSL_CTX_set_tlsext_status_arg(ssl, arg) \
 SSL_CTX_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG,0, (void *)arg)
 
+#define SSL_set_tlsext_opaque_prf_input(s, src, len) \
+SSL_ctrl(s,SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT, len, src)
+#define SSL_CTX_set_tlsext_opaque_prf_input_callback(ctx, cb) \
+SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB, (void (*)(void))cb)
+#define SSL_CTX_set_tlsext_opaque_prf_input_callback_arg(ctx, arg) \
+SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB_ARG, 0, arg)
+
 #define SSL_CTX_set_tlsext_ticket_key_cb(ssl, cb) \
 SSL_CTX_callback_ctrl(ssl,SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB,(void (*)(void))cb)
 
 #endif
 
-/* Additional TLS ciphersuites from draft-ietf-tls-56-bit-ciphersuites-00.txt
+/* PSK ciphersuites from 4279 */
+#define TLS1_CK_PSK_WITH_RC4_128_SHA                    0x0300008A
+#define TLS1_CK_PSK_WITH_3DES_EDE_CBC_SHA               0x0300008B
+#define TLS1_CK_PSK_WITH_AES_128_CBC_SHA                0x0300008C
+#define TLS1_CK_PSK_WITH_AES_256_CBC_SHA                0x0300008D
+
+/* Additional TLS ciphersuites from expired Internet Draft
+ * draft-ietf-tls-56-bit-ciphersuites-01.txt
  * (available if TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES is defined, see
  * s3_lib.c).  We actually treat them like SSL 3.0 ciphers, which we probably
- * shouldn't. */
-#define TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_MD5         0x03000060
-#define TLS1_CK_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5     0x03000061
+ * shouldn't.  Note that the first two are actually not in the IDs. */
+#define TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_MD5         0x03000060 /* not in ID */
+#define TLS1_CK_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5     0x03000061 /* not in ID */
 #define TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA                0x03000062
 #define TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA    0x03000063
 #define TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_SHA         0x03000064
@@ -335,6 +445,12 @@ SSL_CTX_callback_ctrl(ssl,SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB,(void (*)(void))cb)
 #define TLS1_TXT_ECDH_anon_WITH_AES_128_CBC_SHA         "AECDH-AES128-SHA"
 #define TLS1_TXT_ECDH_anon_WITH_AES_256_CBC_SHA         "AECDH-AES256-SHA"
 
+/* PSK ciphersuites from RFC 4279 */
+#define TLS1_TXT_PSK_WITH_RC4_128_SHA                  "PSK-RC4-SHA"
+#define TLS1_TXT_PSK_WITH_3DES_EDE_CBC_SHA             "PSK-3DES-EDE-CBC-SHA"
+#define TLS1_TXT_PSK_WITH_AES_128_CBC_SHA              "PSK-AES128-CBC-SHA"
+#define TLS1_TXT_PSK_WITH_AES_256_CBC_SHA              "PSK-AES256-CBC-SHA"
+
 /* Camellia ciphersuites from RFC4132 */
 #define TLS1_TXT_RSA_WITH_CAMELLIA_128_CBC_SHA         "CAMELLIA128-SHA"
 #define TLS1_TXT_DH_DSS_WITH_CAMELLIA_128_CBC_SHA      "DH-DSS-CAMELLIA128-SHA"
@@ -358,6 +474,7 @@ SSL_CTX_callback_ctrl(ssl,SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB,(void (*)(void))cb)
 #define TLS1_TXT_DHE_RSA_WITH_SEED_SHA                  "DHE-RSA-SEED-SHA"
 #define TLS1_TXT_ADH_WITH_SEED_SHA                      "ADH-SEED-SHA"
 
+
 #define TLS_CT_RSA_SIGN                        1
 #define TLS_CT_DSS_SIGN                        2
 #define TLS_CT_RSA_FIXED_DH            3
@@ -365,7 +482,11 @@ SSL_CTX_callback_ctrl(ssl,SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB,(void (*)(void))cb)
 #define TLS_CT_ECDSA_SIGN              64
 #define TLS_CT_RSA_FIXED_ECDH          65
 #define TLS_CT_ECDSA_FIXED_ECDH        66
-#define TLS_CT_NUMBER                  7
+#define TLS_CT_GOST94_SIGN             21
+#define TLS_CT_GOST01_SIGN             22
+/* when correcting this number, correct also SSL3_CT_NUMBER in ssl3.h (see
+ * comment there) */
+#define TLS_CT_NUMBER                  9
 
 #define TLS1_FINISH_MAC_LENGTH         12
 
@@ -406,10 +527,14 @@ SSL_CTX_callback_ctrl(ssl,SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB,(void (*)(void))cb)
 #define TLS_MD_MASTER_SECRET_CONST    "\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74"  /*master secret*/
 #endif
 
+/* TLS Session Ticket extension struct */
+struct tls_session_ticket_ext_st
+       {
+       unsigned short length;
+       void *data;
+       };
+
 #ifdef  __cplusplus
 }
 #endif
 #endif
-
-
-
diff --git a/deps/openssl/openssl/test/CAss.cnf b/deps/openssl/openssl/test/CAss.cnf
new file mode 100644 (file)
index 0000000..20f8f05
--- /dev/null
@@ -0,0 +1,76 @@
+#
+# SSLeay example configuration file.
+# This is mostly being used for generation of certificate requests.
+#
+
+RANDFILE               = ./.rnd
+
+####################################################################
+[ req ]
+default_bits           = 512
+default_keyfile        = keySS.pem
+distinguished_name     = req_distinguished_name
+encrypt_rsa_key                = no
+default_md             = sha1
+
+[ req_distinguished_name ]
+countryName                    = Country Name (2 letter code)
+countryName_default            = AU
+countryName_value              = AU
+
+organizationName               = Organization Name (eg, company)
+organizationName_value         = Dodgy Brothers
+
+commonName                     = Common Name (eg, YOUR name)
+commonName_value               = Dodgy CA
+
+####################################################################
+[ ca ]
+default_ca     = CA_default            # The default ca section
+
+####################################################################
+[ CA_default ]
+
+dir            = ./demoCA              # Where everything is kept
+certs          = $dir/certs            # Where the issued certs are kept
+crl_dir                = $dir/crl              # Where the issued crl are kept
+database       = $dir/index.txt        # database index file.
+#unique_subject        = no                    # Set to 'no' to allow creation of
+                                       # several ctificates with same subject.
+new_certs_dir  = $dir/newcerts         # default place for new certs.
+
+certificate    = $dir/cacert.pem       # The CA certificate
+serial         = $dir/serial           # The current serial number
+crl            = $dir/crl.pem          # The current CRL
+private_key    = $dir/private/cakey.pem# The private key
+RANDFILE       = $dir/private/.rand    # private random number file
+
+x509_extensions        = v3_ca                 # The extentions to add to the cert
+
+name_opt       = ca_default            # Subject Name options
+cert_opt       = ca_default            # Certificate field options
+
+default_days   = 365                   # how long to certify for
+default_crl_days= 30                   # how long before next CRL
+default_md     = md5                   # which md to use.
+preserve       = no                    # keep passed DN ordering
+
+policy         = policy_anything
+
+[ policy_anything ]
+countryName            = optional
+stateOrProvinceName    = optional
+localityName           = optional
+organizationName       = optional
+organizationalUnitName = optional
+commonName             = supplied
+emailAddress           = optional
+
+
+
+[ v3_ca ]
+subjectKeyIdentifier=hash
+authorityKeyIdentifier=keyid:always,issuer:always
+basicConstraints = CA:true,pathlen:1
+keyUsage = cRLSign, keyCertSign
+issuerAltName=issuer:copy
diff --git a/deps/openssl/openssl/test/CAssdh.cnf b/deps/openssl/openssl/test/CAssdh.cnf
new file mode 100644 (file)
index 0000000..4e0a908
--- /dev/null
@@ -0,0 +1,24 @@
+#
+# SSLeay example configuration file.
+# This is mostly being used for generation of certificate requests.
+#
+# hacked by iang to do DH certs - CA
+
+RANDFILE              = ./.rnd
+
+####################################################################
+[ req ]
+distinguished_name    = req_distinguished_name
+encrypt_rsa_key               = no
+
+[ req_distinguished_name ]
+countryName                   = Country Name (2 letter code)
+countryName_default           = CU
+countryName_value             = CU
+
+organizationName              = Organization Name (eg, company)
+organizationName_value                = La Junta de la Revolucion
+
+commonName                    = Common Name (eg, YOUR name)
+commonName_value              = Junta
+
diff --git a/deps/openssl/openssl/test/CAssdsa.cnf b/deps/openssl/openssl/test/CAssdsa.cnf
new file mode 100644 (file)
index 0000000..a6b4d18
--- /dev/null
@@ -0,0 +1,23 @@
+#
+# SSLeay example configuration file.
+# This is mostly being used for generation of certificate requests.
+#
+# hacked by iang to do DSA certs - CA
+
+RANDFILE              = ./.rnd
+
+####################################################################
+[ req ]
+distinguished_name    = req_distinguished_name
+encrypt_rsa_key               = no
+
+[ req_distinguished_name ]
+countryName                   = Country Name (2 letter code)
+countryName_default           = ES
+countryName_value             = ES
+
+organizationName              = Organization Name (eg, company)
+organizationName_value                = Hermanos Locos
+
+commonName                    = Common Name (eg, YOUR name)
+commonName_value              = Hermanos Locos CA
diff --git a/deps/openssl/openssl/test/CAssrsa.cnf b/deps/openssl/openssl/test/CAssrsa.cnf
new file mode 100644 (file)
index 0000000..eb24a6d
--- /dev/null
@@ -0,0 +1,24 @@
+#
+# SSLeay example configuration file.
+# This is mostly being used for generation of certificate requests.
+#
+# create RSA certs - CA
+
+RANDFILE              = ./.rnd
+
+####################################################################
+[ req ]
+distinguished_name    = req_distinguished_name
+encrypt_key           = no
+
+[ req_distinguished_name ]
+countryName                   = Country Name (2 letter code)
+countryName_default           = ES
+countryName_value             = ES
+
+organizationName              = Organization Name (eg, company)
+organizationName_value                = Hermanos Locos
+
+commonName                    = Common Name (eg, YOUR name)
+commonName_value              = Hermanos Locos CA
+
diff --git a/deps/openssl/openssl/test/CAtsa.cnf b/deps/openssl/openssl/test/CAtsa.cnf
new file mode 100644 (file)
index 0000000..f5a275b
--- /dev/null
@@ -0,0 +1,163 @@
+
+#
+# This config is used by the Time Stamp Authority tests.
+#
+
+RANDFILE               = ./.rnd
+
+# Extra OBJECT IDENTIFIER info:
+oid_section            = new_oids
+
+TSDNSECT               = ts_cert_dn
+INDEX                  = 1
+
+[ new_oids ]
+
+# Policies used by the TSA tests.
+tsa_policy1 = 1.2.3.4.1
+tsa_policy2 = 1.2.3.4.5.6
+tsa_policy3 = 1.2.3.4.5.7
+
+#----------------------------------------------------------------------
+[ ca ]
+default_ca     = CA_default            # The default ca section
+
+[ CA_default ]
+
+dir            = ./demoCA
+certs          = $dir/certs            # Where the issued certs are kept
+database       = $dir/index.txt        # database index file.
+new_certs_dir  = $dir/newcerts         # default place for new certs.
+
+certificate    = $dir/cacert.pem       # The CA certificate
+serial         = $dir/serial           # The current serial number
+private_key    = $dir/private/cakey.pem# The private key
+RANDFILE       = $dir/private/.rand    # private random number file
+
+default_days   = 365                   # how long to certify for
+default_md     = sha1                  # which md to use.
+preserve       = no                    # keep passed DN ordering
+
+policy         = policy_match
+
+# For the CA policy
+[ policy_match ]
+countryName            = supplied
+stateOrProvinceName    = supplied
+organizationName       = supplied
+organizationalUnitName = optional
+commonName             = supplied
+emailAddress           = optional
+
+#----------------------------------------------------------------------
+[ req ]
+default_bits           = 1024
+default_md             = sha1
+distinguished_name     = $ENV::TSDNSECT
+encrypt_rsa_key                = no
+prompt                         = no
+# attributes           = req_attributes
+x509_extensions        = v3_ca # The extentions to add to the self signed cert
+
+string_mask = nombstr
+
+[ ts_ca_dn ]
+countryName                    = HU
+stateOrProvinceName            = Budapest
+localityName                   = Budapest
+organizationName               = Gov-CA Ltd.
+commonName                     = ca1
+
+[ ts_cert_dn ]
+countryName                    = HU
+stateOrProvinceName            = Budapest
+localityName                   = Buda
+organizationName               = Hun-TSA Ltd.
+commonName                     = tsa$ENV::INDEX
+
+[ tsa_cert ]
+
+# TSA server cert is not a CA cert.
+basicConstraints=CA:FALSE
+
+# The following key usage flags are needed for TSA server certificates.
+keyUsage = nonRepudiation, digitalSignature
+extendedKeyUsage = critical,timeStamping
+
+# PKIX recommendations harmless if included in all certificates.
+subjectKeyIdentifier=hash
+authorityKeyIdentifier=keyid,issuer:always
+
+[ non_tsa_cert ]
+
+# This is not a CA cert and not a TSA cert, either (timeStamping usage missing)
+basicConstraints=CA:FALSE
+
+# The following key usage flags are needed for TSA server certificates.
+keyUsage = nonRepudiation, digitalSignature
+# timeStamping is not supported by this certificate
+# extendedKeyUsage = critical,timeStamping
+
+# PKIX recommendations harmless if included in all certificates.
+subjectKeyIdentifier=hash
+authorityKeyIdentifier=keyid,issuer:always
+
+[ v3_req ]
+
+# Extensions to add to a certificate request
+basicConstraints = CA:FALSE
+keyUsage = nonRepudiation, digitalSignature
+
+[ v3_ca ]
+
+# Extensions for a typical CA
+
+subjectKeyIdentifier=hash
+authorityKeyIdentifier=keyid:always,issuer:always
+basicConstraints = critical,CA:true
+keyUsage = cRLSign, keyCertSign
+
+#----------------------------------------------------------------------
+[ tsa ]
+
+default_tsa = tsa_config1      # the default TSA section
+
+[ tsa_config1 ]
+
+# These are used by the TSA reply generation only.
+dir            = .                     # TSA root directory
+serial         = $dir/tsa_serial       # The current serial number (mandatory)
+signer_cert    = $dir/tsa_cert1.pem    # The TSA signing certificate
+                                       # (optional)
+certs          = $dir/tsaca.pem        # Certificate chain to include in reply
+                                       # (optional)
+signer_key     = $dir/tsa_key1.pem     # The TSA private key (optional)
+
+default_policy = tsa_policy1           # Policy if request did not specify it
+                                       # (optional)
+other_policies = tsa_policy2, tsa_policy3      # acceptable policies (optional)
+digests                = md5, sha1             # Acceptable message digests (mandatory)
+accuracy       = secs:1, millisecs:500, microsecs:100  # (optional)
+ordering               = yes   # Is ordering defined for timestamps?
+                               # (optional, default: no)
+tsa_name               = yes   # Must the TSA name be included in the reply?
+                               # (optional, default: no)
+ess_cert_id_chain      = yes   # Must the ESS cert id chain be included?
+                               # (optional, default: no)
+
+[ tsa_config2 ]
+
+# This configuration uses a certificate which doesn't have timeStamping usage.
+# These are used by the TSA reply generation only.
+dir            = .                     # TSA root directory
+serial         = $dir/tsa_serial       # The current serial number (mandatory)
+signer_cert    = $dir/tsa_cert2.pem    # The TSA signing certificate
+                                       # (optional)
+certs          = $dir/demoCA/cacert.pem# Certificate chain to include in reply
+                                       # (optional)
+signer_key     = $dir/tsa_key2.pem     # The TSA private key (optional)
+
+default_policy = tsa_policy1           # Policy if request did not specify it
+                                       # (optional)
+other_policies = tsa_policy2, tsa_policy3      # acceptable policies (optional)
+digests                = md5, sha1             # Acceptable message digests (mandatory)
diff --git a/deps/openssl/openssl/test/Makefile b/deps/openssl/openssl/test/Makefile
new file mode 100644 (file)
index 0000000..3912f82
--- /dev/null
@@ -0,0 +1,698 @@
+#
+# test/Makefile
+#
+
+DIR=           test
+TOP=           ..
+CC=            cc
+INCLUDES=      -I$(TOP) -I../include $(KRB5_INCLUDES)
+CFLAG=         -g
+MAKEDEPEND=    $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
+PERL=          perl
+# KRB5 stuff
+KRB5_INCLUDES=
+LIBKRB5=
+
+PEX_LIBS=
+EX_LIBS= #-lnsl -lsocket
+
+CFLAGS= $(INCLUDES) $(CFLAG)
+
+GENERAL=Makefile maketests.com \
+       tests.com testenc.com tx509.com trsa.com tcrl.com tsid.com treq.com \
+       tpkcs7.com tpkcs7d.com tverify.com testgen.com testss.com testssl.com \
+       testca.com VMSca-response.1 VMSca-response.2
+
+DLIBCRYPTO= ../libcrypto.a
+DLIBSSL= ../libssl.a
+LIBCRYPTO= -L.. -lcrypto
+LIBSSL= -L.. -lssl
+
+BNTEST=                bntest
+ECTEST=                ectest
+ECDSATEST=     ecdsatest
+ECDHTEST=      ecdhtest
+EXPTEST=       exptest
+IDEATEST=      ideatest
+SHATEST=       shatest
+SHA1TEST=      sha1test
+SHA256TEST=    sha256t
+SHA512TEST=    sha512t
+MDC2TEST=      mdc2test
+RMDTEST=       rmdtest
+MD2TEST=       md2test
+MD4TEST=       md4test
+MD5TEST=       md5test
+HMACTEST=      hmactest
+WPTEST=                wp_test
+RC2TEST=       rc2test
+RC4TEST=       rc4test
+RC5TEST=       rc5test
+BFTEST=                bftest
+CASTTEST=      casttest
+DESTEST=       destest
+RANDTEST=      randtest
+DHTEST=                dhtest
+DSATEST=       dsatest
+METHTEST=      methtest
+SSLTEST=       ssltest
+RSATEST=       rsa_test
+ENGINETEST=    enginetest
+EVPTEST=       evp_test
+IGETEST=       igetest
+JPAKETEST=     jpaketest
+ASN1TEST=      asn1test
+
+TESTS=         alltests
+
+EXE=   $(BNTEST)$(EXE_EXT) $(ECTEST)$(EXE_EXT)  $(ECDSATEST)$(EXE_EXT) $(ECDHTEST)$(EXE_EXT) $(IDEATEST)$(EXE_EXT) \
+       $(MD2TEST)$(EXE_EXT)  $(MD4TEST)$(EXE_EXT) $(MD5TEST)$(EXE_EXT) $(HMACTEST)$(EXE_EXT) $(WPTEST)$(EXE_EXT) \
+       $(RC2TEST)$(EXE_EXT) $(RC4TEST)$(EXE_EXT) $(RC5TEST)$(EXE_EXT) \
+       $(DESTEST)$(EXE_EXT) $(SHATEST)$(EXE_EXT) $(SHA1TEST)$(EXE_EXT) $(SHA256TEST)$(EXE_EXT) $(SHA512TEST)$(EXE_EXT) \
+       $(MDC2TEST)$(EXE_EXT) $(RMDTEST)$(EXE_EXT) \
+       $(RANDTEST)$(EXE_EXT) $(DHTEST)$(EXE_EXT) $(ENGINETEST)$(EXE_EXT) \
+       $(BFTEST)$(EXE_EXT) $(CASTTEST)$(EXE_EXT) $(SSLTEST)$(EXE_EXT) $(EXPTEST)$(EXE_EXT) $(DSATEST)$(EXE_EXT) $(RSATEST)$(EXE_EXT) \
+       $(EVPTEST)$(EXE_EXT) $(IGETEST)$(EXE_EXT) $(JPAKETEST)$(EXE_EXT) \
+       $(ASN1TEST)$(EXE_EXT)
+
+# $(METHTEST)$(EXE_EXT)
+
+OBJ=   $(BNTEST).o $(ECTEST).o  $(ECDSATEST).o $(ECDHTEST).o $(IDEATEST).o \
+       $(MD2TEST).o $(MD4TEST).o $(MD5TEST).o \
+       $(HMACTEST).o $(WPTEST).o \
+       $(RC2TEST).o $(RC4TEST).o $(RC5TEST).o \
+       $(DESTEST).o $(SHATEST).o $(SHA1TEST).o $(SHA256TEST).o $(SHA512TEST).o \
+       $(MDC2TEST).o $(RMDTEST).o \
+       $(RANDTEST).o $(DHTEST).o $(ENGINETEST).o $(CASTTEST).o \
+       $(BFTEST).o  $(SSLTEST).o  $(DSATEST).o  $(EXPTEST).o $(RSATEST).o \
+       $(EVPTEST).o $(IGETEST).o $(JPAKETEST).o $(ASN1TEST).o
+SRC=   $(BNTEST).c $(ECTEST).c  $(ECDSATEST).c $(ECDHTEST).c $(IDEATEST).c \
+       $(MD2TEST).c  $(MD4TEST).c $(MD5TEST).c \
+       $(HMACTEST).c $(WPTEST).c \
+       $(RC2TEST).c $(RC4TEST).c $(RC5TEST).c \
+       $(DESTEST).c $(SHATEST).c $(SHA1TEST).c $(MDC2TEST).c $(RMDTEST).c \
+       $(RANDTEST).c $(DHTEST).c $(ENGINETEST).c $(CASTTEST).c \
+       $(BFTEST).c  $(SSLTEST).c $(DSATEST).c   $(EXPTEST).c $(RSATEST).c \
+       $(EVPTEST).c $(IGETEST).c $(JPAKETEST).c $(ASN1TEST).c
+
+EXHEADER= 
+HEADER=        $(EXHEADER)
+
+ALL=    $(GENERAL) $(SRC) $(HEADER)
+
+top:
+       (cd ..; $(MAKE) DIRS=$(DIR) TESTS=$(TESTS) all)
+
+all:   exe
+
+exe:   $(EXE) dummytest$(EXE_EXT)
+
+files:
+       $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
+
+links:
+
+generate: $(SRC)
+$(SRC):
+       @sh $(TOP)/util/point.sh dummytest.c $@
+
+errors:
+
+install:
+
+tags:
+       ctags $(SRC)
+
+tests: exe apps $(TESTS)
+
+apps:
+       @(cd ..; $(MAKE) DIRS=apps all)
+
+alltests: \
+       test_des test_idea test_sha test_md4 test_md5 test_hmac \
+       test_md2 test_mdc2 test_wp \
+       test_rmd test_rc2 test_rc4 test_rc5 test_bf test_cast test_aes \
+       test_rand test_bn test_ec test_ecdsa test_ecdh \
+       test_enc test_x509 test_rsa test_crl test_sid \
+       test_gen test_req test_pkcs7 test_verify test_dh test_dsa \
+       test_ss test_ca test_engine test_evp test_ssl test_tsa test_ige \
+       test_jpake test_cms
+
+test_evp:
+       ../util/shlib_wrap.sh ./$(EVPTEST) evptests.txt
+
+test_des:
+       ../util/shlib_wrap.sh ./$(DESTEST)
+
+test_idea:
+       ../util/shlib_wrap.sh ./$(IDEATEST)
+
+test_sha:
+       ../util/shlib_wrap.sh ./$(SHATEST)
+       ../util/shlib_wrap.sh ./$(SHA1TEST)
+       ../util/shlib_wrap.sh ./$(SHA256TEST)
+       ../util/shlib_wrap.sh ./$(SHA512TEST)
+
+test_mdc2:
+       ../util/shlib_wrap.sh ./$(MDC2TEST)
+
+test_md5:
+       ../util/shlib_wrap.sh ./$(MD5TEST)
+
+test_md4:
+       ../util/shlib_wrap.sh ./$(MD4TEST)
+
+test_hmac:
+       ../util/shlib_wrap.sh ./$(HMACTEST)
+
+test_wp:
+       ../util/shlib_wrap.sh ./$(WPTEST)
+
+test_md2:
+       ../util/shlib_wrap.sh ./$(MD2TEST)
+
+test_rmd:
+       ../util/shlib_wrap.sh ./$(RMDTEST)
+
+test_bf:
+       ../util/shlib_wrap.sh ./$(BFTEST)
+
+test_cast:
+       ../util/shlib_wrap.sh ./$(CASTTEST)
+
+test_rc2:
+       ../util/shlib_wrap.sh ./$(RC2TEST)
+
+test_rc4:
+       ../util/shlib_wrap.sh ./$(RC4TEST)
+
+test_rc5:
+       ../util/shlib_wrap.sh ./$(RC5TEST)
+
+test_rand:
+       ../util/shlib_wrap.sh ./$(RANDTEST)
+
+test_enc:
+       @sh ./testenc
+
+test_x509:
+       echo test normal x509v1 certificate
+       sh ./tx509 2>/dev/null
+       echo test first x509v3 certificate
+       sh ./tx509 v3-cert1.pem 2>/dev/null
+       echo test second x509v3 certificate
+       sh ./tx509 v3-cert2.pem 2>/dev/null
+
+test_rsa: $(RSATEST)$(EXE_EXT)
+       @sh ./trsa 2>/dev/null
+       ../util/shlib_wrap.sh ./$(RSATEST)
+
+test_crl:
+       @sh ./tcrl 2>/dev/null
+
+test_sid:
+       @sh ./tsid 2>/dev/null
+
+test_req:
+       @sh ./treq 2>/dev/null
+       @sh ./treq testreq2.pem 2>/dev/null
+
+test_pkcs7:
+       @sh ./tpkcs7 2>/dev/null
+       @sh ./tpkcs7d 2>/dev/null
+
+test_bn:
+       @echo starting big number library test, could take a while...
+       @../util/shlib_wrap.sh ./$(BNTEST) >tmp.bntest
+       @echo quit >>tmp.bntest
+       @echo "running bc"
+       @<tmp.bntest sh -c "`sh ./bctest ignore`" | $(PERL) -e '$$i=0; while (<STDIN>) {if (/^test (.*)/) {print STDERR "\nverify $$1";} elsif (!/^0$$/) {die "\nFailed! bc: $$_";} else {print STDERR "."; $$i++;}} print STDERR "\n$$i tests passed\n"'
+       @echo 'test a^b%c implementations'
+       ../util/shlib_wrap.sh ./$(EXPTEST)
+
+test_ec:
+       @echo 'test elliptic curves'
+       ../util/shlib_wrap.sh ./$(ECTEST)
+
+test_ecdsa:
+       @echo 'test ecdsa'
+       ../util/shlib_wrap.sh ./$(ECDSATEST)
+
+test_ecdh:
+       @echo 'test ecdh'
+       ../util/shlib_wrap.sh ./$(ECDHTEST)
+
+test_verify:
+       @echo "The following command should have some OK's and some failures"
+       @echo "There are definitly a few expired certificates"
+       ../util/shlib_wrap.sh ../apps/openssl verify -CApath ../certs ../certs/*.pem
+
+test_dh:
+       @echo "Generate a set of DH parameters"
+       ../util/shlib_wrap.sh ./$(DHTEST)
+
+test_dsa:
+       @echo "Generate a set of DSA parameters"
+       ../util/shlib_wrap.sh ./$(DSATEST)
+       ../util/shlib_wrap.sh ./$(DSATEST) -app2_1
+
+test_gen:
+       @echo "Generate and verify a certificate request"
+       @sh ./testgen
+
+test_ss keyU.ss certU.ss certCA.ss certP1.ss keyP1.ss certP2.ss keyP2.ss \
+               intP1.ss intP2.ss: testss
+       @echo "Generate and certify a test certificate"
+       @sh ./testss
+       @cat certCA.ss certU.ss > intP1.ss
+       @cat certCA.ss certU.ss certP1.ss > intP2.ss
+
+test_engine: 
+       @echo "Manipulate the ENGINE structures"
+       ../util/shlib_wrap.sh ./$(ENGINETEST)
+
+test_ssl: keyU.ss certU.ss certCA.ss certP1.ss keyP1.ss certP2.ss keyP2.ss \
+               intP1.ss intP2.ss
+       @echo "test SSL protocol"
+       ../util/shlib_wrap.sh ./$(SSLTEST) -test_cipherlist
+       @sh ./testssl keyU.ss certU.ss certCA.ss
+       @sh ./testsslproxy keyP1.ss certP1.ss intP1.ss
+       @sh ./testsslproxy keyP2.ss certP2.ss intP2.ss
+
+test_ca:
+       @if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then \
+         echo "skipping CA.sh test -- requires RSA"; \
+       else \
+         echo "Generate and certify a test certificate via the 'ca' program"; \
+         sh ./testca; \
+       fi
+
+test_aes: #$(AESTEST)
+#      @echo "test Rijndael"
+#      ../util/shlib_wrap.sh ./$(AESTEST)
+
+test_tsa:
+       @if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then \
+         echo "skipping testtsa test -- requires RSA"; \
+       else \
+         sh ./testtsa; \
+       fi
+
+test_ige: $(IGETEST)$(EXE_EXT)
+       @echo "Test IGE mode"
+       ../util/shlib_wrap.sh ./$(IGETEST)
+
+test_jpake: $(JPAKETEST)$(EXE_EXT)
+       @echo "Test JPAKE"
+       ../util/shlib_wrap.sh ./$(JPAKETEST)
+
+test_cms:
+       @echo "CMS consistency test"
+       $(PERL) cms-test.pl
+
+lint:
+       lint -DLINT $(INCLUDES) $(SRC)>fluff
+
+depend:
+       @if [ -z "$(THIS)" ]; then \
+           $(MAKE) -f $(TOP)/Makefile reflect THIS=$@; \
+       else \
+           $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(SRC); \
+       fi
+
+dclean:
+       $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
+       mv -f Makefile.new $(MAKEFILE)
+       rm -f $(SRC) $(SHA256TEST).c $(SHA512TEST).c evptests.txt newkey.pem testkey.pem \
+                       testreq.pem
+
+clean:
+       rm -f .rnd tmp.bntest tmp.bctest *.o *.obj *.dll lib tags core .pure .nfs* *.old *.bak fluff $(EXE) *.ss *.srl log dummytest
+
+$(DLIBSSL):
+       (cd ..; $(MAKE) DIRS=ssl all)
+
+$(DLIBCRYPTO):
+       (cd ..; $(MAKE) DIRS=crypto all)
+
+BUILD_CMD=shlib_target=; if [ -n "$(SHARED_LIBS)" ]; then \
+               shlib_target="$(SHLIB_TARGET)"; \
+       fi; \
+       LIBRARIES="$(LIBSSL) $(LIBCRYPTO) $(LIBKRB5)"; \
+       $(MAKE) -f $(TOP)/Makefile.shared -e \
+               APPNAME=$$target$(EXE_EXT) OBJECTS="$$target.o" \
+               LIBDEPS="$(PEX_LIBS) $$LIBRARIES $(EX_LIBS)" \
+               link_app.$${shlib_target}
+
+$(RSATEST)$(EXE_EXT): $(RSATEST).o $(DLIBCRYPTO)
+       @target=$(RSATEST); $(BUILD_CMD)
+
+$(BNTEST)$(EXE_EXT): $(BNTEST).o $(DLIBCRYPTO)
+       @target=$(BNTEST); $(BUILD_CMD)
+
+$(ECTEST)$(EXE_EXT): $(ECTEST).o $(DLIBCRYPTO)
+       @target=$(ECTEST); $(BUILD_CMD)
+
+$(EXPTEST)$(EXE_EXT): $(EXPTEST).o $(DLIBCRYPTO)
+       @target=$(EXPTEST); $(BUILD_CMD)
+
+$(IDEATEST)$(EXE_EXT): $(IDEATEST).o $(DLIBCRYPTO)
+       @target=$(IDEATEST); $(BUILD_CMD)
+
+$(MD2TEST)$(EXE_EXT): $(MD2TEST).o $(DLIBCRYPTO)
+       @target=$(MD2TEST); $(BUILD_CMD)
+
+$(SHATEST)$(EXE_EXT): $(SHATEST).o $(DLIBCRYPTO)
+       @target=$(SHATEST); $(BUILD_CMD)
+
+$(SHA1TEST)$(EXE_EXT): $(SHA1TEST).o $(DLIBCRYPTO)
+       @target=$(SHA1TEST); $(BUILD_CMD)
+
+$(SHA256TEST)$(EXE_EXT): $(SHA256TEST).o $(DLIBCRYPTO)
+       @target=$(SHA256TEST); $(BUILD_CMD)
+
+$(SHA512TEST)$(EXE_EXT): $(SHA512TEST).o $(DLIBCRYPTO)
+       @target=$(SHA512TEST); $(BUILD_CMD)
+
+$(RMDTEST)$(EXE_EXT): $(RMDTEST).o $(DLIBCRYPTO)
+       @target=$(RMDTEST); $(BUILD_CMD)
+
+$(MDC2TEST)$(EXE_EXT): $(MDC2TEST).o $(DLIBCRYPTO)
+       @target=$(MDC2TEST); $(BUILD_CMD)
+
+$(MD4TEST)$(EXE_EXT): $(MD4TEST).o $(DLIBCRYPTO)
+       @target=$(MD4TEST); $(BUILD_CMD)
+
+$(MD5TEST)$(EXE_EXT): $(MD5TEST).o $(DLIBCRYPTO)
+       @target=$(MD5TEST); $(BUILD_CMD)
+
+$(HMACTEST)$(EXE_EXT): $(HMACTEST).o $(DLIBCRYPTO)
+       @target=$(HMACTEST); $(BUILD_CMD)
+
+$(WPTEST)$(EXE_EXT): $(WPTEST).o $(DLIBCRYPTO)
+       @target=$(WPTEST); $(BUILD_CMD)
+
+$(RC2TEST)$(EXE_EXT): $(RC2TEST).o $(DLIBCRYPTO)
+       @target=$(RC2TEST); $(BUILD_CMD)
+
+$(BFTEST)$(EXE_EXT): $(BFTEST).o $(DLIBCRYPTO)
+       @target=$(BFTEST); $(BUILD_CMD)
+
+$(CASTTEST)$(EXE_EXT): $(CASTTEST).o $(DLIBCRYPTO)
+       @target=$(CASTTEST); $(BUILD_CMD)
+
+$(RC4TEST)$(EXE_EXT): $(RC4TEST).o $(DLIBCRYPTO)
+       @target=$(RC4TEST); $(BUILD_CMD)
+
+$(RC5TEST)$(EXE_EXT): $(RC5TEST).o $(DLIBCRYPTO)
+       @target=$(RC5TEST); $(BUILD_CMD)
+
+$(DESTEST)$(EXE_EXT): $(DESTEST).o $(DLIBCRYPTO)
+       @target=$(DESTEST); $(BUILD_CMD)
+
+$(RANDTEST)$(EXE_EXT): $(RANDTEST).o $(DLIBCRYPTO)
+       @target=$(RANDTEST); $(BUILD_CMD)
+
+$(DHTEST)$(EXE_EXT): $(DHTEST).o $(DLIBCRYPTO)
+       @target=$(DHTEST); $(BUILD_CMD)
+
+$(DSATEST)$(EXE_EXT): $(DSATEST).o $(DLIBCRYPTO)
+       @target=$(DSATEST); $(BUILD_CMD)
+
+$(METHTEST)$(EXE_EXT): $(METHTEST).o $(DLIBCRYPTO)
+       @target=$(METHTEST); $(BUILD_CMD)
+
+$(SSLTEST)$(EXE_EXT): $(SSLTEST).o $(DLIBSSL) $(DLIBCRYPTO)
+       @target=$(SSLTEST); $(BUILD_CMD)
+
+$(ENGINETEST)$(EXE_EXT): $(ENGINETEST).o $(DLIBCRYPTO)
+       @target=$(ENGINETEST); $(BUILD_CMD)
+
+$(EVPTEST)$(EXE_EXT): $(EVPTEST).o $(DLIBCRYPTO)
+       @target=$(EVPTEST); $(BUILD_CMD)
+
+$(ECDSATEST)$(EXE_EXT): $(ECDSATEST).o $(DLIBCRYPTO)
+       @target=$(ECDSATEST); $(BUILD_CMD)
+
+$(ECDHTEST)$(EXE_EXT): $(ECDHTEST).o $(DLIBCRYPTO)
+       @target=$(ECDHTEST); $(BUILD_CMD)
+
+$(IGETEST)$(EXE_EXT): $(IGETEST).o $(DLIBCRYPTO)
+       @target=$(IGETEST); $(BUILD_CMD)
+
+$(JPAKETEST)$(EXE_EXT): $(JPAKETEST).o $(DLIBCRYPTO)
+       @target=$(JPAKETEST); $(BUILD_CMD)
+
+$(ASN1TEST)$(EXE_EXT): $(ASN1TEST).o $(DLIBCRYPTO)
+       @target=$(ASN1TEST); $(BUILD_CMD)
+
+#$(AESTEST).o: $(AESTEST).c
+#      $(CC) -c $(CFLAGS) -DINTERMEDIATE_VALUE_KAT -DTRACE_KAT_MCT $(AESTEST).c
+
+#$(AESTEST)$(EXE_EXT): $(AESTEST).o $(DLIBCRYPTO)
+#      if [ "$(SHLIB_TARGET)" = "hpux-shared" -o "$(SHLIB_TARGET)" = "darwin-shared" ] ; then \
+#        $(CC) -o $(AESTEST)$(EXE_EXT) $(CFLAGS) $(AESTEST).o $(PEX_LIBS) $(DLIBCRYPTO) $(EX_LIBS) ; \
+#      else \
+#        $(CC) -o $(AESTEST)$(EXE_EXT) $(CFLAGS) $(AESTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) ; \
+#      fi
+
+dummytest$(EXE_EXT): dummytest.o $(DLIBCRYPTO)
+       @target=dummytest; $(BUILD_CMD)
+
+# DO NOT DELETE THIS LINE -- make depend depends on it.
+
+asn1test.o: ../include/openssl/asn1.h ../include/openssl/asn1_mac.h
+asn1test.o: ../include/openssl/bio.h ../include/openssl/buffer.h
+asn1test.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
+asn1test.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+asn1test.o: ../include/openssl/ecdsa.h ../include/openssl/evp.h
+asn1test.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+asn1test.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
+asn1test.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+asn1test.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
+asn1test.o: ../include/openssl/sha.h ../include/openssl/stack.h
+asn1test.o: ../include/openssl/symhacks.h ../include/openssl/x509.h
+asn1test.o: ../include/openssl/x509_vfy.h asn1test.c
+bftest.o: ../e_os.h ../include/openssl/blowfish.h ../include/openssl/e_os2.h
+bftest.o: ../include/openssl/opensslconf.h bftest.c
+bntest.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
+bntest.o: ../include/openssl/bn.h ../include/openssl/buffer.h
+bntest.o: ../include/openssl/crypto.h ../include/openssl/dh.h
+bntest.o: ../include/openssl/dsa.h ../include/openssl/e_os2.h
+bntest.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+bntest.o: ../include/openssl/ecdsa.h ../include/openssl/err.h
+bntest.o: ../include/openssl/evp.h ../include/openssl/lhash.h
+bntest.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+bntest.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+bntest.o: ../include/openssl/ossl_typ.h ../include/openssl/pkcs7.h
+bntest.o: ../include/openssl/rand.h ../include/openssl/rsa.h
+bntest.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+bntest.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+bntest.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h bntest.c
+casttest.o: ../e_os.h ../include/openssl/cast.h ../include/openssl/e_os2.h
+casttest.o: ../include/openssl/opensslconf.h casttest.c
+destest.o: ../include/openssl/des.h ../include/openssl/des_old.h
+destest.o: ../include/openssl/e_os2.h ../include/openssl/opensslconf.h
+destest.o: ../include/openssl/ossl_typ.h ../include/openssl/safestack.h
+destest.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+destest.o: ../include/openssl/ui.h ../include/openssl/ui_compat.h destest.c
+dhtest.o: ../e_os.h ../include/openssl/bio.h ../include/openssl/bn.h
+dhtest.o: ../include/openssl/crypto.h ../include/openssl/dh.h
+dhtest.o: ../include/openssl/e_os2.h ../include/openssl/err.h
+dhtest.o: ../include/openssl/lhash.h ../include/openssl/opensslconf.h
+dhtest.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+dhtest.o: ../include/openssl/rand.h ../include/openssl/safestack.h
+dhtest.o: ../include/openssl/stack.h ../include/openssl/symhacks.h dhtest.c
+dsatest.o: ../e_os.h ../include/openssl/bio.h ../include/openssl/bn.h
+dsatest.o: ../include/openssl/crypto.h ../include/openssl/dh.h
+dsatest.o: ../include/openssl/dsa.h ../include/openssl/e_os2.h
+dsatest.o: ../include/openssl/err.h ../include/openssl/lhash.h
+dsatest.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+dsatest.o: ../include/openssl/ossl_typ.h ../include/openssl/rand.h
+dsatest.o: ../include/openssl/safestack.h ../include/openssl/stack.h
+dsatest.o: ../include/openssl/symhacks.h dsatest.c
+ecdhtest.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
+ecdhtest.o: ../include/openssl/bn.h ../include/openssl/crypto.h
+ecdhtest.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
+ecdhtest.o: ../include/openssl/ecdh.h ../include/openssl/err.h
+ecdhtest.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+ecdhtest.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
+ecdhtest.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+ecdhtest.o: ../include/openssl/rand.h ../include/openssl/safestack.h
+ecdhtest.o: ../include/openssl/sha.h ../include/openssl/stack.h
+ecdhtest.o: ../include/openssl/symhacks.h ecdhtest.c
+ecdsatest.o: ../include/openssl/asn1.h ../include/openssl/bio.h
+ecdsatest.o: ../include/openssl/bn.h ../include/openssl/buffer.h
+ecdsatest.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
+ecdsatest.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+ecdsatest.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
+ecdsatest.o: ../include/openssl/err.h ../include/openssl/evp.h
+ecdsatest.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+ecdsatest.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
+ecdsatest.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+ecdsatest.o: ../include/openssl/pkcs7.h ../include/openssl/rand.h
+ecdsatest.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+ecdsatest.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+ecdsatest.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
+ecdsatest.o: ecdsatest.c
+ectest.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
+ectest.o: ../include/openssl/bn.h ../include/openssl/buffer.h
+ectest.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
+ectest.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+ectest.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
+ectest.o: ../include/openssl/err.h ../include/openssl/evp.h
+ectest.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+ectest.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
+ectest.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+ectest.o: ../include/openssl/pkcs7.h ../include/openssl/rand.h
+ectest.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+ectest.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+ectest.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h ectest.c
+enginetest.o: ../include/openssl/asn1.h ../include/openssl/bio.h
+enginetest.o: ../include/openssl/buffer.h ../include/openssl/crypto.h
+enginetest.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
+enginetest.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
+enginetest.o: ../include/openssl/engine.h ../include/openssl/err.h
+enginetest.o: ../include/openssl/evp.h ../include/openssl/lhash.h
+enginetest.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+enginetest.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+enginetest.o: ../include/openssl/ossl_typ.h ../include/openssl/pkcs7.h
+enginetest.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+enginetest.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+enginetest.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
+enginetest.o: enginetest.c
+evp_test.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
+evp_test.o: ../include/openssl/buffer.h ../include/openssl/conf.h
+evp_test.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
+evp_test.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+evp_test.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
+evp_test.o: ../include/openssl/err.h ../include/openssl/evp.h
+evp_test.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
+evp_test.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
+evp_test.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+evp_test.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
+evp_test.o: ../include/openssl/sha.h ../include/openssl/stack.h
+evp_test.o: ../include/openssl/symhacks.h ../include/openssl/x509.h
+evp_test.o: ../include/openssl/x509_vfy.h evp_test.c
+exptest.o: ../e_os.h ../include/openssl/bio.h ../include/openssl/bn.h
+exptest.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
+exptest.o: ../include/openssl/err.h ../include/openssl/lhash.h
+exptest.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+exptest.o: ../include/openssl/ossl_typ.h ../include/openssl/rand.h
+exptest.o: ../include/openssl/safestack.h ../include/openssl/stack.h
+exptest.o: ../include/openssl/symhacks.h exptest.c
+hmactest.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
+hmactest.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
+hmactest.o: ../include/openssl/evp.h ../include/openssl/hmac.h
+hmactest.o: ../include/openssl/md5.h ../include/openssl/obj_mac.h
+hmactest.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
+hmactest.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+hmactest.o: ../include/openssl/safestack.h ../include/openssl/stack.h
+hmactest.o: ../include/openssl/symhacks.h hmactest.c
+ideatest.o: ../e_os.h ../include/openssl/e_os2.h ../include/openssl/idea.h
+ideatest.o: ../include/openssl/opensslconf.h ideatest.c
+igetest.o: ../include/openssl/aes.h ../include/openssl/e_os2.h
+igetest.o: ../include/openssl/opensslconf.h ../include/openssl/ossl_typ.h
+igetest.o: ../include/openssl/rand.h igetest.c
+jpaketest.o: ../include/openssl/buffer.h ../include/openssl/crypto.h
+jpaketest.o: ../include/openssl/e_os2.h ../include/openssl/opensslconf.h
+jpaketest.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+jpaketest.o: ../include/openssl/safestack.h ../include/openssl/stack.h
+jpaketest.o: ../include/openssl/symhacks.h jpaketest.c
+md2test.o: ../include/openssl/buffer.h ../include/openssl/crypto.h
+md2test.o: ../include/openssl/e_os2.h ../include/openssl/opensslconf.h
+md2test.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+md2test.o: ../include/openssl/safestack.h ../include/openssl/stack.h
+md2test.o: ../include/openssl/symhacks.h md2test.c
+md4test.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
+md4test.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
+md4test.o: ../include/openssl/evp.h ../include/openssl/md4.h
+md4test.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+md4test.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+md4test.o: ../include/openssl/ossl_typ.h ../include/openssl/safestack.h
+md4test.o: ../include/openssl/stack.h ../include/openssl/symhacks.h md4test.c
+md5test.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
+md5test.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
+md5test.o: ../include/openssl/evp.h ../include/openssl/md5.h
+md5test.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+md5test.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+md5test.o: ../include/openssl/ossl_typ.h ../include/openssl/safestack.h
+md5test.o: ../include/openssl/stack.h ../include/openssl/symhacks.h md5test.c
+mdc2test.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
+mdc2test.o: ../include/openssl/crypto.h ../include/openssl/des.h
+mdc2test.o: ../include/openssl/des_old.h ../include/openssl/e_os2.h
+mdc2test.o: ../include/openssl/evp.h ../include/openssl/mdc2.h
+mdc2test.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+mdc2test.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+mdc2test.o: ../include/openssl/ossl_typ.h ../include/openssl/safestack.h
+mdc2test.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+mdc2test.o: ../include/openssl/ui.h ../include/openssl/ui_compat.h mdc2test.c
+randtest.o: ../e_os.h ../include/openssl/e_os2.h
+randtest.o: ../include/openssl/opensslconf.h ../include/openssl/ossl_typ.h
+randtest.o: ../include/openssl/rand.h randtest.c
+rc2test.o: ../e_os.h ../include/openssl/e_os2.h
+rc2test.o: ../include/openssl/opensslconf.h ../include/openssl/rc2.h rc2test.c
+rc4test.o: ../e_os.h ../include/openssl/e_os2.h
+rc4test.o: ../include/openssl/opensslconf.h ../include/openssl/rc4.h
+rc4test.o: ../include/openssl/sha.h rc4test.c
+rc5test.o: ../include/openssl/buffer.h ../include/openssl/crypto.h
+rc5test.o: ../include/openssl/e_os2.h ../include/openssl/opensslconf.h
+rc5test.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+rc5test.o: ../include/openssl/safestack.h ../include/openssl/stack.h
+rc5test.o: ../include/openssl/symhacks.h rc5test.c
+rmdtest.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
+rmdtest.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
+rmdtest.o: ../include/openssl/evp.h ../include/openssl/obj_mac.h
+rmdtest.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
+rmdtest.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+rmdtest.o: ../include/openssl/ripemd.h ../include/openssl/safestack.h
+rmdtest.o: ../include/openssl/stack.h ../include/openssl/symhacks.h rmdtest.c
+rsa_test.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
+rsa_test.o: ../include/openssl/bn.h ../include/openssl/crypto.h
+rsa_test.o: ../include/openssl/e_os2.h ../include/openssl/err.h
+rsa_test.o: ../include/openssl/lhash.h ../include/openssl/opensslconf.h
+rsa_test.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+rsa_test.o: ../include/openssl/rand.h ../include/openssl/rsa.h
+rsa_test.o: ../include/openssl/safestack.h ../include/openssl/stack.h
+rsa_test.o: ../include/openssl/symhacks.h rsa_test.c
+sha1test.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
+sha1test.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
+sha1test.o: ../include/openssl/evp.h ../include/openssl/obj_mac.h
+sha1test.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
+sha1test.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+sha1test.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+sha1test.o: ../include/openssl/stack.h ../include/openssl/symhacks.h sha1test.c
+shatest.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
+shatest.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
+shatest.o: ../include/openssl/evp.h ../include/openssl/obj_mac.h
+shatest.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
+shatest.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+shatest.o: ../include/openssl/safestack.h ../include/openssl/sha.h
+shatest.o: ../include/openssl/stack.h ../include/openssl/symhacks.h shatest.c
+ssltest.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
+ssltest.o: ../include/openssl/bn.h ../include/openssl/buffer.h
+ssltest.o: ../include/openssl/comp.h ../include/openssl/conf.h
+ssltest.o: ../include/openssl/crypto.h ../include/openssl/dh.h
+ssltest.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
+ssltest.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
+ssltest.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
+ssltest.o: ../include/openssl/engine.h ../include/openssl/err.h
+ssltest.o: ../include/openssl/evp.h ../include/openssl/hmac.h
+ssltest.o: ../include/openssl/kssl.h ../include/openssl/lhash.h
+ssltest.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+ssltest.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+ssltest.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+ssltest.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
+ssltest.o: ../include/openssl/pqueue.h ../include/openssl/rand.h
+ssltest.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+ssltest.o: ../include/openssl/sha.h ../include/openssl/ssl.h
+ssltest.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
+ssltest.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
+ssltest.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
+ssltest.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
+ssltest.o: ../include/openssl/x509v3.h ssltest.c
+wp_test.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
+wp_test.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+wp_test.o: ../include/openssl/ossl_typ.h ../include/openssl/safestack.h
+wp_test.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+wp_test.o: ../include/openssl/whrlpool.h wp_test.c
diff --git a/deps/openssl/openssl/test/P1ss.cnf b/deps/openssl/openssl/test/P1ss.cnf
new file mode 100644 (file)
index 0000000..876a0d3
--- /dev/null
@@ -0,0 +1,37 @@
+#
+# SSLeay example configuration file.
+# This is mostly being used for generation of certificate requests.
+#
+
+RANDFILE               = ./.rnd
+
+####################################################################
+[ req ]
+default_bits           = 512
+default_keyfile        = keySS.pem
+distinguished_name     = req_distinguished_name
+encrypt_rsa_key                = no
+default_md             = md2
+
+[ req_distinguished_name ]
+countryName                    = Country Name (2 letter code)
+countryName_default            = AU
+countryName_value              = AU
+
+organizationName                = Organization Name (eg, company)
+organizationName_value          = Dodgy Brothers
+
+0.commonName                   = Common Name (eg, YOUR name)
+0.commonName_value             = Brother 1
+
+1.commonName                   = Common Name (eg, YOUR name)
+1.commonName_value             = Brother 2
+
+2.commonName                   = Common Name (eg, YOUR name)
+2.commonName_value             = Proxy 1
+
+[ v3_proxy ]
+basicConstraints=CA:FALSE
+subjectKeyIdentifier=hash
+authorityKeyIdentifier=keyid,issuer:always
+proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:1,policy:text:AB
diff --git a/deps/openssl/openssl/test/P2ss.cnf b/deps/openssl/openssl/test/P2ss.cnf
new file mode 100644 (file)
index 0000000..373a87e
--- /dev/null
@@ -0,0 +1,45 @@
+#
+# SSLeay example configuration file.
+# This is mostly being used for generation of certificate requests.
+#
+
+RANDFILE               = ./.rnd
+
+####################################################################
+[ req ]
+default_bits           = 512
+default_keyfile        = keySS.pem
+distinguished_name     = req_distinguished_name
+encrypt_rsa_key                = no
+default_md             = md2
+
+[ req_distinguished_name ]
+countryName                    = Country Name (2 letter code)
+countryName_default            = AU
+countryName_value              = AU
+
+organizationName                = Organization Name (eg, company)
+organizationName_value          = Dodgy Brothers
+
+0.commonName                   = Common Name (eg, YOUR name)
+0.commonName_value             = Brother 1
+
+1.commonName                   = Common Name (eg, YOUR name)
+1.commonName_value             = Brother 2
+
+2.commonName                   = Common Name (eg, YOUR name)
+2.commonName_value             = Proxy 1
+
+3.commonName                   = Common Name (eg, YOUR name)
+3.commonName_value             = Proxy 2
+
+[ v3_proxy ]
+basicConstraints=CA:FALSE
+subjectKeyIdentifier=hash
+authorityKeyIdentifier=keyid,issuer:always
+proxyCertInfo=critical,@proxy_ext
+
+[ proxy_ext ]
+language=id-ppl-anyLanguage
+pathlen=0
+policy=text:BC
diff --git a/deps/openssl/openssl/test/Sssdsa.cnf b/deps/openssl/openssl/test/Sssdsa.cnf
new file mode 100644 (file)
index 0000000..8e170a2
--- /dev/null
@@ -0,0 +1,27 @@
+#
+# SSLeay example configuration file.
+# This is mostly being used for generation of certificate requests.
+#
+# hacked by iang to do DSA certs - Server
+
+RANDFILE              = ./.rnd
+
+####################################################################
+[ req ]
+distinguished_name    = req_distinguished_name
+encrypt_rsa_key               = no
+
+[ req_distinguished_name ]
+countryName                   = Country Name (2 letter code)
+countryName_default           = ES
+countryName_value             = ES
+
+organizationName                = Organization Name (eg, company)
+organizationName_value          = Tortilleras S.A.
+
+0.commonName                  = Common Name (eg, YOUR name)
+0.commonName_value            = Torti
+
+1.commonName                  = Common Name (eg, YOUR name)
+1.commonName_value            = Gordita
+
diff --git a/deps/openssl/openssl/test/Sssrsa.cnf b/deps/openssl/openssl/test/Sssrsa.cnf
new file mode 100644 (file)
index 0000000..8c79a03
--- /dev/null
@@ -0,0 +1,26 @@
+#
+# SSLeay example configuration file.
+# This is mostly being used for generation of certificate requests.
+#
+# create RSA certs - Server
+
+RANDFILE              = ./.rnd
+
+####################################################################
+[ req ]
+distinguished_name    = req_distinguished_name
+encrypt_key           = no
+
+[ req_distinguished_name ]
+countryName                   = Country Name (2 letter code)
+countryName_default           = ES
+countryName_value             = ES
+
+organizationName                = Organization Name (eg, company)
+organizationName_value          = Tortilleras S.A.
+
+0.commonName                  = Common Name (eg, YOUR name)
+0.commonName_value            = Torti
+
+1.commonName                  = Common Name (eg, YOUR name)
+1.commonName_value            = Gordita
diff --git a/deps/openssl/openssl/test/Uss.cnf b/deps/openssl/openssl/test/Uss.cnf
new file mode 100644 (file)
index 0000000..0c0ebb5
--- /dev/null
@@ -0,0 +1,36 @@
+#
+# SSLeay example configuration file.
+# This is mostly being used for generation of certificate requests.
+#
+
+RANDFILE               = ./.rnd
+
+####################################################################
+[ req ]
+default_bits           = 512
+default_keyfile        = keySS.pem
+distinguished_name     = req_distinguished_name
+encrypt_rsa_key                = no
+default_md             = md2
+
+[ req_distinguished_name ]
+countryName                    = Country Name (2 letter code)
+countryName_default            = AU
+countryName_value              = AU
+
+organizationName                = Organization Name (eg, company)
+organizationName_value          = Dodgy Brothers
+
+0.commonName                   = Common Name (eg, YOUR name)
+0.commonName_value             = Brother 1
+
+1.commonName                   = Common Name (eg, YOUR name)
+1.commonName_value             = Brother 2
+
+[ v3_ee ]
+subjectKeyIdentifier=hash
+authorityKeyIdentifier=keyid,issuer:always
+basicConstraints = CA:false
+keyUsage = nonRepudiation, digitalSignature, keyEncipherment
+issuerAltName=issuer:copy
+
diff --git a/deps/openssl/openssl/test/VMSca-response.1 b/deps/openssl/openssl/test/VMSca-response.1
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
diff --git a/deps/openssl/openssl/test/VMSca-response.2 b/deps/openssl/openssl/test/VMSca-response.2
new file mode 100644 (file)
index 0000000..9b48ee4
--- /dev/null
@@ -0,0 +1,2 @@
+y
+y
diff --git a/deps/openssl/openssl/test/asn1test.c b/deps/openssl/openssl/test/asn1test.c
new file mode 100644 (file)
index 0000000..9f53d80
--- /dev/null
@@ -0,0 +1,22 @@
+#include <openssl/x509.h>
+#include <openssl/asn1_mac.h>
+
+typedef struct X
+    {
+    STACK_OF(X509_EXTENSION) *ext;
+    } X;
+
+/* This isn't meant to run particularly, it's just to test type checking */
+int main(int argc, char **argv)
+    {
+    X *x = NULL;
+    unsigned char **pp = NULL;
+
+    M_ASN1_I2D_vars(x);
+    M_ASN1_I2D_len_SEQUENCE_opt_type(X509_EXTENSION, x->ext,
+                                    i2d_X509_EXTENSION);
+    M_ASN1_I2D_seq_total();
+    M_ASN1_I2D_put_SEQUENCE_opt_type(X509_EXTENSION, x->ext,
+                                    i2d_X509_EXTENSION);
+    M_ASN1_I2D_finish();
+    }
diff --git a/deps/openssl/openssl/test/bctest b/deps/openssl/openssl/test/bctest
new file mode 100755 (executable)
index 0000000..bdb3218
--- /dev/null
@@ -0,0 +1,111 @@
+#!/bin/sh
+
+# This script is used by test/Makefile.ssl to check whether a sane 'bc'
+# is installed.
+# ('make test_bn' should not try to run 'bc' if it does not exist or if
+# it is a broken 'bc' version that is known to cause trouble.)
+#
+# If 'bc' works, we also test if it knows the 'print' command.
+#
+# In any case, output an appropriate command line for running (or not
+# running) bc.
+
+
+IFS=:
+try_without_dir=true
+# First we try "bc", then "$dir/bc" for each item in $PATH.
+for dir in dummy:$PATH; do
+    if [ "$try_without_dir" = true ]; then
+      # first iteration
+      bc=bc
+      try_without_dir=false
+    else
+      # second and later iterations
+      bc="$dir/bc"
+      if [ ! -f "$bc" ]; then  # '-x' is not available on Ultrix
+        bc=''
+      fi
+    fi
+
+    if [ ! "$bc" = '' ]; then
+        failure=none
+
+
+        # Test for SunOS 5.[78] bc bug
+        "$bc" >tmp.bctest <<\EOF
+obase=16
+ibase=16
+a=AD88C418F31B3FC712D0425001D522B3AE9134FF3A98C13C1FCC1682211195406C1A6C66C6A\
+CEEC1A0EC16950233F77F1C2F2363D56DD71A36C57E0B2511FC4BA8F22D261FE2E9356D99AF57\
+10F3817C0E05BF79C423C3F66FDF321BE8D3F18F625D91B670931C1EF25F28E489BDA1C5422D1\
+C3F6F7A1AD21585746ECC4F10A14A778AF56F08898E965E9909E965E0CB6F85B514150C644759\
+3BE731877B16EA07B552088FF2EA728AC5E0FF3A23EB939304519AB8B60F2C33D6BA0945B66F0\
+4FC3CADF855448B24A9D7640BCF473E
+b=DCE91E7D120B983EA9A104B5A96D634DD644C37657B1C7860B45E6838999B3DCE5A555583C6\
+9209E41F413422954175A06E67FFEF6746DD652F0F48AEFECC3D8CAC13523BDAAD3F5AF4212BD\
+8B3CD64126E1A82E190228020C05B91C8B141F1110086FC2A4C6ED631EBA129D04BB9A19FC53D\
+3ED0E2017D60A68775B75481449
+(a/b)*b + (a%b) - a
+EOF
+        if [ 0 != "`cat tmp.bctest`" ]; then
+            failure=SunOStest
+        fi
+
+
+        if [ "$failure" = none ]; then
+            # Test for SCO bc bug.
+            "$bc" >tmp.bctest <<\EOF
+obase=16
+ibase=16
+-FFDD63BA1A4648F0D804F8A1C66C53F0D2110590E8A3907EC73B4AEC6F15AC177F176F2274D2\
+9DC8022EA0D7DD3ABE9746D2D46DD3EA5B5F6F69DF12877E0AC5E7F5ADFACEE54573F5D256A06\
+11B5D2BC24947724E22AE4EC3FB0C39D9B4694A01AFE5E43B4D99FB9812A0E4A5773D8B254117\
+1239157EC6E3D8D50199 * -FFDD63BA1A4648F0D804F8A1C66C53F0D2110590E8A3907EC73B4\
+AEC6F15AC177F176F2274D29DC8022EA0D7DD3ABE9746D2D46DD3EA5B5F6F69DF12877E0AC5E7\
+F5ADFACEE54573F5D256A0611B5D2BC24947724E22AE4EC3FB0C39D9B4694A01AFE5E43B4D99F\
+B9812A0E4A5773D8B2541171239157EC6E3D8D50199 - FFBACC221682DA464B6D7F123482522\
+02EDAEDCA38C3B69E9B7BBCD6165A9CD8716C4903417F23C09A85B851961F92C217258CEEB866\
+85EFCC5DD131853A02C07A873B8E2AF2E40C6D5ED598CD0E8F35AD49F3C3A17FDB7653E4E2DC4\
+A8D23CC34686EE4AD01F7407A7CD74429AC6D36DBF0CB6A3E302D0E5BDFCD048A3B90C1BE5AA8\
+E16C3D5884F9136B43FF7BB443764153D4AEC176C681B078F4CC53D6EB6AB76285537DDEE7C18\
+8C72441B52EDBDDBC77E02D34E513F2AABF92F44109CAFE8242BD0ECBAC5604A94B02EA44D43C\
+04E9476E6FBC48043916BFA1485C6093603600273C9C33F13114D78064AE42F3DC466C7DA543D\
+89C8D71
+AD534AFBED2FA39EE9F40E20FCF9E2C861024DB98DDCBA1CD118C49CA55EEBC20D6BA51B2271C\
+928B693D6A73F67FEB1B4571448588B46194617D25D910C6A9A130CC963155CF34079CB218A44\
+8A1F57E276D92A33386DDCA3D241DB78C8974ABD71DD05B0FA555709C9910D745185E6FE108E3\
+37F1907D0C56F8BFBF52B9704 % -E557905B56B13441574CAFCE2BD257A750B1A8B2C88D0E36\
+E18EF7C38DAC80D3948E17ED63AFF3B3467866E3B89D09A81B3D16B52F6A3C7134D3C6F5123E9\
+F617E3145BBFBE9AFD0D6E437EA4FF6F04BC67C4F1458B4F0F47B64 - 1C2BBBB19B74E86FD32\
+9E8DB6A8C3B1B9986D57ED5419C2E855F7D5469E35E76334BB42F4C43E3F3A31B9697C171DAC4\
+D97935A7E1A14AD209D6CF811F55C6DB83AA9E6DFECFCD6669DED7171EE22A40C6181615CAF3F\
+5296964
+EOF
+            if [ "0
+0" != "`cat tmp.bctest`" ]; then
+                failure=SCOtest
+            fi
+        fi
+
+
+        if [ "$failure" = none ]; then
+            # bc works; now check if it knows the 'print' command.
+            if [ "OK" = "`echo 'print \"OK\"' | $bc 2>/dev/null`" ]
+            then
+                echo "$bc"
+            else
+                echo "sed 's/print.*//' | $bc"
+            fi
+            exit 0
+        fi
+
+        echo "$bc does not work properly ('$failure' failed).  Looking for another bc ..." >&2
+    fi
+done
+
+echo "No working bc found.  Consider installing GNU bc." >&2
+if [ "$1" = ignore ]; then
+  echo "cat >/dev/null"
+  exit 0
+fi
+exit 1
diff --git a/deps/openssl/openssl/test/bctest.com b/deps/openssl/openssl/test/bctest.com
new file mode 100644 (file)
index 0000000..d7e5ec1
--- /dev/null
@@ -0,0 +1,152 @@
+$!
+$! Check operation of "bc".
+$!
+$! 2010-04-05 SMS.  New.  Based (loosely) on "bctest".
+$!
+$!
+$ tmp_file_name = "tmp.bctest"
+$ failure = ""
+$!
+$! Basic command test.
+$!
+$ on warning then goto bc_fail
+$ bc
+$ on error then exit
+$!
+$! Test for SunOS 5.[78] bc bug.
+$!
+$ if (failure .eqs. "")
+$ then
+$!
+$     define /user_mode sys$output 'tmp_file_name'
+$     bc
+obase=16
+ibase=16
+a=AD88C418F31B3FC712D0425001D522B3AE9134FF3A98C13C1FCC1682211195406C1A6C66C6A\
+CEEC1A0EC16950233F77F1C2F2363D56DD71A36C57E0B2511FC4BA8F22D261FE2E9356D99AF57\
+10F3817C0E05BF79C423C3F66FDF321BE8D3F18F625D91B670931C1EF25F28E489BDA1C5422D1\
+C3F6F7A1AD21585746ECC4F10A14A778AF56F08898E965E9909E965E0CB6F85B514150C644759\
+3BE731877B16EA07B552088FF2EA728AC5E0FF3A23EB939304519AB8B60F2C33D6BA0945B66F0\
+4FC3CADF855448B24A9D7640BCF473E
+b=DCE91E7D120B983EA9A104B5A96D634DD644C37657B1C7860B45E6838999B3DCE5A555583C6\
+9209E41F413422954175A06E67FFEF6746DD652F0F48AEFECC3D8CAC13523BDAAD3F5AF4212BD\
+8B3CD64126E1A82E190228020C05B91C8B141F1110086FC2A4C6ED631EBA129D04BB9A19FC53D\
+3ED0E2017D60A68775B75481449
+(a/b)*b + (a%b) - a
+$     status = $status
+$     output_expected = "0"
+$     gosub check_output
+$     if (output .ne. 1)
+$     then
+$         failure = "SunOStest"
+$     else
+$         delete 'f$parse( tmp_file_name)'
+$     endif
+$ endif
+$!
+$! Test for SCO bc bug.
+$!
+$ if (failure .eqs. "")
+$ then
+$!
+$     define /user_mode sys$output 'tmp_file_name'
+$     bc
+obase=16
+ibase=16
+-FFDD63BA1A4648F0D804F8A1C66C53F0D2110590E8A3907EC73B4AEC6F15AC177F176F2274D2\
+9DC8022EA0D7DD3ABE9746D2D46DD3EA5B5F6F69DF12877E0AC5E7F5ADFACEE54573F5D256A06\
+11B5D2BC24947724E22AE4EC3FB0C39D9B4694A01AFE5E43B4D99FB9812A0E4A5773D8B254117\
+1239157EC6E3D8D50199 * -FFDD63BA1A4648F0D804F8A1C66C53F0D2110590E8A3907EC73B4\
+AEC6F15AC177F176F2274D29DC8022EA0D7DD3ABE9746D2D46DD3EA5B5F6F69DF12877E0AC5E7\
+F5ADFACEE54573F5D256A0611B5D2BC24947724E22AE4EC3FB0C39D9B4694A01AFE5E43B4D99F\
+B9812A0E4A5773D8B2541171239157EC6E3D8D50199 - FFBACC221682DA464B6D7F123482522\
+02EDAEDCA38C3B69E9B7BBCD6165A9CD8716C4903417F23C09A85B851961F92C217258CEEB866\
+85EFCC5DD131853A02C07A873B8E2AF2E40C6D5ED598CD0E8F35AD49F3C3A17FDB7653E4E2DC4\
+A8D23CC34686EE4AD01F7407A7CD74429AC6D36DBF0CB6A3E302D0E5BDFCD048A3B90C1BE5AA8\
+E16C3D5884F9136B43FF7BB443764153D4AEC176C681B078F4CC53D6EB6AB76285537DDEE7C18\
+8C72441B52EDBDDBC77E02D34E513F2AABF92F44109CAFE8242BD0ECBAC5604A94B02EA44D43C\
+04E9476E6FBC48043916BFA1485C6093603600273C9C33F13114D78064AE42F3DC466C7DA543D\
+89C8D71
+AD534AFBED2FA39EE9F40E20FCF9E2C861024DB98DDCBA1CD118C49CA55EEBC20D6BA51B2271C\
+928B693D6A73F67FEB1B4571448588B46194617D25D910C6A9A130CC963155CF34079CB218A44\
+8A1F57E276D92A33386DDCA3D241DB78C8974ABD71DD05B0FA555709C9910D745185E6FE108E3\
+37F1907D0C56F8BFBF52B9704 % -E557905B56B13441574CAFCE2BD257A750B1A8B2C88D0E36\
+E18EF7C38DAC80D3948E17ED63AFF3B3467866E3B89D09A81B3D16B52F6A3C7134D3C6F5123E9\
+F617E3145BBFBE9AFD0D6E437EA4FF6F04BC67C4F1458B4F0F47B64 - 1C2BBBB19B74E86FD32\
+9E8DB6A8C3B1B9986D57ED5419C2E855F7D5469E35E76334BB42F4C43E3F3A31B9697C171DAC4\
+D97935A7E1A14AD209D6CF811F55C6DB83AA9E6DFECFCD6669DED7171EE22A40C6181615CAF3F\
+5296964
+$     status = $status
+$     output_expected = "0\0"
+$     gosub check_output
+$     if (output .ne. 1)
+$     then
+$         failure = "SCOtest"
+$     else
+$         delete 'f$parse( tmp_file_name)'
+$     endif
+$ endif
+$!
+$! Test for working 'print' command.
+$!
+$ if (failure .eqs. "")
+$ then
+$!
+$     define /user_mode sys$output 'tmp_file_name'
+$     bc
+print "OK"
+$     status = $status
+$     output_expected = "OK"
+$     gosub check_output
+$     if (output .ne. 1)
+$     then
+$         failure = "printtest"
+$     else
+$         delete 'f$parse( tmp_file_name)'
+$     endif
+$ endif
+$!
+$ if (failure .nes. "")
+$ then
+$     write sys$output -
+       "No working bc found.  Consider installing GNU bc."
+$     exit %X00030000 ! %DCL-W-NORMAL
+$ endif
+$!
+$ exit
+$!
+$!
+$! Complete "bc" command failure.
+$!
+$ bc_fail:
+$ write sys$output -
+   "No ""bc"" program/symbol found.  Consider installing GNU bc."
+$ exit %X00030000 ! %DCL-W-NORMAL
+$!
+$!
+$! Output check subroutine.
+$!
+$ check_output:
+$     eof = 0
+$     line_nr = 0
+$     open /read tmp_file 'tmp_file_name'
+$     c_o_loop:
+$         read /error = error_read tmp_file line
+$         goto ok_read
+$         error_read:
+$         eof = 1
+$         ok_read:
+$         line_expected = f$element( line_nr, "\", output_expected)
+$         line_nr = line_nr+ 1
+$     if ((line_expected .nes. "\") .and. (.not. eof) .and. -
+       (line_expected .eqs. line)) then goto c_o_loop
+$!
+$     if ((line_expected .eqs. "\") .and. eof)
+$     then
+$         output = 1
+$     else
+$         output = 0
+$     endif
+$     close tmp_file
+$ return
+$!
diff --git a/deps/openssl/openssl/test/bftest.c b/deps/openssl/openssl/test/bftest.c
new file mode 120000 (symlink)
index 0000000..78b1749
--- /dev/null
@@ -0,0 +1 @@
+../crypto/bf/bftest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/bntest.c b/deps/openssl/openssl/test/bntest.c
new file mode 120000 (symlink)
index 0000000..03f54a2
--- /dev/null
@@ -0,0 +1 @@
+../crypto/bn/bntest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/bntest.com b/deps/openssl/openssl/test/bntest.com
new file mode 100644 (file)
index 0000000..6545d2e
--- /dev/null
@@ -0,0 +1,76 @@
+$!
+$! Analyze bntest output file.
+$!
+$! Exit status = 1 (success) if all tests passed,
+$!               0 (warning) if any test failed.
+$!
+$! 2011-02-20 SMS.  Added code to skip "#" comments in the input file.
+$!
+$! 2010-04-05 SMS.  New.  Based (loosely) on perl code in bntest-vms.sh.
+$!
+$!                  Expect data like:
+$!                        test test_name1
+$!                        0
+$!                        [...]
+$!                        test test_name2
+$!                        0
+$!                        [...]
+$!                        [...]
+$!
+$!                  Some tests have no following "0" lines.
+$!
+$ result_file_name = f$edit( p1, "TRIM")
+$ if (result_file_name .eqs. "")
+$ then
+$     result_file_name = "bntest-vms.out"
+$ endif
+$!
+$ fail = 0
+$ passed = 0
+$ tests = 0
+$!
+$ on control_c then goto tidy
+$ on error then goto tidy
+$!
+$ open /read result_file 'result_file_name'
+$!
+$ read_loop:
+$     read /end = read_loop_end /error = tidy result_file line
+$     t1 = f$element( 0, " ", line)
+$!
+$!    Skip "#" comment lines.
+$     if (f$extract( 0, 1, f$edit( line, "TRIM")) .eqs. "#") then -
+       goto read_loop
+$!
+$     if (t1 .eqs. "test")
+$     then
+$         passed = passed+ 1
+$         tests = tests+ 1
+$         fail = 1
+$         t2 = f$extract( 5, 1000, line)
+$         write sys$output "verify ''t2'"
+$     else
+$         if (t1 .nes. "0")
+$         then
+$             write sys$output "Failed! bc: ''line'"
+$             passed = passed- fail
+$             fail = 0
+$         endif
+$     endif
+$ goto read_loop
+$ read_loop_end:
+$ write sys$output "''passed'/''tests' tests passed"
+$!
+$ tidy:
+$ if f$trnlnm( "result_file", "LNM$PROCESS_TABLE", , "SUPERVISOR", , "CONFINE")
+$ then
+$     close result_file
+$ endif
+$!
+$ if ((tests .gt. 0) .and. (tests .eq. passed))
+$ then
+$    exit 1
+$ else
+$    exit 0
+$ endif
+$!
diff --git a/deps/openssl/openssl/test/casttest.c b/deps/openssl/openssl/test/casttest.c
new file mode 120000 (symlink)
index 0000000..ac7ede8
--- /dev/null
@@ -0,0 +1 @@
+../crypto/cast/casttest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/clean_test.com b/deps/openssl/openssl/test/clean_test.com
new file mode 100644 (file)
index 0000000..7df633f
--- /dev/null
@@ -0,0 +1,35 @@
+$!
+$! Delete various test results files.
+$!
+$ def_orig = f$environment( "default")
+$ proc = f$environment( "procedure")
+$ proc_dev_dir = f$parse( "A.;", proc) - "A.;"
+$!
+$ on control_c then goto tidy
+$ on error then goto tidy
+$!
+$ set default 'proc_dev_dir'
+$!
+$ files := *.cms;*, *.srl;*, *.ss;*, -
+   cms.err;*, cms.out;*, newreq.pem;*, -
+   p.txt-zlib-cipher;*, -
+   smtst.txt;*, testkey.pem;*, testreq.pem;*, -
+   test_*.err;*, test_*.out;*, -
+   .rnd;*
+$!
+$ delim = ","
+$ i = 0
+$ loop:
+$    file = f$edit( f$element( i, delim, files), "trim")
+$    if (file .eqs. delim) then goto loop_end
+$    if (f$search( file) .nes. "") then -
+      delete 'p1' 'file'
+$    i = i+ 1
+$ goto loop
+$ loop_end:
+$!
+$ tidy:
+$ 
+$ if (f$type( def_orig) .nes. "") then -
+   set default 'def_orig'
+$!
diff --git a/deps/openssl/openssl/test/cms-examples.pl b/deps/openssl/openssl/test/cms-examples.pl
new file mode 100644 (file)
index 0000000..2e95b48
--- /dev/null
@@ -0,0 +1,409 @@
+# test/cms-examples.pl
+# Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+# project.
+#
+# ====================================================================
+# Copyright (c) 2008 The OpenSSL 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 OpenSSL Project
+#    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+#
+# 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+#    endorse or promote products derived from this software without
+#    prior written permission. For written permission, please contact
+#    licensing@OpenSSL.org.
+#
+# 5. Products derived from this software may not be called "OpenSSL"
+#    nor may "OpenSSL" appear in their names without prior written
+#    permission of the OpenSSL Project.
+#
+# 6. Redistributions of any form whatsoever must retain the following
+#    acknowledgment:
+#    "This product includes software developed by the OpenSSL Project
+#    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+#
+# THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+# ====================================================================
+
+# Perl script to run tests against S/MIME examples in RFC4134
+# Assumes RFC is in current directory and called "rfc4134.txt"
+
+use MIME::Base64;
+
+my $badttest = 0;
+my $verbose  = 1;
+
+my $cmscmd;
+my $exdir  = "./";
+my $exfile = "./rfc4134.txt";
+
+if (-f "../apps/openssl")
+       {
+       $cmscmd = "../util/shlib_wrap.sh ../apps/openssl cms";
+       }
+elsif (-f "..\\out32dll\\openssl.exe")
+       {
+       $cmscmd = "..\\out32dll\\openssl.exe cms";
+       }
+elsif (-f "..\\out32\\openssl.exe")
+       {
+       $cmscmd = "..\\out32\\openssl.exe cms";
+       }
+
+my @test_list = (
+    [ "3.1.bin"  => "dataout" ],
+    [ "3.2.bin"  => "encode, dataout" ],
+    [ "4.1.bin"  => "encode, verifyder, cont, dss" ],
+    [ "4.2.bin"  => "encode, verifyder, cont, rsa" ],
+    [ "4.3.bin"  => "encode, verifyder, cont_extern, dss" ],
+    [ "4.4.bin"  => "encode, verifyder, cont, dss" ],
+    [ "4.5.bin"  => "verifyder, cont, rsa" ],
+    [ "4.6.bin"  => "encode, verifyder, cont, dss" ],
+    [ "4.7.bin"  => "encode, verifyder, cont, dss" ],
+    [ "4.8.eml"  => "verifymime, dss" ],
+    [ "4.9.eml"  => "verifymime, dss" ],
+    [ "4.10.bin" => "encode, verifyder, cont, dss" ],
+    [ "4.11.bin" => "encode, certsout" ],
+    [ "5.1.bin"  => "encode, envelopeder, cont" ],
+    [ "5.2.bin"  => "encode, envelopeder, cont" ],
+    [ "5.3.eml"  => "envelopemime, cont" ],
+    [ "6.0.bin"  => "encode, digest, cont" ],
+    [ "7.1.bin"  => "encode, encrypted, cont" ],
+    [ "7.2.bin"  => "encode, encrypted, cont" ]
+);
+
+# Extract examples from RFC4134 text.
+# Base64 decode all examples, certificates and
+# private keys are converted to PEM format.
+
+my ( $filename, $data );
+
+my @cleanup = ( "cms.out", "cms.err", "tmp.der", "tmp.txt" );
+
+$data = "";
+
+open( IN, $exfile ) || die "Can't Open RFC examples file $exfile";
+
+while (<IN>) {
+    next unless (/^\|/);
+    s/^\|//;
+    next if (/^\*/);
+    if (/^>(.*)$/) {
+        $filename = $1;
+        next;
+    }
+    if (/^</) {
+        $filename = "$exdir/$filename";
+        if ( $filename =~ /\.bin$/ || $filename =~ /\.eml$/ ) {
+            $data = decode_base64($data);
+            open OUT, ">$filename";
+            binmode OUT;
+            print OUT $data;
+            close OUT;
+            push @cleanup, $filename;
+        }
+        elsif ( $filename =~ /\.cer$/ ) {
+            write_pem( $filename, "CERTIFICATE", $data );
+        }
+        elsif ( $filename =~ /\.pri$/ ) {
+            write_pem( $filename, "PRIVATE KEY", $data );
+        }
+        $data     = "";
+        $filename = "";
+    }
+    else {
+        $data .= $_;
+    }
+
+}
+
+my $secretkey =
+  "73:7c:79:1f:25:ea:d0:e0:46:29:25:43:52:f7:dc:62:91:e5:cb:26:91:7a:da:32";
+
+foreach (@test_list) {
+    my ( $file, $tlist ) = @$_;
+    print "Example file $file:\n";
+    if ( $tlist =~ /encode/ ) {
+        run_reencode_test( $exdir, $file );
+    }
+    if ( $tlist =~ /certsout/ ) {
+        run_certsout_test( $exdir, $file );
+    }
+    if ( $tlist =~ /dataout/ ) {
+        run_dataout_test( $exdir, $file );
+    }
+    if ( $tlist =~ /verify/ ) {
+        run_verify_test( $exdir, $tlist, $file );
+    }
+    if ( $tlist =~ /digest/ ) {
+        run_digest_test( $exdir, $tlist, $file );
+    }
+    if ( $tlist =~ /encrypted/ ) {
+        run_encrypted_test( $exdir, $tlist, $file, $secretkey );
+    }
+    if ( $tlist =~ /envelope/ ) {
+        run_envelope_test( $exdir, $tlist, $file );
+    }
+
+}
+
+foreach (@cleanup) {
+    unlink $_;
+}
+
+if ($badtest) {
+    print "\n$badtest TESTS FAILED!!\n";
+}
+else {
+    print "\n***All tests successful***\n";
+}
+
+sub write_pem {
+    my ( $filename, $str, $data ) = @_;
+
+    $filename =~ s/\.[^.]*$/.pem/;
+
+    push @cleanup, $filename;
+
+    open OUT, ">$filename";
+
+    print OUT "-----BEGIN $str-----\n";
+    print OUT $data;
+    print OUT "-----END $str-----\n";
+
+    close OUT;
+}
+
+sub run_reencode_test {
+    my ( $cmsdir, $tfile ) = @_;
+    unlink "tmp.der";
+
+    system( "$cmscmd -cmsout -inform DER -outform DER"
+          . " -in $cmsdir/$tfile -out tmp.der" );
+
+    if ($?) {
+        print "\tReencode command FAILED!!\n";
+        $badtest++;
+    }
+    elsif ( !cmp_files( "$cmsdir/$tfile", "tmp.der" ) ) {
+        print "\tReencode FAILED!!\n";
+        $badtest++;
+    }
+    else {
+        print "\tReencode passed\n" if $verbose;
+    }
+}
+
+sub run_certsout_test {
+    my ( $cmsdir, $tfile ) = @_;
+    unlink "tmp.der";
+    unlink "tmp.pem";
+
+    system( "$cmscmd -cmsout -inform DER -certsout tmp.pem"
+          . " -in $cmsdir/$tfile -out tmp.der" );
+
+    if ($?) {
+        print "\tCertificate output command FAILED!!\n";
+        $badtest++;
+    }
+    else {
+        print "\tCertificate output passed\n" if $verbose;
+    }
+}
+
+sub run_dataout_test {
+    my ( $cmsdir, $tfile ) = @_;
+    unlink "tmp.txt";
+
+    system(
+        "$cmscmd -data_out -inform DER" . " -in $cmsdir/$tfile -out tmp.txt" );
+
+    if ($?) {
+        print "\tDataout command FAILED!!\n";
+        $badtest++;
+    }
+    elsif ( !cmp_files( "$cmsdir/ExContent.bin", "tmp.txt" ) ) {
+        print "\tDataout compare FAILED!!\n";
+        $badtest++;
+    }
+    else {
+        print "\tDataout passed\n" if $verbose;
+    }
+}
+
+sub run_verify_test {
+    my ( $cmsdir, $tlist, $tfile ) = @_;
+    unlink "tmp.txt";
+
+    $form   = "DER"                     if $tlist =~ /verifyder/;
+    $form   = "SMIME"                   if $tlist =~ /verifymime/;
+    $cafile = "$cmsdir/CarlDSSSelf.pem" if $tlist =~ /dss/;
+    $cafile = "$cmsdir/CarlRSASelf.pem" if $tlist =~ /rsa/;
+
+    $cmd =
+        "$cmscmd -verify -inform $form"
+      . " -CAfile $cafile"
+      . " -in $cmsdir/$tfile -out tmp.txt";
+
+    $cmd .= " -content $cmsdir/ExContent.bin" if $tlist =~ /cont_extern/;
+
+    system("$cmd 2>cms.err 1>cms.out");
+
+    if ($?) {
+        print "\tVerify command FAILED!!\n";
+        $badtest++;
+    }
+    elsif ( $tlist =~ /cont/
+        && !cmp_files( "$cmsdir/ExContent.bin", "tmp.txt" ) )
+    {
+        print "\tVerify content compare FAILED!!\n";
+        $badtest++;
+    }
+    else {
+        print "\tVerify passed\n" if $verbose;
+    }
+}
+
+sub run_envelope_test {
+    my ( $cmsdir, $tlist, $tfile ) = @_;
+    unlink "tmp.txt";
+
+    $form = "DER"   if $tlist =~ /envelopeder/;
+    $form = "SMIME" if $tlist =~ /envelopemime/;
+
+    $cmd =
+        "$cmscmd -decrypt -inform $form"
+      . " -recip $cmsdir/BobRSASignByCarl.pem"
+      . " -inkey $cmsdir/BobPrivRSAEncrypt.pem"
+      . " -in $cmsdir/$tfile -out tmp.txt";
+
+    system("$cmd 2>cms.err 1>cms.out");
+
+    if ($?) {
+        print "\tDecrypt command FAILED!!\n";
+        $badtest++;
+    }
+    elsif ( $tlist =~ /cont/
+        && !cmp_files( "$cmsdir/ExContent.bin", "tmp.txt" ) )
+    {
+        print "\tDecrypt content compare FAILED!!\n";
+        $badtest++;
+    }
+    else {
+        print "\tDecrypt passed\n" if $verbose;
+    }
+}
+
+sub run_digest_test {
+    my ( $cmsdir, $tlist, $tfile ) = @_;
+    unlink "tmp.txt";
+
+    my $cmd =
+      "$cmscmd -digest_verify -inform DER" . " -in $cmsdir/$tfile -out tmp.txt";
+
+    system("$cmd 2>cms.err 1>cms.out");
+
+    if ($?) {
+        print "\tDigest verify command FAILED!!\n";
+        $badtest++;
+    }
+    elsif ( $tlist =~ /cont/
+        && !cmp_files( "$cmsdir/ExContent.bin", "tmp.txt" ) )
+    {
+        print "\tDigest verify content compare FAILED!!\n";
+        $badtest++;
+    }
+    else {
+        print "\tDigest verify passed\n" if $verbose;
+    }
+}
+
+sub run_encrypted_test {
+    my ( $cmsdir, $tlist, $tfile, $key ) = @_;
+    unlink "tmp.txt";
+
+    system( "$cmscmd -EncryptedData_decrypt -inform DER"
+          . " -secretkey $key"
+          . " -in $cmsdir/$tfile -out tmp.txt" );
+
+    if ($?) {
+        print "\tEncrypted Data command FAILED!!\n";
+        $badtest++;
+    }
+    elsif ( $tlist =~ /cont/
+        && !cmp_files( "$cmsdir/ExContent.bin", "tmp.txt" ) )
+    {
+        print "\tEncrypted Data content compare FAILED!!\n";
+        $badtest++;
+    }
+    else {
+        print "\tEncryptedData verify passed\n" if $verbose;
+    }
+}
+
+sub cmp_files {
+    my ( $f1, $f2 ) = @_;
+    my ( $fp1, $fp2 );
+
+    my ( $rd1, $rd2 );
+
+    if ( !open( $fp1, "<$f1" ) ) {
+        print STDERR "Can't Open file $f1\n";
+        return 0;
+    }
+
+    if ( !open( $fp2, "<$f2" ) ) {
+        print STDERR "Can't Open file $f2\n";
+        return 0;
+    }
+
+    binmode $fp1;
+    binmode $fp2;
+
+    my $ret = 0;
+
+    for ( ; ; ) {
+        $n1 = sysread $fp1, $rd1, 4096;
+        $n2 = sysread $fp2, $rd2, 4096;
+        last if ( $n1 != $n2 );
+        last if ( $rd1 ne $rd2 );
+
+        if ( $n1 == 0 ) {
+            $ret = 1;
+            last;
+        }
+
+    }
+
+    close $fp1;
+    close $fp2;
+
+    return $ret;
+
+}
+
diff --git a/deps/openssl/openssl/test/cms-test.pl b/deps/openssl/openssl/test/cms-test.pl
new file mode 100644 (file)
index 0000000..c938bcf
--- /dev/null
@@ -0,0 +1,457 @@
+# test/cms-test.pl
+# Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+# project.
+#
+# ====================================================================
+# Copyright (c) 2008 The OpenSSL 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 OpenSSL Project
+#    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+#
+# 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+#    endorse or promote products derived from this software without
+#    prior written permission. For written permission, please contact
+#    licensing@OpenSSL.org.
+#
+# 5. Products derived from this software may not be called "OpenSSL"
+#    nor may "OpenSSL" appear in their names without prior written
+#    permission of the OpenSSL Project.
+#
+# 6. Redistributions of any form whatsoever must retain the following
+#    acknowledgment:
+#    "This product includes software developed by the OpenSSL Project
+#    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+#
+# THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+# ====================================================================
+
+# CMS, PKCS7 consistency test script. Run extensive tests on
+# OpenSSL PKCS#7 and CMS implementations.
+
+my $ossl_path;
+my $redir = " 2> cms.err > cms.out";
+# Make VMS work
+if ( $^O eq "VMS" && -f "OSSLX:openssl.exe" ) {
+    $ossl_path = "pipe mcr OSSLX:openssl";
+}
+# Make MSYS work
+elsif ( $^O eq "MSWin32" && -f "../apps/openssl.exe" ) {
+    $ossl_path = "cmd /c ..\\apps\\openssl";
+}
+elsif ( -f "../apps/openssl$ENV{EXE_EXT}" ) {
+    $ossl_path = "../util/shlib_wrap.sh ../apps/openssl";
+}
+elsif ( -f "..\\out32dll\\openssl.exe" ) {
+    $ossl_path = "..\\out32dll\\openssl.exe";
+}
+elsif ( -f "..\\out32\\openssl.exe" ) {
+    $ossl_path = "..\\out32\\openssl.exe";
+}
+else {
+    die "Can't find OpenSSL executable";
+}
+
+my $pk7cmd   = "$ossl_path smime ";
+my $cmscmd   = "$ossl_path cms ";
+my $smdir    = "smime-certs";
+my $halt_err = 1;
+
+my $badcmd = 0;
+my $ossl8 = `$ossl_path version -v` =~ /0\.9\.8/;
+
+my @smime_pkcs7_tests = (
+
+    [
+        "signed content DER format, RSA key",
+        "-sign -in smcont.txt -outform \"DER\" -nodetach"
+          . " -certfile $smdir/smroot.pem"
+          . " -signer $smdir/smrsa1.pem -out test.cms",
+        "-verify -in test.cms -inform \"DER\" "
+          . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
+    ],
+
+    [
+        "signed detached content DER format, RSA key",
+        "-sign -in smcont.txt -outform \"DER\""
+          . " -signer $smdir/smrsa1.pem -out test.cms",
+        "-verify -in test.cms -inform \"DER\" "
+          . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt -content smcont.txt"
+    ],
+
+    [
+        "signed content test streaming BER format, RSA",
+        "-sign -in smcont.txt -outform \"DER\" -nodetach"
+          . " -stream -signer $smdir/smrsa1.pem -out test.cms",
+        "-verify -in test.cms -inform \"DER\" "
+          . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
+    ],
+
+    [
+        "signed content DER format, DSA key",
+        "-sign -in smcont.txt -outform \"DER\" -nodetach"
+          . " -signer $smdir/smdsa1.pem -out test.cms",
+        "-verify -in test.cms -inform \"DER\" "
+          . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
+    ],
+
+    [
+        "signed detached content DER format, DSA key",
+        "-sign -in smcont.txt -outform \"DER\""
+          . " -signer $smdir/smdsa1.pem -out test.cms",
+        "-verify -in test.cms -inform \"DER\" "
+          . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt -content smcont.txt"
+    ],
+
+    [
+        "signed detached content DER format, add RSA signer",
+        "-resign -inform \"DER\" -in test.cms -outform \"DER\""
+          . " -signer $smdir/smrsa1.pem -out test2.cms",
+        "-verify -in test2.cms -inform \"DER\" "
+          . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt -content smcont.txt"
+    ],
+
+    [
+        "signed content test streaming BER format, DSA key",
+        "-sign -in smcont.txt -outform \"DER\" -nodetach"
+          . " -stream -signer $smdir/smdsa1.pem -out test.cms",
+        "-verify -in test.cms -inform \"DER\" "
+          . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
+    ],
+
+    [
+        "signed content test streaming BER format, 2 DSA and 2 RSA keys",
+        "-sign -in smcont.txt -outform \"DER\" -nodetach"
+          . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
+          . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
+          . " -stream -out test.cms",
+        "-verify -in test.cms -inform \"DER\" "
+          . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
+    ],
+
+    [
+"signed content test streaming BER format, 2 DSA and 2 RSA keys, no attributes",
+        "-sign -in smcont.txt -outform \"DER\" -noattr -nodetach"
+          . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
+          . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
+          . " -stream -out test.cms",
+        "-verify -in test.cms -inform \"DER\" "
+          . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
+    ],
+
+    [
+        "signed content test streaming S/MIME format, 2 DSA and 2 RSA keys",
+        "-sign -in smcont.txt -nodetach"
+          . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
+          . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
+          . " -stream -out test.cms",
+        "-verify -in test.cms " . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
+    ],
+
+    [
+"signed content test streaming multipart S/MIME format, 2 DSA and 2 RSA keys",
+        "-sign -in smcont.txt"
+          . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
+          . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
+          . " -stream -out test.cms",
+        "-verify -in test.cms " . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
+    ],
+
+    [
+        "enveloped content test streaming S/MIME format, 3 recipients",
+        "-encrypt -in smcont.txt"
+          . " -stream -out test.cms"
+          . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
+        "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
+    ],
+
+    [
+"enveloped content test streaming S/MIME format, 3 recipients, 3rd used",
+        "-encrypt -in smcont.txt"
+          . " -stream -out test.cms"
+          . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
+        "-decrypt -recip $smdir/smrsa3.pem -in test.cms -out smtst.txt"
+    ],
+
+    [
+"enveloped content test streaming S/MIME format, 3 recipients, key only used",
+        "-encrypt -in smcont.txt"
+          . " -stream -out test.cms"
+          . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
+        "-decrypt -inkey $smdir/smrsa3.pem -in test.cms -out smtst.txt"
+    ],
+
+    [
+"enveloped content test streaming S/MIME format, AES-256 cipher, 3 recipients",
+        "-encrypt -in smcont.txt"
+          . " -aes256 -stream -out test.cms"
+          . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
+        "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
+    ],
+
+);
+
+my @smime_cms_tests = (
+
+    [
+        "signed content test streaming BER format, 2 DSA and 2 RSA keys, keyid",
+        "-sign -in smcont.txt -outform \"DER\" -nodetach -keyid"
+          . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
+          . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
+          . " -stream -out test.cms",
+        "-verify -in test.cms -inform \"DER\" "
+          . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
+    ],
+
+    [
+        "signed content test streaming PEM format, 2 DSA and 2 RSA keys",
+        "-sign -in smcont.txt -outform PEM -nodetach"
+          . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
+          . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
+          . " -stream -out test.cms",
+        "-verify -in test.cms -inform PEM "
+          . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
+    ],
+
+    [
+        "signed content MIME format, RSA key, signed receipt request",
+        "-sign -in smcont.txt -signer $smdir/smrsa1.pem -nodetach"
+          . " -receipt_request_to test\@openssl.org -receipt_request_all"
+          . " -out test.cms",
+        "-verify -in test.cms "
+          . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
+    ],
+
+    [
+        "signed receipt MIME format, RSA key",
+        "-sign_receipt -in test.cms"
+          . " -signer $smdir/smrsa2.pem"
+          . " -out test2.cms",
+        "-verify_receipt test2.cms -in test.cms"
+          . " \"-CAfile\" $smdir/smroot.pem"
+    ],
+
+    [
+        "enveloped content test streaming S/MIME format, 3 recipients, keyid",
+        "-encrypt -in smcont.txt"
+          . " -stream -out test.cms -keyid"
+          . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
+        "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
+    ],
+
+    [
+        "enveloped content test streaming PEM format, KEK",
+        "-encrypt -in smcont.txt -outform PEM -aes128"
+          . " -stream -out test.cms "
+          . " -secretkey 000102030405060708090A0B0C0D0E0F "
+          . " -secretkeyid C0FEE0",
+        "-decrypt -in test.cms -out smtst.txt -inform PEM"
+          . " -secretkey 000102030405060708090A0B0C0D0E0F "
+          . " -secretkeyid C0FEE0"
+    ],
+
+    [
+        "enveloped content test streaming PEM format, KEK, key only",
+        "-encrypt -in smcont.txt -outform PEM -aes128"
+          . " -stream -out test.cms "
+          . " -secretkey 000102030405060708090A0B0C0D0E0F "
+          . " -secretkeyid C0FEE0",
+        "-decrypt -in test.cms -out smtst.txt -inform PEM"
+          . " -secretkey 000102030405060708090A0B0C0D0E0F "
+    ],
+
+    [
+        "data content test streaming PEM format",
+        "-data_create -in smcont.txt -outform PEM -nodetach"
+          . " -stream -out test.cms",
+        "-data_out -in test.cms -inform PEM -out smtst.txt"
+    ],
+
+    [
+        "encrypted content test streaming PEM format, 128 bit RC2 key",
+        "\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
+          . " -rc2 -secretkey 000102030405060708090A0B0C0D0E0F"
+          . " -stream -out test.cms",
+        "\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
+          . " -secretkey 000102030405060708090A0B0C0D0E0F -out smtst.txt"
+    ],
+
+    [
+        "encrypted content test streaming PEM format, 40 bit RC2 key",
+        "\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
+          . " -rc2 -secretkey 0001020304"
+          . " -stream -out test.cms",
+        "\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
+          . " -secretkey 0001020304 -out smtst.txt"
+    ],
+
+    [
+        "encrypted content test streaming PEM format, triple DES key",
+        "\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
+          . " -des3 -secretkey 000102030405060708090A0B0C0D0E0F1011121314151617"
+          . " -stream -out test.cms",
+        "\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
+          . " -secretkey 000102030405060708090A0B0C0D0E0F1011121314151617"
+          . " -out smtst.txt"
+    ],
+
+    [
+        "encrypted content test streaming PEM format, 128 bit AES key",
+        "\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
+          . " -aes128 -secretkey 000102030405060708090A0B0C0D0E0F"
+          . " -stream -out test.cms",
+        "\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
+          . " -secretkey 000102030405060708090A0B0C0D0E0F -out smtst.txt"
+    ],
+
+);
+
+my @smime_cms_comp_tests = (
+
+    [
+        "compressed content test streaming PEM format",
+        "-compress -in smcont.txt -outform PEM -nodetach"
+          . " -stream -out test.cms",
+        "-uncompress -in test.cms -inform PEM -out smtst.txt"
+    ]
+
+);
+
+print "CMS => PKCS#7 compatibility tests\n";
+
+run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $cmscmd, $pk7cmd );
+
+print "CMS <= PKCS#7 compatibility tests\n";
+
+run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $pk7cmd, $cmscmd );
+
+print "CMS <=> CMS consistency tests\n";
+
+run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $cmscmd, $cmscmd );
+run_smime_tests( \$badcmd, \@smime_cms_tests,   $cmscmd, $cmscmd );
+
+if ( `$ossl_path version -f` =~ /ZLIB/ ) {
+    run_smime_tests( \$badcmd, \@smime_cms_comp_tests, $cmscmd, $cmscmd );
+}
+else {
+    print "Zlib not supported: compression tests skipped\n";
+}
+
+print "Running modified tests for OpenSSL 0.9.8 cms backport\n" if($ossl8);
+
+if ($badcmd) {
+    print "$badcmd TESTS FAILED!!\n";
+}
+else {
+    print "ALL TESTS SUCCESSFUL.\n";
+}
+
+unlink "test.cms";
+unlink "test2.cms";
+unlink "smtst.txt";
+unlink "cms.out";
+unlink "cms.err";
+
+sub run_smime_tests {
+    my ( $rv, $aref, $scmd, $vcmd ) = @_;
+
+    foreach $smtst (@$aref) {
+        my ( $tnam, $rscmd, $rvcmd ) = @$smtst;
+       if ($ossl8)
+               {
+               # Skip smime resign: 0.9.8 smime doesn't support -resign        
+               next if ($scmd =~ /smime/ && $rscmd =~ /-resign/);
+               # Disable streaming: option not supported in 0.9.8
+               $tnam =~ s/streaming//; 
+               $rscmd =~ s/-stream//;  
+               $rvcmd =~ s/-stream//;
+               }
+        system("$scmd$rscmd$redir");
+        if ($?) {
+            print "$tnam: generation error\n";
+            $$rv++;
+            exit 1 if $halt_err;
+            next;
+        }
+        system("$vcmd$rvcmd$redir");
+        if ($?) {
+            print "$tnam: verify error\n";
+            $$rv++;
+            exit 1 if $halt_err;
+            next;
+        }
+       if (!cmp_files("smtst.txt", "smcont.txt")) {
+            print "$tnam: content verify error\n";
+            $$rv++;
+            exit 1 if $halt_err;
+            next;
+       }
+        print "$tnam: OK\n";
+    }
+}
+
+sub cmp_files {
+    my ( $f1, $f2 ) = @_;
+    my ( $fp1, $fp2 );
+
+    my ( $rd1, $rd2 );
+
+    if ( !open( $fp1, "<$f1" ) ) {
+        print STDERR "Can't Open file $f1\n";
+        return 0;
+    }
+
+    if ( !open( $fp2, "<$f2" ) ) {
+        print STDERR "Can't Open file $f2\n";
+        return 0;
+    }
+
+    binmode $fp1;
+    binmode $fp2;
+
+    my $ret = 0;
+
+    for ( ; ; ) {
+        $n1 = sysread $fp1, $rd1, 4096;
+        $n2 = sysread $fp2, $rd2, 4096;
+        last if ( $n1 != $n2 );
+        last if ( $rd1 ne $rd2 );
+
+        if ( $n1 == 0 ) {
+            $ret = 1;
+            last;
+        }
+
+    }
+
+    close $fp1;
+    close $fp2;
+
+    return $ret;
+
+}
+
diff --git a/deps/openssl/openssl/test/destest.c b/deps/openssl/openssl/test/destest.c
new file mode 120000 (symlink)
index 0000000..5988c73
--- /dev/null
@@ -0,0 +1 @@
+../crypto/des/destest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/dhtest.c b/deps/openssl/openssl/test/dhtest.c
new file mode 120000 (symlink)
index 0000000..9a67f91
--- /dev/null
@@ -0,0 +1 @@
+../crypto/dh/dhtest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/dsatest.c b/deps/openssl/openssl/test/dsatest.c
new file mode 120000 (symlink)
index 0000000..16a1b5a
--- /dev/null
@@ -0,0 +1 @@
+../crypto/dsa/dsatest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/dummytest.c b/deps/openssl/openssl/test/dummytest.c
new file mode 100644 (file)
index 0000000..5b4467e
--- /dev/null
@@ -0,0 +1,48 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <openssl/e_os2.h>
+#include <openssl/buffer.h>
+#include <openssl/crypto.h>
+
+int main(int argc, char *argv[])
+       {
+       char *p, *q = 0, *program;
+
+       p = strrchr(argv[0], '/');
+       if (!p) p = strrchr(argv[0], '\\');
+#ifdef OPENSSL_SYS_VMS
+       if (!p) p = strrchr(argv[0], ']');
+       if (p) q = strrchr(p, '>');
+       if (q) p = q;
+       if (!p) p = strrchr(argv[0], ':');
+       q = 0;
+#endif
+       if (p) p++;
+       if (!p) p = argv[0];
+       if (p) q = strchr(p, '.');
+       if (p && !q) q = p + strlen(p);
+
+       if (!p)
+               program = BUF_strdup("(unknown)");
+       else
+               {
+               program = OPENSSL_malloc((q - p) + 1);
+               strncpy(program, p, q - p);
+               program[q - p] = '\0';
+               }
+
+       for(p = program; *p; p++)
+               if (islower((unsigned char)(*p)))
+                       *p = toupper((unsigned char)(*p));
+
+       q = strstr(program, "TEST");
+       if (q > p && q[-1] == '_') q--;
+       *q = '\0';
+
+       printf("No %s support\n", program);
+
+       OPENSSL_free(program);
+       return(0);
+       }
diff --git a/deps/openssl/openssl/test/ecdhtest.c b/deps/openssl/openssl/test/ecdhtest.c
new file mode 120000 (symlink)
index 0000000..206d986
--- /dev/null
@@ -0,0 +1 @@
+../crypto/ecdh/ecdhtest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/ecdsatest.c b/deps/openssl/openssl/test/ecdsatest.c
new file mode 120000 (symlink)
index 0000000..441082b
--- /dev/null
@@ -0,0 +1 @@
+../crypto/ecdsa/ecdsatest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/ectest.c b/deps/openssl/openssl/test/ectest.c
new file mode 120000 (symlink)
index 0000000..df1831f
--- /dev/null
@@ -0,0 +1 @@
+../crypto/ec/ectest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/enginetest.c b/deps/openssl/openssl/test/enginetest.c
new file mode 120000 (symlink)
index 0000000..5c74a6f
--- /dev/null
@@ -0,0 +1 @@
+../crypto/engine/enginetest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/evp_test.c b/deps/openssl/openssl/test/evp_test.c
new file mode 120000 (symlink)
index 0000000..0741628
--- /dev/null
@@ -0,0 +1 @@
+../crypto/evp/evp_test.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/evptests.txt b/deps/openssl/openssl/test/evptests.txt
new file mode 100644 (file)
index 0000000..beb1214
--- /dev/null
@@ -0,0 +1,321 @@
+#cipher:key:iv:plaintext:ciphertext:0/1(decrypt/encrypt)
+#digest:::input:output
+
+# SHA(1) tests (from shatest.c)
+SHA1:::616263:a9993e364706816aba3e25717850c26c9cd0d89d
+
+# MD5 tests (from md5test.c)
+MD5::::d41d8cd98f00b204e9800998ecf8427e
+MD5:::61:0cc175b9c0f1b6a831c399e269772661
+MD5:::616263:900150983cd24fb0d6963f7d28e17f72
+MD5:::6d65737361676520646967657374:f96b697d7cb7938d525a2f31aaf161d0
+MD5:::6162636465666768696a6b6c6d6e6f707172737475767778797a:c3fcd3d76192e4007dfb496cca67e13b
+MD5:::4142434445464748494a4b4c4d4e4f505152535455565758595a6162636465666768696a6b6c6d6e6f707172737475767778797a30313233343536373839:d174ab98d277d9f5a5611c2c9f419d9f
+MD5:::3132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930:57edf4a22be3c955ac49da2e2107b67a
+
+# AES 128 ECB tests (from FIPS-197 test vectors, encrypt)
+
+AES-128-ECB:000102030405060708090A0B0C0D0E0F::00112233445566778899AABBCCDDEEFF:69C4E0D86A7B0430D8CDB78070B4C55A:1
+
+# AES 192 ECB tests (from FIPS-197 test vectors, encrypt)
+
+AES-192-ECB:000102030405060708090A0B0C0D0E0F1011121314151617::00112233445566778899AABBCCDDEEFF:DDA97CA4864CDFE06EAF70A0EC0D7191:1
+
+# AES 256 ECB tests (from FIPS-197 test vectors, encrypt)
+
+AES-256-ECB:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F::00112233445566778899AABBCCDDEEFF:8EA2B7CA516745BFEAFC49904B496089:1
+
+# AES 128 ECB tests (from NIST test vectors, encrypt)
+
+#AES-128-ECB:00000000000000000000000000000000::00000000000000000000000000000000:C34C052CC0DA8D73451AFE5F03BE297F:1
+
+# AES 128 ECB tests (from NIST test vectors, decrypt)
+
+#AES-128-ECB:00000000000000000000000000000000::44416AC2D1F53C583303917E6BE9EBE0:00000000000000000000000000000000:0
+
+# AES 192 ECB tests (from NIST test vectors, decrypt)
+
+#AES-192-ECB:000000000000000000000000000000000000000000000000::48E31E9E256718F29229319C19F15BA4:00000000000000000000000000000000:0
+
+# AES 256 ECB tests (from NIST test vectors, decrypt)
+
+#AES-256-ECB:0000000000000000000000000000000000000000000000000000000000000000::058CCFFDBBCB382D1F6F56585D8A4ADE:00000000000000000000000000000000:0
+
+# AES 128 CBC tests (from NIST test vectors, encrypt)
+
+#AES-128-CBC:00000000000000000000000000000000:00000000000000000000000000000000:00000000000000000000000000000000:8A05FC5E095AF4848A08D328D3688E3D:1
+
+# AES 192 CBC tests (from NIST test vectors, encrypt)
+
+#AES-192-CBC:000000000000000000000000000000000000000000000000:00000000000000000000000000000000:00000000000000000000000000000000:7BD966D53AD8C1BB85D2ADFAE87BB104:1
+
+# AES 256 CBC tests (from NIST test vectors, encrypt)
+
+#AES-256-CBC:0000000000000000000000000000000000000000000000000000000000000000:00000000000000000000000000000000:00000000000000000000000000000000:FE3C53653E2F45B56FCD88B2CC898FF0:1
+
+# AES 128 CBC tests (from NIST test vectors, decrypt)
+
+#AES-128-CBC:00000000000000000000000000000000:00000000000000000000000000000000:FACA37E0B0C85373DF706E73F7C9AF86:00000000000000000000000000000000:0
+
+# AES tests from NIST document SP800-38A
+# For all ECB encrypts and decrypts, the transformed sequence is
+#   AES-bits-ECB:key::plaintext:ciphertext:encdec
+# ECB-AES128.Encrypt and ECB-AES128.Decrypt
+AES-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::6BC1BEE22E409F96E93D7E117393172A:3AD77BB40D7A3660A89ECAF32466EF97
+AES-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::AE2D8A571E03AC9C9EB76FAC45AF8E51:F5D3D58503B9699DE785895A96FDBAAF
+AES-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::30C81C46A35CE411E5FBC1191A0A52EF:43B1CD7F598ECE23881B00E3ED030688
+AES-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::F69F2445DF4F9B17AD2B417BE66C3710:7B0C785E27E8AD3F8223207104725DD4
+# ECB-AES192.Encrypt and ECB-AES192.Decrypt 
+AES-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::6BC1BEE22E409F96E93D7E117393172A:BD334F1D6E45F25FF712A214571FA5CC
+AES-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::AE2D8A571E03AC9C9EB76FAC45AF8E51:974104846D0AD3AD7734ECB3ECEE4EEF
+AES-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::30C81C46A35CE411E5FBC1191A0A52EF:EF7AFD2270E2E60ADCE0BA2FACE6444E
+AES-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::F69F2445DF4F9B17AD2B417BE66C3710:9A4B41BA738D6C72FB16691603C18E0E
+# ECB-AES256.Encrypt and ECB-AES256.Decrypt 
+AES-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::6BC1BEE22E409F96E93D7E117393172A:F3EED1BDB5D2A03C064B5A7E3DB181F8
+AES-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::AE2D8A571E03AC9C9EB76FAC45AF8E51:591CCB10D410ED26DC5BA74A31362870
+AES-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::30C81C46A35CE411E5FBC1191A0A52EF:B6ED21B99CA6F4F9F153E7B1BEAFED1D
+AES-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::F69F2445DF4F9B17AD2B417BE66C3710:23304B7A39F9F3FF067D8D8F9E24ECC7
+# For all CBC encrypts and decrypts, the transformed sequence is
+#   AES-bits-CBC:key:IV/ciphertext':plaintext:ciphertext:encdec
+# CBC-AES128.Encrypt and CBC-AES128.Decrypt 
+AES-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:7649ABAC8119B246CEE98E9B12E9197D
+AES-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:7649ABAC8119B246CEE98E9B12E9197D:AE2D8A571E03AC9C9EB76FAC45AF8E51:5086CB9B507219EE95DB113A917678B2
+AES-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:5086CB9B507219EE95DB113A917678B2:30C81C46A35CE411E5FBC1191A0A52EF:73BED6B8E3C1743B7116E69E22229516
+AES-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:73BED6B8E3C1743B7116E69E22229516:F69F2445DF4F9B17AD2B417BE66C3710:3FF1CAA1681FAC09120ECA307586E1A7
+# CBC-AES192.Encrypt and CBC-AES192.Decrypt 
+AES-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:4F021DB243BC633D7178183A9FA071E8
+AES-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:4F021DB243BC633D7178183A9FA071E8:AE2D8A571E03AC9C9EB76FAC45AF8E51:B4D9ADA9AD7DEDF4E5E738763F69145A
+AES-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:B4D9ADA9AD7DEDF4E5E738763F69145A:30C81C46A35CE411E5FBC1191A0A52EF:571B242012FB7AE07FA9BAAC3DF102E0
+AES-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:571B242012FB7AE07FA9BAAC3DF102E0:F69F2445DF4F9B17AD2B417BE66C3710:08B0E27988598881D920A9E64F5615CD
+# CBC-AES256.Encrypt and CBC-AES256.Decrypt 
+AES-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:F58C4C04D6E5F1BA779EABFB5F7BFBD6
+AES-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:F58C4C04D6E5F1BA779EABFB5F7BFBD6:AE2D8A571E03AC9C9EB76FAC45AF8E51:9CFC4E967EDB808D679F777BC6702C7D
+AES-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:9CFC4E967EDB808D679F777BC6702C7D:30C81C46A35CE411E5FBC1191A0A52EF:39F23369A9D9BACFA530E26304231461
+AES-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:39F23369A9D9BACFA530E26304231461:F69F2445DF4F9B17AD2B417BE66C3710:B2EB05E2C39BE9FCDA6C19078C6A9D1B
+# We don't support CFB{1,8}-AESxxx.{En,De}crypt
+# For all CFB128 encrypts and decrypts, the transformed sequence is
+#   AES-bits-CFB:key:IV/ciphertext':plaintext:ciphertext:encdec
+# CFB128-AES128.Encrypt 
+AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:3B3FD92EB72DAD20333449F8E83CFB4A:1
+AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:3B3FD92EB72DAD20333449F8E83CFB4A:AE2D8A571E03AC9C9EB76FAC45AF8E51:C8A64537A0B3A93FCDE3CDAD9F1CE58B:1
+AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:C8A64537A0B3A93FCDE3CDAD9F1CE58B:30C81C46A35CE411E5FBC1191A0A52EF:26751F67A3CBB140B1808CF187A4F4DF:1
+AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:26751F67A3CBB140B1808CF187A4F4DF:F69F2445DF4F9B17AD2B417BE66C3710:C04B05357C5D1C0EEAC4C66F9FF7F2E6:1
+# CFB128-AES128.Decrypt 
+AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:3B3FD92EB72DAD20333449F8E83CFB4A:0
+AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:3B3FD92EB72DAD20333449F8E83CFB4A:AE2D8A571E03AC9C9EB76FAC45AF8E51:C8A64537A0B3A93FCDE3CDAD9F1CE58B:0
+AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:C8A64537A0B3A93FCDE3CDAD9F1CE58B:30C81C46A35CE411E5FBC1191A0A52EF:26751F67A3CBB140B1808CF187A4F4DF:0
+AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:26751F67A3CBB140B1808CF187A4F4DF:F69F2445DF4F9B17AD2B417BE66C3710:C04B05357C5D1C0EEAC4C66F9FF7F2E6:0
+# CFB128-AES192.Encrypt
+AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CDC80D6FDDF18CAB34C25909C99A4174:1
+AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:CDC80D6FDDF18CAB34C25909C99A4174:AE2D8A571E03AC9C9EB76FAC45AF8E51:67CE7F7F81173621961A2B70171D3D7A:1
+AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:67CE7F7F81173621961A2B70171D3D7A:30C81C46A35CE411E5FBC1191A0A52EF:2E1E8A1DD59B88B1C8E60FED1EFAC4C9:1
+AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:2E1E8A1DD59B88B1C8E60FED1EFAC4C9:F69F2445DF4F9B17AD2B417BE66C3710:C05F9F9CA9834FA042AE8FBA584B09FF:1
+# CFB128-AES192.Decrypt
+AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CDC80D6FDDF18CAB34C25909C99A4174:0
+AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:CDC80D6FDDF18CAB34C25909C99A4174:AE2D8A571E03AC9C9EB76FAC45AF8E51:67CE7F7F81173621961A2B70171D3D7A:0
+AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:67CE7F7F81173621961A2B70171D3D7A:30C81C46A35CE411E5FBC1191A0A52EF:2E1E8A1DD59B88B1C8E60FED1EFAC4C9:0
+AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:2E1E8A1DD59B88B1C8E60FED1EFAC4C9:F69F2445DF4F9B17AD2B417BE66C3710:C05F9F9CA9834FA042AE8FBA584B09FF:0
+# CFB128-AES256.Encrypt 
+AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:DC7E84BFDA79164B7ECD8486985D3860:1
+AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:DC7E84BFDA79164B7ECD8486985D3860:AE2D8A571E03AC9C9EB76FAC45AF8E51:39FFED143B28B1C832113C6331E5407B:1
+AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:39FFED143B28B1C832113C6331E5407B:30C81C46A35CE411E5FBC1191A0A52EF:DF10132415E54B92A13ED0A8267AE2F9:1
+AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:DF10132415E54B92A13ED0A8267AE2F9:F69F2445DF4F9B17AD2B417BE66C3710:75A385741AB9CEF82031623D55B1E471:1
+# CFB128-AES256.Decrypt 
+AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:DC7E84BFDA79164B7ECD8486985D3860:0
+AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:DC7E84BFDA79164B7ECD8486985D3860:AE2D8A571E03AC9C9EB76FAC45AF8E51:39FFED143B28B1C832113C6331E5407B:0
+AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:39FFED143B28B1C832113C6331E5407B:30C81C46A35CE411E5FBC1191A0A52EF:DF10132415E54B92A13ED0A8267AE2F9:0
+AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:DF10132415E54B92A13ED0A8267AE2F9:F69F2445DF4F9B17AD2B417BE66C3710:75A385741AB9CEF82031623D55B1E471:0
+# For all OFB encrypts and decrypts, the transformed sequence is
+#   AES-bits-CFB:key:IV/output':plaintext:ciphertext:encdec
+# OFB-AES128.Encrypt 
+AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:3B3FD92EB72DAD20333449F8E83CFB4A:1 
+AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:50FE67CC996D32B6DA0937E99BAFEC60:AE2D8A571E03AC9C9EB76FAC45AF8E51:7789508D16918F03F53C52DAC54ED825:1 
+AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:D9A4DADA0892239F6B8B3D7680E15674:30C81C46A35CE411E5FBC1191A0A52EF:9740051E9C5FECF64344F7A82260EDCC:1 
+AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:A78819583F0308E7A6BF36B1386ABF23:F69F2445DF4F9B17AD2B417BE66C3710:304C6528F659C77866A510D9C1D6AE5E:1 
+# OFB-AES128.Decrypt 
+AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:3B3FD92EB72DAD20333449F8E83CFB4A:0
+AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:50FE67CC996D32B6DA0937E99BAFEC60:AE2D8A571E03AC9C9EB76FAC45AF8E51:7789508D16918F03F53C52DAC54ED825:0
+AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:D9A4DADA0892239F6B8B3D7680E15674:30C81C46A35CE411E5FBC1191A0A52EF:9740051E9C5FECF64344F7A82260EDCC:0
+AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:A78819583F0308E7A6BF36B1386ABF23:F69F2445DF4F9B17AD2B417BE66C3710:304C6528F659C77866A510D9C1D6AE5E:0
+# OFB-AES192.Encrypt 
+AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CDC80D6FDDF18CAB34C25909C99A4174:1 
+AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:A609B38DF3B1133DDDFF2718BA09565E:AE2D8A571E03AC9C9EB76FAC45AF8E51:FCC28B8D4C63837C09E81700C1100401:1 
+AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:52EF01DA52602FE0975F78AC84BF8A50:30C81C46A35CE411E5FBC1191A0A52EF:8D9A9AEAC0F6596F559C6D4DAF59A5F2:1 
+AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:BD5286AC63AABD7EB067AC54B553F71D:F69F2445DF4F9B17AD2B417BE66C3710:6D9F200857CA6C3E9CAC524BD9ACC92A:1 
+# OFB-AES192.Decrypt 
+AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CDC80D6FDDF18CAB34C25909C99A4174:0 
+AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:A609B38DF3B1133DDDFF2718BA09565E:AE2D8A571E03AC9C9EB76FAC45AF8E51:FCC28B8D4C63837C09E81700C1100401:0 
+AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:52EF01DA52602FE0975F78AC84BF8A50:30C81C46A35CE411E5FBC1191A0A52EF:8D9A9AEAC0F6596F559C6D4DAF59A5F2:0 
+AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:BD5286AC63AABD7EB067AC54B553F71D:F69F2445DF4F9B17AD2B417BE66C3710:6D9F200857CA6C3E9CAC524BD9ACC92A:0 
+# OFB-AES256.Encrypt 
+AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:DC7E84BFDA79164B7ECD8486985D3860:1
+AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:B7BF3A5DF43989DD97F0FA97EBCE2F4A:AE2D8A571E03AC9C9EB76FAC45AF8E51:4FEBDC6740D20B3AC88F6AD82A4FB08D:1
+AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:E1C656305ED1A7A6563805746FE03EDC:30C81C46A35CE411E5FBC1191A0A52EF:71AB47A086E86EEDF39D1C5BBA97C408:1
+AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:41635BE625B48AFC1666DD42A09D96E7:F69F2445DF4F9B17AD2B417BE66C3710:0126141D67F37BE8538F5A8BE740E484:1
+# OFB-AES256.Decrypt 
+AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:DC7E84BFDA79164B7ECD8486985D3860:0
+AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:B7BF3A5DF43989DD97F0FA97EBCE2F4A:AE2D8A571E03AC9C9EB76FAC45AF8E51:4FEBDC6740D20B3AC88F6AD82A4FB08D:0
+AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:E1C656305ED1A7A6563805746FE03EDC:30C81C46A35CE411E5FBC1191A0A52EF:71AB47A086E86EEDF39D1C5BBA97C408:0
+AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:41635BE625B48AFC1666DD42A09D96E7:F69F2445DF4F9B17AD2B417BE66C3710:0126141D67F37BE8538F5A8BE740E484:0
+
+# DES ECB tests (from destest)
+
+DES-ECB:0000000000000000::0000000000000000:8CA64DE9C1B123A7
+DES-ECB:FFFFFFFFFFFFFFFF::FFFFFFFFFFFFFFFF:7359B2163E4EDC58
+DES-ECB:3000000000000000::1000000000000001:958E6E627A05557B
+DES-ECB:1111111111111111::1111111111111111:F40379AB9E0EC533
+DES-ECB:0123456789ABCDEF::1111111111111111:17668DFC7292532D
+DES-ECB:1111111111111111::0123456789ABCDEF:8A5AE1F81AB8F2DD
+DES-ECB:FEDCBA9876543210::0123456789ABCDEF:ED39D950FA74BCC4
+
+# DESX-CBC tests (from destest)
+DESX-CBC:0123456789abcdeff1e0d3c2b5a49786fedcba9876543210:fedcba9876543210:37363534333231204E6F77206973207468652074696D6520666F722000000000:846B2914851E9A2954732F8AA0A611C115CDC2D7951B1053A63C5E03B21AA3C4
+
+# DES EDE3 CBC tests (from destest)
+DES-EDE3-CBC:0123456789abcdeff1e0d3c2b5a49786fedcba9876543210:fedcba9876543210:37363534333231204E6F77206973207468652074696D6520666F722000000000:3FE301C962AC01D02213763C1CBD4CDC799657C064ECF5D41C673812CFDE9675
+
+# RC4 tests (from rc4test)
+RC4:0123456789abcdef0123456789abcdef::0123456789abcdef:75b7878099e0c596
+RC4:0123456789abcdef0123456789abcdef::0000000000000000:7494c2e7104b0879
+RC4:00000000000000000000000000000000::0000000000000000:de188941a3375d3a
+RC4:ef012345ef012345ef012345ef012345::0000000000000000000000000000000000000000:d6a141a7ec3c38dfbd615a1162e1c7ba36b67858
+RC4:0123456789abcdef0123456789abcdef::123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345678:66a0949f8af7d6891f7f832ba833c00c892ebe30143ce28740011ecf
+RC4:ef012345ef012345ef012345ef012345::00000000000000000000:d6a141a7ec3c38dfbd61
+
+
+# Camellia tests from RFC3713
+# For all ECB encrypts and decrypts, the transformed sequence is
+#   CAMELLIA-bits-ECB:key::plaintext:ciphertext:encdec
+CAMELLIA-128-ECB:0123456789abcdeffedcba9876543210::0123456789abcdeffedcba9876543210:67673138549669730857065648eabe43
+CAMELLIA-192-ECB:0123456789abcdeffedcba98765432100011223344556677::0123456789abcdeffedcba9876543210:b4993401b3e996f84ee5cee7d79b09b9
+CAMELLIA-256-ECB:0123456789abcdeffedcba987654321000112233445566778899aabbccddeeff::0123456789abcdeffedcba9876543210:9acc237dff16d76c20ef7c919e3a7509
+
+# ECB-CAMELLIA128.Encrypt
+CAMELLIA-128-ECB:000102030405060708090A0B0C0D0E0F::00112233445566778899AABBCCDDEEFF:77CF412067AF8270613529149919546F:1
+CAMELLIA-192-ECB:000102030405060708090A0B0C0D0E0F1011121314151617::00112233445566778899AABBCCDDEEFF:B22F3C36B72D31329EEE8ADDC2906C68:1
+CAMELLIA-256-ECB:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F::00112233445566778899AABBCCDDEEFF:2EDF1F3418D53B88841FC8985FB1ECF2:1
+
+# ECB-CAMELLIA128.Encrypt and ECB-CAMELLIA128.Decrypt 
+CAMELLIA-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::6BC1BEE22E409F96E93D7E117393172A:432FC5DCD628115B7C388D770B270C96
+CAMELLIA-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::AE2D8A571E03AC9C9EB76FAC45AF8E51:0BE1F14023782A22E8384C5ABB7FAB2B
+CAMELLIA-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::30C81C46A35CE411E5FBC1191A0A52EF:A0A1ABCD1893AB6FE0FE5B65DF5F8636
+CAMELLIA-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::F69F2445DF4F9B17AD2B417BE66C3710:E61925E0D5DFAA9BB29F815B3076E51A
+
+# ECB-CAMELLIA192.Encrypt and ECB-CAMELLIA192.Decrypt 
+CAMELLIA-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::6BC1BEE22E409F96E93D7E117393172A:CCCC6C4E138B45848514D48D0D3439D3
+CAMELLIA-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::AE2D8A571E03AC9C9EB76FAC45AF8E51:5713C62C14B2EC0F8393B6AFD6F5785A
+CAMELLIA-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::30C81C46A35CE411E5FBC1191A0A52EF:B40ED2B60EB54D09D030CF511FEEF366
+CAMELLIA-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::F69F2445DF4F9B17AD2B417BE66C3710:909DBD95799096748CB27357E73E1D26
+
+# ECB-CAMELLIA256.Encrypt and ECB-CAMELLIA256.Decrypt 
+CAMELLIA-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::6BC1BEE22E409F96E93D7E117393172A:BEFD219B112FA00098919CD101C9CCFA
+CAMELLIA-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::AE2D8A571E03AC9C9EB76FAC45AF8E51:C91D3A8F1AEA08A9386CF4B66C0169EA
+CAMELLIA-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::30C81C46A35CE411E5FBC1191A0A52EF:A623D711DC5F25A51BB8A80D56397D28
+CAMELLIA-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::F69F2445DF4F9B17AD2B417BE66C3710:7960109FB6DC42947FCFE59EA3C5EB6B
+
+# For all CBC encrypts and decrypts, the transformed sequence is
+#   CAMELLIA-bits-CBC:key:IV/ciphertext':plaintext:ciphertext:encdec
+# CBC-CAMELLIA128.Encrypt and CBC-CAMELLIA128.Decrypt 
+CAMELLIA-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:1607CF494B36BBF00DAEB0B503C831AB
+CAMELLIA-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:1607CF494B36BBF00DAEB0B503C831AB:AE2D8A571E03AC9C9EB76FAC45AF8E51:A2F2CF671629EF7840C5A5DFB5074887
+CAMELLIA-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:A2F2CF671629EF7840C5A5DFB5074887:30C81C46A35CE411E5FBC1191A0A52EF:0F06165008CF8B8B5A63586362543E54
+CAMELLIA-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:36A84CDAFD5F9A85ADA0F0A993D6D577:F69F2445DF4F9B17AD2B417BE66C3710:74C64268CDB8B8FAF5B34E8AF3732980
+
+# CBC-CAMELLIA192.Encrypt and CBC-CAMELLIA192.Decrypt 
+CAMELLIA-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:2A4830AB5AC4A1A2405955FD2195CF93
+CAMELLIA-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:2A4830AB5AC4A1A2405955FD2195CF93:AE2D8A571E03AC9C9EB76FAC45AF8E51:5D5A869BD14CE54264F892A6DD2EC3D5
+CAMELLIA-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:5D5A869BD14CE54264F892A6DD2EC3D5:30C81C46A35CE411E5FBC1191A0A52EF:37D359C3349836D884E310ADDF68C449
+CAMELLIA-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:37D359C3349836D884E310ADDF68C449:F69F2445DF4F9B17AD2B417BE66C3710:01FAAA930B4AB9916E9668E1428C6B08
+
+# CBC-CAMELLIA256.Encrypt and CBC-CAMELLIA256.Decrypt 
+CAMELLIA-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:E6CFA35FC02B134A4D2C0B6737AC3EDA
+CAMELLIA-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:E6CFA35FC02B134A4D2C0B6737AC3EDA:AE2D8A571E03AC9C9EB76FAC45AF8E51:36CBEB73BD504B4070B1B7DE2B21EB50
+CAMELLIA-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:36CBEB73BD504B4070B1B7DE2B21EB50:30C81C46A35CE411E5FBC1191A0A52EF:E31A6055297D96CA3330CDF1B1860A83
+CAMELLIA-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:E31A6055297D96CA3330CDF1B1860A83:F69F2445DF4F9B17AD2B417BE66C3710:5D563F6D1CCCF236051C0C5C1C58F28F
+
+# We don't support CFB{1,8}-CAMELLIAxxx.{En,De}crypt
+# For all CFB128 encrypts and decrypts, the transformed sequence is
+#   CAMELLIA-bits-CFB:key:IV/ciphertext':plaintext:ciphertext:encdec
+# CFB128-CAMELLIA128.Encrypt 
+CAMELLIA-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:14F7646187817EB586599146B82BD719:1
+CAMELLIA-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:14F7646187817EB586599146B82BD719:AE2D8A571E03AC9C9EB76FAC45AF8E51:A53D28BB82DF741103EA4F921A44880B:1
+CAMELLIA-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:A53D28BB82DF741103EA4F921A44880B:30C81C46A35CE411E5FBC1191A0A52EF:9C2157A664626D1DEF9EA420FDE69B96:1
+CAMELLIA-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:9C2157A664626D1DEF9EA420FDE69B96:F69F2445DF4F9B17AD2B417BE66C3710:742A25F0542340C7BAEF24CA8482BB09:1
+
+# CFB128-CAMELLIA128.Decrypt 
+CAMELLIA-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:14F7646187817EB586599146B82BD719:0
+CAMELLIA-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:14F7646187817EB586599146B82BD719:AE2D8A571E03AC9C9EB76FAC45AF8E51:A53D28BB82DF741103EA4F921A44880B:0
+CAMELLIA-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:A53D28BB82DF741103EA4F921A44880B:30C81C46A35CE411E5FBC1191A0A52EF:9C2157A664626D1DEF9EA420FDE69B96:0
+CAMELLIA-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:9C2157A664626D1DEF9EA420FDE69B96:F69F2445DF4F9B17AD2B417BE66C3710:742A25F0542340C7BAEF24CA8482BB09:0
+
+# CFB128-CAMELLIA192.Encrypt
+CAMELLIA-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:C832BB9780677DAA82D9B6860DCD565E:1
+CAMELLIA-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:C832BB9780677DAA82D9B6860DCD565E:AE2D8A571E03AC9C9EB76FAC45AF8E51:86F8491627906D780C7A6D46EA331F98:1
+CAMELLIA-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:86F8491627906D780C7A6D46EA331F98:30C81C46A35CE411E5FBC1191A0A52EF:69511CCE594CF710CB98BB63D7221F01:1
+CAMELLIA-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:69511CCE594CF710CB98BB63D7221F01:F69F2445DF4F9B17AD2B417BE66C3710:D5B5378A3ABED55803F25565D8907B84:1
+
+# CFB128-CAMELLIA192.Decrypt
+CAMELLIA-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:C832BB9780677DAA82D9B6860DCD565E:0
+CAMELLIA-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:C832BB9780677DAA82D9B6860DCD565E:AE2D8A571E03AC9C9EB76FAC45AF8E51:86F8491627906D780C7A6D46EA331F98:0
+CAMELLIA-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:86F8491627906D780C7A6D46EA331F98:30C81C46A35CE411E5FBC1191A0A52EF:69511CCE594CF710CB98BB63D7221F01:0
+CAMELLIA-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:69511CCE594CF710CB98BB63D7221F01:F69F2445DF4F9B17AD2B417BE66C3710:D5B5378A3ABED55803F25565D8907B84:0
+
+# CFB128-CAMELLIA256.Encrypt 
+CAMELLIA-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CF6107BB0CEA7D7FB1BD31F5E7B06C93:1
+CAMELLIA-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:CF6107BB0CEA7D7FB1BD31F5E7B06C93:AE2D8A571E03AC9C9EB76FAC45AF8E51:89BEDB4CCDD864EA11BA4CBE849B5E2B:1
+CAMELLIA-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:89BEDB4CCDD864EA11BA4CBE849B5E2B:30C81C46A35CE411E5FBC1191A0A52EF:555FC3F34BDD2D54C62D9E3BF338C1C4:1
+CAMELLIA-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:555FC3F34BDD2D54C62D9E3BF338C1C4:F69F2445DF4F9B17AD2B417BE66C3710:5953ADCE14DB8C7F39F1BD39F359BFFA:1
+
+# CFB128-CAMELLIA256.Decrypt 
+CAMELLIA-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CF6107BB0CEA7D7FB1BD31F5E7B06C93:0
+CAMELLIA-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:CF6107BB0CEA7D7FB1BD31F5E7B06C93:AE2D8A571E03AC9C9EB76FAC45AF8E51:89BEDB4CCDD864EA11BA4CBE849B5E2B:0
+CAMELLIA-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:89BEDB4CCDD864EA11BA4CBE849B5E2B:30C81C46A35CE411E5FBC1191A0A52EF:555FC3F34BDD2D54C62D9E3BF338C1C4:0
+CAMELLIA-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:555FC3F34BDD2D54C62D9E3BF338C1C4:F69F2445DF4F9B17AD2B417BE66C3710:5953ADCE14DB8C7F39F1BD39F359BFFA:0
+
+# For all OFB encrypts and decrypts, the transformed sequence is
+#   CAMELLIA-bits-OFB:key:IV/output':plaintext:ciphertext:encdec
+# OFB-CAMELLIA128.Encrypt 
+CAMELLIA-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:14F7646187817EB586599146B82BD719:1
+CAMELLIA-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:50FE67CC996D32B6DA0937E99BAFEC60:AE2D8A571E03AC9C9EB76FAC45AF8E51:25623DB569CA51E01482649977E28D84:1
+CAMELLIA-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:D9A4DADA0892239F6B8B3D7680E15674:30C81C46A35CE411E5FBC1191A0A52EF:C776634A60729DC657D12B9FCA801E98:1
+CAMELLIA-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:A78819583F0308E7A6BF36B1386ABF23:F69F2445DF4F9B17AD2B417BE66C3710:D776379BE0E50825E681DA1A4C980E8E:1
+
+# OFB-CAMELLIA128.Decrypt 
+CAMELLIA-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:14F7646187817EB586599146B82BD719:0
+CAMELLIA-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:50FE67CC996D32B6DA0937E99BAFEC60:AE2D8A571E03AC9C9EB76FAC45AF8E51:25623DB569CA51E01482649977E28D84:0
+CAMELLIA-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:D9A4DADA0892239F6B8B3D7680E15674:30C81C46A35CE411E5FBC1191A0A52EF:C776634A60729DC657D12B9FCA801E98:0
+CAMELLIA-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:A78819583F0308E7A6BF36B1386ABF23:F69F2445DF4F9B17AD2B417BE66C3710:D776379BE0E50825E681DA1A4C980E8E:0
+
+# OFB-CAMELLIA192.Encrypt 
+CAMELLIA-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:C832BB9780677DAA82D9B6860DCD565E:1
+CAMELLIA-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:A609B38DF3B1133DDDFF2718BA09565E:AE2D8A571E03AC9C9EB76FAC45AF8E51:8ECEB7D0350D72C7F78562AEBDF99339:1
+CAMELLIA-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:52EF01DA52602FE0975F78AC84BF8A50:30C81C46A35CE411E5FBC1191A0A52EF:BDD62DBBB9700846C53B507F544696F0:1
+CAMELLIA-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:BD5286AC63AABD7EB067AC54B553F71D:F69F2445DF4F9B17AD2B417BE66C3710:E28014E046B802F385C4C2E13EAD4A72:1
+
+# OFB-CAMELLIA192.Decrypt 
+CAMELLIA-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:C832BB9780677DAA82D9B6860DCD565E:0
+CAMELLIA-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:A609B38DF3B1133DDDFF2718BA09565E:AE2D8A571E03AC9C9EB76FAC45AF8E51:8ECEB7D0350D72C7F78562AEBDF99339:0
+CAMELLIA-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:52EF01DA52602FE0975F78AC84BF8A50:30C81C46A35CE411E5FBC1191A0A52EF:BDD62DBBB9700846C53B507F544696F0:0
+CAMELLIA-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:BD5286AC63AABD7EB067AC54B553F71D:F69F2445DF4F9B17AD2B417BE66C3710:E28014E046B802F385C4C2E13EAD4A72:0
+
+# OFB-CAMELLIA256.Encrypt 
+CAMELLIA-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CF6107BB0CEA7D7FB1BD31F5E7B06C93:1
+CAMELLIA-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:B7BF3A5DF43989DD97F0FA97EBCE2F4A:AE2D8A571E03AC9C9EB76FAC45AF8E51:127AD97E8E3994E4820027D7BA109368:1
+CAMELLIA-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:E1C656305ED1A7A6563805746FE03EDC:30C81C46A35CE411E5FBC1191A0A52EF:6BFF6265A6A6B7A535BC65A80B17214E:1
+CAMELLIA-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:41635BE625B48AFC1666DD42A09D96E7:F69F2445DF4F9B17AD2B417BE66C3710:0A4A0404E26AA78A27CB271E8BF3CF20:1
+
+# OFB-CAMELLIA256.Decrypt 
+CAMELLIA-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CF6107BB0CEA7D7FB1BD31F5E7B06C93:0
+CAMELLIA-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:B7BF3A5DF43989DD97F0FA97EBCE2F4A:AE2D8A571E03AC9C9EB76FAC45AF8E51:127AD97E8E3994E4820027D7BA109368:0
+CAMELLIA-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:E1C656305ED1A7A6563805746FE03EDC:30C81C46A35CE411E5FBC1191A0A52EF:6BFF6265A6A6B7A535BC65A80B17214E:0
+CAMELLIA-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:41635BE625B48AFC1666DD42A09D96E7:F69F2445DF4F9B17AD2B417BE66C3710:0A4A0404E26AA78A27CB271E8BF3CF20:0
+
+# SEED test vectors from RFC4269
+SEED-ECB:00000000000000000000000000000000::000102030405060708090A0B0C0D0E0F:5EBAC6E0054E166819AFF1CC6D346CDB:0
+SEED-ECB:000102030405060708090A0B0C0D0E0F::00000000000000000000000000000000:C11F22F20140505084483597E4370F43:0
+SEED-ECB:4706480851E61BE85D74BFB3FD956185::83A2F8A288641FB9A4E9A5CC2F131C7D:EE54D13EBCAE706D226BC3142CD40D4A:0
+SEED-ECB:28DBC3BC49FFD87DCFA509B11D422BE7::B41E6BE2EBA84A148E2EED84593C5EC7:9B9B7BFCD1813CB95D0B3618F40F5122:0
+SEED-ECB:00000000000000000000000000000000::000102030405060708090A0B0C0D0E0F:5EBAC6E0054E166819AFF1CC6D346CDB:1
+SEED-ECB:000102030405060708090A0B0C0D0E0F::00000000000000000000000000000000:C11F22F20140505084483597E4370F43:1
+SEED-ECB:4706480851E61BE85D74BFB3FD956185::83A2F8A288641FB9A4E9A5CC2F131C7D:EE54D13EBCAE706D226BC3142CD40D4A:1
+SEED-ECB:28DBC3BC49FFD87DCFA509B11D422BE7::B41E6BE2EBA84A148E2EED84593C5EC7:9B9B7BFCD1813CB95D0B3618F40F5122:1
diff --git a/deps/openssl/openssl/test/exptest.c b/deps/openssl/openssl/test/exptest.c
new file mode 120000 (symlink)
index 0000000..50ccf71
--- /dev/null
@@ -0,0 +1 @@
+../crypto/bn/exptest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/fips_aesavs.c b/deps/openssl/openssl/test/fips_aesavs.c
new file mode 120000 (symlink)
index 0000000..7d9da0e
--- /dev/null
@@ -0,0 +1 @@
+../fips/aes/fips_aesavs.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/fips_desmovs.c b/deps/openssl/openssl/test/fips_desmovs.c
new file mode 120000 (symlink)
index 0000000..dd74966
--- /dev/null
@@ -0,0 +1 @@
+../fips/des/fips_desmovs.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/fips_dsatest.c b/deps/openssl/openssl/test/fips_dsatest.c
new file mode 120000 (symlink)
index 0000000..e43b79b
--- /dev/null
@@ -0,0 +1 @@
+../fips/dsa/fips_dsatest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/fips_dssvs.c b/deps/openssl/openssl/test/fips_dssvs.c
new file mode 120000 (symlink)
index 0000000..93e05e6
--- /dev/null
@@ -0,0 +1 @@
+../fips/dsa/fips_dssvs.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/fips_hmactest.c b/deps/openssl/openssl/test/fips_hmactest.c
new file mode 120000 (symlink)
index 0000000..b674d16
--- /dev/null
@@ -0,0 +1 @@
+../fips/hmac/fips_hmactest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/fips_randtest.c b/deps/openssl/openssl/test/fips_randtest.c
new file mode 120000 (symlink)
index 0000000..8b8f486
--- /dev/null
@@ -0,0 +1 @@
+../fips/rand/fips_randtest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/fips_rngvs.c b/deps/openssl/openssl/test/fips_rngvs.c
new file mode 120000 (symlink)
index 0000000..0d6c9be
--- /dev/null
@@ -0,0 +1 @@
+../fips/rand/fips_rngvs.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/fips_rsagtest.c b/deps/openssl/openssl/test/fips_rsagtest.c
new file mode 120000 (symlink)
index 0000000..3ed6b51
--- /dev/null
@@ -0,0 +1 @@
+../fips/rsa/fips_rsagtest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/fips_rsastest.c b/deps/openssl/openssl/test/fips_rsastest.c
new file mode 120000 (symlink)
index 0000000..2a5f8b0
--- /dev/null
@@ -0,0 +1 @@
+../fips/rsa/fips_rsastest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/fips_rsavtest.c b/deps/openssl/openssl/test/fips_rsavtest.c
new file mode 120000 (symlink)
index 0000000..f45aa58
--- /dev/null
@@ -0,0 +1 @@
+../fips/rsa/fips_rsavtest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/fips_shatest.c b/deps/openssl/openssl/test/fips_shatest.c
new file mode 120000 (symlink)
index 0000000..67c47ca
--- /dev/null
@@ -0,0 +1 @@
+../fips/sha/fips_shatest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/fips_test_suite.c b/deps/openssl/openssl/test/fips_test_suite.c
new file mode 120000 (symlink)
index 0000000..b538efa
--- /dev/null
@@ -0,0 +1 @@
+../fips/fips_test_suite.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/hmactest.c b/deps/openssl/openssl/test/hmactest.c
new file mode 120000 (symlink)
index 0000000..353ee2c
--- /dev/null
@@ -0,0 +1 @@
+../crypto/hmac/hmactest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/ideatest.c b/deps/openssl/openssl/test/ideatest.c
new file mode 120000 (symlink)
index 0000000..a9bfb3d
--- /dev/null
@@ -0,0 +1 @@
+../crypto/idea/ideatest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/igetest.c b/deps/openssl/openssl/test/igetest.c
new file mode 100644 (file)
index 0000000..1ba9002
--- /dev/null
@@ -0,0 +1,503 @@
+/* test/igetest.c -*- mode:C; c-file-style: "eay" -*- */
+/* ====================================================================
+ * Copyright (c) 2006 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    openssl-core@openssl.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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 <openssl/aes.h>
+#include <openssl/rand.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+#define TEST_SIZE      128
+#define BIG_TEST_SIZE 10240
+
+static void hexdump(FILE *f,const char *title,const unsigned char *s,int l)
+    {
+    int n=0;
+
+    fprintf(f,"%s",title);
+    for( ; n < l ; ++n)
+               {
+               if((n%16) == 0)
+                       fprintf(f,"\n%04x",n);
+               fprintf(f," %02x",s[n]);
+               }
+    fprintf(f,"\n");
+    }
+
+#define MAX_VECTOR_SIZE        64
+
+struct ige_test
+       {
+       const unsigned char key[16];
+       const unsigned char iv[32];
+       const unsigned char in[MAX_VECTOR_SIZE];
+       const unsigned char out[MAX_VECTOR_SIZE];
+       const size_t length;
+       const int encrypt;
+       };
+
+static struct ige_test const ige_test_vectors[] = {
+{ { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, /* key */
+  { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+    0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }, /* iv */
+  { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* in */
+  { 0x1a, 0x85, 0x19, 0xa6, 0x55, 0x7b, 0xe6, 0x52,
+    0xe9, 0xda, 0x8e, 0x43, 0xda, 0x4e, 0xf4, 0x45,
+    0x3c, 0xf4, 0x56, 0xb4, 0xca, 0x48, 0x8a, 0xa3,
+    0x83, 0xc7, 0x9c, 0x98, 0xb3, 0x47, 0x97, 0xcb }, /* out */
+  32, AES_ENCRYPT }, /* test vector 0 */
+
+{ { 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
+    0x61, 0x6e, 0x20, 0x69, 0x6d, 0x70, 0x6c, 0x65 }, /* key */
+  { 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f,
+    0x6e, 0x20, 0x6f, 0x66, 0x20, 0x49, 0x47, 0x45,
+    0x20, 0x6d, 0x6f, 0x64, 0x65, 0x20, 0x66, 0x6f,
+    0x72, 0x20, 0x4f, 0x70, 0x65, 0x6e, 0x53, 0x53 }, /* iv */
+  { 0x4c, 0x2e, 0x20, 0x4c, 0x65, 0x74, 0x27, 0x73,
+    0x20, 0x68, 0x6f, 0x70, 0x65, 0x20, 0x42, 0x65,
+    0x6e, 0x20, 0x67, 0x6f, 0x74, 0x20, 0x69, 0x74,
+    0x20, 0x72, 0x69, 0x67, 0x68, 0x74, 0x21, 0x0a }, /* in */
+  { 0x99, 0x70, 0x64, 0x87, 0xa1, 0xcd, 0xe6, 0x13,
+    0xbc, 0x6d, 0xe0, 0xb6, 0xf2, 0x4b, 0x1c, 0x7a,
+    0xa4, 0x48, 0xc8, 0xb9, 0xc3, 0x40, 0x3e, 0x34,
+    0x67, 0xa8, 0xca, 0xd8, 0x93, 0x40, 0xf5, 0x3b }, /* out */
+  32, AES_DECRYPT }, /* test vector 1 */
+};
+
+struct bi_ige_test
+       {
+       const unsigned char key1[32];
+       const unsigned char key2[32];
+       const unsigned char iv[64];
+       const unsigned char in[MAX_VECTOR_SIZE];
+       const unsigned char out[MAX_VECTOR_SIZE];
+       const size_t keysize;
+       const size_t length;
+       const int encrypt;
+       };
+
+static struct bi_ige_test const bi_ige_test_vectors[] = {
+{ { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, /* key1 */
+  { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+    0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }, /* key2 */
+  { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+    0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+    0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+    0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+    0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+    0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f }, /* iv */
+  { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* in */
+  { 0x14, 0x40, 0x6f, 0xae, 0xa2, 0x79, 0xf2, 0x56,
+       0x1f, 0x86, 0xeb, 0x3b, 0x7d, 0xff, 0x53, 0xdc,
+       0x4e, 0x27, 0x0c, 0x03, 0xde, 0x7c, 0xe5, 0x16,
+       0x6a, 0x9c, 0x20, 0x33, 0x9d, 0x33, 0xfe, 0x12 }, /* out */
+  16, 32, AES_ENCRYPT }, /* test vector 0 */
+{ { 0x58, 0x0a, 0x06, 0xe9, 0x97, 0x07, 0x59, 0x5c,
+       0x9e, 0x19, 0xd2, 0xa7, 0xbb, 0x40, 0x2b, 0x7a,
+       0xc7, 0xd8, 0x11, 0x9e, 0x4c, 0x51, 0x35, 0x75,
+       0x64, 0x28, 0x0f, 0x23, 0xad, 0x74, 0xac, 0x37 }, /* key1 */
+  { 0xd1, 0x80, 0xa0, 0x31, 0x47, 0xa3, 0x11, 0x13,
+       0x86, 0x26, 0x9e, 0x6d, 0xff, 0xaf, 0x72, 0x74,
+       0x5b, 0xa2, 0x35, 0x81, 0xd2, 0xa6, 0x3d, 0x21,
+       0x67, 0x7b, 0x58, 0xa8, 0x18, 0xf9, 0x72, 0xe4 }, /* key2 */
+  { 0x80, 0x3d, 0xbd, 0x4c, 0xe6, 0x7b, 0x06, 0xa9,
+       0x53, 0x35, 0xd5, 0x7e, 0x71, 0xc1, 0x70, 0x70,
+       0x74, 0x9a, 0x00, 0x28, 0x0c, 0xbf, 0x6c, 0x42,
+       0x9b, 0xa4, 0xdd, 0x65, 0x11, 0x77, 0x7c, 0x67,
+       0xfe, 0x76, 0x0a, 0xf0, 0xd5, 0xc6, 0x6e, 0x6a,
+       0xe7, 0x5e, 0x4c, 0xf2, 0x7e, 0x9e, 0xf9, 0x20,
+       0x0e, 0x54, 0x6f, 0x2d, 0x8a, 0x8d, 0x7e, 0xbd,
+       0x48, 0x79, 0x37, 0x99, 0xff, 0x27, 0x93, 0xa3 }, /* iv */
+  { 0xf1, 0x54, 0x3d, 0xca, 0xfe, 0xb5, 0xef, 0x1c,
+       0x4f, 0xa6, 0x43, 0xf6, 0xe6, 0x48, 0x57, 0xf0,
+       0xee, 0x15, 0x7f, 0xe3, 0xe7, 0x2f, 0xd0, 0x2f,
+       0x11, 0x95, 0x7a, 0x17, 0x00, 0xab, 0xa7, 0x0b,
+       0xbe, 0x44, 0x09, 0x9c, 0xcd, 0xac, 0xa8, 0x52,
+       0xa1, 0x8e, 0x7b, 0x75, 0xbc, 0xa4, 0x92, 0x5a,
+       0xab, 0x46, 0xd3, 0x3a, 0xa0, 0xd5, 0x35, 0x1c,
+       0x55, 0xa4, 0xb3, 0xa8, 0x40, 0x81, 0xa5, 0x0b}, /* in */
+  { 0x42, 0xe5, 0x28, 0x30, 0x31, 0xc2, 0xa0, 0x23,
+       0x68, 0x49, 0x4e, 0xb3, 0x24, 0x59, 0x92, 0x79,
+       0xc1, 0xa5, 0xcc, 0xe6, 0x76, 0x53, 0xb1, 0xcf,
+       0x20, 0x86, 0x23, 0xe8, 0x72, 0x55, 0x99, 0x92,
+       0x0d, 0x16, 0x1c, 0x5a, 0x2f, 0xce, 0xcb, 0x51,
+       0xe2, 0x67, 0xfa, 0x10, 0xec, 0xcd, 0x3d, 0x67,
+       0xa5, 0xe6, 0xf7, 0x31, 0x26, 0xb0, 0x0d, 0x76,
+       0x5e, 0x28, 0xdc, 0x7f, 0x01, 0xc5, 0xa5, 0x4c}, /* out */
+  32, 64, AES_ENCRYPT }, /* test vector 1 */
+
+};
+
+static int run_test_vectors(void)
+       {
+       unsigned int n;
+       int errs = 0;
+
+       for(n=0 ; n < sizeof(ige_test_vectors)/sizeof(ige_test_vectors[0]) ; ++n)
+               {
+               const struct ige_test * const v = &ige_test_vectors[n];
+               AES_KEY key;
+               unsigned char buf[MAX_VECTOR_SIZE];
+               unsigned char iv[AES_BLOCK_SIZE*2];
+
+               assert(v->length <= MAX_VECTOR_SIZE);
+
+               if(v->encrypt == AES_ENCRYPT)
+                       AES_set_encrypt_key(v->key, 8*sizeof v->key, &key);
+               else
+                       AES_set_decrypt_key(v->key, 8*sizeof v->key, &key);
+               memcpy(iv, v->iv, sizeof iv);
+               AES_ige_encrypt(v->in, buf, v->length, &key, iv, v->encrypt);
+
+               if(memcmp(v->out, buf, v->length))
+                       {
+                       printf("IGE test vector %d failed\n", n);
+                       hexdump(stdout, "key", v->key, sizeof v->key);
+                       hexdump(stdout, "iv", v->iv, sizeof v->iv);
+                       hexdump(stdout, "in", v->in, v->length);
+                       hexdump(stdout, "expected", v->out, v->length);
+                       hexdump(stdout, "got", buf, v->length);
+
+                       ++errs;
+                       }
+
+                /* try with in == out */
+               memcpy(iv, v->iv, sizeof iv);
+                memcpy(buf, v->in, v->length);
+               AES_ige_encrypt(buf, buf, v->length, &key, iv, v->encrypt);
+
+               if(memcmp(v->out, buf, v->length))
+                       {
+                       printf("IGE test vector %d failed (with in == out)\n", n);
+                       hexdump(stdout, "key", v->key, sizeof v->key);
+                       hexdump(stdout, "iv", v->iv, sizeof v->iv);
+                       hexdump(stdout, "in", v->in, v->length);
+                       hexdump(stdout, "expected", v->out, v->length);
+                       hexdump(stdout, "got", buf, v->length);
+
+                       ++errs;
+                       }
+               }
+
+       for(n=0 ; n < sizeof(bi_ige_test_vectors)/sizeof(bi_ige_test_vectors[0])
+                       ; ++n)
+               {
+               const struct bi_ige_test * const v = &bi_ige_test_vectors[n];
+               AES_KEY key1;
+               AES_KEY key2;
+               unsigned char buf[MAX_VECTOR_SIZE];
+
+               assert(v->length <= MAX_VECTOR_SIZE);
+
+               if(v->encrypt == AES_ENCRYPT)
+                       {
+                       AES_set_encrypt_key(v->key1, 8*v->keysize, &key1);
+                       AES_set_encrypt_key(v->key2, 8*v->keysize, &key2);
+                       }
+               else
+                       {
+                       AES_set_decrypt_key(v->key1, 8*v->keysize, &key1);
+                       AES_set_decrypt_key(v->key2, 8*v->keysize, &key2);
+                       }
+
+               AES_bi_ige_encrypt(v->in, buf, v->length, &key1, &key2, v->iv,
+                                                  v->encrypt);
+
+               if(memcmp(v->out, buf, v->length))
+                       {
+                       printf("Bidirectional IGE test vector %d failed\n", n);
+                       hexdump(stdout, "key 1", v->key1, sizeof v->key1);
+                       hexdump(stdout, "key 2", v->key2, sizeof v->key2);
+                       hexdump(stdout, "iv", v->iv, sizeof v->iv);
+                       hexdump(stdout, "in", v->in, v->length);
+                       hexdump(stdout, "expected", v->out, v->length);
+                       hexdump(stdout, "got", buf, v->length);
+
+                       ++errs;
+                       }
+               }
+
+       return errs;
+       }
+
+int main(int argc, char **argv)
+       {
+       unsigned char rkey[16];
+       unsigned char rkey2[16];
+       AES_KEY key;
+       AES_KEY key2;
+       unsigned char plaintext[BIG_TEST_SIZE];
+       unsigned char ciphertext[BIG_TEST_SIZE];
+       unsigned char checktext[BIG_TEST_SIZE];
+       unsigned char iv[AES_BLOCK_SIZE*4];
+       unsigned char saved_iv[AES_BLOCK_SIZE*4];
+       int err = 0;
+       unsigned int n;
+       unsigned matches;
+
+       assert(BIG_TEST_SIZE >= TEST_SIZE);
+
+       RAND_pseudo_bytes(rkey, sizeof rkey);
+       RAND_pseudo_bytes(plaintext, sizeof plaintext);
+       RAND_pseudo_bytes(iv, sizeof iv);
+       memcpy(saved_iv, iv, sizeof saved_iv);
+
+       /* Forward IGE only... */
+
+       /* Straight encrypt/decrypt */
+       AES_set_encrypt_key(rkey, 8*sizeof rkey, &key);
+       AES_ige_encrypt(plaintext, ciphertext, TEST_SIZE, &key, iv,
+                                       AES_ENCRYPT);
+
+       AES_set_decrypt_key(rkey, 8*sizeof rkey, &key);
+       memcpy(iv, saved_iv, sizeof iv);
+       AES_ige_encrypt(ciphertext, checktext, TEST_SIZE, &key, iv,
+                                       AES_DECRYPT);
+
+       if(memcmp(checktext, plaintext, TEST_SIZE))
+               {
+               printf("Encrypt+decrypt doesn't match\n");
+               hexdump(stdout, "Plaintext", plaintext, TEST_SIZE);
+               hexdump(stdout, "Checktext", checktext, TEST_SIZE);
+               ++err;
+               }
+
+       /* Now check encrypt chaining works */
+       AES_set_encrypt_key(rkey, 8*sizeof rkey, &key);
+       memcpy(iv, saved_iv, sizeof iv);
+       AES_ige_encrypt(plaintext, ciphertext, TEST_SIZE/2, &key, iv,
+                                       AES_ENCRYPT);
+       AES_ige_encrypt(plaintext+TEST_SIZE/2,
+                                       ciphertext+TEST_SIZE/2, TEST_SIZE/2,
+                                       &key, iv, AES_ENCRYPT);
+
+       AES_set_decrypt_key(rkey, 8*sizeof rkey, &key);
+       memcpy(iv, saved_iv, sizeof iv);
+       AES_ige_encrypt(ciphertext, checktext, TEST_SIZE, &key, iv,
+                                       AES_DECRYPT);
+
+       if(memcmp(checktext, plaintext, TEST_SIZE))
+               {
+               printf("Chained encrypt+decrypt doesn't match\n");
+               hexdump(stdout, "Plaintext", plaintext, TEST_SIZE);
+               hexdump(stdout, "Checktext", checktext, TEST_SIZE);
+               ++err;
+               }
+
+       /* And check decrypt chaining */
+       AES_set_encrypt_key(rkey, 8*sizeof rkey, &key);
+       memcpy(iv, saved_iv, sizeof iv);
+       AES_ige_encrypt(plaintext, ciphertext, TEST_SIZE/2, &key, iv,
+                                       AES_ENCRYPT);
+       AES_ige_encrypt(plaintext+TEST_SIZE/2,
+                                       ciphertext+TEST_SIZE/2, TEST_SIZE/2,
+                                       &key, iv, AES_ENCRYPT);
+
+       AES_set_decrypt_key(rkey, 8*sizeof rkey, &key);
+       memcpy(iv, saved_iv, sizeof iv);
+       AES_ige_encrypt(ciphertext, checktext, TEST_SIZE/2, &key, iv,
+                                       AES_DECRYPT);
+       AES_ige_encrypt(ciphertext+TEST_SIZE/2,
+                                       checktext+TEST_SIZE/2, TEST_SIZE/2, &key, iv,
+                                       AES_DECRYPT);
+
+       if(memcmp(checktext, plaintext, TEST_SIZE))
+               {
+               printf("Chained encrypt+chained decrypt doesn't match\n");
+               hexdump(stdout, "Plaintext", plaintext, TEST_SIZE);
+               hexdump(stdout, "Checktext", checktext, TEST_SIZE);
+               ++err;
+               }
+
+       /* make sure garble extends forwards only */
+       AES_set_encrypt_key(rkey, 8*sizeof rkey, &key);
+       memcpy(iv, saved_iv, sizeof iv);
+       AES_ige_encrypt(plaintext, ciphertext, sizeof plaintext, &key, iv,
+                                       AES_ENCRYPT);
+
+       /* corrupt halfway through */
+       ++ciphertext[sizeof ciphertext/2];
+       AES_set_decrypt_key(rkey, 8*sizeof rkey, &key);
+       memcpy(iv, saved_iv, sizeof iv);
+       AES_ige_encrypt(ciphertext, checktext, sizeof checktext, &key, iv,
+                                       AES_DECRYPT);
+
+       matches=0;
+       for(n=0 ; n < sizeof checktext ; ++n)
+               if(checktext[n] == plaintext[n])
+                       ++matches;
+
+       if(matches > sizeof checktext/2+sizeof checktext/100)
+               {
+               printf("More than 51%% matches after garbling\n");
+               ++err;
+               }
+
+       if(matches < sizeof checktext/2)
+               {
+               printf("Garble extends backwards!\n");
+               ++err;
+               }
+
+       /* Bi-directional IGE */
+
+       /* Note that we don't have to recover the IV, because chaining isn't */
+       /* possible with biIGE, so the IV is not updated. */
+
+       RAND_pseudo_bytes(rkey2, sizeof rkey2);
+
+       /* Straight encrypt/decrypt */
+       AES_set_encrypt_key(rkey, 8*sizeof rkey, &key);
+       AES_set_encrypt_key(rkey2, 8*sizeof rkey2, &key2);
+       AES_bi_ige_encrypt(plaintext, ciphertext, TEST_SIZE, &key, &key2, iv,
+                                          AES_ENCRYPT);
+
+       AES_set_decrypt_key(rkey, 8*sizeof rkey, &key);
+       AES_set_decrypt_key(rkey2, 8*sizeof rkey2, &key2);
+       AES_bi_ige_encrypt(ciphertext, checktext, TEST_SIZE, &key, &key2, iv,
+                                          AES_DECRYPT);
+
+       if(memcmp(checktext, plaintext, TEST_SIZE))
+               {
+               printf("Encrypt+decrypt doesn't match\n");
+               hexdump(stdout, "Plaintext", plaintext, TEST_SIZE);
+               hexdump(stdout, "Checktext", checktext, TEST_SIZE);
+               ++err;
+               }
+
+       /* make sure garble extends both ways */
+       AES_set_encrypt_key(rkey, 8*sizeof rkey, &key);
+       AES_set_encrypt_key(rkey2, 8*sizeof rkey2, &key2);
+       AES_ige_encrypt(plaintext, ciphertext, sizeof plaintext, &key, iv,
+                                       AES_ENCRYPT);
+
+       /* corrupt halfway through */
+       ++ciphertext[sizeof ciphertext/2];
+       AES_set_decrypt_key(rkey, 8*sizeof rkey, &key);
+       AES_set_decrypt_key(rkey2, 8*sizeof rkey2, &key2);
+       AES_ige_encrypt(ciphertext, checktext, sizeof checktext, &key, iv,
+                                       AES_DECRYPT);
+
+       matches=0;
+       for(n=0 ; n < sizeof checktext ; ++n)
+               if(checktext[n] == plaintext[n])
+                       ++matches;
+
+       if(matches > sizeof checktext/100)
+               {
+               printf("More than 1%% matches after bidirectional garbling\n");
+               ++err;
+               }
+
+       /* make sure garble extends both ways (2) */
+       AES_set_encrypt_key(rkey, 8*sizeof rkey, &key);
+       AES_set_encrypt_key(rkey2, 8*sizeof rkey2, &key2);
+       AES_ige_encrypt(plaintext, ciphertext, sizeof plaintext, &key, iv,
+                                       AES_ENCRYPT);
+
+       /* corrupt right at the end */
+       ++ciphertext[sizeof ciphertext-1];
+       AES_set_decrypt_key(rkey, 8*sizeof rkey, &key);
+       AES_set_decrypt_key(rkey2, 8*sizeof rkey2, &key2);
+       AES_ige_encrypt(ciphertext, checktext, sizeof checktext, &key, iv,
+                                       AES_DECRYPT);
+
+       matches=0;
+       for(n=0 ; n < sizeof checktext ; ++n)
+               if(checktext[n] == plaintext[n])
+                       ++matches;
+
+       if(matches > sizeof checktext/100)
+               {
+               printf("More than 1%% matches after bidirectional garbling (2)\n");
+               ++err;
+               }
+
+       /* make sure garble extends both ways (3) */
+       AES_set_encrypt_key(rkey, 8*sizeof rkey, &key);
+       AES_set_encrypt_key(rkey2, 8*sizeof rkey2, &key2);
+       AES_ige_encrypt(plaintext, ciphertext, sizeof plaintext, &key, iv,
+                                       AES_ENCRYPT);
+
+       /* corrupt right at the start */
+       ++ciphertext[0];
+       AES_set_decrypt_key(rkey, 8*sizeof rkey, &key);
+       AES_set_decrypt_key(rkey2, 8*sizeof rkey2, &key2);
+       AES_ige_encrypt(ciphertext, checktext, sizeof checktext, &key, iv,
+                                       AES_DECRYPT);
+
+       matches=0;
+       for(n=0 ; n < sizeof checktext ; ++n)
+               if(checktext[n] == plaintext[n])
+                       ++matches;
+
+       if(matches > sizeof checktext/100)
+               {
+               printf("More than 1%% matches after bidirectional garbling (3)\n");
+               ++err;
+               }
+
+       err += run_test_vectors();
+
+       return err;
+       }
diff --git a/deps/openssl/openssl/test/jpaketest.c b/deps/openssl/openssl/test/jpaketest.c
new file mode 120000 (symlink)
index 0000000..49f44f8
--- /dev/null
@@ -0,0 +1 @@
+dummytest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/maketests.com b/deps/openssl/openssl/test/maketests.com
new file mode 100644 (file)
index 0000000..386e5cf
--- /dev/null
@@ -0,0 +1,1085 @@
+$!
+$!  MAKETESTS.COM
+$!  Written By:  Robert Byer
+$!               Vice-President
+$!               A-Com Computing, Inc.
+$!               byer@mail.all-net.net
+$!
+$!  Changes by Richard Levitte <richard@levitte.org>
+$!
+$!  This command files compiles and creates all the various different
+$!  "test" programs for the different types of encryption for OpenSSL.
+$!  It was written so it would try to determine what "C" compiler to
+$!  use or you can specify which "C" compiler to use.
+$!
+$!  The test "executables" will be placed in a directory called
+$!  [.xxx.EXE.TEST] where "xxx" denotes ALPHA, IA64, or VAX, depending
+$!  on your machine architecture.
+$!
+$!  Specify DEBUG or NODEBUG P1 to compile with or without debugger
+$!  information.
+$!
+$!  Specify which compiler at P2 to try to compile under.
+$!
+$!        VAXC  For VAX C.
+$!        DECC  For DEC C.
+$!        GNUC  For GNU C.
+$!
+$!  If you don't specify a compiler, it will try to determine which
+$!  "C" compiler to use.
+$!
+$!  P3, if defined, sets a TCP/IP library to use, through one of the following
+$!  keywords:
+$!
+$!     UCX             for UCX
+$!     SOCKETSHR       for SOCKETSHR+NETLIB
+$!
+$!  P4, if defined, sets a compiler thread NOT needed on OpenVMS 7.1 (and up)
+$!
+$!
+$!  P5, if defined, specifies the C pointer size.  Ignored on VAX.
+$!      ("64=ARGV" gives more efficient code with HP C V7.3 or newer.)
+$!      Supported values are:
+$!
+$!      ""       Compile with default (/NOPOINTER_SIZE)
+$!      32       Compile with /POINTER_SIZE=32 (SHORT)
+$!      64       Compile with /POINTER_SIZE=64[=ARGV] (LONG[=ARGV])
+$!               (Automatically select ARGV if compiler supports it.)
+$!      64=      Compile with /POINTER_SIZE=64 (LONG).
+$!      64=ARGV  Compile with /POINTER_SIZE=64=ARGV (LONG=ARGV).
+$!
+$!  P6, if defined, specifies a directory where ZLIB files (zlib.h,
+$!  libz.olb) may be found.  Optionally, a non-default object library
+$!  name may be included ("dev:[dir]libz_64.olb", for example).
+$!
+$!
+$! Announce/identify.
+$!
+$ proc = f$environment( "procedure")
+$ write sys$output "@@@ "+ -
+   f$parse( proc, , , "name")+ f$parse( proc, , , "type")
+$!
+$! Define A TCP/IP Library That We Will Need To Link To.
+$! (That is, If We Need To Link To One.)
+$!
+$ TCPIP_LIB = ""
+$ ZLIB_LIB = ""
+$!
+$! Check Which Architecture We Are Using.
+$!
+$ if (f$getsyi( "cpu") .lt. 128)
+$ then
+$    ARCH = "VAX"
+$ else
+$    ARCH = f$edit( f$getsyi( "ARCH_NAME"), "UPCASE")
+$    if (ARCH .eqs. "") then ARCH = "UNK"
+$ endif
+$!
+$ ARCHD = ARCH
+$ LIB32 = "32"
+$ OPT_FILE = ""
+$ POINTER_SIZE = ""
+$!
+$! Check To Make Sure We Have Valid Command Line Parameters.
+$!
+$ GOSUB CHECK_OPTIONS
+$!
+$! Define The OBJ and EXE Directories.
+$!
+$ OBJ_DIR := SYS$DISK:[-.'ARCHD'.OBJ.TEST]
+$ EXE_DIR := SYS$DISK:[-.'ARCHD'.EXE.TEST]
+$!
+$! Specify the destination directory in any /MAP option.
+$!
+$ if (LINKMAP .eqs. "MAP")
+$ then
+$   LINKMAP = LINKMAP+ "=''EXE_DIR'"
+$ endif
+$!
+$! Add the location prefix to the linker options file name.
+$!
+$ if (OPT_FILE .nes. "")
+$ then
+$   OPT_FILE = EXE_DIR+ OPT_FILE
+$ endif
+$!
+$! Initialise logical names and such
+$!
+$ GOSUB INITIALISE
+$!
+$! Tell The User What Kind of Machine We Run On.
+$!
+$ WRITE SYS$OUTPUT "Host system architecture: ''ARCHD'"
+$!
+$! Define The CRYPTO-LIB We Are To Use.
+$!
+$ CRYPTO_LIB := SYS$DISK:[-.'ARCHD'.EXE.CRYPTO]SSL_LIBCRYPTO'LIB32'.OLB
+$!
+$! Define The SSL We Are To Use.
+$!
+$ SSL_LIB := SYS$DISK:[-.'ARCHD'.EXE.SSL]SSL_LIBSSL'LIB32'.OLB
+$!
+$! Create the OBJ and EXE Directories, if needed.
+$!
+$ IF (F$PARSE(OBJ_DIR).EQS."") THEN -
+   CREATE /DIRECTORY 'OBJ_DIR'
+$ IF (F$PARSE(EXE_DIR).EQS."") THEN -
+   CREATE /DIRECTORY 'EXE_DIR'
+$!
+$! Check To See If We Have The Proper Libraries.
+$!
+$ GOSUB LIB_CHECK
+$!
+$! Check To See If We Have A Linker Option File.
+$!
+$ GOSUB CHECK_OPT_FILE
+$!
+$! Define The TEST Files.
+$! NOTE: Some might think this list ugly.  However, it's made this way to
+$! reflect the EXE variable in Makefile as closely as possible,
+$! thereby making it fairly easy to verify that the lists are the same.
+$!
+$ TEST_FILES = "BNTEST,ECTEST,ECDSATEST,ECDHTEST,IDEATEST,"+ -
+              "MD2TEST,MD4TEST,MD5TEST,HMACTEST,WP_TEST,"+ -
+              "RC2TEST,RC4TEST,RC5TEST,"+ -
+              "DESTEST,SHATEST,SHA1TEST,SHA256T,SHA512T,"+ -
+              "MDC2TEST,RMDTEST,"+ -
+              "RANDTEST,DHTEST,ENGINETEST,"+ -
+              "BFTEST,CASTTEST,SSLTEST,EXPTEST,DSATEST,RSA_TEST,"+ -
+              "EVP_TEST,IGETEST,JPAKETEST,ASN1TEST"
+$! Should we add MTTEST,PQ_TEST,LH_TEST,DIVTEST,TABTEST as well?
+$!
+$! Additional directory information.
+$ T_D_BNTEST     := [-.crypto.bn]
+$ T_D_ECTEST     := [-.crypto.ec]
+$ T_D_ECDSATEST  := [-.crypto.ecdsa]
+$ T_D_ECDHTEST   := [-.crypto.ecdh]
+$ T_D_IDEATEST   := [-.crypto.idea]
+$ T_D_MD2TEST    := [-.crypto.md2]
+$ T_D_MD4TEST    := [-.crypto.md4]
+$ T_D_MD5TEST    := [-.crypto.md5]
+$ T_D_HMACTEST   := [-.crypto.hmac]
+$ T_D_WP_TEST    := [-.crypto.whrlpool]
+$ T_D_RC2TEST    := [-.crypto.rc2]
+$ T_D_RC4TEST    := [-.crypto.rc4]
+$ T_D_RC5TEST    := [-.crypto.rc5]
+$ T_D_DESTEST    := [-.crypto.des]
+$ T_D_SHATEST    := [-.crypto.sha]
+$ T_D_SHA1TEST   := [-.crypto.sha]
+$ T_D_SHA256T    := [-.crypto.sha]
+$ T_D_SHA512T    := [-.crypto.sha]
+$ T_D_MDC2TEST   := [-.crypto.mdc2]
+$ T_D_RMDTEST    := [-.crypto.ripemd]
+$ T_D_RANDTEST   := [-.crypto.rand]
+$ T_D_DHTEST     := [-.crypto.dh]
+$ T_D_ENGINETEST := [-.crypto.engine]
+$ T_D_BFTEST     := [-.crypto.bf]
+$ T_D_CASTTEST   := [-.crypto.cast]
+$ T_D_SSLTEST    := [-.ssl]
+$ T_D_EXPTEST    := [-.crypto.bn]
+$ T_D_DSATEST    := [-.crypto.dsa]
+$ T_D_RSA_TEST   := [-.crypto.rsa]
+$ T_D_EVP_TEST   := [-.crypto.evp]
+$ T_D_IGETEST    := [-.test]
+$ T_D_JPAKETEST  := [-.crypto.jpake]
+$ T_D_ASN1TEST   := [-.test]
+$!
+$ TCPIP_PROGRAMS = ",,"
+$ IF COMPILER .EQS. "VAXC" THEN -
+     TCPIP_PROGRAMS = ",SSLTEST,"
+$!
+$! Define A File Counter And Set It To "0".
+$!
+$ FILE_COUNTER = 0
+$!
+$! Top Of The File Loop.
+$!
+$ NEXT_FILE:
+$!
+$! O.K, Extract The File Name From The File List.
+$!
+$ FILE_NAME = F$ELEMENT(FILE_COUNTER,",",TEST_FILES)
+$!
+$! Check To See If We Are At The End Of The File List.
+$!
+$ IF (FILE_NAME.EQS.",") THEN GOTO FILE_DONE
+$!
+$! Increment The Counter.
+$!
+$ FILE_COUNTER = FILE_COUNTER + 1
+$!
+$! Create The Source File Name.
+$!
+$ SOURCE_FILE = "SYS$DISK:" + T_D_'FILE_NAME' + FILE_NAME + ".C"
+$!
+$! Create The Object File Name.
+$!
+$ OBJECT_FILE = OBJ_DIR + FILE_NAME + ".OBJ"
+$!
+$! Create The Executable File Name.
+$!
+$ EXE_FILE = EXE_DIR + FILE_NAME + ".EXE"
+$ ON WARNING THEN GOTO NEXT_FILE
+$!
+$! Check To See If The File We Want To Compile Actually Exists.
+$!
+$ IF (F$SEARCH(SOURCE_FILE).EQS."")
+$ THEN
+$!
+$!  Tell The User That The File Dosen't Exist.
+$!
+$   WRITE SYS$OUTPUT ""
+$   WRITE SYS$OUTPUT "The File ",SOURCE_FILE," Dosen't Exist."
+$   WRITE SYS$OUTPUT ""
+$!
+$!  Exit The Build.
+$!
+$   GOTO EXIT
+$ ENDIF
+$!
+$! Tell The User What We Are Building.
+$!
+$ WRITE SYS$OUTPUT "Building The ",FILE_NAME," Test Program."
+$!
+$! Compile The File.
+$!
+$ ON ERROR THEN GOTO NEXT_FILE
+$ CC /OBJECT='OBJECT_FILE' 'SOURCE_FILE'
+$ ON WARNING THEN GOTO NEXT_FILE
+$!
+$! Check If What We Are About To Compile Works Without A TCP/IP Library.
+$!
+$ IF ((TCPIP_LIB.EQS."").AND.((TCPIP_PROGRAMS-FILE_NAME).NES.TCPIP_PROGRAMS))
+$ THEN
+$!
+$!  Inform The User That A TCP/IP Library Is Needed To Compile This Program.
+$!
+$   WRITE SYS$OUTPUT -
+         FILE_NAME," Needs A TCP/IP Library.  Can't Link.  Skipping..."
+$   GOTO NEXT_FILE
+$!
+$! End The TCP/IP Library Check.
+$!
+$ ENDIF
+$!
+$! Link The Program, Check To See If We Need To Link With RSAREF Or Not.
+$! Check To See If We Are To Link With A Specific TCP/IP Library.
+$!
+$!  Don't Link With The RSAREF Routines And TCP/IP Library.
+$!
+$ LINK /'DEBUGGER' /'LINKMAP' /'TRACEBACK' /EXECTABLE = 'EXE_FILE' -
+   'OBJECT_FILE', -
+   'SSL_LIB' /LIBRARY, -
+   'CRYPTO_LIB' /LIBRARY -
+   'TCPIP_LIB' -
+   'ZLIB_LIB' -
+   ,'OPT_FILE' /OPTIONS
+$!
+$! Go Back And Do It Again.
+$!
+$ GOTO NEXT_FILE
+$!
+$! All Done With This Library Part.
+$!
+$ FILE_DONE:
+$!
+$! All Done, Time To Exit.
+$!
+$ EXIT:
+$ GOSUB CLEANUP
+$ EXIT
+$!
+$! Check For The Link Option FIle.
+$!
+$ CHECK_OPT_FILE:
+$!
+$! Check To See If We Need To Make A VAX C Option File.
+$!
+$ IF (COMPILER.EQS."VAXC")
+$ THEN
+$!
+$!  Check To See If We Already Have A VAX C Linker Option File.
+$!
+$   IF (F$SEARCH(OPT_FILE).EQS."")
+$   THEN
+$!
+$!    We Need A VAX C Linker Option File.
+$!
+$     CREATE 'OPT_FILE'
+$DECK
+!
+! Default System Options File To Link Against 
+! The Sharable VAX C Runtime Library.
+!
+SYS$SHARE:VAXCRTL.EXE /SHAREABLE
+$EOD
+$!
+$!  End The Option File Check.
+$!
+$   ENDIF
+$!
+$! End The VAXC Check.
+$!
+$ ENDIF
+$!
+$! Check To See If We Need A GNU C Option File.
+$!
+$ IF (COMPILER.EQS."GNUC")
+$ THEN
+$!
+$!  Check To See If We Already Have A GNU C Linker Option File.
+$!
+$   IF (F$SEARCH(OPT_FILE).EQS."")
+$   THEN
+$!
+$!    We Need A GNU C Linker Option File.
+$!
+$     CREATE 'OPT_FILE'
+$DECK
+!
+! Default System Options File To Link Against 
+! The Sharable C Runtime Library.
+!
+GNU_CC:[000000]GCCLIB.OLB /LIBRARY
+SYS$SHARE:VAXCRTL.EXE /SHAREABLE
+$EOD
+$!
+$!  End The Option File Check.
+$!
+$   ENDIF
+$!
+$! End The GNU C Check.
+$!
+$ ENDIF
+$!
+$! Check To See If We Need A DEC C Option File.
+$!
+$ IF (COMPILER.EQS."DECC")
+$ THEN
+$!
+$!  Check To See If We Already Have A DEC C Linker Option File.
+$!
+$   IF (F$SEARCH(OPT_FILE).EQS."")
+$   THEN
+$!
+$!    Figure Out If We Need A non-VAX Or A VAX Linker Option File.
+$!
+$     IF (ARCH.EQS."VAX")
+$     THEN
+$!
+$!      We Need A DEC C Linker Option File For VAX.
+$!
+$       CREATE 'OPT_FILE'
+$DECK
+!
+! Default System Options File To Link Against 
+! The Sharable DEC C Runtime Library.
+!
+SYS$SHARE:DECC$SHR.EXE /SHAREABLE
+$EOD
+$!
+$!    Else...
+$!
+$     ELSE
+$!
+$!      Create The non-VAX Linker Option File.
+$!
+$       CREATE 'OPT_FILE'
+$DECK
+!
+! Default System Options File For non-VAX To Link Against 
+! The Sharable C Runtime Library.
+!
+SYS$SHARE:CMA$OPEN_LIB_SHR.EXE /SHAREABLE
+SYS$SHARE:CMA$OPEN_RTL.EXE /SHAREABLE
+$EOD
+$!
+$!    End The DEC C Option File Check.
+$!
+$     ENDIF
+$!
+$!  End The Option File Search.
+$!
+$   ENDIF
+$!
+$! End The DEC C Check.
+$!
+$ ENDIF
+$!
+$!  Tell The User What Linker Option File We Are Using.
+$!
+$ WRITE SYS$OUTPUT "Using Linker Option File ",OPT_FILE,"."    
+$!
+$! Time To RETURN.
+$!
+$ RETURN
+$!
+$! Check To See If We Have The Appropiate Libraries.
+$!
+$ LIB_CHECK:
+$!
+$! Look For The Library LIBCRYPTO.OLB.
+$!
+$ IF (F$SEARCH(CRYPTO_LIB).EQS."")
+$ THEN
+$!
+$!  Tell The User We Can't Find The LIBCRYPTO.OLB Library.
+$!
+$   WRITE SYS$OUTPUT ""
+$   WRITE SYS$OUTPUT "Can't Find The Library ",CRYPTO_LIB,"."
+$   WRITE SYS$OUTPUT "We Can't Link Without It."
+$   WRITE SYS$OUTPUT ""
+$!
+$!  Since We Can't Link Without It, Exit.
+$!
+$   EXIT
+$!
+$! End The Crypto Library Check.
+$!
+$ ENDIF
+$!
+$! Look For The Library LIBSSL.OLB.
+$!
+$ IF (F$SEARCH(SSL_LIB).EQS."")
+$ THEN
+$!
+$!  Tell The User We Can't Find The LIBSSL.OLB Library.
+$!
+$   WRITE SYS$OUTPUT ""
+$   WRITE SYS$OUTPUT "Can't Find The Library ",SSL_LIB,"."
+$   WRITE SYS$OUTPUT "Some Of The Test Programs Need To Link To It."
+$   WRITE SYS$OUTPUT ""
+$!
+$!  Since We Can't Link Without It, Exit.
+$!
+$   EXIT
+$!
+$! End The SSL Library Check.
+$!
+$ ENDIF
+$!
+$! Time To Return.
+$!
+$ RETURN
+$!
+$! Check The User's Options.
+$!
+$ CHECK_OPTIONS:
+$!
+$! Set basic C compiler /INCLUDE directories.
+$!
+$ CC_INCLUDES = "SYS$DISK:[-],SYS$DISK:[-.CRYPTO]"
+$!
+$! Check To See If P1 Is Blank.
+$!
+$ IF (P1.EQS."NODEBUG")
+$ THEN
+$!
+$!  P1 Is NODEBUG, So Compile Without Debugger Information.
+$!
+$   DEBUGGER  = "NODEBUG"
+$   LINKMAP = "NOMAP"
+$   TRACEBACK = "NOTRACEBACK" 
+$   GCC_OPTIMIZE = "OPTIMIZE"
+$   CC_OPTIMIZE = "OPTIMIZE"
+$   WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile."
+$   WRITE SYS$OUTPUT "Compiling With Compiler Optimization."
+$!
+$! Else...
+$!
+$ ELSE
+$!
+$!  Check To See If We Are To Compile With Debugger Information.
+$!
+$   IF (P1.EQS."DEBUG")
+$   THEN
+$!
+$!    Compile With Debugger Information.
+$!
+$     DEBUGGER  = "DEBUG"
+$     LINKMAP = "MAP"
+$     TRACEBACK = "TRACEBACK"
+$     GCC_OPTIMIZE = "NOOPTIMIZE"
+$     CC_OPTIMIZE = "NOOPTIMIZE"
+$     WRITE SYS$OUTPUT "Debugger Information Will Be Produced During Compile."
+$     WRITE SYS$OUTPUT "Compiling Without Compiler Optimization."
+$!
+$!  Else...
+$!
+$   ELSE
+$!
+$!    Tell The User Entered An Invalid Option.
+$!
+$     WRITE SYS$OUTPUT ""
+$     WRITE SYS$OUTPUT "The Option ",P1," Is Invalid.  The Valid Options Are:"
+$     WRITE SYS$OUTPUT ""
+$     WRITE SYS$OUTPUT "    DEBUG    :  Compile With The Debugger Information."
+$     WRITE SYS$OUTPUT "    NODEBUG  :  Compile Without The Debugger Information."
+$     WRITE SYS$OUTPUT ""
+$!
+$!    Time To EXIT.
+$!
+$     EXIT
+$!
+$!  End The Valid Argument Check.
+$!
+$   ENDIF
+$!
+$! End The P1 Check.
+$!
+$ ENDIF
+$!
+$! Check P5 (POINTER_SIZE).
+$!
+$ IF (P5 .NES. "") .AND. (ARCH .NES. "VAX")
+$ THEN
+$!
+$   IF (P5 .EQS. "32")
+$   THEN
+$     POINTER_SIZE = " /POINTER_SIZE=32"
+$   ELSE
+$     POINTER_SIZE = F$EDIT( P5, "COLLAPSE, UPCASE")
+$     IF ((POINTER_SIZE .EQS. "64") .OR. -
+       (POINTER_SIZE .EQS. "64=") .OR. -
+       (POINTER_SIZE .EQS. "64=ARGV"))
+$     THEN
+$       ARCHD = ARCH+ "_64"
+$       LIB32 = ""
+$       IF (F$EXTRACT( 2, 1, POINTER_SIZE) .EQS. "=")
+$       THEN
+$!        Explicit user choice: "64" or "64=ARGV".
+$         IF (POINTER_SIZE .EQS. "64=") THEN POINTER_SIZE = "64"
+$       ELSE
+$         SET NOON
+$         DEFINE /USER_MODE SYS$OUTPUT NL:
+$         DEFINE /USER_MODE SYS$ERROR NL:
+$         CC /NOLIST /NOOBJECT /POINTER_SIZE=64=ARGV NL:
+$         IF ($STATUS .AND. %X0FFF0000) .EQ. %X00030000
+$         THEN
+$           ! If we got here, it means DCL complained like this:
+$           ! %DCL-W-NOVALU, value not allowed - remove value specification
+$           !  \64=\
+$           !
+$           ! If the compiler was run, logicals defined in /USER would
+$           ! have been deassigned automatically.  However, when DCL
+$           ! complains, they aren't, so we do it here (it might be
+$           ! unnecessary, but just in case there will be another error
+$           ! message further on that we don't want to miss)
+$           DEASSIGN /USER_MODE SYS$ERROR
+$           DEASSIGN /USER_MODE SYS$OUTPUT
+$         ELSE
+$           POINTER_SIZE = POINTER_SIZE + "=ARGV"
+$         ENDIF
+$         SET ON
+$       ENDIF
+$       POINTER_SIZE = " /POINTER_SIZE=''POINTER_SIZE'"
+$     ELSE
+$!
+$!      Tell The User Entered An Invalid Option.
+$!
+$       WRITE SYS$OUTPUT ""
+$       WRITE SYS$OUTPUT "The Option ", P5, -
+         " Is Invalid.  The Valid Options Are:"
+$       WRITE SYS$OUTPUT ""
+$       WRITE SYS$OUTPUT -
+         "    """"  :  Compile with default (short) pointers."
+$       WRITE SYS$OUTPUT -
+         "    32  :  Compile with 32-bit (short) pointers."
+$       WRITE SYS$OUTPUT -
+         "    64       :  Compile with 64-bit (long) pointers (auto ARGV)."
+$       WRITE SYS$OUTPUT -
+         "    64=      :  Compile with 64-bit (long) pointers (no ARGV)."
+$       WRITE SYS$OUTPUT -
+         "    64=ARGV  :  Compile with 64-bit (long) pointers (ARGV)."
+$       WRITE SYS$OUTPUT ""
+$! 
+$!      Time To EXIT.
+$!
+$       EXIT
+$!
+$     ENDIF
+$!
+$   ENDIF
+$!
+$! End The P5 (POINTER_SIZE) Check.
+$!
+$ ENDIF
+$!
+$! Check To See If P2 Is Blank.
+$!
+$ IF (P2.EQS."")
+$ THEN
+$!
+$!  O.K., The User Didn't Specify A Compiler, Let's Try To
+$!  Find Out Which One To Use.
+$!
+$!  Check To See If We Have GNU C.
+$!
+$   IF (F$TRNLNM("GNU_CC").NES."")
+$   THEN
+$!
+$!    Looks Like GNUC, Set To Use GNUC.
+$!
+$     P2 = "GNUC"
+$!
+$!  End The GNU C Compiler Check.
+$!
+$   ELSE
+$!
+$!  Check To See If We Have VAXC Or DECC.
+$!
+$     IF (ARCH.NES."VAX").OR.(F$TRNLNM("DECC$CC_DEFAULT").NES."")
+$     THEN 
+$!
+$!      Looks Like DECC, Set To Use DECC.
+$!
+$       P2 = "DECC"
+$!
+$!      Else...
+$!
+$     ELSE
+$!
+$!      Looks Like VAXC, Set To Use VAXC.
+$!
+$       P2 = "VAXC"
+$!
+$!    End The VAXC Compiler Check.
+$!
+$     ENDIF
+$!
+$!  End The DECC & VAXC Compiler Check.
+$!
+$   ENDIF
+$!
+$!  End The Compiler Check.
+$!
+$ ENDIF
+$!
+$! Check To See If We Have A Option For P3.
+$!
+$ IF (P3.EQS."")
+$ THEN
+$!
+$!  Find out what socket library we have available
+$!
+$   IF F$PARSE("SOCKETSHR:") .NES. ""
+$   THEN
+$!
+$!    We have SOCKETSHR, and it is my opinion that it's the best to use.
+$!
+$     P3 = "SOCKETSHR"
+$!
+$!    Tell the user
+$!
+$     WRITE SYS$OUTPUT "Using SOCKETSHR for TCP/IP"
+$!
+$!    Else, let's look for something else
+$!
+$   ELSE
+$!
+$!    Like UCX (the reason to do this before Multinet is that the UCX
+$!    emulation is easier to use...)
+$!
+$     IF F$TRNLNM("UCX$IPC_SHR") .NES. "" -
+        .OR. F$PARSE("SYS$SHARE:UCX$IPC_SHR.EXE") .NES. "" -
+        .OR. F$PARSE("SYS$LIBRARY:UCX$IPC.OLB") .NES. ""
+$     THEN
+$!
+$!     Last resort: a UCX or UCX-compatible library
+$!
+$      P3 = "UCX"
+$!
+$!      Tell the user
+$!
+$       WRITE SYS$OUTPUT "Using UCX or an emulation thereof for TCP/IP"
+$!
+$!     That was all...
+$!
+$     ENDIF
+$   ENDIF
+$ ENDIF
+$!
+$! Set Up Initial CC Definitions, Possibly With User Ones
+$!
+$ CCDEFS = "TCPIP_TYPE_''P3'"
+$ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS
+$ CCEXTRAFLAGS = ""
+$ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS
+$ CCDISABLEWARNINGS = "" !!! "LONGLONGTYPE,LONGLONGSUFX,FOUNDCR"
+$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN -
+       CCDISABLEWARNINGS = CCDISABLEWARNINGS + "," + USER_CCDISABLEWARNINGS
+$!
+$! Check To See If We Have A ZLIB Option.
+$!
+$ ZLIB = P6
+$ IF (ZLIB .NES. "")
+$ THEN
+$!
+$!  Check for expected ZLIB files.
+$!
+$   err = 0
+$   file1 = f$parse( "zlib.h", ZLIB, , , "SYNTAX_ONLY")
+$   if (f$search( file1) .eqs. "")
+$   then
+$     WRITE SYS$OUTPUT ""
+$     WRITE SYS$OUTPUT "The Option ", ZLIB, " Is Invalid."
+$     WRITE SYS$OUTPUT "    Can't find header: ''file1'"
+$     err = 1
+$   endif
+$   file1 = f$parse( "A.;", ZLIB)- "A.;"
+$!
+$   file2 = f$parse( ZLIB, "libz.olb", , , "SYNTAX_ONLY")
+$   if (f$search( file2) .eqs. "")
+$   then
+$     if (err .eq. 0)
+$     then
+$       WRITE SYS$OUTPUT ""
+$       WRITE SYS$OUTPUT "The Option ", ZLIB, " Is Invalid."
+$     endif
+$     WRITE SYS$OUTPUT "    Can't find library: ''file2'"
+$     WRITE SYS$OUTPUT ""
+$     err = err+ 2
+$   endif
+$   if (err .eq. 1)
+$   then
+$     WRITE SYS$OUTPUT ""
+$   endif
+$!
+$   if (err .ne. 0)
+$   then
+$     GOTO EXIT
+$   endif
+$!
+$   CCDEFS = """ZLIB=1"", "+ CCDEFS
+$   CC_INCLUDES = CC_INCLUDES+ ", "+ file1
+$   ZLIB_LIB = ", ''file2' /library"
+$!
+$!  Print info
+$!
+$   WRITE SYS$OUTPUT "ZLIB library spec: ", file2
+$!
+$! End The P8 Check.
+$!
+$ ENDIF
+$!
+$!  Check To See If The User Entered A Valid Parameter.
+$!
+$ IF (P2.EQS."VAXC").OR.(P2.EQS."DECC").OR.(P2.EQS."GNUC")
+$ THEN
+$!
+$!  Check To See If The User Wanted DECC.
+$!
+$   IF (P2.EQS."DECC")
+$   THEN
+$!
+$!    Looks Like DECC, Set To Use DECC.
+$!
+$     COMPILER = "DECC"
+$!
+$!    Tell The User We Are Using DECC.
+$!
+$     WRITE SYS$OUTPUT "Using DECC 'C' Compiler."
+$!
+$!    Use DECC...
+$!
+$     CC = "CC"
+$     IF ARCH.EQS."VAX" .AND. F$TRNLNM("DECC$CC_DEFAULT").NES."/DECC" -
+        THEN CC = "CC /DECC"
+$     CC = CC + " /''CC_OPTIMIZE' /''DEBUGGER' /STANDARD=RELAXED"+ -
+       "''POINTER_SIZE' /NOLIST /PREFIX=ALL" + -
+       " /INCLUDE=(''CC_INCLUDES') " + CCEXTRAFLAGS
+$!
+$!    Define The Linker Options File Name.
+$!
+$     OPT_FILE = "VAX_DECC_OPTIONS.OPT"
+$!
+$!  End DECC Check.
+$!
+$   ENDIF
+$!
+$!  Check To See If We Are To Use VAXC.
+$!
+$   IF (P2.EQS."VAXC")
+$   THEN
+$!
+$!    Looks Like VAXC, Set To Use VAXC.
+$!
+$     COMPILER = "VAXC"
+$!
+$!    Tell The User We Are Using VAX C.
+$!
+$     WRITE SYS$OUTPUT "Using VAXC 'C' Compiler."
+$!
+$!    Compile Using VAXC.
+$!
+$     CC = "CC"
+$     IF ARCH.NES."VAX"
+$     THEN
+$      WRITE SYS$OUTPUT "There is no VAX C on ''ARCH'!"
+$      EXIT
+$     ENDIF
+$     IF F$TRNLNM("DECC$CC_DEFAULT").EQS."/DECC" THEN CC = "CC /VAXC"
+$     CC = CC + "/''CC_OPTIMIZE' /''DEBUGGER' /NOLIST" + -
+          "/INCLUDE=(''CC_INCLUDES')" + CCEXTRAFLAGS
+$     CCDEFS = CCDEFS + ",""VAXC"""
+$!
+$!    Define <sys> As SYS$COMMON:[SYSLIB]
+$!
+$     DEFINE /NOLOG SYS SYS$COMMON:[SYSLIB]
+$!
+$!    Define The Linker Options File Name.
+$!
+$     OPT_FILE = "VAX_VAXC_OPTIONS.OPT"
+$!
+$!  End VAXC Check
+$!
+$   ENDIF
+$!
+$!  Check To See If We Are To Use GNU C.
+$!
+$   IF (P2.EQS."GNUC")
+$   THEN
+$!
+$!    Looks Like GNUC, Set To Use GNUC.
+$!
+$     COMPILER = "GNUC"
+$!
+$!    Tell The User We Are Using GNUC.
+$!
+$     WRITE SYS$OUTPUT "Using GNU 'C' Compiler."
+$!
+$!    Use GNU C...
+$!
+$     CC = "GCC /NOCASE_HACK /''GCC_OPTIMIZE' /''DEBUGGER' /NOLIST" + -
+          "/INCLUDE=(''CC_INCLUDES')" + CCEXTRAFLAGS
+$!
+$!    Define The Linker Options File Name.
+$!
+$     OPT_FILE = "VAX_GNUC_OPTIONS.OPT"
+$!
+$!  End The GNU C Check.
+$!
+$   ENDIF
+$!
+$!  Set up default defines
+$!
+$   CCDEFS = """FLAT_INC=1""," + CCDEFS
+$!
+$!  Finish up the definition of CC.
+$!
+$   IF COMPILER .EQS. "DECC"
+$   THEN
+$     IF CCDISABLEWARNINGS .EQS. ""
+$     THEN
+$       CC4DISABLEWARNINGS = "DOLLARID"
+$     ELSE
+$       CC4DISABLEWARNINGS = CCDISABLEWARNINGS + ",DOLLARID"
+$       CCDISABLEWARNINGS = " /WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))"
+$     ENDIF
+$     CC4DISABLEWARNINGS = " /WARNING=(DISABLE=(" + CC4DISABLEWARNINGS + "))"
+$   ELSE
+$     CCDISABLEWARNINGS = ""
+$     CC4DISABLEWARNINGS = ""
+$   ENDIF
+$   CC = CC + " /DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS
+$!
+$!  Show user the result
+$!
+$   WRITE /SYMBOL SYS$OUTPUT "Main Compiling Command: ", CC
+$!
+$!  Else The User Entered An Invalid Argument.
+$!
+$ ELSE
+$!
+$!  Tell The User We Don't Know What They Want.
+$!
+$   WRITE SYS$OUTPUT ""
+$   WRITE SYS$OUTPUT "The Option ",P2," Is Invalid.  The Valid Options Are:"
+$   WRITE SYS$OUTPUT ""
+$   WRITE SYS$OUTPUT "    VAXC  :  To Compile With VAX C."
+$   WRITE SYS$OUTPUT "    DECC  :  To Compile With DEC C."
+$   WRITE SYS$OUTPUT "    GNUC  :  To Compile With GNU C."
+$   WRITE SYS$OUTPUT ""
+$!
+$!  Time To EXIT.
+$!
+$   EXIT
+$ ENDIF
+$!
+$! Time to check the contents, and to make sure we get the correct library.
+$!
+$ IF P3.EQS."SOCKETSHR" .OR. P3.EQS."MULTINET" .OR. P3.EQS."UCX" -
+     .OR. P3.EQS."TCPIP" .OR. P3.EQS."NONE"
+$ THEN
+$!
+$!  Check to see if SOCKETSHR was chosen
+$!
+$   IF P3.EQS."SOCKETSHR"
+$   THEN
+$!
+$!    Set the library to use SOCKETSHR
+$!
+$     TCPIP_LIB = ",SYS$DISK:[-.VMS]SOCKETSHR_SHR.OPT /OPTIONS"
+$!
+$!    Done with SOCKETSHR
+$!
+$   ENDIF
+$!
+$!  Check to see if MULTINET was chosen
+$!
+$   IF P3.EQS."MULTINET"
+$   THEN
+$!
+$!    Set the library to use UCX emulation.
+$!
+$     P3 = "UCX"
+$!
+$!    Done with MULTINET
+$!
+$   ENDIF
+$!
+$!  Check to see if UCX was chosen
+$!
+$   IF P3.EQS."UCX"
+$   THEN
+$!
+$!    Set the library to use UCX.
+$!
+$     TCPIP_LIB = ",SYS$DISK:[-.VMS]UCX_SHR_DECC.OPT /OPTIONS"
+$     IF F$TRNLNM("UCX$IPC_SHR") .NES. ""
+$     THEN
+$       TCPIP_LIB = ",SYS$DISK:[-.VMS]UCX_SHR_DECC_LOG.OPT /OPTIONS"
+$     ELSE
+$       IF COMPILER .NES. "DECC" .AND. ARCH .EQS. "VAX" THEN -
+         TCPIP_LIB = ",SYS$DISK:[-.VMS]UCX_SHR_VAXC.OPT /OPTIONS"
+$     ENDIF
+$!
+$!    Done with UCX
+$!
+$   ENDIF
+$!
+$!  Check to see if TCPIP was chosen
+$!
+$   IF P3.EQS."TCPIP"
+$   THEN
+$!
+$!    Set the library to use TCPIP (post UCX).
+$!
+$     TCPIP_LIB = ",SYS$DISK:[-.VMS]TCPIP_SHR_DECC.OPT /OPTIONS"
+$!
+$!    Done with TCPIP
+$!
+$   ENDIF
+$!
+$!  Check to see if NONE was chosen
+$!
+$   IF P3.EQS."NONE"
+$   THEN
+$!
+$!    Do not use a TCPIP library.
+$!
+$     TCPIP_LIB = ""
+$!
+$!    Done with NONE
+$!
+$   ENDIF
+$!
+$!  Print info
+$!
+$   WRITE SYS$OUTPUT "TCP/IP library spec: ", TCPIP_LIB- ","
+$!
+$!  Else The User Entered An Invalid Argument.
+$!
+$ ELSE
+$!
+$!  Tell The User We Don't Know What They Want.
+$!
+$   WRITE SYS$OUTPUT ""
+$   WRITE SYS$OUTPUT "The Option ",P3," Is Invalid.  The Valid Options Are:"
+$   WRITE SYS$OUTPUT ""
+$   WRITE SYS$OUTPUT "    SOCKETSHR  :  To link with SOCKETSHR TCP/IP library."
+$   WRITE SYS$OUTPUT "    UCX        :  To link with UCX TCP/IP library."
+$   WRITE SYS$OUTPUT "    TCPIP      :  To link with TCPIP (post UCX) TCP/IP library."
+$   WRITE SYS$OUTPUT ""
+$!
+$!  Time To EXIT.
+$!
+$   EXIT
+$!
+$!  Done with TCP/IP libraries
+$!
+$ ENDIF
+$!
+$! Special Threads For OpenVMS v7.1 Or Later
+$!
+$! Written By:  Richard Levitte
+$!              richard@levitte.org
+$!
+$!
+$! Check To See If We Have A Option For P4.
+$!
+$ IF (P4.EQS."")
+$ THEN
+$!
+$!  Get The Version Of VMS We Are Using.
+$!
+$   ISSEVEN :=
+$   TMP = F$ELEMENT(0,"-",F$EXTRACT(1,4,F$GETSYI("VERSION")))
+$   TMP = F$INTEGER(F$ELEMENT(0,".",TMP)+F$ELEMENT(1,".",TMP))
+$!
+$!  Check To See If The VMS Version Is v7.1 Or Later.
+$!
+$   IF (TMP.GE.71)
+$   THEN
+$!
+$!    We Have OpenVMS v7.1 Or Later, So Use The Special Threads.
+$!
+$     ISSEVEN := ,PTHREAD_USE_D4
+$!
+$!  End The VMS Version Check.
+$!
+$   ENDIF
+$!
+$! End The P4 Check.
+$!
+$ ENDIF
+$!
+$!  Time To RETURN...
+$!
+$ RETURN
+$!
+$ INITIALISE:
+$!
+$! Save old value of the logical name OPENSSL
+$!
+$ __SAVE_OPENSSL = F$TRNLNM("OPENSSL","LNM$PROCESS_TABLE")
+$!
+$! Save directory information
+$!
+$ __HERE = F$PARSE(F$PARSE("A.;",F$ENVIRONMENT("PROCEDURE"))-"A.;","[]A.;") - "A.;"
+$ __HERE = F$EDIT(__HERE,"UPCASE")
+$ __TOP = __HERE - "TEST]"
+$ __INCLUDE = __TOP + "INCLUDE.OPENSSL]"
+$!
+$! Set up the logical name OPENSSL to point at the include directory
+$!
+$ DEFINE OPENSSL /NOLOG '__INCLUDE'
+$!
+$! Done
+$!
+$ RETURN
+$!
+$ CLEANUP:
+$!
+$! Restore the logical name OPENSSL if it had a value
+$!
+$ IF __SAVE_OPENSSL .EQS. ""
+$ THEN
+$   DEASSIGN OPENSSL
+$ ELSE
+$   DEFINE /NOLOG OPENSSL '__SAVE_OPENSSL'
+$ ENDIF
+$!
+$! Done
+$!
+$ RETURN
diff --git a/deps/openssl/openssl/test/md2test.c b/deps/openssl/openssl/test/md2test.c
new file mode 120000 (symlink)
index 0000000..b0c6e6f
--- /dev/null
@@ -0,0 +1 @@
+../crypto/md2/md2test.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/md4test.c b/deps/openssl/openssl/test/md4test.c
new file mode 120000 (symlink)
index 0000000..1509be9
--- /dev/null
@@ -0,0 +1 @@
+../crypto/md4/md4test.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/md5test.c b/deps/openssl/openssl/test/md5test.c
new file mode 120000 (symlink)
index 0000000..20f4aaf
--- /dev/null
@@ -0,0 +1 @@
+../crypto/md5/md5test.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/mdc2test.c b/deps/openssl/openssl/test/mdc2test.c
new file mode 120000 (symlink)
index 0000000..49f44f8
--- /dev/null
@@ -0,0 +1 @@
+dummytest.c
\ No newline at end of file
similarity index 72%
rename from deps/openssl/openssl/crypto/dsa/dsa_utl.c
rename to deps/openssl/openssl/test/methtest.c
index 24c021d..005c2f4 100644 (file)
@@ -1,4 +1,4 @@
-/* crypto/dsa/dsa_lib.c */
+/* test/methtest.c */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
  * [including the GNU Public Licence.]
  */
 
-/* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
-
 #include <stdio.h>
-#include "cryptlib.h"
-#include <openssl/bn.h>
-#include <openssl/dsa.h>
-#include <openssl/asn1.h>
-#ifndef OPENSSL_NO_ENGINE
-#include <openssl/engine.h>
-#endif
-#ifndef OPENSSL_NO_DH
-#include <openssl/dh.h>
-#endif
+#include <stdlib.h>
+#include <openssl/rsa.h>
+#include <openssl/x509.h>
+#include "meth.h"
+#include <openssl/err.h>
 
-DSA_SIG *DSA_SIG_new(void)
+int main(argc,argv)
+int argc;
+char *argv[];
        {
-       DSA_SIG *sig;
-       sig = OPENSSL_malloc(sizeof(DSA_SIG));
-       if (!sig)
-               return NULL;
-       sig->r = NULL;
-       sig->s = NULL;
-       return sig;
-       }
+       METHOD_CTX *top,*tmp1,*tmp2;
 
-void DSA_SIG_free(DSA_SIG *sig)
-       {
-       if (sig)
-               {
-               if (sig->r)
-                       BN_free(sig->r);
-               if (sig->s)
-                       BN_free(sig->s);
-               OPENSSL_free(sig);
-               }
-       }
+       top=METH_new(x509_lookup()); /* get a top level context */
+       if (top == NULL) goto err;
+
+       tmp1=METH_new(x509_by_file());
+       if (top == NULL) goto err;
+       METH_arg(tmp1,METH_TYPE_FILE,"cafile1");
+       METH_arg(tmp1,METH_TYPE_FILE,"cafile2");
+       METH_push(top,METH_X509_CA_BY_SUBJECT,tmp1);
 
+       tmp2=METH_new(x509_by_dir());
+       METH_arg(tmp2,METH_TYPE_DIR,"/home/eay/.CAcerts");
+       METH_arg(tmp2,METH_TYPE_DIR,"/home/eay/SSLeay/certs");
+       METH_arg(tmp2,METH_TYPE_DIR,"/usr/local/ssl/certs");
+       METH_push(top,METH_X509_CA_BY_SUBJECT,tmp2);
+
+/*     tmp=METH_new(x509_by_issuer_dir);
+       METH_arg(tmp,METH_TYPE_DIR,"/home/eay/.mycerts");
+       METH_push(top,METH_X509_BY_ISSUER,tmp);
+
+       tmp=METH_new(x509_by_issuer_primary);
+       METH_arg(tmp,METH_TYPE_FILE,"/home/eay/.mycerts/primary.pem");
+       METH_push(top,METH_X509_BY_ISSUER,tmp);
+*/
+
+       METH_init(top);
+       METH_control(tmp1,METH_CONTROL_DUMP,stdout);
+       METH_control(tmp2,METH_CONTROL_DUMP,stdout);
+       EXIT(0);
+err:
+       ERR_load_crypto_strings();
+       ERR_print_errors_fp(stderr);
+       EXIT(1);
+       return(0);
+       }
diff --git a/deps/openssl/openssl/test/pkcs7-1.pem b/deps/openssl/openssl/test/pkcs7-1.pem
new file mode 100644 (file)
index 0000000..c47b27a
--- /dev/null
@@ -0,0 +1,15 @@
+-----BEGIN PKCS7-----
+MIICUAYJKoZIhvcNAQcCoIICQTCCAj0CAQExDjAMBggqhkiG9w0CAgUAMCgGCSqG
+SIb3DQEHAaAbBBlFdmVyeW9uZSBnZXRzIEZyaWRheSBvZmYuoIIBXjCCAVowggEE
+AgQUAAApMA0GCSqGSIb3DQEBAgUAMCwxCzAJBgNVBAYTAlVTMR0wGwYDVQQKExRF
+eGFtcGxlIE9yZ2FuaXphdGlvbjAeFw05MjA5MDkyMjE4MDZaFw05NDA5MDkyMjE4
+MDVaMEIxCzAJBgNVBAYTAlVTMR0wGwYDVQQKExRFeGFtcGxlIE9yZ2FuaXphdGlv
+bjEUMBIGA1UEAxMLVGVzdCBVc2VyIDEwWzANBgkqhkiG9w0BAQEFAANKADBHAkAK
+ZnkdxpiBaN56t3QZu3+wwAHGJxAnAHUUKULhmo2MUdBTs+N4Kh3l3Fr06+mUaBcB
+FKHf5nzcmpr1XWVWILurAgMBAAEwDQYJKoZIhvcNAQECBQADQQBFGqHhqncgSl/N
+9XYGnQL3MsJvNnsNV4puZPOakR9Hld8JlDQFEaDR30ogsmp3TMrvdfxpLlTCoZN8
+BxEmnZsWMYGbMIGYAgEBMDQwLDELMAkGA1UEBhMCVVMxHTAbBgNVBAoTFEV4YW1w
+bGUgT3JnYW5pemF0aW9uAgQUAAApMAwGCCqGSIb3DQICBQAwDQYJKoZIhvcNAQEB
+BQAEQAX6aoEvx9+L9PJUJQngPoRuEbnGIL4gCe+0QO+8xmkhaZSsBPNBtX0FIC1C
+j7Kie1x339mxW/w9VZNTUDQQweHh
+-----END PKCS7-----
diff --git a/deps/openssl/openssl/test/pkcs7.pem b/deps/openssl/openssl/test/pkcs7.pem
new file mode 100644 (file)
index 0000000..d55c60b
--- /dev/null
@@ -0,0 +1,54 @@
+     MIAGCSqGSIb3DQEHAqCAMIACAQExADCABgkqhkiG9w0BBwEAAKCAMIIE+DCCBGGg
+     AwIBAgIQaGSF/JpbS1C223+yrc+N1DANBgkqhkiG9w0BAQQFADBiMREwDwYDVQQH
+     EwhJbnRlcm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNVBAsTK1Zl
+     cmlTaWduIENsYXNzIDEgQ0EgLSBJbmRpdmlkdWFsIFN1YnNjcmliZXIwHhcNOTYw
+     ODEyMDAwMDAwWhcNOTYwODE3MjM1OTU5WjCCASAxETAPBgNVBAcTCEludGVybmV0
+     MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrVmVyaVNpZ24gQ2xh
+     c3MgMSBDQSAtIEluZGl2aWR1YWwgU3Vic2NyaWJlcjE3MDUGA1UECxMuRGlnaXRh
+     bCBJRCBDbGFzcyAxIC0gU01JTUUgVmVyaVNpZ24sIEluYy4gVEVTVDFGMEQGA1UE
+     CxM9d3d3LnZlcmlzaWduLmNvbS9yZXBvc2l0b3J5L0NQUyBJbmNvcnAuIGJ5IFJl
+     Zi4sTElBQi5MVEQoYyk5NjEZMBcGA1UEAxMQQWxleGFuZHJlIERlYWNvbjEgMB4G
+     CSqGSIb3DQEJARYRYWxleEB2ZXJpc2lnbi5jb20wWzANBgkqhkiG9w0BAQEFAANK
+     ADBHAkAOy7xxCAIkOfuIA2LyRpxgKlDORl8htdXYhF5iBGUx1GYaK6KF+bK/CCI0
+     l4j2OfWGFBUrwGoWqxTNcWgTfMzRAgMBAAGjggIyMIICLjAJBgNVHRMEAjAAMIIC
+     HwYDVR0DBIICFjCCAhIwggIOMIICCgYLYIZIAYb4RQEHAQEwggH5FoIBp1RoaXMg
+     Y2VydGlmaWNhdGUgaW5jb3Jwb3JhdGVzIGJ5IHJlZmVyZW5jZSwgYW5kIGl0cyB1
+     c2UgaXMgc3RyaWN0bHkgc3ViamVjdCB0bywgdGhlIFZlcmlTaWduIENlcnRpZmlj
+     YXRpb24gUHJhY3RpY2UgU3RhdGVtZW50IChDUFMpLCBhdmFpbGFibGUgYXQ6IGh0
+     dHBzOi8vd3d3LnZlcmlzaWduLmNvbS9DUFM7IGJ5IEUtbWFpbCBhdCBDUFMtcmVx
+     dWVzdHNAdmVyaXNpZ24uY29tOyBvciBieSBtYWlsIGF0IFZlcmlTaWduLCBJbmMu
+     LCAyNTkzIENvYXN0IEF2ZS4sIE1vdW50YWluIFZpZXcsIENBIDk0MDQzIFVTQSBU
+     ZWwuICsxICg0MTUpIDk2MS04ODMwIENvcHlyaWdodCAoYykgMTk5NiBWZXJpU2ln
+     biwgSW5jLiAgQWxsIFJpZ2h0cyBSZXNlcnZlZC4gQ0VSVEFJTiBXQVJSQU5USUVT
+     IERJU0NMQUlNRUQgYW5kIExJQUJJTElUWSBMSU1JVEVELqAOBgxghkgBhvhFAQcB
+     AQGhDgYMYIZIAYb4RQEHAQECMCwwKhYoaHR0cHM6Ly93d3cudmVyaXNpZ24uY29t
+     L3JlcG9zaXRvcnkvQ1BTIDANBgkqhkiG9w0BAQQFAAOBgQAimWMGQwwwxk+b3KAL
+     HlSWXtU7LWHe29CEG8XeVNTvrqs6SBqT7OoENOkGxpfdpVgZ3Qw2SKjxDvbvpfSF
+     slsqcxWSgB/hWuaVuZCkvTw/dYGGOxkTJGxvDCfl1PZjX4dKbatslsi9Z9HpGWT7
+     ttItRwKqcBKgmCJvKi1pGWED0zCCAnkwggHioAMCAQICEDURpVKQb+fQKaRAGdQR
+     /D4wDQYJKoZIhvcNAQECBQAwXzELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlT
+     aWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAxIFB1YmxpYyBQcmltYXJ5IENlcnRp
+     ZmljYXRpb24gQXV0aG9yaXR5MB4XDTk2MDYyNzAwMDAwMFoXDTk3MDYyNzIzNTk1
+     OVowYjERMA8GA1UEBxMISW50ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMu
+     MTQwMgYDVQQLEytWZXJpU2lnbiBDbGFzcyAxIENBIC0gSW5kaXZpZHVhbCBTdWJz
+     Y3JpYmVyMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2FKbPTdAFDdjKI9Bv
+     qrQpkmOOLPhvltcunXZLEbE2jVfJw/0cxrr+Hgi6M8qV6r7jW80GqLd5HUQq7XPy
+     sVKDaBBwZJHXPmv5912dFEObbpdFmIFH0S3L3bty10w/cariQPJUObwW7s987Lrb
+     P2wqsxaxhhKdrpM01bjV0Pc+qQIDAQABozMwMTAPBgNVHRMECDAGAQH/AgEBMAsG
+     A1UdDwQEAwIBBjARBglghkgBhvhCAQEEBAMCAgQwDQYJKoZIhvcNAQECBQADgYEA
+     KeXHoBmnbxRCgk0jM9e9mDppdxpsipIna/J8DOHEUuD4nONAr4+xOg73SBl026n7
+     Bk55A2wvAMGo7+kKTZ+rHaFDDcmq4O+rzFri2RIOeGAncj1IcGptAQhvXoIhFMG4
+     Jlzg1KlHZHqy7D3jex78zcSU7kKOu8f5tAX1jC3+sToAAKGAMIIBJzCBkTANBgkq
+     hkiG9w0BAQIFADBiMREwDwYDVQQHEwhJbnRlcm5ldDEXMBUGA1UEChMOVmVyaVNp
+     Z24sIEluYy4xNDAyBgNVBAsTK1ZlcmlTaWduIENsYXNzIDEgQ0EgLSBJbmRpdmlk
+     dWFsIFN1YnNjcmliZXIXDTk2MDcwMTE3MzA0MFoXDTk3MDcwMTAwMDAwMFowDQYJ
+     KoZIhvcNAQECBQADgYEAGLuQ6PX8A7AiqBEtWzYtl6lZNSDI0bR5YUo+D2Jzkw30
+     dxQnJSbKXEc6XYuzAW5HvrzATXu5c19WWPT4cRDwmjH71i9QcDysWwf/wE0qGTiW
+     I3tQT0I5VGh7jIJD07nlBw3R4Xl8dH9kr85JsWinqDH5YKpIo9o8knY5n7+qjOow
+     ggEkMIGOMA0GCSqGSIb3DQEBAgUAMF8xCzAJBgNVBAYTAlVTMRcwFQYDVQQKEw5W
+     ZXJpU2lnbiwgSW5jLjE3MDUGA1UECxMuQ2xhc3MgMSBQdWJsaWMgUHJpbWFyeSBD
+     ZXJ0aWZpY2F0aW9uIEF1dGhvcml0eRcNOTYwNzE2MjMxMTI5WhcNOTYwODE1MDAw
+     MDAwWjANBgkqhkiG9w0BAQIFAAOBgQAXsLE4vnsY6sY67QrmWec7iaU2ehzxanEK
+     /9wKHZNuhlNzk+qGZZw2evxfUe2OaRbYpl8zuZvhK9BHD3ad14OSe9/zx5hOPgP/
+     DQXt6R4R8Q/1JheBrolrgbavjvI2wKS8/Psp2prBrkF4T48+AKRmS8Zzh1guxgvP
+     b+xSu/jH0gAAMYAAAAAAAAAAAA==
diff --git a/deps/openssl/openssl/test/pkits-test.pl b/deps/openssl/openssl/test/pkits-test.pl
new file mode 100644 (file)
index 0000000..69dffa1
--- /dev/null
@@ -0,0 +1,940 @@
+# test/pkits-test.pl
+# Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+# project.
+#
+# ====================================================================
+# Copyright (c) 2008 The OpenSSL 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 OpenSSL Project
+#    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+#
+# 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+#    endorse or promote products derived from this software without
+#    prior written permission. For written permission, please contact
+#    licensing@OpenSSL.org.
+#
+# 5. Products derived from this software may not be called "OpenSSL"
+#    nor may "OpenSSL" appear in their names without prior written
+#    permission of the OpenSSL Project.
+#
+# 6. Redistributions of any form whatsoever must retain the following
+#    acknowledgment:
+#    "This product includes software developed by the OpenSSL Project
+#    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+#
+# THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+# ====================================================================
+
+# Perl utility to run PKITS tests for RFC3280 compliance. 
+
+my $ossl_path;
+
+if ( -f "../apps/openssl" ) {
+    $ossl_path = "../util/shlib_wrap.sh ../apps/openssl";
+}
+elsif ( -f "..\\out32dll\\openssl.exe" ) {
+    $ossl_path = "..\\out32dll\\openssl.exe";
+}
+elsif ( -f "..\\out32\\openssl.exe" ) {
+    $ossl_path = "..\\out32\\openssl.exe";
+}
+else {
+    die "Can't find OpenSSL executable";
+}
+
+my $pkitsdir = "pkits/smime";
+my $pkitsta = "pkits/certs/TrustAnchorRootCertificate.crt";
+
+die "Can't find PKITS test data" if !-d $pkitsdir;
+
+my $nist1 = "2.16.840.1.101.3.2.1.48.1";
+my $nist2 = "2.16.840.1.101.3.2.1.48.2";
+my $nist3 = "2.16.840.1.101.3.2.1.48.3";
+my $nist4 = "2.16.840.1.101.3.2.1.48.4";
+my $nist5 = "2.16.840.1.101.3.2.1.48.5";
+my $nist6 = "2.16.840.1.101.3.2.1.48.6";
+
+my $apolicy = "X509v3 Any Policy";
+
+# This table contains the chapter headings of the accompanying PKITS
+# document. They provide useful informational output and their names
+# can be converted into the filename to test.
+
+my @testlists = (
+    [ "4.1", "Signature Verification" ],
+    [ "4.1.1", "Valid Signatures Test1",                        0 ],
+    [ "4.1.2", "Invalid CA Signature Test2",                    7 ],
+    [ "4.1.3", "Invalid EE Signature Test3",                    7 ],
+    [ "4.1.4", "Valid DSA Signatures Test4",                    0 ],
+    [ "4.1.5", "Valid DSA Parameter Inheritance Test5",         0 ],
+    [ "4.1.6", "Invalid DSA Signature Test6",                   7 ],
+    [ "4.2",   "Validity Periods" ],
+    [ "4.2.1", "Invalid CA notBefore Date Test1",               9 ],
+    [ "4.2.2", "Invalid EE notBefore Date Test2",               9 ],
+    [ "4.2.3", "Valid pre2000 UTC notBefore Date Test3",        0 ],
+    [ "4.2.4", "Valid GeneralizedTime notBefore Date Test4",    0 ],
+    [ "4.2.5", "Invalid CA notAfter Date Test5",                10 ],
+    [ "4.2.6", "Invalid EE notAfter Date Test6",                10 ],
+    [ "4.2.7", "Invalid pre2000 UTC EE notAfter Date Test7",    10 ],
+    [ "4.2.8", "Valid GeneralizedTime notAfter Date Test8",     0 ],
+    [ "4.3",   "Verifying Name Chaining" ],
+    [ "4.3.1", "Invalid Name Chaining EE Test1",                20 ],
+    [ "4.3.2", "Invalid Name Chaining Order Test2",             20 ],
+    [ "4.3.3", "Valid Name Chaining Whitespace Test3",          0 ],
+    [ "4.3.4", "Valid Name Chaining Whitespace Test4",          0 ],
+    [ "4.3.5", "Valid Name Chaining Capitalization Test5",      0 ],
+    [ "4.3.6", "Valid Name Chaining UIDs Test6",                0 ],
+    [ "4.3.7", "Valid RFC3280 Mandatory Attribute Types Test7", 0 ],
+    [ "4.3.8", "Valid RFC3280 Optional Attribute Types Test8",  0 ],
+    [ "4.3.9", "Valid UTF8String Encoded Names Test9",          0 ],
+    [ "4.3.10", "Valid Rollover from PrintableString to UTF8String Test10", 0 ],
+    [ "4.3.11", "Valid UTF8String Case Insensitive Match Test11",           0 ],
+    [ "4.4",    "Basic Certificate Revocation Tests" ],
+    [ "4.4.1",  "Missing CRL Test1",                                        3 ],
+    [ "4.4.2", "Invalid Revoked CA Test2",          23 ],
+    [ "4.4.3", "Invalid Revoked EE Test3",          23 ],
+    [ "4.4.4", "Invalid Bad CRL Signature Test4",   8 ],
+    [ "4.4.5", "Invalid Bad CRL Issuer Name Test5", 3 ],
+    [ "4.4.6", "Invalid Wrong CRL Test6",           3 ],
+    [ "4.4.7", "Valid Two CRLs Test7",              0 ],
+
+    # The test document suggests these should return certificate revoked...
+    # Subsquent discussion has concluded they should not due to unhandle
+    # critical CRL extensions.
+    [ "4.4.8", "Invalid Unknown CRL Entry Extension Test8", 36 ],
+    [ "4.4.9", "Invalid Unknown CRL Extension Test9",       36 ],
+
+    [ "4.4.10", "Invalid Unknown CRL Extension Test10",             36 ],
+    [ "4.4.11", "Invalid Old CRL nextUpdate Test11",                12 ],
+    [ "4.4.12", "Invalid pre2000 CRL nextUpdate Test12",            12 ],
+    [ "4.4.13", "Valid GeneralizedTime CRL nextUpdate Test13",      0 ],
+    [ "4.4.14", "Valid Negative Serial Number Test14",              0 ],
+    [ "4.4.15", "Invalid Negative Serial Number Test15",            23 ],
+    [ "4.4.16", "Valid Long Serial Number Test16",                  0 ],
+    [ "4.4.17", "Valid Long Serial Number Test17",                  0 ],
+    [ "4.4.18", "Invalid Long Serial Number Test18",                23 ],
+    [ "4.4.19", "Valid Separate Certificate and CRL Keys Test19",   0 ],
+    [ "4.4.20", "Invalid Separate Certificate and CRL Keys Test20", 23 ],
+
+    # CRL path is revoked so get a CRL path validation error
+    [ "4.4.21", "Invalid Separate Certificate and CRL Keys Test21",      54 ],
+    [ "4.5",    "Verifying Paths with Self-Issued Certificates" ],
+    [ "4.5.1",  "Valid Basic Self-Issued Old With New Test1",            0 ],
+    [ "4.5.2",  "Invalid Basic Self-Issued Old With New Test2",          23 ],
+    [ "4.5.3",  "Valid Basic Self-Issued New With Old Test3",            0 ],
+    [ "4.5.4",  "Valid Basic Self-Issued New With Old Test4",            0 ],
+    [ "4.5.5",  "Invalid Basic Self-Issued New With Old Test5",          23 ],
+    [ "4.5.6",  "Valid Basic Self-Issued CRL Signing Key Test6",         0 ],
+    [ "4.5.7",  "Invalid Basic Self-Issued CRL Signing Key Test7",       23 ],
+    [ "4.5.8",  "Invalid Basic Self-Issued CRL Signing Key Test8",       20 ],
+    [ "4.6",    "Verifying Basic Constraints" ],
+    [ "4.6.1",  "Invalid Missing basicConstraints Test1",                24 ],
+    [ "4.6.2",  "Invalid cA False Test2",                                24 ],
+    [ "4.6.3",  "Invalid cA False Test3",                                24 ],
+    [ "4.6.4",  "Valid basicConstraints Not Critical Test4",             0 ],
+    [ "4.6.5",  "Invalid pathLenConstraint Test5",                       25 ],
+    [ "4.6.6",  "Invalid pathLenConstraint Test6",                       25 ],
+    [ "4.6.7",  "Valid pathLenConstraint Test7",                         0 ],
+    [ "4.6.8",  "Valid pathLenConstraint Test8",                         0 ],
+    [ "4.6.9",  "Invalid pathLenConstraint Test9",                       25 ],
+    [ "4.6.10", "Invalid pathLenConstraint Test10",                      25 ],
+    [ "4.6.11", "Invalid pathLenConstraint Test11",                      25 ],
+    [ "4.6.12", "Invalid pathLenConstraint Test12",                      25 ],
+    [ "4.6.13", "Valid pathLenConstraint Test13",                        0 ],
+    [ "4.6.14", "Valid pathLenConstraint Test14",                        0 ],
+    [ "4.6.15", "Valid Self-Issued pathLenConstraint Test15",            0 ],
+    [ "4.6.16", "Invalid Self-Issued pathLenConstraint Test16",          25 ],
+    [ "4.6.17", "Valid Self-Issued pathLenConstraint Test17",            0 ],
+    [ "4.7",    "Key Usage" ],
+    [ "4.7.1",  "Invalid keyUsage Critical keyCertSign False Test1",     20 ],
+    [ "4.7.2",  "Invalid keyUsage Not Critical keyCertSign False Test2", 20 ],
+    [ "4.7.3",  "Valid keyUsage Not Critical Test3",                     0 ],
+    [ "4.7.4",  "Invalid keyUsage Critical cRLSign False Test4",         35 ],
+    [ "4.7.5",  "Invalid keyUsage Not Critical cRLSign False Test5",     35 ],
+
+    # Certificate policy tests need special handling. They can have several
+    # sub tests and we need to check the outputs are correct.
+
+    [ "4.8", "Certificate Policies" ],
+    [
+        "4.8.1.1",
+        "All Certificates Same Policy Test1",
+        "-policy anyPolicy -explicit_policy",
+        "True", $nist1, $nist1, 0
+    ],
+    [
+        "4.8.1.2",
+        "All Certificates Same Policy Test1",
+        "-policy $nist1 -explicit_policy",
+        "True", $nist1, $nist1, 0
+    ],
+    [
+        "4.8.1.3",
+        "All Certificates Same Policy Test1",
+        "-policy $nist2 -explicit_policy",
+        "True", $nist1, "<empty>", 43
+    ],
+    [
+        "4.8.1.4",
+        "All Certificates Same Policy Test1",
+        "-policy $nist1 -policy $nist2 -explicit_policy",
+        "True", $nist1, $nist1, 0
+    ],
+    [
+        "4.8.2.1",
+        "All Certificates No Policies Test2",
+        "-policy anyPolicy",
+        "False", "<empty>", "<empty>", 0
+    ],
+    [
+        "4.8.2.2",
+        "All Certificates No Policies Test2",
+        "-policy anyPolicy -explicit_policy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.8.3.1",
+        "Different Policies Test3",
+        "-policy anyPolicy",
+        "False", "<empty>", "<empty>", 0
+    ],
+    [
+        "4.8.3.2",
+        "Different Policies Test3",
+        "-policy anyPolicy -explicit_policy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.8.3.3",
+        "Different Policies Test3",
+        "-policy $nist1 -policy $nist2 -explicit_policy",
+        "True", "<empty>", "<empty>", 43
+    ],
+
+    [
+        "4.8.4",
+        "Different Policies Test4",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.8.5",
+        "Different Policies Test5",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.8.6.1",
+        "Overlapping Policies Test6",
+        "-policy anyPolicy",
+        "True", $nist1, $nist1, 0
+    ],
+    [
+        "4.8.6.2",
+        "Overlapping Policies Test6",
+        "-policy $nist1",
+        "True", $nist1, $nist1, 0
+    ],
+    [
+        "4.8.6.3",
+        "Overlapping Policies Test6",
+        "-policy $nist2",
+        "True", $nist1, "<empty>", 43
+    ],
+    [
+        "4.8.7",
+        "Different Policies Test7",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.8.8",
+        "Different Policies Test8",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.8.9",
+        "Different Policies Test9",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.8.10.1",
+        "All Certificates Same Policies Test10",
+        "-policy $nist1",
+        "True", "$nist1:$nist2", "$nist1", 0
+    ],
+    [
+        "4.8.10.2",
+        "All Certificates Same Policies Test10",
+        "-policy $nist2",
+        "True", "$nist1:$nist2", "$nist2", 0
+    ],
+    [
+        "4.8.10.3",
+        "All Certificates Same Policies Test10",
+        "-policy anyPolicy",
+        "True", "$nist1:$nist2", "$nist1:$nist2", 0
+    ],
+    [
+        "4.8.11.1",
+        "All Certificates AnyPolicy Test11",
+        "-policy anyPolicy",
+        "True", "$apolicy", "$apolicy", 0
+    ],
+    [
+        "4.8.11.2",
+        "All Certificates AnyPolicy Test11",
+        "-policy $nist1",
+        "True", "$apolicy", "$nist1", 0
+    ],
+    [
+        "4.8.12",
+        "Different Policies Test12",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.8.13.1",
+        "All Certificates Same Policies Test13",
+        "-policy $nist1",
+        "True", "$nist1:$nist2:$nist3", "$nist1", 0
+    ],
+    [
+        "4.8.13.2",
+        "All Certificates Same Policies Test13",
+        "-policy $nist2",
+        "True", "$nist1:$nist2:$nist3", "$nist2", 0
+    ],
+    [
+        "4.8.13.3",
+        "All Certificates Same Policies Test13",
+        "-policy $nist3",
+        "True", "$nist1:$nist2:$nist3", "$nist3", 0
+    ],
+    [
+        "4.8.14.1",       "AnyPolicy Test14",
+        "-policy $nist1", "True",
+        "$nist1",         "$nist1",
+        0
+    ],
+    [
+        "4.8.14.2",       "AnyPolicy Test14",
+        "-policy $nist2", "True",
+        "$nist1",         "<empty>",
+        43
+    ],
+    [
+        "4.8.15",
+        "User Notice Qualifier Test15",
+        "-policy anyPolicy",
+        "False", "$nist1", "$nist1", 0
+    ],
+    [
+        "4.8.16",
+        "User Notice Qualifier Test16",
+        "-policy anyPolicy",
+        "False", "$nist1", "$nist1", 0
+    ],
+    [
+        "4.8.17",
+        "User Notice Qualifier Test17",
+        "-policy anyPolicy",
+        "False", "$nist1", "$nist1", 0
+    ],
+    [
+        "4.8.18.1",
+        "User Notice Qualifier Test18",
+        "-policy $nist1",
+        "True", "$nist1:$nist2", "$nist1", 0
+    ],
+    [
+        "4.8.18.2",
+        "User Notice Qualifier Test18",
+        "-policy $nist2",
+        "True", "$nist1:$nist2", "$nist2", 0
+    ],
+    [
+        "4.8.19",
+        "User Notice Qualifier Test19",
+        "-policy anyPolicy",
+        "False", "$nist1", "$nist1", 0
+    ],
+    [
+        "4.8.20",
+        "CPS Pointer Qualifier Test20",
+        "-policy anyPolicy -explicit_policy",
+        "True", "$nist1", "$nist1", 0
+    ],
+    [ "4.9", "Require Explicit Policy" ],
+    [
+        "4.9.1",
+        "Valid RequireExplicitPolicy Test1",
+        "-policy anyPolicy",
+        "False", "<empty>", "<empty>", 0
+    ],
+    [
+        "4.9.2",
+        "Valid RequireExplicitPolicy Test2",
+        "-policy anyPolicy",
+        "False", "<empty>", "<empty>", 0
+    ],
+    [
+        "4.9.3",
+        "Invalid RequireExplicitPolicy Test3",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.9.4",
+        "Valid RequireExplicitPolicy Test4",
+        "-policy anyPolicy",
+        "True", "$nist1", "$nist1", 0
+    ],
+    [
+        "4.9.5",
+        "Invalid RequireExplicitPolicy Test5",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.9.6",
+        "Valid Self-Issued requireExplicitPolicy Test6",
+        "-policy anyPolicy",
+        "False", "<empty>", "<empty>", 0
+    ],
+    [
+        "4.9.7",
+        "Invalid Self-Issued requireExplicitPolicy Test7",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.9.8",
+        "Invalid Self-Issued requireExplicitPolicy Test8",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [ "4.10", "Policy Mappings" ],
+    [
+        "4.10.1.1",
+        "Valid Policy Mapping Test1",
+        "-policy $nist1",
+        "True", "$nist1", "$nist1", 0
+    ],
+    [
+        "4.10.1.2",
+        "Valid Policy Mapping Test1",
+        "-policy $nist2",
+        "True", "$nist1", "<empty>", 43
+    ],
+    [
+        "4.10.1.3",
+        "Valid Policy Mapping Test1",
+        "-policy anyPolicy -inhibit_map",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.10.2.1",
+        "Invalid Policy Mapping Test2",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.10.2.2",
+        "Invalid Policy Mapping Test2",
+        "-policy anyPolicy -inhibit_map",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.10.3.1",
+        "Valid Policy Mapping Test3",
+        "-policy $nist1",
+        "True", "$nist2", "<empty>", 43
+    ],
+    [
+        "4.10.3.2",
+        "Valid Policy Mapping Test3",
+        "-policy $nist2",
+        "True", "$nist2", "$nist2", 0
+    ],
+    [
+        "4.10.4",
+        "Invalid Policy Mapping Test4",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.10.5.1",
+        "Valid Policy Mapping Test5",
+        "-policy $nist1",
+        "True", "$nist1", "$nist1", 0
+    ],
+    [
+        "4.10.5.2",
+        "Valid Policy Mapping Test5",
+        "-policy $nist6",
+        "True", "$nist1", "<empty>", 43
+    ],
+    [
+        "4.10.6.1",
+        "Valid Policy Mapping Test6",
+        "-policy $nist1",
+        "True", "$nist1", "$nist1", 0
+    ],
+    [
+        "4.10.6.2",
+        "Valid Policy Mapping Test6",
+        "-policy $nist6",
+        "True", "$nist1", "<empty>", 43
+    ],
+    [ "4.10.7", "Invalid Mapping From anyPolicy Test7", 42 ],
+    [ "4.10.8", "Invalid Mapping To anyPolicy Test8",   42 ],
+    [
+        "4.10.9",
+        "Valid Policy Mapping Test9",
+        "-policy anyPolicy",
+        "True", "$nist1", "$nist1", 0
+    ],
+    [
+        "4.10.10",
+        "Invalid Policy Mapping Test10",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.10.11",
+        "Valid Policy Mapping Test11",
+        "-policy anyPolicy",
+        "True", "$nist1", "$nist1", 0
+    ],
+
+    # TODO: check notice display
+    [
+        "4.10.12.1",
+        "Valid Policy Mapping Test12",
+        "-policy $nist1",
+        "True", "$nist1:$nist2", "$nist1", 0
+    ],
+
+    # TODO: check notice display
+    [
+        "4.10.12.2",
+        "Valid Policy Mapping Test12",
+        "-policy $nist2",
+        "True", "$nist1:$nist2", "$nist2", 0
+    ],
+    [
+        "4.10.13",
+        "Valid Policy Mapping Test13",
+        "-policy anyPolicy",
+        "True", "$nist1", "$nist1", 0
+    ],
+
+    # TODO: check notice display
+    [
+        "4.10.14",
+        "Valid Policy Mapping Test14",
+        "-policy anyPolicy",
+        "True", "$nist1", "$nist1", 0
+    ],
+    [ "4.11", "Inhibit Policy Mapping" ],
+    [
+        "4.11.1",
+        "Invalid inhibitPolicyMapping Test1",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.11.2",
+        "Valid inhibitPolicyMapping Test2",
+        "-policy anyPolicy",
+        "True", "$nist1", "$nist1", 0
+    ],
+    [
+        "4.11.3",
+        "Invalid inhibitPolicyMapping Test3",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.11.4",
+        "Valid inhibitPolicyMapping Test4",
+        "-policy anyPolicy",
+        "True", "$nist2", "$nist2", 0
+    ],
+    [
+        "4.11.5",
+        "Invalid inhibitPolicyMapping Test5",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.11.6",
+        "Invalid inhibitPolicyMapping Test6",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.11.7",
+        "Valid Self-Issued inhibitPolicyMapping Test7",
+        "-policy anyPolicy",
+        "True", "$nist1", "$nist1", 0
+    ],
+    [
+        "4.11.8",
+        "Invalid Self-Issued inhibitPolicyMapping Test8",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.11.9",
+        "Invalid Self-Issued inhibitPolicyMapping Test9",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.11.10",
+        "Invalid Self-Issued inhibitPolicyMapping Test10",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.11.11",
+        "Invalid Self-Issued inhibitPolicyMapping Test11",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [ "4.12", "Inhibit Any Policy" ],
+    [
+        "4.12.1",
+        "Invalid inhibitAnyPolicy Test1",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.12.2",
+        "Valid inhibitAnyPolicy Test2",
+        "-policy anyPolicy",
+        "True", "$nist1", "$nist1", 0
+    ],
+    [
+        "4.12.3.1",
+        "inhibitAnyPolicy Test3",
+        "-policy anyPolicy",
+        "True", "$nist1", "$nist1", 0
+    ],
+    [
+        "4.12.3.2",
+        "inhibitAnyPolicy Test3",
+        "-policy anyPolicy -inhibit_any",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.12.4",
+        "Invalid inhibitAnyPolicy Test4",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.12.5",
+        "Invalid inhibitAnyPolicy Test5",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [
+        "4.12.6",
+        "Invalid inhibitAnyPolicy Test6",
+        "-policy anyPolicy",
+        "True", "<empty>", "<empty>", 43
+    ],
+    [ "4.12.7",  "Valid Self-Issued inhibitAnyPolicy Test7",      0 ],
+    [ "4.12.8",  "Invalid Self-Issued inhibitAnyPolicy Test8",    43 ],
+    [ "4.12.9",  "Valid Self-Issued inhibitAnyPolicy Test9",      0 ],
+    [ "4.12.10", "Invalid Self-Issued inhibitAnyPolicy Test10",   43 ],
+    [ "4.13",    "Name Constraints" ],
+    [ "4.13.1",  "Valid DN nameConstraints Test1",                0 ],
+    [ "4.13.2",  "Invalid DN nameConstraints Test2",              47 ],
+    [ "4.13.3",  "Invalid DN nameConstraints Test3",              47 ],
+    [ "4.13.4",  "Valid DN nameConstraints Test4",                0 ],
+    [ "4.13.5",  "Valid DN nameConstraints Test5",                0 ],
+    [ "4.13.6",  "Valid DN nameConstraints Test6",                0 ],
+    [ "4.13.7",  "Invalid DN nameConstraints Test7",              48 ],
+    [ "4.13.8",  "Invalid DN nameConstraints Test8",              48 ],
+    [ "4.13.9",  "Invalid DN nameConstraints Test9",              48 ],
+    [ "4.13.10", "Invalid DN nameConstraints Test10",             48 ],
+    [ "4.13.11", "Valid DN nameConstraints Test11",               0 ],
+    [ "4.13.12", "Invalid DN nameConstraints Test12",             47 ],
+    [ "4.13.13", "Invalid DN nameConstraints Test13",             47 ],
+    [ "4.13.14", "Valid DN nameConstraints Test14",               0 ],
+    [ "4.13.15", "Invalid DN nameConstraints Test15",             48 ],
+    [ "4.13.16", "Invalid DN nameConstraints Test16",             48 ],
+    [ "4.13.17", "Invalid DN nameConstraints Test17",             48 ],
+    [ "4.13.18", "Valid DN nameConstraints Test18",               0 ],
+    [ "4.13.19", "Valid Self-Issued DN nameConstraints Test19",   0 ],
+    [ "4.13.20", "Invalid Self-Issued DN nameConstraints Test20", 47 ],
+    [ "4.13.21", "Valid RFC822 nameConstraints Test21",           0 ],
+    [ "4.13.22", "Invalid RFC822 nameConstraints Test22",         47 ],
+    [ "4.13.23", "Valid RFC822 nameConstraints Test23",           0 ],
+    [ "4.13.24", "Invalid RFC822 nameConstraints Test24",         47 ],
+    [ "4.13.25", "Valid RFC822 nameConstraints Test25",           0 ],
+    [ "4.13.26", "Invalid RFC822 nameConstraints Test26",         48 ],
+    [ "4.13.27", "Valid DN and RFC822 nameConstraints Test27",    0 ],
+    [ "4.13.28", "Invalid DN and RFC822 nameConstraints Test28",  47 ],
+    [ "4.13.29", "Invalid DN and RFC822 nameConstraints Test29",  47 ],
+    [ "4.13.30", "Valid DNS nameConstraints Test30",              0 ],
+    [ "4.13.31", "Invalid DNS nameConstraints Test31",            47 ],
+    [ "4.13.32", "Valid DNS nameConstraints Test32",              0 ],
+    [ "4.13.33", "Invalid DNS nameConstraints Test33",            48 ],
+    [ "4.13.34", "Valid URI nameConstraints Test34",              0 ],
+    [ "4.13.35", "Invalid URI nameConstraints Test35",            47 ],
+    [ "4.13.36", "Valid URI nameConstraints Test36",              0 ],
+    [ "4.13.37", "Invalid URI nameConstraints Test37",            48 ],
+    [ "4.13.38", "Invalid DNS nameConstraints Test38",            47 ],
+    [ "4.14",    "Distribution Points" ],
+    [ "4.14.1",  "Valid distributionPoint Test1",                 0 ],
+    [ "4.14.2",  "Invalid distributionPoint Test2",               23 ],
+    [ "4.14.3",  "Invalid distributionPoint Test3",               44 ],
+    [ "4.14.4",  "Valid distributionPoint Test4",                 0 ],
+    [ "4.14.5",  "Valid distributionPoint Test5",                 0 ],
+    [ "4.14.6",  "Invalid distributionPoint Test6",               23 ],
+    [ "4.14.7",  "Valid distributionPoint Test7",                 0 ],
+    [ "4.14.8",  "Invalid distributionPoint Test8",               44 ],
+    [ "4.14.9",  "Invalid distributionPoint Test9",               44 ],
+    [ "4.14.10", "Valid No issuingDistributionPoint Test10",      0 ],
+    [ "4.14.11", "Invalid onlyContainsUserCerts CRL Test11",      44 ],
+    [ "4.14.12", "Invalid onlyContainsCACerts CRL Test12",        44 ],
+    [ "4.14.13", "Valid onlyContainsCACerts CRL Test13",          0 ],
+    [ "4.14.14", "Invalid onlyContainsAttributeCerts Test14",     44 ],
+    [ "4.14.15", "Invalid onlySomeReasons Test15",                23 ],
+    [ "4.14.16", "Invalid onlySomeReasons Test16",                23 ],
+    [ "4.14.17", "Invalid onlySomeReasons Test17",                3 ],
+    [ "4.14.18", "Valid onlySomeReasons Test18",                  0 ],
+    [ "4.14.19", "Valid onlySomeReasons Test19",                  0 ],
+    [ "4.14.20", "Invalid onlySomeReasons Test20",                23 ],
+    [ "4.14.21", "Invalid onlySomeReasons Test21",                23 ],
+    [ "4.14.22", "Valid IDP with indirectCRL Test22",             0 ],
+    [ "4.14.23", "Invalid IDP with indirectCRL Test23",           23 ],
+    [ "4.14.24", "Valid IDP with indirectCRL Test24",             0 ],
+    [ "4.14.25", "Valid IDP with indirectCRL Test25",             0 ],
+    [ "4.14.26", "Invalid IDP with indirectCRL Test26",           44 ],
+    [ "4.14.27", "Invalid cRLIssuer Test27",                      3 ],
+    [ "4.14.28", "Valid cRLIssuer Test28",                        0 ],
+    [ "4.14.29", "Valid cRLIssuer Test29",                        0 ],
+
+    # Although this test is valid it has a circular dependency. As a result
+    # an attempt is made to reursively checks a CRL path and rejected due to
+    # a CRL path validation error. PKITS notes suggest this test does not
+    # need to be run due to this issue.
+    [ "4.14.30", "Valid cRLIssuer Test30",                                 54 ],
+    [ "4.14.31", "Invalid cRLIssuer Test31",                               23 ],
+    [ "4.14.32", "Invalid cRLIssuer Test32",                               23 ],
+    [ "4.14.33", "Valid cRLIssuer Test33",                                 0 ],
+    [ "4.14.34", "Invalid cRLIssuer Test34",                               23 ],
+    [ "4.14.35", "Invalid cRLIssuer Test35",                               44 ],
+    [ "4.15",    "Delta-CRLs" ],
+    [ "4.15.1",  "Invalid deltaCRLIndicator No Base Test1",                3 ],
+    [ "4.15.2",  "Valid delta-CRL Test2",                                  0 ],
+    [ "4.15.3",  "Invalid delta-CRL Test3",                                23 ],
+    [ "4.15.4",  "Invalid delta-CRL Test4",                                23 ],
+    [ "4.15.5",  "Valid delta-CRL Test5",                                  0 ],
+    [ "4.15.6",  "Invalid delta-CRL Test6",                                23 ],
+    [ "4.15.7",  "Valid delta-CRL Test7",                                  0 ],
+    [ "4.15.8",  "Valid delta-CRL Test8",                                  0 ],
+    [ "4.15.9",  "Invalid delta-CRL Test9",                                23 ],
+    [ "4.15.10", "Invalid delta-CRL Test10",                               12 ],
+    [ "4.16",    "Private Certificate Extensions" ],
+    [ "4.16.1",  "Valid Unknown Not Critical Certificate Extension Test1", 0 ],
+    [ "4.16.2",  "Invalid Unknown Critical Certificate Extension Test2",   34 ],
+);
+
+
+my $verbose = 1;
+
+my $numtest = 0;
+my $numfail = 0;
+
+my $ossl = "ossl/apps/openssl";
+
+my $ossl_cmd = "$ossl_path cms -verify -verify_retcode ";
+$ossl_cmd .= "-CAfile pkitsta.pem -crl_check_all -x509_strict ";
+$ossl_cmd .= "-policy_check -extended_crl -use_deltas -out /dev/null 2>&1 ";
+
+system "$ossl_path x509 -inform DER -in $pkitsta -out pkitsta.pem";
+
+die "Can't create trust anchor file" if $?;
+
+print "Running PKITS tests:\n" if $verbose;
+
+foreach (@testlists) {
+    my $argnum = @$_;
+    if ( $argnum == 2 ) {
+        my ( $tnum, $title ) = @$_;
+        print "$tnum $title\n" if $verbose;
+    }
+    elsif ( $argnum == 3 ) {
+        my ( $tnum, $title, $exp_ret ) = @$_;
+        my $filename = $title;
+        $exp_ret += 32 if $exp_ret;
+        $filename =~ tr/ -//d;
+        $filename = "Signed${filename}.eml";
+        if ( !-f "$pkitsdir/$filename" ) {
+            print "\"$filename\" not found\n";
+        }
+        else {
+            my $ret;
+            my $test_fail = 0;
+            my $errmsg    = "";
+            my $cmd       = $ossl_cmd;
+            $cmd .= "-in $pkitsdir/$filename -policy anyPolicy";
+            my $cmdout = `$cmd`;
+            $ret = $? >> 8;
+            if ( $? & 0xff ) {
+                $errmsg .= "Abnormal OpenSSL termination\n";
+                $test_fail = 1;
+            }
+            if ( $exp_ret != $ret ) {
+                $errmsg .= "Return code:$ret, ";
+                $errmsg .= "expected $exp_ret\n";
+                $test_fail = 1;
+            }
+            if ($test_fail) {
+                print "$tnum $title : Failed!\n";
+                print "Filename: $pkitsdir/$filename\n";
+                print $errmsg;
+                print "Command output:\n$cmdout\n";
+                $numfail++;
+            }
+            $numtest++;
+        }
+    }
+    elsif ( $argnum == 7 ) {
+        my ( $tnum, $title, $exargs, $exp_epol, $exp_aset, $exp_uset, $exp_ret )
+          = @$_;
+        my $filename = $title;
+        $exp_ret += 32 if $exp_ret;
+        $filename =~ tr/ -//d;
+        $filename = "Signed${filename}.eml";
+        if ( !-f "$pkitsdir/$filename" ) {
+            print "\"$filename\" not found\n";
+        }
+        else {
+            my $ret;
+            my $cmdout    = "";
+            my $errmsg    = "";
+            my $epol      = "";
+            my $aset      = "";
+            my $uset      = "";
+            my $pol       = -1;
+            my $test_fail = 0;
+            my $cmd       = $ossl_cmd;
+            $cmd .= "-in $pkitsdir/$filename $exargs -policy_print";
+            @oparr = `$cmd`;
+            $ret   = $? >> 8;
+
+            if ( $? & 0xff ) {
+                $errmsg .= "Abnormal OpenSSL termination\n";
+                $test_fail = 1;
+            }
+            foreach (@oparr) {
+                my $test_failed = 0;
+                $cmdout .= $_;
+                if (/^Require explicit Policy: (.*)$/) {
+                    $epol = $1;
+                }
+                if (/^Authority Policies/) {
+                    if (/empty/) {
+                        $aset = "<empty>";
+                    }
+                    else {
+                        $pol = 1;
+                    }
+                }
+                $test_fail = 1 if (/leak/i);
+                if (/^User Policies/) {
+                    if (/empty/) {
+                        $uset = "<empty>";
+                    }
+                    else {
+                        $pol = 2;
+                    }
+                }
+                if (/\s+Policy: (.*)$/) {
+                    if ( $pol == 1 ) {
+                        $aset .= ":" if $aset ne "";
+                        $aset .= $1;
+                    }
+                    elsif ( $pol == 2 ) {
+                        $uset .= ":" if $uset ne "";
+                        $uset .= $1;
+                    }
+                }
+            }
+
+            if ( $epol ne $exp_epol ) {
+                $errmsg .= "Explicit policy:$epol, ";
+                $errmsg .= "expected $exp_epol\n";
+                $test_fail = 1;
+            }
+            if ( $aset ne $exp_aset ) {
+                $errmsg .= "Authority policy set :$aset, ";
+                $errmsg .= "expected $exp_aset\n";
+                $test_fail = 1;
+            }
+            if ( $uset ne $exp_uset ) {
+                $errmsg .= "User policy set :$uset, ";
+                $errmsg .= "expected $exp_uset\n";
+                $test_fail = 1;
+            }
+
+            if ( $exp_ret != $ret ) {
+                print "Return code:$ret, expected $exp_ret\n";
+                $test_fail = 1;
+            }
+
+            if ($test_fail) {
+                print "$tnum $title : Failed!\n";
+                print "Filename: $pkitsdir/$filename\n";
+                print "Command output:\n$cmdout\n";
+                $numfail++;
+            }
+            $numtest++;
+        }
+    }
+}
+
+if ($numfail) {
+    print "$numfail tests failed out of $numtest\n";
+}
+else {
+    print "All Tests Successful.\n";
+}
+
+unlink "pkitsta.pem";
+
similarity index 89%
rename from deps/openssl/openssl/crypto/err/err_bio.c
rename to deps/openssl/openssl/test/r160test.c
index a42f804..a172e39 100644 (file)
@@ -1,4 +1,4 @@
-/* crypto/err/err_prn.c */
+/* test/r160test.c */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
  * copied and put under another distribution licence
  * [including the GNU Public Licence.]
  */
-
-#include <stdio.h>
-#include "cryptlib.h"
-#include <openssl/lhash.h>
-#include <openssl/crypto.h>
-#include <openssl/buffer.h>
-#include <openssl/err.h>
-
-static int print_bio(const char *str, size_t len, void *bp)
-       {
-       return BIO_write((BIO *)bp, str, len);
-       }
-void ERR_print_errors(BIO *bp)
-       {
-       ERR_print_errors_cb(print_bio, bp);
-       }
-
-       
diff --git a/deps/openssl/openssl/test/randtest.c b/deps/openssl/openssl/test/randtest.c
new file mode 120000 (symlink)
index 0000000..a2b107a
--- /dev/null
@@ -0,0 +1 @@
+../crypto/rand/randtest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/rc2test.c b/deps/openssl/openssl/test/rc2test.c
new file mode 120000 (symlink)
index 0000000..5c53ad9
--- /dev/null
@@ -0,0 +1 @@
+../crypto/rc2/rc2test.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/rc4test.c b/deps/openssl/openssl/test/rc4test.c
new file mode 120000 (symlink)
index 0000000..061ac37
--- /dev/null
@@ -0,0 +1 @@
+../crypto/rc4/rc4test.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/rc5test.c b/deps/openssl/openssl/test/rc5test.c
new file mode 120000 (symlink)
index 0000000..49f44f8
--- /dev/null
@@ -0,0 +1 @@
+dummytest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/rmdtest.c b/deps/openssl/openssl/test/rmdtest.c
new file mode 120000 (symlink)
index 0000000..ce66460
--- /dev/null
@@ -0,0 +1 @@
+../crypto/ripemd/rmdtest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/rsa_test.c b/deps/openssl/openssl/test/rsa_test.c
new file mode 120000 (symlink)
index 0000000..aaea20d
--- /dev/null
@@ -0,0 +1 @@
+../crypto/rsa/rsa_test.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/sha1test.c b/deps/openssl/openssl/test/sha1test.c
new file mode 120000 (symlink)
index 0000000..8d66e9e
--- /dev/null
@@ -0,0 +1 @@
+../crypto/sha/sha1test.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/sha256t.c b/deps/openssl/openssl/test/sha256t.c
new file mode 120000 (symlink)
index 0000000..952a508
--- /dev/null
@@ -0,0 +1 @@
+../crypto/sha/sha256t.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/sha512t.c b/deps/openssl/openssl/test/sha512t.c
new file mode 120000 (symlink)
index 0000000..c80d152
--- /dev/null
@@ -0,0 +1 @@
+../crypto/sha/sha512t.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/shatest.c b/deps/openssl/openssl/test/shatest.c
new file mode 120000 (symlink)
index 0000000..43cfda7
--- /dev/null
@@ -0,0 +1 @@
+../crypto/sha/shatest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/smcont.txt b/deps/openssl/openssl/test/smcont.txt
new file mode 100644 (file)
index 0000000..e837c0b
--- /dev/null
@@ -0,0 +1 @@
+Some test content for OpenSSL CMS
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/smime-certs/smdsa1.pem b/deps/openssl/openssl/test/smime-certs/smdsa1.pem
new file mode 100644 (file)
index 0000000..d5677db
--- /dev/null
@@ -0,0 +1,34 @@
+-----BEGIN DSA PRIVATE KEY-----
+MIIBuwIBAAKBgQDFJfsIPOIawMO5biw+AoYUhNVxReBOLQosU3Qv4B8krac0BNr3
+OjSGLh1wZxHqhlAE0QmasTaKojuk20nNWeFnczSz6vDl0IVJEhS8VYor5kt9gLqt
+GcoAgsf4gRDIutJyQDaNn3IVY89uXUVIoexvQeLQDBCgQPC5O8rJdqBwtwIVAK2J
+jt+dqk07eQUE59koYUEKyNorAoGBAI4IEpusf8G14kCHmRtnHXM2tG5EWJDmW6Qt
+wjqvWp1GKUx5WFy1tVWR9nl5rL0Di+kNdENo+SkKj7h3uDulGOI6T0mQYbV2h1IK
++FMOGnOqvZ8eNTE2n4PGTo5puZ63LBm+QYrQsrNiUY4vakLFQ2rEK/SLwdsDFK4Z
+SJCBQw5zAoGATQlPPF+OeU8nu3rsdXGDiZdJzOkuCce3KQfTABA9C+Dk4CVcvBdd
+YRLGpnykumkNTO1sTO+4/Gphsuje1ujK9td4UEhdYqylCe5QjEMrszDlJtelDQF9
+C0yhdjKGTP0kxofLhsGckcuQvcKEKffT2pDDKJIy4vWQO0UyJl1vjLcCFG2uiGGx
+9fMUZq1v0ePD4Wo0Xkxo
+-----END DSA PRIVATE KEY-----
+-----BEGIN CERTIFICATE-----
+MIIDpDCCAw2gAwIBAgIJAMtotfHYdEsWMA0GCSqGSIb3DQEBBQUAMEQxCzAJBgNV
+BAYTAlVLMRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMR0wGwYDVQQDExRUZXN0IFMv
+TUlNRSBSU0EgUm9vdDAeFw0wODAyMjIxMzUzMDlaFw0xNjA1MTAxMzUzMDlaMEUx
+CzAJBgNVBAYTAlVLMRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMR4wHAYDVQQDDBVU
+ZXN0IFMvTUlNRSBFRSBEU0EgIzEwggG3MIIBLAYHKoZIzjgEATCCAR8CgYEAxSX7
+CDziGsDDuW4sPgKGFITVcUXgTi0KLFN0L+AfJK2nNATa9zo0hi4dcGcR6oZQBNEJ
+mrE2iqI7pNtJzVnhZ3M0s+rw5dCFSRIUvFWKK+ZLfYC6rRnKAILH+IEQyLrSckA2
+jZ9yFWPPbl1FSKHsb0Hi0AwQoEDwuTvKyXagcLcCFQCtiY7fnapNO3kFBOfZKGFB
+CsjaKwKBgQCOCBKbrH/BteJAh5kbZx1zNrRuRFiQ5lukLcI6r1qdRilMeVhctbVV
+kfZ5eay9A4vpDXRDaPkpCo+4d7g7pRjiOk9JkGG1dodSCvhTDhpzqr2fHjUxNp+D
+xk6OabmetywZvkGK0LKzYlGOL2pCxUNqxCv0i8HbAxSuGUiQgUMOcwOBhAACgYBN
+CU88X455Tye7eux1cYOJl0nM6S4Jx7cpB9MAED0L4OTgJVy8F11hEsamfKS6aQ1M
+7WxM77j8amGy6N7W6Mr213hQSF1irKUJ7lCMQyuzMOUm16UNAX0LTKF2MoZM/STG
+h8uGwZyRy5C9woQp99PakMMokjLi9ZA7RTImXW+Mt6OBgzCBgDAdBgNVHQ4EFgQU
+4Qfbhpi5yqXaXuCLXj427mR25MkwHwYDVR0jBBgwFoAUE89Lp7uJLrM4Vxd2xput
+aFvl7RcwDAYDVR0TAQH/BAIwADAOBgNVHQ8BAf8EBAMCBsAwIAYDVR0RBBkwF4EV
+c21pbWVkc2ExQG9wZW5zc2wub3JnMA0GCSqGSIb3DQEBBQUAA4GBAFrdUzKK1pWO
+kd02S423KUBc4GWWyiGlVoEO7WxVhHLJ8sm67X7OtJOwe0UGt+Nc5qLtyJYSirw8
+phjiTdNpQCTJ8+Kc56tWkJ6H7NAI4vTJtPL5BM/EmeYrVSU9JI9xhqpyKw9IBD+n
+hRJ79W9FaiJRvaAOX+TkyTukJrxAWRyv
+-----END CERTIFICATE-----
diff --git a/deps/openssl/openssl/test/smime-certs/smdsa2.pem b/deps/openssl/openssl/test/smime-certs/smdsa2.pem
new file mode 100644 (file)
index 0000000..ef86c11
--- /dev/null
@@ -0,0 +1,34 @@
+-----BEGIN DSA PRIVATE KEY-----
+MIIBvAIBAAKBgQDFJfsIPOIawMO5biw+AoYUhNVxReBOLQosU3Qv4B8krac0BNr3
+OjSGLh1wZxHqhlAE0QmasTaKojuk20nNWeFnczSz6vDl0IVJEhS8VYor5kt9gLqt
+GcoAgsf4gRDIutJyQDaNn3IVY89uXUVIoexvQeLQDBCgQPC5O8rJdqBwtwIVAK2J
+jt+dqk07eQUE59koYUEKyNorAoGBAI4IEpusf8G14kCHmRtnHXM2tG5EWJDmW6Qt
+wjqvWp1GKUx5WFy1tVWR9nl5rL0Di+kNdENo+SkKj7h3uDulGOI6T0mQYbV2h1IK
++FMOGnOqvZ8eNTE2n4PGTo5puZ63LBm+QYrQsrNiUY4vakLFQ2rEK/SLwdsDFK4Z
+SJCBQw5zAoGBAIPmO8BtJ+Yac58trrPwq9b/6VW3jQTWzTLWSH84/QQdqQa+Pz3v
+It/+hHM0daNF5uls8ICsPL1aLXmRx0pHvIyb0aAzYae4T4Jv/COPDMTdKbA1uitJ
+VbkGZrm+LIrs7I9lOkb4T0vI6kL/XdOCXY1469zsqCgJ/O2ibn6mq0nWAhR716o2
+Nf8SimTZYB0/CKje6M5ufA==
+-----END DSA PRIVATE KEY-----
+-----BEGIN CERTIFICATE-----
+MIIDpTCCAw6gAwIBAgIJAMtotfHYdEsXMA0GCSqGSIb3DQEBBQUAMEQxCzAJBgNV
+BAYTAlVLMRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMR0wGwYDVQQDExRUZXN0IFMv
+TUlNRSBSU0EgUm9vdDAeFw0wODAyMjIxMzUzMDlaFw0xNjA1MTAxMzUzMDlaMEUx
+CzAJBgNVBAYTAlVLMRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMR4wHAYDVQQDDBVU
+ZXN0IFMvTUlNRSBFRSBEU0EgIzIwggG4MIIBLAYHKoZIzjgEATCCAR8CgYEAxSX7
+CDziGsDDuW4sPgKGFITVcUXgTi0KLFN0L+AfJK2nNATa9zo0hi4dcGcR6oZQBNEJ
+mrE2iqI7pNtJzVnhZ3M0s+rw5dCFSRIUvFWKK+ZLfYC6rRnKAILH+IEQyLrSckA2
+jZ9yFWPPbl1FSKHsb0Hi0AwQoEDwuTvKyXagcLcCFQCtiY7fnapNO3kFBOfZKGFB
+CsjaKwKBgQCOCBKbrH/BteJAh5kbZx1zNrRuRFiQ5lukLcI6r1qdRilMeVhctbVV
+kfZ5eay9A4vpDXRDaPkpCo+4d7g7pRjiOk9JkGG1dodSCvhTDhpzqr2fHjUxNp+D
+xk6OabmetywZvkGK0LKzYlGOL2pCxUNqxCv0i8HbAxSuGUiQgUMOcwOBhQACgYEA
+g+Y7wG0n5hpzny2us/Cr1v/pVbeNBNbNMtZIfzj9BB2pBr4/Pe8i3/6EczR1o0Xm
+6WzwgKw8vVoteZHHSke8jJvRoDNhp7hPgm/8I48MxN0psDW6K0lVuQZmub4siuzs
+j2U6RvhPS8jqQv9d04JdjXjr3OyoKAn87aJufqarSdajgYMwgYAwHQYDVR0OBBYE
+FHsAGNfVltSYUq4hC+YVYwsYtA+dMB8GA1UdIwQYMBaAFBPPS6e7iS6zOFcXdsab
+rWhb5e0XMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgbAMCAGA1UdEQQZMBeB
+FXNtaW1lZHNhMkBvcGVuc3NsLm9yZzANBgkqhkiG9w0BAQUFAAOBgQCx9BtCbaYF
+FXjLClkuKXbESaDZA1biPgY25i00FsUzARuhCpqD2v+0tu5c33ZzIhL6xlvBRU5l
+6Atw/xpZhae+hdBEtxPJoGekLLrHOau7Md3XwDjV4lFgcEJkWZoaSOOIK+4D5jF0
+jZWtHjnwEzuLYlo7ScHSsbcQfjH0M1TP5A==
+-----END CERTIFICATE-----
diff --git a/deps/openssl/openssl/test/smime-certs/smdsa3.pem b/deps/openssl/openssl/test/smime-certs/smdsa3.pem
new file mode 100644 (file)
index 0000000..eeb848d
--- /dev/null
@@ -0,0 +1,34 @@
+-----BEGIN DSA PRIVATE KEY-----
+MIIBvAIBAAKBgQDFJfsIPOIawMO5biw+AoYUhNVxReBOLQosU3Qv4B8krac0BNr3
+OjSGLh1wZxHqhlAE0QmasTaKojuk20nNWeFnczSz6vDl0IVJEhS8VYor5kt9gLqt
+GcoAgsf4gRDIutJyQDaNn3IVY89uXUVIoexvQeLQDBCgQPC5O8rJdqBwtwIVAK2J
+jt+dqk07eQUE59koYUEKyNorAoGBAI4IEpusf8G14kCHmRtnHXM2tG5EWJDmW6Qt
+wjqvWp1GKUx5WFy1tVWR9nl5rL0Di+kNdENo+SkKj7h3uDulGOI6T0mQYbV2h1IK
++FMOGnOqvZ8eNTE2n4PGTo5puZ63LBm+QYrQsrNiUY4vakLFQ2rEK/SLwdsDFK4Z
+SJCBQw5zAoGAYzOpPmh8Je1IDauEXhgaLz14wqYUHHcrj2VWVJ6fRm8GhdQFJSI7
+GUk08pgKZSKic2lNqxuzW7/vFxKQ/nvzfytY16b+2i+BR4Q6yvMzCebE1hHVg0Ju
+TwfUMwoFEOhYP6ZwHSUiQl9IBMH9TNJCMwYMxfY+VOrURFsjGTRUgpwCFQCIGt5g
+Y+XZd0Sv69CatDIRYWvaIA==
+-----END DSA PRIVATE KEY-----
+-----BEGIN CERTIFICATE-----
+MIIDpDCCAw2gAwIBAgIJAMtotfHYdEsYMA0GCSqGSIb3DQEBBQUAMEQxCzAJBgNV
+BAYTAlVLMRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMR0wGwYDVQQDExRUZXN0IFMv
+TUlNRSBSU0EgUm9vdDAeFw0wODAyMjIxMzUzMDlaFw0xNjA1MTAxMzUzMDlaMEUx
+CzAJBgNVBAYTAlVLMRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMR4wHAYDVQQDDBVU
+ZXN0IFMvTUlNRSBFRSBEU0EgIzMwggG3MIIBLAYHKoZIzjgEATCCAR8CgYEAxSX7
+CDziGsDDuW4sPgKGFITVcUXgTi0KLFN0L+AfJK2nNATa9zo0hi4dcGcR6oZQBNEJ
+mrE2iqI7pNtJzVnhZ3M0s+rw5dCFSRIUvFWKK+ZLfYC6rRnKAILH+IEQyLrSckA2
+jZ9yFWPPbl1FSKHsb0Hi0AwQoEDwuTvKyXagcLcCFQCtiY7fnapNO3kFBOfZKGFB
+CsjaKwKBgQCOCBKbrH/BteJAh5kbZx1zNrRuRFiQ5lukLcI6r1qdRilMeVhctbVV
+kfZ5eay9A4vpDXRDaPkpCo+4d7g7pRjiOk9JkGG1dodSCvhTDhpzqr2fHjUxNp+D
+xk6OabmetywZvkGK0LKzYlGOL2pCxUNqxCv0i8HbAxSuGUiQgUMOcwOBhAACgYBj
+M6k+aHwl7UgNq4ReGBovPXjCphQcdyuPZVZUnp9GbwaF1AUlIjsZSTTymAplIqJz
+aU2rG7Nbv+8XEpD+e/N/K1jXpv7aL4FHhDrK8zMJ5sTWEdWDQm5PB9QzCgUQ6Fg/
+pnAdJSJCX0gEwf1M0kIzBgzF9j5U6tREWyMZNFSCnKOBgzCBgDAdBgNVHQ4EFgQU
+VhpVXqQ/EzUMdxLvP7o9EhJ8h70wHwYDVR0jBBgwFoAUE89Lp7uJLrM4Vxd2xput
+aFvl7RcwDAYDVR0TAQH/BAIwADAOBgNVHQ8BAf8EBAMCBsAwIAYDVR0RBBkwF4EV
+c21pbWVkc2EzQG9wZW5zc2wub3JnMA0GCSqGSIb3DQEBBQUAA4GBACM9e75EQa8m
+k/AZkH/tROqf3yeqijULl9x8FjFatqoY+29OM6oMGM425IqSkKd2ipz7OxO0SShu
+rE0O3edS7DvYBwvhWPviRaYBMyZ4iFJVup+fOzoYK/j/bASxS3BHQBwb2r4rhe25
+OlTyyFEk7DJyW18YFOG97S1P52oQ5f5x
+-----END CERTIFICATE-----
diff --git a/deps/openssl/openssl/test/smime-certs/smdsap.pem b/deps/openssl/openssl/test/smime-certs/smdsap.pem
new file mode 100644 (file)
index 0000000..249706c
--- /dev/null
@@ -0,0 +1,9 @@
+-----BEGIN DSA PARAMETERS-----
+MIIBHwKBgQDFJfsIPOIawMO5biw+AoYUhNVxReBOLQosU3Qv4B8krac0BNr3OjSG
+Lh1wZxHqhlAE0QmasTaKojuk20nNWeFnczSz6vDl0IVJEhS8VYor5kt9gLqtGcoA
+gsf4gRDIutJyQDaNn3IVY89uXUVIoexvQeLQDBCgQPC5O8rJdqBwtwIVAK2Jjt+d
+qk07eQUE59koYUEKyNorAoGBAI4IEpusf8G14kCHmRtnHXM2tG5EWJDmW6Qtwjqv
+Wp1GKUx5WFy1tVWR9nl5rL0Di+kNdENo+SkKj7h3uDulGOI6T0mQYbV2h1IK+FMO
+GnOqvZ8eNTE2n4PGTo5puZ63LBm+QYrQsrNiUY4vakLFQ2rEK/SLwdsDFK4ZSJCB
+Qw5z
+-----END DSA PARAMETERS-----
diff --git a/deps/openssl/openssl/test/smime-certs/smroot.pem b/deps/openssl/openssl/test/smime-certs/smroot.pem
new file mode 100644 (file)
index 0000000..a59eb26
--- /dev/null
@@ -0,0 +1,30 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICXAIBAAKBgQDBV1Z/Q5gPF7lojc8pKUdyz5+Jf2B3vs4he6egekugWnoJduki
+9Lnae/JchB/soIX0co3nLc11NuFFlnAWJNMDJr08l5AHAJLYNHevF5l/f9oDQwvZ
+speKh1xpIAJNqCTzVeQ/ZLx6/GccIXV/xDuKIiovqJTPgR5WPkYKaw++lQIDAQAB
+AoGALXnUj5SflJU4+B2652ydMKUjWl0KnL/VjkyejgGV/j6py8Ybaixz9q8Gv7oY
+JDlRqMC1HfZJCFQDQrHy5VJ+CywA/H9WrqKo/Ch9U4tJAZtkig1Cmay/BAYixVu0
+xBeim10aKF6hxHH4Chg9We+OCuzWBWJhqveNjuDedL/i7JUCQQDlejovcwBUCbhJ
+U12qKOwlaboolWbl7yF3XdckTJZg7+1UqQHZH5jYZlLZyZxiaC92SNV0SyTLJZnS
+Jh5CO+VDAkEA16/pPcuVtMMz/R6SSPpRSIAa1stLs0mFSs3NpR4pdm0n42mu05pO
+1tJEt3a1g7zkreQBf53+Dwb+lA841EkjRwJBAIFmt0DifKDnCkBu/jZh9SfzwsH3
+3Zpzik+hXxxdA7+ODCrdUul449vDd5zQD5t+XKU61QNLDGhxv5e9XvrCg7kCQH/a
+3ldsVF0oDaxxL+QkxoREtCQ5tLEd1u7F2q6Tl56FDE0pe6Ih6bQ8RtG+g9EI60IN
+U7oTrOO5kLWx5E0q4ccCQAZVgoenn9MhRU1agKOCuM6LT2DxReTu4XztJzynej+8
+0J93n3ebanB1MlRpn1XJwhQ7gAC8ImaQKLJK5jdJzFc=
+-----END RSA PRIVATE KEY-----
+-----BEGIN CERTIFICATE-----
+MIICaTCCAdKgAwIBAgIJAP6VN47boiXRMA0GCSqGSIb3DQEBBQUAMEQxCzAJBgNV
+BAYTAlVLMRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMR0wGwYDVQQDExRUZXN0IFMv
+TUlNRSBSU0EgUm9vdDAeFw0wODAyMjIxMzUzMDdaFw0xNjA1MTExMzUzMDdaMEQx
+CzAJBgNVBAYTAlVLMRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMR0wGwYDVQQDExRU
+ZXN0IFMvTUlNRSBSU0EgUm9vdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA
+wVdWf0OYDxe5aI3PKSlHcs+fiX9gd77OIXunoHpLoFp6CXbpIvS52nvyXIQf7KCF
+9HKN5y3NdTbhRZZwFiTTAya9PJeQBwCS2DR3rxeZf3/aA0ML2bKXiodcaSACTagk
+81XkP2S8evxnHCF1f8Q7iiIqL6iUz4EeVj5GCmsPvpUCAwEAAaNjMGEwHQYDVR0O
+BBYEFBPPS6e7iS6zOFcXdsabrWhb5e0XMB8GA1UdIwQYMBaAFBPPS6e7iS6zOFcX
+dsabrWhb5e0XMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEGMA0GCSqG
+SIb3DQEBBQUAA4GBAIECprq5viDvnDbkyOaiSr9ubMUmWqvycfAJMdPZRKcOZczS
+l+L9R9lF3JSqbt3knOe9u6bGDBOTY2285PdCCuHRVMk2Af1f6El1fqAlRUwNqipp
+r68sWFuRqrcRNtk6QQvXfkOhrqQBuDa7te/OVQLa2lGN9Dr2mQsD8ijctatG
+-----END CERTIFICATE-----
diff --git a/deps/openssl/openssl/test/smime-certs/smrsa1.pem b/deps/openssl/openssl/test/smime-certs/smrsa1.pem
new file mode 100644 (file)
index 0000000..2cf3148
--- /dev/null
@@ -0,0 +1,31 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICXgIBAAKBgQC6A978j4pmPgUtUQqF+bjh6vdhwGOGZSD7xXgFTMjm88twfv+E
+ixkq2KXSDjD0ZXoQbdOaSbvGRQrIJpG2NGiKAFdYNrP025kCCdh5wF/aEI7KLEm7
+JlHwXpQsuj4wkMgmkFjL3Ty4Z55aNH+2pPQIa0k+ENJXm2gDuhqgBmduAwIDAQAB
+AoGBAJMuYu51aO2THyeHGwt81uOytcCbqGP7eoib62ZOJhxPRGYjpmuqX+R9/V5i
+KiwGavm63JYUx0WO9YP+uIZxm1BUATzkgkS74u5LP6ajhkZh6/Bck1oIYYkbVOXl
+JVrdENuH6U7nupznsyYgONByo+ykFPVUGmutgiaC7NMVo/MxAkEA6KLejWXdCIEn
+xr7hGph9NlvY9xuRIMexRV/WrddcFfCdjI1PciIupgrIkR65M9yr7atm1iU6/aRf
+KOr8rLZsSQJBAMyyXN71NsDNx4BP6rtJ/LJMP0BylznWkA7zWfGCbAYn9VhZVlSY
+Eu9Gyr7quD1ix7G3kInKVYOEEOpockBLz+sCQQCedyMmKjcQLfpMVYW8uhbAynvW
+h36qV5yXZxszO7nMcCTBsxhk5IfmLv5EbCs3+p9avCDGyoGOeUMg+kC33WORAkAg
+oUIarH4o5+SoeJTTfCzTA0KF9H5U0vYt2+73h7HOnWoHxl3zqDZEfEVvf50U8/0f
+QELDJETTbScBJtsnkq43AkEA38etvoZ2i4FJvvo7R/9gWBHVEcrGzcsCBYrNnIR1
+SZLRwHEGaiOK1wxMsWzqp7PJwL9z/M8A8DyOFBx3GPOniA==
+-----END RSA PRIVATE KEY-----
+-----BEGIN CERTIFICATE-----
+MIICizCCAfSgAwIBAgIJAMtotfHYdEsTMA0GCSqGSIb3DQEBBQUAMEQxCzAJBgNV
+BAYTAlVLMRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMR0wGwYDVQQDExRUZXN0IFMv
+TUlNRSBSU0EgUm9vdDAeFw0wODAyMjIxMzUzMDhaFw0xNjA1MTAxMzUzMDhaMEUx
+CzAJBgNVBAYTAlVLMRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMR4wHAYDVQQDDBVU
+ZXN0IFMvTUlNRSBFRSBSU0EgIzEwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB
+ALoD3vyPimY+BS1RCoX5uOHq92HAY4ZlIPvFeAVMyObzy3B+/4SLGSrYpdIOMPRl
+ehBt05pJu8ZFCsgmkbY0aIoAV1g2s/TbmQIJ2HnAX9oQjsosSbsmUfBelCy6PjCQ
+yCaQWMvdPLhnnlo0f7ak9AhrST4Q0lebaAO6GqAGZ24DAgMBAAGjgYMwgYAwHQYD
+VR0OBBYEFE2vMvKz5jrC7Lbdg68XwZ95iL/QMB8GA1UdIwQYMBaAFBPPS6e7iS6z
+OFcXdsabrWhb5e0XMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgXgMCAGA1Ud
+EQQZMBeBFXNtaW1lcnNhMUBvcGVuc3NsLm9yZzANBgkqhkiG9w0BAQUFAAOBgQAi
+O3GOkUl646oLnOimc36i9wxZ1tejsqs8vMjJ0Pym6Uq9FE2JoGzJ6OhB1GOsEVmj
+9cQ5UNQcRYL3cqOFtl6f4Dpu/lhzfbaqgmLjv29G1mS0uuTZrixhlyCXjwcbOkNC
+I/+wvHHENYIK5+T/79M9LaZ2Qk4F9MNE1VMljdz9Qw==
+-----END CERTIFICATE-----
diff --git a/deps/openssl/openssl/test/smime-certs/smrsa2.pem b/deps/openssl/openssl/test/smime-certs/smrsa2.pem
new file mode 100644 (file)
index 0000000..d41f69c
--- /dev/null
@@ -0,0 +1,31 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICWwIBAAKBgQCwBfryW4Vu5U9wNIDKspJO/N9YF4CcTlrCUyzVlKgb+8urHlSe
+59i5verR9IOCCXkemjOzZ/3nALTGqYZlnEvHp0Rjk+KdKXnKBIB+SRPpeu3LcXMT
+WPgsThPa0UQxedNKG0g6aG+kLhsDlFBCoxd09jJtSpb9jmroJOq0ZYEHLwIDAQAB
+AoGAKa/w4677Je1W5+r3SYoLDnvi5TkDs4D3C6ipKJgBTEdQz+DqB4w/DpZE4551
++rkFn1LDxcxuHGRVa+tAMhZW97fwq9YUbjVZEyOz79qrX+BMyl/NbHkf1lIKDo3q
+dWalzQvop7nbzeLC+VmmviwZfLQUbA61AQl3jm4dswT4XykCQQDloDadEv/28NTx
+bvvywvyGuvJkCkEIycm4JrIInvwsd76h/chZ3oymrqzc7hkEtK6kThqlS5y+WXl6
+QzPruTKTAkEAxD2ro/VUoN+scIVaLmn0RBmZ67+9Pdn6pNSfjlK3s0T0EM6/iUWS
+M06l6L9wFS3/ceu1tIifsh9BeqOGTa+udQJARIFnybTBaIqw/NZ/lA1YCVn8tpvY
+iyaoZ6gjtS65TQrsdKeh/i3HCHNUXxUpoZ3F/H7QtD+6o49ODou+EbVOwQJAVmex
+A2gp8wuJKaINqxIL81AybZLnCCzKJ3lXJ5tUNyLNM/lUbGStktm2Q1zHRQwTxV07
+jFn7trn8YrtNjzcjYQJAUKIJRt38A8Jw3HoPT+D0WS2IgxjVL0eYGsZX1lyeammG
+6rfnQ3u5uP7mEK2EH2o8mDUpAE0gclWBU9UkKxJsGA==
+-----END RSA PRIVATE KEY-----
+-----BEGIN CERTIFICATE-----
+MIICizCCAfSgAwIBAgIJAMtotfHYdEsUMA0GCSqGSIb3DQEBBQUAMEQxCzAJBgNV
+BAYTAlVLMRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMR0wGwYDVQQDExRUZXN0IFMv
+TUlNRSBSU0EgUm9vdDAeFw0wODAyMjIxMzUzMDhaFw0xNjA1MTAxMzUzMDhaMEUx
+CzAJBgNVBAYTAlVLMRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMR4wHAYDVQQDDBVU
+ZXN0IFMvTUlNRSBFRSBSU0EgIzIwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB
+ALAF+vJbhW7lT3A0gMqykk7831gXgJxOWsJTLNWUqBv7y6seVJ7n2Lm96tH0g4IJ
+eR6aM7Nn/ecAtMaphmWcS8enRGOT4p0pecoEgH5JE+l67ctxcxNY+CxOE9rRRDF5
+00obSDpob6QuGwOUUEKjF3T2Mm1Klv2Oaugk6rRlgQcvAgMBAAGjgYMwgYAwHQYD
+VR0OBBYEFIL/u+mEvaw7RuKLRuElfVkxSQjYMB8GA1UdIwQYMBaAFBPPS6e7iS6z
+OFcXdsabrWhb5e0XMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgXgMCAGA1Ud
+EQQZMBeBFXNtaW1lcnNhMkBvcGVuc3NsLm9yZzANBgkqhkiG9w0BAQUFAAOBgQC2
+rXR5bm/9RtOMQPleNpd3y6uUX3oy+0CafK5Yl3PMnItjjnKJ0l1/DbLbDj2twehe
+ewaB8CROcBCA3AMLSmGvPKgUCFMGtWam3328M4fBHzon5ka7qDXzM+imkAly/Yx2
+YNdR/aNOug+5sXygHmTSKqiCpQjOIClzXoPVVeEVHw==
+-----END CERTIFICATE-----
diff --git a/deps/openssl/openssl/test/smime-certs/smrsa3.pem b/deps/openssl/openssl/test/smime-certs/smrsa3.pem
new file mode 100644 (file)
index 0000000..c8cbe55
--- /dev/null
@@ -0,0 +1,31 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICXAIBAAKBgQC6syTZtZNe1hRScFc4PUVyVLsr7+C1HDIZnOHmwFoLayX6RHwy
+ep/TkdwiPHnemVLuwvpSjLMLZkXy/J764kSHJrNeVl3UvmCVCOm40hAtK1+F39pM
+h8phkbPPD7i+hwq4/Vs79o46nzwbVKmzgoZBJhZ+codujUSYM3LjJ4aq+wIDAQAB
+AoGAE1Zixrnr3bLGwBMqtYSDIOhtyos59whImCaLr17U9MHQWS+mvYO98if1aQZi
+iQ/QazJ+wvYXxWJ+dEB+JvYwqrGeuAU6He/rAb4OShG4FPVU2D19gzRnaButWMeT
+/1lgXV08hegGBL7RQNaN7b0viFYMcKnSghleMP0/q+Y/oaECQQDkXEwDYJW13X9p
+ijS20ykWdY5lLknjkHRhhOYux0rlhOqsyMZjoUmwI2m0qj9yrIysKhrk4MZaM/uC
+hy0xp3hdAkEA0Uv/UY0Kwsgc+W6YxeypECtg1qCE6FBib8n4iFy/6VcWqhvE5xrs
+OdhKv9/p6aLjLneGd1sU+F8eS9LGyKIbNwJBAJPgbNzXA7uUZriqZb5qeTXxBDfj
+RLfXSHYKAKEULxz3+JvRHB9SR4yHMiFrCdExiZrHXUkPgYLSHLGG5a4824UCQD6T
+9XvhquUARkGCAuWy0/3Eqoihp/t6BWSdQ9Upviu7YUhtUxsyXo0REZB7F4pGrJx5
+GlhXgFaewgUzuUHFzlMCQCzJMMWslWpoLntnR6sMhBMhBFHSw+Y5CbxBmFrdtSkd
+VdtNO1VuDCTxjjW7W3Khj7LX4KZ1ye/5jfAgnnnXisc=
+-----END RSA PRIVATE KEY-----
+-----BEGIN CERTIFICATE-----
+MIICizCCAfSgAwIBAgIJAMtotfHYdEsVMA0GCSqGSIb3DQEBBQUAMEQxCzAJBgNV
+BAYTAlVLMRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMR0wGwYDVQQDExRUZXN0IFMv
+TUlNRSBSU0EgUm9vdDAeFw0wODAyMjIxMzUzMDlaFw0xNjA1MTAxMzUzMDlaMEUx
+CzAJBgNVBAYTAlVLMRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMR4wHAYDVQQDDBVU
+ZXN0IFMvTUlNRSBFRSBSU0EgIzMwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB
+ALqzJNm1k17WFFJwVzg9RXJUuyvv4LUcMhmc4ebAWgtrJfpEfDJ6n9OR3CI8ed6Z
+Uu7C+lKMswtmRfL8nvriRIcms15WXdS+YJUI6bjSEC0rX4Xf2kyHymGRs88PuL6H
+Crj9Wzv2jjqfPBtUqbOChkEmFn5yh26NRJgzcuMnhqr7AgMBAAGjgYMwgYAwHQYD
+VR0OBBYEFDsSFjNtYZzd0tTHafNS7tneQQj6MB8GA1UdIwQYMBaAFBPPS6e7iS6z
+OFcXdsabrWhb5e0XMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgXgMCAGA1Ud
+EQQZMBeBFXNtaW1lcnNhM0BvcGVuc3NsLm9yZzANBgkqhkiG9w0BAQUFAAOBgQBE
+tUDB+1Dqigu4p1xtdq7JRK6S+gfA7RWmhz0j2scb2zhpS12h37JLHsidGeKAzZYq
+jUjOrH/j3xcV5AnuJoqImJaN23nzzxtR4qGGX2mrq6EtObzdEGgCUaizsGM+0slJ
+PYxcy8KeY/63B1BpYhj2RjGkL6HrvuAaxVORa3acoA==
+-----END CERTIFICATE-----
diff --git a/deps/openssl/openssl/test/ssltest.c b/deps/openssl/openssl/test/ssltest.c
new file mode 120000 (symlink)
index 0000000..40191f0
--- /dev/null
@@ -0,0 +1 @@
+../ssl/ssltest.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/test/tcrl b/deps/openssl/openssl/test/tcrl
new file mode 100644 (file)
index 0000000..055269e
--- /dev/null
@@ -0,0 +1,78 @@
+#!/bin/sh
+
+cmd='../util/shlib_wrap.sh ../apps/openssl crl'
+
+if [ "$1"x != "x" ]; then
+       t=$1
+else
+       t=testcrl.pem
+fi
+
+echo testing crl conversions
+cp $t fff.p
+
+echo "p -> d"
+$cmd -in fff.p -inform p -outform d >f.d
+if [ $? != 0 ]; then exit 1; fi
+#echo "p -> t"
+#$cmd -in fff.p -inform p -outform t >f.t
+#if [ $? != 0 ]; then exit 1; fi
+echo "p -> p"
+$cmd -in fff.p -inform p -outform p >f.p
+if [ $? != 0 ]; then exit 1; fi
+
+echo "d -> d"
+$cmd -in f.d -inform d -outform d >ff.d1
+if [ $? != 0 ]; then exit 1; fi
+#echo "t -> d"
+#$cmd -in f.t -inform t -outform d >ff.d2
+#if [ $? != 0 ]; then exit 1; fi
+echo "p -> d"
+$cmd -in f.p -inform p -outform d >ff.d3
+if [ $? != 0 ]; then exit 1; fi
+
+#echo "d -> t"
+#$cmd -in f.d -inform d -outform t >ff.t1
+#if [ $? != 0 ]; then exit 1; fi
+#echo "t -> t"
+#$cmd -in f.t -inform t -outform t >ff.t2
+#if [ $? != 0 ]; then exit 1; fi
+#echo "p -> t"
+#$cmd -in f.p -inform p -outform t >ff.t3
+#if [ $? != 0 ]; then exit 1; fi
+
+echo "d -> p"
+$cmd -in f.d -inform d -outform p >ff.p1
+if [ $? != 0 ]; then exit 1; fi
+#echo "t -> p"
+#$cmd -in f.t -inform t -outform p >ff.p2
+#if [ $? != 0 ]; then exit 1; fi
+echo "p -> p"
+$cmd -in f.p -inform p -outform p >ff.p3
+if [ $? != 0 ]; then exit 1; fi
+
+cmp fff.p f.p
+if [ $? != 0 ]; then exit 1; fi
+cmp fff.p ff.p1
+if [ $? != 0 ]; then exit 1; fi
+#cmp fff.p ff.p2
+#if [ $? != 0 ]; then exit 1; fi
+cmp fff.p ff.p3
+if [ $? != 0 ]; then exit 1; fi
+
+#cmp f.t ff.t1
+#if [ $? != 0 ]; then exit 1; fi
+#cmp f.t ff.t2
+#if [ $? != 0 ]; then exit 1; fi
+#cmp f.t ff.t3
+#if [ $? != 0 ]; then exit 1; fi
+
+cmp f.p ff.p1
+if [ $? != 0 ]; then exit 1; fi
+#cmp f.p ff.p2
+#if [ $? != 0 ]; then exit 1; fi
+cmp f.p ff.p3
+if [ $? != 0 ]; then exit 1; fi
+
+/bin/rm -f f.* ff.* fff.*
+exit 0
diff --git a/deps/openssl/openssl/test/tcrl.com b/deps/openssl/openssl/test/tcrl.com
new file mode 100644 (file)
index 0000000..dd96a2b
--- /dev/null
@@ -0,0 +1,88 @@
+$! TCRL.COM  --  Tests crl keys
+$
+$      __arch = "VAX"
+$      if f$getsyi("cpu") .ge. 128 then -
+          __arch = f$edit( f$getsyi( "ARCH_NAME"), "UPCASE")
+$      if __arch .eqs. "" then __arch = "UNK"
+$!
+$      if (p2 .eqs. "64") then __arch = __arch+ "_64"
+$!
+$      exe_dir = "sys$disk:[-.''__arch'.exe.apps]"
+$
+$      cmd = "mcr ''exe_dir'openssl crl"
+$
+$      t = "testcrl.pem"
+$      if p1 .nes. "" then t = p1
+$
+$      write sys$output "testing CRL conversions"
+$      if f$search("fff.*") .nes "" then delete fff.*;*
+$      if f$search("ff.*") .nes "" then delete ff.*;*
+$      if f$search("f.*") .nes "" then delete f.*;*
+$      convert/fdl=sys$input: 't' fff.p
+RECORD
+       FORMAT STREAM_LF
+$
+$      write sys$output "p -> d"
+$      'cmd' -in fff.p -inform p -outform d -out f.d
+$      if $severity .ne. 1 then exit 3
+$!     write sys$output "p -> t"
+$!     'cmd' -in fff.p -inform p -outform t -out f.t
+$!     if $severity .ne. 1 then exit 3
+$      write sys$output "p -> p"
+$      'cmd' -in fff.p -inform p -outform p -out f.p
+$      if $severity .ne. 1 then exit 3
+$
+$      write sys$output "d -> d"
+$      'cmd' -in f.d -inform d -outform d -out ff.d1
+$      if $severity .ne. 1 then exit 3
+$!     write sys$output "t -> d"
+$!     'cmd' -in f.t -inform t -outform d -out ff.d2
+$!     if $severity .ne. 1 then exit 3
+$      write sys$output "p -> d"
+$      'cmd' -in f.p -inform p -outform d -out ff.d3
+$      if $severity .ne. 1 then exit 3
+$
+$!     write sys$output "d -> t"
+$!     'cmd' -in f.d -inform d -outform t -out ff.t1
+$!     if $severity .ne. 1 then exit 3
+$!     write sys$output "t -> t"
+$!     'cmd' -in f.t -inform t -outform t -out ff.t2
+$!     if $severity .ne. 1 then exit 3
+$!     write sys$output "p -> t"
+$!     'cmd' -in f.p -inform p -outform t -out ff.t3
+$!     if $severity .ne. 1 then exit 3
+$
+$      write sys$output "d -> p"
+$      'cmd' -in f.d -inform d -outform p -out ff.p1
+$      if $severity .ne. 1 then exit 3
+$!     write sys$output "t -> p"
+$!     'cmd' -in f.t -inform t -outform p -out ff.p2
+$!     if $severity .ne. 1 then exit 3
+$      write sys$output "p -> p"
+$      'cmd' -in f.p -inform p -outform p -out ff.p3
+$      if $severity .ne. 1 then exit 3
+$
+$      backup/compare fff.p f.p
+$      if $severity .ne. 1 then exit 3
+$      backup/compare fff.p ff.p1
+$      if $severity .ne. 1 then exit 3
+$!     backup/compare fff.p ff.p2
+$!     if $severity .ne. 1 then exit 3
+$      backup/compare fff.p ff.p3
+$      if $severity .ne. 1 then exit 3
+$
+$!     backup/compare f.t ff.t1
+$!     if $severity .ne. 1 then exit 3
+$!     backup/compare f.t ff.t2
+$!     if $severity .ne. 1 then exit 3
+$!     backup/compare f.t ff.t3
+$!     if $severity .ne. 1 then exit 3
+$
+$      backup/compare f.p ff.p1
+$      if $severity .ne. 1 then exit 3
+$!     backup/compare f.p ff.p2
+$!     if $severity .ne. 1 then exit 3
+$      backup/compare f.p ff.p3
+$      if $severity .ne. 1 then exit 3
+$
+$      delete f.*;*,ff.*;*,fff.*;*
diff --git a/deps/openssl/openssl/test/test.cnf b/deps/openssl/openssl/test/test.cnf
new file mode 100644 (file)
index 0000000..faad391
--- /dev/null
@@ -0,0 +1,88 @@
+#
+# SSLeay example configuration file.
+# This is mostly being used for generation of certificate requests.
+#
+
+RANDFILE               = ./.rnd
+
+####################################################################
+[ ca ]
+default_ca     = CA_default            # The default ca section
+
+####################################################################
+[ CA_default ]
+
+dir            = ./demoCA              # Where everything is kept
+certs          = $dir/certs            # Where the issued certs are kept
+crl_dir                = $dir/crl              # Where the issued crl are kept
+database       = $dir/index.txt        # database index file.
+new_certs_dir  = $dir/new_certs        # default place for new certs.
+
+certificate    = $dir/CAcert.pem       # The CA certificate
+serial         = $dir/serial           # The current serial number
+crl            = $dir/crl.pem          # The current CRL
+private_key    = $dir/private/CAkey.pem# The private key
+RANDFILE       = $dir/private/.rand    # private random number file
+
+default_days   = 365                   # how long to certify for
+default_crl_days= 30                   # how long before next CRL
+default_md     = md5                   # which md to use.
+
+# A few difference way of specifying how similar the request should look
+# For type CA, the listed attributes must be the same, and the optional
+# and supplied fields are just that :-)
+policy         = policy_match
+
+# For the CA policy
+[ policy_match ]
+countryName            = match
+stateOrProvinceName    = match
+organizationName       = match
+organizationalUnitName = optional
+commonName             = supplied
+emailAddress           = optional
+
+# For the 'anything' policy
+# At this point in time, you must list all acceptable 'object'
+# types.
+[ policy_anything ]
+countryName            = optional
+stateOrProvinceName    = optional
+localityName           = optional
+organizationName       = optional
+organizationalUnitName = optional
+commonName             = supplied
+emailAddress           = optional
+
+####################################################################
+[ req ]
+default_bits           = 512
+default_keyfile        = testkey.pem
+distinguished_name     = req_distinguished_name
+encrypt_rsa_key                = no
+
+[ req_distinguished_name ]
+countryName                    = Country Name (2 letter code)
+countryName_default            = AU
+countryName_value              = AU
+
+stateOrProvinceName            = State or Province Name (full name)
+stateOrProvinceName_default    = Queensland
+stateOrProvinceName_value      =
+
+localityName                   = Locality Name (eg, city)
+localityName_value             = Brisbane
+
+organizationName               = Organization Name (eg, company)
+organizationName_default       = 
+organizationName_value         = CryptSoft Pty Ltd
+
+organizationalUnitName         = Organizational Unit Name (eg, section)
+organizationalUnitName_default =
+organizationalUnitName_value   = .
+
+commonName                     = Common Name (eg, YOUR name)
+commonName_value               = Eric Young
+
+emailAddress                   = Email Address
+emailAddress_value             = eay@mincom.oz.au
diff --git a/deps/openssl/openssl/test/test_padlock b/deps/openssl/openssl/test/test_padlock
new file mode 100644 (file)
index 0000000..5c0f210
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/sh
+
+PROG=$1
+
+if [ -x $PROG ]; then
+    if expr "x`$PROG version`" : "xOpenSSL" > /dev/null; then
+       :
+    else
+       echo "$PROG is not OpenSSL executable"
+       exit 1
+    fi
+else
+    echo "$PROG is not executable"
+    exit 1;
+fi
+
+if $PROG engine padlock | grep -v no-ACE; then
+
+    HASH=`cat $PROG | $PROG dgst -hex`
+
+    ACE_ALGS=" aes-128-ecb aes-192-ecb aes-256-ecb \
+               aes-128-cbc aes-192-cbc aes-256-cbc \
+               aes-128-cfb aes-192-cfb aes-256-cfb \
+               aes-128-ofb aes-192-ofb aes-256-ofb"
+
+    nerr=0
+
+    for alg in $ACE_ALGS; do
+       echo $alg
+       TEST=`( cat $PROG | \
+               $PROG enc -e -k "$HASH" -$alg -bufsize 999 -engine padlock | \
+               $PROG enc -d -k "$HASH" -$alg | \
+               $PROG dgst -hex ) 2>/dev/null`
+       if [ "$TEST" != "$HASH" ]; then
+               echo "-$alg encrypt test failed"
+               nerr=`expr $nerr + 1`
+       fi
+       TEST=`( cat $PROG | \
+               $PROG enc -e -k "$HASH" -$alg | \
+               $PROG enc -d -k "$HASH" -$alg -bufsize 999 -engine padlock | \
+               $PROG dgst -hex ) 2>/dev/null`
+       if [ "$TEST" != "$HASH" ]; then
+               echo "-$alg decrypt test failed"
+               nerr=`expr $nerr + 1`
+       fi
+       TEST=`( cat $PROG | \
+               $PROG enc -e -k "$HASH" -$alg -engine padlock | \
+               $PROG enc -d -k "$HASH" -$alg -engine padlock | \
+               $PROG dgst -hex ) 2>/dev/null`
+       if [ "$TEST" != "$HASH" ]; then
+               echo "-$alg en/decrypt test failed"
+               nerr=`expr $nerr + 1`
+       fi
+    done
+
+    if [ $nerr -gt 0 ]; then
+       echo "PadLock ACE test failed."
+       exit 1;
+    fi
+else
+    echo "PadLock ACE is not available"
+fi
+
+exit 0
diff --git a/deps/openssl/openssl/test/testca b/deps/openssl/openssl/test/testca
new file mode 100644 (file)
index 0000000..b109cfe
--- /dev/null
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+SH="/bin/sh"
+if test "$OSTYPE" = msdosdjgpp; then
+    PATH="../apps\;$PATH"
+else
+    PATH="../apps:$PATH"
+fi
+export SH PATH
+
+SSLEAY_CONFIG="-config CAss.cnf"
+export SSLEAY_CONFIG
+
+OPENSSL="`pwd`/../util/opensslwrap.sh"
+export OPENSSL
+
+/bin/rm -fr demoCA
+$SH ../apps/CA.sh -newca <<EOF
+EOF
+
+if [ $? != 0 ]; then
+       exit 1;
+fi
+
+SSLEAY_CONFIG="-config Uss.cnf"
+export SSLEAY_CONFIG
+$SH ../apps/CA.sh -newreq
+if [ $? != 0 ]; then
+       exit 1;
+fi
+
+
+SSLEAY_CONFIG="-config ../apps/openssl.cnf"
+export SSLEAY_CONFIG
+$SH ../apps/CA.sh -sign  <<EOF
+y
+y
+EOF
+if [ $? != 0 ]; then
+       exit 1;
+fi
+
+
+$SH ../apps/CA.sh -verify newcert.pem
+if [ $? != 0 ]; then
+       exit 1;
+fi
+
+/bin/rm -fr demoCA newcert.pem newreq.pem
+#usage: CA -newcert|-newreq|-newca|-sign|-verify
+
diff --git a/deps/openssl/openssl/test/testca.com b/deps/openssl/openssl/test/testca.com
new file mode 100644 (file)
index 0000000..78cda9e
--- /dev/null
@@ -0,0 +1,52 @@
+$! TESTCA.COM
+$
+$      __arch = "VAX"
+$      if f$getsyi("cpu") .ge. 128 then -
+          __arch = f$edit( f$getsyi( "ARCH_NAME"), "UPCASE")
+$      if __arch .eqs. "" then __arch = "UNK"
+$!
+$       if (p1 .eqs. "64") then __arch = __arch+ "_64"
+$
+$      openssl = "mcr ''exe_dir'openssl"
+$
+$      SSLEAY_CONFIG="-config ""CAss.cnf"""
+$
+$      set noon
+$      if f$search("demoCA.dir") .nes. ""
+$      then
+$          @[-.util]deltree [.demoCA]*.*
+$          set file/prot=(S:RWED,O:RWED,G:RWED,W:RWED) demoCA.dir;*
+$          delete demoCA.dir;*
+$      endif
+$      set on
+$      open/read sys$ca_input VMSca-response.1
+$      @[-.apps]CA.com -input sys$ca_input -newca
+$      close sys$ca_input
+$      if $severity .ne. 1 then exit 3
+$
+$
+$      SSLEAY_CONFIG="-config ""Uss.cnf"""
+$      @[-.apps]CA.com -newreq
+$      if $severity .ne. 1 then exit 3
+$
+$
+$      SSLEAY_CONFIG="-config [-.apps]openssl-vms.cnf"
+$      open/read sys$ca_input VMSca-response.2
+$      @[-.apps]CA.com -input sys$ca_input -sign
+$      close sys$ca_input
+$      if $severity .ne. 1 then exit 3
+$
+$
+$      @[-.apps]CA.com -verify newcert.pem
+$      if $severity .ne. 1 then exit 3
+$
+$      set noon
+$      @[-.util]deltree [.demoCA]*.*
+$      set file/prot=(S:RWED,O:RWED,G:RWED,W:RWED) demoCA.dir;*
+$      delete demoCA.dir;*
+$      if f$search("newcert.pem") .nes. "" then delete newcert.pem;*
+$      if f$search("newcert.pem") .nes. "" then delete newreq.pem;*
+$      set on
+$!     #usage: CA -newcert|-newreq|-newca|-sign|-verify
+$
+$      exit
diff --git a/deps/openssl/openssl/test/testcrl.pem b/deps/openssl/openssl/test/testcrl.pem
new file mode 100644 (file)
index 0000000..0989788
--- /dev/null
@@ -0,0 +1,16 @@
+-----BEGIN X509 CRL-----
+MIICjTCCAfowDQYJKoZIhvcNAQECBQAwXzELMAkGA1UEBhMCVVMxIDAeBgNVBAoT
+F1JTQSBEYXRhIFNlY3VyaXR5LCBJbmMuMS4wLAYDVQQLEyVTZWN1cmUgU2VydmVy
+IENlcnRpZmljYXRpb24gQXV0aG9yaXR5Fw05NTA1MDIwMjEyMjZaFw05NTA2MDEw
+MDAxNDlaMIIBaDAWAgUCQQAABBcNOTUwMjAxMTcyNDI2WjAWAgUCQQAACRcNOTUw
+MjEwMDIxNjM5WjAWAgUCQQAADxcNOTUwMjI0MDAxMjQ5WjAWAgUCQQAADBcNOTUw
+MjI1MDA0NjQ0WjAWAgUCQQAAGxcNOTUwMzEzMTg0MDQ5WjAWAgUCQQAAFhcNOTUw
+MzE1MTkxNjU0WjAWAgUCQQAAGhcNOTUwMzE1MTk0MDQxWjAWAgUCQQAAHxcNOTUw
+MzI0MTk0NDMzWjAWAgUCcgAABRcNOTUwMzI5MjAwNzExWjAWAgUCcgAAERcNOTUw
+MzMwMDIzNDI2WjAWAgUCQQAAIBcNOTUwNDA3MDExMzIxWjAWAgUCcgAAHhcNOTUw
+NDA4MDAwMjU5WjAWAgUCcgAAQRcNOTUwNDI4MTcxNzI0WjAWAgUCcgAAOBcNOTUw
+NDI4MTcyNzIxWjAWAgUCcgAATBcNOTUwNTAyMDIxMjI2WjANBgkqhkiG9w0BAQIF
+AAN+AHqOEJXSDejYy0UwxxrH/9+N2z5xu/if0J6qQmK92W0hW158wpJg+ovV3+wQ
+wvIEPRL2rocL0tKfAsVq1IawSJzSNgxG0lrcla3MrJBnZ4GaZDu4FutZh72MR3Gt
+JaAL3iTJHJD55kK2D/VoyY1djlsPuNh6AEgdVwFAyp0v
+-----END X509 CRL-----
diff --git a/deps/openssl/openssl/test/testenc b/deps/openssl/openssl/test/testenc
new file mode 100644 (file)
index 0000000..f5ce7c0
--- /dev/null
@@ -0,0 +1,54 @@
+#!/bin/sh
+
+testsrc=Makefile
+test=./p
+cmd="../util/shlib_wrap.sh ../apps/openssl"
+
+cat $testsrc >$test;
+
+echo cat
+$cmd enc < $test > $test.cipher
+$cmd enc < $test.cipher >$test.clear
+cmp $test $test.clear
+if [ $? != 0 ]
+then
+       exit 1
+else
+       /bin/rm $test.cipher $test.clear
+fi
+echo base64
+$cmd enc -a -e < $test > $test.cipher
+$cmd enc -a -d < $test.cipher >$test.clear
+cmp $test $test.clear
+if [ $? != 0 ]
+then
+       exit 1
+else
+       /bin/rm $test.cipher $test.clear
+fi
+
+for i in `$cmd list-cipher-commands`
+do
+       echo $i
+       $cmd $i -bufsize 113 -e -k test < $test > $test.$i.cipher
+       $cmd $i -bufsize 157 -d -k test < $test.$i.cipher >$test.$i.clear
+       cmp $test $test.$i.clear
+       if [ $? != 0 ]
+       then
+               exit 1
+       else
+               /bin/rm $test.$i.cipher $test.$i.clear
+       fi
+
+       echo $i base64
+       $cmd $i -bufsize 113 -a -e -k test < $test > $test.$i.cipher
+       $cmd $i -bufsize 157 -a -d -k test < $test.$i.cipher >$test.$i.clear
+       cmp $test $test.$i.clear
+       if [ $? != 0 ]
+       then
+               exit 1
+       else
+               /bin/rm $test.$i.cipher $test.$i.clear
+       fi
+done
+rm -f $test
diff --git a/deps/openssl/openssl/test/testenc.com b/deps/openssl/openssl/test/testenc.com
new file mode 100644 (file)
index 0000000..75acd6f
--- /dev/null
@@ -0,0 +1,66 @@
+$! TESTENC.COM  --  Test encoding and decoding
+$
+$      __arch = "VAX"
+$      if f$getsyi("cpu") .ge. 128 then -
+          __arch = f$edit( f$getsyi( "ARCH_NAME"), "UPCASE")
+$      if __arch .eqs. "" then __arch = "UNK"
+$!
+$      if (p1 .eqs. 64) then __arch = __arch+ "_64"
+$
+$      exe_dir = "sys$disk:[-.''__arch'.exe.apps]"
+$      testsrc = "makefile."
+$      test = "p.txt"
+$      cmd = "mcr ''exe_dir'openssl"
+$
+$      if f$search(test) .nes. "" then delete 'test';*
+$      convert/fdl=sys$input: 'testsrc' 'test'
+RECORD
+       FORMAT STREAM_LF
+$
+$      if f$search(test+"-cipher") .nes. "" then delete 'test'-cipher;*
+$      if f$search(test+"-clear") .nes. "" then delete 'test'-clear;*
+$
+$      write sys$output "cat"
+$      'cmd' enc -in 'test' -out 'test'-cipher
+$      'cmd' enc -in 'test'-cipher -out 'test'-clear
+$      backup/compare 'test' 'test'-clear
+$      if $severity .ne. 1 then exit 3
+$      delete 'test'-cipher;*,'test'-clear;*
+$
+$      write sys$output "base64"
+$      'cmd' enc -a -e -in 'test' -out 'test'-cipher
+$      'cmd' enc -a -d -in 'test'-cipher -out 'test'-clear
+$      backup/compare 'test' 'test'-clear
+$      if $severity .ne. 1 then exit 3
+$      delete 'test'-cipher;*,'test'-clear;*
+$
+$      define/user sys$output 'test'-cipher-commands
+$      'cmd' list-cipher-commands
+$      open/read f 'test'-cipher-commands
+$ loop_cipher_commands:
+$      read/end=loop_cipher_commands_end f i
+$      write sys$output i
+$
+$      if f$search(test+"-"+i+"-cipher") .nes. "" then -
+               delete 'test'-'i'-cipher;*
+$      if f$search(test+"-"+i+"-clear") .nes. "" then -
+               delete 'test'-'i'-clear;*
+$
+$      'cmd' 'i' -bufsize 113 -e -k test -in 'test' -out 'test'-'i'-cipher
+$      'cmd' 'i' -bufsize 157 -d -k test -in 'test'-'i'-cipher -out 'test'-'i'-clear
+$      backup/compare 'test' 'test'-'i'-clear
+$      if $severity .ne. 1 then exit 3
+$      delete 'test'-'i'-cipher;*,'test'-'i'-clear;*
+$
+$      write sys$output i," base64"
+$      'cmd' 'i' -bufsize 113 -a -e -k test -in 'test' -out 'test'-'i'-cipher
+$      'cmd' 'i' -bufsize 157 -a -d -k test -in 'test'-'i'-cipher -out 'test'-'i'-clear
+$      backup/compare 'test' 'test'-'i'-clear
+$      if $severity .ne. 1 then exit 3
+$      delete 'test'-'i'-cipher;*,'test'-'i'-clear;*
+$
+$      goto loop_cipher_commands
+$ loop_cipher_commands_end:
+$      close f
+$      delete 'test'-cipher-commands;*
+$      delete 'test';*
diff --git a/deps/openssl/openssl/test/testgen b/deps/openssl/openssl/test/testgen
new file mode 100644 (file)
index 0000000..524c0d1
--- /dev/null
@@ -0,0 +1,44 @@
+#!/bin/sh
+
+T=testcert
+KEY=512
+CA=../certs/testca.pem
+
+/bin/rm -f $T.1 $T.2 $T.key
+
+if test "$OSTYPE" = msdosdjgpp; then
+    PATH=../apps\;$PATH;
+else
+    PATH=../apps:$PATH;
+fi
+export PATH
+
+echo "generating certificate request"
+
+echo "string to make the random number generator think it has entropy" >> ./.rnd
+
+if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then
+  req_new='-newkey dsa:../apps/dsa512.pem'
+else
+  req_new='-new'
+  echo "There should be a 2 sequences of .'s and some +'s."
+  echo "There should not be more that at most 80 per line"
+fi
+
+echo "This could take some time."
+
+rm -f testkey.pem testreq.pem
+
+../util/shlib_wrap.sh ../apps/openssl req -config test.cnf $req_new -out testreq.pem
+if [ $? != 0 ]; then
+echo problems creating request
+exit 1
+fi
+
+../util/shlib_wrap.sh ../apps/openssl req -config test.cnf -verify -in testreq.pem -noout
+if [ $? != 0 ]; then
+echo signature on req is wrong
+exit 1
+fi
+
+exit 0
diff --git a/deps/openssl/openssl/test/testgen.com b/deps/openssl/openssl/test/testgen.com
new file mode 100644 (file)
index 0000000..e076da2
--- /dev/null
@@ -0,0 +1,58 @@
+$! TESTGEN.COM
+$
+$      __arch = "VAX"
+$      if f$getsyi("cpu") .ge. 128 then -
+          __arch = f$edit( f$getsyi( "ARCH_NAME"), "UPCASE")
+$      if __arch .eqs. "" then __arch = "UNK"
+$      if (p1 .eqs. 64) then __arch = __arch+ "_64"
+$      exe_dir = "sys$disk:[-.''__arch'.exe.apps]"
+$
+$      T = "testcert"
+$      KEY = 512
+$      CA = "[-.certs]testca.pem"
+$
+$      set noon
+$      if f$search(T+".1;*") .nes. "" then delete 'T'.1;*
+$      if f$search(T+".2;*") .nes. "" then delete 'T'.2;*
+$      if f$search(T+".key;*") .nes. "" then delete 'T'.key;*
+$      set on
+$
+$      write sys$output "generating certificate request"
+$
+$      append/new nl: .rnd
+$      open/append random_file .rnd
+$      write random_file -
+        "string to make the random number generator think it has entropy"
+$      close random_file
+$
+$      set noon
+$      define/user sys$output nla0:
+$      mcr 'exe_dir'openssl no-rsa
+$      save_severity=$SEVERITY
+$      set on
+$      if save_severity
+$      then
+$          req_new="-newkey dsa:[-.apps]dsa512.pem"
+$      else
+$          req_new="-new"
+$          write sys$output -
+            "There should be a 2 sequences of .'s and some +'s."
+$          write sys$output -
+            "There should not be more that at most 80 per line"
+$      endif
+$
+$      write sys$output "This could take some time."
+$
+$      mcr 'exe_dir'openssl req -config test.cnf 'req_new' -out testreq.pem
+$      if $severity .ne. 1
+$      then
+$          write sys$output "problems creating request"
+$          exit 3
+$      endif
+$
+$      mcr 'exe_dir'openssl req -config test.cnf -verify -in testreq.pem -noout
+$      if $severity .ne. 1
+$      then
+$          write sys$output "signature on req is wrong"
+$          exit 3
+$      endif
diff --git a/deps/openssl/openssl/test/testp7.pem b/deps/openssl/openssl/test/testp7.pem
new file mode 100644 (file)
index 0000000..e5b7866
--- /dev/null
@@ -0,0 +1,46 @@
+-----BEGIN PKCS7-----
+MIIIGAYJKoZIhvcNAQcCoIIICTCCCAUCAQExADALBgkqhkiG9w0BBwGgggY8MIIE
+cjCCBBygAwIBAgIQeS+OJfWJUZAx6cX0eAiMjzANBgkqhkiG9w0BAQQFADBiMREw
+DwYDVQQHEwhJbnRlcm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNV
+BAsTK1ZlcmlTaWduIENsYXNzIDEgQ0EgLSBJbmRpdmlkdWFsIFN1YnNjcmliZXIw
+HhcNOTYwNzE5MDAwMDAwWhcNOTcwMzMwMjM1OTU5WjCB1TERMA8GA1UEBxMISW50
+ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQLEytWZXJpU2ln
+biBDbGFzcyAxIENBIC0gSW5kaXZpZHVhbCBTdWJzY3JpYmVyMSgwJgYDVQQLEx9E
+aWdpdGFsIElEIENsYXNzIDEgLSBTTUlNRSBUZXN0MUcwRQYDVQQLEz53d3cudmVy
+aXNpZ24uY29tL3JlcG9zaXRvcnkvQ1BTLTEuMCBJbmMuIGJ5IFJlZi4sTElBQi5M
+VEQoYyk5NjBbMA0GCSqGSIb3DQEBAQUAA0oAMEcCQA7LvHEIAiQ5+4gDYvJGnGAq
+UM5GXyG11diEXmIEZTHUZhorooX5sr8IIjSXiPY59YYUFSvAaharFM1xaBN8zNEC
+AwEAAaOCAjkwggI1MAkGA1UdEwQCMAAwggImBgNVHQMEggIdMIICGTCCAhUwggIR
+BgtghkgBhvhFAQcBATCCAgAWggGrVGhpcyBjZXJ0aWZpY2F0ZSBpbmNvcnBvcmF0
+ZXMgYnkgcmVmZXJlbmNlLCBhbmQgaXRzIHVzZSBpcyBzdHJpY3RseSBzdWJqZWN0
+IHRvLCB0aGUgVmVyaVNpZ24gQ2VydGlmaWNhdGlvbiBQcmFjdGljZSBTdGF0ZW1l
+bnQgKENQUyksIGF2YWlsYWJsZSBhdDogaHR0cHM6Ly93d3cudmVyaXNpZ24uY29t
+L0NQUy0xLjA7IGJ5IEUtbWFpbCBhdCBDUFMtcmVxdWVzdHNAdmVyaXNpZ24uY29t
+OyBvciBieSBtYWlsIGF0IFZlcmlTaWduLCBJbmMuLCAyNTkzIENvYXN0IEF2ZS4s
+IE1vdW50YWluIFZpZXcsIENBIDk0MDQzIFVTQSBUZWwuICsxICg0MTUpIDk2MS04
+ODMwIENvcHlyaWdodCAoYykgMTk5NiBWZXJpU2lnbiwgSW5jLiAgQWxsIFJpZ2h0
+cyBSZXNlcnZlZC4gQ0VSVEFJTiBXQVJSQU5USUVTIERJU0NMQUlNRUQgYW5kIExJ
+QUJJTElUWSBMSU1JVEVELqAOBgxghkgBhvhFAQcBAQGhDgYMYIZIAYb4RQEHAQEC
+MC8wLRYraHR0cHM6Ly93d3cudmVyaXNpZ24uY29tL3JlcG9zaXRvcnkvQ1BTLTEu
+AzANBgkqhkiG9w0BAQQFAANBAMCYDuSb/eIlYSxY31nZZTaCZkCSfHjlacMofExr
+cF+A2yHoEuT+eCQkqM0pMNHXddUeoQ9RjV+VuMBNmm63DUYwggHCMIIBbKADAgEC
+AhB8CYTq1bkRFJBYOd67cp9JMA0GCSqGSIb3DQEBAgUAMD4xCzAJBgNVBAYTAlVT
+MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjEWMBQGA1UECxMNVEVTVCBSb290IFBD
+QTAeFw05NjA3MTcwMDAwMDBaFw05NzA3MTcyMzU5NTlaMGIxETAPBgNVBAcTCElu
+dGVybmV0MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrVmVyaVNp
+Z24gQ2xhc3MgMSBDQSAtIEluZGl2aWR1YWwgU3Vic2NyaWJlcjBcMA0GCSqGSIb3
+DQEBAQUAA0sAMEgCQQDsVzrNgnDhbAJZrWeLd9g1vMZJA2W67D33TTbga6yMt+ES
+TWEywhS6RNP+fzLGg7utinjH4tL60cXa0G27GDsLAgMBAAGjIjAgMAsGA1UdDwQE
+AwIBBjARBglghkgBhvhCAQEEBAMCAgQwDQYJKoZIhvcNAQECBQADQQAUp6bRwkaD
+2d1MBs/mjUcgTI2fXVmW8tTm/Ud6OzUwpC3vYgybiOOA4f6mOC5dbyUHrLOsrihU
+47ZQ0Jo1DUfboYIBrTCBwTBtMA0GCSqGSIb3DQEBAgUAMD4xCzAJBgNVBAYTAlVT
+MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjEWMBQGA1UECxMNVEVTVCBSb290IFBD
+QRcNOTYwNzE3MTc0NDA5WhcNOTgwNzE3MDAwMDAwWjANBgkqhkiG9w0BAQIFAANB
+AHitA0/xAukCjHzeh1AMT/l2oC68N+yFb+aJPHBBMxc6gG2MaKjBNwb5hcXUllMl
+ExONA3ju10f7owIq3s3wx10wgeYwgZEwDQYJKoZIhvcNAQECBQAwYjERMA8GA1UE
+BxMISW50ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQLEytW
+ZXJpU2lnbiBDbGFzcyAxIENBIC0gSW5kaXZpZHVhbCBTdWJzY3JpYmVyFw05NjA3
+MTcxNzU5MjlaFw05NzA3MTgwMDAwMDBaMA0GCSqGSIb3DQEBAgUAA0EAubVWYTsW
+sQmste9f+UgMw8BkjDlM25fwQLrCfmmnLxjewey10kSROypUaJLb+r4oRALc0fG9
+XfZsaiiIgotQHjEA
+-----END PKCS7-----
diff --git a/deps/openssl/openssl/test/testreq2.pem b/deps/openssl/openssl/test/testreq2.pem
new file mode 100644 (file)
index 0000000..c3cdcff
--- /dev/null
@@ -0,0 +1,7 @@
+-----BEGIN CERTIFICATE REQUEST-----
+MIHaMIGFAgEAMA4xDDAKBgNVBAMTA2NuNDBcMA0GCSqGSIb3DQEBAQUAA0sAMEgC
+QQCQsnkyUGDY2R3mYoeTprFJKgWuJ3f1jUjlIuW5+wfAUoeMt35c4vcFZ2mIBpEG
+DtzkNQN1kr2O9ldm9zYnYhyhAgMBAAGgEjAQBgorBgEEAYI3AgEOMQIwADANBgkq
+hkiG9w0BAQQFAANBAAb2szZgVIxg3vK6kYLjGSBISyuzcXJ6IvuPW6M+yzi1Qgoi
+gQhazHTJp91T8ItZEzUJGZSZl2e5iXlnffWB+/U=
+-----END CERTIFICATE REQUEST-----
diff --git a/deps/openssl/openssl/test/testrsa.pem b/deps/openssl/openssl/test/testrsa.pem
new file mode 100644 (file)
index 0000000..aad2106
--- /dev/null
@@ -0,0 +1,9 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIBPAIBAAJBAKrbeqkuRk8VcRmWFmtP+LviMB3+6dizWW3DwaffznyHGAFwUJ/I
+Tv0XtbsCyl3QoyKGhrOAy3RvPK5M38iuXT0CAwEAAQJAZ3cnzaHXM/bxGaR5CR1R
+rD1qFBAVfoQFiOH9uPJgMaoAuoQEisPHVcZDKcOv4wEg6/TInAIXBnEigtqvRzuy
+oQIhAPcgZzUq3yVooAaoov8UbXPxqHlwo6GBMqnv20xzkf6ZAiEAsP4BnIaQTM8S
+mvcpHZwQJdmdHHkGKAs37Dfxi67HbkUCIQCeZGliHXFa071Fp06ZeWlR2ADonTZz
+rJBhdTe0v5pCeQIhAIZfkiGgGBX4cIuuckzEm43g9WMUjxP/0GlK39vIyihxAiEA
+mymehFRT0MvqW5xAKAx7Pgkt8HVKwVhc2LwGKHE0DZM=
+-----END RSA PRIVATE KEY-----
diff --git a/deps/openssl/openssl/test/tests.com b/deps/openssl/openssl/test/tests.com
new file mode 100644 (file)
index 0000000..373dd16
--- /dev/null
@@ -0,0 +1,366 @@
+$! TESTS.COM  --  Performs the necessary tests
+$!
+$! P1  tests to be performed.  Empty means all.
+$! P2  Pointer size: "", "32", or "64".
+$!
+$! Announce/identify.
+$!
+$      proc = f$environment( "procedure")
+$      write sys$output "@@@ "+ -
+        f$parse( proc, , , "name")+ f$parse( proc, , , "type")
+$!
+$      __proc = f$element(0,";",f$environment("procedure"))
+$      __here = f$parse(f$parse("A.;",__proc) - "A.;","[]A.;") - "A.;"
+$      __save_default = f$environment("default")
+$      __arch = "VAX"
+$      if f$getsyi("cpu") .ge. 128 then -
+          __arch = f$edit( f$getsyi( "ARCH_NAME"), "UPCASE")
+$      if __arch .eqs. "" then __arch = "UNK"
+$!
+$      __archd = __arch
+$       pointer_size = ""
+$      if (p2 .eq. "64")
+$      then
+$        pointer_size = "64"
+$        __archd = __arch+ "_64"
+$      endif
+$!
+$      texe_dir := sys$disk:[-.'__archd'.exe.test]
+$      exe_dir := sys$disk:[-.'__archd'.exe.apps]
+$
+$      set default '__here'
+$
+$       ROOT = F$PARSE("sys$disk:[-]A.;0",,,,"SYNTAX_ONLY,NO_CONCEAL") - "A.;0"
+$       ROOT_DEV = F$PARSE(ROOT,,,"DEVICE","SYNTAX_ONLY")
+$       ROOT_DIR = F$PARSE(ROOT,,,"DIRECTORY","SYNTAX_ONLY") -
+                   - ".][000000" - "[000000." - "][" - "[" - "]"
+$       ROOT = ROOT_DEV + "[" + ROOT_DIR
+$       DEFINE/NOLOG SSLROOT 'ROOT'.APPS.] /TRANS=CONC
+$      openssl_conf := sslroot:[000000]openssl-vms.cnf
+$
+$      on control_y then goto exit
+$      on error then goto exit
+$
+$      if p1 .nes. ""
+$      then
+$          tests = p1
+$      else
+$! NOTE: This list reflects the list of dependencies following the
+$! "alltests" target in Makefile.  This should make it easy to see
+$! if there's a difference that needs to be taken care of.
+$          tests := -
+       test_des,test_idea,test_sha,test_md4,test_md5,test_hmac,-
+       test_md2,test_mdc2,test_wp,-
+       test_rmd,test_rc2,test_rc4,test_rc5,test_bf,test_cast,test_aes,-
+       test_rand,test_bn,test_ec,test_ecdsa,test_ecdh,-
+       test_enc,test_x509,test_rsa,test_crl,test_sid,-
+       test_gen,test_req,test_pkcs7,test_verify,test_dh,test_dsa,-
+       test_ss,test_ca,test_engine,test_evp,test_ssl,test_tsa,test_ige,-
+       test_jpake,test_cms
+$      endif
+$      tests = f$edit(tests,"COLLAPSE")
+$
+$      BNTEST :=       bntest
+$      ECTEST :=       ectest
+$      ECDSATEST :=    ecdsatest
+$      ECDHTEST :=     ecdhtest
+$      EXPTEST :=      exptest
+$      IDEATEST :=     ideatest
+$      SHATEST :=      shatest
+$      SHA1TEST :=     sha1test
+$      MDC2TEST :=     mdc2test
+$      RMDTEST :=      rmdtest
+$      MD2TEST :=      md2test
+$      MD4TEST :=      md4test
+$      MD5TEST :=      md5test
+$      HMACTEST :=     hmactest
+$      WPTEST :=       wp_test
+$      RC2TEST :=      rc2test
+$      RC4TEST :=      rc4test
+$      RC5TEST :=      rc5test
+$      BFTEST :=       bftest
+$      CASTTEST :=     casttest
+$      DESTEST :=      destest
+$      RANDTEST :=     randtest
+$      DHTEST :=       dhtest
+$      DSATEST :=      dsatest
+$      METHTEST :=     methtest
+$      SSLTEST :=      ssltest
+$      RSATEST :=      rsa_test
+$      ENGINETEST :=   enginetest
+$      EVPTEST :=      evp_test
+$      IGETEST :=      igetest
+$      JPAKETEST :=    jpaketest
+$      ASN1TEST :=     asn1test
+$!
+$      tests_i = 0
+$ loop_tests:
+$      tests_e = f$element(tests_i,",",tests)
+$      tests_i = tests_i + 1
+$      if tests_e .eqs. "," then goto exit
+$      write sys$output "---> ''tests_e'"
+$      gosub 'tests_e'
+$      goto loop_tests
+$
+$ test_evp:
+$      mcr 'texe_dir''evptest' 'ROOT'.CRYPTO.EVP]evptests.txt
+$      return
+$ test_des:
+$      mcr 'texe_dir''destest'
+$      return
+$ test_idea:
+$      mcr 'texe_dir''ideatest'
+$      return
+$ test_sha:
+$      mcr 'texe_dir''shatest'
+$      mcr 'texe_dir''sha1test'
+$      return
+$ test_mdc2:
+$      mcr 'texe_dir''mdc2test'
+$      return
+$ test_md5:
+$      mcr 'texe_dir''md5test'
+$      return
+$ test_md4:
+$      mcr 'texe_dir''md4test'
+$      return
+$ test_hmac:
+$      mcr 'texe_dir''hmactest'
+$      return
+$ test_wp:
+$      mcr 'texe_dir''wptest'
+$      return
+$ test_md2:
+$      mcr 'texe_dir''md2test'
+$      return
+$ test_rmd:
+$      mcr 'texe_dir''rmdtest'
+$      return
+$ test_bf:
+$      mcr 'texe_dir''bftest'
+$      return
+$ test_cast:
+$      mcr 'texe_dir''casttest'
+$      return
+$ test_rc2:
+$      mcr 'texe_dir''rc2test'
+$      return
+$ test_rc4:
+$      mcr 'texe_dir''rc4test'
+$      return
+$ test_rc5:
+$      mcr 'texe_dir''rc5test'
+$      return
+$ test_rand:
+$      mcr 'texe_dir''randtest'
+$      return
+$ test_enc:
+$      @testenc.com 'pointer_size'
+$      return
+$ test_x509:
+$      set noon
+$      define sys$error test_x509.err
+$      write sys$output "test normal x509v1 certificate"
+$      @tx509.com "" 'pointer_size'
+$      write sys$output "test first x509v3 certificate"
+$      @tx509.com v3-cert1.pem 'pointer_size'
+$      write sys$output "test second x509v3 certificate"
+$      @tx509.com v3-cert2.pem 'pointer_size'
+$      deassign sys$error
+$      set on
+$      return
+$ test_rsa:
+$      set noon
+$      define sys$error test_rsa.err
+$      @trsa.com "" 'pointer_size'
+$      deassign sys$error
+$      mcr 'texe_dir''rsatest'
+$      set on
+$      return
+$ test_crl:
+$      set noon
+$      define sys$error test_crl.err
+$      @tcrl.com "" 'pointer_size'
+$      deassign sys$error
+$      set on
+$      return
+$ test_sid:
+$      set noon
+$      define sys$error test_sid.err
+$      @tsid.com "" 'pointer_size'
+$      deassign sys$error
+$      set on
+$      return
+$ test_req:
+$      set noon
+$      define sys$error test_req.err
+$      @treq.com "" 'pointer_size'
+$      @treq.com testreq2.pem 'pointer_size'
+$      deassign sys$error
+$      set on
+$      return
+$ test_pkcs7:
+$      set noon
+$      define sys$error test_pkcs7.err
+$      @tpkcs7.com "" 'pointer_size'
+$      @tpkcs7d.com "" 'pointer_size'
+$      deassign sys$error
+$      set on
+$      return
+$ test_bn:
+$      write sys$output -
+             "starting big number library test, could take a while..."
+$      set noon
+$      define sys$error test_bn.err
+$      define sys$output test_bn.out
+$      @ bctest.com
+$      status = $status
+$      deassign sys$error
+$      deassign sys$output
+$      set on
+$      if (status)
+$      then
+$          create /fdl = sys$input bntest-vms.tmp
+FILE
+       ORGANIZATION    sequential
+RECORD
+       FORMAT          stream_lf
+$          define /user_mode sys$output bntest-vms.tmp
+$          mcr 'texe_dir''bntest'
+$          define /user_mode sys$input bntest-vms.tmp
+$          define /user_mode sys$output bntest-vms.out
+$          bc
+$          @ bntest.com bntest-vms.out
+$          status = $status
+$          if (status)
+$          then
+$              delete bntest-vms.out;*
+$              delete bntest-vms.tmp;*
+$          endif
+$      else
+$          create /fdl = sys$input bntest-vms.sh
+FILE
+       ORGANIZATION    sequential
+RECORD
+       FORMAT          stream_lf
+$          open /append bntest_file bntest-vms.sh
+$          type /output = bntest_file sys$input:
+<< __FOO__ sh -c "`sh ./bctest`" | perl -e '$i=0; while (<STDIN>) {if (/^test (.*)/) {print STDERR "\nverify $1";} elsif (!/^0$/) {die "\nFailed! bc: $_";} else {print STDERR "."; $i++;}} print STDERR "\n$i tests passed\n"'
+$          define /user_mode sys$output bntest-vms.tmp
+$          mcr 'texe_dir''bntest'
+$          copy bntest-vms.tmp bntest_file
+$          delete bntest-vms.tmp;*
+$          type /output = bntest_file sys$input:
+__FOO__
+$          close bntest_file
+$          write sys$output "-- copy the [.test]bntest-vms.sh and [.test]bctest files to a Unix system and"
+$          write sys$output "-- run bntest-vms.sh through sh or bash to verify that the bignum operations"
+$          write sys$output "-- went well."
+$          write sys$output ""
+$      endif
+$      write sys$output "test a^b%c implementations"
+$      mcr 'texe_dir''exptest'
+$      return
+$ test_ec:
+$      write sys$output "test elliptic curves"
+$      mcr 'texe_dir''ectest'
+$      return
+$ test_ecdsa:
+$      write sys$output "test ecdsa"
+$      mcr 'texe_dir''ecdsatest'
+$      return
+$ test_ecdh:
+$      write sys$output "test ecdh"
+$      mcr 'texe_dir''ecdhtest'
+$      return
+$ test_verify:
+$      write sys$output "The following command should have some OK's and some failures"
+$      write sys$output "There are definitly a few expired certificates"
+$      @tverify.com 'pointer_size'
+$      return
+$ test_dh:
+$      write sys$output "Generate a set of DH parameters"
+$      mcr 'texe_dir''dhtest'
+$      return
+$ test_dsa:
+$      write sys$output "Generate a set of DSA parameters"
+$      mcr 'texe_dir''dsatest'
+$      return
+$ test_gen:
+$      write sys$output "Generate and verify a certificate request"
+$      @testgen.com 'pointer_size'
+$      return
+$ maybe_test_ss:
+$      testss_RDT = f$cvtime(f$file_attributes("testss.com","RDT"))
+$      if f$cvtime(f$file_attributes("keyU.ss","RDT")) .les. testss_RDT then -
+               goto test_ss
+$      if f$cvtime(f$file_attributes("certU.ss","RDT")) .les. testss_RDT then -
+               goto test_ss
+$      if f$cvtime(f$file_attributes("certCA.ss","RDT")) .les. testss_RDT then -
+               goto test_ss
+$      return
+$ test_ss:
+$      write sys$output "Generate and certify a test certificate"
+$      @testss.com 'pointer_size'
+$      return
+$ test_engine: 
+$      write sys$output "Manipulate the ENGINE structures"
+$      mcr 'texe_dir''enginetest'
+$      return
+$ test_ssl:
+$      write sys$output "test SSL protocol"
+$      gosub maybe_test_ss
+$      @testssl.com keyU.ss certU.ss certCA.ss 'pointer_size'
+$      return
+$ test_ca:
+$      set noon
+$      define /user_mode sys$output test_ca.out
+$      mcr 'exe_dir'openssl no-rsa
+$      save_severity=$SEVERITY
+$      set on
+$      if save_severity
+$      then
+$          write sys$output "skipping CA.com test -- requires RSA"
+$      else
+$          write sys$output "Generate and certify a test certificate via the 'ca' program"
+$          @testca.com 'pointer_size'
+$      endif
+$      return
+$ test_aes: 
+$!     write sys$output "test AES"
+$!     !mcr 'texe_dir''aestest'
+$      return
+$ test_tsa:
+$      set noon
+$      define /user_mode sys$output nla0:
+$      mcr 'exe_dir'openssl no-rsa
+$      save_severity=$SEVERITY
+$      set on
+$      if save_severity
+$      then
+$          write sys$output "skipping testtsa.com test -- requires RSA"
+$      else
+$          @testtsa.com "" "" "" 'pointer_size'
+$      endif
+$      return
+$ test_ige: 
+$      write sys$output "Test IGE mode"
+$      mcr 'texe_dir''igetest'
+$      return
+$ test_jpake: 
+$      write sys$output "Test JPAKE"
+$      mcr 'texe_dir''jpaketest'
+$      return
+$ test_cms:
+$      write sys$output "CMS consistency test"
+$      ! Define the logical name used to find openssl.exe in the perl script.
+$      define /user_mode osslx 'exe_dir'
+$      perl CMS-TEST.PL
+$      return
+$
+$
+$ exit:
+$      mcr 'exe_dir'openssl version -a
+$      set default '__save_default'
+$      deassign sslroot
+$      exit
diff --git a/deps/openssl/openssl/test/testsid.pem b/deps/openssl/openssl/test/testsid.pem
new file mode 100644 (file)
index 0000000..7ffd008
--- /dev/null
@@ -0,0 +1,12 @@
+-----BEGIN SSL SESSION PARAMETERS-----
+MIIB1gIBAQIBAgQDAQCABBCi11xa5qkOP8xrr02K/NQCBBBkIYQZM0Bt95W0EHNV
+bA58oQYCBDIBr7WiBAICASyjggGGMIIBgjCCASwCAQMwDQYJKoZIhvcNAQEEBQAw
+ODELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA1FMRDEbMBkGA1UEAxMSU1NMZWF5L3Jz
+YSB0ZXN0IENBMB4XDTk1MTAwOTIzMzEzNFoXDTk4MDcwNTIzMzEzNFowYDELMAkG
+A1UEBhMCQVUxDDAKBgNVBAgTA1FMRDEZMBcGA1UEChMQTWluY29tIFB0eS4gTHRk
+LjELMAkGA1UECxMCQ1MxGzAZBgNVBAMTElNTTGVheSBkZW1vIGNsaWVudDBcMA0G
+CSqGSIb3DQEBAQUAA0sAMEgCQQC4pcXEL1lgVA+B5Q3TcuW/O3LZHoA73IYm8oFD
+TezgCDhL2RTMn+seKWF36UtJKRIOBU9jZHCVVd0Me5ls6BEjAgMBAAEwDQYJKoZI
+hvcNAQEEBQADQQBoIpOcwUY1qlVF7j3ROSGvUsbvByOBFmYWkIBgsCqR+9qo1A7L
+CrWF5i8LWt/vLwAHaxWNx2YuBJMFyuK81fTvpA0EC3Rlc3Rjb250ZXh0
+-----END SSL SESSION PARAMETERS-----
diff --git a/deps/openssl/openssl/test/testss b/deps/openssl/openssl/test/testss
new file mode 100644 (file)
index 0000000..1a42685
--- /dev/null
@@ -0,0 +1,163 @@
+#!/bin/sh
+
+digest='-sha1'
+reqcmd="../util/shlib_wrap.sh ../apps/openssl req"
+x509cmd="../util/shlib_wrap.sh ../apps/openssl x509 $digest"
+verifycmd="../util/shlib_wrap.sh ../apps/openssl verify"
+dummycnf="../apps/openssl.cnf"
+
+CAkey="keyCA.ss"
+CAcert="certCA.ss"
+CAreq="reqCA.ss"
+CAconf="CAss.cnf"
+CAreq2="req2CA.ss"     # temp
+
+Uconf="Uss.cnf"
+Ukey="keyU.ss"
+Ureq="reqU.ss"
+Ucert="certU.ss"
+
+P1conf="P1ss.cnf"
+P1key="keyP1.ss"
+P1req="reqP1.ss"
+P1cert="certP1.ss"
+P1intermediate="tmp_intP1.ss"
+
+P2conf="P2ss.cnf"
+P2key="keyP2.ss"
+P2req="reqP2.ss"
+P2cert="certP2.ss"
+P2intermediate="tmp_intP2.ss"
+
+echo
+echo "make a certificate request using 'req'"
+
+echo "string to make the random number generator think it has entropy" >> ./.rnd
+
+if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then
+  req_new='-newkey dsa:../apps/dsa512.pem'
+else
+  req_new='-new'
+fi
+
+$reqcmd -config $CAconf -out $CAreq -keyout $CAkey $req_new #>err.ss
+if [ $? != 0 ]; then
+       echo "error using 'req' to generate a certificate request"
+       exit 1
+fi
+echo
+echo "convert the certificate request into a self signed certificate using 'x509'"
+$x509cmd -CAcreateserial -in $CAreq -days 30 -req -out $CAcert -signkey $CAkey -extfile $CAconf -extensions v3_ca >err.ss
+if [ $? != 0 ]; then
+       echo "error using 'x509' to self sign a certificate request"
+       exit 1
+fi
+
+echo
+echo "convert a certificate into a certificate request using 'x509'"
+$x509cmd -in $CAcert -x509toreq -signkey $CAkey -out $CAreq2 >err.ss
+if [ $? != 0 ]; then
+       echo "error using 'x509' convert a certificate to a certificate request"
+       exit 1
+fi
+
+$reqcmd -config $dummycnf -verify -in $CAreq -noout
+if [ $? != 0 ]; then
+       echo first generated request is invalid
+       exit 1
+fi
+
+$reqcmd -config $dummycnf -verify -in $CAreq2 -noout
+if [ $? != 0 ]; then
+       echo second generated request is invalid
+       exit 1
+fi
+
+$verifycmd -CAfile $CAcert $CAcert
+if [ $? != 0 ]; then
+       echo first generated cert is invalid
+       exit 1
+fi
+
+echo
+echo "make a user certificate request using 'req'"
+$reqcmd -config $Uconf -out $Ureq -keyout $Ukey $req_new >err.ss
+if [ $? != 0 ]; then
+       echo "error using 'req' to generate a user certificate request"
+       exit 1
+fi
+
+echo
+echo "sign user certificate request with the just created CA via 'x509'"
+$x509cmd -CAcreateserial -in $Ureq -days 30 -req -out $Ucert -CA $CAcert -CAkey $CAkey -extfile $Uconf -extensions v3_ee >err.ss
+if [ $? != 0 ]; then
+       echo "error using 'x509' to sign a user certificate request"
+       exit 1
+fi
+
+$verifycmd -CAfile $CAcert $Ucert
+echo
+echo "Certificate details"
+$x509cmd -subject -issuer -startdate -enddate -noout -in $Ucert
+
+echo
+echo "make a proxy certificate request using 'req'"
+$reqcmd -config $P1conf -out $P1req -keyout $P1key $req_new >err.ss
+if [ $? != 0 ]; then
+       echo "error using 'req' to generate a proxy certificate request"
+       exit 1
+fi
+
+echo
+echo "sign proxy certificate request with the just created user certificate via 'x509'"
+$x509cmd -CAcreateserial -in $P1req -days 30 -req -out $P1cert -CA $Ucert -CAkey $Ukey -extfile $P1conf -extensions v3_proxy >err.ss
+if [ $? != 0 ]; then
+       echo "error using 'x509' to sign a proxy certificate request"
+       exit 1
+fi
+
+cat $Ucert > $P1intermediate
+$verifycmd -CAfile $CAcert -untrusted $P1intermediate $P1cert
+echo
+echo "Certificate details"
+$x509cmd -subject -issuer -startdate -enddate -noout -in $P1cert
+
+echo
+echo "make another proxy certificate request using 'req'"
+$reqcmd -config $P2conf -out $P2req -keyout $P2key $req_new >err.ss
+if [ $? != 0 ]; then
+       echo "error using 'req' to generate another proxy certificate request"
+       exit 1
+fi
+
+echo
+echo "sign second proxy certificate request with the first proxy certificate via 'x509'"
+$x509cmd -CAcreateserial -in $P2req -days 30 -req -out $P2cert -CA $P1cert -CAkey $P1key -extfile $P2conf -extensions v3_proxy >err.ss
+if [ $? != 0 ]; then
+       echo "error using 'x509' to sign a second proxy certificate request"
+       exit 1
+fi
+
+cat $Ucert $P1cert > $P2intermediate
+$verifycmd -CAfile $CAcert -untrusted $P2intermediate $P2cert
+echo
+echo "Certificate details"
+$x509cmd -subject -issuer -startdate -enddate -noout -in $P2cert
+
+echo
+echo The generated CA certificate is $CAcert
+echo The generated CA private key is $CAkey
+
+echo The generated user certificate is $Ucert
+echo The generated user private key is $Ukey
+
+echo The first generated proxy certificate is $P1cert
+echo The first generated proxy private key is $P1key
+
+echo The second generated proxy certificate is $P2cert
+echo The second generated proxy private key is $P2key
+
+/bin/rm err.ss
+#/bin/rm $P1intermediate
+#/bin/rm $P2intermediate
+exit 0
diff --git a/deps/openssl/openssl/test/testss.com b/deps/openssl/openssl/test/testss.com
new file mode 100644 (file)
index 0000000..32a74d0
--- /dev/null
@@ -0,0 +1,123 @@
+$! TESTSS.COM
+$
+$      __arch = "VAX"
+$      if f$getsyi("cpu") .ge. 128 then -
+          __arch = f$edit( f$getsyi( "ARCH_NAME"), "UPCASE")
+$      if __arch .eqs. "" then __arch = "UNK"
+$!
+$      if (p1 .eqs. "64") then __arch = __arch+ "_64"
+$!
+$      exe_dir = "sys$disk:[-.''__arch'.exe.apps]"
+$
+$      digest="-md5"
+$      reqcmd = "mcr ''exe_dir'openssl req"
+$      x509cmd = "mcr ''exe_dir'openssl x509 ''digest'"
+$      verifycmd = "mcr ''exe_dir'openssl verify"
+$      dummycnf = "sys$disk:[-.apps]openssl-vms.cnf"
+$
+$      CAkey="""keyCA.ss"""
+$      CAcert="""certCA.ss"""
+$      CAreq="""reqCA.ss"""
+$      CAconf="""CAss.cnf"""
+$      CAreq2="""req2CA.ss"""  ! temp
+$
+$      Uconf="""Uss.cnf"""
+$      Ukey="""keyU.ss"""
+$      Ureq="""reqU.ss"""
+$      Ucert="""certU.ss"""
+$
+$      write sys$output ""
+$      write sys$output "make a certificate request using 'req'"
+$
+$      set noon
+$      define/user sys$output nla0:
+$      mcr 'exe_dir'openssl no-rsa
+$      save_severity=$SEVERITY
+$      set on
+$      if save_severity
+$      then
+$          req_new="-newkey dsa:[-.apps]dsa512.pem"
+$      else
+$          req_new="-new"
+$      endif
+$
+$      'reqcmd' -config 'CAconf' -out 'CAreq' -keyout 'CAkey' 'req_new' ! -out err.ss
+$      if $severity .ne. 1
+$      then
+$              write sys$output "error using 'req' to generate a certificate request"
+$              exit 3
+$      endif
+$      write sys$output ""
+$      write sys$output "convert the certificate request into a self signed certificate using 'x509'"
+$      define /user sys$output err.ss
+$      'x509cmd' "-CAcreateserial" -in 'CAreq' -days 30 -req -out 'CAcert' -signkey 'CAkey'
+$      if $severity .ne. 1
+$      then
+$              write sys$output "error using 'x509' to self sign a certificate request"
+$              exit 3
+$      endif
+$
+$      write sys$output ""
+$      write sys$output "convert a certificate into a certificate request using 'x509'"
+$      define /user sys$output err.ss
+$      'x509cmd' -in 'CAcert' -x509toreq -signkey 'CAkey' -out 'CAreq2'
+$      if $severity .ne. 1
+$      then
+$              write sys$output "error using 'x509' convert a certificate to a certificate request"
+$              exit 3
+$      endif
+$
+$      'reqcmd' -config 'dummycnf' -verify -in 'CAreq' -noout
+$      if $severity .ne. 1
+$      then
+$              write sys$output "first generated request is invalid"
+$              exit 3
+$      endif
+$
+$      'reqcmd' -config 'dummycnf' -verify -in 'CAreq2' -noout
+$      if $severity .ne. 1
+$      then
+$              write sys$output "second generated request is invalid"
+$              exit 3
+$      endif
+$
+$      'verifycmd' "-CAfile" 'CAcert' 'CAcert'
+$      if $severity .ne. 1
+$      then
+$              write sys$output "first generated cert is invalid"
+$              exit 3
+$      endif
+$
+$      write sys$output ""
+$      write sys$output "make another certificate request using 'req'"
+$      define /user sys$output err.ss
+$      'reqcmd' -config 'Uconf' -out 'Ureq' -keyout 'Ukey' 'req_new'
+$      if $severity .ne. 1
+$      then
+$              write sys$output "error using 'req' to generate a certificate request"
+$              exit 3
+$      endif
+$
+$      write sys$output ""
+$      write sys$output "sign certificate request with the just created CA via 'x509'"
+$      define /user sys$output err.ss
+$      'x509cmd' "-CAcreateserial" -in 'Ureq' -days 30 -req -out 'Ucert' "-CA" 'CAcert' "-CAkey" 'CAkey'
+$      if $severity .ne. 1
+$      then
+$              write sys$output "error using 'x509' to sign a certificate request"
+$              exit 3
+$      endif
+$
+$      'verifycmd' "-CAfile" 'CAcert' 'Ucert'
+$      write sys$output ""
+$      write sys$output "Certificate details"
+$      'x509cmd' -subject -issuer -startdate -enddate -noout -in 'Ucert'
+$
+$      write sys$output ""
+$      write sys$output "The generated CA certificate is ",CAcert
+$      write sys$output "The generated CA private key is ",CAkey
+$
+$      write sys$output "The generated user certificate is ",Ucert
+$      write sys$output "The generated user private key is ",Ukey
+$
+$      if f$search("err.ss;*") .nes. "" then delete err.ss;*
diff --git a/deps/openssl/openssl/test/testssl b/deps/openssl/openssl/test/testssl
new file mode 100644 (file)
index 0000000..aa5be9e
--- /dev/null
@@ -0,0 +1,163 @@
+#!/bin/sh
+
+if [ "$1" = "" ]; then
+  key=../apps/server.pem
+else
+  key="$1"
+fi
+if [ "$2" = "" ]; then
+  cert=../apps/server.pem
+else
+  cert="$2"
+fi
+ssltest="../util/shlib_wrap.sh ./ssltest -key $key -cert $cert -c_key $key -c_cert $cert"
+
+if ../util/shlib_wrap.sh ../apps/openssl x509 -in $cert -text -noout | fgrep 'DSA Public Key' >/dev/null; then
+  dsa_cert=YES
+else
+  dsa_cert=NO
+fi
+
+if [ "$3" = "" ]; then
+  CA="-CApath ../certs"
+else
+  CA="-CAfile $3"
+fi
+
+if [ "$4" = "" ]; then
+  extra=""
+else
+  extra="$4"
+fi
+
+#############################################################################
+
+echo test sslv2
+$ssltest -ssl2 $extra || exit 1
+
+echo test sslv2 with server authentication
+$ssltest -ssl2 -server_auth $CA $extra || exit 1
+
+if [ $dsa_cert = NO ]; then
+  echo test sslv2 with client authentication
+  $ssltest -ssl2 -client_auth $CA $extra || exit 1
+
+  echo test sslv2 with both client and server authentication
+  $ssltest -ssl2 -server_auth -client_auth $CA $extra || exit 1
+fi
+
+echo test sslv3
+$ssltest -ssl3 $extra || exit 1
+
+echo test sslv3 with server authentication
+$ssltest -ssl3 -server_auth $CA $extra || exit 1
+
+echo test sslv3 with client authentication
+$ssltest -ssl3 -client_auth $CA $extra || exit 1
+
+echo test sslv3 with both client and server authentication
+$ssltest -ssl3 -server_auth -client_auth $CA $extra || exit 1
+
+echo test sslv2/sslv3
+$ssltest $extra || exit 1
+
+echo test sslv2/sslv3 with server authentication
+$ssltest -server_auth $CA $extra || exit 1
+
+echo test sslv2/sslv3 with client authentication
+$ssltest -client_auth $CA $extra || exit 1
+
+echo test sslv2/sslv3 with both client and server authentication
+$ssltest -server_auth -client_auth $CA $extra || exit 1
+
+echo test sslv2/sslv3 with both client and server authentication and small client buffers
+$ssltest -server_auth -client_auth -c_small_records $CA $extra || exit 1
+
+echo test sslv2/sslv3 with both client and server authentication and small server buffers
+$ssltest -server_auth -client_auth -s_small_records $CA $extra || exit 1
+
+echo test sslv2/sslv3 with both client and server authentication and small client and server buffers
+$ssltest -server_auth -client_auth -c_small_records -s_small_records $CA $extra || exit 1
+
+echo test sslv2/sslv3 with both client and server authentication and handshake cutthrough
+$ssltest -server_auth -client_auth -cutthrough $CA $extra || exit 1
+
+echo test sslv2 via BIO pair
+$ssltest -bio_pair -ssl2 $extra || exit 1
+
+echo test sslv2 with server authentication via BIO pair
+$ssltest -bio_pair -ssl2 -server_auth $CA $extra || exit 1
+
+if [ $dsa_cert = NO ]; then
+  echo test sslv2 with client authentication via BIO pair
+  $ssltest -bio_pair -ssl2 -client_auth $CA $extra || exit 1
+
+  echo test sslv2 with both client and server authentication via BIO pair
+  $ssltest -bio_pair -ssl2 -server_auth -client_auth $CA $extra || exit 1
+fi
+
+echo test sslv3 via BIO pair
+$ssltest -bio_pair -ssl3 $extra || exit 1
+
+echo test sslv3 with server authentication via BIO pair
+$ssltest -bio_pair -ssl3 -server_auth $CA $extra || exit 1
+
+echo test sslv3 with client authentication via BIO pair
+$ssltest -bio_pair -ssl3 -client_auth $CA $extra || exit 1
+
+echo test sslv3 with both client and server authentication via BIO pair
+$ssltest -bio_pair -ssl3 -server_auth -client_auth $CA $extra || exit 1
+
+echo test sslv2/sslv3 via BIO pair
+$ssltest $extra || exit 1
+
+if [ $dsa_cert = NO ]; then
+  echo 'test sslv2/sslv3 w/o (EC)DHE via BIO pair'
+  $ssltest -bio_pair -no_dhe -no_ecdhe $extra || exit 1
+fi
+
+echo test sslv2/sslv3 with 1024bit DHE via BIO pair
+$ssltest -bio_pair -dhe1024dsa -v $extra || exit 1
+
+echo test sslv2/sslv3 with server authentication
+$ssltest -bio_pair -server_auth $CA $extra || exit 1
+
+echo test sslv2/sslv3 with client authentication via BIO pair
+$ssltest -bio_pair -client_auth $CA $extra || exit 1
+
+echo test sslv2/sslv3 with both client and server authentication via BIO pair
+$ssltest -bio_pair -server_auth -client_auth $CA $extra || exit 1
+
+echo test sslv2/sslv3 with both client and server authentication via BIO pair and app verify
+$ssltest -bio_pair -server_auth -client_auth -app_verify $CA $extra || exit 1
+
+#############################################################################
+
+if ../util/shlib_wrap.sh ../apps/openssl no-dh; then
+  echo skipping anonymous DH tests
+else
+  echo test tls1 with 1024bit anonymous DH, multiple handshakes
+  $ssltest -v -bio_pair -tls1 -cipher ADH -dhe1024dsa -num 10 -f -time $extra || exit 1
+fi
+
+if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then
+  echo skipping RSA tests
+else
+  echo 'test tls1 with 1024bit RSA, no (EC)DHE, multiple handshakes'
+  ../util/shlib_wrap.sh ./ssltest -v -bio_pair -tls1 -cert ../apps/server2.pem -no_dhe -no_ecdhe -num 10 -f -time $extra || exit 1
+
+  if ../util/shlib_wrap.sh ../apps/openssl no-dh; then
+    echo skipping RSA+DHE tests
+  else
+    echo test tls1 with 1024bit RSA, 1024bit DHE, multiple handshakes
+    ../util/shlib_wrap.sh ./ssltest -v -bio_pair -tls1 -cert ../apps/server2.pem -dhe1024dsa -num 10 -f -time $extra || exit 1
+  fi
+fi
+
+echo test tls1 with PSK
+$ssltest -tls1 -cipher PSK -psk abc123 $extra || exit 1
+
+echo test tls1 with PSK via BIO pair
+$ssltest -bio_pair -tls1 -cipher PSK -psk abc123 $extra || exit 1
+
+exit 0
diff --git a/deps/openssl/openssl/test/testssl.com b/deps/openssl/openssl/test/testssl.com
new file mode 100644 (file)
index 0000000..f19edc4
--- /dev/null
@@ -0,0 +1,208 @@
+$! TESTSSL.COM
+$
+$      __arch = "VAX"
+$      if f$getsyi("cpu") .ge. 128 then -
+          __arch = f$edit( f$getsyi( "ARCH_NAME"), "UPCASE")
+$      if __arch .eqs. "" then __arch = "UNK"
+$!
+$      if (p4 .eqs. "64") then __arch = __arch+ "_64"
+$!
+$      texe_dir = "sys$disk:[-.''__arch'.exe.test]"
+$      exe_dir = "sys$disk:[-.''__arch'.exe.apps]"
+$
+$      if p1 .eqs. ""
+$      then
+$          key="[-.apps]server.pem"
+$      else
+$          key=p1
+$      endif
+$      if p2 .eqs. ""
+$      then
+$          cert="[-.apps]server.pem"
+$      else
+$          cert=p2
+$      endif
+$      ssltest = "mcr ''texe_dir'ssltest -key ''key'"+ -
+        " -cert ''cert' -c_key ''key' -c_cert ''cert'"
+$!
+$      set noon
+$      define/user sys$output testssl-x509-output.
+$      define/user sys$error nla0:
+$      mcr 'exe_dir'openssl x509 -in 'cert' -text -noout
+$      define/user sys$error nla0:
+$      search/output=nla0: testssl-x509-output. "DSA Public Key"/exact
+$      if $severity .eq. 1
+$      then
+$          dsa_cert = "YES"
+$      else
+$          dsa_cert = "NO"
+$      endif
+$      delete testssl-x509-output.;*
+$
+$      if p3 .eqs. ""
+$      then
+$          copy/concatenate [-.certs]*.pem certs.tmp
+$          CA = """-CAfile"" certs.tmp"
+$      else
+$          CA = """-CAfile"" "+p3
+$      endif
+$
+$!###########################################################################
+$
+$      write sys$output "test sslv2"
+$      'ssltest' -ssl2
+$      if $severity .ne. 1 then goto exit3
+$
+$      write sys$output "test sslv2 with server authentication"
+$      'ssltest' -ssl2 -server_auth 'CA'
+$      if $severity .ne. 1 then goto exit3
+$
+$      if .not. dsa_cert
+$      then
+$          write sys$output "test sslv2 with client authentication"
+$          'ssltest' -ssl2 -client_auth 'CA'
+$          if $severity .ne. 1 then goto exit3
+$
+$          write sys$output "test sslv2 with both client and server authentication"
+$          'ssltest' -ssl2 -server_auth -client_auth 'CA'
+$          if $severity .ne. 1 then goto exit3
+$      endif
+$
+$      write sys$output "test sslv3"
+$      'ssltest' -ssl3
+$      if $severity .ne. 1 then goto exit3
+$
+$      write sys$output "test sslv3 with server authentication"
+$      'ssltest' -ssl3 -server_auth 'CA'
+$      if $severity .ne. 1 then goto exit3
+$
+$      write sys$output "test sslv3 with client authentication"
+$      'ssltest' -ssl3 -client_auth 'CA'
+$      if $severity .ne. 1 then goto exit3
+$
+$      write sys$output "test sslv3 with both client and server authentication"
+$      'ssltest' -ssl3 -server_auth -client_auth 'CA'
+$      if $severity .ne. 1 then goto exit3
+$
+$      write sys$output "test sslv2/sslv3"
+$      'ssltest'
+$      if $severity .ne. 1 then goto exit3
+$
+$      write sys$output "test sslv2/sslv3 with server authentication"
+$      'ssltest' -server_auth 'CA'
+$      if $severity .ne. 1 then goto exit3
+$
+$      write sys$output "test sslv2/sslv3 with client authentication"
+$      'ssltest' -client_auth 'CA'
+$      if $severity .ne. 1 then goto exit3
+$
+$      write sys$output "test sslv2/sslv3 with both client and server authentication"
+$      'ssltest' -server_auth -client_auth 'CA'
+$      if $severity .ne. 1 then goto exit3
+$
+$      write sys$output "test sslv2 via BIO pair"
+$      'ssltest' -bio_pair -ssl2 
+$      if $severity .ne. 1 then goto exit3
+$
+$      write sys$output "test sslv2 with server authentication via BIO pair"
+$      'ssltest' -bio_pair -ssl2 -server_auth 'CA' 
+$      if $severity .ne. 1 then goto exit3
+$
+$      if .not. dsa_cert
+$      then
+$          write sys$output "test sslv2 with client authentication via BIO pair"
+$          'ssltest' -bio_pair -ssl2 -client_auth 'CA' 
+$          if $severity .ne. 1 then goto exit3
+$
+$          write sys$output "test sslv2 with both client and server authentication via BIO pair"
+$          'ssltest' -bio_pair -ssl2 -server_auth -client_auth 'CA' 
+$          if $severity .ne. 1 then goto exit3
+$      endif
+$
+$      write sys$output "test sslv3 via BIO pair"
+$      'ssltest' -bio_pair -ssl3 
+$      if $severity .ne. 1 then goto exit3
+$
+$      write sys$output "test sslv3 with server authentication via BIO pair"
+$      'ssltest' -bio_pair -ssl3 -server_auth 'CA' 
+$      if $severity .ne. 1 then goto exit3
+$
+$      write sys$output "test sslv3 with client authentication via BIO pair"
+$      'ssltest' -bio_pair -ssl3 -client_auth 'CA' 
+$      if $severity .ne. 1 then goto exit3
+$      write sys$output "test sslv3 with both client and server authentication via BIO pair"
+$      'ssltest' -bio_pair -ssl3 -server_auth -client_auth 'CA' 
+$      if $severity .ne. 1 then goto exit3
+$
+$      write sys$output "test sslv2/sslv3 via BIO pair"
+$      'ssltest' 
+$      if $severity .ne. 1 then goto exit3
+$
+$      if .not. dsa_cert
+$      then
+$          write sys$output "test sslv2/sslv3 w/o DHE via BIO pair"
+$          'ssltest' -bio_pair -no_dhe
+$          if $severity .ne. 1 then goto exit3
+$      endif
+$
+$      write sys$output "test sslv2/sslv3 with 1024 bit DHE via BIO pair"
+$      'ssltest' -bio_pair -dhe1024dsa -v
+$      if $severity .ne. 1 then goto exit3
+$
+$      write sys$output "test sslv2/sslv3 with server authentication"
+$      'ssltest' -bio_pair -server_auth 'CA' 
+$      if $severity .ne. 1 then goto exit3
+$
+$      write sys$output "test sslv2/sslv3 with client authentication via BIO pair"
+$      'ssltest' -bio_pair -client_auth 'CA' 
+$      if $severity .ne. 1 then goto exit3
+$
+$      write sys$output "test sslv2/sslv3 with both client and server authentication via BIO pair"
+$      'ssltest' -bio_pair -server_auth -client_auth 'CA' 
+$      if $severity .ne. 1 then goto exit3
+$
+$!###########################################################################
+$
+$      define/user sys$output nla0:
+$      mcr 'exe_dir'openssl no-rsa
+$      no_rsa=$SEVERITY
+$      define/user sys$output nla0:
+$      mcr 'exe_dir'openssl no-dh
+$      no_dh=$SEVERITY
+$
+$      if no_dh
+$      then
+$          write sys$output "skipping anonymous DH tests"
+$      else
+$          write sys$output "test tls1 with 1024bit anonymous DH, multiple handshakes"
+$          'ssltest' -v -bio_pair -tls1 -cipher "ADH" -dhe1024dsa -num 10 -f -time
+$          if $severity .ne. 1 then goto exit3
+$      endif
+$
+$      if no_rsa
+$      then
+$          write sys$output "skipping RSA tests"
+$      else
+$          write sys$output "test tls1 with 1024bit RSA, no DHE, multiple handshakes"
+$          mcr 'texe_dir'ssltest -v -bio_pair -tls1 -cert [-.apps]server2.pem -no_dhe -num 10 -f -time
+$          if $severity .ne. 1 then goto exit3
+$
+$          if no_dh
+$          then
+$              write sys$output "skipping RSA+DHE tests"
+$          else
+$              write sys$output "test tls1 with 1024bit RSA, 1024bit DHE, multiple handshakes"
+$              mcr 'texe_dir'ssltest -v -bio_pair -tls1 -cert [-.apps]server2.pem -dhe1024dsa -num 10 -f -time
+$              if $severity .ne. 1 then goto exit3
+$          endif
+$      endif
+$
+$      RET = 1
+$      goto exit
+$ exit3:
+$      RET = 3
+$ exit:
+$      if p3 .eqs. "" then delete certs.tmp;*
+$      set on
+$      exit 'RET'
diff --git a/deps/openssl/openssl/test/testsslproxy b/deps/openssl/openssl/test/testsslproxy
new file mode 100644 (file)
index 0000000..58bbda8
--- /dev/null
@@ -0,0 +1,10 @@
+#! /bin/sh
+
+echo 'Testing a lot of proxy conditions.'
+echo 'Some of them may turn out being invalid, which is fine.'
+for auth in A B C BC; do
+    for cond in A B C 'A|B&!C'; do
+       sh ./testssl $1 $2 $3 "-proxy -proxy_auth $auth -proxy_cond $cond"
+       if [ $? = 3 ]; then exit 1; fi
+    done
+done
diff --git a/deps/openssl/openssl/test/testtsa b/deps/openssl/openssl/test/testtsa
new file mode 100644 (file)
index 0000000..bb653b5
--- /dev/null
@@ -0,0 +1,238 @@
+#!/bin/sh
+
+#
+# A few very basic tests for the 'ts' time stamping authority command.
+#
+
+SH="/bin/sh"
+if test "$OSTYPE" = msdosdjgpp; then
+    PATH="../apps\;$PATH"
+else
+    PATH="../apps:$PATH"
+fi
+export SH PATH
+
+OPENSSL_CONF="../CAtsa.cnf"
+export OPENSSL_CONF
+# Because that's what ../apps/CA.sh really looks at
+SSLEAY_CONFIG="-config $OPENSSL_CONF"
+export SSLEAY_CONFIG
+
+OPENSSL="`pwd`/../util/opensslwrap.sh"
+export OPENSSL
+
+error () {
+
+    echo "TSA test failed!" >&2
+    exit 1
+}
+
+setup_dir () {
+
+    rm -rf tsa 2>/dev/null
+    mkdir tsa
+    cd ./tsa
+}
+
+clean_up_dir () {
+
+    cd ..
+    rm -rf tsa
+}
+
+create_ca () {
+
+    echo "Creating a new CA for the TSA tests..."
+    TSDNSECT=ts_ca_dn
+    export TSDNSECT   
+    ../../util/shlib_wrap.sh ../../apps/openssl req -new -x509 -nodes \
+       -out tsaca.pem -keyout tsacakey.pem
+    test $? != 0 && error
+}
+
+create_tsa_cert () {
+
+    INDEX=$1
+    export INDEX
+    EXT=$2
+    TSDNSECT=ts_cert_dn
+    export TSDNSECT   
+
+    ../../util/shlib_wrap.sh ../../apps/openssl req -new \
+       -out tsa_req${INDEX}.pem -keyout tsa_key${INDEX}.pem
+    test $? != 0 && error
+echo Using extension $EXT
+    ../../util/shlib_wrap.sh ../../apps/openssl x509 -req \
+       -in tsa_req${INDEX}.pem -out tsa_cert${INDEX}.pem \
+       -CA tsaca.pem -CAkey tsacakey.pem -CAcreateserial \
+       -extfile $OPENSSL_CONF -extensions $EXT
+    test $? != 0 && error
+}
+
+print_request () {
+
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -query -in $1 -text
+}
+
+create_time_stamp_request1 () {
+
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -query -data ../testtsa -policy tsa_policy1 -cert -out req1.tsq
+    test $? != 0 && error
+}
+
+create_time_stamp_request2 () {
+
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -query -data ../testtsa -policy tsa_policy2 -no_nonce \
+       -out req2.tsq
+    test $? != 0 && error
+}
+
+create_time_stamp_request3 () {
+
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -query -data ../CAtsa.cnf -no_nonce -out req3.tsq
+    test $? != 0 && error
+}
+
+print_response () {
+
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -in $1 -text
+    test $? != 0 && error
+}
+
+create_time_stamp_response () {
+
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -section $3 -queryfile $1 -out $2
+    test $? != 0 && error
+}
+
+time_stamp_response_token_test () {
+
+    RESPONSE2=$2.copy.tsr
+    TOKEN_DER=$2.token.der
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -in $2 -out $TOKEN_DER -token_out
+    test $? != 0 && error
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -in $TOKEN_DER -token_in -out $RESPONSE2
+    test $? != 0 && error
+    cmp $RESPONSE2 $2
+    test $? != 0 && error
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -in $2 -text -token_out
+    test $? != 0 && error
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -in $TOKEN_DER -token_in -text -token_out
+    test $? != 0 && error
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -queryfile $1 -text -token_out
+    test $? != 0 && error
+}
+
+verify_time_stamp_response () {
+
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -verify -queryfile $1 -in $2 -CAfile tsaca.pem \
+       -untrusted tsa_cert1.pem
+    test $? != 0 && error
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -verify -data $3 -in $2 -CAfile tsaca.pem \
+       -untrusted tsa_cert1.pem
+    test $? != 0 && error
+}
+
+verify_time_stamp_token () {
+
+    # create the token from the response first
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -in $2 -out $2.token -token_out
+    test $? != 0 && error
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -verify -queryfile $1 -in $2.token -token_in \
+       -CAfile tsaca.pem -untrusted tsa_cert1.pem
+    test $? != 0 && error
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -verify -data $3 -in $2.token -token_in \
+       -CAfile tsaca.pem -untrusted tsa_cert1.pem
+    test $? != 0 && error
+}
+
+verify_time_stamp_response_fail () {
+
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -verify -queryfile $1 -in $2 -CAfile tsaca.pem \
+       -untrusted tsa_cert1.pem
+    # Checks if the verification failed, as it should have.
+    test $? = 0 && error
+    echo Ok
+}
+
+# main functions
+
+echo "Setting up TSA test directory..."
+setup_dir
+
+echo "Creating CA for TSA tests..."
+create_ca
+
+echo "Creating tsa_cert1.pem TSA server cert..."
+create_tsa_cert 1 tsa_cert
+
+echo "Creating tsa_cert2.pem non-TSA server cert..."
+create_tsa_cert 2 non_tsa_cert
+
+echo "Creating req1.req time stamp request for file testtsa..."
+create_time_stamp_request1
+
+echo "Printing req1.req..."
+print_request req1.tsq
+
+echo "Generating valid response for req1.req..."
+create_time_stamp_response req1.tsq resp1.tsr tsa_config1
+
+echo "Printing response..."
+print_response resp1.tsr
+
+echo "Verifying valid response..."
+verify_time_stamp_response req1.tsq resp1.tsr ../testtsa
+
+echo "Verifying valid token..."
+verify_time_stamp_token req1.tsq resp1.tsr ../testtsa
+
+# The tests below are commented out, because invalid signer certificates
+# can no longer be specified in the config file.
+
+# echo "Generating _invalid_ response for req1.req..."
+# create_time_stamp_response req1.tsq resp1_bad.tsr tsa_config2
+
+# echo "Printing response..."
+# print_response resp1_bad.tsr
+
+# echo "Verifying invalid response, it should fail..."
+# verify_time_stamp_response_fail req1.tsq resp1_bad.tsr
+
+echo "Creating req2.req time stamp request for file testtsa..."
+create_time_stamp_request2
+
+echo "Printing req2.req..."
+print_request req2.tsq
+
+echo "Generating valid response for req2.req..."
+create_time_stamp_response req2.tsq resp2.tsr tsa_config1
+
+echo "Checking '-token_in' and '-token_out' options with '-reply'..."
+time_stamp_response_token_test req2.tsq resp2.tsr
+
+echo "Printing response..."
+print_response resp2.tsr
+
+echo "Verifying valid response..."
+verify_time_stamp_response req2.tsq resp2.tsr ../testtsa
+
+echo "Verifying response against wrong request, it should fail..."
+verify_time_stamp_response_fail req1.tsq resp2.tsr
+
+echo "Verifying response against wrong request, it should fail..."
+verify_time_stamp_response_fail req2.tsq resp1.tsr
+
+echo "Creating req3.req time stamp request for file CAtsa.cnf..."
+create_time_stamp_request3
+
+echo "Printing req3.req..."
+print_request req3.tsq
+
+echo "Verifying response against wrong request, it should fail..."
+verify_time_stamp_response_fail req3.tsq resp1.tsr
+
+echo "Cleaning up..."
+clean_up_dir
+
+exit 0
diff --git a/deps/openssl/openssl/test/testtsa.com b/deps/openssl/openssl/test/testtsa.com
new file mode 100644 (file)
index 0000000..29fb1d0
--- /dev/null
@@ -0,0 +1,255 @@
+$!
+$! A few very basic tests for the 'ts' time stamping authority command.
+$!
+$
+$      __arch = "VAX"
+$      if f$getsyi("cpu") .ge. 128 then -
+          __arch = f$edit( f$getsyi( "ARCH_NAME"), "UPCASE")
+$      if __arch .eqs. "" then __arch = "UNK"
+$!
+$      if (p4 .eqs. "64") then __arch = __arch+ "_64"
+$!
+$      exe_dir = "sys$disk:[-.''__arch'.exe.apps]"
+$
+$      openssl = "mcr ''f$parse(exe_dir+"openssl.exe")'"
+$      OPENSSL_CONF = "[-]CAtsa.cnf"
+$      ! Because that's what ../apps/CA.sh really looks at
+$      SSLEAY_CONFIG = "-config " + OPENSSL_CONF
+$
+$ error:
+$      subroutine
+$              write sys$error "TSA test failed!"
+$              exit 3
+$      endsubroutine
+$
+$ setup_dir:
+$      subroutine
+$
+$              if f$search("tsa.dir") .nes ""
+$              then
+$                      @[-.util]deltree [.tsa]*.*
+$                      set file/prot=(S:RWED,O:RWED,G:RWED,W:RWED) tsa.dir;*
+$                      delete tsa.dir;*
+$              endif
+$
+$              create/dir [.tsa]
+$              set default [.tsa]
+$      endsubroutine
+$
+$ clean_up_dir:
+$      subroutine
+$
+$              set default [-]
+$              @[-.util]deltree [.tsa]*.*
+$              set file/prot=(S:RWED,O:RWED,G:RWED,W:RWED) tsa.dir;*
+$              delete tsa.dir;*
+$      endsubroutine
+$
+$ create_ca:
+$      subroutine
+$
+$              write sys$output "Creating a new CA for the TSA tests..."
+$              TSDNSECT = "ts_ca_dn"
+$              openssl req -new -x509 -nodes -
+                       -out tsaca.pem -keyout tsacakey.pem
+$              if $severity .ne. 1 then call error
+$      endsubroutine
+$
+$ create_tsa_cert:
+$      subroutine
+$
+$              INDEX=p1
+$              EXT=p2
+$              TSDNSECT = "ts_cert_dn"
+$
+$              openssl req -new -
+                       -out tsa_req'INDEX'.pem -keyout tsa_key'INDEX'.pem
+$              if $severity .ne. 1 then call error
+$
+$              write sys$output "Using extension ''EXT'"
+$              openssl x509 -req -
+                       -in tsa_req'INDEX'.pem -out tsa_cert'INDEX'.pem -
+                       "-CA" tsaca.pem "-CAkey" tsacakey.pem "-CAcreateserial" -
+                       -extfile 'OPENSSL_CONF' -extensions "''EXT'"
+$              if $severity .ne. 1 then call error
+$      endsubroutine
+$
+$ print_request:
+$      subroutine
+$
+$              openssl ts -query -in 'p1' -text
+$      endsubroutine
+$
+$ create_time_stamp_request1: subroutine
+$
+$              openssl ts -query -data [-]testtsa.com -policy tsa_policy1 -
+                       -cert -out req1.tsq
+$              if $severity .ne. 1 then call error
+$      endsubroutine
+$
+$ create_time_stamp_request2: subroutine
+$
+$              openssl ts -query -data [-]testtsa.com -policy tsa_policy2 -
+                       -no_nonce -out req2.tsq
+$              if $severity .ne. 1 then call error
+$      endsubroutine
+$
+$ create_time_stamp_request3: subroutine
+$
+$              openssl ts -query -data [-]CAtsa.cnf -no_nonce -out req3.tsq
+$              if $severity .ne. 1 then call error
+$      endsubroutine
+$
+$ print_response:
+$      subroutine
+$
+$              openssl ts -reply -in 'p1' -text
+$              if $severity .ne. 1 then call error
+$      endsubroutine
+$
+$ create_time_stamp_response:
+$      subroutine
+$
+$              openssl ts -reply -section 'p3' -queryfile 'p1' -out 'p2'
+$              if $severity .ne. 1 then call error
+$      endsubroutine
+$
+$ time_stamp_response_token_test:
+$      subroutine
+$
+$              RESPONSE2 = p2+ "-copy_tsr"
+$              TOKEN_DER = p2+ "-token_der"
+$              openssl ts -reply -in 'p2' -out 'TOKEN_DER' -token_out
+$              if $severity .ne. 1 then call error
+$              openssl ts -reply -in 'TOKEN_DER' -token_in -out 'RESPONSE2'
+$              if $severity .ne. 1 then call error
+$              backup/compare 'RESPONSE2' 'p2'
+$              if $severity .ne. 1 then call error
+$              openssl ts -reply -in 'p2' -text -token_out
+$              if $severity .ne. 1 then call error
+$              openssl ts -reply -in 'TOKEN_DER' -token_in -text -token_out
+$              if $severity .ne. 1 then call error
+$              openssl ts -reply -queryfile 'p1' -text -token_out
+$              if $severity .ne. 1 then call error
+$      endsubroutine
+$
+$ verify_time_stamp_response:
+$      subroutine
+$
+$              openssl ts -verify -queryfile 'p1' -in 'p2' -
+                       "-CAfile" tsaca.pem -untrusted tsa_cert1.pem
+$              if $severity .ne. 1 then call error
+$              openssl ts -verify -data 'p3' -in 'p2' -
+                       "-CAfile" tsaca.pem -untrusted tsa_cert1.pem
+$              if $severity .ne. 1 then call error
+$      endsubroutine
+$
+$ verify_time_stamp_token:
+$      subroutine
+$
+$              ! create the token from the response first
+$              openssl ts -reply -in "''p2'" -out "''p2'-token" -token_out
+$              if $severity .ne. 1 then call error
+$              openssl ts -verify -queryfile "''p1'" -in "''p2'-token" -
+                -token_in "-CAfile" tsaca.pem -untrusted tsa_cert1.pem
+$              if $severity .ne. 1 then call error
+$              openssl ts -verify -data "''p3'" -in "''p2'-token" -
+                -token_in "-CAfile" tsaca.pem -untrusted tsa_cert1.pem
+$              if $severity .ne. 1 then call error
+$      endsubroutine
+$
+$ verify_time_stamp_response_fail:
+$      subroutine
+$
+$              openssl ts -verify -queryfile 'p1' -in 'p2' -
+                       "-CAfile" tsaca.pem -untrusted tsa_cert1.pem
+$              ! Checks if the verification failed, as it should have.
+$              if $severity .eq. 1 then call error
+$              write sys$output "Ok"
+$      endsubroutine
+$
+$      ! Main body ----------------------------------------------------------
+$
+$      set noon
+$
+$      write sys$output "Setting up TSA test directory..."
+$      call setup_dir
+$
+$      write sys$output "Creating CA for TSA tests..."
+$      call create_ca
+$
+$      write sys$output "Creating tsa_cert1.pem TSA server cert..."
+$      call create_tsa_cert 1 "tsa_cert"
+$
+$      write sys$output "Creating tsa_cert2.pem non-TSA server cert..."
+$      call create_tsa_cert 2 "non_tsa_cert"
+$
+$      write sys$output "Creating req1.req time stamp request for file testtsa..."
+$      call create_time_stamp_request1
+$
+$      write sys$output "Printing req1.req..."
+$      call print_request "req1.tsq"
+$
+$      write sys$output "Generating valid response for req1.req..."
+$      call create_time_stamp_response "req1.tsq" "resp1.tsr" "tsa_config1"
+$
+$      write sys$output "Printing response..."
+$      call print_response "resp1.tsr"
+$
+$      write sys$output "Verifying valid response..."
+$      call verify_time_stamp_response "req1.tsq" "resp1.tsr" "[-]testtsa.com"
+$
+$      write sys$output "Verifying valid token..."
+$      call verify_time_stamp_token "req1.tsq" "resp1.tsr" "[-]testtsa.com"
+$
+$      ! The tests below are commented out, because invalid signer certificates
+$      ! can no longer be specified in the config file.
+$
+$      ! write sys$output "Generating _invalid_ response for req1.req..."
+$      ! call create_time_stamp_response "req1.tsq" "resp1_bad.tsr" "tsa_config2"
+$
+$      ! write sys$output "Printing response..."
+$      ! call print_response "resp1_bad.tsr"
+$
+$      ! write sys$output "Verifying invalid response, it should fail..."
+$      ! call verify_time_stamp_response_fail "req1.tsq" "resp1_bad.tsr"
+$
+$      write sys$output "Creating req2.req time stamp request for file testtsa..."
+$      call create_time_stamp_request2
+$
+$      write sys$output "Printing req2.req..."
+$      call print_request "req2.tsq"
+$
+$      write sys$output "Generating valid response for req2.req..."
+$      call create_time_stamp_response "req2.tsq" "resp2.tsr" "tsa_config1"
+$
+$      write sys$output "Checking '-token_in' and '-token_out' options with '-reply'..."
+$      call time_stamp_response_token_test "req2.tsq" "resp2.tsr"
+$
+$      write sys$output "Printing response..."
+$      call print_response "resp2.tsr"
+$
+$      write sys$output "Verifying valid response..."
+$      call verify_time_stamp_response "req2.tsq" "resp2.tsr" "[-]testtsa.com"
+$
+$      write sys$output "Verifying response against wrong request, it should fail..."
+$      call verify_time_stamp_response_fail "req1.tsq" "resp2.tsr"
+$
+$      write sys$output "Verifying response against wrong request, it should fail..."
+$      call verify_time_stamp_response_fail "req2.tsq" "resp1.tsr"
+$
+$      write sys$output "Creating req3.req time stamp request for file CAtsa.cnf..."
+$      call create_time_stamp_request3
+$
+$      write sys$output "Printing req3.req..."
+$      call print_request "req3.tsq"
+$
+$      write sys$output "Verifying response against wrong request, it should fail..."
+$      call verify_time_stamp_response_fail "req3.tsq" "resp1.tsr"
+$
+$      write sys$output "Cleaning up..."
+$      call clean_up_dir
+$
+$      set on
+$
+$      exit
diff --git a/deps/openssl/openssl/test/testx509.pem b/deps/openssl/openssl/test/testx509.pem
new file mode 100644 (file)
index 0000000..8a85d14
--- /dev/null
@@ -0,0 +1,10 @@
+-----BEGIN CERTIFICATE-----
+MIIBWzCCAQYCARgwDQYJKoZIhvcNAQEEBQAwODELMAkGA1UEBhMCQVUxDDAKBgNV
+BAgTA1FMRDEbMBkGA1UEAxMSU1NMZWF5L3JzYSB0ZXN0IENBMB4XDTk1MDYxOTIz
+MzMxMloXDTk1MDcxNzIzMzMxMlowOjELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA1FM
+RDEdMBsGA1UEAxMUU1NMZWF5L3JzYSB0ZXN0IGNlcnQwXDANBgkqhkiG9w0BAQEF
+AANLADBIAkEAqtt6qS5GTxVxGZYWa0/4u+IwHf7p2LNZbcPBp9/OfIcYAXBQn8hO
+/Re1uwLKXdCjIoaGs4DLdG88rkzfyK5dPQIDAQABMAwGCCqGSIb3DQIFBQADQQAE
+Wc7EcF8po2/ZO6kNCwK/ICH6DobgLekA5lSLr5EvuioZniZp5lFzAw4+YzPQ7XKJ
+zl9HYIMxATFyqSiD9jsx
+-----END CERTIFICATE-----
diff --git a/deps/openssl/openssl/test/times b/deps/openssl/openssl/test/times
new file mode 100644 (file)
index 0000000..6b66eb3
--- /dev/null
@@ -0,0 +1,113 @@
+
+More number for the questions about SSL overheads....
+
+The following numbers were generated on a Pentium pro 200, running Linux.
+They give an indication of the SSL protocol and encryption overheads.
+
+The program that generated them is an unreleased version of ssl/ssltest.c
+which is the SSLeay ssl protocol testing program.  It is a single process that
+talks both sides of the SSL protocol via a non-blocking memory buffer
+interface.
+
+How do I read this?  The protocol and cipher are reasonable obvious.
+The next number is the number of connections being made.  The next is the
+number of bytes exchanged between the client and server side of the protocol.
+This is the number of bytes that the client sends to the server, and then
+the server sends back.  Because this is all happening in one process,
+the data is being encrypted, decrypted, encrypted and then decrypted again.
+It is a round trip of that many bytes.  Because the one process performs
+both the client and server sides of the protocol and it sends this many bytes
+each direction, multiply this number by 4 to generate the number
+of bytes encrypted/decrypted/MACed.  The first time value is how many seconds
+elapsed doing a full SSL handshake, the second is the cost of one
+full handshake and the rest being session-id reuse.
+
+SSLv2 RC4-MD5      1000 x      1   12.83s   0.70s
+SSLv3 NULL-MD5     1000 x      1   14.35s   1.47s
+SSLv3 RC4-MD5      1000 x      1   14.46s   1.56s
+SSLv3 RC4-MD5      1000 x      1   51.93s   1.62s 1024bit RSA
+SSLv3 RC4-SHA      1000 x      1   14.61s   1.83s
+SSLv3 DES-CBC-SHA  1000 x      1   14.70s   1.89s
+SSLv3 DES-CBC3-SHA 1000 x      1   15.16s   2.16s
+
+SSLv2 RC4-MD5      1000 x   1024   13.72s   1.27s
+SSLv3 NULL-MD5     1000 x   1024   14.79s   1.92s
+SSLv3 RC4-MD5      1000 x   1024   52.58s   2.29s 1024bit RSA
+SSLv3 RC4-SHA      1000 x   1024   15.39s   2.67s
+SSLv3 DES-CBC-SHA  1000 x   1024   16.45s   3.55s
+SSLv3 DES-CBC3-SHA 1000 x   1024   18.21s   5.38s
+
+SSLv2 RC4-MD5      1000 x  10240   18.97s   6.52s
+SSLv3 NULL-MD5     1000 x  10240   17.79s   5.11s
+SSLv3 RC4-MD5      1000 x  10240   20.25s   7.90s
+SSLv3 RC4-MD5      1000 x  10240   58.26s   8.08s 1024bit RSA
+SSLv3 RC4-SHA      1000 x  10240   22.96s  11.44s
+SSLv3 DES-CBC-SHA  1000 x  10240   30.65s  18.41s
+SSLv3 DES-CBC3-SHA 1000 x  10240   47.04s  34.53s
+
+SSLv2 RC4-MD5      1000 x 102400   70.22s  57.74s
+SSLv3 NULL-MD5     1000 x 102400   43.73s  31.03s
+SSLv3 RC4-MD5      1000 x 102400   71.32s  58.83s
+SSLv3 RC4-MD5      1000 x 102400  109.66s  59.20s 1024bit RSA
+SSLv3 RC4-SHA      1000 x 102400   95.88s  82.21s
+SSLv3 DES-CBC-SHA  1000 x 102400  173.22s 160.55s
+SSLv3 DES-CBC3-SHA 1000 x 102400  336.61s 323.82s
+
+What does this all mean?  Well for a server, with no session-id reuse, with
+a transfer size of 10240 bytes, using RC4-MD5 and a 512bit server key,
+a Pentium pro 200 running Linux can handle the SSLv3 protocol overheads of
+about 49 connections a second.  Reality will be quite different :-).
+
+Remember the first number is 1000 full ssl handshakes, the second is
+1 full and 999 with session-id reuse.  The RSA overheads for each exchange
+would be one public and one private operation, but the protocol/MAC/cipher
+cost would be quite similar in both the client and server.
+
+eric (adding numbers to speculation)
+
+--- Appendix ---
+- The time measured is user time but these number a very rough.
+- Remember this is the cost of both client and server sides of the protocol.
+- The TCP/kernel overhead of connection establishment is normally the
+  killer in SSL.  Often delays in the TCP protocol will make session-id
+  reuse look slower that new sessions, but this would not be the case on
+  a loaded server.
+- The TCP round trip latencies, while slowing individual connections,
+  would have minimal impact on throughput.
+- Instead of sending one 102400 byte buffer, one 8k buffer is sent until
+- the required number of bytes are processed.
+- The SSLv3 connections were actually SSLv2 compatible SSLv3 headers.
+- A 512bit server key was being used except where noted.
+- No server key verification was being performed on the client side of the
+  protocol.  This would slow things down very little.
+- The library being used is SSLeay 0.8.x.
+- The normal measuring system was commands of the form
+  time ./ssltest -num 1000 -bytes 102400 -cipher DES-CBC-SHA -reuse
+  This modified version of ssltest should be in the next public release of
+  SSLeay.
+
+The general cipher performance number for this platform are
+
+SSLeay 0.8.2a 04-Sep-1997
+built on Fri Sep  5 17:37:05 EST 1997
+options:bn(64,32) md2(int) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2)
+C flags:gcc -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized 
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2               131.02k      368.41k      500.57k      549.21k      566.09k
+mdc2              535.60k      589.10k      595.88k      595.97k      594.54k
+md5              1801.53k     9674.77k    17484.03k    21849.43k    23592.96k
+sha              1261.63k     5533.25k     9285.63k    11187.88k    11913.90k
+sha1             1103.13k     4782.53k     7933.78k     9472.34k    10070.70k
+rc4             10722.53k    14443.93k    15215.79k    15299.24k    15219.59k
+des cbc          3286.57k     3827.73k     3913.39k     3931.82k     3926.70k
+des ede3         1443.50k     1549.08k     1561.17k     1566.38k     1564.67k
+idea cbc         2203.64k     2508.16k     2538.33k     2543.62k     2547.71k
+rc2 cbc          1430.94k     1511.59k     1524.82k     1527.13k     1523.33k
+blowfish cbc     4716.07k     5965.82k     6190.17k     6243.67k     6234.11k
+                  sign    verify
+rsa  512 bits   0.0100s   0.0011s
+rsa 1024 bits   0.0451s   0.0012s
+rsa 2048 bits   0.2605s   0.0086s
+rsa 4096 bits   1.6883s   0.0302s
+
diff --git a/deps/openssl/openssl/test/tpkcs7 b/deps/openssl/openssl/test/tpkcs7
new file mode 100644 (file)
index 0000000..3e435ff
--- /dev/null
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+cmd='../util/shlib_wrap.sh ../apps/openssl pkcs7'
+
+if [ "$1"x != "x" ]; then
+       t=$1
+else
+       t=testp7.pem
+fi
+
+echo testing pkcs7 conversions
+cp $t fff.p
+
+echo "p -> d"
+$cmd -in fff.p -inform p -outform d >f.d
+if [ $? != 0 ]; then exit 1; fi
+echo "p -> p"
+$cmd -in fff.p -inform p -outform p >f.p
+if [ $? != 0 ]; then exit 1; fi
+
+echo "d -> d"
+$cmd -in f.d -inform d -outform d >ff.d1
+if [ $? != 0 ]; then exit 1; fi
+echo "p -> d"
+$cmd -in f.p -inform p -outform d >ff.d3
+if [ $? != 0 ]; then exit 1; fi
+
+echo "d -> p"
+$cmd -in f.d -inform d -outform p >ff.p1
+if [ $? != 0 ]; then exit 1; fi
+echo "p -> p"
+$cmd -in f.p -inform p -outform p >ff.p3
+if [ $? != 0 ]; then exit 1; fi
+
+cmp fff.p f.p
+if [ $? != 0 ]; then exit 1; fi
+cmp fff.p ff.p1
+if [ $? != 0 ]; then exit 1; fi
+cmp fff.p ff.p3
+if [ $? != 0 ]; then exit 1; fi
+
+cmp f.p ff.p1
+if [ $? != 0 ]; then exit 1; fi
+cmp f.p ff.p3
+if [ $? != 0 ]; then exit 1; fi
+
+/bin/rm -f f.* ff.* fff.*
+exit 0
diff --git a/deps/openssl/openssl/test/tpkcs7.com b/deps/openssl/openssl/test/tpkcs7.com
new file mode 100644 (file)
index 0000000..3fc4982
--- /dev/null
@@ -0,0 +1,59 @@
+$! TPKCS7.COM  --  Tests pkcs7 keys
+$
+$      __arch = "VAX"
+$      if f$getsyi("cpu") .ge. 128 then -
+          __arch = f$edit( f$getsyi( "ARCH_NAME"), "UPCASE")
+$      if __arch .eqs. "" then __arch = "UNK"
+$!
+$      if (p2 .eqs. "64") then __arch = __arch+ "_64"
+$!
+$      exe_dir = "sys$disk:[-.''__arch'.exe.apps]"
+$
+$      cmd = "mcr ''exe_dir'openssl pkcs7"
+$
+$      t = "testp7.pem"
+$      if p1 .nes. "" then t = p1
+$
+$      write sys$output "testing PKCS7 conversions"
+$      if f$search("fff.*") .nes "" then delete fff.*;*
+$      if f$search("ff.*") .nes "" then delete ff.*;*
+$      if f$search("f.*") .nes "" then delete f.*;*
+$      convert/fdl=sys$input: 't' fff.p
+RECORD
+       FORMAT STREAM_LF
+$
+$      write sys$output "p -> d"
+$      'cmd' -in fff.p -inform p -outform d -out f.d
+$      if $severity .ne. 1 then exit 3
+$      write sys$output "p -> p"
+$      'cmd' -in fff.p -inform p -outform p -out f.p
+$      if $severity .ne. 1 then exit 3
+$
+$      write sys$output "d -> d"
+$      'cmd' -in f.d -inform d -outform d -out ff.d1
+$      if $severity .ne. 1 then exit 3
+$      write sys$output "p -> d"
+$      'cmd' -in f.p -inform p -outform d -out ff.d3
+$      if $severity .ne. 1 then exit 3
+$
+$
+$      write sys$output "d -> p"
+$      'cmd' -in f.d -inform d -outform p -out ff.p1
+$      if $severity .ne. 1 then exit 3
+$      write sys$output "p -> p"
+$      'cmd' -in f.p -inform p -outform p -out ff.p3
+$      if $severity .ne. 1 then exit 3
+$
+$      backup/compare fff.p f.p
+$      if $severity .ne. 1 then exit 3
+$      backup/compare fff.p ff.p1
+$      if $severity .ne. 1 then exit 3
+$      backup/compare fff.p ff.p3
+$      if $severity .ne. 1 then exit 3
+$
+$      backup/compare f.p ff.p1
+$      if $severity .ne. 1 then exit 3
+$      backup/compare f.p ff.p3
+$      if $severity .ne. 1 then exit 3
+$
+$      delete f.*;*,ff.*;*,fff.*;*
diff --git a/deps/openssl/openssl/test/tpkcs7d b/deps/openssl/openssl/test/tpkcs7d
new file mode 100644 (file)
index 0000000..64fc28e
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+cmd='../util/shlib_wrap.sh ../apps/openssl pkcs7'
+
+if [ "$1"x != "x" ]; then
+       t=$1
+else
+       t=pkcs7-1.pem
+fi
+
+echo "testing pkcs7 conversions (2)"
+cp $t fff.p
+
+echo "p -> d"
+$cmd -in fff.p -inform p -outform d >f.d
+if [ $? != 0 ]; then exit 1; fi
+echo "p -> p"
+$cmd -in fff.p -inform p -outform p >f.p
+if [ $? != 0 ]; then exit 1; fi
+
+echo "d -> d"
+$cmd -in f.d -inform d -outform d >ff.d1
+if [ $? != 0 ]; then exit 1; fi
+echo "p -> d"
+$cmd -in f.p -inform p -outform d >ff.d3
+if [ $? != 0 ]; then exit 1; fi
+
+echo "d -> p"
+$cmd -in f.d -inform d -outform p >ff.p1
+if [ $? != 0 ]; then exit 1; fi
+echo "p -> p"
+$cmd -in f.p -inform p -outform p >ff.p3
+if [ $? != 0 ]; then exit 1; fi
+
+cmp f.p ff.p1
+if [ $? != 0 ]; then exit 1; fi
+cmp f.p ff.p3
+if [ $? != 0 ]; then exit 1; fi
+
+/bin/rm -f f.* ff.* fff.*
+exit 0
diff --git a/deps/openssl/openssl/test/tpkcs7d.com b/deps/openssl/openssl/test/tpkcs7d.com
new file mode 100644 (file)
index 0000000..eea8c88
--- /dev/null
@@ -0,0 +1,52 @@
+$! TPKCS7.COM  --  Tests pkcs7 keys
+$
+$      __arch = "VAX"
+$      if f$getsyi("cpu") .ge. 128 then -
+          __arch = f$edit( f$getsyi( "ARCH_NAME"), "UPCASE")
+$      if __arch .eqs. "" then __arch = "UNK"
+$!
+$      if (p2 .eqs. "64") then __arch = __arch+ "_64"
+$!
+$      exe_dir = "sys$disk:[-.''__arch'.exe.apps]"
+$
+$      cmd = "mcr ''exe_dir'openssl pkcs7"
+$
+$      t = "pkcs7-1.pem"
+$      if p1 .nes. "" then t = p1
+$
+$      write sys$output "testing PKCS7 conversions (2)"
+$      if f$search("fff.*") .nes "" then delete fff.*;*
+$      if f$search("ff.*") .nes "" then delete ff.*;*
+$      if f$search("f.*") .nes "" then delete f.*;*
+$      convert/fdl=sys$input: 't' fff.p
+RECORD
+       FORMAT STREAM_LF
+$
+$      write sys$output "p -> d"
+$      'cmd' -in fff.p -inform p -outform d -out f.d
+$      if $severity .ne. 1 then exit 3
+$      write sys$output "p -> p"
+$      'cmd' -in fff.p -inform p -outform p -out f.p
+$      if $severity .ne. 1 then exit 3
+$
+$      write sys$output "d -> d"
+$      'cmd' -in f.d -inform d -outform d -out ff.d1
+$      if $severity .ne. 1 then exit 3
+$      write sys$output "p -> d"
+$      'cmd' -in f.p -inform p -outform d -out ff.d3
+$      if $severity .ne. 1 then exit 3
+$
+$
+$      write sys$output "d -> p"
+$      'cmd' -in f.d -inform d -outform p -out ff.p1
+$      if $severity .ne. 1 then exit 3
+$      write sys$output "p -> p"
+$      'cmd' -in f.p -inform p -outform p -out ff.p3
+$      if $severity .ne. 1 then exit 3
+$
+$      backup/compare f.p ff.p1
+$      if $severity .ne. 1 then exit 3
+$      backup/compare f.p ff.p3
+$      if $severity .ne. 1 then exit 3
+$
+$      delete f.*;*,ff.*;*,fff.*;*
diff --git a/deps/openssl/openssl/test/treq b/deps/openssl/openssl/test/treq
new file mode 100644 (file)
index 0000000..77f37dc
--- /dev/null
@@ -0,0 +1,83 @@
+#!/bin/sh
+
+cmd='../util/shlib_wrap.sh ../apps/openssl req -config ../apps/openssl.cnf'
+
+if [ "$1"x != "x" ]; then
+       t=$1
+else
+       t=testreq.pem
+fi
+
+if $cmd -in $t -inform p -noout -text 2>&1 | fgrep -i 'Unknown Public Key'; then
+  echo "skipping req conversion test for $t"
+  exit 0
+fi
+
+echo testing req conversions
+cp $t fff.p
+
+echo "p -> d"
+$cmd -in fff.p -inform p -outform d >f.d
+if [ $? != 0 ]; then exit 1; fi
+#echo "p -> t"
+#$cmd -in fff.p -inform p -outform t >f.t
+#if [ $? != 0 ]; then exit 1; fi
+echo "p -> p"
+$cmd -in fff.p -inform p -outform p >f.p
+if [ $? != 0 ]; then exit 1; fi
+
+echo "d -> d"
+$cmd -verify -in f.d -inform d -outform d >ff.d1
+if [ $? != 0 ]; then exit 1; fi
+#echo "t -> d"
+#$cmd -in f.t -inform t -outform d >ff.d2
+#if [ $? != 0 ]; then exit 1; fi
+echo "p -> d"
+$cmd -verify -in f.p -inform p -outform d >ff.d3
+if [ $? != 0 ]; then exit 1; fi
+
+#echo "d -> t"
+#$cmd -in f.d -inform d -outform t >ff.t1
+#if [ $? != 0 ]; then exit 1; fi
+#echo "t -> t"
+#$cmd -in f.t -inform t -outform t >ff.t2
+#if [ $? != 0 ]; then exit 1; fi
+#echo "p -> t"
+#$cmd -in f.p -inform p -outform t >ff.t3
+#if [ $? != 0 ]; then exit 1; fi
+
+echo "d -> p"
+$cmd -in f.d -inform d -outform p >ff.p1
+if [ $? != 0 ]; then exit 1; fi
+#echo "t -> p"
+#$cmd -in f.t -inform t -outform p >ff.p2
+#if [ $? != 0 ]; then exit 1; fi
+echo "p -> p"
+$cmd -in f.p -inform p -outform p >ff.p3
+if [ $? != 0 ]; then exit 1; fi
+
+cmp fff.p f.p
+if [ $? != 0 ]; then exit 1; fi
+cmp fff.p ff.p1
+if [ $? != 0 ]; then exit 1; fi
+#cmp fff.p ff.p2
+#if [ $? != 0 ]; then exit 1; fi
+cmp fff.p ff.p3
+if [ $? != 0 ]; then exit 1; fi
+
+#cmp f.t ff.t1
+#if [ $? != 0 ]; then exit 1; fi
+#cmp f.t ff.t2
+#if [ $? != 0 ]; then exit 1; fi
+#cmp f.t ff.t3
+#if [ $? != 0 ]; then exit 1; fi
+
+cmp f.p ff.p1
+if [ $? != 0 ]; then exit 1; fi
+#cmp f.p ff.p2
+#if [ $? != 0 ]; then exit 1; fi
+cmp f.p ff.p3
+if [ $? != 0 ]; then exit 1; fi
+
+/bin/rm -f f.* ff.* fff.*
+exit 0
diff --git a/deps/openssl/openssl/test/treq.com b/deps/openssl/openssl/test/treq.com
new file mode 100644 (file)
index 0000000..acf08b7
--- /dev/null
@@ -0,0 +1,88 @@
+$! TREQ.COM  --  Tests req keys
+$
+$      __arch = "VAX"
+$      if f$getsyi("cpu") .ge. 128 then -
+          __arch = f$edit( f$getsyi( "ARCH_NAME"), "UPCASE")
+$      if __arch .eqs. "" then __arch = "UNK"
+$!
+$      if (p2 .eqs. "64") then __arch = __arch+ "_64"
+$!
+$      exe_dir = "sys$disk:[-.''__arch'.exe.apps]"
+$
+$      cmd = "mcr ''exe_dir'openssl req -config [-.apps]openssl-vms.cnf"
+$
+$      t = "testreq.pem"
+$      if p1 .nes. "" then t = p1
+$
+$      write sys$output "testing req conversions"
+$      if f$search("fff.*") .nes "" then delete fff.*;*
+$      if f$search("ff.*") .nes "" then delete ff.*;*
+$      if f$search("f.*") .nes "" then delete f.*;*
+$      convert/fdl=sys$input: 't' fff.p
+RECORD
+       FORMAT STREAM_LF
+$
+$      write sys$output "p -> d"
+$      'cmd' -in fff.p -inform p -outform d -out f.d
+$      if $severity .ne. 1 then exit 3
+$!     write sys$output "p -> t"
+$!     'cmd' -in fff.p -inform p -outform t -out f.t
+$!     if $severity .ne. 1 then exit 3
+$      write sys$output "p -> p"
+$      'cmd' -in fff.p -inform p -outform p -out f.p
+$      if $severity .ne. 1 then exit 3
+$
+$      write sys$output "d -> d"
+$      'cmd' -verify -in f.d -inform d -outform d -out ff.d1
+$      if $severity .ne. 1 then exit 3
+$!     write sys$output "t -> d"
+$!     'cmd' -verify -in f.t -inform t -outform d -out ff.d2
+$!     if $severity .ne. 1 then exit 3
+$      write sys$output "p -> d"
+$      'cmd' -verify -in f.p -inform p -outform d -out ff.d3
+$      if $severity .ne. 1 then exit 3
+$
+$!     write sys$output "d -> t"
+$!     'cmd' -in f.d -inform d -outform t -out ff.t1
+$!     if $severity .ne. 1 then exit 3
+$!     write sys$output "t -> t"
+$!     'cmd' -in f.t -inform t -outform t -out ff.t2
+$!     if $severity .ne. 1 then exit 3
+$!     write sys$output "p -> t"
+$!     'cmd' -in f.p -inform p -outform t -out ff.t3
+$!     if $severity .ne. 1 then exit 3
+$
+$      write sys$output "d -> p"
+$      'cmd' -in f.d -inform d -outform p -out ff.p1
+$      if $severity .ne. 1 then exit 3
+$!     write sys$output "t -> p"
+$!     'cmd' -in f.t -inform t -outform p -out ff.p2
+$!     if $severity .ne. 1 then exit 3
+$      write sys$output "p -> p"
+$      'cmd' -in f.p -inform p -outform p -out ff.p3
+$      if $severity .ne. 1 then exit 3
+$
+$      backup/compare fff.p f.p
+$      if $severity .ne. 1 then exit 3
+$      backup/compare fff.p ff.p1
+$      if $severity .ne. 1 then exit 3
+$!     backup/compare fff.p ff.p2
+$!     if $severity .ne. 1 then exit 3
+$      backup/compare fff.p ff.p3
+$      if $severity .ne. 1 then exit 3
+$
+$!     backup/compare f.t ff.t1
+$!     if $severity .ne. 1 then exit 3
+$!     backup/compare f.t ff.t2
+$!     if $severity .ne. 1 then exit 3
+$!     backup/compare f.t ff.t3
+$!     if $severity .ne. 1 then exit 3
+$
+$      backup/compare f.p ff.p1
+$      if $severity .ne. 1 then exit 3
+$!     backup/compare f.p ff.p2
+$!     if $severity .ne. 1 then exit 3
+$      backup/compare f.p ff.p3
+$      if $severity .ne. 1 then exit 3
+$
+$      delete f.*;*,ff.*;*,fff.*;*
diff --git a/deps/openssl/openssl/test/trsa b/deps/openssl/openssl/test/trsa
new file mode 100644 (file)
index 0000000..249ac1d
--- /dev/null
@@ -0,0 +1,83 @@
+#!/bin/sh
+
+if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then
+  echo skipping rsa conversion test
+  exit 0
+fi
+
+cmd='../util/shlib_wrap.sh ../apps/openssl rsa'
+
+if [ "$1"x != "x" ]; then
+       t=$1
+else
+       t=testrsa.pem
+fi
+
+echo testing rsa conversions
+cp $t fff.p
+
+echo "p -> d"
+$cmd -in fff.p -inform p -outform d >f.d
+if [ $? != 0 ]; then exit 1; fi
+#echo "p -> t"
+#$cmd -in fff.p -inform p -outform t >f.t
+#if [ $? != 0 ]; then exit 1; fi
+echo "p -> p"
+$cmd -in fff.p -inform p -outform p >f.p
+if [ $? != 0 ]; then exit 1; fi
+
+echo "d -> d"
+$cmd -in f.d -inform d -outform d >ff.d1
+if [ $? != 0 ]; then exit 1; fi
+#echo "t -> d"
+#$cmd -in f.t -inform t -outform d >ff.d2
+#if [ $? != 0 ]; then exit 1; fi
+echo "p -> d"
+$cmd -in f.p -inform p -outform d >ff.d3
+if [ $? != 0 ]; then exit 1; fi
+
+#echo "d -> t"
+#$cmd -in f.d -inform d -outform t >ff.t1
+#if [ $? != 0 ]; then exit 1; fi
+#echo "t -> t"
+#$cmd -in f.t -inform t -outform t >ff.t2
+#if [ $? != 0 ]; then exit 1; fi
+#echo "p -> t"
+#$cmd -in f.p -inform p -outform t >ff.t3
+#if [ $? != 0 ]; then exit 1; fi
+
+echo "d -> p"
+$cmd -in f.d -inform d -outform p >ff.p1
+if [ $? != 0 ]; then exit 1; fi
+#echo "t -> p"
+#$cmd -in f.t -inform t -outform p >ff.p2
+#if [ $? != 0 ]; then exit 1; fi
+echo "p -> p"
+$cmd -in f.p -inform p -outform p >ff.p3
+if [ $? != 0 ]; then exit 1; fi
+
+cmp fff.p f.p
+if [ $? != 0 ]; then exit 1; fi
+cmp fff.p ff.p1
+if [ $? != 0 ]; then exit 1; fi
+#cmp fff.p ff.p2
+#if [ $? != 0 ]; then exit 1; fi
+cmp fff.p ff.p3
+if [ $? != 0 ]; then exit 1; fi
+
+#cmp f.t ff.t1
+#if [ $? != 0 ]; then exit 1; fi
+#cmp f.t ff.t2
+#if [ $? != 0 ]; then exit 1; fi
+#cmp f.t ff.t3
+#if [ $? != 0 ]; then exit 1; fi
+
+cmp f.p ff.p1
+if [ $? != 0 ]; then exit 1; fi
+#cmp f.p ff.p2
+#if [ $? != 0 ]; then exit 1; fi
+cmp f.p ff.p3
+if [ $? != 0 ]; then exit 1; fi
+
+/bin/rm -f f.* ff.* fff.*
+exit 0
diff --git a/deps/openssl/openssl/test/trsa.com b/deps/openssl/openssl/test/trsa.com
new file mode 100644 (file)
index 0000000..5418084
--- /dev/null
@@ -0,0 +1,99 @@
+$! TRSA.COM  --  Tests rsa keys
+$
+$      __arch = "VAX"
+$      if f$getsyi("cpu") .ge. 128 then -
+          __arch = f$edit( f$getsyi( "ARCH_NAME"), "UPCASE")
+$      if __arch .eqs. "" then __arch = "UNK"
+$!
+$      if (p2 .eqs. "64") then __arch = __arch+ "_64"
+$!
+$      exe_dir = "sys$disk:[-.''__arch'.exe.apps]"
+$
+$      set noon
+$      define/user sys$output nla0:
+$      mcr 'exe_dir'openssl no-rsa
+$      save_severity=$SEVERITY
+$      set on
+$      if save_severity
+$      then
+$          write sys$output "skipping RSA conversion test"
+$          exit
+$      endif
+$
+$      cmd = "mcr ''exe_dir'openssl rsa"
+$
+$      t = "testrsa.pem"
+$      if p1 .nes. "" then t = p1
+$
+$      write sys$output "testing RSA conversions"
+$      if f$search("fff.*") .nes "" then delete fff.*;*
+$      if f$search("ff.*") .nes "" then delete ff.*;*
+$      if f$search("f.*") .nes "" then delete f.*;*
+$      convert/fdl=sys$input: 't' fff.p
+RECORD
+       FORMAT STREAM_LF
+$
+$      write sys$output "p -> d"
+$      'cmd' -in fff.p -inform p -outform d -out f.d
+$      if $severity .ne. 1 then exit 3
+$!     write sys$output "p -> t"
+$!     'cmd' -in fff.p -inform p -outform t -out f.t
+$!     if $severity .ne. 1 then exit 3
+$      write sys$output "p -> p"
+$      'cmd' -in fff.p -inform p -outform p -out f.p
+$      if $severity .ne. 1 then exit 3
+$
+$      write sys$output "d -> d"
+$      'cmd' -in f.d -inform d -outform d -out ff.d1
+$      if $severity .ne. 1 then exit 3
+$!     write sys$output "t -> d"
+$!     'cmd' -in f.t -inform t -outform d -out ff.d2
+$!     if $severity .ne. 1 then exit 3
+$      write sys$output "p -> d"
+$      'cmd' -in f.p -inform p -outform d -out ff.d3
+$      if $severity .ne. 1 then exit 3
+$
+$!     write sys$output "d -> t"
+$!     'cmd' -in f.d -inform d -outform t -out ff.t1
+$!     if $severity .ne. 1 then exit 3
+$!     write sys$output "t -> t"
+$!     'cmd' -in f.t -inform t -outform t -out ff.t2
+$!     if $severity .ne. 1 then exit 3
+$!     write sys$output "p -> t"
+$!     'cmd' -in f.p -inform p -outform t -out ff.t3
+$!     if $severity .ne. 1 then exit 3
+$
+$      write sys$output "d -> p"
+$      'cmd' -in f.d -inform d -outform p -out ff.p1
+$      if $severity .ne. 1 then exit 3
+$!     write sys$output "t -> p"
+$!     'cmd' -in f.t -inform t -outform p -out ff.p2
+$!     if $severity .ne. 1 then exit 3
+$      write sys$output "p -> p"
+$      'cmd' -in f.p -inform p -outform p -out ff.p3
+$      if $severity .ne. 1 then exit 3
+$
+$      backup/compare fff.p f.p
+$      if $severity .ne. 1 then exit 3
+$      backup/compare fff.p ff.p1
+$      if $severity .ne. 1 then exit 3
+$!     backup/compare fff.p ff.p2
+$!     if $severity .ne. 1 then exit 3
+$      backup/compare fff.p ff.p3
+$      if $severity .ne. 1 then exit 3
+$
+$!     backup/compare f.t ff.t1
+$!     if $severity .ne. 1 then exit 3
+$!     backup/compare f.t ff.t2
+$!     if $severity .ne. 1 then exit 3
+$!     backup/compare f.t ff.t3
+$!     if $severity .ne. 1 then exit 3
+$
+$      backup/compare f.p ff.p1
+$      if $severity .ne. 1 then exit 3
+$!     backup/compare f.p ff.p2
+$!     if $severity .ne. 1 then exit 3
+$      backup/compare f.p ff.p3
+$      if $severity .ne. 1 then exit 3
+$
+$      delete f.*;*,ff.*;*,fff.*;*
diff --git a/deps/openssl/openssl/test/tsid b/deps/openssl/openssl/test/tsid
new file mode 100644 (file)
index 0000000..6adbd53
--- /dev/null
@@ -0,0 +1,78 @@
+#!/bin/sh
+
+cmd='../util/shlib_wrap.sh ../apps/openssl sess_id'
+
+if [ "$1"x != "x" ]; then
+       t=$1
+else
+       t=testsid.pem
+fi
+
+echo testing session-id conversions
+cp $t fff.p
+
+echo "p -> d"
+$cmd -in fff.p -inform p -outform d >f.d
+if [ $? != 0 ]; then exit 1; fi
+#echo "p -> t"
+#$cmd -in fff.p -inform p -outform t >f.t
+#if [ $? != 0 ]; then exit 1; fi
+echo "p -> p"
+$cmd -in fff.p -inform p -outform p >f.p
+if [ $? != 0 ]; then exit 1; fi
+
+echo "d -> d"
+$cmd -in f.d -inform d -outform d >ff.d1
+if [ $? != 0 ]; then exit 1; fi
+#echo "t -> d"
+#$cmd -in f.t -inform t -outform d >ff.d2
+#if [ $? != 0 ]; then exit 1; fi
+echo "p -> d"
+$cmd -in f.p -inform p -outform d >ff.d3
+if [ $? != 0 ]; then exit 1; fi
+
+#echo "d -> t"
+#$cmd -in f.d -inform d -outform t >ff.t1
+#if [ $? != 0 ]; then exit 1; fi
+#echo "t -> t"
+#$cmd -in f.t -inform t -outform t >ff.t2
+#if [ $? != 0 ]; then exit 1; fi
+#echo "p -> t"
+#$cmd -in f.p -inform p -outform t >ff.t3
+#if [ $? != 0 ]; then exit 1; fi
+
+echo "d -> p"
+$cmd -in f.d -inform d -outform p >ff.p1
+if [ $? != 0 ]; then exit 1; fi
+#echo "t -> p"
+#$cmd -in f.t -inform t -outform p >ff.p2
+#if [ $? != 0 ]; then exit 1; fi
+echo "p -> p"
+$cmd -in f.p -inform p -outform p >ff.p3
+if [ $? != 0 ]; then exit 1; fi
+
+cmp fff.p f.p
+if [ $? != 0 ]; then exit 1; fi
+cmp fff.p ff.p1
+if [ $? != 0 ]; then exit 1; fi
+#cmp fff.p ff.p2
+#if [ $? != 0 ]; then exit 1; fi
+cmp fff.p ff.p3
+if [ $? != 0 ]; then exit 1; fi
+
+#cmp f.t ff.t1
+#if [ $? != 0 ]; then exit 1; fi
+#cmp f.t ff.t2
+#if [ $? != 0 ]; then exit 1; fi
+#cmp f.t ff.t3
+#if [ $? != 0 ]; then exit 1; fi
+
+cmp f.p ff.p1
+if [ $? != 0 ]; then exit 1; fi
+#cmp f.p ff.p2
+#if [ $? != 0 ]; then exit 1; fi
+cmp f.p ff.p3
+if [ $? != 0 ]; then exit 1; fi
+
+/bin/rm -f f.* ff.* fff.*
+exit 0
diff --git a/deps/openssl/openssl/test/tsid.com b/deps/openssl/openssl/test/tsid.com
new file mode 100644 (file)
index 0000000..b6c4e49
--- /dev/null
@@ -0,0 +1,88 @@
+$! TSID.COM  --  Tests sid keys
+$
+$      __arch = "VAX"
+$      if f$getsyi("cpu") .ge. 128 then -
+          __arch = f$edit( f$getsyi( "ARCH_NAME"), "UPCASE")
+$      if __arch .eqs. "" then __arch = "UNK"
+$!
+$      if (p2 .eqs. "64") then __arch = __arch+ "_64"
+$!
+$      exe_dir = "sys$disk:[-.''__arch'.exe.apps]"
+$
+$      cmd = "mcr ''exe_dir'openssl sess_id"
+$
+$      t = "testsid.pem"
+$      if p1 .nes. "" then t = p1
+$
+$      write sys$output "testing session-id conversions"
+$      if f$search("fff.*") .nes "" then delete fff.*;*
+$      if f$search("ff.*") .nes "" then delete ff.*;*
+$      if f$search("f.*") .nes "" then delete f.*;*
+$      convert/fdl=sys$input: 't' fff.p
+RECORD
+       FORMAT STREAM_LF
+$
+$      write sys$output "p -> d"
+$      'cmd' -in fff.p -inform p -outform d -out f.d
+$      if $severity .ne. 1 then exit 3
+$!     write sys$output "p -> t"
+$!     'cmd' -in fff.p -inform p -outform t -out f.t
+$!     if $severity .ne. 1 then exit 3
+$      write sys$output "p -> p"
+$      'cmd' -in fff.p -inform p -outform p -out f.p
+$      if $severity .ne. 1 then exit 3
+$
+$      write sys$output "d -> d"
+$      'cmd' -in f.d -inform d -outform d -out ff.d1
+$      if $severity .ne. 1 then exit 3
+$!     write sys$output "t -> d"
+$!     'cmd' -in f.t -inform t -outform d -out ff.d2
+$!     if $severity .ne. 1 then exit 3
+$      write sys$output "p -> d"
+$      'cmd' -in f.p -inform p -outform d -out ff.d3
+$      if $severity .ne. 1 then exit 3
+$
+$!     write sys$output "d -> t"
+$!     'cmd' -in f.d -inform d -outform t -out ff.t1
+$!     if $severity .ne. 1 then exit 3
+$!     write sys$output "t -> t"
+$!     'cmd' -in f.t -inform t -outform t -out ff.t2
+$!     if $severity .ne. 1 then exit 3
+$!     write sys$output "p -> t"
+$!     'cmd' -in f.p -inform p -outform t -out ff.t3
+$!     if $severity .ne. 1 then exit 3
+$
+$      write sys$output "d -> p"
+$      'cmd' -in f.d -inform d -outform p -out ff.p1
+$      if $severity .ne. 1 then exit 3
+$!     write sys$output "t -> p"
+$!     'cmd' -in f.t -inform t -outform p -out ff.p2
+$!     if $severity .ne. 1 then exit 3
+$      write sys$output "p -> p"
+$      'cmd' -in f.p -inform p -outform p -out ff.p3
+$      if $severity .ne. 1 then exit 3
+$
+$      backup/compare fff.p f.p
+$      if $severity .ne. 1 then exit 3
+$      backup/compare fff.p ff.p1
+$      if $severity .ne. 1 then exit 3
+$!     backup/compare fff.p ff.p2
+$!     if $severity .ne. 1 then exit 3
+$      backup/compare fff.p ff.p3
+$      if $severity .ne. 1 then exit 3
+$
+$!     backup/compare f.t ff.t1
+$!     if $severity .ne. 1 then exit 3
+$!     backup/compare f.t ff.t2
+$!     if $severity .ne. 1 then exit 3
+$!     backup/compare f.t ff.t3
+$!     if $severity .ne. 1 then exit 3
+$
+$      backup/compare f.p ff.p1
+$      if $severity .ne. 1 then exit 3
+$!     backup/compare f.p ff.p2
+$!     if $severity .ne. 1 then exit 3
+$      backup/compare f.p ff.p3
+$      if $severity .ne. 1 then exit 3
+$
+$      delete f.*;*,ff.*;*,fff.*;*
diff --git a/deps/openssl/openssl/test/tverify.com b/deps/openssl/openssl/test/tverify.com
new file mode 100644 (file)
index 0000000..d888344
--- /dev/null
@@ -0,0 +1,65 @@
+$! TVERIFY.COM
+$
+$      __arch = "VAX"
+$      if f$getsyi("cpu") .ge. 128 then -
+          __arch = f$edit( f$getsyi( "ARCH_NAME"), "UPCASE")
+$      if __arch .eqs. "" then __arch = "UNK"
+$!
+$      if (p1 .eqs. "64") then __arch = __arch+ "_64"
+$!
+$      line_max = 255 ! Could be longer on modern non-VAX.
+$      temp_file_name = "certs_"+ f$getjpi( "", "PID")+ ".tmp"
+$      exe_dir = "sys$disk:[-.''__arch'.exe.apps]"
+$      cmd = "mcr ''exe_dir'openssl verify ""-CAfile"" ''temp_file_name'"
+$      cmd_len = f$length( cmd)
+$      pems = "[-.certs...]*.pem"
+$!
+$!     Concatenate all the certificate files.
+$!
+$      copy /concatenate 'pems' 'temp_file_name'
+$!
+$!     Loop through all the certificate files.
+$!
+$      args = ""
+$      old_f = ""
+$ loop_file: 
+$          f = f$search( pems)
+$          if ((f .nes. "") .and. (f .nes. old_f))
+$          then
+$            old_f = f
+$!
+$!           If this file name would over-extend the command line, then
+$!           run the command now.
+$!
+$            if (cmd_len+ f$length( args)+ 1+ f$length( f) .gt. line_max)
+$            then
+$               if (args .eqs. "") then goto disaster
+$               'cmd''args'
+$               args = ""
+$            endif
+$!           Add the next file to the argument list.
+$            args = args+ " "+ f
+$         else
+$!            No more files in the list
+$            goto loop_file_end
+$         endif
+$      goto loop_file
+$      loop_file_end:
+$!
+$!     Run the command for any left-over arguments.
+$!
+$      if (args .nes. "")
+$      then
+$         'cmd''args'
+$      endif
+$!
+$!     Delete the temporary file.
+$!
+$      if (f$search( "''temp_file_name';*") .nes. "") then -
+        delete 'temp_file_name';*
+$!
+$      exit
+$!
+$      disaster:
+$      write sys$output "   Command line too long.  Doomed."
+$!
diff --git a/deps/openssl/openssl/test/tx509 b/deps/openssl/openssl/test/tx509
new file mode 100644 (file)
index 0000000..4a15b98
--- /dev/null
@@ -0,0 +1,78 @@
+#!/bin/sh
+
+cmd='../util/shlib_wrap.sh ../apps/openssl x509'
+
+if [ "$1"x != "x" ]; then
+       t=$1
+else
+       t=testx509.pem
+fi
+
+echo testing X509 conversions
+cp $t fff.p
+
+echo "p -> d"
+$cmd -in fff.p -inform p -outform d >f.d
+if [ $? != 0 ]; then exit 1; fi
+echo "p -> n"
+$cmd -in fff.p -inform p -outform n >f.n
+if [ $? != 0 ]; then exit 1; fi
+echo "p -> p"
+$cmd -in fff.p -inform p -outform p >f.p
+if [ $? != 0 ]; then exit 1; fi
+
+echo "d -> d"
+$cmd -in f.d -inform d -outform d >ff.d1
+if [ $? != 0 ]; then exit 1; fi
+echo "n -> d"
+$cmd -in f.n -inform n -outform d >ff.d2
+if [ $? != 0 ]; then exit 1; fi
+echo "p -> d"
+$cmd -in f.p -inform p -outform d >ff.d3
+if [ $? != 0 ]; then exit 1; fi
+
+echo "d -> n"
+$cmd -in f.d -inform d -outform n >ff.n1
+if [ $? != 0 ]; then exit 1; fi
+echo "n -> n"
+$cmd -in f.n -inform n -outform n >ff.n2
+if [ $? != 0 ]; then exit 1; fi
+echo "p -> n"
+$cmd -in f.p -inform p -outform n >ff.n3
+if [ $? != 0 ]; then exit 1; fi
+
+echo "d -> p"
+$cmd -in f.d -inform d -outform p >ff.p1
+if [ $? != 0 ]; then exit 1; fi
+echo "n -> p"
+$cmd -in f.n -inform n -outform p >ff.p2
+if [ $? != 0 ]; then exit 1; fi
+echo "p -> p"
+$cmd -in f.p -inform p -outform p >ff.p3
+if [ $? != 0 ]; then exit 1; fi
+
+cmp fff.p f.p
+if [ $? != 0 ]; then exit 1; fi
+cmp fff.p ff.p1
+if [ $? != 0 ]; then exit 1; fi
+cmp fff.p ff.p2
+if [ $? != 0 ]; then exit 1; fi
+cmp fff.p ff.p3
+if [ $? != 0 ]; then exit 1; fi
+
+cmp f.n ff.n1
+if [ $? != 0 ]; then exit 1; fi
+cmp f.n ff.n2
+if [ $? != 0 ]; then exit 1; fi
+cmp f.n ff.n3
+if [ $? != 0 ]; then exit 1; fi
+
+cmp f.p ff.p1
+if [ $? != 0 ]; then exit 1; fi
+cmp f.p ff.p2
+if [ $? != 0 ]; then exit 1; fi
+cmp f.p ff.p3
+if [ $? != 0 ]; then exit 1; fi
+
+/bin/rm -f f.* ff.* fff.*
+exit 0
diff --git a/deps/openssl/openssl/test/tx509.com b/deps/openssl/openssl/test/tx509.com
new file mode 100644 (file)
index 0000000..93ce988
--- /dev/null
@@ -0,0 +1,88 @@
+$! TX509.COM  --  Tests x509 certificates
+$
+$      __arch = "VAX"
+$      if f$getsyi("cpu") .ge. 128 then -
+          __arch = f$edit( f$getsyi( "ARCH_NAME"), "UPCASE")
+$      if __arch .eqs. "" then __arch = "UNK"
+$!
+$      if (p2 .eqs. "64") then __arch = __arch+ "_64"
+$!
+$      exe_dir = "sys$disk:[-.''__arch'.exe.apps]"
+$
+$      cmd = "mcr ''exe_dir'openssl x509"
+$
+$      t = "testx509.pem"
+$      if p1 .nes. "" then t = p1
+$
+$      write sys$output "testing X509 conversions"
+$      if f$search("fff.*") .nes "" then delete fff.*;*
+$      if f$search("ff.*") .nes "" then delete ff.*;*
+$      if f$search("f.*") .nes "" then delete f.*;*
+$      convert/fdl=sys$input: 't' fff.p
+RECORD
+       FORMAT STREAM_LF
+$
+$      write sys$output "p -> d"
+$      'cmd' -in fff.p -inform p -outform d -out f.d
+$      if $severity .ne. 1 then exit 3
+$      write sys$output "p -> n"
+$      'cmd' -in fff.p -inform p -outform n -out f.n
+$      if $severity .ne. 1 then exit 3
+$      write sys$output "p -> p"
+$      'cmd' -in fff.p -inform p -outform p -out f.p
+$      if $severity .ne. 1 then exit 3
+$
+$      write sys$output "d -> d"
+$      'cmd' -in f.d -inform d -outform d -out ff.d1
+$      if $severity .ne. 1 then exit 3
+$      write sys$output "n -> d"
+$      'cmd' -in f.n -inform n -outform d -out ff.d2
+$      if $severity .ne. 1 then exit 3
+$      write sys$output "p -> d"
+$      'cmd' -in f.p -inform p -outform d -out ff.d3
+$      if $severity .ne. 1 then exit 3
+$
+$      write sys$output "d -> n"
+$      'cmd' -in f.d -inform d -outform n -out ff.n1
+$      if $severity .ne. 1 then exit 3
+$      write sys$output "n -> n"
+$      'cmd' -in f.n -inform n -outform n -out ff.n2
+$      if $severity .ne. 1 then exit 3
+$      write sys$output "p -> n"
+$      'cmd' -in f.p -inform p -outform n -out ff.n3
+$      if $severity .ne. 1 then exit 3
+$
+$      write sys$output "d -> p"
+$      'cmd' -in f.d -inform d -outform p -out ff.p1
+$      if $severity .ne. 1 then exit 3
+$      write sys$output "n -> p"
+$      'cmd' -in f.n -inform n -outform p -out ff.p2
+$      if $severity .ne. 1 then exit 3
+$      write sys$output "p -> p"
+$      'cmd' -in f.p -inform p -outform p -out ff.p3
+$      if $severity .ne. 1 then exit 3
+$
+$      backup/compare fff.p f.p
+$      if $severity .ne. 1 then exit 3
+$      backup/compare fff.p ff.p1
+$      if $severity .ne. 1 then exit 3
+$      backup/compare fff.p ff.p2
+$      if $severity .ne. 1 then exit 3
+$      backup/compare fff.p ff.p3
+$      if $severity .ne. 1 then exit 3
+$
+$      backup/compare f.n ff.n1
+$      if $severity .ne. 1 then exit 3
+$      backup/compare f.n ff.n2
+$      if $severity .ne. 1 then exit 3
+$      backup/compare f.n ff.n3
+$      if $severity .ne. 1 then exit 3
+$
+$      backup/compare f.p ff.p1
+$      if $severity .ne. 1 then exit 3
+$      backup/compare f.p ff.p2
+$      if $severity .ne. 1 then exit 3
+$      backup/compare f.p ff.p3
+$      if $severity .ne. 1 then exit 3
+$
+$      delete f.*;*,ff.*;*,fff.*;*
diff --git a/deps/openssl/openssl/test/v3-cert1.pem b/deps/openssl/openssl/test/v3-cert1.pem
new file mode 100644 (file)
index 0000000..0da253d
--- /dev/null
@@ -0,0 +1,16 @@
+-----BEGIN CERTIFICATE-----
+MIICjTCCAfigAwIBAgIEMaYgRzALBgkqhkiG9w0BAQQwRTELMAkGA1UEBhMCVVMx
+NjA0BgNVBAoTLU5hdGlvbmFsIEFlcm9uYXV0aWNzIGFuZCBTcGFjZSBBZG1pbmlz
+dHJhdGlvbjAmFxE5NjA1MjgxMzQ5MDUrMDgwMBcROTgwNTI4MTM0OTA1KzA4MDAw
+ZzELMAkGA1UEBhMCVVMxNjA0BgNVBAoTLU5hdGlvbmFsIEFlcm9uYXV0aWNzIGFu
+ZCBTcGFjZSBBZG1pbmlzdHJhdGlvbjEgMAkGA1UEBRMCMTYwEwYDVQQDEwxTdGV2
+ZSBTY2hvY2gwWDALBgkqhkiG9w0BAQEDSQAwRgJBALrAwyYdgxmzNP/ts0Uyf6Bp
+miJYktU/w4NG67ULaN4B5CnEz7k57s9o3YY3LecETgQ5iQHmkwlYDTL2fTgVfw0C
+AQOjgaswgagwZAYDVR0ZAQH/BFowWDBWMFQxCzAJBgNVBAYTAlVTMTYwNAYDVQQK
+Ey1OYXRpb25hbCBBZXJvbmF1dGljcyBhbmQgU3BhY2UgQWRtaW5pc3RyYXRpb24x
+DTALBgNVBAMTBENSTDEwFwYDVR0BAQH/BA0wC4AJODMyOTcwODEwMBgGA1UdAgQR
+MA8ECTgzMjk3MDgyM4ACBSAwDQYDVR0KBAYwBAMCBkAwCwYJKoZIhvcNAQEEA4GB
+AH2y1VCEw/A4zaXzSYZJTTUi3uawbbFiS2yxHvgf28+8Js0OHXk1H1w2d6qOHH21
+X82tZXd/0JtG0g1T9usFFBDvYK8O0ebgz/P5ELJnBL2+atObEuJy1ZZ0pBDWINR3
+WkDNLCGiTkCKp0F5EWIrVDwh54NNevkCQRZita+z4IBO
+-----END CERTIFICATE-----
diff --git a/deps/openssl/openssl/test/v3-cert2.pem b/deps/openssl/openssl/test/v3-cert2.pem
new file mode 100644 (file)
index 0000000..de0723f
--- /dev/null
@@ -0,0 +1,16 @@
+-----BEGIN CERTIFICATE-----
+MIICiTCCAfKgAwIBAgIEMeZfHzANBgkqhkiG9w0BAQQFADB9MQswCQYDVQQGEwJD
+YTEPMA0GA1UEBxMGTmVwZWFuMR4wHAYDVQQLExVObyBMaWFiaWxpdHkgQWNjZXB0
+ZWQxHzAdBgNVBAoTFkZvciBEZW1vIFB1cnBvc2VzIE9ubHkxHDAaBgNVBAMTE0Vu
+dHJ1c3QgRGVtbyBXZWIgQ0EwHhcNOTYwNzEyMTQyMDE1WhcNOTYxMDEyMTQyMDE1
+WjB0MSQwIgYJKoZIhvcNAQkBExVjb29rZUBpc3NsLmF0bC5ocC5jb20xCzAJBgNV
+BAYTAlVTMScwJQYDVQQLEx5IZXdsZXR0IFBhY2thcmQgQ29tcGFueSAoSVNTTCkx
+FjAUBgNVBAMTDVBhdWwgQS4gQ29va2UwXDANBgkqhkiG9w0BAQEFAANLADBIAkEA
+6ceSq9a9AU6g+zBwaL/yVmW1/9EE8s5you1mgjHnj0wAILuoB3L6rm6jmFRy7QZT
+G43IhVZdDua4e+5/n1ZslwIDAQABo2MwYTARBglghkgBhvhCAQEEBAMCB4AwTAYJ
+YIZIAYb4QgENBD8WPVRoaXMgY2VydGlmaWNhdGUgaXMgb25seSBpbnRlbmRlZCBm
+b3IgZGVtb25zdHJhdGlvbiBwdXJwb3Nlcy4wDQYJKoZIhvcNAQEEBQADgYEAi8qc
+F3zfFqy1sV8NhjwLVwOKuSfhR/Z8mbIEUeSTlnH3QbYt3HWZQ+vXI8mvtZoBc2Fz
+lexKeIkAZXCesqGbs6z6nCt16P6tmdfbZF3I3AWzLquPcOXjPf4HgstkyvVBn0Ap
+jAFN418KF/Cx4qyHB4cjdvLrRjjQLnb2+ibo7QU=
+-----END CERTIFICATE-----
diff --git a/deps/openssl/openssl/test/wp_test.c b/deps/openssl/openssl/test/wp_test.c
new file mode 100644 (file)
index 0000000..7a4bb75
--- /dev/null
@@ -0,0 +1 @@
+link ../crypto/whrlpool/wp_test.c
\ No newline at end of file
diff --git a/deps/openssl/openssl/times/090/586-100.nt b/deps/openssl/openssl/times/090/586-100.nt
new file mode 100644 (file)
index 0000000..297ec3e
--- /dev/null
@@ -0,0 +1,32 @@
+SSLeay 0.9.0 08-Apr-1998
+built on Wed Apr  8 12:47:17 EST 1998
+options:bn(64,32) md2(int) rc4(idx,int) des(idx,cisc,4,long) idea(int) blowfish(
+ptr2)
+C flags:cl /MD /W3 /WX /G5 /Ox /O2 /Ob2 /Gs0 /GF /Gy /nologo -DWIN32 -DL_ENDIAN
+-DBN_ASM -DMD5_ASM -DSHA1_ASM -DRMD160_ASM
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                 92.25k      256.80k      347.01k      380.40k      390.31k
+mdc2               240.72k      251.10k      252.00k      250.80k      251.40k
+md5               1013.61k     5651.94k    11831.61k    16294.89k    17901.43k
+hmac(md5)          419.50k     2828.07k     7770.11k    13824.34k    17091.70k
+sha1               524.31k     2721.45k     5216.15k     6766.10k     7308.42k
+rmd160             462.09k     2288.59k     4260.77k     5446.44k     5841.65k
+rc4               7895.90k    10326.73k    10555.43k    10728.22k    10429.44k
+des cbc           2036.86k     2208.92k     2237.68k     2237.20k     2181.35k
+des ede3           649.92k      739.42k      749.07k      748.86k      738.27k
+idea cbc           823.19k      885.10k      894.92k      896.45k      891.87k
+rc2 cbc            792.63k      859.00k      867.45k      868.96k      865.30k
+rc5-32/12 cbc     3502.26k     4026.79k     4107.23k     4121.76k     4073.72k
+blowfish cbc      3752.96k     4026.79k     4075.31k     3965.87k     3892.26k
+cast cbc          2566.27k     2807.43k     2821.79k     2792.48k     2719.34k
+                  sign    verify    sign/s verify/s
+rsa  512 bits   0.0179s   0.0020s     56.0    501.7
+rsa 1024 bits   0.0950s   0.0060s     10.5    166.6
+rsa 2048 bits   0.6299s   0.0209s      1.6     47.8
+rsa 4096 bits   4.5870s   0.0787s      0.2     12.7
+                  sign    verify    sign/s verify/s
+dsa  512 bits   0.0180s   0.0339s     55.6     29.5
+dsa 1024 bits   0.0555s   0.1076s     18.0      9.3
+dsa 2048 bits   0.1971s   0.3918s      5.1      2.6
+
diff --git a/deps/openssl/openssl/times/091/486-50.nt b/deps/openssl/openssl/times/091/486-50.nt
new file mode 100644 (file)
index 0000000..84820d9
--- /dev/null
@@ -0,0 +1,30 @@
+486-50 NT 4.0
+
+SSLeay 0.9.1a 06-Jul-1998
+built on Sat Jul 18 18:03:20 EST 1998
+options:bn(64,32) md2(int) rc4(idx,int) des(idx,cisc,4,long) idea(int) blowfish(ptr2)
+C flags:cl /MD /W3 /WX /G5 /Ox /O2 /Ob2 /Gs0 /GF /Gy /nologo -DWIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DBN_ASM -DMD5_ASM -DSHA1_ASM -DRMD160_ASM /Fdout32
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                 28.77k       80.30k      108.50k      118.98k      122.47k
+mdc2                51.52k       54.06k       54.54k       54.65k       54.62k
+md5                304.39k     1565.04k     3061.54k     3996.10k     4240.10k
+hmac(md5)          119.53k      793.23k     2061.29k     3454.95k     4121.76k
+sha1               127.51k      596.93k     1055.54k     1313.84k     1413.18k
+rmd160             128.50k      572.49k     1001.03k     1248.01k     1323.63k
+rc4               1224.40k     1545.11k     1590.29k     1600.20k     1576.90k
+des cbc            448.19k      503.45k      512.30k      513.30k      508.23k
+des ede3           148.66k      162.48k      163.68k      163.94k      164.24k
+idea cbc           194.18k      211.10k      212.99k      213.18k      212.64k
+rc2 cbc            245.78k      271.01k      274.12k      274.38k      273.52k
+rc5-32/12 cbc     1252.48k     1625.20k     1700.03k     1711.12k     1677.18k
+blowfish cbc       725.16k      828.26k      850.01k      846.99k      833.79k
+cast cbc           643.30k      717.22k      739.48k      741.57k      735.33k
+                  sign    verify    sign/s verify/s
+rsa  512 bits   0.0904s   0.0104s     11.1     96.2
+rsa 1024 bits   0.5968s   0.0352s      1.7     28.4
+rsa 2048 bits   3.8860s   0.1017s      0.3      9.8
+                  sign    verify    sign/s verify/s
+dsa  512 bits   0.1006s   0.1249s      9.9      8.0
+dsa 1024 bits   0.3306s   0.4093s      3.0      2.4
+dsa 2048 bits   0.9454s   1.1707s      1.1      0.9
diff --git a/deps/openssl/openssl/times/091/586-100.lnx b/deps/openssl/openssl/times/091/586-100.lnx
new file mode 100644 (file)
index 0000000..92892a6
--- /dev/null
@@ -0,0 +1,32 @@
+Pentium 100mhz, linux
+
+SSLeay 0.9.0a 14-Apr-1998
+built on Fri Apr 17 08:47:07 EST 1998
+options:bn(64,32) md2(int) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2)
+C flags:gcc -DL_ENDIAN -DTERMIO -DBN_ASM -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized -DSHA1_ASM -DMD5_ASM -DRMD160_ASM
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                 56.65k      153.88k      208.47k      229.03k      237.57k
+mdc2               189.59k      204.95k      206.93k      208.90k      209.56k
+md5               1019.48k     5882.41k    12085.42k    16376.49k    18295.47k
+hmac(md5)          415.86k     2887.85k     7891.29k    13894.66k    17446.23k
+sha1               540.68k     2791.96k     5289.30k     6813.01k     7432.87k
+rmd160             298.37k     1846.87k     3869.10k     5273.94k     5892.78k
+rc4               7870.87k    10438.10k    10857.13k    10729.47k    10788.86k
+des cbc           1960.60k     2226.37k     2241.88k     2054.83k     2181.80k
+des ede3           734.44k      739.69k      779.43k      750.25k      772.78k
+idea cbc           654.07k      711.00k      716.89k      718.51k      720.90k
+rc2 cbc            648.83k      701.91k      708.61k      708.95k      709.97k
+rc5-32/12 cbc     3504.71k     4054.76k     4131.41k     4105.56k     4134.23k
+blowfish cbc      3762.25k     4313.79k     4460.54k     4356.78k     4317.18k
+cast cbc          2755.01k     3038.91k     3076.44k     3027.63k     2998.27k
+                  sign    verify    sign/s verify/s
+rsa  512 bits   0.0195s   0.0019s     51.4    519.9
+rsa 1024 bits   0.1000s   0.0059s     10.0    168.2
+rsa 2048 bits   0.6406s   0.0209s      1.6     47.8
+rsa 4096 bits   4.6100s   0.0787s      0.2     12.7
+                  sign    verify    sign/s verify/s
+dsa  512 bits   0.0188s   0.0360s     53.1     27.8
+dsa 1024 bits   0.0570s   0.1126s     17.5      8.9
+dsa 2048 bits   0.1990s   0.3954s      5.0      2.5
+
diff --git a/deps/openssl/openssl/times/091/68000.bsd b/deps/openssl/openssl/times/091/68000.bsd
new file mode 100644 (file)
index 0000000..a3a14e8
--- /dev/null
@@ -0,0 +1,32 @@
+Motorolla 68020 20mhz, NetBSD
+
+SSLeay 0.9.0t 29-May-1998
+built on Fri Jun  5 12:42:23 EST 1998
+options:bn(64,32) md2(char) rc4(idx,int) des(idx,cisc,16,long) idea(int) blowfish(idx) 
+C flags:gcc -DTERMIOS -O3 -fomit-frame-pointer -Wall -DB_ENDIAN
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2               2176.00      5994.67      8079.73      8845.18      9077.01 
+mdc2              5730.67      6122.67      6167.66      6176.51      6174.87 
+md5                 29.10k      127.31k      209.66k      250.50k      263.99k
+hmac(md5)           12.33k       73.02k      160.17k      228.04k      261.15k
+sha1                11.27k       49.37k       84.31k      102.40k      109.23k
+rmd160              11.69k       48.62k       78.76k       93.15k       98.41k
+rc4                117.96k      148.94k      152.57k      153.09k      152.92k
+des cbc             27.13k       30.06k       30.38k       30.38k       30.53k
+des ede3            10.51k       10.94k       11.01k       11.01k       11.01k
+idea cbc            26.74k       29.23k       29.45k       29.60k       29.74k
+rc2 cbc             34.27k       39.39k       40.03k       40.07k       40.16k
+rc5-32/12 cbc       64.31k       83.18k       85.70k       86.70k       87.09k
+blowfish cbc        48.86k       59.18k       60.07k       60.42k       60.78k
+cast cbc            42.67k       50.01k       50.86k       51.20k       51.37k
+                  sign    verify    sign/s verify/s
+rsa  512 bits   0.7738s   0.0774s      1.3     12.9
+rsa 1024 bits   4.3967s   0.2615s      0.2      3.8
+rsa 2048 bits  29.5200s   0.9664s      0.0      1.0
+                  sign    verify    sign/s verify/s
+dsa  512 bits   0.7862s   0.9709s      1.3      1.0
+dsa 1024 bits   2.5375s   3.1625s      0.4      0.3
+dsa 2048 bits   9.2150s  11.8200s      0.1      0.1
+
+
diff --git a/deps/openssl/openssl/times/091/686-200.lnx b/deps/openssl/openssl/times/091/686-200.lnx
new file mode 100644 (file)
index 0000000..bb857d4
--- /dev/null
@@ -0,0 +1,32 @@
+Pentium Pro 200mhz, linux
+
+SSLeay 0.9.0d 26-Apr-1998
+built on Sun Apr 26 10:25:33 EST 1998
+options:bn(64,32) md2(int) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2) 
+C flags:gcc -DL_ENDIAN -DTERMIO -DBN_ASM -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized -DSHA1_ASM -DMD5_ASM -DRMD160_ASM
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                130.58k      364.54k      499.24k      545.79k      561.66k
+mdc2               526.68k      579.72k      588.37k      588.80k      589.82k
+md5               1917.71k    11434.69k    22512.21k    29495.30k    32677.89k
+hmac(md5)          749.18k     5264.83k    14227.20k    25018.71k    31760.38k
+sha1              1343.83k     6436.29k    11702.78k    14664.70k    15829.67k
+rmd160            1038.05k     5138.77k     8985.51k    10985.13k    11799.21k
+rc4              14891.04k    21334.06k    22376.79k    22579.54k    22574.42k
+des cbc           4131.97k     4568.31k     4645.29k     4631.21k     4572.73k
+des ede3          1567.17k     1631.13k     1657.32k     1653.08k     1643.86k
+idea cbc          2427.23k     2671.21k     2716.67k     2723.84k     2733.40k
+rc2 cbc           1629.90k     1767.38k     1788.50k     1797.12k     1799.51k
+rc5-32/12 cbc    10290.55k    13161.60k    13744.55k    14011.73k    14123.01k
+blowfish cbc      5896.42k     6920.77k     7122.01k     7151.62k     7146.15k
+cast cbc          6037.71k     6935.19k     7101.35k     7145.81k     7116.12k
+                  sign    verify    sign/s verify/s
+rsa  512 bits   0.0070s   0.0007s    142.6   1502.9
+rsa 1024 bits   0.0340s   0.0019s     29.4    513.3
+rsa 2048 bits   0.2087s   0.0066s      4.8    151.3
+rsa 4096 bits   1.4700s   0.0242s      0.7     41.2
+                  sign    verify    sign/s verify/s
+dsa  512 bits   0.0064s   0.0121s    156.1     82.9
+dsa 1024 bits   0.0184s   0.0363s     54.4     27.5
+dsa 2048 bits   0.0629s   0.1250s     15.9      8.0
+
diff --git a/deps/openssl/openssl/times/091/alpha064.osf b/deps/openssl/openssl/times/091/alpha064.osf
new file mode 100644 (file)
index 0000000..a8e7fdf
--- /dev/null
@@ -0,0 +1,32 @@
+Alpha EV4.5 (21064) 275mhz, OSF1 V4.0
+SSLeay 0.9.0g 01-May-1998
+built on Mon May  4 17:26:09 CST 1998
+options:bn(64,64) md2(int) rc4(ptr,int) des(idx,cisc,4,long) idea(int) blowfish(idx) 
+C flags:cc -tune host -O4 -readonly_strings
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                119.58k      327.48k      443.28k      480.09k      495.16k
+mdc2               436.67k      456.35k      465.42k      466.57k      469.01k
+md5               1459.34k     6566.46k    11111.91k    13375.30k    14072.60k
+hmac(md5)          597.90k     3595.45k     8180.88k    12099.49k    13884.46k
+sha1               707.01k     3253.09k     6131.73k     7798.23k     8439.67k
+rmd160             618.57k     2729.07k     4711.33k     5825.16k     6119.23k
+rc4               8796.43k     9393.62k     9548.88k     9378.77k     9472.57k
+des cbc           2165.97k     2514.90k     2586.27k     2572.93k     2639.08k
+des ede3           945.44k     1004.03k     1005.96k     1017.33k     1020.85k
+idea cbc          1498.81k     1629.11k     1637.28k     1625.50k     1641.11k
+rc2 cbc           1866.00k     2044.92k     2067.12k     2064.00k     2068.96k
+rc5-32/12 cbc     4366.97k     5521.32k     5687.50k     5729.16k     5736.96k
+blowfish cbc      3997.31k     4790.60k     4937.84k     4954.56k     5024.85k
+cast cbc          2900.19k     3673.30k     3803.73k     3823.93k     3890.25k
+                  sign    verify    sign/s verify/s
+rsa  512 bits   0.0069s   0.0006s    144.2   1545.8
+rsa 1024 bits   0.0304s   0.0018s     32.9    552.6
+rsa 2048 bits   0.1887s   0.0062s      5.3    161.4
+rsa 4096 bits   1.3667s   0.0233s      0.7     42.9
+                  sign    verify    sign/s verify/s
+dsa  512 bits   0.0067s   0.0123s    149.6     81.1
+dsa 1024 bits   0.0177s   0.0332s     56.6     30.1
+dsa 2048 bits   0.0590s   0.1162s     16.9      8.6
+
+
diff --git a/deps/openssl/openssl/times/091/alpha164.lnx b/deps/openssl/openssl/times/091/alpha164.lnx
new file mode 100644 (file)
index 0000000..c994662
--- /dev/null
@@ -0,0 +1,32 @@
+Alpha EV5.6 (21164A) 533mhz, Linux 2.0.32
+
+SSLeay 0.9.0p 22-May-1998
+built on Sun May 27 14:23:38 GMT 2018
+options:bn(64,64) md2(int) rc4(ptr,int) des(idx,risc1,16,long) idea(int) blowfish(idx) 
+C flags:gcc -O3
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                295.78k      825.34k     1116.42k     1225.10k     1262.65k
+mdc2               918.16k     1017.55k     1032.18k     1034.24k     1035.60k
+md5               3574.93k    15517.05k    25482.67k    30434.31k    32210.51k
+hmac(md5)         1261.54k     7757.15k    18025.46k    27081.21k    31653.27k
+sha1              2251.89k    10056.84k    16990.19k    20651.04k    21973.29k
+rmd160            1615.49k     7017.13k    11601.11k    13875.62k    14690.31k
+rc4              22435.16k    24476.40k    24349.95k    23042.36k    24581.53k
+des cbc           5198.38k     6559.04k     6775.43k     6827.87k     6875.82k
+des ede3          2257.73k     2602.18k     2645.60k     2657.12k     2670.59k
+idea cbc          3694.42k     4125.61k     4180.74k     4193.28k     4192.94k
+rc2 cbc           4642.47k     5323.85k     5415.42k     5435.86k     5434.03k
+rc5-32/12 cbc     9705.26k    13277.79k    13843.46k    13989.66k    13987.57k
+blowfish cbc      7861.28k    10852.34k    11447.98k    11616.97k    11667.54k
+cast cbc          6718.13k     8599.98k     8967.17k     9070.81k     9099.28k
+                  sign    verify    sign/s verify/s
+rsa  512 bits   0.0018s   0.0002s    555.9   6299.5
+rsa 1024 bits   0.0081s   0.0005s    123.3   2208.7
+rsa 2048 bits   0.0489s   0.0015s     20.4    648.5
+rsa 4096 bits   0.3402s   0.0057s      2.9    174.7
+                  sign    verify    sign/s verify/s
+dsa  512 bits   0.0019s   0.0032s    529.0    310.2
+dsa 1024 bits   0.0047s   0.0086s    214.1    115.7
+dsa 2048 bits   0.0150s   0.0289s     66.7     34.6
+
diff --git a/deps/openssl/openssl/times/091/alpha164.osf b/deps/openssl/openssl/times/091/alpha164.osf
new file mode 100644 (file)
index 0000000..df712c6
--- /dev/null
@@ -0,0 +1,31 @@
+Alpha EV5.6 (21164A) 400mhz, OSF1 V4.0
+
+SSLeay 0.9.0 10-Apr-1998
+built on Sun Apr 19 07:54:37 EST 1998
+options:bn(64,64) md2(int) rc4(ptr,int) des(ptr,risc2,4,int) idea(int) blowfish(idx) 
+C flags:cc -O4 -tune host -fast
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                276.30k      762.07k     1034.35k     1134.07k     1160.53k
+mdc2               814.99k      845.83k      849.09k      850.33k      849.24k
+md5               2468.43k    10945.27k    17963.48k    21430.89k    22544.38k
+hmac(md5)         1002.48k     6023.98k    13430.99k    19344.17k    22351.80k
+sha1              1984.93k     8882.47k    14856.47k    17878.70k    18955.10k
+rmd160            1286.96k     5595.52k     9167.00k    10957.74k    11582.30k
+rc4              15948.15k    16710.29k    16793.20k    17929.50k    18474.56k
+des cbc           3416.04k     4149.37k     4296.25k     4328.89k     4327.57k
+des ede3          1540.14k     1683.36k     1691.14k     1705.90k     1705.22k
+idea cbc          2795.87k     3192.93k     3238.13k     3238.17k     3256.66k
+rc2 cbc           3529.00k     4069.93k     4135.79k     4135.25k     4160.07k
+rc5-32/12 cbc     7212.35k     9849.71k    10260.91k    10423.38k    10439.99k
+blowfish cbc      6061.75k     8363.50k     8706.80k     8779.40k     8784.55k
+cast cbc          5401.75k     6433.31k     6638.18k     6662.40k     6702.80k
+                  sign    verify    sign/s verify/s
+rsa  512 bits   0.0022s   0.0002s    449.6   4916.2
+rsa 1024 bits   0.0105s   0.0006s     95.3   1661.2
+rsa 2048 bits   0.0637s   0.0020s     15.7    495.6
+rsa 4096 bits   0.4457s   0.0075s      2.2    132.7
+                  sign    verify    sign/s verify/s
+dsa  512 bits   0.0028s   0.0048s    362.2    210.4
+dsa 1024 bits   0.0064s   0.0123s    155.2     81.6
+dsa 2048 bits   0.0201s   0.0394s     49.7     25.4
diff --git a/deps/openssl/openssl/times/091/mips-rel.pl b/deps/openssl/openssl/times/091/mips-rel.pl
new file mode 100644 (file)
index 0000000..4b25093
--- /dev/null
@@ -0,0 +1,21 @@
+#!/usr/local/bin/perl
+
+&doit(100,"Pentium   100 32",0.0195,0.1000,0.6406,4.6100);     # pentium-100
+&doit(200,"PPro      200 32",0.0070,0.0340,0.2087,1.4700);     # pentium-100
+&doit( 25,"R3000      25 32",0.0860,0.4825,3.2417,23.8833);    # R3000-25
+&doit(200,"R4400     200 32",0.0137,0.0717,0.4730,3.4367);     # R4400 32bit
+&doit(180,"R10000    180 32",0.0061,0.0311,0.1955,1.3871);     # R10000 32bit
+&doit(180,"R10000    180 64",0.0034,0.0149,0.0880,0.5933);     # R10000 64bit
+&doit(400,"DEC 21164 400 64",0.0022,0.0105,0.0637,0.4457);     # R10000 64bit
+
+sub doit
+       {
+       local($mhz,$label,@data)=@_;
+
+       for ($i=0; $i <= $#data; $i++)
+               {
+               $data[$i]=1/$data[$i]*200/$mhz;
+               }
+       printf("%s %6.1f %6.1f %6.1f %6.1f\n",$label,@data);
+       }
+
diff --git a/deps/openssl/openssl/times/091/r10000.irx b/deps/openssl/openssl/times/091/r10000.irx
new file mode 100644 (file)
index 0000000..237ee5d
--- /dev/null
@@ -0,0 +1,37 @@
+MIPS R10000 32kI+32kD 180mhz, IRIX 6.4
+
+Using crypto/bn/mips3.s
+
+This is built for n32, which is faster for all benchmarks than the n64
+compilation model
+
+SSLeay 0.9.0b 19-Apr-1998
+built on Sat Apr 25 12:43:14 EST 1998
+options:bn(64,64) md2(int) rc4(ptr,int) des(ptr,risc2,16,long) idea(int) blowfish(ptr) 
+C flags:cc -use_readonly_const -O2 -DTERMIOS -DB_ENDIAN
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                126.38k      349.38k      472.67k      517.01k      529.81k
+mdc2               501.64k      545.87k      551.80k      553.64k      554.41k
+md5               1825.77k     7623.64k    12630.47k    15111.74k    16012.09k
+hmac(md5)          780.81k     4472.86k     9667.22k    13802.67k    15777.89k
+sha1              1375.52k     6213.91k    11037.30k    13682.01k    14714.09k
+rmd160             856.72k     3454.40k     5598.33k     6689.94k     7073.48k
+rc4              11260.93k    13311.50k    13360.05k    13322.17k    13364.39k
+des cbc           2770.78k     3055.42k     3095.18k     3092.48k     3103.03k
+des ede3          1023.22k     1060.58k     1063.81k     1070.37k     1064.54k
+idea cbc          3029.09k     3334.30k     3375.29k     3375.65k     3380.64k
+rc2 cbc           2307.45k     2470.72k     2501.25k     2500.68k     2500.55k
+rc5-32/12 cbc     6770.91k     8629.89k     8909.58k     9009.64k     9044.95k
+blowfish cbc      4796.53k     5598.20k     5717.14k     5755.11k     5749.86k
+cast cbc          3986.20k     4426.17k     4465.04k     4476.84k     4475.08k
+                  sign    verify    sign/s verify/s
+rsa  512 bits   0.0034s   0.0003s    296.1   3225.4
+rsa 1024 bits   0.0139s   0.0008s     71.8   1221.8
+rsa 2048 bits   0.0815s   0.0026s     12.3    380.3
+rsa 4096 bits   0.5656s   0.0096s      1.8    103.7
+                  sign    verify    sign/s verify/s
+dsa  512 bits   0.0034s   0.0061s    290.8    164.9
+dsa 1024 bits   0.0084s   0.0161s    119.1     62.3
+dsa 2048 bits   0.0260s   0.0515s     38.5     19.4
+
diff --git a/deps/openssl/openssl/times/091/r3000.ult b/deps/openssl/openssl/times/091/r3000.ult
new file mode 100644 (file)
index 0000000..ecd3390
--- /dev/null
@@ -0,0 +1,32 @@
+MIPS R3000 64kI+64kD 25mhz, ultrix 4.3
+
+SSLeay 0.9.0b 19-Apr-1998
+built on Thu Apr 23 07:22:31 EST 1998
+options:bn(32,32) md2(int) rc4(ptr,int) des(ptr,risc2,16,long) idea(int) blowfish(idx) 
+C flags:cc -O2 -DL_ENDIAN -DNOPROTO -DNOCONST
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                 14.63k       40.65k       54.70k       60.07k       61.78k
+mdc2                29.43k       37.27k       38.23k       38.57k       38.60k
+md5                140.04k      676.59k     1283.84k     1654.10k     1802.24k
+hmac(md5)           60.51k      378.90k      937.82k     1470.46k     1766.74k
+sha1                60.77k      296.79k      525.40k      649.90k      699.05k
+rmd160              48.82k      227.16k      417.19k      530.31k      572.05k
+rc4                904.76k      996.20k     1007.53k     1015.65k     1010.35k
+des cbc            178.87k      209.39k      213.42k      215.55k      214.53k
+des ede3            74.25k       79.30k       80.40k       80.21k       80.14k
+idea cbc           181.02k      209.37k      214.44k      214.36k      213.83k
+rc2 cbc            161.52k      184.98k      187.99k      188.76k      189.05k
+rc5-32/12 cbc      398.99k      582.91k      614.66k      626.07k      621.87k
+blowfish cbc       296.38k      387.69k      405.50k      412.57k      410.05k
+cast cbc           214.76k      260.63k      266.92k      268.63k      258.26k
+                  sign    verify    sign/s verify/s
+rsa  512 bits   0.0870s   0.0089s     11.5    112.4
+rsa 1024 bits   0.4881s   0.0295s      2.0     33.9
+rsa 2048 bits   3.2750s   0.1072s      0.3      9.3
+rsa 4096 bits  23.9833s   0.4093s      0.0      2.4
+                  sign    verify    sign/s verify/s
+dsa  512 bits   0.0898s   0.1706s     11.1      5.9
+dsa 1024 bits   0.2847s   0.5565s      3.5      1.8
+dsa 2048 bits   1.0267s   2.0433s      1.0      0.5
+
diff --git a/deps/openssl/openssl/times/091/r4400.irx b/deps/openssl/openssl/times/091/r4400.irx
new file mode 100644 (file)
index 0000000..9b96ca1
--- /dev/null
@@ -0,0 +1,32 @@
+R4400 16kI+16kD 200mhz, Irix 5.3
+
+SSLeay 0.9.0e 27-Apr-1998
+built on Sun Apr 26 07:26:05 PDT 1998
+options:bn(64,32) md2(int) rc4(ptr,int) des(ptr,risc2,16,long) idea(int) blowfish(ptr) 
+C flags:cc -O2 -use_readonly_const -DTERMIOS -DB_ENDIAN
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                 79.80k      220.59k      298.01k      327.06k      338.60k
+mdc2               262.74k      285.30k      289.16k      288.36k      288.49k
+md5                930.35k     4167.13k     7167.91k     8678.23k     9235.86k
+hmac(md5)          399.44k     2367.57k     5370.74k     7884.28k     9076.98k
+sha1               550.96k     2488.17k     4342.76k     5362.50k     5745.40k
+rmd160             424.58k     1752.83k     2909.67k     3486.08k     3702.89k
+rc4               6687.79k     7834.63k     7962.61k     8035.65k     7915.28k
+des cbc           1544.20k     1725.94k     1748.35k     1758.17k     1745.61k
+des ede3           587.29k      637.75k      645.93k      643.17k      646.01k
+idea cbc          1575.52k     1719.75k     1732.41k     1736.69k     1740.11k
+rc2 cbc           1496.21k     1629.90k     1643.19k     1652.14k     1646.62k
+rc5-32/12 cbc     3452.48k     4276.47k     4390.74k     4405.25k     4400.12k
+blowfish cbc      2354.58k     3242.36k     3401.11k     3433.65k     3383.65k
+cast cbc          1942.22k     2152.28k     2187.51k     2185.67k     2177.20k
+                  sign    verify    sign/s verify/s
+rsa  512 bits   0.0130s   0.0014s     76.9    729.8
+rsa 1024 bits   0.0697s   0.0043s     14.4    233.9
+rsa 2048 bits   0.4664s   0.0156s      2.1     64.0
+rsa 4096 bits   3.4067s   0.0586s      0.3     17.1
+                  sign    verify    sign/s verify/s
+dsa  512 bits   0.0140s   0.0261s     71.4     38.4
+dsa 1024 bits   0.0417s   0.0794s     24.0     12.6
+dsa 2048 bits   0.1478s   0.2929s      6.8      3.4
+
diff --git a/deps/openssl/openssl/times/100.lnx b/deps/openssl/openssl/times/100.lnx
new file mode 100644 (file)
index 0000000..d0f4537
--- /dev/null
@@ -0,0 +1,32 @@
+SSLeay 0.8.4c 03-Aug-1999
+built on Tue Nov  4 02:52:29 EST 1997
+options:bn(64,32) md2(int) rc4(ptr,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2) 
+C flags:gcc -DL_ENDIAN -DTERMIO -DBN_ASM -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized -DMD5_ASM -DSHA1_ASM
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                53.27k      155.95k      201.30k      216.41k      236.78k
+mdc2              192.98k      207.98k      206.76k      206.17k      208.87k
+md5               993.15k     5748.27k    11944.70k    16477.53k    18287.27k
+hmac(md5)         404.97k     2787.58k     7690.07k    13744.43k    17601.88k
+sha1              563.24k     2851.67k     5363.71k     6879.23k     7441.07k
+rc4              7876.70k    10400.85k    10825.90k    10943.49k    10745.17k
+des cbc          2047.39k     2188.25k     2188.29k     2239.49k     2233.69k
+des ede3          660.55k      764.01k      773.55k      779.21k      780.97k
+idea cbc          653.93k      708.48k      715.43k      719.87k      720.90k
+rc2 cbc           648.08k      702.23k      708.78k      711.00k      709.97k
+blowfish cbc     3764.39k     4288.66k     4375.04k     4497.07k     4423.68k
+cast cbc         2757.14k     2993.75k     3035.31k     3078.90k     3055.62k
+
+blowfish cbc     3258.81k     3673.47k     3767.30k     3774.12k     3719.17k
+cast cbc         2677.05k     3164.78k     3273.05k     3287.38k     3244.03k
+
+
+                  sign    verify
+rsa  512 bits   0.0213s   0.0020s
+rsa 1024 bits   0.1073s   0.0063s
+rsa 2048 bits   0.6873s   0.0224s
+rsa 4096 bits   4.9333s   0.0845s
+                  sign    verify
+dsa  512 bits   0.0201s   0.0385s
+dsa 1024 bits   0.0604s   0.1190s
+dsa 2048 bits   0.2121s   0.4229s
diff --git a/deps/openssl/openssl/times/100.nt b/deps/openssl/openssl/times/100.nt
new file mode 100644 (file)
index 0000000..0dd7cfc
--- /dev/null
@@ -0,0 +1,29 @@
+SSLeay 0.8.4c 03-Aug-1999
+built on Tue Aug  3 09:49:58 EST 1999
+options:bn(64,32) md2(int) rc4(ptr,int) des(idx,cisc,4,long) idea(int) blowfish(
+ptr2)
+C flags:cl /W3 /WX /G5 /Ox /O2 /Ob2 /Gs0 /GF /Gy /nologo -DWIN32 -DL_ENDIAN -DBN
+_ASM -DMD5_ASM -DSHA1_ASM
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                93.07k      258.38k      349.03k      382.83k      392.87k
+mdc2              245.80k      259.02k      259.34k      259.16k      260.14k
+md5              1103.42k     6017.65k    12210.49k    16552.11k    18291.77k
+hmac(md5)         520.15k     3394.00k     8761.86k    14593.96k    17742.40k
+sha1              538.06k     2726.76k     5242.22k     6821.12k     7426.18k
+rc4              8283.90k    10513.09k    10886.38k    10929.50k    10816.75k
+des cbc          2073.10k     2232.91k     2251.61k     2256.46k     2232.44k
+des ede3          758.85k      782.46k      786.14k      786.08k      781.24k
+idea cbc          831.02k      892.63k      901.07k      903.48k      901.85k
+rc2 cbc           799.89k      866.09k      873.96k      876.22k      874.03k
+blowfish cbc     3835.32k     4418.78k     4511.94k     4494.54k     4416.92k
+cast cbc         2974.68k     3272.71k     3313.04k     3335.17k     3261.51k
+                  sign    verify
+rsa  512 bits   0.0202s   0.0019s
+rsa 1024 bits   0.1029s   0.0062s
+rsa 2048 bits   0.6770s   0.0220s
+rsa 4096 bits   4.8770s   0.0838s
+                  sign    verify
+dsa  512 bits   0.0191s   0.0364s
+dsa 1024 bits   0.0590s   0.1141s
+dsa 2048 bits   0.2088s   0.4171s
diff --git a/deps/openssl/openssl/times/200.lnx b/deps/openssl/openssl/times/200.lnx
new file mode 100644 (file)
index 0000000..fd7e7f4
--- /dev/null
@@ -0,0 +1,30 @@
+This machine was slightly loaded :-(
+
+SSLeay 0.8.4c 03-Aug-1999
+built on Tue Nov  4 02:52:29 EST 1997
+options:bn(64,32) md2(int) rc4(ptr,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2) 
+C flags:gcc -DL_ENDIAN -DTERMIO -DBN_ASM -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized -DMD5_ASM -DSHA1_ASM
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2               130.86k      365.31k      499.60k      547.75k      561.41k
+mdc2              526.03k      581.38k      587.12k      586.31k      589.60k
+md5              1919.49k    11173.23k    22387.60k    29553.47k    32587.21k
+hmac(md5)         747.09k     5248.35k    14275.44k    24713.26k    31737.13k
+sha1             1336.63k     6400.50k    11668.67k    14648.83k    15700.85k
+rc4             15002.32k    21327.21k    22301.63k    22503.78k    22549.26k
+des cbc          4115.16k     4521.08k     4632.37k     4607.28k     4570.57k
+des ede3         1540.29k     1609.76k     1623.64k     1620.76k     1624.18k
+idea cbc         2405.08k     2664.78k     2704.22k     2713.95k     2716.29k
+rc2 cbc          1634.07k     1764.30k     1780.23k     1790.27k     1788.12k
+blowfish cbc     5993.98k     6927.27k     7083.61k     7088.40k     7123.72k
+cast cbc         5981.52k     6900.44k     7079.70k     7110.40k     7057.72k
+                  sign    verify
+rsa  512 bits   0.0085s   0.0007s
+rsa 1024 bits   0.0377s   0.0020s
+rsa 2048 bits   0.2176s   0.0067s
+rsa 4096 bits   1.4800s   0.0242s
+sign    verify
+dsa  512 bits   0.0071s   0.0132s
+dsa 1024 bits   0.0192s   0.0376s
+dsa 2048 bits   0.0638s   0.1280s
+
diff --git a/deps/openssl/openssl/times/486-66.dos b/deps/openssl/openssl/times/486-66.dos
new file mode 100644 (file)
index 0000000..1644bf8
--- /dev/null
@@ -0,0 +1,22 @@
+MS-dos static libs, 16bit C build, 16bit assember
+
+SSLeay 0.6.1
+options:bn(32,16) md2(char) rc4(idx,int) des(ptr,long) idea(short)
+C flags:cl /ALw /Gx- /Gf /f- /Ocgnotb2 /G2 /W3 /WX -DL_ENDIAN /nologo -DMSDOS -D
+NO_SOCK
+The 'numbers' are in 1000s of bytes per second processed.
+type           8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2             18.62k       55.54k       76.88k       85.39k       86.52k
+md5             94.03k      442.06k      794.38k      974.51k     1061.31k
+sha             38.37k      166.23k      272.78k      331.41k      353.77k
+sha1            34.38k      147.77k      244.77k      292.57k      312.08k
+rc4            641.25k      795.34k      817.16k      829.57k      817.16k
+des cfb        111.46k      118.08k      120.69k      119.16k      119.37k
+des cbc        122.96k      135.69k      137.10k      135.69k      135.40k
+des ede3        48.01k       50.92k       50.32k       50.96k       50.96k
+idea cfb        97.09k      100.21k      100.36k      101.14k      100.98k
+idea cbc       102.08k      109.41k      111.46k      111.65k      110.52k
+rc2 cfb        120.47k      125.55k      125.79k      125.55k      125.55k
+rc2 cbc        129.77k      140.33k      143.72k      142.16k      141.85k
+rsa  512 bits   0.264s
+rsa 1024 bits   1.494s
diff --git a/deps/openssl/openssl/times/486-66.nt b/deps/openssl/openssl/times/486-66.nt
new file mode 100644 (file)
index 0000000..b26a900
--- /dev/null
@@ -0,0 +1,22 @@
+SSLeay 0.6.1 02-Jul-1996
+built on Fri Jul 10 09:53:15 EST 1996
+options:bn(64,32) md2(int) rc4(idx,int) des(idx,long) idea(int)
+C flags:cl /W3 /WX /G5 /Ox /O2 /Ob2 /Gs0 /nologo -DWIN32 -DL_ENDIAN /MD
+The 'numbers' are in 1000s of bytes per second processed.
+type           8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2             38.27k      107.28k      145.43k      159.60k      164.15k
+md5            399.00k     1946.13k     3610.80k     4511.94k     4477.27k
+sha            182.04k      851.26k     1470.65k     1799.20k     1876.48k
+sha1           151.83k      756.55k     1289.76k     1567.38k     1625.70k
+rc4           1853.92k     2196.25k     2232.91k     2241.31k     2152.96k
+des cfb        360.58k      382.69k      384.94k      386.07k      377.19k
+des cbc        376.10k      431.87k      436.32k      437.78k      430.45k
+des ede3       152.55k      160.38k      161.51k      161.33k      159.98k
+idea cfb       245.59k      255.60k      256.65k      257.16k      254.61k
+idea cbc       257.16k      276.12k      279.05k      279.11k      276.70k
+rc2 cfb        280.25k      293.49k      294.74k      294.15k      291.47k
+rc2 cbc        295.47k      321.57k      324.76k      324.76k      320.00k
+rsa  512 bits   0.084s
+rsa 1024 bits   0.495s
+rsa 2048 bits   3.435s
+
diff --git a/deps/openssl/openssl/times/486-66.w31 b/deps/openssl/openssl/times/486-66.w31
new file mode 100644 (file)
index 0000000..381f149
--- /dev/null
@@ -0,0 +1,23 @@
+Windows 3.1 DLL's, 16 bit C with 32bit assember
+
+SSLeay 0.6.1 02-Jul-1996
+built on Wed Jul 10 09:53:15 EST 1996
+options:bn(32,32) md2(char) rc4(idx,int) des(ptr,long) idea(short)
+C flags:cl /ALw /Gx- /Gf /G2 /f- /Ocgnotb2 /W3 /WX -DL_ENDIAN /nologo -DWIN16
+The 'numbers' are in 1000s of bytes per second processed.
+type           8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2             18.94k       54.27k       73.43k       80.91k       83.75k
+md5             78.96k      391.26k      734.30k      919.80k      992.97k
+sha             39.01k      168.04k      280.67k      336.08k      359.10k
+sha1            35.20k      150.14k      247.31k      294.54k      313.94k
+rc4            509.61k      655.36k      678.43k      677.02k      670.10k
+des cfb         97.09k      104.69k      106.56k      105.70k      106.56k
+des cbc        116.82k      129.77k      131.07k      131.07k      131.07k
+des ede3        44.22k       47.90k       48.53k       48.47k       47.86k
+idea cfb        83.49k       87.03k       87.03k       87.15k       87.73k
+idea cbc        89.04k       96.23k       96.95k       97.81k       97.09k
+rc2 cfb        108.32k      113.58k      113.78k      114.57k      114.77k
+rc2 cbc        118.08k      131.07k      134.02k      134.02k      132.66k
+rsa  512 bits   0.181s
+rsa 1024 bits   0.846s
+
diff --git a/deps/openssl/openssl/times/5.lnx b/deps/openssl/openssl/times/5.lnx
new file mode 100644 (file)
index 0000000..1c1e392
--- /dev/null
@@ -0,0 +1,29 @@
+SSLeay 0.8.5g 24-Jan-1998
+built on Tue Jan 27 08:11:42 EST 1998
+options:bn(64,32) md2(int) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2) 
+C flags:gcc -DL_ENDIAN -DTERMIO -DBN_ASM -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized -DSHA1_ASM -DMD5_ASM -DRMD160_ASM
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                 56.55k      156.69k      211.63k      231.77k      238.71k
+mdc2               192.26k      208.09k      210.09k      209.58k      210.26k
+md5                991.04k     5745.51k    11932.67k    16465.24k    18306.39k
+hmac(md5)          333.99k     2383.89k     6890.67k    13133.82k    17397.08k
+sha1               571.68k     2883.88k     5379.07k     6880.26k     7443.80k
+rmd160             409.41k     2212.91k     4225.45k     5456.55k     5928.28k
+rc4               6847.57k     8596.22k     8901.80k     8912.90k     8850.09k
+des cbc           2046.29k     2229.78k     2254.76k     2259.97k     2233.69k
+des ede3           751.11k      779.95k      783.96k      784.38k      780.97k
+idea cbc           653.40k      708.29k      718.42k      720.21k      720.90k
+rc2 cbc            647.19k      702.46k      709.21k      710.66k      709.97k
+rc5-32/12 cbc     3498.18k     4054.12k     4133.46k     4151.64k     4139.69k
+blowfish cbc      3763.95k     4437.74k     4532.74k     4515.50k     4448.26k
+cast cbc          2754.22k     3020.67k     3079.08k     3069.95k     3036.50k
+                  sign    verify    sign/s verify/s
+rsa  512 bits   0.0207s   0.0020s     48.3    511.3
+rsa 1024 bits   0.1018s   0.0059s      9.8    169.6
+rsa 2048 bits   0.6438s   0.0208s      1.6     48.0
+rsa 4096 bits   4.6033s   0.0793s      0.2     12.6
+                  sign    verify    sign/s verify/s
+dsa  512 bits   0.0190s   0.0359s     52.6     27.8
+dsa 1024 bits   0.0566s   0.1109s     17.7      9.0
+dsa 2048 bits   0.1988s   0.3915s      5.0      2.6
diff --git a/deps/openssl/openssl/times/586-085i.nt b/deps/openssl/openssl/times/586-085i.nt
new file mode 100644 (file)
index 0000000..8a57975
--- /dev/null
@@ -0,0 +1,29 @@
+SSLeay 0.8.5i 28-Jan-1998
+built on Wed Jan 28 18:00:07 EST 1998
+options:bn(64,32) md2(int) rc4(idx,int) des(idx,cisc,4,long) idea(int) blowfish(ptr2)
+C flags:cl /MT /W3 /WX /G5 /Ox /O2 /Ob2 /Gs0 /GF /Gy /nologo -DWIN32 -DL_ENDIAN -DBN_ASM -DMD5_ASM -DSHA1_ASM -DRMD160_ASM
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                 92.74k      257.59k      348.16k      381.79k      392.14k
+mdc2               227.65k      247.82k      249.90k      250.65k      250.20k
+md5               1089.54k     5966.29k    12104.77k    16493.53k    18204.44k
+hmac(md5)          513.53k     3361.36k     8725.41k    14543.36k    17593.56k
+sha1               580.74k     2880.51k     5376.62k     6865.78k     7413.05k
+rmd160             508.06k     2427.96k     4385.51k     5510.84k     5915.80k
+rc4               8004.40k    10408.74k    10794.48k    10884.12k    10728.22k
+des cbc           2057.24k     2222.97k     2246.79k     2209.39k     2223.44k
+des ede3           739.42k      761.99k      765.48k      760.26k      760.97k
+idea cbc           827.08k      889.60k      898.83k      901.15k      897.98k
+rc2 cbc            795.64k      861.04k      871.13k      872.58k      871.13k
+rc5-32/12 cbc     3597.17k     4139.66k     4204.39k     4223.02k     4204.39k
+blowfish cbc      3807.47k     3996.10k     4156.07k     4204.39k     4105.62k
+cast cbc          2777.68k     2814.21k     2892.62k     2916.76k     2868.88k
+                  sign    verify    sign/s verify/s
+rsa  512 bits   0.0178s   0.0018s     56.3    541.6
+rsa 1024 bits   0.0945s   0.0059s     10.6    168.3
+rsa 2048 bits   0.6269s   0.0208s      1.6     48.0
+rsa 4096 bits   4.5560s   0.0784s      0.2     12.8
+                  sign    verify    sign/s verify/s
+dsa  512 bits   0.0178s   0.0340s     56.2     29.4
+dsa 1024 bits   0.0552s   0.1077s     18.1      9.3
+dsa 2048 bits   0.1963s   0.3811s      5.1      2.6
diff --git a/deps/openssl/openssl/times/586-100.LN3 b/deps/openssl/openssl/times/586-100.LN3
new file mode 100644 (file)
index 0000000..a6fa818
--- /dev/null
@@ -0,0 +1,26 @@
+SSLeay 0.8.3v 15-Oct-1997
+built on Wed Oct 15 10:05:00 EST 1997
+options:bn(64,32) md2(int) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2) 
+C flags:gcc -DL_ENDIAN -DTERMIO -DX86_ASM -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                56.27k      156.76k      211.46k      231.77k      238.71k
+mdc2              188.74k      206.12k      207.70k      207.87k      208.18k
+md5               991.56k     5718.31k    11748.61k    16090.79k    17850.37k
+hmac(md5)         387.56k     2636.01k     7327.83k    13340.33k    17091.24k
+sha1              463.55k     2274.18k     4071.17k     5072.90k     5447.68k
+rc4              3673.94k     4314.52k     4402.26k     4427.09k     4407.30k
+des cbc          2023.79k     2209.77k     2233.34k     2220.71k     2222.76k
+des ede3          747.17k      778.54k      781.57k      778.24k      778.24k
+idea cbc          614.64k      678.04k      683.52k      685.06k      685.40k
+rc2 cbc           536.83k      574.10k      578.05k      579.24k      578.90k
+blowfish cbc     3673.39k     4354.58k     4450.22k     4429.48k     4377.26k
+                  sign    verify
+rsa  512 bits   0.0217s   0.0021s
+rsa 1024 bits   0.1083s   0.0064s
+rsa 2048 bits   0.6867s   0.0223s
+rsa 4096 bits   4.9400s   0.0846s
+                  sign    verify
+dsa  512 bits   0.0203s   0.0387s
+dsa 1024 bits   0.0599s   0.1170s
+dsa 2048 bits   0.2115s   0.4242s
diff --git a/deps/openssl/openssl/times/586-100.NT2 b/deps/openssl/openssl/times/586-100.NT2
new file mode 100644 (file)
index 0000000..7f8c167
--- /dev/null
@@ -0,0 +1,26 @@
+SSLeay 0.8.3e 30-Sep-1997
+built on Tue Sep 30 14:52:58 EST 1997
+options:bn(64,32) md2(int) rc4(idx,int) des(idx,cisc,4,long) idea(int) blowfish(ptr2)
+C flags:cl /W3 /WX /G5 /Ox /O2 /Ob2 /Gs0 /GF /Gy /nologo -DWIN32 -DL_ENDIAN -DX86_ASM
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                92.99k      257.59k      348.16k      381.47k      392.14k
+mdc2              223.77k      235.30k      237.15k      236.77k      237.29k
+md5               862.53k     4222.17k     7842.75k     9925.00k    10392.23k
+sha               491.34k     2338.61k     4062.28k     4986.10k     5307.90k
+sha1              494.38k     2234.94k     3838.83k     4679.58k     4980.18k
+rc4              6338.10k     7489.83k     7676.25k     7698.80k     7631.56k
+des cbc          1654.17k     1917.66k     1961.05k     1968.05k     1960.69k
+des ede3          691.17k      739.42k      744.13k      745.82k      741.40k
+idea cbc          788.46k      870.33k      879.16k      881.38k      879.90k
+rc2 cbc           794.44k      859.63k      868.24k      869.68k      867.45k
+blowfish cbc     2379.88k     3017.48k     3116.12k     3134.76k     3070.50k
+                  sign    verify
+rsa  512 bits   0.0204s   0.0027s
+rsa 1024 bits   0.1074s   0.0032s
+rsa 2048 bits   0.6890s   0.0246s
+rsa 4096 bits   5.0180s   0.0911s
+                  sign    verify
+dsa  512 bits   0.0201s   0.0376s
+dsa 1024 bits   0.0608s   0.1193s
+dsa 2048 bits   0.2133s   0.4294s
diff --git a/deps/openssl/openssl/times/586-100.dos b/deps/openssl/openssl/times/586-100.dos
new file mode 100644 (file)
index 0000000..3085c25
--- /dev/null
@@ -0,0 +1,24 @@
+ms-dos static libs, 16 bit C and 16 bit assmber 
+
+SSLeay 0.6.1 02-Jul-1996
+built on Tue Jul  9 22:52:54 EST 1996
+options:bn(32,16) md2(char) rc4(idx,int) des(ptr,long) idea(short)
+C flags:cl /ALw /Gx- /Gf /G2 /f- /Ocgnotb2 /W3 /WX -DL_ENDIAN /nologo -DMSDOS -DNO_SOCK
+The 'numbers' are in 1000s of bytes per second processed.
+type           8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2             45.99k      130.75k      176.53k      199.35k      203.21k
+md5            236.17k     1072.16k     1839.61k     2221.56k     2383.13k
+sha            107.97k      459.10k      757.64k      908.64k      954.99k
+sha1            96.95k      409.92k      672.16k      788.40k      844.26k
+rc4           1659.14k     1956.30k     2022.72k     2022.72k     2022.72k
+des cfb        313.57k      326.86k      326.86k      331.83k      326.86k
+des cbc        345.84k      378.82k      378.82k      384.38k      378.82k
+des ede3       139.59k      144.66k      144.61k      144.45k      143.29k
+idea cfb       262.67k      274.21k      274.21k      274.21k      274.21k
+idea cbc       284.32k      318.14k      318.14k      318.14k      318.14k
+rc2 cfb        265.33k      274.21k      277.69k      277.11k      277.69k
+rc2 cbc        283.71k      310.60k      309.86k      313.57k      314.32k
+rsa  512 bits   0.104s
+rsa 1024 bits   0.566s
+rsa 2048 bits   3.680s
+rsa 4096 bits  26.740s
diff --git a/deps/openssl/openssl/times/586-100.ln4 b/deps/openssl/openssl/times/586-100.ln4
new file mode 100644 (file)
index 0000000..14a9db9
--- /dev/null
@@ -0,0 +1,26 @@
+SSLeay 0.8.3aa 24-Oct-1997
+built on Mon Oct 27 10:16:25 EST 1997
+options:bn(64,32) md2(int) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2) 
+C flags:gcc -DL_ENDIAN -DTERMIO -DBN_ASM -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized -DMD5_ASM -DSHA1_ASM
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                56.78k      156.71k      211.46k      231.77k      238.71k
+mdc2              187.45k      200.49k      201.64k      202.75k      202.77k
+md5              1002.51k     5798.66k    11967.15k    16449.19k    18251.78k
+hmac(md5)         468.71k     3173.46k     8386.99k    14305.56k    17607.34k
+sha1              586.98k     2934.87k     5393.58k     6863.19k     7408.30k
+rc4              3675.10k     4314.15k     4402.77k     4427.78k     4404.57k
+des cbc          1902.96k     2202.01k     2242.30k     2252.46k     2236.42k
+des ede3          700.15k      774.23k      783.70k      781.62k      783.70k
+idea cbc          618.46k      677.93k      683.61k      685.40k      685.40k
+rc2 cbc           536.97k      573.87k      577.96k      579.24k      578.90k
+blowfish cbc     3672.66k     4271.89k     4428.80k     4469.76k     4374.53k
+                  sign    verify
+rsa  512 bits   0.0213s   0.0021s
+rsa 1024 bits   0.1075s   0.0063s
+rsa 2048 bits   0.6853s   0.0224s
+rsa 4096 bits   4.9400s   0.0845s
+                  sign    verify
+dsa  512 bits   0.0203s   0.0380s
+dsa 1024 bits   0.0600s   0.1189s
+dsa 2048 bits   0.2110s   0.4250s
diff --git a/deps/openssl/openssl/times/586-100.lnx b/deps/openssl/openssl/times/586-100.lnx
new file mode 100644 (file)
index 0000000..0c05173
--- /dev/null
@@ -0,0 +1,23 @@
+SSLeay 0.7.3 30-Apr-1997
+built on Mon May 12 04:13:55 EST 1997
+options:bn(64,32) md2(char) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2)
+C flags:gcc -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                72.95k      202.77k      274.01k      300.37k      309.23k
+md5               770.57k     4094.02k     7409.41k     9302.36k     9986.05k
+sha               363.05k     1571.07k     2613.85k     3134.81k     3320.49k
+sha1              340.94k     1462.85k     2419.20k     2892.12k     3042.35k
+rc4              3676.91k     4314.94k     4407.47k     4430.51k     4412.76k
+des cbc          1489.95k     1799.08k     1841.66k     1851.73k     1848.66k
+des ede3          621.93k      711.19k      726.10k      729.77k      729.09k
+idea cbc          618.16k      676.99k      683.09k      684.37k      683.59k
+rc2 cbc           537.59k      573.93k      578.56k      579.58k      579.70k
+blowfish cbc     2077.57k     2682.20k     2827.18k     2840.92k     2842.62k
+rsa  512 bits   0.024s   0.003
+rsa 1024 bits   0.120s   0.003
+rsa 2048 bits   0.751s   0.026
+rsa 4096 bits   5.320s   0.096
+dsa  512 bits   0.022s   0.042
+dsa 1024 bits   0.065s   0.126
+dsa 2048 bits   0.227s   0.449
diff --git a/deps/openssl/openssl/times/586-100.nt b/deps/openssl/openssl/times/586-100.nt
new file mode 100644 (file)
index 0000000..9adcac3
--- /dev/null
@@ -0,0 +1,23 @@
+SSLeay 0.7.3 30-Apr-1997
+built on Mon May 19 10:47:38 EST 1997
+options:bn(64,32) md2(char) rc4(idx,int) des(idx,cisc,4,long) idea(int) blowfish(ptr2)
+C flags not available
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                89.57k      245.94k      331.59k      362.95k      373.29k
+md5               858.93k     4175.51k     7700.21k     9715.78k    10369.11k
+sha               466.18k     2103.67k     3607.69k     4399.31k     4669.16k
+sha1              449.59k     2041.02k     3496.13k     4256.45k     4512.92k
+rc4              5862.55k     7447.27k     7698.80k     7768.38k     7653.84k
+des cbc          1562.71k     1879.84k     1928.24k     1938.93k     1911.02k
+des ede3          680.27k      707.97k      728.62k      733.15k      725.98k
+idea cbc          797.46k      885.85k      895.68k      898.06k      896.45k
+rc2 cbc           609.46k      648.75k      654.01k      654.42k      653.60k
+blowfish cbc     2357.94k     3000.22k     3106.89k     3134.76k     3080.42k
+rsa  512 bits   0.022s   0.003
+rsa 1024 bits   0.112s   0.003
+rsa 2048 bits   0.726s   0.026
+rsa 4096 bits   5.268s   0.095
+dsa  512 bits   0.021s   0.039
+dsa 1024 bits   0.063s   0.127
+dsa 2048 bits   0.224s   0.451
diff --git a/deps/openssl/openssl/times/586-100.ntx b/deps/openssl/openssl/times/586-100.ntx
new file mode 100644 (file)
index 0000000..35166a5
--- /dev/null
@@ -0,0 +1,30 @@
+SSLeay 0.8.5f 22-Jan-1998
+built on Wed Jan 21 17:11:53 EST 1998
+options:bn(64,32) md2(int) rc4(idx,int) des(idx,cisc,4,long) idea(int) blowfish(
+ptr2)
+C flags:cl /MT /W3 /WX /G5 /Ox /O2 /Ob2 /Gs0 /GF /Gy /nologo -DWIN32 -DL_ENDIAN
+-DBN_ASM -DMD5_ASM -DSHA1_ASM -DRMD160_ASM
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                92.99k      257.43k      347.84k      381.82k      392.14k
+mdc2              232.19k      253.68k      257.57k      258.70k      258.70k
+md5              1094.09k     5974.79k    12139.81k    16487.04k    18291.77k
+hmac(md5)         375.70k     2590.04k     7309.70k    13469.18k    17447.19k
+sha1              613.78k     2982.93k     5446.44k     6889.46k     7424.86k
+rmd160            501.23k     2405.68k     4367.25k     5503.61k     5915.80k
+rc4              8167.75k    10429.44k    10839.12k    10929.50k    10772.30k
+des cbc          2057.24k     2218.27k     2237.20k     2227.69k     2213.59k
+des ede3          719.63k      727.11k      728.77k      719.56k      722.97k
+idea cbc          827.67k      888.85k      898.06k      900.30k      898.75k
+rc2 cbc           797.46k      862.53k      870.33k      872.58k      870.40k
+blowfish cbc     3835.32k     4435.60k     4513.89k     4513.89k     4416.92k
+cast cbc         2785.06k     3052.62k     3088.59k     3034.95k     3034.95k
+                  sign    verify    sign/s verify/s
+rsa  512 bits   0.0202s   0.0020s     49.4    500.2
+rsa 1024 bits   0.1030s   0.0063s      9.7    159.4
+rsa 2048 bits   0.6740s   0.0223s      1.5     44.9
+rsa 4096 bits   4.8970s   0.0844s      0.2     11.8
+                  sign    verify    sign/s verify/s
+dsa  512 bits   0.0191s   0.0361s     52.4     27.7
+dsa 1024 bits   0.0587s   0.1167s     17.0      8.6
+dsa 2048 bits   0.2091s   0.4123s      4.8      2.4
diff --git a/deps/openssl/openssl/times/586-100.w31 b/deps/openssl/openssl/times/586-100.w31
new file mode 100644 (file)
index 0000000..d5b1c10
--- /dev/null
@@ -0,0 +1,27 @@
+Pentium 100, Windows 3.1 DLL's, 16 bit C, 32bit assember.
+
+Running under Windows NT 4.0 Beta 2
+
+SSLeay 0.6.4 20-Aug-1996
+built on Thu Aug 22 08:44:21 EST 1996
+options:bn(32,32) md2(char) rc4(idx,int) des(ptr,long) idea(short)
+C flags:cl /ALw /Gx- /Gf /G2 /f- /Ocgnotb2 /W3 /WX -DL_ENDIAN /nologo -DWIN16
+The 'numbers' are in 1000s of bytes per second processed.
+type           8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2             45.83k      128.82k      180.17k      194.90k      198.59k
+md5            224.82k     1038.19k     1801.68k     2175.47k     2330.17k
+sha            105.11k      448.11k      739.48k      884.13k      944.66k
+sha1            94.71k      402.99k      667.88k      795.58k      844.26k
+rc4           1614.19k     1956.30k     2022.72k     2022.72k     2022.72k
+des cfb        291.27k      318.14k      318.14k      318.14k      322.84k
+des cbc        326.86k      356.17k      362.08k      362.08k      367.15k
+des ede3       132.40k      139.57k      139.53k      139.37k      140.97k
+idea cfb       265.33k      280.67k      280.67k      277.69k      281.27k
+idea cbc       274.21k      302.01k      306.24k      306.24k      305.53k
+rc2 cfb        264.79k      274.21k      274.78k      274.21k      274.21k
+rc2 cbc        281.27k      306.24k      309.86k      305.53k      309.86k
+rsa  512 bits   0.058s
+rsa 1024 bits   0.280s
+rsa 2048 bits   1.430s
+rsa 4096 bits  10.600s
+
diff --git a/deps/openssl/openssl/times/586-1002.lnx b/deps/openssl/openssl/times/586-1002.lnx
new file mode 100644 (file)
index 0000000..d830bce
--- /dev/null
@@ -0,0 +1,26 @@
+SSLeay 0.8.3e 30-Sep-1997
+built on Wed Oct  1 03:01:44 EST 1997
+options:bn(64,32) md2(int) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2) 
+C flags:gcc -DL_ENDIAN -DTERMIO -DX86_ASM -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                56.21k      156.57k      211.29k      231.77k      237.92k
+mdc2              170.99k      191.70k      193.90k      195.58k      195.95k
+md5               770.50k     3961.96k     7291.22k     9250.82k     9942.36k
+sha               344.93k     1520.77k     2569.81k     3108.52k     3295.91k
+sha1              326.20k     1423.74k     2385.15k     2870.95k     3041.96k
+rc4              3672.88k     4309.65k     4374.41k     4408.66k     4355.41k
+des cbc          1349.73k     1689.05k     1735.34k     1748.99k     1739.43k
+des ede3          638.70k      704.00k      711.85k      714.41k      712.70k
+idea cbc          619.55k      677.33k      683.26k      685.06k      685.40k
+rc2 cbc           521.18k      571.20k      573.46k      578.90k      578.90k
+blowfish cbc     2079.67k     2592.49k     2702.34k     2730.33k     2695.17k
+                  sign    verify
+rsa  512 bits   0.0213s   0.0026s
+rsa 1024 bits   0.1099s   0.0031s
+rsa 2048 bits   0.7007s   0.0248s
+rsa 4096 bits   5.0500s   0.0921s
+                  sign    verify
+dsa  512 bits   0.0203s   0.0389s
+dsa 1024 bits   0.0614s   0.1222s
+dsa 2048 bits   0.2149s   0.4283s
diff --git a/deps/openssl/openssl/times/586p-100.lnx b/deps/openssl/openssl/times/586p-100.lnx
new file mode 100644 (file)
index 0000000..561eb31
--- /dev/null
@@ -0,0 +1,26 @@
+Pentium 100 - Linux 1.2.13 - gcc 2.7.2p
+This is the pentium specific version of gcc
+
+SSLeay 0.6.4 20-Aug-1996
+built on Thu Aug 22 08:27:58 EST 1996
+options:bn(64,32) md2(char) rc4(idx,int) des(idx,long) idea(int)
+C flags:gcc -DL_ENDIAN -DTERMIO -O6 -fomit-frame-pointer -mpentium -Wall
+The 'numbers' are in 1000s of bytes per second processed.
+type           8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2             74.90k      208.43k      282.11k      309.59k      318.43k
+md5            807.08k     4205.67k     7801.51k     9958.06k    10810.71k
+sha            405.98k     1821.55k     3119.10k     3799.04k     4052.31k
+sha1           389.13k     1699.50k     2852.78k     3437.57k     3656.36k
+rc4           3621.15k     4130.07k     4212.74k     4228.44k     4213.42k
+des cfb        794.39k      828.37k      831.74k      832.51k      832.85k
+des cbc        817.68k      886.17k      894.72k      896.00k      892.93k
+des ede3       308.83k      323.29k      324.61k      324.95k      324.95k
+idea cfb       690.41k      715.39k      718.51k      719.19k      718.17k
+idea cbc       696.80k      760.60k      767.32k      768.68k      770.05k
+rc2 cfb        619.91k      639.74k      642.30k      642.73k      641.71k
+rc2 cbc        631.99k      671.42k      676.35k      676.18k      677.21k
+rsa  512 bits   0.025s
+rsa 1024 bits   0.123s
+rsa 2048 bits   0.756s
+rsa 4096 bits   5.365s
+
diff --git a/deps/openssl/openssl/times/686-200.bsd b/deps/openssl/openssl/times/686-200.bsd
new file mode 100644 (file)
index 0000000..f23c580
--- /dev/null
@@ -0,0 +1,25 @@
+Pentium Pro 200mhz
+FreeBSD 2.1.5
+gcc 2.7.2.2
+
+SSLeay 0.7.0 30-Jan-1997
+built on Tue Apr 22 12:14:36 EST 1997
+options:bn(64,32) md2(int) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2)
+C flags:gcc -DTERMIOS -D_ANSI_SOURCE -fomit-frame-pointer -O3 -m486 -Wall
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2               130.99k      367.68k      499.09k      547.04k      566.50k
+md5              1924.98k     8293.50k    13464.41k    16010.39k    16820.68k
+sha              1250.75k     5330.43k     8636.88k    10227.36k    10779.14k
+sha1             1071.55k     4572.50k     7459.98k     8791.96k     9341.61k
+rc4             10724.22k    14546.25k    15240.18k    15259.50k    15265.63k
+des cbc          3309.11k     3883.01k     3968.25k     3971.86k     3979.14k
+des ede3         1442.98k     1548.33k     1562.48k     1562.00k     1563.33k
+idea cbc         2195.69k     2506.39k     2529.59k     2545.66k     2546.54k
+rc2 cbc           806.00k      833.52k      837.58k      838.52k      836.69k
+blowfish cbc     4687.34k     5949.97k     6182.43k     6248.11k     6226.09k
+rsa  512 bits   0.010s
+rsa 1024 bits   0.045s
+rsa 2048 bits   0.260s
+rsa 4096 bits   1.690s
+
diff --git a/deps/openssl/openssl/times/686-200.lnx b/deps/openssl/openssl/times/686-200.lnx
new file mode 100644 (file)
index 0000000..a10cc2f
--- /dev/null
@@ -0,0 +1,26 @@
+SSLeay 0.8.2a 04-Sep-1997
+built on Fri Sep  5 17:37:05 EST 1997
+options:bn(64,32) md2(int) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2) C flags:gcc -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2               131.02k      368.41k      500.57k      549.21k      566.09k
+mdc2              535.60k      589.10k      595.88k      595.97k      594.54k
+md5              1801.53k     9674.77k    17484.03k    21849.43k    23592.96k
+sha              1261.63k     5533.25k     9285.63k    11187.88k    11913.90k
+sha1             1103.13k     4782.53k     7933.78k     9472.34k    10070.70k
+rc4             10722.53k    14443.93k    15215.79k    15299.24k    15219.59k
+des cbc          3286.57k     3827.73k     3913.39k     3931.82k     3926.70k
+des ede3         1443.50k     1549.08k     1561.17k     1566.38k     1564.67k
+idea cbc         2203.64k     2508.16k     2538.33k     2543.62k     2547.71k
+rc2 cbc          1430.94k     1511.59k     1524.82k     1527.13k     1523.33k
+blowfish cbc     4716.07k     5965.82k     6190.17k     6243.67k     6234.11k
+                  sign    verify
+rsa  512 bits   0.0100s   0.0011s
+rsa 1024 bits   0.0451s   0.0012s
+rsa 2048 bits   0.2605s   0.0086s
+rsa 4096 bits   1.6883s   0.0302s
+                  sign    verify
+dsa  512 bits   0.0083s   0.0156s
+dsa 1024 bits   0.0228s   0.0454s
+dsa 2048 bits   0.0719s   0.1446s
+
diff --git a/deps/openssl/openssl/times/686-200.nt b/deps/openssl/openssl/times/686-200.nt
new file mode 100644 (file)
index 0000000..c8cbaa0
--- /dev/null
@@ -0,0 +1,24 @@
+built on Tue May 13 08:24:51 EST 1997
+options:bn(64,32) md2(char) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfi
+sh(ptr2)
+C flags not available
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2               156.39k      427.99k      576.14k      628.36k      647.27k
+md5              2120.48k    10255.02k    18396.07k    22795.13k    24244.53k
+sha              1468.59k     6388.89k    10686.12k    12826.62k    13640.01k
+sha1             1393.46k     6013.34k     9974.56k    11932.59k    12633.45k
+rc4             13833.46k    19275.29k    20321.24k    20281.93k    20520.08k
+des cbc          3382.50k     4104.02k     4152.78k     4194.30k     4194.30k
+des ede3         1465.51k     1533.00k     1549.96k     1553.29k     1570.29k
+idea cbc         2579.52k     3079.52k     3130.08k     3153.61k     3106.89k
+rc2 cbc          1204.57k     1276.42k     1285.81k     1289.76k     1285.81k
+blowfish cbc     5229.81k     6374.32k     6574.14k     6574.14k     6594.82k
+rsa  512 bits   0.008s   0.001
+rsa 1024 bits   0.038s   0.001
+rsa 2048 bits   0.231s   0.008
+rsa 4096 bits   1.540s   0.027
+dsa  512 bits   0.007s   0.013
+dsa 1024 bits   0.021s   0.040
+dsa 2048 bits   0.066s   0.130
+
diff --git a/deps/openssl/openssl/times/L1 b/deps/openssl/openssl/times/L1
new file mode 100644 (file)
index 0000000..09253d7
--- /dev/null
@@ -0,0 +1,27 @@
+SSLeay 0.8.3ad 27-Oct-1997
+built on Wed Oct 29 00:36:17 EST 1997
+options:bn(64,32) md2(int) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2) 
+C flags:gcc -DL_ENDIAN -DTERMIO -DBN_ASM -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized -DMD5_ASM -DSHA1_ASM
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                56.16k      156.50k      211.46k      231.77k      238.71k
+mdc2              183.37k      205.21k      205.57k      209.92k      207.53k
+md5              1003.65k     5605.56k    11628.54k    15887.70k    17522.69k
+hmac(md5)         411.24k     2803.46k     7616.94k    13475.84k    16864.60k
+sha1              542.66k     2843.50k     5320.53k     6833.49k     7389.18k
+rc4              3677.15k     4313.73k     4407.89k     4429.82k     4404.57k
+des cbc          1787.94k     2174.51k     2236.76k     2249.73k     2230.95k
+des ede3          719.46k      777.26k      784.81k      780.29k      783.70k
+idea cbc          619.56k      677.89k      684.12k      685.40k      685.40k
+rc2 cbc           537.51k      573.93k      578.47k      579.24k      578.90k
+blowfish cbc     3226.76k     4221.65k     4424.19k     4468.39k     4377.26k
+cast cbc         2866.13k     3165.35k     3263.15k     3287.04k     3233.11k
+                  sign    verify
+rsa  512 bits   0.0212s   0.0021s
+rsa 1024 bits   0.1072s   0.0064s
+rsa 2048 bits   0.6853s   0.0222s
+rsa 4096 bits   4.9300s   0.0848s
+                  sign    verify
+dsa  512 bits   0.0200s   0.0380s
+dsa 1024 bits   0.0600s   0.1180s
+dsa 2048 bits   0.2110s   0.4221s
diff --git a/deps/openssl/openssl/times/R10000.t b/deps/openssl/openssl/times/R10000.t
new file mode 100644 (file)
index 0000000..6b3874c
--- /dev/null
@@ -0,0 +1,24 @@
+IRIX 6.2 - R10000 195mhz
+SLeay 0.6.5a 06-Dec-1996
+built on Tue Dec 24 03:51:45 EST 1996
+options:bn(32,32) md2(int) rc4(ptr,int) des(ptr,risc2,16,long) idea(int)
+C flags:cc -O2 -DTERMIOS -DB_ENDIAN
+The 'numbers' are in 1000s of bytes per second processed.
+type           8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2            156.34k      424.03k      571.88k      628.88k      646.01k
+md5           1885.02k     8181.72k    13440.53k    16020.60k    16947.54k
+sha           1587.12k     7022.05k    11951.24k    14440.12k    15462.74k
+sha1          1413.13k     6215.86k    10571.16k    12736.22k    13628.51k
+rc4          10556.28k    11974.08k    12077.10k    12111.38k    12103.20k
+des cfb       2977.71k     3252.27k     3284.36k     3302.66k     3290.54k
+des cbc       3298.31k     3704.96k     3771.30k     3730.73k     3778.80k
+des ede3      1278.28k     1328.82k     1342.66k     1339.82k     1343.27k
+idea cfb      2843.34k     3138.04k     3180.95k     3176.46k     3188.54k
+idea cbc      3115.21k     3558.03k     3590.61k     3591.24k     3601.18k
+rc2 cfb       2006.66k     2133.33k     2149.03k     2159.36k     2149.71k
+rc2 cbc       2167.07k     2315.30k     2338.05k     2329.34k     2333.90k
+rsa  512 bits   0.008s
+rsa 1024 bits   0.043s
+rsa 2048 bits   0.280s
+rsa 4096 bits   2.064s
+
diff --git a/deps/openssl/openssl/times/R4400.t b/deps/openssl/openssl/times/R4400.t
new file mode 100644 (file)
index 0000000..af8848f
--- /dev/null
@@ -0,0 +1,26 @@
+IRIX 5.3
+R4400 200mhz
+cc -O2
+SSLeay 0.6.5a 06-Dec-1996
+built on Mon Dec 23 11:51:11 EST 1996
+options:bn(32,32) md2(int) rc4(ptr,int) des(ptr,risc2,16,long) idea(int)
+C flags:cc -O2 -DTERMIOS -DB_ENDIAN
+The 'numbers' are in 1000s of bytes per second processed.
+type           8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2            100.62k      280.25k      380.15k      416.02k      428.82k
+md5            828.62k     3525.05k     6311.98k     7742.51k     8328.04k
+sha            580.04k     2513.74k     4251.73k     5101.04k     5394.80k
+sha1           520.23k     2382.94k     4107.82k     5024.62k     5362.56k
+rc4           5871.53k     6323.08k     6357.49k     6392.04k     6305.45k
+des cfb       1016.76k     1156.72k     1176.59k     1180.55k     1181.65k
+des cbc       1016.38k     1303.81k     1349.10k     1359.41k     1356.62k
+des ede3       607.39k      650.74k      655.11k      657.52k      654.18k
+idea cfb      1296.10k     1348.66k     1353.80k     1358.75k     1355.40k
+idea cbc      1453.90k     1554.68k     1567.84k     1569.89k     1573.57k
+rc2 cfb       1199.86k     1251.69k     1253.57k     1259.56k     1251.31k
+rc2 cbc       1334.60k     1428.55k     1441.89k     1445.42k     1441.45k
+rsa  512 bits   0.024s
+rsa 1024 bits   0.125s
+rsa 2048 bits   0.806s
+rsa 4096 bits   5.800s
+
diff --git a/deps/openssl/openssl/times/aix.t b/deps/openssl/openssl/times/aix.t
new file mode 100644 (file)
index 0000000..4f24e39
--- /dev/null
@@ -0,0 +1,34 @@
+from Paco Garcia <pgarcia@ctv.es>
+This machine is a Bull Estrella  Minitower Model MT604-100
+Processor        : PPC604 
+P.Speed          : 100Mhz 
+Data/Instr Cache :    16 K
+L2 Cache         :   256 K
+PCI BUS Speed    :    33 Mhz
+TransfRate PCI   :   132 MB/s
+Memory           :    96 MB
+
+AIX 4.1.4
+
+SSLeay 0.6.6 14-Jan-1997
+built on Mon Jan 13 21:36:03 CUT 1997
+options:bn(64,32) md2(int) rc4(ptr,char) des(idx,cisc,4,long) idea(int) blowfish
+(idx)
+C flags:cc -O -DAIX -DB_ENDIAN
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                53.83k      147.46k      197.63k      215.72k     221.70k
+md5              1278.13k     5354.77k     8679.60k    10195.09k   10780.56k
+sha              1055.34k     4600.37k     7721.30k     9298.94k    9868.63k
+sha1              276.90k     1270.25k     2187.95k     2666.84k    2850.82k
+rc4              4660.57k     5268.93k     5332.48k     5362.47k    5346.65k
+des cbc          1774.16k     1981.10k     1979.56k     2032.71k    1972.25k
+des ede3          748.81k      781.42k      785.66k      785.75k     780.84k
+idea cbc         2066.19k     2329.58k     2378.91k     2379.86k    2380.89k
+rc2 cbc          1278.53k     1379.69k     1389.99k     1393.66k    1389.91k
+blowfish cbc     2812.91k     3307.90k     3364.91k     3386.37k    3374.32k
+rsa  512 bits   0.019s
+rsa 1024 bits   0.096s
+rsa 2048 bits   0.614s
+rsa 4096 bits   4.433s
+
diff --git a/deps/openssl/openssl/times/aixold.t b/deps/openssl/openssl/times/aixold.t
new file mode 100644 (file)
index 0000000..0b51412
--- /dev/null
@@ -0,0 +1,23 @@
+SSLeay 0.7.3r 20-May-1997
+built on Mon Jun  2 04:06:32 EST 1997
+options:bn(64,32) md2(int) rc4(ptr,char) des(idx,cisc,4,long) idea(int) blowfish(idx)
+C flags:cc -O -DAIX -DB_ENDIAN
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                19.09k       52.47k       71.23k       77.49k       78.93k
+md5               214.56k      941.21k     1585.43k     1883.12k     1988.70k
+sha               118.35k      521.65k      860.28k     1042.27k     1100.46k
+sha1              109.52k      478.98k      825.90k      995.48k     1049.69k
+rc4              1263.63k     1494.24k     1545.70k     1521.66k     1518.99k
+des cbc           259.62k      286.55k      287.15k      288.15k      289.45k
+des ede3          104.92k      107.88k      109.27k      109.25k      109.96k
+idea cbc          291.63k      320.07k      319.40k      320.51k      318.27k
+rc2 cbc           220.04k      237.76k      241.44k      245.90k      244.08k
+blowfish cbc      407.95k      474.83k      480.99k      485.71k      481.07k
+rsa  512 bits   0.157s   0.019
+rsa 1024 bits   0.908s   0.023
+rsa 2048 bits   6.225s   0.218
+rsa 4096 bits  46.500s   0.830
+dsa  512 bits   0.159s   0.312
+dsa 1024 bits   0.536s   1.057
+dsa 2048 bits   1.970s   3.977
diff --git a/deps/openssl/openssl/times/alpha.t b/deps/openssl/openssl/times/alpha.t
new file mode 100644 (file)
index 0000000..3a7c6c4
--- /dev/null
@@ -0,0 +1,81 @@
+SSLeay-051 Alpha gcc -O3 64Bit (assember bn_mul)
+type           8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2             44.40k      121.56k      162.73k      179.20k      185.01k
+md5            780.85k     3278.53k     5281.52k     6327.98k     6684.67k
+sha            501.40k     2249.19k     3855.27k     4801.19k     5160.96k
+sha-1          384.99k     1759.72k     3113.64k     3946.92k     4229.80k
+rc4           3505.05k     3724.54k     3723.78k     3555.33k     3694.68k
+des cfb        946.96k     1015.27k     1021.87k     1033.56k     1037.65k
+des cbc       1001.24k     1220.20k     1243.31k     1272.73k     1265.87k
+des ede3       445.34k      491.65k      500.53k      502.10k      502.44k
+idea cfb       643.53k      667.49k      663.81k      666.28k      664.51k
+idea cbc       650.42k      735.41k      733.27k      742.74k      745.47k
+rsa  512 bits   0.031s
+rsa 1024 bits   0.141s
+rsa 2048 bits   0.844s
+rsa 4096 bits   6.033s
+
+SSLeay-051 Alpha cc -O2 64bit (assember bn_mul)
+type           8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2             45.37k      122.86k      165.97k      182.95k      188.42k
+md5            842.42k     3629.93k     5916.76k     7039.17k     7364.61k
+sha            498.93k     2197.23k     3895.60k     4756.48k     5132.13k
+sha-1          382.02k     1757.21k     3112.53k     3865.23k     4128.77k
+rc4           2975.25k     3049.33k     3180.97k     3214.68k     3424.26k
+des cfb        901.55k      990.83k     1006.08k     1011.19k     1004.89k
+des cbc        947.84k     1127.84k     1163.67k     1162.24k     1157.80k
+des ede3       435.62k      485.57k      493.67k      491.52k      491.52k
+idea cfb       629.31k      648.66k      647.77k      648.53k      649.90k
+idea cbc       565.15k      608.00k      613.46k      613.38k      617.13k
+rsa  512 bits   0.030s
+rsa 1024 bits   0.141s
+rsa 2048 bits   0.854s
+rsa 4096 bits   6.067s
+
+des cfb        718.28k      822.64k      833.11k      836.27k      841.05k
+des cbc        806.10k      951.42k      975.83k      983.73k      991.23k
+des ede3       329.50k      379.11k      387.95k      387.41k      388.33k
+
+des cfb        871.62k      948.65k      951.81k      953.00k      955.58k
+des cbc        953.60k     1174.27k     1206.70k     1216.10k     1216.44k
+des ede3       349.34k      418.05k      427.26k      429.74k      431.45k
+
+
+
+
+SSLeay-045c Alpha gcc -O3 64Bit
+type           8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2             44.95k      122.22k      164.27k      180.62k      184.66k
+md5            808.71k     3371.95k     5415.68k     6385.66k     6684.67k
+sha            493.68k     2162.05k     3725.82k     4552.02k     4838.74k
+rc4           3317.32k     3649.09k     3728.30k     3744.09k     3691.86k
+cfb des        996.45k     1050.77k     1058.30k     1059.16k     1064.96k
+cbc des       1096.52k     1255.49k     1282.13k     1289.90k     1299.80k
+ede3 des       482.14k      513.51k      518.66k      520.19k      521.39k
+cfb idea       519.90k      533.40k      535.21k      535.55k      535.21k
+cbc idea       619.34k      682.21k      688.04k      689.15k      690.86k
+rsa  512 bits   0.050s
+rsa 1024 bits   0.279s
+rsa 2048 bits   1.908s
+rsa 4096 bits  14.750s
+
+type           8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2             37.31k      102.77k      137.64k      151.55k      155.78k
+md5            516.65k     2535.21k     4655.72k     5859.66k     6343.34k
+rc4           3519.61k     3707.01k     3746.86k     3755.39k     3675.48k
+cfb des        780.27k      894.68k      913.10k      921.26k      922.97k
+cbc des        867.54k     1040.13k     1074.17k     1075.54k     1084.07k
+ede3 des       357.19k      397.36k      398.08k      402.28k      401.41k
+cbc idea       646.53k      686.44k      694.03k      691.20k      693.59k
+rsa  512 bits   0.046s
+rsa 1024 bits   0.270s
+rsa 2048 bits   1.858s
+rsa 4096 bits  14.350s
+
+md2      C      37.83k      103.17k      137.90k      150.87k      155.37k
+md2      L      37.30k      102.04k      139.01k      152.74k      155.78k
+rc4       I   3532.24k     3718.08k     3750.83k     3768.78k     3694.59k
+rc4      CI   2662.97k     2873.26k     2907.22k     2920.63k     2886.31k
+rc4      LI   3514.63k     3738.72k     3747.41k     3752.96k     3708.49k
+cbc idea S     619.01k      658.68k      661.50k      662.53k      663.55k
+cbc idea  L    645.69k      684.22k      694.55k      692.57k      690.86k
diff --git a/deps/openssl/openssl/times/alpha400.t b/deps/openssl/openssl/times/alpha400.t
new file mode 100644 (file)
index 0000000..079e0d1
--- /dev/null
@@ -0,0 +1,25 @@
+Alpha EV5.6 (21164A) 400mhz
+
+SSLeay 0.7.3r 20-May-1997
+built on Mon Jun  2 03:39:58 EST 1997
+options:bn(64,64) md2(int) rc4(ptr,int) des(idx,cisc,4,long) idea(int) blowfish(idx)
+C flags:cc -arch host -tune host -fast -std -O4 -inline speed
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2               274.98k      760.96k     1034.27k     1124.69k     1148.69k
+md5              2524.46k    11602.60k    19838.81k    24075.26k    25745.10k
+sha              1848.46k     8335.66k    14232.49k    17247.91k    18530.30k
+sha1             1639.67k     7336.53k    12371.80k    14807.72k    15870.63k
+rc4             17950.93k    19390.66k    19652.44k    19700.39k    19412.31k
+des cbc          4018.59k     4872.06k     4988.76k     5003.26k     4995.73k
+des ede3         1809.11k     1965.67k     1984.26k     1986.90k     1982.46k
+idea cbc         2848.82k     3204.33k     3250.26k     3257.34k     3260.42k
+rc2 cbc          3766.08k     4349.50k     4432.21k     4448.94k     4448.26k
+blowfish cbc     6694.88k     9042.35k     9486.93k     9598.98k     9624.91k
+rsa  512 bits   0.003s   0.000
+rsa 1024 bits   0.013s   0.000
+rsa 2048 bits   0.081s   0.003
+rsa 4096 bits   0.577s   0.011
+dsa  512 bits   0.003s   0.005
+dsa 1024 bits   0.007s   0.014
+dsa 2048 bits   0.025s   0.050
diff --git a/deps/openssl/openssl/times/cyrix100.lnx b/deps/openssl/openssl/times/cyrix100.lnx
new file mode 100644 (file)
index 0000000..010a221
--- /dev/null
@@ -0,0 +1,22 @@
+SSLeay 0.6.6 06-Dec-1996
+built on Fri Dec  6 10:05:20 GMT 1996
+options:bn(64,32) md2(char) rc4(idx,int) des(idx,risc,16,long) idea(int)
+C flags:gcc -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized
+The 'numbers' are in 1000s of bytes per second processed.
+type           8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2             36.77k      102.48k      138.00k      151.57k      155.78k
+md5            513.59k     2577.22k     4623.51k     5768.99k     6214.53k
+sha            259.89k     1105.45k     1814.97k     2156.16k     2292.13k
+sha1           242.43k     1040.95k     1719.44k     2049.74k     2164.64k
+rc4           1984.48k     2303.41k     2109.37k     2071.47k     1985.61k
+des cfb        712.08k      758.29k      753.17k      752.06k      748.67k
+des cbc        787.37k      937.64k      956.77k      961.61k      957.54k
+des ede3       353.97k      377.28k      379.99k      379.34k      379.11k
+idea cfb       403.80k      418.50k      416.60k      415.78k      415.03k
+idea cbc       426.54k      466.40k      471.31k      472.67k      473.14k
+rc2 cfb        405.15k      420.05k      418.16k      416.72k      416.36k
+rc2 cbc        428.21k      468.43k      473.09k      472.59k      474.70k
+rsa  512 bits   0.040s
+rsa 1024 bits   0.195s
+rsa 2048 bits   1.201s
+rsa 4096 bits   8.700s
diff --git a/deps/openssl/openssl/times/dgux-x86.t b/deps/openssl/openssl/times/dgux-x86.t
new file mode 100644 (file)
index 0000000..70635c5
--- /dev/null
@@ -0,0 +1,23 @@
+version:SSLeay 0.5.2c 15-May-1996
+built Fri Jun 14 19:47:04 EST 1996
+options:bn(LLONG,thirty_two) md2(CHAR) rc4(IDX,int) des(ary,long) idea(int)
+C flags:gcc -O3 -fomit-frame-pointer -DL_ENDIAN
+
+type           8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2            113.86k      316.48k      428.36k      467.63k      481.56k
+md5           1001.99k     5037.99k     9545.94k    12036.95k    11800.38k
+sha            628.77k     2743.48k     5113.42k     6206.99k     6165.42k
+sha1           583.83k     2638.66k     4538.85k     5532.09k     5917.04k
+rc4           5493.27k     6369.39k     6511.30k     6577.83k     6486.73k
+des cfb       1219.01k     1286.06k     1299.33k     1288.87k     1381.72k
+des cbc       1360.58k     1469.04k     1456.96k     1454.08k     1513.57k
+des ede3       544.45k      567.84k      568.99k      570.37k      566.09k
+idea cfb      1012.39k     1056.30k     1063.52k      989.17k      863.24k
+idea cbc       985.36k     1090.44k     1105.92k     1108.65k     1090.17k
+rc2 cfb        963.86k      979.06k      995.30k      937.35k      827.39k
+rc2 cbc        951.72k     1042.11k     1049.60k     1047.21k     1059.11k
+rsa  512 bits   0.032s
+rsa 1024 bits   0.159s
+rsa 2048 bits   1.025s
+rsa 4096 bits   7.270s
+
diff --git a/deps/openssl/openssl/times/dgux.t b/deps/openssl/openssl/times/dgux.t
new file mode 100644 (file)
index 0000000..c7f7564
--- /dev/null
@@ -0,0 +1,17 @@
+type           8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2             38.54k      106.28k      144.00k      157.46k      161.72k
+md5            323.23k     1471.62k     2546.11k     3100.20k     3309.57k
+rc4        I  1902.74k     2055.20k     2080.42k     2077.88k     2065.46k
+cfb des        456.23k      475.22k      481.79k      488.42k      487.17k
+cbc des        484.30k      537.50k      553.09k      558.08k      558.67k
+ede3 des       199.97k      209.05k      211.03k      211.85k      212.78k
+cbc idea       478.50k      519.33k      523.42k      525.09k      526.44k
+rsa  512 bits   0.159s !RSA_LLONG
+rsa 1024 bits   1.053s
+rsa 2048 bits   7.600s
+rsa 4096 bits  59.760s
+
+md2       C     30.53k       83.58k      112.84k      123.22k      126.24k
+rc4           1844.56k     1975.50k     1997.73k     1994.95k     1984.88k
+rc4       C   1800.09k     1968.85k     1995.20k     1992.36k     1996.80k
+rc4       CI  1830.81k     2035.75k     2067.28k     2070.23k     2062.77k
diff --git a/deps/openssl/openssl/times/hpux-acc.t b/deps/openssl/openssl/times/hpux-acc.t
new file mode 100644 (file)
index 0000000..0c0e936
--- /dev/null
@@ -0,0 +1,25 @@
+HPUX 887
+
+SSLeay 0.7.3r 20-May-1997
+built on Mon Jun  2 02:59:45 EST 1997
+options:bn(32,32) md2(int) rc4(ptr,int) des(ptr,risc1,16,long) idea(int) blowfish(idx)
+C flags:cc -DB_ENDIAN -D_HPUX_SOURCE -Aa -Ae +ESlit +O4 -Wl,-a,archive
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                58.99k      166.85k      225.07k      247.21k      253.76k
+md5               639.22k     2726.98k     4477.25k     5312.69k     5605.20k
+sha               381.08k     1661.49k     2793.84k     3368.86k     3581.23k
+sha1              349.54k     1514.56k     2536.63k     3042.59k     3224.39k
+rc4              2891.10k     4238.01k     4464.11k     4532.49k     4545.87k
+des cbc           717.05k      808.76k      820.14k      821.97k      821.96k
+des ede3          288.21k      303.50k      303.69k      305.82k      305.14k
+idea cbc          325.83k      334.36k      335.89k      336.61k      333.43k
+rc2 cbc           793.00k      915.81k      926.69k      933.28k      929.53k
+blowfish cbc     1561.91k     2051.97k     2122.65k     2139.40k     2145.92k
+rsa  512 bits   0.031s   0.004
+rsa 1024 bits   0.164s   0.004
+rsa 2048 bits   1.055s   0.037
+rsa 4096 bits   7.600s   0.137
+dsa  512 bits   0.029s   0.057
+dsa 1024 bits   0.092s   0.177
+dsa 2048 bits   0.325s   0.646
diff --git a/deps/openssl/openssl/times/hpux-kr.t b/deps/openssl/openssl/times/hpux-kr.t
new file mode 100644 (file)
index 0000000..ad4a0ad
--- /dev/null
@@ -0,0 +1,23 @@
+SSLeay 0.7.3r 20-May-1997
+built on Mon Jun  2 02:17:35 EST 1997
+options:bn(32,32) md2(int) rc4(ptr,int) des(ptr,cisc,16,long) idea(int) blowfish(idx)
+C flags:cc -DB_ENDIAN -DNOCONST -DNOPROTO -D_HPUX_SOURCE
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                35.30k       98.36k      133.41k      146.34k      150.69k
+md5               391.20k     1737.31k     2796.65k     3313.75k     3503.74k
+sha               189.55k      848.14k     1436.72k     1735.87k     1848.03k
+sha1              175.30k      781.14k     1310.32k     1575.61k     1675.81k
+rc4              2070.55k     2501.47k     2556.65k     2578.34k     2584.91k
+des cbc           465.13k      536.85k      545.87k      547.86k      548.89k
+des ede3          190.05k      200.99k      202.31k      202.22k      202.75k
+idea cbc          263.44k      277.77k      282.13k      281.51k      283.15k
+rc2 cbc           448.37k      511.39k      519.54k      522.00k      521.31k
+blowfish cbc      839.98k     1097.70k     1131.16k     1145.64k     1144.67k
+rsa  512 bits   0.048s   0.005
+rsa 1024 bits   0.222s   0.006
+rsa 2048 bits   1.272s   0.042
+rsa 4096 bits   8.445s   0.149
+dsa  512 bits   0.041s   0.077
+dsa 1024 bits   0.111s   0.220
+dsa 2048 bits   0.363s   0.726
diff --git a/deps/openssl/openssl/times/hpux.t b/deps/openssl/openssl/times/hpux.t
new file mode 100644 (file)
index 0000000..dcf7615
--- /dev/null
@@ -0,0 +1,86 @@
+HP-UX A.09.05 9000/712
+
+SSLeay 0.6.6 14-Jan-1997
+built on Tue Jan 14 16:36:31 WET 1997
+options:bn(32,32) md2(int) rc4(ptr,int) des(ptr,risc1,16,long) idea(int) 
+blowfish(idx)
+C flags:cc -DB_ENDIAN -D_HPUX_SOURCE -Aa +ESlit +O2 -Wl,-a,archive
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                66.56k      184.92k      251.82k      259.86k      282.62k
+md5               615.54k     2805.92k     4764.30k     5724.21k     6084.39k
+sha               358.23k     1616.46k     2781.50k     3325.72k     3640.89k
+sha1              327.50k     1497.98k     2619.44k     3220.26k     3460.85k
+rc4              3500.47k     3890.99k     3943.81k     3883.74k     3900.02k
+des cbc           742.65k      871.66k      887.15k      891.21k      895.40k
+des ede3          302.42k      322.50k      324.46k      326.66k      326.05k
+idea cbc          664.41k      755.87k      765.61k      772.70k      773.69k
+rc2 cbc           798.78k      931.04k      947.69k      950.31k      952.04k
+blowfish cbc     1353.32k     1932.29k     2021.93k     2047.02k     2053.66k
+rsa  512 bits   0.059s
+rsa 1024 bits   0.372s
+rsa 2048 bits   2.697s
+rsa 4096 bits  20.790s
+
+SSLeay 0.6.6 14-Jan-1997
+built on Tue Jan 14 15:37:30 WET 1997
+options:bn(64,32) md2(int) rc4(ptr,int) des(ptr,risc1,16,long) idea(int) 
+blowfish(idx)
+C flags:gcc -DB_ENDIAN -O3
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                44.91k      122.57k      167.71k      183.89k      190.24k
+md5               532.50k     2316.27k     3965.72k     4740.11k     5055.06k
+sha               363.76k     1684.09k     2978.53k     3730.86k     3972.72k
+sha1              385.76k     1743.53k     2997.69k     3650.74k     3899.08k
+rc4              3178.84k     3621.31k     3672.71k     3684.01k     3571.54k
+des cbc           733.00k      844.70k      863.28k      863.72k      868.73k
+des ede3          289.99k      308.94k      310.11k      309.64k      312.08k
+idea cbc          624.07k      713.91k      724.76k      723.35k      725.13k
+rc2 cbc           704.34k      793.39k      804.25k      805.99k      782.63k
+blowfish cbc     1371.24k     1823.66k     1890.05k     1915.51k     1920.12k
+rsa  512 bits   0.030s
+rsa 1024 bits   0.156s
+rsa 2048 bits   1.113s
+rsa 4096 bits   7.480s
+
+
+HPUX B.10.01 V 9000/887 - HP92453-01 A.10.11 HP C Compiler
+SSLeay 0.5.2 - -Aa +ESlit +Oall +O4 -Wl,-a,archive
+
+HPUX A.09.04 B 9000/887
+
+ssleay 0.5.1 gcc v 2.7.0 -O3 -mpa-risc-1-1
+type           8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2             53.00k      166.81k      205.66k      241.95k      242.20k
+md5            743.22k     3128.44k     6031.85k     6142.07k     7025.26k
+sha            481.30k     2008.24k     3361.31k     3985.07k     4180.74k
+sha-1          463.60k     1916.15k     3139.24k     3786.27k     3997.70k
+rc4           3708.61k     4125.16k     4547.53k     4206.21k     4390.07k
+des cfb        665.91k      705.97k      698.48k      694.25k      666.08k
+des cbc        679.80k      741.90k      769.85k      747.62k      719.47k
+des ede3       264.31k      270.22k      265.63k      273.07k      273.07k
+idea cfb       635.91k      673.40k      605.60k      699.53k      672.36k
+idea cbc       705.85k      774.63k      750.60k      715.83k      721.50k
+rsa  512 bits   0.066s
+rsa 1024 bits   0.372s
+rsa 2048 bits   2.177s
+rsa 4096 bits  16.230s
+
+HP92453-01 A.09.61 HP C Compiler
+ssleay 0.5.1 cc -Ae +ESlit +Oall -Wl,-a,archive
+type           8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2             58.69k      163.30k      213.57k      230.40k      254.23k
+md5            608.60k     2596.82k     3871.43k     4684.10k     4763.88k
+sha            343.26k     1482.43k     2316.80k     2766.27k     2860.26k
+sha-1          319.15k     1324.13k     2106.03k     2527.82k     2747.95k
+rc4           2467.47k     3374.41k     3265.49k     3354.39k     3368.55k
+des cfb        812.05k      814.90k      851.20k      819.20k      854.56k
+des cbc        836.35k      994.06k      916.02k     1020.01k      988.14k
+des ede3       369.78k      389.15k      401.01k      382.94k      408.03k
+idea cfb       290.40k      298.06k      286.11k      296.92k      299.46k
+idea cbc       301.30k      297.72k      304.34k      300.10k      309.70k
+rsa  512 bits   0.350s
+rsa 1024 bits   2.635s
+rsa 2048 bits  19.930s
+
diff --git a/deps/openssl/openssl/times/p2.w95 b/deps/openssl/openssl/times/p2.w95
new file mode 100644 (file)
index 0000000..82d1e55
--- /dev/null
@@ -0,0 +1,22 @@
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2               235.90k      652.30k      893.36k      985.74k      985.74k
+mdc2              779.61k      816.81k      825.65k      816.01k      825.65k
+md5              2788.77k    13508.23k    24672.38k    30504.03k    33156.55k
+sha              1938.22k     8397.01k    14122.24k    16980.99k    18196.55k
+sha1             1817.29k     7832.50k    13168.93k    15738.48k    16810.84k
+rc4             15887.52k    21709.65k    22745.68k    22995.09k    22995.09k
+des cbc          4599.02k     5377.31k     5377.31k     5533.38k     5533.38k
+des ede3         1899.59k     2086.71k     2086.67k     2086.51k     2085.90k
+idea cbc         3350.08k     3934.62k     3979.42k     4017.53k     4017.53k
+rc2 cbc          1534.13k     1630.76k     1625.70k     1644.83k     1653.91k
+blowfish cbc     6678.83k     8490.49k     8701.88k     8848.74k     8886.24k
+                  sign    verify
+rsa  512 bits   0.0062s   0.0008s
+rsa 1024 bits   0.0287s   0.0009s
+rsa 2048 bits   0.1785s   0.0059s
+rsa 4096 bits   1.1300s   0.0205s
+                  sign    verify
+dsa  512 bits   0.0055s   0.0100s
+dsa 1024 bits   0.0154s   0.0299s
+dsa 2048 bits   0.0502s   0.0996s
diff --git a/deps/openssl/openssl/times/pent2.t b/deps/openssl/openssl/times/pent2.t
new file mode 100644 (file)
index 0000000..b6dc269
--- /dev/null
@@ -0,0 +1,24 @@
+pentium 2, 266mhz, Visual C++ 5.0, Windows 95
+
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2               235.90k      652.30k      893.36k      985.74k      985.74k
+mdc2              779.61k      816.81k      825.65k      816.01k      825.65k
+md5              2788.77k    13508.23k    24672.38k    30504.03k    33156.55k
+sha              1938.22k     8397.01k    14122.24k    16980.99k    18196.55k
+sha1             1817.29k     7832.50k    13168.93k    15738.48k    16810.84k
+rc4             15887.52k    21709.65k    22745.68k    22995.09k    22995.09k
+des cbc          4599.02k     5377.31k     5377.31k     5533.38k     5533.38k
+des ede3         1899.59k     2086.71k     2086.67k     2086.51k     2085.90k
+idea cbc         3350.08k     3934.62k     3979.42k     4017.53k     4017.53k
+rc2 cbc          1534.13k     1630.76k     1625.70k     1644.83k     1653.91k
+blowfish cbc     6678.83k     8490.49k     8701.88k     8848.74k     8886.24k
+                  sign    verify
+rsa  512 bits   0.0062s   0.0008s
+rsa 1024 bits   0.0287s   0.0009s
+rsa 2048 bits   0.1785s   0.0059s
+rsa 4096 bits   1.1300s   0.0205s
+                  sign    verify
+dsa  512 bits   0.0055s   0.0100s
+dsa 1024 bits   0.0154s   0.0299s
+dsa 2048 bits   0.0502s   0.0996s
diff --git a/deps/openssl/openssl/times/readme b/deps/openssl/openssl/times/readme
new file mode 100644 (file)
index 0000000..7074f58
--- /dev/null
@@ -0,0 +1,11 @@
+The 'times' in this directory are not all for the most recent version of
+the library and it should be noted that on some CPUs (specifically sparc
+and Alpha), the locations of files in the application after linking can
+make upto a %10 speed difference when running benchmarks on things like
+cbc mode DES.  To put it mildly this can be very anoying.
+
+About the only way to get around this would be to compile the library as one
+object file, or to 'include' the source files in a specific order.
+
+The best way to get an idea of the 'raw' DES speed is to build the 
+'speed' program in crypto/des.
diff --git a/deps/openssl/openssl/times/s586-100.lnx b/deps/openssl/openssl/times/s586-100.lnx
new file mode 100644 (file)
index 0000000..cbc3e3c
--- /dev/null
@@ -0,0 +1,25 @@
+Shared library build
+
+SSLeay 0.7.3 30-Apr-1997
+built on Tue May 13 03:43:56 EST 1997
+options:bn(64,32) md2(char) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2)
+C flags:-DTERMIO -O3 -DL_ENDIAN -fomit-frame-pointer -m486 -Wall
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                68.95k      191.40k      258.22k      283.31k      291.21k
+md5               627.37k     3064.75k     5370.15k     6765.91k     7255.38k
+sha               323.35k     1431.32k     2417.07k     2916.69k     3102.04k
+sha1              298.08k     1318.34k     2228.82k     2694.83k     2864.47k
+rc4              3404.13k     4026.33k     4107.43k     4136.28k     4117.85k
+des cbc          1414.60k     1782.53k     1824.24k     1847.64k     1840.47k
+des ede3          588.36k      688.19k      700.33k      702.46k      704.51k
+idea cbc          582.96k      636.71k      641.54k      642.39k      642.30k
+rc2 cbc           569.34k      612.37k      617.64k      617.47k      619.86k
+blowfish cbc     2015.77k     2534.49k     2609.65k     2607.10k     2615.98k
+rsa  512 bits   0.027s   0.003
+rsa 1024 bits   0.128s   0.003
+rsa 2048 bits   0.779s   0.027
+rsa 4096 bits   5.450s   0.098
+dsa  512 bits   0.024s   0.045
+dsa 1024 bits   0.068s   0.132
+dsa 2048 bits   0.231s   0.469
diff --git a/deps/openssl/openssl/times/s586-100.nt b/deps/openssl/openssl/times/s586-100.nt
new file mode 100644 (file)
index 0000000..8e3baf6
--- /dev/null
@@ -0,0 +1,23 @@
+SSLeay 0.7.3 30-Apr-1997
+built on Mon May 19 10:47:38 EST 1997
+options:bn(64,32) md2(char) rc4(idx,int) des(idx,cisc,4,long) idea(int) blowfish(ptr2)
+C flags not available
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                90.26k      248.57k      335.06k      366.09k      376.64k
+md5               863.95k     4205.24k     7628.78k     9582.60k    10290.25k
+sha               463.93k     2102.51k     3623.28k     4417.85k     4695.29k
+sha1              458.23k     2005.88k     3385.78k     4094.00k     4340.13k
+rc4              5843.60k     7543.71k     7790.31k     7836.89k     7791.47k
+des cbc          1583.95k     1910.67k     1960.69k     1972.12k     1946.13k
+des ede3          654.79k      722.60k      740.97k      745.82k      738.27k
+idea cbc          792.04k      876.96k      887.35k      892.63k      890.36k
+rc2 cbc           603.50k      652.38k      661.85k      662.69k      661.44k
+blowfish cbc     2379.88k     3043.76k     3153.61k     3153.61k     3134.76k
+rsa  512 bits   0.022s   0.003
+rsa 1024 bits   0.111s   0.003
+rsa 2048 bits   0.716s   0.025
+rsa 4096 bits   5.188s   0.094
+dsa  512 bits   0.020s   0.039
+dsa 1024 bits   0.062s   0.124
+dsa 2048 bits   0.221s   0.441
diff --git a/deps/openssl/openssl/times/sgi.t b/deps/openssl/openssl/times/sgi.t
new file mode 100644 (file)
index 0000000..7963610
--- /dev/null
@@ -0,0 +1,29 @@
+SGI Challenge R4400 200mhz IRIX 5.3 - gcc (2.6.3)
+SSLeay 0.6.1 02-Jul-1996
+built on Tue Jul  2 16:25:30 EST 1996
+options:bn(64,32) md2(char) rc4(idx,char) des(idx,long) idea(int)
+C flags:gcc -O2 -mips2 -DTERMIOS -DB_ENDIAN
+The 'numbers' are in 1000s of bytes per second processed.
+type           8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2             96.53k      266.70k      360.09k      393.70k      405.07k
+md5            971.15k     4382.56k     7406.90k     8979.99k     9559.18k
+sha            596.86k     2832.26k     4997.30k     6277.75k     6712.89k
+sha1           578.34k     2630.16k     4632.05k     5684.34k     6083.37k
+rc4           5641.12k     6821.76k     6996.13k     7052.61k     6913.32k
+des cfb       1354.86k     1422.11k     1434.58k     1433.24k     1432.89k
+des cbc       1467.13k     1618.92k     1630.08k     1637.00k     1629.62k
+des ede3       566.13k      591.91k      596.86k      596.18k      592.54k
+idea cfb      1190.60k     1264.49k     1270.38k     1267.84k     1272.37k
+idea cbc      1271.45k     1410.37k     1422.49k     1426.46k     1421.73k
+rc2 cfb       1285.73k     1371.40k     1380.92k     1383.13k     1379.23k
+rc2 cbc       1386.61k     1542.10k     1562.49k     1572.45k     1567.93k
+rsa  512 bits   0.018s
+rsa 1024 bits   0.106s
+rsa 2048 bits   0.738s
+rsa 4096 bits   5.535s
+
+version:SSLeay 0.5.2c 15-May-1996
+rsa  512 bits   0.035s
+rsa 1024 bits   0.204s
+rsa 2048 bits   1.423s
+rsa 4096 bits  10.800s
diff --git a/deps/openssl/openssl/times/sparc.t b/deps/openssl/openssl/times/sparc.t
new file mode 100644 (file)
index 0000000..1611f76
--- /dev/null
@@ -0,0 +1,26 @@
+gcc 2.7.2
+Sparc 10 - Solaris 2.3 - 50mhz
+SSLeay 0.7.3r 20-May-1997
+built on Mon Jun  2 00:55:51 EST 1997
+options:bn(64,32) md2(int) rc4(ptr,char) des(idx,cisc,16,long) idea(int) blowfish(ptr)
+C flags:gcc -O3 -fomit-frame-pointer -mv8 -Wall
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                54.88k      154.52k      210.35k      231.08k      237.21k
+md5               550.75k     2460.49k     4116.01k     4988.74k     5159.86k
+sha               340.28k     1461.76k     2430.10k     2879.87k     2999.15k
+sha1              307.27k     1298.41k     2136.26k     2540.07k     2658.28k
+rc4              2652.21k     2805.24k     3301.63k     4003.98k     4071.18k
+des cbc           811.78k      903.93k      914.19k      921.60k      932.29k
+des ede3          328.21k      344.93k      349.64k      351.48k      345.07k
+idea cbc          685.06k      727.42k      734.41k      730.11k      739.21k
+rc2 cbc           718.59k      777.02k      781.96k      784.38k      782.60k
+blowfish cbc     1268.85k     1520.64k     1568.88k     1587.54k     1591.98k
+rsa  512 bits   0.037s   0.005
+rsa 1024 bits   0.213s   0.006
+rsa 2048 bits   1.471s   0.053
+rsa 4096 bits  11.100s   0.202
+dsa  512 bits   0.038s   0.074
+dsa 1024 bits   0.128s   0.248
+dsa 2048 bits   0.473s   0.959
+
diff --git a/deps/openssl/openssl/times/sparc2 b/deps/openssl/openssl/times/sparc2
new file mode 100644 (file)
index 0000000..4b0dd80
--- /dev/null
@@ -0,0 +1,21 @@
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                14.56k       40.25k       54.95k       60.13k       62.18k
+mdc2               53.59k       57.45k       58.11k       58.21k       58.51k
+md5               176.95k      764.75k     1270.36k     1520.14k     1608.36k
+hmac(md5)          55.88k      369.70k      881.15k     1337.05k     1567.40k
+sha1               92.69k      419.75k      723.63k      878.82k      939.35k
+rc4              1247.28k     1414.09k     1434.30k     1434.34k     1441.13k
+des cbc           284.41k      318.58k      323.07k      324.09k      323.87k
+des ede3          109.99k      119.99k      121.60k      121.87k      121.66k
+idea cbc           43.06k       43.68k       43.84k       43.64k       44.07k
+rc2 cbc           278.85k      311.44k      316.50k      316.57k      317.37k
+blowfish cbc      468.89k      569.35k      581.61k      568.34k      559.54k
+cast cbc          285.84k      338.79k      345.71k      346.19k      341.09k
+                  sign    verify
+rsa  512 bits   0.4175s   0.0519s
+rsa 1024 bits   2.9325s   0.1948s
+rsa 2048 bits  22.3600s   0.7669s
+                 sign    verify
+dsa  512 bits   0.5178s   1.0300s
+dsa 1024 bits   1.8780s   3.7167s
+dsa 2048 bits   7.3500s  14.4800s
diff --git a/deps/openssl/openssl/times/sparcLX.t b/deps/openssl/openssl/times/sparcLX.t
new file mode 100644 (file)
index 0000000..2fdaed7
--- /dev/null
@@ -0,0 +1,22 @@
+Sparc Station LX
+SSLeay 0.7.3 30-Apr-1997
+built on Thu May  1 10:44:02 EST 1997
+options:bn(64,32) md2(int) rc4(ptr,char) des(idx,cisc,16,long) idea(int) blowfish(ptr)
+C flags:gcc -O3 -fomit-frame-pointer -mv8 -Wall
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2                17.60k       48.72k       66.47k       72.70k       74.72k
+md5               226.24k     1082.21k     1982.72k     2594.02k     2717.01k
+sha                71.38k      320.71k      551.08k      677.76k      720.90k
+sha1               63.08k      280.79k      473.86k      576.94k      608.94k
+rc4              1138.30k     1257.67k     1304.49k     1377.78k     1364.42k
+des cbc           265.34k      308.85k      314.28k      315.39k      317.20k
+des ede3           83.23k       93.13k       94.04k       94.50k       94.63k
+idea cbc          254.48k      274.26k      275.88k      274.68k      275.80k
+rc2 cbc           328.27k      375.39k      381.43k      381.61k      380.83k
+blowfish cbc      487.00k      498.02k      510.12k      515.41k      516.10k
+rsa  512 bits   0.093s
+rsa 1024 bits   0.537s
+rsa 2048 bits   3.823s
+rsa 4096 bits  28.650s
+
diff --git a/deps/openssl/openssl/times/usparc.t b/deps/openssl/openssl/times/usparc.t
new file mode 100644 (file)
index 0000000..2215624
--- /dev/null
@@ -0,0 +1,25 @@
+Sparc 2000? - Solaris 2.5.1 - 167mhz Ultra sparc
+
+SSLeay 0.7.3r 20-May-1997
+built on Mon Jun  2 02:25:48 EST 1997
+options:bn(64,32) md2(int) rc4(ptr,char) des(ptr,risc1,16,long) idea(int) blowfish(ptr)
+C flags:cc cc -xtarget=ultra -xarch=v8plus -Xa -xO5 -Xa -DB_ENDIAN
+The 'numbers' are in 1000s of bytes per second processed.
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+md2               135.23k      389.87k      536.66k      591.87k      603.48k
+md5              1534.38k     6160.41k     9842.69k    11446.95k    11993.09k
+sha              1178.30k     5020.74k     8532.22k    10275.50k    11010.05k
+sha1             1114.22k     4703.94k     7703.81k     9236.14k     9756.67k
+rc4             10818.03k    13327.57k    13711.10k    13810.69k    13836.29k
+des cbc          3052.44k     3320.02k     3356.25k     3369.98k     3295.91k
+des ede3         1310.32k     1359.98k     1367.47k     1362.94k     1362.60k
+idea cbc         1749.52k     1833.13k     1844.74k     1848.32k     1848.66k
+rc2 cbc          1950.25k     2053.23k     2064.21k     2072.58k     2072.58k
+blowfish cbc     4927.16k     5659.75k     5762.73k     5797.55k     5805.40k
+rsa  512 bits   0.021s   0.003
+rsa 1024 bits   0.126s   0.003
+rsa 2048 bits   0.888s   0.032
+rsa 4096 bits   6.770s   0.122
+dsa  512 bits   0.022s   0.043
+dsa 1024 bits   0.076s   0.151
+dsa 2048 bits   0.286s   0.574
diff --git a/deps/openssl/openssl/times/x86/bfs.cpp b/deps/openssl/openssl/times/x86/bfs.cpp
new file mode 100644 (file)
index 0000000..d74c457
--- /dev/null
@@ -0,0 +1,67 @@
+//
+// gettsc.inl
+//
+// gives access to the Pentium's (secret) cycle counter
+//
+// This software was written by Leonard Janke (janke@unixg.ubc.ca)
+// in 1996-7 and is entered, by him, into the public domain.
+
+#if defined(__WATCOMC__)
+void GetTSC(unsigned long&);
+#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
+#elif defined(__GNUC__)
+inline
+void GetTSC(unsigned long& tsc)
+{
+  asm volatile(".byte 15, 49\n\t"
+              : "=eax" (tsc)
+              :
+              : "%edx", "%eax");
+}
+#elif defined(_MSC_VER)
+inline
+void GetTSC(unsigned long& tsc)
+{
+  unsigned long a;
+  __asm _emit 0fh
+  __asm _emit 31h
+  __asm mov a, eax;
+  tsc=a;
+}
+#endif      
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <openssl/blowfish.h>
+
+void main(int argc,char *argv[])
+       {
+       BF_KEY key;
+       unsigned long s1,s2,e1,e2;
+       unsigned long data[2];
+       int i,j;
+
+       for (j=0; j<6; j++)
+               {
+               for (i=0; i<1000; i++) /**/
+                       {
+                       BF_encrypt(&data[0],&key);
+                       GetTSC(s1);
+                       BF_encrypt(&data[0],&key);
+                       BF_encrypt(&data[0],&key);
+                       BF_encrypt(&data[0],&key);
+                       GetTSC(e1);
+                       GetTSC(s2);
+                       BF_encrypt(&data[0],&key);
+                       BF_encrypt(&data[0],&key);
+                       BF_encrypt(&data[0],&key);
+                       BF_encrypt(&data[0],&key);
+                       GetTSC(e2);
+                       BF_encrypt(&data[0],&key);
+                       }
+
+               printf("blowfish %d %d (%d)\n",
+                       e1-s1,e2-s2,((e2-s2)-(e1-s1)));
+               }
+       }
+
diff --git a/deps/openssl/openssl/times/x86/casts.cpp b/deps/openssl/openssl/times/x86/casts.cpp
new file mode 100644 (file)
index 0000000..7661191
--- /dev/null
@@ -0,0 +1,67 @@
+//
+// gettsc.inl
+//
+// gives access to the Pentium's (secret) cycle counter
+//
+// This software was written by Leonard Janke (janke@unixg.ubc.ca)
+// in 1996-7 and is entered, by him, into the public domain.
+
+#if defined(__WATCOMC__)
+void GetTSC(unsigned long&);
+#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
+#elif defined(__GNUC__)
+inline
+void GetTSC(unsigned long& tsc)
+{
+  asm volatile(".byte 15, 49\n\t"
+              : "=eax" (tsc)
+              :
+              : "%edx", "%eax");
+}
+#elif defined(_MSC_VER)
+inline
+void GetTSC(unsigned long& tsc)
+{
+  unsigned long a;
+  __asm _emit 0fh
+  __asm _emit 31h
+  __asm mov a, eax;
+  tsc=a;
+}
+#endif      
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <openssl/cast.h>
+
+void main(int argc,char *argv[])
+       {
+       CAST_KEY key;
+       unsigned long s1,s2,e1,e2;
+       unsigned long data[2];
+       int i,j;
+
+       for (j=0; j<6; j++)
+               {
+               for (i=0; i<1000; i++) /**/
+                       {
+                       CAST_encrypt(&data[0],&key);
+                       GetTSC(s1);
+                       CAST_encrypt(&data[0],&key);
+                       CAST_encrypt(&data[0],&key);
+                       CAST_encrypt(&data[0],&key);
+                       GetTSC(e1);
+                       GetTSC(s2);
+                       CAST_encrypt(&data[0],&key);
+                       CAST_encrypt(&data[0],&key);
+                       CAST_encrypt(&data[0],&key);
+                       CAST_encrypt(&data[0],&key);
+                       GetTSC(e2);
+                       CAST_encrypt(&data[0],&key);
+                       }
+
+               printf("cast %d %d (%d)\n",
+                       e1-s1,e2-s2,((e2-s2)-(e1-s1)));
+               }
+       }
+
diff --git a/deps/openssl/openssl/times/x86/des3s.cpp b/deps/openssl/openssl/times/x86/des3s.cpp
new file mode 100644 (file)
index 0000000..cd2b112
--- /dev/null
@@ -0,0 +1,67 @@
+//
+// gettsc.inl
+//
+// gives access to the Pentium's (secret) cycle counter
+//
+// This software was written by Leonard Janke (janke@unixg.ubc.ca)
+// in 1996-7 and is entered, by him, into the public domain.
+
+#if defined(__WATCOMC__)
+void GetTSC(unsigned long&);
+#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
+#elif defined(__GNUC__)
+inline
+void GetTSC(unsigned long& tsc)
+{
+  asm volatile(".byte 15, 49\n\t"
+              : "=eax" (tsc)
+              :
+              : "%edx", "%eax");
+}
+#elif defined(_MSC_VER)
+inline
+void GetTSC(unsigned long& tsc)
+{
+  unsigned long a;
+  __asm _emit 0fh
+  __asm _emit 31h
+  __asm mov a, eax;
+  tsc=a;
+}
+#endif      
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <openssl/des.h>
+
+void main(int argc,char *argv[])
+       {
+       des_key_schedule key1,key2,key3;
+       unsigned long s1,s2,e1,e2;
+       unsigned long data[2];
+       int i,j;
+
+       for (j=0; j<6; j++)
+               {
+               for (i=0; i<1000; i++) /**/
+                       {
+                       des_encrypt3(&data[0],key1,key2,key3);
+                       GetTSC(s1);
+                       des_encrypt3(&data[0],key1,key2,key3);
+                       des_encrypt3(&data[0],key1,key2,key3);
+                       des_encrypt3(&data[0],key1,key2,key3);
+                       GetTSC(e1);
+                       GetTSC(s2);
+                       des_encrypt3(&data[0],key1,key2,key3);
+                       des_encrypt3(&data[0],key1,key2,key3);
+                       des_encrypt3(&data[0],key1,key2,key3);
+                       des_encrypt3(&data[0],key1,key2,key3);
+                       GetTSC(e2);
+                       des_encrypt3(&data[0],key1,key2,key3);
+                       }
+
+               printf("des3 %d %d (%d)\n",
+                       e1-s1,e2-s2,((e2-s2)-(e1-s1)));
+               }
+       }
+
diff --git a/deps/openssl/openssl/times/x86/dess.cpp b/deps/openssl/openssl/times/x86/dess.cpp
new file mode 100644 (file)
index 0000000..753e67a
--- /dev/null
@@ -0,0 +1,67 @@
+//
+// gettsc.inl
+//
+// gives access to the Pentium's (secret) cycle counter
+//
+// This software was written by Leonard Janke (janke@unixg.ubc.ca)
+// in 1996-7 and is entered, by him, into the public domain.
+
+#if defined(__WATCOMC__)
+void GetTSC(unsigned long&);
+#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
+#elif defined(__GNUC__)
+inline
+void GetTSC(unsigned long& tsc)
+{
+  asm volatile(".byte 15, 49\n\t"
+              : "=eax" (tsc)
+              :
+              : "%edx", "%eax");
+}
+#elif defined(_MSC_VER)
+inline
+void GetTSC(unsigned long& tsc)
+{
+  unsigned long a;
+  __asm _emit 0fh
+  __asm _emit 31h
+  __asm mov a, eax;
+  tsc=a;
+}
+#endif      
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <openssl/des.h>
+
+void main(int argc,char *argv[])
+       {
+       des_key_schedule key;
+       unsigned long s1,s2,e1,e2;
+       unsigned long data[2];
+       int i,j;
+
+       for (j=0; j<6; j++)
+               {
+               for (i=0; i<1000; i++) /**/
+                       {
+                       des_encrypt(&data[0],key,1);
+                       GetTSC(s1);
+                       des_encrypt(&data[0],key,1);
+                       des_encrypt(&data[0],key,1);
+                       des_encrypt(&data[0],key,1);
+                       GetTSC(e1);
+                       GetTSC(s2);
+                       des_encrypt(&data[0],key,1);
+                       des_encrypt(&data[0],key,1);
+                       des_encrypt(&data[0],key,1);
+                       des_encrypt(&data[0],key,1);
+                       GetTSC(e2);
+                       des_encrypt(&data[0],key,1);
+                       }
+
+               printf("des %d %d (%d)\n",
+                       e1-s1,e2-s2,((e2-s2)-(e1-s1)));
+               }
+       }
+
diff --git a/deps/openssl/openssl/times/x86/md4s.cpp b/deps/openssl/openssl/times/x86/md4s.cpp
new file mode 100644 (file)
index 0000000..c0ec97f
--- /dev/null
@@ -0,0 +1,78 @@
+//
+// gettsc.inl
+//
+// gives access to the Pentium's (secret) cycle counter
+//
+// This software was written by Leonard Janke (janke@unixg.ubc.ca)
+// in 1996-7 and is entered, by him, into the public domain.
+
+#if defined(__WATCOMC__)
+void GetTSC(unsigned long&);
+#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
+#elif defined(__GNUC__)
+inline
+void GetTSC(unsigned long& tsc)
+{
+  asm volatile(".byte 15, 49\n\t"
+              : "=eax" (tsc)
+              :
+              : "%edx", "%eax");
+}
+#elif defined(_MSC_VER)
+inline
+void GetTSC(unsigned long& tsc)
+{
+  unsigned long a;
+  __asm _emit 0fh
+  __asm _emit 31h
+  __asm mov a, eax;
+  tsc=a;
+}
+#endif      
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <openssl/md4.h>
+
+extern "C" {
+void md4_block_x86(MD4_CTX *ctx, unsigned char *buffer,int num);
+}
+
+void main(int argc,char *argv[])
+       {
+       unsigned char buffer[64*256];
+       MD4_CTX ctx;
+       unsigned long s1,s2,e1,e2;
+       unsigned char k[16];
+       unsigned long data[2];
+       unsigned char iv[8];
+       int i,num=0,numm;
+       int j=0;
+
+       if (argc >= 2)
+               num=atoi(argv[1]);
+
+       if (num == 0) num=16;
+       if (num > 250) num=16;
+       numm=num+2;
+       num*=64;
+       numm*=64;
+
+       for (j=0; j<6; j++)
+               {
+               for (i=0; i<10; i++) /**/
+                       {
+                       md4_block_x86(&ctx,buffer,numm);
+                       GetTSC(s1);
+                       md4_block_x86(&ctx,buffer,numm);
+                       GetTSC(e1);
+                       GetTSC(s2);
+                       md4_block_x86(&ctx,buffer,num);
+                       GetTSC(e2);
+                       md4_block_x86(&ctx,buffer,num);
+                       }
+               printf("md4 (%d bytes) %d %d (%.2f)\n",num,
+                       e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2);
+               }
+       }
+
diff --git a/deps/openssl/openssl/times/x86/md5s.cpp b/deps/openssl/openssl/times/x86/md5s.cpp
new file mode 100644 (file)
index 0000000..dd343fd
--- /dev/null
@@ -0,0 +1,78 @@
+//
+// gettsc.inl
+//
+// gives access to the Pentium's (secret) cycle counter
+//
+// This software was written by Leonard Janke (janke@unixg.ubc.ca)
+// in 1996-7 and is entered, by him, into the public domain.
+
+#if defined(__WATCOMC__)
+void GetTSC(unsigned long&);
+#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
+#elif defined(__GNUC__)
+inline
+void GetTSC(unsigned long& tsc)
+{
+  asm volatile(".byte 15, 49\n\t"
+              : "=eax" (tsc)
+              :
+              : "%edx", "%eax");
+}
+#elif defined(_MSC_VER)
+inline
+void GetTSC(unsigned long& tsc)
+{
+  unsigned long a;
+  __asm _emit 0fh
+  __asm _emit 31h
+  __asm mov a, eax;
+  tsc=a;
+}
+#endif      
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <openssl/md5.h>
+
+extern "C" {
+void md5_block_x86(MD5_CTX *ctx, unsigned char *buffer,int num);
+}
+
+void main(int argc,char *argv[])
+       {
+       unsigned char buffer[64*256];
+       MD5_CTX ctx;
+       unsigned long s1,s2,e1,e2;
+       unsigned char k[16];
+       unsigned long data[2];
+       unsigned char iv[8];
+       int i,num=0,numm;
+       int j=0;
+
+       if (argc >= 2)
+               num=atoi(argv[1]);
+
+       if (num == 0) num=16;
+       if (num > 250) num=16;
+       numm=num+2;
+       num*=64;
+       numm*=64;
+
+       for (j=0; j<6; j++)
+               {
+               for (i=0; i<10; i++) /**/
+                       {
+                       md5_block_x86(&ctx,buffer,numm);
+                       GetTSC(s1);
+                       md5_block_x86(&ctx,buffer,numm);
+                       GetTSC(e1);
+                       GetTSC(s2);
+                       md5_block_x86(&ctx,buffer,num);
+                       GetTSC(e2);
+                       md5_block_x86(&ctx,buffer,num);
+                       }
+               printf("md5 (%d bytes) %d %d (%.2f)\n",num,
+                       e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2);
+               }
+       }
+
diff --git a/deps/openssl/openssl/times/x86/rc4s.cpp b/deps/openssl/openssl/times/x86/rc4s.cpp
new file mode 100644 (file)
index 0000000..3814fde
--- /dev/null
@@ -0,0 +1,73 @@
+//
+// gettsc.inl
+//
+// gives access to the Pentium's (secret) cycle counter
+//
+// This software was written by Leonard Janke (janke@unixg.ubc.ca)
+// in 1996-7 and is entered, by him, into the public domain.
+
+#if defined(__WATCOMC__)
+void GetTSC(unsigned long&);
+#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
+#elif defined(__GNUC__)
+inline
+void GetTSC(unsigned long& tsc)
+{
+  asm volatile(".byte 15, 49\n\t"
+              : "=eax" (tsc)
+              :
+              : "%edx", "%eax");
+}
+#elif defined(_MSC_VER)
+inline
+void GetTSC(unsigned long& tsc)
+{
+  unsigned long a;
+  __asm _emit 0fh
+  __asm _emit 31h
+  __asm mov a, eax;
+  tsc=a;
+}
+#endif      
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <openssl/rc4.h>
+
+void main(int argc,char *argv[])
+       {
+       unsigned char buffer[1024];
+       RC4_KEY ctx;
+       unsigned long s1,s2,e1,e2;
+       unsigned char k[16];
+       unsigned long data[2];
+       unsigned char iv[8];
+       int i,num=64,numm;
+       int j=0;
+
+       if (argc >= 2)
+               num=atoi(argv[1]);
+
+       if (num == 0) num=256;
+       if (num > 1024-16) num=1024-16;
+       numm=num+8;
+
+       for (j=0; j<6; j++)
+               {
+               for (i=0; i<10; i++) /**/
+                       {
+                       RC4(&ctx,numm,buffer,buffer);
+                       GetTSC(s1);
+                       RC4(&ctx,numm,buffer,buffer);
+                       GetTSC(e1);
+                       GetTSC(s2);
+                       RC4(&ctx,num,buffer,buffer);
+                       GetTSC(e2);
+                       RC4(&ctx,num,buffer,buffer);
+                       }
+
+               printf("RC4 (%d bytes) %d %d (%d) - 8 bytes\n",num,
+                       e1-s1,e2-s2,(e1-s1)-(e2-s2));
+               }
+       }
+
similarity index 92%
rename from deps/openssl/openssl/crypto/sha/sha1s.cpp
rename to deps/openssl/openssl/times/x86/sha1s.cpp
index af23d1e..3103e18 100644 (file)
@@ -34,7 +34,6 @@ void GetTSC(unsigned long& tsc)
 #include <stdlib.h>
 #include <openssl/sha.h>
 
-#define sha1_block_x86 sha1_block_asm_data_order
 extern "C" {
 void sha1_block_x86(SHA_CTX *ctx, unsigned char *buffer,int num);
 }
@@ -56,10 +55,8 @@ void main(int argc,char *argv[])
        if (num == 0) num=16;
        if (num > 250) num=16;
        numm=num+2;
-#if 0
        num*=64;
        numm*=64;
-#endif
 
        for (j=0; j<6; j++)
                {
@@ -75,7 +72,7 @@ void main(int argc,char *argv[])
                        sha1_block_x86(&ctx,buffer,num);
                        }
 
-               printf("sha1 (%d bytes) %d %d (%.2f)\n",num*64,
+               printf("sha1 (%d bytes) %d %d (%.2f)\n",num,
                        e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2);
                }
        }
index 4ca835c..bb6fb71 100644 (file)
@@ -49,6 +49,7 @@ depend:
 dclean:
        $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
        mv -f Makefile.new $(MAKEFILE)
+       rm -f c_rehash
 
 clean:
        rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
index ba4e394..6a20011 100644 (file)
@@ -16,13 +16,23 @@ if(defined $ENV{OPENSSL}) {
        $ENV{OPENSSL} = $openssl;
 }
 
-$ENV{PATH} .= ":$dir/bin";
+my $pwd;
+eval "require Cwd";
+if (defined(&Cwd::getcwd)) {
+       $pwd=Cwd::getcwd();
+} else {
+       $pwd=`pwd`; chomp($pwd);
+}
+my $path_delim = ($pwd =~ /^[a-z]\:/i) ? ';' : ':'; # DOS/Win32 or Unix delimiter?
+
+$ENV{PATH} = "$prefix/bin" . ($ENV{PATH} ? $path_delim . $ENV{PATH} : ""); # prefix our path
 
 if(! -x $openssl) {
        my $found = 0;
-       foreach (split /:/, $ENV{PATH}) {
+       foreach (split /$path_delim/, $ENV{PATH}) {
                if(-x "$_/$openssl") {
                        $found = 1;
+                       $openssl = "$_/$openssl";
                        last;
                }       
        }
@@ -35,11 +45,16 @@ if(! -x $openssl) {
 if(@ARGV) {
        @dirlist = @ARGV;
 } elsif($ENV{SSL_CERT_DIR}) {
-       @dirlist = split /:/, $ENV{SSL_CERT_DIR};
+       @dirlist = split /$path_delim/, $ENV{SSL_CERT_DIR};
 } else {
        $dirlist[0] = "$dir/certs";
 }
 
+if (-d $dirlist[0]) {
+       chdir $dirlist[0];
+       $openssl="$pwd/$openssl" if (!-x $openssl);
+       chdir $pwd;
+}
 
 foreach (@dirlist) {
        if(-d $_ and -w $_) {
@@ -102,7 +117,7 @@ sub check_file {
 sub link_hash_cert {
                my $fname = $_[0];
                $fname =~ s/'/'\\''/g;
-               my ($hash, $fprint) = `"$openssl" x509 -hash -fingerprint -noout -in '$fname'`;
+               my ($hash, $fprint) = `"$openssl" x509 -hash -fingerprint -noout -in "$fname"`;
                chomp $hash;
                chomp $fprint;
                $fprint =~ s/^.*=//;
@@ -123,7 +138,11 @@ sub link_hash_cert {
                if ($symlink_exists) {
                        symlink $fname, $hash;
                } else {
-                       system ("cp", $fname, $hash);
+                       open IN,"<$fname" or die "can't open $fname for read";
+                       open OUT,">$hash" or die "can't open $hash for write";
+                       print OUT <IN>; # does the job for small text files
+                       close OUT;
+                       close IN;
                }
                $hashlist{$hash} = $fprint;
 }
index 8b6d3f5..bfc4a69 100644 (file)
@@ -16,13 +16,23 @@ if(defined $ENV{OPENSSL}) {
        $ENV{OPENSSL} = $openssl;
 }
 
-$ENV{PATH} .= ":$dir/bin";
+my $pwd;
+eval "require Cwd";
+if (defined(&Cwd::getcwd)) {
+       $pwd=Cwd::getcwd();
+} else {
+       $pwd=`pwd`; chomp($pwd);
+}
+my $path_delim = ($pwd =~ /^[a-z]\:/i) ? ';' : ':'; # DOS/Win32 or Unix delimiter?
+
+$ENV{PATH} = "$prefix/bin" . ($ENV{PATH} ? $path_delim . $ENV{PATH} : ""); # prefix our path
 
 if(! -x $openssl) {
        my $found = 0;
-       foreach (split /:/, $ENV{PATH}) {
+       foreach (split /$path_delim/, $ENV{PATH}) {
                if(-x "$_/$openssl") {
                        $found = 1;
+                       $openssl = "$_/$openssl";
                        last;
                }       
        }
@@ -35,11 +45,16 @@ if(! -x $openssl) {
 if(@ARGV) {
        @dirlist = @ARGV;
 } elsif($ENV{SSL_CERT_DIR}) {
-       @dirlist = split /:/, $ENV{SSL_CERT_DIR};
+       @dirlist = split /$path_delim/, $ENV{SSL_CERT_DIR};
 } else {
        $dirlist[0] = "$dir/certs";
 }
 
+if (-d $dirlist[0]) {
+       chdir $dirlist[0];
+       $openssl="$pwd/$openssl" if (!-x $openssl);
+       chdir $pwd;
+}
 
 foreach (@dirlist) {
        if(-d $_ and -w $_) {
@@ -102,7 +117,7 @@ sub check_file {
 sub link_hash_cert {
                my $fname = $_[0];
                $fname =~ s/'/'\\''/g;
-               my ($hash, $fprint) = `"$openssl" x509 -hash -fingerprint -noout -in '$fname'`;
+               my ($hash, $fprint) = `"$openssl" x509 -hash -fingerprint -noout -in "$fname"`;
                chomp $hash;
                chomp $fprint;
                $fprint =~ s/^.*=//;
@@ -123,7 +138,11 @@ sub link_hash_cert {
                if ($symlink_exists) {
                        symlink $fname, $hash;
                } else {
-                       system ("cp", $fname, $hash);
+                       open IN,"<$fname" or die "can't open $fname for read";
+                       open OUT,">$hash" or die "can't open $hash for write";
+                       print OUT <IN>; # does the job for small text files
+                       close OUT;
+                       close IN;
                }
                $hashlist{$hash} = $fprint;
 }
diff --git a/deps/openssl/openssl/util/FreeBSD.sh b/deps/openssl/openssl/util/FreeBSD.sh
new file mode 100755 (executable)
index 0000000..db8edfc
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+perl util/perlpath.pl /usr/bin
+perl util/ssldir.pl /usr/local  
+perl util/mk1mf.pl FreeBSD >Makefile.FreeBSD
+perl Configure FreeBSD
old mode 100644 (file)
new mode 100755 (executable)
similarity index 73%
rename from deps/openssl/openssl/crypto/des/des_lib.c
rename to deps/openssl/openssl/util/add_cr.pl
index d4b3047..c7b62c1
@@ -1,4 +1,68 @@
-/* crypto/des/ecb_enc.c */
+#!/usr/local/bin/perl
+#
+# This adds a copyright message to a souce code file.
+# It also gets the file name correct.
+#
+# perl util/add_cr.pl *.[ch] */*.[ch] */*/*.[ch]
+#
+
+foreach (@ARGV)
+       {
+       &dofile($_);
+       }
+
+sub dofile
+       {
+       local($file)=@_;
+
+       open(IN,"<$file") || die "unable to open $file:$!\n";
+
+       print STDERR "doing $file\n";
+       @in=<IN>;
+
+       return(1) if ($in[0] =~ / NOCW /);
+
+       @out=();
+       open(OUT,">$file.out") || die "unable to open $file.$$:$!\n";
+       push(@out,"/* $file */\n");
+       if (($in[1] !~ /^\/\* Copyright \(C\) [0-9-]+ Eric Young \(eay\@cryptsoft.com\)/))
+               {
+               push(@out,&Copyright);
+               $i=2;
+               @a=grep(/ Copyright \(C\) /,@in);
+               if ($#a >= 0)
+                       {
+                       while (($i <= $#in) && ($in[$i] ne " */\n"))
+                               { $i++; }
+                       $i++ if ($in[$i] eq " */\n");
+
+                       while (($i <= $#in) && ($in[$i] =~ /^\s*$/))
+                               { $i++; }
+
+                       push(@out,"\n");
+                       for ( ; $i <= $#in; $i++)
+                               { push(@out,$in[$i]); }
+                       }
+               else
+                       { push(@out,@in); }
+               }
+       else
+               {
+               shift(@in);
+               push(@out,@in);
+               }
+       print OUT @out;
+       close(IN);
+       close(OUT);
+       rename("$file","$file.orig") || die "unable to rename $file:$!\n";
+       rename("$file.out",$file) || die "unable to rename $file.out:$!\n";
+       }
+
+
+
+sub Copyright
+       {
+       return <<'EOF';
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
  * copied and put under another distribution licence
  * [including the GNU Public Licence.]
  */
-
-#include "des_locl.h"
-#include "des_ver.h"
-#include <openssl/opensslv.h>
-#include <openssl/bio.h>
-
-OPENSSL_GLOBAL const char libdes_version[]="libdes" OPENSSL_VERSION_PTEXT;
-OPENSSL_GLOBAL const char DES_version[]="DES" OPENSSL_VERSION_PTEXT;
-
-const char *DES_options(void)
-       {
-       static int init=1;
-       static char buf[32];
-
-       if (init)
-               {
-               const char *ptr,*unroll,*risc,*size;
-
-#ifdef DES_PTR
-               ptr="ptr";
-#else
-               ptr="idx";
-#endif
-#if defined(DES_RISC1) || defined(DES_RISC2)
-#ifdef DES_RISC1
-               risc="risc1";
-#endif
-#ifdef DES_RISC2
-               risc="risc2";
-#endif
-#else
-               risc="cisc";
-#endif
-#ifdef DES_UNROLL
-               unroll="16";
-#else
-               unroll="4";
-#endif
-               if (sizeof(DES_LONG) != sizeof(long))
-                       size="int";
-               else
-                       size="long";
-               BIO_snprintf(buf,sizeof buf,"des(%s,%s,%s,%s)",ptr,risc,unroll,
-                            size);
-               init=0;
-               }
-       return(buf);
+EOF
        }
-
diff --git a/deps/openssl/openssl/util/bat.sh b/deps/openssl/openssl/util/bat.sh
new file mode 100755 (executable)
index 0000000..4d9a828
--- /dev/null
@@ -0,0 +1,134 @@
+#!/usr/local/bin/perl
+
+$infile="/home/eay/ssl/SSLeay/MINFO";
+
+open(IN,"<$infile") || die "unable to open $infile:$!\n";
+$_=<IN>;
+for (;;)
+       {
+       chop;
+
+       ($key,$val)=/^([^=]+)=(.*)/;
+       if ($key eq "RELATIVE_DIRECTORY")
+               {
+               if ($lib ne "")
+                       {
+                       $uc=$lib;
+                       $uc =~ s/^lib(.*)\.a/$1/;
+                       $uc =~ tr/a-z/A-Z/;
+                       $lib_nam{$uc}=$uc;
+                       $lib_obj{$uc}.=$libobj." ";
+                       }
+               last if ($val eq "FINISHED");
+               $lib="";
+               $libobj="";
+               $dir=$val;
+               }
+
+       if ($key eq "TEST")
+               { $test.=&var_add($dir,$val); }
+
+       if (($key eq "PROGS") || ($key eq "E_OBJ"))
+               { $e_exe.=&var_add($dir,$val); }
+
+       if ($key eq "LIB")
+               {
+               $lib=$val;
+               $lib =~ s/^.*\/([^\/]+)$/$1/;
+               }
+
+       if ($key eq "EXHEADER")
+               { $exheader.=&var_add($dir,$val); }
+
+       if ($key eq "HEADER")
+               { $header.=&var_add($dir,$val); }
+
+       if ($key eq "LIBSRC")
+               { $libsrc.=&var_add($dir,$val); }
+
+       if (!($_=<IN>))
+               { $_="RELATIVE_DIRECTORY=FINISHED\n"; }
+       }
+close(IN);
+
+@a=split(/\s+/,$libsrc);
+foreach (@a)
+       {
+       print "${_}.c\n";
+       }
+
+sub var_add
+       {
+       local($dir,$val)=@_;
+       local(@a,$_,$ret);
+
+       return("") if $no_engine && $dir =~ /\/engine/;
+       return("") if $no_idea && $dir =~ /\/idea/;
+       return("") if $no_rc2  && $dir =~ /\/rc2/;
+       return("") if $no_rc4  && $dir =~ /\/rc4/;
+       return("") if $no_rsa  && $dir =~ /\/rsa/;
+       return("") if $no_rsa  && $dir =~ /^rsaref/;
+       return("") if $no_dsa  && $dir =~ /\/dsa/;
+       return("") if $no_dh   && $dir =~ /\/dh/;
+       if ($no_des && $dir =~ /\/des/)
+               {
+               if ($val =~ /read_pwd/)
+                       { return("$dir/read_pwd "); }
+               else
+                       { return(""); }
+               }
+       return("") if $no_mdc2 && $dir =~ /\/mdc2/;
+       return("") if $no_sock && $dir =~ /\/proxy/;
+       return("") if $no_bf   && $dir =~ /\/bf/;
+       return("") if $no_cast && $dir =~ /\/cast/;
+
+       $val =~ s/^\s*(.*)\s*$/$1/;
+       @a=split(/\s+/,$val);
+       grep(s/\.[och]$//,@a);
+
+       @a=grep(!/^e_.*_3d$/,@a) if $no_des;
+       @a=grep(!/^e_.*_d$/,@a) if $no_des;
+       @a=grep(!/^e_.*_i$/,@a) if $no_idea;
+       @a=grep(!/^e_.*_r2$/,@a) if $no_rc2;
+       @a=grep(!/^e_.*_bf$/,@a) if $no_bf;
+       @a=grep(!/^e_.*_c$/,@a) if $no_cast;
+       @a=grep(!/^e_rc4$/,@a) if $no_rc4;
+
+       @a=grep(!/(^s2_)|(^s23_)/,@a) if $no_ssl2;
+       @a=grep(!/(^s3_)|(^s23_)/,@a) if $no_ssl3;
+
+       @a=grep(!/(_sock$)|(_acpt$)|(_conn$)|(^pxy_)/,@a) if $no_sock;
+
+       @a=grep(!/(^md2)|(_md2$)/,@a) if $no_md2;
+       @a=grep(!/(^md5)|(_md5$)/,@a) if $no_md5;
+
+       @a=grep(!/(^d2i_r_)|(^i2d_r_)/,@a) if $no_rsa;
+       @a=grep(!/(^p_open$)|(^p_seal$)/,@a) if $no_rsa;
+       @a=grep(!/(^pem_seal$)/,@a) if $no_rsa;
+
+       @a=grep(!/(m_dss$)|(m_dss1$)/,@a) if $no_dsa;
+       @a=grep(!/(^d2i_s_)|(^i2d_s_)|(_dsap$)/,@a) if $no_dsa;
+
+       @a=grep(!/^n_pkey$/,@a) if $no_rsa || $no_rc4;
+
+       @a=grep(!/_dhp$/,@a) if $no_dh;
+
+       @a=grep(!/(^sha[^1])|(_sha$)|(m_dss$)/,@a) if $no_sha;
+       @a=grep(!/(^sha1)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
+       @a=grep(!/_mdc2$/,@a) if $no_mdc2;
+
+       @a=grep(!/^engine$/,@a) if $no_engine;
+       @a=grep(!/(^rsa$)|(^genrsa$)|(^req$)|(^ca$)/,@a) if $no_rsa;
+       @a=grep(!/(^dsa$)|(^gendsa$)|(^dsaparam$)/,@a) if $no_dsa;
+       @a=grep(!/^gendsa$/,@a) if $no_sha1;
+       @a=grep(!/(^dh$)|(^gendh$)/,@a) if $no_dh;
+
+       @a=grep(!/(^dh)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
+
+       grep($_="$dir/$_",@a);
+       @a=grep(!/(^|\/)s_/,@a) if $no_sock;
+       @a=grep(!/(^|\/)bio_sock/,@a) if $no_sock;
+       $ret=join(' ',@a)." ";
+       return($ret);
+       }
+
diff --git a/deps/openssl/openssl/util/ck_errf.pl b/deps/openssl/openssl/util/ck_errf.pl
new file mode 100755 (executable)
index 0000000..f13af5c
--- /dev/null
@@ -0,0 +1,64 @@
+#!/usr/local/bin/perl
+#
+# This is just a quick script to scan for cases where the 'error'
+# function name in a XXXerr() macro is wrong.
+# 
+# Run in the top level by going
+# perl util/ck_errf.pl */*.c */*/*.c
+#
+
+my $err_strict = 0;
+my $bad = 0;
+
+foreach $file (@ARGV)
+       {
+       if ($file eq "-strict")
+               {
+               $err_strict = 1;
+               next;
+               }
+       open(IN,"<$file") || die "unable to open $file\n";
+       $func="";
+       while (<IN>)
+               {
+               if (!/;$/ && /^([a-zA-Z].*[\s*])?([A-Za-z_0-9]+)\(.*[),]/)
+                       {
+                       /^([^()]*(\([^()]*\)[^()]*)*)\(/;
+                       $1 =~ /([A-Za-z_0-9]*)$/;
+                       $func = $1;
+                       $func =~ tr/A-Z/a-z/;
+                       }
+               if (/([A-Z0-9]+)err\(([^,]+)/ && ! /ckerr_ignore/)
+                       {
+                       $errlib=$1;
+                       $n=$2;
+
+                       if ($func eq "")
+                               { print "$file:$.:???:$n\n"; $bad = 1; next; }
+
+                       if ($n !~ /([^_]+)_F_(.+)$/)
+                               {
+               #               print "check -$file:$.:$func:$n\n";
+                               next;
+                               }
+                       $lib=$1;
+                       $n=$2;
+
+                       if ($lib ne $errlib)
+                               { print "$file:$.:$func:$n [${errlib}err]\n"; $bad = 1; next; }
+
+                       $n =~ tr/A-Z/a-z/;
+                       if (($n ne $func) && ($errlib ne "SYS"))
+                               { print "$file:$.:$func:$n\n"; $bad = 1; next; }
+       #               print "$func:$1\n";
+                       }
+               }
+       close(IN);
+        }
+
+if ($bad && $err_strict)
+       {
+       print STDERR "FATAL: error discrepancy\n";
+       exit 1;
+       }
+
diff --git a/deps/openssl/openssl/util/clean-depend.pl b/deps/openssl/openssl/util/clean-depend.pl
new file mode 100755 (executable)
index 0000000..d3525b0
--- /dev/null
@@ -0,0 +1,58 @@
+#!/usr/local/bin/perl -w
+# Clean the dependency list in a makefile of standard includes...
+# Written by Ben Laurie <ben@algroup.co.uk> 19 Jan 1999
+
+use strict;
+
+while(<STDIN>) {
+    print;
+    last if /^# DO NOT DELETE THIS LINE/;
+}
+
+my %files;
+
+my $thisfile="";
+while(<STDIN>) {
+    my ($dummy, $file,$deps)=/^((.*):)? (.*)$/;
+    my $origfile="";
+    $thisfile=$file if defined $file;
+    next if !defined $deps;
+    $origfile=$thisfile;
+    $origfile=~s/\.o$/.c/;
+    my @deps=split ' ',$deps;
+    @deps=grep(!/^\//,@deps);
+    @deps=grep(!/^\\$/,@deps);
+    @deps=grep(!/^$origfile$/,@deps);
+# pull out the kludged kerberos header (if present).
+    @deps=grep(!/^[.\/]+\/krb5.h/,@deps);
+    push @{$files{$thisfile}},@deps;
+}
+
+my $file;
+foreach $file (sort keys %files) {
+    my $len=0;
+    my $dep;
+    my $origfile=$file;
+    $origfile=~s/\.o$/.c/;
+    $file=~s/^\.\///;
+    push @{$files{$file}},$origfile;
+    my $prevdep="";
+
+    # Remove leading ./ before sorting
+    my @deps = map { $_ =~ s/^\.\///; $_ } @{$files{$file}};
+
+    foreach $dep (sort @deps) {
+       $dep=~s/^\.\///;
+       next if $prevdep eq $dep; # to exterminate duplicates...
+       $prevdep = $dep;
+       $len=0 if $len+length($dep)+1 >= 80;
+       if($len == 0) {
+           print "\n$file:";
+           $len=length($file)+1;
+       }
+       print " $dep";
+       $len+=length($dep)+1;
+    }
+}
+
+print "\n";
diff --git a/deps/openssl/openssl/util/copy.pl b/deps/openssl/openssl/util/copy.pl
new file mode 100644 (file)
index 0000000..e20b455
--- /dev/null
@@ -0,0 +1,59 @@
+#!/usr/local/bin/perl
+
+use Fcntl;
+
+
+# copy.pl
+
+# Perl script 'copy' comment. On Windows the built in "copy" command also
+# copies timestamps: this messes up Makefile dependencies.
+
+my $arg;
+
+foreach $arg (@ARGV) {
+       $arg =~ s|\\|/|g;       # compensate for bug/feature in cygwin glob...
+       foreach (glob $arg)
+               {
+               push @filelist, $_;
+               }
+}
+
+$fnum = @filelist;
+
+if ($fnum <= 1)
+       {
+       die "Need at least two filenames";
+       }
+
+$dest = pop @filelist;
+       
+if ($fnum > 2 && ! -d $dest)
+       {
+       die "Destination must be a directory";
+       }
+
+foreach (@filelist)
+       {
+       if (-d $dest)
+               {
+               $dfile = $_;
+               $dfile =~ s|^.*[/\\]([^/\\]*)$|$1|;
+               $dfile = "$dest/$dfile";
+               }
+       else
+               {
+               $dfile = $dest;
+               }
+       sysopen(IN, $_, O_RDONLY|O_BINARY) || die "Can't Open $_";
+       sysopen(OUT, $dfile, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY)
+                                       || die "Can't Open $dfile";
+       while (sysread IN, $buf, 10240)
+               {
+               syswrite(OUT, $buf, length($buf));
+               }
+       close(IN);
+       close(OUT);
+       print "Copying: $_ to $dfile\n";
+       }
+               
+
diff --git a/deps/openssl/openssl/util/cygwin.sh b/deps/openssl/openssl/util/cygwin.sh
new file mode 100755 (executable)
index 0000000..d622852
--- /dev/null
@@ -0,0 +1,146 @@
+#!/bin/bash
+#
+# This script configures, builds and packs the binary package for
+# the Cygwin net distribution version of OpenSSL
+#
+
+# Uncomment when debugging
+#set -x
+
+CONFIG_OPTIONS="--prefix=/usr shared zlib no-idea no-rc5"
+INSTALL_PREFIX=/tmp/install/INSTALL
+
+VERSION=
+SUBVERSION=$1
+
+function cleanup()
+{
+  rm -rf ${INSTALL_PREFIX}/etc
+  rm -rf ${INSTALL_PREFIX}/usr
+}
+
+function get_openssl_version()
+{
+  eval `grep '^VERSION=' Makefile`
+  if [ -z "${VERSION}" ]
+  then
+    echo "Error: Couldn't retrieve OpenSSL version from Makefile."
+    echo "       Check value of variable VERSION in Makefile."
+    exit 1
+  fi
+}
+
+function base_install()
+{
+  mkdir -p ${INSTALL_PREFIX}
+  cleanup
+  make install INSTALL_PREFIX="${INSTALL_PREFIX}"
+}
+
+function doc_install()
+{
+  DOC_DIR=${INSTALL_PREFIX}/usr/share/doc/openssl
+
+  mkdir -p ${DOC_DIR}
+  cp CHANGES CHANGES.SSLeay INSTALL LICENSE NEWS README ${DOC_DIR}
+
+  create_cygwin_readme
+}
+
+function certs_install()
+{
+  CERTS_DIR=${INSTALL_PREFIX}/usr/ssl/certs
+
+  mkdir -p ${CERTS_DIR}
+  cp -rp certs/* ${CERTS_DIR}
+}
+
+function create_cygwin_readme()
+{
+  README_DIR=${INSTALL_PREFIX}/usr/share/doc/Cygwin
+  README_FILE=${README_DIR}/openssl-${VERSION}.README
+
+  mkdir -p ${README_DIR}
+  cat > ${README_FILE} <<- EOF
+       The Cygwin version has been built using the following configure:
+
+         ./config ${CONFIG_OPTIONS}
+
+       The IDEA and RC5 algorithms are disabled due to patent and/or
+       licensing issues.
+       EOF
+}
+
+function create_profile_files()
+{
+  PROFILE_DIR=${INSTALL_PREFIX}/etc/profile.d
+
+  mkdir -p $PROFILE_DIR
+  cat > ${PROFILE_DIR}/openssl.sh <<- "EOF"
+       export MANPATH="${MANPATH}:/usr/ssl/man"
+       EOF
+  cat > ${PROFILE_DIR}/openssl.csh <<- "EOF"
+       if ( $?MANPATH ) then
+         setenv MANPATH "${MANPATH}:/usr/ssl/man"
+       else
+         setenv MANPATH ":/usr/ssl/man"
+       endif
+       EOF
+}
+
+if [ -z "${SUBVERSION}" ]
+then
+  echo "Usage: $0 subversion"
+  exit 1
+fi
+
+if [ ! -f config ]
+then
+  echo "You must start this script in the OpenSSL toplevel source dir."
+  exit 1
+fi
+
+./config ${CONFIG_OPTIONS}
+
+get_openssl_version
+
+make depend || exit 1
+
+make || exit 1
+
+base_install
+
+doc_install
+
+certs_install
+
+create_cygwin_readme
+
+create_profile_files
+
+cd ${INSTALL_PREFIX}
+chmod u+w usr/lib/engines/*.so
+strip usr/bin/*.exe usr/bin/*.dll usr/lib/engines/*.so
+chmod u-w usr/lib/engines/*.so
+
+# Runtime package
+tar cjf libopenssl${VERSION//[!0-9]/}-${VERSION}-${SUBVERSION}.tar.bz2 \
+     usr/bin/cyg*dll
+# Base package
+find etc usr/bin/openssl.exe usr/bin/c_rehash usr/lib/engines usr/share/doc \
+     usr/ssl/certs usr/ssl/man/man[157] usr/ssl/misc usr/ssl/openssl.cnf \
+     usr/ssl/private \
+     -empty -o \! -type d |
+tar cjfT openssl-${VERSION}-${SUBVERSION}.tar.bz2 -
+# Development package
+find usr/include usr/lib/*.a usr/lib/pkgconfig usr/ssl/man/man3 \
+     -empty -o \! -type d |
+tar cjfT openssl-devel-${VERSION}-${SUBVERSION}.tar.bz2 -
+
+ls -l openssl-${VERSION}-${SUBVERSION}.tar.bz2
+ls -l openssl-devel-${VERSION}-${SUBVERSION}.tar.bz2
+ls -l libopenssl${VERSION//[!0-9]/}-${VERSION}-${SUBVERSION}.tar.bz2
+
+cleanup
+
+exit 0
diff --git a/deps/openssl/openssl/util/deleof.pl b/deps/openssl/openssl/util/deleof.pl
new file mode 100755 (executable)
index 0000000..155acd8
--- /dev/null
@@ -0,0 +1,7 @@
+#!/usr/local/bin/perl
+
+while (<>)
+       {
+       print
+       last if (/^# DO NOT DELETE THIS LINE/);
+       }
diff --git a/deps/openssl/openssl/util/deltree.com b/deps/openssl/openssl/util/deltree.com
new file mode 100644 (file)
index 0000000..9f36b1a
--- /dev/null
@@ -0,0 +1,34 @@
+$! DELTREE.COM
+$
+$ call deltree 'p1'
+$ exit $status
+$
+$ deltree: subroutine ! P1 is a name of a directory
+$      on control_y then goto dt_STOP
+$      on warning then goto dt_exit
+$      _dt_def = f$trnlnm("SYS$DISK")+f$directory()
+$      if f$parse(p1) .eqs. "" then exit
+$      set default 'f$parse(p1,,,"DEVICE")''f$parse(p1,,,"DIRECTORY")'
+$      p1 = f$parse(p1,,,"NAME") + f$parse(p1,,,"TYPE")
+$      _fp = f$parse(".DIR",p1)
+$ dt_loop:
+$      _f = f$search(_fp)
+$      if _f .eqs. "" then goto dt_loopend
+$      call deltree [.'f$parse(_f,,,"NAME")']*.*
+$      goto dt_loop
+$ dt_loopend:
+$      _fp = f$parse(p1,".;*")
+$      if f$search(_fp) .eqs. "" then goto dt_exit
+$      set noon
+$      set file/prot=(S:RWED,O:RWED,G:RWED,W:RWED) '_fp'
+$      set on
+$      delete/nolog '_fp'
+$ dt_exit:
+$      set default '_dt_def'
+$      goto dt_end
+$ dt_STOP:
+$      set default '_dt_def'
+$      stop/id=""
+$      exit
+$ dt_end:
+$      endsubroutine
diff --git a/deps/openssl/openssl/util/dirname.pl b/deps/openssl/openssl/util/dirname.pl
new file mode 100644 (file)
index 0000000..d7a66d9
--- /dev/null
@@ -0,0 +1,18 @@
+#!/usr/local/bin/perl
+
+if ($#ARGV < 0) {
+    die "dirname.pl: too few arguments\n";
+} elsif ($#ARGV > 0) {
+    die "dirname.pl: too many arguments\n";
+}
+
+my $d = $ARGV[0];
+
+if ($d =~ m|.*/.*|) {
+    $d =~ s|/[^/]*$||;
+} else {
+    $d = ".";
+}
+
+print $d,"\n";
+exit(0);
diff --git a/deps/openssl/openssl/util/do_ms.sh b/deps/openssl/openssl/util/do_ms.sh
new file mode 100755 (executable)
index 0000000..515b074
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh
+#
+# generate the Microsoft makefiles and .def files
+#
+
+PATH=util:../util:$PATH
+
+# perl util/mk1mf.pl no-sock VC-MSDOS >ms/msdos.mak
+# perl util/mk1mf.pl VC-W31-32 >ms/w31.mak
+perl util/mk1mf.pl dll VC-WIN16 >ms/w31dll.mak
+# perl util/mk1mf.pl VC-WIN32 >ms/nt.mak
+perl util/mk1mf.pl dll VC-WIN32 >ms/ntdll.mak
+perl util/mk1mf.pl Mingw32 >ms/mingw32.mak
+perl util/mk1mf.pl Mingw32-files >ms/mingw32f.mak
+
+perl util/mkdef.pl 16 libeay > ms/libeay16.def
+perl util/mkdef.pl 32 libeay > ms/libeay32.def
+perl util/mkdef.pl 16 ssleay > ms/ssleay16.def
+perl util/mkdef.pl 32 ssleay > ms/ssleay32.def
diff --git a/deps/openssl/openssl/util/domd b/deps/openssl/openssl/util/domd
new file mode 100755 (executable)
index 0000000..bab48cb
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/sh
+# Do a makedepend, only leave out the standard headers
+# Written by Ben Laurie <ben@algroup.co.uk> 19 Jan 1999
+
+TOP=$1
+shift
+if [ "$1" = "-MD" ]; then
+    shift
+    MAKEDEPEND=$1
+    shift
+fi
+if [ "$MAKEDEPEND" = "" ]; then MAKEDEPEND=makedepend; fi
+
+cp Makefile Makefile.save
+# fake the presence of Kerberos
+touch $TOP/krb5.h
+if expr "$MAKEDEPEND" : '.*gcc$' > /dev/null; then
+    args=""
+    while [ $# -gt 0 ]; do
+       if [ "$1" != "--" ]; then args="$args $1"; fi
+       shift
+    done
+    sed -e '/^# DO NOT DELETE.*/,$d' < Makefile > Makefile.tmp
+    echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' >> Makefile.tmp
+    ${MAKEDEPEND} -Werror -D OPENSSL_DOING_MAKEDEPEND -M $args >> Makefile.tmp || exit 1
+    ${PERL} $TOP/util/clean-depend.pl < Makefile.tmp > Makefile.new
+    RC=$?
+    rm -f Makefile.tmp
+else
+    ${MAKEDEPEND} -D OPENSSL_DOING_MAKEDEPEND $@ && \
+    ${PERL} $TOP/util/clean-depend.pl < Makefile > Makefile.new
+    RC=$?
+fi
+mv Makefile.new Makefile
+# unfake the presence of Kerberos
+rm $TOP/krb5.h
+
+exit $RC
diff --git a/deps/openssl/openssl/util/err-ins.pl b/deps/openssl/openssl/util/err-ins.pl
new file mode 100755 (executable)
index 0000000..31b70df
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/local/bin/perl
+#
+# tack error codes onto the end of a file
+#
+
+open(ERR,$ARGV[0]) || die "unable to open error file '$ARGV[0]':$!\n";
+@err=<ERR>;
+close(ERR);
+
+open(IN,$ARGV[1]) || die "unable to open header file '$ARGV[1]':$!\n";
+
+@out="";
+while (<IN>)
+       {
+       push(@out,$_);
+       last if /BEGIN ERROR CODES/;
+       }
+close(IN);
+
+open(OUT,">$ARGV[1]") || die "unable to open header file '$ARGV[1]':$1\n";
+print OUT @out;
+print OUT @err;
+print OUT <<"EOF";
+#ifdef  __cplusplus
+}
+#endif
+#endif
+
+EOF
+close(OUT);
+
+
diff --git a/deps/openssl/openssl/util/extract-names.pl b/deps/openssl/openssl/util/extract-names.pl
new file mode 100644 (file)
index 0000000..35bd6ed
--- /dev/null
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+
+$/ = "";                       # Eat a paragraph at once.
+while(<STDIN>) {
+    chop;
+    s/\n/ /gm;
+    if (/^=head1 /) {
+       $name = 0;
+    } elsif ($name) {
+       if (/ - /) {
+           s/ - .*//;
+           s/,\s+/,/g;
+           s/\s+,/,/g;
+           s/^\s+//g;
+           s/\s+$//g;
+           s/\s/_/g;
+           push @words, split ',';
+       }
+    }
+    if (/^=head1 *NAME *$/) {
+       $name = 1;
+    }
+}
+
+print join("\n", @words),"\n";
+
diff --git a/deps/openssl/openssl/util/extract-section.pl b/deps/openssl/openssl/util/extract-section.pl
new file mode 100644 (file)
index 0000000..7a0ba4f
--- /dev/null
@@ -0,0 +1,12 @@
+#!/usr/bin/perl
+
+while(<STDIN>) {
+       if (/=for\s+comment\s+openssl_manual_section:(\S+)/)
+               {
+               print "$1\n";
+               exit 0;
+               }
+}
+
+print "$ARGV[0]\n";
+
diff --git a/deps/openssl/openssl/util/files.pl b/deps/openssl/openssl/util/files.pl
new file mode 100755 (executable)
index 0000000..41f033e
--- /dev/null
@@ -0,0 +1,61 @@
+#!/usr/local/bin/perl
+#
+# used to generate the file MINFO for use by util/mk1mf.pl
+# It is basically a list of all variables from the passed makefile
+#
+
+$s="";
+while (<>)
+       {
+       chop;
+       s/#.*//;
+       if (/^(\S+)\s*=\s*(.*)$/)
+               {
+               $o="";
+               ($s,$b)=($1,$2);
+               for (;;)
+                       {
+                       if ($b =~ /\\$/)
+                               {
+                               chop($b);
+                               $o.=$b." ";
+                               $b=<>;
+                               chop($b);
+                               }
+                       else
+                               {
+                               $o.=$b." ";
+                               last;
+                               }
+                       }
+               $o =~ s/^\s+//;
+               $o =~ s/\s+$//;
+               $o =~ s/\s+/ /g;
+
+               $o =~ s/\$[({]([^)}]+)[)}]/$sym{$1}/g;
+               $sym{$s}=$o;
+               }
+       }
+
+$pwd=`pwd`; chop($pwd);
+
+if ($sym{'TOP'} eq ".")
+       {
+       $n=0;
+       $dir=".";
+       }
+else   {
+       $n=split(/\//,$sym{'TOP'});
+       @_=split(/\//,$pwd);
+       $z=$#_-$n+1;
+       foreach $i ($z .. $#_) { $dir.=$_[$i]."/"; }
+       chop($dir);
+       }
+
+print "RELATIVE_DIRECTORY=$dir\n";
+
+foreach (sort keys %sym)
+       {
+       print "$_=$sym{$_}\n";
+       }
+print "RELATIVE_DIRECTORY=\n";
diff --git a/deps/openssl/openssl/util/fixNT.sh b/deps/openssl/openssl/util/fixNT.sh
new file mode 100755 (executable)
index 0000000..ab9e766
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/sh
+#
+# clean up the mess that NT makes of my source tree
+#
+
+if [ -f makefile -a ! -f Makefile ]; then
+       /bin/mv makefile Makefile
+fi
+chmod +x Configure util/*
+echo cleaning
+/bin/rm -f `find . -name '*.$$$' -print` 2>/dev/null >/dev/null
+echo 'removing those damn ^M'
+perl -pi -e 's/\015//' `find . -type 'f' -print |grep -v '.obj$' |grep -v '.der$' |grep -v '.gz'`
+make -f Makefile links
diff --git a/deps/openssl/openssl/util/install.sh b/deps/openssl/openssl/util/install.sh
new file mode 100755 (executable)
index 0000000..e1d0c98
--- /dev/null
@@ -0,0 +1,108 @@
+#!/bin/sh
+#
+# install - install a program, script, or datafile
+# This comes from X11R5; it is not part of GNU.
+#
+# $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $
+#
+# This script is compatible with the BSD install script, but was written
+# from scratch.
+#
+
+
+# set DOITPROG to echo to test this script
+
+doit="${DOITPROG:-}"
+
+
+# put in absolute paths if you don't have them in your path; or use env. vars.
+
+mvprog="${MVPROG:-mv}"
+cpprog="${CPPROG:-cp}"
+chmodprog="${CHMODPROG:-chmod}"
+chownprog="${CHOWNPROG:-chown}"
+chgrpprog="${CHGRPPROG:-chgrp}"
+stripprog="${STRIPPROG:-strip}"
+rmprog="${RMPROG:-rm}"
+
+instcmd="$mvprog"
+chmodcmd=""
+chowncmd=""
+chgrpcmd=""
+stripcmd=""
+rmcmd="$rmprog -f"
+src=""
+dst=""
+
+while [ x"$1" != x ]; do
+    case $1 in
+       -c) instcmd="$cpprog"
+           shift
+           continue;;
+
+       -m) chmodcmd="$chmodprog $2"
+           shift
+           shift
+           continue;;
+
+       -o) chowncmd="$chownprog $2"
+           shift
+           shift
+           continue;;
+
+       -g) chgrpcmd="$chgrpprog $2"
+           shift
+           shift
+           continue;;
+
+       -s) stripcmd="$stripprog"
+           shift
+           continue;;
+
+       *)  if [ x"$src" = x ]
+           then
+               src=$1
+           else
+               dst=$1
+           fi
+           shift
+           continue;;
+    esac
+done
+
+if [ x"$src" = x ]
+then
+       echo "install:  no input file specified"
+       exit 1
+fi
+
+if [ x"$dst" = x ]
+then
+       echo "install:  no destination specified"
+       exit 1
+fi
+
+
+# if destination is a directory, append the input filename; if your system
+# does not like double slashes in filenames, you may need to add some logic
+
+if [ -d $dst ]
+then
+       dst="$dst"/`basename $src`
+fi
+
+
+# get rid of the old one and mode the new one in
+
+$doit $rmcmd $dst
+$doit $instcmd $src $dst
+
+
+# and set any options; do chmod last to preserve setuid bits
+
+if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; fi
+if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; fi
+if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; fi
+if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; fi
+
+exit 0
diff --git a/deps/openssl/openssl/util/libeay.num b/deps/openssl/openssl/util/libeay.num
new file mode 100755 (executable)
index 0000000..b23619f
--- /dev/null
@@ -0,0 +1,4196 @@
+SSLeay                                  1      EXIST::FUNCTION:
+SSLeay_version                          2      EXIST::FUNCTION:
+ASN1_BIT_STRING_asn1_meth               3      NOEXIST::FUNCTION:
+ASN1_HEADER_free                        4      NOEXIST::FUNCTION:
+ASN1_HEADER_new                         5      NOEXIST::FUNCTION:
+ASN1_IA5STRING_asn1_meth                6      NOEXIST::FUNCTION:
+ASN1_INTEGER_get                        7      EXIST::FUNCTION:
+ASN1_INTEGER_set                        8      EXIST::FUNCTION:
+ASN1_INTEGER_to_BN                      9      EXIST::FUNCTION:
+ASN1_OBJECT_create                      10     EXIST::FUNCTION:
+ASN1_OBJECT_free                        11     EXIST::FUNCTION:
+ASN1_OBJECT_new                         12     EXIST::FUNCTION:
+ASN1_PRINTABLE_type                     13     EXIST::FUNCTION:
+ASN1_STRING_cmp                         14     EXIST::FUNCTION:
+ASN1_STRING_dup                         15     EXIST::FUNCTION:
+ASN1_STRING_free                        16     EXIST::FUNCTION:
+ASN1_STRING_new                         17     EXIST::FUNCTION:
+ASN1_STRING_print                       18     EXIST::FUNCTION:BIO
+ASN1_STRING_set                         19     EXIST::FUNCTION:
+ASN1_STRING_type_new                    20     EXIST::FUNCTION:
+ASN1_TYPE_free                          21     EXIST::FUNCTION:
+ASN1_TYPE_new                           22     EXIST::FUNCTION:
+ASN1_UNIVERSALSTRING_to_string          23     EXIST::FUNCTION:
+ASN1_UTCTIME_check                      24     EXIST::FUNCTION:
+ASN1_UTCTIME_print                      25     EXIST::FUNCTION:BIO
+ASN1_UTCTIME_set                        26     EXIST::FUNCTION:
+ASN1_check_infinite_end                 27     EXIST::FUNCTION:
+ASN1_d2i_bio                            28     EXIST::FUNCTION:BIO
+ASN1_d2i_fp                             29     EXIST::FUNCTION:FP_API
+ASN1_digest                             30     EXIST::FUNCTION:EVP
+ASN1_dup                                31     EXIST::FUNCTION:
+ASN1_get_object                         32     EXIST::FUNCTION:
+ASN1_i2d_bio                            33     EXIST::FUNCTION:BIO
+ASN1_i2d_fp                             34     EXIST::FUNCTION:FP_API
+ASN1_object_size                        35     EXIST::FUNCTION:
+ASN1_parse                              36     EXIST::FUNCTION:BIO
+ASN1_put_object                         37     EXIST::FUNCTION:
+ASN1_sign                               38     EXIST::FUNCTION:EVP
+ASN1_verify                             39     EXIST::FUNCTION:EVP
+BF_cbc_encrypt                          40     EXIST::FUNCTION:BF
+BF_cfb64_encrypt                        41     EXIST::FUNCTION:BF
+BF_ecb_encrypt                          42     EXIST::FUNCTION:BF
+BF_encrypt                              43     EXIST::FUNCTION:BF
+BF_ofb64_encrypt                        44     EXIST::FUNCTION:BF
+BF_options                              45     EXIST::FUNCTION:BF
+BF_set_key                              46     EXIST::FUNCTION:BF
+BIO_CONNECT_free                        47     NOEXIST::FUNCTION:
+BIO_CONNECT_new                         48     NOEXIST::FUNCTION:
+BIO_accept                              51     EXIST::FUNCTION:
+BIO_ctrl                                52     EXIST::FUNCTION:
+BIO_int_ctrl                            53     EXIST::FUNCTION:
+BIO_debug_callback                      54     EXIST::FUNCTION:
+BIO_dump                                55     EXIST::FUNCTION:
+BIO_dup_chain                           56     EXIST::FUNCTION:
+BIO_f_base64                            57     EXIST::FUNCTION:BIO
+BIO_f_buffer                            58     EXIST::FUNCTION:
+BIO_f_cipher                            59     EXIST::FUNCTION:BIO
+BIO_f_md                                60     EXIST::FUNCTION:BIO
+BIO_f_null                              61     EXIST::FUNCTION:
+BIO_f_proxy_server                      62     NOEXIST::FUNCTION:
+BIO_fd_non_fatal_error                  63     EXIST::FUNCTION:
+BIO_fd_should_retry                     64     EXIST::FUNCTION:
+BIO_find_type                           65     EXIST::FUNCTION:
+BIO_free                                66     EXIST::FUNCTION:
+BIO_free_all                            67     EXIST::FUNCTION:
+BIO_get_accept_socket                   69     EXIST::FUNCTION:
+BIO_get_filter_bio                      70     NOEXIST::FUNCTION:
+BIO_get_host_ip                         71     EXIST::FUNCTION:
+BIO_get_port                            72     EXIST::FUNCTION:
+BIO_get_retry_BIO                       73     EXIST::FUNCTION:
+BIO_get_retry_reason                    74     EXIST::FUNCTION:
+BIO_gethostbyname                       75     EXIST::FUNCTION:
+BIO_gets                                76     EXIST::FUNCTION:
+BIO_new                                 78     EXIST::FUNCTION:
+BIO_new_accept                          79     EXIST::FUNCTION:
+BIO_new_connect                         80     EXIST::FUNCTION:
+BIO_new_fd                              81     EXIST::FUNCTION:
+BIO_new_file                            82     EXIST::FUNCTION:FP_API
+BIO_new_fp                              83     EXIST::FUNCTION:FP_API
+BIO_new_socket                          84     EXIST::FUNCTION:
+BIO_pop                                 85     EXIST::FUNCTION:
+BIO_printf                              86     EXIST::FUNCTION:
+BIO_push                                87     EXIST::FUNCTION:
+BIO_puts                                88     EXIST::FUNCTION:
+BIO_read                                89     EXIST::FUNCTION:
+BIO_s_accept                            90     EXIST::FUNCTION:
+BIO_s_connect                           91     EXIST::FUNCTION:
+BIO_s_fd                                92     EXIST::FUNCTION:
+BIO_s_file                              93     EXIST::FUNCTION:FP_API
+BIO_s_mem                               95     EXIST::FUNCTION:
+BIO_s_null                              96     EXIST::FUNCTION:
+BIO_s_proxy_client                      97     NOEXIST::FUNCTION:
+BIO_s_socket                            98     EXIST::FUNCTION:
+BIO_set                                 100    EXIST::FUNCTION:
+BIO_set_cipher                          101    EXIST::FUNCTION:BIO
+BIO_set_tcp_ndelay                      102    EXIST::FUNCTION:
+BIO_sock_cleanup                        103    EXIST::FUNCTION:
+BIO_sock_error                          104    EXIST::FUNCTION:
+BIO_sock_init                           105    EXIST::FUNCTION:
+BIO_sock_non_fatal_error                106    EXIST::FUNCTION:
+BIO_sock_should_retry                   107    EXIST::FUNCTION:
+BIO_socket_ioctl                        108    EXIST::FUNCTION:
+BIO_write                               109    EXIST::FUNCTION:
+BN_CTX_free                             110    EXIST::FUNCTION:
+BN_CTX_new                              111    EXIST::FUNCTION:
+BN_MONT_CTX_free                        112    EXIST::FUNCTION:
+BN_MONT_CTX_new                         113    EXIST::FUNCTION:
+BN_MONT_CTX_set                         114    EXIST::FUNCTION:
+BN_add                                  115    EXIST::FUNCTION:
+BN_add_word                             116    EXIST::FUNCTION:
+BN_hex2bn                               117    EXIST::FUNCTION:
+BN_bin2bn                               118    EXIST::FUNCTION:
+BN_bn2hex                               119    EXIST::FUNCTION:
+BN_bn2bin                               120    EXIST::FUNCTION:
+BN_clear                                121    EXIST::FUNCTION:
+BN_clear_bit                            122    EXIST::FUNCTION:
+BN_clear_free                           123    EXIST::FUNCTION:
+BN_cmp                                  124    EXIST::FUNCTION:
+BN_copy                                 125    EXIST::FUNCTION:
+BN_div                                  126    EXIST::FUNCTION:
+BN_div_word                             127    EXIST::FUNCTION:
+BN_dup                                  128    EXIST::FUNCTION:
+BN_free                                 129    EXIST::FUNCTION:
+BN_from_montgomery                      130    EXIST::FUNCTION:
+BN_gcd                                  131    EXIST::FUNCTION:
+BN_generate_prime                       132    EXIST::FUNCTION:DEPRECATED
+BN_get_word                             133    EXIST::FUNCTION:
+BN_is_bit_set                           134    EXIST::FUNCTION:
+BN_is_prime                             135    EXIST::FUNCTION:DEPRECATED
+BN_lshift                               136    EXIST::FUNCTION:
+BN_lshift1                              137    EXIST::FUNCTION:
+BN_mask_bits                            138    EXIST::FUNCTION:
+BN_mod                                  139    NOEXIST::FUNCTION:
+BN_mod_exp                              140    EXIST::FUNCTION:
+BN_mod_exp_mont                         141    EXIST::FUNCTION:
+BN_mod_exp_simple                       143    EXIST::FUNCTION:
+BN_mod_inverse                          144    EXIST::FUNCTION:
+BN_mod_mul                              145    EXIST::FUNCTION:
+BN_mod_mul_montgomery                   146    EXIST::FUNCTION:
+BN_mod_word                             148    EXIST::FUNCTION:
+BN_mul                                  149    EXIST::FUNCTION:
+BN_new                                  150    EXIST::FUNCTION:
+BN_num_bits                             151    EXIST::FUNCTION:
+BN_num_bits_word                        152    EXIST::FUNCTION:
+BN_options                              153    EXIST::FUNCTION:
+BN_print                                154    EXIST::FUNCTION:
+BN_print_fp                             155    EXIST::FUNCTION:FP_API
+BN_rand                                 156    EXIST::FUNCTION:
+BN_reciprocal                           157    EXIST::FUNCTION:
+BN_rshift                               158    EXIST::FUNCTION:
+BN_rshift1                              159    EXIST::FUNCTION:
+BN_set_bit                              160    EXIST::FUNCTION:
+BN_set_word                             161    EXIST::FUNCTION:
+BN_sqr                                  162    EXIST::FUNCTION:
+BN_sub                                  163    EXIST::FUNCTION:
+BN_to_ASN1_INTEGER                      164    EXIST::FUNCTION:
+BN_ucmp                                 165    EXIST::FUNCTION:
+BN_value_one                            166    EXIST::FUNCTION:
+BUF_MEM_free                            167    EXIST::FUNCTION:
+BUF_MEM_grow                            168    EXIST::FUNCTION:
+BUF_MEM_new                             169    EXIST::FUNCTION:
+BUF_strdup                              170    EXIST::FUNCTION:
+CONF_free                               171    EXIST::FUNCTION:
+CONF_get_number                         172    EXIST::FUNCTION:
+CONF_get_section                        173    EXIST::FUNCTION:
+CONF_get_string                         174    EXIST::FUNCTION:
+CONF_load                               175    EXIST::FUNCTION:
+CRYPTO_add_lock                         176    EXIST::FUNCTION:
+CRYPTO_dbg_free                         177    EXIST::FUNCTION:
+CRYPTO_dbg_malloc                       178    EXIST::FUNCTION:
+CRYPTO_dbg_realloc                      179    EXIST::FUNCTION:
+CRYPTO_dbg_remalloc                     180    NOEXIST::FUNCTION:
+CRYPTO_free                             181    EXIST::FUNCTION:
+CRYPTO_get_add_lock_callback            182    EXIST::FUNCTION:
+CRYPTO_get_id_callback                  183    EXIST::FUNCTION:DEPRECATED
+CRYPTO_get_lock_name                    184    EXIST::FUNCTION:
+CRYPTO_get_locking_callback             185    EXIST::FUNCTION:
+CRYPTO_get_mem_functions                186    EXIST::FUNCTION:
+CRYPTO_lock                             187    EXIST::FUNCTION:
+CRYPTO_malloc                           188    EXIST::FUNCTION:
+CRYPTO_mem_ctrl                         189    EXIST::FUNCTION:
+CRYPTO_mem_leaks                        190    EXIST::FUNCTION:
+CRYPTO_mem_leaks_cb                     191    EXIST::FUNCTION:
+CRYPTO_mem_leaks_fp                     192    EXIST::FUNCTION:FP_API
+CRYPTO_realloc                          193    EXIST::FUNCTION:
+CRYPTO_remalloc                         194    EXIST::FUNCTION:
+CRYPTO_set_add_lock_callback            195    EXIST::FUNCTION:
+CRYPTO_set_id_callback                  196    EXIST::FUNCTION:DEPRECATED
+CRYPTO_set_locking_callback             197    EXIST::FUNCTION:
+CRYPTO_set_mem_functions                198    EXIST::FUNCTION:
+CRYPTO_thread_id                        199    EXIST::FUNCTION:DEPRECATED
+DH_check                                200    EXIST::FUNCTION:DH
+DH_compute_key                          201    EXIST::FUNCTION:DH
+DH_free                                 202    EXIST::FUNCTION:DH
+DH_generate_key                         203    EXIST::FUNCTION:DH
+DH_generate_parameters                  204    EXIST::FUNCTION:DEPRECATED,DH
+DH_new                                  205    EXIST::FUNCTION:DH
+DH_size                                 206    EXIST::FUNCTION:DH
+DHparams_print                          207    EXIST::FUNCTION:BIO,DH
+DHparams_print_fp                       208    EXIST::FUNCTION:DH,FP_API
+DSA_free                                209    EXIST::FUNCTION:DSA
+DSA_generate_key                        210    EXIST::FUNCTION:DSA
+DSA_generate_parameters                 211    EXIST::FUNCTION:DEPRECATED,DSA
+DSA_is_prime                            212    NOEXIST::FUNCTION:
+DSA_new                                 213    EXIST::FUNCTION:DSA
+DSA_print                               214    EXIST::FUNCTION:BIO,DSA
+DSA_print_fp                            215    EXIST::FUNCTION:DSA,FP_API
+DSA_sign                                216    EXIST::FUNCTION:DSA
+DSA_sign_setup                          217    EXIST::FUNCTION:DSA
+DSA_size                                218    EXIST::FUNCTION:DSA
+DSA_verify                              219    EXIST::FUNCTION:DSA
+DSAparams_print                         220    EXIST::FUNCTION:BIO,DSA
+DSAparams_print_fp                      221    EXIST::FUNCTION:DSA,FP_API
+ERR_clear_error                         222    EXIST::FUNCTION:
+ERR_error_string                        223    EXIST::FUNCTION:
+ERR_free_strings                        224    EXIST::FUNCTION:
+ERR_func_error_string                   225    EXIST::FUNCTION:
+ERR_get_err_state_table                 226    EXIST::FUNCTION:LHASH
+ERR_get_error                           227    EXIST::FUNCTION:
+ERR_get_error_line                      228    EXIST::FUNCTION:
+ERR_get_state                           229    EXIST::FUNCTION:
+ERR_get_string_table                    230    EXIST::FUNCTION:LHASH
+ERR_lib_error_string                    231    EXIST::FUNCTION:
+ERR_load_ASN1_strings                   232    EXIST::FUNCTION:
+ERR_load_BIO_strings                    233    EXIST::FUNCTION:
+ERR_load_BN_strings                     234    EXIST::FUNCTION:
+ERR_load_BUF_strings                    235    EXIST::FUNCTION:
+ERR_load_CONF_strings                   236    EXIST::FUNCTION:
+ERR_load_DH_strings                     237    EXIST::FUNCTION:DH
+ERR_load_DSA_strings                    238    EXIST::FUNCTION:DSA
+ERR_load_ERR_strings                    239    EXIST::FUNCTION:
+ERR_load_EVP_strings                    240    EXIST::FUNCTION:
+ERR_load_OBJ_strings                    241    EXIST::FUNCTION:
+ERR_load_PEM_strings                    242    EXIST::FUNCTION:
+ERR_load_PROXY_strings                  243    NOEXIST::FUNCTION:
+ERR_load_RSA_strings                    244    EXIST::FUNCTION:RSA
+ERR_load_X509_strings                   245    EXIST::FUNCTION:
+ERR_load_crypto_strings                 246    EXIST::FUNCTION:
+ERR_load_strings                        247    EXIST::FUNCTION:
+ERR_peek_error                          248    EXIST::FUNCTION:
+ERR_peek_error_line                     249    EXIST::FUNCTION:
+ERR_print_errors                        250    EXIST::FUNCTION:BIO
+ERR_print_errors_fp                     251    EXIST::FUNCTION:FP_API
+ERR_put_error                           252    EXIST::FUNCTION:
+ERR_reason_error_string                 253    EXIST::FUNCTION:
+ERR_remove_state                        254    EXIST::FUNCTION:DEPRECATED
+EVP_BytesToKey                          255    EXIST::FUNCTION:
+EVP_CIPHER_CTX_cleanup                  256    EXIST::FUNCTION:
+EVP_CipherFinal                         257    EXIST::FUNCTION:
+EVP_CipherInit                          258    EXIST::FUNCTION:
+EVP_CipherUpdate                        259    EXIST::FUNCTION:
+EVP_DecodeBlock                         260    EXIST::FUNCTION:
+EVP_DecodeFinal                         261    EXIST::FUNCTION:
+EVP_DecodeInit                          262    EXIST::FUNCTION:
+EVP_DecodeUpdate                        263    EXIST::FUNCTION:
+EVP_DecryptFinal                        264    EXIST::FUNCTION:
+EVP_DecryptInit                         265    EXIST::FUNCTION:
+EVP_DecryptUpdate                       266    EXIST::FUNCTION:
+EVP_DigestFinal                         267    EXIST::FUNCTION:
+EVP_DigestInit                          268    EXIST::FUNCTION:
+EVP_DigestUpdate                        269    EXIST::FUNCTION:
+EVP_EncodeBlock                         270    EXIST::FUNCTION:
+EVP_EncodeFinal                         271    EXIST::FUNCTION:
+EVP_EncodeInit                          272    EXIST::FUNCTION:
+EVP_EncodeUpdate                        273    EXIST::FUNCTION:
+EVP_EncryptFinal                        274    EXIST::FUNCTION:
+EVP_EncryptInit                         275    EXIST::FUNCTION:
+EVP_EncryptUpdate                       276    EXIST::FUNCTION:
+EVP_OpenFinal                           277    EXIST::FUNCTION:RSA
+EVP_OpenInit                            278    EXIST::FUNCTION:RSA
+EVP_PKEY_assign                         279    EXIST::FUNCTION:
+EVP_PKEY_copy_parameters                280    EXIST::FUNCTION:
+EVP_PKEY_free                           281    EXIST::FUNCTION:
+EVP_PKEY_missing_parameters             282    EXIST::FUNCTION:
+EVP_PKEY_new                            283    EXIST::FUNCTION:
+EVP_PKEY_save_parameters                284    EXIST::FUNCTION:
+EVP_PKEY_size                           285    EXIST::FUNCTION:
+EVP_PKEY_type                           286    EXIST::FUNCTION:
+EVP_SealFinal                           287    EXIST::FUNCTION:RSA
+EVP_SealInit                            288    EXIST::FUNCTION:RSA
+EVP_SignFinal                           289    EXIST::FUNCTION:
+EVP_VerifyFinal                         290    EXIST::FUNCTION:
+EVP_add_alias                           291    NOEXIST::FUNCTION:
+EVP_add_cipher                          292    EXIST::FUNCTION:
+EVP_add_digest                          293    EXIST::FUNCTION:
+EVP_bf_cbc                              294    EXIST::FUNCTION:BF
+EVP_bf_cfb64                            295    EXIST::FUNCTION:BF
+EVP_bf_ecb                              296    EXIST::FUNCTION:BF
+EVP_bf_ofb                              297    EXIST::FUNCTION:BF
+EVP_cleanup                             298    EXIST::FUNCTION:
+EVP_des_cbc                             299    EXIST::FUNCTION:DES
+EVP_des_cfb64                           300    EXIST::FUNCTION:DES
+EVP_des_ecb                             301    EXIST::FUNCTION:DES
+EVP_des_ede                             302    EXIST::FUNCTION:DES
+EVP_des_ede3                            303    EXIST::FUNCTION:DES
+EVP_des_ede3_cbc                        304    EXIST::FUNCTION:DES
+EVP_des_ede3_cfb64                      305    EXIST::FUNCTION:DES
+EVP_des_ede3_ofb                        306    EXIST::FUNCTION:DES
+EVP_des_ede_cbc                         307    EXIST::FUNCTION:DES
+EVP_des_ede_cfb64                       308    EXIST::FUNCTION:DES
+EVP_des_ede_ofb                         309    EXIST::FUNCTION:DES
+EVP_des_ofb                             310    EXIST::FUNCTION:DES
+EVP_desx_cbc                            311    EXIST::FUNCTION:DES
+EVP_dss                                 312    EXIST::FUNCTION:DSA,SHA
+EVP_dss1                                313    EXIST::FUNCTION:DSA,SHA
+EVP_enc_null                            314    EXIST::FUNCTION:
+EVP_get_cipherbyname                    315    EXIST::FUNCTION:
+EVP_get_digestbyname                    316    EXIST::FUNCTION:
+EVP_get_pw_prompt                       317    EXIST::FUNCTION:
+EVP_idea_cbc                            318    EXIST::FUNCTION:IDEA
+EVP_idea_cfb64                          319    EXIST::FUNCTION:IDEA
+EVP_idea_ecb                            320    EXIST::FUNCTION:IDEA
+EVP_idea_ofb                            321    EXIST::FUNCTION:IDEA
+EVP_md2                                 322    EXIST::FUNCTION:MD2
+EVP_md5                                 323    EXIST::FUNCTION:MD5
+EVP_md_null                             324    EXIST::FUNCTION:
+EVP_rc2_cbc                             325    EXIST::FUNCTION:RC2
+EVP_rc2_cfb64                           326    EXIST::FUNCTION:RC2
+EVP_rc2_ecb                             327    EXIST::FUNCTION:RC2
+EVP_rc2_ofb                             328    EXIST::FUNCTION:RC2
+EVP_rc4                                 329    EXIST::FUNCTION:RC4
+EVP_read_pw_string                      330    EXIST::FUNCTION:
+EVP_set_pw_prompt                       331    EXIST::FUNCTION:
+EVP_sha                                 332    EXIST::FUNCTION:SHA
+EVP_sha1                                333    EXIST::FUNCTION:SHA
+MD2                                     334    EXIST::FUNCTION:MD2
+MD2_Final                               335    EXIST::FUNCTION:MD2
+MD2_Init                                336    EXIST::FUNCTION:MD2
+MD2_Update                              337    EXIST::FUNCTION:MD2
+MD2_options                             338    EXIST::FUNCTION:MD2
+MD5                                     339    EXIST::FUNCTION:MD5
+MD5_Final                               340    EXIST::FUNCTION:MD5
+MD5_Init                                341    EXIST::FUNCTION:MD5
+MD5_Update                              342    EXIST::FUNCTION:MD5
+MDC2                                    343    EXIST::FUNCTION:MDC2
+MDC2_Final                              344    EXIST::FUNCTION:MDC2
+MDC2_Init                               345    EXIST::FUNCTION:MDC2
+MDC2_Update                             346    EXIST::FUNCTION:MDC2
+NETSCAPE_SPKAC_free                     347    EXIST::FUNCTION:
+NETSCAPE_SPKAC_new                      348    EXIST::FUNCTION:
+NETSCAPE_SPKI_free                      349    EXIST::FUNCTION:
+NETSCAPE_SPKI_new                       350    EXIST::FUNCTION:
+NETSCAPE_SPKI_sign                      351    EXIST::FUNCTION:EVP
+NETSCAPE_SPKI_verify                    352    EXIST::FUNCTION:EVP
+OBJ_add_object                          353    EXIST::FUNCTION:
+OBJ_bsearch                             354    NOEXIST::FUNCTION:
+OBJ_cleanup                             355    EXIST::FUNCTION:
+OBJ_cmp                                 356    EXIST::FUNCTION:
+OBJ_create                              357    EXIST::FUNCTION:
+OBJ_dup                                 358    EXIST::FUNCTION:
+OBJ_ln2nid                              359    EXIST::FUNCTION:
+OBJ_new_nid                             360    EXIST::FUNCTION:
+OBJ_nid2ln                              361    EXIST::FUNCTION:
+OBJ_nid2obj                             362    EXIST::FUNCTION:
+OBJ_nid2sn                              363    EXIST::FUNCTION:
+OBJ_obj2nid                             364    EXIST::FUNCTION:
+OBJ_sn2nid                              365    EXIST::FUNCTION:
+OBJ_txt2nid                             366    EXIST::FUNCTION:
+PEM_ASN1_read                           367    EXIST::FUNCTION:
+PEM_ASN1_read_bio                       368    EXIST::FUNCTION:BIO
+PEM_ASN1_write                          369    EXIST::FUNCTION:
+PEM_ASN1_write_bio                      370    EXIST::FUNCTION:BIO
+PEM_SealFinal                           371    EXIST::FUNCTION:RSA
+PEM_SealInit                            372    EXIST::FUNCTION:RSA
+PEM_SealUpdate                          373    EXIST::FUNCTION:RSA
+PEM_SignFinal                           374    EXIST::FUNCTION:
+PEM_SignInit                            375    EXIST::FUNCTION:
+PEM_SignUpdate                          376    EXIST::FUNCTION:
+PEM_X509_INFO_read                      377    EXIST::FUNCTION:
+PEM_X509_INFO_read_bio                  378    EXIST::FUNCTION:BIO
+PEM_X509_INFO_write_bio                 379    EXIST::FUNCTION:BIO
+PEM_dek_info                            380    EXIST::FUNCTION:
+PEM_do_header                           381    EXIST::FUNCTION:
+PEM_get_EVP_CIPHER_INFO                 382    EXIST::FUNCTION:
+PEM_proc_type                           383    EXIST::FUNCTION:
+PEM_read                                384    EXIST::FUNCTION:
+PEM_read_DHparams                       385    EXIST:!WIN16:FUNCTION:DH
+PEM_read_DSAPrivateKey                  386    EXIST:!WIN16:FUNCTION:DSA
+PEM_read_DSAparams                      387    EXIST:!WIN16:FUNCTION:DSA
+PEM_read_PKCS7                          388    EXIST:!WIN16:FUNCTION:
+PEM_read_PrivateKey                     389    EXIST:!WIN16:FUNCTION:
+PEM_read_RSAPrivateKey                  390    EXIST:!WIN16:FUNCTION:RSA
+PEM_read_X509                           391    EXIST:!WIN16:FUNCTION:
+PEM_read_X509_CRL                       392    EXIST:!WIN16:FUNCTION:
+PEM_read_X509_REQ                       393    EXIST:!WIN16:FUNCTION:
+PEM_read_bio                            394    EXIST::FUNCTION:BIO
+PEM_read_bio_DHparams                   395    EXIST::FUNCTION:DH
+PEM_read_bio_DSAPrivateKey              396    EXIST::FUNCTION:DSA
+PEM_read_bio_DSAparams                  397    EXIST::FUNCTION:DSA
+PEM_read_bio_PKCS7                      398    EXIST::FUNCTION:
+PEM_read_bio_PrivateKey                 399    EXIST::FUNCTION:
+PEM_read_bio_RSAPrivateKey              400    EXIST::FUNCTION:RSA
+PEM_read_bio_X509                       401    EXIST::FUNCTION:
+PEM_read_bio_X509_CRL                   402    EXIST::FUNCTION:
+PEM_read_bio_X509_REQ                   403    EXIST::FUNCTION:
+PEM_write                               404    EXIST::FUNCTION:
+PEM_write_DHparams                      405    EXIST:!WIN16:FUNCTION:DH
+PEM_write_DSAPrivateKey                 406    EXIST:!WIN16:FUNCTION:DSA
+PEM_write_DSAparams                     407    EXIST:!WIN16:FUNCTION:DSA
+PEM_write_PKCS7                         408    EXIST:!WIN16:FUNCTION:
+PEM_write_PrivateKey                    409    EXIST:!WIN16:FUNCTION:
+PEM_write_RSAPrivateKey                 410    EXIST:!WIN16:FUNCTION:RSA
+PEM_write_X509                          411    EXIST:!WIN16:FUNCTION:
+PEM_write_X509_CRL                      412    EXIST:!WIN16:FUNCTION:
+PEM_write_X509_REQ                      413    EXIST:!WIN16:FUNCTION:
+PEM_write_bio                           414    EXIST::FUNCTION:BIO
+PEM_write_bio_DHparams                  415    EXIST::FUNCTION:DH
+PEM_write_bio_DSAPrivateKey             416    EXIST::FUNCTION:DSA
+PEM_write_bio_DSAparams                 417    EXIST::FUNCTION:DSA
+PEM_write_bio_PKCS7                     418    EXIST::FUNCTION:
+PEM_write_bio_PrivateKey                419    EXIST::FUNCTION:
+PEM_write_bio_RSAPrivateKey             420    EXIST::FUNCTION:RSA
+PEM_write_bio_X509                      421    EXIST::FUNCTION:
+PEM_write_bio_X509_CRL                  422    EXIST::FUNCTION:
+PEM_write_bio_X509_REQ                  423    EXIST::FUNCTION:
+PKCS7_DIGEST_free                       424    EXIST::FUNCTION:
+PKCS7_DIGEST_new                        425    EXIST::FUNCTION:
+PKCS7_ENCRYPT_free                      426    EXIST::FUNCTION:
+PKCS7_ENCRYPT_new                       427    EXIST::FUNCTION:
+PKCS7_ENC_CONTENT_free                  428    EXIST::FUNCTION:
+PKCS7_ENC_CONTENT_new                   429    EXIST::FUNCTION:
+PKCS7_ENVELOPE_free                     430    EXIST::FUNCTION:
+PKCS7_ENVELOPE_new                      431    EXIST::FUNCTION:
+PKCS7_ISSUER_AND_SERIAL_digest          432    EXIST::FUNCTION:
+PKCS7_ISSUER_AND_SERIAL_free            433    EXIST::FUNCTION:
+PKCS7_ISSUER_AND_SERIAL_new             434    EXIST::FUNCTION:
+PKCS7_RECIP_INFO_free                   435    EXIST::FUNCTION:
+PKCS7_RECIP_INFO_new                    436    EXIST::FUNCTION:
+PKCS7_SIGNED_free                       437    EXIST::FUNCTION:
+PKCS7_SIGNED_new                        438    EXIST::FUNCTION:
+PKCS7_SIGNER_INFO_free                  439    EXIST::FUNCTION:
+PKCS7_SIGNER_INFO_new                   440    EXIST::FUNCTION:
+PKCS7_SIGN_ENVELOPE_free                441    EXIST::FUNCTION:
+PKCS7_SIGN_ENVELOPE_new                 442    EXIST::FUNCTION:
+PKCS7_dup                               443    EXIST::FUNCTION:
+PKCS7_free                              444    EXIST::FUNCTION:
+PKCS7_new                               445    EXIST::FUNCTION:
+PROXY_ENTRY_add_noproxy                 446    NOEXIST::FUNCTION:
+PROXY_ENTRY_clear_noproxy               447    NOEXIST::FUNCTION:
+PROXY_ENTRY_free                        448    NOEXIST::FUNCTION:
+PROXY_ENTRY_get_noproxy                 449    NOEXIST::FUNCTION:
+PROXY_ENTRY_new                         450    NOEXIST::FUNCTION:
+PROXY_ENTRY_set_server                  451    NOEXIST::FUNCTION:
+PROXY_add_noproxy                       452    NOEXIST::FUNCTION:
+PROXY_add_server                        453    NOEXIST::FUNCTION:
+PROXY_check_by_host                     454    NOEXIST::FUNCTION:
+PROXY_check_url                         455    NOEXIST::FUNCTION:
+PROXY_clear_noproxy                     456    NOEXIST::FUNCTION:
+PROXY_free                              457    NOEXIST::FUNCTION:
+PROXY_get_noproxy                       458    NOEXIST::FUNCTION:
+PROXY_get_proxies                       459    NOEXIST::FUNCTION:
+PROXY_get_proxy_entry                   460    NOEXIST::FUNCTION:
+PROXY_load_conf                         461    NOEXIST::FUNCTION:
+PROXY_new                               462    NOEXIST::FUNCTION:
+PROXY_print                             463    NOEXIST::FUNCTION:
+RAND_bytes                              464    EXIST::FUNCTION:
+RAND_cleanup                            465    EXIST::FUNCTION:
+RAND_file_name                          466    EXIST::FUNCTION:
+RAND_load_file                          467    EXIST::FUNCTION:
+RAND_screen                             468    EXIST:WIN32:FUNCTION:
+RAND_seed                               469    EXIST::FUNCTION:
+RAND_write_file                         470    EXIST::FUNCTION:
+RC2_cbc_encrypt                         471    EXIST::FUNCTION:RC2
+RC2_cfb64_encrypt                       472    EXIST::FUNCTION:RC2
+RC2_ecb_encrypt                         473    EXIST::FUNCTION:RC2
+RC2_encrypt                             474    EXIST::FUNCTION:RC2
+RC2_ofb64_encrypt                       475    EXIST::FUNCTION:RC2
+RC2_set_key                             476    EXIST::FUNCTION:RC2
+RC4                                     477    EXIST::FUNCTION:RC4
+RC4_options                             478    EXIST::FUNCTION:RC4
+RC4_set_key                             479    EXIST::FUNCTION:RC4
+RSAPrivateKey_asn1_meth                 480    NOEXIST::FUNCTION:
+RSAPrivateKey_dup                       481    EXIST::FUNCTION:RSA
+RSAPublicKey_dup                        482    EXIST::FUNCTION:RSA
+RSA_PKCS1_SSLeay                        483    EXIST::FUNCTION:RSA
+RSA_free                                484    EXIST::FUNCTION:RSA
+RSA_generate_key                        485    EXIST::FUNCTION:DEPRECATED,RSA
+RSA_new                                 486    EXIST::FUNCTION:RSA
+RSA_new_method                          487    EXIST::FUNCTION:RSA
+RSA_print                               488    EXIST::FUNCTION:BIO,RSA
+RSA_print_fp                            489    EXIST::FUNCTION:FP_API,RSA
+RSA_private_decrypt                     490    EXIST::FUNCTION:RSA
+RSA_private_encrypt                     491    EXIST::FUNCTION:RSA
+RSA_public_decrypt                      492    EXIST::FUNCTION:RSA
+RSA_public_encrypt                      493    EXIST::FUNCTION:RSA
+RSA_set_default_method                  494    EXIST::FUNCTION:RSA
+RSA_sign                                495    EXIST::FUNCTION:RSA
+RSA_sign_ASN1_OCTET_STRING              496    EXIST::FUNCTION:RSA
+RSA_size                                497    EXIST::FUNCTION:RSA
+RSA_verify                              498    EXIST::FUNCTION:RSA
+RSA_verify_ASN1_OCTET_STRING            499    EXIST::FUNCTION:RSA
+SHA                                     500    EXIST::FUNCTION:SHA,SHA0
+SHA1                                    501    EXIST::FUNCTION:SHA,SHA1
+SHA1_Final                              502    EXIST::FUNCTION:SHA,SHA1
+SHA1_Init                               503    EXIST::FUNCTION:SHA,SHA1
+SHA1_Update                             504    EXIST::FUNCTION:SHA,SHA1
+SHA_Final                               505    EXIST::FUNCTION:SHA,SHA0
+SHA_Init                                506    EXIST::FUNCTION:SHA,SHA0
+SHA_Update                              507    EXIST::FUNCTION:SHA,SHA0
+OpenSSL_add_all_algorithms              508    NOEXIST::FUNCTION:
+OpenSSL_add_all_ciphers                 509    EXIST::FUNCTION:
+OpenSSL_add_all_digests                 510    EXIST::FUNCTION:
+TXT_DB_create_index                     511    EXIST::FUNCTION:
+TXT_DB_free                             512    EXIST::FUNCTION:
+TXT_DB_get_by_index                     513    EXIST::FUNCTION:
+TXT_DB_insert                           514    EXIST::FUNCTION:
+TXT_DB_read                             515    EXIST::FUNCTION:BIO
+TXT_DB_write                            516    EXIST::FUNCTION:BIO
+X509_ALGOR_free                         517    EXIST::FUNCTION:
+X509_ALGOR_new                          518    EXIST::FUNCTION:
+X509_ATTRIBUTE_free                     519    EXIST::FUNCTION:
+X509_ATTRIBUTE_new                      520    EXIST::FUNCTION:
+X509_CINF_free                          521    EXIST::FUNCTION:
+X509_CINF_new                           522    EXIST::FUNCTION:
+X509_CRL_INFO_free                      523    EXIST::FUNCTION:
+X509_CRL_INFO_new                       524    EXIST::FUNCTION:
+X509_CRL_add_ext                        525    EXIST::FUNCTION:
+X509_CRL_cmp                            526    EXIST::FUNCTION:
+X509_CRL_delete_ext                     527    EXIST::FUNCTION:
+X509_CRL_dup                            528    EXIST::FUNCTION:
+X509_CRL_free                           529    EXIST::FUNCTION:
+X509_CRL_get_ext                        530    EXIST::FUNCTION:
+X509_CRL_get_ext_by_NID                 531    EXIST::FUNCTION:
+X509_CRL_get_ext_by_OBJ                 532    EXIST::FUNCTION:
+X509_CRL_get_ext_by_critical            533    EXIST::FUNCTION:
+X509_CRL_get_ext_count                  534    EXIST::FUNCTION:
+X509_CRL_new                            535    EXIST::FUNCTION:
+X509_CRL_sign                           536    EXIST::FUNCTION:EVP
+X509_CRL_verify                         537    EXIST::FUNCTION:EVP
+X509_EXTENSION_create_by_NID            538    EXIST::FUNCTION:
+X509_EXTENSION_create_by_OBJ            539    EXIST::FUNCTION:
+X509_EXTENSION_dup                      540    EXIST::FUNCTION:
+X509_EXTENSION_free                     541    EXIST::FUNCTION:
+X509_EXTENSION_get_critical             542    EXIST::FUNCTION:
+X509_EXTENSION_get_data                 543    EXIST::FUNCTION:
+X509_EXTENSION_get_object               544    EXIST::FUNCTION:
+X509_EXTENSION_new                      545    EXIST::FUNCTION:
+X509_EXTENSION_set_critical             546    EXIST::FUNCTION:
+X509_EXTENSION_set_data                 547    EXIST::FUNCTION:
+X509_EXTENSION_set_object               548    EXIST::FUNCTION:
+X509_INFO_free                          549    EXIST::FUNCTION:EVP
+X509_INFO_new                           550    EXIST::FUNCTION:EVP
+X509_LOOKUP_by_alias                    551    EXIST::FUNCTION:
+X509_LOOKUP_by_fingerprint              552    EXIST::FUNCTION:
+X509_LOOKUP_by_issuer_serial            553    EXIST::FUNCTION:
+X509_LOOKUP_by_subject                  554    EXIST::FUNCTION:
+X509_LOOKUP_ctrl                        555    EXIST::FUNCTION:
+X509_LOOKUP_file                        556    EXIST::FUNCTION:
+X509_LOOKUP_free                        557    EXIST::FUNCTION:
+X509_LOOKUP_hash_dir                    558    EXIST::FUNCTION:
+X509_LOOKUP_init                        559    EXIST::FUNCTION:
+X509_LOOKUP_new                         560    EXIST::FUNCTION:
+X509_LOOKUP_shutdown                    561    EXIST::FUNCTION:
+X509_NAME_ENTRY_create_by_NID           562    EXIST::FUNCTION:
+X509_NAME_ENTRY_create_by_OBJ           563    EXIST::FUNCTION:
+X509_NAME_ENTRY_dup                     564    EXIST::FUNCTION:
+X509_NAME_ENTRY_free                    565    EXIST::FUNCTION:
+X509_NAME_ENTRY_get_data                566    EXIST::FUNCTION:
+X509_NAME_ENTRY_get_object              567    EXIST::FUNCTION:
+X509_NAME_ENTRY_new                     568    EXIST::FUNCTION:
+X509_NAME_ENTRY_set_data                569    EXIST::FUNCTION:
+X509_NAME_ENTRY_set_object              570    EXIST::FUNCTION:
+X509_NAME_add_entry                     571    EXIST::FUNCTION:
+X509_NAME_cmp                           572    EXIST::FUNCTION:
+X509_NAME_delete_entry                  573    EXIST::FUNCTION:
+X509_NAME_digest                        574    EXIST::FUNCTION:EVP
+X509_NAME_dup                           575    EXIST::FUNCTION:
+X509_NAME_entry_count                   576    EXIST::FUNCTION:
+X509_NAME_free                          577    EXIST::FUNCTION:
+X509_NAME_get_entry                     578    EXIST::FUNCTION:
+X509_NAME_get_index_by_NID              579    EXIST::FUNCTION:
+X509_NAME_get_index_by_OBJ              580    EXIST::FUNCTION:
+X509_NAME_get_text_by_NID               581    EXIST::FUNCTION:
+X509_NAME_get_text_by_OBJ               582    EXIST::FUNCTION:
+X509_NAME_hash                          583    EXIST::FUNCTION:
+X509_NAME_new                           584    EXIST::FUNCTION:
+X509_NAME_oneline                       585    EXIST::FUNCTION:EVP
+X509_NAME_print                         586    EXIST::FUNCTION:BIO
+X509_NAME_set                           587    EXIST::FUNCTION:
+X509_OBJECT_free_contents               588    EXIST::FUNCTION:
+X509_OBJECT_retrieve_by_subject         589    EXIST::FUNCTION:
+X509_OBJECT_up_ref_count                590    EXIST::FUNCTION:
+X509_PKEY_free                          591    EXIST::FUNCTION:
+X509_PKEY_new                           592    EXIST::FUNCTION:
+X509_PUBKEY_free                        593    EXIST::FUNCTION:
+X509_PUBKEY_get                         594    EXIST::FUNCTION:
+X509_PUBKEY_new                         595    EXIST::FUNCTION:
+X509_PUBKEY_set                         596    EXIST::FUNCTION:
+X509_REQ_INFO_free                      597    EXIST::FUNCTION:
+X509_REQ_INFO_new                       598    EXIST::FUNCTION:
+X509_REQ_dup                            599    EXIST::FUNCTION:
+X509_REQ_free                           600    EXIST::FUNCTION:
+X509_REQ_get_pubkey                     601    EXIST::FUNCTION:
+X509_REQ_new                            602    EXIST::FUNCTION:
+X509_REQ_print                          603    EXIST::FUNCTION:BIO
+X509_REQ_print_fp                       604    EXIST::FUNCTION:FP_API
+X509_REQ_set_pubkey                     605    EXIST::FUNCTION:
+X509_REQ_set_subject_name               606    EXIST::FUNCTION:
+X509_REQ_set_version                    607    EXIST::FUNCTION:
+X509_REQ_sign                           608    EXIST::FUNCTION:EVP
+X509_REQ_to_X509                        609    EXIST::FUNCTION:
+X509_REQ_verify                         610    EXIST::FUNCTION:EVP
+X509_REVOKED_add_ext                    611    EXIST::FUNCTION:
+X509_REVOKED_delete_ext                 612    EXIST::FUNCTION:
+X509_REVOKED_free                       613    EXIST::FUNCTION:
+X509_REVOKED_get_ext                    614    EXIST::FUNCTION:
+X509_REVOKED_get_ext_by_NID             615    EXIST::FUNCTION:
+X509_REVOKED_get_ext_by_OBJ             616    EXIST::FUNCTION:
+X509_REVOKED_get_ext_by_critical        617    EXIST:!VMS:FUNCTION:
+X509_REVOKED_get_ext_by_critic          617    EXIST:VMS:FUNCTION:
+X509_REVOKED_get_ext_count              618    EXIST::FUNCTION:
+X509_REVOKED_new                        619    EXIST::FUNCTION:
+X509_SIG_free                           620    EXIST::FUNCTION:
+X509_SIG_new                            621    EXIST::FUNCTION:
+X509_STORE_CTX_cleanup                  622    EXIST::FUNCTION:
+X509_STORE_CTX_init                     623    EXIST::FUNCTION:
+X509_STORE_add_cert                     624    EXIST::FUNCTION:
+X509_STORE_add_lookup                   625    EXIST::FUNCTION:
+X509_STORE_free                         626    EXIST::FUNCTION:
+X509_STORE_get_by_subject               627    EXIST::FUNCTION:
+X509_STORE_load_locations               628    EXIST::FUNCTION:STDIO
+X509_STORE_new                          629    EXIST::FUNCTION:
+X509_STORE_set_default_paths            630    EXIST::FUNCTION:STDIO
+X509_VAL_free                           631    EXIST::FUNCTION:
+X509_VAL_new                            632    EXIST::FUNCTION:
+X509_add_ext                            633    EXIST::FUNCTION:
+X509_asn1_meth                          634    NOEXIST::FUNCTION:
+X509_certificate_type                   635    EXIST::FUNCTION:
+X509_check_private_key                  636    EXIST::FUNCTION:
+X509_cmp_current_time                   637    EXIST::FUNCTION:
+X509_delete_ext                         638    EXIST::FUNCTION:
+X509_digest                             639    EXIST::FUNCTION:EVP
+X509_dup                                640    EXIST::FUNCTION:
+X509_free                               641    EXIST::FUNCTION:
+X509_get_default_cert_area              642    EXIST::FUNCTION:
+X509_get_default_cert_dir               643    EXIST::FUNCTION:
+X509_get_default_cert_dir_env           644    EXIST::FUNCTION:
+X509_get_default_cert_file              645    EXIST::FUNCTION:
+X509_get_default_cert_file_env          646    EXIST::FUNCTION:
+X509_get_default_private_dir            647    EXIST::FUNCTION:
+X509_get_ext                            648    EXIST::FUNCTION:
+X509_get_ext_by_NID                     649    EXIST::FUNCTION:
+X509_get_ext_by_OBJ                     650    EXIST::FUNCTION:
+X509_get_ext_by_critical                651    EXIST::FUNCTION:
+X509_get_ext_count                      652    EXIST::FUNCTION:
+X509_get_issuer_name                    653    EXIST::FUNCTION:
+X509_get_pubkey                         654    EXIST::FUNCTION:
+X509_get_pubkey_parameters              655    EXIST::FUNCTION:
+X509_get_serialNumber                   656    EXIST::FUNCTION:
+X509_get_subject_name                   657    EXIST::FUNCTION:
+X509_gmtime_adj                         658    EXIST::FUNCTION:
+X509_issuer_and_serial_cmp              659    EXIST::FUNCTION:
+X509_issuer_and_serial_hash             660    EXIST::FUNCTION:
+X509_issuer_name_cmp                    661    EXIST::FUNCTION:
+X509_issuer_name_hash                   662    EXIST::FUNCTION:
+X509_load_cert_file                     663    EXIST::FUNCTION:STDIO
+X509_new                                664    EXIST::FUNCTION:
+X509_print                              665    EXIST::FUNCTION:BIO
+X509_print_fp                           666    EXIST::FUNCTION:FP_API
+X509_set_issuer_name                    667    EXIST::FUNCTION:
+X509_set_notAfter                       668    EXIST::FUNCTION:
+X509_set_notBefore                      669    EXIST::FUNCTION:
+X509_set_pubkey                         670    EXIST::FUNCTION:
+X509_set_serialNumber                   671    EXIST::FUNCTION:
+X509_set_subject_name                   672    EXIST::FUNCTION:
+X509_set_version                        673    EXIST::FUNCTION:
+X509_sign                               674    EXIST::FUNCTION:EVP
+X509_subject_name_cmp                   675    EXIST::FUNCTION:
+X509_subject_name_hash                  676    EXIST::FUNCTION:
+X509_to_X509_REQ                        677    EXIST::FUNCTION:
+X509_verify                             678    EXIST::FUNCTION:EVP
+X509_verify_cert                        679    EXIST::FUNCTION:
+X509_verify_cert_error_string           680    EXIST::FUNCTION:
+X509v3_add_ext                          681    EXIST::FUNCTION:
+X509v3_add_extension                    682    NOEXIST::FUNCTION:
+X509v3_add_netscape_extensions          683    NOEXIST::FUNCTION:
+X509v3_add_standard_extensions          684    NOEXIST::FUNCTION:
+X509v3_cleanup_extensions               685    NOEXIST::FUNCTION:
+X509v3_data_type_by_NID                 686    NOEXIST::FUNCTION:
+X509v3_data_type_by_OBJ                 687    NOEXIST::FUNCTION:
+X509v3_delete_ext                       688    EXIST::FUNCTION:
+X509v3_get_ext                          689    EXIST::FUNCTION:
+X509v3_get_ext_by_NID                   690    EXIST::FUNCTION:
+X509v3_get_ext_by_OBJ                   691    EXIST::FUNCTION:
+X509v3_get_ext_by_critical              692    EXIST::FUNCTION:
+X509v3_get_ext_count                    693    EXIST::FUNCTION:
+X509v3_pack_string                      694    NOEXIST::FUNCTION:
+X509v3_pack_type_by_NID                 695    NOEXIST::FUNCTION:
+X509v3_pack_type_by_OBJ                 696    NOEXIST::FUNCTION:
+X509v3_unpack_string                    697    NOEXIST::FUNCTION:
+_des_crypt                              698    NOEXIST::FUNCTION:
+a2d_ASN1_OBJECT                         699    EXIST::FUNCTION:
+a2i_ASN1_INTEGER                        700    EXIST::FUNCTION:BIO
+a2i_ASN1_STRING                         701    EXIST::FUNCTION:BIO
+asn1_Finish                             702    EXIST::FUNCTION:
+asn1_GetSequence                        703    EXIST::FUNCTION:
+bn_div_words                            704    EXIST::FUNCTION:
+bn_expand2                              705    EXIST::FUNCTION:
+bn_mul_add_words                        706    EXIST::FUNCTION:
+bn_mul_words                            707    EXIST::FUNCTION:
+BN_uadd                                 708    EXIST::FUNCTION:
+BN_usub                                 709    EXIST::FUNCTION:
+bn_sqr_words                            710    EXIST::FUNCTION:
+_ossl_old_crypt                         711    EXIST:!NeXT,!PERL5:FUNCTION:DES
+d2i_ASN1_BIT_STRING                     712    EXIST::FUNCTION:
+d2i_ASN1_BOOLEAN                        713    EXIST::FUNCTION:
+d2i_ASN1_HEADER                         714    NOEXIST::FUNCTION:
+d2i_ASN1_IA5STRING                      715    EXIST::FUNCTION:
+d2i_ASN1_INTEGER                        716    EXIST::FUNCTION:
+d2i_ASN1_OBJECT                         717    EXIST::FUNCTION:
+d2i_ASN1_OCTET_STRING                   718    EXIST::FUNCTION:
+d2i_ASN1_PRINTABLE                      719    EXIST::FUNCTION:
+d2i_ASN1_PRINTABLESTRING                720    EXIST::FUNCTION:
+d2i_ASN1_SET                            721    EXIST::FUNCTION:
+d2i_ASN1_T61STRING                      722    EXIST::FUNCTION:
+d2i_ASN1_TYPE                           723    EXIST::FUNCTION:
+d2i_ASN1_UTCTIME                        724    EXIST::FUNCTION:
+d2i_ASN1_bytes                          725    EXIST::FUNCTION:
+d2i_ASN1_type_bytes                     726    EXIST::FUNCTION:
+d2i_DHparams                            727    EXIST::FUNCTION:DH
+d2i_DSAPrivateKey                       728    EXIST::FUNCTION:DSA
+d2i_DSAPrivateKey_bio                   729    EXIST::FUNCTION:BIO,DSA
+d2i_DSAPrivateKey_fp                    730    EXIST::FUNCTION:DSA,FP_API
+d2i_DSAPublicKey                        731    EXIST::FUNCTION:DSA
+d2i_DSAparams                           732    EXIST::FUNCTION:DSA
+d2i_NETSCAPE_SPKAC                      733    EXIST::FUNCTION:
+d2i_NETSCAPE_SPKI                       734    EXIST::FUNCTION:
+d2i_Netscape_RSA                        735    EXIST::FUNCTION:RC4,RSA
+d2i_PKCS7                               736    EXIST::FUNCTION:
+d2i_PKCS7_DIGEST                        737    EXIST::FUNCTION:
+d2i_PKCS7_ENCRYPT                       738    EXIST::FUNCTION:
+d2i_PKCS7_ENC_CONTENT                   739    EXIST::FUNCTION:
+d2i_PKCS7_ENVELOPE                      740    EXIST::FUNCTION:
+d2i_PKCS7_ISSUER_AND_SERIAL             741    EXIST::FUNCTION:
+d2i_PKCS7_RECIP_INFO                    742    EXIST::FUNCTION:
+d2i_PKCS7_SIGNED                        743    EXIST::FUNCTION:
+d2i_PKCS7_SIGNER_INFO                   744    EXIST::FUNCTION:
+d2i_PKCS7_SIGN_ENVELOPE                 745    EXIST::FUNCTION:
+d2i_PKCS7_bio                           746    EXIST::FUNCTION:
+d2i_PKCS7_fp                            747    EXIST::FUNCTION:FP_API
+d2i_PrivateKey                          748    EXIST::FUNCTION:
+d2i_PublicKey                           749    EXIST::FUNCTION:
+d2i_RSAPrivateKey                       750    EXIST::FUNCTION:RSA
+d2i_RSAPrivateKey_bio                   751    EXIST::FUNCTION:BIO,RSA
+d2i_RSAPrivateKey_fp                    752    EXIST::FUNCTION:FP_API,RSA
+d2i_RSAPublicKey                        753    EXIST::FUNCTION:RSA
+d2i_X509                                754    EXIST::FUNCTION:
+d2i_X509_ALGOR                          755    EXIST::FUNCTION:
+d2i_X509_ATTRIBUTE                      756    EXIST::FUNCTION:
+d2i_X509_CINF                           757    EXIST::FUNCTION:
+d2i_X509_CRL                            758    EXIST::FUNCTION:
+d2i_X509_CRL_INFO                       759    EXIST::FUNCTION:
+d2i_X509_CRL_bio                        760    EXIST::FUNCTION:BIO
+d2i_X509_CRL_fp                         761    EXIST::FUNCTION:FP_API
+d2i_X509_EXTENSION                      762    EXIST::FUNCTION:
+d2i_X509_NAME                           763    EXIST::FUNCTION:
+d2i_X509_NAME_ENTRY                     764    EXIST::FUNCTION:
+d2i_X509_PKEY                           765    EXIST::FUNCTION:
+d2i_X509_PUBKEY                         766    EXIST::FUNCTION:
+d2i_X509_REQ                            767    EXIST::FUNCTION:
+d2i_X509_REQ_INFO                       768    EXIST::FUNCTION:
+d2i_X509_REQ_bio                        769    EXIST::FUNCTION:BIO
+d2i_X509_REQ_fp                         770    EXIST::FUNCTION:FP_API
+d2i_X509_REVOKED                        771    EXIST::FUNCTION:
+d2i_X509_SIG                            772    EXIST::FUNCTION:
+d2i_X509_VAL                            773    EXIST::FUNCTION:
+d2i_X509_bio                            774    EXIST::FUNCTION:BIO
+d2i_X509_fp                             775    EXIST::FUNCTION:FP_API
+DES_cbc_cksum                           777    EXIST::FUNCTION:DES
+DES_cbc_encrypt                         778    EXIST::FUNCTION:DES
+DES_cblock_print_file                   779    NOEXIST::FUNCTION:
+DES_cfb64_encrypt                       780    EXIST::FUNCTION:DES
+DES_cfb_encrypt                         781    EXIST::FUNCTION:DES
+DES_decrypt3                            782    EXIST::FUNCTION:DES
+DES_ecb3_encrypt                        783    EXIST::FUNCTION:DES
+DES_ecb_encrypt                         784    EXIST::FUNCTION:DES
+DES_ede3_cbc_encrypt                    785    EXIST::FUNCTION:DES
+DES_ede3_cfb64_encrypt                  786    EXIST::FUNCTION:DES
+DES_ede3_ofb64_encrypt                  787    EXIST::FUNCTION:DES
+DES_enc_read                            788    EXIST::FUNCTION:DES
+DES_enc_write                           789    EXIST::FUNCTION:DES
+DES_encrypt1                            790    EXIST::FUNCTION:DES
+DES_encrypt2                            791    EXIST::FUNCTION:DES
+DES_encrypt3                            792    EXIST::FUNCTION:DES
+DES_fcrypt                              793    EXIST::FUNCTION:DES
+DES_is_weak_key                         794    EXIST::FUNCTION:DES
+DES_key_sched                           795    EXIST::FUNCTION:DES
+DES_ncbc_encrypt                        796    EXIST::FUNCTION:DES
+DES_ofb64_encrypt                       797    EXIST::FUNCTION:DES
+DES_ofb_encrypt                         798    EXIST::FUNCTION:DES
+DES_options                             799    EXIST::FUNCTION:DES
+DES_pcbc_encrypt                        800    EXIST::FUNCTION:DES
+DES_quad_cksum                          801    EXIST::FUNCTION:DES
+DES_random_key                          802    EXIST::FUNCTION:DES
+_ossl_old_des_random_seed               803    EXIST::FUNCTION:DES
+_ossl_old_des_read_2passwords           804    EXIST::FUNCTION:DES
+_ossl_old_des_read_password             805    EXIST::FUNCTION:DES
+_ossl_old_des_read_pw                   806    EXIST::FUNCTION:
+_ossl_old_des_read_pw_string            807    EXIST::FUNCTION:
+DES_set_key                             808    EXIST::FUNCTION:DES
+DES_set_odd_parity                      809    EXIST::FUNCTION:DES
+DES_string_to_2keys                     810    EXIST::FUNCTION:DES
+DES_string_to_key                       811    EXIST::FUNCTION:DES
+DES_xcbc_encrypt                        812    EXIST::FUNCTION:DES
+DES_xwhite_in2out                       813    NOEXIST::FUNCTION:
+fcrypt_body                             814    NOEXIST::FUNCTION:
+i2a_ASN1_INTEGER                        815    EXIST::FUNCTION:BIO
+i2a_ASN1_OBJECT                         816    EXIST::FUNCTION:BIO
+i2a_ASN1_STRING                         817    EXIST::FUNCTION:BIO
+i2d_ASN1_BIT_STRING                     818    EXIST::FUNCTION:
+i2d_ASN1_BOOLEAN                        819    EXIST::FUNCTION:
+i2d_ASN1_HEADER                         820    NOEXIST::FUNCTION:
+i2d_ASN1_IA5STRING                      821    EXIST::FUNCTION:
+i2d_ASN1_INTEGER                        822    EXIST::FUNCTION:
+i2d_ASN1_OBJECT                         823    EXIST::FUNCTION:
+i2d_ASN1_OCTET_STRING                   824    EXIST::FUNCTION:
+i2d_ASN1_PRINTABLE                      825    EXIST::FUNCTION:
+i2d_ASN1_SET                            826    EXIST::FUNCTION:
+i2d_ASN1_TYPE                           827    EXIST::FUNCTION:
+i2d_ASN1_UTCTIME                        828    EXIST::FUNCTION:
+i2d_ASN1_bytes                          829    EXIST::FUNCTION:
+i2d_DHparams                            830    EXIST::FUNCTION:DH
+i2d_DSAPrivateKey                       831    EXIST::FUNCTION:DSA
+i2d_DSAPrivateKey_bio                   832    EXIST::FUNCTION:BIO,DSA
+i2d_DSAPrivateKey_fp                    833    EXIST::FUNCTION:DSA,FP_API
+i2d_DSAPublicKey                        834    EXIST::FUNCTION:DSA
+i2d_DSAparams                           835    EXIST::FUNCTION:DSA
+i2d_NETSCAPE_SPKAC                      836    EXIST::FUNCTION:
+i2d_NETSCAPE_SPKI                       837    EXIST::FUNCTION:
+i2d_Netscape_RSA                        838    EXIST::FUNCTION:RC4,RSA
+i2d_PKCS7                               839    EXIST::FUNCTION:
+i2d_PKCS7_DIGEST                        840    EXIST::FUNCTION:
+i2d_PKCS7_ENCRYPT                       841    EXIST::FUNCTION:
+i2d_PKCS7_ENC_CONTENT                   842    EXIST::FUNCTION:
+i2d_PKCS7_ENVELOPE                      843    EXIST::FUNCTION:
+i2d_PKCS7_ISSUER_AND_SERIAL             844    EXIST::FUNCTION:
+i2d_PKCS7_RECIP_INFO                    845    EXIST::FUNCTION:
+i2d_PKCS7_SIGNED                        846    EXIST::FUNCTION:
+i2d_PKCS7_SIGNER_INFO                   847    EXIST::FUNCTION:
+i2d_PKCS7_SIGN_ENVELOPE                 848    EXIST::FUNCTION:
+i2d_PKCS7_bio                           849    EXIST::FUNCTION:
+i2d_PKCS7_fp                            850    EXIST::FUNCTION:FP_API
+i2d_PrivateKey                          851    EXIST::FUNCTION:
+i2d_PublicKey                           852    EXIST::FUNCTION:
+i2d_RSAPrivateKey                       853    EXIST::FUNCTION:RSA
+i2d_RSAPrivateKey_bio                   854    EXIST::FUNCTION:BIO,RSA
+i2d_RSAPrivateKey_fp                    855    EXIST::FUNCTION:FP_API,RSA
+i2d_RSAPublicKey                        856    EXIST::FUNCTION:RSA
+i2d_X509                                857    EXIST::FUNCTION:
+i2d_X509_ALGOR                          858    EXIST::FUNCTION:
+i2d_X509_ATTRIBUTE                      859    EXIST::FUNCTION:
+i2d_X509_CINF                           860    EXIST::FUNCTION:
+i2d_X509_CRL                            861    EXIST::FUNCTION:
+i2d_X509_CRL_INFO                       862    EXIST::FUNCTION:
+i2d_X509_CRL_bio                        863    EXIST::FUNCTION:BIO
+i2d_X509_CRL_fp                         864    EXIST::FUNCTION:FP_API
+i2d_X509_EXTENSION                      865    EXIST::FUNCTION:
+i2d_X509_NAME                           866    EXIST::FUNCTION:
+i2d_X509_NAME_ENTRY                     867    EXIST::FUNCTION:
+i2d_X509_PKEY                           868    EXIST::FUNCTION:
+i2d_X509_PUBKEY                         869    EXIST::FUNCTION:
+i2d_X509_REQ                            870    EXIST::FUNCTION:
+i2d_X509_REQ_INFO                       871    EXIST::FUNCTION:
+i2d_X509_REQ_bio                        872    EXIST::FUNCTION:BIO
+i2d_X509_REQ_fp                         873    EXIST::FUNCTION:FP_API
+i2d_X509_REVOKED                        874    EXIST::FUNCTION:
+i2d_X509_SIG                            875    EXIST::FUNCTION:
+i2d_X509_VAL                            876    EXIST::FUNCTION:
+i2d_X509_bio                            877    EXIST::FUNCTION:BIO
+i2d_X509_fp                             878    EXIST::FUNCTION:FP_API
+idea_cbc_encrypt                        879    EXIST::FUNCTION:IDEA
+idea_cfb64_encrypt                      880    EXIST::FUNCTION:IDEA
+idea_ecb_encrypt                        881    EXIST::FUNCTION:IDEA
+idea_encrypt                            882    EXIST::FUNCTION:IDEA
+idea_ofb64_encrypt                      883    EXIST::FUNCTION:IDEA
+idea_options                            884    EXIST::FUNCTION:IDEA
+idea_set_decrypt_key                    885    EXIST::FUNCTION:IDEA
+idea_set_encrypt_key                    886    EXIST::FUNCTION:IDEA
+lh_delete                               887    EXIST::FUNCTION:
+lh_doall                                888    EXIST::FUNCTION:
+lh_doall_arg                            889    EXIST::FUNCTION:
+lh_free                                 890    EXIST::FUNCTION:
+lh_insert                               891    EXIST::FUNCTION:
+lh_new                                  892    EXIST::FUNCTION:
+lh_node_stats                           893    EXIST::FUNCTION:FP_API
+lh_node_stats_bio                       894    EXIST::FUNCTION:BIO
+lh_node_usage_stats                     895    EXIST::FUNCTION:FP_API
+lh_node_usage_stats_bio                 896    EXIST::FUNCTION:BIO
+lh_retrieve                             897    EXIST::FUNCTION:
+lh_stats                                898    EXIST::FUNCTION:FP_API
+lh_stats_bio                            899    EXIST::FUNCTION:BIO
+lh_strhash                              900    EXIST::FUNCTION:
+sk_delete                               901    EXIST::FUNCTION:
+sk_delete_ptr                           902    EXIST::FUNCTION:
+sk_dup                                  903    EXIST::FUNCTION:
+sk_find                                 904    EXIST::FUNCTION:
+sk_free                                 905    EXIST::FUNCTION:
+sk_insert                               906    EXIST::FUNCTION:
+sk_new                                  907    EXIST::FUNCTION:
+sk_pop                                  908    EXIST::FUNCTION:
+sk_pop_free                             909    EXIST::FUNCTION:
+sk_push                                 910    EXIST::FUNCTION:
+sk_set_cmp_func                         911    EXIST::FUNCTION:
+sk_shift                                912    EXIST::FUNCTION:
+sk_unshift                              913    EXIST::FUNCTION:
+sk_zero                                 914    EXIST::FUNCTION:
+BIO_f_nbio_test                         915    EXIST::FUNCTION:
+ASN1_TYPE_get                           916    EXIST::FUNCTION:
+ASN1_TYPE_set                           917    EXIST::FUNCTION:
+PKCS7_content_free                      918    NOEXIST::FUNCTION:
+ERR_load_PKCS7_strings                  919    EXIST::FUNCTION:
+X509_find_by_issuer_and_serial          920    EXIST::FUNCTION:
+X509_find_by_subject                    921    EXIST::FUNCTION:
+PKCS7_ctrl                              927    EXIST::FUNCTION:
+PKCS7_set_type                          928    EXIST::FUNCTION:
+PKCS7_set_content                       929    EXIST::FUNCTION:
+PKCS7_SIGNER_INFO_set                   930    EXIST::FUNCTION:
+PKCS7_add_signer                        931    EXIST::FUNCTION:
+PKCS7_add_certificate                   932    EXIST::FUNCTION:
+PKCS7_add_crl                           933    EXIST::FUNCTION:
+PKCS7_content_new                       934    EXIST::FUNCTION:
+PKCS7_dataSign                          935    NOEXIST::FUNCTION:
+PKCS7_dataVerify                        936    EXIST::FUNCTION:
+PKCS7_dataInit                          937    EXIST::FUNCTION:
+PKCS7_add_signature                     938    EXIST::FUNCTION:
+PKCS7_cert_from_signer_info             939    EXIST::FUNCTION:
+PKCS7_get_signer_info                   940    EXIST::FUNCTION:
+EVP_delete_alias                        941    NOEXIST::FUNCTION:
+EVP_mdc2                                942    EXIST::FUNCTION:MDC2
+PEM_read_bio_RSAPublicKey               943    EXIST::FUNCTION:RSA
+PEM_write_bio_RSAPublicKey              944    EXIST::FUNCTION:RSA
+d2i_RSAPublicKey_bio                    945    EXIST::FUNCTION:BIO,RSA
+i2d_RSAPublicKey_bio                    946    EXIST::FUNCTION:BIO,RSA
+PEM_read_RSAPublicKey                   947    EXIST:!WIN16:FUNCTION:RSA
+PEM_write_RSAPublicKey                  949    EXIST:!WIN16:FUNCTION:RSA
+d2i_RSAPublicKey_fp                     952    EXIST::FUNCTION:FP_API,RSA
+i2d_RSAPublicKey_fp                     954    EXIST::FUNCTION:FP_API,RSA
+BIO_copy_next_retry                     955    EXIST::FUNCTION:
+RSA_flags                               956    EXIST::FUNCTION:RSA
+X509_STORE_add_crl                      957    EXIST::FUNCTION:
+X509_load_crl_file                      958    EXIST::FUNCTION:STDIO
+EVP_rc2_40_cbc                          959    EXIST::FUNCTION:RC2
+EVP_rc4_40                              960    EXIST::FUNCTION:RC4
+EVP_CIPHER_CTX_init                     961    EXIST::FUNCTION:
+HMAC                                    962    EXIST::FUNCTION:HMAC
+HMAC_Init                               963    EXIST::FUNCTION:HMAC
+HMAC_Update                             964    EXIST::FUNCTION:HMAC
+HMAC_Final                              965    EXIST::FUNCTION:HMAC
+ERR_get_next_error_library              966    EXIST::FUNCTION:
+EVP_PKEY_cmp_parameters                 967    EXIST::FUNCTION:
+HMAC_cleanup                            968    NOEXIST::FUNCTION:
+BIO_ptr_ctrl                            969    EXIST::FUNCTION:
+BIO_new_file_internal                   970    NOEXIST::FUNCTION:
+BIO_new_fp_internal                     971    NOEXIST::FUNCTION:
+BIO_s_file_internal                     972    NOEXIST::FUNCTION:
+BN_BLINDING_convert                     973    EXIST::FUNCTION:
+BN_BLINDING_invert                      974    EXIST::FUNCTION:
+BN_BLINDING_update                      975    EXIST::FUNCTION:
+RSA_blinding_on                         977    EXIST::FUNCTION:RSA
+RSA_blinding_off                        978    EXIST::FUNCTION:RSA
+i2t_ASN1_OBJECT                         979    EXIST::FUNCTION:
+BN_BLINDING_new                         980    EXIST::FUNCTION:
+BN_BLINDING_free                        981    EXIST::FUNCTION:
+EVP_cast5_cbc                           983    EXIST::FUNCTION:CAST
+EVP_cast5_cfb64                         984    EXIST::FUNCTION:CAST
+EVP_cast5_ecb                           985    EXIST::FUNCTION:CAST
+EVP_cast5_ofb                           986    EXIST::FUNCTION:CAST
+BF_decrypt                              987    EXIST::FUNCTION:BF
+CAST_set_key                            988    EXIST::FUNCTION:CAST
+CAST_encrypt                            989    EXIST::FUNCTION:CAST
+CAST_decrypt                            990    EXIST::FUNCTION:CAST
+CAST_ecb_encrypt                        991    EXIST::FUNCTION:CAST
+CAST_cbc_encrypt                        992    EXIST::FUNCTION:CAST
+CAST_cfb64_encrypt                      993    EXIST::FUNCTION:CAST
+CAST_ofb64_encrypt                      994    EXIST::FUNCTION:CAST
+RC2_decrypt                             995    EXIST::FUNCTION:RC2
+OBJ_create_objects                      997    EXIST::FUNCTION:
+BN_exp                                  998    EXIST::FUNCTION:
+BN_mul_word                             999    EXIST::FUNCTION:
+BN_sub_word                             1000   EXIST::FUNCTION:
+BN_dec2bn                               1001   EXIST::FUNCTION:
+BN_bn2dec                               1002   EXIST::FUNCTION:
+BIO_ghbn_ctrl                           1003   NOEXIST::FUNCTION:
+CRYPTO_free_ex_data                     1004   EXIST::FUNCTION:
+CRYPTO_get_ex_data                      1005   EXIST::FUNCTION:
+CRYPTO_set_ex_data                      1007   EXIST::FUNCTION:
+ERR_load_CRYPTO_strings                 1009   EXIST:!OS2,!VMS:FUNCTION:
+ERR_load_CRYPTOlib_strings              1009   EXIST:OS2,VMS:FUNCTION:
+EVP_PKEY_bits                           1010   EXIST::FUNCTION:
+MD5_Transform                           1011   EXIST::FUNCTION:MD5
+SHA1_Transform                          1012   EXIST::FUNCTION:SHA,SHA1
+SHA_Transform                           1013   EXIST::FUNCTION:SHA,SHA0
+X509_STORE_CTX_get_chain                1014   EXIST::FUNCTION:
+X509_STORE_CTX_get_current_cert         1015   EXIST::FUNCTION:
+X509_STORE_CTX_get_error                1016   EXIST::FUNCTION:
+X509_STORE_CTX_get_error_depth          1017   EXIST::FUNCTION:
+X509_STORE_CTX_get_ex_data              1018   EXIST::FUNCTION:
+X509_STORE_CTX_set_cert                 1020   EXIST::FUNCTION:
+X509_STORE_CTX_set_chain                1021   EXIST::FUNCTION:
+X509_STORE_CTX_set_error                1022   EXIST::FUNCTION:
+X509_STORE_CTX_set_ex_data              1023   EXIST::FUNCTION:
+CRYPTO_dup_ex_data                      1025   EXIST::FUNCTION:
+CRYPTO_get_new_lockid                   1026   EXIST::FUNCTION:
+CRYPTO_new_ex_data                      1027   EXIST::FUNCTION:
+RSA_set_ex_data                         1028   EXIST::FUNCTION:RSA
+RSA_get_ex_data                         1029   EXIST::FUNCTION:RSA
+RSA_get_ex_new_index                    1030   EXIST::FUNCTION:RSA
+RSA_padding_add_PKCS1_type_1            1031   EXIST::FUNCTION:RSA
+RSA_padding_add_PKCS1_type_2            1032   EXIST::FUNCTION:RSA
+RSA_padding_add_SSLv23                  1033   EXIST::FUNCTION:RSA
+RSA_padding_add_none                    1034   EXIST::FUNCTION:RSA
+RSA_padding_check_PKCS1_type_1          1035   EXIST::FUNCTION:RSA
+RSA_padding_check_PKCS1_type_2          1036   EXIST::FUNCTION:RSA
+RSA_padding_check_SSLv23                1037   EXIST::FUNCTION:RSA
+RSA_padding_check_none                  1038   EXIST::FUNCTION:RSA
+bn_add_words                            1039   EXIST::FUNCTION:
+d2i_Netscape_RSA_2                      1040   NOEXIST::FUNCTION:
+CRYPTO_get_ex_new_index                 1041   EXIST::FUNCTION:
+RIPEMD160_Init                          1042   EXIST::FUNCTION:RIPEMD
+RIPEMD160_Update                        1043   EXIST::FUNCTION:RIPEMD
+RIPEMD160_Final                         1044   EXIST::FUNCTION:RIPEMD
+RIPEMD160                               1045   EXIST::FUNCTION:RIPEMD
+RIPEMD160_Transform                     1046   EXIST::FUNCTION:RIPEMD
+RC5_32_set_key                          1047   EXIST::FUNCTION:RC5
+RC5_32_ecb_encrypt                      1048   EXIST::FUNCTION:RC5
+RC5_32_encrypt                          1049   EXIST::FUNCTION:RC5
+RC5_32_decrypt                          1050   EXIST::FUNCTION:RC5
+RC5_32_cbc_encrypt                      1051   EXIST::FUNCTION:RC5
+RC5_32_cfb64_encrypt                    1052   EXIST::FUNCTION:RC5
+RC5_32_ofb64_encrypt                    1053   EXIST::FUNCTION:RC5
+BN_bn2mpi                               1058   EXIST::FUNCTION:
+BN_mpi2bn                               1059   EXIST::FUNCTION:
+ASN1_BIT_STRING_get_bit                 1060   EXIST::FUNCTION:
+ASN1_BIT_STRING_set_bit                 1061   EXIST::FUNCTION:
+BIO_get_ex_data                         1062   EXIST::FUNCTION:
+BIO_get_ex_new_index                    1063   EXIST::FUNCTION:
+BIO_set_ex_data                         1064   EXIST::FUNCTION:
+X509v3_get_key_usage                    1066   NOEXIST::FUNCTION:
+X509v3_set_key_usage                    1067   NOEXIST::FUNCTION:
+a2i_X509v3_key_usage                    1068   NOEXIST::FUNCTION:
+i2a_X509v3_key_usage                    1069   NOEXIST::FUNCTION:
+EVP_PKEY_decrypt                        1070   EXIST::FUNCTION:
+EVP_PKEY_encrypt                        1071   EXIST::FUNCTION:
+PKCS7_RECIP_INFO_set                    1072   EXIST::FUNCTION:
+PKCS7_add_recipient                     1073   EXIST::FUNCTION:
+PKCS7_add_recipient_info                1074   EXIST::FUNCTION:
+PKCS7_set_cipher                        1075   EXIST::FUNCTION:
+ASN1_TYPE_get_int_octetstring           1076   EXIST::FUNCTION:
+ASN1_TYPE_get_octetstring               1077   EXIST::FUNCTION:
+ASN1_TYPE_set_int_octetstring           1078   EXIST::FUNCTION:
+ASN1_TYPE_set_octetstring               1079   EXIST::FUNCTION:
+ASN1_UTCTIME_set_string                 1080   EXIST::FUNCTION:
+ERR_add_error_data                      1081   EXIST::FUNCTION:BIO
+ERR_set_error_data                      1082   EXIST::FUNCTION:
+EVP_CIPHER_asn1_to_param                1083   EXIST::FUNCTION:
+EVP_CIPHER_param_to_asn1                1084   EXIST::FUNCTION:
+EVP_CIPHER_get_asn1_iv                  1085   EXIST::FUNCTION:
+EVP_CIPHER_set_asn1_iv                  1086   EXIST::FUNCTION:
+EVP_rc5_32_12_16_cbc                    1087   EXIST::FUNCTION:RC5
+EVP_rc5_32_12_16_cfb64                  1088   EXIST::FUNCTION:RC5
+EVP_rc5_32_12_16_ecb                    1089   EXIST::FUNCTION:RC5
+EVP_rc5_32_12_16_ofb                    1090   EXIST::FUNCTION:RC5
+asn1_add_error                          1091   EXIST::FUNCTION:
+d2i_ASN1_BMPSTRING                      1092   EXIST::FUNCTION:
+i2d_ASN1_BMPSTRING                      1093   EXIST::FUNCTION:
+BIO_f_ber                               1094   NOEXIST::FUNCTION:
+BN_init                                 1095   EXIST::FUNCTION:
+COMP_CTX_new                            1096   EXIST::FUNCTION:
+COMP_CTX_free                           1097   EXIST::FUNCTION:
+COMP_CTX_compress_block                 1098   NOEXIST::FUNCTION:
+COMP_CTX_expand_block                   1099   NOEXIST::FUNCTION:
+X509_STORE_CTX_get_ex_new_index         1100   EXIST::FUNCTION:
+OBJ_NAME_add                            1101   EXIST::FUNCTION:
+BIO_socket_nbio                         1102   EXIST::FUNCTION:
+EVP_rc2_64_cbc                          1103   EXIST::FUNCTION:RC2
+OBJ_NAME_cleanup                        1104   EXIST::FUNCTION:
+OBJ_NAME_get                            1105   EXIST::FUNCTION:
+OBJ_NAME_init                           1106   EXIST::FUNCTION:
+OBJ_NAME_new_index                      1107   EXIST::FUNCTION:
+OBJ_NAME_remove                         1108   EXIST::FUNCTION:
+BN_MONT_CTX_copy                        1109   EXIST::FUNCTION:
+BIO_new_socks4a_connect                 1110   NOEXIST::FUNCTION:
+BIO_s_socks4a_connect                   1111   NOEXIST::FUNCTION:
+PROXY_set_connect_mode                  1112   NOEXIST::FUNCTION:
+RAND_SSLeay                             1113   EXIST::FUNCTION:
+RAND_set_rand_method                    1114   EXIST::FUNCTION:
+RSA_memory_lock                         1115   EXIST::FUNCTION:RSA
+bn_sub_words                            1116   EXIST::FUNCTION:
+bn_mul_normal                           1117   NOEXIST::FUNCTION:
+bn_mul_comba8                           1118   NOEXIST::FUNCTION:
+bn_mul_comba4                           1119   NOEXIST::FUNCTION:
+bn_sqr_normal                           1120   NOEXIST::FUNCTION:
+bn_sqr_comba8                           1121   NOEXIST::FUNCTION:
+bn_sqr_comba4                           1122   NOEXIST::FUNCTION:
+bn_cmp_words                            1123   NOEXIST::FUNCTION:
+bn_mul_recursive                        1124   NOEXIST::FUNCTION:
+bn_mul_part_recursive                   1125   NOEXIST::FUNCTION:
+bn_sqr_recursive                        1126   NOEXIST::FUNCTION:
+bn_mul_low_normal                       1127   NOEXIST::FUNCTION:
+BN_RECP_CTX_init                        1128   EXIST::FUNCTION:
+BN_RECP_CTX_new                         1129   EXIST::FUNCTION:
+BN_RECP_CTX_free                        1130   EXIST::FUNCTION:
+BN_RECP_CTX_set                         1131   EXIST::FUNCTION:
+BN_mod_mul_reciprocal                   1132   EXIST::FUNCTION:
+BN_mod_exp_recp                         1133   EXIST::FUNCTION:
+BN_div_recp                             1134   EXIST::FUNCTION:
+BN_CTX_init                             1135   EXIST::FUNCTION:DEPRECATED
+BN_MONT_CTX_init                        1136   EXIST::FUNCTION:
+RAND_get_rand_method                    1137   EXIST::FUNCTION:
+PKCS7_add_attribute                     1138   EXIST::FUNCTION:
+PKCS7_add_signed_attribute              1139   EXIST::FUNCTION:
+PKCS7_digest_from_attributes            1140   EXIST::FUNCTION:
+PKCS7_get_attribute                     1141   EXIST::FUNCTION:
+PKCS7_get_issuer_and_serial             1142   EXIST::FUNCTION:
+PKCS7_get_signed_attribute              1143   EXIST::FUNCTION:
+COMP_compress_block                     1144   EXIST::FUNCTION:
+COMP_expand_block                       1145   EXIST::FUNCTION:
+COMP_rle                                1146   EXIST::FUNCTION:
+COMP_zlib                               1147   EXIST::FUNCTION:
+ms_time_diff                            1148   NOEXIST::FUNCTION:
+ms_time_new                             1149   NOEXIST::FUNCTION:
+ms_time_free                            1150   NOEXIST::FUNCTION:
+ms_time_cmp                             1151   NOEXIST::FUNCTION:
+ms_time_get                             1152   NOEXIST::FUNCTION:
+PKCS7_set_attributes                    1153   EXIST::FUNCTION:
+PKCS7_set_signed_attributes             1154   EXIST::FUNCTION:
+X509_ATTRIBUTE_create                   1155   EXIST::FUNCTION:
+X509_ATTRIBUTE_dup                      1156   EXIST::FUNCTION:
+ASN1_GENERALIZEDTIME_check              1157   EXIST::FUNCTION:
+ASN1_GENERALIZEDTIME_print              1158   EXIST::FUNCTION:BIO
+ASN1_GENERALIZEDTIME_set                1159   EXIST::FUNCTION:
+ASN1_GENERALIZEDTIME_set_string         1160   EXIST::FUNCTION:
+ASN1_TIME_print                         1161   EXIST::FUNCTION:BIO
+BASIC_CONSTRAINTS_free                  1162   EXIST::FUNCTION:
+BASIC_CONSTRAINTS_new                   1163   EXIST::FUNCTION:
+ERR_load_X509V3_strings                 1164   EXIST::FUNCTION:
+NETSCAPE_CERT_SEQUENCE_free             1165   EXIST::FUNCTION:
+NETSCAPE_CERT_SEQUENCE_new              1166   EXIST::FUNCTION:
+OBJ_txt2obj                             1167   EXIST::FUNCTION:
+PEM_read_NETSCAPE_CERT_SEQUENCE         1168   EXIST:!VMS,!WIN16:FUNCTION:
+PEM_read_NS_CERT_SEQ                    1168   EXIST:VMS:FUNCTION:
+PEM_read_bio_NETSCAPE_CERT_SEQUENCE     1169   EXIST:!VMS:FUNCTION:
+PEM_read_bio_NS_CERT_SEQ                1169   EXIST:VMS:FUNCTION:
+PEM_write_NETSCAPE_CERT_SEQUENCE        1170   EXIST:!VMS,!WIN16:FUNCTION:
+PEM_write_NS_CERT_SEQ                   1170   EXIST:VMS:FUNCTION:
+PEM_write_bio_NETSCAPE_CERT_SEQUENCE    1171   EXIST:!VMS:FUNCTION:
+PEM_write_bio_NS_CERT_SEQ               1171   EXIST:VMS:FUNCTION:
+X509V3_EXT_add                          1172   EXIST::FUNCTION:
+X509V3_EXT_add_alias                    1173   EXIST::FUNCTION:
+X509V3_EXT_add_conf                     1174   EXIST::FUNCTION:
+X509V3_EXT_cleanup                      1175   EXIST::FUNCTION:
+X509V3_EXT_conf                         1176   EXIST::FUNCTION:
+X509V3_EXT_conf_nid                     1177   EXIST::FUNCTION:
+X509V3_EXT_get                          1178   EXIST::FUNCTION:
+X509V3_EXT_get_nid                      1179   EXIST::FUNCTION:
+X509V3_EXT_print                        1180   EXIST::FUNCTION:
+X509V3_EXT_print_fp                     1181   EXIST::FUNCTION:
+X509V3_add_standard_extensions          1182   EXIST::FUNCTION:
+X509V3_add_value                        1183   EXIST::FUNCTION:
+X509V3_add_value_bool                   1184   EXIST::FUNCTION:
+X509V3_add_value_int                    1185   EXIST::FUNCTION:
+X509V3_conf_free                        1186   EXIST::FUNCTION:
+X509V3_get_value_bool                   1187   EXIST::FUNCTION:
+X509V3_get_value_int                    1188   EXIST::FUNCTION:
+X509V3_parse_list                       1189   EXIST::FUNCTION:
+d2i_ASN1_GENERALIZEDTIME                1190   EXIST::FUNCTION:
+d2i_ASN1_TIME                           1191   EXIST::FUNCTION:
+d2i_BASIC_CONSTRAINTS                   1192   EXIST::FUNCTION:
+d2i_NETSCAPE_CERT_SEQUENCE              1193   EXIST::FUNCTION:
+d2i_ext_ku                              1194   NOEXIST::FUNCTION:
+ext_ku_free                             1195   NOEXIST::FUNCTION:
+ext_ku_new                              1196   NOEXIST::FUNCTION:
+i2d_ASN1_GENERALIZEDTIME                1197   EXIST::FUNCTION:
+i2d_ASN1_TIME                           1198   EXIST::FUNCTION:
+i2d_BASIC_CONSTRAINTS                   1199   EXIST::FUNCTION:
+i2d_NETSCAPE_CERT_SEQUENCE              1200   EXIST::FUNCTION:
+i2d_ext_ku                              1201   NOEXIST::FUNCTION:
+EVP_MD_CTX_copy                         1202   EXIST::FUNCTION:
+i2d_ASN1_ENUMERATED                     1203   EXIST::FUNCTION:
+d2i_ASN1_ENUMERATED                     1204   EXIST::FUNCTION:
+ASN1_ENUMERATED_set                     1205   EXIST::FUNCTION:
+ASN1_ENUMERATED_get                     1206   EXIST::FUNCTION:
+BN_to_ASN1_ENUMERATED                   1207   EXIST::FUNCTION:
+ASN1_ENUMERATED_to_BN                   1208   EXIST::FUNCTION:
+i2a_ASN1_ENUMERATED                     1209   EXIST::FUNCTION:BIO
+a2i_ASN1_ENUMERATED                     1210   EXIST::FUNCTION:BIO
+i2d_GENERAL_NAME                        1211   EXIST::FUNCTION:
+d2i_GENERAL_NAME                        1212   EXIST::FUNCTION:
+GENERAL_NAME_new                        1213   EXIST::FUNCTION:
+GENERAL_NAME_free                       1214   EXIST::FUNCTION:
+GENERAL_NAMES_new                       1215   EXIST::FUNCTION:
+GENERAL_NAMES_free                      1216   EXIST::FUNCTION:
+d2i_GENERAL_NAMES                       1217   EXIST::FUNCTION:
+i2d_GENERAL_NAMES                       1218   EXIST::FUNCTION:
+i2v_GENERAL_NAMES                       1219   EXIST::FUNCTION:
+i2s_ASN1_OCTET_STRING                   1220   EXIST::FUNCTION:
+s2i_ASN1_OCTET_STRING                   1221   EXIST::FUNCTION:
+X509V3_EXT_check_conf                   1222   NOEXIST::FUNCTION:
+hex_to_string                           1223   EXIST::FUNCTION:
+string_to_hex                           1224   EXIST::FUNCTION:
+DES_ede3_cbcm_encrypt                   1225   EXIST::FUNCTION:DES
+RSA_padding_add_PKCS1_OAEP              1226   EXIST::FUNCTION:RSA
+RSA_padding_check_PKCS1_OAEP            1227   EXIST::FUNCTION:RSA
+X509_CRL_print_fp                       1228   EXIST::FUNCTION:FP_API
+X509_CRL_print                          1229   EXIST::FUNCTION:BIO
+i2v_GENERAL_NAME                        1230   EXIST::FUNCTION:
+v2i_GENERAL_NAME                        1231   EXIST::FUNCTION:
+i2d_PKEY_USAGE_PERIOD                   1232   EXIST::FUNCTION:
+d2i_PKEY_USAGE_PERIOD                   1233   EXIST::FUNCTION:
+PKEY_USAGE_PERIOD_new                   1234   EXIST::FUNCTION:
+PKEY_USAGE_PERIOD_free                  1235   EXIST::FUNCTION:
+v2i_GENERAL_NAMES                       1236   EXIST::FUNCTION:
+i2s_ASN1_INTEGER                        1237   EXIST::FUNCTION:
+X509V3_EXT_d2i                          1238   EXIST::FUNCTION:
+name_cmp                                1239   EXIST::FUNCTION:
+str_dup                                 1240   NOEXIST::FUNCTION:
+i2s_ASN1_ENUMERATED                     1241   EXIST::FUNCTION:
+i2s_ASN1_ENUMERATED_TABLE               1242   EXIST::FUNCTION:
+BIO_s_log                               1243   EXIST:!OS2,!WIN16,!WIN32,!macintosh:FUNCTION:
+BIO_f_reliable                          1244   EXIST::FUNCTION:BIO
+PKCS7_dataFinal                         1245   EXIST::FUNCTION:
+PKCS7_dataDecode                        1246   EXIST::FUNCTION:
+X509V3_EXT_CRL_add_conf                 1247   EXIST::FUNCTION:
+BN_set_params                           1248   EXIST::FUNCTION:DEPRECATED
+BN_get_params                           1249   EXIST::FUNCTION:DEPRECATED
+BIO_get_ex_num                          1250   NOEXIST::FUNCTION:
+BIO_set_ex_free_func                    1251   NOEXIST::FUNCTION:
+EVP_ripemd160                           1252   EXIST::FUNCTION:RIPEMD
+ASN1_TIME_set                           1253   EXIST::FUNCTION:
+i2d_AUTHORITY_KEYID                     1254   EXIST::FUNCTION:
+d2i_AUTHORITY_KEYID                     1255   EXIST::FUNCTION:
+AUTHORITY_KEYID_new                     1256   EXIST::FUNCTION:
+AUTHORITY_KEYID_free                    1257   EXIST::FUNCTION:
+ASN1_seq_unpack                         1258   EXIST::FUNCTION:
+ASN1_seq_pack                           1259   EXIST::FUNCTION:
+ASN1_unpack_string                      1260   EXIST::FUNCTION:
+ASN1_pack_string                        1261   EXIST::FUNCTION:
+PKCS12_pack_safebag                     1262   NOEXIST::FUNCTION:
+PKCS12_MAKE_KEYBAG                      1263   EXIST::FUNCTION:
+PKCS8_encrypt                           1264   EXIST::FUNCTION:
+PKCS12_MAKE_SHKEYBAG                    1265   EXIST::FUNCTION:
+PKCS12_pack_p7data                      1266   EXIST::FUNCTION:
+PKCS12_pack_p7encdata                   1267   EXIST::FUNCTION:
+PKCS12_add_localkeyid                   1268   EXIST::FUNCTION:
+PKCS12_add_friendlyname_asc             1269   EXIST::FUNCTION:
+PKCS12_add_friendlyname_uni             1270   EXIST::FUNCTION:
+PKCS12_get_friendlyname                 1271   EXIST::FUNCTION:
+PKCS12_pbe_crypt                        1272   EXIST::FUNCTION:
+PKCS12_decrypt_d2i                      1273   NOEXIST::FUNCTION:
+PKCS12_i2d_encrypt                      1274   NOEXIST::FUNCTION:
+PKCS12_init                             1275   EXIST::FUNCTION:
+PKCS12_key_gen_asc                      1276   EXIST::FUNCTION:
+PKCS12_key_gen_uni                      1277   EXIST::FUNCTION:
+PKCS12_gen_mac                          1278   EXIST::FUNCTION:
+PKCS12_verify_mac                       1279   EXIST::FUNCTION:
+PKCS12_set_mac                          1280   EXIST::FUNCTION:
+PKCS12_setup_mac                        1281   EXIST::FUNCTION:
+OPENSSL_asc2uni                         1282   EXIST::FUNCTION:
+OPENSSL_uni2asc                         1283   EXIST::FUNCTION:
+i2d_PKCS12_BAGS                         1284   EXIST::FUNCTION:
+PKCS12_BAGS_new                         1285   EXIST::FUNCTION:
+d2i_PKCS12_BAGS                         1286   EXIST::FUNCTION:
+PKCS12_BAGS_free                        1287   EXIST::FUNCTION:
+i2d_PKCS12                              1288   EXIST::FUNCTION:
+d2i_PKCS12                              1289   EXIST::FUNCTION:
+PKCS12_new                              1290   EXIST::FUNCTION:
+PKCS12_free                             1291   EXIST::FUNCTION:
+i2d_PKCS12_MAC_DATA                     1292   EXIST::FUNCTION:
+PKCS12_MAC_DATA_new                     1293   EXIST::FUNCTION:
+d2i_PKCS12_MAC_DATA                     1294   EXIST::FUNCTION:
+PKCS12_MAC_DATA_free                    1295   EXIST::FUNCTION:
+i2d_PKCS12_SAFEBAG                      1296   EXIST::FUNCTION:
+PKCS12_SAFEBAG_new                      1297   EXIST::FUNCTION:
+d2i_PKCS12_SAFEBAG                      1298   EXIST::FUNCTION:
+PKCS12_SAFEBAG_free                     1299   EXIST::FUNCTION:
+ERR_load_PKCS12_strings                 1300   EXIST::FUNCTION:
+PKCS12_PBE_add                          1301   EXIST::FUNCTION:
+PKCS8_add_keyusage                      1302   EXIST::FUNCTION:
+PKCS12_get_attr_gen                     1303   EXIST::FUNCTION:
+PKCS12_parse                            1304   EXIST::FUNCTION:
+PKCS12_create                           1305   EXIST::FUNCTION:
+i2d_PKCS12_bio                          1306   EXIST::FUNCTION:
+i2d_PKCS12_fp                           1307   EXIST::FUNCTION:
+d2i_PKCS12_bio                          1308   EXIST::FUNCTION:
+d2i_PKCS12_fp                           1309   EXIST::FUNCTION:
+i2d_PBEPARAM                            1310   EXIST::FUNCTION:
+PBEPARAM_new                            1311   EXIST::FUNCTION:
+d2i_PBEPARAM                            1312   EXIST::FUNCTION:
+PBEPARAM_free                           1313   EXIST::FUNCTION:
+i2d_PKCS8_PRIV_KEY_INFO                 1314   EXIST::FUNCTION:
+PKCS8_PRIV_KEY_INFO_new                 1315   EXIST::FUNCTION:
+d2i_PKCS8_PRIV_KEY_INFO                 1316   EXIST::FUNCTION:
+PKCS8_PRIV_KEY_INFO_free                1317   EXIST::FUNCTION:
+EVP_PKCS82PKEY                          1318   EXIST::FUNCTION:
+EVP_PKEY2PKCS8                          1319   EXIST::FUNCTION:
+PKCS8_set_broken                        1320   EXIST::FUNCTION:
+EVP_PBE_ALGOR_CipherInit                1321   NOEXIST::FUNCTION:
+EVP_PBE_alg_add                         1322   EXIST::FUNCTION:
+PKCS5_pbe_set                           1323   EXIST::FUNCTION:
+EVP_PBE_cleanup                         1324   EXIST::FUNCTION:
+i2d_SXNET                               1325   EXIST::FUNCTION:
+d2i_SXNET                               1326   EXIST::FUNCTION:
+SXNET_new                               1327   EXIST::FUNCTION:
+SXNET_free                              1328   EXIST::FUNCTION:
+i2d_SXNETID                             1329   EXIST::FUNCTION:
+d2i_SXNETID                             1330   EXIST::FUNCTION:
+SXNETID_new                             1331   EXIST::FUNCTION:
+SXNETID_free                            1332   EXIST::FUNCTION:
+DSA_SIG_new                             1333   EXIST::FUNCTION:DSA
+DSA_SIG_free                            1334   EXIST::FUNCTION:DSA
+DSA_do_sign                             1335   EXIST::FUNCTION:DSA
+DSA_do_verify                           1336   EXIST::FUNCTION:DSA
+d2i_DSA_SIG                             1337   EXIST::FUNCTION:DSA
+i2d_DSA_SIG                             1338   EXIST::FUNCTION:DSA
+i2d_ASN1_VISIBLESTRING                  1339   EXIST::FUNCTION:
+d2i_ASN1_VISIBLESTRING                  1340   EXIST::FUNCTION:
+i2d_ASN1_UTF8STRING                     1341   EXIST::FUNCTION:
+d2i_ASN1_UTF8STRING                     1342   EXIST::FUNCTION:
+i2d_DIRECTORYSTRING                     1343   EXIST::FUNCTION:
+d2i_DIRECTORYSTRING                     1344   EXIST::FUNCTION:
+i2d_DISPLAYTEXT                         1345   EXIST::FUNCTION:
+d2i_DISPLAYTEXT                         1346   EXIST::FUNCTION:
+d2i_ASN1_SET_OF_X509                    1379   NOEXIST::FUNCTION:
+i2d_ASN1_SET_OF_X509                    1380   NOEXIST::FUNCTION:
+i2d_PBKDF2PARAM                         1397   EXIST::FUNCTION:
+PBKDF2PARAM_new                         1398   EXIST::FUNCTION:
+d2i_PBKDF2PARAM                         1399   EXIST::FUNCTION:
+PBKDF2PARAM_free                        1400   EXIST::FUNCTION:
+i2d_PBE2PARAM                           1401   EXIST::FUNCTION:
+PBE2PARAM_new                           1402   EXIST::FUNCTION:
+d2i_PBE2PARAM                           1403   EXIST::FUNCTION:
+PBE2PARAM_free                          1404   EXIST::FUNCTION:
+d2i_ASN1_SET_OF_GENERAL_NAME            1421   NOEXIST::FUNCTION:
+i2d_ASN1_SET_OF_GENERAL_NAME            1422   NOEXIST::FUNCTION:
+d2i_ASN1_SET_OF_SXNETID                 1439   NOEXIST::FUNCTION:
+i2d_ASN1_SET_OF_SXNETID                 1440   NOEXIST::FUNCTION:
+d2i_ASN1_SET_OF_POLICYQUALINFO          1457   NOEXIST::FUNCTION:
+i2d_ASN1_SET_OF_POLICYQUALINFO          1458   NOEXIST::FUNCTION:
+d2i_ASN1_SET_OF_POLICYINFO              1475   NOEXIST::FUNCTION:
+i2d_ASN1_SET_OF_POLICYINFO              1476   NOEXIST::FUNCTION:
+SXNET_add_id_asc                        1477   EXIST::FUNCTION:
+SXNET_add_id_ulong                      1478   EXIST::FUNCTION:
+SXNET_add_id_INTEGER                    1479   EXIST::FUNCTION:
+SXNET_get_id_asc                        1480   EXIST::FUNCTION:
+SXNET_get_id_ulong                      1481   EXIST::FUNCTION:
+SXNET_get_id_INTEGER                    1482   EXIST::FUNCTION:
+X509V3_set_conf_lhash                   1483   EXIST::FUNCTION:
+i2d_CERTIFICATEPOLICIES                 1484   EXIST::FUNCTION:
+CERTIFICATEPOLICIES_new                 1485   EXIST::FUNCTION:
+CERTIFICATEPOLICIES_free                1486   EXIST::FUNCTION:
+d2i_CERTIFICATEPOLICIES                 1487   EXIST::FUNCTION:
+i2d_POLICYINFO                          1488   EXIST::FUNCTION:
+POLICYINFO_new                          1489   EXIST::FUNCTION:
+d2i_POLICYINFO                          1490   EXIST::FUNCTION:
+POLICYINFO_free                         1491   EXIST::FUNCTION:
+i2d_POLICYQUALINFO                      1492   EXIST::FUNCTION:
+POLICYQUALINFO_new                      1493   EXIST::FUNCTION:
+d2i_POLICYQUALINFO                      1494   EXIST::FUNCTION:
+POLICYQUALINFO_free                     1495   EXIST::FUNCTION:
+i2d_USERNOTICE                          1496   EXIST::FUNCTION:
+USERNOTICE_new                          1497   EXIST::FUNCTION:
+d2i_USERNOTICE                          1498   EXIST::FUNCTION:
+USERNOTICE_free                         1499   EXIST::FUNCTION:
+i2d_NOTICEREF                           1500   EXIST::FUNCTION:
+NOTICEREF_new                           1501   EXIST::FUNCTION:
+d2i_NOTICEREF                           1502   EXIST::FUNCTION:
+NOTICEREF_free                          1503   EXIST::FUNCTION:
+X509V3_get_string                       1504   EXIST::FUNCTION:
+X509V3_get_section                      1505   EXIST::FUNCTION:
+X509V3_string_free                      1506   EXIST::FUNCTION:
+X509V3_section_free                     1507   EXIST::FUNCTION:
+X509V3_set_ctx                          1508   EXIST::FUNCTION:
+s2i_ASN1_INTEGER                        1509   EXIST::FUNCTION:
+CRYPTO_set_locked_mem_functions         1510   EXIST::FUNCTION:
+CRYPTO_get_locked_mem_functions         1511   EXIST::FUNCTION:
+CRYPTO_malloc_locked                    1512   EXIST::FUNCTION:
+CRYPTO_free_locked                      1513   EXIST::FUNCTION:
+BN_mod_exp2_mont                        1514   EXIST::FUNCTION:
+ERR_get_error_line_data                 1515   EXIST::FUNCTION:
+ERR_peek_error_line_data                1516   EXIST::FUNCTION:
+PKCS12_PBE_keyivgen                     1517   EXIST::FUNCTION:
+X509_ALGOR_dup                          1518   EXIST::FUNCTION:
+d2i_ASN1_SET_OF_DIST_POINT              1535   NOEXIST::FUNCTION:
+i2d_ASN1_SET_OF_DIST_POINT              1536   NOEXIST::FUNCTION:
+i2d_CRL_DIST_POINTS                     1537   EXIST::FUNCTION:
+CRL_DIST_POINTS_new                     1538   EXIST::FUNCTION:
+CRL_DIST_POINTS_free                    1539   EXIST::FUNCTION:
+d2i_CRL_DIST_POINTS                     1540   EXIST::FUNCTION:
+i2d_DIST_POINT                          1541   EXIST::FUNCTION:
+DIST_POINT_new                          1542   EXIST::FUNCTION:
+d2i_DIST_POINT                          1543   EXIST::FUNCTION:
+DIST_POINT_free                         1544   EXIST::FUNCTION:
+i2d_DIST_POINT_NAME                     1545   EXIST::FUNCTION:
+DIST_POINT_NAME_new                     1546   EXIST::FUNCTION:
+DIST_POINT_NAME_free                    1547   EXIST::FUNCTION:
+d2i_DIST_POINT_NAME                     1548   EXIST::FUNCTION:
+X509V3_add_value_uchar                  1549   EXIST::FUNCTION:
+d2i_ASN1_SET_OF_X509_ATTRIBUTE          1555   NOEXIST::FUNCTION:
+i2d_ASN1_SET_OF_ASN1_TYPE               1560   NOEXIST::FUNCTION:
+d2i_ASN1_SET_OF_X509_EXTENSION          1567   NOEXIST::FUNCTION:
+d2i_ASN1_SET_OF_X509_NAME_ENTRY         1574   NOEXIST::FUNCTION:
+d2i_ASN1_SET_OF_ASN1_TYPE               1589   NOEXIST::FUNCTION:
+i2d_ASN1_SET_OF_X509_ATTRIBUTE          1615   NOEXIST::FUNCTION:
+i2d_ASN1_SET_OF_X509_EXTENSION          1624   NOEXIST::FUNCTION:
+i2d_ASN1_SET_OF_X509_NAME_ENTRY         1633   NOEXIST::FUNCTION:
+X509V3_EXT_i2d                          1646   EXIST::FUNCTION:
+X509V3_EXT_val_prn                      1647   EXIST::FUNCTION:
+X509V3_EXT_add_list                     1648   EXIST::FUNCTION:
+EVP_CIPHER_type                         1649   EXIST::FUNCTION:
+EVP_PBE_CipherInit                      1650   EXIST::FUNCTION:
+X509V3_add_value_bool_nf                1651   EXIST::FUNCTION:
+d2i_ASN1_UINTEGER                       1652   EXIST::FUNCTION:
+sk_value                                1653   EXIST::FUNCTION:
+sk_num                                  1654   EXIST::FUNCTION:
+sk_set                                  1655   EXIST::FUNCTION:
+i2d_ASN1_SET_OF_X509_REVOKED            1661   NOEXIST::FUNCTION:
+sk_sort                                 1671   EXIST::FUNCTION:
+d2i_ASN1_SET_OF_X509_REVOKED            1674   NOEXIST::FUNCTION:
+i2d_ASN1_SET_OF_X509_ALGOR              1682   NOEXIST::FUNCTION:
+i2d_ASN1_SET_OF_X509_CRL                1685   NOEXIST::FUNCTION:
+d2i_ASN1_SET_OF_X509_ALGOR              1696   NOEXIST::FUNCTION:
+d2i_ASN1_SET_OF_X509_CRL                1702   NOEXIST::FUNCTION:
+i2d_ASN1_SET_OF_PKCS7_SIGNER_INFO       1723   NOEXIST::FUNCTION:
+i2d_ASN1_SET_OF_PKCS7_RECIP_INFO        1738   NOEXIST::FUNCTION:
+d2i_ASN1_SET_OF_PKCS7_SIGNER_INFO       1748   NOEXIST::FUNCTION:
+d2i_ASN1_SET_OF_PKCS7_RECIP_INFO        1753   NOEXIST::FUNCTION:
+PKCS5_PBE_add                           1775   EXIST::FUNCTION:
+PEM_write_bio_PKCS8                     1776   EXIST::FUNCTION:
+i2d_PKCS8_fp                            1777   EXIST::FUNCTION:FP_API
+PEM_read_bio_PKCS8_PRIV_KEY_INFO        1778   EXIST:!VMS:FUNCTION:
+PEM_read_bio_P8_PRIV_KEY_INFO           1778   EXIST:VMS:FUNCTION:
+d2i_PKCS8_bio                           1779   EXIST::FUNCTION:BIO
+d2i_PKCS8_PRIV_KEY_INFO_fp              1780   EXIST::FUNCTION:FP_API
+PEM_write_bio_PKCS8_PRIV_KEY_INFO       1781   EXIST:!VMS:FUNCTION:
+PEM_write_bio_P8_PRIV_KEY_INFO          1781   EXIST:VMS:FUNCTION:
+PEM_read_PKCS8                          1782   EXIST:!WIN16:FUNCTION:
+d2i_PKCS8_PRIV_KEY_INFO_bio             1783   EXIST::FUNCTION:BIO
+d2i_PKCS8_fp                            1784   EXIST::FUNCTION:FP_API
+PEM_write_PKCS8                         1785   EXIST:!WIN16:FUNCTION:
+PEM_read_PKCS8_PRIV_KEY_INFO            1786   EXIST:!VMS,!WIN16:FUNCTION:
+PEM_read_P8_PRIV_KEY_INFO               1786   EXIST:VMS:FUNCTION:
+PEM_read_bio_PKCS8                      1787   EXIST::FUNCTION:
+PEM_write_PKCS8_PRIV_KEY_INFO           1788   EXIST:!VMS,!WIN16:FUNCTION:
+PEM_write_P8_PRIV_KEY_INFO              1788   EXIST:VMS:FUNCTION:
+PKCS5_PBE_keyivgen                      1789   EXIST::FUNCTION:
+i2d_PKCS8_bio                           1790   EXIST::FUNCTION:BIO
+i2d_PKCS8_PRIV_KEY_INFO_fp              1791   EXIST::FUNCTION:FP_API
+i2d_PKCS8_PRIV_KEY_INFO_bio             1792   EXIST::FUNCTION:BIO
+BIO_s_bio                               1793   EXIST::FUNCTION:
+PKCS5_pbe2_set                          1794   EXIST::FUNCTION:
+PKCS5_PBKDF2_HMAC_SHA1                  1795   EXIST::FUNCTION:
+PKCS5_v2_PBE_keyivgen                   1796   EXIST::FUNCTION:
+PEM_write_bio_PKCS8PrivateKey           1797   EXIST::FUNCTION:
+PEM_write_PKCS8PrivateKey               1798   EXIST::FUNCTION:
+BIO_ctrl_get_read_request               1799   EXIST::FUNCTION:
+BIO_ctrl_pending                        1800   EXIST::FUNCTION:
+BIO_ctrl_wpending                       1801   EXIST::FUNCTION:
+BIO_new_bio_pair                        1802   EXIST::FUNCTION:
+BIO_ctrl_get_write_guarantee            1803   EXIST::FUNCTION:
+CRYPTO_num_locks                        1804   EXIST::FUNCTION:
+CONF_load_bio                           1805   EXIST::FUNCTION:
+CONF_load_fp                            1806   EXIST::FUNCTION:FP_API
+i2d_ASN1_SET_OF_ASN1_OBJECT             1837   NOEXIST::FUNCTION:
+d2i_ASN1_SET_OF_ASN1_OBJECT             1844   NOEXIST::FUNCTION:
+PKCS7_signatureVerify                   1845   EXIST::FUNCTION:
+RSA_set_method                          1846   EXIST::FUNCTION:RSA
+RSA_get_method                          1847   EXIST::FUNCTION:RSA
+RSA_get_default_method                  1848   EXIST::FUNCTION:RSA
+RSA_check_key                           1869   EXIST::FUNCTION:RSA
+OBJ_obj2txt                             1870   EXIST::FUNCTION:
+DSA_dup_DH                              1871   EXIST::FUNCTION:DH,DSA
+X509_REQ_get_extensions                 1872   EXIST::FUNCTION:
+X509_REQ_set_extension_nids             1873   EXIST::FUNCTION:
+BIO_nwrite                              1874   EXIST::FUNCTION:
+X509_REQ_extension_nid                  1875   EXIST::FUNCTION:
+BIO_nread                               1876   EXIST::FUNCTION:
+X509_REQ_get_extension_nids             1877   EXIST::FUNCTION:
+BIO_nwrite0                             1878   EXIST::FUNCTION:
+X509_REQ_add_extensions_nid             1879   EXIST::FUNCTION:
+BIO_nread0                              1880   EXIST::FUNCTION:
+X509_REQ_add_extensions                 1881   EXIST::FUNCTION:
+BIO_new_mem_buf                         1882   EXIST::FUNCTION:
+DH_set_ex_data                          1883   EXIST::FUNCTION:DH
+DH_set_method                           1884   EXIST::FUNCTION:DH
+DSA_OpenSSL                             1885   EXIST::FUNCTION:DSA
+DH_get_ex_data                          1886   EXIST::FUNCTION:DH
+DH_get_ex_new_index                     1887   EXIST::FUNCTION:DH
+DSA_new_method                          1888   EXIST::FUNCTION:DSA
+DH_new_method                           1889   EXIST::FUNCTION:DH
+DH_OpenSSL                              1890   EXIST::FUNCTION:DH
+DSA_get_ex_new_index                    1891   EXIST::FUNCTION:DSA
+DH_get_default_method                   1892   EXIST::FUNCTION:DH
+DSA_set_ex_data                         1893   EXIST::FUNCTION:DSA
+DH_set_default_method                   1894   EXIST::FUNCTION:DH
+DSA_get_ex_data                         1895   EXIST::FUNCTION:DSA
+X509V3_EXT_REQ_add_conf                 1896   EXIST::FUNCTION:
+NETSCAPE_SPKI_print                     1897   EXIST::FUNCTION:EVP
+NETSCAPE_SPKI_set_pubkey                1898   EXIST::FUNCTION:EVP
+NETSCAPE_SPKI_b64_encode                1899   EXIST::FUNCTION:EVP
+NETSCAPE_SPKI_get_pubkey                1900   EXIST::FUNCTION:EVP
+NETSCAPE_SPKI_b64_decode                1901   EXIST::FUNCTION:EVP
+UTF8_putc                               1902   EXIST::FUNCTION:
+UTF8_getc                               1903   EXIST::FUNCTION:
+RSA_null_method                         1904   EXIST::FUNCTION:RSA
+ASN1_tag2str                            1905   EXIST::FUNCTION:
+BIO_ctrl_reset_read_request             1906   EXIST::FUNCTION:
+DISPLAYTEXT_new                         1907   EXIST::FUNCTION:
+ASN1_GENERALIZEDTIME_free               1908   EXIST::FUNCTION:
+X509_REVOKED_get_ext_d2i                1909   EXIST::FUNCTION:
+X509_set_ex_data                        1910   EXIST::FUNCTION:
+X509_reject_set_bit_asc                 1911   NOEXIST::FUNCTION:
+X509_NAME_add_entry_by_txt              1912   EXIST::FUNCTION:
+X509_NAME_add_entry_by_NID              1914   EXIST::FUNCTION:
+X509_PURPOSE_get0                       1915   EXIST::FUNCTION:
+PEM_read_X509_AUX                       1917   EXIST:!WIN16:FUNCTION:
+d2i_AUTHORITY_INFO_ACCESS               1918   EXIST::FUNCTION:
+PEM_write_PUBKEY                        1921   EXIST:!WIN16:FUNCTION:
+ACCESS_DESCRIPTION_new                  1925   EXIST::FUNCTION:
+X509_CERT_AUX_free                      1926   EXIST::FUNCTION:
+d2i_ACCESS_DESCRIPTION                  1927   EXIST::FUNCTION:
+X509_trust_clear                        1928   EXIST::FUNCTION:
+X509_TRUST_add                          1931   EXIST::FUNCTION:
+ASN1_VISIBLESTRING_new                  1932   EXIST::FUNCTION:
+X509_alias_set1                         1933   EXIST::FUNCTION:
+ASN1_PRINTABLESTRING_free               1934   EXIST::FUNCTION:
+EVP_PKEY_get1_DSA                       1935   EXIST::FUNCTION:DSA
+ASN1_BMPSTRING_new                      1936   EXIST::FUNCTION:
+ASN1_mbstring_copy                      1937   EXIST::FUNCTION:
+ASN1_UTF8STRING_new                     1938   EXIST::FUNCTION:
+DSA_get_default_method                  1941   EXIST::FUNCTION:DSA
+i2d_ASN1_SET_OF_ACCESS_DESCRIPTION      1945   NOEXIST::FUNCTION:
+ASN1_T61STRING_free                     1946   EXIST::FUNCTION:
+DSA_set_method                          1949   EXIST::FUNCTION:DSA
+X509_get_ex_data                        1950   EXIST::FUNCTION:
+ASN1_STRING_type                        1951   EXIST::FUNCTION:
+X509_PURPOSE_get_by_sname               1952   EXIST::FUNCTION:
+ASN1_TIME_free                          1954   EXIST::FUNCTION:
+ASN1_OCTET_STRING_cmp                   1955   EXIST::FUNCTION:
+ASN1_BIT_STRING_new                     1957   EXIST::FUNCTION:
+X509_get_ext_d2i                        1958   EXIST::FUNCTION:
+PEM_read_bio_X509_AUX                   1959   EXIST::FUNCTION:
+ASN1_STRING_set_default_mask_asc        1960   EXIST:!VMS:FUNCTION:
+ASN1_STRING_set_def_mask_asc            1960   EXIST:VMS:FUNCTION:
+PEM_write_bio_RSA_PUBKEY                1961   EXIST::FUNCTION:RSA
+ASN1_INTEGER_cmp                        1963   EXIST::FUNCTION:
+d2i_RSA_PUBKEY_fp                       1964   EXIST::FUNCTION:FP_API,RSA
+X509_trust_set_bit_asc                  1967   NOEXIST::FUNCTION:
+PEM_write_bio_DSA_PUBKEY                1968   EXIST::FUNCTION:DSA
+X509_STORE_CTX_free                     1969   EXIST::FUNCTION:
+EVP_PKEY_set1_DSA                       1970   EXIST::FUNCTION:DSA
+i2d_DSA_PUBKEY_fp                       1971   EXIST::FUNCTION:DSA,FP_API
+X509_load_cert_crl_file                 1972   EXIST::FUNCTION:STDIO
+ASN1_TIME_new                           1973   EXIST::FUNCTION:
+i2d_RSA_PUBKEY                          1974   EXIST::FUNCTION:RSA
+X509_STORE_CTX_purpose_inherit          1976   EXIST::FUNCTION:
+PEM_read_RSA_PUBKEY                     1977   EXIST:!WIN16:FUNCTION:RSA
+d2i_X509_AUX                            1980   EXIST::FUNCTION:
+i2d_DSA_PUBKEY                          1981   EXIST::FUNCTION:DSA
+X509_CERT_AUX_print                     1982   EXIST::FUNCTION:BIO
+PEM_read_DSA_PUBKEY                     1984   EXIST:!WIN16:FUNCTION:DSA
+i2d_RSA_PUBKEY_bio                      1985   EXIST::FUNCTION:BIO,RSA
+ASN1_BIT_STRING_num_asc                 1986   EXIST::FUNCTION:
+i2d_PUBKEY                              1987   EXIST::FUNCTION:
+ASN1_UTCTIME_free                       1988   EXIST::FUNCTION:
+DSA_set_default_method                  1989   EXIST::FUNCTION:DSA
+X509_PURPOSE_get_by_id                  1990   EXIST::FUNCTION:
+ACCESS_DESCRIPTION_free                 1994   EXIST::FUNCTION:
+PEM_read_bio_PUBKEY                     1995   EXIST::FUNCTION:
+ASN1_STRING_set_by_NID                  1996   EXIST::FUNCTION:
+X509_PURPOSE_get_id                     1997   EXIST::FUNCTION:
+DISPLAYTEXT_free                        1998   EXIST::FUNCTION:
+OTHERNAME_new                           1999   EXIST::FUNCTION:
+X509_CERT_AUX_new                       2001   EXIST::FUNCTION:
+X509_TRUST_cleanup                      2007   EXIST::FUNCTION:
+X509_NAME_add_entry_by_OBJ              2008   EXIST::FUNCTION:
+X509_CRL_get_ext_d2i                    2009   EXIST::FUNCTION:
+X509_PURPOSE_get0_name                  2011   EXIST::FUNCTION:
+PEM_read_PUBKEY                         2012   EXIST:!WIN16:FUNCTION:
+i2d_DSA_PUBKEY_bio                      2014   EXIST::FUNCTION:BIO,DSA
+i2d_OTHERNAME                           2015   EXIST::FUNCTION:
+ASN1_OCTET_STRING_free                  2016   EXIST::FUNCTION:
+ASN1_BIT_STRING_set_asc                 2017   EXIST::FUNCTION:
+X509_get_ex_new_index                   2019   EXIST::FUNCTION:
+ASN1_STRING_TABLE_cleanup               2020   EXIST::FUNCTION:
+X509_TRUST_get_by_id                    2021   EXIST::FUNCTION:
+X509_PURPOSE_get_trust                  2022   EXIST::FUNCTION:
+ASN1_STRING_length                      2023   EXIST::FUNCTION:
+d2i_ASN1_SET_OF_ACCESS_DESCRIPTION      2024   NOEXIST::FUNCTION:
+ASN1_PRINTABLESTRING_new                2025   EXIST::FUNCTION:
+X509V3_get_d2i                          2026   EXIST::FUNCTION:
+ASN1_ENUMERATED_free                    2027   EXIST::FUNCTION:
+i2d_X509_CERT_AUX                       2028   EXIST::FUNCTION:
+X509_STORE_CTX_set_trust                2030   EXIST::FUNCTION:
+ASN1_STRING_set_default_mask            2032   EXIST::FUNCTION:
+X509_STORE_CTX_new                      2033   EXIST::FUNCTION:
+EVP_PKEY_get1_RSA                       2034   EXIST::FUNCTION:RSA
+DIRECTORYSTRING_free                    2038   EXIST::FUNCTION:
+PEM_write_X509_AUX                      2039   EXIST:!WIN16:FUNCTION:
+ASN1_OCTET_STRING_set                   2040   EXIST::FUNCTION:
+d2i_DSA_PUBKEY_fp                       2041   EXIST::FUNCTION:DSA,FP_API
+d2i_RSA_PUBKEY                          2044   EXIST::FUNCTION:RSA
+X509_TRUST_get0_name                    2046   EXIST::FUNCTION:
+X509_TRUST_get0                         2047   EXIST::FUNCTION:
+AUTHORITY_INFO_ACCESS_free              2048   EXIST::FUNCTION:
+ASN1_IA5STRING_new                      2049   EXIST::FUNCTION:
+d2i_DSA_PUBKEY                          2050   EXIST::FUNCTION:DSA
+X509_check_purpose                      2051   EXIST::FUNCTION:
+ASN1_ENUMERATED_new                     2052   EXIST::FUNCTION:
+d2i_RSA_PUBKEY_bio                      2053   EXIST::FUNCTION:BIO,RSA
+d2i_PUBKEY                              2054   EXIST::FUNCTION:
+X509_TRUST_get_trust                    2055   EXIST::FUNCTION:
+X509_TRUST_get_flags                    2056   EXIST::FUNCTION:
+ASN1_BMPSTRING_free                     2057   EXIST::FUNCTION:
+ASN1_T61STRING_new                      2058   EXIST::FUNCTION:
+ASN1_UTCTIME_new                        2060   EXIST::FUNCTION:
+i2d_AUTHORITY_INFO_ACCESS               2062   EXIST::FUNCTION:
+EVP_PKEY_set1_RSA                       2063   EXIST::FUNCTION:RSA
+X509_STORE_CTX_set_purpose              2064   EXIST::FUNCTION:
+ASN1_IA5STRING_free                     2065   EXIST::FUNCTION:
+PEM_write_bio_X509_AUX                  2066   EXIST::FUNCTION:
+X509_PURPOSE_get_count                  2067   EXIST::FUNCTION:
+CRYPTO_add_info                         2068   NOEXIST::FUNCTION:
+X509_NAME_ENTRY_create_by_txt           2071   EXIST::FUNCTION:
+ASN1_STRING_get_default_mask            2072   EXIST::FUNCTION:
+X509_alias_get0                         2074   EXIST::FUNCTION:
+ASN1_STRING_data                        2075   EXIST::FUNCTION:
+i2d_ACCESS_DESCRIPTION                  2077   EXIST::FUNCTION:
+X509_trust_set_bit                      2078   NOEXIST::FUNCTION:
+ASN1_BIT_STRING_free                    2080   EXIST::FUNCTION:
+PEM_read_bio_RSA_PUBKEY                 2081   EXIST::FUNCTION:RSA
+X509_add1_reject_object                 2082   EXIST::FUNCTION:
+X509_check_trust                        2083   EXIST::FUNCTION:
+PEM_read_bio_DSA_PUBKEY                 2088   EXIST::FUNCTION:DSA
+X509_PURPOSE_add                        2090   EXIST::FUNCTION:
+ASN1_STRING_TABLE_get                   2091   EXIST::FUNCTION:
+ASN1_UTF8STRING_free                    2092   EXIST::FUNCTION:
+d2i_DSA_PUBKEY_bio                      2093   EXIST::FUNCTION:BIO,DSA
+PEM_write_RSA_PUBKEY                    2095   EXIST:!WIN16:FUNCTION:RSA
+d2i_OTHERNAME                           2096   EXIST::FUNCTION:
+X509_reject_set_bit                     2098   NOEXIST::FUNCTION:
+PEM_write_DSA_PUBKEY                    2101   EXIST:!WIN16:FUNCTION:DSA
+X509_PURPOSE_get0_sname                 2105   EXIST::FUNCTION:
+EVP_PKEY_set1_DH                        2107   EXIST::FUNCTION:DH
+ASN1_OCTET_STRING_dup                   2108   EXIST::FUNCTION:
+ASN1_BIT_STRING_set                     2109   EXIST::FUNCTION:
+X509_TRUST_get_count                    2110   EXIST::FUNCTION:
+ASN1_INTEGER_free                       2111   EXIST::FUNCTION:
+OTHERNAME_free                          2112   EXIST::FUNCTION:
+i2d_RSA_PUBKEY_fp                       2113   EXIST::FUNCTION:FP_API,RSA
+ASN1_INTEGER_dup                        2114   EXIST::FUNCTION:
+d2i_X509_CERT_AUX                       2115   EXIST::FUNCTION:
+PEM_write_bio_PUBKEY                    2117   EXIST::FUNCTION:
+ASN1_VISIBLESTRING_free                 2118   EXIST::FUNCTION:
+X509_PURPOSE_cleanup                    2119   EXIST::FUNCTION:
+ASN1_mbstring_ncopy                     2123   EXIST::FUNCTION:
+ASN1_GENERALIZEDTIME_new                2126   EXIST::FUNCTION:
+EVP_PKEY_get1_DH                        2128   EXIST::FUNCTION:DH
+ASN1_OCTET_STRING_new                   2130   EXIST::FUNCTION:
+ASN1_INTEGER_new                        2131   EXIST::FUNCTION:
+i2d_X509_AUX                            2132   EXIST::FUNCTION:
+ASN1_BIT_STRING_name_print              2134   EXIST::FUNCTION:BIO
+X509_cmp                                2135   EXIST::FUNCTION:
+ASN1_STRING_length_set                  2136   EXIST::FUNCTION:
+DIRECTORYSTRING_new                     2137   EXIST::FUNCTION:
+X509_add1_trust_object                  2140   EXIST::FUNCTION:
+PKCS12_newpass                          2141   EXIST::FUNCTION:
+SMIME_write_PKCS7                       2142   EXIST::FUNCTION:
+SMIME_read_PKCS7                        2143   EXIST::FUNCTION:
+DES_set_key_checked                     2144   EXIST::FUNCTION:DES
+PKCS7_verify                            2145   EXIST::FUNCTION:
+PKCS7_encrypt                           2146   EXIST::FUNCTION:
+DES_set_key_unchecked                   2147   EXIST::FUNCTION:DES
+SMIME_crlf_copy                         2148   EXIST::FUNCTION:
+i2d_ASN1_PRINTABLESTRING                2149   EXIST::FUNCTION:
+PKCS7_get0_signers                      2150   EXIST::FUNCTION:
+PKCS7_decrypt                           2151   EXIST::FUNCTION:
+SMIME_text                              2152   EXIST::FUNCTION:
+PKCS7_simple_smimecap                   2153   EXIST::FUNCTION:
+PKCS7_get_smimecap                      2154   EXIST::FUNCTION:
+PKCS7_sign                              2155   EXIST::FUNCTION:
+PKCS7_add_attrib_smimecap               2156   EXIST::FUNCTION:
+CRYPTO_dbg_set_options                  2157   EXIST::FUNCTION:
+CRYPTO_remove_all_info                  2158   EXIST::FUNCTION:
+CRYPTO_get_mem_debug_functions          2159   EXIST::FUNCTION:
+CRYPTO_is_mem_check_on                  2160   EXIST::FUNCTION:
+CRYPTO_set_mem_debug_functions          2161   EXIST::FUNCTION:
+CRYPTO_pop_info                         2162   EXIST::FUNCTION:
+CRYPTO_push_info_                       2163   EXIST::FUNCTION:
+CRYPTO_set_mem_debug_options            2164   EXIST::FUNCTION:
+PEM_write_PKCS8PrivateKey_nid           2165   EXIST::FUNCTION:
+PEM_write_bio_PKCS8PrivateKey_nid       2166   EXIST:!VMS:FUNCTION:
+PEM_write_bio_PKCS8PrivKey_nid          2166   EXIST:VMS:FUNCTION:
+d2i_PKCS8PrivateKey_bio                 2167   EXIST::FUNCTION:
+ASN1_NULL_free                          2168   EXIST::FUNCTION:
+d2i_ASN1_NULL                           2169   EXIST::FUNCTION:
+ASN1_NULL_new                           2170   EXIST::FUNCTION:
+i2d_PKCS8PrivateKey_bio                 2171   EXIST::FUNCTION:
+i2d_PKCS8PrivateKey_fp                  2172   EXIST::FUNCTION:
+i2d_ASN1_NULL                           2173   EXIST::FUNCTION:
+i2d_PKCS8PrivateKey_nid_fp              2174   EXIST::FUNCTION:
+d2i_PKCS8PrivateKey_fp                  2175   EXIST::FUNCTION:
+i2d_PKCS8PrivateKey_nid_bio             2176   EXIST::FUNCTION:
+i2d_PKCS8PrivateKeyInfo_fp              2177   EXIST::FUNCTION:FP_API
+i2d_PKCS8PrivateKeyInfo_bio             2178   EXIST::FUNCTION:BIO
+PEM_cb                                  2179   NOEXIST::FUNCTION:
+i2d_PrivateKey_fp                       2180   EXIST::FUNCTION:FP_API
+d2i_PrivateKey_bio                      2181   EXIST::FUNCTION:BIO
+d2i_PrivateKey_fp                       2182   EXIST::FUNCTION:FP_API
+i2d_PrivateKey_bio                      2183   EXIST::FUNCTION:BIO
+X509_reject_clear                       2184   EXIST::FUNCTION:
+X509_TRUST_set_default                  2185   EXIST::FUNCTION:
+d2i_AutoPrivateKey                      2186   EXIST::FUNCTION:
+X509_ATTRIBUTE_get0_type                2187   EXIST::FUNCTION:
+X509_ATTRIBUTE_set1_data                2188   EXIST::FUNCTION:
+X509at_get_attr                         2189   EXIST::FUNCTION:
+X509at_get_attr_count                   2190   EXIST::FUNCTION:
+X509_ATTRIBUTE_create_by_NID            2191   EXIST::FUNCTION:
+X509_ATTRIBUTE_set1_object              2192   EXIST::FUNCTION:
+X509_ATTRIBUTE_count                    2193   EXIST::FUNCTION:
+X509_ATTRIBUTE_create_by_OBJ            2194   EXIST::FUNCTION:
+X509_ATTRIBUTE_get0_object              2195   EXIST::FUNCTION:
+X509at_get_attr_by_NID                  2196   EXIST::FUNCTION:
+X509at_add1_attr                        2197   EXIST::FUNCTION:
+X509_ATTRIBUTE_get0_data                2198   EXIST::FUNCTION:
+X509at_delete_attr                      2199   EXIST::FUNCTION:
+X509at_get_attr_by_OBJ                  2200   EXIST::FUNCTION:
+RAND_add                                2201   EXIST::FUNCTION:
+BIO_number_written                      2202   EXIST::FUNCTION:
+BIO_number_read                         2203   EXIST::FUNCTION:
+X509_STORE_CTX_get1_chain               2204   EXIST::FUNCTION:
+ERR_load_RAND_strings                   2205   EXIST::FUNCTION:
+RAND_pseudo_bytes                       2206   EXIST::FUNCTION:
+X509_REQ_get_attr_by_NID                2207   EXIST::FUNCTION:
+X509_REQ_get_attr                       2208   EXIST::FUNCTION:
+X509_REQ_add1_attr_by_NID               2209   EXIST::FUNCTION:
+X509_REQ_get_attr_by_OBJ                2210   EXIST::FUNCTION:
+X509at_add1_attr_by_NID                 2211   EXIST::FUNCTION:
+X509_REQ_add1_attr_by_OBJ               2212   EXIST::FUNCTION:
+X509_REQ_get_attr_count                 2213   EXIST::FUNCTION:
+X509_REQ_add1_attr                      2214   EXIST::FUNCTION:
+X509_REQ_delete_attr                    2215   EXIST::FUNCTION:
+X509at_add1_attr_by_OBJ                 2216   EXIST::FUNCTION:
+X509_REQ_add1_attr_by_txt               2217   EXIST::FUNCTION:
+X509_ATTRIBUTE_create_by_txt            2218   EXIST::FUNCTION:
+X509at_add1_attr_by_txt                 2219   EXIST::FUNCTION:
+BN_pseudo_rand                          2239   EXIST::FUNCTION:
+BN_is_prime_fasttest                    2240   EXIST::FUNCTION:DEPRECATED
+BN_CTX_end                              2241   EXIST::FUNCTION:
+BN_CTX_start                            2242   EXIST::FUNCTION:
+BN_CTX_get                              2243   EXIST::FUNCTION:
+EVP_PKEY2PKCS8_broken                   2244   EXIST::FUNCTION:
+ASN1_STRING_TABLE_add                   2245   EXIST::FUNCTION:
+CRYPTO_dbg_get_options                  2246   EXIST::FUNCTION:
+AUTHORITY_INFO_ACCESS_new               2247   EXIST::FUNCTION:
+CRYPTO_get_mem_debug_options            2248   EXIST::FUNCTION:
+DES_crypt                               2249   EXIST::FUNCTION:DES
+PEM_write_bio_X509_REQ_NEW              2250   EXIST::FUNCTION:
+PEM_write_X509_REQ_NEW                  2251   EXIST:!WIN16:FUNCTION:
+BIO_callback_ctrl                       2252   EXIST::FUNCTION:
+RAND_egd                                2253   EXIST::FUNCTION:
+RAND_status                             2254   EXIST::FUNCTION:
+bn_dump1                                2255   NOEXIST::FUNCTION:
+DES_check_key_parity                    2256   EXIST::FUNCTION:DES
+lh_num_items                            2257   EXIST::FUNCTION:
+RAND_event                              2258   EXIST:WIN32:FUNCTION:
+DSO_new                                 2259   EXIST::FUNCTION:
+DSO_new_method                          2260   EXIST::FUNCTION:
+DSO_free                                2261   EXIST::FUNCTION:
+DSO_flags                               2262   EXIST::FUNCTION:
+DSO_up                                  2263   NOEXIST::FUNCTION:
+DSO_set_default_method                  2264   EXIST::FUNCTION:
+DSO_get_default_method                  2265   EXIST::FUNCTION:
+DSO_get_method                          2266   EXIST::FUNCTION:
+DSO_set_method                          2267   EXIST::FUNCTION:
+DSO_load                                2268   EXIST::FUNCTION:
+DSO_bind_var                            2269   EXIST::FUNCTION:
+DSO_METHOD_null                         2270   EXIST::FUNCTION:
+DSO_METHOD_openssl                      2271   EXIST::FUNCTION:
+DSO_METHOD_dlfcn                        2272   EXIST::FUNCTION:
+DSO_METHOD_win32                        2273   EXIST::FUNCTION:
+ERR_load_DSO_strings                    2274   EXIST::FUNCTION:
+DSO_METHOD_dl                           2275   EXIST::FUNCTION:
+NCONF_load                              2276   EXIST::FUNCTION:
+NCONF_load_fp                           2278   EXIST::FUNCTION:FP_API
+NCONF_new                               2279   EXIST::FUNCTION:
+NCONF_get_string                        2280   EXIST::FUNCTION:
+NCONF_free                              2281   EXIST::FUNCTION:
+NCONF_get_number                        2282   NOEXIST::FUNCTION:
+CONF_dump_fp                            2283   EXIST::FUNCTION:
+NCONF_load_bio                          2284   EXIST::FUNCTION:
+NCONF_dump_fp                           2285   EXIST::FUNCTION:
+NCONF_get_section                       2286   EXIST::FUNCTION:
+NCONF_dump_bio                          2287   EXIST::FUNCTION:
+CONF_dump_bio                           2288   EXIST::FUNCTION:
+NCONF_free_data                         2289   EXIST::FUNCTION:
+CONF_set_default_method                 2290   EXIST::FUNCTION:
+ERR_error_string_n                      2291   EXIST::FUNCTION:
+BIO_snprintf                            2292   EXIST::FUNCTION:
+DSO_ctrl                                2293   EXIST::FUNCTION:
+i2d_ASN1_SET_OF_ASN1_INTEGER            2317   NOEXIST::FUNCTION:
+i2d_ASN1_SET_OF_PKCS12_SAFEBAG          2320   NOEXIST::FUNCTION:
+i2d_ASN1_SET_OF_PKCS7                   2328   NOEXIST::FUNCTION:
+BIO_vfree                               2334   EXIST::FUNCTION:
+d2i_ASN1_SET_OF_ASN1_INTEGER            2339   NOEXIST::FUNCTION:
+d2i_ASN1_SET_OF_PKCS12_SAFEBAG          2341   NOEXIST::FUNCTION:
+ASN1_UTCTIME_get                        2350   NOEXIST::FUNCTION:
+X509_REQ_digest                         2362   EXIST::FUNCTION:EVP
+X509_CRL_digest                         2391   EXIST::FUNCTION:EVP
+d2i_ASN1_SET_OF_PKCS7                   2397   NOEXIST::FUNCTION:
+EVP_CIPHER_CTX_set_key_length           2399   EXIST::FUNCTION:
+EVP_CIPHER_CTX_ctrl                     2400   EXIST::FUNCTION:
+BN_mod_exp_mont_word                    2401   EXIST::FUNCTION:
+RAND_egd_bytes                          2402   EXIST::FUNCTION:
+X509_REQ_get1_email                     2403   EXIST::FUNCTION:
+X509_get1_email                         2404   EXIST::FUNCTION:
+X509_email_free                         2405   EXIST::FUNCTION:
+i2d_RSA_NET                             2406   EXIST::FUNCTION:RC4,RSA
+d2i_RSA_NET_2                           2407   NOEXIST::FUNCTION:
+d2i_RSA_NET                             2408   EXIST::FUNCTION:RC4,RSA
+DSO_bind_func                           2409   EXIST::FUNCTION:
+CRYPTO_get_new_dynlockid                2410   EXIST::FUNCTION:
+sk_new_null                             2411   EXIST::FUNCTION:
+CRYPTO_set_dynlock_destroy_callback     2412   EXIST:!VMS:FUNCTION:
+CRYPTO_set_dynlock_destroy_cb           2412   EXIST:VMS:FUNCTION:
+CRYPTO_destroy_dynlockid                2413   EXIST::FUNCTION:
+CRYPTO_set_dynlock_size                 2414   NOEXIST::FUNCTION:
+CRYPTO_set_dynlock_create_callback      2415   EXIST:!VMS:FUNCTION:
+CRYPTO_set_dynlock_create_cb            2415   EXIST:VMS:FUNCTION:
+CRYPTO_set_dynlock_lock_callback        2416   EXIST:!VMS:FUNCTION:
+CRYPTO_set_dynlock_lock_cb              2416   EXIST:VMS:FUNCTION:
+CRYPTO_get_dynlock_lock_callback        2417   EXIST:!VMS:FUNCTION:
+CRYPTO_get_dynlock_lock_cb              2417   EXIST:VMS:FUNCTION:
+CRYPTO_get_dynlock_destroy_callback     2418   EXIST:!VMS:FUNCTION:
+CRYPTO_get_dynlock_destroy_cb           2418   EXIST:VMS:FUNCTION:
+CRYPTO_get_dynlock_value                2419   EXIST::FUNCTION:
+CRYPTO_get_dynlock_create_callback      2420   EXIST:!VMS:FUNCTION:
+CRYPTO_get_dynlock_create_cb            2420   EXIST:VMS:FUNCTION:
+c2i_ASN1_BIT_STRING                     2421   EXIST::FUNCTION:
+i2c_ASN1_BIT_STRING                     2422   EXIST::FUNCTION:
+RAND_poll                               2423   EXIST::FUNCTION:
+c2i_ASN1_INTEGER                        2424   EXIST::FUNCTION:
+i2c_ASN1_INTEGER                        2425   EXIST::FUNCTION:
+BIO_dump_indent                         2426   EXIST::FUNCTION:
+ASN1_parse_dump                         2427   EXIST::FUNCTION:BIO
+c2i_ASN1_OBJECT                         2428   EXIST::FUNCTION:
+X509_NAME_print_ex_fp                   2429   EXIST::FUNCTION:FP_API
+ASN1_STRING_print_ex_fp                 2430   EXIST::FUNCTION:FP_API
+X509_NAME_print_ex                      2431   EXIST::FUNCTION:BIO
+ASN1_STRING_print_ex                    2432   EXIST::FUNCTION:BIO
+MD4                                     2433   EXIST::FUNCTION:MD4
+MD4_Transform                           2434   EXIST::FUNCTION:MD4
+MD4_Final                               2435   EXIST::FUNCTION:MD4
+MD4_Update                              2436   EXIST::FUNCTION:MD4
+MD4_Init                                2437   EXIST::FUNCTION:MD4
+EVP_md4                                 2438   EXIST::FUNCTION:MD4
+i2d_PUBKEY_bio                          2439   EXIST::FUNCTION:BIO
+i2d_PUBKEY_fp                           2440   EXIST::FUNCTION:FP_API
+d2i_PUBKEY_bio                          2441   EXIST::FUNCTION:BIO
+ASN1_STRING_to_UTF8                     2442   EXIST::FUNCTION:
+BIO_vprintf                             2443   EXIST::FUNCTION:
+BIO_vsnprintf                           2444   EXIST::FUNCTION:
+d2i_PUBKEY_fp                           2445   EXIST::FUNCTION:FP_API
+X509_cmp_time                           2446   EXIST::FUNCTION:
+X509_STORE_CTX_set_time                 2447   EXIST::FUNCTION:
+X509_STORE_CTX_get1_issuer              2448   EXIST::FUNCTION:
+X509_OBJECT_retrieve_match              2449   EXIST::FUNCTION:
+X509_OBJECT_idx_by_subject              2450   EXIST::FUNCTION:
+X509_STORE_CTX_set_flags                2451   EXIST::FUNCTION:
+X509_STORE_CTX_trusted_stack            2452   EXIST::FUNCTION:
+X509_time_adj                           2453   EXIST::FUNCTION:
+X509_check_issued                       2454   EXIST::FUNCTION:
+ASN1_UTCTIME_cmp_time_t                 2455   EXIST::FUNCTION:
+DES_set_weak_key_flag                   2456   NOEXIST::FUNCTION:
+DES_check_key                           2457   NOEXIST::FUNCTION:
+DES_rw_mode                             2458   NOEXIST::FUNCTION:
+RSA_PKCS1_RSAref                        2459   NOEXIST::FUNCTION:
+X509_keyid_set1                         2460   EXIST::FUNCTION:
+BIO_next                                2461   EXIST::FUNCTION:
+DSO_METHOD_vms                          2462   EXIST::FUNCTION:
+BIO_f_linebuffer                        2463   EXIST:VMS:FUNCTION:
+BN_bntest_rand                          2464   EXIST::FUNCTION:
+OPENSSL_issetugid                       2465   EXIST::FUNCTION:
+BN_rand_range                           2466   EXIST::FUNCTION:
+ERR_load_ENGINE_strings                 2467   EXIST::FUNCTION:ENGINE
+ENGINE_set_DSA                          2468   EXIST::FUNCTION:ENGINE
+ENGINE_get_finish_function              2469   EXIST::FUNCTION:ENGINE
+ENGINE_get_default_RSA                  2470   EXIST::FUNCTION:ENGINE
+ENGINE_get_BN_mod_exp                   2471   NOEXIST::FUNCTION:
+DSA_get_default_openssl_method          2472   NOEXIST::FUNCTION:
+ENGINE_set_DH                           2473   EXIST::FUNCTION:ENGINE
+ENGINE_set_def_BN_mod_exp_crt           2474   NOEXIST::FUNCTION:
+ENGINE_set_default_BN_mod_exp_crt       2474   NOEXIST::FUNCTION:
+ENGINE_init                             2475   EXIST::FUNCTION:ENGINE
+DH_get_default_openssl_method           2476   NOEXIST::FUNCTION:
+RSA_set_default_openssl_method          2477   NOEXIST::FUNCTION:
+ENGINE_finish                           2478   EXIST::FUNCTION:ENGINE
+ENGINE_load_public_key                  2479   EXIST::FUNCTION:ENGINE
+ENGINE_get_DH                           2480   EXIST::FUNCTION:ENGINE
+ENGINE_ctrl                             2481   EXIST::FUNCTION:ENGINE
+ENGINE_get_init_function                2482   EXIST::FUNCTION:ENGINE
+ENGINE_set_init_function                2483   EXIST::FUNCTION:ENGINE
+ENGINE_set_default_DSA                  2484   EXIST::FUNCTION:ENGINE
+ENGINE_get_name                         2485   EXIST::FUNCTION:ENGINE
+ENGINE_get_last                         2486   EXIST::FUNCTION:ENGINE
+ENGINE_get_prev                         2487   EXIST::FUNCTION:ENGINE
+ENGINE_get_default_DH                   2488   EXIST::FUNCTION:ENGINE
+ENGINE_get_RSA                          2489   EXIST::FUNCTION:ENGINE
+ENGINE_set_default                      2490   EXIST::FUNCTION:ENGINE
+ENGINE_get_RAND                         2491   EXIST::FUNCTION:ENGINE
+ENGINE_get_first                        2492   EXIST::FUNCTION:ENGINE
+ENGINE_by_id                            2493   EXIST::FUNCTION:ENGINE
+ENGINE_set_finish_function              2494   EXIST::FUNCTION:ENGINE
+ENGINE_get_def_BN_mod_exp_crt           2495   NOEXIST::FUNCTION:
+ENGINE_get_default_BN_mod_exp_crt       2495   NOEXIST::FUNCTION:
+RSA_get_default_openssl_method          2496   NOEXIST::FUNCTION:
+ENGINE_set_RSA                          2497   EXIST::FUNCTION:ENGINE
+ENGINE_load_private_key                 2498   EXIST::FUNCTION:ENGINE
+ENGINE_set_default_RAND                 2499   EXIST::FUNCTION:ENGINE
+ENGINE_set_BN_mod_exp                   2500   NOEXIST::FUNCTION:
+ENGINE_remove                           2501   EXIST::FUNCTION:ENGINE
+ENGINE_free                             2502   EXIST::FUNCTION:ENGINE
+ENGINE_get_BN_mod_exp_crt               2503   NOEXIST::FUNCTION:
+ENGINE_get_next                         2504   EXIST::FUNCTION:ENGINE
+ENGINE_set_name                         2505   EXIST::FUNCTION:ENGINE
+ENGINE_get_default_DSA                  2506   EXIST::FUNCTION:ENGINE
+ENGINE_set_default_BN_mod_exp           2507   NOEXIST::FUNCTION:
+ENGINE_set_default_RSA                  2508   EXIST::FUNCTION:ENGINE
+ENGINE_get_default_RAND                 2509   EXIST::FUNCTION:ENGINE
+ENGINE_get_default_BN_mod_exp           2510   NOEXIST::FUNCTION:
+ENGINE_set_RAND                         2511   EXIST::FUNCTION:ENGINE
+ENGINE_set_id                           2512   EXIST::FUNCTION:ENGINE
+ENGINE_set_BN_mod_exp_crt               2513   NOEXIST::FUNCTION:
+ENGINE_set_default_DH                   2514   EXIST::FUNCTION:ENGINE
+ENGINE_new                              2515   EXIST::FUNCTION:ENGINE
+ENGINE_get_id                           2516   EXIST::FUNCTION:ENGINE
+DSA_set_default_openssl_method          2517   NOEXIST::FUNCTION:
+ENGINE_add                              2518   EXIST::FUNCTION:ENGINE
+DH_set_default_openssl_method           2519   NOEXIST::FUNCTION:
+ENGINE_get_DSA                          2520   EXIST::FUNCTION:ENGINE
+ENGINE_get_ctrl_function                2521   EXIST::FUNCTION:ENGINE
+ENGINE_set_ctrl_function                2522   EXIST::FUNCTION:ENGINE
+BN_pseudo_rand_range                    2523   EXIST::FUNCTION:
+X509_STORE_CTX_set_verify_cb            2524   EXIST::FUNCTION:
+ERR_load_COMP_strings                   2525   EXIST::FUNCTION:
+PKCS12_item_decrypt_d2i                 2526   EXIST::FUNCTION:
+ASN1_UTF8STRING_it                      2527   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_UTF8STRING_it                      2527   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+ENGINE_unregister_ciphers               2528   EXIST::FUNCTION:ENGINE
+ENGINE_get_ciphers                      2529   EXIST::FUNCTION:ENGINE
+d2i_OCSP_BASICRESP                      2530   EXIST::FUNCTION:
+KRB5_CHECKSUM_it                        2531   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+KRB5_CHECKSUM_it                        2531   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+EC_POINT_add                            2532   EXIST::FUNCTION:EC
+ASN1_item_ex_i2d                        2533   EXIST::FUNCTION:
+OCSP_CERTID_it                          2534   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+OCSP_CERTID_it                          2534   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+d2i_OCSP_RESPBYTES                      2535   EXIST::FUNCTION:
+X509V3_add1_i2d                         2536   EXIST::FUNCTION:
+PKCS7_ENVELOPE_it                       2537   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PKCS7_ENVELOPE_it                       2537   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+UI_add_input_boolean                    2538   EXIST::FUNCTION:
+ENGINE_unregister_RSA                   2539   EXIST::FUNCTION:ENGINE
+X509V3_EXT_nconf                        2540   EXIST::FUNCTION:
+ASN1_GENERALSTRING_free                 2541   EXIST::FUNCTION:
+d2i_OCSP_CERTSTATUS                     2542   EXIST::FUNCTION:
+X509_REVOKED_set_serialNumber           2543   EXIST::FUNCTION:
+X509_print_ex                           2544   EXIST::FUNCTION:BIO
+OCSP_ONEREQ_get1_ext_d2i                2545   EXIST::FUNCTION:
+ENGINE_register_all_RAND                2546   EXIST::FUNCTION:ENGINE
+ENGINE_load_dynamic                     2547   EXIST::FUNCTION:ENGINE
+PBKDF2PARAM_it                          2548   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PBKDF2PARAM_it                          2548   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+EXTENDED_KEY_USAGE_new                  2549   EXIST::FUNCTION:
+EC_GROUP_clear_free                     2550   EXIST::FUNCTION:EC
+OCSP_sendreq_bio                        2551   EXIST::FUNCTION:
+ASN1_item_digest                        2552   EXIST::FUNCTION:EVP
+OCSP_BASICRESP_delete_ext               2553   EXIST::FUNCTION:
+OCSP_SIGNATURE_it                       2554   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+OCSP_SIGNATURE_it                       2554   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+X509_CRL_it                             2555   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+X509_CRL_it                             2555   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+OCSP_BASICRESP_add_ext                  2556   EXIST::FUNCTION:
+KRB5_ENCKEY_it                          2557   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+KRB5_ENCKEY_it                          2557   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+UI_method_set_closer                    2558   EXIST::FUNCTION:
+X509_STORE_set_purpose                  2559   EXIST::FUNCTION:
+i2d_ASN1_GENERALSTRING                  2560   EXIST::FUNCTION:
+OCSP_response_status                    2561   EXIST::FUNCTION:
+i2d_OCSP_SERVICELOC                     2562   EXIST::FUNCTION:
+ENGINE_get_digest_engine                2563   EXIST::FUNCTION:ENGINE
+EC_GROUP_set_curve_GFp                  2564   EXIST::FUNCTION:EC
+OCSP_REQUEST_get_ext_by_OBJ             2565   EXIST::FUNCTION:
+_ossl_old_des_random_key                2566   EXIST::FUNCTION:DES
+ASN1_T61STRING_it                       2567   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_T61STRING_it                       2567   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+EC_GROUP_method_of                      2568   EXIST::FUNCTION:EC
+i2d_KRB5_APREQ                          2569   EXIST::FUNCTION:
+_ossl_old_des_encrypt                   2570   EXIST::FUNCTION:DES
+ASN1_PRINTABLE_new                      2571   EXIST::FUNCTION:
+HMAC_Init_ex                            2572   EXIST::FUNCTION:HMAC
+d2i_KRB5_AUTHENT                        2573   EXIST::FUNCTION:
+OCSP_archive_cutoff_new                 2574   EXIST::FUNCTION:
+EC_POINT_set_Jprojective_coordinates_GFp 2575  EXIST:!VMS:FUNCTION:EC
+EC_POINT_set_Jproj_coords_GFp           2575   EXIST:VMS:FUNCTION:EC
+_ossl_old_des_is_weak_key               2576   EXIST::FUNCTION:DES
+OCSP_BASICRESP_get_ext_by_OBJ           2577   EXIST::FUNCTION:
+EC_POINT_oct2point                      2578   EXIST::FUNCTION:EC
+OCSP_SINGLERESP_get_ext_count           2579   EXIST::FUNCTION:
+UI_ctrl                                 2580   EXIST::FUNCTION:
+_shadow_DES_rw_mode                     2581   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:DES
+_shadow_DES_rw_mode                     2581   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:DES
+asn1_do_adb                             2582   EXIST::FUNCTION:
+ASN1_template_i2d                       2583   EXIST::FUNCTION:
+ENGINE_register_DH                      2584   EXIST::FUNCTION:ENGINE
+UI_construct_prompt                     2585   EXIST::FUNCTION:
+X509_STORE_set_trust                    2586   EXIST::FUNCTION:
+UI_dup_input_string                     2587   EXIST::FUNCTION:
+d2i_KRB5_APREQ                          2588   EXIST::FUNCTION:
+EVP_MD_CTX_copy_ex                      2589   EXIST::FUNCTION:
+OCSP_request_is_signed                  2590   EXIST::FUNCTION:
+i2d_OCSP_REQINFO                        2591   EXIST::FUNCTION:
+KRB5_ENCKEY_free                        2592   EXIST::FUNCTION:
+OCSP_resp_get0                          2593   EXIST::FUNCTION:
+GENERAL_NAME_it                         2594   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+GENERAL_NAME_it                         2594   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+ASN1_GENERALIZEDTIME_it                 2595   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_GENERALIZEDTIME_it                 2595   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+X509_STORE_set_flags                    2596   EXIST::FUNCTION:
+EC_POINT_set_compressed_coordinates_GFp 2597   EXIST:!VMS:FUNCTION:EC
+EC_POINT_set_compr_coords_GFp           2597   EXIST:VMS:FUNCTION:EC
+OCSP_response_status_str                2598   EXIST::FUNCTION:
+d2i_OCSP_REVOKEDINFO                    2599   EXIST::FUNCTION:
+OCSP_basic_add1_cert                    2600   EXIST::FUNCTION:
+ERR_get_implementation                  2601   EXIST::FUNCTION:
+EVP_CipherFinal_ex                      2602   EXIST::FUNCTION:
+OCSP_CERTSTATUS_new                     2603   EXIST::FUNCTION:
+CRYPTO_cleanup_all_ex_data              2604   EXIST::FUNCTION:
+OCSP_resp_find                          2605   EXIST::FUNCTION:
+BN_nnmod                                2606   EXIST::FUNCTION:
+X509_CRL_sort                           2607   EXIST::FUNCTION:
+X509_REVOKED_set_revocationDate         2608   EXIST::FUNCTION:
+ENGINE_register_RAND                    2609   EXIST::FUNCTION:ENGINE
+OCSP_SERVICELOC_new                     2610   EXIST::FUNCTION:
+EC_POINT_set_affine_coordinates_GFp     2611   EXIST:!VMS:FUNCTION:EC
+EC_POINT_set_affine_coords_GFp          2611   EXIST:VMS:FUNCTION:EC
+_ossl_old_des_options                   2612   EXIST::FUNCTION:DES
+SXNET_it                                2613   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+SXNET_it                                2613   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+UI_dup_input_boolean                    2614   EXIST::FUNCTION:
+PKCS12_add_CSPName_asc                  2615   EXIST::FUNCTION:
+EC_POINT_is_at_infinity                 2616   EXIST::FUNCTION:EC
+ENGINE_load_cryptodev                   2617   EXIST::FUNCTION:ENGINE
+DSO_convert_filename                    2618   EXIST::FUNCTION:
+POLICYQUALINFO_it                       2619   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+POLICYQUALINFO_it                       2619   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+ENGINE_register_ciphers                 2620   EXIST::FUNCTION:ENGINE
+BN_mod_lshift_quick                     2621   EXIST::FUNCTION:
+DSO_set_filename                        2622   EXIST::FUNCTION:
+ASN1_item_free                          2623   EXIST::FUNCTION:
+KRB5_TKTBODY_free                       2624   EXIST::FUNCTION:
+AUTHORITY_KEYID_it                      2625   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+AUTHORITY_KEYID_it                      2625   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+KRB5_APREQBODY_new                      2626   EXIST::FUNCTION:
+X509V3_EXT_REQ_add_nconf                2627   EXIST::FUNCTION:
+ENGINE_ctrl_cmd_string                  2628   EXIST::FUNCTION:ENGINE
+i2d_OCSP_RESPDATA                       2629   EXIST::FUNCTION:
+EVP_MD_CTX_init                         2630   EXIST::FUNCTION:
+EXTENDED_KEY_USAGE_free                 2631   EXIST::FUNCTION:
+PKCS7_ATTR_SIGN_it                      2632   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PKCS7_ATTR_SIGN_it                      2632   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+UI_add_error_string                     2633   EXIST::FUNCTION:
+KRB5_CHECKSUM_free                      2634   EXIST::FUNCTION:
+OCSP_REQUEST_get_ext                    2635   EXIST::FUNCTION:
+ENGINE_load_ubsec                       2636   EXIST::FUNCTION:ENGINE,STATIC_ENGINE
+ENGINE_register_all_digests             2637   EXIST::FUNCTION:ENGINE
+PKEY_USAGE_PERIOD_it                    2638   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PKEY_USAGE_PERIOD_it                    2638   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+PKCS12_unpack_authsafes                 2639   EXIST::FUNCTION:
+ASN1_item_unpack                        2640   EXIST::FUNCTION:
+NETSCAPE_SPKAC_it                       2641   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+NETSCAPE_SPKAC_it                       2641   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+X509_REVOKED_it                         2642   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+X509_REVOKED_it                         2642   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+ASN1_STRING_encode                      2643   NOEXIST::FUNCTION:
+EVP_aes_128_ecb                         2644   EXIST::FUNCTION:AES
+KRB5_AUTHENT_free                       2645   EXIST::FUNCTION:
+OCSP_BASICRESP_get_ext_by_critical      2646   EXIST:!VMS:FUNCTION:
+OCSP_BASICRESP_get_ext_by_crit          2646   EXIST:VMS:FUNCTION:
+OCSP_cert_status_str                    2647   EXIST::FUNCTION:
+d2i_OCSP_REQUEST                        2648   EXIST::FUNCTION:
+UI_dup_info_string                      2649   EXIST::FUNCTION:
+_ossl_old_des_xwhite_in2out             2650   NOEXIST::FUNCTION:
+PKCS12_it                               2651   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PKCS12_it                               2651   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+OCSP_SINGLERESP_get_ext_by_critical     2652   EXIST:!VMS:FUNCTION:
+OCSP_SINGLERESP_get_ext_by_crit         2652   EXIST:VMS:FUNCTION:
+OCSP_CERTSTATUS_free                    2653   EXIST::FUNCTION:
+_ossl_old_des_crypt                     2654   EXIST::FUNCTION:DES
+ASN1_item_i2d                           2655   EXIST::FUNCTION:
+EVP_DecryptFinal_ex                     2656   EXIST::FUNCTION:
+ENGINE_load_openssl                     2657   EXIST::FUNCTION:ENGINE
+ENGINE_get_cmd_defns                    2658   EXIST::FUNCTION:ENGINE
+ENGINE_set_load_privkey_function        2659   EXIST:!VMS:FUNCTION:ENGINE
+ENGINE_set_load_privkey_fn              2659   EXIST:VMS:FUNCTION:ENGINE
+EVP_EncryptFinal_ex                     2660   EXIST::FUNCTION:
+ENGINE_set_default_digests              2661   EXIST::FUNCTION:ENGINE
+X509_get0_pubkey_bitstr                 2662   EXIST::FUNCTION:
+asn1_ex_i2c                             2663   EXIST::FUNCTION:
+ENGINE_register_RSA                     2664   EXIST::FUNCTION:ENGINE
+ENGINE_unregister_DSA                   2665   EXIST::FUNCTION:ENGINE
+_ossl_old_des_key_sched                 2666   EXIST::FUNCTION:DES
+X509_EXTENSION_it                       2667   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+X509_EXTENSION_it                       2667   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+i2d_KRB5_AUTHENT                        2668   EXIST::FUNCTION:
+SXNETID_it                              2669   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+SXNETID_it                              2669   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+d2i_OCSP_SINGLERESP                     2670   EXIST::FUNCTION:
+EDIPARTYNAME_new                        2671   EXIST::FUNCTION:
+PKCS12_certbag2x509                     2672   EXIST::FUNCTION:
+_ossl_old_des_ofb64_encrypt             2673   EXIST::FUNCTION:DES
+d2i_EXTENDED_KEY_USAGE                  2674   EXIST::FUNCTION:
+ERR_print_errors_cb                     2675   EXIST::FUNCTION:
+ENGINE_set_ciphers                      2676   EXIST::FUNCTION:ENGINE
+d2i_KRB5_APREQBODY                      2677   EXIST::FUNCTION:
+UI_method_get_flusher                   2678   EXIST::FUNCTION:
+X509_PUBKEY_it                          2679   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+X509_PUBKEY_it                          2679   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+_ossl_old_des_enc_read                  2680   EXIST::FUNCTION:DES
+PKCS7_ENCRYPT_it                        2681   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PKCS7_ENCRYPT_it                        2681   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+i2d_OCSP_RESPONSE                       2682   EXIST::FUNCTION:
+EC_GROUP_get_cofactor                   2683   EXIST::FUNCTION:EC
+PKCS12_unpack_p7data                    2684   EXIST::FUNCTION:
+d2i_KRB5_AUTHDATA                       2685   EXIST::FUNCTION:
+OCSP_copy_nonce                         2686   EXIST::FUNCTION:
+KRB5_AUTHDATA_new                       2687   EXIST::FUNCTION:
+OCSP_RESPDATA_new                       2688   EXIST::FUNCTION:
+EC_GFp_mont_method                      2689   EXIST::FUNCTION:EC
+OCSP_REVOKEDINFO_free                   2690   EXIST::FUNCTION:
+UI_get_ex_data                          2691   EXIST::FUNCTION:
+KRB5_APREQBODY_free                     2692   EXIST::FUNCTION:
+EC_GROUP_get0_generator                 2693   EXIST::FUNCTION:EC
+UI_get_default_method                   2694   EXIST::FUNCTION:
+X509V3_set_nconf                        2695   EXIST::FUNCTION:
+PKCS12_item_i2d_encrypt                 2696   EXIST::FUNCTION:
+X509_add1_ext_i2d                       2697   EXIST::FUNCTION:
+PKCS7_SIGNER_INFO_it                    2698   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PKCS7_SIGNER_INFO_it                    2698   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+KRB5_PRINCNAME_new                      2699   EXIST::FUNCTION:
+PKCS12_SAFEBAG_it                       2700   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PKCS12_SAFEBAG_it                       2700   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+EC_GROUP_get_order                      2701   EXIST::FUNCTION:EC
+d2i_OCSP_RESPID                         2702   EXIST::FUNCTION:
+OCSP_request_verify                     2703   EXIST::FUNCTION:
+NCONF_get_number_e                      2704   EXIST::FUNCTION:
+_ossl_old_des_decrypt3                  2705   EXIST::FUNCTION:DES
+X509_signature_print                    2706   EXIST::FUNCTION:EVP
+OCSP_SINGLERESP_free                    2707   EXIST::FUNCTION:
+ENGINE_load_builtin_engines             2708   EXIST::FUNCTION:ENGINE
+i2d_OCSP_ONEREQ                         2709   EXIST::FUNCTION:
+OCSP_REQUEST_add_ext                    2710   EXIST::FUNCTION:
+OCSP_RESPBYTES_new                      2711   EXIST::FUNCTION:
+EVP_MD_CTX_create                       2712   EXIST::FUNCTION:
+OCSP_resp_find_status                   2713   EXIST::FUNCTION:
+X509_ALGOR_it                           2714   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+X509_ALGOR_it                           2714   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+ASN1_TIME_it                            2715   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_TIME_it                            2715   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+OCSP_request_set1_name                  2716   EXIST::FUNCTION:
+OCSP_ONEREQ_get_ext_count               2717   EXIST::FUNCTION:
+UI_get0_result                          2718   EXIST::FUNCTION:
+PKCS12_AUTHSAFES_it                     2719   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PKCS12_AUTHSAFES_it                     2719   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+EVP_aes_256_ecb                         2720   EXIST::FUNCTION:AES
+PKCS12_pack_authsafes                   2721   EXIST::FUNCTION:
+ASN1_IA5STRING_it                       2722   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_IA5STRING_it                       2722   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+UI_get_input_flags                      2723   EXIST::FUNCTION:
+EC_GROUP_set_generator                  2724   EXIST::FUNCTION:EC
+_ossl_old_des_string_to_2keys           2725   EXIST::FUNCTION:DES
+OCSP_CERTID_free                        2726   EXIST::FUNCTION:
+X509_CERT_AUX_it                        2727   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+X509_CERT_AUX_it                        2727   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+CERTIFICATEPOLICIES_it                  2728   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+CERTIFICATEPOLICIES_it                  2728   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+_ossl_old_des_ede3_cbc_encrypt          2729   EXIST::FUNCTION:DES
+RAND_set_rand_engine                    2730   EXIST::FUNCTION:ENGINE
+DSO_get_loaded_filename                 2731   EXIST::FUNCTION:
+X509_ATTRIBUTE_it                       2732   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+X509_ATTRIBUTE_it                       2732   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+OCSP_ONEREQ_get_ext_by_NID              2733   EXIST::FUNCTION:
+PKCS12_decrypt_skey                     2734   EXIST::FUNCTION:
+KRB5_AUTHENT_it                         2735   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+KRB5_AUTHENT_it                         2735   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+UI_dup_error_string                     2736   EXIST::FUNCTION:
+RSAPublicKey_it                         2737   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:RSA
+RSAPublicKey_it                         2737   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:RSA
+i2d_OCSP_REQUEST                        2738   EXIST::FUNCTION:
+PKCS12_x509crl2certbag                  2739   EXIST::FUNCTION:
+OCSP_SERVICELOC_it                      2740   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+OCSP_SERVICELOC_it                      2740   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+ASN1_item_sign                          2741   EXIST::FUNCTION:EVP
+X509_CRL_set_issuer_name                2742   EXIST::FUNCTION:
+OBJ_NAME_do_all_sorted                  2743   EXIST::FUNCTION:
+i2d_OCSP_BASICRESP                      2744   EXIST::FUNCTION:
+i2d_OCSP_RESPBYTES                      2745   EXIST::FUNCTION:
+PKCS12_unpack_p7encdata                 2746   EXIST::FUNCTION:
+HMAC_CTX_init                           2747   EXIST::FUNCTION:HMAC
+ENGINE_get_digest                       2748   EXIST::FUNCTION:ENGINE
+OCSP_RESPONSE_print                     2749   EXIST::FUNCTION:
+KRB5_TKTBODY_it                         2750   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+KRB5_TKTBODY_it                         2750   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+ACCESS_DESCRIPTION_it                   2751   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ACCESS_DESCRIPTION_it                   2751   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+PKCS7_ISSUER_AND_SERIAL_it              2752   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PKCS7_ISSUER_AND_SERIAL_it              2752   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+PBE2PARAM_it                            2753   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PBE2PARAM_it                            2753   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+PKCS12_certbag2x509crl                  2754   EXIST::FUNCTION:
+PKCS7_SIGNED_it                         2755   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PKCS7_SIGNED_it                         2755   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+ENGINE_get_cipher                       2756   EXIST::FUNCTION:ENGINE
+i2d_OCSP_CRLID                          2757   EXIST::FUNCTION:
+OCSP_SINGLERESP_new                     2758   EXIST::FUNCTION:
+ENGINE_cmd_is_executable                2759   EXIST::FUNCTION:ENGINE
+RSA_up_ref                              2760   EXIST::FUNCTION:RSA
+ASN1_GENERALSTRING_it                   2761   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_GENERALSTRING_it                   2761   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+ENGINE_register_DSA                     2762   EXIST::FUNCTION:ENGINE
+X509V3_EXT_add_nconf_sk                 2763   EXIST::FUNCTION:
+ENGINE_set_load_pubkey_function         2764   EXIST::FUNCTION:ENGINE
+PKCS8_decrypt                           2765   EXIST::FUNCTION:
+PEM_bytes_read_bio                      2766   EXIST::FUNCTION:BIO
+DIRECTORYSTRING_it                      2767   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+DIRECTORYSTRING_it                      2767   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+d2i_OCSP_CRLID                          2768   EXIST::FUNCTION:
+EC_POINT_is_on_curve                    2769   EXIST::FUNCTION:EC
+CRYPTO_set_locked_mem_ex_functions      2770   EXIST:!VMS:FUNCTION:
+CRYPTO_set_locked_mem_ex_funcs          2770   EXIST:VMS:FUNCTION:
+d2i_KRB5_CHECKSUM                       2771   EXIST::FUNCTION:
+ASN1_item_dup                           2772   EXIST::FUNCTION:
+X509_it                                 2773   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+X509_it                                 2773   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+BN_mod_add                              2774   EXIST::FUNCTION:
+KRB5_AUTHDATA_free                      2775   EXIST::FUNCTION:
+_ossl_old_des_cbc_cksum                 2776   EXIST::FUNCTION:DES
+ASN1_item_verify                        2777   EXIST::FUNCTION:EVP
+CRYPTO_set_mem_ex_functions             2778   EXIST::FUNCTION:
+EC_POINT_get_Jprojective_coordinates_GFp 2779  EXIST:!VMS:FUNCTION:EC
+EC_POINT_get_Jproj_coords_GFp           2779   EXIST:VMS:FUNCTION:EC
+ZLONG_it                                2780   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ZLONG_it                                2780   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+CRYPTO_get_locked_mem_ex_functions      2781   EXIST:!VMS:FUNCTION:
+CRYPTO_get_locked_mem_ex_funcs          2781   EXIST:VMS:FUNCTION:
+ASN1_TIME_check                         2782   EXIST::FUNCTION:
+UI_get0_user_data                       2783   EXIST::FUNCTION:
+HMAC_CTX_cleanup                        2784   EXIST::FUNCTION:HMAC
+DSA_up_ref                              2785   EXIST::FUNCTION:DSA
+_ossl_old_des_ede3_cfb64_encrypt        2786   EXIST:!VMS:FUNCTION:DES
+_ossl_odes_ede3_cfb64_encrypt           2786   EXIST:VMS:FUNCTION:DES
+ASN1_BMPSTRING_it                       2787   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_BMPSTRING_it                       2787   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+ASN1_tag2bit                            2788   EXIST::FUNCTION:
+UI_method_set_flusher                   2789   EXIST::FUNCTION:
+X509_ocspid_print                       2790   EXIST::FUNCTION:BIO
+KRB5_ENCDATA_it                         2791   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+KRB5_ENCDATA_it                         2791   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+ENGINE_get_load_pubkey_function         2792   EXIST::FUNCTION:ENGINE
+UI_add_user_data                        2793   EXIST::FUNCTION:
+OCSP_REQUEST_delete_ext                 2794   EXIST::FUNCTION:
+UI_get_method                           2795   EXIST::FUNCTION:
+OCSP_ONEREQ_free                        2796   EXIST::FUNCTION:
+ASN1_PRINTABLESTRING_it                 2797   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_PRINTABLESTRING_it                 2797   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+X509_CRL_set_nextUpdate                 2798   EXIST::FUNCTION:
+OCSP_REQUEST_it                         2799   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+OCSP_REQUEST_it                         2799   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+OCSP_BASICRESP_it                       2800   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+OCSP_BASICRESP_it                       2800   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+AES_ecb_encrypt                         2801   EXIST::FUNCTION:AES
+BN_mod_sqr                              2802   EXIST::FUNCTION:
+NETSCAPE_CERT_SEQUENCE_it               2803   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+NETSCAPE_CERT_SEQUENCE_it               2803   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+GENERAL_NAMES_it                        2804   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+GENERAL_NAMES_it                        2804   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+AUTHORITY_INFO_ACCESS_it                2805   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+AUTHORITY_INFO_ACCESS_it                2805   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+ASN1_FBOOLEAN_it                        2806   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_FBOOLEAN_it                        2806   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+UI_set_ex_data                          2807   EXIST::FUNCTION:
+_ossl_old_des_string_to_key             2808   EXIST::FUNCTION:DES
+ENGINE_register_all_RSA                 2809   EXIST::FUNCTION:ENGINE
+d2i_KRB5_PRINCNAME                      2810   EXIST::FUNCTION:
+OCSP_RESPBYTES_it                       2811   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+OCSP_RESPBYTES_it                       2811   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+X509_CINF_it                            2812   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+X509_CINF_it                            2812   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+ENGINE_unregister_digests               2813   EXIST::FUNCTION:ENGINE
+d2i_EDIPARTYNAME                        2814   EXIST::FUNCTION:
+d2i_OCSP_SERVICELOC                     2815   EXIST::FUNCTION:
+ENGINE_get_digests                      2816   EXIST::FUNCTION:ENGINE
+_ossl_old_des_set_odd_parity            2817   EXIST::FUNCTION:DES
+OCSP_RESPDATA_free                      2818   EXIST::FUNCTION:
+d2i_KRB5_TICKET                         2819   EXIST::FUNCTION:
+OTHERNAME_it                            2820   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+OTHERNAME_it                            2820   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+EVP_MD_CTX_cleanup                      2821   EXIST::FUNCTION:
+d2i_ASN1_GENERALSTRING                  2822   EXIST::FUNCTION:
+X509_CRL_set_version                    2823   EXIST::FUNCTION:
+BN_mod_sub                              2824   EXIST::FUNCTION:
+OCSP_SINGLERESP_get_ext_by_NID          2825   EXIST::FUNCTION:
+ENGINE_get_ex_new_index                 2826   EXIST::FUNCTION:ENGINE
+OCSP_REQUEST_free                       2827   EXIST::FUNCTION:
+OCSP_REQUEST_add1_ext_i2d               2828   EXIST::FUNCTION:
+X509_VAL_it                             2829   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+X509_VAL_it                             2829   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+EC_POINTs_make_affine                   2830   EXIST::FUNCTION:EC
+EC_POINT_mul                            2831   EXIST::FUNCTION:EC
+X509V3_EXT_add_nconf                    2832   EXIST::FUNCTION:
+X509_TRUST_set                          2833   EXIST::FUNCTION:
+X509_CRL_add1_ext_i2d                   2834   EXIST::FUNCTION:
+_ossl_old_des_fcrypt                    2835   EXIST::FUNCTION:DES
+DISPLAYTEXT_it                          2836   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+DISPLAYTEXT_it                          2836   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+X509_CRL_set_lastUpdate                 2837   EXIST::FUNCTION:
+OCSP_BASICRESP_free                     2838   EXIST::FUNCTION:
+OCSP_BASICRESP_add1_ext_i2d             2839   EXIST::FUNCTION:
+d2i_KRB5_AUTHENTBODY                    2840   EXIST::FUNCTION:
+CRYPTO_set_ex_data_implementation       2841   EXIST:!VMS:FUNCTION:
+CRYPTO_set_ex_data_impl                 2841   EXIST:VMS:FUNCTION:
+KRB5_ENCDATA_new                        2842   EXIST::FUNCTION:
+DSO_up_ref                              2843   EXIST::FUNCTION:
+OCSP_crl_reason_str                     2844   EXIST::FUNCTION:
+UI_get0_result_string                   2845   EXIST::FUNCTION:
+ASN1_GENERALSTRING_new                  2846   EXIST::FUNCTION:
+X509_SIG_it                             2847   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+X509_SIG_it                             2847   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+ERR_set_implementation                  2848   EXIST::FUNCTION:
+ERR_load_EC_strings                     2849   EXIST::FUNCTION:EC
+UI_get0_action_string                   2850   EXIST::FUNCTION:
+OCSP_ONEREQ_get_ext                     2851   EXIST::FUNCTION:
+EC_POINT_method_of                      2852   EXIST::FUNCTION:EC
+i2d_KRB5_APREQBODY                      2853   EXIST::FUNCTION:
+_ossl_old_des_ecb3_encrypt              2854   EXIST::FUNCTION:DES
+CRYPTO_get_mem_ex_functions             2855   EXIST::FUNCTION:
+ENGINE_get_ex_data                      2856   EXIST::FUNCTION:ENGINE
+UI_destroy_method                       2857   EXIST::FUNCTION:
+ASN1_item_i2d_bio                       2858   EXIST::FUNCTION:BIO
+OCSP_ONEREQ_get_ext_by_OBJ              2859   EXIST::FUNCTION:
+ASN1_primitive_new                      2860   EXIST::FUNCTION:
+ASN1_PRINTABLE_it                       2861   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_PRINTABLE_it                       2861   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+EVP_aes_192_ecb                         2862   EXIST::FUNCTION:AES
+OCSP_SIGNATURE_new                      2863   EXIST::FUNCTION:
+LONG_it                                 2864   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+LONG_it                                 2864   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+ASN1_VISIBLESTRING_it                   2865   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_VISIBLESTRING_it                   2865   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+OCSP_SINGLERESP_add1_ext_i2d            2866   EXIST::FUNCTION:
+d2i_OCSP_CERTID                         2867   EXIST::FUNCTION:
+ASN1_item_d2i_fp                        2868   EXIST::FUNCTION:FP_API
+CRL_DIST_POINTS_it                      2869   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+CRL_DIST_POINTS_it                      2869   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+GENERAL_NAME_print                      2870   EXIST::FUNCTION:
+OCSP_SINGLERESP_delete_ext              2871   EXIST::FUNCTION:
+PKCS12_SAFEBAGS_it                      2872   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PKCS12_SAFEBAGS_it                      2872   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+d2i_OCSP_SIGNATURE                      2873   EXIST::FUNCTION:
+OCSP_request_add1_nonce                 2874   EXIST::FUNCTION:
+ENGINE_set_cmd_defns                    2875   EXIST::FUNCTION:ENGINE
+OCSP_SERVICELOC_free                    2876   EXIST::FUNCTION:
+EC_GROUP_free                           2877   EXIST::FUNCTION:EC
+ASN1_BIT_STRING_it                      2878   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_BIT_STRING_it                      2878   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+X509_REQ_it                             2879   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+X509_REQ_it                             2879   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+_ossl_old_des_cbc_encrypt               2880   EXIST::FUNCTION:DES
+ERR_unload_strings                      2881   EXIST::FUNCTION:
+PKCS7_SIGN_ENVELOPE_it                  2882   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PKCS7_SIGN_ENVELOPE_it                  2882   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+EDIPARTYNAME_free                       2883   EXIST::FUNCTION:
+OCSP_REQINFO_free                       2884   EXIST::FUNCTION:
+EC_GROUP_new_curve_GFp                  2885   EXIST::FUNCTION:EC
+OCSP_REQUEST_get1_ext_d2i               2886   EXIST::FUNCTION:
+PKCS12_item_pack_safebag                2887   EXIST::FUNCTION:
+asn1_ex_c2i                             2888   EXIST::FUNCTION:
+ENGINE_register_digests                 2889   EXIST::FUNCTION:ENGINE
+i2d_OCSP_REVOKEDINFO                    2890   EXIST::FUNCTION:
+asn1_enc_restore                        2891   EXIST::FUNCTION:
+UI_free                                 2892   EXIST::FUNCTION:
+UI_new_method                           2893   EXIST::FUNCTION:
+EVP_EncryptInit_ex                      2894   EXIST::FUNCTION:
+X509_pubkey_digest                      2895   EXIST::FUNCTION:EVP
+EC_POINT_invert                         2896   EXIST::FUNCTION:EC
+OCSP_basic_sign                         2897   EXIST::FUNCTION:
+i2d_OCSP_RESPID                         2898   EXIST::FUNCTION:
+OCSP_check_nonce                        2899   EXIST::FUNCTION:
+ENGINE_ctrl_cmd                         2900   EXIST::FUNCTION:ENGINE
+d2i_KRB5_ENCKEY                         2901   EXIST::FUNCTION:
+OCSP_parse_url                          2902   EXIST::FUNCTION:
+OCSP_SINGLERESP_get_ext                 2903   EXIST::FUNCTION:
+OCSP_CRLID_free                         2904   EXIST::FUNCTION:
+OCSP_BASICRESP_get1_ext_d2i             2905   EXIST::FUNCTION:
+RSAPrivateKey_it                        2906   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:RSA
+RSAPrivateKey_it                        2906   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:RSA
+ENGINE_register_all_DH                  2907   EXIST::FUNCTION:ENGINE
+i2d_EDIPARTYNAME                        2908   EXIST::FUNCTION:
+EC_POINT_get_affine_coordinates_GFp     2909   EXIST:!VMS:FUNCTION:EC
+EC_POINT_get_affine_coords_GFp          2909   EXIST:VMS:FUNCTION:EC
+OCSP_CRLID_new                          2910   EXIST::FUNCTION:
+ENGINE_get_flags                        2911   EXIST::FUNCTION:ENGINE
+OCSP_ONEREQ_it                          2912   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+OCSP_ONEREQ_it                          2912   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+UI_process                              2913   EXIST::FUNCTION:
+ASN1_INTEGER_it                         2914   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_INTEGER_it                         2914   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+EVP_CipherInit_ex                       2915   EXIST::FUNCTION:
+UI_get_string_type                      2916   EXIST::FUNCTION:
+ENGINE_unregister_DH                    2917   EXIST::FUNCTION:ENGINE
+ENGINE_register_all_DSA                 2918   EXIST::FUNCTION:ENGINE
+OCSP_ONEREQ_get_ext_by_critical         2919   EXIST::FUNCTION:
+bn_dup_expand                           2920   EXIST::FUNCTION:DEPRECATED
+OCSP_cert_id_new                        2921   EXIST::FUNCTION:
+BASIC_CONSTRAINTS_it                    2922   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+BASIC_CONSTRAINTS_it                    2922   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+BN_mod_add_quick                        2923   EXIST::FUNCTION:
+EC_POINT_new                            2924   EXIST::FUNCTION:EC
+EVP_MD_CTX_destroy                      2925   EXIST::FUNCTION:
+OCSP_RESPBYTES_free                     2926   EXIST::FUNCTION:
+EVP_aes_128_cbc                         2927   EXIST::FUNCTION:AES
+OCSP_SINGLERESP_get1_ext_d2i            2928   EXIST::FUNCTION:
+EC_POINT_free                           2929   EXIST::FUNCTION:EC
+DH_up_ref                               2930   EXIST::FUNCTION:DH
+X509_NAME_ENTRY_it                      2931   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+X509_NAME_ENTRY_it                      2931   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+UI_get_ex_new_index                     2932   EXIST::FUNCTION:
+BN_mod_sub_quick                        2933   EXIST::FUNCTION:
+OCSP_ONEREQ_add_ext                     2934   EXIST::FUNCTION:
+OCSP_request_sign                       2935   EXIST::FUNCTION:
+EVP_DigestFinal_ex                      2936   EXIST::FUNCTION:
+ENGINE_set_digests                      2937   EXIST::FUNCTION:ENGINE
+OCSP_id_issuer_cmp                      2938   EXIST::FUNCTION:
+OBJ_NAME_do_all                         2939   EXIST::FUNCTION:
+EC_POINTs_mul                           2940   EXIST::FUNCTION:EC
+ENGINE_register_complete                2941   EXIST::FUNCTION:ENGINE
+X509V3_EXT_nconf_nid                    2942   EXIST::FUNCTION:
+ASN1_SEQUENCE_it                        2943   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_SEQUENCE_it                        2943   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+UI_set_default_method                   2944   EXIST::FUNCTION:
+RAND_query_egd_bytes                    2945   EXIST::FUNCTION:
+UI_method_get_writer                    2946   EXIST::FUNCTION:
+UI_OpenSSL                              2947   EXIST::FUNCTION:
+PEM_def_callback                        2948   EXIST::FUNCTION:
+ENGINE_cleanup                          2949   EXIST::FUNCTION:ENGINE
+DIST_POINT_it                           2950   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+DIST_POINT_it                           2950   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+OCSP_SINGLERESP_it                      2951   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+OCSP_SINGLERESP_it                      2951   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+d2i_KRB5_TKTBODY                        2952   EXIST::FUNCTION:
+EC_POINT_cmp                            2953   EXIST::FUNCTION:EC
+OCSP_REVOKEDINFO_new                    2954   EXIST::FUNCTION:
+i2d_OCSP_CERTSTATUS                     2955   EXIST::FUNCTION:
+OCSP_basic_add1_nonce                   2956   EXIST::FUNCTION:
+ASN1_item_ex_d2i                        2957   EXIST::FUNCTION:
+BN_mod_lshift1_quick                    2958   EXIST::FUNCTION:
+UI_set_method                           2959   EXIST::FUNCTION:
+OCSP_id_get0_info                       2960   EXIST::FUNCTION:
+BN_mod_sqrt                             2961   EXIST::FUNCTION:
+EC_GROUP_copy                           2962   EXIST::FUNCTION:EC
+KRB5_ENCDATA_free                       2963   EXIST::FUNCTION:
+_ossl_old_des_cfb_encrypt               2964   EXIST::FUNCTION:DES
+OCSP_SINGLERESP_get_ext_by_OBJ          2965   EXIST::FUNCTION:
+OCSP_cert_to_id                         2966   EXIST::FUNCTION:
+OCSP_RESPID_new                         2967   EXIST::FUNCTION:
+OCSP_RESPDATA_it                        2968   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+OCSP_RESPDATA_it                        2968   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+d2i_OCSP_RESPDATA                       2969   EXIST::FUNCTION:
+ENGINE_register_all_complete            2970   EXIST::FUNCTION:ENGINE
+OCSP_check_validity                     2971   EXIST::FUNCTION:
+PKCS12_BAGS_it                          2972   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PKCS12_BAGS_it                          2972   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+OCSP_url_svcloc_new                     2973   EXIST::FUNCTION:
+ASN1_template_free                      2974   EXIST::FUNCTION:
+OCSP_SINGLERESP_add_ext                 2975   EXIST::FUNCTION:
+KRB5_AUTHENTBODY_it                     2976   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+KRB5_AUTHENTBODY_it                     2976   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+X509_supported_extension                2977   EXIST::FUNCTION:
+i2d_KRB5_AUTHDATA                       2978   EXIST::FUNCTION:
+UI_method_get_opener                    2979   EXIST::FUNCTION:
+ENGINE_set_ex_data                      2980   EXIST::FUNCTION:ENGINE
+OCSP_REQUEST_print                      2981   EXIST::FUNCTION:
+CBIGNUM_it                              2982   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+CBIGNUM_it                              2982   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+KRB5_TICKET_new                         2983   EXIST::FUNCTION:
+KRB5_APREQ_new                          2984   EXIST::FUNCTION:
+EC_GROUP_get_curve_GFp                  2985   EXIST::FUNCTION:EC
+KRB5_ENCKEY_new                         2986   EXIST::FUNCTION:
+ASN1_template_d2i                       2987   EXIST::FUNCTION:
+_ossl_old_des_quad_cksum                2988   EXIST::FUNCTION:DES
+OCSP_single_get0_status                 2989   EXIST::FUNCTION:
+BN_swap                                 2990   EXIST::FUNCTION:
+POLICYINFO_it                           2991   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+POLICYINFO_it                           2991   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+ENGINE_set_destroy_function             2992   EXIST::FUNCTION:ENGINE
+asn1_enc_free                           2993   EXIST::FUNCTION:
+OCSP_RESPID_it                          2994   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+OCSP_RESPID_it                          2994   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+EC_GROUP_new                            2995   EXIST::FUNCTION:EC
+EVP_aes_256_cbc                         2996   EXIST::FUNCTION:AES
+i2d_KRB5_PRINCNAME                      2997   EXIST::FUNCTION:
+_ossl_old_des_encrypt2                  2998   EXIST::FUNCTION:DES
+_ossl_old_des_encrypt3                  2999   EXIST::FUNCTION:DES
+PKCS8_PRIV_KEY_INFO_it                  3000   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PKCS8_PRIV_KEY_INFO_it                  3000   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+OCSP_REQINFO_it                         3001   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+OCSP_REQINFO_it                         3001   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+PBEPARAM_it                             3002   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PBEPARAM_it                             3002   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+KRB5_AUTHENTBODY_new                    3003   EXIST::FUNCTION:
+X509_CRL_add0_revoked                   3004   EXIST::FUNCTION:
+EDIPARTYNAME_it                         3005   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+EDIPARTYNAME_it                         3005   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+NETSCAPE_SPKI_it                        3006   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+NETSCAPE_SPKI_it                        3006   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+UI_get0_test_string                     3007   EXIST::FUNCTION:
+ENGINE_get_cipher_engine                3008   EXIST::FUNCTION:ENGINE
+ENGINE_register_all_ciphers             3009   EXIST::FUNCTION:ENGINE
+EC_POINT_copy                           3010   EXIST::FUNCTION:EC
+BN_kronecker                            3011   EXIST::FUNCTION:
+_ossl_old_des_ede3_ofb64_encrypt        3012   EXIST:!VMS:FUNCTION:DES
+_ossl_odes_ede3_ofb64_encrypt           3012   EXIST:VMS:FUNCTION:DES
+UI_method_get_reader                    3013   EXIST::FUNCTION:
+OCSP_BASICRESP_get_ext_count            3014   EXIST::FUNCTION:
+ASN1_ENUMERATED_it                      3015   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_ENUMERATED_it                      3015   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+UI_set_result                           3016   EXIST::FUNCTION:
+i2d_KRB5_TICKET                         3017   EXIST::FUNCTION:
+X509_print_ex_fp                        3018   EXIST::FUNCTION:FP_API
+EVP_CIPHER_CTX_set_padding              3019   EXIST::FUNCTION:
+d2i_OCSP_RESPONSE                       3020   EXIST::FUNCTION:
+ASN1_UTCTIME_it                         3021   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_UTCTIME_it                         3021   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+_ossl_old_des_enc_write                 3022   EXIST::FUNCTION:DES
+OCSP_RESPONSE_new                       3023   EXIST::FUNCTION:
+AES_set_encrypt_key                     3024   EXIST::FUNCTION:AES
+OCSP_resp_count                         3025   EXIST::FUNCTION:
+KRB5_CHECKSUM_new                       3026   EXIST::FUNCTION:
+ENGINE_load_cswift                      3027   EXIST::FUNCTION:ENGINE,STATIC_ENGINE
+OCSP_onereq_get0_id                     3028   EXIST::FUNCTION:
+ENGINE_set_default_ciphers              3029   EXIST::FUNCTION:ENGINE
+NOTICEREF_it                            3030   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+NOTICEREF_it                            3030   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+X509V3_EXT_CRL_add_nconf                3031   EXIST::FUNCTION:
+OCSP_REVOKEDINFO_it                     3032   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+OCSP_REVOKEDINFO_it                     3032   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+AES_encrypt                             3033   EXIST::FUNCTION:AES
+OCSP_REQUEST_new                        3034   EXIST::FUNCTION:
+ASN1_ANY_it                             3035   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_ANY_it                             3035   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+CRYPTO_ex_data_new_class                3036   EXIST::FUNCTION:
+_ossl_old_des_ncbc_encrypt              3037   EXIST::FUNCTION:DES
+i2d_KRB5_TKTBODY                        3038   EXIST::FUNCTION:
+EC_POINT_clear_free                     3039   EXIST::FUNCTION:EC
+AES_decrypt                             3040   EXIST::FUNCTION:AES
+asn1_enc_init                           3041   EXIST::FUNCTION:
+UI_get_result_maxsize                   3042   EXIST::FUNCTION:
+OCSP_CERTID_new                         3043   EXIST::FUNCTION:
+ENGINE_unregister_RAND                  3044   EXIST::FUNCTION:ENGINE
+UI_method_get_closer                    3045   EXIST::FUNCTION:
+d2i_KRB5_ENCDATA                        3046   EXIST::FUNCTION:
+OCSP_request_onereq_count               3047   EXIST::FUNCTION:
+OCSP_basic_verify                       3048   EXIST::FUNCTION:
+KRB5_AUTHENTBODY_free                   3049   EXIST::FUNCTION:
+ASN1_item_d2i                           3050   EXIST::FUNCTION:
+ASN1_primitive_free                     3051   EXIST::FUNCTION:
+i2d_EXTENDED_KEY_USAGE                  3052   EXIST::FUNCTION:
+i2d_OCSP_SIGNATURE                      3053   EXIST::FUNCTION:
+asn1_enc_save                           3054   EXIST::FUNCTION:
+ENGINE_load_nuron                       3055   EXIST::FUNCTION:ENGINE,STATIC_ENGINE
+_ossl_old_des_pcbc_encrypt              3056   EXIST::FUNCTION:DES
+PKCS12_MAC_DATA_it                      3057   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PKCS12_MAC_DATA_it                      3057   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+OCSP_accept_responses_new               3058   EXIST::FUNCTION:
+asn1_do_lock                            3059   EXIST::FUNCTION:
+PKCS7_ATTR_VERIFY_it                    3060   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PKCS7_ATTR_VERIFY_it                    3060   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+KRB5_APREQBODY_it                       3061   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+KRB5_APREQBODY_it                       3061   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+i2d_OCSP_SINGLERESP                     3062   EXIST::FUNCTION:
+ASN1_item_ex_new                        3063   EXIST::FUNCTION:
+UI_add_verify_string                    3064   EXIST::FUNCTION:
+_ossl_old_des_set_key                   3065   EXIST::FUNCTION:DES
+KRB5_PRINCNAME_it                       3066   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+KRB5_PRINCNAME_it                       3066   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+EVP_DecryptInit_ex                      3067   EXIST::FUNCTION:
+i2d_OCSP_CERTID                         3068   EXIST::FUNCTION:
+ASN1_item_d2i_bio                       3069   EXIST::FUNCTION:BIO
+EC_POINT_dbl                            3070   EXIST::FUNCTION:EC
+asn1_get_choice_selector                3071   EXIST::FUNCTION:
+i2d_KRB5_CHECKSUM                       3072   EXIST::FUNCTION:
+ENGINE_set_table_flags                  3073   EXIST::FUNCTION:ENGINE
+AES_options                             3074   EXIST::FUNCTION:AES
+ENGINE_load_chil                        3075   EXIST::FUNCTION:ENGINE,STATIC_ENGINE
+OCSP_id_cmp                             3076   EXIST::FUNCTION:
+OCSP_BASICRESP_new                      3077   EXIST::FUNCTION:
+OCSP_REQUEST_get_ext_by_NID             3078   EXIST::FUNCTION:
+KRB5_APREQ_it                           3079   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+KRB5_APREQ_it                           3079   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+ENGINE_get_destroy_function             3080   EXIST::FUNCTION:ENGINE
+CONF_set_nconf                          3081   EXIST::FUNCTION:
+ASN1_PRINTABLE_free                     3082   EXIST::FUNCTION:
+OCSP_BASICRESP_get_ext_by_NID           3083   EXIST::FUNCTION:
+DIST_POINT_NAME_it                      3084   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+DIST_POINT_NAME_it                      3084   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+X509V3_extensions_print                 3085   EXIST::FUNCTION:
+_ossl_old_des_cfb64_encrypt             3086   EXIST::FUNCTION:DES
+X509_REVOKED_add1_ext_i2d               3087   EXIST::FUNCTION:
+_ossl_old_des_ofb_encrypt               3088   EXIST::FUNCTION:DES
+KRB5_TKTBODY_new                        3089   EXIST::FUNCTION:
+ASN1_OCTET_STRING_it                    3090   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_OCTET_STRING_it                    3090   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+ERR_load_UI_strings                     3091   EXIST::FUNCTION:
+i2d_KRB5_ENCKEY                         3092   EXIST::FUNCTION:
+ASN1_template_new                       3093   EXIST::FUNCTION:
+OCSP_SIGNATURE_free                     3094   EXIST::FUNCTION:
+ASN1_item_i2d_fp                        3095   EXIST::FUNCTION:FP_API
+KRB5_PRINCNAME_free                     3096   EXIST::FUNCTION:
+PKCS7_RECIP_INFO_it                     3097   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PKCS7_RECIP_INFO_it                     3097   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+EXTENDED_KEY_USAGE_it                   3098   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+EXTENDED_KEY_USAGE_it                   3098   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+EC_GFp_simple_method                    3099   EXIST::FUNCTION:EC
+EC_GROUP_precompute_mult                3100   EXIST::FUNCTION:EC
+OCSP_request_onereq_get0                3101   EXIST::FUNCTION:
+UI_method_set_writer                    3102   EXIST::FUNCTION:
+KRB5_AUTHENT_new                        3103   EXIST::FUNCTION:
+X509_CRL_INFO_it                        3104   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+X509_CRL_INFO_it                        3104   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+DSO_set_name_converter                  3105   EXIST::FUNCTION:
+AES_set_decrypt_key                     3106   EXIST::FUNCTION:AES
+PKCS7_DIGEST_it                         3107   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PKCS7_DIGEST_it                         3107   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+PKCS12_x5092certbag                     3108   EXIST::FUNCTION:
+EVP_DigestInit_ex                       3109   EXIST::FUNCTION:
+i2a_ACCESS_DESCRIPTION                  3110   EXIST::FUNCTION:
+OCSP_RESPONSE_it                        3111   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+OCSP_RESPONSE_it                        3111   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+PKCS7_ENC_CONTENT_it                    3112   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PKCS7_ENC_CONTENT_it                    3112   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+OCSP_request_add0_id                    3113   EXIST::FUNCTION:
+EC_POINT_make_affine                    3114   EXIST::FUNCTION:EC
+DSO_get_filename                        3115   EXIST::FUNCTION:
+OCSP_CERTSTATUS_it                      3116   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+OCSP_CERTSTATUS_it                      3116   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+OCSP_request_add1_cert                  3117   EXIST::FUNCTION:
+UI_get0_output_string                   3118   EXIST::FUNCTION:
+UI_dup_verify_string                    3119   EXIST::FUNCTION:
+BN_mod_lshift                           3120   EXIST::FUNCTION:
+KRB5_AUTHDATA_it                        3121   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+KRB5_AUTHDATA_it                        3121   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+asn1_set_choice_selector                3122   EXIST::FUNCTION:
+OCSP_basic_add1_status                  3123   EXIST::FUNCTION:
+OCSP_RESPID_free                        3124   EXIST::FUNCTION:
+asn1_get_field_ptr                      3125   EXIST::FUNCTION:
+UI_add_input_string                     3126   EXIST::FUNCTION:
+OCSP_CRLID_it                           3127   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+OCSP_CRLID_it                           3127   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+i2d_KRB5_AUTHENTBODY                    3128   EXIST::FUNCTION:
+OCSP_REQUEST_get_ext_count              3129   EXIST::FUNCTION:
+ENGINE_load_atalla                      3130   EXIST::FUNCTION:ENGINE,STATIC_ENGINE
+X509_NAME_it                            3131   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+X509_NAME_it                            3131   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+USERNOTICE_it                           3132   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+USERNOTICE_it                           3132   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+OCSP_REQINFO_new                        3133   EXIST::FUNCTION:
+OCSP_BASICRESP_get_ext                  3134   EXIST::FUNCTION:
+CRYPTO_get_ex_data_implementation       3135   EXIST:!VMS:FUNCTION:
+CRYPTO_get_ex_data_impl                 3135   EXIST:VMS:FUNCTION:
+ASN1_item_pack                          3136   EXIST::FUNCTION:
+i2d_KRB5_ENCDATA                        3137   EXIST::FUNCTION:
+X509_PURPOSE_set                        3138   EXIST::FUNCTION:
+X509_REQ_INFO_it                        3139   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+X509_REQ_INFO_it                        3139   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+UI_method_set_opener                    3140   EXIST::FUNCTION:
+ASN1_item_ex_free                       3141   EXIST::FUNCTION:
+ASN1_BOOLEAN_it                         3142   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_BOOLEAN_it                         3142   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+ENGINE_get_table_flags                  3143   EXIST::FUNCTION:ENGINE
+UI_create_method                        3144   EXIST::FUNCTION:
+OCSP_ONEREQ_add1_ext_i2d                3145   EXIST::FUNCTION:
+_shadow_DES_check_key                   3146   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:DES
+_shadow_DES_check_key                   3146   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:DES
+d2i_OCSP_REQINFO                        3147   EXIST::FUNCTION:
+UI_add_info_string                      3148   EXIST::FUNCTION:
+UI_get_result_minsize                   3149   EXIST::FUNCTION:
+ASN1_NULL_it                            3150   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_NULL_it                            3150   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+BN_mod_lshift1                          3151   EXIST::FUNCTION:
+d2i_OCSP_ONEREQ                         3152   EXIST::FUNCTION:
+OCSP_ONEREQ_new                         3153   EXIST::FUNCTION:
+KRB5_TICKET_it                          3154   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+KRB5_TICKET_it                          3154   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+EVP_aes_192_cbc                         3155   EXIST::FUNCTION:AES
+KRB5_TICKET_free                        3156   EXIST::FUNCTION:
+UI_new                                  3157   EXIST::FUNCTION:
+OCSP_response_create                    3158   EXIST::FUNCTION:
+_ossl_old_des_xcbc_encrypt              3159   EXIST::FUNCTION:DES
+PKCS7_it                                3160   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PKCS7_it                                3160   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+OCSP_REQUEST_get_ext_by_critical        3161   EXIST:!VMS:FUNCTION:
+OCSP_REQUEST_get_ext_by_crit            3161   EXIST:VMS:FUNCTION:
+ENGINE_set_flags                        3162   EXIST::FUNCTION:ENGINE
+_ossl_old_des_ecb_encrypt               3163   EXIST::FUNCTION:DES
+OCSP_response_get1_basic                3164   EXIST::FUNCTION:
+EVP_Digest                              3165   EXIST::FUNCTION:
+OCSP_ONEREQ_delete_ext                  3166   EXIST::FUNCTION:
+ASN1_TBOOLEAN_it                        3167   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_TBOOLEAN_it                        3167   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+ASN1_item_new                           3168   EXIST::FUNCTION:
+ASN1_TIME_to_generalizedtime            3169   EXIST::FUNCTION:
+BIGNUM_it                               3170   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+BIGNUM_it                               3170   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+AES_cbc_encrypt                         3171   EXIST::FUNCTION:AES
+ENGINE_get_load_privkey_function        3172   EXIST:!VMS:FUNCTION:ENGINE
+ENGINE_get_load_privkey_fn              3172   EXIST:VMS:FUNCTION:ENGINE
+OCSP_RESPONSE_free                      3173   EXIST::FUNCTION:
+UI_method_set_reader                    3174   EXIST::FUNCTION:
+i2d_ASN1_T61STRING                      3175   EXIST::FUNCTION:
+EC_POINT_set_to_infinity                3176   EXIST::FUNCTION:EC
+ERR_load_OCSP_strings                   3177   EXIST::FUNCTION:
+EC_POINT_point2oct                      3178   EXIST::FUNCTION:EC
+KRB5_APREQ_free                         3179   EXIST::FUNCTION:
+ASN1_OBJECT_it                          3180   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_OBJECT_it                          3180   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+OCSP_crlID_new                          3181   EXIST:!OS2,!VMS:FUNCTION:
+OCSP_crlID2_new                         3181   EXIST:OS2,VMS:FUNCTION:
+CONF_modules_load_file                  3182   EXIST::FUNCTION:
+CONF_imodule_set_usr_data               3183   EXIST::FUNCTION:
+ENGINE_set_default_string               3184   EXIST::FUNCTION:ENGINE
+CONF_module_get_usr_data                3185   EXIST::FUNCTION:
+ASN1_add_oid_module                     3186   EXIST::FUNCTION:
+CONF_modules_finish                     3187   EXIST::FUNCTION:
+OPENSSL_config                          3188   EXIST::FUNCTION:
+CONF_modules_unload                     3189   EXIST::FUNCTION:
+CONF_imodule_get_value                  3190   EXIST::FUNCTION:
+CONF_module_set_usr_data                3191   EXIST::FUNCTION:
+CONF_parse_list                         3192   EXIST::FUNCTION:
+CONF_module_add                         3193   EXIST::FUNCTION:
+CONF_get1_default_config_file           3194   EXIST::FUNCTION:
+CONF_imodule_get_flags                  3195   EXIST::FUNCTION:
+CONF_imodule_get_module                 3196   EXIST::FUNCTION:
+CONF_modules_load                       3197   EXIST::FUNCTION:
+CONF_imodule_get_name                   3198   EXIST::FUNCTION:
+ERR_peek_top_error                      3199   NOEXIST::FUNCTION:
+CONF_imodule_get_usr_data               3200   EXIST::FUNCTION:
+CONF_imodule_set_flags                  3201   EXIST::FUNCTION:
+ENGINE_add_conf_module                  3202   EXIST::FUNCTION:ENGINE
+ERR_peek_last_error_line                3203   EXIST::FUNCTION:
+ERR_peek_last_error_line_data           3204   EXIST::FUNCTION:
+ERR_peek_last_error                     3205   EXIST::FUNCTION:
+DES_read_2passwords                     3206   EXIST::FUNCTION:DES
+DES_read_password                       3207   EXIST::FUNCTION:DES
+UI_UTIL_read_pw                         3208   EXIST::FUNCTION:
+UI_UTIL_read_pw_string                  3209   EXIST::FUNCTION:
+ENGINE_load_aep                         3210   EXIST::FUNCTION:ENGINE,STATIC_ENGINE
+ENGINE_load_sureware                    3211   EXIST::FUNCTION:ENGINE,STATIC_ENGINE
+OPENSSL_add_all_algorithms_noconf       3212   EXIST:!VMS:FUNCTION:
+OPENSSL_add_all_algo_noconf             3212   EXIST:VMS:FUNCTION:
+OPENSSL_add_all_algorithms_conf         3213   EXIST:!VMS:FUNCTION:
+OPENSSL_add_all_algo_conf               3213   EXIST:VMS:FUNCTION:
+OPENSSL_load_builtin_modules            3214   EXIST::FUNCTION:
+AES_ofb128_encrypt                      3215   EXIST::FUNCTION:AES
+AES_ctr128_encrypt                      3216   EXIST::FUNCTION:AES
+AES_cfb128_encrypt                      3217   EXIST::FUNCTION:AES
+ENGINE_load_4758cca                     3218   EXIST::FUNCTION:ENGINE,STATIC_ENGINE
+_ossl_096_des_random_seed               3219   EXIST::FUNCTION:DES
+EVP_aes_256_ofb                         3220   EXIST::FUNCTION:AES
+EVP_aes_192_ofb                         3221   EXIST::FUNCTION:AES
+EVP_aes_128_cfb128                      3222   EXIST::FUNCTION:AES
+EVP_aes_256_cfb128                      3223   EXIST::FUNCTION:AES
+EVP_aes_128_ofb                         3224   EXIST::FUNCTION:AES
+EVP_aes_192_cfb128                      3225   EXIST::FUNCTION:AES
+CONF_modules_free                       3226   EXIST::FUNCTION:
+NCONF_default                           3227   EXIST::FUNCTION:
+OPENSSL_no_config                       3228   EXIST::FUNCTION:
+NCONF_WIN32                             3229   EXIST::FUNCTION:
+ASN1_UNIVERSALSTRING_new                3230   EXIST::FUNCTION:
+EVP_des_ede_ecb                         3231   EXIST::FUNCTION:DES
+i2d_ASN1_UNIVERSALSTRING                3232   EXIST::FUNCTION:
+ASN1_UNIVERSALSTRING_free               3233   EXIST::FUNCTION:
+ASN1_UNIVERSALSTRING_it                 3234   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_UNIVERSALSTRING_it                 3234   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+d2i_ASN1_UNIVERSALSTRING                3235   EXIST::FUNCTION:
+EVP_des_ede3_ecb                        3236   EXIST::FUNCTION:DES
+X509_REQ_print_ex                       3237   EXIST::FUNCTION:BIO
+ENGINE_up_ref                           3238   EXIST::FUNCTION:ENGINE
+BUF_MEM_grow_clean                      3239   EXIST::FUNCTION:
+CRYPTO_realloc_clean                    3240   EXIST::FUNCTION:
+BUF_strlcat                             3241   EXIST::FUNCTION:
+BIO_indent                              3242   EXIST::FUNCTION:
+BUF_strlcpy                             3243   EXIST::FUNCTION:
+OpenSSLDie                              3244   EXIST::FUNCTION:
+OPENSSL_cleanse                         3245   EXIST::FUNCTION:
+ENGINE_setup_bsd_cryptodev              3246   EXIST:__FreeBSD__:FUNCTION:ENGINE
+ERR_release_err_state_table             3247   EXIST::FUNCTION:LHASH
+EVP_aes_128_cfb8                        3248   EXIST::FUNCTION:AES
+FIPS_corrupt_rsa                        3249   NOEXIST::FUNCTION:
+FIPS_selftest_des                       3250   NOEXIST::FUNCTION:
+EVP_aes_128_cfb1                        3251   EXIST::FUNCTION:AES
+EVP_aes_192_cfb8                        3252   EXIST::FUNCTION:AES
+FIPS_mode_set                           3253   NOEXIST::FUNCTION:
+FIPS_selftest_dsa                       3254   NOEXIST::FUNCTION:
+EVP_aes_256_cfb8                        3255   EXIST::FUNCTION:AES
+FIPS_allow_md5                          3256   NOEXIST::FUNCTION:
+DES_ede3_cfb_encrypt                    3257   EXIST::FUNCTION:DES
+EVP_des_ede3_cfb8                       3258   EXIST::FUNCTION:DES
+FIPS_rand_seeded                        3259   NOEXIST::FUNCTION:
+AES_cfbr_encrypt_block                  3260   NOEXIST::FUNCTION:
+AES_cfb8_encrypt                        3261   EXIST::FUNCTION:AES
+FIPS_rand_seed                          3262   NOEXIST::FUNCTION:
+FIPS_corrupt_des                        3263   NOEXIST::FUNCTION:
+EVP_aes_192_cfb1                        3264   EXIST::FUNCTION:AES
+FIPS_selftest_aes                       3265   NOEXIST::FUNCTION:
+FIPS_set_prng_key                       3266   NOEXIST::FUNCTION:
+EVP_des_cfb8                            3267   EXIST::FUNCTION:DES
+FIPS_corrupt_dsa                        3268   NOEXIST::FUNCTION:
+FIPS_test_mode                          3269   NOEXIST::FUNCTION:
+FIPS_rand_method                        3270   NOEXIST::FUNCTION:
+EVP_aes_256_cfb1                        3271   EXIST::FUNCTION:AES
+ERR_load_FIPS_strings                   3272   NOEXIST::FUNCTION:
+FIPS_corrupt_aes                        3273   NOEXIST::FUNCTION:
+FIPS_selftest_sha1                      3274   NOEXIST::FUNCTION:
+FIPS_selftest_rsa                       3275   NOEXIST::FUNCTION:
+FIPS_corrupt_sha1                       3276   NOEXIST::FUNCTION:
+EVP_des_cfb1                            3277   EXIST::FUNCTION:DES
+FIPS_dsa_check                          3278   NOEXIST::FUNCTION:
+AES_cfb1_encrypt                        3279   EXIST::FUNCTION:AES
+EVP_des_ede3_cfb1                       3280   EXIST::FUNCTION:DES
+FIPS_rand_check                         3281   NOEXIST::FUNCTION:
+FIPS_md5_allowed                        3282   NOEXIST::FUNCTION:
+FIPS_mode                               3283   NOEXIST::FUNCTION:
+FIPS_selftest_failed                    3284   NOEXIST::FUNCTION:
+sk_is_sorted                            3285   EXIST::FUNCTION:
+X509_check_ca                           3286   EXIST::FUNCTION:
+private_idea_set_encrypt_key            3287   NOEXIST::FUNCTION:
+HMAC_CTX_set_flags                      3288   EXIST::FUNCTION:HMAC
+private_SHA_Init                        3289   NOEXIST::FUNCTION:
+private_CAST_set_key                    3290   NOEXIST::FUNCTION:
+private_RIPEMD160_Init                  3291   NOEXIST::FUNCTION:
+private_RC5_32_set_key                  3292   NOEXIST::FUNCTION:
+private_MD5_Init                        3293   NOEXIST::FUNCTION:
+private_RC4_set_key                     3294   NOEXIST::FUNCTION:
+private_MDC2_Init                       3295   NOEXIST::FUNCTION:
+private_RC2_set_key                     3296   NOEXIST::FUNCTION:
+private_MD4_Init                        3297   NOEXIST::FUNCTION:
+private_BF_set_key                      3298   NOEXIST::FUNCTION:
+private_MD2_Init                        3299   NOEXIST::FUNCTION:
+d2i_PROXY_CERT_INFO_EXTENSION           3300   EXIST::FUNCTION:
+PROXY_POLICY_it                         3301   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PROXY_POLICY_it                         3301   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+i2d_PROXY_POLICY                        3302   EXIST::FUNCTION:
+i2d_PROXY_CERT_INFO_EXTENSION           3303   EXIST::FUNCTION:
+d2i_PROXY_POLICY                        3304   EXIST::FUNCTION:
+PROXY_CERT_INFO_EXTENSION_new           3305   EXIST::FUNCTION:
+PROXY_CERT_INFO_EXTENSION_free          3306   EXIST::FUNCTION:
+PROXY_CERT_INFO_EXTENSION_it            3307   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+PROXY_CERT_INFO_EXTENSION_it            3307   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+PROXY_POLICY_free                       3308   EXIST::FUNCTION:
+PROXY_POLICY_new                        3309   EXIST::FUNCTION:
+BN_MONT_CTX_set_locked                  3310   EXIST::FUNCTION:
+FIPS_selftest_rng                       3311   NOEXIST::FUNCTION:
+EVP_sha384                              3312   EXIST:!VMSVAX:FUNCTION:SHA,SHA512
+EVP_sha512                              3313   EXIST:!VMSVAX:FUNCTION:SHA,SHA512
+EVP_sha224                              3314   EXIST::FUNCTION:SHA,SHA256
+EVP_sha256                              3315   EXIST::FUNCTION:SHA,SHA256
+FIPS_selftest_hmac                      3316   NOEXIST::FUNCTION:
+FIPS_corrupt_rng                        3317   NOEXIST::FUNCTION:
+BN_mod_exp_mont_consttime               3318   EXIST::FUNCTION:
+RSA_X931_hash_id                        3319   EXIST::FUNCTION:RSA
+RSA_padding_check_X931                  3320   EXIST::FUNCTION:RSA
+RSA_verify_PKCS1_PSS                    3321   EXIST::FUNCTION:RSA
+RSA_padding_add_X931                    3322   EXIST::FUNCTION:RSA
+RSA_padding_add_PKCS1_PSS               3323   EXIST::FUNCTION:RSA
+PKCS1_MGF1                              3324   EXIST::FUNCTION:RSA
+BN_X931_generate_Xpq                    3325   NOEXIST::FUNCTION:
+RSA_X931_generate_key                   3326   NOEXIST::FUNCTION:
+BN_X931_derive_prime                    3327   NOEXIST::FUNCTION:
+BN_X931_generate_prime                  3328   NOEXIST::FUNCTION:
+RSA_X931_derive                         3329   NOEXIST::FUNCTION:
+BIO_new_dgram                           3330   EXIST::FUNCTION:
+BN_get0_nist_prime_384                  3331   EXIST::FUNCTION:
+ERR_set_mark                            3332   EXIST::FUNCTION:
+X509_STORE_CTX_set0_crls                3333   EXIST::FUNCTION:
+ENGINE_set_STORE                        3334   EXIST::FUNCTION:ENGINE
+ENGINE_register_ECDSA                   3335   EXIST::FUNCTION:ENGINE
+STORE_meth_set_list_start_fn            3336   NOEXIST::FUNCTION:
+STORE_method_set_list_start_function    3336   NOEXIST::FUNCTION:
+BN_BLINDING_invert_ex                   3337   EXIST::FUNCTION:
+NAME_CONSTRAINTS_free                   3338   EXIST::FUNCTION:
+STORE_ATTR_INFO_set_number              3339   NOEXIST::FUNCTION:
+BN_BLINDING_get_thread_id               3340   EXIST::FUNCTION:DEPRECATED
+X509_STORE_CTX_set0_param               3341   EXIST::FUNCTION:
+POLICY_MAPPING_it                       3342   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+POLICY_MAPPING_it                       3342   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+STORE_parse_attrs_start                 3343   NOEXIST::FUNCTION:
+POLICY_CONSTRAINTS_free                 3344   EXIST::FUNCTION:
+EVP_PKEY_add1_attr_by_NID               3345   EXIST::FUNCTION:
+BN_nist_mod_192                         3346   EXIST::FUNCTION:
+EC_GROUP_get_trinomial_basis            3347   EXIST::FUNCTION:EC
+STORE_set_method                        3348   NOEXIST::FUNCTION:
+GENERAL_SUBTREE_free                    3349   EXIST::FUNCTION:
+NAME_CONSTRAINTS_it                     3350   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+NAME_CONSTRAINTS_it                     3350   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+ECDH_get_default_method                 3351   EXIST::FUNCTION:ECDH
+PKCS12_add_safe                         3352   EXIST::FUNCTION:
+EC_KEY_new_by_curve_name                3353   EXIST::FUNCTION:EC
+STORE_meth_get_update_store_fn          3354   NOEXIST::FUNCTION:
+STORE_method_get_update_store_function  3354   NOEXIST::FUNCTION:
+ENGINE_register_ECDH                    3355   EXIST::FUNCTION:ENGINE
+SHA512_Update                           3356   EXIST:!VMSVAX:FUNCTION:SHA,SHA512
+i2d_ECPrivateKey                        3357   EXIST::FUNCTION:EC
+BN_get0_nist_prime_192                  3358   EXIST::FUNCTION:
+STORE_modify_certificate                3359   NOEXIST::FUNCTION:
+EC_POINT_set_affine_coordinates_GF2m    3360   EXIST:!VMS:FUNCTION:EC
+EC_POINT_set_affine_coords_GF2m         3360   EXIST:VMS:FUNCTION:EC
+BN_GF2m_mod_exp_arr                     3361   EXIST::FUNCTION:
+STORE_ATTR_INFO_modify_number           3362   NOEXIST::FUNCTION:
+X509_keyid_get0                         3363   EXIST::FUNCTION:
+ENGINE_load_gmp                         3364   EXIST::FUNCTION:ENGINE,GMP,STATIC_ENGINE
+pitem_new                               3365   EXIST::FUNCTION:
+BN_GF2m_mod_mul_arr                     3366   EXIST::FUNCTION:
+STORE_list_public_key_endp              3367   NOEXIST::FUNCTION:
+o2i_ECPublicKey                         3368   EXIST::FUNCTION:EC
+EC_KEY_copy                             3369   EXIST::FUNCTION:EC
+BIO_dump_fp                             3370   EXIST::FUNCTION:FP_API
+X509_policy_node_get0_parent            3371   EXIST::FUNCTION:
+EC_GROUP_check_discriminant             3372   EXIST::FUNCTION:EC
+i2o_ECPublicKey                         3373   EXIST::FUNCTION:EC
+EC_KEY_precompute_mult                  3374   EXIST::FUNCTION:EC
+a2i_IPADDRESS                           3375   EXIST::FUNCTION:
+STORE_meth_set_initialise_fn            3376   NOEXIST::FUNCTION:
+STORE_method_set_initialise_function    3376   NOEXIST::FUNCTION:
+X509_STORE_CTX_set_depth                3377   EXIST::FUNCTION:
+X509_VERIFY_PARAM_inherit               3378   EXIST::FUNCTION:
+EC_POINT_point2bn                       3379   EXIST::FUNCTION:EC
+STORE_ATTR_INFO_set_dn                  3380   NOEXIST::FUNCTION:
+X509_policy_tree_get0_policies          3381   EXIST::FUNCTION:
+EC_GROUP_new_curve_GF2m                 3382   EXIST::FUNCTION:EC
+STORE_destroy_method                    3383   NOEXIST::FUNCTION:
+ENGINE_unregister_STORE                 3384   EXIST::FUNCTION:ENGINE
+EVP_PKEY_get1_EC_KEY                    3385   EXIST::FUNCTION:EC
+STORE_ATTR_INFO_get0_number             3386   NOEXIST::FUNCTION:
+ENGINE_get_default_ECDH                 3387   EXIST::FUNCTION:ENGINE
+EC_KEY_get_conv_form                    3388   EXIST::FUNCTION:EC
+ASN1_OCTET_STRING_NDEF_it               3389   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_OCTET_STRING_NDEF_it               3389   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+STORE_delete_public_key                 3390   NOEXIST::FUNCTION:
+STORE_get_public_key                    3391   NOEXIST::FUNCTION:
+STORE_modify_arbitrary                  3392   NOEXIST::FUNCTION:
+ENGINE_get_static_state                 3393   EXIST::FUNCTION:ENGINE
+pqueue_iterator                         3394   EXIST::FUNCTION:
+ECDSA_SIG_new                           3395   EXIST::FUNCTION:ECDSA
+OPENSSL_DIR_end                         3396   EXIST::FUNCTION:
+BN_GF2m_mod_sqr                         3397   EXIST::FUNCTION:
+EC_POINT_bn2point                       3398   EXIST::FUNCTION:EC
+X509_VERIFY_PARAM_set_depth             3399   EXIST::FUNCTION:
+EC_KEY_set_asn1_flag                    3400   EXIST::FUNCTION:EC
+STORE_get_method                        3401   NOEXIST::FUNCTION:
+EC_KEY_get_key_method_data              3402   EXIST::FUNCTION:EC
+ECDSA_sign_ex                           3403   EXIST::FUNCTION:ECDSA
+STORE_parse_attrs_end                   3404   NOEXIST::FUNCTION:
+EC_GROUP_get_point_conversion_form      3405   EXIST:!VMS:FUNCTION:EC
+EC_GROUP_get_point_conv_form            3405   EXIST:VMS:FUNCTION:EC
+STORE_method_set_store_function         3406   NOEXIST::FUNCTION:
+STORE_ATTR_INFO_in                      3407   NOEXIST::FUNCTION:
+PEM_read_bio_ECPKParameters             3408   EXIST::FUNCTION:EC
+EC_GROUP_get_pentanomial_basis          3409   EXIST::FUNCTION:EC
+EVP_PKEY_add1_attr_by_txt               3410   EXIST::FUNCTION:
+BN_BLINDING_set_flags                   3411   EXIST::FUNCTION:
+X509_VERIFY_PARAM_set1_policies         3412   EXIST::FUNCTION:
+X509_VERIFY_PARAM_set1_name             3413   EXIST::FUNCTION:
+X509_VERIFY_PARAM_set_purpose           3414   EXIST::FUNCTION:
+STORE_get_number                        3415   NOEXIST::FUNCTION:
+ECDSA_sign_setup                        3416   EXIST::FUNCTION:ECDSA
+BN_GF2m_mod_solve_quad_arr              3417   EXIST::FUNCTION:
+EC_KEY_up_ref                           3418   EXIST::FUNCTION:EC
+POLICY_MAPPING_free                     3419   EXIST::FUNCTION:
+BN_GF2m_mod_div                         3420   EXIST::FUNCTION:
+X509_VERIFY_PARAM_set_flags             3421   EXIST::FUNCTION:
+EC_KEY_free                             3422   EXIST::FUNCTION:EC
+STORE_meth_set_list_next_fn             3423   NOEXIST::FUNCTION:
+STORE_method_set_list_next_function     3423   NOEXIST::FUNCTION:
+PEM_write_bio_ECPrivateKey              3424   EXIST::FUNCTION:EC
+d2i_EC_PUBKEY                           3425   EXIST::FUNCTION:EC
+STORE_meth_get_generate_fn              3426   NOEXIST::FUNCTION:
+STORE_method_get_generate_function      3426   NOEXIST::FUNCTION:
+STORE_meth_set_list_end_fn              3427   NOEXIST::FUNCTION:
+STORE_method_set_list_end_function      3427   NOEXIST::FUNCTION:
+pqueue_print                            3428   EXIST::FUNCTION:
+EC_GROUP_have_precompute_mult           3429   EXIST::FUNCTION:EC
+EC_KEY_print_fp                         3430   EXIST::FUNCTION:EC,FP_API
+BN_GF2m_mod_arr                         3431   EXIST::FUNCTION:
+PEM_write_bio_X509_CERT_PAIR            3432   EXIST::FUNCTION:
+EVP_PKEY_cmp                            3433   EXIST::FUNCTION:
+X509_policy_level_node_count            3434   EXIST::FUNCTION:
+STORE_new_engine                        3435   NOEXIST::FUNCTION:
+STORE_list_public_key_start             3436   NOEXIST::FUNCTION:
+X509_VERIFY_PARAM_new                   3437   EXIST::FUNCTION:
+ECDH_get_ex_data                        3438   EXIST::FUNCTION:ECDH
+EVP_PKEY_get_attr                       3439   EXIST::FUNCTION:
+ECDSA_do_sign                           3440   EXIST::FUNCTION:ECDSA
+ENGINE_unregister_ECDH                  3441   EXIST::FUNCTION:ENGINE
+ECDH_OpenSSL                            3442   EXIST::FUNCTION:ECDH
+EC_KEY_set_conv_form                    3443   EXIST::FUNCTION:EC
+EC_POINT_dup                            3444   EXIST::FUNCTION:EC
+GENERAL_SUBTREE_new                     3445   EXIST::FUNCTION:
+STORE_list_crl_endp                     3446   NOEXIST::FUNCTION:
+EC_get_builtin_curves                   3447   EXIST::FUNCTION:EC
+X509_policy_node_get0_qualifiers        3448   EXIST:!VMS:FUNCTION:
+X509_pcy_node_get0_qualifiers           3448   EXIST:VMS:FUNCTION:
+STORE_list_crl_end                      3449   NOEXIST::FUNCTION:
+EVP_PKEY_set1_EC_KEY                    3450   EXIST::FUNCTION:EC
+BN_GF2m_mod_sqrt_arr                    3451   EXIST::FUNCTION:
+i2d_ECPrivateKey_bio                    3452   EXIST::FUNCTION:BIO,EC
+ECPKParameters_print_fp                 3453   EXIST::FUNCTION:EC,FP_API
+pqueue_find                             3454   EXIST::FUNCTION:
+ECDSA_SIG_free                          3455   EXIST::FUNCTION:ECDSA
+PEM_write_bio_ECPKParameters            3456   EXIST::FUNCTION:EC
+STORE_method_set_ctrl_function          3457   NOEXIST::FUNCTION:
+STORE_list_public_key_end               3458   NOEXIST::FUNCTION:
+EC_KEY_set_private_key                  3459   EXIST::FUNCTION:EC
+pqueue_peek                             3460   EXIST::FUNCTION:
+STORE_get_arbitrary                     3461   NOEXIST::FUNCTION:
+STORE_store_crl                         3462   NOEXIST::FUNCTION:
+X509_policy_node_get0_policy            3463   EXIST::FUNCTION:
+PKCS12_add_safes                        3464   EXIST::FUNCTION:
+BN_BLINDING_convert_ex                  3465   EXIST::FUNCTION:
+X509_policy_tree_free                   3466   EXIST::FUNCTION:
+OPENSSL_ia32cap_loc                     3467   EXIST::FUNCTION:
+BN_GF2m_poly2arr                        3468   EXIST::FUNCTION:
+STORE_ctrl                              3469   NOEXIST::FUNCTION:
+STORE_ATTR_INFO_compare                 3470   NOEXIST::FUNCTION:
+BN_get0_nist_prime_224                  3471   EXIST::FUNCTION:
+i2d_ECParameters                        3472   EXIST::FUNCTION:EC
+i2d_ECPKParameters                      3473   EXIST::FUNCTION:EC
+BN_GENCB_call                           3474   EXIST::FUNCTION:
+d2i_ECPKParameters                      3475   EXIST::FUNCTION:EC
+STORE_meth_set_generate_fn              3476   NOEXIST::FUNCTION:
+STORE_method_set_generate_function      3476   NOEXIST::FUNCTION:
+ENGINE_set_ECDH                         3477   EXIST::FUNCTION:ENGINE
+NAME_CONSTRAINTS_new                    3478   EXIST::FUNCTION:
+SHA256_Init                             3479   EXIST::FUNCTION:SHA,SHA256
+EC_KEY_get0_public_key                  3480   EXIST::FUNCTION:EC
+PEM_write_bio_EC_PUBKEY                 3481   EXIST::FUNCTION:EC
+STORE_ATTR_INFO_set_cstr                3482   NOEXIST::FUNCTION:
+STORE_list_crl_next                     3483   NOEXIST::FUNCTION:
+STORE_ATTR_INFO_in_range                3484   NOEXIST::FUNCTION:
+ECParameters_print                      3485   EXIST::FUNCTION:BIO,EC
+STORE_meth_set_delete_fn                3486   NOEXIST::FUNCTION:
+STORE_method_set_delete_function        3486   NOEXIST::FUNCTION:
+STORE_list_certificate_next             3487   NOEXIST::FUNCTION:
+ASN1_generate_nconf                     3488   EXIST::FUNCTION:
+BUF_memdup                              3489   EXIST::FUNCTION:
+BN_GF2m_mod_mul                         3490   EXIST::FUNCTION:
+STORE_meth_get_list_next_fn             3491   NOEXIST::FUNCTION:
+STORE_method_get_list_next_function     3491   NOEXIST::FUNCTION:
+STORE_ATTR_INFO_get0_dn                 3492   NOEXIST::FUNCTION:
+STORE_list_private_key_next             3493   NOEXIST::FUNCTION:
+EC_GROUP_set_seed                       3494   EXIST::FUNCTION:EC
+X509_VERIFY_PARAM_set_trust             3495   EXIST::FUNCTION:
+STORE_ATTR_INFO_free                    3496   NOEXIST::FUNCTION:
+STORE_get_private_key                   3497   NOEXIST::FUNCTION:
+EVP_PKEY_get_attr_count                 3498   EXIST::FUNCTION:
+STORE_ATTR_INFO_new                     3499   NOEXIST::FUNCTION:
+EC_GROUP_get_curve_GF2m                 3500   EXIST::FUNCTION:EC
+STORE_meth_set_revoke_fn                3501   NOEXIST::FUNCTION:
+STORE_method_set_revoke_function        3501   NOEXIST::FUNCTION:
+STORE_store_number                      3502   NOEXIST::FUNCTION:
+BN_is_prime_ex                          3503   EXIST::FUNCTION:
+STORE_revoke_public_key                 3504   NOEXIST::FUNCTION:
+X509_STORE_CTX_get0_param               3505   EXIST::FUNCTION:
+STORE_delete_arbitrary                  3506   NOEXIST::FUNCTION:
+PEM_read_X509_CERT_PAIR                 3507   EXIST:!WIN16:FUNCTION:
+X509_STORE_set_depth                    3508   EXIST::FUNCTION:
+ECDSA_get_ex_data                       3509   EXIST::FUNCTION:ECDSA
+SHA224                                  3510   EXIST::FUNCTION:SHA,SHA256
+BIO_dump_indent_fp                      3511   EXIST::FUNCTION:FP_API
+EC_KEY_set_group                        3512   EXIST::FUNCTION:EC
+BUF_strndup                             3513   EXIST::FUNCTION:
+STORE_list_certificate_start            3514   NOEXIST::FUNCTION:
+BN_GF2m_mod                             3515   EXIST::FUNCTION:
+X509_REQ_check_private_key              3516   EXIST::FUNCTION:
+EC_GROUP_get_seed_len                   3517   EXIST::FUNCTION:EC
+ERR_load_STORE_strings                  3518   NOEXIST::FUNCTION:
+PEM_read_bio_EC_PUBKEY                  3519   EXIST::FUNCTION:EC
+STORE_list_private_key_end              3520   NOEXIST::FUNCTION:
+i2d_EC_PUBKEY                           3521   EXIST::FUNCTION:EC
+ECDSA_get_default_method                3522   EXIST::FUNCTION:ECDSA
+ASN1_put_eoc                            3523   EXIST::FUNCTION:
+X509_STORE_CTX_get_explicit_policy      3524   EXIST:!VMS:FUNCTION:
+X509_STORE_CTX_get_expl_policy          3524   EXIST:VMS:FUNCTION:
+X509_VERIFY_PARAM_table_cleanup         3525   EXIST::FUNCTION:
+STORE_modify_private_key                3526   NOEXIST::FUNCTION:
+X509_VERIFY_PARAM_free                  3527   EXIST::FUNCTION:
+EC_METHOD_get_field_type                3528   EXIST::FUNCTION:EC
+EC_GFp_nist_method                      3529   EXIST::FUNCTION:EC
+STORE_meth_set_modify_fn                3530   NOEXIST::FUNCTION:
+STORE_method_set_modify_function        3530   NOEXIST::FUNCTION:
+STORE_parse_attrs_next                  3531   NOEXIST::FUNCTION:
+ENGINE_load_padlock                     3532   EXIST::FUNCTION:ENGINE,STATIC_ENGINE
+EC_GROUP_set_curve_name                 3533   EXIST::FUNCTION:EC
+X509_CERT_PAIR_it                       3534   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+X509_CERT_PAIR_it                       3534   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+STORE_meth_get_revoke_fn                3535   NOEXIST::FUNCTION:
+STORE_method_get_revoke_function        3535   NOEXIST::FUNCTION:
+STORE_method_set_get_function           3536   NOEXIST::FUNCTION:
+STORE_modify_number                     3537   NOEXIST::FUNCTION:
+STORE_method_get_store_function         3538   NOEXIST::FUNCTION:
+STORE_store_private_key                 3539   NOEXIST::FUNCTION:
+BN_GF2m_mod_sqr_arr                     3540   EXIST::FUNCTION:
+RSA_setup_blinding                      3541   EXIST::FUNCTION:RSA
+BIO_s_datagram                          3542   EXIST::FUNCTION:DGRAM
+STORE_Memory                            3543   NOEXIST::FUNCTION:
+sk_find_ex                              3544   EXIST::FUNCTION:
+EC_GROUP_set_curve_GF2m                 3545   EXIST::FUNCTION:EC
+ENGINE_set_default_ECDSA                3546   EXIST::FUNCTION:ENGINE
+POLICY_CONSTRAINTS_new                  3547   EXIST::FUNCTION:
+BN_GF2m_mod_sqrt                        3548   EXIST::FUNCTION:
+ECDH_set_default_method                 3549   EXIST::FUNCTION:ECDH
+EC_KEY_generate_key                     3550   EXIST::FUNCTION:EC
+SHA384_Update                           3551   EXIST:!VMSVAX:FUNCTION:SHA,SHA512
+BN_GF2m_arr2poly                        3552   EXIST::FUNCTION:
+STORE_method_get_get_function           3553   NOEXIST::FUNCTION:
+STORE_meth_set_cleanup_fn               3554   NOEXIST::FUNCTION:
+STORE_method_set_cleanup_function       3554   NOEXIST::FUNCTION:
+EC_GROUP_check                          3555   EXIST::FUNCTION:EC
+d2i_ECPrivateKey_bio                    3556   EXIST::FUNCTION:BIO,EC
+EC_KEY_insert_key_method_data           3557   EXIST::FUNCTION:EC
+STORE_meth_get_lock_store_fn            3558   NOEXIST::FUNCTION:
+STORE_method_get_lock_store_function    3558   NOEXIST::FUNCTION:
+X509_VERIFY_PARAM_get_depth             3559   EXIST::FUNCTION:
+SHA224_Final                            3560   EXIST::FUNCTION:SHA,SHA256
+STORE_meth_set_update_store_fn          3561   NOEXIST::FUNCTION:
+STORE_method_set_update_store_function  3561   NOEXIST::FUNCTION:
+SHA224_Update                           3562   EXIST::FUNCTION:SHA,SHA256
+d2i_ECPrivateKey                        3563   EXIST::FUNCTION:EC
+ASN1_item_ndef_i2d                      3564   EXIST::FUNCTION:
+STORE_delete_private_key                3565   NOEXIST::FUNCTION:
+ERR_pop_to_mark                         3566   EXIST::FUNCTION:
+ENGINE_register_all_STORE               3567   EXIST::FUNCTION:ENGINE
+X509_policy_level_get0_node             3568   EXIST::FUNCTION:
+i2d_PKCS7_NDEF                          3569   EXIST::FUNCTION:
+EC_GROUP_get_degree                     3570   EXIST::FUNCTION:EC
+ASN1_generate_v3                        3571   EXIST::FUNCTION:
+STORE_ATTR_INFO_modify_cstr             3572   NOEXIST::FUNCTION:
+X509_policy_tree_level_count            3573   EXIST::FUNCTION:
+BN_GF2m_add                             3574   EXIST::FUNCTION:
+EC_KEY_get0_group                       3575   EXIST::FUNCTION:EC
+STORE_generate_crl                      3576   NOEXIST::FUNCTION:
+STORE_store_public_key                  3577   NOEXIST::FUNCTION:
+X509_CERT_PAIR_free                     3578   EXIST::FUNCTION:
+STORE_revoke_private_key                3579   NOEXIST::FUNCTION:
+BN_nist_mod_224                         3580   EXIST::FUNCTION:
+SHA512_Final                            3581   EXIST:!VMSVAX:FUNCTION:SHA,SHA512
+STORE_ATTR_INFO_modify_dn               3582   NOEXIST::FUNCTION:
+STORE_meth_get_initialise_fn            3583   NOEXIST::FUNCTION:
+STORE_method_get_initialise_function    3583   NOEXIST::FUNCTION:
+STORE_delete_number                     3584   NOEXIST::FUNCTION:
+i2d_EC_PUBKEY_bio                       3585   EXIST::FUNCTION:BIO,EC
+BIO_dgram_non_fatal_error               3586   EXIST::FUNCTION:
+EC_GROUP_get_asn1_flag                  3587   EXIST::FUNCTION:EC
+STORE_ATTR_INFO_in_ex                   3588   NOEXIST::FUNCTION:
+STORE_list_crl_start                    3589   NOEXIST::FUNCTION:
+ECDH_get_ex_new_index                   3590   EXIST::FUNCTION:ECDH
+STORE_meth_get_modify_fn                3591   NOEXIST::FUNCTION:
+STORE_method_get_modify_function        3591   NOEXIST::FUNCTION:
+v2i_ASN1_BIT_STRING                     3592   EXIST::FUNCTION:
+STORE_store_certificate                 3593   NOEXIST::FUNCTION:
+OBJ_bsearch_ex                          3594   NOEXIST::FUNCTION:
+X509_STORE_CTX_set_default              3595   EXIST::FUNCTION:
+STORE_ATTR_INFO_set_sha1str             3596   NOEXIST::FUNCTION:
+BN_GF2m_mod_inv                         3597   EXIST::FUNCTION:
+BN_GF2m_mod_exp                         3598   EXIST::FUNCTION:
+STORE_modify_public_key                 3599   NOEXIST::FUNCTION:
+STORE_meth_get_list_start_fn            3600   NOEXIST::FUNCTION:
+STORE_method_get_list_start_function    3600   NOEXIST::FUNCTION:
+EC_GROUP_get0_seed                      3601   EXIST::FUNCTION:EC
+STORE_store_arbitrary                   3602   NOEXIST::FUNCTION:
+STORE_meth_set_unlock_store_fn          3603   NOEXIST::FUNCTION:
+STORE_method_set_unlock_store_function  3603   NOEXIST::FUNCTION:
+BN_GF2m_mod_div_arr                     3604   EXIST::FUNCTION:
+ENGINE_set_ECDSA                        3605   EXIST::FUNCTION:ENGINE
+STORE_create_method                     3606   NOEXIST::FUNCTION:
+ECPKParameters_print                    3607   EXIST::FUNCTION:BIO,EC
+EC_KEY_get0_private_key                 3608   EXIST::FUNCTION:EC
+PEM_write_EC_PUBKEY                     3609   EXIST:!WIN16:FUNCTION:EC
+X509_VERIFY_PARAM_set1                  3610   EXIST::FUNCTION:
+ECDH_set_method                         3611   EXIST::FUNCTION:ECDH
+v2i_GENERAL_NAME_ex                     3612   EXIST::FUNCTION:
+ECDH_set_ex_data                        3613   EXIST::FUNCTION:ECDH
+STORE_generate_key                      3614   NOEXIST::FUNCTION:
+BN_nist_mod_521                         3615   EXIST::FUNCTION:
+X509_policy_tree_get0_level             3616   EXIST::FUNCTION:
+EC_GROUP_set_point_conversion_form      3617   EXIST:!VMS:FUNCTION:EC
+EC_GROUP_set_point_conv_form            3617   EXIST:VMS:FUNCTION:EC
+PEM_read_EC_PUBKEY                      3618   EXIST:!WIN16:FUNCTION:EC
+i2d_ECDSA_SIG                           3619   EXIST::FUNCTION:ECDSA
+ECDSA_OpenSSL                           3620   EXIST::FUNCTION:ECDSA
+STORE_delete_crl                        3621   NOEXIST::FUNCTION:
+EC_KEY_get_enc_flags                    3622   EXIST::FUNCTION:EC
+ASN1_const_check_infinite_end           3623   EXIST::FUNCTION:
+EVP_PKEY_delete_attr                    3624   EXIST::FUNCTION:
+ECDSA_set_default_method                3625   EXIST::FUNCTION:ECDSA
+EC_POINT_set_compressed_coordinates_GF2m 3626  EXIST:!VMS:FUNCTION:EC
+EC_POINT_set_compr_coords_GF2m          3626   EXIST:VMS:FUNCTION:EC
+EC_GROUP_cmp                            3627   EXIST::FUNCTION:EC
+STORE_revoke_certificate                3628   NOEXIST::FUNCTION:
+BN_get0_nist_prime_256                  3629   EXIST::FUNCTION:
+STORE_meth_get_delete_fn                3630   NOEXIST::FUNCTION:
+STORE_method_get_delete_function        3630   NOEXIST::FUNCTION:
+SHA224_Init                             3631   EXIST::FUNCTION:SHA,SHA256
+PEM_read_ECPrivateKey                   3632   EXIST:!WIN16:FUNCTION:EC
+SHA512_Init                             3633   EXIST:!VMSVAX:FUNCTION:SHA,SHA512
+STORE_parse_attrs_endp                  3634   NOEXIST::FUNCTION:
+BN_set_negative                         3635   EXIST::FUNCTION:
+ERR_load_ECDSA_strings                  3636   EXIST::FUNCTION:ECDSA
+EC_GROUP_get_basis_type                 3637   EXIST::FUNCTION:EC
+STORE_list_public_key_next              3638   NOEXIST::FUNCTION:
+i2v_ASN1_BIT_STRING                     3639   EXIST::FUNCTION:
+STORE_OBJECT_free                       3640   NOEXIST::FUNCTION:
+BN_nist_mod_384                         3641   EXIST::FUNCTION:
+i2d_X509_CERT_PAIR                      3642   EXIST::FUNCTION:
+PEM_write_ECPKParameters                3643   EXIST:!WIN16:FUNCTION:EC
+ECDH_compute_key                        3644   EXIST::FUNCTION:ECDH
+STORE_ATTR_INFO_get0_sha1str            3645   NOEXIST::FUNCTION:
+ENGINE_register_all_ECDH                3646   EXIST::FUNCTION:ENGINE
+pqueue_pop                              3647   EXIST::FUNCTION:
+STORE_ATTR_INFO_get0_cstr               3648   NOEXIST::FUNCTION:
+POLICY_CONSTRAINTS_it                   3649   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+POLICY_CONSTRAINTS_it                   3649   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+STORE_get_ex_new_index                  3650   NOEXIST::FUNCTION:
+EVP_PKEY_get_attr_by_OBJ                3651   EXIST::FUNCTION:
+X509_VERIFY_PARAM_add0_policy           3652   EXIST::FUNCTION:
+BN_GF2m_mod_solve_quad                  3653   EXIST::FUNCTION:
+SHA256                                  3654   EXIST::FUNCTION:SHA,SHA256
+i2d_ECPrivateKey_fp                     3655   EXIST::FUNCTION:EC,FP_API
+X509_policy_tree_get0_user_policies     3656   EXIST:!VMS:FUNCTION:
+X509_pcy_tree_get0_usr_policies         3656   EXIST:VMS:FUNCTION:
+OPENSSL_DIR_read                        3657   EXIST::FUNCTION:
+ENGINE_register_all_ECDSA               3658   EXIST::FUNCTION:ENGINE
+X509_VERIFY_PARAM_lookup                3659   EXIST::FUNCTION:
+EC_POINT_get_affine_coordinates_GF2m    3660   EXIST:!VMS:FUNCTION:EC
+EC_POINT_get_affine_coords_GF2m         3660   EXIST:VMS:FUNCTION:EC
+EC_GROUP_dup                            3661   EXIST::FUNCTION:EC
+ENGINE_get_default_ECDSA                3662   EXIST::FUNCTION:ENGINE
+EC_KEY_new                              3663   EXIST::FUNCTION:EC
+SHA256_Transform                        3664   EXIST::FUNCTION:SHA,SHA256
+EC_KEY_set_enc_flags                    3665   EXIST::FUNCTION:EC
+ECDSA_verify                            3666   EXIST::FUNCTION:ECDSA
+EC_POINT_point2hex                      3667   EXIST::FUNCTION:EC
+ENGINE_get_STORE                        3668   EXIST::FUNCTION:ENGINE
+SHA512                                  3669   EXIST:!VMSVAX:FUNCTION:SHA,SHA512
+STORE_get_certificate                   3670   NOEXIST::FUNCTION:
+ECDSA_do_sign_ex                        3671   EXIST::FUNCTION:ECDSA
+ECDSA_do_verify                         3672   EXIST::FUNCTION:ECDSA
+d2i_ECPrivateKey_fp                     3673   EXIST::FUNCTION:EC,FP_API
+STORE_delete_certificate                3674   NOEXIST::FUNCTION:
+SHA512_Transform                        3675   EXIST:!VMSVAX:FUNCTION:SHA,SHA512
+X509_STORE_set1_param                   3676   EXIST::FUNCTION:
+STORE_method_get_ctrl_function          3677   NOEXIST::FUNCTION:
+STORE_free                              3678   NOEXIST::FUNCTION:
+PEM_write_ECPrivateKey                  3679   EXIST:!WIN16:FUNCTION:EC
+STORE_meth_get_unlock_store_fn          3680   NOEXIST::FUNCTION:
+STORE_method_get_unlock_store_function  3680   NOEXIST::FUNCTION:
+STORE_get_ex_data                       3681   NOEXIST::FUNCTION:
+EC_KEY_set_public_key                   3682   EXIST::FUNCTION:EC
+PEM_read_ECPKParameters                 3683   EXIST:!WIN16:FUNCTION:EC
+X509_CERT_PAIR_new                      3684   EXIST::FUNCTION:
+ENGINE_register_STORE                   3685   EXIST::FUNCTION:ENGINE
+RSA_generate_key_ex                     3686   EXIST::FUNCTION:RSA
+DSA_generate_parameters_ex              3687   EXIST::FUNCTION:DSA
+ECParameters_print_fp                   3688   EXIST::FUNCTION:EC,FP_API
+X509V3_NAME_from_section                3689   EXIST::FUNCTION:
+EVP_PKEY_add1_attr                      3690   EXIST::FUNCTION:
+STORE_modify_crl                        3691   NOEXIST::FUNCTION:
+STORE_list_private_key_start            3692   NOEXIST::FUNCTION:
+POLICY_MAPPINGS_it                      3693   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+POLICY_MAPPINGS_it                      3693   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+GENERAL_SUBTREE_it                      3694   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+GENERAL_SUBTREE_it                      3694   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+EC_GROUP_get_curve_name                 3695   EXIST::FUNCTION:EC
+PEM_write_X509_CERT_PAIR                3696   EXIST:!WIN16:FUNCTION:
+BIO_dump_indent_cb                      3697   EXIST::FUNCTION:
+d2i_X509_CERT_PAIR                      3698   EXIST::FUNCTION:
+STORE_list_private_key_endp             3699   NOEXIST::FUNCTION:
+asn1_const_Finish                       3700   EXIST::FUNCTION:
+i2d_EC_PUBKEY_fp                        3701   EXIST::FUNCTION:EC,FP_API
+BN_nist_mod_256                         3702   EXIST::FUNCTION:
+X509_VERIFY_PARAM_add0_table            3703   EXIST::FUNCTION:
+pqueue_free                             3704   EXIST::FUNCTION:
+BN_BLINDING_create_param                3705   EXIST::FUNCTION:
+ECDSA_size                              3706   EXIST::FUNCTION:ECDSA
+d2i_EC_PUBKEY_bio                       3707   EXIST::FUNCTION:BIO,EC
+BN_get0_nist_prime_521                  3708   EXIST::FUNCTION:
+STORE_ATTR_INFO_modify_sha1str          3709   NOEXIST::FUNCTION:
+BN_generate_prime_ex                    3710   EXIST::FUNCTION:
+EC_GROUP_new_by_curve_name              3711   EXIST::FUNCTION:EC
+SHA256_Final                            3712   EXIST::FUNCTION:SHA,SHA256
+DH_generate_parameters_ex               3713   EXIST::FUNCTION:DH
+PEM_read_bio_ECPrivateKey               3714   EXIST::FUNCTION:EC
+STORE_meth_get_cleanup_fn               3715   NOEXIST::FUNCTION:
+STORE_method_get_cleanup_function       3715   NOEXIST::FUNCTION:
+ENGINE_get_ECDH                         3716   EXIST::FUNCTION:ENGINE
+d2i_ECDSA_SIG                           3717   EXIST::FUNCTION:ECDSA
+BN_is_prime_fasttest_ex                 3718   EXIST::FUNCTION:
+ECDSA_sign                              3719   EXIST::FUNCTION:ECDSA
+X509_policy_check                       3720   EXIST::FUNCTION:
+EVP_PKEY_get_attr_by_NID                3721   EXIST::FUNCTION:
+STORE_set_ex_data                       3722   NOEXIST::FUNCTION:
+ENGINE_get_ECDSA                        3723   EXIST::FUNCTION:ENGINE
+EVP_ecdsa                               3724   EXIST::FUNCTION:SHA
+BN_BLINDING_get_flags                   3725   EXIST::FUNCTION:
+PKCS12_add_cert                         3726   EXIST::FUNCTION:
+STORE_OBJECT_new                        3727   NOEXIST::FUNCTION:
+ERR_load_ECDH_strings                   3728   EXIST::FUNCTION:ECDH
+EC_KEY_dup                              3729   EXIST::FUNCTION:EC
+EVP_CIPHER_CTX_rand_key                 3730   EXIST::FUNCTION:
+ECDSA_set_method                        3731   EXIST::FUNCTION:ECDSA
+a2i_IPADDRESS_NC                        3732   EXIST::FUNCTION:
+d2i_ECParameters                        3733   EXIST::FUNCTION:EC
+STORE_list_certificate_end              3734   NOEXIST::FUNCTION:
+STORE_get_crl                           3735   NOEXIST::FUNCTION:
+X509_POLICY_NODE_print                  3736   EXIST::FUNCTION:
+SHA384_Init                             3737   EXIST:!VMSVAX:FUNCTION:SHA,SHA512
+EC_GF2m_simple_method                   3738   EXIST::FUNCTION:EC
+ECDSA_set_ex_data                       3739   EXIST::FUNCTION:ECDSA
+SHA384_Final                            3740   EXIST:!VMSVAX:FUNCTION:SHA,SHA512
+PKCS7_set_digest                        3741   EXIST::FUNCTION:
+EC_KEY_print                            3742   EXIST::FUNCTION:BIO,EC
+STORE_meth_set_lock_store_fn            3743   NOEXIST::FUNCTION:
+STORE_method_set_lock_store_function    3743   NOEXIST::FUNCTION:
+ECDSA_get_ex_new_index                  3744   EXIST::FUNCTION:ECDSA
+SHA384                                  3745   EXIST:!VMSVAX:FUNCTION:SHA,SHA512
+POLICY_MAPPING_new                      3746   EXIST::FUNCTION:
+STORE_list_certificate_endp             3747   NOEXIST::FUNCTION:
+X509_STORE_CTX_get0_policy_tree         3748   EXIST::FUNCTION:
+EC_GROUP_set_asn1_flag                  3749   EXIST::FUNCTION:EC
+EC_KEY_check_key                        3750   EXIST::FUNCTION:EC
+d2i_EC_PUBKEY_fp                        3751   EXIST::FUNCTION:EC,FP_API
+PKCS7_set0_type_other                   3752   EXIST::FUNCTION:
+PEM_read_bio_X509_CERT_PAIR             3753   EXIST::FUNCTION:
+pqueue_next                             3754   EXIST::FUNCTION:
+STORE_meth_get_list_end_fn              3755   NOEXIST::FUNCTION:
+STORE_method_get_list_end_function      3755   NOEXIST::FUNCTION:
+EVP_PKEY_add1_attr_by_OBJ               3756   EXIST::FUNCTION:
+X509_VERIFY_PARAM_set_time              3757   EXIST::FUNCTION:
+pqueue_new                              3758   EXIST::FUNCTION:
+ENGINE_set_default_ECDH                 3759   EXIST::FUNCTION:ENGINE
+STORE_new_method                        3760   NOEXIST::FUNCTION:
+PKCS12_add_key                          3761   EXIST::FUNCTION:
+DSO_merge                               3762   EXIST::FUNCTION:
+EC_POINT_hex2point                      3763   EXIST::FUNCTION:EC
+BIO_dump_cb                             3764   EXIST::FUNCTION:
+SHA256_Update                           3765   EXIST::FUNCTION:SHA,SHA256
+pqueue_insert                           3766   EXIST::FUNCTION:
+pitem_free                              3767   EXIST::FUNCTION:
+BN_GF2m_mod_inv_arr                     3768   EXIST::FUNCTION:
+ENGINE_unregister_ECDSA                 3769   EXIST::FUNCTION:ENGINE
+BN_BLINDING_set_thread_id               3770   EXIST::FUNCTION:DEPRECATED
+get_rfc3526_prime_8192                  3771   EXIST::FUNCTION:
+X509_VERIFY_PARAM_clear_flags           3772   EXIST::FUNCTION:
+get_rfc2409_prime_1024                  3773   EXIST::FUNCTION:
+DH_check_pub_key                        3774   EXIST::FUNCTION:DH
+get_rfc3526_prime_2048                  3775   EXIST::FUNCTION:
+get_rfc3526_prime_6144                  3776   EXIST::FUNCTION:
+get_rfc3526_prime_1536                  3777   EXIST::FUNCTION:
+get_rfc3526_prime_3072                  3778   EXIST::FUNCTION:
+get_rfc3526_prime_4096                  3779   EXIST::FUNCTION:
+get_rfc2409_prime_768                   3780   EXIST::FUNCTION:
+X509_VERIFY_PARAM_get_flags             3781   EXIST::FUNCTION:
+EVP_CIPHER_CTX_new                      3782   EXIST::FUNCTION:
+EVP_CIPHER_CTX_free                     3783   EXIST::FUNCTION:
+Camellia_cbc_encrypt                    3784   EXIST::FUNCTION:CAMELLIA
+Camellia_cfb128_encrypt                 3785   EXIST::FUNCTION:CAMELLIA
+Camellia_cfb1_encrypt                   3786   EXIST::FUNCTION:CAMELLIA
+Camellia_cfb8_encrypt                   3787   EXIST::FUNCTION:CAMELLIA
+Camellia_ctr128_encrypt                 3788   EXIST::FUNCTION:CAMELLIA
+Camellia_cfbr_encrypt_block             3789   NOEXIST::FUNCTION:
+Camellia_decrypt                        3790   EXIST::FUNCTION:CAMELLIA
+Camellia_ecb_encrypt                    3791   EXIST::FUNCTION:CAMELLIA
+Camellia_encrypt                        3792   EXIST::FUNCTION:CAMELLIA
+Camellia_ofb128_encrypt                 3793   EXIST::FUNCTION:CAMELLIA
+Camellia_set_key                        3794   EXIST::FUNCTION:CAMELLIA
+EVP_camellia_128_cbc                    3795   EXIST::FUNCTION:CAMELLIA
+EVP_camellia_128_cfb128                 3796   EXIST::FUNCTION:CAMELLIA
+EVP_camellia_128_cfb1                   3797   EXIST::FUNCTION:CAMELLIA
+EVP_camellia_128_cfb8                   3798   EXIST::FUNCTION:CAMELLIA
+EVP_camellia_128_ecb                    3799   EXIST::FUNCTION:CAMELLIA
+EVP_camellia_128_ofb                    3800   EXIST::FUNCTION:CAMELLIA
+EVP_camellia_192_cbc                    3801   EXIST::FUNCTION:CAMELLIA
+EVP_camellia_192_cfb128                 3802   EXIST::FUNCTION:CAMELLIA
+EVP_camellia_192_cfb1                   3803   EXIST::FUNCTION:CAMELLIA
+EVP_camellia_192_cfb8                   3804   EXIST::FUNCTION:CAMELLIA
+EVP_camellia_192_ecb                    3805   EXIST::FUNCTION:CAMELLIA
+EVP_camellia_192_ofb                    3806   EXIST::FUNCTION:CAMELLIA
+EVP_camellia_256_cbc                    3807   EXIST::FUNCTION:CAMELLIA
+EVP_camellia_256_cfb128                 3808   EXIST::FUNCTION:CAMELLIA
+EVP_camellia_256_cfb1                   3809   EXIST::FUNCTION:CAMELLIA
+EVP_camellia_256_cfb8                   3810   EXIST::FUNCTION:CAMELLIA
+EVP_camellia_256_ecb                    3811   EXIST::FUNCTION:CAMELLIA
+EVP_camellia_256_ofb                    3812   EXIST::FUNCTION:CAMELLIA
+a2i_ipadd                               3813   EXIST::FUNCTION:
+ASIdentifiers_free                      3814   EXIST::FUNCTION:RFC3779
+i2d_ASIdOrRange                         3815   EXIST::FUNCTION:RFC3779
+EVP_CIPHER_block_size                   3816   EXIST::FUNCTION:
+v3_asid_is_canonical                    3817   EXIST::FUNCTION:RFC3779
+IPAddressChoice_free                    3818   EXIST::FUNCTION:RFC3779
+EVP_CIPHER_CTX_set_app_data             3819   EXIST::FUNCTION:
+BIO_set_callback_arg                    3820   EXIST::FUNCTION:
+v3_addr_add_prefix                      3821   EXIST::FUNCTION:RFC3779
+IPAddressOrRange_it                     3822   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:RFC3779
+IPAddressOrRange_it                     3822   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:RFC3779
+BIO_set_flags                           3823   EXIST::FUNCTION:
+ASIdentifiers_it                        3824   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:RFC3779
+ASIdentifiers_it                        3824   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:RFC3779
+v3_addr_get_range                       3825   EXIST::FUNCTION:RFC3779
+BIO_method_type                         3826   EXIST::FUNCTION:
+v3_addr_inherits                        3827   EXIST::FUNCTION:RFC3779
+IPAddressChoice_it                      3828   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:RFC3779
+IPAddressChoice_it                      3828   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:RFC3779
+AES_ige_encrypt                         3829   EXIST::FUNCTION:AES
+v3_addr_add_range                       3830   EXIST::FUNCTION:RFC3779
+EVP_CIPHER_CTX_nid                      3831   EXIST::FUNCTION:
+d2i_ASRange                             3832   EXIST::FUNCTION:RFC3779
+v3_addr_add_inherit                     3833   EXIST::FUNCTION:RFC3779
+v3_asid_add_id_or_range                 3834   EXIST::FUNCTION:RFC3779
+v3_addr_validate_resource_set           3835   EXIST::FUNCTION:RFC3779
+EVP_CIPHER_iv_length                    3836   EXIST::FUNCTION:
+EVP_MD_type                             3837   EXIST::FUNCTION:
+v3_asid_canonize                        3838   EXIST::FUNCTION:RFC3779
+IPAddressRange_free                     3839   EXIST::FUNCTION:RFC3779
+v3_asid_add_inherit                     3840   EXIST::FUNCTION:RFC3779
+EVP_CIPHER_CTX_key_length               3841   EXIST::FUNCTION:
+IPAddressRange_new                      3842   EXIST::FUNCTION:RFC3779
+ASIdOrRange_new                         3843   EXIST::FUNCTION:RFC3779
+EVP_MD_size                             3844   EXIST::FUNCTION:
+EVP_MD_CTX_test_flags                   3845   EXIST::FUNCTION:
+BIO_clear_flags                         3846   EXIST::FUNCTION:
+i2d_ASRange                             3847   EXIST::FUNCTION:RFC3779
+IPAddressRange_it                       3848   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:RFC3779
+IPAddressRange_it                       3848   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:RFC3779
+IPAddressChoice_new                     3849   EXIST::FUNCTION:RFC3779
+ASIdentifierChoice_new                  3850   EXIST::FUNCTION:RFC3779
+ASRange_free                            3851   EXIST::FUNCTION:RFC3779
+EVP_MD_pkey_type                        3852   EXIST::FUNCTION:
+EVP_MD_CTX_clear_flags                  3853   EXIST::FUNCTION:
+IPAddressFamily_free                    3854   EXIST::FUNCTION:RFC3779
+i2d_IPAddressFamily                     3855   EXIST::FUNCTION:RFC3779
+IPAddressOrRange_new                    3856   EXIST::FUNCTION:RFC3779
+EVP_CIPHER_flags                        3857   EXIST::FUNCTION:
+v3_asid_validate_resource_set           3858   EXIST::FUNCTION:RFC3779
+d2i_IPAddressRange                      3859   EXIST::FUNCTION:RFC3779
+AES_bi_ige_encrypt                      3860   EXIST::FUNCTION:AES
+BIO_get_callback                        3861   EXIST::FUNCTION:
+IPAddressOrRange_free                   3862   EXIST::FUNCTION:RFC3779
+v3_addr_subset                          3863   EXIST::FUNCTION:RFC3779
+d2i_IPAddressFamily                     3864   EXIST::FUNCTION:RFC3779
+v3_asid_subset                          3865   EXIST::FUNCTION:RFC3779
+BIO_test_flags                          3866   EXIST::FUNCTION:
+i2d_ASIdentifierChoice                  3867   EXIST::FUNCTION:RFC3779
+ASRange_it                              3868   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:RFC3779
+ASRange_it                              3868   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:RFC3779
+d2i_ASIdentifiers                       3869   EXIST::FUNCTION:RFC3779
+ASRange_new                             3870   EXIST::FUNCTION:RFC3779
+d2i_IPAddressChoice                     3871   EXIST::FUNCTION:RFC3779
+v3_addr_get_afi                         3872   EXIST::FUNCTION:RFC3779
+EVP_CIPHER_key_length                   3873   EXIST::FUNCTION:
+EVP_Cipher                              3874   EXIST::FUNCTION:
+i2d_IPAddressOrRange                    3875   EXIST::FUNCTION:RFC3779
+ASIdOrRange_it                          3876   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:RFC3779
+ASIdOrRange_it                          3876   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:RFC3779
+EVP_CIPHER_nid                          3877   EXIST::FUNCTION:
+i2d_IPAddressChoice                     3878   EXIST::FUNCTION:RFC3779
+EVP_CIPHER_CTX_block_size               3879   EXIST::FUNCTION:
+ASIdentifiers_new                       3880   EXIST::FUNCTION:RFC3779
+v3_addr_validate_path                   3881   EXIST::FUNCTION:RFC3779
+IPAddressFamily_new                     3882   EXIST::FUNCTION:RFC3779
+EVP_MD_CTX_set_flags                    3883   EXIST::FUNCTION:
+v3_addr_is_canonical                    3884   EXIST::FUNCTION:RFC3779
+i2d_IPAddressRange                      3885   EXIST::FUNCTION:RFC3779
+IPAddressFamily_it                      3886   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:RFC3779
+IPAddressFamily_it                      3886   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:RFC3779
+v3_asid_inherits                        3887   EXIST::FUNCTION:RFC3779
+EVP_CIPHER_CTX_cipher                   3888   EXIST::FUNCTION:
+EVP_CIPHER_CTX_get_app_data             3889   EXIST::FUNCTION:
+EVP_MD_block_size                       3890   EXIST::FUNCTION:
+EVP_CIPHER_CTX_flags                    3891   EXIST::FUNCTION:
+v3_asid_validate_path                   3892   EXIST::FUNCTION:RFC3779
+d2i_IPAddressOrRange                    3893   EXIST::FUNCTION:RFC3779
+v3_addr_canonize                        3894   EXIST::FUNCTION:RFC3779
+ASIdentifierChoice_it                   3895   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:RFC3779
+ASIdentifierChoice_it                   3895   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:RFC3779
+EVP_MD_CTX_md                           3896   EXIST::FUNCTION:
+d2i_ASIdentifierChoice                  3897   EXIST::FUNCTION:RFC3779
+BIO_method_name                         3898   EXIST::FUNCTION:
+EVP_CIPHER_CTX_iv_length                3899   EXIST::FUNCTION:
+ASIdOrRange_free                        3900   EXIST::FUNCTION:RFC3779
+ASIdentifierChoice_free                 3901   EXIST::FUNCTION:RFC3779
+BIO_get_callback_arg                    3902   EXIST::FUNCTION:
+BIO_set_callback                        3903   EXIST::FUNCTION:
+d2i_ASIdOrRange                         3904   EXIST::FUNCTION:RFC3779
+i2d_ASIdentifiers                       3905   EXIST::FUNCTION:RFC3779
+SEED_decrypt                            3908   EXIST::FUNCTION:SEED
+SEED_encrypt                            3909   EXIST::FUNCTION:SEED
+SEED_cbc_encrypt                        3910   EXIST::FUNCTION:SEED
+EVP_seed_ofb                            3911   EXIST::FUNCTION:SEED
+SEED_cfb128_encrypt                     3912   EXIST::FUNCTION:SEED
+SEED_ofb128_encrypt                     3913   EXIST::FUNCTION:SEED
+EVP_seed_cbc                            3914   EXIST::FUNCTION:SEED
+SEED_ecb_encrypt                        3915   EXIST::FUNCTION:SEED
+EVP_seed_ecb                            3916   EXIST::FUNCTION:SEED
+SEED_set_key                            3917   EXIST::FUNCTION:SEED
+EVP_seed_cfb128                         3918   EXIST::FUNCTION:SEED
+X509_EXTENSIONS_it                      3919   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+X509_EXTENSIONS_it                      3919   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+X509_get1_ocsp                          3920   EXIST::FUNCTION:
+OCSP_REQ_CTX_free                       3921   EXIST::FUNCTION:
+i2d_X509_EXTENSIONS                     3922   EXIST::FUNCTION:
+OCSP_sendreq_nbio                       3923   EXIST::FUNCTION:
+OCSP_sendreq_new                        3924   EXIST::FUNCTION:
+d2i_X509_EXTENSIONS                     3925   EXIST::FUNCTION:
+X509_ALGORS_it                          3926   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+X509_ALGORS_it                          3926   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+X509_ALGOR_get0                         3927   EXIST::FUNCTION:
+X509_ALGOR_set0                         3928   EXIST::FUNCTION:
+AES_unwrap_key                          3929   EXIST::FUNCTION:AES
+AES_wrap_key                            3930   EXIST::FUNCTION:AES
+X509at_get0_data_by_OBJ                 3931   EXIST::FUNCTION:
+ASN1_TYPE_set1                          3932   EXIST::FUNCTION:
+ASN1_STRING_set0                        3933   EXIST::FUNCTION:
+i2d_X509_ALGORS                         3934   EXIST::FUNCTION:
+BIO_f_zlib                              3935   EXIST:ZLIB:FUNCTION:
+COMP_zlib_cleanup                       3936   EXIST::FUNCTION:
+d2i_X509_ALGORS                         3937   EXIST::FUNCTION:
+CMS_ReceiptRequest_free                 3938   EXIST::FUNCTION:CMS
+PEM_write_CMS                           3939   EXIST:!WIN16:FUNCTION:CMS
+CMS_add0_CertificateChoices             3940   EXIST::FUNCTION:CMS
+CMS_unsigned_add1_attr_by_OBJ           3941   EXIST::FUNCTION:CMS
+ERR_load_CMS_strings                    3942   EXIST::FUNCTION:CMS
+CMS_sign_receipt                        3943   EXIST::FUNCTION:CMS
+i2d_CMS_ContentInfo                     3944   EXIST::FUNCTION:CMS
+CMS_signed_delete_attr                  3945   EXIST::FUNCTION:CMS
+d2i_CMS_bio                             3946   EXIST::FUNCTION:CMS
+CMS_unsigned_get_attr_by_NID            3947   EXIST::FUNCTION:CMS
+CMS_verify                              3948   EXIST::FUNCTION:CMS
+SMIME_read_CMS                          3949   EXIST::FUNCTION:CMS
+CMS_decrypt_set1_key                    3950   EXIST::FUNCTION:CMS
+CMS_SignerInfo_get0_algs                3951   EXIST::FUNCTION:CMS
+CMS_add1_cert                           3952   EXIST::FUNCTION:CMS
+CMS_set_detached                        3953   EXIST::FUNCTION:CMS
+CMS_encrypt                             3954   EXIST::FUNCTION:CMS
+CMS_EnvelopedData_create                3955   EXIST::FUNCTION:CMS
+CMS_uncompress                          3956   EXIST::FUNCTION:CMS
+CMS_add0_crl                            3957   EXIST::FUNCTION:CMS
+CMS_SignerInfo_verify_content           3958   EXIST::FUNCTION:CMS
+CMS_unsigned_get0_data_by_OBJ           3959   EXIST::FUNCTION:CMS
+PEM_write_bio_CMS                       3960   EXIST::FUNCTION:CMS
+CMS_unsigned_get_attr                   3961   EXIST::FUNCTION:CMS
+CMS_RecipientInfo_ktri_cert_cmp         3962   EXIST::FUNCTION:CMS
+CMS_RecipientInfo_ktri_get0_algs        3963   EXIST:!VMS:FUNCTION:CMS
+CMS_RecipInfo_ktri_get0_algs            3963   EXIST:VMS:FUNCTION:CMS
+CMS_ContentInfo_free                    3964   EXIST::FUNCTION:CMS
+CMS_final                               3965   EXIST::FUNCTION:CMS
+CMS_add_simple_smimecap                 3966   EXIST::FUNCTION:CMS
+CMS_SignerInfo_verify                   3967   EXIST::FUNCTION:CMS
+CMS_data                                3968   EXIST::FUNCTION:CMS
+CMS_ContentInfo_it                      3969   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:CMS
+CMS_ContentInfo_it                      3969   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:CMS
+d2i_CMS_ReceiptRequest                  3970   EXIST::FUNCTION:CMS
+CMS_compress                            3971   EXIST::FUNCTION:CMS
+CMS_digest_create                       3972   EXIST::FUNCTION:CMS
+CMS_SignerInfo_cert_cmp                 3973   EXIST::FUNCTION:CMS
+CMS_SignerInfo_sign                     3974   EXIST::FUNCTION:CMS
+CMS_data_create                         3975   EXIST::FUNCTION:CMS
+i2d_CMS_bio                             3976   EXIST::FUNCTION:CMS
+CMS_EncryptedData_set1_key              3977   EXIST::FUNCTION:CMS
+CMS_decrypt                             3978   EXIST::FUNCTION:CMS
+int_smime_write_ASN1                    3979   NOEXIST::FUNCTION:
+CMS_unsigned_delete_attr                3980   EXIST::FUNCTION:CMS
+CMS_unsigned_get_attr_count             3981   EXIST::FUNCTION:CMS
+CMS_add_smimecap                        3982   EXIST::FUNCTION:CMS
+PEM_read_CMS                            3983   EXIST:!WIN16:FUNCTION:CMS
+CMS_signed_get_attr_by_OBJ              3984   EXIST::FUNCTION:CMS
+d2i_CMS_ContentInfo                     3985   EXIST::FUNCTION:CMS
+CMS_add_standard_smimecap               3986   EXIST::FUNCTION:CMS
+CMS_ContentInfo_new                     3987   EXIST::FUNCTION:CMS
+CMS_RecipientInfo_type                  3988   EXIST::FUNCTION:CMS
+CMS_get0_type                           3989   EXIST::FUNCTION:CMS
+CMS_is_detached                         3990   EXIST::FUNCTION:CMS
+CMS_sign                                3991   EXIST::FUNCTION:CMS
+CMS_signed_add1_attr                    3992   EXIST::FUNCTION:CMS
+CMS_unsigned_get_attr_by_OBJ            3993   EXIST::FUNCTION:CMS
+SMIME_write_CMS                         3994   EXIST::FUNCTION:CMS
+CMS_EncryptedData_decrypt               3995   EXIST::FUNCTION:CMS
+CMS_get0_RecipientInfos                 3996   EXIST::FUNCTION:CMS
+CMS_add0_RevocationInfoChoice           3997   EXIST::FUNCTION:CMS
+CMS_decrypt_set1_pkey                   3998   EXIST::FUNCTION:CMS
+CMS_SignerInfo_set1_signer_cert         3999   EXIST::FUNCTION:CMS
+CMS_get0_signers                        4000   EXIST::FUNCTION:CMS
+CMS_ReceiptRequest_get0_values          4001   EXIST::FUNCTION:CMS
+CMS_signed_get0_data_by_OBJ             4002   EXIST::FUNCTION:CMS
+CMS_get0_SignerInfos                    4003   EXIST::FUNCTION:CMS
+CMS_add0_cert                           4004   EXIST::FUNCTION:CMS
+CMS_EncryptedData_encrypt               4005   EXIST::FUNCTION:CMS
+CMS_digest_verify                       4006   EXIST::FUNCTION:CMS
+CMS_set1_signers_certs                  4007   EXIST::FUNCTION:CMS
+CMS_signed_get_attr                     4008   EXIST::FUNCTION:CMS
+CMS_RecipientInfo_set0_key              4009   EXIST::FUNCTION:CMS
+CMS_SignedData_init                     4010   EXIST::FUNCTION:CMS
+CMS_RecipientInfo_kekri_get0_id         4011   EXIST::FUNCTION:CMS
+CMS_verify_receipt                      4012   EXIST::FUNCTION:CMS
+CMS_ReceiptRequest_it                   4013   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:CMS
+CMS_ReceiptRequest_it                   4013   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:CMS
+PEM_read_bio_CMS                        4014   EXIST::FUNCTION:CMS
+CMS_get1_crls                           4015   EXIST::FUNCTION:CMS
+CMS_add0_recipient_key                  4016   EXIST::FUNCTION:CMS
+SMIME_read_ASN1                         4017   EXIST::FUNCTION:
+CMS_ReceiptRequest_new                  4018   EXIST::FUNCTION:CMS
+CMS_get0_content                        4019   EXIST::FUNCTION:CMS
+CMS_get1_ReceiptRequest                 4020   EXIST::FUNCTION:CMS
+CMS_signed_add1_attr_by_OBJ             4021   EXIST::FUNCTION:CMS
+CMS_RecipientInfo_kekri_id_cmp          4022   EXIST::FUNCTION:CMS
+CMS_add1_ReceiptRequest                 4023   EXIST::FUNCTION:CMS
+CMS_SignerInfo_get0_signer_id           4024   EXIST::FUNCTION:CMS
+CMS_unsigned_add1_attr_by_NID           4025   EXIST::FUNCTION:CMS
+CMS_unsigned_add1_attr                  4026   EXIST::FUNCTION:CMS
+CMS_signed_get_attr_by_NID              4027   EXIST::FUNCTION:CMS
+CMS_get1_certs                          4028   EXIST::FUNCTION:CMS
+CMS_signed_add1_attr_by_NID             4029   EXIST::FUNCTION:CMS
+CMS_unsigned_add1_attr_by_txt           4030   EXIST::FUNCTION:CMS
+CMS_dataFinal                           4031   EXIST::FUNCTION:CMS
+CMS_RecipientInfo_ktri_get0_signer_id   4032   EXIST:!VMS:FUNCTION:CMS
+CMS_RecipInfo_ktri_get0_sigr_id         4032   EXIST:VMS:FUNCTION:CMS
+i2d_CMS_ReceiptRequest                  4033   EXIST::FUNCTION:CMS
+CMS_add1_recipient_cert                 4034   EXIST::FUNCTION:CMS
+CMS_dataInit                            4035   EXIST::FUNCTION:CMS
+CMS_signed_add1_attr_by_txt             4036   EXIST::FUNCTION:CMS
+CMS_RecipientInfo_decrypt               4037   EXIST::FUNCTION:CMS
+CMS_signed_get_attr_count               4038   EXIST::FUNCTION:CMS
+CMS_get0_eContentType                   4039   EXIST::FUNCTION:CMS
+CMS_set1_eContentType                   4040   EXIST::FUNCTION:CMS
+CMS_ReceiptRequest_create0              4041   EXIST::FUNCTION:CMS
+CMS_add1_signer                         4042   EXIST::FUNCTION:CMS
+CMS_RecipientInfo_set0_pkey             4043   EXIST::FUNCTION:CMS
+ENGINE_set_load_ssl_client_cert_function 4044  EXIST:!VMS:FUNCTION:ENGINE
+ENGINE_set_ld_ssl_clnt_cert_fn          4044   EXIST:VMS:FUNCTION:ENGINE
+ENGINE_get_ssl_client_cert_function     4045   EXIST:!VMS:FUNCTION:ENGINE
+ENGINE_get_ssl_client_cert_fn           4045   EXIST:VMS:FUNCTION:ENGINE
+ENGINE_load_ssl_client_cert             4046   EXIST::FUNCTION:ENGINE
+ENGINE_load_capi                        4047   EXIST::FUNCTION:ENGINE,STATIC_ENGINE
+OPENSSL_isservice                       4048   EXIST::FUNCTION:
+FIPS_dsa_sig_decode                     4049   NOEXIST::FUNCTION:
+EVP_CIPHER_CTX_clear_flags              4050   EXIST::FUNCTION:
+FIPS_rand_status                        4051   NOEXIST::FUNCTION:
+FIPS_rand_set_key                       4052   NOEXIST::FUNCTION:
+CRYPTO_set_mem_info_functions           4053   NOEXIST::FUNCTION:
+RSA_X931_generate_key_ex                4054   NOEXIST::FUNCTION:
+int_ERR_set_state_func                  4055   NOEXIST::FUNCTION:
+int_EVP_MD_set_engine_callbacks         4056   NOEXIST::FUNCTION:
+int_CRYPTO_set_do_dynlock_callback      4057   NOEXIST::FUNCTION:
+FIPS_rng_stick                          4058   NOEXIST::FUNCTION:
+EVP_CIPHER_CTX_set_flags                4059   EXIST::FUNCTION:
+BN_X931_generate_prime_ex               4060   NOEXIST::FUNCTION:
+FIPS_selftest_check                     4061   NOEXIST::FUNCTION:
+FIPS_rand_set_dt                        4062   NOEXIST::FUNCTION:
+CRYPTO_dbg_pop_info                     4063   NOEXIST::FUNCTION:
+FIPS_dsa_free                           4064   NOEXIST::FUNCTION:
+RSA_X931_derive_ex                      4065   NOEXIST::FUNCTION:
+FIPS_rsa_new                            4066   NOEXIST::FUNCTION:
+FIPS_rand_bytes                         4067   NOEXIST::FUNCTION:
+fips_cipher_test                        4068   NOEXIST::FUNCTION:
+EVP_CIPHER_CTX_test_flags               4069   EXIST::FUNCTION:
+CRYPTO_malloc_debug_init                4070   NOEXIST::FUNCTION:
+CRYPTO_dbg_push_info                    4071   NOEXIST::FUNCTION:
+FIPS_corrupt_rsa_keygen                 4072   NOEXIST::FUNCTION:
+FIPS_dh_new                             4073   NOEXIST::FUNCTION:
+FIPS_corrupt_dsa_keygen                 4074   NOEXIST::FUNCTION:
+FIPS_dh_free                            4075   NOEXIST::FUNCTION:
+fips_pkey_signature_test                4076   NOEXIST::FUNCTION:
+EVP_add_alg_module                      4077   NOEXIST::FUNCTION:
+int_RAND_init_engine_callbacks          4078   NOEXIST::FUNCTION:
+int_EVP_CIPHER_set_engine_callbacks     4079   NOEXIST::FUNCTION:
+int_EVP_MD_init_engine_callbacks        4080   NOEXIST::FUNCTION:
+FIPS_rand_test_mode                     4081   NOEXIST::FUNCTION:
+FIPS_rand_reset                         4082   NOEXIST::FUNCTION:
+FIPS_dsa_new                            4083   NOEXIST::FUNCTION:
+int_RAND_set_callbacks                  4084   NOEXIST::FUNCTION:
+BN_X931_derive_prime_ex                 4085   NOEXIST::FUNCTION:
+int_ERR_lib_init                        4086   NOEXIST::FUNCTION:
+int_EVP_CIPHER_init_engine_callbacks    4087   NOEXIST::FUNCTION:
+FIPS_rsa_free                           4088   NOEXIST::FUNCTION:
+FIPS_dsa_sig_encode                     4089   NOEXIST::FUNCTION:
+CRYPTO_dbg_remove_all_info              4090   NOEXIST::FUNCTION:
+OPENSSL_init                            4091   NOEXIST::FUNCTION:
+private_Camellia_set_key                4092   NOEXIST::FUNCTION:
+CRYPTO_strdup                           4093   EXIST::FUNCTION:
+JPAKE_STEP3A_process                    4094   EXIST::FUNCTION:JPAKE
+JPAKE_STEP1_release                     4095   EXIST::FUNCTION:JPAKE
+JPAKE_get_shared_key                    4096   EXIST::FUNCTION:JPAKE
+JPAKE_STEP3B_init                       4097   EXIST::FUNCTION:JPAKE
+JPAKE_STEP1_generate                    4098   EXIST::FUNCTION:JPAKE
+JPAKE_STEP1_init                        4099   EXIST::FUNCTION:JPAKE
+JPAKE_STEP3B_process                    4100   EXIST::FUNCTION:JPAKE
+JPAKE_STEP2_generate                    4101   EXIST::FUNCTION:JPAKE
+JPAKE_CTX_new                           4102   EXIST::FUNCTION:JPAKE
+JPAKE_CTX_free                          4103   EXIST::FUNCTION:JPAKE
+JPAKE_STEP3B_release                    4104   EXIST::FUNCTION:JPAKE
+JPAKE_STEP3A_release                    4105   EXIST::FUNCTION:JPAKE
+JPAKE_STEP2_process                     4106   EXIST::FUNCTION:JPAKE
+JPAKE_STEP3B_generate                   4107   EXIST::FUNCTION:JPAKE
+JPAKE_STEP1_process                     4108   EXIST::FUNCTION:JPAKE
+JPAKE_STEP3A_generate                   4109   EXIST::FUNCTION:JPAKE
+JPAKE_STEP2_release                     4110   EXIST::FUNCTION:JPAKE
+JPAKE_STEP3A_init                       4111   EXIST::FUNCTION:JPAKE
+ERR_load_JPAKE_strings                  4112   EXIST::FUNCTION:JPAKE
+JPAKE_STEP2_init                        4113   EXIST::FUNCTION:JPAKE
+pqueue_size                             4114   EXIST::FUNCTION:
+i2d_TS_ACCURACY                         4115   EXIST::FUNCTION:
+i2d_TS_MSG_IMPRINT_fp                   4116   EXIST::FUNCTION:
+i2d_TS_MSG_IMPRINT                      4117   EXIST::FUNCTION:
+EVP_PKEY_print_public                   4118   EXIST::FUNCTION:
+EVP_PKEY_CTX_new                        4119   EXIST::FUNCTION:
+i2d_TS_TST_INFO                         4120   EXIST::FUNCTION:
+EVP_PKEY_asn1_find                      4121   EXIST::FUNCTION:
+DSO_METHOD_beos                         4122   EXIST::FUNCTION:
+TS_CONF_load_cert                       4123   EXIST::FUNCTION:
+TS_REQ_get_ext                          4124   EXIST::FUNCTION:
+EVP_PKEY_sign_init                      4125   EXIST::FUNCTION:
+ASN1_item_print                         4126   EXIST::FUNCTION:
+TS_TST_INFO_set_nonce                   4127   EXIST::FUNCTION:
+TS_RESP_dup                             4128   EXIST::FUNCTION:
+ENGINE_register_pkey_meths              4129   EXIST::FUNCTION:ENGINE
+EVP_PKEY_asn1_add0                      4130   EXIST::FUNCTION:
+PKCS7_add0_attrib_signing_time          4131   EXIST::FUNCTION:
+i2d_TS_TST_INFO_fp                      4132   EXIST::FUNCTION:
+BIO_asn1_get_prefix                     4133   EXIST::FUNCTION:
+TS_TST_INFO_set_time                    4134   EXIST::FUNCTION:
+EVP_PKEY_meth_set_decrypt               4135   EXIST::FUNCTION:
+EVP_PKEY_set_type_str                   4136   EXIST::FUNCTION:
+EVP_PKEY_CTX_get_keygen_info            4137   EXIST::FUNCTION:
+TS_REQ_set_policy_id                    4138   EXIST::FUNCTION:
+d2i_TS_RESP_fp                          4139   EXIST::FUNCTION:
+ENGINE_get_pkey_asn1_meth_engine        4140   EXIST:!VMS:FUNCTION:ENGINE
+ENGINE_get_pkey_asn1_meth_eng           4140   EXIST:VMS:FUNCTION:ENGINE
+WHIRLPOOL_Init                          4141   EXIST:!VMSVAX:FUNCTION:WHIRLPOOL
+TS_RESP_set_status_info                 4142   EXIST::FUNCTION:
+EVP_PKEY_keygen                         4143   EXIST::FUNCTION:
+EVP_DigestSignInit                      4144   EXIST::FUNCTION:
+TS_ACCURACY_set_millis                  4145   EXIST::FUNCTION:
+TS_REQ_dup                              4146   EXIST::FUNCTION:
+GENERAL_NAME_dup                        4147   EXIST::FUNCTION:
+ASN1_SEQUENCE_ANY_it                    4148   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_SEQUENCE_ANY_it                    4148   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+WHIRLPOOL                               4149   EXIST:!VMSVAX:FUNCTION:WHIRLPOOL
+X509_STORE_get1_crls                    4150   EXIST::FUNCTION:
+ENGINE_get_pkey_asn1_meth               4151   EXIST::FUNCTION:ENGINE
+EVP_PKEY_asn1_new                       4152   EXIST::FUNCTION:
+BIO_new_NDEF                            4153   EXIST::FUNCTION:
+ENGINE_get_pkey_meth                    4154   EXIST::FUNCTION:ENGINE
+TS_MSG_IMPRINT_set_algo                 4155   EXIST::FUNCTION:
+i2d_TS_TST_INFO_bio                     4156   EXIST::FUNCTION:
+TS_TST_INFO_set_ordering                4157   EXIST::FUNCTION:
+TS_TST_INFO_get_ext_by_OBJ              4158   EXIST::FUNCTION:
+CRYPTO_THREADID_set_pointer             4159   EXIST::FUNCTION:
+TS_CONF_get_tsa_section                 4160   EXIST::FUNCTION:
+SMIME_write_ASN1                        4161   EXIST::FUNCTION:
+TS_RESP_CTX_set_signer_key              4162   EXIST::FUNCTION:
+EVP_PKEY_encrypt_old                    4163   EXIST::FUNCTION:
+EVP_PKEY_encrypt_init                   4164   EXIST::FUNCTION:
+CRYPTO_THREADID_cpy                     4165   EXIST::FUNCTION:
+ASN1_PCTX_get_cert_flags                4166   EXIST::FUNCTION:
+i2d_ESS_SIGNING_CERT                    4167   EXIST::FUNCTION:
+TS_CONF_load_key                        4168   EXIST::FUNCTION:
+i2d_ASN1_SEQUENCE_ANY                   4169   EXIST::FUNCTION:
+d2i_TS_MSG_IMPRINT_bio                  4170   EXIST::FUNCTION:
+EVP_PKEY_asn1_set_public                4171   EXIST::FUNCTION:
+b2i_PublicKey_bio                       4172   EXIST::FUNCTION:
+BIO_asn1_set_prefix                     4173   EXIST::FUNCTION:
+EVP_PKEY_new_mac_key                    4174   EXIST::FUNCTION:
+BIO_new_CMS                             4175   EXIST::FUNCTION:CMS
+CRYPTO_THREADID_cmp                     4176   EXIST::FUNCTION:
+TS_REQ_ext_free                         4177   EXIST::FUNCTION:
+EVP_PKEY_asn1_set_free                  4178   EXIST::FUNCTION:
+EVP_PKEY_get0_asn1                      4179   EXIST::FUNCTION:
+d2i_NETSCAPE_X509                       4180   EXIST::FUNCTION:
+EVP_PKEY_verify_recover_init            4181   EXIST::FUNCTION:
+EVP_PKEY_CTX_set_data                   4182   EXIST::FUNCTION:
+EVP_PKEY_keygen_init                    4183   EXIST::FUNCTION:
+TS_RESP_CTX_set_status_info             4184   EXIST::FUNCTION:
+TS_MSG_IMPRINT_get_algo                 4185   EXIST::FUNCTION:
+TS_REQ_print_bio                        4186   EXIST::FUNCTION:
+EVP_PKEY_CTX_ctrl_str                   4187   EXIST::FUNCTION:
+EVP_PKEY_get_default_digest_nid         4188   EXIST::FUNCTION:
+PEM_write_bio_PKCS7_stream              4189   EXIST::FUNCTION:
+TS_MSG_IMPRINT_print_bio                4190   EXIST::FUNCTION:
+BN_asc2bn                               4191   EXIST::FUNCTION:
+TS_REQ_get_policy_id                    4192   EXIST::FUNCTION:
+ENGINE_set_default_pkey_asn1_meths      4193   EXIST:!VMS:FUNCTION:ENGINE
+ENGINE_set_def_pkey_asn1_meths          4193   EXIST:VMS:FUNCTION:ENGINE
+d2i_TS_ACCURACY                         4194   EXIST::FUNCTION:
+DSO_global_lookup                       4195   EXIST::FUNCTION:
+TS_CONF_set_tsa_name                    4196   EXIST::FUNCTION:
+i2d_ASN1_SET_ANY                        4197   EXIST::FUNCTION:
+ENGINE_load_gost                        4198   EXIST::FUNCTION:ENGINE,GOST,STATIC_ENGINE
+WHIRLPOOL_BitUpdate                     4199   EXIST:!VMSVAX:FUNCTION:WHIRLPOOL
+ASN1_PCTX_get_flags                     4200   EXIST::FUNCTION:
+TS_TST_INFO_get_ext_by_NID              4201   EXIST::FUNCTION:
+TS_RESP_new                             4202   EXIST::FUNCTION:
+ESS_CERT_ID_dup                         4203   EXIST::FUNCTION:
+TS_STATUS_INFO_dup                      4204   EXIST::FUNCTION:
+TS_REQ_delete_ext                       4205   EXIST::FUNCTION:
+EVP_DigestVerifyFinal                   4206   EXIST::FUNCTION:
+EVP_PKEY_print_params                   4207   EXIST::FUNCTION:
+i2d_CMS_bio_stream                      4208   EXIST::FUNCTION:CMS
+TS_REQ_get_msg_imprint                  4209   EXIST::FUNCTION:
+OBJ_find_sigid_by_algs                  4210   EXIST::FUNCTION:
+TS_TST_INFO_get_serial                  4211   EXIST::FUNCTION:
+TS_REQ_get_nonce                        4212   EXIST::FUNCTION:
+X509_PUBKEY_set0_param                  4213   EXIST::FUNCTION:
+EVP_PKEY_CTX_set0_keygen_info           4214   EXIST::FUNCTION:
+DIST_POINT_set_dpname                   4215   EXIST::FUNCTION:
+i2d_ISSUING_DIST_POINT                  4216   EXIST::FUNCTION:
+ASN1_SET_ANY_it                         4217   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ASN1_SET_ANY_it                         4217   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+EVP_PKEY_CTX_get_data                   4218   EXIST::FUNCTION:
+TS_STATUS_INFO_print_bio                4219   EXIST::FUNCTION:
+EVP_PKEY_derive_init                    4220   EXIST::FUNCTION:
+d2i_TS_TST_INFO                         4221   EXIST::FUNCTION:
+EVP_PKEY_asn1_add_alias                 4222   EXIST::FUNCTION:
+d2i_TS_RESP_bio                         4223   EXIST::FUNCTION:
+OTHERNAME_cmp                           4224   EXIST::FUNCTION:
+GENERAL_NAME_set0_value                 4225   EXIST::FUNCTION:
+PKCS7_RECIP_INFO_get0_alg               4226   EXIST::FUNCTION:
+TS_RESP_CTX_new                         4227   EXIST::FUNCTION:
+TS_RESP_set_tst_info                    4228   EXIST::FUNCTION:
+PKCS7_final                             4229   EXIST::FUNCTION:
+EVP_PKEY_base_id                        4230   EXIST::FUNCTION:
+TS_RESP_CTX_set_signer_cert             4231   EXIST::FUNCTION:
+TS_REQ_set_msg_imprint                  4232   EXIST::FUNCTION:
+EVP_PKEY_CTX_ctrl                       4233   EXIST::FUNCTION:
+TS_CONF_set_digests                     4234   EXIST::FUNCTION:
+d2i_TS_MSG_IMPRINT                      4235   EXIST::FUNCTION:
+EVP_PKEY_meth_set_ctrl                  4236   EXIST::FUNCTION:
+TS_REQ_get_ext_by_NID                   4237   EXIST::FUNCTION:
+PKCS5_pbe_set0_algor                    4238   EXIST::FUNCTION:
+BN_BLINDING_thread_id                   4239   EXIST::FUNCTION:
+TS_ACCURACY_new                         4240   EXIST::FUNCTION:
+X509_CRL_METHOD_free                    4241   EXIST::FUNCTION:
+ASN1_PCTX_get_nm_flags                  4242   EXIST::FUNCTION:
+EVP_PKEY_meth_set_sign                  4243   EXIST::FUNCTION:
+CRYPTO_THREADID_current                 4244   EXIST::FUNCTION:
+EVP_PKEY_decrypt_init                   4245   EXIST::FUNCTION:
+NETSCAPE_X509_free                      4246   EXIST::FUNCTION:
+i2b_PVK_bio                             4247   EXIST::FUNCTION:RC4
+EVP_PKEY_print_private                  4248   EXIST::FUNCTION:
+GENERAL_NAME_get0_value                 4249   EXIST::FUNCTION:
+b2i_PVK_bio                             4250   EXIST::FUNCTION:RC4
+ASN1_UTCTIME_adj                        4251   EXIST::FUNCTION:
+TS_TST_INFO_new                         4252   EXIST::FUNCTION:
+EVP_MD_do_all_sorted                    4253   EXIST::FUNCTION:
+TS_CONF_set_default_engine              4254   EXIST::FUNCTION:
+TS_ACCURACY_set_seconds                 4255   EXIST::FUNCTION:
+TS_TST_INFO_get_time                    4256   EXIST::FUNCTION:
+PKCS8_pkey_get0                         4257   EXIST::FUNCTION:
+EVP_PKEY_asn1_get0                      4258   EXIST::FUNCTION:
+OBJ_add_sigid                           4259   EXIST::FUNCTION:
+PKCS7_SIGNER_INFO_sign                  4260   EXIST::FUNCTION:
+EVP_PKEY_paramgen_init                  4261   EXIST::FUNCTION:
+EVP_PKEY_sign                           4262   EXIST::FUNCTION:
+OBJ_sigid_free                          4263   EXIST::FUNCTION:
+EVP_PKEY_meth_set_init                  4264   EXIST::FUNCTION:
+d2i_ESS_ISSUER_SERIAL                   4265   EXIST::FUNCTION:
+ISSUING_DIST_POINT_new                  4266   EXIST::FUNCTION:
+ASN1_TIME_adj                           4267   EXIST::FUNCTION:
+TS_OBJ_print_bio                        4268   EXIST::FUNCTION:
+EVP_PKEY_meth_set_verify_recover        4269   EXIST:!VMS:FUNCTION:
+EVP_PKEY_meth_set_vrfy_recover          4269   EXIST:VMS:FUNCTION:
+TS_RESP_get_status_info                 4270   EXIST::FUNCTION:
+CMS_stream                              4271   EXIST::FUNCTION:CMS
+EVP_PKEY_CTX_set_cb                     4272   EXIST::FUNCTION:
+PKCS7_to_TS_TST_INFO                    4273   EXIST::FUNCTION:
+ASN1_PCTX_get_oid_flags                 4274   EXIST::FUNCTION:
+TS_TST_INFO_add_ext                     4275   EXIST::FUNCTION:
+EVP_PKEY_meth_set_derive                4276   EXIST::FUNCTION:
+i2d_TS_RESP_fp                          4277   EXIST::FUNCTION:
+i2d_TS_MSG_IMPRINT_bio                  4278   EXIST::FUNCTION:
+TS_RESP_CTX_set_accuracy                4279   EXIST::FUNCTION:
+TS_REQ_set_nonce                        4280   EXIST::FUNCTION:
+ESS_CERT_ID_new                         4281   EXIST::FUNCTION:
+ENGINE_pkey_asn1_find_str               4282   EXIST::FUNCTION:ENGINE
+TS_REQ_get_ext_count                    4283   EXIST::FUNCTION:
+BUF_reverse                             4284   EXIST::FUNCTION:
+TS_TST_INFO_print_bio                   4285   EXIST::FUNCTION:
+d2i_ISSUING_DIST_POINT                  4286   EXIST::FUNCTION:
+ENGINE_get_pkey_meths                   4287   EXIST::FUNCTION:ENGINE
+i2b_PrivateKey_bio                      4288   EXIST::FUNCTION:
+i2d_TS_RESP                             4289   EXIST::FUNCTION:
+b2i_PublicKey                           4290   EXIST::FUNCTION:
+TS_VERIFY_CTX_cleanup                   4291   EXIST::FUNCTION:
+TS_STATUS_INFO_free                     4292   EXIST::FUNCTION:
+TS_RESP_verify_token                    4293   EXIST::FUNCTION:
+OBJ_bsearch_ex_                         4294   EXIST::FUNCTION:
+ASN1_bn_print                           4295   EXIST::FUNCTION:BIO
+EVP_PKEY_asn1_get_count                 4296   EXIST::FUNCTION:
+ENGINE_register_pkey_asn1_meths         4297   EXIST::FUNCTION:ENGINE
+ASN1_PCTX_set_nm_flags                  4298   EXIST::FUNCTION:
+EVP_DigestVerifyInit                    4299   EXIST::FUNCTION:
+ENGINE_set_default_pkey_meths           4300   EXIST::FUNCTION:ENGINE
+TS_TST_INFO_get_policy_id               4301   EXIST::FUNCTION:
+TS_REQ_get_cert_req                     4302   EXIST::FUNCTION:
+X509_CRL_set_meth_data                  4303   EXIST::FUNCTION:
+PKCS8_pkey_set0                         4304   EXIST::FUNCTION:
+ASN1_STRING_copy                        4305   EXIST::FUNCTION:
+d2i_TS_TST_INFO_fp                      4306   EXIST::FUNCTION:
+X509_CRL_match                          4307   EXIST::FUNCTION:
+EVP_PKEY_asn1_set_private               4308   EXIST::FUNCTION:
+TS_TST_INFO_get_ext_d2i                 4309   EXIST::FUNCTION:
+TS_RESP_CTX_add_policy                  4310   EXIST::FUNCTION:
+d2i_TS_RESP                             4311   EXIST::FUNCTION:
+TS_CONF_load_certs                      4312   EXIST::FUNCTION:
+TS_TST_INFO_get_msg_imprint             4313   EXIST::FUNCTION:
+ERR_load_TS_strings                     4314   EXIST::FUNCTION:
+TS_TST_INFO_get_version                 4315   EXIST::FUNCTION:
+EVP_PKEY_CTX_dup                        4316   EXIST::FUNCTION:
+EVP_PKEY_meth_set_verify                4317   EXIST::FUNCTION:
+i2b_PublicKey_bio                       4318   EXIST::FUNCTION:
+TS_CONF_set_certs                       4319   EXIST::FUNCTION:
+EVP_PKEY_asn1_get0_info                 4320   EXIST::FUNCTION:
+TS_VERIFY_CTX_free                      4321   EXIST::FUNCTION:
+TS_REQ_get_ext_by_critical              4322   EXIST::FUNCTION:
+TS_RESP_CTX_set_serial_cb               4323   EXIST::FUNCTION:
+X509_CRL_get_meth_data                  4324   EXIST::FUNCTION:
+TS_RESP_CTX_set_time_cb                 4325   EXIST::FUNCTION:
+TS_MSG_IMPRINT_get_msg                  4326   EXIST::FUNCTION:
+TS_TST_INFO_ext_free                    4327   EXIST::FUNCTION:
+TS_REQ_get_version                      4328   EXIST::FUNCTION:
+TS_REQ_add_ext                          4329   EXIST::FUNCTION:
+EVP_PKEY_CTX_set_app_data               4330   EXIST::FUNCTION:
+OBJ_bsearch_                            4331   EXIST::FUNCTION:
+EVP_PKEY_meth_set_verifyctx             4332   EXIST::FUNCTION:
+i2d_PKCS7_bio_stream                    4333   EXIST::FUNCTION:
+CRYPTO_THREADID_set_numeric             4334   EXIST::FUNCTION:
+PKCS7_sign_add_signer                   4335   EXIST::FUNCTION:
+d2i_TS_TST_INFO_bio                     4336   EXIST::FUNCTION:
+TS_TST_INFO_get_ordering                4337   EXIST::FUNCTION:
+TS_RESP_print_bio                       4338   EXIST::FUNCTION:
+TS_TST_INFO_get_exts                    4339   EXIST::FUNCTION:
+HMAC_CTX_copy                           4340   EXIST::FUNCTION:HMAC
+PKCS5_pbe2_set_iv                       4341   EXIST::FUNCTION:
+ENGINE_get_pkey_asn1_meths              4342   EXIST::FUNCTION:ENGINE
+b2i_PrivateKey                          4343   EXIST::FUNCTION:
+EVP_PKEY_CTX_get_app_data               4344   EXIST::FUNCTION:
+TS_REQ_set_cert_req                     4345   EXIST::FUNCTION:
+CRYPTO_THREADID_set_callback            4346   EXIST::FUNCTION:
+TS_CONF_set_serial                      4347   EXIST::FUNCTION:
+TS_TST_INFO_free                        4348   EXIST::FUNCTION:
+d2i_TS_REQ_fp                           4349   EXIST::FUNCTION:
+TS_RESP_verify_response                 4350   EXIST::FUNCTION:
+i2d_ESS_ISSUER_SERIAL                   4351   EXIST::FUNCTION:
+TS_ACCURACY_get_seconds                 4352   EXIST::FUNCTION:
+EVP_CIPHER_do_all                       4353   EXIST::FUNCTION:
+b2i_PrivateKey_bio                      4354   EXIST::FUNCTION:
+OCSP_CERTID_dup                         4355   EXIST::FUNCTION:
+X509_PUBKEY_get0_param                  4356   EXIST::FUNCTION:
+TS_MSG_IMPRINT_dup                      4357   EXIST::FUNCTION:
+PKCS7_print_ctx                         4358   EXIST::FUNCTION:
+i2d_TS_REQ_bio                          4359   EXIST::FUNCTION:
+EVP_whirlpool                           4360   EXIST:!VMSVAX:FUNCTION:WHIRLPOOL
+EVP_PKEY_asn1_set_param                 4361   EXIST::FUNCTION:
+EVP_PKEY_meth_set_encrypt               4362   EXIST::FUNCTION:
+ASN1_PCTX_set_flags                     4363   EXIST::FUNCTION:
+i2d_ESS_CERT_ID                         4364   EXIST::FUNCTION:
+TS_VERIFY_CTX_new                       4365   EXIST::FUNCTION:
+TS_RESP_CTX_set_extension_cb            4366   EXIST::FUNCTION:
+ENGINE_register_all_pkey_meths          4367   EXIST::FUNCTION:ENGINE
+TS_RESP_CTX_set_status_info_cond        4368   EXIST:!VMS:FUNCTION:
+TS_RESP_CTX_set_stat_info_cond          4368   EXIST:VMS:FUNCTION:
+EVP_PKEY_verify                         4369   EXIST::FUNCTION:
+WHIRLPOOL_Final                         4370   EXIST:!VMSVAX:FUNCTION:WHIRLPOOL
+X509_CRL_METHOD_new                     4371   EXIST::FUNCTION:
+EVP_DigestSignFinal                     4372   EXIST::FUNCTION:
+TS_RESP_CTX_set_def_policy              4373   EXIST::FUNCTION:
+NETSCAPE_X509_it                        4374   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+NETSCAPE_X509_it                        4374   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+TS_RESP_create_response                 4375   EXIST::FUNCTION:
+PKCS7_SIGNER_INFO_get0_algs             4376   EXIST::FUNCTION:
+TS_TST_INFO_get_nonce                   4377   EXIST::FUNCTION:
+EVP_PKEY_decrypt_old                    4378   EXIST::FUNCTION:
+TS_TST_INFO_set_policy_id               4379   EXIST::FUNCTION:
+TS_CONF_set_ess_cert_id_chain           4380   EXIST::FUNCTION:
+EVP_PKEY_CTX_get0_pkey                  4381   EXIST::FUNCTION:
+d2i_TS_REQ                              4382   EXIST::FUNCTION:
+EVP_PKEY_asn1_find_str                  4383   EXIST::FUNCTION:
+BIO_f_asn1                              4384   EXIST::FUNCTION:
+ESS_SIGNING_CERT_new                    4385   EXIST::FUNCTION:
+EVP_PBE_find                            4386   EXIST::FUNCTION:
+X509_CRL_get0_by_cert                   4387   EXIST::FUNCTION:
+EVP_PKEY_derive                         4388   EXIST::FUNCTION:
+i2d_TS_REQ                              4389   EXIST::FUNCTION:
+TS_TST_INFO_delete_ext                  4390   EXIST::FUNCTION:
+ESS_ISSUER_SERIAL_free                  4391   EXIST::FUNCTION:
+ASN1_PCTX_set_str_flags                 4392   EXIST::FUNCTION:
+ENGINE_get_pkey_asn1_meth_str           4393   EXIST::FUNCTION:ENGINE
+TS_CONF_set_signer_key                  4394   EXIST::FUNCTION:
+TS_ACCURACY_get_millis                  4395   EXIST::FUNCTION:
+TS_RESP_get_token                       4396   EXIST::FUNCTION:
+TS_ACCURACY_dup                         4397   EXIST::FUNCTION:
+ENGINE_register_all_pkey_asn1_meths     4398   EXIST:!VMS:FUNCTION:ENGINE
+ENGINE_reg_all_pkey_asn1_meths          4398   EXIST:VMS:FUNCTION:ENGINE
+X509_CRL_set_default_method             4399   EXIST::FUNCTION:
+CRYPTO_THREADID_hash                    4400   EXIST::FUNCTION:
+CMS_ContentInfo_print_ctx               4401   EXIST::FUNCTION:CMS
+TS_RESP_free                            4402   EXIST::FUNCTION:
+ISSUING_DIST_POINT_free                 4403   EXIST::FUNCTION:
+ESS_ISSUER_SERIAL_new                   4404   EXIST::FUNCTION:
+CMS_add1_crl                            4405   EXIST::FUNCTION:CMS
+PKCS7_add1_attrib_digest                4406   EXIST::FUNCTION:
+TS_RESP_CTX_add_md                      4407   EXIST::FUNCTION:
+TS_TST_INFO_dup                         4408   EXIST::FUNCTION:
+ENGINE_set_pkey_asn1_meths              4409   EXIST::FUNCTION:ENGINE
+PEM_write_bio_Parameters                4410   EXIST::FUNCTION:
+TS_TST_INFO_get_accuracy                4411   EXIST::FUNCTION:
+X509_CRL_get0_by_serial                 4412   EXIST::FUNCTION:
+TS_TST_INFO_set_version                 4413   EXIST::FUNCTION:
+TS_RESP_CTX_get_tst_info                4414   EXIST::FUNCTION:
+TS_RESP_verify_signature                4415   EXIST::FUNCTION:
+CRYPTO_THREADID_get_callback            4416   EXIST::FUNCTION:
+TS_TST_INFO_get_tsa                     4417   EXIST::FUNCTION:
+TS_STATUS_INFO_new                      4418   EXIST::FUNCTION:
+EVP_PKEY_CTX_get_cb                     4419   EXIST::FUNCTION:
+TS_REQ_get_ext_d2i                      4420   EXIST::FUNCTION:
+GENERAL_NAME_set0_othername             4421   EXIST::FUNCTION:
+TS_TST_INFO_get_ext_count               4422   EXIST::FUNCTION:
+TS_RESP_CTX_get_request                 4423   EXIST::FUNCTION:
+i2d_NETSCAPE_X509                       4424   EXIST::FUNCTION:
+ENGINE_get_pkey_meth_engine             4425   EXIST::FUNCTION:ENGINE
+EVP_PKEY_meth_set_signctx               4426   EXIST::FUNCTION:
+EVP_PKEY_asn1_copy                      4427   EXIST::FUNCTION:
+ASN1_TYPE_cmp                           4428   EXIST::FUNCTION:
+EVP_CIPHER_do_all_sorted                4429   EXIST::FUNCTION:
+EVP_PKEY_CTX_free                       4430   EXIST::FUNCTION:
+ISSUING_DIST_POINT_it                   4431   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
+ISSUING_DIST_POINT_it                   4431   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
+d2i_TS_MSG_IMPRINT_fp                   4432   EXIST::FUNCTION:
+X509_STORE_get1_certs                   4433   EXIST::FUNCTION:
+EVP_PKEY_CTX_get_operation              4434   EXIST::FUNCTION:
+d2i_ESS_SIGNING_CERT                    4435   EXIST::FUNCTION:
+TS_CONF_set_ordering                    4436   EXIST::FUNCTION:
+EVP_PBE_alg_add_type                    4437   EXIST::FUNCTION:
+TS_REQ_set_version                      4438   EXIST::FUNCTION:
+EVP_PKEY_get0                           4439   EXIST::FUNCTION:
+BIO_asn1_set_suffix                     4440   EXIST::FUNCTION:
+i2d_TS_STATUS_INFO                      4441   EXIST::FUNCTION:
+EVP_MD_do_all                           4442   EXIST::FUNCTION:
+TS_TST_INFO_set_accuracy                4443   EXIST::FUNCTION:
+PKCS7_add_attrib_content_type           4444   EXIST::FUNCTION:
+ERR_remove_thread_state                 4445   EXIST::FUNCTION:
+EVP_PKEY_meth_add0                      4446   EXIST::FUNCTION:
+TS_TST_INFO_set_tsa                     4447   EXIST::FUNCTION:
+EVP_PKEY_meth_new                       4448   EXIST::FUNCTION:
+WHIRLPOOL_Update                        4449   EXIST:!VMSVAX:FUNCTION:WHIRLPOOL
+TS_CONF_set_accuracy                    4450   EXIST::FUNCTION:
+ASN1_PCTX_set_oid_flags                 4451   EXIST::FUNCTION:
+ESS_SIGNING_CERT_dup                    4452   EXIST::FUNCTION:
+d2i_TS_REQ_bio                          4453   EXIST::FUNCTION:
+X509_time_adj_ex                        4454   EXIST::FUNCTION:
+TS_RESP_CTX_add_flags                   4455   EXIST::FUNCTION:
+d2i_TS_STATUS_INFO                      4456   EXIST::FUNCTION:
+TS_MSG_IMPRINT_set_msg                  4457   EXIST::FUNCTION:
+BIO_asn1_get_suffix                     4458   EXIST::FUNCTION:
+TS_REQ_free                             4459   EXIST::FUNCTION:
+EVP_PKEY_meth_free                      4460   EXIST::FUNCTION:
+TS_REQ_get_exts                         4461   EXIST::FUNCTION:
+TS_RESP_CTX_set_clock_precision_digits  4462   EXIST:!VMS:FUNCTION:
+TS_RESP_CTX_set_clk_prec_digits         4462   EXIST:VMS:FUNCTION:
+TS_RESP_CTX_add_failure_info            4463   EXIST::FUNCTION:
+i2d_TS_RESP_bio                         4464   EXIST::FUNCTION:
+EVP_PKEY_CTX_get0_peerkey               4465   EXIST::FUNCTION:
+PEM_write_bio_CMS_stream                4466   EXIST::FUNCTION:CMS
+TS_REQ_new                              4467   EXIST::FUNCTION:
+TS_MSG_IMPRINT_new                      4468   EXIST::FUNCTION:
+EVP_PKEY_meth_find                      4469   EXIST::FUNCTION:
+EVP_PKEY_id                             4470   EXIST::FUNCTION:
+TS_TST_INFO_set_serial                  4471   EXIST::FUNCTION:
+a2i_GENERAL_NAME                        4472   EXIST::FUNCTION:
+TS_CONF_set_crypto_device               4473   EXIST::FUNCTION:
+EVP_PKEY_verify_init                    4474   EXIST::FUNCTION:
+TS_CONF_set_policies                    4475   EXIST::FUNCTION:
+ASN1_PCTX_new                           4476   EXIST::FUNCTION:
+ESS_CERT_ID_free                        4477   EXIST::FUNCTION:
+ENGINE_unregister_pkey_meths            4478   EXIST::FUNCTION:ENGINE
+TS_MSG_IMPRINT_free                     4479   EXIST::FUNCTION:
+TS_VERIFY_CTX_init                      4480   EXIST::FUNCTION:
+PKCS7_stream                            4481   EXIST::FUNCTION:
+TS_RESP_CTX_set_certs                   4482   EXIST::FUNCTION:
+TS_CONF_set_def_policy                  4483   EXIST::FUNCTION:
+ASN1_GENERALIZEDTIME_adj                4484   EXIST::FUNCTION:
+NETSCAPE_X509_new                       4485   EXIST::FUNCTION:
+TS_ACCURACY_free                        4486   EXIST::FUNCTION:
+TS_RESP_get_tst_info                    4487   EXIST::FUNCTION:
+EVP_PKEY_derive_set_peer                4488   EXIST::FUNCTION:
+PEM_read_bio_Parameters                 4489   EXIST::FUNCTION:
+TS_CONF_set_clock_precision_digits      4490   EXIST:!VMS:FUNCTION:
+TS_CONF_set_clk_prec_digits             4490   EXIST:VMS:FUNCTION:
+ESS_ISSUER_SERIAL_dup                   4491   EXIST::FUNCTION:
+TS_ACCURACY_get_micros                  4492   EXIST::FUNCTION:
+ASN1_PCTX_get_str_flags                 4493   EXIST::FUNCTION:
+NAME_CONSTRAINTS_check                  4494   EXIST::FUNCTION:
+ASN1_BIT_STRING_check                   4495   EXIST::FUNCTION:
+X509_check_akid                         4496   EXIST::FUNCTION:
+ENGINE_unregister_pkey_asn1_meths       4497   EXIST:!VMS:FUNCTION:ENGINE
+ENGINE_unreg_pkey_asn1_meths            4497   EXIST:VMS:FUNCTION:ENGINE
+ASN1_PCTX_free                          4498   EXIST::FUNCTION:
+PEM_write_bio_ASN1_stream               4499   EXIST::FUNCTION:
+i2d_ASN1_bio_stream                     4500   EXIST::FUNCTION:
+TS_X509_ALGOR_print_bio                 4501   EXIST::FUNCTION:
+EVP_PKEY_meth_set_cleanup               4502   EXIST::FUNCTION:
+EVP_PKEY_asn1_free                      4503   EXIST::FUNCTION:
+ESS_SIGNING_CERT_free                   4504   EXIST::FUNCTION:
+TS_TST_INFO_set_msg_imprint             4505   EXIST::FUNCTION:
+GENERAL_NAME_cmp                        4506   EXIST::FUNCTION:
+d2i_ASN1_SET_ANY                        4507   EXIST::FUNCTION:
+ENGINE_set_pkey_meths                   4508   EXIST::FUNCTION:ENGINE
+i2d_TS_REQ_fp                           4509   EXIST::FUNCTION:
+d2i_ASN1_SEQUENCE_ANY                   4510   EXIST::FUNCTION:
+GENERAL_NAME_get0_otherName             4511   EXIST::FUNCTION:
+d2i_ESS_CERT_ID                         4512   EXIST::FUNCTION:
+OBJ_find_sigid_algs                     4513   EXIST::FUNCTION:
+EVP_PKEY_meth_set_keygen                4514   EXIST::FUNCTION:
+PKCS5_PBKDF2_HMAC                       4515   EXIST::FUNCTION:
+EVP_PKEY_paramgen                       4516   EXIST::FUNCTION:
+EVP_PKEY_meth_set_paramgen              4517   EXIST::FUNCTION:
+BIO_new_PKCS7                           4518   EXIST::FUNCTION:
+EVP_PKEY_verify_recover                 4519   EXIST::FUNCTION:
+TS_ext_print_bio                        4520   EXIST::FUNCTION:
+TS_ASN1_INTEGER_print_bio               4521   EXIST::FUNCTION:
+check_defer                             4522   EXIST::FUNCTION:
+DSO_pathbyaddr                          4523   EXIST::FUNCTION:
+EVP_PKEY_set_type                       4524   EXIST::FUNCTION:
+TS_ACCURACY_set_micros                  4525   EXIST::FUNCTION:
+TS_REQ_to_TS_VERIFY_CTX                 4526   EXIST::FUNCTION:
+EVP_PKEY_meth_set_copy                  4527   EXIST::FUNCTION:
+ASN1_PCTX_set_cert_flags                4528   EXIST::FUNCTION:
+TS_TST_INFO_get_ext                     4529   EXIST::FUNCTION:
+EVP_PKEY_asn1_set_ctrl                  4530   EXIST::FUNCTION:
+TS_TST_INFO_get_ext_by_critical         4531   EXIST::FUNCTION:
+EVP_PKEY_CTX_new_id                     4532   EXIST::FUNCTION:
+TS_REQ_get_ext_by_OBJ                   4533   EXIST::FUNCTION:
+TS_CONF_set_signer_cert                 4534   EXIST::FUNCTION:
+X509_NAME_hash_old                      4535   EXIST::FUNCTION:
+ASN1_TIME_set_string                    4536   EXIST::FUNCTION:
+EVP_MD_flags                            4537   EXIST::FUNCTION:
+TS_RESP_CTX_free                        4538   EXIST::FUNCTION:
+DSAparams_dup                           4539   EXIST::FUNCTION:DSA
+DHparams_dup                            4540   EXIST::FUNCTION:DH
+OCSP_REQ_CTX_add1_header                4541   EXIST::FUNCTION:
+OCSP_REQ_CTX_set1_req                   4542   EXIST::FUNCTION:
+X509_STORE_set_verify_cb                4543   EXIST::FUNCTION:
+X509_STORE_CTX_get0_current_crl         4544   EXIST::FUNCTION:
+X509_STORE_CTX_get0_parent_ctx          4545   EXIST::FUNCTION:
+X509_STORE_CTX_get0_current_issuer      4546   EXIST:!VMS:FUNCTION:
+X509_STORE_CTX_get0_cur_issuer          4546   EXIST:VMS:FUNCTION:
+X509_issuer_name_hash_old               4547   EXIST::FUNCTION:MD5
+X509_subject_name_hash_old              4548   EXIST::FUNCTION:MD5
+EVP_CIPHER_CTX_copy                     4549   EXIST::FUNCTION:
+UI_method_get_prompt_constructor        4550   EXIST:!VMS:FUNCTION:
+UI_method_get_prompt_constructr         4550   EXIST:VMS:FUNCTION:
+UI_method_set_prompt_constructor        4551   EXIST:!VMS:FUNCTION:
+UI_method_set_prompt_constructr         4551   EXIST:VMS:FUNCTION:
+EVP_read_pw_string_min                  4552   EXIST::FUNCTION:
+CRYPTO_cts128_encrypt                   4553   EXIST::FUNCTION:
+CRYPTO_cts128_decrypt_block             4554   EXIST::FUNCTION:
+CRYPTO_cfb128_1_encrypt                 4555   EXIST::FUNCTION:
+CRYPTO_cbc128_encrypt                   4556   EXIST::FUNCTION:
+CRYPTO_ctr128_encrypt                   4557   EXIST::FUNCTION:
+CRYPTO_ofb128_encrypt                   4558   EXIST::FUNCTION:
+CRYPTO_cts128_decrypt                   4559   EXIST::FUNCTION:
+CRYPTO_cts128_encrypt_block             4560   EXIST::FUNCTION:
+CRYPTO_cbc128_decrypt                   4561   EXIST::FUNCTION:
+CRYPTO_cfb128_encrypt                   4562   EXIST::FUNCTION:
+CRYPTO_cfb128_8_encrypt                 4563   EXIST::FUNCTION:
+OPENSSL_strcasecmp                      4564   EXIST::FUNCTION:
+OPENSSL_memcmp                          4565   EXIST::FUNCTION:
+OPENSSL_strncasecmp                     4566   EXIST::FUNCTION:
+OPENSSL_gmtime                          4567   EXIST::FUNCTION:
+OPENSSL_gmtime_adj                      4568   EXIST::FUNCTION:
diff --git a/deps/openssl/openssl/util/mk1mf.pl b/deps/openssl/openssl/util/mk1mf.pl
new file mode 100755 (executable)
index 0000000..afe8c73
--- /dev/null
@@ -0,0 +1,1164 @@
+#!/usr/local/bin/perl
+# A bit of an evil hack but it post processes the file ../MINFO which
+# is generated by `make files` in the top directory.
+# This script outputs one mega makefile that has no shell stuff or any
+# funny stuff
+#
+
+$INSTALLTOP="/usr/local/ssl";
+$OPENSSLDIR="/usr/local/ssl";
+$OPTIONS="";
+$ssl_version="";
+$banner="\t\@echo Building OpenSSL";
+
+my $no_static_engine = 1;
+my $engines = "";
+my $otherlibs = "";
+local $zlib_opt = 0;   # 0 = no zlib, 1 = static, 2 = dynamic
+local $zlib_lib = "";
+local $perl_asm = 0;   # 1 to autobuild asm files from perl scripts
+
+# Options to import from top level Makefile
+
+my %mf_import = (
+       VERSION        => \$ssl_version,
+       OPTIONS        => \$OPTIONS,
+       INSTALLTOP     => \$INSTALLTOP,
+       OPENSSLDIR     => \$OPENSSLDIR,
+       PLATFORM       => \$mf_platform,
+       CFLAG          => \$mf_cflag,
+       DEPFLAG        => \$mf_depflag,
+       CPUID_OBJ      => \$mf_cpuid_asm,
+       BN_ASM         => \$mf_bn_asm,
+       DES_ENC        => \$mf_des_asm,
+       AES_ENC        => \$mf_aes_asm,
+       BF_ENC         => \$mf_bf_asm,
+       CAST_ENC       => \$mf_cast_asm,
+       RC4_ENC        => \$mf_rc4_asm,
+       RC5_ENC        => \$mf_rc5_asm,
+       MD5_ASM_OBJ    => \$mf_md5_asm,
+       SHA1_ASM_OBJ   => \$mf_sha_asm,
+       RMD160_ASM_OBJ => \$mf_rmd_asm,
+       WP_ASM_OBJ     => \$mf_wp_asm,
+       CMLL_ENC       => \$mf_cm_asm
+);
+
+
+open(IN,"<Makefile") || die "unable to open Makefile!\n";
+while(<IN>) {
+    my ($mf_opt, $mf_ref);
+    while (($mf_opt, $mf_ref) = each %mf_import) {
+       if (/^$mf_opt\s*=\s*(.*)$/) {
+          $$mf_ref = $1;
+       }
+    }
+}
+close(IN);
+
+$debug = 1 if $mf_platform =~ /^debug-/;
+
+die "Makefile is not the toplevel Makefile!\n" if $ssl_version eq "";
+
+$infile="MINFO";
+
+%ops=(
+       "VC-WIN32",   "Microsoft Visual C++ [4-6] - Windows NT or 9X",
+       "VC-WIN64I",  "Microsoft C/C++ - Win64/IA-64",
+       "VC-WIN64A",  "Microsoft C/C++ - Win64/x64",
+       "VC-CE",   "Microsoft eMbedded Visual C++ 3.0 - Windows CE ONLY",
+       "VC-NT",   "Microsoft Visual C++ [4-6] - Windows NT ONLY",
+       "Mingw32", "GNU C++ - Windows NT or 9x",
+       "Mingw32-files", "Create files with DOS copy ...",
+       "BC-NT",   "Borland C++ 4.5 - Windows NT",
+       "linux-elf","Linux elf",
+       "ultrix-mips","DEC mips ultrix",
+       "FreeBSD","FreeBSD distribution",
+       "OS2-EMX", "EMX GCC OS/2",
+       "netware-clib", "CodeWarrior for NetWare - CLib - with WinSock Sockets",
+       "netware-clib-bsdsock", "CodeWarrior for NetWare - CLib - with BSD Sockets",
+       "netware-libc", "CodeWarrior for NetWare - LibC - with WinSock Sockets",
+       "netware-libc-bsdsock", "CodeWarrior for NetWare - LibC - with BSD Sockets",
+       "default","cc under unix",
+       "auto", "auto detect from top level Makefile"
+       );
+
+$platform="";
+my $xcflags="";
+foreach (@ARGV)
+       {
+       if (!&read_options && !defined($ops{$_}))
+               {
+               print STDERR "unknown option - $_\n";
+               print STDERR "usage: perl mk1mf.pl [options] [system]\n";
+               print STDERR "\nwhere [system] can be one of the following\n";
+               foreach $i (sort keys %ops)
+               { printf STDERR "\t%-10s\t%s\n",$i,$ops{$i}; }
+               print STDERR <<"EOF";
+and [options] can be one of
+       no-md2 no-md4 no-md5 no-sha no-mdc2     - Skip this digest
+       no-ripemd
+       no-rc2 no-rc4 no-rc5 no-idea no-des     - Skip this symetric cipher
+       no-bf no-cast no-aes no-camellia no-seed
+       no-rsa no-dsa no-dh                     - Skip this public key cipher
+       no-ssl2 no-ssl3                         - Skip this version of SSL
+       just-ssl                                - remove all non-ssl keys/digest
+       no-asm                                  - No x86 asm
+       no-krb5                                 - No KRB5
+       no-ec                                   - No EC
+       no-ecdsa                                - No ECDSA
+       no-ecdh                                 - No ECDH
+       no-engine                               - No engine
+       no-hw                                   - No hw
+       nasm                                    - Use NASM for x86 asm
+       nw-nasm                                 - Use NASM x86 asm for NetWare
+       nw-mwasm                                - Use Metrowerks x86 asm for NetWare
+       gaswin                                  - Use GNU as with Mingw32
+       no-socks                                - No socket code
+       no-err                                  - No error strings
+       dll/shlib                               - Build shared libraries (MS)
+       debug                                   - Debug build
+        profile                                 - Profiling build
+       gcc                                     - Use Gcc (unix)
+
+Values that can be set
+TMP=tmpdir OUT=outdir SRC=srcdir BIN=binpath INC=header-outdir CC=C-compiler
+
+-L<ex_lib_path> -l<ex_lib>                     - extra library flags (unix)
+-<ex_cc_flags>                                 - extra 'cc' flags,
+                                                 added (MS), or replace (unix)
+EOF
+               exit(1);
+               }
+       $platform=$_;
+       }
+foreach (grep(!/^$/, split(/ /, $OPTIONS)))
+       {
+       print STDERR "unknown option - $_\n" if !&read_options;
+       }
+
+$no_static_engine = 0 if (!$shlib);
+
+$no_mdc2=1 if ($no_des);
+
+$no_ssl3=1 if ($no_md5 || $no_sha);
+$no_ssl3=1 if ($no_rsa && $no_dh);
+
+$no_ssl2=1 if ($no_md5);
+$no_ssl2=1 if ($no_rsa);
+
+$out_def="out";
+$inc_def="outinc";
+$tmp_def="tmp";
+
+$perl="perl" unless defined $perl;
+$mkdir="-mkdir" unless defined $mkdir;
+
+($ssl,$crypto)=("ssl","crypto");
+$ranlib="echo ranlib";
+
+$cc=(defined($VARS{'CC'}))?$VARS{'CC'}:'cc';
+$src_dir=(defined($VARS{'SRC'}))?$VARS{'SRC'}:'.';
+$bin_dir=(defined($VARS{'BIN'}))?$VARS{'BIN'}:'';
+
+# $bin_dir.=$o causes a core dump on my sparc :-(
+
+
+$NT=0;
+
+push(@INC,"util/pl","pl");
+
+if ($platform eq "auto") {
+       $platform = $mf_platform;
+       print STDERR "Imported platform $mf_platform\n";
+}
+
+if (($platform =~ /VC-(.+)/))
+       {
+       $FLAVOR=$1;
+       $NT = 1 if $1 eq "NT";
+       require 'VC-32.pl';
+       }
+elsif ($platform eq "Mingw32")
+       {
+       require 'Mingw32.pl';
+       }
+elsif ($platform eq "Mingw32-files")
+       {
+       require 'Mingw32f.pl';
+       }
+elsif ($platform eq "BC-NT")
+       {
+       $bc=1;
+       require 'BC-32.pl';
+       }
+elsif ($platform eq "FreeBSD")
+       {
+       require 'unix.pl';
+       $cflags='-DTERMIO -D_ANSI_SOURCE -O2 -fomit-frame-pointer';
+       }
+elsif ($platform eq "linux-elf")
+       {
+       require "unix.pl";
+       require "linux.pl";
+       $unix=1;
+       }
+elsif ($platform eq "ultrix-mips")
+       {
+       require "unix.pl";
+       require "ultrix.pl";
+       $unix=1;
+       }
+elsif ($platform eq "OS2-EMX")
+       {
+       $wc=1;
+       require 'OS2-EMX.pl';
+       }
+elsif (($platform eq "netware-clib") || ($platform eq "netware-libc") ||
+       ($platform eq "netware-clib-bsdsock") || ($platform eq "netware-libc-bsdsock"))
+       {
+       $LIBC=1 if $platform eq "netware-libc" || $platform eq "netware-libc-bsdsock";
+       $BSDSOCK=1 if ($platform eq "netware-libc-bsdsock") || ($platform eq "netware-clib-bsdsock");
+       require 'netware.pl';
+       }
+else
+       {
+       require "unix.pl";
+
+       $unix=1;
+       $cflags.=' -DTERMIO';
+       }
+
+$out_dir=(defined($VARS{'OUT'}))?$VARS{'OUT'}:$out_def.($debug?".dbg":"");
+$tmp_dir=(defined($VARS{'TMP'}))?$VARS{'TMP'}:$tmp_def.($debug?".dbg":"");
+$inc_dir=(defined($VARS{'INC'}))?$VARS{'INC'}:$inc_def;
+
+$bin_dir=$bin_dir.$o unless ((substr($bin_dir,-1,1) eq $o) || ($bin_dir eq ''));
+
+$cflags= "$xcflags$cflags" if $xcflags ne "";
+
+$cflags.=" -DOPENSSL_NO_IDEA" if $no_idea;
+$cflags.=" -DOPENSSL_NO_AES"  if $no_aes;
+$cflags.=" -DOPENSSL_NO_CAMELLIA"  if $no_camellia;
+$cflags.=" -DOPENSSL_NO_SEED" if $no_seed;
+$cflags.=" -DOPENSSL_NO_RC2"  if $no_rc2;
+$cflags.=" -DOPENSSL_NO_RC4"  if $no_rc4;
+$cflags.=" -DOPENSSL_NO_RC5"  if $no_rc5;
+$cflags.=" -DOPENSSL_NO_MD2"  if $no_md2;
+$cflags.=" -DOPENSSL_NO_MD4"  if $no_md4;
+$cflags.=" -DOPENSSL_NO_MD5"  if $no_md5;
+$cflags.=" -DOPENSSL_NO_SHA"  if $no_sha;
+$cflags.=" -DOPENSSL_NO_SHA1" if $no_sha1;
+$cflags.=" -DOPENSSL_NO_RIPEMD" if $no_ripemd;
+$cflags.=" -DOPENSSL_NO_MDC2" if $no_mdc2;
+$cflags.=" -DOPENSSL_NO_BF"  if $no_bf;
+$cflags.=" -DOPENSSL_NO_CAST" if $no_cast;
+$cflags.=" -DOPENSSL_NO_DES"  if $no_des;
+$cflags.=" -DOPENSSL_NO_RSA"  if $no_rsa;
+$cflags.=" -DOPENSSL_NO_DSA"  if $no_dsa;
+$cflags.=" -DOPENSSL_NO_DH"   if $no_dh;
+$cflags.=" -DOPENSSL_NO_WHIRLPOOL"   if $no_whirlpool;
+$cflags.=" -DOPENSSL_NO_SOCK" if $no_sock;
+$cflags.=" -DOPENSSL_NO_SSL2" if $no_ssl2;
+$cflags.=" -DOPENSSL_NO_SSL3" if $no_ssl3;
+$cflags.=" -DOPENSSL_NO_TLSEXT" if $no_tlsext;
+$cflags.=" -DOPENSSL_NO_CMS" if $no_cms;
+$cflags.=" -DOPENSSL_NO_ERR"  if $no_err;
+$cflags.=" -DOPENSSL_NO_KRB5" if $no_krb5;
+$cflags.=" -DOPENSSL_NO_EC"   if $no_ec;
+$cflags.=" -DOPENSSL_NO_ECDSA" if $no_ecdsa;
+$cflags.=" -DOPENSSL_NO_ECDH" if $no_ecdh;
+$cflags.=" -DOPENSSL_NO_GOST" if $no_gost;
+$cflags.=" -DOPENSSL_NO_ENGINE"   if $no_engine;
+$cflags.=" -DOPENSSL_NO_HW"   if $no_hw;
+$cflags.=" -DOPENSSL_NO_JPAKE"    if $no_jpake;
+$cflags.= " -DZLIB" if $zlib_opt;
+$cflags.= " -DZLIB_SHARED" if $zlib_opt == 2;
+
+if ($no_static_engine)
+       {
+       $cflags .= " -DOPENSSL_NO_STATIC_ENGINE";
+       }
+else
+       {
+       $cflags .= " -DOPENSSL_NO_DYNAMIC_ENGINE";
+       }
+
+#$cflags.=" -DRSAref"  if $rsaref ne "";
+
+## if ($unix)
+##     { $cflags="$c_flags" if ($c_flags ne ""); }
+##else
+       { $cflags="$c_flags$cflags" if ($c_flags ne ""); }
+
+$ex_libs="$l_flags$ex_libs" if ($l_flags ne "");
+
+
+%shlib_ex_cflags=("SSL" => " -DOPENSSL_BUILD_SHLIBSSL",
+                 "CRYPTO" => " -DOPENSSL_BUILD_SHLIBCRYPTO");
+
+if ($msdos)
+       {
+       $banner ="\t\@echo Make sure you have run 'perl Configure $platform' in the\n";
+       $banner.="\t\@echo top level directory, if you don't have perl, you will\n";
+       $banner.="\t\@echo need to probably edit crypto/bn/bn.h, check the\n";
+       $banner.="\t\@echo documentation for details.\n";
+       }
+
+# have to do this to allow $(CC) under unix
+$link="$bin_dir$link" if ($link !~ /^\$/);
+
+$INSTALLTOP =~ s|/|$o|g;
+$OPENSSLDIR =~ s|/|$o|g;
+
+#############################################
+# We parse in input file and 'store' info for later printing.
+open(IN,"<$infile") || die "unable to open $infile:$!\n";
+$_=<IN>;
+for (;;)
+       {
+       chop;
+
+       ($key,$val)=/^([^=]+)=(.*)/;
+       if ($key eq "RELATIVE_DIRECTORY")
+               {
+               if ($lib ne "")
+                       {
+                       $uc=$lib;
+                       $uc =~ s/^lib(.*)\.a/$1/;
+                       $uc =~ tr/a-z/A-Z/;
+                       $lib_nam{$uc}=$uc;
+                       $lib_obj{$uc}.=$libobj." ";
+                       }
+               last if ($val eq "FINISHED");
+               $lib="";
+               $libobj="";
+               $dir=$val;
+               }
+
+       if ($key eq "KRB5_INCLUDES")
+               { $cflags .= " $val";}
+
+       if ($key eq "ZLIB_INCLUDE")
+               { $cflags .= " $val" if $val ne "";}
+
+       if ($key eq "LIBZLIB")
+               { $zlib_lib = "$val" if $val ne "";}
+
+       if ($key eq "LIBKRB5")
+               { $ex_libs .= " $val" if $val ne "";}
+
+       if ($key eq "TEST")
+               { $test.=&var_add($dir,$val, 0); }
+
+       if (($key eq "PROGS") || ($key eq "E_OBJ"))
+               { $e_exe.=&var_add($dir,$val, 0); }
+
+       if ($key eq "LIB")
+               {
+               $lib=$val;
+               $lib =~ s/^.*\/([^\/]+)$/$1/;
+               }
+       if ($key eq "LIBNAME" && $no_static_engine)
+               {
+               $lib=$val;
+               $lib =~ s/^.*\/([^\/]+)$/$1/;
+               $otherlibs .= " $lib";
+               }
+
+       if ($key eq "EXHEADER")
+               { $exheader.=&var_add($dir,$val, 1); }
+
+       if ($key eq "HEADER")
+               { $header.=&var_add($dir,$val, 1); }
+
+       if ($key eq "LIBOBJ" && ($dir ne "engines" || !$no_static_engine))
+               { $libobj=&var_add($dir,$val, 0); }
+       if ($key eq "LIBNAMES" && $dir eq "engines" && $no_static_engine)
+               { $engines.=$val }
+
+       if (!($_=<IN>))
+               { $_="RELATIVE_DIRECTORY=FINISHED\n"; }
+       }
+close(IN);
+
+if ($shlib)
+       {
+       $extra_install= <<"EOF";
+       \$(CP) \"\$(O_SSL)\" \"\$(INSTALLTOP)${o}bin\"
+       \$(CP) \"\$(O_CRYPTO)\" \"\$(INSTALLTOP)${o}bin\"
+       \$(CP) \"\$(L_SSL)\" \"\$(INSTALLTOP)${o}lib\"
+       \$(CP) \"\$(L_CRYPTO)\" \"\$(INSTALLTOP)${o}lib\"
+EOF
+       if ($no_static_engine)
+               {
+               $extra_install .= <<"EOF"
+       \$(MKDIR) \"\$(INSTALLTOP)${o}lib${o}engines\"
+       \$(CP) \"\$(E_SHLIB)\" \"\$(INSTALLTOP)${o}lib${o}engines\"
+EOF
+               }
+       }
+else
+       {
+       $extra_install= <<"EOF";
+       \$(CP) \"\$(O_SSL)\" \"\$(INSTALLTOP)${o}lib\"
+       \$(CP) \"\$(O_CRYPTO)\" \"\$(INSTALLTOP)${o}lib\"
+EOF
+       $ex_libs .= " $zlib_lib" if $zlib_opt == 1;
+       }
+
+$defs= <<"EOF";
+# This makefile has been automatically generated from the OpenSSL distribution.
+# This single makefile will build the complete OpenSSL distribution and
+# by default leave the 'intertesting' output files in .${o}out and the stuff
+# that needs deleting in .${o}tmp.
+# The file was generated by running 'make makefile.one', which
+# does a 'make files', which writes all the environment variables from all
+# the makefiles to the file call MINFO.  This file is used by
+# util${o}mk1mf.pl to generate makefile.one.
+# The 'makefile per directory' system suites me when developing this
+# library and also so I can 'distribute' indervidual library sections.
+# The one monster makefile better suits building in non-unix
+# environments.
+
+EOF
+
+$defs .= $preamble if defined $preamble;
+
+$defs.= <<"EOF";
+INSTALLTOP=$INSTALLTOP
+OPENSSLDIR=$OPENSSLDIR
+
+# Set your compiler options
+PLATFORM=$platform
+CC=$bin_dir${cc}
+CFLAG=$cflags
+APP_CFLAG=$app_cflag
+LIB_CFLAG=$lib_cflag
+SHLIB_CFLAG=$shl_cflag
+APP_EX_OBJ=$app_ex_obj
+SHLIB_EX_OBJ=$shlib_ex_obj
+# add extra libraries to this define, for solaris -lsocket -lnsl would
+# be added
+EX_LIBS=$ex_libs
+
+# The OpenSSL directory
+SRC_D=$src_dir
+
+LINK=$link
+LFLAGS=$lflags
+RSC=$rsc
+
+# The output directory for everything intersting
+OUT_D=$out_dir
+# The output directory for all the temporary muck
+TMP_D=$tmp_dir
+# The output directory for the header files
+INC_D=$inc_dir
+INCO_D=$inc_dir${o}openssl
+
+PERL=$perl
+CP=$cp
+RM=$rm
+RANLIB=$ranlib
+MKDIR=$mkdir
+MKLIB=$bin_dir$mklib
+MLFLAGS=$mlflags
+ASM=$bin_dir$asm
+
+######################################################
+# You should not need to touch anything below this point
+######################################################
+
+E_EXE=openssl
+SSL=$ssl
+CRYPTO=$crypto
+
+# BIN_D  - Binary output directory
+# TEST_D - Binary test file output directory
+# LIB_D  - library output directory
+# ENG_D  - dynamic engine output directory
+# Note: if you change these point to different directories then uncomment out
+# the lines around the 'NB' comment below.
+# 
+BIN_D=\$(OUT_D)
+TEST_D=\$(OUT_D)
+LIB_D=\$(OUT_D)
+ENG_D=\$(OUT_D)
+
+# INCL_D - local library directory
+# OBJ_D  - temp object file directory
+OBJ_D=\$(TMP_D)
+INCL_D=\$(TMP_D)
+
+O_SSL=     \$(LIB_D)$o$plib\$(SSL)$shlibp
+O_CRYPTO=  \$(LIB_D)$o$plib\$(CRYPTO)$shlibp
+SO_SSL=    $plib\$(SSL)$so_shlibp
+SO_CRYPTO= $plib\$(CRYPTO)$so_shlibp
+L_SSL=     \$(LIB_D)$o$plib\$(SSL)$libp
+L_CRYPTO=  \$(LIB_D)$o$plib\$(CRYPTO)$libp
+
+L_LIBS= \$(L_SSL) \$(L_CRYPTO)
+
+######################################################
+# Don't touch anything below this point
+######################################################
+
+INC=-I\$(INC_D) -I\$(INCL_D)
+APP_CFLAGS=\$(INC) \$(CFLAG) \$(APP_CFLAG)
+LIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG)
+SHLIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG) \$(SHLIB_CFLAG)
+LIBS_DEP=\$(O_CRYPTO) \$(O_SSL)
+
+#############################################
+EOF
+
+$rules=<<"EOF";
+all: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) \$(INCO_D) headers lib exe
+
+banner:
+$banner
+
+\$(TMP_D):
+       \$(MKDIR) \"\$(TMP_D)\"
+# NB: uncomment out these lines if BIN_D, TEST_D and LIB_D are different
+#\$(BIN_D):
+#      \$(MKDIR) \$(BIN_D)
+#
+#\$(TEST_D):
+#      \$(MKDIR) \$(TEST_D)
+
+\$(LIB_D):
+       \$(MKDIR) \"\$(LIB_D)\"
+
+\$(INCO_D): \$(INC_D)
+       \$(MKDIR) \"\$(INCO_D)\"
+
+\$(INC_D):
+       \$(MKDIR) \"\$(INC_D)\"
+
+headers: \$(HEADER) \$(EXHEADER)
+       @
+
+lib: \$(LIBS_DEP) \$(E_SHLIB)
+
+exe: \$(T_EXE) \$(BIN_D)$o\$(E_EXE)$exep
+
+install: all
+       \$(MKDIR) \"\$(INSTALLTOP)\"
+       \$(MKDIR) \"\$(INSTALLTOP)${o}bin\"
+       \$(MKDIR) \"\$(INSTALLTOP)${o}include\"
+       \$(MKDIR) \"\$(INSTALLTOP)${o}include${o}openssl\"
+       \$(MKDIR) \"\$(INSTALLTOP)${o}lib\"
+       \$(CP) \"\$(INCO_D)${o}*.\[ch\]\" \"\$(INSTALLTOP)${o}include${o}openssl\"
+       \$(CP) \"\$(BIN_D)$o\$(E_EXE)$exep \$(INSTALLTOP)${o}bin\"
+       \$(MKDIR) \"\$(OPENSSLDIR)\"
+       \$(CP) apps${o}openssl.cnf \"\$(OPENSSLDIR)\"
+$extra_install
+
+
+test: \$(T_EXE)
+       cd \$(BIN_D)
+       ..${o}ms${o}test
+
+clean:
+       \$(RM) \$(TMP_D)$o*.*
+
+vclean:
+       \$(RM) \$(TMP_D)$o*.*
+       \$(RM) \$(OUT_D)$o*.*
+
+EOF
+    
+my $platform_cpp_symbol = "MK1MF_PLATFORM_$platform";
+$platform_cpp_symbol =~ s/-/_/g;
+if (open(IN,"crypto/buildinf.h"))
+       {
+       # Remove entry for this platform in existing file buildinf.h.
+
+       my $old_buildinf_h = "";
+       while (<IN>)
+               {
+               if (/^\#ifdef $platform_cpp_symbol$/)
+                       {
+                       while (<IN>) { last if (/^\#endif/); }
+                       }
+               else
+                       {
+                       $old_buildinf_h .= $_;
+                       }
+               }
+       close(IN);
+
+       open(OUT,">crypto/buildinf.h") || die "Can't open buildinf.h";
+       print OUT $old_buildinf_h;
+       close(OUT);
+       }
+
+open (OUT,">>crypto/buildinf.h") || die "Can't open buildinf.h";
+printf OUT <<EOF;
+#ifdef $platform_cpp_symbol
+  /* auto-generated/updated by util/mk1mf.pl for crypto/cversion.c */
+  #define CFLAGS "$cc $cflags"
+  #define PLATFORM "$platform"
+EOF
+printf OUT "  #define DATE \"%s\"\n", scalar gmtime();
+printf OUT "#endif\n";
+close(OUT);
+
+# Strip of trailing ' '
+foreach (keys %lib_obj) { $lib_obj{$_}=&clean_up_ws($lib_obj{$_}); }
+$test=&clean_up_ws($test);
+$e_exe=&clean_up_ws($e_exe);
+$exheader=&clean_up_ws($exheader);
+$header=&clean_up_ws($header);
+
+# First we strip the exheaders from the headers list
+foreach (split(/\s+/,$exheader)){ $h{$_}=1; }
+foreach (split(/\s+/,$header)) { $h.=$_." " unless $h{$_}; }
+chop($h); $header=$h;
+
+$defs.=&do_defs("HEADER",$header,"\$(INCL_D)","");
+$rules.=&do_copy_rule("\$(INCL_D)",$header,"");
+
+$defs.=&do_defs("EXHEADER",$exheader,"\$(INCO_D)","");
+$rules.=&do_copy_rule("\$(INCO_D)",$exheader,"");
+
+$defs.=&do_defs("T_OBJ",$test,"\$(OBJ_D)",$obj);
+$rules.=&do_compile_rule("\$(OBJ_D)",$test,"\$(APP_CFLAGS)");
+
+$defs.=&do_defs("E_OBJ",$e_exe,"\$(OBJ_D)",$obj);
+$rules.=&do_compile_rule("\$(OBJ_D)",$e_exe,'-DMONOLITH $(APP_CFLAGS)');
+
+foreach (values %lib_nam)
+       {
+       $lib_obj=$lib_obj{$_};
+       local($slib)=$shlib;
+
+       if (($_ eq "SSL") && $no_ssl2 && $no_ssl3)
+               {
+               $rules.="\$(O_SSL):\n\n"; 
+               next;
+               }
+
+       $defs.=&do_defs(${_}."OBJ",$lib_obj,"\$(OBJ_D)",$obj);
+       $lib=($slib)?" \$(SHLIB_CFLAGS)".$shlib_ex_cflags{$_}:" \$(LIB_CFLAGS)";
+       $rules.=&do_compile_rule("\$(OBJ_D)",$lib_obj{$_},$lib);
+       }
+
+# hack to add version info on MSVC
+if (($platform eq "VC-WIN32") || ($platform eq "VC-WIN64A")
+       || ($platform eq "VC-WIN64I") || ($platform eq "VC-NT")) {
+    $rules.= <<"EOF";
+\$(OBJ_D)\\\$(CRYPTO).res: ms\\version32.rc
+       \$(RSC) /fo"\$(OBJ_D)\\\$(CRYPTO).res" /d CRYPTO ms\\version32.rc
+
+\$(OBJ_D)\\\$(SSL).res: ms\\version32.rc
+       \$(RSC) /fo"\$(OBJ_D)\\\$(SSL).res" /d SSL ms\\version32.rc
+
+EOF
+}
+
+$defs.=&do_defs("T_EXE",$test,"\$(TEST_D)",$exep);
+foreach (split(/\s+/,$test))
+       {
+       $t=&bname($_);
+       $tt="\$(OBJ_D)${o}$t${obj}";
+       $rules.=&do_link_rule("\$(TEST_D)$o$t$exep",$tt,"\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)");
+       }
+
+$defs.=&do_defs("E_SHLIB",$engines . $otherlibs,"\$(ENG_D)",$shlibp);
+
+foreach (split(/\s+/,$engines))
+       {
+       $rules.=&do_compile_rule("\$(OBJ_D)","engines${o}e_$_",$lib);
+       $rules.= &do_lib_rule("\$(OBJ_D)${o}e_${_}.obj","\$(ENG_D)$o$_$shlibp","",$shlib,"");
+       }
+
+
+
+$rules.= &do_lib_rule("\$(SSLOBJ)","\$(O_SSL)",$ssl,$shlib,"\$(SO_SSL)");
+$rules.= &do_lib_rule("\$(CRYPTOOBJ)","\$(O_CRYPTO)",$crypto,$shlib,"\$(SO_CRYPTO)");
+
+foreach (split(" ",$otherlibs))
+       {
+       my $uc = $_;
+       $uc =~ tr /a-z/A-Z/;    
+       $rules.= &do_lib_rule("\$(${uc}OBJ)","\$(ENG_D)$o$_$shlibp", "", $shlib, "");
+
+       }
+
+$rules.=&do_link_rule("\$(BIN_D)$o\$(E_EXE)$exep","\$(E_OBJ)","\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)");
+
+print $defs;
+
+if ($platform eq "linux-elf") {
+    print <<"EOF";
+# Generate perlasm output files
+%.cpp:
+       (cd \$(\@D)/..; PERL=perl make -f Makefile asm/\$(\@F))
+EOF
+}
+print "###################################################################\n";
+print $rules;
+
+###############################################
+# strip off any trailing .[och] and append the relative directory
+# also remembering to do nothing if we are in one of the dropped
+# directories
+sub var_add
+       {
+       local($dir,$val,$keepext)=@_;
+       local(@a,$_,$ret);
+
+       return("") if $no_engine && $dir =~ /\/engine/;
+       return("") if $no_hw   && $dir =~ /\/hw/;
+       return("") if $no_idea && $dir =~ /\/idea/;
+       return("") if $no_aes  && $dir =~ /\/aes/;
+       return("") if $no_camellia  && $dir =~ /\/camellia/;
+       return("") if $no_seed && $dir =~ /\/seed/;
+       return("") if $no_rc2  && $dir =~ /\/rc2/;
+       return("") if $no_rc4  && $dir =~ /\/rc4/;
+       return("") if $no_rc5  && $dir =~ /\/rc5/;
+       return("") if $no_rsa  && $dir =~ /\/rsa/;
+       return("") if $no_rsa  && $dir =~ /^rsaref/;
+       return("") if $no_dsa  && $dir =~ /\/dsa/;
+       return("") if $no_dh   && $dir =~ /\/dh/;
+       return("") if $no_ec   && $dir =~ /\/ec/;
+       return("") if $no_gost   && $dir =~ /\/ccgost/;
+       return("") if $no_cms  && $dir =~ /\/cms/;
+       return("") if $no_jpake  && $dir =~ /\/jpake/;
+       if ($no_des && $dir =~ /\/des/)
+               {
+               if ($val =~ /read_pwd/)
+                       { return("$dir/read_pwd "); }
+               else
+                       { return(""); }
+               }
+       return("") if $no_mdc2 && $dir =~ /\/mdc2/;
+       return("") if $no_sock && $dir =~ /\/proxy/;
+       return("") if $no_bf   && $dir =~ /\/bf/;
+       return("") if $no_cast && $dir =~ /\/cast/;
+       return("") if $no_whirlpool && $dir =~ /\/whrlpool/;
+
+       $val =~ s/^\s*(.*)\s*$/$1/;
+       @a=split(/\s+/,$val);
+       grep(s/\.[och]$//,@a) unless $keepext;
+
+       @a=grep(!/^e_.*_3d$/,@a) if $no_des;
+       @a=grep(!/^e_.*_d$/,@a) if $no_des;
+       @a=grep(!/^e_.*_ae$/,@a) if $no_idea;
+       @a=grep(!/^e_.*_i$/,@a) if $no_aes;
+       @a=grep(!/^e_.*_r2$/,@a) if $no_rc2;
+       @a=grep(!/^e_.*_r5$/,@a) if $no_rc5;
+       @a=grep(!/^e_.*_bf$/,@a) if $no_bf;
+       @a=grep(!/^e_.*_c$/,@a) if $no_cast;
+       @a=grep(!/^e_rc4$/,@a) if $no_rc4;
+       @a=grep(!/^e_camellia$/,@a) if $no_camellia;
+       @a=grep(!/^e_seed$/,@a) if $no_seed;
+
+       #@a=grep(!/(^s2_)|(^s23_)/,@a) if $no_ssl2;
+       #@a=grep(!/(^s3_)|(^s23_)/,@a) if $no_ssl3;
+
+       @a=grep(!/(_sock$)|(_acpt$)|(_conn$)|(^pxy_)/,@a) if $no_sock;
+
+       @a=grep(!/(^md2)|(_md2$)/,@a) if $no_md2;
+       @a=grep(!/(^md4)|(_md4$)/,@a) if $no_md4;
+       @a=grep(!/(^md5)|(_md5$)/,@a) if $no_md5;
+       @a=grep(!/(rmd)|(ripemd)/,@a) if $no_ripemd;
+
+       @a=grep(!/(^d2i_r_)|(^i2d_r_)/,@a) if $no_rsa;
+       @a=grep(!/(^p_open$)|(^p_seal$)/,@a) if $no_rsa;
+       @a=grep(!/(^pem_seal$)/,@a) if $no_rsa;
+
+       @a=grep(!/(m_dss$)|(m_dss1$)/,@a) if $no_dsa;
+       @a=grep(!/(^d2i_s_)|(^i2d_s_)|(_dsap$)/,@a) if $no_dsa;
+
+       @a=grep(!/^n_pkey$/,@a) if $no_rsa || $no_rc4;
+
+       @a=grep(!/_dhp$/,@a) if $no_dh;
+
+       @a=grep(!/(^sha[^1])|(_sha$)|(m_dss$)/,@a) if $no_sha;
+       @a=grep(!/(^sha1)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
+       @a=grep(!/_mdc2$/,@a) if $no_mdc2;
+
+       @a=grep(!/^engine$/,@a) if $no_engine;
+       @a=grep(!/^hw$/,@a) if $no_hw;
+       @a=grep(!/(^rsa$)|(^genrsa$)/,@a) if $no_rsa;
+       @a=grep(!/(^dsa$)|(^gendsa$)|(^dsaparam$)/,@a) if $no_dsa;
+       @a=grep(!/^gendsa$/,@a) if $no_sha1;
+       @a=grep(!/(^dh$)|(^gendh$)/,@a) if $no_dh;
+
+       @a=grep(!/(^dh)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
+
+       grep($_="$dir/$_",@a);
+       @a=grep(!/(^|\/)s_/,@a) if $no_sock;
+       @a=grep(!/(^|\/)bio_sock/,@a) if $no_sock;
+       $ret=join(' ',@a)." ";
+       return($ret);
+       }
+
+# change things so that each 'token' is only separated by one space
+sub clean_up_ws
+       {
+       local($w)=@_;
+
+       $w =~ s/^\s*(.*)\s*$/$1/;
+       $w =~ s/\s+/ /g;
+       return($w);
+       }
+
+sub do_defs
+       {
+       local($var,$files,$location,$postfix)=@_;
+       local($_,$ret,$pf);
+       local(*OUT,$tmp,$t);
+
+       $files =~ s/\//$o/g if $o ne '/';
+       $ret="$var="; 
+       $n=1;
+       $Vars{$var}.="";
+       foreach (split(/ /,$files))
+               {
+               $orig=$_;
+               $_=&bname($_) unless /^\$/;
+               if ($n++ == 2)
+                       {
+                       $n=0;
+                       $ret.="\\\n\t";
+                       }
+               if (($_ =~ /bss_file/) && ($postfix eq ".h"))
+                       { $pf=".c"; }
+               else    { $pf=$postfix; }
+               if ($_ =~ /BN_ASM/)     { $t="$_ "; }
+               elsif ($_ =~ /BNCO_ASM/){ $t="$_ "; }
+               elsif ($_ =~ /AES_ASM/){ $t="$_ "; }
+               elsif ($_ =~ /DES_ENC/) { $t="$_ "; }
+               elsif ($_ =~ /BF_ENC/)  { $t="$_ "; }
+               elsif ($_ =~ /CAST_ENC/){ $t="$_ "; }
+               elsif ($_ =~ /RC4_ENC/) { $t="$_ "; }
+               elsif ($_ =~ /RC5_ENC/) { $t="$_ "; }
+               elsif ($_ =~ /MD5_ASM/) { $t="$_ "; }
+               elsif ($_ =~ /SHA1_ASM/){ $t="$_ "; }
+               elsif ($_ =~ /RMD160_ASM/){ $t="$_ "; }
+               elsif ($_ =~ /WHIRLPOOL_ASM/){ $t="$_ "; }
+               elsif ($_ =~ /CPUID_ASM/){ $t="$_ "; }
+               else    { $t="$location${o}$_$pf "; }
+
+               $Vars{$var}.="$t ";
+               $ret.=$t;
+               }
+       # hack to add version info on MSVC
+       if ($shlib && (($platform eq "VC-WIN32") || ($platfrom eq "VC-WIN64I") || ($platform eq "VC-WIN64A") || ($platform eq "VC-NT")))
+               {
+               if ($var eq "CRYPTOOBJ")
+                       { $ret.="\$(OBJ_D)\\\$(CRYPTO).res "; }
+               elsif ($var eq "SSLOBJ")
+                       { $ret.="\$(OBJ_D)\\\$(SSL).res "; }
+               }
+       chomp($ret);
+       $ret.="\n\n";
+       return($ret);
+       }
+
+# return the name with the leading path removed
+sub bname
+       {
+       local($ret)=@_;
+       $ret =~ s/^.*[\\\/]([^\\\/]+)$/$1/;
+       return($ret);
+       }
+
+# return the leading path
+sub dname
+       {
+       my $ret=shift;
+       $ret =~ s/(^.*)[\\\/][^\\\/]+$/$1/;
+       return($ret);
+       }
+
+##############################################################
+# do a rule for each file that says 'compile' to new direcory
+# compile the files in '$files' into $to
+sub do_compile_rule
+       {
+       local($to,$files,$ex)=@_;
+       local($ret,$_,$n,$d,$s);
+
+       $files =~ s/\//$o/g if $o ne '/';
+       foreach (split(/\s+/,$files))
+               {
+               $n=&bname($_);
+               $d=&dname($_);
+               if (-f "${_}.c")
+                       {
+                       $ret.=&cc_compile_target("$to${o}$n$obj","${_}.c",$ex)
+                       }
+               elsif (-f ($s="${d}${o}asm${o}${n}.pl") or
+                      ($s=~s/sha256/sha512/ and -f $s) or
+                      -f ($s="${d}${o}${n}.pl"))
+                       {
+                       $ret.=&perlasm_compile_target("$to${o}$n$obj",$s,$n);
+                       }
+               elsif (-f ($s="${d}${o}asm${o}${n}.S") or
+                      -f ($s="${d}${o}${n}.S"))
+                       {
+                       $ret.=&Sasm_compile_target("$to${o}$n$obj",$s,$n);
+                       }
+               else    { die "no rule for $_"; }
+               }
+       return($ret);
+       }
+
+##############################################################
+# do a rule for each file that says 'compile' to new direcory
+sub perlasm_compile_target
+       {
+       my($target,$source,$bname)=@_;
+       my($ret);
+
+       $bname =~ s/(.*)\.[^\.]$/$1/;
+       $ret ="\$(TMP_D)$o$bname.asm: $source\n";
+       $ret.="\t\$(PERL) $source $asmtype \$(CFLAG) >\$\@\n\n";
+       $ret.="$target: \$(TMP_D)$o$bname.asm\n";
+       $ret.="\t\$(ASM) $afile\$\@ \$(TMP_D)$o$bname.asm\n\n";
+       return($ret);
+       }
+
+sub Sasm_compile_target
+       {
+       my($target,$source,$bname)=@_;
+       my($ret);
+
+       $bname =~ s/(.*)\.[^\.]$/$1/;
+       $ret ="\$(TMP_D)$o$bname.asm: $source\n";
+       $ret.="\t\$(CC) -E \$(CFLAG) $source >\$\@\n\n";
+       $ret.="$target: \$(TMP_D)$o$bname.asm\n";
+       $ret.="\t\$(ASM) $afile\$\@ \$(TMP_D)$o$bname.asm\n\n";
+       return($ret);
+       }
+
+sub cc_compile_target
+       {
+       local($target,$source,$ex_flags)=@_;
+       local($ret);
+       
+       $ex_flags.=" -DMK1MF_BUILD -D$platform_cpp_symbol" if ($source =~ /cversion/);
+       $target =~ s/\//$o/g if $o ne "/";
+       $source =~ s/\//$o/g if $o ne "/";
+       $ret ="$target: \$(SRC_D)$o$source\n\t";
+       $ret.="\$(CC) ${ofile}$target $ex_flags -c \$(SRC_D)$o$source\n\n";
+       return($ret);
+       }
+
+##############################################################
+sub do_asm_rule
+       {
+       local($target,$src)=@_;
+       local($ret,@s,@t,$i);
+
+       $target =~ s/\//$o/g if $o ne "/";
+       $src =~ s/\//$o/g if $o ne "/";
+
+       @t=split(/\s+/,$target);
+       @s=split(/\s+/,$src);
+
+
+       for ($i=0; $i<=$#s; $i++)
+               {
+               my $objfile = $t[$i];
+               my $srcfile = $s[$i];
+
+               if ($perl_asm == 1)
+                       {
+                       my $plasm = $objfile;
+                       $plasm =~ s/${obj}/.pl/;
+                       $ret.="$srcfile: $plasm\n";
+                       $ret.="\t\$(PERL) $plasm $asmtype \$(CFLAG) >$srcfile\n\n";
+                       }
+
+               $ret.="$objfile: $srcfile\n";
+               $ret.="\t\$(ASM) $afile$objfile \$(SRC_D)$o$srcfile\n\n";
+               }
+       return($ret);
+       }
+
+sub do_shlib_rule
+       {
+       local($n,$def)=@_;
+       local($ret,$nn);
+       local($t);
+
+       ($nn=$n) =~ tr/a-z/A-Z/;
+       $ret.="$n.dll: \$(${nn}OBJ)\n";
+       if ($vc && $w32)
+               {
+               $ret.="\t\$(MKSHLIB) $efile$n.dll $def @<<\n  \$(${nn}OBJ_F)\n<<\n";
+               }
+       $ret.="\n";
+       return($ret);
+       }
+
+# do a rule for each file that says 'copy' to new direcory on change
+sub do_copy_rule
+       {
+       local($to,$files,$p)=@_;
+       local($ret,$_,$n,$pp);
+       
+       $files =~ s/\//$o/g if $o ne '/';
+       foreach (split(/\s+/,$files))
+               {
+               $n=&bname($_);
+               if ($n =~ /bss_file/)
+                       { $pp=".c"; }
+               else    { $pp=$p; }
+               $ret.="$to${o}$n$pp: \$(SRC_D)$o$_$pp\n\t\$(CP) \"\$(SRC_D)$o$_$pp\" \"$to${o}$n$pp\"\n\n";
+               }
+       return($ret);
+       }
+
+sub read_options
+       {
+       # Many options are handled in a similar way. In particular
+       # no-xxx sets zero or more scalars to 1.
+       # Process these using a hash containing the option name and
+       # reference to the scalars to set.
+
+       my %valid_options = (
+               "no-rc2" => \$no_rc2,
+               "no-rc4" => \$no_rc4,
+               "no-rc5" => \$no_rc5,
+               "no-idea" => \$no_idea,
+               "no-aes" => \$no_aes,
+               "no-camellia" => \$no_camellia,
+               "no-seed" => \$no_seed,
+               "no-des" => \$no_des,
+               "no-bf" => \$no_bf,
+               "no-cast" => \$no_cast,
+               "no-md2" => \$no_md2,
+               "no-md4" => \$no_md4,
+               "no-md5" => \$no_md5,
+               "no-sha" => \$no_sha,
+               "no-sha1" => \$no_sha1,
+               "no-ripemd" => \$no_ripemd,
+               "no-mdc2" => \$no_mdc2,
+               "no-whirlpool" => \$no_whirlpool,
+               "no-patents" => 
+                       [\$no_rc2, \$no_rc4, \$no_rc5, \$no_idea, \$no_rsa],
+               "no-rsa" => \$no_rsa,
+               "no-dsa" => \$no_dsa,
+               "no-dh" => \$no_dh,
+               "no-hmac" => \$no_hmac,
+               "no-asm" => \$no_asm,
+               "nasm" => \$nasm,
+               "nw-nasm" => \$nw_nasm,
+               "nw-mwasm" => \$nw_mwasm,
+               "gaswin" => \$gaswin,
+               "no-ssl2" => \$no_ssl2,
+               "no-ssl3" => \$no_ssl3,
+               "no-tlsext" => \$no_tlsext,
+               "no-cms" => \$no_cms,
+               "no-jpake" => \$no_jpake,
+               "no-err" => \$no_err,
+               "no-sock" => \$no_sock,
+               "no-krb5" => \$no_krb5,
+               "no-ec" => \$no_ec,
+               "no-ecdsa" => \$no_ecdsa,
+               "no-ecdh" => \$no_ecdh,
+               "no-gost" => \$no_gost,
+               "no-engine" => \$no_engine,
+               "no-hw" => \$no_hw,
+               "just-ssl" =>
+                       [\$no_rc2, \$no_idea, \$no_des, \$no_bf, \$no_cast,
+                         \$no_md2, \$no_sha, \$no_mdc2, \$no_dsa, \$no_dh,
+                         \$no_ssl2, \$no_err, \$no_ripemd, \$no_rc5,
+                         \$no_aes, \$no_camellia, \$no_seed],
+               "rsaref" => 0,
+               "gcc" => \$gcc,
+               "debug" => \$debug,
+               "profile" => \$profile,
+               "shlib" => \$shlib,
+               "dll" => \$shlib,
+               "shared" => 0,
+               "no-gmp" => 0,
+               "no-rfc3779" => 0,
+               "no-montasm" => 0,
+               "no-shared" => 0,
+               "no-store" => 0,
+               "no-zlib" => 0,
+               "no-zlib-dynamic" => 0,
+               );
+
+       if (exists $valid_options{$_})
+               {
+               my $r = $valid_options{$_};
+               if ( ref $r eq "SCALAR")
+                       { $$r = 1;}
+               elsif ( ref $r eq "ARRAY")
+                       {
+                       my $r2;
+                       foreach $r2 (@$r)
+                               {
+                               $$r2 = 1;
+                               }
+                       }
+               }
+       elsif (/^no-comp$/) { $xcflags = "-DOPENSSL_NO_COMP $xcflags"; }
+       elsif (/^enable-zlib$/) { $zlib_opt = 1 if $zlib_opt == 0 }
+       elsif (/^enable-zlib-dynamic$/)
+               {
+               $zlib_opt = 2;
+               }
+       elsif (/^no-static-engine/)
+               {
+               $no_static_engine = 1;
+               }
+       elsif (/^enable-static-engine/)
+               {
+               $no_static_engine = 0;
+               }
+       # There are also enable-xxx options which correspond to
+       # the no-xxx. Since the scalars are enabled by default
+       # these can be ignored.
+       elsif (/^enable-/)
+               {
+               my $t = $_;
+               $t =~ s/^enable/no/;
+               if (exists $valid_options{$t})
+                       {return 1;}
+               return 0;
+               }
+       # experimental-xxx is mostly like enable-xxx, but opensslconf.v
+       # will still set OPENSSL_NO_xxx unless we set OPENSSL_EXPERIMENTAL_xxx.
+       # (No need to fail if we don't know the algorithm -- this is for adventurous users only.)
+       elsif (/^experimental-/)
+               {
+               my $algo, $ALGO;
+               ($algo = $_) =~ s/^experimental-//;
+               ($ALGO = $algo) =~ tr/[a-z]/[A-Z]/;
+
+               $xcflags="-DOPENSSL_EXPERIMENTAL_$ALGO $xcflags";
+               
+               }
+       elsif (/^--with-krb5-flavor=(.*)$/)
+               {
+               my $krb5_flavor = $1;
+               if ($krb5_flavor =~ /^force-[Hh]eimdal$/)
+                       {
+                       $xcflags="-DKRB5_HEIMDAL $xcflags";
+                       }
+               elsif ($krb5_flavor =~ /^MIT/i)
+                       {
+                       $xcflags="-DKRB5_MIT $xcflags";
+                       if ($krb5_flavor =~ /^MIT[._-]*1[._-]*[01]/i)
+                               {
+                               $xcflags="-DKRB5_MIT_OLD11 $xcflags"
+                               }
+                       }
+               }
+       elsif (/^([^=]*)=(.*)$/){ $VARS{$1}=$2; }
+       elsif (/^-[lL].*$/)     { $l_flags.="$_ "; }
+       elsif ((!/^-help/) && (!/^-h/) && (!/^-\?/) && /^-.*$/)
+               { $c_flags.="$_ "; }
+       else { return(0); }
+       return(1);
+       }
diff --git a/deps/openssl/openssl/util/mkcerts.sh b/deps/openssl/openssl/util/mkcerts.sh
new file mode 100755 (executable)
index 0000000..0184fcb
--- /dev/null
@@ -0,0 +1,220 @@
+#!/bin/sh
+
+# This script will re-make all the required certs.
+# cd apps
+# sh ../util/mkcerts.sh
+# mv ca-cert.pem pca-cert.pem ../certs
+# cd ..
+# cat certs/*.pem >>apps/server.pem
+# cat certs/*.pem >>apps/server2.pem
+# SSLEAY=`pwd`/apps/ssleay; export SSLEAY
+# sh tools/c_rehash certs
+#
+CAbits=1024
+SSLEAY="../apps/openssl"
+CONF="-config ../apps/openssl.cnf"
+
+# create pca request.
+echo creating $CAbits bit PCA cert request
+$SSLEAY req $CONF \
+       -new -md5 -newkey $CAbits \
+       -keyout pca-key.pem \
+       -out pca-req.pem -nodes >/dev/null <<EOF
+AU
+Queensland
+.
+CryptSoft Pty Ltd
+.
+Test PCA (1024 bit)
+
+
+
+EOF
+
+if [ $? != 0 ]; then
+       echo problems generating PCA request
+       exit 1
+fi
+
+#sign it.
+echo
+echo self signing PCA
+$SSLEAY x509 -md5 -days 1461 \
+       -req -signkey pca-key.pem \
+       -CAcreateserial -CAserial pca-cert.srl \
+       -in pca-req.pem -out pca-cert.pem
+
+if [ $? != 0 ]; then
+       echo problems self signing PCA cert
+       exit 1
+fi
+echo
+
+# create ca request.
+echo creating $CAbits bit CA cert request
+$SSLEAY req $CONF \
+       -new -md5 -newkey $CAbits \
+       -keyout ca-key.pem \
+       -out ca-req.pem -nodes >/dev/null <<EOF
+AU
+Queensland
+.
+CryptSoft Pty Ltd
+.
+Test CA (1024 bit)
+
+
+
+EOF
+
+if [ $? != 0 ]; then
+       echo problems generating CA request
+       exit 1
+fi
+
+#sign it.
+echo
+echo signing CA
+$SSLEAY x509 -md5 -days 1461 \
+       -req \
+       -CAcreateserial -CAserial pca-cert.srl \
+       -CA pca-cert.pem -CAkey pca-key.pem \
+       -in ca-req.pem -out ca-cert.pem
+
+if [ $? != 0 ]; then
+       echo problems signing CA cert
+       exit 1
+fi
+echo
+
+# create server request.
+echo creating 512 bit server cert request
+$SSLEAY req $CONF \
+       -new -md5 -newkey 512 \
+       -keyout s512-key.pem \
+       -out s512-req.pem -nodes >/dev/null <<EOF
+AU
+Queensland
+.
+CryptSoft Pty Ltd
+.
+Server test cert (512 bit)
+
+
+
+EOF
+
+if [ $? != 0 ]; then
+       echo problems generating 512 bit server cert request
+       exit 1
+fi
+
+#sign it.
+echo
+echo signing 512 bit server cert
+$SSLEAY x509 -md5 -days 365 \
+       -req \
+       -CAcreateserial -CAserial ca-cert.srl \
+       -CA ca-cert.pem -CAkey ca-key.pem \
+       -in s512-req.pem -out server.pem
+
+if [ $? != 0 ]; then
+       echo problems signing 512 bit server cert
+       exit 1
+fi
+echo
+
+# create 1024 bit server request.
+echo creating 1024 bit server cert request
+$SSLEAY req $CONF \
+       -new -md5 -newkey 1024 \
+       -keyout s1024key.pem \
+       -out s1024req.pem -nodes >/dev/null <<EOF
+AU
+Queensland
+.
+CryptSoft Pty Ltd
+.
+Server test cert (1024 bit)
+
+
+
+EOF
+
+if [ $? != 0 ]; then
+       echo problems generating 1024 bit server cert request
+       exit 1
+fi
+
+#sign it.
+echo
+echo signing 1024 bit server cert
+$SSLEAY x509 -md5 -days 365 \
+       -req \
+       -CAcreateserial -CAserial ca-cert.srl \
+       -CA ca-cert.pem -CAkey ca-key.pem \
+       -in s1024req.pem -out server2.pem
+
+if [ $? != 0 ]; then
+       echo problems signing 1024 bit server cert
+       exit 1
+fi
+echo
+
+# create 512 bit client request.
+echo creating 512 bit client cert request
+$SSLEAY req $CONF \
+       -new -md5 -newkey 512 \
+       -keyout c512-key.pem \
+       -out c512-req.pem -nodes >/dev/null <<EOF
+AU
+Queensland
+.
+CryptSoft Pty Ltd
+.
+Client test cert (512 bit)
+
+
+
+EOF
+
+if [ $? != 0 ]; then
+       echo problems generating 512 bit client cert request
+       exit 1
+fi
+
+#sign it.
+echo
+echo signing 512 bit client cert
+$SSLEAY x509 -md5 -days 365 \
+       -req \
+       -CAcreateserial -CAserial ca-cert.srl \
+       -CA ca-cert.pem -CAkey ca-key.pem \
+       -in c512-req.pem -out client.pem
+
+if [ $? != 0 ]; then
+       echo problems signing 512 bit client cert
+       exit 1
+fi
+
+echo cleanup
+
+cat pca-key.pem  >> pca-cert.pem
+cat ca-key.pem   >> ca-cert.pem
+cat s512-key.pem >> server.pem
+cat s1024key.pem >> server2.pem
+cat c512-key.pem >> client.pem
+
+for i in pca-cert.pem ca-cert.pem server.pem server2.pem client.pem
+do
+$SSLEAY x509 -issuer -subject -in $i -noout >$$
+cat $$
+/bin/cat $i >>$$
+/bin/mv $$ $i
+done
+
+#/bin/rm -f *key.pem *req.pem *.srl
+
+echo Finished
+
diff --git a/deps/openssl/openssl/util/mkdef.pl b/deps/openssl/openssl/util/mkdef.pl
new file mode 100755 (executable)
index 0000000..ab47329
--- /dev/null
@@ -0,0 +1,1509 @@
+#!/usr/local/bin/perl -w
+#
+# generate a .def file
+#
+# It does this by parsing the header files and looking for the
+# prototyped functions: it then prunes the output.
+#
+# Intermediary files are created, call libeay.num and ssleay.num,...
+# Previously, they had the following format:
+#
+#      routine-name    nnnn
+#
+# But that isn't enough for a number of reasons, the first on being that
+# this format is (needlessly) very Win32-centric, and even then...
+# One of the biggest problems is that there's no information about what
+# routines should actually be used, which varies with what crypto algorithms
+# are disabled.  Also, some operating systems (for example VMS with VAX C)
+# need to keep track of the global variables as well as the functions.
+#
+# So, a remake of this script is done so as to include information on the
+# kind of symbol it is (function or variable) and what algorithms they're
+# part of.  This will allow easy translating to .def files or the corresponding
+# file in other operating systems (a .opt file for VMS, possibly with a .mar
+# file).
+#
+# The format now becomes:
+#
+#      routine-name    nnnn    info
+#
+# and the "info" part is actually a colon-separated string of fields with
+# the following meaning:
+#
+#      existence:platform:kind:algorithms
+#
+# - "existence" can be "EXIST" or "NOEXIST" depending on if the symbol is
+#   found somewhere in the source, 
+# - "platforms" is empty if it exists on all platforms, otherwise it contains
+#   comma-separated list of the platform, just as they are if the symbol exists
+#   for those platforms, or prepended with a "!" if not.  This helps resolve
+#   symbol name variants for platforms where the names are too long for the
+#   compiler or linker, or if the systems is case insensitive and there is a
+#   clash, or the symbol is implemented differently (see
+#   EXPORT_VAR_AS_FUNCTION).  This script assumes renaming of symbols is found
+#   in the file crypto/symhacks.h.
+#   The semantics for the platforms is that every item is checked against the
+#   environment.  For the negative items ("!FOO"), if any of them is false
+#   (i.e. "FOO" is true) in the environment, the corresponding symbol can't be
+#   used.  For the positive itms, if all of them are false in the environment,
+#   the corresponding symbol can't be used.  Any combination of positive and
+#   negative items are possible, and of course leave room for some redundancy.
+# - "kind" is "FUNCTION" or "VARIABLE".  The meaning of that is obvious.
+# - "algorithms" is a comma-separated list of algorithm names.  This helps
+#   exclude symbols that are part of an algorithm that some user wants to
+#   exclude.
+#
+
+my $debug=0;
+
+my $crypto_num= "util/libeay.num";
+my $ssl_num=    "util/ssleay.num";
+my $libname;
+
+my $do_update = 0;
+my $do_rewrite = 1;
+my $do_crypto = 0;
+my $do_ssl = 0;
+my $do_ctest = 0;
+my $do_ctestall = 0;
+my $do_checkexist = 0;
+
+my $VMSVAX=0;
+my $VMSNonVAX=0;
+my $VMS=0;
+my $W32=0;
+my $W16=0;
+my $NT=0;
+my $OS2=0;
+# Set this to make typesafe STACK definitions appear in DEF
+my $safe_stack_def = 0;
+
+my @known_platforms = ( "__FreeBSD__", "PERL5", "NeXT",
+                       "EXPORT_VAR_AS_FUNCTION", "ZLIB" );
+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",
+                        "MDC2", "WHIRLPOOL", "RSA", "DSA", "DH", "EC", "ECDH", "ECDSA",
+                        "HMAC", "AES", "CAMELLIA", "SEED", "GOST",
+                        # Envelope "algorithms"
+                        "EVP", "X509", "ASN1_TYPEDEFS",
+                        # Helper "algorithms"
+                        "BIO", "COMP", "BUFFER", "LHASH", "STACK", "ERR",
+                        "LOCKING",
+                        # External "algorithms"
+                        "FP_API", "STDIO", "SOCK", "KRB5", "DGRAM",
+                        # Engines
+                        "STATIC_ENGINE", "ENGINE", "HW", "GMP",
+                        # RFC3779
+                        "RFC3779",
+                        # TLS
+                        "TLSEXT", "PSK",
+                        # CMS
+                        "CMS",
+                        # CryptoAPI Engine
+                        "CAPIENG",
+                        # SSL v2
+                        "SSL2",
+                        # JPAKE
+                        "JPAKE",
+                        # Deprecated functions
+                        "DEPRECATED" );
+
+my $options="";
+open(IN,"<Makefile") || die "unable to open Makefile!\n";
+while(<IN>) {
+    $options=$1 if (/^OPTIONS=(.*)$/);
+}
+close(IN);
+
+# The following ciphers may be excluded (by Configure). This means functions
+# defined with ifndef(NO_XXX) are not included in the .def file, and everything
+# in directory xxx is ignored.
+my $no_rc2; my $no_rc4; my $no_rc5; my $no_idea; my $no_des; my $no_bf;
+my $no_cast; my $no_whirlpool; my $no_camellia; my $no_seed;
+my $no_md2; my $no_md4; my $no_md5; my $no_sha; my $no_ripemd; my $no_mdc2;
+my $no_rsa; my $no_dsa; my $no_dh; my $no_hmac=0; my $no_aes; my $no_krb5;
+my $no_ec; my $no_ecdsa; my $no_ecdh; my $no_engine; my $no_hw;
+my $no_fp_api; my $no_static_engine=1; my $no_gmp; my $no_deprecated;
+my $no_rfc3779; my $no_psk; my $no_tlsext; my $no_cms; my $no_capieng;
+my $no_jpake; my $no_ssl2;
+
+my $zlib;
+
+
+foreach (@ARGV, split(/ /, $options))
+       {
+       $debug=1 if $_ eq "debug";
+       $W32=1 if $_ eq "32";
+       $W16=1 if $_ eq "16";
+       if($_ eq "NT") {
+               $W32 = 1;
+               $NT = 1;
+       }
+       if ($_ eq "VMS-VAX") {
+               $VMS=1;
+               $VMSVAX=1;
+       }
+       if ($_ eq "VMS-NonVAX") {
+               $VMS=1;
+               $VMSNonVAX=1;
+       }
+       $VMS=1 if $_ eq "VMS";
+       $OS2=1 if $_ eq "OS2";
+       if ($_ eq "zlib" || $_ eq "enable-zlib" || $_ eq "zlib-dynamic"
+                        || $_ eq "enable-zlib-dynamic") {
+               $zlib = 1;
+       }
+
+       $do_ssl=1 if $_ eq "ssleay";
+       if ($_ eq "ssl") {
+               $do_ssl=1; 
+               $libname=$_
+       }
+       $do_crypto=1 if $_ eq "libeay";
+       if ($_ eq "crypto") {
+               $do_crypto=1;
+               $libname=$_;
+       }
+       $no_static_engine=1 if $_ eq "no-static-engine";
+       $no_static_engine=0 if $_ eq "enable-static-engine";
+       $do_update=1 if $_ eq "update";
+       $do_rewrite=1 if $_ eq "rewrite";
+       $do_ctest=1 if $_ eq "ctest";
+       $do_ctestall=1 if $_ eq "ctestall";
+       $do_checkexist=1 if $_ eq "exist";
+       #$safe_stack_def=1 if $_ eq "-DDEBUG_SAFESTACK";
+
+       if    (/^no-rc2$/)      { $no_rc2=1; }
+       elsif (/^no-rc4$/)      { $no_rc4=1; }
+       elsif (/^no-rc5$/)      { $no_rc5=1; }
+       elsif (/^no-idea$/)     { $no_idea=1; }
+       elsif (/^no-des$/)      { $no_des=1; $no_mdc2=1; }
+       elsif (/^no-bf$/)       { $no_bf=1; }
+       elsif (/^no-cast$/)     { $no_cast=1; }
+       elsif (/^no-whirlpool$/)     { $no_whirlpool=1; }
+       elsif (/^no-md2$/)      { $no_md2=1; }
+       elsif (/^no-md4$/)      { $no_md4=1; }
+       elsif (/^no-md5$/)      { $no_md5=1; }
+       elsif (/^no-sha$/)      { $no_sha=1; }
+       elsif (/^no-ripemd$/)   { $no_ripemd=1; }
+       elsif (/^no-mdc2$/)     { $no_mdc2=1; }
+       elsif (/^no-rsa$/)      { $no_rsa=1; }
+       elsif (/^no-dsa$/)      { $no_dsa=1; }
+       elsif (/^no-dh$/)       { $no_dh=1; }
+       elsif (/^no-ec$/)       { $no_ec=1; }
+       elsif (/^no-ecdsa$/)    { $no_ecdsa=1; }
+       elsif (/^no-ecdh$/)     { $no_ecdh=1; }
+       elsif (/^no-hmac$/)     { $no_hmac=1; }
+       elsif (/^no-aes$/)      { $no_aes=1; }
+       elsif (/^no-camellia$/) { $no_camellia=1; }
+       elsif (/^no-seed$/)     { $no_seed=1; }
+       elsif (/^no-evp$/)      { $no_evp=1; }
+       elsif (/^no-lhash$/)    { $no_lhash=1; }
+       elsif (/^no-stack$/)    { $no_stack=1; }
+       elsif (/^no-err$/)      { $no_err=1; }
+       elsif (/^no-buffer$/)   { $no_buffer=1; }
+       elsif (/^no-bio$/)      { $no_bio=1; }
+       #elsif (/^no-locking$/) { $no_locking=1; }
+       elsif (/^no-comp$/)     { $no_comp=1; }
+       elsif (/^no-dso$/)      { $no_dso=1; }
+       elsif (/^no-krb5$/)     { $no_krb5=1; }
+       elsif (/^no-engine$/)   { $no_engine=1; }
+       elsif (/^no-hw$/)       { $no_hw=1; }
+       elsif (/^no-gmp$/)      { $no_gmp=1; }
+       elsif (/^no-rfc3779$/)  { $no_rfc3779=1; }
+       elsif (/^no-tlsext$/)   { $no_tlsext=1; }
+       elsif (/^no-cms$/)      { $no_cms=1; }
+       elsif (/^no-ssl2$/)     { $no_ssl2=1; }
+       elsif (/^no-capieng$/)  { $no_capieng=1; }
+       elsif (/^no-jpake$/)    { $no_jpake=1; }
+       }
+
+
+if (!$libname) { 
+       if ($do_ssl) {
+               $libname="SSLEAY";
+       }
+       if ($do_crypto) {
+               $libname="LIBEAY";
+       }
+}
+
+# If no platform is given, assume WIN32
+if ($W32 + $W16 + $VMS + $OS2 == 0) {
+       $W32 = 1;
+}
+
+# Add extra knowledge
+if ($W16) {
+       $no_fp_api=1;
+}
+
+if (!$do_ssl && !$do_crypto)
+       {
+       print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT | OS2 ]\n";
+       exit(1);
+       }
+
+%ssl_list=&load_numbers($ssl_num);
+$max_ssl = $max_num;
+%crypto_list=&load_numbers($crypto_num);
+$max_crypto = $max_num;
+
+my $ssl="ssl/ssl.h";
+$ssl.=" ssl/kssl.h";
+$ssl.=" ssl/tls1.h";
+
+my $crypto ="crypto/crypto.h";
+$crypto.=" crypto/o_dir.h";
+$crypto.=" crypto/o_str.h";
+$crypto.=" crypto/o_time.h";
+$crypto.=" crypto/des/des.h crypto/des/des_old.h" ; # unless $no_des;
+$crypto.=" crypto/idea/idea.h" ; # unless $no_idea;
+$crypto.=" crypto/rc4/rc4.h" ; # unless $no_rc4;
+$crypto.=" crypto/rc5/rc5.h" ; # unless $no_rc5;
+$crypto.=" crypto/rc2/rc2.h" ; # unless $no_rc2;
+$crypto.=" crypto/bf/blowfish.h" ; # unless $no_bf;
+$crypto.=" crypto/cast/cast.h" ; # unless $no_cast;
+$crypto.=" crypto/whrlpool/whrlpool.h" ;
+$crypto.=" crypto/md2/md2.h" ; # unless $no_md2;
+$crypto.=" crypto/md4/md4.h" ; # unless $no_md4;
+$crypto.=" crypto/md5/md5.h" ; # unless $no_md5;
+$crypto.=" crypto/mdc2/mdc2.h" ; # unless $no_mdc2;
+$crypto.=" crypto/sha/sha.h" ; # unless $no_sha;
+$crypto.=" crypto/ripemd/ripemd.h" ; # unless $no_ripemd;
+$crypto.=" crypto/aes/aes.h" ; # unless $no_aes;
+$crypto.=" crypto/camellia/camellia.h" ; # unless $no_camellia;
+$crypto.=" crypto/seed/seed.h"; # unless $no_seed;
+
+$crypto.=" crypto/bn/bn.h";
+$crypto.=" crypto/rsa/rsa.h" ; # unless $no_rsa;
+$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/ecdh/ecdh.h" ; # unless $no_ecdh;
+$crypto.=" crypto/hmac/hmac.h" ; # unless $no_hmac;
+
+$crypto.=" crypto/engine/engine.h"; # unless $no_engine;
+$crypto.=" crypto/stack/stack.h" ; # unless $no_stack;
+$crypto.=" crypto/buffer/buffer.h" ; # unless $no_buffer;
+$crypto.=" crypto/bio/bio.h" ; # unless $no_bio;
+$crypto.=" crypto/dso/dso.h" ; # unless $no_dso;
+$crypto.=" crypto/lhash/lhash.h" ; # unless $no_lhash;
+$crypto.=" crypto/conf/conf.h";
+$crypto.=" crypto/txt_db/txt_db.h";
+
+$crypto.=" crypto/evp/evp.h" ; # unless $no_evp;
+$crypto.=" crypto/objects/objects.h";
+$crypto.=" crypto/pem/pem.h";
+#$crypto.=" crypto/meth/meth.h";
+$crypto.=" crypto/asn1/asn1.h";
+$crypto.=" crypto/asn1/asn1t.h";
+$crypto.=" crypto/asn1/asn1_mac.h";
+$crypto.=" crypto/err/err.h" ; # unless $no_err;
+$crypto.=" crypto/pkcs7/pkcs7.h";
+$crypto.=" crypto/pkcs12/pkcs12.h";
+$crypto.=" crypto/x509/x509.h";
+$crypto.=" crypto/x509/x509_vfy.h";
+$crypto.=" crypto/x509v3/x509v3.h";
+$crypto.=" crypto/ts/ts.h";
+$crypto.=" crypto/rand/rand.h";
+$crypto.=" crypto/comp/comp.h" ; # unless $no_comp;
+$crypto.=" crypto/ocsp/ocsp.h";
+$crypto.=" crypto/ui/ui.h crypto/ui/ui_compat.h";
+$crypto.=" crypto/krb5/krb5_asn.h";
+#$crypto.=" crypto/store/store.h";
+$crypto.=" crypto/pqueue/pqueue.h";
+$crypto.=" crypto/cms/cms.h";
+$crypto.=" crypto/jpake/jpake.h";
+$crypto.=" crypto/modes/modes.h";
+
+my $symhacks="crypto/symhacks.h";
+
+my @ssl_symbols = &do_defs("SSLEAY", $ssl, $symhacks);
+my @crypto_symbols = &do_defs("LIBEAY", $crypto, $symhacks);
+
+if ($do_update) {
+
+if ($do_ssl == 1) {
+
+       &maybe_add_info("SSLEAY",*ssl_list,@ssl_symbols);
+       if ($do_rewrite == 1) {
+               open(OUT, ">$ssl_num");
+               &rewrite_numbers(*OUT,"SSLEAY",*ssl_list,@ssl_symbols);
+       } else {
+               open(OUT, ">>$ssl_num");
+       }
+       &update_numbers(*OUT,"SSLEAY",*ssl_list,$max_ssl,@ssl_symbols);
+       close OUT;
+}
+
+if($do_crypto == 1) {
+
+       &maybe_add_info("LIBEAY",*crypto_list,@crypto_symbols);
+       if ($do_rewrite == 1) {
+               open(OUT, ">$crypto_num");
+               &rewrite_numbers(*OUT,"LIBEAY",*crypto_list,@crypto_symbols);
+       } else {
+               open(OUT, ">>$crypto_num");
+       }
+       &update_numbers(*OUT,"LIBEAY",*crypto_list,$max_crypto,@crypto_symbols);
+       close OUT;
+} 
+
+} elsif ($do_checkexist) {
+       &check_existing(*ssl_list, @ssl_symbols)
+               if $do_ssl == 1;
+       &check_existing(*crypto_list, @crypto_symbols)
+               if $do_crypto == 1;
+} elsif ($do_ctest || $do_ctestall) {
+
+       print <<"EOF";
+
+/* Test file to check all DEF file symbols are present by trying
+ * to link to all of them. This is *not* intended to be run!
+ */
+
+int main()
+{
+EOF
+       &print_test_file(*STDOUT,"SSLEAY",*ssl_list,$do_ctestall,@ssl_symbols)
+               if $do_ssl == 1;
+
+       &print_test_file(*STDOUT,"LIBEAY",*crypto_list,$do_ctestall,@crypto_symbols)
+               if $do_crypto == 1;
+
+       print "}\n";
+
+} else {
+
+       &print_def_file(*STDOUT,$libname,*ssl_list,@ssl_symbols)
+               if $do_ssl == 1;
+
+       &print_def_file(*STDOUT,$libname,*crypto_list,@crypto_symbols)
+               if $do_crypto == 1;
+
+}
+
+
+sub do_defs
+{
+       my($name,$files,$symhacksfile)=@_;
+       my $file;
+       my @ret;
+       my %syms;
+       my %platform;           # For anything undefined, we assume ""
+       my %kind;               # For anything undefined, we assume "FUNCTION"
+       my %algorithm;          # For anything undefined, we assume ""
+       my %variant;
+       my %variant_cnt;        # To be able to allocate "name{n}" if "name"
+                               # is the same name as the original.
+       my $cpp;
+       my %unknown_algorithms = ();
+
+       foreach $file (split(/\s+/,$symhacksfile." ".$files))
+               {
+               print STDERR "DEBUG: starting on $file:\n" if $debug;
+               open(IN,"<$file") || die "unable to open $file:$!\n";
+               my $line = "", my $def= "";
+               my %tag = (
+                       (map { $_ => 0 } @known_platforms),
+                       (map { "OPENSSL_SYS_".$_ => 0 } @known_ossl_platforms),
+                       (map { "OPENSSL_NO_".$_ => 0 } @known_algorithms),
+                       NOPROTO         => 0,
+                       PERL5           => 0,
+                       _WINDLL         => 0,
+                       CONST_STRICT    => 0,
+                       TRUE            => 1,
+               );
+               my $symhacking = $file eq $symhacksfile;
+               my @current_platforms = ();
+               my @current_algorithms = ();
+
+               # params: symbol, alias, platforms, kind
+               # The reason to put this subroutine in a variable is that
+               # it will otherwise create it's own, unshared, version of
+               # %tag and %variant...
+               my $make_variant = sub
+               {
+                       my ($s, $a, $p, $k) = @_;
+                       my ($a1, $a2);
+
+                       print STDERR "DEBUG: make_variant: Entered with ",$s,", ",$a,", ",(defined($p)?$p:""),", ",(defined($k)?$k:""),"\n" if $debug;
+                       if (defined($p))
+                       {
+                               $a1 = join(",",$p,
+                                          grep(!/^$/,
+                                               map { $tag{$_} == 1 ? $_ : "" }
+                                               @known_platforms));
+                       }
+                       else
+                       {
+                               $a1 = join(",",
+                                          grep(!/^$/,
+                                               map { $tag{$_} == 1 ? $_ : "" }
+                                               @known_platforms));
+                       }
+                       $a2 = join(",",
+                                  grep(!/^$/,
+                                       map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : "" }
+                                       @known_ossl_platforms));
+                       print STDERR "DEBUG: make_variant: a1 = $a1; a2 = $a2\n" if $debug;
+                       if ($a1 eq "") { $a1 = $a2; }
+                       elsif ($a1 ne "" && $a2 ne "") { $a1 .= ",".$a2; }
+                       if ($a eq $s)
+                       {
+                               if (!defined($variant_cnt{$s}))
+                               {
+                                       $variant_cnt{$s} = 0;
+                               }
+                               $variant_cnt{$s}++;
+                               $a .= "{$variant_cnt{$s}}";
+                       }
+                       my $toadd = $a.":".$a1.(defined($k)?":".$k:"");
+                       my $togrep = $s.'(\{[0-9]+\})?:'.$a1.(defined($k)?":".$k:"");
+                       if (!grep(/^$togrep$/,
+                                 split(/;/, defined($variant{$s})?$variant{$s}:""))) {
+                               if (defined($variant{$s})) { $variant{$s} .= ";"; }
+                               $variant{$s} .= $toadd;
+                       }
+                       print STDERR "DEBUG: make_variant: Exit with variant of ",$s," = ",$variant{$s},"\n" if $debug;
+               };
+
+               print STDERR "DEBUG: parsing ----------\n" if $debug;
+               while(<IN>) {
+                       if (/\/\* Error codes for the \w+ functions\. \*\//)
+                               {
+                               undef @tag;
+                               last;
+                               }
+                       if ($line ne '') {
+                               $_ = $line . $_;
+                               $line = '';
+                       }
+
+                       if (/\\$/) {
+                               chomp; # remove eol
+                               chop; # remove ending backslash
+                               $line = $_;
+                               next;
+                       }
+
+                       if(/\/\*/) {
+                               if (not /\*\//) {       # multiline comment...
+                                       $line = $_;     # ... just accumulate
+                                       next;
+                               } else {
+                                       s/\/\*.*?\*\///gs;# wipe it
+                               }
+                       }
+
+                       if ($cpp) {
+                               $cpp++ if /^#\s*if/;
+                               $cpp-- if /^#\s*endif/;
+                               next;
+                       }
+                       $cpp = 1 if /^#.*ifdef.*cplusplus/;
+
+                       s/{[^{}]*}//gs;                      # ignore {} blocks
+                       print STDERR "DEBUG: \$def=\"$def\"\n" if $debug && $def ne "";
+                       print STDERR "DEBUG: \$_=\"$_\"\n" if $debug;
+                       if (/^\#\s*ifndef\s+(.*)/) {
+                               push(@tag,"-");
+                               push(@tag,$1);
+                               $tag{$1}=-1;
+                               print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
+                       } elsif (/^\#\s*if\s+!defined\(([^\)]+)\)/) {
+                               push(@tag,"-");
+                               if (/^\#\s*if\s+(!defined\(([^\)]+)\)(\s+\&\&\s+!defined\(([^\)]+)\))*)$/) {
+                                       my $tmp_1 = $1;
+                                       my $tmp_;
+                                       foreach $tmp_ (split '\&\&',$tmp_1) {
+                                               $tmp_ =~ /!defined\(([^\)]+)\)/;
+                                               print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
+                                               push(@tag,$1);
+                                               $tag{$1}=-1;
+                                       }
+                               } else {
+                                       print STDERR "Warning: $file: complicated expression: $_" if $debug; # because it is O...
+                                       print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
+                                       push(@tag,$1);
+                                       $tag{$1}=-1;
+                               }
+                       } elsif (/^\#\s*ifdef\s+(\S*)/) {
+                               push(@tag,"-");
+                               push(@tag,$1);
+                               $tag{$1}=1;
+                               print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
+                       } elsif (/^\#\s*if\s+defined\(([^\)]+)\)/) {
+                               push(@tag,"-");
+                               if (/^\#\s*if\s+(defined\(([^\)]+)\)(\s+\|\|\s+defined\(([^\)]+)\))*)$/) {
+                                       my $tmp_1 = $1;
+                                       my $tmp_;
+                                       foreach $tmp_ (split '\|\|',$tmp_1) {
+                                               $tmp_ =~ /defined\(([^\)]+)\)/;
+                                               print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
+                                               push(@tag,$1);
+                                               $tag{$1}=1;
+                                       }
+                               } else {
+                                       print STDERR "Warning: $file: complicated expression: $_\n" if $debug; # because it is O...
+                                       print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
+                                       push(@tag,$1);
+                                       $tag{$1}=1;
+                               }
+                       } elsif (/^\#\s*error\s+(\w+) is disabled\./) {
+                               my $tag_i = $#tag;
+                               while($tag[$tag_i] ne "-") {
+                                       if ($tag[$tag_i] eq "OPENSSL_NO_".$1) {
+                                               $tag{$tag[$tag_i]}=2;
+                                               print STDERR "DEBUG: $file: chaged tag $1 = 2\n" if $debug;
+                                       }
+                                       $tag_i--;
+                               }
+                       } elsif (/^\#\s*endif/) {
+                               my $tag_i = $#tag;
+                               while($tag_i > 0 && $tag[$tag_i] ne "-") {
+                                       my $t=$tag[$tag_i];
+                                       print STDERR "DEBUG: \$t=\"$t\"\n" if $debug;
+                                       if ($tag{$t}==2) {
+                                               $tag{$t}=-1;
+                                       } else {
+                                               $tag{$t}=0;
+                                       }
+                                       print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
+                                       pop(@tag);
+                                       if ($t =~ /^OPENSSL_NO_([A-Z0-9_]+)$/) {
+                                               $t=$1;
+                                       } else {
+                                               $t="";
+                                       }
+                                       if ($t ne ""
+                                           && !grep(/^$t$/, @known_algorithms)) {
+                                               $unknown_algorithms{$t} = 1;
+                                               #print STDERR "DEBUG: Added as unknown algorithm: $t\n" if $debug;
+                                       }
+                                       $tag_i--;
+                               }
+                               pop(@tag);
+                       } elsif (/^\#\s*else/) {
+                               my $tag_i = $#tag;
+                               while($tag[$tag_i] ne "-") {
+                                       my $t=$tag[$tag_i];
+                                       $tag{$t}= -$tag{$t};
+                                       print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
+                                       $tag_i--;
+                               }
+                       } elsif (/^\#\s*if\s+1/) {
+                               push(@tag,"-");
+                               # Dummy tag
+                               push(@tag,"TRUE");
+                               $tag{"TRUE"}=1;
+                               print STDERR "DEBUG: $file: found 1\n" if $debug;
+                       } elsif (/^\#\s*if\s+0/) {
+                               push(@tag,"-");
+                               # Dummy tag
+                               push(@tag,"TRUE");
+                               $tag{"TRUE"}=-1;
+                               print STDERR "DEBUG: $file: found 0\n" if $debug;
+                       } elsif (/^\#\s*define\s+(\w+)\s+(\w+)/
+                                && $symhacking && $tag{'TRUE'} != -1) {
+                               # This is for aliasing.  When we find an alias,
+                               # we have to invert
+                               &$make_variant($1,$2);
+                               print STDERR "DEBUG: $file: defined $1 = $2\n" if $debug;
+                       }
+                       if (/^\#/) {
+                               @current_platforms =
+                                   grep(!/^$/,
+                                        map { $tag{$_} == 1 ? $_ :
+                                                  $tag{$_} == -1 ? "!".$_  : "" }
+                                        @known_platforms);
+                               push @current_platforms
+                                   , grep(!/^$/,
+                                          map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ :
+                                                    $tag{"OPENSSL_SYS_".$_} == -1 ? "!".$_  : "" }
+                                          @known_ossl_platforms);
+                               @current_algorithms =
+                                   grep(!/^$/,
+                                        map { $tag{"OPENSSL_NO_".$_} == -1 ? $_ : "" }
+                                        @known_algorithms);
+                               $def .=
+                                   "#INFO:"
+                                       .join(',',@current_platforms).":"
+                                           .join(',',@current_algorithms).";";
+                               next;
+                       }
+                       if ($tag{'TRUE'} != -1) {
+                               if (/^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) {
+                                       next;
+                               } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
+                                       $def .= "int d2i_$3(void);";
+                                       $def .= "int i2d_$3(void);";
+                                       # Variant for platforms that do not
+                                       # have to access globale variables
+                                       # in shared libraries through functions
+                                       $def .=
+                                           "#INFO:"
+                                               .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
+                                                   .join(',',@current_algorithms).";";
+                                       $def .= "OPENSSL_EXTERN int $2_it;";
+                                       $def .=
+                                           "#INFO:"
+                                               .join(',',@current_platforms).":"
+                                                   .join(',',@current_algorithms).";";
+                                       # Variant for platforms that have to
+                                       # access globale variables in shared
+                                       # libraries through functions
+                                       &$make_variant("$2_it","$2_it",
+                                                     "EXPORT_VAR_AS_FUNCTION",
+                                                     "FUNCTION");
+                                       next;
+                               } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_fname\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
+                                       $def .= "int d2i_$3(void);";
+                                       $def .= "int i2d_$3(void);";
+                                       $def .= "int $3_free(void);";
+                                       $def .= "int $3_new(void);";
+                                       # Variant for platforms that do not
+                                       # have to access globale variables
+                                       # in shared libraries through functions
+                                       $def .=
+                                           "#INFO:"
+                                               .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
+                                                   .join(',',@current_algorithms).";";
+                                       $def .= "OPENSSL_EXTERN int $2_it;";
+                                       $def .=
+                                           "#INFO:"
+                                               .join(',',@current_platforms).":"
+                                                   .join(',',@current_algorithms).";";
+                                       # Variant for platforms that have to
+                                       # access globale variables in shared
+                                       # libraries through functions
+                                       &$make_variant("$2_it","$2_it",
+                                                     "EXPORT_VAR_AS_FUNCTION",
+                                                     "FUNCTION");
+                                       next;
+                               } elsif (/^\s*DECLARE_ASN1_FUNCTIONS\s*\(\s*(\w*)\s*\)/ ||
+                                        /^\s*DECLARE_ASN1_FUNCTIONS_const\s*\(\s*(\w*)\s*\)/) {
+                                       $def .= "int d2i_$1(void);";
+                                       $def .= "int i2d_$1(void);";
+                                       $def .= "int $1_free(void);";
+                                       $def .= "int $1_new(void);";
+                                       # Variant for platforms that do not
+                                       # have to access globale variables
+                                       # in shared libraries through functions
+                                       $def .=
+                                           "#INFO:"
+                                               .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
+                                                   .join(',',@current_algorithms).";";
+                                       $def .= "OPENSSL_EXTERN int $1_it;";
+                                       $def .=
+                                           "#INFO:"
+                                               .join(',',@current_platforms).":"
+                                                   .join(',',@current_algorithms).";";
+                                       # Variant for platforms that have to
+                                       # access globale variables in shared
+                                       # libraries through functions
+                                       &$make_variant("$1_it","$1_it",
+                                                     "EXPORT_VAR_AS_FUNCTION",
+                                                     "FUNCTION");
+                                       next;
+                               } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS_const\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
+                                       $def .= "int d2i_$2(void);";
+                                       $def .= "int i2d_$2(void);";
+                                       # Variant for platforms that do not
+                                       # have to access globale variables
+                                       # in shared libraries through functions
+                                       $def .=
+                                           "#INFO:"
+                                               .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
+                                                   .join(',',@current_algorithms).";";
+                                       $def .= "OPENSSL_EXTERN int $2_it;";
+                                       $def .=
+                                           "#INFO:"
+                                               .join(',',@current_platforms).":"
+                                                   .join(',',@current_algorithms).";";
+                                       # Variant for platforms that have to
+                                       # access globale variables in shared
+                                       # libraries through functions
+                                       &$make_variant("$2_it","$2_it",
+                                                     "EXPORT_VAR_AS_FUNCTION",
+                                                     "FUNCTION");
+                                       next;
+                               } elsif (/^\s*DECLARE_ASN1_ALLOC_FUNCTIONS\s*\(\s*(\w*)\s*\)/) {
+                                       $def .= "int $1_free(void);";
+                                       $def .= "int $1_new(void);";
+                                       next;
+                               } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
+                                       $def .= "int d2i_$2(void);";
+                                       $def .= "int i2d_$2(void);";
+                                       $def .= "int $2_free(void);";
+                                       $def .= "int $2_new(void);";
+                                       # Variant for platforms that do not
+                                       # have to access globale variables
+                                       # in shared libraries through functions
+                                       $def .=
+                                           "#INFO:"
+                                               .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
+                                                   .join(',',@current_algorithms).";";
+                                       $def .= "OPENSSL_EXTERN int $2_it;";
+                                       $def .=
+                                           "#INFO:"
+                                               .join(',',@current_platforms).":"
+                                                   .join(',',@current_algorithms).";";
+                                       # Variant for platforms that have to
+                                       # access globale variables in shared
+                                       # libraries through functions
+                                       &$make_variant("$2_it","$2_it",
+                                                     "EXPORT_VAR_AS_FUNCTION",
+                                                     "FUNCTION");
+                                       next;
+                               } elsif (/^\s*DECLARE_ASN1_ITEM\s*\(\s*(\w*)\s*\)/) {
+                                       # Variant for platforms that do not
+                                       # have to access globale variables
+                                       # in shared libraries through functions
+                                       $def .=
+                                           "#INFO:"
+                                               .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
+                                                   .join(',',@current_algorithms).";";
+                                       $def .= "OPENSSL_EXTERN int $1_it;";
+                                       $def .=
+                                           "#INFO:"
+                                               .join(',',@current_platforms).":"
+                                                   .join(',',@current_algorithms).";";
+                                       # Variant for platforms that have to
+                                       # access globale variables in shared
+                                       # libraries through functions
+                                       &$make_variant("$1_it","$1_it",
+                                                     "EXPORT_VAR_AS_FUNCTION",
+                                                     "FUNCTION");
+                                       next;
+                               } elsif (/^\s*DECLARE_ASN1_NDEF_FUNCTION\s*\(\s*(\w*)\s*\)/) {
+                                       $def .= "int i2d_$1_NDEF(void);";
+                               } elsif (/^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) {
+                                       next;
+                               } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION\s*\(\s*(\w*)\s*\)/) {
+                                       $def .= "int $1_print_ctx(void);";
+                                       next;
+                               } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
+                                       $def .= "int $2_print_ctx(void);";
+                                       next;
+                               } elsif (/^\s*DECLARE_PKCS12_STACK_OF\s*\(\s*(\w*)\s*\)/) {
+                                       next;
+                               } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ ||
+                                        /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ ||
+                                        /^DECLARE_PEM_rw_const\s*\(\s*(\w*)\s*,/ ) {
+                                       # Things not in Win16
+                                       $def .=
+                                           "#INFO:"
+                                               .join(',',"!WIN16",@current_platforms).":"
+                                                   .join(',',@current_algorithms).";";
+                                       $def .= "int PEM_read_$1(void);";
+                                       $def .= "int PEM_write_$1(void);";
+                                       $def .=
+                                           "#INFO:"
+                                               .join(',',@current_platforms).":"
+                                                   .join(',',@current_algorithms).";";
+                                       # Things that are everywhere
+                                       $def .= "int PEM_read_bio_$1(void);";
+                                       $def .= "int PEM_write_bio_$1(void);";
+                                       next;
+                               } elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ ||
+                                        /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) {
+                                       # Things not in Win16
+                                       $def .=
+                                           "#INFO:"
+                                               .join(',',"!WIN16",@current_platforms).":"
+                                                   .join(',',@current_algorithms).";";
+                                       $def .= "int PEM_write_$1(void);";
+                                       $def .=
+                                           "#INFO:"
+                                               .join(',',@current_platforms).":"
+                                                   .join(',',@current_algorithms).";";
+                                       # Things that are everywhere
+                                       $def .= "int PEM_write_bio_$1(void);";
+                                       next;
+                               } elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ ||
+                                        /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) {
+                                       # Things not in Win16
+                                       $def .=
+                                           "#INFO:"
+                                               .join(',',"!WIN16",@current_platforms).":"
+                                                   .join(',',@current_algorithms).";";
+                                       $def .= "int PEM_read_$1(void);";
+                                       $def .=
+                                           "#INFO:"
+                                               .join(',',@current_platforms).":"
+                                                   .join(',',@current_algorithms).";";
+                                       # Things that are everywhere
+                                       $def .= "int PEM_read_bio_$1(void);";
+                                       next;
+                               } elsif (/^OPENSSL_DECLARE_GLOBAL\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
+                                       # Variant for platforms that do not
+                                       # have to access globale variables
+                                       # in shared libraries through functions
+                                       $def .=
+                                           "#INFO:"
+                                               .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
+                                                   .join(',',@current_algorithms).";";
+                                       $def .= "OPENSSL_EXTERN int _shadow_$2;";
+                                       $def .=
+                                           "#INFO:"
+                                               .join(',',@current_platforms).":"
+                                                   .join(',',@current_algorithms).";";
+                                       # Variant for platforms that have to
+                                       # access globale variables in shared
+                                       # libraries through functions
+                                       &$make_variant("_shadow_$2","_shadow_$2",
+                                                     "EXPORT_VAR_AS_FUNCTION",
+                                                     "FUNCTION");
+                               } elsif ($tag{'CONST_STRICT'} != 1) {
+                                       if (/\{|\/\*|\([^\)]*$/) {
+                                               $line = $_;
+                                       } else {
+                                               $def .= $_;
+                                       }
+                               }
+                       }
+               }
+               close(IN);
+
+               my $algs;
+               my $plays;
+
+               print STDERR "DEBUG: postprocessing ----------\n" if $debug;
+               foreach (split /;/, $def) {
+                       my $s; my $k = "FUNCTION"; my $p; my $a;
+                       s/^[\n\s]*//g;
+                       s/[\n\s]*$//g;
+                       next if(/\#undef/);
+                       next if(/typedef\W/);
+                       next if(/\#define/);
+
+                       # Reduce argument lists to empty ()
+                       # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {}
+                       while(/\(.*\)/s) {
+                               s/\([^\(\)]+\)/\{\}/gs;
+                               s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs;    #(*f{}) -> f
+                       }
+                       # pretend as we didn't use curly braces: {} -> ()
+                       s/\{\}/\(\)/gs;
+
+                       s/STACK_OF\(\)/void/gs;
+                       s/LHASH_OF\(\)/void/gs;
+
+                       print STDERR "DEBUG: \$_ = \"$_\"\n" if $debug;
+                       if (/^\#INFO:([^:]*):(.*)$/) {
+                               $plats = $1;
+                               $algs = $2;
+                               print STDERR "DEBUG: found info on platforms ($plats) and algorithms ($algs)\n" if $debug;
+                               next;
+                       } elsif (/^\s*OPENSSL_EXTERN\s.*?(\w+(\{[0-9]+\})?)(\[[0-9]*\])*\s*$/) {
+                               $s = $1;
+                               $k = "VARIABLE";
+                               print STDERR "DEBUG: found external variable $s\n" if $debug;
+                       } elsif (/TYPEDEF_\w+_OF/s) {
+                               next;
+                       } elsif (/(\w+)\s*\(\).*/s) {   # first token prior [first] () is
+                               $s = $1;                # a function name!
+                               print STDERR "DEBUG: found function $s\n" if $debug;
+                       } elsif (/\(/ and not (/=/)) {
+                               print STDERR "File $file: cannot parse: $_;\n";
+                               next;
+                       } else {
+                               next;
+                       }
+
+                       $syms{$s} = 1;
+                       $kind{$s} = $k;
+
+                       $p = $plats;
+                       $a = $algs;
+                       $a .= ",BF" if($s =~ /EVP_bf/);
+                       $a .= ",CAST" if($s =~ /EVP_cast/);
+                       $a .= ",DES" if($s =~ /EVP_des/);
+                       $a .= ",DSA" if($s =~ /EVP_dss/);
+                       $a .= ",IDEA" if($s =~ /EVP_idea/);
+                       $a .= ",MD2" if($s =~ /EVP_md2/);
+                       $a .= ",MD4" if($s =~ /EVP_md4/);
+                       $a .= ",MD5" if($s =~ /EVP_md5/);
+                       $a .= ",RC2" if($s =~ /EVP_rc2/);
+                       $a .= ",RC4" if($s =~ /EVP_rc4/);
+                       $a .= ",RC5" if($s =~ /EVP_rc5/);
+                       $a .= ",RIPEMD" if($s =~ /EVP_ripemd/);
+                       $a .= ",SHA" if($s =~ /EVP_sha/);
+                       $a .= ",RSA" if($s =~ /EVP_(Open|Seal)(Final|Init)/);
+                       $a .= ",RSA" if($s =~ /PEM_Seal(Final|Init|Update)/);
+                       $a .= ",RSA" if($s =~ /RSAPrivateKey/);
+                       $a .= ",RSA" if($s =~ /SSLv23?_((client|server)_)?method/);
+
+                       $platform{$s} =
+                           &reduce_platforms((defined($platform{$s})?$platform{$s}.',':"").$p);
+                       $algorithm{$s} .= ','.$a;
+
+                       if (defined($variant{$s})) {
+                               foreach $v (split /;/,$variant{$s}) {
+                                       (my $r, my $p, my $k) = split(/:/,$v);
+                                       my $ip = join ',',map({ /^!(.*)$/ ? $1 : "!".$_ } split /,/, $p);
+                                       $syms{$r} = 1;
+                                       if (!defined($k)) { $k = $kind{$s}; }
+                                       $kind{$r} = $k."(".$s.")";
+                                       $algorithm{$r} = $algorithm{$s};
+                                       $platform{$r} = &reduce_platforms($platform{$s}.",".$p.",".$p);
+                                       $platform{$s} = &reduce_platforms($platform{$s}.','.$ip.','.$ip);
+                                       print STDERR "DEBUG: \$variant{\"$s\"} = ",$v,"; \$r = $r; \$p = ",$platform{$r},"; \$a = ",$algorithm{$r},"; \$kind = ",$kind{$r},"\n" if $debug;
+                               }
+                       }
+                       print STDERR "DEBUG: \$s = $s; \$p = ",$platform{$s},"; \$a = ",$algorithm{$s},"; \$kind = ",$kind{$s},"\n" if $debug;
+               }
+       }
+
+       # Prune the returned symbols
+
+        delete $syms{"bn_dump1"};
+       $platform{"BIO_s_log"} .= ",!WIN32,!WIN16,!macintosh";
+
+       $platform{"PEM_read_NS_CERT_SEQ"} = "VMS";
+       $platform{"PEM_write_NS_CERT_SEQ"} = "VMS";
+       $platform{"PEM_read_P8_PRIV_KEY_INFO"} = "VMS";
+       $platform{"PEM_write_P8_PRIV_KEY_INFO"} = "VMS";
+       $platform{"EVP_sha384"} = "!VMSVAX";
+       $platform{"EVP_sha512"} = "!VMSVAX";
+       $platform{"SHA384_Init"} = "!VMSVAX";
+       $platform{"SHA384_Transform"} = "!VMSVAX";
+       $platform{"SHA384_Update"} = "!VMSVAX";
+       $platform{"SHA384_Final"} = "!VMSVAX";
+       $platform{"SHA384"} = "!VMSVAX";
+       $platform{"SHA512_Init"} = "!VMSVAX";
+       $platform{"SHA512_Transform"} = "!VMSVAX";
+       $platform{"SHA512_Update"} = "!VMSVAX";
+       $platform{"SHA512_Final"} = "!VMSVAX";
+       $platform{"SHA512"} = "!VMSVAX";
+       $platform{"WHIRLPOOL_Init"} = "!VMSVAX";
+       $platform{"WHIRLPOOL"} = "!VMSVAX";
+       $platform{"WHIRLPOOL_BitUpdate"} = "!VMSVAX";
+       $platform{"EVP_whirlpool"} = "!VMSVAX";
+       $platform{"WHIRLPOOL_Final"} = "!VMSVAX";
+       $platform{"WHIRLPOOL_Update"} = "!VMSVAX";
+
+
+       # Info we know about
+
+       push @ret, map { $_."\\".&info_string($_,"EXIST",
+                                             $platform{$_},
+                                             $kind{$_},
+                                             $algorithm{$_}) } keys %syms;
+
+       if (keys %unknown_algorithms) {
+               print STDERR "WARNING: mkdef.pl doesn't know the following algorithms:\n";
+               print STDERR "\t",join("\n\t",keys %unknown_algorithms),"\n";
+       }
+       return(@ret);
+}
+
+# Param: string of comma-separated platform-specs.
+sub reduce_platforms
+{
+       my ($platforms) = @_;
+       my $pl = defined($platforms) ? $platforms : "";
+       my %p = map { $_ => 0 } split /,/, $pl;
+       my $ret;
+
+       print STDERR "DEBUG: Entered reduce_platforms with \"$platforms\"\n"
+           if $debug;
+       # We do this, because if there's code like the following, it really
+       # means the function exists in all cases and should therefore be
+       # everywhere.  By increasing and decreasing, we may attain 0:
+       #
+       # ifndef WIN16
+       #    int foo();
+       # else
+       #    int _fat foo();
+       # endif
+       foreach $platform (split /,/, $pl) {
+               if ($platform =~ /^!(.*)$/) {
+                       $p{$1}--;
+               } else {
+                       $p{$platform}++;
+               }
+       }
+       foreach $platform (keys %p) {
+               if ($p{$platform} == 0) { delete $p{$platform}; }
+       }
+
+       delete $p{""};
+
+       $ret = join(',',sort(map { $p{$_} < 0 ? "!".$_ : $_ } keys %p));
+       print STDERR "DEBUG: Exiting reduce_platforms with \"$ret\"\n"
+           if $debug;
+       return $ret;
+}
+
+sub info_string {
+       (my $symbol, my $exist, my $platforms, my $kind, my $algorithms) = @_;
+
+       my %a = defined($algorithms) ?
+           map { $_ => 1 } split /,/, $algorithms : ();
+       my $k = defined($kind) ? $kind : "FUNCTION";
+       my $ret;
+       my $p = &reduce_platforms($platforms);
+
+       delete $a{""};
+
+       $ret = $exist;
+       $ret .= ":".$p;
+       $ret .= ":".$k;
+       $ret .= ":".join(',',sort keys %a);
+       return $ret;
+}
+
+sub maybe_add_info {
+       (my $name, *nums, my @symbols) = @_;
+       my $sym;
+       my $new_info = 0;
+       my %syms=();
+
+       print STDERR "Updating $name info\n";
+       foreach $sym (@symbols) {
+               (my $s, my $i) = split /\\/, $sym;
+               if (defined($nums{$s})) {
+                       $i =~ s/^(.*?:.*?:\w+)(\(\w+\))?/$1/;
+                       (my $n, my $dummy) = split /\\/, $nums{$s};
+                       if (!defined($dummy) || $i ne $dummy) {
+                               $nums{$s} = $n."\\".$i;
+                               $new_info++;
+                               print STDERR "DEBUG: maybe_add_info for $s: \"$dummy\" => \"$i\"\n" if $debug;
+                       }
+               }
+               $syms{$s} = 1;
+       }
+
+       my @s=sort { &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") } keys %nums;
+       foreach $sym (@s) {
+               (my $n, my $i) = split /\\/, $nums{$sym};
+               if (!defined($syms{$sym}) && $i !~ /^NOEXIST:/) {
+                       $new_info++;
+                       print STDERR "DEBUG: maybe_add_info for $sym: -> undefined\n" if $debug;
+               }
+       }
+       if ($new_info) {
+               print STDERR "$new_info old symbols got an info update\n";
+               if (!$do_rewrite) {
+                       print STDERR "You should do a rewrite to fix this.\n";
+               }
+       } else {
+               print STDERR "No old symbols needed info update\n";
+       }
+}
+
+# Param: string of comma-separated keywords, each possibly prefixed with a "!"
+sub is_valid
+{
+       my ($keywords_txt,$platforms) = @_;
+       my (@keywords) = split /,/,$keywords_txt;
+       my ($falsesum, $truesum) = (0, 1);
+
+       # Param: one keyword
+       sub recognise
+       {
+               my ($keyword,$platforms) = @_;
+
+               if ($platforms) {
+                       # platforms
+                       if ($keyword eq "VMSVAX" && $VMSVAX) { return 1; }
+                       if ($keyword eq "VMSNonVAX" && $VMSNonVAX) { return 1; }
+                       if ($keyword eq "VMS" && $VMS) { return 1; }
+                       if ($keyword eq "WIN32" && $W32) { return 1; }
+                       if ($keyword eq "WIN16" && $W16) { return 1; }
+                       if ($keyword eq "WINNT" && $NT) { return 1; }
+                       if ($keyword eq "OS2" && $OS2) { return 1; }
+                       # Special platforms:
+                       # EXPORT_VAR_AS_FUNCTION means that global variables
+                       # will be represented as functions.  This currently
+                       # only happens on VMS-VAX.
+                       if ($keyword eq "EXPORT_VAR_AS_FUNCTION" && ($VMSVAX || $W32 || $W16)) {
+                               return 1;
+                       }
+                       if ($keyword eq "ZLIB" && $zlib) { return 1; }
+                       return 0;
+               } else {
+                       # algorithms
+                       if ($keyword eq "RC2" && $no_rc2) { return 0; }
+                       if ($keyword eq "RC4" && $no_rc4) { return 0; }
+                       if ($keyword eq "RC5" && $no_rc5) { return 0; }
+                       if ($keyword eq "IDEA" && $no_idea) { return 0; }
+                       if ($keyword eq "DES" && $no_des) { return 0; }
+                       if ($keyword eq "BF" && $no_bf) { return 0; }
+                       if ($keyword eq "CAST" && $no_cast) { return 0; }
+                       if ($keyword eq "MD2" && $no_md2) { return 0; }
+                       if ($keyword eq "MD4" && $no_md4) { return 0; }
+                       if ($keyword eq "MD5" && $no_md5) { return 0; }
+                       if ($keyword eq "SHA" && $no_sha) { return 0; }
+                       if ($keyword eq "RIPEMD" && $no_ripemd) { return 0; }
+                       if ($keyword eq "MDC2" && $no_mdc2) { return 0; }
+                       if ($keyword eq "WHIRLPOOL" && $no_whirlpool) { return 0; }
+                       if ($keyword eq "RSA" && $no_rsa) { return 0; }
+                       if ($keyword eq "DSA" && $no_dsa) { return 0; }
+                       if ($keyword eq "DH" && $no_dh) { return 0; }
+                       if ($keyword eq "EC" && $no_ec) { return 0; }
+                       if ($keyword eq "ECDSA" && $no_ecdsa) { return 0; }
+                       if ($keyword eq "ECDH" && $no_ecdh) { return 0; }
+                       if ($keyword eq "HMAC" && $no_hmac) { return 0; }
+                       if ($keyword eq "AES" && $no_aes) { return 0; }
+                       if ($keyword eq "CAMELLIA" && $no_camellia) { return 0; }
+                       if ($keyword eq "SEED" && $no_seed) { return 0; }
+                       if ($keyword eq "EVP" && $no_evp) { return 0; }
+                       if ($keyword eq "LHASH" && $no_lhash) { return 0; }
+                       if ($keyword eq "STACK" && $no_stack) { return 0; }
+                       if ($keyword eq "ERR" && $no_err) { return 0; }
+                       if ($keyword eq "BUFFER" && $no_buffer) { return 0; }
+                       if ($keyword eq "BIO" && $no_bio) { return 0; }
+                       if ($keyword eq "COMP" && $no_comp) { return 0; }
+                       if ($keyword eq "DSO" && $no_dso) { return 0; }
+                       if ($keyword eq "KRB5" && $no_krb5) { return 0; }
+                       if ($keyword eq "ENGINE" && $no_engine) { return 0; }
+                       if ($keyword eq "HW" && $no_hw) { return 0; }
+                       if ($keyword eq "FP_API" && $no_fp_api) { return 0; }
+                       if ($keyword eq "STATIC_ENGINE" && $no_static_engine) { return 0; }
+                       if ($keyword eq "GMP" && $no_gmp) { return 0; }
+                       if ($keyword eq "RFC3779" && $no_rfc3779) { return 0; }
+                       if ($keyword eq "TLSEXT" && $no_tlsext) { return 0; }
+                       if ($keyword eq "PSK" && $no_psk) { return 0; }
+                       if ($keyword eq "CMS" && $no_cms) { return 0; }
+                       if ($keyword eq "SSL2" && $no_ssl2) { return 0; }
+                       if ($keyword eq "CAPIENG" && $no_capieng) { return 0; }
+                       if ($keyword eq "JPAKE" && $no_jpake) { return 0; }
+                       if ($keyword eq "DEPRECATED" && $no_deprecated) { return 0; }
+
+                       # Nothing recognise as true
+                       return 1;
+               }
+       }
+
+       foreach $k (@keywords) {
+               if ($k =~ /^!(.*)$/) {
+                       $falsesum += &recognise($1,$platforms);
+               } else {
+                       $truesum *= &recognise($k,$platforms);
+               }
+       }
+       print STDERR "DEBUG: [",$#keywords,",",$#keywords < 0,"] is_valid($keywords_txt) => (\!$falsesum) && $truesum = ",(!$falsesum) && $truesum,"\n" if $debug;
+       return (!$falsesum) && $truesum;
+}
+
+sub print_test_file
+{
+       (*OUT,my $name,*nums,my $testall,my @symbols)=@_;
+       my $n = 1; my @e; my @r;
+       my $sym; my $prev = ""; my $prefSSLeay;
+
+       (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols);
+       (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:.*/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols);
+       @symbols=((sort @e),(sort @r));
+
+       foreach $sym (@symbols) {
+               (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
+               my $v = 0;
+               $v = 1 if $i=~ /^.*?:.*?:VARIABLE/;
+               my $p = ($i =~ /^[^:]*:([^:]*):/,$1);
+               my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1);
+               if (!defined($nums{$s})) {
+                       print STDERR "Warning: $s does not have a number assigned\n"
+                           if(!$do_update);
+               } elsif (is_valid($p,1) && is_valid($a,0)) {
+                       my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1);
+                       if ($prev eq $s2) {
+                               print OUT "\t/* The following has already appeared previously */\n";
+                               print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n";
+                       }
+                       $prev = $s2;    # To warn about duplicates...
+
+                       ($nn,$ni)=($nums{$s2} =~ /^(.*?)\\(.*)$/);
+                       if ($v) {
+                               print OUT "\textern int $s2; /* type unknown */ /* $nn $ni */\n";
+                       } else {
+                               print OUT "\textern int $s2(); /* type unknown */ /* $nn $ni */\n";
+                       }
+               }
+       }
+}
+
+sub get_version {
+   local *MF;
+   my $v = '?';
+   open MF, 'Makefile' or return $v;
+   while (<MF>) {
+     $v = $1, last if /^VERSION=(.*?)\s*$/;
+   }
+   close MF;
+   return $v;
+}
+
+sub print_def_file
+{
+       (*OUT,my $name,*nums,my @symbols)=@_;
+       my $n = 1; my @e; my @r; my @v; my $prev="";
+       my $liboptions="";
+       my $libname = $name;
+       my $http_vendor = 'www.openssl.org/';
+       my $version = get_version();
+       my $what = "OpenSSL: implementation of Secure Socket Layer";
+       my $description = "$what $version, $name - http://$http_vendor";
+
+       if ($W32)
+               { $libname.="32"; }
+       elsif ($W16)
+               { $libname.="16"; }
+       elsif ($OS2)
+               { # DLL names should not clash on the whole system.
+                 # However, they should not have any particular relationship
+                 # to the name of the static library.  Chose descriptive names
+                 # (must be at most 8 chars).
+                 my %translate = (ssl => 'open_ssl', crypto => 'cryptssl');
+                 $libname = $translate{$name} || $name;
+                 $liboptions = <<EOO;
+INITINSTANCE
+DATA MULTIPLE NONSHARED
+EOO
+                 # Vendor field can't contain colon, drat; so we omit http://
+                 $description = "\@#$http_vendor:$version#\@$what; DLL for library $name.  Build for EMX -Zmtd";
+               }
+
+       print OUT <<"EOF";
+;
+; Definition file for the DLL version of the $name library from OpenSSL
+;
+
+LIBRARY         $libname       $liboptions
+
+EOF
+
+       if ($W16) {
+               print <<"EOF";
+CODE            PRELOAD MOVEABLE
+DATA            PRELOAD MOVEABLE SINGLE
+
+EXETYPE                WINDOWS
+
+HEAPSIZE       4096
+STACKSIZE      8192
+
+EOF
+       }
+
+       print "EXPORTS\n";
+
+       (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols);
+       (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:FUNCTION/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols);
+       (@v)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:VARIABLE/,@symbols);
+       @symbols=((sort @e),(sort @r), (sort @v));
+
+
+       foreach $sym (@symbols) {
+               (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
+               my $v = 0;
+               $v = 1 if $i =~ /^.*?:.*?:VARIABLE/;
+               if (!defined($nums{$s})) {
+                       printf STDERR "Warning: $s does not have a number assigned\n"
+                           if(!$do_update);
+               } else {
+                       (my $n, my $dummy) = split /\\/, $nums{$s};
+                       my %pf = ();
+                       my $p = ($i =~ /^[^:]*:([^:]*):/,$1);
+                       my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1);
+                       if (is_valid($p,1) && is_valid($a,0)) {
+                               my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1);
+                               if ($prev eq $s2) {
+                                       print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n";
+                               }
+                               $prev = $s2;    # To warn about duplicates...
+                               if($v && !$OS2) {
+                                       printf OUT "    %s%-39s @%-8d DATA\n",($W32)?"":"_",$s2,$n;
+                               } else {
+                                       printf OUT "    %s%-39s @%d\n",($W32||$OS2)?"":"_",$s2,$n;
+                               }
+                       }
+               }
+       }
+       printf OUT "\n";
+}
+
+sub load_numbers
+{
+       my($name)=@_;
+       my(@a,%ret);
+
+       $max_num = 0;
+       $num_noinfo = 0;
+       $prev = "";
+       $prev_cnt = 0;
+
+       open(IN,"<$name") || die "unable to open $name:$!\n";
+       while (<IN>) {
+               chop;
+               s/#.*$//;
+               next if /^\s*$/;
+               @a=split;
+               if (defined $ret{$a[0]}) {
+                       # This is actually perfectly OK
+                       #print STDERR "Warning: Symbol '",$a[0],"' redefined. old=",$ret{$a[0]},", new=",$a[1],"\n";
+               }
+               if ($max_num > $a[1]) {
+                       print STDERR "Warning: Number decreased from ",$max_num," to ",$a[1],"\n";
+               }
+               elsif ($max_num == $a[1]) {
+                       # This is actually perfectly OK
+                       #print STDERR "Warning: Symbol ",$a[0]," has same number as previous ",$prev,": ",$a[1],"\n";
+                       if ($a[0] eq $prev) {
+                               $prev_cnt++;
+                               $a[0] .= "{$prev_cnt}";
+                       }
+               }
+               else {
+                       $prev_cnt = 0;
+               }
+               if ($#a < 2) {
+                       # Existence will be proven later, in do_defs
+                       $ret{$a[0]}=$a[1];
+                       $num_noinfo++;
+               } else {
+                       $ret{$a[0]}=$a[1]."\\".$a[2]; # \\ is a special marker
+               }
+               $max_num = $a[1] if $a[1] > $max_num;
+               $prev=$a[0];
+       }
+       if ($num_noinfo) {
+               print STDERR "Warning: $num_noinfo symbols were without info.";
+               if ($do_rewrite) {
+                       printf STDERR "  The rewrite will fix this.\n";
+               } else {
+                       printf STDERR "  You should do a rewrite to fix this.\n";
+               }
+       }
+       close(IN);
+       return(%ret);
+}
+
+sub parse_number
+{
+       (my $str, my $what) = @_;
+       (my $n, my $i) = split(/\\/,$str);
+       if ($what eq "n") {
+               return $n;
+       } else {
+               return $i;
+       }
+}
+
+sub rewrite_numbers
+{
+       (*OUT,$name,*nums,@symbols)=@_;
+       my $thing;
+
+       print STDERR "Rewriting $name\n";
+
+       my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
+       my $r; my %r; my %rsyms;
+       foreach $r (@r) {
+               (my $s, my $i) = split /\\/, $r;
+               my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/;
+               $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/;
+               $r{$a} = $s."\\".$i;
+               $rsyms{$s} = 1;
+       }
+
+       my %syms = ();
+       foreach $_ (@symbols) {
+               (my $n, my $i) = split /\\/;
+               $syms{$n} = 1;
+       }
+
+       my @s=sort {
+           &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n")
+           || $a cmp $b
+       } keys %nums;
+       foreach $sym (@s) {
+               (my $n, my $i) = split /\\/, $nums{$sym};
+               next if defined($i) && $i =~ /^.*?:.*?:\w+\(\w+\)/;
+               next if defined($rsyms{$sym});
+               print STDERR "DEBUG: rewrite_numbers for sym = ",$sym,": i = ",$i,", n = ",$n,", rsym{sym} = ",$rsyms{$sym},"syms{sym} = ",$syms{$sym},"\n" if $debug;
+               $i="NOEXIST::FUNCTION:"
+                       if !defined($i) || $i eq "" || !defined($syms{$sym});
+               my $s2 = $sym;
+               $s2 =~ s/\{[0-9]+\}$//;
+               printf OUT "%s%-39s %d\t%s\n","",$s2,$n,$i;
+               if (exists $r{$sym}) {
+                       (my $s, $i) = split /\\/,$r{$sym};
+                       my $s2 = $s;
+                       $s2 =~ s/\{[0-9]+\}$//;
+                       printf OUT "%s%-39s %d\t%s\n","",$s2,$n,$i;
+               }
+       }
+}
+
+sub update_numbers
+{
+       (*OUT,$name,*nums,my $start_num, my @symbols)=@_;
+       my $new_syms = 0;
+
+       print STDERR "Updating $name numbers\n";
+
+       my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
+       my $r; my %r; my %rsyms;
+       foreach $r (@r) {
+               (my $s, my $i) = split /\\/, $r;
+               my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/;
+               $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/;
+               $r{$a} = $s."\\".$i;
+               $rsyms{$s} = 1;
+       }
+
+       foreach $sym (@symbols) {
+               (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
+               next if $i =~ /^.*?:.*?:\w+\(\w+\)/;
+               next if defined($rsyms{$sym});
+               die "ERROR: Symbol $sym had no info attached to it."
+                   if $i eq "";
+               if (!exists $nums{$s}) {
+                       $new_syms++;
+                       my $s2 = $s;
+                       $s2 =~ s/\{[0-9]+\}$//;
+                       printf OUT "%s%-39s %d\t%s\n","",$s2, ++$start_num,$i;
+                       if (exists $r{$s}) {
+                               ($s, $i) = split /\\/,$r{$s};
+                               $s =~ s/\{[0-9]+\}$//;
+                               printf OUT "%s%-39s %d\t%s\n","",$s, $start_num,$i;
+                       }
+               }
+       }
+       if($new_syms) {
+               print STDERR "$new_syms New symbols added\n";
+       } else {
+               print STDERR "No New symbols Added\n";
+       }
+}
+
+sub check_existing
+{
+       (*nums, my @symbols)=@_;
+       my %existing; my @remaining;
+       @remaining=();
+       foreach $sym (@symbols) {
+               (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
+               $existing{$s}=1;
+       }
+       foreach $sym (keys %nums) {
+               if (!exists $existing{$sym}) {
+                       push @remaining, $sym;
+               }
+       }
+       if(@remaining) {
+               print STDERR "The following symbols do not seem to exist:\n";
+               foreach $sym (@remaining) {
+                       print STDERR "\t",$sym,"\n";
+               }
+       }
+}
+
diff --git a/deps/openssl/openssl/util/mkdir-p.pl b/deps/openssl/openssl/util/mkdir-p.pl
new file mode 100755 (executable)
index 0000000..e73d02b
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/local/bin/perl
+
+# mkdir-p.pl
+
+# On some systems, the -p option to mkdir (= also create any missing parent
+# directories) is not available.
+
+my $arg;
+
+foreach $arg (@ARGV) {
+  $arg =~ tr|\\|/|;
+  &do_mkdir_p($arg);
+}
+
+
+sub do_mkdir_p {
+  local($dir) = @_;
+
+  $dir =~ s|/*\Z(?!\n)||s;
+
+  if (-d $dir) {
+    return;
+  }
+
+  if ($dir =~ m|[^/]/|s) {
+    local($parent) = $dir;
+    $parent =~ s|[^/]*\Z(?!\n)||s;
+
+    do_mkdir_p($parent);
+  }
+
+  mkdir($dir, 0777) || die "Cannot create directory $dir: $!\n";
+  print "created directory `$dir'\n";
+}
diff --git a/deps/openssl/openssl/util/mkerr.pl b/deps/openssl/openssl/util/mkerr.pl
new file mode 100644 (file)
index 0000000..aec401c
--- /dev/null
@@ -0,0 +1,810 @@
+#!/usr/local/bin/perl -w
+
+my $config = "crypto/err/openssl.ec";
+my $hprefix = "openssl/";
+my $debug = 0;
+my $rebuild = 0;
+my $static = 1;
+my $recurse = 0;
+my $reindex = 0;
+my $dowrite = 0;
+my $staticloader = "";
+
+my $pack_errcode;
+my $load_errcode;
+
+my $errcount;
+
+while (@ARGV) {
+       my $arg = $ARGV[0];
+       if($arg eq "-conf") {
+               shift @ARGV;
+               $config = shift @ARGV;
+       } elsif($arg eq "-hprefix") {
+               shift @ARGV;
+               $hprefix = shift @ARGV;
+       } elsif($arg eq "-debug") {
+               $debug = 1;
+               shift @ARGV;
+       } elsif($arg eq "-rebuild") {
+               $rebuild = 1;
+               shift @ARGV;
+       } elsif($arg eq "-recurse") {
+               $recurse = 1;
+               shift @ARGV;
+       } elsif($arg eq "-reindex") {
+               $reindex = 1;
+               shift @ARGV;
+       } elsif($arg eq "-nostatic") {
+               $static = 0;
+               shift @ARGV;
+       } elsif($arg eq "-staticloader") {
+               $staticloader = "static ";
+               shift @ARGV;
+       } elsif($arg eq "-write") {
+               $dowrite = 1;
+               shift @ARGV;
+       } elsif($arg eq "-help" || $arg eq "-h" || $arg eq "-?" || $arg eq "--help") {
+               print STDERR <<"EOF";
+mkerr.pl [options] ...
+
+Options:
+
+  -conf F       Use the config file F instead of the default one:
+                  crypto/err/openssl.ec
+
+  -hprefix P    Prepend the filenames in generated #include <header>
+                statements with prefix P. Default: 'openssl/' (without
+                the quotes, naturally)
+
+  -debug        Turn on debugging verbose output on stderr.
+
+  -rebuild      Rebuild all header and C source files, irrespective of the
+                fact if any error or function codes have been added/removed.
+                Default: only update files for libraries which saw change
+                         (of course, this requires '-write' as well, or no
+                          files will be touched!)
+
+  -recurse      scan a preconfigured set of directories / files for error and
+                function codes:
+                  (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>, <apps/*.c>)
+                When this option is NOT specified, the filelist is taken from
+                the commandline instead. Here, wildcards may be embedded. (Be
+                sure to escape those to prevent the shell from expanding them
+                for you when you wish mkerr.pl to do so instead.)
+                Default: take file list to scan from the command line.
+
+  -reindex      Discard the numeric values previously assigned to the error
+                and function codes as extracted from the scanned header files;
+                instead renumber all of them starting from 100. (Note that
+                the numbers assigned through 'R' records in the config file
+                remain intact.)
+                Default: keep previously assigned numbers. (You are warned
+                         when collisions are detected.)
+
+  -nostatic     Generates a different source code, where these additional 
+                functions are generated for each library specified in the
+                config file:
+                  void ERR_load_<LIB>_strings(void);
+                  void ERR_unload_<LIB>_strings(void);
+                  void ERR_<LIB>_error(int f, int r, char *fn, int ln);
+                  #define <LIB>err(f,r) ERR_<LIB>_error(f,r,__FILE__,__LINE__)
+                while the code facilitates the use of these in an environment
+                where the error support routines are dynamically loaded at 
+                runtime.
+                Default: 'static' code generation.
+
+  -staticloader Prefix generated functions with the 'static' scope modifier.
+                Default: don't write any scope modifier prefix.
+
+  -write        Actually (over)write the generated code to the header and C 
+                source files as assigned to each library through the config 
+                file.
+                Default: don't write.
+
+  -help / -h / -? / --help            Show this help text.
+
+  ...           Additional arguments are added to the file list to scan,
+                assuming '-recurse' was NOT specified on the command line.
+
+EOF
+               exit 1;
+       } else {
+               last;
+       }
+}
+
+if($recurse) {
+       @source = (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>);
+} else {
+       @source = @ARGV;
+}
+
+# Read in the config file
+
+open(IN, "<$config") || die "Can't open config file $config";
+
+# Parse config file
+
+while(<IN>)
+{
+       if(/^L\s+(\S+)\s+(\S+)\s+(\S+)/) {
+               $hinc{$1} = $2;
+               $libinc{$2} = $1;
+               $cskip{$3} = $1;
+               if($3 ne "NONE") {
+                       $csrc{$1} = $3;
+                       $fmax{$1} = 100;
+                       $rmax{$1} = 100;
+                       $fassigned{$1} = ":";
+                       $rassigned{$1} = ":";
+                       $fnew{$1} = 0;
+                       $rnew{$1} = 0;
+               }
+       } elsif (/^F\s+(\S+)/) {
+       # Add extra function with $1
+       } elsif (/^R\s+(\S+)\s+(\S+)/) {
+               $rextra{$1} = $2;
+               $rcodes{$1} = $2;
+       }
+}
+
+close IN;
+
+# Scan each header file in turn and make a list of error codes
+# and function names
+
+while (($hdr, $lib) = each %libinc)
+{
+       next if($hdr eq "NONE");
+       print STDERR "Scanning header file $hdr\n" if $debug; 
+       my $line = "", $def= "", $linenr = 0, $gotfile = 0;
+       if (open(IN, "<$hdr")) {
+           $gotfile = 1;
+           while(<IN>) {
+               $linenr++;
+               print STDERR "line: $linenr\r" if $debug;
+
+               last if(/BEGIN\s+ERROR\s+CODES/);
+               if ($line ne '') {
+                   $_ = $line . $_;
+                   $line = '';
+               }
+
+               if (/\\$/) {
+                   $line = $_;
+                   next;
+               }
+
+               if(/\/\*/) {
+                   if (not /\*\//) {           # multiline comment...
+                       $line = $_;             # ... just accumulate
+                       next; 
+                   } else {
+                       s/\/\*.*?\*\///gs;      # wipe it
+                   }
+               }
+
+               if ($cpp) {
+                   $cpp++ if /^#\s*if/;
+                   $cpp-- if /^#\s*endif/;
+                   next;
+               }
+               $cpp = 1 if /^#.*ifdef.*cplusplus/;  # skip "C" declaration
+
+               next if (/^\#/);                      # skip preprocessor directives
+
+               s/{[^{}]*}//gs;                      # ignore {} blocks
+
+               if (/\{|\/\*/) { # Add a } so editor works...
+                   $line = $_;
+               } else {
+                   $def .= $_;
+               }
+           }
+       }
+
+       print STDERR "                                  \r" if $debug;
+        $defnr = 0;
+       # Delete any DECLARE_ macros
+       $def =~ s/DECLARE_\w+\([\w,\s]+\)//gs;
+       foreach (split /;/, $def) {
+           $defnr++;
+           print STDERR "def: $defnr\r" if $debug;
+
+           # The goal is to collect function names from function declarations.
+
+           s/^[\n\s]*//g;
+           s/[\n\s]*$//g;
+
+           # Skip over recognized non-function declarations
+           next if(/typedef\W/ or /DECLARE_STACK_OF/ or /TYPEDEF_.*_OF/);
+
+           # Remove STACK_OF(foo)
+           s/STACK_OF\(\w+\)/void/;
+
+           # Reduce argument lists to empty ()
+           # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {}
+           while(/\(.*\)/s) {
+               s/\([^\(\)]+\)/\{\}/gs;
+               s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs;    #(*f{}) -> f
+           }
+           # pretend as we didn't use curly braces: {} -> ()
+           s/\{\}/\(\)/gs;
+
+           if (/(\w+)\s*\(\).*/s) {    # first token prior [first] () is
+               my $name = $1;          # a function name!
+               $name =~ tr/[a-z]/[A-Z]/;
+               $ftrans{$name} = $1;
+           } elsif (/[\(\)]/ and not (/=/)) {
+               print STDERR "Header $hdr: cannot parse: $_;\n";
+           }
+       }
+
+       print STDERR "                                  \r" if $debug;
+
+       next if $reindex;
+
+       # Scan function and reason codes and store them: keep a note of the
+       # maximum code used.
+
+       if ($gotfile) {
+         while(<IN>) {
+               if(/^\#define\s+(\S+)\s+(\S+)/) {
+                       $name = $1;
+                       $code = $2;
+                       next if $name =~ /^${lib}err/;
+                       unless($name =~ /^${lib}_([RF])_(\w+)$/) {
+                               print STDERR "Invalid error code $name\n";
+                               next;
+                       }
+                       if($1 eq "R") {
+                               $rcodes{$name} = $code;
+                               if ($rassigned{$lib} =~ /:$code:/) {
+                                       print STDERR "!! ERROR: $lib reason code $code assigned twice (collision at $name)\n";
+                                       ++$errcount;
+                               }
+                               $rassigned{$lib} .= "$code:";
+                               if(!(exists $rextra{$name}) &&
+                                        ($code > $rmax{$lib}) ) {
+                                       $rmax{$lib} = $code;
+                               }
+                       } else {
+                               if ($fassigned{$lib} =~ /:$code:/) {
+                                       print STDERR "!! ERROR: $lib function code $code assigned twice (collision at $name)\n";
+                                       ++$errcount;
+                               }
+                               $fassigned{$lib} .= "$code:";
+                               if($code > $fmax{$lib}) {
+                                       $fmax{$lib} = $code;
+                               }
+                               $fcodes{$name} = $code;
+                       }
+               }
+         }
+       }
+
+       if ($debug) {
+               if (defined($fmax{$lib})) {
+                       print STDERR "Max function code fmax" . "{" . "$lib" . "} = $fmax{$lib}\n";
+                       $fassigned{$lib} =~ m/^:(.*):$/;
+                       @fassigned = sort {$a <=> $b} split(":", $1);
+                       print STDERR "  @fassigned\n";
+               }
+               if (defined($rmax{$lib})) {
+                       print STDERR "Max reason code rmax" . "{" . "$lib" . "} = $rmax{$lib}\n";
+                       $rassigned{$lib} =~ m/^:(.*):$/;
+                       @rassigned = sort {$a <=> $b} split(":", $1);
+                       print STDERR "  @rassigned\n";
+               }
+       }
+
+       if ($lib eq "SSL") {
+               if ($rmax{$lib} >= 1000) {
+                       print STDERR "!! ERROR: SSL error codes 1000+ are reserved for alerts.\n";
+                       print STDERR "!!        Any new alerts must be added to $config.\n";
+                       ++$errcount;
+                       print STDERR "\n";
+               }
+       }
+       close IN;
+}
+
+# Scan each C source file and look for function and reason codes
+# This is done by looking for strings that "look like" function or
+# reason codes: basically anything consisting of all upper case and
+# numerics which has _F_ or _R_ in it and which has the name of an
+# error library at the start. This seems to work fine except for the
+# oddly named structure BIO_F_CTX which needs to be ignored.
+# If a code doesn't exist in list compiled from headers then mark it
+# with the value "X" as a place holder to give it a value later.
+# Store all function and reason codes found in %ufcodes and %urcodes
+# so all those unreferenced can be printed out.
+
+
+foreach $file (@source) {
+       # Don't parse the error source file.
+       next if exists $cskip{$file};
+       print STDERR "File loaded: ".$file."\r" if $debug;
+       open(IN, "<$file") || die "Can't open source file $file\n";
+       while(<IN>) {
+               # skip obsoleted source files entirely!
+               last if(/^#error\s+obsolete/);
+
+               if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
+                       next unless exists $csrc{$2};
+                       next if($1 eq "BIO_F_BUFFER_CTX");
+                       $ufcodes{$1} = 1;
+                       if(!exists $fcodes{$1}) {
+                               $fcodes{$1} = "X";
+                               $fnew{$2}++;
+                       }
+                       $notrans{$1} = 1 unless exists $ftrans{$3};
+                       print STDERR "Function: $1\t= $fcodes{$1} (lib: $2, name: $3)\n" if $debug; 
+               }
+               if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
+                       next unless exists $csrc{$2};
+                       $urcodes{$1} = 1;
+                       if(!exists $rcodes{$1}) {
+                               $rcodes{$1} = "X";
+                               $rnew{$2}++;
+                       }
+                       print STDERR "Reason: $1\t= $rcodes{$1} (lib: $2)\n" if $debug; 
+               } 
+       }
+       close IN;
+}
+print STDERR "                                  \n" if $debug;
+
+# Now process each library in turn.
+
+foreach $lib (keys %csrc)
+{
+       my $hfile = $hinc{$lib};
+       my $cfile = $csrc{$lib};
+       if(!$fnew{$lib} && !$rnew{$lib}) {
+               print STDERR "$lib:\t\tNo new error codes\n";
+               next unless $rebuild;
+       } else {
+               print STDERR "$lib:\t\t$fnew{$lib} New Functions,";
+               print STDERR " $rnew{$lib} New Reasons.\n";
+               next unless $dowrite;
+       }
+
+       # If we get here then we have some new error codes so we
+       # need to rebuild the header file and C file.
+
+       # Make a sorted list of error and reason codes for later use.
+
+       my @function = sort grep(/^${lib}_/,keys %fcodes);
+       my @reasons = sort grep(/^${lib}_/,keys %rcodes);
+
+       # Rewrite the header file
+
+       if (open(IN, "<$hfile")) {
+           # Copy across the old file
+           while(<IN>) {
+               push @out, $_;
+               last if (/BEGIN ERROR CODES/);
+           }
+           close IN;
+       } else {
+           push @out,
+"/* ====================================================================\n",
+" * Copyright (c) 2001-2011 The OpenSSL Project.  All rights reserved.\n",
+" *\n",
+" * Redistribution and use in source and binary forms, with or without\n",
+" * modification, are permitted provided that the following conditions\n",
+" * are met:\n",
+" *\n",
+" * 1. Redistributions of source code must retain the above copyright\n",
+" *    notice, this list of conditions and the following disclaimer. \n",
+" *\n",
+" * 2. Redistributions in binary form must reproduce the above copyright\n",
+" *    notice, this list of conditions and the following disclaimer in\n",
+" *    the documentation and/or other materials provided with the\n",
+" *    distribution.\n",
+" *\n",
+" * 3. All advertising materials mentioning features or use of this\n",
+" *    software must display the following acknowledgment:\n",
+" *    \"This product includes software developed by the OpenSSL Project\n",
+" *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)\"\n",
+" *\n",
+" * 4. The names \"OpenSSL Toolkit\" and \"OpenSSL Project\" must not be used to\n",
+" *    endorse or promote products derived from this software without\n",
+" *    prior written permission. For written permission, please contact\n",
+" *    openssl-core\@openssl.org.\n",
+" *\n",
+" * 5. Products derived from this software may not be called \"OpenSSL\"\n",
+" *    nor may \"OpenSSL\" appear in their names without prior written\n",
+" *    permission of the OpenSSL Project.\n",
+" *\n",
+" * 6. Redistributions of any form whatsoever must retain the following\n",
+" *    acknowledgment:\n",
+" *    \"This product includes software developed by the OpenSSL Project\n",
+" *    for use in the OpenSSL Toolkit (http://www.openssl.org/)\"\n",
+" *\n",
+" * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\n",
+" * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n",
+" * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n",
+" * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\n",
+" * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n",
+" * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n",
+" * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n",
+" * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n",
+" * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n",
+" * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n",
+" * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n",
+" * OF THE POSSIBILITY OF SUCH DAMAGE.\n",
+" * ====================================================================\n",
+" *\n",
+" * This product includes cryptographic software written by Eric Young\n",
+" * (eay\@cryptsoft.com).  This product includes software written by Tim\n",
+" * Hudson (tjh\@cryptsoft.com).\n",
+" *\n",
+" */\n",
+"\n",
+"#ifndef HEADER_${lib}_ERR_H\n",
+"#define HEADER_${lib}_ERR_H\n",
+"\n",
+"#ifdef  __cplusplus\n",
+"extern \"C\" {\n",
+"#endif\n",
+"\n",
+"/* BEGIN ERROR CODES */\n";
+       }
+       open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n";
+
+       print OUT @out;
+       undef @out;
+       print OUT <<"EOF";
+/* The following lines are auto generated by the script mkerr.pl. Any changes
+ * made after this point may be overwritten when the script is next run.
+ */
+EOF
+       if($static) {
+               print OUT <<"EOF";
+${staticloader}void ERR_load_${lib}_strings(void);
+
+EOF
+       } else {
+               print OUT <<"EOF";
+${staticloader}void ERR_load_${lib}_strings(void);
+${staticloader}void ERR_unload_${lib}_strings(void);
+${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line);
+#define ${lib}err(f,r) ERR_${lib}_error((f),(r),__FILE__,__LINE__)
+
+EOF
+       }
+       print OUT <<"EOF";
+/* Error codes for the $lib functions. */
+
+/* Function codes. */
+EOF
+
+       foreach $i (@function) {
+               $z=6-int(length($i)/8);
+               if($fcodes{$i} eq "X") {
+                       $fassigned{$lib} =~ m/^:([^:]*):/;
+                       $findcode = $1;
+                       if (!defined($findcode)) {
+                               $findcode = $fmax{$lib};
+                       }
+                       while ($fassigned{$lib} =~ m/:$findcode:/) {
+                               $findcode++;
+                       }
+                       $fcodes{$i} = $findcode;
+                       $fassigned{$lib} .= "$findcode:";
+                       print STDERR "New Function code $i\n" if $debug;
+               }
+               printf OUT "#define $i%s $fcodes{$i}\n","\t" x $z;
+       }
+
+       print OUT "\n/* Reason codes. */\n";
+
+       foreach $i (@reasons) {
+               $z=6-int(length($i)/8);
+               if($rcodes{$i} eq "X") {
+                       $rassigned{$lib} =~ m/^:([^:]*):/;
+                       $findcode = $1;
+                       if (!defined($findcode)) {
+                               $findcode = $rmax{$lib};
+                       }
+                       while ($rassigned{$lib} =~ m/:$findcode:/) {
+                               $findcode++;
+                       }
+                       $rcodes{$i} = $findcode;
+                       $rassigned{$lib} .= "$findcode:";
+                       print STDERR "New Reason code   $i\n" if $debug;
+               }
+               printf OUT "#define $i%s $rcodes{$i}\n","\t" x $z;
+       }
+       print OUT <<"EOF";
+
+#ifdef  __cplusplus
+}
+#endif
+#endif
+EOF
+       close OUT;
+
+       # Rewrite the C source file containing the error details.
+
+       # First, read any existing reason string definitions:
+       my %err_reason_strings;
+       if (open(IN,"<$cfile")) {
+               while (<IN>) {
+                       if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) {
+                               $err_reason_strings{$1} = $2;
+                       }
+                       if (/\b${lib}_F_(\w*)\b.*\"(.*)\"/) {
+                               if (!exists $ftrans{$1} && ($1 ne $2)) {
+                                       print STDERR "WARNING: Mismatched function string $2\n";
+                                       $ftrans{$1} = $2;
+                               }
+                       }
+               }
+               close(IN);
+       }
+
+
+       my $hincf;
+       if($static) {
+               $hfile =~ /([^\/]+)$/;
+               $hincf = "<${hprefix}$1>";
+       } else {
+               $hincf = "\"$hfile\"";
+       }
+
+       # If static we know the error code at compile time so use it
+       # in error definitions.
+
+       if ($static)
+               {
+               $pack_errcode = "ERR_LIB_${lib}";
+               $load_errcode = "0";
+               }
+       else
+               {
+               $pack_errcode = "0";
+               $load_errcode = "ERR_LIB_${lib}";
+               }
+
+
+       open (OUT,">$cfile") || die "Can't open $cfile for writing";
+
+       print OUT <<"EOF";
+/* $cfile */
+/* ====================================================================
+ * Copyright (c) 1999-2011 The OpenSSL 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 OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    openssl-core\@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL 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 OpenSSL 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay\@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh\@cryptsoft.com).
+ *
+ */
+
+/* NOTE: this file was auto generated by the mkerr.pl script: any changes
+ * made to it will be overwritten when the script next updates this file,
+ * only reason strings will be preserved.
+ */
+
+#include <stdio.h>
+#include <openssl/err.h>
+#include $hincf
+
+/* BEGIN ERROR CODES */
+#ifndef OPENSSL_NO_ERR
+
+#define ERR_FUNC(func) ERR_PACK($pack_errcode,func,0)
+#define ERR_REASON(reason) ERR_PACK($pack_errcode,0,reason)
+
+static ERR_STRING_DATA ${lib}_str_functs[]=
+       {
+EOF
+       # Add each function code: if a function name is found then use it.
+       foreach $i (@function) {
+               my $fn;
+               $i =~ /^${lib}_F_(\S+)$/;
+               $fn = $1;
+               if(exists $ftrans{$fn}) {
+                       $fn = $ftrans{$fn};
+               }
+#              print OUT "{ERR_PACK($pack_errcode,$i,0),\t\"$fn\"},\n";
+               print OUT "{ERR_FUNC($i),\t\"$fn\"},\n";
+       }
+       print OUT <<"EOF";
+{0,NULL}
+       };
+
+static ERR_STRING_DATA ${lib}_str_reasons[]=
+       {
+EOF
+       # Add each reason code.
+       foreach $i (@reasons) {
+               my $rn;
+               my $rstr = "ERR_REASON($i)";
+               my $nspc = 0;
+               if (exists $err_reason_strings{$i}) {
+                       $rn = $err_reason_strings{$i};
+               } else {
+                       $i =~ /^${lib}_R_(\S+)$/;
+                       $rn = $1;
+                       $rn =~ tr/_[A-Z]/ [a-z]/;
+               }
+               $nspc = 40 - length($rstr) unless length($rstr) > 40;
+               $nspc = " " x $nspc;
+               print OUT "{${rstr}${nspc},\"$rn\"},\n";
+       }
+if($static) {
+       print OUT <<"EOF";
+{0,NULL}
+       };
+
+#endif
+
+${staticloader}void ERR_load_${lib}_strings(void)
+       {
+#ifndef OPENSSL_NO_ERR
+
+       if (ERR_func_error_string(${lib}_str_functs[0].error) == NULL)
+               {
+               ERR_load_strings($load_errcode,${lib}_str_functs);
+               ERR_load_strings($load_errcode,${lib}_str_reasons);
+               }
+#endif
+       }
+EOF
+} else {
+       print OUT <<"EOF";
+{0,NULL}
+       };
+
+#endif
+
+#ifdef ${lib}_LIB_NAME
+static ERR_STRING_DATA ${lib}_lib_name[]=
+        {
+{0     ,${lib}_LIB_NAME},
+{0,NULL}
+       };
+#endif
+
+
+static int ${lib}_lib_error_code=0;
+static int ${lib}_error_init=1;
+
+${staticloader}void ERR_load_${lib}_strings(void)
+       {
+       if (${lib}_lib_error_code == 0)
+               ${lib}_lib_error_code=ERR_get_next_error_library();
+
+       if (${lib}_error_init)
+               {
+               ${lib}_error_init=0;
+#ifndef OPENSSL_NO_ERR
+               ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs);
+               ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons);
+#endif
+
+#ifdef ${lib}_LIB_NAME
+               ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0);
+               ERR_load_strings(0,${lib}_lib_name);
+#endif
+               }
+       }
+
+${staticloader}void ERR_unload_${lib}_strings(void)
+       {
+       if (${lib}_error_init == 0)
+               {
+#ifndef OPENSSL_NO_ERR
+               ERR_unload_strings(${lib}_lib_error_code,${lib}_str_functs);
+               ERR_unload_strings(${lib}_lib_error_code,${lib}_str_reasons);
+#endif
+
+#ifdef ${lib}_LIB_NAME
+               ERR_unload_strings(0,${lib}_lib_name);
+#endif
+               ${lib}_error_init=1;
+               }
+       }
+
+${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line)
+       {
+       if (${lib}_lib_error_code == 0)
+               ${lib}_lib_error_code=ERR_get_next_error_library();
+       ERR_PUT_error(${lib}_lib_error_code,function,reason,file,line);
+       }
+EOF
+
+}
+
+       close OUT;
+       undef %err_reason_strings;
+}
+
+if($debug && %notrans) {
+       print STDERR "The following function codes were not translated:\n";
+       foreach(sort keys %notrans)
+       {
+               print STDERR "$_\n";
+       }
+}
+
+# Make a list of unreferenced function and reason codes
+
+foreach (keys %fcodes) {
+       push (@funref, $_) unless exists $ufcodes{$_};
+}
+
+foreach (keys %rcodes) {
+       push (@runref, $_) unless exists $urcodes{$_};
+}
+
+if($debug && defined(@funref) ) {
+       print STDERR "The following function codes were not referenced:\n";
+       foreach(sort @funref)
+       {
+               print STDERR "$_\n";
+       }
+}
+
+if($debug && defined(@runref) ) {
+       print STDERR "The following reason codes were not referenced:\n";
+       foreach(sort @runref)
+       {
+               print STDERR "$_\n";
+       }
+}
+
+if($errcount) {
+       print STDERR "There were errors, failing...\n\n";
+       exit $errcount;
+}
+
diff --git a/deps/openssl/openssl/util/mkfiles.pl b/deps/openssl/openssl/util/mkfiles.pl
new file mode 100755 (executable)
index 0000000..6d15831
--- /dev/null
@@ -0,0 +1,141 @@
+#!/usr/local/bin/perl
+#
+# This is a hacked version of files.pl for systems that can't do a 'make files'.
+# Do a perl util/mkminfo.pl >MINFO to build MINFO
+# Written by Steve Henson 1999.
+
+# List of directories to process
+
+my @dirs = (
+".",
+"crypto",
+"crypto/md2",
+"crypto/md4",
+"crypto/md5",
+"crypto/sha",
+"crypto/mdc2",
+"crypto/hmac",
+"crypto/ripemd",
+"crypto/des",
+"crypto/rc2",
+"crypto/rc4",
+"crypto/rc5",
+"crypto/idea",
+"crypto/bf",
+"crypto/cast",
+"crypto/aes",
+"crypto/camellia",
+"crypto/seed",
+"crypto/modes",
+"crypto/bn",
+"crypto/rsa",
+"crypto/dsa",
+"crypto/dso",
+"crypto/dh",
+"crypto/ec",
+"crypto/ecdh",
+"crypto/ecdsa",
+"crypto/buffer",
+"crypto/bio",
+"crypto/stack",
+"crypto/lhash",
+"crypto/rand",
+"crypto/err",
+"crypto/objects",
+"crypto/evp",
+"crypto/asn1",
+"crypto/pem",
+"crypto/x509",
+"crypto/x509v3",
+"crypto/cms",
+"crypto/conf",
+"crypto/jpake",
+"crypto/txt_db",
+"crypto/pkcs7",
+"crypto/pkcs12",
+"crypto/comp",
+"crypto/engine",
+"crypto/ocsp",
+"crypto/ui",
+"crypto/krb5",
+#"crypto/store",
+"crypto/pqueue",
+"crypto/whrlpool",
+"crypto/ts",
+"ssl",
+"apps",
+"engines",
+"engines/ccgost",
+"test",
+"tools"
+);
+
+%top;
+
+foreach (@dirs) {
+       &files_dir ($_, "Makefile");
+}
+
+exit(0);
+
+sub files_dir
+{
+my ($dir, $makefile) = @_;
+
+my %sym;
+
+open (IN, "$dir/$makefile") || die "Can't open $dir/$makefile";
+
+my $s="";
+
+while (<IN>)
+       {
+       chop;
+       s/#.*//;
+       if (/^(\S+)\s*=\s*(.*)$/)
+               {
+               $o="";
+               ($s,$b)=($1,$2);
+               for (;;)
+                       {
+                       if ($b =~ /\\$/)
+                               {
+                               chop($b);
+                               $o.=$b." ";
+                               $b=<IN>;
+                               chop($b);
+                               }
+                       else
+                               {
+                               $o.=$b." ";
+                               last;
+                               }
+                       }
+               $o =~ s/^\s+//;
+               $o =~ s/\s+$//;
+               $o =~ s/\s+/ /g;
+
+               $o =~ s/\$[({]([^)}]+)[)}]/$top{$1} or $sym{$1}/ge;
+               $sym{$s}=($top{$s} or $o);
+               }
+       }
+
+print "RELATIVE_DIRECTORY=$dir\n";
+
+foreach (sort keys %sym)
+       {
+       print "$_=$sym{$_}\n";
+       }
+if ($dir eq "." && defined($sym{"BUILDENV"}))
+       {
+       foreach (split(' ',$sym{"BUILDENV"}))
+               {
+               /^(.+)=/;
+               $top{$1}=$sym{$1};
+               }
+       }
+
+print "RELATIVE_DIRECTORY=\n";
+
+close (IN);
+}
diff --git a/deps/openssl/openssl/util/mklink.pl b/deps/openssl/openssl/util/mklink.pl
new file mode 100755 (executable)
index 0000000..61db12c
--- /dev/null
@@ -0,0 +1,73 @@
+#!/usr/local/bin/perl
+
+# mklink.pl
+
+# The first command line argument is a non-empty relative path
+# specifying the "from" directory.
+# Each other argument is a file name not containing / and
+# names a file in the current directory.
+#
+# For each of these files, we create in the "from" directory a link
+# of the same name pointing to the local file.
+#
+# We assume that the directory structure is a tree, i.e. that it does
+# not contain symbolic links and that the parent of / is never referenced.
+# Apart from this, this script should be able to handle even the most
+# pathological cases.
+
+use Cwd;
+
+my $from = shift;
+my @files = @ARGV;
+
+my @from_path = split(/[\\\/]/, $from);
+my $pwd = getcwd();
+chomp($pwd);
+my @pwd_path = split(/[\\\/]/, $pwd);
+
+my @to_path = ();
+
+my $dirname;
+foreach $dirname (@from_path) {
+
+    # In this loop, @to_path always is a relative path from
+    # @pwd_path (interpreted is an absolute path) to the original pwd.
+
+    # At the end, @from_path (as a relative path from the original pwd)
+    # designates the same directory as the absolute path @pwd_path,
+    # which means that @to_path then is a path from there to the original pwd.
+
+    next if ($dirname eq "" || $dirname eq ".");
+
+    if ($dirname eq "..") {
+       @to_path = (pop(@pwd_path), @to_path);
+    } else {
+       @to_path = ("..", @to_path);
+       push(@pwd_path, $dirname);
+    }
+}
+
+my $to = join('/', @to_path);
+
+my $file;
+$symlink_exists=eval {symlink("",""); 1};
+if ($^O eq "msys") { $symlink_exists=0 };
+foreach $file (@files) {
+    my $err = "";
+    if ($symlink_exists) {
+       unlink "$from/$file";
+       symlink("$to/$file", "$from/$file") or $err = " [$!]";
+    } else {
+       unlink "$from/$file"; 
+       open (OLD, "<$file") or die "Can't open $file: $!";
+       open (NEW, ">$from/$file") or die "Can't open $from/$file: $!";
+       binmode(OLD);
+       binmode(NEW);
+       while (<OLD>) {
+           print NEW $_;
+       }
+       close (OLD) or die "Can't close $file: $!";
+       close (NEW) or die "Can't close $from/$file: $!";
+    }
+    print $file . " => $from/$file$err\n";
+}
diff --git a/deps/openssl/openssl/util/mkrc.pl b/deps/openssl/openssl/util/mkrc.pl
new file mode 100644 (file)
index 0000000..0ceadcf
--- /dev/null
@@ -0,0 +1,71 @@
+#!/bin/env perl
+#
+open FD,"crypto/opensslv.h";
+while(<FD>) {
+    if (/OPENSSL_VERSION_NUMBER\s+(0x[0-9a-f]+)/i) {
+       $ver = hex($1);
+       $v1 = ($ver>>28);
+       $v2 = ($ver>>20)&0xff;
+       $v3 = ($ver>>12)&0xff;
+       $v4 = ($ver>> 4)&0xff;
+       $beta = $ver&0xf;
+       $version = "$v1.$v2.$v3";
+       if ($beta==0xf) { $version .= chr(ord('a')+$v4-1) if ($v4);     }
+       elsif ($beta==0){ $version .= "-dev";                           }
+       else            { $version .= "-beta$beta";                     }
+       last;
+    }
+}
+close(FD);
+
+$filename = $ARGV[0]; $filename =~ /(.*)\.([^.]+)$/;
+$basename = $1;
+$extname  = $2;
+
+if ($extname =~ /dll/i)        { $description = "OpenSSL shared library"; }
+else                   { $description = "OpenSSL application";    }
+
+print <<___;
+#include <winver.h>
+
+LANGUAGE 0x09,0x01
+
+1 VERSIONINFO
+  FILEVERSION $v1,$v2,$v3,$v4
+  PRODUCTVERSION $v1,$v2,$v3,$v4
+  FILEFLAGSMASK 0x3fL
+#ifdef _DEBUG
+  FILEFLAGS 0x01L
+#else
+  FILEFLAGS 0x00L
+#endif
+  FILEOS VOS__WINDOWS32
+  FILETYPE VFT_DLL
+  FILESUBTYPE 0x0L
+BEGIN
+    BLOCK "StringFileInfo"
+    BEGIN
+        BLOCK "040904b0"
+        BEGIN
+            // Required:
+            VALUE "CompanyName", "The OpenSSL Project, http://www.openssl.org/\\0"
+            VALUE "FileDescription", "$description\\0"
+            VALUE "FileVersion", "$version\\0"
+            VALUE "InternalName", "$basename\\0"
+            VALUE "OriginalFilename", "$filename\\0"
+            VALUE "ProductName", "The OpenSSL Toolkit\\0"
+            VALUE "ProductVersion", "$version\\0"
+            // Optional:
+            //VALUE "Comments", "\\0"
+            VALUE "LegalCopyright", "Copyright Â© 1998-2006 The OpenSSL Project. Copyright Â© 1995-1998 Eric A. Young, Tim J. Hudson. All rights reserved.\\0"
+            //VALUE "LegalTrademarks", "\\0"
+            //VALUE "PrivateBuild", "\\0"
+            //VALUE "SpecialBuild", "\\0"
+        END
+    END
+    BLOCK "VarFileInfo"
+    BEGIN
+        VALUE "Translation", 0x409, 0x4b0
+    END
+END
+___
diff --git a/deps/openssl/openssl/util/mkstack.pl b/deps/openssl/openssl/util/mkstack.pl
new file mode 100755 (executable)
index 0000000..f708610
--- /dev/null
@@ -0,0 +1,192 @@
+#!/usr/local/bin/perl -w
+
+# This is a utility that searches out "DECLARE_STACK_OF()"
+# declarations in .h and .c files, and updates/creates/replaces
+# the corresponding macro declarations in crypto/stack/safestack.h.
+# As it's not generally possible to have macros that generate macros,
+# we need to control this from the "outside", here in this script.
+#
+# Geoff Thorpe, June, 2000 (with massive Perl-hacking
+#                           help from Steve Robb)
+
+my $safestack = "crypto/stack/safestack";
+
+my $do_write;
+while (@ARGV) {
+       my $arg = $ARGV[0];
+       if($arg eq "-write") {
+               $do_write = 1;
+       }
+       shift @ARGV;
+}
+
+
+@source = (<crypto/*.[ch]>, <crypto/*/*.[ch]>, <ssl/*.[ch]>, <apps/*.[ch]>);
+foreach $file (@source) {
+       next if -l $file;
+
+       # Open the .c/.h file for reading
+       open(IN, "< $file") || die "Can't open $file for reading: $!";
+
+       while(<IN>) {
+               if (/^DECLARE_STACK_OF\(([^)]+)\)/) {
+                       push @stacklst, $1;
+               }
+               if (/^DECLARE_SPECIAL_STACK_OF\(([^,\s]+)\s*,\s*([^>\s]+)\)/) {
+                       push @sstacklst, [$1, $2];
+               }
+               if (/^DECLARE_ASN1_SET_OF\(([^)]+)\)/) {
+                       push @asn1setlst, $1;
+               }
+               if (/^DECLARE_PKCS12_STACK_OF\(([^)]+)\)/) {
+                       push @p12stklst, $1;
+               }
+               if (/^DECLARE_LHASH_OF\(([^)]+)\)/) {
+                       push @lhashlst, $1;
+               }
+       }
+       close(IN);
+}
+
+
+
+my $old_stackfile = "";
+my $new_stackfile = "";
+my $inside_block = 0;
+my $type_thing;
+
+open(IN, "< $safestack.h") || die "Can't open input file: $!";
+while(<IN>) {
+       $old_stackfile .= $_;
+
+       if (m|^/\* This block of defines is updated by util/mkstack.pl, please do not touch! \*/|) {
+               $inside_block = 1;
+       }
+       if (m|^/\* End of util/mkstack.pl block, you may now edit :-\) \*/|) {
+               $inside_block = 0;
+       } elsif ($inside_block == 0) {
+               $new_stackfile .= $_;
+       }
+       next if($inside_block != 1);
+       $new_stackfile .= "/* This block of defines is updated by util/mkstack.pl, please do not touch! */";
+               
+       foreach $type_thing (sort @stacklst) {
+               $new_stackfile .= <<EOF;
+
+#define sk_${type_thing}_new(cmp) SKM_sk_new($type_thing, (cmp))
+#define sk_${type_thing}_new_null() SKM_sk_new_null($type_thing)
+#define sk_${type_thing}_free(st) SKM_sk_free($type_thing, (st))
+#define sk_${type_thing}_num(st) SKM_sk_num($type_thing, (st))
+#define sk_${type_thing}_value(st, i) SKM_sk_value($type_thing, (st), (i))
+#define sk_${type_thing}_set(st, i, val) SKM_sk_set($type_thing, (st), (i), (val))
+#define sk_${type_thing}_zero(st) SKM_sk_zero($type_thing, (st))
+#define sk_${type_thing}_push(st, val) SKM_sk_push($type_thing, (st), (val))
+#define sk_${type_thing}_unshift(st, val) SKM_sk_unshift($type_thing, (st), (val))
+#define sk_${type_thing}_find(st, val) SKM_sk_find($type_thing, (st), (val))
+#define sk_${type_thing}_find_ex(st, val) SKM_sk_find_ex($type_thing, (st), (val))
+#define sk_${type_thing}_delete(st, i) SKM_sk_delete($type_thing, (st), (i))
+#define sk_${type_thing}_delete_ptr(st, ptr) SKM_sk_delete_ptr($type_thing, (st), (ptr))
+#define sk_${type_thing}_insert(st, val, i) SKM_sk_insert($type_thing, (st), (val), (i))
+#define sk_${type_thing}_set_cmp_func(st, cmp) SKM_sk_set_cmp_func($type_thing, (st), (cmp))
+#define sk_${type_thing}_dup(st) SKM_sk_dup($type_thing, st)
+#define sk_${type_thing}_pop_free(st, free_func) SKM_sk_pop_free($type_thing, (st), (free_func))
+#define sk_${type_thing}_shift(st) SKM_sk_shift($type_thing, (st))
+#define sk_${type_thing}_pop(st) SKM_sk_pop($type_thing, (st))
+#define sk_${type_thing}_sort(st) SKM_sk_sort($type_thing, (st))
+#define sk_${type_thing}_is_sorted(st) SKM_sk_is_sorted($type_thing, (st))
+EOF
+       }
+
+       foreach $type_thing (sort @sstacklst) {
+           my $t1 = $type_thing->[0];
+           my $t2 = $type_thing->[1];
+           $new_stackfile .= <<EOF;
+
+#define sk_${t1}_new(cmp) ((STACK_OF($t1) *)sk_new(CHECKED_SK_CMP_FUNC($t2, cmp)))
+#define sk_${t1}_new_null() ((STACK_OF($t1) *)sk_new_null())
+#define sk_${t1}_push(st, val) sk_push(CHECKED_STACK_OF($t1, st), CHECKED_PTR_OF($t2, val))
+#define sk_${t1}_find(st, val) sk_find(CHECKED_STACK_OF($t1, st), CHECKED_PTR_OF($t2, val))
+#define sk_${t1}_value(st, i) (($t1)sk_value(CHECKED_STACK_OF($t1, st), i))
+#define sk_${t1}_num(st) SKM_sk_num($t1, st)
+#define sk_${t1}_pop_free(st, free_func) sk_pop_free(CHECKED_STACK_OF($t1, st), CHECKED_SK_FREE_FUNC2($t1, free_func))
+#define sk_${t1}_insert(st, val, i) sk_insert(CHECKED_STACK_OF($t1, st), CHECKED_PTR_OF($t2, val), i)
+#define sk_${t1}_free(st) SKM_sk_free(${t1}, st)
+#define sk_${t1}_set(st, i, val) sk_set(CHECKED_STACK_OF($t1, st), i, CHECKED_PTR_OF($t2, val))
+#define sk_${t1}_zero(st) SKM_sk_zero($t1, (st))
+#define sk_${t1}_unshift(st, val) sk_unshift(CHECKED_STACK_OF($t1, st), CHECKED_PTR_OF($t2, val))
+#define sk_${t1}_find_ex(st, val) sk_find_ex((_STACK *)CHECKED_CONST_PTR_OF(STACK_OF($t1), st), CHECKED_CONST_PTR_OF($t2, val))
+#define sk_${t1}_delete(st, i) SKM_sk_delete($t1, (st), (i))
+#define sk_${t1}_delete_ptr(st, ptr) ($t1 *)sk_delete_ptr(CHECKED_STACK_OF($t1, st), CHECKED_PTR_OF($t2, ptr))
+#define sk_${t1}_set_cmp_func(st, cmp)  \\
+       ((int (*)(const $t2 * const *,const $t2 * const *)) \\
+       sk_set_cmp_func(CHECKED_STACK_OF($t1, st), CHECKED_SK_CMP_FUNC($t2, cmp)))
+#define sk_${t1}_dup(st) SKM_sk_dup($t1, st)
+#define sk_${t1}_shift(st) SKM_sk_shift($t1, (st))
+#define sk_${t1}_pop(st) ($t2 *)sk_pop(CHECKED_STACK_OF($t1, st))
+#define sk_${t1}_sort(st) SKM_sk_sort($t1, (st))
+#define sk_${t1}_is_sorted(st) SKM_sk_is_sorted($t1, (st))
+
+EOF
+       }
+
+       foreach $type_thing (sort @asn1setlst) {
+               $new_stackfile .= <<EOF;
+
+#define d2i_ASN1_SET_OF_${type_thing}(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\
+       SKM_ASN1_SET_OF_d2i($type_thing, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) 
+#define i2d_ASN1_SET_OF_${type_thing}(st, pp, i2d_func, ex_tag, ex_class, is_set) \\
+       SKM_ASN1_SET_OF_i2d($type_thing, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
+#define ASN1_seq_pack_${type_thing}(st, i2d_func, buf, len) \\
+       SKM_ASN1_seq_pack($type_thing, (st), (i2d_func), (buf), (len))
+#define ASN1_seq_unpack_${type_thing}(buf, len, d2i_func, free_func) \\
+       SKM_ASN1_seq_unpack($type_thing, (buf), (len), (d2i_func), (free_func))
+EOF
+       }
+       foreach $type_thing (sort @p12stklst) {
+               $new_stackfile .= <<EOF;
+
+#define PKCS12_decrypt_d2i_${type_thing}(algor, d2i_func, free_func, pass, passlen, oct, seq) \\
+       SKM_PKCS12_decrypt_d2i($type_thing, (algor), (d2i_func), (free_func), (pass), (passlen), (oct), (seq))
+EOF
+       }
+
+       foreach $type_thing (sort @lhashlst) {
+               my $lc_tt = lc $type_thing;
+               $new_stackfile .= <<EOF;
+
+#define lh_${type_thing}_new() LHM_lh_new(${type_thing},${lc_tt})
+#define lh_${type_thing}_insert(lh,inst) LHM_lh_insert(${type_thing},lh,inst)
+#define lh_${type_thing}_retrieve(lh,inst) LHM_lh_retrieve(${type_thing},lh,inst)
+#define lh_${type_thing}_delete(lh,inst) LHM_lh_delete(${type_thing},lh,inst)
+#define lh_${type_thing}_doall(lh,fn) LHM_lh_doall(${type_thing},lh,fn)
+#define lh_${type_thing}_doall_arg(lh,fn,arg_type,arg) \\
+  LHM_lh_doall_arg(${type_thing},lh,fn,arg_type,arg)
+#define lh_${type_thing}_error(lh) LHM_lh_error(${type_thing},lh)
+#define lh_${type_thing}_num_items(lh) LHM_lh_num_items(${type_thing},lh)
+#define lh_${type_thing}_down_load(lh) LHM_lh_down_load(${type_thing},lh)
+#define lh_${type_thing}_node_stats_bio(lh,out) \\
+  LHM_lh_node_stats_bio(${type_thing},lh,out)
+#define lh_${type_thing}_node_usage_stats_bio(lh,out) \\
+  LHM_lh_node_usage_stats_bio(${type_thing},lh,out)
+#define lh_${type_thing}_stats_bio(lh,out) \\
+  LHM_lh_stats_bio(${type_thing},lh,out)
+#define lh_${type_thing}_free(lh) LHM_lh_free(${type_thing},lh)
+EOF
+       }
+
+       $new_stackfile .= "/* End of util/mkstack.pl block, you may now edit :-) */\n";
+       $inside_block = 2;
+}
+
+
+if ($new_stackfile eq $old_stackfile) {
+       print "No changes to $safestack.h.\n";
+       exit 0; # avoid unnecessary rebuild
+}
+
+if ($do_write) {
+       print "Writing new $safestack.h.\n";
+       open OUT, ">$safestack.h" || die "Can't open output file";
+       print OUT $new_stackfile;
+       close OUT;
+}
diff --git a/deps/openssl/openssl/util/opensslwrap.sh b/deps/openssl/openssl/util/opensslwrap.sh
new file mode 100755 (executable)
index 0000000..b27cbb8
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+HERE="`echo $0 | sed -e 's|[^/]*$||'`"
+OPENSSL="${HERE}../apps/openssl"
+
+if [ -d "${HERE}../engines" -a "x$OPENSSL_ENGINES" = "x" ]; then
+       OPENSSL_ENGINES="${HERE}../engines"; export OPENSSL_ENGINES
+fi
+
+if [ -x "${OPENSSL}.exe" ]; then
+       # The original reason for this script existence is to work around
+       # certain caveats in run-time linker behaviour. On Windows platforms
+       # adjusting $PATH used to be sufficient, but with introduction of
+       # SafeDllSearchMode in XP/2003 the only way to get it right in
+       # *all* possible situations is to copy newly built .DLLs to apps/
+       # and test/, which is now done elsewhere... The $PATH is adjusted
+       # for backward compatibility (and nostagical reasons:-).
+       if [ "$OSTYPE" != msdosdjgpp ]; then
+               PATH="${HERE}..:$PATH"; export PATH
+       fi
+       exec "${OPENSSL}.exe" "$@"
+elif [ -x "${OPENSSL}" -a -x "${HERE}shlib_wrap.sh" ]; then
+       exec "${HERE}shlib_wrap.sh" "${OPENSSL}" "$@"
+else
+       exec "${OPENSSL}" "$@"  # hope for the best...
+fi
diff --git a/deps/openssl/openssl/util/perlpath.pl b/deps/openssl/openssl/util/perlpath.pl
new file mode 100755 (executable)
index 0000000..a1f236b
--- /dev/null
@@ -0,0 +1,35 @@
+#!/usr/local/bin/perl
+#
+# modify the '#!/usr/local/bin/perl'
+# line in all scripts that rely on perl.
+#
+
+require "find.pl";
+
+$#ARGV == 0 || print STDERR "usage: perlpath newpath  (eg /usr/bin)\n";
+&find(".");
+
+sub wanted
+       {
+       return unless /\.pl$/ || /^[Cc]onfigur/;
+
+       open(IN,"<$_") || die "unable to open $dir/$_:$!\n";
+       @a=<IN>;
+       close(IN);
+
+       if (-d $ARGV[0]) {
+               $a[0]="#!$ARGV[0]/perl\n";
+       }
+       else {
+               $a[0]="#!$ARGV[0]\n";
+       }
+
+       # Playing it safe...
+       $new="$_.new";
+       open(OUT,">$new") || die "unable to open $dir/$new:$!\n";
+       print OUT @a;
+       close(OUT);
+
+       rename($new,$_) || die "unable to rename $dir/$new:$!\n";
+       chmod(0755,$_) || die "unable to chmod $dir/$new:$!\n";
+       }
diff --git a/deps/openssl/openssl/util/pl/BC-32.pl b/deps/openssl/openssl/util/pl/BC-32.pl
new file mode 100644 (file)
index 0000000..1f1e13f
--- /dev/null
@@ -0,0 +1,139 @@
+#!/usr/local/bin/perl
+# Borland C++ builder 3 and 4 -- Janez Jere <jj@void.si>
+#
+
+$ssl=  "ssleay32";
+$crypto="libeay32";
+
+$o='\\';
+$cp='copy';
+$rm='del';
+
+# C compiler stuff
+$cc='bcc32';
+$lflags="-ap -Tpe -x -Gn ";
+$mlflags='';
+
+$out_def="out32";
+$tmp_def="tmp32";
+$inc_def="inc32";
+#enable max error messages, disable most common warnings
+$cflags="-DWIN32_LEAN_AND_MEAN -q -w-ccc -w-rch -w-pia -w-aus -w-par -w-inl  -c -tWC -tWM -DOPENSSL_SYSNAME_WIN32 -DL_ENDIAN -DDSO_WIN32 -D_stricmp=stricmp -D_strnicmp=strnicmp ";
+if ($debug)
+{
+    $cflags.="-Od -y -v -vi- -D_DEBUG";
+    $mlflags.=' ';
+}
+else
+{
+    $cflags.="-O2 -ff -fp";
+}
+
+$obj='.obj';
+$ofile="-o";
+
+# EXE linking stuff
+$link="ilink32";
+$efile="";
+$exep='.exe';
+if ($no_sock)
+       { $ex_libs=""; }
+else   { $ex_libs="cw32mt.lib import32.lib"; }
+
+# static library stuff
+$mklib='tlib /P64';
+$ranlib='';
+$plib="";
+$libp=".lib";
+$shlibp=($shlib)?".dll":".lib";
+$lfile='';
+
+$shlib_ex_obj="";
+$app_ex_obj="c0x32.obj"; 
+
+$asm='nasmw -f obj -d__omf__';
+$asm.=" /Zi" if $debug;
+$afile='-o';
+
+$bn_mulw_obj='';
+$bn_mulw_src='';
+$des_enc_obj='';
+$des_enc_src='';
+$bf_enc_obj='';
+$bf_enc_src='';
+
+if (!$no_asm)
+       {
+       $bn_mulw_obj='crypto\bn\asm\bn_win32.obj';
+       $bn_mulw_src='crypto\bn\asm\bn_win32.asm';
+       $des_enc_obj='crypto\des\asm\d_win32.obj crypto\des\asm\y_win32.obj';
+       $des_enc_src='crypto\des\asm\d_win32.asm crypto\des\asm\y_win32.asm';
+       $bf_enc_obj='crypto\bf\asm\b_win32.obj';
+       $bf_enc_src='crypto\bf\asm\b_win32.asm';
+       $cast_enc_obj='crypto\cast\asm\c_win32.obj';
+       $cast_enc_src='crypto\cast\asm\c_win32.asm';
+       $rc4_enc_obj='crypto\rc4\asm\r4_win32.obj';
+       $rc4_enc_src='crypto\rc4\asm\r4_win32.asm';
+       $rc5_enc_obj='crypto\rc5\asm\r5_win32.obj';
+       $rc5_enc_src='crypto\rc5\asm\r5_win32.asm';
+       $md5_asm_obj='crypto\md5\asm\m5_win32.obj';
+       $md5_asm_src='crypto\md5\asm\m5_win32.asm';
+       $sha1_asm_obj='crypto\sha\asm\s1_win32.obj';
+       $sha1_asm_src='crypto\sha\asm\s1_win32.asm';
+       $rmd160_asm_obj='crypto\ripemd\asm\rm_win32.obj';
+       $rmd160_asm_src='crypto\ripemd\asm\rm_win32.asm';
+       $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM -DRMD160_ASM";
+       }
+
+if ($shlib)
+       {
+       $mlflags.=" $lflags /dll";
+#      $cflags =~ s| /MD| /MT|;
+       $lib_cflag=" /GD -D_WINDLL -D_DLL";
+       $out_def="out32dll";
+       $tmp_def="tmp32dll";
+       }
+
+sub do_lib_rule
+       {
+       local($objs,$target,$name,$shlib)=@_;
+       local($ret,$Name);
+
+       $taget =~ s/\//$o/g if $o ne '/';
+       ($Name=$name) =~ tr/a-z/A-Z/;
+
+#      $target="\$(LIB_D)$o$target";
+       $ret.="$target: $objs\n";
+       if (!$shlib)
+               {
+               $ret.=<<___;
+       -\$(RM) $lfile$target
+       \$(MKLIB) $lfile$target \@&&!
++\$(**: = &^
++)
+!
+___
+               }
+       else
+               {
+               local($ex)=($target =~ /O_SSL/)?' $(L_CRYPTO)':'';
+               $ex.=' ws2_32.lib gdi32.lib';
+               $ret.="\t\$(LINK) \$(MLFLAGS) $efile$target /def:ms/${Name}.def @<<\n  \$(SHLIB_EX_OBJ) $objs $ex\n<<\n";
+               }
+       $ret.="\n";
+       return($ret);
+       }
+
+sub do_link_rule
+       {
+       local($target,$files,$dep_libs,$libs)=@_;
+       local($ret,$_);
+       
+       $file =~ s/\//$o/g if $o ne '/';
+       $n=&bname($targer);
+       $ret.="$target: $files $dep_libs\n";
+       $ret.="\t\$(LINK) \$(LFLAGS) $files \$(APP_EX_OBJ), $target,, $libs\n\n";
+       return($ret);
+       }
+
+1;
diff --git a/deps/openssl/openssl/util/pl/Mingw32.pl b/deps/openssl/openssl/util/pl/Mingw32.pl
new file mode 100644 (file)
index 0000000..fe3fb27
--- /dev/null
@@ -0,0 +1,104 @@
+#!/usr/local/bin/perl
+#
+# Mingw32.pl -- Mingw
+#
+
+$o='/';
+$cp='cp';
+$rm='rm -f';
+$mkdir='gmkdir';
+
+$o='\\';
+$cp='copy';
+$rm='del';
+$mkdir='mkdir';
+
+# C compiler stuff
+
+$cc='gcc';
+if ($debug)
+       { $cflags="-DL_ENDIAN -DDSO_WIN32 -g2 -ggdb"; }
+else
+       { $cflags="-DL_ENDIAN -DDSO_WIN32 -fomit-frame-pointer -O3 -mcpu=i486 -Wall"; }
+
+if ($gaswin and !$no_asm)
+       {
+        $bn_asm_obj='$(OBJ_D)\bn-win32.o';
+        $bn_asm_src='crypto/bn/asm/bn-win32.s';
+        $bnco_asm_obj='$(OBJ_D)\co-win32.o';
+        $bnco_asm_src='crypto/bn/asm/co-win32.s';
+        $des_enc_obj='$(OBJ_D)\d-win32.o $(OBJ_D)\y-win32.o';
+        $des_enc_src='crypto/des/asm/d-win32.s crypto/des/asm/y-win32.s';
+        $bf_enc_obj='$(OBJ_D)\b-win32.o';
+        $bf_enc_src='crypto/bf/asm/b-win32.s';
+#       $cast_enc_obj='$(OBJ_D)\c-win32.o';
+#       $cast_enc_src='crypto/cast/asm/c-win32.s';
+        $rc4_enc_obj='$(OBJ_D)\r4-win32.o';
+        $rc4_enc_src='crypto/rc4/asm/r4-win32.s';
+        $rc5_enc_obj='$(OBJ_D)\r5-win32.o';
+        $rc5_enc_src='crypto/rc5/asm/r5-win32.s';
+        $md5_asm_obj='$(OBJ_D)\m5-win32.o';
+        $md5_asm_src='crypto/md5/asm/m5-win32.s';
+        $rmd160_asm_obj='$(OBJ_D)\rm-win32.o';
+        $rmd160_asm_src='crypto/ripemd/asm/rm-win32.s';
+        $sha1_asm_obj='$(OBJ_D)\s1-win32.o';
+        $sha1_asm_src='crypto/sha/asm/s1-win32.s';
+       $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM -DOPENSSL_BN_ASM_PART_WORDS";
+       }
+
+
+$obj='.o';
+$ofile='-o ';
+
+# EXE linking stuff
+$link='${CC}';
+$lflags='${CFLAGS}';
+$efile='-o ';
+$exep='';
+$ex_libs="-lws2_32 -lgdi32";
+
+# static library stuff
+$mklib='ar r';
+$mlflags='';
+$ranlib='ranlib';
+$plib='lib';
+$libp=".a";
+$shlibp=".a";
+$lfile='';
+
+$asm='as';
+$afile='-o ';
+#$bn_asm_obj="";
+#$bn_asm_src="";
+#$des_enc_obj="";
+#$des_enc_src="";
+#$bf_enc_obj="";
+#$bf_enc_src="";
+
+sub do_lib_rule
+       {
+       local($obj,$target,$name,$shlib)=@_;
+       local($ret,$_,$Name);
+
+       $target =~ s/\//$o/g if $o ne '/';
+       $target="$target";
+       ($Name=$name) =~ tr/a-z/A-Z/;
+
+       $ret.="$target: \$(${Name}OBJ)\n";
+       $ret.="\tif exist $target \$(RM) $target\n";
+       $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n";
+       $ret.="\t\$(RANLIB) $target\n\n";
+       }
+
+sub do_link_rule
+       {
+       local($target,$files,$dep_libs,$libs)=@_;
+       local($ret,$_);
+       
+       $file =~ s/\//$o/g if $o ne '/';
+       $n=&bname($target);
+       $ret.="$target: $files $dep_libs\n";
+       $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n";
+       return($ret);
+       }
+1;
diff --git a/deps/openssl/openssl/util/pl/OS2-EMX.pl b/deps/openssl/openssl/util/pl/OS2-EMX.pl
new file mode 100644 (file)
index 0000000..28cd116
--- /dev/null
@@ -0,0 +1,120 @@
+#!/usr/local/bin/perl
+#
+# OS2-EMX.pl - for EMX GCC on OS/2
+#
+
+$o='/';
+$cp='cp';
+$rm='rm -f';
+
+$preamble = "SHELL=sh\n";
+
+# C compiler stuff
+
+$cc='gcc';
+$cflags="-DL_ENDIAN -O3 -fomit-frame-pointer -m486 -Zmtd -Wall ";
+$cflags.="-Zomf " if $shlib;
+$shl_cflag="-Zdll";
+
+if ($debug) { 
+       $cflags.="-g "; 
+}
+
+$obj=$shlib ? '.obj' : '.o';
+$ofile='-o ';
+
+# EXE linking stuff
+$link='${CC}';
+$lflags='${CFLAGS} -Zbsd-signals -s';
+$efile='-o ';
+$exep='.exe';
+$ex_libs="-lsocket";
+
+# static library stuff
+$mklib='ar r';
+$mlflags='';
+$ranlib="ar s";
+$plib='';
+$libp=$shlib ? ".lib" : ".a";
+$shlibp=$shlib ? ".dll" : ".a";
+$lfile='';
+
+$asm=$shlib ? 'as -Zomf' : 'as';
+$afile='-o ';
+$bn_asm_obj="";
+$bn_asm_src="";
+$des_enc_obj="";
+$des_enc_src="";
+$bf_enc_obj="";
+$bf_enc_src="";
+
+if (!$no_asm)
+       {
+       $bn_asm_obj="crypto/bn/asm/bn-os2$obj crypto/bn/asm/co-os2$obj";
+       $bn_asm_src="crypto/bn/asm/bn-os2.asm crypto/bn/asm/co-os2.asm";
+       $des_enc_obj="crypto/des/asm/d-os2$obj crypto/des/asm/y-os2$obj";
+       $des_enc_src="crypto/des/asm/d-os2.asm crypto/des/asm/y-os2.asm";
+       $bf_enc_obj="crypto/bf/asm/b-os2$obj";
+       $bf_enc_src="crypto/bf/asm/b-os2.asm";
+       $cast_enc_obj="crypto/cast/asm/c-os2$obj";
+       $cast_enc_src="crypto/cast/asm/c-os2.asm";
+       $rc4_enc_obj="crypto/rc4/asm/r4-os2$obj";
+       $rc4_enc_src="crypto/rc4/asm/r4-os2.asm";
+       $rc5_enc_obj="crypto/rc5/asm/r5-os2$obj";
+       $rc5_enc_src="crypto/rc5/asm/r5-os2.asm";
+       $md5_asm_obj="crypto/md5/asm/m5-os2$obj";
+       $md5_asm_src="crypto/md5/asm/m5-os2.asm";
+       $sha1_asm_obj="crypto/sha/asm/s1-os2$obj";
+       $sha1_asm_src="crypto/sha/asm/s1-os2.asm";
+       $rmd160_asm_obj="crypto/ripemd/asm/rm-os2$obj";
+       $rmd160_asm_src="crypto/ripemd/asm/rm-os2.asm";
+       $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM -DOPENSSL_BN_ASM_PART_WORDS";
+       }
+
+if ($shlib)
+       {
+       $mlflags.=" $lflags -Zdll";
+       $lib_cflag=" -D_DLL";
+       $out_def="out_dll";
+       $tmp_def="tmp_dll";
+       }
+
+sub do_lib_rule
+       {
+       local($obj,$target,$name,$shlib)=@_;
+       local($ret,$_,$Name);
+
+       $target =~ s/\//$o/g if $o ne '/';
+       $target="$target";
+       ($Name=$name) =~ tr/a-z/A-Z/;
+
+       $ret.="$target: \$(${Name}OBJ)\n";
+       if (!$shlib) 
+               {
+               $ret.="\t\$(RM) $target\n";
+               $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n";
+               $ret.="\t\$(RANLIB) $target\n\n";
+               }
+       else
+               {
+               local($ex)=($target =~ /O_SSL/)?' $(L_CRYPTO)':'';
+               $ex.=' -lsocket';
+               $ret.="\t\$(LINK) \$(SHLIB_CFLAGS) \$(MLFLAGS) $efile$target \$(SHLIB_EX_OBJ) \$(${Name}OBJ) $ex os2/${Name}.def\n";
+               $ret.="\temximp -o $out_def/$name.a os2/${Name}.def\n";
+               $ret.="\temximp -o $out_def/$name.lib os2/${Name}.def\n\n";
+               }
+       }
+
+sub do_link_rule
+       {
+       local($target,$files,$dep_libs,$libs)=@_;
+       local($ret,$_);
+       
+       $file =~ s/\//$o/g if $o ne '/';
+       $n=&bname($target);
+       $ret.="$target: $files $dep_libs\n";
+       $ret.="\t\$(LINK) ${efile}$target \$(CFLAG) \$(LFLAGS) $files $libs\n\n";
+       return($ret);
+       }
+
+1;
diff --git a/deps/openssl/openssl/util/pl/VC-32.pl b/deps/openssl/openssl/util/pl/VC-32.pl
new file mode 100644 (file)
index 0000000..5f25fc4
--- /dev/null
@@ -0,0 +1,338 @@
+#!/usr/local/bin/perl
+# VC-32.pl - unified script for Microsoft Visual C++, covering Win32,
+# Win64 and WinCE [follow $FLAVOR variable to trace the differences].
+#
+
+$ssl=  "ssleay32";
+$crypto="libeay32";
+
+$o='\\';
+$cp='$(PERL) util/copy.pl';
+$mkdir='$(PERL) util/mkdir-p.pl';
+$rm='del /Q';
+
+$zlib_lib="zlib1.lib";
+
+# Santize -L options for ms link
+$l_flags =~ s/-L("\[^"]+")/\/libpath:$1/g;
+$l_flags =~ s/-L(\S+)/\/libpath:$1/g;
+
+# C compiler stuff
+$cc='cl';
+if ($FLAVOR =~ /WIN64/)
+    {
+    # Note that we currently don't have /WX on Win64! There is a lot of
+    # warnings, but only of two types:
+    #
+    # C4344: conversion from '__int64' to 'int/long', possible loss of data
+    # C4267: conversion from 'size_t' to 'int/long', possible loss of data
+    #
+    # Amount of latter type is minimized by aliasing strlen to function of
+    # own desing and limiting its return value to 2GB-1 (see e_os.h). As
+    # per 0.9.8 release remaining warnings were explicitly examined and
+    # considered safe to ignore.
+    # 
+    $base_cflags= " $mf_cflag";
+    my $f = $shlib?' /MD':' /MT';
+    $lib_cflag='/Zl' if (!$shlib);     # remove /DEFAULTLIBs from static lib
+    $opt_cflags=$f.' /Ox';
+    $dbg_cflags=$f.'d /Od -DDEBUG -D_DEBUG';
+    $lflags="/nologo /subsystem:console /opt:ref";
+
+    *::perlasm_compile_target = sub {
+       my ($target,$source,$bname)=@_;
+       my $ret;
+
+       $bname =~ s/(.*)\.[^\.]$/$1/;
+       $ret=<<___;
+\$(TMP_D)$o$bname.asm: $source
+       set ASM=\$(ASM)
+       \$(PERL) $source \$\@
+
+$target: \$(TMP_D)$o$bname.asm
+       \$(ASM) $afile\$\@ \$(TMP_D)$o$bname.asm
+
+___
+       }
+    }
+elsif ($FLAVOR =~ /CE/)
+    {
+    # sanity check
+    die '%OSVERSION% is not defined'   if (!defined($ENV{'OSVERSION'}));
+    die '%PLATFORM% is not defined'    if (!defined($ENV{'PLATFORM'}));
+    die '%TARGETCPU% is not defined'   if (!defined($ENV{'TARGETCPU'}));
+
+    #
+    # Idea behind this is to mimic flags set by eVC++ IDE...
+    #
+    $wcevers = $ENV{'OSVERSION'};                      # WCENNN
+    die '%OSVERSION% value is insane'  if ($wcevers !~ /^WCE([1-9])([0-9]{2})$/);
+    $wcecdefs = "-D_WIN32_WCE=$1$2 -DUNDER_CE=$1$2";   # -D_WIN32_WCE=NNN
+    $wcelflag = "/subsystem:windowsce,$1.$2";          # ...,N.NN
+
+    $wceplatf =  $ENV{'PLATFORM'};
+    $wceplatf =~ tr/a-z0-9 /A-Z0-9_/d;
+    $wcecdefs .= " -DWCE_PLATFORM_$wceplatf";
+
+    $wcetgt = $ENV{'TARGETCPU'};       # just shorter name...
+    SWITCH: for($wcetgt) {
+       /^X86/          && do { $wcecdefs.=" -Dx86 -D_X86_ -D_i386_ -Di_386_";
+                               $wcelflag.=" /machine:IX86";    last; };
+       /^ARMV4[IT]/    && do { $wcecdefs.=" -DARM -D_ARM_ -D$wcetgt";
+                               $wcecdefs.=" -DTHUMB -D_THUMB_" if($wcetgt=~/T$/);
+                               $wcecdefs.=" -QRarch4T -QRinterwork-return";
+                               $wcelflag.=" /machine:THUMB";   last; };
+       /^ARM/          && do { $wcecdefs.=" -DARM -D_ARM_ -D$wcetgt";
+                               $wcelflag.=" /machine:ARM";     last; };
+       /^MIPSIV/       && do { $wcecdefs.=" -DMIPS -D_MIPS_ -DR4000 -D$wcetgt";
+                               $wcecdefs.=" -D_MIPS64 -QMmips4 -QMn32";
+                               $wcelflag.=" /machine:MIPSFPU"; last; };
+       /^MIPS16/       && do { $wcecdefs.=" -DMIPS -D_MIPS_ -DR4000 -D$wcetgt";
+                               $wcecdefs.=" -DMIPSII -QMmips16";
+                               $wcelflag.=" /machine:MIPS16";  last; };
+       /^MIPSII/       && do { $wcecdefs.=" -DMIPS -D_MIPS_ -DR4000 -D$wcetgt";
+                               $wcecdefs.=" -QMmips2";
+                               $wcelflag.=" /machine:MIPS";    last; };
+       /^R4[0-9]{3}/   && do { $wcecdefs.=" -DMIPS -D_MIPS_ -DR4000";
+                               $wcelflag.=" /machine:MIPS";    last; };
+       /^SH[0-9]/      && do { $wcecdefs.=" -D$wcetgt -D_$wcetgt_ -DSHx";
+                               $wcecdefs.=" -Qsh4" if ($wcetgt =~ /^SH4/);
+                               $wcelflag.=" /machine:$wcetgt"; last; };
+       { $wcecdefs.=" -D$wcetgt -D_$wcetgt_";
+         $wcelflag.=" /machine:$wcetgt";                       last; };
+    }
+
+    $cc='$(CC)';
+    $base_cflags=' /W3 /WX /GF /Gy /nologo -DUNICODE -D_UNICODE -DOPENSSL_SYSNAME_WINCE -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DDSO_WIN32 -DNO_CHMOD -DOPENSSL_SMALL_FOOTPRINT';
+    $base_cflags.=" $wcecdefs";
+    $base_cflags.=' -I$(WCECOMPAT)/include'            if (defined($ENV{'WCECOMPAT'}));
+    $base_cflags.=' -I$(PORTSDK_LIBPATH)/../../include'        if (defined($ENV{'PORTSDK_LIBPATH'}));
+    $opt_cflags=' /MC /O1i';   # optimize for space, but with intrinsics...
+    $dbg_clfags=' /MC /Od -DDEBUG -D_DEBUG';
+    $lflags="/nologo /opt:ref $wcelflag";
+    }
+else   # Win32
+    {
+    $base_cflags= " $mf_cflag";
+    my $f = $shlib?' /MD':' /MT';
+    $lib_cflag='/Zl' if (!$shlib);     # remove /DEFAULTLIBs from static lib
+    $opt_cflags=$f.' /Ox /O2 /Ob2';
+    $dbg_cflags=$f.'d /Od -DDEBUG -D_DEBUG';
+    $lflags="/nologo /subsystem:console /opt:ref";
+    }
+$mlflags='';
+
+$out_def ="out32";     $out_def.="dll"                 if ($shlib);
+                       $out_def.='_$(TARGETCPU)'       if ($FLAVOR =~ /CE/);
+$tmp_def ="tmp32";     $tmp_def.="dll"                 if ($shlib);
+                       $tmp_def.='_$(TARGETCPU)'       if ($FLAVOR =~ /CE/);
+$inc_def="inc32";
+
+if ($debug)
+       {
+       $cflags=$dbg_cflags.$base_cflags;
+       }
+else
+       {
+       $cflags=$opt_cflags.$base_cflags;
+       }
+
+# generate symbols.pdb unconditionally
+$app_cflag.=" /Zi /Fd\$(TMP_D)/app";
+$lib_cflag.=" /Zi /Fd\$(TMP_D)/lib";
+$lflags.=" /debug";
+
+$obj='.obj';
+$asm_suffix='.asm';
+$ofile="/Fo";
+
+# EXE linking stuff
+$link="link";
+$rsc="rc";
+$efile="/out:";
+$exep='.exe';
+if ($no_sock)          { $ex_libs=''; }
+elsif ($FLAVOR =~ /CE/)        { $ex_libs='winsock.lib'; }
+else                   { $ex_libs='ws2_32.lib'; }
+
+if ($FLAVOR =~ /CE/)
+       {
+       $ex_libs.=' $(WCECOMPAT)/lib/wcecompatex.lib'   if (defined($ENV{'WCECOMPAT'}));
+       $ex_libs.=' $(PORTSDK_LIBPATH)/portlib.lib'     if (defined($ENV{'PORTSDK_LIBPATH'}));
+       $ex_libs.=' /nodefaultlib:oldnames.lib coredll.lib corelibc.lib' if ($ENV{'TARGETCPU'} eq "X86");
+       }
+else
+       {
+       $ex_libs.=' gdi32.lib advapi32.lib crypt32.lib user32.lib';
+       $ex_libs.=' bufferoverflowu.lib' if ($FLAVOR =~ /WIN64/ and `cl 2>&1` =~ /14\.00\.4[0-9]{4}\./);
+       # WIN32 UNICODE build gets linked with unicows.lib for
+       # backward compatibility with Win9x.
+       $ex_libs="unicows.lib $ex_libs" if ($FLAVOR =~ /WIN32/ and $cflags =~ /\-DUNICODE/);
+       }
+
+# static library stuff
+$mklib='lib /nologo';
+$ranlib='';
+$plib="";
+$libp=".lib";
+$shlibp=($shlib)?".dll":".lib";
+$lfile='/out:';
+
+$shlib_ex_obj="";
+$app_ex_obj="setargv.obj" if ($FLAVOR !~ /CE/);
+if ($FLAVOR =~ /WIN64A/) {
+       if (`nasm -v 2>NUL` =~ /NASM version ([0-9]+\.[0-9]+)/ && $1 >= 2.0) {
+               $asm='nasm -f win64 -DNEAR -Ox -g';
+               $afile='-o ';
+       } else {
+               $asm='ml64 /c /Cp /Cx /Zi';
+               $afile='/Fo';
+       }
+} elsif ($FLAVOR =~ /WIN64I/) {
+       $asm='ias -d debug';
+       $afile="-o ";
+} elsif ($nasm) {
+       my $ver=`nasm -v 2>NUL`;
+       my $vew=`nasmw -v 2>NUL`;
+       # pick newest version
+       $asm=($ver ge $vew?"nasm":"nasmw")." -f win32";
+       $asmtype="win32n";
+       $afile='-o ';
+} else {
+       $asm='ml /nologo /Cp /coff /c /Cx /Zi';
+       $afile='/Fo';
+       $asmtype="win32";
+}
+
+$bn_asm_obj='';
+$bn_asm_src='';
+$des_enc_obj='';
+$des_enc_src='';
+$bf_enc_obj='';
+$bf_enc_src='';
+
+if (!$no_asm)
+       {
+       win32_import_asm($mf_bn_asm, "bn", \$bn_asm_obj, \$bn_asm_src);
+       win32_import_asm($mf_aes_asm, "aes", \$aes_asm_obj, \$aes_asm_src);
+       win32_import_asm($mf_des_asm, "des", \$des_enc_obj, \$des_enc_src);
+       win32_import_asm($mf_bf_asm, "bf", \$bf_enc_obj, \$bf_enc_src);
+       win32_import_asm($mf_cast_asm, "cast", \$cast_enc_obj, \$cast_enc_src);
+       win32_import_asm($mf_rc4_asm, "rc4", \$rc4_enc_obj, \$rc4_enc_src);
+       win32_import_asm($mf_rc5_asm, "rc5", \$rc5_enc_obj, \$rc5_enc_src);
+       win32_import_asm($mf_md5_asm, "md5", \$md5_asm_obj, \$md5_asm_src);
+       win32_import_asm($mf_sha_asm, "sha", \$sha1_asm_obj, \$sha1_asm_src);
+       win32_import_asm($mf_rmd_asm, "ripemd", \$rmd160_asm_obj, \$rmd160_asm_src);
+       win32_import_asm($mf_wp_asm, "whrlpool", \$whirlpool_asm_obj, \$whirlpool_asm_src);
+       win32_import_asm($mf_cpuid_asm, "", \$cpuid_asm_obj, \$cpuid_asm_src);
+       $perl_asm = 1;
+       }
+
+if ($shlib && $FLAVOR !~ /CE/)
+       {
+       $mlflags.=" $lflags /dll";
+       $lib_cflag.=" -D_WINDLL";
+       #
+       # Engage Applink...
+       #
+       $app_ex_obj.=" \$(OBJ_D)\\applink.obj /implib:\$(TMP_D)\\junk.lib";
+       $cflags.=" -DOPENSSL_USE_APPLINK -I.";
+       # I'm open for better suggestions than overriding $banner...
+       $banner=<<'___';
+       @echo Building OpenSSL
+
+$(OBJ_D)\applink.obj:  ms\applink.c
+       $(CC) /Fo$(OBJ_D)\applink.obj $(APP_CFLAGS) -c ms\applink.c
+$(OBJ_D)\uplink.obj:   ms\uplink.c ms\applink.c
+       $(CC) /Fo$(OBJ_D)\uplink.obj $(SHLIB_CFLAGS) -c ms\uplink.c
+$(INCO_D)\applink.c:   ms\applink.c
+       $(CP) ms\applink.c $(INCO_D)\applink.c
+
+EXHEADER= $(EXHEADER) $(INCO_D)\applink.c
+
+LIBS_DEP=$(LIBS_DEP) $(OBJ_D)\applink.obj
+CRYPTOOBJ=$(OBJ_D)\uplink.obj $(CRYPTOOBJ)
+___
+       $banner.=<<'___' if ($FLAVOR =~ /WIN64/);
+CRYPTOOBJ=ms\uptable.obj $(CRYPTOOBJ)
+___
+       }
+elsif ($shlib && $FLAVOR =~ /CE/)
+       {
+       $mlflags.=" $lflags /dll";
+       $lflags.=' /entry:mainCRTstartup' if(defined($ENV{'PORTSDK_LIBPATH'}));
+       $lib_cflag.=" -D_WINDLL -D_DLL";
+       }
+
+sub do_lib_rule
+       {
+       local($objs,$target,$name,$shlib)=@_;
+       local($ret);
+
+       $taget =~ s/\//$o/g if $o ne '/';
+       if ($name ne "")
+               {
+               $name =~ tr/a-z/A-Z/;
+               $name = "/def:ms/${name}.def";
+               }
+
+#      $target="\$(LIB_D)$o$target";
+       $ret.="$target: $objs\n";
+       if (!$shlib)
+               {
+#              $ret.="\t\$(RM) \$(O_$Name)\n";
+               $ret.="\t\$(MKLIB) $lfile$target @<<\n  $objs\n<<\n";
+               }
+       else
+               {
+               local($ex)=($target =~ /O_CRYPTO/)?'':' $(L_CRYPTO)';
+               $ex.=" $zlib_lib" if $zlib_opt == 1 && $target =~ /O_CRYPTO/;
+               $ret.="\t\$(LINK) \$(MLFLAGS) $efile$target $name @<<\n  \$(SHLIB_EX_OBJ) $objs $ex \$(EX_LIBS)\n<<\n";
+               $ret.="\tIF EXIST \$@.manifest mt -nologo -manifest \$@.manifest -outputresource:\$@;2\n\n";
+               }
+       $ret.="\n";
+       return($ret);
+       }
+
+sub do_link_rule
+       {
+       local($target,$files,$dep_libs,$libs)=@_;
+       local($ret,$_);
+       
+       $file =~ s/\//$o/g if $o ne '/';
+       $n=&bname($targer);
+       $ret.="$target: $files $dep_libs\n";
+       $ret.="\t\$(LINK) \$(LFLAGS) $efile$target @<<\n";
+       $ret.="  \$(APP_EX_OBJ) $files $libs\n<<\n";
+       $ret.="\tIF EXIST \$@.manifest mt -nologo -manifest \$@.manifest -outputresource:\$@;1\n\n";
+       return($ret);
+       }
+
+sub win32_import_asm
+       {
+       my ($mf_var, $asm_name, $oref, $sref) = @_;
+       my $asm_dir;
+       if ($asm_name eq "")
+               {
+               $asm_dir = "crypto\\";
+               }
+       else
+               {
+               $asm_dir = "crypto\\$asm_name\\asm\\";
+               }
+
+       $$oref = "";
+       $mf_var =~ s/\.o$/.obj/g;
+
+       foreach (split(/ /, $mf_var))
+               {
+               $$oref .= $asm_dir . $_ . " ";
+               }
+       $$oref =~ s/ $//;
+       $$sref = $$oref;
+       $$sref =~ s/\.obj/.asm/g;
+
+       }
+
+
+1;
diff --git a/deps/openssl/openssl/util/pl/linux.pl b/deps/openssl/openssl/util/pl/linux.pl
new file mode 100644 (file)
index 0000000..d24f7b7
--- /dev/null
@@ -0,0 +1,104 @@
+#!/usr/local/bin/perl
+#
+# linux.pl - the standard unix makefile stuff.
+#
+
+$o='/';
+$cp='/bin/cp';
+$rm='/bin/rm -f';
+
+# C compiler stuff
+
+$cc='gcc';
+if ($debug)
+       { $cflags="-g2 -ggdb -DREF_CHECK -DCRYPTO_MDEBUG"; }
+elsif ($profile)
+       { $cflags="-pg -O3"; }
+else
+       { $cflags="-O3 -fomit-frame-pointer"; }
+
+if (!$no_asm)
+       {
+       $bn_asm_obj='$(OBJ_D)/bn86-elf.o';
+       $bn_asm_src='crypto/bn/asm/bn86unix.cpp';
+       $bnco_asm_obj='$(OBJ_D)/co86-elf.o';
+       $bnco_asm_src='crypto/bn/asm/co86unix.cpp';
+       $des_enc_obj='$(OBJ_D)/dx86-elf.o $(OBJ_D)/yx86-elf.o';
+       $des_enc_src='crypto/des/asm/dx86unix.cpp crypto/des/asm/yx86unix.cpp';
+       $bf_enc_obj='$(OBJ_D)/bx86-elf.o';
+       $bf_enc_src='crypto/bf/asm/bx86unix.cpp';
+       $cast_enc_obj='$(OBJ_D)/cx86-elf.o';
+       $cast_enc_src='crypto/cast/asm/cx86unix.cpp';
+       $rc4_enc_obj='$(OBJ_D)/rx86-elf.o';
+       $rc4_enc_src='crypto/rc4/asm/rx86unix.cpp';
+       $rc5_enc_obj='$(OBJ_D)/r586-elf.o';
+       $rc5_enc_src='crypto/rc5/asm/r586unix.cpp';
+       $md5_asm_obj='$(OBJ_D)/mx86-elf.o';
+       $md5_asm_src='crypto/md5/asm/mx86unix.cpp';
+       $rmd160_asm_obj='$(OBJ_D)/rm86-elf.o';
+       $rmd160_asm_src='crypto/ripemd/asm/rm86unix.cpp';
+       $sha1_asm_obj='$(OBJ_D)/sx86-elf.o';
+       $sha1_asm_src='crypto/sha/asm/sx86unix.cpp';
+       $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM -DOPENSSL_BN_ASM_PART_WORDS";
+       }
+
+$cflags.=" -DTERMIO -DL_ENDIAN -m486 -Wall";
+
+if ($shlib)
+       {
+       $shl_cflag=" -DPIC -fpic";
+       $shlibp=".so.$ssl_version";
+       $so_shlibp=".so";
+       }
+
+sub do_shlib_rule
+       {
+       local($obj,$target,$name,$shlib,$so_name)=@_;
+       local($ret,$_,$Name);
+
+       $target =~ s/\//$o/g if $o ne '/';
+       ($Name=$name) =~ tr/a-z/A-Z/;
+
+       $ret.="$target: \$(${Name}OBJ)\n";
+       $ret.="\t\$(RM) target\n";
+       $ret.="\tgcc \${CFLAGS} -shared -Wl,-soname,$target -o $target \$(${Name}OBJ)\n";
+       ($t=$target) =~ s/(^.*)\/[^\/]*$/$1/;
+       if ($so_name ne "")
+               {
+               $ret.="\t\$(RM) \$(LIB_D)$o$so_name\n";
+               $ret.="\tln -s $target \$(LIB_D)$o$so_name\n\n";
+               }
+       }
+
+sub do_link_rule
+       {
+       local($target,$files,$dep_libs,$libs)=@_;
+       local($ret,$_);
+       
+       $file =~ s/\//$o/g if $o ne '/';
+       $n=&bname($target);
+       $ret.="$target: $files $dep_libs\n";
+       $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n";
+       return($ret);
+       }
+
+sub do_asm_rule
+       {
+       local($target,$src)=@_;
+       local($ret,@s,@t,$i);
+
+       $target =~ s/\//$o/g if $o ne "/";
+       $src =~ s/\//$o/g if $o ne "/";
+
+       @s=split(/\s+/,$src);
+       @t=split(/\s+/,$target);
+
+       for ($i=0; $i<=$#s; $i++)
+               {
+               $ret.="$t[$i]: $s[$i]\n";
+               $ret.="\tgcc -E -DELF \$(SRC_D)$o$s[$i]|\$(AS) $afile$t[$i]\n\n";
+               }
+       return($ret);
+       }
+
+1;
diff --git a/deps/openssl/openssl/util/pl/netware.pl b/deps/openssl/openssl/util/pl/netware.pl
new file mode 100644 (file)
index 0000000..c78bcfc
--- /dev/null
@@ -0,0 +1,532 @@
+# Metrowerks Codewarrior or gcc / nlmconv for NetWare
+#
+
+$version_header = "crypto/opensslv.h";
+open(IN, "$version_header") or die "Couldn't open $version_header: $!";
+while (<IN>) {
+  if (/^#define[\s\t]+OPENSSL_VERSION_NUMBER[\s\t]+0x(\d)(\d{2})(\d{2})(\d{2})/)
+  {
+    # die "OpenSSL version detected: $1.$2.$3.$4\n";
+    #$nlmvernum = "$1,$2,$3";
+    $nlmvernum = "$1,".($2*10+$3).",".($4*1);
+    #$nlmverstr = "$1.".($2*1).".".($3*1).($4?(chr(96+$4)):"");
+    break;
+  }
+}
+close(IN) or die "Couldn't close $version_header: $!";
+
+$readme_file = "README";
+open(IN, $readme_file) or die "Couldn't open $readme_file: $!";
+while (<IN>) {
+  if (/^[\s\t]+OpenSSL[\s\t]+(\d)\.(\d{1,2})\.(\d{1,2})([a-z])(.*)/)
+  {
+    #$nlmvernum = "$1,$2,$3";
+    #$nlmvernum = "$1,".($2*10+$3).",".($4*1);
+    $nlmverstr = "$1.$2.$3$4$5";
+  }
+  elsif (/^[\s\t]+(Copyright \(c\) \d{4}\-\d{4} The OpenSSL Project)$/)
+  {
+    $nlmcpystr = $1;
+  }
+  break if ($nlmvernum && $nlmcpystr);
+}
+close(IN) or die "Couldn't close $readme_file: $!";
+
+# Define stacksize here
+$nlmstack = "32768";
+
+# some default settings here in case we failed to find them in README
+$nlmvernum = "1,0,0" if (!$nlmvernum);
+$nlmverstr = "OpenSSL" if (!$nlmverstr);
+$nlmcpystr = "Copyright (c) 1998-now The OpenSSL Project" if (!$nlmcpystr);
+
+# die "OpenSSL copyright: $nlmcpystr\nOpenSSL verstring: $nlmverstr\nOpenSSL vernumber: $nlmvernum\n";
+
+# The import files and other misc imports needed to link
+@misc_imports = ("GetProcessSwitchCount", "RunningProcess",
+                 "GetSuperHighResolutionTimer");
+if ($LIBC)
+{
+   @import_files = ("libc.imp");
+   @module_files = ("libc");
+   $libarch = "LIBC";
+}
+else
+{
+   # clib build
+   @import_files = ("clib.imp");
+   push(@import_files, "socklib.imp") if ($BSDSOCK);
+   @module_files = ("clib");
+   # push(@misc_imports, "_rt_modu64%16", "_rt_divu64%16");
+   $libarch = "CLIB";
+}
+if ($BSDSOCK)
+{
+   $libarch .= "-BSD";
+}
+else
+{
+   $libarch .= "-WS2";
+   push(@import_files, "ws2nlm.imp");
+}
+
+# The "IMPORTS" environment variable must be set and point to the location
+# where import files (*.imp) can be found.
+# Example:  set IMPORTS=c:\ndk\nwsdk\imports
+$import_path = $ENV{"IMPORTS"} || die ("IMPORTS environment variable not set\n");
+
+
+# The "PRELUDE" environment variable must be set and point to the location
+# and name of the prelude source to link with ( nwpre.obj is recommended ).
+# Example: set PRELUDE=c:\codewar\novell support\metrowerks support\libraries\runtime\nwpre.obj
+$prelude = $ENV{"PRELUDE"} || die ("PRELUDE environment variable not set\n");
+
+# The "INCLUDES" environment variable must be set and point to the location
+# where import files (*.imp) can be found.
+$include_path = $ENV{"INCLUDE"} || die ("INCLUDES environment variable not set\n");
+$include_path =~ s/\\/\//g;
+$include_path = join(" -I", split(/;/, $include_path));
+
+# check for gcc compiler
+$gnuc = $ENV{"GNUC"};
+
+#$ssl=   "ssleay32";
+#$crypto="libeay32";
+
+if ($gnuc)
+{
+   # C compiler
+   $cc='gcc';
+   # Linker
+   $link='nlmconv';
+   # librarian
+   $mklib='ar';
+   $o='/';
+   # cp command
+   $cp='cp -af';
+   # rm command
+   $rm='rm -f';
+   # mv command
+   $mv='mv -f';
+   # mkdir command
+   $mkdir='gmkdir';
+   #$ranlib='ranlib';
+}
+else
+{
+   # C compiler
+   $cc='mwccnlm';
+   # Linker
+   $link='mwldnlm';
+   # librarian
+   $mklib='mwldnlm';
+   # Path separator
+   $o='\\';
+   # cp command
+   $cp='copy >nul:';
+   # rm command
+   $rm='del /f /q';
+}
+
+# assembler
+if ($nw_nasm)
+{
+   $asm=(`nasm -v 2>NUL` gt `nasmw -v 2>NUL`?"nasm":"nasmw");
+   if ($gnuc)
+   {
+      $asm.=" -s -f elf";
+   }
+   else
+   {
+      $asm.=" -s -f coff -d __coff__";
+   }
+   $afile="-o ";
+   $asm.=" -g" if $debug;
+}
+elsif ($nw_mwasm)
+{
+   $asm="mwasmnlm -maxerrors 20";
+   $afile="-o ";
+   $asm.=" -g" if $debug;
+}
+elsif ($nw_masm)
+{
+# masm assembly settings - it should be possible to use masm but haven't
+# got it working.
+# $asm='ml /Cp /coff /c /Cx';
+# $asm.=" /Zi" if $debug;
+# $afile='/Fo';
+   die("Support for masm assembler not yet functional\n");
+}
+else
+{
+   $asm="";
+   $afile="";
+}
+
+
+
+if ($gnuc)
+{
+   # compile flags for GNUC
+   # additional flags based upon debug | non-debug
+   if ($debug)
+   {
+      $cflags="-g -DDEBUG";
+   }
+   else
+   {
+      $cflags="-O2";
+   }
+   $cflags.=" -nostdinc -I$include_path \\
+         -fno-builtin -fpcc-struct-return -fno-strict-aliasing \\
+         -funsigned-char -Wall -Wno-unused -Wno-uninitialized";
+
+   # link flags
+   $lflags="-T";
+}
+else
+{
+   # compile flags for CodeWarrior
+   # additional flags based upon debug | non-debug
+   if ($debug)
+   {
+      $cflags="-opt off -g -sym internal -DDEBUG";
+   }
+   else
+   {
+   # CodeWarrior compiler has a problem with optimizations for floating
+   # points - no optimizations until further investigation
+   #      $cflags="-opt all";
+   }
+
+   # NOTES: Several c files in the crypto subdirectory include headers from
+   #        their local directories.  Metrowerks wouldn't find these h files
+   #        without adding individual include directives as compile flags
+   #        or modifying the c files.  Instead of adding individual include
+   #        paths for each subdirectory a recursive include directive
+   #        is used ( -ir crypto ).
+   #
+   #        A similar issue exists for the engines and apps subdirectories.
+   #
+   #        Turned off the "possible" warnings ( -w nopossible ).  Metrowerks
+   #        complained a lot about various stuff.  May want to turn back
+   #        on for further development.
+   $cflags.=" -nostdinc -ir crypto -ir engines -ir apps -I$include_path \\
+         -msgstyle gcc -align 4 -processor pentium -char unsigned \\
+         -w on -w nolargeargs -w nopossible -w nounusedarg -w nounusedexpr \\
+         -w noimplicitconv -relax_pointers -nosyspath -maxerrors 20";
+
+   # link flags
+   $lflags="-msgstyle gcc -zerobss -nostdlib -sym internal -commandfile";
+}
+
+# common defines
+$cflags.=" -DL_ENDIAN -DOPENSSL_SYSNAME_NETWARE -U_WIN32";
+
+# If LibC build add in NKS_LIBC define and set the entry/exit
+# routines - The default entry/exit routines are for CLib and don't exist
+# in LibC
+if ($LIBC)
+{
+   $cflags.=" -DNETWARE_LIBC";
+   $nlmstart = "_LibCPrelude";
+   $nlmexit = "_LibCPostlude";
+   @nlm_flags = ("pseudopreemption", "flag_on 64");
+}
+else
+{
+   $cflags.=" -DNETWARE_CLIB";
+   $nlmstart = "_Prelude";
+   $nlmexit = "_Stop";
+}
+
+# If BSD Socket support is requested, set a define for the compiler
+if ($BSDSOCK)
+{
+   $cflags.=" -DNETWARE_BSDSOCK";
+   if (!$LIBC)
+   {
+      $cflags.=" -DNETDB_USE_INTERNET";
+   }
+}
+
+
+# linking stuff
+# for the output directories use the mk1mf.pl values with "_nw" appended
+if ($shlib)
+{
+   if ($LIBC)
+   {
+      $out_def.="_nw_libc_nlm";
+      $tmp_def.="_nw_libc_nlm";
+      $inc_def.="_nw_libc_nlm";
+   }
+   else  # NETWARE_CLIB
+   {
+      $out_def.="_nw_clib_nlm";
+      $tmp_def.="_nw_clib_nlm";
+      $inc_def.="_nw_clib_nlm";
+   }
+}
+else
+{
+   if ($gnuc) # GNUC Tools
+   {
+      $libp=".a";
+      $shlibp=".a";
+      $lib_flags="-cr";
+   }
+   else       # CodeWarrior
+   {
+      $libp=".lib";
+      $shlibp=".lib";
+      $lib_flags="-nodefaults -type library -o";
+   }
+   if ($LIBC)
+   {
+      $out_def.="_nw_libc";
+      $tmp_def.="_nw_libc";
+      $inc_def.="_nw_libc";
+   }
+   else  # NETWARE_CLIB
+   {
+      $out_def.="_nw_clib";
+      $tmp_def.="_nw_clib";
+      $inc_def.="_nw_clib";
+   }
+}
+
+# used by mk1mf.pl
+$obj='.o';
+$ofile='-o ';
+$efile='';
+$exep='.nlm';
+$ex_libs='';
+
+if (!$no_asm)
+{
+   $bn_asm_obj="\$(OBJ_D)${o}bn-nw${obj}";
+   $bn_asm_src="crypto${o}bn${o}asm${o}bn-nw.asm";
+   $bnco_asm_obj="\$(OBJ_D)${o}co-nw${obj}";
+   $bnco_asm_src="crypto${o}bn${o}asm${o}co-nw.asm";
+   $aes_asm_obj="\$(OBJ_D)${o}a-nw${obj}";
+   $aes_asm_src="crypto${o}aes${o}asm${o}a-nw.asm";
+   $des_enc_obj="\$(OBJ_D)${o}d-nw${obj} \$(OBJ_D)${o}y-nw${obj}";
+   $des_enc_src="crypto${o}des${o}asm${o}d-nw.asm crypto${o}des${o}asm${o}y-nw.asm";
+   $bf_enc_obj="\$(OBJ_D)${o}b-nw${obj}";
+   $bf_enc_src="crypto${o}bf${o}asm${o}b-nw.asm";
+   $cast_enc_obj="\$(OBJ_D)${o}c-nw${obj}";
+   $cast_enc_src="crypto${o}cast${o}asm${o}c-nw.asm";
+   $rc4_enc_obj="\$(OBJ_D)${o}r4-nw${obj}";
+   $rc4_enc_src="crypto${o}rc4${o}asm${o}r4-nw.asm";
+   $rc5_enc_obj="\$(OBJ_D)${o}r5-nw${obj}";
+   $rc5_enc_src="crypto${o}rc5${o}asm${o}r5-nw.asm";
+   $md5_asm_obj="\$(OBJ_D)${o}m5-nw${obj}";
+   $md5_asm_src="crypto${o}md5${o}asm${o}m5-nw.asm";
+   $sha1_asm_obj="\$(OBJ_D)${o}s1-nw${obj} \$(OBJ_D)${o}sha256-nw${obj} \$(OBJ_D)${o}sha512-nw${obj}";
+   $sha1_asm_src="crypto${o}sha${o}asm${o}s1-nw.asm crypto${o}sha${o}asm${o}sha256-nw.asm crypto${o}sha${o}asm${o}sha512-nw.asm";
+   $rmd160_asm_obj="\$(OBJ_D)${o}rm-nw${obj}";
+   $rmd160_asm_src="crypto${o}ripemd${o}asm${o}rm-nw.asm";
+   $whirlpool_asm_obj="\$(OBJ_D)${o}wp-nw${obj}";
+   $whirlpool_asm_src="crypto${o}whrlpool${o}asm${o}wp-nw.asm";
+   $cpuid_asm_obj="\$(OBJ_D)${o}x86cpuid-nw${obj}";
+   $cpuid_asm_src="crypto${o}x86cpuid-nw.asm";
+   $cflags.=" -DOPENSSL_CPUID_OBJ -DBN_ASM -DOPENSSL_BN_ASM_PART_WORDS -DMD5_ASM -DWHIRLPOOL_ASM";
+   $cflags.=" -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM";
+   $cflags.=" -DAES_ASM -DRMD160_ASM";
+}
+else
+{
+   $bn_asm_obj='';
+   $bn_asm_src='';
+   $bnco_asm_obj='';
+   $bnco_asm_src='';
+   $aes_asm_obj='';
+   $aes_asm_src='';
+   $des_enc_obj='';
+   $des_enc_src='';
+   $bf_enc_obj='';
+   $bf_enc_src='';
+   $cast_enc_obj='';
+   $cast_enc_src='';
+   $rc4_enc_obj='';
+   $rc4_enc_src='';
+   $rc5_enc_obj='';
+   $rc5_enc_src='';
+   $md5_asm_obj='';
+   $md5_asm_src='';
+   $sha1_asm_obj='';
+   $sha1_asm_src='';
+   $rmd160_asm_obj='';
+   $rmd160_asm_src='';
+   $whirlpool_asm_obj='';
+   $whirlpool_asm_src='';
+   $cpuid_asm_obj='';
+   $cpuid_asm_src='';
+}
+
+# create the *.def linker command files in \openssl\netware\ directory
+sub do_def_file
+{
+   # strip off the leading path
+   my($target) = bname(shift);
+   my($i);
+
+   if ($target =~ /(.*).nlm/)
+   {
+      $target = $1;
+   }
+
+   # special case for openssl - the mk1mf.pl defines E_EXE = openssl
+   if ($target =~ /E_EXE/)
+   {
+      $target =~ s/\$\(E_EXE\)/openssl/;
+   }
+
+   # Note: originally tried to use full path ( \openssl\netware\$target.def )
+   # Metrowerks linker choked on this with an assertion failure. bug???
+   #
+   my($def_file) = "netware${o}$target.def";
+
+   open(DEF_OUT, ">$def_file") || die("unable to open file $def_file\n");
+
+   print( DEF_OUT "# command file generated by netware.pl for NLM target.\n" );
+   print( DEF_OUT "# do not edit this file - all your changes will be lost!!\n" );
+   print( DEF_OUT "#\n");
+   print( DEF_OUT "DESCRIPTION \"$target ($libarch) - OpenSSL $nlmverstr\"\n");
+   print( DEF_OUT "COPYRIGHT \"$nlmcpystr\"\n");
+   print( DEF_OUT "VERSION $nlmvernum\n");
+   print( DEF_OUT "STACK $nlmstack\n");
+   print( DEF_OUT "START $nlmstart\n");
+   print( DEF_OUT "EXIT $nlmexit\n");
+
+   # special case for openssl
+   if ($target eq "openssl")
+   {
+      print( DEF_OUT "SCREENNAME \"OpenSSL $nlmverstr\"\n");
+   }
+   else
+   {
+      print( DEF_OUT "SCREENNAME \"DEFAULT\"\n");
+   }
+
+   foreach $i (@misc_imports)
+   {
+      print( DEF_OUT "IMPORT $i\n");
+   }
+
+   foreach $i (@import_files)
+   {
+      print( DEF_OUT "IMPORT \@$import_path${o}$i\n");
+   }
+
+   foreach $i (@module_files)
+   {
+      print( DEF_OUT "MODULE $i\n");
+   }
+
+   foreach $i (@nlm_flags)
+   {
+      print( DEF_OUT "$i\n");
+   }
+
+   if ($gnuc)
+   {
+      if ($target =~ /openssl/)
+      {
+         print( DEF_OUT "INPUT ${tmp_def}${o}openssl${obj}\n");
+         print( DEF_OUT "INPUT ${tmp_def}${o}openssl${libp}\n");
+      }
+      else
+      {
+         print( DEF_OUT "INPUT ${tmp_def}${o}${target}${obj}\n");
+      }
+      print( DEF_OUT "INPUT $prelude\n");
+      print( DEF_OUT "INPUT ${out_def}${o}${ssl}${libp} ${out_def}${o}${crypto}${libp}\n");
+      print( DEF_OUT "OUTPUT $target.nlm\n");
+   }
+
+   close(DEF_OUT);
+   return($def_file);
+}
+
+sub do_lib_rule
+{
+   my($objs,$target,$name,$shlib)=@_;
+   my($ret);
+
+   $ret.="$target: $objs\n";
+   if (!$shlib)
+   {
+      $ret.="\t\@echo Building Lib: $name\n";
+      $ret.="\t\$(MKLIB) $lib_flags $target $objs\n";
+      $ret.="\t\@echo .\n"
+   }
+   else
+   {
+      die( "Building as NLM not currently supported!" );
+   }
+
+   $ret.="\n";
+   return($ret);
+}
+
+sub do_link_rule
+{
+   my($target,$files,$dep_libs,$libs)=@_;
+   my($ret);
+   my($def_file) = do_def_file($target);
+
+   $ret.="$target: $files $dep_libs\n";
+
+   # NOTE:  When building the test nlms no screen name is given
+   #  which causes the console screen to be used.  By using the console
+   #  screen there is no "<press any key to continue>" message which
+   #  requires user interaction.  The test script ( do_tests.pl ) needs
+   #  to be able to run the tests without requiring user interaction.
+   #
+   #  However, the sample program "openssl.nlm" is used by the tests and is
+   #  a interactive sample so a screen is desired when not be run by the
+   #  tests.  To solve the problem, two versions of the program are built:
+   #    openssl2 - no screen used by tests
+   #    openssl - default screen - use for normal interactive modes
+   #
+
+   # special case for openssl - the mk1mf.pl defines E_EXE = openssl
+   if ($target =~ /E_EXE/)
+   {
+      my($target2) = $target;
+
+      $target2 =~ s/\(E_EXE\)/\(E_EXE\)2/;
+
+      # openssl2
+      my($def_file2) = do_def_file($target2);
+
+      if ($gnuc)
+      {
+         $ret.="\t\$(MKLIB) $lib_flags \$(TMP_D)${o}\$(E_EXE).a \$(filter-out \$(TMP_D)${o}\$(E_EXE)${obj},$files)\n";
+         $ret.="\t\$(LINK) \$(LFLAGS) $def_file2\n";
+         $ret.="\t\@$mv \$(E_EXE)2.nlm \$(TEST_D)\n";
+      }
+      else
+      {
+         $ret.="\t\$(LINK) \$(LFLAGS) $def_file2 $files \"$prelude\" $libs -o $target2\n";
+      }
+   }
+   if ($gnuc)
+   {
+      $ret.="\t\$(LINK) \$(LFLAGS) $def_file\n";
+      $ret.="\t\@$mv \$(\@F) \$(TEST_D)\n";
+   }
+   else
+   {
+      $ret.="\t\$(LINK) \$(LFLAGS) $def_file $files \"$prelude\" $libs -o $target\n";
+   }
+
+   $ret.="\n";
+   return($ret);
+
+}
+
+1;
diff --git a/deps/openssl/openssl/util/pl/ultrix.pl b/deps/openssl/openssl/util/pl/ultrix.pl
new file mode 100644 (file)
index 0000000..ea370c7
--- /dev/null
@@ -0,0 +1,38 @@
+#!/usr/local/bin/perl
+#
+# linux.pl - the standard unix makefile stuff.
+#
+
+$o='/';
+$cp='/bin/cp';
+$rm='/bin/rm -f';
+
+# C compiler stuff
+
+$cc='cc';
+if ($debug)
+       { $cflags="-g -DREF_CHECK -DCRYPTO_MDEBUG"; }
+else
+       { $cflags="-O2"; }
+
+$cflags.=" -std1 -DL_ENDIAN";
+
+if (!$no_asm)
+       {
+       $bn_asm_obj='$(OBJ_D)/mips1.o';
+       $bn_asm_src='crypto/bn/asm/mips1.s';
+       }
+
+sub do_link_rule
+       {
+       local($target,$files,$dep_libs,$libs)=@_;
+       local($ret,$_);
+       
+       $file =~ s/\//$o/g if $o ne '/';
+       $n=&bname($target);
+       $ret.="$target: $files $dep_libs\n";
+       $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n";
+       return($ret);
+       }
+
+1;
diff --git a/deps/openssl/openssl/util/pl/unix.pl b/deps/openssl/openssl/util/pl/unix.pl
new file mode 100644 (file)
index 0000000..146611a
--- /dev/null
@@ -0,0 +1,96 @@
+#!/usr/local/bin/perl
+#
+# unix.pl - the standard unix makefile stuff.
+#
+
+$o='/';
+$cp='/bin/cp';
+$rm='/bin/rm -f';
+
+# C compiler stuff
+
+if ($gcc)
+       {
+       $cc='gcc';
+       if ($debug)
+               { $cflags="-g2 -ggdb"; }
+       else
+               { $cflags="-O3 -fomit-frame-pointer"; }
+       }
+else
+       {
+       $cc='cc';
+       if ($debug)
+               { $cflags="-g"; }
+       else
+               { $cflags="-O"; }
+       }
+$obj='.o';
+$ofile='-o ';
+
+# EXE linking stuff
+$link='${CC}';
+$lflags='${CFLAGS}';
+$efile='-o ';
+$exep='';
+$ex_libs="";
+
+# static library stuff
+$mklib='ar r';
+$mlflags='';
+$ranlib=&which("ranlib") or $ranlib="true";
+$plib='lib';
+$libp=".a";
+$shlibp=".a";
+$lfile='';
+
+$asm='as';
+$afile='-o ';
+$bn_asm_obj="";
+$bn_asm_src="";
+$des_enc_obj="";
+$des_enc_src="";
+$bf_enc_obj="";
+$bf_enc_src="";
+
+sub do_lib_rule
+       {
+       local($obj,$target,$name,$shlib)=@_;
+       local($ret,$_,$Name);
+
+       $target =~ s/\//$o/g if $o ne '/';
+       $target="$target";
+       ($Name=$name) =~ tr/a-z/A-Z/;
+
+       $ret.="$target: \$(${Name}OBJ)\n";
+       $ret.="\t\$(RM) $target\n";
+       $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n";
+       $ret.="\t\$(RANLIB) $target\n\n";
+       }
+
+sub do_link_rule
+       {
+       local($target,$files,$dep_libs,$libs)=@_;
+       local($ret,$_);
+       
+       $file =~ s/\//$o/g if $o ne '/';
+       $n=&bname($target);
+       $ret.="$target: $files $dep_libs\n";
+       $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n";
+       return($ret);
+       }
+
+sub which
+       {
+       my ($name)=@_;
+       my $path;
+       foreach $path (split /:/, $ENV{PATH})
+               {
+               if (-x "$path/$name")
+                       {
+                       return "$path/$name";
+                       }
+               }
+       }
+
+1;
diff --git a/deps/openssl/openssl/util/pod2man.pl b/deps/openssl/openssl/util/pod2man.pl
new file mode 100755 (executable)
index 0000000..025d914
--- /dev/null
@@ -0,0 +1,1184 @@
+: #!/usr/bin/perl-5.005
+    eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
+       if $running_under_some_shell;
+
+$DEF_PM_SECTION = '3pm' || '3';
+
+=head1 NAME
+
+pod2man - translate embedded Perl pod directives into man pages
+
+=head1 SYNOPSIS
+
+B<pod2man>
+[ B<--section=>I<manext> ]
+[ B<--release=>I<relpatch> ]
+[ B<--center=>I<string> ]
+[ B<--date=>I<string> ]
+[ B<--fixed=>I<font> ]
+[ B<--official> ]
+[ B<--lax> ]
+I<inputfile>
+
+=head1 DESCRIPTION
+
+B<pod2man> converts its input file containing embedded pod directives (see
+L<perlpod>) into nroff source suitable for viewing with nroff(1) or
+troff(1) using the man(7) macro set.
+
+Besides the obvious pod conversions, B<pod2man> also takes care of
+func(), func(n), and simple variable references like $foo or @bar so
+you don't have to use code escapes for them; complex expressions like
+C<$fred{'stuff'}> will still need to be escaped, though.  Other nagging
+little roffish things that it catches include translating the minus in
+something like foo-bar, making a long dash--like this--into a real em
+dash, fixing up "paired quotes", putting a little space after the
+parens in something like func(), making C++ and PI look right, making
+double underbars have a little tiny space between them, making ALLCAPS
+a teeny bit smaller in troff(1), and escaping backslashes so you don't
+have to.
+
+=head1 OPTIONS
+
+=over 8
+
+=item center
+
+Set the centered header to a specific string.  The default is
+"User Contributed Perl Documentation", unless the C<--official> flag is
+given, in which case the default is "Perl Programmers Reference Guide".
+
+=item date
+
+Set the left-hand footer string to this value.  By default,
+the modification date of the input file will be used.
+
+=item fixed
+
+The fixed font to use for code refs.  Defaults to CW.
+
+=item official
+
+Set the default header to indicate that this page is of
+the standard release in case C<--center> is not given.
+
+=item release
+
+Set the centered footer.  By default, this is the current
+perl release.
+
+=item section
+
+Set the section for the C<.TH> macro.  The standard conventions on
+sections are to use 1 for user commands,  2 for system calls, 3 for
+functions, 4 for devices, 5 for file formats, 6 for games, 7 for
+miscellaneous information, and 8 for administrator commands.  This works
+best if you put your Perl man pages in a separate tree, like
+F</usr/local/perl/man/>.  By default, section 1 will be used
+unless the file ends in F<.pm> in which case section 3 will be selected.
+
+=item lax
+
+Don't complain when required sections aren't present.
+
+=back
+
+=head1 Anatomy of a Proper Man Page
+
+For those not sure of the proper layout of a man page, here's
+an example of the skeleton of a proper man page.  Head of the
+major headers should be setout as a C<=head1> directive, and
+are historically written in the rather startling ALL UPPER CASE
+format, although this is not mandatory.
+Minor headers may be included using C<=head2>, and are
+typically in mixed case.
+
+=over 10
+
+=item NAME
+
+Mandatory section; should be a comma-separated list of programs or
+functions documented by this podpage, such as:
+
+    foo, bar - programs to do something
+
+=item SYNOPSIS
+
+A short usage summary for programs and functions, which
+may someday be deemed mandatory.
+
+=item DESCRIPTION
+
+Long drawn out discussion of the program.  It's a good idea to break this
+up into subsections using the C<=head2> directives, like
+
+    =head2 A Sample Subection
+
+    =head2 Yet Another Sample Subection
+
+=item OPTIONS
+
+Some people make this separate from the description.
+
+=item RETURN VALUE
+
+What the program or function returns if successful.
+
+=item ERRORS
+
+Exceptions, return codes, exit stati, and errno settings.
+
+=item EXAMPLES
+
+Give some example uses of the program.
+
+=item ENVIRONMENT
+
+Envariables this program might care about.
+
+=item FILES
+
+All files used by the program.  You should probably use the FE<lt>E<gt>
+for these.
+
+=item SEE ALSO
+
+Other man pages to check out, like man(1), man(7), makewhatis(8), or catman(8).
+
+=item NOTES
+
+Miscellaneous commentary.
+
+=item CAVEATS
+
+Things to take special care with; sometimes called WARNINGS.
+
+=item DIAGNOSTICS
+
+All possible messages the program can print out--and
+what they mean.
+
+=item BUGS
+
+Things that are broken or just don't work quite right.
+
+=item RESTRICTIONS
+
+Bugs you don't plan to fix :-)
+
+=item AUTHOR
+
+Who wrote it (or AUTHORS if multiple).
+
+=item HISTORY
+
+Programs derived from other sources sometimes have this, or
+you might keep a modification log here.
+
+=back
+
+=head1 EXAMPLES
+
+    pod2man program > program.1
+    pod2man some_module.pm > /usr/perl/man/man3/some_module.3
+    pod2man --section=7 note.pod > note.7
+
+=head1 DIAGNOSTICS
+
+The following diagnostics are generated by B<pod2man>.  Items
+marked "(W)" are non-fatal, whereas the "(F)" errors will cause
+B<pod2man> to immediately exit with a non-zero status.
+
+=over 4
+
+=item bad option in paragraph %d of %s: ``%s'' should be [%s]<%s>
+
+(W) If you start include an option, you should set it off
+as bold, italic, or code.
+
+=item can't open %s: %s
+
+(F) The input file wasn't available for the given reason.
+
+=item Improper man page - no dash in NAME header in paragraph %d of %s
+
+(W) The NAME header did not have an isolated dash in it.  This is
+considered important.
+
+=item Invalid man page - no NAME line in %s
+
+(F) You did not include a NAME header, which is essential.
+
+=item roff font should be 1 or 2 chars, not `%s'  (F)
+
+(F) The font specified with the C<--fixed> option was not
+a one- or two-digit roff font.
+
+=item %s is missing required section: %s
+
+(W) Required sections include NAME, DESCRIPTION, and if you're
+using a section starting with a 3, also a SYNOPSIS.  Actually,
+not having a NAME is a fatal.
+
+=item Unknown escape: %s in %s
+
+(W) An unknown HTML entity (probably for an 8-bit character) was given via
+a C<EE<lt>E<gt>> directive.  Besides amp, lt, gt, and quot, recognized
+entities are Aacute, aacute, Acirc, acirc, AElig, aelig, Agrave, agrave,
+Aring, aring, Atilde, atilde, Auml, auml, Ccedil, ccedil, Eacute, eacute,
+Ecirc, ecirc, Egrave, egrave, ETH, eth, Euml, euml, Iacute, iacute, Icirc,
+icirc, Igrave, igrave, Iuml, iuml, Ntilde, ntilde, Oacute, oacute, Ocirc,
+ocirc, Ograve, ograve, Oslash, oslash, Otilde, otilde, Ouml, ouml, szlig,
+THORN, thorn, Uacute, uacute, Ucirc, ucirc, Ugrave, ugrave, Uuml, uuml,
+Yacute, yacute, and yuml.
+
+=item Unmatched =back
+
+(W) You have a C<=back> without a corresponding C<=over>.
+
+=item Unrecognized pod directive: %s
+
+(W) You specified a pod directive that isn't in the known list of
+C<=head1>, C<=head2>, C<=item>, C<=over>, C<=back>, or C<=cut>.
+
+
+=back
+
+=head1 NOTES
+
+If you would like to print out a lot of man page continuously, you
+probably want to set the C and D registers to set contiguous page
+numbering and even/odd paging, at least on some versions of man(7).
+Settting the F register will get you some additional experimental
+indexing:
+
+    troff -man -rC1 -rD1 -rF1 perl.1 perldata.1 perlsyn.1 ...
+
+The indexing merely outputs messages via C<.tm> for each
+major page, section, subsection, item, and any C<XE<lt>E<gt>>
+directives.
+
+
+=head1 RESTRICTIONS
+
+None at this time.
+
+=head1 BUGS
+
+The =over and =back directives don't really work right.  They
+take absolute positions instead of offsets, don't nest well, and
+making people count is suboptimal in any event.
+
+=head1 AUTHORS
+
+Original prototype by Larry Wall, but so massively hacked over by
+Tom Christiansen such that Larry probably doesn't recognize it anymore.
+
+=cut
+
+$/ = "";
+$cutting = 1;
+@Indices = ();
+
+# We try first to get the version number from a local binary, in case we're
+# running an installed version of Perl to produce documentation from an
+# uninstalled newer version's pod files.
+if ($^O ne 'plan9' and $^O ne 'dos' and $^O ne 'os2' and $^O ne 'MSWin32') {
+  my $perl = (-x './perl' && -f './perl' ) ?
+                 './perl' :
+                 ((-x '../perl' && -f '../perl') ?
+                      '../perl' :
+                      '');
+  ($version,$patch) = `$perl -e 'print $]'` =~ /^(\d\.\d{3})(\d{2})?/ if $perl;
+}
+# No luck; we'll just go with the running Perl's version
+($version,$patch) = $] =~ /^(.{5})(\d{2})?/ unless $version;
+$DEF_RELEASE  = "perl $version";
+$DEF_RELEASE .= ", patch $patch" if $patch;
+
+
+sub makedate {
+    my $secs = shift;
+    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($secs);
+    my $mname = (qw{Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec})[$mon];
+    $year += 1900;
+    return "$mday/$mname/$year";
+}
+
+use Getopt::Long;
+
+$DEF_SECTION = 1;
+$DEF_CENTER = "User Contributed Perl Documentation";
+$STD_CENTER = "Perl Programmers Reference Guide";
+$DEF_FIXED = 'CW';
+$DEF_LAX = 0;
+
+sub usage {
+    warn "$0: @_\n" if @_;
+    die <<EOF;
+usage: $0 [options] podpage
+Options are:
+       --section=manext      (default "$DEF_SECTION")
+       --release=relpatch    (default "$DEF_RELEASE")
+       --center=string       (default "$DEF_CENTER")
+       --date=string         (default "$DEF_DATE")
+       --fixed=font          (default "$DEF_FIXED")
+       --official            (default NOT)
+       --lax                 (default NOT)
+EOF
+}
+
+$uok = GetOptions( qw(
+       section=s
+       release=s
+       center=s
+       date=s
+       fixed=s
+       official
+       lax
+       help));
+
+$DEF_DATE = makedate((stat($ARGV[0]))[9] || time());
+
+usage("Usage error!") unless $uok;
+usage() if $opt_help;
+usage("Need one and only one podpage argument") unless @ARGV == 1;
+
+$section = $opt_section || ($ARGV[0] =~ /\.pm$/
+                               ? $DEF_PM_SECTION : $DEF_SECTION);
+$RP = $opt_release || $DEF_RELEASE;
+$center = $opt_center || ($opt_official ? $STD_CENTER : $DEF_CENTER);
+$lax = $opt_lax || $DEF_LAX;
+
+$CFont = $opt_fixed || $DEF_FIXED;
+
+if (length($CFont) == 2) {
+    $CFont_embed = "\\f($CFont";
+}
+elsif (length($CFont) == 1) {
+    $CFont_embed = "\\f$CFont";
+}
+else {
+    die "roff font should be 1 or 2 chars, not `$CFont_embed'";
+}
+
+$date = $opt_date || $DEF_DATE;
+
+for (qw{NAME DESCRIPTION}) {
+# for (qw{NAME DESCRIPTION AUTHOR}) {
+    $wanna_see{$_}++;
+}
+$wanna_see{SYNOPSIS}++ if $section =~ /^3/;
+
+
+$name = @ARGV ? $ARGV[0] : "<STDIN>";
+$Filename = $name;
+if ($section =~ /^1/) {
+    require File::Basename;
+    $name = uc File::Basename::basename($name);
+}
+$name =~ s/\.(pod|p[lm])$//i;
+
+# Lose everything up to the first of
+#     */lib/*perl*     standard or site_perl module
+#     */*perl*/lib     from -D prefix=/opt/perl
+#     */*perl*/                random module hierarchy
+# which works.
+$name =~ s-//+-/-g;
+if ($name =~ s-^.*?/lib/[^/]*perl[^/]*/--i
+       or $name =~ s-^.*?/[^/]*perl[^/]*/lib/--i
+       or $name =~ s-^.*?/[^/]*perl[^/]*/--i) {
+    # Lose ^site(_perl)?/.
+    $name =~ s-^site(_perl)?/--;
+    # Lose ^arch/.     (XXX should we use Config? Just for archname?)
+    $name =~ s~^(.*-$^O|$^O-.*)/~~o;
+    # Lose ^version/.
+    $name =~ s-^\d+\.\d+/--;
+}
+
+# Translate Getopt/Long to Getopt::Long, etc.
+$name =~ s(/)(::)g;
+
+if ($name ne 'something') {
+    FCHECK: {
+       open(F, "< $ARGV[0]") || die "can't open $ARGV[0]: $!";
+       while (<F>) {
+           next unless /^=\b/;
+           if (/^=head1\s+NAME\s*$/) {  # an /m would forgive mistakes
+               $_ = <F>;
+               unless (/\s*-+\s+/) {
+                   $oops++;
+                   warn "$0: Improper man page - no dash in NAME header in paragraph $. of $ARGV[0]\n"
+                } else {
+                   my @n = split /\s+-+\s+/;
+                   if (@n != 2) {
+                       $oops++;
+                       warn "$0: Improper man page - malformed NAME header in paragraph $. of $ARGV[0]\n"
+                   }
+                   else {
+                       $n[0] =~ s/\n/ /g;
+                       $n[1] =~ s/\n/ /g;
+                       %namedesc = @n;
+                   }
+               }
+               last FCHECK;
+           }
+           next if /^=cut\b/;  # DB_File and Net::Ping have =cut before NAME
+           next if /^=pod\b/;  # It is OK to have =pod before NAME
+           next if /^=(for|begin|end)\s+comment\b/;  # It is OK to have =for =begin or =end comment before NAME
+           die "$0: Invalid man page - 1st pod line is not NAME in $ARGV[0]\n" unless $lax;
+       }
+       die "$0: Invalid man page - no documentation in $ARGV[0]\n" unless $lax;
+    }
+    close F;
+}
+
+print <<"END";
+.rn '' }`
+''' \$RCSfile\$\$Revision\$\$Date\$
+'''
+''' \$Log\$
+'''
+.de Sh
+.br
+.if t .Sp
+.ne 5
+.PP
+\\fB\\\\\$1\\fR
+.PP
+..
+.de Sp
+.if t .sp .5v
+.if n .sp
+..
+.de Ip
+.br
+.ie \\\\n(.\$>=3 .ne \\\\\$3
+.el .ne 3
+.IP "\\\\\$1" \\\\\$2
+..
+.de Vb
+.ft $CFont
+.nf
+.ne \\\\\$1
+..
+.de Ve
+.ft R
+
+.fi
+..
+'''
+'''
+'''     Set up \\*(-- to give an unbreakable dash;
+'''     string Tr holds user defined translation string.
+'''     Bell System Logo is used as a dummy character.
+'''
+.tr \\(*W-|\\(bv\\*(Tr
+.ie n \\{\\
+.ds -- \\(*W-
+.ds PI pi
+.if (\\n(.H=4u)&(1m=24u) .ds -- \\(*W\\h'-12u'\\(*W\\h'-12u'-\\" diablo 10 pitch
+.if (\\n(.H=4u)&(1m=20u) .ds -- \\(*W\\h'-12u'\\(*W\\h'-8u'-\\" diablo 12 pitch
+.ds L" ""
+.ds R" ""
+'''   \\*(M", \\*(S", \\*(N" and \\*(T" are the equivalent of
+'''   \\*(L" and \\*(R", except that they are used on ".xx" lines,
+'''   such as .IP and .SH, which do another additional levels of
+'''   double-quote interpretation
+.ds M" """
+.ds S" """
+.ds N" """""
+.ds T" """""
+.ds L' '
+.ds R' '
+.ds M' '
+.ds S' '
+.ds N' '
+.ds T' '
+'br\\}
+.el\\{\\
+.ds -- \\(em\\|
+.tr \\*(Tr
+.ds L" ``
+.ds R" ''
+.ds M" ``
+.ds S" ''
+.ds N" ``
+.ds T" ''
+.ds L' `
+.ds R' '
+.ds M' `
+.ds S' '
+.ds N' `
+.ds T' '
+.ds PI \\(*p
+'br\\}
+END
+
+print <<'END';
+.\"    If the F register is turned on, we'll generate
+.\"    index entries out stderr for the following things:
+.\"            TH      Title 
+.\"            SH      Header
+.\"            Sh      Subsection 
+.\"            Ip      Item
+.\"            X<>     Xref  (embedded
+.\"    Of course, you have to process the output yourself
+.\"    in some meaninful fashion.
+.if \nF \{
+.de IX
+.tm Index:\\$1\t\\n%\t"\\$2"
+..
+.nr % 0
+.rr F
+.\}
+END
+
+print <<"END";
+.TH $name $section "$RP" "$date" "$center"
+.UC
+END
+
+push(@Indices, qq{.IX Title "$name $section"});
+
+while (($name, $desc) = each %namedesc) {
+    for ($name, $desc) { s/^\s+//; s/\s+$//; }
+    push(@Indices, qq(.IX Name "$name - $desc"\n));
+}
+
+print <<'END';
+.if n .hy 0
+.if n .na
+.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
+.de CQ          \" put $1 in typewriter font
+END
+print ".ft $CFont\n";
+print <<'END';
+'if n "\c
+'if t \\&\\$1\c
+'if n \\&\\$1\c
+'if n \&"
+\\&\\$2 \\$3 \\$4 \\$5 \\$6 \\$7
+'.ft R
+..
+.\" @(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2
+.      \" AM - accent mark definitions
+.bd B 3
+.      \" fudge factors for nroff and troff
+.if n \{\
+.      ds #H 0
+.      ds #V .8m
+.      ds #F .3m
+.      ds #[ \f1
+.      ds #] \fP
+.\}
+.if t \{\
+.      ds #H ((1u-(\\\\n(.fu%2u))*.13m)
+.      ds #V .6m
+.      ds #F 0
+.      ds #[ \&
+.      ds #] \&
+.\}
+.      \" simple accents for nroff and troff
+.if n \{\
+.      ds ' \&
+.      ds ` \&
+.      ds ^ \&
+.      ds , \&
+.      ds ~ ~
+.      ds ? ?
+.      ds ! !
+.      ds /
+.      ds q
+.\}
+.if t \{\
+.      ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
+.      ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
+.      ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
+.      ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
+.      ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
+.      ds ? \s-2c\h'-\w'c'u*7/10'\u\h'\*(#H'\zi\d\s+2\h'\w'c'u*8/10'
+.      ds ! \s-2\(or\s+2\h'-\w'\(or'u'\v'-.8m'.\v'.8m'
+.      ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
+.      ds q o\h'-\w'o'u*8/10'\s-4\v'.4m'\z\(*i\v'-.4m'\s+4\h'\w'o'u*8/10'
+.\}
+.      \" troff and (daisy-wheel) nroff accents
+.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
+.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
+.ds v \\k:\h'-(\\n(.wu*9/10-\*(#H)'\v'-\*(#V'\*(#[\s-4v\s0\v'\*(#V'\h'|\\n:u'\*(#]
+.ds _ \\k:\h'-(\\n(.wu*9/10-\*(#H+(\*(#F*2/3))'\v'-.4m'\z\(hy\v'.4m'\h'|\\n:u'
+.ds . \\k:\h'-(\\n(.wu*8/10)'\v'\*(#V*4/10'\z.\v'-\*(#V*4/10'\h'|\\n:u'
+.ds 3 \*(#[\v'.2m'\s-2\&3\s0\v'-.2m'\*(#]
+.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
+.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
+.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
+.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
+.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
+.ds ae a\h'-(\w'a'u*4/10)'e
+.ds Ae A\h'-(\w'A'u*4/10)'E
+.ds oe o\h'-(\w'o'u*4/10)'e
+.ds Oe O\h'-(\w'O'u*4/10)'E
+.      \" corrections for vroff
+.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
+.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
+.      \" for low resolution devices (crt and lpr)
+.if \n(.H>23 .if \n(.V>19 \
+\{\
+.      ds : e
+.      ds 8 ss
+.      ds v \h'-1'\o'\(aa\(ga'
+.      ds _ \h'-1'^
+.      ds . \h'-1'.
+.      ds 3 3
+.      ds o a
+.      ds d- d\h'-1'\(ga
+.      ds D- D\h'-1'\(hy
+.      ds th \o'bp'
+.      ds Th \o'LP'
+.      ds ae ae
+.      ds Ae AE
+.      ds oe oe
+.      ds Oe OE
+.\}
+.rm #[ #] #H #V #F C
+END
+
+$indent = 0;
+
+$begun = "";
+
+# Unrolling [^A-Z>]|[A-Z](?!<) gives:    // MRE pp 165.
+my $nonest = '(?:[^A-Z>]*(?:[A-Z](?!<)[^A-Z>]*)*)';
+
+while (<>) {
+    if ($cutting) {
+       next unless /^=/;
+       $cutting = 0;
+    }
+    if ($begun) {
+       if (/^=end\s+$begun/) {
+            $begun = "";
+       }
+       elsif ($begun =~ /^(roff|man)$/) {
+           print STDOUT $_;
+        }
+       next;
+    }
+    chomp;
+
+    # Translate verbatim paragraph
+
+    if (/^\s/) {
+       @lines = split(/\n/);
+       for (@lines) {
+           1 while s
+               {^( [^\t]* ) \t ( \t* ) }
+               { $1 . ' ' x (8 - (length($1)%8) + 8 * (length($2))) }ex;
+           s/\\/\\e/g;
+           s/\A/\\&/s;
+       }
+       $lines = @lines;
+       makespace() unless $verbatim++;
+       print ".Vb $lines\n";
+       print join("\n", @lines), "\n";
+       print ".Ve\n";
+       $needspace = 0;
+       next;
+    }
+
+    $verbatim = 0;
+
+    if (/^=for\s+(\S+)\s*/s) {
+       if ($1 eq "man" or $1 eq "roff") {
+           print STDOUT $',"\n\n";
+       } else {
+           # ignore unknown for
+       }
+       next;
+    }
+    elsif (/^=begin\s+(\S+)\s*/s) {
+       $begun = $1;
+       if ($1 eq "man" or $1 eq "roff") {
+           print STDOUT $'."\n\n";
+       }
+       next;
+    }
+
+    # check for things that'll hosed our noremap scheme; affects $_
+    init_noremap();
+
+    if (!/^=item/) {
+
+       # trofficate backslashes; must do it before what happens below
+       s/\\/noremap('\\e')/ge;
+
+       # protect leading periods and quotes against *roff
+       # mistaking them for directives
+       s/^(?:[A-Z]<)?[.']/\\&$&/gm;
+
+       # first hide the escapes in case we need to
+       # intuit something and get it wrong due to fmting
+
+       1 while s/([A-Z]<$nonest>)/noremap($1)/ge;
+
+       # func() is a reference to a perl function
+       s{
+           \b
+           (
+               [:\w]+ \(\)
+           )
+       } {I<$1>}gx;
+
+       # func(n) is a reference to a perl function or a man page
+       s{
+           ([:\w]+)
+           (
+               \( [^\051]+ \)
+           )
+       } {I<$1>\\|$2}gx;
+
+       # convert simple variable references
+       s/(\s+)([\$\@%][\w:]+)(?!\()/${1}C<$2>/g;
+
+       if (m{ (
+                   [\-\w]+
+                   \(
+                       [^\051]*?
+                       [\@\$,]
+                       [^\051]*?
+                   \)
+               )
+           }x && $` !~ /([LCI]<[^<>]*|-)$/ && !/^=\w/)
+       {
+           warn "$0: bad option in paragraph $. of $ARGV: ``$1'' should be [LCI]<$1>\n";
+           $oops++;
+       }
+
+       while (/(-[a-zA-Z])\b/g && $` !~ /[\w\-]$/) {
+           warn "$0: bad option in paragraph $. of $ARGV: ``$1'' should be [CB]<$1>\n";
+           $oops++;
+       }
+
+       # put it back so we get the <> processed again;
+       clear_noremap(0); # 0 means leave the E's
+
+    } else {
+       # trofficate backslashes
+       s/\\/noremap('\\e')/ge;
+
+    }
+
+    # need to hide E<> first; they're processed in clear_noremap
+    s/(E<[^<>]+>)/noremap($1)/ge;
+
+
+    $maxnest = 10;
+    while ($maxnest-- && /[A-Z]</) {
+
+       # can't do C font here
+       s/([BI])<($nonest)>/font($1) . $2 . font('R')/eg;
+
+       # files and filelike refs in italics
+       s/F<($nonest)>/I<$1>/g;
+
+       # no break -- usually we want C<> for this
+       s/S<($nonest)>/nobreak($1)/eg;
+
+       # LREF: a la HREF L<show this text|man/section>
+       s:L<([^|>]+)\|[^>]+>:$1:g;
+
+       # LREF: a manpage(3f)
+       s:L<([a-zA-Z][^\s\/]+)(\([^\)]+\))?>:the I<$1>$2 manpage:g;
+
+       # LREF: an =item on another manpage
+       s{
+           L<
+               ([^/]+)
+               /
+               (
+                   [:\w]+
+                   (\(\))?
+               )
+           >
+       } {the C<$2> entry in the I<$1> manpage}gx;
+
+       # LREF: an =item on this manpage
+       s{
+          ((?:
+           L<
+               /
+               (
+                   [:\w]+
+                   (\(\))?
+               )
+           >
+           (,?\s+(and\s+)?)?
+         )+)
+       } { internal_lrefs($1) }gex;
+
+       # LREF: a =head2 (head1?), maybe on a manpage, maybe right here
+       # the "func" can disambiguate
+       s{
+           L<
+               (?:
+                   ([a-zA-Z]\S+?) /
+               )?
+               "?(.*?)"?
+           >
+       }{
+           do {
+               $1      # if no $1, assume it means on this page.
+                   ?  "the section on I<$2> in the I<$1> manpage"
+                   :  "the section on I<$2>"
+           }
+       }gesx; # s in case it goes over multiple lines, so . matches \n
+
+       s/Z<>/\\&/g;
+
+       # comes last because not subject to reprocessing
+       s/C<($nonest)>/noremap("${CFont_embed}${1}\\fR")/eg;
+    }
+
+    if (s/^=//) {
+       $needspace = 0;         # Assume this.
+
+       s/\n/ /g;
+
+       ($Cmd, $_) = split(' ', $_, 2);
+
+       $dotlevel = 1;
+       if ($Cmd eq 'head1') {
+          $dotlevel = 1;
+       }
+       elsif ($Cmd eq 'head2') {
+          $dotlevel = 1;
+       }
+       elsif ($Cmd eq 'item') {
+          $dotlevel = 2;
+       }
+
+       if (defined $_) {
+           &escapes($dotlevel);
+           s/"/""/g;
+       }
+
+       clear_noremap(1);
+
+       if ($Cmd eq 'cut') {
+           $cutting = 1;
+       }
+       elsif ($Cmd eq 'head1') {
+           s/\s+$//;
+           delete $wanna_see{$_} if exists $wanna_see{$_};
+           print qq{.SH "$_"\n};
+      push(@Indices, qq{.IX Header "$_"\n});
+       }
+       elsif ($Cmd eq 'head2') {
+           print qq{.Sh "$_"\n};
+      push(@Indices, qq{.IX Subsection "$_"\n});
+       }
+       elsif ($Cmd eq 'over') {
+           push(@indent,$indent);
+           $indent += ($_ + 0) || 5;
+       }
+       elsif ($Cmd eq 'back') {
+           $indent = pop(@indent);
+           warn "$0: Unmatched =back in paragraph $. of $ARGV\n" unless defined $indent;
+           $needspace = 1;
+       }
+       elsif ($Cmd eq 'item') {
+           s/^\*( |$)/\\(bu$1/g;
+           # if you know how to get ":s please do
+           s/\\\*\(L"([^"]+?)\\\*\(R"/'$1'/g;
+           s/\\\*\(L"([^"]+?)""/'$1'/g;
+           s/[^"]""([^"]+?)""[^"]/'$1'/g;
+           # here do something about the $" in perlvar?
+           print STDOUT qq{.Ip "$_" $indent\n};
+      push(@Indices, qq{.IX Item "$_"\n});
+       }
+       elsif ($Cmd eq 'pod') {
+           # this is just a comment
+       } 
+       else {
+           warn "$0: Unrecognized pod directive in paragraph $. of $ARGV: $Cmd\n";
+       }
+    }
+    else {
+       if ($needspace) {
+           &makespace;
+       }
+       &escapes(0);
+       clear_noremap(1);
+       print $_, "\n";
+       $needspace = 1;
+    }
+}
+
+print <<"END";
+
+.rn }` ''
+END
+
+if (%wanna_see && !$lax) {
+    @missing = keys %wanna_see;
+    warn "$0: $Filename is missing required section"
+       .  (@missing > 1 && "s")
+       .  ": @missing\n";
+    $oops++;
+}
+
+foreach (@Indices) { print "$_\n"; }
+
+exit;
+#exit ($oops != 0);
+
+#########################################################################
+
+sub nobreak {
+    my $string = shift;
+    $string =~ s/ /\\ /g;
+    $string;
+}
+
+sub escapes {
+    my $indot = shift;
+
+    s/X<(.*?)>/mkindex($1)/ge;
+
+    # translate the minus in foo-bar into foo\-bar for roff
+    s/([^0-9a-z-])-([^-])/$1\\-$2/g;
+
+    # make -- into the string version \*(-- (defined above)
+    s/\b--\b/\\*(--/g;
+    s/"--([^"])/"\\*(--$1/g;  # should be a better way
+    s/([^"])--"/$1\\*(--"/g;
+
+    # fix up quotes; this is somewhat tricky
+    my $dotmacroL = 'L';
+    my $dotmacroR = 'R';
+    if ( $indot == 1 ) {
+       $dotmacroL = 'M';
+       $dotmacroR = 'S';
+    }  
+    elsif ( $indot >= 2 ) {
+       $dotmacroL = 'N';
+       $dotmacroR = 'T';
+    }  
+    if (!/""/) {
+       s/(^|\s)(['"])/noremap("$1\\*($dotmacroL$2")/ge;
+       s/(['"])($|[\-\s,;\\!?.])/noremap("\\*($dotmacroR$1$2")/ge;
+    }
+
+    #s/(?!")(?:.)--(?!")(?:.)/\\*(--/g;
+    #s/(?:(?!")(?:.)--(?:"))|(?:(?:")--(?!")(?:.))/\\*(--/g;
+
+
+    # make sure that func() keeps a bit a space tween the parens
+    ### s/\b\(\)/\\|()/g;
+    ### s/\b\(\)/(\\|)/g;
+
+    # make C++ into \*C+, which is a squinched version (defined above)
+    s/\bC\+\+/\\*(C+/g;
+
+    # make double underbars have a little tiny space between them
+    s/__/_\\|_/g;
+
+    # PI goes to \*(PI (defined above)
+    s/\bPI\b/noremap('\\*(PI')/ge;
+
+    # make all caps a teeny bit smaller, but don't muck with embedded code literals
+    my $hidCFont = font('C');
+    if ($Cmd !~ /^head1/) { # SH already makes smaller
+       # /g isn't enough; 1 while or we'll be off
+
+#      1 while s{
+#          (?!$hidCFont)(..|^.|^)
+#          \b
+#          (
+#              [A-Z][\/A-Z+:\-\d_$.]+
+#          )
+#          (s?)                
+#          \b
+#      } {$1\\s-1$2\\s0}gmox;
+
+       1 while s{
+           (?!$hidCFont)(..|^.|^)
+           (
+               \b[A-Z]{2,}[\/A-Z+:\-\d_\$]*\b
+           )
+       } {
+           $1 . noremap( '\\s-1' .  $2 . '\\s0' )
+       }egmox;
+
+    }
+}
+
+# make troff just be normal, but make small nroff get quoted
+# decided to just put the quotes in the text; sigh;
+sub ccvt {
+    local($_,$prev) = @_;
+    noremap(qq{.CQ "$_" \n\\&});
+}
+
+sub makespace {
+    if ($indent) {
+       print ".Sp\n";
+    }
+    else {
+       print ".PP\n";
+    }
+}
+
+sub mkindex {
+    my ($entry) = @_;
+    my @entries = split m:\s*/\s*:, $entry;
+    push @Indices, ".IX Xref " . join ' ', map {qq("$_")} @entries;
+    return '';
+}
+
+sub font {
+    local($font) = shift;
+    return '\\f' . noremap($font);
+}
+
+sub noremap {
+    local($thing_to_hide) = shift;
+    $thing_to_hide =~ tr/\000-\177/\200-\377/;
+    return $thing_to_hide;
+}
+
+sub init_noremap {
+       # escape high bit characters in input stream
+       s/([\200-\377])/"E<".ord($1).">"/ge;
+}
+
+sub clear_noremap {
+    my $ready_to_print = $_[0];
+
+    tr/\200-\377/\000-\177/;
+
+    # trofficate backslashes
+    # s/(?!\\e)(?:..|^.|^)\\/\\e/g;
+
+    # now for the E<>s, which have been hidden until now
+    # otherwise the interative \w<> processing would have
+    # been hosed by the E<gt>
+    s {
+           E<
+           (
+               ( \d + ) 
+               | ( [A-Za-z]+ ) 
+           )
+           >   
+    } {
+        do {
+            defined $2
+               ? chr($2)
+               :       
+            exists $HTML_Escapes{$3}
+               ? do { $HTML_Escapes{$3} }
+               : do {
+                   warn "$0: Unknown escape in paragraph $. of $ARGV: ``$&''\n";
+                   "E<$1>";
+               }
+        }
+    }egx if $ready_to_print;
+}
+
+sub internal_lrefs {
+    local($_) = shift;
+    local $trailing_and = s/and\s+$// ? "and " : "";
+
+    s{L</([^>]+)>}{$1}g;
+    my(@items) = split( /(?:,?\s+(?:and\s+)?)/ );
+    my $retstr = "the ";
+    my $i;
+    for ($i = 0; $i <= $#items; $i++) {
+       $retstr .= "C<$items[$i]>";
+       $retstr .= ", " if @items > 2 && $i != $#items;
+       $retstr .= " and " if $i+2 == @items;
+    }
+
+    $retstr .= " entr" . ( @items > 1  ? "ies" : "y" )
+           .  " elsewhere in this document";
+    # terminal space to avoid words running together (pattern used
+    # strips terminal spaces)
+    $retstr .= " " if length $trailing_and;
+    $retstr .=  $trailing_and;
+
+    return $retstr;
+
+}
+
+BEGIN {
+%HTML_Escapes = (
+    'amp'      =>      '&',    #   ampersand
+    'lt'       =>      '<',    #   left chevron, less-than
+    'gt'       =>      '>',    #   right chevron, greater-than
+    'quot'     =>      '"',    #   double quote
+
+    "Aacute"   =>      "A\\*'",        #   capital A, acute accent
+    "aacute"   =>      "a\\*'",        #   small a, acute accent
+    "Acirc"    =>      "A\\*^",        #   capital A, circumflex accent
+    "acirc"    =>      "a\\*^",        #   small a, circumflex accent
+    "AElig"    =>      '\*(AE',        #   capital AE diphthong (ligature)
+    "aelig"    =>      '\*(ae',        #   small ae diphthong (ligature)
+    "Agrave"   =>      "A\\*`",        #   capital A, grave accent
+    "agrave"   =>      "A\\*`",        #   small a, grave accent
+    "Aring"    =>      'A\\*o',        #   capital A, ring
+    "aring"    =>      'a\\*o',        #   small a, ring
+    "Atilde"   =>      'A\\*~',        #   capital A, tilde
+    "atilde"   =>      'a\\*~',        #   small a, tilde
+    "Auml"     =>      'A\\*:',        #   capital A, dieresis or umlaut mark
+    "auml"     =>      'a\\*:',        #   small a, dieresis or umlaut mark
+    "Ccedil"   =>      'C\\*,',        #   capital C, cedilla
+    "ccedil"   =>      'c\\*,',        #   small c, cedilla
+    "Eacute"   =>      "E\\*'",        #   capital E, acute accent
+    "eacute"   =>      "e\\*'",        #   small e, acute accent
+    "Ecirc"    =>      "E\\*^",        #   capital E, circumflex accent
+    "ecirc"    =>      "e\\*^",        #   small e, circumflex accent
+    "Egrave"   =>      "E\\*`",        #   capital E, grave accent
+    "egrave"   =>      "e\\*`",        #   small e, grave accent
+    "ETH"      =>      '\\*(D-',       #   capital Eth, Icelandic
+    "eth"      =>      '\\*(d-',       #   small eth, Icelandic
+    "Euml"     =>      "E\\*:",        #   capital E, dieresis or umlaut mark
+    "euml"     =>      "e\\*:",        #   small e, dieresis or umlaut mark
+    "Iacute"   =>      "I\\*'",        #   capital I, acute accent
+    "iacute"   =>      "i\\*'",        #   small i, acute accent
+    "Icirc"    =>      "I\\*^",        #   capital I, circumflex accent
+    "icirc"    =>      "i\\*^",        #   small i, circumflex accent
+    "Igrave"   =>      "I\\*`",        #   capital I, grave accent
+    "igrave"   =>      "i\\*`",        #   small i, grave accent
+    "Iuml"     =>      "I\\*:",        #   capital I, dieresis or umlaut mark
+    "iuml"     =>      "i\\*:",        #   small i, dieresis or umlaut mark
+    "Ntilde"   =>      'N\*~',         #   capital N, tilde
+    "ntilde"   =>      'n\*~',         #   small n, tilde
+    "Oacute"   =>      "O\\*'",        #   capital O, acute accent
+    "oacute"   =>      "o\\*'",        #   small o, acute accent
+    "Ocirc"    =>      "O\\*^",        #   capital O, circumflex accent
+    "ocirc"    =>      "o\\*^",        #   small o, circumflex accent
+    "Ograve"   =>      "O\\*`",        #   capital O, grave accent
+    "ograve"   =>      "o\\*`",        #   small o, grave accent
+    "Oslash"   =>      "O\\*/",        #   capital O, slash
+    "oslash"   =>      "o\\*/",        #   small o, slash
+    "Otilde"   =>      "O\\*~",        #   capital O, tilde
+    "otilde"   =>      "o\\*~",        #   small o, tilde
+    "Ouml"     =>      "O\\*:",        #   capital O, dieresis or umlaut mark
+    "ouml"     =>      "o\\*:",        #   small o, dieresis or umlaut mark
+    "szlig"    =>      '\*8',          #   small sharp s, German (sz ligature)
+    "THORN"    =>      '\\*(Th',       #   capital THORN, Icelandic
+    "thorn"    =>      '\\*(th',,      #   small thorn, Icelandic
+    "Uacute"   =>      "U\\*'",        #   capital U, acute accent
+    "uacute"   =>      "u\\*'",        #   small u, acute accent
+    "Ucirc"    =>      "U\\*^",        #   capital U, circumflex accent
+    "ucirc"    =>      "u\\*^",        #   small u, circumflex accent
+    "Ugrave"   =>      "U\\*`",        #   capital U, grave accent
+    "ugrave"   =>      "u\\*`",        #   small u, grave accent
+    "Uuml"     =>      "U\\*:",        #   capital U, dieresis or umlaut mark
+    "uuml"     =>      "u\\*:",        #   small u, dieresis or umlaut mark
+    "Yacute"   =>      "Y\\*'",        #   capital Y, acute accent
+    "yacute"   =>      "y\\*'",        #   small y, acute accent
+    "yuml"     =>      "y\\*:",        #   small y, dieresis or umlaut mark
+);
+}
+
diff --git a/deps/openssl/openssl/util/pod2mantest b/deps/openssl/openssl/util/pod2mantest
new file mode 100755 (executable)
index 0000000..384e683
--- /dev/null
@@ -0,0 +1,58 @@
+#!/bin/sh
+
+# This script is used by test/Makefile to check whether a sane 'pod2man'
+# is installed.
+# ('make install' should not try to run 'pod2man' if it does not exist or if
+# it is a broken 'pod2man' version that is known to cause trouble. if we find
+# the system 'pod2man' to be broken, we use our own copy instead)
+#
+# In any case, output an appropriate command line for running (or not
+# running) pod2man.
+
+
+IFS=:
+if test "$OSTYPE" = "msdosdjgpp"; then IFS=";"; fi
+
+try_without_dir=true
+# First we try "pod2man", then "$dir/pod2man" for each item in $PATH.
+for dir in dummy${IFS}$PATH; do
+    if [ "$try_without_dir" = true ]; then
+      # first iteration
+      pod2man=pod2man
+      try_without_dir=false
+    else
+      # second and later iterations
+      pod2man="$dir/pod2man"
+      if [ ! -f "$pod2man" ]; then  # '-x' is not available on Ultrix
+        pod2man=''
+      fi
+    fi
+
+    if [ ! "$pod2man" = '' ]; then
+        failure=none
+
+       if "$pod2man" --section=1 --center=OpenSSL --release=dev pod2mantest.pod | fgrep OpenSSL >/dev/null; then
+           :
+       else
+           failure=BasicTest
+       fi
+
+       if [ "$failure" = none ]; then
+           if "$pod2man" --section=1 --center=OpenSSL --release=dev pod2mantest.pod | grep '^MARKER - ' >/dev/null; then
+               failure=MultilineTest
+           fi
+       fi
+
+
+        if [ "$failure" = none ]; then
+            echo "$pod2man"
+            exit 0
+        fi
+
+        echo "$pod2man does not work properly ('$failure' failed).  Looking for another pod2man ..." >&2
+    fi
+done
+
+echo "No working pod2man found.  Consider installing a new version." >&2
+echo "As a workaround, we'll use a bundled old copy of pod2man.pl." >&2
+echo "$1 ../../util/pod2man.pl"
diff --git a/deps/openssl/openssl/util/pod2mantest.pod b/deps/openssl/openssl/util/pod2mantest.pod
new file mode 100644 (file)
index 0000000..5d2539a
--- /dev/null
@@ -0,0 +1,15 @@
+=pod
+
+=head1 NAME
+
+foo, bar,
+MARKER - test of multiline name section
+
+=head1 DESCRIPTION
+
+This is a test .pod file to see if we have a buggy pod2man or not.
+If we have a buggy implementation, we will get a line matching the
+regular expression "^ +MARKER - test of multiline name section *$"
+at the end of the resulting document.
+
+=cut
diff --git a/deps/openssl/openssl/util/point.sh b/deps/openssl/openssl/util/point.sh
new file mode 100755 (executable)
index 0000000..da39899
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+rm -f "$2"
+if test "$OSTYPE" = msdosdjgpp || test "x$PLATFORM" = xmingw ; then
+    cp "$1" "$2"
+else
+    ln -s "$1" "$2"
+fi
+echo "$2 => $1"
+
diff --git a/deps/openssl/openssl/util/selftest.pl b/deps/openssl/openssl/util/selftest.pl
new file mode 100644 (file)
index 0000000..7b32e9f
--- /dev/null
@@ -0,0 +1,201 @@
+#!/usr/local/bin/perl -w
+#
+# Run the test suite and generate a report
+#
+
+if (! -f "Configure") {
+    print "Please run perl util/selftest.pl in the OpenSSL directory.\n";
+    exit 1;
+}
+
+my $report="testlog";
+my $os="??";
+my $version="??";
+my $platform0="??";
+my $platform="??";
+my $options="??";
+my $last="??";
+my $ok=0;
+my $cc="cc";
+my $cversion="??";
+my $sep="-----------------------------------------------------------------------------\n";
+my $not_our_fault="\nPlease ask your system administrator/vendor for more information.\n[Problems with your operating system setup should not be reported\nto the OpenSSL project.]\n";
+
+open(OUT,">$report") or die;
+
+print OUT "OpenSSL self-test report:\n\n";
+
+$uname=`uname -a`;
+$uname="??\n" if $uname eq "";
+
+$c=`sh config -t`;
+foreach $_ (split("\n",$c)) {
+    $os=$1 if (/Operating system: (.*)$/);
+    $platform0=$1 if (/Configuring for (.*)$/);
+}
+
+system "sh config" if (! -f "Makefile");
+
+if (open(IN,"<Makefile")) {
+    while (<IN>) {
+       $version=$1 if (/^VERSION=(.*)$/);
+       $platform=$1 if (/^PLATFORM=(.*)$/);
+       $options=$1 if (/^OPTIONS=(.*)$/);
+       $cc=$1 if (/^CC= *(.*)$/);
+    }
+    close(IN);
+} else {
+    print OUT "Error running config!\n";
+}
+
+$cversion=`$cc -v 2>&1`;
+$cversion=`$cc -V 2>&1` if $cversion =~ "[Uu]sage";
+$cversion=`$cc -V |head -1` if $cversion =~ "Error";
+$cversion=`$cc --version` if $cversion eq "";
+$cversion =~ s/Reading specs.*\n//;
+$cversion =~ s/usage.*\n//;
+chomp $cversion;
+
+if (open(IN,"<CHANGES")) {
+    while(<IN>) {
+       if (/\*\) (.{0,55})/ && !/applies to/) {
+           $last=$1;
+           last;
+       }
+    }
+    close(IN);
+}
+
+print OUT "OpenSSL version:  $version\n";
+print OUT "Last change:      $last...\n";
+print OUT "Options:          $options\n" if $options ne "";
+print OUT "OS (uname):       $uname";
+print OUT "OS (config):      $os\n";
+print OUT "Target (default): $platform0\n";
+print OUT "Target:           $platform\n";
+print OUT "Compiler:         $cversion\n";
+print OUT "\n";
+
+print "Checking compiler...\n";
+if (open(TEST,">cctest.c")) {
+    print TEST "#include <stdio.h>\n#include <stdlib.h>\n#include <errno.h>\nmain(){printf(\"Hello world\\n\");}\n";
+    close(TEST);
+    system("$cc -o cctest cctest.c");
+    if (`./cctest` !~ /Hello world/) {
+       print OUT "Compiler doesn't work.\n";
+       print OUT $not_our_fault;
+       goto err;
+    }
+    system("ar r cctest.a /dev/null");
+    if (not -f "cctest.a") {
+       print OUT "Check your archive tool (ar).\n";
+       print OUT $not_our_fault;
+       goto err;
+    }
+} else {
+    print OUT "Can't create cctest.c\n";
+}
+if (open(TEST,">cctest.c")) {
+    print TEST "#include <stdio.h>\n#include <stdlib.h>\n#include <openssl/opensslv.h>\nmain(){printf(OPENSSL_VERSION_TEXT);}\n";
+    close(TEST);
+    system("$cc -o cctest -Iinclude cctest.c");
+    $cctest = `./cctest`;
+    if ($cctest !~ /OpenSSL $version/) {
+       if ($cctest =~ /OpenSSL/) {
+           print OUT "#include uses headers from different OpenSSL version!\n";
+       } else {
+           print OUT "Can't compile test program!\n";
+       }
+       print OUT $not_our_fault;
+       goto err;
+    }
+} else {
+    print OUT "Can't create cctest.c\n";
+}
+
+print "Running make...\n";
+if (system("make 2>&1 | tee make.log") > 255) {
+
+    print OUT "make failed!\n";
+    if (open(IN,"<make.log")) {
+       print OUT $sep;
+       while (<IN>) {
+           print OUT;
+       }
+       close(IN);
+       print OUT $sep;
+    } else {
+       print OUT "make.log not found!\n";
+    }
+    goto err;
+}
+
+# Not sure why this is here.  The tests themselves can detect if their
+# particular feature isn't included, and should therefore skip themselves.
+# To skip *all* tests just because one algorithm isn't included is like
+# shooting mosquito with an elephant gun...
+#                   -- Richard Levitte, inspired by problem report 1089
+#
+#$_=$options;
+#s/no-asm//;
+#s/no-shared//;
+#s/no-krb5//;
+#if (/no-/)
+#{
+#    print OUT "Test skipped.\n";
+#    goto err;
+#}
+
+print "Running make test...\n";
+if (system("make test 2>&1 | tee maketest.log") > 255)
+ {
+    print OUT "make test failed!\n";
+} else {
+    $ok=1;
+}
+
+if ($ok and open(IN,"<maketest.log")) {
+    while (<IN>) {
+       $ok=2 if /^platform: $platform/;
+    }
+    close(IN);
+}
+
+if ($ok != 2) {
+    print OUT "Failure!\n";
+    if (open(IN,"<make.log")) {
+       print OUT $sep;
+       while (<IN>) {
+           print OUT;
+       }
+       close(IN);
+       print OUT $sep;
+    } else {
+       print OUT "make.log not found!\n";
+    }
+    if (open(IN,"<maketest.log")) {
+       while (<IN>) {
+           print OUT;
+       }
+       close(IN);
+       print OUT $sep;
+    } else {
+       print OUT "maketest.log not found!\n";
+    }
+} else {
+    print OUT "Test passed.\n";
+}
+err:
+close(OUT);
+
+print "\n";
+open(IN,"<$report") or die;
+while (<IN>) {
+    if (/$sep/) {
+       print "[...]\n";
+       last;
+    }
+    print;
+}
+print "\nTest report in file $report\n";
+
diff --git a/deps/openssl/openssl/util/shlib_wrap.sh b/deps/openssl/openssl/util/shlib_wrap.sh
new file mode 100755 (executable)
index 0000000..9416d59
--- /dev/null
@@ -0,0 +1,93 @@
+#!/bin/sh
+
+[ $# -ne 0 ] || set -x         # debug mode without arguments:-)
+
+THERE="`echo $0 | sed -e 's|[^/]*$||' 2>/dev/null`.."
+[ -d "${THERE}" ] || exec "$@" # should never happen...
+
+# Alternative to this is to parse ${THERE}/Makefile...
+LIBCRYPTOSO="${THERE}/libcrypto.so"
+if [ -f "$LIBCRYPTOSO" ]; then
+    while [ -h "$LIBCRYPTOSO" ]; do
+       LIBCRYPTOSO="${THERE}/`ls -l "$LIBCRYPTOSO" | sed -e 's|.*\-> ||'`"
+    done
+    SOSUFFIX=`echo ${LIBCRYPTOSO} | sed -e 's|.*\.so||' 2>/dev/null`
+    LIBSSLSO="${THERE}/libssl.so${SOSUFFIX}"
+fi
+
+SYSNAME=`(uname -s) 2>/dev/null`;
+case "$SYSNAME" in
+SunOS|IRIX*)
+       # SunOS and IRIX run-time linkers evaluate alternative
+       # variables depending on target ABI...
+       rld_var=LD_LIBRARY_PATH
+       case "`(/usr/bin/file "$LIBCRYPTOSO") 2>/dev/null`" in
+       *ELF\ 64*SPARC*|*ELF\ 64*AMD64*)
+               [ -n "$LD_LIBRARY_PATH_64" ] && rld_var=LD_LIBRARY_PATH_64
+               LD_PRELOAD_64="$LIBCRYPTOSO $LIBSSLSO"; export LD_PRELOAD_64
+               preload_var=LD_PRELOAD_64
+               ;;
+       # Why are newly built .so's preloaded anyway? Because run-time
+       # .so lookup path embedded into application takes precedence
+       # over LD_LIBRARY_PATH and as result application ends up linking
+       # to previously installed .so's. On IRIX instead of preloading
+       # newly built .so's we trick run-time linker to fail to find
+       # the installed .so by setting _RLD_ROOT variable.
+       *ELF\ 32*MIPS*)
+               #_RLD_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT"; export _RLD_LIST
+               _RLD_ROOT=/no/such/dir; export _RLD_ROOT
+               eval $rld_var=\"/usr/lib'${'$rld_var':+:$'$rld_var'}'\"
+               preload_var=_RLD_LIST
+               ;;
+       *ELF\ N32*MIPS*)
+               [ -n "$LD_LIBRARYN32_PATH" ] && rld_var=LD_LIBRARYN32_PATH
+               #_RLDN32_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT"; export _RLDN32_LIST
+               _RLDN32_ROOT=/no/such/dir; export _RLDN32_ROOT
+               eval $rld_var=\"/usr/lib32'${'$rld_var':+:$'$rld_var'}'\"
+               preload_var=_RLDN32_LIST
+               ;;
+       *ELF\ 64*MIPS*)
+               [ -n "$LD_LIBRARY64_PATH"  ] && rld_var=LD_LIBRARY64_PATH
+               #_RLD64_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT"; export _RLD64_LIST
+               _RLD64_ROOT=/no/such/dir; export _RLD64_ROOT
+               eval $rld_var=\"/usr/lib64'${'$rld_var':+:$'$rld_var'}'\"
+               preload_var=_RLD64_LIST
+               ;;
+       esac
+       eval $rld_var=\"${THERE}'${'$rld_var':+:$'$rld_var'}'\"; export $rld_var
+       unset rld_var
+       ;;
+*)     LD_LIBRARY_PATH="${THERE}:$LD_LIBRARY_PATH"     # Linux, ELF HP-UX
+       DYLD_LIBRARY_PATH="${THERE}:$DYLD_LIBRARY_PATH" # MacOS X
+       SHLIB_PATH="${THERE}:$SHLIB_PATH"               # legacy HP-UX
+       LIBPATH="${THERE}:$LIBPATH"                     # AIX, OS/2
+       export LD_LIBRARY_PATH DYLD_LIBRARY_PATH SHLIB_PATH LIBPATH
+       # Even though $PATH is adjusted [for Windows sake], it doesn't
+       # necessarily does the trick. Trouble is that with introduction
+       # of SafeDllSearchMode in XP/2003 it's more appropriate to copy
+       # .DLLs in vicinity of executable, which is done elsewhere...
+       if [ "$OSTYPE" != msdosdjgpp ]; then
+               PATH="${THERE}:$PATH"; export PATH
+       fi
+       ;;
+esac
+
+if [ -f "$LIBCRYPTOSO" -a -z "$preload_var" ]; then
+       # Following three lines are major excuse for isolating them into
+       # this wrapper script. Original reason for setting LD_PRELOAD
+       # was to make it possible to pass 'make test' when user linked
+       # with -rpath pointing to previous version installation. Wrapping
+       # it into a script makes it possible to do so on multi-ABI
+       # platforms.
+       case "$SYSNAME" in
+       *BSD|QNX)       LD_PRELOAD="$LIBCRYPTOSO:$LIBSSLSO" ;;  # *BSD, QNX
+       *)      LD_PRELOAD="$LIBCRYPTOSO $LIBSSLSO" ;;  # SunOS, Linux, ELF HP-UX
+       esac
+       _RLD_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT"      # Tru64, o32 IRIX
+       DYLD_INSERT_LIBRARIES="$LIBCRYPTOSO:$LIBSSLSO"  # MacOS X
+       export LD_PRELOAD _RLD_LIST DYLD_INSERT_LIBRARIES
+fi
+
+cmd="$1${EXE_EXT}"
+shift
+exec "$cmd" "$@"
diff --git a/deps/openssl/openssl/util/sp-diff.pl b/deps/openssl/openssl/util/sp-diff.pl
new file mode 100755 (executable)
index 0000000..9d6c603
--- /dev/null
@@ -0,0 +1,80 @@
+#!/usr/local/bin/perl
+#
+# This file takes as input, the files that have been output from
+# ssleay speed.
+# It prints a table of the relative differences with %100 being 'no difference'
+#
+
+($#ARGV == 1) || die "$0 speedout1 speedout2\n";
+
+%one=&loadfile($ARGV[0]);
+%two=&loadfile($ARGV[1]);
+
+$line=0;
+foreach $a ("md2","md4","md5","sha","sha1","rc4","des cfb","des cbc","des ede3",
+       "idea cfb","idea cbc","rc2 cfb","rc2 cbc","blowfish cbc","cast cbc")
+       {
+       if (defined($one{$a,8}) && defined($two{$a,8}))
+               {
+               print "type              8 byte%    64 byte%   256 byte%  1024 byte%  8192 byte%\n"
+                       unless $line;
+               $line++;
+               printf "%-12s ",$a;
+               foreach $b (8,64,256,1024,8192)
+                       {
+                       $r=$two{$a,$b}/$one{$a,$b}*100;
+                       printf "%12.2f",$r;
+                       }
+               print "\n";
+               }
+       }
+
+foreach $a     (
+               "rsa  512","rsa 1024","rsa 2048","rsa 4096",
+               "dsa  512","dsa 1024","dsa 2048",
+               )
+       {
+       if (defined($one{$a,1}) && defined($two{$a,1}))
+               {
+               $r1=($one{$a,1}/$two{$a,1})*100;
+               $r2=($one{$a,2}/$two{$a,2})*100;
+               printf "$a bits %%    %6.2f %%    %6.2f\n",$r1,$r2;
+               }
+       }
+
+sub loadfile
+       {
+       local($file)=@_;
+       local($_,%ret);
+
+       open(IN,"<$file") || die "unable to open '$file' for input\n";
+       $header=1;
+       while (<IN>)
+               {
+               $header=0 if /^[dr]sa/;
+               if (/^type/) { $header=0; next; }
+               next if $header;
+               chop;
+               @a=split;
+               if ($a[0] =~ /^[dr]sa$/)
+                       {
+                       ($n,$t1,$t2)=($_ =~ /^([dr]sa\s+\d+)\s+bits\s+([.\d]+)s\s+([.\d]+)/);
+                       $ret{$n,1}=$t1;
+                       $ret{$n,2}=$t2;
+                       }
+               else
+                       {
+                       $n=join(' ',grep(/[^k]$/,@a));
+                       @k=grep(s/k$//,@a);
+                       
+                       $ret{$n,   8}=$k[0];
+                       $ret{$n,  64}=$k[1];
+                       $ret{$n, 256}=$k[2];
+                       $ret{$n,1024}=$k[3];
+                       $ret{$n,8192}=$k[4];
+                       }
+               }
+       close(IN);
+       return(%ret);
+       }
+
diff --git a/deps/openssl/openssl/util/speed.sh b/deps/openssl/openssl/util/speed.sh
new file mode 100755 (executable)
index 0000000..f489706
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+#
+# This is a ugly script use, in conjuction with editing the 'b'
+# configuration in the $(TOP)/Configure script which will
+# output when finished a file called speed.log which is the
+# timings of SSLeay with various options turned on or off.
+#
+# from the $(TOP) directory
+# Edit Configure, modifying things to do with the b/bl-4c-2c etc
+# configurations.
+#
+
+make clean
+perl Configure b
+make
+apps/ssleay version -v -b -f >speed.1
+apps/ssleay speed >speed.1l
+
+perl Configure bl-4c-2c
+/bin/rm -f crypto/rc4/*.o crypto/bn/bn*.o crypto/md2/md2_dgst.o
+make
+apps/ssleay speed rc4 rsa md2 >speed.2l
+
+perl Configure bl-4c-ri
+/bin/rm -f crypto/rc4/rc4*.o
+make
+apps/ssleay speed rc4 >speed.3l
+
+perl Configure b2-is-ri-dp
+/bin/rm -f crypto/idea/i_*.o crypto/rc4/*.o crypto/des/ecb_enc.o crypto/bn/bn*.o
+apps/ssleay speed rsa rc4 idea des >speed.4l
+
+cat speed.1 >speed.log
+cat speed.1l >>speed.log
+perl util/sp-diff.pl speed.1l speed.2l >>speed.log
+perl util/sp-diff.pl speed.1l speed.3l >>speed.log
+perl util/sp-diff.pl speed.1l speed.4l >>speed.log
+
diff --git a/deps/openssl/openssl/util/src-dep.pl b/deps/openssl/openssl/util/src-dep.pl
new file mode 100755 (executable)
index 0000000..ad997e4
--- /dev/null
@@ -0,0 +1,147 @@
+#!/usr/local/bin/perl
+
+# we make up an array of
+# $file{function_name}=filename;
+# $unres{filename}="func1 func2 ...."
+$debug=1;
+#$nm_func="parse_linux";
+$nm_func="parse_solaris";
+
+foreach (@ARGV)
+       {
+       &$nm_func($_);
+       }
+
+foreach $file (sort keys %unres)
+       {
+       @a=split(/\s+/,$unres{$file});
+       %ff=();
+       foreach $func (@a)
+               {
+               $f=$file{$func};
+               $ff{$f}=1 if $f ne "";
+               }
+
+       foreach $a (keys %ff)
+               { $we_need{$file}.="$a "; }
+       }
+
+foreach $file (sort keys %we_need)
+       {
+#      print " $file $we_need{$file}\n";
+       foreach $bit (split(/\s+/,$we_need{$file}))
+               { push(@final,&walk($bit)); }
+
+       foreach (@final) { $fin{$_}=1; }
+       @final="";
+       foreach (sort keys %fin)
+               { push(@final,$_); }
+
+       print "$file: @final\n";
+       }
+
+sub walk
+       {
+       local($f)=@_;
+       local(@a,%seen,@ret,$r);
+
+       @ret="";
+       $f =~ s/^\s+//;
+       $f =~ s/\s+$//;
+       return "" if ($f =~ "^\s*$");
+
+       return(split(/\s/,$done{$f})) if defined ($done{$f});
+
+       return if $in{$f} > 0;
+       $in{$f}++;
+       push(@ret,$f);
+       foreach $r (split(/\s+/,$we_need{$f}))
+               {
+               push(@ret,&walk($r));
+               }
+       $in{$f}--;
+       $done{$f}=join(" ",@ret);
+       return(@ret);
+       }
+
+sub parse_linux
+       {
+       local($name)=@_;
+
+       open(IN,"nm $name|") || die "unable to run 'nn $name':$!\n";
+       while (<IN>)
+               {
+               chop;
+               next if /^\s*$/;
+               if (/^[^[](.*):$/)
+                       {
+                       $file=$1;
+                       $file="$1.c" if /\[(.*).o\]/;
+                       print STDERR "$file\n";
+                       $we_need{$file}=" ";
+                       next;
+                       }
+
+               @a=split(/\s*\|\s*/);
+               next unless $#a == 7;
+               next unless $a[4] eq "GLOB";
+               if ($a[6] eq "UNDEF")
+                       {
+                       $unres{$file}.=$a[7]." ";
+                       }
+               else
+                       {
+                       if ($file{$a[7]} ne "")
+                               {
+                               print STDERR "duplicate definition of $a[7],\n$file{$a[7]} and $file \n";
+                               }
+                       else
+                               {
+                               $file{$a[7]}=$file;
+                               }
+                       }
+               }
+       close(IN);
+       }
+
+sub parse_solaris
+       {
+       local($name)=@_;
+
+       open(IN,"nm $name|") || die "unable to run 'nn $name':$!\n";
+       while (<IN>)
+               {
+               chop;
+               next if /^\s*$/;
+               if (/^(\S+):$/)
+                       {
+                       $file=$1;
+                       #$file="$1.c" if $file =~ /^(.*).o$/;
+                       print STDERR "$file\n";
+                       $we_need{$file}=" ";
+                       next;
+                       }
+               @a=split(/\s*\|\s*/);
+               next unless $#a == 7;
+               next unless $a[4] eq "GLOB";
+               if ($a[6] eq "UNDEF")
+                       {
+                       $unres{$file}.=$a[7]." ";
+                       print STDERR "$file needs $a[7]\n" if $debug;
+                       }
+               else
+                       {
+                       if ($file{$a[7]} ne "")
+                               {
+                               print STDERR "duplicate definition of $a[7],\n$file{$a[7]} and $file \n";
+                               }
+                       else
+                               {
+                               $file{$a[7]}=$file;
+                               print STDERR "$file has $a[7]\n" if $debug;
+                               }
+                       }
+               }
+       close(IN);
+       }
+
diff --git a/deps/openssl/openssl/util/ssleay.num b/deps/openssl/openssl/util/ssleay.num
new file mode 100755 (executable)
index 0000000..15a58e7
--- /dev/null
@@ -0,0 +1,261 @@
+ERR_load_SSL_strings                    1      EXIST::FUNCTION:
+SSL_CIPHER_description                  2      EXIST::FUNCTION:
+SSL_CTX_add_client_CA                   3      EXIST::FUNCTION:
+SSL_CTX_add_session                     4      EXIST::FUNCTION:
+SSL_CTX_check_private_key               5      EXIST::FUNCTION:
+SSL_CTX_ctrl                            6      EXIST::FUNCTION:
+SSL_CTX_flush_sessions                  7      EXIST::FUNCTION:
+SSL_CTX_free                            8      EXIST::FUNCTION:
+SSL_CTX_get_client_CA_list              9      EXIST::FUNCTION:
+SSL_CTX_get_verify_callback             10     EXIST::FUNCTION:
+SSL_CTX_get_verify_mode                 11     EXIST::FUNCTION:
+SSL_CTX_new                             12     EXIST::FUNCTION:
+SSL_CTX_remove_session                  13     EXIST::FUNCTION:
+SSL_CTX_set_cipher_list                 15     EXIST::FUNCTION:
+SSL_CTX_set_client_CA_list              16     EXIST::FUNCTION:
+SSL_CTX_set_default_passwd_cb           17     EXIST::FUNCTION:
+SSL_CTX_set_ssl_version                 19     EXIST::FUNCTION:
+SSL_CTX_set_verify                      21     EXIST::FUNCTION:
+SSL_CTX_use_PrivateKey                  22     EXIST::FUNCTION:
+SSL_CTX_use_PrivateKey_ASN1             23     EXIST::FUNCTION:
+SSL_CTX_use_PrivateKey_file             24     EXIST::FUNCTION:STDIO
+SSL_CTX_use_RSAPrivateKey               25     EXIST::FUNCTION:RSA
+SSL_CTX_use_RSAPrivateKey_ASN1          26     EXIST::FUNCTION:RSA
+SSL_CTX_use_RSAPrivateKey_file          27     EXIST::FUNCTION:RSA,STDIO
+SSL_CTX_use_certificate                 28     EXIST::FUNCTION:
+SSL_CTX_use_certificate_ASN1            29     EXIST::FUNCTION:
+SSL_CTX_use_certificate_file            30     EXIST::FUNCTION:STDIO
+SSL_SESSION_free                        31     EXIST::FUNCTION:
+SSL_SESSION_new                         32     EXIST::FUNCTION:
+SSL_SESSION_print                       33     EXIST::FUNCTION:BIO
+SSL_SESSION_print_fp                    34     EXIST::FUNCTION:FP_API
+SSL_accept                              35     EXIST::FUNCTION:
+SSL_add_client_CA                       36     EXIST::FUNCTION:
+SSL_alert_desc_string                   37     EXIST::FUNCTION:
+SSL_alert_desc_string_long              38     EXIST::FUNCTION:
+SSL_alert_type_string                   39     EXIST::FUNCTION:
+SSL_alert_type_string_long              40     EXIST::FUNCTION:
+SSL_check_private_key                   41     EXIST::FUNCTION:
+SSL_clear                               42     EXIST::FUNCTION:
+SSL_connect                             43     EXIST::FUNCTION:
+SSL_copy_session_id                     44     EXIST::FUNCTION:
+SSL_ctrl                                45     EXIST::FUNCTION:
+SSL_dup                                 46     EXIST::FUNCTION:
+SSL_dup_CA_list                         47     EXIST::FUNCTION:
+SSL_free                                48     EXIST::FUNCTION:
+SSL_get_certificate                     49     EXIST::FUNCTION:
+SSL_get_cipher_list                     52     EXIST::FUNCTION:
+SSL_get_ciphers                         55     EXIST::FUNCTION:
+SSL_get_client_CA_list                  56     EXIST::FUNCTION:
+SSL_get_default_timeout                 57     EXIST::FUNCTION:
+SSL_get_error                           58     EXIST::FUNCTION:
+SSL_get_fd                              59     EXIST::FUNCTION:
+SSL_get_peer_cert_chain                 60     EXIST::FUNCTION:
+SSL_get_peer_certificate                61     EXIST::FUNCTION:
+SSL_get_rbio                            63     EXIST::FUNCTION:BIO
+SSL_get_read_ahead                      64     EXIST::FUNCTION:
+SSL_get_shared_ciphers                  65     EXIST::FUNCTION:
+SSL_get_ssl_method                      66     EXIST::FUNCTION:
+SSL_get_verify_callback                 69     EXIST::FUNCTION:
+SSL_get_verify_mode                     70     EXIST::FUNCTION:
+SSL_get_version                         71     EXIST::FUNCTION:
+SSL_get_wbio                            72     EXIST::FUNCTION:BIO
+SSL_load_client_CA_file                 73     EXIST::FUNCTION:STDIO
+SSL_load_error_strings                  74     EXIST::FUNCTION:
+SSL_new                                 75     EXIST::FUNCTION:
+SSL_peek                                76     EXIST::FUNCTION:
+SSL_pending                             77     EXIST::FUNCTION:
+SSL_read                                78     EXIST::FUNCTION:
+SSL_renegotiate                         79     EXIST::FUNCTION:
+SSL_rstate_string                       80     EXIST::FUNCTION:
+SSL_rstate_string_long                  81     EXIST::FUNCTION:
+SSL_set_accept_state                    82     EXIST::FUNCTION:
+SSL_set_bio                             83     EXIST::FUNCTION:BIO
+SSL_set_cipher_list                     84     EXIST::FUNCTION:
+SSL_set_client_CA_list                  85     EXIST::FUNCTION:
+SSL_set_connect_state                   86     EXIST::FUNCTION:
+SSL_set_fd                              87     EXIST::FUNCTION:SOCK
+SSL_set_read_ahead                      88     EXIST::FUNCTION:
+SSL_set_rfd                             89     EXIST::FUNCTION:SOCK
+SSL_set_session                         90     EXIST::FUNCTION:
+SSL_set_ssl_method                      91     EXIST::FUNCTION:
+SSL_set_verify                          94     EXIST::FUNCTION:
+SSL_set_wfd                             95     EXIST::FUNCTION:SOCK
+SSL_shutdown                            96     EXIST::FUNCTION:
+SSL_state_string                        97     EXIST::FUNCTION:
+SSL_state_string_long                   98     EXIST::FUNCTION:
+SSL_use_PrivateKey                      99     EXIST::FUNCTION:
+SSL_use_PrivateKey_ASN1                 100    EXIST::FUNCTION:
+SSL_use_PrivateKey_file                 101    EXIST::FUNCTION:STDIO
+SSL_use_RSAPrivateKey                   102    EXIST::FUNCTION:RSA
+SSL_use_RSAPrivateKey_ASN1              103    EXIST::FUNCTION:RSA
+SSL_use_RSAPrivateKey_file              104    EXIST::FUNCTION:RSA,STDIO
+SSL_use_certificate                     105    EXIST::FUNCTION:
+SSL_use_certificate_ASN1                106    EXIST::FUNCTION:
+SSL_use_certificate_file                107    EXIST::FUNCTION:STDIO
+SSL_write                               108    EXIST::FUNCTION:
+SSLeay_add_ssl_algorithms               109    NOEXIST::FUNCTION:
+SSLv23_client_method                    110    EXIST::FUNCTION:RSA
+SSLv23_method                           111    EXIST::FUNCTION:RSA
+SSLv23_server_method                    112    EXIST::FUNCTION:RSA
+SSLv2_client_method                     113    EXIST::FUNCTION:RSA,SSL2
+SSLv2_method                            114    EXIST::FUNCTION:RSA,SSL2
+SSLv2_server_method                     115    EXIST::FUNCTION:RSA,SSL2
+SSLv3_client_method                     116    EXIST::FUNCTION:
+SSLv3_method                            117    EXIST::FUNCTION:
+SSLv3_server_method                     118    EXIST::FUNCTION:
+d2i_SSL_SESSION                         119    EXIST::FUNCTION:
+i2d_SSL_SESSION                         120    EXIST::FUNCTION:
+BIO_f_ssl                               121    EXIST::FUNCTION:BIO
+BIO_new_ssl                             122    EXIST::FUNCTION:BIO
+BIO_proxy_ssl_copy_session_id           123    NOEXIST::FUNCTION:
+BIO_ssl_copy_session_id                 124    EXIST::FUNCTION:BIO
+SSL_do_handshake                        125    EXIST::FUNCTION:
+SSL_get_privatekey                      126    EXIST::FUNCTION:
+SSL_get_current_cipher                  127    EXIST::FUNCTION:
+SSL_CIPHER_get_bits                     128    EXIST::FUNCTION:
+SSL_CIPHER_get_version                  129    EXIST::FUNCTION:
+SSL_CIPHER_get_name                     130    EXIST::FUNCTION:
+BIO_ssl_shutdown                        131    EXIST::FUNCTION:BIO
+SSL_SESSION_cmp                         132    NOEXIST::FUNCTION:
+SSL_SESSION_hash                        133    NOEXIST::FUNCTION:
+SSL_SESSION_get_time                    134    EXIST::FUNCTION:
+SSL_SESSION_set_time                    135    EXIST::FUNCTION:
+SSL_SESSION_get_timeout                 136    EXIST::FUNCTION:
+SSL_SESSION_set_timeout                 137    EXIST::FUNCTION:
+SSL_CTX_get_ex_data                     138    EXIST::FUNCTION:
+SSL_CTX_get_quiet_shutdown              140    EXIST::FUNCTION:
+SSL_CTX_load_verify_locations           141    EXIST::FUNCTION:
+SSL_CTX_set_default_verify_paths        142    EXIST:!VMS:FUNCTION:
+SSL_CTX_set_def_verify_paths            142    EXIST:VMS:FUNCTION:
+SSL_CTX_set_ex_data                     143    EXIST::FUNCTION:
+SSL_CTX_set_quiet_shutdown              145    EXIST::FUNCTION:
+SSL_SESSION_get_ex_data                 146    EXIST::FUNCTION:
+SSL_SESSION_set_ex_data                 148    EXIST::FUNCTION:
+SSL_get_SSL_CTX                         150    EXIST::FUNCTION:
+SSL_get_ex_data                         151    EXIST::FUNCTION:
+SSL_get_quiet_shutdown                  153    EXIST::FUNCTION:
+SSL_get_session                         154    EXIST::FUNCTION:
+SSL_get_shutdown                        155    EXIST::FUNCTION:
+SSL_get_verify_result                   157    EXIST::FUNCTION:
+SSL_set_ex_data                         158    EXIST::FUNCTION:
+SSL_set_info_callback                   160    EXIST::FUNCTION:
+SSL_set_quiet_shutdown                  161    EXIST::FUNCTION:
+SSL_set_shutdown                        162    EXIST::FUNCTION:
+SSL_set_verify_result                   163    EXIST::FUNCTION:
+SSL_version                             164    EXIST::FUNCTION:
+SSL_get_info_callback                   165    EXIST::FUNCTION:
+SSL_state                               166    EXIST::FUNCTION:
+SSL_CTX_get_ex_new_index                167    EXIST::FUNCTION:
+SSL_SESSION_get_ex_new_index            168    EXIST::FUNCTION:
+SSL_get_ex_new_index                    169    EXIST::FUNCTION:
+TLSv1_method                            170    EXIST::FUNCTION:
+TLSv1_server_method                     171    EXIST::FUNCTION:
+TLSv1_client_method                     172    EXIST::FUNCTION:
+BIO_new_buffer_ssl_connect              173    EXIST::FUNCTION:BIO
+BIO_new_ssl_connect                     174    EXIST::FUNCTION:BIO
+SSL_get_ex_data_X509_STORE_CTX_idx      175    EXIST:!VMS:FUNCTION:
+SSL_get_ex_d_X509_STORE_CTX_idx         175    EXIST:VMS:FUNCTION:
+SSL_CTX_set_tmp_dh_callback             176    EXIST::FUNCTION:DH
+SSL_CTX_set_tmp_rsa_callback            177    EXIST::FUNCTION:RSA
+SSL_CTX_set_timeout                     178    EXIST::FUNCTION:
+SSL_CTX_get_timeout                     179    EXIST::FUNCTION:
+SSL_CTX_get_cert_store                  180    EXIST::FUNCTION:
+SSL_CTX_set_cert_store                  181    EXIST::FUNCTION:
+SSL_want                                182    EXIST::FUNCTION:
+SSL_library_init                        183    EXIST::FUNCTION:
+SSL_COMP_add_compression_method         184    EXIST::FUNCTION:COMP
+SSL_add_file_cert_subjects_to_stack     185    EXIST:!VMS:FUNCTION:STDIO
+SSL_add_file_cert_subjs_to_stk          185    EXIST:VMS:FUNCTION:STDIO
+SSL_set_tmp_rsa_callback                186    EXIST::FUNCTION:RSA
+SSL_set_tmp_dh_callback                 187    EXIST::FUNCTION:DH
+SSL_add_dir_cert_subjects_to_stack      188    EXIST:!VMS:FUNCTION:STDIO
+SSL_add_dir_cert_subjs_to_stk           188    EXIST:VMS:FUNCTION:STDIO
+SSL_set_session_id_context              189    EXIST::FUNCTION:
+SSL_CTX_use_certificate_chain_file      222    EXIST:!VMS:FUNCTION:STDIO
+SSL_CTX_use_cert_chain_file             222    EXIST:VMS:FUNCTION:STDIO
+SSL_CTX_set_verify_depth                225    EXIST::FUNCTION:
+SSL_set_verify_depth                    226    EXIST::FUNCTION:
+SSL_CTX_get_verify_depth                228    EXIST::FUNCTION:
+SSL_get_verify_depth                    229    EXIST::FUNCTION:
+SSL_CTX_set_session_id_context          231    EXIST::FUNCTION:
+SSL_CTX_set_cert_verify_callback        232    EXIST:!VMS:FUNCTION:
+SSL_CTX_set_cert_verify_cb              232    EXIST:VMS:FUNCTION:
+SSL_CTX_set_default_passwd_cb_userdata  235    EXIST:!VMS:FUNCTION:
+SSL_CTX_set_def_passwd_cb_ud            235    EXIST:VMS:FUNCTION:
+SSL_set_purpose                         236    EXIST::FUNCTION:
+SSL_CTX_set_trust                       237    EXIST::FUNCTION:
+SSL_CTX_set_purpose                     238    EXIST::FUNCTION:
+SSL_set_trust                           239    EXIST::FUNCTION:
+SSL_get_finished                        240    EXIST::FUNCTION:
+SSL_get_peer_finished                   241    EXIST::FUNCTION:
+SSL_get1_session                        242    EXIST::FUNCTION:
+SSL_CTX_callback_ctrl                   243    EXIST::FUNCTION:
+SSL_callback_ctrl                       244    EXIST::FUNCTION:
+SSL_CTX_sessions                        245    EXIST::FUNCTION:
+SSL_get_rfd                             246    EXIST::FUNCTION:
+SSL_get_wfd                             247    EXIST::FUNCTION:
+kssl_cget_tkt                           248    EXIST::FUNCTION:KRB5
+SSL_has_matching_session_id             249    EXIST::FUNCTION:
+kssl_err_set                            250    EXIST::FUNCTION:KRB5
+kssl_ctx_show                           251    EXIST::FUNCTION:KRB5
+kssl_validate_times                     252    EXIST::FUNCTION:KRB5
+kssl_check_authent                      253    EXIST::FUNCTION:KRB5
+kssl_ctx_new                            254    EXIST::FUNCTION:KRB5
+kssl_build_principal_2                  255    EXIST::FUNCTION:KRB5
+kssl_skip_confound                      256    EXIST::FUNCTION:KRB5
+kssl_sget_tkt                           257    EXIST::FUNCTION:KRB5
+SSL_set_generate_session_id             258    EXIST::FUNCTION:
+kssl_ctx_setkey                         259    EXIST::FUNCTION:KRB5
+kssl_ctx_setprinc                       260    EXIST::FUNCTION:KRB5
+kssl_ctx_free                           261    EXIST::FUNCTION:KRB5
+kssl_krb5_free_data_contents            262    EXIST::FUNCTION:KRB5
+kssl_ctx_setstring                      263    EXIST::FUNCTION:KRB5
+SSL_CTX_set_generate_session_id         264    EXIST::FUNCTION:
+SSL_renegotiate_pending                 265    EXIST::FUNCTION:
+SSL_CTX_set_msg_callback                266    EXIST::FUNCTION:
+SSL_set_msg_callback                    267    EXIST::FUNCTION:
+DTLSv1_client_method                    268    EXIST::FUNCTION:
+SSL_CTX_set_tmp_ecdh_callback           269    EXIST::FUNCTION:ECDH
+SSL_set_tmp_ecdh_callback               270    EXIST::FUNCTION:ECDH
+SSL_COMP_get_name                       271    EXIST::FUNCTION:COMP
+SSL_get_current_compression             272    EXIST::FUNCTION:COMP
+DTLSv1_method                           273    EXIST::FUNCTION:
+SSL_get_current_expansion               274    EXIST::FUNCTION:COMP
+DTLSv1_server_method                    275    EXIST::FUNCTION:
+SSL_COMP_get_compression_methods        276    EXIST:!VMS:FUNCTION:COMP
+SSL_COMP_get_compress_methods           276    EXIST:VMS:FUNCTION:COMP
+SSL_SESSION_get_id                      277    EXIST::FUNCTION:
+SSL_CTX_sess_set_new_cb                 278    EXIST::FUNCTION:
+SSL_CTX_sess_get_get_cb                 279    EXIST::FUNCTION:
+SSL_CTX_sess_set_get_cb                 280    EXIST::FUNCTION:
+SSL_CTX_set_cookie_verify_cb            281    EXIST::FUNCTION:
+SSL_CTX_get_info_callback               282    EXIST::FUNCTION:
+SSL_CTX_set_cookie_generate_cb          283    EXIST::FUNCTION:
+SSL_CTX_set_client_cert_cb              284    EXIST::FUNCTION:
+SSL_CTX_sess_set_remove_cb              285    EXIST::FUNCTION:
+SSL_CTX_set_info_callback               286    EXIST::FUNCTION:
+SSL_CTX_sess_get_new_cb                 287    EXIST::FUNCTION:
+SSL_CTX_get_client_cert_cb              288    EXIST::FUNCTION:
+SSL_CTX_sess_get_remove_cb              289    EXIST::FUNCTION:
+SSL_set_SSL_CTX                         290    EXIST::FUNCTION:
+SSL_get_servername                      291    EXIST::FUNCTION:TLSEXT
+SSL_get_servername_type                 292    EXIST::FUNCTION:TLSEXT
+SSL_CTX_set_client_cert_engine          293    EXIST::FUNCTION:ENGINE
+SSL_CTX_use_psk_identity_hint           294    EXIST::FUNCTION:PSK
+SSL_CTX_set_psk_client_callback         295    EXIST::FUNCTION:PSK
+PEM_write_bio_SSL_SESSION               296    EXIST::FUNCTION:
+SSL_get_psk_identity_hint               297    EXIST::FUNCTION:PSK
+SSL_set_psk_server_callback             298    EXIST::FUNCTION:PSK
+SSL_use_psk_identity_hint               299    EXIST::FUNCTION:PSK
+SSL_set_psk_client_callback             300    EXIST::FUNCTION:PSK
+PEM_read_SSL_SESSION                    301    EXIST:!WIN16:FUNCTION:
+PEM_read_bio_SSL_SESSION                302    EXIST::FUNCTION:
+SSL_CTX_set_psk_server_callback         303    EXIST::FUNCTION:PSK
+SSL_get_psk_identity                    304    EXIST::FUNCTION:PSK
+PEM_write_SSL_SESSION                   305    EXIST:!WIN16:FUNCTION:
+SSL_set_session_ticket_ext              306    EXIST::FUNCTION:
+SSL_set_session_secret_cb               307    EXIST::FUNCTION:
+SSL_set_session_ticket_ext_cb           308    EXIST::FUNCTION:
+SSL_set1_param                          309    EXIST::FUNCTION:
+SSL_CTX_set1_param                      310    EXIST::FUNCTION:
diff --git a/deps/openssl/openssl/util/tab_num.pl b/deps/openssl/openssl/util/tab_num.pl
new file mode 100755 (executable)
index 0000000..a81ed0e
--- /dev/null
@@ -0,0 +1,17 @@
+#!/usr/local/bin/perl
+
+$num=1;
+$width=40;
+
+while (<>)
+       {
+       chop;
+
+       $i=length($_);
+
+       $n=$width-$i;
+       $i=int(($n+7)/8);
+       print $_.("\t" x $i).$num."\n";
+       $num++;
+       }
+
diff --git a/deps/openssl/openssl/util/x86asm.sh b/deps/openssl/openssl/util/x86asm.sh
new file mode 100755 (executable)
index 0000000..d2090a9
--- /dev/null
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+echo Generating x86 assember
+echo Bignum
+(cd crypto/bn/asm; perl x86.pl cpp > bn86unix.cpp)
+(cd crypto/bn/asm; perl x86.pl win32 > bn-win32.asm)
+
+echo DES
+(cd crypto/des/asm; perl des-586.pl cpp > dx86unix.cpp)
+(cd crypto/des/asm; perl des-586.pl win32 > d-win32.asm)
+
+echo "crypt(3)"
+(cd crypto/des/asm; perl crypt586.pl cpp > yx86unix.cpp)
+(cd crypto/des/asm; perl crypt586.pl win32 > y-win32.asm)
+
+echo Blowfish
+(cd crypto/bf/asm; perl bf-586.pl cpp > bx86unix.cpp)
+(cd crypto/bf/asm; perl bf-586.pl win32 > b-win32.asm)
+
+echo CAST5
+(cd crypto/cast/asm; perl cast-586.pl cpp > cx86unix.cpp)
+(cd crypto/cast/asm; perl cast-586.pl win32 > c-win32.asm)
+
+echo RC4
+(cd crypto/rc4/asm; perl rc4-586.pl cpp > rx86unix.cpp)
+(cd crypto/rc4/asm; perl rc4-586.pl win32 > r4-win32.asm)
+
+echo MD5
+(cd crypto/md5/asm; perl md5-586.pl cpp > mx86unix.cpp)
+(cd crypto/md5/asm; perl md5-586.pl win32 > m5-win32.asm)
+
+echo SHA1
+(cd crypto/sha/asm; perl sha1-586.pl cpp > sx86unix.cpp)
+(cd crypto/sha/asm; perl sha1-586.pl win32 > s1-win32.asm)
+
+echo RIPEMD160
+(cd crypto/ripemd/asm; perl rmd-586.pl cpp > rm86unix.cpp)
+(cd crypto/ripemd/asm; perl rmd-586.pl win32 > rm-win32.asm)
+
+echo RC5/32
+(cd crypto/rc5/asm; perl rc5-586.pl cpp > r586unix.cpp)
+(cd crypto/rc5/asm; perl rc5-586.pl win32 > r5-win32.asm)
diff --git a/deps/openssl/patches/empty_OPENSSL_cpuid_setup.patch b/deps/openssl/patches/empty_OPENSSL_cpuid_setup.patch
new file mode 100644 (file)
index 0000000..58e52ad
--- /dev/null
@@ -0,0 +1,11 @@
+--- openssl-1.0.0f-origin/crypto/cryptlib.c    2011-06-22 23:39:00.000000000 +0800
++++ openssl-1.0.0f/crypto/cryptlib.c   2012-01-19 02:17:50.261681856 +0800
+@@ -690,7 +690,7 @@
+ unsigned long *OPENSSL_ia32cap_loc(void) { return NULL; }
+ #endif
+ int OPENSSL_NONPIC_relocated = 0;
+-#if !defined(OPENSSL_CPUID_SETUP) && !defined(OPENSSL_CPUID_OBJ)
++#if !defined(OPENSSL_CPUID_SETUP)
+ void OPENSSL_cpuid_setup(void) {}
+ #endif
index bf68d3c..4f29839 100644 (file)
@@ -1,22 +1,15 @@
-commit 704cdddfa1c59066a53ecab46c5bfb7238a7a54d
-Author: Adam Langley <agl@chromium.org>
-Date:   Thu Nov 4 16:03:41 2010 -0400
-
-    handshake_cutthrough.patch
-
-diff --git a/apps/s_client.c b/apps/s_client.c
-index 2f743f0..c071658 100644
---- a/apps/s_client.c
-+++ b/apps/s_client.c
+diff -uarp openssl-1.0.0.orig/apps/s_client.c openssl-1.0.0/apps/s_client.c
+--- openssl-1.0.0.orig/apps/s_client.c 2009-12-16 15:28:28.000000000 -0500
++++ openssl-1.0.0/apps/s_client.c      2010-04-21 14:39:49.000000000 -0400
 @@ -248,6 +248,7 @@ static void sc_usage(void)
        BIO_printf(bio_err," -tlsextdebug      - hex dump of all TLS extensions received\n");
        BIO_printf(bio_err," -status           - request certificate status from server\n");
        BIO_printf(bio_err," -no_ticket        - disable use of RFC4507bis session tickets\n");
 +      BIO_printf(bio_err," -cutthrough       - enable 1-RTT full-handshake for strong ciphers\n");
  #endif
-       BIO_printf(bio_err," -legacy_renegotiation - enable use of legacy renegotiation (dangerous)\n");
        }
-@@ -305,6 +306,7 @@ int MAIN(int argc, char **argv)
+@@ -304,6 +305,7 @@ int MAIN(int argc, char **argv)
        EVP_PKEY *key = NULL;
        char *CApath=NULL,*CAfile=NULL,*cipher=NULL;
        int reconnect=0,badop=0,verify=SSL_VERIFY_NONE,bugs=0;
@@ -24,7 +17,7 @@ index 2f743f0..c071658 100644
        int crlf=0;
        int write_tty,read_tty,write_ssl,read_ssl,tty_on,ssl_pending;
        SSL_CTX *ctx=NULL;
-@@ -535,6 +537,8 @@ int MAIN(int argc, char **argv)
+@@ -533,6 +535,8 @@ int MAIN(int argc, char **argv)
                else if (strcmp(*argv,"-no_ticket") == 0)
                        { off|=SSL_OP_NO_TICKET; }
  #endif
@@ -32,8 +25,8 @@ index 2f743f0..c071658 100644
 +                      cutthrough=1;
                else if (strcmp(*argv,"-serverpref") == 0)
                        off|=SSL_OP_CIPHER_SERVER_PREFERENCE;
-               else if (strcmp(*argv,"-legacy_renegotiation") == 0)
-@@ -725,6 +729,15 @@ bad:
+               else if (strcmp(*argv,"-cipher") == 0)
+@@ -714,6 +718,15 @@ bad:
         */
        if (sock_type == SOCK_DGRAM) SSL_CTX_set_read_ahead(ctx, 1);
  
@@ -49,23 +42,29 @@ index 2f743f0..c071658 100644
        if (state) SSL_CTX_set_info_callback(ctx,apps_ssl_info_callback);
        if (cipher != NULL)
                if(!SSL_CTX_set_cipher_list(ctx,cipher)) {
-diff --git a/ssl/s3_clnt.c b/ssl/s3_clnt.c
-index e5138b6..6173dbe 100644
---- a/ssl/s3_clnt.c
-+++ b/ssl/s3_clnt.c
-@@ -182,6 +182,11 @@ int ssl3_connect(SSL *s)
+diff -uarp openssl-1.0.0.orig/ssl/s3_clnt.c openssl-1.0.0/ssl/s3_clnt.c
+--- openssl-1.0.0.orig/ssl/s3_clnt.c   2010-02-27 19:24:24.000000000 -0500
++++ openssl-1.0.0/ssl/s3_clnt.c        2010-04-21 14:39:49.000000000 -0400
+@@ -186,6 +186,18 @@ int ssl3_connect(SSL *s)
        
        s->in_handshake++;
        if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s); 
++#if 0 /* Send app data in separate packet, otherwise, some particular site
++       * (only one site so far) closes the socket.
++       * Note: there is a very small chance that two TCP packets
++       * could be arriving at server combined into a single TCP packet,
++       * then trigger that site to break. We haven't encounter that though.
++       */
 +      if (SSL_get_mode(s) & SSL_MODE_HANDSHAKE_CUTTHROUGH)
 +              {
 +              /* Send app data along with CCS/Finished */
 +              s->s3->flags |= SSL3_FLAGS_DELAY_CLIENT_FINISHED;
 +              }
++#endif
  
        for (;;)
                {
-@@ -450,14 +455,31 @@ int ssl3_connect(SSL *s)
+@@ -454,14 +468,31 @@ int ssl3_connect(SSL *s)
                                }
                        else
                                {
@@ -103,7 +102,7 @@ index e5138b6..6173dbe 100644
                                }
                        s->init_num=0;
                        break;
-@@ -505,6 +527,24 @@ int ssl3_connect(SSL *s)
+@@ -512,6 +541,24 @@ int ssl3_connect(SSL *s)
                        s->state=s->s3->tmp.next_state;
                        break;
  
@@ -128,11 +127,10 @@ index e5138b6..6173dbe 100644
                case SSL_ST_OK:
                        /* clean a few things up */
                        ssl3_cleanup_key_block(s);
-diff --git a/ssl/s3_lib.c b/ssl/s3_lib.c
-index 8fa4ab0..2c44bde 100644
---- a/ssl/s3_lib.c
-+++ b/ssl/s3_lib.c
-@@ -2566,9 +2566,22 @@ int ssl3_write(SSL *s, const void *buf, int len)
+diff -uarp openssl-1.0.0.orig/ssl/s3_lib.c openssl-1.0.0/ssl/s3_lib.c
+-- openssl-1.0.0.orig/ssl/s3_lib.c     2009-10-16 11:24:19.000000000 -0400
++++ openssl-1.0.0/ssl/s3_lib.c  2010-04-21 14:39:49.000000000 -0400
+@@ -2551,9 +2551,22 @@ int ssl3_write(SSL *s, const void *buf, 
  
  static int ssl3_read_internal(SSL *s, void *buf, int len, int peek)
        {
@@ -156,23 +154,21 @@ index 8fa4ab0..2c44bde 100644
        if (s->s3->renegotiate) ssl3_renegotiate_check(s);
        s->s3->in_read_app_data=1;
        ret=s->method->ssl_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len,peek);
-diff --git a/ssl/ssl.h b/ssl/ssl.h
-index 7d4e46e..9ab9495 100644
---- a/ssl/ssl.h
-+++ b/ssl/ssl.h
-@@ -560,7 +560,10 @@ typedef struct ssl_session_st
- #define SSL_MODE_AUTO_RETRY 0x00000004L
- /* Don't attempt to automatically build certificate chain */
- #define SSL_MODE_NO_AUTO_CHAIN 0x00000008L
--
+diff -uarp openssl-1.0.0.orig/ssl/ssl.h openssl-1.0.0/ssl/ssl.h
+--- openssl-1.0.0.orig/ssl/ssl.h       2010-01-06 12:37:38.000000000 -0500
++++ openssl-1.0.0/ssl/ssl.h    2010-04-21 16:57:49.000000000 -0400
+@@ -605,6 +605,10 @@ typedef struct ssl_session_st
+ /* Use small read and write buffers: (a) lazy allocate read buffers for
+  * large incoming records, and (b) limit the size of outgoing records. */
+ #define SSL_MODE_SMALL_BUFFERS 0x00000020L
 +/* When set, clients may send application data before receipt of CCS
 + * and Finished.  This mode enables full-handshakes to 'complete' in
 + * one RTT. */
-+#define SSL_MODE_HANDSHAKE_CUTTHROUGH 0x00000020L
++#define SSL_MODE_HANDSHAKE_CUTTHROUGH 0x00000040L
+
  /* Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value,
   * they cannot be used to clear bits. */
-@@ -1111,10 +1114,12 @@ extern "C" {
+@@ -1097,10 +1101,12 @@ extern "C" {
  /* Is the SSL_connection established? */
  #define SSL_get_state(a)              SSL_state(a)
  #define SSL_is_init_finished(a)               (SSL_state(a) == SSL_ST_OK)
@@ -186,27 +182,25 @@ index 7d4e46e..9ab9495 100644
  
  /* The following 2 states are kept in ssl->rstate when reads fail,
   * you should not need these */
-diff --git a/ssl/ssl3.h b/ssl/ssl3.h
-index 2f579c2..afbdd70 100644
---- a/ssl/ssl3.h
-+++ b/ssl/ssl3.h
+Only in openssl-1.0.0/ssl: ssl.h.orig
+diff -uarp openssl-1.0.0.orig/ssl/ssl3.h openssl-1.0.0/ssl/ssl3.h
+-- openssl-1.0.0.orig/ssl/ssl3.h       2010-01-06 12:37:38.000000000 -0500
++++ openssl-1.0.0/ssl/ssl3.h   2010-04-21 14:39:49.000000000 -0400
 @@ -456,6 +456,7 @@ typedef struct ssl3_state_st
  /*client */
  /* extra state */
  #define SSL3_ST_CW_FLUSH              (0x100|SSL_ST_CONNECT)
-+#define SSL3_ST_CUTTHROUGH_COMPLETE (0x101|SSL_ST_CONNECT)
++#define SSL3_ST_CUTTHROUGH_COMPLETE   (0x101|SSL_ST_CONNECT)
  /* write to server */
  #define SSL3_ST_CW_CLNT_HELLO_A               (0x110|SSL_ST_CONNECT)
  #define SSL3_ST_CW_CLNT_HELLO_B               (0x111|SSL_ST_CONNECT)
-diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c
-index 15650da..96e056d 100644
---- a/ssl/ssl_lib.c
-+++ b/ssl/ssl_lib.c
-@@ -2752,7 +2752,18 @@ void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version, int con
+diff -uarp openssl-1.0.0.orig/ssl/ssl_lib.c openssl-1.0.0/ssl/ssl_lib.c
+--- openssl-1.0.0.orig/ssl/ssl_lib.c   2010-02-17 14:43:46.000000000 -0500
++++ openssl-1.0.0/ssl/ssl_lib.c        2010-04-21 17:02:45.000000000 -0400
+@@ -3031,6 +3031,19 @@ void SSL_set_msg_callback(SSL *ssl, void
        SSL_callback_ctrl(ssl, SSL_CTRL_SET_MSG_CALLBACK, (void (*)(void))cb);
        }
--
+
 +int SSL_cutthrough_complete(const SSL *s)
 +      {
 +      return (!s->server &&                 /* cutthrough only applies to clients */
@@ -219,33 +213,32 @@ index 15650da..96e056d 100644
 +              (s->state == SSL3_ST_CR_SESSION_TICKET_A ||                 /* ready to write app-data*/
 +                      s->state == SSL3_ST_CR_FINISHED_A));
 +      }
- #if defined(_WINDLL) && defined(OPENSSL_SYS_WIN16)
- #include "../crypto/bio/bss_file.c"
-diff --git a/ssl/ssltest.c b/ssl/ssltest.c
-index b09c542..6ddd0aa 100644
---- a/ssl/ssltest.c
-+++ b/ssl/ssltest.c
-@@ -277,6 +277,7 @@ static void sv_usage(void)
-                      "                 (default is sect163r2).\n");
- #endif
++
+ /* Allocates new EVP_MD_CTX and sets pointer to it into given pointer
+  * vairable, freeing  EVP_MD_CTX previously stored in that variable, if
+  * any. If EVP_MD pointer is passed, initializes ctx with this md
+diff -uarp openssl-1.0.0.orig/ssl/ssltest.c openssl-1.0.0/ssl/ssltest.c
+--- openssl-1.0.0.orig/ssl/ssltest.c   2010-01-24 11:57:38.000000000 -0500
++++ openssl-1.0.0/ssl/ssltest.c        2010-04-21 17:06:35.000000000 -0400
+@@ -279,6 +279,7 @@ static void sv_usage(void)
        fprintf(stderr," -test_cipherlist - verifies the order of the ssl cipher lists\n");
-+      fprintf(stderr," -cutthrough       - enable 1-RTT full-handshake for strong ciphers\n");
+       fprintf(stderr," -c_small_records - enable client side use of small SSL record buffers\n");
+       fprintf(stderr," -s_small_records - enable server side use of small SSL record buffers\n");
++      fprintf(stderr," -cutthrough      - enable 1-RTT full-handshake for strong ciphers\n");
        }
  
  static void print_details(SSL *c_ssl, const char *prefix)
-@@ -431,6 +432,8 @@ int main(int argc, char *argv[])
- #ifdef OPENSSL_FIPS
-       int fips_mode=0;
- #endif
-+      int ssl_mode = 0;
+@@ -436,6 +437,7 @@ int main(int argc, char *argv[])
+       int ssl_mode = 0;
+       int c_small_records=0;
+       int s_small_records=0;
 +      int cutthrough = 0;
  
        verbose = 0;
        debug = 0;
-@@ -619,6 +622,10 @@ int main(int argc, char *argv[])
+@@ -632,6 +634,10 @@ int main(int argc, char *argv[])
                        {
-                       test_cipherlist = 1;
+                       s_small_records = 1;
                        }
 +              else if (strcmp(*argv, "-cutthrough") == 0)
 +                      {
@@ -254,9 +247,9 @@ index b09c542..6ddd0aa 100644
                else
                        {
                        fprintf(stderr,"unknown option %s\n",*argv);
-@@ -754,6 +761,13 @@ bad:
-               SSL_CTX_set_cipher_list(c_ctx,cipher);
-               SSL_CTX_set_cipher_list(s_ctx,cipher);
+@@ -782,6 +788,13 @@ bad:
+               ssl_mode |= SSL_MODE_SMALL_BUFFERS;
+               SSL_CTX_set_mode(s_ctx, ssl_mode);
                }
 +      ssl_mode = 0;
 +      if (cutthrough)
@@ -268,17 +261,15 @@ index b09c542..6ddd0aa 100644
  
  #ifndef OPENSSL_NO_DH
        if (!no_dhe)
-diff --git a/test/testssl b/test/testssl
-index 8ac90ae..c0c1c1c 100644
---- a/test/testssl
-+++ b/test/testssl
-@@ -70,6 +70,9 @@ $ssltest -client_auth $CA $extra || exit 1
- echo test sslv2/sslv3 with both client and server authentication
- $ssltest -server_auth -client_auth $CA $extra || exit 1
+diff -uarp openssl-1.0.0.orig/test/testssl openssl-1.0.0/test/testssl
+--- openssl-1.0.0.orig/test/testssl    2006-03-10 18:06:27.000000000 -0500
++++ openssl-1.0.0/test/testssl 2010-04-21 16:50:13.000000000 -0400
+@@ -79,6 +79,8 @@ $ssltest -server_auth -client_auth -s_sm
+ echo test sslv2/sslv3 with both client and server authentication and small client and server buffers
+ $ssltest -server_auth -client_auth -c_small_records -s_small_records $CA $extra || exit 1
  
 +echo test sslv2/sslv3 with both client and server authentication and handshake cutthrough
 +$ssltest -server_auth -client_auth -cutthrough $CA $extra || exit 1
-+
  echo test sslv2 via BIO pair
  $ssltest -bio_pair -ssl2 $extra || exit 1
diff --git a/deps/openssl/patches/jsse.patch b/deps/openssl/patches/jsse.patch
new file mode 100644 (file)
index 0000000..249fb5b
--- /dev/null
@@ -0,0 +1,426 @@
+--- openssl-1.0.0b.orig/ssl/ssl.h      2010-11-30 00:03:46.000000000 +0000
++++ openssl-1.0.0b/ssl/ssl.h   2010-11-30 00:03:47.000000000 +0000
+@@ -1133,6 +1133,9 @@ struct ssl_st
+       /* This can also be in the session once a session is established */
+       SSL_SESSION *session;
++        /* This can be disabled to prevent the use of uncached sessions */
++      int session_creation_enabled;
++
+       /* Default generate session ID callback. */
+       GEN_SESSION_CB generate_session_id;
+@@ -1546,6 +1549,7 @@ const SSL_CIPHER *SSL_get_current_cipher
+ int   SSL_CIPHER_get_bits(const SSL_CIPHER *c,int *alg_bits);
+ char *        SSL_CIPHER_get_version(const SSL_CIPHER *c);
+ const char *  SSL_CIPHER_get_name(const SSL_CIPHER *c);
++const char *  SSL_CIPHER_authentication_method(const SSL_CIPHER *c);
+ int   SSL_get_fd(const SSL *s);
+ int   SSL_get_rfd(const SSL *s);
+@@ -1554,6 +1558,7 @@ const char  * SSL_get_cipher_list(const 
+ char *        SSL_get_shared_ciphers(const SSL *s, char *buf, int len);
+ int   SSL_get_read_ahead(const SSL * s);
+ int   SSL_pending(const SSL *s);
++const char *  SSL_authentication_method(const SSL *c);
+ #ifndef OPENSSL_NO_SOCK
+ int   SSL_set_fd(SSL *s, int fd);
+ int   SSL_set_rfd(SSL *s, int fd);
+@@ -1565,6 +1570,7 @@ BIO *    SSL_get_rbio(const SSL *s);
+ BIO * SSL_get_wbio(const SSL *s);
+ #endif
+ int   SSL_set_cipher_list(SSL *s, const char *str);
++int   SSL_set_cipher_lists(SSL *s, STACK_OF(SSL_CIPHER) *sk);
+ void  SSL_set_read_ahead(SSL *s, int yes);
+ int   SSL_get_verify_mode(const SSL *s);
+ int   SSL_get_verify_depth(const SSL *s);
+@@ -1580,6 +1586,8 @@ int      SSL_use_PrivateKey(SSL *ssl, EVP_PKE
+ int   SSL_use_PrivateKey_ASN1(int pk,SSL *ssl, const unsigned char *d, long len);
+ int   SSL_use_certificate(SSL *ssl, X509 *x);
+ int   SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len);
++int   SSL_use_certificate_chain(SSL *ssl, STACK_OF(X509) *cert_chain);
++STACK_OF(X509) * SSL_get_certificate_chain(SSL *ssl, X509 *x);
+ #ifndef OPENSSL_NO_STDIO
+ int   SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type);
+@@ -1615,6 +1623,7 @@ void     SSL_copy_session_id(SSL *to,const S
+ SSL_SESSION *SSL_SESSION_new(void);
+ const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s,
+                                       unsigned int *len);
++const char *  SSL_SESSION_get_version(const SSL_SESSION *s);
+ #ifndef OPENSSL_NO_FP_API
+ int   SSL_SESSION_print_fp(FILE *fp,const SSL_SESSION *ses);
+ #endif
+@@ -1624,6 +1633,7 @@ int      SSL_SESSION_print(BIO *fp,const SSL_
+ void  SSL_SESSION_free(SSL_SESSION *ses);
+ int   i2d_SSL_SESSION(SSL_SESSION *in,unsigned char **pp);
+ int   SSL_set_session(SSL *to, SSL_SESSION *session);
++void  SSL_set_session_creation_enabled(SSL *, int);
+ int   SSL_CTX_add_session(SSL_CTX *s, SSL_SESSION *c);
+ int   SSL_CTX_remove_session(SSL_CTX *,SSL_SESSION *c);
+ int   SSL_CTX_set_generate_session_id(SSL_CTX *, GEN_SESSION_CB);
+@@ -2066,6 +2076,7 @@ void ERR_load_SSL_strings(void);
+ #define SSL_F_SSL_UNDEFINED_VOID_FUNCTION              244
+ #define SSL_F_SSL_USE_CERTIFICATE                      198
+ #define SSL_F_SSL_USE_CERTIFICATE_ASN1                         199
++#define SSL_F_SSL_USE_CERTIFICATE_CHAIN                        2000
+ #define SSL_F_SSL_USE_CERTIFICATE_FILE                         200
+ #define SSL_F_SSL_USE_PRIVATEKEY                       201
+ #define SSL_F_SSL_USE_PRIVATEKEY_ASN1                  202
+@@ -2272,6 +2283,7 @@ void ERR_load_SSL_strings(void);
+ #define SSL_R_SCSV_RECEIVED_WHEN_RENEGOTIATING                 345
+ #define SSL_R_SERVERHELLO_TLSEXT                       275
+ #define SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED                 277
++#define SSL_R_SESSION_MAY_NOT_BE_CREATED               2000
+ #define SSL_R_SHORT_READ                               219
+ #define SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE    220
+ #define SSL_R_SSL23_DOING_SESSION_ID_REUSE             221
+--- openssl-1.0.0b.orig/ssl/d1_clnt.c  2010-01-26 19:46:29.000000000 +0000
++++ openssl-1.0.0b/ssl/d1_clnt.c       2010-11-30 00:03:47.000000000 +0000
+@@ -613,6 +613,12 @@ int dtls1_client_hello(SSL *s)
+ #endif
+                       (s->session->not_resumable))
+                       {
++                      if (!s->session_creation_enabled)
++                              {
++                              ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
++                              SSLerr(SSL_F_DTLS1_CLIENT_HELLO,SSL_R_SESSION_MAY_NOT_BE_CREATED);
++                              goto err;
++                              }
+                       if (!ssl_get_new_session(s,0))
+                               goto err;
+                       }
+--- openssl-1.0.0b.orig/ssl/s23_clnt.c 2010-02-16 14:20:40.000000000 +0000
++++ openssl-1.0.0b/ssl/s23_clnt.c      2010-11-30 00:03:47.000000000 +0000
+@@ -687,6 +687,13 @@ static int ssl23_get_server_hello(SSL *s
+       /* Since, if we are sending a ssl23 client hello, we are not
+        * reusing a session-id */
++        if (!s->session_creation_enabled)
++              {
++              if (!(s->client_version == SSL2_VERSION))
++                      ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
++              SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_SESSION_MAY_NOT_BE_CREATED);
++              goto err;
++              }
+       if (!ssl_get_new_session(s,0))
+               goto err;
+--- openssl-1.0.0b.orig/ssl/s3_both.c  2010-11-30 00:03:46.000000000 +0000
++++ openssl-1.0.0b/ssl/s3_both.c       2010-11-30 00:03:47.000000000 +0000
+@@ -347,8 +347,11 @@ unsigned long ssl3_output_cert_chain(SSL
+       unsigned long l=7;
+       BUF_MEM *buf;
+       int no_chain;
++      STACK_OF(X509) *cert_chain;
+-      if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || s->ctx->extra_certs)
++      cert_chain = SSL_get_certificate_chain(s, x);
++
++      if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || s->ctx->extra_certs || cert_chain)
+               no_chain = 1;
+       else
+               no_chain = 0;
+@@ -400,6 +403,10 @@ unsigned long ssl3_output_cert_chain(SSL
+                       return(0);
+               }
++      for (i=0; i<sk_X509_num(cert_chain); i++)
++              if (ssl3_add_cert_to_buf(buf, &l, sk_X509_value(cert_chain,i)))
++                      return(0);
++
+       l-=7;
+       p=(unsigned char *)&(buf->data[4]);
+       l2n3(l,p);
+--- openssl-1.0.0b.orig/ssl/s3_clnt.c  2010-11-30 00:03:46.000000000 +0000
++++ openssl-1.0.0b/ssl/s3_clnt.c       2010-11-30 00:03:47.000000000 +0000
+@@ -686,6 +686,12 @@ int ssl3_client_hello(SSL *s)
+ #endif
+                       (sess->not_resumable))
+                       {
++                      if (!s->session_creation_enabled)
++                              {
++                              ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
++                              SSLerr(SSL_F_SSL3_CLIENT_HELLO,SSL_R_SESSION_MAY_NOT_BE_CREATED);
++                              goto err;
++                              }
+                       if (!ssl_get_new_session(s,0))
+                               goto err;
+                       }
+@@ -894,6 +900,12 @@ int ssl3_get_server_hello(SSL *s)
+               s->hit=0;
+               if (s->session->session_id_length > 0)
+                       {
++                      if (!s->session_creation_enabled)
++                              {
++                              ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
++                              SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_SESSION_MAY_NOT_BE_CREATED);
++                              goto err;
++                              }
+                       if (!ssl_get_new_session(s,0))
+                               {
+                               al=SSL_AD_INTERNAL_ERROR;
+--- openssl-1.0.0b.orig/ssl/s3_srvr.c  2010-11-30 00:03:46.000000000 +0000
++++ openssl-1.0.0b/ssl/s3_srvr.c       2010-11-30 00:03:47.000000000 +0000
+@@ -902,6 +902,12 @@ int ssl3_get_client_hello(SSL *s)
+        */
+       if ((s->new_session && (s->options & SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION)))
+               {
++              if (!s->session_creation_enabled)
++                      {
++                      ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
++                      SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_SESSION_MAY_NOT_BE_CREATED);
++                      goto err;
++              }
+               if (!ssl_get_new_session(s,1))
+                       goto err;
+               }
+@@ -916,6 +922,12 @@ int ssl3_get_client_hello(SSL *s)
+                       goto err;
+               else /* i == 0 */
+                       {
++                      if (!s->session_creation_enabled)
++                              {
++                              ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
++                              SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_SESSION_MAY_NOT_BE_CREATED);
++                              goto err;
++                              }
+                       if (!ssl_get_new_session(s,1))
+                               goto err;
+                       }
+--- openssl-1.0.0b.orig/ssl/ssl_ciph.c 2010-06-15 17:25:14.000000000 +0000
++++ openssl-1.0.0b/ssl/ssl_ciph.c      2010-11-30 00:03:47.000000000 +0000
+@@ -1652,6 +1652,52 @@ int SSL_CIPHER_get_bits(const SSL_CIPHER
+       return(ret);
+       }
++/* return string version of key exchange algorithm */
++const char* SSL_CIPHER_authentication_method(const SSL_CIPHER* cipher)
++      {
++      switch (cipher->algorithm_mkey)
++              {
++      case SSL_kRSA:
++              return SSL_TXT_RSA;
++      case SSL_kDHr:
++              return SSL_TXT_DH "_" SSL_TXT_RSA;
++      case SSL_kDHd:
++              return SSL_TXT_DH "_" SSL_TXT_DSS;
++      case SSL_kEDH:
++              switch (cipher->algorithm_auth)
++                      {
++              case SSL_aDSS:
++                      return "DHE_" SSL_TXT_DSS;
++              case SSL_aRSA:
++                      return "DHE_" SSL_TXT_RSA;
++              case SSL_aNULL:
++                      return SSL_TXT_DH "_anon";
++              default:
++                      return "UNKNOWN";
++                        }
++      case SSL_kKRB5:
++              return SSL_TXT_KRB5;
++      case SSL_kECDHr:
++              return SSL_TXT_ECDH "_" SSL_TXT_RSA;
++      case SSL_kECDHe:
++              return SSL_TXT_ECDH "_" SSL_TXT_ECDSA;
++      case SSL_kEECDH:
++              switch (cipher->algorithm_auth)
++                      {
++              case SSL_aECDSA:
++                      return "ECDHE_" SSL_TXT_ECDSA;
++              case SSL_aRSA:
++                      return "ECDHE_" SSL_TXT_RSA;
++              case SSL_aNULL:
++                      return SSL_TXT_ECDH "_anon";
++              default:
++                      return "UNKNOWN";
++                        }
++        default:
++              return "UNKNOWN";
++              }
++      }
++
+ SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n)
+       {
+       SSL_COMP *ctmp;
+--- openssl-1.0.0b.orig/ssl/ssl_err.c  2010-11-30 00:03:46.000000000 +0000
++++ openssl-1.0.0b/ssl/ssl_err.c       2010-11-30 00:03:47.000000000 +0000
+@@ -465,6 +465,7 @@ static ERR_STRING_DATA SSL_str_reasons[]
+ {ERR_REASON(SSL_R_SCSV_RECEIVED_WHEN_RENEGOTIATING),"scsv received when renegotiating"},
+ {ERR_REASON(SSL_R_SERVERHELLO_TLSEXT)    ,"serverhello tlsext"},
+ {ERR_REASON(SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED),"session id context uninitialized"},
++{ERR_REASON(SSL_R_SESSION_MAY_NOT_BE_CREATED),"session may not be created"},
+ {ERR_REASON(SSL_R_SHORT_READ)            ,"short read"},
+ {ERR_REASON(SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE),"signature for non signing certificate"},
+ {ERR_REASON(SSL_R_SSL23_DOING_SESSION_ID_REUSE),"ssl23 doing session id reuse"},
+--- openssl-1.0.0b.orig/ssl/ssl_lib.c  2010-11-30 00:03:46.000000000 +0000
++++ openssl-1.0.0b/ssl/ssl_lib.c       2010-11-30 00:03:47.000000000 +0000
+@@ -326,6 +326,7 @@ SSL *SSL_new(SSL_CTX *ctx)
+       OPENSSL_assert(s->sid_ctx_length <= sizeof s->sid_ctx);
+       memcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx));
+       s->verify_callback=ctx->default_verify_callback;
++      s->session_creation_enabled=1;
+       s->generate_session_id=ctx->generate_session_id;
+       s->param = X509_VERIFY_PARAM_new();
+@@ -1311,6 +1312,32 @@ int SSL_set_cipher_list(SSL *s,const cha
+       return 1;
+       }
++/** specify the ciphers to be used by the SSL */
++int SSL_set_cipher_lists(SSL *s,STACK_OF(SSL_CIPHER) *sk)
++      {
++      STACK_OF(SSL_CIPHER) *tmp_cipher_list;
++
++      if (sk == NULL)
++              return 0;
++
++        /* Based on end of ssl_create_cipher_list */
++      tmp_cipher_list = sk_SSL_CIPHER_dup(sk);
++      if (tmp_cipher_list == NULL)
++              {
++              return 0;
++              }
++      if (s->cipher_list != NULL)
++              sk_SSL_CIPHER_free(s->cipher_list);
++      s->cipher_list = sk;
++      if (s->cipher_list_by_id != NULL)
++              sk_SSL_CIPHER_free(s->cipher_list_by_id);
++      s->cipher_list_by_id = tmp_cipher_list;
++      (void)sk_SSL_CIPHER_set_cmp_func(s->cipher_list_by_id,ssl_cipher_ptr_id_cmp);
++
++      sk_SSL_CIPHER_sort(s->cipher_list_by_id);
++      return 1;
++      }
++
+ /* works well for SSLv2, not so good for SSLv3 */
+ char *SSL_get_shared_ciphers(const SSL *s,char *buf,int len)
+       {
+@@ -2551,18 +2578,45 @@ SSL_METHOD *ssl_bad_method(int ver)
+       return(NULL);
+       }
+-const char *SSL_get_version(const SSL *s)
++static const char *ssl_get_version(int version)
+       {
+-      if (s->version == TLS1_VERSION)
++      if (version == TLS1_VERSION)
+               return("TLSv1");
+-      else if (s->version == SSL3_VERSION)
++      else if (version == SSL3_VERSION)
+               return("SSLv3");
+-      else if (s->version == SSL2_VERSION)
++      else if (version == SSL2_VERSION)
+               return("SSLv2");
+       else
+               return("unknown");
+       }
++const char *SSL_get_version(const SSL *s)
++      {
++              return ssl_get_version(s->version);
++      }
++
++const char *SSL_SESSION_get_version(const SSL_SESSION *s)
++      {
++              return ssl_get_version(s->ssl_version);
++      }
++
++const char* SSL_authentication_method(const SSL* ssl)
++      {
++      if (ssl->cert != NULL && ssl->cert->rsa_tmp != NULL)
++              return SSL_TXT_RSA "_" SSL_TXT_EXPORT;
++      switch (ssl->version)
++              {
++      case SSL2_VERSION:
++              return SSL_TXT_RSA;
++      case SSL3_VERSION:
++      case TLS1_VERSION:
++      case DTLS1_VERSION:
++              return SSL_CIPHER_authentication_method(ssl->s3->tmp.new_cipher);
++      default:
++              return "UNKNOWN";
++              }
++      }
++
+ SSL *SSL_dup(SSL *s)
+       {
+       STACK_OF(X509_NAME) *sk;
+--- openssl-1.0.0b.orig/ssl/ssl_locl.h 2010-11-30 00:03:46.000000000 +0000
++++ openssl-1.0.0b/ssl/ssl_locl.h      2010-11-30 00:03:47.000000000 +0000
+@@ -456,6 +456,7 @@
+ typedef struct cert_pkey_st
+       {
+       X509 *x509;
++      STACK_OF(X509) *cert_chain;
+       EVP_PKEY *privatekey;
+       } CERT_PKEY;
+--- openssl-1.0.0b.orig/ssl/ssl_rsa.c  2009-09-12 23:09:26.000000000 +0000
++++ openssl-1.0.0b/ssl/ssl_rsa.c       2010-11-30 00:03:47.000000000 +0000
+@@ -697,6 +697,42 @@ int SSL_CTX_use_PrivateKey_ASN1(int type
+       }
++int SSL_use_certificate_chain(SSL *ssl, STACK_OF(X509) *cert_chain)
++      {
++      if (ssl == NULL)
++              {
++              SSLerr(SSL_F_SSL_USE_CERTIFICATE_CHAIN,ERR_R_PASSED_NULL_PARAMETER);
++              return(0);
++              }
++      if (ssl->cert == NULL)
++              {
++              SSLerr(SSL_F_SSL_USE_CERTIFICATE_CHAIN,SSL_R_NO_CERTIFICATE_ASSIGNED);
++              return(0);
++              }
++      if (ssl->cert->key == NULL)
++              {
++              SSLerr(SSL_F_SSL_USE_CERTIFICATE_CHAIN,SSL_R_NO_CERTIFICATE_ASSIGNED);
++              return(0);
++              }
++      ssl->cert->key->cert_chain = cert_chain;
++      return(1);
++      }
++
++STACK_OF(X509) *SSL_get_certificate_chain(SSL *ssl, X509 *x)
++      {
++      int i;
++      if (x == NULL)
++              return NULL;
++      if (ssl == NULL)
++              return NULL;
++      if (ssl->cert == NULL)
++              return NULL;
++      for (i = 0; i < SSL_PKEY_NUM; i++)
++              if (ssl->cert->pkeys[i].x509 == x)
++                      return ssl->cert->pkeys[i].cert_chain;
++      return NULL;
++      }
++
+ #ifndef OPENSSL_NO_STDIO
+ /* Read a file that contains our certificate in "PEM" format,
+  * possibly followed by a sequence of CA certificates that should be
+--- openssl-1.0.0b.orig/ssl/ssl_sess.c 2010-02-01 16:49:42.000000000 +0000
++++ openssl-1.0.0b/ssl/ssl_sess.c      2010-11-30 00:03:47.000000000 +0000
+@@ -261,6 +261,11 @@ static int def_generate_session_id(const
+       return 0;
+ }
++void SSL_set_session_creation_enabled (SSL *s, int creation_enabled)
++      {
++      s->session_creation_enabled = creation_enabled;
++      }
++
+ int ssl_get_new_session(SSL *s, int session)
+       {
+       /* This gets used by clients and servers. */
+@@ -269,6 +274,8 @@ int ssl_get_new_session(SSL *s, int sess
+       SSL_SESSION *ss=NULL;
+       GEN_SESSION_CB cb = def_generate_session_id;
++      /* caller should check this if they can do better error handling */
++        if (!s->session_creation_enabled) return(0);
+       if ((ss=SSL_SESSION_new()) == NULL) return(0);
+       /* If the context has a default timeout, use it */
diff --git a/deps/openssl/patches/missing_stddef.patch b/deps/openssl/patches/missing_stddef.patch
deleted file mode 100644 (file)
index 9b551b8..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-commit 90641d2d6d251d014815e1703157f0cd0a6d5ea1
-Author: Adam Langley <agl@chromium.org>
-Date:   Thu Nov 4 16:02:17 2010 -0400
-
-    missing_stddef.patch
-
-diff --git a/crypto/md2/md2.h b/crypto/md2/md2.h
-index d59c9f2..75446fd 100644
---- a/crypto/md2/md2.h
-+++ b/crypto/md2/md2.h
-@@ -72,6 +72,8 @@
- extern "C" {
- #endif
-+#include <stddef.h>
-+
- typedef struct MD2state_st
-       {
-       unsigned int num;
-diff --git a/crypto/md4/md4.h b/crypto/md4/md4.h
-index ba1fe4a..d9b2717 100644
---- a/crypto/md4/md4.h
-+++ b/crypto/md4/md4.h
-@@ -66,6 +66,8 @@
- extern "C" {
- #endif
-+#include <stddef.h>
-+
- #ifdef OPENSSL_NO_MD4
- #error MD4 is disabled.
- #endif
-diff --git a/crypto/md5/md5.h b/crypto/md5/md5.h
-index 0761f84..1a51bcf 100644
---- a/crypto/md5/md5.h
-+++ b/crypto/md5/md5.h
-@@ -66,6 +66,8 @@
- extern "C" {
- #endif
-+#include <stddef.h>
-+
- #ifdef OPENSSL_NO_MD5
- #error MD5 is disabled.
- #endif
-diff --git a/crypto/ripemd/ripemd.h b/crypto/ripemd/ripemd.h
-index 3b6d043..70a9637 100644
---- a/crypto/ripemd/ripemd.h
-+++ b/crypto/ripemd/ripemd.h
-@@ -66,6 +66,8 @@
- extern "C" {
- #endif
-+#include <stddef.h>
-+
- #ifdef OPENSSL_NO_RIPEMD
- #error RIPEMD is disabled.
- #endif
-diff --git a/crypto/sha/sha.h b/crypto/sha/sha.h
-index 47a2c29..1f6ad37 100644
---- a/crypto/sha/sha.h
-+++ b/crypto/sha/sha.h
-@@ -66,6 +66,8 @@
- extern "C" {
- #endif
-+#include <stddef.h>
-+
- #if defined(OPENSSL_NO_SHA) || (defined(OPENSSL_NO_SHA0) && defined(OPENSSL_NO_SHA1))
- #error SHA is disabled.
- #endif
similarity index 58%
rename from deps/openssl/patches/next_proto_neg.patch
rename to deps/openssl/patches/npn.patch
index 4fc045a..46b7a7d 100644 (file)
@@ -1,25 +1,17 @@
-commit ed5845e49b3c76f8735ec00e151a7b234acc266c
-Author: Adam Langley <agl@chromium.org>
-Date:   Thu Nov 4 16:06:58 2010 -0400
-
-    next_proto_neg.patch
-
-diff --git a/apps/apps.c b/apps/apps.c
-index ab60b70..eede8a8 100644
---- a/apps/apps.c
-+++ b/apps/apps.c
-@@ -2579,3 +2579,45 @@ void jpake_server_auth(BIO *out, BIO *conn, const char *secret)
-       }
+--- openssl-1.0.0b.orig/apps/apps.c    2010-11-11 14:42:19.000000000 +0000
++++ openssl-1.0.0b/apps/apps.c 2010-11-29 19:56:04.902465346 +0000
+@@ -3012,3 +3012,46 @@ int raw_write_stdout(const void *buf,int
+ int raw_write_stdout(const void *buf,int siz)
+       {       return write(fileno(stdout),buf,siz);   }
  #endif
 +
++#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
 +/* next_protos_parse parses a comma separated list of strings into a string
 + * in a format suitable for passing to SSL_CTX_set_next_protos_advertised.
 + *   outlen: (output) set to the length of the resulting buffer on success.
-+ *   err: (maybe NULL) on failure, an error message line is written to this BIO.
 + *   in: a NUL termianted string like "abc,def,ghi"
 + *
-+ *   returns: a malloced buffer
++ *   returns: a malloced buffer or NULL on failure.
 + */
 +unsigned char *next_protos_parse(unsigned short *outlen, const char *in)
 +      {
@@ -28,7 +20,7 @@ index ab60b70..eede8a8 100644
 +      size_t i, start = 0;
 +
 +      len = strlen(in);
-+      if (len > 65535)
++      if (len >= 65535)
 +              return NULL;
 +
 +      out = OPENSSL_malloc(strlen(in) + 1);
@@ -54,32 +46,35 @@ index ab60b70..eede8a8 100644
 +      *outlen = len + 1;
 +      return out;
 +      }
-diff --git a/apps/s_apps.h b/apps/s_apps.h
-index f5a39ba..513bcfe 100644
---- a/apps/s_apps.h
-+++ b/apps/s_apps.h
-@@ -174,3 +174,5 @@ void MS_CALLBACK tlsext_cb(SSL *s, int client_server, int type,
- int MS_CALLBACK generate_cookie_callback(SSL *ssl, unsigned char *cookie, unsigned int *cookie_len);
- int MS_CALLBACK verify_cookie_callback(SSL *ssl, unsigned char *cookie, unsigned int cookie_len);
++#endif  /* !OPENSSL_NO_TLSEXT && !OPENSSL_NO_NEXTPROTONEG */
+--- openssl-1.0.0b.orig/apps/apps.h    2009-10-31 13:34:19.000000000 +0000
++++ openssl-1.0.0b/apps/apps.h 2010-11-29 19:56:04.902465346 +0000
+@@ -358,3 +358,7 @@ int raw_write_stdout(const void *,int);
+ #define TM_STOP               1
+ double app_tminterval (int stop,int usertime);
+ #endif
 +
++#ifndef OPENSSL_NO_NEXTPROTONEG
 +unsigned char *next_protos_parse(unsigned short *outlen, const char *in);
-diff --git a/apps/s_client.c b/apps/s_client.c
-index c071658..6033e77 100644
---- a/apps/s_client.c
-+++ b/apps/s_client.c
-@@ -249,6 +249,7 @@ static void sc_usage(void)
++#endif
+--- openssl-1.0.0b.orig/apps/s_client.c        2010-11-29 19:56:04.832465351 +0000
++++ openssl-1.0.0b/apps/s_client.c     2010-11-29 19:56:04.902465346 +0000
+@@ -342,6 +342,9 @@ static void sc_usage(void)
+       BIO_printf(bio_err," -tlsextdebug      - hex dump of all TLS extensions received\n");
        BIO_printf(bio_err," -status           - request certificate status from server\n");
        BIO_printf(bio_err," -no_ticket        - disable use of RFC4507bis session tickets\n");
-       BIO_printf(bio_err," -cutthrough       - enable 1-RTT full-handshake for strong ciphers\n");
++# ifndef OPENSSL_NO_NEXTPROTONEG
 +      BIO_printf(bio_err," -nextprotoneg arg - enable NPN extension, considering named protocols supported (comma-separated list)\n");
++# endif
+       BIO_printf(bio_err," -cutthrough       - enable 1-RTT full-handshake for strong ciphers\n");
  #endif
        BIO_printf(bio_err," -legacy_renegotiation - enable use of legacy renegotiation (dangerous)\n");
+@@ -367,6 +370,40 @@ static int MS_CALLBACK ssl_servername_cb
+       
+       return SSL_TLSEXT_ERR_OK;
        }
-@@ -284,6 +285,38 @@ enum
-       PROTO_XMPP
- };
++
++# ifndef OPENSSL_NO_NEXTPROTONEG
 +/* This the context that we pass to next_proto_cb */
 +typedef struct tlsextnextprotoctx_st {
 +      unsigned char *data;
@@ -111,35 +106,39 @@ index c071658..6033e77 100644
 +      ctx->status = SSL_select_next_proto(out, outlen, in, inlen, ctx->data, ctx->len);
 +      return SSL_TLSEXT_ERR_OK;
 +      }
-+
- int MAIN(int, char **);
++# endif  /* ndef OPENSSL_NO_NEXTPROTONEG */
+ #endif
  
- int MAIN(int argc, char **argv)
-@@ -336,6 +369,7 @@ int MAIN(int argc, char **argv)
+ enum
+@@ -431,6 +468,9 @@ int MAIN(int argc, char **argv)
        char *servername = NULL; 
          tlsextctx tlsextcbp = 
          {NULL,0};
++# ifndef OPENSSL_NO_NEXTPROTONEG
 +      const char *next_proto_neg_in = NULL;
++# endif
  #endif
        char *sess_in = NULL;
        char *sess_out = NULL;
-@@ -536,6 +570,11 @@ int MAIN(int argc, char **argv)
+@@ -658,6 +698,13 @@ int MAIN(int argc, char **argv)
  #ifndef OPENSSL_NO_TLSEXT
                else if (strcmp(*argv,"-no_ticket") == 0)
                        { off|=SSL_OP_NO_TICKET; }
++# ifndef OPENSSL_NO_NEXTPROTONEG
 +              else if (strcmp(*argv,"-nextprotoneg") == 0)
 +                      {
 +                      if (--argc < 1) goto bad;
 +                      next_proto_neg_in = *(++argv);
 +                      }
++# endif
  #endif
                else if (strcmp(*argv,"-cutthrough") == 0)
                        cutthrough=1;
-@@ -624,6 +663,21 @@ bad:
+@@ -766,6 +813,21 @@ bad:
        OpenSSL_add_ssl_algorithms();
        SSL_load_error_strings();
  
-+#ifndef OPENSSL_NO_TLSEXT
++#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
 +      next_proto.status = -1;
 +      if (next_proto_neg_in)
 +              {
@@ -157,62 +156,61 @@ index c071658..6033e77 100644
  #ifndef OPENSSL_NO_ENGINE
          e = setup_engine(bio_err, engine_id, 1);
        if (ssl_client_engine_id)
-@@ -738,6 +792,9 @@ bad:
+@@ -896,6 +958,11 @@ bad:
                SSL_CTX_set_mode(ctx, ssl_mode);
                }
  
++#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
 +      if (next_proto.data)
 +              SSL_CTX_set_next_proto_select_cb(ctx, next_proto_cb, &next_proto);
++#endif
 +
        if (state) SSL_CTX_set_info_callback(ctx,apps_ssl_info_callback);
        if (cipher != NULL)
                if(!SSL_CTX_set_cipher_list(ctx,cipher)) {
-@@ -1555,6 +1612,20 @@ static void print_stuff(BIO *bio, SSL *s, int full)
+@@ -1755,6 +1822,18 @@ static void print_stuff(BIO *bio, SSL *s
        BIO_printf(bio,"Expansion: %s\n",
                expansion ? SSL_COMP_get_name(expansion) : "NONE");
  #endif
 +
-+#ifndef OPENSSL_NO_TLSEXT
-+      {
-+              if (next_proto.status != -1) {
-+                      const unsigned char *proto;
-+                      unsigned int proto_len;
-+                      SSL_get0_next_proto_negotiated(s, &proto, &proto_len);
-+                      BIO_printf(bio, "Next protocol: (%d) ", next_proto.status);
-+                      BIO_write(bio, proto, proto_len);
-+                      BIO_write(bio, "\n", 1);
-+              }
++#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
++      if (next_proto.status != -1) {
++              const unsigned char *proto;
++              unsigned int proto_len;
++              SSL_get0_next_proto_negotiated(s, &proto, &proto_len);
++              BIO_printf(bio, "Next protocol: (%d) ", next_proto.status);
++              BIO_write(bio, proto, proto_len);
++              BIO_write(bio, "\n", 1);
 +      }
 +#endif
 +
        SSL_SESSION_print(bio,SSL_get_session(s));
        BIO_printf(bio,"---\n");
        if (peer != NULL)
-diff --git a/apps/s_server.c b/apps/s_server.c
-index 88b308c..c4e19c9 100644
---- a/apps/s_server.c
-+++ b/apps/s_server.c
-@@ -405,6 +405,7 @@ static void sv_usage(void)
+--- openssl-1.0.0b.orig/apps/s_server.c        2010-06-15 17:25:02.000000000 +0000
++++ openssl-1.0.0b/apps/s_server.c     2010-11-29 19:56:04.902465346 +0000
+@@ -492,6 +492,9 @@ static void sv_usage(void)
        BIO_printf(bio_err," -tlsextdebug  - hex dump of all TLS extensions received\n");
        BIO_printf(bio_err," -no_ticket    - disable use of RFC4507bis session tickets\n");
        BIO_printf(bio_err," -legacy_renegotiation - enable use of legacy renegotiation (dangerous)\n");
++# ifndef OPENSSL_NO_NEXTPROTONEG
 +      BIO_printf(bio_err," -nextprotoneg arg - set the advertised protocols for the NPN extension (comma-separated list)\n");
++# endif
  #endif
        }
  
-@@ -740,6 +741,26 @@ BIO_printf(err, "cert_status: received %d ids\n", sk_OCSP_RESPID_num(ids));
+@@ -826,6 +829,24 @@ BIO_printf(err, "cert_status: received %
+       ret = SSL_TLSEXT_ERR_ALERT_FATAL;
        goto done;
        }
- #endif
 +
-+
-+/* This the context that we pass to next_proto_cb */
++# ifndef OPENSSL_NO_NEXTPROTONEG
++/* This is the context that we pass to next_proto_cb */
 +typedef struct tlsextnextprotoctx_st {
 +      unsigned char *data;
 +      unsigned int len;
 +} tlsextnextprotoctx;
 +
-+
 +static int next_proto_cb(SSL *s, const unsigned char **data, unsigned int *len, void *arg)
 +      {
 +      tlsextnextprotoctx *next_proto = arg;
@@ -222,38 +220,53 @@ index 88b308c..c4e19c9 100644
 +
 +      return SSL_TLSEXT_ERR_OK;
 +      }
-+
-+
- int MAIN(int, char **);
++# endif  /* ndef OPENSSL_NO_NPN */
+ #endif
  
- #ifndef OPENSSL_NO_JPAKE
-@@ -779,6 +800,8 @@ int MAIN(int argc, char *argv[])
+ int MAIN(int, char **);
+@@ -867,6 +888,10 @@ int MAIN(int argc, char *argv[])
  #endif
  #ifndef OPENSSL_NO_TLSEXT
          tlsextctx tlsextcbp = {NULL, NULL, SSL_TLSEXT_ERR_ALERT_WARNING};
++# ifndef OPENSSL_NO_NEXTPROTONEG
 +      const char *next_proto_neg_in = NULL;
 +      tlsextnextprotoctx next_proto;
++# endif
  #endif
- #if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL3)
-@@ -1077,7 +1100,11 @@ int MAIN(int argc, char *argv[])
+ #ifndef OPENSSL_NO_PSK
+       /* by default do not send a PSK identity hint */
+@@ -1191,7 +1216,13 @@ int MAIN(int argc, char *argv[])
                        if (--argc < 1) goto bad;
                        s_key_file2= *(++argv);
                        }
 -                      
++# ifndef OPENSSL_NO_NEXTPROTONEG
 +              else if (strcmp(*argv,"-nextprotoneg") == 0)
 +                      {
 +                      if (--argc < 1) goto bad;
 +                      next_proto_neg_in = *(++argv);
 +                      }
++# endif
  #endif
- #ifndef OPENSSL_NO_JPAKE
+ #if !defined(OPENSSL_NO_JPAKE) && !defined(OPENSSL_NO_PSK)
                else if (strcmp(*argv,"-jpake") == 0)
-@@ -1162,6 +1189,20 @@ bad:
-                               goto end;
-                               }
-                       }
+@@ -1476,6 +1507,11 @@ bad:
+               if (vpm)
+                       SSL_CTX_set1_param(ctx2, vpm);
+               }
 +
++# ifndef OPENSSL_NO_NEXTPROTONEG
++      if (next_proto.data)
++              SSL_CTX_set_next_protos_advertised_cb(ctx, next_proto_cb, &next_proto);
++# endif
+ #endif 
+ #ifndef OPENSSL_NO_DH
+@@ -1617,6 +1653,21 @@ bad:
+                                       goto end;
+                                       }
+                               }
++# ifndef OPENSSL_NO_NEXTPROTONEG
 +              if (next_proto_neg_in)
 +                      {
 +                      unsigned short len;
@@ -267,57 +280,204 @@ index 88b308c..c4e19c9 100644
 +                      {
 +                      next_proto.data = NULL;
 +                      }
++# endif
  #endif
-               }
-       if (s_dcert_file)
-@@ -1341,6 +1382,11 @@ bad:
-               store = SSL_CTX_get_cert_store(ctx2);
-               X509_STORE_set_flags(store, vflags);
-               }
-+
-+      if (next_proto.data)
-+              {
-+              SSL_CTX_set_next_protos_advertised_cb(ctx, next_proto_cb, &next_proto);
-+              }
- #endif 
-@@ -1980,6 +2026,10 @@ static int init_ssl_connection(SSL *con)
+               RSA_free(rsa);
+               BIO_printf(bio_s_out,"\n");
+@@ -2159,6 +2210,10 @@ static int init_ssl_connection(SSL *con)
        X509 *peer;
        long verify_error;
        MS_STATIC char buf[BUFSIZ];
-+#ifndef OPENSSL_NO_TLSEXT
++#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
 +      const unsigned char *next_proto_neg;
 +      unsigned next_proto_neg_len;
 +#endif
  
        if ((i=SSL_accept(con)) <= 0)
                {
-@@ -2019,6 +2069,14 @@ static int init_ssl_connection(SSL *con)
+@@ -2198,6 +2253,15 @@ static int init_ssl_connection(SSL *con)
                BIO_printf(bio_s_out,"Shared ciphers:%s\n",buf);
        str=SSL_CIPHER_get_name(SSL_get_current_cipher(con));
        BIO_printf(bio_s_out,"CIPHER is %s\n",(str != NULL)?str:"(NONE)");
-+#ifndef OPENSSL_NO_TLSEXT
++#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
 +      SSL_get0_next_proto_negotiated(con, &next_proto_neg, &next_proto_neg_len);
-+      if (next_proto_neg) {
++      if (next_proto_neg)
++              {
 +              BIO_printf(bio_s_out,"NEXTPROTO is ");
 +              BIO_write(bio_s_out, next_proto_neg, next_proto_neg_len);
 +              BIO_printf(bio_s_out, "\n");
-+      }
++              }
 +#endif
        if (con->hit) BIO_printf(bio_s_out,"Reused session-id\n");
        if (SSL_ctrl(con,SSL_CTRL_GET_FLAGS,0,NULL) &
                TLS1_FLAGS_TLS_PADDING_BUG)
-diff --git a/ssl/s3_both.c b/ssl/s3_both.c
-index 869a25d..b88288e 100644
---- a/ssl/s3_both.c
-+++ b/ssl/s3_both.c
-@@ -204,16 +204,34 @@ int ssl3_send_finished(SSL *s, int a, int b, const char *sender, int slen)
+--- openssl-1.0.0b.orig/include/openssl/ssl.h  2010-11-29 19:56:04.846517045 +0000
++++ openssl-1.0.0b/include/openssl/ssl.h       2010-11-29 19:56:04.965928855 +0000
+@@ -857,6 +857,25 @@ struct ssl_ctx_st
+       /* draft-rescorla-tls-opaque-prf-input-00.txt information */
+       int (*tlsext_opaque_prf_input_callback)(SSL *, void *peerinput, size_t len, void *arg);
+       void *tlsext_opaque_prf_input_callback_arg;
++
++# ifndef OPENSSL_NO_NEXTPROTONEG
++      /* Next protocol negotiation information */
++      /* (for experimental NPN extension). */
++
++      /* For a server, this contains a callback function by which the set of
++       * advertised protocols can be provided. */
++      int (*next_protos_advertised_cb)(SSL *s, const unsigned char **buf,
++                                       unsigned int *len, void *arg);
++      void *next_protos_advertised_cb_arg;
++      /* For a client, this contains a callback function that selects the
++       * next protocol from the list provided by the server. */
++      int (*next_proto_select_cb)(SSL *s, unsigned char **out,
++                                  unsigned char *outlen,
++                                  const unsigned char *in,
++                                  unsigned int inlen,
++                                  void *arg);
++      void *next_proto_select_cb_arg;
++# endif
+ #endif
+ #ifndef OPENSSL_NO_PSK
+@@ -928,6 +947,30 @@ int SSL_CTX_set_client_cert_engine(SSL_C
+ #endif
+ void SSL_CTX_set_cookie_generate_cb(SSL_CTX *ctx, int (*app_gen_cookie_cb)(SSL *ssl, unsigned char *cookie, unsigned int *cookie_len));
+ void SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx, int (*app_verify_cookie_cb)(SSL *ssl, unsigned char *cookie, unsigned int cookie_len));
++#ifndef OPENSSL_NO_NEXTPROTONEG
++void SSL_CTX_set_next_protos_advertised_cb(SSL_CTX *s,
++                                         int (*cb) (SSL *ssl,
++                                                    const unsigned char **out,
++                                                    unsigned int *outlen,
++                                                    void *arg), void *arg);
++void SSL_CTX_set_next_proto_select_cb(SSL_CTX *s,
++                                    int (*cb) (SSL *ssl, unsigned char **out,
++                                               unsigned char *outlen,
++                                               const unsigned char *in,
++                                               unsigned int inlen, void *arg),
++                                    void *arg);
++
++int SSL_select_next_proto(unsigned char **out, unsigned char *outlen,
++                        const unsigned char *in, unsigned int inlen,
++                        const unsigned char *client, unsigned int client_len);
++void SSL_get0_next_proto_negotiated(const SSL *s, const unsigned char **data,
++                                  unsigned *len);
++
++#define OPENSSL_NPN_UNSUPPORTED       0
++#define OPENSSL_NPN_NEGOTIATED        1
++#define OPENSSL_NPN_NO_OVERLAP        2
++
++#endif
+ #ifndef OPENSSL_NO_PSK
+ /* the maximum length of the buffer given to callbacks containing the
+@@ -1187,6 +1230,19 @@ struct ssl_st
+       void *tls_session_secret_cb_arg;
+       SSL_CTX * initial_ctx; /* initial ctx, used to store sessions */
++
++#ifndef OPENSSL_NO_NEXTPROTONEG
++      /* Next protocol negotiation. For the client, this is the protocol that
++       * we sent in NextProtocol and is set when handling ServerHello
++       * extensions.
++       *
++       * For a server, this is the client's selected_protocol from
++       * NextProtocol and is set when handling the NextProtocol message,
++       * before the Finished message. */
++      unsigned char *next_proto_negotiated;
++      unsigned char next_proto_negotiated_len;
++#endif
++
+ #define session_ctx initial_ctx
+ #else
+ #define session_ctx ctx
+@@ -1919,6 +1975,7 @@ void ERR_load_SSL_strings(void);
+ #define SSL_F_SSL3_GET_KEY_EXCHANGE                    141
+ #define SSL_F_SSL3_GET_MESSAGE                                 142
+ #define SSL_F_SSL3_GET_NEW_SESSION_TICKET              283
++#define SSL_F_SSL3_GET_NEXT_PROTO                      304
+ #define SSL_F_SSL3_GET_RECORD                          143
+ #define SSL_F_SSL3_GET_SERVER_CERTIFICATE              144
+ #define SSL_F_SSL3_GET_SERVER_DONE                     145
+@@ -2117,6 +2174,8 @@ void ERR_load_SSL_strings(void);
+ #define SSL_R_EXCESSIVE_MESSAGE_SIZE                   152
+ #define SSL_R_EXTRA_DATA_IN_MESSAGE                    153
+ #define SSL_R_GOT_A_FIN_BEFORE_A_CCS                   154
++#define SSL_R_GOT_NEXT_PROTO_BEFORE_A_CCS              346
++#define SSL_R_GOT_NEXT_PROTO_WITHOUT_EXTENSION                 347
+ #define SSL_R_HTTPS_PROXY_REQUEST                      155
+ #define SSL_R_HTTP_REQUEST                             156
+ #define SSL_R_ILLEGAL_PADDING                          283
+--- openssl-1.0.0b.orig/include/openssl/ssl3.h 2010-11-29 19:56:04.832465351 +0000
++++ openssl-1.0.0b/include/openssl/ssl3.h      2010-11-29 19:56:04.965928855 +0000
+@@ -465,6 +465,12 @@ typedef struct ssl3_state_st
+       void *server_opaque_prf_input;
+       size_t server_opaque_prf_input_len;
++#ifndef OPENSSL_NO_NEXTPROTONEG
++      /* Set if we saw the Next Protocol Negotiation extension from
++         our peer. */
++      int next_proto_neg_seen;
++#endif
++
+       struct  {
+               /* actually only needs to be 16+20 */
+               unsigned char cert_verify_md[EVP_MAX_MD_SIZE*2];
+@@ -557,6 +563,10 @@ typedef struct ssl3_state_st
+ #define SSL3_ST_CW_CERT_VRFY_B                (0x191|SSL_ST_CONNECT)
+ #define SSL3_ST_CW_CHANGE_A           (0x1A0|SSL_ST_CONNECT)
+ #define SSL3_ST_CW_CHANGE_B           (0x1A1|SSL_ST_CONNECT)
++#ifndef OPENSSL_NO_NEXTPROTONEG
++#define SSL3_ST_CW_NEXT_PROTO_A               (0x200|SSL_ST_CONNECT)
++#define SSL3_ST_CW_NEXT_PROTO_B               (0x201|SSL_ST_CONNECT)
++#endif
+ #define SSL3_ST_CW_FINISHED_A         (0x1B0|SSL_ST_CONNECT)
+ #define SSL3_ST_CW_FINISHED_B         (0x1B1|SSL_ST_CONNECT)
+ /* read from server */
+@@ -602,6 +612,10 @@ typedef struct ssl3_state_st
+ #define SSL3_ST_SR_CERT_VRFY_B                (0x1A1|SSL_ST_ACCEPT)
+ #define SSL3_ST_SR_CHANGE_A           (0x1B0|SSL_ST_ACCEPT)
+ #define SSL3_ST_SR_CHANGE_B           (0x1B1|SSL_ST_ACCEPT)
++#ifndef OPENSSL_NO_NEXTPROTONEG
++#define SSL3_ST_SR_NEXT_PROTO_A               (0x210|SSL_ST_ACCEPT)
++#define SSL3_ST_SR_NEXT_PROTO_B               (0x211|SSL_ST_ACCEPT)
++#endif
+ #define SSL3_ST_SR_FINISHED_A         (0x1C0|SSL_ST_ACCEPT)
+ #define SSL3_ST_SR_FINISHED_B         (0x1C1|SSL_ST_ACCEPT)
+ /* write to client */
+@@ -626,6 +640,9 @@ typedef struct ssl3_state_st
+ #define SSL3_MT_CLIENT_KEY_EXCHANGE           16
+ #define SSL3_MT_FINISHED                      20
+ #define SSL3_MT_CERTIFICATE_STATUS            22
++#ifndef OPENSSL_NO_NEXTPROTONEG
++#define SSL3_MT_NEXT_PROTO                    67
++#endif
+ #define DTLS1_MT_HELLO_VERIFY_REQUEST    3
+--- openssl-1.0.0b.orig/include/openssl/tls1.h 2009-11-11 14:51:29.000000000 +0000
++++ openssl-1.0.0b/include/openssl/tls1.h      2010-11-29 19:56:04.965928855 +0000
+@@ -204,6 +204,11 @@ extern "C" {
+ /* Temporary extension type */
+ #define TLSEXT_TYPE_renegotiate                 0xff01
++#ifndef OPENSSL_NO_NEXTPROTONEG
++/* This is not an IANA defined extension number */
++#define TLSEXT_TYPE_next_proto_neg            13172
++#endif
++
+ /* NameType value from RFC 3546 */
+ #define TLSEXT_NAMETYPE_host_name 0
+ /* status request value from RFC 3546 */
+--- openssl-1.0.0b.orig/ssl/s3_both.c  2010-11-29 19:56:04.846517045 +0000
++++ openssl-1.0.0b/ssl/s3_both.c       2010-11-29 19:56:04.965928855 +0000
+@@ -202,15 +202,40 @@ int ssl3_send_finished(SSL *s, int a, in
        return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
        }
  
++#ifndef OPENSSL_NO_NEXTPROTONEG
 +/* ssl3_take_mac calculates the Finished MAC for the handshakes messages seen to far. */
-+void ssl3_take_mac(SSL *s) {
++static void ssl3_take_mac(SSL *s)
++      {
 +      const char *sender;
 +      int slen;
 +
@@ -333,10 +493,9 @@ index 869a25d..b88288e 100644
 +              }
 +
 +      s->s3->tmp.peer_finish_md_len = s->method->ssl3_enc->final_finish_mac(s,
-+              &(s->s3->finish_dgst1),
-+              &(s->s3->finish_dgst2),
 +              sender,slen,s->s3->tmp.peer_finish_md);
-+}
++      }
++#endif
 +
  int ssl3_get_finished(SSL *s, int a, int b)
        {
@@ -344,60 +503,70 @@ index 869a25d..b88288e 100644
        long n;
        unsigned char *p;
  
--      /* the mac has already been generated when we received the
--       * change cipher spec message and is in s->s3->tmp.peer_finish_md
--       */ 
--
++#ifdef OPENSSL_NO_NEXTPROTONEG
+       /* the mac has already been generated when we received the
+        * change cipher spec message and is in s->s3->tmp.peer_finish_md
+        */ 
++#endif
        n=s->method->ssl_get_message(s,
                a,
-               b,
-@@ -516,6 +534,11 @@ long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok)
+@@ -521,6 +546,15 @@ long ssl3_get_message(SSL *s, int st1, i
                s->init_num += i;
                n -= i;
                }
++
++#ifndef OPENSSL_NO_NEXTPROTONEG
 +      /* If receiving Finished, record MAC of prior handshake messages for
 +       * Finished verification. */
 +      if (*s->init_buf->data == SSL3_MT_FINISHED)
 +              ssl3_take_mac(s);
++#endif
++
 +      /* Feed this message into MAC computation. */
        ssl3_finish_mac(s, (unsigned char *)s->init_buf->data, s->init_num + 4);
        if (s->msg_callback)
                s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, s->init_buf->data, (size_t)s->init_num + 4, s, s->msg_callback_arg);
-diff --git a/ssl/s3_clnt.c b/ssl/s3_clnt.c
-index 6173dbe..f9e1554 100644
---- a/ssl/s3_clnt.c
-+++ b/ssl/s3_clnt.c
-@@ -404,7 +404,11 @@ int ssl3_connect(SSL *s)
+--- openssl-1.0.0b.orig/ssl/s3_clnt.c  2010-11-29 19:56:04.846517045 +0000
++++ openssl-1.0.0b/ssl/s3_clnt.c       2010-11-29 19:56:04.965928855 +0000
+@@ -435,7 +435,16 @@ int ssl3_connect(SSL *s)
                        ret=ssl3_send_change_cipher_spec(s,
                                SSL3_ST_CW_CHANGE_A,SSL3_ST_CW_CHANGE_B);
                        if (ret <= 0) goto end;
--                      s->state=SSL3_ST_CW_FINISHED_A;
 +
++#if defined(OPENSSL_NO_TLSEXT) || defined(OPENSSL_NO_NEXTPROTONEG)
+                       s->state=SSL3_ST_CW_FINISHED_A;
++#else
 +                      if (s->next_proto_negotiated)
 +                              s->state=SSL3_ST_CW_NEXT_PROTO_A;
 +                      else
 +                              s->state=SSL3_ST_CW_FINISHED_A;
++#endif
++
                        s->init_num=0;
  
                        s->session->cipher=s->s3->tmp.new_cipher;
-@@ -432,6 +436,13 @@ int ssl3_connect(SSL *s)
+@@ -463,6 +472,15 @@ int ssl3_connect(SSL *s)
  
                        break;
  
++#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
 +              case SSL3_ST_CW_NEXT_PROTO_A:
 +              case SSL3_ST_CW_NEXT_PROTO_B:
 +                      ret=ssl3_send_next_proto(s);
 +                      if (ret <= 0) goto end;
 +                      s->state=SSL3_ST_CW_FINISHED_A;
 +                      break;
++#endif
 +
                case SSL3_ST_CW_FINISHED_A:
                case SSL3_ST_CW_FINISHED_B:
                        ret=ssl3_send_finished(s,
-@@ -2752,6 +2763,30 @@ static int curve_id2nid(int curve_id)
- }
- #endif
+@@ -3060,6 +3078,32 @@ err:
+  */
  
+ #ifndef OPENSSL_NO_TLSEXT
++# ifndef OPENSSL_NO_NEXTPROTONEG
 +int ssl3_send_next_proto(SSL *s)
 +      {
 +      unsigned int len, padding_len;
@@ -420,97 +589,92 @@ index 6173dbe..f9e1554 100644
 +              }
 +
 +      return ssl3_do_write(s, SSL3_RT_HANDSHAKE);
-+}
++      }
++# endif
 +
- /* Check to see if handshake is full or resumed. Usually this is just a
-  * case of checking to see if a cache hit has occurred. In the case of
-  * session tickets we have to check the next message to be sure.
-diff --git a/ssl/s3_lib.c b/ssl/s3_lib.c
-index 2c44bde..84bff8d 100644
---- a/ssl/s3_lib.c
-+++ b/ssl/s3_lib.c
-@@ -1751,6 +1751,14 @@ void ssl3_clear(SSL *s)
+ int ssl3_check_finished(SSL *s)
+       {
+       int ok;
+--- openssl-1.0.0b.orig/ssl/s3_lib.c   2010-11-29 19:56:04.832465351 +0000
++++ openssl-1.0.0b/ssl/s3_lib.c        2010-11-29 19:56:04.965928855 +0000
+@@ -2230,6 +2230,15 @@ void ssl3_clear(SSL *s)
        s->s3->num_renegotiations=0;
        s->s3->in_read_app_data=0;
        s->version=SSL3_VERSION;
 +
-+#ifndef OPENSSL_NO_TLSEXT
-+      if (s->next_proto_negotiated) {
++#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
++      if (s->next_proto_negotiated)
++              {
 +              OPENSSL_free(s->next_proto_negotiated);
-+              s->next_proto_negotiated = 0;
++              s->next_proto_negotiated = NULL;
 +              s->next_proto_negotiated_len = 0;
-+      }
++              }
 +#endif
        }
  
  long ssl3_ctrl(SSL *s, int cmd, long larg, void *parg)
-diff --git a/ssl/s3_pkt.c b/ssl/s3_pkt.c
-index 5e3583c..6853058 100644
---- a/ssl/s3_pkt.c
-+++ b/ssl/s3_pkt.c
-@@ -1264,8 +1264,6 @@ err:
+--- openssl-1.0.0b.orig/ssl/s3_pkt.c   2010-11-29 19:56:04.832465351 +0000
++++ openssl-1.0.0b/ssl/s3_pkt.c        2010-11-29 19:56:04.965928855 +0000
+@@ -1394,8 +1394,10 @@ err:
  int ssl3_do_change_cipher_spec(SSL *s)
        {
        int i;
--      const char *sender;
--      int slen;
++#ifdef OPENSSL_NO_NEXTPROTONEG
+       const char *sender;
+       int slen;
++#endif
  
        if (s->state & SSL_ST_ACCEPT)
                i=SSL3_CHANGE_CIPHER_SERVER_READ;
-@@ -1288,25 +1286,6 @@ int ssl3_do_change_cipher_spec(SSL *s)
+@@ -1418,6 +1420,7 @@ int ssl3_do_change_cipher_spec(SSL *s)
        if (!s->method->ssl3_enc->change_cipher_state(s,i))
                return(0);
  
--      /* we have to record the message digest at
--       * this point so we can get it before we read
--       * the finished message */
--      if (s->state & SSL_ST_CONNECT)
--              {
--              sender=s->method->ssl3_enc->server_finished_label;
--              slen=s->method->ssl3_enc->server_finished_label_len;
--              }
--      else
--              {
--              sender=s->method->ssl3_enc->client_finished_label;
--              slen=s->method->ssl3_enc->client_finished_label_len;
--              }
--
--      s->s3->tmp.peer_finish_md_len = s->method->ssl3_enc->final_finish_mac(s,
--              &(s->s3->finish_dgst1),
--              &(s->s3->finish_dgst2),
--              sender,slen,s->s3->tmp.peer_finish_md);
--
++#ifdef OPENSSL_NO_NEXTPROTONEG
+       /* we have to record the message digest at
+        * this point so we can get it before we read
+        * the finished message */
+@@ -1434,6 +1437,7 @@ int ssl3_do_change_cipher_spec(SSL *s)
+       s->s3->tmp.peer_finish_md_len = s->method->ssl3_enc->final_finish_mac(s,
+               sender,slen,s->s3->tmp.peer_finish_md);
++#endif
        return(1);
        }
-diff --git a/ssl/s3_srvr.c b/ssl/s3_srvr.c
-index e696450..8e0a504 100644
---- a/ssl/s3_srvr.c
-+++ b/ssl/s3_srvr.c
-@@ -499,7 +499,10 @@ int ssl3_accept(SSL *s)
-                                * a certificate, the CertificateVerify
-                                * message is not sent.
+--- openssl-1.0.0b.orig/ssl/s3_srvr.c  2010-11-29 19:56:04.846517045 +0000
++++ openssl-1.0.0b/ssl/s3_srvr.c       2010-11-29 19:56:04.965928855 +0000
+@@ -538,7 +538,14 @@ int ssl3_accept(SSL *s)
+                                * the client uses its key from the certificate
+                                * for key exchange.
                                 */
--                              s->state=SSL3_ST_SR_FINISHED_A;
++#if defined(OPENSSL_NO_TLSEXT) || defined(OPENSSL_NO_NEXTPROTONEG)
+                               s->state=SSL3_ST_SR_FINISHED_A;
++#else
 +                              if (s->s3->next_proto_neg_seen)
 +                                      s->state=SSL3_ST_SR_NEXT_PROTO_A;
 +                              else
 +                                      s->state=SSL3_ST_SR_FINISHED_A;
++#endif
                                s->init_num = 0;
                                }
-                       else   
-@@ -526,10 +529,21 @@ int ssl3_accept(SSL *s)
+                       else
+@@ -581,10 +588,27 @@ int ssl3_accept(SSL *s)
                        ret=ssl3_get_cert_verify(s);
                        if (ret <= 0) goto end;
  
--                      s->state=SSL3_ST_SR_FINISHED_A;
++#if defined(OPENSSL_NO_TLSEXT) || defined(OPENSSL_NO_NEXTPROTONEG)
+                       s->state=SSL3_ST_SR_FINISHED_A;
++#else
 +                      if (s->s3->next_proto_neg_seen)
 +                              s->state=SSL3_ST_SR_NEXT_PROTO_A;
 +                      else
 +                              s->state=SSL3_ST_SR_FINISHED_A;
++#endif
                        s->init_num=0;
                        break;
  
++#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
 +              case SSL3_ST_SR_NEXT_PROTO_A:
 +              case SSL3_ST_SR_NEXT_PROTO_B:
 +                      ret=ssl3_get_next_proto(s);
@@ -518,28 +682,34 @@ index e696450..8e0a504 100644
 +                      s->init_num = 0;
 +                      s->state=SSL3_ST_SR_FINISHED_A;
 +                      break;
++#endif
 +
                case SSL3_ST_SR_FINISHED_A:
                case SSL3_ST_SR_FINISHED_B:
                        ret=ssl3_get_finished(s,SSL3_ST_SR_FINISHED_A,
-@@ -597,7 +611,12 @@ int ssl3_accept(SSL *s)
+@@ -655,7 +679,16 @@ int ssl3_accept(SSL *s)
                        if (ret <= 0) goto end;
                        s->state=SSL3_ST_SW_FLUSH;
                        if (s->hit)
--                              s->s3->tmp.next_state=SSL3_ST_SR_FINISHED_A;
 +                              {
++#if defined(OPENSSL_NO_TLSEXT) || defined(OPENSSL_NO_NEXTPROTONEG)
+                               s->s3->tmp.next_state=SSL3_ST_SR_FINISHED_A;
++#else
 +                              if (s->s3->next_proto_neg_seen)
 +                                      s->s3->tmp.next_state=SSL3_ST_SR_NEXT_PROTO_A;
 +                              else
 +                                      s->s3->tmp.next_state=SSL3_ST_SR_FINISHED_A;
++#endif
 +                              }
                        else
                                s->s3->tmp.next_state=SSL_ST_OK;
                        s->init_num=0;
-@@ -2324,6 +2343,70 @@ err:
-       return(-1);
+@@ -3196,4 +3229,72 @@ int ssl3_send_cert_status(SSL *s)
+       /* SSL3_ST_SW_CERT_STATUS_B */
+       return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
        }
++
++# ifndef OPENSSL_NO_NPN
 +/* ssl3_get_next_proto reads a Next Protocol Negotiation handshake message. It
 + * sets the next_proto member in s if found */
 +int ssl3_get_next_proto(SSL *s)
@@ -551,16 +721,17 @@ index e696450..8e0a504 100644
 +
 +      /* Clients cannot send a NextProtocol message if we didn't see the
 +       * extension in their ClientHello */
-+      if (!s->s3->next_proto_neg_seen) {
++      if (!s->s3->next_proto_neg_seen)
++              {
 +              SSLerr(SSL_F_SSL3_GET_NEXT_PROTO,SSL_R_GOT_NEXT_PROTO_WITHOUT_EXTENSION);
 +              return -1;
-+      }
++              }
 +
 +      n=s->method->ssl_get_message(s,
 +              SSL3_ST_SR_NEXT_PROTO_A,
 +              SSL3_ST_SR_NEXT_PROTO_B,
 +              SSL3_MT_NEXT_PROTO,
-+              129,
++              514,  /* See the payload format below */
 +              &ok);
 +
 +      if (!ok)
@@ -576,7 +747,7 @@ index e696450..8e0a504 100644
 +              }
 +
 +      if (n < 2)
-+              return 0;  // The body must be > 1 bytes long */
++              return 0;  /* The body must be > 1 bytes long */
 +
 +      p=(unsigned char *)s->init_msg;
 +
@@ -594,28 +765,26 @@ index e696450..8e0a504 100644
 +              return 0;
 +
 +      s->next_proto_negotiated = OPENSSL_malloc(proto_len);
-+      if (!s->next_proto_negotiated) {
++      if (!s->next_proto_negotiated)
++              {
 +              SSLerr(SSL_F_SSL3_GET_NEXT_PROTO,ERR_R_MALLOC_FAILURE);
 +              return 0;
-+      }
++              }
 +      memcpy(s->next_proto_negotiated, p + 1, proto_len);
 +      s->next_proto_negotiated_len = proto_len;
 +
 +      return 1;
 +      }
-+
- int ssl3_get_cert_verify(SSL *s)
-       {
-       EVP_PKEY *pkey=NULL;
-diff --git a/ssl/ssl.h b/ssl/ssl.h
-index 9ab9495..dc8dff8 100644
---- a/ssl/ssl.h
-+++ b/ssl/ssl.h
-@@ -801,6 +801,23 @@ struct ssl_ctx_st
-       /* Callback for status request */
-       int (*tlsext_status_cb)(SSL *ssl, void *arg);
-       void *tlsext_status_arg;
-+
++# endif
+ #endif
+--- openssl-1.0.0b.orig/ssl/ssl.h      2010-11-29 19:56:04.846517045 +0000
++++ openssl-1.0.0b/ssl/ssl.h   2010-11-29 19:56:04.965928855 +0000
+@@ -857,6 +857,25 @@ struct ssl_ctx_st
+       /* draft-rescorla-tls-opaque-prf-input-00.txt information */
+       int (*tlsext_opaque_prf_input_callback)(SSL *, void *peerinput, size_t len, void *arg);
+       void *tlsext_opaque_prf_input_callback_arg;
++
++# ifndef OPENSSL_NO_NEXTPROTONEG
 +      /* Next protocol negotiation information */
 +      /* (for experimental NPN extension). */
 +
@@ -632,30 +801,47 @@ index 9ab9495..dc8dff8 100644
 +                                  unsigned int inlen,
 +                                  void *arg);
 +      void *next_proto_select_cb_arg;
++# endif
  #endif
  
-       };
-@@ -857,6 +874,15 @@ int SSL_CTX_set_client_cert_engine(SSL_CTX *ctx, ENGINE *e);
+ #ifndef OPENSSL_NO_PSK
+@@ -928,6 +947,30 @@ int SSL_CTX_set_client_cert_engine(SSL_C
  #endif
  void SSL_CTX_set_cookie_generate_cb(SSL_CTX *ctx, int (*app_gen_cookie_cb)(SSL *ssl, unsigned char *cookie, unsigned int *cookie_len));
  void SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx, int (*app_verify_cookie_cb)(SSL *ssl, unsigned char *cookie, unsigned int cookie_len));
-+void SSL_CTX_set_next_protos_advertised_cb(SSL_CTX *s, int (*cb) (SSL *ssl, const unsigned char **out, unsigned int *outlen, void *arg), void *arg);
-+void SSL_CTX_set_next_proto_select_cb(SSL_CTX *s, int (*cb) (SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg), void *arg);
-+
-+int SSL_select_next_proto(unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, const unsigned char *client, unsigned int client_len);
-+void SSL_get0_next_proto_negotiated(const SSL *s, const unsigned char **data, unsigned *len);
++#ifndef OPENSSL_NO_NEXTPROTONEG
++void SSL_CTX_set_next_protos_advertised_cb(SSL_CTX *s,
++                                         int (*cb) (SSL *ssl,
++                                                    const unsigned char **out,
++                                                    unsigned int *outlen,
++                                                    void *arg), void *arg);
++void SSL_CTX_set_next_proto_select_cb(SSL_CTX *s,
++                                    int (*cb) (SSL *ssl, unsigned char **out,
++                                               unsigned char *outlen,
++                                               const unsigned char *in,
++                                               unsigned int inlen, void *arg),
++                                    void *arg);
++
++int SSL_select_next_proto(unsigned char **out, unsigned char *outlen,
++                        const unsigned char *in, unsigned int inlen,
++                        const unsigned char *client, unsigned int client_len);
++void SSL_get0_next_proto_negotiated(const SSL *s, const unsigned char **data,
++                                  unsigned *len);
 +
 +#define OPENSSL_NPN_UNSUPPORTED       0
 +#define OPENSSL_NPN_NEGOTIATED        1
 +#define OPENSSL_NPN_NO_OVERLAP        2
++
++#endif
+ #ifndef OPENSSL_NO_PSK
+ /* the maximum length of the buffer given to callbacks containing the
+@@ -1187,6 +1230,19 @@ struct ssl_st
+       void *tls_session_secret_cb_arg;
  
- #define SSL_NOTHING   1
- #define SSL_WRITING   2
-@@ -1054,6 +1080,16 @@ struct ssl_st
-       /* RFC4507 session ticket expected to be received or sent */
-       int tlsext_ticket_expected;
        SSL_CTX * initial_ctx; /* initial ctx, used to store sessions */
 +
++#ifndef OPENSSL_NO_NEXTPROTONEG
 +      /* Next protocol negotiation. For the client, this is the protocol that
 +       * we sent in NextProtocol and is set when handling ServerHello
 +       * extensions.
@@ -665,95 +851,78 @@ index 9ab9495..dc8dff8 100644
 +       * before the Finished message. */
 +      unsigned char *next_proto_negotiated;
 +      unsigned char next_proto_negotiated_len;
++#endif
++
  #define session_ctx initial_ctx
  #else
  #define session_ctx ctx
-@@ -1761,6 +1797,7 @@ void ERR_load_SSL_strings(void);
+@@ -1919,6 +1975,7 @@ void ERR_load_SSL_strings(void);
  #define SSL_F_SSL3_GET_KEY_EXCHANGE                    141
  #define SSL_F_SSL3_GET_MESSAGE                                 142
  #define SSL_F_SSL3_GET_NEW_SESSION_TICKET              283
-+#define SSL_F_SSL3_GET_NEXT_PROTO                      297
++#define SSL_F_SSL3_GET_NEXT_PROTO                      304
  #define SSL_F_SSL3_GET_RECORD                          143
  #define SSL_F_SSL3_GET_SERVER_CERTIFICATE              144
  #define SSL_F_SSL3_GET_SERVER_DONE                     145
-@@ -1827,6 +1864,7 @@ void ERR_load_SSL_strings(void);
- #define SSL_F_SSL_INIT_WBIO_BUFFER                     184
- #define SSL_F_SSL_LOAD_CLIENT_CA_FILE                  185
- #define SSL_F_SSL_NEW                                  186
-+#define SSL_F_SSL_NEXT_PROTOS_PARSE                    298
- #define SSL_F_SSL_PARSE_CLIENTHELLO_RENEGOTIATE_EXT    287
- #define SSL_F_SSL_PARSE_CLIENTHELLO_TLSEXT             290
- #define SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT    289
-@@ -1869,6 +1907,7 @@ void ERR_load_SSL_strings(void);
- #define SSL_F_TLS1_ENC                                         210
- #define SSL_F_TLS1_SETUP_KEY_BLOCK                     211
- #define SSL_F_WRITE_PENDING                            212
-+/* Next entry: 299 */
- /* Reason codes. */
- #define SSL_R_APP_DATA_IN_HANDSHAKE                    100
-@@ -1939,6 +1978,8 @@ void ERR_load_SSL_strings(void);
+@@ -2117,6 +2174,8 @@ void ERR_load_SSL_strings(void);
  #define SSL_R_EXCESSIVE_MESSAGE_SIZE                   152
  #define SSL_R_EXTRA_DATA_IN_MESSAGE                    153
  #define SSL_R_GOT_A_FIN_BEFORE_A_CCS                   154
-+#define SSL_R_GOT_NEXT_PROTO_BEFORE_A_CCS              334
-+#define SSL_R_GOT_NEXT_PROTO_WITHOUT_EXTENSION                 335
++#define SSL_R_GOT_NEXT_PROTO_BEFORE_A_CCS              346
++#define SSL_R_GOT_NEXT_PROTO_WITHOUT_EXTENSION                 347
  #define SSL_R_HTTPS_PROXY_REQUEST                      155
  #define SSL_R_HTTP_REQUEST                             156
  #define SSL_R_ILLEGAL_PADDING                          283
-@@ -2120,6 +2161,7 @@ void ERR_load_SSL_strings(void);
- #define SSL_R_WRONG_VERSION_NUMBER                     267
- #define SSL_R_X509_LIB                                         268
- #define SSL_R_X509_VERIFICATION_SETUP_PROBLEMS                 269
-+/* Next entry: 335 or 1115 */
- #ifdef  __cplusplus
- }
-diff --git a/ssl/ssl3.h b/ssl/ssl3.h
-index afbdd70..54b73b7 100644
---- a/ssl/ssl3.h
-+++ b/ssl/ssl3.h
-@@ -394,6 +394,9 @@ typedef struct ssl3_state_st
+--- openssl-1.0.0b.orig/ssl/ssl3.h     2010-11-29 19:56:04.832465351 +0000
++++ openssl-1.0.0b/ssl/ssl3.h  2010-11-29 19:56:04.965928855 +0000
+@@ -465,6 +465,12 @@ typedef struct ssl3_state_st
+       void *server_opaque_prf_input;
+       size_t server_opaque_prf_input_len;
  
-       int in_read_app_data;
-+      /* Set if we saw the Next Protocol Negotiation extension from our peer. */
++#ifndef OPENSSL_NO_NEXTPROTONEG
++      /* Set if we saw the Next Protocol Negotiation extension from
++         our peer. */
 +      int next_proto_neg_seen;
++#endif
 +
        struct  {
                /* actually only needs to be 16+20 */
                unsigned char cert_verify_md[EVP_MAX_MD_SIZE*2];
-@@ -484,6 +487,8 @@ typedef struct ssl3_state_st
+@@ -557,6 +563,10 @@ typedef struct ssl3_state_st
  #define SSL3_ST_CW_CERT_VRFY_B                (0x191|SSL_ST_CONNECT)
  #define SSL3_ST_CW_CHANGE_A           (0x1A0|SSL_ST_CONNECT)
  #define SSL3_ST_CW_CHANGE_B           (0x1A1|SSL_ST_CONNECT)
++#ifndef OPENSSL_NO_NEXTPROTONEG
 +#define SSL3_ST_CW_NEXT_PROTO_A               (0x200|SSL_ST_CONNECT)
 +#define SSL3_ST_CW_NEXT_PROTO_B               (0x201|SSL_ST_CONNECT)
++#endif
  #define SSL3_ST_CW_FINISHED_A         (0x1B0|SSL_ST_CONNECT)
  #define SSL3_ST_CW_FINISHED_B         (0x1B1|SSL_ST_CONNECT)
  /* read from server */
-@@ -529,6 +534,8 @@ typedef struct ssl3_state_st
+@@ -602,6 +612,10 @@ typedef struct ssl3_state_st
  #define SSL3_ST_SR_CERT_VRFY_B                (0x1A1|SSL_ST_ACCEPT)
  #define SSL3_ST_SR_CHANGE_A           (0x1B0|SSL_ST_ACCEPT)
  #define SSL3_ST_SR_CHANGE_B           (0x1B1|SSL_ST_ACCEPT)
++#ifndef OPENSSL_NO_NEXTPROTONEG
 +#define SSL3_ST_SR_NEXT_PROTO_A               (0x210|SSL_ST_ACCEPT)
 +#define SSL3_ST_SR_NEXT_PROTO_B               (0x211|SSL_ST_ACCEPT)
++#endif
  #define SSL3_ST_SR_FINISHED_A         (0x1C0|SSL_ST_ACCEPT)
  #define SSL3_ST_SR_FINISHED_B         (0x1C1|SSL_ST_ACCEPT)
  /* write to client */
-@@ -553,6 +560,7 @@ typedef struct ssl3_state_st
+@@ -626,6 +640,9 @@ typedef struct ssl3_state_st
  #define SSL3_MT_CLIENT_KEY_EXCHANGE           16
  #define SSL3_MT_FINISHED                      20
  #define SSL3_MT_CERTIFICATE_STATUS            22
++#ifndef OPENSSL_NO_NEXTPROTONEG
 +#define SSL3_MT_NEXT_PROTO                    67
++#endif
  #define DTLS1_MT_HELLO_VERIFY_REQUEST    3
  
  
-diff --git a/ssl/ssl_err.c b/ssl/ssl_err.c
-index 7eb5202..ff9c856 100644
---- a/ssl/ssl_err.c
-+++ b/ssl/ssl_err.c
-@@ -154,6 +154,7 @@ static ERR_STRING_DATA SSL_str_functs[]=
+--- openssl-1.0.0b.orig/ssl/ssl_err.c  2010-11-29 19:56:04.846517045 +0000
++++ openssl-1.0.0b/ssl/ssl_err.c       2010-11-29 19:56:04.965928855 +0000
+@@ -155,6 +155,7 @@ static ERR_STRING_DATA SSL_str_functs[]=
  {ERR_FUNC(SSL_F_SSL3_GET_KEY_EXCHANGE),       "SSL3_GET_KEY_EXCHANGE"},
  {ERR_FUNC(SSL_F_SSL3_GET_MESSAGE),    "SSL3_GET_MESSAGE"},
  {ERR_FUNC(SSL_F_SSL3_GET_NEW_SESSION_TICKET), "SSL3_GET_NEW_SESSION_TICKET"},
@@ -761,15 +930,7 @@ index 7eb5202..ff9c856 100644
  {ERR_FUNC(SSL_F_SSL3_GET_RECORD),     "SSL3_GET_RECORD"},
  {ERR_FUNC(SSL_F_SSL3_GET_SERVER_CERTIFICATE), "SSL3_GET_SERVER_CERTIFICATE"},
  {ERR_FUNC(SSL_F_SSL3_GET_SERVER_DONE),        "SSL3_GET_SERVER_DONE"},
-@@ -220,6 +221,7 @@ static ERR_STRING_DATA SSL_str_functs[]=
- {ERR_FUNC(SSL_F_SSL_INIT_WBIO_BUFFER),        "SSL_INIT_WBIO_BUFFER"},
- {ERR_FUNC(SSL_F_SSL_LOAD_CLIENT_CA_FILE),     "SSL_load_client_CA_file"},
- {ERR_FUNC(SSL_F_SSL_NEW),     "SSL_new"},
-+{ERR_FUNC(SSL_F_SSL_NEXT_PROTOS_PARSE),       "SSL_next_protos_parse"},
- {ERR_FUNC(SSL_F_SSL_PARSE_CLIENTHELLO_RENEGOTIATE_EXT),       "SSL_PARSE_CLIENTHELLO_RENEGOTIATE_EXT"},
- {ERR_FUNC(SSL_F_SSL_PARSE_CLIENTHELLO_TLSEXT),        "SSL_PARSE_CLIENTHELLO_TLSEXT"},
- {ERR_FUNC(SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT),       "SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT"},
-@@ -335,6 +337,8 @@ static ERR_STRING_DATA SSL_str_reasons[]=
+@@ -355,6 +356,8 @@ static ERR_STRING_DATA SSL_str_reasons[]
  {ERR_REASON(SSL_R_EXCESSIVE_MESSAGE_SIZE),"excessive message size"},
  {ERR_REASON(SSL_R_EXTRA_DATA_IN_MESSAGE) ,"extra data in message"},
  {ERR_REASON(SSL_R_GOT_A_FIN_BEFORE_A_CCS),"got a fin before a ccs"},
@@ -778,23 +939,23 @@ index 7eb5202..ff9c856 100644
  {ERR_REASON(SSL_R_HTTPS_PROXY_REQUEST)   ,"https proxy request"},
  {ERR_REASON(SSL_R_HTTP_REQUEST)          ,"http request"},
  {ERR_REASON(SSL_R_ILLEGAL_PADDING)       ,"illegal padding"},
-diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c
-index 96e056d..cfa70ec 100644
---- a/ssl/ssl_lib.c
-+++ b/ssl/ssl_lib.c
-@@ -323,6 +323,7 @@ SSL *SSL_new(SSL_CTX *ctx)
+--- openssl-1.0.0b.orig/ssl/ssl_lib.c  2010-11-29 19:56:04.846517045 +0000
++++ openssl-1.0.0b/ssl/ssl_lib.c       2010-11-29 19:56:04.965928855 +0000
+@@ -354,6 +354,9 @@ SSL *SSL_new(SSL_CTX *ctx)
        s->tlsext_ocsp_resplen = -1;
        CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);
        s->initial_ctx=ctx;
++# ifndef OPENSSL_NO_NEXTPROTONEG
 +      s->next_proto_negotiated = NULL;
++# endif
  #endif
-       s->verify_result=X509_V_OK;
  
-@@ -532,6 +533,11 @@ void SSL_free(SSL *s)
+       s->verify_result=X509_V_OK;
+@@ -587,6 +590,11 @@ void SSL_free(SSL *s)
                kssl_ctx_free(s->kssl_ctx);
  #endif        /* OPENSSL_NO_KRB5 */
  
-+#ifndef OPENSSL_NO_TLSEXT
++#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
 +      if (s->next_proto_negotiated)
 +              OPENSSL_free(s->next_proto_negotiated);
 +#endif
@@ -802,28 +963,12 @@ index 96e056d..cfa70ec 100644
        OPENSSL_free(s);
        }
  
-@@ -1576,6 +1582,8 @@ SSL_CTX *SSL_CTX_new(SSL_METHOD *meth)
-       ret->tlsext_status_cb = 0;
-       ret->tlsext_status_arg = NULL;
-+      ret->next_protos_advertised_cb = 0;
-+      ret->next_proto_select_cb = 0;
- #endif
- #ifndef OPENSSL_NO_ENGINE
-@@ -1677,6 +1685,7 @@ void SSL_CTX_free(SSL_CTX *a)
-       if (a->client_cert_engine)
-               ENGINE_finish(a->client_cert_engine);
- #endif
-+
-       OPENSSL_free(a);
-       }
-@@ -2752,6 +2761,123 @@ void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version, int con
-       SSL_callback_ctrl(ssl, SSL_CTRL_SET_MSG_CALLBACK, (void (*)(void))cb);
+@@ -1503,6 +1511,124 @@ int SSL_get_servername_type(const SSL *s
+               return TLSEXT_NAMETYPE_host_name;
+       return -1;
        }
-+#ifndef OPENSSL_NO_TLSEXT
++
++# ifndef OPENSSL_NO_NEXTPROTONEG
 +/* SSL_select_next_proto implements the standard protocol selection. It is
 + * expected that this function is called from the callback set by
 + * SSL_CTX_set_next_proto_select_cb.
@@ -938,40 +1083,52 @@ index 96e056d..cfa70ec 100644
 +      ctx->next_proto_select_cb = cb;
 +      ctx->next_proto_select_cb_arg = arg;
 +      }
-+#endif
 +
- int SSL_cutthrough_complete(const SSL *s)
-       {
-       return (!s->server &&                 /* cutthrough only applies to clients */
-diff --git a/ssl/ssl_locl.h b/ssl/ssl_locl.h
-index e305db4..a9183ff 100644
---- a/ssl/ssl_locl.h
-+++ b/ssl/ssl_locl.h
-@@ -895,6 +895,7 @@ int ssl3_get_server_certificate(SSL *s);
++# endif
+ #endif
+ static unsigned long ssl_session_hash(const SSL_SESSION *a)
+@@ -1667,6 +1793,10 @@ SSL_CTX *SSL_CTX_new(const SSL_METHOD *m
+       ret->tlsext_status_cb = 0;
+       ret->tlsext_status_arg = NULL;
++# ifndef OPENSSL_NO_NEXTPROTONEG
++      ret->next_protos_advertised_cb = 0;
++      ret->next_proto_select_cb = 0;
++# endif
+ #endif
+ #ifndef OPENSSL_NO_PSK
+       ret->psk_identity_hint=NULL;
+--- openssl-1.0.0b.orig/ssl/ssl_locl.h 2010-11-29 19:56:04.846517045 +0000
++++ openssl-1.0.0b/ssl/ssl_locl.h      2010-11-29 19:56:04.965928855 +0000
+@@ -968,6 +968,9 @@ int ssl3_get_server_certificate(SSL *s);
  int ssl3_check_cert_and_algorithm(SSL *s);
  #ifndef OPENSSL_NO_TLSEXT
  int ssl3_check_finished(SSL *s);
++# ifndef OPENSSL_NO_NEXTPROTONEG
 +int ssl3_send_next_proto(SSL *s);
++# endif
  #endif
  
  int dtls1_client_hello(SSL *s);
-@@ -913,6 +914,7 @@ int ssl3_check_client_hello(SSL *s);
+@@ -986,6 +989,9 @@ int ssl3_check_client_hello(SSL *s);
  int ssl3_get_client_certificate(SSL *s);
  int ssl3_get_client_key_exchange(SSL *s);
  int ssl3_get_cert_verify(SSL *s);
++#ifndef OPENSSL_NO_NEXTPROTONEG
 +int ssl3_get_next_proto(SSL *s);
++#endif
  
  int dtls1_send_hello_request(SSL *s);
  int dtls1_send_server_hello(SSL *s);
-diff --git a/ssl/t1_lib.c b/ssl/t1_lib.c
-index 8b53112..fd35b18 100644
---- a/ssl/t1_lib.c
-+++ b/ssl/t1_lib.c
-@@ -271,6 +271,16 @@ unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, unsigned cha
+--- openssl-1.0.0b.orig/ssl/t1_lib.c   2010-11-16 13:26:24.000000000 +0000
++++ openssl-1.0.0b/ssl/t1_lib.c        2010-11-29 19:56:04.965928855 +0000
+@@ -494,6 +494,18 @@ unsigned char *ssl_add_clienthello_tlsex
                        i2d_X509_EXTENSIONS(s->tlsext_ocsp_exts, &ret);
                }
  
-+      if (s->ctx->next_proto_select_cb)
++#ifndef OPENSSL_NO_NEXTPROTONEG
++      if (s->ctx->next_proto_select_cb && !s->s3->tmp.finish_md_len)
 +              {
 +              /* The client advertises an emtpy extension to indicate its
 +               * support for Next Protocol Negotiation */
@@ -980,22 +1137,26 @@ index 8b53112..fd35b18 100644
 +              s2n(TLSEXT_TYPE_next_proto_neg,ret);
 +              s2n(0,ret);
 +              }
++#endif
 +
        if ((extdatalen = ret-p-2)== 0) 
                return p;
  
-@@ -282,6 +292,7 @@ unsigned char *ssl_add_serverhello_tlsext(SSL *s, unsigned char *p, unsigned cha
+@@ -505,6 +517,9 @@ unsigned char *ssl_add_serverhello_tlsex
        {
        int extdatalen=0;
        unsigned char *ret = p;
-+      char next_proto_neg_seen;
++#ifndef OPENSSL_NO_NEXTPROTONEG
++      int next_proto_neg_seen;
++#endif
  
        /* don't add extensions for SSLv3, unless doing secure renegotiation */
        if (s->version == SSL3_VERSION && !s->s3->send_connection_binding)
-@@ -337,6 +348,26 @@ unsigned char *ssl_add_serverhello_tlsext(SSL *s, unsigned char *p, unsigned cha
-               s2n(0,ret);
+@@ -618,6 +633,28 @@ unsigned char *ssl_add_serverhello_tlsex
                }
  
++#ifndef OPENSSL_NO_NEXTPROTONEG
 +      next_proto_neg_seen = s->s3->next_proto_neg_seen;
 +      s->s3->next_proto_neg_seen = 0;
 +      if (next_proto_neg_seen && s->ctx->next_protos_advertised_cb)
@@ -1015,18 +1176,21 @@ index 8b53112..fd35b18 100644
 +                      s->s3->next_proto_neg_seen = 1;
 +                      }
 +              }
++#endif
 +
        if ((extdatalen = ret-p-2)== 0) 
                return p;
  
-@@ -576,6 +607,25 @@ int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
+@@ -982,6 +1019,28 @@ int ssl_parse_clienthello_tlsext(SSL *s,
                                else
                                        s->tlsext_status_type = -1;
                        }
-+              else if (type == TLSEXT_TYPE_next_proto_neg)
++#ifndef OPENSSL_NO_NEXTPROTONEG
++              else if (type == TLSEXT_TYPE_next_proto_neg &&
++                         s->s3->tmp.finish_md_len == 0)
 +                      {
 +                      /* We shouldn't accept this extension on a
-+                       * renegotiation, but we currently do.
++                       * renegotiation.
 +                       *
 +                       * s->new_session will be set on renegotiation, but we
 +                       * probably shouldn't rely that it couldn't be set on
@@ -1042,17 +1206,19 @@ index 8b53112..fd35b18 100644
 +                       * Finished message could have been computed.) */
 +                      s->s3->next_proto_neg_seen = 1;
 +                      }
++#endif
  
                /* session ticket processed earlier */
-@@ -599,6 +649,24 @@ int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
+               data+=size;
+@@ -1005,6 +1064,26 @@ int ssl_parse_clienthello_tlsext(SSL *s,
        return 1;
        }
  
++#ifndef OPENSSL_NO_NEXTPROTONEG
 +/* ssl_next_proto_validate validates a Next Protocol Negotiation block. No
 + * elements of zero length are allowed and the set of elements must exactly fill
 + * the length of the block. */
-+static char ssl_next_proto_validate(unsigned char *d, unsigned len)
++static int ssl_next_proto_validate(unsigned char *d, unsigned len)
 +      {
 +      unsigned int off = 0;
 +
@@ -1066,14 +1232,16 @@ index 8b53112..fd35b18 100644
 +
 +      return off == len;
 +      }
++#endif
 +
  int ssl_parse_serverhello_tlsext(SSL *s, unsigned char **p, unsigned char *d, int n, int *al)
        {
-       unsigned short type;
-@@ -658,6 +726,37 @@ int ssl_parse_serverhello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
+       unsigned short length;
+@@ -1139,6 +1218,39 @@ int ssl_parse_serverhello_tlsext(SSL *s,
                        /* Set flag to expect CertificateStatus message */
                        s->tlsext_status_expected = 1;
                        }
++#ifndef OPENSSL_NO_NEXTPROTONEG
 +              else if (type == TLSEXT_TYPE_next_proto_neg)
 +                      {
 +                      unsigned char *selected;
@@ -1105,19 +1273,20 @@ index 8b53112..fd35b18 100644
 +                      memcpy(s->next_proto_negotiated, selected, selected_len);
 +                      s->next_proto_negotiated_len = selected_len;
 +                      }
++#endif
                else if (type == TLSEXT_TYPE_renegotiate)
                        {
                        if(!ssl_parse_serverhello_renegotiate_ext(s, data, size, al))
-diff --git a/ssl/tls1.h b/ssl/tls1.h
-index afe4807..71d76de 100644
---- a/ssl/tls1.h
-+++ b/ssl/tls1.h
-@@ -118,6 +118,9 @@ extern "C" {
+--- openssl-1.0.0b.orig/ssl/tls1.h     2009-11-11 14:51:29.000000000 +0000
++++ openssl-1.0.0b/ssl/tls1.h  2010-11-29 19:56:04.965928855 +0000
+@@ -204,6 +204,11 @@ extern "C" {
  /* Temporary extension type */
  #define TLSEXT_TYPE_renegotiate                 0xff01
  
++#ifndef OPENSSL_NO_NEXTPROTONEG
 +/* This is not an IANA defined extension number */
 +#define TLSEXT_TYPE_next_proto_neg            13172
++#endif
 +
  /* NameType value from RFC 3546 */
  #define TLSEXT_NAMETYPE_host_name 0
diff --git a/deps/openssl/patches/openssl_no_dtls1.patch b/deps/openssl/patches/openssl_no_dtls1.patch
new file mode 100644 (file)
index 0000000..8b61cd3
--- /dev/null
@@ -0,0 +1,13 @@
+--- openssl-1.0.0f.orig/ssl/ssl_lib.c  2012-01-04 22:13:21.000000000 +0000
++++ openssl-1.0.0f/ssl/ssl_lib.c       2012-01-04 22:13:21.000000000 +0000
+@@ -1063,8 +1063,10 @@ long SSL_ctrl(SSL *s,int cmd,long larg,v
+               s->max_cert_list=larg;
+               return(l);
+       case SSL_CTRL_SET_MTU:
++#ifndef OPENSSL_NO_DTLS1
+               if (larg < (long)dtls1_min_mtu())
+                       return 0;
++#endif
+               if (SSL_version(s) == DTLS1_VERSION ||
+                   SSL_version(s) == DTLS1_BAD_VER)
diff --git a/deps/openssl/patches/posix_c_source.patch b/deps/openssl/patches/posix_c_source.patch
deleted file mode 100644 (file)
index ff51594..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-diff --git a/openssl/crypto/ui/ui_openssl.c b/openssl/crypto/ui/ui_openssl.c
-index 06270f0..e2fff79 100644
---- a/openssl/crypto/ui/ui_openssl.c
-+++ b/openssl/crypto/ui/ui_openssl.c
-@@ -122,7 +122,10 @@
-  * sigaction and fileno included. -pedantic would be more appropriate for
-  * the intended purposes, but we can't prevent users from adding -ansi.
-  */
-+#ifndef _POSIX_C_SOURCE
- #define _POSIX_C_SOURCE 1
-+#endif
-+
- #include <signal.h>
- #include <stdio.h>
- #include <string.h>
diff --git a/deps/openssl/patches/progs.patch b/deps/openssl/patches/progs.patch
new file mode 100644 (file)
index 0000000..16fd9b0
--- /dev/null
@@ -0,0 +1,54 @@
+--- openssl-1.0.0.orig/apps/openssl.c  2009-10-04 09:43:21.000000000 -0700
++++ openssl-1.0.0/apps/openssl.c       2010-05-18 14:05:14.000000000 -0700
+@@ -275,8 +275,10 @@ int main(int Argc, char *Argv[])
+               if (ERR_GET_REASON(ERR_peek_last_error())
+                   == CONF_R_NO_SUCH_FILE)
+                       {
++#if 0 /* ANDROID */
+                       BIO_printf(bio_err,
+                                  "WARNING: can't open config file: %s\n",p);
++#endif
+                       ERR_clear_error();
+                       NCONF_free(config);
+                       config = NULL;
+--- openssl-1.0.0.orig/apps/progs.h    2009-06-30 08:08:38.000000000 -0700
++++ openssl-1.0.0/apps/progs.h 2010-05-18 14:05:38.000000000 -0700
+@@ -146,7 +152,9 @@ FUNCTION functions[] = {
+       {FUNC_TYPE_GENERAL,"ocsp",ocsp_main},
+ #endif
+       {FUNC_TYPE_GENERAL,"prime",prime_main},
++#if 0 /* ANDROID */
+       {FUNC_TYPE_GENERAL,"ts",ts_main},
++#endif
+ #ifndef OPENSSL_NO_MD2
+       {FUNC_TYPE_MD,"md2",dgst_main},
+ #endif
+--- openssl-1.0.0.orig/apps/speed.c    2010-03-03 11:56:17.000000000 -0800
++++ openssl-1.0.0/apps/speed.c 2010-05-18 14:05:57.000000000 -0700
+@@ -1718,6 +1718,7 @@ int MAIN(int argc, char **argv)
+                       }
+               }
++#if 0 /* ANDROID */
+       if (doit[D_IGE_128_AES])
+               {
+               for (j=0; j<SIZE_NUM; j++)
+@@ -1763,6 +1764,7 @@ int MAIN(int argc, char **argv)
+ #endif
++#endif
+ #ifndef OPENSSL_NO_CAMELLIA
+       if (doit[D_CBC_128_CML])
+               {
+--- openssl-1.0.0.orig/crypto/ui/ui_openssl.c  2009-10-04 09:43:21.000000000 -0700
++++ openssl-1.0.0/crypto/ui/ui_openssl.c       2010-05-18 13:36:26.000000000 -0700
+@@ -184,7 +184,7 @@
+ # undef  SGTTY
+ #endif
+-#if defined(linux) && !defined(TERMIO)
++#if defined(linux) && !defined(TERMIO) && !defined(__ANDROID__)
+ # undef  TERMIOS
+ # define TERMIO
+ # undef  SGTTY
diff --git a/deps/openssl/patches/sha1_armv4_large.patch b/deps/openssl/patches/sha1_armv4_large.patch
new file mode 100644 (file)
index 0000000..359ff94
--- /dev/null
@@ -0,0 +1,21 @@
+diff --git a/crypto/sha/asm/sha1-armv4-large.pl b/crypto/sha/asm/sha1-armv4-large.pl
+index 6e65fe3..79e3f61 100644
+--- a/crypto/sha/asm/sha1-armv4-large.pl
++++ b/crypto/sha/asm/sha1-armv4-large.pl
+@@ -161,6 +161,7 @@ for($i=0;$i<5;$i++) {
+ $code.=<<___;
+       teq     $Xi,sp
+       bne     .L_00_15                @ [((11+4)*5+2)*3]
++      sub     sp,sp,#5*4
+ ___
+       &BODY_00_15(@V);        unshift(@V,pop(@V));
+       &BODY_16_19(@V);        unshift(@V,pop(@V));
+@@ -170,7 +171,7 @@ ___
+ $code.=<<___;
+       ldr     $K,.LK_20_39            @ [+15+16*4]
+-      sub     sp,sp,#25*4
++      sub     sp,sp,#20*4
+       cmn     sp,#0                   @ [+3], clear carry to denote 20_39
+ .L_20_39_or_60_79:
+ ___
diff --git a/deps/openssl/patches/small_records.patch b/deps/openssl/patches/small_records.patch
new file mode 100644 (file)
index 0000000..a2ea51c
--- /dev/null
@@ -0,0 +1,337 @@
+--- openssl-1.0.0a.orig/ssl/d1_pkt.c   2010-04-14 00:09:55.000000000 +0000
++++ openssl-1.0.0a/ssl/d1_pkt.c        2010-08-25 21:12:39.000000000 +0000
+@@ -608,6 +608,24 @@ again:
+                       goto again;
+                       }
++              /* If we receive a valid record larger than the current buffer size,
++               * allocate some memory for it.
++               */
++              if (rr->length > s->s3->rbuf.len - DTLS1_RT_HEADER_LENGTH)
++                      {
++                      unsigned char *pp;
++                      unsigned int newlen = rr->length + DTLS1_RT_HEADER_LENGTH;
++                      if ((pp=OPENSSL_realloc(s->s3->rbuf.buf, newlen))==NULL)
++                              {
++                              SSLerr(SSL_F_DTLS1_GET_RECORD,ERR_R_MALLOC_FAILURE);
++                              return(-1);
++                              }
++                      p = pp + (p - s->s3->rbuf.buf);
++                      s->s3->rbuf.buf=pp;
++                      s->s3->rbuf.len=newlen;
++                      s->packet= &(s->s3->rbuf.buf[0]);
++                      }
++
+               /* now s->rstate == SSL_ST_READ_BODY */
+               }
+@@ -1342,6 +1360,7 @@ int do_dtls1_write(SSL *s, int type, con
+       SSL3_BUFFER *wb;
+       SSL_SESSION *sess;
+       int bs;
++      unsigned int len_with_overhead = len + SSL3_RT_DEFAULT_WRITE_OVERHEAD;
+       /* first check if there is a SSL3_BUFFER still being written
+        * out.  This will happen with non blocking IO */
+@@ -1351,6 +1370,16 @@ int do_dtls1_write(SSL *s, int type, con
+               return(ssl3_write_pending(s,type,buf,len));
+               }
++      if (s->s3->wbuf.len < len_with_overhead)
++              {
++              if ((p=OPENSSL_realloc(s->s3->wbuf.buf, len_with_overhead)) == NULL) {
++                      SSLerr(SSL_F_DO_DTLS1_WRITE,ERR_R_MALLOC_FAILURE);
++                      goto err;
++              }
++              s->s3->wbuf.buf = p;
++              s->s3->wbuf.len = len_with_overhead;
++              }
++
+       /* If we have an alert to send, lets send it */
+       if (s->s3->alert_dispatch)
+               {
+--- openssl-1.0.0a.orig/ssl/s23_srvr.c 2010-02-16 14:20:40.000000000 +0000
++++ openssl-1.0.0a/ssl/s23_srvr.c      2010-08-25 21:12:39.000000000 +0000
+@@ -403,8 +403,13 @@ int ssl23_get_client_hello(SSL *s)
+               v[0] = p[3]; /* == SSL3_VERSION_MAJOR */
+               v[1] = p[4];
++/* The SSL2 protocol allows n to be larger, just pick
++ * a reasonable buffer size. */
++#if SSL3_RT_DEFAULT_PACKET_SIZE < 1024*4 - SSL3_RT_DEFAULT_WRITE_OVERHEAD
++#error "SSL3_RT_DEFAULT_PACKET_SIZE is too small."
++#endif
+               n=((p[0]&0x7f)<<8)|p[1];
+-              if (n > (1024*4))
++              if (n > SSL3_RT_DEFAULT_PACKET_SIZE - 2)
+                       {
+                       SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_TOO_LARGE);
+                       goto err;
+--- openssl-1.0.0a.orig/ssl/s3_both.c  2010-03-24 23:16:49.000000000 +0000
++++ openssl-1.0.0a/ssl/s3_both.c       2010-08-25 21:12:39.000000000 +0000
+@@ -715,13 +722,20 @@ int ssl3_setup_read_buffer(SSL *s)
+       if (s->s3->rbuf.buf == NULL)
+               {
+-              len = SSL3_RT_MAX_PLAIN_LENGTH
+-                      + SSL3_RT_MAX_ENCRYPTED_OVERHEAD
+-                      + headerlen + align;
+-              if (s->options & SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER)
++              if (SSL_get_mode(s) & SSL_MODE_SMALL_BUFFERS)
+                       {
+-                      s->s3->init_extra = 1;
+-                      len += SSL3_RT_MAX_EXTRA;
++                      len = SSL3_RT_DEFAULT_PACKET_SIZE;
++                      }
++              else
++                      {
++                      len = SSL3_RT_MAX_PLAIN_LENGTH
++                              + SSL3_RT_MAX_ENCRYPTED_OVERHEAD
++                              + headerlen + align;
++                      if (s->options & SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER)
++                              {
++                              s->s3->init_extra = 1;
++                              len += SSL3_RT_MAX_EXTRA;
++                              }
+                       }
+ #ifndef OPENSSL_NO_COMP
+               if (!(s->options & SSL_OP_NO_COMPRESSION))
+@@ -757,7 +771,15 @@ int ssl3_setup_write_buffer(SSL *s)
+       if (s->s3->wbuf.buf == NULL)
+               {
+-              len = s->max_send_fragment
++              if (SSL_get_mode(s) & SSL_MODE_SMALL_BUFFERS)
++                      {
++                      len = SSL3_RT_DEFAULT_PACKET_SIZE;
++                      }
++              else
++                      {
++                      len = s->max_send_fragment;
++                      }
++              len += 0
+                       + SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD
+                       + headerlen + align;
+ #ifndef OPENSSL_NO_COMP
+@@ -767,7 +789,6 @@ int ssl3_setup_write_buffer(SSL *s)
+               if (!(s->options & SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS))
+                       len += headerlen + align
+                               + SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD;
+-
+               if ((p=freelist_extract(s->ctx, 0, len)) == NULL)
+                       goto err;
+               s->s3->wbuf.buf = p;
+@@ -810,4 +831,3 @@ int ssl3_release_read_buffer(SSL *s)
+               }
+       return 1;
+       }
+-
+--- openssl-1.0.0a.orig/ssl/s3_pkt.c   2010-03-25 11:22:42.000000000 +0000
++++ openssl-1.0.0a/ssl/s3_pkt.c        2010-08-25 21:12:39.000000000 +0000
+@@ -293,6 +293,11 @@ static int ssl3_get_record(SSL *s)
+       size_t extra;
+       int decryption_failed_or_bad_record_mac = 0;
+       unsigned char *mac = NULL;
++#if defined(SSL3_ALIGN_PAYLOAD) && SSL3_ALIGN_PAYLOAD!=0
++      long align=SSL3_ALIGN_PAYLOAD;
++#else
++      long align=0;
++#endif
+       rr= &(s->s3->rrec);
+       sess=s->session;
+@@ -301,7 +306,8 @@ static int ssl3_get_record(SSL *s)
+               extra=SSL3_RT_MAX_EXTRA;
+       else
+               extra=0;
+-      if (extra && !s->s3->init_extra)
++      if (!(SSL_get_mode(s) & SSL_MODE_SMALL_BUFFERS) &&
++              extra && !s->s3->init_extra)
+               {
+               /* An application error: SLS_OP_MICROSOFT_BIG_SSLV3_BUFFER
+                * set after ssl3_setup_buffers() was done */
+@@ -350,6 +356,21 @@ fprintf(stderr, "Record type=%d, Length=
+                       goto err;
+                       }
++              /* If we receive a valid record larger than the current buffer size,
++               * allocate some memory for it.
++               */
++              if (rr->length > s->s3->rbuf.len - SSL3_RT_HEADER_LENGTH - align)
++                      {
++                      if ((p=OPENSSL_realloc(s->s3->rbuf.buf, rr->length + SSL3_RT_HEADER_LENGTH + align))==NULL)
++                              {
++                              SSLerr(SSL_F_SSL3_GET_RECORD,ERR_R_MALLOC_FAILURE);
++                              goto err;
++                              }
++                      s->s3->rbuf.buf=p;
++                      s->s3->rbuf.len=rr->length + SSL3_RT_HEADER_LENGTH + align;
++                      s->packet= &(s->s3->rbuf.buf[0]);
++                      }
++
+               if (rr->length > s->s3->rbuf.len - SSL3_RT_HEADER_LENGTH)
+                       {
+                       al=SSL_AD_RECORD_OVERFLOW;
+@@ -576,6 +597,7 @@ int ssl3_write_bytes(SSL *s, int type, c
+       const unsigned char *buf=buf_;
+       unsigned int tot,n,nw;
+       int i;
++      unsigned int max_plain_length;
+       s->rwstate=SSL_NOTHING;
+       tot=s->s3->wnum;
+@@ -595,8 +617,13 @@ int ssl3_write_bytes(SSL *s, int type, c
+       n=(len-tot);
+       for (;;)
+               {
+-              if (n > s->max_send_fragment)
+-                      nw=s->max_send_fragment;
++              if (type == SSL3_RT_APPLICATION_DATA && (SSL_get_mode(s) & SSL_MODE_SMALL_BUFFERS))
++                      max_plain_length = SSL3_RT_DEFAULT_PLAIN_LENGTH;
++              else
++                      max_plain_length = s->max_send_fragment;
++
++              if (n > max_plain_length)
++                      nw = max_plain_length;
+               else
+                       nw=n;
+@@ -727,6 +727,18 @@ static int do_ssl3_write(SSL *s, int type, const unsigned char *buf,
+               s->s3->empty_fragment_done = 1;
+               }
++      /* resize if necessary to hold the data. */
++      if (len + SSL3_RT_DEFAULT_WRITE_OVERHEAD > wb->len)
++              {
++              if ((p=OPENSSL_realloc(wb->buf, len + SSL3_RT_DEFAULT_WRITE_OVERHEAD))==NULL)
++                      {
++                      SSLerr(SSL_F_DO_SSL3_WRITE,ERR_R_MALLOC_FAILURE);
++                      goto err;
++                      }
++              wb->buf = p;
++              wb->len = len + SSL3_RT_DEFAULT_WRITE_OVERHEAD;
++              }
++
+       if (create_empty_fragment)
+               {
+ #if defined(SSL3_ALIGN_PAYLOAD) && SSL3_ALIGN_PAYLOAD!=0
+--- openssl-1.0.0a.orig/ssl/ssl.h      2010-01-06 17:37:38.000000000 +0000
++++ openssl-1.0.0a/ssl/ssl.h   2010-08-25 21:12:39.000000000 +0000
+@@ -602,6 +602,9 @@ typedef struct ssl_session_st
+  * TLS only.)  "Released" buffers are put onto a free-list in the context
+  * or just freed (depending on the context's setting for freelist_max_len). */
+ #define SSL_MODE_RELEASE_BUFFERS 0x00000010L
++/* Use small read and write buffers: (a) lazy allocate read buffers for
++ * large incoming records, and (b) limit the size of outgoing records. */
++#define SSL_MODE_SMALL_BUFFERS 0x00000020L
+ /* Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value,
+  * they cannot be used to clear bits. */
+--- openssl-1.0.0a.orig/ssl/ssl3.h     2010-01-06 17:37:38.000000000 +0000
++++ openssl-1.0.0a/ssl/ssl3.h  2010-08-25 21:12:39.000000000 +0000
+@@ -280,6 +280,9 @@ extern "C" {
+ #define SSL3_RT_MAX_EXTRA                     (16384)
++/* Default buffer length used for writen records.  Thus a generated record
++ * will contain plaintext no larger than this value. */
++#define SSL3_RT_DEFAULT_PLAIN_LENGTH  2048
+ /* Maximum plaintext length: defined by SSL/TLS standards */
+ #define SSL3_RT_MAX_PLAIN_LENGTH              16384
+ /* Maximum compression overhead: defined by SSL/TLS standards */
+@@ -311,6 +314,13 @@ extern "C" {
+ #define SSL3_RT_MAX_PACKET_SIZE               \
+               (SSL3_RT_MAX_ENCRYPTED_LENGTH+SSL3_RT_HEADER_LENGTH)
++/* Extra space for empty fragment, headers, MAC, and padding. */
++#define SSL3_RT_DEFAULT_WRITE_OVERHEAD  256
++#define SSL3_RT_DEFAULT_PACKET_SIZE     4096 - SSL3_RT_DEFAULT_WRITE_OVERHEAD
++#if SSL3_RT_DEFAULT_PLAIN_LENGTH + SSL3_RT_DEFAULT_WRITE_OVERHEAD > SSL3_RT_DEFAULT_PACKET_SIZE
++#error "Insufficient space allocated for write buffers."
++#endif
++
+ #define SSL3_MD_CLIENT_FINISHED_CONST "\x43\x4C\x4E\x54"
+ #define SSL3_MD_SERVER_FINISHED_CONST "\x53\x52\x56\x52"
+@@ -634,4 +645,3 @@ typedef struct ssl3_state_st
+ }
+ #endif
+ #endif
+-
+--- openssl-1.0.0a.orig/ssl/ssltest.c  2010-01-24 16:57:38.000000000 +0000
++++ openssl-1.0.0a/ssl/ssltest.c       2010-08-25 21:12:39.000000000 +0000
+@@ -316,6 +316,8 @@ static void sv_usage(void)
+                      "                 (default is sect163r2).\n");
+ #endif
+       fprintf(stderr," -test_cipherlist - verifies the order of the ssl cipher lists\n");
++      fprintf(stderr," -c_small_records - enable client side use of small SSL record buffers\n");
++      fprintf(stderr," -s_small_records - enable server side use of small SSL record buffers\n");
+       }
+ static void print_details(SSL *c_ssl, const char *prefix)
+@@ -444,6 +447,9 @@ int opaque_prf_input_cb(SSL *ssl, void *
+       return arg->ret;
+       }
+ #endif
++      int ssl_mode = 0;
++      int c_small_records=0;
++      int s_small_records=0;
+ int main(int argc, char *argv[])
+       {
+@@ -680,6 +687,14 @@ int main(int argc, char *argv[])
+                       {
+                       test_cipherlist = 1;
+                       }
++              else if (strcmp(*argv, "-c_small_records") == 0)
++                      {
++                      c_small_records = 1;
++                      }
++              else if (strcmp(*argv, "-s_small_records") == 0)
++                      {
++                      s_small_records = 1;
++                      }
+               else
+                       {
+                       fprintf(stderr,"unknown option %s\n",*argv);
+@@ -802,6 +821,21 @@ bad:
+               SSL_CTX_set_cipher_list(s_ctx,cipher);
+               }
++      ssl_mode = 0;
++      if (c_small_records)
++              {
++              ssl_mode = SSL_CTX_get_mode(c_ctx);
++              ssl_mode |= SSL_MODE_SMALL_BUFFERS;
++              SSL_CTX_set_mode(c_ctx, ssl_mode);
++              }
++      ssl_mode = 0;
++      if (s_small_records)
++              {
++              ssl_mode = SSL_CTX_get_mode(s_ctx);
++              ssl_mode |= SSL_MODE_SMALL_BUFFERS;
++              SSL_CTX_set_mode(s_ctx, ssl_mode);
++              }
++
+ #ifndef OPENSSL_NO_DH
+       if (!no_dhe)
+               {
+--- openssl-1.0.0.orig/test/testssl    2006-03-10 15:06:27.000000000 -0800
++++ openssl-1.0.0/test/testssl 2010-04-26 10:24:55.000000000 -0700
+@@ -70,6 +70,16 @@ $ssltest -client_auth $CA $extra || exit
+ echo test sslv2/sslv3 with both client and server authentication
+ $ssltest -server_auth -client_auth $CA $extra || exit 1
++echo test sslv2/sslv3 with both client and server authentication and small client buffers
++$ssltest -server_auth -client_auth -c_small_records $CA $extra || exit 1
++
++echo test sslv2/sslv3 with both client and server authentication and small server buffers
++$ssltest -server_auth -client_auth -s_small_records $CA $extra || exit 1
++
++echo test sslv2/sslv3 with both client and server authentication and small client and server buffers
++$ssltest -server_auth -client_auth -c_small_records -s_small_records $CA $extra || exit 1
++
++
+ echo test sslv2 via BIO pair
+ $ssltest -bio_pair -ssl2 $extra || exit 1
diff --git a/deps/openssl/patches/snap_start.patch b/deps/openssl/patches/snap_start.patch
deleted file mode 100644 (file)
index 9eb1b0c..0000000
+++ /dev/null
@@ -1,780 +0,0 @@
-commit ca77729f0395a16f08ff5d54968e05dbd84b331f
-Author: Adam Langley <agl@chromium.org>
-Date:   Thu Nov 4 16:09:48 2010 -0400
-
-    snap_start.patch
-
-diff --git a/apps/s_server.c b/apps/s_server.c
-index c4e19c9..37db8f9 100644
---- a/apps/s_server.c
-+++ b/apps/s_server.c
-@@ -802,6 +802,7 @@ int MAIN(int argc, char *argv[])
-         tlsextctx tlsextcbp = {NULL, NULL, SSL_TLSEXT_ERR_ALERT_WARNING};
-       const char *next_proto_neg_in = NULL;
-       tlsextnextprotoctx next_proto;
-+      char snapstart = 0;
- #endif
- #if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL3)
-@@ -1105,6 +1106,10 @@ int MAIN(int argc, char *argv[])
-                       if (--argc < 1) goto bad;
-                       next_proto_neg_in = *(++argv);
-                       }
-+              else if (strcmp(*argv,"-snapstart") == 0)
-+                      {
-+                      snapstart = 1;
-+                      }
- #endif
- #ifndef OPENSSL_NO_JPAKE
-               else if (strcmp(*argv,"-jpake") == 0)
-@@ -1389,6 +1394,11 @@ bad:
-               }
- #endif 
-+      if (snapstart)
-+              {
-+              static const unsigned char orbit[8] = {1, 2, 3, 4, 5, 6, 7, 8};
-+              SSL_CTX_set_snap_start_orbit(ctx, orbit);
-+              }
- #ifndef OPENSSL_NO_DH
-       if (!no_dhe)
-@@ -2031,6 +2041,7 @@ static int init_ssl_connection(SSL *con)
-       unsigned next_proto_neg_len;
- #endif
-+again:
-       if ((i=SSL_accept(con)) <= 0)
-               {
-               if (BIO_sock_should_retry(i))
-@@ -2039,6 +2050,12 @@ static int init_ssl_connection(SSL *con)
-                       return(1);
-                       }
-+              if (SSL_get_error(con, i) == SSL_ERROR_SERVER_RANDOM_VALIDATION_PENDING)
-+                      {
-+                      SSL_set_suggested_server_random_validity(con, 1);
-+                      goto again;
-+                      }
-+
-               BIO_printf(bio_err,"ERROR\n");
-               verify_error=SSL_get_verify_result(con);
-               if (verify_error != X509_V_OK)
-@@ -2224,6 +2241,9 @@ static int www_body(char *hostname, int s, unsigned char *context)
-                       case SSL_ERROR_WANT_READ:
-                       case SSL_ERROR_WANT_X509_LOOKUP:
-                               continue;
-+                      case SSL_ERROR_SERVER_RANDOM_VALIDATION_PENDING:
-+                              SSL_set_suggested_server_random_validity(con, 1);
-+                              continue;
-                       case SSL_ERROR_SYSCALL:
-                       case SSL_ERROR_SSL:
-                       case SSL_ERROR_ZERO_RETURN:
-diff --git a/ssl/s3_enc.c b/ssl/s3_enc.c
-index 06e5466..e32f97d 100644
---- a/ssl/s3_enc.c
-+++ b/ssl/s3_enc.c
-@@ -111,6 +111,7 @@
- #include <stdio.h>
- #include "ssl_locl.h"
-+#include "fnv1a64.h"
- #include <openssl/evp.h>
- #include <openssl/md5.h>
-@@ -529,6 +530,11 @@ void ssl3_finish_mac(SSL *s, const unsigned char *buf, int len)
-       {
-       EVP_DigestUpdate(&(s->s3->finish_dgst1),buf,len);
-       EVP_DigestUpdate(&(s->s3->finish_dgst2),buf,len);
-+      if (s->s3->snap_start_requested)
-+              {
-+              /* Compute Fowler-Noll-Vo (FNV) hash for Snap Start handshake */
-+              fnv1a64_update((FNV1A64*) s->s3->response_hash, buf, len);
-+              }
-       }
- int ssl3_cert_verify_mac(SSL *s, EVP_MD_CTX *ctx, unsigned char *p)
-diff --git a/ssl/s3_lib.c b/ssl/s3_lib.c
-index 84bff8d..1058b4e 100644
---- a/ssl/s3_lib.c
-+++ b/ssl/s3_lib.c
-@@ -1701,6 +1701,12 @@ void ssl3_free(SSL *s)
-       pq_64bit_free(&(s->s3->rrec.seq_num));
-       pq_64bit_free(&(s->s3->wrec.seq_num));
-+      if (s->s3->snap_start_client_hello.buf)
-+              {
-+              /* s->s3->snap_start_records, if set, uses the same buffer */
-+              OPENSSL_free(s->s3->snap_start_client_hello.buf);
-+              }
-+
-       OPENSSL_cleanse(s->s3,sizeof *s->s3);
-       OPENSSL_free(s->s3);
-       s->s3=NULL;
-diff --git a/ssl/s3_pkt.c b/ssl/s3_pkt.c
-index 6853058..61774b2 100644
---- a/ssl/s3_pkt.c
-+++ b/ssl/s3_pkt.c
-@@ -120,8 +120,51 @@ static int do_ssl3_write(SSL *s, int type, const unsigned char *buf,
-                        unsigned int len, int create_empty_fragment);
- static int ssl3_get_record(SSL *s);
-+/* ssl3_read_snap_start_n reads from the opportunistic records contained within
-+ * a Snap Start extension. |s->packet| and |s->packet_length| are set to frame
-+ * a record within this area. Partial records are not allowed. The Snap Start
-+ * records are held in |s->s3->snap_start_records| and the |left| member must
-+ * be non-zero on entry.
-+ *
-+ * If |extend| is true then we'll expand the currently framed record by |n|
-+ * bytes, otherwise we frame a new record. */
-+static int ssl3_read_snap_start_n(SSL *s, int n, int extend)
-+      {
-+      if (!extend)
-+              {
-+              s->packet = s->s3->snap_start_records.buf + s->s3->snap_start_records.offset;
-+              s->packet_length = 0;
-+              }
-+
-+      if (s->s3->snap_start_records.left < n)
-+              {
-+              /* We aren't called unless .left is non-zero, therefore this
-+               * means that we wanted to read more than we have. Since
-+               * partial records aren't allowed, this is fatal. */
-+              SSLerr(SSL_F_SSL3_READ_SNAP_START_N,SSL_R_BAD_PACKET_LENGTH);
-+              return -1;
-+              }
-+
-+      s->packet_length += n;
-+      s->s3->snap_start_records.left -= n;
-+      s->s3->snap_start_records.offset += n;
-+
-+      return n;
-+      }
-+
- int ssl3_read_n(SSL *s, int n, int max, int extend)
-       {
-+      if (s->s3->snap_start_records.left)
-+              return ssl3_read_snap_start_n(s, n, extend);
-+      else if (s->s3->snap_start_client_hello.buf && !extend)
-+              {
-+              /* If we started reading the opportunistic records then we know
-+               * that we didn't enter recovery. Thus it's safe to free the
-+               * copy of the ClientHello now because we'll not need it again. */
-+              OPENSSL_free(s->s3->snap_start_client_hello.buf);
-+              s->s3->snap_start_client_hello.buf = NULL;
-+              }
-+
-       /* If extend == 0, obtain new n-byte packet; if extend == 1, increase
-        * packet by another n bytes.
-        * The packet will be in the sub-array of s->s3->rbuf.buf specified
-diff --git a/ssl/s3_srvr.c b/ssl/s3_srvr.c
-index 8e0a504..315b8f3 100644
---- a/ssl/s3_srvr.c
-+++ b/ssl/s3_srvr.c
-@@ -144,6 +144,7 @@
- #include <openssl/md5.h>
- static SSL_METHOD *ssl3_get_server_method(int ver);
-+static int ssl3_snap_start_evaluate_handshake(SSL* s);
- #ifndef OPENSSL_NO_ECDH
- static int nid2curve_id(int nid);
- #endif
-@@ -300,10 +301,36 @@ int ssl3_accept(SSL *s)
-               case SSL3_ST_SW_SRVR_HELLO_A:
-               case SSL3_ST_SW_SRVR_HELLO_B:
-                       ret=ssl3_send_server_hello(s);
-+                      if (ret == SERVER_RANDOM_VALIDATION_PENDING)
-+                              {
-+                              s->rwstate = SSL_SERVER_RANDOM_VALIDATE;
-+                              s->state = SSL3_ST_SW_SRVR_HELLO_A;
-+                              s->init_num = 0;
-+                              goto end;
-+                              }
-                       if (ret <= 0) goto end;
- #ifndef OPENSSL_NO_TLSEXT
-+                      if ((s->s3->tmp.new_cipher->algorithms & SSL_MKEY_MASK) != SSL_kRSA &&
-+                          (s->s3->tmp.new_cipher->algorithms & SSL_MKEY_MASK) != SSL_kKRB5 &&
-+                          (s->s3->tmp.new_cipher->algorithms & SSL_MKEY_MASK) != SSL_kDHr &&
-+                          (s->s3->tmp.new_cipher->algorithms & SSL_MKEY_MASK) != SSL_kDHd &&
-+                          (s->s3->tmp.new_cipher->algorithms & SSL_MKEY_MASK) != SSL_kECDH &&
-+                          s->s3->snap_start_requested)
-+                              {
-+                              /* There's no point in carrying on with a Snap
-+                               * Start handshake if we're using a cipher
-+                               * suite which is going to send a
-+                               * ServerKeyExchange message. */
-+                              ssl3_snap_start_reset_for_recovery(s);
-+                              s->state = SSL3_ST_SW_SRVR_HELLO_A;
-+                              break;
-+                              }
-+
-                       if (s->hit)
-                               {
-+                              if (ssl3_snap_start_evaluate_handshake(s))
-+                                      break;
-+
-                               if (s->tlsext_ticket_expected)
-                                       s->state=SSL3_ST_SW_SESSION_TICKET_A;
-                               else
-@@ -440,8 +467,19 @@ int ssl3_accept(SSL *s)
-               case SSL3_ST_SW_SRVR_DONE_B:
-                       ret=ssl3_send_server_done(s);
-                       if (ret <= 0) goto end;
--                      s->s3->tmp.next_state=SSL3_ST_SR_CERT_A;
--                      s->state=SSL3_ST_SW_FLUSH;
-+
-+                      if (s->s3->snap_start_requested)
-+                              {
-+                              if (ssl3_snap_start_evaluate_handshake(s))
-+                                      break;
-+                              s->state = SSL3_ST_SR_CERT_A;
-+                              }
-+                      else
-+                              {
-+                                      s->s3->tmp.next_state=SSL3_ST_SR_CERT_A;
-+                                      s->state=SSL3_ST_SW_FLUSH;
-+                              }
-+
-                       s->init_num=0;
-                       break;
-               
-@@ -1152,11 +1190,19 @@ int ssl3_send_server_hello(SSL *s)
-       if (s->state == SSL3_ST_SW_SRVR_HELLO_A)
-               {
-               buf=(unsigned char *)s->init_buf->data;
--              p=s->s3->server_random;
--              Time=(unsigned long)time(NULL);                 /* Time */
--              l2n(Time,p);
--              if (RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0)
--                      return -1;
-+              if (!s->s3->snap_start_requested)
-+                      {
-+                      p=s->s3->server_random;
-+                      Time=(unsigned long)time(NULL);                 /* Time */
-+                      l2n(Time,p);
-+                      if (RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0)
-+                              return -1;
-+                      }
-+              else if (s->s3->server_random_suggestion_valid == 0)
-+                      {
-+                      return SERVER_RANDOM_VALIDATION_PENDING;
-+                      }
-+
-               /* Do the message type and length last */
-               d=p= &(buf[4]);
-@@ -2952,3 +2998,55 @@ int ssl3_send_cert_status(SSL *s)
-       return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
-       }
- #endif
-+
-+/* ssl3_snap_start_evaluate_handshake verifies the Snap Start prediction (if
-+ * this is a Snap Start handshake). If it returns non-zero, then we are
-+ * entering recovery and |s->state| has been set accordingly. */
-+static int ssl3_snap_start_evaluate_handshake(SSL* s)
-+      {
-+      unsigned char digest[8];
-+
-+      if (!s->s3->snap_start_requested)
-+              return 0;
-+
-+      /* Drop the currently queued messages. Either we're entering recovery,
-+       * in which case they're wrong, or we're doing snap start, in which
-+       * case we don't want to send them. */
-+      if (!ssl_init_wbio_buffer(s, 1 /* push new BIO */))
-+              return -1;
-+
-+      fnv1a64_final(digest, (FNV1A64*) s->s3->response_hash);
-+
-+      /* Turn off FNV hashing of handshake messages. */
-+      s->s3->snap_start_requested = 0;
-+
-+      if (memcmp(digest, s->s3->predicted_response_hash, sizeof(digest)) != 0)
-+              {
-+              /* The predicted handshake didn't match. */
-+              ssl3_snap_start_reset_for_recovery(s);
-+              s->state = SSL3_ST_SW_SRVR_HELLO_A;
-+              return 1;
-+              }
-+
-+      return 0;
-+      }
-+
-+/* ssl3_snap_start_reset_for_recovery is called is called when a Snap Start
-+ * handshake is impossible because either the application layer has rejected
-+ * the client's suggested server random, or predicated_response_hash failed to
-+ * match response_hash */
-+int ssl3_snap_start_reset_for_recovery(SSL* s)
-+      {
-+      s->s3->snap_start_requested = 0;
-+      s->s3->snap_start_records.left = 0;
-+      s->init_num = 0;
-+
-+      /* Reset the handshake hash and hash in the original ClientHello. */
-+      ssl3_init_finished_mac(s);
-+      ssl3_finish_mac(s, s->s3->snap_start_client_hello.buf, s->s3->snap_start_client_hello.left);
-+
-+      OPENSSL_free(s->s3->snap_start_client_hello.buf);
-+      s->s3->snap_start_client_hello.buf = NULL;
-+
-+      return 0;
-+      }
-diff --git a/ssl/ssl.h b/ssl/ssl.h
-index dc8dff8..bbe2543 100644
---- a/ssl/ssl.h
-+++ b/ssl/ssl.h
-@@ -770,6 +770,11 @@ struct ssl_ctx_st
-       X509_VERIFY_PARAM *param;
-+      /* The configured Snap Start orbit value, if set. */
-+      char snap_start_orbit_valid;
-+      unsigned char snap_start_orbit[8];
-+
-+
- #if 0
-       int purpose;            /* Purpose setting */
-       int trust;              /* Trust setting */
-@@ -876,10 +881,14 @@ void SSL_CTX_set_cookie_generate_cb(SSL_CTX *ctx, int (*app_gen_cookie_cb)(SSL *
- void SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx, int (*app_verify_cookie_cb)(SSL *ssl, unsigned char *cookie, unsigned int cookie_len));
- void SSL_CTX_set_next_protos_advertised_cb(SSL_CTX *s, int (*cb) (SSL *ssl, const unsigned char **out, unsigned int *outlen, void *arg), void *arg);
- void SSL_CTX_set_next_proto_select_cb(SSL_CTX *s, int (*cb) (SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg), void *arg);
-+void SSL_CTX_set_snap_start_orbit(SSL_CTX *s, const unsigned char orbit[8]);
- int SSL_select_next_proto(unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, const unsigned char *client, unsigned int client_len);
- void SSL_get0_next_proto_negotiated(const SSL *s, const unsigned char **data, unsigned *len);
-+void SSL_get0_suggested_server_random(const SSL *s, const unsigned char **data, unsigned *len);
-+void SSL_set_suggested_server_random_validity(SSL *s, char is_valid);
-+
- #define OPENSSL_NPN_UNSUPPORTED       0
- #define OPENSSL_NPN_NEGOTIATED        1
- #define OPENSSL_NPN_NO_OVERLAP        2
-@@ -888,12 +897,14 @@ void SSL_get0_next_proto_negotiated(const SSL *s, const unsigned char **data, un
- #define SSL_WRITING   2
- #define SSL_READING   3
- #define SSL_X509_LOOKUP       4
-+#define SSL_SERVER_RANDOM_VALIDATE    6
- /* These will only be used when doing non-blocking IO */
- #define SSL_want_nothing(s)   (SSL_want(s) == SSL_NOTHING)
- #define SSL_want_read(s)      (SSL_want(s) == SSL_READING)
- #define SSL_want_write(s)     (SSL_want(s) == SSL_WRITING)
- #define SSL_want_x509_lookup(s)       (SSL_want(s) == SSL_X509_LOOKUP)
-+#define SSL_want_server_random_validation(s)  (SSL_want(s) == SSL_SERVER_RANDOM_VALIDATE)
- struct ssl_st
-       {
-@@ -1255,6 +1266,7 @@ size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count);
- #define SSL_ERROR_ZERO_RETURN         6
- #define SSL_ERROR_WANT_CONNECT                7
- #define SSL_ERROR_WANT_ACCEPT         8
-+#define SSL_ERROR_SERVER_RANDOM_VALIDATION_PENDING    10
- #define SSL_CTRL_NEED_TMP_RSA                 1
- #define SSL_CTRL_SET_TMP_RSA                  2
-@@ -1754,6 +1766,7 @@ void ERR_load_SSL_strings(void);
- #define SSL_F_GET_SERVER_VERIFY                                110
- #define SSL_F_I2D_SSL_SESSION                          111
- #define SSL_F_READ_N                                   112
-+#define SSL_F_SSL3_READ_SNAP_START_N                   300
- #define SSL_F_REQUEST_CERTIFICATE                      113
- #define SSL_F_SERVER_FINISH                            239
- #define SSL_F_SERVER_HELLO                             114
-@@ -1907,7 +1920,7 @@ void ERR_load_SSL_strings(void);
- #define SSL_F_TLS1_ENC                                         210
- #define SSL_F_TLS1_SETUP_KEY_BLOCK                     211
- #define SSL_F_WRITE_PENDING                            212
--/* Next entry: 299 */
-+/* Next entry: 300 */
- /* Reason codes. */
- #define SSL_R_APP_DATA_IN_HANDSHAKE                    100
-diff --git a/ssl/ssl3.h b/ssl/ssl3.h
-index 54b73b7..4a6e8cf 100644
---- a/ssl/ssl3.h
-+++ b/ssl/ssl3.h
-@@ -452,6 +452,48 @@ typedef struct ssl3_state_st
-         unsigned char previous_server_finished[EVP_MAX_MD_SIZE];
-         unsigned char previous_server_finished_len;
-         int send_connection_binding; /* TODOEKR */
-+
-+      /* Snap Start support (server-side only):
-+       *
-+       * Snap Start allows the client to 'suggest' the value of our random
-+       * nonce. Assuming that we accept this suggestion, then the client can
-+       * predict our exact reply and calculate a complete handshake based on
-+       * that. These opportunistic handshake messages are embedded in the
-+       * Snap Start extension, possibly including application data.
-+       *
-+       * (Note that if the handshake doesn't resume a session, the client
-+       * couldn't hope to predict the exact server reply unless it uses the
-+       * session ticket extension to suppress session ID generation.)
-+       *
-+       * All this allows for a TLS handshake that doesn't incur additional
-+       * latency if the client side sends application data first. */
-+
-+      /* Set if the client presented a Snap Start extension (empty or
-+       * otherwise and the SSL_CTX has a cell configured. Server side only. */
-+      int snap_start_ext_seen;
-+      /* Set if the client-suggested a server random value (which is stored
-+       * in |server_random|) */
-+      char snap_start_requested;
-+      /* Set if the appplication has indicated that the client's
-+       * server_random suggestion is acceptable (see
-+       * SSL_set_suggested_server_random_validity). If so, a Snap Start
-+       * handshake will be attempted. */
-+      char server_random_suggestion_valid;
-+      /* Client's predicted response_hash from client snap start extension.
-+       * Valid if |snap_start_requested| is set. */
-+      unsigned char predicted_response_hash[8];
-+      /* Actual server handshake message hash.  A Snap Start handshake is
-+       * possible only if predicated_response_hash matches this. */
-+      unsigned char response_hash[8];
-+      /* If we need to enter snap start recovery then we need to reset the
-+       * Finished hash with a different value for the ClientHello. Thus, we
-+       * need a copy of the whole ClientHello: */
-+      SSL3_BUFFER snap_start_client_hello;
-+      /* A snap start ClientHello can contain records embedded in an
-+       * extension. If we wish to read them then this points to the records
-+       * within |snap_start_client_hello|. */
-+      SSL3_BUFFER snap_start_records;
-+
-       } SSL3_STATE;
-diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c
-index cfa70ec..88358fb 100644
---- a/ssl/ssl_lib.c
-+++ b/ssl/ssl_lib.c
-@@ -2119,6 +2119,9 @@ int SSL_get_error(const SSL *s,int i)
-                       return(SSL_ERROR_SSL);
-               }
-+      if ((i < 0) && SSL_want_server_random_validation(s))
-+              return(SSL_ERROR_SERVER_RANDOM_VALIDATION_PENDING);
-+
-       if ((i < 0) && SSL_want_read(s))
-               {
-               bio=SSL_get_rbio(s);
-@@ -2876,6 +2879,61 @@ void SSL_CTX_set_next_proto_select_cb(SSL_CTX *ctx, int (*cb) (SSL *s, unsigned
-       ctx->next_proto_select_cb = cb;
-       ctx->next_proto_select_cb_arg = arg;
-       }
-+
-+/* SSL_CTX_set_snap_start_orbit sets the orbit value which will be echoed back
-+ * to the client and enables Snap Start for this context.
-+ *
-+ * An orbit value can be used to spatially partition the state needed to support
-+ * Snap Start. See the comments above SSL_set_suggested_server_random_validity
-+ * (below).  */
-+void SSL_CTX_set_snap_start_orbit(SSL_CTX *ctx, const unsigned char orbit[8])
-+      {
-+      memcpy(ctx->snap_start_orbit, orbit, sizeof(ctx->snap_start_orbit));
-+      ctx->snap_start_orbit_valid = 1;
-+      }
-+
-+/* Once SSL_accept has returned with SSL_SERVER_RANDOM_VALIDATE, then one can
-+ * call this function in order to get the client's suggested server random
-+ * value. */
-+void SSL_get0_suggested_server_random(const SSL* s, const unsigned char **data, unsigned *length)
-+      {
-+      if (!s->s3->snap_start_requested)
-+              {
-+              *data = NULL;
-+              *length = 0;
-+              return;
-+              }
-+      *length = 32;
-+      *data = s->s3->server_random;
-+      }
-+
-+/* SSL_set_suggested_server_random_validity passes judgement on a
-+ * client-suggested random value (obtained from
-+ * SSL_get0_suggested_server_random). Rejecting the value triggers a recovery,
-+ * while accepting the value /may/ result in a successful Snap Start, as long
-+ * as the client predicted the handshake correctly.
-+ *
-+ * In order to accept a random value the user must ensure that it has NEVER
-+ * been used before by this server, or any server configured with any of the
-+ * same certificates. It may reject more if necessary.
-+ *
-+ * The first four bytes of the random value contain a timestamp (UNIX seconds
-+ * since the epoch) which can be used to manage a time window.  Additionally,
-+ * the following eight bytes contain the orbit which which can also bound the
-+ * state required if geographically separate servers share certificates.
-+ *
-+ * It's recommended that the time window have a maximum size, independent of
-+ * the resources available, in order to prevent an attacker from arbitrarily
-+ * delaying a Snap Start handshake.
-+ */
-+void SSL_set_suggested_server_random_validity(SSL *s, char is_valid)
-+      {
-+      if (is_valid)
-+              s->s3->server_random_suggestion_valid = 1;
-+      else
-+              ssl3_snap_start_reset_for_recovery(s);
-+      }
-+
- #endif
- int SSL_cutthrough_complete(const SSL *s)
-diff --git a/ssl/ssl_locl.h b/ssl/ssl_locl.h
-index a9183ff..639a185 100644
---- a/ssl/ssl_locl.h
-+++ b/ssl/ssl_locl.h
-@@ -392,6 +392,11 @@
- #define CERT_PRIVATE_KEY      2
- */
-+/* This can be returned from ssl3_send_server_hello to indicate that an
-+ * offline validation of a client-suggested server_random needs to be
-+ * performed. */
-+#define SERVER_RANDOM_VALIDATION_PENDING -(TLSEXT_TYPE_snap_start)
-+
- #ifndef OPENSSL_NO_EC
- /* From ECC-TLS draft, used in encoding the curve type in 
-  * ECParameters
-@@ -915,6 +920,7 @@ int ssl3_get_client_certificate(SSL *s);
- int ssl3_get_client_key_exchange(SSL *s);
- int ssl3_get_cert_verify(SSL *s);
- int ssl3_get_next_proto(SSL *s);
-+int ssl3_snap_start_reset_for_recovery(SSL* s);
- int dtls1_send_hello_request(SSL *s);
- int dtls1_send_server_hello(SSL *s);
-diff --git a/ssl/t1_lib.c b/ssl/t1_lib.c
-index fd35b18..ce33f16 100644
---- a/ssl/t1_lib.c
-+++ b/ssl/t1_lib.c
-@@ -62,6 +62,7 @@
- #include <openssl/hmac.h>
- #include <openssl/ocsp.h>
- #include "ssl_locl.h"
-+#include "fnv1a64.h"
- const char tls1_version_str[]="TLSv1" OPENSSL_VERSION_PTEXT;
-@@ -368,6 +369,21 @@ unsigned char *ssl_add_serverhello_tlsext(SSL *s, unsigned char *p, unsigned cha
-                       }
-               }
-+      if (s->s3->snap_start_ext_seen)
-+              {
-+              if ((long)(limit - ret - 14) < 0) return NULL;
-+              s2n(TLSEXT_TYPE_snap_start,ret);
-+              s2n(10,ret); /* extension length */
-+              memcpy(ret, s->ctx->snap_start_orbit, 8);
-+              ret += 8;
-+              /* This is the ciphersuite that we would pick in the event of a
-+               * Snap Start handshake. (Maybe the server wants to do EDH
-+               * unless the client is Snap Start capable). At the moment we
-+               * don't have any logic to pick a different cipher suite so we
-+               * repeat the choice from the ServerHello. */
-+              s2n(s->s3->tmp.new_cipher->id & 0xffff,ret);
-+              }
-+
-       if ((extdatalen = ret-p-2)== 0) 
-               return p;
-@@ -375,6 +391,174 @@ unsigned char *ssl_add_serverhello_tlsext(SSL *s, unsigned char *p, unsigned cha
-       return ret;
-       }
-+
-+static int ssl_hash_snap_start_client_hello(SSL* s,
-+                                          const char* data,
-+                                          unsigned len,
-+                                          unsigned ext_len)
-+      {
-+      /* We walk the ClientHello from the beginning, writing
-+       * adjusted lengths into |b| and hashing as we go.
-+       *
-+       * The resulting ClientHello is going to be shorter by the length of
-+       * this extension, which is |ext_len + 4| (two bytes for the type and two for
-+       * the length). */
-+
-+      const unsigned char *p;
-+      unsigned remaining;
-+      unsigned char b[3], *c;
-+      unsigned long l;
-+
-+      p = (unsigned char*) data;
-+      remaining = len;
-+      /* Handshake header: type */
-+      if (!remaining)
-+              return 0;
-+      ssl3_finish_mac(s, p, 1);
-+      p++;
-+      remaining--;
-+      /* Handshake header: length */
-+      if (remaining < 3)
-+              return 0;
-+      n2l3(p, l);
-+      l -= ext_len + 4;
-+      c = b;
-+      l2n3(l, c);
-+      ssl3_finish_mac(s, b, 3);
-+      remaining -= 3;
-+      /* ClientHello: version and random */
-+      if (remaining < 34)
-+              return 0;
-+      ssl3_finish_mac(s, p, 34);
-+      p += 34;
-+      remaining -= 34;
-+      /* ClientHello: session id length */
-+      if (!remaining)
-+              return 0;
-+      l = *p;
-+      ssl3_finish_mac(s, p, 1);
-+      p++;
-+      remaining--;
-+      /* ClientHello: session id */
-+      if (remaining < l)
-+              return 0;
-+      ssl3_finish_mac(s, p, l);
-+      p += l;
-+      remaining -= l;
-+      /* ClientHello: cipher suites length */
-+      if (remaining < 2)
-+              return 0;
-+      ssl3_finish_mac(s, p, 2);
-+      n2s(p, l);
-+      remaining -= 2;
-+      /* ClientHello: cipher suites */
-+      if (remaining < l)
-+              return 0;
-+      ssl3_finish_mac(s, p, l);
-+      p += l;
-+      remaining -= l;
-+      /* ClientHello: compression methods length */
-+      if (!remaining)
-+              return 0;
-+      l = *p;
-+      ssl3_finish_mac(s, p, 1);
-+      p++;
-+      remaining--;
-+      /* ClientHello: compression methods */
-+      if (remaining < l)
-+              return 0;
-+      ssl3_finish_mac(s, p, l);
-+      p += l;
-+      remaining -= l;
-+      /* ClientHello: extensions length (must exist given that we're already
-+       * parsing the extensions from it */
-+      if (remaining < 2)
-+              return 0;
-+      n2s(p, l);
-+      remaining -= 2;
-+      if (l != remaining || l < ext_len + 4)
-+              return 0;
-+      l -= ext_len + 4;
-+      c = b;
-+      s2n(l, c);
-+      ssl3_finish_mac(s, b, 2);
-+
-+      while (remaining)
-+              {
-+              unsigned long extension_type, extension_len;
-+              if (remaining < 4)
-+                      return 0;
-+              n2s(p, extension_type);
-+              n2s(p, extension_len);
-+              remaining -= 4;
-+              if (remaining < extension_len)
-+                      return 0;
-+              if (extension_type != TLSEXT_TYPE_snap_start)
-+                      ssl3_finish_mac(s, p - 4, extension_len + 4);
-+              p += extension_len;
-+              remaining -= extension_len;
-+              }
-+
-+      return 1;
-+      }
-+
-+static char ssl_parse_snap_start_tlsext(SSL *s, const unsigned char *data, unsigned short len)
-+      {
-+      ptrdiff_t extension_offset = data - (unsigned char *) s->init_buf->data;
-+
-+      if (len > 0 && len < 36)
-+              return 0;
-+      s->s3->snap_start_ext_seen = 1;
-+      if (len == 0)
-+              return 1;
-+
-+      fnv1a64_init((FNV1A64*) s->s3->response_hash);
-+
-+      /* We need to make a copy of the ClientHello because we'll be hashing a
-+       * modified version. However, if we enter recovery then we need to hash
-+       * the unchanged message.
-+       *
-+       * We are adding 4 bytes to the length here because we're including the
-+       * handshake header. */
-+      s->s3->snap_start_client_hello.left = s->init_num + 4;
-+      s->s3->snap_start_client_hello.offset = 0;
-+      s->s3->snap_start_client_hello.buf = OPENSSL_malloc(s->init_num + 4);
-+      if (!s->s3->snap_start_client_hello.buf)
-+              {
-+              /* If we're out of memory then we pretend that we
-+               * didn't see the extension. */
-+              s->s3->snap_start_ext_seen = 0;
-+              return 1;
-+              }
-+
-+      memcpy(s->s3->snap_start_client_hello.buf, s->init_buf->data, s->init_num + 4);
-+      memcpy(s->s3->server_random, s->s3->client_random, 4); /* time */
-+      memcpy(s->s3->server_random + 4, data, 28); /* orbit and random bytes */
-+      memcpy(s->s3->predicted_response_hash, data + 28, 8);
-+
-+      /* Point snap_start_records to within the copy of the ClientHello */
-+      s->s3->snap_start_records.offset = 0;
-+      s->s3->snap_start_records.left = len - 36;
-+      s->s3->snap_start_records.buf = s->s3->snap_start_client_hello.buf + extension_offset + 36;
-+
-+      /* Reset the handshake hash */
-+      ssl3_init_finished_mac(s);
-+
-+      /* Need to hash the ClientHello as if the snap start extension wasn't
-+       * included. */
-+      if (!ssl_hash_snap_start_client_hello(
-+                      s,
-+                      s->init_buf->data,
-+                      s->init_num + 4 /* four bytes of handshake header */,
-+                      len))
-+              {
-+              return 0;
-+              }
-+
-+      s->s3->snap_start_requested = 1;
-+      return 1;
-+      }
-+
- int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, int n, int *al)
-       {
-       unsigned short type;
-@@ -627,6 +811,12 @@ int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
-                       s->s3->next_proto_neg_seen = 1;
-                       }
-+              else if (type == TLSEXT_TYPE_snap_start && s->ctx->snap_start_orbit_valid)
-+                      {
-+                      if (ssl_parse_snap_start_tlsext(s, data, size) == 0)
-+                              return 0;
-+                      }
-+
-               /* session ticket processed earlier */
-               data+=size;             
-diff --git a/ssl/tls1.h b/ssl/tls1.h
-index 71d76de..52ff325 100644
---- a/ssl/tls1.h
-+++ b/ssl/tls1.h
-@@ -120,6 +120,8 @@ extern "C" {
- /* This is not an IANA defined extension number */
- #define TLSEXT_TYPE_next_proto_neg            13172
-+  /* http://tools.ietf.org/html/draft-agl-tls-snapstart-00 */
-+#define TLSEXT_TYPE_snap_start                        13174
- /* NameType value from RFC 3546 */
- #define TLSEXT_NAMETYPE_host_name 0
diff --git a/deps/openssl/patches/tls_exporter.patch b/deps/openssl/patches/tls_exporter.patch
new file mode 100755 (executable)
index 0000000..a9e64a3
--- /dev/null
@@ -0,0 +1,220 @@
+diff --git a/ssl/d1_lib.c b/ssl/d1_lib.c
+index c3b77c8..a94290a 100644
+--- a/ssl/d1_lib.c
++++ b/ssl/d1_lib.c
+@@ -82,6 +82,7 @@ SSL3_ENC_METHOD DTLSv1_enc_data={
+       TLS_MD_CLIENT_FINISH_CONST,TLS_MD_CLIENT_FINISH_CONST_SIZE,
+       TLS_MD_SERVER_FINISH_CONST,TLS_MD_SERVER_FINISH_CONST_SIZE,
+       tls1_alert_code,
++      tls1_export_keying_material,
+       };
+ long dtls1_default_timeout(void)
+diff --git a/ssl/s3_lib.c b/ssl/s3_lib.c
+index c19538a..1fecbbc 100644
+--- a/ssl/s3_lib.c
++++ b/ssl/s3_lib.c
+@@ -2087,6 +2087,9 @@ SSL3_ENC_METHOD SSLv3_enc_data={
+       SSL3_MD_CLIENT_FINISHED_CONST,4,
+       SSL3_MD_SERVER_FINISHED_CONST,4,
+       ssl3_alert_code,
++      (int (*)(SSL *, unsigned char *, size_t, const char *,
++               size_t, const unsigned char *, size_t,
++               int use_context)) ssl_undefined_function,
+       };
+ long ssl3_default_timeout(void)
+diff --git a/ssl/ssl.h b/ssl/ssl.h
+index 9336af8..be4af2f 100644
+--- a/ssl/ssl.h
++++ b/ssl/ssl.h
+@@ -2116,6 +2116,7 @@ void ERR_load_SSL_strings(void);
+ #define SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT    301
+ #define SSL_F_SSL_PARSE_SERVERHELLO_TLSEXT             303
+ #define SSL_F_SSL_PEEK                                         270
++#define SSL_F_TLS1_EXPORT_KEYING_MATERIAL              312
+ #define SSL_F_SSL_PREPARE_CLIENTHELLO_TLSEXT           281
+ #define SSL_F_SSL_PREPARE_SERVERHELLO_TLSEXT           282
+ #define SSL_F_SSL_READ                                         223
+@@ -2394,6 +2395,7 @@ void ERR_load_SSL_strings(void);
+ #define SSL_R_TLSV1_UNRECOGNIZED_NAME                  1112
+ #define SSL_R_TLSV1_UNSUPPORTED_EXTENSION              1110
+ #define SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER     232
++#define SSL_R_TLS_ILLEGAL_EXPORTER_LABEL               367
+ #define SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST           157
+ #define SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST 233
+ #define SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG  234
+diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c
+index 17d2cde..d6ad3c1 100644
+--- a/ssl/ssl_lib.c
++++ b/ssl/ssl_lib.c
+@@ -3127,6 +3127,18 @@ void SSL_CTX_set_next_proto_select_cb(SSL_CTX *ctx, int (*cb) (SSL *s, unsigned
+       }
+ #endif
++int SSL_export_keying_material(SSL *s, unsigned char *out, size_t olen,
++        const char *label, size_t llen, const unsigned char *p, size_t plen,
++        int use_context)
++      {
++      if (s->version < TLS1_VERSION)
++              return -1;
++
++      return s->method->ssl3_enc->export_keying_material(s, out, olen, label,
++                                                         llen, p, plen,
++                                                         use_context);
++      }
++
+ int SSL_cutthrough_complete(const SSL *s)
+       {
+       return (!s->server &&                 /* cutthrough only applies to clients */
+diff --git a/ssl/ssl_locl.h b/ssl/ssl_locl.h
+index 146c89c..e7c6b9a 100644
+--- a/ssl/ssl_locl.h
++++ b/ssl/ssl_locl.h
+@@ -557,6 +557,10 @@ typedef struct ssl3_enc_method
+       const char *server_finished_label;
+       int server_finished_label_len;
+       int (*alert_value)(int);
++      int (*export_keying_material)(SSL *, unsigned char *, size_t,
++                                    const char *, size_t,
++                                    const unsigned char *, size_t,
++                                    int use_context);
+       } SSL3_ENC_METHOD;
+ #ifndef OPENSSL_NO_COMP
+@@ -1041,6 +1045,9 @@ int tls1_cert_verify_mac(SSL *s, int md_nid, unsigned char *p);
+ int tls1_mac(SSL *ssl, unsigned char *md, int snd);
+ int tls1_generate_master_secret(SSL *s, unsigned char *out,
+       unsigned char *p, int len);
++int tls1_export_keying_material(SSL *s, unsigned char *out, size_t olen,
++      const char *label, size_t llen, const unsigned char *p,
++      size_t plen, int use_context);
+ int tls1_alert_code(int code);
+ int ssl3_alert_code(int code);
+ int ssl_ok(SSL *s);
+diff --git a/ssl/t1_enc.c b/ssl/t1_enc.c
+index 793ea43..b1d5b28 100644
+--- a/ssl/t1_enc.c
++++ b/ssl/t1_enc.c
+@@ -1001,6 +1001,95 @@ int tls1_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p,
+       return(SSL3_MASTER_SECRET_SIZE);
+       }
++int tls1_export_keying_material(SSL *s, unsigned char *out, size_t olen,
++       const char *label, size_t llen, const unsigned char *context,
++       size_t contextlen, int use_context)
++      {
++      unsigned char *buff;
++      unsigned char *val = NULL;
++      size_t vallen, currentvalpos;
++      int rv;
++
++#ifdef KSSL_DEBUG
++      printf ("tls1_export_keying_material(%p,%p,%d,%s,%d,%p,%d)\n", s, out, olen, label, llen, p, plen);
++#endif        /* KSSL_DEBUG */
++
++      buff = OPENSSL_malloc(olen);
++      if (buff == NULL) goto err2;
++
++      /* construct PRF arguments
++       * we construct the PRF argument ourself rather than passing separate
++       * values into the TLS PRF to ensure that the concatenation of values
++       * does not create a prohibited label.
++       */
++      vallen = llen + SSL3_RANDOM_SIZE * 2;
++      if (use_context)
++              {
++              vallen += 2 + contextlen;
++              }
++
++      val = OPENSSL_malloc(vallen);
++      if (val == NULL) goto err2;
++      currentvalpos = 0;
++      memcpy(val + currentvalpos, (unsigned char *) label, llen);
++      currentvalpos += llen;
++      memcpy(val + currentvalpos, s->s3->client_random, SSL3_RANDOM_SIZE);
++      currentvalpos += SSL3_RANDOM_SIZE;
++      memcpy(val + currentvalpos, s->s3->server_random, SSL3_RANDOM_SIZE);
++      currentvalpos += SSL3_RANDOM_SIZE;
++
++      if (use_context)
++              {
++              val[currentvalpos] = (contextlen >> 8) & 0xff;
++              currentvalpos++;
++              val[currentvalpos] = contextlen & 0xff;
++              currentvalpos++;
++              if ((contextlen > 0) || (context != NULL))
++                      {
++                      memcpy(val + currentvalpos, context, contextlen);
++                      }
++              }
++
++      /* disallow prohibited labels
++       * note that SSL3_RANDOM_SIZE > max(prohibited label len) =
++       * 15, so size of val > max(prohibited label len) = 15 and the
++       * comparisons won't have buffer overflow
++       */
++      if (memcmp(val, TLS_MD_CLIENT_FINISH_CONST,
++               TLS_MD_CLIENT_FINISH_CONST_SIZE) == 0) goto err1;
++      if (memcmp(val, TLS_MD_SERVER_FINISH_CONST,
++               TLS_MD_SERVER_FINISH_CONST_SIZE) == 0) goto err1;
++      if (memcmp(val, TLS_MD_MASTER_SECRET_CONST,
++               TLS_MD_MASTER_SECRET_CONST_SIZE) == 0) goto err1;
++      if (memcmp(val, TLS_MD_KEY_EXPANSION_CONST,
++               TLS_MD_KEY_EXPANSION_CONST_SIZE) == 0) goto err1;
++
++      rv = tls1_PRF(s->s3->tmp.new_cipher->algorithm2,
++                    val, vallen,
++                    NULL, 0,
++                    NULL, 0,
++                    NULL, 0,
++                    NULL, 0,
++                    s->session->master_key,s->session->master_key_length,
++                    out,buff,olen);
++
++#ifdef KSSL_DEBUG
++      printf ("tls1_export_keying_material() complete\n");
++#endif        /* KSSL_DEBUG */
++      goto ret;
++err1:
++      SSLerr(SSL_F_TLS1_EXPORT_KEYING_MATERIAL, SSL_R_TLS_ILLEGAL_EXPORTER_LABEL);
++      rv = 0;
++      goto ret;
++err2:
++      SSLerr(SSL_F_TLS1_EXPORT_KEYING_MATERIAL, ERR_R_MALLOC_FAILURE);
++      rv = 0;
++ret:
++      if (buff != NULL) OPENSSL_free(buff);
++      if (val != NULL) OPENSSL_free(val);
++      return(rv);
++      }
++
+ int tls1_alert_code(int code)
+       {
+       switch (code)
+diff --git a/ssl/t1_lib.c b/ssl/t1_lib.c
+index daa65c9..c094471 100644
+--- a/ssl/t1_lib.c
++++ b/ssl/t1_lib.c
+@@ -209,6 +209,7 @@ SSL3_ENC_METHOD TLSv1_enc_data={
+       TLS_MD_CLIENT_FINISH_CONST,TLS_MD_CLIENT_FINISH_CONST_SIZE,
+       TLS_MD_SERVER_FINISH_CONST,TLS_MD_SERVER_FINISH_CONST_SIZE,
+       tls1_alert_code,
++      tls1_export_keying_material,
+       };
+ long tls1_default_timeout(void)
+diff --git a/ssl/tls1.h b/ssl/tls1.h
+index 1fa96e5..7bbb875 100644
+--- a/ssl/tls1.h
++++ b/ssl/tls1.h
+@@ -231,6 +231,9 @@ extern "C" {
+ const char *SSL_get_servername(const SSL *s, const int type) ;
+ int SSL_get_servername_type(const SSL *s) ;
++int SSL_export_keying_material(SSL *s, unsigned char *out, size_t olen,
++      const char *label, size_t llen, const unsigned char *p, size_t plen,
++      int use_context);
+ #define SSL_set_tlsext_host_name(s,name) \
+ SSL_ctrl(s,SSL_CTRL_SET_TLSEXT_HOSTNAME,TLSEXT_NAMETYPE_host_name,(char *)name)
\ No newline at end of file
diff --git a/deps/openssl/patches/x509_hash_name_algorithm_change.patch b/deps/openssl/patches/x509_hash_name_algorithm_change.patch
new file mode 100644 (file)
index 0000000..d960184
--- /dev/null
@@ -0,0 +1,31 @@
+--- openssl-1.0.0f-origin/crypto/x509/by_dir.c 2012-01-19 02:20:24.821550944 +0800
++++ openssl-1.0.0f/crypto/x509/by_dir.c        2012-01-19 23:36:53.597870429 +0800
+@@ -287,6 +287,8 @@
+       int ok=0;
+       int i,j,k;
+       unsigned long h;
++      unsigned long hash_array[2];
++      int hash_index;
+       BUF_MEM *b=NULL;
+       X509_OBJECT stmp,*tmp;
+       const char *postfix="";
+@@ -323,6 +325,11 @@
+       ctx=(BY_DIR *)xl->method_data;
+       h=X509_NAME_hash(name);
++      hash_array[0]=h;
++      hash_array[1]=X509_NAME_hash_old(name);
++      for (hash_index=0; hash_index < 2; hash_index++)
++              {
++              h=hash_array[hash_index];
+       for (i=0; i < sk_BY_DIR_ENTRY_num(ctx->dirs); i++)
+               {
+               BY_DIR_ENTRY *ent;
+@@ -476,6 +483,7 @@
+                       goto finish;
+                       }
+               }
++              }
+ finish:
+       if (b != NULL) BUF_MEM_free(b);
+       return(ok);